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.

rhine.h 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #ifndef _RHINE_H
  2. #define _RHINE_H
  3. /** @file
  4. *
  5. * VIA Rhine network driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. /** Rhine BAR size */
  10. #define RHINE_BAR_SIZE 256
  11. /** Default timeout */
  12. #define RHINE_TIMEOUT_US 10000
  13. /** Rhine descriptor format */
  14. struct rhine_descriptor {
  15. uint32_t des0;
  16. uint32_t des1;
  17. uint32_t buffer;
  18. uint32_t next;
  19. } __attribute__ (( packed ));
  20. #define RHINE_DES0_OWN (1 << 31) /*< Owned descriptor */
  21. #define RHINE_DES1_IC (1 << 23) /*< Generate interrupt */
  22. #define RHINE_TDES1_EDP (1 << 22) /*< End of packet */
  23. #define RHINE_TDES1_STP (1 << 21) /*< Start of packet */
  24. #define RHINE_TDES1_TCPCK (1 << 20) /*< HW TCP checksum */
  25. #define RHINE_TDES1_UDPCK (1 << 19) /*< HW UDP checksum */
  26. #define RHINE_TDES1_IPCK (1 << 18) /*< HW IP checksum */
  27. #define RHINE_TDES1_TAG (1 << 17) /*< Tagged frame */
  28. #define RHINE_TDES1_CRC (1 << 16) /*< No CRC */
  29. #define RHINE_DES1_CHAIN (1 << 15) /*< Chained descriptor */
  30. #define RHINE_DES1_SIZE(_x) ((_x) & 0x7ff) /*< Frame size */
  31. #define RHINE_DES0_GETSIZE(_x) (((_x) >> 16) & 0x7ff)
  32. #define RHINE_RDES0_RXOK (1 << 15)
  33. #define RHINE_RDES0_VIDHIT (1 << 14)
  34. #define RHINE_RDES0_MAR (1 << 13)
  35. #define RHINE_RDES0_BAR (1 << 12)
  36. #define RHINE_RDES0_PHY (1 << 11)
  37. #define RHINE_RDES0_CHN (1 << 10)
  38. #define RHINE_RDES0_STP (1 << 9)
  39. #define RHINE_RDES0_EDP (1 << 8)
  40. #define RHINE_RDES0_BUFF (1 << 7)
  41. #define RHINE_RDES0_FRAG (1 << 6)
  42. #define RHINE_RDES0_RUNT (1 << 5)
  43. #define RHINE_RDES0_LONG (1 << 4)
  44. #define RHINE_RDES0_FOV (1 << 3)
  45. #define RHINE_RDES0_FAE (1 << 2)
  46. #define RHINE_RDES0_CRCE (1 << 1)
  47. #define RHINE_RDES0_RERR (1 << 0)
  48. #define RHINE_TDES0_TERR (1 << 15)
  49. #define RHINE_TDES0_UDF (1 << 11)
  50. #define RHINE_TDES0_CRS (1 << 10)
  51. #define RHINE_TDES0_OWC (1 << 9)
  52. #define RHINE_TDES0_ABT (1 << 8)
  53. #define RHINE_TDES0_CDH (1 << 7)
  54. #define RHINE_TDES0_COLS (1 << 4)
  55. #define RHINE_TDES0_NCR(_x) ((_x) & 0xf)
  56. #define RHINE_RING_ALIGN 4
  57. /** Rhine descriptor rings sizes */
  58. #define RHINE_RXDESC_NUM 4
  59. #define RHINE_TXDESC_NUM 8
  60. #define RHINE_RX_MAX_LEN 1536
  61. /** Rhine MAC address registers */
  62. #define RHINE_MAC 0x00
  63. /** Receive control register */
  64. #define RHINE_RCR 0x06
  65. #define RHINE_RCR_FIFO_TRSH(_x) (((_x) & 0x7) << 5) /*< RX FIFO threshold */
  66. #define RHINE_RCR_PHYS_ACCEPT (1 << 4) /*< Accept matching PA */
  67. #define RHINE_RCR_BCAST_ACCEPT (1 << 3) /*< Accept broadcast */
  68. #define RHINE_RCR_MCAST_ACCEPT (1 << 2) /*< Accept multicast */
  69. #define RHINE_RCR_RUNT_ACCEPT (1 << 1) /*< Accept runt frames */
  70. #define RHINE_RCR_ERR_ACCEPT (1 << 0) /*< Accept erroneous frames */
  71. /** Transmit control register */
  72. #define RHINE_TCR 0x07
  73. #define RHINE_TCR_LOOPBACK(_x) (((_x) & 0x3) << 1) /*< Transmit loop mode */
  74. #define RHINE_TCR_TAGGING (1 << 0) /*< 802.1P/Q packet tagging */
  75. /** Command 0 register */
  76. #define RHINE_CR0 0x08
  77. #define RHINE_CR0_RXSTART (1 << 6)
  78. #define RHINE_CR0_TXSTART (1 << 5)
  79. #define RHINE_CR0_TXEN (1 << 4) /*< Transmit enable */
  80. #define RHINE_CR0_RXEN (1 << 3) /*< Receive enable */
  81. #define RHINE_CR0_STOPNIC (1 << 2) /*< Stop NIC */
  82. #define RHINE_CR0_STARTNIC (1 << 1) /*< Start NIC */
  83. /** Command 1 register */
  84. #define RHINE_CR1 0x09
  85. #define RHINE_CR1_RESET (1 << 7) /*< Software reset */
  86. #define RHINE_CR1_RXPOLL (1 << 6) /*< Receive poll demand */
  87. #define RHINE_CR1_TXPOLL (1 << 5) /*< Xmit poll demand */
  88. #define RHINE_CR1_AUTOPOLL (1 << 3) /*< Disable autopoll */
  89. #define RHINE_CR1_FDX (1 << 2) /*< Full duplex */
  90. #define RIHNE_CR1_ACCUNI (1 << 1) /*< Disable accept unicast */
  91. /** Transmit queue wake register */
  92. #define RHINE_TXQUEUE_WAKE 0x0a
  93. /** Interrupt service 0 */
  94. #define RHINE_ISR0 0x0c
  95. #define RHINE_ISR0_MIBOVFL (1 << 7)
  96. #define RHINE_ISR0_PCIERR (1 << 6)
  97. #define RHINE_ISR0_RXRINGERR (1 << 5)
  98. #define RHINE_ISR0_TXRINGERR (1 << 4)
  99. #define RHINE_ISR0_TXERR (1 << 3)
  100. #define RHINE_ISR0_RXERR (1 << 2)
  101. #define RHINE_ISR0_TXDONE (1 << 1)
  102. #define RHINE_ISR0_RXDONE (1 << 0)
  103. /** Interrupt service 1 */
  104. #define RHINE_ISR1 0x0d
  105. #define RHINE_ISR1_GPI (1 << 7)
  106. #define RHINE_ISR1_PORTSTATE (1 << 6)
  107. #define RHINE_ISR1_TXABORT (1 << 5)
  108. #define RHINE_ISR1_RXNOBUF (1 << 4)
  109. #define RHINE_ISR1_RXFIFOOVFL (1 << 3)
  110. #define RHINE_ISR1_RXFIFOUNFL (1 << 2)
  111. #define RHINE_ISR1_TXFIFOUNFL (1 << 1)
  112. #define RHINE_ISR1_EARLYRX (1 << 0)
  113. /** Interrupt enable mask register 0 */
  114. #define RHINE_IMR0 0x0e
  115. /** Interrupt enable mask register 1 */
  116. #define RHINE_IMR1 0x0f
  117. /** RX queue descriptor base address */
  118. #define RHINE_RXQUEUE_BASE 0x18
  119. /** TX queue 0 descriptor base address */
  120. #define RHINE_TXQUEUE_BASE 0x1c
  121. /** MII configuration */
  122. #define RHINE_MII_CFG 0x6c
  123. /** MII status register */
  124. #define RHINE_MII_SR 0x6d
  125. #define RHINE_MII_SR_PHYRST (1 << 7) /*< PHY reset */
  126. #define RHINE_MII_SR_LINKNWAY (1 << 4) /*< Link status after N-Way */
  127. #define RHINE_MII_SR_PHYERR (1 << 3) /*< PHY device error */
  128. #define RHINE_MII_SR_DUPLEX (1 << 2) /*< Duplex mode after N-Way */
  129. #define RHINE_MII_SR_LINKPOLL (1 << 1) /*< Link status after poll */
  130. #define RHINE_MII_SR_LINKSPD (1 << 0) /*< Link speed after N-Way */
  131. /** MII bus control 0 register */
  132. #define RHINE_MII_BCR0 0x6e
  133. /** MII bus control 1 register */
  134. #define RHINE_MII_BCR1 0x6f
  135. /** MII control register */
  136. #define RHINE_MII_CR 0x70
  137. #define RHINE_MII_CR_AUTOPOLL (1 << 7) /*< MII auto polling */
  138. #define RHINE_MII_CR_RDEN (1 << 6) /*< PHY read enable */
  139. #define RHINE_MII_CR_WREN (1 << 5) /*< PHY write enable */
  140. #define RHINE_MII_CR_DIRECT (1 << 4) /*< Direct programming mode */
  141. #define RHINE_MII_CR_MDIOOUT (1 << 3) /*< MDIO output enable */
  142. /** MII port address */
  143. #define RHINE_MII_ADDR 0x71
  144. #define RHINE_MII_ADDR_MSRCEN (1 << 6)
  145. #define RHINE_MII_ADDR_MDONE (1 << 5)
  146. /** MII read/write data */
  147. #define RHINE_MII_RDWR 0x72
  148. /** EERPOM control/status register */
  149. #define RHINE_EEPROM_CTRL 0x74
  150. #define RHINE_EEPROM_CTRL_STATUS (1 << 7) /*< EEPROM status */
  151. #define RHINE_EEPROM_CTRL_RELOAD (1 << 5) /*< EEPROM reload */
  152. /** Chip configuration A */
  153. #define RHINE_CHIPCFG_A 0x78
  154. /* MMIO enable. Only valid for Rhine I. Reserved on later boards */
  155. #define RHINE_CHIPCFG_A_MMIO (1 << 5)
  156. /** Chip configuration B */
  157. #define RHINE_CHIPCFG_B 0x79
  158. /** Chip configuation C */
  159. #define RHINE_CHIPCFG_C 0x7a
  160. /** Chip configuration D */
  161. #define RHINE_CHIPCFG_D 0x7b
  162. /* MMIO enable. Only valid on Rhine II and later. GPIOEN on Rhine I */
  163. #define RHINE_CHIPCFG_D_MMIO (1 << 7)
  164. #define RHINE_REVISION_OLD 0x20
  165. /** A VIA Rhine descriptor ring */
  166. struct rhine_ring {
  167. /** Descriptors */
  168. struct rhine_descriptor *desc;
  169. /** Producer index */
  170. unsigned int prod;
  171. /** Consumer index */
  172. unsigned int cons;
  173. /** Number of descriptors */
  174. unsigned int count;
  175. /** Register address */
  176. unsigned int reg;
  177. };
  178. /**
  179. * Initialise descriptor ring
  180. *
  181. * @v ring Descriptor ring
  182. * @v count Number of descriptors (must be a power of 2)
  183. * @v reg Register address
  184. */
  185. static inline __attribute__ (( always_inline)) void
  186. rhine_init_ring ( struct rhine_ring *ring, unsigned int count,
  187. unsigned int reg ) {
  188. ring->count = count;
  189. ring->reg = reg;
  190. }
  191. /** A VIA Rhine network card */
  192. struct rhine_nic {
  193. /** I/O address (some PIO access is always required) */
  194. unsigned long ioaddr;
  195. /** Registers */
  196. void *regs;
  197. /** Cached value of CR1 (to avoid read-modify-write on fast path) */
  198. uint8_t cr1;
  199. /** MII interface */
  200. struct mii_interface mdio;
  201. /** MII device */
  202. struct mii_device mii;
  203. /** Transmit descriptor ring */
  204. struct rhine_ring tx;
  205. /** Receive descriptor ring */
  206. struct rhine_ring rx;
  207. /** Receive I/O buffers */
  208. struct io_buffer *rx_iobuf[RHINE_RXDESC_NUM];
  209. };
  210. #endif /* _RHINE_H */