iPXE
ncm.h
Go to the documentation of this file.
1 #ifndef _NCM_H
2 #define _NCM_H
3 
4 /** @file
5  *
6  * CDC-NCM USB Ethernet driver
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/usb.h>
15 #include <ipxe/cdc.h>
16 #include <byteswap.h>
17 #include "ecm.h"
18 
19 /** CDC-NCM subclass */
20 #define USB_SUBCLASS_CDC_NCM 0x0d
21 
22 /** Get NTB parameters */
23 #define NCM_GET_NTB_PARAMETERS \
24  ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
25  USB_REQUEST_TYPE ( 0x80 ) )
26 
27 /** NTB datagram parameters */
29  /** Maximum size */
31  /** Alignment divisor */
33  /** Alignment remainder */
35  /** Alignment modulus */
37 } __attribute__ (( packed ));
38 
39 /** NTB parameters */
41  /** Length */
43  /** Supported formats */
45  /** IN datagram parameters */
47  /** Reserved */
49  /** OUT datagram parameters */
51  /** Maximum number of datagrams per OUT NTB */
53 } __attribute__ (( packed ));
54 
55 /** Set MAC address */
56 #define NCM_SET_NET_ADDRESS \
57  ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
58  USB_REQUEST_TYPE ( 0x82 ) )
59 
60 /** Set NTB input size */
61 #define NCM_SET_NTB_INPUT_SIZE \
62  ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
63  USB_REQUEST_TYPE ( 0x86 ) )
64 
65 /** Set NTB input size */
67  /** Maximum size */
69 } __attribute__ (( packed ));
70 
71 /** Minimum allowed NTB input size */
72 #define NCM_MIN_NTB_INPUT_SIZE 2048
73 
74 /** Maximum allowed NTB input size (16-bit) */
75 #define NCM_MAX_NTB_INPUT_SIZE 65536
76 
77 /** CDC-NCM transfer header (16-bit) */
79  /** Signature */
81  /** Header length */
83  /** Sequence number */
85  /** Total length */
87  /** Offset of first datagram pointer */
89 } __attribute__ (( packed ));
90 
91 /** CDC-NCM transfer header magic */
92 #define NCM_TRANSFER_HEADER_MAGIC 0x484d434eUL
93 
94 /** CDC-NCM datagram descriptor (16-bit) */
96  /** Starting offset */
98  /** Length */
100 } __attribute__ (( packed ));
101 
102 /** CDC-NCM datagram pointer (16-bit) */
104  /** Signature */
106  /** Header length */
108  /** Offset of next datagram pointer */
110  /** Datagram descriptors
111  *
112  * Must be terminated by an empty descriptor.
113  */
115 } __attribute__ (( packed ));
116 
117 /** CDC-NCM datagram pointer magic */
118 #define NCM_DATAGRAM_POINTER_MAGIC 0x304d434eUL
119 
120 /** CDC-NCM datagram pointer CRC present flag */
121 #define NCM_DATAGRAM_POINTER_MAGIC_CRC 0x01000000UL
122 
123 /** NTB constructed for transmitted packets (excluding padding)
124  *
125  * This is a policy decision.
126  */
128  /** Transfer header */
130  /** Datagram pointer */
132  /** Datagram descriptors */
134 } __attribute__ (( packed ));
135 
136 /** A CDC-NCM network device */
137 struct ncm_device {
138  /** USB device */
139  struct usb_device *usb;
140  /** USB bus */
141  struct usb_bus *bus;
142  /** Network device */
144  /** USB network device */
146 
147  /** Maximum supported NTB input size */
148  size_t mtu;
149  /** Transmitted packet sequence number */
151  /** Alignment padding required on transmitted packets */
152  size_t padding;
153 };
154 
155 /** Bulk IN ring minimum buffer count
156  *
157  * This is a policy decision.
158  */
159 #define NCM_IN_MIN_COUNT 3
160 
161 /** Bulk IN ring minimum total buffer size
162  *
163  * This is a policy decision.
164  */
165 #define NCM_IN_MIN_SIZE 16384
166 
167 /** Bulk IN ring maximum total buffer size
168  *
169  * This is a policy decision.
170  */
171 #define NCM_IN_MAX_SIZE 131072
172 
173 /** Interrupt ring buffer count
174  *
175  * This is a policy decision.
176  */
177 #define NCM_INTR_COUNT 2
178 
179 #endif /* _NCM_H */
unsigned short uint16_t
Definition: stdint.h:11
CDC-ECM USB Ethernet driver.
NTB datagram parameters.
Definition: ncm.h:28
size_t mtu
Maximum supported NTB input size.
Definition: ncm.h:148
struct ncm_datagram_pointer ndp
Datagram pointer.
Definition: ncm.h:131
uint16_t remainder
Alignment remainder.
Definition: ncm.h:34
CDC-NCM datagram pointer (16-bit)
Definition: ncm.h:103
uint16_t modulus
Alignment modulus.
Definition: ncm.h:36
CDC-NCM transfer header (16-bit)
Definition: ncm.h:78
struct ncm_transfer_header nth
Transfer header.
Definition: ncm.h:129
struct ncm_datagram_descriptor desc[2]
Datagram descriptors.
Definition: ncm.h:133
struct ncm_ntb_datagram_parameters in
IN datagram parameters.
Definition: ncm.h:46
struct ncm_ntb_datagram_parameters out
OUT datagram parameters.
Definition: ncm.h:50
struct ncm_ntb_datagram_parameters __attribute__
uint32_t mtu
Maximum size.
Definition: ncm.h:30
uint16_t sequence
Sequence number.
Definition: ncm.h:84
struct ncm_datagram_descriptor desc[0]
Datagram descriptors.
Definition: ncm.h:114
Set NTB input size.
Definition: ncm.h:66
uint32_t mtu
Maximum size.
Definition: ncm.h:68
uint16_t offset
Offset of first datagram pointer.
Definition: ncm.h:88
uint16_t sequence
Transmitted packet sequence number.
Definition: ncm.h:150
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct net_device * netdev
Network device.
Definition: ncm.h:143
uint16_t header_len
Header length.
Definition: ncm.h:107
CDC-NCM datagram descriptor (16-bit)
Definition: ncm.h:95
struct usb_device * usb
USB device.
Definition: ncm.h:139
uint16_t offset
Starting offset.
Definition: ncm.h:97
uint16_t max
Maximum number of datagrams per OUT NTB.
Definition: ncm.h:52
A USB device.
Definition: usb.h:723
uint16_t len
Total length.
Definition: ncm.h:86
uint32_t magic
Signature.
Definition: ncm.h:80
uint16_t offset
Offset of next datagram pointer.
Definition: ncm.h:109
A USB network device.
Definition: usbnet.h:16
uint16_t len
Length.
Definition: ncm.h:42
NTB parameters.
Definition: ncm.h:40
struct usbnet_device usbnet
USB network device.
Definition: ncm.h:145
A network device.
Definition: netdevice.h:353
uint16_t len
Length.
Definition: ncm.h:99
uint16_t divisor
Alignment divisor.
Definition: ncm.h:32
unsigned int uint32_t
Definition: stdint.h:12
A CDC-NCM network device.
Definition: ncm.h:137
uint32_t magic
Signature.
Definition: ncm.h:105
Universal Serial Bus (USB)
FILE_SECBOOT(PERMITTED)
USB Communications Device Class (CDC)
uint16_t header_len
Header length.
Definition: ncm.h:82
NTB constructed for transmitted packets (excluding padding)
Definition: ncm.h:127
size_t padding
Alignment padding required on transmitted packets.
Definition: ncm.h:152
A USB bus.
Definition: usb.h:966
uint16_t formats
Supported formats.
Definition: ncm.h:44
struct usb_bus * bus
USB bus.
Definition: ncm.h:141
uint16_t reserved
Reserved.
Definition: ncm.h:48