tn40.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /* Copyright (c) Tehuti Networks Ltd. */
  3. #ifndef _TN40_H_
  4. #define _TN40_H_
  5. #include <linux/property.h>
  6. #include "tn40_regs.h"
  7. #define TN40_DRV_NAME "tn40xx"
  8. #define PCI_DEVICE_ID_TEHUTI_TN9510 0x4025
  9. #define TN40_MDIO_SPEED_1MHZ (1)
  10. #define TN40_MDIO_SPEED_6MHZ (6)
  11. /* netdev tx queue len for Luxor. The default value is 1000.
  12. * ifconfig eth1 txqueuelen 3000 - to change it at runtime.
  13. */
  14. #define TN40_NDEV_TXQ_LEN 1000
  15. #define TN40_FIFO_SIZE 4096
  16. #define TN40_FIFO_EXTRA_SPACE 1024
  17. #define TN40_TXF_DESC_SZ 16
  18. #define TN40_MAX_TX_LEVEL (priv->txd_fifo0.m.memsz - 16)
  19. #define TN40_MIN_TX_LEVEL 256
  20. #define TN40_NO_UPD_PACKETS 40
  21. #define TN40_MAX_MTU BIT(14)
  22. #define TN40_PCK_TH_MULT 128
  23. #define TN40_INT_COAL_MULT 2
  24. #define TN40_INT_REG_VAL(coal, coal_rc, rxf_th, pck_th) ( \
  25. FIELD_PREP(GENMASK(14, 0), (coal)) | \
  26. FIELD_PREP(BIT(15), (coal_rc)) | \
  27. FIELD_PREP(GENMASK(19, 16), (rxf_th)) | \
  28. FIELD_PREP(GENMASK(31, 20), (pck_th)) \
  29. )
  30. struct tn40_fifo {
  31. dma_addr_t da; /* Physical address of fifo (used by HW) */
  32. char *va; /* Virtual address of fifo (used by SW) */
  33. u32 rptr, wptr;
  34. /* Cached values of RPTR and WPTR registers,
  35. * they're 32 bits on both 32 and 64 archs.
  36. */
  37. u16 reg_cfg0;
  38. u16 reg_cfg1;
  39. u16 reg_rptr;
  40. u16 reg_wptr;
  41. u16 memsz; /* Memory size allocated for fifo */
  42. u16 size_mask;
  43. u16 pktsz; /* Skb packet size to allocate */
  44. u16 rcvno; /* Number of buffers that come from this RXF */
  45. };
  46. struct tn40_txf_fifo {
  47. struct tn40_fifo m; /* The minimal set of variables used by all fifos */
  48. };
  49. struct tn40_txd_fifo {
  50. struct tn40_fifo m; /* The minimal set of variables used by all fifos */
  51. };
  52. struct tn40_rxf_fifo {
  53. struct tn40_fifo m; /* The minimal set of variables used by all fifos */
  54. };
  55. struct tn40_rxd_fifo {
  56. struct tn40_fifo m; /* The minimal set of variables used by all fifos */
  57. };
  58. struct tn40_rx_map {
  59. struct page *page;
  60. };
  61. struct tn40_rxdb {
  62. unsigned int *stack;
  63. struct tn40_rx_map *elems;
  64. unsigned int nelem;
  65. unsigned int top;
  66. };
  67. union tn40_tx_dma_addr {
  68. dma_addr_t dma;
  69. struct sk_buff *skb;
  70. };
  71. /* Entry in the db.
  72. * if len == 0 addr is dma
  73. * if len != 0 addr is skb
  74. */
  75. struct tn40_tx_map {
  76. union tn40_tx_dma_addr addr;
  77. int len;
  78. };
  79. /* tx database - implemented as circular fifo buffer */
  80. struct tn40_txdb {
  81. struct tn40_tx_map *start; /* Points to the first element */
  82. struct tn40_tx_map *end; /* Points just AFTER the last element */
  83. struct tn40_tx_map *rptr; /* Points to the next element to read */
  84. struct tn40_tx_map *wptr; /* Points to the next element to write */
  85. int size; /* Number of elements in the db */
  86. };
  87. #define NODE_PROP(_NAME, _PROP) ( \
  88. (const struct software_node) { \
  89. .name = _NAME, \
  90. .properties = _PROP, \
  91. })
  92. #define NODE_PAR_PROP(_NAME, _PAR, _PROP) ( \
  93. (const struct software_node) { \
  94. .name = _NAME, \
  95. .parent = _PAR, \
  96. .properties = _PROP, \
  97. })
  98. enum tn40_swnodes {
  99. SWNODE_MDIO,
  100. SWNODE_PHY,
  101. SWNODE_MAX
  102. };
  103. struct tn40_nodes {
  104. char phy_name[32];
  105. char mdio_name[32];
  106. struct property_entry phy_props[3];
  107. struct software_node swnodes[SWNODE_MAX];
  108. const struct software_node *group[SWNODE_MAX + 1];
  109. };
  110. struct tn40_priv {
  111. struct net_device *ndev;
  112. struct pci_dev *pdev;
  113. struct tn40_nodes nodes;
  114. struct napi_struct napi;
  115. /* RX FIFOs: 1 for data (full) descs, and 2 for free descs */
  116. struct tn40_rxd_fifo rxd_fifo0;
  117. struct tn40_rxf_fifo rxf_fifo0;
  118. struct tn40_rxdb *rxdb0; /* Rx dbs to store skb pointers */
  119. struct page_pool *page_pool;
  120. /* Tx FIFOs: 1 for data desc, 1 for empty (acks) desc */
  121. struct tn40_txd_fifo txd_fifo0;
  122. struct tn40_txf_fifo txf_fifo0;
  123. struct tn40_txdb txdb;
  124. int tx_level;
  125. int tx_update_mark;
  126. int tx_noupd;
  127. int stats_flag;
  128. struct rtnl_link_stats64 stats;
  129. u64 alloc_fail;
  130. struct u64_stats_sync syncp;
  131. u8 txd_size;
  132. u8 txf_size;
  133. u8 rxd_size;
  134. u8 rxf_size;
  135. u32 rdintcm;
  136. u32 tdintcm;
  137. u32 isr_mask;
  138. void __iomem *regs;
  139. /* SHORT_PKT_FIX */
  140. u32 b0_len;
  141. dma_addr_t b0_dma; /* Physical address of buffer */
  142. char *b0_va; /* Virtual address of buffer */
  143. struct mii_bus *mdio;
  144. struct phy_device *phydev;
  145. struct phylink *phylink;
  146. struct phylink_config phylink_config;
  147. };
  148. /* RX FREE descriptor - 64bit */
  149. struct tn40_rxf_desc {
  150. __le32 info; /* Buffer Count + Info - described below */
  151. __le32 va_lo; /* VAdr[31:0] */
  152. __le32 va_hi; /* VAdr[63:32] */
  153. __le32 pa_lo; /* PAdr[31:0] */
  154. __le32 pa_hi; /* PAdr[63:32] */
  155. __le32 len; /* Buffer Length */
  156. };
  157. #define TN40_GET_RXD_BC(x) FIELD_GET(GENMASK(4, 0), (x))
  158. #define TN40_GET_RXD_ERR(x) FIELD_GET(GENMASK(26, 21), (x))
  159. #define TN40_GET_RXD_PKT_ID(x) FIELD_GET(GENMASK(30, 28), (x))
  160. #define TN40_GET_RXD_VTAG(x) FIELD_GET(BIT(31), (x))
  161. #define TN40_GET_RXD_VLAN_TCI(x) FIELD_GET(GENMASK(15, 0), (x))
  162. struct tn40_rxd_desc {
  163. __le32 rxd_val1;
  164. __le16 len;
  165. __le16 rxd_vlan;
  166. __le32 va_lo;
  167. __le32 va_hi;
  168. __le32 rss_lo;
  169. __le32 rss_hash;
  170. };
  171. #define TN40_MAX_PBL (19)
  172. /* PBL describes each virtual buffer to be transmitted from the host. */
  173. struct tn40_pbl {
  174. __le32 pa_lo;
  175. __le32 pa_hi;
  176. __le32 len;
  177. };
  178. /* First word for TXD descriptor. It means: type = 3 for regular Tx packet,
  179. * hw_csum = 7 for IP+UDP+TCP HW checksums.
  180. */
  181. #define TN40_TXD_W1_VAL(bc, checksum, vtag, lgsnd, vlan_id) ( \
  182. GENMASK(17, 16) | \
  183. FIELD_PREP(GENMASK(4, 0), (bc)) | \
  184. FIELD_PREP(GENMASK(7, 5), (checksum)) | \
  185. FIELD_PREP(BIT(8), (vtag)) | \
  186. FIELD_PREP(GENMASK(12, 9), (lgsnd)) | \
  187. FIELD_PREP(GENMASK(15, 13), \
  188. FIELD_GET(GENMASK(15, 13), (vlan_id))) | \
  189. FIELD_PREP(GENMASK(31, 20), \
  190. FIELD_GET(GENMASK(11, 0), (vlan_id))) \
  191. )
  192. struct tn40_txd_desc {
  193. __le32 txd_val1;
  194. __le16 mss;
  195. __le16 length;
  196. __le32 va_lo;
  197. __le32 va_hi;
  198. struct tn40_pbl pbl[]; /* Fragments */
  199. };
  200. struct tn40_txf_desc {
  201. u32 status;
  202. u32 va_lo; /* VAdr[31:0] */
  203. u32 va_hi; /* VAdr[63:32] */
  204. u32 pad;
  205. };
  206. static inline u32 tn40_read_reg(struct tn40_priv *priv, u32 reg)
  207. {
  208. return readl(priv->regs + reg);
  209. }
  210. static inline void tn40_write_reg(struct tn40_priv *priv, u32 reg, u32 val)
  211. {
  212. writel(val, priv->regs + reg);
  213. }
  214. int tn40_set_link_speed(struct tn40_priv *priv, u32 speed);
  215. void tn40_swnodes_cleanup(struct tn40_priv *priv);
  216. int tn40_mdiobus_init(struct tn40_priv *priv);
  217. int tn40_phy_register(struct tn40_priv *priv);
  218. void tn40_phy_unregister(struct tn40_priv *priv);
  219. #endif /* _TN40XX_H */