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