iPXE
Functions | Variables
ecm.c File Reference

CDC-ECM USB Ethernet driver. More...

#include <stdint.h>
#include <errno.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/base16.h>
#include <ipxe/profile.h>
#include <ipxe/acpimac.h>
#include <ipxe/usb.h>
#include "ecm.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
struct ecm_ethernet_descriptorecm_ethernet_descriptor (struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface)
 Locate Ethernet functional descriptor. More...
 
int ecm_fetch_mac (struct usb_function *func, struct ecm_ethernet_descriptor *desc, struct net_device *netdev)
 Get hardware MAC address. More...
 
static void ecm_intr_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete interrupt transfer. More...
 
static void ecm_in_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk IN transfer. More...
 
static int ecm_out_transmit (struct ecm_device *ecm, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void ecm_out_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk OUT transfer. More...
 
static int ecm_open (struct net_device *netdev)
 Open network device. More...
 
static void ecm_close (struct net_device *netdev)
 Close network device. More...
 
static int ecm_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void ecm_poll (struct net_device *netdev)
 Poll for completed and received packets. More...
 
static int ecm_probe (struct usb_function *func, struct usb_configuration_descriptor *config)
 Probe device. More...
 
static void ecm_remove (struct usb_function *func)
 Remove device. More...
 

Variables

static struct profiler ecm_intr_profiler __profiler
 Interrupt completion profiler. More...
 
static struct usb_endpoint_driver_operations ecm_intr_operations
 Interrupt endpoint operations. More...
 
static struct usb_endpoint_driver_operations ecm_in_operations
 Bulk IN endpoint operations. More...
 
static struct usb_endpoint_driver_operations ecm_out_operations
 Bulk OUT endpoint operations. More...
 
static struct net_device_operations ecm_operations
 CDC-ECM network device operations. More...
 
static struct usb_device_id ecm_ids []
 CDC-ECM device IDs. More...
 
struct usb_driver ecm_driver __usb_driver
 CDC-ECM driver. More...
 

Detailed Description

CDC-ECM USB Ethernet driver.

Definition in file ecm.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ecm_ethernet_descriptor()

Locate Ethernet functional descriptor.

Parameters
configConfiguration descriptor
interfaceInterface descriptor
Return values
descDescriptor, or NULL if not found

Definition at line 70 of file ecm.c.

71  {
73 
75  if ( ( desc->header.type == USB_CS_INTERFACE_DESCRIPTOR ) &&
76  ( desc->subtype == CDC_SUBTYPE_ETHERNET ) )
77  return desc;
78  }
79  return NULL;
80 }
An Ethernet Functional Descriptor.
Definition: ecm.h:39
#define CDC_SUBTYPE_ETHERNET
Ethernet descriptor subtype.
Definition: cdc.h:41
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:379
An object interface.
Definition: interface.h:124
#define USB_CS_INTERFACE_DESCRIPTOR
A class-specific interface descriptor.
Definition: usb.h:331
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References CDC_SUBTYPE_ETHERNET, desc, for_each_interface_descriptor, NULL, and USB_CS_INTERFACE_DESCRIPTOR.

Referenced by ecm_probe(), and ncm_probe().

◆ ecm_fetch_mac()

int ecm_fetch_mac ( struct usb_function func,
struct ecm_ethernet_descriptor desc,
struct net_device netdev 
)

Get hardware MAC address.

Parameters
funcUSB function
descEthernet functional descriptor
netdevNetwork device
Return values
rcReturn status code

Definition at line 90 of file ecm.c.

