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

Variables

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

Detailed Description

CDC-ECM USB Ethernet driver.

Definition in file ecm.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ecm_ethernet_descriptor()

struct ecm_ethernet_descriptor * ecm_ethernet_descriptor ( struct usb_configuration_descriptor * config,
struct usb_interface_descriptor * interface )

Locate Ethernet functional descriptor.

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

Definition at line 71 of file ecm.c.

72 {
74
76 if ( ( desc->header.type == USB_CS_INTERFACE_DESCRIPTOR ) &&
77 ( desc->subtype == CDC_SUBTYPE_ETHERNET ) )
78 return desc;
79 }
80 return NULL;
81}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define CDC_SUBTYPE_ETHERNET
Ethernet descriptor subtype.
Definition cdc.h:42
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition usb.h:394
#define USB_CS_INTERFACE_DESCRIPTOR
A class-specific interface descriptor.
Definition usb.h:346
An Ethernet Functional Descriptor.
Definition ecm.h:40
An object interface.
Definition interface.h:125

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 91 of file ecm.c.

93 {
94 struct usb_device *usb = func->usb;
95 char buf[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
96 uint8_t amac[ETH_ALEN];
97 int len;
98 int rc;
99
100 /* Fetch MAC address string */
101 buf[ sizeof ( buf ) - 1 ] = '\0';
102 len = usb_get_string_descriptor ( usb, desc->mac, 0, buf,
103 ( sizeof ( buf ) - 1 ) );
104 if ( len < 0 ) {
105 rc = len;
106 return rc;
107 }
108
109 /* Sanity check */
110 if ( len != ( ( int ) ( sizeof ( buf ) - 1 /* NUL */ ) ) ) {
111 DBGC ( usb, "USB %s has invalid ECM MAC \"%s\"\n",
112 func->name, buf );
113 return -EINVAL;
114 }
115
116 /* Decode MAC address */
117 len = base16_decode ( buf, netdev->hw_addr, ETH_ALEN );
118 if ( len < 0 ) {
119 rc = len;
120 DBGC ( usb, "USB %s could not decode ECM MAC \"%s\": %s\n",
121 func->name, buf, strerror ( rc ) );
122 return rc;
123 }
124
125 /* Apply system-specific MAC address as current link-layer
126 * address, if present.
127 */
128 if ( ( rc = acpi_mac ( amac ) ) == 0 ) {
129 memcpy ( netdev->ll_addr, amac, ETH_ALEN );
130 DBGC ( usb, "USB %s using system-specific MAC %s\n",
131 func->name, eth_ntoa ( netdev->ll_addr ) );
132 }
133
134 return 0;
135}
int acpi_mac(uint8_t *hw_addr)
Extract MAC address from DSDT/SSDT.
Definition acpimac.c:235
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned char uint8_t
Definition stdint.h:10
static size_t base16_encoded_len(size_t raw_len)
Calculate length of base16-encoded data.
Definition base16.h:25
ring len
Length.
Definition dwmac.h:226
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition ethernet.c:176
static struct net_device * netdev
Definition gdbudp.c:53
#define DBGC(...)
Definition compiler.h:505
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ETH_ALEN
Definition if_ether.h:9
void * memcpy(void *dest, const void *src, size_t len) __nonnull
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A USB device.
Definition usb.h:723
struct usb_device * usb
USB device.
Definition usb.h:678
const char * name
Name.
Definition usb.h:676
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:916

References acpi_mac(), base16_encoded_len(), DBGC, desc, EINVAL, ETH_ALEN, eth_ntoa(), len, 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()

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 151 of file ecm.c.

152 {
153 struct ecm_device *ecm = container_of ( ep, struct ecm_device,
154 usbnet.intr );
155 struct net_device *netdev = ecm->netdev;
157 size_t len = iob_len ( iobuf );
158
159 /* Profile completions */
160 profile_start ( &ecm_intr_profiler );
161
162 /* Ignore packets cancelled when the endpoint closes */
163 if ( ! ep->open )
164 goto ignore;
165
166 /* Drop packets with errors */
167 if ( rc != 0 ) {
168 DBGC ( ecm, "ECM %p interrupt failed: %s\n",
169 ecm, strerror ( rc ) );
170 DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
171 goto error;
172 }
173
174 /* Extract message header */
175 if ( len < sizeof ( *message ) ) {
176 DBGC ( ecm, "ECM %p underlength interrupt:\n", ecm );
177 DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
178 rc = -EINVAL;
179 goto error;
180 }
181 message = iobuf->data;
182
183 /* Parse message header */
184 switch ( message->request ) {
185
187 if ( message->value && ! netdev_link_ok ( netdev ) ) {
188 DBGC ( ecm, "ECM %p link up\n", ecm );
190 } else if ( netdev_link_ok ( netdev ) && ! message->value ) {
191 DBGC ( ecm, "ECM %p link down\n", ecm );
193 }
194 break;
195
197 /* Ignore */
198 break;
199
200 default:
201 DBGC ( ecm, "ECM %p unrecognised interrupt:\n", ecm );
202 DBGC_HDA ( ecm, 0, iobuf->data, iob_len ( iobuf ) );
203 rc = -ENOTSUP;
204 goto error;
205 }
206
207 /* Free I/O buffer */
208 free_iob ( iobuf );
209 profile_stop ( &ecm_intr_profiler );
210
211 return;
212
213 error:
214 netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
215 ignore:
216 free_iob ( iobuf );
217 return;
218}
pseudo_bit_t value[0x00020]
Definition arbel.h:2
struct arbelprm_completion_with_error error
Definition arbel.h:1
#define CDC_NETWORK_CONNECTION
Network connection notification.
Definition cdc.h:50
#define CDC_CONNECTION_SPEED_CHANGE
Connection speed change notification.
Definition cdc.h:55
#define DBGC_HDA(...)
Definition compiler.h:506
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define cpu_to_le16(value)
Definition byteswap.h:107
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition profile.h:174
static void profile_start(struct profiler *profiler)
Start profiling.
Definition profile.h:161
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition iobuf.h:217
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
if(natsemi->flags &NATSEMI_64BIT) return 1
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition netdevice.c:231
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition netdevice.h:640
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition netdevice.h:789
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
A CDC-ECM network device.
Definition ecm.h:58
struct usbnet_device usbnet
USB network device.
Definition ecm.h:66
struct net_device * netdev
Network device.
Definition ecm.h:64
void * data
Start of data.
Definition iobuf.h:53
A network device.
Definition netdevice.h:353
int open
Endpoint is open.
Definition usb.h:419
A USB setup data packet.
Definition usb.h:83
struct usb_endpoint intr
Interrupt endpoint.
Definition usbnet.h:28
char message[VMCONSOLE_BUFSIZE]
Definition vmconsole.c:54

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, ecm_device::netdev, 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()

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 239 of file ecm.c.

240 {
241 struct ecm_device *ecm = container_of ( ep, struct ecm_device,
242 usbnet.in );
243 struct net_device *netdev = ecm->netdev;
244
245 /* Profile receive completions */
246 profile_start ( &ecm_in_profiler );
247
248 /* Ignore packets cancelled when the endpoint closes */
249 if ( ! ep->open )
250 goto ignore;
251
252 /* Record USB errors against the network device */
253 if ( rc != 0 ) {
254 DBGC ( ecm, "ECM %p bulk IN failed: %s\n",
255 ecm, strerror ( rc ) );
256 goto error;
257 }
258
259 /* Hand off to network stack */
260 netdev_rx ( netdev, iob_disown ( iobuf ) );
261
262 profile_stop ( &ecm_in_profiler );
263 return;
264
265 error:
266 netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
267 ignore:
268 free_iob ( iobuf );
269}
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
struct usb_endpoint in
Bulk IN endpoint.
Definition usbnet.h:30

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

◆ ecm_out_transmit()

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 283 of file ecm.c.

284 {
285 int rc;
286
287 /* Profile transmissions */
288 profile_start ( &ecm_out_profiler );
289
290 /* Enqueue I/O buffer */
291 if ( ( rc = usb_stream ( &ecm->usbnet.out, iobuf, 1 ) ) != 0 )
292 return rc;
293
294 profile_stop ( &ecm_out_profiler );
295 return 0;
296}
struct usb_endpoint out
Bulk OUT endpoint.
Definition usbnet.h:32
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition usb.c:546

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

Referenced by ecm_transmit().

◆ ecm_out_complete()

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 305 of file ecm.c.

306 {
307 struct ecm_device *ecm = container_of ( ep, struct ecm_device,
308 usbnet.out );
309 struct net_device *netdev = ecm->netdev;
310
311 /* Report TX completion */
312 netdev_tx_complete_err ( netdev, iobuf, rc );
313}
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition netdevice.c:471

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

◆ ecm_open()

int ecm_open ( struct net_device * netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 333 of file ecm.c.

333 {
334 struct ecm_device *ecm = netdev->priv;
335 struct usb_device *usb = ecm->usb;
336 unsigned int filter;
337 int rc;
338
339 /* Open USB network device */
340 if ( ( rc = usbnet_open ( &ecm->usbnet ) ) != 0 ) {
341 DBGC ( ecm, "ECM %p could not open: %s\n",
342 ecm, strerror ( rc ) );
343 goto err_open;
344 }
345
346 /* Set packet filter */
352 filter, ecm->usbnet.comms, NULL, 0 ) ) != 0 ){
353 DBGC ( ecm, "ECM %p could not set packet filter: %s\n",
354 ecm, strerror ( rc ) );
355 goto err_set_filter;
356 }
357
358 return 0;
359
360 err_set_filter:
361 usbnet_close ( &ecm->usbnet );
362 err_open:
363 return rc;
364}
@ ECM_PACKET_TYPE_ALL_MULTICAST
All multicast packets.
Definition ecm.h:30
@ ECM_PACKET_TYPE_PROMISCUOUS
Promiscuous mode.
Definition ecm.h:28
@ ECM_PACKET_TYPE_BROADCAST
Broadcast packets.
Definition ecm.h:34
@ ECM_PACKET_TYPE_DIRECTED
Unicast packets.
Definition ecm.h:32
#define ECM_SET_ETHERNET_PACKET_FILTER
Set Ethernet packet filter.
Definition ecm.h:21
UINT8_t filter
Receive packet filter.
Definition pxe_api.h:11
struct usb_device * usb
USB device.
Definition ecm.h:60
unsigned int comms
Communications interface.
Definition usbnet.h:21
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:784
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition usbnet.c:55
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition usbnet.c:128

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, rc, strerror(), ecm_device::usb, usb_control(), ecm_device::usbnet, usbnet_close(), and usbnet_open().

