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