blob: 5dff127a08237bec743f8fe90d9654e0dfcb6980 [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>
118#include <linux/clk.h>
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500119#include <linux/bitrev.h>
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500120#include <linux/crc32.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500121
122#include "xgbe.h"
123#include "xgbe-common.h"
124
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500125static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
126 unsigned int usec)
127{
128 unsigned long rate;
129 unsigned int ret;
130
131 DBGPR("-->xgbe_usec_to_riwt\n");
132
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500133 rate = clk_get_rate(pdata->sysclk);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500134
135 /*
136 * Convert the input usec value to the watchdog timer value. Each
137 * watchdog timer value is equivalent to 256 clock cycles.
138 * Calculate the required value as:
139 * ( usec * ( system_clock_mhz / 10^6 ) / 256
140 */
141 ret = (usec * (rate / 1000000)) / 256;
142
143 DBGPR("<--xgbe_usec_to_riwt\n");
144
145 return ret;
146}
147
148static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
149 unsigned int riwt)
150{
151 unsigned long rate;
152 unsigned int ret;
153
154 DBGPR("-->xgbe_riwt_to_usec\n");
155
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500156 rate = clk_get_rate(pdata->sysclk);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500157
158 /*
159 * Convert the input watchdog timer value to the usec value. Each
160 * watchdog timer value is equivalent to 256 clock cycles.
161 * Calculate the required value as:
162 * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
163 */
164 ret = (riwt * 256) / (rate / 1000000);
165
166 DBGPR("<--xgbe_riwt_to_usec\n");
167
168 return ret;
169}
170
171static int xgbe_config_pblx8(struct xgbe_prv_data *pdata)
172{
173 struct xgbe_channel *channel;
174 unsigned int i;
175
176 channel = pdata->channel;
177 for (i = 0; i < pdata->channel_count; i++, channel++)
178 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8,
179 pdata->pblx8);
180
181 return 0;
182}
183
184static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata)
185{
186 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL);
187}
188
189static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata)
190{
191 struct xgbe_channel *channel;
192 unsigned int i;
193
194 channel = pdata->channel;
195 for (i = 0; i < pdata->channel_count; i++, channel++) {
196 if (!channel->tx_ring)
197 break;
198
199 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL,
200 pdata->tx_pbl);
201 }
202
203 return 0;
204}
205
206static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata)
207{
208 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL);
209}
210
211static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata)
212{
213 struct xgbe_channel *channel;
214 unsigned int i;
215
216 channel = pdata->channel;
217 for (i = 0; i < pdata->channel_count; i++, channel++) {
218 if (!channel->rx_ring)
219 break;
220
221 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL,
222 pdata->rx_pbl);
223 }
224
225 return 0;
226}
227
228static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
229{
230 struct xgbe_channel *channel;
231 unsigned int i;
232
233 channel = pdata->channel;
234 for (i = 0; i < pdata->channel_count; i++, channel++) {
235 if (!channel->tx_ring)
236 break;
237
238 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP,
239 pdata->tx_osp_mode);
240 }
241
242 return 0;
243}
244
245static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
246{
247 unsigned int i;
248
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500249 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500250 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
251
252 return 0;
253}
254
255static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
256{
257 unsigned int i;
258
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500259 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500260 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
261
262 return 0;
263}
264
265static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
266 unsigned int val)
267{
268 unsigned int i;
269
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500270 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500271 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
272
273 return 0;
274}
275
276static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
277 unsigned int val)
278{
279 unsigned int i;
280
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500281 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500282 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
283
284 return 0;
285}
286
287static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
288{
289 struct xgbe_channel *channel;
290 unsigned int i;
291
292 channel = pdata->channel;
293 for (i = 0; i < pdata->channel_count; i++, channel++) {
294 if (!channel->rx_ring)
295 break;
296
297 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT,
298 pdata->rx_riwt);
299 }
300
301 return 0;
302}
303
304static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
305{
306 return 0;
307}
308
309static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
310{
311 struct xgbe_channel *channel;
312 unsigned int i;
313
314 channel = pdata->channel;
315 for (i = 0; i < pdata->channel_count; i++, channel++) {
316 if (!channel->rx_ring)
317 break;
318
319 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ,
320 pdata->rx_buf_size);
321 }
322}
323
324static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
325{
326 struct xgbe_channel *channel;
327 unsigned int i;
328
329 channel = pdata->channel;
330 for (i = 0; i < pdata->channel_count; i++, channel++) {
331 if (!channel->tx_ring)
332 break;
333
334 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1);
335 }
336}
337
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600338static void xgbe_config_sph_mode(struct xgbe_prv_data *pdata)
339{
340 struct xgbe_channel *channel;
341 unsigned int i;
342
343 channel = pdata->channel;
344 for (i = 0; i < pdata->channel_count; i++, channel++) {
345 if (!channel->rx_ring)
346 break;
347
348 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, SPH, 1);
349 }
350
351 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE);
352}
353
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600354static int xgbe_write_rss_reg(struct xgbe_prv_data *pdata, unsigned int type,
355 unsigned int index, unsigned int val)
356{
357 unsigned int wait;
358 int ret = 0;
359
360 mutex_lock(&pdata->rss_mutex);
361
362 if (XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB)) {
363 ret = -EBUSY;
364 goto unlock;
365 }
366
367 XGMAC_IOWRITE(pdata, MAC_RSSDR, val);
368
369 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, RSSIA, index);
370 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, ADDRT, type);
371 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, CT, 0);
372 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, OB, 1);
373
374 wait = 1000;
375 while (wait--) {
376 if (!XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB))
377 goto unlock;
378
379 usleep_range(1000, 1500);
380 }
381
382 ret = -EBUSY;
383
384unlock:
385 mutex_unlock(&pdata->rss_mutex);
386
387 return ret;
388}
389
390static int xgbe_write_rss_hash_key(struct xgbe_prv_data *pdata)
391{
392 unsigned int key_regs = sizeof(pdata->rss_key) / sizeof(u32);
393 unsigned int *key = (unsigned int *)&pdata->rss_key;
394 int ret;
395
396 while (key_regs--) {
397 ret = xgbe_write_rss_reg(pdata, XGBE_RSS_HASH_KEY_TYPE,
398 key_regs, *key++);
399 if (ret)
400 return ret;
401 }
402
403 return 0;
404}
405
406static int xgbe_write_rss_lookup_table(struct xgbe_prv_data *pdata)
407{
408 unsigned int i;
409 int ret;
410
411 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) {
412 ret = xgbe_write_rss_reg(pdata,
413 XGBE_RSS_LOOKUP_TABLE_TYPE, i,
414 pdata->rss_table[i]);
415 if (ret)
416 return ret;
417 }
418
419 return 0;
420}
421
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600422static int xgbe_set_rss_hash_key(struct xgbe_prv_data *pdata, const u8 *key)
423{
424 memcpy(pdata->rss_key, key, sizeof(pdata->rss_key));
425
426 return xgbe_write_rss_hash_key(pdata);
427}
428
429static int xgbe_set_rss_lookup_table(struct xgbe_prv_data *pdata,
430 const u32 *table)
431{
432 unsigned int i;
433
434 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
435 XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, table[i]);
436
437 return xgbe_write_rss_lookup_table(pdata);
438}
439
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600440static int xgbe_enable_rss(struct xgbe_prv_data *pdata)
441{
442 int ret;
443
444 if (!pdata->hw_feat.rss)
445 return -EOPNOTSUPP;
446
447 /* Program the hash key */
448 ret = xgbe_write_rss_hash_key(pdata);
449 if (ret)
450 return ret;
451
452 /* Program the lookup table */
453 ret = xgbe_write_rss_lookup_table(pdata);
454 if (ret)
455 return ret;
456
457 /* Set the RSS options */
458 XGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options);
459
460 /* Enable RSS */
461 XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 1);
462
463 return 0;
464}
465
466static int xgbe_disable_rss(struct xgbe_prv_data *pdata)
467{
468 if (!pdata->hw_feat.rss)
469 return -EOPNOTSUPP;
470
471 XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 0);
472
473 return 0;
474}
475
476static void xgbe_config_rss(struct xgbe_prv_data *pdata)
477{
478 int ret;
479
480 if (!pdata->hw_feat.rss)
481 return;
482
483 if (pdata->netdev->features & NETIF_F_RXHASH)
484 ret = xgbe_enable_rss(pdata);
485 else
486 ret = xgbe_disable_rss(pdata);
487
488 if (ret)
489 netdev_err(pdata->netdev,
490 "error configuring RSS, RSS disabled\n");
491}
492
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500493static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
494{
495 unsigned int max_q_count, q_count;
496 unsigned int reg, reg_val;
497 unsigned int i;
498
499 /* Clear MTL flow control */
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500500 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500501 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
502
503 /* Clear MAC flow control */
504 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas9fc69af2014-08-29 13:17:08 -0500505 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500506 reg = MAC_Q0TFCR;
507 for (i = 0; i < q_count; i++) {
508 reg_val = XGMAC_IOREAD(pdata, reg);
509 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
510 XGMAC_IOWRITE(pdata, reg, reg_val);
511
512 reg += MAC_QTFCR_INC;
513 }
514
515 return 0;
516}
517
518static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
519{
520 unsigned int max_q_count, q_count;
521 unsigned int reg, reg_val;
522 unsigned int i;
523
524 /* Set MTL flow control */
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500525 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500526 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 1);
527
528 /* Set MAC flow control */
529 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas9fc69af2014-08-29 13:17:08 -0500530 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500531 reg = MAC_Q0TFCR;
532 for (i = 0; i < q_count; i++) {
533 reg_val = XGMAC_IOREAD(pdata, reg);
534
535 /* Enable transmit flow control */
536 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
537 /* Set pause time */
538 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
539
540 XGMAC_IOWRITE(pdata, reg, reg_val);
541
542 reg += MAC_QTFCR_INC;
543 }
544
545 return 0;
546}
547
548static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
549{
550 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
551
552 return 0;
553}
554
555static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
556{
557 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
558
559 return 0;
560}
561
562static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
563{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500564 struct ieee_pfc *pfc = pdata->pfc;
565
566 if (pdata->tx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500567 xgbe_enable_tx_flow_control(pdata);
568 else
569 xgbe_disable_tx_flow_control(pdata);
570
571 return 0;
572}
573
574static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
575{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500576 struct ieee_pfc *pfc = pdata->pfc;
577
578 if (pdata->rx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500579 xgbe_enable_rx_flow_control(pdata);
580 else
581 xgbe_disable_rx_flow_control(pdata);
582
583 return 0;
584}
585
586static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
587{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500588 struct ieee_pfc *pfc = pdata->pfc;
589
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500590 xgbe_config_tx_flow_control(pdata);
591 xgbe_config_rx_flow_control(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500592
593 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
594 (pfc && pfc->pfc_en) ? 1 : 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500595}
596
597static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
598{
599 struct xgbe_channel *channel;
600 unsigned int dma_ch_isr, dma_ch_ier;
601 unsigned int i;
602
603 channel = pdata->channel;
604 for (i = 0; i < pdata->channel_count; i++, channel++) {
605 /* Clear all the interrupts which are set */
606 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
607 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
608
609 /* Clear all interrupt enable bits */
610 dma_ch_ier = 0;
611
612 /* Enable following interrupts
613 * NIE - Normal Interrupt Summary Enable
614 * AIE - Abnormal Interrupt Summary Enable
615 * FBEE - Fatal Bus Error Enable
616 */
617 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
618 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
619 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
620
621 if (channel->tx_ring) {
622 /* Enable the following Tx interrupts
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600623 * TIE - Transmit Interrupt Enable (unless using
624 * per channel interrupts)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500625 */
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600626 if (!pdata->per_channel_irq)
627 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500628 }
629 if (channel->rx_ring) {
630 /* Enable following Rx interrupts
631 * RBUE - Receive Buffer Unavailable Enable
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600632 * RIE - Receive Interrupt Enable (unless using
633 * per channel interrupts)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500634 */
635 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600636 if (!pdata->per_channel_irq)
637 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500638 }
639
640 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
641 }
642}
643
644static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
645{
646 unsigned int mtl_q_isr;
647 unsigned int q_count, i;
648
649 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
650 for (i = 0; i < q_count; i++) {
651 /* Clear all the interrupts which are set */
652 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
653 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
654
655 /* No MTL interrupts to be enabled */
Lendacky, Thomas91f87342014-07-02 13:04:34 -0500656 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500657 }
658}
659
660static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
661{
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500662 unsigned int mac_ier = 0;
663
664 /* Enable Timestamp interrupt */
665 XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
666
667 XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500668
669 /* Enable all counter interrupts */
Lendacky, Thomasa3ba7c92014-09-05 18:02:36 -0500670 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
671 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500672}
673
674static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
675{
676 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
677
678 return 0;
679}
680
681static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
682{
683 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
684
685 return 0;
686}
687
688static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
689{
690 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
691
692 return 0;
693}
694
695static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
696 unsigned int enable)
697{
698 unsigned int val = enable ? 1 : 0;
699
700 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
701 return 0;
702
703 DBGPR(" %s promiscuous mode\n", enable ? "entering" : "leaving");
704 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
705
706 return 0;
707}
708
709static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
710 unsigned int enable)
711{
712 unsigned int val = enable ? 1 : 0;
713
714 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
715 return 0;
716
717 DBGPR(" %s allmulti mode\n", enable ? "entering" : "leaving");
718 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
719
720 return 0;
721}
722
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500723static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
724 struct netdev_hw_addr *ha, unsigned int *mac_reg)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500725{
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500726 unsigned int mac_addr_hi, mac_addr_lo;
727 u8 *mac_addr;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500728
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500729 mac_addr_lo = 0;
730 mac_addr_hi = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500731
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500732 if (ha) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500733 mac_addr = (u8 *)&mac_addr_lo;
734 mac_addr[0] = ha->addr[0];
735 mac_addr[1] = ha->addr[1];
736 mac_addr[2] = ha->addr[2];
737 mac_addr[3] = ha->addr[3];
738 mac_addr = (u8 *)&mac_addr_hi;
739 mac_addr[0] = ha->addr[4];
740 mac_addr[1] = ha->addr[5];
741
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500742 DBGPR(" adding mac address %pM at 0x%04x\n", ha->addr,
743 *mac_reg);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500744
745 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500746 }
747
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500748 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
749 *mac_reg += MAC_MACA_INC;
750 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
751 *mac_reg += MAC_MACA_INC;
752}
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500753
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500754static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
755{
756 struct net_device *netdev = pdata->netdev;
757 struct netdev_hw_addr *ha;
758 unsigned int mac_reg;
759 unsigned int addn_macs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500760
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500761 mac_reg = MAC_MACA1HR;
762 addn_macs = pdata->hw_feat.addn_mac;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500763
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500764 if (netdev_uc_count(netdev) > addn_macs) {
765 xgbe_set_promiscuous_mode(pdata, 1);
766 } else {
767 netdev_for_each_uc_addr(ha, netdev) {
768 xgbe_set_mac_reg(pdata, ha, &mac_reg);
769 addn_macs--;
770 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500771
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500772 if (netdev_mc_count(netdev) > addn_macs) {
773 xgbe_set_all_multicast_mode(pdata, 1);
774 } else {
775 netdev_for_each_mc_addr(ha, netdev) {
776 xgbe_set_mac_reg(pdata, ha, &mac_reg);
777 addn_macs--;
778 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500779 }
780 }
781
782 /* Clear remaining additional MAC address entries */
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500783 while (addn_macs--)
784 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
785}
786
787static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
788{
789 struct net_device *netdev = pdata->netdev;
790 struct netdev_hw_addr *ha;
791 unsigned int hash_reg;
792 unsigned int hash_table_shift, hash_table_count;
793 u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
794 u32 crc;
795 unsigned int i;
796
797 hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
798 hash_table_count = pdata->hw_feat.hash_table_size / 32;
799 memset(hash_table, 0, sizeof(hash_table));
800
801 /* Build the MAC Hash Table register values */
802 netdev_for_each_uc_addr(ha, netdev) {
803 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
804 crc >>= hash_table_shift;
805 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500806 }
807
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500808 netdev_for_each_mc_addr(ha, netdev) {
809 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
810 crc >>= hash_table_shift;
811 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
812 }
813
814 /* Set the MAC Hash Table registers */
815 hash_reg = MAC_HTR0;
816 for (i = 0; i < hash_table_count; i++) {
817 XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
818 hash_reg += MAC_HTR_INC;
819 }
820}
821
822static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
823{
824 if (pdata->hw_feat.hash_table_size)
825 xgbe_set_mac_hash_table(pdata);
826 else
827 xgbe_set_mac_addn_addrs(pdata);
828
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500829 return 0;
830}
831
832static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
833{
834 unsigned int mac_addr_hi, mac_addr_lo;
835
836 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
837 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
838 (addr[1] << 8) | (addr[0] << 0);
839
840 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
841 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
842
843 return 0;
844}
845
846static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
847 int mmd_reg)
848{
849 unsigned int mmd_address;
850 int mmd_data;
851
852 if (mmd_reg & MII_ADDR_C45)
853 mmd_address = mmd_reg & ~MII_ADDR_C45;
854 else
855 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
856
857 /* The PCS registers are accessed using mmio. The underlying APB3
858 * management interface uses indirect addressing to access the MMD
859 * register sets. This requires accessing of the PCS register in two
860 * phases, an address phase and a data phase.
861 *
862 * The mmio interface is based on 32-bit offsets and values. All
863 * register offsets must therefore be adjusted by left shifting the
864 * offset 2 bits and reading 32 bits of data.
865 */
866 mutex_lock(&pdata->xpcs_mutex);
867 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
868 mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
869 mutex_unlock(&pdata->xpcs_mutex);
870
871 return mmd_data;
872}
873
874static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
875 int mmd_reg, int mmd_data)
876{
877 unsigned int mmd_address;
878
879 if (mmd_reg & MII_ADDR_C45)
880 mmd_address = mmd_reg & ~MII_ADDR_C45;
881 else
882 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
883
884 /* The PCS registers are accessed using mmio. The underlying APB3
885 * management interface uses indirect addressing to access the MMD
886 * register sets. This requires accessing of the PCS register in two
887 * phases, an address phase and a data phase.
888 *
889 * The mmio interface is based on 32-bit offsets and values. All
890 * register offsets must therefore be adjusted by left shifting the
891 * offset 2 bits and reading 32 bits of data.
892 */
893 mutex_lock(&pdata->xpcs_mutex);
894 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
895 XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
896 mutex_unlock(&pdata->xpcs_mutex);
897}
898
899static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
900{
901 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
902}
903
904static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
905{
906 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
907
908 return 0;
909}
910
911static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
912{
913 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
914
915 return 0;
916}
917
918static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
919{
920 /* Put the VLAN tag in the Rx descriptor */
921 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
922
923 /* Don't check the VLAN type */
924 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
925
926 /* Check only C-TAG (0x8100) packets */
927 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
928
929 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
930 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
931
932 /* Enable VLAN tag stripping */
933 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
934
935 return 0;
936}
937
938static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
939{
940 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
941
942 return 0;
943}
944
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500945static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
946{
947 /* Enable VLAN filtering */
948 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
949
950 /* Enable VLAN Hash Table filtering */
951 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
952
953 /* Disable VLAN tag inverse matching */
954 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
955
956 /* Only filter on the lower 12-bits of the VLAN tag */
957 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
958
959 /* In order for the VLAN Hash Table filtering to be effective,
960 * the VLAN tag identifier in the VLAN Tag Register must not
961 * be zero. Set the VLAN tag identifier to "1" to enable the
962 * VLAN Hash Table filtering. This implies that a VLAN tag of
963 * 1 will always pass filtering.
964 */
965 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
966
967 return 0;
968}
969
970static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
971{
972 /* Disable VLAN filtering */
973 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
974
975 return 0;
976}
977
978#ifndef CRCPOLY_LE
979#define CRCPOLY_LE 0xedb88320
980#endif
981static u32 xgbe_vid_crc32_le(__le16 vid_le)
982{
983 u32 poly = CRCPOLY_LE;
984 u32 crc = ~0;
985 u32 temp = 0;
986 unsigned char *data = (unsigned char *)&vid_le;
987 unsigned char data_byte = 0;
988 int i, bits;
989
990 bits = get_bitmask_order(VLAN_VID_MASK);
991 for (i = 0; i < bits; i++) {
992 if ((i % 8) == 0)
993 data_byte = data[i / 8];
994
995 temp = ((crc & 1) ^ data_byte) & 1;
996 crc >>= 1;
997 data_byte >>= 1;
998
999 if (temp)
1000 crc ^= poly;
1001 }
1002
1003 return crc;
1004}
1005
1006static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
1007{
1008 u32 crc;
1009 u16 vid;
1010 __le16 vid_le;
1011 u16 vlan_hash_table = 0;
1012
1013 /* Generate the VLAN Hash Table value */
1014 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
1015 /* Get the CRC32 value of the VLAN ID */
1016 vid_le = cpu_to_le16(vid);
1017 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
1018
1019 vlan_hash_table |= (1 << crc);
1020 }
1021
1022 /* Set the VLAN Hash Table filtering register */
1023 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
1024
1025 return 0;
1026}
1027
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001028static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
1029{
1030 struct xgbe_ring_desc *rdesc = rdata->rdesc;
1031
1032 /* Reset the Tx descriptor
1033 * Set buffer 1 (lo) address to zero
1034 * Set buffer 1 (hi) address to zero
1035 * Reset all other control bits (IC, TTSE, B2L & B1L)
1036 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
1037 */
1038 rdesc->desc0 = 0;
1039 rdesc->desc1 = 0;
1040 rdesc->desc2 = 0;
1041 rdesc->desc3 = 0;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001042
1043 /* Make sure ownership is written to the descriptor */
1044 wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001045}
1046
1047static void xgbe_tx_desc_init(struct xgbe_channel *channel)
1048{
1049 struct xgbe_ring *ring = channel->tx_ring;
1050 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001051 int i;
1052 int start_index = ring->cur;
1053
1054 DBGPR("-->tx_desc_init\n");
1055
1056 /* Initialze all descriptors */
1057 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001058 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001059
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001060 /* Initialize Tx descriptor */
1061 xgbe_tx_desc_reset(rdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001062 }
1063
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001064 /* Update the total number of Tx descriptors */
1065 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
1066
1067 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001068 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001069 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
1070 upper_32_bits(rdata->rdesc_dma));
1071 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
1072 lower_32_bits(rdata->rdesc_dma));
1073
1074 DBGPR("<--tx_desc_init\n");
1075}
1076
1077static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
1078{
1079 struct xgbe_ring_desc *rdesc = rdata->rdesc;
1080
1081 /* Reset the Rx descriptor
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001082 * Set buffer 1 (lo) address to header dma address (lo)
1083 * Set buffer 1 (hi) address to header dma address (hi)
1084 * Set buffer 2 (lo) address to buffer dma address (lo)
1085 * Set buffer 2 (hi) address to buffer dma address (hi) and
1086 * set control bits OWN and INTE
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001087 */
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001088 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->rx.hdr.dma));
1089 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->rx.hdr.dma));
1090 rdesc->desc2 = cpu_to_le32(lower_32_bits(rdata->rx.buf.dma));
1091 rdesc->desc3 = cpu_to_le32(upper_32_bits(rdata->rx.buf.dma));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001092
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001093 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE,
1094 rdata->interrupt ? 1 : 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001095
1096 /* Since the Rx DMA engine is likely running, make sure everything
1097 * is written to the descriptor(s) before setting the OWN bit
1098 * for the descriptor
1099 */
1100 wmb();
1101
1102 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
1103
1104 /* Make sure ownership is written to the descriptor */
1105 wmb();
1106}
1107
1108static void xgbe_rx_desc_init(struct xgbe_channel *channel)
1109{
1110 struct xgbe_prv_data *pdata = channel->pdata;
1111 struct xgbe_ring *ring = channel->rx_ring;
1112 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001113 unsigned int start_index = ring->cur;
1114 unsigned int rx_coalesce, rx_frames;
1115 unsigned int i;
1116
1117 DBGPR("-->rx_desc_init\n");
1118
1119 rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
1120 rx_frames = pdata->rx_frames;
1121
1122 /* Initialize all descriptors */
1123 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001124 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001125
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001126 /* Set interrupt on completion bit as appropriate */
1127 if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames)))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001128 rdata->interrupt = 0;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001129 else
1130 rdata->interrupt = 1;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001131
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001132 /* Initialize Rx descriptor */
1133 xgbe_rx_desc_reset(rdata);
1134 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001135
1136 /* Update the total number of Rx descriptors */
1137 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
1138
1139 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001140 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001141 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
1142 upper_32_bits(rdata->rdesc_dma));
1143 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
1144 lower_32_bits(rdata->rdesc_dma));
1145
1146 /* Update the Rx Descriptor Tail Pointer */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001147 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001148 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
1149 lower_32_bits(rdata->rdesc_dma));
1150
1151 DBGPR("<--rx_desc_init\n");
1152}
1153
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001154static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
1155 unsigned int addend)
1156{
1157 /* Set the addend register value and tell the device */
1158 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1159 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1160
1161 /* Wait for addend update to complete */
1162 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1163 udelay(5);
1164}
1165
1166static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1167 unsigned int nsec)
1168{
1169 /* Set the time values and tell the device */
1170 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1171 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1172 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1173
1174 /* Wait for time update to complete */
1175 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1176 udelay(5);
1177}
1178
1179static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1180{
1181 u64 nsec;
1182
1183 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1184 nsec *= NSEC_PER_SEC;
1185 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1186
1187 return nsec;
1188}
1189
1190static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1191{
1192 unsigned int tx_snr;
1193 u64 nsec;
1194
1195 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1196 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1197 return 0;
1198
1199 nsec = XGMAC_IOREAD(pdata, MAC_TXSSR);
1200 nsec *= NSEC_PER_SEC;
1201 nsec += tx_snr;
1202
1203 return nsec;
1204}
1205
1206static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1207 struct xgbe_ring_desc *rdesc)
1208{
1209 u64 nsec;
1210
1211 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1212 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1213 nsec = le32_to_cpu(rdesc->desc1);
1214 nsec <<= 32;
1215 nsec |= le32_to_cpu(rdesc->desc0);
1216 if (nsec != 0xffffffffffffffffULL) {
1217 packet->rx_tstamp = nsec;
1218 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1219 RX_TSTAMP, 1);
1220 }
1221 }
1222}
1223
1224static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1225 unsigned int mac_tscr)
1226{
1227 /* Set one nano-second accuracy */
1228 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1229
1230 /* Set fine timestamp update */
1231 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1232
1233 /* Overwrite earlier timestamps */
1234 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1235
1236 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1237
1238 /* Exit if timestamping is not enabled */
1239 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1240 return 0;
1241
1242 /* Initialize time registers */
1243 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1244 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1245 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1246 xgbe_set_tstamp_time(pdata, 0, 0);
1247
1248 /* Initialize the timecounter */
1249 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1250 ktime_to_ns(ktime_get_real()));
1251
1252 return 0;
1253}
1254
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001255static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
1256{
1257 struct ieee_ets *ets = pdata->ets;
1258 unsigned int total_weight, min_weight, weight;
1259 unsigned int i;
1260
1261 if (!ets)
1262 return;
1263
1264 /* Set Tx to deficit weighted round robin scheduling algorithm (when
1265 * traffic class is using ETS algorithm)
1266 */
1267 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
1268
1269 /* Set Traffic Class algorithms */
1270 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
1271 min_weight = total_weight / 100;
1272 if (!min_weight)
1273 min_weight = 1;
1274
1275 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1276 switch (ets->tc_tsa[i]) {
1277 case IEEE_8021QAZ_TSA_STRICT:
1278 DBGPR(" TC%u using SP\n", i);
1279 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1280 MTL_TSA_SP);
1281 break;
1282 case IEEE_8021QAZ_TSA_ETS:
1283 weight = total_weight * ets->tc_tx_bw[i] / 100;
1284 weight = clamp(weight, min_weight, total_weight);
1285
1286 DBGPR(" TC%u using DWRR (weight %u)\n", i, weight);
1287 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1288 MTL_TSA_ETS);
1289 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
1290 weight);
1291 break;
1292 }
1293 }
1294}
1295
1296static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
1297{
1298 struct ieee_pfc *pfc = pdata->pfc;
1299 struct ieee_ets *ets = pdata->ets;
1300 unsigned int mask, reg, reg_val;
1301 unsigned int tc, prio;
1302
1303 if (!pfc || !ets)
1304 return;
1305
1306 for (tc = 0; tc < pdata->hw_feat.tc_cnt; tc++) {
1307 mask = 0;
1308 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
1309 if ((pfc->pfc_en & (1 << prio)) &&
1310 (ets->prio_tc[prio] == tc))
1311 mask |= (1 << prio);
1312 }
1313 mask &= 0xff;
1314
1315 DBGPR(" TC%u PFC mask=%#x\n", tc, mask);
1316 reg = MTL_TCPM0R + (MTL_TCPM_INC * (tc / MTL_TCPM_TC_PER_REG));
1317 reg_val = XGMAC_IOREAD(pdata, reg);
1318
1319 reg_val &= ~(0xff << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1320 reg_val |= (mask << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1321
1322 XGMAC_IOWRITE(pdata, reg, reg_val);
1323 }
1324
1325 xgbe_config_flow_control(pdata);
1326}
1327
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001328static void xgbe_tx_start_xmit(struct xgbe_channel *channel,
1329 struct xgbe_ring *ring)
1330{
1331 struct xgbe_prv_data *pdata = channel->pdata;
1332 struct xgbe_ring_data *rdata;
1333
1334 /* Issue a poll command to Tx DMA by writing address
1335 * of next immediate free descriptor */
1336 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1337 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1338 lower_32_bits(rdata->rdesc_dma));
1339
1340 /* Start the Tx coalescing timer */
1341 if (pdata->tx_usecs && !channel->tx_timer_active) {
1342 channel->tx_timer_active = 1;
1343 hrtimer_start(&channel->tx_timer,
1344 ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
1345 HRTIMER_MODE_REL);
1346 }
1347
1348 ring->tx.xmit_more = 0;
1349}
1350
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001351static void xgbe_dev_xmit(struct xgbe_channel *channel)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001352{
1353 struct xgbe_prv_data *pdata = channel->pdata;
1354 struct xgbe_ring *ring = channel->tx_ring;
1355 struct xgbe_ring_data *rdata;
1356 struct xgbe_ring_desc *rdesc;
1357 struct xgbe_packet_data *packet = &ring->packet_data;
1358 unsigned int csum, tso, vlan;
1359 unsigned int tso_context, vlan_context;
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001360 unsigned int tx_set_ic;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001361 int start_index = ring->cur;
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001362 int cur_index = ring->cur;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001363 int i;
1364
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001365 DBGPR("-->xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001366
1367 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1368 CSUM_ENABLE);
1369 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1370 TSO_ENABLE);
1371 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1372 VLAN_CTAG);
1373
1374 if (tso && (packet->mss != ring->tx.cur_mss))
1375 tso_context = 1;
1376 else
1377 tso_context = 0;
1378
1379 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1380 vlan_context = 1;
1381 else
1382 vlan_context = 0;
1383
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001384 /* Determine if an interrupt should be generated for this Tx:
1385 * Interrupt:
1386 * - Tx frame count exceeds the frame count setting
1387 * - Addition of Tx frame count to the frame count since the
1388 * last interrupt was set exceeds the frame count setting
1389 * No interrupt:
1390 * - No frame count setting specified (ethtool -C ethX tx-frames 0)
1391 * - Addition of Tx frame count to the frame count since the
1392 * last interrupt was set does not exceed the frame count setting
1393 */
1394 ring->coalesce_count += packet->tx_packets;
1395 if (!pdata->tx_frames)
1396 tx_set_ic = 0;
1397 else if (packet->tx_packets > pdata->tx_frames)
1398 tx_set_ic = 1;
1399 else if ((ring->coalesce_count % pdata->tx_frames) <
1400 packet->tx_packets)
1401 tx_set_ic = 1;
1402 else
1403 tx_set_ic = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001404
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001405 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001406 rdesc = rdata->rdesc;
1407
1408 /* Create a context descriptor if this is a TSO packet */
1409 if (tso_context || vlan_context) {
1410 if (tso_context) {
1411 DBGPR(" TSO context descriptor, mss=%u\n",
1412 packet->mss);
1413
1414 /* Set the MSS size */
1415 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1416 MSS, packet->mss);
1417
1418 /* Mark it as a CONTEXT descriptor */
1419 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1420 CTXT, 1);
1421
1422 /* Indicate this descriptor contains the MSS */
1423 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1424 TCMSSV, 1);
1425
1426 ring->tx.cur_mss = packet->mss;
1427 }
1428
1429 if (vlan_context) {
1430 DBGPR(" VLAN context descriptor, ctag=%u\n",
1431 packet->vlan_ctag);
1432
1433 /* Mark it as a CONTEXT descriptor */
1434 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1435 CTXT, 1);
1436
1437 /* Set the VLAN tag */
1438 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1439 VT, packet->vlan_ctag);
1440
1441 /* Indicate this descriptor contains the VLAN tag */
1442 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1443 VLTV, 1);
1444
1445 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1446 }
1447
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001448 cur_index++;
1449 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001450 rdesc = rdata->rdesc;
1451 }
1452
1453 /* Update buffer address (for TSO this is the header) */
1454 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1455 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1456
1457 /* Update the buffer length */
1458 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1459 rdata->skb_dma_len);
1460
1461 /* VLAN tag insertion check */
1462 if (vlan)
1463 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1464 TX_NORMAL_DESC2_VLAN_INSERT);
1465
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001466 /* Timestamp enablement check */
1467 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1468 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1469
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001470 /* Mark it as First Descriptor */
1471 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1472
1473 /* Mark it as a NORMAL descriptor */
1474 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1475
1476 /* Set OWN bit if not the first descriptor */
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001477 if (cur_index != start_index)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001478 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1479
1480 if (tso) {
1481 /* Enable TSO */
1482 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1483 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1484 packet->tcp_payload_len);
1485 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1486 packet->tcp_header_len / 4);
1487 } else {
1488 /* Enable CRC and Pad Insertion */
1489 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1490
1491 /* Enable HW CSUM */
1492 if (csum)
1493 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1494 CIC, 0x3);
1495
1496 /* Set the total length to be transmitted */
1497 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1498 packet->length);
1499 }
1500
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001501 for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) {
1502 cur_index++;
1503 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001504 rdesc = rdata->rdesc;
1505
1506 /* Update buffer address */
1507 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1508 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1509
1510 /* Update the buffer length */
1511 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1512 rdata->skb_dma_len);
1513
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001514 /* Set OWN bit */
1515 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1516
1517 /* Mark it as NORMAL descriptor */
1518 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1519
1520 /* Enable HW CSUM */
1521 if (csum)
1522 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1523 CIC, 0x3);
1524 }
1525
1526 /* Set LAST bit for the last descriptor */
1527 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1528
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001529 /* Set IC bit based on Tx coalescing settings */
1530 if (tx_set_ic)
1531 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1532
Lendacky, Thomas5fb4b862014-11-20 11:03:50 -06001533 /* Save the Tx info to report back during cleanup */
1534 rdata->tx.packets = packet->tx_packets;
1535 rdata->tx.bytes = packet->tx_bytes;
1536
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001537 /* In case the Tx DMA engine is running, make sure everything
1538 * is written to the descriptor(s) before setting the OWN bit
1539 * for the first descriptor
1540 */
1541 wmb();
1542
1543 /* Set OWN bit for the first descriptor */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001544 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001545 rdesc = rdata->rdesc;
1546 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1547
1548#ifdef XGMAC_ENABLE_TX_DESC_DUMP
1549 xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
1550#endif
1551
1552 /* Make sure ownership is written to the descriptor */
1553 wmb();
1554
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001555 ring->cur = cur_index + 1;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001556 if (!packet->skb->xmit_more ||
1557 netif_xmit_stopped(netdev_get_tx_queue(pdata->netdev,
1558 channel->queue_index)))
1559 xgbe_tx_start_xmit(channel, ring);
1560 else
1561 ring->tx.xmit_more = 1;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001562
1563 DBGPR(" %s: descriptors %u to %u written\n",
1564 channel->name, start_index & (ring->rdesc_count - 1),
1565 (ring->cur - 1) & (ring->rdesc_count - 1));
1566
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001567 DBGPR("<--xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001568}
1569
1570static int xgbe_dev_read(struct xgbe_channel *channel)
1571{
1572 struct xgbe_ring *ring = channel->rx_ring;
1573 struct xgbe_ring_data *rdata;
1574 struct xgbe_ring_desc *rdesc;
1575 struct xgbe_packet_data *packet = &ring->packet_data;
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001576 struct net_device *netdev = channel->pdata->netdev;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001577 unsigned int err, etlt, l34t;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001578
1579 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1580
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001581 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001582 rdesc = rdata->rdesc;
1583
1584 /* Check for data availability */
1585 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1586 return 1;
1587
Lendacky, Thomas5449e272014-11-20 11:03:26 -06001588 /* Make sure descriptor fields are read after reading the OWN bit */
1589 rmb();
1590
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001591#ifdef XGMAC_ENABLE_RX_DESC_DUMP
1592 xgbe_dump_rx_desc(ring, rdesc, ring->cur);
1593#endif
1594
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001595 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1596 /* Timestamp Context Descriptor */
1597 xgbe_get_rx_tstamp(packet, rdesc);
1598
1599 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1600 CONTEXT, 1);
1601 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1602 CONTEXT_NEXT, 0);
1603 return 0;
1604 }
1605
1606 /* Normal Descriptor, be sure Context Descriptor bit is off */
1607 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1608
1609 /* Indicate if a Context Descriptor is next */
1610 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1611 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1612 CONTEXT_NEXT, 1);
1613
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001614 /* Get the header length */
1615 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD))
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001616 rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2,
1617 RX_NORMAL_DESC2, HL);
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001618
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001619 /* Get the RSS hash */
1620 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, RSV)) {
1621 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1622 RSS_HASH, 1);
1623
1624 packet->rss_hash = le32_to_cpu(rdesc->desc1);
1625
1626 l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T);
1627 switch (l34t) {
1628 case RX_DESC3_L34T_IPV4_TCP:
1629 case RX_DESC3_L34T_IPV4_UDP:
1630 case RX_DESC3_L34T_IPV6_TCP:
1631 case RX_DESC3_L34T_IPV6_UDP:
1632 packet->rss_hash_type = PKT_HASH_TYPE_L4;
Dan Carpenterb6267d32014-11-13 09:19:06 +03001633 break;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001634 default:
1635 packet->rss_hash_type = PKT_HASH_TYPE_L3;
1636 }
1637 }
1638
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001639 /* Get the packet length */
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001640 rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001641
1642 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1643 /* Not all the data has been transferred for this packet */
1644 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1645 INCOMPLETE, 1);
1646 return 0;
1647 }
1648
1649 /* This is the last of the data for this packet */
1650 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1651 INCOMPLETE, 0);
1652
1653 /* Set checksum done indicator as appropriate */
1654 if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
1655 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1656 CSUM_DONE, 1);
1657
1658 /* Check for errors (only valid in last descriptor) */
1659 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1660 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1661 DBGPR(" err=%u, etlt=%#x\n", err, etlt);
1662
Lendacky, Thomas7bba35b2014-11-20 11:03:38 -06001663 if (!err || !etlt) {
1664 /* No error if err is 0 or etlt is 0 */
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001665 if ((etlt == 0x09) &&
1666 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001667 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1668 VLAN_CTAG, 1);
1669 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1670 RX_NORMAL_DESC0,
1671 OVT);
1672 DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
1673 }
1674 } else {
1675 if ((etlt == 0x05) || (etlt == 0x06))
1676 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1677 CSUM_DONE, 0);
1678 else
1679 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1680 FRAME, 1);
1681 }
1682
1683 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1684 ring->cur & (ring->rdesc_count - 1), ring->cur);
1685
1686 return 0;
1687}
1688
1689static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1690{
1691 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1692 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1693}
1694
1695static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1696{
1697 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1698 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1699}
1700
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001701static int xgbe_enable_int(struct xgbe_channel *channel,
1702 enum xgbe_int int_id)
1703{
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001704 unsigned int dma_ch_ier;
1705
1706 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1707
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001708 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001709 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001710 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001711 break;
1712 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001713 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001714 break;
1715 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001716 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001717 break;
1718 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001719 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001720 break;
1721 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001722 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001723 break;
1724 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001725 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1726 break;
1727 case XGMAC_INT_DMA_CH_SR_TI_RI:
1728 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1729 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001730 break;
1731 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001732 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001733 break;
1734 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001735 dma_ch_ier |= channel->saved_ier;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001736 break;
1737 default:
1738 return -1;
1739 }
1740
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001741 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1742
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001743 return 0;
1744}
1745
1746static int xgbe_disable_int(struct xgbe_channel *channel,
1747 enum xgbe_int int_id)
1748{
1749 unsigned int dma_ch_ier;
1750
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001751 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1752
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001753 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001754 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001755 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001756 break;
1757 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001758 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001759 break;
1760 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001761 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001762 break;
1763 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001764 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001765 break;
1766 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001767 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001768 break;
1769 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001770 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1771 break;
1772 case XGMAC_INT_DMA_CH_SR_TI_RI:
1773 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1774 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001775 break;
1776 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001777 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001778 break;
1779 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001780 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001781 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001782 break;
1783 default:
1784 return -1;
1785 }
1786
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001787 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1788
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001789 return 0;
1790}
1791
1792static int xgbe_exit(struct xgbe_prv_data *pdata)
1793{
1794 unsigned int count = 2000;
1795
1796 DBGPR("-->xgbe_exit\n");
1797
1798 /* Issue a software reset */
1799 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1800 usleep_range(10, 15);
1801
1802 /* Poll Until Poll Condition */
1803 while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1804 usleep_range(500, 600);
1805
1806 if (!count)
1807 return -EBUSY;
1808
1809 DBGPR("<--xgbe_exit\n");
1810
1811 return 0;
1812}
1813
1814static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1815{
1816 unsigned int i, count;
1817
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -05001818 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
1819 return 0;
1820
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001821 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001822 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1823
1824 /* Poll Until Poll Condition */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001825 for (i = 0; i < pdata->tx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001826 count = 2000;
1827 while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
1828 MTL_Q_TQOMR, FTQ))
1829 usleep_range(500, 600);
1830
1831 if (!count)
1832 return -EBUSY;
1833 }
1834
1835 return 0;
1836}
1837
1838static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1839{
1840 /* Set enhanced addressing mode */
1841 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1842
1843 /* Set the System Bus mode */
1844 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001845 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001846}
1847
1848static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1849{
1850 unsigned int arcache, awcache;
1851
1852 arcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001853 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
1854 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
1855 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
1856 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
1857 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
1858 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001859 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1860
1861 awcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001862 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
1863 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
1864 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
1865 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
1866 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
1867 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
1868 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
1869 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001870 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1871}
1872
1873static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1874{
1875 unsigned int i;
1876
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001877 /* Set Tx to weighted round robin scheduling algorithm */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001878 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1879
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001880 /* Set Tx traffic classes to use WRR algorithm with equal weights */
1881 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1882 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1883 MTL_TSA_ETS);
1884 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
1885 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001886
1887 /* Set Rx to strict priority algorithm */
1888 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1889}
1890
Lendacky, Thomasf076f452014-08-29 13:16:56 -05001891static unsigned int xgbe_calculate_per_queue_fifo(unsigned int fifo_size,
1892 unsigned int queue_count)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001893{
1894 unsigned int q_fifo_size = 0;
1895 enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1896
1897 /* Calculate Tx/Rx fifo share per queue */
1898 switch (fifo_size) {
1899 case 0:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001900 q_fifo_size = XGBE_FIFO_SIZE_B(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001901 break;
1902 case 1:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001903 q_fifo_size = XGBE_FIFO_SIZE_B(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001904 break;
1905 case 2:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001906 q_fifo_size = XGBE_FIFO_SIZE_B(512);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001907 break;
1908 case 3:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001909 q_fifo_size = XGBE_FIFO_SIZE_KB(1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001910 break;
1911 case 4:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001912 q_fifo_size = XGBE_FIFO_SIZE_KB(2);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001913 break;
1914 case 5:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001915 q_fifo_size = XGBE_FIFO_SIZE_KB(4);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001916 break;
1917 case 6:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001918 q_fifo_size = XGBE_FIFO_SIZE_KB(8);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001919 break;
1920 case 7:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001921 q_fifo_size = XGBE_FIFO_SIZE_KB(16);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001922 break;
1923 case 8:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001924 q_fifo_size = XGBE_FIFO_SIZE_KB(32);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001925 break;
1926 case 9:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001927 q_fifo_size = XGBE_FIFO_SIZE_KB(64);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001928 break;
1929 case 10:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001930 q_fifo_size = XGBE_FIFO_SIZE_KB(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001931 break;
1932 case 11:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001933 q_fifo_size = XGBE_FIFO_SIZE_KB(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001934 break;
1935 }
Lendacky, Thomasf076f452014-08-29 13:16:56 -05001936
1937 /* The configured value is not the actual amount of fifo RAM */
1938 q_fifo_size = min_t(unsigned int, XGBE_FIFO_MAX, q_fifo_size);
1939
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001940 q_fifo_size = q_fifo_size / queue_count;
1941
1942 /* Set the queue fifo size programmable value */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001943 if (q_fifo_size >= XGBE_FIFO_SIZE_KB(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001944 p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001945 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(128))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001946 p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001947 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(64))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001948 p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001949 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(32))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001950 p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001951 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(16))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001952 p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001953 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(8))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001954 p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001955 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(4))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001956 p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001957 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(2))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001958 p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001959 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(1))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001960 p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001961 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(512))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001962 p_fifo = XGMAC_MTL_FIFO_SIZE_512;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001963 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001964 p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1965
1966 return p_fifo;
1967}
1968
1969static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
1970{
1971 enum xgbe_mtl_fifo_size fifo_size;
1972 unsigned int i;
1973
1974 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001975 pdata->tx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001976
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001977 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001978 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
1979
1980 netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001981 pdata->tx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001982}
1983
1984static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
1985{
1986 enum xgbe_mtl_fifo_size fifo_size;
1987 unsigned int i;
1988
1989 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001990 pdata->rx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001991
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001992 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001993 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
1994
1995 netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001996 pdata->rx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001997}
1998
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001999static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002000{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002001 unsigned int qptc, qptc_extra, queue;
2002 unsigned int prio_queues;
2003 unsigned int ppq, ppq_extra, prio;
2004 unsigned int mask;
2005 unsigned int i, j, reg, reg_val;
2006
2007 /* Map the MTL Tx Queues to Traffic Classes
2008 * Note: Tx Queues >= Traffic Classes
2009 */
2010 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
2011 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
2012
2013 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
2014 for (j = 0; j < qptc; j++) {
2015 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
2016 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2017 Q2TCMAP, i);
2018 pdata->q2tc_map[queue++] = i;
2019 }
2020
2021 if (i < qptc_extra) {
2022 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
2023 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2024 Q2TCMAP, i);
2025 pdata->q2tc_map[queue++] = i;
2026 }
2027 }
2028
2029 /* Map the 8 VLAN priority values to available MTL Rx queues */
2030 prio_queues = min_t(unsigned int, IEEE_8021QAZ_MAX_TCS,
2031 pdata->rx_q_count);
2032 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
2033 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
2034
2035 reg = MAC_RQC2R;
2036 reg_val = 0;
2037 for (i = 0, prio = 0; i < prio_queues;) {
2038 mask = 0;
2039 for (j = 0; j < ppq; j++) {
2040 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
2041 mask |= (1 << prio);
2042 pdata->prio2q_map[prio++] = i;
2043 }
2044
2045 if (i < ppq_extra) {
2046 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
2047 mask |= (1 << prio);
2048 pdata->prio2q_map[prio++] = i;
2049 }
2050
2051 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
2052
2053 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
2054 continue;
2055
2056 XGMAC_IOWRITE(pdata, reg, reg_val);
2057 reg += MAC_RQC2_INC;
2058 reg_val = 0;
2059 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002060
2061 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
2062 reg = MTL_RQDCM0R;
2063 reg_val = 0;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002064 for (i = 0; i < pdata->rx_q_count;) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002065 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
2066
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002067 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002068 continue;
2069
2070 XGMAC_IOWRITE(pdata, reg, reg_val);
2071
2072 reg += MTL_RQDCM_INC;
2073 reg_val = 0;
2074 }
2075}
2076
2077static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
2078{
2079 unsigned int i;
2080
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002081 for (i = 0; i < pdata->rx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002082 /* Activate flow control when less than 4k left in fifo */
2083 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
2084
2085 /* De-activate flow control when more than 6k left in fifo */
2086 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
2087 }
2088}
2089
2090static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
2091{
2092 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05002093
2094 /* Filtering is done using perfect filtering and hash filtering */
2095 if (pdata->hw_feat.hash_table_size) {
2096 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
2097 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
2098 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
2099 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002100}
2101
2102static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
2103{
2104 unsigned int val;
2105
2106 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
2107
2108 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
2109}
2110
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002111static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata)
2112{
2113 switch (pdata->phy_speed) {
2114 case SPEED_10000:
2115 xgbe_set_xgmii_speed(pdata);
2116 break;
2117
2118 case SPEED_2500:
2119 xgbe_set_gmii_2500_speed(pdata);
2120 break;
2121
2122 case SPEED_1000:
2123 xgbe_set_gmii_speed(pdata);
2124 break;
2125 }
2126}
2127
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002128static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
2129{
2130 if (pdata->netdev->features & NETIF_F_RXCSUM)
2131 xgbe_enable_rx_csum(pdata);
2132 else
2133 xgbe_disable_rx_csum(pdata);
2134}
2135
2136static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
2137{
Lendacky, Thomas6e5eed02014-06-24 16:19:12 -05002138 /* Indicate that VLAN Tx CTAGs come from context descriptors */
2139 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
2140 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
2141
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002142 /* Set the current VLAN Hash Table register value */
2143 xgbe_update_vlan_hash_table(pdata);
2144
2145 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
2146 xgbe_enable_rx_vlan_filtering(pdata);
2147 else
2148 xgbe_disable_rx_vlan_filtering(pdata);
2149
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002150 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2151 xgbe_enable_rx_vlan_stripping(pdata);
2152 else
2153 xgbe_disable_rx_vlan_stripping(pdata);
2154}
2155
Lendacky, Thomas60265102014-09-05 18:02:30 -05002156static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
2157{
2158 bool read_hi;
2159 u64 val;
2160
2161 switch (reg_lo) {
2162 /* These registers are always 64 bit */
2163 case MMC_TXOCTETCOUNT_GB_LO:
2164 case MMC_TXOCTETCOUNT_G_LO:
2165 case MMC_RXOCTETCOUNT_GB_LO:
2166 case MMC_RXOCTETCOUNT_G_LO:
2167 read_hi = true;
2168 break;
2169
2170 default:
2171 read_hi = false;
2172 };
2173
2174 val = XGMAC_IOREAD(pdata, reg_lo);
2175
2176 if (read_hi)
2177 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
2178
2179 return val;
2180}
2181
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002182static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
2183{
2184 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2185 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
2186
2187 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
2188 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002189 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002190
2191 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
2192 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002193 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002194
2195 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
2196 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002197 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002198
2199 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
2200 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002201 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002202
2203 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
2204 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002205 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002206
2207 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
2208 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002209 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002210
2211 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
2212 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002213 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002214
2215 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
2216 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002217 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002218
2219 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
2220 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002221 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002222
2223 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
2224 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002225 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002226
2227 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
2228 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002229 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002230
2231 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2232 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002233 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002234
2235 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2236 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002237 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002238
2239 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2240 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002241 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002242
2243 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2244 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002245 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002246
2247 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2248 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002249 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002250
2251 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2252 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002253 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002254
2255 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2256 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002257 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002258}
2259
2260static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2261{
2262 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2263 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2264
2265 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2266 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002267 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002268
2269 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2270 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002271 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002272
2273 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2274 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002275 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002276
2277 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2278 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002279 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002280
2281 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2282 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002283 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002284
2285 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2286 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002287 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002288
2289 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2290 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002291 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002292
2293 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2294 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002295 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002296
2297 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
2298 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002299 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002300
2301 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
2302 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002303 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002304
2305 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
2306 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002307 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002308
2309 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
2310 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002311 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002312
2313 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
2314 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002315 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002316
2317 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
2318 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002319 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002320
2321 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
2322 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002323 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002324
2325 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
2326 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002327 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002328
2329 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
2330 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002331 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002332
2333 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
2334 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002335 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002336
2337 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
2338 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002339 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002340
2341 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
2342 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002343 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002344
2345 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
2346 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002347 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002348
2349 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
2350 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002351 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002352
2353 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
2354 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002355 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002356}
2357
2358static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
2359{
2360 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2361
2362 /* Freeze counters */
2363 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
2364
2365 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002366 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002367
2368 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002369 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002370
2371 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002372 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002373
2374 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002375 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002376
2377 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002378 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002379
2380 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002381 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002382
2383 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002384 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002385
2386 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002387 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002388
2389 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002390 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002391
2392 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002393 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002394
2395 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002396 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002397
2398 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002399 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002400
2401 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002402 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002403
2404 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002405 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002406
2407 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002408 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002409
2410 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002411 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002412
2413 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002414 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002415
2416 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002417 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002418
2419 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002420 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002421
2422 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002423 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002424
2425 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002426 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002427
2428 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002429 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002430
2431 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002432 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002433
2434 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002435 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002436
2437 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002438 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002439
2440 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002441 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002442
2443 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002444 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002445
2446 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002447 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002448
2449 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002450 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002451
2452 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002453 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002454
2455 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002456 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002457
2458 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002459 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002460
2461 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002462 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002463
2464 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002465 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002466
2467 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002468 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002469
2470 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002471 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002472
2473 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002474 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002475
2476 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002477 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002478
2479 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002480 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002481
2482 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002483 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002484
2485 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002486 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002487
2488 /* Un-freeze counters */
2489 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
2490}
2491
2492static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
2493{
2494 /* Set counters to reset on read */
2495 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
2496
2497 /* Reset the counters */
2498 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
2499}
2500
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002501static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
2502 struct xgbe_channel *channel)
2503{
2504 unsigned int tx_dsr, tx_pos, tx_qidx;
2505 unsigned int tx_status;
2506 unsigned long tx_timeout;
2507
2508 /* Calculate the status register to read and the position within */
2509 if (channel->queue_index < DMA_DSRX_FIRST_QUEUE) {
2510 tx_dsr = DMA_DSR0;
2511 tx_pos = (channel->queue_index * DMA_DSR_Q_WIDTH) +
2512 DMA_DSR0_TPS_START;
2513 } else {
2514 tx_qidx = channel->queue_index - DMA_DSRX_FIRST_QUEUE;
2515
2516 tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
2517 tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
2518 DMA_DSRX_TPS_START;
2519 }
2520
2521 /* The Tx engine cannot be stopped if it is actively processing
2522 * descriptors. Wait for the Tx engine to enter the stopped or
2523 * suspended state. Don't wait forever though...
2524 */
2525 tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
2526 while (time_before(jiffies, tx_timeout)) {
2527 tx_status = XGMAC_IOREAD(pdata, tx_dsr);
2528 tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
2529 if ((tx_status == DMA_TPS_STOPPED) ||
2530 (tx_status == DMA_TPS_SUSPENDED))
2531 break;
2532
2533 usleep_range(500, 1000);
2534 }
2535
2536 if (!time_before(jiffies, tx_timeout))
2537 netdev_info(pdata->netdev,
2538 "timed out waiting for Tx DMA channel %u to stop\n",
2539 channel->queue_index);
2540}
2541
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002542static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
2543{
2544 struct xgbe_channel *channel;
2545 unsigned int i;
2546
2547 /* Enable each Tx DMA channel */
2548 channel = pdata->channel;
2549 for (i = 0; i < pdata->channel_count; i++, channel++) {
2550 if (!channel->tx_ring)
2551 break;
2552
2553 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2554 }
2555
2556 /* Enable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002557 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002558 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
2559 MTL_Q_ENABLED);
2560
2561 /* Enable MAC Tx */
2562 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2563}
2564
2565static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
2566{
2567 struct xgbe_channel *channel;
2568 unsigned int i;
2569
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002570 /* Prepare for Tx DMA channel stop */
2571 channel = pdata->channel;
2572 for (i = 0; i < pdata->channel_count; i++, channel++) {
2573 if (!channel->tx_ring)
2574 break;
2575
2576 xgbe_prepare_tx_stop(pdata, channel);
2577 }
2578
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002579 /* Disable MAC Tx */
2580 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2581
2582 /* Disable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002583 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002584 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
2585
2586 /* Disable each Tx DMA channel */
2587 channel = pdata->channel;
2588 for (i = 0; i < pdata->channel_count; i++, channel++) {
2589 if (!channel->tx_ring)
2590 break;
2591
2592 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2593 }
2594}
2595
2596static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
2597{
2598 struct xgbe_channel *channel;
2599 unsigned int reg_val, i;
2600
2601 /* Enable each Rx DMA channel */
2602 channel = pdata->channel;
2603 for (i = 0; i < pdata->channel_count; i++, channel++) {
2604 if (!channel->rx_ring)
2605 break;
2606
2607 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2608 }
2609
2610 /* Enable each Rx queue */
2611 reg_val = 0;
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002612 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002613 reg_val |= (0x02 << (i << 1));
2614 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
2615
2616 /* Enable MAC Rx */
2617 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
2618 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
2619 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
2620 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
2621}
2622
2623static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
2624{
2625 struct xgbe_channel *channel;
2626 unsigned int i;
2627
2628 /* Disable MAC Rx */
2629 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
2630 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
2631 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
2632 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
2633
2634 /* Disable each Rx queue */
2635 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
2636
2637 /* Disable each Rx DMA channel */
2638 channel = pdata->channel;
2639 for (i = 0; i < pdata->channel_count; i++, channel++) {
2640 if (!channel->rx_ring)
2641 break;
2642
2643 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2644 }
2645}
2646
2647static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
2648{
2649 struct xgbe_channel *channel;
2650 unsigned int i;
2651
2652 /* Enable each Tx DMA channel */
2653 channel = pdata->channel;
2654 for (i = 0; i < pdata->channel_count; i++, channel++) {
2655 if (!channel->tx_ring)
2656 break;
2657
2658 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2659 }
2660
2661 /* Enable MAC Tx */
2662 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2663}
2664
2665static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
2666{
2667 struct xgbe_channel *channel;
2668 unsigned int i;
2669
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002670 /* Prepare for Tx DMA channel stop */
2671 channel = pdata->channel;
2672 for (i = 0; i < pdata->channel_count; i++, channel++) {
2673 if (!channel->tx_ring)
2674 break;
2675
2676 xgbe_prepare_tx_stop(pdata, channel);
2677 }
2678
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002679 /* Disable MAC Tx */
2680 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2681
2682 /* Disable each Tx DMA channel */
2683 channel = pdata->channel;
2684 for (i = 0; i < pdata->channel_count; i++, channel++) {
2685 if (!channel->tx_ring)
2686 break;
2687
2688 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2689 }
2690}
2691
2692static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2693{
2694 struct xgbe_channel *channel;
2695 unsigned int i;
2696
2697 /* Enable each Rx DMA channel */
2698 channel = pdata->channel;
2699 for (i = 0; i < pdata->channel_count; i++, channel++) {
2700 if (!channel->rx_ring)
2701 break;
2702
2703 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2704 }
2705}
2706
2707static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2708{
2709 struct xgbe_channel *channel;
2710 unsigned int i;
2711
2712 /* Disable each Rx DMA channel */
2713 channel = pdata->channel;
2714 for (i = 0; i < pdata->channel_count; i++, channel++) {
2715 if (!channel->rx_ring)
2716 break;
2717
2718 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2719 }
2720}
2721
2722static int xgbe_init(struct xgbe_prv_data *pdata)
2723{
2724 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2725 int ret;
2726
2727 DBGPR("-->xgbe_init\n");
2728
2729 /* Flush Tx queues */
2730 ret = xgbe_flush_tx_queues(pdata);
2731 if (ret)
2732 return ret;
2733
2734 /*
2735 * Initialize DMA related features
2736 */
2737 xgbe_config_dma_bus(pdata);
2738 xgbe_config_dma_cache(pdata);
2739 xgbe_config_osp_mode(pdata);
2740 xgbe_config_pblx8(pdata);
2741 xgbe_config_tx_pbl_val(pdata);
2742 xgbe_config_rx_pbl_val(pdata);
2743 xgbe_config_rx_coalesce(pdata);
2744 xgbe_config_tx_coalesce(pdata);
2745 xgbe_config_rx_buffer_size(pdata);
2746 xgbe_config_tso_mode(pdata);
Lendacky, Thomas174fd252014-11-04 16:06:50 -06002747 xgbe_config_sph_mode(pdata);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06002748 xgbe_config_rss(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002749 desc_if->wrapper_tx_desc_init(pdata);
2750 desc_if->wrapper_rx_desc_init(pdata);
2751 xgbe_enable_dma_interrupts(pdata);
2752
2753 /*
2754 * Initialize MTL related features
2755 */
2756 xgbe_config_mtl_mode(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002757 xgbe_config_queue_mapping(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002758 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2759 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2760 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2761 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2762 xgbe_config_tx_fifo_size(pdata);
2763 xgbe_config_rx_fifo_size(pdata);
2764 xgbe_config_flow_control_threshold(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002765 /*TODO: Error Packet and undersized good Packet forwarding enable
2766 (FEP and FUP)
2767 */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002768 xgbe_config_dcb_tc(pdata);
2769 xgbe_config_dcb_pfc(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002770 xgbe_enable_mtl_interrupts(pdata);
2771
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002772 /*
2773 * Initialize MAC related features
2774 */
2775 xgbe_config_mac_address(pdata);
2776 xgbe_config_jumbo_enable(pdata);
2777 xgbe_config_flow_control(pdata);
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002778 xgbe_config_mac_speed(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002779 xgbe_config_checksum_offload(pdata);
2780 xgbe_config_vlan_support(pdata);
2781 xgbe_config_mmc(pdata);
2782 xgbe_enable_mac_interrupts(pdata);
2783
2784 DBGPR("<--xgbe_init\n");
2785
2786 return 0;
2787}
2788
2789void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2790{
2791 DBGPR("-->xgbe_init_function_ptrs\n");
2792
2793 hw_if->tx_complete = xgbe_tx_complete;
2794
2795 hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
2796 hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05002797 hw_if->add_mac_addresses = xgbe_add_mac_addresses;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002798 hw_if->set_mac_address = xgbe_set_mac_address;
2799
2800 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2801 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2802
2803 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2804 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002805 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
2806 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
2807 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002808
2809 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2810 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2811
2812 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2813 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2814 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2815
2816 hw_if->enable_tx = xgbe_enable_tx;
2817 hw_if->disable_tx = xgbe_disable_tx;
2818 hw_if->enable_rx = xgbe_enable_rx;
2819 hw_if->disable_rx = xgbe_disable_rx;
2820
2821 hw_if->powerup_tx = xgbe_powerup_tx;
2822 hw_if->powerdown_tx = xgbe_powerdown_tx;
2823 hw_if->powerup_rx = xgbe_powerup_rx;
2824 hw_if->powerdown_rx = xgbe_powerdown_rx;
2825
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06002826 hw_if->dev_xmit = xgbe_dev_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002827 hw_if->dev_read = xgbe_dev_read;
2828 hw_if->enable_int = xgbe_enable_int;
2829 hw_if->disable_int = xgbe_disable_int;
2830 hw_if->init = xgbe_init;
2831 hw_if->exit = xgbe_exit;
2832
2833 /* Descriptor related Sequences have to be initialized here */
2834 hw_if->tx_desc_init = xgbe_tx_desc_init;
2835 hw_if->rx_desc_init = xgbe_rx_desc_init;
2836 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2837 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2838 hw_if->is_last_desc = xgbe_is_last_desc;
2839 hw_if->is_context_desc = xgbe_is_context_desc;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06002840 hw_if->tx_start_xmit = xgbe_tx_start_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002841
2842 /* For FLOW ctrl */
2843 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2844 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2845
2846 /* For RX coalescing */
2847 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2848 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2849 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2850 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2851
2852 /* For RX and TX threshold config */
2853 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2854 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2855
2856 /* For RX and TX Store and Forward Mode config */
2857 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2858 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2859
2860 /* For TX DMA Operating on Second Frame config */
2861 hw_if->config_osp_mode = xgbe_config_osp_mode;
2862
2863 /* For RX and TX PBL config */
2864 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2865 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2866 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2867 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2868 hw_if->config_pblx8 = xgbe_config_pblx8;
2869
2870 /* For MMC statistics support */
2871 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2872 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2873 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2874
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05002875 /* For PTP config */
2876 hw_if->config_tstamp = xgbe_config_tstamp;
2877 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
2878 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
2879 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
2880 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
2881
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002882 /* For Data Center Bridging config */
2883 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
2884 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
2885
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06002886 /* For Receive Side Scaling */
2887 hw_if->enable_rss = xgbe_enable_rss;
2888 hw_if->disable_rss = xgbe_disable_rss;
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -06002889 hw_if->set_rss_hash_key = xgbe_set_rss_hash_key;
2890 hw_if->set_rss_lookup_table = xgbe_set_rss_lookup_table;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06002891
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002892 DBGPR("<--xgbe_init_function_ptrs\n");
2893}