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.

dm96xx.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #ifndef _DM96XX_H
  2. #define _DM96XX_H
  3. /** @file
  4. *
  5. * Davicom DM96xx USB Ethernet driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <ipxe/usb.h>
  10. #include <ipxe/usbnet.h>
  11. #include <ipxe/if_ether.h>
  12. /** Read register(s) */
  13. #define DM96XX_READ_REGISTER \
  14. ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
  15. USB_REQUEST_TYPE ( 0x00 ) )
  16. /** Write register(s) */
  17. #define DM96XX_WRITE_REGISTER \
  18. ( USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
  19. USB_REQUEST_TYPE ( 0x01 ) )
  20. /** Write single register */
  21. #define DM96XX_WRITE1_REGISTER \
  22. ( USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
  23. USB_REQUEST_TYPE ( 0x03 ) )
  24. /** Network control register */
  25. #define DM96XX_NCR 0x00
  26. #define DM96XX_NCR_RST 0x01 /**< Software reset */
  27. /** Network status register */
  28. #define DM96XX_NSR 0x01
  29. #define DM96XX_NSR_LINKST 0x40 /**< Link status */
  30. /** Receive control register */
  31. #define DM96XX_RCR 0x05
  32. #define DM96XX_RCR_ALL 0x08 /**< Pass all multicast */
  33. #define DM96XX_RCR_RUNT 0x04 /**< Pass runt packet */
  34. #define DM96XX_RCR_PRMSC 0x02 /**< Promiscuous mode */
  35. #define DM96XX_RCR_RXEN 0x01 /**< RX enable */
  36. /** Receive status register */
  37. #define DM96XX_RSR 0x06
  38. #define DM96XX_RSR_MF 0x40 /**< Multicast frame */
  39. /** PHY address registers */
  40. #define DM96XX_PAR 0x10
  41. /** Chip revision register */
  42. #define DM96XX_CHIPR 0x2c
  43. #define DM96XX_CHIPR_9601 0x00 /**< DM9601 */
  44. #define DM96XX_CHIPR_9620 0x01 /**< DM9620 */
  45. /** RX header control/status register (DM9620+ only) */
  46. #define DM96XX_MODE_CTL 0x91
  47. #define DM96XX_MODE_CTL_MODE 0x80 /**< 4-byte header mode */
  48. /** DM96xx interrupt data */
  49. struct dm96xx_interrupt {
  50. /** Network status register */
  51. uint8_t nsr;
  52. /** Transmit status registers */
  53. uint8_t tsr[2];
  54. /** Receive status register */
  55. uint8_t rsr;
  56. /** Receive overflow counter register */
  57. uint8_t rocr;
  58. /** Receive packet counter */
  59. uint8_t rxc;
  60. /** Transmit packet counter */
  61. uint8_t txc;
  62. /** General purpose register */
  63. uint8_t gpr;
  64. } __attribute__ (( packed ));
  65. /** DM96xx receive header */
  66. struct dm96xx_rx_header {
  67. /** Packet status */
  68. uint8_t rsr;
  69. /** Packet length (excluding this header, including CRC) */
  70. uint16_t len;
  71. } __attribute__ (( packed ));
  72. /** DM96xx transmit header */
  73. struct dm96xx_tx_header {
  74. /** Packet length (excluding this header) */
  75. uint16_t len;
  76. } __attribute__ (( packed ));
  77. /** A DM96xx network device */
  78. struct dm96xx_device {
  79. /** USB device */
  80. struct usb_device *usb;
  81. /** USB bus */
  82. struct usb_bus *bus;
  83. /** Network device */
  84. struct net_device *netdev;
  85. /** USB network device */
  86. struct usbnet_device usbnet;
  87. };
  88. /**
  89. * Read registers
  90. *
  91. * @v dm96xx DM96xx device
  92. * @v offset Register offset
  93. * @v data Data buffer
  94. * @v len Length of data
  95. * @ret rc Return status code
  96. */
  97. static inline __attribute__ (( always_inline )) int
  98. dm96xx_read_registers ( struct dm96xx_device *dm96xx, unsigned int offset,
  99. void *data, size_t len ) {
  100. return usb_control ( dm96xx->usb, DM96XX_READ_REGISTER, 0, offset,
  101. data, len );
  102. }
  103. /**
  104. * Read register
  105. *
  106. * @v dm96xx DM96xx device
  107. * @v offset Register offset
  108. * @ret value Register value, or negative error
  109. */
  110. static inline __attribute__ (( always_inline )) int
  111. dm96xx_read_register ( struct dm96xx_device *dm96xx, unsigned int offset ) {
  112. uint8_t value;
  113. int rc;
  114. if ( ( rc = dm96xx_read_registers ( dm96xx, offset, &value,
  115. sizeof ( value ) ) ) != 0 )
  116. return rc;
  117. return value;
  118. }
  119. /**
  120. * Write registers
  121. *
  122. * @v dm96xx DM96xx device
  123. * @v offset Register offset
  124. * @v data Data buffer
  125. * @v len Length of data
  126. * @ret rc Return status code
  127. */
  128. static inline __attribute__ (( always_inline )) int
  129. dm96xx_write_registers ( struct dm96xx_device *dm96xx, unsigned int offset,
  130. void *data, size_t len ) {
  131. return usb_control ( dm96xx->usb, DM96XX_WRITE_REGISTER, 0, offset,
  132. data, len );
  133. }
  134. /**
  135. * Write register
  136. *
  137. * @v dm96xx DM96xx device
  138. * @v offset Register offset
  139. * @v value Register value
  140. * @ret rc Return status code
  141. */
  142. static inline __attribute__ (( always_inline )) int
  143. dm96xx_write_register ( struct dm96xx_device *dm96xx, unsigned int offset,
  144. uint8_t value ) {
  145. return usb_control ( dm96xx->usb, DM96XX_WRITE1_REGISTER, value,
  146. offset, NULL, 0 );
  147. }
  148. /** Reset delay (in microseconds) */
  149. #define DM96XX_RESET_DELAY_US 10
  150. /** Interrupt maximum fill level
  151. *
  152. * This is a policy decision.
  153. */
  154. #define DM96XX_INTR_MAX_FILL 2
  155. /** Bulk IN maximum fill level
  156. *
  157. * This is a policy decision.
  158. */
  159. #define DM96XX_IN_MAX_FILL 8
  160. /** Bulk IN buffer size */
  161. #define DM96XX_IN_MTU \
  162. ( 4 /* DM96xx header */ + ETH_FRAME_LEN + \
  163. 4 /* possible VLAN header */ + 4 /* CRC */ )
  164. #endif /* _DM96XX_H */