Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
Ido Shayevitz | 909ed38 | 2013-02-15 02:25:35 +0200 | [diff] [blame] | 2 | * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 17 | #include <linux/spinlock.h> |
| 18 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 19 | #include <mach/usb_gadget_xport.h> |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 20 | #include <mach/usb_bam.h> |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 21 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | #include "u_rmnet.h" |
| 23 | #include "gadget_chips.h" |
| 24 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | #define RMNET_NOTIFY_INTERVAL 5 |
| 26 | #define RMNET_MAX_NOTIFY_SIZE sizeof(struct usb_cdc_notification) |
| 27 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | |
| 29 | #define ACM_CTRL_DTR (1 << 0) |
| 30 | |
| 31 | /* TODO: use separate structures for data and |
| 32 | * control paths |
| 33 | */ |
| 34 | struct f_rmnet { |
| 35 | struct grmnet port; |
| 36 | int ifc_id; |
| 37 | u8 port_num; |
| 38 | atomic_t online; |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 39 | atomic_t ctrl_online; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 40 | struct usb_composite_dev *cdev; |
| 41 | |
| 42 | spinlock_t lock; |
| 43 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | /* usb eps*/ |
| 45 | struct usb_ep *notify; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | struct usb_request *notify_req; |
| 47 | |
| 48 | /* control info */ |
| 49 | struct list_head cpkt_resp_q; |
| 50 | atomic_t notify_count; |
| 51 | unsigned long cpkts_len; |
| 52 | }; |
| 53 | |
Anna Perel | 2151516 | 2012-02-02 20:50:02 +0200 | [diff] [blame] | 54 | #define NR_RMNET_PORTS 3 |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 55 | static unsigned int nr_rmnet_ports; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 56 | static unsigned int no_ctrl_smd_ports; |
Bar Weiner | 0dae81b | 2013-02-14 13:53:54 +0200 | [diff] [blame] | 57 | static unsigned int no_ctrl_qti_ports; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 58 | static unsigned int no_ctrl_hsic_ports; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 59 | static unsigned int no_ctrl_hsuart_ports; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 60 | static unsigned int no_data_bam_ports; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 61 | static unsigned int no_data_bam2bam_ports; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 62 | static unsigned int no_data_hsic_ports; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 63 | static unsigned int no_data_hsuart_ports; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | static struct rmnet_ports { |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 65 | enum transport_type data_xport; |
| 66 | enum transport_type ctrl_xport; |
| 67 | unsigned data_xport_num; |
| 68 | unsigned ctrl_xport_num; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 69 | unsigned port_num; |
| 70 | struct f_rmnet *port; |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 71 | } rmnet_ports[NR_RMNET_PORTS]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 72 | |
| 73 | static struct usb_interface_descriptor rmnet_interface_desc = { |
| 74 | .bLength = USB_DT_INTERFACE_SIZE, |
| 75 | .bDescriptorType = USB_DT_INTERFACE, |
| 76 | .bNumEndpoints = 3, |
| 77 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 78 | .bInterfaceSubClass = USB_CLASS_VENDOR_SPEC, |
| 79 | .bInterfaceProtocol = USB_CLASS_VENDOR_SPEC, |
| 80 | /* .iInterface = DYNAMIC */ |
| 81 | }; |
| 82 | |
| 83 | /* Full speed support */ |
| 84 | static struct usb_endpoint_descriptor rmnet_fs_notify_desc = { |
| 85 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 86 | .bDescriptorType = USB_DT_ENDPOINT, |
| 87 | .bEndpointAddress = USB_DIR_IN, |
| 88 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 89 | .wMaxPacketSize = __constant_cpu_to_le16(RMNET_MAX_NOTIFY_SIZE), |
| 90 | .bInterval = 1 << RMNET_NOTIFY_INTERVAL, |
| 91 | }; |
| 92 | |
| 93 | static struct usb_endpoint_descriptor rmnet_fs_in_desc = { |
| 94 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 95 | .bDescriptorType = USB_DT_ENDPOINT, |
| 96 | .bEndpointAddress = USB_DIR_IN, |
| 97 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
| 98 | .wMaxPacketSize = __constant_cpu_to_le16(64), |
| 99 | }; |
| 100 | |
| 101 | static struct usb_endpoint_descriptor rmnet_fs_out_desc = { |
| 102 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 103 | .bDescriptorType = USB_DT_ENDPOINT, |
| 104 | .bEndpointAddress = USB_DIR_OUT, |
| 105 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
| 106 | .wMaxPacketSize = __constant_cpu_to_le16(64), |
| 107 | }; |
| 108 | |
| 109 | static struct usb_descriptor_header *rmnet_fs_function[] = { |
| 110 | (struct usb_descriptor_header *) &rmnet_interface_desc, |
| 111 | (struct usb_descriptor_header *) &rmnet_fs_notify_desc, |
| 112 | (struct usb_descriptor_header *) &rmnet_fs_in_desc, |
| 113 | (struct usb_descriptor_header *) &rmnet_fs_out_desc, |
| 114 | NULL, |
| 115 | }; |
| 116 | |
| 117 | /* High speed support */ |
| 118 | static struct usb_endpoint_descriptor rmnet_hs_notify_desc = { |
| 119 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 120 | .bDescriptorType = USB_DT_ENDPOINT, |
| 121 | .bEndpointAddress = USB_DIR_IN, |
| 122 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 123 | .wMaxPacketSize = __constant_cpu_to_le16(RMNET_MAX_NOTIFY_SIZE), |
| 124 | .bInterval = RMNET_NOTIFY_INTERVAL + 4, |
| 125 | }; |
| 126 | |
| 127 | static struct usb_endpoint_descriptor rmnet_hs_in_desc = { |
| 128 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 129 | .bDescriptorType = USB_DT_ENDPOINT, |
| 130 | .bEndpointAddress = USB_DIR_IN, |
| 131 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
| 132 | .wMaxPacketSize = __constant_cpu_to_le16(512), |
| 133 | }; |
| 134 | |
| 135 | static struct usb_endpoint_descriptor rmnet_hs_out_desc = { |
| 136 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 137 | .bDescriptorType = USB_DT_ENDPOINT, |
| 138 | .bEndpointAddress = USB_DIR_OUT, |
| 139 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
| 140 | .wMaxPacketSize = __constant_cpu_to_le16(512), |
| 141 | }; |
| 142 | |
| 143 | static struct usb_descriptor_header *rmnet_hs_function[] = { |
| 144 | (struct usb_descriptor_header *) &rmnet_interface_desc, |
| 145 | (struct usb_descriptor_header *) &rmnet_hs_notify_desc, |
| 146 | (struct usb_descriptor_header *) &rmnet_hs_in_desc, |
| 147 | (struct usb_descriptor_header *) &rmnet_hs_out_desc, |
| 148 | NULL, |
| 149 | }; |
| 150 | |
Pavankumar Kondeti | 6f94bc9 | 2012-08-03 09:34:32 +0530 | [diff] [blame] | 151 | /* Super speed support */ |
| 152 | static struct usb_endpoint_descriptor rmnet_ss_notify_desc = { |
Vijayavardhan Vennapusa | 724ae31 | 2012-11-20 17:36:21 +0530 | [diff] [blame] | 153 | .bLength = USB_DT_ENDPOINT_SIZE, |
Pavankumar Kondeti | 6f94bc9 | 2012-08-03 09:34:32 +0530 | [diff] [blame] | 154 | .bDescriptorType = USB_DT_ENDPOINT, |
| 155 | .bEndpointAddress = USB_DIR_IN, |
| 156 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 157 | .wMaxPacketSize = __constant_cpu_to_le16(RMNET_MAX_NOTIFY_SIZE), |
| 158 | .bInterval = RMNET_NOTIFY_INTERVAL + 4, |
| 159 | }; |
| 160 | |
| 161 | static struct usb_ss_ep_comp_descriptor rmnet_ss_notify_comp_desc = { |
| 162 | .bLength = sizeof rmnet_ss_notify_comp_desc, |
| 163 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
| 164 | |
| 165 | /* the following 3 values can be tweaked if necessary */ |
| 166 | /* .bMaxBurst = 0, */ |
| 167 | /* .bmAttributes = 0, */ |
| 168 | .wBytesPerInterval = cpu_to_le16(RMNET_MAX_NOTIFY_SIZE), |
| 169 | }; |
| 170 | |
| 171 | static struct usb_endpoint_descriptor rmnet_ss_in_desc = { |
Vijayavardhan Vennapusa | 724ae31 | 2012-11-20 17:36:21 +0530 | [diff] [blame] | 172 | .bLength = USB_DT_ENDPOINT_SIZE, |
Pavankumar Kondeti | 6f94bc9 | 2012-08-03 09:34:32 +0530 | [diff] [blame] | 173 | .bDescriptorType = USB_DT_ENDPOINT, |
| 174 | .bEndpointAddress = USB_DIR_IN, |
| 175 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
| 176 | .wMaxPacketSize = __constant_cpu_to_le16(1024), |
| 177 | }; |
| 178 | |
| 179 | static struct usb_ss_ep_comp_descriptor rmnet_ss_in_comp_desc = { |
| 180 | .bLength = sizeof rmnet_ss_in_comp_desc, |
| 181 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
| 182 | |
| 183 | /* the following 2 values can be tweaked if necessary */ |
| 184 | /* .bMaxBurst = 0, */ |
| 185 | /* .bmAttributes = 0, */ |
| 186 | }; |
| 187 | |
| 188 | static struct usb_endpoint_descriptor rmnet_ss_out_desc = { |
Vijayavardhan Vennapusa | 724ae31 | 2012-11-20 17:36:21 +0530 | [diff] [blame] | 189 | .bLength = USB_DT_ENDPOINT_SIZE, |
Pavankumar Kondeti | 6f94bc9 | 2012-08-03 09:34:32 +0530 | [diff] [blame] | 190 | .bDescriptorType = USB_DT_ENDPOINT, |
| 191 | .bEndpointAddress = USB_DIR_OUT, |
| 192 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
| 193 | .wMaxPacketSize = __constant_cpu_to_le16(1024), |
| 194 | }; |
| 195 | |
| 196 | static struct usb_ss_ep_comp_descriptor rmnet_ss_out_comp_desc = { |
| 197 | .bLength = sizeof rmnet_ss_out_comp_desc, |
| 198 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
| 199 | |
| 200 | /* the following 2 values can be tweaked if necessary */ |
| 201 | /* .bMaxBurst = 0, */ |
| 202 | /* .bmAttributes = 0, */ |
| 203 | }; |
| 204 | |
| 205 | static struct usb_descriptor_header *rmnet_ss_function[] = { |
| 206 | (struct usb_descriptor_header *) &rmnet_interface_desc, |
| 207 | (struct usb_descriptor_header *) &rmnet_ss_notify_desc, |
| 208 | (struct usb_descriptor_header *) &rmnet_ss_notify_comp_desc, |
| 209 | (struct usb_descriptor_header *) &rmnet_ss_in_desc, |
| 210 | (struct usb_descriptor_header *) &rmnet_ss_in_comp_desc, |
| 211 | (struct usb_descriptor_header *) &rmnet_ss_out_desc, |
| 212 | (struct usb_descriptor_header *) &rmnet_ss_out_comp_desc, |
| 213 | NULL, |
| 214 | }; |
| 215 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 216 | /* String descriptors */ |
| 217 | |
| 218 | static struct usb_string rmnet_string_defs[] = { |
| 219 | [0].s = "RmNet", |
| 220 | { } /* end of list */ |
| 221 | }; |
| 222 | |
| 223 | static struct usb_gadget_strings rmnet_string_table = { |
| 224 | .language = 0x0409, /* en-us */ |
| 225 | .strings = rmnet_string_defs, |
| 226 | }; |
| 227 | |
| 228 | static struct usb_gadget_strings *rmnet_strings[] = { |
| 229 | &rmnet_string_table, |
| 230 | NULL, |
| 231 | }; |
| 232 | |
Amit Blay | 2d4fb63 | 2012-05-29 18:05:38 +0300 | [diff] [blame] | 233 | static void frmnet_ctrl_response_available(struct f_rmnet *dev); |
| 234 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 235 | /* ------- misc functions --------------------*/ |
| 236 | |
| 237 | static inline struct f_rmnet *func_to_rmnet(struct usb_function *f) |
| 238 | { |
| 239 | return container_of(f, struct f_rmnet, port.func); |
| 240 | } |
| 241 | |
| 242 | static inline struct f_rmnet *port_to_rmnet(struct grmnet *r) |
| 243 | { |
| 244 | return container_of(r, struct f_rmnet, port); |
| 245 | } |
| 246 | |
| 247 | static struct usb_request * |
| 248 | frmnet_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags) |
| 249 | { |
| 250 | struct usb_request *req; |
| 251 | |
| 252 | req = usb_ep_alloc_request(ep, flags); |
| 253 | if (!req) |
| 254 | return ERR_PTR(-ENOMEM); |
| 255 | |
| 256 | req->buf = kmalloc(len, flags); |
| 257 | if (!req->buf) { |
| 258 | usb_ep_free_request(ep, req); |
| 259 | return ERR_PTR(-ENOMEM); |
| 260 | } |
| 261 | |
| 262 | req->length = len; |
| 263 | |
| 264 | return req; |
| 265 | } |
| 266 | |
| 267 | void frmnet_free_req(struct usb_ep *ep, struct usb_request *req) |
| 268 | { |
| 269 | kfree(req->buf); |
| 270 | usb_ep_free_request(ep, req); |
| 271 | } |
| 272 | |
| 273 | static struct rmnet_ctrl_pkt *rmnet_alloc_ctrl_pkt(unsigned len, gfp_t flags) |
| 274 | { |
| 275 | struct rmnet_ctrl_pkt *pkt; |
| 276 | |
| 277 | pkt = kzalloc(sizeof(struct rmnet_ctrl_pkt), flags); |
| 278 | if (!pkt) |
| 279 | return ERR_PTR(-ENOMEM); |
| 280 | |
| 281 | pkt->buf = kmalloc(len, flags); |
| 282 | if (!pkt->buf) { |
| 283 | kfree(pkt); |
| 284 | return ERR_PTR(-ENOMEM); |
| 285 | } |
| 286 | pkt->len = len; |
| 287 | |
| 288 | return pkt; |
| 289 | } |
| 290 | |
| 291 | static void rmnet_free_ctrl_pkt(struct rmnet_ctrl_pkt *pkt) |
| 292 | { |
| 293 | kfree(pkt->buf); |
| 294 | kfree(pkt); |
| 295 | } |
| 296 | |
| 297 | /* -------------------------------------------*/ |
| 298 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 299 | static int rmnet_gport_setup(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 300 | { |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 301 | int ret; |
| 302 | int port_idx; |
| 303 | int i; |
Bar Weiner | 6c817eb | 2013-04-15 20:52:18 +0300 | [diff] [blame] | 304 | u8 base; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 305 | |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 306 | pr_debug("%s: bam ports: %u bam2bam ports: %u data hsic ports: %u data hsuart ports: %u" |
| 307 | " smd ports: %u ctrl hsic ports: %u ctrl hsuart ports: %u" |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 308 | " nr_rmnet_ports: %u\n", |
| 309 | __func__, no_data_bam_ports, no_data_bam2bam_ports, |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 310 | no_data_hsic_ports, no_data_hsuart_ports, no_ctrl_smd_ports, |
| 311 | no_ctrl_hsic_ports, no_ctrl_hsuart_ports, nr_rmnet_ports); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 312 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 313 | if (no_data_bam_ports || no_data_bam2bam_ports) { |
| 314 | ret = gbam_setup(no_data_bam_ports, |
| 315 | no_data_bam2bam_ports); |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 316 | if (ret) |
| 317 | return ret; |
| 318 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 319 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 320 | if (no_ctrl_smd_ports) { |
Bar Weiner | 6c817eb | 2013-04-15 20:52:18 +0300 | [diff] [blame] | 321 | ret = gsmd_ctrl_setup(FRMNET_CTRL_CLIENT, |
| 322 | no_ctrl_smd_ports, &base); |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 323 | if (ret) |
| 324 | return ret; |
Bar Weiner | 6c817eb | 2013-04-15 20:52:18 +0300 | [diff] [blame] | 325 | for (i = 0; i < nr_rmnet_ports; i++) |
| 326 | if (rmnet_ports[i].port) |
| 327 | rmnet_ports[i].port->port_num += base; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 328 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 329 | |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 330 | if (no_data_hsic_ports) { |
| 331 | port_idx = ghsic_data_setup(no_data_hsic_ports, |
| 332 | USB_GADGET_RMNET); |
| 333 | if (port_idx < 0) |
| 334 | return port_idx; |
| 335 | for (i = 0; i < nr_rmnet_ports; i++) { |
| 336 | if (rmnet_ports[i].data_xport == |
| 337 | USB_GADGET_XPORT_HSIC) { |
| 338 | rmnet_ports[i].data_xport_num = port_idx; |
| 339 | port_idx++; |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | if (no_ctrl_hsic_ports) { |
| 345 | port_idx = ghsic_ctrl_setup(no_ctrl_hsic_ports, |
| 346 | USB_GADGET_RMNET); |
| 347 | if (port_idx < 0) |
| 348 | return port_idx; |
| 349 | for (i = 0; i < nr_rmnet_ports; i++) { |
| 350 | if (rmnet_ports[i].ctrl_xport == |
| 351 | USB_GADGET_XPORT_HSIC) { |
| 352 | rmnet_ports[i].ctrl_xport_num = port_idx; |
| 353 | port_idx++; |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 358 | if (no_data_hsuart_ports) { |
| 359 | port_idx = ghsuart_data_setup(no_data_hsuart_ports, |
| 360 | USB_GADGET_RMNET); |
| 361 | if (port_idx < 0) |
| 362 | return port_idx; |
| 363 | for (i = 0; i < nr_rmnet_ports; i++) { |
| 364 | if (rmnet_ports[i].data_xport == |
| 365 | USB_GADGET_XPORT_HSUART) { |
| 366 | rmnet_ports[i].data_xport_num = port_idx; |
| 367 | port_idx++; |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | if (no_ctrl_hsuart_ports) { |
| 373 | port_idx = ghsuart_ctrl_setup(no_ctrl_hsuart_ports, |
| 374 | USB_GADGET_RMNET); |
| 375 | if (port_idx < 0) |
| 376 | return port_idx; |
| 377 | for (i = 0; i < nr_rmnet_ports; i++) { |
| 378 | if (rmnet_ports[i].ctrl_xport == |
| 379 | USB_GADGET_XPORT_HSUART) { |
| 380 | rmnet_ports[i].ctrl_xport_num = port_idx; |
| 381 | port_idx++; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 386 | return 0; |
| 387 | } |
| 388 | |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 389 | static int gport_rmnet_connect(struct f_rmnet *dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 390 | { |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 391 | int ret; |
| 392 | unsigned port_num; |
| 393 | enum transport_type cxport = rmnet_ports[dev->port_num].ctrl_xport; |
| 394 | enum transport_type dxport = rmnet_ports[dev->port_num].data_xport; |
Vijayavardhan Vennapusa | 768dfc0 | 2013-03-27 18:40:08 +0530 | [diff] [blame] | 395 | int src_connection_idx = 0, dst_connection_idx = 0; |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 396 | struct usb_gadget *gadget = dev->cdev->gadget; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 397 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 398 | pr_debug("%s: ctrl xport: %s data xport: %s dev: %p portno: %d\n", |
| 399 | __func__, xport_to_str(cxport), xport_to_str(dxport), |
| 400 | dev, dev->port_num); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 401 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 402 | port_num = rmnet_ports[dev->port_num].ctrl_xport_num; |
| 403 | switch (cxport) { |
| 404 | case USB_GADGET_XPORT_SMD: |
| 405 | ret = gsmd_ctrl_connect(&dev->port, port_num); |
| 406 | if (ret) { |
| 407 | pr_err("%s: gsmd_ctrl_connect failed: err:%d\n", |
| 408 | __func__, ret); |
| 409 | return ret; |
| 410 | } |
| 411 | break; |
Bar Weiner | 0dae81b | 2013-02-14 13:53:54 +0200 | [diff] [blame] | 412 | case USB_GADGET_XPORT_QTI: |
| 413 | ret = gqti_ctrl_connect(&dev->port); |
| 414 | if (ret) { |
| 415 | pr_err("%s: gqti_ctrl_connect failed: err:%d\n", |
| 416 | __func__, ret); |
| 417 | return ret; |
| 418 | } |
| 419 | break; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 420 | case USB_GADGET_XPORT_HSIC: |
| 421 | ret = ghsic_ctrl_connect(&dev->port, port_num); |
| 422 | if (ret) { |
| 423 | pr_err("%s: ghsic_ctrl_connect failed: err:%d\n", |
| 424 | __func__, ret); |
| 425 | return ret; |
| 426 | } |
| 427 | break; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 428 | case USB_GADGET_XPORT_HSUART: |
| 429 | ret = ghsuart_ctrl_connect(&dev->port, port_num); |
| 430 | if (ret) { |
| 431 | pr_err("%s: ghsuart_ctrl_connect failed: err:%d\n", |
| 432 | __func__, ret); |
| 433 | return ret; |
| 434 | } |
| 435 | break; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 436 | case USB_GADGET_XPORT_NONE: |
| 437 | break; |
| 438 | default: |
| 439 | pr_err("%s: Un-supported transport: %s\n", __func__, |
| 440 | xport_to_str(cxport)); |
| 441 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 444 | port_num = rmnet_ports[dev->port_num].data_xport_num; |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 445 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 446 | switch (dxport) { |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 447 | case USB_GADGET_XPORT_BAM2BAM: |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 448 | src_connection_idx = usb_bam_get_connection_idx(gadget->name, |
| 449 | A2_P_BAM, USB_TO_PEER_PERIPHERAL, port_num); |
| 450 | dst_connection_idx = usb_bam_get_connection_idx(gadget->name, |
| 451 | A2_P_BAM, PEER_PERIPHERAL_TO_USB, port_num); |
| 452 | if (dst_connection_idx < 0 || src_connection_idx < 0) { |
| 453 | pr_err("%s: usb_bam_get_connection_idx failed\n", |
| 454 | __func__); |
| 455 | gsmd_ctrl_disconnect(&dev->port, port_num); |
| 456 | return ret; |
| 457 | } |
Vijayavardhan Vennapusa | 768dfc0 | 2013-03-27 18:40:08 +0530 | [diff] [blame] | 458 | case USB_GADGET_XPORT_BAM: |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 459 | ret = gbam_connect(&dev->port, port_num, |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 460 | dxport, src_connection_idx, dst_connection_idx); |
| 461 | if (ret) { |
| 462 | pr_err("%s: gbam_connect failed: err:%d\n", |
| 463 | __func__, ret); |
| 464 | gsmd_ctrl_disconnect(&dev->port, port_num); |
| 465 | return ret; |
| 466 | } |
| 467 | break; |
| 468 | case USB_GADGET_XPORT_BAM2BAM_IPA: |
| 469 | src_connection_idx = usb_bam_get_connection_idx(gadget->name, |
| 470 | IPA_P_BAM, USB_TO_PEER_PERIPHERAL, port_num); |
| 471 | dst_connection_idx = usb_bam_get_connection_idx(gadget->name, |
| 472 | IPA_P_BAM, PEER_PERIPHERAL_TO_USB, port_num); |
| 473 | if (dst_connection_idx < 0 || src_connection_idx < 0) { |
| 474 | pr_err("%s: usb_bam_get_connection_idx failed\n", |
| 475 | __func__); |
| 476 | gsmd_ctrl_disconnect(&dev->port, port_num); |
| 477 | return ret; |
| 478 | } |
| 479 | ret = gbam_connect(&dev->port, port_num, |
| 480 | dxport, src_connection_idx, dst_connection_idx); |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 481 | if (ret) { |
| 482 | pr_err("%s: gbam_connect failed: err:%d\n", |
| 483 | __func__, ret); |
Bar Weiner | 0dae81b | 2013-02-14 13:53:54 +0200 | [diff] [blame] | 484 | if (cxport == USB_GADGET_XPORT_QTI) |
| 485 | gqti_ctrl_disconnect(&dev->port); |
| 486 | else |
| 487 | gsmd_ctrl_disconnect(&dev->port, port_num); |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 488 | return ret; |
| 489 | } |
| 490 | break; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 491 | case USB_GADGET_XPORT_HSIC: |
| 492 | ret = ghsic_data_connect(&dev->port, port_num); |
| 493 | if (ret) { |
| 494 | pr_err("%s: ghsic_data_connect failed: err:%d\n", |
| 495 | __func__, ret); |
| 496 | ghsic_ctrl_disconnect(&dev->port, port_num); |
| 497 | return ret; |
| 498 | } |
| 499 | break; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 500 | case USB_GADGET_XPORT_HSUART: |
| 501 | ret = ghsuart_data_connect(&dev->port, port_num); |
| 502 | if (ret) { |
| 503 | pr_err("%s: ghsuart_data_connect failed: err:%d\n", |
| 504 | __func__, ret); |
| 505 | ghsuart_ctrl_disconnect(&dev->port, port_num); |
| 506 | return ret; |
| 507 | } |
| 508 | break; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 509 | case USB_GADGET_XPORT_NONE: |
| 510 | break; |
| 511 | default: |
| 512 | pr_err("%s: Un-supported transport: %s\n", __func__, |
| 513 | xport_to_str(dxport)); |
| 514 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 520 | static int gport_rmnet_disconnect(struct f_rmnet *dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 521 | { |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 522 | unsigned port_num; |
| 523 | enum transport_type cxport = rmnet_ports[dev->port_num].ctrl_xport; |
| 524 | enum transport_type dxport = rmnet_ports[dev->port_num].data_xport; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 525 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 526 | pr_debug("%s: ctrl xport: %s data xport: %s dev: %p portno: %d\n", |
| 527 | __func__, xport_to_str(cxport), xport_to_str(dxport), |
| 528 | dev, dev->port_num); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 529 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 530 | port_num = rmnet_ports[dev->port_num].ctrl_xport_num; |
| 531 | switch (cxport) { |
| 532 | case USB_GADGET_XPORT_SMD: |
| 533 | gsmd_ctrl_disconnect(&dev->port, port_num); |
| 534 | break; |
Bar Weiner | 0dae81b | 2013-02-14 13:53:54 +0200 | [diff] [blame] | 535 | case USB_GADGET_XPORT_QTI: |
| 536 | gqti_ctrl_disconnect(&dev->port); |
| 537 | break; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 538 | case USB_GADGET_XPORT_HSIC: |
| 539 | ghsic_ctrl_disconnect(&dev->port, port_num); |
| 540 | break; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 541 | case USB_GADGET_XPORT_HSUART: |
| 542 | ghsuart_ctrl_disconnect(&dev->port, port_num); |
| 543 | break; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 544 | case USB_GADGET_XPORT_NONE: |
| 545 | break; |
| 546 | default: |
| 547 | pr_err("%s: Un-supported transport: %s\n", __func__, |
| 548 | xport_to_str(cxport)); |
| 549 | return -ENODEV; |
| 550 | } |
| 551 | |
| 552 | port_num = rmnet_ports[dev->port_num].data_xport_num; |
| 553 | switch (dxport) { |
| 554 | case USB_GADGET_XPORT_BAM: |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 555 | case USB_GADGET_XPORT_BAM2BAM: |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 556 | case USB_GADGET_XPORT_BAM2BAM_IPA: |
Ofir Cohen | 77848d6 | 2012-12-05 13:16:10 +0200 | [diff] [blame] | 557 | gbam_disconnect(&dev->port, port_num, dxport); |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 558 | break; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 559 | case USB_GADGET_XPORT_HSIC: |
| 560 | ghsic_data_disconnect(&dev->port, port_num); |
| 561 | break; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 562 | case USB_GADGET_XPORT_HSUART: |
| 563 | ghsuart_data_disconnect(&dev->port, port_num); |
| 564 | break; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 565 | case USB_GADGET_XPORT_NONE: |
| 566 | break; |
| 567 | default: |
| 568 | pr_err("%s: Un-supported transport: %s\n", __func__, |
| 569 | xport_to_str(dxport)); |
| 570 | return -ENODEV; |
| 571 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 576 | static void frmnet_unbind(struct usb_configuration *c, struct usb_function *f) |
| 577 | { |
| 578 | struct f_rmnet *dev = func_to_rmnet(f); |
| 579 | |
| 580 | pr_debug("%s: portno:%d\n", __func__, dev->port_num); |
| 581 | |
Pavankumar Kondeti | 6f94bc9 | 2012-08-03 09:34:32 +0530 | [diff] [blame] | 582 | if (gadget_is_superspeed(c->cdev->gadget)) |
| 583 | usb_free_descriptors(f->ss_descriptors); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 584 | if (gadget_is_dualspeed(c->cdev->gadget)) |
| 585 | usb_free_descriptors(f->hs_descriptors); |
| 586 | usb_free_descriptors(f->descriptors); |
| 587 | |
| 588 | frmnet_free_req(dev->notify, dev->notify_req); |
| 589 | |
Manu Gautam | dd4222b | 2011-09-09 15:06:05 +0530 | [diff] [blame] | 590 | kfree(f->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Ido Shayevitz | 909ed38 | 2013-02-15 02:25:35 +0200 | [diff] [blame] | 593 | static void frmnet_purge_responses(struct f_rmnet *dev) |
| 594 | { |
| 595 | unsigned long flags; |
| 596 | struct rmnet_ctrl_pkt *cpkt; |
| 597 | |
| 598 | pr_debug("%s: port#%d\n", __func__, dev->port_num); |
| 599 | |
| 600 | spin_lock_irqsave(&dev->lock, flags); |
| 601 | while (!list_empty(&dev->cpkt_resp_q)) { |
| 602 | cpkt = list_first_entry(&dev->cpkt_resp_q, |
| 603 | struct rmnet_ctrl_pkt, list); |
| 604 | |
| 605 | list_del(&cpkt->list); |
| 606 | rmnet_free_ctrl_pkt(cpkt); |
| 607 | } |
| 608 | atomic_set(&dev->notify_count, 0); |
| 609 | spin_unlock_irqrestore(&dev->lock, flags); |
| 610 | } |
| 611 | |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 612 | static void frmnet_suspend(struct usb_function *f) |
| 613 | { |
| 614 | struct f_rmnet *dev = func_to_rmnet(f); |
| 615 | unsigned port_num; |
| 616 | enum transport_type dxport = rmnet_ports[dev->port_num].data_xport; |
| 617 | |
| 618 | pr_debug("%s: data xport: %s dev: %p portno: %d\n", |
| 619 | __func__, xport_to_str(dxport), |
| 620 | dev, dev->port_num); |
| 621 | |
Ido Shayevitz | 909ed38 | 2013-02-15 02:25:35 +0200 | [diff] [blame] | 622 | frmnet_purge_responses(dev); |
| 623 | |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 624 | port_num = rmnet_ports[dev->port_num].data_xport_num; |
| 625 | switch (dxport) { |
| 626 | case USB_GADGET_XPORT_BAM: |
| 627 | break; |
| 628 | case USB_GADGET_XPORT_BAM2BAM: |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 629 | case USB_GADGET_XPORT_BAM2BAM_IPA: |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 630 | gbam_suspend(&dev->port, port_num, dxport); |
| 631 | break; |
| 632 | case USB_GADGET_XPORT_HSIC: |
| 633 | break; |
Mayank Rana | 9dc199a | 2012-08-28 10:22:07 +0530 | [diff] [blame] | 634 | case USB_GADGET_XPORT_HSUART: |
| 635 | break; |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 636 | case USB_GADGET_XPORT_NONE: |
| 637 | break; |
| 638 | default: |
| 639 | pr_err("%s: Un-supported transport: %s\n", __func__, |
| 640 | xport_to_str(dxport)); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | static void frmnet_resume(struct usb_function *f) |
| 645 | { |
| 646 | struct f_rmnet *dev = func_to_rmnet(f); |
| 647 | unsigned port_num; |
| 648 | enum transport_type dxport = rmnet_ports[dev->port_num].data_xport; |
| 649 | |
| 650 | pr_debug("%s: data xport: %s dev: %p portno: %d\n", |
| 651 | __func__, xport_to_str(dxport), |
| 652 | dev, dev->port_num); |
| 653 | |
| 654 | port_num = rmnet_ports[dev->port_num].data_xport_num; |
| 655 | switch (dxport) { |
| 656 | case USB_GADGET_XPORT_BAM: |
| 657 | break; |
| 658 | case USB_GADGET_XPORT_BAM2BAM: |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 659 | case USB_GADGET_XPORT_BAM2BAM_IPA: |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 660 | gbam_resume(&dev->port, port_num, dxport); |
| 661 | break; |
| 662 | case USB_GADGET_XPORT_HSIC: |
| 663 | break; |
Mayank Rana | 9dc199a | 2012-08-28 10:22:07 +0530 | [diff] [blame] | 664 | case USB_GADGET_XPORT_HSUART: |
| 665 | break; |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 666 | case USB_GADGET_XPORT_NONE: |
| 667 | break; |
| 668 | default: |
| 669 | pr_err("%s: Un-supported transport: %s\n", __func__, |
| 670 | xport_to_str(dxport)); |
| 671 | } |
| 672 | } |
| 673 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 674 | static void frmnet_disable(struct usb_function *f) |
| 675 | { |
| 676 | struct f_rmnet *dev = func_to_rmnet(f); |
| 677 | |
| 678 | pr_debug("%s: port#%d\n", __func__, dev->port_num); |
| 679 | |
| 680 | usb_ep_disable(dev->notify); |
Anna Perel | 97b8c22 | 2012-01-18 10:08:14 +0200 | [diff] [blame] | 681 | dev->notify->driver_data = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 682 | |
| 683 | atomic_set(&dev->online, 0); |
| 684 | |
Ido Shayevitz | 909ed38 | 2013-02-15 02:25:35 +0200 | [diff] [blame] | 685 | frmnet_purge_responses(dev); |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 686 | |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 687 | gport_rmnet_disconnect(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | static int |
| 691 | frmnet_set_alt(struct usb_function *f, unsigned intf, unsigned alt) |
| 692 | { |
| 693 | struct f_rmnet *dev = func_to_rmnet(f); |
| 694 | struct usb_composite_dev *cdev = dev->cdev; |
| 695 | int ret; |
Amit Blay | 2d4fb63 | 2012-05-29 18:05:38 +0300 | [diff] [blame] | 696 | struct list_head *cpkt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 697 | |
| 698 | pr_debug("%s:dev:%p port#%d\n", __func__, dev, dev->port_num); |
| 699 | |
| 700 | if (dev->notify->driver_data) { |
| 701 | pr_debug("%s: reset port:%d\n", __func__, dev->port_num); |
| 702 | usb_ep_disable(dev->notify); |
| 703 | } |
Tatyana Brokhman | 31ac352 | 2011-06-28 15:33:50 +0200 | [diff] [blame] | 704 | |
| 705 | ret = config_ep_by_speed(cdev->gadget, f, dev->notify); |
| 706 | if (ret) { |
| 707 | dev->notify->desc = NULL; |
| 708 | ERROR(cdev, "config_ep_by_speed failes for ep %s, result %d\n", |
| 709 | dev->notify->name, ret); |
| 710 | return ret; |
| 711 | } |
Tatyana Brokhman | cf709c1 | 2011-06-28 16:33:48 +0300 | [diff] [blame] | 712 | ret = usb_ep_enable(dev->notify); |
Tatyana Brokhman | 31ac352 | 2011-06-28 15:33:50 +0200 | [diff] [blame] | 713 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 714 | if (ret) { |
| 715 | pr_err("%s: usb ep#%s enable failed, err#%d\n", |
| 716 | __func__, dev->notify->name, ret); |
| 717 | return ret; |
| 718 | } |
| 719 | dev->notify->driver_data = dev; |
| 720 | |
Chiranjeevi Velempati | 502b1c8 | 2012-05-16 14:49:46 +0530 | [diff] [blame] | 721 | if (!dev->port.in->desc || !dev->port.out->desc) { |
Bar Weiner | 0fc137a | 2012-03-28 16:58:09 +0200 | [diff] [blame] | 722 | if (config_ep_by_speed(cdev->gadget, f, dev->port.in) || |
| 723 | config_ep_by_speed(cdev->gadget, f, dev->port.out)) { |
| 724 | dev->port.in->desc = NULL; |
| 725 | dev->port.out->desc = NULL; |
| 726 | return -EINVAL; |
| 727 | } |
| 728 | ret = gport_rmnet_connect(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 731 | atomic_set(&dev->online, 1); |
| 732 | |
Amit Blay | 2d4fb63 | 2012-05-29 18:05:38 +0300 | [diff] [blame] | 733 | /* In case notifications were aborted, but there are pending control |
| 734 | packets in the response queue, re-add the notifications */ |
| 735 | list_for_each(cpkt, &dev->cpkt_resp_q) |
| 736 | frmnet_ctrl_response_available(dev); |
| 737 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 738 | return ret; |
| 739 | } |
| 740 | |
| 741 | static void frmnet_ctrl_response_available(struct f_rmnet *dev) |
| 742 | { |
| 743 | struct usb_request *req = dev->notify_req; |
| 744 | struct usb_cdc_notification *event; |
| 745 | unsigned long flags; |
| 746 | int ret; |
Anna Perel | f3af59d | 2012-08-12 15:28:30 +0300 | [diff] [blame] | 747 | struct rmnet_ctrl_pkt *cpkt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 748 | |
| 749 | pr_debug("%s:dev:%p portno#%d\n", __func__, dev, dev->port_num); |
| 750 | |
| 751 | spin_lock_irqsave(&dev->lock, flags); |
| 752 | if (!atomic_read(&dev->online) || !req || !req->buf) { |
| 753 | spin_unlock_irqrestore(&dev->lock, flags); |
| 754 | return; |
| 755 | } |
| 756 | |
| 757 | if (atomic_inc_return(&dev->notify_count) != 1) { |
| 758 | spin_unlock_irqrestore(&dev->lock, flags); |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | event = req->buf; |
| 763 | event->bmRequestType = USB_DIR_IN | USB_TYPE_CLASS |
| 764 | | USB_RECIP_INTERFACE; |
| 765 | event->bNotificationType = USB_CDC_NOTIFY_RESPONSE_AVAILABLE; |
| 766 | event->wValue = cpu_to_le16(0); |
| 767 | event->wIndex = cpu_to_le16(dev->ifc_id); |
| 768 | event->wLength = cpu_to_le16(0); |
| 769 | spin_unlock_irqrestore(&dev->lock, flags); |
| 770 | |
| 771 | ret = usb_ep_queue(dev->notify, dev->notify_req, GFP_ATOMIC); |
| 772 | if (ret) { |
Anna Perel | f3af59d | 2012-08-12 15:28:30 +0300 | [diff] [blame] | 773 | spin_lock_irqsave(&dev->lock, flags); |
Ido Shayevitz | 909ed38 | 2013-02-15 02:25:35 +0200 | [diff] [blame] | 774 | if (!list_empty(&dev->cpkt_resp_q)) { |
| 775 | atomic_dec(&dev->notify_count); |
| 776 | cpkt = list_first_entry(&dev->cpkt_resp_q, |
Anna Perel | f3af59d | 2012-08-12 15:28:30 +0300 | [diff] [blame] | 777 | struct rmnet_ctrl_pkt, list); |
Anna Perel | f3af59d | 2012-08-12 15:28:30 +0300 | [diff] [blame] | 778 | list_del(&cpkt->list); |
| 779 | rmnet_free_ctrl_pkt(cpkt); |
| 780 | } |
| 781 | spin_unlock_irqrestore(&dev->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 782 | pr_debug("ep enqueue error %d\n", ret); |
| 783 | } |
| 784 | } |
| 785 | |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 786 | static void frmnet_connect(struct grmnet *gr) |
| 787 | { |
| 788 | struct f_rmnet *dev; |
| 789 | |
| 790 | if (!gr) { |
| 791 | pr_err("%s: Invalid grmnet:%p\n", __func__, gr); |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | dev = port_to_rmnet(gr); |
| 796 | |
| 797 | atomic_set(&dev->ctrl_online, 1); |
| 798 | } |
| 799 | |
| 800 | static void frmnet_disconnect(struct grmnet *gr) |
| 801 | { |
| 802 | struct f_rmnet *dev; |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 803 | struct usb_cdc_notification *event; |
| 804 | int status; |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 805 | |
| 806 | if (!gr) { |
| 807 | pr_err("%s: Invalid grmnet:%p\n", __func__, gr); |
| 808 | return; |
| 809 | } |
| 810 | |
| 811 | dev = port_to_rmnet(gr); |
| 812 | |
| 813 | atomic_set(&dev->ctrl_online, 0); |
| 814 | |
| 815 | if (!atomic_read(&dev->online)) { |
| 816 | pr_debug("%s: nothing to do\n", __func__); |
| 817 | return; |
| 818 | } |
| 819 | |
| 820 | usb_ep_fifo_flush(dev->notify); |
| 821 | |
| 822 | event = dev->notify_req->buf; |
| 823 | event->bmRequestType = USB_DIR_IN | USB_TYPE_CLASS |
| 824 | | USB_RECIP_INTERFACE; |
| 825 | event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION; |
| 826 | event->wValue = cpu_to_le16(0); |
| 827 | event->wIndex = cpu_to_le16(dev->ifc_id); |
| 828 | event->wLength = cpu_to_le16(0); |
| 829 | |
Vamsi Krishna | 188078d | 2011-10-26 15:09:55 -0700 | [diff] [blame] | 830 | status = usb_ep_queue(dev->notify, dev->notify_req, GFP_ATOMIC); |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 831 | if (status < 0) { |
| 832 | if (!atomic_read(&dev->online)) |
| 833 | return; |
| 834 | pr_err("%s: rmnet notify ep enqueue error %d\n", |
| 835 | __func__, status); |
| 836 | } |
| 837 | |
Ido Shayevitz | 909ed38 | 2013-02-15 02:25:35 +0200 | [diff] [blame] | 838 | frmnet_purge_responses(dev); |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 841 | static int |
Hemant Kumar | f60c025 | 2011-11-03 12:37:07 -0700 | [diff] [blame] | 842 | frmnet_send_cpkt_response(void *gr, void *buf, size_t len) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 843 | { |
| 844 | struct f_rmnet *dev; |
Hemant Kumar | f60c025 | 2011-11-03 12:37:07 -0700 | [diff] [blame] | 845 | struct rmnet_ctrl_pkt *cpkt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 846 | unsigned long flags; |
| 847 | |
Hemant Kumar | f60c025 | 2011-11-03 12:37:07 -0700 | [diff] [blame] | 848 | if (!gr || !buf) { |
| 849 | pr_err("%s: Invalid grmnet/buf, grmnet:%p buf:%p\n", |
| 850 | __func__, gr, buf); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 851 | return -ENODEV; |
| 852 | } |
Hemant Kumar | f60c025 | 2011-11-03 12:37:07 -0700 | [diff] [blame] | 853 | cpkt = rmnet_alloc_ctrl_pkt(len, GFP_ATOMIC); |
| 854 | if (IS_ERR(cpkt)) { |
| 855 | pr_err("%s: Unable to allocate ctrl pkt\n", __func__); |
| 856 | return -ENOMEM; |
| 857 | } |
| 858 | memcpy(cpkt->buf, buf, len); |
| 859 | cpkt->len = len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 860 | |
| 861 | dev = port_to_rmnet(gr); |
| 862 | |
| 863 | pr_debug("%s: dev:%p port#%d\n", __func__, dev, dev->port_num); |
| 864 | |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 865 | if (!atomic_read(&dev->online) || !atomic_read(&dev->ctrl_online)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 866 | rmnet_free_ctrl_pkt(cpkt); |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | spin_lock_irqsave(&dev->lock, flags); |
Chiranjeevi Velempati | 263e6c8 | 2011-11-11 23:07:36 +0530 | [diff] [blame] | 871 | list_add_tail(&cpkt->list, &dev->cpkt_resp_q); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 872 | spin_unlock_irqrestore(&dev->lock, flags); |
| 873 | |
| 874 | frmnet_ctrl_response_available(dev); |
| 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | static void |
| 880 | frmnet_cmd_complete(struct usb_ep *ep, struct usb_request *req) |
| 881 | { |
| 882 | struct f_rmnet *dev = req->context; |
| 883 | struct usb_composite_dev *cdev; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 884 | unsigned port_num; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 885 | |
| 886 | if (!dev) { |
| 887 | pr_err("%s: rmnet dev is null\n", __func__); |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | pr_debug("%s: dev:%p port#%d\n", __func__, dev, dev->port_num); |
| 892 | |
| 893 | cdev = dev->cdev; |
| 894 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 895 | if (dev->port.send_encap_cmd) { |
| 896 | port_num = rmnet_ports[dev->port_num].ctrl_xport_num; |
| 897 | dev->port.send_encap_cmd(port_num, req->buf, req->actual); |
| 898 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | static void frmnet_notify_complete(struct usb_ep *ep, struct usb_request *req) |
| 902 | { |
| 903 | struct f_rmnet *dev = req->context; |
| 904 | int status = req->status; |
Anna Perel | f3af59d | 2012-08-12 15:28:30 +0300 | [diff] [blame] | 905 | unsigned long flags; |
| 906 | struct rmnet_ctrl_pkt *cpkt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 907 | |
| 908 | pr_debug("%s: dev:%p port#%d\n", __func__, dev, dev->port_num); |
| 909 | |
| 910 | switch (status) { |
| 911 | case -ECONNRESET: |
| 912 | case -ESHUTDOWN: |
| 913 | /* connection gone */ |
| 914 | atomic_set(&dev->notify_count, 0); |
| 915 | break; |
| 916 | default: |
| 917 | pr_err("rmnet notify ep error %d\n", status); |
| 918 | /* FALLTHROUGH */ |
| 919 | case 0: |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 920 | if (!atomic_read(&dev->ctrl_online)) |
| 921 | break; |
| 922 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 923 | if (atomic_dec_and_test(&dev->notify_count)) |
| 924 | break; |
| 925 | |
| 926 | status = usb_ep_queue(dev->notify, req, GFP_ATOMIC); |
| 927 | if (status) { |
Anna Perel | f3af59d | 2012-08-12 15:28:30 +0300 | [diff] [blame] | 928 | spin_lock_irqsave(&dev->lock, flags); |
Ido Shayevitz | 909ed38 | 2013-02-15 02:25:35 +0200 | [diff] [blame] | 929 | if (!list_empty(&dev->cpkt_resp_q)) { |
| 930 | atomic_dec(&dev->notify_count); |
| 931 | cpkt = list_first_entry(&dev->cpkt_resp_q, |
Anna Perel | f3af59d | 2012-08-12 15:28:30 +0300 | [diff] [blame] | 932 | struct rmnet_ctrl_pkt, list); |
Anna Perel | f3af59d | 2012-08-12 15:28:30 +0300 | [diff] [blame] | 933 | list_del(&cpkt->list); |
| 934 | rmnet_free_ctrl_pkt(cpkt); |
| 935 | } |
| 936 | spin_unlock_irqrestore(&dev->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 937 | pr_debug("ep enqueue error %d\n", status); |
| 938 | } |
| 939 | break; |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | static int |
| 944 | frmnet_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) |
| 945 | { |
| 946 | struct f_rmnet *dev = func_to_rmnet(f); |
| 947 | struct usb_composite_dev *cdev = dev->cdev; |
| 948 | struct usb_request *req = cdev->req; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 949 | unsigned port_num; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 950 | u16 w_index = le16_to_cpu(ctrl->wIndex); |
| 951 | u16 w_value = le16_to_cpu(ctrl->wValue); |
| 952 | u16 w_length = le16_to_cpu(ctrl->wLength); |
| 953 | int ret = -EOPNOTSUPP; |
| 954 | |
| 955 | pr_debug("%s:dev:%p port#%d\n", __func__, dev, dev->port_num); |
| 956 | |
| 957 | if (!atomic_read(&dev->online)) { |
| 958 | pr_debug("%s: usb cable is not connected\n", __func__); |
| 959 | return -ENOTCONN; |
| 960 | } |
| 961 | |
| 962 | switch ((ctrl->bRequestType << 8) | ctrl->bRequest) { |
| 963 | |
| 964 | case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) |
| 965 | | USB_CDC_SEND_ENCAPSULATED_COMMAND: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 966 | ret = w_length; |
| 967 | req->complete = frmnet_cmd_complete; |
| 968 | req->context = dev; |
| 969 | break; |
| 970 | |
| 971 | |
| 972 | case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) |
| 973 | | USB_CDC_GET_ENCAPSULATED_RESPONSE: |
| 974 | if (w_value) |
| 975 | goto invalid; |
| 976 | else { |
| 977 | unsigned len; |
| 978 | struct rmnet_ctrl_pkt *cpkt; |
| 979 | |
| 980 | spin_lock(&dev->lock); |
| 981 | if (list_empty(&dev->cpkt_resp_q)) { |
| 982 | pr_err("ctrl resp queue empty " |
| 983 | " req%02x.%02x v%04x i%04x l%d\n", |
| 984 | ctrl->bRequestType, ctrl->bRequest, |
| 985 | w_value, w_index, w_length); |
| 986 | spin_unlock(&dev->lock); |
| 987 | goto invalid; |
| 988 | } |
| 989 | |
| 990 | cpkt = list_first_entry(&dev->cpkt_resp_q, |
| 991 | struct rmnet_ctrl_pkt, list); |
| 992 | list_del(&cpkt->list); |
| 993 | spin_unlock(&dev->lock); |
| 994 | |
| 995 | len = min_t(unsigned, w_length, cpkt->len); |
| 996 | memcpy(req->buf, cpkt->buf, len); |
| 997 | ret = len; |
| 998 | |
| 999 | rmnet_free_ctrl_pkt(cpkt); |
| 1000 | } |
| 1001 | break; |
| 1002 | case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) |
| 1003 | | USB_CDC_REQ_SET_CONTROL_LINE_STATE: |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1004 | if (dev->port.notify_modem) { |
| 1005 | port_num = rmnet_ports[dev->port_num].ctrl_xport_num; |
| 1006 | dev->port.notify_modem(&dev->port, port_num, w_value); |
| 1007 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1008 | ret = 0; |
| 1009 | |
| 1010 | break; |
| 1011 | default: |
| 1012 | |
| 1013 | invalid: |
| 1014 | DBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n", |
| 1015 | ctrl->bRequestType, ctrl->bRequest, |
| 1016 | w_value, w_index, w_length); |
| 1017 | } |
| 1018 | |
| 1019 | /* respond with data transfer or status phase? */ |
| 1020 | if (ret >= 0) { |
| 1021 | VDBG(cdev, "rmnet req%02x.%02x v%04x i%04x l%d\n", |
| 1022 | ctrl->bRequestType, ctrl->bRequest, |
| 1023 | w_value, w_index, w_length); |
| 1024 | req->zero = (ret < w_length); |
| 1025 | req->length = ret; |
| 1026 | ret = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); |
| 1027 | if (ret < 0) |
| 1028 | ERROR(cdev, "rmnet ep0 enqueue err %d\n", ret); |
| 1029 | } |
| 1030 | |
| 1031 | return ret; |
| 1032 | } |
| 1033 | |
| 1034 | static int frmnet_bind(struct usb_configuration *c, struct usb_function *f) |
| 1035 | { |
| 1036 | struct f_rmnet *dev = func_to_rmnet(f); |
| 1037 | struct usb_ep *ep; |
| 1038 | struct usb_composite_dev *cdev = c->cdev; |
| 1039 | int ret = -ENODEV; |
| 1040 | |
| 1041 | dev->ifc_id = usb_interface_id(c, f); |
| 1042 | if (dev->ifc_id < 0) { |
| 1043 | pr_err("%s: unable to allocate ifc id, err:%d", |
| 1044 | __func__, dev->ifc_id); |
| 1045 | return dev->ifc_id; |
| 1046 | } |
| 1047 | rmnet_interface_desc.bInterfaceNumber = dev->ifc_id; |
| 1048 | |
| 1049 | ep = usb_ep_autoconfig(cdev->gadget, &rmnet_fs_in_desc); |
| 1050 | if (!ep) { |
| 1051 | pr_err("%s: usb epin autoconfig failed\n", __func__); |
| 1052 | return -ENODEV; |
| 1053 | } |
| 1054 | dev->port.in = ep; |
| 1055 | ep->driver_data = cdev; |
| 1056 | |
| 1057 | ep = usb_ep_autoconfig(cdev->gadget, &rmnet_fs_out_desc); |
| 1058 | if (!ep) { |
| 1059 | pr_err("%s: usb epout autoconfig failed\n", __func__); |
| 1060 | ret = -ENODEV; |
| 1061 | goto ep_auto_out_fail; |
| 1062 | } |
| 1063 | dev->port.out = ep; |
| 1064 | ep->driver_data = cdev; |
| 1065 | |
| 1066 | ep = usb_ep_autoconfig(cdev->gadget, &rmnet_fs_notify_desc); |
| 1067 | if (!ep) { |
| 1068 | pr_err("%s: usb epnotify autoconfig failed\n", __func__); |
| 1069 | ret = -ENODEV; |
| 1070 | goto ep_auto_notify_fail; |
| 1071 | } |
| 1072 | dev->notify = ep; |
| 1073 | ep->driver_data = cdev; |
| 1074 | |
| 1075 | dev->notify_req = frmnet_alloc_req(ep, |
Hemant Kumar | fbf113d | 2011-09-16 18:24:45 -0700 | [diff] [blame] | 1076 | sizeof(struct usb_cdc_notification), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1077 | GFP_KERNEL); |
| 1078 | if (IS_ERR(dev->notify_req)) { |
| 1079 | pr_err("%s: unable to allocate memory for notify req\n", |
| 1080 | __func__); |
| 1081 | ret = -ENOMEM; |
| 1082 | goto ep_notify_alloc_fail; |
| 1083 | } |
| 1084 | |
| 1085 | dev->notify_req->complete = frmnet_notify_complete; |
| 1086 | dev->notify_req->context = dev; |
| 1087 | |
Pavankumar Kondeti | 6f94bc9 | 2012-08-03 09:34:32 +0530 | [diff] [blame] | 1088 | ret = -ENOMEM; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1089 | f->descriptors = usb_copy_descriptors(rmnet_fs_function); |
| 1090 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1091 | if (!f->descriptors) |
| 1092 | goto fail; |
| 1093 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1094 | if (gadget_is_dualspeed(cdev->gadget)) { |
| 1095 | rmnet_hs_in_desc.bEndpointAddress = |
| 1096 | rmnet_fs_in_desc.bEndpointAddress; |
| 1097 | rmnet_hs_out_desc.bEndpointAddress = |
| 1098 | rmnet_fs_out_desc.bEndpointAddress; |
| 1099 | rmnet_hs_notify_desc.bEndpointAddress = |
| 1100 | rmnet_fs_notify_desc.bEndpointAddress; |
| 1101 | |
| 1102 | /* copy descriptors, and track endpoint copies */ |
| 1103 | f->hs_descriptors = usb_copy_descriptors(rmnet_hs_function); |
| 1104 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1105 | if (!f->hs_descriptors) |
| 1106 | goto fail; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
Pavankumar Kondeti | 6f94bc9 | 2012-08-03 09:34:32 +0530 | [diff] [blame] | 1109 | if (gadget_is_superspeed(cdev->gadget)) { |
| 1110 | rmnet_ss_in_desc.bEndpointAddress = |
| 1111 | rmnet_fs_in_desc.bEndpointAddress; |
| 1112 | rmnet_ss_out_desc.bEndpointAddress = |
| 1113 | rmnet_fs_out_desc.bEndpointAddress; |
| 1114 | rmnet_ss_notify_desc.bEndpointAddress = |
| 1115 | rmnet_fs_notify_desc.bEndpointAddress; |
| 1116 | |
| 1117 | /* copy descriptors, and track endpoint copies */ |
| 1118 | f->ss_descriptors = usb_copy_descriptors(rmnet_ss_function); |
| 1119 | |
| 1120 | if (!f->ss_descriptors) |
| 1121 | goto fail; |
| 1122 | } |
| 1123 | |
Mayank Rana | ce1aaa5 | 2013-06-12 12:29:54 +0530 | [diff] [blame] | 1124 | pr_debug("%s: RmNet(%d) %s Speed, IN:%s OUT:%s\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1125 | __func__, dev->port_num, |
| 1126 | gadget_is_dualspeed(cdev->gadget) ? "dual" : "full", |
| 1127 | dev->port.in->name, dev->port.out->name); |
| 1128 | |
| 1129 | return 0; |
| 1130 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1131 | fail: |
Pavankumar Kondeti | 6f94bc9 | 2012-08-03 09:34:32 +0530 | [diff] [blame] | 1132 | if (f->ss_descriptors) |
| 1133 | usb_free_descriptors(f->ss_descriptors); |
| 1134 | if (f->hs_descriptors) |
| 1135 | usb_free_descriptors(f->hs_descriptors); |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1136 | if (f->descriptors) |
| 1137 | usb_free_descriptors(f->descriptors); |
Pavankumar Kondeti | 6f94bc9 | 2012-08-03 09:34:32 +0530 | [diff] [blame] | 1138 | if (dev->notify_req) |
| 1139 | frmnet_free_req(dev->notify, dev->notify_req); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1140 | ep_notify_alloc_fail: |
| 1141 | dev->notify->driver_data = NULL; |
| 1142 | dev->notify = NULL; |
| 1143 | ep_auto_notify_fail: |
| 1144 | dev->port.out->driver_data = NULL; |
| 1145 | dev->port.out = NULL; |
| 1146 | ep_auto_out_fail: |
| 1147 | dev->port.in->driver_data = NULL; |
| 1148 | dev->port.in = NULL; |
| 1149 | |
| 1150 | return ret; |
| 1151 | } |
| 1152 | |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 1153 | static int frmnet_bind_config(struct usb_configuration *c, unsigned portno) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1154 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1155 | int status; |
| 1156 | struct f_rmnet *dev; |
| 1157 | struct usb_function *f; |
| 1158 | unsigned long flags; |
| 1159 | |
| 1160 | pr_debug("%s: usb config:%p\n", __func__, c); |
| 1161 | |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 1162 | if (portno >= nr_rmnet_ports) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1163 | pr_err("%s: supporting ports#%u port_id:%u", __func__, |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 1164 | nr_rmnet_ports, portno); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1165 | return -ENODEV; |
| 1166 | } |
| 1167 | |
| 1168 | if (rmnet_string_defs[0].id == 0) { |
| 1169 | status = usb_string_id(c->cdev); |
| 1170 | if (status < 0) { |
| 1171 | pr_err("%s: failed to get string id, err:%d\n", |
| 1172 | __func__, status); |
| 1173 | return status; |
| 1174 | } |
| 1175 | rmnet_string_defs[0].id = status; |
| 1176 | } |
| 1177 | |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 1178 | dev = rmnet_ports[portno].port; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1179 | |
| 1180 | spin_lock_irqsave(&dev->lock, flags); |
| 1181 | dev->cdev = c->cdev; |
| 1182 | f = &dev->port.func; |
Vamsi Krishna | 188078d | 2011-10-26 15:09:55 -0700 | [diff] [blame] | 1183 | f->name = kasprintf(GFP_ATOMIC, "rmnet%d", portno); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1184 | spin_unlock_irqrestore(&dev->lock, flags); |
Vamsi Krishna | 188078d | 2011-10-26 15:09:55 -0700 | [diff] [blame] | 1185 | if (!f->name) { |
| 1186 | pr_err("%s: cannot allocate memory for name\n", __func__); |
| 1187 | return -ENOMEM; |
| 1188 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1189 | |
| 1190 | f->strings = rmnet_strings; |
| 1191 | f->bind = frmnet_bind; |
| 1192 | f->unbind = frmnet_unbind; |
| 1193 | f->disable = frmnet_disable; |
| 1194 | f->set_alt = frmnet_set_alt; |
| 1195 | f->setup = frmnet_setup; |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 1196 | f->suspend = frmnet_suspend; |
| 1197 | f->resume = frmnet_resume; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1198 | dev->port.send_cpkt_response = frmnet_send_cpkt_response; |
Vamsi Krishna | 9e9921a | 2011-10-04 16:09:31 -0700 | [diff] [blame] | 1199 | dev->port.disconnect = frmnet_disconnect; |
| 1200 | dev->port.connect = frmnet_connect; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1201 | |
| 1202 | status = usb_add_function(c, f); |
| 1203 | if (status) { |
| 1204 | pr_err("%s: usb add function failed: %d\n", |
| 1205 | __func__, status); |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 1206 | kfree(f->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1207 | return status; |
| 1208 | } |
| 1209 | |
| 1210 | pr_debug("%s: complete\n", __func__); |
| 1211 | |
| 1212 | return status; |
| 1213 | } |
| 1214 | |
Manu Gautam | e3e897c | 2011-09-12 17:18:46 +0530 | [diff] [blame] | 1215 | static void frmnet_cleanup(void) |
| 1216 | { |
| 1217 | int i; |
| 1218 | |
| 1219 | for (i = 0; i < nr_rmnet_ports; i++) |
| 1220 | kfree(rmnet_ports[i].port); |
| 1221 | |
Tarun Gupta | 44ad2bb | 2013-09-30 18:01:58 +0530 | [diff] [blame] | 1222 | gbam_cleanup(); |
Manu Gautam | e3e897c | 2011-09-12 17:18:46 +0530 | [diff] [blame] | 1223 | nr_rmnet_ports = 0; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1224 | no_ctrl_smd_ports = 0; |
Bar Weiner | 0dae81b | 2013-02-14 13:53:54 +0200 | [diff] [blame] | 1225 | no_ctrl_qti_ports = 0; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1226 | no_data_bam_ports = 0; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1227 | no_data_bam2bam_ports = 0; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 1228 | no_ctrl_hsic_ports = 0; |
| 1229 | no_data_hsic_ports = 0; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 1230 | no_ctrl_hsuart_ports = 0; |
| 1231 | no_data_hsuart_ports = 0; |
Manu Gautam | e3e897c | 2011-09-12 17:18:46 +0530 | [diff] [blame] | 1232 | } |
| 1233 | |
Hemant Kumar | c2b1778 | 2013-02-03 15:56:29 -0800 | [diff] [blame] | 1234 | static int frmnet_init_port(const char *ctrl_name, const char *data_name, |
| 1235 | const char *port_name) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1236 | { |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1237 | struct f_rmnet *dev; |
| 1238 | struct rmnet_ports *rmnet_port; |
| 1239 | int ret; |
| 1240 | int i; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1241 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1242 | if (nr_rmnet_ports >= NR_RMNET_PORTS) { |
| 1243 | pr_err("%s: Max-%d instances supported\n", |
| 1244 | __func__, NR_RMNET_PORTS); |
Manu Gautam | e3e897c | 2011-09-12 17:18:46 +0530 | [diff] [blame] | 1245 | return -EINVAL; |
| 1246 | } |
| 1247 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1248 | pr_debug("%s: port#:%d, ctrl port: %s data port: %s\n", |
| 1249 | __func__, nr_rmnet_ports, ctrl_name, data_name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1250 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1251 | dev = kzalloc(sizeof(struct f_rmnet), GFP_KERNEL); |
| 1252 | if (!dev) { |
| 1253 | pr_err("%s: Unable to allocate rmnet device\n", __func__); |
| 1254 | return -ENOMEM; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1257 | dev->port_num = nr_rmnet_ports; |
| 1258 | spin_lock_init(&dev->lock); |
| 1259 | INIT_LIST_HEAD(&dev->cpkt_resp_q); |
| 1260 | |
| 1261 | rmnet_port = &rmnet_ports[nr_rmnet_ports]; |
| 1262 | rmnet_port->port = dev; |
| 1263 | rmnet_port->port_num = nr_rmnet_ports; |
| 1264 | rmnet_port->ctrl_xport = str_to_xport(ctrl_name); |
| 1265 | rmnet_port->data_xport = str_to_xport(data_name); |
| 1266 | |
| 1267 | switch (rmnet_port->ctrl_xport) { |
| 1268 | case USB_GADGET_XPORT_SMD: |
| 1269 | rmnet_port->ctrl_xport_num = no_ctrl_smd_ports; |
| 1270 | no_ctrl_smd_ports++; |
| 1271 | break; |
Bar Weiner | 0dae81b | 2013-02-14 13:53:54 +0200 | [diff] [blame] | 1272 | case USB_GADGET_XPORT_QTI: |
| 1273 | rmnet_port->ctrl_xport_num = no_ctrl_qti_ports; |
| 1274 | no_ctrl_qti_ports++; |
| 1275 | break; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 1276 | case USB_GADGET_XPORT_HSIC: |
Hemant Kumar | c2b1778 | 2013-02-03 15:56:29 -0800 | [diff] [blame] | 1277 | ghsic_ctrl_set_port_name(port_name, ctrl_name); |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 1278 | rmnet_port->ctrl_xport_num = no_ctrl_hsic_ports; |
| 1279 | no_ctrl_hsic_ports++; |
| 1280 | break; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 1281 | case USB_GADGET_XPORT_HSUART: |
| 1282 | rmnet_port->ctrl_xport_num = no_ctrl_hsuart_ports; |
| 1283 | no_ctrl_hsuart_ports++; |
| 1284 | break; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1285 | case USB_GADGET_XPORT_NONE: |
| 1286 | break; |
| 1287 | default: |
| 1288 | pr_err("%s: Un-supported transport: %u\n", __func__, |
| 1289 | rmnet_port->ctrl_xport); |
| 1290 | ret = -ENODEV; |
| 1291 | goto fail_probe; |
| 1292 | } |
| 1293 | |
| 1294 | switch (rmnet_port->data_xport) { |
| 1295 | case USB_GADGET_XPORT_BAM: |
| 1296 | rmnet_port->data_xport_num = no_data_bam_ports; |
| 1297 | no_data_bam_ports++; |
| 1298 | break; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1299 | case USB_GADGET_XPORT_BAM2BAM: |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1300 | case USB_GADGET_XPORT_BAM2BAM_IPA: |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1301 | rmnet_port->data_xport_num = no_data_bam2bam_ports; |
| 1302 | no_data_bam2bam_ports++; |
| 1303 | break; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 1304 | case USB_GADGET_XPORT_HSIC: |
Hemant Kumar | c2b1778 | 2013-02-03 15:56:29 -0800 | [diff] [blame] | 1305 | ghsic_data_set_port_name(port_name, data_name); |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 1306 | rmnet_port->data_xport_num = no_data_hsic_ports; |
| 1307 | no_data_hsic_ports++; |
| 1308 | break; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 1309 | case USB_GADGET_XPORT_HSUART: |
| 1310 | rmnet_port->data_xport_num = no_data_hsuart_ports; |
| 1311 | no_data_hsuart_ports++; |
| 1312 | break; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1313 | case USB_GADGET_XPORT_NONE: |
| 1314 | break; |
| 1315 | default: |
| 1316 | pr_err("%s: Un-supported transport: %u\n", __func__, |
| 1317 | rmnet_port->data_xport); |
| 1318 | ret = -ENODEV; |
| 1319 | goto fail_probe; |
| 1320 | } |
| 1321 | nr_rmnet_ports++; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1322 | |
| 1323 | return 0; |
| 1324 | |
| 1325 | fail_probe: |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 1326 | for (i = 0; i < nr_rmnet_ports; i++) |
| 1327 | kfree(rmnet_ports[i].port); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1328 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1329 | nr_rmnet_ports = 0; |
| 1330 | no_ctrl_smd_ports = 0; |
Bar Weiner | 0dae81b | 2013-02-14 13:53:54 +0200 | [diff] [blame] | 1331 | no_ctrl_qti_ports = 0; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1332 | no_data_bam_ports = 0; |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 1333 | no_ctrl_hsic_ports = 0; |
| 1334 | no_data_hsic_ports = 0; |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 1335 | no_ctrl_hsuart_ports = 0; |
| 1336 | no_data_hsuart_ports = 0; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 1337 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1338 | return ret; |
| 1339 | } |