blob: 96c5e4babbdf4b391a5c1c6f3241b087e1be364d [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 *
9 * Copyright (c) 2014 Advanced Micro Devices, Inc.
10 *
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 *
59 * Copyright (c) 2014 Advanced Micro Devices, Inc.
60 * 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{
521 unsigned int max_q_count, q_count;
522 unsigned int reg, reg_val;
523 unsigned int i;
524
525 /* Set MTL flow control */
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500526 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500527 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 1);
528
529 /* Set MAC flow control */
530 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas9fc69af2014-08-29 13:17:08 -0500531 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500532 reg = MAC_Q0TFCR;
533 for (i = 0; i < q_count; i++) {
534 reg_val = XGMAC_IOREAD(pdata, reg);
535
536 /* Enable transmit flow control */
537 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
538 /* Set pause time */
539 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
540
541 XGMAC_IOWRITE(pdata, reg, reg_val);
542
543 reg += MAC_QTFCR_INC;
544 }
545
546 return 0;
547}
548
549static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
550{
551 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
552
553 return 0;
554}
555
556static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
557{
558 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
559
560 return 0;
561}
562
563static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
564{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500565 struct ieee_pfc *pfc = pdata->pfc;
566
567 if (pdata->tx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500568 xgbe_enable_tx_flow_control(pdata);
569 else
570 xgbe_disable_tx_flow_control(pdata);
571
572 return 0;
573}
574
575static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
576{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500577 struct ieee_pfc *pfc = pdata->pfc;
578
579 if (pdata->rx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500580 xgbe_enable_rx_flow_control(pdata);
581 else
582 xgbe_disable_rx_flow_control(pdata);
583
584 return 0;
585}
586
587static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
588{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500589 struct ieee_pfc *pfc = pdata->pfc;
590
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500591 xgbe_config_tx_flow_control(pdata);
592 xgbe_config_rx_flow_control(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500593
594 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
595 (pfc && pfc->pfc_en) ? 1 : 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500596}
597
598static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
599{
600 struct xgbe_channel *channel;
601 unsigned int dma_ch_isr, dma_ch_ier;
602 unsigned int i;
603
604 channel = pdata->channel;
605 for (i = 0; i < pdata->channel_count; i++, channel++) {
606 /* Clear all the interrupts which are set */
607 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
608 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
609
610 /* Clear all interrupt enable bits */
611 dma_ch_ier = 0;
612
613 /* Enable following interrupts
614 * NIE - Normal Interrupt Summary Enable
615 * AIE - Abnormal Interrupt Summary Enable
616 * FBEE - Fatal Bus Error Enable
617 */
618 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
619 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
620 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
621
622 if (channel->tx_ring) {
623 /* Enable the following Tx interrupts
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600624 * TIE - Transmit Interrupt Enable (unless using
625 * per channel interrupts)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500626 */
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600627 if (!pdata->per_channel_irq)
628 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500629 }
630 if (channel->rx_ring) {
631 /* Enable following Rx interrupts
632 * RBUE - Receive Buffer Unavailable Enable
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600633 * RIE - Receive Interrupt Enable (unless using
634 * per channel interrupts)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500635 */
636 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600637 if (!pdata->per_channel_irq)
638 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500639 }
640
641 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
642 }
643}
644
645static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
646{
647 unsigned int mtl_q_isr;
648 unsigned int q_count, i;
649
650 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
651 for (i = 0; i < q_count; i++) {
652 /* Clear all the interrupts which are set */
653 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
654 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
655
656 /* No MTL interrupts to be enabled */
Lendacky, Thomas91f87342014-07-02 13:04:34 -0500657 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500658 }
659}
660
661static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
662{
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500663 unsigned int mac_ier = 0;
664
665 /* Enable Timestamp interrupt */
666 XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
667
668 XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500669
670 /* Enable all counter interrupts */
Lendacky, Thomasa3ba7c92014-09-05 18:02:36 -0500671 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
672 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500673}
674
675static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
676{
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600677 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) == 0x3)
678 return 0;
679
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500680 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
681
682 return 0;
683}
684
685static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
686{
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600687 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) == 0x2)
688 return 0;
689
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500690 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
691
692 return 0;
693}
694
695static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
696{
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600697 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) == 0)
698 return 0;
699
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500700 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
701
702 return 0;
703}
704
705static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
706 unsigned int enable)
707{
708 unsigned int val = enable ? 1 : 0;
709
710 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
711 return 0;
712
713 DBGPR(" %s promiscuous mode\n", enable ? "entering" : "leaving");
714 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
715
716 return 0;
717}
718
719static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
720 unsigned int enable)
721{
722 unsigned int val = enable ? 1 : 0;
723
724 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
725 return 0;
726
727 DBGPR(" %s allmulti mode\n", enable ? "entering" : "leaving");
728 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
729
730 return 0;
731}
732
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500733static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
734 struct netdev_hw_addr *ha, unsigned int *mac_reg)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500735{
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500736 unsigned int mac_addr_hi, mac_addr_lo;
737 u8 *mac_addr;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500738
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500739 mac_addr_lo = 0;
740 mac_addr_hi = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500741
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500742 if (ha) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500743 mac_addr = (u8 *)&mac_addr_lo;
744 mac_addr[0] = ha->addr[0];
745 mac_addr[1] = ha->addr[1];
746 mac_addr[2] = ha->addr[2];
747 mac_addr[3] = ha->addr[3];
748 mac_addr = (u8 *)&mac_addr_hi;
749 mac_addr[0] = ha->addr[4];
750 mac_addr[1] = ha->addr[5];
751
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500752 DBGPR(" adding mac address %pM at 0x%04x\n", ha->addr,
753 *mac_reg);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500754
755 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500756 }
757
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500758 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
759 *mac_reg += MAC_MACA_INC;
760 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
761 *mac_reg += MAC_MACA_INC;
762}
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500763
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500764static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
765{
766 struct net_device *netdev = pdata->netdev;
767 struct netdev_hw_addr *ha;
768 unsigned int mac_reg;
769 unsigned int addn_macs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500770
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500771 mac_reg = MAC_MACA1HR;
772 addn_macs = pdata->hw_feat.addn_mac;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500773
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500774 if (netdev_uc_count(netdev) > addn_macs) {
775 xgbe_set_promiscuous_mode(pdata, 1);
776 } else {
777 netdev_for_each_uc_addr(ha, netdev) {
778 xgbe_set_mac_reg(pdata, ha, &mac_reg);
779 addn_macs--;
780 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500781
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500782 if (netdev_mc_count(netdev) > addn_macs) {
783 xgbe_set_all_multicast_mode(pdata, 1);
784 } else {
785 netdev_for_each_mc_addr(ha, netdev) {
786 xgbe_set_mac_reg(pdata, ha, &mac_reg);
787 addn_macs--;
788 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500789 }
790 }
791
792 /* Clear remaining additional MAC address entries */
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500793 while (addn_macs--)
794 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
795}
796
797static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
798{
799 struct net_device *netdev = pdata->netdev;
800 struct netdev_hw_addr *ha;
801 unsigned int hash_reg;
802 unsigned int hash_table_shift, hash_table_count;
803 u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
804 u32 crc;
805 unsigned int i;
806
807 hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
808 hash_table_count = pdata->hw_feat.hash_table_size / 32;
809 memset(hash_table, 0, sizeof(hash_table));
810
811 /* Build the MAC Hash Table register values */
812 netdev_for_each_uc_addr(ha, netdev) {
813 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
814 crc >>= hash_table_shift;
815 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500816 }
817
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500818 netdev_for_each_mc_addr(ha, netdev) {
819 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
820 crc >>= hash_table_shift;
821 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
822 }
823
824 /* Set the MAC Hash Table registers */
825 hash_reg = MAC_HTR0;
826 for (i = 0; i < hash_table_count; i++) {
827 XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
828 hash_reg += MAC_HTR_INC;
829 }
830}
831
832static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
833{
834 if (pdata->hw_feat.hash_table_size)
835 xgbe_set_mac_hash_table(pdata);
836 else
837 xgbe_set_mac_addn_addrs(pdata);
838
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500839 return 0;
840}
841
842static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
843{
844 unsigned int mac_addr_hi, mac_addr_lo;
845
846 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
847 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
848 (addr[1] << 8) | (addr[0] << 0);
849
850 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
851 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
852
853 return 0;
854}
855
856static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
857 int mmd_reg)
858{
859 unsigned int mmd_address;
860 int mmd_data;
861
862 if (mmd_reg & MII_ADDR_C45)
863 mmd_address = mmd_reg & ~MII_ADDR_C45;
864 else
865 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
866
867 /* The PCS registers are accessed using mmio. The underlying APB3
868 * management interface uses indirect addressing to access the MMD
869 * register sets. This requires accessing of the PCS register in two
870 * phases, an address phase and a data phase.
871 *
872 * The mmio interface is based on 32-bit offsets and values. All
873 * register offsets must therefore be adjusted by left shifting the
874 * offset 2 bits and reading 32 bits of data.
875 */
876 mutex_lock(&pdata->xpcs_mutex);
877 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
878 mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
879 mutex_unlock(&pdata->xpcs_mutex);
880
881 return mmd_data;
882}
883
884static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
885 int mmd_reg, int mmd_data)
886{
887 unsigned int mmd_address;
888
889 if (mmd_reg & MII_ADDR_C45)
890 mmd_address = mmd_reg & ~MII_ADDR_C45;
891 else
892 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
893
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600894 /* If the PCS is changing modes, match the MAC speed to it */
895 if (((mmd_address >> 16) == MDIO_MMD_PCS) &&
896 ((mmd_address & 0xffff) == MDIO_CTRL2)) {
897 struct phy_device *phydev = pdata->phydev;
898
899 if (mmd_data & MDIO_PCS_CTRL2_TYPE) {
900 /* KX mode */
901 if (phydev->supported & SUPPORTED_1000baseKX_Full)
902 xgbe_set_gmii_speed(pdata);
903 else
904 xgbe_set_gmii_2500_speed(pdata);
905 } else {
906 /* KR mode */
907 xgbe_set_xgmii_speed(pdata);
908 }
909 }
910
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500911 /* The PCS registers are accessed using mmio. The underlying APB3
912 * management interface uses indirect addressing to access the MMD
913 * register sets. This requires accessing of the PCS register in two
914 * phases, an address phase and a data phase.
915 *
916 * The mmio interface is based on 32-bit offsets and values. All
917 * register offsets must therefore be adjusted by left shifting the
918 * offset 2 bits and reading 32 bits of data.
919 */
920 mutex_lock(&pdata->xpcs_mutex);
921 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
922 XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
923 mutex_unlock(&pdata->xpcs_mutex);
924}
925
926static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
927{
928 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
929}
930
931static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
932{
933 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
934
935 return 0;
936}
937
938static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
939{
940 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
941
942 return 0;
943}
944
945static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
946{
947 /* Put the VLAN tag in the Rx descriptor */
948 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
949
950 /* Don't check the VLAN type */
951 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
952
953 /* Check only C-TAG (0x8100) packets */
954 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
955
956 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
957 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
958
959 /* Enable VLAN tag stripping */
960 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
961
962 return 0;
963}
964
965static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
966{
967 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
968
969 return 0;
970}
971
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500972static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
973{
974 /* Enable VLAN filtering */
975 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
976
977 /* Enable VLAN Hash Table filtering */
978 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
979
980 /* Disable VLAN tag inverse matching */
981 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
982
983 /* Only filter on the lower 12-bits of the VLAN tag */
984 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
985
986 /* In order for the VLAN Hash Table filtering to be effective,
987 * the VLAN tag identifier in the VLAN Tag Register must not
988 * be zero. Set the VLAN tag identifier to "1" to enable the
989 * VLAN Hash Table filtering. This implies that a VLAN tag of
990 * 1 will always pass filtering.
991 */
992 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
993
994 return 0;
995}
996
997static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
998{
999 /* Disable VLAN filtering */
1000 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
1001
1002 return 0;
1003}
1004
1005#ifndef CRCPOLY_LE
1006#define CRCPOLY_LE 0xedb88320
1007#endif
1008static u32 xgbe_vid_crc32_le(__le16 vid_le)
1009{
1010 u32 poly = CRCPOLY_LE;
1011 u32 crc = ~0;
1012 u32 temp = 0;
1013 unsigned char *data = (unsigned char *)&vid_le;
1014 unsigned char data_byte = 0;
1015 int i, bits;
1016
1017 bits = get_bitmask_order(VLAN_VID_MASK);
1018 for (i = 0; i < bits; i++) {
1019 if ((i % 8) == 0)
1020 data_byte = data[i / 8];
1021
1022 temp = ((crc & 1) ^ data_byte) & 1;
1023 crc >>= 1;
1024 data_byte >>= 1;
1025
1026 if (temp)
1027 crc ^= poly;
1028 }
1029
1030 return crc;
1031}
1032
1033static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
1034{
1035 u32 crc;
1036 u16 vid;
1037 __le16 vid_le;
1038 u16 vlan_hash_table = 0;
1039
1040 /* Generate the VLAN Hash Table value */
1041 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
1042 /* Get the CRC32 value of the VLAN ID */
1043 vid_le = cpu_to_le16(vid);
1044 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
1045
1046 vlan_hash_table |= (1 << crc);
1047 }
1048
1049 /* Set the VLAN Hash Table filtering register */
1050 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
1051
1052 return 0;
1053}
1054
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001055static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
1056{
1057 struct xgbe_ring_desc *rdesc = rdata->rdesc;
1058
1059 /* Reset the Tx descriptor
1060 * Set buffer 1 (lo) address to zero
1061 * Set buffer 1 (hi) address to zero
1062 * Reset all other control bits (IC, TTSE, B2L & B1L)
1063 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
1064 */
1065 rdesc->desc0 = 0;
1066 rdesc->desc1 = 0;
1067 rdesc->desc2 = 0;
1068 rdesc->desc3 = 0;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001069
1070 /* Make sure ownership is written to the descriptor */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001071 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001072}
1073
1074static void xgbe_tx_desc_init(struct xgbe_channel *channel)
1075{
1076 struct xgbe_ring *ring = channel->tx_ring;
1077 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001078 int i;
1079 int start_index = ring->cur;
1080
1081 DBGPR("-->tx_desc_init\n");
1082
1083 /* Initialze all descriptors */
1084 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001085 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001086
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001087 /* Initialize Tx descriptor */
1088 xgbe_tx_desc_reset(rdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001089 }
1090
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001091 /* Update the total number of Tx descriptors */
1092 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
1093
1094 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001095 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001096 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
1097 upper_32_bits(rdata->rdesc_dma));
1098 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
1099 lower_32_bits(rdata->rdesc_dma));
1100
1101 DBGPR("<--tx_desc_init\n");
1102}
1103
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001104static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata,
1105 struct xgbe_ring_data *rdata, unsigned int index)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001106{
1107 struct xgbe_ring_desc *rdesc = rdata->rdesc;
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001108 unsigned int rx_usecs = pdata->rx_usecs;
1109 unsigned int rx_frames = pdata->rx_frames;
1110 unsigned int inte;
1111
1112 if (!rx_usecs && !rx_frames) {
1113 /* No coalescing, interrupt for every descriptor */
1114 inte = 1;
1115 } else {
1116 /* Set interrupt based on Rx frame coalescing setting */
1117 if (rx_frames && !((index + 1) % rx_frames))
1118 inte = 1;
1119 else
1120 inte = 0;
1121 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001122
1123 /* Reset the Rx descriptor
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001124 * Set buffer 1 (lo) address to header dma address (lo)
1125 * Set buffer 1 (hi) address to header dma address (hi)
1126 * Set buffer 2 (lo) address to buffer dma address (lo)
1127 * Set buffer 2 (hi) address to buffer dma address (hi) and
1128 * set control bits OWN and INTE
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001129 */
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001130 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->rx.hdr.dma));
1131 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->rx.hdr.dma));
1132 rdesc->desc2 = cpu_to_le32(lower_32_bits(rdata->rx.buf.dma));
1133 rdesc->desc3 = cpu_to_le32(upper_32_bits(rdata->rx.buf.dma));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001134
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001135 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001136
1137 /* Since the Rx DMA engine is likely running, make sure everything
1138 * is written to the descriptor(s) before setting the OWN bit
1139 * for the descriptor
1140 */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001141 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001142
1143 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
1144
1145 /* Make sure ownership is written to the descriptor */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001146 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001147}
1148
1149static void xgbe_rx_desc_init(struct xgbe_channel *channel)
1150{
1151 struct xgbe_prv_data *pdata = channel->pdata;
1152 struct xgbe_ring *ring = channel->rx_ring;
1153 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001154 unsigned int start_index = ring->cur;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001155 unsigned int i;
1156
1157 DBGPR("-->rx_desc_init\n");
1158
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001159 /* Initialize all descriptors */
1160 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001161 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001162
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001163 /* Initialize Rx descriptor */
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001164 xgbe_rx_desc_reset(pdata, rdata, i);
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001165 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001166
1167 /* Update the total number of Rx descriptors */
1168 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
1169
1170 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001171 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001172 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
1173 upper_32_bits(rdata->rdesc_dma));
1174 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
1175 lower_32_bits(rdata->rdesc_dma));
1176
1177 /* Update the Rx Descriptor Tail Pointer */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001178 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001179 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
1180 lower_32_bits(rdata->rdesc_dma));
1181
1182 DBGPR("<--rx_desc_init\n");
1183}
1184
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001185static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
1186 unsigned int addend)
1187{
1188 /* Set the addend register value and tell the device */
1189 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1190 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1191
1192 /* Wait for addend update to complete */
1193 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1194 udelay(5);
1195}
1196
1197static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1198 unsigned int nsec)
1199{
1200 /* Set the time values and tell the device */
1201 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1202 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1203 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1204
1205 /* Wait for time update to complete */
1206 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1207 udelay(5);
1208}
1209
1210static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1211{
1212 u64 nsec;
1213
1214 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1215 nsec *= NSEC_PER_SEC;
1216 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1217
1218 return nsec;
1219}
1220
1221static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1222{
1223 unsigned int tx_snr;
1224 u64 nsec;
1225
1226 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1227 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1228 return 0;
1229
1230 nsec = XGMAC_IOREAD(pdata, MAC_TXSSR);
1231 nsec *= NSEC_PER_SEC;
1232 nsec += tx_snr;
1233
1234 return nsec;
1235}
1236
1237static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1238 struct xgbe_ring_desc *rdesc)
1239{
1240 u64 nsec;
1241
1242 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1243 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1244 nsec = le32_to_cpu(rdesc->desc1);
1245 nsec <<= 32;
1246 nsec |= le32_to_cpu(rdesc->desc0);
1247 if (nsec != 0xffffffffffffffffULL) {
1248 packet->rx_tstamp = nsec;
1249 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1250 RX_TSTAMP, 1);
1251 }
1252 }
1253}
1254
1255static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1256 unsigned int mac_tscr)
1257{
1258 /* Set one nano-second accuracy */
1259 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1260
1261 /* Set fine timestamp update */
1262 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1263
1264 /* Overwrite earlier timestamps */
1265 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1266
1267 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1268
1269 /* Exit if timestamping is not enabled */
1270 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1271 return 0;
1272
1273 /* Initialize time registers */
1274 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1275 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1276 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1277 xgbe_set_tstamp_time(pdata, 0, 0);
1278
1279 /* Initialize the timecounter */
1280 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1281 ktime_to_ns(ktime_get_real()));
1282
1283 return 0;
1284}
1285
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001286static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
1287{
1288 struct ieee_ets *ets = pdata->ets;
1289 unsigned int total_weight, min_weight, weight;
1290 unsigned int i;
1291
1292 if (!ets)
1293 return;
1294
1295 /* Set Tx to deficit weighted round robin scheduling algorithm (when
1296 * traffic class is using ETS algorithm)
1297 */
1298 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
1299
1300 /* Set Traffic Class algorithms */
1301 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
1302 min_weight = total_weight / 100;
1303 if (!min_weight)
1304 min_weight = 1;
1305
1306 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1307 switch (ets->tc_tsa[i]) {
1308 case IEEE_8021QAZ_TSA_STRICT:
1309 DBGPR(" TC%u using SP\n", i);
1310 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1311 MTL_TSA_SP);
1312 break;
1313 case IEEE_8021QAZ_TSA_ETS:
1314 weight = total_weight * ets->tc_tx_bw[i] / 100;
1315 weight = clamp(weight, min_weight, total_weight);
1316
1317 DBGPR(" TC%u using DWRR (weight %u)\n", i, weight);
1318 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1319 MTL_TSA_ETS);
1320 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
1321 weight);
1322 break;
1323 }
1324 }
1325}
1326
1327static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
1328{
1329 struct ieee_pfc *pfc = pdata->pfc;
1330 struct ieee_ets *ets = pdata->ets;
1331 unsigned int mask, reg, reg_val;
1332 unsigned int tc, prio;
1333
1334 if (!pfc || !ets)
1335 return;
1336
1337 for (tc = 0; tc < pdata->hw_feat.tc_cnt; tc++) {
1338 mask = 0;
1339 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
1340 if ((pfc->pfc_en & (1 << prio)) &&
1341 (ets->prio_tc[prio] == tc))
1342 mask |= (1 << prio);
1343 }
1344 mask &= 0xff;
1345
1346 DBGPR(" TC%u PFC mask=%#x\n", tc, mask);
1347 reg = MTL_TCPM0R + (MTL_TCPM_INC * (tc / MTL_TCPM_TC_PER_REG));
1348 reg_val = XGMAC_IOREAD(pdata, reg);
1349
1350 reg_val &= ~(0xff << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1351 reg_val |= (mask << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1352
1353 XGMAC_IOWRITE(pdata, reg, reg_val);
1354 }
1355
1356 xgbe_config_flow_control(pdata);
1357}
1358
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001359static void xgbe_tx_start_xmit(struct xgbe_channel *channel,
1360 struct xgbe_ring *ring)
1361{
1362 struct xgbe_prv_data *pdata = channel->pdata;
1363 struct xgbe_ring_data *rdata;
1364
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001365 /* Make sure everything is written before the register write */
1366 wmb();
1367
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001368 /* Issue a poll command to Tx DMA by writing address
1369 * of next immediate free descriptor */
1370 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1371 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1372 lower_32_bits(rdata->rdesc_dma));
1373
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -05001374 /* Start the Tx timer */
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001375 if (pdata->tx_usecs && !channel->tx_timer_active) {
1376 channel->tx_timer_active = 1;
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -05001377 mod_timer(&channel->tx_timer,
1378 jiffies + usecs_to_jiffies(pdata->tx_usecs));
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001379 }
1380
1381 ring->tx.xmit_more = 0;
1382}
1383
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001384static void xgbe_dev_xmit(struct xgbe_channel *channel)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001385{
1386 struct xgbe_prv_data *pdata = channel->pdata;
1387 struct xgbe_ring *ring = channel->tx_ring;
1388 struct xgbe_ring_data *rdata;
1389 struct xgbe_ring_desc *rdesc;
1390 struct xgbe_packet_data *packet = &ring->packet_data;
1391 unsigned int csum, tso, vlan;
1392 unsigned int tso_context, vlan_context;
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001393 unsigned int tx_set_ic;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001394 int start_index = ring->cur;
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001395 int cur_index = ring->cur;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001396 int i;
1397
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001398 DBGPR("-->xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001399
1400 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1401 CSUM_ENABLE);
1402 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1403 TSO_ENABLE);
1404 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1405 VLAN_CTAG);
1406
1407 if (tso && (packet->mss != ring->tx.cur_mss))
1408 tso_context = 1;
1409 else
1410 tso_context = 0;
1411
1412 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1413 vlan_context = 1;
1414 else
1415 vlan_context = 0;
1416
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001417 /* Determine if an interrupt should be generated for this Tx:
1418 * Interrupt:
1419 * - Tx frame count exceeds the frame count setting
1420 * - Addition of Tx frame count to the frame count since the
1421 * last interrupt was set exceeds the frame count setting
1422 * No interrupt:
1423 * - No frame count setting specified (ethtool -C ethX tx-frames 0)
1424 * - Addition of Tx frame count to the frame count since the
1425 * last interrupt was set does not exceed the frame count setting
1426 */
1427 ring->coalesce_count += packet->tx_packets;
1428 if (!pdata->tx_frames)
1429 tx_set_ic = 0;
1430 else if (packet->tx_packets > pdata->tx_frames)
1431 tx_set_ic = 1;
1432 else if ((ring->coalesce_count % pdata->tx_frames) <
1433 packet->tx_packets)
1434 tx_set_ic = 1;
1435 else
1436 tx_set_ic = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001437
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001438 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001439 rdesc = rdata->rdesc;
1440
1441 /* Create a context descriptor if this is a TSO packet */
1442 if (tso_context || vlan_context) {
1443 if (tso_context) {
1444 DBGPR(" TSO context descriptor, mss=%u\n",
1445 packet->mss);
1446
1447 /* Set the MSS size */
1448 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1449 MSS, packet->mss);
1450
1451 /* Mark it as a CONTEXT descriptor */
1452 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1453 CTXT, 1);
1454
1455 /* Indicate this descriptor contains the MSS */
1456 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1457 TCMSSV, 1);
1458
1459 ring->tx.cur_mss = packet->mss;
1460 }
1461
1462 if (vlan_context) {
1463 DBGPR(" VLAN context descriptor, ctag=%u\n",
1464 packet->vlan_ctag);
1465
1466 /* Mark it as a CONTEXT descriptor */
1467 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1468 CTXT, 1);
1469
1470 /* Set the VLAN tag */
1471 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1472 VT, packet->vlan_ctag);
1473
1474 /* Indicate this descriptor contains the VLAN tag */
1475 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1476 VLTV, 1);
1477
1478 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1479 }
1480
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001481 cur_index++;
1482 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001483 rdesc = rdata->rdesc;
1484 }
1485
1486 /* Update buffer address (for TSO this is the header) */
1487 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1488 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1489
1490 /* Update the buffer length */
1491 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1492 rdata->skb_dma_len);
1493
1494 /* VLAN tag insertion check */
1495 if (vlan)
1496 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1497 TX_NORMAL_DESC2_VLAN_INSERT);
1498
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001499 /* Timestamp enablement check */
1500 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1501 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1502
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001503 /* Mark it as First Descriptor */
1504 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1505
1506 /* Mark it as a NORMAL descriptor */
1507 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1508
1509 /* Set OWN bit if not the first descriptor */
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001510 if (cur_index != start_index)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001511 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1512
1513 if (tso) {
1514 /* Enable TSO */
1515 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1516 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1517 packet->tcp_payload_len);
1518 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1519 packet->tcp_header_len / 4);
1520 } else {
1521 /* Enable CRC and Pad Insertion */
1522 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1523
1524 /* Enable HW CSUM */
1525 if (csum)
1526 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1527 CIC, 0x3);
1528
1529 /* Set the total length to be transmitted */
1530 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1531 packet->length);
1532 }
1533
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001534 for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) {
1535 cur_index++;
1536 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001537 rdesc = rdata->rdesc;
1538
1539 /* Update buffer address */
1540 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1541 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1542
1543 /* Update the buffer length */
1544 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1545 rdata->skb_dma_len);
1546
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001547 /* Set OWN bit */
1548 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1549
1550 /* Mark it as NORMAL descriptor */
1551 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1552
1553 /* Enable HW CSUM */
1554 if (csum)
1555 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1556 CIC, 0x3);
1557 }
1558
1559 /* Set LAST bit for the last descriptor */
1560 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1561
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001562 /* Set IC bit based on Tx coalescing settings */
1563 if (tx_set_ic)
1564 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1565
Lendacky, Thomas5fb4b862014-11-20 11:03:50 -06001566 /* Save the Tx info to report back during cleanup */
1567 rdata->tx.packets = packet->tx_packets;
1568 rdata->tx.bytes = packet->tx_bytes;
1569
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001570 /* In case the Tx DMA engine is running, make sure everything
1571 * is written to the descriptor(s) before setting the OWN bit
1572 * for the first descriptor
1573 */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001574 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001575
1576 /* Set OWN bit for the first descriptor */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001577 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001578 rdesc = rdata->rdesc;
1579 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1580
1581#ifdef XGMAC_ENABLE_TX_DESC_DUMP
1582 xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
1583#endif
1584
1585 /* Make sure ownership is written to the descriptor */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001586 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001587
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001588 ring->cur = cur_index + 1;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001589 if (!packet->skb->xmit_more ||
1590 netif_xmit_stopped(netdev_get_tx_queue(pdata->netdev,
1591 channel->queue_index)))
1592 xgbe_tx_start_xmit(channel, ring);
1593 else
1594 ring->tx.xmit_more = 1;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001595
1596 DBGPR(" %s: descriptors %u to %u written\n",
1597 channel->name, start_index & (ring->rdesc_count - 1),
1598 (ring->cur - 1) & (ring->rdesc_count - 1));
1599
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001600 DBGPR("<--xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001601}
1602
1603static int xgbe_dev_read(struct xgbe_channel *channel)
1604{
1605 struct xgbe_ring *ring = channel->rx_ring;
1606 struct xgbe_ring_data *rdata;
1607 struct xgbe_ring_desc *rdesc;
1608 struct xgbe_packet_data *packet = &ring->packet_data;
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001609 struct net_device *netdev = channel->pdata->netdev;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001610 unsigned int err, etlt, l34t;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001611
1612 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1613
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001614 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001615 rdesc = rdata->rdesc;
1616
1617 /* Check for data availability */
1618 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1619 return 1;
1620
Lendacky, Thomas5449e272014-11-20 11:03:26 -06001621 /* Make sure descriptor fields are read after reading the OWN bit */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001622 dma_rmb();
Lendacky, Thomas5449e272014-11-20 11:03:26 -06001623
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001624#ifdef XGMAC_ENABLE_RX_DESC_DUMP
1625 xgbe_dump_rx_desc(ring, rdesc, ring->cur);
1626#endif
1627
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001628 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1629 /* Timestamp Context Descriptor */
1630 xgbe_get_rx_tstamp(packet, rdesc);
1631
1632 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1633 CONTEXT, 1);
1634 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1635 CONTEXT_NEXT, 0);
1636 return 0;
1637 }
1638
1639 /* Normal Descriptor, be sure Context Descriptor bit is off */
1640 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1641
1642 /* Indicate if a Context Descriptor is next */
1643 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1644 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1645 CONTEXT_NEXT, 1);
1646
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001647 /* Get the header length */
1648 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD))
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001649 rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2,
1650 RX_NORMAL_DESC2, HL);
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001651
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001652 /* Get the RSS hash */
1653 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, RSV)) {
1654 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1655 RSS_HASH, 1);
1656
1657 packet->rss_hash = le32_to_cpu(rdesc->desc1);
1658
1659 l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T);
1660 switch (l34t) {
1661 case RX_DESC3_L34T_IPV4_TCP:
1662 case RX_DESC3_L34T_IPV4_UDP:
1663 case RX_DESC3_L34T_IPV6_TCP:
1664 case RX_DESC3_L34T_IPV6_UDP:
1665 packet->rss_hash_type = PKT_HASH_TYPE_L4;
Dan Carpenterb6267d32014-11-13 09:19:06 +03001666 break;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001667 default:
1668 packet->rss_hash_type = PKT_HASH_TYPE_L3;
1669 }
1670 }
1671
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001672 /* Get the packet length */
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001673 rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001674
1675 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1676 /* Not all the data has been transferred for this packet */
1677 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1678 INCOMPLETE, 1);
1679 return 0;
1680 }
1681
1682 /* This is the last of the data for this packet */
1683 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1684 INCOMPLETE, 0);
1685
1686 /* Set checksum done indicator as appropriate */
1687 if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
1688 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1689 CSUM_DONE, 1);
1690
1691 /* Check for errors (only valid in last descriptor) */
1692 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1693 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1694 DBGPR(" err=%u, etlt=%#x\n", err, etlt);
1695
Lendacky, Thomas7bba35b2014-11-20 11:03:38 -06001696 if (!err || !etlt) {
1697 /* No error if err is 0 or etlt is 0 */
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001698 if ((etlt == 0x09) &&
1699 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001700 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1701 VLAN_CTAG, 1);
1702 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1703 RX_NORMAL_DESC0,
1704 OVT);
1705 DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
1706 }
1707 } else {
1708 if ((etlt == 0x05) || (etlt == 0x06))
1709 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1710 CSUM_DONE, 0);
1711 else
1712 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1713 FRAME, 1);
1714 }
1715
1716 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1717 ring->cur & (ring->rdesc_count - 1), ring->cur);
1718
1719 return 0;
1720}
1721
1722static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1723{
1724 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1725 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1726}
1727
1728static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1729{
1730 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1731 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1732}
1733
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001734static int xgbe_enable_int(struct xgbe_channel *channel,
1735 enum xgbe_int int_id)
1736{
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001737 unsigned int dma_ch_ier;
1738
1739 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1740
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001741 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001742 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001743 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001744 break;
1745 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001746 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001747 break;
1748 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001749 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001750 break;
1751 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001752 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001753 break;
1754 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001755 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001756 break;
1757 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001758 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1759 break;
1760 case XGMAC_INT_DMA_CH_SR_TI_RI:
1761 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1762 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001763 break;
1764 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001765 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001766 break;
1767 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001768 dma_ch_ier |= channel->saved_ier;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001769 break;
1770 default:
1771 return -1;
1772 }
1773
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001774 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1775
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001776 return 0;
1777}
1778
1779static int xgbe_disable_int(struct xgbe_channel *channel,
1780 enum xgbe_int int_id)
1781{
1782 unsigned int dma_ch_ier;
1783
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001784 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1785
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001786 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001787 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001788 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001789 break;
1790 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001791 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001792 break;
1793 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001794 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001795 break;
1796 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001797 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001798 break;
1799 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001800 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001801 break;
1802 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001803 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1804 break;
1805 case XGMAC_INT_DMA_CH_SR_TI_RI:
1806 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1807 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001808 break;
1809 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001810 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001811 break;
1812 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001813 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001814 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001815 break;
1816 default:
1817 return -1;
1818 }
1819
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001820 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1821
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001822 return 0;
1823}
1824
1825static int xgbe_exit(struct xgbe_prv_data *pdata)
1826{
1827 unsigned int count = 2000;
1828
1829 DBGPR("-->xgbe_exit\n");
1830
1831 /* Issue a software reset */
1832 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1833 usleep_range(10, 15);
1834
1835 /* Poll Until Poll Condition */
1836 while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1837 usleep_range(500, 600);
1838
1839 if (!count)
1840 return -EBUSY;
1841
1842 DBGPR("<--xgbe_exit\n");
1843
1844 return 0;
1845}
1846
1847static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1848{
1849 unsigned int i, count;
1850
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -05001851 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
1852 return 0;
1853
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001854 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001855 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1856
1857 /* Poll Until Poll Condition */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001858 for (i = 0; i < pdata->tx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001859 count = 2000;
1860 while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
1861 MTL_Q_TQOMR, FTQ))
1862 usleep_range(500, 600);
1863
1864 if (!count)
1865 return -EBUSY;
1866 }
1867
1868 return 0;
1869}
1870
1871static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1872{
1873 /* Set enhanced addressing mode */
1874 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1875
1876 /* Set the System Bus mode */
1877 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001878 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001879}
1880
1881static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1882{
1883 unsigned int arcache, awcache;
1884
1885 arcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001886 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
1887 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
1888 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
1889 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
1890 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
1891 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001892 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1893
1894 awcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001895 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
1896 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
1897 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
1898 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
1899 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
1900 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
1901 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
1902 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001903 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1904}
1905
1906static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1907{
1908 unsigned int i;
1909
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001910 /* Set Tx to weighted round robin scheduling algorithm */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001911 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1912
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001913 /* Set Tx traffic classes to use WRR algorithm with equal weights */
1914 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1915 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1916 MTL_TSA_ETS);
1917 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
1918 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001919
1920 /* Set Rx to strict priority algorithm */
1921 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1922}
1923
Lendacky, Thomasf076f452014-08-29 13:16:56 -05001924static unsigned int xgbe_calculate_per_queue_fifo(unsigned int fifo_size,
1925 unsigned int queue_count)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001926{
1927 unsigned int q_fifo_size = 0;
1928 enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1929
1930 /* Calculate Tx/Rx fifo share per queue */
1931 switch (fifo_size) {
1932 case 0:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001933 q_fifo_size = XGBE_FIFO_SIZE_B(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001934 break;
1935 case 1:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001936 q_fifo_size = XGBE_FIFO_SIZE_B(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001937 break;
1938 case 2:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001939 q_fifo_size = XGBE_FIFO_SIZE_B(512);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001940 break;
1941 case 3:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001942 q_fifo_size = XGBE_FIFO_SIZE_KB(1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001943 break;
1944 case 4:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001945 q_fifo_size = XGBE_FIFO_SIZE_KB(2);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001946 break;
1947 case 5:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001948 q_fifo_size = XGBE_FIFO_SIZE_KB(4);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001949 break;
1950 case 6:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001951 q_fifo_size = XGBE_FIFO_SIZE_KB(8);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001952 break;
1953 case 7:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001954 q_fifo_size = XGBE_FIFO_SIZE_KB(16);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001955 break;
1956 case 8:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001957 q_fifo_size = XGBE_FIFO_SIZE_KB(32);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001958 break;
1959 case 9:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001960 q_fifo_size = XGBE_FIFO_SIZE_KB(64);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001961 break;
1962 case 10:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001963 q_fifo_size = XGBE_FIFO_SIZE_KB(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001964 break;
1965 case 11:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001966 q_fifo_size = XGBE_FIFO_SIZE_KB(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001967 break;
1968 }
Lendacky, Thomasf076f452014-08-29 13:16:56 -05001969
1970 /* The configured value is not the actual amount of fifo RAM */
1971 q_fifo_size = min_t(unsigned int, XGBE_FIFO_MAX, q_fifo_size);
1972
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001973 q_fifo_size = q_fifo_size / queue_count;
1974
1975 /* Set the queue fifo size programmable value */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001976 if (q_fifo_size >= XGBE_FIFO_SIZE_KB(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001977 p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001978 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(128))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001979 p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001980 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(64))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001981 p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001982 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(32))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001983 p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001984 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(16))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001985 p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001986 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(8))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001987 p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001988 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(4))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001989 p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001990 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(2))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001991 p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001992 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(1))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001993 p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001994 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(512))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001995 p_fifo = XGMAC_MTL_FIFO_SIZE_512;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001996 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001997 p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1998
1999 return p_fifo;
2000}
2001
2002static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
2003{
2004 enum xgbe_mtl_fifo_size fifo_size;
2005 unsigned int i;
2006
2007 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002008 pdata->tx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002009
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002010 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002011 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
2012
Lendacky, Thomas600c8812015-03-20 11:50:10 -05002013 netdev_notice(pdata->netdev,
2014 "%d Tx hardware queues, %d byte fifo per queue\n",
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002015 pdata->tx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002016}
2017
2018static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
2019{
2020 enum xgbe_mtl_fifo_size fifo_size;
2021 unsigned int i;
2022
2023 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002024 pdata->rx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002025
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002026 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002027 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
2028
Lendacky, Thomas600c8812015-03-20 11:50:10 -05002029 netdev_notice(pdata->netdev,
2030 "%d Rx hardware queues, %d byte fifo per queue\n",
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002031 pdata->rx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002032}
2033
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002034static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002035{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002036 unsigned int qptc, qptc_extra, queue;
2037 unsigned int prio_queues;
2038 unsigned int ppq, ppq_extra, prio;
2039 unsigned int mask;
2040 unsigned int i, j, reg, reg_val;
2041
2042 /* Map the MTL Tx Queues to Traffic Classes
2043 * Note: Tx Queues >= Traffic Classes
2044 */
2045 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
2046 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
2047
2048 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
2049 for (j = 0; j < qptc; j++) {
2050 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
2051 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2052 Q2TCMAP, i);
2053 pdata->q2tc_map[queue++] = i;
2054 }
2055
2056 if (i < qptc_extra) {
2057 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
2058 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2059 Q2TCMAP, i);
2060 pdata->q2tc_map[queue++] = i;
2061 }
2062 }
2063
2064 /* Map the 8 VLAN priority values to available MTL Rx queues */
2065 prio_queues = min_t(unsigned int, IEEE_8021QAZ_MAX_TCS,
2066 pdata->rx_q_count);
2067 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
2068 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
2069
2070 reg = MAC_RQC2R;
2071 reg_val = 0;
2072 for (i = 0, prio = 0; i < prio_queues;) {
2073 mask = 0;
2074 for (j = 0; j < ppq; j++) {
2075 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
2076 mask |= (1 << prio);
2077 pdata->prio2q_map[prio++] = i;
2078 }
2079
2080 if (i < ppq_extra) {
2081 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
2082 mask |= (1 << prio);
2083 pdata->prio2q_map[prio++] = i;
2084 }
2085
2086 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
2087
2088 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
2089 continue;
2090
2091 XGMAC_IOWRITE(pdata, reg, reg_val);
2092 reg += MAC_RQC2_INC;
2093 reg_val = 0;
2094 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002095
2096 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
2097 reg = MTL_RQDCM0R;
2098 reg_val = 0;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002099 for (i = 0; i < pdata->rx_q_count;) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002100 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
2101
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002102 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002103 continue;
2104
2105 XGMAC_IOWRITE(pdata, reg, reg_val);
2106
2107 reg += MTL_RQDCM_INC;
2108 reg_val = 0;
2109 }
2110}
2111
2112static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
2113{
2114 unsigned int i;
2115
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002116 for (i = 0; i < pdata->rx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002117 /* Activate flow control when less than 4k left in fifo */
Lendacky, Thomase2a27292015-01-20 12:20:31 -06002118 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFA, 2);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002119
2120 /* De-activate flow control when more than 6k left in fifo */
Lendacky, Thomase2a27292015-01-20 12:20:31 -06002121 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFD, 4);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002122 }
2123}
2124
2125static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
2126{
2127 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05002128
2129 /* Filtering is done using perfect filtering and hash filtering */
2130 if (pdata->hw_feat.hash_table_size) {
2131 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
2132 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
2133 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
2134 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002135}
2136
2137static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
2138{
2139 unsigned int val;
2140
2141 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
2142
2143 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
2144}
2145
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002146static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata)
2147{
2148 switch (pdata->phy_speed) {
2149 case SPEED_10000:
2150 xgbe_set_xgmii_speed(pdata);
2151 break;
2152
2153 case SPEED_2500:
2154 xgbe_set_gmii_2500_speed(pdata);
2155 break;
2156
2157 case SPEED_1000:
2158 xgbe_set_gmii_speed(pdata);
2159 break;
2160 }
2161}
2162
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002163static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
2164{
2165 if (pdata->netdev->features & NETIF_F_RXCSUM)
2166 xgbe_enable_rx_csum(pdata);
2167 else
2168 xgbe_disable_rx_csum(pdata);
2169}
2170
2171static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
2172{
Lendacky, Thomas6e5eed02014-06-24 16:19:12 -05002173 /* Indicate that VLAN Tx CTAGs come from context descriptors */
2174 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
2175 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
2176
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002177 /* Set the current VLAN Hash Table register value */
2178 xgbe_update_vlan_hash_table(pdata);
2179
2180 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
2181 xgbe_enable_rx_vlan_filtering(pdata);
2182 else
2183 xgbe_disable_rx_vlan_filtering(pdata);
2184
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002185 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2186 xgbe_enable_rx_vlan_stripping(pdata);
2187 else
2188 xgbe_disable_rx_vlan_stripping(pdata);
2189}
2190
Lendacky, Thomas60265102014-09-05 18:02:30 -05002191static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
2192{
2193 bool read_hi;
2194 u64 val;
2195
2196 switch (reg_lo) {
2197 /* These registers are always 64 bit */
2198 case MMC_TXOCTETCOUNT_GB_LO:
2199 case MMC_TXOCTETCOUNT_G_LO:
2200 case MMC_RXOCTETCOUNT_GB_LO:
2201 case MMC_RXOCTETCOUNT_G_LO:
2202 read_hi = true;
2203 break;
2204
2205 default:
2206 read_hi = false;
2207 };
2208
2209 val = XGMAC_IOREAD(pdata, reg_lo);
2210
2211 if (read_hi)
2212 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
2213
2214 return val;
2215}
2216
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002217static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
2218{
2219 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2220 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
2221
2222 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
2223 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002224 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002225
2226 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
2227 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002228 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002229
2230 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
2231 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002232 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002233
2234 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
2235 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002236 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002237
2238 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
2239 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002240 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002241
2242 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
2243 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002244 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002245
2246 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
2247 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002248 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002249
2250 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
2251 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002252 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002253
2254 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
2255 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002256 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002257
2258 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
2259 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002260 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002261
2262 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
2263 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002264 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002265
2266 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2267 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002268 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002269
2270 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2271 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002272 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002273
2274 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2275 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002276 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002277
2278 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2279 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002280 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002281
2282 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2283 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002284 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002285
2286 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2287 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002288 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002289
2290 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2291 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002292 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002293}
2294
2295static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2296{
2297 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2298 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2299
2300 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2301 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002302 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002303
2304 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2305 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002306 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002307
2308 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2309 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002310 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002311
2312 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2313 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002314 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002315
2316 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2317 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002318 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002319
2320 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2321 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002322 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002323
2324 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2325 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002326 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002327
2328 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2329 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002330 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002331
2332 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
2333 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002334 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002335
2336 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
2337 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002338 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002339
2340 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
2341 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002342 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002343
2344 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
2345 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002346 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002347
2348 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
2349 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002350 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002351
2352 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
2353 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002354 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002355
2356 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
2357 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002358 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002359
2360 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
2361 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002362 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002363
2364 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
2365 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002366 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002367
2368 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
2369 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002370 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002371
2372 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
2373 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002374 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002375
2376 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
2377 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002378 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002379
2380 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
2381 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002382 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002383
2384 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
2385 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002386 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002387
2388 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
2389 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002390 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002391}
2392
2393static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
2394{
2395 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2396
2397 /* Freeze counters */
2398 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
2399
2400 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002401 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002402
2403 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002404 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002405
2406 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002407 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002408
2409 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002410 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002411
2412 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002413 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002414
2415 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002416 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002417
2418 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002419 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002420
2421 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002422 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002423
2424 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002425 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002426
2427 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002428 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002429
2430 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002431 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002432
2433 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002434 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002435
2436 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002437 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002438
2439 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002440 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002441
2442 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002443 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002444
2445 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002446 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002447
2448 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002449 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002450
2451 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002452 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002453
2454 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002455 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002456
2457 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002458 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002459
2460 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002461 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002462
2463 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002464 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002465
2466 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002467 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002468
2469 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002470 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002471
2472 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002473 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002474
2475 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002476 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002477
2478 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002479 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002480
2481 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002482 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002483
2484 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002485 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002486
2487 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002488 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002489
2490 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002491 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002492
2493 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002494 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002495
2496 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002497 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002498
2499 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002500 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002501
2502 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002503 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002504
2505 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002506 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002507
2508 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002509 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002510
2511 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002512 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002513
2514 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002515 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002516
2517 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002518 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002519
2520 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002521 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002522
2523 /* Un-freeze counters */
2524 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
2525}
2526
2527static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
2528{
2529 /* Set counters to reset on read */
2530 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
2531
2532 /* Reset the counters */
2533 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
2534}
2535
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002536static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
2537 struct xgbe_channel *channel)
2538{
2539 unsigned int tx_dsr, tx_pos, tx_qidx;
2540 unsigned int tx_status;
2541 unsigned long tx_timeout;
2542
2543 /* Calculate the status register to read and the position within */
2544 if (channel->queue_index < DMA_DSRX_FIRST_QUEUE) {
2545 tx_dsr = DMA_DSR0;
2546 tx_pos = (channel->queue_index * DMA_DSR_Q_WIDTH) +
2547 DMA_DSR0_TPS_START;
2548 } else {
2549 tx_qidx = channel->queue_index - DMA_DSRX_FIRST_QUEUE;
2550
2551 tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
2552 tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
2553 DMA_DSRX_TPS_START;
2554 }
2555
2556 /* The Tx engine cannot be stopped if it is actively processing
2557 * descriptors. Wait for the Tx engine to enter the stopped or
2558 * suspended state. Don't wait forever though...
2559 */
2560 tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
2561 while (time_before(jiffies, tx_timeout)) {
2562 tx_status = XGMAC_IOREAD(pdata, tx_dsr);
2563 tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
2564 if ((tx_status == DMA_TPS_STOPPED) ||
2565 (tx_status == DMA_TPS_SUSPENDED))
2566 break;
2567
2568 usleep_range(500, 1000);
2569 }
2570
2571 if (!time_before(jiffies, tx_timeout))
2572 netdev_info(pdata->netdev,
2573 "timed out waiting for Tx DMA channel %u to stop\n",
2574 channel->queue_index);
2575}
2576
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002577static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
2578{
2579 struct xgbe_channel *channel;
2580 unsigned int i;
2581
2582 /* Enable each Tx DMA channel */
2583 channel = pdata->channel;
2584 for (i = 0; i < pdata->channel_count; i++, channel++) {
2585 if (!channel->tx_ring)
2586 break;
2587
2588 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2589 }
2590
2591 /* Enable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002592 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002593 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
2594 MTL_Q_ENABLED);
2595
2596 /* Enable MAC Tx */
2597 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2598}
2599
2600static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
2601{
2602 struct xgbe_channel *channel;
2603 unsigned int i;
2604
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002605 /* Prepare for Tx DMA channel stop */
2606 channel = pdata->channel;
2607 for (i = 0; i < pdata->channel_count; i++, channel++) {
2608 if (!channel->tx_ring)
2609 break;
2610
2611 xgbe_prepare_tx_stop(pdata, channel);
2612 }
2613
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002614 /* Disable MAC Tx */
2615 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2616
2617 /* Disable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002618 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002619 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
2620
2621 /* Disable each Tx DMA channel */
2622 channel = pdata->channel;
2623 for (i = 0; i < pdata->channel_count; i++, channel++) {
2624 if (!channel->tx_ring)
2625 break;
2626
2627 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2628 }
2629}
2630
2631static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
2632{
2633 struct xgbe_channel *channel;
2634 unsigned int reg_val, i;
2635
2636 /* Enable each Rx DMA channel */
2637 channel = pdata->channel;
2638 for (i = 0; i < pdata->channel_count; i++, channel++) {
2639 if (!channel->rx_ring)
2640 break;
2641
2642 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2643 }
2644
2645 /* Enable each Rx queue */
2646 reg_val = 0;
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002647 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002648 reg_val |= (0x02 << (i << 1));
2649 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
2650
2651 /* Enable MAC Rx */
2652 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
2653 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
2654 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
2655 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
2656}
2657
2658static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
2659{
2660 struct xgbe_channel *channel;
2661 unsigned int i;
2662
2663 /* Disable MAC Rx */
2664 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
2665 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
2666 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
2667 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
2668
2669 /* Disable each Rx queue */
2670 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
2671
2672 /* Disable each Rx DMA channel */
2673 channel = pdata->channel;
2674 for (i = 0; i < pdata->channel_count; i++, channel++) {
2675 if (!channel->rx_ring)
2676 break;
2677
2678 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2679 }
2680}
2681
2682static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
2683{
2684 struct xgbe_channel *channel;
2685 unsigned int i;
2686
2687 /* Enable each Tx DMA channel */
2688 channel = pdata->channel;
2689 for (i = 0; i < pdata->channel_count; i++, channel++) {
2690 if (!channel->tx_ring)
2691 break;
2692
2693 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2694 }
2695
2696 /* Enable MAC Tx */
2697 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2698}
2699
2700static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
2701{
2702 struct xgbe_channel *channel;
2703 unsigned int i;
2704
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002705 /* Prepare for Tx DMA channel stop */
2706 channel = pdata->channel;
2707 for (i = 0; i < pdata->channel_count; i++, channel++) {
2708 if (!channel->tx_ring)
2709 break;
2710
2711 xgbe_prepare_tx_stop(pdata, channel);
2712 }
2713
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002714 /* Disable MAC Tx */
2715 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2716
2717 /* Disable each Tx DMA channel */
2718 channel = pdata->channel;
2719 for (i = 0; i < pdata->channel_count; i++, channel++) {
2720 if (!channel->tx_ring)
2721 break;
2722
2723 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2724 }
2725}
2726
2727static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2728{
2729 struct xgbe_channel *channel;
2730 unsigned int i;
2731
2732 /* Enable each Rx DMA channel */
2733 channel = pdata->channel;
2734 for (i = 0; i < pdata->channel_count; i++, channel++) {
2735 if (!channel->rx_ring)
2736 break;
2737
2738 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2739 }
2740}
2741
2742static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2743{
2744 struct xgbe_channel *channel;
2745 unsigned int i;
2746
2747 /* Disable each Rx DMA channel */
2748 channel = pdata->channel;
2749 for (i = 0; i < pdata->channel_count; i++, channel++) {
2750 if (!channel->rx_ring)
2751 break;
2752
2753 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2754 }
2755}
2756
2757static int xgbe_init(struct xgbe_prv_data *pdata)
2758{
2759 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2760 int ret;
2761
2762 DBGPR("-->xgbe_init\n");
2763
2764 /* Flush Tx queues */
2765 ret = xgbe_flush_tx_queues(pdata);
2766 if (ret)
2767 return ret;
2768
2769 /*
2770 * Initialize DMA related features
2771 */
2772 xgbe_config_dma_bus(pdata);
2773 xgbe_config_dma_cache(pdata);
2774 xgbe_config_osp_mode(pdata);
2775 xgbe_config_pblx8(pdata);
2776 xgbe_config_tx_pbl_val(pdata);
2777 xgbe_config_rx_pbl_val(pdata);
2778 xgbe_config_rx_coalesce(pdata);
2779 xgbe_config_tx_coalesce(pdata);
2780 xgbe_config_rx_buffer_size(pdata);
2781 xgbe_config_tso_mode(pdata);
Lendacky, Thomas174fd252014-11-04 16:06:50 -06002782 xgbe_config_sph_mode(pdata);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06002783 xgbe_config_rss(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002784 desc_if->wrapper_tx_desc_init(pdata);
2785 desc_if->wrapper_rx_desc_init(pdata);
2786 xgbe_enable_dma_interrupts(pdata);
2787
2788 /*
2789 * Initialize MTL related features
2790 */
2791 xgbe_config_mtl_mode(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002792 xgbe_config_queue_mapping(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002793 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2794 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2795 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2796 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2797 xgbe_config_tx_fifo_size(pdata);
2798 xgbe_config_rx_fifo_size(pdata);
2799 xgbe_config_flow_control_threshold(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002800 /*TODO: Error Packet and undersized good Packet forwarding enable
2801 (FEP and FUP)
2802 */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002803 xgbe_config_dcb_tc(pdata);
2804 xgbe_config_dcb_pfc(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002805 xgbe_enable_mtl_interrupts(pdata);
2806
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002807 /*
2808 * Initialize MAC related features
2809 */
2810 xgbe_config_mac_address(pdata);
2811 xgbe_config_jumbo_enable(pdata);
2812 xgbe_config_flow_control(pdata);
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002813 xgbe_config_mac_speed(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002814 xgbe_config_checksum_offload(pdata);
2815 xgbe_config_vlan_support(pdata);
2816 xgbe_config_mmc(pdata);
2817 xgbe_enable_mac_interrupts(pdata);
2818
2819 DBGPR("<--xgbe_init\n");
2820
2821 return 0;
2822}
2823
2824void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2825{
2826 DBGPR("-->xgbe_init_function_ptrs\n");
2827
2828 hw_if->tx_complete = xgbe_tx_complete;
2829
2830 hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
2831 hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05002832 hw_if->add_mac_addresses = xgbe_add_mac_addresses;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002833 hw_if->set_mac_address = xgbe_set_mac_address;
2834
2835 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2836 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2837
2838 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2839 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002840 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
2841 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
2842 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002843
2844 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2845 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2846
2847 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2848 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2849 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2850
2851 hw_if->enable_tx = xgbe_enable_tx;
2852 hw_if->disable_tx = xgbe_disable_tx;
2853 hw_if->enable_rx = xgbe_enable_rx;
2854 hw_if->disable_rx = xgbe_disable_rx;
2855
2856 hw_if->powerup_tx = xgbe_powerup_tx;
2857 hw_if->powerdown_tx = xgbe_powerdown_tx;
2858 hw_if->powerup_rx = xgbe_powerup_rx;
2859 hw_if->powerdown_rx = xgbe_powerdown_rx;
2860
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06002861 hw_if->dev_xmit = xgbe_dev_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002862 hw_if->dev_read = xgbe_dev_read;
2863 hw_if->enable_int = xgbe_enable_int;
2864 hw_if->disable_int = xgbe_disable_int;
2865 hw_if->init = xgbe_init;
2866 hw_if->exit = xgbe_exit;
2867
2868 /* Descriptor related Sequences have to be initialized here */
2869 hw_if->tx_desc_init = xgbe_tx_desc_init;
2870 hw_if->rx_desc_init = xgbe_rx_desc_init;
2871 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2872 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2873 hw_if->is_last_desc = xgbe_is_last_desc;
2874 hw_if->is_context_desc = xgbe_is_context_desc;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06002875 hw_if->tx_start_xmit = xgbe_tx_start_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002876
2877 /* For FLOW ctrl */
2878 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2879 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2880
2881 /* For RX coalescing */
2882 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2883 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2884 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2885 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2886
2887 /* For RX and TX threshold config */
2888 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2889 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2890
2891 /* For RX and TX Store and Forward Mode config */
2892 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2893 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2894
2895 /* For TX DMA Operating on Second Frame config */
2896 hw_if->config_osp_mode = xgbe_config_osp_mode;
2897
2898 /* For RX and TX PBL config */
2899 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2900 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2901 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2902 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2903 hw_if->config_pblx8 = xgbe_config_pblx8;
2904
2905 /* For MMC statistics support */
2906 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2907 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2908 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2909
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05002910 /* For PTP config */
2911 hw_if->config_tstamp = xgbe_config_tstamp;
2912 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
2913 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
2914 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
2915 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
2916
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002917 /* For Data Center Bridging config */
2918 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
2919 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
2920
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06002921 /* For Receive Side Scaling */
2922 hw_if->enable_rss = xgbe_enable_rss;
2923 hw_if->disable_rss = xgbe_disable_rss;
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -06002924 hw_if->set_rss_hash_key = xgbe_set_rss_hash_key;
2925 hw_if->set_rss_lookup_table = xgbe_set_rss_lookup_table;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06002926
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002927 DBGPR("<--xgbe_init_function_ptrs\n");
2928}