You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ncm.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #ifndef _NCM_H
  2. #define _NCM_H
  3. /** @file
  4. *
  5. * CDC-NCM USB Ethernet driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <stdint.h>
  10. #include <ipxe/usb.h>
  11. #include <ipxe/cdc.h>
  12. #include <byteswap.h>
  13. #include "ecm.h"
  14. /** CDC-NCM subclass */
  15. #define USB_SUBCLASS_CDC_NCM 0x0d
  16. /** CDC-NCM interfaces */
  17. enum ncm_interfaces {
  18. /** Communications interface */
  19. NCM_INTERFACE_COMMS = 0,
  20. /** Data interface */
  21. NCM_INTERFACE_DATA,
  22. NCM_INTERFACE_COUNT
  23. };
  24. /** Alternate setting for CDC-NCM data interface */
  25. #define NCM_DATA_ALTERNATE 1
  26. /** Get NTB parameters */
  27. #define NCM_GET_NTB_PARAMETERS \
  28. ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  29. USB_REQUEST_TYPE ( 0x80 ) )
  30. /** NTB datagram parameters */
  31. struct ncm_ntb_datagram_parameters {
  32. /** Maximum size */
  33. uint32_t mtu;
  34. /** Alignment divisor */
  35. uint16_t divisor;
  36. /** Alignment remainder */
  37. uint16_t remainder;
  38. /** Alignment modulus */
  39. uint16_t modulus;
  40. } __attribute__ (( packed ));
  41. /** NTB parameters */
  42. struct ncm_ntb_parameters {
  43. /** Length */
  44. uint16_t len;
  45. /** Supported formats */
  46. uint16_t formats;
  47. /** IN datagram parameters */
  48. struct ncm_ntb_datagram_parameters in;
  49. /** Reserved */
  50. uint16_t reserved;
  51. /** OUT datagram parameters */
  52. struct ncm_ntb_datagram_parameters out;
  53. /** Maximum number of datagrams per OUT NTB */
  54. uint16_t max;
  55. } __attribute__ (( packed ));
  56. /** Set NTB input size */
  57. #define NCM_SET_NTB_INPUT_SIZE \
  58. ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  59. USB_REQUEST_TYPE ( 0x86 ) )
  60. /** Set NTB input size */
  61. struct ncm_set_ntb_input_size {
  62. /** Maximum size */
  63. uint32_t mtu;
  64. } __attribute__ (( packed ));
  65. /** NTB input size
  66. *
  67. * This is a policy decision. 2048 is the minimum size which must be
  68. * supported according to the specification.
  69. */
  70. #define NCM_NTB_INPUT_SIZE 2048
  71. /** CDC-NCM transfer header (16-bit) */
  72. struct ncm_transfer_header {
  73. /** Signature */
  74. uint32_t magic;
  75. /** Header length */
  76. uint16_t header_len;
  77. /** Sequence number */
  78. uint16_t sequence;
  79. /** Total length */
  80. uint16_t len;
  81. /** Offset of first datagram pointer */
  82. uint16_t offset;
  83. } __attribute__ (( packed ));
  84. /** CDC-NCM transfer header magic */
  85. #define NCM_TRANSFER_HEADER_MAGIC 0x484d434eUL
  86. /** CDC-NCM datagram descriptor (16-bit) */
  87. struct ncm_datagram_descriptor {
  88. /** Starting offset */
  89. uint16_t offset;
  90. /** Length */
  91. uint16_t len;
  92. } __attribute__ (( packed ));
  93. /** CDC-NCM datagram pointer (16-bit) */
  94. struct ncm_datagram_pointer {
  95. /** Signature */
  96. uint32_t magic;
  97. /** Header length */
  98. uint16_t header_len;
  99. /** Offset of next datagram pointer */
  100. uint16_t offset;
  101. /** Datagram descriptors
  102. *
  103. * Must be terminated by an empty descriptor.
  104. */
  105. struct ncm_datagram_descriptor desc[0];
  106. } __attribute__ (( packed ));
  107. /** CDC-NCM datagram pointer magic */
  108. #define NCM_DATAGRAM_POINTER_MAGIC 0x304d434eUL
  109. /** CDC-NCM datagram pointer CRC present flag */
  110. #define NCM_DATAGRAM_POINTER_MAGIC_CRC 0x01000000UL
  111. /** NTB constructed for transmitted packets (excluding padding)
  112. *
  113. * This is a policy decision.
  114. */
  115. struct ncm_ntb_header {
  116. /** Transfer header */
  117. struct ncm_transfer_header nth;
  118. /** Datagram pointer */
  119. struct ncm_datagram_pointer ndp;
  120. /** Datagram descriptors */
  121. struct ncm_datagram_descriptor desc[2];
  122. } __attribute__ (( packed ));
  123. /** A CDC-NCM network device */
  124. struct ncm_device {
  125. /** USB device */
  126. struct usb_device *usb;
  127. /** USB bus */
  128. struct usb_bus *bus;
  129. /** Network device */
  130. struct net_device *netdev;
  131. /** Communications interface */
  132. unsigned int comms;
  133. /** Data interface */
  134. unsigned int data;
  135. /** Interrupt endpoint */
  136. struct usb_endpoint intr;
  137. /** Bulk IN endpoint */
  138. struct usb_endpoint in;
  139. /** Bulk OUT endpoint */
  140. struct usb_endpoint out;
  141. /** Recycled interrupt I/O buffers */
  142. struct list_head intrs;
  143. /** Current bulk IN ring fill level */
  144. unsigned int fill;
  145. /** Transmitted packet sequence number */
  146. uint16_t sequence;
  147. /** Alignment padding required on transmitted packets */
  148. size_t padding;
  149. };
  150. /** Bulk IN ring fill level
  151. *
  152. * This is a policy decision.
  153. */
  154. #define NCM_IN_FILL 16
  155. /** Interrupt ring fill level
  156. *
  157. * This is a policy decision.
  158. */
  159. #define NCM_INTR_FILL 2
  160. #endif /* _NCM_H */