2 * This is the driver for the GMAC on-chip Ethernet controller for ST SoCs.
3 * DWC Ether MAC version 4.00 has been used for developing this code.
5 * This only implements the mac core functions for this chip.
7 * Copyright (C) 2015 STMicroelectronics Ltd
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
13 * Author: Alexandre Torgue <alexandre.torgue@st.com>
16 #include <linux/crc32.h>
17 #include <linux/slab.h>
18 #include <linux/ethtool.h>
21 #include "stmmac_pcs.h"
24 static void dwmac4_core_init(struct mac_device_info *hw,
25 struct net_device *dev)
27 void __iomem *ioaddr = hw->pcsr;
28 u32 value = readl(ioaddr + GMAC_CONFIG);
31 value |= GMAC_CORE_INIT;
34 value |= GMAC_CONFIG_2K;
36 value |= GMAC_CONFIG_JE;
39 value |= GMAC_CONFIG_TE;
41 value &= hw->link.speed_mask;
44 value |= hw->link.speed1000;
47 value |= hw->link.speed100;
50 value |= hw->link.speed10;
55 writel(value, ioaddr + GMAC_CONFIG);
57 /* Mask GMAC interrupts */
58 value = GMAC_INT_DEFAULT_MASK;
60 value |= GMAC_INT_PMT_EN;
62 value |= GMAC_PCS_IRQ_DEFAULT;
64 writel(value, ioaddr + GMAC_INT_EN);
67 static void dwmac4_rx_queue_enable(struct mac_device_info *hw,
70 void __iomem *ioaddr = hw->pcsr;
71 u32 value = readl(ioaddr + GMAC_RXQ_CTRL0);
73 value &= GMAC_RX_QUEUE_CLEAR(queue);
74 if (mode == MTL_QUEUE_AVB)
75 value |= GMAC_RX_AV_QUEUE_ENABLE(queue);
76 else if (mode == MTL_QUEUE_DCB)
77 value |= GMAC_RX_DCB_QUEUE_ENABLE(queue);
79 writel(value, ioaddr + GMAC_RXQ_CTRL0);
82 static void dwmac4_rx_queue_priority(struct mac_device_info *hw,
85 void __iomem *ioaddr = hw->pcsr;
89 base_register = (queue < 4) ? GMAC_RXQ_CTRL2 : GMAC_RXQ_CTRL3;
91 value = readl(ioaddr + base_register);
93 value &= ~GMAC_RXQCTRL_PSRQX_MASK(queue);
94 value |= (prio << GMAC_RXQCTRL_PSRQX_SHIFT(queue)) &
95 GMAC_RXQCTRL_PSRQX_MASK(queue);
96 writel(value, ioaddr + base_register);
99 static void dwmac4_tx_queue_priority(struct mac_device_info *hw,
102 void __iomem *ioaddr = hw->pcsr;
106 base_register = (queue < 4) ? GMAC_TXQ_PRTY_MAP0 : GMAC_TXQ_PRTY_MAP1;
108 value = readl(ioaddr + base_register);
110 value &= ~GMAC_TXQCTRL_PSTQX_MASK(queue);
111 value |= (prio << GMAC_TXQCTRL_PSTQX_SHIFT(queue)) &
112 GMAC_TXQCTRL_PSTQX_MASK(queue);
114 writel(value, ioaddr + base_register);
117 static void dwmac4_tx_queue_routing(struct mac_device_info *hw,
118 u8 packet, u32 queue)
120 void __iomem *ioaddr = hw->pcsr;
123 static const struct stmmac_rx_routing route_possibilities[] = {
124 { GMAC_RXQCTRL_AVCPQ_MASK, GMAC_RXQCTRL_AVCPQ_SHIFT },
125 { GMAC_RXQCTRL_PTPQ_MASK, GMAC_RXQCTRL_PTPQ_SHIFT },
126 { GMAC_RXQCTRL_DCBCPQ_MASK, GMAC_RXQCTRL_DCBCPQ_SHIFT },
127 { GMAC_RXQCTRL_UPQ_MASK, GMAC_RXQCTRL_UPQ_SHIFT },
128 { GMAC_RXQCTRL_MCBCQ_MASK, GMAC_RXQCTRL_MCBCQ_SHIFT },
131 value = readl(ioaddr + GMAC_RXQ_CTRL1);
133 /* routing configuration */
134 value &= ~route_possibilities[packet - 1].reg_mask;
135 value |= (queue << route_possibilities[packet-1].reg_shift) &
136 route_possibilities[packet - 1].reg_mask;
138 /* some packets require extra ops */
139 if (packet == PACKET_AVCPQ) {
140 value &= ~GMAC_RXQCTRL_TACPQE;
141 value |= 0x1 << GMAC_RXQCTRL_TACPQE_SHIFT;
142 } else if (packet == PACKET_MCBCQ) {
143 value &= ~GMAC_RXQCTRL_MCBCQEN;
144 value |= 0x1 << GMAC_RXQCTRL_MCBCQEN_SHIFT;
147 writel(value, ioaddr + GMAC_RXQ_CTRL1);
150 static void dwmac4_prog_mtl_rx_algorithms(struct mac_device_info *hw,
153 void __iomem *ioaddr = hw->pcsr;
154 u32 value = readl(ioaddr + MTL_OPERATION_MODE);
156 value &= ~MTL_OPERATION_RAA;
158 case MTL_RX_ALGORITHM_SP:
159 value |= MTL_OPERATION_RAA_SP;
161 case MTL_RX_ALGORITHM_WSP:
162 value |= MTL_OPERATION_RAA_WSP;
168 writel(value, ioaddr + MTL_OPERATION_MODE);
171 static void dwmac4_prog_mtl_tx_algorithms(struct mac_device_info *hw,
174 void __iomem *ioaddr = hw->pcsr;
175 u32 value = readl(ioaddr + MTL_OPERATION_MODE);
177 value &= ~MTL_OPERATION_SCHALG_MASK;
179 case MTL_TX_ALGORITHM_WRR:
180 value |= MTL_OPERATION_SCHALG_WRR;
182 case MTL_TX_ALGORITHM_WFQ:
183 value |= MTL_OPERATION_SCHALG_WFQ;
185 case MTL_TX_ALGORITHM_DWRR:
186 value |= MTL_OPERATION_SCHALG_DWRR;
188 case MTL_TX_ALGORITHM_SP:
189 value |= MTL_OPERATION_SCHALG_SP;
196 static void dwmac4_set_mtl_tx_queue_weight(struct mac_device_info *hw,
197 u32 weight, u32 queue)
199 void __iomem *ioaddr = hw->pcsr;
200 u32 value = readl(ioaddr + MTL_TXQX_WEIGHT_BASE_ADDR(queue));
202 value &= ~MTL_TXQ_WEIGHT_ISCQW_MASK;
203 value |= weight & MTL_TXQ_WEIGHT_ISCQW_MASK;
204 writel(value, ioaddr + MTL_TXQX_WEIGHT_BASE_ADDR(queue));
207 static void dwmac4_map_mtl_dma(struct mac_device_info *hw, u32 queue, u32 chan)
209 void __iomem *ioaddr = hw->pcsr;
213 value = readl(ioaddr + MTL_RXQ_DMA_MAP0);
215 value = readl(ioaddr + MTL_RXQ_DMA_MAP1);
217 if (queue == 0 || queue == 4) {
218 value &= ~MTL_RXQ_DMA_Q04MDMACH_MASK;
219 value |= MTL_RXQ_DMA_Q04MDMACH(chan);
221 value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue);
222 value |= MTL_RXQ_DMA_QXMDMACH(chan, queue);
226 writel(value, ioaddr + MTL_RXQ_DMA_MAP0);
228 writel(value, ioaddr + MTL_RXQ_DMA_MAP1);
231 static void dwmac4_config_cbs(struct mac_device_info *hw,
232 u32 send_slope, u32 idle_slope,
233 u32 high_credit, u32 low_credit, u32 queue)
235 void __iomem *ioaddr = hw->pcsr;
238 pr_debug("Queue %d configured as AVB. Parameters:\n", queue);
239 pr_debug("\tsend_slope: 0x%08x\n", send_slope);
240 pr_debug("\tidle_slope: 0x%08x\n", idle_slope);
241 pr_debug("\thigh_credit: 0x%08x\n", high_credit);
242 pr_debug("\tlow_credit: 0x%08x\n", low_credit);
244 /* enable AV algorithm */
245 value = readl(ioaddr + MTL_ETSX_CTRL_BASE_ADDR(queue));
246 value |= MTL_ETS_CTRL_AVALG;
247 value |= MTL_ETS_CTRL_CC;
248 writel(value, ioaddr + MTL_ETSX_CTRL_BASE_ADDR(queue));
250 /* configure send slope */
251 value = readl(ioaddr + MTL_SEND_SLP_CREDX_BASE_ADDR(queue));
252 value &= ~MTL_SEND_SLP_CRED_SSC_MASK;
253 value |= send_slope & MTL_SEND_SLP_CRED_SSC_MASK;
254 writel(value, ioaddr + MTL_SEND_SLP_CREDX_BASE_ADDR(queue));
256 /* configure idle slope (same register as tx weight) */
257 dwmac4_set_mtl_tx_queue_weight(hw, idle_slope, queue);
259 /* configure high credit */
260 value = readl(ioaddr + MTL_HIGH_CREDX_BASE_ADDR(queue));
261 value &= ~MTL_HIGH_CRED_HC_MASK;
262 value |= high_credit & MTL_HIGH_CRED_HC_MASK;
263 writel(value, ioaddr + MTL_HIGH_CREDX_BASE_ADDR(queue));
265 /* configure high credit */
266 value = readl(ioaddr + MTL_LOW_CREDX_BASE_ADDR(queue));
267 value &= ~MTL_HIGH_CRED_LC_MASK;
268 value |= low_credit & MTL_HIGH_CRED_LC_MASK;
269 writel(value, ioaddr + MTL_LOW_CREDX_BASE_ADDR(queue));
272 static void dwmac4_dump_regs(struct mac_device_info *hw, u32 *reg_space)
274 void __iomem *ioaddr = hw->pcsr;
277 for (i = 0; i < GMAC_REG_NUM; i++)
278 reg_space[i] = readl(ioaddr + i * 4);
281 static int dwmac4_rx_ipc_enable(struct mac_device_info *hw)
283 void __iomem *ioaddr = hw->pcsr;
284 u32 value = readl(ioaddr + GMAC_CONFIG);
287 value |= GMAC_CONFIG_IPC;
289 value &= ~GMAC_CONFIG_IPC;
291 writel(value, ioaddr + GMAC_CONFIG);
293 value = readl(ioaddr + GMAC_CONFIG);
295 return !!(value & GMAC_CONFIG_IPC);
298 static void dwmac4_pmt(struct mac_device_info *hw, unsigned long mode)
300 void __iomem *ioaddr = hw->pcsr;
301 unsigned int pmt = 0;
304 if (mode & WAKE_MAGIC) {
305 pr_debug("GMAC: WOL Magic frame\n");
306 pmt |= power_down | magic_pkt_en;
308 if (mode & WAKE_UCAST) {
309 pr_debug("GMAC: WOL on global unicast\n");
310 pmt |= power_down | global_unicast | wake_up_frame_en;
314 /* The receiver must be enabled for WOL before powering down */
315 config = readl(ioaddr + GMAC_CONFIG);
316 config |= GMAC_CONFIG_RE;
317 writel(config, ioaddr + GMAC_CONFIG);
319 writel(pmt, ioaddr + GMAC_PMT);
322 static void dwmac4_set_umac_addr(struct mac_device_info *hw,
323 unsigned char *addr, unsigned int reg_n)
325 void __iomem *ioaddr = hw->pcsr;
327 stmmac_dwmac4_set_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n),
328 GMAC_ADDR_LOW(reg_n));
331 static void dwmac4_get_umac_addr(struct mac_device_info *hw,
332 unsigned char *addr, unsigned int reg_n)
334 void __iomem *ioaddr = hw->pcsr;
336 stmmac_dwmac4_get_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n),
337 GMAC_ADDR_LOW(reg_n));
340 static void dwmac4_set_eee_mode(struct mac_device_info *hw,
341 bool en_tx_lpi_clockgating)
343 void __iomem *ioaddr = hw->pcsr;
346 /* Enable the link status receive on RGMII, SGMII ore SMII
347 * receive path and instruct the transmit to enter in LPI
350 value = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
351 value |= GMAC4_LPI_CTRL_STATUS_LPIEN | GMAC4_LPI_CTRL_STATUS_LPITXA;
353 if (en_tx_lpi_clockgating)
354 value |= GMAC4_LPI_CTRL_STATUS_LPITCSE;
356 writel(value, ioaddr + GMAC4_LPI_CTRL_STATUS);
359 static void dwmac4_reset_eee_mode(struct mac_device_info *hw)
361 void __iomem *ioaddr = hw->pcsr;
364 value = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
365 value &= ~(GMAC4_LPI_CTRL_STATUS_LPIEN | GMAC4_LPI_CTRL_STATUS_LPITXA);
366 writel(value, ioaddr + GMAC4_LPI_CTRL_STATUS);
369 static void dwmac4_set_eee_pls(struct mac_device_info *hw, int link)
371 void __iomem *ioaddr = hw->pcsr;
374 value = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
377 value |= GMAC4_LPI_CTRL_STATUS_PLS;
379 value &= ~GMAC4_LPI_CTRL_STATUS_PLS;
381 writel(value, ioaddr + GMAC4_LPI_CTRL_STATUS);
384 static void dwmac4_set_eee_timer(struct mac_device_info *hw, int ls, int tw)
386 void __iomem *ioaddr = hw->pcsr;
387 int value = ((tw & 0xffff)) | ((ls & 0x3ff) << 16);
389 /* Program the timers in the LPI timer control register:
390 * LS: minimum time (ms) for which the link
391 * status from PHY should be ok before transmitting
393 * TW: minimum time (us) for which the core waits
394 * after it has stopped transmitting the LPI pattern.
396 writel(value, ioaddr + GMAC4_LPI_TIMER_CTRL);
399 static void dwmac4_set_filter(struct mac_device_info *hw,
400 struct net_device *dev)
402 void __iomem *ioaddr = (void __iomem *)dev->base_addr;
403 unsigned int value = 0;
405 if (dev->flags & IFF_PROMISC) {
406 value = GMAC_PACKET_FILTER_PR;
407 } else if ((dev->flags & IFF_ALLMULTI) ||
408 (netdev_mc_count(dev) > HASH_TABLE_SIZE)) {
410 value = GMAC_PACKET_FILTER_PM;
411 /* Set the 64 bits of the HASH tab. To be updated if taller
414 writel(0xffffffff, ioaddr + GMAC_HASH_TAB_0_31);
415 writel(0xffffffff, ioaddr + GMAC_HASH_TAB_32_63);
416 } else if (!netdev_mc_empty(dev)) {
418 struct netdev_hw_addr *ha;
420 /* Hash filter for multicast */
421 value = GMAC_PACKET_FILTER_HMC;
423 memset(mc_filter, 0, sizeof(mc_filter));
424 netdev_for_each_mc_addr(ha, dev) {
425 /* The upper 6 bits of the calculated CRC are used to
426 * index the content of the Hash Table Reg 0 and 1.
429 (bitrev32(~crc32_le(~0, ha->addr, 6)) >> 26);
430 /* The most significant bit determines the register
431 * to use while the other 5 bits determines the bit
432 * within the selected register
434 mc_filter[bit_nr >> 5] |= (1 << (bit_nr & 0x1F));
436 writel(mc_filter[0], ioaddr + GMAC_HASH_TAB_0_31);
437 writel(mc_filter[1], ioaddr + GMAC_HASH_TAB_32_63);
440 /* Handle multiple unicast addresses */
441 if (netdev_uc_count(dev) > hw->unicast_filter_entries) {
442 /* Switch to promiscuous mode if more than 128 addrs
445 value |= GMAC_PACKET_FILTER_PR;
447 struct netdev_hw_addr *ha;
450 netdev_for_each_uc_addr(ha, dev) {
451 dwmac4_set_umac_addr(hw, ha->addr, reg);
455 while (reg <= GMAC_MAX_PERFECT_ADDRESSES) {
456 writel(0, ioaddr + GMAC_ADDR_HIGH(reg));
457 writel(0, ioaddr + GMAC_ADDR_LOW(reg));
462 writel(value, ioaddr + GMAC_PACKET_FILTER);
465 static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,
466 unsigned int fc, unsigned int pause_time,
469 void __iomem *ioaddr = hw->pcsr;
470 unsigned int flow = 0;
473 pr_debug("GMAC Flow-Control:\n");
475 pr_debug("\tReceive Flow-Control ON\n");
476 flow |= GMAC_RX_FLOW_CTRL_RFE;
478 writel(flow, ioaddr + GMAC_RX_FLOW_CTRL);
481 pr_debug("\tTransmit Flow-Control ON\n");
484 pr_debug("\tduplex mode: PAUSE %d\n", pause_time);
486 for (queue = 0; queue < tx_cnt; queue++) {
487 flow = GMAC_TX_FLOW_CTRL_TFE;
491 (pause_time << GMAC_TX_FLOW_CTRL_PT_SHIFT);
493 writel(flow, ioaddr + GMAC_QX_TX_FLOW_CTRL(queue));
496 for (queue = 0; queue < tx_cnt; queue++)
497 writel(0, ioaddr + GMAC_QX_TX_FLOW_CTRL(queue));
501 static void dwmac4_ctrl_ane(void __iomem *ioaddr, bool ane, bool srgmi_ral,
504 dwmac_ctrl_ane(ioaddr, GMAC_PCS_BASE, ane, srgmi_ral, loopback);
507 static void dwmac4_rane(void __iomem *ioaddr, bool restart)
509 dwmac_rane(ioaddr, GMAC_PCS_BASE, restart);
512 static void dwmac4_get_adv_lp(void __iomem *ioaddr, struct rgmii_adv *adv)
514 dwmac_get_adv_lp(ioaddr, GMAC_PCS_BASE, adv);
517 /* RGMII or SMII interface */
518 static void dwmac4_phystatus(void __iomem *ioaddr, struct stmmac_extra_stats *x)
522 status = readl(ioaddr + GMAC_PHYIF_CONTROL_STATUS);
525 /* Check the link status */
526 if (status & GMAC_PHYIF_CTRLSTATUS_LNKSTS) {
531 speed_value = ((status & GMAC_PHYIF_CTRLSTATUS_SPEED) >>
532 GMAC_PHYIF_CTRLSTATUS_SPEED_SHIFT);
533 if (speed_value == GMAC_PHYIF_CTRLSTATUS_SPEED_125)
534 x->pcs_speed = SPEED_1000;
535 else if (speed_value == GMAC_PHYIF_CTRLSTATUS_SPEED_25)
536 x->pcs_speed = SPEED_100;
538 x->pcs_speed = SPEED_10;
540 x->pcs_duplex = (status & GMAC_PHYIF_CTRLSTATUS_LNKMOD_MASK);
542 pr_info("Link is Up - %d/%s\n", (int)x->pcs_speed,
543 x->pcs_duplex ? "Full" : "Half");
546 pr_info("Link is Down\n");
550 static int dwmac4_irq_mtl_status(struct mac_device_info *hw, u32 chan)
552 void __iomem *ioaddr = hw->pcsr;
553 u32 mtl_int_qx_status;
556 mtl_int_qx_status = readl(ioaddr + MTL_INT_STATUS);
558 /* Check MTL Interrupt */
559 if (mtl_int_qx_status & MTL_INT_QX(chan)) {
560 /* read Queue x Interrupt status */
561 u32 status = readl(ioaddr + MTL_CHAN_INT_CTRL(chan));
563 if (status & MTL_RX_OVERFLOW_INT) {
564 /* clear Interrupt */
565 writel(status | MTL_RX_OVERFLOW_INT,
566 ioaddr + MTL_CHAN_INT_CTRL(chan));
567 ret = CORE_IRQ_MTL_RX_OVERFLOW;
574 static int dwmac4_irq_status(struct mac_device_info *hw,
575 struct stmmac_extra_stats *x)
577 void __iomem *ioaddr = hw->pcsr;
578 u32 intr_status = readl(ioaddr + GMAC_INT_STATUS);
579 u32 intr_enable = readl(ioaddr + GMAC_INT_EN);
582 /* Discard disabled bits */
583 intr_status &= intr_enable;
585 /* Not used events (e.g. MMC interrupts) are not handled. */
586 if ((intr_status & mmc_tx_irq))
588 if (unlikely(intr_status & mmc_rx_irq))
590 if (unlikely(intr_status & mmc_rx_csum_offload_irq))
591 x->mmc_rx_csum_offload_irq_n++;
592 /* Clear the PMT bits 5 and 6 by reading the PMT status reg */
593 if (unlikely(intr_status & pmt_irq)) {
594 readl(ioaddr + GMAC_PMT);
595 x->irq_receive_pmt_irq_n++;
598 dwmac_pcs_isr(ioaddr, GMAC_PCS_BASE, intr_status, x);
599 if (intr_status & PCS_RGSMIIIS_IRQ)
600 dwmac4_phystatus(ioaddr, x);
605 static void dwmac4_debug(void __iomem *ioaddr, struct stmmac_extra_stats *x,
606 u32 rx_queues, u32 tx_queues)
611 for (queue = 0; queue < tx_queues; queue++) {
612 value = readl(ioaddr + MTL_CHAN_TX_DEBUG(queue));
614 if (value & MTL_DEBUG_TXSTSFSTS)
615 x->mtl_tx_status_fifo_full++;
616 if (value & MTL_DEBUG_TXFSTS)
617 x->mtl_tx_fifo_not_empty++;
618 if (value & MTL_DEBUG_TWCSTS)
620 if (value & MTL_DEBUG_TRCSTS_MASK) {
621 u32 trcsts = (value & MTL_DEBUG_TRCSTS_MASK)
622 >> MTL_DEBUG_TRCSTS_SHIFT;
623 if (trcsts == MTL_DEBUG_TRCSTS_WRITE)
624 x->mtl_tx_fifo_read_ctrl_write++;
625 else if (trcsts == MTL_DEBUG_TRCSTS_TXW)
626 x->mtl_tx_fifo_read_ctrl_wait++;
627 else if (trcsts == MTL_DEBUG_TRCSTS_READ)
628 x->mtl_tx_fifo_read_ctrl_read++;
630 x->mtl_tx_fifo_read_ctrl_idle++;
632 if (value & MTL_DEBUG_TXPAUSED)
633 x->mac_tx_in_pause++;
636 for (queue = 0; queue < rx_queues; queue++) {
637 value = readl(ioaddr + MTL_CHAN_RX_DEBUG(queue));
639 if (value & MTL_DEBUG_RXFSTS_MASK) {
640 u32 rxfsts = (value & MTL_DEBUG_RXFSTS_MASK)
641 >> MTL_DEBUG_RRCSTS_SHIFT;
643 if (rxfsts == MTL_DEBUG_RXFSTS_FULL)
644 x->mtl_rx_fifo_fill_level_full++;
645 else if (rxfsts == MTL_DEBUG_RXFSTS_AT)
646 x->mtl_rx_fifo_fill_above_thresh++;
647 else if (rxfsts == MTL_DEBUG_RXFSTS_BT)
648 x->mtl_rx_fifo_fill_below_thresh++;
650 x->mtl_rx_fifo_fill_level_empty++;
652 if (value & MTL_DEBUG_RRCSTS_MASK) {
653 u32 rrcsts = (value & MTL_DEBUG_RRCSTS_MASK) >>
654 MTL_DEBUG_RRCSTS_SHIFT;
656 if (rrcsts == MTL_DEBUG_RRCSTS_FLUSH)
657 x->mtl_rx_fifo_read_ctrl_flush++;
658 else if (rrcsts == MTL_DEBUG_RRCSTS_RSTAT)
659 x->mtl_rx_fifo_read_ctrl_read_data++;
660 else if (rrcsts == MTL_DEBUG_RRCSTS_RDATA)
661 x->mtl_rx_fifo_read_ctrl_status++;
663 x->mtl_rx_fifo_read_ctrl_idle++;
665 if (value & MTL_DEBUG_RWCSTS)
666 x->mtl_rx_fifo_ctrl_active++;
670 value = readl(ioaddr + GMAC_DEBUG);
672 if (value & GMAC_DEBUG_TFCSTS_MASK) {
673 u32 tfcsts = (value & GMAC_DEBUG_TFCSTS_MASK)
674 >> GMAC_DEBUG_TFCSTS_SHIFT;
676 if (tfcsts == GMAC_DEBUG_TFCSTS_XFER)
677 x->mac_tx_frame_ctrl_xfer++;
678 else if (tfcsts == GMAC_DEBUG_TFCSTS_GEN_PAUSE)
679 x->mac_tx_frame_ctrl_pause++;
680 else if (tfcsts == GMAC_DEBUG_TFCSTS_WAIT)
681 x->mac_tx_frame_ctrl_wait++;
683 x->mac_tx_frame_ctrl_idle++;
685 if (value & GMAC_DEBUG_TPESTS)
686 x->mac_gmii_tx_proto_engine++;
687 if (value & GMAC_DEBUG_RFCFCSTS_MASK)
688 x->mac_rx_frame_ctrl_fifo = (value & GMAC_DEBUG_RFCFCSTS_MASK)
689 >> GMAC_DEBUG_RFCFCSTS_SHIFT;
690 if (value & GMAC_DEBUG_RPESTS)
691 x->mac_gmii_rx_proto_engine++;
694 static const struct stmmac_ops dwmac4_ops = {
695 .core_init = dwmac4_core_init,
696 .set_mac = stmmac_set_mac,
697 .rx_ipc = dwmac4_rx_ipc_enable,
698 .rx_queue_enable = dwmac4_rx_queue_enable,
699 .rx_queue_prio = dwmac4_rx_queue_priority,
700 .tx_queue_prio = dwmac4_tx_queue_priority,
701 .rx_queue_routing = dwmac4_tx_queue_routing,
702 .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
703 .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
704 .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
705 .map_mtl_to_dma = dwmac4_map_mtl_dma,
706 .config_cbs = dwmac4_config_cbs,
707 .dump_regs = dwmac4_dump_regs,
708 .host_irq_status = dwmac4_irq_status,
709 .host_mtl_irq_status = dwmac4_irq_mtl_status,
710 .flow_ctrl = dwmac4_flow_ctrl,
712 .set_umac_addr = dwmac4_set_umac_addr,
713 .get_umac_addr = dwmac4_get_umac_addr,
714 .set_eee_mode = dwmac4_set_eee_mode,
715 .reset_eee_mode = dwmac4_reset_eee_mode,
716 .set_eee_timer = dwmac4_set_eee_timer,
717 .set_eee_pls = dwmac4_set_eee_pls,
718 .pcs_ctrl_ane = dwmac4_ctrl_ane,
719 .pcs_rane = dwmac4_rane,
720 .pcs_get_adv_lp = dwmac4_get_adv_lp,
721 .debug = dwmac4_debug,
722 .set_filter = dwmac4_set_filter,
725 static const struct stmmac_ops dwmac410_ops = {
726 .core_init = dwmac4_core_init,
727 .set_mac = stmmac_dwmac4_set_mac,
728 .rx_ipc = dwmac4_rx_ipc_enable,
729 .rx_queue_enable = dwmac4_rx_queue_enable,
730 .rx_queue_prio = dwmac4_rx_queue_priority,
731 .tx_queue_prio = dwmac4_tx_queue_priority,
732 .rx_queue_routing = dwmac4_tx_queue_routing,
733 .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
734 .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
735 .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
736 .map_mtl_to_dma = dwmac4_map_mtl_dma,
737 .config_cbs = dwmac4_config_cbs,
738 .dump_regs = dwmac4_dump_regs,
739 .host_irq_status = dwmac4_irq_status,
740 .host_mtl_irq_status = dwmac4_irq_mtl_status,
741 .flow_ctrl = dwmac4_flow_ctrl,
743 .set_umac_addr = dwmac4_set_umac_addr,
744 .get_umac_addr = dwmac4_get_umac_addr,
745 .set_eee_mode = dwmac4_set_eee_mode,
746 .reset_eee_mode = dwmac4_reset_eee_mode,
747 .set_eee_timer = dwmac4_set_eee_timer,
748 .set_eee_pls = dwmac4_set_eee_pls,
749 .pcs_ctrl_ane = dwmac4_ctrl_ane,
750 .pcs_rane = dwmac4_rane,
751 .pcs_get_adv_lp = dwmac4_get_adv_lp,
752 .debug = dwmac4_debug,
753 .set_filter = dwmac4_set_filter,
756 struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
757 int perfect_uc_entries, int *synopsys_id)
759 struct mac_device_info *mac;
760 u32 hwid = readl(ioaddr + GMAC_VERSION);
762 mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);
767 mac->multicast_filter_bins = mcbins;
768 mac->unicast_filter_entries = perfect_uc_entries;
769 mac->mcast_bits_log2 = 0;
771 if (mac->multicast_filter_bins)
772 mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
774 mac->link.duplex = GMAC_CONFIG_DM;
775 mac->link.speed10 = GMAC_CONFIG_PS;
776 mac->link.speed100 = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
777 mac->link.speed1000 = 0;
778 mac->link.speed_mask = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
779 mac->mii.addr = GMAC_MDIO_ADDR;
780 mac->mii.data = GMAC_MDIO_DATA;
781 mac->mii.addr_shift = 21;
782 mac->mii.addr_mask = GENMASK(25, 21);
783 mac->mii.reg_shift = 16;
784 mac->mii.reg_mask = GENMASK(20, 16);
785 mac->mii.clk_csr_shift = 8;
786 mac->mii.clk_csr_mask = GENMASK(11, 8);
788 /* Get and dump the chip ID */
789 *synopsys_id = stmmac_get_synopsys_id(hwid);
791 if (*synopsys_id > DWMAC_CORE_4_00)
792 mac->dma = &dwmac410_dma_ops;
794 mac->dma = &dwmac4_dma_ops;
796 if (*synopsys_id >= DWMAC_CORE_4_00)
797 mac->mac = &dwmac410_ops;
799 mac->mac = &dwmac4_ops;