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