Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------------- |
| 2 | * Copyright (c) 2011 Ozmo Inc |
| 3 | * Released under the GNU General Public License Version 2 (GPLv2). |
| 4 | * |
| 5 | * This file provides the implementation of a USB host controller device that |
| 6 | * does not have any associated hardware. Instead the virtual device is |
| 7 | * connected to the WiFi network and emulates the operation of a USB hcd by |
| 8 | * receiving and sending network frames. |
| 9 | * Note: |
| 10 | * We take great pains to reduce the amount of code where interrupts need to be |
| 11 | * disabled and in this respect we are different from standard HCD's. In |
| 12 | * particular we don't want in_irq() code bleeding over to the protocol side of |
| 13 | * the driver. |
| 14 | * The troublesome functions are the urb enqueue and dequeue functions both of |
| 15 | * which can be called in_irq(). So for these functions we put the urbs into a |
| 16 | * queue and request a tasklet to process them. This means that a spinlock with |
| 17 | * interrupts disabled must be held for insertion and removal but most code is |
| 18 | * is in tasklet or soft irq context. The lock that protects this list is called |
| 19 | * the tasklet lock and serves the purpose of the 'HCD lock' which must be held |
| 20 | * when calling the following functions. |
| 21 | * usb_hcd_link_urb_to_ep() |
| 22 | * usb_hcd_unlink_urb_from_ep() |
| 23 | * usb_hcd_flush_endpoint() |
| 24 | * usb_hcd_check_unlink_urb() |
| 25 | * ----------------------------------------------------------------------------- |
| 26 | */ |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/usb.h> |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 29 | #include <linux/slab.h> |
| 30 | #include <linux/export.h> |
| 31 | #include "linux/usb/hcd.h" |
| 32 | #include <asm/unaligned.h> |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 33 | #include "ozdbg.h" |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 34 | #include "ozusbif.h" |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 35 | #include "ozurbparanoia.h" |
Peter Huewe | 4f9d5b2 | 2013-02-15 21:17:21 +0100 | [diff] [blame] | 36 | #include "ozhcd.h" |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 37 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 38 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 39 | * Number of units of buffering to capture for an isochronous IN endpoint before |
| 40 | * allowing data to be indicated up. |
| 41 | */ |
Rupesh Gujare | be5e592 | 2013-08-28 12:43:14 +0100 | [diff] [blame] | 42 | #define OZ_IN_BUFFERING_UNITS 100 |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 43 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 44 | /* Name of our platform device. |
| 45 | */ |
| 46 | #define OZ_PLAT_DEV_NAME "ozwpan" |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 47 | |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 48 | /*EP0 timeout before ep0 request is again added to TX queue. (13*8 = 98mSec) |
| 49 | */ |
| 50 | #define EP0_TIMEOUT_COUNTER 13 |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 51 | |
Rupesh Gujare | 0140eb2 | 2013-08-27 16:53:42 +0100 | [diff] [blame] | 52 | /* Debounce time HCD driver should wait before unregistering. |
| 53 | */ |
| 54 | #define OZ_HUB_DEBOUNCE_TIMEOUT 1500 |
| 55 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 56 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 57 | * Used to link urbs together and also store some status information for each |
| 58 | * urb. |
| 59 | * A cache of these are kept in a pool to reduce number of calls to kmalloc. |
| 60 | */ |
| 61 | struct oz_urb_link { |
| 62 | struct list_head link; |
| 63 | struct urb *urb; |
| 64 | struct oz_port *port; |
| 65 | u8 req_id; |
| 66 | u8 ep_num; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 67 | unsigned submit_counter; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Christoph Jaeger | 9e6fbdd | 2014-08-08 07:59:24 +0200 | [diff] [blame] | 70 | static struct kmem_cache *oz_urb_link_cache; |
| 71 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 72 | /* Holds state information about a USB endpoint. |
| 73 | */ |
Rupesh Gujare | 0f750be | 2013-08-23 18:33:29 +0100 | [diff] [blame] | 74 | #define OZ_EP_BUFFER_SIZE_ISOC (1024 * 24) |
Rupesh Gujare | 00d2a46 | 2013-08-23 18:33:30 +0100 | [diff] [blame] | 75 | #define OZ_EP_BUFFER_SIZE_INT 512 |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 76 | struct oz_endpoint { |
| 77 | struct list_head urb_list; /* List of oz_urb_link items. */ |
| 78 | struct list_head link; /* For isoc ep, links in to isoc |
| 79 | lists of oz_port. */ |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 80 | struct timespec timestamp; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 81 | int credit; |
| 82 | int credit_ceiling; |
| 83 | u8 ep_num; |
| 84 | u8 attrib; |
| 85 | u8 *buffer; |
| 86 | int buffer_size; |
| 87 | int in_ix; |
| 88 | int out_ix; |
| 89 | int buffered_units; |
| 90 | unsigned flags; |
| 91 | int start_frame; |
| 92 | }; |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 93 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 94 | /* Bits in the flags field. */ |
| 95 | #define OZ_F_EP_BUFFERING 0x1 |
| 96 | #define OZ_F_EP_HAVE_STREAM 0x2 |
| 97 | |
| 98 | /* Holds state information about a USB interface. |
| 99 | */ |
| 100 | struct oz_interface { |
| 101 | unsigned ep_mask; |
| 102 | u8 alt; |
| 103 | }; |
| 104 | |
| 105 | /* Holds state information about an hcd port. |
| 106 | */ |
| 107 | #define OZ_NB_ENDPOINTS 16 |
| 108 | struct oz_port { |
| 109 | unsigned flags; |
| 110 | unsigned status; |
| 111 | void *hpd; |
| 112 | struct oz_hcd *ozhcd; |
| 113 | spinlock_t port_lock; |
| 114 | u8 bus_addr; |
| 115 | u8 next_req_id; |
| 116 | u8 config_num; |
| 117 | int num_iface; |
| 118 | struct oz_interface *iface; |
| 119 | struct oz_endpoint *out_ep[OZ_NB_ENDPOINTS]; |
| 120 | struct oz_endpoint *in_ep[OZ_NB_ENDPOINTS]; |
| 121 | struct list_head isoc_out_ep; |
| 122 | struct list_head isoc_in_ep; |
| 123 | }; |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 124 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 125 | #define OZ_PORT_F_PRESENT 0x1 |
| 126 | #define OZ_PORT_F_CHANGED 0x2 |
| 127 | #define OZ_PORT_F_DYING 0x4 |
| 128 | |
| 129 | /* Data structure in the private context area of struct usb_hcd. |
| 130 | */ |
| 131 | #define OZ_NB_PORTS 8 |
| 132 | struct oz_hcd { |
| 133 | spinlock_t hcd_lock; |
| 134 | struct list_head urb_pending_list; |
| 135 | struct list_head urb_cancel_list; |
| 136 | struct list_head orphanage; |
| 137 | int conn_port; /* Port that is currently connecting, -1 if none.*/ |
| 138 | struct oz_port ports[OZ_NB_PORTS]; |
| 139 | uint flags; |
| 140 | struct usb_hcd *hcd; |
| 141 | }; |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 142 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 143 | /* Bits in flags field. |
| 144 | */ |
| 145 | #define OZ_HDC_F_SUSPENDED 0x1 |
| 146 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 147 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 148 | * Static function prototypes. |
| 149 | */ |
| 150 | static int oz_hcd_start(struct usb_hcd *hcd); |
| 151 | static void oz_hcd_stop(struct usb_hcd *hcd); |
| 152 | static void oz_hcd_shutdown(struct usb_hcd *hcd); |
| 153 | static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 154 | gfp_t mem_flags); |
| 155 | static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status); |
| 156 | static void oz_hcd_endpoint_disable(struct usb_hcd *hcd, |
| 157 | struct usb_host_endpoint *ep); |
| 158 | static void oz_hcd_endpoint_reset(struct usb_hcd *hcd, |
| 159 | struct usb_host_endpoint *ep); |
| 160 | static int oz_hcd_get_frame_number(struct usb_hcd *hcd); |
| 161 | static int oz_hcd_hub_status_data(struct usb_hcd *hcd, char *buf); |
| 162 | static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue, |
| 163 | u16 windex, char *buf, u16 wlength); |
| 164 | static int oz_hcd_bus_suspend(struct usb_hcd *hcd); |
| 165 | static int oz_hcd_bus_resume(struct usb_hcd *hcd); |
| 166 | static int oz_plat_probe(struct platform_device *dev); |
| 167 | static int oz_plat_remove(struct platform_device *dev); |
| 168 | static void oz_plat_shutdown(struct platform_device *dev); |
| 169 | static int oz_plat_suspend(struct platform_device *dev, pm_message_t msg); |
| 170 | static int oz_plat_resume(struct platform_device *dev); |
| 171 | static void oz_urb_process_tasklet(unsigned long unused); |
| 172 | static int oz_build_endpoints_for_config(struct usb_hcd *hcd, |
| 173 | struct oz_port *port, struct usb_host_config *config, |
| 174 | gfp_t mem_flags); |
| 175 | static void oz_clean_endpoints_for_config(struct usb_hcd *hcd, |
| 176 | struct oz_port *port); |
| 177 | static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, |
| 178 | struct oz_port *port, |
| 179 | struct usb_host_interface *intf, gfp_t mem_flags); |
| 180 | static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, |
| 181 | struct oz_port *port, int if_ix); |
| 182 | static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, |
| 183 | gfp_t mem_flags); |
| 184 | static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, |
| 185 | struct urb *urb); |
| 186 | static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status); |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 187 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 188 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 189 | * Static external variables. |
| 190 | */ |
| 191 | static struct platform_device *g_plat_dev; |
| 192 | static struct oz_hcd *g_ozhcd; |
| 193 | static DEFINE_SPINLOCK(g_hcdlock); /* Guards g_ozhcd. */ |
| 194 | static const char g_hcd_name[] = "Ozmo WPAN"; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 195 | static DEFINE_SPINLOCK(g_tasklet_lock); |
| 196 | static struct tasklet_struct g_urb_process_tasklet; |
| 197 | static struct tasklet_struct g_urb_cancel_tasklet; |
| 198 | static atomic_t g_pending_urbs = ATOMIC_INIT(0); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 199 | static atomic_t g_usb_frame_number = ATOMIC_INIT(0); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 200 | static const struct hc_driver g_oz_hc_drv = { |
| 201 | .description = g_hcd_name, |
| 202 | .product_desc = "Ozmo Devices WPAN", |
| 203 | .hcd_priv_size = sizeof(struct oz_hcd), |
| 204 | .flags = HCD_USB11, |
| 205 | .start = oz_hcd_start, |
| 206 | .stop = oz_hcd_stop, |
| 207 | .shutdown = oz_hcd_shutdown, |
| 208 | .urb_enqueue = oz_hcd_urb_enqueue, |
| 209 | .urb_dequeue = oz_hcd_urb_dequeue, |
| 210 | .endpoint_disable = oz_hcd_endpoint_disable, |
| 211 | .endpoint_reset = oz_hcd_endpoint_reset, |
| 212 | .get_frame_number = oz_hcd_get_frame_number, |
| 213 | .hub_status_data = oz_hcd_hub_status_data, |
| 214 | .hub_control = oz_hcd_hub_control, |
| 215 | .bus_suspend = oz_hcd_bus_suspend, |
| 216 | .bus_resume = oz_hcd_bus_resume, |
| 217 | }; |
| 218 | |
| 219 | static struct platform_driver g_oz_plat_drv = { |
| 220 | .probe = oz_plat_probe, |
| 221 | .remove = oz_plat_remove, |
| 222 | .shutdown = oz_plat_shutdown, |
| 223 | .suspend = oz_plat_suspend, |
| 224 | .resume = oz_plat_resume, |
| 225 | .driver = { |
| 226 | .name = OZ_PLAT_DEV_NAME, |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 227 | }, |
| 228 | }; |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 229 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 230 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 231 | * Gets our private context area (which is of type struct oz_hcd) from the |
| 232 | * usb_hcd structure. |
| 233 | * Context: any |
| 234 | */ |
| 235 | static inline struct oz_hcd *oz_hcd_private(struct usb_hcd *hcd) |
| 236 | { |
| 237 | return (struct oz_hcd *)hcd->hcd_priv; |
| 238 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 239 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 240 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 241 | * Searches list of ports to find the index of the one with a specified USB |
| 242 | * bus address. If none of the ports has the bus address then the connection |
| 243 | * port is returned, if there is one or -1 otherwise. |
| 244 | * Context: any |
| 245 | */ |
| 246 | static int oz_get_port_from_addr(struct oz_hcd *ozhcd, u8 bus_addr) |
| 247 | { |
| 248 | int i; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 249 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 250 | for (i = 0; i < OZ_NB_PORTS; i++) { |
| 251 | if (ozhcd->ports[i].bus_addr == bus_addr) |
| 252 | return i; |
| 253 | } |
| 254 | return ozhcd->conn_port; |
| 255 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 256 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 257 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 258 | * Context: any |
| 259 | */ |
| 260 | static struct oz_urb_link *oz_alloc_urb_link(void) |
| 261 | { |
Christoph Jaeger | 9e6fbdd | 2014-08-08 07:59:24 +0200 | [diff] [blame] | 262 | return kmem_cache_alloc(oz_urb_link_cache, GFP_ATOMIC); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 263 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 264 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 265 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 266 | * Context: any |
| 267 | */ |
| 268 | static void oz_free_urb_link(struct oz_urb_link *urbl) |
| 269 | { |
Christoph Jaeger | 9e6fbdd | 2014-08-08 07:59:24 +0200 | [diff] [blame] | 270 | if (!urbl) |
| 271 | return; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 272 | |
Christoph Jaeger | 9e6fbdd | 2014-08-08 07:59:24 +0200 | [diff] [blame] | 273 | kmem_cache_free(oz_urb_link_cache, urbl); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 274 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 275 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 276 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 277 | * Allocates endpoint structure and optionally a buffer. If a buffer is |
| 278 | * allocated it immediately follows the endpoint structure. |
| 279 | * Context: softirq |
| 280 | */ |
Rupesh Gujare | 5f1f7b1 | 2013-08-13 18:29:25 +0100 | [diff] [blame] | 281 | static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 282 | { |
Quentin Lambert | e03b7297 | 2015-02-10 10:24:12 +0100 | [diff] [blame] | 283 | struct oz_endpoint *ep; |
| 284 | |
| 285 | ep = kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags); |
Quentin Lambert | 6498613 | 2015-02-10 11:42:08 +0100 | [diff] [blame] | 286 | if (!ep) |
| 287 | return NULL; |
| 288 | |
| 289 | INIT_LIST_HEAD(&ep->urb_list); |
| 290 | INIT_LIST_HEAD(&ep->link); |
| 291 | ep->credit = -1; |
| 292 | if (buffer_size) { |
| 293 | ep->buffer_size = buffer_size; |
| 294 | ep->buffer = (u8 *)(ep+1); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 295 | } |
Quentin Lambert | 6498613 | 2015-02-10 11:42:08 +0100 | [diff] [blame] | 296 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 297 | return ep; |
| 298 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 299 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 300 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 301 | * Pre-condition: Must be called with g_tasklet_lock held and interrupts |
| 302 | * disabled. |
| 303 | * Context: softirq or process |
| 304 | */ |
Jérôme Pinot | 46374d3 | 2014-03-13 10:17:17 +0900 | [diff] [blame] | 305 | static struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, |
| 306 | struct urb *urb) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 307 | { |
| 308 | struct oz_urb_link *urbl; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 309 | |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 310 | list_for_each_entry(urbl, &ozhcd->urb_cancel_list, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 311 | if (urb == urbl->urb) { |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 312 | list_del_init(&urbl->link); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 313 | return urbl; |
| 314 | } |
| 315 | } |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 316 | return NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 317 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 318 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 319 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 320 | * This is called when we have finished processing an urb. It unlinks it from |
| 321 | * the ep and returns it to the core. |
| 322 | * Context: softirq or process |
| 323 | */ |
| 324 | static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb, |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 325 | int status) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 326 | { |
| 327 | struct oz_hcd *ozhcd = oz_hcd_private(hcd); |
| 328 | unsigned long irq_state; |
Rupesh Gujare | a15e042 | 2013-08-13 18:29:24 +0100 | [diff] [blame] | 329 | struct oz_urb_link *cancel_urbl; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 330 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 331 | spin_lock_irqsave(&g_tasklet_lock, irq_state); |
| 332 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
| 333 | /* Clear hcpriv which will prevent it being put in the cancel list |
| 334 | * in the event that an attempt is made to cancel it. |
| 335 | */ |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 336 | urb->hcpriv = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 337 | /* Walk the cancel list in case the urb is already sitting there. |
| 338 | * Since we process the cancel list in a tasklet rather than in |
| 339 | * the dequeue function this could happen. |
| 340 | */ |
| 341 | cancel_urbl = oz_uncancel_urb(ozhcd, urb); |
| 342 | /* Note: we release lock but do not enable local irqs. |
| 343 | * It appears that usb_hcd_giveback_urb() expects irqs to be disabled, |
| 344 | * or at least other host controllers disable interrupts at this point |
| 345 | * so we do the same. We must, however, release the lock otherwise a |
| 346 | * deadlock will occur if an urb is submitted to our driver in the urb |
| 347 | * completion function. Because we disable interrupts it is possible |
| 348 | * that the urb_enqueue function can be called with them disabled. |
| 349 | */ |
| 350 | spin_unlock(&g_tasklet_lock); |
| 351 | if (oz_forget_urb(urb)) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 352 | oz_dbg(ON, "ERROR Unknown URB %p\n", urb); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 353 | } else { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 354 | atomic_dec(&g_pending_urbs); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 355 | usb_hcd_giveback_urb(hcd, urb, status); |
| 356 | } |
| 357 | spin_lock(&g_tasklet_lock); |
| 358 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
Markus Elfring | 968bf0c | 2014-11-25 16:51:08 +0100 | [diff] [blame] | 359 | oz_free_urb_link(cancel_urbl); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 360 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 361 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 362 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 363 | * Deallocates an endpoint including deallocating any associated stream and |
| 364 | * returning any queued urbs to the core. |
| 365 | * Context: softirq |
| 366 | */ |
| 367 | static void oz_ep_free(struct oz_port *port, struct oz_endpoint *ep) |
| 368 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 369 | if (port) { |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 370 | LIST_HEAD(list); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 371 | struct oz_hcd *ozhcd = port->ozhcd; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 372 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 373 | if (ep->flags & OZ_F_EP_HAVE_STREAM) |
| 374 | oz_usb_stream_delete(port->hpd, ep->ep_num); |
| 375 | /* Transfer URBs to the orphanage while we hold the lock. */ |
| 376 | spin_lock_bh(&ozhcd->hcd_lock); |
| 377 | /* Note: this works even if ep->urb_list is empty.*/ |
| 378 | list_replace_init(&ep->urb_list, &list); |
| 379 | /* Put the URBs in the orphanage. */ |
| 380 | list_splice_tail(&list, &ozhcd->orphanage); |
| 381 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 382 | } |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 383 | oz_dbg(ON, "Freeing endpoint memory\n"); |
Greg Kroah-Hartman | 1ec41a3 | 2012-03-02 16:51:09 -0800 | [diff] [blame] | 384 | kfree(ep); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 385 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 386 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 387 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 388 | * Context: softirq |
| 389 | */ |
Peter Huewe | a7f74c3 | 2013-02-15 21:17:22 +0100 | [diff] [blame] | 390 | static void oz_complete_buffered_urb(struct oz_port *port, |
| 391 | struct oz_endpoint *ep, |
Rupesh Gujare | 28a7229 | 2012-07-23 18:49:43 +0100 | [diff] [blame] | 392 | struct urb *urb) |
| 393 | { |
Rupesh Gujare | 4882ad95 | 2013-08-23 18:33:31 +0100 | [diff] [blame] | 394 | int data_len, available_space, copy_len; |
Rupesh Gujare | 28a7229 | 2012-07-23 18:49:43 +0100 | [diff] [blame] | 395 | |
Rupesh Gujare | 4882ad95 | 2013-08-23 18:33:31 +0100 | [diff] [blame] | 396 | data_len = ep->buffer[ep->out_ix]; |
Rupesh Gujare | 28a7229 | 2012-07-23 18:49:43 +0100 | [diff] [blame] | 397 | if (data_len <= urb->transfer_buffer_length) |
| 398 | available_space = data_len; |
| 399 | else |
| 400 | available_space = urb->transfer_buffer_length; |
| 401 | |
| 402 | if (++ep->out_ix == ep->buffer_size) |
| 403 | ep->out_ix = 0; |
| 404 | copy_len = ep->buffer_size - ep->out_ix; |
| 405 | if (copy_len >= available_space) |
| 406 | copy_len = available_space; |
| 407 | memcpy(urb->transfer_buffer, &ep->buffer[ep->out_ix], copy_len); |
| 408 | |
| 409 | if (copy_len < available_space) { |
| 410 | memcpy((urb->transfer_buffer + copy_len), ep->buffer, |
| 411 | (available_space - copy_len)); |
| 412 | ep->out_ix = available_space - copy_len; |
| 413 | } else { |
| 414 | ep->out_ix += copy_len; |
| 415 | } |
| 416 | urb->actual_length = available_space; |
| 417 | if (ep->out_ix == ep->buffer_size) |
| 418 | ep->out_ix = 0; |
| 419 | |
| 420 | ep->buffered_units--; |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 421 | oz_dbg(ON, "Trying to give back buffered frame of size=%d\n", |
| 422 | available_space); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 423 | oz_complete_urb(port->ozhcd->hcd, urb, 0); |
Rupesh Gujare | 28a7229 | 2012-07-23 18:49:43 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 426 | /* |
Rupesh Gujare | 28a7229 | 2012-07-23 18:49:43 +0100 | [diff] [blame] | 427 | * Context: softirq |
| 428 | */ |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 429 | static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, |
| 430 | struct urb *urb, u8 req_id) |
| 431 | { |
| 432 | struct oz_urb_link *urbl; |
Rupesh Gujare | 2c66335 | 2013-08-13 18:24:23 +0100 | [diff] [blame] | 433 | struct oz_endpoint *ep = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 434 | int err = 0; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 435 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 436 | if (ep_addr >= OZ_NB_ENDPOINTS) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 437 | oz_dbg(ON, "%s: Invalid endpoint number\n", __func__); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 438 | return -EINVAL; |
| 439 | } |
| 440 | urbl = oz_alloc_urb_link(); |
| 441 | if (!urbl) |
| 442 | return -ENOMEM; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 443 | urbl->submit_counter = 0; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 444 | urbl->urb = urb; |
| 445 | urbl->req_id = req_id; |
| 446 | urbl->ep_num = ep_addr; |
| 447 | /* Hold lock while we insert the URB into the list within the |
| 448 | * endpoint structure. |
| 449 | */ |
| 450 | spin_lock_bh(&port->ozhcd->hcd_lock); |
| 451 | /* If the urb has been unlinked while out of any list then |
| 452 | * complete it now. |
| 453 | */ |
| 454 | if (urb->unlinked) { |
| 455 | spin_unlock_bh(&port->ozhcd->hcd_lock); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 456 | oz_dbg(ON, "urb %p unlinked so complete immediately\n", urb); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 457 | oz_complete_urb(port->ozhcd->hcd, urb, 0); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 458 | oz_free_urb_link(urbl); |
| 459 | return 0; |
| 460 | } |
Rupesh Gujare | 2c66335 | 2013-08-13 18:24:23 +0100 | [diff] [blame] | 461 | |
| 462 | if (in_dir) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 463 | ep = port->in_ep[ep_addr]; |
Rupesh Gujare | 2c66335 | 2013-08-13 18:24:23 +0100 | [diff] [blame] | 464 | else |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 465 | ep = port->out_ep[ep_addr]; |
Rupesh Gujare | 2c66335 | 2013-08-13 18:24:23 +0100 | [diff] [blame] | 466 | if (!ep) { |
Rupesh Gujare | bc9aece | 2013-08-05 18:40:12 +0100 | [diff] [blame] | 467 | err = -ENOMEM; |
| 468 | goto out; |
| 469 | } |
Rupesh Gujare | 28a7229 | 2012-07-23 18:49:43 +0100 | [diff] [blame] | 470 | |
| 471 | /*For interrupt endpoint check for buffered data |
| 472 | * & complete urb |
| 473 | */ |
| 474 | if (((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) |
| 475 | && ep->buffered_units > 0) { |
| 476 | oz_free_urb_link(urbl); |
| 477 | spin_unlock_bh(&port->ozhcd->hcd_lock); |
| 478 | oz_complete_buffered_urb(port, ep, urb); |
| 479 | return 0; |
| 480 | } |
| 481 | |
Rupesh Gujare | c45905a | 2013-08-13 18:29:21 +0100 | [diff] [blame] | 482 | if (port->hpd) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 483 | list_add_tail(&urbl->link, &ep->urb_list); |
| 484 | if (!in_dir && ep_addr && (ep->credit < 0)) { |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 485 | getrawmonotonic(&ep->timestamp); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 486 | ep->credit = 0; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 487 | } |
| 488 | } else { |
| 489 | err = -EPIPE; |
| 490 | } |
Rupesh Gujare | bc9aece | 2013-08-05 18:40:12 +0100 | [diff] [blame] | 491 | out: |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 492 | spin_unlock_bh(&port->ozhcd->hcd_lock); |
| 493 | if (err) |
| 494 | oz_free_urb_link(urbl); |
| 495 | return err; |
| 496 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 497 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 498 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 499 | * Removes an urb from the queue in the endpoint. |
| 500 | * Returns 0 if it is found and -EIDRM otherwise. |
| 501 | * Context: softirq |
| 502 | */ |
| 503 | static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, |
| 504 | struct urb *urb) |
| 505 | { |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 506 | struct oz_urb_link *urbl = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 507 | struct oz_endpoint *ep; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 508 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 509 | spin_lock_bh(&port->ozhcd->hcd_lock); |
| 510 | if (in_dir) |
| 511 | ep = port->in_ep[ep_addr]; |
| 512 | else |
| 513 | ep = port->out_ep[ep_addr]; |
| 514 | if (ep) { |
| 515 | struct list_head *e; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 516 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 517 | list_for_each(e, &ep->urb_list) { |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 518 | urbl = list_entry(e, struct oz_urb_link, link); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 519 | if (urbl->urb == urb) { |
| 520 | list_del_init(e); |
| 521 | break; |
| 522 | } |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 523 | urbl = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | spin_unlock_bh(&port->ozhcd->hcd_lock); |
Markus Elfring | 968bf0c | 2014-11-25 16:51:08 +0100 | [diff] [blame] | 527 | oz_free_urb_link(urbl); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 528 | return urbl ? 0 : -EIDRM; |
| 529 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 530 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 531 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 532 | * Finds an urb given its request id. |
| 533 | * Context: softirq |
| 534 | */ |
| 535 | static struct urb *oz_find_urb_by_id(struct oz_port *port, int ep_ix, |
| 536 | u8 req_id) |
| 537 | { |
| 538 | struct oz_hcd *ozhcd = port->ozhcd; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 539 | struct urb *urb = NULL; |
Rupesh Gujare | a15e042 | 2013-08-13 18:29:24 +0100 | [diff] [blame] | 540 | struct oz_urb_link *urbl; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 541 | struct oz_endpoint *ep; |
| 542 | |
| 543 | spin_lock_bh(&ozhcd->hcd_lock); |
| 544 | ep = port->out_ep[ep_ix]; |
| 545 | if (ep) { |
| 546 | struct list_head *e; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 547 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 548 | list_for_each(e, &ep->urb_list) { |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 549 | urbl = list_entry(e, struct oz_urb_link, link); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 550 | if (urbl->req_id == req_id) { |
| 551 | urb = urbl->urb; |
| 552 | list_del_init(e); |
| 553 | break; |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 558 | /* If urb is non-zero then we we must have an urb link to delete. |
| 559 | */ |
| 560 | if (urb) |
| 561 | oz_free_urb_link(urbl); |
| 562 | return urb; |
| 563 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 564 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 565 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 566 | * Pre-condition: Port lock must be held. |
| 567 | * Context: softirq |
| 568 | */ |
| 569 | static void oz_acquire_port(struct oz_port *port, void *hpd) |
| 570 | { |
| 571 | INIT_LIST_HEAD(&port->isoc_out_ep); |
| 572 | INIT_LIST_HEAD(&port->isoc_in_ep); |
| 573 | port->flags |= OZ_PORT_F_PRESENT | OZ_PORT_F_CHANGED; |
| 574 | port->status |= USB_PORT_STAT_CONNECTION | |
| 575 | (USB_PORT_STAT_C_CONNECTION << 16); |
| 576 | oz_usb_get(hpd); |
| 577 | port->hpd = hpd; |
| 578 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 579 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 580 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 581 | * Context: softirq |
| 582 | */ |
| 583 | static struct oz_hcd *oz_hcd_claim(void) |
| 584 | { |
| 585 | struct oz_hcd *ozhcd; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 586 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 587 | spin_lock_bh(&g_hcdlock); |
| 588 | ozhcd = g_ozhcd; |
| 589 | if (ozhcd) |
| 590 | usb_get_hcd(ozhcd->hcd); |
| 591 | spin_unlock_bh(&g_hcdlock); |
| 592 | return ozhcd; |
| 593 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 594 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 595 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 596 | * Context: softirq |
| 597 | */ |
| 598 | static inline void oz_hcd_put(struct oz_hcd *ozhcd) |
| 599 | { |
| 600 | if (ozhcd) |
| 601 | usb_put_hcd(ozhcd->hcd); |
| 602 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 603 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 604 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 605 | * This is called by the protocol handler to notify that a PD has arrived. |
| 606 | * We allocate a port to associate with the PD and create a structure for |
| 607 | * endpoint 0. This port is made the connection port. |
| 608 | * In the event that one of the other port is already a connection port then |
| 609 | * we fail. |
| 610 | * TODO We should be able to do better than fail and should be able remember |
| 611 | * that this port needs configuring and make it the connection port once the |
| 612 | * current connection port has been assigned an address. Collisions here are |
| 613 | * probably very rare indeed. |
| 614 | * Context: softirq |
| 615 | */ |
Rupesh Gujare | 0503d20 | 2013-08-13 18:29:22 +0100 | [diff] [blame] | 616 | struct oz_port *oz_hcd_pd_arrived(void *hpd) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 617 | { |
| 618 | int i; |
Rupesh Gujare | 3bc0d88 | 2013-08-15 12:00:21 +0100 | [diff] [blame] | 619 | struct oz_port *hport; |
Rupesh Gujare | a15e042 | 2013-08-13 18:29:24 +0100 | [diff] [blame] | 620 | struct oz_hcd *ozhcd; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 621 | struct oz_endpoint *ep; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 622 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 623 | ozhcd = oz_hcd_claim(); |
Dan Carpenter | 95b20b8 | 2013-08-13 18:29:26 +0100 | [diff] [blame] | 624 | if (!ozhcd) |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 625 | return NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 626 | /* Allocate an endpoint object in advance (before holding hcd lock) to |
| 627 | * use for out endpoint 0. |
| 628 | */ |
Rupesh Gujare | 5f1f7b1 | 2013-08-13 18:29:25 +0100 | [diff] [blame] | 629 | ep = oz_ep_alloc(0, GFP_ATOMIC); |
Dan Carpenter | 95b20b8 | 2013-08-13 18:29:26 +0100 | [diff] [blame] | 630 | if (!ep) |
| 631 | goto err_put; |
| 632 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 633 | spin_lock_bh(&ozhcd->hcd_lock); |
Dan Carpenter | 95b20b8 | 2013-08-13 18:29:26 +0100 | [diff] [blame] | 634 | if (ozhcd->conn_port >= 0) |
| 635 | goto err_unlock; |
| 636 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 637 | for (i = 0; i < OZ_NB_PORTS; i++) { |
| 638 | struct oz_port *port = &ozhcd->ports[i]; |
Dan Carpenter | 95b20b8 | 2013-08-13 18:29:26 +0100 | [diff] [blame] | 639 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 640 | spin_lock(&port->port_lock); |
Rupesh Gujare | 0a7bfbf | 2013-08-22 17:38:48 +0100 | [diff] [blame] | 641 | if (!(port->flags & (OZ_PORT_F_PRESENT | OZ_PORT_F_CHANGED))) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 642 | oz_acquire_port(port, hpd); |
| 643 | spin_unlock(&port->port_lock); |
| 644 | break; |
| 645 | } |
| 646 | spin_unlock(&port->port_lock); |
| 647 | } |
Dan Carpenter | 95b20b8 | 2013-08-13 18:29:26 +0100 | [diff] [blame] | 648 | if (i == OZ_NB_PORTS) |
| 649 | goto err_unlock; |
| 650 | |
| 651 | ozhcd->conn_port = i; |
| 652 | hport = &ozhcd->ports[i]; |
| 653 | hport->out_ep[0] = ep; |
| 654 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 655 | if (ozhcd->flags & OZ_HDC_F_SUSPENDED) |
| 656 | usb_hcd_resume_root_hub(ozhcd->hcd); |
| 657 | usb_hcd_poll_rh_status(ozhcd->hcd); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 658 | oz_hcd_put(ozhcd); |
Dan Carpenter | 95b20b8 | 2013-08-13 18:29:26 +0100 | [diff] [blame] | 659 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 660 | return hport; |
Dan Carpenter | 95b20b8 | 2013-08-13 18:29:26 +0100 | [diff] [blame] | 661 | |
| 662 | err_unlock: |
| 663 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 664 | oz_ep_free(NULL, ep); |
| 665 | err_put: |
| 666 | oz_hcd_put(ozhcd); |
| 667 | return NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 668 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 669 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 670 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 671 | * This is called by the protocol handler to notify that the PD has gone away. |
| 672 | * We need to deallocate all resources and then request that the root hub is |
| 673 | * polled. We release the reference we hold on the PD. |
| 674 | * Context: softirq |
| 675 | */ |
Rupesh Gujare | 83db51f | 2013-08-15 12:00:22 +0100 | [diff] [blame] | 676 | void oz_hcd_pd_departed(struct oz_port *port) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 677 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 678 | struct oz_hcd *ozhcd; |
| 679 | void *hpd; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 680 | struct oz_endpoint *ep = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 681 | |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 682 | if (port == NULL) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 683 | oz_dbg(ON, "%s: port = 0\n", __func__); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 684 | return; |
| 685 | } |
| 686 | ozhcd = port->ozhcd; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 687 | if (ozhcd == NULL) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 688 | return; |
| 689 | /* Check if this is the connection port - if so clear it. |
| 690 | */ |
| 691 | spin_lock_bh(&ozhcd->hcd_lock); |
| 692 | if ((ozhcd->conn_port >= 0) && |
| 693 | (port == &ozhcd->ports[ozhcd->conn_port])) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 694 | oz_dbg(ON, "Clearing conn_port\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 695 | ozhcd->conn_port = -1; |
| 696 | } |
| 697 | spin_lock(&port->port_lock); |
| 698 | port->flags |= OZ_PORT_F_DYING; |
| 699 | spin_unlock(&port->port_lock); |
| 700 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 701 | |
| 702 | oz_clean_endpoints_for_config(ozhcd->hcd, port); |
| 703 | spin_lock_bh(&port->port_lock); |
| 704 | hpd = port->hpd; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 705 | port->hpd = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 706 | port->bus_addr = 0xff; |
Rupesh Gujare | d772983 | 2013-08-05 18:40:14 +0100 | [diff] [blame] | 707 | port->config_num = 0; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 708 | port->flags &= ~(OZ_PORT_F_PRESENT | OZ_PORT_F_DYING); |
| 709 | port->flags |= OZ_PORT_F_CHANGED; |
Rupesh Gujare | 6850143 | 2013-08-27 16:53:41 +0100 | [diff] [blame] | 710 | port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 711 | port->status |= (USB_PORT_STAT_C_CONNECTION << 16); |
| 712 | /* If there is an endpont 0 then clear the pointer while we hold |
| 713 | * the spinlock be we deallocate it after releasing the lock. |
| 714 | */ |
| 715 | if (port->out_ep[0]) { |
| 716 | ep = port->out_ep[0]; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 717 | port->out_ep[0] = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 718 | } |
| 719 | spin_unlock_bh(&port->port_lock); |
| 720 | if (ep) |
| 721 | oz_ep_free(port, ep); |
| 722 | usb_hcd_poll_rh_status(ozhcd->hcd); |
| 723 | oz_usb_put(hpd); |
| 724 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 725 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 726 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 727 | * Context: softirq |
| 728 | */ |
| 729 | void oz_hcd_pd_reset(void *hpd, void *hport) |
| 730 | { |
| 731 | /* Cleanup the current configuration and report reset to the core. |
| 732 | */ |
Tapasweni Pathak | b3d43a3 | 2014-10-30 17:02:57 +0530 | [diff] [blame] | 733 | struct oz_port *port = hport; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 734 | struct oz_hcd *ozhcd = port->ozhcd; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 735 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 736 | oz_dbg(ON, "PD Reset\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 737 | spin_lock_bh(&port->port_lock); |
| 738 | port->flags |= OZ_PORT_F_CHANGED; |
| 739 | port->status |= USB_PORT_STAT_RESET; |
| 740 | port->status |= (USB_PORT_STAT_C_RESET << 16); |
| 741 | spin_unlock_bh(&port->port_lock); |
| 742 | oz_clean_endpoints_for_config(ozhcd->hcd, port); |
| 743 | usb_hcd_poll_rh_status(ozhcd->hcd); |
| 744 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 745 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 746 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 747 | * Context: softirq |
| 748 | */ |
Jason A. Donenfeld | b1bb5b4 | 2015-05-29 13:06:59 +0200 | [diff] [blame] | 749 | void oz_hcd_get_desc_cnf(void *hport, u8 req_id, u8 status, const u8 *desc, |
| 750 | u8 length, u16 offset, u16 total_size) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 751 | { |
Tapasweni Pathak | b3d43a3 | 2014-10-30 17:02:57 +0530 | [diff] [blame] | 752 | struct oz_port *port = hport; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 753 | struct urb *urb; |
| 754 | int err = 0; |
| 755 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 756 | oz_dbg(ON, "oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n", |
| 757 | length, offset, total_size); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 758 | urb = oz_find_urb_by_id(port, 0, req_id); |
| 759 | if (!urb) |
| 760 | return; |
| 761 | if (status == 0) { |
Jason A. Donenfeld | b1bb5b4 | 2015-05-29 13:06:59 +0200 | [diff] [blame] | 762 | unsigned int copy_len; |
| 763 | unsigned int required_size = urb->transfer_buffer_length; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 764 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 765 | if (required_size > total_size) |
| 766 | required_size = total_size; |
| 767 | copy_len = required_size-offset; |
| 768 | if (length <= copy_len) |
| 769 | copy_len = length; |
| 770 | memcpy(urb->transfer_buffer+offset, desc, copy_len); |
| 771 | offset += copy_len; |
| 772 | if (offset < required_size) { |
| 773 | struct usb_ctrlrequest *setup = |
| 774 | (struct usb_ctrlrequest *)urb->setup_packet; |
| 775 | unsigned wvalue = le16_to_cpu(setup->wValue); |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 776 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 777 | if (oz_enqueue_ep_urb(port, 0, 0, urb, req_id)) |
| 778 | err = -ENOMEM; |
| 779 | else if (oz_usb_get_desc_req(port->hpd, req_id, |
| 780 | setup->bRequestType, (u8)(wvalue>>8), |
| 781 | (u8)wvalue, setup->wIndex, offset, |
| 782 | required_size-offset)) { |
| 783 | oz_dequeue_ep_urb(port, 0, 0, urb); |
| 784 | err = -ENOMEM; |
| 785 | } |
| 786 | if (err == 0) |
| 787 | return; |
| 788 | } |
| 789 | } |
| 790 | urb->actual_length = total_size; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 791 | oz_complete_urb(port->ozhcd->hcd, urb, 0); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 792 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 793 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 794 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 795 | * Context: softirq |
| 796 | */ |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 797 | static void oz_display_conf_type(u8 t) |
| 798 | { |
| 799 | switch (t) { |
| 800 | case USB_REQ_GET_STATUS: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 801 | oz_dbg(ON, "USB_REQ_GET_STATUS - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 802 | break; |
| 803 | case USB_REQ_CLEAR_FEATURE: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 804 | oz_dbg(ON, "USB_REQ_CLEAR_FEATURE - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 805 | break; |
| 806 | case USB_REQ_SET_FEATURE: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 807 | oz_dbg(ON, "USB_REQ_SET_FEATURE - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 808 | break; |
| 809 | case USB_REQ_SET_ADDRESS: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 810 | oz_dbg(ON, "USB_REQ_SET_ADDRESS - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 811 | break; |
| 812 | case USB_REQ_GET_DESCRIPTOR: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 813 | oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 814 | break; |
| 815 | case USB_REQ_SET_DESCRIPTOR: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 816 | oz_dbg(ON, "USB_REQ_SET_DESCRIPTOR - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 817 | break; |
| 818 | case USB_REQ_GET_CONFIGURATION: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 819 | oz_dbg(ON, "USB_REQ_GET_CONFIGURATION - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 820 | break; |
| 821 | case USB_REQ_SET_CONFIGURATION: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 822 | oz_dbg(ON, "USB_REQ_SET_CONFIGURATION - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 823 | break; |
| 824 | case USB_REQ_GET_INTERFACE: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 825 | oz_dbg(ON, "USB_REQ_GET_INTERFACE - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 826 | break; |
| 827 | case USB_REQ_SET_INTERFACE: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 828 | oz_dbg(ON, "USB_REQ_SET_INTERFACE - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 829 | break; |
| 830 | case USB_REQ_SYNCH_FRAME: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 831 | oz_dbg(ON, "USB_REQ_SYNCH_FRAME - cnf\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 832 | break; |
| 833 | } |
| 834 | } |
Joe Perches | 05f608f | 2013-07-23 13:45:01 +0100 | [diff] [blame] | 835 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 836 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 837 | * Context: softirq |
| 838 | */ |
| 839 | static void oz_hcd_complete_set_config(struct oz_port *port, struct urb *urb, |
| 840 | u8 rcode, u8 config_num) |
| 841 | { |
| 842 | int rc = 0; |
| 843 | struct usb_hcd *hcd = port->ozhcd->hcd; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 844 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 845 | if (rcode == 0) { |
| 846 | port->config_num = config_num; |
| 847 | oz_clean_endpoints_for_config(hcd, port); |
| 848 | if (oz_build_endpoints_for_config(hcd, port, |
| 849 | &urb->dev->config[port->config_num-1], GFP_ATOMIC)) { |
| 850 | rc = -ENOMEM; |
| 851 | } |
| 852 | } else { |
| 853 | rc = -ENOMEM; |
| 854 | } |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 855 | oz_complete_urb(hcd, urb, rc); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 856 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 857 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 858 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 859 | * Context: softirq |
| 860 | */ |
| 861 | static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb, |
| 862 | u8 rcode, u8 if_num, u8 alt) |
| 863 | { |
| 864 | struct usb_hcd *hcd = port->ozhcd->hcd; |
| 865 | int rc = 0; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 866 | |
Rupesh Gujare | 050596a | 2013-08-23 18:33:28 +0100 | [diff] [blame] | 867 | if ((rcode == 0) && (port->config_num > 0)) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 868 | struct usb_host_config *config; |
| 869 | struct usb_host_interface *intf; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 870 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 871 | oz_dbg(ON, "Set interface %d alt %d\n", if_num, alt); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 872 | oz_clean_endpoints_for_interface(hcd, port, if_num); |
| 873 | config = &urb->dev->config[port->config_num-1]; |
| 874 | intf = &config->intf_cache[if_num]->altsetting[alt]; |
| 875 | if (oz_build_endpoints_for_interface(hcd, port, intf, |
| 876 | GFP_ATOMIC)) |
| 877 | rc = -ENOMEM; |
| 878 | else |
| 879 | port->iface[if_num].alt = alt; |
| 880 | } else { |
| 881 | rc = -ENOMEM; |
| 882 | } |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 883 | oz_complete_urb(hcd, urb, rc); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 884 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 885 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 886 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 887 | * Context: softirq |
| 888 | */ |
Peter Huewe | dc7f5b3 | 2013-02-15 21:17:24 +0100 | [diff] [blame] | 889 | void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data, |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 890 | int data_len) |
| 891 | { |
Tapasweni Pathak | b3d43a3 | 2014-10-30 17:02:57 +0530 | [diff] [blame] | 892 | struct oz_port *port = hport; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 893 | struct urb *urb; |
| 894 | struct usb_ctrlrequest *setup; |
| 895 | struct usb_hcd *hcd = port->ozhcd->hcd; |
| 896 | unsigned windex; |
| 897 | unsigned wvalue; |
| 898 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 899 | oz_dbg(ON, "oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 900 | urb = oz_find_urb_by_id(port, 0, req_id); |
| 901 | if (!urb) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 902 | oz_dbg(ON, "URB not found\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 903 | return; |
| 904 | } |
| 905 | setup = (struct usb_ctrlrequest *)urb->setup_packet; |
| 906 | windex = le16_to_cpu(setup->wIndex); |
| 907 | wvalue = le16_to_cpu(setup->wValue); |
| 908 | if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { |
| 909 | /* Standard requests */ |
| 910 | oz_display_conf_type(setup->bRequest); |
| 911 | switch (setup->bRequest) { |
| 912 | case USB_REQ_SET_CONFIGURATION: |
| 913 | oz_hcd_complete_set_config(port, urb, rcode, |
| 914 | (u8)wvalue); |
| 915 | break; |
| 916 | case USB_REQ_SET_INTERFACE: |
| 917 | oz_hcd_complete_set_interface(port, urb, rcode, |
| 918 | (u8)windex, (u8)wvalue); |
| 919 | break; |
| 920 | default: |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 921 | oz_complete_urb(hcd, urb, 0); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | } else { |
| 925 | int copy_len; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 926 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 927 | oz_dbg(ON, "VENDOR-CLASS - cnf\n"); |
Rupesh Gujare | 5494ebd | 2012-07-23 18:49:45 +0100 | [diff] [blame] | 928 | if (data_len) { |
| 929 | if (data_len <= urb->transfer_buffer_length) |
| 930 | copy_len = data_len; |
| 931 | else |
| 932 | copy_len = urb->transfer_buffer_length; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 933 | memcpy(urb->transfer_buffer, data, copy_len); |
Rupesh Gujare | 5494ebd | 2012-07-23 18:49:45 +0100 | [diff] [blame] | 934 | urb->actual_length = copy_len; |
| 935 | } |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 936 | oz_complete_urb(hcd, urb, 0); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 937 | } |
| 938 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 939 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 940 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 941 | * Context: softirq-serialized |
| 942 | */ |
Peter Huewe | dc7f5b3 | 2013-02-15 21:17:24 +0100 | [diff] [blame] | 943 | static int oz_hcd_buffer_data(struct oz_endpoint *ep, const u8 *data, |
| 944 | int data_len) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 945 | { |
| 946 | int space; |
| 947 | int copy_len; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 948 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 949 | if (!ep->buffer) |
| 950 | return -1; |
| 951 | space = ep->out_ix-ep->in_ix-1; |
| 952 | if (space < 0) |
| 953 | space += ep->buffer_size; |
| 954 | if (space < (data_len+1)) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 955 | oz_dbg(ON, "Buffer full\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 956 | return -1; |
| 957 | } |
| 958 | ep->buffer[ep->in_ix] = (u8)data_len; |
| 959 | if (++ep->in_ix == ep->buffer_size) |
| 960 | ep->in_ix = 0; |
| 961 | copy_len = ep->buffer_size - ep->in_ix; |
| 962 | if (copy_len > data_len) |
| 963 | copy_len = data_len; |
| 964 | memcpy(&ep->buffer[ep->in_ix], data, copy_len); |
| 965 | |
| 966 | if (copy_len < data_len) { |
| 967 | memcpy(ep->buffer, data+copy_len, data_len-copy_len); |
| 968 | ep->in_ix = data_len-copy_len; |
| 969 | } else { |
| 970 | ep->in_ix += copy_len; |
| 971 | } |
| 972 | if (ep->in_ix == ep->buffer_size) |
| 973 | ep->in_ix = 0; |
| 974 | ep->buffered_units++; |
| 975 | return 0; |
| 976 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 977 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 978 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 979 | * Context: softirq-serialized |
| 980 | */ |
Peter Huewe | dc7f5b3 | 2013-02-15 21:17:24 +0100 | [diff] [blame] | 981 | void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 982 | { |
| 983 | struct oz_port *port = (struct oz_port *)hport; |
| 984 | struct oz_endpoint *ep; |
| 985 | struct oz_hcd *ozhcd = port->ozhcd; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 986 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 987 | spin_lock_bh(&ozhcd->hcd_lock); |
| 988 | ep = port->in_ep[endpoint & USB_ENDPOINT_NUMBER_MASK]; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 989 | if (ep == NULL) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 990 | goto done; |
| 991 | switch (ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) { |
| 992 | case USB_ENDPOINT_XFER_INT: |
| 993 | case USB_ENDPOINT_XFER_BULK: |
| 994 | if (!list_empty(&ep->urb_list)) { |
| 995 | struct oz_urb_link *urbl = |
| 996 | list_first_entry(&ep->urb_list, |
| 997 | struct oz_urb_link, link); |
| 998 | struct urb *urb; |
| 999 | int copy_len; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 1000 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1001 | list_del_init(&urbl->link); |
| 1002 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 1003 | urb = urbl->urb; |
| 1004 | oz_free_urb_link(urbl); |
| 1005 | if (data_len <= urb->transfer_buffer_length) |
| 1006 | copy_len = data_len; |
| 1007 | else |
| 1008 | copy_len = urb->transfer_buffer_length; |
| 1009 | memcpy(urb->transfer_buffer, data, copy_len); |
| 1010 | urb->actual_length = copy_len; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1011 | oz_complete_urb(port->ozhcd->hcd, urb, 0); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1012 | return; |
| 1013 | } |
Adrian Nicoara | d75b6c6 | 2014-09-08 14:41:48 -0400 | [diff] [blame] | 1014 | oz_dbg(ON, "buffering frame as URB is not available\n"); |
| 1015 | oz_hcd_buffer_data(ep, data, data_len); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1016 | break; |
| 1017 | case USB_ENDPOINT_XFER_ISOC: |
| 1018 | oz_hcd_buffer_data(ep, data, data_len); |
| 1019 | break; |
| 1020 | } |
| 1021 | done: |
| 1022 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 1023 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1024 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1025 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1026 | * Context: unknown |
| 1027 | */ |
| 1028 | static inline int oz_usb_get_frame_number(void) |
| 1029 | { |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1030 | return atomic_inc_return(&g_usb_frame_number); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1031 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1032 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1033 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1034 | * Context: softirq |
| 1035 | */ |
| 1036 | int oz_hcd_heartbeat(void *hport) |
| 1037 | { |
| 1038 | int rc = 0; |
Tapasweni Pathak | b3d43a3 | 2014-10-30 17:02:57 +0530 | [diff] [blame] | 1039 | struct oz_port *port = hport; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1040 | struct oz_hcd *ozhcd = port->ozhcd; |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1041 | struct oz_urb_link *urbl, *n; |
| 1042 | LIST_HEAD(xfr_list); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1043 | struct urb *urb; |
| 1044 | struct oz_endpoint *ep; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1045 | struct timespec ts, delta; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1046 | |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1047 | getrawmonotonic(&ts); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1048 | /* Check the OUT isoc endpoints to see if any URB data can be sent. |
| 1049 | */ |
| 1050 | spin_lock_bh(&ozhcd->hcd_lock); |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1051 | list_for_each_entry(ep, &port->isoc_out_ep, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1052 | if (ep->credit < 0) |
| 1053 | continue; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1054 | delta = timespec_sub(ts, ep->timestamp); |
Rupesh Gujare | 5cf9d25 | 2013-08-05 12:14:04 +0100 | [diff] [blame] | 1055 | ep->credit += div_u64(timespec_to_ns(&delta), NSEC_PER_MSEC); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1056 | if (ep->credit > ep->credit_ceiling) |
| 1057 | ep->credit = ep->credit_ceiling; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1058 | ep->timestamp = ts; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1059 | while (ep->credit && !list_empty(&ep->urb_list)) { |
| 1060 | urbl = list_first_entry(&ep->urb_list, |
| 1061 | struct oz_urb_link, link); |
| 1062 | urb = urbl->urb; |
Rupesh Gujare | 2416891 | 2012-07-23 18:49:44 +0100 | [diff] [blame] | 1063 | if ((ep->credit + 1) < urb->number_of_packets) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1064 | break; |
| 1065 | ep->credit -= urb->number_of_packets; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1066 | if (ep->credit < 0) |
| 1067 | ep->credit = 0; |
Wei Yongjun | 094e74c | 2012-09-05 14:48:48 +0800 | [diff] [blame] | 1068 | list_move_tail(&urbl->link, &xfr_list); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 1072 | /* Send to PD and complete URBs. |
| 1073 | */ |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1074 | list_for_each_entry_safe(urbl, n, &xfr_list, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1075 | urb = urbl->urb; |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1076 | list_del_init(&urbl->link); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1077 | urb->error_count = 0; |
| 1078 | urb->start_frame = oz_usb_get_frame_number(); |
| 1079 | oz_usb_send_isoc(port->hpd, urbl->ep_num, urb); |
| 1080 | oz_free_urb_link(urbl); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1081 | oz_complete_urb(port->ozhcd->hcd, urb, 0); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1082 | } |
| 1083 | /* Check the IN isoc endpoints to see if any URBs can be completed. |
| 1084 | */ |
| 1085 | spin_lock_bh(&ozhcd->hcd_lock); |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1086 | list_for_each_entry(ep, &port->isoc_in_ep, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1087 | if (ep->flags & OZ_F_EP_BUFFERING) { |
Rupesh Gujare | b360cb9 | 2013-01-29 17:00:55 +0000 | [diff] [blame] | 1088 | if (ep->buffered_units >= OZ_IN_BUFFERING_UNITS) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1089 | ep->flags &= ~OZ_F_EP_BUFFERING; |
| 1090 | ep->credit = 0; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1091 | ep->timestamp = ts; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1092 | ep->start_frame = 0; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1093 | } |
| 1094 | continue; |
| 1095 | } |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1096 | delta = timespec_sub(ts, ep->timestamp); |
Rupesh Gujare | 5cf9d25 | 2013-08-05 12:14:04 +0100 | [diff] [blame] | 1097 | ep->credit += div_u64(timespec_to_ns(&delta), NSEC_PER_MSEC); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1098 | ep->timestamp = ts; |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1099 | list_for_each_entry_safe(urbl, n, &ep->urb_list, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1100 | struct urb *urb = urbl->urb; |
| 1101 | int len = 0; |
| 1102 | int copy_len; |
| 1103 | int i; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 1104 | |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1105 | if (ep->credit < urb->number_of_packets) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1106 | break; |
| 1107 | if (ep->buffered_units < urb->number_of_packets) |
| 1108 | break; |
| 1109 | urb->actual_length = 0; |
| 1110 | for (i = 0; i < urb->number_of_packets; i++) { |
| 1111 | len = ep->buffer[ep->out_ix]; |
| 1112 | if (++ep->out_ix == ep->buffer_size) |
| 1113 | ep->out_ix = 0; |
| 1114 | copy_len = ep->buffer_size - ep->out_ix; |
| 1115 | if (copy_len > len) |
| 1116 | copy_len = len; |
| 1117 | memcpy(urb->transfer_buffer, |
| 1118 | &ep->buffer[ep->out_ix], copy_len); |
| 1119 | if (copy_len < len) { |
| 1120 | memcpy(urb->transfer_buffer+copy_len, |
| 1121 | ep->buffer, len-copy_len); |
| 1122 | ep->out_ix = len-copy_len; |
| 1123 | } else |
| 1124 | ep->out_ix += copy_len; |
| 1125 | if (ep->out_ix == ep->buffer_size) |
| 1126 | ep->out_ix = 0; |
| 1127 | urb->iso_frame_desc[i].offset = |
| 1128 | urb->actual_length; |
| 1129 | urb->actual_length += len; |
| 1130 | urb->iso_frame_desc[i].actual_length = len; |
| 1131 | urb->iso_frame_desc[i].status = 0; |
| 1132 | } |
| 1133 | ep->buffered_units -= urb->number_of_packets; |
| 1134 | urb->error_count = 0; |
| 1135 | urb->start_frame = ep->start_frame; |
| 1136 | ep->start_frame += urb->number_of_packets; |
Wei Yongjun | 094e74c | 2012-09-05 14:48:48 +0800 | [diff] [blame] | 1137 | list_move_tail(&urbl->link, &xfr_list); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1138 | ep->credit -= urb->number_of_packets; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | if (!list_empty(&port->isoc_out_ep) || !list_empty(&port->isoc_in_ep)) |
| 1142 | rc = 1; |
| 1143 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 1144 | /* Complete the filled URBs. |
| 1145 | */ |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1146 | list_for_each_entry_safe(urbl, n, &xfr_list, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1147 | urb = urbl->urb; |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1148 | list_del_init(&urbl->link); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1149 | oz_free_urb_link(urbl); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1150 | oz_complete_urb(port->ozhcd->hcd, urb, 0); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1151 | } |
| 1152 | /* Check if there are any ep0 requests that have timed out. |
| 1153 | * If so resent to PD. |
| 1154 | */ |
| 1155 | ep = port->out_ep[0]; |
| 1156 | if (ep) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1157 | spin_lock_bh(&ozhcd->hcd_lock); |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1158 | list_for_each_entry_safe(urbl, n, &ep->urb_list, link) { |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1159 | if (urbl->submit_counter > EP0_TIMEOUT_COUNTER) { |
| 1160 | oz_dbg(ON, "Request 0x%p timeout\n", urbl->urb); |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1161 | list_move_tail(&urbl->link, &xfr_list); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1162 | urbl->submit_counter = 0; |
| 1163 | } else { |
| 1164 | urbl->submit_counter++; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | if (!list_empty(&ep->urb_list)) |
| 1168 | rc = 1; |
| 1169 | spin_unlock_bh(&ozhcd->hcd_lock); |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1170 | list_for_each_entry_safe(urbl, n, &xfr_list, link) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1171 | oz_dbg(ON, "Resending request to PD\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1172 | oz_process_ep0_urb(ozhcd, urbl->urb, GFP_ATOMIC); |
| 1173 | oz_free_urb_link(urbl); |
| 1174 | } |
| 1175 | } |
| 1176 | return rc; |
| 1177 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1178 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1179 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1180 | * Context: softirq |
| 1181 | */ |
| 1182 | static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, |
| 1183 | struct oz_port *port, |
| 1184 | struct usb_host_interface *intf, gfp_t mem_flags) |
| 1185 | { |
| 1186 | struct oz_hcd *ozhcd = port->ozhcd; |
| 1187 | int i; |
| 1188 | int if_ix = intf->desc.bInterfaceNumber; |
| 1189 | int request_heartbeat = 0; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1190 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1191 | oz_dbg(ON, "interface[%d] = %p\n", if_ix, intf); |
Rupesh Gujare | d236dc1 | 2013-08-22 17:38:49 +0100 | [diff] [blame] | 1192 | if (if_ix >= port->num_iface || port->iface == NULL) |
| 1193 | return -ENOMEM; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1194 | for (i = 0; i < intf->desc.bNumEndpoints; i++) { |
| 1195 | struct usb_host_endpoint *hep = &intf->endpoint[i]; |
| 1196 | u8 ep_addr = hep->desc.bEndpointAddress; |
| 1197 | u8 ep_num = ep_addr & USB_ENDPOINT_NUMBER_MASK; |
| 1198 | struct oz_endpoint *ep; |
| 1199 | int buffer_size = 0; |
| 1200 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1201 | oz_dbg(ON, "%d bEndpointAddress = %x\n", i, ep_addr); |
Rupesh Gujare | 28a7229 | 2012-07-23 18:49:43 +0100 | [diff] [blame] | 1202 | if (ep_addr & USB_ENDPOINT_DIR_MASK) { |
| 1203 | switch (hep->desc.bmAttributes & |
| 1204 | USB_ENDPOINT_XFERTYPE_MASK) { |
| 1205 | case USB_ENDPOINT_XFER_ISOC: |
Rupesh Gujare | 0f750be | 2013-08-23 18:33:29 +0100 | [diff] [blame] | 1206 | buffer_size = OZ_EP_BUFFER_SIZE_ISOC; |
Rupesh Gujare | 28a7229 | 2012-07-23 18:49:43 +0100 | [diff] [blame] | 1207 | break; |
| 1208 | case USB_ENDPOINT_XFER_INT: |
Rupesh Gujare | 00d2a46 | 2013-08-23 18:33:30 +0100 | [diff] [blame] | 1209 | buffer_size = OZ_EP_BUFFER_SIZE_INT; |
Rupesh Gujare | 28a7229 | 2012-07-23 18:49:43 +0100 | [diff] [blame] | 1210 | break; |
| 1211 | } |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
Rupesh Gujare | 5f1f7b1 | 2013-08-13 18:29:25 +0100 | [diff] [blame] | 1214 | ep = oz_ep_alloc(buffer_size, mem_flags); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1215 | if (!ep) { |
| 1216 | oz_clean_endpoints_for_interface(hcd, port, if_ix); |
| 1217 | return -ENOMEM; |
| 1218 | } |
| 1219 | ep->attrib = hep->desc.bmAttributes; |
| 1220 | ep->ep_num = ep_num; |
| 1221 | if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) |
| 1222 | == USB_ENDPOINT_XFER_ISOC) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1223 | oz_dbg(ON, "wMaxPacketSize = %d\n", |
| 1224 | usb_endpoint_maxp(&hep->desc)); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1225 | ep->credit_ceiling = 200; |
| 1226 | if (ep_addr & USB_ENDPOINT_DIR_MASK) { |
| 1227 | ep->flags |= OZ_F_EP_BUFFERING; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1228 | } else { |
| 1229 | ep->flags |= OZ_F_EP_HAVE_STREAM; |
| 1230 | if (oz_usb_stream_create(port->hpd, ep_num)) |
| 1231 | ep->flags &= ~OZ_F_EP_HAVE_STREAM; |
| 1232 | } |
| 1233 | } |
| 1234 | spin_lock_bh(&ozhcd->hcd_lock); |
| 1235 | if (ep_addr & USB_ENDPOINT_DIR_MASK) { |
| 1236 | port->in_ep[ep_num] = ep; |
| 1237 | port->iface[if_ix].ep_mask |= |
| 1238 | (1<<(ep_num+OZ_NB_ENDPOINTS)); |
| 1239 | if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) |
| 1240 | == USB_ENDPOINT_XFER_ISOC) { |
| 1241 | list_add_tail(&ep->link, &port->isoc_in_ep); |
| 1242 | request_heartbeat = 1; |
| 1243 | } |
| 1244 | } else { |
| 1245 | port->out_ep[ep_num] = ep; |
| 1246 | port->iface[if_ix].ep_mask |= (1<<ep_num); |
| 1247 | if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) |
| 1248 | == USB_ENDPOINT_XFER_ISOC) { |
| 1249 | list_add_tail(&ep->link, &port->isoc_out_ep); |
| 1250 | request_heartbeat = 1; |
| 1251 | } |
| 1252 | } |
| 1253 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 1254 | if (request_heartbeat && port->hpd) |
| 1255 | oz_usb_request_heartbeat(port->hpd); |
| 1256 | } |
| 1257 | return 0; |
| 1258 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1259 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1260 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1261 | * Context: softirq |
| 1262 | */ |
| 1263 | static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, |
| 1264 | struct oz_port *port, int if_ix) |
| 1265 | { |
| 1266 | struct oz_hcd *ozhcd = port->ozhcd; |
| 1267 | unsigned mask; |
| 1268 | int i; |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1269 | LIST_HEAD(ep_list); |
| 1270 | struct oz_endpoint *ep, *n; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1271 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1272 | oz_dbg(ON, "Deleting endpoints for interface %d\n", if_ix); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1273 | if (if_ix >= port->num_iface) |
| 1274 | return; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1275 | spin_lock_bh(&ozhcd->hcd_lock); |
| 1276 | mask = port->iface[if_ix].ep_mask; |
| 1277 | port->iface[if_ix].ep_mask = 0; |
| 1278 | for (i = 0; i < OZ_NB_ENDPOINTS; i++) { |
| 1279 | struct list_head *e; |
| 1280 | /* Gather OUT endpoints. |
| 1281 | */ |
| 1282 | if ((mask & (1<<i)) && port->out_ep[i]) { |
| 1283 | e = &port->out_ep[i]->link; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1284 | port->out_ep[i] = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1285 | /* Remove from isoc list if present. |
| 1286 | */ |
Wei Yongjun | 094e74c | 2012-09-05 14:48:48 +0800 | [diff] [blame] | 1287 | list_move_tail(e, &ep_list); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1288 | } |
| 1289 | /* Gather IN endpoints. |
| 1290 | */ |
| 1291 | if ((mask & (1<<(i+OZ_NB_ENDPOINTS))) && port->in_ep[i]) { |
| 1292 | e = &port->in_ep[i]->link; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1293 | port->in_ep[i] = NULL; |
Wei Yongjun | 094e74c | 2012-09-05 14:48:48 +0800 | [diff] [blame] | 1294 | list_move_tail(e, &ep_list); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | spin_unlock_bh(&ozhcd->hcd_lock); |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1298 | list_for_each_entry_safe(ep, n, &ep_list, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1299 | list_del_init(&ep->link); |
| 1300 | oz_ep_free(port, ep); |
| 1301 | } |
| 1302 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1303 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1304 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1305 | * Context: softirq |
| 1306 | */ |
| 1307 | static int oz_build_endpoints_for_config(struct usb_hcd *hcd, |
| 1308 | struct oz_port *port, struct usb_host_config *config, |
| 1309 | gfp_t mem_flags) |
| 1310 | { |
| 1311 | struct oz_hcd *ozhcd = port->ozhcd; |
| 1312 | int i; |
| 1313 | int num_iface = config->desc.bNumInterfaces; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1314 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1315 | if (num_iface) { |
Greg Kroah-Hartman | 1ec41a3 | 2012-03-02 16:51:09 -0800 | [diff] [blame] | 1316 | struct oz_interface *iface; |
| 1317 | |
Adrian Nicoara | e0301d0 | 2014-09-08 15:02:49 -0400 | [diff] [blame] | 1318 | iface = kmalloc_array(num_iface, sizeof(struct oz_interface), |
| 1319 | mem_flags | __GFP_ZERO); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1320 | if (!iface) |
| 1321 | return -ENOMEM; |
| 1322 | spin_lock_bh(&ozhcd->hcd_lock); |
| 1323 | port->iface = iface; |
| 1324 | port->num_iface = num_iface; |
| 1325 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 1326 | } |
| 1327 | for (i = 0; i < num_iface; i++) { |
| 1328 | struct usb_host_interface *intf = |
| 1329 | &config->intf_cache[i]->altsetting[0]; |
| 1330 | if (oz_build_endpoints_for_interface(hcd, port, intf, |
| 1331 | mem_flags)) |
| 1332 | goto fail; |
| 1333 | } |
| 1334 | return 0; |
| 1335 | fail: |
| 1336 | oz_clean_endpoints_for_config(hcd, port); |
| 1337 | return -1; |
| 1338 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1339 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1340 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1341 | * Context: softirq |
| 1342 | */ |
| 1343 | static void oz_clean_endpoints_for_config(struct usb_hcd *hcd, |
| 1344 | struct oz_port *port) |
| 1345 | { |
| 1346 | struct oz_hcd *ozhcd = port->ozhcd; |
| 1347 | int i; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1348 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1349 | oz_dbg(ON, "Deleting endpoints for configuration\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1350 | for (i = 0; i < port->num_iface; i++) |
| 1351 | oz_clean_endpoints_for_interface(hcd, port, i); |
| 1352 | spin_lock_bh(&ozhcd->hcd_lock); |
| 1353 | if (port->iface) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1354 | oz_dbg(ON, "Freeing interfaces object\n"); |
Greg Kroah-Hartman | 1ec41a3 | 2012-03-02 16:51:09 -0800 | [diff] [blame] | 1355 | kfree(port->iface); |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1356 | port->iface = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1357 | } |
| 1358 | port->num_iface = 0; |
| 1359 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 1360 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1361 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1362 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1363 | * Context: tasklet |
| 1364 | */ |
| 1365 | static void *oz_claim_hpd(struct oz_port *port) |
| 1366 | { |
Rupesh Gujare | a15e042 | 2013-08-13 18:29:24 +0100 | [diff] [blame] | 1367 | void *hpd; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1368 | struct oz_hcd *ozhcd = port->ozhcd; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1369 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1370 | spin_lock_bh(&ozhcd->hcd_lock); |
| 1371 | hpd = port->hpd; |
| 1372 | if (hpd) |
| 1373 | oz_usb_get(hpd); |
| 1374 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 1375 | return hpd; |
| 1376 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1377 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1378 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1379 | * Context: tasklet |
| 1380 | */ |
| 1381 | static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, |
| 1382 | gfp_t mem_flags) |
| 1383 | { |
| 1384 | struct usb_ctrlrequest *setup; |
| 1385 | unsigned windex; |
| 1386 | unsigned wvalue; |
| 1387 | unsigned wlength; |
Rupesh Gujare | a15e042 | 2013-08-13 18:29:24 +0100 | [diff] [blame] | 1388 | void *hpd; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1389 | u8 req_id; |
| 1390 | int rc = 0; |
| 1391 | unsigned complete = 0; |
| 1392 | |
| 1393 | int port_ix = -1; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1394 | struct oz_port *port = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1395 | |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1396 | oz_dbg(URB, "[%s]:(%p)\n", __func__, urb); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1397 | port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum); |
| 1398 | if (port_ix < 0) { |
| 1399 | rc = -EPIPE; |
| 1400 | goto out; |
| 1401 | } |
| 1402 | port = &ozhcd->ports[port_ix]; |
| 1403 | if (((port->flags & OZ_PORT_F_PRESENT) == 0) |
| 1404 | || (port->flags & OZ_PORT_F_DYING)) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1405 | oz_dbg(ON, "Refusing URB port_ix = %d devnum = %d\n", |
| 1406 | port_ix, urb->dev->devnum); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1407 | rc = -EPIPE; |
| 1408 | goto out; |
| 1409 | } |
| 1410 | /* Store port in private context data. |
| 1411 | */ |
| 1412 | urb->hcpriv = port; |
| 1413 | setup = (struct usb_ctrlrequest *)urb->setup_packet; |
| 1414 | windex = le16_to_cpu(setup->wIndex); |
| 1415 | wvalue = le16_to_cpu(setup->wValue); |
| 1416 | wlength = le16_to_cpu(setup->wLength); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1417 | oz_dbg(CTRL_DETAIL, "bRequestType = %x\n", setup->bRequestType); |
| 1418 | oz_dbg(CTRL_DETAIL, "bRequest = %x\n", setup->bRequest); |
| 1419 | oz_dbg(CTRL_DETAIL, "wValue = %x\n", wvalue); |
| 1420 | oz_dbg(CTRL_DETAIL, "wIndex = %x\n", windex); |
| 1421 | oz_dbg(CTRL_DETAIL, "wLength = %x\n", wlength); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1422 | |
| 1423 | req_id = port->next_req_id++; |
| 1424 | hpd = oz_claim_hpd(port); |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1425 | if (hpd == NULL) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1426 | oz_dbg(ON, "Cannot claim port\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1427 | rc = -EPIPE; |
| 1428 | goto out; |
| 1429 | } |
| 1430 | |
| 1431 | if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { |
| 1432 | /* Standard requests |
| 1433 | */ |
| 1434 | switch (setup->bRequest) { |
| 1435 | case USB_REQ_GET_DESCRIPTOR: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1436 | oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - req\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1437 | break; |
| 1438 | case USB_REQ_SET_ADDRESS: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1439 | oz_dbg(ON, "USB_REQ_SET_ADDRESS - req\n"); |
| 1440 | oz_dbg(ON, "Port %d address is 0x%x\n", |
| 1441 | ozhcd->conn_port, |
| 1442 | (u8)le16_to_cpu(setup->wValue)); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1443 | spin_lock_bh(&ozhcd->hcd_lock); |
| 1444 | if (ozhcd->conn_port >= 0) { |
| 1445 | ozhcd->ports[ozhcd->conn_port].bus_addr = |
| 1446 | (u8)le16_to_cpu(setup->wValue); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1447 | oz_dbg(ON, "Clearing conn_port\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1448 | ozhcd->conn_port = -1; |
| 1449 | } |
| 1450 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 1451 | complete = 1; |
| 1452 | break; |
| 1453 | case USB_REQ_SET_CONFIGURATION: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1454 | oz_dbg(ON, "USB_REQ_SET_CONFIGURATION - req\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1455 | break; |
| 1456 | case USB_REQ_GET_CONFIGURATION: |
Masanari Iida | 8dc2459 | 2012-04-25 23:28:35 +0900 | [diff] [blame] | 1457 | /* We short circuit this case and reply directly since |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1458 | * we have the selected configuration number cached. |
| 1459 | */ |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1460 | oz_dbg(ON, "USB_REQ_GET_CONFIGURATION - reply now\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1461 | if (urb->transfer_buffer_length >= 1) { |
| 1462 | urb->actual_length = 1; |
| 1463 | *((u8 *)urb->transfer_buffer) = |
| 1464 | port->config_num; |
| 1465 | complete = 1; |
| 1466 | } else { |
| 1467 | rc = -EPIPE; |
| 1468 | } |
| 1469 | break; |
| 1470 | case USB_REQ_GET_INTERFACE: |
Masanari Iida | 8dc2459 | 2012-04-25 23:28:35 +0900 | [diff] [blame] | 1471 | /* We short circuit this case and reply directly since |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1472 | * we have the selected interface alternative cached. |
| 1473 | */ |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1474 | oz_dbg(ON, "USB_REQ_GET_INTERFACE - reply now\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1475 | if (urb->transfer_buffer_length >= 1) { |
| 1476 | urb->actual_length = 1; |
| 1477 | *((u8 *)urb->transfer_buffer) = |
| 1478 | port->iface[(u8)windex].alt; |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1479 | oz_dbg(ON, "interface = %d alt = %d\n", |
| 1480 | windex, port->iface[(u8)windex].alt); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1481 | complete = 1; |
| 1482 | } else { |
| 1483 | rc = -EPIPE; |
| 1484 | } |
| 1485 | break; |
| 1486 | case USB_REQ_SET_INTERFACE: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1487 | oz_dbg(ON, "USB_REQ_SET_INTERFACE - req\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1488 | break; |
| 1489 | } |
| 1490 | } |
| 1491 | if (!rc && !complete) { |
| 1492 | int data_len = 0; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 1493 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1494 | if ((setup->bRequestType & USB_DIR_IN) == 0) |
| 1495 | data_len = wlength; |
Rupesh Gujare | 5494ebd | 2012-07-23 18:49:45 +0100 | [diff] [blame] | 1496 | urb->actual_length = data_len; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1497 | if (oz_usb_control_req(port->hpd, req_id, setup, |
| 1498 | urb->transfer_buffer, data_len)) { |
| 1499 | rc = -ENOMEM; |
| 1500 | } else { |
| 1501 | /* Note: we are queuing the request after we have |
Justin P. Mattock | 595914f | 2012-03-19 08:17:50 -0700 | [diff] [blame] | 1502 | * submitted it to be transmitted. If the request were |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1503 | * to complete before we queued it then it would not |
| 1504 | * be found in the queue. It seems impossible for |
| 1505 | * this to happen but if it did the request would |
| 1506 | * be resubmitted so the problem would hopefully |
| 1507 | * resolve itself. Putting the request into the |
| 1508 | * queue before it has been sent is worse since the |
| 1509 | * urb could be cancelled while we are using it |
| 1510 | * to build the request. |
| 1511 | */ |
| 1512 | if (oz_enqueue_ep_urb(port, 0, 0, urb, req_id)) |
| 1513 | rc = -ENOMEM; |
| 1514 | } |
| 1515 | } |
| 1516 | oz_usb_put(hpd); |
| 1517 | out: |
| 1518 | if (rc || complete) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1519 | oz_dbg(ON, "Completing request locally\n"); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1520 | oz_complete_urb(ozhcd->hcd, urb, rc); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1521 | } else { |
| 1522 | oz_usb_request_heartbeat(port->hpd); |
| 1523 | } |
| 1524 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1525 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1526 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1527 | * Context: tasklet |
| 1528 | */ |
| 1529 | static int oz_urb_process(struct oz_hcd *ozhcd, struct urb *urb) |
| 1530 | { |
| 1531 | int rc = 0; |
| 1532 | struct oz_port *port = urb->hcpriv; |
| 1533 | u8 ep_addr; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1534 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1535 | /* When we are paranoid we keep a list of urbs which we check against |
| 1536 | * before handing one back. This is just for debugging during |
| 1537 | * development and should be turned off in the released driver. |
| 1538 | */ |
| 1539 | oz_remember_urb(urb); |
| 1540 | /* Check buffer is valid. |
| 1541 | */ |
| 1542 | if (!urb->transfer_buffer && urb->transfer_buffer_length) |
| 1543 | return -EINVAL; |
| 1544 | /* Check if there is a device at the port - refuse if not. |
| 1545 | */ |
| 1546 | if ((port->flags & OZ_PORT_F_PRESENT) == 0) |
| 1547 | return -EPIPE; |
| 1548 | ep_addr = usb_pipeendpoint(urb->pipe); |
| 1549 | if (ep_addr) { |
| 1550 | /* If the request is not for EP0 then queue it. |
| 1551 | */ |
| 1552 | if (oz_enqueue_ep_urb(port, ep_addr, usb_pipein(urb->pipe), |
| 1553 | urb, 0)) |
| 1554 | rc = -EPIPE; |
| 1555 | } else { |
| 1556 | oz_process_ep0_urb(ozhcd, urb, GFP_ATOMIC); |
| 1557 | } |
| 1558 | return rc; |
| 1559 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1560 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1561 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1562 | * Context: tasklet |
| 1563 | */ |
| 1564 | static void oz_urb_process_tasklet(unsigned long unused) |
| 1565 | { |
| 1566 | unsigned long irq_state; |
| 1567 | struct urb *urb; |
| 1568 | struct oz_hcd *ozhcd = oz_hcd_claim(); |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1569 | struct oz_urb_link *urbl, *n; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1570 | int rc = 0; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1571 | |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1572 | if (ozhcd == NULL) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1573 | return; |
| 1574 | /* This is called from a tasklet so is in softirq context but the urb |
| 1575 | * list is filled from any context so we need to lock |
| 1576 | * appropriately while removing urbs. |
| 1577 | */ |
| 1578 | spin_lock_irqsave(&g_tasklet_lock, irq_state); |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1579 | list_for_each_entry_safe(urbl, n, &ozhcd->urb_pending_list, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1580 | list_del_init(&urbl->link); |
| 1581 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
| 1582 | urb = urbl->urb; |
| 1583 | oz_free_urb_link(urbl); |
| 1584 | rc = oz_urb_process(ozhcd, urb); |
| 1585 | if (rc) |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1586 | oz_complete_urb(ozhcd->hcd, urb, rc); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1587 | spin_lock_irqsave(&g_tasklet_lock, irq_state); |
| 1588 | } |
| 1589 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
| 1590 | oz_hcd_put(ozhcd); |
| 1591 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1592 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1593 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1594 | * This function searches for the urb in any of the lists it could be in. |
| 1595 | * If it is found it is removed from the list and completed. If the urb is |
| 1596 | * being processed then it won't be in a list so won't be found. However, the |
| 1597 | * call to usb_hcd_check_unlink_urb() will set the value of the unlinked field |
| 1598 | * to a non-zero value. When an attempt is made to put the urb back in a list |
| 1599 | * the unlinked field will be checked and the urb will then be completed. |
| 1600 | * Context: tasklet |
| 1601 | */ |
| 1602 | static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) |
| 1603 | { |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1604 | struct oz_urb_link *urbl = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1605 | struct list_head *e; |
| 1606 | struct oz_hcd *ozhcd; |
| 1607 | unsigned long irq_state; |
| 1608 | u8 ix; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1609 | |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1610 | if (port == NULL) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1611 | oz_dbg(ON, "%s: ERROR: (%p) port is null\n", __func__, urb); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1612 | return; |
| 1613 | } |
| 1614 | ozhcd = port->ozhcd; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1615 | if (ozhcd == NULL) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1616 | oz_dbg(ON, "%s; ERROR: (%p) ozhcd is null\n", __func__, urb); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1617 | return; |
| 1618 | } |
| 1619 | |
| 1620 | /* Look in the tasklet queue. |
| 1621 | */ |
| 1622 | spin_lock_irqsave(&g_tasklet_lock, irq_state); |
| 1623 | list_for_each(e, &ozhcd->urb_cancel_list) { |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1624 | urbl = list_entry(e, struct oz_urb_link, link); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1625 | if (urb == urbl->urb) { |
| 1626 | list_del_init(e); |
| 1627 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
| 1628 | goto out2; |
| 1629 | } |
| 1630 | } |
| 1631 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1632 | urbl = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1633 | |
| 1634 | /* Look in the orphanage. |
| 1635 | */ |
| 1636 | spin_lock_irqsave(&ozhcd->hcd_lock, irq_state); |
| 1637 | list_for_each(e, &ozhcd->orphanage) { |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1638 | urbl = list_entry(e, struct oz_urb_link, link); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1639 | if (urbl->urb == urb) { |
| 1640 | list_del(e); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1641 | oz_dbg(ON, "Found urb in orphanage\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1642 | goto out; |
| 1643 | } |
| 1644 | } |
| 1645 | ix = (ep_num & 0xf); |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1646 | urbl = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1647 | if ((ep_num & USB_DIR_IN) && ix) |
| 1648 | urbl = oz_remove_urb(port->in_ep[ix], urb); |
| 1649 | else |
| 1650 | urbl = oz_remove_urb(port->out_ep[ix], urb); |
| 1651 | out: |
| 1652 | spin_unlock_irqrestore(&ozhcd->hcd_lock, irq_state); |
| 1653 | out2: |
| 1654 | if (urbl) { |
| 1655 | urb->actual_length = 0; |
| 1656 | oz_free_urb_link(urbl); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1657 | oz_complete_urb(ozhcd->hcd, urb, -EPIPE); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1658 | } |
| 1659 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1660 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1661 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1662 | * Context: tasklet |
| 1663 | */ |
| 1664 | static void oz_urb_cancel_tasklet(unsigned long unused) |
| 1665 | { |
| 1666 | unsigned long irq_state; |
| 1667 | struct urb *urb; |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1668 | struct oz_urb_link *urbl, *n; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1669 | struct oz_hcd *ozhcd = oz_hcd_claim(); |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1670 | |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1671 | if (ozhcd == NULL) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1672 | return; |
| 1673 | spin_lock_irqsave(&g_tasklet_lock, irq_state); |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1674 | list_for_each_entry_safe(urbl, n, &ozhcd->urb_cancel_list, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1675 | list_del_init(&urbl->link); |
| 1676 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
| 1677 | urb = urbl->urb; |
| 1678 | if (urb->unlinked) |
| 1679 | oz_urb_cancel(urbl->port, urbl->ep_num, urb); |
| 1680 | oz_free_urb_link(urbl); |
| 1681 | spin_lock_irqsave(&g_tasklet_lock, irq_state); |
| 1682 | } |
| 1683 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
| 1684 | oz_hcd_put(ozhcd); |
| 1685 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1686 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1687 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1688 | * Context: unknown |
| 1689 | */ |
| 1690 | static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status) |
| 1691 | { |
| 1692 | if (ozhcd) { |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1693 | struct oz_urb_link *urbl, *n; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 1694 | |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1695 | list_for_each_entry_safe(urbl, n, &ozhcd->orphanage, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1696 | list_del(&urbl->link); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1697 | oz_complete_urb(ozhcd->hcd, urbl->urb, status); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1698 | oz_free_urb_link(urbl); |
| 1699 | } |
| 1700 | } |
| 1701 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1702 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1703 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1704 | * Context: unknown |
| 1705 | */ |
| 1706 | static int oz_hcd_start(struct usb_hcd *hcd) |
| 1707 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1708 | hcd->power_budget = 200; |
| 1709 | hcd->state = HC_STATE_RUNNING; |
| 1710 | hcd->uses_new_polling = 1; |
| 1711 | return 0; |
| 1712 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1713 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1714 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1715 | * Context: unknown |
| 1716 | */ |
| 1717 | static void oz_hcd_stop(struct usb_hcd *hcd) |
| 1718 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1719 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1720 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1721 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1722 | * Context: unknown |
| 1723 | */ |
| 1724 | static void oz_hcd_shutdown(struct usb_hcd *hcd) |
| 1725 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1726 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1727 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1728 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1729 | * Called to queue an urb for the device. |
| 1730 | * This function should return a non-zero error code if it fails the urb but |
| 1731 | * should not call usb_hcd_giveback_urb(). |
| 1732 | * Context: any |
| 1733 | */ |
| 1734 | static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 1735 | gfp_t mem_flags) |
| 1736 | { |
| 1737 | struct oz_hcd *ozhcd = oz_hcd_private(hcd); |
Rupesh Gujare | a15e042 | 2013-08-13 18:29:24 +0100 | [diff] [blame] | 1738 | int rc; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1739 | int port_ix; |
| 1740 | struct oz_port *port; |
| 1741 | unsigned long irq_state; |
| 1742 | struct oz_urb_link *urbl; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1743 | |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1744 | oz_dbg(URB, "%s: (%p)\n", __func__, urb); |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1745 | if (unlikely(ozhcd == NULL)) { |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1746 | oz_dbg(URB, "Refused urb(%p) not ozhcd\n", urb); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1747 | return -EPIPE; |
| 1748 | } |
| 1749 | if (unlikely(hcd->state != HC_STATE_RUNNING)) { |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1750 | oz_dbg(URB, "Refused urb(%p) not running\n", urb); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1751 | return -EPIPE; |
| 1752 | } |
| 1753 | port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum); |
| 1754 | if (port_ix < 0) |
| 1755 | return -EPIPE; |
| 1756 | port = &ozhcd->ports[port_ix]; |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1757 | if (port == NULL) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1758 | return -EPIPE; |
Rupesh Gujare | 0a7bfbf | 2013-08-22 17:38:48 +0100 | [diff] [blame] | 1759 | if (!(port->flags & OZ_PORT_F_PRESENT) || |
| 1760 | (port->flags & OZ_PORT_F_CHANGED)) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1761 | oz_dbg(ON, "Refusing URB port_ix = %d devnum = %d\n", |
| 1762 | port_ix, urb->dev->devnum); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1763 | return -EPIPE; |
| 1764 | } |
| 1765 | urb->hcpriv = port; |
| 1766 | /* Put request in queue for processing by tasklet. |
| 1767 | */ |
| 1768 | urbl = oz_alloc_urb_link(); |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1769 | if (unlikely(urbl == NULL)) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1770 | return -ENOMEM; |
| 1771 | urbl->urb = urb; |
| 1772 | spin_lock_irqsave(&g_tasklet_lock, irq_state); |
| 1773 | rc = usb_hcd_link_urb_to_ep(hcd, urb); |
| 1774 | if (unlikely(rc)) { |
| 1775 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
| 1776 | oz_free_urb_link(urbl); |
| 1777 | return rc; |
| 1778 | } |
| 1779 | list_add_tail(&urbl->link, &ozhcd->urb_pending_list); |
| 1780 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
| 1781 | tasklet_schedule(&g_urb_process_tasklet); |
| 1782 | atomic_inc(&g_pending_urbs); |
| 1783 | return 0; |
| 1784 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1785 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1786 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1787 | * Context: tasklet |
| 1788 | */ |
| 1789 | static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, |
| 1790 | struct urb *urb) |
| 1791 | { |
Rupesh Gujare | a15e042 | 2013-08-13 18:29:24 +0100 | [diff] [blame] | 1792 | struct oz_urb_link *urbl; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1793 | |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1794 | if (unlikely(ep == NULL)) |
| 1795 | return NULL; |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1796 | |
| 1797 | list_for_each_entry(urbl, &ep->urb_list, link) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1798 | if (urbl->urb == urb) { |
Christoph Jaeger | a87c380 | 2014-08-04 14:54:56 +0200 | [diff] [blame] | 1799 | list_del_init(&urbl->link); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1800 | if (usb_pipeisoc(urb->pipe)) { |
| 1801 | ep->credit -= urb->number_of_packets; |
| 1802 | if (ep->credit < 0) |
| 1803 | ep->credit = 0; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1804 | } |
| 1805 | return urbl; |
| 1806 | } |
| 1807 | } |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1808 | return NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1809 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1810 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1811 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1812 | * Called to dequeue a previously submitted urb for the device. |
| 1813 | * Context: any |
| 1814 | */ |
| 1815 | static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) |
| 1816 | { |
| 1817 | struct oz_hcd *ozhcd = oz_hcd_private(hcd); |
Rupesh Gujare | a15e042 | 2013-08-13 18:29:24 +0100 | [diff] [blame] | 1818 | struct oz_urb_link *urbl; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1819 | int rc; |
| 1820 | unsigned long irq_state; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 1821 | |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 1822 | oz_dbg(URB, "%s: (%p)\n", __func__, urb); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1823 | urbl = oz_alloc_urb_link(); |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 1824 | if (unlikely(urbl == NULL)) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1825 | return -ENOMEM; |
| 1826 | spin_lock_irqsave(&g_tasklet_lock, irq_state); |
| 1827 | /* The following function checks the urb is still in the queue |
| 1828 | * maintained by the core and that the unlinked field is zero. |
| 1829 | * If both are true the function sets the unlinked field and returns |
| 1830 | * zero. Otherwise it returns an error. |
| 1831 | */ |
| 1832 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); |
| 1833 | /* We have to check we haven't completed the urb or are about |
| 1834 | * to complete it. When we do we set hcpriv to 0 so if this has |
| 1835 | * already happened we don't put the urb in the cancel queue. |
| 1836 | */ |
| 1837 | if ((rc == 0) && urb->hcpriv) { |
| 1838 | urbl->urb = urb; |
| 1839 | urbl->port = (struct oz_port *)urb->hcpriv; |
| 1840 | urbl->ep_num = usb_pipeendpoint(urb->pipe); |
| 1841 | if (usb_pipein(urb->pipe)) |
| 1842 | urbl->ep_num |= USB_DIR_IN; |
| 1843 | list_add_tail(&urbl->link, &ozhcd->urb_cancel_list); |
| 1844 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
| 1845 | tasklet_schedule(&g_urb_cancel_tasklet); |
| 1846 | } else { |
| 1847 | spin_unlock_irqrestore(&g_tasklet_lock, irq_state); |
| 1848 | oz_free_urb_link(urbl); |
| 1849 | } |
| 1850 | return rc; |
| 1851 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1852 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1853 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1854 | * Context: unknown |
| 1855 | */ |
| 1856 | static void oz_hcd_endpoint_disable(struct usb_hcd *hcd, |
| 1857 | struct usb_host_endpoint *ep) |
| 1858 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1859 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1860 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1861 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1862 | * Context: unknown |
| 1863 | */ |
| 1864 | static void oz_hcd_endpoint_reset(struct usb_hcd *hcd, |
| 1865 | struct usb_host_endpoint *ep) |
| 1866 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1867 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1868 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1869 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1870 | * Context: unknown |
| 1871 | */ |
| 1872 | static int oz_hcd_get_frame_number(struct usb_hcd *hcd) |
| 1873 | { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1874 | oz_dbg(ON, "oz_hcd_get_frame_number\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1875 | return oz_usb_get_frame_number(); |
| 1876 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1877 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1878 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1879 | * Context: softirq |
| 1880 | * This is called as a consquence of us calling usb_hcd_poll_rh_status() and we |
| 1881 | * always do that in softirq context. |
| 1882 | */ |
| 1883 | static int oz_hcd_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 1884 | { |
| 1885 | struct oz_hcd *ozhcd = oz_hcd_private(hcd); |
| 1886 | int i; |
| 1887 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1888 | buf[0] = 0; |
Rupesh Gujare | a666981 | 2013-08-05 18:40:15 +0100 | [diff] [blame] | 1889 | buf[1] = 0; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1890 | |
| 1891 | spin_lock_bh(&ozhcd->hcd_lock); |
| 1892 | for (i = 0; i < OZ_NB_PORTS; i++) { |
| 1893 | if (ozhcd->ports[i].flags & OZ_PORT_F_CHANGED) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1894 | oz_dbg(HUB, "Port %d changed\n", i); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1895 | ozhcd->ports[i].flags &= ~OZ_PORT_F_CHANGED; |
Rupesh Gujare | a666981 | 2013-08-05 18:40:15 +0100 | [diff] [blame] | 1896 | if (i < 7) |
Rupesh Gujare | 0535281 | 2013-08-13 18:24:24 +0100 | [diff] [blame] | 1897 | buf[0] |= 1 << (i + 1); |
Rupesh Gujare | a666981 | 2013-08-05 18:40:15 +0100 | [diff] [blame] | 1898 | else |
Rupesh Gujare | 0535281 | 2013-08-13 18:24:24 +0100 | [diff] [blame] | 1899 | buf[1] |= 1 << (i - 7); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | spin_unlock_bh(&ozhcd->hcd_lock); |
Rupesh Gujare | a666981 | 2013-08-05 18:40:15 +0100 | [diff] [blame] | 1903 | if (buf[0] != 0 || buf[1] != 0) |
| 1904 | return 2; |
Adrian Nicoara | d75b6c6 | 2014-09-08 14:41:48 -0400 | [diff] [blame] | 1905 | return 0; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1906 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1907 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1908 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1909 | * Context: process |
| 1910 | */ |
| 1911 | static void oz_get_hub_descriptor(struct usb_hcd *hcd, |
| 1912 | struct usb_hub_descriptor *desc) |
| 1913 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1914 | memset(desc, 0, sizeof(*desc)); |
| 1915 | desc->bDescriptorType = 0x29; |
| 1916 | desc->bDescLength = 9; |
Melike Yurtoglu | 43f61da | 2014-10-26 23:55:22 +0200 | [diff] [blame] | 1917 | desc->wHubCharacteristics = cpu_to_le16(0x0001); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1918 | desc->bNbrPorts = OZ_NB_PORTS; |
| 1919 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1920 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1921 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1922 | * Context: process |
| 1923 | */ |
| 1924 | static int oz_set_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) |
| 1925 | { |
| 1926 | struct oz_port *port; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1927 | u8 port_id = (u8)windex; |
| 1928 | struct oz_hcd *ozhcd = oz_hcd_private(hcd); |
| 1929 | unsigned set_bits = 0; |
| 1930 | unsigned clear_bits = 0; |
Joe Perches | 30f1e5a | 2013-07-23 13:44:59 +0100 | [diff] [blame] | 1931 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1932 | if ((port_id < 1) || (port_id > OZ_NB_PORTS)) |
| 1933 | return -EPIPE; |
| 1934 | port = &ozhcd->ports[port_id-1]; |
| 1935 | switch (wvalue) { |
| 1936 | case USB_PORT_FEAT_CONNECTION: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1937 | oz_dbg(HUB, "USB_PORT_FEAT_CONNECTION\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1938 | break; |
| 1939 | case USB_PORT_FEAT_ENABLE: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1940 | oz_dbg(HUB, "USB_PORT_FEAT_ENABLE\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1941 | break; |
| 1942 | case USB_PORT_FEAT_SUSPEND: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1943 | oz_dbg(HUB, "USB_PORT_FEAT_SUSPEND\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1944 | break; |
| 1945 | case USB_PORT_FEAT_OVER_CURRENT: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1946 | oz_dbg(HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1947 | break; |
| 1948 | case USB_PORT_FEAT_RESET: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1949 | oz_dbg(HUB, "USB_PORT_FEAT_RESET\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1950 | set_bits = USB_PORT_STAT_ENABLE | (USB_PORT_STAT_C_RESET<<16); |
| 1951 | clear_bits = USB_PORT_STAT_RESET; |
| 1952 | ozhcd->ports[port_id-1].bus_addr = 0; |
| 1953 | break; |
| 1954 | case USB_PORT_FEAT_POWER: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1955 | oz_dbg(HUB, "USB_PORT_FEAT_POWER\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1956 | set_bits |= USB_PORT_STAT_POWER; |
| 1957 | break; |
| 1958 | case USB_PORT_FEAT_LOWSPEED: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1959 | oz_dbg(HUB, "USB_PORT_FEAT_LOWSPEED\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1960 | break; |
| 1961 | case USB_PORT_FEAT_C_CONNECTION: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1962 | oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1963 | break; |
| 1964 | case USB_PORT_FEAT_C_ENABLE: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1965 | oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1966 | break; |
| 1967 | case USB_PORT_FEAT_C_SUSPEND: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1968 | oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1969 | break; |
| 1970 | case USB_PORT_FEAT_C_OVER_CURRENT: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1971 | oz_dbg(HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1972 | break; |
| 1973 | case USB_PORT_FEAT_C_RESET: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1974 | oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1975 | break; |
| 1976 | case USB_PORT_FEAT_TEST: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1977 | oz_dbg(HUB, "USB_PORT_FEAT_TEST\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1978 | break; |
| 1979 | case USB_PORT_FEAT_INDICATOR: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1980 | oz_dbg(HUB, "USB_PORT_FEAT_INDICATOR\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1981 | break; |
| 1982 | default: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1983 | oz_dbg(HUB, "Other %d\n", wvalue); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1984 | break; |
| 1985 | } |
| 1986 | if (set_bits || clear_bits) { |
| 1987 | spin_lock_bh(&port->port_lock); |
| 1988 | port->status &= ~clear_bits; |
| 1989 | port->status |= set_bits; |
| 1990 | spin_unlock_bh(&port->port_lock); |
| 1991 | } |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 1992 | oz_dbg(HUB, "Port[%d] status = 0x%x\n", port_id, port->status); |
Peter Senna Tschudin | a3c9719 | 2014-05-20 12:33:47 +0200 | [diff] [blame] | 1993 | return 0; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1994 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 1995 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 1996 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 1997 | * Context: process |
| 1998 | */ |
| 1999 | static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) |
| 2000 | { |
| 2001 | struct oz_port *port; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2002 | u8 port_id = (u8)windex; |
| 2003 | struct oz_hcd *ozhcd = oz_hcd_private(hcd); |
| 2004 | unsigned clear_bits = 0; |
Joe Perches | 30f1e5a | 2013-07-23 13:44:59 +0100 | [diff] [blame] | 2005 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2006 | if ((port_id < 1) || (port_id > OZ_NB_PORTS)) |
| 2007 | return -EPIPE; |
| 2008 | port = &ozhcd->ports[port_id-1]; |
| 2009 | switch (wvalue) { |
| 2010 | case USB_PORT_FEAT_CONNECTION: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2011 | oz_dbg(HUB, "USB_PORT_FEAT_CONNECTION\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2012 | break; |
| 2013 | case USB_PORT_FEAT_ENABLE: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2014 | oz_dbg(HUB, "USB_PORT_FEAT_ENABLE\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2015 | clear_bits = USB_PORT_STAT_ENABLE; |
| 2016 | break; |
| 2017 | case USB_PORT_FEAT_SUSPEND: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2018 | oz_dbg(HUB, "USB_PORT_FEAT_SUSPEND\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2019 | break; |
| 2020 | case USB_PORT_FEAT_OVER_CURRENT: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2021 | oz_dbg(HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2022 | break; |
| 2023 | case USB_PORT_FEAT_RESET: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2024 | oz_dbg(HUB, "USB_PORT_FEAT_RESET\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2025 | break; |
| 2026 | case USB_PORT_FEAT_POWER: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2027 | oz_dbg(HUB, "USB_PORT_FEAT_POWER\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2028 | clear_bits |= USB_PORT_STAT_POWER; |
| 2029 | break; |
| 2030 | case USB_PORT_FEAT_LOWSPEED: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2031 | oz_dbg(HUB, "USB_PORT_FEAT_LOWSPEED\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2032 | break; |
| 2033 | case USB_PORT_FEAT_C_CONNECTION: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2034 | oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n"); |
Jiayi Ye | 1d06bb4 | 2014-10-25 10:58:28 +0800 | [diff] [blame] | 2035 | clear_bits = USB_PORT_STAT_C_CONNECTION << 16; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2036 | break; |
| 2037 | case USB_PORT_FEAT_C_ENABLE: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2038 | oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n"); |
Jiayi Ye | 1d06bb4 | 2014-10-25 10:58:28 +0800 | [diff] [blame] | 2039 | clear_bits = USB_PORT_STAT_C_ENABLE << 16; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2040 | break; |
| 2041 | case USB_PORT_FEAT_C_SUSPEND: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2042 | oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | case USB_PORT_FEAT_C_OVER_CURRENT: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2045 | oz_dbg(HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2046 | break; |
| 2047 | case USB_PORT_FEAT_C_RESET: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2048 | oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n"); |
Jiayi Ye | 1d06bb4 | 2014-10-25 10:58:28 +0800 | [diff] [blame] | 2049 | clear_bits = USB_PORT_FEAT_C_RESET << 16; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2050 | break; |
| 2051 | case USB_PORT_FEAT_TEST: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2052 | oz_dbg(HUB, "USB_PORT_FEAT_TEST\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2053 | break; |
| 2054 | case USB_PORT_FEAT_INDICATOR: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2055 | oz_dbg(HUB, "USB_PORT_FEAT_INDICATOR\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2056 | break; |
| 2057 | default: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2058 | oz_dbg(HUB, "Other %d\n", wvalue); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2059 | break; |
| 2060 | } |
| 2061 | if (clear_bits) { |
| 2062 | spin_lock_bh(&port->port_lock); |
| 2063 | port->status &= ~clear_bits; |
| 2064 | spin_unlock_bh(&port->port_lock); |
| 2065 | } |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2066 | oz_dbg(HUB, "Port[%d] status = 0x%x\n", |
| 2067 | port_id, ozhcd->ports[port_id-1].status); |
Peter Senna Tschudin | a3c9719 | 2014-05-20 12:33:47 +0200 | [diff] [blame] | 2068 | return 0; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2069 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 2070 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2071 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2072 | * Context: process |
| 2073 | */ |
| 2074 | static int oz_get_port_status(struct usb_hcd *hcd, u16 windex, char *buf) |
| 2075 | { |
| 2076 | struct oz_hcd *ozhcd; |
Rupesh Gujare | a15e042 | 2013-08-13 18:29:24 +0100 | [diff] [blame] | 2077 | u32 status; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 2078 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2079 | if ((windex < 1) || (windex > OZ_NB_PORTS)) |
| 2080 | return -EPIPE; |
| 2081 | ozhcd = oz_hcd_private(hcd); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2082 | oz_dbg(HUB, "GetPortStatus windex = %d\n", windex); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2083 | status = ozhcd->ports[windex-1].status; |
| 2084 | put_unaligned(cpu_to_le32(status), (__le32 *)buf); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2085 | oz_dbg(HUB, "Port[%d] status = %x\n", windex, status); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2086 | return 0; |
| 2087 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 2088 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2089 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2090 | * Context: process |
| 2091 | */ |
| 2092 | static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue, |
| 2093 | u16 windex, char *buf, u16 wlength) |
| 2094 | { |
| 2095 | int err = 0; |
Joe Perches | 30f1e5a | 2013-07-23 13:44:59 +0100 | [diff] [blame] | 2096 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2097 | switch (req_type) { |
| 2098 | case ClearHubFeature: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2099 | oz_dbg(HUB, "ClearHubFeature: %d\n", req_type); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2100 | break; |
| 2101 | case ClearPortFeature: |
| 2102 | err = oz_clear_port_feature(hcd, wvalue, windex); |
| 2103 | break; |
| 2104 | case GetHubDescriptor: |
| 2105 | oz_get_hub_descriptor(hcd, (struct usb_hub_descriptor *)buf); |
| 2106 | break; |
| 2107 | case GetHubStatus: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2108 | oz_dbg(HUB, "GetHubStatus: req_type = 0x%x\n", req_type); |
Jérôme Pinot | c632824 | 2014-03-13 10:20:55 +0900 | [diff] [blame] | 2109 | put_unaligned(cpu_to_le32(0), (__le32 *)buf); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2110 | break; |
| 2111 | case GetPortStatus: |
| 2112 | err = oz_get_port_status(hcd, windex, buf); |
| 2113 | break; |
| 2114 | case SetHubFeature: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2115 | oz_dbg(HUB, "SetHubFeature: %d\n", req_type); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2116 | break; |
| 2117 | case SetPortFeature: |
| 2118 | err = oz_set_port_feature(hcd, wvalue, windex); |
| 2119 | break; |
| 2120 | default: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2121 | oz_dbg(HUB, "Other: %d\n", req_type); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2122 | break; |
| 2123 | } |
| 2124 | return err; |
| 2125 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 2126 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2127 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2128 | * Context: process |
| 2129 | */ |
| 2130 | static int oz_hcd_bus_suspend(struct usb_hcd *hcd) |
| 2131 | { |
| 2132 | struct oz_hcd *ozhcd; |
Joe Perches | 30f1e5a | 2013-07-23 13:44:59 +0100 | [diff] [blame] | 2133 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2134 | ozhcd = oz_hcd_private(hcd); |
| 2135 | spin_lock_bh(&ozhcd->hcd_lock); |
| 2136 | hcd->state = HC_STATE_SUSPENDED; |
| 2137 | ozhcd->flags |= OZ_HDC_F_SUSPENDED; |
| 2138 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 2139 | return 0; |
| 2140 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 2141 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2142 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2143 | * Context: process |
| 2144 | */ |
| 2145 | static int oz_hcd_bus_resume(struct usb_hcd *hcd) |
| 2146 | { |
| 2147 | struct oz_hcd *ozhcd; |
Joe Perches | 30f1e5a | 2013-07-23 13:44:59 +0100 | [diff] [blame] | 2148 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2149 | ozhcd = oz_hcd_private(hcd); |
| 2150 | spin_lock_bh(&ozhcd->hcd_lock); |
| 2151 | ozhcd->flags &= ~OZ_HDC_F_SUSPENDED; |
| 2152 | hcd->state = HC_STATE_RUNNING; |
| 2153 | spin_unlock_bh(&ozhcd->hcd_lock); |
| 2154 | return 0; |
| 2155 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 2156 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2157 | static void oz_plat_shutdown(struct platform_device *dev) |
| 2158 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2159 | } |
Joe Perches | 30f1e5a | 2013-07-23 13:44:59 +0100 | [diff] [blame] | 2160 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2161 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2162 | * Context: process |
| 2163 | */ |
| 2164 | static int oz_plat_probe(struct platform_device *dev) |
| 2165 | { |
| 2166 | int i; |
| 2167 | int err; |
| 2168 | struct usb_hcd *hcd; |
| 2169 | struct oz_hcd *ozhcd; |
Joe Perches | 30f1e5a | 2013-07-23 13:44:59 +0100 | [diff] [blame] | 2170 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2171 | hcd = usb_create_hcd(&g_oz_hc_drv, &dev->dev, dev_name(&dev->dev)); |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 2172 | if (hcd == NULL) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2173 | oz_dbg(ON, "Failed to created hcd object OK\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2174 | return -ENOMEM; |
| 2175 | } |
| 2176 | ozhcd = oz_hcd_private(hcd); |
| 2177 | memset(ozhcd, 0, sizeof(*ozhcd)); |
| 2178 | INIT_LIST_HEAD(&ozhcd->urb_pending_list); |
| 2179 | INIT_LIST_HEAD(&ozhcd->urb_cancel_list); |
| 2180 | INIT_LIST_HEAD(&ozhcd->orphanage); |
| 2181 | ozhcd->hcd = hcd; |
| 2182 | ozhcd->conn_port = -1; |
| 2183 | spin_lock_init(&ozhcd->hcd_lock); |
| 2184 | for (i = 0; i < OZ_NB_PORTS; i++) { |
| 2185 | struct oz_port *port = &ozhcd->ports[i]; |
James A Shackleford | ba91080 | 2014-05-21 14:50:26 -0400 | [diff] [blame] | 2186 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2187 | port->ozhcd = ozhcd; |
| 2188 | port->flags = 0; |
| 2189 | port->status = 0; |
| 2190 | port->bus_addr = 0xff; |
| 2191 | spin_lock_init(&port->port_lock); |
| 2192 | } |
| 2193 | err = usb_add_hcd(hcd, 0, 0); |
| 2194 | if (err) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2195 | oz_dbg(ON, "Failed to add hcd object OK\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2196 | usb_put_hcd(hcd); |
| 2197 | return -1; |
| 2198 | } |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 2199 | device_wakeup_enable(hcd->self.controller); |
| 2200 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2201 | spin_lock_bh(&g_hcdlock); |
| 2202 | g_ozhcd = ozhcd; |
| 2203 | spin_unlock_bh(&g_hcdlock); |
| 2204 | return 0; |
| 2205 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 2206 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2207 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2208 | * Context: unknown |
| 2209 | */ |
| 2210 | static int oz_plat_remove(struct platform_device *dev) |
| 2211 | { |
| 2212 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
| 2213 | struct oz_hcd *ozhcd; |
Joe Perches | 30f1e5a | 2013-07-23 13:44:59 +0100 | [diff] [blame] | 2214 | |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 2215 | if (hcd == NULL) |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2216 | return -1; |
| 2217 | ozhcd = oz_hcd_private(hcd); |
| 2218 | spin_lock_bh(&g_hcdlock); |
| 2219 | if (ozhcd == g_ozhcd) |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 2220 | g_ozhcd = NULL; |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2221 | spin_unlock_bh(&g_hcdlock); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2222 | oz_dbg(ON, "Clearing orphanage\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2223 | oz_hcd_clear_orphanage(ozhcd, -EPIPE); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2224 | oz_dbg(ON, "Removing hcd\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2225 | usb_remove_hcd(hcd); |
| 2226 | usb_put_hcd(hcd); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2227 | return 0; |
| 2228 | } |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2229 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2230 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2231 | * Context: unknown |
| 2232 | */ |
| 2233 | static int oz_plat_suspend(struct platform_device *dev, pm_message_t msg) |
| 2234 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2235 | return 0; |
| 2236 | } |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2237 | |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 2238 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2239 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2240 | * Context: unknown |
| 2241 | */ |
| 2242 | static int oz_plat_resume(struct platform_device *dev) |
| 2243 | { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2244 | return 0; |
| 2245 | } |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2246 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2247 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2248 | * Context: process |
| 2249 | */ |
| 2250 | int oz_hcd_init(void) |
| 2251 | { |
| 2252 | int err; |
Rupesh Gujare | 18f8191 | 2013-08-13 18:24:21 +0100 | [diff] [blame] | 2253 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2254 | if (usb_disabled()) |
| 2255 | return -ENODEV; |
Christoph Jaeger | 9e6fbdd | 2014-08-08 07:59:24 +0200 | [diff] [blame] | 2256 | |
| 2257 | oz_urb_link_cache = KMEM_CACHE(oz_urb_link, 0); |
| 2258 | if (!oz_urb_link_cache) |
| 2259 | return -ENOMEM; |
| 2260 | |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2261 | tasklet_init(&g_urb_process_tasklet, oz_urb_process_tasklet, 0); |
| 2262 | tasklet_init(&g_urb_cancel_tasklet, oz_urb_cancel_tasklet, 0); |
| 2263 | err = platform_driver_register(&g_oz_plat_drv); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2264 | oz_dbg(ON, "platform_driver_register() returned %d\n", err); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2265 | if (err) |
| 2266 | goto error; |
| 2267 | g_plat_dev = platform_device_alloc(OZ_PLAT_DEV_NAME, -1); |
Peter Huewe | 7be7d6d | 2013-02-15 15:22:28 +0100 | [diff] [blame] | 2268 | if (g_plat_dev == NULL) { |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2269 | err = -ENOMEM; |
| 2270 | goto error1; |
| 2271 | } |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2272 | oz_dbg(ON, "platform_device_alloc() succeeded\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2273 | err = platform_device_add(g_plat_dev); |
| 2274 | if (err) |
| 2275 | goto error2; |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2276 | oz_dbg(ON, "platform_device_add() succeeded\n"); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2277 | return 0; |
| 2278 | error2: |
| 2279 | platform_device_put(g_plat_dev); |
| 2280 | error1: |
| 2281 | platform_driver_unregister(&g_oz_plat_drv); |
| 2282 | error: |
| 2283 | tasklet_disable(&g_urb_process_tasklet); |
| 2284 | tasklet_disable(&g_urb_cancel_tasklet); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2285 | oz_dbg(ON, "oz_hcd_init() failed %d\n", err); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2286 | return err; |
| 2287 | } |
Rupesh Gujare | 6e244a8 | 2013-08-13 18:24:22 +0100 | [diff] [blame] | 2288 | |
Rupesh Gujare | 4e7fb82 | 2013-08-23 16:11:02 +0100 | [diff] [blame] | 2289 | /* |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2290 | * Context: process |
| 2291 | */ |
| 2292 | void oz_hcd_term(void) |
| 2293 | { |
Rupesh Gujare | 0140eb2 | 2013-08-27 16:53:42 +0100 | [diff] [blame] | 2294 | msleep(OZ_HUB_DEBOUNCE_TIMEOUT); |
Xiaotian Feng | 984a4a0 | 2012-10-31 18:56:48 +0800 | [diff] [blame] | 2295 | tasklet_kill(&g_urb_process_tasklet); |
| 2296 | tasklet_kill(&g_urb_cancel_tasklet); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2297 | platform_device_unregister(g_plat_dev); |
| 2298 | platform_driver_unregister(&g_oz_plat_drv); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 2299 | oz_dbg(ON, "Pending urbs:%d\n", atomic_read(&g_pending_urbs)); |
Christoph Jaeger | 9e6fbdd | 2014-08-08 07:59:24 +0200 | [diff] [blame] | 2300 | kmem_cache_destroy(oz_urb_link_cache); |
Chris Kelly | ae92605 | 2012-02-20 21:11:53 +0000 | [diff] [blame] | 2301 | } |