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.0KB

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