blob: 78a2063029daabd5352216299f01ad2b01ffec57 [file] [log] [blame]
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001/*
2 * AMD 10Gb Ethernet driver
3 *
4 * This file is available to you under your choice of the following two
5 * licenses:
6 *
7 * License 1: GPLv2
8 *
Lendacky, Thomasb4eee842016-02-17 11:48:08 -06009 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050010 *
11 * This file is free software; you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * This file incorporates work covered by the following copyright and
25 * permission notice:
26 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
27 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28 * Inc. unless otherwise expressly agreed to in writing between Synopsys
29 * and you.
30 *
31 * The Software IS NOT an item of Licensed Software or Licensed Product
32 * under any End User Software License Agreement or Agreement for Licensed
33 * Product with Synopsys or any supplement thereto. Permission is hereby
34 * granted, free of charge, to any person obtaining a copy of this software
35 * annotated with this license and the Software, to deal in the Software
36 * without restriction, including without limitation the rights to use,
37 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 * of the Software, and to permit persons to whom the Software is furnished
39 * to do so, subject to the following conditions:
40 *
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
43 *
44 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54 * THE POSSIBILITY OF SUCH DAMAGE.
55 *
56 *
57 * License 2: Modified BSD
58 *
Lendacky, Thomasb4eee842016-02-17 11:48:08 -060059 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050060 * All rights reserved.
61 *
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions are met:
64 * * Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 * * Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
69 * * Neither the name of Advanced Micro Devices, Inc. nor the
70 * names of its contributors may be used to endorse or promote products
71 * derived from this software without specific prior written permission.
72 *
73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 *
84 * This file incorporates work covered by the following copyright and
85 * permission notice:
86 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
87 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88 * Inc. unless otherwise expressly agreed to in writing between Synopsys
89 * and you.
90 *
91 * The Software IS NOT an item of Licensed Software or Licensed Product
92 * under any End User Software License Agreement or Agreement for Licensed
93 * Product with Synopsys or any supplement thereto. Permission is hereby
94 * granted, free of charge, to any person obtaining a copy of this software
95 * annotated with this license and the Software, to deal in the Software
96 * without restriction, including without limitation the rights to use,
97 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98 * of the Software, and to permit persons to whom the Software is furnished
99 * to do so, subject to the following conditions:
100 *
101 * The above copyright notice and this permission notice shall be included
102 * in all copies or substantial portions of the Software.
103 *
104 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114 * THE POSSIBILITY OF SUCH DAMAGE.
115 */
116
117#include <linux/phy.h>
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600118#include <linux/mdio.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500119#include <linux/clk.h>
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500120#include <linux/bitrev.h>
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500121#include <linux/crc32.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500122
123#include "xgbe.h"
124#include "xgbe-common.h"
125
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500126static inline unsigned int xgbe_get_max_frame(struct xgbe_prv_data *pdata)
127{
128 return pdata->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
129}
130
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500131static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
132 unsigned int usec)
133{
134 unsigned long rate;
135 unsigned int ret;
136
137 DBGPR("-->xgbe_usec_to_riwt\n");
138
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600139 rate = pdata->sysclk_rate;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500140
141 /*
142 * Convert the input usec value to the watchdog timer value. Each
143 * watchdog timer value is equivalent to 256 clock cycles.
144 * Calculate the required value as:
145 * ( usec * ( system_clock_mhz / 10^6 ) / 256
146 */
147 ret = (usec * (rate / 1000000)) / 256;
148
149 DBGPR("<--xgbe_usec_to_riwt\n");
150
151 return ret;
152}
153
154static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
155 unsigned int riwt)
156{
157 unsigned long rate;
158 unsigned int ret;
159
160 DBGPR("-->xgbe_riwt_to_usec\n");
161
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600162 rate = pdata->sysclk_rate;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500163
164 /*
165 * Convert the input watchdog timer value to the usec value. Each
166 * watchdog timer value is equivalent to 256 clock cycles.
167 * Calculate the required value as:
168 * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
169 */
170 ret = (riwt * 256) / (rate / 1000000);
171
172 DBGPR("<--xgbe_riwt_to_usec\n");
173
174 return ret;
175}
176
177static int xgbe_config_pblx8(struct xgbe_prv_data *pdata)
178{
179 struct xgbe_channel *channel;
180 unsigned int i;
181
182 channel = pdata->channel;
183 for (i = 0; i < pdata->channel_count; i++, channel++)
184 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8,
185 pdata->pblx8);
186
187 return 0;
188}
189
190static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata)
191{
192 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL);
193}
194
195static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata)
196{
197 struct xgbe_channel *channel;
198 unsigned int i;
199
200 channel = pdata->channel;
201 for (i = 0; i < pdata->channel_count; i++, channel++) {
202 if (!channel->tx_ring)
203 break;
204
205 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL,
206 pdata->tx_pbl);
207 }
208
209 return 0;
210}
211
212static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata)
213{
214 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL);
215}
216
217static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata)
218{
219 struct xgbe_channel *channel;
220 unsigned int i;
221
222 channel = pdata->channel;
223 for (i = 0; i < pdata->channel_count; i++, channel++) {
224 if (!channel->rx_ring)
225 break;
226
227 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL,
228 pdata->rx_pbl);
229 }
230
231 return 0;
232}
233
234static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
235{
236 struct xgbe_channel *channel;
237 unsigned int i;
238
239 channel = pdata->channel;
240 for (i = 0; i < pdata->channel_count; i++, channel++) {
241 if (!channel->tx_ring)
242 break;
243
244 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP,
245 pdata->tx_osp_mode);
246 }
247
248 return 0;
249}
250
251static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
252{
253 unsigned int i;
254
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500255 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500256 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
257
258 return 0;
259}
260
261static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
262{
263 unsigned int i;
264
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500265 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500266 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
267
268 return 0;
269}
270
271static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
272 unsigned int val)
273{
274 unsigned int i;
275
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500276 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500277 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
278
279 return 0;
280}
281
282static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
283 unsigned int val)
284{
285 unsigned int i;
286
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500287 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500288 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
289
290 return 0;
291}
292
293static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
294{
295 struct xgbe_channel *channel;
296 unsigned int i;
297
298 channel = pdata->channel;
299 for (i = 0; i < pdata->channel_count; i++, channel++) {
300 if (!channel->rx_ring)
301 break;
302
303 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT,
304 pdata->rx_riwt);
305 }
306
307 return 0;
308}
309
310static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
311{
312 return 0;
313}
314
315static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
316{
317 struct xgbe_channel *channel;
318 unsigned int i;
319
320 channel = pdata->channel;
321 for (i = 0; i < pdata->channel_count; i++, channel++) {
322 if (!channel->rx_ring)
323 break;
324
325 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ,
326 pdata->rx_buf_size);
327 }
328}
329
330static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
331{
332 struct xgbe_channel *channel;
333 unsigned int i;
334
335 channel = pdata->channel;
336 for (i = 0; i < pdata->channel_count; i++, channel++) {
337 if (!channel->tx_ring)
338 break;
339
340 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1);
341 }
342}
343
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600344static void xgbe_config_sph_mode(struct xgbe_prv_data *pdata)
345{
346 struct xgbe_channel *channel;
347 unsigned int i;
348
349 channel = pdata->channel;
350 for (i = 0; i < pdata->channel_count; i++, channel++) {
351 if (!channel->rx_ring)
352 break;
353
354 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, SPH, 1);
355 }
356
357 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE);
358}
359
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600360static int xgbe_write_rss_reg(struct xgbe_prv_data *pdata, unsigned int type,
361 unsigned int index, unsigned int val)
362{
363 unsigned int wait;
364 int ret = 0;
365
366 mutex_lock(&pdata->rss_mutex);
367
368 if (XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB)) {
369 ret = -EBUSY;
370 goto unlock;
371 }
372
373 XGMAC_IOWRITE(pdata, MAC_RSSDR, val);
374
375 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, RSSIA, index);
376 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, ADDRT, type);
377 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, CT, 0);
378 XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, OB, 1);
379
380 wait = 1000;
381 while (wait--) {
382 if (!XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB))
383 goto unlock;
384
385 usleep_range(1000, 1500);
386 }
387
388 ret = -EBUSY;
389
390unlock:
391 mutex_unlock(&pdata->rss_mutex);
392
393 return ret;
394}
395
396static int xgbe_write_rss_hash_key(struct xgbe_prv_data *pdata)
397{
398 unsigned int key_regs = sizeof(pdata->rss_key) / sizeof(u32);
399 unsigned int *key = (unsigned int *)&pdata->rss_key;
400 int ret;
401
402 while (key_regs--) {
403 ret = xgbe_write_rss_reg(pdata, XGBE_RSS_HASH_KEY_TYPE,
404 key_regs, *key++);
405 if (ret)
406 return ret;
407 }
408
409 return 0;
410}
411
412static int xgbe_write_rss_lookup_table(struct xgbe_prv_data *pdata)
413{
414 unsigned int i;
415 int ret;
416
417 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) {
418 ret = xgbe_write_rss_reg(pdata,
419 XGBE_RSS_LOOKUP_TABLE_TYPE, i,
420 pdata->rss_table[i]);
421 if (ret)
422 return ret;
423 }
424
425 return 0;
426}
427
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600428static int xgbe_set_rss_hash_key(struct xgbe_prv_data *pdata, const u8 *key)
429{
430 memcpy(pdata->rss_key, key, sizeof(pdata->rss_key));
431
432 return xgbe_write_rss_hash_key(pdata);
433}
434
435static int xgbe_set_rss_lookup_table(struct xgbe_prv_data *pdata,
436 const u32 *table)
437{
438 unsigned int i;
439
440 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
441 XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, table[i]);
442
443 return xgbe_write_rss_lookup_table(pdata);
444}
445
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600446static int xgbe_enable_rss(struct xgbe_prv_data *pdata)
447{
448 int ret;
449
450 if (!pdata->hw_feat.rss)
451 return -EOPNOTSUPP;
452
453 /* Program the hash key */
454 ret = xgbe_write_rss_hash_key(pdata);
455 if (ret)
456 return ret;
457
458 /* Program the lookup table */
459 ret = xgbe_write_rss_lookup_table(pdata);
460 if (ret)
461 return ret;
462
463 /* Set the RSS options */
464 XGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options);
465
466 /* Enable RSS */
467 XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 1);
468
469 return 0;
470}
471
472static int xgbe_disable_rss(struct xgbe_prv_data *pdata)
473{
474 if (!pdata->hw_feat.rss)
475 return -EOPNOTSUPP;
476
477 XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 0);
478
479 return 0;
480}
481
482static void xgbe_config_rss(struct xgbe_prv_data *pdata)
483{
484 int ret;
485
486 if (!pdata->hw_feat.rss)
487 return;
488
489 if (pdata->netdev->features & NETIF_F_RXHASH)
490 ret = xgbe_enable_rss(pdata);
491 else
492 ret = xgbe_disable_rss(pdata);
493
494 if (ret)
495 netdev_err(pdata->netdev,
496 "error configuring RSS, RSS disabled\n");
497}
498
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500499static bool xgbe_is_pfc_queue(struct xgbe_prv_data *pdata,
500 unsigned int queue)
501{
502 unsigned int prio, tc;
503
504 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
505 /* Does this queue handle the priority? */
506 if (pdata->prio2q_map[prio] != queue)
507 continue;
508
509 /* Get the Traffic Class for this priority */
510 tc = pdata->ets->prio_tc[prio];
511
512 /* Check if PFC is enabled for this traffic class */
513 if (pdata->pfc->pfc_en & (1 << tc))
514 return true;
515 }
516
517 return false;
518}
519
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500520static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
521{
522 unsigned int max_q_count, q_count;
523 unsigned int reg, reg_val;
524 unsigned int i;
525
526 /* Clear MTL flow control */
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500527 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500528 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
529
530 /* Clear MAC flow control */
531 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas9fc69af2014-08-29 13:17:08 -0500532 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500533 reg = MAC_Q0TFCR;
534 for (i = 0; i < q_count; i++) {
535 reg_val = XGMAC_IOREAD(pdata, reg);
536 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
537 XGMAC_IOWRITE(pdata, reg, reg_val);
538
539 reg += MAC_QTFCR_INC;
540 }
541
542 return 0;
543}
544
545static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
546{
Lendacky, Thomas8dba2a22016-02-17 11:48:48 -0600547 struct ieee_pfc *pfc = pdata->pfc;
548 struct ieee_ets *ets = pdata->ets;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500549 unsigned int max_q_count, q_count;
550 unsigned int reg, reg_val;
551 unsigned int i;
552
553 /* Set MTL flow control */
Lendacky, Thomas8dba2a22016-02-17 11:48:48 -0600554 for (i = 0; i < pdata->rx_q_count; i++) {
555 unsigned int ehfc = 0;
556
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500557 if (pdata->rx_rfd[i]) {
558 /* Flow control thresholds are established */
559 if (pfc && ets) {
560 if (xgbe_is_pfc_queue(pdata, i))
Lendacky, Thomas8dba2a22016-02-17 11:48:48 -0600561 ehfc = 1;
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500562 } else {
563 ehfc = 1;
Lendacky, Thomas8dba2a22016-02-17 11:48:48 -0600564 }
Lendacky, Thomas8dba2a22016-02-17 11:48:48 -0600565 }
566
567 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, ehfc);
568
569 netif_dbg(pdata, drv, pdata->netdev,
570 "flow control %s for RXq%u\n",
571 ehfc ? "enabled" : "disabled", i);
572 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500573
574 /* Set MAC flow control */
575 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas9fc69af2014-08-29 13:17:08 -0500576 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500577 reg = MAC_Q0TFCR;
578 for (i = 0; i < q_count; i++) {
579 reg_val = XGMAC_IOREAD(pdata, reg);
580
581 /* Enable transmit flow control */
582 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
583 /* Set pause time */
584 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
585
586 XGMAC_IOWRITE(pdata, reg, reg_val);
587
588 reg += MAC_QTFCR_INC;
589 }
590
591 return 0;
592}
593
594static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
595{
596 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
597
598 return 0;
599}
600
601static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
602{
603 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
604
605 return 0;
606}
607
608static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
609{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500610 struct ieee_pfc *pfc = pdata->pfc;
611
612 if (pdata->tx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500613 xgbe_enable_tx_flow_control(pdata);
614 else
615 xgbe_disable_tx_flow_control(pdata);
616
617 return 0;
618}
619
620static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
621{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500622 struct ieee_pfc *pfc = pdata->pfc;
623
624 if (pdata->rx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500625 xgbe_enable_rx_flow_control(pdata);
626 else
627 xgbe_disable_rx_flow_control(pdata);
628
629 return 0;
630}
631
632static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
633{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500634 struct ieee_pfc *pfc = pdata->pfc;
635
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500636 xgbe_config_tx_flow_control(pdata);
637 xgbe_config_rx_flow_control(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500638
639 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
640 (pfc && pfc->pfc_en) ? 1 : 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500641}
642
643static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
644{
645 struct xgbe_channel *channel;
646 unsigned int dma_ch_isr, dma_ch_ier;
647 unsigned int i;
648
Lendacky, Thomas4c70dd82016-11-10 17:10:17 -0600649 /* Set the interrupt mode if supported */
650 if (pdata->channel_irq_mode)
651 XGMAC_IOWRITE_BITS(pdata, DMA_MR, INTM,
652 pdata->channel_irq_mode);
653
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500654 channel = pdata->channel;
655 for (i = 0; i < pdata->channel_count; i++, channel++) {
656 /* Clear all the interrupts which are set */
657 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
658 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
659
660 /* Clear all interrupt enable bits */
661 dma_ch_ier = 0;
662
663 /* Enable following interrupts
664 * NIE - Normal Interrupt Summary Enable
665 * AIE - Abnormal Interrupt Summary Enable
666 * FBEE - Fatal Bus Error Enable
667 */
668 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
669 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
670 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
671
672 if (channel->tx_ring) {
673 /* Enable the following Tx interrupts
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600674 * TIE - Transmit Interrupt Enable (unless using
Lendacky, Thomas4c70dd82016-11-10 17:10:17 -0600675 * per channel interrupts in edge triggered
676 * mode)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500677 */
Lendacky, Thomas4c70dd82016-11-10 17:10:17 -0600678 if (!pdata->per_channel_irq || pdata->channel_irq_mode)
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600679 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500680 }
681 if (channel->rx_ring) {
682 /* Enable following Rx interrupts
683 * RBUE - Receive Buffer Unavailable Enable
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600684 * RIE - Receive Interrupt Enable (unless using
Lendacky, Thomas4c70dd82016-11-10 17:10:17 -0600685 * per channel interrupts in edge triggered
686 * mode)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500687 */
688 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomas4c70dd82016-11-10 17:10:17 -0600689 if (!pdata->per_channel_irq || pdata->channel_irq_mode)
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600690 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500691 }
692
693 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
694 }
695}
696
697static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
698{
699 unsigned int mtl_q_isr;
700 unsigned int q_count, i;
701
702 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
703 for (i = 0; i < q_count; i++) {
704 /* Clear all the interrupts which are set */
705 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
706 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
707
708 /* No MTL interrupts to be enabled */
Lendacky, Thomas91f87342014-07-02 13:04:34 -0500709 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500710 }
711}
712
713static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
714{
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500715 unsigned int mac_ier = 0;
716
717 /* Enable Timestamp interrupt */
718 XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
719
720 XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500721
722 /* Enable all counter interrupts */
Lendacky, Thomasa3ba7c92014-09-05 18:02:36 -0500723 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
724 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500725}
726
Lendacky, Thomase78332b2016-11-10 17:10:26 -0600727static void xgbe_enable_ecc_interrupts(struct xgbe_prv_data *pdata)
728{
729 unsigned int ecc_isr, ecc_ier = 0;
730
731 if (!pdata->vdata->ecc_support)
732 return;
733
734 /* Clear all the interrupts which are set */
735 ecc_isr = XP_IOREAD(pdata, XP_ECC_ISR);
736 XP_IOWRITE(pdata, XP_ECC_ISR, ecc_isr);
737
738 /* Enable ECC interrupts */
739 XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_DED, 1);
740 XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_SEC, 1);
741 XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_DED, 1);
742 XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_SEC, 1);
743 XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_DED, 1);
744 XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_SEC, 1);
745
746 XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier);
747}
748
749static void xgbe_disable_ecc_ded(struct xgbe_prv_data *pdata)
750{
751 unsigned int ecc_ier;
752
753 ecc_ier = XP_IOREAD(pdata, XP_ECC_IER);
754
755 /* Disable ECC DED interrupts */
756 XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_DED, 0);
757 XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_DED, 0);
758 XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_DED, 0);
759
760 XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier);
761}
762
763static void xgbe_disable_ecc_sec(struct xgbe_prv_data *pdata,
764 enum xgbe_ecc_sec sec)
765{
766 unsigned int ecc_ier;
767
768 ecc_ier = XP_IOREAD(pdata, XP_ECC_IER);
769
770 /* Disable ECC SEC interrupt */
771 switch (sec) {
772 case XGBE_ECC_SEC_TX:
773 XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_SEC, 0);
774 break;
775 case XGBE_ECC_SEC_RX:
776 XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_SEC, 0);
777 break;
778 case XGBE_ECC_SEC_DESC:
779 XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_SEC, 0);
780 break;
781 }
782
783 XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier);
784}
785
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500786static int xgbe_set_speed(struct xgbe_prv_data *pdata, int speed)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500787{
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500788 unsigned int ss;
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600789
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500790 switch (speed) {
791 case SPEED_1000:
792 ss = 0x03;
793 break;
794 case SPEED_2500:
795 ss = 0x02;
796 break;
797 case SPEED_10000:
798 ss = 0x00;
799 break;
800 default:
801 return -EINVAL;
802 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500803
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500804 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) != ss)
805 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, ss);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500806
807 return 0;
808}
809
Lendacky, Thomasb4eee842016-02-17 11:48:08 -0600810static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
811{
812 /* Put the VLAN tag in the Rx descriptor */
813 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
814
815 /* Don't check the VLAN type */
816 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
817
818 /* Check only C-TAG (0x8100) packets */
819 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
820
821 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
822 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
823
824 /* Enable VLAN tag stripping */
825 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
826
827 return 0;
828}
829
830static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
831{
832 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
833
834 return 0;
835}
836
837static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
838{
839 /* Enable VLAN filtering */
840 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
841
842 /* Enable VLAN Hash Table filtering */
843 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
844
845 /* Disable VLAN tag inverse matching */
846 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
847
848 /* Only filter on the lower 12-bits of the VLAN tag */
849 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
850
851 /* In order for the VLAN Hash Table filtering to be effective,
852 * the VLAN tag identifier in the VLAN Tag Register must not
853 * be zero. Set the VLAN tag identifier to "1" to enable the
854 * VLAN Hash Table filtering. This implies that a VLAN tag of
855 * 1 will always pass filtering.
856 */
857 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
858
859 return 0;
860}
861
862static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
863{
864 /* Disable VLAN filtering */
865 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
866
867 return 0;
868}
869
870static u32 xgbe_vid_crc32_le(__le16 vid_le)
871{
872 u32 poly = 0xedb88320; /* CRCPOLY_LE */
873 u32 crc = ~0;
874 u32 temp = 0;
875 unsigned char *data = (unsigned char *)&vid_le;
876 unsigned char data_byte = 0;
877 int i, bits;
878
879 bits = get_bitmask_order(VLAN_VID_MASK);
880 for (i = 0; i < bits; i++) {
881 if ((i % 8) == 0)
882 data_byte = data[i / 8];
883
884 temp = ((crc & 1) ^ data_byte) & 1;
885 crc >>= 1;
886 data_byte >>= 1;
887
888 if (temp)
889 crc ^= poly;
890 }
891
892 return crc;
893}
894
895static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
896{
897 u32 crc;
898 u16 vid;
899 __le16 vid_le;
900 u16 vlan_hash_table = 0;
901
902 /* Generate the VLAN Hash Table value */
903 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
904 /* Get the CRC32 value of the VLAN ID */
905 vid_le = cpu_to_le16(vid);
906 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
907
908 vlan_hash_table |= (1 << crc);
909 }
910
911 /* Set the VLAN Hash Table filtering register */
912 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
913
914 return 0;
915}
916
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500917static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
918 unsigned int enable)
919{
920 unsigned int val = enable ? 1 : 0;
921
922 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
923 return 0;
924
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500925 netif_dbg(pdata, drv, pdata->netdev, "%s promiscuous mode\n",
926 enable ? "entering" : "leaving");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500927 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
928
Lendacky, Thomasb4eee842016-02-17 11:48:08 -0600929 /* Hardware will still perform VLAN filtering in promiscuous mode */
930 if (enable) {
931 xgbe_disable_rx_vlan_filtering(pdata);
932 } else {
933 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
934 xgbe_enable_rx_vlan_filtering(pdata);
935 }
936
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500937 return 0;
938}
939
940static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
941 unsigned int enable)
942{
943 unsigned int val = enable ? 1 : 0;
944
945 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
946 return 0;
947
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500948 netif_dbg(pdata, drv, pdata->netdev, "%s allmulti mode\n",
949 enable ? "entering" : "leaving");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500950 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
951
952 return 0;
953}
954
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500955static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
956 struct netdev_hw_addr *ha, unsigned int *mac_reg)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500957{
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500958 unsigned int mac_addr_hi, mac_addr_lo;
959 u8 *mac_addr;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500960
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500961 mac_addr_lo = 0;
962 mac_addr_hi = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500963
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500964 if (ha) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500965 mac_addr = (u8 *)&mac_addr_lo;
966 mac_addr[0] = ha->addr[0];
967 mac_addr[1] = ha->addr[1];
968 mac_addr[2] = ha->addr[2];
969 mac_addr[3] = ha->addr[3];
970 mac_addr = (u8 *)&mac_addr_hi;
971 mac_addr[0] = ha->addr[4];
972 mac_addr[1] = ha->addr[5];
973
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500974 netif_dbg(pdata, drv, pdata->netdev,
975 "adding mac address %pM at %#x\n",
976 ha->addr, *mac_reg);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500977
978 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500979 }
980
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500981 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
982 *mac_reg += MAC_MACA_INC;
983 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
984 *mac_reg += MAC_MACA_INC;
985}
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500986
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500987static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
988{
989 struct net_device *netdev = pdata->netdev;
990 struct netdev_hw_addr *ha;
991 unsigned int mac_reg;
992 unsigned int addn_macs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500993
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500994 mac_reg = MAC_MACA1HR;
995 addn_macs = pdata->hw_feat.addn_mac;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500996
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500997 if (netdev_uc_count(netdev) > addn_macs) {
998 xgbe_set_promiscuous_mode(pdata, 1);
999 } else {
1000 netdev_for_each_uc_addr(ha, netdev) {
1001 xgbe_set_mac_reg(pdata, ha, &mac_reg);
1002 addn_macs--;
1003 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001004
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05001005 if (netdev_mc_count(netdev) > addn_macs) {
1006 xgbe_set_all_multicast_mode(pdata, 1);
1007 } else {
1008 netdev_for_each_mc_addr(ha, netdev) {
1009 xgbe_set_mac_reg(pdata, ha, &mac_reg);
1010 addn_macs--;
1011 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001012 }
1013 }
1014
1015 /* Clear remaining additional MAC address entries */
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05001016 while (addn_macs--)
1017 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
1018}
1019
1020static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
1021{
1022 struct net_device *netdev = pdata->netdev;
1023 struct netdev_hw_addr *ha;
1024 unsigned int hash_reg;
1025 unsigned int hash_table_shift, hash_table_count;
1026 u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
1027 u32 crc;
1028 unsigned int i;
1029
1030 hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
1031 hash_table_count = pdata->hw_feat.hash_table_size / 32;
1032 memset(hash_table, 0, sizeof(hash_table));
1033
1034 /* Build the MAC Hash Table register values */
1035 netdev_for_each_uc_addr(ha, netdev) {
1036 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
1037 crc >>= hash_table_shift;
1038 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001039 }
1040
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05001041 netdev_for_each_mc_addr(ha, netdev) {
1042 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
1043 crc >>= hash_table_shift;
1044 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
1045 }
1046
1047 /* Set the MAC Hash Table registers */
1048 hash_reg = MAC_HTR0;
1049 for (i = 0; i < hash_table_count; i++) {
1050 XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
1051 hash_reg += MAC_HTR_INC;
1052 }
1053}
1054
1055static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
1056{
1057 if (pdata->hw_feat.hash_table_size)
1058 xgbe_set_mac_hash_table(pdata);
1059 else
1060 xgbe_set_mac_addn_addrs(pdata);
1061
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001062 return 0;
1063}
1064
1065static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
1066{
1067 unsigned int mac_addr_hi, mac_addr_lo;
1068
1069 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
1070 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
1071 (addr[1] << 8) | (addr[0] << 0);
1072
1073 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
1074 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
1075
1076 return 0;
1077}
1078
Lendacky, Thomasb8763822015-04-09 12:11:57 -05001079static int xgbe_config_rx_mode(struct xgbe_prv_data *pdata)
1080{
1081 struct net_device *netdev = pdata->netdev;
1082 unsigned int pr_mode, am_mode;
1083
1084 pr_mode = ((netdev->flags & IFF_PROMISC) != 0);
1085 am_mode = ((netdev->flags & IFF_ALLMULTI) != 0);
1086
1087 xgbe_set_promiscuous_mode(pdata, pr_mode);
1088 xgbe_set_all_multicast_mode(pdata, am_mode);
1089
1090 xgbe_add_mac_addresses(pdata);
1091
1092 return 0;
1093}
1094
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001095static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,
1096 int mmd_reg)
1097{
1098 unsigned long flags;
1099 unsigned int mmd_address, index, offset;
1100 int mmd_data;
1101
1102 if (mmd_reg & MII_ADDR_C45)
1103 mmd_address = mmd_reg & ~MII_ADDR_C45;
1104 else
1105 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1106
1107 /* The PCS registers are accessed using mmio. The underlying
1108 * management interface uses indirect addressing to access the MMD
1109 * register sets. This requires accessing of the PCS register in two
1110 * phases, an address phase and a data phase.
1111 *
1112 * The mmio interface is based on 16-bit offsets and values. All
1113 * register offsets must therefore be adjusted by left shifting the
1114 * offset 1 bit and reading 16 bits of data.
1115 */
1116 mmd_address <<= 1;
1117 index = mmd_address & ~pdata->xpcs_window_mask;
1118 offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask);
1119
1120 spin_lock_irqsave(&pdata->xpcs_lock, flags);
1121 XPCS32_IOWRITE(pdata, PCS_V2_WINDOW_SELECT, index);
1122 mmd_data = XPCS16_IOREAD(pdata, offset);
1123 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
1124
1125 return mmd_data;
1126}
1127
1128static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,
1129 int mmd_reg, int mmd_data)
1130{
1131 unsigned long flags;
1132 unsigned int mmd_address, index, offset;
1133
1134 if (mmd_reg & MII_ADDR_C45)
1135 mmd_address = mmd_reg & ~MII_ADDR_C45;
1136 else
1137 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1138
1139 /* The PCS registers are accessed using mmio. The underlying
1140 * management interface uses indirect addressing to access the MMD
1141 * register sets. This requires accessing of the PCS register in two
1142 * phases, an address phase and a data phase.
1143 *
1144 * The mmio interface is based on 16-bit offsets and values. All
1145 * register offsets must therefore be adjusted by left shifting the
1146 * offset 1 bit and writing 16 bits of data.
1147 */
1148 mmd_address <<= 1;
1149 index = mmd_address & ~pdata->xpcs_window_mask;
1150 offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask);
1151
1152 spin_lock_irqsave(&pdata->xpcs_lock, flags);
1153 XPCS32_IOWRITE(pdata, PCS_V2_WINDOW_SELECT, index);
1154 XPCS16_IOWRITE(pdata, offset, mmd_data);
1155 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
1156}
1157
1158static int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,
1159 int mmd_reg)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001160{
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001161 unsigned long flags;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001162 unsigned int mmd_address;
1163 int mmd_data;
1164
1165 if (mmd_reg & MII_ADDR_C45)
1166 mmd_address = mmd_reg & ~MII_ADDR_C45;
1167 else
1168 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1169
1170 /* The PCS registers are accessed using mmio. The underlying APB3
1171 * management interface uses indirect addressing to access the MMD
1172 * register sets. This requires accessing of the PCS register in two
1173 * phases, an address phase and a data phase.
1174 *
1175 * The mmio interface is based on 32-bit offsets and values. All
1176 * register offsets must therefore be adjusted by left shifting the
1177 * offset 2 bits and reading 32 bits of data.
1178 */
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001179 spin_lock_irqsave(&pdata->xpcs_lock, flags);
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001180 XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8);
1181 mmd_data = XPCS32_IOREAD(pdata, (mmd_address & 0xff) << 2);
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001182 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001183
1184 return mmd_data;
1185}
1186
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001187static void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,
1188 int mmd_reg, int mmd_data)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001189{
1190 unsigned int mmd_address;
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001191 unsigned long flags;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001192
1193 if (mmd_reg & MII_ADDR_C45)
1194 mmd_address = mmd_reg & ~MII_ADDR_C45;
1195 else
1196 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1197
1198 /* The PCS registers are accessed using mmio. The underlying APB3
1199 * management interface uses indirect addressing to access the MMD
1200 * register sets. This requires accessing of the PCS register in two
1201 * phases, an address phase and a data phase.
1202 *
1203 * The mmio interface is based on 32-bit offsets and values. All
1204 * register offsets must therefore be adjusted by left shifting the
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001205 * offset 2 bits and writing 32 bits of data.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001206 */
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001207 spin_lock_irqsave(&pdata->xpcs_lock, flags);
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001208 XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8);
1209 XPCS32_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001210 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001211}
1212
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001213static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
1214 int mmd_reg)
1215{
1216 switch (pdata->vdata->xpcs_access) {
1217 case XGBE_XPCS_ACCESS_V1:
1218 return xgbe_read_mmd_regs_v1(pdata, prtad, mmd_reg);
1219
1220 case XGBE_XPCS_ACCESS_V2:
1221 default:
1222 return xgbe_read_mmd_regs_v2(pdata, prtad, mmd_reg);
1223 }
1224}
1225
1226static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
1227 int mmd_reg, int mmd_data)
1228{
1229 switch (pdata->vdata->xpcs_access) {
1230 case XGBE_XPCS_ACCESS_V1:
1231 return xgbe_write_mmd_regs_v1(pdata, prtad, mmd_reg, mmd_data);
1232
1233 case XGBE_XPCS_ACCESS_V2:
1234 default:
1235 return xgbe_write_mmd_regs_v2(pdata, prtad, mmd_reg, mmd_data);
1236 }
1237}
1238
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001239static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
1240{
1241 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
1242}
1243
1244static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
1245{
1246 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
1247
1248 return 0;
1249}
1250
1251static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
1252{
1253 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
1254
1255 return 0;
1256}
1257
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001258static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
1259{
1260 struct xgbe_ring_desc *rdesc = rdata->rdesc;
1261
1262 /* Reset the Tx descriptor
1263 * Set buffer 1 (lo) address to zero
1264 * Set buffer 1 (hi) address to zero
1265 * Reset all other control bits (IC, TTSE, B2L & B1L)
1266 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
1267 */
1268 rdesc->desc0 = 0;
1269 rdesc->desc1 = 0;
1270 rdesc->desc2 = 0;
1271 rdesc->desc3 = 0;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001272
1273 /* Make sure ownership is written to the descriptor */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001274 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001275}
1276
1277static void xgbe_tx_desc_init(struct xgbe_channel *channel)
1278{
1279 struct xgbe_ring *ring = channel->tx_ring;
1280 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001281 int i;
1282 int start_index = ring->cur;
1283
1284 DBGPR("-->tx_desc_init\n");
1285
1286 /* Initialze all descriptors */
1287 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001288 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001289
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001290 /* Initialize Tx descriptor */
1291 xgbe_tx_desc_reset(rdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001292 }
1293
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001294 /* Update the total number of Tx descriptors */
1295 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
1296
1297 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001298 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001299 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
1300 upper_32_bits(rdata->rdesc_dma));
1301 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
1302 lower_32_bits(rdata->rdesc_dma));
1303
1304 DBGPR("<--tx_desc_init\n");
1305}
1306
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001307static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata,
1308 struct xgbe_ring_data *rdata, unsigned int index)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001309{
1310 struct xgbe_ring_desc *rdesc = rdata->rdesc;
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001311 unsigned int rx_usecs = pdata->rx_usecs;
1312 unsigned int rx_frames = pdata->rx_frames;
1313 unsigned int inte;
Lendacky, Thomascfbfd862015-07-06 11:57:37 -05001314 dma_addr_t hdr_dma, buf_dma;
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001315
1316 if (!rx_usecs && !rx_frames) {
1317 /* No coalescing, interrupt for every descriptor */
1318 inte = 1;
1319 } else {
1320 /* Set interrupt based on Rx frame coalescing setting */
1321 if (rx_frames && !((index + 1) % rx_frames))
1322 inte = 1;
1323 else
1324 inte = 0;
1325 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001326
1327 /* Reset the Rx descriptor
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001328 * Set buffer 1 (lo) address to header dma address (lo)
1329 * Set buffer 1 (hi) address to header dma address (hi)
1330 * Set buffer 2 (lo) address to buffer dma address (lo)
1331 * Set buffer 2 (hi) address to buffer dma address (hi) and
1332 * set control bits OWN and INTE
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001333 */
Lendacky, Thomascfbfd862015-07-06 11:57:37 -05001334 hdr_dma = rdata->rx.hdr.dma_base + rdata->rx.hdr.dma_off;
1335 buf_dma = rdata->rx.buf.dma_base + rdata->rx.buf.dma_off;
1336 rdesc->desc0 = cpu_to_le32(lower_32_bits(hdr_dma));
1337 rdesc->desc1 = cpu_to_le32(upper_32_bits(hdr_dma));
1338 rdesc->desc2 = cpu_to_le32(lower_32_bits(buf_dma));
1339 rdesc->desc3 = cpu_to_le32(upper_32_bits(buf_dma));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001340
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001341 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001342
1343 /* Since the Rx DMA engine is likely running, make sure everything
1344 * is written to the descriptor(s) before setting the OWN bit
1345 * for the descriptor
1346 */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001347 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001348
1349 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
1350
1351 /* Make sure ownership is written to the descriptor */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001352 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001353}
1354
1355static void xgbe_rx_desc_init(struct xgbe_channel *channel)
1356{
1357 struct xgbe_prv_data *pdata = channel->pdata;
1358 struct xgbe_ring *ring = channel->rx_ring;
1359 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001360 unsigned int start_index = ring->cur;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001361 unsigned int i;
1362
1363 DBGPR("-->rx_desc_init\n");
1364
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001365 /* Initialize all descriptors */
1366 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001367 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001368
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001369 /* Initialize Rx descriptor */
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001370 xgbe_rx_desc_reset(pdata, rdata, i);
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001371 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001372
1373 /* Update the total number of Rx descriptors */
1374 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
1375
1376 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001377 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001378 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
1379 upper_32_bits(rdata->rdesc_dma));
1380 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
1381 lower_32_bits(rdata->rdesc_dma));
1382
1383 /* Update the Rx Descriptor Tail Pointer */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001384 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001385 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
1386 lower_32_bits(rdata->rdesc_dma));
1387
1388 DBGPR("<--rx_desc_init\n");
1389}
1390
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001391static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
1392 unsigned int addend)
1393{
1394 /* Set the addend register value and tell the device */
1395 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1396 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1397
1398 /* Wait for addend update to complete */
1399 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1400 udelay(5);
1401}
1402
1403static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1404 unsigned int nsec)
1405{
1406 /* Set the time values and tell the device */
1407 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1408 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1409 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1410
1411 /* Wait for time update to complete */
1412 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1413 udelay(5);
1414}
1415
1416static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1417{
1418 u64 nsec;
1419
1420 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1421 nsec *= NSEC_PER_SEC;
1422 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1423
1424 return nsec;
1425}
1426
1427static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1428{
Lendacky, Thomasaba97772016-11-10 17:09:45 -06001429 unsigned int tx_snr, tx_ssr;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001430 u64 nsec;
1431
Lendacky, Thomasaba97772016-11-10 17:09:45 -06001432 if (pdata->vdata->tx_tstamp_workaround) {
1433 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1434 tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR);
1435 } else {
1436 tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR);
1437 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1438 }
1439
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001440 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1441 return 0;
1442
Lendacky, Thomasaba97772016-11-10 17:09:45 -06001443 nsec = tx_ssr;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001444 nsec *= NSEC_PER_SEC;
1445 nsec += tx_snr;
1446
1447 return nsec;
1448}
1449
1450static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1451 struct xgbe_ring_desc *rdesc)
1452{
1453 u64 nsec;
1454
1455 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1456 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1457 nsec = le32_to_cpu(rdesc->desc1);
1458 nsec <<= 32;
1459 nsec |= le32_to_cpu(rdesc->desc0);
1460 if (nsec != 0xffffffffffffffffULL) {
1461 packet->rx_tstamp = nsec;
1462 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1463 RX_TSTAMP, 1);
1464 }
1465 }
1466}
1467
1468static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1469 unsigned int mac_tscr)
1470{
1471 /* Set one nano-second accuracy */
1472 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1473
1474 /* Set fine timestamp update */
1475 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1476
1477 /* Overwrite earlier timestamps */
1478 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1479
1480 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1481
1482 /* Exit if timestamping is not enabled */
1483 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1484 return 0;
1485
1486 /* Initialize time registers */
1487 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1488 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1489 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1490 xgbe_set_tstamp_time(pdata, 0, 0);
1491
1492 /* Initialize the timecounter */
1493 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1494 ktime_to_ns(ktime_get_real()));
1495
1496 return 0;
1497}
1498
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001499static void xgbe_tx_start_xmit(struct xgbe_channel *channel,
1500 struct xgbe_ring *ring)
1501{
1502 struct xgbe_prv_data *pdata = channel->pdata;
1503 struct xgbe_ring_data *rdata;
1504
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001505 /* Make sure everything is written before the register write */
1506 wmb();
1507
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001508 /* Issue a poll command to Tx DMA by writing address
1509 * of next immediate free descriptor */
1510 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1511 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1512 lower_32_bits(rdata->rdesc_dma));
1513
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -05001514 /* Start the Tx timer */
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001515 if (pdata->tx_usecs && !channel->tx_timer_active) {
1516 channel->tx_timer_active = 1;
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -05001517 mod_timer(&channel->tx_timer,
1518 jiffies + usecs_to_jiffies(pdata->tx_usecs));
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001519 }
1520
1521 ring->tx.xmit_more = 0;
1522}
1523
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001524static void xgbe_dev_xmit(struct xgbe_channel *channel)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001525{
1526 struct xgbe_prv_data *pdata = channel->pdata;
1527 struct xgbe_ring *ring = channel->tx_ring;
1528 struct xgbe_ring_data *rdata;
1529 struct xgbe_ring_desc *rdesc;
1530 struct xgbe_packet_data *packet = &ring->packet_data;
1531 unsigned int csum, tso, vlan;
1532 unsigned int tso_context, vlan_context;
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001533 unsigned int tx_set_ic;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001534 int start_index = ring->cur;
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001535 int cur_index = ring->cur;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001536 int i;
1537
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001538 DBGPR("-->xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001539
1540 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1541 CSUM_ENABLE);
1542 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1543 TSO_ENABLE);
1544 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1545 VLAN_CTAG);
1546
1547 if (tso && (packet->mss != ring->tx.cur_mss))
1548 tso_context = 1;
1549 else
1550 tso_context = 0;
1551
1552 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1553 vlan_context = 1;
1554 else
1555 vlan_context = 0;
1556
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001557 /* Determine if an interrupt should be generated for this Tx:
1558 * Interrupt:
1559 * - Tx frame count exceeds the frame count setting
1560 * - Addition of Tx frame count to the frame count since the
1561 * last interrupt was set exceeds the frame count setting
1562 * No interrupt:
1563 * - No frame count setting specified (ethtool -C ethX tx-frames 0)
1564 * - Addition of Tx frame count to the frame count since the
1565 * last interrupt was set does not exceed the frame count setting
1566 */
1567 ring->coalesce_count += packet->tx_packets;
1568 if (!pdata->tx_frames)
1569 tx_set_ic = 0;
1570 else if (packet->tx_packets > pdata->tx_frames)
1571 tx_set_ic = 1;
1572 else if ((ring->coalesce_count % pdata->tx_frames) <
1573 packet->tx_packets)
1574 tx_set_ic = 1;
1575 else
1576 tx_set_ic = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001577
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001578 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001579 rdesc = rdata->rdesc;
1580
1581 /* Create a context descriptor if this is a TSO packet */
1582 if (tso_context || vlan_context) {
1583 if (tso_context) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001584 netif_dbg(pdata, tx_queued, pdata->netdev,
1585 "TSO context descriptor, mss=%u\n",
1586 packet->mss);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001587
1588 /* Set the MSS size */
1589 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1590 MSS, packet->mss);
1591
1592 /* Mark it as a CONTEXT descriptor */
1593 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1594 CTXT, 1);
1595
1596 /* Indicate this descriptor contains the MSS */
1597 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1598 TCMSSV, 1);
1599
1600 ring->tx.cur_mss = packet->mss;
1601 }
1602
1603 if (vlan_context) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001604 netif_dbg(pdata, tx_queued, pdata->netdev,
1605 "VLAN context descriptor, ctag=%u\n",
1606 packet->vlan_ctag);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001607
1608 /* Mark it as a CONTEXT descriptor */
1609 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1610 CTXT, 1);
1611
1612 /* Set the VLAN tag */
1613 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1614 VT, packet->vlan_ctag);
1615
1616 /* Indicate this descriptor contains the VLAN tag */
1617 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1618 VLTV, 1);
1619
1620 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1621 }
1622
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001623 cur_index++;
1624 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001625 rdesc = rdata->rdesc;
1626 }
1627
1628 /* Update buffer address (for TSO this is the header) */
1629 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1630 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1631
1632 /* Update the buffer length */
1633 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1634 rdata->skb_dma_len);
1635
1636 /* VLAN tag insertion check */
1637 if (vlan)
1638 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1639 TX_NORMAL_DESC2_VLAN_INSERT);
1640
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001641 /* Timestamp enablement check */
1642 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1643 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1644
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001645 /* Mark it as First Descriptor */
1646 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1647
1648 /* Mark it as a NORMAL descriptor */
1649 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1650
1651 /* Set OWN bit if not the first descriptor */
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001652 if (cur_index != start_index)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001653 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1654
1655 if (tso) {
1656 /* Enable TSO */
1657 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1658 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1659 packet->tcp_payload_len);
1660 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1661 packet->tcp_header_len / 4);
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001662
1663 pdata->ext_stats.tx_tso_packets++;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001664 } else {
1665 /* Enable CRC and Pad Insertion */
1666 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1667
1668 /* Enable HW CSUM */
1669 if (csum)
1670 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1671 CIC, 0x3);
1672
1673 /* Set the total length to be transmitted */
1674 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1675 packet->length);
1676 }
1677
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001678 for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) {
1679 cur_index++;
1680 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001681 rdesc = rdata->rdesc;
1682
1683 /* Update buffer address */
1684 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1685 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1686
1687 /* Update the buffer length */
1688 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1689 rdata->skb_dma_len);
1690
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001691 /* Set OWN bit */
1692 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1693
1694 /* Mark it as NORMAL descriptor */
1695 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1696
1697 /* Enable HW CSUM */
1698 if (csum)
1699 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1700 CIC, 0x3);
1701 }
1702
1703 /* Set LAST bit for the last descriptor */
1704 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1705
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001706 /* Set IC bit based on Tx coalescing settings */
1707 if (tx_set_ic)
1708 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1709
Lendacky, Thomas5fb4b862014-11-20 11:03:50 -06001710 /* Save the Tx info to report back during cleanup */
1711 rdata->tx.packets = packet->tx_packets;
1712 rdata->tx.bytes = packet->tx_bytes;
1713
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001714 /* In case the Tx DMA engine is running, make sure everything
1715 * is written to the descriptor(s) before setting the OWN bit
1716 * for the first descriptor
1717 */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001718 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001719
1720 /* Set OWN bit for the first descriptor */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001721 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001722 rdesc = rdata->rdesc;
1723 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1724
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001725 if (netif_msg_tx_queued(pdata))
1726 xgbe_dump_tx_desc(pdata, ring, start_index,
1727 packet->rdesc_count, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001728
1729 /* Make sure ownership is written to the descriptor */
Lendacky, Thomas20986ed2015-10-26 17:13:54 -05001730 smp_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001731
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001732 ring->cur = cur_index + 1;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001733 if (!packet->skb->xmit_more ||
1734 netif_xmit_stopped(netdev_get_tx_queue(pdata->netdev,
1735 channel->queue_index)))
1736 xgbe_tx_start_xmit(channel, ring);
1737 else
1738 ring->tx.xmit_more = 1;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001739
1740 DBGPR(" %s: descriptors %u to %u written\n",
1741 channel->name, start_index & (ring->rdesc_count - 1),
1742 (ring->cur - 1) & (ring->rdesc_count - 1));
1743
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001744 DBGPR("<--xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001745}
1746
1747static int xgbe_dev_read(struct xgbe_channel *channel)
1748{
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001749 struct xgbe_prv_data *pdata = channel->pdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001750 struct xgbe_ring *ring = channel->rx_ring;
1751 struct xgbe_ring_data *rdata;
1752 struct xgbe_ring_desc *rdesc;
1753 struct xgbe_packet_data *packet = &ring->packet_data;
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001754 struct net_device *netdev = pdata->netdev;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001755 unsigned int err, etlt, l34t;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001756
1757 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1758
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001759 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001760 rdesc = rdata->rdesc;
1761
1762 /* Check for data availability */
1763 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1764 return 1;
1765
Lendacky, Thomas5449e272014-11-20 11:03:26 -06001766 /* Make sure descriptor fields are read after reading the OWN bit */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001767 dma_rmb();
Lendacky, Thomas5449e272014-11-20 11:03:26 -06001768
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001769 if (netif_msg_rx_status(pdata))
1770 xgbe_dump_rx_desc(pdata, ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001771
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001772 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1773 /* Timestamp Context Descriptor */
1774 xgbe_get_rx_tstamp(packet, rdesc);
1775
1776 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1777 CONTEXT, 1);
1778 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1779 CONTEXT_NEXT, 0);
1780 return 0;
1781 }
1782
1783 /* Normal Descriptor, be sure Context Descriptor bit is off */
1784 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1785
1786 /* Indicate if a Context Descriptor is next */
1787 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1788 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1789 CONTEXT_NEXT, 1);
1790
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001791 /* Get the header length */
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001792 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD)) {
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001793 rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2,
1794 RX_NORMAL_DESC2, HL);
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001795 if (rdata->rx.hdr_len)
1796 pdata->ext_stats.rx_split_header_packets++;
1797 }
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001798
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001799 /* Get the RSS hash */
1800 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, RSV)) {
1801 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1802 RSS_HASH, 1);
1803
1804 packet->rss_hash = le32_to_cpu(rdesc->desc1);
1805
1806 l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T);
1807 switch (l34t) {
1808 case RX_DESC3_L34T_IPV4_TCP:
1809 case RX_DESC3_L34T_IPV4_UDP:
1810 case RX_DESC3_L34T_IPV6_TCP:
1811 case RX_DESC3_L34T_IPV6_UDP:
1812 packet->rss_hash_type = PKT_HASH_TYPE_L4;
Dan Carpenterb6267d32014-11-13 09:19:06 +03001813 break;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001814 default:
1815 packet->rss_hash_type = PKT_HASH_TYPE_L3;
1816 }
1817 }
1818
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001819 /* Get the packet length */
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001820 rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001821
1822 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1823 /* Not all the data has been transferred for this packet */
1824 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1825 INCOMPLETE, 1);
1826 return 0;
1827 }
1828
1829 /* This is the last of the data for this packet */
1830 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1831 INCOMPLETE, 0);
1832
1833 /* Set checksum done indicator as appropriate */
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001834 if (netdev->features & NETIF_F_RXCSUM)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001835 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1836 CSUM_DONE, 1);
1837
1838 /* Check for errors (only valid in last descriptor) */
1839 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1840 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001841 netif_dbg(pdata, rx_status, netdev, "err=%u, etlt=%#x\n", err, etlt);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001842
Lendacky, Thomas7bba35b2014-11-20 11:03:38 -06001843 if (!err || !etlt) {
1844 /* No error if err is 0 or etlt is 0 */
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001845 if ((etlt == 0x09) &&
1846 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001847 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1848 VLAN_CTAG, 1);
1849 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1850 RX_NORMAL_DESC0,
1851 OVT);
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001852 netif_dbg(pdata, rx_status, netdev, "vlan-ctag=%#06x\n",
1853 packet->vlan_ctag);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001854 }
1855 } else {
1856 if ((etlt == 0x05) || (etlt == 0x06))
1857 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1858 CSUM_DONE, 0);
1859 else
1860 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1861 FRAME, 1);
1862 }
1863
1864 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1865 ring->cur & (ring->rdesc_count - 1), ring->cur);
1866
1867 return 0;
1868}
1869
1870static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1871{
1872 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1873 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1874}
1875
1876static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1877{
1878 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1879 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1880}
1881
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001882static int xgbe_enable_int(struct xgbe_channel *channel,
1883 enum xgbe_int int_id)
1884{
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001885 unsigned int dma_ch_ier;
1886
1887 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1888
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001889 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001890 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001891 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001892 break;
1893 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001894 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001895 break;
1896 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001897 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001898 break;
1899 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001900 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001901 break;
1902 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001903 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001904 break;
1905 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001906 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1907 break;
1908 case XGMAC_INT_DMA_CH_SR_TI_RI:
1909 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1910 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001911 break;
1912 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001913 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001914 break;
1915 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001916 dma_ch_ier |= channel->saved_ier;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001917 break;
1918 default:
1919 return -1;
1920 }
1921
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001922 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1923
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001924 return 0;
1925}
1926
1927static int xgbe_disable_int(struct xgbe_channel *channel,
1928 enum xgbe_int int_id)
1929{
1930 unsigned int dma_ch_ier;
1931
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001932 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1933
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001934 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001935 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001936 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001937 break;
1938 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001939 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001940 break;
1941 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001942 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001943 break;
1944 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001945 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001946 break;
1947 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001948 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001949 break;
1950 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001951 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1952 break;
1953 case XGMAC_INT_DMA_CH_SR_TI_RI:
1954 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1955 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001956 break;
1957 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001958 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001959 break;
1960 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001961 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001962 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001963 break;
1964 default:
1965 return -1;
1966 }
1967
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001968 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1969
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001970 return 0;
1971}
1972
Lendacky, Thomas5ffc0332016-11-10 17:09:29 -06001973static int __xgbe_exit(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001974{
1975 unsigned int count = 2000;
1976
1977 DBGPR("-->xgbe_exit\n");
1978
1979 /* Issue a software reset */
1980 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1981 usleep_range(10, 15);
1982
1983 /* Poll Until Poll Condition */
Dan Carpenterc7557e62015-12-15 13:12:29 +03001984 while (--count && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001985 usleep_range(500, 600);
1986
1987 if (!count)
1988 return -EBUSY;
1989
1990 DBGPR("<--xgbe_exit\n");
1991
1992 return 0;
1993}
1994
Lendacky, Thomas5ffc0332016-11-10 17:09:29 -06001995static int xgbe_exit(struct xgbe_prv_data *pdata)
1996{
1997 int ret;
1998
1999 /* To guard against possible incorrectly generated interrupts,
2000 * issue the software reset twice.
2001 */
2002 ret = __xgbe_exit(pdata);
2003 if (ret)
2004 return ret;
2005
2006 return __xgbe_exit(pdata);
2007}
2008
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002009static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
2010{
2011 unsigned int i, count;
2012
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -05002013 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
2014 return 0;
2015
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002016 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002017 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
2018
2019 /* Poll Until Poll Condition */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002020 for (i = 0; i < pdata->tx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002021 count = 2000;
Dan Carpenterc7557e62015-12-15 13:12:29 +03002022 while (--count && XGMAC_MTL_IOREAD_BITS(pdata, i,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002023 MTL_Q_TQOMR, FTQ))
2024 usleep_range(500, 600);
2025
2026 if (!count)
2027 return -EBUSY;
2028 }
2029
2030 return 0;
2031}
2032
2033static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
2034{
2035 /* Set enhanced addressing mode */
2036 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
2037
2038 /* Set the System Bus mode */
2039 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05002040 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002041}
2042
2043static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
2044{
2045 unsigned int arcache, awcache;
2046
2047 arcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05002048 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
2049 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
2050 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
2051 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
2052 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
2053 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002054 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
2055
2056 awcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05002057 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
2058 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
2059 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
2060 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
2061 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
2062 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
2063 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
2064 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002065 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
2066}
2067
2068static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
2069{
2070 unsigned int i;
2071
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002072 /* Set Tx to weighted round robin scheduling algorithm */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002073 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
2074
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002075 /* Set Tx traffic classes to use WRR algorithm with equal weights */
2076 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
2077 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
2078 MTL_TSA_ETS);
2079 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
2080 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002081
2082 /* Set Rx to strict priority algorithm */
2083 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
2084}
2085
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002086static void xgbe_queue_flow_control_threshold(struct xgbe_prv_data *pdata,
2087 unsigned int queue,
2088 unsigned int q_fifo_size)
2089{
2090 unsigned int frame_fifo_size;
2091 unsigned int rfa, rfd;
2092
2093 frame_fifo_size = XGMAC_FLOW_CONTROL_ALIGN(xgbe_get_max_frame(pdata));
2094
2095 if (pdata->pfcq[queue] && (q_fifo_size > pdata->pfc_rfa)) {
2096 /* PFC is active for this queue */
2097 rfa = pdata->pfc_rfa;
2098 rfd = rfa + frame_fifo_size;
2099 if (rfd > XGMAC_FLOW_CONTROL_MAX)
2100 rfd = XGMAC_FLOW_CONTROL_MAX;
2101 if (rfa >= XGMAC_FLOW_CONTROL_MAX)
2102 rfa = XGMAC_FLOW_CONTROL_MAX - XGMAC_FLOW_CONTROL_UNIT;
2103 } else {
2104 /* This path deals with just maximum frame sizes which are
2105 * limited to a jumbo frame of 9,000 (plus headers, etc.)
2106 * so we can never exceed the maximum allowable RFA/RFD
2107 * values.
2108 */
2109 if (q_fifo_size <= 2048) {
2110 /* rx_rfd to zero to signal no flow control */
2111 pdata->rx_rfa[queue] = 0;
2112 pdata->rx_rfd[queue] = 0;
2113 return;
2114 }
2115
2116 if (q_fifo_size <= 4096) {
2117 /* Between 2048 and 4096 */
2118 pdata->rx_rfa[queue] = 0; /* Full - 1024 bytes */
2119 pdata->rx_rfd[queue] = 1; /* Full - 1536 bytes */
2120 return;
2121 }
2122
2123 if (q_fifo_size <= frame_fifo_size) {
2124 /* Between 4096 and max-frame */
2125 pdata->rx_rfa[queue] = 2; /* Full - 2048 bytes */
2126 pdata->rx_rfd[queue] = 5; /* Full - 3584 bytes */
2127 return;
2128 }
2129
2130 if (q_fifo_size <= (frame_fifo_size * 3)) {
2131 /* Between max-frame and 3 max-frames,
2132 * trigger if we get just over a frame of data and
2133 * resume when we have just under half a frame left.
2134 */
2135 rfa = q_fifo_size - frame_fifo_size;
2136 rfd = rfa + (frame_fifo_size / 2);
2137 } else {
2138 /* Above 3 max-frames - trigger when just over
2139 * 2 frames of space available
2140 */
2141 rfa = frame_fifo_size * 2;
2142 rfa += XGMAC_FLOW_CONTROL_UNIT;
2143 rfd = rfa + frame_fifo_size;
2144 }
2145 }
2146
2147 pdata->rx_rfa[queue] = XGMAC_FLOW_CONTROL_VALUE(rfa);
2148 pdata->rx_rfd[queue] = XGMAC_FLOW_CONTROL_VALUE(rfd);
2149}
2150
2151static void xgbe_calculate_flow_control_threshold(struct xgbe_prv_data *pdata,
2152 unsigned int *fifo)
2153{
2154 unsigned int q_fifo_size;
2155 unsigned int i;
2156
2157 for (i = 0; i < pdata->rx_q_count; i++) {
2158 q_fifo_size = (fifo[i] + 1) * XGMAC_FIFO_UNIT;
2159
2160 xgbe_queue_flow_control_threshold(pdata, i, q_fifo_size);
2161 }
2162}
2163
2164static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
2165{
2166 unsigned int i;
2167
2168 for (i = 0; i < pdata->rx_q_count; i++) {
2169 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFA,
2170 pdata->rx_rfa[i]);
2171 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFD,
2172 pdata->rx_rfd[i]);
2173 }
2174}
2175
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002176static unsigned int xgbe_get_tx_fifo_size(struct xgbe_prv_data *pdata)
2177{
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002178 /* The configured value may not be the actual amount of fifo RAM */
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -05002179 return min_t(unsigned int, pdata->tx_max_fifo_size,
2180 pdata->hw_feat.tx_fifo_size);
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002181}
2182
2183static unsigned int xgbe_get_rx_fifo_size(struct xgbe_prv_data *pdata)
2184{
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002185 /* The configured value may not be the actual amount of fifo RAM */
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -05002186 return min_t(unsigned int, pdata->rx_max_fifo_size,
2187 pdata->hw_feat.rx_fifo_size);
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002188}
2189
2190static void xgbe_calculate_equal_fifo(unsigned int fifo_size,
2191 unsigned int queue_count,
2192 unsigned int *fifo)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002193{
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002194 unsigned int q_fifo_size;
2195 unsigned int p_fifo;
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002196 unsigned int i;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002197
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002198 q_fifo_size = fifo_size / queue_count;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002199
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002200 /* Calculate the fifo setting by dividing the queue's fifo size
2201 * by the fifo allocation increment (with 0 representing the
2202 * base allocation increment so decrement the result by 1).
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002203 */
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002204 p_fifo = q_fifo_size / XGMAC_FIFO_UNIT;
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002205 if (p_fifo)
2206 p_fifo--;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002207
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002208 /* Distribute the fifo equally amongst the queues */
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002209 for (i = 0; i < queue_count; i++)
2210 fifo[i] = p_fifo;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002211}
2212
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002213static unsigned int xgbe_set_nonprio_fifos(unsigned int fifo_size,
2214 unsigned int queue_count,
2215 unsigned int *fifo)
2216{
2217 unsigned int i;
2218
2219 BUILD_BUG_ON_NOT_POWER_OF_2(XGMAC_FIFO_MIN_ALLOC);
2220
2221 if (queue_count <= IEEE_8021QAZ_MAX_TCS)
2222 return fifo_size;
2223
2224 /* Rx queues 9 and up are for specialized packets,
2225 * such as PTP or DCB control packets, etc. and
2226 * don't require a large fifo
2227 */
2228 for (i = IEEE_8021QAZ_MAX_TCS; i < queue_count; i++) {
2229 fifo[i] = (XGMAC_FIFO_MIN_ALLOC / XGMAC_FIFO_UNIT) - 1;
2230 fifo_size -= XGMAC_FIFO_MIN_ALLOC;
2231 }
2232
2233 return fifo_size;
2234}
2235
2236static unsigned int xgbe_get_pfc_delay(struct xgbe_prv_data *pdata)
2237{
2238 unsigned int delay;
2239
2240 /* If a delay has been provided, use that */
2241 if (pdata->pfc->delay)
2242 return pdata->pfc->delay / 8;
2243
2244 /* Allow for two maximum size frames */
2245 delay = xgbe_get_max_frame(pdata);
2246 delay += XGMAC_ETH_PREAMBLE;
2247 delay *= 2;
2248
2249 /* Allow for PFC frame */
2250 delay += XGMAC_PFC_DATA_LEN;
2251 delay += ETH_HLEN + ETH_FCS_LEN;
2252 delay += XGMAC_ETH_PREAMBLE;
2253
2254 /* Allow for miscellaneous delays (LPI exit, cable, etc.) */
2255 delay += XGMAC_PFC_DELAYS;
2256
2257 return delay;
2258}
2259
2260static unsigned int xgbe_get_pfc_queues(struct xgbe_prv_data *pdata)
2261{
2262 unsigned int count, prio_queues;
2263 unsigned int i;
2264
2265 if (!pdata->pfc->pfc_en)
2266 return 0;
2267
2268 count = 0;
2269 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2270 for (i = 0; i < prio_queues; i++) {
2271 if (!xgbe_is_pfc_queue(pdata, i))
2272 continue;
2273
2274 pdata->pfcq[i] = 1;
2275 count++;
2276 }
2277
2278 return count;
2279}
2280
2281static void xgbe_calculate_dcb_fifo(struct xgbe_prv_data *pdata,
2282 unsigned int fifo_size,
2283 unsigned int *fifo)
2284{
2285 unsigned int q_fifo_size, rem_fifo, addn_fifo;
2286 unsigned int prio_queues;
2287 unsigned int pfc_count;
2288 unsigned int i;
2289
2290 q_fifo_size = XGMAC_FIFO_ALIGN(xgbe_get_max_frame(pdata));
2291 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2292 pfc_count = xgbe_get_pfc_queues(pdata);
2293
2294 if (!pfc_count || ((q_fifo_size * prio_queues) > fifo_size)) {
2295 /* No traffic classes with PFC enabled or can't do lossless */
2296 xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo);
2297 return;
2298 }
2299
2300 /* Calculate how much fifo we have to play with */
2301 rem_fifo = fifo_size - (q_fifo_size * prio_queues);
2302
2303 /* Calculate how much more than base fifo PFC needs, which also
2304 * becomes the threshold activation point (RFA)
2305 */
2306 pdata->pfc_rfa = xgbe_get_pfc_delay(pdata);
2307 pdata->pfc_rfa = XGMAC_FLOW_CONTROL_ALIGN(pdata->pfc_rfa);
2308
2309 if (pdata->pfc_rfa > q_fifo_size) {
2310 addn_fifo = pdata->pfc_rfa - q_fifo_size;
2311 addn_fifo = XGMAC_FIFO_ALIGN(addn_fifo);
2312 } else {
2313 addn_fifo = 0;
2314 }
2315
2316 /* Calculate DCB fifo settings:
2317 * - distribute remaining fifo between the VLAN priority
2318 * queues based on traffic class PFC enablement and overall
2319 * priority (0 is lowest priority, so start at highest)
2320 */
2321 i = prio_queues;
2322 while (i > 0) {
2323 i--;
2324
2325 fifo[i] = (q_fifo_size / XGMAC_FIFO_UNIT) - 1;
2326
2327 if (!pdata->pfcq[i] || !addn_fifo)
2328 continue;
2329
2330 if (addn_fifo > rem_fifo) {
2331 netdev_warn(pdata->netdev,
2332 "RXq%u cannot set needed fifo size\n", i);
2333 if (!rem_fifo)
2334 continue;
2335
2336 addn_fifo = rem_fifo;
2337 }
2338
2339 fifo[i] += (addn_fifo / XGMAC_FIFO_UNIT);
2340 rem_fifo -= addn_fifo;
2341 }
2342
2343 if (rem_fifo) {
2344 unsigned int inc_fifo = rem_fifo / prio_queues;
2345
2346 /* Distribute remaining fifo across queues */
2347 for (i = 0; i < prio_queues; i++)
2348 fifo[i] += (inc_fifo / XGMAC_FIFO_UNIT);
2349 }
2350}
2351
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002352static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
2353{
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002354 unsigned int fifo_size;
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002355 unsigned int fifo[XGBE_MAX_QUEUES];
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002356 unsigned int i;
2357
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002358 fifo_size = xgbe_get_tx_fifo_size(pdata);
2359
2360 xgbe_calculate_equal_fifo(fifo_size, pdata->tx_q_count, fifo);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002361
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002362 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002363 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo[i]);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002364
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002365 netif_info(pdata, drv, pdata->netdev,
2366 "%d Tx hardware queues, %d byte fifo per queue\n",
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002367 pdata->tx_q_count, ((fifo[0] + 1) * XGMAC_FIFO_UNIT));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002368}
2369
2370static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
2371{
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002372 unsigned int fifo_size;
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002373 unsigned int fifo[XGBE_MAX_QUEUES];
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002374 unsigned int prio_queues;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002375 unsigned int i;
2376
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002377 /* Clear any DCB related fifo/queue information */
2378 memset(pdata->pfcq, 0, sizeof(pdata->pfcq));
2379 pdata->pfc_rfa = 0;
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002380
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002381 fifo_size = xgbe_get_rx_fifo_size(pdata);
2382 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2383
2384 /* Assign a minimum fifo to the non-VLAN priority queues */
2385 fifo_size = xgbe_set_nonprio_fifos(fifo_size, pdata->rx_q_count, fifo);
2386
2387 if (pdata->pfc && pdata->ets)
2388 xgbe_calculate_dcb_fifo(pdata, fifo_size, fifo);
2389 else
2390 xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002391
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002392 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002393 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo[i]);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002394
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002395 xgbe_calculate_flow_control_threshold(pdata, fifo);
2396 xgbe_config_flow_control_threshold(pdata);
2397
2398 if (pdata->pfc && pdata->ets && pdata->pfc->pfc_en) {
2399 netif_info(pdata, drv, pdata->netdev,
2400 "%u Rx hardware queues\n", pdata->rx_q_count);
2401 for (i = 0; i < pdata->rx_q_count; i++)
2402 netif_info(pdata, drv, pdata->netdev,
2403 "RxQ%u, %u byte fifo queue\n", i,
2404 ((fifo[i] + 1) * XGMAC_FIFO_UNIT));
2405 } else {
2406 netif_info(pdata, drv, pdata->netdev,
2407 "%u Rx hardware queues, %u byte fifo per queue\n",
2408 pdata->rx_q_count,
2409 ((fifo[0] + 1) * XGMAC_FIFO_UNIT));
2410 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002411}
2412
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002413static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002414{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002415 unsigned int qptc, qptc_extra, queue;
2416 unsigned int prio_queues;
2417 unsigned int ppq, ppq_extra, prio;
2418 unsigned int mask;
2419 unsigned int i, j, reg, reg_val;
2420
2421 /* Map the MTL Tx Queues to Traffic Classes
2422 * Note: Tx Queues >= Traffic Classes
2423 */
2424 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
2425 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
2426
2427 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
2428 for (j = 0; j < qptc; j++) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002429 netif_dbg(pdata, drv, pdata->netdev,
2430 "TXq%u mapped to TC%u\n", queue, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002431 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2432 Q2TCMAP, i);
2433 pdata->q2tc_map[queue++] = i;
2434 }
2435
2436 if (i < qptc_extra) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002437 netif_dbg(pdata, drv, pdata->netdev,
2438 "TXq%u mapped to TC%u\n", queue, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002439 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2440 Q2TCMAP, i);
2441 pdata->q2tc_map[queue++] = i;
2442 }
2443 }
2444
2445 /* Map the 8 VLAN priority values to available MTL Rx queues */
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002446 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002447 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
2448 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
2449
2450 reg = MAC_RQC2R;
2451 reg_val = 0;
2452 for (i = 0, prio = 0; i < prio_queues;) {
2453 mask = 0;
2454 for (j = 0; j < ppq; j++) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002455 netif_dbg(pdata, drv, pdata->netdev,
2456 "PRIO%u mapped to RXq%u\n", prio, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002457 mask |= (1 << prio);
2458 pdata->prio2q_map[prio++] = i;
2459 }
2460
2461 if (i < ppq_extra) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002462 netif_dbg(pdata, drv, pdata->netdev,
2463 "PRIO%u mapped to RXq%u\n", prio, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002464 mask |= (1 << prio);
2465 pdata->prio2q_map[prio++] = i;
2466 }
2467
2468 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
2469
2470 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
2471 continue;
2472
2473 XGMAC_IOWRITE(pdata, reg, reg_val);
2474 reg += MAC_RQC2_INC;
2475 reg_val = 0;
2476 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002477
2478 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
2479 reg = MTL_RQDCM0R;
2480 reg_val = 0;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002481 for (i = 0; i < pdata->rx_q_count;) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002482 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
2483
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002484 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002485 continue;
2486
2487 XGMAC_IOWRITE(pdata, reg, reg_val);
2488
2489 reg += MTL_RQDCM_INC;
2490 reg_val = 0;
2491 }
2492}
2493
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002494static void xgbe_config_tc(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002495{
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002496 unsigned int offset, queue, prio;
2497 u8 i;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002498
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002499 netdev_reset_tc(pdata->netdev);
2500 if (!pdata->num_tcs)
2501 return;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002502
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002503 netdev_set_num_tc(pdata->netdev, pdata->num_tcs);
2504
2505 for (i = 0, queue = 0, offset = 0; i < pdata->num_tcs; i++) {
2506 while ((queue < pdata->tx_q_count) &&
2507 (pdata->q2tc_map[queue] == i))
2508 queue++;
2509
2510 netif_dbg(pdata, drv, pdata->netdev, "TC%u using TXq%u-%u\n",
2511 i, offset, queue - 1);
2512 netdev_set_tc_queue(pdata->netdev, i, queue - offset, offset);
2513 offset = queue;
2514 }
2515
2516 if (!pdata->ets)
2517 return;
2518
2519 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++)
2520 netdev_set_prio_tc_map(pdata->netdev, prio,
2521 pdata->ets->prio_tc[prio]);
2522}
2523
2524static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
2525{
2526 struct ieee_ets *ets = pdata->ets;
2527 unsigned int total_weight, min_weight, weight;
2528 unsigned int mask, reg, reg_val;
2529 unsigned int i, prio;
2530
2531 if (!ets)
2532 return;
2533
2534 /* Set Tx to deficit weighted round robin scheduling algorithm (when
2535 * traffic class is using ETS algorithm)
2536 */
2537 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
2538
2539 /* Set Traffic Class algorithms */
2540 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
2541 min_weight = total_weight / 100;
2542 if (!min_weight)
2543 min_weight = 1;
2544
2545 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
2546 /* Map the priorities to the traffic class */
2547 mask = 0;
2548 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
2549 if (ets->prio_tc[prio] == i)
2550 mask |= (1 << prio);
2551 }
2552 mask &= 0xff;
2553
2554 netif_dbg(pdata, drv, pdata->netdev, "TC%u PRIO mask=%#x\n",
2555 i, mask);
2556 reg = MTL_TCPM0R + (MTL_TCPM_INC * (i / MTL_TCPM_TC_PER_REG));
2557 reg_val = XGMAC_IOREAD(pdata, reg);
2558
2559 reg_val &= ~(0xff << ((i % MTL_TCPM_TC_PER_REG) << 3));
2560 reg_val |= (mask << ((i % MTL_TCPM_TC_PER_REG) << 3));
2561
2562 XGMAC_IOWRITE(pdata, reg, reg_val);
2563
2564 /* Set the traffic class algorithm */
2565 switch (ets->tc_tsa[i]) {
2566 case IEEE_8021QAZ_TSA_STRICT:
2567 netif_dbg(pdata, drv, pdata->netdev,
2568 "TC%u using SP\n", i);
2569 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
2570 MTL_TSA_SP);
2571 break;
2572 case IEEE_8021QAZ_TSA_ETS:
2573 weight = total_weight * ets->tc_tx_bw[i] / 100;
2574 weight = clamp(weight, min_weight, total_weight);
2575
2576 netif_dbg(pdata, drv, pdata->netdev,
2577 "TC%u using DWRR (weight %u)\n", i, weight);
2578 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
2579 MTL_TSA_ETS);
2580 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
2581 weight);
2582 break;
2583 }
2584 }
2585
2586 xgbe_config_tc(pdata);
2587}
2588
2589static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
2590{
2591 if (!test_bit(XGBE_DOWN, &pdata->dev_state)) {
2592 /* Just stop the Tx queues while Rx fifo is changed */
2593 netif_tx_stop_all_queues(pdata->netdev);
2594
2595 /* Suspend Rx so that fifo's can be adjusted */
2596 pdata->hw_if.disable_rx(pdata);
2597 }
2598
2599 xgbe_config_rx_fifo_size(pdata);
2600 xgbe_config_flow_control(pdata);
2601
2602 if (!test_bit(XGBE_DOWN, &pdata->dev_state)) {
2603 /* Resume Rx */
2604 pdata->hw_if.enable_rx(pdata);
2605
2606 /* Resume Tx queues */
2607 netif_tx_start_all_queues(pdata->netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002608 }
2609}
2610
2611static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
2612{
2613 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05002614
2615 /* Filtering is done using perfect filtering and hash filtering */
2616 if (pdata->hw_feat.hash_table_size) {
2617 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
2618 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
2619 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
2620 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002621}
2622
2623static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
2624{
2625 unsigned int val;
2626
2627 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
2628
2629 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
2630}
2631
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002632static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata)
2633{
Lendacky, Thomase57f7a32016-11-03 13:18:27 -05002634 xgbe_set_speed(pdata, pdata->phy_speed);
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002635}
2636
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002637static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
2638{
2639 if (pdata->netdev->features & NETIF_F_RXCSUM)
2640 xgbe_enable_rx_csum(pdata);
2641 else
2642 xgbe_disable_rx_csum(pdata);
2643}
2644
2645static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
2646{
Lendacky, Thomas6e5eed02014-06-24 16:19:12 -05002647 /* Indicate that VLAN Tx CTAGs come from context descriptors */
2648 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
2649 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
2650
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002651 /* Set the current VLAN Hash Table register value */
2652 xgbe_update_vlan_hash_table(pdata);
2653
2654 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
2655 xgbe_enable_rx_vlan_filtering(pdata);
2656 else
2657 xgbe_disable_rx_vlan_filtering(pdata);
2658
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002659 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2660 xgbe_enable_rx_vlan_stripping(pdata);
2661 else
2662 xgbe_disable_rx_vlan_stripping(pdata);
2663}
2664
Lendacky, Thomas60265102014-09-05 18:02:30 -05002665static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
2666{
2667 bool read_hi;
2668 u64 val;
2669
Lendacky, Thomase5a20b92016-11-03 13:19:07 -05002670 if (pdata->vdata->mmc_64bit) {
2671 switch (reg_lo) {
2672 /* These registers are always 32 bit */
2673 case MMC_RXRUNTERROR:
2674 case MMC_RXJABBERERROR:
2675 case MMC_RXUNDERSIZE_G:
2676 case MMC_RXOVERSIZE_G:
2677 case MMC_RXWATCHDOGERROR:
2678 read_hi = false;
2679 break;
Lendacky, Thomas60265102014-09-05 18:02:30 -05002680
Lendacky, Thomase5a20b92016-11-03 13:19:07 -05002681 default:
2682 read_hi = true;
2683 }
2684 } else {
2685 switch (reg_lo) {
2686 /* These registers are always 64 bit */
2687 case MMC_TXOCTETCOUNT_GB_LO:
2688 case MMC_TXOCTETCOUNT_G_LO:
2689 case MMC_RXOCTETCOUNT_GB_LO:
2690 case MMC_RXOCTETCOUNT_G_LO:
2691 read_hi = true;
2692 break;
2693
2694 default:
2695 read_hi = false;
2696 }
Lendacky, Thomas3947d782015-09-30 08:52:38 -05002697 }
Lendacky, Thomas60265102014-09-05 18:02:30 -05002698
2699 val = XGMAC_IOREAD(pdata, reg_lo);
2700
2701 if (read_hi)
2702 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
2703
2704 return val;
2705}
2706
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002707static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
2708{
2709 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2710 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
2711
2712 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
2713 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002714 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002715
2716 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
2717 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002718 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002719
2720 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
2721 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002722 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002723
2724 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
2725 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002726 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002727
2728 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
2729 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002730 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002731
2732 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
2733 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002734 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002735
2736 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
2737 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002738 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002739
2740 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
2741 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002742 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002743
2744 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
2745 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002746 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002747
2748 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
2749 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002750 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002751
2752 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
2753 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002754 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002755
2756 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2757 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002758 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002759
2760 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2761 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002762 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002763
2764 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2765 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002766 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002767
2768 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2769 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002770 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002771
2772 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2773 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002774 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002775
2776 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2777 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002778 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002779
2780 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2781 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002782 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002783}
2784
2785static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2786{
2787 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2788 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2789
2790 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2791 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002792 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002793
2794 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2795 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002796 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002797
2798 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2799 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002800 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002801
2802 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2803 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002804 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002805
2806 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2807 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002808 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002809
2810 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2811 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002812 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002813
2814 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2815 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002816 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002817
2818 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2819 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002820 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002821
2822 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
2823 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002824 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002825
2826 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
2827 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002828 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002829
2830 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
2831 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002832 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002833
2834 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
2835 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002836 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002837
2838 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
2839 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002840 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002841
2842 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
2843 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002844 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002845
2846 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
2847 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002848 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002849
2850 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
2851 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002852 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002853
2854 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
2855 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002856 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002857
2858 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
2859 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002860 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002861
2862 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
2863 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002864 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002865
2866 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
2867 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002868 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002869
2870 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
2871 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002872 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002873
2874 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
2875 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002876 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002877
2878 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
2879 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002880 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002881}
2882
2883static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
2884{
2885 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2886
2887 /* Freeze counters */
2888 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
2889
2890 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002891 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002892
2893 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002894 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002895
2896 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002897 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002898
2899 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002900 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002901
2902 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002903 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002904
2905 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002906 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002907
2908 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002909 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002910
2911 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002912 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002913
2914 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002915 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002916
2917 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002918 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002919
2920 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002921 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002922
2923 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002924 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002925
2926 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002927 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002928
2929 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002930 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002931
2932 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002933 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002934
2935 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002936 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002937
2938 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002939 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002940
2941 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002942 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002943
2944 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002945 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002946
2947 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002948 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002949
2950 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002951 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002952
2953 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002954 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002955
2956 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002957 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002958
2959 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002960 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002961
2962 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002963 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002964
2965 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002966 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002967
2968 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002969 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002970
2971 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002972 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002973
2974 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002975 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002976
2977 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002978 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002979
2980 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002981 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002982
2983 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002984 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002985
2986 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002987 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002988
2989 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002990 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002991
2992 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002993 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002994
2995 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002996 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002997
2998 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002999 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003000
3001 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05003002 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003003
3004 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05003005 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003006
3007 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05003008 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003009
3010 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05003011 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003012
3013 /* Un-freeze counters */
3014 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
3015}
3016
3017static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
3018{
3019 /* Set counters to reset on read */
3020 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
3021
3022 /* Reset the counters */
3023 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
3024}
3025
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003026static void xgbe_txq_prepare_tx_stop(struct xgbe_prv_data *pdata,
3027 unsigned int queue)
3028{
3029 unsigned int tx_status;
3030 unsigned long tx_timeout;
3031
3032 /* The Tx engine cannot be stopped if it is actively processing
3033 * packets. Wait for the Tx queue to empty the Tx fifo. Don't
3034 * wait forever though...
3035 */
3036 tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
3037 while (time_before(jiffies, tx_timeout)) {
3038 tx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR);
3039 if ((XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TRCSTS) != 1) &&
3040 (XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TXQSTS) == 0))
3041 break;
3042
3043 usleep_range(500, 1000);
3044 }
3045
3046 if (!time_before(jiffies, tx_timeout))
3047 netdev_info(pdata->netdev,
3048 "timed out waiting for Tx queue %u to empty\n",
3049 queue);
3050}
3051
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003052static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003053 unsigned int queue)
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003054{
3055 unsigned int tx_dsr, tx_pos, tx_qidx;
3056 unsigned int tx_status;
3057 unsigned long tx_timeout;
3058
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003059 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) > 0x20)
3060 return xgbe_txq_prepare_tx_stop(pdata, queue);
3061
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003062 /* Calculate the status register to read and the position within */
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003063 if (queue < DMA_DSRX_FIRST_QUEUE) {
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003064 tx_dsr = DMA_DSR0;
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003065 tx_pos = (queue * DMA_DSR_Q_WIDTH) + DMA_DSR0_TPS_START;
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003066 } else {
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003067 tx_qidx = queue - DMA_DSRX_FIRST_QUEUE;
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003068
3069 tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
3070 tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
3071 DMA_DSRX_TPS_START;
3072 }
3073
3074 /* The Tx engine cannot be stopped if it is actively processing
3075 * descriptors. Wait for the Tx engine to enter the stopped or
3076 * suspended state. Don't wait forever though...
3077 */
3078 tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
3079 while (time_before(jiffies, tx_timeout)) {
3080 tx_status = XGMAC_IOREAD(pdata, tx_dsr);
3081 tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
3082 if ((tx_status == DMA_TPS_STOPPED) ||
3083 (tx_status == DMA_TPS_SUSPENDED))
3084 break;
3085
3086 usleep_range(500, 1000);
3087 }
3088
3089 if (!time_before(jiffies, tx_timeout))
3090 netdev_info(pdata->netdev,
3091 "timed out waiting for Tx DMA channel %u to stop\n",
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003092 queue);
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003093}
3094
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003095static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
3096{
3097 struct xgbe_channel *channel;
3098 unsigned int i;
3099
3100 /* Enable each Tx DMA channel */
3101 channel = pdata->channel;
3102 for (i = 0; i < pdata->channel_count; i++, channel++) {
3103 if (!channel->tx_ring)
3104 break;
3105
3106 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
3107 }
3108
3109 /* Enable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05003110 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003111 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
3112 MTL_Q_ENABLED);
3113
3114 /* Enable MAC Tx */
3115 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
3116}
3117
3118static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
3119{
3120 struct xgbe_channel *channel;
3121 unsigned int i;
3122
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003123 /* Prepare for Tx DMA channel stop */
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003124 for (i = 0; i < pdata->tx_q_count; i++)
3125 xgbe_prepare_tx_stop(pdata, i);
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003126
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003127 /* Disable MAC Tx */
3128 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
3129
3130 /* Disable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05003131 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003132 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
3133
3134 /* Disable each Tx DMA channel */
3135 channel = pdata->channel;
3136 for (i = 0; i < pdata->channel_count; i++, channel++) {
3137 if (!channel->tx_ring)
3138 break;
3139
3140 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
3141 }
3142}
3143
Lendacky, Thomasc3727d62016-02-17 11:49:16 -06003144static void xgbe_prepare_rx_stop(struct xgbe_prv_data *pdata,
3145 unsigned int queue)
3146{
3147 unsigned int rx_status;
3148 unsigned long rx_timeout;
3149
3150 /* The Rx engine cannot be stopped if it is actively processing
3151 * packets. Wait for the Rx queue to empty the Rx fifo. Don't
3152 * wait forever though...
3153 */
3154 rx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
3155 while (time_before(jiffies, rx_timeout)) {
3156 rx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR);
3157 if ((XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) &&
3158 (XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0))
3159 break;
3160
3161 usleep_range(500, 1000);
3162 }
3163
3164 if (!time_before(jiffies, rx_timeout))
3165 netdev_info(pdata->netdev,
3166 "timed out waiting for Rx queue %u to empty\n",
3167 queue);
3168}
3169
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003170static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
3171{
3172 struct xgbe_channel *channel;
3173 unsigned int reg_val, i;
3174
3175 /* Enable each Rx DMA channel */
3176 channel = pdata->channel;
3177 for (i = 0; i < pdata->channel_count; i++, channel++) {
3178 if (!channel->rx_ring)
3179 break;
3180
3181 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
3182 }
3183
3184 /* Enable each Rx queue */
3185 reg_val = 0;
Lendacky, Thomas853eb162014-07-29 08:57:31 -05003186 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003187 reg_val |= (0x02 << (i << 1));
3188 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
3189
3190 /* Enable MAC Rx */
3191 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
3192 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
3193 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
3194 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
3195}
3196
3197static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
3198{
3199 struct xgbe_channel *channel;
3200 unsigned int i;
3201
3202 /* Disable MAC Rx */
3203 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
3204 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
3205 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
3206 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
3207
Lendacky, Thomasc3727d62016-02-17 11:49:16 -06003208 /* Prepare for Rx DMA channel stop */
3209 for (i = 0; i < pdata->rx_q_count; i++)
3210 xgbe_prepare_rx_stop(pdata, i);
3211
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003212 /* Disable each Rx queue */
3213 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
3214
3215 /* Disable each Rx DMA channel */
3216 channel = pdata->channel;
3217 for (i = 0; i < pdata->channel_count; i++, channel++) {
3218 if (!channel->rx_ring)
3219 break;
3220
3221 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
3222 }
3223}
3224
3225static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
3226{
3227 struct xgbe_channel *channel;
3228 unsigned int i;
3229
3230 /* Enable each Tx DMA channel */
3231 channel = pdata->channel;
3232 for (i = 0; i < pdata->channel_count; i++, channel++) {
3233 if (!channel->tx_ring)
3234 break;
3235
3236 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
3237 }
3238
3239 /* Enable MAC Tx */
3240 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
3241}
3242
3243static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
3244{
3245 struct xgbe_channel *channel;
3246 unsigned int i;
3247
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003248 /* Prepare for Tx DMA channel stop */
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003249 for (i = 0; i < pdata->tx_q_count; i++)
3250 xgbe_prepare_tx_stop(pdata, i);
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003251
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003252 /* Disable MAC Tx */
3253 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
3254
3255 /* Disable each Tx DMA channel */
3256 channel = pdata->channel;
3257 for (i = 0; i < pdata->channel_count; i++, channel++) {
3258 if (!channel->tx_ring)
3259 break;
3260
3261 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
3262 }
3263}
3264
3265static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
3266{
3267 struct xgbe_channel *channel;
3268 unsigned int i;
3269
3270 /* Enable each Rx DMA channel */
3271 channel = pdata->channel;
3272 for (i = 0; i < pdata->channel_count; i++, channel++) {
3273 if (!channel->rx_ring)
3274 break;
3275
3276 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
3277 }
3278}
3279
3280static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
3281{
3282 struct xgbe_channel *channel;
3283 unsigned int i;
3284
3285 /* Disable each Rx DMA channel */
3286 channel = pdata->channel;
3287 for (i = 0; i < pdata->channel_count; i++, channel++) {
3288 if (!channel->rx_ring)
3289 break;
3290
3291 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
3292 }
3293}
3294
3295static int xgbe_init(struct xgbe_prv_data *pdata)
3296{
3297 struct xgbe_desc_if *desc_if = &pdata->desc_if;
3298 int ret;
3299
3300 DBGPR("-->xgbe_init\n");
3301
3302 /* Flush Tx queues */
3303 ret = xgbe_flush_tx_queues(pdata);
3304 if (ret)
3305 return ret;
3306
3307 /*
3308 * Initialize DMA related features
3309 */
3310 xgbe_config_dma_bus(pdata);
3311 xgbe_config_dma_cache(pdata);
3312 xgbe_config_osp_mode(pdata);
3313 xgbe_config_pblx8(pdata);
3314 xgbe_config_tx_pbl_val(pdata);
3315 xgbe_config_rx_pbl_val(pdata);
3316 xgbe_config_rx_coalesce(pdata);
3317 xgbe_config_tx_coalesce(pdata);
3318 xgbe_config_rx_buffer_size(pdata);
3319 xgbe_config_tso_mode(pdata);
Lendacky, Thomas174fd252014-11-04 16:06:50 -06003320 xgbe_config_sph_mode(pdata);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06003321 xgbe_config_rss(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003322 desc_if->wrapper_tx_desc_init(pdata);
3323 desc_if->wrapper_rx_desc_init(pdata);
3324 xgbe_enable_dma_interrupts(pdata);
3325
3326 /*
3327 * Initialize MTL related features
3328 */
3329 xgbe_config_mtl_mode(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05003330 xgbe_config_queue_mapping(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003331 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
3332 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
3333 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
3334 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
3335 xgbe_config_tx_fifo_size(pdata);
3336 xgbe_config_rx_fifo_size(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003337 /*TODO: Error Packet and undersized good Packet forwarding enable
3338 (FEP and FUP)
3339 */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05003340 xgbe_config_dcb_tc(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003341 xgbe_enable_mtl_interrupts(pdata);
3342
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003343 /*
3344 * Initialize MAC related features
3345 */
3346 xgbe_config_mac_address(pdata);
Lendacky, Thomasb8763822015-04-09 12:11:57 -05003347 xgbe_config_rx_mode(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003348 xgbe_config_jumbo_enable(pdata);
3349 xgbe_config_flow_control(pdata);
Lendacky, Thomas916102c2015-01-16 12:46:45 -06003350 xgbe_config_mac_speed(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003351 xgbe_config_checksum_offload(pdata);
3352 xgbe_config_vlan_support(pdata);
3353 xgbe_config_mmc(pdata);
3354 xgbe_enable_mac_interrupts(pdata);
3355
Lendacky, Thomase78332b2016-11-10 17:10:26 -06003356 /*
3357 * Initialize ECC related features
3358 */
3359 xgbe_enable_ecc_interrupts(pdata);
3360
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003361 DBGPR("<--xgbe_init\n");
3362
3363 return 0;
3364}
3365
3366void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
3367{
3368 DBGPR("-->xgbe_init_function_ptrs\n");
3369
3370 hw_if->tx_complete = xgbe_tx_complete;
3371
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003372 hw_if->set_mac_address = xgbe_set_mac_address;
Lendacky, Thomasb8763822015-04-09 12:11:57 -05003373 hw_if->config_rx_mode = xgbe_config_rx_mode;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003374
3375 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
3376 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
3377
3378 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
3379 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05003380 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
3381 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
3382 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003383
3384 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
3385 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
3386
Lendacky, Thomase57f7a32016-11-03 13:18:27 -05003387 hw_if->set_speed = xgbe_set_speed;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003388
3389 hw_if->enable_tx = xgbe_enable_tx;
3390 hw_if->disable_tx = xgbe_disable_tx;
3391 hw_if->enable_rx = xgbe_enable_rx;
3392 hw_if->disable_rx = xgbe_disable_rx;
3393
3394 hw_if->powerup_tx = xgbe_powerup_tx;
3395 hw_if->powerdown_tx = xgbe_powerdown_tx;
3396 hw_if->powerup_rx = xgbe_powerup_rx;
3397 hw_if->powerdown_rx = xgbe_powerdown_rx;
3398
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06003399 hw_if->dev_xmit = xgbe_dev_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003400 hw_if->dev_read = xgbe_dev_read;
3401 hw_if->enable_int = xgbe_enable_int;
3402 hw_if->disable_int = xgbe_disable_int;
3403 hw_if->init = xgbe_init;
3404 hw_if->exit = xgbe_exit;
3405
3406 /* Descriptor related Sequences have to be initialized here */
3407 hw_if->tx_desc_init = xgbe_tx_desc_init;
3408 hw_if->rx_desc_init = xgbe_rx_desc_init;
3409 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
3410 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
3411 hw_if->is_last_desc = xgbe_is_last_desc;
3412 hw_if->is_context_desc = xgbe_is_context_desc;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06003413 hw_if->tx_start_xmit = xgbe_tx_start_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003414
3415 /* For FLOW ctrl */
3416 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
3417 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
3418
3419 /* For RX coalescing */
3420 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
3421 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
3422 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
3423 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
3424
3425 /* For RX and TX threshold config */
3426 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
3427 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
3428
3429 /* For RX and TX Store and Forward Mode config */
3430 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
3431 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
3432
3433 /* For TX DMA Operating on Second Frame config */
3434 hw_if->config_osp_mode = xgbe_config_osp_mode;
3435
3436 /* For RX and TX PBL config */
3437 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
3438 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
3439 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
3440 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
3441 hw_if->config_pblx8 = xgbe_config_pblx8;
3442
3443 /* For MMC statistics support */
3444 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
3445 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
3446 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
3447
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05003448 /* For PTP config */
3449 hw_if->config_tstamp = xgbe_config_tstamp;
3450 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
3451 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
3452 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
3453 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
3454
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05003455 /* For Data Center Bridging config */
Lendacky, Thomasb3b71592016-02-17 11:49:08 -06003456 hw_if->config_tc = xgbe_config_tc;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05003457 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
3458 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
3459
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06003460 /* For Receive Side Scaling */
3461 hw_if->enable_rss = xgbe_enable_rss;
3462 hw_if->disable_rss = xgbe_disable_rss;
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -06003463 hw_if->set_rss_hash_key = xgbe_set_rss_hash_key;
3464 hw_if->set_rss_lookup_table = xgbe_set_rss_lookup_table;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06003465
Lendacky, Thomase78332b2016-11-10 17:10:26 -06003466 /* For ECC */
3467 hw_if->disable_ecc_ded = xgbe_disable_ecc_ded;
3468 hw_if->disable_ecc_sec = xgbe_disable_ecc_sec;
3469
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003470 DBGPR("<--xgbe_init_function_ptrs\n");
3471}