Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / net / ethernet / amd / xgbe / xgbe-dev.c
blobe107e180e2c8e5e0071f38dd96557a13b64baae2
1 /*
2 * AMD 10Gb Ethernet driver
4 * This file is available to you under your choice of the following two
5 * licenses:
7 * License 1: GPLv2
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
25 * permission notice:
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
29 * and you.
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
85 * permission notice:
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
89 * and you.
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/mdio.h>
119 #include <linux/clk.h>
120 #include <linux/bitrev.h>
121 #include <linux/crc32.h>
123 #include "xgbe.h"
124 #include "xgbe-common.h"
126 static inline unsigned int xgbe_get_max_frame(struct xgbe_prv_data *pdata)
128 return pdata->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
131 static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
132 unsigned int usec)
134 unsigned long rate;
135 unsigned int ret;
137 DBGPR("-->xgbe_usec_to_riwt\n");
139 rate = pdata->sysclk_rate;
142 * Convert the input usec value to the watchdog timer value. Each
143 * watchdog timer value is equivalent to 256 clock cycles.
144 * Calculate the required value as:
145 * ( usec * ( system_clock_mhz / 10^6 ) / 256
147 ret = (usec * (rate / 1000000)) / 256;
149 DBGPR("<--xgbe_usec_to_riwt\n");
151 return ret;
154 static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
155 unsigned int riwt)
157 unsigned long rate;
158 unsigned int ret;
160 DBGPR("-->xgbe_riwt_to_usec\n");
162 rate = pdata->sysclk_rate;
165 * Convert the input watchdog timer value to the usec value. Each
166 * watchdog timer value is equivalent to 256 clock cycles.
167 * Calculate the required value as:
168 * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
170 ret = (riwt * 256) / (rate / 1000000);
172 DBGPR("<--xgbe_riwt_to_usec\n");
174 return ret;
177 static int xgbe_config_pbl_val(struct xgbe_prv_data *pdata)
179 unsigned int pblx8, pbl;
180 unsigned int i;
182 pblx8 = DMA_PBL_X8_DISABLE;
183 pbl = pdata->pbl;
185 if (pdata->pbl > 32) {
186 pblx8 = DMA_PBL_X8_ENABLE;
187 pbl >>= 3;
190 for (i = 0; i < pdata->channel_count; i++) {
191 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_CR, PBLX8,
192 pblx8);
194 if (pdata->channel[i]->tx_ring)
195 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR,
196 PBL, pbl);
198 if (pdata->channel[i]->rx_ring)
199 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR,
200 PBL, pbl);
203 return 0;
206 static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
208 unsigned int i;
210 for (i = 0; i < pdata->channel_count; i++) {
211 if (!pdata->channel[i]->tx_ring)
212 break;
214 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, OSP,
215 pdata->tx_osp_mode);
218 return 0;
221 static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
223 unsigned int i;
225 for (i = 0; i < pdata->rx_q_count; i++)
226 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
228 return 0;
231 static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
233 unsigned int i;
235 for (i = 0; i < pdata->tx_q_count; i++)
236 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
238 return 0;
241 static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
242 unsigned int val)
244 unsigned int i;
246 for (i = 0; i < pdata->rx_q_count; i++)
247 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
249 return 0;
252 static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
253 unsigned int val)
255 unsigned int i;
257 for (i = 0; i < pdata->tx_q_count; i++)
258 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
260 return 0;
263 static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
265 unsigned int i;
267 for (i = 0; i < pdata->channel_count; i++) {
268 if (!pdata->channel[i]->rx_ring)
269 break;
271 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RIWT, RWT,
272 pdata->rx_riwt);
275 return 0;
278 static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
280 return 0;
283 static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
285 unsigned int i;
287 for (i = 0; i < pdata->channel_count; i++) {
288 if (!pdata->channel[i]->rx_ring)
289 break;
291 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, RBSZ,
292 pdata->rx_buf_size);
296 static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
298 unsigned int i;
300 for (i = 0; i < pdata->channel_count; i++) {
301 if (!pdata->channel[i]->tx_ring)
302 break;
304 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, TSE, 1);
308 static void xgbe_config_sph_mode(struct xgbe_prv_data *pdata)
310 unsigned int i;
312 for (i = 0; i < pdata->channel_count; i++) {
313 if (!pdata->channel[i]->rx_ring)
314 break;
316 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_CR, SPH, 1);
319 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE);
322 static int xgbe_write_rss_reg(struct xgbe_prv_data *pdata, unsigned int type,
323 unsigned int index, unsigned int val)
325 unsigned int wait;
326 int ret = 0;
328 mutex_lock(&pdata->rss_mutex);
330 if (XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB)) {
331 ret = -EBUSY;
332 goto unlock;
335 XGMAC_IOWRITE(pdata, MAC_RSSDR, val);
337 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, RSSIA, index);
338 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, ADDRT, type);
339 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, CT, 0);
340 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, OB, 1);
342 wait = 1000;
343 while (wait--) {
344 if (!XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB))
345 goto unlock;
347 usleep_range(1000, 1500);
350 ret = -EBUSY;
352 unlock:
353 mutex_unlock(&pdata->rss_mutex);
355 return ret;
358 static int xgbe_write_rss_hash_key(struct xgbe_prv_data *pdata)
360 unsigned int key_regs = sizeof(pdata->rss_key) / sizeof(u32);
361 unsigned int *key = (unsigned int *)&pdata->rss_key;
362 int ret;
364 while (key_regs--) {
365 ret = xgbe_write_rss_reg(pdata, XGBE_RSS_HASH_KEY_TYPE,
366 key_regs, *key++);
367 if (ret)
368 return ret;
371 return 0;
374 static int xgbe_write_rss_lookup_table(struct xgbe_prv_data *pdata)
376 unsigned int i;
377 int ret;
379 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) {
380 ret = xgbe_write_rss_reg(pdata,
381 XGBE_RSS_LOOKUP_TABLE_TYPE, i,
382 pdata->rss_table[i]);
383 if (ret)
384 return ret;
387 return 0;
390 static int xgbe_set_rss_hash_key(struct xgbe_prv_data *pdata, const u8 *key)
392 memcpy(pdata->rss_key, key, sizeof(pdata->rss_key));
394 return xgbe_write_rss_hash_key(pdata);
397 static int xgbe_set_rss_lookup_table(struct xgbe_prv_data *pdata,
398 const u32 *table)
400 unsigned int i;
402 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
403 XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, table[i]);
405 return xgbe_write_rss_lookup_table(pdata);
408 static int xgbe_enable_rss(struct xgbe_prv_data *pdata)
410 int ret;
412 if (!pdata->hw_feat.rss)
413 return -EOPNOTSUPP;
415 /* Program the hash key */
416 ret = xgbe_write_rss_hash_key(pdata);
417 if (ret)
418 return ret;
420 /* Program the lookup table */
421 ret = xgbe_write_rss_lookup_table(pdata);
422 if (ret)
423 return ret;
425 /* Set the RSS options */
426 XGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options);
428 /* Enable RSS */
429 XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 1);
431 return 0;
434 static int xgbe_disable_rss(struct xgbe_prv_data *pdata)
436 if (!pdata->hw_feat.rss)
437 return -EOPNOTSUPP;
439 XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 0);
441 return 0;
444 static void xgbe_config_rss(struct xgbe_prv_data *pdata)
446 int ret;
448 if (!pdata->hw_feat.rss)
449 return;
451 if (pdata->netdev->features & NETIF_F_RXHASH)
452 ret = xgbe_enable_rss(pdata);
453 else
454 ret = xgbe_disable_rss(pdata);
456 if (ret)
457 netdev_err(pdata->netdev,
458 "error configuring RSS, RSS disabled\n");
461 static bool xgbe_is_pfc_queue(struct xgbe_prv_data *pdata,
462 unsigned int queue)
464 unsigned int prio, tc;
466 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
467 /* Does this queue handle the priority? */
468 if (pdata->prio2q_map[prio] != queue)
469 continue;
471 /* Get the Traffic Class for this priority */
472 tc = pdata->ets->prio_tc[prio];
474 /* Check if PFC is enabled for this traffic class */
475 if (pdata->pfc->pfc_en & (1 << tc))
476 return true;
479 return false;
482 static void xgbe_set_vxlan_id(struct xgbe_prv_data *pdata)
484 /* Program the VXLAN port */
485 XGMAC_IOWRITE_BITS(pdata, MAC_TIR, TNID, pdata->vxlan_port);
487 netif_dbg(pdata, drv, pdata->netdev, "VXLAN tunnel id set to %hx\n",
488 pdata->vxlan_port);
491 static void xgbe_enable_vxlan(struct xgbe_prv_data *pdata)
493 if (!pdata->hw_feat.vxn)
494 return;
496 /* Program the VXLAN port */
497 xgbe_set_vxlan_id(pdata);
499 /* Allow for IPv6/UDP zero-checksum VXLAN packets */
500 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VUCC, 1);
502 /* Enable VXLAN tunneling mode */
503 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, VNM, 0);
504 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, VNE, 1);
506 netif_dbg(pdata, drv, pdata->netdev, "VXLAN acceleration enabled\n");
509 static void xgbe_disable_vxlan(struct xgbe_prv_data *pdata)
511 if (!pdata->hw_feat.vxn)
512 return;
514 /* Disable tunneling mode */
515 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, VNE, 0);
517 /* Clear IPv6/UDP zero-checksum VXLAN packets setting */
518 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VUCC, 0);
520 /* Clear the VXLAN port */
521 XGMAC_IOWRITE_BITS(pdata, MAC_TIR, TNID, 0);
523 netif_dbg(pdata, drv, pdata->netdev, "VXLAN acceleration disabled\n");
526 static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
528 unsigned int max_q_count, q_count;
529 unsigned int reg, reg_val;
530 unsigned int i;
532 /* Clear MTL flow control */
533 for (i = 0; i < pdata->rx_q_count; i++)
534 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
536 /* Clear MAC flow control */
537 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
538 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
539 reg = MAC_Q0TFCR;
540 for (i = 0; i < q_count; i++) {
541 reg_val = XGMAC_IOREAD(pdata, reg);
542 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
543 XGMAC_IOWRITE(pdata, reg, reg_val);
545 reg += MAC_QTFCR_INC;
548 return 0;
551 static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
553 struct ieee_pfc *pfc = pdata->pfc;
554 struct ieee_ets *ets = pdata->ets;
555 unsigned int max_q_count, q_count;
556 unsigned int reg, reg_val;
557 unsigned int i;
559 /* Set MTL flow control */
560 for (i = 0; i < pdata->rx_q_count; i++) {
561 unsigned int ehfc = 0;
563 if (pdata->rx_rfd[i]) {
564 /* Flow control thresholds are established */
565 if (pfc && ets) {
566 if (xgbe_is_pfc_queue(pdata, i))
567 ehfc = 1;
568 } else {
569 ehfc = 1;
573 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, ehfc);
575 netif_dbg(pdata, drv, pdata->netdev,
576 "flow control %s for RXq%u\n",
577 ehfc ? "enabled" : "disabled", i);
580 /* Set MAC flow control */
581 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
582 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
583 reg = MAC_Q0TFCR;
584 for (i = 0; i < q_count; i++) {
585 reg_val = XGMAC_IOREAD(pdata, reg);
587 /* Enable transmit flow control */
588 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
589 /* Set pause time */
590 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
592 XGMAC_IOWRITE(pdata, reg, reg_val);
594 reg += MAC_QTFCR_INC;
597 return 0;
600 static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
602 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
604 return 0;
607 static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
609 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
611 return 0;
614 static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
616 struct ieee_pfc *pfc = pdata->pfc;
618 if (pdata->tx_pause || (pfc && pfc->pfc_en))
619 xgbe_enable_tx_flow_control(pdata);
620 else
621 xgbe_disable_tx_flow_control(pdata);
623 return 0;
626 static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
628 struct ieee_pfc *pfc = pdata->pfc;
630 if (pdata->rx_pause || (pfc && pfc->pfc_en))
631 xgbe_enable_rx_flow_control(pdata);
632 else
633 xgbe_disable_rx_flow_control(pdata);
635 return 0;
638 static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
640 struct ieee_pfc *pfc = pdata->pfc;
642 xgbe_config_tx_flow_control(pdata);
643 xgbe_config_rx_flow_control(pdata);
645 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
646 (pfc && pfc->pfc_en) ? 1 : 0);
649 static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
651 struct xgbe_channel *channel;
652 unsigned int i, ver;
654 /* Set the interrupt mode if supported */
655 if (pdata->channel_irq_mode)
656 XGMAC_IOWRITE_BITS(pdata, DMA_MR, INTM,
657 pdata->channel_irq_mode);
659 ver = XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER);
661 for (i = 0; i < pdata->channel_count; i++) {
662 channel = pdata->channel[i];
664 /* Clear all the interrupts which are set */
665 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR,
666 XGMAC_DMA_IOREAD(channel, DMA_CH_SR));
668 /* Clear all interrupt enable bits */
669 channel->curr_ier = 0;
671 /* Enable following interrupts
672 * NIE - Normal Interrupt Summary Enable
673 * AIE - Abnormal Interrupt Summary Enable
674 * FBEE - Fatal Bus Error Enable
676 if (ver < 0x21) {
677 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, NIE20, 1);
678 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, AIE20, 1);
679 } else {
680 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, NIE, 1);
681 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, AIE, 1);
683 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, FBEE, 1);
685 if (channel->tx_ring) {
686 /* Enable the following Tx interrupts
687 * TIE - Transmit Interrupt Enable (unless using
688 * per channel interrupts in edge triggered
689 * mode)
691 if (!pdata->per_channel_irq || pdata->channel_irq_mode)
692 XGMAC_SET_BITS(channel->curr_ier,
693 DMA_CH_IER, TIE, 1);
695 if (channel->rx_ring) {
696 /* Enable following Rx interrupts
697 * RBUE - Receive Buffer Unavailable Enable
698 * RIE - Receive Interrupt Enable (unless using
699 * per channel interrupts in edge triggered
700 * mode)
702 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RBUE, 1);
703 if (!pdata->per_channel_irq || pdata->channel_irq_mode)
704 XGMAC_SET_BITS(channel->curr_ier,
705 DMA_CH_IER, RIE, 1);
708 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, channel->curr_ier);
712 static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
714 unsigned int mtl_q_isr;
715 unsigned int q_count, i;
717 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
718 for (i = 0; i < q_count; i++) {
719 /* Clear all the interrupts which are set */
720 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
721 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
723 /* No MTL interrupts to be enabled */
724 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
728 static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
730 unsigned int mac_ier = 0;
732 /* Enable Timestamp interrupt */
733 XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
735 XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
737 /* Enable all counter interrupts */
738 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
739 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
741 /* Enable MDIO single command completion interrupt */
742 XGMAC_IOWRITE_BITS(pdata, MAC_MDIOIER, SNGLCOMPIE, 1);
745 static void xgbe_enable_ecc_interrupts(struct xgbe_prv_data *pdata)
747 unsigned int ecc_isr, ecc_ier = 0;
749 if (!pdata->vdata->ecc_support)
750 return;
752 /* Clear all the interrupts which are set */
753 ecc_isr = XP_IOREAD(pdata, XP_ECC_ISR);
754 XP_IOWRITE(pdata, XP_ECC_ISR, ecc_isr);
756 /* Enable ECC interrupts */
757 XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_DED, 1);
758 XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_SEC, 1);
759 XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_DED, 1);
760 XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_SEC, 1);
761 XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_DED, 1);
762 XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_SEC, 1);
764 XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier);
767 static void xgbe_disable_ecc_ded(struct xgbe_prv_data *pdata)
769 unsigned int ecc_ier;
771 ecc_ier = XP_IOREAD(pdata, XP_ECC_IER);
773 /* Disable ECC DED interrupts */
774 XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_DED, 0);
775 XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_DED, 0);
776 XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_DED, 0);
778 XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier);
781 static void xgbe_disable_ecc_sec(struct xgbe_prv_data *pdata,
782 enum xgbe_ecc_sec sec)
784 unsigned int ecc_ier;
786 ecc_ier = XP_IOREAD(pdata, XP_ECC_IER);
788 /* Disable ECC SEC interrupt */
789 switch (sec) {
790 case XGBE_ECC_SEC_TX:
791 XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_SEC, 0);
792 break;
793 case XGBE_ECC_SEC_RX:
794 XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_SEC, 0);
795 break;
796 case XGBE_ECC_SEC_DESC:
797 XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_SEC, 0);
798 break;
801 XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier);
804 static int xgbe_set_speed(struct xgbe_prv_data *pdata, int speed)
806 unsigned int ss;
808 switch (speed) {
809 case SPEED_1000:
810 ss = 0x03;
811 break;
812 case SPEED_2500:
813 ss = 0x02;
814 break;
815 case SPEED_10000:
816 ss = 0x00;
817 break;
818 default:
819 return -EINVAL;
822 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) != ss)
823 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, ss);
825 return 0;
828 static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
830 /* Put the VLAN tag in the Rx descriptor */
831 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
833 /* Don't check the VLAN type */
834 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
836 /* Check only C-TAG (0x8100) packets */
837 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
839 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
840 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
842 /* Enable VLAN tag stripping */
843 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
845 return 0;
848 static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
850 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
852 return 0;
855 static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
857 /* Enable VLAN filtering */
858 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
860 /* Enable VLAN Hash Table filtering */
861 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
863 /* Disable VLAN tag inverse matching */
864 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
866 /* Only filter on the lower 12-bits of the VLAN tag */
867 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
869 /* In order for the VLAN Hash Table filtering to be effective,
870 * the VLAN tag identifier in the VLAN Tag Register must not
871 * be zero. Set the VLAN tag identifier to "1" to enable the
872 * VLAN Hash Table filtering. This implies that a VLAN tag of
873 * 1 will always pass filtering.
875 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
877 return 0;
880 static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
882 /* Disable VLAN filtering */
883 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
885 return 0;
888 static u32 xgbe_vid_crc32_le(__le16 vid_le)
890 u32 poly = 0xedb88320; /* CRCPOLY_LE */
891 u32 crc = ~0;
892 u32 temp = 0;
893 unsigned char *data = (unsigned char *)&vid_le;
894 unsigned char data_byte = 0;
895 int i, bits;
897 bits = get_bitmask_order(VLAN_VID_MASK);
898 for (i = 0; i < bits; i++) {
899 if ((i % 8) == 0)
900 data_byte = data[i / 8];
902 temp = ((crc & 1) ^ data_byte) & 1;
903 crc >>= 1;
904 data_byte >>= 1;
906 if (temp)
907 crc ^= poly;
910 return crc;
913 static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
915 u32 crc;
916 u16 vid;
917 __le16 vid_le;
918 u16 vlan_hash_table = 0;
920 /* Generate the VLAN Hash Table value */
921 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
922 /* Get the CRC32 value of the VLAN ID */
923 vid_le = cpu_to_le16(vid);
924 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
926 vlan_hash_table |= (1 << crc);
929 /* Set the VLAN Hash Table filtering register */
930 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
932 return 0;
935 static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
936 unsigned int enable)
938 unsigned int val = enable ? 1 : 0;
940 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
941 return 0;
943 netif_dbg(pdata, drv, pdata->netdev, "%s promiscuous mode\n",
944 enable ? "entering" : "leaving");
945 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
947 /* Hardware will still perform VLAN filtering in promiscuous mode */
948 if (enable) {
949 xgbe_disable_rx_vlan_filtering(pdata);
950 } else {
951 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
952 xgbe_enable_rx_vlan_filtering(pdata);
955 return 0;
958 static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
959 unsigned int enable)
961 unsigned int val = enable ? 1 : 0;
963 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
964 return 0;
966 netif_dbg(pdata, drv, pdata->netdev, "%s allmulti mode\n",
967 enable ? "entering" : "leaving");
968 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
970 return 0;
973 static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
974 struct netdev_hw_addr *ha, unsigned int *mac_reg)
976 unsigned int mac_addr_hi, mac_addr_lo;
977 u8 *mac_addr;
979 mac_addr_lo = 0;
980 mac_addr_hi = 0;
982 if (ha) {
983 mac_addr = (u8 *)&mac_addr_lo;
984 mac_addr[0] = ha->addr[0];
985 mac_addr[1] = ha->addr[1];
986 mac_addr[2] = ha->addr[2];
987 mac_addr[3] = ha->addr[3];
988 mac_addr = (u8 *)&mac_addr_hi;
989 mac_addr[0] = ha->addr[4];
990 mac_addr[1] = ha->addr[5];
992 netif_dbg(pdata, drv, pdata->netdev,
993 "adding mac address %pM at %#x\n",
994 ha->addr, *mac_reg);
996 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
999 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
1000 *mac_reg += MAC_MACA_INC;
1001 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
1002 *mac_reg += MAC_MACA_INC;
1005 static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
1007 struct net_device *netdev = pdata->netdev;
1008 struct netdev_hw_addr *ha;
1009 unsigned int mac_reg;
1010 unsigned int addn_macs;
1012 mac_reg = MAC_MACA1HR;
1013 addn_macs = pdata->hw_feat.addn_mac;
1015 if (netdev_uc_count(netdev) > addn_macs) {
1016 xgbe_set_promiscuous_mode(pdata, 1);
1017 } else {
1018 netdev_for_each_uc_addr(ha, netdev) {
1019 xgbe_set_mac_reg(pdata, ha, &mac_reg);
1020 addn_macs--;
1023 if (netdev_mc_count(netdev) > addn_macs) {
1024 xgbe_set_all_multicast_mode(pdata, 1);
1025 } else {
1026 netdev_for_each_mc_addr(ha, netdev) {
1027 xgbe_set_mac_reg(pdata, ha, &mac_reg);
1028 addn_macs--;
1033 /* Clear remaining additional MAC address entries */
1034 while (addn_macs--)
1035 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
1038 static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
1040 struct net_device *netdev = pdata->netdev;
1041 struct netdev_hw_addr *ha;
1042 unsigned int hash_reg;
1043 unsigned int hash_table_shift, hash_table_count;
1044 u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
1045 u32 crc;
1046 unsigned int i;
1048 hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
1049 hash_table_count = pdata->hw_feat.hash_table_size / 32;
1050 memset(hash_table, 0, sizeof(hash_table));
1052 /* Build the MAC Hash Table register values */
1053 netdev_for_each_uc_addr(ha, netdev) {
1054 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
1055 crc >>= hash_table_shift;
1056 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
1059 netdev_for_each_mc_addr(ha, netdev) {
1060 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
1061 crc >>= hash_table_shift;
1062 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
1065 /* Set the MAC Hash Table registers */
1066 hash_reg = MAC_HTR0;
1067 for (i = 0; i < hash_table_count; i++) {
1068 XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
1069 hash_reg += MAC_HTR_INC;
1073 static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
1075 if (pdata->hw_feat.hash_table_size)
1076 xgbe_set_mac_hash_table(pdata);
1077 else
1078 xgbe_set_mac_addn_addrs(pdata);
1080 return 0;
1083 static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
1085 unsigned int mac_addr_hi, mac_addr_lo;
1087 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
1088 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
1089 (addr[1] << 8) | (addr[0] << 0);
1091 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
1092 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
1094 return 0;
1097 static int xgbe_config_rx_mode(struct xgbe_prv_data *pdata)
1099 struct net_device *netdev = pdata->netdev;
1100 unsigned int pr_mode, am_mode;
1102 pr_mode = ((netdev->flags & IFF_PROMISC) != 0);
1103 am_mode = ((netdev->flags & IFF_ALLMULTI) != 0);
1105 xgbe_set_promiscuous_mode(pdata, pr_mode);
1106 xgbe_set_all_multicast_mode(pdata, am_mode);
1108 xgbe_add_mac_addresses(pdata);
1110 return 0;
1113 static int xgbe_clr_gpio(struct xgbe_prv_data *pdata, unsigned int gpio)
1115 unsigned int reg;
1117 if (gpio > 15)
1118 return -EINVAL;
1120 reg = XGMAC_IOREAD(pdata, MAC_GPIOSR);
1122 reg &= ~(1 << (gpio + 16));
1123 XGMAC_IOWRITE(pdata, MAC_GPIOSR, reg);
1125 return 0;
1128 static int xgbe_set_gpio(struct xgbe_prv_data *pdata, unsigned int gpio)
1130 unsigned int reg;
1132 if (gpio > 15)
1133 return -EINVAL;
1135 reg = XGMAC_IOREAD(pdata, MAC_GPIOSR);
1137 reg |= (1 << (gpio + 16));
1138 XGMAC_IOWRITE(pdata, MAC_GPIOSR, reg);
1140 return 0;
1143 static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,
1144 int mmd_reg)
1146 unsigned long flags;
1147 unsigned int mmd_address, index, offset;
1148 int mmd_data;
1150 if (mmd_reg & MII_ADDR_C45)
1151 mmd_address = mmd_reg & ~MII_ADDR_C45;
1152 else
1153 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1155 /* The PCS registers are accessed using mmio. The underlying
1156 * management interface uses indirect addressing to access the MMD
1157 * register sets. This requires accessing of the PCS register in two
1158 * phases, an address phase and a data phase.
1160 * The mmio interface is based on 16-bit offsets and values. All
1161 * register offsets must therefore be adjusted by left shifting the
1162 * offset 1 bit and reading 16 bits of data.
1164 mmd_address <<= 1;
1165 index = mmd_address & ~pdata->xpcs_window_mask;
1166 offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask);
1168 spin_lock_irqsave(&pdata->xpcs_lock, flags);
1169 XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index);
1170 mmd_data = XPCS16_IOREAD(pdata, offset);
1171 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
1173 return mmd_data;
1176 static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,
1177 int mmd_reg, int mmd_data)
1179 unsigned long flags;
1180 unsigned int mmd_address, index, offset;
1182 if (mmd_reg & MII_ADDR_C45)
1183 mmd_address = mmd_reg & ~MII_ADDR_C45;
1184 else
1185 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1187 /* The PCS registers are accessed using mmio. The underlying
1188 * management interface uses indirect addressing to access the MMD
1189 * register sets. This requires accessing of the PCS register in two
1190 * phases, an address phase and a data phase.
1192 * The mmio interface is based on 16-bit offsets and values. All
1193 * register offsets must therefore be adjusted by left shifting the
1194 * offset 1 bit and writing 16 bits of data.
1196 mmd_address <<= 1;
1197 index = mmd_address & ~pdata->xpcs_window_mask;
1198 offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask);
1200 spin_lock_irqsave(&pdata->xpcs_lock, flags);
1201 XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index);
1202 XPCS16_IOWRITE(pdata, offset, mmd_data);
1203 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
1206 static int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,
1207 int mmd_reg)
1209 unsigned long flags;
1210 unsigned int mmd_address;
1211 int mmd_data;
1213 if (mmd_reg & MII_ADDR_C45)
1214 mmd_address = mmd_reg & ~MII_ADDR_C45;
1215 else
1216 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1218 /* The PCS registers are accessed using mmio. The underlying APB3
1219 * management interface uses indirect addressing to access the MMD
1220 * register sets. This requires accessing of the PCS register in two
1221 * phases, an address phase and a data phase.
1223 * The mmio interface is based on 32-bit offsets and values. All
1224 * register offsets must therefore be adjusted by left shifting the
1225 * offset 2 bits and reading 32 bits of data.
1227 spin_lock_irqsave(&pdata->xpcs_lock, flags);
1228 XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8);
1229 mmd_data = XPCS32_IOREAD(pdata, (mmd_address & 0xff) << 2);
1230 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
1232 return mmd_data;
1235 static void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,
1236 int mmd_reg, int mmd_data)
1238 unsigned int mmd_address;
1239 unsigned long flags;
1241 if (mmd_reg & MII_ADDR_C45)
1242 mmd_address = mmd_reg & ~MII_ADDR_C45;
1243 else
1244 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1246 /* The PCS registers are accessed using mmio. The underlying APB3
1247 * management interface uses indirect addressing to access the MMD
1248 * register sets. This requires accessing of the PCS register in two
1249 * phases, an address phase and a data phase.
1251 * The mmio interface is based on 32-bit offsets and values. All
1252 * register offsets must therefore be adjusted by left shifting the
1253 * offset 2 bits and writing 32 bits of data.
1255 spin_lock_irqsave(&pdata->xpcs_lock, flags);
1256 XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8);
1257 XPCS32_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
1258 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
1261 static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
1262 int mmd_reg)
1264 switch (pdata->vdata->xpcs_access) {
1265 case XGBE_XPCS_ACCESS_V1:
1266 return xgbe_read_mmd_regs_v1(pdata, prtad, mmd_reg);
1268 case XGBE_XPCS_ACCESS_V2:
1269 default:
1270 return xgbe_read_mmd_regs_v2(pdata, prtad, mmd_reg);
1274 static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
1275 int mmd_reg, int mmd_data)
1277 switch (pdata->vdata->xpcs_access) {
1278 case XGBE_XPCS_ACCESS_V1:
1279 return xgbe_write_mmd_regs_v1(pdata, prtad, mmd_reg, mmd_data);
1281 case XGBE_XPCS_ACCESS_V2:
1282 default:
1283 return xgbe_write_mmd_regs_v2(pdata, prtad, mmd_reg, mmd_data);
1287 static int xgbe_write_ext_mii_regs(struct xgbe_prv_data *pdata, int addr,
1288 int reg, u16 val)
1290 unsigned int mdio_sca, mdio_sccd;
1292 reinit_completion(&pdata->mdio_complete);
1294 mdio_sca = 0;
1295 XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, REG, reg);
1296 XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, DA, addr);
1297 XGMAC_IOWRITE(pdata, MAC_MDIOSCAR, mdio_sca);
1299 mdio_sccd = 0;
1300 XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, DATA, val);
1301 XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, CMD, 1);
1302 XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, BUSY, 1);
1303 XGMAC_IOWRITE(pdata, MAC_MDIOSCCDR, mdio_sccd);
1305 if (!wait_for_completion_timeout(&pdata->mdio_complete, HZ)) {
1306 netdev_err(pdata->netdev, "mdio write operation timed out\n");
1307 return -ETIMEDOUT;
1310 return 0;
1313 static int xgbe_read_ext_mii_regs(struct xgbe_prv_data *pdata, int addr,
1314 int reg)
1316 unsigned int mdio_sca, mdio_sccd;
1318 reinit_completion(&pdata->mdio_complete);
1320 mdio_sca = 0;
1321 XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, REG, reg);
1322 XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, DA, addr);
1323 XGMAC_IOWRITE(pdata, MAC_MDIOSCAR, mdio_sca);
1325 mdio_sccd = 0;
1326 XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, CMD, 3);
1327 XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, BUSY, 1);
1328 XGMAC_IOWRITE(pdata, MAC_MDIOSCCDR, mdio_sccd);
1330 if (!wait_for_completion_timeout(&pdata->mdio_complete, HZ)) {
1331 netdev_err(pdata->netdev, "mdio read operation timed out\n");
1332 return -ETIMEDOUT;
1335 return XGMAC_IOREAD_BITS(pdata, MAC_MDIOSCCDR, DATA);
1338 static int xgbe_set_ext_mii_mode(struct xgbe_prv_data *pdata, unsigned int port,
1339 enum xgbe_mdio_mode mode)
1341 unsigned int reg_val = XGMAC_IOREAD(pdata, MAC_MDIOCL22R);
1343 switch (mode) {
1344 case XGBE_MDIO_MODE_CL22:
1345 if (port > XGMAC_MAX_C22_PORT)
1346 return -EINVAL;
1347 reg_val |= (1 << port);
1348 break;
1349 case XGBE_MDIO_MODE_CL45:
1350 break;
1351 default:
1352 return -EINVAL;
1355 XGMAC_IOWRITE(pdata, MAC_MDIOCL22R, reg_val);
1357 return 0;
1360 static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
1362 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
1365 static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
1367 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
1369 return 0;
1372 static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
1374 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
1376 return 0;
1379 static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
1381 struct xgbe_ring_desc *rdesc = rdata->rdesc;
1383 /* Reset the Tx descriptor
1384 * Set buffer 1 (lo) address to zero
1385 * Set buffer 1 (hi) address to zero
1386 * Reset all other control bits (IC, TTSE, B2L & B1L)
1387 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
1389 rdesc->desc0 = 0;
1390 rdesc->desc1 = 0;
1391 rdesc->desc2 = 0;
1392 rdesc->desc3 = 0;
1394 /* Make sure ownership is written to the descriptor */
1395 dma_wmb();
1398 static void xgbe_tx_desc_init(struct xgbe_channel *channel)
1400 struct xgbe_ring *ring = channel->tx_ring;
1401 struct xgbe_ring_data *rdata;
1402 int i;
1403 int start_index = ring->cur;
1405 DBGPR("-->tx_desc_init\n");
1407 /* Initialze all descriptors */
1408 for (i = 0; i < ring->rdesc_count; i++) {
1409 rdata = XGBE_GET_DESC_DATA(ring, i);
1411 /* Initialize Tx descriptor */
1412 xgbe_tx_desc_reset(rdata);
1415 /* Update the total number of Tx descriptors */
1416 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
1418 /* Update the starting address of descriptor ring */
1419 rdata = XGBE_GET_DESC_DATA(ring, start_index);
1420 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
1421 upper_32_bits(rdata->rdesc_dma));
1422 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
1423 lower_32_bits(rdata->rdesc_dma));
1425 DBGPR("<--tx_desc_init\n");
1428 static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata,
1429 struct xgbe_ring_data *rdata, unsigned int index)
1431 struct xgbe_ring_desc *rdesc = rdata->rdesc;
1432 unsigned int rx_usecs = pdata->rx_usecs;
1433 unsigned int rx_frames = pdata->rx_frames;
1434 unsigned int inte;
1435 dma_addr_t hdr_dma, buf_dma;
1437 if (!rx_usecs && !rx_frames) {
1438 /* No coalescing, interrupt for every descriptor */
1439 inte = 1;
1440 } else {
1441 /* Set interrupt based on Rx frame coalescing setting */
1442 if (rx_frames && !((index + 1) % rx_frames))
1443 inte = 1;
1444 else
1445 inte = 0;
1448 /* Reset the Rx descriptor
1449 * Set buffer 1 (lo) address to header dma address (lo)
1450 * Set buffer 1 (hi) address to header dma address (hi)
1451 * Set buffer 2 (lo) address to buffer dma address (lo)
1452 * Set buffer 2 (hi) address to buffer dma address (hi) and
1453 * set control bits OWN and INTE
1455 hdr_dma = rdata->rx.hdr.dma_base + rdata->rx.hdr.dma_off;
1456 buf_dma = rdata->rx.buf.dma_base + rdata->rx.buf.dma_off;
1457 rdesc->desc0 = cpu_to_le32(lower_32_bits(hdr_dma));
1458 rdesc->desc1 = cpu_to_le32(upper_32_bits(hdr_dma));
1459 rdesc->desc2 = cpu_to_le32(lower_32_bits(buf_dma));
1460 rdesc->desc3 = cpu_to_le32(upper_32_bits(buf_dma));
1462 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte);
1464 /* Since the Rx DMA engine is likely running, make sure everything
1465 * is written to the descriptor(s) before setting the OWN bit
1466 * for the descriptor
1468 dma_wmb();
1470 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
1472 /* Make sure ownership is written to the descriptor */
1473 dma_wmb();
1476 static void xgbe_rx_desc_init(struct xgbe_channel *channel)
1478 struct xgbe_prv_data *pdata = channel->pdata;
1479 struct xgbe_ring *ring = channel->rx_ring;
1480 struct xgbe_ring_data *rdata;
1481 unsigned int start_index = ring->cur;
1482 unsigned int i;
1484 DBGPR("-->rx_desc_init\n");
1486 /* Initialize all descriptors */
1487 for (i = 0; i < ring->rdesc_count; i++) {
1488 rdata = XGBE_GET_DESC_DATA(ring, i);
1490 /* Initialize Rx descriptor */
1491 xgbe_rx_desc_reset(pdata, rdata, i);
1494 /* Update the total number of Rx descriptors */
1495 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
1497 /* Update the starting address of descriptor ring */
1498 rdata = XGBE_GET_DESC_DATA(ring, start_index);
1499 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
1500 upper_32_bits(rdata->rdesc_dma));
1501 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
1502 lower_32_bits(rdata->rdesc_dma));
1504 /* Update the Rx Descriptor Tail Pointer */
1505 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
1506 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
1507 lower_32_bits(rdata->rdesc_dma));
1509 DBGPR("<--rx_desc_init\n");
1512 static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
1513 unsigned int addend)
1515 unsigned int count = 10000;
1517 /* Set the addend register value and tell the device */
1518 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1519 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1521 /* Wait for addend update to complete */
1522 while (--count && XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1523 udelay(5);
1525 if (!count)
1526 netdev_err(pdata->netdev,
1527 "timed out updating timestamp addend register\n");
1530 static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1531 unsigned int nsec)
1533 unsigned int count = 10000;
1535 /* Set the time values and tell the device */
1536 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1537 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1538 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1540 /* Wait for time update to complete */
1541 while (--count && XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1542 udelay(5);
1544 if (!count)
1545 netdev_err(pdata->netdev, "timed out initializing timestamp\n");
1548 static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1550 u64 nsec;
1552 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1553 nsec *= NSEC_PER_SEC;
1554 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1556 return nsec;
1559 static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1561 unsigned int tx_snr, tx_ssr;
1562 u64 nsec;
1564 if (pdata->vdata->tx_tstamp_workaround) {
1565 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1566 tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR);
1567 } else {
1568 tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR);
1569 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1572 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1573 return 0;
1575 nsec = tx_ssr;
1576 nsec *= NSEC_PER_SEC;
1577 nsec += tx_snr;
1579 return nsec;
1582 static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1583 struct xgbe_ring_desc *rdesc)
1585 u64 nsec;
1587 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1588 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1589 nsec = le32_to_cpu(rdesc->desc1);
1590 nsec <<= 32;
1591 nsec |= le32_to_cpu(rdesc->desc0);
1592 if (nsec != 0xffffffffffffffffULL) {
1593 packet->rx_tstamp = nsec;
1594 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1595 RX_TSTAMP, 1);
1600 static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1601 unsigned int mac_tscr)
1603 /* Set one nano-second accuracy */
1604 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1606 /* Set fine timestamp update */
1607 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1609 /* Overwrite earlier timestamps */
1610 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1612 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1614 /* Exit if timestamping is not enabled */
1615 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1616 return 0;
1618 /* Initialize time registers */
1619 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1620 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1621 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1622 xgbe_set_tstamp_time(pdata, 0, 0);
1624 /* Initialize the timecounter */
1625 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1626 ktime_to_ns(ktime_get_real()));
1628 return 0;
1631 static void xgbe_tx_start_xmit(struct xgbe_channel *channel,
1632 struct xgbe_ring *ring)
1634 struct xgbe_prv_data *pdata = channel->pdata;
1635 struct xgbe_ring_data *rdata;
1637 /* Make sure everything is written before the register write */
1638 wmb();
1640 /* Issue a poll command to Tx DMA by writing address
1641 * of next immediate free descriptor */
1642 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1643 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1644 lower_32_bits(rdata->rdesc_dma));
1646 /* Start the Tx timer */
1647 if (pdata->tx_usecs && !channel->tx_timer_active) {
1648 channel->tx_timer_active = 1;
1649 mod_timer(&channel->tx_timer,
1650 jiffies + usecs_to_jiffies(pdata->tx_usecs));
1653 ring->tx.xmit_more = 0;
1656 static void xgbe_dev_xmit(struct xgbe_channel *channel)
1658 struct xgbe_prv_data *pdata = channel->pdata;
1659 struct xgbe_ring *ring = channel->tx_ring;
1660 struct xgbe_ring_data *rdata;
1661 struct xgbe_ring_desc *rdesc;
1662 struct xgbe_packet_data *packet = &ring->packet_data;
1663 unsigned int tx_packets, tx_bytes;
1664 unsigned int csum, tso, vlan, vxlan;
1665 unsigned int tso_context, vlan_context;
1666 unsigned int tx_set_ic;
1667 int start_index = ring->cur;
1668 int cur_index = ring->cur;
1669 int i;
1671 DBGPR("-->xgbe_dev_xmit\n");
1673 tx_packets = packet->tx_packets;
1674 tx_bytes = packet->tx_bytes;
1676 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1677 CSUM_ENABLE);
1678 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1679 TSO_ENABLE);
1680 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1681 VLAN_CTAG);
1682 vxlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1683 VXLAN);
1685 if (tso && (packet->mss != ring->tx.cur_mss))
1686 tso_context = 1;
1687 else
1688 tso_context = 0;
1690 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1691 vlan_context = 1;
1692 else
1693 vlan_context = 0;
1695 /* Determine if an interrupt should be generated for this Tx:
1696 * Interrupt:
1697 * - Tx frame count exceeds the frame count setting
1698 * - Addition of Tx frame count to the frame count since the
1699 * last interrupt was set exceeds the frame count setting
1700 * No interrupt:
1701 * - No frame count setting specified (ethtool -C ethX tx-frames 0)
1702 * - Addition of Tx frame count to the frame count since the
1703 * last interrupt was set does not exceed the frame count setting
1705 ring->coalesce_count += tx_packets;
1706 if (!pdata->tx_frames)
1707 tx_set_ic = 0;
1708 else if (tx_packets > pdata->tx_frames)
1709 tx_set_ic = 1;
1710 else if ((ring->coalesce_count % pdata->tx_frames) < tx_packets)
1711 tx_set_ic = 1;
1712 else
1713 tx_set_ic = 0;
1715 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
1716 rdesc = rdata->rdesc;
1718 /* Create a context descriptor if this is a TSO packet */
1719 if (tso_context || vlan_context) {
1720 if (tso_context) {
1721 netif_dbg(pdata, tx_queued, pdata->netdev,
1722 "TSO context descriptor, mss=%u\n",
1723 packet->mss);
1725 /* Set the MSS size */
1726 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1727 MSS, packet->mss);
1729 /* Mark it as a CONTEXT descriptor */
1730 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1731 CTXT, 1);
1733 /* Indicate this descriptor contains the MSS */
1734 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1735 TCMSSV, 1);
1737 ring->tx.cur_mss = packet->mss;
1740 if (vlan_context) {
1741 netif_dbg(pdata, tx_queued, pdata->netdev,
1742 "VLAN context descriptor, ctag=%u\n",
1743 packet->vlan_ctag);
1745 /* Mark it as a CONTEXT descriptor */
1746 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1747 CTXT, 1);
1749 /* Set the VLAN tag */
1750 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1751 VT, packet->vlan_ctag);
1753 /* Indicate this descriptor contains the VLAN tag */
1754 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1755 VLTV, 1);
1757 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1760 cur_index++;
1761 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
1762 rdesc = rdata->rdesc;
1765 /* Update buffer address (for TSO this is the header) */
1766 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1767 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1769 /* Update the buffer length */
1770 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1771 rdata->skb_dma_len);
1773 /* VLAN tag insertion check */
1774 if (vlan)
1775 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1776 TX_NORMAL_DESC2_VLAN_INSERT);
1778 /* Timestamp enablement check */
1779 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1780 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1782 /* Mark it as First Descriptor */
1783 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1785 /* Mark it as a NORMAL descriptor */
1786 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1788 /* Set OWN bit if not the first descriptor */
1789 if (cur_index != start_index)
1790 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1792 if (tso) {
1793 /* Enable TSO */
1794 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1795 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1796 packet->tcp_payload_len);
1797 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1798 packet->tcp_header_len / 4);
1800 pdata->ext_stats.tx_tso_packets += tx_packets;
1801 } else {
1802 /* Enable CRC and Pad Insertion */
1803 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1805 /* Enable HW CSUM */
1806 if (csum)
1807 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1808 CIC, 0x3);
1810 /* Set the total length to be transmitted */
1811 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1812 packet->length);
1815 if (vxlan) {
1816 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, VNP,
1817 TX_NORMAL_DESC3_VXLAN_PACKET);
1819 pdata->ext_stats.tx_vxlan_packets += packet->tx_packets;
1822 for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) {
1823 cur_index++;
1824 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
1825 rdesc = rdata->rdesc;
1827 /* Update buffer address */
1828 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1829 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1831 /* Update the buffer length */
1832 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1833 rdata->skb_dma_len);
1835 /* Set OWN bit */
1836 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1838 /* Mark it as NORMAL descriptor */
1839 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1841 /* Enable HW CSUM */
1842 if (csum)
1843 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1844 CIC, 0x3);
1847 /* Set LAST bit for the last descriptor */
1848 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1850 /* Set IC bit based on Tx coalescing settings */
1851 if (tx_set_ic)
1852 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1854 /* Save the Tx info to report back during cleanup */
1855 rdata->tx.packets = tx_packets;
1856 rdata->tx.bytes = tx_bytes;
1858 pdata->ext_stats.txq_packets[channel->queue_index] += tx_packets;
1859 pdata->ext_stats.txq_bytes[channel->queue_index] += tx_bytes;
1861 /* In case the Tx DMA engine is running, make sure everything
1862 * is written to the descriptor(s) before setting the OWN bit
1863 * for the first descriptor
1865 dma_wmb();
1867 /* Set OWN bit for the first descriptor */
1868 rdata = XGBE_GET_DESC_DATA(ring, start_index);
1869 rdesc = rdata->rdesc;
1870 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1872 if (netif_msg_tx_queued(pdata))
1873 xgbe_dump_tx_desc(pdata, ring, start_index,
1874 packet->rdesc_count, 1);
1876 /* Make sure ownership is written to the descriptor */
1877 smp_wmb();
1879 ring->cur = cur_index + 1;
1880 if (!packet->skb->xmit_more ||
1881 netif_xmit_stopped(netdev_get_tx_queue(pdata->netdev,
1882 channel->queue_index)))
1883 xgbe_tx_start_xmit(channel, ring);
1884 else
1885 ring->tx.xmit_more = 1;
1887 DBGPR(" %s: descriptors %u to %u written\n",
1888 channel->name, start_index & (ring->rdesc_count - 1),
1889 (ring->cur - 1) & (ring->rdesc_count - 1));
1891 DBGPR("<--xgbe_dev_xmit\n");
1894 static int xgbe_dev_read(struct xgbe_channel *channel)
1896 struct xgbe_prv_data *pdata = channel->pdata;
1897 struct xgbe_ring *ring = channel->rx_ring;
1898 struct xgbe_ring_data *rdata;
1899 struct xgbe_ring_desc *rdesc;
1900 struct xgbe_packet_data *packet = &ring->packet_data;
1901 struct net_device *netdev = pdata->netdev;
1902 unsigned int err, etlt, l34t;
1904 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1906 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1907 rdesc = rdata->rdesc;
1909 /* Check for data availability */
1910 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1911 return 1;
1913 /* Make sure descriptor fields are read after reading the OWN bit */
1914 dma_rmb();
1916 if (netif_msg_rx_status(pdata))
1917 xgbe_dump_rx_desc(pdata, ring, ring->cur);
1919 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1920 /* Timestamp Context Descriptor */
1921 xgbe_get_rx_tstamp(packet, rdesc);
1923 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1924 CONTEXT, 1);
1925 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1926 CONTEXT_NEXT, 0);
1927 return 0;
1930 /* Normal Descriptor, be sure Context Descriptor bit is off */
1931 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1933 /* Indicate if a Context Descriptor is next */
1934 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1935 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1936 CONTEXT_NEXT, 1);
1938 /* Get the header length */
1939 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD)) {
1940 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1941 FIRST, 1);
1942 rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2,
1943 RX_NORMAL_DESC2, HL);
1944 if (rdata->rx.hdr_len)
1945 pdata->ext_stats.rx_split_header_packets++;
1946 } else {
1947 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1948 FIRST, 0);
1951 /* Get the RSS hash */
1952 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, RSV)) {
1953 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1954 RSS_HASH, 1);
1956 packet->rss_hash = le32_to_cpu(rdesc->desc1);
1958 l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T);
1959 switch (l34t) {
1960 case RX_DESC3_L34T_IPV4_TCP:
1961 case RX_DESC3_L34T_IPV4_UDP:
1962 case RX_DESC3_L34T_IPV6_TCP:
1963 case RX_DESC3_L34T_IPV6_UDP:
1964 packet->rss_hash_type = PKT_HASH_TYPE_L4;
1965 break;
1966 default:
1967 packet->rss_hash_type = PKT_HASH_TYPE_L3;
1971 /* Not all the data has been transferred for this packet */
1972 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD))
1973 return 0;
1975 /* This is the last of the data for this packet */
1976 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1977 LAST, 1);
1979 /* Get the packet length */
1980 rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
1982 /* Set checksum done indicator as appropriate */
1983 if (netdev->features & NETIF_F_RXCSUM) {
1984 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1985 CSUM_DONE, 1);
1986 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1987 TNPCSUM_DONE, 1);
1990 /* Set the tunneled packet indicator */
1991 if (XGMAC_GET_BITS_LE(rdesc->desc2, RX_NORMAL_DESC2, TNP)) {
1992 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1993 TNP, 1);
1994 pdata->ext_stats.rx_vxlan_packets++;
1996 l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T);
1997 switch (l34t) {
1998 case RX_DESC3_L34T_IPV4_UNKNOWN:
1999 case RX_DESC3_L34T_IPV6_UNKNOWN:
2000 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
2001 TNPCSUM_DONE, 0);
2002 break;
2006 /* Check for errors (only valid in last descriptor) */
2007 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
2008 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
2009 netif_dbg(pdata, rx_status, netdev, "err=%u, etlt=%#x\n", err, etlt);
2011 if (!err || !etlt) {
2012 /* No error if err is 0 or etlt is 0 */
2013 if ((etlt == 0x09) &&
2014 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
2015 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
2016 VLAN_CTAG, 1);
2017 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
2018 RX_NORMAL_DESC0,
2019 OVT);
2020 netif_dbg(pdata, rx_status, netdev, "vlan-ctag=%#06x\n",
2021 packet->vlan_ctag);
2023 } else {
2024 unsigned int tnp = XGMAC_GET_BITS(packet->attributes,
2025 RX_PACKET_ATTRIBUTES, TNP);
2027 if ((etlt == 0x05) || (etlt == 0x06)) {
2028 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
2029 CSUM_DONE, 0);
2030 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
2031 TNPCSUM_DONE, 0);
2032 pdata->ext_stats.rx_csum_errors++;
2033 } else if (tnp && ((etlt == 0x09) || (etlt == 0x0a))) {
2034 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
2035 CSUM_DONE, 0);
2036 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
2037 TNPCSUM_DONE, 0);
2038 pdata->ext_stats.rx_vxlan_csum_errors++;
2039 } else {
2040 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
2041 FRAME, 1);
2045 pdata->ext_stats.rxq_packets[channel->queue_index]++;
2046 pdata->ext_stats.rxq_bytes[channel->queue_index] += rdata->rx.len;
2048 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
2049 ring->cur & (ring->rdesc_count - 1), ring->cur);
2051 return 0;
2054 static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
2056 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
2057 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
2060 static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
2062 /* Rx and Tx share LD bit, so check TDES3.LD bit */
2063 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
2066 static int xgbe_enable_int(struct xgbe_channel *channel,
2067 enum xgbe_int int_id)
2069 switch (int_id) {
2070 case XGMAC_INT_DMA_CH_SR_TI:
2071 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 1);
2072 break;
2073 case XGMAC_INT_DMA_CH_SR_TPS:
2074 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TXSE, 1);
2075 break;
2076 case XGMAC_INT_DMA_CH_SR_TBU:
2077 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TBUE, 1);
2078 break;
2079 case XGMAC_INT_DMA_CH_SR_RI:
2080 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 1);
2081 break;
2082 case XGMAC_INT_DMA_CH_SR_RBU:
2083 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RBUE, 1);
2084 break;
2085 case XGMAC_INT_DMA_CH_SR_RPS:
2086 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RSE, 1);
2087 break;
2088 case XGMAC_INT_DMA_CH_SR_TI_RI:
2089 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 1);
2090 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 1);
2091 break;
2092 case XGMAC_INT_DMA_CH_SR_FBE:
2093 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, FBEE, 1);
2094 break;
2095 case XGMAC_INT_DMA_ALL:
2096 channel->curr_ier |= channel->saved_ier;
2097 break;
2098 default:
2099 return -1;
2102 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, channel->curr_ier);
2104 return 0;
2107 static int xgbe_disable_int(struct xgbe_channel *channel,
2108 enum xgbe_int int_id)
2110 switch (int_id) {
2111 case XGMAC_INT_DMA_CH_SR_TI:
2112 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 0);
2113 break;
2114 case XGMAC_INT_DMA_CH_SR_TPS:
2115 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TXSE, 0);
2116 break;
2117 case XGMAC_INT_DMA_CH_SR_TBU:
2118 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TBUE, 0);
2119 break;
2120 case XGMAC_INT_DMA_CH_SR_RI:
2121 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 0);
2122 break;
2123 case XGMAC_INT_DMA_CH_SR_RBU:
2124 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RBUE, 0);
2125 break;
2126 case XGMAC_INT_DMA_CH_SR_RPS:
2127 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RSE, 0);
2128 break;
2129 case XGMAC_INT_DMA_CH_SR_TI_RI:
2130 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 0);
2131 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 0);
2132 break;
2133 case XGMAC_INT_DMA_CH_SR_FBE:
2134 XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, FBEE, 0);
2135 break;
2136 case XGMAC_INT_DMA_ALL:
2137 channel->saved_ier = channel->curr_ier;
2138 channel->curr_ier = 0;
2139 break;
2140 default:
2141 return -1;
2144 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, channel->curr_ier);
2146 return 0;
2149 static int __xgbe_exit(struct xgbe_prv_data *pdata)
2151 unsigned int count = 2000;
2153 DBGPR("-->xgbe_exit\n");
2155 /* Issue a software reset */
2156 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
2157 usleep_range(10, 15);
2159 /* Poll Until Poll Condition */
2160 while (--count && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
2161 usleep_range(500, 600);
2163 if (!count)
2164 return -EBUSY;
2166 DBGPR("<--xgbe_exit\n");
2168 return 0;
2171 static int xgbe_exit(struct xgbe_prv_data *pdata)
2173 int ret;
2175 /* To guard against possible incorrectly generated interrupts,
2176 * issue the software reset twice.
2178 ret = __xgbe_exit(pdata);
2179 if (ret)
2180 return ret;
2182 return __xgbe_exit(pdata);
2185 static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
2187 unsigned int i, count;
2189 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
2190 return 0;
2192 for (i = 0; i < pdata->tx_q_count; i++)
2193 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
2195 /* Poll Until Poll Condition */
2196 for (i = 0; i < pdata->tx_q_count; i++) {
2197 count = 2000;
2198 while (--count && XGMAC_MTL_IOREAD_BITS(pdata, i,
2199 MTL_Q_TQOMR, FTQ))
2200 usleep_range(500, 600);
2202 if (!count)
2203 return -EBUSY;
2206 return 0;
2209 static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
2211 unsigned int sbmr;
2213 sbmr = XGMAC_IOREAD(pdata, DMA_SBMR);
2215 /* Set enhanced addressing mode */
2216 XGMAC_SET_BITS(sbmr, DMA_SBMR, EAME, 1);
2218 /* Set the System Bus mode */
2219 XGMAC_SET_BITS(sbmr, DMA_SBMR, UNDEF, 1);
2220 XGMAC_SET_BITS(sbmr, DMA_SBMR, BLEN, pdata->blen >> 2);
2221 XGMAC_SET_BITS(sbmr, DMA_SBMR, AAL, pdata->aal);
2222 XGMAC_SET_BITS(sbmr, DMA_SBMR, RD_OSR_LMT, pdata->rd_osr_limit - 1);
2223 XGMAC_SET_BITS(sbmr, DMA_SBMR, WR_OSR_LMT, pdata->wr_osr_limit - 1);
2225 XGMAC_IOWRITE(pdata, DMA_SBMR, sbmr);
2227 /* Set descriptor fetching threshold */
2228 if (pdata->vdata->tx_desc_prefetch)
2229 XGMAC_IOWRITE_BITS(pdata, DMA_TXEDMACR, TDPS,
2230 pdata->vdata->tx_desc_prefetch);
2232 if (pdata->vdata->rx_desc_prefetch)
2233 XGMAC_IOWRITE_BITS(pdata, DMA_RXEDMACR, RDPS,
2234 pdata->vdata->rx_desc_prefetch);
2237 static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
2239 XGMAC_IOWRITE(pdata, DMA_AXIARCR, pdata->arcr);
2240 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, pdata->awcr);
2241 if (pdata->awarcr)
2242 XGMAC_IOWRITE(pdata, DMA_AXIAWARCR, pdata->awarcr);
2245 static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
2247 unsigned int i;
2249 /* Set Tx to weighted round robin scheduling algorithm */
2250 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
2252 /* Set Tx traffic classes to use WRR algorithm with equal weights */
2253 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
2254 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
2255 MTL_TSA_ETS);
2256 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
2259 /* Set Rx to strict priority algorithm */
2260 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
2263 static void xgbe_queue_flow_control_threshold(struct xgbe_prv_data *pdata,
2264 unsigned int queue,
2265 unsigned int q_fifo_size)
2267 unsigned int frame_fifo_size;
2268 unsigned int rfa, rfd;
2270 frame_fifo_size = XGMAC_FLOW_CONTROL_ALIGN(xgbe_get_max_frame(pdata));
2272 if (pdata->pfcq[queue] && (q_fifo_size > pdata->pfc_rfa)) {
2273 /* PFC is active for this queue */
2274 rfa = pdata->pfc_rfa;
2275 rfd = rfa + frame_fifo_size;
2276 if (rfd > XGMAC_FLOW_CONTROL_MAX)
2277 rfd = XGMAC_FLOW_CONTROL_MAX;
2278 if (rfa >= XGMAC_FLOW_CONTROL_MAX)
2279 rfa = XGMAC_FLOW_CONTROL_MAX - XGMAC_FLOW_CONTROL_UNIT;
2280 } else {
2281 /* This path deals with just maximum frame sizes which are
2282 * limited to a jumbo frame of 9,000 (plus headers, etc.)
2283 * so we can never exceed the maximum allowable RFA/RFD
2284 * values.
2286 if (q_fifo_size <= 2048) {
2287 /* rx_rfd to zero to signal no flow control */
2288 pdata->rx_rfa[queue] = 0;
2289 pdata->rx_rfd[queue] = 0;
2290 return;
2293 if (q_fifo_size <= 4096) {
2294 /* Between 2048 and 4096 */
2295 pdata->rx_rfa[queue] = 0; /* Full - 1024 bytes */
2296 pdata->rx_rfd[queue] = 1; /* Full - 1536 bytes */
2297 return;
2300 if (q_fifo_size <= frame_fifo_size) {
2301 /* Between 4096 and max-frame */
2302 pdata->rx_rfa[queue] = 2; /* Full - 2048 bytes */
2303 pdata->rx_rfd[queue] = 5; /* Full - 3584 bytes */
2304 return;
2307 if (q_fifo_size <= (frame_fifo_size * 3)) {
2308 /* Between max-frame and 3 max-frames,
2309 * trigger if we get just over a frame of data and
2310 * resume when we have just under half a frame left.
2312 rfa = q_fifo_size - frame_fifo_size;
2313 rfd = rfa + (frame_fifo_size / 2);
2314 } else {
2315 /* Above 3 max-frames - trigger when just over
2316 * 2 frames of space available
2318 rfa = frame_fifo_size * 2;
2319 rfa += XGMAC_FLOW_CONTROL_UNIT;
2320 rfd = rfa + frame_fifo_size;
2324 pdata->rx_rfa[queue] = XGMAC_FLOW_CONTROL_VALUE(rfa);
2325 pdata->rx_rfd[queue] = XGMAC_FLOW_CONTROL_VALUE(rfd);
2328 static void xgbe_calculate_flow_control_threshold(struct xgbe_prv_data *pdata,
2329 unsigned int *fifo)
2331 unsigned int q_fifo_size;
2332 unsigned int i;
2334 for (i = 0; i < pdata->rx_q_count; i++) {
2335 q_fifo_size = (fifo[i] + 1) * XGMAC_FIFO_UNIT;
2337 xgbe_queue_flow_control_threshold(pdata, i, q_fifo_size);
2341 static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
2343 unsigned int i;
2345 for (i = 0; i < pdata->rx_q_count; i++) {
2346 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFA,
2347 pdata->rx_rfa[i]);
2348 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFD,
2349 pdata->rx_rfd[i]);
2353 static unsigned int xgbe_get_tx_fifo_size(struct xgbe_prv_data *pdata)
2355 /* The configured value may not be the actual amount of fifo RAM */
2356 return min_t(unsigned int, pdata->tx_max_fifo_size,
2357 pdata->hw_feat.tx_fifo_size);
2360 static unsigned int xgbe_get_rx_fifo_size(struct xgbe_prv_data *pdata)
2362 /* The configured value may not be the actual amount of fifo RAM */
2363 return min_t(unsigned int, pdata->rx_max_fifo_size,
2364 pdata->hw_feat.rx_fifo_size);
2367 static void xgbe_calculate_equal_fifo(unsigned int fifo_size,
2368 unsigned int queue_count,
2369 unsigned int *fifo)
2371 unsigned int q_fifo_size;
2372 unsigned int p_fifo;
2373 unsigned int i;
2375 q_fifo_size = fifo_size / queue_count;
2377 /* Calculate the fifo setting by dividing the queue's fifo size
2378 * by the fifo allocation increment (with 0 representing the
2379 * base allocation increment so decrement the result by 1).
2381 p_fifo = q_fifo_size / XGMAC_FIFO_UNIT;
2382 if (p_fifo)
2383 p_fifo--;
2385 /* Distribute the fifo equally amongst the queues */
2386 for (i = 0; i < queue_count; i++)
2387 fifo[i] = p_fifo;
2390 static unsigned int xgbe_set_nonprio_fifos(unsigned int fifo_size,
2391 unsigned int queue_count,
2392 unsigned int *fifo)
2394 unsigned int i;
2396 BUILD_BUG_ON_NOT_POWER_OF_2(XGMAC_FIFO_MIN_ALLOC);
2398 if (queue_count <= IEEE_8021QAZ_MAX_TCS)
2399 return fifo_size;
2401 /* Rx queues 9 and up are for specialized packets,
2402 * such as PTP or DCB control packets, etc. and
2403 * don't require a large fifo
2405 for (i = IEEE_8021QAZ_MAX_TCS; i < queue_count; i++) {
2406 fifo[i] = (XGMAC_FIFO_MIN_ALLOC / XGMAC_FIFO_UNIT) - 1;
2407 fifo_size -= XGMAC_FIFO_MIN_ALLOC;
2410 return fifo_size;
2413 static unsigned int xgbe_get_pfc_delay(struct xgbe_prv_data *pdata)
2415 unsigned int delay;
2417 /* If a delay has been provided, use that */
2418 if (pdata->pfc->delay)
2419 return pdata->pfc->delay / 8;
2421 /* Allow for two maximum size frames */
2422 delay = xgbe_get_max_frame(pdata);
2423 delay += XGMAC_ETH_PREAMBLE;
2424 delay *= 2;
2426 /* Allow for PFC frame */
2427 delay += XGMAC_PFC_DATA_LEN;
2428 delay += ETH_HLEN + ETH_FCS_LEN;
2429 delay += XGMAC_ETH_PREAMBLE;
2431 /* Allow for miscellaneous delays (LPI exit, cable, etc.) */
2432 delay += XGMAC_PFC_DELAYS;
2434 return delay;
2437 static unsigned int xgbe_get_pfc_queues(struct xgbe_prv_data *pdata)
2439 unsigned int count, prio_queues;
2440 unsigned int i;
2442 if (!pdata->pfc->pfc_en)
2443 return 0;
2445 count = 0;
2446 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2447 for (i = 0; i < prio_queues; i++) {
2448 if (!xgbe_is_pfc_queue(pdata, i))
2449 continue;
2451 pdata->pfcq[i] = 1;
2452 count++;
2455 return count;
2458 static void xgbe_calculate_dcb_fifo(struct xgbe_prv_data *pdata,
2459 unsigned int fifo_size,
2460 unsigned int *fifo)
2462 unsigned int q_fifo_size, rem_fifo, addn_fifo;
2463 unsigned int prio_queues;
2464 unsigned int pfc_count;
2465 unsigned int i;
2467 q_fifo_size = XGMAC_FIFO_ALIGN(xgbe_get_max_frame(pdata));
2468 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2469 pfc_count = xgbe_get_pfc_queues(pdata);
2471 if (!pfc_count || ((q_fifo_size * prio_queues) > fifo_size)) {
2472 /* No traffic classes with PFC enabled or can't do lossless */
2473 xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo);
2474 return;
2477 /* Calculate how much fifo we have to play with */
2478 rem_fifo = fifo_size - (q_fifo_size * prio_queues);
2480 /* Calculate how much more than base fifo PFC needs, which also
2481 * becomes the threshold activation point (RFA)
2483 pdata->pfc_rfa = xgbe_get_pfc_delay(pdata);
2484 pdata->pfc_rfa = XGMAC_FLOW_CONTROL_ALIGN(pdata->pfc_rfa);
2486 if (pdata->pfc_rfa > q_fifo_size) {
2487 addn_fifo = pdata->pfc_rfa - q_fifo_size;
2488 addn_fifo = XGMAC_FIFO_ALIGN(addn_fifo);
2489 } else {
2490 addn_fifo = 0;
2493 /* Calculate DCB fifo settings:
2494 * - distribute remaining fifo between the VLAN priority
2495 * queues based on traffic class PFC enablement and overall
2496 * priority (0 is lowest priority, so start at highest)
2498 i = prio_queues;
2499 while (i > 0) {
2500 i--;
2502 fifo[i] = (q_fifo_size / XGMAC_FIFO_UNIT) - 1;
2504 if (!pdata->pfcq[i] || !addn_fifo)
2505 continue;
2507 if (addn_fifo > rem_fifo) {
2508 netdev_warn(pdata->netdev,
2509 "RXq%u cannot set needed fifo size\n", i);
2510 if (!rem_fifo)
2511 continue;
2513 addn_fifo = rem_fifo;
2516 fifo[i] += (addn_fifo / XGMAC_FIFO_UNIT);
2517 rem_fifo -= addn_fifo;
2520 if (rem_fifo) {
2521 unsigned int inc_fifo = rem_fifo / prio_queues;
2523 /* Distribute remaining fifo across queues */
2524 for (i = 0; i < prio_queues; i++)
2525 fifo[i] += (inc_fifo / XGMAC_FIFO_UNIT);
2529 static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
2531 unsigned int fifo_size;
2532 unsigned int fifo[XGBE_MAX_QUEUES];
2533 unsigned int i;
2535 fifo_size = xgbe_get_tx_fifo_size(pdata);
2537 xgbe_calculate_equal_fifo(fifo_size, pdata->tx_q_count, fifo);
2539 for (i = 0; i < pdata->tx_q_count; i++)
2540 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo[i]);
2542 netif_info(pdata, drv, pdata->netdev,
2543 "%d Tx hardware queues, %d byte fifo per queue\n",
2544 pdata->tx_q_count, ((fifo[0] + 1) * XGMAC_FIFO_UNIT));
2547 static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
2549 unsigned int fifo_size;
2550 unsigned int fifo[XGBE_MAX_QUEUES];
2551 unsigned int prio_queues;
2552 unsigned int i;
2554 /* Clear any DCB related fifo/queue information */
2555 memset(pdata->pfcq, 0, sizeof(pdata->pfcq));
2556 pdata->pfc_rfa = 0;
2558 fifo_size = xgbe_get_rx_fifo_size(pdata);
2559 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2561 /* Assign a minimum fifo to the non-VLAN priority queues */
2562 fifo_size = xgbe_set_nonprio_fifos(fifo_size, pdata->rx_q_count, fifo);
2564 if (pdata->pfc && pdata->ets)
2565 xgbe_calculate_dcb_fifo(pdata, fifo_size, fifo);
2566 else
2567 xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo);
2569 for (i = 0; i < pdata->rx_q_count; i++)
2570 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo[i]);
2572 xgbe_calculate_flow_control_threshold(pdata, fifo);
2573 xgbe_config_flow_control_threshold(pdata);
2575 if (pdata->pfc && pdata->ets && pdata->pfc->pfc_en) {
2576 netif_info(pdata, drv, pdata->netdev,
2577 "%u Rx hardware queues\n", pdata->rx_q_count);
2578 for (i = 0; i < pdata->rx_q_count; i++)
2579 netif_info(pdata, drv, pdata->netdev,
2580 "RxQ%u, %u byte fifo queue\n", i,
2581 ((fifo[i] + 1) * XGMAC_FIFO_UNIT));
2582 } else {
2583 netif_info(pdata, drv, pdata->netdev,
2584 "%u Rx hardware queues, %u byte fifo per queue\n",
2585 pdata->rx_q_count,
2586 ((fifo[0] + 1) * XGMAC_FIFO_UNIT));
2590 static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
2592 unsigned int qptc, qptc_extra, queue;
2593 unsigned int prio_queues;
2594 unsigned int ppq, ppq_extra, prio;
2595 unsigned int mask;
2596 unsigned int i, j, reg, reg_val;
2598 /* Map the MTL Tx Queues to Traffic Classes
2599 * Note: Tx Queues >= Traffic Classes
2601 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
2602 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
2604 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
2605 for (j = 0; j < qptc; j++) {
2606 netif_dbg(pdata, drv, pdata->netdev,
2607 "TXq%u mapped to TC%u\n", queue, i);
2608 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2609 Q2TCMAP, i);
2610 pdata->q2tc_map[queue++] = i;
2613 if (i < qptc_extra) {
2614 netif_dbg(pdata, drv, pdata->netdev,
2615 "TXq%u mapped to TC%u\n", queue, i);
2616 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2617 Q2TCMAP, i);
2618 pdata->q2tc_map[queue++] = i;
2622 /* Map the 8 VLAN priority values to available MTL Rx queues */
2623 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2624 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
2625 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
2627 reg = MAC_RQC2R;
2628 reg_val = 0;
2629 for (i = 0, prio = 0; i < prio_queues;) {
2630 mask = 0;
2631 for (j = 0; j < ppq; j++) {
2632 netif_dbg(pdata, drv, pdata->netdev,
2633 "PRIO%u mapped to RXq%u\n", prio, i);
2634 mask |= (1 << prio);
2635 pdata->prio2q_map[prio++] = i;
2638 if (i < ppq_extra) {
2639 netif_dbg(pdata, drv, pdata->netdev,
2640 "PRIO%u mapped to RXq%u\n", prio, i);
2641 mask |= (1 << prio);
2642 pdata->prio2q_map[prio++] = i;
2645 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
2647 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
2648 continue;
2650 XGMAC_IOWRITE(pdata, reg, reg_val);
2651 reg += MAC_RQC2_INC;
2652 reg_val = 0;
2655 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
2656 reg = MTL_RQDCM0R;
2657 reg_val = 0;
2658 for (i = 0; i < pdata->rx_q_count;) {
2659 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
2661 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
2662 continue;
2664 XGMAC_IOWRITE(pdata, reg, reg_val);
2666 reg += MTL_RQDCM_INC;
2667 reg_val = 0;
2671 static void xgbe_config_tc(struct xgbe_prv_data *pdata)
2673 unsigned int offset, queue, prio;
2674 u8 i;
2676 netdev_reset_tc(pdata->netdev);
2677 if (!pdata->num_tcs)
2678 return;
2680 netdev_set_num_tc(pdata->netdev, pdata->num_tcs);
2682 for (i = 0, queue = 0, offset = 0; i < pdata->num_tcs; i++) {
2683 while ((queue < pdata->tx_q_count) &&
2684 (pdata->q2tc_map[queue] == i))
2685 queue++;
2687 netif_dbg(pdata, drv, pdata->netdev, "TC%u using TXq%u-%u\n",
2688 i, offset, queue - 1);
2689 netdev_set_tc_queue(pdata->netdev, i, queue - offset, offset);
2690 offset = queue;
2693 if (!pdata->ets)
2694 return;
2696 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++)
2697 netdev_set_prio_tc_map(pdata->netdev, prio,
2698 pdata->ets->prio_tc[prio]);
2701 static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
2703 struct ieee_ets *ets = pdata->ets;
2704 unsigned int total_weight, min_weight, weight;
2705 unsigned int mask, reg, reg_val;
2706 unsigned int i, prio;
2708 if (!ets)
2709 return;
2711 /* Set Tx to deficit weighted round robin scheduling algorithm (when
2712 * traffic class is using ETS algorithm)
2714 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
2716 /* Set Traffic Class algorithms */
2717 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
2718 min_weight = total_weight / 100;
2719 if (!min_weight)
2720 min_weight = 1;
2722 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
2723 /* Map the priorities to the traffic class */
2724 mask = 0;
2725 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
2726 if (ets->prio_tc[prio] == i)
2727 mask |= (1 << prio);
2729 mask &= 0xff;
2731 netif_dbg(pdata, drv, pdata->netdev, "TC%u PRIO mask=%#x\n",
2732 i, mask);
2733 reg = MTL_TCPM0R + (MTL_TCPM_INC * (i / MTL_TCPM_TC_PER_REG));
2734 reg_val = XGMAC_IOREAD(pdata, reg);
2736 reg_val &= ~(0xff << ((i % MTL_TCPM_TC_PER_REG) << 3));
2737 reg_val |= (mask << ((i % MTL_TCPM_TC_PER_REG) << 3));
2739 XGMAC_IOWRITE(pdata, reg, reg_val);
2741 /* Set the traffic class algorithm */
2742 switch (ets->tc_tsa[i]) {
2743 case IEEE_8021QAZ_TSA_STRICT:
2744 netif_dbg(pdata, drv, pdata->netdev,
2745 "TC%u using SP\n", i);
2746 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
2747 MTL_TSA_SP);
2748 break;
2749 case IEEE_8021QAZ_TSA_ETS:
2750 weight = total_weight * ets->tc_tx_bw[i] / 100;
2751 weight = clamp(weight, min_weight, total_weight);
2753 netif_dbg(pdata, drv, pdata->netdev,
2754 "TC%u using DWRR (weight %u)\n", i, weight);
2755 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
2756 MTL_TSA_ETS);
2757 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
2758 weight);
2759 break;
2763 xgbe_config_tc(pdata);
2766 static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
2768 if (!test_bit(XGBE_DOWN, &pdata->dev_state)) {
2769 /* Just stop the Tx queues while Rx fifo is changed */
2770 netif_tx_stop_all_queues(pdata->netdev);
2772 /* Suspend Rx so that fifo's can be adjusted */
2773 pdata->hw_if.disable_rx(pdata);
2776 xgbe_config_rx_fifo_size(pdata);
2777 xgbe_config_flow_control(pdata);
2779 if (!test_bit(XGBE_DOWN, &pdata->dev_state)) {
2780 /* Resume Rx */
2781 pdata->hw_if.enable_rx(pdata);
2783 /* Resume Tx queues */
2784 netif_tx_start_all_queues(pdata->netdev);
2788 static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
2790 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
2792 /* Filtering is done using perfect filtering and hash filtering */
2793 if (pdata->hw_feat.hash_table_size) {
2794 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
2795 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
2796 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
2800 static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
2802 unsigned int val;
2804 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
2806 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
2809 static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata)
2811 xgbe_set_speed(pdata, pdata->phy_speed);
2814 static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
2816 if (pdata->netdev->features & NETIF_F_RXCSUM)
2817 xgbe_enable_rx_csum(pdata);
2818 else
2819 xgbe_disable_rx_csum(pdata);
2822 static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
2824 /* Indicate that VLAN Tx CTAGs come from context descriptors */
2825 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
2826 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
2828 /* Set the current VLAN Hash Table register value */
2829 xgbe_update_vlan_hash_table(pdata);
2831 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
2832 xgbe_enable_rx_vlan_filtering(pdata);
2833 else
2834 xgbe_disable_rx_vlan_filtering(pdata);
2836 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2837 xgbe_enable_rx_vlan_stripping(pdata);
2838 else
2839 xgbe_disable_rx_vlan_stripping(pdata);
2842 static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
2844 bool read_hi;
2845 u64 val;
2847 if (pdata->vdata->mmc_64bit) {
2848 switch (reg_lo) {
2849 /* These registers are always 32 bit */
2850 case MMC_RXRUNTERROR:
2851 case MMC_RXJABBERERROR:
2852 case MMC_RXUNDERSIZE_G:
2853 case MMC_RXOVERSIZE_G:
2854 case MMC_RXWATCHDOGERROR:
2855 read_hi = false;
2856 break;
2858 default:
2859 read_hi = true;
2861 } else {
2862 switch (reg_lo) {
2863 /* These registers are always 64 bit */
2864 case MMC_TXOCTETCOUNT_GB_LO:
2865 case MMC_TXOCTETCOUNT_G_LO:
2866 case MMC_RXOCTETCOUNT_GB_LO:
2867 case MMC_RXOCTETCOUNT_G_LO:
2868 read_hi = true;
2869 break;
2871 default:
2872 read_hi = false;
2876 val = XGMAC_IOREAD(pdata, reg_lo);
2878 if (read_hi)
2879 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
2881 return val;
2884 static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
2886 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2887 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
2889 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
2890 stats->txoctetcount_gb +=
2891 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
2893 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
2894 stats->txframecount_gb +=
2895 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
2897 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
2898 stats->txbroadcastframes_g +=
2899 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
2901 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
2902 stats->txmulticastframes_g +=
2903 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
2905 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
2906 stats->tx64octets_gb +=
2907 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
2909 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
2910 stats->tx65to127octets_gb +=
2911 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
2913 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
2914 stats->tx128to255octets_gb +=
2915 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
2917 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
2918 stats->tx256to511octets_gb +=
2919 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
2921 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
2922 stats->tx512to1023octets_gb +=
2923 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
2925 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
2926 stats->tx1024tomaxoctets_gb +=
2927 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
2929 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
2930 stats->txunicastframes_gb +=
2931 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
2933 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2934 stats->txmulticastframes_gb +=
2935 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
2937 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2938 stats->txbroadcastframes_g +=
2939 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
2941 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2942 stats->txunderflowerror +=
2943 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
2945 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2946 stats->txoctetcount_g +=
2947 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
2949 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2950 stats->txframecount_g +=
2951 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
2953 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2954 stats->txpauseframes +=
2955 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
2957 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2958 stats->txvlanframes_g +=
2959 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
2962 static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2964 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2965 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2967 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2968 stats->rxframecount_gb +=
2969 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
2971 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2972 stats->rxoctetcount_gb +=
2973 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
2975 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2976 stats->rxoctetcount_g +=
2977 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
2979 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2980 stats->rxbroadcastframes_g +=
2981 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
2983 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2984 stats->rxmulticastframes_g +=
2985 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
2987 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2988 stats->rxcrcerror +=
2989 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
2991 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2992 stats->rxrunterror +=
2993 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
2995 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2996 stats->rxjabbererror +=
2997 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
2999 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
3000 stats->rxundersize_g +=
3001 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
3003 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
3004 stats->rxoversize_g +=
3005 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
3007 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
3008 stats->rx64octets_gb +=
3009 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
3011 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
3012 stats->rx65to127octets_gb +=
3013 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
3015 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
3016 stats->rx128to255octets_gb +=
3017 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
3019 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
3020 stats->rx256to511octets_gb +=
3021 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
3023 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
3024 stats->rx512to1023octets_gb +=
3025 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
3027 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
3028 stats->rx1024tomaxoctets_gb +=
3029 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
3031 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
3032 stats->rxunicastframes_g +=
3033 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
3035 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
3036 stats->rxlengtherror +=
3037 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
3039 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
3040 stats->rxoutofrangetype +=
3041 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
3043 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
3044 stats->rxpauseframes +=
3045 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
3047 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
3048 stats->rxfifooverflow +=
3049 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
3051 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
3052 stats->rxvlanframes_gb +=
3053 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
3055 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
3056 stats->rxwatchdogerror +=
3057 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
3060 static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
3062 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
3064 /* Freeze counters */
3065 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
3067 stats->txoctetcount_gb +=
3068 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
3070 stats->txframecount_gb +=
3071 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
3073 stats->txbroadcastframes_g +=
3074 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
3076 stats->txmulticastframes_g +=
3077 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
3079 stats->tx64octets_gb +=
3080 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
3082 stats->tx65to127octets_gb +=
3083 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
3085 stats->tx128to255octets_gb +=
3086 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
3088 stats->tx256to511octets_gb +=
3089 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
3091 stats->tx512to1023octets_gb +=
3092 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
3094 stats->tx1024tomaxoctets_gb +=
3095 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
3097 stats->txunicastframes_gb +=
3098 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
3100 stats->txmulticastframes_gb +=
3101 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
3103 stats->txbroadcastframes_g +=
3104 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
3106 stats->txunderflowerror +=
3107 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
3109 stats->txoctetcount_g +=
3110 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
3112 stats->txframecount_g +=
3113 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
3115 stats->txpauseframes +=
3116 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
3118 stats->txvlanframes_g +=
3119 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
3121 stats->rxframecount_gb +=
3122 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
3124 stats->rxoctetcount_gb +=
3125 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
3127 stats->rxoctetcount_g +=
3128 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
3130 stats->rxbroadcastframes_g +=
3131 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
3133 stats->rxmulticastframes_g +=
3134 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
3136 stats->rxcrcerror +=
3137 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
3139 stats->rxrunterror +=
3140 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
3142 stats->rxjabbererror +=
3143 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
3145 stats->rxundersize_g +=
3146 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
3148 stats->rxoversize_g +=
3149 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
3151 stats->rx64octets_gb +=
3152 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
3154 stats->rx65to127octets_gb +=
3155 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
3157 stats->rx128to255octets_gb +=
3158 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
3160 stats->rx256to511octets_gb +=
3161 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
3163 stats->rx512to1023octets_gb +=
3164 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
3166 stats->rx1024tomaxoctets_gb +=
3167 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
3169 stats->rxunicastframes_g +=
3170 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
3172 stats->rxlengtherror +=
3173 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
3175 stats->rxoutofrangetype +=
3176 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
3178 stats->rxpauseframes +=
3179 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
3181 stats->rxfifooverflow +=
3182 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
3184 stats->rxvlanframes_gb +=
3185 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
3187 stats->rxwatchdogerror +=
3188 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
3190 /* Un-freeze counters */
3191 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
3194 static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
3196 /* Set counters to reset on read */
3197 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
3199 /* Reset the counters */
3200 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
3203 static void xgbe_txq_prepare_tx_stop(struct xgbe_prv_data *pdata,
3204 unsigned int queue)
3206 unsigned int tx_status;
3207 unsigned long tx_timeout;
3209 /* The Tx engine cannot be stopped if it is actively processing
3210 * packets. Wait for the Tx queue to empty the Tx fifo. Don't
3211 * wait forever though...
3213 tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
3214 while (time_before(jiffies, tx_timeout)) {
3215 tx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR);
3216 if ((XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TRCSTS) != 1) &&
3217 (XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TXQSTS) == 0))
3218 break;
3220 usleep_range(500, 1000);
3223 if (!time_before(jiffies, tx_timeout))
3224 netdev_info(pdata->netdev,
3225 "timed out waiting for Tx queue %u to empty\n",
3226 queue);
3229 static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
3230 unsigned int queue)
3232 unsigned int tx_dsr, tx_pos, tx_qidx;
3233 unsigned int tx_status;
3234 unsigned long tx_timeout;
3236 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) > 0x20)
3237 return xgbe_txq_prepare_tx_stop(pdata, queue);
3239 /* Calculate the status register to read and the position within */
3240 if (queue < DMA_DSRX_FIRST_QUEUE) {
3241 tx_dsr = DMA_DSR0;
3242 tx_pos = (queue * DMA_DSR_Q_WIDTH) + DMA_DSR0_TPS_START;
3243 } else {
3244 tx_qidx = queue - DMA_DSRX_FIRST_QUEUE;
3246 tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
3247 tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
3248 DMA_DSRX_TPS_START;
3251 /* The Tx engine cannot be stopped if it is actively processing
3252 * descriptors. Wait for the Tx engine to enter the stopped or
3253 * suspended state. Don't wait forever though...
3255 tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
3256 while (time_before(jiffies, tx_timeout)) {
3257 tx_status = XGMAC_IOREAD(pdata, tx_dsr);
3258 tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
3259 if ((tx_status == DMA_TPS_STOPPED) ||
3260 (tx_status == DMA_TPS_SUSPENDED))
3261 break;
3263 usleep_range(500, 1000);
3266 if (!time_before(jiffies, tx_timeout))
3267 netdev_info(pdata->netdev,
3268 "timed out waiting for Tx DMA channel %u to stop\n",
3269 queue);
3272 static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
3274 unsigned int i;
3276 /* Enable each Tx DMA channel */
3277 for (i = 0; i < pdata->channel_count; i++) {
3278 if (!pdata->channel[i]->tx_ring)
3279 break;
3281 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 1);
3284 /* Enable each Tx queue */
3285 for (i = 0; i < pdata->tx_q_count; i++)
3286 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
3287 MTL_Q_ENABLED);
3289 /* Enable MAC Tx */
3290 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
3293 static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
3295 unsigned int i;
3297 /* Prepare for Tx DMA channel stop */
3298 for (i = 0; i < pdata->tx_q_count; i++)
3299 xgbe_prepare_tx_stop(pdata, i);
3301 /* Disable MAC Tx */
3302 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
3304 /* Disable each Tx queue */
3305 for (i = 0; i < pdata->tx_q_count; i++)
3306 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
3308 /* Disable each Tx DMA channel */
3309 for (i = 0; i < pdata->channel_count; i++) {
3310 if (!pdata->channel[i]->tx_ring)
3311 break;
3313 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 0);
3317 static void xgbe_prepare_rx_stop(struct xgbe_prv_data *pdata,
3318 unsigned int queue)
3320 unsigned int rx_status;
3321 unsigned long rx_timeout;
3323 /* The Rx engine cannot be stopped if it is actively processing
3324 * packets. Wait for the Rx queue to empty the Rx fifo. Don't
3325 * wait forever though...
3327 rx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
3328 while (time_before(jiffies, rx_timeout)) {
3329 rx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR);
3330 if ((XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) &&
3331 (XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0))
3332 break;
3334 usleep_range(500, 1000);
3337 if (!time_before(jiffies, rx_timeout))
3338 netdev_info(pdata->netdev,
3339 "timed out waiting for Rx queue %u to empty\n",
3340 queue);
3343 static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
3345 unsigned int reg_val, i;
3347 /* Enable each Rx DMA channel */
3348 for (i = 0; i < pdata->channel_count; i++) {
3349 if (!pdata->channel[i]->rx_ring)
3350 break;
3352 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 1);
3355 /* Enable each Rx queue */
3356 reg_val = 0;
3357 for (i = 0; i < pdata->rx_q_count; i++)
3358 reg_val |= (0x02 << (i << 1));
3359 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
3361 /* Enable MAC Rx */
3362 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
3363 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
3364 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
3365 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
3368 static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
3370 unsigned int i;
3372 /* Disable MAC Rx */
3373 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
3374 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
3375 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
3376 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
3378 /* Prepare for Rx DMA channel stop */
3379 for (i = 0; i < pdata->rx_q_count; i++)
3380 xgbe_prepare_rx_stop(pdata, i);
3382 /* Disable each Rx queue */
3383 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
3385 /* Disable each Rx DMA channel */
3386 for (i = 0; i < pdata->channel_count; i++) {
3387 if (!pdata->channel[i]->rx_ring)
3388 break;
3390 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 0);
3394 static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
3396 unsigned int i;
3398 /* Enable each Tx DMA channel */
3399 for (i = 0; i < pdata->channel_count; i++) {
3400 if (!pdata->channel[i]->tx_ring)
3401 break;
3403 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 1);
3406 /* Enable MAC Tx */
3407 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
3410 static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
3412 unsigned int i;
3414 /* Prepare for Tx DMA channel stop */
3415 for (i = 0; i < pdata->tx_q_count; i++)
3416 xgbe_prepare_tx_stop(pdata, i);
3418 /* Disable MAC Tx */
3419 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
3421 /* Disable each Tx DMA channel */
3422 for (i = 0; i < pdata->channel_count; i++) {
3423 if (!pdata->channel[i]->tx_ring)
3424 break;
3426 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 0);
3430 static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
3432 unsigned int i;
3434 /* Enable each Rx DMA channel */
3435 for (i = 0; i < pdata->channel_count; i++) {
3436 if (!pdata->channel[i]->rx_ring)
3437 break;
3439 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 1);
3443 static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
3445 unsigned int i;
3447 /* Disable each Rx DMA channel */
3448 for (i = 0; i < pdata->channel_count; i++) {
3449 if (!pdata->channel[i]->rx_ring)
3450 break;
3452 XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 0);
3456 static int xgbe_init(struct xgbe_prv_data *pdata)
3458 struct xgbe_desc_if *desc_if = &pdata->desc_if;
3459 int ret;
3461 DBGPR("-->xgbe_init\n");
3463 /* Flush Tx queues */
3464 ret = xgbe_flush_tx_queues(pdata);
3465 if (ret) {
3466 netdev_err(pdata->netdev, "error flushing TX queues\n");
3467 return ret;
3471 * Initialize DMA related features
3473 xgbe_config_dma_bus(pdata);
3474 xgbe_config_dma_cache(pdata);
3475 xgbe_config_osp_mode(pdata);
3476 xgbe_config_pbl_val(pdata);
3477 xgbe_config_rx_coalesce(pdata);
3478 xgbe_config_tx_coalesce(pdata);
3479 xgbe_config_rx_buffer_size(pdata);
3480 xgbe_config_tso_mode(pdata);
3481 xgbe_config_sph_mode(pdata);
3482 xgbe_config_rss(pdata);
3483 desc_if->wrapper_tx_desc_init(pdata);
3484 desc_if->wrapper_rx_desc_init(pdata);
3485 xgbe_enable_dma_interrupts(pdata);
3488 * Initialize MTL related features
3490 xgbe_config_mtl_mode(pdata);
3491 xgbe_config_queue_mapping(pdata);
3492 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
3493 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
3494 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
3495 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
3496 xgbe_config_tx_fifo_size(pdata);
3497 xgbe_config_rx_fifo_size(pdata);
3498 /*TODO: Error Packet and undersized good Packet forwarding enable
3499 (FEP and FUP)
3501 xgbe_config_dcb_tc(pdata);
3502 xgbe_enable_mtl_interrupts(pdata);
3505 * Initialize MAC related features
3507 xgbe_config_mac_address(pdata);
3508 xgbe_config_rx_mode(pdata);
3509 xgbe_config_jumbo_enable(pdata);
3510 xgbe_config_flow_control(pdata);
3511 xgbe_config_mac_speed(pdata);
3512 xgbe_config_checksum_offload(pdata);
3513 xgbe_config_vlan_support(pdata);
3514 xgbe_config_mmc(pdata);
3515 xgbe_enable_mac_interrupts(pdata);
3518 * Initialize ECC related features
3520 xgbe_enable_ecc_interrupts(pdata);
3522 DBGPR("<--xgbe_init\n");
3524 return 0;
3527 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
3529 DBGPR("-->xgbe_init_function_ptrs\n");
3531 hw_if->tx_complete = xgbe_tx_complete;
3533 hw_if->set_mac_address = xgbe_set_mac_address;
3534 hw_if->config_rx_mode = xgbe_config_rx_mode;
3536 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
3537 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
3539 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
3540 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
3541 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
3542 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
3543 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
3545 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
3546 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
3548 hw_if->set_speed = xgbe_set_speed;
3550 hw_if->set_ext_mii_mode = xgbe_set_ext_mii_mode;
3551 hw_if->read_ext_mii_regs = xgbe_read_ext_mii_regs;
3552 hw_if->write_ext_mii_regs = xgbe_write_ext_mii_regs;
3554 hw_if->set_gpio = xgbe_set_gpio;
3555 hw_if->clr_gpio = xgbe_clr_gpio;
3557 hw_if->enable_tx = xgbe_enable_tx;
3558 hw_if->disable_tx = xgbe_disable_tx;
3559 hw_if->enable_rx = xgbe_enable_rx;
3560 hw_if->disable_rx = xgbe_disable_rx;
3562 hw_if->powerup_tx = xgbe_powerup_tx;
3563 hw_if->powerdown_tx = xgbe_powerdown_tx;
3564 hw_if->powerup_rx = xgbe_powerup_rx;
3565 hw_if->powerdown_rx = xgbe_powerdown_rx;
3567 hw_if->dev_xmit = xgbe_dev_xmit;
3568 hw_if->dev_read = xgbe_dev_read;
3569 hw_if->enable_int = xgbe_enable_int;
3570 hw_if->disable_int = xgbe_disable_int;
3571 hw_if->init = xgbe_init;
3572 hw_if->exit = xgbe_exit;
3574 /* Descriptor related Sequences have to be initialized here */
3575 hw_if->tx_desc_init = xgbe_tx_desc_init;
3576 hw_if->rx_desc_init = xgbe_rx_desc_init;
3577 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
3578 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
3579 hw_if->is_last_desc = xgbe_is_last_desc;
3580 hw_if->is_context_desc = xgbe_is_context_desc;
3581 hw_if->tx_start_xmit = xgbe_tx_start_xmit;
3583 /* For FLOW ctrl */
3584 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
3585 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
3587 /* For RX coalescing */
3588 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
3589 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
3590 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
3591 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
3593 /* For RX and TX threshold config */
3594 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
3595 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
3597 /* For RX and TX Store and Forward Mode config */
3598 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
3599 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
3601 /* For TX DMA Operating on Second Frame config */
3602 hw_if->config_osp_mode = xgbe_config_osp_mode;
3604 /* For MMC statistics support */
3605 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
3606 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
3607 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
3609 /* For PTP config */
3610 hw_if->config_tstamp = xgbe_config_tstamp;
3611 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
3612 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
3613 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
3614 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
3616 /* For Data Center Bridging config */
3617 hw_if->config_tc = xgbe_config_tc;
3618 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
3619 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
3621 /* For Receive Side Scaling */
3622 hw_if->enable_rss = xgbe_enable_rss;
3623 hw_if->disable_rss = xgbe_disable_rss;
3624 hw_if->set_rss_hash_key = xgbe_set_rss_hash_key;
3625 hw_if->set_rss_lookup_table = xgbe_set_rss_lookup_table;
3627 /* For ECC */
3628 hw_if->disable_ecc_ded = xgbe_disable_ecc_ded;
3629 hw_if->disable_ecc_sec = xgbe_disable_ecc_sec;
3631 /* For VXLAN */
3632 hw_if->enable_vxlan = xgbe_enable_vxlan;
3633 hw_if->disable_vxlan = xgbe_disable_vxlan;
3634 hw_if->set_vxlan_id = xgbe_set_vxlan_id;
3636 DBGPR("<--xgbe_init_function_ptrs\n");