2 * AMD 10Gb Ethernet driver
4 * This file is available to you under your choice of the following two
9 * Copyright (c) 2014 Advanced Micro Devices, Inc.
11 * This file is free software; you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or (at
14 * your option) any later version.
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * This file incorporates work covered by the following copyright and
26 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
27 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28 * Inc. unless otherwise expressly agreed to in writing between Synopsys
31 * The Software IS NOT an item of Licensed Software or Licensed Product
32 * under any End User Software License Agreement or Agreement for Licensed
33 * Product with Synopsys or any supplement thereto. Permission is hereby
34 * granted, free of charge, to any person obtaining a copy of this software
35 * annotated with this license and the Software, to deal in the Software
36 * without restriction, including without limitation the rights to use,
37 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 * of the Software, and to permit persons to whom the Software is furnished
39 * to do so, subject to the following conditions:
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
44 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54 * THE POSSIBILITY OF SUCH DAMAGE.
57 * License 2: Modified BSD
59 * Copyright (c) 2014 Advanced Micro Devices, Inc.
60 * All rights reserved.
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions are met:
64 * * Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 * * Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
69 * * Neither the name of Advanced Micro Devices, Inc. nor the
70 * names of its contributors may be used to endorse or promote products
71 * derived from this software without specific prior written permission.
73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84 * This file incorporates work covered by the following copyright and
86 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
87 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88 * Inc. unless otherwise expressly agreed to in writing between Synopsys
91 * The Software IS NOT an item of Licensed Software or Licensed Product
92 * under any End User Software License Agreement or Agreement for Licensed
93 * Product with Synopsys or any supplement thereto. Permission is hereby
94 * granted, free of charge, to any person obtaining a copy of this software
95 * annotated with this license and the Software, to deal in the Software
96 * without restriction, including without limitation the rights to use,
97 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98 * of the Software, and to permit persons to whom the Software is furnished
99 * to do so, subject to the following conditions:
101 * The above copyright notice and this permission notice shall be included
102 * in all copies or substantial portions of the Software.
104 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114 * THE POSSIBILITY OF SUCH DAMAGE.
117 #include <linux/phy.h>
118 #include <linux/clk.h>
119 #include <linux/bitrev.h>
120 #include <linux/crc32.h>
123 #include "xgbe-common.h"
125 static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
131 DBGPR("-->xgbe_usec_to_riwt\n");
133 rate = clk_get_rate(pdata->sysclk);
136 * Convert the input usec value to the watchdog timer value. Each
137 * watchdog timer value is equivalent to 256 clock cycles.
138 * Calculate the required value as:
139 * ( usec * ( system_clock_mhz / 10^6 ) / 256
141 ret = (usec * (rate / 1000000)) / 256;
143 DBGPR("<--xgbe_usec_to_riwt\n");
148 static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
154 DBGPR("-->xgbe_riwt_to_usec\n");
156 rate = clk_get_rate(pdata->sysclk);
159 * Convert the input watchdog timer value to the usec value. Each
160 * watchdog timer value is equivalent to 256 clock cycles.
161 * Calculate the required value as:
162 * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
164 ret = (riwt * 256) / (rate / 1000000);
166 DBGPR("<--xgbe_riwt_to_usec\n");
171 static int xgbe_config_pblx8(struct xgbe_prv_data *pdata)
173 struct xgbe_channel *channel;
176 channel = pdata->channel;
177 for (i = 0; i < pdata->channel_count; i++, channel++)
178 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8,
184 static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata)
186 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL);
189 static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata)
191 struct xgbe_channel *channel;
194 channel = pdata->channel;
195 for (i = 0; i < pdata->channel_count; i++, channel++) {
196 if (!channel->tx_ring)
199 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL,
206 static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata)
208 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL);
211 static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata)
213 struct xgbe_channel *channel;
216 channel = pdata->channel;
217 for (i = 0; i < pdata->channel_count; i++, channel++) {
218 if (!channel->rx_ring)
221 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL,
228 static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
230 struct xgbe_channel *channel;
233 channel = pdata->channel;
234 for (i = 0; i < pdata->channel_count; i++, channel++) {
235 if (!channel->tx_ring)
238 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP,
245 static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
249 for (i = 0; i < pdata->rx_q_count; i++)
250 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
255 static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
259 for (i = 0; i < pdata->tx_q_count; i++)
260 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
265 static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
270 for (i = 0; i < pdata->rx_q_count; i++)
271 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
276 static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
281 for (i = 0; i < pdata->tx_q_count; i++)
282 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
287 static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
289 struct xgbe_channel *channel;
292 channel = pdata->channel;
293 for (i = 0; i < pdata->channel_count; i++, channel++) {
294 if (!channel->rx_ring)
297 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT,
304 static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
309 static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
311 struct xgbe_channel *channel;
314 channel = pdata->channel;
315 for (i = 0; i < pdata->channel_count; i++, channel++) {
316 if (!channel->rx_ring)
319 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ,
324 static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
326 struct xgbe_channel *channel;
329 channel = pdata->channel;
330 for (i = 0; i < pdata->channel_count; i++, channel++) {
331 if (!channel->tx_ring)
334 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1);
338 static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
340 unsigned int max_q_count, q_count;
341 unsigned int reg, reg_val;
344 /* Clear MTL flow control */
345 for (i = 0; i < pdata->rx_q_count; i++)
346 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
348 /* Clear MAC flow control */
349 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
350 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
352 for (i = 0; i < q_count; i++) {
353 reg_val = XGMAC_IOREAD(pdata, reg);
354 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
355 XGMAC_IOWRITE(pdata, reg, reg_val);
357 reg += MAC_QTFCR_INC;
363 static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
365 unsigned int max_q_count, q_count;
366 unsigned int reg, reg_val;
369 /* Set MTL flow control */
370 for (i = 0; i < pdata->rx_q_count; i++)
371 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 1);
373 /* Set MAC flow control */
374 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
375 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
377 for (i = 0; i < q_count; i++) {
378 reg_val = XGMAC_IOREAD(pdata, reg);
380 /* Enable transmit flow control */
381 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
383 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
385 XGMAC_IOWRITE(pdata, reg, reg_val);
387 reg += MAC_QTFCR_INC;
393 static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
395 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
400 static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
402 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
407 static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
409 struct ieee_pfc *pfc = pdata->pfc;
411 if (pdata->tx_pause || (pfc && pfc->pfc_en))
412 xgbe_enable_tx_flow_control(pdata);
414 xgbe_disable_tx_flow_control(pdata);
419 static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
421 struct ieee_pfc *pfc = pdata->pfc;
423 if (pdata->rx_pause || (pfc && pfc->pfc_en))
424 xgbe_enable_rx_flow_control(pdata);
426 xgbe_disable_rx_flow_control(pdata);
431 static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
433 struct ieee_pfc *pfc = pdata->pfc;
435 xgbe_config_tx_flow_control(pdata);
436 xgbe_config_rx_flow_control(pdata);
438 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
439 (pfc && pfc->pfc_en) ? 1 : 0);
442 static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
444 struct xgbe_channel *channel;
445 unsigned int dma_ch_isr, dma_ch_ier;
448 channel = pdata->channel;
449 for (i = 0; i < pdata->channel_count; i++, channel++) {
450 /* Clear all the interrupts which are set */
451 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
452 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
454 /* Clear all interrupt enable bits */
457 /* Enable following interrupts
458 * NIE - Normal Interrupt Summary Enable
459 * AIE - Abnormal Interrupt Summary Enable
460 * FBEE - Fatal Bus Error Enable
462 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
463 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
464 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
466 if (channel->tx_ring) {
467 /* Enable the following Tx interrupts
468 * TIE - Transmit Interrupt Enable (unless polling)
470 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
472 if (channel->rx_ring) {
473 /* Enable following Rx interrupts
474 * RBUE - Receive Buffer Unavailable Enable
475 * RIE - Receive Interrupt Enable
477 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
478 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
481 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
485 static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
487 unsigned int mtl_q_isr;
488 unsigned int q_count, i;
490 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
491 for (i = 0; i < q_count; i++) {
492 /* Clear all the interrupts which are set */
493 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
494 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
496 /* No MTL interrupts to be enabled */
497 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
501 static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
503 unsigned int mac_ier = 0;
505 /* Enable Timestamp interrupt */
506 XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
508 XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
510 /* Enable all counter interrupts */
511 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
512 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
515 static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
517 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
522 static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
524 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
529 static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
531 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
536 static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
539 unsigned int val = enable ? 1 : 0;
541 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
544 DBGPR(" %s promiscuous mode\n", enable ? "entering" : "leaving");
545 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
550 static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
553 unsigned int val = enable ? 1 : 0;
555 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
558 DBGPR(" %s allmulti mode\n", enable ? "entering" : "leaving");
559 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
564 static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
565 struct netdev_hw_addr *ha, unsigned int *mac_reg)
567 unsigned int mac_addr_hi, mac_addr_lo;
574 mac_addr = (u8 *)&mac_addr_lo;
575 mac_addr[0] = ha->addr[0];
576 mac_addr[1] = ha->addr[1];
577 mac_addr[2] = ha->addr[2];
578 mac_addr[3] = ha->addr[3];
579 mac_addr = (u8 *)&mac_addr_hi;
580 mac_addr[0] = ha->addr[4];
581 mac_addr[1] = ha->addr[5];
583 DBGPR(" adding mac address %pM at 0x%04x\n", ha->addr,
586 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
589 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
590 *mac_reg += MAC_MACA_INC;
591 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
592 *mac_reg += MAC_MACA_INC;
595 static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
597 struct net_device *netdev = pdata->netdev;
598 struct netdev_hw_addr *ha;
599 unsigned int mac_reg;
600 unsigned int addn_macs;
602 mac_reg = MAC_MACA1HR;
603 addn_macs = pdata->hw_feat.addn_mac;
605 if (netdev_uc_count(netdev) > addn_macs) {
606 xgbe_set_promiscuous_mode(pdata, 1);
608 netdev_for_each_uc_addr(ha, netdev) {
609 xgbe_set_mac_reg(pdata, ha, &mac_reg);
613 if (netdev_mc_count(netdev) > addn_macs) {
614 xgbe_set_all_multicast_mode(pdata, 1);
616 netdev_for_each_mc_addr(ha, netdev) {
617 xgbe_set_mac_reg(pdata, ha, &mac_reg);
623 /* Clear remaining additional MAC address entries */
625 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
628 static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
630 struct net_device *netdev = pdata->netdev;
631 struct netdev_hw_addr *ha;
632 unsigned int hash_reg;
633 unsigned int hash_table_shift, hash_table_count;
634 u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
638 hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
639 hash_table_count = pdata->hw_feat.hash_table_size / 32;
640 memset(hash_table, 0, sizeof(hash_table));
642 /* Build the MAC Hash Table register values */
643 netdev_for_each_uc_addr(ha, netdev) {
644 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
645 crc >>= hash_table_shift;
646 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
649 netdev_for_each_mc_addr(ha, netdev) {
650 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
651 crc >>= hash_table_shift;
652 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
655 /* Set the MAC Hash Table registers */
657 for (i = 0; i < hash_table_count; i++) {
658 XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
659 hash_reg += MAC_HTR_INC;
663 static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
665 if (pdata->hw_feat.hash_table_size)
666 xgbe_set_mac_hash_table(pdata);
668 xgbe_set_mac_addn_addrs(pdata);
673 static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
675 unsigned int mac_addr_hi, mac_addr_lo;
677 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
678 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
679 (addr[1] << 8) | (addr[0] << 0);
681 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
682 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
687 static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
690 unsigned int mmd_address;
693 if (mmd_reg & MII_ADDR_C45)
694 mmd_address = mmd_reg & ~MII_ADDR_C45;
696 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
698 /* The PCS registers are accessed using mmio. The underlying APB3
699 * management interface uses indirect addressing to access the MMD
700 * register sets. This requires accessing of the PCS register in two
701 * phases, an address phase and a data phase.
703 * The mmio interface is based on 32-bit offsets and values. All
704 * register offsets must therefore be adjusted by left shifting the
705 * offset 2 bits and reading 32 bits of data.
707 mutex_lock(&pdata->xpcs_mutex);
708 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
709 mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
710 mutex_unlock(&pdata->xpcs_mutex);
715 static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
716 int mmd_reg, int mmd_data)
718 unsigned int mmd_address;
720 if (mmd_reg & MII_ADDR_C45)
721 mmd_address = mmd_reg & ~MII_ADDR_C45;
723 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
725 /* The PCS registers are accessed using mmio. The underlying APB3
726 * management interface uses indirect addressing to access the MMD
727 * register sets. This requires accessing of the PCS register in two
728 * phases, an address phase and a data phase.
730 * The mmio interface is based on 32-bit offsets and values. All
731 * register offsets must therefore be adjusted by left shifting the
732 * offset 2 bits and reading 32 bits of data.
734 mutex_lock(&pdata->xpcs_mutex);
735 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
736 XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
737 mutex_unlock(&pdata->xpcs_mutex);
740 static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
742 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
745 static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
747 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
752 static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
754 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
759 static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
761 /* Put the VLAN tag in the Rx descriptor */
762 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
764 /* Don't check the VLAN type */
765 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
767 /* Check only C-TAG (0x8100) packets */
768 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
770 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
771 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
773 /* Enable VLAN tag stripping */
774 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
779 static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
781 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
786 static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
788 /* Enable VLAN filtering */
789 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
791 /* Enable VLAN Hash Table filtering */
792 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
794 /* Disable VLAN tag inverse matching */
795 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
797 /* Only filter on the lower 12-bits of the VLAN tag */
798 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
800 /* In order for the VLAN Hash Table filtering to be effective,
801 * the VLAN tag identifier in the VLAN Tag Register must not
802 * be zero. Set the VLAN tag identifier to "1" to enable the
803 * VLAN Hash Table filtering. This implies that a VLAN tag of
804 * 1 will always pass filtering.
806 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
811 static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
813 /* Disable VLAN filtering */
814 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
820 #define CRCPOLY_LE 0xedb88320
822 static u32 xgbe_vid_crc32_le(__le16 vid_le)
824 u32 poly = CRCPOLY_LE;
827 unsigned char *data = (unsigned char *)&vid_le;
828 unsigned char data_byte = 0;
831 bits = get_bitmask_order(VLAN_VID_MASK);
832 for (i = 0; i < bits; i++) {
834 data_byte = data[i / 8];
836 temp = ((crc & 1) ^ data_byte) & 1;
847 static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
852 u16 vlan_hash_table = 0;
854 /* Generate the VLAN Hash Table value */
855 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
856 /* Get the CRC32 value of the VLAN ID */
857 vid_le = cpu_to_le16(vid);
858 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
860 vlan_hash_table |= (1 << crc);
863 /* Set the VLAN Hash Table filtering register */
864 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
869 static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
871 struct xgbe_ring_desc *rdesc = rdata->rdesc;
873 /* Reset the Tx descriptor
874 * Set buffer 1 (lo) address to zero
875 * Set buffer 1 (hi) address to zero
876 * Reset all other control bits (IC, TTSE, B2L & B1L)
877 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
884 /* Make sure ownership is written to the descriptor */
888 static void xgbe_tx_desc_init(struct xgbe_channel *channel)
890 struct xgbe_ring *ring = channel->tx_ring;
891 struct xgbe_ring_data *rdata;
893 int start_index = ring->cur;
895 DBGPR("-->tx_desc_init\n");
897 /* Initialze all descriptors */
898 for (i = 0; i < ring->rdesc_count; i++) {
899 rdata = XGBE_GET_DESC_DATA(ring, i);
901 /* Initialize Tx descriptor */
902 xgbe_tx_desc_reset(rdata);
905 /* Update the total number of Tx descriptors */
906 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
908 /* Update the starting address of descriptor ring */
909 rdata = XGBE_GET_DESC_DATA(ring, start_index);
910 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
911 upper_32_bits(rdata->rdesc_dma));
912 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
913 lower_32_bits(rdata->rdesc_dma));
915 DBGPR("<--tx_desc_init\n");
918 static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
920 struct xgbe_ring_desc *rdesc = rdata->rdesc;
922 /* Reset the Rx descriptor
923 * Set buffer 1 (lo) address to dma address (lo)
924 * Set buffer 1 (hi) address to dma address (hi)
925 * Set buffer 2 (lo) address to zero
926 * Set buffer 2 (hi) address to zero and set control bits
929 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->rx_dma));
930 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->rx_dma));
934 if (rdata->interrupt)
935 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
937 /* Since the Rx DMA engine is likely running, make sure everything
938 * is written to the descriptor(s) before setting the OWN bit
943 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
945 /* Make sure ownership is written to the descriptor */
949 static void xgbe_rx_desc_init(struct xgbe_channel *channel)
951 struct xgbe_prv_data *pdata = channel->pdata;
952 struct xgbe_ring *ring = channel->rx_ring;
953 struct xgbe_ring_data *rdata;
954 unsigned int start_index = ring->cur;
955 unsigned int rx_coalesce, rx_frames;
958 DBGPR("-->rx_desc_init\n");
960 rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
961 rx_frames = pdata->rx_frames;
963 /* Initialize all descriptors */
964 for (i = 0; i < ring->rdesc_count; i++) {
965 rdata = XGBE_GET_DESC_DATA(ring, i);
967 /* Set interrupt on completion bit as appropriate */
968 if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames)))
969 rdata->interrupt = 0;
971 rdata->interrupt = 1;
973 /* Initialize Rx descriptor */
974 xgbe_rx_desc_reset(rdata);
977 /* Update the total number of Rx descriptors */
978 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
980 /* Update the starting address of descriptor ring */
981 rdata = XGBE_GET_DESC_DATA(ring, start_index);
982 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
983 upper_32_bits(rdata->rdesc_dma));
984 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
985 lower_32_bits(rdata->rdesc_dma));
987 /* Update the Rx Descriptor Tail Pointer */
988 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
989 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
990 lower_32_bits(rdata->rdesc_dma));
992 DBGPR("<--rx_desc_init\n");
995 static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
998 /* Set the addend register value and tell the device */
999 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1000 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1002 /* Wait for addend update to complete */
1003 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1007 static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1010 /* Set the time values and tell the device */
1011 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1012 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1013 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1015 /* Wait for time update to complete */
1016 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1020 static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1024 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1025 nsec *= NSEC_PER_SEC;
1026 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1031 static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1033 unsigned int tx_snr;
1036 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1037 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1040 nsec = XGMAC_IOREAD(pdata, MAC_TXSSR);
1041 nsec *= NSEC_PER_SEC;
1047 static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1048 struct xgbe_ring_desc *rdesc)
1052 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1053 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1054 nsec = le32_to_cpu(rdesc->desc1);
1056 nsec |= le32_to_cpu(rdesc->desc0);
1057 if (nsec != 0xffffffffffffffffULL) {
1058 packet->rx_tstamp = nsec;
1059 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1065 static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1066 unsigned int mac_tscr)
1068 /* Set one nano-second accuracy */
1069 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1071 /* Set fine timestamp update */
1072 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1074 /* Overwrite earlier timestamps */
1075 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1077 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1079 /* Exit if timestamping is not enabled */
1080 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1083 /* Initialize time registers */
1084 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1085 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1086 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1087 xgbe_set_tstamp_time(pdata, 0, 0);
1089 /* Initialize the timecounter */
1090 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1091 ktime_to_ns(ktime_get_real()));
1096 static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
1098 struct ieee_ets *ets = pdata->ets;
1099 unsigned int total_weight, min_weight, weight;
1105 /* Set Tx to deficit weighted round robin scheduling algorithm (when
1106 * traffic class is using ETS algorithm)
1108 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
1110 /* Set Traffic Class algorithms */
1111 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
1112 min_weight = total_weight / 100;
1116 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1117 switch (ets->tc_tsa[i]) {
1118 case IEEE_8021QAZ_TSA_STRICT:
1119 DBGPR(" TC%u using SP\n", i);
1120 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1123 case IEEE_8021QAZ_TSA_ETS:
1124 weight = total_weight * ets->tc_tx_bw[i] / 100;
1125 weight = clamp(weight, min_weight, total_weight);
1127 DBGPR(" TC%u using DWRR (weight %u)\n", i, weight);
1128 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1130 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
1137 static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
1139 struct ieee_pfc *pfc = pdata->pfc;
1140 struct ieee_ets *ets = pdata->ets;
1141 unsigned int mask, reg, reg_val;
1142 unsigned int tc, prio;
1147 for (tc = 0; tc < pdata->hw_feat.tc_cnt; tc++) {
1149 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
1150 if ((pfc->pfc_en & (1 << prio)) &&
1151 (ets->prio_tc[prio] == tc))
1152 mask |= (1 << prio);
1156 DBGPR(" TC%u PFC mask=%#x\n", tc, mask);
1157 reg = MTL_TCPM0R + (MTL_TCPM_INC * (tc / MTL_TCPM_TC_PER_REG));
1158 reg_val = XGMAC_IOREAD(pdata, reg);
1160 reg_val &= ~(0xff << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1161 reg_val |= (mask << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1163 XGMAC_IOWRITE(pdata, reg, reg_val);
1166 xgbe_config_flow_control(pdata);
1169 static void xgbe_dev_xmit(struct xgbe_channel *channel)
1171 struct xgbe_prv_data *pdata = channel->pdata;
1172 struct xgbe_ring *ring = channel->tx_ring;
1173 struct xgbe_ring_data *rdata;
1174 struct xgbe_ring_desc *rdesc;
1175 struct xgbe_packet_data *packet = &ring->packet_data;
1176 unsigned int csum, tso, vlan;
1177 unsigned int tso_context, vlan_context;
1178 unsigned int tx_coalesce, tx_frames;
1179 int start_index = ring->cur;
1182 DBGPR("-->xgbe_dev_xmit\n");
1184 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1186 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1188 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1191 if (tso && (packet->mss != ring->tx.cur_mss))
1196 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1201 tx_coalesce = (pdata->tx_usecs || pdata->tx_frames) ? 1 : 0;
1202 tx_frames = pdata->tx_frames;
1203 if (tx_coalesce && !channel->tx_timer_active)
1204 ring->coalesce_count = 0;
1206 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1207 rdesc = rdata->rdesc;
1209 /* Create a context descriptor if this is a TSO packet */
1210 if (tso_context || vlan_context) {
1212 DBGPR(" TSO context descriptor, mss=%u\n",
1215 /* Set the MSS size */
1216 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1219 /* Mark it as a CONTEXT descriptor */
1220 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1223 /* Indicate this descriptor contains the MSS */
1224 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1227 ring->tx.cur_mss = packet->mss;
1231 DBGPR(" VLAN context descriptor, ctag=%u\n",
1234 /* Mark it as a CONTEXT descriptor */
1235 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1238 /* Set the VLAN tag */
1239 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1240 VT, packet->vlan_ctag);
1242 /* Indicate this descriptor contains the VLAN tag */
1243 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1246 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1250 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1251 rdesc = rdata->rdesc;
1254 /* Update buffer address (for TSO this is the header) */
1255 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1256 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1258 /* Update the buffer length */
1259 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1260 rdata->skb_dma_len);
1262 /* VLAN tag insertion check */
1264 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1265 TX_NORMAL_DESC2_VLAN_INSERT);
1267 /* Timestamp enablement check */
1268 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1269 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1271 /* Set IC bit based on Tx coalescing settings */
1272 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1273 if (tx_coalesce && (!tx_frames ||
1274 (++ring->coalesce_count % tx_frames)))
1276 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1278 /* Mark it as First Descriptor */
1279 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1281 /* Mark it as a NORMAL descriptor */
1282 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1284 /* Set OWN bit if not the first descriptor */
1285 if (ring->cur != start_index)
1286 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1290 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1291 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1292 packet->tcp_payload_len);
1293 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1294 packet->tcp_header_len / 4);
1296 /* Enable CRC and Pad Insertion */
1297 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1299 /* Enable HW CSUM */
1301 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1304 /* Set the total length to be transmitted */
1305 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1309 for (i = ring->cur - start_index + 1; i < packet->rdesc_count; i++) {
1311 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1312 rdesc = rdata->rdesc;
1314 /* Update buffer address */
1315 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1316 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1318 /* Update the buffer length */
1319 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1320 rdata->skb_dma_len);
1322 /* Set IC bit based on Tx coalescing settings */
1323 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1324 if (tx_coalesce && (!tx_frames ||
1325 (++ring->coalesce_count % tx_frames)))
1327 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1330 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1332 /* Mark it as NORMAL descriptor */
1333 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1335 /* Enable HW CSUM */
1337 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1341 /* Set LAST bit for the last descriptor */
1342 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1344 /* In case the Tx DMA engine is running, make sure everything
1345 * is written to the descriptor(s) before setting the OWN bit
1346 * for the first descriptor
1350 /* Set OWN bit for the first descriptor */
1351 rdata = XGBE_GET_DESC_DATA(ring, start_index);
1352 rdesc = rdata->rdesc;
1353 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1355 #ifdef XGMAC_ENABLE_TX_DESC_DUMP
1356 xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
1359 /* Make sure ownership is written to the descriptor */
1362 /* Issue a poll command to Tx DMA by writing address
1363 * of next immediate free descriptor */
1365 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1366 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1367 lower_32_bits(rdata->rdesc_dma));
1369 /* Start the Tx coalescing timer */
1370 if (tx_coalesce && !channel->tx_timer_active) {
1371 channel->tx_timer_active = 1;
1372 hrtimer_start(&channel->tx_timer,
1373 ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
1377 DBGPR(" %s: descriptors %u to %u written\n",
1378 channel->name, start_index & (ring->rdesc_count - 1),
1379 (ring->cur - 1) & (ring->rdesc_count - 1));
1381 DBGPR("<--xgbe_dev_xmit\n");
1384 static int xgbe_dev_read(struct xgbe_channel *channel)
1386 struct xgbe_ring *ring = channel->rx_ring;
1387 struct xgbe_ring_data *rdata;
1388 struct xgbe_ring_desc *rdesc;
1389 struct xgbe_packet_data *packet = &ring->packet_data;
1390 struct net_device *netdev = channel->pdata->netdev;
1391 unsigned int err, etlt;
1393 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1395 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1396 rdesc = rdata->rdesc;
1398 /* Check for data availability */
1399 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1402 #ifdef XGMAC_ENABLE_RX_DESC_DUMP
1403 xgbe_dump_rx_desc(ring, rdesc, ring->cur);
1406 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1407 /* Timestamp Context Descriptor */
1408 xgbe_get_rx_tstamp(packet, rdesc);
1410 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1412 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1417 /* Normal Descriptor, be sure Context Descriptor bit is off */
1418 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1420 /* Indicate if a Context Descriptor is next */
1421 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1422 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1425 /* Get the packet length */
1426 rdata->len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
1428 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1429 /* Not all the data has been transferred for this packet */
1430 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1435 /* This is the last of the data for this packet */
1436 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1439 /* Set checksum done indicator as appropriate */
1440 if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
1441 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1444 /* Check for errors (only valid in last descriptor) */
1445 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1446 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1447 DBGPR(" err=%u, etlt=%#x\n", err, etlt);
1449 if (!err || (err && !etlt)) {
1450 if ((etlt == 0x09) &&
1451 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1452 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1454 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1457 DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
1460 if ((etlt == 0x05) || (etlt == 0x06))
1461 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1464 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1468 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1469 ring->cur & (ring->rdesc_count - 1), ring->cur);
1474 static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1476 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1477 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1480 static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1482 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1483 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1486 static int xgbe_enable_int(struct xgbe_channel *channel,
1487 enum xgbe_int int_id)
1489 unsigned int dma_ch_ier;
1491 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1494 case XGMAC_INT_DMA_CH_SR_TI:
1495 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1497 case XGMAC_INT_DMA_CH_SR_TPS:
1498 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
1500 case XGMAC_INT_DMA_CH_SR_TBU:
1501 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
1503 case XGMAC_INT_DMA_CH_SR_RI:
1504 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
1506 case XGMAC_INT_DMA_CH_SR_RBU:
1507 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
1509 case XGMAC_INT_DMA_CH_SR_RPS:
1510 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1512 case XGMAC_INT_DMA_CH_SR_TI_RI:
1513 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1514 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
1516 case XGMAC_INT_DMA_CH_SR_FBE:
1517 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
1519 case XGMAC_INT_DMA_ALL:
1520 dma_ch_ier |= channel->saved_ier;
1526 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1531 static int xgbe_disable_int(struct xgbe_channel *channel,
1532 enum xgbe_int int_id)
1534 unsigned int dma_ch_ier;
1536 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1539 case XGMAC_INT_DMA_CH_SR_TI:
1540 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1542 case XGMAC_INT_DMA_CH_SR_TPS:
1543 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
1545 case XGMAC_INT_DMA_CH_SR_TBU:
1546 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
1548 case XGMAC_INT_DMA_CH_SR_RI:
1549 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
1551 case XGMAC_INT_DMA_CH_SR_RBU:
1552 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
1554 case XGMAC_INT_DMA_CH_SR_RPS:
1555 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1557 case XGMAC_INT_DMA_CH_SR_TI_RI:
1558 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1559 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
1561 case XGMAC_INT_DMA_CH_SR_FBE:
1562 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
1564 case XGMAC_INT_DMA_ALL:
1565 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
1566 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
1572 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1577 static int xgbe_exit(struct xgbe_prv_data *pdata)
1579 unsigned int count = 2000;
1581 DBGPR("-->xgbe_exit\n");
1583 /* Issue a software reset */
1584 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1585 usleep_range(10, 15);
1587 /* Poll Until Poll Condition */
1588 while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1589 usleep_range(500, 600);
1594 DBGPR("<--xgbe_exit\n");
1599 static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1601 unsigned int i, count;
1603 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
1606 for (i = 0; i < pdata->tx_q_count; i++)
1607 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1609 /* Poll Until Poll Condition */
1610 for (i = 0; i < pdata->tx_q_count; i++) {
1612 while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
1614 usleep_range(500, 600);
1623 static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1625 /* Set enhanced addressing mode */
1626 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1628 /* Set the System Bus mode */
1629 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
1630 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
1633 static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1635 unsigned int arcache, awcache;
1638 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
1639 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
1640 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
1641 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
1642 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
1643 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
1644 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1647 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
1648 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
1649 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
1650 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
1651 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
1652 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
1653 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
1654 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
1655 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1658 static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1662 /* Set Tx to weighted round robin scheduling algorithm */
1663 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1665 /* Set Tx traffic classes to use WRR algorithm with equal weights */
1666 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1667 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1669 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
1672 /* Set Rx to strict priority algorithm */
1673 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1676 static unsigned int xgbe_calculate_per_queue_fifo(unsigned int fifo_size,
1677 unsigned int queue_count)
1679 unsigned int q_fifo_size = 0;
1680 enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1682 /* Calculate Tx/Rx fifo share per queue */
1683 switch (fifo_size) {
1685 q_fifo_size = XGBE_FIFO_SIZE_B(128);
1688 q_fifo_size = XGBE_FIFO_SIZE_B(256);
1691 q_fifo_size = XGBE_FIFO_SIZE_B(512);
1694 q_fifo_size = XGBE_FIFO_SIZE_KB(1);
1697 q_fifo_size = XGBE_FIFO_SIZE_KB(2);
1700 q_fifo_size = XGBE_FIFO_SIZE_KB(4);
1703 q_fifo_size = XGBE_FIFO_SIZE_KB(8);
1706 q_fifo_size = XGBE_FIFO_SIZE_KB(16);
1709 q_fifo_size = XGBE_FIFO_SIZE_KB(32);
1712 q_fifo_size = XGBE_FIFO_SIZE_KB(64);
1715 q_fifo_size = XGBE_FIFO_SIZE_KB(128);
1718 q_fifo_size = XGBE_FIFO_SIZE_KB(256);
1722 /* The configured value is not the actual amount of fifo RAM */
1723 q_fifo_size = min_t(unsigned int, XGBE_FIFO_MAX, q_fifo_size);
1725 q_fifo_size = q_fifo_size / queue_count;
1727 /* Set the queue fifo size programmable value */
1728 if (q_fifo_size >= XGBE_FIFO_SIZE_KB(256))
1729 p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
1730 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(128))
1731 p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
1732 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(64))
1733 p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
1734 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(32))
1735 p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
1736 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(16))
1737 p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
1738 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(8))
1739 p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
1740 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(4))
1741 p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
1742 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(2))
1743 p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
1744 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(1))
1745 p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
1746 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(512))
1747 p_fifo = XGMAC_MTL_FIFO_SIZE_512;
1748 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(256))
1749 p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1754 static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
1756 enum xgbe_mtl_fifo_size fifo_size;
1759 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
1762 for (i = 0; i < pdata->tx_q_count; i++)
1763 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
1765 netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
1766 pdata->tx_q_count, ((fifo_size + 1) * 256));
1769 static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
1771 enum xgbe_mtl_fifo_size fifo_size;
1774 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
1777 for (i = 0; i < pdata->rx_q_count; i++)
1778 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
1780 netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
1781 pdata->rx_q_count, ((fifo_size + 1) * 256));
1784 static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
1786 unsigned int qptc, qptc_extra, queue;
1787 unsigned int prio_queues;
1788 unsigned int ppq, ppq_extra, prio;
1790 unsigned int i, j, reg, reg_val;
1792 /* Map the MTL Tx Queues to Traffic Classes
1793 * Note: Tx Queues >= Traffic Classes
1795 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
1796 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
1798 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
1799 for (j = 0; j < qptc; j++) {
1800 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
1801 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1803 pdata->q2tc_map[queue++] = i;
1806 if (i < qptc_extra) {
1807 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
1808 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1810 pdata->q2tc_map[queue++] = i;
1814 /* Map the 8 VLAN priority values to available MTL Rx queues */
1815 prio_queues = min_t(unsigned int, IEEE_8021QAZ_MAX_TCS,
1817 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
1818 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
1822 for (i = 0, prio = 0; i < prio_queues;) {
1824 for (j = 0; j < ppq; j++) {
1825 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
1826 mask |= (1 << prio);
1827 pdata->prio2q_map[prio++] = i;
1830 if (i < ppq_extra) {
1831 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
1832 mask |= (1 << prio);
1833 pdata->prio2q_map[prio++] = i;
1836 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
1838 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
1841 XGMAC_IOWRITE(pdata, reg, reg_val);
1842 reg += MAC_RQC2_INC;
1846 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
1849 for (i = 0; i < pdata->rx_q_count;) {
1850 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
1852 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
1855 XGMAC_IOWRITE(pdata, reg, reg_val);
1857 reg += MTL_RQDCM_INC;
1862 static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
1866 for (i = 0; i < pdata->rx_q_count; i++) {
1867 /* Activate flow control when less than 4k left in fifo */
1868 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
1870 /* De-activate flow control when more than 6k left in fifo */
1871 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
1875 static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
1877 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
1879 /* Filtering is done using perfect filtering and hash filtering */
1880 if (pdata->hw_feat.hash_table_size) {
1881 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
1882 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
1883 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
1887 static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
1891 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
1893 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1896 static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
1898 if (pdata->netdev->features & NETIF_F_RXCSUM)
1899 xgbe_enable_rx_csum(pdata);
1901 xgbe_disable_rx_csum(pdata);
1904 static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
1906 /* Indicate that VLAN Tx CTAGs come from context descriptors */
1907 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
1908 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
1910 /* Set the current VLAN Hash Table register value */
1911 xgbe_update_vlan_hash_table(pdata);
1913 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
1914 xgbe_enable_rx_vlan_filtering(pdata);
1916 xgbe_disable_rx_vlan_filtering(pdata);
1918 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
1919 xgbe_enable_rx_vlan_stripping(pdata);
1921 xgbe_disable_rx_vlan_stripping(pdata);
1924 static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
1930 /* These registers are always 64 bit */
1931 case MMC_TXOCTETCOUNT_GB_LO:
1932 case MMC_TXOCTETCOUNT_G_LO:
1933 case MMC_RXOCTETCOUNT_GB_LO:
1934 case MMC_RXOCTETCOUNT_G_LO:
1942 val = XGMAC_IOREAD(pdata, reg_lo);
1945 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
1950 static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
1952 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1953 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
1955 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
1956 stats->txoctetcount_gb +=
1957 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
1959 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
1960 stats->txframecount_gb +=
1961 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
1963 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
1964 stats->txbroadcastframes_g +=
1965 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1967 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
1968 stats->txmulticastframes_g +=
1969 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1971 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
1972 stats->tx64octets_gb +=
1973 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
1975 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
1976 stats->tx65to127octets_gb +=
1977 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
1979 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
1980 stats->tx128to255octets_gb +=
1981 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
1983 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
1984 stats->tx256to511octets_gb +=
1985 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
1987 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
1988 stats->tx512to1023octets_gb +=
1989 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1991 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
1992 stats->tx1024tomaxoctets_gb +=
1993 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1995 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
1996 stats->txunicastframes_gb +=
1997 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
1999 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2000 stats->txmulticastframes_gb +=
2001 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
2003 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2004 stats->txbroadcastframes_g +=
2005 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
2007 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2008 stats->txunderflowerror +=
2009 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
2011 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2012 stats->txoctetcount_g +=
2013 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
2015 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2016 stats->txframecount_g +=
2017 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
2019 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2020 stats->txpauseframes +=
2021 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
2023 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2024 stats->txvlanframes_g +=
2025 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
2028 static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2030 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2031 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2033 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2034 stats->rxframecount_gb +=
2035 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
2037 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2038 stats->rxoctetcount_gb +=
2039 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
2041 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2042 stats->rxoctetcount_g +=
2043 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
2045 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2046 stats->rxbroadcastframes_g +=
2047 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
2049 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2050 stats->rxmulticastframes_g +=
2051 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
2053 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2054 stats->rxcrcerror +=
2055 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
2057 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2058 stats->rxrunterror +=
2059 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
2061 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2062 stats->rxjabbererror +=
2063 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
2065 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
2066 stats->rxundersize_g +=
2067 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
2069 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
2070 stats->rxoversize_g +=
2071 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
2073 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
2074 stats->rx64octets_gb +=
2075 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
2077 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
2078 stats->rx65to127octets_gb +=
2079 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
2081 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
2082 stats->rx128to255octets_gb +=
2083 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
2085 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
2086 stats->rx256to511octets_gb +=
2087 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
2089 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
2090 stats->rx512to1023octets_gb +=
2091 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
2093 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
2094 stats->rx1024tomaxoctets_gb +=
2095 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
2097 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
2098 stats->rxunicastframes_g +=
2099 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
2101 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
2102 stats->rxlengtherror +=
2103 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
2105 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
2106 stats->rxoutofrangetype +=
2107 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
2109 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
2110 stats->rxpauseframes +=
2111 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
2113 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
2114 stats->rxfifooverflow +=
2115 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
2117 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
2118 stats->rxvlanframes_gb +=
2119 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
2121 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
2122 stats->rxwatchdogerror +=
2123 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
2126 static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
2128 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2130 /* Freeze counters */
2131 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
2133 stats->txoctetcount_gb +=
2134 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
2136 stats->txframecount_gb +=
2137 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
2139 stats->txbroadcastframes_g +=
2140 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
2142 stats->txmulticastframes_g +=
2143 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
2145 stats->tx64octets_gb +=
2146 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
2148 stats->tx65to127octets_gb +=
2149 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
2151 stats->tx128to255octets_gb +=
2152 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
2154 stats->tx256to511octets_gb +=
2155 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
2157 stats->tx512to1023octets_gb +=
2158 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
2160 stats->tx1024tomaxoctets_gb +=
2161 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
2163 stats->txunicastframes_gb +=
2164 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
2166 stats->txmulticastframes_gb +=
2167 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
2169 stats->txbroadcastframes_g +=
2170 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
2172 stats->txunderflowerror +=
2173 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
2175 stats->txoctetcount_g +=
2176 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
2178 stats->txframecount_g +=
2179 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
2181 stats->txpauseframes +=
2182 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
2184 stats->txvlanframes_g +=
2185 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
2187 stats->rxframecount_gb +=
2188 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
2190 stats->rxoctetcount_gb +=
2191 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
2193 stats->rxoctetcount_g +=
2194 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
2196 stats->rxbroadcastframes_g +=
2197 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
2199 stats->rxmulticastframes_g +=
2200 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
2202 stats->rxcrcerror +=
2203 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
2205 stats->rxrunterror +=
2206 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
2208 stats->rxjabbererror +=
2209 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
2211 stats->rxundersize_g +=
2212 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
2214 stats->rxoversize_g +=
2215 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
2217 stats->rx64octets_gb +=
2218 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
2220 stats->rx65to127octets_gb +=
2221 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
2223 stats->rx128to255octets_gb +=
2224 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
2226 stats->rx256to511octets_gb +=
2227 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
2229 stats->rx512to1023octets_gb +=
2230 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
2232 stats->rx1024tomaxoctets_gb +=
2233 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
2235 stats->rxunicastframes_g +=
2236 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
2238 stats->rxlengtherror +=
2239 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
2241 stats->rxoutofrangetype +=
2242 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
2244 stats->rxpauseframes +=
2245 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
2247 stats->rxfifooverflow +=
2248 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
2250 stats->rxvlanframes_gb +=
2251 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
2253 stats->rxwatchdogerror +=
2254 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
2256 /* Un-freeze counters */
2257 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
2260 static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
2262 /* Set counters to reset on read */
2263 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
2265 /* Reset the counters */
2266 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
2269 static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
2271 struct xgbe_channel *channel;
2274 /* Enable each Tx DMA channel */
2275 channel = pdata->channel;
2276 for (i = 0; i < pdata->channel_count; i++, channel++) {
2277 if (!channel->tx_ring)
2280 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2283 /* Enable each Tx queue */
2284 for (i = 0; i < pdata->tx_q_count; i++)
2285 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
2289 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2292 static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
2294 struct xgbe_channel *channel;
2297 /* Disable MAC Tx */
2298 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2300 /* Disable each Tx queue */
2301 for (i = 0; i < pdata->tx_q_count; i++)
2302 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
2304 /* Disable each Tx DMA channel */
2305 channel = pdata->channel;
2306 for (i = 0; i < pdata->channel_count; i++, channel++) {
2307 if (!channel->tx_ring)
2310 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2314 static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
2316 struct xgbe_channel *channel;
2317 unsigned int reg_val, i;
2319 /* Enable each Rx DMA channel */
2320 channel = pdata->channel;
2321 for (i = 0; i < pdata->channel_count; i++, channel++) {
2322 if (!channel->rx_ring)
2325 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2328 /* Enable each Rx queue */
2330 for (i = 0; i < pdata->rx_q_count; i++)
2331 reg_val |= (0x02 << (i << 1));
2332 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
2335 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
2336 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
2337 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
2338 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
2341 static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
2343 struct xgbe_channel *channel;
2346 /* Disable MAC Rx */
2347 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
2348 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
2349 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
2350 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
2352 /* Disable each Rx queue */
2353 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
2355 /* Disable each Rx DMA channel */
2356 channel = pdata->channel;
2357 for (i = 0; i < pdata->channel_count; i++, channel++) {
2358 if (!channel->rx_ring)
2361 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2365 static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
2367 struct xgbe_channel *channel;
2370 /* Enable each Tx DMA channel */
2371 channel = pdata->channel;
2372 for (i = 0; i < pdata->channel_count; i++, channel++) {
2373 if (!channel->tx_ring)
2376 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2380 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2383 static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
2385 struct xgbe_channel *channel;
2388 /* Disable MAC Tx */
2389 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2391 /* Disable each Tx DMA channel */
2392 channel = pdata->channel;
2393 for (i = 0; i < pdata->channel_count; i++, channel++) {
2394 if (!channel->tx_ring)
2397 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2401 static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2403 struct xgbe_channel *channel;
2406 /* Enable each Rx DMA channel */
2407 channel = pdata->channel;
2408 for (i = 0; i < pdata->channel_count; i++, channel++) {
2409 if (!channel->rx_ring)
2412 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2416 static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2418 struct xgbe_channel *channel;
2421 /* Disable each Rx DMA channel */
2422 channel = pdata->channel;
2423 for (i = 0; i < pdata->channel_count; i++, channel++) {
2424 if (!channel->rx_ring)
2427 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2431 static int xgbe_init(struct xgbe_prv_data *pdata)
2433 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2436 DBGPR("-->xgbe_init\n");
2438 /* Flush Tx queues */
2439 ret = xgbe_flush_tx_queues(pdata);
2444 * Initialize DMA related features
2446 xgbe_config_dma_bus(pdata);
2447 xgbe_config_dma_cache(pdata);
2448 xgbe_config_osp_mode(pdata);
2449 xgbe_config_pblx8(pdata);
2450 xgbe_config_tx_pbl_val(pdata);
2451 xgbe_config_rx_pbl_val(pdata);
2452 xgbe_config_rx_coalesce(pdata);
2453 xgbe_config_tx_coalesce(pdata);
2454 xgbe_config_rx_buffer_size(pdata);
2455 xgbe_config_tso_mode(pdata);
2456 desc_if->wrapper_tx_desc_init(pdata);
2457 desc_if->wrapper_rx_desc_init(pdata);
2458 xgbe_enable_dma_interrupts(pdata);
2461 * Initialize MTL related features
2463 xgbe_config_mtl_mode(pdata);
2464 xgbe_config_queue_mapping(pdata);
2465 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2466 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2467 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2468 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2469 xgbe_config_tx_fifo_size(pdata);
2470 xgbe_config_rx_fifo_size(pdata);
2471 xgbe_config_flow_control_threshold(pdata);
2472 /*TODO: Error Packet and undersized good Packet forwarding enable
2475 xgbe_config_dcb_tc(pdata);
2476 xgbe_config_dcb_pfc(pdata);
2477 xgbe_enable_mtl_interrupts(pdata);
2480 * Initialize MAC related features
2482 xgbe_config_mac_address(pdata);
2483 xgbe_config_jumbo_enable(pdata);
2484 xgbe_config_flow_control(pdata);
2485 xgbe_config_checksum_offload(pdata);
2486 xgbe_config_vlan_support(pdata);
2487 xgbe_config_mmc(pdata);
2488 xgbe_enable_mac_interrupts(pdata);
2490 DBGPR("<--xgbe_init\n");
2495 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2497 DBGPR("-->xgbe_init_function_ptrs\n");
2499 hw_if->tx_complete = xgbe_tx_complete;
2501 hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
2502 hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
2503 hw_if->add_mac_addresses = xgbe_add_mac_addresses;
2504 hw_if->set_mac_address = xgbe_set_mac_address;
2506 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2507 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2509 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2510 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
2511 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
2512 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
2513 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
2515 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2516 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2518 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2519 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2520 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2522 hw_if->enable_tx = xgbe_enable_tx;
2523 hw_if->disable_tx = xgbe_disable_tx;
2524 hw_if->enable_rx = xgbe_enable_rx;
2525 hw_if->disable_rx = xgbe_disable_rx;
2527 hw_if->powerup_tx = xgbe_powerup_tx;
2528 hw_if->powerdown_tx = xgbe_powerdown_tx;
2529 hw_if->powerup_rx = xgbe_powerup_rx;
2530 hw_if->powerdown_rx = xgbe_powerdown_rx;
2532 hw_if->dev_xmit = xgbe_dev_xmit;
2533 hw_if->dev_read = xgbe_dev_read;
2534 hw_if->enable_int = xgbe_enable_int;
2535 hw_if->disable_int = xgbe_disable_int;
2536 hw_if->init = xgbe_init;
2537 hw_if->exit = xgbe_exit;
2539 /* Descriptor related Sequences have to be initialized here */
2540 hw_if->tx_desc_init = xgbe_tx_desc_init;
2541 hw_if->rx_desc_init = xgbe_rx_desc_init;
2542 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2543 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2544 hw_if->is_last_desc = xgbe_is_last_desc;
2545 hw_if->is_context_desc = xgbe_is_context_desc;
2548 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2549 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2551 /* For RX coalescing */
2552 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2553 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2554 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2555 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2557 /* For RX and TX threshold config */
2558 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2559 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2561 /* For RX and TX Store and Forward Mode config */
2562 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2563 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2565 /* For TX DMA Operating on Second Frame config */
2566 hw_if->config_osp_mode = xgbe_config_osp_mode;
2568 /* For RX and TX PBL config */
2569 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2570 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2571 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2572 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2573 hw_if->config_pblx8 = xgbe_config_pblx8;
2575 /* For MMC statistics support */
2576 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2577 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2578 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2580 /* For PTP config */
2581 hw_if->config_tstamp = xgbe_config_tstamp;
2582 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
2583 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
2584 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
2585 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
2587 /* For Data Center Bridging config */
2588 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
2589 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
2591 DBGPR("<--xgbe_init_function_ptrs\n");