1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (c) Tehuti Networks Ltd. */
9 #define TN40_DRV_NAME "tn40xx"
11 #define TN40_MDIO_SPEED_1MHZ (1)
12 #define TN40_MDIO_SPEED_6MHZ (6)
14 /* netdev tx queue len for Luxor. The default value is 1000.
15 * ifconfig eth1 txqueuelen 3000 - to change it at runtime.
17 #define TN40_NDEV_TXQ_LEN 1000
19 #define TN40_FIFO_SIZE 4096
20 #define TN40_FIFO_EXTRA_SPACE 1024
22 #define TN40_TXF_DESC_SZ 16
23 #define TN40_MAX_TX_LEVEL (priv->txd_fifo0.m.memsz - 16)
24 #define TN40_MIN_TX_LEVEL 256
25 #define TN40_NO_UPD_PACKETS 40
26 #define TN40_MAX_MTU BIT(14)
28 #define TN40_PCK_TH_MULT 128
29 #define TN40_INT_COAL_MULT 2
31 #define TN40_INT_REG_VAL(coal, coal_rc, rxf_th, pck_th) ( \
32 FIELD_PREP(GENMASK(14, 0), (coal)) | \
33 FIELD_PREP(BIT(15), (coal_rc)) | \
34 FIELD_PREP(GENMASK(19, 16), (rxf_th)) | \
35 FIELD_PREP(GENMASK(31, 20), (pck_th)) \
39 dma_addr_t da; /* Physical address of fifo (used by HW) */
40 char *va; /* Virtual address of fifo (used by SW) */
42 /* Cached values of RPTR and WPTR registers,
43 * they're 32 bits on both 32 and 64 archs.
49 u16 memsz; /* Memory size allocated for fifo */
51 u16 pktsz; /* Skb packet size to allocate */
52 u16 rcvno; /* Number of buffers that come from this RXF */
55 struct tn40_txf_fifo {
56 struct tn40_fifo m; /* The minimal set of variables used by all fifos */
59 struct tn40_txd_fifo {
60 struct tn40_fifo m; /* The minimal set of variables used by all fifos */
63 struct tn40_rxf_fifo {
64 struct tn40_fifo m; /* The minimal set of variables used by all fifos */
67 struct tn40_rxd_fifo {
68 struct tn40_fifo m; /* The minimal set of variables used by all fifos */
77 struct tn40_rx_map *elems;
82 union tn40_tx_dma_addr {
88 * if len == 0 addr is dma
89 * if len != 0 addr is skb
92 union tn40_tx_dma_addr addr;
96 /* tx database - implemented as circular fifo buffer */
98 struct tn40_tx_map *start; /* Points to the first element */
99 struct tn40_tx_map *end; /* Points just AFTER the last element */
100 struct tn40_tx_map *rptr; /* Points to the next element to read */
101 struct tn40_tx_map *wptr; /* Points to the next element to write */
102 int size; /* Number of elements in the db */
106 struct net_device *ndev;
107 struct pci_dev *pdev;
109 struct napi_struct napi;
110 /* RX FIFOs: 1 for data (full) descs, and 2 for free descs */
111 struct tn40_rxd_fifo rxd_fifo0;
112 struct tn40_rxf_fifo rxf_fifo0;
113 struct tn40_rxdb *rxdb0; /* Rx dbs to store skb pointers */
114 struct page_pool *page_pool;
116 /* Tx FIFOs: 1 for data desc, 1 for empty (acks) desc */
117 struct tn40_txd_fifo txd_fifo0;
118 struct tn40_txf_fifo txf_fifo0;
119 struct tn40_txdb txdb;
125 struct rtnl_link_stats64 stats;
127 struct u64_stats_sync syncp;
142 dma_addr_t b0_dma; /* Physical address of buffer */
143 char *b0_va; /* Virtual address of buffer */
145 struct mii_bus *mdio;
146 struct phy_device *phydev;
147 struct phylink *phylink;
148 struct phylink_config phylink_config;
151 /* RX FREE descriptor - 64bit */
152 struct tn40_rxf_desc {
153 __le32 info; /* Buffer Count + Info - described below */
154 __le32 va_lo; /* VAdr[31:0] */
155 __le32 va_hi; /* VAdr[63:32] */
156 __le32 pa_lo; /* PAdr[31:0] */
157 __le32 pa_hi; /* PAdr[63:32] */
158 __le32 len; /* Buffer Length */
161 #define TN40_GET_RXD_BC(x) FIELD_GET(GENMASK(4, 0), (x))
162 #define TN40_GET_RXD_ERR(x) FIELD_GET(GENMASK(26, 21), (x))
163 #define TN40_GET_RXD_PKT_ID(x) FIELD_GET(GENMASK(30, 28), (x))
164 #define TN40_GET_RXD_VTAG(x) FIELD_GET(BIT(31), (x))
165 #define TN40_GET_RXD_VLAN_TCI(x) FIELD_GET(GENMASK(15, 0), (x))
167 struct tn40_rxd_desc {
177 #define TN40_MAX_PBL (19)
178 /* PBL describes each virtual buffer to be transmitted from the host. */
185 /* First word for TXD descriptor. It means: type = 3 for regular Tx packet,
186 * hw_csum = 7 for IP+UDP+TCP HW checksums.
188 #define TN40_TXD_W1_VAL(bc, checksum, vtag, lgsnd, vlan_id) ( \
190 FIELD_PREP(GENMASK(4, 0), (bc)) | \
191 FIELD_PREP(GENMASK(7, 5), (checksum)) | \
192 FIELD_PREP(BIT(8), (vtag)) | \
193 FIELD_PREP(GENMASK(12, 9), (lgsnd)) | \
194 FIELD_PREP(GENMASK(15, 13), \
195 FIELD_GET(GENMASK(15, 13), (vlan_id))) | \
196 FIELD_PREP(GENMASK(31, 20), \
197 FIELD_GET(GENMASK(11, 0), (vlan_id))) \
200 struct tn40_txd_desc {
206 struct tn40_pbl pbl[]; /* Fragments */
209 struct tn40_txf_desc {
211 u32 va_lo; /* VAdr[31:0] */
212 u32 va_hi; /* VAdr[63:32] */
216 static inline u32 tn40_read_reg(struct tn40_priv *priv, u32 reg)
218 return readl(priv->regs + reg);
221 static inline void tn40_write_reg(struct tn40_priv *priv, u32 reg, u32 val)
223 writel(val, priv->regs + reg);
226 int tn40_set_link_speed(struct tn40_priv *priv, u32 speed);
228 int tn40_mdiobus_init(struct tn40_priv *priv);
230 int tn40_phy_register(struct tn40_priv *priv);
231 void tn40_phy_unregister(struct tn40_priv *priv);
233 #endif /* _TN40XX_H */