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/acpimac.h>
34 #include <ipxe/usb.h>
35 #include "ecm.h"
36 
37 /** @file
38  *
39  * CDC-ECM USB Ethernet driver
40  *
41  */
42 
43 /** Interrupt completion profiler */
44 static struct profiler ecm_intr_profiler __profiler =
45  { .name = "ecm.intr" };
46 
47 /** Bulk IN completion profiler */
48 static struct profiler ecm_in_profiler __profiler =
49  { .name = "ecm.in" };
50 
51 /** Bulk OUT profiler */
52 static struct profiler ecm_out_profiler __profiler =
53  { .name = "ecm.out" };
54 
55 /******************************************************************************
56  *
57  * Ethernet functional descriptor
58  *
59  ******************************************************************************
60  */
61 
62 /**
63  * Locate Ethernet functional descriptor
64  *
65  * @v config Configuration descriptor
66  * @v interface Interface descriptor
67  * @ret desc Descriptor, or NULL if not found
68  */
73 
75  if ( ( desc->header.type == USB_CS_INTERFACE_DESCRIPTOR ) &&
76  ( desc->subtype == CDC_SUBTYPE_ETHERNET ) )
77  return desc;
78  }
79  return NULL;
80 }
81 
82 /**
83  * Get hardware MAC address
84  *
85  * @v func USB function
86  * @v desc Ethernet functional descriptor
87  * @v netdev Network device
88  * @ret rc Return status code
89  */
90 int ecm_fetch_mac ( struct usb_function *func,
92  struct net_device *netdev ) {
93  struct usb_device *usb = func->usb;
94  char buf[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
95  uint8_t amac[ETH_ALEN];
96  int len;
97  int rc;
98 
99  /* Fetch MAC address string */
100  buf[ sizeof ( buf ) - 1 ] = '\0';
101  len = usb_get_string_descriptor ( usb, desc->mac, 0, buf,
102  ( sizeof ( buf ) - 1 ) );
103  if ( len < 0 ) {
104  rc = len;
105  return rc;
106  }
107 
108  /* Sanity check */
109  if ( len != ( ( int ) ( sizeof ( buf ) - 1 /* NUL */ ) ) ) {
110  DBGC ( usb, "USB %s has invalid ECM MAC \"%s\"\n",
111  func->name, buf );
112  return -EINVAL;
113  }
114 
115  /* Decode MAC address */
116  len = base16_decode ( buf, netdev->hw_addr, ETH_ALEN );
117  if ( len < 0 ) {
118  rc = len;
119  DBGC ( usb, "USB %s could not decode ECM MAC \"%s\": %s\n",
120  func->name, buf, strerror ( rc ) );
121  return rc;
122  }
123 
124  /* Apply system-specific MAC address as current link-layer
125  * address, if present.
126  */
127  if ( ( rc = acpi_mac ( amac ) ) == 0 ) {
128  memcpy ( netdev->ll_addr, amac, ETH_ALEN );
129  DBGC ( usb, "USB %s using system-specific MAC %s\n",
130  func->name, eth_ntoa ( netdev->ll_addr ) );
131  }
132 
133  return 0;
134 }
135 
136 /******************************************************************************
137  *
138  * CDC-ECM communications interface
139  *
140  ******************************************************************************
141  */
142 
143 /**
144  * Complete interrupt transfer
145  *
146  * @v ep USB endpoint
147  * @v iobuf I/O buffer
148  * @v rc Completion status code
149  */
150 static void ecm_intr_complete ( struct usb_endpoint *ep,
151  struct io_buffer *iobuf, int rc ) {
152  struct ecm_device *ecm = container_of ( ep, struct ecm_device,
153  usbnet.intr );
154  struct net_device *netdev = ecm->netdev;
155  struct usb_setup_packet *message;
156  size_t len = iob_len ( iobuf );
157 
158  /* Profile completions */
159  profile_start ( &ecm_intr_profiler );
160 
161  /* Ignore packets cancelled when the endpoint closes */
162  if ( ! ep->open )
163  goto ignore;
164 
165  /* Drop packets with errors */
166  if ( rc != 0 ) {
167  DBGC ( ecm, "ECM %p interrupt failed: %s\n",
168  ecm, strerror ( rc ) );
169  DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
170  goto error;
171  }
172 
173  /* Extract message header */
174  if ( len < sizeof ( *message ) ) {
175  DBGC ( ecm, "ECM %p underlength interrupt:\n", ecm );
176  DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
177  rc = -EINVAL;
178  goto error;
179  }
180  message = iobuf->data;
181 
182  /* Parse message header */
183  switch ( message->request ) {
184 
186  if ( message->value && ! netdev_link_ok ( netdev ) ) {
187  DBGC ( ecm, "ECM %p link up\n", ecm );
189  } else if ( netdev_link_ok ( netdev ) && ! message->value ) {
190  DBGC ( ecm, "ECM %p link down\n", ecm );
192  }
193  break;
194 
196  /* Ignore */
197  break;
198 
199  default:
200  DBGC ( ecm, "ECM %p unrecognised interrupt:\n", ecm );
201  DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
202  rc = -ENOTSUP;
203  goto error;
204  }
205 
206  /* Free I/O buffer */
207  free_iob ( iobuf );
208  profile_stop ( &ecm_intr_profiler );
209 
210  return;
211 
212  error:
213  netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
214  ignore:
215  free_iob ( iobuf );
216  return;
217 }
218 
219 /** Interrupt endpoint operations */
222 };
223 
224 /******************************************************************************
225  *
226  * CDC-ECM data interface
227  *
228  ******************************************************************************
229  */
230 
231 /**
232  * Complete bulk IN transfer
233  *
234  * @v ep USB endpoint
235  * @v iobuf I/O buffer
236  * @v rc Completion status code
237  */
238 static void ecm_in_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf,
239  int rc ) {
240  struct ecm_device *ecm = container_of ( ep, struct ecm_device,
241  usbnet.in );
242  struct net_device *netdev = ecm->netdev;
243 
244  /* Profile receive completions */
245  profile_start ( &ecm_in_profiler );
246 
247  /* Ignore packets cancelled when the endpoint closes */
248  if ( ! ep->open )
249  goto ignore;
250 
251  /* Record USB errors against the network device */
252  if ( rc != 0 ) {
253  DBGC ( ecm, "ECM %p bulk IN failed: %s\n",
254  ecm, strerror ( rc ) );
255  goto error;
256  }
257 
258  /* Hand off to network stack */
259  netdev_rx ( netdev, iob_disown ( iobuf ) );
260 
261  profile_stop ( &ecm_in_profiler );
262  return;
263 
264  error:
265  netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
266  ignore:
267  free_iob ( iobuf );
268 }
269 
270 /** Bulk IN endpoint operations */
273 };
274 
275 /**
276  * Transmit packet
277  *
278  * @v ecm CDC-ECM device
279  * @v iobuf I/O buffer
280  * @ret rc Return status code
281  */
282 static int ecm_out_transmit ( struct ecm_device *ecm,
283  struct io_buffer *iobuf ) {
284  int rc;
285 
286  /* Profile transmissions */
287  profile_start ( &ecm_out_profiler );
288 
289  /* Enqueue I/O buffer */
290  if ( ( rc = usb_stream ( &ecm->usbnet.out, iobuf, 1 ) ) != 0 )
291  return rc;
292 
293  profile_stop ( &ecm_out_profiler );
294  return 0;
295 }
296 
297 /**
298  * Complete bulk OUT transfer
299  *
300  * @v ep USB endpoint
301  * @v iobuf I/O buffer
302  * @v rc Completion status code
303  */
304 static void ecm_out_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf,
305  int rc ) {
306  struct ecm_device *ecm = container_of ( ep, struct ecm_device,
307  usbnet.out );
308  struct net_device *netdev = ecm->netdev;
309 
310  /* Report TX completion */
311  netdev_tx_complete_err ( netdev, iobuf, rc );
312 }
313 
314 /** Bulk OUT endpoint operations */
317 };
318 
319 /******************************************************************************
320  *
321  * Network device interface
322  *
323  ******************************************************************************
324  */
325 
326 /**
327  * Open network device
328  *
329  * @v netdev Network device
330  * @ret rc Return status code
331  */
332 static int ecm_open ( struct net_device *netdev ) {
333  struct ecm_device *ecm = netdev->priv;
334  struct usb_device *usb = ecm->usb;
335  unsigned int filter;
336  int rc;
337 
338  /* Open USB network device */
339  if ( ( rc = usbnet_open ( &ecm->usbnet ) ) != 0 ) {
340  DBGC ( ecm, "ECM %p could not open: %s\n",
341  ecm, strerror ( rc ) );
342  goto err_open;
343  }
344 
345  /* Set packet filter */
351  filter, ecm->usbnet.comms, NULL, 0 ) ) != 0 ){
352  DBGC ( ecm, "ECM %p could not set packet filter: %s\n",
353  ecm, strerror ( rc ) );
354  goto err_set_filter;
355  }
356 
357  return 0;
358 
359  err_set_filter:
360  usbnet_close ( &ecm->usbnet );
361  err_open:
362  return rc;
363 }
364 
365 /**
366  * Close network device
367  *
368  * @v netdev Network device
369  */
370 static void ecm_close ( struct net_device *netdev ) {
371  struct ecm_device *ecm = netdev->priv;
372 
373  /* Close USB network device */
374  usbnet_close ( &ecm->usbnet );
375 }
376 
377 /**
378  * Transmit packet
379  *
380  * @v netdev Network device
381  * @v iobuf I/O buffer
382  * @ret rc Return status code
383  */
384 static int ecm_transmit ( struct net_device *netdev,
385  struct io_buffer *iobuf ) {
386  struct ecm_device *ecm = netdev->priv;
387  int rc;
388 
389  /* Transmit packet */
390  if ( ( rc = ecm_out_transmit ( ecm, iobuf ) ) != 0 )
391  return rc;
392 
393  return 0;
394 }
395 
396 /**
397  * Poll for completed and received packets
398  *
399  * @v netdev Network device
400  */
401 static void ecm_poll ( struct net_device *netdev ) {
402  struct ecm_device *ecm = netdev->priv;
403  int rc;
404 
405  /* Poll USB bus */
406  usb_poll ( ecm->bus );
407 
408  /* Refill endpoints */
409  if ( ( rc = usbnet_refill ( &ecm->usbnet ) ) != 0 )
410  netdev_rx_err ( netdev, NULL, rc );
411 }
412 
413 /** CDC-ECM network device operations */
415  .open = ecm_open,
416  .close = ecm_close,
417  .transmit = ecm_transmit,
418  .poll = ecm_poll,
419 };
420 
421 /******************************************************************************
422  *
423  * USB interface
424  *
425  ******************************************************************************
426  */
427 
428 /**
429  * Probe device
430  *
431  * @v func USB function
432  * @v config Configuration descriptor
433  * @ret rc Return status code
434  */
435 static int ecm_probe ( struct usb_function *func,
436  struct usb_configuration_descriptor *config ) {
437  struct usb_device *usb = func->usb;
438  struct net_device *netdev;
439  struct ecm_device *ecm;
440  struct usb_interface_descriptor *comms;
441  struct ecm_ethernet_descriptor *ethernet;
442  int rc;
443 
444  /* Allocate and initialise structure */
445  netdev = alloc_etherdev ( sizeof ( *ecm ) );
446  if ( ! netdev ) {
447  rc = -ENOMEM;
448  goto err_alloc;
449  }
451  netdev->dev = &func->dev;
452  ecm = netdev->priv;
453  memset ( ecm, 0, sizeof ( *ecm ) );
454  ecm->usb = usb;
455  ecm->bus = usb->port->hub->bus;
456  ecm->netdev = netdev;
457  usbnet_init ( &ecm->usbnet, func, &ecm_intr_operations,
459  usb_refill_init ( &ecm->usbnet.intr, 0, 0, ECM_INTR_MAX_FILL );
461  DBGC ( ecm, "ECM %p on %s\n", ecm, func->name );
462 
463  /* Describe USB network device */
464  if ( ( rc = usbnet_describe ( &ecm->usbnet, config ) ) != 0 ) {
465  DBGC ( ecm, "ECM %p could not describe: %s\n",
466  ecm, strerror ( rc ) );
467  goto err_describe;
468  }
469 
470  /* Locate Ethernet descriptor */
471  comms = usb_interface_descriptor ( config, ecm->usbnet.comms, 0 );
472  assert ( comms != NULL );
473  ethernet = ecm_ethernet_descriptor ( config, comms );
474  if ( ! ethernet ) {
475  DBGC ( ecm, "ECM %p has no Ethernet descriptor\n", ecm );
476  rc = -EINVAL;
477  goto err_ethernet;
478  }
479 
480  /* Fetch MAC address */
481  if ( ( rc = ecm_fetch_mac ( func, ethernet, netdev ) ) != 0 ) {
482  DBGC ( ecm, "ECM %p could not fetch MAC address: %s\n",
483  ecm, strerror ( rc ) );
484  goto err_fetch_mac;
485  }
486 
487  /* Register network device */
488  if ( ( rc = register_netdev ( netdev ) ) != 0 )
489  goto err_register;
490 
491  usb_func_set_drvdata ( func, ecm );
492  return 0;
493 
495  err_register:
496  err_fetch_mac:
497  err_ethernet:
498  err_describe:
500  netdev_put ( netdev );
501  err_alloc:
502  return rc;
503 }
504 
505 /**
506  * Remove device
507  *
508  * @v func USB function
509  */
510 static void ecm_remove ( struct usb_function *func ) {
511  struct ecm_device *ecm = usb_func_get_drvdata ( func );
512  struct net_device *netdev = ecm->netdev;
513 
516  netdev_put ( netdev );
517 }
518 
519 /** CDC-ECM device IDs */
520 static struct usb_device_id ecm_ids[] = {
521  {
522  .name = "cdc-ecm",
523  .vendor = USB_ANY_ID,
524  .product = USB_ANY_ID,
525  },
526 };
527 
528 /** CDC-ECM driver */
529 struct usb_driver ecm_driver __usb_driver = {
530  .ids = ecm_ids,
531  .id_count = ( sizeof ( ecm_ids ) / sizeof ( ecm_ids[0] ) ),
533  .score = USB_SCORE_NORMAL,
534  .probe = ecm_probe,
535  .remove = ecm_remove,
536 };
A USB driver.
Definition: usb.h:1406
#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:1360
void(* complete)(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer.
Definition: usb.h:495
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
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:717
CDC-ECM USB Ethernet driver.
const char * name
Name.
Definition: usb.h:675
#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:1362
static void ecm_in_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk IN transfer.
Definition: ecm.c:238
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:414
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#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
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#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:545
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:393
static struct usb_endpoint_driver_operations ecm_intr_operations
Interrupt endpoint operations.
Definition: ecm.c:220
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:230
static int ecm_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: ecm.c:384
A data structure for storing profiling information.
Definition: profile.h:26
int open
Endpoint is open.
Definition: usb.h:418
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
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:783
static int ecm_out_transmit(struct ecm_device *ecm, struct io_buffer *iobuf)
Transmit packet.
Definition: ecm.c:282
static void ecm_remove(struct usb_function *func)
Remove device.
Definition: ecm.c:510
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static size_t base16_encoded_len(size_t raw_len)
Calculate length of base16-encoded data.
Definition: base16.h:24
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:515
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
A USB endpoint.
Definition: usb.h:403
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct usb_endpoint_driver_operations ecm_in_operations
Bulk IN endpoint operations.
Definition: ecm.c:271
Promiscuous mode.
Definition: ecm.h:27
const char * name
Name.
Definition: profile.h:28
A USB interface descriptor.
Definition: usb.h:244
int acpi_mac(uint8_t *hw_addr)
Extract MAC address from DSDT/SSDT.
Definition: acpimac.c:233
struct usb_port * port
USB port.
Definition: usb.h:726
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:572
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
Ethernet protocol.
An object interface.
Definition: interface.h:124
All multicast packets.
Definition: ecm.h:29
void * priv
Driver private data.
Definition: netdevice.h:431
#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:774
struct ecm_ethernet_descriptor * ecm_ethernet_descriptor(struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface)
Locate Ethernet functional descriptor.
Definition: ecm.c:70
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:616
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:636
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:706
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
#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:345
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
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:722
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
#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:1071
#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:759
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition: usb.h:1388
A network device.
Definition: netdevice.h:352
static void ecm_close(struct net_device *netdev)
Close network device.
Definition: ecm.c:370
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:304
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
Normal driver.
Definition: usb.h:1452
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)
#define ETH_ALEN
Definition: if_ether.h:8
static int ecm_open(struct net_device *netdev)
Open network device.
Definition: ecm.c:332
struct usb_device * usb
USB device.
Definition: usb.h:677
A USB setup data packet.
Definition: usb.h:82
static void ecm_intr_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete interrupt transfer.
Definition: ecm.c:150
#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:548
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
static int ecm_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: ecm.c:435
Network device management.
A CDC-ECM network device.
Definition: ecm.h:57
A USB configuration descriptor.
Definition: usb.h:209
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1372
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:48
struct usb_hub * hub
USB hub.
Definition: usb.h:814
static struct usb_device_id ecm_ids[]
CDC-ECM device IDs.
Definition: ecm.c:520
int ecm_fetch_mac(struct usb_function *func, struct ecm_ethernet_descriptor *desc, struct net_device *netdev)
Get hardware MAC address.
Definition: ecm.c:90
static struct usb_endpoint_driver_operations ecm_out_operations
Bulk OUT endpoint operations.
Definition: ecm.c:315
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
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:529
ACPI MAC address.
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition: usbnet.c:277
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
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:488
struct device dev
Generic device.
Definition: usb.h:681
A USB function.
Definition: usb.h:673
static void ecm_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: ecm.c:401
struct usb_bus * bus
USB bus.
Definition: usb.h:844
Broadcast packets.
Definition: ecm.h:33
uint32_t len
Length.
Definition: ena.h:14
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct net_device * netdev
Network device.
Definition: ecm.h:63
struct usb_device_id * ids
USB ID table.
Definition: usb.h:1408
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:915
void * memset(void *dest, int character, size_t len) __nonnull
Base16 encoding.
A persistent I/O buffer.
Definition: iobuf.h:33
static struct profiler ecm_intr_profiler __profiler
Interrupt completion profiler.
Definition: ecm.c:44
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition: usbnet.c:54