1 // SPDX-License-Identifier: GPL-2.0-only
3 * This is the driver for the GMAC on-chip Ethernet controller for ST SoCs.
4 * DWC Ether MAC version 4.00 has been used for developing this code.
6 * This only implements the mac core functions for this chip.
8 * Copyright (C) 2015 STMicroelectronics Ltd
10 * Author: Alexandre Torgue <alexandre.torgue@st.com>
13 #include <linux/crc32.h>
14 #include <linux/slab.h>
15 #include <linux/ethtool.h>
19 #include "stmmac_pcs.h"
23 static void dwmac4_core_init(struct mac_device_info *hw,
24 struct net_device *dev)
26 struct stmmac_priv *priv = netdev_priv(dev);
27 void __iomem *ioaddr = hw->pcsr;
28 u32 value = readl(ioaddr + GMAC_CONFIG);
30 value |= GMAC_CORE_INIT;
33 value |= GMAC_CONFIG_TE;
35 value &= hw->link.speed_mask;
38 value |= hw->link.speed1000;
41 value |= hw->link.speed100;
44 value |= hw->link.speed10;
49 writel(value, ioaddr + GMAC_CONFIG);
51 /* Enable GMAC interrupts */
52 value = GMAC_INT_DEFAULT_ENABLE;
55 value |= GMAC_PCS_IRQ_DEFAULT;
57 /* Enable FPE interrupt */
58 if ((GMAC_HW_FEAT_FPESEL & readl(ioaddr + GMAC_HW_FEATURE3)) >> 26)
59 value |= GMAC_INT_FPE_EN;
61 writel(value, ioaddr + GMAC_INT_EN);
63 if (GMAC_INT_DEFAULT_ENABLE & GMAC_INT_TSIE)
64 init_waitqueue_head(&priv->tstamp_busy_wait);
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;
93 value = readl(ioaddr + base_register);
95 value &= ~GMAC_RXQCTRL_PSRQX_MASK(queue);
96 value |= (prio << GMAC_RXQCTRL_PSRQX_SHIFT(queue)) &
97 GMAC_RXQCTRL_PSRQX_MASK(queue);
98 writel(value, ioaddr + base_register);
101 static void dwmac4_tx_queue_priority(struct mac_device_info *hw,
104 void __iomem *ioaddr = hw->pcsr;
108 base_register = (queue < 4) ? GMAC_TXQ_PRTY_MAP0 : GMAC_TXQ_PRTY_MAP1;
112 value = readl(ioaddr + base_register);
114 value &= ~GMAC_TXQCTRL_PSTQX_MASK(queue);
115 value |= (prio << GMAC_TXQCTRL_PSTQX_SHIFT(queue)) &
116 GMAC_TXQCTRL_PSTQX_MASK(queue);
118 writel(value, ioaddr + base_register);
121 static void dwmac4_rx_queue_routing(struct mac_device_info *hw,
122 u8 packet, u32 queue)
124 void __iomem *ioaddr = hw->pcsr;
127 static const struct stmmac_rx_routing route_possibilities[] = {
128 { GMAC_RXQCTRL_AVCPQ_MASK, GMAC_RXQCTRL_AVCPQ_SHIFT },
129 { GMAC_RXQCTRL_PTPQ_MASK, GMAC_RXQCTRL_PTPQ_SHIFT },
130 { GMAC_RXQCTRL_DCBCPQ_MASK, GMAC_RXQCTRL_DCBCPQ_SHIFT },
131 { GMAC_RXQCTRL_UPQ_MASK, GMAC_RXQCTRL_UPQ_SHIFT },
132 { GMAC_RXQCTRL_MCBCQ_MASK, GMAC_RXQCTRL_MCBCQ_SHIFT },
135 value = readl(ioaddr + GMAC_RXQ_CTRL1);
137 /* routing configuration */
138 value &= ~route_possibilities[packet - 1].reg_mask;
139 value |= (queue << route_possibilities[packet-1].reg_shift) &
140 route_possibilities[packet - 1].reg_mask;
142 /* some packets require extra ops */
143 if (packet == PACKET_AVCPQ) {
144 value &= ~GMAC_RXQCTRL_TACPQE;
145 value |= 0x1 << GMAC_RXQCTRL_TACPQE_SHIFT;
146 } else if (packet == PACKET_MCBCQ) {
147 value &= ~GMAC_RXQCTRL_MCBCQEN;
148 value |= 0x1 << GMAC_RXQCTRL_MCBCQEN_SHIFT;
151 writel(value, ioaddr + GMAC_RXQ_CTRL1);
154 static void dwmac4_prog_mtl_rx_algorithms(struct mac_device_info *hw,
157 void __iomem *ioaddr = hw->pcsr;
158 u32 value = readl(ioaddr + MTL_OPERATION_MODE);
160 value &= ~MTL_OPERATION_RAA;
162 case MTL_RX_ALGORITHM_SP:
163 value |= MTL_OPERATION_RAA_SP;
165 case MTL_RX_ALGORITHM_WSP:
166 value |= MTL_OPERATION_RAA_WSP;
172 writel(value, ioaddr + MTL_OPERATION_MODE);
175 static void dwmac4_prog_mtl_tx_algorithms(struct mac_device_info *hw,
178 void __iomem *ioaddr = hw->pcsr;
179 u32 value = readl(ioaddr + MTL_OPERATION_MODE);
181 value &= ~MTL_OPERATION_SCHALG_MASK;
183 case MTL_TX_ALGORITHM_WRR:
184 value |= MTL_OPERATION_SCHALG_WRR;
186 case MTL_TX_ALGORITHM_WFQ:
187 value |= MTL_OPERATION_SCHALG_WFQ;
189 case MTL_TX_ALGORITHM_DWRR:
190 value |= MTL_OPERATION_SCHALG_DWRR;
192 case MTL_TX_ALGORITHM_SP:
193 value |= MTL_OPERATION_SCHALG_SP;
199 writel(value, ioaddr + MTL_OPERATION_MODE);
202 static void dwmac4_set_mtl_tx_queue_weight(struct mac_device_info *hw,
203 u32 weight, u32 queue)
205 void __iomem *ioaddr = hw->pcsr;
206 u32 value = readl(ioaddr + MTL_TXQX_WEIGHT_BASE_ADDR(queue));
208 value &= ~MTL_TXQ_WEIGHT_ISCQW_MASK;
209 value |= weight & MTL_TXQ_WEIGHT_ISCQW_MASK;
210 writel(value, ioaddr + MTL_TXQX_WEIGHT_BASE_ADDR(queue));
213 static void dwmac4_map_mtl_dma(struct mac_device_info *hw, u32 queue, u32 chan)
215 void __iomem *ioaddr = hw->pcsr;
219 value = readl(ioaddr + MTL_RXQ_DMA_MAP0);
221 value = readl(ioaddr + MTL_RXQ_DMA_MAP1);
223 if (queue == 0 || queue == 4) {
224 value &= ~MTL_RXQ_DMA_Q04MDMACH_MASK;
225 value |= MTL_RXQ_DMA_Q04MDMACH(chan);
226 } else if (queue > 4) {
227 value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue - 4);
228 value |= MTL_RXQ_DMA_QXMDMACH(chan, queue - 4);
230 value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue);
231 value |= MTL_RXQ_DMA_QXMDMACH(chan, queue);
235 writel(value, ioaddr + MTL_RXQ_DMA_MAP0);
237 writel(value, ioaddr + MTL_RXQ_DMA_MAP1);
240 static void dwmac4_config_cbs(struct mac_device_info *hw,
241 u32 send_slope, u32 idle_slope,
242 u32 high_credit, u32 low_credit, u32 queue)
244 void __iomem *ioaddr = hw->pcsr;
247 pr_debug("Queue %d configured as AVB. Parameters:\n", queue);
248 pr_debug("\tsend_slope: 0x%08x\n", send_slope);
249 pr_debug("\tidle_slope: 0x%08x\n", idle_slope);
250 pr_debug("\thigh_credit: 0x%08x\n", high_credit);
251 pr_debug("\tlow_credit: 0x%08x\n", low_credit);
253 /* enable AV algorithm */
254 value = readl(ioaddr + MTL_ETSX_CTRL_BASE_ADDR(queue));
255 value |= MTL_ETS_CTRL_AVALG;
256 value |= MTL_ETS_CTRL_CC;
257 writel(value, ioaddr + MTL_ETSX_CTRL_BASE_ADDR(queue));
259 /* configure send slope */
260 value = readl(ioaddr + MTL_SEND_SLP_CREDX_BASE_ADDR(queue));
261 value &= ~MTL_SEND_SLP_CRED_SSC_MASK;
262 value |= send_slope & MTL_SEND_SLP_CRED_SSC_MASK;
263 writel(value, ioaddr + MTL_SEND_SLP_CREDX_BASE_ADDR(queue));
265 /* configure idle slope (same register as tx weight) */
266 dwmac4_set_mtl_tx_queue_weight(hw, idle_slope, queue);
268 /* configure high credit */
269 value = readl(ioaddr + MTL_HIGH_CREDX_BASE_ADDR(queue));
270 value &= ~MTL_HIGH_CRED_HC_MASK;
271 value |= high_credit & MTL_HIGH_CRED_HC_MASK;
272 writel(value, ioaddr + MTL_HIGH_CREDX_BASE_ADDR(queue));
274 /* configure high credit */
275 value = readl(ioaddr + MTL_LOW_CREDX_BASE_ADDR(queue));
276 value &= ~MTL_HIGH_CRED_LC_MASK;
277 value |= low_credit & MTL_HIGH_CRED_LC_MASK;
278 writel(value, ioaddr + MTL_LOW_CREDX_BASE_ADDR(queue));
281 static void dwmac4_dump_regs(struct mac_device_info *hw, u32 *reg_space)
283 void __iomem *ioaddr = hw->pcsr;
286 for (i = 0; i < GMAC_REG_NUM; i++)
287 reg_space[i] = readl(ioaddr + i * 4);
290 static int dwmac4_rx_ipc_enable(struct mac_device_info *hw)
292 void __iomem *ioaddr = hw->pcsr;
293 u32 value = readl(ioaddr + GMAC_CONFIG);
296 value |= GMAC_CONFIG_IPC;
298 value &= ~GMAC_CONFIG_IPC;
300 writel(value, ioaddr + GMAC_CONFIG);
302 value = readl(ioaddr + GMAC_CONFIG);
304 return !!(value & GMAC_CONFIG_IPC);
307 static void dwmac4_pmt(struct mac_device_info *hw, unsigned long mode)
309 void __iomem *ioaddr = hw->pcsr;
310 unsigned int pmt = 0;
313 if (mode & WAKE_MAGIC) {
314 pr_debug("GMAC: WOL Magic frame\n");
315 pmt |= power_down | magic_pkt_en;
317 if (mode & WAKE_UCAST) {
318 pr_debug("GMAC: WOL on global unicast\n");
319 pmt |= power_down | global_unicast | wake_up_frame_en;
323 /* The receiver must be enabled for WOL before powering down */
324 config = readl(ioaddr + GMAC_CONFIG);
325 config |= GMAC_CONFIG_RE;
326 writel(config, ioaddr + GMAC_CONFIG);
328 writel(pmt, ioaddr + GMAC_PMT);
331 static void dwmac4_set_umac_addr(struct mac_device_info *hw,
332 const unsigned char *addr, unsigned int reg_n)
334 void __iomem *ioaddr = hw->pcsr;
336 stmmac_dwmac4_set_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n),
337 GMAC_ADDR_LOW(reg_n));
340 static void dwmac4_get_umac_addr(struct mac_device_info *hw,
341 unsigned char *addr, unsigned int reg_n)
343 void __iomem *ioaddr = hw->pcsr;
345 stmmac_dwmac4_get_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n),
346 GMAC_ADDR_LOW(reg_n));
349 static void dwmac4_set_eee_mode(struct mac_device_info *hw,
350 bool en_tx_lpi_clockgating)
352 void __iomem *ioaddr = hw->pcsr;
355 /* Enable the link status receive on RGMII, SGMII ore SMII
356 * receive path and instruct the transmit to enter in LPI
359 value = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
360 value |= GMAC4_LPI_CTRL_STATUS_LPIEN | GMAC4_LPI_CTRL_STATUS_LPITXA;
362 if (en_tx_lpi_clockgating)
363 value |= GMAC4_LPI_CTRL_STATUS_LPITCSE;
365 writel(value, ioaddr + GMAC4_LPI_CTRL_STATUS);
368 static void dwmac4_reset_eee_mode(struct mac_device_info *hw)
370 void __iomem *ioaddr = hw->pcsr;
373 value = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
374 value &= ~(GMAC4_LPI_CTRL_STATUS_LPIEN | GMAC4_LPI_CTRL_STATUS_LPITXA);
375 writel(value, ioaddr + GMAC4_LPI_CTRL_STATUS);
378 static void dwmac4_set_eee_pls(struct mac_device_info *hw, int link)
380 void __iomem *ioaddr = hw->pcsr;
383 value = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
386 value |= GMAC4_LPI_CTRL_STATUS_PLS;
388 value &= ~GMAC4_LPI_CTRL_STATUS_PLS;
390 writel(value, ioaddr + GMAC4_LPI_CTRL_STATUS);
393 static void dwmac4_set_eee_lpi_entry_timer(struct mac_device_info *hw, int et)
395 void __iomem *ioaddr = hw->pcsr;
396 int value = et & STMMAC_ET_MAX;
399 /* Program LPI entry timer value into register */
400 writel(value, ioaddr + GMAC4_LPI_ENTRY_TIMER);
402 /* Enable/disable LPI entry timer */
403 regval = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
404 regval |= GMAC4_LPI_CTRL_STATUS_LPIEN | GMAC4_LPI_CTRL_STATUS_LPITXA;
407 regval |= GMAC4_LPI_CTRL_STATUS_LPIATE;
409 regval &= ~GMAC4_LPI_CTRL_STATUS_LPIATE;
411 writel(regval, ioaddr + GMAC4_LPI_CTRL_STATUS);
414 static void dwmac4_set_eee_timer(struct mac_device_info *hw, int ls, int tw)
416 void __iomem *ioaddr = hw->pcsr;
417 int value = ((tw & 0xffff)) | ((ls & 0x3ff) << 16);
419 /* Program the timers in the LPI timer control register:
420 * LS: minimum time (ms) for which the link
421 * status from PHY should be ok before transmitting
423 * TW: minimum time (us) for which the core waits
424 * after it has stopped transmitting the LPI pattern.
426 writel(value, ioaddr + GMAC4_LPI_TIMER_CTRL);
429 static void dwmac4_write_single_vlan(struct net_device *dev, u16 vid)
431 void __iomem *ioaddr = (void __iomem *)dev->base_addr;
434 val = readl(ioaddr + GMAC_VLAN_TAG);
435 val &= ~GMAC_VLAN_TAG_VID;
436 val |= GMAC_VLAN_TAG_ETV | vid;
438 writel(val, ioaddr + GMAC_VLAN_TAG);
441 static int dwmac4_write_vlan_filter(struct net_device *dev,
442 struct mac_device_info *hw,
445 void __iomem *ioaddr = (void __iomem *)dev->base_addr;
449 if (index >= hw->num_vlan)
452 writel(data, ioaddr + GMAC_VLAN_TAG_DATA);
454 val = readl(ioaddr + GMAC_VLAN_TAG);
455 val &= ~(GMAC_VLAN_TAG_CTRL_OFS_MASK |
456 GMAC_VLAN_TAG_CTRL_CT |
457 GMAC_VLAN_TAG_CTRL_OB);
458 val |= (index << GMAC_VLAN_TAG_CTRL_OFS_SHIFT) | GMAC_VLAN_TAG_CTRL_OB;
460 writel(val, ioaddr + GMAC_VLAN_TAG);
462 for (i = 0; i < timeout; i++) {
463 val = readl(ioaddr + GMAC_VLAN_TAG);
464 if (!(val & GMAC_VLAN_TAG_CTRL_OB))
469 netdev_err(dev, "Timeout accessing MAC_VLAN_Tag_Filter\n");
474 static int dwmac4_add_hw_vlan_rx_fltr(struct net_device *dev,
475 struct mac_device_info *hw,
476 __be16 proto, u16 vid)
487 "Adding VLAN in promisc mode not supported\n");
491 /* Single Rx VLAN Filter */
492 if (hw->num_vlan == 1) {
493 /* For single VLAN filter, VID 0 means VLAN promiscuous */
495 netdev_warn(dev, "Adding VLAN ID 0 is not supported\n");
499 if (hw->vlan_filter[0] & GMAC_VLAN_TAG_VID) {
500 netdev_err(dev, "Only single VLAN ID supported\n");
504 hw->vlan_filter[0] = vid;
505 dwmac4_write_single_vlan(dev, vid);
510 /* Extended Rx VLAN Filter Enable */
511 val |= GMAC_VLAN_TAG_DATA_ETV | GMAC_VLAN_TAG_DATA_VEN | vid;
513 for (i = 0; i < hw->num_vlan; i++) {
514 if (hw->vlan_filter[i] == val)
516 else if (!(hw->vlan_filter[i] & GMAC_VLAN_TAG_DATA_VEN))
521 netdev_err(dev, "MAC_VLAN_Tag_Filter full (size: %0u)\n",
526 ret = dwmac4_write_vlan_filter(dev, hw, index, val);
529 hw->vlan_filter[index] = val;
534 static int dwmac4_del_hw_vlan_rx_fltr(struct net_device *dev,
535 struct mac_device_info *hw,
536 __be16 proto, u16 vid)
542 "Deleting VLAN in promisc mode not supported\n");
546 /* Single Rx VLAN Filter */
547 if (hw->num_vlan == 1) {
548 if ((hw->vlan_filter[0] & GMAC_VLAN_TAG_VID) == vid) {
549 hw->vlan_filter[0] = 0;
550 dwmac4_write_single_vlan(dev, 0);
555 /* Extended Rx VLAN Filter Enable */
556 for (i = 0; i < hw->num_vlan; i++) {
557 if ((hw->vlan_filter[i] & GMAC_VLAN_TAG_DATA_VID) == vid) {
558 ret = dwmac4_write_vlan_filter(dev, hw, i, 0);
561 hw->vlan_filter[i] = 0;
570 static void dwmac4_vlan_promisc_enable(struct net_device *dev,
571 struct mac_device_info *hw)
573 void __iomem *ioaddr = hw->pcsr;
579 /* Single Rx VLAN Filter */
580 if (hw->num_vlan == 1) {
581 dwmac4_write_single_vlan(dev, 0);
585 /* Extended Rx VLAN Filter Enable */
586 for (i = 0; i < hw->num_vlan; i++) {
587 if (hw->vlan_filter[i] & GMAC_VLAN_TAG_DATA_VEN) {
588 val = hw->vlan_filter[i] & ~GMAC_VLAN_TAG_DATA_VEN;
589 dwmac4_write_vlan_filter(dev, hw, i, val);
593 hash = readl(ioaddr + GMAC_VLAN_HASH_TABLE);
594 if (hash & GMAC_VLAN_VLHT) {
595 value = readl(ioaddr + GMAC_VLAN_TAG);
596 if (value & GMAC_VLAN_VTHM) {
597 value &= ~GMAC_VLAN_VTHM;
598 writel(value, ioaddr + GMAC_VLAN_TAG);
603 static void dwmac4_restore_hw_vlan_rx_fltr(struct net_device *dev,
604 struct mac_device_info *hw)
606 void __iomem *ioaddr = hw->pcsr;
612 /* Single Rx VLAN Filter */
613 if (hw->num_vlan == 1) {
614 dwmac4_write_single_vlan(dev, hw->vlan_filter[0]);
618 /* Extended Rx VLAN Filter Enable */
619 for (i = 0; i < hw->num_vlan; i++) {
620 if (hw->vlan_filter[i] & GMAC_VLAN_TAG_DATA_VEN) {
621 val = hw->vlan_filter[i];
622 dwmac4_write_vlan_filter(dev, hw, i, val);
626 hash = readl(ioaddr + GMAC_VLAN_HASH_TABLE);
627 if (hash & GMAC_VLAN_VLHT) {
628 value = readl(ioaddr + GMAC_VLAN_TAG);
629 value |= GMAC_VLAN_VTHM;
630 writel(value, ioaddr + GMAC_VLAN_TAG);
634 static void dwmac4_set_filter(struct mac_device_info *hw,
635 struct net_device *dev)
637 void __iomem *ioaddr = (void __iomem *)dev->base_addr;
638 int numhashregs = (hw->multicast_filter_bins >> 5);
639 int mcbitslog2 = hw->mcast_bits_log2;
644 memset(mc_filter, 0, sizeof(mc_filter));
646 value = readl(ioaddr + GMAC_PACKET_FILTER);
647 value &= ~GMAC_PACKET_FILTER_HMC;
648 value &= ~GMAC_PACKET_FILTER_HPF;
649 value &= ~GMAC_PACKET_FILTER_PCF;
650 value &= ~GMAC_PACKET_FILTER_PM;
651 value &= ~GMAC_PACKET_FILTER_PR;
652 value &= ~GMAC_PACKET_FILTER_RA;
653 if (dev->flags & IFF_PROMISC) {
654 /* VLAN Tag Filter Fail Packets Queuing */
655 if (hw->vlan_fail_q_en) {
656 value = readl(ioaddr + GMAC_RXQ_CTRL4);
657 value &= ~GMAC_RXQCTRL_VFFQ_MASK;
658 value |= GMAC_RXQCTRL_VFFQE |
659 (hw->vlan_fail_q << GMAC_RXQCTRL_VFFQ_SHIFT);
660 writel(value, ioaddr + GMAC_RXQ_CTRL4);
661 value = GMAC_PACKET_FILTER_PR | GMAC_PACKET_FILTER_RA;
663 value = GMAC_PACKET_FILTER_PR | GMAC_PACKET_FILTER_PCF;
666 } else if ((dev->flags & IFF_ALLMULTI) ||
667 (netdev_mc_count(dev) > hw->multicast_filter_bins)) {
669 value |= GMAC_PACKET_FILTER_PM;
670 /* Set all the bits of the HASH tab */
671 memset(mc_filter, 0xff, sizeof(mc_filter));
672 } else if (!netdev_mc_empty(dev) && (dev->flags & IFF_MULTICAST)) {
673 struct netdev_hw_addr *ha;
675 /* Hash filter for multicast */
676 value |= GMAC_PACKET_FILTER_HMC;
678 netdev_for_each_mc_addr(ha, dev) {
679 /* The upper n bits of the calculated CRC are used to
680 * index the contents of the hash table. The number of
681 * bits used depends on the hardware configuration
682 * selected at core configuration time.
684 u32 bit_nr = bitrev32(~crc32_le(~0, ha->addr,
685 ETH_ALEN)) >> (32 - mcbitslog2);
686 /* The most significant bit determines the register to
687 * use (H/L) while the other 5 bits determine the bit
688 * within the register.
690 mc_filter[bit_nr >> 5] |= (1 << (bit_nr & 0x1f));
694 for (i = 0; i < numhashregs; i++)
695 writel(mc_filter[i], ioaddr + GMAC_HASH_TAB(i));
697 value |= GMAC_PACKET_FILTER_HPF;
699 /* Handle multiple unicast addresses */
700 if (netdev_uc_count(dev) > hw->unicast_filter_entries) {
701 /* Switch to promiscuous mode if more than 128 addrs
704 value |= GMAC_PACKET_FILTER_PR;
706 struct netdev_hw_addr *ha;
709 netdev_for_each_uc_addr(ha, dev) {
710 dwmac4_set_umac_addr(hw, ha->addr, reg);
714 while (reg < GMAC_MAX_PERFECT_ADDRESSES) {
715 writel(0, ioaddr + GMAC_ADDR_HIGH(reg));
716 writel(0, ioaddr + GMAC_ADDR_LOW(reg));
722 if (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
723 value |= GMAC_PACKET_FILTER_VTFE;
725 writel(value, ioaddr + GMAC_PACKET_FILTER);
727 if (dev->flags & IFF_PROMISC && !hw->vlan_fail_q_en) {
730 dwmac4_vlan_promisc_enable(dev, hw);
735 dwmac4_restore_hw_vlan_rx_fltr(dev, hw);
740 static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,
741 unsigned int fc, unsigned int pause_time,
744 void __iomem *ioaddr = hw->pcsr;
745 unsigned int flow = 0;
748 pr_debug("GMAC Flow-Control:\n");
750 pr_debug("\tReceive Flow-Control ON\n");
751 flow |= GMAC_RX_FLOW_CTRL_RFE;
753 writel(flow, ioaddr + GMAC_RX_FLOW_CTRL);
756 pr_debug("\tTransmit Flow-Control ON\n");
759 pr_debug("\tduplex mode: PAUSE %d\n", pause_time);
761 for (queue = 0; queue < tx_cnt; queue++) {
762 flow = GMAC_TX_FLOW_CTRL_TFE;
766 (pause_time << GMAC_TX_FLOW_CTRL_PT_SHIFT);
768 writel(flow, ioaddr + GMAC_QX_TX_FLOW_CTRL(queue));
771 for (queue = 0; queue < tx_cnt; queue++)
772 writel(0, ioaddr + GMAC_QX_TX_FLOW_CTRL(queue));
776 static void dwmac4_ctrl_ane(void __iomem *ioaddr, bool ane, bool srgmi_ral,
779 dwmac_ctrl_ane(ioaddr, GMAC_PCS_BASE, ane, srgmi_ral, loopback);
782 static void dwmac4_rane(void __iomem *ioaddr, bool restart)
784 dwmac_rane(ioaddr, GMAC_PCS_BASE, restart);
787 static void dwmac4_get_adv_lp(void __iomem *ioaddr, struct rgmii_adv *adv)
789 dwmac_get_adv_lp(ioaddr, GMAC_PCS_BASE, adv);
792 /* RGMII or SMII interface */
793 static void dwmac4_phystatus(void __iomem *ioaddr, struct stmmac_extra_stats *x)
797 status = readl(ioaddr + GMAC_PHYIF_CONTROL_STATUS);
800 /* Check the link status */
801 if (status & GMAC_PHYIF_CTRLSTATUS_LNKSTS) {
806 speed_value = ((status & GMAC_PHYIF_CTRLSTATUS_SPEED) >>
807 GMAC_PHYIF_CTRLSTATUS_SPEED_SHIFT);
808 if (speed_value == GMAC_PHYIF_CTRLSTATUS_SPEED_125)
809 x->pcs_speed = SPEED_1000;
810 else if (speed_value == GMAC_PHYIF_CTRLSTATUS_SPEED_25)
811 x->pcs_speed = SPEED_100;
813 x->pcs_speed = SPEED_10;
815 x->pcs_duplex = (status & GMAC_PHYIF_CTRLSTATUS_LNKMOD_MASK);
817 pr_info("Link is Up - %d/%s\n", (int)x->pcs_speed,
818 x->pcs_duplex ? "Full" : "Half");
821 pr_info("Link is Down\n");
825 static int dwmac4_irq_mtl_status(struct mac_device_info *hw, u32 chan)
827 void __iomem *ioaddr = hw->pcsr;
828 u32 mtl_int_qx_status;
831 mtl_int_qx_status = readl(ioaddr + MTL_INT_STATUS);
833 /* Check MTL Interrupt */
834 if (mtl_int_qx_status & MTL_INT_QX(chan)) {
835 /* read Queue x Interrupt status */
836 u32 status = readl(ioaddr + MTL_CHAN_INT_CTRL(chan));
838 if (status & MTL_RX_OVERFLOW_INT) {
839 /* clear Interrupt */
840 writel(status | MTL_RX_OVERFLOW_INT,
841 ioaddr + MTL_CHAN_INT_CTRL(chan));
842 ret = CORE_IRQ_MTL_RX_OVERFLOW;
849 static int dwmac4_irq_status(struct mac_device_info *hw,
850 struct stmmac_extra_stats *x)
852 void __iomem *ioaddr = hw->pcsr;
853 u32 intr_status = readl(ioaddr + GMAC_INT_STATUS);
854 u32 intr_enable = readl(ioaddr + GMAC_INT_EN);
857 /* Discard disabled bits */
858 intr_status &= intr_enable;
860 /* Not used events (e.g. MMC interrupts) are not handled. */
861 if ((intr_status & mmc_tx_irq))
863 if (unlikely(intr_status & mmc_rx_irq))
865 if (unlikely(intr_status & mmc_rx_csum_offload_irq))
866 x->mmc_rx_csum_offload_irq_n++;
867 /* Clear the PMT bits 5 and 6 by reading the PMT status reg */
868 if (unlikely(intr_status & pmt_irq)) {
869 readl(ioaddr + GMAC_PMT);
870 x->irq_receive_pmt_irq_n++;
873 /* MAC tx/rx EEE LPI entry/exit interrupts */
874 if (intr_status & lpi_irq) {
875 /* Clear LPI interrupt by reading MAC_LPI_Control_Status */
876 u32 status = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
878 if (status & GMAC4_LPI_CTRL_STATUS_TLPIEN) {
879 ret |= CORE_IRQ_TX_PATH_IN_LPI_MODE;
880 x->irq_tx_path_in_lpi_mode_n++;
882 if (status & GMAC4_LPI_CTRL_STATUS_TLPIEX) {
883 ret |= CORE_IRQ_TX_PATH_EXIT_LPI_MODE;
884 x->irq_tx_path_exit_lpi_mode_n++;
886 if (status & GMAC4_LPI_CTRL_STATUS_RLPIEN)
887 x->irq_rx_path_in_lpi_mode_n++;
888 if (status & GMAC4_LPI_CTRL_STATUS_RLPIEX)
889 x->irq_rx_path_exit_lpi_mode_n++;
892 dwmac_pcs_isr(ioaddr, GMAC_PCS_BASE, intr_status, x);
893 if (intr_status & PCS_RGSMIIIS_IRQ)
894 dwmac4_phystatus(ioaddr, x);
899 static void dwmac4_debug(void __iomem *ioaddr, struct stmmac_extra_stats *x,
900 u32 rx_queues, u32 tx_queues)
905 for (queue = 0; queue < tx_queues; queue++) {
906 value = readl(ioaddr + MTL_CHAN_TX_DEBUG(queue));
908 if (value & MTL_DEBUG_TXSTSFSTS)
909 x->mtl_tx_status_fifo_full++;
910 if (value & MTL_DEBUG_TXFSTS)
911 x->mtl_tx_fifo_not_empty++;
912 if (value & MTL_DEBUG_TWCSTS)
914 if (value & MTL_DEBUG_TRCSTS_MASK) {
915 u32 trcsts = (value & MTL_DEBUG_TRCSTS_MASK)
916 >> MTL_DEBUG_TRCSTS_SHIFT;
917 if (trcsts == MTL_DEBUG_TRCSTS_WRITE)
918 x->mtl_tx_fifo_read_ctrl_write++;
919 else if (trcsts == MTL_DEBUG_TRCSTS_TXW)
920 x->mtl_tx_fifo_read_ctrl_wait++;
921 else if (trcsts == MTL_DEBUG_TRCSTS_READ)
922 x->mtl_tx_fifo_read_ctrl_read++;
924 x->mtl_tx_fifo_read_ctrl_idle++;
926 if (value & MTL_DEBUG_TXPAUSED)
927 x->mac_tx_in_pause++;
930 for (queue = 0; queue < rx_queues; queue++) {
931 value = readl(ioaddr + MTL_CHAN_RX_DEBUG(queue));
933 if (value & MTL_DEBUG_RXFSTS_MASK) {
934 u32 rxfsts = (value & MTL_DEBUG_RXFSTS_MASK)
935 >> MTL_DEBUG_RRCSTS_SHIFT;
937 if (rxfsts == MTL_DEBUG_RXFSTS_FULL)
938 x->mtl_rx_fifo_fill_level_full++;
939 else if (rxfsts == MTL_DEBUG_RXFSTS_AT)
940 x->mtl_rx_fifo_fill_above_thresh++;
941 else if (rxfsts == MTL_DEBUG_RXFSTS_BT)
942 x->mtl_rx_fifo_fill_below_thresh++;
944 x->mtl_rx_fifo_fill_level_empty++;
946 if (value & MTL_DEBUG_RRCSTS_MASK) {
947 u32 rrcsts = (value & MTL_DEBUG_RRCSTS_MASK) >>
948 MTL_DEBUG_RRCSTS_SHIFT;
950 if (rrcsts == MTL_DEBUG_RRCSTS_FLUSH)
951 x->mtl_rx_fifo_read_ctrl_flush++;
952 else if (rrcsts == MTL_DEBUG_RRCSTS_RSTAT)
953 x->mtl_rx_fifo_read_ctrl_read_data++;
954 else if (rrcsts == MTL_DEBUG_RRCSTS_RDATA)
955 x->mtl_rx_fifo_read_ctrl_status++;
957 x->mtl_rx_fifo_read_ctrl_idle++;
959 if (value & MTL_DEBUG_RWCSTS)
960 x->mtl_rx_fifo_ctrl_active++;
964 value = readl(ioaddr + GMAC_DEBUG);
966 if (value & GMAC_DEBUG_TFCSTS_MASK) {
967 u32 tfcsts = (value & GMAC_DEBUG_TFCSTS_MASK)
968 >> GMAC_DEBUG_TFCSTS_SHIFT;
970 if (tfcsts == GMAC_DEBUG_TFCSTS_XFER)
971 x->mac_tx_frame_ctrl_xfer++;
972 else if (tfcsts == GMAC_DEBUG_TFCSTS_GEN_PAUSE)
973 x->mac_tx_frame_ctrl_pause++;
974 else if (tfcsts == GMAC_DEBUG_TFCSTS_WAIT)
975 x->mac_tx_frame_ctrl_wait++;
977 x->mac_tx_frame_ctrl_idle++;
979 if (value & GMAC_DEBUG_TPESTS)
980 x->mac_gmii_tx_proto_engine++;
981 if (value & GMAC_DEBUG_RFCFCSTS_MASK)
982 x->mac_rx_frame_ctrl_fifo = (value & GMAC_DEBUG_RFCFCSTS_MASK)
983 >> GMAC_DEBUG_RFCFCSTS_SHIFT;
984 if (value & GMAC_DEBUG_RPESTS)
985 x->mac_gmii_rx_proto_engine++;
988 static void dwmac4_set_mac_loopback(void __iomem *ioaddr, bool enable)
990 u32 value = readl(ioaddr + GMAC_CONFIG);
993 value |= GMAC_CONFIG_LM;
995 value &= ~GMAC_CONFIG_LM;
997 writel(value, ioaddr + GMAC_CONFIG);
1000 static void dwmac4_update_vlan_hash(struct mac_device_info *hw, u32 hash,
1001 __le16 perfect_match, bool is_double)
1003 void __iomem *ioaddr = hw->pcsr;
1006 writel(hash, ioaddr + GMAC_VLAN_HASH_TABLE);
1008 value = readl(ioaddr + GMAC_VLAN_TAG);
1011 value |= GMAC_VLAN_VTHM | GMAC_VLAN_ETV;
1013 value |= GMAC_VLAN_EDVLP;
1014 value |= GMAC_VLAN_ESVL;
1015 value |= GMAC_VLAN_DOVLTC;
1018 writel(value, ioaddr + GMAC_VLAN_TAG);
1019 } else if (perfect_match) {
1020 u32 value = GMAC_VLAN_ETV;
1023 value |= GMAC_VLAN_EDVLP;
1024 value |= GMAC_VLAN_ESVL;
1025 value |= GMAC_VLAN_DOVLTC;
1028 writel(value | perfect_match, ioaddr + GMAC_VLAN_TAG);
1030 value &= ~(GMAC_VLAN_VTHM | GMAC_VLAN_ETV);
1031 value &= ~(GMAC_VLAN_EDVLP | GMAC_VLAN_ESVL);
1032 value &= ~GMAC_VLAN_DOVLTC;
1033 value &= ~GMAC_VLAN_VID;
1035 writel(value, ioaddr + GMAC_VLAN_TAG);
1039 static void dwmac4_sarc_configure(void __iomem *ioaddr, int val)
1041 u32 value = readl(ioaddr + GMAC_CONFIG);
1043 value &= ~GMAC_CONFIG_SARC;
1044 value |= val << GMAC_CONFIG_SARC_SHIFT;
1046 writel(value, ioaddr + GMAC_CONFIG);
1049 static void dwmac4_enable_vlan(struct mac_device_info *hw, u32 type)
1051 void __iomem *ioaddr = hw->pcsr;
1054 value = readl(ioaddr + GMAC_VLAN_INCL);
1055 value |= GMAC_VLAN_VLTI;
1056 value |= GMAC_VLAN_CSVL; /* Only use SVLAN */
1057 value &= ~GMAC_VLAN_VLC;
1058 value |= (type << GMAC_VLAN_VLC_SHIFT) & GMAC_VLAN_VLC;
1059 writel(value, ioaddr + GMAC_VLAN_INCL);
1062 static void dwmac4_set_arp_offload(struct mac_device_info *hw, bool en,
1065 void __iomem *ioaddr = hw->pcsr;
1068 writel(addr, ioaddr + GMAC_ARP_ADDR);
1070 value = readl(ioaddr + GMAC_CONFIG);
1072 value |= GMAC_CONFIG_ARPEN;
1074 value &= ~GMAC_CONFIG_ARPEN;
1075 writel(value, ioaddr + GMAC_CONFIG);
1078 static int dwmac4_config_l3_filter(struct mac_device_info *hw, u32 filter_no,
1079 bool en, bool ipv6, bool sa, bool inv,
1082 void __iomem *ioaddr = hw->pcsr;
1085 value = readl(ioaddr + GMAC_PACKET_FILTER);
1086 value |= GMAC_PACKET_FILTER_IPFE;
1087 writel(value, ioaddr + GMAC_PACKET_FILTER);
1089 value = readl(ioaddr + GMAC_L3L4_CTRL(filter_no));
1091 /* For IPv6 not both SA/DA filters can be active */
1093 value |= GMAC_L3PEN0;
1094 value &= ~(GMAC_L3SAM0 | GMAC_L3SAIM0);
1095 value &= ~(GMAC_L3DAM0 | GMAC_L3DAIM0);
1097 value |= GMAC_L3SAM0;
1099 value |= GMAC_L3SAIM0;
1101 value |= GMAC_L3DAM0;
1103 value |= GMAC_L3DAIM0;
1106 value &= ~GMAC_L3PEN0;
1108 value |= GMAC_L3SAM0;
1110 value |= GMAC_L3SAIM0;
1112 value |= GMAC_L3DAM0;
1114 value |= GMAC_L3DAIM0;
1118 writel(value, ioaddr + GMAC_L3L4_CTRL(filter_no));
1121 writel(match, ioaddr + GMAC_L3_ADDR0(filter_no));
1123 writel(match, ioaddr + GMAC_L3_ADDR1(filter_no));
1127 writel(0, ioaddr + GMAC_L3L4_CTRL(filter_no));
1132 static int dwmac4_config_l4_filter(struct mac_device_info *hw, u32 filter_no,
1133 bool en, bool udp, bool sa, bool inv,
1136 void __iomem *ioaddr = hw->pcsr;
1139 value = readl(ioaddr + GMAC_PACKET_FILTER);
1140 value |= GMAC_PACKET_FILTER_IPFE;
1141 writel(value, ioaddr + GMAC_PACKET_FILTER);
1143 value = readl(ioaddr + GMAC_L3L4_CTRL(filter_no));
1145 value |= GMAC_L4PEN0;
1147 value &= ~GMAC_L4PEN0;
1150 value &= ~(GMAC_L4SPM0 | GMAC_L4SPIM0);
1151 value &= ~(GMAC_L4DPM0 | GMAC_L4DPIM0);
1153 value |= GMAC_L4SPM0;
1155 value |= GMAC_L4SPIM0;
1157 value |= GMAC_L4DPM0;
1159 value |= GMAC_L4DPIM0;
1162 writel(value, ioaddr + GMAC_L3L4_CTRL(filter_no));
1165 value = match & GMAC_L4SP0;
1167 value = (match << GMAC_L4DP0_SHIFT) & GMAC_L4DP0;
1170 writel(value, ioaddr + GMAC_L4_ADDR(filter_no));
1173 writel(0, ioaddr + GMAC_L3L4_CTRL(filter_no));
1178 const struct stmmac_ops dwmac4_ops = {
1179 .core_init = dwmac4_core_init,
1180 .set_mac = stmmac_set_mac,
1181 .rx_ipc = dwmac4_rx_ipc_enable,
1182 .rx_queue_enable = dwmac4_rx_queue_enable,
1183 .rx_queue_prio = dwmac4_rx_queue_priority,
1184 .tx_queue_prio = dwmac4_tx_queue_priority,
1185 .rx_queue_routing = dwmac4_rx_queue_routing,
1186 .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
1187 .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
1188 .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
1189 .map_mtl_to_dma = dwmac4_map_mtl_dma,
1190 .config_cbs = dwmac4_config_cbs,
1191 .dump_regs = dwmac4_dump_regs,
1192 .host_irq_status = dwmac4_irq_status,
1193 .host_mtl_irq_status = dwmac4_irq_mtl_status,
1194 .flow_ctrl = dwmac4_flow_ctrl,
1196 .set_umac_addr = dwmac4_set_umac_addr,
1197 .get_umac_addr = dwmac4_get_umac_addr,
1198 .set_eee_mode = dwmac4_set_eee_mode,
1199 .reset_eee_mode = dwmac4_reset_eee_mode,
1200 .set_eee_lpi_entry_timer = dwmac4_set_eee_lpi_entry_timer,
1201 .set_eee_timer = dwmac4_set_eee_timer,
1202 .set_eee_pls = dwmac4_set_eee_pls,
1203 .pcs_ctrl_ane = dwmac4_ctrl_ane,
1204 .pcs_rane = dwmac4_rane,
1205 .pcs_get_adv_lp = dwmac4_get_adv_lp,
1206 .debug = dwmac4_debug,
1207 .set_filter = dwmac4_set_filter,
1208 .set_mac_loopback = dwmac4_set_mac_loopback,
1209 .update_vlan_hash = dwmac4_update_vlan_hash,
1210 .sarc_configure = dwmac4_sarc_configure,
1211 .enable_vlan = dwmac4_enable_vlan,
1212 .set_arp_offload = dwmac4_set_arp_offload,
1213 .config_l3_filter = dwmac4_config_l3_filter,
1214 .config_l4_filter = dwmac4_config_l4_filter,
1215 .add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
1216 .del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
1217 .restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
1220 const struct stmmac_ops dwmac410_ops = {
1221 .core_init = dwmac4_core_init,
1222 .set_mac = stmmac_dwmac4_set_mac,
1223 .rx_ipc = dwmac4_rx_ipc_enable,
1224 .rx_queue_enable = dwmac4_rx_queue_enable,
1225 .rx_queue_prio = dwmac4_rx_queue_priority,
1226 .tx_queue_prio = dwmac4_tx_queue_priority,
1227 .rx_queue_routing = dwmac4_rx_queue_routing,
1228 .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
1229 .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
1230 .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
1231 .map_mtl_to_dma = dwmac4_map_mtl_dma,
1232 .config_cbs = dwmac4_config_cbs,
1233 .dump_regs = dwmac4_dump_regs,
1234 .host_irq_status = dwmac4_irq_status,
1235 .host_mtl_irq_status = dwmac4_irq_mtl_status,
1236 .flow_ctrl = dwmac4_flow_ctrl,
1238 .set_umac_addr = dwmac4_set_umac_addr,
1239 .get_umac_addr = dwmac4_get_umac_addr,
1240 .set_eee_mode = dwmac4_set_eee_mode,
1241 .reset_eee_mode = dwmac4_reset_eee_mode,
1242 .set_eee_lpi_entry_timer = dwmac4_set_eee_lpi_entry_timer,
1243 .set_eee_timer = dwmac4_set_eee_timer,
1244 .set_eee_pls = dwmac4_set_eee_pls,
1245 .pcs_ctrl_ane = dwmac4_ctrl_ane,
1246 .pcs_rane = dwmac4_rane,
1247 .pcs_get_adv_lp = dwmac4_get_adv_lp,
1248 .debug = dwmac4_debug,
1249 .set_filter = dwmac4_set_filter,
1250 .flex_pps_config = dwmac5_flex_pps_config,
1251 .set_mac_loopback = dwmac4_set_mac_loopback,
1252 .update_vlan_hash = dwmac4_update_vlan_hash,
1253 .sarc_configure = dwmac4_sarc_configure,
1254 .enable_vlan = dwmac4_enable_vlan,
1255 .set_arp_offload = dwmac4_set_arp_offload,
1256 .config_l3_filter = dwmac4_config_l3_filter,
1257 .config_l4_filter = dwmac4_config_l4_filter,
1258 .est_configure = dwmac5_est_configure,
1259 .est_irq_status = dwmac5_est_irq_status,
1260 .fpe_configure = dwmac5_fpe_configure,
1261 .fpe_send_mpacket = dwmac5_fpe_send_mpacket,
1262 .fpe_irq_status = dwmac5_fpe_irq_status,
1263 .add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
1264 .del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
1265 .restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
1268 const struct stmmac_ops dwmac510_ops = {
1269 .core_init = dwmac4_core_init,
1270 .set_mac = stmmac_dwmac4_set_mac,
1271 .rx_ipc = dwmac4_rx_ipc_enable,
1272 .rx_queue_enable = dwmac4_rx_queue_enable,
1273 .rx_queue_prio = dwmac4_rx_queue_priority,
1274 .tx_queue_prio = dwmac4_tx_queue_priority,
1275 .rx_queue_routing = dwmac4_rx_queue_routing,
1276 .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
1277 .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
1278 .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
1279 .map_mtl_to_dma = dwmac4_map_mtl_dma,
1280 .config_cbs = dwmac4_config_cbs,
1281 .dump_regs = dwmac4_dump_regs,
1282 .host_irq_status = dwmac4_irq_status,
1283 .host_mtl_irq_status = dwmac4_irq_mtl_status,
1284 .flow_ctrl = dwmac4_flow_ctrl,
1286 .set_umac_addr = dwmac4_set_umac_addr,
1287 .get_umac_addr = dwmac4_get_umac_addr,
1288 .set_eee_mode = dwmac4_set_eee_mode,
1289 .reset_eee_mode = dwmac4_reset_eee_mode,
1290 .set_eee_lpi_entry_timer = dwmac4_set_eee_lpi_entry_timer,
1291 .set_eee_timer = dwmac4_set_eee_timer,
1292 .set_eee_pls = dwmac4_set_eee_pls,
1293 .pcs_ctrl_ane = dwmac4_ctrl_ane,
1294 .pcs_rane = dwmac4_rane,
1295 .pcs_get_adv_lp = dwmac4_get_adv_lp,
1296 .debug = dwmac4_debug,
1297 .set_filter = dwmac4_set_filter,
1298 .safety_feat_config = dwmac5_safety_feat_config,
1299 .safety_feat_irq_status = dwmac5_safety_feat_irq_status,
1300 .safety_feat_dump = dwmac5_safety_feat_dump,
1301 .rxp_config = dwmac5_rxp_config,
1302 .flex_pps_config = dwmac5_flex_pps_config,
1303 .set_mac_loopback = dwmac4_set_mac_loopback,
1304 .update_vlan_hash = dwmac4_update_vlan_hash,
1305 .sarc_configure = dwmac4_sarc_configure,
1306 .enable_vlan = dwmac4_enable_vlan,
1307 .set_arp_offload = dwmac4_set_arp_offload,
1308 .config_l3_filter = dwmac4_config_l3_filter,
1309 .config_l4_filter = dwmac4_config_l4_filter,
1310 .est_configure = dwmac5_est_configure,
1311 .est_irq_status = dwmac5_est_irq_status,
1312 .fpe_configure = dwmac5_fpe_configure,
1313 .fpe_send_mpacket = dwmac5_fpe_send_mpacket,
1314 .fpe_irq_status = dwmac5_fpe_irq_status,
1315 .add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
1316 .del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
1317 .restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
1320 static u32 dwmac4_get_num_vlan(void __iomem *ioaddr)
1324 val = readl(ioaddr + GMAC_HW_FEATURE3);
1325 switch (val & GMAC_HW_FEAT_NRVF) {
1351 int dwmac4_setup(struct stmmac_priv *priv)
1353 struct mac_device_info *mac = priv->hw;
1355 dev_info(priv->device, "\tDWMAC4/5\n");
1357 priv->dev->priv_flags |= IFF_UNICAST_FLT;
1358 mac->pcsr = priv->ioaddr;
1359 mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
1360 mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
1361 mac->mcast_bits_log2 = 0;
1363 if (mac->multicast_filter_bins)
1364 mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
1366 mac->link.duplex = GMAC_CONFIG_DM;
1367 mac->link.speed10 = GMAC_CONFIG_PS;
1368 mac->link.speed100 = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
1369 mac->link.speed1000 = 0;
1370 mac->link.speed2500 = GMAC_CONFIG_FES;
1371 mac->link.speed_mask = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
1372 mac->mii.addr = GMAC_MDIO_ADDR;
1373 mac->mii.data = GMAC_MDIO_DATA;
1374 mac->mii.addr_shift = 21;
1375 mac->mii.addr_mask = GENMASK(25, 21);
1376 mac->mii.reg_shift = 16;
1377 mac->mii.reg_mask = GENMASK(20, 16);
1378 mac->mii.clk_csr_shift = 8;
1379 mac->mii.clk_csr_mask = GENMASK(11, 8);
1380 mac->num_vlan = dwmac4_get_num_vlan(priv->ioaddr);