iPXE
ecm.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stdint.h>
27 #include <errno.h>
28 #include <ipxe/netdevice.h>
29 #include <ipxe/ethernet.h>
30 #include <ipxe/if_ether.h>
31 #include <ipxe/base16.h>
32 #include <ipxe/profile.h>
33 #include <ipxe/usb.h>
34 #include "ecm.h"
35 
36 /** @file
37  *
38  * CDC-ECM USB Ethernet driver
39  *
40  */
41 
42 /** Interrupt completion profiler */
43 static struct profiler ecm_intr_profiler __profiler =
44  { .name = "ecm.intr" };
45 
46 /** Bulk IN completion profiler */
47 static struct profiler ecm_in_profiler __profiler =
48  { .name = "ecm.in" };
49 
50 /** Bulk OUT profiler */
51 static struct profiler ecm_out_profiler __profiler =
52  { .name = "ecm.out" };
53 
54 /******************************************************************************
55  *
56  * Ethernet functional descriptor
57  *
58  ******************************************************************************
59  */
60 
61 /**
62  * Locate Ethernet functional descriptor
63  *
64  * @v config Configuration descriptor
65  * @v interface Interface descriptor
66  * @ret desc Descriptor, or NULL if not found
67  */
71  struct ecm_ethernet_descriptor *desc;
72 
73  for_each_interface_descriptor ( desc, config, interface ) {
74  if ( ( desc->header.type == USB_CS_INTERFACE_DESCRIPTOR ) &&
75  ( desc->subtype == CDC_SUBTYPE_ETHERNET ) )
76  return desc;
77  }
78  return NULL;
79 }
80 
81 /**
82  * Get hardware MAC address
83  *
84  * @v usb USB device
85  * @v desc Ethernet functional descriptor
86  * @v hw_addr Hardware address to fill in
87  * @ret rc Return status code
88  */
89 int ecm_fetch_mac ( struct usb_device *usb,
90  struct ecm_ethernet_descriptor *desc, uint8_t *hw_addr ) {
91  char buf[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
92  int len;
93  int rc;
94 
95  /* Fetch MAC address string */
96  len = usb_get_string_descriptor ( usb, desc->mac, 0, buf,
97  sizeof ( buf ) );
98  if ( len < 0 ) {
99  rc = len;
100  return rc;
101  }
102 
103  /* Sanity check */
104  if ( len != ( ( int ) ( sizeof ( buf ) - 1 /* NUL */ ) ) ) {
105  DBGC ( usb, "USB %s has invalid ECM MAC \"%s\"\n",
106  usb->name, buf );
107  return -EINVAL;
108  }
109 
110  /* Decode MAC address */
111  len = base16_decode ( buf, hw_addr, ETH_ALEN );
112  if ( len < 0 ) {
113  rc = len;
114  DBGC ( usb, "USB %s could not decode ECM MAC \"%s\": %s\n",
115  usb->name, buf, strerror ( rc ) );
116  return rc;
117  }
118 
119  return 0;
120 }
121 
122 /******************************************************************************
123  *
124  * CDC-ECM communications interface
125  *
126  ******************************************************************************
127  */
128 
129 /**
130  * Complete interrupt transfer
131  *
132  * @v ep USB endpoint
133  * @v iobuf I/O buffer
134  * @v rc Completion status code
135  */
136 static void ecm_intr_complete ( struct usb_endpoint *ep,
137  struct io_buffer *iobuf, int rc ) {
138  struct ecm_device *ecm = container_of ( ep, struct ecm_device,
139  usbnet.intr );
140  struct net_device *netdev = ecm->netdev;
141  struct usb_setup_packet *message;
142  size_t len = iob_len ( iobuf );
143 
144  /* Profile completions */
145  profile_start ( &ecm_intr_profiler );
146 
147  /* Ignore packets cancelled when the endpoint closes */
148  if ( ! ep->open )
149  goto ignore;
150 
151  /* Drop packets with errors */
152  if ( rc != 0 ) {
153  DBGC ( ecm, "ECM %p interrupt failed: %s\n",
154  ecm, strerror ( rc ) );
155  DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
156  goto error;
157  }
158 
159  /* Extract message header */
160  if ( len < sizeof ( *message ) ) {
161  DBGC ( ecm, "ECM %p underlength interrupt:\n", ecm );
162  DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
163  rc = -EINVAL;
164  goto error;
165  }
166  message = iobuf->data;
167 
168  /* Parse message header */
169  switch ( message->request ) {
170 
172  if ( message->value && ! netdev_link_ok ( netdev ) ) {
173  DBGC ( ecm, "ECM %p link up\n", ecm );
175  } else if ( netdev_link_ok ( netdev ) && ! message->value ) {
176  DBGC ( ecm, "ECM %p link down\n", ecm );
178  }
179  break;
180 
182  /* Ignore */
183  break;
184 
185  default:
186  DBGC ( ecm, "ECM %p unrecognised interrupt:\n", ecm );
187  DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
188  rc = -ENOTSUP;
189  goto error;
190  }
191 
192  /* Free I/O buffer */
193  free_iob ( iobuf );
194  profile_stop ( &ecm_intr_profiler );
195 
196  return;
197 
198  error:
199  netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
200  ignore:
201  free_iob ( iobuf );
202  return;
203 }
204 
205 /** Interrupt endpoint operations */
208 };
209 
210 /******************************************************************************
211  *
212  * CDC-ECM data interface
213  *
214  ******************************************************************************
215  */
216 
217 /**
218  * Complete bulk IN transfer
219  *
220  * @v ep USB endpoint
221  * @v iobuf I/O buffer
222  * @v rc Completion status code
223  */
224 static void ecm_in_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf,
225  int rc ) {
226  struct ecm_device *ecm = container_of ( ep, struct ecm_device,
227  usbnet.in );
228  struct net_device *netdev = ecm->netdev;
229 
230  /* Profile receive completions */
231  profile_start ( &ecm_in_profiler );
232 
233  /* Ignore packets cancelled when the endpoint closes */
234  if ( ! ep->open )
235  goto ignore;
236 
237  /* Record USB errors against the network device */
238  if ( rc != 0 ) {
239  DBGC ( ecm, "ECM %p bulk IN failed: %s\n",
240  ecm, strerror ( rc ) );
241  goto error;
242  }
243 
244  /* Hand off to network stack */
245  netdev_rx ( netdev, iob_disown ( iobuf ) );
246 
247  profile_stop ( &ecm_in_profiler );
248  return;
249 
250  error:
251  netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
252  ignore:
253  free_iob ( iobuf );
254 }
255 
256 /** Bulk IN endpoint operations */
259 };
260 
261 /**
262  * Transmit packet
263  *
264  * @v ecm CDC-ECM device
265  * @v iobuf I/O buffer
266  * @ret rc Return status code
267  */
268 static int ecm_out_transmit ( struct ecm_device *ecm,
269  struct io_buffer *iobuf ) {
270  int rc;
271 
272  /* Profile transmissions */
273  profile_start ( &ecm_out_profiler );
274 
275  /* Enqueue I/O buffer */
276  if ( ( rc = usb_stream ( &ecm->usbnet.out, iobuf, 1 ) ) != 0 )
277  return rc;
278 
279  profile_stop ( &ecm_out_profiler );
280  return 0;
281 }
282 
283 /**
284  * Complete bulk OUT transfer
285  *
286  * @v ep USB endpoint
287  * @v iobuf I/O buffer
288  * @v rc Completion status code
289  */
290 static void ecm_out_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf,
291  int rc ) {
292  struct ecm_device *ecm = container_of ( ep, struct ecm_device,
293  usbnet.out );
294  struct net_device *netdev = ecm->netdev;
295 
296  /* Report TX completion */
297  netdev_tx_complete_err ( netdev, iobuf, rc );
298 }
299 
300 /** Bulk OUT endpoint operations */
303 };
304 
305 /******************************************************************************
306  *
307  * Network device interface
308  *
309  ******************************************************************************
310  */
311 
312 /**
313  * Open network device
314  *
315  * @v netdev Network device
316  * @ret rc Return status code
317  */
318 static int ecm_open ( struct net_device *netdev ) {
319  struct ecm_device *ecm = netdev->priv;
320  struct usb_device *usb = ecm->usb;
321  unsigned int filter;
322  int rc;
323 
324  /* Open USB network device */
325  if ( ( rc = usbnet_open ( &ecm->usbnet ) ) != 0 ) {
326  DBGC ( ecm, "ECM %p could not open: %s\n",
327  ecm, strerror ( rc ) );
328  goto err_open;
329  }
330 
331  /* Set packet filter */
337  filter, ecm->usbnet.comms, NULL, 0 ) ) != 0 ){
338  DBGC ( ecm, "ECM %p could not set packet filter: %s\n",
339  ecm, strerror ( rc ) );
340  goto err_set_filter;
341  }
342 
343  return 0;
344 
345  err_set_filter:
346  usbnet_close ( &ecm->usbnet );
347  err_open:
348  return rc;
349 }
350 
351 /**
352  * Close network device
353  *
354  * @v netdev Network device
355  */
356 static void ecm_close ( struct net_device *netdev ) {
357  struct ecm_device *ecm = netdev->priv;
358 
359  /* Close USB network device */
360  usbnet_close ( &ecm->usbnet );
361 }
362 
363 /**
364  * Transmit packet
365  *
366  * @v netdev Network device
367  * @v iobuf I/O buffer
368  * @ret rc Return status code
369  */
370 static int ecm_transmit ( struct net_device *netdev,
371  struct io_buffer *iobuf ) {
372  struct ecm_device *ecm = netdev->priv;
373  int rc;
374 
375  /* Transmit packet */
376  if ( ( rc = ecm_out_transmit ( ecm, iobuf ) ) != 0 )
377  return rc;
378 
379  return 0;
380 }
381 
382 /**
383  * Poll for completed and received packets
384  *
385  * @v netdev Network device
386  */
387 static void ecm_poll ( struct net_device *netdev ) {
388  struct ecm_device *ecm = netdev->priv;
389  int rc;
390 
391  /* Poll USB bus */
392  usb_poll ( ecm->bus );
393 
394  /* Refill endpoints */
395  if ( ( rc = usbnet_refill ( &ecm->usbnet ) ) != 0 )
396  netdev_rx_err ( netdev, NULL, rc );
397 }
398 
399 /** CDC-ECM network device operations */
401  .open = ecm_open,
402  .close = ecm_close,
403  .transmit = ecm_transmit,
404  .poll = ecm_poll,
405 };
406 
407 /******************************************************************************
408  *
409  * USB interface
410  *
411  ******************************************************************************
412  */
413 
414 /**
415  * Probe device
416  *
417  * @v func USB function
418  * @v config Configuration descriptor
419  * @ret rc Return status code
420  */
421 static int ecm_probe ( struct usb_function *func,
422  struct usb_configuration_descriptor *config ) {
423  struct usb_device *usb = func->usb;
424  struct net_device *netdev;
425  struct ecm_device *ecm;
426  struct usb_interface_descriptor *comms;
427  struct ecm_ethernet_descriptor *ethernet;
428  int rc;
429 
430  /* Allocate and initialise structure */
431  netdev = alloc_etherdev ( sizeof ( *ecm ) );
432  if ( ! netdev ) {
433  rc = -ENOMEM;
434  goto err_alloc;
435  }
437  netdev->dev = &func->dev;
438  ecm = netdev->priv;
439  memset ( ecm, 0, sizeof ( *ecm ) );
440  ecm->usb = usb;
441  ecm->bus = usb->port->hub->bus;
442  ecm->netdev = netdev;
443  usbnet_init ( &ecm->usbnet, func, &ecm_intr_operations,
445  usb_refill_init ( &ecm->usbnet.intr, 0, 0, ECM_INTR_MAX_FILL );
447  DBGC ( ecm, "ECM %p on %s\n", ecm, func->name );
448 
449  /* Describe USB network device */
450  if ( ( rc = usbnet_describe ( &ecm->usbnet, config ) ) != 0 ) {
451  DBGC ( ecm, "ECM %p could not describe: %s\n",
452  ecm, strerror ( rc ) );
453  goto err_describe;
454  }
455 
456  /* Locate Ethernet descriptor */
457  comms = usb_interface_descriptor ( config, ecm->usbnet.comms, 0 );
458  assert ( comms != NULL );
459  ethernet = ecm_ethernet_descriptor ( config, comms );
460  if ( ! ethernet ) {
461  DBGC ( ecm, "ECM %p has no Ethernet descriptor\n", ecm );
462  rc = -EINVAL;
463  goto err_ethernet;
464  }
465 
466  /* Fetch MAC address */
467  if ( ( rc = ecm_fetch_mac ( usb, ethernet, netdev->hw_addr ) ) != 0 ) {
468  DBGC ( ecm, "ECM %p could not fetch MAC address: %s\n",
469  ecm, strerror ( rc ) );
470  goto err_fetch_mac;
471  }
472 
473  /* Register network device */
474  if ( ( rc = register_netdev ( netdev ) ) != 0 )
475  goto err_register;
476 
477  usb_func_set_drvdata ( func, ecm );
478  return 0;
479 
481  err_register:
482  err_fetch_mac:
483  err_ethernet:
484  err_describe:
486  netdev_put ( netdev );
487  err_alloc:
488  return rc;
489 }
490 
491 /**
492  * Remove device
493  *
494  * @v func USB function
495  */
496 static void ecm_remove ( struct usb_function *func ) {
497  struct ecm_device *ecm = usb_func_get_drvdata ( func );
498  struct net_device *netdev = ecm->netdev;
499 
502  netdev_put ( netdev );
503 }
504 
505 /** CDC-ECM device IDs */
506 static struct usb_device_id ecm_ids[] = {
507  {
508  .name = "cdc-ecm",
509  .vendor = USB_ANY_ID,
510  .product = USB_ANY_ID,
511  },
512 };
513 
514 /** CDC-ECM driver */
515 struct usb_driver ecm_driver __usb_driver = {
516  .ids = ecm_ids,
517  .id_count = ( sizeof ( ecm_ids ) / sizeof ( ecm_ids[0] ) ),
519  .score = USB_SCORE_NORMAL,
520  .probe = ecm_probe,
521  .remove = ecm_remove,
522 };
A USB driver.
Definition: usb.h:1363
#define EINVAL
Invalid argument.
Definition: errno.h:428
Unicast packets.
Definition: ecm.h:31
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A USB device ID.
Definition: usb.h:1317
void(* complete)(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer.
Definition: usb.h:481
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
An Ethernet Functional Descriptor.
Definition: ecm.h:39
unsigned int comms
Communications interface.
Definition: usbnet.h:20
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition: usb.h:701
CDC-ECM USB Ethernet driver.
const char * name
Name.
Definition: usb.h:659
#define USB_SUBCLASS_CDC_ECM
CDC-ECM subclass.
Definition: ecm.h:17
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
const char * name
Name.
Definition: usb.h:1319
static void ecm_in_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk IN transfer.
Definition: ecm.c:224
UINT8_t filter
Receive packet filter.
Definition: pxe_api.h:68
Error codes.
static struct net_device_operations ecm_operations
CDC-ECM network device operations.
Definition: ecm.c:400
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define CDC_SUBTYPE_ETHERNET
Ethernet descriptor subtype.
Definition: cdc.h:41
struct arbelprm_completion_with_error error
Definition: arbel.h:12
struct usbnet_device usbnet
USB network device.
Definition: ecm.h:65
#define DBGC(...)
Definition: compiler.h:505
#define ECM_IN_MAX_FILL
Bulk IN maximum fill level.
Definition: ecm.h:78
#define ECM_SET_ETHERNET_PACKET_FILTER
Set Ethernet packet filter.
Definition: ecm.h:20
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:528
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:379
static struct usb_endpoint_driver_operations ecm_intr_operations
Interrupt endpoint operations.
Definition: ecm.c:206
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
static int ecm_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: ecm.c:370
A data structure for storing profiling information.
Definition: profile.h:26
int open
Endpoint is open.
Definition: usb.h:404
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:27
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition: usb.c:753
static int ecm_out_transmit(struct ecm_device *ecm, struct io_buffer *iobuf)
Transmit packet.
Definition: ecm.c:268
static void ecm_remove(struct usb_function *func)
Remove device.
Definition: ecm.c:496
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
uint8_t subtype
Descriptor subtype.
Definition: ecm.h:43
static size_t base16_encoded_len(size_t raw_len)
Calculate length of base16-encoded data.
Definition: base16.h:21
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
A USB endpoint.
Definition: usb.h:389
static struct usb_endpoint_driver_operations ecm_in_operations
Bulk IN endpoint operations.
Definition: ecm.c:257
Promiscuous mode.
Definition: ecm.h:27
const char * name
Name.
Definition: profile.h:28
A USB interface descriptor.
Definition: usb.h:230
struct usb_port * port
USB port.
Definition: usb.h:710
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
Ethernet protocol.
An object interface.
Definition: interface.h:109
All multicast packets.
Definition: ecm.h:29
void * priv
Driver private data.
Definition: netdevice.h:425
#define DBGC_HDA(...)
Definition: compiler.h:506
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
struct ecm_ethernet_descriptor * ecm_ethernet_descriptor(struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface)
Locate Ethernet functional descriptor.
Definition: ecm.c:69
static void usb_refill_init(struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
Initialise USB endpoint refill.
Definition: usb.h:601
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:630
static struct net_device * netdev
Definition: gdbudp.c:52
struct usb_device * usb
USB device.
Definition: ecm.h:59
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition: usb.h:690
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
char name[32]
Name.
Definition: usb.h:708
#define ECM_IN_MTU
Bulk IN buffer size.
Definition: ecm.h:84
Profiling.
#define USB_CS_INTERFACE_DESCRIPTOR
A class-specific interface descriptor.
Definition: usb.h:331
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition: usbnet.c:151
A USB device.
Definition: usb.h:706
uint8_t type
Descriptor type.
Definition: usb.h:162
struct usb_interface_descriptor * usb_interface_descriptor(struct usb_configuration_descriptor *config, unsigned int interface, unsigned int alternate)
Locate USB interface descriptor.
Definition: usb.c:143
struct usb_descriptor_header header
Descriptor header.
Definition: ecm.h:41
#define CDC_NETWORK_CONNECTION
Network connection notification.
Definition: cdc.h:49
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1049
#define CDC_CONNECTION_SPEED_CHANGE
Connection speed change notification.
Definition: cdc.h:54
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define ECM_INTR_MAX_FILL
Interrupt maximum fill level.
Definition: ecm.h:72
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition: usb.h:1345
A network device.
Definition: netdevice.h:348
static void ecm_close(struct net_device *netdev)
Close network device.
Definition: ecm.c:356
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
static void ecm_out_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk OUT transfer.
Definition: ecm.c:290
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
Normal driver.
Definition: usb.h:1406
struct usb_bus * bus
USB bus.
Definition: ecm.h:61
unsigned char uint8_t
Definition: stdint.h:10
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint8_t mac
MAC address string.
Definition: ecm.h:45
#define ETH_ALEN
Definition: if_ether.h:8
static int ecm_open(struct net_device *netdev)
Open network device.
Definition: ecm.c:318
int ecm_fetch_mac(struct usb_device *usb, struct ecm_ethernet_descriptor *desc, uint8_t *hw_addr)
Get hardware MAC address.
Definition: ecm.c:89
struct usb_device * usb
USB device.
Definition: usb.h:661
A USB setup data packet.
Definition: usb.h:68
static void ecm_intr_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete interrupt transfer.
Definition: ecm.c:136
#define USB_CLASS_CDC
Class code for communications devices.
Definition: cdc.h:15
Network device operations.
Definition: netdevice.h:213
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
static int ecm_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: ecm.c:421
Network device management.
A CDC-ECM network device.
Definition: ecm.h:57
A USB configuration descriptor.
Definition: usb.h:195
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:395
uint32_t len
Length.
Definition: ena.h:14
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1329
Universal Serial Bus (USB)
static void usbnet_init(struct usbnet_device *usbnet, struct usb_function *func, struct usb_endpoint_driver_operations *intr, struct usb_endpoint_driver_operations *in, struct usb_endpoint_driver_operations *out)
Initialise USB network device.
Definition: usbnet.h:44
void * data
Start of data.
Definition: iobuf.h:44
struct usb_hub * hub
USB hub.
Definition: usb.h:798
static struct usb_device_id ecm_ids[]
CDC-ECM device IDs.
Definition: ecm.c:506
static struct usb_endpoint_driver_operations ecm_out_operations
Bulk OUT endpoint operations.
Definition: ecm.c:301
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
#define cpu_to_le16(value)
Definition: byteswap.h:106
struct usb_driver ecm_driver __usb_driver
CDC-ECM driver.
Definition: ecm.c:515
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition: usbnet.c:277
char message[VMCONSOLE_BUFSIZE]
Definition: vmconsole.c:54
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127
USB endpoint driver operations.
Definition: usb.h:474
struct device dev
Generic device.
Definition: usb.h:665
A USB function.
Definition: usb.h:657
static void ecm_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: ecm.c:387
struct usb_bus * bus
USB bus.
Definition: usb.h:828
Broadcast packets.
Definition: ecm.h:33
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct net_device * netdev
Network device.
Definition: ecm.h:63
struct usb_device_id * ids
USB ID table.
Definition: usb.h:1365
int usb_get_string_descriptor(struct usb_device *usb, unsigned int index, unsigned int language, char *buf, size_t len)
Get USB string descriptor.
Definition: usb.c:884
void * memset(void *dest, int character, size_t len) __nonnull
Base16 encoding.
A persistent I/O buffer.
Definition: iobuf.h:32
static struct profiler ecm_intr_profiler __profiler
Interrupt completion profiler.
Definition: ecm.c:43
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition: usbnet.c:54