blob: b48c6eca3e6b275c6bd9c5314139273e95c155fe [file] [log] [blame]
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001/*
2 * AMD 10Gb Ethernet driver
3 *
4 * This file is available to you under your choice of the following two
5 * licenses:
6 *
7 * License 1: GPLv2
8 *
Lendacky, Thomasb4eee842016-02-17 11:48:08 -06009 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050010 *
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.
15 *
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.
20 *
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/>.
23 *
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.
30 *
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:
40 *
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
43 *
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.
55 *
56 *
57 * License 2: Modified BSD
58 *
Lendacky, Thomasb4eee842016-02-17 11:48:08 -060059 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050060 * All rights reserved.
61 *
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.
72 *
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.
83 *
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.
90 *
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:
100 *
101 * The above copyright notice and this permission notice shall be included
102 * in all copies or substantial portions of the Software.
103 *
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.
115 */
116
117#include <linux/phy.h>
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600118#include <linux/mdio.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500119#include <linux/clk.h>
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500120#include <linux/bitrev.h>
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500121#include <linux/crc32.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500122
123#include "xgbe.h"
124#include "xgbe-common.h"
125
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500126static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
127 unsigned int usec)
128{
129 unsigned long rate;
130 unsigned int ret;
131
132 DBGPR("-->xgbe_usec_to_riwt\n");
133
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600134 rate = pdata->sysclk_rate;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500135
136 /*
137 * Convert the input usec value to the watchdog timer value. Each
138 * watchdog timer value is equivalent to 256 clock cycles.
139 * Calculate the required value as:
140 * ( usec * ( system_clock_mhz / 10^6 ) / 256
141 */
142 ret = (usec * (rate / 1000000)) / 256;
143
144 DBGPR("<--xgbe_usec_to_riwt\n");
145
146 return ret;
147}
148
149static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
150 unsigned int riwt)
151{
152 unsigned long rate;
153 unsigned int ret;
154
155 DBGPR("-->xgbe_riwt_to_usec\n");
156
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600157 rate = pdata->sysclk_rate;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500158
159 /*
160 * Convert the input watchdog timer value to the usec value. Each
161 * watchdog timer value is equivalent to 256 clock cycles.
162 * Calculate the required value as:
163 * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
164 */
165 ret = (riwt * 256) / (rate / 1000000);
166
167 DBGPR("<--xgbe_riwt_to_usec\n");
168
169 return ret;
170}
171
172static int xgbe_config_pblx8(struct xgbe_prv_data *pdata)
173{
174 struct xgbe_channel *channel;
175 unsigned int i;
176
177 channel = pdata->channel;
178 for (i = 0; i < pdata->channel_count; i++, channel++)
179 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8,
180 pdata->pblx8);
181
182 return 0;
183}
184
185static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata)
186{
187 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL);
188}
189
190static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata)
191{
192 struct xgbe_channel *channel;
193 unsigned int i;
194
195 channel = pdata->channel;
196 for (i = 0; i < pdata->channel_count; i++, channel++) {
197 if (!channel->tx_ring)
198 break;
199
200 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL,
201 pdata->tx_pbl);
202 }
203
204 return 0;
205}
206
207static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata)
208{
209 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL);
210}
211
212static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata)
213{
214 struct xgbe_channel *channel;
215 unsigned int i;
216
217 channel = pdata->channel;
218 for (i = 0; i < pdata->channel_count; i++, channel++) {
219 if (!channel->rx_ring)
220 break;
221
222 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL,
223 pdata->rx_pbl);
224 }
225
226 return 0;
227}
228
229static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
230{
231 struct xgbe_channel *channel;
232 unsigned int i;
233
234 channel = pdata->channel;
235 for (i = 0; i < pdata->channel_count; i++, channel++) {
236 if (!channel->tx_ring)
237 break;
238
239 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP,
240 pdata->tx_osp_mode);
241 }
242
243 return 0;
244}
245
246static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
247{
248 unsigned int i;
249
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500250 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500251 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
252
253 return 0;
254}
255
256static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
257{
258 unsigned int i;
259
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500260 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500261 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
262
263 return 0;
264}
265
266static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
267 unsigned int val)
268{
269 unsigned int i;
270
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500271 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500272 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
273
274 return 0;
275}
276
277static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
278 unsigned int val)
279{
280 unsigned int i;
281
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500282 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500283 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
284
285 return 0;
286}
287
288static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
289{
290 struct xgbe_channel *channel;
291 unsigned int i;
292
293 channel = pdata->channel;
294 for (i = 0; i < pdata->channel_count; i++, channel++) {
295 if (!channel->rx_ring)
296 break;
297
298 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT,
299 pdata->rx_riwt);
300 }
301
302 return 0;
303}
304
305static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
306{
307 return 0;
308}
309
310static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
311{
312 struct xgbe_channel *channel;
313 unsigned int i;
314
315 channel = pdata->channel;
316 for (i = 0; i < pdata->channel_count; i++, channel++) {
317 if (!channel->rx_ring)
318 break;
319
320 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ,
321 pdata->rx_buf_size);
322 }
323}
324
325static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
326{
327 struct xgbe_channel *channel;
328 unsigned int i;
329
330 channel = pdata->channel;
331 for (i = 0; i < pdata->channel_count; i++, channel++) {
332 if (!channel->tx_ring)
333 break;
334
335 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1);
336 }
337}
338
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600339static void xgbe_config_sph_mode(struct xgbe_prv_data *pdata)
340{
341 struct xgbe_channel *channel;
342 unsigned int i;
343
344 channel = pdata->channel;
345 for (i = 0; i < pdata->channel_count; i++, channel++) {
346 if (!channel->rx_ring)
347 break;
348
349 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, SPH, 1);
350 }
351
352 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE);
353}
354
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600355static int xgbe_write_rss_reg(struct xgbe_prv_data *pdata, unsigned int type,
356 unsigned int index, unsigned int val)
357{
358 unsigned int wait;
359 int ret = 0;
360
361 mutex_lock(&pdata->rss_mutex);
362
363 if (XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB)) {
364 ret = -EBUSY;
365 goto unlock;
366 }
367
368 XGMAC_IOWRITE(pdata, MAC_RSSDR, val);
369
370 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, RSSIA, index);
371 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, ADDRT, type);
372 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, CT, 0);
373 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, OB, 1);
374
375 wait = 1000;
376 while (wait--) {
377 if (!XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB))
378 goto unlock;
379
380 usleep_range(1000, 1500);
381 }
382
383 ret = -EBUSY;
384
385unlock:
386 mutex_unlock(&pdata->rss_mutex);
387
388 return ret;
389}
390
391static int xgbe_write_rss_hash_key(struct xgbe_prv_data *pdata)
392{
393 unsigned int key_regs = sizeof(pdata->rss_key) / sizeof(u32);
394 unsigned int *key = (unsigned int *)&pdata->rss_key;
395 int ret;
396
397 while (key_regs--) {
398 ret = xgbe_write_rss_reg(pdata, XGBE_RSS_HASH_KEY_TYPE,
399 key_regs, *key++);
400 if (ret)
401 return ret;
402 }
403
404 return 0;
405}
406
407static int xgbe_write_rss_lookup_table(struct xgbe_prv_data *pdata)
408{
409 unsigned int i;
410 int ret;
411
412 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) {
413 ret = xgbe_write_rss_reg(pdata,
414 XGBE_RSS_LOOKUP_TABLE_TYPE, i,
415 pdata->rss_table[i]);
416 if (ret)
417 return ret;
418 }
419
420 return 0;
421}
422
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600423static int xgbe_set_rss_hash_key(struct xgbe_prv_data *pdata, const u8 *key)
424{
425 memcpy(pdata->rss_key, key, sizeof(pdata->rss_key));
426
427 return xgbe_write_rss_hash_key(pdata);
428}
429
430static int xgbe_set_rss_lookup_table(struct xgbe_prv_data *pdata,
431 const u32 *table)
432{
433 unsigned int i;
434
435 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
436 XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, table[i]);
437
438 return xgbe_write_rss_lookup_table(pdata);
439}
440
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600441static int xgbe_enable_rss(struct xgbe_prv_data *pdata)
442{
443 int ret;
444
445 if (!pdata->hw_feat.rss)
446 return -EOPNOTSUPP;
447
448 /* Program the hash key */
449 ret = xgbe_write_rss_hash_key(pdata);
450 if (ret)
451 return ret;
452
453 /* Program the lookup table */
454 ret = xgbe_write_rss_lookup_table(pdata);
455 if (ret)
456 return ret;
457
458 /* Set the RSS options */
459 XGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options);
460
461 /* Enable RSS */
462 XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 1);
463
464 return 0;
465}
466
467static int xgbe_disable_rss(struct xgbe_prv_data *pdata)
468{
469 if (!pdata->hw_feat.rss)
470 return -EOPNOTSUPP;
471
472 XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 0);
473
474 return 0;
475}
476
477static void xgbe_config_rss(struct xgbe_prv_data *pdata)
478{
479 int ret;
480
481 if (!pdata->hw_feat.rss)
482 return;
483
484 if (pdata->netdev->features & NETIF_F_RXHASH)
485 ret = xgbe_enable_rss(pdata);
486 else
487 ret = xgbe_disable_rss(pdata);
488
489 if (ret)
490 netdev_err(pdata->netdev,
491 "error configuring RSS, RSS disabled\n");
492}
493
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500494static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
495{
496 unsigned int max_q_count, q_count;
497 unsigned int reg, reg_val;
498 unsigned int i;
499
500 /* Clear MTL flow control */
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500501 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500502 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
503
504 /* Clear MAC flow control */
505 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas9fc69af2014-08-29 13:17:08 -0500506 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500507 reg = MAC_Q0TFCR;
508 for (i = 0; i < q_count; i++) {
509 reg_val = XGMAC_IOREAD(pdata, reg);
510 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
511 XGMAC_IOWRITE(pdata, reg, reg_val);
512
513 reg += MAC_QTFCR_INC;
514 }
515
516 return 0;
517}
518
519static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
520{
Lendacky, Thomas8dba2a22016-02-17 11:48:48 -0600521 struct ieee_pfc *pfc = pdata->pfc;
522 struct ieee_ets *ets = pdata->ets;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500523 unsigned int max_q_count, q_count;
524 unsigned int reg, reg_val;
525 unsigned int i;
526
527 /* Set MTL flow control */
Lendacky, Thomas8dba2a22016-02-17 11:48:48 -0600528 for (i = 0; i < pdata->rx_q_count; i++) {
529 unsigned int ehfc = 0;
530
531 if (pfc && ets) {
532 unsigned int prio;
533
534 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
535 unsigned int tc;
536
537 /* Does this queue handle the priority? */
538 if (pdata->prio2q_map[prio] != i)
539 continue;
540
541 /* Get the Traffic Class for this priority */
542 tc = ets->prio_tc[prio];
543
544 /* Check if flow control should be enabled */
545 if (pfc->pfc_en & (1 << tc)) {
546 ehfc = 1;
547 break;
548 }
549 }
550 } else {
551 ehfc = 1;
552 }
553
554 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, ehfc);
555
556 netif_dbg(pdata, drv, pdata->netdev,
557 "flow control %s for RXq%u\n",
558 ehfc ? "enabled" : "disabled", i);
559 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500560
561 /* Set MAC flow control */
562 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas9fc69af2014-08-29 13:17:08 -0500563 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500564 reg = MAC_Q0TFCR;
565 for (i = 0; i < q_count; i++) {
566 reg_val = XGMAC_IOREAD(pdata, reg);
567
568 /* Enable transmit flow control */
569 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
570 /* Set pause time */
571 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
572
573 XGMAC_IOWRITE(pdata, reg, reg_val);
574
575 reg += MAC_QTFCR_INC;
576 }
577
578 return 0;
579}
580
581static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
582{
583 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
584
585 return 0;
586}
587
588static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
589{
590 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
591
592 return 0;
593}
594
595static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
596{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500597 struct ieee_pfc *pfc = pdata->pfc;
598
599 if (pdata->tx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500600 xgbe_enable_tx_flow_control(pdata);
601 else
602 xgbe_disable_tx_flow_control(pdata);
603
604 return 0;
605}
606
607static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
608{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500609 struct ieee_pfc *pfc = pdata->pfc;
610
611 if (pdata->rx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500612 xgbe_enable_rx_flow_control(pdata);
613 else
614 xgbe_disable_rx_flow_control(pdata);
615
616 return 0;
617}
618
619static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
620{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500621 struct ieee_pfc *pfc = pdata->pfc;
622
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500623 xgbe_config_tx_flow_control(pdata);
624 xgbe_config_rx_flow_control(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500625
626 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
627 (pfc && pfc->pfc_en) ? 1 : 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500628}
629
630static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
631{
632 struct xgbe_channel *channel;
633 unsigned int dma_ch_isr, dma_ch_ier;
634 unsigned int i;
635
636 channel = pdata->channel;
637 for (i = 0; i < pdata->channel_count; i++, channel++) {
638 /* Clear all the interrupts which are set */
639 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
640 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
641
642 /* Clear all interrupt enable bits */
643 dma_ch_ier = 0;
644
645 /* Enable following interrupts
646 * NIE - Normal Interrupt Summary Enable
647 * AIE - Abnormal Interrupt Summary Enable
648 * FBEE - Fatal Bus Error Enable
649 */
650 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
651 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
652 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
653
654 if (channel->tx_ring) {
655 /* Enable the following Tx interrupts
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600656 * TIE - Transmit Interrupt Enable (unless using
657 * per channel interrupts)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500658 */
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600659 if (!pdata->per_channel_irq)
660 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500661 }
662 if (channel->rx_ring) {
663 /* Enable following Rx interrupts
664 * RBUE - Receive Buffer Unavailable Enable
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600665 * RIE - Receive Interrupt Enable (unless using
666 * per channel interrupts)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500667 */
668 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600669 if (!pdata->per_channel_irq)
670 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500671 }
672
673 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
674 }
675}
676
677static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
678{
679 unsigned int mtl_q_isr;
680 unsigned int q_count, i;
681
682 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
683 for (i = 0; i < q_count; i++) {
684 /* Clear all the interrupts which are set */
685 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
686 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
687
688 /* No MTL interrupts to be enabled */
Lendacky, Thomas91f87342014-07-02 13:04:34 -0500689 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500690 }
691}
692
693static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
694{
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500695 unsigned int mac_ier = 0;
696
697 /* Enable Timestamp interrupt */
698 XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
699
700 XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500701
702 /* Enable all counter interrupts */
Lendacky, Thomasa3ba7c92014-09-05 18:02:36 -0500703 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
704 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500705}
706
707static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
708{
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600709 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) == 0x3)
710 return 0;
711
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500712 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
713
714 return 0;
715}
716
717static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
718{
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600719 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) == 0x2)
720 return 0;
721
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500722 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
723
724 return 0;
725}
726
727static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
728{
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600729 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) == 0)
730 return 0;
731
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500732 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
733
734 return 0;
735}
736
Lendacky, Thomasb4eee842016-02-17 11:48:08 -0600737static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
738{
739 /* Put the VLAN tag in the Rx descriptor */
740 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
741
742 /* Don't check the VLAN type */
743 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
744
745 /* Check only C-TAG (0x8100) packets */
746 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
747
748 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
749 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
750
751 /* Enable VLAN tag stripping */
752 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
753
754 return 0;
755}
756
757static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
758{
759 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
760
761 return 0;
762}
763
764static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
765{
766 /* Enable VLAN filtering */
767 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
768
769 /* Enable VLAN Hash Table filtering */
770 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
771
772 /* Disable VLAN tag inverse matching */
773 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
774
775 /* Only filter on the lower 12-bits of the VLAN tag */
776 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
777
778 /* In order for the VLAN Hash Table filtering to be effective,
779 * the VLAN tag identifier in the VLAN Tag Register must not
780 * be zero. Set the VLAN tag identifier to "1" to enable the
781 * VLAN Hash Table filtering. This implies that a VLAN tag of
782 * 1 will always pass filtering.
783 */
784 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
785
786 return 0;
787}
788
789static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
790{
791 /* Disable VLAN filtering */
792 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
793
794 return 0;
795}
796
797static u32 xgbe_vid_crc32_le(__le16 vid_le)
798{
799 u32 poly = 0xedb88320; /* CRCPOLY_LE */
800 u32 crc = ~0;
801 u32 temp = 0;
802 unsigned char *data = (unsigned char *)&vid_le;
803 unsigned char data_byte = 0;
804 int i, bits;
805
806 bits = get_bitmask_order(VLAN_VID_MASK);
807 for (i = 0; i < bits; i++) {
808 if ((i % 8) == 0)
809 data_byte = data[i / 8];
810
811 temp = ((crc & 1) ^ data_byte) & 1;
812 crc >>= 1;
813 data_byte >>= 1;
814
815 if (temp)
816 crc ^= poly;
817 }
818
819 return crc;
820}
821
822static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
823{
824 u32 crc;
825 u16 vid;
826 __le16 vid_le;
827 u16 vlan_hash_table = 0;
828
829 /* Generate the VLAN Hash Table value */
830 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
831 /* Get the CRC32 value of the VLAN ID */
832 vid_le = cpu_to_le16(vid);
833 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
834
835 vlan_hash_table |= (1 << crc);
836 }
837
838 /* Set the VLAN Hash Table filtering register */
839 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
840
841 return 0;
842}
843
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500844static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
845 unsigned int enable)
846{
847 unsigned int val = enable ? 1 : 0;
848
849 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
850 return 0;
851
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500852 netif_dbg(pdata, drv, pdata->netdev, "%s promiscuous mode\n",
853 enable ? "entering" : "leaving");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500854 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
855
Lendacky, Thomasb4eee842016-02-17 11:48:08 -0600856 /* Hardware will still perform VLAN filtering in promiscuous mode */
857 if (enable) {
858 xgbe_disable_rx_vlan_filtering(pdata);
859 } else {
860 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
861 xgbe_enable_rx_vlan_filtering(pdata);
862 }
863
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500864 return 0;
865}
866
867static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
868 unsigned int enable)
869{
870 unsigned int val = enable ? 1 : 0;
871
872 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
873 return 0;
874
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500875 netif_dbg(pdata, drv, pdata->netdev, "%s allmulti mode\n",
876 enable ? "entering" : "leaving");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500877 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
878
879 return 0;
880}
881
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500882static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
883 struct netdev_hw_addr *ha, unsigned int *mac_reg)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500884{
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500885 unsigned int mac_addr_hi, mac_addr_lo;
886 u8 *mac_addr;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500887
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500888 mac_addr_lo = 0;
889 mac_addr_hi = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500890
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500891 if (ha) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500892 mac_addr = (u8 *)&mac_addr_lo;
893 mac_addr[0] = ha->addr[0];
894 mac_addr[1] = ha->addr[1];
895 mac_addr[2] = ha->addr[2];
896 mac_addr[3] = ha->addr[3];
897 mac_addr = (u8 *)&mac_addr_hi;
898 mac_addr[0] = ha->addr[4];
899 mac_addr[1] = ha->addr[5];
900
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500901 netif_dbg(pdata, drv, pdata->netdev,
902 "adding mac address %pM at %#x\n",
903 ha->addr, *mac_reg);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500904
905 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500906 }
907
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500908 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
909 *mac_reg += MAC_MACA_INC;
910 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
911 *mac_reg += MAC_MACA_INC;
912}
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500913
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500914static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
915{
916 struct net_device *netdev = pdata->netdev;
917 struct netdev_hw_addr *ha;
918 unsigned int mac_reg;
919 unsigned int addn_macs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500920
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500921 mac_reg = MAC_MACA1HR;
922 addn_macs = pdata->hw_feat.addn_mac;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500923
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500924 if (netdev_uc_count(netdev) > addn_macs) {
925 xgbe_set_promiscuous_mode(pdata, 1);
926 } else {
927 netdev_for_each_uc_addr(ha, netdev) {
928 xgbe_set_mac_reg(pdata, ha, &mac_reg);
929 addn_macs--;
930 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500931
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500932 if (netdev_mc_count(netdev) > addn_macs) {
933 xgbe_set_all_multicast_mode(pdata, 1);
934 } else {
935 netdev_for_each_mc_addr(ha, netdev) {
936 xgbe_set_mac_reg(pdata, ha, &mac_reg);
937 addn_macs--;
938 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500939 }
940 }
941
942 /* Clear remaining additional MAC address entries */
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500943 while (addn_macs--)
944 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
945}
946
947static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
948{
949 struct net_device *netdev = pdata->netdev;
950 struct netdev_hw_addr *ha;
951 unsigned int hash_reg;
952 unsigned int hash_table_shift, hash_table_count;
953 u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
954 u32 crc;
955 unsigned int i;
956
957 hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
958 hash_table_count = pdata->hw_feat.hash_table_size / 32;
959 memset(hash_table, 0, sizeof(hash_table));
960
961 /* Build the MAC Hash Table register values */
962 netdev_for_each_uc_addr(ha, netdev) {
963 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
964 crc >>= hash_table_shift;
965 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500966 }
967
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500968 netdev_for_each_mc_addr(ha, netdev) {
969 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
970 crc >>= hash_table_shift;
971 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
972 }
973
974 /* Set the MAC Hash Table registers */
975 hash_reg = MAC_HTR0;
976 for (i = 0; i < hash_table_count; i++) {
977 XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
978 hash_reg += MAC_HTR_INC;
979 }
980}
981
982static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
983{
984 if (pdata->hw_feat.hash_table_size)
985 xgbe_set_mac_hash_table(pdata);
986 else
987 xgbe_set_mac_addn_addrs(pdata);
988
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500989 return 0;
990}
991
992static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
993{
994 unsigned int mac_addr_hi, mac_addr_lo;
995
996 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
997 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
998 (addr[1] << 8) | (addr[0] << 0);
999
1000 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
1001 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
1002
1003 return 0;
1004}
1005
Lendacky, Thomasb8763822015-04-09 12:11:57 -05001006static int xgbe_config_rx_mode(struct xgbe_prv_data *pdata)
1007{
1008 struct net_device *netdev = pdata->netdev;
1009 unsigned int pr_mode, am_mode;
1010
1011 pr_mode = ((netdev->flags & IFF_PROMISC) != 0);
1012 am_mode = ((netdev->flags & IFF_ALLMULTI) != 0);
1013
1014 xgbe_set_promiscuous_mode(pdata, pr_mode);
1015 xgbe_set_all_multicast_mode(pdata, am_mode);
1016
1017 xgbe_add_mac_addresses(pdata);
1018
1019 return 0;
1020}
1021
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001022static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
1023 int mmd_reg)
1024{
1025 unsigned int mmd_address;
1026 int mmd_data;
1027
1028 if (mmd_reg & MII_ADDR_C45)
1029 mmd_address = mmd_reg & ~MII_ADDR_C45;
1030 else
1031 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1032
1033 /* The PCS registers are accessed using mmio. The underlying APB3
1034 * management interface uses indirect addressing to access the MMD
1035 * register sets. This requires accessing of the PCS register in two
1036 * phases, an address phase and a data phase.
1037 *
1038 * The mmio interface is based on 32-bit offsets and values. All
1039 * register offsets must therefore be adjusted by left shifting the
1040 * offset 2 bits and reading 32 bits of data.
1041 */
1042 mutex_lock(&pdata->xpcs_mutex);
1043 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
1044 mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
1045 mutex_unlock(&pdata->xpcs_mutex);
1046
1047 return mmd_data;
1048}
1049
1050static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
1051 int mmd_reg, int mmd_data)
1052{
1053 unsigned int mmd_address;
1054
1055 if (mmd_reg & MII_ADDR_C45)
1056 mmd_address = mmd_reg & ~MII_ADDR_C45;
1057 else
1058 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1059
1060 /* The PCS registers are accessed using mmio. The underlying APB3
1061 * management interface uses indirect addressing to access the MMD
1062 * register sets. This requires accessing of the PCS register in two
1063 * phases, an address phase and a data phase.
1064 *
1065 * The mmio interface is based on 32-bit offsets and values. All
1066 * register offsets must therefore be adjusted by left shifting the
1067 * offset 2 bits and reading 32 bits of data.
1068 */
1069 mutex_lock(&pdata->xpcs_mutex);
1070 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
1071 XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
1072 mutex_unlock(&pdata->xpcs_mutex);
1073}
1074
1075static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
1076{
1077 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
1078}
1079
1080static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
1081{
1082 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
1083
1084 return 0;
1085}
1086
1087static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
1088{
1089 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
1090
1091 return 0;
1092}
1093
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001094static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
1095{
1096 struct xgbe_ring_desc *rdesc = rdata->rdesc;
1097
1098 /* Reset the Tx descriptor
1099 * Set buffer 1 (lo) address to zero
1100 * Set buffer 1 (hi) address to zero
1101 * Reset all other control bits (IC, TTSE, B2L & B1L)
1102 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
1103 */
1104 rdesc->desc0 = 0;
1105 rdesc->desc1 = 0;
1106 rdesc->desc2 = 0;
1107 rdesc->desc3 = 0;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001108
1109 /* Make sure ownership is written to the descriptor */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001110 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001111}
1112
1113static void xgbe_tx_desc_init(struct xgbe_channel *channel)
1114{
1115 struct xgbe_ring *ring = channel->tx_ring;
1116 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001117 int i;
1118 int start_index = ring->cur;
1119
1120 DBGPR("-->tx_desc_init\n");
1121
1122 /* Initialze all descriptors */
1123 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001124 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001125
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001126 /* Initialize Tx descriptor */
1127 xgbe_tx_desc_reset(rdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001128 }
1129
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001130 /* Update the total number of Tx descriptors */
1131 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
1132
1133 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001134 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001135 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
1136 upper_32_bits(rdata->rdesc_dma));
1137 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
1138 lower_32_bits(rdata->rdesc_dma));
1139
1140 DBGPR("<--tx_desc_init\n");
1141}
1142
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001143static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata,
1144 struct xgbe_ring_data *rdata, unsigned int index)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001145{
1146 struct xgbe_ring_desc *rdesc = rdata->rdesc;
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001147 unsigned int rx_usecs = pdata->rx_usecs;
1148 unsigned int rx_frames = pdata->rx_frames;
1149 unsigned int inte;
Lendacky, Thomascfbfd862015-07-06 11:57:37 -05001150 dma_addr_t hdr_dma, buf_dma;
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001151
1152 if (!rx_usecs && !rx_frames) {
1153 /* No coalescing, interrupt for every descriptor */
1154 inte = 1;
1155 } else {
1156 /* Set interrupt based on Rx frame coalescing setting */
1157 if (rx_frames && !((index + 1) % rx_frames))
1158 inte = 1;
1159 else
1160 inte = 0;
1161 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001162
1163 /* Reset the Rx descriptor
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001164 * Set buffer 1 (lo) address to header dma address (lo)
1165 * Set buffer 1 (hi) address to header dma address (hi)
1166 * Set buffer 2 (lo) address to buffer dma address (lo)
1167 * Set buffer 2 (hi) address to buffer dma address (hi) and
1168 * set control bits OWN and INTE
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001169 */
Lendacky, Thomascfbfd862015-07-06 11:57:37 -05001170 hdr_dma = rdata->rx.hdr.dma_base + rdata->rx.hdr.dma_off;
1171 buf_dma = rdata->rx.buf.dma_base + rdata->rx.buf.dma_off;
1172 rdesc->desc0 = cpu_to_le32(lower_32_bits(hdr_dma));
1173 rdesc->desc1 = cpu_to_le32(upper_32_bits(hdr_dma));
1174 rdesc->desc2 = cpu_to_le32(lower_32_bits(buf_dma));
1175 rdesc->desc3 = cpu_to_le32(upper_32_bits(buf_dma));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001176
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001177 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001178
1179 /* Since the Rx DMA engine is likely running, make sure everything
1180 * is written to the descriptor(s) before setting the OWN bit
1181 * for the descriptor
1182 */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001183 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001184
1185 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
1186
1187 /* Make sure ownership is written to the descriptor */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001188 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001189}
1190
1191static void xgbe_rx_desc_init(struct xgbe_channel *channel)
1192{
1193 struct xgbe_prv_data *pdata = channel->pdata;
1194 struct xgbe_ring *ring = channel->rx_ring;
1195 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001196 unsigned int start_index = ring->cur;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001197 unsigned int i;
1198
1199 DBGPR("-->rx_desc_init\n");
1200
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001201 /* Initialize all descriptors */
1202 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001203 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001204
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001205 /* Initialize Rx descriptor */
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001206 xgbe_rx_desc_reset(pdata, rdata, i);
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001207 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001208
1209 /* Update the total number of Rx descriptors */
1210 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
1211
1212 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001213 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001214 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
1215 upper_32_bits(rdata->rdesc_dma));
1216 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
1217 lower_32_bits(rdata->rdesc_dma));
1218
1219 /* Update the Rx Descriptor Tail Pointer */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001220 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001221 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
1222 lower_32_bits(rdata->rdesc_dma));
1223
1224 DBGPR("<--rx_desc_init\n");
1225}
1226
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001227static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
1228 unsigned int addend)
1229{
1230 /* Set the addend register value and tell the device */
1231 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1232 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1233
1234 /* Wait for addend update to complete */
1235 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1236 udelay(5);
1237}
1238
1239static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1240 unsigned int nsec)
1241{
1242 /* Set the time values and tell the device */
1243 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1244 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1245 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1246
1247 /* Wait for time update to complete */
1248 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1249 udelay(5);
1250}
1251
1252static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1253{
1254 u64 nsec;
1255
1256 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1257 nsec *= NSEC_PER_SEC;
1258 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1259
1260 return nsec;
1261}
1262
1263static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1264{
1265 unsigned int tx_snr;
1266 u64 nsec;
1267
1268 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1269 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1270 return 0;
1271
1272 nsec = XGMAC_IOREAD(pdata, MAC_TXSSR);
1273 nsec *= NSEC_PER_SEC;
1274 nsec += tx_snr;
1275
1276 return nsec;
1277}
1278
1279static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1280 struct xgbe_ring_desc *rdesc)
1281{
1282 u64 nsec;
1283
1284 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1285 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1286 nsec = le32_to_cpu(rdesc->desc1);
1287 nsec <<= 32;
1288 nsec |= le32_to_cpu(rdesc->desc0);
1289 if (nsec != 0xffffffffffffffffULL) {
1290 packet->rx_tstamp = nsec;
1291 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1292 RX_TSTAMP, 1);
1293 }
1294 }
1295}
1296
1297static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1298 unsigned int mac_tscr)
1299{
1300 /* Set one nano-second accuracy */
1301 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1302
1303 /* Set fine timestamp update */
1304 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1305
1306 /* Overwrite earlier timestamps */
1307 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1308
1309 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1310
1311 /* Exit if timestamping is not enabled */
1312 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1313 return 0;
1314
1315 /* Initialize time registers */
1316 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1317 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1318 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1319 xgbe_set_tstamp_time(pdata, 0, 0);
1320
1321 /* Initialize the timecounter */
1322 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1323 ktime_to_ns(ktime_get_real()));
1324
1325 return 0;
1326}
1327
Lendacky, Thomasb3b71592016-02-17 11:49:08 -06001328static void xgbe_config_tc(struct xgbe_prv_data *pdata)
1329{
1330 unsigned int offset, queue, prio;
1331 u8 i;
1332
1333 netdev_reset_tc(pdata->netdev);
1334 if (!pdata->num_tcs)
1335 return;
1336
1337 netdev_set_num_tc(pdata->netdev, pdata->num_tcs);
1338
1339 for (i = 0, queue = 0, offset = 0; i < pdata->num_tcs; i++) {
1340 while ((queue < pdata->tx_q_count) &&
1341 (pdata->q2tc_map[queue] == i))
1342 queue++;
1343
1344 netif_dbg(pdata, drv, pdata->netdev, "TC%u using TXq%u-%u\n",
1345 i, offset, queue - 1);
1346 netdev_set_tc_queue(pdata->netdev, i, queue - offset, offset);
1347 offset = queue;
1348 }
1349
1350 if (!pdata->ets)
1351 return;
1352
1353 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++)
1354 netdev_set_prio_tc_map(pdata->netdev, prio,
1355 pdata->ets->prio_tc[prio]);
1356}
1357
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001358static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
1359{
1360 struct ieee_ets *ets = pdata->ets;
1361 unsigned int total_weight, min_weight, weight;
Lendacky, Thomas6a49ee42016-02-17 11:48:57 -06001362 unsigned int mask, reg, reg_val;
1363 unsigned int i, prio;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001364
1365 if (!ets)
1366 return;
1367
1368 /* Set Tx to deficit weighted round robin scheduling algorithm (when
1369 * traffic class is using ETS algorithm)
1370 */
1371 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
1372
1373 /* Set Traffic Class algorithms */
1374 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
1375 min_weight = total_weight / 100;
1376 if (!min_weight)
1377 min_weight = 1;
1378
1379 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
Lendacky, Thomas6a49ee42016-02-17 11:48:57 -06001380 /* Map the priorities to the traffic class */
1381 mask = 0;
1382 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
1383 if (ets->prio_tc[prio] == i)
1384 mask |= (1 << prio);
1385 }
1386 mask &= 0xff;
1387
1388 netif_dbg(pdata, drv, pdata->netdev, "TC%u PRIO mask=%#x\n",
1389 i, mask);
1390 reg = MTL_TCPM0R + (MTL_TCPM_INC * (i / MTL_TCPM_TC_PER_REG));
1391 reg_val = XGMAC_IOREAD(pdata, reg);
1392
1393 reg_val &= ~(0xff << ((i % MTL_TCPM_TC_PER_REG) << 3));
1394 reg_val |= (mask << ((i % MTL_TCPM_TC_PER_REG) << 3));
1395
1396 XGMAC_IOWRITE(pdata, reg, reg_val);
1397
1398 /* Set the traffic class algorithm */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001399 switch (ets->tc_tsa[i]) {
1400 case IEEE_8021QAZ_TSA_STRICT:
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001401 netif_dbg(pdata, drv, pdata->netdev,
1402 "TC%u using SP\n", i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001403 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1404 MTL_TSA_SP);
1405 break;
1406 case IEEE_8021QAZ_TSA_ETS:
1407 weight = total_weight * ets->tc_tx_bw[i] / 100;
1408 weight = clamp(weight, min_weight, total_weight);
1409
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001410 netif_dbg(pdata, drv, pdata->netdev,
1411 "TC%u using DWRR (weight %u)\n", i, weight);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001412 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1413 MTL_TSA_ETS);
1414 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
1415 weight);
1416 break;
1417 }
1418 }
Lendacky, Thomasb3b71592016-02-17 11:49:08 -06001419
1420 xgbe_config_tc(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001421}
1422
1423static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
1424{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001425 xgbe_config_flow_control(pdata);
1426}
1427
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001428static void xgbe_tx_start_xmit(struct xgbe_channel *channel,
1429 struct xgbe_ring *ring)
1430{
1431 struct xgbe_prv_data *pdata = channel->pdata;
1432 struct xgbe_ring_data *rdata;
1433
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001434 /* Make sure everything is written before the register write */
1435 wmb();
1436
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001437 /* Issue a poll command to Tx DMA by writing address
1438 * of next immediate free descriptor */
1439 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1440 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1441 lower_32_bits(rdata->rdesc_dma));
1442
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -05001443 /* Start the Tx timer */
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001444 if (pdata->tx_usecs && !channel->tx_timer_active) {
1445 channel->tx_timer_active = 1;
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -05001446 mod_timer(&channel->tx_timer,
1447 jiffies + usecs_to_jiffies(pdata->tx_usecs));
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001448 }
1449
1450 ring->tx.xmit_more = 0;
1451}
1452
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001453static void xgbe_dev_xmit(struct xgbe_channel *channel)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001454{
1455 struct xgbe_prv_data *pdata = channel->pdata;
1456 struct xgbe_ring *ring = channel->tx_ring;
1457 struct xgbe_ring_data *rdata;
1458 struct xgbe_ring_desc *rdesc;
1459 struct xgbe_packet_data *packet = &ring->packet_data;
1460 unsigned int csum, tso, vlan;
1461 unsigned int tso_context, vlan_context;
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001462 unsigned int tx_set_ic;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001463 int start_index = ring->cur;
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001464 int cur_index = ring->cur;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001465 int i;
1466
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001467 DBGPR("-->xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001468
1469 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1470 CSUM_ENABLE);
1471 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1472 TSO_ENABLE);
1473 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1474 VLAN_CTAG);
1475
1476 if (tso && (packet->mss != ring->tx.cur_mss))
1477 tso_context = 1;
1478 else
1479 tso_context = 0;
1480
1481 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1482 vlan_context = 1;
1483 else
1484 vlan_context = 0;
1485
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001486 /* Determine if an interrupt should be generated for this Tx:
1487 * Interrupt:
1488 * - Tx frame count exceeds the frame count setting
1489 * - Addition of Tx frame count to the frame count since the
1490 * last interrupt was set exceeds the frame count setting
1491 * No interrupt:
1492 * - No frame count setting specified (ethtool -C ethX tx-frames 0)
1493 * - Addition of Tx frame count to the frame count since the
1494 * last interrupt was set does not exceed the frame count setting
1495 */
1496 ring->coalesce_count += packet->tx_packets;
1497 if (!pdata->tx_frames)
1498 tx_set_ic = 0;
1499 else if (packet->tx_packets > pdata->tx_frames)
1500 tx_set_ic = 1;
1501 else if ((ring->coalesce_count % pdata->tx_frames) <
1502 packet->tx_packets)
1503 tx_set_ic = 1;
1504 else
1505 tx_set_ic = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001506
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001507 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001508 rdesc = rdata->rdesc;
1509
1510 /* Create a context descriptor if this is a TSO packet */
1511 if (tso_context || vlan_context) {
1512 if (tso_context) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001513 netif_dbg(pdata, tx_queued, pdata->netdev,
1514 "TSO context descriptor, mss=%u\n",
1515 packet->mss);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001516
1517 /* Set the MSS size */
1518 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1519 MSS, packet->mss);
1520
1521 /* Mark it as a CONTEXT descriptor */
1522 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1523 CTXT, 1);
1524
1525 /* Indicate this descriptor contains the MSS */
1526 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1527 TCMSSV, 1);
1528
1529 ring->tx.cur_mss = packet->mss;
1530 }
1531
1532 if (vlan_context) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001533 netif_dbg(pdata, tx_queued, pdata->netdev,
1534 "VLAN context descriptor, ctag=%u\n",
1535 packet->vlan_ctag);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001536
1537 /* Mark it as a CONTEXT descriptor */
1538 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1539 CTXT, 1);
1540
1541 /* Set the VLAN tag */
1542 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1543 VT, packet->vlan_ctag);
1544
1545 /* Indicate this descriptor contains the VLAN tag */
1546 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1547 VLTV, 1);
1548
1549 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1550 }
1551
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001552 cur_index++;
1553 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001554 rdesc = rdata->rdesc;
1555 }
1556
1557 /* Update buffer address (for TSO this is the header) */
1558 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1559 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1560
1561 /* Update the buffer length */
1562 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1563 rdata->skb_dma_len);
1564
1565 /* VLAN tag insertion check */
1566 if (vlan)
1567 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1568 TX_NORMAL_DESC2_VLAN_INSERT);
1569
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001570 /* Timestamp enablement check */
1571 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1572 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1573
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001574 /* Mark it as First Descriptor */
1575 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1576
1577 /* Mark it as a NORMAL descriptor */
1578 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1579
1580 /* Set OWN bit if not the first descriptor */
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001581 if (cur_index != start_index)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001582 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1583
1584 if (tso) {
1585 /* Enable TSO */
1586 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1587 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1588 packet->tcp_payload_len);
1589 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1590 packet->tcp_header_len / 4);
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001591
1592 pdata->ext_stats.tx_tso_packets++;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001593 } else {
1594 /* Enable CRC and Pad Insertion */
1595 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1596
1597 /* Enable HW CSUM */
1598 if (csum)
1599 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1600 CIC, 0x3);
1601
1602 /* Set the total length to be transmitted */
1603 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1604 packet->length);
1605 }
1606
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001607 for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) {
1608 cur_index++;
1609 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001610 rdesc = rdata->rdesc;
1611
1612 /* Update buffer address */
1613 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1614 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1615
1616 /* Update the buffer length */
1617 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1618 rdata->skb_dma_len);
1619
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001620 /* Set OWN bit */
1621 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1622
1623 /* Mark it as NORMAL descriptor */
1624 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1625
1626 /* Enable HW CSUM */
1627 if (csum)
1628 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1629 CIC, 0x3);
1630 }
1631
1632 /* Set LAST bit for the last descriptor */
1633 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1634
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001635 /* Set IC bit based on Tx coalescing settings */
1636 if (tx_set_ic)
1637 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1638
Lendacky, Thomas5fb4b862014-11-20 11:03:50 -06001639 /* Save the Tx info to report back during cleanup */
1640 rdata->tx.packets = packet->tx_packets;
1641 rdata->tx.bytes = packet->tx_bytes;
1642
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001643 /* In case the Tx DMA engine is running, make sure everything
1644 * is written to the descriptor(s) before setting the OWN bit
1645 * for the first descriptor
1646 */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001647 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001648
1649 /* Set OWN bit for the first descriptor */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001650 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001651 rdesc = rdata->rdesc;
1652 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1653
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001654 if (netif_msg_tx_queued(pdata))
1655 xgbe_dump_tx_desc(pdata, ring, start_index,
1656 packet->rdesc_count, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001657
1658 /* Make sure ownership is written to the descriptor */
Lendacky, Thomas20986ed2015-10-26 17:13:54 -05001659 smp_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001660
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001661 ring->cur = cur_index + 1;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001662 if (!packet->skb->xmit_more ||
1663 netif_xmit_stopped(netdev_get_tx_queue(pdata->netdev,
1664 channel->queue_index)))
1665 xgbe_tx_start_xmit(channel, ring);
1666 else
1667 ring->tx.xmit_more = 1;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001668
1669 DBGPR(" %s: descriptors %u to %u written\n",
1670 channel->name, start_index & (ring->rdesc_count - 1),
1671 (ring->cur - 1) & (ring->rdesc_count - 1));
1672
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001673 DBGPR("<--xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001674}
1675
1676static int xgbe_dev_read(struct xgbe_channel *channel)
1677{
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001678 struct xgbe_prv_data *pdata = channel->pdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001679 struct xgbe_ring *ring = channel->rx_ring;
1680 struct xgbe_ring_data *rdata;
1681 struct xgbe_ring_desc *rdesc;
1682 struct xgbe_packet_data *packet = &ring->packet_data;
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001683 struct net_device *netdev = pdata->netdev;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001684 unsigned int err, etlt, l34t;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001685
1686 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1687
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001688 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001689 rdesc = rdata->rdesc;
1690
1691 /* Check for data availability */
1692 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1693 return 1;
1694
Lendacky, Thomas5449e272014-11-20 11:03:26 -06001695 /* Make sure descriptor fields are read after reading the OWN bit */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001696 dma_rmb();
Lendacky, Thomas5449e272014-11-20 11:03:26 -06001697
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001698 if (netif_msg_rx_status(pdata))
1699 xgbe_dump_rx_desc(pdata, ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001700
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001701 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1702 /* Timestamp Context Descriptor */
1703 xgbe_get_rx_tstamp(packet, rdesc);
1704
1705 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1706 CONTEXT, 1);
1707 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1708 CONTEXT_NEXT, 0);
1709 return 0;
1710 }
1711
1712 /* Normal Descriptor, be sure Context Descriptor bit is off */
1713 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1714
1715 /* Indicate if a Context Descriptor is next */
1716 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1717 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1718 CONTEXT_NEXT, 1);
1719
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001720 /* Get the header length */
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001721 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD)) {
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001722 rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2,
1723 RX_NORMAL_DESC2, HL);
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001724 if (rdata->rx.hdr_len)
1725 pdata->ext_stats.rx_split_header_packets++;
1726 }
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001727
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001728 /* Get the RSS hash */
1729 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, RSV)) {
1730 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1731 RSS_HASH, 1);
1732
1733 packet->rss_hash = le32_to_cpu(rdesc->desc1);
1734
1735 l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T);
1736 switch (l34t) {
1737 case RX_DESC3_L34T_IPV4_TCP:
1738 case RX_DESC3_L34T_IPV4_UDP:
1739 case RX_DESC3_L34T_IPV6_TCP:
1740 case RX_DESC3_L34T_IPV6_UDP:
1741 packet->rss_hash_type = PKT_HASH_TYPE_L4;
Dan Carpenterb6267d32014-11-13 09:19:06 +03001742 break;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001743 default:
1744 packet->rss_hash_type = PKT_HASH_TYPE_L3;
1745 }
1746 }
1747
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001748 /* Get the packet length */
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001749 rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001750
1751 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1752 /* Not all the data has been transferred for this packet */
1753 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1754 INCOMPLETE, 1);
1755 return 0;
1756 }
1757
1758 /* This is the last of the data for this packet */
1759 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1760 INCOMPLETE, 0);
1761
1762 /* Set checksum done indicator as appropriate */
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001763 if (netdev->features & NETIF_F_RXCSUM)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001764 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1765 CSUM_DONE, 1);
1766
1767 /* Check for errors (only valid in last descriptor) */
1768 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1769 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001770 netif_dbg(pdata, rx_status, netdev, "err=%u, etlt=%#x\n", err, etlt);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001771
Lendacky, Thomas7bba35b2014-11-20 11:03:38 -06001772 if (!err || !etlt) {
1773 /* No error if err is 0 or etlt is 0 */
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001774 if ((etlt == 0x09) &&
1775 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001776 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1777 VLAN_CTAG, 1);
1778 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1779 RX_NORMAL_DESC0,
1780 OVT);
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001781 netif_dbg(pdata, rx_status, netdev, "vlan-ctag=%#06x\n",
1782 packet->vlan_ctag);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001783 }
1784 } else {
1785 if ((etlt == 0x05) || (etlt == 0x06))
1786 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1787 CSUM_DONE, 0);
1788 else
1789 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1790 FRAME, 1);
1791 }
1792
1793 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1794 ring->cur & (ring->rdesc_count - 1), ring->cur);
1795
1796 return 0;
1797}
1798
1799static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1800{
1801 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1802 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1803}
1804
1805static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1806{
1807 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1808 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1809}
1810
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001811static int xgbe_enable_int(struct xgbe_channel *channel,
1812 enum xgbe_int int_id)
1813{
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001814 unsigned int dma_ch_ier;
1815
1816 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1817
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001818 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001819 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001820 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001821 break;
1822 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001823 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001824 break;
1825 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001826 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001827 break;
1828 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001829 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001830 break;
1831 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001832 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001833 break;
1834 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001835 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1836 break;
1837 case XGMAC_INT_DMA_CH_SR_TI_RI:
1838 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1839 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001840 break;
1841 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001842 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001843 break;
1844 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001845 dma_ch_ier |= channel->saved_ier;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001846 break;
1847 default:
1848 return -1;
1849 }
1850
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001851 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1852
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001853 return 0;
1854}
1855
1856static int xgbe_disable_int(struct xgbe_channel *channel,
1857 enum xgbe_int int_id)
1858{
1859 unsigned int dma_ch_ier;
1860
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001861 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1862
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001863 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001864 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001865 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001866 break;
1867 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001868 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001869 break;
1870 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001871 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001872 break;
1873 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001874 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001875 break;
1876 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001877 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001878 break;
1879 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001880 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1881 break;
1882 case XGMAC_INT_DMA_CH_SR_TI_RI:
1883 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1884 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001885 break;
1886 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001887 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001888 break;
1889 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001890 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001891 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001892 break;
1893 default:
1894 return -1;
1895 }
1896
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001897 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1898
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001899 return 0;
1900}
1901
1902static int xgbe_exit(struct xgbe_prv_data *pdata)
1903{
1904 unsigned int count = 2000;
1905
1906 DBGPR("-->xgbe_exit\n");
1907
1908 /* Issue a software reset */
1909 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1910 usleep_range(10, 15);
1911
1912 /* Poll Until Poll Condition */
Dan Carpenterc7557e62015-12-15 13:12:29 +03001913 while (--count && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001914 usleep_range(500, 600);
1915
1916 if (!count)
1917 return -EBUSY;
1918
1919 DBGPR("<--xgbe_exit\n");
1920
1921 return 0;
1922}
1923
1924static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1925{
1926 unsigned int i, count;
1927
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -05001928 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
1929 return 0;
1930
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001931 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001932 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1933
1934 /* Poll Until Poll Condition */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001935 for (i = 0; i < pdata->tx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001936 count = 2000;
Dan Carpenterc7557e62015-12-15 13:12:29 +03001937 while (--count && XGMAC_MTL_IOREAD_BITS(pdata, i,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001938 MTL_Q_TQOMR, FTQ))
1939 usleep_range(500, 600);
1940
1941 if (!count)
1942 return -EBUSY;
1943 }
1944
1945 return 0;
1946}
1947
1948static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1949{
1950 /* Set enhanced addressing mode */
1951 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1952
1953 /* Set the System Bus mode */
1954 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001955 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001956}
1957
1958static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1959{
1960 unsigned int arcache, awcache;
1961
1962 arcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001963 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
1964 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
1965 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
1966 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
1967 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
1968 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001969 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1970
1971 awcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001972 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
1973 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
1974 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
1975 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
1976 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
1977 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
1978 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
1979 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001980 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1981}
1982
1983static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1984{
1985 unsigned int i;
1986
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001987 /* Set Tx to weighted round robin scheduling algorithm */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001988 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1989
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001990 /* Set Tx traffic classes to use WRR algorithm with equal weights */
1991 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1992 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1993 MTL_TSA_ETS);
1994 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
1995 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001996
1997 /* Set Rx to strict priority algorithm */
1998 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1999}
2000
Lendacky, Thomasf076f452014-08-29 13:16:56 -05002001static unsigned int xgbe_calculate_per_queue_fifo(unsigned int fifo_size,
2002 unsigned int queue_count)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002003{
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002004 unsigned int q_fifo_size;
2005 unsigned int p_fifo;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002006
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002007 /* Calculate the configured fifo size */
2008 q_fifo_size = 1 << (fifo_size + 7);
Lendacky, Thomasf076f452014-08-29 13:16:56 -05002009
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002010 /* The configured value may not be the actual amount of fifo RAM */
Lendacky, Thomasf076f452014-08-29 13:16:56 -05002011 q_fifo_size = min_t(unsigned int, XGBE_FIFO_MAX, q_fifo_size);
2012
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002013 q_fifo_size = q_fifo_size / queue_count;
2014
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002015 /* Each increment in the queue fifo size represents 256 bytes of
2016 * fifo, with 0 representing 256 bytes. Distribute the fifo equally
2017 * between the queues.
2018 */
2019 p_fifo = q_fifo_size / 256;
2020 if (p_fifo)
2021 p_fifo--;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002022
2023 return p_fifo;
2024}
2025
2026static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
2027{
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002028 unsigned int fifo_size;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002029 unsigned int i;
2030
2031 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002032 pdata->tx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002033
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002034 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002035 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
2036
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002037 netif_info(pdata, drv, pdata->netdev,
2038 "%d Tx hardware queues, %d byte fifo per queue\n",
2039 pdata->tx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002040}
2041
2042static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
2043{
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002044 unsigned int fifo_size;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002045 unsigned int i;
2046
2047 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002048 pdata->rx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002049
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002050 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002051 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
2052
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002053 netif_info(pdata, drv, pdata->netdev,
2054 "%d Rx hardware queues, %d byte fifo per queue\n",
2055 pdata->rx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002056}
2057
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002058static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002059{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002060 unsigned int qptc, qptc_extra, queue;
2061 unsigned int prio_queues;
2062 unsigned int ppq, ppq_extra, prio;
2063 unsigned int mask;
2064 unsigned int i, j, reg, reg_val;
2065
2066 /* Map the MTL Tx Queues to Traffic Classes
2067 * Note: Tx Queues >= Traffic Classes
2068 */
2069 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
2070 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
2071
2072 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
2073 for (j = 0; j < qptc; j++) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002074 netif_dbg(pdata, drv, pdata->netdev,
2075 "TXq%u mapped to TC%u\n", queue, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002076 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2077 Q2TCMAP, i);
2078 pdata->q2tc_map[queue++] = i;
2079 }
2080
2081 if (i < qptc_extra) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002082 netif_dbg(pdata, drv, pdata->netdev,
2083 "TXq%u mapped to TC%u\n", queue, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002084 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2085 Q2TCMAP, i);
2086 pdata->q2tc_map[queue++] = i;
2087 }
2088 }
2089
2090 /* Map the 8 VLAN priority values to available MTL Rx queues */
2091 prio_queues = min_t(unsigned int, IEEE_8021QAZ_MAX_TCS,
2092 pdata->rx_q_count);
2093 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
2094 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
2095
2096 reg = MAC_RQC2R;
2097 reg_val = 0;
2098 for (i = 0, prio = 0; i < prio_queues;) {
2099 mask = 0;
2100 for (j = 0; j < ppq; j++) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002101 netif_dbg(pdata, drv, pdata->netdev,
2102 "PRIO%u mapped to RXq%u\n", prio, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002103 mask |= (1 << prio);
2104 pdata->prio2q_map[prio++] = i;
2105 }
2106
2107 if (i < ppq_extra) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002108 netif_dbg(pdata, drv, pdata->netdev,
2109 "PRIO%u mapped to RXq%u\n", prio, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002110 mask |= (1 << prio);
2111 pdata->prio2q_map[prio++] = i;
2112 }
2113
2114 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
2115
2116 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
2117 continue;
2118
2119 XGMAC_IOWRITE(pdata, reg, reg_val);
2120 reg += MAC_RQC2_INC;
2121 reg_val = 0;
2122 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002123
2124 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
2125 reg = MTL_RQDCM0R;
2126 reg_val = 0;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002127 for (i = 0; i < pdata->rx_q_count;) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002128 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
2129
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002130 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002131 continue;
2132
2133 XGMAC_IOWRITE(pdata, reg, reg_val);
2134
2135 reg += MTL_RQDCM_INC;
2136 reg_val = 0;
2137 }
2138}
2139
2140static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
2141{
2142 unsigned int i;
2143
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002144 for (i = 0; i < pdata->rx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002145 /* Activate flow control when less than 4k left in fifo */
Lendacky, Thomase2a27292015-01-20 12:20:31 -06002146 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFA, 2);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002147
2148 /* De-activate flow control when more than 6k left in fifo */
Lendacky, Thomase2a27292015-01-20 12:20:31 -06002149 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFD, 4);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002150 }
2151}
2152
2153static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
2154{
2155 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05002156
2157 /* Filtering is done using perfect filtering and hash filtering */
2158 if (pdata->hw_feat.hash_table_size) {
2159 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
2160 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
2161 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
2162 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002163}
2164
2165static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
2166{
2167 unsigned int val;
2168
2169 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
2170
2171 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
2172}
2173
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002174static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata)
2175{
2176 switch (pdata->phy_speed) {
2177 case SPEED_10000:
2178 xgbe_set_xgmii_speed(pdata);
2179 break;
2180
2181 case SPEED_2500:
2182 xgbe_set_gmii_2500_speed(pdata);
2183 break;
2184
2185 case SPEED_1000:
2186 xgbe_set_gmii_speed(pdata);
2187 break;
2188 }
2189}
2190
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002191static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
2192{
2193 if (pdata->netdev->features & NETIF_F_RXCSUM)
2194 xgbe_enable_rx_csum(pdata);
2195 else
2196 xgbe_disable_rx_csum(pdata);
2197}
2198
2199static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
2200{
Lendacky, Thomas6e5eed02014-06-24 16:19:12 -05002201 /* Indicate that VLAN Tx CTAGs come from context descriptors */
2202 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
2203 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
2204
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002205 /* Set the current VLAN Hash Table register value */
2206 xgbe_update_vlan_hash_table(pdata);
2207
2208 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
2209 xgbe_enable_rx_vlan_filtering(pdata);
2210 else
2211 xgbe_disable_rx_vlan_filtering(pdata);
2212
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002213 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2214 xgbe_enable_rx_vlan_stripping(pdata);
2215 else
2216 xgbe_disable_rx_vlan_stripping(pdata);
2217}
2218
Lendacky, Thomas60265102014-09-05 18:02:30 -05002219static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
2220{
2221 bool read_hi;
2222 u64 val;
2223
2224 switch (reg_lo) {
2225 /* These registers are always 64 bit */
2226 case MMC_TXOCTETCOUNT_GB_LO:
2227 case MMC_TXOCTETCOUNT_G_LO:
2228 case MMC_RXOCTETCOUNT_GB_LO:
2229 case MMC_RXOCTETCOUNT_G_LO:
2230 read_hi = true;
2231 break;
2232
2233 default:
2234 read_hi = false;
Lendacky, Thomas3947d782015-09-30 08:52:38 -05002235 }
Lendacky, Thomas60265102014-09-05 18:02:30 -05002236
2237 val = XGMAC_IOREAD(pdata, reg_lo);
2238
2239 if (read_hi)
2240 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
2241
2242 return val;
2243}
2244
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002245static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
2246{
2247 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2248 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
2249
2250 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
2251 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002252 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002253
2254 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
2255 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002256 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002257
2258 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
2259 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002260 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002261
2262 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
2263 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002264 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002265
2266 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
2267 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002268 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002269
2270 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
2271 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002272 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002273
2274 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
2275 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002276 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002277
2278 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
2279 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002280 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002281
2282 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
2283 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002284 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002285
2286 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
2287 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002288 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002289
2290 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
2291 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002292 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002293
2294 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2295 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002296 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002297
2298 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2299 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002300 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002301
2302 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2303 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002304 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002305
2306 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2307 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002308 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002309
2310 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2311 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002312 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002313
2314 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2315 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002316 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002317
2318 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2319 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002320 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002321}
2322
2323static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2324{
2325 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2326 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2327
2328 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2329 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002330 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002331
2332 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2333 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002334 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002335
2336 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2337 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002338 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002339
2340 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2341 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002342 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002343
2344 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2345 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002346 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002347
2348 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2349 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002350 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002351
2352 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2353 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002354 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002355
2356 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2357 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002358 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002359
2360 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
2361 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002362 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002363
2364 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
2365 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002366 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002367
2368 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
2369 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002370 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002371
2372 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
2373 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002374 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002375
2376 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
2377 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002378 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002379
2380 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
2381 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002382 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002383
2384 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
2385 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002386 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002387
2388 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
2389 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002390 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002391
2392 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
2393 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002394 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002395
2396 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
2397 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002398 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002399
2400 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
2401 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002402 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002403
2404 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
2405 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002406 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002407
2408 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
2409 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002410 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002411
2412 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
2413 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002414 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002415
2416 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
2417 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002418 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002419}
2420
2421static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
2422{
2423 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2424
2425 /* Freeze counters */
2426 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
2427
2428 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002429 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002430
2431 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002432 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002433
2434 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002435 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002436
2437 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002438 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002439
2440 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002441 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002442
2443 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002444 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002445
2446 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002447 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002448
2449 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002450 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002451
2452 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002453 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002454
2455 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002456 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002457
2458 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002459 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002460
2461 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002462 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002463
2464 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002465 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002466
2467 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002468 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002469
2470 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002471 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002472
2473 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002474 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002475
2476 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002477 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002478
2479 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002480 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002481
2482 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002483 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002484
2485 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002486 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002487
2488 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002489 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002490
2491 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002492 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002493
2494 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002495 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002496
2497 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002498 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002499
2500 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002501 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002502
2503 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002504 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002505
2506 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002507 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002508
2509 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002510 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002511
2512 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002513 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002514
2515 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002516 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002517
2518 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002519 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002520
2521 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002522 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002523
2524 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002525 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002526
2527 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002528 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002529
2530 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002531 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002532
2533 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002534 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002535
2536 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002537 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002538
2539 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002540 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002541
2542 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002543 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002544
2545 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002546 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002547
2548 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002549 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002550
2551 /* Un-freeze counters */
2552 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
2553}
2554
2555static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
2556{
2557 /* Set counters to reset on read */
2558 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
2559
2560 /* Reset the counters */
2561 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
2562}
2563
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002564static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
2565 struct xgbe_channel *channel)
2566{
2567 unsigned int tx_dsr, tx_pos, tx_qidx;
2568 unsigned int tx_status;
2569 unsigned long tx_timeout;
2570
2571 /* Calculate the status register to read and the position within */
2572 if (channel->queue_index < DMA_DSRX_FIRST_QUEUE) {
2573 tx_dsr = DMA_DSR0;
2574 tx_pos = (channel->queue_index * DMA_DSR_Q_WIDTH) +
2575 DMA_DSR0_TPS_START;
2576 } else {
2577 tx_qidx = channel->queue_index - DMA_DSRX_FIRST_QUEUE;
2578
2579 tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
2580 tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
2581 DMA_DSRX_TPS_START;
2582 }
2583
2584 /* The Tx engine cannot be stopped if it is actively processing
2585 * descriptors. Wait for the Tx engine to enter the stopped or
2586 * suspended state. Don't wait forever though...
2587 */
2588 tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
2589 while (time_before(jiffies, tx_timeout)) {
2590 tx_status = XGMAC_IOREAD(pdata, tx_dsr);
2591 tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
2592 if ((tx_status == DMA_TPS_STOPPED) ||
2593 (tx_status == DMA_TPS_SUSPENDED))
2594 break;
2595
2596 usleep_range(500, 1000);
2597 }
2598
2599 if (!time_before(jiffies, tx_timeout))
2600 netdev_info(pdata->netdev,
2601 "timed out waiting for Tx DMA channel %u to stop\n",
2602 channel->queue_index);
2603}
2604
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002605static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
2606{
2607 struct xgbe_channel *channel;
2608 unsigned int i;
2609
2610 /* Enable each Tx DMA channel */
2611 channel = pdata->channel;
2612 for (i = 0; i < pdata->channel_count; i++, channel++) {
2613 if (!channel->tx_ring)
2614 break;
2615
2616 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2617 }
2618
2619 /* Enable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002620 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002621 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
2622 MTL_Q_ENABLED);
2623
2624 /* Enable MAC Tx */
2625 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2626}
2627
2628static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
2629{
2630 struct xgbe_channel *channel;
2631 unsigned int i;
2632
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002633 /* Prepare for Tx DMA channel stop */
2634 channel = pdata->channel;
2635 for (i = 0; i < pdata->channel_count; i++, channel++) {
2636 if (!channel->tx_ring)
2637 break;
2638
2639 xgbe_prepare_tx_stop(pdata, channel);
2640 }
2641
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002642 /* Disable MAC Tx */
2643 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2644
2645 /* Disable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002646 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002647 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
2648
2649 /* Disable each Tx DMA channel */
2650 channel = pdata->channel;
2651 for (i = 0; i < pdata->channel_count; i++, channel++) {
2652 if (!channel->tx_ring)
2653 break;
2654
2655 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2656 }
2657}
2658
Lendacky, Thomasc3727d62016-02-17 11:49:16 -06002659static void xgbe_prepare_rx_stop(struct xgbe_prv_data *pdata,
2660 unsigned int queue)
2661{
2662 unsigned int rx_status;
2663 unsigned long rx_timeout;
2664
2665 /* The Rx engine cannot be stopped if it is actively processing
2666 * packets. Wait for the Rx queue to empty the Rx fifo. Don't
2667 * wait forever though...
2668 */
2669 rx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
2670 while (time_before(jiffies, rx_timeout)) {
2671 rx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR);
2672 if ((XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) &&
2673 (XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0))
2674 break;
2675
2676 usleep_range(500, 1000);
2677 }
2678
2679 if (!time_before(jiffies, rx_timeout))
2680 netdev_info(pdata->netdev,
2681 "timed out waiting for Rx queue %u to empty\n",
2682 queue);
2683}
2684
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002685static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
2686{
2687 struct xgbe_channel *channel;
2688 unsigned int reg_val, i;
2689
2690 /* Enable each Rx DMA channel */
2691 channel = pdata->channel;
2692 for (i = 0; i < pdata->channel_count; i++, channel++) {
2693 if (!channel->rx_ring)
2694 break;
2695
2696 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2697 }
2698
2699 /* Enable each Rx queue */
2700 reg_val = 0;
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002701 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002702 reg_val |= (0x02 << (i << 1));
2703 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
2704
2705 /* Enable MAC Rx */
2706 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
2707 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
2708 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
2709 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
2710}
2711
2712static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
2713{
2714 struct xgbe_channel *channel;
2715 unsigned int i;
2716
2717 /* Disable MAC Rx */
2718 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
2719 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
2720 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
2721 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
2722
Lendacky, Thomasc3727d62016-02-17 11:49:16 -06002723 /* Prepare for Rx DMA channel stop */
2724 for (i = 0; i < pdata->rx_q_count; i++)
2725 xgbe_prepare_rx_stop(pdata, i);
2726
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002727 /* Disable each Rx queue */
2728 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
2729
2730 /* Disable each Rx DMA channel */
2731 channel = pdata->channel;
2732 for (i = 0; i < pdata->channel_count; i++, channel++) {
2733 if (!channel->rx_ring)
2734 break;
2735
2736 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2737 }
2738}
2739
2740static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
2741{
2742 struct xgbe_channel *channel;
2743 unsigned int i;
2744
2745 /* Enable each Tx DMA channel */
2746 channel = pdata->channel;
2747 for (i = 0; i < pdata->channel_count; i++, channel++) {
2748 if (!channel->tx_ring)
2749 break;
2750
2751 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2752 }
2753
2754 /* Enable MAC Tx */
2755 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2756}
2757
2758static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
2759{
2760 struct xgbe_channel *channel;
2761 unsigned int i;
2762
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002763 /* Prepare for Tx DMA channel stop */
2764 channel = pdata->channel;
2765 for (i = 0; i < pdata->channel_count; i++, channel++) {
2766 if (!channel->tx_ring)
2767 break;
2768
2769 xgbe_prepare_tx_stop(pdata, channel);
2770 }
2771
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002772 /* Disable MAC Tx */
2773 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2774
2775 /* Disable each Tx DMA channel */
2776 channel = pdata->channel;
2777 for (i = 0; i < pdata->channel_count; i++, channel++) {
2778 if (!channel->tx_ring)
2779 break;
2780
2781 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2782 }
2783}
2784
2785static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2786{
2787 struct xgbe_channel *channel;
2788 unsigned int i;
2789
2790 /* Enable each Rx DMA channel */
2791 channel = pdata->channel;
2792 for (i = 0; i < pdata->channel_count; i++, channel++) {
2793 if (!channel->rx_ring)
2794 break;
2795
2796 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2797 }
2798}
2799
2800static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2801{
2802 struct xgbe_channel *channel;
2803 unsigned int i;
2804
2805 /* Disable each Rx DMA channel */
2806 channel = pdata->channel;
2807 for (i = 0; i < pdata->channel_count; i++, channel++) {
2808 if (!channel->rx_ring)
2809 break;
2810
2811 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2812 }
2813}
2814
2815static int xgbe_init(struct xgbe_prv_data *pdata)
2816{
2817 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2818 int ret;
2819
2820 DBGPR("-->xgbe_init\n");
2821
2822 /* Flush Tx queues */
2823 ret = xgbe_flush_tx_queues(pdata);
2824 if (ret)
2825 return ret;
2826
2827 /*
2828 * Initialize DMA related features
2829 */
2830 xgbe_config_dma_bus(pdata);
2831 xgbe_config_dma_cache(pdata);
2832 xgbe_config_osp_mode(pdata);
2833 xgbe_config_pblx8(pdata);
2834 xgbe_config_tx_pbl_val(pdata);
2835 xgbe_config_rx_pbl_val(pdata);
2836 xgbe_config_rx_coalesce(pdata);
2837 xgbe_config_tx_coalesce(pdata);
2838 xgbe_config_rx_buffer_size(pdata);
2839 xgbe_config_tso_mode(pdata);
Lendacky, Thomas174fd252014-11-04 16:06:50 -06002840 xgbe_config_sph_mode(pdata);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06002841 xgbe_config_rss(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002842 desc_if->wrapper_tx_desc_init(pdata);
2843 desc_if->wrapper_rx_desc_init(pdata);
2844 xgbe_enable_dma_interrupts(pdata);
2845
2846 /*
2847 * Initialize MTL related features
2848 */
2849 xgbe_config_mtl_mode(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002850 xgbe_config_queue_mapping(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002851 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2852 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2853 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2854 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2855 xgbe_config_tx_fifo_size(pdata);
2856 xgbe_config_rx_fifo_size(pdata);
2857 xgbe_config_flow_control_threshold(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002858 /*TODO: Error Packet and undersized good Packet forwarding enable
2859 (FEP and FUP)
2860 */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002861 xgbe_config_dcb_tc(pdata);
2862 xgbe_config_dcb_pfc(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002863 xgbe_enable_mtl_interrupts(pdata);
2864
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002865 /*
2866 * Initialize MAC related features
2867 */
2868 xgbe_config_mac_address(pdata);
Lendacky, Thomasb8763822015-04-09 12:11:57 -05002869 xgbe_config_rx_mode(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002870 xgbe_config_jumbo_enable(pdata);
2871 xgbe_config_flow_control(pdata);
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002872 xgbe_config_mac_speed(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002873 xgbe_config_checksum_offload(pdata);
2874 xgbe_config_vlan_support(pdata);
2875 xgbe_config_mmc(pdata);
2876 xgbe_enable_mac_interrupts(pdata);
2877
2878 DBGPR("<--xgbe_init\n");
2879
2880 return 0;
2881}
2882
2883void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2884{
2885 DBGPR("-->xgbe_init_function_ptrs\n");
2886
2887 hw_if->tx_complete = xgbe_tx_complete;
2888
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002889 hw_if->set_mac_address = xgbe_set_mac_address;
Lendacky, Thomasb8763822015-04-09 12:11:57 -05002890 hw_if->config_rx_mode = xgbe_config_rx_mode;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002891
2892 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2893 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2894
2895 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2896 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002897 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
2898 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
2899 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002900
2901 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2902 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2903
2904 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2905 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2906 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2907
2908 hw_if->enable_tx = xgbe_enable_tx;
2909 hw_if->disable_tx = xgbe_disable_tx;
2910 hw_if->enable_rx = xgbe_enable_rx;
2911 hw_if->disable_rx = xgbe_disable_rx;
2912
2913 hw_if->powerup_tx = xgbe_powerup_tx;
2914 hw_if->powerdown_tx = xgbe_powerdown_tx;
2915 hw_if->powerup_rx = xgbe_powerup_rx;
2916 hw_if->powerdown_rx = xgbe_powerdown_rx;
2917
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06002918 hw_if->dev_xmit = xgbe_dev_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002919 hw_if->dev_read = xgbe_dev_read;
2920 hw_if->enable_int = xgbe_enable_int;
2921 hw_if->disable_int = xgbe_disable_int;
2922 hw_if->init = xgbe_init;
2923 hw_if->exit = xgbe_exit;
2924
2925 /* Descriptor related Sequences have to be initialized here */
2926 hw_if->tx_desc_init = xgbe_tx_desc_init;
2927 hw_if->rx_desc_init = xgbe_rx_desc_init;
2928 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2929 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2930 hw_if->is_last_desc = xgbe_is_last_desc;
2931 hw_if->is_context_desc = xgbe_is_context_desc;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06002932 hw_if->tx_start_xmit = xgbe_tx_start_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002933
2934 /* For FLOW ctrl */
2935 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2936 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2937
2938 /* For RX coalescing */
2939 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2940 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2941 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2942 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2943
2944 /* For RX and TX threshold config */
2945 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2946 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2947
2948 /* For RX and TX Store and Forward Mode config */
2949 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2950 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2951
2952 /* For TX DMA Operating on Second Frame config */
2953 hw_if->config_osp_mode = xgbe_config_osp_mode;
2954
2955 /* For RX and TX PBL config */
2956 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2957 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2958 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2959 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2960 hw_if->config_pblx8 = xgbe_config_pblx8;
2961
2962 /* For MMC statistics support */
2963 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2964 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2965 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2966
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05002967 /* For PTP config */
2968 hw_if->config_tstamp = xgbe_config_tstamp;
2969 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
2970 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
2971 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
2972 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
2973
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002974 /* For Data Center Bridging config */
Lendacky, Thomasb3b71592016-02-17 11:49:08 -06002975 hw_if->config_tc = xgbe_config_tc;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002976 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
2977 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
2978
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06002979 /* For Receive Side Scaling */
2980 hw_if->enable_rss = xgbe_enable_rss;
2981 hw_if->disable_rss = xgbe_disable_rss;
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -06002982 hw_if->set_rss_hash_key = xgbe_set_rss_hash_key;
2983 hw_if->set_rss_lookup_table = xgbe_set_rss_lookup_table;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06002984
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002985 DBGPR("<--xgbe_init_function_ptrs\n");
2986}