1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Fri, 20 May 2022 20:11:36 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: introduce MTK_NETSYS_V2 support
5 Introduce MTK_NETSYS_V2 support. MTK_NETSYS_V2 defines 32B TX/RX DMA
7 This is a preliminary patch to add mt7986 ethernet support.
9 Tested-by: Sam Shih <sam.shih@mediatek.com>
10 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
14 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
15 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
16 @@ -863,8 +863,8 @@ static inline int mtk_max_buf_size(int f
20 -static inline bool mtk_rx_get_desc(struct mtk_rx_dma *rxd,
21 - struct mtk_rx_dma *dma_rxd)
22 +static bool mtk_rx_get_desc(struct mtk_eth *eth, struct mtk_rx_dma_v2 *rxd,
23 + struct mtk_rx_dma_v2 *dma_rxd)
25 rxd->rxd2 = READ_ONCE(dma_rxd->rxd2);
26 if (!(rxd->rxd2 & RX_DMA_DONE))
27 @@ -873,6 +873,10 @@ static inline bool mtk_rx_get_desc(struc
28 rxd->rxd1 = READ_ONCE(dma_rxd->rxd1);
29 rxd->rxd3 = READ_ONCE(dma_rxd->rxd3);
30 rxd->rxd4 = READ_ONCE(dma_rxd->rxd4);
31 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
32 + rxd->rxd5 = READ_ONCE(dma_rxd->rxd5);
33 + rxd->rxd6 = READ_ONCE(dma_rxd->rxd6);
38 @@ -917,7 +921,7 @@ static int mtk_init_fq_dma(struct mtk_et
39 phy_ring_tail = eth->phy_scratch_ring + soc->txrx.txd_size * (cnt - 1);
41 for (i = 0; i < cnt; i++) {
42 - struct mtk_tx_dma *txd;
43 + struct mtk_tx_dma_v2 *txd;
45 txd = (void *)eth->scratch_ring + i * soc->txrx.txd_size;
46 txd->txd1 = dma_addr + i * MTK_QDMA_PAGE_SIZE;
47 @@ -927,6 +931,12 @@ static int mtk_init_fq_dma(struct mtk_et
49 txd->txd3 = TX_DMA_PLEN0(MTK_QDMA_PAGE_SIZE);
51 + if (MTK_HAS_CAPS(soc->caps, MTK_NETSYS_V2)) {
59 mtk_w32(eth, eth->phy_scratch_ring, soc->reg_map->qdma.fq_head);
60 @@ -1030,10 +1040,12 @@ static void setup_tx_buf(struct mtk_eth
64 -static void mtk_tx_set_dma_desc(struct net_device *dev, struct mtk_tx_dma *desc,
65 - struct mtk_tx_dma_desc_info *info)
66 +static void mtk_tx_set_dma_desc_v1(struct net_device *dev, void *txd,
67 + struct mtk_tx_dma_desc_info *info)
69 struct mtk_mac *mac = netdev_priv(dev);
70 + struct mtk_eth *eth = mac->hw;
71 + struct mtk_tx_dma *desc = txd;
74 WRITE_ONCE(desc->txd1, info->addr);
75 @@ -1057,6 +1069,59 @@ static void mtk_tx_set_dma_desc(struct n
76 WRITE_ONCE(desc->txd4, data);
79 +static void mtk_tx_set_dma_desc_v2(struct net_device *dev, void *txd,
80 + struct mtk_tx_dma_desc_info *info)
82 + struct mtk_mac *mac = netdev_priv(dev);
83 + struct mtk_tx_dma_v2 *desc = txd;
84 + struct mtk_eth *eth = mac->hw;
87 + WRITE_ONCE(desc->txd1, info->addr);
89 + data = TX_DMA_PLEN0(info->size);
92 + WRITE_ONCE(desc->txd3, data);
94 + if (!info->qid && mac->id)
95 + info->qid = MTK_QDMA_GMAC2_QID;
97 + data = (mac->id + 1) << TX_DMA_FPORT_SHIFT_V2; /* forward port */
98 + data |= TX_DMA_SWC_V2 | QID_BITS_V2(info->qid);
99 + WRITE_ONCE(desc->txd4, data);
104 + data |= TX_DMA_TSO_V2;
105 + /* tx checksum offload */
107 + data |= TX_DMA_CHKSUM_V2;
109 + WRITE_ONCE(desc->txd5, data);
112 + if (info->first && info->vlan)
113 + data |= TX_DMA_INS_VLAN_V2 | info->vlan_tci;
114 + WRITE_ONCE(desc->txd6, data);
116 + WRITE_ONCE(desc->txd7, 0);
117 + WRITE_ONCE(desc->txd8, 0);
120 +static void mtk_tx_set_dma_desc(struct net_device *dev, void *txd,
121 + struct mtk_tx_dma_desc_info *info)
123 + struct mtk_mac *mac = netdev_priv(dev);
124 + struct mtk_eth *eth = mac->hw;
126 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
127 + mtk_tx_set_dma_desc_v2(dev, txd, info);
129 + mtk_tx_set_dma_desc_v1(dev, txd, info);
132 static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
133 int tx_num, struct mtk_tx_ring *ring, bool gso)
135 @@ -1065,6 +1130,7 @@ static int mtk_tx_map(struct sk_buff *sk
137 .csum = skb->ip_summed == CHECKSUM_PARTIAL,
138 .vlan = skb_vlan_tag_present(skb),
139 + .qid = skb->mark & MTK_QDMA_TX_MASK,
140 .vlan_tci = skb_vlan_tag_get(skb),
142 .last = !skb_is_nonlinear(skb),
143 @@ -1124,7 +1190,9 @@ static int mtk_tx_map(struct sk_buff *sk
146 memset(&txd_info, 0, sizeof(struct mtk_tx_dma_desc_info));
147 - txd_info.size = min(frag_size, MTK_TX_DMA_BUF_LEN);
148 + txd_info.size = min_t(unsigned int, frag_size,
149 + soc->txrx.dma_max_len);
150 + txd_info.qid = skb->mark & MTK_QDMA_TX_MASK;
151 txd_info.last = i == skb_shinfo(skb)->nr_frags - 1 &&
152 !(frag_size - txd_info.size);
153 txd_info.addr = skb_frag_dma_map(eth->dma_dev, frag,
154 @@ -1205,17 +1273,16 @@ err_dma:
158 -static inline int mtk_cal_txd_req(struct sk_buff *skb)
159 +static int mtk_cal_txd_req(struct mtk_eth *eth, struct sk_buff *skb)
166 if (skb_is_gso(skb)) {
167 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
168 frag = &skb_shinfo(skb)->frags[i];
169 nfrags += DIV_ROUND_UP(skb_frag_size(frag),
170 - MTK_TX_DMA_BUF_LEN);
171 + eth->soc->txrx.dma_max_len);
174 nfrags += skb_shinfo(skb)->nr_frags;
175 @@ -1267,7 +1334,7 @@ static netdev_tx_t mtk_start_xmit(struct
176 if (unlikely(test_bit(MTK_RESETTING, ð->state)))
179 - tx_num = mtk_cal_txd_req(skb);
180 + tx_num = mtk_cal_txd_req(eth, skb);
181 if (unlikely(atomic_read(&ring->free_count) <= tx_num)) {
182 netif_stop_queue(dev);
183 netif_err(eth, tx_queued, dev,
184 @@ -1359,7 +1426,7 @@ static int mtk_poll_rx(struct napi_struc
188 - struct mtk_rx_dma *rxd, trxd;
189 + struct mtk_rx_dma_v2 *rxd, trxd;
190 int done = 0, bytes = 0;
192 while (done < budget) {
193 @@ -1367,7 +1434,7 @@ static int mtk_poll_rx(struct napi_struc
200 ring = mtk_get_rx_ring(eth);
202 @@ -1377,16 +1444,15 @@ static int mtk_poll_rx(struct napi_struc
203 rxd = (void *)ring->dma + idx * eth->soc->txrx.rxd_size;
204 data = ring->data[idx];
206 - if (!mtk_rx_get_desc(&trxd, rxd))
207 + if (!mtk_rx_get_desc(eth, &trxd, rxd))
210 /* find out which mac the packet come from. values start at 1 */
211 - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628) ||
212 - (trxd.rxd4 & RX_DMA_SPECIAL_TAG))
215 - mac = ((trxd.rxd4 >> RX_DMA_FPORT_SHIFT) &
216 - RX_DMA_FPORT_MASK) - 1;
217 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
218 + mac = RX_DMA_GET_SPORT_V2(trxd.rxd5) - 1;
219 + else if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628) &&
220 + !(trxd.rxd4 & RX_DMA_SPECIAL_TAG))
221 + mac = RX_DMA_GET_SPORT(trxd.rxd4) - 1;
223 if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
225 @@ -1432,7 +1498,7 @@ static int mtk_poll_rx(struct napi_struc
226 pktlen = RX_DMA_GET_PLEN0(trxd.rxd2);
228 skb_put(skb, pktlen);
229 - if (trxd.rxd4 & eth->rx_dma_l4_valid)
230 + if (trxd.rxd4 & eth->soc->txrx.rx_dma_l4_valid)
231 skb->ip_summed = CHECKSUM_UNNECESSARY;
233 skb_checksum_none_assert(skb);
234 @@ -1450,10 +1516,25 @@ static int mtk_poll_rx(struct napi_struc
235 mtk_ppe_check_skb(eth->ppe, skb,
236 trxd.rxd4 & MTK_RXD4_FOE_ENTRY);
238 - if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX &&
239 - (trxd.rxd2 & RX_DMA_VTAG))
240 - __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
241 - RX_DMA_VID(trxd.rxd3));
242 + if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
243 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
244 + if (trxd.rxd3 & RX_DMA_VTAG_V2)
245 + __vlan_hwaccel_put_tag(skb,
246 + htons(RX_DMA_VPID(trxd.rxd4)),
247 + RX_DMA_VID(trxd.rxd4));
248 + } else if (trxd.rxd2 & RX_DMA_VTAG) {
249 + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
250 + RX_DMA_VID(trxd.rxd3));
253 + /* If the device is attached to a dsa switch, the special
254 + * tag inserted in VLAN field by hw switch can * be offloaded
255 + * by RX HW VLAN offload. Clear vlan info.
257 + if (netdev_uses_dsa(netdev))
258 + __vlan_hwaccel_clear_tag(skb);
261 skb_record_rx_queue(skb, 0);
262 napi_gro_receive(napi, skb);
264 @@ -1465,7 +1546,7 @@ release_desc:
265 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
266 rxd->rxd2 = RX_DMA_LSO;
268 - rxd->rxd2 = RX_DMA_PLEN0(ring->buf_size);
269 + rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size);
271 ring->calc_idx = idx;
273 @@ -1667,7 +1748,8 @@ static int mtk_napi_rx(struct napi_struc
277 - mtk_w32(eth, MTK_RX_DONE_INT, reg_map->pdma.irq_status);
278 + mtk_w32(eth, eth->soc->txrx.rx_irq_done_mask,
279 + reg_map->pdma.irq_status);
280 rx_done = mtk_poll_rx(napi, budget - rx_done_total, eth);
281 rx_done_total += rx_done;
283 @@ -1681,10 +1763,11 @@ static int mtk_napi_rx(struct napi_struc
284 if (rx_done_total == budget)
287 - } while (mtk_r32(eth, reg_map->pdma.irq_status) & MTK_RX_DONE_INT);
288 + } while (mtk_r32(eth, reg_map->pdma.irq_status) &
289 + eth->soc->txrx.rx_irq_done_mask);
291 if (napi_complete_done(napi, rx_done_total))
292 - mtk_rx_irq_enable(eth, MTK_RX_DONE_INT);
293 + mtk_rx_irq_enable(eth, eth->soc->txrx.rx_irq_done_mask);
295 return rx_done_total;
297 @@ -1694,7 +1777,7 @@ static int mtk_tx_alloc(struct mtk_eth *
298 const struct mtk_soc_data *soc = eth->soc;
299 struct mtk_tx_ring *ring = ð->tx_ring;
300 int i, sz = soc->txrx.txd_size;
301 - struct mtk_tx_dma *txd;
302 + struct mtk_tx_dma_v2 *txd;
304 ring->buf = kcalloc(MTK_DMA_SIZE, sizeof(*ring->buf),
306 @@ -1714,13 +1797,19 @@ static int mtk_tx_alloc(struct mtk_eth *
307 txd->txd2 = next_ptr;
308 txd->txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
310 + if (MTK_HAS_CAPS(soc->caps, MTK_NETSYS_V2)) {
318 /* On MT7688 (PDMA only) this driver uses the ring->dma structs
319 * only as the framework. The real HW descriptors are the PDMA
320 * descriptors in ring->dma_pdma.
322 - if (!MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA)) {
323 + if (!MTK_HAS_CAPS(soc->caps, MTK_QDMA)) {
324 ring->dma_pdma = dma_alloc_coherent(eth->dma_dev, MTK_DMA_SIZE * sz,
325 &ring->phys_pdma, GFP_KERNEL);
327 @@ -1800,13 +1889,11 @@ static int mtk_rx_alloc(struct mtk_eth *
328 struct mtk_rx_ring *ring;
329 int rx_data_len, rx_dma_size;
333 if (rx_flag == MTK_RX_FLAGS_QDMA) {
336 ring = ð->rx_ring_qdma;
339 ring = ð->rx_ring[ring_no];
341 @@ -1842,7 +1929,7 @@ static int mtk_rx_alloc(struct mtk_eth *
344 for (i = 0; i < rx_dma_size; i++) {
345 - struct mtk_rx_dma *rxd;
346 + struct mtk_rx_dma_v2 *rxd;
348 dma_addr_t dma_addr = dma_map_single(eth->dma_dev,
349 ring->data[i] + NET_SKB_PAD + eth->ip_align,
350 @@ -1857,26 +1944,47 @@ static int mtk_rx_alloc(struct mtk_eth *
351 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
352 rxd->rxd2 = RX_DMA_LSO;
354 - rxd->rxd2 = RX_DMA_PLEN0(ring->buf_size);
355 + rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size);
359 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
366 ring->dma_size = rx_dma_size;
367 ring->calc_idx_update = false;
368 ring->calc_idx = rx_dma_size - 1;
369 - ring->crx_idx_reg = reg_map->pdma.pcrx_ptr + ring_no * MTK_QRX_OFFSET;
370 + if (rx_flag == MTK_RX_FLAGS_QDMA)
371 + ring->crx_idx_reg = reg_map->qdma.qcrx_ptr +
372 + ring_no * MTK_QRX_OFFSET;
374 + ring->crx_idx_reg = reg_map->pdma.pcrx_ptr +
375 + ring_no * MTK_QRX_OFFSET;
376 /* make sure that all changes to the dma ring are flushed before we
381 - mtk_w32(eth, ring->phys,
382 - reg_map->pdma.rx_ptr + ring_no * MTK_QRX_OFFSET + offset);
383 - mtk_w32(eth, rx_dma_size,
384 - reg_map->pdma.rx_cnt_cfg + ring_no * MTK_QRX_OFFSET + offset);
385 - mtk_w32(eth, ring->calc_idx, ring->crx_idx_reg + offset);
386 - mtk_w32(eth, MTK_PST_DRX_IDX_CFG(ring_no), reg_map->pdma.rst_idx + offset);
387 + if (rx_flag == MTK_RX_FLAGS_QDMA) {
388 + mtk_w32(eth, ring->phys,
389 + reg_map->qdma.rx_ptr + ring_no * MTK_QRX_OFFSET);
390 + mtk_w32(eth, rx_dma_size,
391 + reg_map->qdma.rx_cnt_cfg + ring_no * MTK_QRX_OFFSET);
392 + mtk_w32(eth, MTK_PST_DRX_IDX_CFG(ring_no),
393 + reg_map->qdma.rst_idx);
395 + mtk_w32(eth, ring->phys,
396 + reg_map->pdma.rx_ptr + ring_no * MTK_QRX_OFFSET);
397 + mtk_w32(eth, rx_dma_size,
398 + reg_map->pdma.rx_cnt_cfg + ring_no * MTK_QRX_OFFSET);
399 + mtk_w32(eth, MTK_PST_DRX_IDX_CFG(ring_no),
400 + reg_map->pdma.rst_idx);
402 + mtk_w32(eth, ring->calc_idx, ring->crx_idx_reg);
406 @@ -2298,7 +2406,7 @@ static irqreturn_t mtk_handle_irq_rx(int
408 if (likely(napi_schedule_prep(ð->rx_napi))) {
409 __napi_schedule(ð->rx_napi);
410 - mtk_rx_irq_disable(eth, MTK_RX_DONE_INT);
411 + mtk_rx_irq_disable(eth, eth->soc->txrx.rx_irq_done_mask);
415 @@ -2322,8 +2430,10 @@ static irqreturn_t mtk_handle_irq(int ir
416 struct mtk_eth *eth = _eth;
417 const struct mtk_reg_map *reg_map = eth->soc->reg_map;
419 - if (mtk_r32(eth, reg_map->pdma.irq_mask) & MTK_RX_DONE_INT) {
420 - if (mtk_r32(eth, reg_map->pdma.irq_status) & MTK_RX_DONE_INT)
421 + if (mtk_r32(eth, reg_map->pdma.irq_mask) &
422 + eth->soc->txrx.rx_irq_done_mask) {
423 + if (mtk_r32(eth, reg_map->pdma.irq_status) &
424 + eth->soc->txrx.rx_irq_done_mask)
425 mtk_handle_irq_rx(irq, _eth);
427 if (mtk_r32(eth, reg_map->tx_irq_mask) & MTK_TX_DONE_INT) {
428 @@ -2341,16 +2451,16 @@ static void mtk_poll_controller(struct n
429 struct mtk_eth *eth = mac->hw;
431 mtk_tx_irq_disable(eth, MTK_TX_DONE_INT);
432 - mtk_rx_irq_disable(eth, MTK_RX_DONE_INT);
433 + mtk_rx_irq_disable(eth, eth->soc->txrx.rx_irq_done_mask);
434 mtk_handle_irq_rx(eth->irq[2], dev);
435 mtk_tx_irq_enable(eth, MTK_TX_DONE_INT);
436 - mtk_rx_irq_enable(eth, MTK_RX_DONE_INT);
437 + mtk_rx_irq_enable(eth, eth->soc->txrx.rx_irq_done_mask);
441 static int mtk_start_dma(struct mtk_eth *eth)
443 - u32 rx_2b_offset = (NET_IP_ALIGN == 2) ? MTK_RX_2B_OFFSET : 0;
444 + u32 val, rx_2b_offset = (NET_IP_ALIGN == 2) ? MTK_RX_2B_OFFSET : 0;
445 const struct mtk_reg_map *reg_map = eth->soc->reg_map;
448 @@ -2361,12 +2471,19 @@ static int mtk_start_dma(struct mtk_eth
451 if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA)) {
453 - MTK_TX_WB_DDONE | MTK_TX_DMA_EN |
454 - MTK_TX_BT_32DWORDS | MTK_NDP_CO_PRO |
455 - MTK_RX_DMA_EN | MTK_RX_2B_OFFSET |
456 - MTK_RX_BT_32DWORDS,
457 - reg_map->qdma.glo_cfg);
458 + val = mtk_r32(eth, reg_map->qdma.glo_cfg);
459 + val |= MTK_TX_DMA_EN | MTK_RX_DMA_EN |
460 + MTK_TX_BT_32DWORDS | MTK_NDP_CO_PRO |
461 + MTK_RX_2B_OFFSET | MTK_TX_WB_DDONE;
463 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
464 + val |= MTK_MUTLI_CNT | MTK_RESV_BUF |
465 + MTK_WCOMP_EN | MTK_DMAD_WR_WDONE |
468 + val |= MTK_RX_BT_32DWORDS;
469 + mtk_w32(eth, val, reg_map->qdma.glo_cfg);
472 MTK_RX_DMA_EN | rx_2b_offset |
473 MTK_RX_BT_32DWORDS | MTK_MULTI_EN,
474 @@ -2440,7 +2557,7 @@ static int mtk_open(struct net_device *d
475 napi_enable(ð->tx_napi);
476 napi_enable(ð->rx_napi);
477 mtk_tx_irq_enable(eth, MTK_TX_DONE_INT);
478 - mtk_rx_irq_enable(eth, MTK_RX_DONE_INT);
479 + mtk_rx_irq_enable(eth, eth->soc->txrx.rx_irq_done_mask);
480 refcount_set(ð->dma_refcnt, 1);
483 @@ -2492,7 +2609,7 @@ static int mtk_stop(struct net_device *d
484 mtk_gdm_config(eth, MTK_GDMA_DROP_ALL);
486 mtk_tx_irq_disable(eth, MTK_TX_DONE_INT);
487 - mtk_rx_irq_disable(eth, MTK_RX_DONE_INT);
488 + mtk_rx_irq_disable(eth, eth->soc->txrx.rx_irq_done_mask);
489 napi_disable(ð->tx_napi);
490 napi_disable(ð->rx_napi);
492 @@ -2652,9 +2769,25 @@ static int mtk_hw_init(struct mtk_eth *e
496 - /* Non-MT7628 handling... */
497 - ethsys_reset(eth, RSTCTRL_FE);
498 - ethsys_reset(eth, RSTCTRL_PPE);
499 + val = RSTCTRL_FE | RSTCTRL_PPE;
500 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
501 + regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN, 0);
503 + val |= RSTCTRL_ETH;
504 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
505 + val |= RSTCTRL_PPE1;
508 + ethsys_reset(eth, val);
510 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
511 + regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN,
514 + /* Set FE to PDMAv2 if necessary */
515 + val = mtk_r32(eth, MTK_FE_GLO_MISC);
516 + mtk_w32(eth, val | BIT(4), MTK_FE_GLO_MISC);
520 /* Set GE2 driving and slew rate */
521 @@ -2693,11 +2826,47 @@ static int mtk_hw_init(struct mtk_eth *e
523 /* FE int grouping */
524 mtk_w32(eth, MTK_TX_DONE_INT, reg_map->pdma.int_grp);
525 - mtk_w32(eth, MTK_RX_DONE_INT, reg_map->pdma.int_grp + 4);
526 + mtk_w32(eth, eth->soc->txrx.rx_irq_done_mask, reg_map->pdma.int_grp + 4);
527 mtk_w32(eth, MTK_TX_DONE_INT, reg_map->qdma.int_grp);
528 - mtk_w32(eth, MTK_RX_DONE_INT, reg_map->qdma.int_grp + 4);
529 + mtk_w32(eth, eth->soc->txrx.rx_irq_done_mask, reg_map->qdma.int_grp + 4);
530 mtk_w32(eth, 0x21021000, MTK_FE_INT_GRP);
532 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
533 + /* PSE should not drop port8 and port9 packets */
534 + mtk_w32(eth, 0x00000300, PSE_DROP_CFG);
536 + /* PSE Free Queue Flow Control */
537 + mtk_w32(eth, 0x01fa01f4, PSE_FQFC_CFG2);
539 + /* PSE config input queue threshold */
540 + mtk_w32(eth, 0x001a000e, PSE_IQ_REV(1));
541 + mtk_w32(eth, 0x01ff001a, PSE_IQ_REV(2));
542 + mtk_w32(eth, 0x000e01ff, PSE_IQ_REV(3));
543 + mtk_w32(eth, 0x000e000e, PSE_IQ_REV(4));
544 + mtk_w32(eth, 0x000e000e, PSE_IQ_REV(5));
545 + mtk_w32(eth, 0x000e000e, PSE_IQ_REV(6));
546 + mtk_w32(eth, 0x000e000e, PSE_IQ_REV(7));
547 + mtk_w32(eth, 0x000e000e, PSE_IQ_REV(8));
549 + /* PSE config output queue threshold */
550 + mtk_w32(eth, 0x000f000a, PSE_OQ_TH(1));
551 + mtk_w32(eth, 0x001a000f, PSE_OQ_TH(2));
552 + mtk_w32(eth, 0x000f001a, PSE_OQ_TH(3));
553 + mtk_w32(eth, 0x01ff000f, PSE_OQ_TH(4));
554 + mtk_w32(eth, 0x000f000f, PSE_OQ_TH(5));
555 + mtk_w32(eth, 0x0006000f, PSE_OQ_TH(6));
556 + mtk_w32(eth, 0x00060006, PSE_OQ_TH(7));
557 + mtk_w32(eth, 0x00060006, PSE_OQ_TH(8));
559 + /* GDM and CDM Threshold */
560 + mtk_w32(eth, 0x00000004, MTK_GDM2_THRES);
561 + mtk_w32(eth, 0x00000004, MTK_CDMW0_THRES);
562 + mtk_w32(eth, 0x00000004, MTK_CDMW1_THRES);
563 + mtk_w32(eth, 0x00000004, MTK_CDME0_THRES);
564 + mtk_w32(eth, 0x00000004, MTK_CDME1_THRES);
565 + mtk_w32(eth, 0x00000004, MTK_CDMM_THRES);
571 @@ -3227,12 +3396,8 @@ static int mtk_probe(struct platform_dev
572 if (IS_ERR(eth->base))
573 return PTR_ERR(eth->base);
575 - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) {
576 - eth->rx_dma_l4_valid = RX_DMA_L4_VALID_PDMA;
577 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
578 eth->ip_align = NET_IP_ALIGN;
580 - eth->rx_dma_l4_valid = RX_DMA_L4_VALID;
583 spin_lock_init(ð->page_lock);
584 spin_lock_init(ð->tx_irq_lock);
585 @@ -3468,6 +3633,10 @@ static const struct mtk_soc_data mt2701_
587 .txd_size = sizeof(struct mtk_tx_dma),
588 .rxd_size = sizeof(struct mtk_rx_dma),
589 + .rx_irq_done_mask = MTK_RX_DONE_INT,
590 + .rx_dma_l4_valid = RX_DMA_L4_VALID,
591 + .dma_max_len = MTK_TX_DMA_BUF_LEN,
592 + .dma_len_offset = 16,
596 @@ -3481,6 +3650,10 @@ static const struct mtk_soc_data mt7621_
598 .txd_size = sizeof(struct mtk_tx_dma),
599 .rxd_size = sizeof(struct mtk_rx_dma),
600 + .rx_irq_done_mask = MTK_RX_DONE_INT,
601 + .rx_dma_l4_valid = RX_DMA_L4_VALID,
602 + .dma_max_len = MTK_TX_DMA_BUF_LEN,
603 + .dma_len_offset = 16,
607 @@ -3495,6 +3668,10 @@ static const struct mtk_soc_data mt7622_
609 .txd_size = sizeof(struct mtk_tx_dma),
610 .rxd_size = sizeof(struct mtk_rx_dma),
611 + .rx_irq_done_mask = MTK_RX_DONE_INT,
612 + .rx_dma_l4_valid = RX_DMA_L4_VALID,
613 + .dma_max_len = MTK_TX_DMA_BUF_LEN,
614 + .dma_len_offset = 16,
618 @@ -3508,6 +3685,10 @@ static const struct mtk_soc_data mt7623_
620 .txd_size = sizeof(struct mtk_tx_dma),
621 .rxd_size = sizeof(struct mtk_rx_dma),
622 + .rx_irq_done_mask = MTK_RX_DONE_INT,
623 + .rx_dma_l4_valid = RX_DMA_L4_VALID,
624 + .dma_max_len = MTK_TX_DMA_BUF_LEN,
625 + .dma_len_offset = 16,
629 @@ -3521,6 +3702,10 @@ static const struct mtk_soc_data mt7629_
631 .txd_size = sizeof(struct mtk_tx_dma),
632 .rxd_size = sizeof(struct mtk_rx_dma),
633 + .rx_irq_done_mask = MTK_RX_DONE_INT,
634 + .rx_dma_l4_valid = RX_DMA_L4_VALID,
635 + .dma_max_len = MTK_TX_DMA_BUF_LEN,
636 + .dma_len_offset = 16,
640 @@ -3533,6 +3718,10 @@ static const struct mtk_soc_data rt5350_
642 .txd_size = sizeof(struct mtk_tx_dma),
643 .rxd_size = sizeof(struct mtk_rx_dma),
644 + .rx_irq_done_mask = MTK_RX_DONE_INT,
645 + .rx_dma_l4_valid = RX_DMA_L4_VALID_PDMA,
646 + .dma_max_len = MTK_TX_DMA_BUF_LEN,
647 + .dma_len_offset = 16,
651 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
652 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
654 #define MTK_MAX_RX_LENGTH 1536
655 #define MTK_MAX_RX_LENGTH_2K 2048
656 #define MTK_TX_DMA_BUF_LEN 0x3fff
657 +#define MTK_TX_DMA_BUF_LEN_V2 0xffff
658 #define MTK_DMA_SIZE 512
659 #define MTK_NAPI_WEIGHT 64
660 #define MTK_MAC_COUNT 2
662 #define MTK_CDMQ_IG_CTRL 0x1400
663 #define MTK_CDMQ_STAG_EN BIT(0)
665 +/* CDMP Ingress Control Register */
666 +#define MTK_CDMP_IG_CTRL 0x400
667 +#define MTK_CDMP_STAG_EN BIT(0)
669 /* CDMP Exgress Control Register */
670 #define MTK_CDMP_EG_CTRL 0x404
672 @@ -102,13 +107,38 @@
673 /* Unicast Filter MAC Address Register - High */
674 #define MTK_GDMA_MAC_ADRH(x) (0x50C + (x * 0x1000))
676 +/* FE global misc reg*/
677 +#define MTK_FE_GLO_MISC 0x124
679 +/* PSE Free Queue Flow Control */
680 +#define PSE_FQFC_CFG1 0x100
681 +#define PSE_FQFC_CFG2 0x104
682 +#define PSE_DROP_CFG 0x108
684 +/* PSE Input Queue Reservation Register*/
685 +#define PSE_IQ_REV(x) (0x140 + (((x) - 1) << 2))
687 +/* PSE Output Queue Threshold Register*/
688 +#define PSE_OQ_TH(x) (0x160 + (((x) - 1) << 2))
690 +/* GDM and CDM Threshold */
691 +#define MTK_GDM2_THRES 0x1530
692 +#define MTK_CDMW0_THRES 0x164c
693 +#define MTK_CDMW1_THRES 0x1650
694 +#define MTK_CDME0_THRES 0x1654
695 +#define MTK_CDME1_THRES 0x1658
696 +#define MTK_CDMM_THRES 0x165c
698 /* PDMA HW LRO Control Registers */
699 #define MTK_PDMA_LRO_CTRL_DW0 0x980
700 #define MTK_LRO_EN BIT(0)
701 #define MTK_L3_CKS_UPD_EN BIT(7)
702 +#define MTK_L3_CKS_UPD_EN_V2 BIT(19)
703 #define MTK_LRO_ALT_PKT_CNT_MODE BIT(21)
704 #define MTK_LRO_RING_RELINQUISH_REQ (0x7 << 26)
705 +#define MTK_LRO_RING_RELINQUISH_REQ_V2 (0xf << 24)
706 #define MTK_LRO_RING_RELINQUISH_DONE (0x7 << 29)
707 +#define MTK_LRO_RING_RELINQUISH_DONE_V2 (0xf << 28)
709 #define MTK_PDMA_LRO_CTRL_DW1 0x984
710 #define MTK_PDMA_LRO_CTRL_DW2 0x988
712 #define MTK_TX_DMA_EN BIT(0)
713 #define MTK_DMA_BUSY_TIMEOUT_US 1000000
715 +/* QDMA V2 Global Configuration Register */
716 +#define MTK_CHK_DDONE_EN BIT(28)
717 +#define MTK_DMAD_WR_WDONE BIT(26)
718 +#define MTK_WCOMP_EN BIT(24)
719 +#define MTK_RESV_BUF (0x40 << 16)
720 +#define MTK_MUTLI_CNT (0x4 << 12)
722 /* QDMA Flow Control Register */
723 #define FC_THRES_DROP_MODE BIT(20)
724 #define FC_THRES_DROP_EN (7 << 16)
725 @@ -199,11 +236,32 @@
726 #define MTK_RX_DONE_INT MTK_RX_DONE_DLY
727 #define MTK_TX_DONE_INT MTK_TX_DONE_DLY
729 +#define MTK_RX_DONE_INT_V2 BIT(14)
731 /* QDMA Interrupt grouping registers */
732 #define MTK_RLS_DONE_INT BIT(0)
734 #define MTK_STAT_OFFSET 0x40
737 +#define MTK_QDMA_TX_NUM 16
738 +#define MTK_QDMA_TX_MASK (MTK_QDMA_TX_NUM - 1)
739 +#define QID_BITS_V2(x) (((x) & 0x3f) << 16)
740 +#define MTK_QDMA_GMAC2_QID 8
742 +#define MTK_TX_DMA_BUF_SHIFT 8
744 +/* QDMA V2 descriptor txd6 */
745 +#define TX_DMA_INS_VLAN_V2 BIT(16)
746 +/* QDMA V2 descriptor txd5 */
747 +#define TX_DMA_CHKSUM_V2 (0x7 << 28)
748 +#define TX_DMA_TSO_V2 BIT(31)
750 +/* QDMA V2 descriptor txd4 */
751 +#define TX_DMA_FPORT_SHIFT_V2 8
752 +#define TX_DMA_FPORT_MASK_V2 0xf
753 +#define TX_DMA_SWC_V2 BIT(30)
755 #define MTK_WDMA0_BASE 0x2800
756 #define MTK_WDMA1_BASE 0x2c00
759 /* QDMA descriptor txd3 */
760 #define TX_DMA_OWNER_CPU BIT(31)
761 #define TX_DMA_LS0 BIT(30)
762 -#define TX_DMA_PLEN0(_x) (((_x) & MTK_TX_DMA_BUF_LEN) << 16)
763 -#define TX_DMA_PLEN1(_x) ((_x) & MTK_TX_DMA_BUF_LEN)
764 +#define TX_DMA_PLEN0(x) (((x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
765 +#define TX_DMA_PLEN1(x) ((x) & eth->soc->txrx.dma_max_len)
766 #define TX_DMA_SWC BIT(14)
767 -#define TX_DMA_SDL(_x) (((_x) & 0x3fff) << 16)
770 #define TX_DMA_DONE BIT(31)
771 @@ -230,12 +287,14 @@
772 /* QDMA descriptor rxd2 */
773 #define RX_DMA_DONE BIT(31)
774 #define RX_DMA_LSO BIT(30)
775 -#define RX_DMA_PLEN0(_x) (((_x) & 0x3fff) << 16)
776 -#define RX_DMA_GET_PLEN0(_x) (((_x) >> 16) & 0x3fff)
777 +#define RX_DMA_PREP_PLEN0(x) (((x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
778 +#define RX_DMA_GET_PLEN0(x) (((x) >> eth->soc->txrx.dma_len_offset) & eth->soc->txrx.dma_max_len)
779 #define RX_DMA_VTAG BIT(15)
781 /* QDMA descriptor rxd3 */
782 -#define RX_DMA_VID(_x) ((_x) & 0xfff)
783 +#define RX_DMA_VID(x) ((x) & VLAN_VID_MASK)
784 +#define RX_DMA_TCI(x) ((x) & (VLAN_PRIO_MASK | VLAN_VID_MASK))
785 +#define RX_DMA_VPID(x) (((x) >> 16) & 0xffff)
787 /* QDMA descriptor rxd4 */
788 #define MTK_RXD4_FOE_ENTRY GENMASK(13, 0)
789 @@ -246,10 +305,15 @@
790 /* QDMA descriptor rxd4 */
791 #define RX_DMA_L4_VALID BIT(24)
792 #define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */
793 -#define RX_DMA_FPORT_SHIFT 19
794 -#define RX_DMA_FPORT_MASK 0x7
795 #define RX_DMA_SPECIAL_TAG BIT(22)
797 +#define RX_DMA_GET_SPORT(x) (((x) >> 19) & 0xf)
798 +#define RX_DMA_GET_SPORT_V2(x) (((x) >> 26) & 0x7)
800 +/* PDMA V2 descriptor rxd3 */
801 +#define RX_DMA_VTAG_V2 BIT(0)
802 +#define RX_DMA_L4_VALID_V2 BIT(2)
804 /* PHY Indirect Access Control registers */
805 #define MTK_PHY_IAC 0x10004
806 #define PHY_IAC_ACCESS BIT(31)
808 #define ETHSYS_TRGMII_MT7621_DDR_PLL BIT(5)
810 /* ethernet reset control register */
811 +#define ETHSYS_RSTCTRL 0x34
812 +#define RSTCTRL_FE BIT(6)
813 +#define RSTCTRL_PPE BIT(31)
814 +#define RSTCTRL_PPE1 BIT(30)
815 +#define RSTCTRL_ETH BIT(23)
817 +/* ethernet reset check idle register */
818 +#define ETHSYS_FE_RST_CHK_IDLE_EN 0x28
820 +/* ethernet reset control register */
821 #define ETHSYS_RSTCTRL 0x34
822 #define RSTCTRL_FE BIT(6)
823 #define RSTCTRL_PPE BIT(31)
824 @@ -454,6 +528,17 @@ struct mtk_rx_dma {
826 } __packed __aligned(4);
828 +struct mtk_rx_dma_v2 {
837 +} __packed __aligned(4);
842 @@ -461,6 +546,17 @@ struct mtk_tx_dma {
844 } __packed __aligned(4);
846 +struct mtk_tx_dma_v2 {
855 +} __packed __aligned(4);
860 @@ -647,7 +743,9 @@ enum mkt_eth_capabilities {
862 MTK_TRGMII_MT7621_CLK_BIT,
866 + MTK_RSTCTRL_PPE1_BIT,
869 MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
870 @@ -679,7 +777,9 @@ enum mkt_eth_capabilities {
871 #define MTK_SHARED_INT BIT(MTK_SHARED_INT_BIT)
872 #define MTK_TRGMII_MT7621_CLK BIT(MTK_TRGMII_MT7621_CLK_BIT)
873 #define MTK_QDMA BIT(MTK_QDMA_BIT)
874 +#define MTK_NETSYS_V2 BIT(MTK_NETSYS_V2_BIT)
875 #define MTK_SOC_MT7628 BIT(MTK_SOC_MT7628_BIT)
876 +#define MTK_RSTCTRL_PPE1 BIT(MTK_RSTCTRL_PPE1_BIT)
878 #define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \
879 BIT(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
880 @@ -756,6 +856,7 @@ struct mtk_tx_dma_desc_info {
888 @@ -813,6 +914,10 @@ struct mtk_reg_map {
889 * the extra setup for those pins used by GMAC.
890 * @txd_size Tx DMA descriptor size.
891 * @rxd_size Rx DMA descriptor size.
892 + * @rx_irq_done_mask Rx irq done register mask.
893 + * @rx_dma_l4_valid Rx DMA valid register mask.
894 + * @dma_max_len Max DMA tx/rx buffer length.
895 + * @dma_len_offset Tx/Rx DMA length field offset.
897 struct mtk_soc_data {
898 const struct mtk_reg_map *reg_map;
899 @@ -825,6 +930,10 @@ struct mtk_soc_data {
903 + u32 rx_irq_done_mask;
904 + u32 rx_dma_l4_valid;
906 + u32 dma_len_offset;
910 @@ -943,7 +1052,6 @@ struct mtk_eth {
914 - u32 rx_dma_l4_valid;