nb8800.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #ifndef _NB8800_H_
  2. #define _NB8800_H_
  3. #include <linux/types.h>
  4. #include <linux/skbuff.h>
  5. #include <linux/phy.h>
  6. #include <linux/clk.h>
  7. #include <linux/bitops.h>
  8. #define RX_DESC_COUNT 256
  9. #define TX_DESC_COUNT 256
  10. #define NB8800_DESC_LOW 4
  11. #define RX_BUF_SIZE 1552
  12. #define RX_COPYBREAK 256
  13. #define RX_COPYHDR 128
  14. #define MAX_MDC_CLOCK 2500000
  15. /* Stargate Solutions SSN8800 core registers */
  16. #define NB8800_TX_CTL1 0x000
  17. #define TX_TPD BIT(5)
  18. #define TX_APPEND_FCS BIT(4)
  19. #define TX_PAD_EN BIT(3)
  20. #define TX_RETRY_EN BIT(2)
  21. #define TX_EN BIT(0)
  22. #define NB8800_TX_CTL2 0x001
  23. #define NB8800_RX_CTL 0x004
  24. #define RX_BC_DISABLE BIT(7)
  25. #define RX_RUNT BIT(6)
  26. #define RX_AF_EN BIT(5)
  27. #define RX_PAUSE_EN BIT(3)
  28. #define RX_SEND_CRC BIT(2)
  29. #define RX_PAD_STRIP BIT(1)
  30. #define RX_EN BIT(0)
  31. #define NB8800_RANDOM_SEED 0x008
  32. #define NB8800_TX_SDP 0x14
  33. #define NB8800_TX_TPDP1 0x18
  34. #define NB8800_TX_TPDP2 0x19
  35. #define NB8800_SLOT_TIME 0x1c
  36. #define NB8800_MDIO_CMD 0x020
  37. #define MDIO_CMD_GO BIT(31)
  38. #define MDIO_CMD_WR BIT(26)
  39. #define MDIO_CMD_ADDR(x) ((x) << 21)
  40. #define MDIO_CMD_REG(x) ((x) << 16)
  41. #define MDIO_CMD_DATA(x) ((x) << 0)
  42. #define NB8800_MDIO_STS 0x024
  43. #define MDIO_STS_ERR BIT(31)
  44. #define NB8800_MC_ADDR(i) (0x028 + (i))
  45. #define NB8800_MC_INIT 0x02e
  46. #define NB8800_UC_ADDR(i) (0x03c + (i))
  47. #define NB8800_MAC_MODE 0x044
  48. #define RGMII_MODE BIT(7)
  49. #define HALF_DUPLEX BIT(4)
  50. #define BURST_EN BIT(3)
  51. #define LOOPBACK_EN BIT(2)
  52. #define GMAC_MODE BIT(0)
  53. #define NB8800_IC_THRESHOLD 0x050
  54. #define NB8800_PE_THRESHOLD 0x051
  55. #define NB8800_PF_THRESHOLD 0x052
  56. #define NB8800_TX_BUFSIZE 0x054
  57. #define NB8800_FIFO_CTL 0x056
  58. #define NB8800_PQ1 0x060
  59. #define NB8800_PQ2 0x061
  60. #define NB8800_SRC_ADDR(i) (0x06a + (i))
  61. #define NB8800_STAT_DATA 0x078
  62. #define NB8800_STAT_INDEX 0x07c
  63. #define NB8800_STAT_CLEAR 0x07d
  64. #define NB8800_SLEEP_MODE 0x07e
  65. #define SLEEP_MODE BIT(0)
  66. #define NB8800_WAKEUP 0x07f
  67. #define WAKEUP BIT(0)
  68. /* Aurora NB8800 host interface registers */
  69. #define NB8800_TXC_CR 0x100
  70. #define TCR_LK BIT(12)
  71. #define TCR_DS BIT(11)
  72. #define TCR_BTS(x) (((x) & 0x7) << 8)
  73. #define TCR_DIE BIT(7)
  74. #define TCR_TFI(x) (((x) & 0x7) << 4)
  75. #define TCR_LE BIT(3)
  76. #define TCR_RS BIT(2)
  77. #define TCR_DM BIT(1)
  78. #define TCR_EN BIT(0)
  79. #define NB8800_TXC_SR 0x104
  80. #define TSR_DE BIT(3)
  81. #define TSR_DI BIT(2)
  82. #define TSR_TO BIT(1)
  83. #define TSR_TI BIT(0)
  84. #define NB8800_TX_SAR 0x108
  85. #define NB8800_TX_DESC_ADDR 0x10c
  86. #define NB8800_TX_REPORT_ADDR 0x110
  87. #define TX_BYTES_TRANSFERRED(x) (((x) >> 16) & 0xffff)
  88. #define TX_FIRST_DEFERRAL BIT(7)
  89. #define TX_EARLY_COLLISIONS(x) (((x) >> 3) & 0xf)
  90. #define TX_LATE_COLLISION BIT(2)
  91. #define TX_PACKET_DROPPED BIT(1)
  92. #define TX_FIFO_UNDERRUN BIT(0)
  93. #define IS_TX_ERROR(r) ((r) & 0x07)
  94. #define NB8800_TX_FIFO_SR 0x114
  95. #define NB8800_TX_ITR 0x118
  96. #define NB8800_RXC_CR 0x200
  97. #define RCR_FL BIT(13)
  98. #define RCR_LK BIT(12)
  99. #define RCR_DS BIT(11)
  100. #define RCR_BTS(x) (((x) & 7) << 8)
  101. #define RCR_DIE BIT(7)
  102. #define RCR_RFI(x) (((x) & 7) << 4)
  103. #define RCR_LE BIT(3)
  104. #define RCR_RS BIT(2)
  105. #define RCR_DM BIT(1)
  106. #define RCR_EN BIT(0)
  107. #define NB8800_RXC_SR 0x204
  108. #define RSR_DE BIT(3)
  109. #define RSR_DI BIT(2)
  110. #define RSR_RO BIT(1)
  111. #define RSR_RI BIT(0)
  112. #define NB8800_RX_SAR 0x208
  113. #define NB8800_RX_DESC_ADDR 0x20c
  114. #define NB8800_RX_REPORT_ADDR 0x210
  115. #define RX_BYTES_TRANSFERRED(x) (((x) >> 16) & 0xFFFF)
  116. #define RX_MULTICAST_PKT BIT(9)
  117. #define RX_BROADCAST_PKT BIT(8)
  118. #define RX_LENGTH_ERR BIT(7)
  119. #define RX_FCS_ERR BIT(6)
  120. #define RX_RUNT_PKT BIT(5)
  121. #define RX_FIFO_OVERRUN BIT(4)
  122. #define RX_LATE_COLLISION BIT(3)
  123. #define RX_ALIGNMENT_ERROR BIT(2)
  124. #define RX_ERROR_MASK 0xfc
  125. #define IS_RX_ERROR(r) ((r) & RX_ERROR_MASK)
  126. #define NB8800_RX_FIFO_SR 0x214
  127. #define NB8800_RX_ITR 0x218
  128. /* Sigma Designs SMP86xx additional registers */
  129. #define NB8800_TANGOX_PAD_MODE 0x400
  130. #define PAD_MODE_MASK 0x7
  131. #define PAD_MODE_MII 0x0
  132. #define PAD_MODE_RGMII 0x1
  133. #define PAD_MODE_GTX_CLK_INV BIT(3)
  134. #define PAD_MODE_GTX_CLK_DELAY BIT(4)
  135. #define NB8800_TANGOX_MDIO_CLKDIV 0x420
  136. #define NB8800_TANGOX_RESET 0x424
  137. /* Hardware DMA descriptor */
  138. struct nb8800_dma_desc {
  139. u32 s_addr; /* start address */
  140. u32 n_addr; /* next descriptor address */
  141. u32 r_addr; /* report address */
  142. u32 config;
  143. } __aligned(8);
  144. #define DESC_ID BIT(23)
  145. #define DESC_EOC BIT(22)
  146. #define DESC_EOF BIT(21)
  147. #define DESC_LK BIT(20)
  148. #define DESC_DS BIT(19)
  149. #define DESC_BTS(x) (((x) & 0x7) << 16)
  150. /* DMA descriptor and associated data for rx.
  151. * Allocated from coherent memory.
  152. */
  153. struct nb8800_rx_desc {
  154. /* DMA descriptor */
  155. struct nb8800_dma_desc desc;
  156. /* Status report filled in by hardware */
  157. u32 report;
  158. };
  159. /* Address of buffer on rx ring */
  160. struct nb8800_rx_buf {
  161. struct page *page;
  162. unsigned long offset;
  163. };
  164. /* DMA descriptors and associated data for tx.
  165. * Allocated from coherent memory.
  166. */
  167. struct nb8800_tx_desc {
  168. /* DMA descriptor. The second descriptor is used if packet
  169. * data is unaligned.
  170. */
  171. struct nb8800_dma_desc desc[2];
  172. /* Status report filled in by hardware */
  173. u32 report;
  174. /* Bounce buffer for initial unaligned part of packet */
  175. u8 buf[8] __aligned(8);
  176. };
  177. /* Packet in tx queue */
  178. struct nb8800_tx_buf {
  179. /* Currently queued skb */
  180. struct sk_buff *skb;
  181. /* DMA address of the first descriptor */
  182. dma_addr_t dma_desc;
  183. /* DMA address of packet data */
  184. dma_addr_t dma_addr;
  185. /* Length of DMA mapping, less than skb->len if alignment
  186. * buffer is used.
  187. */
  188. unsigned int dma_len;
  189. /* Number of packets in chain starting here */
  190. unsigned int chain_len;
  191. /* Packet chain ready to be submitted to hardware */
  192. bool ready;
  193. };
  194. struct nb8800_priv {
  195. struct napi_struct napi;
  196. void __iomem *base;
  197. /* RX DMA descriptors */
  198. struct nb8800_rx_desc *rx_descs;
  199. /* RX buffers referenced by DMA descriptors */
  200. struct nb8800_rx_buf *rx_bufs;
  201. /* Current end of chain */
  202. u32 rx_eoc;
  203. /* Value for rx interrupt time register in NAPI interrupt mode */
  204. u32 rx_itr_irq;
  205. /* Value for rx interrupt time register in NAPI poll mode */
  206. u32 rx_itr_poll;
  207. /* Value for config field of rx DMA descriptors */
  208. u32 rx_dma_config;
  209. /* TX DMA descriptors */
  210. struct nb8800_tx_desc *tx_descs;
  211. /* TX packet queue */
  212. struct nb8800_tx_buf *tx_bufs;
  213. /* Number of free tx queue entries */
  214. atomic_t tx_free;
  215. /* First free tx queue entry */
  216. u32 tx_next;
  217. /* Next buffer to transmit */
  218. u32 tx_queue;
  219. /* Start of current packet chain */
  220. struct nb8800_tx_buf *tx_chain;
  221. /* Next buffer to reclaim */
  222. u32 tx_done;
  223. /* Lock for DMA activation */
  224. spinlock_t tx_lock;
  225. struct mii_bus *mii_bus;
  226. struct device_node *phy_node;
  227. struct phy_device *phydev;
  228. /* PHY connection type from DT */
  229. int phy_mode;
  230. /* Current link status */
  231. int speed;
  232. int duplex;
  233. int link;
  234. /* Pause settings */
  235. bool pause_aneg;
  236. bool pause_rx;
  237. bool pause_tx;
  238. /* DMA base address of rx descriptors, see rx_descs above */
  239. dma_addr_t rx_desc_dma;
  240. /* DMA base address of tx descriptors, see tx_descs above */
  241. dma_addr_t tx_desc_dma;
  242. struct clk *clk;
  243. };
  244. struct nb8800_ops {
  245. int (*init)(struct net_device *dev);
  246. int (*reset)(struct net_device *dev);
  247. };
  248. #endif /* _NB8800_H_ */