2 * AMD 10Gb Ethernet driver
4 * This file is available to you under your choice of the following two
9 * Copyright (c) 2014-2016 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-2016 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 <sys/cdefs.h>
118 __FBSDID("$FreeBSD$");
120 #include <sys/param.h>
121 #include <sys/kernel.h>
124 #include "xgbe-common.h"
126 #include <net/if_dl.h>
127 #include <net/if_var.h>
129 static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
135 DBGPR("-->xgbe_usec_to_riwt\n");
137 rate = pdata->sysclk_rate;
140 * Convert the input usec value to the watchdog timer value. Each
141 * watchdog timer value is equivalent to 256 clock cycles.
142 * Calculate the required value as:
143 * ( usec * ( system_clock_mhz / 10^6 ) / 256
145 ret = (usec * (rate / 1000000)) / 256;
147 DBGPR("<--xgbe_usec_to_riwt\n");
152 static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
158 DBGPR("-->xgbe_riwt_to_usec\n");
160 rate = pdata->sysclk_rate;
163 * Convert the input watchdog timer value to the usec value. Each
164 * watchdog timer value is equivalent to 256 clock cycles.
165 * Calculate the required value as:
166 * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
168 ret = (riwt * 256) / (rate / 1000000);
170 DBGPR("<--xgbe_riwt_to_usec\n");
175 static int xgbe_config_pblx8(struct xgbe_prv_data *pdata)
177 struct xgbe_channel *channel;
180 channel = pdata->channel;
181 for (i = 0; i < pdata->channel_count; i++, channel++)
182 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8,
188 static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata)
190 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL);
193 static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata)
195 struct xgbe_channel *channel;
198 channel = pdata->channel;
199 for (i = 0; i < pdata->channel_count; i++, channel++) {
200 if (!channel->tx_ring)
203 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL,
210 static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata)
212 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL);
215 static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata)
217 struct xgbe_channel *channel;
220 channel = pdata->channel;
221 for (i = 0; i < pdata->channel_count; i++, channel++) {
222 if (!channel->rx_ring)
225 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL,
232 static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
234 struct xgbe_channel *channel;
237 channel = pdata->channel;
238 for (i = 0; i < pdata->channel_count; i++, channel++) {
239 if (!channel->tx_ring)
242 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP,
249 static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
253 for (i = 0; i < pdata->rx_q_count; i++)
254 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
259 static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
263 for (i = 0; i < pdata->tx_q_count; i++)
264 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
269 static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
274 for (i = 0; i < pdata->rx_q_count; i++)
275 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
280 static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
285 for (i = 0; i < pdata->tx_q_count; i++)
286 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
291 static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
293 struct xgbe_channel *channel;
296 channel = pdata->channel;
297 for (i = 0; i < pdata->channel_count; i++, channel++) {
298 if (!channel->rx_ring)
301 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT,
308 static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
313 static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
315 struct xgbe_channel *channel;
318 channel = pdata->channel;
319 for (i = 0; i < pdata->channel_count; i++, channel++) {
320 if (!channel->rx_ring)
323 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ,
328 static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
330 struct xgbe_channel *channel;
333 channel = pdata->channel;
334 for (i = 0; i < pdata->channel_count; i++, channel++) {
335 if (!channel->tx_ring)
338 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1);
342 static void xgbe_config_sph_mode(struct xgbe_prv_data *pdata)
344 struct xgbe_channel *channel;
347 channel = pdata->channel;
348 for (i = 0; i < pdata->channel_count; i++, channel++) {
349 if (!channel->rx_ring)
352 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, SPH, 1);
355 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE);
358 static int xgbe_disable_rss(struct xgbe_prv_data *pdata)
360 if (!pdata->hw_feat.rss)
363 XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 0);
368 static void xgbe_config_rss(struct xgbe_prv_data *pdata)
371 if (!pdata->hw_feat.rss)
374 xgbe_disable_rss(pdata);
377 static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
379 unsigned int max_q_count, q_count;
380 unsigned int reg, reg_val;
383 /* Clear MTL flow control */
384 for (i = 0; i < pdata->rx_q_count; i++)
385 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
387 /* Clear MAC flow control */
388 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
389 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
391 for (i = 0; i < q_count; i++) {
392 reg_val = XGMAC_IOREAD(pdata, reg);
393 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
394 XGMAC_IOWRITE(pdata, reg, reg_val);
396 reg += MAC_QTFCR_INC;
402 static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
404 unsigned int max_q_count, q_count;
405 unsigned int reg, reg_val;
408 /* Set MTL flow control */
409 for (i = 0; i < pdata->rx_q_count; i++) {
410 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 1);
413 /* Set MAC flow control */
414 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
415 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
417 for (i = 0; i < q_count; i++) {
418 reg_val = XGMAC_IOREAD(pdata, reg);
420 /* Enable transmit flow control */
421 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
423 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
425 XGMAC_IOWRITE(pdata, reg, reg_val);
427 reg += MAC_QTFCR_INC;
433 static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
435 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
440 static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
442 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
447 static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
451 xgbe_enable_tx_flow_control(pdata);
453 xgbe_disable_tx_flow_control(pdata);
458 static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
462 xgbe_enable_rx_flow_control(pdata);
464 xgbe_disable_rx_flow_control(pdata);
469 static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
472 xgbe_config_tx_flow_control(pdata);
473 xgbe_config_rx_flow_control(pdata);
475 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 0);
478 static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
480 struct xgbe_channel *channel;
481 unsigned int dma_ch_isr, dma_ch_ier;
484 channel = pdata->channel;
485 for (i = 0; i < pdata->channel_count; i++, channel++) {
486 /* Clear all the interrupts which are set */
487 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
488 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
490 /* Clear all interrupt enable bits */
493 /* Enable following interrupts
494 * NIE - Normal Interrupt Summary Enable
495 * AIE - Abnormal Interrupt Summary Enable
496 * FBEE - Fatal Bus Error Enable
498 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
499 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
500 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
502 if (channel->tx_ring) {
503 /* Enable the following Tx interrupts
504 * TIE - Transmit Interrupt Enable (unless using
505 * per channel interrupts)
507 if (!pdata->per_channel_irq)
508 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
510 if (channel->rx_ring) {
511 /* Enable following Rx interrupts
512 * RBUE - Receive Buffer Unavailable Enable
513 * RIE - Receive Interrupt Enable (unless using
514 * per channel interrupts)
516 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
517 if (!pdata->per_channel_irq)
518 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
521 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
525 static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
527 unsigned int mtl_q_isr;
528 unsigned int q_count, i;
530 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
531 for (i = 0; i < q_count; i++) {
532 /* Clear all the interrupts which are set */
533 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
534 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
536 /* No MTL interrupts to be enabled */
537 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
541 static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
543 unsigned int mac_ier = 0;
545 /* Enable Timestamp interrupt */
546 XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
548 XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
550 /* Enable all counter interrupts */
551 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
552 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
555 static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
557 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) == 0x3)
560 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
565 static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
567 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) == 0x2)
570 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
575 static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
577 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) == 0)
580 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
585 static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
587 /* Put the VLAN tag in the Rx descriptor */
588 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
590 /* Don't check the VLAN type */
591 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
593 /* Check only C-TAG (0x8100) packets */
594 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
596 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
597 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
599 /* Enable VLAN tag stripping */
600 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
605 static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
607 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
612 static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
614 /* Enable VLAN filtering */
615 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
617 /* Enable VLAN Hash Table filtering */
618 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
620 /* Disable VLAN tag inverse matching */
621 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
623 /* Only filter on the lower 12-bits of the VLAN tag */
624 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
626 /* In order for the VLAN Hash Table filtering to be effective,
627 * the VLAN tag identifier in the VLAN Tag Register must not
628 * be zero. Set the VLAN tag identifier to "1" to enable the
629 * VLAN Hash Table filtering. This implies that a VLAN tag of
630 * 1 will always pass filtering.
632 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
637 static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
639 /* Disable VLAN filtering */
640 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
645 static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
647 u16 vlan_hash_table = 0;
649 /* Set the VLAN Hash Table filtering register */
650 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
655 static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
658 unsigned int val = enable ? 1 : 0;
660 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
663 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
665 /* Hardware will still perform VLAN filtering in promiscuous mode */
666 xgbe_disable_rx_vlan_filtering(pdata);
671 static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
674 unsigned int val = enable ? 1 : 0;
676 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
679 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
684 static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
685 char *addr, unsigned int *mac_reg)
687 unsigned int mac_addr_hi, mac_addr_lo;
694 mac_addr = (u8 *)&mac_addr_lo;
695 mac_addr[0] = addr[0];
696 mac_addr[1] = addr[1];
697 mac_addr[2] = addr[2];
698 mac_addr[3] = addr[3];
699 mac_addr = (u8 *)&mac_addr_hi;
700 mac_addr[0] = addr[4];
701 mac_addr[1] = addr[5];
703 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
706 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
707 *mac_reg += MAC_MACA_INC;
708 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
709 *mac_reg += MAC_MACA_INC;
712 static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
714 unsigned int mac_reg;
715 unsigned int addn_macs;
717 mac_reg = MAC_MACA1HR;
718 addn_macs = pdata->hw_feat.addn_mac;
720 xgbe_set_mac_reg(pdata, pdata->mac_addr, &mac_reg);
723 /* Clear remaining additional MAC address entries */
725 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
728 static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
730 xgbe_set_mac_addn_addrs(pdata);
735 static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
737 unsigned int mac_addr_hi, mac_addr_lo;
739 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
740 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
741 (addr[1] << 8) | (addr[0] << 0);
743 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
744 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
749 static int xgbe_config_rx_mode(struct xgbe_prv_data *pdata)
751 unsigned int pr_mode, am_mode;
757 xgbe_set_promiscuous_mode(pdata, pr_mode);
758 xgbe_set_all_multicast_mode(pdata, am_mode);
760 xgbe_add_mac_addresses(pdata);
765 static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
769 unsigned int mmd_address;
772 if (mmd_reg & MII_ADDR_C45)
773 mmd_address = mmd_reg & ~MII_ADDR_C45;
775 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
777 /* The PCS registers are accessed using mmio. The underlying APB3
778 * management interface uses indirect addressing to access the MMD
779 * register sets. This requires accessing of the PCS register in two
780 * phases, an address phase and a data phase.
782 * The mmio interface is based on 32-bit offsets and values. All
783 * register offsets must therefore be adjusted by left shifting the
784 * offset 2 bits and reading 32 bits of data.
786 spin_lock_irqsave(&pdata->xpcs_lock, flags);
787 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
788 mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
789 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
794 static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
795 int mmd_reg, int mmd_data)
797 unsigned int mmd_address;
800 if (mmd_reg & MII_ADDR_C45)
801 mmd_address = mmd_reg & ~MII_ADDR_C45;
803 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
805 /* The PCS registers are accessed using mmio. The underlying APB3
806 * management interface uses indirect addressing to access the MMD
807 * register sets. This requires accessing of the PCS register in two
808 * phases, an address phase and a data phase.
810 * The mmio interface is based on 32-bit offsets and values. All
811 * register offsets must therefore be adjusted by left shifting the
812 * offset 2 bits and reading 32 bits of data.
814 spin_lock_irqsave(&pdata->xpcs_lock, flags);
815 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
816 XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
817 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
820 static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
822 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
825 static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
827 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
832 static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
834 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
839 static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
841 struct xgbe_ring_desc *rdesc = rdata->rdesc;
843 /* Reset the Tx descriptor
844 * Set buffer 1 (lo) address to zero
845 * Set buffer 1 (hi) address to zero
846 * Reset all other control bits (IC, TTSE, B2L & B1L)
847 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
857 static void xgbe_tx_desc_init(struct xgbe_channel *channel)
859 struct xgbe_ring *ring = channel->tx_ring;
860 struct xgbe_ring_data *rdata;
862 int start_index = ring->cur;
864 DBGPR("-->tx_desc_init\n");
866 /* Initialze all descriptors */
867 for (i = 0; i < ring->rdesc_count; i++) {
868 rdata = XGBE_GET_DESC_DATA(ring, i);
870 /* Initialize Tx descriptor */
871 xgbe_tx_desc_reset(rdata);
874 /* Update the total number of Tx descriptors */
875 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
877 /* Update the starting address of descriptor ring */
878 rdata = XGBE_GET_DESC_DATA(ring, start_index);
879 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
880 upper_32_bits(rdata->rdata_paddr));
881 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
882 lower_32_bits(rdata->rdata_paddr));
884 DBGPR("<--tx_desc_init\n");
887 static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata,
888 struct xgbe_ring_data *rdata, unsigned int index)
890 struct xgbe_ring_desc *rdesc = rdata->rdesc;
895 /* Reset the Rx descriptor
896 * Set buffer 1 (lo) address to header dma address (lo)
897 * Set buffer 1 (hi) address to header dma address (hi)
898 * Set buffer 2 (lo) address to buffer dma address (lo)
899 * Set buffer 2 (hi) address to buffer dma address (hi) and
900 * set control bits OWN and INTE
902 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->mbuf_hdr_paddr));
903 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->mbuf_hdr_paddr));
904 rdesc->desc2 = cpu_to_le32(lower_32_bits(rdata->mbuf_data_paddr));
905 rdesc->desc3 = cpu_to_le32(upper_32_bits(rdata->mbuf_data_paddr));
907 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte);
911 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
916 static void xgbe_rx_desc_init(struct xgbe_channel *channel)
918 struct xgbe_prv_data *pdata = channel->pdata;
919 struct xgbe_ring *ring = channel->rx_ring;
920 struct xgbe_ring_data *rdata;
921 unsigned int start_index = ring->cur;
924 DBGPR("-->rx_desc_init\n");
926 /* Initialize all descriptors */
927 for (i = 0; i < ring->rdesc_count; i++) {
928 rdata = XGBE_GET_DESC_DATA(ring, i);
930 /* Initialize Rx descriptor */
931 xgbe_rx_desc_reset(pdata, rdata, i);
934 bus_dmamap_sync(ring->rdesc_dmat, ring->rdesc_map,
935 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
937 /* Update the total number of Rx descriptors */
938 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
940 /* Update the starting address of descriptor ring */
941 rdata = XGBE_GET_DESC_DATA(ring, start_index);
942 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
943 upper_32_bits(rdata->rdata_paddr));
944 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
945 lower_32_bits(rdata->rdata_paddr));
947 /* Update the Rx Descriptor Tail Pointer */
948 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
949 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
950 lower_32_bits(rdata->rdata_paddr));
952 DBGPR("<--rx_desc_init\n");
955 static void xgbe_tx_start_xmit(struct xgbe_channel *channel,
956 struct xgbe_ring *ring)
958 struct xgbe_ring_data *rdata;
960 /* Issue a poll command to Tx DMA by writing address
961 * of next immediate free descriptor */
962 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
963 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
964 lower_32_bits(rdata->rdata_paddr));
966 ring->tx.xmit_more = 0;
969 static void xgbe_dev_xmit(struct xgbe_channel *channel)
971 struct xgbe_prv_data *pdata = channel->pdata;
972 struct xgbe_ring *ring = channel->tx_ring;
973 struct xgbe_ring_data *rdata;
974 struct xgbe_ring_desc *rdesc;
975 struct xgbe_packet_data *packet = &ring->packet_data;
976 unsigned int tx_set_ic;
977 int start_index = ring->cur;
978 int cur_index = ring->cur;
981 DBGPR("-->xgbe_dev_xmit\n");
983 /* Determine if an interrupt should be generated for this Tx:
985 * - Tx frame count exceeds the frame count setting
986 * - Addition of Tx frame count to the frame count since the
987 * last interrupt was set exceeds the frame count setting
989 * - No frame count setting specified (ethtool -C ethX tx-frames 0)
990 * - Addition of Tx frame count to the frame count since the
991 * last interrupt was set does not exceed the frame count setting
993 ring->coalesce_count += packet->tx_packets;
994 if (!pdata->tx_frames)
996 else if (packet->tx_packets > pdata->tx_frames)
998 else if ((ring->coalesce_count % pdata->tx_frames) <
1005 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
1006 rdesc = rdata->rdesc;
1008 /* Update buffer address (for TSO this is the header) */
1009 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->mbuf_data_paddr));
1010 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->mbuf_data_paddr));
1012 /* Update the buffer length */
1013 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1016 /* Timestamp enablement check */
1017 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1018 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1020 /* Mark it as First Descriptor */
1021 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1023 /* Mark it as a NORMAL descriptor */
1024 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1026 /* Set OWN bit if not the first descriptor */
1027 if (cur_index != start_index)
1028 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1030 /* Enable CRC and Pad Insertion */
1031 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1033 /* Set the total length to be transmitted */
1034 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1037 for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) {
1039 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
1040 rdesc = rdata->rdesc;
1042 /* Update buffer address */
1043 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->mbuf_data_paddr));
1044 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->mbuf_data_paddr));
1046 /* Update the buffer length */
1047 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1051 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1053 /* Mark it as NORMAL descriptor */
1054 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1057 /* Set LAST bit for the last descriptor */
1058 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1060 /* Set IC bit based on Tx coalescing settings */
1062 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1064 /* Save the Tx info to report back during cleanup */
1065 rdata->tx.packets = packet->tx_packets;
1066 rdata->tx.bytes = packet->tx_bytes;
1068 /* Sync the DMA buffers */
1069 bus_dmamap_sync(ring->rdesc_dmat, ring->rdesc_map,
1070 BUS_DMASYNC_PREWRITE);
1071 bus_dmamap_sync(ring->mbuf_dmat, ring->mbuf_map,
1072 BUS_DMASYNC_PREWRITE);
1074 /* In case the Tx DMA engine is running, make sure everything
1075 * is written to the descriptor(s) before setting the OWN bit
1076 * for the first descriptor
1079 /* Set OWN bit for the first descriptor */
1080 rdata = XGBE_GET_DESC_DATA(ring, start_index);
1081 rdesc = rdata->rdesc;
1082 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1084 /* Sync to ensure the OWN bit was seen */
1085 bus_dmamap_sync(ring->rdesc_dmat, ring->rdesc_map,
1086 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1088 ring->cur = cur_index + 1;
1089 xgbe_tx_start_xmit(channel, ring);
1091 DBGPR(" %s: descriptors %u to %u written\n",
1092 channel->name, start_index & (ring->rdesc_count - 1),
1093 (ring->cur - 1) & (ring->rdesc_count - 1));
1095 DBGPR("<--xgbe_dev_xmit\n");
1098 static int xgbe_dev_read(struct xgbe_channel *channel)
1100 struct xgbe_ring *ring = channel->rx_ring;
1101 struct xgbe_ring_data *rdata;
1102 struct xgbe_ring_desc *rdesc;
1103 struct xgbe_packet_data *packet = &ring->packet_data;
1104 unsigned int err, etlt;
1106 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1108 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1109 rdesc = rdata->rdesc;
1111 bus_dmamap_sync(ring->rdesc_dmat, ring->rdesc_map,
1112 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1116 /* Check for data availability */
1117 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1122 /* Normal Descriptor, be sure Context Descriptor bit is off */
1123 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1125 /* Indicate if a Context Descriptor is next */
1126 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1127 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1130 /* Get the header length */
1131 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD)) {
1132 rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2,
1133 RX_NORMAL_DESC2, HL);
1136 /* Get the packet length */
1137 rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
1139 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1140 /* Not all the data has been transferred for this packet */
1141 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1146 /* This is the last of the data for this packet */
1147 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1150 /* Check for errors (only valid in last descriptor) */
1151 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1152 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1155 if ((etlt == 0x05) || (etlt == 0x06))
1156 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1159 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1163 bus_dmamap_sync(ring->mbuf_dmat, rdata->mbuf_map,
1164 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1166 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1167 ring->cur & (ring->rdesc_count - 1), ring->cur);
1172 static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1174 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1175 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1178 static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1180 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1181 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1184 static int xgbe_enable_int(struct xgbe_channel *channel,
1185 enum xgbe_int int_id)
1187 unsigned int dma_ch_ier;
1189 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1192 case XGMAC_INT_DMA_CH_SR_TI:
1193 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1195 case XGMAC_INT_DMA_CH_SR_TPS:
1196 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
1198 case XGMAC_INT_DMA_CH_SR_TBU:
1199 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
1201 case XGMAC_INT_DMA_CH_SR_RI:
1202 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
1204 case XGMAC_INT_DMA_CH_SR_RBU:
1205 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
1207 case XGMAC_INT_DMA_CH_SR_RPS:
1208 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1210 case XGMAC_INT_DMA_CH_SR_TI_RI:
1211 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1212 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
1214 case XGMAC_INT_DMA_CH_SR_FBE:
1215 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
1217 case XGMAC_INT_DMA_ALL:
1218 dma_ch_ier |= channel->saved_ier;
1224 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1229 static int xgbe_disable_int(struct xgbe_channel *channel,
1230 enum xgbe_int int_id)
1232 unsigned int dma_ch_ier;
1234 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1237 case XGMAC_INT_DMA_CH_SR_TI:
1238 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1240 case XGMAC_INT_DMA_CH_SR_TPS:
1241 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
1243 case XGMAC_INT_DMA_CH_SR_TBU:
1244 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
1246 case XGMAC_INT_DMA_CH_SR_RI:
1247 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
1249 case XGMAC_INT_DMA_CH_SR_RBU:
1250 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
1252 case XGMAC_INT_DMA_CH_SR_RPS:
1253 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1255 case XGMAC_INT_DMA_CH_SR_TI_RI:
1256 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1257 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
1259 case XGMAC_INT_DMA_CH_SR_FBE:
1260 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
1262 case XGMAC_INT_DMA_ALL:
1263 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
1264 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
1270 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1275 static int xgbe_exit(struct xgbe_prv_data *pdata)
1277 unsigned int count = 2000;
1279 DBGPR("-->xgbe_exit\n");
1281 /* Issue a software reset */
1282 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1285 /* Poll Until Poll Condition */
1286 while (--count && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1292 DBGPR("<--xgbe_exit\n");
1297 static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1299 unsigned int i, count;
1301 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
1304 for (i = 0; i < pdata->tx_q_count; i++)
1305 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1307 /* Poll Until Poll Condition */
1308 for (i = 0; i < pdata->tx_q_count; i++) {
1310 while (--count && XGMAC_MTL_IOREAD_BITS(pdata, i,
1321 static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1323 /* Set enhanced addressing mode */
1324 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1326 /* Set the System Bus mode */
1327 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
1328 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
1331 static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1333 unsigned int arcache, awcache;
1336 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
1337 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
1338 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
1339 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
1340 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
1341 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
1342 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1345 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
1346 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
1347 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
1348 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
1349 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
1350 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
1351 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
1352 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
1353 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1356 static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1360 /* Set Tx to weighted round robin scheduling algorithm */
1361 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1363 /* Set Tx traffic classes to use WRR algorithm with equal weights */
1364 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1365 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1367 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
1370 /* Set Rx to strict priority algorithm */
1371 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1374 static unsigned int xgbe_calculate_per_queue_fifo(unsigned int fifo_size,
1375 unsigned int queue_count)
1377 unsigned int q_fifo_size;
1378 unsigned int p_fifo;
1380 /* Calculate the configured fifo size */
1381 q_fifo_size = 1 << (fifo_size + 7);
1383 /* The configured value may not be the actual amount of fifo RAM */
1384 q_fifo_size = min_t(unsigned int, XGBE_FIFO_MAX, q_fifo_size);
1386 q_fifo_size = q_fifo_size / queue_count;
1388 /* Each increment in the queue fifo size represents 256 bytes of
1389 * fifo, with 0 representing 256 bytes. Distribute the fifo equally
1390 * between the queues.
1392 p_fifo = q_fifo_size / 256;
1399 static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
1401 unsigned int fifo_size;
1404 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
1407 for (i = 0; i < pdata->tx_q_count; i++)
1408 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
1411 static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
1413 unsigned int fifo_size;
1416 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
1419 for (i = 0; i < pdata->rx_q_count; i++)
1420 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
1423 static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
1425 unsigned int qptc, qptc_extra, queue;
1426 unsigned int prio_queues;
1427 unsigned int ppq, ppq_extra, prio;
1429 unsigned int i, j, reg, reg_val;
1431 /* Map the MTL Tx Queues to Traffic Classes
1432 * Note: Tx Queues >= Traffic Classes
1434 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
1435 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
1437 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
1438 for (j = 0; j < qptc; j++) {
1439 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1441 pdata->q2tc_map[queue++] = i;
1444 if (i < qptc_extra) {
1445 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1447 pdata->q2tc_map[queue++] = i;
1451 /* Map the 8 VLAN priority values to available MTL Rx queues */
1452 prio_queues = min_t(unsigned int, IEEE_8021QAZ_MAX_TCS,
1454 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
1455 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
1459 for (i = 0, prio = 0; i < prio_queues;) {
1461 for (j = 0; j < ppq; j++) {
1462 mask |= (1 << prio);
1463 pdata->prio2q_map[prio++] = i;
1466 if (i < ppq_extra) {
1467 mask |= (1 << prio);
1468 pdata->prio2q_map[prio++] = i;
1471 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
1473 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
1476 XGMAC_IOWRITE(pdata, reg, reg_val);
1477 reg += MAC_RQC2_INC;
1481 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
1484 for (i = 0; i < pdata->rx_q_count;) {
1485 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
1487 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
1490 XGMAC_IOWRITE(pdata, reg, reg_val);
1492 reg += MTL_RQDCM_INC;
1497 static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
1501 for (i = 0; i < pdata->rx_q_count; i++) {
1502 /* Activate flow control when less than 4k left in fifo */
1503 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFA, 2);
1505 /* De-activate flow control when more than 6k left in fifo */
1506 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFD, 4);
1510 static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
1513 xgbe_set_mac_address(pdata, IF_LLADDR(pdata->netdev));
1516 static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
1520 val = (if_getmtu(pdata->netdev) > XGMAC_STD_PACKET_MTU) ? 1 : 0;
1522 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1525 static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata)
1527 switch (pdata->phy_speed) {
1529 xgbe_set_xgmii_speed(pdata);
1533 xgbe_set_gmii_2500_speed(pdata);
1537 xgbe_set_gmii_speed(pdata);
1542 panic("TODO %s:%d\n", __FILE__, __LINE__);
1546 static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
1548 if ((if_getcapenable(pdata->netdev) & IFCAP_RXCSUM) != 0)
1549 xgbe_enable_rx_csum(pdata);
1551 xgbe_disable_rx_csum(pdata);
1554 static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
1556 /* Indicate that VLAN Tx CTAGs come from context descriptors */
1557 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
1558 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
1560 /* Set the current VLAN Hash Table register value */
1561 xgbe_update_vlan_hash_table(pdata);
1563 xgbe_disable_rx_vlan_filtering(pdata);
1564 xgbe_disable_rx_vlan_stripping(pdata);
1567 static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
1573 /* These registers are always 64 bit */
1574 case MMC_TXOCTETCOUNT_GB_LO:
1575 case MMC_TXOCTETCOUNT_G_LO:
1576 case MMC_RXOCTETCOUNT_GB_LO:
1577 case MMC_RXOCTETCOUNT_G_LO:
1585 val = XGMAC_IOREAD(pdata, reg_lo);
1588 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
1593 static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
1595 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1596 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
1598 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
1599 stats->txoctetcount_gb +=
1600 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
1602 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
1603 stats->txframecount_gb +=
1604 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
1606 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
1607 stats->txbroadcastframes_g +=
1608 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1610 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
1611 stats->txmulticastframes_g +=
1612 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1614 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
1615 stats->tx64octets_gb +=
1616 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
1618 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
1619 stats->tx65to127octets_gb +=
1620 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
1622 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
1623 stats->tx128to255octets_gb +=
1624 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
1626 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
1627 stats->tx256to511octets_gb +=
1628 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
1630 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
1631 stats->tx512to1023octets_gb +=
1632 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1634 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
1635 stats->tx1024tomaxoctets_gb +=
1636 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1638 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
1639 stats->txunicastframes_gb +=
1640 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
1642 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
1643 stats->txmulticastframes_gb +=
1644 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
1646 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
1647 stats->txbroadcastframes_g +=
1648 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
1650 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
1651 stats->txunderflowerror +=
1652 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
1654 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
1655 stats->txoctetcount_g +=
1656 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
1658 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
1659 stats->txframecount_g +=
1660 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
1662 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
1663 stats->txpauseframes +=
1664 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
1666 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
1667 stats->txvlanframes_g +=
1668 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
1671 static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
1673 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1674 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
1676 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
1677 stats->rxframecount_gb +=
1678 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
1680 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
1681 stats->rxoctetcount_gb +=
1682 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
1684 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
1685 stats->rxoctetcount_g +=
1686 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
1688 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
1689 stats->rxbroadcastframes_g +=
1690 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
1692 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
1693 stats->rxmulticastframes_g +=
1694 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
1696 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
1697 stats->rxcrcerror +=
1698 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
1700 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
1701 stats->rxrunterror +=
1702 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
1704 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
1705 stats->rxjabbererror +=
1706 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
1708 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
1709 stats->rxundersize_g +=
1710 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
1712 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
1713 stats->rxoversize_g +=
1714 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
1716 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
1717 stats->rx64octets_gb +=
1718 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
1720 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
1721 stats->rx65to127octets_gb +=
1722 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
1724 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
1725 stats->rx128to255octets_gb +=
1726 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
1728 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
1729 stats->rx256to511octets_gb +=
1730 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
1732 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
1733 stats->rx512to1023octets_gb +=
1734 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
1736 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
1737 stats->rx1024tomaxoctets_gb +=
1738 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
1740 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
1741 stats->rxunicastframes_g +=
1742 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
1744 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
1745 stats->rxlengtherror +=
1746 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
1748 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
1749 stats->rxoutofrangetype +=
1750 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
1752 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
1753 stats->rxpauseframes +=
1754 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
1756 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
1757 stats->rxfifooverflow +=
1758 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
1760 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
1761 stats->rxvlanframes_gb +=
1762 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
1764 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
1765 stats->rxwatchdogerror +=
1766 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
1769 static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
1771 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1773 /* Freeze counters */
1774 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
1776 stats->txoctetcount_gb +=
1777 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
1779 stats->txframecount_gb +=
1780 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
1782 stats->txbroadcastframes_g +=
1783 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1785 stats->txmulticastframes_g +=
1786 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1788 stats->tx64octets_gb +=
1789 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
1791 stats->tx65to127octets_gb +=
1792 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
1794 stats->tx128to255octets_gb +=
1795 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
1797 stats->tx256to511octets_gb +=
1798 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
1800 stats->tx512to1023octets_gb +=
1801 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1803 stats->tx1024tomaxoctets_gb +=
1804 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1806 stats->txunicastframes_gb +=
1807 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
1809 stats->txmulticastframes_gb +=
1810 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
1812 stats->txbroadcastframes_g +=
1813 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
1815 stats->txunderflowerror +=
1816 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
1818 stats->txoctetcount_g +=
1819 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
1821 stats->txframecount_g +=
1822 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
1824 stats->txpauseframes +=
1825 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
1827 stats->txvlanframes_g +=
1828 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
1830 stats->rxframecount_gb +=
1831 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
1833 stats->rxoctetcount_gb +=
1834 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
1836 stats->rxoctetcount_g +=
1837 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
1839 stats->rxbroadcastframes_g +=
1840 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
1842 stats->rxmulticastframes_g +=
1843 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
1845 stats->rxcrcerror +=
1846 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
1848 stats->rxrunterror +=
1849 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
1851 stats->rxjabbererror +=
1852 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
1854 stats->rxundersize_g +=
1855 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
1857 stats->rxoversize_g +=
1858 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
1860 stats->rx64octets_gb +=
1861 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
1863 stats->rx65to127octets_gb +=
1864 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
1866 stats->rx128to255octets_gb +=
1867 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
1869 stats->rx256to511octets_gb +=
1870 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
1872 stats->rx512to1023octets_gb +=
1873 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
1875 stats->rx1024tomaxoctets_gb +=
1876 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
1878 stats->rxunicastframes_g +=
1879 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
1881 stats->rxlengtherror +=
1882 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
1884 stats->rxoutofrangetype +=
1885 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
1887 stats->rxpauseframes +=
1888 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
1890 stats->rxfifooverflow +=
1891 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
1893 stats->rxvlanframes_gb +=
1894 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
1896 stats->rxwatchdogerror +=
1897 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
1899 /* Un-freeze counters */
1900 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
1903 static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
1905 /* Set counters to reset on read */
1906 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
1908 /* Reset the counters */
1909 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
1912 static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
1913 struct xgbe_channel *channel)
1915 unsigned int tx_dsr, tx_pos, tx_qidx;
1916 unsigned int tx_status;
1917 unsigned long tx_timeout;
1919 /* Calculate the status register to read and the position within */
1920 if (channel->queue_index < DMA_DSRX_FIRST_QUEUE) {
1922 tx_pos = (channel->queue_index * DMA_DSR_Q_WIDTH) +
1925 tx_qidx = channel->queue_index - DMA_DSRX_FIRST_QUEUE;
1927 tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
1928 tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
1932 /* The Tx engine cannot be stopped if it is actively processing
1933 * descriptors. Wait for the Tx engine to enter the stopped or
1934 * suspended state. Don't wait forever though...
1936 tx_timeout = ticks + (XGBE_DMA_STOP_TIMEOUT * hz);
1937 while (ticks < tx_timeout) {
1938 tx_status = XGMAC_IOREAD(pdata, tx_dsr);
1939 tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
1940 if ((tx_status == DMA_TPS_STOPPED) ||
1941 (tx_status == DMA_TPS_SUSPENDED))
1948 static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
1950 struct xgbe_channel *channel;
1953 /* Enable each Tx DMA channel */
1954 channel = pdata->channel;
1955 for (i = 0; i < pdata->channel_count; i++, channel++) {
1956 if (!channel->tx_ring)
1959 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
1962 /* Enable each Tx queue */
1963 for (i = 0; i < pdata->tx_q_count; i++)
1964 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
1968 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
1971 static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
1973 struct xgbe_channel *channel;
1976 /* Prepare for Tx DMA channel stop */
1977 channel = pdata->channel;
1978 for (i = 0; i < pdata->channel_count; i++, channel++) {
1979 if (!channel->tx_ring)
1982 xgbe_prepare_tx_stop(pdata, channel);
1985 /* Disable MAC Tx */
1986 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
1988 /* Disable each Tx queue */
1989 for (i = 0; i < pdata->tx_q_count; i++)
1990 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 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_prepare_rx_stop(struct xgbe_prv_data *pdata,
2005 unsigned int rx_status;
2006 unsigned long rx_timeout;
2008 /* The Rx engine cannot be stopped if it is actively processing
2009 * packets. Wait for the Rx queue to empty the Rx fifo. Don't
2010 * wait forever though...
2012 rx_timeout = ticks + (XGBE_DMA_STOP_TIMEOUT * hz);
2013 while (ticks < rx_timeout) {
2014 rx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR);
2015 if ((XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) &&
2016 (XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0))
2023 static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
2025 struct xgbe_channel *channel;
2026 unsigned int reg_val, i;
2028 /* Enable each Rx DMA channel */
2029 channel = pdata->channel;
2030 for (i = 0; i < pdata->channel_count; i++, channel++) {
2031 if (!channel->rx_ring)
2034 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2037 /* Enable each Rx queue */
2039 for (i = 0; i < pdata->rx_q_count; i++)
2040 reg_val |= (0x02 << (i << 1));
2041 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
2044 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
2045 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
2046 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
2047 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
2050 static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
2052 struct xgbe_channel *channel;
2055 /* Disable MAC Rx */
2056 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
2057 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
2058 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
2059 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
2061 /* Prepare for Rx DMA channel stop */
2062 for (i = 0; i < pdata->rx_q_count; i++)
2063 xgbe_prepare_rx_stop(pdata, i);
2065 /* Disable each Rx queue */
2066 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
2068 /* Disable each Rx DMA channel */
2069 channel = pdata->channel;
2070 for (i = 0; i < pdata->channel_count; i++, channel++) {
2071 if (!channel->rx_ring)
2074 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2078 static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
2080 struct xgbe_channel *channel;
2083 /* Enable each Tx DMA channel */
2084 channel = pdata->channel;
2085 for (i = 0; i < pdata->channel_count; i++, channel++) {
2086 if (!channel->tx_ring)
2089 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2093 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2096 static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
2098 struct xgbe_channel *channel;
2101 /* Prepare for Tx DMA channel stop */
2102 channel = pdata->channel;
2103 for (i = 0; i < pdata->channel_count; i++, channel++) {
2104 if (!channel->tx_ring)
2107 xgbe_prepare_tx_stop(pdata, channel);
2110 /* Disable MAC Tx */
2111 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2113 /* Disable each Tx DMA channel */
2114 channel = pdata->channel;
2115 for (i = 0; i < pdata->channel_count; i++, channel++) {
2116 if (!channel->tx_ring)
2119 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2123 static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2125 struct xgbe_channel *channel;
2128 /* Enable each Rx DMA channel */
2129 channel = pdata->channel;
2130 for (i = 0; i < pdata->channel_count; i++, channel++) {
2131 if (!channel->rx_ring)
2134 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2138 static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2140 struct xgbe_channel *channel;
2143 /* Disable each Rx DMA channel */
2144 channel = pdata->channel;
2145 for (i = 0; i < pdata->channel_count; i++, channel++) {
2146 if (!channel->rx_ring)
2149 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2153 static int xgbe_init(struct xgbe_prv_data *pdata)
2155 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2158 DBGPR("-->xgbe_init\n");
2160 /* Flush Tx queues */
2161 ret = xgbe_flush_tx_queues(pdata);
2166 * Initialize DMA related features
2168 xgbe_config_dma_bus(pdata);
2169 xgbe_config_dma_cache(pdata);
2170 xgbe_config_osp_mode(pdata);
2171 xgbe_config_pblx8(pdata);
2172 xgbe_config_tx_pbl_val(pdata);
2173 xgbe_config_rx_pbl_val(pdata);
2174 xgbe_config_rx_coalesce(pdata);
2175 xgbe_config_tx_coalesce(pdata);
2176 xgbe_config_rx_buffer_size(pdata);
2177 xgbe_config_tso_mode(pdata);
2178 xgbe_config_sph_mode(pdata);
2179 xgbe_config_rss(pdata);
2180 desc_if->wrapper_tx_desc_init(pdata);
2181 desc_if->wrapper_rx_desc_init(pdata);
2182 xgbe_enable_dma_interrupts(pdata);
2185 * Initialize MTL related features
2187 xgbe_config_mtl_mode(pdata);
2188 xgbe_config_queue_mapping(pdata);
2189 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2190 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2191 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2192 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2193 xgbe_config_tx_fifo_size(pdata);
2194 xgbe_config_rx_fifo_size(pdata);
2195 xgbe_config_flow_control_threshold(pdata);
2196 /*TODO: Error Packet and undersized good Packet forwarding enable
2199 xgbe_enable_mtl_interrupts(pdata);
2202 * Initialize MAC related features
2204 xgbe_config_mac_address(pdata);
2205 xgbe_config_rx_mode(pdata);
2206 xgbe_config_jumbo_enable(pdata);
2207 xgbe_config_flow_control(pdata);
2208 xgbe_config_mac_speed(pdata);
2209 xgbe_config_checksum_offload(pdata);
2210 xgbe_config_vlan_support(pdata);
2211 xgbe_config_mmc(pdata);
2212 xgbe_enable_mac_interrupts(pdata);
2214 DBGPR("<--xgbe_init\n");
2219 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2221 DBGPR("-->xgbe_init_function_ptrs\n");
2223 hw_if->tx_complete = xgbe_tx_complete;
2225 hw_if->set_mac_address = xgbe_set_mac_address;
2226 hw_if->config_rx_mode = xgbe_config_rx_mode;
2228 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2229 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2231 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2232 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
2233 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
2234 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
2235 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
2237 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2238 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2240 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2241 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2242 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2244 hw_if->enable_tx = xgbe_enable_tx;
2245 hw_if->disable_tx = xgbe_disable_tx;
2246 hw_if->enable_rx = xgbe_enable_rx;
2247 hw_if->disable_rx = xgbe_disable_rx;
2249 hw_if->powerup_tx = xgbe_powerup_tx;
2250 hw_if->powerdown_tx = xgbe_powerdown_tx;
2251 hw_if->powerup_rx = xgbe_powerup_rx;
2252 hw_if->powerdown_rx = xgbe_powerdown_rx;
2254 hw_if->dev_xmit = xgbe_dev_xmit;
2255 hw_if->dev_read = xgbe_dev_read;
2256 hw_if->enable_int = xgbe_enable_int;
2257 hw_if->disable_int = xgbe_disable_int;
2258 hw_if->init = xgbe_init;
2259 hw_if->exit = xgbe_exit;
2261 /* Descriptor related Sequences have to be initialized here */
2262 hw_if->tx_desc_init = xgbe_tx_desc_init;
2263 hw_if->rx_desc_init = xgbe_rx_desc_init;
2264 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2265 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2266 hw_if->is_last_desc = xgbe_is_last_desc;
2267 hw_if->is_context_desc = xgbe_is_context_desc;
2268 hw_if->tx_start_xmit = xgbe_tx_start_xmit;
2271 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2272 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2274 /* For RX coalescing */
2275 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2276 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2277 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2278 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2280 /* For RX and TX threshold config */
2281 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2282 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2284 /* For RX and TX Store and Forward Mode config */
2285 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2286 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2288 /* For TX DMA Operating on Second Frame config */
2289 hw_if->config_osp_mode = xgbe_config_osp_mode;
2291 /* For RX and TX PBL config */
2292 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2293 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2294 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2295 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2296 hw_if->config_pblx8 = xgbe_config_pblx8;
2298 /* For MMC statistics support */
2299 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2300 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2301 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2303 /* For Receive Side Scaling */
2304 hw_if->disable_rss = xgbe_disable_rss;
2306 DBGPR("<--xgbe_init_function_ptrs\n");