iPXE
Data Structures | Macros | Enumerations | Functions
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. More...
 
#define ECM_SET_ETHERNET_PACKET_FILTER
 Set Ethernet packet filter. More...
 
#define ECM_INTR_MAX_FILL   2
 Interrupt maximum fill level. More...
 
#define ECM_IN_MAX_FILL   8
 Bulk IN maximum fill level. More...
 
#define ECM_IN_MTU   ( ETH_FRAME_LEN + 4 /* possible VLAN header */ )
 Bulk IN buffer size. More...
 

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

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 17 of file ecm.h.

◆ ECM_SET_ETHERNET_PACKET_FILTER

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

Set Ethernet packet filter.

Definition at line 20 of file ecm.h.

◆ ECM_INTR_MAX_FILL

#define ECM_INTR_MAX_FILL   2

Interrupt maximum fill level.

This is a policy decision.

Definition at line 72 of file ecm.h.

◆ ECM_IN_MAX_FILL

#define ECM_IN_MAX_FILL   8

Bulk IN maximum fill level.

This is a policy decision.

Definition at line 78 of file ecm.h.

◆ 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 84 of file ecm.h.

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 25 of file ecm.h.

25  {
26  /** Promiscuous mode */
28  /** All multicast packets */
30  /** Unicast packets */
31  ECM_PACKET_TYPE_DIRECTED = 0x0004,
32  /** Broadcast packets */
34  /** Specified multicast packets */
36 };
Unicast packets.
Definition: ecm.h:31
Promiscuous mode.
Definition: ecm.h:27
Specified multicast packets.
Definition: ecm.h:35
All multicast packets.
Definition: ecm.h:29
Broadcast packets.
Definition: ecm.h:33

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