iPXE
ncm.h
Go to the documentation of this file.
00001 #ifndef _NCM_H
00002 #define _NCM_H
00003 
00004 /** @file
00005  *
00006  * CDC-NCM USB Ethernet driver
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <ipxe/usb.h>
00014 #include <ipxe/cdc.h>
00015 #include <byteswap.h>
00016 #include "ecm.h"
00017 
00018 /** CDC-NCM subclass */
00019 #define USB_SUBCLASS_CDC_NCM 0x0d
00020 
00021 /** Get NTB parameters */
00022 #define NCM_GET_NTB_PARAMETERS                                          \
00023         ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE |           \
00024           USB_REQUEST_TYPE ( 0x80 ) )
00025 
00026 /** NTB datagram parameters */
00027 struct ncm_ntb_datagram_parameters {
00028         /** Maximum size */
00029         uint32_t mtu;
00030         /** Alignment divisor */
00031         uint16_t divisor;
00032         /** Alignment remainder */
00033         uint16_t remainder;
00034         /** Alignment modulus */
00035         uint16_t modulus;
00036 } __attribute__ (( packed ));
00037 
00038 /** NTB parameters */
00039 struct ncm_ntb_parameters {
00040         /** Length */
00041         uint16_t len;
00042         /** Supported formats */
00043         uint16_t formats;
00044         /** IN datagram parameters */
00045         struct ncm_ntb_datagram_parameters in;
00046         /** Reserved */
00047         uint16_t reserved;
00048         /** OUT datagram parameters */
00049         struct ncm_ntb_datagram_parameters out;
00050         /** Maximum number of datagrams per OUT NTB */
00051         uint16_t max;
00052 } __attribute__ (( packed ));
00053 
00054 /** Set MAC address */
00055 #define NCM_SET_NET_ADDRESS                                             \
00056         ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
00057           USB_REQUEST_TYPE ( 0x82 ) )
00058 
00059 /** Set NTB input size */
00060 #define NCM_SET_NTB_INPUT_SIZE                                          \
00061         ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
00062           USB_REQUEST_TYPE ( 0x86 ) )
00063 
00064 /** Set NTB input size */
00065 struct ncm_set_ntb_input_size {
00066         /** Maximum size */
00067         uint32_t mtu;
00068 } __attribute__ (( packed ));
00069 
00070 /** Minimum allowed NTB input size */
00071 #define NCM_MIN_NTB_INPUT_SIZE 2048
00072 
00073 /** Maximum allowed NTB input size (16-bit) */
00074 #define NCM_MAX_NTB_INPUT_SIZE 65536
00075 
00076 /** CDC-NCM transfer header (16-bit) */
00077 struct ncm_transfer_header {
00078         /** Signature */
00079         uint32_t magic;
00080         /** Header length */
00081         uint16_t header_len;
00082         /** Sequence number */
00083         uint16_t sequence;
00084         /** Total length */
00085         uint16_t len;
00086         /** Offset of first datagram pointer */
00087         uint16_t offset;
00088 } __attribute__ (( packed ));
00089 
00090 /** CDC-NCM transfer header magic */
00091 #define NCM_TRANSFER_HEADER_MAGIC 0x484d434eUL
00092 
00093 /** CDC-NCM datagram descriptor (16-bit) */
00094 struct ncm_datagram_descriptor {
00095         /** Starting offset */
00096         uint16_t offset;
00097         /** Length */
00098         uint16_t len;
00099 } __attribute__ (( packed ));
00100 
00101 /** CDC-NCM datagram pointer (16-bit) */
00102 struct ncm_datagram_pointer {
00103         /** Signature */
00104         uint32_t magic;
00105         /** Header length */
00106         uint16_t header_len;
00107         /** Offset of next datagram pointer */
00108         uint16_t offset;
00109         /** Datagram descriptors
00110          *
00111          * Must be terminated by an empty descriptor.
00112          */
00113         struct ncm_datagram_descriptor desc[0];
00114 } __attribute__ (( packed ));
00115 
00116 /** CDC-NCM datagram pointer magic */
00117 #define NCM_DATAGRAM_POINTER_MAGIC 0x304d434eUL
00118 
00119 /** CDC-NCM datagram pointer CRC present flag */
00120 #define NCM_DATAGRAM_POINTER_MAGIC_CRC 0x01000000UL
00121 
00122 /** NTB constructed for transmitted packets (excluding padding)
00123  *
00124  * This is a policy decision.
00125  */
00126 struct ncm_ntb_header {
00127         /** Transfer header */
00128         struct ncm_transfer_header nth;
00129         /** Datagram pointer */
00130         struct ncm_datagram_pointer ndp;
00131         /** Datagram descriptors */
00132         struct ncm_datagram_descriptor desc[2];
00133 } __attribute__ (( packed ));
00134 
00135 /** A CDC-NCM network device */
00136 struct ncm_device {
00137         /** USB device */
00138         struct usb_device *usb;
00139         /** USB bus */
00140         struct usb_bus *bus;
00141         /** Network device */
00142         struct net_device *netdev;
00143         /** USB network device */
00144         struct usbnet_device usbnet;
00145 
00146         /** Maximum supported NTB input size */
00147         size_t mtu;
00148         /** Transmitted packet sequence number */
00149         uint16_t sequence;
00150         /** Alignment padding required on transmitted packets */
00151         size_t padding;
00152 };
00153 
00154 /** Bulk IN ring minimum buffer count
00155  *
00156  * This is a policy decision.
00157  */
00158 #define NCM_IN_MIN_COUNT 3
00159 
00160 /** Bulk IN ring minimum total buffer size
00161  *
00162  * This is a policy decision.
00163  */
00164 #define NCM_IN_MIN_SIZE 16384
00165 
00166 /** Bulk IN ring maximum total buffer size
00167  *
00168  * This is a policy decision.
00169  */
00170 #define NCM_IN_MAX_SIZE 131072
00171 
00172 /** Interrupt ring buffer count
00173  *
00174  * This is a policy decision.
00175  */
00176 #define NCM_INTR_COUNT 2
00177 
00178 #endif /* _NCM_H */