blob: ff7f5ab4d5fb6193022b54fcf4e4a5625912c7fa [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, Thomase57f7a32016-11-03 13:18:27 -0500727static int xgbe_set_speed(struct xgbe_prv_data *pdata, int speed)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500728{
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500729 unsigned int ss;
Lendacky, Thomasc3152d42015-01-16 12:47:00 -0600730
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500731 switch (speed) {
732 case SPEED_1000:
733 ss = 0x03;
734 break;
735 case SPEED_2500:
736 ss = 0x02;
737 break;
738 case SPEED_10000:
739 ss = 0x00;
740 break;
741 default:
742 return -EINVAL;
743 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500744
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500745 if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) != ss)
746 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, ss);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500747
748 return 0;
749}
750
Lendacky, Thomasb4eee842016-02-17 11:48:08 -0600751static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
752{
753 /* Put the VLAN tag in the Rx descriptor */
754 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
755
756 /* Don't check the VLAN type */
757 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
758
759 /* Check only C-TAG (0x8100) packets */
760 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
761
762 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
763 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
764
765 /* Enable VLAN tag stripping */
766 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
767
768 return 0;
769}
770
771static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
772{
773 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
774
775 return 0;
776}
777
778static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
779{
780 /* Enable VLAN filtering */
781 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
782
783 /* Enable VLAN Hash Table filtering */
784 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
785
786 /* Disable VLAN tag inverse matching */
787 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
788
789 /* Only filter on the lower 12-bits of the VLAN tag */
790 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
791
792 /* In order for the VLAN Hash Table filtering to be effective,
793 * the VLAN tag identifier in the VLAN Tag Register must not
794 * be zero. Set the VLAN tag identifier to "1" to enable the
795 * VLAN Hash Table filtering. This implies that a VLAN tag of
796 * 1 will always pass filtering.
797 */
798 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
799
800 return 0;
801}
802
803static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
804{
805 /* Disable VLAN filtering */
806 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
807
808 return 0;
809}
810
811static u32 xgbe_vid_crc32_le(__le16 vid_le)
812{
813 u32 poly = 0xedb88320; /* CRCPOLY_LE */
814 u32 crc = ~0;
815 u32 temp = 0;
816 unsigned char *data = (unsigned char *)&vid_le;
817 unsigned char data_byte = 0;
818 int i, bits;
819
820 bits = get_bitmask_order(VLAN_VID_MASK);
821 for (i = 0; i < bits; i++) {
822 if ((i % 8) == 0)
823 data_byte = data[i / 8];
824
825 temp = ((crc & 1) ^ data_byte) & 1;
826 crc >>= 1;
827 data_byte >>= 1;
828
829 if (temp)
830 crc ^= poly;
831 }
832
833 return crc;
834}
835
836static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
837{
838 u32 crc;
839 u16 vid;
840 __le16 vid_le;
841 u16 vlan_hash_table = 0;
842
843 /* Generate the VLAN Hash Table value */
844 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
845 /* Get the CRC32 value of the VLAN ID */
846 vid_le = cpu_to_le16(vid);
847 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
848
849 vlan_hash_table |= (1 << crc);
850 }
851
852 /* Set the VLAN Hash Table filtering register */
853 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
854
855 return 0;
856}
857
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500858static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
859 unsigned int enable)
860{
861 unsigned int val = enable ? 1 : 0;
862
863 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
864 return 0;
865
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500866 netif_dbg(pdata, drv, pdata->netdev, "%s promiscuous mode\n",
867 enable ? "entering" : "leaving");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500868 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
869
Lendacky, Thomasb4eee842016-02-17 11:48:08 -0600870 /* Hardware will still perform VLAN filtering in promiscuous mode */
871 if (enable) {
872 xgbe_disable_rx_vlan_filtering(pdata);
873 } else {
874 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
875 xgbe_enable_rx_vlan_filtering(pdata);
876 }
877
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500878 return 0;
879}
880
881static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
882 unsigned int enable)
883{
884 unsigned int val = enable ? 1 : 0;
885
886 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
887 return 0;
888
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500889 netif_dbg(pdata, drv, pdata->netdev, "%s allmulti mode\n",
890 enable ? "entering" : "leaving");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500891 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
892
893 return 0;
894}
895
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500896static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
897 struct netdev_hw_addr *ha, unsigned int *mac_reg)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500898{
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500899 unsigned int mac_addr_hi, mac_addr_lo;
900 u8 *mac_addr;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500901
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500902 mac_addr_lo = 0;
903 mac_addr_hi = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500904
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500905 if (ha) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500906 mac_addr = (u8 *)&mac_addr_lo;
907 mac_addr[0] = ha->addr[0];
908 mac_addr[1] = ha->addr[1];
909 mac_addr[2] = ha->addr[2];
910 mac_addr[3] = ha->addr[3];
911 mac_addr = (u8 *)&mac_addr_hi;
912 mac_addr[0] = ha->addr[4];
913 mac_addr[1] = ha->addr[5];
914
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500915 netif_dbg(pdata, drv, pdata->netdev,
916 "adding mac address %pM at %#x\n",
917 ha->addr, *mac_reg);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500918
919 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500920 }
921
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500922 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
923 *mac_reg += MAC_MACA_INC;
924 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
925 *mac_reg += MAC_MACA_INC;
926}
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500927
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500928static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
929{
930 struct net_device *netdev = pdata->netdev;
931 struct netdev_hw_addr *ha;
932 unsigned int mac_reg;
933 unsigned int addn_macs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500934
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500935 mac_reg = MAC_MACA1HR;
936 addn_macs = pdata->hw_feat.addn_mac;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500937
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500938 if (netdev_uc_count(netdev) > addn_macs) {
939 xgbe_set_promiscuous_mode(pdata, 1);
940 } else {
941 netdev_for_each_uc_addr(ha, netdev) {
942 xgbe_set_mac_reg(pdata, ha, &mac_reg);
943 addn_macs--;
944 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500945
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500946 if (netdev_mc_count(netdev) > addn_macs) {
947 xgbe_set_all_multicast_mode(pdata, 1);
948 } else {
949 netdev_for_each_mc_addr(ha, netdev) {
950 xgbe_set_mac_reg(pdata, ha, &mac_reg);
951 addn_macs--;
952 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500953 }
954 }
955
956 /* Clear remaining additional MAC address entries */
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500957 while (addn_macs--)
958 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
959}
960
961static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
962{
963 struct net_device *netdev = pdata->netdev;
964 struct netdev_hw_addr *ha;
965 unsigned int hash_reg;
966 unsigned int hash_table_shift, hash_table_count;
967 u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
968 u32 crc;
969 unsigned int i;
970
971 hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
972 hash_table_count = pdata->hw_feat.hash_table_size / 32;
973 memset(hash_table, 0, sizeof(hash_table));
974
975 /* Build the MAC Hash Table register values */
976 netdev_for_each_uc_addr(ha, netdev) {
977 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
978 crc >>= hash_table_shift;
979 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500980 }
981
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500982 netdev_for_each_mc_addr(ha, netdev) {
983 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
984 crc >>= hash_table_shift;
985 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
986 }
987
988 /* Set the MAC Hash Table registers */
989 hash_reg = MAC_HTR0;
990 for (i = 0; i < hash_table_count; i++) {
991 XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
992 hash_reg += MAC_HTR_INC;
993 }
994}
995
996static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
997{
998 if (pdata->hw_feat.hash_table_size)
999 xgbe_set_mac_hash_table(pdata);
1000 else
1001 xgbe_set_mac_addn_addrs(pdata);
1002
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001003 return 0;
1004}
1005
1006static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
1007{
1008 unsigned int mac_addr_hi, mac_addr_lo;
1009
1010 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
1011 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
1012 (addr[1] << 8) | (addr[0] << 0);
1013
1014 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
1015 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
1016
1017 return 0;
1018}
1019
Lendacky, Thomasb8763822015-04-09 12:11:57 -05001020static int xgbe_config_rx_mode(struct xgbe_prv_data *pdata)
1021{
1022 struct net_device *netdev = pdata->netdev;
1023 unsigned int pr_mode, am_mode;
1024
1025 pr_mode = ((netdev->flags & IFF_PROMISC) != 0);
1026 am_mode = ((netdev->flags & IFF_ALLMULTI) != 0);
1027
1028 xgbe_set_promiscuous_mode(pdata, pr_mode);
1029 xgbe_set_all_multicast_mode(pdata, am_mode);
1030
1031 xgbe_add_mac_addresses(pdata);
1032
1033 return 0;
1034}
1035
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001036static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,
1037 int mmd_reg)
1038{
1039 unsigned long flags;
1040 unsigned int mmd_address, index, offset;
1041 int mmd_data;
1042
1043 if (mmd_reg & MII_ADDR_C45)
1044 mmd_address = mmd_reg & ~MII_ADDR_C45;
1045 else
1046 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1047
1048 /* The PCS registers are accessed using mmio. The underlying
1049 * management interface uses indirect addressing to access the MMD
1050 * register sets. This requires accessing of the PCS register in two
1051 * phases, an address phase and a data phase.
1052 *
1053 * The mmio interface is based on 16-bit offsets and values. All
1054 * register offsets must therefore be adjusted by left shifting the
1055 * offset 1 bit and reading 16 bits of data.
1056 */
1057 mmd_address <<= 1;
1058 index = mmd_address & ~pdata->xpcs_window_mask;
1059 offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask);
1060
1061 spin_lock_irqsave(&pdata->xpcs_lock, flags);
1062 XPCS32_IOWRITE(pdata, PCS_V2_WINDOW_SELECT, index);
1063 mmd_data = XPCS16_IOREAD(pdata, offset);
1064 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
1065
1066 return mmd_data;
1067}
1068
1069static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,
1070 int mmd_reg, int mmd_data)
1071{
1072 unsigned long flags;
1073 unsigned int mmd_address, index, offset;
1074
1075 if (mmd_reg & MII_ADDR_C45)
1076 mmd_address = mmd_reg & ~MII_ADDR_C45;
1077 else
1078 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1079
1080 /* The PCS registers are accessed using mmio. The underlying
1081 * management interface uses indirect addressing to access the MMD
1082 * register sets. This requires accessing of the PCS register in two
1083 * phases, an address phase and a data phase.
1084 *
1085 * The mmio interface is based on 16-bit offsets and values. All
1086 * register offsets must therefore be adjusted by left shifting the
1087 * offset 1 bit and writing 16 bits of data.
1088 */
1089 mmd_address <<= 1;
1090 index = mmd_address & ~pdata->xpcs_window_mask;
1091 offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask);
1092
1093 spin_lock_irqsave(&pdata->xpcs_lock, flags);
1094 XPCS32_IOWRITE(pdata, PCS_V2_WINDOW_SELECT, index);
1095 XPCS16_IOWRITE(pdata, offset, mmd_data);
1096 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
1097}
1098
1099static int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,
1100 int mmd_reg)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001101{
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001102 unsigned long flags;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001103 unsigned int mmd_address;
1104 int mmd_data;
1105
1106 if (mmd_reg & MII_ADDR_C45)
1107 mmd_address = mmd_reg & ~MII_ADDR_C45;
1108 else
1109 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
1110
1111 /* The PCS registers are accessed using mmio. The underlying APB3
1112 * management interface uses indirect addressing to access the MMD
1113 * register sets. This requires accessing of the PCS register in two
1114 * phases, an address phase and a data phase.
1115 *
1116 * The mmio interface is based on 32-bit offsets and values. All
1117 * register offsets must therefore be adjusted by left shifting the
1118 * offset 2 bits and reading 32 bits of data.
1119 */
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001120 spin_lock_irqsave(&pdata->xpcs_lock, flags);
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001121 XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8);
1122 mmd_data = XPCS32_IOREAD(pdata, (mmd_address & 0xff) << 2);
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001123 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001124
1125 return mmd_data;
1126}
1127
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001128static void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,
1129 int mmd_reg, int mmd_data)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001130{
1131 unsigned int mmd_address;
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001132 unsigned long flags;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001133
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 APB3
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 32-bit offsets and values. All
1145 * register offsets must therefore be adjusted by left shifting the
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001146 * offset 2 bits and writing 32 bits of data.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001147 */
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001148 spin_lock_irqsave(&pdata->xpcs_lock, flags);
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001149 XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8);
1150 XPCS32_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001151 spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001152}
1153
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -05001154static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
1155 int mmd_reg)
1156{
1157 switch (pdata->vdata->xpcs_access) {
1158 case XGBE_XPCS_ACCESS_V1:
1159 return xgbe_read_mmd_regs_v1(pdata, prtad, mmd_reg);
1160
1161 case XGBE_XPCS_ACCESS_V2:
1162 default:
1163 return xgbe_read_mmd_regs_v2(pdata, prtad, mmd_reg);
1164 }
1165}
1166
1167static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
1168 int mmd_reg, int mmd_data)
1169{
1170 switch (pdata->vdata->xpcs_access) {
1171 case XGBE_XPCS_ACCESS_V1:
1172 return xgbe_write_mmd_regs_v1(pdata, prtad, mmd_reg, mmd_data);
1173
1174 case XGBE_XPCS_ACCESS_V2:
1175 default:
1176 return xgbe_write_mmd_regs_v2(pdata, prtad, mmd_reg, mmd_data);
1177 }
1178}
1179
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001180static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
1181{
1182 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
1183}
1184
1185static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
1186{
1187 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
1188
1189 return 0;
1190}
1191
1192static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
1193{
1194 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
1195
1196 return 0;
1197}
1198
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001199static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
1200{
1201 struct xgbe_ring_desc *rdesc = rdata->rdesc;
1202
1203 /* Reset the Tx descriptor
1204 * Set buffer 1 (lo) address to zero
1205 * Set buffer 1 (hi) address to zero
1206 * Reset all other control bits (IC, TTSE, B2L & B1L)
1207 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
1208 */
1209 rdesc->desc0 = 0;
1210 rdesc->desc1 = 0;
1211 rdesc->desc2 = 0;
1212 rdesc->desc3 = 0;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001213
1214 /* Make sure ownership is written to the descriptor */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001215 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001216}
1217
1218static void xgbe_tx_desc_init(struct xgbe_channel *channel)
1219{
1220 struct xgbe_ring *ring = channel->tx_ring;
1221 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001222 int i;
1223 int start_index = ring->cur;
1224
1225 DBGPR("-->tx_desc_init\n");
1226
1227 /* Initialze all descriptors */
1228 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001229 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001230
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001231 /* Initialize Tx descriptor */
1232 xgbe_tx_desc_reset(rdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001233 }
1234
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001235 /* Update the total number of Tx descriptors */
1236 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
1237
1238 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001239 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001240 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
1241 upper_32_bits(rdata->rdesc_dma));
1242 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
1243 lower_32_bits(rdata->rdesc_dma));
1244
1245 DBGPR("<--tx_desc_init\n");
1246}
1247
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001248static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata,
1249 struct xgbe_ring_data *rdata, unsigned int index)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001250{
1251 struct xgbe_ring_desc *rdesc = rdata->rdesc;
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001252 unsigned int rx_usecs = pdata->rx_usecs;
1253 unsigned int rx_frames = pdata->rx_frames;
1254 unsigned int inte;
Lendacky, Thomascfbfd862015-07-06 11:57:37 -05001255 dma_addr_t hdr_dma, buf_dma;
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001256
1257 if (!rx_usecs && !rx_frames) {
1258 /* No coalescing, interrupt for every descriptor */
1259 inte = 1;
1260 } else {
1261 /* Set interrupt based on Rx frame coalescing setting */
1262 if (rx_frames && !((index + 1) % rx_frames))
1263 inte = 1;
1264 else
1265 inte = 0;
1266 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001267
1268 /* Reset the Rx descriptor
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001269 * Set buffer 1 (lo) address to header dma address (lo)
1270 * Set buffer 1 (hi) address to header dma address (hi)
1271 * Set buffer 2 (lo) address to buffer dma address (lo)
1272 * Set buffer 2 (hi) address to buffer dma address (hi) and
1273 * set control bits OWN and INTE
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001274 */
Lendacky, Thomascfbfd862015-07-06 11:57:37 -05001275 hdr_dma = rdata->rx.hdr.dma_base + rdata->rx.hdr.dma_off;
1276 buf_dma = rdata->rx.buf.dma_base + rdata->rx.buf.dma_off;
1277 rdesc->desc0 = cpu_to_le32(lower_32_bits(hdr_dma));
1278 rdesc->desc1 = cpu_to_le32(upper_32_bits(hdr_dma));
1279 rdesc->desc2 = cpu_to_le32(lower_32_bits(buf_dma));
1280 rdesc->desc3 = cpu_to_le32(upper_32_bits(buf_dma));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001281
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001282 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001283
1284 /* Since the Rx DMA engine is likely running, make sure everything
1285 * is written to the descriptor(s) before setting the OWN bit
1286 * for the descriptor
1287 */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001288 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001289
1290 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
1291
1292 /* Make sure ownership is written to the descriptor */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001293 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001294}
1295
1296static void xgbe_rx_desc_init(struct xgbe_channel *channel)
1297{
1298 struct xgbe_prv_data *pdata = channel->pdata;
1299 struct xgbe_ring *ring = channel->rx_ring;
1300 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001301 unsigned int start_index = ring->cur;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001302 unsigned int i;
1303
1304 DBGPR("-->rx_desc_init\n");
1305
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001306 /* Initialize all descriptors */
1307 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001308 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001309
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001310 /* Initialize Rx descriptor */
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -05001311 xgbe_rx_desc_reset(pdata, rdata, i);
Lendacky, Thomas08dcc472014-11-04 16:06:44 -06001312 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001313
1314 /* Update the total number of Rx descriptors */
1315 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
1316
1317 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001318 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001319 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
1320 upper_32_bits(rdata->rdesc_dma));
1321 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
1322 lower_32_bits(rdata->rdesc_dma));
1323
1324 /* Update the Rx Descriptor Tail Pointer */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001325 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001326 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
1327 lower_32_bits(rdata->rdesc_dma));
1328
1329 DBGPR("<--rx_desc_init\n");
1330}
1331
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001332static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
1333 unsigned int addend)
1334{
1335 /* Set the addend register value and tell the device */
1336 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1337 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1338
1339 /* Wait for addend update to complete */
1340 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1341 udelay(5);
1342}
1343
1344static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1345 unsigned int nsec)
1346{
1347 /* Set the time values and tell the device */
1348 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1349 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1350 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1351
1352 /* Wait for time update to complete */
1353 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1354 udelay(5);
1355}
1356
1357static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1358{
1359 u64 nsec;
1360
1361 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1362 nsec *= NSEC_PER_SEC;
1363 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1364
1365 return nsec;
1366}
1367
1368static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1369{
Lendacky, Thomasaba97772016-11-10 17:09:45 -06001370 unsigned int tx_snr, tx_ssr;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001371 u64 nsec;
1372
Lendacky, Thomasaba97772016-11-10 17:09:45 -06001373 if (pdata->vdata->tx_tstamp_workaround) {
1374 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1375 tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR);
1376 } else {
1377 tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR);
1378 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1379 }
1380
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001381 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1382 return 0;
1383
Lendacky, Thomasaba97772016-11-10 17:09:45 -06001384 nsec = tx_ssr;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001385 nsec *= NSEC_PER_SEC;
1386 nsec += tx_snr;
1387
1388 return nsec;
1389}
1390
1391static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1392 struct xgbe_ring_desc *rdesc)
1393{
1394 u64 nsec;
1395
1396 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1397 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1398 nsec = le32_to_cpu(rdesc->desc1);
1399 nsec <<= 32;
1400 nsec |= le32_to_cpu(rdesc->desc0);
1401 if (nsec != 0xffffffffffffffffULL) {
1402 packet->rx_tstamp = nsec;
1403 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1404 RX_TSTAMP, 1);
1405 }
1406 }
1407}
1408
1409static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1410 unsigned int mac_tscr)
1411{
1412 /* Set one nano-second accuracy */
1413 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1414
1415 /* Set fine timestamp update */
1416 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1417
1418 /* Overwrite earlier timestamps */
1419 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1420
1421 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1422
1423 /* Exit if timestamping is not enabled */
1424 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1425 return 0;
1426
1427 /* Initialize time registers */
1428 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1429 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1430 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1431 xgbe_set_tstamp_time(pdata, 0, 0);
1432
1433 /* Initialize the timecounter */
1434 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1435 ktime_to_ns(ktime_get_real()));
1436
1437 return 0;
1438}
1439
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001440static void xgbe_tx_start_xmit(struct xgbe_channel *channel,
1441 struct xgbe_ring *ring)
1442{
1443 struct xgbe_prv_data *pdata = channel->pdata;
1444 struct xgbe_ring_data *rdata;
1445
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001446 /* Make sure everything is written before the register write */
1447 wmb();
1448
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001449 /* Issue a poll command to Tx DMA by writing address
1450 * of next immediate free descriptor */
1451 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
1452 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1453 lower_32_bits(rdata->rdesc_dma));
1454
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -05001455 /* Start the Tx timer */
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001456 if (pdata->tx_usecs && !channel->tx_timer_active) {
1457 channel->tx_timer_active = 1;
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -05001458 mod_timer(&channel->tx_timer,
1459 jiffies + usecs_to_jiffies(pdata->tx_usecs));
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001460 }
1461
1462 ring->tx.xmit_more = 0;
1463}
1464
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001465static void xgbe_dev_xmit(struct xgbe_channel *channel)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001466{
1467 struct xgbe_prv_data *pdata = channel->pdata;
1468 struct xgbe_ring *ring = channel->tx_ring;
1469 struct xgbe_ring_data *rdata;
1470 struct xgbe_ring_desc *rdesc;
1471 struct xgbe_packet_data *packet = &ring->packet_data;
1472 unsigned int csum, tso, vlan;
1473 unsigned int tso_context, vlan_context;
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001474 unsigned int tx_set_ic;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001475 int start_index = ring->cur;
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001476 int cur_index = ring->cur;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001477 int i;
1478
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001479 DBGPR("-->xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001480
1481 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1482 CSUM_ENABLE);
1483 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1484 TSO_ENABLE);
1485 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1486 VLAN_CTAG);
1487
1488 if (tso && (packet->mss != ring->tx.cur_mss))
1489 tso_context = 1;
1490 else
1491 tso_context = 0;
1492
1493 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1494 vlan_context = 1;
1495 else
1496 vlan_context = 0;
1497
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001498 /* Determine if an interrupt should be generated for this Tx:
1499 * Interrupt:
1500 * - Tx frame count exceeds the frame count setting
1501 * - Addition of Tx frame count to the frame count since the
1502 * last interrupt was set exceeds the frame count setting
1503 * No interrupt:
1504 * - No frame count setting specified (ethtool -C ethX tx-frames 0)
1505 * - Addition of Tx frame count to the frame count since the
1506 * last interrupt was set does not exceed the frame count setting
1507 */
1508 ring->coalesce_count += packet->tx_packets;
1509 if (!pdata->tx_frames)
1510 tx_set_ic = 0;
1511 else if (packet->tx_packets > pdata->tx_frames)
1512 tx_set_ic = 1;
1513 else if ((ring->coalesce_count % pdata->tx_frames) <
1514 packet->tx_packets)
1515 tx_set_ic = 1;
1516 else
1517 tx_set_ic = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001518
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001519 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001520 rdesc = rdata->rdesc;
1521
1522 /* Create a context descriptor if this is a TSO packet */
1523 if (tso_context || vlan_context) {
1524 if (tso_context) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001525 netif_dbg(pdata, tx_queued, pdata->netdev,
1526 "TSO context descriptor, mss=%u\n",
1527 packet->mss);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001528
1529 /* Set the MSS size */
1530 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1531 MSS, packet->mss);
1532
1533 /* Mark it as a CONTEXT descriptor */
1534 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1535 CTXT, 1);
1536
1537 /* Indicate this descriptor contains the MSS */
1538 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1539 TCMSSV, 1);
1540
1541 ring->tx.cur_mss = packet->mss;
1542 }
1543
1544 if (vlan_context) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001545 netif_dbg(pdata, tx_queued, pdata->netdev,
1546 "VLAN context descriptor, ctag=%u\n",
1547 packet->vlan_ctag);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001548
1549 /* Mark it as a CONTEXT descriptor */
1550 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1551 CTXT, 1);
1552
1553 /* Set the VLAN tag */
1554 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1555 VT, packet->vlan_ctag);
1556
1557 /* Indicate this descriptor contains the VLAN tag */
1558 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1559 VLTV, 1);
1560
1561 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1562 }
1563
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001564 cur_index++;
1565 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001566 rdesc = rdata->rdesc;
1567 }
1568
1569 /* Update buffer address (for TSO this is the header) */
1570 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1571 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1572
1573 /* Update the buffer length */
1574 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1575 rdata->skb_dma_len);
1576
1577 /* VLAN tag insertion check */
1578 if (vlan)
1579 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1580 TX_NORMAL_DESC2_VLAN_INSERT);
1581
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001582 /* Timestamp enablement check */
1583 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1584 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1585
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001586 /* Mark it as First Descriptor */
1587 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1588
1589 /* Mark it as a NORMAL descriptor */
1590 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1591
1592 /* Set OWN bit if not the first descriptor */
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001593 if (cur_index != start_index)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001594 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1595
1596 if (tso) {
1597 /* Enable TSO */
1598 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1599 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1600 packet->tcp_payload_len);
1601 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1602 packet->tcp_header_len / 4);
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001603
1604 pdata->ext_stats.tx_tso_packets++;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001605 } else {
1606 /* Enable CRC and Pad Insertion */
1607 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1608
1609 /* Enable HW CSUM */
1610 if (csum)
1611 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1612 CIC, 0x3);
1613
1614 /* Set the total length to be transmitted */
1615 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1616 packet->length);
1617 }
1618
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001619 for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) {
1620 cur_index++;
1621 rdata = XGBE_GET_DESC_DATA(ring, cur_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001622 rdesc = rdata->rdesc;
1623
1624 /* Update buffer address */
1625 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1626 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1627
1628 /* Update the buffer length */
1629 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1630 rdata->skb_dma_len);
1631
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001632 /* Set OWN bit */
1633 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1634
1635 /* Mark it as NORMAL descriptor */
1636 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1637
1638 /* Enable HW CSUM */
1639 if (csum)
1640 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1641 CIC, 0x3);
1642 }
1643
1644 /* Set LAST bit for the last descriptor */
1645 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1646
Lendacky, Thomaseb79e642014-11-20 11:04:02 -06001647 /* Set IC bit based on Tx coalescing settings */
1648 if (tx_set_ic)
1649 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1650
Lendacky, Thomas5fb4b862014-11-20 11:03:50 -06001651 /* Save the Tx info to report back during cleanup */
1652 rdata->tx.packets = packet->tx_packets;
1653 rdata->tx.bytes = packet->tx_bytes;
1654
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001655 /* In case the Tx DMA engine is running, make sure everything
1656 * is written to the descriptor(s) before setting the OWN bit
1657 * for the first descriptor
1658 */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001659 dma_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001660
1661 /* Set OWN bit for the first descriptor */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001662 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001663 rdesc = rdata->rdesc;
1664 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1665
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001666 if (netif_msg_tx_queued(pdata))
1667 xgbe_dump_tx_desc(pdata, ring, start_index,
1668 packet->rdesc_count, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001669
1670 /* Make sure ownership is written to the descriptor */
Lendacky, Thomas20986ed2015-10-26 17:13:54 -05001671 smp_wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001672
Lendacky, Thomasa83ef422015-01-16 12:46:55 -06001673 ring->cur = cur_index + 1;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06001674 if (!packet->skb->xmit_more ||
1675 netif_xmit_stopped(netdev_get_tx_queue(pdata->netdev,
1676 channel->queue_index)))
1677 xgbe_tx_start_xmit(channel, ring);
1678 else
1679 ring->tx.xmit_more = 1;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001680
1681 DBGPR(" %s: descriptors %u to %u written\n",
1682 channel->name, start_index & (ring->rdesc_count - 1),
1683 (ring->cur - 1) & (ring->rdesc_count - 1));
1684
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001685 DBGPR("<--xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001686}
1687
1688static int xgbe_dev_read(struct xgbe_channel *channel)
1689{
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001690 struct xgbe_prv_data *pdata = channel->pdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001691 struct xgbe_ring *ring = channel->rx_ring;
1692 struct xgbe_ring_data *rdata;
1693 struct xgbe_ring_desc *rdesc;
1694 struct xgbe_packet_data *packet = &ring->packet_data;
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001695 struct net_device *netdev = pdata->netdev;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001696 unsigned int err, etlt, l34t;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001697
1698 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1699
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001700 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001701 rdesc = rdata->rdesc;
1702
1703 /* Check for data availability */
1704 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1705 return 1;
1706
Lendacky, Thomas5449e272014-11-20 11:03:26 -06001707 /* Make sure descriptor fields are read after reading the OWN bit */
Lendacky, Thomasceb8f6b2015-03-20 11:50:16 -05001708 dma_rmb();
Lendacky, Thomas5449e272014-11-20 11:03:26 -06001709
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001710 if (netif_msg_rx_status(pdata))
1711 xgbe_dump_rx_desc(pdata, ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001712
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001713 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1714 /* Timestamp Context Descriptor */
1715 xgbe_get_rx_tstamp(packet, rdesc);
1716
1717 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1718 CONTEXT, 1);
1719 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1720 CONTEXT_NEXT, 0);
1721 return 0;
1722 }
1723
1724 /* Normal Descriptor, be sure Context Descriptor bit is off */
1725 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1726
1727 /* Indicate if a Context Descriptor is next */
1728 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1729 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1730 CONTEXT_NEXT, 1);
1731
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001732 /* Get the header length */
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001733 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD)) {
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001734 rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2,
1735 RX_NORMAL_DESC2, HL);
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001736 if (rdata->rx.hdr_len)
1737 pdata->ext_stats.rx_split_header_packets++;
1738 }
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001739
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001740 /* Get the RSS hash */
1741 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, RSV)) {
1742 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1743 RSS_HASH, 1);
1744
1745 packet->rss_hash = le32_to_cpu(rdesc->desc1);
1746
1747 l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T);
1748 switch (l34t) {
1749 case RX_DESC3_L34T_IPV4_TCP:
1750 case RX_DESC3_L34T_IPV4_UDP:
1751 case RX_DESC3_L34T_IPV6_TCP:
1752 case RX_DESC3_L34T_IPV6_UDP:
1753 packet->rss_hash_type = PKT_HASH_TYPE_L4;
Dan Carpenterb6267d32014-11-13 09:19:06 +03001754 break;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06001755 default:
1756 packet->rss_hash_type = PKT_HASH_TYPE_L3;
1757 }
1758 }
1759
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001760 /* Get the packet length */
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -06001761 rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001762
1763 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1764 /* Not all the data has been transferred for this packet */
1765 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1766 INCOMPLETE, 1);
1767 return 0;
1768 }
1769
1770 /* This is the last of the data for this packet */
1771 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1772 INCOMPLETE, 0);
1773
1774 /* Set checksum done indicator as appropriate */
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -05001775 if (netdev->features & NETIF_F_RXCSUM)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001776 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1777 CSUM_DONE, 1);
1778
1779 /* Check for errors (only valid in last descriptor) */
1780 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1781 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001782 netif_dbg(pdata, rx_status, netdev, "err=%u, etlt=%#x\n", err, etlt);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001783
Lendacky, Thomas7bba35b2014-11-20 11:03:38 -06001784 if (!err || !etlt) {
1785 /* No error if err is 0 or etlt is 0 */
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001786 if ((etlt == 0x09) &&
1787 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001788 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1789 VLAN_CTAG, 1);
1790 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1791 RX_NORMAL_DESC0,
1792 OVT);
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001793 netif_dbg(pdata, rx_status, netdev, "vlan-ctag=%#06x\n",
1794 packet->vlan_ctag);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001795 }
1796 } else {
1797 if ((etlt == 0x05) || (etlt == 0x06))
1798 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1799 CSUM_DONE, 0);
1800 else
1801 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1802 FRAME, 1);
1803 }
1804
1805 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1806 ring->cur & (ring->rdesc_count - 1), ring->cur);
1807
1808 return 0;
1809}
1810
1811static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1812{
1813 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1814 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1815}
1816
1817static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1818{
1819 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1820 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1821}
1822
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001823static int xgbe_enable_int(struct xgbe_channel *channel,
1824 enum xgbe_int int_id)
1825{
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001826 unsigned int dma_ch_ier;
1827
1828 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1829
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001830 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001831 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001832 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001833 break;
1834 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001835 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001836 break;
1837 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001838 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001839 break;
1840 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001841 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001842 break;
1843 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001844 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001845 break;
1846 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001847 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1848 break;
1849 case XGMAC_INT_DMA_CH_SR_TI_RI:
1850 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1851 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001852 break;
1853 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001854 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001855 break;
1856 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001857 dma_ch_ier |= channel->saved_ier;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001858 break;
1859 default:
1860 return -1;
1861 }
1862
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001863 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1864
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001865 return 0;
1866}
1867
1868static int xgbe_disable_int(struct xgbe_channel *channel,
1869 enum xgbe_int int_id)
1870{
1871 unsigned int dma_ch_ier;
1872
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001873 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1874
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001875 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001876 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001877 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001878 break;
1879 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001880 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001881 break;
1882 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001883 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001884 break;
1885 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001886 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001887 break;
1888 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001889 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001890 break;
1891 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001892 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1893 break;
1894 case XGMAC_INT_DMA_CH_SR_TI_RI:
1895 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1896 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001897 break;
1898 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001899 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001900 break;
1901 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001902 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001903 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001904 break;
1905 default:
1906 return -1;
1907 }
1908
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001909 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1910
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001911 return 0;
1912}
1913
Lendacky, Thomas5ffc0332016-11-10 17:09:29 -06001914static int __xgbe_exit(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001915{
1916 unsigned int count = 2000;
1917
1918 DBGPR("-->xgbe_exit\n");
1919
1920 /* Issue a software reset */
1921 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1922 usleep_range(10, 15);
1923
1924 /* Poll Until Poll Condition */
Dan Carpenterc7557e62015-12-15 13:12:29 +03001925 while (--count && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001926 usleep_range(500, 600);
1927
1928 if (!count)
1929 return -EBUSY;
1930
1931 DBGPR("<--xgbe_exit\n");
1932
1933 return 0;
1934}
1935
Lendacky, Thomas5ffc0332016-11-10 17:09:29 -06001936static int xgbe_exit(struct xgbe_prv_data *pdata)
1937{
1938 int ret;
1939
1940 /* To guard against possible incorrectly generated interrupts,
1941 * issue the software reset twice.
1942 */
1943 ret = __xgbe_exit(pdata);
1944 if (ret)
1945 return ret;
1946
1947 return __xgbe_exit(pdata);
1948}
1949
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001950static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1951{
1952 unsigned int i, count;
1953
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -05001954 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
1955 return 0;
1956
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001957 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001958 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1959
1960 /* Poll Until Poll Condition */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001961 for (i = 0; i < pdata->tx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001962 count = 2000;
Dan Carpenterc7557e62015-12-15 13:12:29 +03001963 while (--count && XGMAC_MTL_IOREAD_BITS(pdata, i,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001964 MTL_Q_TQOMR, FTQ))
1965 usleep_range(500, 600);
1966
1967 if (!count)
1968 return -EBUSY;
1969 }
1970
1971 return 0;
1972}
1973
1974static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1975{
1976 /* Set enhanced addressing mode */
1977 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1978
1979 /* Set the System Bus mode */
1980 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001981 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001982}
1983
1984static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1985{
1986 unsigned int arcache, awcache;
1987
1988 arcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001989 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
1990 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
1991 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
1992 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
1993 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
1994 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001995 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1996
1997 awcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001998 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
1999 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
2000 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
2001 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
2002 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
2003 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
2004 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
2005 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002006 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
2007}
2008
2009static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
2010{
2011 unsigned int i;
2012
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002013 /* Set Tx to weighted round robin scheduling algorithm */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002014 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
2015
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002016 /* Set Tx traffic classes to use WRR algorithm with equal weights */
2017 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
2018 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
2019 MTL_TSA_ETS);
2020 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
2021 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002022
2023 /* Set Rx to strict priority algorithm */
2024 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
2025}
2026
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002027static void xgbe_queue_flow_control_threshold(struct xgbe_prv_data *pdata,
2028 unsigned int queue,
2029 unsigned int q_fifo_size)
2030{
2031 unsigned int frame_fifo_size;
2032 unsigned int rfa, rfd;
2033
2034 frame_fifo_size = XGMAC_FLOW_CONTROL_ALIGN(xgbe_get_max_frame(pdata));
2035
2036 if (pdata->pfcq[queue] && (q_fifo_size > pdata->pfc_rfa)) {
2037 /* PFC is active for this queue */
2038 rfa = pdata->pfc_rfa;
2039 rfd = rfa + frame_fifo_size;
2040 if (rfd > XGMAC_FLOW_CONTROL_MAX)
2041 rfd = XGMAC_FLOW_CONTROL_MAX;
2042 if (rfa >= XGMAC_FLOW_CONTROL_MAX)
2043 rfa = XGMAC_FLOW_CONTROL_MAX - XGMAC_FLOW_CONTROL_UNIT;
2044 } else {
2045 /* This path deals with just maximum frame sizes which are
2046 * limited to a jumbo frame of 9,000 (plus headers, etc.)
2047 * so we can never exceed the maximum allowable RFA/RFD
2048 * values.
2049 */
2050 if (q_fifo_size <= 2048) {
2051 /* rx_rfd to zero to signal no flow control */
2052 pdata->rx_rfa[queue] = 0;
2053 pdata->rx_rfd[queue] = 0;
2054 return;
2055 }
2056
2057 if (q_fifo_size <= 4096) {
2058 /* Between 2048 and 4096 */
2059 pdata->rx_rfa[queue] = 0; /* Full - 1024 bytes */
2060 pdata->rx_rfd[queue] = 1; /* Full - 1536 bytes */
2061 return;
2062 }
2063
2064 if (q_fifo_size <= frame_fifo_size) {
2065 /* Between 4096 and max-frame */
2066 pdata->rx_rfa[queue] = 2; /* Full - 2048 bytes */
2067 pdata->rx_rfd[queue] = 5; /* Full - 3584 bytes */
2068 return;
2069 }
2070
2071 if (q_fifo_size <= (frame_fifo_size * 3)) {
2072 /* Between max-frame and 3 max-frames,
2073 * trigger if we get just over a frame of data and
2074 * resume when we have just under half a frame left.
2075 */
2076 rfa = q_fifo_size - frame_fifo_size;
2077 rfd = rfa + (frame_fifo_size / 2);
2078 } else {
2079 /* Above 3 max-frames - trigger when just over
2080 * 2 frames of space available
2081 */
2082 rfa = frame_fifo_size * 2;
2083 rfa += XGMAC_FLOW_CONTROL_UNIT;
2084 rfd = rfa + frame_fifo_size;
2085 }
2086 }
2087
2088 pdata->rx_rfa[queue] = XGMAC_FLOW_CONTROL_VALUE(rfa);
2089 pdata->rx_rfd[queue] = XGMAC_FLOW_CONTROL_VALUE(rfd);
2090}
2091
2092static void xgbe_calculate_flow_control_threshold(struct xgbe_prv_data *pdata,
2093 unsigned int *fifo)
2094{
2095 unsigned int q_fifo_size;
2096 unsigned int i;
2097
2098 for (i = 0; i < pdata->rx_q_count; i++) {
2099 q_fifo_size = (fifo[i] + 1) * XGMAC_FIFO_UNIT;
2100
2101 xgbe_queue_flow_control_threshold(pdata, i, q_fifo_size);
2102 }
2103}
2104
2105static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
2106{
2107 unsigned int i;
2108
2109 for (i = 0; i < pdata->rx_q_count; i++) {
2110 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFA,
2111 pdata->rx_rfa[i]);
2112 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFD,
2113 pdata->rx_rfd[i]);
2114 }
2115}
2116
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002117static unsigned int xgbe_get_tx_fifo_size(struct xgbe_prv_data *pdata)
2118{
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002119 /* The configured value may not be the actual amount of fifo RAM */
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -05002120 return min_t(unsigned int, pdata->tx_max_fifo_size,
2121 pdata->hw_feat.tx_fifo_size);
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002122}
2123
2124static unsigned int xgbe_get_rx_fifo_size(struct xgbe_prv_data *pdata)
2125{
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002126 /* The configured value may not be the actual amount of fifo RAM */
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -05002127 return min_t(unsigned int, pdata->rx_max_fifo_size,
2128 pdata->hw_feat.rx_fifo_size);
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002129}
2130
2131static void xgbe_calculate_equal_fifo(unsigned int fifo_size,
2132 unsigned int queue_count,
2133 unsigned int *fifo)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002134{
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002135 unsigned int q_fifo_size;
2136 unsigned int p_fifo;
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002137 unsigned int i;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002138
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002139 q_fifo_size = fifo_size / queue_count;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002140
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002141 /* Calculate the fifo setting by dividing the queue's fifo size
2142 * by the fifo allocation increment (with 0 representing the
2143 * base allocation increment so decrement the result by 1).
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002144 */
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002145 p_fifo = q_fifo_size / XGMAC_FIFO_UNIT;
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002146 if (p_fifo)
2147 p_fifo--;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002148
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002149 /* Distribute the fifo equally amongst the queues */
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002150 for (i = 0; i < queue_count; i++)
2151 fifo[i] = p_fifo;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002152}
2153
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002154static unsigned int xgbe_set_nonprio_fifos(unsigned int fifo_size,
2155 unsigned int queue_count,
2156 unsigned int *fifo)
2157{
2158 unsigned int i;
2159
2160 BUILD_BUG_ON_NOT_POWER_OF_2(XGMAC_FIFO_MIN_ALLOC);
2161
2162 if (queue_count <= IEEE_8021QAZ_MAX_TCS)
2163 return fifo_size;
2164
2165 /* Rx queues 9 and up are for specialized packets,
2166 * such as PTP or DCB control packets, etc. and
2167 * don't require a large fifo
2168 */
2169 for (i = IEEE_8021QAZ_MAX_TCS; i < queue_count; i++) {
2170 fifo[i] = (XGMAC_FIFO_MIN_ALLOC / XGMAC_FIFO_UNIT) - 1;
2171 fifo_size -= XGMAC_FIFO_MIN_ALLOC;
2172 }
2173
2174 return fifo_size;
2175}
2176
2177static unsigned int xgbe_get_pfc_delay(struct xgbe_prv_data *pdata)
2178{
2179 unsigned int delay;
2180
2181 /* If a delay has been provided, use that */
2182 if (pdata->pfc->delay)
2183 return pdata->pfc->delay / 8;
2184
2185 /* Allow for two maximum size frames */
2186 delay = xgbe_get_max_frame(pdata);
2187 delay += XGMAC_ETH_PREAMBLE;
2188 delay *= 2;
2189
2190 /* Allow for PFC frame */
2191 delay += XGMAC_PFC_DATA_LEN;
2192 delay += ETH_HLEN + ETH_FCS_LEN;
2193 delay += XGMAC_ETH_PREAMBLE;
2194
2195 /* Allow for miscellaneous delays (LPI exit, cable, etc.) */
2196 delay += XGMAC_PFC_DELAYS;
2197
2198 return delay;
2199}
2200
2201static unsigned int xgbe_get_pfc_queues(struct xgbe_prv_data *pdata)
2202{
2203 unsigned int count, prio_queues;
2204 unsigned int i;
2205
2206 if (!pdata->pfc->pfc_en)
2207 return 0;
2208
2209 count = 0;
2210 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2211 for (i = 0; i < prio_queues; i++) {
2212 if (!xgbe_is_pfc_queue(pdata, i))
2213 continue;
2214
2215 pdata->pfcq[i] = 1;
2216 count++;
2217 }
2218
2219 return count;
2220}
2221
2222static void xgbe_calculate_dcb_fifo(struct xgbe_prv_data *pdata,
2223 unsigned int fifo_size,
2224 unsigned int *fifo)
2225{
2226 unsigned int q_fifo_size, rem_fifo, addn_fifo;
2227 unsigned int prio_queues;
2228 unsigned int pfc_count;
2229 unsigned int i;
2230
2231 q_fifo_size = XGMAC_FIFO_ALIGN(xgbe_get_max_frame(pdata));
2232 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2233 pfc_count = xgbe_get_pfc_queues(pdata);
2234
2235 if (!pfc_count || ((q_fifo_size * prio_queues) > fifo_size)) {
2236 /* No traffic classes with PFC enabled or can't do lossless */
2237 xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo);
2238 return;
2239 }
2240
2241 /* Calculate how much fifo we have to play with */
2242 rem_fifo = fifo_size - (q_fifo_size * prio_queues);
2243
2244 /* Calculate how much more than base fifo PFC needs, which also
2245 * becomes the threshold activation point (RFA)
2246 */
2247 pdata->pfc_rfa = xgbe_get_pfc_delay(pdata);
2248 pdata->pfc_rfa = XGMAC_FLOW_CONTROL_ALIGN(pdata->pfc_rfa);
2249
2250 if (pdata->pfc_rfa > q_fifo_size) {
2251 addn_fifo = pdata->pfc_rfa - q_fifo_size;
2252 addn_fifo = XGMAC_FIFO_ALIGN(addn_fifo);
2253 } else {
2254 addn_fifo = 0;
2255 }
2256
2257 /* Calculate DCB fifo settings:
2258 * - distribute remaining fifo between the VLAN priority
2259 * queues based on traffic class PFC enablement and overall
2260 * priority (0 is lowest priority, so start at highest)
2261 */
2262 i = prio_queues;
2263 while (i > 0) {
2264 i--;
2265
2266 fifo[i] = (q_fifo_size / XGMAC_FIFO_UNIT) - 1;
2267
2268 if (!pdata->pfcq[i] || !addn_fifo)
2269 continue;
2270
2271 if (addn_fifo > rem_fifo) {
2272 netdev_warn(pdata->netdev,
2273 "RXq%u cannot set needed fifo size\n", i);
2274 if (!rem_fifo)
2275 continue;
2276
2277 addn_fifo = rem_fifo;
2278 }
2279
2280 fifo[i] += (addn_fifo / XGMAC_FIFO_UNIT);
2281 rem_fifo -= addn_fifo;
2282 }
2283
2284 if (rem_fifo) {
2285 unsigned int inc_fifo = rem_fifo / prio_queues;
2286
2287 /* Distribute remaining fifo across queues */
2288 for (i = 0; i < prio_queues; i++)
2289 fifo[i] += (inc_fifo / XGMAC_FIFO_UNIT);
2290 }
2291}
2292
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002293static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
2294{
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002295 unsigned int fifo_size;
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002296 unsigned int fifo[XGBE_MAX_QUEUES];
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002297 unsigned int i;
2298
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002299 fifo_size = xgbe_get_tx_fifo_size(pdata);
2300
2301 xgbe_calculate_equal_fifo(fifo_size, pdata->tx_q_count, fifo);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002302
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002303 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002304 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo[i]);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002305
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002306 netif_info(pdata, drv, pdata->netdev,
2307 "%d Tx hardware queues, %d byte fifo per queue\n",
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002308 pdata->tx_q_count, ((fifo[0] + 1) * XGMAC_FIFO_UNIT));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002309}
2310
2311static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
2312{
Lendacky, Thomas9c439e42015-09-30 08:53:03 -05002313 unsigned int fifo_size;
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002314 unsigned int fifo[XGBE_MAX_QUEUES];
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002315 unsigned int prio_queues;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002316 unsigned int i;
2317
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002318 /* Clear any DCB related fifo/queue information */
2319 memset(pdata->pfcq, 0, sizeof(pdata->pfcq));
2320 pdata->pfc_rfa = 0;
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002321
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002322 fifo_size = xgbe_get_rx_fifo_size(pdata);
2323 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
2324
2325 /* Assign a minimum fifo to the non-VLAN priority queues */
2326 fifo_size = xgbe_set_nonprio_fifos(fifo_size, pdata->rx_q_count, fifo);
2327
2328 if (pdata->pfc && pdata->ets)
2329 xgbe_calculate_dcb_fifo(pdata, fifo_size, fifo);
2330 else
2331 xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002332
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002333 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomas586e3cfb2016-11-03 13:17:48 -05002334 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo[i]);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002335
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002336 xgbe_calculate_flow_control_threshold(pdata, fifo);
2337 xgbe_config_flow_control_threshold(pdata);
2338
2339 if (pdata->pfc && pdata->ets && pdata->pfc->pfc_en) {
2340 netif_info(pdata, drv, pdata->netdev,
2341 "%u Rx hardware queues\n", pdata->rx_q_count);
2342 for (i = 0; i < pdata->rx_q_count; i++)
2343 netif_info(pdata, drv, pdata->netdev,
2344 "RxQ%u, %u byte fifo queue\n", i,
2345 ((fifo[i] + 1) * XGMAC_FIFO_UNIT));
2346 } else {
2347 netif_info(pdata, drv, pdata->netdev,
2348 "%u Rx hardware queues, %u byte fifo per queue\n",
2349 pdata->rx_q_count,
2350 ((fifo[0] + 1) * XGMAC_FIFO_UNIT));
2351 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002352}
2353
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002354static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002355{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002356 unsigned int qptc, qptc_extra, queue;
2357 unsigned int prio_queues;
2358 unsigned int ppq, ppq_extra, prio;
2359 unsigned int mask;
2360 unsigned int i, j, reg, reg_val;
2361
2362 /* Map the MTL Tx Queues to Traffic Classes
2363 * Note: Tx Queues >= Traffic Classes
2364 */
2365 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
2366 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
2367
2368 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
2369 for (j = 0; j < qptc; j++) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002370 netif_dbg(pdata, drv, pdata->netdev,
2371 "TXq%u mapped to TC%u\n", queue, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002372 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2373 Q2TCMAP, i);
2374 pdata->q2tc_map[queue++] = i;
2375 }
2376
2377 if (i < qptc_extra) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002378 netif_dbg(pdata, drv, pdata->netdev,
2379 "TXq%u mapped to TC%u\n", queue, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002380 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
2381 Q2TCMAP, i);
2382 pdata->q2tc_map[queue++] = i;
2383 }
2384 }
2385
2386 /* Map the 8 VLAN priority values to available MTL Rx queues */
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002387 prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002388 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
2389 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
2390
2391 reg = MAC_RQC2R;
2392 reg_val = 0;
2393 for (i = 0, prio = 0; i < prio_queues;) {
2394 mask = 0;
2395 for (j = 0; j < ppq; j++) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002396 netif_dbg(pdata, drv, pdata->netdev,
2397 "PRIO%u mapped to RXq%u\n", prio, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002398 mask |= (1 << prio);
2399 pdata->prio2q_map[prio++] = i;
2400 }
2401
2402 if (i < ppq_extra) {
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05002403 netif_dbg(pdata, drv, pdata->netdev,
2404 "PRIO%u mapped to RXq%u\n", prio, i);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002405 mask |= (1 << prio);
2406 pdata->prio2q_map[prio++] = i;
2407 }
2408
2409 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
2410
2411 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
2412 continue;
2413
2414 XGMAC_IOWRITE(pdata, reg, reg_val);
2415 reg += MAC_RQC2_INC;
2416 reg_val = 0;
2417 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002418
2419 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
2420 reg = MTL_RQDCM0R;
2421 reg_val = 0;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002422 for (i = 0; i < pdata->rx_q_count;) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002423 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
2424
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002425 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002426 continue;
2427
2428 XGMAC_IOWRITE(pdata, reg, reg_val);
2429
2430 reg += MTL_RQDCM_INC;
2431 reg_val = 0;
2432 }
2433}
2434
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002435static void xgbe_config_tc(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002436{
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002437 unsigned int offset, queue, prio;
2438 u8 i;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002439
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002440 netdev_reset_tc(pdata->netdev);
2441 if (!pdata->num_tcs)
2442 return;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002443
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -05002444 netdev_set_num_tc(pdata->netdev, pdata->num_tcs);
2445
2446 for (i = 0, queue = 0, offset = 0; i < pdata->num_tcs; i++) {
2447 while ((queue < pdata->tx_q_count) &&
2448 (pdata->q2tc_map[queue] == i))
2449 queue++;
2450
2451 netif_dbg(pdata, drv, pdata->netdev, "TC%u using TXq%u-%u\n",
2452 i, offset, queue - 1);
2453 netdev_set_tc_queue(pdata->netdev, i, queue - offset, offset);
2454 offset = queue;
2455 }
2456
2457 if (!pdata->ets)
2458 return;
2459
2460 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++)
2461 netdev_set_prio_tc_map(pdata->netdev, prio,
2462 pdata->ets->prio_tc[prio]);
2463}
2464
2465static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
2466{
2467 struct ieee_ets *ets = pdata->ets;
2468 unsigned int total_weight, min_weight, weight;
2469 unsigned int mask, reg, reg_val;
2470 unsigned int i, prio;
2471
2472 if (!ets)
2473 return;
2474
2475 /* Set Tx to deficit weighted round robin scheduling algorithm (when
2476 * traffic class is using ETS algorithm)
2477 */
2478 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
2479
2480 /* Set Traffic Class algorithms */
2481 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
2482 min_weight = total_weight / 100;
2483 if (!min_weight)
2484 min_weight = 1;
2485
2486 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
2487 /* Map the priorities to the traffic class */
2488 mask = 0;
2489 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
2490 if (ets->prio_tc[prio] == i)
2491 mask |= (1 << prio);
2492 }
2493 mask &= 0xff;
2494
2495 netif_dbg(pdata, drv, pdata->netdev, "TC%u PRIO mask=%#x\n",
2496 i, mask);
2497 reg = MTL_TCPM0R + (MTL_TCPM_INC * (i / MTL_TCPM_TC_PER_REG));
2498 reg_val = XGMAC_IOREAD(pdata, reg);
2499
2500 reg_val &= ~(0xff << ((i % MTL_TCPM_TC_PER_REG) << 3));
2501 reg_val |= (mask << ((i % MTL_TCPM_TC_PER_REG) << 3));
2502
2503 XGMAC_IOWRITE(pdata, reg, reg_val);
2504
2505 /* Set the traffic class algorithm */
2506 switch (ets->tc_tsa[i]) {
2507 case IEEE_8021QAZ_TSA_STRICT:
2508 netif_dbg(pdata, drv, pdata->netdev,
2509 "TC%u using SP\n", i);
2510 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
2511 MTL_TSA_SP);
2512 break;
2513 case IEEE_8021QAZ_TSA_ETS:
2514 weight = total_weight * ets->tc_tx_bw[i] / 100;
2515 weight = clamp(weight, min_weight, total_weight);
2516
2517 netif_dbg(pdata, drv, pdata->netdev,
2518 "TC%u using DWRR (weight %u)\n", i, weight);
2519 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
2520 MTL_TSA_ETS);
2521 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
2522 weight);
2523 break;
2524 }
2525 }
2526
2527 xgbe_config_tc(pdata);
2528}
2529
2530static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
2531{
2532 if (!test_bit(XGBE_DOWN, &pdata->dev_state)) {
2533 /* Just stop the Tx queues while Rx fifo is changed */
2534 netif_tx_stop_all_queues(pdata->netdev);
2535
2536 /* Suspend Rx so that fifo's can be adjusted */
2537 pdata->hw_if.disable_rx(pdata);
2538 }
2539
2540 xgbe_config_rx_fifo_size(pdata);
2541 xgbe_config_flow_control(pdata);
2542
2543 if (!test_bit(XGBE_DOWN, &pdata->dev_state)) {
2544 /* Resume Rx */
2545 pdata->hw_if.enable_rx(pdata);
2546
2547 /* Resume Tx queues */
2548 netif_tx_start_all_queues(pdata->netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002549 }
2550}
2551
2552static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
2553{
2554 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05002555
2556 /* Filtering is done using perfect filtering and hash filtering */
2557 if (pdata->hw_feat.hash_table_size) {
2558 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
2559 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
2560 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
2561 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002562}
2563
2564static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
2565{
2566 unsigned int val;
2567
2568 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
2569
2570 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
2571}
2572
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002573static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata)
2574{
Lendacky, Thomase57f7a32016-11-03 13:18:27 -05002575 xgbe_set_speed(pdata, pdata->phy_speed);
Lendacky, Thomas916102c2015-01-16 12:46:45 -06002576}
2577
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002578static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
2579{
2580 if (pdata->netdev->features & NETIF_F_RXCSUM)
2581 xgbe_enable_rx_csum(pdata);
2582 else
2583 xgbe_disable_rx_csum(pdata);
2584}
2585
2586static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
2587{
Lendacky, Thomas6e5eed02014-06-24 16:19:12 -05002588 /* Indicate that VLAN Tx CTAGs come from context descriptors */
2589 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
2590 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
2591
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002592 /* Set the current VLAN Hash Table register value */
2593 xgbe_update_vlan_hash_table(pdata);
2594
2595 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
2596 xgbe_enable_rx_vlan_filtering(pdata);
2597 else
2598 xgbe_disable_rx_vlan_filtering(pdata);
2599
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002600 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2601 xgbe_enable_rx_vlan_stripping(pdata);
2602 else
2603 xgbe_disable_rx_vlan_stripping(pdata);
2604}
2605
Lendacky, Thomas60265102014-09-05 18:02:30 -05002606static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
2607{
2608 bool read_hi;
2609 u64 val;
2610
Lendacky, Thomase5a20b92016-11-03 13:19:07 -05002611 if (pdata->vdata->mmc_64bit) {
2612 switch (reg_lo) {
2613 /* These registers are always 32 bit */
2614 case MMC_RXRUNTERROR:
2615 case MMC_RXJABBERERROR:
2616 case MMC_RXUNDERSIZE_G:
2617 case MMC_RXOVERSIZE_G:
2618 case MMC_RXWATCHDOGERROR:
2619 read_hi = false;
2620 break;
Lendacky, Thomas60265102014-09-05 18:02:30 -05002621
Lendacky, Thomase5a20b92016-11-03 13:19:07 -05002622 default:
2623 read_hi = true;
2624 }
2625 } else {
2626 switch (reg_lo) {
2627 /* These registers are always 64 bit */
2628 case MMC_TXOCTETCOUNT_GB_LO:
2629 case MMC_TXOCTETCOUNT_G_LO:
2630 case MMC_RXOCTETCOUNT_GB_LO:
2631 case MMC_RXOCTETCOUNT_G_LO:
2632 read_hi = true;
2633 break;
2634
2635 default:
2636 read_hi = false;
2637 }
Lendacky, Thomas3947d782015-09-30 08:52:38 -05002638 }
Lendacky, Thomas60265102014-09-05 18:02:30 -05002639
2640 val = XGMAC_IOREAD(pdata, reg_lo);
2641
2642 if (read_hi)
2643 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
2644
2645 return val;
2646}
2647
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002648static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
2649{
2650 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2651 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
2652
2653 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
2654 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002655 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002656
2657 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
2658 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002659 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002660
2661 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
2662 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002663 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002664
2665 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
2666 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002667 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002668
2669 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
2670 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002671 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002672
2673 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
2674 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002675 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002676
2677 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
2678 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002679 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002680
2681 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
2682 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002683 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002684
2685 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
2686 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002687 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002688
2689 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
2690 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002691 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002692
2693 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
2694 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002695 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002696
2697 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2698 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002699 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002700
2701 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2702 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002703 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002704
2705 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2706 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002707 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002708
2709 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2710 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002711 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002712
2713 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2714 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002715 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002716
2717 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2718 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002719 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002720
2721 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2722 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002723 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002724}
2725
2726static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2727{
2728 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2729 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2730
2731 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2732 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002733 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002734
2735 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2736 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002737 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002738
2739 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2740 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002741 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002742
2743 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2744 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002745 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002746
2747 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2748 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002749 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002750
2751 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2752 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002753 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002754
2755 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2756 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002757 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002758
2759 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2760 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002761 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002762
2763 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
2764 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002765 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002766
2767 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
2768 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002769 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002770
2771 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
2772 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002773 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002774
2775 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
2776 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002777 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002778
2779 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
2780 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002781 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002782
2783 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
2784 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002785 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002786
2787 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
2788 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002789 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002790
2791 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
2792 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002793 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002794
2795 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
2796 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002797 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002798
2799 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
2800 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002801 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002802
2803 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
2804 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002805 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002806
2807 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
2808 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002809 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002810
2811 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
2812 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002813 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002814
2815 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
2816 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002817 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002818
2819 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
2820 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002821 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002822}
2823
2824static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
2825{
2826 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2827
2828 /* Freeze counters */
2829 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
2830
2831 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002832 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002833
2834 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002835 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002836
2837 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002838 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002839
2840 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002841 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002842
2843 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002844 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002845
2846 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002847 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002848
2849 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002850 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002851
2852 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002853 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002854
2855 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002856 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002857
2858 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002859 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002860
2861 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002862 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002863
2864 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002865 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002866
2867 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002868 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002869
2870 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002871 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002872
2873 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002874 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002875
2876 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002877 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002878
2879 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002880 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002881
2882 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002883 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002884
2885 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002886 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002887
2888 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002889 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002890
2891 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002892 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002893
2894 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002895 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002896
2897 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002898 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002899
2900 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002901 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002902
2903 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002904 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002905
2906 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002907 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002908
2909 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002910 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002911
2912 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002913 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002914
2915 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002916 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002917
2918 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002919 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002920
2921 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002922 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002923
2924 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002925 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002926
2927 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002928 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002929
2930 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002931 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002932
2933 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002934 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002935
2936 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002937 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002938
2939 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002940 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002941
2942 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002943 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002944
2945 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002946 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002947
2948 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002949 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002950
2951 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002952 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002953
2954 /* Un-freeze counters */
2955 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
2956}
2957
2958static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
2959{
2960 /* Set counters to reset on read */
2961 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
2962
2963 /* Reset the counters */
2964 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
2965}
2966
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05002967static void xgbe_txq_prepare_tx_stop(struct xgbe_prv_data *pdata,
2968 unsigned int queue)
2969{
2970 unsigned int tx_status;
2971 unsigned long tx_timeout;
2972
2973 /* The Tx engine cannot be stopped if it is actively processing
2974 * packets. Wait for the Tx queue to empty the Tx fifo. Don't
2975 * wait forever though...
2976 */
2977 tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
2978 while (time_before(jiffies, tx_timeout)) {
2979 tx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR);
2980 if ((XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TRCSTS) != 1) &&
2981 (XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TXQSTS) == 0))
2982 break;
2983
2984 usleep_range(500, 1000);
2985 }
2986
2987 if (!time_before(jiffies, tx_timeout))
2988 netdev_info(pdata->netdev,
2989 "timed out waiting for Tx queue %u to empty\n",
2990 queue);
2991}
2992
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002993static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05002994 unsigned int queue)
Lendacky, Thomas16edd342014-11-20 11:03:32 -06002995{
2996 unsigned int tx_dsr, tx_pos, tx_qidx;
2997 unsigned int tx_status;
2998 unsigned long tx_timeout;
2999
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003000 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) > 0x20)
3001 return xgbe_txq_prepare_tx_stop(pdata, queue);
3002
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003003 /* Calculate the status register to read and the position within */
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003004 if (queue < DMA_DSRX_FIRST_QUEUE) {
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003005 tx_dsr = DMA_DSR0;
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003006 tx_pos = (queue * DMA_DSR_Q_WIDTH) + DMA_DSR0_TPS_START;
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003007 } else {
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003008 tx_qidx = queue - DMA_DSRX_FIRST_QUEUE;
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003009
3010 tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
3011 tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
3012 DMA_DSRX_TPS_START;
3013 }
3014
3015 /* The Tx engine cannot be stopped if it is actively processing
3016 * descriptors. Wait for the Tx engine to enter the stopped or
3017 * suspended state. Don't wait forever though...
3018 */
3019 tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
3020 while (time_before(jiffies, tx_timeout)) {
3021 tx_status = XGMAC_IOREAD(pdata, tx_dsr);
3022 tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
3023 if ((tx_status == DMA_TPS_STOPPED) ||
3024 (tx_status == DMA_TPS_SUSPENDED))
3025 break;
3026
3027 usleep_range(500, 1000);
3028 }
3029
3030 if (!time_before(jiffies, tx_timeout))
3031 netdev_info(pdata->netdev,
3032 "timed out waiting for Tx DMA channel %u to stop\n",
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003033 queue);
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003034}
3035
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003036static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
3037{
3038 struct xgbe_channel *channel;
3039 unsigned int i;
3040
3041 /* Enable each Tx DMA channel */
3042 channel = pdata->channel;
3043 for (i = 0; i < pdata->channel_count; i++, channel++) {
3044 if (!channel->tx_ring)
3045 break;
3046
3047 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
3048 }
3049
3050 /* Enable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05003051 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003052 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
3053 MTL_Q_ENABLED);
3054
3055 /* Enable MAC Tx */
3056 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
3057}
3058
3059static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
3060{
3061 struct xgbe_channel *channel;
3062 unsigned int i;
3063
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003064 /* Prepare for Tx DMA channel stop */
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003065 for (i = 0; i < pdata->tx_q_count; i++)
3066 xgbe_prepare_tx_stop(pdata, i);
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003067
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003068 /* Disable MAC Tx */
3069 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
3070
3071 /* Disable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05003072 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003073 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
3074
3075 /* Disable each Tx DMA channel */
3076 channel = pdata->channel;
3077 for (i = 0; i < pdata->channel_count; i++, channel++) {
3078 if (!channel->tx_ring)
3079 break;
3080
3081 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
3082 }
3083}
3084
Lendacky, Thomasc3727d62016-02-17 11:49:16 -06003085static void xgbe_prepare_rx_stop(struct xgbe_prv_data *pdata,
3086 unsigned int queue)
3087{
3088 unsigned int rx_status;
3089 unsigned long rx_timeout;
3090
3091 /* The Rx engine cannot be stopped if it is actively processing
3092 * packets. Wait for the Rx queue to empty the Rx fifo. Don't
3093 * wait forever though...
3094 */
3095 rx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
3096 while (time_before(jiffies, rx_timeout)) {
3097 rx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR);
3098 if ((XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) &&
3099 (XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0))
3100 break;
3101
3102 usleep_range(500, 1000);
3103 }
3104
3105 if (!time_before(jiffies, rx_timeout))
3106 netdev_info(pdata->netdev,
3107 "timed out waiting for Rx queue %u to empty\n",
3108 queue);
3109}
3110
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003111static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
3112{
3113 struct xgbe_channel *channel;
3114 unsigned int reg_val, i;
3115
3116 /* Enable each Rx DMA channel */
3117 channel = pdata->channel;
3118 for (i = 0; i < pdata->channel_count; i++, channel++) {
3119 if (!channel->rx_ring)
3120 break;
3121
3122 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
3123 }
3124
3125 /* Enable each Rx queue */
3126 reg_val = 0;
Lendacky, Thomas853eb162014-07-29 08:57:31 -05003127 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003128 reg_val |= (0x02 << (i << 1));
3129 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
3130
3131 /* Enable MAC Rx */
3132 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
3133 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
3134 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
3135 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
3136}
3137
3138static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
3139{
3140 struct xgbe_channel *channel;
3141 unsigned int i;
3142
3143 /* Disable MAC Rx */
3144 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
3145 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
3146 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
3147 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
3148
Lendacky, Thomasc3727d62016-02-17 11:49:16 -06003149 /* Prepare for Rx DMA channel stop */
3150 for (i = 0; i < pdata->rx_q_count; i++)
3151 xgbe_prepare_rx_stop(pdata, i);
3152
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003153 /* Disable each Rx queue */
3154 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
3155
3156 /* Disable each Rx DMA channel */
3157 channel = pdata->channel;
3158 for (i = 0; i < pdata->channel_count; i++, channel++) {
3159 if (!channel->rx_ring)
3160 break;
3161
3162 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
3163 }
3164}
3165
3166static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
3167{
3168 struct xgbe_channel *channel;
3169 unsigned int i;
3170
3171 /* Enable each Tx DMA channel */
3172 channel = pdata->channel;
3173 for (i = 0; i < pdata->channel_count; i++, channel++) {
3174 if (!channel->tx_ring)
3175 break;
3176
3177 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
3178 }
3179
3180 /* Enable MAC Tx */
3181 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
3182}
3183
3184static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
3185{
3186 struct xgbe_channel *channel;
3187 unsigned int i;
3188
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003189 /* Prepare for Tx DMA channel stop */
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -05003190 for (i = 0; i < pdata->tx_q_count; i++)
3191 xgbe_prepare_tx_stop(pdata, i);
Lendacky, Thomas16edd342014-11-20 11:03:32 -06003192
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003193 /* Disable MAC Tx */
3194 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
3195
3196 /* Disable each Tx DMA channel */
3197 channel = pdata->channel;
3198 for (i = 0; i < pdata->channel_count; i++, channel++) {
3199 if (!channel->tx_ring)
3200 break;
3201
3202 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
3203 }
3204}
3205
3206static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
3207{
3208 struct xgbe_channel *channel;
3209 unsigned int i;
3210
3211 /* Enable each Rx DMA channel */
3212 channel = pdata->channel;
3213 for (i = 0; i < pdata->channel_count; i++, channel++) {
3214 if (!channel->rx_ring)
3215 break;
3216
3217 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
3218 }
3219}
3220
3221static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
3222{
3223 struct xgbe_channel *channel;
3224 unsigned int i;
3225
3226 /* Disable each Rx DMA channel */
3227 channel = pdata->channel;
3228 for (i = 0; i < pdata->channel_count; i++, channel++) {
3229 if (!channel->rx_ring)
3230 break;
3231
3232 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
3233 }
3234}
3235
3236static int xgbe_init(struct xgbe_prv_data *pdata)
3237{
3238 struct xgbe_desc_if *desc_if = &pdata->desc_if;
3239 int ret;
3240
3241 DBGPR("-->xgbe_init\n");
3242
3243 /* Flush Tx queues */
3244 ret = xgbe_flush_tx_queues(pdata);
3245 if (ret)
3246 return ret;
3247
3248 /*
3249 * Initialize DMA related features
3250 */
3251 xgbe_config_dma_bus(pdata);
3252 xgbe_config_dma_cache(pdata);
3253 xgbe_config_osp_mode(pdata);
3254 xgbe_config_pblx8(pdata);
3255 xgbe_config_tx_pbl_val(pdata);
3256 xgbe_config_rx_pbl_val(pdata);
3257 xgbe_config_rx_coalesce(pdata);
3258 xgbe_config_tx_coalesce(pdata);
3259 xgbe_config_rx_buffer_size(pdata);
3260 xgbe_config_tso_mode(pdata);
Lendacky, Thomas174fd252014-11-04 16:06:50 -06003261 xgbe_config_sph_mode(pdata);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06003262 xgbe_config_rss(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003263 desc_if->wrapper_tx_desc_init(pdata);
3264 desc_if->wrapper_rx_desc_init(pdata);
3265 xgbe_enable_dma_interrupts(pdata);
3266
3267 /*
3268 * Initialize MTL related features
3269 */
3270 xgbe_config_mtl_mode(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05003271 xgbe_config_queue_mapping(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003272 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
3273 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
3274 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
3275 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
3276 xgbe_config_tx_fifo_size(pdata);
3277 xgbe_config_rx_fifo_size(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003278 /*TODO: Error Packet and undersized good Packet forwarding enable
3279 (FEP and FUP)
3280 */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05003281 xgbe_config_dcb_tc(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003282 xgbe_enable_mtl_interrupts(pdata);
3283
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003284 /*
3285 * Initialize MAC related features
3286 */
3287 xgbe_config_mac_address(pdata);
Lendacky, Thomasb8763822015-04-09 12:11:57 -05003288 xgbe_config_rx_mode(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003289 xgbe_config_jumbo_enable(pdata);
3290 xgbe_config_flow_control(pdata);
Lendacky, Thomas916102c2015-01-16 12:46:45 -06003291 xgbe_config_mac_speed(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003292 xgbe_config_checksum_offload(pdata);
3293 xgbe_config_vlan_support(pdata);
3294 xgbe_config_mmc(pdata);
3295 xgbe_enable_mac_interrupts(pdata);
3296
3297 DBGPR("<--xgbe_init\n");
3298
3299 return 0;
3300}
3301
3302void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
3303{
3304 DBGPR("-->xgbe_init_function_ptrs\n");
3305
3306 hw_if->tx_complete = xgbe_tx_complete;
3307
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003308 hw_if->set_mac_address = xgbe_set_mac_address;
Lendacky, Thomasb8763822015-04-09 12:11:57 -05003309 hw_if->config_rx_mode = xgbe_config_rx_mode;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003310
3311 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
3312 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
3313
3314 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
3315 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05003316 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
3317 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
3318 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003319
3320 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
3321 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
3322
Lendacky, Thomase57f7a32016-11-03 13:18:27 -05003323 hw_if->set_speed = xgbe_set_speed;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003324
3325 hw_if->enable_tx = xgbe_enable_tx;
3326 hw_if->disable_tx = xgbe_disable_tx;
3327 hw_if->enable_rx = xgbe_enable_rx;
3328 hw_if->disable_rx = xgbe_disable_rx;
3329
3330 hw_if->powerup_tx = xgbe_powerup_tx;
3331 hw_if->powerdown_tx = xgbe_powerdown_tx;
3332 hw_if->powerup_rx = xgbe_powerup_rx;
3333 hw_if->powerdown_rx = xgbe_powerdown_rx;
3334
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06003335 hw_if->dev_xmit = xgbe_dev_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003336 hw_if->dev_read = xgbe_dev_read;
3337 hw_if->enable_int = xgbe_enable_int;
3338 hw_if->disable_int = xgbe_disable_int;
3339 hw_if->init = xgbe_init;
3340 hw_if->exit = xgbe_exit;
3341
3342 /* Descriptor related Sequences have to be initialized here */
3343 hw_if->tx_desc_init = xgbe_tx_desc_init;
3344 hw_if->rx_desc_init = xgbe_rx_desc_init;
3345 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
3346 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
3347 hw_if->is_last_desc = xgbe_is_last_desc;
3348 hw_if->is_context_desc = xgbe_is_context_desc;
Lendacky, Thomas16958a22014-11-20 11:04:08 -06003349 hw_if->tx_start_xmit = xgbe_tx_start_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003350
3351 /* For FLOW ctrl */
3352 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
3353 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
3354
3355 /* For RX coalescing */
3356 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
3357 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
3358 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
3359 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
3360
3361 /* For RX and TX threshold config */
3362 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
3363 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
3364
3365 /* For RX and TX Store and Forward Mode config */
3366 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
3367 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
3368
3369 /* For TX DMA Operating on Second Frame config */
3370 hw_if->config_osp_mode = xgbe_config_osp_mode;
3371
3372 /* For RX and TX PBL config */
3373 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
3374 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
3375 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
3376 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
3377 hw_if->config_pblx8 = xgbe_config_pblx8;
3378
3379 /* For MMC statistics support */
3380 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
3381 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
3382 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
3383
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05003384 /* For PTP config */
3385 hw_if->config_tstamp = xgbe_config_tstamp;
3386 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
3387 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
3388 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
3389 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
3390
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05003391 /* For Data Center Bridging config */
Lendacky, Thomasb3b71592016-02-17 11:49:08 -06003392 hw_if->config_tc = xgbe_config_tc;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05003393 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
3394 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
3395
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06003396 /* For Receive Side Scaling */
3397 hw_if->enable_rss = xgbe_enable_rss;
3398 hw_if->disable_rss = xgbe_disable_rss;
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -06003399 hw_if->set_rss_hash_key = xgbe_set_rss_hash_key;
3400 hw_if->set_rss_lookup_table = xgbe_set_rss_lookup_table;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -06003401
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05003402 DBGPR("<--xgbe_init_function_ptrs\n");
3403}