blob: 22d19483e101352f471c4f3f1c389dbb85016b7d [file] [log] [blame]
David Brownellda741b82008-06-19 18:19:46 -07001/*
2 * f_ecm.c -- USB CDC Ethernet (ECM) link function driver
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
David Brownellda741b82008-06-19 18:19:46 -070011 */
12
13/* #define VERBOSE_DEBUG */
14
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
David Brownellda741b82008-06-19 18:19:46 -070016#include <linux/kernel.h>
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +020017#include <linux/module.h>
David Brownellda741b82008-06-19 18:19:46 -070018#include <linux/device.h>
19#include <linux/etherdevice.h>
20
21#include "u_ether.h"
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +020022#include "u_ecm.h"
David Brownellda741b82008-06-19 18:19:46 -070023
24
25/*
26 * This function is a "CDC Ethernet Networking Control Model" (CDC ECM)
27 * Ethernet link. The data transfer model is simple (packets sent and
28 * received over bulk endpoints using normal short packet termination),
29 * and the control model exposes various data and optional notifications.
30 *
31 * ECM is well standardized and (except for Microsoft) supported by most
32 * operating systems with USB host support. It's the preferred interop
33 * solution for Ethernet over USB, at least for firmware based solutions.
34 * (Hardware solutions tend to be more minimalist.) A newer and simpler
35 * "Ethernet Emulation Model" (CDC EEM) hasn't yet caught on.
36 *
37 * Note that ECM requires the use of "alternate settings" for its data
38 * interface. This means that the set_alt() method has real work to do,
39 * and also means that a get_alt() method is required.
40 */
41
David Brownellda741b82008-06-19 18:19:46 -070042
43enum ecm_notify_state {
44 ECM_NOTIFY_NONE, /* don't notify */
45 ECM_NOTIFY_CONNECT, /* issue CONNECT next */
46 ECM_NOTIFY_SPEED, /* issue SPEED_CHANGE next */
47};
48
49struct f_ecm {
50 struct gether port;
51 u8 ctrl_id, data_id;
52
53 char ethaddr[14];
54
David Brownellda741b82008-06-19 18:19:46 -070055 struct usb_ep *notify;
David Brownellda741b82008-06-19 18:19:46 -070056 struct usb_request *notify_req;
57 u8 notify_state;
58 bool is_open;
59
60 /* FIXME is_open needs some irq-ish locking
61 * ... possibly the same as port.ioport
62 */
63};
64
65static inline struct f_ecm *func_to_ecm(struct usb_function *f)
66{
67 return container_of(f, struct f_ecm, port.func);
68}
69
70/* peak (theoretical) bulk transfer rate in bits-per-second */
David Brownell33376c12008-08-18 17:45:07 -070071static inline unsigned ecm_bitrate(struct usb_gadget *g)
David Brownellda741b82008-06-19 18:19:46 -070072{
Paul Zimmerman04617db2011-06-27 14:13:18 -070073 if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
74 return 13 * 1024 * 8 * 1000 * 8;
75 else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
David Brownellda741b82008-06-19 18:19:46 -070076 return 13 * 512 * 8 * 1000 * 8;
77 else
Paul Zimmerman04617db2011-06-27 14:13:18 -070078 return 19 * 64 * 1 * 1000 * 8;
David Brownellda741b82008-06-19 18:19:46 -070079}
80
81/*-------------------------------------------------------------------------*/
82
83/*
84 * Include the status endpoint if we can, even though it's optional.
85 *
86 * Use wMaxPacketSize big enough to fit CDC_NOTIFY_SPEED_CHANGE in one
87 * packet, to simplify cancellation; and a big transfer interval, to
88 * waste less bandwidth.
89 *
90 * Some drivers (like Linux 2.4 cdc-ether!) "need" it to exist even
91 * if they ignore the connect/disconnect notifications that real aether
92 * can provide. More advanced cdc configurations might want to support
93 * encapsulated commands (vendor-specific, using control-OUT).
94 */
95
Sebastian Andrzej Siewiorbcb2f992012-10-22 22:14:57 +020096#define ECM_STATUS_INTERVAL_MS 32
David Brownell33376c12008-08-18 17:45:07 -070097#define ECM_STATUS_BYTECOUNT 16 /* 8 byte header + data */
David Brownellda741b82008-06-19 18:19:46 -070098
99
100/* interface descriptor: */
101
Praveena Nadahallyd11519a2012-01-25 11:02:03 +0100102static struct usb_interface_assoc_descriptor
103ecm_iad_descriptor = {
104 .bLength = sizeof ecm_iad_descriptor,
105 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
106
107 /* .bFirstInterface = DYNAMIC, */
108 .bInterfaceCount = 2, /* control + data */
109 .bFunctionClass = USB_CLASS_COMM,
110 .bFunctionSubClass = USB_CDC_SUBCLASS_ETHERNET,
111 .bFunctionProtocol = USB_CDC_PROTO_NONE,
112 /* .iFunction = DYNAMIC */
113};
114
115
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200116static struct usb_interface_descriptor ecm_control_intf = {
David Brownellda741b82008-06-19 18:19:46 -0700117 .bLength = sizeof ecm_control_intf,
118 .bDescriptorType = USB_DT_INTERFACE,
119
120 /* .bInterfaceNumber = DYNAMIC */
121 /* status endpoint is optional; this could be patched later */
122 .bNumEndpoints = 1,
123 .bInterfaceClass = USB_CLASS_COMM,
124 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET,
125 .bInterfaceProtocol = USB_CDC_PROTO_NONE,
126 /* .iInterface = DYNAMIC */
127};
128
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200129static struct usb_cdc_header_desc ecm_header_desc = {
David Brownell33376c12008-08-18 17:45:07 -0700130 .bLength = sizeof ecm_header_desc,
David Brownellda741b82008-06-19 18:19:46 -0700131 .bDescriptorType = USB_DT_CS_INTERFACE,
132 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
133
Harvey Harrison551509d2009-02-11 14:11:36 -0800134 .bcdCDC = cpu_to_le16(0x0110),
David Brownellda741b82008-06-19 18:19:46 -0700135};
136
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200137static struct usb_cdc_union_desc ecm_union_desc = {
David Brownellda741b82008-06-19 18:19:46 -0700138 .bLength = sizeof(ecm_union_desc),
139 .bDescriptorType = USB_DT_CS_INTERFACE,
140 .bDescriptorSubType = USB_CDC_UNION_TYPE,
141 /* .bMasterInterface0 = DYNAMIC */
142 /* .bSlaveInterface0 = DYNAMIC */
143};
144
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200145static struct usb_cdc_ether_desc ecm_desc = {
David Brownell33376c12008-08-18 17:45:07 -0700146 .bLength = sizeof ecm_desc,
David Brownellda741b82008-06-19 18:19:46 -0700147 .bDescriptorType = USB_DT_CS_INTERFACE,
148 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
149
150 /* this descriptor actually adds value, surprise! */
151 /* .iMACAddress = DYNAMIC */
Harvey Harrison551509d2009-02-11 14:11:36 -0800152 .bmEthernetStatistics = cpu_to_le32(0), /* no statistics */
153 .wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN),
154 .wNumberMCFilters = cpu_to_le16(0),
David Brownellda741b82008-06-19 18:19:46 -0700155 .bNumberPowerFilters = 0,
156};
157
158/* the default data interface has no endpoints ... */
159
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200160static struct usb_interface_descriptor ecm_data_nop_intf = {
David Brownellda741b82008-06-19 18:19:46 -0700161 .bLength = sizeof ecm_data_nop_intf,
162 .bDescriptorType = USB_DT_INTERFACE,
163
164 .bInterfaceNumber = 1,
165 .bAlternateSetting = 0,
166 .bNumEndpoints = 0,
167 .bInterfaceClass = USB_CLASS_CDC_DATA,
168 .bInterfaceSubClass = 0,
169 .bInterfaceProtocol = 0,
170 /* .iInterface = DYNAMIC */
171};
172
173/* ... but the "real" data interface has two bulk endpoints */
174
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200175static struct usb_interface_descriptor ecm_data_intf = {
David Brownellda741b82008-06-19 18:19:46 -0700176 .bLength = sizeof ecm_data_intf,
177 .bDescriptorType = USB_DT_INTERFACE,
178
179 .bInterfaceNumber = 1,
180 .bAlternateSetting = 1,
181 .bNumEndpoints = 2,
182 .bInterfaceClass = USB_CLASS_CDC_DATA,
183 .bInterfaceSubClass = 0,
184 .bInterfaceProtocol = 0,
185 /* .iInterface = DYNAMIC */
186};
187
188/* full speed support: */
189
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200190static struct usb_endpoint_descriptor fs_ecm_notify_desc = {
David Brownellda741b82008-06-19 18:19:46 -0700191 .bLength = USB_DT_ENDPOINT_SIZE,
192 .bDescriptorType = USB_DT_ENDPOINT,
193
194 .bEndpointAddress = USB_DIR_IN,
195 .bmAttributes = USB_ENDPOINT_XFER_INT,
Harvey Harrison551509d2009-02-11 14:11:36 -0800196 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
Sebastian Andrzej Siewiorbcb2f992012-10-22 22:14:57 +0200197 .bInterval = ECM_STATUS_INTERVAL_MS,
David Brownellda741b82008-06-19 18:19:46 -0700198};
199
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200200static struct usb_endpoint_descriptor fs_ecm_in_desc = {
David Brownellda741b82008-06-19 18:19:46 -0700201 .bLength = USB_DT_ENDPOINT_SIZE,
202 .bDescriptorType = USB_DT_ENDPOINT,
203
204 .bEndpointAddress = USB_DIR_IN,
205 .bmAttributes = USB_ENDPOINT_XFER_BULK,
206};
207
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200208static struct usb_endpoint_descriptor fs_ecm_out_desc = {
David Brownellda741b82008-06-19 18:19:46 -0700209 .bLength = USB_DT_ENDPOINT_SIZE,
210 .bDescriptorType = USB_DT_ENDPOINT,
211
212 .bEndpointAddress = USB_DIR_OUT,
213 .bmAttributes = USB_ENDPOINT_XFER_BULK,
214};
215
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200216static struct usb_descriptor_header *ecm_fs_function[] = {
David Brownellda741b82008-06-19 18:19:46 -0700217 /* CDC ECM control descriptors */
Praveena Nadahallyd11519a2012-01-25 11:02:03 +0100218 (struct usb_descriptor_header *) &ecm_iad_descriptor,
David Brownellda741b82008-06-19 18:19:46 -0700219 (struct usb_descriptor_header *) &ecm_control_intf,
David Brownell33376c12008-08-18 17:45:07 -0700220 (struct usb_descriptor_header *) &ecm_header_desc,
David Brownellda741b82008-06-19 18:19:46 -0700221 (struct usb_descriptor_header *) &ecm_union_desc,
David Brownell33376c12008-08-18 17:45:07 -0700222 (struct usb_descriptor_header *) &ecm_desc,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700223
David Brownellda741b82008-06-19 18:19:46 -0700224 /* NOTE: status endpoint might need to be removed */
David Brownell33376c12008-08-18 17:45:07 -0700225 (struct usb_descriptor_header *) &fs_ecm_notify_desc,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700226
David Brownellda741b82008-06-19 18:19:46 -0700227 /* data interface, altsettings 0 and 1 */
228 (struct usb_descriptor_header *) &ecm_data_nop_intf,
229 (struct usb_descriptor_header *) &ecm_data_intf,
David Brownell33376c12008-08-18 17:45:07 -0700230 (struct usb_descriptor_header *) &fs_ecm_in_desc,
231 (struct usb_descriptor_header *) &fs_ecm_out_desc,
David Brownellda741b82008-06-19 18:19:46 -0700232 NULL,
233};
234
235/* high speed support: */
236
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200237static struct usb_endpoint_descriptor hs_ecm_notify_desc = {
David Brownellda741b82008-06-19 18:19:46 -0700238 .bLength = USB_DT_ENDPOINT_SIZE,
239 .bDescriptorType = USB_DT_ENDPOINT,
240
241 .bEndpointAddress = USB_DIR_IN,
242 .bmAttributes = USB_ENDPOINT_XFER_INT,
Harvey Harrison551509d2009-02-11 14:11:36 -0800243 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
Sebastian Andrzej Siewiorbcb2f992012-10-22 22:14:57 +0200244 .bInterval = USB_MS_TO_HS_INTERVAL(ECM_STATUS_INTERVAL_MS),
David Brownellda741b82008-06-19 18:19:46 -0700245};
Paul Zimmerman04617db2011-06-27 14:13:18 -0700246
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200247static struct usb_endpoint_descriptor hs_ecm_in_desc = {
David Brownellda741b82008-06-19 18:19:46 -0700248 .bLength = USB_DT_ENDPOINT_SIZE,
249 .bDescriptorType = USB_DT_ENDPOINT,
250
251 .bEndpointAddress = USB_DIR_IN,
252 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -0800253 .wMaxPacketSize = cpu_to_le16(512),
David Brownellda741b82008-06-19 18:19:46 -0700254};
255
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200256static struct usb_endpoint_descriptor hs_ecm_out_desc = {
David Brownellda741b82008-06-19 18:19:46 -0700257 .bLength = USB_DT_ENDPOINT_SIZE,
258 .bDescriptorType = USB_DT_ENDPOINT,
259
260 .bEndpointAddress = USB_DIR_OUT,
261 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -0800262 .wMaxPacketSize = cpu_to_le16(512),
David Brownellda741b82008-06-19 18:19:46 -0700263};
264
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200265static struct usb_descriptor_header *ecm_hs_function[] = {
David Brownellda741b82008-06-19 18:19:46 -0700266 /* CDC ECM control descriptors */
Praveena Nadahallyd11519a2012-01-25 11:02:03 +0100267 (struct usb_descriptor_header *) &ecm_iad_descriptor,
David Brownellda741b82008-06-19 18:19:46 -0700268 (struct usb_descriptor_header *) &ecm_control_intf,
David Brownell33376c12008-08-18 17:45:07 -0700269 (struct usb_descriptor_header *) &ecm_header_desc,
David Brownellda741b82008-06-19 18:19:46 -0700270 (struct usb_descriptor_header *) &ecm_union_desc,
David Brownell33376c12008-08-18 17:45:07 -0700271 (struct usb_descriptor_header *) &ecm_desc,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700272
David Brownellda741b82008-06-19 18:19:46 -0700273 /* NOTE: status endpoint might need to be removed */
David Brownell33376c12008-08-18 17:45:07 -0700274 (struct usb_descriptor_header *) &hs_ecm_notify_desc,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700275
David Brownellda741b82008-06-19 18:19:46 -0700276 /* data interface, altsettings 0 and 1 */
277 (struct usb_descriptor_header *) &ecm_data_nop_intf,
278 (struct usb_descriptor_header *) &ecm_data_intf,
David Brownell33376c12008-08-18 17:45:07 -0700279 (struct usb_descriptor_header *) &hs_ecm_in_desc,
280 (struct usb_descriptor_header *) &hs_ecm_out_desc,
David Brownellda741b82008-06-19 18:19:46 -0700281 NULL,
282};
283
Paul Zimmerman04617db2011-06-27 14:13:18 -0700284/* super speed support: */
285
286static struct usb_endpoint_descriptor ss_ecm_notify_desc = {
287 .bLength = USB_DT_ENDPOINT_SIZE,
288 .bDescriptorType = USB_DT_ENDPOINT,
289
290 .bEndpointAddress = USB_DIR_IN,
291 .bmAttributes = USB_ENDPOINT_XFER_INT,
292 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
Sebastian Andrzej Siewiorbcb2f992012-10-22 22:14:57 +0200293 .bInterval = USB_MS_TO_HS_INTERVAL(ECM_STATUS_INTERVAL_MS),
Paul Zimmerman04617db2011-06-27 14:13:18 -0700294};
295
296static struct usb_ss_ep_comp_descriptor ss_ecm_intr_comp_desc = {
297 .bLength = sizeof ss_ecm_intr_comp_desc,
298 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
299
300 /* the following 3 values can be tweaked if necessary */
301 /* .bMaxBurst = 0, */
302 /* .bmAttributes = 0, */
303 .wBytesPerInterval = cpu_to_le16(ECM_STATUS_BYTECOUNT),
304};
305
306static struct usb_endpoint_descriptor ss_ecm_in_desc = {
307 .bLength = USB_DT_ENDPOINT_SIZE,
308 .bDescriptorType = USB_DT_ENDPOINT,
309
310 .bEndpointAddress = USB_DIR_IN,
311 .bmAttributes = USB_ENDPOINT_XFER_BULK,
312 .wMaxPacketSize = cpu_to_le16(1024),
313};
314
315static struct usb_endpoint_descriptor ss_ecm_out_desc = {
316 .bLength = USB_DT_ENDPOINT_SIZE,
317 .bDescriptorType = USB_DT_ENDPOINT,
318
319 .bEndpointAddress = USB_DIR_OUT,
320 .bmAttributes = USB_ENDPOINT_XFER_BULK,
321 .wMaxPacketSize = cpu_to_le16(1024),
322};
323
324static struct usb_ss_ep_comp_descriptor ss_ecm_bulk_comp_desc = {
325 .bLength = sizeof ss_ecm_bulk_comp_desc,
326 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
327
328 /* the following 2 values can be tweaked if necessary */
329 /* .bMaxBurst = 0, */
330 /* .bmAttributes = 0, */
331};
332
333static struct usb_descriptor_header *ecm_ss_function[] = {
334 /* CDC ECM control descriptors */
Sebastian Andrzej Siewior585e3932012-10-22 22:14:55 +0200335 (struct usb_descriptor_header *) &ecm_iad_descriptor,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700336 (struct usb_descriptor_header *) &ecm_control_intf,
337 (struct usb_descriptor_header *) &ecm_header_desc,
338 (struct usb_descriptor_header *) &ecm_union_desc,
339 (struct usb_descriptor_header *) &ecm_desc,
340
341 /* NOTE: status endpoint might need to be removed */
342 (struct usb_descriptor_header *) &ss_ecm_notify_desc,
343 (struct usb_descriptor_header *) &ss_ecm_intr_comp_desc,
344
345 /* data interface, altsettings 0 and 1 */
346 (struct usb_descriptor_header *) &ecm_data_nop_intf,
347 (struct usb_descriptor_header *) &ecm_data_intf,
348 (struct usb_descriptor_header *) &ss_ecm_in_desc,
349 (struct usb_descriptor_header *) &ss_ecm_bulk_comp_desc,
350 (struct usb_descriptor_header *) &ss_ecm_out_desc,
351 (struct usb_descriptor_header *) &ss_ecm_bulk_comp_desc,
352 NULL,
353};
354
David Brownellda741b82008-06-19 18:19:46 -0700355/* string descriptors: */
356
357static struct usb_string ecm_string_defs[] = {
358 [0].s = "CDC Ethernet Control Model (ECM)",
Sebastian Andrzej Siewior1616e992012-10-22 22:15:10 +0200359 [1].s = "",
David Brownellda741b82008-06-19 18:19:46 -0700360 [2].s = "CDC Ethernet Data",
Praveena Nadahallyd11519a2012-01-25 11:02:03 +0100361 [3].s = "CDC ECM",
David Brownellda741b82008-06-19 18:19:46 -0700362 { } /* end of list */
363};
364
365static struct usb_gadget_strings ecm_string_table = {
366 .language = 0x0409, /* en-us */
367 .strings = ecm_string_defs,
368};
369
370static struct usb_gadget_strings *ecm_strings[] = {
371 &ecm_string_table,
372 NULL,
373};
374
375/*-------------------------------------------------------------------------*/
376
377static void ecm_do_notify(struct f_ecm *ecm)
378{
379 struct usb_request *req = ecm->notify_req;
380 struct usb_cdc_notification *event;
381 struct usb_composite_dev *cdev = ecm->port.func.config->cdev;
382 __le32 *data;
383 int status;
384
385 /* notification already in flight? */
386 if (!req)
387 return;
388
389 event = req->buf;
390 switch (ecm->notify_state) {
391 case ECM_NOTIFY_NONE:
392 return;
393
394 case ECM_NOTIFY_CONNECT:
395 event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION;
396 if (ecm->is_open)
397 event->wValue = cpu_to_le16(1);
398 else
399 event->wValue = cpu_to_le16(0);
400 event->wLength = 0;
401 req->length = sizeof *event;
402
403 DBG(cdev, "notify connect %s\n",
404 ecm->is_open ? "true" : "false");
405 ecm->notify_state = ECM_NOTIFY_SPEED;
406 break;
407
408 case ECM_NOTIFY_SPEED:
409 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE;
410 event->wValue = cpu_to_le16(0);
411 event->wLength = cpu_to_le16(8);
David Brownell33376c12008-08-18 17:45:07 -0700412 req->length = ECM_STATUS_BYTECOUNT;
David Brownellda741b82008-06-19 18:19:46 -0700413
414 /* SPEED_CHANGE data is up/down speeds in bits/sec */
415 data = req->buf + sizeof *event;
David Brownell33376c12008-08-18 17:45:07 -0700416 data[0] = cpu_to_le32(ecm_bitrate(cdev->gadget));
David Brownellda741b82008-06-19 18:19:46 -0700417 data[1] = data[0];
418
David Brownell33376c12008-08-18 17:45:07 -0700419 DBG(cdev, "notify speed %d\n", ecm_bitrate(cdev->gadget));
David Brownellda741b82008-06-19 18:19:46 -0700420 ecm->notify_state = ECM_NOTIFY_NONE;
421 break;
422 }
423 event->bmRequestType = 0xA1;
424 event->wIndex = cpu_to_le16(ecm->ctrl_id);
425
426 ecm->notify_req = NULL;
427 status = usb_ep_queue(ecm->notify, req, GFP_ATOMIC);
428 if (status < 0) {
429 ecm->notify_req = req;
430 DBG(cdev, "notify --> %d\n", status);
431 }
432}
433
434static void ecm_notify(struct f_ecm *ecm)
435{
436 /* NOTE on most versions of Linux, host side cdc-ethernet
437 * won't listen for notifications until its netdevice opens.
438 * The first notification then sits in the FIFO for a long
439 * time, and the second one is queued.
440 */
441 ecm->notify_state = ECM_NOTIFY_CONNECT;
442 ecm_do_notify(ecm);
443}
444
445static void ecm_notify_complete(struct usb_ep *ep, struct usb_request *req)
446{
447 struct f_ecm *ecm = req->context;
448 struct usb_composite_dev *cdev = ecm->port.func.config->cdev;
449 struct usb_cdc_notification *event = req->buf;
450
451 switch (req->status) {
452 case 0:
453 /* no fault */
454 break;
455 case -ECONNRESET:
456 case -ESHUTDOWN:
457 ecm->notify_state = ECM_NOTIFY_NONE;
458 break;
459 default:
460 DBG(cdev, "event %02x --> %d\n",
461 event->bNotificationType, req->status);
462 break;
463 }
464 ecm->notify_req = req;
465 ecm_do_notify(ecm);
466}
467
468static int ecm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
469{
470 struct f_ecm *ecm = func_to_ecm(f);
471 struct usb_composite_dev *cdev = f->config->cdev;
472 struct usb_request *req = cdev->req;
473 int value = -EOPNOTSUPP;
474 u16 w_index = le16_to_cpu(ctrl->wIndex);
475 u16 w_value = le16_to_cpu(ctrl->wValue);
476 u16 w_length = le16_to_cpu(ctrl->wLength);
477
478 /* composite driver infrastructure handles everything except
479 * CDC class messages; interface activation uses set_alt().
480 */
481 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
482 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
483 | USB_CDC_SET_ETHERNET_PACKET_FILTER:
484 /* see 6.2.30: no data, wIndex = interface,
485 * wValue = packet filter bitmap
486 */
487 if (w_length != 0 || w_index != ecm->ctrl_id)
488 goto invalid;
489 DBG(cdev, "packet filter %02x\n", w_value);
490 /* REVISIT locking of cdc_filter. This assumes the UDC
491 * driver won't have a concurrent packet TX irq running on
492 * another CPU; or that if it does, this write is atomic...
493 */
494 ecm->port.cdc_filter = w_value;
495 value = 0;
496 break;
497
498 /* and optionally:
499 * case USB_CDC_SEND_ENCAPSULATED_COMMAND:
500 * case USB_CDC_GET_ENCAPSULATED_RESPONSE:
501 * case USB_CDC_SET_ETHERNET_MULTICAST_FILTERS:
502 * case USB_CDC_SET_ETHERNET_PM_PATTERN_FILTER:
503 * case USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER:
504 * case USB_CDC_GET_ETHERNET_STATISTIC:
505 */
506
507 default:
508invalid:
509 DBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
510 ctrl->bRequestType, ctrl->bRequest,
511 w_value, w_index, w_length);
512 }
513
514 /* respond with data transfer or status phase? */
515 if (value >= 0) {
516 DBG(cdev, "ecm req%02x.%02x v%04x i%04x l%d\n",
517 ctrl->bRequestType, ctrl->bRequest,
518 w_value, w_index, w_length);
519 req->zero = 0;
520 req->length = value;
521 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
522 if (value < 0)
523 ERROR(cdev, "ecm req %02x.%02x response err %d\n",
524 ctrl->bRequestType, ctrl->bRequest,
525 value);
526 }
527
528 /* device either stalls (value < 0) or reports success */
529 return value;
530}
531
532
533static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
534{
535 struct f_ecm *ecm = func_to_ecm(f);
536 struct usb_composite_dev *cdev = f->config->cdev;
537
538 /* Control interface has only altsetting 0 */
539 if (intf == ecm->ctrl_id) {
540 if (alt != 0)
541 goto fail;
542
543 if (ecm->notify->driver_data) {
544 VDBG(cdev, "reset ecm control %d\n", intf);
545 usb_ep_disable(ecm->notify);
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300546 }
547 if (!(ecm->notify->desc)) {
David Brownellda741b82008-06-19 18:19:46 -0700548 VDBG(cdev, "init ecm ctrl %d\n", intf);
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300549 if (config_ep_by_speed(cdev->gadget, f, ecm->notify))
550 goto fail;
David Brownellda741b82008-06-19 18:19:46 -0700551 }
Tatyana Brokhman72c973d2011-06-28 16:33:48 +0300552 usb_ep_enable(ecm->notify);
David Brownellda741b82008-06-19 18:19:46 -0700553 ecm->notify->driver_data = ecm;
554
555 /* Data interface has two altsettings, 0 and 1 */
556 } else if (intf == ecm->data_id) {
557 if (alt > 1)
558 goto fail;
559
560 if (ecm->port.in_ep->driver_data) {
561 DBG(cdev, "reset ecm\n");
562 gether_disconnect(&ecm->port);
563 }
564
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300565 if (!ecm->port.in_ep->desc ||
566 !ecm->port.out_ep->desc) {
David Brownellda741b82008-06-19 18:19:46 -0700567 DBG(cdev, "init ecm\n");
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300568 if (config_ep_by_speed(cdev->gadget, f,
569 ecm->port.in_ep) ||
570 config_ep_by_speed(cdev->gadget, f,
571 ecm->port.out_ep)) {
572 ecm->port.in_ep->desc = NULL;
573 ecm->port.out_ep->desc = NULL;
574 goto fail;
575 }
David Brownellda741b82008-06-19 18:19:46 -0700576 }
577
578 /* CDC Ethernet only sends data in non-default altsettings.
579 * Changing altsettings resets filters, statistics, etc.
580 */
581 if (alt == 1) {
582 struct net_device *net;
583
584 /* Enable zlps by default for ECM conformance;
Christoph Egger90f79762010-02-05 13:24:12 +0100585 * override for musb_hdrc (avoids txdma ovhead).
David Brownellda741b82008-06-19 18:19:46 -0700586 */
Christoph Egger90f79762010-02-05 13:24:12 +0100587 ecm->port.is_zlp_ok = !(gadget_is_musbhdrc(cdev->gadget)
David Brownellda741b82008-06-19 18:19:46 -0700588 );
589 ecm->port.cdc_filter = DEFAULT_FILTER;
590 DBG(cdev, "activate ecm\n");
591 net = gether_connect(&ecm->port);
592 if (IS_ERR(net))
593 return PTR_ERR(net);
594 }
595
596 /* NOTE this can be a minor disagreement with the ECM spec,
597 * which says speed notifications will "always" follow
598 * connection notifications. But we allow one connect to
599 * follow another (if the first is in flight), and instead
600 * just guarantee that a speed notification is always sent.
601 */
602 ecm_notify(ecm);
603 } else
604 goto fail;
605
606 return 0;
607fail:
608 return -EINVAL;
609}
610
611/* Because the data interface supports multiple altsettings,
612 * this ECM function *MUST* implement a get_alt() method.
613 */
614static int ecm_get_alt(struct usb_function *f, unsigned intf)
615{
616 struct f_ecm *ecm = func_to_ecm(f);
617
618 if (intf == ecm->ctrl_id)
619 return 0;
620 return ecm->port.in_ep->driver_data ? 1 : 0;
621}
622
623static void ecm_disable(struct usb_function *f)
624{
625 struct f_ecm *ecm = func_to_ecm(f);
626 struct usb_composite_dev *cdev = f->config->cdev;
627
628 DBG(cdev, "ecm deactivated\n");
629
630 if (ecm->port.in_ep->driver_data)
631 gether_disconnect(&ecm->port);
632
633 if (ecm->notify->driver_data) {
634 usb_ep_disable(ecm->notify);
635 ecm->notify->driver_data = NULL;
Tatyana Brokhman72c973d2011-06-28 16:33:48 +0300636 ecm->notify->desc = NULL;
David Brownellda741b82008-06-19 18:19:46 -0700637 }
638}
639
640/*-------------------------------------------------------------------------*/
641
642/*
643 * Callbacks let us notify the host about connect/disconnect when the
644 * net device is opened or closed.
645 *
646 * For testing, note that link states on this side include both opened
647 * and closed variants of:
648 *
649 * - disconnected/unconfigured
650 * - configured but inactive (data alt 0)
651 * - configured and active (data alt 1)
652 *
653 * Each needs to be tested with unplug, rmmod, SET_CONFIGURATION, and
654 * SET_INTERFACE (altsetting). Remember also that "configured" doesn't
655 * imply the host is actually polling the notification endpoint, and
656 * likewise that "active" doesn't imply it's actually using the data
657 * endpoints for traffic.
658 */
659
660static void ecm_open(struct gether *geth)
661{
662 struct f_ecm *ecm = func_to_ecm(&geth->func);
663
664 DBG(ecm->port.func.config->cdev, "%s\n", __func__);
665
666 ecm->is_open = true;
667 ecm_notify(ecm);
668}
669
670static void ecm_close(struct gether *geth)
671{
672 struct f_ecm *ecm = func_to_ecm(&geth->func);
673
674 DBG(ecm->port.func.config->cdev, "%s\n", __func__);
675
676 ecm->is_open = false;
677 ecm_notify(ecm);
678}
679
680/*-------------------------------------------------------------------------*/
681
682/* ethernet function driver setup/binding */
683
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200684static int
David Brownellda741b82008-06-19 18:19:46 -0700685ecm_bind(struct usb_configuration *c, struct usb_function *f)
686{
687 struct usb_composite_dev *cdev = c->cdev;
688 struct f_ecm *ecm = func_to_ecm(f);
Andrzej Pietrasiewicz06b72592013-05-23 10:32:05 +0200689 struct usb_string *us;
David Brownellda741b82008-06-19 18:19:46 -0700690 int status;
691 struct usb_ep *ep;
692
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +0200693#ifndef USBF_ECM_INCLUDED
694 struct f_ecm_opts *ecm_opts;
695
696 if (!can_support_ecm(cdev->gadget))
697 return -EINVAL;
698
699 ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst);
700
701 /*
702 * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
703 * configurations are bound in sequence with list_for_each_entry,
704 * in each configuration its functions are bound in sequence
705 * with list_for_each_entry, so we assume no race condition
706 * with regard to ecm_opts->bound access
707 */
708 if (!ecm_opts->bound) {
709 gether_set_gadget(ecm_opts->net, cdev->gadget);
710 status = gether_register_netdev(ecm_opts->net);
711 if (status)
712 return status;
713 ecm_opts->bound = true;
714 }
715#endif
Andrzej Pietrasiewicz06b72592013-05-23 10:32:05 +0200716 us = usb_gstrings_attach(cdev, ecm_strings,
717 ARRAY_SIZE(ecm_string_defs));
718 if (IS_ERR(us))
719 return PTR_ERR(us);
720 ecm_control_intf.iInterface = us[0].id;
721 ecm_data_intf.iInterface = us[2].id;
722 ecm_desc.iMACAddress = us[1].id;
723 ecm_iad_descriptor.iFunction = us[3].id;
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +0200724
David Brownellda741b82008-06-19 18:19:46 -0700725 /* allocate instance-specific interface IDs */
726 status = usb_interface_id(c, f);
727 if (status < 0)
728 goto fail;
729 ecm->ctrl_id = status;
Praveena Nadahallyd11519a2012-01-25 11:02:03 +0100730 ecm_iad_descriptor.bFirstInterface = status;
David Brownellda741b82008-06-19 18:19:46 -0700731
732 ecm_control_intf.bInterfaceNumber = status;
733 ecm_union_desc.bMasterInterface0 = status;
734
735 status = usb_interface_id(c, f);
736 if (status < 0)
737 goto fail;
738 ecm->data_id = status;
739
740 ecm_data_nop_intf.bInterfaceNumber = status;
741 ecm_data_intf.bInterfaceNumber = status;
742 ecm_union_desc.bSlaveInterface0 = status;
743
744 status = -ENODEV;
745
746 /* allocate instance-specific endpoints */
David Brownell33376c12008-08-18 17:45:07 -0700747 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_in_desc);
David Brownellda741b82008-06-19 18:19:46 -0700748 if (!ep)
749 goto fail;
750 ecm->port.in_ep = ep;
751 ep->driver_data = cdev; /* claim */
752
David Brownell33376c12008-08-18 17:45:07 -0700753 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_out_desc);
David Brownellda741b82008-06-19 18:19:46 -0700754 if (!ep)
755 goto fail;
756 ecm->port.out_ep = ep;
757 ep->driver_data = cdev; /* claim */
758
759 /* NOTE: a status/notification endpoint is *OPTIONAL* but we
760 * don't treat it that way. It's simpler, and some newer CDC
761 * profiles (wireless handsets) no longer treat it as optional.
762 */
David Brownell33376c12008-08-18 17:45:07 -0700763 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_notify_desc);
David Brownellda741b82008-06-19 18:19:46 -0700764 if (!ep)
765 goto fail;
766 ecm->notify = ep;
767 ep->driver_data = cdev; /* claim */
768
769 status = -ENOMEM;
770
771 /* allocate notification request and buffer */
772 ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
773 if (!ecm->notify_req)
774 goto fail;
David Brownell33376c12008-08-18 17:45:07 -0700775 ecm->notify_req->buf = kmalloc(ECM_STATUS_BYTECOUNT, GFP_KERNEL);
David Brownellda741b82008-06-19 18:19:46 -0700776 if (!ecm->notify_req->buf)
777 goto fail;
778 ecm->notify_req->context = ecm;
779 ecm->notify_req->complete = ecm_notify_complete;
780
David Brownellda741b82008-06-19 18:19:46 -0700781 /* support all relevant hardware speeds... we expect that when
782 * hardware is dual speed, all bulk-capable endpoints work at
783 * both speeds
784 */
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200785 hs_ecm_in_desc.bEndpointAddress = fs_ecm_in_desc.bEndpointAddress;
786 hs_ecm_out_desc.bEndpointAddress = fs_ecm_out_desc.bEndpointAddress;
787 hs_ecm_notify_desc.bEndpointAddress =
788 fs_ecm_notify_desc.bEndpointAddress;
David Brownellda741b82008-06-19 18:19:46 -0700789
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200790 ss_ecm_in_desc.bEndpointAddress = fs_ecm_in_desc.bEndpointAddress;
791 ss_ecm_out_desc.bEndpointAddress = fs_ecm_out_desc.bEndpointAddress;
792 ss_ecm_notify_desc.bEndpointAddress =
793 fs_ecm_notify_desc.bEndpointAddress;
David Brownellda741b82008-06-19 18:19:46 -0700794
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200795 status = usb_assign_descriptors(f, ecm_fs_function, ecm_hs_function,
796 ecm_ss_function);
797 if (status)
798 goto fail;
Paul Zimmerman04617db2011-06-27 14:13:18 -0700799
David Brownellda741b82008-06-19 18:19:46 -0700800 /* NOTE: all that is done without knowing or caring about
801 * the network link ... which is unavailable to this code
802 * until we're activated via set_alt().
803 */
804
805 ecm->port.open = ecm_open;
806 ecm->port.close = ecm_close;
807
808 DBG(cdev, "CDC Ethernet: %s speed IN/%s OUT/%s NOTIFY/%s\n",
Paul Zimmerman04617db2011-06-27 14:13:18 -0700809 gadget_is_superspeed(c->cdev->gadget) ? "super" :
David Brownellda741b82008-06-19 18:19:46 -0700810 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
811 ecm->port.in_ep->name, ecm->port.out_ep->name,
812 ecm->notify->name);
813 return 0;
814
815fail:
David Brownellda741b82008-06-19 18:19:46 -0700816 if (ecm->notify_req) {
817 kfree(ecm->notify_req->buf);
818 usb_ep_free_request(ecm->notify, ecm->notify_req);
819 }
820
821 /* we might as well release our claims on endpoints */
822 if (ecm->notify)
823 ecm->notify->driver_data = NULL;
Sebastian Andrzej Siewiore79cc612012-10-22 22:15:00 +0200824 if (ecm->port.out_ep)
David Brownellda741b82008-06-19 18:19:46 -0700825 ecm->port.out_ep->driver_data = NULL;
Sebastian Andrzej Siewiore79cc612012-10-22 22:15:00 +0200826 if (ecm->port.in_ep)
David Brownellda741b82008-06-19 18:19:46 -0700827 ecm->port.in_ep->driver_data = NULL;
828
829 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
830
831 return status;
832}
833
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +0200834#ifdef USBF_ECM_INCLUDED
835
David Brownellda741b82008-06-19 18:19:46 -0700836static void
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +0200837ecm_old_unbind(struct usb_configuration *c, struct usb_function *f)
David Brownellda741b82008-06-19 18:19:46 -0700838{
839 struct f_ecm *ecm = func_to_ecm(f);
840
841 DBG(c->cdev, "ecm unbind\n");
842
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200843 usb_free_all_descriptors(f);
David Brownellda741b82008-06-19 18:19:46 -0700844
845 kfree(ecm->notify_req->buf);
846 usb_ep_free_request(ecm->notify, ecm->notify_req);
David Brownellda741b82008-06-19 18:19:46 -0700847 kfree(ecm);
848}
849
850/**
851 * ecm_bind_config - add CDC Ethernet network link to a configuration
852 * @c: the configuration to support the network link
853 * @ethaddr: a buffer in which the ethernet address of the host side
854 * side of the link was recorded
Robert P. J. Day21c7dee2013-05-02 10:28:33 -0400855 * @dev: eth_dev structure
David Brownellda741b82008-06-19 18:19:46 -0700856 * Context: single threaded during gadget setup
857 *
858 * Returns zero on success, else negative errno.
859 *
860 * Caller must have called @gether_setup(). Caller is also responsible
861 * for calling @gether_cleanup() before module unload.
862 */
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200863int
Sebastian Andrzej Siewiord6a01432012-12-23 21:10:12 +0100864ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
865 struct eth_dev *dev)
David Brownellda741b82008-06-19 18:19:46 -0700866{
867 struct f_ecm *ecm;
868 int status;
869
870 if (!can_support_ecm(c->cdev->gadget) || !ethaddr)
871 return -EINVAL;
872
David Brownellda741b82008-06-19 18:19:46 -0700873 /* allocate and initialize one new instance */
874 ecm = kzalloc(sizeof *ecm, GFP_KERNEL);
875 if (!ecm)
876 return -ENOMEM;
877
878 /* export host's Ethernet address in CDC format */
Andy Shevchenko8c7ca992012-07-06 18:30:21 +0300879 snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr);
David Brownellda741b82008-06-19 18:19:46 -0700880 ecm_string_defs[1].s = ecm->ethaddr;
881
Sebastian Andrzej Siewiord6a01432012-12-23 21:10:12 +0100882 ecm->port.ioport = dev;
David Brownellda741b82008-06-19 18:19:46 -0700883 ecm->port.cdc_filter = DEFAULT_FILTER;
884
885 ecm->port.func.name = "cdc_ethernet";
David Brownellda741b82008-06-19 18:19:46 -0700886 /* descriptors are per-instance copies */
887 ecm->port.func.bind = ecm_bind;
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +0200888 ecm->port.func.unbind = ecm_old_unbind;
David Brownellda741b82008-06-19 18:19:46 -0700889 ecm->port.func.set_alt = ecm_set_alt;
890 ecm->port.func.get_alt = ecm_get_alt;
891 ecm->port.func.setup = ecm_setup;
892 ecm->port.func.disable = ecm_disable;
893
894 status = usb_add_function(c, &ecm->port.func);
Sebastian Andrzej Siewior1616e992012-10-22 22:15:10 +0200895 if (status)
David Brownellda741b82008-06-19 18:19:46 -0700896 kfree(ecm);
David Brownellda741b82008-06-19 18:19:46 -0700897 return status;
898}
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +0200899
900#else
901
902static void ecm_free_inst(struct usb_function_instance *f)
903{
904 struct f_ecm_opts *opts;
905
906 opts = container_of(f, struct f_ecm_opts, func_inst);
907 if (opts->bound)
908 gether_cleanup(netdev_priv(opts->net));
909 else
910 free_netdev(opts->net);
911 kfree(opts);
912}
913
914static struct usb_function_instance *ecm_alloc_inst(void)
915{
916 struct f_ecm_opts *opts;
917
918 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
919 if (!opts)
920 return ERR_PTR(-ENOMEM);
921
922 opts->func_inst.free_func_inst = ecm_free_inst;
923 opts->net = gether_setup_default();
924 if (IS_ERR(opts->net))
925 return ERR_PTR(PTR_ERR(opts->net));
926
927 return &opts->func_inst;
928}
929
930static void ecm_free(struct usb_function *f)
931{
932 struct f_ecm *ecm;
933
934 ecm = func_to_ecm(f);
935 kfree(ecm);
936}
937
938static void ecm_unbind(struct usb_configuration *c, struct usb_function *f)
939{
940 struct f_ecm *ecm = func_to_ecm(f);
941
942 DBG(c->cdev, "ecm unbind\n");
943
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +0200944 usb_free_all_descriptors(f);
945
946 kfree(ecm->notify_req->buf);
947 usb_ep_free_request(ecm->notify, ecm->notify_req);
948}
949
950struct usb_function *ecm_alloc(struct usb_function_instance *fi)
951{
952 struct f_ecm *ecm;
953 struct f_ecm_opts *opts;
954 int status;
955
956 /* allocate and initialize one new instance */
957 ecm = kzalloc(sizeof(*ecm), GFP_KERNEL);
958 if (!ecm)
959 return ERR_PTR(-ENOMEM);
960
961 opts = container_of(fi, struct f_ecm_opts, func_inst);
962
963 /* export host's Ethernet address in CDC format */
964 status = gether_get_host_addr_cdc(opts->net, ecm->ethaddr,
965 sizeof(ecm->ethaddr));
966 if (status < 12) {
967 kfree(ecm);
968 return ERR_PTR(-EINVAL);
969 }
970 ecm_string_defs[1].s = ecm->ethaddr;
971
972 ecm->port.ioport = netdev_priv(opts->net);
973 ecm->port.cdc_filter = DEFAULT_FILTER;
974
975 ecm->port.func.name = "cdc_ethernet";
Andrzej Pietrasiewiczfee562a2013-05-23 10:32:03 +0200976 /* descriptors are per-instance copies */
977 ecm->port.func.bind = ecm_bind;
978 ecm->port.func.unbind = ecm_unbind;
979 ecm->port.func.set_alt = ecm_set_alt;
980 ecm->port.func.get_alt = ecm_get_alt;
981 ecm->port.func.setup = ecm_setup;
982 ecm->port.func.disable = ecm_disable;
983 ecm->port.func.free_func = ecm_free;
984
985 return &ecm->port.func;
986}
987
988DECLARE_USB_FUNCTION_INIT(ecm, ecm_alloc_inst, ecm_alloc);
989MODULE_LICENSE("GPL");
990MODULE_AUTHOR("David Brownell");
991
992#endif