pasemi_mac.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2006 PA Semi, Inc
  4. *
  5. * Driver for the PA6T-1682M onchip 1G/10G Ethernet MACs, soft state and
  6. * hardware register layouts.
  7. */
  8. #ifndef PASEMI_MAC_H
  9. #define PASEMI_MAC_H
  10. #include <linux/ethtool.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/phy.h>
  14. /* Must be a power of two */
  15. #define RX_RING_SIZE 2048
  16. #define TX_RING_SIZE 4096
  17. #define CS_RING_SIZE (TX_RING_SIZE*2)
  18. #define MAX_CS 2
  19. struct pasemi_mac_txring {
  20. struct pasemi_dmachan chan; /* Must be first */
  21. spinlock_t lock;
  22. unsigned int size;
  23. unsigned int next_to_fill;
  24. unsigned int next_to_clean;
  25. struct pasemi_mac_buffer *ring_info;
  26. struct pasemi_mac *mac; /* Needed in intr handler */
  27. struct timer_list clean_timer;
  28. };
  29. struct pasemi_mac_rxring {
  30. struct pasemi_dmachan chan; /* Must be first */
  31. spinlock_t lock;
  32. u64 *buffers; /* RX interface buffer ring */
  33. dma_addr_t buf_dma;
  34. unsigned int size;
  35. unsigned int next_to_fill;
  36. unsigned int next_to_clean;
  37. struct pasemi_mac_buffer *ring_info;
  38. struct pasemi_mac *mac; /* Needed in intr handler */
  39. };
  40. struct pasemi_mac_csring {
  41. struct pasemi_dmachan chan;
  42. unsigned int size;
  43. unsigned int next_to_fill;
  44. int events[2];
  45. int last_event;
  46. int fun;
  47. };
  48. struct pasemi_mac {
  49. struct net_device *netdev;
  50. struct pci_dev *pdev;
  51. struct pci_dev *dma_pdev;
  52. struct pci_dev *iob_pdev;
  53. struct napi_struct napi;
  54. int bufsz; /* RX ring buffer size */
  55. int last_cs;
  56. int num_cs;
  57. u32 dma_if;
  58. u8 type;
  59. #define MAC_TYPE_GMAC 1
  60. #define MAC_TYPE_XAUI 2
  61. u8 mac_addr[ETH_ALEN];
  62. struct timer_list rxtimer;
  63. struct pasemi_mac_txring *tx;
  64. struct pasemi_mac_rxring *rx;
  65. struct pasemi_mac_csring *cs[MAX_CS];
  66. char tx_irq_name[10]; /* "eth%d tx" */
  67. char rx_irq_name[10]; /* "eth%d rx" */
  68. int link;
  69. int speed;
  70. int duplex;
  71. unsigned int msg_enable;
  72. };
  73. /* Software status descriptor (ring_info) */
  74. struct pasemi_mac_buffer {
  75. struct sk_buff *skb;
  76. dma_addr_t dma;
  77. };
  78. #define TX_DESC(tx, num) ((tx)->chan.ring_virt[(num) & (TX_RING_SIZE-1)])
  79. #define TX_DESC_INFO(tx, num) ((tx)->ring_info[(num) & (TX_RING_SIZE-1)])
  80. #define RX_DESC(rx, num) ((rx)->chan.ring_virt[(num) & (RX_RING_SIZE-1)])
  81. #define RX_DESC_INFO(rx, num) ((rx)->ring_info[(num) & (RX_RING_SIZE-1)])
  82. #define RX_BUFF(rx, num) ((rx)->buffers[(num) & (RX_RING_SIZE-1)])
  83. #define CS_DESC(cs, num) ((cs)->chan.ring_virt[(num) & (CS_RING_SIZE-1)])
  84. #define RING_USED(ring) (((ring)->next_to_fill - (ring)->next_to_clean) \
  85. & ((ring)->size - 1))
  86. #define RING_AVAIL(ring) ((ring->size) - RING_USED(ring))
  87. /* PCI register offsets and formats */
  88. /* MAC CFG register offsets */
  89. enum {
  90. PAS_MAC_CFG_PCFG = 0x80,
  91. PAS_MAC_CFG_MACCFG = 0x84,
  92. PAS_MAC_CFG_ADR0 = 0x8c,
  93. PAS_MAC_CFG_ADR1 = 0x90,
  94. PAS_MAC_CFG_TXP = 0x98,
  95. PAS_MAC_CFG_RMON = 0x100,
  96. PAS_MAC_IPC_CHNL = 0x208,
  97. };
  98. /* MAC CFG register fields */
  99. #define PAS_MAC_CFG_PCFG_PE 0x80000000
  100. #define PAS_MAC_CFG_PCFG_CE 0x40000000
  101. #define PAS_MAC_CFG_PCFG_BU 0x20000000
  102. #define PAS_MAC_CFG_PCFG_TT 0x10000000
  103. #define PAS_MAC_CFG_PCFG_TSR_M 0x0c000000
  104. #define PAS_MAC_CFG_PCFG_TSR_10M 0x00000000
  105. #define PAS_MAC_CFG_PCFG_TSR_100M 0x04000000
  106. #define PAS_MAC_CFG_PCFG_TSR_1G 0x08000000
  107. #define PAS_MAC_CFG_PCFG_TSR_10G 0x0c000000
  108. #define PAS_MAC_CFG_PCFG_T24 0x02000000
  109. #define PAS_MAC_CFG_PCFG_PR 0x01000000
  110. #define PAS_MAC_CFG_PCFG_CRO_M 0x00ff0000
  111. #define PAS_MAC_CFG_PCFG_CRO_S 16
  112. #define PAS_MAC_CFG_PCFG_IPO_M 0x0000ff00
  113. #define PAS_MAC_CFG_PCFG_IPO_S 8
  114. #define PAS_MAC_CFG_PCFG_S1 0x00000080
  115. #define PAS_MAC_CFG_PCFG_IO_M 0x00000060
  116. #define PAS_MAC_CFG_PCFG_IO_MAC 0x00000000
  117. #define PAS_MAC_CFG_PCFG_IO_OFF 0x00000020
  118. #define PAS_MAC_CFG_PCFG_IO_IND_ETH 0x00000040
  119. #define PAS_MAC_CFG_PCFG_IO_IND_IP 0x00000060
  120. #define PAS_MAC_CFG_PCFG_LP 0x00000010
  121. #define PAS_MAC_CFG_PCFG_TS 0x00000008
  122. #define PAS_MAC_CFG_PCFG_HD 0x00000004
  123. #define PAS_MAC_CFG_PCFG_SPD_M 0x00000003
  124. #define PAS_MAC_CFG_PCFG_SPD_10M 0x00000000
  125. #define PAS_MAC_CFG_PCFG_SPD_100M 0x00000001
  126. #define PAS_MAC_CFG_PCFG_SPD_1G 0x00000002
  127. #define PAS_MAC_CFG_PCFG_SPD_10G 0x00000003
  128. #define PAS_MAC_CFG_MACCFG_TXT_M 0x70000000
  129. #define PAS_MAC_CFG_MACCFG_TXT_S 28
  130. #define PAS_MAC_CFG_MACCFG_PRES_M 0x0f000000
  131. #define PAS_MAC_CFG_MACCFG_PRES_S 24
  132. #define PAS_MAC_CFG_MACCFG_MAXF_M 0x00ffff00
  133. #define PAS_MAC_CFG_MACCFG_MAXF_S 8
  134. #define PAS_MAC_CFG_MACCFG_MAXF(x) (((x) << PAS_MAC_CFG_MACCFG_MAXF_S) & \
  135. PAS_MAC_CFG_MACCFG_MAXF_M)
  136. #define PAS_MAC_CFG_MACCFG_MINF_M 0x000000ff
  137. #define PAS_MAC_CFG_MACCFG_MINF_S 0
  138. #define PAS_MAC_CFG_TXP_FCF 0x01000000
  139. #define PAS_MAC_CFG_TXP_FCE 0x00800000
  140. #define PAS_MAC_CFG_TXP_FC 0x00400000
  141. #define PAS_MAC_CFG_TXP_FPC_M 0x00300000
  142. #define PAS_MAC_CFG_TXP_FPC_S 20
  143. #define PAS_MAC_CFG_TXP_FPC(x) (((x) << PAS_MAC_CFG_TXP_FPC_S) & \
  144. PAS_MAC_CFG_TXP_FPC_M)
  145. #define PAS_MAC_CFG_TXP_RT 0x00080000
  146. #define PAS_MAC_CFG_TXP_BL 0x00040000
  147. #define PAS_MAC_CFG_TXP_SL_M 0x00030000
  148. #define PAS_MAC_CFG_TXP_SL_S 16
  149. #define PAS_MAC_CFG_TXP_SL(x) (((x) << PAS_MAC_CFG_TXP_SL_S) & \
  150. PAS_MAC_CFG_TXP_SL_M)
  151. #define PAS_MAC_CFG_TXP_COB_M 0x0000f000
  152. #define PAS_MAC_CFG_TXP_COB_S 12
  153. #define PAS_MAC_CFG_TXP_COB(x) (((x) << PAS_MAC_CFG_TXP_COB_S) & \
  154. PAS_MAC_CFG_TXP_COB_M)
  155. #define PAS_MAC_CFG_TXP_TIFT_M 0x00000f00
  156. #define PAS_MAC_CFG_TXP_TIFT_S 8
  157. #define PAS_MAC_CFG_TXP_TIFT(x) (((x) << PAS_MAC_CFG_TXP_TIFT_S) & \
  158. PAS_MAC_CFG_TXP_TIFT_M)
  159. #define PAS_MAC_CFG_TXP_TIFG_M 0x000000ff
  160. #define PAS_MAC_CFG_TXP_TIFG_S 0
  161. #define PAS_MAC_CFG_TXP_TIFG(x) (((x) << PAS_MAC_CFG_TXP_TIFG_S) & \
  162. PAS_MAC_CFG_TXP_TIFG_M)
  163. #define PAS_MAC_RMON(r) (0x100+(r)*4)
  164. #define PAS_MAC_IPC_CHNL_DCHNO_M 0x003f0000
  165. #define PAS_MAC_IPC_CHNL_DCHNO_S 16
  166. #define PAS_MAC_IPC_CHNL_DCHNO(x) (((x) << PAS_MAC_IPC_CHNL_DCHNO_S) & \
  167. PAS_MAC_IPC_CHNL_DCHNO_M)
  168. #define PAS_MAC_IPC_CHNL_BCH_M 0x0000003f
  169. #define PAS_MAC_IPC_CHNL_BCH_S 0
  170. #define PAS_MAC_IPC_CHNL_BCH(x) (((x) << PAS_MAC_IPC_CHNL_BCH_S) & \
  171. PAS_MAC_IPC_CHNL_BCH_M)
  172. #endif /* PASEMI_MAC_H */