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 <asm/cputype.h>
122 #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->sysclock);
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->sysclock);
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->hw_feat.rx_q_cnt; 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->hw_feat.tx_q_cnt; 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->hw_feat.rx_q_cnt; 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->hw_feat.tx_q_cnt; 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->hw_feat.rx_q_cnt; 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->hw_feat.rx_q_cnt, 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->hw_feat.rx_q_cnt; 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->hw_feat.rx_q_cnt, 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)
410 xgbe_enable_tx_flow_control(pdata);
412 xgbe_disable_tx_flow_control(pdata);
417 static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
420 xgbe_enable_rx_flow_control(pdata);
422 xgbe_disable_rx_flow_control(pdata);
427 static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
429 xgbe_config_tx_flow_control(pdata);
430 xgbe_config_rx_flow_control(pdata);
433 static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
435 struct xgbe_channel *channel;
436 unsigned int dma_ch_isr, dma_ch_ier;
439 channel = pdata->channel;
440 for (i = 0; i < pdata->channel_count; i++, channel++) {
441 /* Clear all the interrupts which are set */
442 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
443 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
445 /* Clear all interrupt enable bits */
448 /* Enable following interrupts
449 * NIE - Normal Interrupt Summary Enable
450 * AIE - Abnormal Interrupt Summary Enable
451 * FBEE - Fatal Bus Error Enable
453 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
454 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
455 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
457 if (channel->tx_ring) {
458 /* Enable the following Tx interrupts
459 * TIE - Transmit Interrupt Enable (unless polling)
461 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
463 if (channel->rx_ring) {
464 /* Enable following Rx interrupts
465 * RBUE - Receive Buffer Unavailable Enable
466 * RIE - Receive Interrupt Enable
468 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
469 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
472 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
476 static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
478 unsigned int mtl_q_isr;
479 unsigned int q_count, i;
481 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
482 for (i = 0; i < q_count; i++) {
483 /* Clear all the interrupts which are set */
484 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
485 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
487 /* No MTL interrupts to be enabled */
488 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, 0);
492 static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
494 /* No MAC interrupts to be enabled */
495 XGMAC_IOWRITE(pdata, MAC_IER, 0);
497 /* Enable all counter interrupts */
498 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xff);
499 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xff);
502 static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
504 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
509 static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
511 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
516 static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
518 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
523 static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
526 unsigned int val = enable ? 1 : 0;
528 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
531 DBGPR(" %s promiscuous mode\n", enable ? "entering" : "leaving");
532 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
537 static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
540 unsigned int val = enable ? 1 : 0;
542 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
545 DBGPR(" %s allmulti mode\n", enable ? "entering" : "leaving");
546 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
551 static int xgbe_set_addn_mac_addrs(struct xgbe_prv_data *pdata,
552 unsigned int am_mode)
554 struct netdev_hw_addr *ha;
555 unsigned int mac_reg;
556 unsigned int mac_addr_hi, mac_addr_lo;
560 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0);
561 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 0);
564 mac_reg = MAC_MACA1HR;
566 netdev_for_each_uc_addr(ha, pdata->netdev) {
569 mac_addr = (u8 *)&mac_addr_lo;
570 mac_addr[0] = ha->addr[0];
571 mac_addr[1] = ha->addr[1];
572 mac_addr[2] = ha->addr[2];
573 mac_addr[3] = ha->addr[3];
574 mac_addr = (u8 *)&mac_addr_hi;
575 mac_addr[0] = ha->addr[4];
576 mac_addr[1] = ha->addr[5];
578 DBGPR(" adding unicast address %pM at 0x%04x\n",
581 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
583 XGMAC_IOWRITE(pdata, mac_reg, mac_addr_hi);
584 mac_reg += MAC_MACA_INC;
585 XGMAC_IOWRITE(pdata, mac_reg, mac_addr_lo);
586 mac_reg += MAC_MACA_INC;
592 netdev_for_each_mc_addr(ha, pdata->netdev) {
595 mac_addr = (u8 *)&mac_addr_lo;
596 mac_addr[0] = ha->addr[0];
597 mac_addr[1] = ha->addr[1];
598 mac_addr[2] = ha->addr[2];
599 mac_addr[3] = ha->addr[3];
600 mac_addr = (u8 *)&mac_addr_hi;
601 mac_addr[0] = ha->addr[4];
602 mac_addr[1] = ha->addr[5];
604 DBGPR(" adding multicast address %pM at 0x%04x\n",
607 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
609 XGMAC_IOWRITE(pdata, mac_reg, mac_addr_hi);
610 mac_reg += MAC_MACA_INC;
611 XGMAC_IOWRITE(pdata, mac_reg, mac_addr_lo);
612 mac_reg += MAC_MACA_INC;
618 /* Clear remaining additional MAC address entries */
619 for (; i < pdata->hw_feat.addn_mac; i++) {
620 XGMAC_IOWRITE(pdata, mac_reg, 0);
621 mac_reg += MAC_MACA_INC;
622 XGMAC_IOWRITE(pdata, mac_reg, 0);
623 mac_reg += MAC_MACA_INC;
629 static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
631 unsigned int mac_addr_hi, mac_addr_lo;
633 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
634 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
635 (addr[1] << 8) | (addr[0] << 0);
637 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
638 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
643 static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
646 unsigned int mmd_address;
649 if (mmd_reg & MII_ADDR_C45)
650 mmd_address = mmd_reg & ~MII_ADDR_C45;
652 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
654 /* The PCS registers are accessed using mmio. The underlying APB3
655 * management interface uses indirect addressing to access the MMD
656 * register sets. This requires accessing of the PCS register in two
657 * phases, an address phase and a data phase.
659 * The mmio interface is based on 32-bit offsets and values. All
660 * register offsets must therefore be adjusted by left shifting the
661 * offset 2 bits and reading 32 bits of data.
663 mutex_lock(&pdata->xpcs_mutex);
664 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
665 mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
666 mutex_unlock(&pdata->xpcs_mutex);
671 static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
672 int mmd_reg, int mmd_data)
674 unsigned int mmd_address;
676 if (mmd_reg & MII_ADDR_C45)
677 mmd_address = mmd_reg & ~MII_ADDR_C45;
679 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
681 /* The PCS registers are accessed using mmio. The underlying APB3
682 * management interface uses indirect addressing to access the MMD
683 * register sets. This requires accessing of the PCS register in two
684 * phases, an address phase and a data phase.
686 * The mmio interface is based on 32-bit offsets and values. All
687 * register offsets must therefore be adjusted by left shifting the
688 * offset 2 bits and reading 32 bits of data.
690 mutex_lock(&pdata->xpcs_mutex);
691 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
692 XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
693 mutex_unlock(&pdata->xpcs_mutex);
696 static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
698 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
701 static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
703 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
708 static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
710 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
715 static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
717 /* Put the VLAN tag in the Rx descriptor */
718 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
720 /* Don't check the VLAN type */
721 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
723 /* Check only C-TAG (0x8100) packets */
724 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
726 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
727 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
729 /* Enable VLAN tag stripping */
730 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
735 static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
737 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
742 static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
744 struct xgbe_ring_desc *rdesc = rdata->rdesc;
746 /* Reset the Tx descriptor
747 * Set buffer 1 (lo) address to zero
748 * Set buffer 1 (hi) address to zero
749 * Reset all other control bits (IC, TTSE, B2L & B1L)
750 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
758 static void xgbe_tx_desc_init(struct xgbe_channel *channel)
760 struct xgbe_ring *ring = channel->tx_ring;
761 struct xgbe_ring_data *rdata;
762 struct xgbe_ring_desc *rdesc;
764 int start_index = ring->cur;
766 DBGPR("-->tx_desc_init\n");
768 /* Initialze all descriptors */
769 for (i = 0; i < ring->rdesc_count; i++) {
770 rdata = GET_DESC_DATA(ring, i);
771 rdesc = rdata->rdesc;
773 /* Initialize Tx descriptor
774 * Set buffer 1 (lo) address to zero
775 * Set buffer 1 (hi) address to zero
776 * Reset all other control bits (IC, TTSE, B2L & B1L)
777 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC,
786 /* Make sure everything is written to the descriptor(s) before
787 * telling the device about them
791 /* Update the total number of Tx descriptors */
792 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
794 /* Update the starting address of descriptor ring */
795 rdata = GET_DESC_DATA(ring, start_index);
796 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
797 upper_32_bits(rdata->rdesc_dma));
798 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
799 lower_32_bits(rdata->rdesc_dma));
801 DBGPR("<--tx_desc_init\n");
804 static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
806 struct xgbe_ring_desc *rdesc = rdata->rdesc;
808 /* Reset the Rx descriptor
809 * Set buffer 1 (lo) address to dma address (lo)
810 * Set buffer 1 (hi) address to dma address (hi)
811 * Set buffer 2 (lo) address to zero
812 * Set buffer 2 (hi) address to zero and set control bits
815 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
816 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
820 if (rdata->interrupt)
821 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
823 /* Since the Rx DMA engine is likely running, make sure everything
824 * is written to the descriptor(s) before setting the OWN bit
829 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
831 /* Make sure ownership is written to the descriptor */
835 static void xgbe_rx_desc_init(struct xgbe_channel *channel)
837 struct xgbe_prv_data *pdata = channel->pdata;
838 struct xgbe_ring *ring = channel->rx_ring;
839 struct xgbe_ring_data *rdata;
840 struct xgbe_ring_desc *rdesc;
841 unsigned int start_index = ring->cur;
842 unsigned int rx_coalesce, rx_frames;
845 DBGPR("-->rx_desc_init\n");
847 rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
848 rx_frames = pdata->rx_frames;
850 /* Initialize all descriptors */
851 for (i = 0; i < ring->rdesc_count; i++) {
852 rdata = GET_DESC_DATA(ring, i);
853 rdesc = rdata->rdesc;
855 /* Initialize Rx descriptor
856 * Set buffer 1 (lo) address to dma address (lo)
857 * Set buffer 1 (hi) address to dma address (hi)
858 * Set buffer 2 (lo) address to zero
859 * Set buffer 2 (hi) address to zero and set control
860 * bits OWN and INTE appropriateley
862 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
863 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
866 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
867 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
868 rdata->interrupt = 1;
869 if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames))) {
870 /* Clear interrupt on completion bit */
871 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE,
873 rdata->interrupt = 0;
877 /* Make sure everything is written to the descriptors before
878 * telling the device about them
882 /* Update the total number of Rx descriptors */
883 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
885 /* Update the starting address of descriptor ring */
886 rdata = GET_DESC_DATA(ring, start_index);
887 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
888 upper_32_bits(rdata->rdesc_dma));
889 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
890 lower_32_bits(rdata->rdesc_dma));
892 /* Update the Rx Descriptor Tail Pointer */
893 rdata = GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
894 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
895 lower_32_bits(rdata->rdesc_dma));
897 DBGPR("<--rx_desc_init\n");
900 static void xgbe_pre_xmit(struct xgbe_channel *channel)
902 struct xgbe_prv_data *pdata = channel->pdata;
903 struct xgbe_ring *ring = channel->tx_ring;
904 struct xgbe_ring_data *rdata;
905 struct xgbe_ring_desc *rdesc;
906 struct xgbe_packet_data *packet = &ring->packet_data;
907 unsigned int csum, tso, vlan;
908 unsigned int tso_context, vlan_context;
909 unsigned int tx_coalesce, tx_frames;
910 int start_index = ring->cur;
913 DBGPR("-->xgbe_pre_xmit\n");
915 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
917 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
919 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
922 if (tso && (packet->mss != ring->tx.cur_mss))
927 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
932 tx_coalesce = (pdata->tx_usecs || pdata->tx_frames) ? 1 : 0;
933 tx_frames = pdata->tx_frames;
934 if (tx_coalesce && !channel->tx_timer_active)
935 ring->coalesce_count = 0;
937 rdata = GET_DESC_DATA(ring, ring->cur);
938 rdesc = rdata->rdesc;
940 /* Create a context descriptor if this is a TSO packet */
941 if (tso_context || vlan_context) {
943 DBGPR(" TSO context descriptor, mss=%u\n",
946 /* Set the MSS size */
947 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
950 /* Mark it as a CONTEXT descriptor */
951 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
954 /* Indicate this descriptor contains the MSS */
955 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
958 ring->tx.cur_mss = packet->mss;
962 DBGPR(" VLAN context descriptor, ctag=%u\n",
965 /* Mark it as a CONTEXT descriptor */
966 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
969 /* Set the VLAN tag */
970 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
971 VT, packet->vlan_ctag);
973 /* Indicate this descriptor contains the VLAN tag */
974 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
977 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
981 rdata = GET_DESC_DATA(ring, ring->cur);
982 rdesc = rdata->rdesc;
985 /* Update buffer address (for TSO this is the header) */
986 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
987 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
989 /* Update the buffer length */
990 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
993 /* VLAN tag insertion check */
995 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
996 TX_NORMAL_DESC2_VLAN_INSERT);
998 /* Set IC bit based on Tx coalescing settings */
999 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1000 if (tx_coalesce && (!tx_frames ||
1001 (++ring->coalesce_count % tx_frames)))
1003 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1005 /* Mark it as First Descriptor */
1006 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1008 /* Mark it as a NORMAL descriptor */
1009 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1011 /* Set OWN bit if not the first descriptor */
1012 if (ring->cur != start_index)
1013 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1017 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1018 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1019 packet->tcp_payload_len);
1020 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1021 packet->tcp_header_len / 4);
1023 /* Enable CRC and Pad Insertion */
1024 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1026 /* Enable HW CSUM */
1028 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1031 /* Set the total length to be transmitted */
1032 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1036 for (i = ring->cur - start_index + 1; i < packet->rdesc_count; i++) {
1038 rdata = GET_DESC_DATA(ring, ring->cur);
1039 rdesc = rdata->rdesc;
1041 /* Update buffer address */
1042 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1043 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1045 /* Update the buffer length */
1046 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1047 rdata->skb_dma_len);
1049 /* Set IC bit based on Tx coalescing settings */
1050 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1051 if (tx_coalesce && (!tx_frames ||
1052 (++ring->coalesce_count % tx_frames)))
1054 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1057 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1059 /* Mark it as NORMAL descriptor */
1060 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1062 /* Enable HW CSUM */
1064 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1068 /* Set LAST bit for the last descriptor */
1069 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1071 /* In case the Tx DMA engine is running, make sure everything
1072 * is written to the descriptor(s) before setting the OWN bit
1073 * for the first descriptor
1077 /* Set OWN bit for the first descriptor */
1078 rdata = GET_DESC_DATA(ring, start_index);
1079 rdesc = rdata->rdesc;
1080 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1082 #ifdef XGMAC_ENABLE_TX_DESC_DUMP
1083 xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
1086 /* Make sure ownership is written to the descriptor */
1089 /* Issue a poll command to Tx DMA by writing address
1090 * of next immediate free descriptor */
1092 rdata = GET_DESC_DATA(ring, ring->cur);
1093 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1094 lower_32_bits(rdata->rdesc_dma));
1096 /* Start the Tx coalescing timer */
1097 if (tx_coalesce && !channel->tx_timer_active) {
1098 channel->tx_timer_active = 1;
1099 hrtimer_start(&channel->tx_timer,
1100 ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
1104 DBGPR(" %s: descriptors %u to %u written\n",
1105 channel->name, start_index & (ring->rdesc_count - 1),
1106 (ring->cur - 1) & (ring->rdesc_count - 1));
1108 DBGPR("<--xgbe_pre_xmit\n");
1111 static int xgbe_dev_read(struct xgbe_channel *channel)
1113 struct xgbe_ring *ring = channel->rx_ring;
1114 struct xgbe_ring_data *rdata;
1115 struct xgbe_ring_desc *rdesc;
1116 struct xgbe_packet_data *packet = &ring->packet_data;
1117 unsigned int err, etlt;
1119 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1121 rdata = GET_DESC_DATA(ring, ring->cur);
1122 rdesc = rdata->rdesc;
1124 /* Check for data availability */
1125 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1128 #ifdef XGMAC_ENABLE_RX_DESC_DUMP
1129 xgbe_dump_rx_desc(ring, rdesc, ring->cur);
1132 /* Get the packet length */
1133 rdata->len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
1135 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1136 /* Not all the data has been transferred for this packet */
1137 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1142 /* This is the last of the data for this packet */
1143 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1146 /* Set checksum done indicator as appropriate */
1147 if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
1148 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1151 /* Check for errors (only valid in last descriptor) */
1152 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1153 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1154 DBGPR(" err=%u, etlt=%#x\n", err, etlt);
1156 if (!err || (err && !etlt)) {
1158 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1160 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1163 DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
1166 if ((etlt == 0x05) || (etlt == 0x06))
1167 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1170 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1174 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1175 ring->cur & (ring->rdesc_count - 1), ring->cur);
1180 static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1182 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1183 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1186 static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1188 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1189 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1192 static void xgbe_save_interrupt_status(struct xgbe_channel *channel,
1193 enum xgbe_int_state int_state)
1195 unsigned int dma_ch_ier;
1197 if (int_state == XGMAC_INT_STATE_SAVE) {
1198 channel->saved_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1199 channel->saved_ier &= DMA_INTERRUPT_MASK;
1201 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1202 dma_ch_ier |= channel->saved_ier;
1203 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1207 static int xgbe_enable_int(struct xgbe_channel *channel,
1208 enum xgbe_int int_id)
1211 case XGMAC_INT_DMA_ISR_DC0IS:
1212 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 1);
1214 case XGMAC_INT_DMA_CH_SR_TI:
1215 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 1);
1217 case XGMAC_INT_DMA_CH_SR_TPS:
1218 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TXSE, 1);
1220 case XGMAC_INT_DMA_CH_SR_TBU:
1221 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TBUE, 1);
1223 case XGMAC_INT_DMA_CH_SR_RI:
1224 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RIE, 1);
1226 case XGMAC_INT_DMA_CH_SR_RBU:
1227 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RBUE, 1);
1229 case XGMAC_INT_DMA_CH_SR_RPS:
1230 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RSE, 1);
1232 case XGMAC_INT_DMA_CH_SR_FBE:
1233 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, FBEE, 1);
1235 case XGMAC_INT_DMA_ALL:
1236 xgbe_save_interrupt_status(channel, XGMAC_INT_STATE_RESTORE);
1245 static int xgbe_disable_int(struct xgbe_channel *channel,
1246 enum xgbe_int int_id)
1248 unsigned int dma_ch_ier;
1251 case XGMAC_INT_DMA_ISR_DC0IS:
1252 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 0);
1254 case XGMAC_INT_DMA_CH_SR_TI:
1255 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 0);
1257 case XGMAC_INT_DMA_CH_SR_TPS:
1258 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TXSE, 0);
1260 case XGMAC_INT_DMA_CH_SR_TBU:
1261 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TBUE, 0);
1263 case XGMAC_INT_DMA_CH_SR_RI:
1264 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RIE, 0);
1266 case XGMAC_INT_DMA_CH_SR_RBU:
1267 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RBUE, 0);
1269 case XGMAC_INT_DMA_CH_SR_RPS:
1270 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RSE, 0);
1272 case XGMAC_INT_DMA_CH_SR_FBE:
1273 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, FBEE, 0);
1275 case XGMAC_INT_DMA_ALL:
1276 xgbe_save_interrupt_status(channel, XGMAC_INT_STATE_SAVE);
1278 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1279 dma_ch_ier &= ~DMA_INTERRUPT_MASK;
1280 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1289 static int xgbe_exit(struct xgbe_prv_data *pdata)
1291 unsigned int count = 2000;
1293 DBGPR("-->xgbe_exit\n");
1295 /* Issue a software reset */
1296 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1297 usleep_range(10, 15);
1299 /* Poll Until Poll Condition */
1300 while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1301 usleep_range(500, 600);
1306 DBGPR("<--xgbe_exit\n");
1311 static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1313 unsigned int i, count;
1315 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1316 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1318 /* Poll Until Poll Condition */
1319 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++) {
1321 while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
1323 usleep_range(500, 600);
1332 static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1334 /* Set enhanced addressing mode */
1335 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1337 /* Set the System Bus mode */
1338 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
1341 static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1343 unsigned int arcache, awcache;
1346 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, DMA_ARCACHE_SETTING);
1347 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, DMA_ARDOMAIN_SETTING);
1348 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, DMA_ARCACHE_SETTING);
1349 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, DMA_ARDOMAIN_SETTING);
1350 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, DMA_ARCACHE_SETTING);
1351 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, DMA_ARDOMAIN_SETTING);
1352 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1355 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, DMA_AWCACHE_SETTING);
1356 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, DMA_AWDOMAIN_SETTING);
1357 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, DMA_AWCACHE_SETTING);
1358 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, DMA_AWDOMAIN_SETTING);
1359 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, DMA_AWCACHE_SETTING);
1360 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, DMA_AWDOMAIN_SETTING);
1361 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, DMA_AWCACHE_SETTING);
1362 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, DMA_AWDOMAIN_SETTING);
1363 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1366 static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1370 /* Set Tx to weighted round robin scheduling algorithm (when
1371 * traffic class is using ETS algorithm)
1373 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1375 /* Set Tx traffic classes to strict priority algorithm */
1376 for (i = 0; i < XGBE_TC_CNT; i++)
1377 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, MTL_TSA_SP);
1379 /* Set Rx to strict priority algorithm */
1380 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1383 static unsigned int xgbe_calculate_per_queue_fifo(unsigned long fifo_size,
1384 unsigned char queue_count)
1386 unsigned int q_fifo_size = 0;
1387 enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1389 /* Calculate Tx/Rx fifo share per queue */
1390 switch (fifo_size) {
1392 q_fifo_size = FIFO_SIZE_B(128);
1395 q_fifo_size = FIFO_SIZE_B(256);
1398 q_fifo_size = FIFO_SIZE_B(512);
1401 q_fifo_size = FIFO_SIZE_KB(1);
1404 q_fifo_size = FIFO_SIZE_KB(2);
1407 q_fifo_size = FIFO_SIZE_KB(4);
1410 q_fifo_size = FIFO_SIZE_KB(8);
1413 q_fifo_size = FIFO_SIZE_KB(16);
1416 q_fifo_size = FIFO_SIZE_KB(32);
1419 q_fifo_size = FIFO_SIZE_KB(64);
1422 q_fifo_size = FIFO_SIZE_KB(128);
1425 q_fifo_size = FIFO_SIZE_KB(256);
1428 q_fifo_size = q_fifo_size / queue_count;
1430 /* Set the queue fifo size programmable value */
1431 if (q_fifo_size >= FIFO_SIZE_KB(256))
1432 p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
1433 else if (q_fifo_size >= FIFO_SIZE_KB(128))
1434 p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
1435 else if (q_fifo_size >= FIFO_SIZE_KB(64))
1436 p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
1437 else if (q_fifo_size >= FIFO_SIZE_KB(32))
1438 p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
1439 else if (q_fifo_size >= FIFO_SIZE_KB(16))
1440 p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
1441 else if (q_fifo_size >= FIFO_SIZE_KB(8))
1442 p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
1443 else if (q_fifo_size >= FIFO_SIZE_KB(4))
1444 p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
1445 else if (q_fifo_size >= FIFO_SIZE_KB(2))
1446 p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
1447 else if (q_fifo_size >= FIFO_SIZE_KB(1))
1448 p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
1449 else if (q_fifo_size >= FIFO_SIZE_B(512))
1450 p_fifo = XGMAC_MTL_FIFO_SIZE_512;
1451 else if (q_fifo_size >= FIFO_SIZE_B(256))
1452 p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1457 static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
1459 enum xgbe_mtl_fifo_size fifo_size;
1462 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
1463 pdata->hw_feat.tx_q_cnt);
1465 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1466 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
1468 netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
1469 pdata->hw_feat.tx_q_cnt, ((fifo_size + 1) * 256));
1472 static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
1474 enum xgbe_mtl_fifo_size fifo_size;
1477 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
1478 pdata->hw_feat.rx_q_cnt);
1480 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
1481 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
1483 netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
1484 pdata->hw_feat.rx_q_cnt, ((fifo_size + 1) * 256));
1487 static void xgbe_config_rx_queue_mapping(struct xgbe_prv_data *pdata)
1489 unsigned int i, reg, reg_val;
1490 unsigned int q_count = pdata->hw_feat.rx_q_cnt;
1492 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
1495 for (i = 0; i < q_count;) {
1496 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
1498 if ((i % MTL_RQDCM_Q_PER_REG) && (i != q_count))
1501 XGMAC_IOWRITE(pdata, reg, reg_val);
1503 reg += MTL_RQDCM_INC;
1508 static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
1512 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++) {
1513 /* Activate flow control when less than 4k left in fifo */
1514 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
1516 /* De-activate flow control when more than 6k left in fifo */
1517 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
1521 static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
1523 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
1526 static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
1530 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
1532 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1535 static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
1537 if (pdata->netdev->features & NETIF_F_RXCSUM)
1538 xgbe_enable_rx_csum(pdata);
1540 xgbe_disable_rx_csum(pdata);
1543 static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
1545 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
1546 xgbe_enable_rx_vlan_stripping(pdata);
1548 xgbe_disable_rx_vlan_stripping(pdata);
1551 static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
1553 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1554 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
1556 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
1557 stats->txoctetcount_gb +=
1558 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
1560 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
1561 stats->txframecount_gb +=
1562 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
1564 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
1565 stats->txbroadcastframes_g +=
1566 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1568 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
1569 stats->txmulticastframes_g +=
1570 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1572 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
1573 stats->tx64octets_gb +=
1574 XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
1576 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
1577 stats->tx65to127octets_gb +=
1578 XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
1580 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
1581 stats->tx128to255octets_gb +=
1582 XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
1584 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
1585 stats->tx256to511octets_gb +=
1586 XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
1588 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
1589 stats->tx512to1023octets_gb +=
1590 XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1592 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
1593 stats->tx1024tomaxoctets_gb +=
1594 XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1596 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
1597 stats->txunicastframes_gb +=
1598 XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
1600 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
1601 stats->txmulticastframes_gb +=
1602 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
1604 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
1605 stats->txbroadcastframes_g +=
1606 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
1608 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
1609 stats->txunderflowerror +=
1610 XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
1612 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
1613 stats->txoctetcount_g +=
1614 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
1616 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
1617 stats->txframecount_g +=
1618 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
1620 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
1621 stats->txpauseframes +=
1622 XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
1624 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
1625 stats->txvlanframes_g +=
1626 XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
1629 static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
1631 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1632 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
1634 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
1635 stats->rxframecount_gb +=
1636 XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
1638 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
1639 stats->rxoctetcount_gb +=
1640 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
1642 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
1643 stats->rxoctetcount_g +=
1644 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
1646 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
1647 stats->rxbroadcastframes_g +=
1648 XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
1650 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
1651 stats->rxmulticastframes_g +=
1652 XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
1654 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
1655 stats->rxcrcerror +=
1656 XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
1658 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
1659 stats->rxrunterror +=
1660 XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
1662 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
1663 stats->rxjabbererror +=
1664 XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
1666 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
1667 stats->rxundersize_g +=
1668 XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
1670 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
1671 stats->rxoversize_g +=
1672 XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
1674 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
1675 stats->rx64octets_gb +=
1676 XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
1678 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
1679 stats->rx65to127octets_gb +=
1680 XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
1682 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
1683 stats->rx128to255octets_gb +=
1684 XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
1686 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
1687 stats->rx256to511octets_gb +=
1688 XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
1690 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
1691 stats->rx512to1023octets_gb +=
1692 XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
1694 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
1695 stats->rx1024tomaxoctets_gb +=
1696 XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
1698 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
1699 stats->rxunicastframes_g +=
1700 XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
1702 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
1703 stats->rxlengtherror +=
1704 XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
1706 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
1707 stats->rxoutofrangetype +=
1708 XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
1710 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
1711 stats->rxpauseframes +=
1712 XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
1714 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
1715 stats->rxfifooverflow +=
1716 XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
1718 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
1719 stats->rxvlanframes_gb +=
1720 XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
1722 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
1723 stats->rxwatchdogerror +=
1724 XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
1727 static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
1729 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1731 /* Freeze counters */
1732 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
1734 stats->txoctetcount_gb +=
1735 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
1737 stats->txframecount_gb +=
1738 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
1740 stats->txbroadcastframes_g +=
1741 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1743 stats->txmulticastframes_g +=
1744 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1746 stats->tx64octets_gb +=
1747 XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
1749 stats->tx65to127octets_gb +=
1750 XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
1752 stats->tx128to255octets_gb +=
1753 XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
1755 stats->tx256to511octets_gb +=
1756 XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
1758 stats->tx512to1023octets_gb +=
1759 XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1761 stats->tx1024tomaxoctets_gb +=
1762 XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1764 stats->txunicastframes_gb +=
1765 XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
1767 stats->txmulticastframes_gb +=
1768 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
1770 stats->txbroadcastframes_g +=
1771 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
1773 stats->txunderflowerror +=
1774 XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
1776 stats->txoctetcount_g +=
1777 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
1779 stats->txframecount_g +=
1780 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
1782 stats->txpauseframes +=
1783 XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
1785 stats->txvlanframes_g +=
1786 XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
1788 stats->rxframecount_gb +=
1789 XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
1791 stats->rxoctetcount_gb +=
1792 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
1794 stats->rxoctetcount_g +=
1795 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
1797 stats->rxbroadcastframes_g +=
1798 XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
1800 stats->rxmulticastframes_g +=
1801 XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
1803 stats->rxcrcerror +=
1804 XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
1806 stats->rxrunterror +=
1807 XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
1809 stats->rxjabbererror +=
1810 XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
1812 stats->rxundersize_g +=
1813 XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
1815 stats->rxoversize_g +=
1816 XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
1818 stats->rx64octets_gb +=
1819 XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
1821 stats->rx65to127octets_gb +=
1822 XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
1824 stats->rx128to255octets_gb +=
1825 XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
1827 stats->rx256to511octets_gb +=
1828 XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
1830 stats->rx512to1023octets_gb +=
1831 XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
1833 stats->rx1024tomaxoctets_gb +=
1834 XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
1836 stats->rxunicastframes_g +=
1837 XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
1839 stats->rxlengtherror +=
1840 XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
1842 stats->rxoutofrangetype +=
1843 XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
1845 stats->rxpauseframes +=
1846 XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
1848 stats->rxfifooverflow +=
1849 XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
1851 stats->rxvlanframes_gb +=
1852 XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
1854 stats->rxwatchdogerror +=
1855 XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
1857 /* Un-freeze counters */
1858 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
1861 static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
1863 /* Set counters to reset on read */
1864 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
1866 /* Reset the counters */
1867 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
1870 static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
1872 struct xgbe_channel *channel;
1875 /* Enable each Tx DMA channel */
1876 channel = pdata->channel;
1877 for (i = 0; i < pdata->channel_count; i++, channel++) {
1878 if (!channel->tx_ring)
1881 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
1884 /* Enable each Tx queue */
1885 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1886 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
1890 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
1893 static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
1895 struct xgbe_channel *channel;
1898 /* Disable MAC Tx */
1899 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
1901 /* Disable each Tx queue */
1902 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1903 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
1905 /* Disable each Tx DMA channel */
1906 channel = pdata->channel;
1907 for (i = 0; i < pdata->channel_count; i++, channel++) {
1908 if (!channel->tx_ring)
1911 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
1915 static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
1917 struct xgbe_channel *channel;
1918 unsigned int reg_val, i;
1920 /* Enable each Rx DMA channel */
1921 channel = pdata->channel;
1922 for (i = 0; i < pdata->channel_count; i++, channel++) {
1923 if (!channel->rx_ring)
1926 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
1929 /* Enable each Rx queue */
1931 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
1932 reg_val |= (0x02 << (i << 1));
1933 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
1936 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
1937 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
1938 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
1939 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
1942 static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
1944 struct xgbe_channel *channel;
1947 /* Disable MAC Rx */
1948 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
1949 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
1950 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
1951 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
1953 /* Disable each Rx queue */
1954 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
1956 /* Disable each Rx DMA channel */
1957 channel = pdata->channel;
1958 for (i = 0; i < pdata->channel_count; i++, channel++) {
1959 if (!channel->rx_ring)
1962 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
1966 static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
1968 struct xgbe_channel *channel;
1971 /* Enable each Tx DMA channel */
1972 channel = pdata->channel;
1973 for (i = 0; i < pdata->channel_count; i++, channel++) {
1974 if (!channel->tx_ring)
1977 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
1981 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
1984 static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
1986 struct xgbe_channel *channel;
1989 /* Disable MAC Tx */
1990 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
1992 /* Disable each Tx DMA channel */
1993 channel = pdata->channel;
1994 for (i = 0; i < pdata->channel_count; i++, channel++) {
1995 if (!channel->tx_ring)
1998 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2002 static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2004 struct xgbe_channel *channel;
2007 /* Enable each Rx DMA channel */
2008 channel = pdata->channel;
2009 for (i = 0; i < pdata->channel_count; i++, channel++) {
2010 if (!channel->rx_ring)
2013 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2017 static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2019 struct xgbe_channel *channel;
2022 /* Disable each Rx DMA channel */
2023 channel = pdata->channel;
2024 for (i = 0; i < pdata->channel_count; i++, channel++) {
2025 if (!channel->rx_ring)
2028 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2032 static int xgbe_init(struct xgbe_prv_data *pdata)
2034 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2037 DBGPR("-->xgbe_init\n");
2039 /* Flush Tx queues */
2040 ret = xgbe_flush_tx_queues(pdata);
2045 * Initialize DMA related features
2047 xgbe_config_dma_bus(pdata);
2048 xgbe_config_dma_cache(pdata);
2049 xgbe_config_osp_mode(pdata);
2050 xgbe_config_pblx8(pdata);
2051 xgbe_config_tx_pbl_val(pdata);
2052 xgbe_config_rx_pbl_val(pdata);
2053 xgbe_config_rx_coalesce(pdata);
2054 xgbe_config_tx_coalesce(pdata);
2055 xgbe_config_rx_buffer_size(pdata);
2056 xgbe_config_tso_mode(pdata);
2057 desc_if->wrapper_tx_desc_init(pdata);
2058 desc_if->wrapper_rx_desc_init(pdata);
2059 xgbe_enable_dma_interrupts(pdata);
2062 * Initialize MTL related features
2064 xgbe_config_mtl_mode(pdata);
2065 xgbe_config_rx_queue_mapping(pdata);
2066 /*TODO: Program the priorities mapped to the Selected Traffic Classes
2067 in MTL_TC_Prty_Map0-3 registers */
2068 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2069 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2070 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2071 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2072 xgbe_config_tx_fifo_size(pdata);
2073 xgbe_config_rx_fifo_size(pdata);
2074 xgbe_config_flow_control_threshold(pdata);
2075 /*TODO: Queue to Traffic Class Mapping (Q2TCMAP) */
2076 /*TODO: Error Packet and undersized good Packet forwarding enable
2079 xgbe_enable_mtl_interrupts(pdata);
2081 /* Transmit Class Weight */
2082 XGMAC_IOWRITE_BITS(pdata, MTL_Q_TCQWR, QW, 0x10);
2085 * Initialize MAC related features
2087 xgbe_config_mac_address(pdata);
2088 xgbe_config_jumbo_enable(pdata);
2089 xgbe_config_flow_control(pdata);
2090 xgbe_config_checksum_offload(pdata);
2091 xgbe_config_vlan_support(pdata);
2092 xgbe_config_mmc(pdata);
2093 xgbe_enable_mac_interrupts(pdata);
2095 DBGPR("<--xgbe_init\n");
2100 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2102 DBGPR("-->xgbe_init_function_ptrs\n");
2104 hw_if->tx_complete = xgbe_tx_complete;
2106 hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
2107 hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
2108 hw_if->set_addn_mac_addrs = xgbe_set_addn_mac_addrs;
2109 hw_if->set_mac_address = xgbe_set_mac_address;
2111 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2112 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2114 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2115 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
2117 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2118 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2120 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2121 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2122 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2124 hw_if->enable_tx = xgbe_enable_tx;
2125 hw_if->disable_tx = xgbe_disable_tx;
2126 hw_if->enable_rx = xgbe_enable_rx;
2127 hw_if->disable_rx = xgbe_disable_rx;
2129 hw_if->powerup_tx = xgbe_powerup_tx;
2130 hw_if->powerdown_tx = xgbe_powerdown_tx;
2131 hw_if->powerup_rx = xgbe_powerup_rx;
2132 hw_if->powerdown_rx = xgbe_powerdown_rx;
2134 hw_if->pre_xmit = xgbe_pre_xmit;
2135 hw_if->dev_read = xgbe_dev_read;
2136 hw_if->enable_int = xgbe_enable_int;
2137 hw_if->disable_int = xgbe_disable_int;
2138 hw_if->init = xgbe_init;
2139 hw_if->exit = xgbe_exit;
2141 /* Descriptor related Sequences have to be initialized here */
2142 hw_if->tx_desc_init = xgbe_tx_desc_init;
2143 hw_if->rx_desc_init = xgbe_rx_desc_init;
2144 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2145 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2146 hw_if->is_last_desc = xgbe_is_last_desc;
2147 hw_if->is_context_desc = xgbe_is_context_desc;
2150 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2151 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2153 /* For RX coalescing */
2154 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2155 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2156 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2157 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2159 /* For RX and TX threshold config */
2160 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2161 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2163 /* For RX and TX Store and Forward Mode config */
2164 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2165 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2167 /* For TX DMA Operating on Second Frame config */
2168 hw_if->config_osp_mode = xgbe_config_osp_mode;
2170 /* For RX and TX PBL config */
2171 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2172 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2173 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2174 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2175 hw_if->config_pblx8 = xgbe_config_pblx8;
2177 /* For MMC statistics support */
2178 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2179 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2180 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2182 DBGPR("<--xgbe_init_function_ptrs\n");