92  {
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  len = usb_get_string_descriptor ( usb, desc->mac, 0, buf,
101  sizeof ( buf ) );
102  if ( len < 0 ) {
103  rc = len;
104  return rc;
105  }
106 
107  /* Sanity check */
108  if ( len != ( ( int ) ( sizeof ( buf ) - 1 /* NUL */ ) ) ) {
109  DBGC ( usb, "USB %s has invalid ECM MAC \"%s\"\n",
110  func->name, buf );
111  return -EINVAL;
112  }
113 
114  /* Decode MAC address */
115  len = base16_decode ( buf, netdev->hw_addr, ETH_ALEN );
116  if ( len < 0 ) {
117  rc = len;
118  DBGC ( usb, "USB %s could not decode ECM MAC \"%s\": %s\n",
119  func->name, buf, strerror ( rc ) );
120  return rc;
121  }
122 
123  /* Apply system-specific MAC address as current link-layer
124  * address, if present.
125  */
126  if ( ( rc = acpi_mac ( amac ) ) == 0 ) {
127  memcpy ( netdev->ll_addr, amac, ETH_ALEN );
128  DBGC ( usb, "USB %s using system-specific MAC %s\n",
129  func->name, eth_ntoa ( netdev->ll_addr ) );
130  }
131 
132  return 0;
133 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Name.
Definition: usb.h:661
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define DBGC(...)
Definition: compiler.h:505
static size_t base16_encoded_len(size_t raw_len)
Calculate length of base16-encoded data.
Definition: base16.h:24
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int acpi_mac(uint8_t *hw_addr)
Extract MAC address from DSDT/SSDT.
Definition: acpimac.c:233
static struct net_device * netdev
Definition: gdbudp.c:52
A USB device.
Definition: usb.h:708
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
unsigned char uint8_t
Definition: stdint.h:10
#define ETH_ALEN
Definition: if_ether.h:8
struct usb_device * usb
USB device.
Definition: usb.h:663
uint32_t len
Length.
Definition: ena.h:14
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
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

References acpi_mac(), base16_encoded_len(), DBGC, desc, EINVAL, ETH_ALEN, eth_ntoa(), net_device::hw_addr, len, net_device::ll_addr, memcpy(), usb_function::name, netdev, rc, strerror(), usb_function::usb, and usb_get_string_descriptor().

Referenced by ecm_probe(), and ncm_probe().

◆ ecm_intr_complete()

static void ecm_intr_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete interrupt transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 149 of file ecm.c.

150  {
151  struct ecm_device *ecm = container_of ( ep, struct ecm_device,
152  usbnet.intr );
153  struct net_device *netdev = ecm->netdev;
154  struct usb_setup_packet *message;
155  size_t len = iob_len ( iobuf );
156 
157  /* Profile completions */
158  profile_start ( &ecm_intr_profiler );
159 
160  /* Ignore packets cancelled when the endpoint closes */
161  if ( ! ep->open )
162  goto ignore;
163 
164  /* Drop packets with errors */
165  if ( rc != 0 ) {
166  DBGC ( ecm, "ECM %p interrupt failed: %s\n",
167  ecm, strerror ( rc ) );
168  DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
169  goto error;
170  }
171 
172  /* Extract message header */
173  if ( len < sizeof ( *message ) ) {
174  DBGC ( ecm, "ECM %p underlength interrupt:\n", ecm );
175  DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
176  rc = -EINVAL;
177  goto error;
178  }
179  message = iobuf->data;
180 
181  /* Parse message header */
182  switch ( message->request ) {
183 
185  if ( message->value && ! netdev_link_ok ( netdev ) ) {
186  DBGC ( ecm, "ECM %p link up\n", ecm );
188  } else if ( netdev_link_ok ( netdev ) && ! message->value ) {
189  DBGC ( ecm, "ECM %p link down\n", ecm );
191  }
192  break;
193 
195  /* Ignore */
196  break;
197 
198  default:
199  DBGC ( ecm, "ECM %p unrecognised interrupt:\n", ecm );
200  DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
201  rc = -ENOTSUP;
202  goto error;
203  }
204 
205  /* Free I/O buffer */
206  free_iob ( iobuf );
207  profile_stop ( &ecm_intr_profiler );
208 
209  return;
210 
211  error:
212  netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
213  ignore:
214  free_iob ( iobuf );
215  return;
216 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
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
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:230
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
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#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
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
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define CDC_NETWORK_CONNECTION
Network connection notification.
Definition: cdc.h:49
#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
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
A network device.
Definition: netdevice.h:352
A USB setup data packet.
Definition: usb.h:68
A CDC-ECM network device.
Definition: ecm.h:57
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:48
#define cpu_to_le16(value)
Definition: byteswap.h:106
char message[VMCONSOLE_BUFSIZE]
Definition: vmconsole.c:54
struct net_device * netdev
Network device.
Definition: ecm.h:63
if(natsemi->flags &NATSEMI_64BIT) return 1

References CDC_CONNECTION_SPEED_CHANGE, CDC_NETWORK_CONNECTION, container_of, cpu_to_le16, io_buffer::data, DBGC, DBGC_HDA, EINVAL, ENOTSUP, error, free_iob(), usbnet_device::intr, iob_disown, iob_len(), len, message, netdev, ecm_device::netdev, netdev_link_down(), netdev_link_ok(), netdev_link_up(), netdev_rx_err(), usb_endpoint::open, profile_start(), profile_stop(), rc, strerror(), and ecm_device::usbnet.

◆ ecm_in_complete()

static void ecm_in_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete bulk IN transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 237 of file ecm.c.

238  {
239  struct ecm_device *ecm = container_of ( ep, struct ecm_device,
240  usbnet.in );
241  struct net_device *netdev = ecm->netdev;
242 
243  /* Profile receive completions */
244  profile_start ( &ecm_in_profiler );
245 
246  /* Ignore packets cancelled when the endpoint closes */
247  if ( ! ep->open )
248  goto ignore;
249 
250  /* Record USB errors against the network device */
251  if ( rc != 0 ) {
252  DBGC ( ecm, "ECM %p bulk IN failed: %s\n",
253  ecm, strerror ( rc ) );
254  goto error;
255  }
256 
257  /* Hand off to network stack */
258  netdev_rx ( netdev, iob_disown ( iobuf ) );
259 
260  profile_stop ( &ecm_in_profiler );
261  return;
262 
263  error:
264  netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
265  ignore:
266  free_iob ( iobuf );
267 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
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
int open
Endpoint is open.
Definition: usb.h:404
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct net_device * netdev
Definition: gdbudp.c:52
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A network device.
Definition: netdevice.h:352
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
A CDC-ECM network device.
Definition: ecm.h:57
struct net_device * netdev
Network device.
Definition: ecm.h:63

References container_of, DBGC, error, free_iob(), usbnet_device::in, iob_disown, netdev, ecm_device::netdev, netdev_rx(), netdev_rx_err(), usb_endpoint::open, profile_start(), profile_stop(), rc, strerror(), and ecm_device::usbnet.

◆ ecm_out_transmit()

static int ecm_out_transmit ( struct ecm_device ecm,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
ecmCDC-ECM device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 281 of file ecm.c.

282  {
283  int rc;
284 
285  /* Profile transmissions */
286  profile_start ( &ecm_out_profiler );
287 
288  /* Enqueue I/O buffer */
289  if ( ( rc = usb_stream ( &ecm->usbnet.out, iobuf, 1 ) ) != 0 )
290  return rc;
291 
292  profile_stop ( &ecm_out_profiler );
293  return 0;
294 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usbnet_device usbnet
USB network device.
Definition: ecm.h:65
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:545
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158

References usbnet_device::out, profile_start(), profile_stop(), rc, usb_stream(), and ecm_device::usbnet.

Referenced by ecm_transmit().

◆ ecm_out_complete()

static void ecm_out_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete bulk OUT transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 303 of file ecm.c.

304  {
305  struct ecm_device *ecm = container_of ( ep, struct ecm_device,
306  usbnet.out );
307  struct net_device *netdev = ecm->netdev;
308 
309  /* Report TX completion */
310  netdev_tx_complete_err ( netdev, iobuf, rc );
311 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usbnet_device usbnet
USB network device.
Definition: ecm.h:65
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
A CDC-ECM network device.
Definition: ecm.h:57
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
struct net_device * netdev
Network device.
Definition: ecm.h:63

References container_of, netdev, ecm_device::netdev, netdev_tx_complete_err(), usbnet_device::out, rc, and ecm_device::usbnet.

◆ ecm_open()

static int ecm_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 331 of file ecm.c.

331  {
332  struct ecm_device *ecm = netdev->priv;
333  struct usb_device *usb = ecm->usb;
334  unsigned int filter;
335  int rc;
336 
337  /* Open USB network device */
338  if ( ( rc = usbnet_open ( &ecm->usbnet ) ) != 0 ) {
339  DBGC ( ecm, "ECM %p could not open: %s\n",
340  ecm, strerror ( rc ) );
341  goto err_open;
342  }
343 
344  /* Set packet filter */
350  filter, ecm->usbnet.comms, NULL, 0 ) ) != 0 ){
351  DBGC ( ecm, "ECM %p could not set packet filter: %s\n",
352  ecm, strerror ( rc ) );
353  goto err_set_filter;
354  }
355 
356  return 0;
357 
358  err_set_filter:
359  usbnet_close ( &ecm->usbnet );
360  err_open:
361  return rc;
362 }
Unicast packets.
Definition: ecm.h:31
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int comms
Communications interface.
Definition: usbnet.h:20
UINT8_t filter
Receive packet filter.
Definition: pxe_api.h:68
struct usbnet_device usbnet
USB network device.
Definition: ecm.h:65
#define DBGC(...)
Definition: compiler.h:505
#define ECM_SET_ETHERNET_PACKET_FILTER
Set Ethernet packet filter.
Definition: ecm.h:20
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
Promiscuous mode.
Definition: ecm.h:27
All multicast packets.
Definition: ecm.h:29
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
struct usb_device * usb
USB device.
Definition: ecm.h:59
A USB device.
Definition: usb.h:708
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A CDC-ECM network device.
Definition: ecm.h:57
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127
Broadcast packets.
Definition: ecm.h:33
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition: usbnet.c:54

References usbnet_device::comms, DBGC, ECM_PACKET_TYPE_ALL_MULTICAST, ECM_PACKET_TYPE_BROADCAST, ECM_PACKET_TYPE_DIRECTED, ECM_PACKET_TYPE_PROMISCUOUS, ECM_SET_ETHERNET_PACKET_FILTER, filter, netdev, NULL, net_device::priv, rc, strerror(), ecm_device::usb, usb_control(), ecm_device::usbnet, usbnet_close(), and usbnet_open().

◆ ecm_close()

static void ecm_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 369 of file ecm.c.

369  {
370  struct ecm_device *ecm = netdev->priv;
371 
372  /* Close USB network device */
373  usbnet_close ( &ecm->usbnet );
374 }
struct usbnet_device usbnet
USB network device.
Definition: ecm.h:65
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
A CDC-ECM network device.
Definition: ecm.h:57
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127

References netdev, net_device::priv, ecm_device::usbnet, and usbnet_close().

◆ ecm_transmit()

static int ecm_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 383 of file ecm.c.

384  {
385  struct ecm_device *ecm = netdev->priv;
386  int rc;
387 
388  /* Transmit packet */
389  if ( ( rc = ecm_out_transmit ( ecm, iobuf ) ) != 0 )
390  return rc;
391 
392  return 0;
393 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int ecm_out_transmit(struct ecm_device *ecm, struct io_buffer *iobuf)
Transmit packet.
Definition: ecm.c:281
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
A CDC-ECM network device.
Definition: ecm.h:57

References ecm_out_transmit(), netdev, net_device::priv, and rc.

◆ ecm_poll()

static void ecm_poll ( struct net_device netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 400 of file ecm.c.

400  {
401  struct ecm_device *ecm = netdev->priv;
402  int rc;
403 
404  /* Poll USB bus */
405  usb_poll ( ecm->bus );
406 
407  /* Refill endpoints */
408  if ( ( rc = usbnet_refill ( &ecm->usbnet ) ) != 0 )
409  netdev_rx_err ( netdev, NULL, rc );
410 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
struct usbnet_device usbnet
USB network device.
Definition: ecm.h:65
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition: usbnet.c:151
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1051
struct usb_bus * bus
USB bus.
Definition: ecm.h:61
A CDC-ECM network device.
Definition: ecm.h:57
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References ecm_device::bus, netdev, netdev_rx_err(), NULL, net_device::priv, rc, usb_poll(), ecm_device::usbnet, and usbnet_refill().

◆ ecm_probe()

static int ecm_probe ( struct usb_function func,
struct usb_configuration_descriptor config 
)
static

Probe device.

Parameters
funcUSB function
configConfiguration descriptor
Return values
rcReturn status code

Definition at line 434 of file ecm.c.

435  {
436  struct usb_device *usb = func->usb;
437  struct net_device *netdev;
438  struct ecm_device *ecm;
439  struct usb_interface_descriptor *comms;
440  struct ecm_ethernet_descriptor *ethernet;
441  int rc;
442 
443  /* Allocate and initialise structure */
444  netdev = alloc_etherdev ( sizeof ( *ecm ) );
445  if ( ! netdev ) {
446  rc = -ENOMEM;
447  goto err_alloc;
448  }
450  netdev->dev = &func->dev;
451  ecm = netdev->priv;
452  memset ( ecm, 0, sizeof ( *ecm ) );
453  ecm->usb = usb;
454  ecm->bus = usb->port->hub->bus;
455  ecm->netdev = netdev;
456  usbnet_init ( &ecm->usbnet, func, &ecm_intr_operations,
458  usb_refill_init ( &ecm->usbnet.intr, 0, 0, ECM_INTR_MAX_FILL );
460  DBGC ( ecm, "ECM %p on %s\n", ecm, func->name );
461 
462  /* Describe USB network device */
463  if ( ( rc = usbnet_describe ( &ecm->usbnet, config ) ) != 0 ) {
464  DBGC ( ecm, "ECM %p could not describe: %s\n",
465  ecm, strerror ( rc ) );
466  goto err_describe;
467  }
468 
469  /* Locate Ethernet descriptor */
470  comms = usb_interface_descriptor ( config, ecm->usbnet.comms, 0 );
471  assert ( comms != NULL );
472  ethernet = ecm_ethernet_descriptor ( config, comms );
473  if ( ! ethernet ) {
474  DBGC ( ecm, "ECM %p has no Ethernet descriptor\n", ecm );
475  rc = -EINVAL;
476  goto err_ethernet;
477  }
478 
479  /* Fetch MAC address */
480  if ( ( rc = ecm_fetch_mac ( func, ethernet, netdev ) ) != 0 ) {
481  DBGC ( ecm, "ECM %p could not fetch MAC address: %s\n",
482  ecm, strerror ( rc ) );
483  goto err_fetch_mac;
484  }
485 
486  /* Register network device */
487  if ( ( rc = register_netdev ( netdev ) ) != 0 )
488  goto err_register;
489 
490  usb_func_set_drvdata ( func, ecm );
491  return 0;
492 
494  err_register:
495  err_fetch_mac:
496  err_ethernet:
497  err_describe:
499  netdev_put ( netdev );
500  err_alloc:
501  return rc;
502 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An Ethernet Functional Descriptor.
Definition: ecm.h:39
unsigned int comms
Communications interface.
Definition: usbnet.h:20
const char * name
Name.
Definition: usb.h:661
static struct net_device_operations ecm_operations
CDC-ECM network device operations.
Definition: ecm.c:413
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
static struct usb_endpoint_driver_operations ecm_intr_operations
Interrupt endpoint operations.
Definition: ecm.c:219
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:27
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
static struct usb_endpoint_driver_operations ecm_in_operations
Bulk IN endpoint operations.
Definition: ecm.c:270
A USB interface descriptor.
Definition: usb.h:230
struct usb_port * port
USB port.
Definition: usb.h:712
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
void * priv
Driver private data.
Definition: netdevice.h:431
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:602
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:692
#define ECM_IN_MTU
Bulk IN buffer size.
Definition: ecm.h:84
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
A USB device.
Definition: usb.h:708
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
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
A network device.
Definition: netdevice.h:352
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
struct usb_bus * bus
USB bus.
Definition: ecm.h:61
struct usb_device * usb
USB device.
Definition: usb.h:663
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
A CDC-ECM network device.
Definition: ecm.h:57
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
struct usb_hub * hub
USB hub.
Definition: usb.h:800
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:314
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition: usbnet.c:277
struct device dev
Generic device.
Definition: usb.h:667
struct usb_bus * bus
USB bus.
Definition: usb.h:830
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct net_device * netdev
Network device.
Definition: ecm.h:63
void * memset(void *dest, int character, size_t len) __nonnull

References alloc_etherdev(), assert(), ecm_device::bus, usb_hub::bus, usbnet_device::comms, DBGC, net_device::dev, usb_function::dev, ecm_ethernet_descriptor(), ecm_fetch_mac(), ECM_IN_MAX_FILL, ECM_IN_MTU, ecm_in_operations, ECM_INTR_MAX_FILL, ecm_intr_operations, ecm_operations, ecm_out_operations, EINVAL, ENOMEM, usb_port::hub, usbnet_device::in, usbnet_device::intr, memset(), usb_function::name, netdev, ecm_device::netdev, netdev_init(), netdev_nullify(), netdev_put(), NULL, usb_device::port, net_device::priv, rc, register_netdev(), strerror(), unregister_netdev(), ecm_device::usb, usb_function::usb, usb_func_set_drvdata(), usb_interface_descriptor(), usb_refill_init(), ecm_device::usbnet, usbnet_describe(), and usbnet_init().

◆ ecm_remove()

static void ecm_remove ( struct usb_function func)
static

Remove device.

Parameters
funcUSB function

Definition at line 509 of file ecm.c.

509  {
510  struct ecm_device *ecm = usb_func_get_drvdata ( func );
511  struct net_device *netdev = ecm->netdev;
512 
515  netdev_put ( netdev );
516 }
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition: usb.h:703
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
A CDC-ECM network device.
Definition: ecm.h:57
struct net_device * netdev
Network device.
Definition: ecm.h:63

References netdev, ecm_device::netdev, netdev_nullify(), netdev_put(), unregister_netdev(), and usb_func_get_drvdata().

Variable Documentation

◆ __profiler

struct profiler ecm_out_profiler __profiler
static
Initial value:
=
{ .name = "ecm.intr" }

Interrupt completion profiler.

Bulk OUT profiler.

Bulk IN completion profiler.

Definition at line 44 of file ecm.c.

◆ ecm_intr_operations

struct usb_endpoint_driver_operations ecm_intr_operations
static
Initial value:
= {
.complete = ecm_intr_complete,
}
static void ecm_intr_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete interrupt transfer.
Definition: ecm.c:149

Interrupt endpoint operations.

Definition at line 219 of file ecm.c.

Referenced by ecm_probe().

◆ ecm_in_operations

struct usb_endpoint_driver_operations ecm_in_operations
static
Initial value:
= {
.complete = ecm_in_complete,
}
static void ecm_in_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk IN transfer.
Definition: ecm.c:237

Bulk IN endpoint operations.

Definition at line 270 of file ecm.c.

Referenced by ecm_probe().

◆ ecm_out_operations

struct usb_endpoint_driver_operations ecm_out_operations
static
Initial value:
= {
.complete = ecm_out_complete,
}
static void ecm_out_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk OUT transfer.
Definition: ecm.c:303

Bulk OUT endpoint operations.

Definition at line 314 of file ecm.c.

Referenced by ecm_probe().

◆ ecm_operations

struct net_device_operations ecm_operations
static
Initial value:
= {
.open = ecm_open,
.close = ecm_close,
.transmit = ecm_transmit,
.poll = ecm_poll,
}
static int ecm_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: ecm.c:383
static void ecm_close(struct net_device *netdev)
Close network device.
Definition: ecm.c:369
static int ecm_open(struct net_device *netdev)
Open network device.
Definition: ecm.c:331
static void ecm_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: ecm.c:400

CDC-ECM network device operations.

Definition at line 413 of file ecm.c.

Referenced by ecm_probe().

◆ ecm_ids

struct usb_device_id ecm_ids[]
static
Initial value:
= {
{
.name = "cdc-ecm",
.vendor = USB_ANY_ID,
.product = USB_ANY_ID,
},
}
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1347

CDC-ECM device IDs.

Definition at line 519 of file ecm.c.

◆ __usb_driver

struct usb_driver ecm_driver __usb_driver
Initial value:
= {
.ids = ecm_ids,
.id_count = ( sizeof ( ecm_ids ) / sizeof ( ecm_ids[0] ) ),
.score = USB_SCORE_NORMAL,
.probe = ecm_probe,
.remove = ecm_remove,
}
#define USB_SUBCLASS_CDC_ECM
CDC-ECM subclass.
Definition: ecm.h:17
static void ecm_remove(struct usb_function *func)
Remove device.
Definition: ecm.c:509
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition: usb.h:1363
Normal driver.
Definition: usb.h:1427
#define USB_CLASS_CDC
Class code for communications devices.
Definition: cdc.h:15
static int ecm_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: ecm.c:434
static struct usb_device_id ecm_ids[]
CDC-ECM device IDs.
Definition: ecm.c:519

CDC-ECM driver.

Definition at line 528 of file ecm.c.