blob: e43747a9926f60324960db849ffd251b3a033265 [file] [log] [blame]
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001/*
2 * AMD 10Gb Ethernet driver
3 *
4 * This file is available to you under your choice of the following two
5 * licenses:
6 *
7 * License 1: GPLv2
8 *
9 * Copyright (c) 2014 Advanced Micro Devices, Inc.
10 *
11 * This file is free software; you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * This file incorporates work covered by the following copyright and
25 * permission notice:
26 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
27 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28 * Inc. unless otherwise expressly agreed to in writing between Synopsys
29 * and you.
30 *
31 * The Software IS NOT an item of Licensed Software or Licensed Product
32 * under any End User Software License Agreement or Agreement for Licensed
33 * Product with Synopsys or any supplement thereto. Permission is hereby
34 * granted, free of charge, to any person obtaining a copy of this software
35 * annotated with this license and the Software, to deal in the Software
36 * without restriction, including without limitation the rights to use,
37 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 * of the Software, and to permit persons to whom the Software is furnished
39 * to do so, subject to the following conditions:
40 *
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
43 *
44 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54 * THE POSSIBILITY OF SUCH DAMAGE.
55 *
56 *
57 * License 2: Modified BSD
58 *
59 * Copyright (c) 2014 Advanced Micro Devices, Inc.
60 * All rights reserved.
61 *
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions are met:
64 * * Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 * * Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
69 * * Neither the name of Advanced Micro Devices, Inc. nor the
70 * names of its contributors may be used to endorse or promote products
71 * derived from this software without specific prior written permission.
72 *
73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 *
84 * This file incorporates work covered by the following copyright and
85 * permission notice:
86 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
87 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88 * Inc. unless otherwise expressly agreed to in writing between Synopsys
89 * and you.
90 *
91 * The Software IS NOT an item of Licensed Software or Licensed Product
92 * under any End User Software License Agreement or Agreement for Licensed
93 * Product with Synopsys or any supplement thereto. Permission is hereby
94 * granted, free of charge, to any person obtaining a copy of this software
95 * annotated with this license and the Software, to deal in the Software
96 * without restriction, including without limitation the rights to use,
97 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98 * of the Software, and to permit persons to whom the Software is furnished
99 * to do so, subject to the following conditions:
100 *
101 * The above copyright notice and this permission notice shall be included
102 * in all copies or substantial portions of the Software.
103 *
104 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114 * THE POSSIBILITY OF SUCH DAMAGE.
115 */
116
117#include <linux/phy.h>
118#include <linux/clk.h>
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500119#include <linux/bitrev.h>
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500120#include <linux/crc32.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500121
122#include "xgbe.h"
123#include "xgbe-common.h"
124
125
126static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
127 unsigned int usec)
128{
129 unsigned long rate;
130 unsigned int ret;
131
132 DBGPR("-->xgbe_usec_to_riwt\n");
133
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500134 rate = clk_get_rate(pdata->sysclk);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500135
136 /*
137 * Convert the input usec value to the watchdog timer value. Each
138 * watchdog timer value is equivalent to 256 clock cycles.
139 * Calculate the required value as:
140 * ( usec * ( system_clock_mhz / 10^6 ) / 256
141 */
142 ret = (usec * (rate / 1000000)) / 256;
143
144 DBGPR("<--xgbe_usec_to_riwt\n");
145
146 return ret;
147}
148
149static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
150 unsigned int riwt)
151{
152 unsigned long rate;
153 unsigned int ret;
154
155 DBGPR("-->xgbe_riwt_to_usec\n");
156
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500157 rate = clk_get_rate(pdata->sysclk);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500158
159 /*
160 * Convert the input watchdog timer value to the usec value. Each
161 * watchdog timer value is equivalent to 256 clock cycles.
162 * Calculate the required value as:
163 * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
164 */
165 ret = (riwt * 256) / (rate / 1000000);
166
167 DBGPR("<--xgbe_riwt_to_usec\n");
168
169 return ret;
170}
171
172static int xgbe_config_pblx8(struct xgbe_prv_data *pdata)
173{
174 struct xgbe_channel *channel;
175 unsigned int i;
176
177 channel = pdata->channel;
178 for (i = 0; i < pdata->channel_count; i++, channel++)
179 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8,
180 pdata->pblx8);
181
182 return 0;
183}
184
185static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata)
186{
187 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL);
188}
189
190static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata)
191{
192 struct xgbe_channel *channel;
193 unsigned int i;
194
195 channel = pdata->channel;
196 for (i = 0; i < pdata->channel_count; i++, channel++) {
197 if (!channel->tx_ring)
198 break;
199
200 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL,
201 pdata->tx_pbl);
202 }
203
204 return 0;
205}
206
207static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata)
208{
209 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL);
210}
211
212static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata)
213{
214 struct xgbe_channel *channel;
215 unsigned int i;
216
217 channel = pdata->channel;
218 for (i = 0; i < pdata->channel_count; i++, channel++) {
219 if (!channel->rx_ring)
220 break;
221
222 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL,
223 pdata->rx_pbl);
224 }
225
226 return 0;
227}
228
229static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
230{
231 struct xgbe_channel *channel;
232 unsigned int i;
233
234 channel = pdata->channel;
235 for (i = 0; i < pdata->channel_count; i++, channel++) {
236 if (!channel->tx_ring)
237 break;
238
239 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP,
240 pdata->tx_osp_mode);
241 }
242
243 return 0;
244}
245
246static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
247{
248 unsigned int i;
249
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500250 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500251 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
252
253 return 0;
254}
255
256static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
257{
258 unsigned int i;
259
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500260 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500261 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
262
263 return 0;
264}
265
266static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
267 unsigned int val)
268{
269 unsigned int i;
270
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500271 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500272 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
273
274 return 0;
275}
276
277static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
278 unsigned int val)
279{
280 unsigned int i;
281
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500282 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500283 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
284
285 return 0;
286}
287
288static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
289{
290 struct xgbe_channel *channel;
291 unsigned int i;
292
293 channel = pdata->channel;
294 for (i = 0; i < pdata->channel_count; i++, channel++) {
295 if (!channel->rx_ring)
296 break;
297
298 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT,
299 pdata->rx_riwt);
300 }
301
302 return 0;
303}
304
305static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
306{
307 return 0;
308}
309
310static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
311{
312 struct xgbe_channel *channel;
313 unsigned int i;
314
315 channel = pdata->channel;
316 for (i = 0; i < pdata->channel_count; i++, channel++) {
317 if (!channel->rx_ring)
318 break;
319
320 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ,
321 pdata->rx_buf_size);
322 }
323}
324
325static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
326{
327 struct xgbe_channel *channel;
328 unsigned int i;
329
330 channel = pdata->channel;
331 for (i = 0; i < pdata->channel_count; i++, channel++) {
332 if (!channel->tx_ring)
333 break;
334
335 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1);
336 }
337}
338
339static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
340{
341 unsigned int max_q_count, q_count;
342 unsigned int reg, reg_val;
343 unsigned int i;
344
345 /* Clear MTL flow control */
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500346 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500347 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
348
349 /* Clear MAC flow control */
350 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500351 q_count = min_t(unsigned int, pdata->rx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500352 reg = MAC_Q0TFCR;
353 for (i = 0; i < q_count; i++) {
354 reg_val = XGMAC_IOREAD(pdata, reg);
355 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
356 XGMAC_IOWRITE(pdata, reg, reg_val);
357
358 reg += MAC_QTFCR_INC;
359 }
360
361 return 0;
362}
363
364static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
365{
366 unsigned int max_q_count, q_count;
367 unsigned int reg, reg_val;
368 unsigned int i;
369
370 /* Set MTL flow control */
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500371 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500372 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 1);
373
374 /* Set MAC flow control */
375 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500376 q_count = min_t(unsigned int, pdata->rx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500377 reg = MAC_Q0TFCR;
378 for (i = 0; i < q_count; i++) {
379 reg_val = XGMAC_IOREAD(pdata, reg);
380
381 /* Enable transmit flow control */
382 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
383 /* Set pause time */
384 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
385
386 XGMAC_IOWRITE(pdata, reg, reg_val);
387
388 reg += MAC_QTFCR_INC;
389 }
390
391 return 0;
392}
393
394static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
395{
396 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
397
398 return 0;
399}
400
401static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
402{
403 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
404
405 return 0;
406}
407
408static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
409{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500410 struct ieee_pfc *pfc = pdata->pfc;
411
412 if (pdata->tx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500413 xgbe_enable_tx_flow_control(pdata);
414 else
415 xgbe_disable_tx_flow_control(pdata);
416
417 return 0;
418}
419
420static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
421{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500422 struct ieee_pfc *pfc = pdata->pfc;
423
424 if (pdata->rx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500425 xgbe_enable_rx_flow_control(pdata);
426 else
427 xgbe_disable_rx_flow_control(pdata);
428
429 return 0;
430}
431
432static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
433{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500434 struct ieee_pfc *pfc = pdata->pfc;
435
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500436 xgbe_config_tx_flow_control(pdata);
437 xgbe_config_rx_flow_control(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500438
439 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
440 (pfc && pfc->pfc_en) ? 1 : 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500441}
442
443static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
444{
445 struct xgbe_channel *channel;
446 unsigned int dma_ch_isr, dma_ch_ier;
447 unsigned int i;
448
449 channel = pdata->channel;
450 for (i = 0; i < pdata->channel_count; i++, channel++) {
451 /* Clear all the interrupts which are set */
452 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
453 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
454
455 /* Clear all interrupt enable bits */
456 dma_ch_ier = 0;
457
458 /* Enable following interrupts
459 * NIE - Normal Interrupt Summary Enable
460 * AIE - Abnormal Interrupt Summary Enable
461 * FBEE - Fatal Bus Error Enable
462 */
463 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
464 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
465 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
466
467 if (channel->tx_ring) {
468 /* Enable the following Tx interrupts
469 * TIE - Transmit Interrupt Enable (unless polling)
470 */
471 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
472 }
473 if (channel->rx_ring) {
474 /* Enable following Rx interrupts
475 * RBUE - Receive Buffer Unavailable Enable
476 * RIE - Receive Interrupt Enable
477 */
478 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
479 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
480 }
481
482 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
483 }
484}
485
486static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
487{
488 unsigned int mtl_q_isr;
489 unsigned int q_count, i;
490
491 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
492 for (i = 0; i < q_count; i++) {
493 /* Clear all the interrupts which are set */
494 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
495 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
496
497 /* No MTL interrupts to be enabled */
Lendacky, Thomas91f87342014-07-02 13:04:34 -0500498 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500499 }
500}
501
502static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
503{
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500504 unsigned int mac_ier = 0;
505
506 /* Enable Timestamp interrupt */
507 XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
508
509 XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500510
511 /* Enable all counter interrupts */
512 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xff);
513 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xff);
514}
515
516static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
517{
518 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
519
520 return 0;
521}
522
523static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
524{
525 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
526
527 return 0;
528}
529
530static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
531{
532 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
533
534 return 0;
535}
536
537static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
538 unsigned int enable)
539{
540 unsigned int val = enable ? 1 : 0;
541
542 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
543 return 0;
544
545 DBGPR(" %s promiscuous mode\n", enable ? "entering" : "leaving");
546 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
547
548 return 0;
549}
550
551static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
552 unsigned int enable)
553{
554 unsigned int val = enable ? 1 : 0;
555
556 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
557 return 0;
558
559 DBGPR(" %s allmulti mode\n", enable ? "entering" : "leaving");
560 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
561
562 return 0;
563}
564
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500565static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
566 struct netdev_hw_addr *ha, unsigned int *mac_reg)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500567{
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500568 unsigned int mac_addr_hi, mac_addr_lo;
569 u8 *mac_addr;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500570
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500571 mac_addr_lo = 0;
572 mac_addr_hi = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500573
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500574 if (ha) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500575 mac_addr = (u8 *)&mac_addr_lo;
576 mac_addr[0] = ha->addr[0];
577 mac_addr[1] = ha->addr[1];
578 mac_addr[2] = ha->addr[2];
579 mac_addr[3] = ha->addr[3];
580 mac_addr = (u8 *)&mac_addr_hi;
581 mac_addr[0] = ha->addr[4];
582 mac_addr[1] = ha->addr[5];
583
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500584 DBGPR(" adding mac address %pM at 0x%04x\n", ha->addr,
585 *mac_reg);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500586
587 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500588 }
589
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500590 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
591 *mac_reg += MAC_MACA_INC;
592 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
593 *mac_reg += MAC_MACA_INC;
594}
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500595
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500596static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
597{
598 struct net_device *netdev = pdata->netdev;
599 struct netdev_hw_addr *ha;
600 unsigned int mac_reg;
601 unsigned int addn_macs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500602
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500603 mac_reg = MAC_MACA1HR;
604 addn_macs = pdata->hw_feat.addn_mac;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500605
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500606 if (netdev_uc_count(netdev) > addn_macs) {
607 xgbe_set_promiscuous_mode(pdata, 1);
608 } else {
609 netdev_for_each_uc_addr(ha, netdev) {
610 xgbe_set_mac_reg(pdata, ha, &mac_reg);
611 addn_macs--;
612 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500613
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500614 if (netdev_mc_count(netdev) > addn_macs) {
615 xgbe_set_all_multicast_mode(pdata, 1);
616 } else {
617 netdev_for_each_mc_addr(ha, netdev) {
618 xgbe_set_mac_reg(pdata, ha, &mac_reg);
619 addn_macs--;
620 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500621 }
622 }
623
624 /* Clear remaining additional MAC address entries */
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500625 while (addn_macs--)
626 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
627}
628
629static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
630{
631 struct net_device *netdev = pdata->netdev;
632 struct netdev_hw_addr *ha;
633 unsigned int hash_reg;
634 unsigned int hash_table_shift, hash_table_count;
635 u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
636 u32 crc;
637 unsigned int i;
638
639 hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
640 hash_table_count = pdata->hw_feat.hash_table_size / 32;
641 memset(hash_table, 0, sizeof(hash_table));
642
643 /* Build the MAC Hash Table register values */
644 netdev_for_each_uc_addr(ha, netdev) {
645 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
646 crc >>= hash_table_shift;
647 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500648 }
649
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500650 netdev_for_each_mc_addr(ha, netdev) {
651 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
652 crc >>= hash_table_shift;
653 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
654 }
655
656 /* Set the MAC Hash Table registers */
657 hash_reg = MAC_HTR0;
658 for (i = 0; i < hash_table_count; i++) {
659 XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
660 hash_reg += MAC_HTR_INC;
661 }
662}
663
664static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
665{
666 if (pdata->hw_feat.hash_table_size)
667 xgbe_set_mac_hash_table(pdata);
668 else
669 xgbe_set_mac_addn_addrs(pdata);
670
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500671 return 0;
672}
673
674static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
675{
676 unsigned int mac_addr_hi, mac_addr_lo;
677
678 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
679 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
680 (addr[1] << 8) | (addr[0] << 0);
681
682 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
683 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
684
685 return 0;
686}
687
688static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
689 int mmd_reg)
690{
691 unsigned int mmd_address;
692 int mmd_data;
693
694 if (mmd_reg & MII_ADDR_C45)
695 mmd_address = mmd_reg & ~MII_ADDR_C45;
696 else
697 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
698
699 /* The PCS registers are accessed using mmio. The underlying APB3
700 * management interface uses indirect addressing to access the MMD
701 * register sets. This requires accessing of the PCS register in two
702 * phases, an address phase and a data phase.
703 *
704 * The mmio interface is based on 32-bit offsets and values. All
705 * register offsets must therefore be adjusted by left shifting the
706 * offset 2 bits and reading 32 bits of data.
707 */
708 mutex_lock(&pdata->xpcs_mutex);
709 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
710 mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
711 mutex_unlock(&pdata->xpcs_mutex);
712
713 return mmd_data;
714}
715
716static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
717 int mmd_reg, int mmd_data)
718{
719 unsigned int mmd_address;
720
721 if (mmd_reg & MII_ADDR_C45)
722 mmd_address = mmd_reg & ~MII_ADDR_C45;
723 else
724 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
725
726 /* The PCS registers are accessed using mmio. The underlying APB3
727 * management interface uses indirect addressing to access the MMD
728 * register sets. This requires accessing of the PCS register in two
729 * phases, an address phase and a data phase.
730 *
731 * The mmio interface is based on 32-bit offsets and values. All
732 * register offsets must therefore be adjusted by left shifting the
733 * offset 2 bits and reading 32 bits of data.
734 */
735 mutex_lock(&pdata->xpcs_mutex);
736 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
737 XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
738 mutex_unlock(&pdata->xpcs_mutex);
739}
740
741static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
742{
743 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
744}
745
746static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
747{
748 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
749
750 return 0;
751}
752
753static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
754{
755 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
756
757 return 0;
758}
759
760static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
761{
762 /* Put the VLAN tag in the Rx descriptor */
763 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
764
765 /* Don't check the VLAN type */
766 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
767
768 /* Check only C-TAG (0x8100) packets */
769 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
770
771 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
772 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
773
774 /* Enable VLAN tag stripping */
775 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
776
777 return 0;
778}
779
780static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
781{
782 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
783
784 return 0;
785}
786
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500787static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
788{
789 /* Enable VLAN filtering */
790 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
791
792 /* Enable VLAN Hash Table filtering */
793 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
794
795 /* Disable VLAN tag inverse matching */
796 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
797
798 /* Only filter on the lower 12-bits of the VLAN tag */
799 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
800
801 /* In order for the VLAN Hash Table filtering to be effective,
802 * the VLAN tag identifier in the VLAN Tag Register must not
803 * be zero. Set the VLAN tag identifier to "1" to enable the
804 * VLAN Hash Table filtering. This implies that a VLAN tag of
805 * 1 will always pass filtering.
806 */
807 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
808
809 return 0;
810}
811
812static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
813{
814 /* Disable VLAN filtering */
815 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
816
817 return 0;
818}
819
820#ifndef CRCPOLY_LE
821#define CRCPOLY_LE 0xedb88320
822#endif
823static u32 xgbe_vid_crc32_le(__le16 vid_le)
824{
825 u32 poly = CRCPOLY_LE;
826 u32 crc = ~0;
827 u32 temp = 0;
828 unsigned char *data = (unsigned char *)&vid_le;
829 unsigned char data_byte = 0;
830 int i, bits;
831
832 bits = get_bitmask_order(VLAN_VID_MASK);
833 for (i = 0; i < bits; i++) {
834 if ((i % 8) == 0)
835 data_byte = data[i / 8];
836
837 temp = ((crc & 1) ^ data_byte) & 1;
838 crc >>= 1;
839 data_byte >>= 1;
840
841 if (temp)
842 crc ^= poly;
843 }
844
845 return crc;
846}
847
848static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
849{
850 u32 crc;
851 u16 vid;
852 __le16 vid_le;
853 u16 vlan_hash_table = 0;
854
855 /* Generate the VLAN Hash Table value */
856 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
857 /* Get the CRC32 value of the VLAN ID */
858 vid_le = cpu_to_le16(vid);
859 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
860
861 vlan_hash_table |= (1 << crc);
862 }
863
864 /* Set the VLAN Hash Table filtering register */
865 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
866
867 return 0;
868}
869
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500870static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
871{
872 struct xgbe_ring_desc *rdesc = rdata->rdesc;
873
874 /* Reset the Tx descriptor
875 * Set buffer 1 (lo) address to zero
876 * Set buffer 1 (hi) address to zero
877 * Reset all other control bits (IC, TTSE, B2L & B1L)
878 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
879 */
880 rdesc->desc0 = 0;
881 rdesc->desc1 = 0;
882 rdesc->desc2 = 0;
883 rdesc->desc3 = 0;
884}
885
886static void xgbe_tx_desc_init(struct xgbe_channel *channel)
887{
888 struct xgbe_ring *ring = channel->tx_ring;
889 struct xgbe_ring_data *rdata;
890 struct xgbe_ring_desc *rdesc;
891 int i;
892 int start_index = ring->cur;
893
894 DBGPR("-->tx_desc_init\n");
895
896 /* Initialze all descriptors */
897 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500898 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500899 rdesc = rdata->rdesc;
900
901 /* Initialize Tx descriptor
902 * Set buffer 1 (lo) address to zero
903 * Set buffer 1 (hi) address to zero
904 * Reset all other control bits (IC, TTSE, B2L & B1L)
905 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC,
906 * etc)
907 */
908 rdesc->desc0 = 0;
909 rdesc->desc1 = 0;
910 rdesc->desc2 = 0;
911 rdesc->desc3 = 0;
912 }
913
914 /* Make sure everything is written to the descriptor(s) before
915 * telling the device about them
916 */
917 wmb();
918
919 /* Update the total number of Tx descriptors */
920 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
921
922 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500923 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500924 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
925 upper_32_bits(rdata->rdesc_dma));
926 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
927 lower_32_bits(rdata->rdesc_dma));
928
929 DBGPR("<--tx_desc_init\n");
930}
931
932static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
933{
934 struct xgbe_ring_desc *rdesc = rdata->rdesc;
935
936 /* Reset the Rx descriptor
937 * Set buffer 1 (lo) address to dma address (lo)
938 * Set buffer 1 (hi) address to dma address (hi)
939 * Set buffer 2 (lo) address to zero
940 * Set buffer 2 (hi) address to zero and set control bits
941 * OWN and INTE
942 */
943 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
944 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
945 rdesc->desc2 = 0;
946
947 rdesc->desc3 = 0;
948 if (rdata->interrupt)
949 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
950
951 /* Since the Rx DMA engine is likely running, make sure everything
952 * is written to the descriptor(s) before setting the OWN bit
953 * for the descriptor
954 */
955 wmb();
956
957 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
958
959 /* Make sure ownership is written to the descriptor */
960 wmb();
961}
962
963static void xgbe_rx_desc_init(struct xgbe_channel *channel)
964{
965 struct xgbe_prv_data *pdata = channel->pdata;
966 struct xgbe_ring *ring = channel->rx_ring;
967 struct xgbe_ring_data *rdata;
968 struct xgbe_ring_desc *rdesc;
969 unsigned int start_index = ring->cur;
970 unsigned int rx_coalesce, rx_frames;
971 unsigned int i;
972
973 DBGPR("-->rx_desc_init\n");
974
975 rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
976 rx_frames = pdata->rx_frames;
977
978 /* Initialize all descriptors */
979 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500980 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500981 rdesc = rdata->rdesc;
982
983 /* Initialize Rx descriptor
984 * Set buffer 1 (lo) address to dma address (lo)
985 * Set buffer 1 (hi) address to dma address (hi)
986 * Set buffer 2 (lo) address to zero
987 * Set buffer 2 (hi) address to zero and set control
988 * bits OWN and INTE appropriateley
989 */
990 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
991 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
992 rdesc->desc2 = 0;
993 rdesc->desc3 = 0;
994 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
995 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
996 rdata->interrupt = 1;
997 if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames))) {
998 /* Clear interrupt on completion bit */
999 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE,
1000 0);
1001 rdata->interrupt = 0;
1002 }
1003 }
1004
1005 /* Make sure everything is written to the descriptors before
1006 * telling the device about them
1007 */
1008 wmb();
1009
1010 /* Update the total number of Rx descriptors */
1011 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
1012
1013 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001014 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001015 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
1016 upper_32_bits(rdata->rdesc_dma));
1017 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
1018 lower_32_bits(rdata->rdesc_dma));
1019
1020 /* Update the Rx Descriptor Tail Pointer */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001021 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001022 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
1023 lower_32_bits(rdata->rdesc_dma));
1024
1025 DBGPR("<--rx_desc_init\n");
1026}
1027
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001028static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
1029 unsigned int addend)
1030{
1031 /* Set the addend register value and tell the device */
1032 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1033 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1034
1035 /* Wait for addend update to complete */
1036 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1037 udelay(5);
1038}
1039
1040static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1041 unsigned int nsec)
1042{
1043 /* Set the time values and tell the device */
1044 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1045 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1046 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1047
1048 /* Wait for time update to complete */
1049 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1050 udelay(5);
1051}
1052
1053static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1054{
1055 u64 nsec;
1056
1057 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1058 nsec *= NSEC_PER_SEC;
1059 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1060
1061 return nsec;
1062}
1063
1064static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1065{
1066 unsigned int tx_snr;
1067 u64 nsec;
1068
1069 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1070 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1071 return 0;
1072
1073 nsec = XGMAC_IOREAD(pdata, MAC_TXSSR);
1074 nsec *= NSEC_PER_SEC;
1075 nsec += tx_snr;
1076
1077 return nsec;
1078}
1079
1080static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1081 struct xgbe_ring_desc *rdesc)
1082{
1083 u64 nsec;
1084
1085 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1086 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1087 nsec = le32_to_cpu(rdesc->desc1);
1088 nsec <<= 32;
1089 nsec |= le32_to_cpu(rdesc->desc0);
1090 if (nsec != 0xffffffffffffffffULL) {
1091 packet->rx_tstamp = nsec;
1092 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1093 RX_TSTAMP, 1);
1094 }
1095 }
1096}
1097
1098static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1099 unsigned int mac_tscr)
1100{
1101 /* Set one nano-second accuracy */
1102 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1103
1104 /* Set fine timestamp update */
1105 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1106
1107 /* Overwrite earlier timestamps */
1108 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1109
1110 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1111
1112 /* Exit if timestamping is not enabled */
1113 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1114 return 0;
1115
1116 /* Initialize time registers */
1117 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1118 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1119 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1120 xgbe_set_tstamp_time(pdata, 0, 0);
1121
1122 /* Initialize the timecounter */
1123 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1124 ktime_to_ns(ktime_get_real()));
1125
1126 return 0;
1127}
1128
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001129static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
1130{
1131 struct ieee_ets *ets = pdata->ets;
1132 unsigned int total_weight, min_weight, weight;
1133 unsigned int i;
1134
1135 if (!ets)
1136 return;
1137
1138 /* Set Tx to deficit weighted round robin scheduling algorithm (when
1139 * traffic class is using ETS algorithm)
1140 */
1141 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
1142
1143 /* Set Traffic Class algorithms */
1144 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
1145 min_weight = total_weight / 100;
1146 if (!min_weight)
1147 min_weight = 1;
1148
1149 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1150 switch (ets->tc_tsa[i]) {
1151 case IEEE_8021QAZ_TSA_STRICT:
1152 DBGPR(" TC%u using SP\n", i);
1153 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1154 MTL_TSA_SP);
1155 break;
1156 case IEEE_8021QAZ_TSA_ETS:
1157 weight = total_weight * ets->tc_tx_bw[i] / 100;
1158 weight = clamp(weight, min_weight, total_weight);
1159
1160 DBGPR(" TC%u using DWRR (weight %u)\n", i, weight);
1161 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1162 MTL_TSA_ETS);
1163 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
1164 weight);
1165 break;
1166 }
1167 }
1168}
1169
1170static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
1171{
1172 struct ieee_pfc *pfc = pdata->pfc;
1173 struct ieee_ets *ets = pdata->ets;
1174 unsigned int mask, reg, reg_val;
1175 unsigned int tc, prio;
1176
1177 if (!pfc || !ets)
1178 return;
1179
1180 for (tc = 0; tc < pdata->hw_feat.tc_cnt; tc++) {
1181 mask = 0;
1182 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
1183 if ((pfc->pfc_en & (1 << prio)) &&
1184 (ets->prio_tc[prio] == tc))
1185 mask |= (1 << prio);
1186 }
1187 mask &= 0xff;
1188
1189 DBGPR(" TC%u PFC mask=%#x\n", tc, mask);
1190 reg = MTL_TCPM0R + (MTL_TCPM_INC * (tc / MTL_TCPM_TC_PER_REG));
1191 reg_val = XGMAC_IOREAD(pdata, reg);
1192
1193 reg_val &= ~(0xff << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1194 reg_val |= (mask << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1195
1196 XGMAC_IOWRITE(pdata, reg, reg_val);
1197 }
1198
1199 xgbe_config_flow_control(pdata);
1200}
1201
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001202static void xgbe_pre_xmit(struct xgbe_channel *channel)
1203{
1204 struct xgbe_prv_data *pdata = channel->pdata;
1205 struct xgbe_ring *ring = channel->tx_ring;
1206 struct xgbe_ring_data *rdata;
1207 struct xgbe_ring_desc *rdesc;
1208 struct xgbe_packet_data *packet = &ring->packet_data;
1209 unsigned int csum, tso, vlan;
1210 unsigned int tso_context, vlan_context;
1211 unsigned int tx_coalesce, tx_frames;
1212 int start_index = ring->cur;
1213 int i;
1214
1215 DBGPR("-->xgbe_pre_xmit\n");
1216
1217 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1218 CSUM_ENABLE);
1219 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1220 TSO_ENABLE);
1221 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1222 VLAN_CTAG);
1223
1224 if (tso && (packet->mss != ring->tx.cur_mss))
1225 tso_context = 1;
1226 else
1227 tso_context = 0;
1228
1229 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1230 vlan_context = 1;
1231 else
1232 vlan_context = 0;
1233
1234 tx_coalesce = (pdata->tx_usecs || pdata->tx_frames) ? 1 : 0;
1235 tx_frames = pdata->tx_frames;
1236 if (tx_coalesce && !channel->tx_timer_active)
1237 ring->coalesce_count = 0;
1238
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001239 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001240 rdesc = rdata->rdesc;
1241
1242 /* Create a context descriptor if this is a TSO packet */
1243 if (tso_context || vlan_context) {
1244 if (tso_context) {
1245 DBGPR(" TSO context descriptor, mss=%u\n",
1246 packet->mss);
1247
1248 /* Set the MSS size */
1249 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1250 MSS, packet->mss);
1251
1252 /* Mark it as a CONTEXT descriptor */
1253 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1254 CTXT, 1);
1255
1256 /* Indicate this descriptor contains the MSS */
1257 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1258 TCMSSV, 1);
1259
1260 ring->tx.cur_mss = packet->mss;
1261 }
1262
1263 if (vlan_context) {
1264 DBGPR(" VLAN context descriptor, ctag=%u\n",
1265 packet->vlan_ctag);
1266
1267 /* Mark it as a CONTEXT descriptor */
1268 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1269 CTXT, 1);
1270
1271 /* Set the VLAN tag */
1272 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1273 VT, packet->vlan_ctag);
1274
1275 /* Indicate this descriptor contains the VLAN tag */
1276 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1277 VLTV, 1);
1278
1279 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1280 }
1281
1282 ring->cur++;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001283 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001284 rdesc = rdata->rdesc;
1285 }
1286
1287 /* Update buffer address (for TSO this is the header) */
1288 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1289 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1290
1291 /* Update the buffer length */
1292 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1293 rdata->skb_dma_len);
1294
1295 /* VLAN tag insertion check */
1296 if (vlan)
1297 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1298 TX_NORMAL_DESC2_VLAN_INSERT);
1299
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001300 /* Timestamp enablement check */
1301 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1302 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1303
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001304 /* Set IC bit based on Tx coalescing settings */
1305 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1306 if (tx_coalesce && (!tx_frames ||
1307 (++ring->coalesce_count % tx_frames)))
1308 /* Clear IC bit */
1309 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1310
1311 /* Mark it as First Descriptor */
1312 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1313
1314 /* Mark it as a NORMAL descriptor */
1315 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1316
1317 /* Set OWN bit if not the first descriptor */
1318 if (ring->cur != start_index)
1319 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1320
1321 if (tso) {
1322 /* Enable TSO */
1323 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1324 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1325 packet->tcp_payload_len);
1326 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1327 packet->tcp_header_len / 4);
1328 } else {
1329 /* Enable CRC and Pad Insertion */
1330 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1331
1332 /* Enable HW CSUM */
1333 if (csum)
1334 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1335 CIC, 0x3);
1336
1337 /* Set the total length to be transmitted */
1338 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1339 packet->length);
1340 }
1341
1342 for (i = ring->cur - start_index + 1; i < packet->rdesc_count; i++) {
1343 ring->cur++;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001344 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001345 rdesc = rdata->rdesc;
1346
1347 /* Update buffer address */
1348 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1349 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1350
1351 /* Update the buffer length */
1352 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1353 rdata->skb_dma_len);
1354
1355 /* Set IC bit based on Tx coalescing settings */
1356 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1357 if (tx_coalesce && (!tx_frames ||
1358 (++ring->coalesce_count % tx_frames)))
1359 /* Clear IC bit */
1360 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1361
1362 /* Set OWN bit */
1363 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1364
1365 /* Mark it as NORMAL descriptor */
1366 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1367
1368 /* Enable HW CSUM */
1369 if (csum)
1370 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1371 CIC, 0x3);
1372 }
1373
1374 /* Set LAST bit for the last descriptor */
1375 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1376
1377 /* In case the Tx DMA engine is running, make sure everything
1378 * is written to the descriptor(s) before setting the OWN bit
1379 * for the first descriptor
1380 */
1381 wmb();
1382
1383 /* Set OWN bit for the first descriptor */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001384 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001385 rdesc = rdata->rdesc;
1386 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1387
1388#ifdef XGMAC_ENABLE_TX_DESC_DUMP
1389 xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
1390#endif
1391
1392 /* Make sure ownership is written to the descriptor */
1393 wmb();
1394
1395 /* Issue a poll command to Tx DMA by writing address
1396 * of next immediate free descriptor */
1397 ring->cur++;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001398 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001399 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1400 lower_32_bits(rdata->rdesc_dma));
1401
1402 /* Start the Tx coalescing timer */
1403 if (tx_coalesce && !channel->tx_timer_active) {
1404 channel->tx_timer_active = 1;
1405 hrtimer_start(&channel->tx_timer,
1406 ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
1407 HRTIMER_MODE_REL);
1408 }
1409
1410 DBGPR(" %s: descriptors %u to %u written\n",
1411 channel->name, start_index & (ring->rdesc_count - 1),
1412 (ring->cur - 1) & (ring->rdesc_count - 1));
1413
1414 DBGPR("<--xgbe_pre_xmit\n");
1415}
1416
1417static int xgbe_dev_read(struct xgbe_channel *channel)
1418{
1419 struct xgbe_ring *ring = channel->rx_ring;
1420 struct xgbe_ring_data *rdata;
1421 struct xgbe_ring_desc *rdesc;
1422 struct xgbe_packet_data *packet = &ring->packet_data;
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001423 struct net_device *netdev = channel->pdata->netdev;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001424 unsigned int err, etlt;
1425
1426 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1427
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001428 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001429 rdesc = rdata->rdesc;
1430
1431 /* Check for data availability */
1432 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1433 return 1;
1434
1435#ifdef XGMAC_ENABLE_RX_DESC_DUMP
1436 xgbe_dump_rx_desc(ring, rdesc, ring->cur);
1437#endif
1438
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001439 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1440 /* Timestamp Context Descriptor */
1441 xgbe_get_rx_tstamp(packet, rdesc);
1442
1443 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1444 CONTEXT, 1);
1445 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1446 CONTEXT_NEXT, 0);
1447 return 0;
1448 }
1449
1450 /* Normal Descriptor, be sure Context Descriptor bit is off */
1451 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1452
1453 /* Indicate if a Context Descriptor is next */
1454 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1455 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1456 CONTEXT_NEXT, 1);
1457
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001458 /* Get the packet length */
1459 rdata->len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
1460
1461 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1462 /* Not all the data has been transferred for this packet */
1463 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1464 INCOMPLETE, 1);
1465 return 0;
1466 }
1467
1468 /* This is the last of the data for this packet */
1469 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1470 INCOMPLETE, 0);
1471
1472 /* Set checksum done indicator as appropriate */
1473 if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
1474 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1475 CSUM_DONE, 1);
1476
1477 /* Check for errors (only valid in last descriptor) */
1478 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1479 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1480 DBGPR(" err=%u, etlt=%#x\n", err, etlt);
1481
1482 if (!err || (err && !etlt)) {
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001483 if ((etlt == 0x09) &&
1484 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001485 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1486 VLAN_CTAG, 1);
1487 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1488 RX_NORMAL_DESC0,
1489 OVT);
1490 DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
1491 }
1492 } else {
1493 if ((etlt == 0x05) || (etlt == 0x06))
1494 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1495 CSUM_DONE, 0);
1496 else
1497 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1498 FRAME, 1);
1499 }
1500
1501 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1502 ring->cur & (ring->rdesc_count - 1), ring->cur);
1503
1504 return 0;
1505}
1506
1507static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1508{
1509 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1510 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1511}
1512
1513static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1514{
1515 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1516 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1517}
1518
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001519static int xgbe_enable_int(struct xgbe_channel *channel,
1520 enum xgbe_int int_id)
1521{
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001522 unsigned int dma_ch_ier;
1523
1524 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1525
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001526 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001527 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001528 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001529 break;
1530 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001531 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001532 break;
1533 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001534 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001535 break;
1536 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001537 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001538 break;
1539 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001540 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001541 break;
1542 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001543 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1544 break;
1545 case XGMAC_INT_DMA_CH_SR_TI_RI:
1546 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1547 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001548 break;
1549 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001550 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001551 break;
1552 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001553 dma_ch_ier |= channel->saved_ier;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001554 break;
1555 default:
1556 return -1;
1557 }
1558
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001559 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1560
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001561 return 0;
1562}
1563
1564static int xgbe_disable_int(struct xgbe_channel *channel,
1565 enum xgbe_int int_id)
1566{
1567 unsigned int dma_ch_ier;
1568
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001569 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1570
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001571 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001572 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001573 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001574 break;
1575 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001576 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001577 break;
1578 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001579 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001580 break;
1581 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001582 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001583 break;
1584 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001585 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001586 break;
1587 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001588 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1589 break;
1590 case XGMAC_INT_DMA_CH_SR_TI_RI:
1591 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1592 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001593 break;
1594 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001595 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001596 break;
1597 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001598 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001599 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001600 break;
1601 default:
1602 return -1;
1603 }
1604
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001605 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1606
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001607 return 0;
1608}
1609
1610static int xgbe_exit(struct xgbe_prv_data *pdata)
1611{
1612 unsigned int count = 2000;
1613
1614 DBGPR("-->xgbe_exit\n");
1615
1616 /* Issue a software reset */
1617 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1618 usleep_range(10, 15);
1619
1620 /* Poll Until Poll Condition */
1621 while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1622 usleep_range(500, 600);
1623
1624 if (!count)
1625 return -EBUSY;
1626
1627 DBGPR("<--xgbe_exit\n");
1628
1629 return 0;
1630}
1631
1632static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1633{
1634 unsigned int i, count;
1635
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -05001636 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
1637 return 0;
1638
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001639 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001640 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1641
1642 /* Poll Until Poll Condition */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001643 for (i = 0; i < pdata->tx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001644 count = 2000;
1645 while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
1646 MTL_Q_TQOMR, FTQ))
1647 usleep_range(500, 600);
1648
1649 if (!count)
1650 return -EBUSY;
1651 }
1652
1653 return 0;
1654}
1655
1656static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1657{
1658 /* Set enhanced addressing mode */
1659 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1660
1661 /* Set the System Bus mode */
1662 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001663 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001664}
1665
1666static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1667{
1668 unsigned int arcache, awcache;
1669
1670 arcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001671 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
1672 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
1673 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
1674 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
1675 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
1676 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001677 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1678
1679 awcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001680 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
1681 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
1682 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
1683 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
1684 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
1685 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
1686 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
1687 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001688 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1689}
1690
1691static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1692{
1693 unsigned int i;
1694
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001695 /* Set Tx to weighted round robin scheduling algorithm */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001696 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1697
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001698 /* Set Tx traffic classes to use WRR algorithm with equal weights */
1699 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1700 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1701 MTL_TSA_ETS);
1702 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
1703 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001704
1705 /* Set Rx to strict priority algorithm */
1706 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1707}
1708
1709static unsigned int xgbe_calculate_per_queue_fifo(unsigned long fifo_size,
1710 unsigned char queue_count)
1711{
1712 unsigned int q_fifo_size = 0;
1713 enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1714
1715 /* Calculate Tx/Rx fifo share per queue */
1716 switch (fifo_size) {
1717 case 0:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001718 q_fifo_size = XGBE_FIFO_SIZE_B(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001719 break;
1720 case 1:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001721 q_fifo_size = XGBE_FIFO_SIZE_B(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001722 break;
1723 case 2:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001724 q_fifo_size = XGBE_FIFO_SIZE_B(512);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001725 break;
1726 case 3:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001727 q_fifo_size = XGBE_FIFO_SIZE_KB(1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001728 break;
1729 case 4:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001730 q_fifo_size = XGBE_FIFO_SIZE_KB(2);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001731 break;
1732 case 5:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001733 q_fifo_size = XGBE_FIFO_SIZE_KB(4);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001734 break;
1735 case 6:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001736 q_fifo_size = XGBE_FIFO_SIZE_KB(8);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001737 break;
1738 case 7:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001739 q_fifo_size = XGBE_FIFO_SIZE_KB(16);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001740 break;
1741 case 8:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001742 q_fifo_size = XGBE_FIFO_SIZE_KB(32);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001743 break;
1744 case 9:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001745 q_fifo_size = XGBE_FIFO_SIZE_KB(64);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001746 break;
1747 case 10:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001748 q_fifo_size = XGBE_FIFO_SIZE_KB(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001749 break;
1750 case 11:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001751 q_fifo_size = XGBE_FIFO_SIZE_KB(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001752 break;
1753 }
1754 q_fifo_size = q_fifo_size / queue_count;
1755
1756 /* Set the queue fifo size programmable value */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001757 if (q_fifo_size >= XGBE_FIFO_SIZE_KB(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001758 p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001759 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(128))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001760 p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001761 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(64))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001762 p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001763 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(32))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001764 p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001765 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(16))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001766 p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001767 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(8))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001768 p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001769 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(4))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001770 p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001771 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(2))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001772 p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001773 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(1))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001774 p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001775 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(512))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001776 p_fifo = XGMAC_MTL_FIFO_SIZE_512;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001777 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001778 p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1779
1780 return p_fifo;
1781}
1782
1783static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
1784{
1785 enum xgbe_mtl_fifo_size fifo_size;
1786 unsigned int i;
1787
1788 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001789 pdata->tx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001790
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001791 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001792 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
1793
1794 netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001795 pdata->tx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001796}
1797
1798static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
1799{
1800 enum xgbe_mtl_fifo_size fifo_size;
1801 unsigned int i;
1802
1803 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001804 pdata->rx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001805
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001806 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001807 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
1808
1809 netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001810 pdata->rx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001811}
1812
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001813static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001814{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001815 unsigned int qptc, qptc_extra, queue;
1816 unsigned int prio_queues;
1817 unsigned int ppq, ppq_extra, prio;
1818 unsigned int mask;
1819 unsigned int i, j, reg, reg_val;
1820
1821 /* Map the MTL Tx Queues to Traffic Classes
1822 * Note: Tx Queues >= Traffic Classes
1823 */
1824 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
1825 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
1826
1827 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
1828 for (j = 0; j < qptc; j++) {
1829 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
1830 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1831 Q2TCMAP, i);
1832 pdata->q2tc_map[queue++] = i;
1833 }
1834
1835 if (i < qptc_extra) {
1836 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
1837 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1838 Q2TCMAP, i);
1839 pdata->q2tc_map[queue++] = i;
1840 }
1841 }
1842
1843 /* Map the 8 VLAN priority values to available MTL Rx queues */
1844 prio_queues = min_t(unsigned int, IEEE_8021QAZ_MAX_TCS,
1845 pdata->rx_q_count);
1846 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
1847 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
1848
1849 reg = MAC_RQC2R;
1850 reg_val = 0;
1851 for (i = 0, prio = 0; i < prio_queues;) {
1852 mask = 0;
1853 for (j = 0; j < ppq; j++) {
1854 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
1855 mask |= (1 << prio);
1856 pdata->prio2q_map[prio++] = i;
1857 }
1858
1859 if (i < ppq_extra) {
1860 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
1861 mask |= (1 << prio);
1862 pdata->prio2q_map[prio++] = i;
1863 }
1864
1865 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
1866
1867 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
1868 continue;
1869
1870 XGMAC_IOWRITE(pdata, reg, reg_val);
1871 reg += MAC_RQC2_INC;
1872 reg_val = 0;
1873 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001874
1875 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
1876 reg = MTL_RQDCM0R;
1877 reg_val = 0;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001878 for (i = 0; i < pdata->rx_q_count;) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001879 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
1880
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001881 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001882 continue;
1883
1884 XGMAC_IOWRITE(pdata, reg, reg_val);
1885
1886 reg += MTL_RQDCM_INC;
1887 reg_val = 0;
1888 }
1889}
1890
1891static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
1892{
1893 unsigned int i;
1894
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001895 for (i = 0; i < pdata->rx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001896 /* Activate flow control when less than 4k left in fifo */
1897 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
1898
1899 /* De-activate flow control when more than 6k left in fifo */
1900 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
1901 }
1902}
1903
1904static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
1905{
1906 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05001907
1908 /* Filtering is done using perfect filtering and hash filtering */
1909 if (pdata->hw_feat.hash_table_size) {
1910 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
1911 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
1912 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
1913 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001914}
1915
1916static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
1917{
1918 unsigned int val;
1919
1920 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
1921
1922 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1923}
1924
1925static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
1926{
1927 if (pdata->netdev->features & NETIF_F_RXCSUM)
1928 xgbe_enable_rx_csum(pdata);
1929 else
1930 xgbe_disable_rx_csum(pdata);
1931}
1932
1933static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
1934{
Lendacky, Thomas6e5eed02014-06-24 16:19:12 -05001935 /* Indicate that VLAN Tx CTAGs come from context descriptors */
1936 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
1937 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
1938
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05001939 /* Set the current VLAN Hash Table register value */
1940 xgbe_update_vlan_hash_table(pdata);
1941
1942 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
1943 xgbe_enable_rx_vlan_filtering(pdata);
1944 else
1945 xgbe_disable_rx_vlan_filtering(pdata);
1946
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001947 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
1948 xgbe_enable_rx_vlan_stripping(pdata);
1949 else
1950 xgbe_disable_rx_vlan_stripping(pdata);
1951}
1952
1953static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
1954{
1955 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1956 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
1957
1958 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
1959 stats->txoctetcount_gb +=
1960 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
1961
1962 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
1963 stats->txframecount_gb +=
1964 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
1965
1966 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
1967 stats->txbroadcastframes_g +=
1968 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1969
1970 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
1971 stats->txmulticastframes_g +=
1972 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1973
1974 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
1975 stats->tx64octets_gb +=
1976 XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
1977
1978 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
1979 stats->tx65to127octets_gb +=
1980 XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
1981
1982 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
1983 stats->tx128to255octets_gb +=
1984 XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
1985
1986 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
1987 stats->tx256to511octets_gb +=
1988 XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
1989
1990 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
1991 stats->tx512to1023octets_gb +=
1992 XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1993
1994 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
1995 stats->tx1024tomaxoctets_gb +=
1996 XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1997
1998 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
1999 stats->txunicastframes_gb +=
2000 XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
2001
2002 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2003 stats->txmulticastframes_gb +=
2004 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
2005
2006 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2007 stats->txbroadcastframes_g +=
2008 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
2009
2010 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2011 stats->txunderflowerror +=
2012 XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
2013
2014 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2015 stats->txoctetcount_g +=
2016 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
2017
2018 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2019 stats->txframecount_g +=
2020 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
2021
2022 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2023 stats->txpauseframes +=
2024 XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
2025
2026 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2027 stats->txvlanframes_g +=
2028 XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
2029}
2030
2031static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2032{
2033 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2034 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2035
2036 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2037 stats->rxframecount_gb +=
2038 XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
2039
2040 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2041 stats->rxoctetcount_gb +=
2042 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
2043
2044 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2045 stats->rxoctetcount_g +=
2046 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
2047
2048 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2049 stats->rxbroadcastframes_g +=
2050 XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
2051
2052 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2053 stats->rxmulticastframes_g +=
2054 XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
2055
2056 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2057 stats->rxcrcerror +=
2058 XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
2059
2060 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2061 stats->rxrunterror +=
2062 XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
2063
2064 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2065 stats->rxjabbererror +=
2066 XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
2067
2068 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
2069 stats->rxundersize_g +=
2070 XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
2071
2072 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
2073 stats->rxoversize_g +=
2074 XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
2075
2076 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
2077 stats->rx64octets_gb +=
2078 XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
2079
2080 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
2081 stats->rx65to127octets_gb +=
2082 XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
2083
2084 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
2085 stats->rx128to255octets_gb +=
2086 XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
2087
2088 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
2089 stats->rx256to511octets_gb +=
2090 XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
2091
2092 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
2093 stats->rx512to1023octets_gb +=
2094 XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
2095
2096 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
2097 stats->rx1024tomaxoctets_gb +=
2098 XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
2099
2100 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
2101 stats->rxunicastframes_g +=
2102 XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
2103
2104 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
2105 stats->rxlengtherror +=
2106 XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
2107
2108 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
2109 stats->rxoutofrangetype +=
2110 XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
2111
2112 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
2113 stats->rxpauseframes +=
2114 XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
2115
2116 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
2117 stats->rxfifooverflow +=
2118 XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
2119
2120 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
2121 stats->rxvlanframes_gb +=
2122 XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
2123
2124 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
2125 stats->rxwatchdogerror +=
2126 XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
2127}
2128
2129static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
2130{
2131 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2132
2133 /* Freeze counters */
2134 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
2135
2136 stats->txoctetcount_gb +=
2137 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
2138
2139 stats->txframecount_gb +=
2140 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
2141
2142 stats->txbroadcastframes_g +=
2143 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
2144
2145 stats->txmulticastframes_g +=
2146 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
2147
2148 stats->tx64octets_gb +=
2149 XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
2150
2151 stats->tx65to127octets_gb +=
2152 XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
2153
2154 stats->tx128to255octets_gb +=
2155 XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
2156
2157 stats->tx256to511octets_gb +=
2158 XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
2159
2160 stats->tx512to1023octets_gb +=
2161 XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
2162
2163 stats->tx1024tomaxoctets_gb +=
2164 XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
2165
2166 stats->txunicastframes_gb +=
2167 XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
2168
2169 stats->txmulticastframes_gb +=
2170 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
2171
2172 stats->txbroadcastframes_g +=
2173 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
2174
2175 stats->txunderflowerror +=
2176 XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
2177
2178 stats->txoctetcount_g +=
2179 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
2180
2181 stats->txframecount_g +=
2182 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
2183
2184 stats->txpauseframes +=
2185 XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
2186
2187 stats->txvlanframes_g +=
2188 XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
2189
2190 stats->rxframecount_gb +=
2191 XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
2192
2193 stats->rxoctetcount_gb +=
2194 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
2195
2196 stats->rxoctetcount_g +=
2197 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
2198
2199 stats->rxbroadcastframes_g +=
2200 XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
2201
2202 stats->rxmulticastframes_g +=
2203 XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
2204
2205 stats->rxcrcerror +=
2206 XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
2207
2208 stats->rxrunterror +=
2209 XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
2210
2211 stats->rxjabbererror +=
2212 XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
2213
2214 stats->rxundersize_g +=
2215 XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
2216
2217 stats->rxoversize_g +=
2218 XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
2219
2220 stats->rx64octets_gb +=
2221 XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
2222
2223 stats->rx65to127octets_gb +=
2224 XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
2225
2226 stats->rx128to255octets_gb +=
2227 XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
2228
2229 stats->rx256to511octets_gb +=
2230 XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
2231
2232 stats->rx512to1023octets_gb +=
2233 XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
2234
2235 stats->rx1024tomaxoctets_gb +=
2236 XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
2237
2238 stats->rxunicastframes_g +=
2239 XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
2240
2241 stats->rxlengtherror +=
2242 XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
2243
2244 stats->rxoutofrangetype +=
2245 XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
2246
2247 stats->rxpauseframes +=
2248 XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
2249
2250 stats->rxfifooverflow +=
2251 XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
2252
2253 stats->rxvlanframes_gb +=
2254 XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
2255
2256 stats->rxwatchdogerror +=
2257 XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
2258
2259 /* Un-freeze counters */
2260 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
2261}
2262
2263static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
2264{
2265 /* Set counters to reset on read */
2266 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
2267
2268 /* Reset the counters */
2269 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
2270}
2271
2272static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
2273{
2274 struct xgbe_channel *channel;
2275 unsigned int i;
2276
2277 /* Enable each Tx DMA channel */
2278 channel = pdata->channel;
2279 for (i = 0; i < pdata->channel_count; i++, channel++) {
2280 if (!channel->tx_ring)
2281 break;
2282
2283 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2284 }
2285
2286 /* Enable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002287 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002288 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
2289 MTL_Q_ENABLED);
2290
2291 /* Enable MAC Tx */
2292 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2293}
2294
2295static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
2296{
2297 struct xgbe_channel *channel;
2298 unsigned int i;
2299
2300 /* Disable MAC Tx */
2301 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2302
2303 /* Disable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002304 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002305 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
2306
2307 /* Disable each Tx DMA channel */
2308 channel = pdata->channel;
2309 for (i = 0; i < pdata->channel_count; i++, channel++) {
2310 if (!channel->tx_ring)
2311 break;
2312
2313 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2314 }
2315}
2316
2317static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
2318{
2319 struct xgbe_channel *channel;
2320 unsigned int reg_val, i;
2321
2322 /* Enable each Rx DMA channel */
2323 channel = pdata->channel;
2324 for (i = 0; i < pdata->channel_count; i++, channel++) {
2325 if (!channel->rx_ring)
2326 break;
2327
2328 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2329 }
2330
2331 /* Enable each Rx queue */
2332 reg_val = 0;
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002333 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002334 reg_val |= (0x02 << (i << 1));
2335 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
2336
2337 /* Enable MAC Rx */
2338 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
2339 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
2340 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
2341 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
2342}
2343
2344static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
2345{
2346 struct xgbe_channel *channel;
2347 unsigned int i;
2348
2349 /* Disable MAC Rx */
2350 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
2351 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
2352 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
2353 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
2354
2355 /* Disable each Rx queue */
2356 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
2357
2358 /* Disable each Rx DMA channel */
2359 channel = pdata->channel;
2360 for (i = 0; i < pdata->channel_count; i++, channel++) {
2361 if (!channel->rx_ring)
2362 break;
2363
2364 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2365 }
2366}
2367
2368static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
2369{
2370 struct xgbe_channel *channel;
2371 unsigned int i;
2372
2373 /* Enable each Tx DMA channel */
2374 channel = pdata->channel;
2375 for (i = 0; i < pdata->channel_count; i++, channel++) {
2376 if (!channel->tx_ring)
2377 break;
2378
2379 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2380 }
2381
2382 /* Enable MAC Tx */
2383 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2384}
2385
2386static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
2387{
2388 struct xgbe_channel *channel;
2389 unsigned int i;
2390
2391 /* Disable MAC Tx */
2392 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2393
2394 /* Disable each Tx DMA channel */
2395 channel = pdata->channel;
2396 for (i = 0; i < pdata->channel_count; i++, channel++) {
2397 if (!channel->tx_ring)
2398 break;
2399
2400 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2401 }
2402}
2403
2404static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2405{
2406 struct xgbe_channel *channel;
2407 unsigned int i;
2408
2409 /* Enable each Rx DMA channel */
2410 channel = pdata->channel;
2411 for (i = 0; i < pdata->channel_count; i++, channel++) {
2412 if (!channel->rx_ring)
2413 break;
2414
2415 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2416 }
2417}
2418
2419static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2420{
2421 struct xgbe_channel *channel;
2422 unsigned int i;
2423
2424 /* Disable each Rx DMA channel */
2425 channel = pdata->channel;
2426 for (i = 0; i < pdata->channel_count; i++, channel++) {
2427 if (!channel->rx_ring)
2428 break;
2429
2430 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2431 }
2432}
2433
2434static int xgbe_init(struct xgbe_prv_data *pdata)
2435{
2436 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2437 int ret;
2438
2439 DBGPR("-->xgbe_init\n");
2440
2441 /* Flush Tx queues */
2442 ret = xgbe_flush_tx_queues(pdata);
2443 if (ret)
2444 return ret;
2445
2446 /*
2447 * Initialize DMA related features
2448 */
2449 xgbe_config_dma_bus(pdata);
2450 xgbe_config_dma_cache(pdata);
2451 xgbe_config_osp_mode(pdata);
2452 xgbe_config_pblx8(pdata);
2453 xgbe_config_tx_pbl_val(pdata);
2454 xgbe_config_rx_pbl_val(pdata);
2455 xgbe_config_rx_coalesce(pdata);
2456 xgbe_config_tx_coalesce(pdata);
2457 xgbe_config_rx_buffer_size(pdata);
2458 xgbe_config_tso_mode(pdata);
2459 desc_if->wrapper_tx_desc_init(pdata);
2460 desc_if->wrapper_rx_desc_init(pdata);
2461 xgbe_enable_dma_interrupts(pdata);
2462
2463 /*
2464 * Initialize MTL related features
2465 */
2466 xgbe_config_mtl_mode(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002467 xgbe_config_queue_mapping(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002468 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2469 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2470 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2471 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2472 xgbe_config_tx_fifo_size(pdata);
2473 xgbe_config_rx_fifo_size(pdata);
2474 xgbe_config_flow_control_threshold(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002475 /*TODO: Error Packet and undersized good Packet forwarding enable
2476 (FEP and FUP)
2477 */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002478 xgbe_config_dcb_tc(pdata);
2479 xgbe_config_dcb_pfc(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002480 xgbe_enable_mtl_interrupts(pdata);
2481
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002482 /*
2483 * Initialize MAC related features
2484 */
2485 xgbe_config_mac_address(pdata);
2486 xgbe_config_jumbo_enable(pdata);
2487 xgbe_config_flow_control(pdata);
2488 xgbe_config_checksum_offload(pdata);
2489 xgbe_config_vlan_support(pdata);
2490 xgbe_config_mmc(pdata);
2491 xgbe_enable_mac_interrupts(pdata);
2492
2493 DBGPR("<--xgbe_init\n");
2494
2495 return 0;
2496}
2497
2498void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2499{
2500 DBGPR("-->xgbe_init_function_ptrs\n");
2501
2502 hw_if->tx_complete = xgbe_tx_complete;
2503
2504 hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
2505 hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05002506 hw_if->add_mac_addresses = xgbe_add_mac_addresses;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002507 hw_if->set_mac_address = xgbe_set_mac_address;
2508
2509 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2510 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2511
2512 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2513 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002514 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
2515 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
2516 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002517
2518 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2519 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2520
2521 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2522 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2523 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2524
2525 hw_if->enable_tx = xgbe_enable_tx;
2526 hw_if->disable_tx = xgbe_disable_tx;
2527 hw_if->enable_rx = xgbe_enable_rx;
2528 hw_if->disable_rx = xgbe_disable_rx;
2529
2530 hw_if->powerup_tx = xgbe_powerup_tx;
2531 hw_if->powerdown_tx = xgbe_powerdown_tx;
2532 hw_if->powerup_rx = xgbe_powerup_rx;
2533 hw_if->powerdown_rx = xgbe_powerdown_rx;
2534
2535 hw_if->pre_xmit = xgbe_pre_xmit;
2536 hw_if->dev_read = xgbe_dev_read;
2537 hw_if->enable_int = xgbe_enable_int;
2538 hw_if->disable_int = xgbe_disable_int;
2539 hw_if->init = xgbe_init;
2540 hw_if->exit = xgbe_exit;
2541
2542 /* Descriptor related Sequences have to be initialized here */
2543 hw_if->tx_desc_init = xgbe_tx_desc_init;
2544 hw_if->rx_desc_init = xgbe_rx_desc_init;
2545 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2546 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2547 hw_if->is_last_desc = xgbe_is_last_desc;
2548 hw_if->is_context_desc = xgbe_is_context_desc;
2549
2550 /* For FLOW ctrl */
2551 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2552 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2553
2554 /* For RX coalescing */
2555 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2556 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2557 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2558 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2559
2560 /* For RX and TX threshold config */
2561 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2562 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2563
2564 /* For RX and TX Store and Forward Mode config */
2565 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2566 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2567
2568 /* For TX DMA Operating on Second Frame config */
2569 hw_if->config_osp_mode = xgbe_config_osp_mode;
2570
2571 /* For RX and TX PBL config */
2572 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2573 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2574 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2575 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2576 hw_if->config_pblx8 = xgbe_config_pblx8;
2577
2578 /* For MMC statistics support */
2579 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2580 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2581 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2582
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05002583 /* For PTP config */
2584 hw_if->config_tstamp = xgbe_config_tstamp;
2585 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
2586 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
2587 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
2588 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
2589
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002590 /* For Data Center Bridging config */
2591 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
2592 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
2593
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002594 DBGPR("<--xgbe_init_function_ptrs\n");
2595}