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 3.8KB

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