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 writel(value
, ioaddr
+ GMAC_INT_EN
);
59 static void dwmac4_rx_queue_enable(struct mac_device_info
*hw
,
62 void __iomem
*ioaddr
= hw
->pcsr
;
63 u32 value
= readl(ioaddr
+ GMAC_RXQ_CTRL0
);
65 value
&= GMAC_RX_QUEUE_CLEAR(queue
);
66 if (mode
== MTL_QUEUE_AVB
)
67 value
|= GMAC_RX_AV_QUEUE_ENABLE(queue
);
68 else if (mode
== MTL_QUEUE_DCB
)
69 value
|= GMAC_RX_DCB_QUEUE_ENABLE(queue
);
71 writel(value
, ioaddr
+ GMAC_RXQ_CTRL0
);
74 static void dwmac4_rx_queue_priority(struct mac_device_info
*hw
,
77 void __iomem
*ioaddr
= hw
->pcsr
;
81 base_register
= (queue
< 4) ? GMAC_RXQ_CTRL2
: GMAC_RXQ_CTRL3
;
85 value
= readl(ioaddr
+ base_register
);
87 value
&= ~GMAC_RXQCTRL_PSRQX_MASK(queue
);
88 value
|= (prio
<< GMAC_RXQCTRL_PSRQX_SHIFT(queue
)) &
89 GMAC_RXQCTRL_PSRQX_MASK(queue
);
90 writel(value
, ioaddr
+ base_register
);
93 static void dwmac4_tx_queue_priority(struct mac_device_info
*hw
,
96 void __iomem
*ioaddr
= hw
->pcsr
;
100 base_register
= (queue
< 4) ? GMAC_TXQ_PRTY_MAP0
: GMAC_TXQ_PRTY_MAP1
;
104 value
= readl(ioaddr
+ base_register
);
106 value
&= ~GMAC_TXQCTRL_PSTQX_MASK(queue
);
107 value
|= (prio
<< GMAC_TXQCTRL_PSTQX_SHIFT(queue
)) &
108 GMAC_TXQCTRL_PSTQX_MASK(queue
);
110 writel(value
, ioaddr
+ base_register
);
113 static void dwmac4_rx_queue_routing(struct mac_device_info
*hw
,
114 u8 packet
, u32 queue
)
116 void __iomem
*ioaddr
= hw
->pcsr
;
119 static const struct stmmac_rx_routing route_possibilities
[] = {
120 { GMAC_RXQCTRL_AVCPQ_MASK
, GMAC_RXQCTRL_AVCPQ_SHIFT
},
121 { GMAC_RXQCTRL_PTPQ_MASK
, GMAC_RXQCTRL_PTPQ_SHIFT
},
122 { GMAC_RXQCTRL_DCBCPQ_MASK
, GMAC_RXQCTRL_DCBCPQ_SHIFT
},
123 { GMAC_RXQCTRL_UPQ_MASK
, GMAC_RXQCTRL_UPQ_SHIFT
},
124 { GMAC_RXQCTRL_MCBCQ_MASK
, GMAC_RXQCTRL_MCBCQ_SHIFT
},
127 value
= readl(ioaddr
+ GMAC_RXQ_CTRL1
);
129 /* routing configuration */
130 value
&= ~route_possibilities
[packet
- 1].reg_mask
;
131 value
|= (queue
<< route_possibilities
[packet
-1].reg_shift
) &
132 route_possibilities
[packet
- 1].reg_mask
;
134 /* some packets require extra ops */
135 if (packet
== PACKET_AVCPQ
) {
136 value
&= ~GMAC_RXQCTRL_TACPQE
;
137 value
|= 0x1 << GMAC_RXQCTRL_TACPQE_SHIFT
;
138 } else if (packet
== PACKET_MCBCQ
) {
139 value
&= ~GMAC_RXQCTRL_MCBCQEN
;
140 value
|= 0x1 << GMAC_RXQCTRL_MCBCQEN_SHIFT
;
143 writel(value
, ioaddr
+ GMAC_RXQ_CTRL1
);
146 static void dwmac4_prog_mtl_rx_algorithms(struct mac_device_info
*hw
,
149 void __iomem
*ioaddr
= hw
->pcsr
;
150 u32 value
= readl(ioaddr
+ MTL_OPERATION_MODE
);
152 value
&= ~MTL_OPERATION_RAA
;
154 case MTL_RX_ALGORITHM_SP
:
155 value
|= MTL_OPERATION_RAA_SP
;
157 case MTL_RX_ALGORITHM_WSP
:
158 value
|= MTL_OPERATION_RAA_WSP
;
164 writel(value
, ioaddr
+ MTL_OPERATION_MODE
);
167 static void dwmac4_prog_mtl_tx_algorithms(struct mac_device_info
*hw
,
170 void __iomem
*ioaddr
= hw
->pcsr
;
171 u32 value
= readl(ioaddr
+ MTL_OPERATION_MODE
);
173 value
&= ~MTL_OPERATION_SCHALG_MASK
;
175 case MTL_TX_ALGORITHM_WRR
:
176 value
|= MTL_OPERATION_SCHALG_WRR
;
178 case MTL_TX_ALGORITHM_WFQ
:
179 value
|= MTL_OPERATION_SCHALG_WFQ
;
181 case MTL_TX_ALGORITHM_DWRR
:
182 value
|= MTL_OPERATION_SCHALG_DWRR
;
184 case MTL_TX_ALGORITHM_SP
:
185 value
|= MTL_OPERATION_SCHALG_SP
;
191 writel(value
, ioaddr
+ MTL_OPERATION_MODE
);
194 static void dwmac4_set_mtl_tx_queue_weight(struct mac_device_info
*hw
,
195 u32 weight
, u32 queue
)
197 void __iomem
*ioaddr
= hw
->pcsr
;
198 u32 value
= readl(ioaddr
+ MTL_TXQX_WEIGHT_BASE_ADDR(queue
));
200 value
&= ~MTL_TXQ_WEIGHT_ISCQW_MASK
;
201 value
|= weight
& MTL_TXQ_WEIGHT_ISCQW_MASK
;
202 writel(value
, ioaddr
+ MTL_TXQX_WEIGHT_BASE_ADDR(queue
));
205 static void dwmac4_map_mtl_dma(struct mac_device_info
*hw
, u32 queue
, u32 chan
)
207 void __iomem
*ioaddr
= hw
->pcsr
;
211 value
= readl(ioaddr
+ MTL_RXQ_DMA_MAP0
);
213 value
= readl(ioaddr
+ MTL_RXQ_DMA_MAP1
);
215 if (queue
== 0 || queue
== 4) {
216 value
&= ~MTL_RXQ_DMA_Q04MDMACH_MASK
;
217 value
|= MTL_RXQ_DMA_Q04MDMACH(chan
);
219 value
&= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue
);
220 value
|= MTL_RXQ_DMA_QXMDMACH(chan
, queue
);
224 writel(value
, ioaddr
+ MTL_RXQ_DMA_MAP0
);
226 writel(value
, ioaddr
+ MTL_RXQ_DMA_MAP1
);
229 static void dwmac4_config_cbs(struct mac_device_info
*hw
,
230 u32 send_slope
, u32 idle_slope
,
231 u32 high_credit
, u32 low_credit
, u32 queue
)
233 void __iomem
*ioaddr
= hw
->pcsr
;
236 pr_debug("Queue %d configured as AVB. Parameters:\n", queue
);
237 pr_debug("\tsend_slope: 0x%08x\n", send_slope
);
238 pr_debug("\tidle_slope: 0x%08x\n", idle_slope
);
239 pr_debug("\thigh_credit: 0x%08x\n", high_credit
);
240 pr_debug("\tlow_credit: 0x%08x\n", low_credit
);
242 /* enable AV algorithm */
243 value
= readl(ioaddr
+ MTL_ETSX_CTRL_BASE_ADDR(queue
));
244 value
|= MTL_ETS_CTRL_AVALG
;
245 value
|= MTL_ETS_CTRL_CC
;
246 writel(value
, ioaddr
+ MTL_ETSX_CTRL_BASE_ADDR(queue
));
248 /* configure send slope */
249 value
= readl(ioaddr
+ MTL_SEND_SLP_CREDX_BASE_ADDR(queue
));
250 value
&= ~MTL_SEND_SLP_CRED_SSC_MASK
;
251 value
|= send_slope
& MTL_SEND_SLP_CRED_SSC_MASK
;
252 writel(value
, ioaddr
+ MTL_SEND_SLP_CREDX_BASE_ADDR(queue
));
254 /* configure idle slope (same register as tx weight) */
255 dwmac4_set_mtl_tx_queue_weight(hw
, idle_slope
, queue
);
257 /* configure high credit */
258 value
= readl(ioaddr
+ MTL_HIGH_CREDX_BASE_ADDR(queue
));
259 value
&= ~MTL_HIGH_CRED_HC_MASK
;
260 value
|= high_credit
& MTL_HIGH_CRED_HC_MASK
;
261 writel(value
, ioaddr
+ MTL_HIGH_CREDX_BASE_ADDR(queue
));
263 /* configure high credit */
264 value
= readl(ioaddr
+ MTL_LOW_CREDX_BASE_ADDR(queue
));
265 value
&= ~MTL_HIGH_CRED_LC_MASK
;
266 value
|= low_credit
& MTL_HIGH_CRED_LC_MASK
;
267 writel(value
, ioaddr
+ MTL_LOW_CREDX_BASE_ADDR(queue
));
270 static void dwmac4_dump_regs(struct mac_device_info
*hw
, u32
*reg_space
)
272 void __iomem
*ioaddr
= hw
->pcsr
;
275 for (i
= 0; i
< GMAC_REG_NUM
; i
++)
276 reg_space
[i
] = readl(ioaddr
+ i
* 4);
279 static int dwmac4_rx_ipc_enable(struct mac_device_info
*hw
)
281 void __iomem
*ioaddr
= hw
->pcsr
;
282 u32 value
= readl(ioaddr
+ GMAC_CONFIG
);
285 value
|= GMAC_CONFIG_IPC
;
287 value
&= ~GMAC_CONFIG_IPC
;
289 writel(value
, ioaddr
+ GMAC_CONFIG
);
291 value
= readl(ioaddr
+ GMAC_CONFIG
);
293 return !!(value
& GMAC_CONFIG_IPC
);
296 static void dwmac4_pmt(struct mac_device_info
*hw
, unsigned long mode
)
298 void __iomem
*ioaddr
= hw
->pcsr
;
299 unsigned int pmt
= 0;
302 if (mode
& WAKE_MAGIC
) {
303 pr_debug("GMAC: WOL Magic frame\n");
304 pmt
|= power_down
| magic_pkt_en
;
306 if (mode
& WAKE_UCAST
) {
307 pr_debug("GMAC: WOL on global unicast\n");
308 pmt
|= power_down
| global_unicast
| wake_up_frame_en
;
312 /* The receiver must be enabled for WOL before powering down */
313 config
= readl(ioaddr
+ GMAC_CONFIG
);
314 config
|= GMAC_CONFIG_RE
;
315 writel(config
, ioaddr
+ GMAC_CONFIG
);
317 writel(pmt
, ioaddr
+ GMAC_PMT
);
320 static void dwmac4_set_umac_addr(struct mac_device_info
*hw
,
321 unsigned char *addr
, unsigned int reg_n
)
323 void __iomem
*ioaddr
= hw
->pcsr
;
325 stmmac_dwmac4_set_mac_addr(ioaddr
, addr
, GMAC_ADDR_HIGH(reg_n
),
326 GMAC_ADDR_LOW(reg_n
));
329 static void dwmac4_get_umac_addr(struct mac_device_info
*hw
,
330 unsigned char *addr
, unsigned int reg_n
)
332 void __iomem
*ioaddr
= hw
->pcsr
;
334 stmmac_dwmac4_get_mac_addr(ioaddr
, addr
, GMAC_ADDR_HIGH(reg_n
),
335 GMAC_ADDR_LOW(reg_n
));
338 static void dwmac4_set_eee_mode(struct mac_device_info
*hw
,
339 bool en_tx_lpi_clockgating
)
341 void __iomem
*ioaddr
= hw
->pcsr
;
344 /* Enable the link status receive on RGMII, SGMII ore SMII
345 * receive path and instruct the transmit to enter in LPI
348 value
= readl(ioaddr
+ GMAC4_LPI_CTRL_STATUS
);
349 value
|= GMAC4_LPI_CTRL_STATUS_LPIEN
| GMAC4_LPI_CTRL_STATUS_LPITXA
;
351 if (en_tx_lpi_clockgating
)
352 value
|= GMAC4_LPI_CTRL_STATUS_LPITCSE
;
354 writel(value
, ioaddr
+ GMAC4_LPI_CTRL_STATUS
);
357 static void dwmac4_reset_eee_mode(struct mac_device_info
*hw
)
359 void __iomem
*ioaddr
= hw
->pcsr
;
362 value
= readl(ioaddr
+ GMAC4_LPI_CTRL_STATUS
);
363 value
&= ~(GMAC4_LPI_CTRL_STATUS_LPIEN
| GMAC4_LPI_CTRL_STATUS_LPITXA
);
364 writel(value
, ioaddr
+ GMAC4_LPI_CTRL_STATUS
);
367 static void dwmac4_set_eee_pls(struct mac_device_info
*hw
, int link
)
369 void __iomem
*ioaddr
= hw
->pcsr
;
372 value
= readl(ioaddr
+ GMAC4_LPI_CTRL_STATUS
);
375 value
|= GMAC4_LPI_CTRL_STATUS_PLS
;
377 value
&= ~GMAC4_LPI_CTRL_STATUS_PLS
;
379 writel(value
, ioaddr
+ GMAC4_LPI_CTRL_STATUS
);
382 static void dwmac4_set_eee_lpi_entry_timer(struct mac_device_info
*hw
, int et
)
384 void __iomem
*ioaddr
= hw
->pcsr
;
385 int value
= et
& STMMAC_ET_MAX
;
388 /* Program LPI entry timer value into register */
389 writel(value
, ioaddr
+ GMAC4_LPI_ENTRY_TIMER
);
391 /* Enable/disable LPI entry timer */
392 regval
= readl(ioaddr
+ GMAC4_LPI_CTRL_STATUS
);
393 regval
|= GMAC4_LPI_CTRL_STATUS_LPIEN
| GMAC4_LPI_CTRL_STATUS_LPITXA
;
396 regval
|= GMAC4_LPI_CTRL_STATUS_LPIATE
;
398 regval
&= ~GMAC4_LPI_CTRL_STATUS_LPIATE
;
400 writel(regval
, ioaddr
+ GMAC4_LPI_CTRL_STATUS
);
403 static void dwmac4_set_eee_timer(struct mac_device_info
*hw
, int ls
, int tw
)
405 void __iomem
*ioaddr
= hw
->pcsr
;
406 int value
= ((tw
& 0xffff)) | ((ls
& 0x3ff) << 16);
408 /* Program the timers in the LPI timer control register:
409 * LS: minimum time (ms) for which the link
410 * status from PHY should be ok before transmitting
412 * TW: minimum time (us) for which the core waits
413 * after it has stopped transmitting the LPI pattern.
415 writel(value
, ioaddr
+ GMAC4_LPI_TIMER_CTRL
);
418 static void dwmac4_write_single_vlan(struct net_device
*dev
, u16 vid
)
420 void __iomem
*ioaddr
= (void __iomem
*)dev
->base_addr
;
423 val
= readl(ioaddr
+ GMAC_VLAN_TAG
);
424 val
&= ~GMAC_VLAN_TAG_VID
;
425 val
|= GMAC_VLAN_TAG_ETV
| vid
;
427 writel(val
, ioaddr
+ GMAC_VLAN_TAG
);
430 static int dwmac4_write_vlan_filter(struct net_device
*dev
,
431 struct mac_device_info
*hw
,
434 void __iomem
*ioaddr
= (void __iomem
*)dev
->base_addr
;
438 if (index
>= hw
->num_vlan
)
441 writel(data
, ioaddr
+ GMAC_VLAN_TAG_DATA
);
443 val
= readl(ioaddr
+ GMAC_VLAN_TAG
);
444 val
&= ~(GMAC_VLAN_TAG_CTRL_OFS_MASK
|
445 GMAC_VLAN_TAG_CTRL_CT
|
446 GMAC_VLAN_TAG_CTRL_OB
);
447 val
|= (index
<< GMAC_VLAN_TAG_CTRL_OFS_SHIFT
) | GMAC_VLAN_TAG_CTRL_OB
;
449 writel(val
, ioaddr
+ GMAC_VLAN_TAG
);
451 for (i
= 0; i
< timeout
; i
++) {
452 val
= readl(ioaddr
+ GMAC_VLAN_TAG
);
453 if (!(val
& GMAC_VLAN_TAG_CTRL_OB
))
458 netdev_err(dev
, "Timeout accessing MAC_VLAN_Tag_Filter\n");
463 static int dwmac4_add_hw_vlan_rx_fltr(struct net_device
*dev
,
464 struct mac_device_info
*hw
,
465 __be16 proto
, u16 vid
)
476 "Adding VLAN in promisc mode not supported\n");
480 /* Single Rx VLAN Filter */
481 if (hw
->num_vlan
== 1) {
482 /* For single VLAN filter, VID 0 means VLAN promiscuous */
484 netdev_warn(dev
, "Adding VLAN ID 0 is not supported\n");
488 if (hw
->vlan_filter
[0] & GMAC_VLAN_TAG_VID
) {
489 netdev_err(dev
, "Only single VLAN ID supported\n");
493 hw
->vlan_filter
[0] = vid
;
494 dwmac4_write_single_vlan(dev
, vid
);
499 /* Extended Rx VLAN Filter Enable */
500 val
|= GMAC_VLAN_TAG_DATA_ETV
| GMAC_VLAN_TAG_DATA_VEN
| vid
;
502 for (i
= 0; i
< hw
->num_vlan
; i
++) {
503 if (hw
->vlan_filter
[i
] == val
)
505 else if (!(hw
->vlan_filter
[i
] & GMAC_VLAN_TAG_DATA_VEN
))
510 netdev_err(dev
, "MAC_VLAN_Tag_Filter full (size: %0u)\n",
515 ret
= dwmac4_write_vlan_filter(dev
, hw
, index
, val
);
518 hw
->vlan_filter
[index
] = val
;
523 static int dwmac4_del_hw_vlan_rx_fltr(struct net_device
*dev
,
524 struct mac_device_info
*hw
,
525 __be16 proto
, u16 vid
)
531 "Deleting VLAN in promisc mode not supported\n");
535 /* Single Rx VLAN Filter */
536 if (hw
->num_vlan
== 1) {
537 if ((hw
->vlan_filter
[0] & GMAC_VLAN_TAG_VID
) == vid
) {
538 hw
->vlan_filter
[0] = 0;
539 dwmac4_write_single_vlan(dev
, 0);
544 /* Extended Rx VLAN Filter Enable */
545 for (i
= 0; i
< hw
->num_vlan
; i
++) {
546 if ((hw
->vlan_filter
[i
] & GMAC_VLAN_TAG_DATA_VID
) == vid
) {
547 ret
= dwmac4_write_vlan_filter(dev
, hw
, i
, 0);
550 hw
->vlan_filter
[i
] = 0;
559 static void dwmac4_vlan_promisc_enable(struct net_device
*dev
,
560 struct mac_device_info
*hw
)
562 void __iomem
*ioaddr
= hw
->pcsr
;
568 /* Single Rx VLAN Filter */
569 if (hw
->num_vlan
== 1) {
570 dwmac4_write_single_vlan(dev
, 0);
574 /* Extended Rx VLAN Filter Enable */
575 for (i
= 0; i
< hw
->num_vlan
; i
++) {
576 if (hw
->vlan_filter
[i
] & GMAC_VLAN_TAG_DATA_VEN
) {
577 val
= hw
->vlan_filter
[i
] & ~GMAC_VLAN_TAG_DATA_VEN
;
578 dwmac4_write_vlan_filter(dev
, hw
, i
, val
);
582 hash
= readl(ioaddr
+ GMAC_VLAN_HASH_TABLE
);
583 if (hash
& GMAC_VLAN_VLHT
) {
584 value
= readl(ioaddr
+ GMAC_VLAN_TAG
);
585 if (value
& GMAC_VLAN_VTHM
) {
586 value
&= ~GMAC_VLAN_VTHM
;
587 writel(value
, ioaddr
+ GMAC_VLAN_TAG
);
592 static void dwmac4_restore_hw_vlan_rx_fltr(struct net_device
*dev
,
593 struct mac_device_info
*hw
)
595 void __iomem
*ioaddr
= hw
->pcsr
;
601 /* Single Rx VLAN Filter */
602 if (hw
->num_vlan
== 1) {
603 dwmac4_write_single_vlan(dev
, hw
->vlan_filter
[0]);
607 /* Extended Rx VLAN Filter Enable */
608 for (i
= 0; i
< hw
->num_vlan
; i
++) {
609 if (hw
->vlan_filter
[i
] & GMAC_VLAN_TAG_DATA_VEN
) {
610 val
= hw
->vlan_filter
[i
];
611 dwmac4_write_vlan_filter(dev
, hw
, i
, val
);
615 hash
= readl(ioaddr
+ GMAC_VLAN_HASH_TABLE
);
616 if (hash
& GMAC_VLAN_VLHT
) {
617 value
= readl(ioaddr
+ GMAC_VLAN_TAG
);
618 value
|= GMAC_VLAN_VTHM
;
619 writel(value
, ioaddr
+ GMAC_VLAN_TAG
);
623 static void dwmac4_set_filter(struct mac_device_info
*hw
,
624 struct net_device
*dev
)
626 void __iomem
*ioaddr
= (void __iomem
*)dev
->base_addr
;
627 int numhashregs
= (hw
->multicast_filter_bins
>> 5);
628 int mcbitslog2
= hw
->mcast_bits_log2
;
633 memset(mc_filter
, 0, sizeof(mc_filter
));
635 value
= readl(ioaddr
+ GMAC_PACKET_FILTER
);
636 value
&= ~GMAC_PACKET_FILTER_HMC
;
637 value
&= ~GMAC_PACKET_FILTER_HPF
;
638 value
&= ~GMAC_PACKET_FILTER_PCF
;
639 value
&= ~GMAC_PACKET_FILTER_PM
;
640 value
&= ~GMAC_PACKET_FILTER_PR
;
641 if (dev
->flags
& IFF_PROMISC
) {
642 /* VLAN Tag Filter Fail Packets Queuing */
643 if (hw
->vlan_fail_q_en
) {
644 value
= readl(ioaddr
+ GMAC_RXQ_CTRL4
);
645 value
&= ~GMAC_RXQCTRL_VFFQ_MASK
;
646 value
|= GMAC_RXQCTRL_VFFQE
|
647 (hw
->vlan_fail_q
<< GMAC_RXQCTRL_VFFQ_SHIFT
);
648 writel(value
, ioaddr
+ GMAC_RXQ_CTRL4
);
649 value
= GMAC_PACKET_FILTER_PR
| GMAC_PACKET_FILTER_RA
;
651 value
= GMAC_PACKET_FILTER_PR
| GMAC_PACKET_FILTER_PCF
;
654 } else if ((dev
->flags
& IFF_ALLMULTI
) ||
655 (netdev_mc_count(dev
) > hw
->multicast_filter_bins
)) {
657 value
|= GMAC_PACKET_FILTER_PM
;
658 /* Set all the bits of the HASH tab */
659 memset(mc_filter
, 0xff, sizeof(mc_filter
));
660 } else if (!netdev_mc_empty(dev
) && (dev
->flags
& IFF_MULTICAST
)) {
661 struct netdev_hw_addr
*ha
;
663 /* Hash filter for multicast */
664 value
|= GMAC_PACKET_FILTER_HMC
;
666 netdev_for_each_mc_addr(ha
, dev
) {
667 /* The upper n bits of the calculated CRC are used to
668 * index the contents of the hash table. The number of
669 * bits used depends on the hardware configuration
670 * selected at core configuration time.
672 u32 bit_nr
= bitrev32(~crc32_le(~0, ha
->addr
,
673 ETH_ALEN
)) >> (32 - mcbitslog2
);
674 /* The most significant bit determines the register to
675 * use (H/L) while the other 5 bits determine the bit
676 * within the register.
678 mc_filter
[bit_nr
>> 5] |= (1 << (bit_nr
& 0x1f));
682 for (i
= 0; i
< numhashregs
; i
++)
683 writel(mc_filter
[i
], ioaddr
+ GMAC_HASH_TAB(i
));
685 value
|= GMAC_PACKET_FILTER_HPF
;
687 /* Handle multiple unicast addresses */
688 if (netdev_uc_count(dev
) > hw
->unicast_filter_entries
) {
689 /* Switch to promiscuous mode if more than 128 addrs
692 value
|= GMAC_PACKET_FILTER_PR
;
694 struct netdev_hw_addr
*ha
;
697 netdev_for_each_uc_addr(ha
, dev
) {
698 dwmac4_set_umac_addr(hw
, ha
->addr
, reg
);
702 while (reg
< GMAC_MAX_PERFECT_ADDRESSES
) {
703 writel(0, ioaddr
+ GMAC_ADDR_HIGH(reg
));
704 writel(0, ioaddr
+ GMAC_ADDR_LOW(reg
));
710 if (dev
->features
& NETIF_F_HW_VLAN_CTAG_FILTER
)
711 value
|= GMAC_PACKET_FILTER_VTFE
;
713 writel(value
, ioaddr
+ GMAC_PACKET_FILTER
);
715 if (dev
->flags
& IFF_PROMISC
&& !hw
->vlan_fail_q_en
) {
718 dwmac4_vlan_promisc_enable(dev
, hw
);
723 dwmac4_restore_hw_vlan_rx_fltr(dev
, hw
);
728 static void dwmac4_flow_ctrl(struct mac_device_info
*hw
, unsigned int duplex
,
729 unsigned int fc
, unsigned int pause_time
,
732 void __iomem
*ioaddr
= hw
->pcsr
;
733 unsigned int flow
= 0;
736 pr_debug("GMAC Flow-Control:\n");
738 pr_debug("\tReceive Flow-Control ON\n");
739 flow
|= GMAC_RX_FLOW_CTRL_RFE
;
741 writel(flow
, ioaddr
+ GMAC_RX_FLOW_CTRL
);
744 pr_debug("\tTransmit Flow-Control ON\n");
747 pr_debug("\tduplex mode: PAUSE %d\n", pause_time
);
749 for (queue
= 0; queue
< tx_cnt
; queue
++) {
750 flow
= GMAC_TX_FLOW_CTRL_TFE
;
754 (pause_time
<< GMAC_TX_FLOW_CTRL_PT_SHIFT
);
756 writel(flow
, ioaddr
+ GMAC_QX_TX_FLOW_CTRL(queue
));
759 for (queue
= 0; queue
< tx_cnt
; queue
++)
760 writel(0, ioaddr
+ GMAC_QX_TX_FLOW_CTRL(queue
));
764 static void dwmac4_ctrl_ane(void __iomem
*ioaddr
, bool ane
, bool srgmi_ral
,
767 dwmac_ctrl_ane(ioaddr
, GMAC_PCS_BASE
, ane
, srgmi_ral
, loopback
);
770 static void dwmac4_rane(void __iomem
*ioaddr
, bool restart
)
772 dwmac_rane(ioaddr
, GMAC_PCS_BASE
, restart
);
775 static void dwmac4_get_adv_lp(void __iomem
*ioaddr
, struct rgmii_adv
*adv
)
777 dwmac_get_adv_lp(ioaddr
, GMAC_PCS_BASE
, adv
);
780 /* RGMII or SMII interface */
781 static void dwmac4_phystatus(void __iomem
*ioaddr
, struct stmmac_extra_stats
*x
)
785 status
= readl(ioaddr
+ GMAC_PHYIF_CONTROL_STATUS
);
788 /* Check the link status */
789 if (status
& GMAC_PHYIF_CTRLSTATUS_LNKSTS
) {
794 speed_value
= ((status
& GMAC_PHYIF_CTRLSTATUS_SPEED
) >>
795 GMAC_PHYIF_CTRLSTATUS_SPEED_SHIFT
);
796 if (speed_value
== GMAC_PHYIF_CTRLSTATUS_SPEED_125
)
797 x
->pcs_speed
= SPEED_1000
;
798 else if (speed_value
== GMAC_PHYIF_CTRLSTATUS_SPEED_25
)
799 x
->pcs_speed
= SPEED_100
;
801 x
->pcs_speed
= SPEED_10
;
803 x
->pcs_duplex
= (status
& GMAC_PHYIF_CTRLSTATUS_LNKMOD_MASK
);
805 pr_info("Link is Up - %d/%s\n", (int)x
->pcs_speed
,
806 x
->pcs_duplex
? "Full" : "Half");
809 pr_info("Link is Down\n");
813 static int dwmac4_irq_mtl_status(struct mac_device_info
*hw
, u32 chan
)
815 void __iomem
*ioaddr
= hw
->pcsr
;
816 u32 mtl_int_qx_status
;
819 mtl_int_qx_status
= readl(ioaddr
+ MTL_INT_STATUS
);
821 /* Check MTL Interrupt */
822 if (mtl_int_qx_status
& MTL_INT_QX(chan
)) {
823 /* read Queue x Interrupt status */
824 u32 status
= readl(ioaddr
+ MTL_CHAN_INT_CTRL(chan
));
826 if (status
& MTL_RX_OVERFLOW_INT
) {
827 /* clear Interrupt */
828 writel(status
| MTL_RX_OVERFLOW_INT
,
829 ioaddr
+ MTL_CHAN_INT_CTRL(chan
));
830 ret
= CORE_IRQ_MTL_RX_OVERFLOW
;
837 static int dwmac4_irq_status(struct mac_device_info
*hw
,
838 struct stmmac_extra_stats
*x
)
840 void __iomem
*ioaddr
= hw
->pcsr
;
841 u32 intr_status
= readl(ioaddr
+ GMAC_INT_STATUS
);
842 u32 intr_enable
= readl(ioaddr
+ GMAC_INT_EN
);
845 /* Discard disabled bits */
846 intr_status
&= intr_enable
;
848 /* Not used events (e.g. MMC interrupts) are not handled. */
849 if ((intr_status
& mmc_tx_irq
))
851 if (unlikely(intr_status
& mmc_rx_irq
))
853 if (unlikely(intr_status
& mmc_rx_csum_offload_irq
))
854 x
->mmc_rx_csum_offload_irq_n
++;
855 /* Clear the PMT bits 5 and 6 by reading the PMT status reg */
856 if (unlikely(intr_status
& pmt_irq
)) {
857 readl(ioaddr
+ GMAC_PMT
);
858 x
->irq_receive_pmt_irq_n
++;
861 /* MAC tx/rx EEE LPI entry/exit interrupts */
862 if (intr_status
& lpi_irq
) {
863 /* Clear LPI interrupt by reading MAC_LPI_Control_Status */
864 u32 status
= readl(ioaddr
+ GMAC4_LPI_CTRL_STATUS
);
866 if (status
& GMAC4_LPI_CTRL_STATUS_TLPIEN
) {
867 ret
|= CORE_IRQ_TX_PATH_IN_LPI_MODE
;
868 x
->irq_tx_path_in_lpi_mode_n
++;
870 if (status
& GMAC4_LPI_CTRL_STATUS_TLPIEX
) {
871 ret
|= CORE_IRQ_TX_PATH_EXIT_LPI_MODE
;
872 x
->irq_tx_path_exit_lpi_mode_n
++;
874 if (status
& GMAC4_LPI_CTRL_STATUS_RLPIEN
)
875 x
->irq_rx_path_in_lpi_mode_n
++;
876 if (status
& GMAC4_LPI_CTRL_STATUS_RLPIEX
)
877 x
->irq_rx_path_exit_lpi_mode_n
++;
880 dwmac_pcs_isr(ioaddr
, GMAC_PCS_BASE
, intr_status
, x
);
881 if (intr_status
& PCS_RGSMIIIS_IRQ
)
882 dwmac4_phystatus(ioaddr
, x
);
887 static void dwmac4_debug(void __iomem
*ioaddr
, struct stmmac_extra_stats
*x
,
888 u32 rx_queues
, u32 tx_queues
)
893 for (queue
= 0; queue
< tx_queues
; queue
++) {
894 value
= readl(ioaddr
+ MTL_CHAN_TX_DEBUG(queue
));
896 if (value
& MTL_DEBUG_TXSTSFSTS
)
897 x
->mtl_tx_status_fifo_full
++;
898 if (value
& MTL_DEBUG_TXFSTS
)
899 x
->mtl_tx_fifo_not_empty
++;
900 if (value
& MTL_DEBUG_TWCSTS
)
902 if (value
& MTL_DEBUG_TRCSTS_MASK
) {
903 u32 trcsts
= (value
& MTL_DEBUG_TRCSTS_MASK
)
904 >> MTL_DEBUG_TRCSTS_SHIFT
;
905 if (trcsts
== MTL_DEBUG_TRCSTS_WRITE
)
906 x
->mtl_tx_fifo_read_ctrl_write
++;
907 else if (trcsts
== MTL_DEBUG_TRCSTS_TXW
)
908 x
->mtl_tx_fifo_read_ctrl_wait
++;
909 else if (trcsts
== MTL_DEBUG_TRCSTS_READ
)
910 x
->mtl_tx_fifo_read_ctrl_read
++;
912 x
->mtl_tx_fifo_read_ctrl_idle
++;
914 if (value
& MTL_DEBUG_TXPAUSED
)
915 x
->mac_tx_in_pause
++;
918 for (queue
= 0; queue
< rx_queues
; queue
++) {
919 value
= readl(ioaddr
+ MTL_CHAN_RX_DEBUG(queue
));
921 if (value
& MTL_DEBUG_RXFSTS_MASK
) {
922 u32 rxfsts
= (value
& MTL_DEBUG_RXFSTS_MASK
)
923 >> MTL_DEBUG_RRCSTS_SHIFT
;
925 if (rxfsts
== MTL_DEBUG_RXFSTS_FULL
)
926 x
->mtl_rx_fifo_fill_level_full
++;
927 else if (rxfsts
== MTL_DEBUG_RXFSTS_AT
)
928 x
->mtl_rx_fifo_fill_above_thresh
++;
929 else if (rxfsts
== MTL_DEBUG_RXFSTS_BT
)
930 x
->mtl_rx_fifo_fill_below_thresh
++;
932 x
->mtl_rx_fifo_fill_level_empty
++;
934 if (value
& MTL_DEBUG_RRCSTS_MASK
) {
935 u32 rrcsts
= (value
& MTL_DEBUG_RRCSTS_MASK
) >>
936 MTL_DEBUG_RRCSTS_SHIFT
;
938 if (rrcsts
== MTL_DEBUG_RRCSTS_FLUSH
)
939 x
->mtl_rx_fifo_read_ctrl_flush
++;
940 else if (rrcsts
== MTL_DEBUG_RRCSTS_RSTAT
)
941 x
->mtl_rx_fifo_read_ctrl_read_data
++;
942 else if (rrcsts
== MTL_DEBUG_RRCSTS_RDATA
)
943 x
->mtl_rx_fifo_read_ctrl_status
++;
945 x
->mtl_rx_fifo_read_ctrl_idle
++;
947 if (value
& MTL_DEBUG_RWCSTS
)
948 x
->mtl_rx_fifo_ctrl_active
++;
952 value
= readl(ioaddr
+ GMAC_DEBUG
);
954 if (value
& GMAC_DEBUG_TFCSTS_MASK
) {
955 u32 tfcsts
= (value
& GMAC_DEBUG_TFCSTS_MASK
)
956 >> GMAC_DEBUG_TFCSTS_SHIFT
;
958 if (tfcsts
== GMAC_DEBUG_TFCSTS_XFER
)
959 x
->mac_tx_frame_ctrl_xfer
++;
960 else if (tfcsts
== GMAC_DEBUG_TFCSTS_GEN_PAUSE
)
961 x
->mac_tx_frame_ctrl_pause
++;
962 else if (tfcsts
== GMAC_DEBUG_TFCSTS_WAIT
)
963 x
->mac_tx_frame_ctrl_wait
++;
965 x
->mac_tx_frame_ctrl_idle
++;
967 if (value
& GMAC_DEBUG_TPESTS
)
968 x
->mac_gmii_tx_proto_engine
++;
969 if (value
& GMAC_DEBUG_RFCFCSTS_MASK
)
970 x
->mac_rx_frame_ctrl_fifo
= (value
& GMAC_DEBUG_RFCFCSTS_MASK
)
971 >> GMAC_DEBUG_RFCFCSTS_SHIFT
;
972 if (value
& GMAC_DEBUG_RPESTS
)
973 x
->mac_gmii_rx_proto_engine
++;
976 static void dwmac4_set_mac_loopback(void __iomem
*ioaddr
, bool enable
)
978 u32 value
= readl(ioaddr
+ GMAC_CONFIG
);
981 value
|= GMAC_CONFIG_LM
;
983 value
&= ~GMAC_CONFIG_LM
;
985 writel(value
, ioaddr
+ GMAC_CONFIG
);
988 static void dwmac4_update_vlan_hash(struct mac_device_info
*hw
, u32 hash
,
989 __le16 perfect_match
, bool is_double
)
991 void __iomem
*ioaddr
= hw
->pcsr
;
994 writel(hash
, ioaddr
+ GMAC_VLAN_HASH_TABLE
);
996 value
= readl(ioaddr
+ GMAC_VLAN_TAG
);
999 value
|= GMAC_VLAN_VTHM
| GMAC_VLAN_ETV
;
1001 value
|= GMAC_VLAN_EDVLP
;
1002 value
|= GMAC_VLAN_ESVL
;
1003 value
|= GMAC_VLAN_DOVLTC
;
1006 writel(value
, ioaddr
+ GMAC_VLAN_TAG
);
1007 } else if (perfect_match
) {
1008 u32 value
= GMAC_VLAN_ETV
;
1011 value
|= GMAC_VLAN_EDVLP
;
1012 value
|= GMAC_VLAN_ESVL
;
1013 value
|= GMAC_VLAN_DOVLTC
;
1016 writel(value
| perfect_match
, ioaddr
+ GMAC_VLAN_TAG
);
1018 value
&= ~(GMAC_VLAN_VTHM
| GMAC_VLAN_ETV
);
1019 value
&= ~(GMAC_VLAN_EDVLP
| GMAC_VLAN_ESVL
);
1020 value
&= ~GMAC_VLAN_DOVLTC
;
1021 value
&= ~GMAC_VLAN_VID
;
1023 writel(value
, ioaddr
+ GMAC_VLAN_TAG
);
1027 static void dwmac4_sarc_configure(void __iomem
*ioaddr
, int val
)
1029 u32 value
= readl(ioaddr
+ GMAC_CONFIG
);
1031 value
&= ~GMAC_CONFIG_SARC
;
1032 value
|= val
<< GMAC_CONFIG_SARC_SHIFT
;
1034 writel(value
, ioaddr
+ GMAC_CONFIG
);
1037 static void dwmac4_enable_vlan(struct mac_device_info
*hw
, u32 type
)
1039 void __iomem
*ioaddr
= hw
->pcsr
;
1042 value
= readl(ioaddr
+ GMAC_VLAN_INCL
);
1043 value
|= GMAC_VLAN_VLTI
;
1044 value
|= GMAC_VLAN_CSVL
; /* Only use SVLAN */
1045 value
&= ~GMAC_VLAN_VLC
;
1046 value
|= (type
<< GMAC_VLAN_VLC_SHIFT
) & GMAC_VLAN_VLC
;
1047 writel(value
, ioaddr
+ GMAC_VLAN_INCL
);
1050 static void dwmac4_set_arp_offload(struct mac_device_info
*hw
, bool en
,
1053 void __iomem
*ioaddr
= hw
->pcsr
;
1056 writel(addr
, ioaddr
+ GMAC_ARP_ADDR
);
1058 value
= readl(ioaddr
+ GMAC_CONFIG
);
1060 value
|= GMAC_CONFIG_ARPEN
;
1062 value
&= ~GMAC_CONFIG_ARPEN
;
1063 writel(value
, ioaddr
+ GMAC_CONFIG
);
1066 static int dwmac4_config_l3_filter(struct mac_device_info
*hw
, u32 filter_no
,
1067 bool en
, bool ipv6
, bool sa
, bool inv
,
1070 void __iomem
*ioaddr
= hw
->pcsr
;
1073 value
= readl(ioaddr
+ GMAC_PACKET_FILTER
);
1074 value
|= GMAC_PACKET_FILTER_IPFE
;
1075 writel(value
, ioaddr
+ GMAC_PACKET_FILTER
);
1077 value
= readl(ioaddr
+ GMAC_L3L4_CTRL(filter_no
));
1079 /* For IPv6 not both SA/DA filters can be active */
1081 value
|= GMAC_L3PEN0
;
1082 value
&= ~(GMAC_L3SAM0
| GMAC_L3SAIM0
);
1083 value
&= ~(GMAC_L3DAM0
| GMAC_L3DAIM0
);
1085 value
|= GMAC_L3SAM0
;
1087 value
|= GMAC_L3SAIM0
;
1089 value
|= GMAC_L3DAM0
;
1091 value
|= GMAC_L3DAIM0
;
1094 value
&= ~GMAC_L3PEN0
;
1096 value
|= GMAC_L3SAM0
;
1098 value
|= GMAC_L3SAIM0
;
1100 value
|= GMAC_L3DAM0
;
1102 value
|= GMAC_L3DAIM0
;
1106 writel(value
, ioaddr
+ GMAC_L3L4_CTRL(filter_no
));
1109 writel(match
, ioaddr
+ GMAC_L3_ADDR0(filter_no
));
1111 writel(match
, ioaddr
+ GMAC_L3_ADDR1(filter_no
));
1115 writel(0, ioaddr
+ GMAC_L3L4_CTRL(filter_no
));
1120 static int dwmac4_config_l4_filter(struct mac_device_info
*hw
, u32 filter_no
,
1121 bool en
, bool udp
, bool sa
, bool inv
,
1124 void __iomem
*ioaddr
= hw
->pcsr
;
1127 value
= readl(ioaddr
+ GMAC_PACKET_FILTER
);
1128 value
|= GMAC_PACKET_FILTER_IPFE
;
1129 writel(value
, ioaddr
+ GMAC_PACKET_FILTER
);
1131 value
= readl(ioaddr
+ GMAC_L3L4_CTRL(filter_no
));
1133 value
|= GMAC_L4PEN0
;
1135 value
&= ~GMAC_L4PEN0
;
1138 value
&= ~(GMAC_L4SPM0
| GMAC_L4SPIM0
);
1139 value
&= ~(GMAC_L4DPM0
| GMAC_L4DPIM0
);
1141 value
|= GMAC_L4SPM0
;
1143 value
|= GMAC_L4SPIM0
;
1145 value
|= GMAC_L4DPM0
;
1147 value
|= GMAC_L4DPIM0
;
1150 writel(value
, ioaddr
+ GMAC_L3L4_CTRL(filter_no
));
1153 value
= match
& GMAC_L4SP0
;
1155 value
= (match
<< GMAC_L4DP0_SHIFT
) & GMAC_L4DP0
;
1158 writel(value
, ioaddr
+ GMAC_L4_ADDR(filter_no
));
1161 writel(0, ioaddr
+ GMAC_L3L4_CTRL(filter_no
));
1166 const struct stmmac_ops dwmac4_ops
= {
1167 .core_init
= dwmac4_core_init
,
1168 .set_mac
= stmmac_set_mac
,
1169 .rx_ipc
= dwmac4_rx_ipc_enable
,
1170 .rx_queue_enable
= dwmac4_rx_queue_enable
,
1171 .rx_queue_prio
= dwmac4_rx_queue_priority
,
1172 .tx_queue_prio
= dwmac4_tx_queue_priority
,
1173 .rx_queue_routing
= dwmac4_rx_queue_routing
,
1174 .prog_mtl_rx_algorithms
= dwmac4_prog_mtl_rx_algorithms
,
1175 .prog_mtl_tx_algorithms
= dwmac4_prog_mtl_tx_algorithms
,
1176 .set_mtl_tx_queue_weight
= dwmac4_set_mtl_tx_queue_weight
,
1177 .map_mtl_to_dma
= dwmac4_map_mtl_dma
,
1178 .config_cbs
= dwmac4_config_cbs
,
1179 .dump_regs
= dwmac4_dump_regs
,
1180 .host_irq_status
= dwmac4_irq_status
,
1181 .host_mtl_irq_status
= dwmac4_irq_mtl_status
,
1182 .flow_ctrl
= dwmac4_flow_ctrl
,
1184 .set_umac_addr
= dwmac4_set_umac_addr
,
1185 .get_umac_addr
= dwmac4_get_umac_addr
,
1186 .set_eee_mode
= dwmac4_set_eee_mode
,
1187 .reset_eee_mode
= dwmac4_reset_eee_mode
,
1188 .set_eee_lpi_entry_timer
= dwmac4_set_eee_lpi_entry_timer
,
1189 .set_eee_timer
= dwmac4_set_eee_timer
,
1190 .set_eee_pls
= dwmac4_set_eee_pls
,
1191 .pcs_ctrl_ane
= dwmac4_ctrl_ane
,
1192 .pcs_rane
= dwmac4_rane
,
1193 .pcs_get_adv_lp
= dwmac4_get_adv_lp
,
1194 .debug
= dwmac4_debug
,
1195 .set_filter
= dwmac4_set_filter
,
1196 .set_mac_loopback
= dwmac4_set_mac_loopback
,
1197 .update_vlan_hash
= dwmac4_update_vlan_hash
,
1198 .sarc_configure
= dwmac4_sarc_configure
,
1199 .enable_vlan
= dwmac4_enable_vlan
,
1200 .set_arp_offload
= dwmac4_set_arp_offload
,
1201 .config_l3_filter
= dwmac4_config_l3_filter
,
1202 .config_l4_filter
= dwmac4_config_l4_filter
,
1203 .add_hw_vlan_rx_fltr
= dwmac4_add_hw_vlan_rx_fltr
,
1204 .del_hw_vlan_rx_fltr
= dwmac4_del_hw_vlan_rx_fltr
,
1205 .restore_hw_vlan_rx_fltr
= dwmac4_restore_hw_vlan_rx_fltr
,
1208 const struct stmmac_ops dwmac410_ops
= {
1209 .core_init
= dwmac4_core_init
,
1210 .set_mac
= stmmac_dwmac4_set_mac
,
1211 .rx_ipc
= dwmac4_rx_ipc_enable
,
1212 .rx_queue_enable
= dwmac4_rx_queue_enable
,
1213 .rx_queue_prio
= dwmac4_rx_queue_priority
,
1214 .tx_queue_prio
= dwmac4_tx_queue_priority
,
1215 .rx_queue_routing
= dwmac4_rx_queue_routing
,
1216 .prog_mtl_rx_algorithms
= dwmac4_prog_mtl_rx_algorithms
,
1217 .prog_mtl_tx_algorithms
= dwmac4_prog_mtl_tx_algorithms
,
1218 .set_mtl_tx_queue_weight
= dwmac4_set_mtl_tx_queue_weight
,
1219 .map_mtl_to_dma
= dwmac4_map_mtl_dma
,
1220 .config_cbs
= dwmac4_config_cbs
,
1221 .dump_regs
= dwmac4_dump_regs
,
1222 .host_irq_status
= dwmac4_irq_status
,
1223 .host_mtl_irq_status
= dwmac4_irq_mtl_status
,
1224 .flow_ctrl
= dwmac4_flow_ctrl
,
1226 .set_umac_addr
= dwmac4_set_umac_addr
,
1227 .get_umac_addr
= dwmac4_get_umac_addr
,
1228 .set_eee_mode
= dwmac4_set_eee_mode
,
1229 .reset_eee_mode
= dwmac4_reset_eee_mode
,
1230 .set_eee_lpi_entry_timer
= dwmac4_set_eee_lpi_entry_timer
,
1231 .set_eee_timer
= dwmac4_set_eee_timer
,
1232 .set_eee_pls
= dwmac4_set_eee_pls
,
1233 .pcs_ctrl_ane
= dwmac4_ctrl_ane
,
1234 .pcs_rane
= dwmac4_rane
,
1235 .pcs_get_adv_lp
= dwmac4_get_adv_lp
,
1236 .debug
= dwmac4_debug
,
1237 .set_filter
= dwmac4_set_filter
,
1238 .flex_pps_config
= dwmac5_flex_pps_config
,
1239 .set_mac_loopback
= dwmac4_set_mac_loopback
,
1240 .update_vlan_hash
= dwmac4_update_vlan_hash
,
1241 .sarc_configure
= dwmac4_sarc_configure
,
1242 .enable_vlan
= dwmac4_enable_vlan
,
1243 .set_arp_offload
= dwmac4_set_arp_offload
,
1244 .config_l3_filter
= dwmac4_config_l3_filter
,
1245 .config_l4_filter
= dwmac4_config_l4_filter
,
1246 .est_configure
= dwmac5_est_configure
,
1247 .fpe_configure
= dwmac5_fpe_configure
,
1248 .add_hw_vlan_rx_fltr
= dwmac4_add_hw_vlan_rx_fltr
,
1249 .del_hw_vlan_rx_fltr
= dwmac4_del_hw_vlan_rx_fltr
,
1250 .restore_hw_vlan_rx_fltr
= dwmac4_restore_hw_vlan_rx_fltr
,
1253 const struct stmmac_ops dwmac510_ops
= {
1254 .core_init
= dwmac4_core_init
,
1255 .set_mac
= stmmac_dwmac4_set_mac
,
1256 .rx_ipc
= dwmac4_rx_ipc_enable
,
1257 .rx_queue_enable
= dwmac4_rx_queue_enable
,
1258 .rx_queue_prio
= dwmac4_rx_queue_priority
,
1259 .tx_queue_prio
= dwmac4_tx_queue_priority
,
1260 .rx_queue_routing
= dwmac4_rx_queue_routing
,
1261 .prog_mtl_rx_algorithms
= dwmac4_prog_mtl_rx_algorithms
,
1262 .prog_mtl_tx_algorithms
= dwmac4_prog_mtl_tx_algorithms
,
1263 .set_mtl_tx_queue_weight
= dwmac4_set_mtl_tx_queue_weight
,
1264 .map_mtl_to_dma
= dwmac4_map_mtl_dma
,
1265 .config_cbs
= dwmac4_config_cbs
,
1266 .dump_regs
= dwmac4_dump_regs
,
1267 .host_irq_status
= dwmac4_irq_status
,
1268 .host_mtl_irq_status
= dwmac4_irq_mtl_status
,
1269 .flow_ctrl
= dwmac4_flow_ctrl
,
1271 .set_umac_addr
= dwmac4_set_umac_addr
,
1272 .get_umac_addr
= dwmac4_get_umac_addr
,
1273 .set_eee_mode
= dwmac4_set_eee_mode
,
1274 .reset_eee_mode
= dwmac4_reset_eee_mode
,
1275 .set_eee_lpi_entry_timer
= dwmac4_set_eee_lpi_entry_timer
,
1276 .set_eee_timer
= dwmac4_set_eee_timer
,
1277 .set_eee_pls
= dwmac4_set_eee_pls
,
1278 .pcs_ctrl_ane
= dwmac4_ctrl_ane
,
1279 .pcs_rane
= dwmac4_rane
,
1280 .pcs_get_adv_lp
= dwmac4_get_adv_lp
,
1281 .debug
= dwmac4_debug
,
1282 .set_filter
= dwmac4_set_filter
,
1283 .safety_feat_config
= dwmac5_safety_feat_config
,
1284 .safety_feat_irq_status
= dwmac5_safety_feat_irq_status
,
1285 .safety_feat_dump
= dwmac5_safety_feat_dump
,
1286 .rxp_config
= dwmac5_rxp_config
,
1287 .flex_pps_config
= dwmac5_flex_pps_config
,
1288 .set_mac_loopback
= dwmac4_set_mac_loopback
,
1289 .update_vlan_hash
= dwmac4_update_vlan_hash
,
1290 .sarc_configure
= dwmac4_sarc_configure
,
1291 .enable_vlan
= dwmac4_enable_vlan
,
1292 .set_arp_offload
= dwmac4_set_arp_offload
,
1293 .config_l3_filter
= dwmac4_config_l3_filter
,
1294 .config_l4_filter
= dwmac4_config_l4_filter
,
1295 .est_configure
= dwmac5_est_configure
,
1296 .fpe_configure
= dwmac5_fpe_configure
,
1297 .add_hw_vlan_rx_fltr
= dwmac4_add_hw_vlan_rx_fltr
,
1298 .del_hw_vlan_rx_fltr
= dwmac4_del_hw_vlan_rx_fltr
,
1299 .restore_hw_vlan_rx_fltr
= dwmac4_restore_hw_vlan_rx_fltr
,
1302 static u32
dwmac4_get_num_vlan(void __iomem
*ioaddr
)
1306 val
= readl(ioaddr
+ GMAC_HW_FEATURE3
);
1307 switch (val
& GMAC_HW_FEAT_NRVF
) {
1333 int dwmac4_setup(struct stmmac_priv
*priv
)
1335 struct mac_device_info
*mac
= priv
->hw
;
1337 dev_info(priv
->device
, "\tDWMAC4/5\n");
1339 priv
->dev
->priv_flags
|= IFF_UNICAST_FLT
;
1340 mac
->pcsr
= priv
->ioaddr
;
1341 mac
->multicast_filter_bins
= priv
->plat
->multicast_filter_bins
;
1342 mac
->unicast_filter_entries
= priv
->plat
->unicast_filter_entries
;
1343 mac
->mcast_bits_log2
= 0;
1345 if (mac
->multicast_filter_bins
)
1346 mac
->mcast_bits_log2
= ilog2(mac
->multicast_filter_bins
);
1348 mac
->link
.duplex
= GMAC_CONFIG_DM
;
1349 mac
->link
.speed10
= GMAC_CONFIG_PS
;
1350 mac
->link
.speed100
= GMAC_CONFIG_FES
| GMAC_CONFIG_PS
;
1351 mac
->link
.speed1000
= 0;
1352 mac
->link
.speed_mask
= GMAC_CONFIG_FES
| GMAC_CONFIG_PS
;
1353 mac
->mii
.addr
= GMAC_MDIO_ADDR
;
1354 mac
->mii
.data
= GMAC_MDIO_DATA
;
1355 mac
->mii
.addr_shift
= 21;
1356 mac
->mii
.addr_mask
= GENMASK(25, 21);
1357 mac
->mii
.reg_shift
= 16;
1358 mac
->mii
.reg_mask
= GENMASK(20, 16);
1359 mac
->mii
.clk_csr_shift
= 8;
1360 mac
->mii
.clk_csr_mask
= GENMASK(11, 8);
1361 mac
->num_vlan
= dwmac4_get_num_vlan(priv
->ioaddr
);