iPXE
ecm.h File Reference

CDC-ECM USB Ethernet driver. More...

#include <ipxe/usb.h>
#include <ipxe/usbnet.h>
#include <ipxe/cdc.h>

Go to the source code of this file.

Data Structures

struct  ecm_ethernet_descriptor
 An Ethernet Functional Descriptor. More...
struct  ecm_device
 A CDC-ECM network device. More...

Macros

#define USB_SUBCLASS_CDC_ECM   0x06
 CDC-ECM subclass.
#define ECM_SET_ETHERNET_PACKET_FILTER
 Set Ethernet packet filter.
#define ECM_INTR_MAX_FILL   2
 Interrupt maximum fill level.
#define ECM_IN_MAX_FILL   8
 Bulk IN maximum fill level.
#define ECM_IN_MTU   ( ETH_FRAME_LEN + 4 /* possible VLAN header */ )
 Bulk IN buffer size.

Enumerations

enum  ecm_ethernet_packet_filter {
  ECM_PACKET_TYPE_PROMISCUOUS = 0x0001 , ECM_PACKET_TYPE_ALL_MULTICAST = 0x0002 , ECM_PACKET_TYPE_DIRECTED = 0x0004 , ECM_PACKET_TYPE_BROADCAST = 0x0008 ,
  ECM_PACKET_TYPE_MULTICAST = 0x0010
}
 Ethernet packet types. More...

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.

Detailed Description

CDC-ECM USB Ethernet driver.

Definition in file ecm.h.

Macro Definition Documentation

◆ USB_SUBCLASS_CDC_ECM

#define USB_SUBCLASS_CDC_ECM   0x06

CDC-ECM subclass.

Definition at line 18 of file ecm.h.

◆ ECM_SET_ETHERNET_PACKET_FILTER

#define ECM_SET_ETHERNET_PACKET_FILTER
Value:
USB_REQUEST_TYPE ( 0x43 ) )
#define USB_DIR_OUT
Data transfer is from host to device.
Definition usb.h:95
#define USB_TYPE_CLASS
Class-specific request type.
Definition usb.h:104
#define USB_RECIP_INTERFACE
Request recipient is an interface.
Definition usb.h:116

Set Ethernet packet filter.

Definition at line 21 of file ecm.h.

21#define ECM_SET_ETHERNET_PACKET_FILTER \
22 ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
23 USB_REQUEST_TYPE ( 0x43 ) )

Referenced by ecm_open().

◆ ECM_INTR_MAX_FILL

#define ECM_INTR_MAX_FILL   2

Interrupt maximum fill level.

This is a policy decision.

Definition at line 73 of file ecm.h.

Referenced by ecm_probe().

◆ ECM_IN_MAX_FILL

#define ECM_IN_MAX_FILL   8

Bulk IN maximum fill level.

This is a policy decision.

Definition at line 79 of file ecm.h.

Referenced by ecm_probe().

◆ ECM_IN_MTU

#define ECM_IN_MTU   ( ETH_FRAME_LEN + 4 /* possible VLAN header */ )

Bulk IN buffer size.

This is a policy decision.

Definition at line 85 of file ecm.h.

Referenced by ecm_probe().

Enumeration Type Documentation

◆ ecm_ethernet_packet_filter

Ethernet packet types.

Enumerator
ECM_PACKET_TYPE_PROMISCUOUS 

Promiscuous mode.

ECM_PACKET_TYPE_ALL_MULTICAST 

All multicast packets.

ECM_PACKET_TYPE_DIRECTED 

Unicast packets.

ECM_PACKET_TYPE_BROADCAST 

Broadcast packets.

ECM_PACKET_TYPE_MULTICAST 

Specified multicast packets.

Definition at line 26 of file ecm.h.

26 {
27 /** Promiscuous mode */
29 /** All multicast packets */
31 /** Unicast packets */
33 /** Broadcast packets */
35 /** Specified multicast packets */
37};
@ 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_MULTICAST
Specified multicast packets.
Definition ecm.h:36
@ ECM_PACKET_TYPE_BROADCAST
Broadcast packets.
Definition ecm.h:34
@ ECM_PACKET_TYPE_DIRECTED
Unicast packets.
Definition ecm.h:32

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 )
extern

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 )
extern

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().