aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/f_ecm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/f_ecm.c')
-rw-r--r--drivers/usb/gadget/f_ecm.c108
1 files changed, 54 insertions, 54 deletions
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index a2b5c092bda0..4ae579948e54 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -83,7 +83,7 @@ static inline struct f_ecm *func_to_ecm(struct usb_function *f)
83} 83}
84 84
85/* peak (theoretical) bulk transfer rate in bits-per-second */ 85/* peak (theoretical) bulk transfer rate in bits-per-second */
86static inline unsigned bitrate(struct usb_gadget *g) 86static inline unsigned ecm_bitrate(struct usb_gadget *g)
87{ 87{
88 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 88 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
89 return 13 * 512 * 8 * 1000 * 8; 89 return 13 * 512 * 8 * 1000 * 8;
@@ -107,7 +107,7 @@ static inline unsigned bitrate(struct usb_gadget *g)
107 */ 107 */
108 108
109#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */ 109#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
110#define STATUS_BYTECOUNT 16 /* 8 byte header + data */ 110#define ECM_STATUS_BYTECOUNT 16 /* 8 byte header + data */
111 111
112 112
113/* interface descriptor: */ 113/* interface descriptor: */
@@ -125,8 +125,8 @@ static struct usb_interface_descriptor ecm_control_intf __initdata = {
125 /* .iInterface = DYNAMIC */ 125 /* .iInterface = DYNAMIC */
126}; 126};
127 127
128static struct usb_cdc_header_desc header_desc __initdata = { 128static struct usb_cdc_header_desc ecm_header_desc __initdata = {
129 .bLength = sizeof header_desc, 129 .bLength = sizeof ecm_header_desc,
130 .bDescriptorType = USB_DT_CS_INTERFACE, 130 .bDescriptorType = USB_DT_CS_INTERFACE,
131 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 131 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
132 132
@@ -141,8 +141,8 @@ static struct usb_cdc_union_desc ecm_union_desc __initdata = {
141 /* .bSlaveInterface0 = DYNAMIC */ 141 /* .bSlaveInterface0 = DYNAMIC */
142}; 142};
143 143
144static struct usb_cdc_ether_desc ether_desc __initdata = { 144static struct usb_cdc_ether_desc ecm_desc __initdata = {
145 .bLength = sizeof ether_desc, 145 .bLength = sizeof ecm_desc,
146 .bDescriptorType = USB_DT_CS_INTERFACE, 146 .bDescriptorType = USB_DT_CS_INTERFACE,
147 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE, 147 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
148 148
@@ -186,17 +186,17 @@ static struct usb_interface_descriptor ecm_data_intf __initdata = {
186 186
187/* full speed support: */ 187/* full speed support: */
188 188
189static struct usb_endpoint_descriptor fs_notify_desc __initdata = { 189static struct usb_endpoint_descriptor fs_ecm_notify_desc __initdata = {
190 .bLength = USB_DT_ENDPOINT_SIZE, 190 .bLength = USB_DT_ENDPOINT_SIZE,
191 .bDescriptorType = USB_DT_ENDPOINT, 191 .bDescriptorType = USB_DT_ENDPOINT,
192 192
193 .bEndpointAddress = USB_DIR_IN, 193 .bEndpointAddress = USB_DIR_IN,
194 .bmAttributes = USB_ENDPOINT_XFER_INT, 194 .bmAttributes = USB_ENDPOINT_XFER_INT,
195 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), 195 .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT),
196 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, 196 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
197}; 197};
198 198
199static struct usb_endpoint_descriptor fs_in_desc __initdata = { 199static struct usb_endpoint_descriptor fs_ecm_in_desc __initdata = {
200 .bLength = USB_DT_ENDPOINT_SIZE, 200 .bLength = USB_DT_ENDPOINT_SIZE,
201 .bDescriptorType = USB_DT_ENDPOINT, 201 .bDescriptorType = USB_DT_ENDPOINT,
202 202
@@ -204,7 +204,7 @@ static struct usb_endpoint_descriptor fs_in_desc __initdata = {
204 .bmAttributes = USB_ENDPOINT_XFER_BULK, 204 .bmAttributes = USB_ENDPOINT_XFER_BULK,
205}; 205};
206 206
207static struct usb_endpoint_descriptor fs_out_desc __initdata = { 207static struct usb_endpoint_descriptor fs_ecm_out_desc __initdata = {
208 .bLength = USB_DT_ENDPOINT_SIZE, 208 .bLength = USB_DT_ENDPOINT_SIZE,
209 .bDescriptorType = USB_DT_ENDPOINT, 209 .bDescriptorType = USB_DT_ENDPOINT,
210 210
@@ -212,34 +212,34 @@ static struct usb_endpoint_descriptor fs_out_desc __initdata = {
212 .bmAttributes = USB_ENDPOINT_XFER_BULK, 212 .bmAttributes = USB_ENDPOINT_XFER_BULK,
213}; 213};
214 214
215static struct usb_descriptor_header *eth_fs_function[] __initdata = { 215static struct usb_descriptor_header *ecm_fs_function[] __initdata = {
216 /* CDC ECM control descriptors */ 216 /* CDC ECM control descriptors */
217 (struct usb_descriptor_header *) &ecm_control_intf, 217 (struct usb_descriptor_header *) &ecm_control_intf,
218 (struct usb_descriptor_header *) &header_desc, 218 (struct usb_descriptor_header *) &ecm_header_desc,
219 (struct usb_descriptor_header *) &ecm_union_desc, 219 (struct usb_descriptor_header *) &ecm_union_desc,
220 (struct usb_descriptor_header *) &ether_desc, 220 (struct usb_descriptor_header *) &ecm_desc,
221 /* NOTE: status endpoint might need to be removed */ 221 /* NOTE: status endpoint might need to be removed */
222 (struct usb_descriptor_header *) &fs_notify_desc, 222 (struct usb_descriptor_header *) &fs_ecm_notify_desc,
223 /* data interface, altsettings 0 and 1 */ 223 /* data interface, altsettings 0 and 1 */
224 (struct usb_descriptor_header *) &ecm_data_nop_intf, 224 (struct usb_descriptor_header *) &ecm_data_nop_intf,
225 (struct usb_descriptor_header *) &ecm_data_intf, 225 (struct usb_descriptor_header *) &ecm_data_intf,
226 (struct usb_descriptor_header *) &fs_in_desc, 226 (struct usb_descriptor_header *) &fs_ecm_in_desc,
227 (struct usb_descriptor_header *) &fs_out_desc, 227 (struct usb_descriptor_header *) &fs_ecm_out_desc,
228 NULL, 228 NULL,
229}; 229};
230 230
231/* high speed support: */ 231/* high speed support: */
232 232
233static struct usb_endpoint_descriptor hs_notify_desc __initdata = { 233static struct usb_endpoint_descriptor hs_ecm_notify_desc __initdata = {
234 .bLength = USB_DT_ENDPOINT_SIZE, 234 .bLength = USB_DT_ENDPOINT_SIZE,
235 .bDescriptorType = USB_DT_ENDPOINT, 235 .bDescriptorType = USB_DT_ENDPOINT,
236 236
237 .bEndpointAddress = USB_DIR_IN, 237 .bEndpointAddress = USB_DIR_IN,
238 .bmAttributes = USB_ENDPOINT_XFER_INT, 238 .bmAttributes = USB_ENDPOINT_XFER_INT,
239 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), 239 .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT),
240 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 240 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
241}; 241};
242static struct usb_endpoint_descriptor hs_in_desc __initdata = { 242static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = {
243 .bLength = USB_DT_ENDPOINT_SIZE, 243 .bLength = USB_DT_ENDPOINT_SIZE,
244 .bDescriptorType = USB_DT_ENDPOINT, 244 .bDescriptorType = USB_DT_ENDPOINT,
245 245
@@ -248,7 +248,7 @@ static struct usb_endpoint_descriptor hs_in_desc __initdata = {
248 .wMaxPacketSize = __constant_cpu_to_le16(512), 248 .wMaxPacketSize = __constant_cpu_to_le16(512),
249}; 249};
250 250
251static struct usb_endpoint_descriptor hs_out_desc __initdata = { 251static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = {
252 .bLength = USB_DT_ENDPOINT_SIZE, 252 .bLength = USB_DT_ENDPOINT_SIZE,
253 .bDescriptorType = USB_DT_ENDPOINT, 253 .bDescriptorType = USB_DT_ENDPOINT,
254 254
@@ -257,19 +257,19 @@ static struct usb_endpoint_descriptor hs_out_desc __initdata = {
257 .wMaxPacketSize = __constant_cpu_to_le16(512), 257 .wMaxPacketSize = __constant_cpu_to_le16(512),
258}; 258};
259 259
260static struct usb_descriptor_header *eth_hs_function[] __initdata = { 260static struct usb_descriptor_header *ecm_hs_function[] __initdata = {
261 /* CDC ECM control descriptors */ 261 /* CDC ECM control descriptors */
262 (struct usb_descriptor_header *) &ecm_control_intf, 262 (struct usb_descriptor_header *) &ecm_control_intf,
263 (struct usb_descriptor_header *) &header_desc, 263 (struct usb_descriptor_header *) &ecm_header_desc,
264 (struct usb_descriptor_header *) &ecm_union_desc, 264 (struct usb_descriptor_header *) &ecm_union_desc,
265 (struct usb_descriptor_header *) &ether_desc, 265 (struct usb_descriptor_header *) &ecm_desc,
266 /* NOTE: status endpoint might need to be removed */ 266 /* NOTE: status endpoint might need to be removed */
267 (struct usb_descriptor_header *) &hs_notify_desc, 267 (struct usb_descriptor_header *) &hs_ecm_notify_desc,
268 /* data interface, altsettings 0 and 1 */ 268 /* data interface, altsettings 0 and 1 */
269 (struct usb_descriptor_header *) &ecm_data_nop_intf, 269 (struct usb_descriptor_header *) &ecm_data_nop_intf,
270 (struct usb_descriptor_header *) &ecm_data_intf, 270 (struct usb_descriptor_header *) &ecm_data_intf,
271 (struct usb_descriptor_header *) &hs_in_desc, 271 (struct usb_descriptor_header *) &hs_ecm_in_desc,
272 (struct usb_descriptor_header *) &hs_out_desc, 272 (struct usb_descriptor_header *) &hs_ecm_out_desc,
273 NULL, 273 NULL,
274}; 274};
275 275
@@ -329,14 +329,14 @@ static void ecm_do_notify(struct f_ecm *ecm)
329 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE; 329 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE;
330 event->wValue = cpu_to_le16(0); 330 event->wValue = cpu_to_le16(0);
331 event->wLength = cpu_to_le16(8); 331 event->wLength = cpu_to_le16(8);
332 req->length = STATUS_BYTECOUNT; 332 req->length = ECM_STATUS_BYTECOUNT;
333 333
334 /* SPEED_CHANGE data is up/down speeds in bits/sec */ 334 /* SPEED_CHANGE data is up/down speeds in bits/sec */
335 data = req->buf + sizeof *event; 335 data = req->buf + sizeof *event;
336 data[0] = cpu_to_le32(bitrate(cdev->gadget)); 336 data[0] = cpu_to_le32(ecm_bitrate(cdev->gadget));
337 data[1] = data[0]; 337 data[1] = data[0];
338 338
339 DBG(cdev, "notify speed %d\n", bitrate(cdev->gadget)); 339 DBG(cdev, "notify speed %d\n", ecm_bitrate(cdev->gadget));
340 ecm->notify_state = ECM_NOTIFY_NONE; 340 ecm->notify_state = ECM_NOTIFY_NONE;
341 break; 341 break;
342 } 342 }
@@ -628,13 +628,13 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
628 status = -ENODEV; 628 status = -ENODEV;
629 629
630 /* allocate instance-specific endpoints */ 630 /* allocate instance-specific endpoints */
631 ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc); 631 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_in_desc);
632 if (!ep) 632 if (!ep)
633 goto fail; 633 goto fail;
634 ecm->port.in_ep = ep; 634 ecm->port.in_ep = ep;
635 ep->driver_data = cdev; /* claim */ 635 ep->driver_data = cdev; /* claim */
636 636
637 ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc); 637 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_out_desc);
638 if (!ep) 638 if (!ep)
639 goto fail; 639 goto fail;
640 ecm->port.out_ep = ep; 640 ecm->port.out_ep = ep;
@@ -644,7 +644,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
644 * don't treat it that way. It's simpler, and some newer CDC 644 * don't treat it that way. It's simpler, and some newer CDC
645 * profiles (wireless handsets) no longer treat it as optional. 645 * profiles (wireless handsets) no longer treat it as optional.
646 */ 646 */
647 ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc); 647 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_notify_desc);
648 if (!ep) 648 if (!ep)
649 goto fail; 649 goto fail;
650 ecm->notify = ep; 650 ecm->notify = ep;
@@ -656,47 +656,47 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
656 ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); 656 ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
657 if (!ecm->notify_req) 657 if (!ecm->notify_req)
658 goto fail; 658 goto fail;
659 ecm->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL); 659 ecm->notify_req->buf = kmalloc(ECM_STATUS_BYTECOUNT, GFP_KERNEL);
660 if (!ecm->notify_req->buf) 660 if (!ecm->notify_req->buf)
661 goto fail; 661 goto fail;
662 ecm->notify_req->context = ecm; 662 ecm->notify_req->context = ecm;
663 ecm->notify_req->complete = ecm_notify_complete; 663 ecm->notify_req->complete = ecm_notify_complete;
664 664
665 /* copy descriptors, and track endpoint copies */ 665 /* copy descriptors, and track endpoint copies */
666 f->descriptors = usb_copy_descriptors(eth_fs_function); 666 f->descriptors = usb_copy_descriptors(ecm_fs_function);
667 if (!f->descriptors) 667 if (!f->descriptors)
668 goto fail; 668 goto fail;
669 669
670 ecm->fs.in = usb_find_endpoint(eth_fs_function, 670 ecm->fs.in = usb_find_endpoint(ecm_fs_function,
671 f->descriptors, &fs_in_desc); 671 f->descriptors, &fs_ecm_in_desc);
672 ecm->fs.out = usb_find_endpoint(eth_fs_function, 672 ecm->fs.out = usb_find_endpoint(ecm_fs_function,
673 f->descriptors, &fs_out_desc); 673 f->descriptors, &fs_ecm_out_desc);
674 ecm->fs.notify = usb_find_endpoint(eth_fs_function, 674 ecm->fs.notify = usb_find_endpoint(ecm_fs_function,
675 f->descriptors, &fs_notify_desc); 675 f->descriptors, &fs_ecm_notify_desc);
676 676
677 /* support all relevant hardware speeds... we expect that when 677 /* support all relevant hardware speeds... we expect that when
678 * hardware is dual speed, all bulk-capable endpoints work at 678 * hardware is dual speed, all bulk-capable endpoints work at
679 * both speeds 679 * both speeds
680 */ 680 */
681 if (gadget_is_dualspeed(c->cdev->gadget)) { 681 if (gadget_is_dualspeed(c->cdev->gadget)) {
682 hs_in_desc.bEndpointAddress = 682 hs_ecm_in_desc.bEndpointAddress =
683 fs_in_desc.bEndpointAddress; 683 fs_ecm_in_desc.bEndpointAddress;
684 hs_out_desc.bEndpointAddress = 684 hs_ecm_out_desc.bEndpointAddress =
685 fs_out_desc.bEndpointAddress; 685 fs_ecm_out_desc.bEndpointAddress;
686 hs_notify_desc.bEndpointAddress = 686 hs_ecm_notify_desc.bEndpointAddress =
687 fs_notify_desc.bEndpointAddress; 687 fs_ecm_notify_desc.bEndpointAddress;
688 688
689 /* copy descriptors, and track endpoint copies */ 689 /* copy descriptors, and track endpoint copies */
690 f->hs_descriptors = usb_copy_descriptors(eth_hs_function); 690 f->hs_descriptors = usb_copy_descriptors(ecm_hs_function);
691 if (!f->hs_descriptors) 691 if (!f->hs_descriptors)
692 goto fail; 692 goto fail;
693 693
694 ecm->hs.in = usb_find_endpoint(eth_hs_function, 694 ecm->hs.in = usb_find_endpoint(ecm_hs_function,
695 f->hs_descriptors, &hs_in_desc); 695 f->hs_descriptors, &hs_ecm_in_desc);
696 ecm->hs.out = usb_find_endpoint(eth_hs_function, 696 ecm->hs.out = usb_find_endpoint(ecm_hs_function,
697 f->hs_descriptors, &hs_out_desc); 697 f->hs_descriptors, &hs_ecm_out_desc);
698 ecm->hs.notify = usb_find_endpoint(eth_hs_function, 698 ecm->hs.notify = usb_find_endpoint(ecm_hs_function,
699 f->hs_descriptors, &hs_notify_desc); 699 f->hs_descriptors, &hs_ecm_notify_desc);
700 } 700 }
701 701
702 /* NOTE: all that is done without knowing or caring about 702 /* NOTE: all that is done without knowing or caring about
@@ -795,7 +795,7 @@ int __init ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
795 if (status < 0) 795 if (status < 0)
796 return status; 796 return status;
797 ecm_string_defs[1].id = status; 797 ecm_string_defs[1].id = status;
798 ether_desc.iMACAddress = status; 798 ecm_desc.iMACAddress = status;
799 } 799 }
800 800
801 /* allocate and initialize one new instance */ 801 /* allocate and initialize one new instance */