Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. /** Minimum allowed NTB input size */
  66. #define NCM_MIN_NTB_INPUT_SIZE 2048
  67. /** Maximum allowed NTB input size (16-bit) */
  68. #define NCM_MAX_NTB_INPUT_SIZE 65536
  69. /** CDC-NCM transfer header (16-bit) */
  70. struct ncm_transfer_header {
  71. /** Signature */
  72. uint32_t magic;
  73. /** Header length */
  74. uint16_t header_len;
  75. /** Sequence number */
  76. uint16_t sequence;
  77. /** Total length */
  78. uint16_t len;
  79. /** Offset of first datagram pointer */
  80. uint16_t offset;
  81. } __attribute__ (( packed ));
  82. /** CDC-NCM transfer header magic */
  83. #define NCM_TRANSFER_HEADER_MAGIC 0x484d434eUL
  84. /** CDC-NCM datagram descriptor (16-bit) */
  85. struct ncm_datagram_descriptor {
  86. /** Starting offset */
  87. uint16_t offset;
  88. /** Length */
  89. uint16_t len;
  90. } __attribute__ (( packed ));
  91. /** CDC-NCM datagram pointer (16-bit) */
  92. struct ncm_datagram_pointer {
  93. /** Signature */
  94. uint32_t magic;
  95. /** Header length */
  96. uint16_t header_len;
  97. /** Offset of next datagram pointer */
  98. uint16_t offset;
  99. /** Datagram descriptors
  100. *
  101. * Must be terminated by an empty descriptor.
  102. */
  103. struct ncm_datagram_descriptor desc[0];
  104. } __attribute__ (( packed ));
  105. /** CDC-NCM datagram pointer magic */
  106. #define NCM_DATAGRAM_POINTER_MAGIC 0x304d434eUL
  107. /** CDC-NCM datagram pointer CRC present flag */
  108. #define NCM_DATAGRAM_POINTER_MAGIC_CRC 0x01000000UL
  109. /** NTB constructed for transmitted packets (excluding padding)
  110. *
  111. * This is a policy decision.
  112. */
  113. struct ncm_ntb_header {
  114. /** Transfer header */
  115. struct ncm_transfer_header nth;
  116. /** Datagram pointer */
  117. struct ncm_datagram_pointer ndp;
  118. /** Datagram descriptors */
  119. struct ncm_datagram_descriptor desc[2];
  120. } __attribute__ (( packed ));
  121. /** A CDC-NCM network device */
  122. struct ncm_device {
  123. /** USB device */
  124. struct usb_device *usb;
  125. /** USB bus */
  126. struct usb_bus *bus;
  127. /** Network device */
  128. struct net_device *netdev;
  129. /** Communications interface */
  130. unsigned int comms;
  131. /** Data interface */
  132. unsigned int data;
  133. /** Maximum supported NTB input size */
  134. size_t mtu;
  135. /** Transmitted packet sequence number */
  136. uint16_t sequence;
  137. /** Alignment padding required on transmitted packets */
  138. size_t padding;
  139. /** Interrupt endpoint */
  140. struct usb_endpoint intr;
  141. /** Bulk IN endpoint */
  142. struct usb_endpoint in;
  143. /** Bulk OUT endpoint */
  144. struct usb_endpoint out;
  145. };
  146. /** Bulk IN ring minimum buffer count
  147. *
  148. * This is a policy decision.
  149. */
  150. #define NCM_IN_MIN_COUNT 3
  151. /** Bulk IN ring minimum total buffer size
  152. *
  153. * This is a policy decision.
  154. */
  155. #define NCM_IN_MIN_SIZE 16384
  156. /** Bulk IN ring maximum total buffer size
  157. *
  158. * This is a policy decision.
  159. */
  160. #define NCM_IN_MAX_SIZE 131072
  161. /** Interrupt ring buffer count
  162. *
  163. * This is a policy decision.
  164. */
  165. #define NCM_INTR_COUNT 2
  166. #endif /* _NCM_H */