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)
885 static void xgbe_tx_desc_init(struct xgbe_channel *channel)
887 struct xgbe_ring *ring = channel->tx_ring;
888 struct xgbe_ring_data *rdata;
889 struct xgbe_ring_desc *rdesc;
891 int start_index = ring->cur;
893 DBGPR("-->tx_desc_init\n");
895 /* Initialze all descriptors */
896 for (i = 0; i < ring->rdesc_count; i++) {
897 rdata = XGBE_GET_DESC_DATA(ring, i);
898 rdesc = rdata->rdesc;
900 /* Initialize Tx descriptor
901 * Set buffer 1 (lo) address to zero
902 * Set buffer 1 (hi) address to zero
903 * Reset all other control bits (IC, TTSE, B2L & B1L)
904 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC,
913 /* Make sure everything is written to the descriptor(s) before
914 * telling the device about them
918 /* Update the total number of Tx descriptors */
919 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
921 /* Update the starting address of descriptor ring */
922 rdata = XGBE_GET_DESC_DATA(ring, start_index);
923 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
924 upper_32_bits(rdata->rdesc_dma));
925 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
926 lower_32_bits(rdata->rdesc_dma));
928 DBGPR("<--tx_desc_init\n");
931 static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
933 struct xgbe_ring_desc *rdesc = rdata->rdesc;
935 /* Reset the Rx descriptor
936 * Set buffer 1 (lo) address to dma address (lo)
937 * Set buffer 1 (hi) address to dma address (hi)
938 * Set buffer 2 (lo) address to zero
939 * Set buffer 2 (hi) address to zero and set control bits
942 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
943 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
947 if (rdata->interrupt)
948 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
950 /* Since the Rx DMA engine is likely running, make sure everything
951 * is written to the descriptor(s) before setting the OWN bit
956 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
958 /* Make sure ownership is written to the descriptor */
962 static void xgbe_rx_desc_init(struct xgbe_channel *channel)
964 struct xgbe_prv_data *pdata = channel->pdata;
965 struct xgbe_ring *ring = channel->rx_ring;
966 struct xgbe_ring_data *rdata;
967 struct xgbe_ring_desc *rdesc;
968 unsigned int start_index = ring->cur;
969 unsigned int rx_coalesce, rx_frames;
972 DBGPR("-->rx_desc_init\n");
974 rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
975 rx_frames = pdata->rx_frames;
977 /* Initialize all descriptors */
978 for (i = 0; i < ring->rdesc_count; i++) {
979 rdata = XGBE_GET_DESC_DATA(ring, i);
980 rdesc = rdata->rdesc;
982 /* Initialize Rx descriptor
983 * Set buffer 1 (lo) address to dma address (lo)
984 * Set buffer 1 (hi) address to dma address (hi)
985 * Set buffer 2 (lo) address to zero
986 * Set buffer 2 (hi) address to zero and set control
987 * bits OWN and INTE appropriateley
989 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
990 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
993 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
994 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
995 rdata->interrupt = 1;
996 if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames))) {
997 /* Clear interrupt on completion bit */
998 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE,
1000 rdata->interrupt = 0;
1004 /* Make sure everything is written to the descriptors before
1005 * telling the device about them
1009 /* Update the total number of Rx descriptors */
1010 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
1012 /* Update the starting address of descriptor ring */
1013 rdata = XGBE_GET_DESC_DATA(ring, start_index);
1014 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
1015 upper_32_bits(rdata->rdesc_dma));
1016 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
1017 lower_32_bits(rdata->rdesc_dma));
1019 /* Update the Rx Descriptor Tail Pointer */
1020 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
1021 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
1022 lower_32_bits(rdata->rdesc_dma));
1024 DBGPR("<--rx_desc_init\n");
1027 static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
1028 unsigned int addend)
1030 /* Set the addend register value and tell the device */
1031 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1032 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1034 /* Wait for addend update to complete */
1035 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1039 static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1042 /* Set the time values and tell the device */
1043 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1044 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1045 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1047 /* Wait for time update to complete */
1048 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1052 static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1056 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1057 nsec *= NSEC_PER_SEC;
1058 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1063 static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1065 unsigned int tx_snr;
1068 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1069 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1072 nsec = XGMAC_IOREAD(pdata, MAC_TXSSR);
1073 nsec *= NSEC_PER_SEC;
1079 static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1080 struct xgbe_ring_desc *rdesc)
1084 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1085 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1086 nsec = le32_to_cpu(rdesc->desc1);
1088 nsec |= le32_to_cpu(rdesc->desc0);
1089 if (nsec != 0xffffffffffffffffULL) {
1090 packet->rx_tstamp = nsec;
1091 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1097 static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1098 unsigned int mac_tscr)
1100 /* Set one nano-second accuracy */
1101 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1103 /* Set fine timestamp update */
1104 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1106 /* Overwrite earlier timestamps */
1107 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1109 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1111 /* Exit if timestamping is not enabled */
1112 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1115 /* Initialize time registers */
1116 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1117 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1118 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1119 xgbe_set_tstamp_time(pdata, 0, 0);
1121 /* Initialize the timecounter */
1122 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1123 ktime_to_ns(ktime_get_real()));
1128 static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
1130 struct ieee_ets *ets = pdata->ets;
1131 unsigned int total_weight, min_weight, weight;
1137 /* Set Tx to deficit weighted round robin scheduling algorithm (when
1138 * traffic class is using ETS algorithm)
1140 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
1142 /* Set Traffic Class algorithms */
1143 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
1144 min_weight = total_weight / 100;
1148 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1149 switch (ets->tc_tsa[i]) {
1150 case IEEE_8021QAZ_TSA_STRICT:
1151 DBGPR(" TC%u using SP\n", i);
1152 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1155 case IEEE_8021QAZ_TSA_ETS:
1156 weight = total_weight * ets->tc_tx_bw[i] / 100;
1157 weight = clamp(weight, min_weight, total_weight);
1159 DBGPR(" TC%u using DWRR (weight %u)\n", i, weight);
1160 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1162 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
1169 static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
1171 struct ieee_pfc *pfc = pdata->pfc;
1172 struct ieee_ets *ets = pdata->ets;
1173 unsigned int mask, reg, reg_val;
1174 unsigned int tc, prio;
1179 for (tc = 0; tc < pdata->hw_feat.tc_cnt; tc++) {
1181 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
1182 if ((pfc->pfc_en & (1 << prio)) &&
1183 (ets->prio_tc[prio] == tc))
1184 mask |= (1 << prio);
1188 DBGPR(" TC%u PFC mask=%#x\n", tc, mask);
1189 reg = MTL_TCPM0R + (MTL_TCPM_INC * (tc / MTL_TCPM_TC_PER_REG));
1190 reg_val = XGMAC_IOREAD(pdata, reg);
1192 reg_val &= ~(0xff << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1193 reg_val |= (mask << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1195 XGMAC_IOWRITE(pdata, reg, reg_val);
1198 xgbe_config_flow_control(pdata);
1201 static void xgbe_dev_xmit(struct xgbe_channel *channel)
1203 struct xgbe_prv_data *pdata = channel->pdata;
1204 struct xgbe_ring *ring = channel->tx_ring;
1205 struct xgbe_ring_data *rdata;
1206 struct xgbe_ring_desc *rdesc;
1207 struct xgbe_packet_data *packet = &ring->packet_data;
1208 unsigned int csum, tso, vlan;
1209 unsigned int tso_context, vlan_context;
1210 unsigned int tx_coalesce, tx_frames;
1211 int start_index = ring->cur;
1214 DBGPR("-->xgbe_dev_xmit\n");
1216 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1218 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1220 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1223 if (tso && (packet->mss != ring->tx.cur_mss))
1228 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1233 tx_coalesce = (pdata->tx_usecs || pdata->tx_frames) ? 1 : 0;
1234 tx_frames = pdata->tx_frames;
1235 if (tx_coalesce && !channel->tx_timer_active)
1236 ring->coalesce_count = 0;
1238 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1239 rdesc = rdata->rdesc;
1241 /* Create a context descriptor if this is a TSO packet */
1242 if (tso_context || vlan_context) {
1244 DBGPR(" TSO context descriptor, mss=%u\n",
1247 /* Set the MSS size */
1248 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1251 /* Mark it as a CONTEXT descriptor */
1252 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1255 /* Indicate this descriptor contains the MSS */
1256 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1259 ring->tx.cur_mss = packet->mss;
1263 DBGPR(" VLAN context descriptor, ctag=%u\n",
1266 /* Mark it as a CONTEXT descriptor */
1267 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1270 /* Set the VLAN tag */
1271 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1272 VT, packet->vlan_ctag);
1274 /* Indicate this descriptor contains the VLAN tag */
1275 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1278 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1282 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1283 rdesc = rdata->rdesc;
1286 /* Update buffer address (for TSO this is the header) */
1287 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1288 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1290 /* Update the buffer length */
1291 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1292 rdata->skb_dma_len);
1294 /* VLAN tag insertion check */
1296 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1297 TX_NORMAL_DESC2_VLAN_INSERT);
1299 /* Timestamp enablement check */
1300 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1301 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1303 /* Set IC bit based on Tx coalescing settings */
1304 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1305 if (tx_coalesce && (!tx_frames ||
1306 (++ring->coalesce_count % tx_frames)))
1308 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1310 /* Mark it as First Descriptor */
1311 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1313 /* Mark it as a NORMAL descriptor */
1314 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1316 /* Set OWN bit if not the first descriptor */
1317 if (ring->cur != start_index)
1318 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1322 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1323 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1324 packet->tcp_payload_len);
1325 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1326 packet->tcp_header_len / 4);
1328 /* Enable CRC and Pad Insertion */
1329 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1331 /* Enable HW CSUM */
1333 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1336 /* Set the total length to be transmitted */
1337 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1341 for (i = ring->cur - start_index + 1; i < packet->rdesc_count; i++) {
1343 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1344 rdesc = rdata->rdesc;
1346 /* Update buffer address */
1347 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1348 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1350 /* Update the buffer length */
1351 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1352 rdata->skb_dma_len);
1354 /* Set IC bit based on Tx coalescing settings */
1355 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1356 if (tx_coalesce && (!tx_frames ||
1357 (++ring->coalesce_count % tx_frames)))
1359 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1362 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1364 /* Mark it as NORMAL descriptor */
1365 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1367 /* Enable HW CSUM */
1369 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1373 /* Set LAST bit for the last descriptor */
1374 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1376 /* In case the Tx DMA engine is running, make sure everything
1377 * is written to the descriptor(s) before setting the OWN bit
1378 * for the first descriptor
1382 /* Set OWN bit for the first descriptor */
1383 rdata = XGBE_GET_DESC_DATA(ring, start_index);
1384 rdesc = rdata->rdesc;
1385 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1387 #ifdef XGMAC_ENABLE_TX_DESC_DUMP
1388 xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
1391 /* Make sure ownership is written to the descriptor */
1394 /* Issue a poll command to Tx DMA by writing address
1395 * of next immediate free descriptor */
1397 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1398 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1399 lower_32_bits(rdata->rdesc_dma));
1401 /* Start the Tx coalescing timer */
1402 if (tx_coalesce && !channel->tx_timer_active) {
1403 channel->tx_timer_active = 1;
1404 hrtimer_start(&channel->tx_timer,
1405 ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
1409 DBGPR(" %s: descriptors %u to %u written\n",
1410 channel->name, start_index & (ring->rdesc_count - 1),
1411 (ring->cur - 1) & (ring->rdesc_count - 1));
1413 DBGPR("<--xgbe_dev_xmit\n");
1416 static int xgbe_dev_read(struct xgbe_channel *channel)
1418 struct xgbe_ring *ring = channel->rx_ring;
1419 struct xgbe_ring_data *rdata;
1420 struct xgbe_ring_desc *rdesc;
1421 struct xgbe_packet_data *packet = &ring->packet_data;
1422 struct net_device *netdev = channel->pdata->netdev;
1423 unsigned int err, etlt;
1425 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1427 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1428 rdesc = rdata->rdesc;
1430 /* Check for data availability */
1431 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1434 #ifdef XGMAC_ENABLE_RX_DESC_DUMP
1435 xgbe_dump_rx_desc(ring, rdesc, ring->cur);
1438 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1439 /* Timestamp Context Descriptor */
1440 xgbe_get_rx_tstamp(packet, rdesc);
1442 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1444 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1449 /* Normal Descriptor, be sure Context Descriptor bit is off */
1450 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1452 /* Indicate if a Context Descriptor is next */
1453 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1454 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1457 /* Get the packet length */
1458 rdata->len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
1460 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1461 /* Not all the data has been transferred for this packet */
1462 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1467 /* This is the last of the data for this packet */
1468 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1471 /* Set checksum done indicator as appropriate */
1472 if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
1473 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1476 /* Check for errors (only valid in last descriptor) */
1477 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1478 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1479 DBGPR(" err=%u, etlt=%#x\n", err, etlt);
1481 if (!err || (err && !etlt)) {
1482 if ((etlt == 0x09) &&
1483 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1484 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1486 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1489 DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
1492 if ((etlt == 0x05) || (etlt == 0x06))
1493 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1496 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1500 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1501 ring->cur & (ring->rdesc_count - 1), ring->cur);
1506 static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1508 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1509 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1512 static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1514 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1515 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1518 static int xgbe_enable_int(struct xgbe_channel *channel,
1519 enum xgbe_int int_id)
1521 unsigned int dma_ch_ier;
1523 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1526 case XGMAC_INT_DMA_CH_SR_TI:
1527 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1529 case XGMAC_INT_DMA_CH_SR_TPS:
1530 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
1532 case XGMAC_INT_DMA_CH_SR_TBU:
1533 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
1535 case XGMAC_INT_DMA_CH_SR_RI:
1536 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
1538 case XGMAC_INT_DMA_CH_SR_RBU:
1539 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
1541 case XGMAC_INT_DMA_CH_SR_RPS:
1542 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1544 case XGMAC_INT_DMA_CH_SR_TI_RI:
1545 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1546 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
1548 case XGMAC_INT_DMA_CH_SR_FBE:
1549 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
1551 case XGMAC_INT_DMA_ALL:
1552 dma_ch_ier |= channel->saved_ier;
1558 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1563 static int xgbe_disable_int(struct xgbe_channel *channel,
1564 enum xgbe_int int_id)
1566 unsigned int dma_ch_ier;
1568 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1571 case XGMAC_INT_DMA_CH_SR_TI:
1572 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1574 case XGMAC_INT_DMA_CH_SR_TPS:
1575 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
1577 case XGMAC_INT_DMA_CH_SR_TBU:
1578 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
1580 case XGMAC_INT_DMA_CH_SR_RI:
1581 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
1583 case XGMAC_INT_DMA_CH_SR_RBU:
1584 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
1586 case XGMAC_INT_DMA_CH_SR_RPS:
1587 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1589 case XGMAC_INT_DMA_CH_SR_TI_RI:
1590 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1591 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
1593 case XGMAC_INT_DMA_CH_SR_FBE:
1594 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
1596 case XGMAC_INT_DMA_ALL:
1597 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
1598 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
1604 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1609 static int xgbe_exit(struct xgbe_prv_data *pdata)
1611 unsigned int count = 2000;
1613 DBGPR("-->xgbe_exit\n");
1615 /* Issue a software reset */
1616 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1617 usleep_range(10, 15);
1619 /* Poll Until Poll Condition */
1620 while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1621 usleep_range(500, 600);
1626 DBGPR("<--xgbe_exit\n");
1631 static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1633 unsigned int i, count;
1635 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
1638 for (i = 0; i < pdata->tx_q_count; i++)
1639 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1641 /* Poll Until Poll Condition */
1642 for (i = 0; i < pdata->tx_q_count; i++) {
1644 while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
1646 usleep_range(500, 600);
1655 static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1657 /* Set enhanced addressing mode */
1658 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1660 /* Set the System Bus mode */
1661 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
1662 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
1665 static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1667 unsigned int arcache, awcache;
1670 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
1671 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
1672 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
1673 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
1674 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
1675 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
1676 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1679 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
1680 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
1681 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
1682 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
1683 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
1684 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
1685 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
1686 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
1687 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1690 static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1694 /* Set Tx to weighted round robin scheduling algorithm */
1695 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1697 /* Set Tx traffic classes to use WRR algorithm with equal weights */
1698 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1699 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1701 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
1704 /* Set Rx to strict priority algorithm */
1705 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1708 static unsigned int xgbe_calculate_per_queue_fifo(unsigned int fifo_size,
1709 unsigned int queue_count)
1711 unsigned int q_fifo_size = 0;
1712 enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1714 /* Calculate Tx/Rx fifo share per queue */
1715 switch (fifo_size) {
1717 q_fifo_size = XGBE_FIFO_SIZE_B(128);
1720 q_fifo_size = XGBE_FIFO_SIZE_B(256);
1723 q_fifo_size = XGBE_FIFO_SIZE_B(512);
1726 q_fifo_size = XGBE_FIFO_SIZE_KB(1);
1729 q_fifo_size = XGBE_FIFO_SIZE_KB(2);
1732 q_fifo_size = XGBE_FIFO_SIZE_KB(4);
1735 q_fifo_size = XGBE_FIFO_SIZE_KB(8);
1738 q_fifo_size = XGBE_FIFO_SIZE_KB(16);
1741 q_fifo_size = XGBE_FIFO_SIZE_KB(32);
1744 q_fifo_size = XGBE_FIFO_SIZE_KB(64);
1747 q_fifo_size = XGBE_FIFO_SIZE_KB(128);
1750 q_fifo_size = XGBE_FIFO_SIZE_KB(256);
1754 /* The configured value is not the actual amount of fifo RAM */
1755 q_fifo_size = min_t(unsigned int, XGBE_FIFO_MAX, q_fifo_size);
1757 q_fifo_size = q_fifo_size / queue_count;
1759 /* Set the queue fifo size programmable value */
1760 if (q_fifo_size >= XGBE_FIFO_SIZE_KB(256))
1761 p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
1762 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(128))
1763 p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
1764 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(64))
1765 p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
1766 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(32))
1767 p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
1768 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(16))
1769 p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
1770 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(8))
1771 p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
1772 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(4))
1773 p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
1774 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(2))
1775 p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
1776 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(1))
1777 p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
1778 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(512))
1779 p_fifo = XGMAC_MTL_FIFO_SIZE_512;
1780 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(256))
1781 p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1786 static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
1788 enum xgbe_mtl_fifo_size fifo_size;
1791 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
1794 for (i = 0; i < pdata->tx_q_count; i++)
1795 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
1797 netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
1798 pdata->tx_q_count, ((fifo_size + 1) * 256));
1801 static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
1803 enum xgbe_mtl_fifo_size fifo_size;
1806 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
1809 for (i = 0; i < pdata->rx_q_count; i++)
1810 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
1812 netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
1813 pdata->rx_q_count, ((fifo_size + 1) * 256));
1816 static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
1818 unsigned int qptc, qptc_extra, queue;
1819 unsigned int prio_queues;
1820 unsigned int ppq, ppq_extra, prio;
1822 unsigned int i, j, reg, reg_val;
1824 /* Map the MTL Tx Queues to Traffic Classes
1825 * Note: Tx Queues >= Traffic Classes
1827 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
1828 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
1830 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
1831 for (j = 0; j < qptc; j++) {
1832 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
1833 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1835 pdata->q2tc_map[queue++] = i;
1838 if (i < qptc_extra) {
1839 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
1840 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1842 pdata->q2tc_map[queue++] = i;
1846 /* Map the 8 VLAN priority values to available MTL Rx queues */
1847 prio_queues = min_t(unsigned int, IEEE_8021QAZ_MAX_TCS,
1849 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
1850 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
1854 for (i = 0, prio = 0; i < prio_queues;) {
1856 for (j = 0; j < ppq; j++) {
1857 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
1858 mask |= (1 << prio);
1859 pdata->prio2q_map[prio++] = i;
1862 if (i < ppq_extra) {
1863 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
1864 mask |= (1 << prio);
1865 pdata->prio2q_map[prio++] = i;
1868 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
1870 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
1873 XGMAC_IOWRITE(pdata, reg, reg_val);
1874 reg += MAC_RQC2_INC;
1878 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
1881 for (i = 0; i < pdata->rx_q_count;) {
1882 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
1884 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
1887 XGMAC_IOWRITE(pdata, reg, reg_val);
1889 reg += MTL_RQDCM_INC;
1894 static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
1898 for (i = 0; i < pdata->rx_q_count; i++) {
1899 /* Activate flow control when less than 4k left in fifo */
1900 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
1902 /* De-activate flow control when more than 6k left in fifo */
1903 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
1907 static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
1909 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
1911 /* Filtering is done using perfect filtering and hash filtering */
1912 if (pdata->hw_feat.hash_table_size) {
1913 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
1914 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
1915 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
1919 static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
1923 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
1925 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1928 static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
1930 if (pdata->netdev->features & NETIF_F_RXCSUM)
1931 xgbe_enable_rx_csum(pdata);
1933 xgbe_disable_rx_csum(pdata);
1936 static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
1938 /* Indicate that VLAN Tx CTAGs come from context descriptors */
1939 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
1940 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
1942 /* Set the current VLAN Hash Table register value */
1943 xgbe_update_vlan_hash_table(pdata);
1945 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
1946 xgbe_enable_rx_vlan_filtering(pdata);
1948 xgbe_disable_rx_vlan_filtering(pdata);
1950 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
1951 xgbe_enable_rx_vlan_stripping(pdata);
1953 xgbe_disable_rx_vlan_stripping(pdata);
1956 static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
1962 /* These registers are always 64 bit */
1963 case MMC_TXOCTETCOUNT_GB_LO:
1964 case MMC_TXOCTETCOUNT_G_LO:
1965 case MMC_RXOCTETCOUNT_GB_LO:
1966 case MMC_RXOCTETCOUNT_G_LO:
1974 val = XGMAC_IOREAD(pdata, reg_lo);
1977 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
1982 static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
1984 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1985 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
1987 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
1988 stats->txoctetcount_gb +=
1989 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
1991 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
1992 stats->txframecount_gb +=
1993 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
1995 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
1996 stats->txbroadcastframes_g +=
1997 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1999 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
2000 stats->txmulticastframes_g +=
2001 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
2003 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
2004 stats->tx64octets_gb +=
2005 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
2007 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
2008 stats->tx65to127octets_gb +=
2009 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
2011 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
2012 stats->tx128to255octets_gb +=
2013 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
2015 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
2016 stats->tx256to511octets_gb +=
2017 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
2019 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
2020 stats->tx512to1023octets_gb +=
2021 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
2023 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
2024 stats->tx1024tomaxoctets_gb +=
2025 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
2027 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
2028 stats->txunicastframes_gb +=
2029 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
2031 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2032 stats->txmulticastframes_gb +=
2033 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
2035 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2036 stats->txbroadcastframes_g +=
2037 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
2039 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2040 stats->txunderflowerror +=
2041 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
2043 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2044 stats->txoctetcount_g +=
2045 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
2047 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2048 stats->txframecount_g +=
2049 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
2051 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2052 stats->txpauseframes +=
2053 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
2055 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2056 stats->txvlanframes_g +=
2057 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
2060 static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2062 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2063 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2065 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2066 stats->rxframecount_gb +=
2067 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
2069 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2070 stats->rxoctetcount_gb +=
2071 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
2073 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2074 stats->rxoctetcount_g +=
2075 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
2077 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2078 stats->rxbroadcastframes_g +=
2079 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
2081 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2082 stats->rxmulticastframes_g +=
2083 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
2085 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2086 stats->rxcrcerror +=
2087 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
2089 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2090 stats->rxrunterror +=
2091 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
2093 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2094 stats->rxjabbererror +=
2095 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
2097 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
2098 stats->rxundersize_g +=
2099 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
2101 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
2102 stats->rxoversize_g +=
2103 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
2105 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
2106 stats->rx64octets_gb +=
2107 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
2109 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
2110 stats->rx65to127octets_gb +=
2111 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
2113 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
2114 stats->rx128to255octets_gb +=
2115 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
2117 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
2118 stats->rx256to511octets_gb +=
2119 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
2121 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
2122 stats->rx512to1023octets_gb +=
2123 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
2125 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
2126 stats->rx1024tomaxoctets_gb +=
2127 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
2129 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
2130 stats->rxunicastframes_g +=
2131 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
2133 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
2134 stats->rxlengtherror +=
2135 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
2137 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
2138 stats->rxoutofrangetype +=
2139 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
2141 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
2142 stats->rxpauseframes +=
2143 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
2145 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
2146 stats->rxfifooverflow +=
2147 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
2149 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
2150 stats->rxvlanframes_gb +=
2151 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
2153 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
2154 stats->rxwatchdogerror +=
2155 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
2158 static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
2160 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2162 /* Freeze counters */
2163 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
2165 stats->txoctetcount_gb +=
2166 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
2168 stats->txframecount_gb +=
2169 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
2171 stats->txbroadcastframes_g +=
2172 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
2174 stats->txmulticastframes_g +=
2175 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
2177 stats->tx64octets_gb +=
2178 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
2180 stats->tx65to127octets_gb +=
2181 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
2183 stats->tx128to255octets_gb +=
2184 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
2186 stats->tx256to511octets_gb +=
2187 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
2189 stats->tx512to1023octets_gb +=
2190 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
2192 stats->tx1024tomaxoctets_gb +=
2193 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
2195 stats->txunicastframes_gb +=
2196 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
2198 stats->txmulticastframes_gb +=
2199 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
2201 stats->txbroadcastframes_g +=
2202 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
2204 stats->txunderflowerror +=
2205 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
2207 stats->txoctetcount_g +=
2208 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
2210 stats->txframecount_g +=
2211 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
2213 stats->txpauseframes +=
2214 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
2216 stats->txvlanframes_g +=
2217 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
2219 stats->rxframecount_gb +=
2220 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
2222 stats->rxoctetcount_gb +=
2223 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
2225 stats->rxoctetcount_g +=
2226 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
2228 stats->rxbroadcastframes_g +=
2229 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
2231 stats->rxmulticastframes_g +=
2232 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
2234 stats->rxcrcerror +=
2235 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
2237 stats->rxrunterror +=
2238 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
2240 stats->rxjabbererror +=
2241 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
2243 stats->rxundersize_g +=
2244 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
2246 stats->rxoversize_g +=
2247 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
2249 stats->rx64octets_gb +=
2250 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
2252 stats->rx65to127octets_gb +=
2253 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
2255 stats->rx128to255octets_gb +=
2256 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
2258 stats->rx256to511octets_gb +=
2259 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
2261 stats->rx512to1023octets_gb +=
2262 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
2264 stats->rx1024tomaxoctets_gb +=
2265 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
2267 stats->rxunicastframes_g +=
2268 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
2270 stats->rxlengtherror +=
2271 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
2273 stats->rxoutofrangetype +=
2274 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
2276 stats->rxpauseframes +=
2277 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
2279 stats->rxfifooverflow +=
2280 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
2282 stats->rxvlanframes_gb +=
2283 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
2285 stats->rxwatchdogerror +=
2286 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
2288 /* Un-freeze counters */
2289 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
2292 static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
2294 /* Set counters to reset on read */
2295 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
2297 /* Reset the counters */
2298 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
2301 static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
2303 struct xgbe_channel *channel;
2306 /* Enable each Tx DMA channel */
2307 channel = pdata->channel;
2308 for (i = 0; i < pdata->channel_count; i++, channel++) {
2309 if (!channel->tx_ring)
2312 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2315 /* Enable each Tx queue */
2316 for (i = 0; i < pdata->tx_q_count; i++)
2317 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
2321 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2324 static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
2326 struct xgbe_channel *channel;
2329 /* Disable MAC Tx */
2330 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2332 /* Disable each Tx queue */
2333 for (i = 0; i < pdata->tx_q_count; i++)
2334 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
2336 /* Disable each Tx DMA channel */
2337 channel = pdata->channel;
2338 for (i = 0; i < pdata->channel_count; i++, channel++) {
2339 if (!channel->tx_ring)
2342 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2346 static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
2348 struct xgbe_channel *channel;
2349 unsigned int reg_val, i;
2351 /* Enable each Rx DMA channel */
2352 channel = pdata->channel;
2353 for (i = 0; i < pdata->channel_count; i++, channel++) {
2354 if (!channel->rx_ring)
2357 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2360 /* Enable each Rx queue */
2362 for (i = 0; i < pdata->rx_q_count; i++)
2363 reg_val |= (0x02 << (i << 1));
2364 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
2367 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
2368 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
2369 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
2370 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
2373 static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
2375 struct xgbe_channel *channel;
2378 /* Disable MAC Rx */
2379 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
2380 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
2381 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
2382 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
2384 /* Disable each Rx queue */
2385 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
2387 /* Disable each Rx DMA channel */
2388 channel = pdata->channel;
2389 for (i = 0; i < pdata->channel_count; i++, channel++) {
2390 if (!channel->rx_ring)
2393 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2397 static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
2399 struct xgbe_channel *channel;
2402 /* Enable each Tx DMA channel */
2403 channel = pdata->channel;
2404 for (i = 0; i < pdata->channel_count; i++, channel++) {
2405 if (!channel->tx_ring)
2408 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2412 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2415 static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
2417 struct xgbe_channel *channel;
2420 /* Disable MAC Tx */
2421 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2423 /* Disable each Tx DMA channel */
2424 channel = pdata->channel;
2425 for (i = 0; i < pdata->channel_count; i++, channel++) {
2426 if (!channel->tx_ring)
2429 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2433 static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2435 struct xgbe_channel *channel;
2438 /* Enable each Rx DMA channel */
2439 channel = pdata->channel;
2440 for (i = 0; i < pdata->channel_count; i++, channel++) {
2441 if (!channel->rx_ring)
2444 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2448 static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2450 struct xgbe_channel *channel;
2453 /* Disable each Rx DMA channel */
2454 channel = pdata->channel;
2455 for (i = 0; i < pdata->channel_count; i++, channel++) {
2456 if (!channel->rx_ring)
2459 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2463 static int xgbe_init(struct xgbe_prv_data *pdata)
2465 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2468 DBGPR("-->xgbe_init\n");
2470 /* Flush Tx queues */
2471 ret = xgbe_flush_tx_queues(pdata);
2476 * Initialize DMA related features
2478 xgbe_config_dma_bus(pdata);
2479 xgbe_config_dma_cache(pdata);
2480 xgbe_config_osp_mode(pdata);
2481 xgbe_config_pblx8(pdata);
2482 xgbe_config_tx_pbl_val(pdata);
2483 xgbe_config_rx_pbl_val(pdata);
2484 xgbe_config_rx_coalesce(pdata);
2485 xgbe_config_tx_coalesce(pdata);
2486 xgbe_config_rx_buffer_size(pdata);
2487 xgbe_config_tso_mode(pdata);
2488 desc_if->wrapper_tx_desc_init(pdata);
2489 desc_if->wrapper_rx_desc_init(pdata);
2490 xgbe_enable_dma_interrupts(pdata);
2493 * Initialize MTL related features
2495 xgbe_config_mtl_mode(pdata);
2496 xgbe_config_queue_mapping(pdata);
2497 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2498 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2499 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2500 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2501 xgbe_config_tx_fifo_size(pdata);
2502 xgbe_config_rx_fifo_size(pdata);
2503 xgbe_config_flow_control_threshold(pdata);
2504 /*TODO: Error Packet and undersized good Packet forwarding enable
2507 xgbe_config_dcb_tc(pdata);
2508 xgbe_config_dcb_pfc(pdata);
2509 xgbe_enable_mtl_interrupts(pdata);
2512 * Initialize MAC related features
2514 xgbe_config_mac_address(pdata);
2515 xgbe_config_jumbo_enable(pdata);
2516 xgbe_config_flow_control(pdata);
2517 xgbe_config_checksum_offload(pdata);
2518 xgbe_config_vlan_support(pdata);
2519 xgbe_config_mmc(pdata);
2520 xgbe_enable_mac_interrupts(pdata);
2522 DBGPR("<--xgbe_init\n");
2527 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2529 DBGPR("-->xgbe_init_function_ptrs\n");
2531 hw_if->tx_complete = xgbe_tx_complete;
2533 hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
2534 hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
2535 hw_if->add_mac_addresses = xgbe_add_mac_addresses;
2536 hw_if->set_mac_address = xgbe_set_mac_address;
2538 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2539 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2541 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2542 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
2543 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
2544 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
2545 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
2547 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2548 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2550 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2551 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2552 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2554 hw_if->enable_tx = xgbe_enable_tx;
2555 hw_if->disable_tx = xgbe_disable_tx;
2556 hw_if->enable_rx = xgbe_enable_rx;
2557 hw_if->disable_rx = xgbe_disable_rx;
2559 hw_if->powerup_tx = xgbe_powerup_tx;
2560 hw_if->powerdown_tx = xgbe_powerdown_tx;
2561 hw_if->powerup_rx = xgbe_powerup_rx;
2562 hw_if->powerdown_rx = xgbe_powerdown_rx;
2564 hw_if->dev_xmit = xgbe_dev_xmit;
2565 hw_if->dev_read = xgbe_dev_read;
2566 hw_if->enable_int = xgbe_enable_int;
2567 hw_if->disable_int = xgbe_disable_int;
2568 hw_if->init = xgbe_init;
2569 hw_if->exit = xgbe_exit;
2571 /* Descriptor related Sequences have to be initialized here */
2572 hw_if->tx_desc_init = xgbe_tx_desc_init;
2573 hw_if->rx_desc_init = xgbe_rx_desc_init;
2574 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2575 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2576 hw_if->is_last_desc = xgbe_is_last_desc;
2577 hw_if->is_context_desc = xgbe_is_context_desc;
2580 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2581 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2583 /* For RX coalescing */
2584 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2585 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2586 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2587 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2589 /* For RX and TX threshold config */
2590 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2591 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2593 /* For RX and TX Store and Forward Mode config */
2594 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2595 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2597 /* For TX DMA Operating on Second Frame config */
2598 hw_if->config_osp_mode = xgbe_config_osp_mode;
2600 /* For RX and TX PBL config */
2601 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2602 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2603 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2604 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2605 hw_if->config_pblx8 = xgbe_config_pblx8;
2607 /* For MMC statistics support */
2608 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2609 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2610 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2612 /* For PTP config */
2613 hw_if->config_tstamp = xgbe_config_tstamp;
2614 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
2615 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
2616 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
2617 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
2619 /* For Data Center Bridging config */
2620 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
2621 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
2623 DBGPR("<--xgbe_init_function_ptrs\n");