◆ ecm_close()

void ecm_close ( struct net_device * netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 371 of file ecm.c.

371 {
372 struct ecm_device *ecm = netdev->priv;
373
374 /* Close USB network device */
375 usbnet_close ( &ecm->usbnet );
376}

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

◆ ecm_transmit()

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 385 of file ecm.c.

386 {
387 struct ecm_device *ecm = netdev->priv;
388 int rc;
389
390 /* Transmit packet */
391 if ( ( rc = ecm_out_transmit ( ecm, iobuf ) ) != 0 )
392 return rc;
393
394 return 0;
395}
static int ecm_out_transmit(struct ecm_device *ecm, struct io_buffer *iobuf)
Transmit packet.
Definition ecm.c:283

References ecm_out_transmit(), netdev, and rc.

◆ ecm_poll()

void ecm_poll ( struct net_device * netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 402 of file ecm.c.

402 {
403 struct ecm_device *ecm = netdev->priv;
404 int rc;
405
406 /* Poll USB bus */
407 usb_poll ( ecm->bus );
408
409 /* Refill endpoints */
410 if ( ( rc = usbnet_refill ( &ecm->usbnet ) ) != 0 )
412}
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition usb.h:1072
struct usb_bus * bus
USB bus.
Definition ecm.h:62
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition usbnet.c:152

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

◆ ecm_probe()

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 436 of file ecm.c.

437 {
438 struct usb_device *usb = func->usb;
439 struct net_device *netdev;
440 struct ecm_device *ecm;
441 struct usb_interface_descriptor *comms;
442 struct ecm_ethernet_descriptor *ethernet;
443 int rc;
444
445 /* Allocate and initialise structure */
446 netdev = alloc_etherdev ( sizeof ( *ecm ) );
447 if ( ! netdev ) {
448 rc = -ENOMEM;
449 goto err_alloc;
450 }
452 netdev->dev = &func->dev;
453 ecm = netdev->priv;
454 memset ( ecm, 0, sizeof ( *ecm ) );
455 ecm->usb = usb;
456 ecm->bus = usb->port->hub->bus;
457 ecm->netdev = netdev;
458 usbnet_init ( &ecm->usbnet, func, &ecm_intr_operations,
462 DBGC ( ecm, "ECM %p on %s\n", ecm, func->name );
463
464 /* Describe USB network device */
465 if ( ( rc = usbnet_describe ( &ecm->usbnet, config ) ) != 0 ) {
466 DBGC ( ecm, "ECM %p could not describe: %s\n",
467 ecm, strerror ( rc ) );
468 goto err_describe;
469 }
470
471 /* Locate Ethernet descriptor */
472 comms = usb_interface_descriptor ( config, ecm->usbnet.comms, 0 );
473 assert ( comms != NULL );
474 ethernet = ecm_ethernet_descriptor ( config, comms );
475 if ( ! ethernet ) {
476 DBGC ( ecm, "ECM %p has no Ethernet descriptor\n", ecm );
477 rc = -EINVAL;
478 goto err_ethernet;
479 }
480
481 /* Fetch MAC address */
482 if ( ( rc = ecm_fetch_mac ( func, ethernet, netdev ) ) != 0 ) {
483 DBGC ( ecm, "ECM %p could not fetch MAC address: %s\n",
484 ecm, strerror ( rc ) );
485 goto err_fetch_mac;
486 }
487
488 /* Register network device */
489 if ( ( rc = register_netdev ( netdev ) ) != 0 )
490 goto err_register;
491
492 usb_func_set_drvdata ( func, ecm );
493 return 0;
494
496 err_register:
497 err_fetch_mac:
498 err_ethernet:
499 err_describe:
501 netdev_put ( netdev );
502 err_alloc:
503 return rc;
504}
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
static struct usb_endpoint_driver_operations ecm_in_operations
Bulk IN endpoint operations.
Definition ecm.c:272
static struct net_device_operations ecm_operations
CDC-ECM network device operations.
Definition ecm.c:415
int ecm_fetch_mac(struct usb_function *func, struct ecm_ethernet_descriptor *desc, struct net_device *netdev)
Get hardware MAC address.
Definition ecm.c:91
struct ecm_ethernet_descriptor * ecm_ethernet_descriptor(struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface)
Locate Ethernet functional descriptor.
Definition ecm.c:71
static struct usb_endpoint_driver_operations ecm_out_operations
Bulk OUT endpoint operations.
Definition ecm.c:316
static struct usb_endpoint_driver_operations ecm_intr_operations
Interrupt endpoint operations.
Definition ecm.c:221
#define ECM_IN_MAX_FILL
Bulk IN maximum fill level.
Definition ecm.h:79
#define ECM_INTR_MAX_FILL
Interrupt maximum fill level.
Definition ecm.h:73
#define ECM_IN_MTU
Bulk IN buffer size.
Definition ecm.h:85
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
#define ENOMEM
Not enough space.
Definition errno.h:535
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:617
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition usb.h:707
void * memset(void *dest, int character, size_t len) __nonnull
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:942
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:519
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:532
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
struct usb_port * port
USB port.
Definition usb.h:727
struct device dev
Generic device.
Definition usb.h:682
struct usb_bus * bus
USB bus.
Definition usb.h:845
A USB interface descriptor.
Definition usb.h:245
struct usb_hub * hub
USB hub.
Definition usb.h:815
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:144
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition usbnet.c:278
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:45

References alloc_etherdev(), assert, ecm_device::bus, usb_hub::bus, usbnet_device::comms, DBGC, 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, ecm_device::netdev, netdev, netdev_init(), netdev_nullify(), netdev_put(), NULL, usb_device::port, 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()

void ecm_remove ( struct usb_function * func)
static

Remove device.

Parameters
funcUSB function

Definition at line 511 of file ecm.c.

511 {
512 struct ecm_device *ecm = usb_func_get_drvdata ( func );
513 struct net_device *netdev = ecm->netdev;
514
517 netdev_put ( netdev );
518}
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition usb.h:718

References ecm_device::netdev, 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 45 of file ecm.c.

46 { .name = "ecm.intr" };

◆ 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:151

Interrupt endpoint operations.

Definition at line 221 of file ecm.c.

221 {
222 .complete = ecm_intr_complete,
223};

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:239

Bulk IN endpoint operations.

Definition at line 272 of file ecm.c.

272 {
273 .complete = ecm_in_complete,
274};

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:305

Bulk OUT endpoint operations.

Definition at line 316 of file ecm.c.

316 {
317 .complete = ecm_out_complete,
318};

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 void ecm_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition ecm.c:402
static int ecm_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition ecm.c:385
static void ecm_close(struct net_device *netdev)
Close network device.
Definition ecm.c:371
static int ecm_open(struct net_device *netdev)
Open network device.
Definition ecm.c:333

CDC-ECM network device operations.

Definition at line 415 of file ecm.c.

415 {
416 .open = ecm_open,
417 .close = ecm_close,
418 .transmit = ecm_transmit,
419 .poll = ecm_poll,
420};

Referenced by ecm_probe().

◆ ecm_ids

struct usb_device_id ecm_ids[]
static
Initial value:
= {
USB_ROM ( 0xffff, 0xffff, "cdc-ecm", "USB CDC-ECM NIC", 0 ),
}
#define USB_ROM(_vendor, _product, _name, _description, _data)
Definition usb.h:1381

CDC-ECM device IDs.

Definition at line 521 of file ecm.c.

521 {
522 USB_ROM ( 0xffff, 0xffff, "cdc-ecm", "USB CDC-ECM NIC", 0 ),
523};

◆ __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_CLASS_CDC
Class code for communications devices.
Definition cdc.h:16
static int ecm_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition ecm.c:436
static void ecm_remove(struct usb_function *func)
Remove device.
Definition ecm.c:511
static struct usb_device_id ecm_ids[]
CDC-ECM device IDs.
Definition ecm.c:521
#define USB_SUBCLASS_CDC_ECM
CDC-ECM subclass.
Definition ecm.h:18
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition usb.h:1401
@ USB_SCORE_NORMAL
Normal driver.
Definition usb.h:1465

CDC-ECM driver.

Definition at line 526 of file ecm.c.

526 {
527 .ids = ecm_ids,
528 .id_count = ( sizeof ( ecm_ids ) / sizeof ( ecm_ids[0] ) ),
530 .score = USB_SCORE_NORMAL,
531 .probe = ecm_probe,
532 .remove = ecm_remove,
533};