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 void __iomem *ioaddr = hw->pcsr;
27 u32 value = readl(ioaddr + GMAC_CONFIG);
29 value |= GMAC_CORE_INIT;
32 value |= GMAC_CONFIG_TE;
34 value &= hw->link.speed_mask;
37 value |= hw->link.speed1000;
40 value |= hw->link.speed100;
43 value |= hw->link.speed10;
48 writel(value, ioaddr + GMAC_CONFIG);
50 /* Enable GMAC interrupts */
51 value = GMAC_INT_DEFAULT_ENABLE;
54 value |= GMAC_PCS_IRQ_DEFAULT;
56 /* Enable FPE interrupt */
57 if ((GMAC_HW_FEAT_FPESEL & readl(ioaddr + GMAC_HW_FEATURE3)) >> 26)
58 value |= GMAC_INT_FPE_EN;
60 writel(value, ioaddr + GMAC_INT_EN);
63 static void dwmac4_rx_queue_enable(struct mac_device_info *hw,
66 void __iomem *ioaddr = hw->pcsr;
67 u32 value = readl(ioaddr + GMAC_RXQ_CTRL0);
69 value &= GMAC_RX_QUEUE_CLEAR(queue);
70 if (mode == MTL_QUEUE_AVB)
71 value |= GMAC_RX_AV_QUEUE_ENABLE(queue);
72 else if (mode == MTL_QUEUE_DCB)
73 value |= GMAC_RX_DCB_QUEUE_ENABLE(queue);
75 writel(value, ioaddr + GMAC_RXQ_CTRL0);
78 static void dwmac4_rx_queue_priority(struct mac_device_info *hw,
81 void __iomem *ioaddr = hw->pcsr;
85 base_register = (queue < 4) ? GMAC_RXQ_CTRL2 : GMAC_RXQ_CTRL3;
89 value = readl(ioaddr + base_register);
91 value &= ~GMAC_RXQCTRL_PSRQX_MASK(queue);
92 value |= (prio << GMAC_RXQCTRL_PSRQX_SHIFT(queue)) &
93 GMAC_RXQCTRL_PSRQX_MASK(queue);
94 writel(value, ioaddr + base_register);
97 static void dwmac4_tx_queue_priority(struct mac_device_info *hw,
100 void __iomem *ioaddr = hw->pcsr;
104 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_rx_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;
195 writel(value, ioaddr + MTL_OPERATION_MODE);
198 static void dwmac4_set_mtl_tx_queue_weight(struct mac_device_info *hw,
199 u32 weight, u32 queue)
201 void __iomem *ioaddr = hw->pcsr;
202 u32 value = readl(ioaddr + MTL_TXQX_WEIGHT_BASE_ADDR(queue));
204 value &= ~MTL_TXQ_WEIGHT_ISCQW_MASK;
205 value |= weight & MTL_TXQ_WEIGHT_ISCQW_MASK;
206 writel(value, ioaddr + MTL_TXQX_WEIGHT_BASE_ADDR(queue));
209 static void dwmac4_map_mtl_dma(struct mac_device_info *hw, u32 queue, u32 chan)
211 void __iomem *ioaddr = hw->pcsr;
215 value = readl(ioaddr + MTL_RXQ_DMA_MAP0);
217 value = readl(ioaddr + MTL_RXQ_DMA_MAP1);
219 if (queue == 0 || queue == 4) {
220 value &= ~MTL_RXQ_DMA_Q04MDMACH_MASK;
221 value |= MTL_RXQ_DMA_Q04MDMACH(chan);
223 value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue);
224 value |= MTL_RXQ_DMA_QXMDMACH(chan, queue);
228 writel(value, ioaddr + MTL_RXQ_DMA_MAP0);
230 writel(value, ioaddr + MTL_RXQ_DMA_MAP1);
233 static void dwmac4_config_cbs(struct mac_device_info *hw,
234 u32 send_slope, u32 idle_slope,
235 u32 high_credit, u32 low_credit, u32 queue)
237 void __iomem *ioaddr = hw->pcsr;
240 pr_debug("Queue %d configured as AVB. Parameters:\n", queue);
241 pr_debug("\tsend_slope: 0x%08x\n", send_slope);
242 pr_debug("\tidle_slope: 0x%08x\n", idle_slope);
243 pr_debug("\thigh_credit: 0x%08x\n", high_credit);
244 pr_debug("\tlow_credit: 0x%08x\n", low_credit);
246 /* enable AV algorithm */
247 value = readl(ioaddr + MTL_ETSX_CTRL_BASE_ADDR(queue));
248 value |= MTL_ETS_CTRL_AVALG;
249 value |= MTL_ETS_CTRL_CC;
250 writel(value, ioaddr + MTL_ETSX_CTRL_BASE_ADDR(queue));
252 /* configure send slope */
253 value = readl(ioaddr + MTL_SEND_SLP_CREDX_BASE_ADDR(queue));
254 value &= ~MTL_SEND_SLP_CRED_SSC_MASK;
255 value |= send_slope & MTL_SEND_SLP_CRED_SSC_MASK;
256 writel(value, ioaddr + MTL_SEND_SLP_CREDX_BASE_ADDR(queue));
258 /* configure idle slope (same register as tx weight) */
259 dwmac4_set_mtl_tx_queue_weight(hw, idle_slope, queue);
261 /* configure high credit */
262 value = readl(ioaddr + MTL_HIGH_CREDX_BASE_ADDR(queue));
263 value &= ~MTL_HIGH_CRED_HC_MASK;
264 value |= high_credit & MTL_HIGH_CRED_HC_MASK;
265 writel(value, ioaddr + MTL_HIGH_CREDX_BASE_ADDR(queue));
267 /* configure high credit */
268 value = readl(ioaddr + MTL_LOW_CREDX_BASE_ADDR(queue));
269 value &= ~MTL_HIGH_CRED_LC_MASK;
270 value |= low_credit & MTL_HIGH_CRED_LC_MASK;
271 writel(value, ioaddr + MTL_LOW_CREDX_BASE_ADDR(queue));
274 static void dwmac4_dump_regs(struct mac_device_info *hw, u32 *reg_space)
276 void __iomem *ioaddr = hw->pcsr;
279 for (i = 0; i < GMAC_REG_NUM; i++)
280 reg_space[i] = readl(ioaddr + i * 4);
283 static int dwmac4_rx_ipc_enable(struct mac_device_info *hw)
285 void __iomem *ioaddr = hw->pcsr;
286 u32 value = readl(ioaddr + GMAC_CONFIG);
289 value |= GMAC_CONFIG_IPC;
291 value &= ~GMAC_CONFIG_IPC;
293 writel(value, ioaddr + GMAC_CONFIG);
295 value = readl(ioaddr + GMAC_CONFIG);
297 return !!(value & GMAC_CONFIG_IPC);
300 static void dwmac4_pmt(struct mac_device_info *hw, unsigned long mode)
302 void __iomem *ioaddr = hw->pcsr;
303 unsigned int pmt = 0;
306 if (mode & WAKE_MAGIC) {
307 pr_debug("GMAC: WOL Magic frame\n");
308 pmt |= power_down | magic_pkt_en;
310 if (mode & WAKE_UCAST) {
311 pr_debug("GMAC: WOL on global unicast\n");
312 pmt |= power_down | global_unicast | wake_up_frame_en;
316 /* The receiver must be enabled for WOL before powering down */
317 config = readl(ioaddr + GMAC_CONFIG);
318 config |= GMAC_CONFIG_RE;
319 writel(config, ioaddr + GMAC_CONFIG);
321 writel(pmt, ioaddr + GMAC_PMT);
324 static void dwmac4_set_umac_addr(struct mac_device_info *hw,
325 unsigned char *addr, unsigned int reg_n)
327 void __iomem *ioaddr = hw->pcsr;
329 stmmac_dwmac4_set_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n),
330 GMAC_ADDR_LOW(reg_n));
333 static void dwmac4_get_umac_addr(struct mac_device_info *hw,
334 unsigned char *addr, unsigned int reg_n)
336 void __iomem *ioaddr = hw->pcsr;
338 stmmac_dwmac4_get_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n),
339 GMAC_ADDR_LOW(reg_n));
342 static void dwmac4_set_eee_mode(struct mac_device_info *hw,
343 bool en_tx_lpi_clockgating)
345 void __iomem *ioaddr = hw->pcsr;
348 /* Enable the link status receive on RGMII, SGMII ore SMII
349 * receive path and instruct the transmit to enter in LPI
352 value = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
353 value |= GMAC4_LPI_CTRL_STATUS_LPIEN | GMAC4_LPI_CTRL_STATUS_LPITXA;
355 if (en_tx_lpi_clockgating)
356 value |= GMAC4_LPI_CTRL_STATUS_LPITCSE;
358 writel(value, ioaddr + GMAC4_LPI_CTRL_STATUS);
361 static void dwmac4_reset_eee_mode(struct mac_device_info *hw)
363 void __iomem *ioaddr = hw->pcsr;
366 value = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
367 value &= ~(GMAC4_LPI_CTRL_STATUS_LPIEN | GMAC4_LPI_CTRL_STATUS_LPITXA);
368 writel(value, ioaddr + GMAC4_LPI_CTRL_STATUS);
371 static void dwmac4_set_eee_pls(struct mac_device_info *hw, int link)
373 void __iomem *ioaddr = hw->pcsr;
376 value = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
379 value |= GMAC4_LPI_CTRL_STATUS_PLS;
381 value &= ~GMAC4_LPI_CTRL_STATUS_PLS;
383 writel(value, ioaddr + GMAC4_LPI_CTRL_STATUS);
386 static void dwmac4_set_eee_lpi_entry_timer(struct mac_device_info *hw, int et)
388 void __iomem *ioaddr = hw->pcsr;
389 int value = et & STMMAC_ET_MAX;
392 /* Program LPI entry timer value into register */
393 writel(value, ioaddr + GMAC4_LPI_ENTRY_TIMER);
395 /* Enable/disable LPI entry timer */
396 regval = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
397 regval |= GMAC4_LPI_CTRL_STATUS_LPIEN | GMAC4_LPI_CTRL_STATUS_LPITXA;
400 regval |= GMAC4_LPI_CTRL_STATUS_LPIATE;
402 regval &= ~GMAC4_LPI_CTRL_STATUS_LPIATE;
404 writel(regval, ioaddr + GMAC4_LPI_CTRL_STATUS);
407 static void dwmac4_set_eee_timer(struct mac_device_info *hw, int ls, int tw)
409 void __iomem *ioaddr = hw->pcsr;
410 int value = ((tw & 0xffff)) | ((ls & 0x3ff) << 16);
412 /* Program the timers in the LPI timer control register:
413 * LS: minimum time (ms) for which the link
414 * status from PHY should be ok before transmitting
416 * TW: minimum time (us) for which the core waits
417 * after it has stopped transmitting the LPI pattern.
419 writel(value, ioaddr + GMAC4_LPI_TIMER_CTRL);
422 static void dwmac4_write_single_vlan(struct net_device *dev, u16 vid)
424 void __iomem *ioaddr = (void __iomem *)dev->base_addr;
427 val = readl(ioaddr + GMAC_VLAN_TAG);
428 val &= ~GMAC_VLAN_TAG_VID;
429 val |= GMAC_VLAN_TAG_ETV | vid;
431 writel(val, ioaddr + GMAC_VLAN_TAG);
434 static int dwmac4_write_vlan_filter(struct net_device *dev,
435 struct mac_device_info *hw,
438 void __iomem *ioaddr = (void __iomem *)dev->base_addr;
442 if (index >= hw->num_vlan)
445 writel(data, ioaddr + GMAC_VLAN_TAG_DATA);
447 val = readl(ioaddr + GMAC_VLAN_TAG);
448 val &= ~(GMAC_VLAN_TAG_CTRL_OFS_MASK |
449 GMAC_VLAN_TAG_CTRL_CT |
450 GMAC_VLAN_TAG_CTRL_OB);
451 val |= (index << GMAC_VLAN_TAG_CTRL_OFS_SHIFT) | GMAC_VLAN_TAG_CTRL_OB;
453 writel(val, ioaddr + GMAC_VLAN_TAG);
455 for (i = 0; i < timeout; i++) {
456 val = readl(ioaddr + GMAC_VLAN_TAG);
457 if (!(val & GMAC_VLAN_TAG_CTRL_OB))
462 netdev_err(dev, "Timeout accessing MAC_VLAN_Tag_Filter\n");
467 static int dwmac4_add_hw_vlan_rx_fltr(struct net_device *dev,
468 struct mac_device_info *hw,
469 __be16 proto, u16 vid)
480 "Adding VLAN in promisc mode not supported\n");
484 /* Single Rx VLAN Filter */
485 if (hw->num_vlan == 1) {
486 /* For single VLAN filter, VID 0 means VLAN promiscuous */
488 netdev_warn(dev, "Adding VLAN ID 0 is not supported\n");
492 if (hw->vlan_filter[0] & GMAC_VLAN_TAG_VID) {
493 netdev_err(dev, "Only single VLAN ID supported\n");
497 hw->vlan_filter[0] = vid;
498 dwmac4_write_single_vlan(dev, vid);
503 /* Extended Rx VLAN Filter Enable */
504 val |= GMAC_VLAN_TAG_DATA_ETV | GMAC_VLAN_TAG_DATA_VEN | vid;
506 for (i = 0; i < hw->num_vlan; i++) {
507 if (hw->vlan_filter[i] == val)
509 else if (!(hw->vlan_filter[i] & GMAC_VLAN_TAG_DATA_VEN))
514 netdev_err(dev, "MAC_VLAN_Tag_Filter full (size: %0u)\n",
519 ret = dwmac4_write_vlan_filter(dev, hw, index, val);
522 hw->vlan_filter[index] = val;
527 static int dwmac4_del_hw_vlan_rx_fltr(struct net_device *dev,
528 struct mac_device_info *hw,
529 __be16 proto, u16 vid)
535 "Deleting VLAN in promisc mode not supported\n");
539 /* Single Rx VLAN Filter */
540 if (hw->num_vlan == 1) {
541 if ((hw->vlan_filter[0] & GMAC_VLAN_TAG_VID) == vid) {
542 hw->vlan_filter[0] = 0;
543 dwmac4_write_single_vlan(dev, 0);
548 /* Extended Rx VLAN Filter Enable */
549 for (i = 0; i < hw->num_vlan; i++) {
550 if ((hw->vlan_filter[i] & GMAC_VLAN_TAG_DATA_VID) == vid) {
551 ret = dwmac4_write_vlan_filter(dev, hw, i, 0);
554 hw->vlan_filter[i] = 0;
563 static void dwmac4_vlan_promisc_enable(struct net_device *dev,
564 struct mac_device_info *hw)
566 void __iomem *ioaddr = hw->pcsr;
572 /* Single Rx VLAN Filter */
573 if (hw->num_vlan == 1) {
574 dwmac4_write_single_vlan(dev, 0);
578 /* Extended Rx VLAN Filter Enable */
579 for (i = 0; i < hw->num_vlan; i++) {
580 if (hw->vlan_filter[i] & GMAC_VLAN_TAG_DATA_VEN) {
581 val = hw->vlan_filter[i] & ~GMAC_VLAN_TAG_DATA_VEN;
582 dwmac4_write_vlan_filter(dev, hw, i, val);
586 hash = readl(ioaddr + GMAC_VLAN_HASH_TABLE);
587 if (hash & GMAC_VLAN_VLHT) {
588 value = readl(ioaddr + GMAC_VLAN_TAG);
589 if (value & GMAC_VLAN_VTHM) {
590 value &= ~GMAC_VLAN_VTHM;
591 writel(value, ioaddr + GMAC_VLAN_TAG);
596 static void dwmac4_restore_hw_vlan_rx_fltr(struct net_device *dev,
597 struct mac_device_info *hw)
599 void __iomem *ioaddr = hw->pcsr;
605 /* Single Rx VLAN Filter */
606 if (hw->num_vlan == 1) {
607 dwmac4_write_single_vlan(dev, hw->vlan_filter[0]);
611 /* Extended Rx VLAN Filter Enable */
612 for (i = 0; i < hw->num_vlan; i++) {
613 if (hw->vlan_filter[i] & GMAC_VLAN_TAG_DATA_VEN) {
614 val = hw->vlan_filter[i];
615 dwmac4_write_vlan_filter(dev, hw, i, val);
619 hash = readl(ioaddr + GMAC_VLAN_HASH_TABLE);
620 if (hash & GMAC_VLAN_VLHT) {
621 value = readl(ioaddr + GMAC_VLAN_TAG);
622 value |= GMAC_VLAN_VTHM;
623 writel(value, ioaddr + GMAC_VLAN_TAG);
627 static void dwmac4_set_filter(struct mac_device_info *hw,
628 struct net_device *dev)
630 void __iomem *ioaddr = (void __iomem *)dev->base_addr;
631 int numhashregs = (hw->multicast_filter_bins >> 5);
632 int mcbitslog2 = hw->mcast_bits_log2;
637 memset(mc_filter, 0, sizeof(mc_filter));
639 value = readl(ioaddr + GMAC_PACKET_FILTER);
640 value &= ~GMAC_PACKET_FILTER_HMC;
641 value &= ~GMAC_PACKET_FILTER_HPF;
642 value &= ~GMAC_PACKET_FILTER_PCF;
643 value &= ~GMAC_PACKET_FILTER_PM;
644 value &= ~GMAC_PACKET_FILTER_PR;
645 value &= ~GMAC_PACKET_FILTER_RA;
646 if (dev->flags & IFF_PROMISC) {
647 /* VLAN Tag Filter Fail Packets Queuing */
648 if (hw->vlan_fail_q_en) {
649 value = readl(ioaddr + GMAC_RXQ_CTRL4);
650 value &= ~GMAC_RXQCTRL_VFFQ_MASK;
651 value |= GMAC_RXQCTRL_VFFQE |
652 (hw->vlan_fail_q << GMAC_RXQCTRL_VFFQ_SHIFT);
653 writel(value, ioaddr + GMAC_RXQ_CTRL4);
654 value = GMAC_PACKET_FILTER_PR | GMAC_PACKET_FILTER_RA;
656 value = GMAC_PACKET_FILTER_PR | GMAC_PACKET_FILTER_PCF;
659 } else if ((dev->flags & IFF_ALLMULTI) ||
660 (netdev_mc_count(dev) > hw->multicast_filter_bins)) {
662 value |= GMAC_PACKET_FILTER_PM;
663 /* Set all the bits of the HASH tab */
664 memset(mc_filter, 0xff, sizeof(mc_filter));
665 } else if (!netdev_mc_empty(dev) && (dev->flags & IFF_MULTICAST)) {
666 struct netdev_hw_addr *ha;
668 /* Hash filter for multicast */
669 value |= GMAC_PACKET_FILTER_HMC;
671 netdev_for_each_mc_addr(ha, dev) {
672 /* The upper n bits of the calculated CRC are used to
673 * index the contents of the hash table. The number of
674 * bits used depends on the hardware configuration
675 * selected at core configuration time.
677 u32 bit_nr = bitrev32(~crc32_le(~0, ha->addr,
678 ETH_ALEN)) >> (32 - mcbitslog2);
679 /* The most significant bit determines the register to
680 * use (H/L) while the other 5 bits determine the bit
681 * within the register.
683 mc_filter[bit_nr >> 5] |= (1 << (bit_nr & 0x1f));
687 for (i = 0; i < numhashregs; i++)
688 writel(mc_filter[i], ioaddr + GMAC_HASH_TAB(i));
690 value |= GMAC_PACKET_FILTER_HPF;
692 /* Handle multiple unicast addresses */
693 if (netdev_uc_count(dev) > hw->unicast_filter_entries) {
694 /* Switch to promiscuous mode if more than 128 addrs
697 value |= GMAC_PACKET_FILTER_PR;
699 struct netdev_hw_addr *ha;
702 netdev_for_each_uc_addr(ha, dev) {
703 dwmac4_set_umac_addr(hw, ha->addr, reg);
707 while (reg < GMAC_MAX_PERFECT_ADDRESSES) {
708 writel(0, ioaddr + GMAC_ADDR_HIGH(reg));
709 writel(0, ioaddr + GMAC_ADDR_LOW(reg));
715 if (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
716 value |= GMAC_PACKET_FILTER_VTFE;
718 writel(value, ioaddr + GMAC_PACKET_FILTER);
720 if (dev->flags & IFF_PROMISC && !hw->vlan_fail_q_en) {
723 dwmac4_vlan_promisc_enable(dev, hw);
728 dwmac4_restore_hw_vlan_rx_fltr(dev, hw);
733 static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,
734 unsigned int fc, unsigned int pause_time,
737 void __iomem *ioaddr = hw->pcsr;
738 unsigned int flow = 0;
741 pr_debug("GMAC Flow-Control:\n");
743 pr_debug("\tReceive Flow-Control ON\n");
744 flow |= GMAC_RX_FLOW_CTRL_RFE;
746 writel(flow, ioaddr + GMAC_RX_FLOW_CTRL);
749 pr_debug("\tTransmit Flow-Control ON\n");
752 pr_debug("\tduplex mode: PAUSE %d\n", pause_time);
754 for (queue = 0; queue < tx_cnt; queue++) {
755 flow = GMAC_TX_FLOW_CTRL_TFE;
759 (pause_time << GMAC_TX_FLOW_CTRL_PT_SHIFT);
761 writel(flow, ioaddr + GMAC_QX_TX_FLOW_CTRL(queue));
764 for (queue = 0; queue < tx_cnt; queue++)
765 writel(0, ioaddr + GMAC_QX_TX_FLOW_CTRL(queue));
769 static void dwmac4_ctrl_ane(void __iomem *ioaddr, bool ane, bool srgmi_ral,
772 dwmac_ctrl_ane(ioaddr, GMAC_PCS_BASE, ane, srgmi_ral, loopback);
775 static void dwmac4_rane(void __iomem *ioaddr, bool restart)
777 dwmac_rane(ioaddr, GMAC_PCS_BASE, restart);
780 static void dwmac4_get_adv_lp(void __iomem *ioaddr, struct rgmii_adv *adv)
782 dwmac_get_adv_lp(ioaddr, GMAC_PCS_BASE, adv);
785 /* RGMII or SMII interface */
786 static void dwmac4_phystatus(void __iomem *ioaddr, struct stmmac_extra_stats *x)
790 status = readl(ioaddr + GMAC_PHYIF_CONTROL_STATUS);
793 /* Check the link status */
794 if (status & GMAC_PHYIF_CTRLSTATUS_LNKSTS) {
799 speed_value = ((status & GMAC_PHYIF_CTRLSTATUS_SPEED) >>
800 GMAC_PHYIF_CTRLSTATUS_SPEED_SHIFT);
801 if (speed_value == GMAC_PHYIF_CTRLSTATUS_SPEED_125)
802 x->pcs_speed = SPEED_1000;
803 else if (speed_value == GMAC_PHYIF_CTRLSTATUS_SPEED_25)
804 x->pcs_speed = SPEED_100;
806 x->pcs_speed = SPEED_10;
808 x->pcs_duplex = (status & GMAC_PHYIF_CTRLSTATUS_LNKMOD_MASK);
810 pr_info("Link is Up - %d/%s\n", (int)x->pcs_speed,
811 x->pcs_duplex ? "Full" : "Half");
814 pr_info("Link is Down\n");
818 static int dwmac4_irq_mtl_status(struct mac_device_info *hw, u32 chan)
820 void __iomem *ioaddr = hw->pcsr;
821 u32 mtl_int_qx_status;
824 mtl_int_qx_status = readl(ioaddr + MTL_INT_STATUS);
826 /* Check MTL Interrupt */
827 if (mtl_int_qx_status & MTL_INT_QX(chan)) {
828 /* read Queue x Interrupt status */
829 u32 status = readl(ioaddr + MTL_CHAN_INT_CTRL(chan));
831 if (status & MTL_RX_OVERFLOW_INT) {
832 /* clear Interrupt */
833 writel(status | MTL_RX_OVERFLOW_INT,
834 ioaddr + MTL_CHAN_INT_CTRL(chan));
835 ret = CORE_IRQ_MTL_RX_OVERFLOW;
842 static int dwmac4_irq_status(struct mac_device_info *hw,
843 struct stmmac_extra_stats *x)
845 void __iomem *ioaddr = hw->pcsr;
846 u32 intr_status = readl(ioaddr + GMAC_INT_STATUS);
847 u32 intr_enable = readl(ioaddr + GMAC_INT_EN);
850 /* Discard disabled bits */
851 intr_status &= intr_enable;
853 /* Not used events (e.g. MMC interrupts) are not handled. */
854 if ((intr_status & mmc_tx_irq))
856 if (unlikely(intr_status & mmc_rx_irq))
858 if (unlikely(intr_status & mmc_rx_csum_offload_irq))
859 x->mmc_rx_csum_offload_irq_n++;
860 /* Clear the PMT bits 5 and 6 by reading the PMT status reg */
861 if (unlikely(intr_status & pmt_irq)) {
862 readl(ioaddr + GMAC_PMT);
863 x->irq_receive_pmt_irq_n++;
866 /* MAC tx/rx EEE LPI entry/exit interrupts */
867 if (intr_status & lpi_irq) {
868 /* Clear LPI interrupt by reading MAC_LPI_Control_Status */
869 u32 status = readl(ioaddr + GMAC4_LPI_CTRL_STATUS);
871 if (status & GMAC4_LPI_CTRL_STATUS_TLPIEN) {
872 ret |= CORE_IRQ_TX_PATH_IN_LPI_MODE;
873 x->irq_tx_path_in_lpi_mode_n++;
875 if (status & GMAC4_LPI_CTRL_STATUS_TLPIEX) {
876 ret |= CORE_IRQ_TX_PATH_EXIT_LPI_MODE;
877 x->irq_tx_path_exit_lpi_mode_n++;
879 if (status & GMAC4_LPI_CTRL_STATUS_RLPIEN)
880 x->irq_rx_path_in_lpi_mode_n++;
881 if (status & GMAC4_LPI_CTRL_STATUS_RLPIEX)
882 x->irq_rx_path_exit_lpi_mode_n++;
885 dwmac_pcs_isr(ioaddr, GMAC_PCS_BASE, intr_status, x);
886 if (intr_status & PCS_RGSMIIIS_IRQ)
887 dwmac4_phystatus(ioaddr, x);
892 static void dwmac4_debug(void __iomem *ioaddr, struct stmmac_extra_stats *x,
893 u32 rx_queues, u32 tx_queues)
898 for (queue = 0; queue < tx_queues; queue++) {
899 value = readl(ioaddr + MTL_CHAN_TX_DEBUG(queue));
901 if (value & MTL_DEBUG_TXSTSFSTS)
902 x->mtl_tx_status_fifo_full++;
903 if (value & MTL_DEBUG_TXFSTS)
904 x->mtl_tx_fifo_not_empty++;
905 if (value & MTL_DEBUG_TWCSTS)
907 if (value & MTL_DEBUG_TRCSTS_MASK) {
908 u32 trcsts = (value & MTL_DEBUG_TRCSTS_MASK)
909 >> MTL_DEBUG_TRCSTS_SHIFT;
910 if (trcsts == MTL_DEBUG_TRCSTS_WRITE)
911 x->mtl_tx_fifo_read_ctrl_write++;
912 else if (trcsts == MTL_DEBUG_TRCSTS_TXW)
913 x->mtl_tx_fifo_read_ctrl_wait++;
914 else if (trcsts == MTL_DEBUG_TRCSTS_READ)
915 x->mtl_tx_fifo_read_ctrl_read++;
917 x->mtl_tx_fifo_read_ctrl_idle++;
919 if (value & MTL_DEBUG_TXPAUSED)
920 x->mac_tx_in_pause++;
923 for (queue = 0; queue < rx_queues; queue++) {
924 value = readl(ioaddr + MTL_CHAN_RX_DEBUG(queue));
926 if (value & MTL_DEBUG_RXFSTS_MASK) {
927 u32 rxfsts = (value & MTL_DEBUG_RXFSTS_MASK)
928 >> MTL_DEBUG_RRCSTS_SHIFT;
930 if (rxfsts == MTL_DEBUG_RXFSTS_FULL)
931 x->mtl_rx_fifo_fill_level_full++;
932 else if (rxfsts == MTL_DEBUG_RXFSTS_AT)
933 x->mtl_rx_fifo_fill_above_thresh++;
934 else if (rxfsts == MTL_DEBUG_RXFSTS_BT)
935 x->mtl_rx_fifo_fill_below_thresh++;
937 x->mtl_rx_fifo_fill_level_empty++;
939 if (value & MTL_DEBUG_RRCSTS_MASK) {
940 u32 rrcsts = (value & MTL_DEBUG_RRCSTS_MASK) >>
941 MTL_DEBUG_RRCSTS_SHIFT;
943 if (rrcsts == MTL_DEBUG_RRCSTS_FLUSH)
944 x->mtl_rx_fifo_read_ctrl_flush++;
945 else if (rrcsts == MTL_DEBUG_RRCSTS_RSTAT)
946 x->mtl_rx_fifo_read_ctrl_read_data++;
947 else if (rrcsts == MTL_DEBUG_RRCSTS_RDATA)
948 x->mtl_rx_fifo_read_ctrl_status++;
950 x->mtl_rx_fifo_read_ctrl_idle++;
952 if (value & MTL_DEBUG_RWCSTS)
953 x->mtl_rx_fifo_ctrl_active++;
957 value = readl(ioaddr + GMAC_DEBUG);
959 if (value & GMAC_DEBUG_TFCSTS_MASK) {
960 u32 tfcsts = (value & GMAC_DEBUG_TFCSTS_MASK)
961 >> GMAC_DEBUG_TFCSTS_SHIFT;
963 if (tfcsts == GMAC_DEBUG_TFCSTS_XFER)
964 x->mac_tx_frame_ctrl_xfer++;
965 else if (tfcsts == GMAC_DEBUG_TFCSTS_GEN_PAUSE)
966 x->mac_tx_frame_ctrl_pause++;
967 else if (tfcsts == GMAC_DEBUG_TFCSTS_WAIT)
968 x->mac_tx_frame_ctrl_wait++;
970 x->mac_tx_frame_ctrl_idle++;
972 if (value & GMAC_DEBUG_TPESTS)
973 x->mac_gmii_tx_proto_engine++;
974 if (value & GMAC_DEBUG_RFCFCSTS_MASK)
975 x->mac_rx_frame_ctrl_fifo = (value & GMAC_DEBUG_RFCFCSTS_MASK)
976 >> GMAC_DEBUG_RFCFCSTS_SHIFT;
977 if (value & GMAC_DEBUG_RPESTS)
978 x->mac_gmii_rx_proto_engine++;
981 static void dwmac4_set_mac_loopback(void __iomem *ioaddr, bool enable)
983 u32 value = readl(ioaddr + GMAC_CONFIG);
986 value |= GMAC_CONFIG_LM;
988 value &= ~GMAC_CONFIG_LM;
990 writel(value, ioaddr + GMAC_CONFIG);
993 static void dwmac4_update_vlan_hash(struct mac_device_info *hw, u32 hash,
994 __le16 perfect_match, bool is_double)
996 void __iomem *ioaddr = hw->pcsr;
999 writel(hash, ioaddr + GMAC_VLAN_HASH_TABLE);
1001 value = readl(ioaddr + GMAC_VLAN_TAG);
1004 value |= GMAC_VLAN_VTHM | GMAC_VLAN_ETV;
1006 value |= GMAC_VLAN_EDVLP;
1007 value |= GMAC_VLAN_ESVL;
1008 value |= GMAC_VLAN_DOVLTC;
1011 writel(value, ioaddr + GMAC_VLAN_TAG);
1012 } else if (perfect_match) {
1013 u32 value = GMAC_VLAN_ETV;
1016 value |= GMAC_VLAN_EDVLP;
1017 value |= GMAC_VLAN_ESVL;
1018 value |= GMAC_VLAN_DOVLTC;
1021 writel(value | perfect_match, ioaddr + GMAC_VLAN_TAG);
1023 value &= ~(GMAC_VLAN_VTHM | GMAC_VLAN_ETV);
1024 value &= ~(GMAC_VLAN_EDVLP | GMAC_VLAN_ESVL);
1025 value &= ~GMAC_VLAN_DOVLTC;
1026 value &= ~GMAC_VLAN_VID;
1028 writel(value, ioaddr + GMAC_VLAN_TAG);
1032 static void dwmac4_sarc_configure(void __iomem *ioaddr, int val)
1034 u32 value = readl(ioaddr + GMAC_CONFIG);
1036 value &= ~GMAC_CONFIG_SARC;
1037 value |= val << GMAC_CONFIG_SARC_SHIFT;
1039 writel(value, ioaddr + GMAC_CONFIG);
1042 static void dwmac4_enable_vlan(struct mac_device_info *hw, u32 type)
1044 void __iomem *ioaddr = hw->pcsr;
1047 value = readl(ioaddr + GMAC_VLAN_INCL);
1048 value |= GMAC_VLAN_VLTI;
1049 value |= GMAC_VLAN_CSVL; /* Only use SVLAN */
1050 value &= ~GMAC_VLAN_VLC;
1051 value |= (type << GMAC_VLAN_VLC_SHIFT) & GMAC_VLAN_VLC;
1052 writel(value, ioaddr + GMAC_VLAN_INCL);
1055 static void dwmac4_set_arp_offload(struct mac_device_info *hw, bool en,
1058 void __iomem *ioaddr = hw->pcsr;
1061 writel(addr, ioaddr + GMAC_ARP_ADDR);
1063 value = readl(ioaddr + GMAC_CONFIG);
1065 value |= GMAC_CONFIG_ARPEN;
1067 value &= ~GMAC_CONFIG_ARPEN;
1068 writel(value, ioaddr + GMAC_CONFIG);
1071 static int dwmac4_config_l3_filter(struct mac_device_info *hw, u32 filter_no,
1072 bool en, bool ipv6, bool sa, bool inv,
1075 void __iomem *ioaddr = hw->pcsr;
1078 value = readl(ioaddr + GMAC_PACKET_FILTER);
1079 value |= GMAC_PACKET_FILTER_IPFE;
1080 writel(value, ioaddr + GMAC_PACKET_FILTER);
1082 value = readl(ioaddr + GMAC_L3L4_CTRL(filter_no));
1084 /* For IPv6 not both SA/DA filters can be active */
1086 value |= GMAC_L3PEN0;
1087 value &= ~(GMAC_L3SAM0 | GMAC_L3SAIM0);
1088 value &= ~(GMAC_L3DAM0 | GMAC_L3DAIM0);
1090 value |= GMAC_L3SAM0;
1092 value |= GMAC_L3SAIM0;
1094 value |= GMAC_L3DAM0;
1096 value |= GMAC_L3DAIM0;
1099 value &= ~GMAC_L3PEN0;
1101 value |= GMAC_L3SAM0;
1103 value |= GMAC_L3SAIM0;
1105 value |= GMAC_L3DAM0;
1107 value |= GMAC_L3DAIM0;
1111 writel(value, ioaddr + GMAC_L3L4_CTRL(filter_no));
1114 writel(match, ioaddr + GMAC_L3_ADDR0(filter_no));
1116 writel(match, ioaddr + GMAC_L3_ADDR1(filter_no));
1120 writel(0, ioaddr + GMAC_L3L4_CTRL(filter_no));
1125 static int dwmac4_config_l4_filter(struct mac_device_info *hw, u32 filter_no,
1126 bool en, bool udp, bool sa, bool inv,
1129 void __iomem *ioaddr = hw->pcsr;
1132 value = readl(ioaddr + GMAC_PACKET_FILTER);
1133 value |= GMAC_PACKET_FILTER_IPFE;
1134 writel(value, ioaddr + GMAC_PACKET_FILTER);
1136 value = readl(ioaddr + GMAC_L3L4_CTRL(filter_no));
1138 value |= GMAC_L4PEN0;
1140 value &= ~GMAC_L4PEN0;
1143 value &= ~(GMAC_L4SPM0 | GMAC_L4SPIM0);
1144 value &= ~(GMAC_L4DPM0 | GMAC_L4DPIM0);
1146 value |= GMAC_L4SPM0;
1148 value |= GMAC_L4SPIM0;
1150 value |= GMAC_L4DPM0;
1152 value |= GMAC_L4DPIM0;
1155 writel(value, ioaddr + GMAC_L3L4_CTRL(filter_no));
1158 value = match & GMAC_L4SP0;
1160 value = (match << GMAC_L4DP0_SHIFT) & GMAC_L4DP0;
1163 writel(value, ioaddr + GMAC_L4_ADDR(filter_no));
1166 writel(0, ioaddr + GMAC_L3L4_CTRL(filter_no));
1171 const struct stmmac_ops dwmac4_ops = {
1172 .core_init = dwmac4_core_init,
1173 .set_mac = stmmac_set_mac,
1174 .rx_ipc = dwmac4_rx_ipc_enable,
1175 .rx_queue_enable = dwmac4_rx_queue_enable,
1176 .rx_queue_prio = dwmac4_rx_queue_priority,
1177 .tx_queue_prio = dwmac4_tx_queue_priority,
1178 .rx_queue_routing = dwmac4_rx_queue_routing,
1179 .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
1180 .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
1181 .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
1182 .map_mtl_to_dma = dwmac4_map_mtl_dma,
1183 .config_cbs = dwmac4_config_cbs,
1184 .dump_regs = dwmac4_dump_regs,
1185 .host_irq_status = dwmac4_irq_status,
1186 .host_mtl_irq_status = dwmac4_irq_mtl_status,
1187 .flow_ctrl = dwmac4_flow_ctrl,
1189 .set_umac_addr = dwmac4_set_umac_addr,
1190 .get_umac_addr = dwmac4_get_umac_addr,
1191 .set_eee_mode = dwmac4_set_eee_mode,
1192 .reset_eee_mode = dwmac4_reset_eee_mode,
1193 .set_eee_lpi_entry_timer = dwmac4_set_eee_lpi_entry_timer,
1194 .set_eee_timer = dwmac4_set_eee_timer,
1195 .set_eee_pls = dwmac4_set_eee_pls,
1196 .pcs_ctrl_ane = dwmac4_ctrl_ane,
1197 .pcs_rane = dwmac4_rane,
1198 .pcs_get_adv_lp = dwmac4_get_adv_lp,
1199 .debug = dwmac4_debug,
1200 .set_filter = dwmac4_set_filter,
1201 .set_mac_loopback = dwmac4_set_mac_loopback,
1202 .update_vlan_hash = dwmac4_update_vlan_hash,
1203 .sarc_configure = dwmac4_sarc_configure,
1204 .enable_vlan = dwmac4_enable_vlan,
1205 .set_arp_offload = dwmac4_set_arp_offload,
1206 .config_l3_filter = dwmac4_config_l3_filter,
1207 .config_l4_filter = dwmac4_config_l4_filter,
1208 .add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
1209 .del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
1210 .restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
1213 const struct stmmac_ops dwmac410_ops = {
1214 .core_init = dwmac4_core_init,
1215 .set_mac = stmmac_dwmac4_set_mac,
1216 .rx_ipc = dwmac4_rx_ipc_enable,
1217 .rx_queue_enable = dwmac4_rx_queue_enable,
1218 .rx_queue_prio = dwmac4_rx_queue_priority,
1219 .tx_queue_prio = dwmac4_tx_queue_priority,
1220 .rx_queue_routing = dwmac4_rx_queue_routing,
1221 .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
1222 .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
1223 .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
1224 .map_mtl_to_dma = dwmac4_map_mtl_dma,
1225 .config_cbs = dwmac4_config_cbs,
1226 .dump_regs = dwmac4_dump_regs,
1227 .host_irq_status = dwmac4_irq_status,
1228 .host_mtl_irq_status = dwmac4_irq_mtl_status,
1229 .flow_ctrl = dwmac4_flow_ctrl,
1231 .set_umac_addr = dwmac4_set_umac_addr,
1232 .get_umac_addr = dwmac4_get_umac_addr,
1233 .set_eee_mode = dwmac4_set_eee_mode,
1234 .reset_eee_mode = dwmac4_reset_eee_mode,
1235 .set_eee_lpi_entry_timer = dwmac4_set_eee_lpi_entry_timer,
1236 .set_eee_timer = dwmac4_set_eee_timer,
1237 .set_eee_pls = dwmac4_set_eee_pls,
1238 .pcs_ctrl_ane = dwmac4_ctrl_ane,
1239 .pcs_rane = dwmac4_rane,
1240 .pcs_get_adv_lp = dwmac4_get_adv_lp,
1241 .debug = dwmac4_debug,
1242 .set_filter = dwmac4_set_filter,
1243 .flex_pps_config = dwmac5_flex_pps_config,
1244 .set_mac_loopback = dwmac4_set_mac_loopback,
1245 .update_vlan_hash = dwmac4_update_vlan_hash,
1246 .sarc_configure = dwmac4_sarc_configure,
1247 .enable_vlan = dwmac4_enable_vlan,
1248 .set_arp_offload = dwmac4_set_arp_offload,
1249 .config_l3_filter = dwmac4_config_l3_filter,
1250 .config_l4_filter = dwmac4_config_l4_filter,
1251 .est_configure = dwmac5_est_configure,
1252 .est_irq_status = dwmac5_est_irq_status,
1253 .fpe_configure = dwmac5_fpe_configure,
1254 .fpe_send_mpacket = dwmac5_fpe_send_mpacket,
1255 .fpe_irq_status = dwmac5_fpe_irq_status,
1256 .add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
1257 .del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
1258 .restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
1261 const struct stmmac_ops dwmac510_ops = {
1262 .core_init = dwmac4_core_init,
1263 .set_mac = stmmac_dwmac4_set_mac,
1264 .rx_ipc = dwmac4_rx_ipc_enable,
1265 .rx_queue_enable = dwmac4_rx_queue_enable,
1266 .rx_queue_prio = dwmac4_rx_queue_priority,
1267 .tx_queue_prio = dwmac4_tx_queue_priority,
1268 .rx_queue_routing = dwmac4_rx_queue_routing,
1269 .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
1270 .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
1271 .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
1272 .map_mtl_to_dma = dwmac4_map_mtl_dma,
1273 .config_cbs = dwmac4_config_cbs,
1274 .dump_regs = dwmac4_dump_regs,
1275 .host_irq_status = dwmac4_irq_status,
1276 .host_mtl_irq_status = dwmac4_irq_mtl_status,
1277 .flow_ctrl = dwmac4_flow_ctrl,
1279 .set_umac_addr = dwmac4_set_umac_addr,
1280 .get_umac_addr = dwmac4_get_umac_addr,
1281 .set_eee_mode = dwmac4_set_eee_mode,
1282 .reset_eee_mode = dwmac4_reset_eee_mode,
1283 .set_eee_lpi_entry_timer = dwmac4_set_eee_lpi_entry_timer,
1284 .set_eee_timer = dwmac4_set_eee_timer,
1285 .set_eee_pls = dwmac4_set_eee_pls,
1286 .pcs_ctrl_ane = dwmac4_ctrl_ane,
1287 .pcs_rane = dwmac4_rane,
1288 .pcs_get_adv_lp = dwmac4_get_adv_lp,
1289 .debug = dwmac4_debug,
1290 .set_filter = dwmac4_set_filter,
1291 .safety_feat_config = dwmac5_safety_feat_config,
1292 .safety_feat_irq_status = dwmac5_safety_feat_irq_status,
1293 .safety_feat_dump = dwmac5_safety_feat_dump,
1294 .rxp_config = dwmac5_rxp_config,
1295 .flex_pps_config = dwmac5_flex_pps_config,
1296 .set_mac_loopback = dwmac4_set_mac_loopback,
1297 .update_vlan_hash = dwmac4_update_vlan_hash,
1298 .sarc_configure = dwmac4_sarc_configure,
1299 .enable_vlan = dwmac4_enable_vlan,
1300 .set_arp_offload = dwmac4_set_arp_offload,
1301 .config_l3_filter = dwmac4_config_l3_filter,
1302 .config_l4_filter = dwmac4_config_l4_filter,
1303 .est_configure = dwmac5_est_configure,
1304 .est_irq_status = dwmac5_est_irq_status,
1305 .fpe_configure = dwmac5_fpe_configure,
1306 .fpe_send_mpacket = dwmac5_fpe_send_mpacket,
1307 .fpe_irq_status = dwmac5_fpe_irq_status,
1308 .add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
1309 .del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
1310 .restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
1313 static u32 dwmac4_get_num_vlan(void __iomem *ioaddr)
1317 val = readl(ioaddr + GMAC_HW_FEATURE3);
1318 switch (val & GMAC_HW_FEAT_NRVF) {
1344 int dwmac4_setup(struct stmmac_priv *priv)
1346 struct mac_device_info *mac = priv->hw;
1348 dev_info(priv->device, "\tDWMAC4/5\n");
1350 priv->dev->priv_flags |= IFF_UNICAST_FLT;
1351 mac->pcsr = priv->ioaddr;
1352 mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
1353 mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
1354 mac->mcast_bits_log2 = 0;
1356 if (mac->multicast_filter_bins)
1357 mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
1359 mac->link.duplex = GMAC_CONFIG_DM;
1360 mac->link.speed10 = GMAC_CONFIG_PS;
1361 mac->link.speed100 = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
1362 mac->link.speed1000 = 0;
1363 mac->link.speed2500 = GMAC_CONFIG_FES;
1364 mac->link.speed_mask = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
1365 mac->mii.addr = GMAC_MDIO_ADDR;
1366 mac->mii.data = GMAC_MDIO_DATA;
1367 mac->mii.addr_shift = 21;
1368 mac->mii.addr_mask = GENMASK(25, 21);
1369 mac->mii.reg_shift = 16;
1370 mac->mii.reg_mask = GENMASK(20, 16);
1371 mac->mii.clk_csr_shift = 8;
1372 mac->mii.clk_csr_mask = GENMASK(11, 8);
1373 mac->num_vlan = dwmac4_get_num_vlan(priv->ioaddr);