blob: ac3d319ffab31eb397cf3f5a06ed0c0ff3688f5a [file] [log] [blame]
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001/*
2 * AMD 10Gb Ethernet driver
3 *
4 * This file is available to you under your choice of the following two
5 * licenses:
6 *
7 * License 1: GPLv2
8 *
9 * Copyright (c) 2014 Advanced Micro Devices, Inc.
10 *
11 * This file is free software; you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * This file incorporates work covered by the following copyright and
25 * permission notice:
26 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
27 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28 * Inc. unless otherwise expressly agreed to in writing between Synopsys
29 * and you.
30 *
31 * The Software IS NOT an item of Licensed Software or Licensed Product
32 * under any End User Software License Agreement or Agreement for Licensed
33 * Product with Synopsys or any supplement thereto. Permission is hereby
34 * granted, free of charge, to any person obtaining a copy of this software
35 * annotated with this license and the Software, to deal in the Software
36 * without restriction, including without limitation the rights to use,
37 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 * of the Software, and to permit persons to whom the Software is furnished
39 * to do so, subject to the following conditions:
40 *
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
43 *
44 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54 * THE POSSIBILITY OF SUCH DAMAGE.
55 *
56 *
57 * License 2: Modified BSD
58 *
59 * Copyright (c) 2014 Advanced Micro Devices, Inc.
60 * All rights reserved.
61 *
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions are met:
64 * * Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 * * Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
69 * * Neither the name of Advanced Micro Devices, Inc. nor the
70 * names of its contributors may be used to endorse or promote products
71 * derived from this software without specific prior written permission.
72 *
73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 *
84 * This file incorporates work covered by the following copyright and
85 * permission notice:
86 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
87 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88 * Inc. unless otherwise expressly agreed to in writing between Synopsys
89 * and you.
90 *
91 * The Software IS NOT an item of Licensed Software or Licensed Product
92 * under any End User Software License Agreement or Agreement for Licensed
93 * Product with Synopsys or any supplement thereto. Permission is hereby
94 * granted, free of charge, to any person obtaining a copy of this software
95 * annotated with this license and the Software, to deal in the Software
96 * without restriction, including without limitation the rights to use,
97 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98 * of the Software, and to permit persons to whom the Software is furnished
99 * to do so, subject to the following conditions:
100 *
101 * The above copyright notice and this permission notice shall be included
102 * in all copies or substantial portions of the Software.
103 *
104 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114 * THE POSSIBILITY OF SUCH DAMAGE.
115 */
116
117#include <linux/phy.h>
118#include <linux/clk.h>
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500119#include <linux/bitrev.h>
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500120#include <linux/crc32.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500121
122#include "xgbe.h"
123#include "xgbe-common.h"
124
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500125static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
126 unsigned int usec)
127{
128 unsigned long rate;
129 unsigned int ret;
130
131 DBGPR("-->xgbe_usec_to_riwt\n");
132
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500133 rate = clk_get_rate(pdata->sysclk);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500134
135 /*
136 * Convert the input usec value to the watchdog timer value. Each
137 * watchdog timer value is equivalent to 256 clock cycles.
138 * Calculate the required value as:
139 * ( usec * ( system_clock_mhz / 10^6 ) / 256
140 */
141 ret = (usec * (rate / 1000000)) / 256;
142
143 DBGPR("<--xgbe_usec_to_riwt\n");
144
145 return ret;
146}
147
148static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
149 unsigned int riwt)
150{
151 unsigned long rate;
152 unsigned int ret;
153
154 DBGPR("-->xgbe_riwt_to_usec\n");
155
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500156 rate = clk_get_rate(pdata->sysclk);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500157
158 /*
159 * Convert the input watchdog timer value to the usec value. Each
160 * watchdog timer value is equivalent to 256 clock cycles.
161 * Calculate the required value as:
162 * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
163 */
164 ret = (riwt * 256) / (rate / 1000000);
165
166 DBGPR("<--xgbe_riwt_to_usec\n");
167
168 return ret;
169}
170
171static int xgbe_config_pblx8(struct xgbe_prv_data *pdata)
172{
173 struct xgbe_channel *channel;
174 unsigned int i;
175
176 channel = pdata->channel;
177 for (i = 0; i < pdata->channel_count; i++, channel++)
178 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8,
179 pdata->pblx8);
180
181 return 0;
182}
183
184static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata)
185{
186 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL);
187}
188
189static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata)
190{
191 struct xgbe_channel *channel;
192 unsigned int i;
193
194 channel = pdata->channel;
195 for (i = 0; i < pdata->channel_count; i++, channel++) {
196 if (!channel->tx_ring)
197 break;
198
199 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL,
200 pdata->tx_pbl);
201 }
202
203 return 0;
204}
205
206static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata)
207{
208 return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL);
209}
210
211static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata)
212{
213 struct xgbe_channel *channel;
214 unsigned int i;
215
216 channel = pdata->channel;
217 for (i = 0; i < pdata->channel_count; i++, channel++) {
218 if (!channel->rx_ring)
219 break;
220
221 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL,
222 pdata->rx_pbl);
223 }
224
225 return 0;
226}
227
228static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
229{
230 struct xgbe_channel *channel;
231 unsigned int i;
232
233 channel = pdata->channel;
234 for (i = 0; i < pdata->channel_count; i++, channel++) {
235 if (!channel->tx_ring)
236 break;
237
238 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP,
239 pdata->tx_osp_mode);
240 }
241
242 return 0;
243}
244
245static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
246{
247 unsigned int i;
248
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500249 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500250 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
251
252 return 0;
253}
254
255static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
256{
257 unsigned int i;
258
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500259 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500260 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
261
262 return 0;
263}
264
265static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
266 unsigned int val)
267{
268 unsigned int i;
269
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500270 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500271 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
272
273 return 0;
274}
275
276static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
277 unsigned int val)
278{
279 unsigned int i;
280
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500281 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500282 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
283
284 return 0;
285}
286
287static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
288{
289 struct xgbe_channel *channel;
290 unsigned int i;
291
292 channel = pdata->channel;
293 for (i = 0; i < pdata->channel_count; i++, channel++) {
294 if (!channel->rx_ring)
295 break;
296
297 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT,
298 pdata->rx_riwt);
299 }
300
301 return 0;
302}
303
304static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
305{
306 return 0;
307}
308
309static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
310{
311 struct xgbe_channel *channel;
312 unsigned int i;
313
314 channel = pdata->channel;
315 for (i = 0; i < pdata->channel_count; i++, channel++) {
316 if (!channel->rx_ring)
317 break;
318
319 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ,
320 pdata->rx_buf_size);
321 }
322}
323
324static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
325{
326 struct xgbe_channel *channel;
327 unsigned int i;
328
329 channel = pdata->channel;
330 for (i = 0; i < pdata->channel_count; i++, channel++) {
331 if (!channel->tx_ring)
332 break;
333
334 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1);
335 }
336}
337
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600338static void xgbe_config_sph_mode(struct xgbe_prv_data *pdata)
339{
340 struct xgbe_channel *channel;
341 unsigned int i;
342
343 channel = pdata->channel;
344 for (i = 0; i < pdata->channel_count; i++, channel++) {
345 if (!channel->rx_ring)
346 break;
347
348 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, SPH, 1);
349 }
350
351 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE);
352}
353
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500354static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
355{
356 unsigned int max_q_count, q_count;
357 unsigned int reg, reg_val;
358 unsigned int i;
359
360 /* Clear MTL flow control */
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500361 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500362 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
363
364 /* Clear MAC flow control */
365 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas9fc69af2014-08-29 13:17:08 -0500366 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500367 reg = MAC_Q0TFCR;
368 for (i = 0; i < q_count; i++) {
369 reg_val = XGMAC_IOREAD(pdata, reg);
370 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
371 XGMAC_IOWRITE(pdata, reg, reg_val);
372
373 reg += MAC_QTFCR_INC;
374 }
375
376 return 0;
377}
378
379static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
380{
381 unsigned int max_q_count, q_count;
382 unsigned int reg, reg_val;
383 unsigned int i;
384
385 /* Set MTL flow control */
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500386 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500387 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 1);
388
389 /* Set MAC flow control */
390 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
Lendacky, Thomas9fc69af2014-08-29 13:17:08 -0500391 q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500392 reg = MAC_Q0TFCR;
393 for (i = 0; i < q_count; i++) {
394 reg_val = XGMAC_IOREAD(pdata, reg);
395
396 /* Enable transmit flow control */
397 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
398 /* Set pause time */
399 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
400
401 XGMAC_IOWRITE(pdata, reg, reg_val);
402
403 reg += MAC_QTFCR_INC;
404 }
405
406 return 0;
407}
408
409static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
410{
411 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
412
413 return 0;
414}
415
416static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
417{
418 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
419
420 return 0;
421}
422
423static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
424{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500425 struct ieee_pfc *pfc = pdata->pfc;
426
427 if (pdata->tx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500428 xgbe_enable_tx_flow_control(pdata);
429 else
430 xgbe_disable_tx_flow_control(pdata);
431
432 return 0;
433}
434
435static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
436{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500437 struct ieee_pfc *pfc = pdata->pfc;
438
439 if (pdata->rx_pause || (pfc && pfc->pfc_en))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500440 xgbe_enable_rx_flow_control(pdata);
441 else
442 xgbe_disable_rx_flow_control(pdata);
443
444 return 0;
445}
446
447static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
448{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500449 struct ieee_pfc *pfc = pdata->pfc;
450
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500451 xgbe_config_tx_flow_control(pdata);
452 xgbe_config_rx_flow_control(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500453
454 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
455 (pfc && pfc->pfc_en) ? 1 : 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500456}
457
458static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
459{
460 struct xgbe_channel *channel;
461 unsigned int dma_ch_isr, dma_ch_ier;
462 unsigned int i;
463
464 channel = pdata->channel;
465 for (i = 0; i < pdata->channel_count; i++, channel++) {
466 /* Clear all the interrupts which are set */
467 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
468 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
469
470 /* Clear all interrupt enable bits */
471 dma_ch_ier = 0;
472
473 /* Enable following interrupts
474 * NIE - Normal Interrupt Summary Enable
475 * AIE - Abnormal Interrupt Summary Enable
476 * FBEE - Fatal Bus Error Enable
477 */
478 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
479 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
480 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
481
482 if (channel->tx_ring) {
483 /* Enable the following Tx interrupts
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600484 * TIE - Transmit Interrupt Enable (unless using
485 * per channel interrupts)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500486 */
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600487 if (!pdata->per_channel_irq)
488 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500489 }
490 if (channel->rx_ring) {
491 /* Enable following Rx interrupts
492 * RBUE - Receive Buffer Unavailable Enable
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600493 * RIE - Receive Interrupt Enable (unless using
494 * per channel interrupts)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500495 */
496 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600497 if (!pdata->per_channel_irq)
498 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500499 }
500
501 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
502 }
503}
504
505static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
506{
507 unsigned int mtl_q_isr;
508 unsigned int q_count, i;
509
510 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
511 for (i = 0; i < q_count; i++) {
512 /* Clear all the interrupts which are set */
513 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
514 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
515
516 /* No MTL interrupts to be enabled */
Lendacky, Thomas91f87342014-07-02 13:04:34 -0500517 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500518 }
519}
520
521static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
522{
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500523 unsigned int mac_ier = 0;
524
525 /* Enable Timestamp interrupt */
526 XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
527
528 XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500529
530 /* Enable all counter interrupts */
Lendacky, Thomasa3ba7c92014-09-05 18:02:36 -0500531 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
532 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500533}
534
535static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
536{
537 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
538
539 return 0;
540}
541
542static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
543{
544 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
545
546 return 0;
547}
548
549static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
550{
551 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
552
553 return 0;
554}
555
556static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
557 unsigned int enable)
558{
559 unsigned int val = enable ? 1 : 0;
560
561 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
562 return 0;
563
564 DBGPR(" %s promiscuous mode\n", enable ? "entering" : "leaving");
565 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
566
567 return 0;
568}
569
570static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
571 unsigned int enable)
572{
573 unsigned int val = enable ? 1 : 0;
574
575 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
576 return 0;
577
578 DBGPR(" %s allmulti mode\n", enable ? "entering" : "leaving");
579 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
580
581 return 0;
582}
583
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500584static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
585 struct netdev_hw_addr *ha, unsigned int *mac_reg)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500586{
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500587 unsigned int mac_addr_hi, mac_addr_lo;
588 u8 *mac_addr;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500589
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500590 mac_addr_lo = 0;
591 mac_addr_hi = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500592
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500593 if (ha) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500594 mac_addr = (u8 *)&mac_addr_lo;
595 mac_addr[0] = ha->addr[0];
596 mac_addr[1] = ha->addr[1];
597 mac_addr[2] = ha->addr[2];
598 mac_addr[3] = ha->addr[3];
599 mac_addr = (u8 *)&mac_addr_hi;
600 mac_addr[0] = ha->addr[4];
601 mac_addr[1] = ha->addr[5];
602
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500603 DBGPR(" adding mac address %pM at 0x%04x\n", ha->addr,
604 *mac_reg);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500605
606 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500607 }
608
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500609 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
610 *mac_reg += MAC_MACA_INC;
611 XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
612 *mac_reg += MAC_MACA_INC;
613}
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500614
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500615static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
616{
617 struct net_device *netdev = pdata->netdev;
618 struct netdev_hw_addr *ha;
619 unsigned int mac_reg;
620 unsigned int addn_macs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500621
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500622 mac_reg = MAC_MACA1HR;
623 addn_macs = pdata->hw_feat.addn_mac;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500624
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500625 if (netdev_uc_count(netdev) > addn_macs) {
626 xgbe_set_promiscuous_mode(pdata, 1);
627 } else {
628 netdev_for_each_uc_addr(ha, netdev) {
629 xgbe_set_mac_reg(pdata, ha, &mac_reg);
630 addn_macs--;
631 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500632
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500633 if (netdev_mc_count(netdev) > addn_macs) {
634 xgbe_set_all_multicast_mode(pdata, 1);
635 } else {
636 netdev_for_each_mc_addr(ha, netdev) {
637 xgbe_set_mac_reg(pdata, ha, &mac_reg);
638 addn_macs--;
639 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500640 }
641 }
642
643 /* Clear remaining additional MAC address entries */
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500644 while (addn_macs--)
645 xgbe_set_mac_reg(pdata, NULL, &mac_reg);
646}
647
648static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
649{
650 struct net_device *netdev = pdata->netdev;
651 struct netdev_hw_addr *ha;
652 unsigned int hash_reg;
653 unsigned int hash_table_shift, hash_table_count;
654 u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
655 u32 crc;
656 unsigned int i;
657
658 hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
659 hash_table_count = pdata->hw_feat.hash_table_size / 32;
660 memset(hash_table, 0, sizeof(hash_table));
661
662 /* Build the MAC Hash Table register values */
663 netdev_for_each_uc_addr(ha, netdev) {
664 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
665 crc >>= hash_table_shift;
666 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500667 }
668
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500669 netdev_for_each_mc_addr(ha, netdev) {
670 crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
671 crc >>= hash_table_shift;
672 hash_table[crc >> 5] |= (1 << (crc & 0x1f));
673 }
674
675 /* Set the MAC Hash Table registers */
676 hash_reg = MAC_HTR0;
677 for (i = 0; i < hash_table_count; i++) {
678 XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
679 hash_reg += MAC_HTR_INC;
680 }
681}
682
683static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
684{
685 if (pdata->hw_feat.hash_table_size)
686 xgbe_set_mac_hash_table(pdata);
687 else
688 xgbe_set_mac_addn_addrs(pdata);
689
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500690 return 0;
691}
692
693static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
694{
695 unsigned int mac_addr_hi, mac_addr_lo;
696
697 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
698 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
699 (addr[1] << 8) | (addr[0] << 0);
700
701 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
702 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
703
704 return 0;
705}
706
707static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
708 int mmd_reg)
709{
710 unsigned int mmd_address;
711 int mmd_data;
712
713 if (mmd_reg & MII_ADDR_C45)
714 mmd_address = mmd_reg & ~MII_ADDR_C45;
715 else
716 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
717
718 /* The PCS registers are accessed using mmio. The underlying APB3
719 * management interface uses indirect addressing to access the MMD
720 * register sets. This requires accessing of the PCS register in two
721 * phases, an address phase and a data phase.
722 *
723 * The mmio interface is based on 32-bit offsets and values. All
724 * register offsets must therefore be adjusted by left shifting the
725 * offset 2 bits and reading 32 bits of data.
726 */
727 mutex_lock(&pdata->xpcs_mutex);
728 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
729 mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
730 mutex_unlock(&pdata->xpcs_mutex);
731
732 return mmd_data;
733}
734
735static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
736 int mmd_reg, int mmd_data)
737{
738 unsigned int mmd_address;
739
740 if (mmd_reg & MII_ADDR_C45)
741 mmd_address = mmd_reg & ~MII_ADDR_C45;
742 else
743 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
744
745 /* The PCS registers are accessed using mmio. The underlying APB3
746 * management interface uses indirect addressing to access the MMD
747 * register sets. This requires accessing of the PCS register in two
748 * phases, an address phase and a data phase.
749 *
750 * The mmio interface is based on 32-bit offsets and values. All
751 * register offsets must therefore be adjusted by left shifting the
752 * offset 2 bits and reading 32 bits of data.
753 */
754 mutex_lock(&pdata->xpcs_mutex);
755 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
756 XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
757 mutex_unlock(&pdata->xpcs_mutex);
758}
759
760static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
761{
762 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
763}
764
765static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
766{
767 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
768
769 return 0;
770}
771
772static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
773{
774 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
775
776 return 0;
777}
778
779static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
780{
781 /* Put the VLAN tag in the Rx descriptor */
782 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
783
784 /* Don't check the VLAN type */
785 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
786
787 /* Check only C-TAG (0x8100) packets */
788 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
789
790 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
791 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
792
793 /* Enable VLAN tag stripping */
794 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
795
796 return 0;
797}
798
799static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
800{
801 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
802
803 return 0;
804}
805
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500806static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
807{
808 /* Enable VLAN filtering */
809 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
810
811 /* Enable VLAN Hash Table filtering */
812 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
813
814 /* Disable VLAN tag inverse matching */
815 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
816
817 /* Only filter on the lower 12-bits of the VLAN tag */
818 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
819
820 /* In order for the VLAN Hash Table filtering to be effective,
821 * the VLAN tag identifier in the VLAN Tag Register must not
822 * be zero. Set the VLAN tag identifier to "1" to enable the
823 * VLAN Hash Table filtering. This implies that a VLAN tag of
824 * 1 will always pass filtering.
825 */
826 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
827
828 return 0;
829}
830
831static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
832{
833 /* Disable VLAN filtering */
834 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
835
836 return 0;
837}
838
839#ifndef CRCPOLY_LE
840#define CRCPOLY_LE 0xedb88320
841#endif
842static u32 xgbe_vid_crc32_le(__le16 vid_le)
843{
844 u32 poly = CRCPOLY_LE;
845 u32 crc = ~0;
846 u32 temp = 0;
847 unsigned char *data = (unsigned char *)&vid_le;
848 unsigned char data_byte = 0;
849 int i, bits;
850
851 bits = get_bitmask_order(VLAN_VID_MASK);
852 for (i = 0; i < bits; i++) {
853 if ((i % 8) == 0)
854 data_byte = data[i / 8];
855
856 temp = ((crc & 1) ^ data_byte) & 1;
857 crc >>= 1;
858 data_byte >>= 1;
859
860 if (temp)
861 crc ^= poly;
862 }
863
864 return crc;
865}
866
867static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
868{
869 u32 crc;
870 u16 vid;
871 __le16 vid_le;
872 u16 vlan_hash_table = 0;
873
874 /* Generate the VLAN Hash Table value */
875 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
876 /* Get the CRC32 value of the VLAN ID */
877 vid_le = cpu_to_le16(vid);
878 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
879
880 vlan_hash_table |= (1 << crc);
881 }
882
883 /* Set the VLAN Hash Table filtering register */
884 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
885
886 return 0;
887}
888
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500889static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
890{
891 struct xgbe_ring_desc *rdesc = rdata->rdesc;
892
893 /* Reset the Tx descriptor
894 * Set buffer 1 (lo) address to zero
895 * Set buffer 1 (hi) address to zero
896 * Reset all other control bits (IC, TTSE, B2L & B1L)
897 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
898 */
899 rdesc->desc0 = 0;
900 rdesc->desc1 = 0;
901 rdesc->desc2 = 0;
902 rdesc->desc3 = 0;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600903
904 /* Make sure ownership is written to the descriptor */
905 wmb();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500906}
907
908static void xgbe_tx_desc_init(struct xgbe_channel *channel)
909{
910 struct xgbe_ring *ring = channel->tx_ring;
911 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500912 int i;
913 int start_index = ring->cur;
914
915 DBGPR("-->tx_desc_init\n");
916
917 /* Initialze all descriptors */
918 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500919 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500920
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600921 /* Initialize Tx descriptor */
922 xgbe_tx_desc_reset(rdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500923 }
924
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500925 /* Update the total number of Tx descriptors */
926 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
927
928 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500929 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500930 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
931 upper_32_bits(rdata->rdesc_dma));
932 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
933 lower_32_bits(rdata->rdesc_dma));
934
935 DBGPR("<--tx_desc_init\n");
936}
937
938static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
939{
940 struct xgbe_ring_desc *rdesc = rdata->rdesc;
941
942 /* Reset the Rx descriptor
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600943 * Set buffer 1 (lo) address to header dma address (lo)
944 * Set buffer 1 (hi) address to header dma address (hi)
945 * Set buffer 2 (lo) address to buffer dma address (lo)
946 * Set buffer 2 (hi) address to buffer dma address (hi) and
947 * set control bits OWN and INTE
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500948 */
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600949 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->rx_hdr.dma));
950 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->rx_hdr.dma));
951 rdesc->desc2 = cpu_to_le32(lower_32_bits(rdata->rx_buf.dma));
952 rdesc->desc3 = cpu_to_le32(upper_32_bits(rdata->rx_buf.dma));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500953
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600954 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE,
955 rdata->interrupt ? 1 : 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500956
957 /* Since the Rx DMA engine is likely running, make sure everything
958 * is written to the descriptor(s) before setting the OWN bit
959 * for the descriptor
960 */
961 wmb();
962
963 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
964
965 /* Make sure ownership is written to the descriptor */
966 wmb();
967}
968
969static void xgbe_rx_desc_init(struct xgbe_channel *channel)
970{
971 struct xgbe_prv_data *pdata = channel->pdata;
972 struct xgbe_ring *ring = channel->rx_ring;
973 struct xgbe_ring_data *rdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500974 unsigned int start_index = ring->cur;
975 unsigned int rx_coalesce, rx_frames;
976 unsigned int i;
977
978 DBGPR("-->rx_desc_init\n");
979
980 rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
981 rx_frames = pdata->rx_frames;
982
983 /* Initialize all descriptors */
984 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500985 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500986
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600987 /* Set interrupt on completion bit as appropriate */
988 if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames)))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500989 rdata->interrupt = 0;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600990 else
991 rdata->interrupt = 1;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500992
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600993 /* Initialize Rx descriptor */
994 xgbe_rx_desc_reset(rdata);
995 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500996
997 /* Update the total number of Rx descriptors */
998 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
999
1000 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001001 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001002 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
1003 upper_32_bits(rdata->rdesc_dma));
1004 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
1005 lower_32_bits(rdata->rdesc_dma));
1006
1007 /* Update the Rx Descriptor Tail Pointer */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001008 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001009 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
1010 lower_32_bits(rdata->rdesc_dma));
1011
1012 DBGPR("<--rx_desc_init\n");
1013}
1014
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001015static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
1016 unsigned int addend)
1017{
1018 /* Set the addend register value and tell the device */
1019 XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1020 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1021
1022 /* Wait for addend update to complete */
1023 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1024 udelay(5);
1025}
1026
1027static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
1028 unsigned int nsec)
1029{
1030 /* Set the time values and tell the device */
1031 XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1032 XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1033 XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1034
1035 /* Wait for time update to complete */
1036 while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1037 udelay(5);
1038}
1039
1040static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
1041{
1042 u64 nsec;
1043
1044 nsec = XGMAC_IOREAD(pdata, MAC_STSR);
1045 nsec *= NSEC_PER_SEC;
1046 nsec += XGMAC_IOREAD(pdata, MAC_STNR);
1047
1048 return nsec;
1049}
1050
1051static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
1052{
1053 unsigned int tx_snr;
1054 u64 nsec;
1055
1056 tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
1057 if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
1058 return 0;
1059
1060 nsec = XGMAC_IOREAD(pdata, MAC_TXSSR);
1061 nsec *= NSEC_PER_SEC;
1062 nsec += tx_snr;
1063
1064 return nsec;
1065}
1066
1067static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
1068 struct xgbe_ring_desc *rdesc)
1069{
1070 u64 nsec;
1071
1072 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
1073 !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
1074 nsec = le32_to_cpu(rdesc->desc1);
1075 nsec <<= 32;
1076 nsec |= le32_to_cpu(rdesc->desc0);
1077 if (nsec != 0xffffffffffffffffULL) {
1078 packet->rx_tstamp = nsec;
1079 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1080 RX_TSTAMP, 1);
1081 }
1082 }
1083}
1084
1085static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
1086 unsigned int mac_tscr)
1087{
1088 /* Set one nano-second accuracy */
1089 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1090
1091 /* Set fine timestamp update */
1092 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1093
1094 /* Overwrite earlier timestamps */
1095 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1096
1097 XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1098
1099 /* Exit if timestamping is not enabled */
1100 if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
1101 return 0;
1102
1103 /* Initialize time registers */
1104 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
1105 XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
1106 xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1107 xgbe_set_tstamp_time(pdata, 0, 0);
1108
1109 /* Initialize the timecounter */
1110 timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
1111 ktime_to_ns(ktime_get_real()));
1112
1113 return 0;
1114}
1115
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001116static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
1117{
1118 struct ieee_ets *ets = pdata->ets;
1119 unsigned int total_weight, min_weight, weight;
1120 unsigned int i;
1121
1122 if (!ets)
1123 return;
1124
1125 /* Set Tx to deficit weighted round robin scheduling algorithm (when
1126 * traffic class is using ETS algorithm)
1127 */
1128 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
1129
1130 /* Set Traffic Class algorithms */
1131 total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
1132 min_weight = total_weight / 100;
1133 if (!min_weight)
1134 min_weight = 1;
1135
1136 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1137 switch (ets->tc_tsa[i]) {
1138 case IEEE_8021QAZ_TSA_STRICT:
1139 DBGPR(" TC%u using SP\n", i);
1140 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1141 MTL_TSA_SP);
1142 break;
1143 case IEEE_8021QAZ_TSA_ETS:
1144 weight = total_weight * ets->tc_tx_bw[i] / 100;
1145 weight = clamp(weight, min_weight, total_weight);
1146
1147 DBGPR(" TC%u using DWRR (weight %u)\n", i, weight);
1148 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1149 MTL_TSA_ETS);
1150 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
1151 weight);
1152 break;
1153 }
1154 }
1155}
1156
1157static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
1158{
1159 struct ieee_pfc *pfc = pdata->pfc;
1160 struct ieee_ets *ets = pdata->ets;
1161 unsigned int mask, reg, reg_val;
1162 unsigned int tc, prio;
1163
1164 if (!pfc || !ets)
1165 return;
1166
1167 for (tc = 0; tc < pdata->hw_feat.tc_cnt; tc++) {
1168 mask = 0;
1169 for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
1170 if ((pfc->pfc_en & (1 << prio)) &&
1171 (ets->prio_tc[prio] == tc))
1172 mask |= (1 << prio);
1173 }
1174 mask &= 0xff;
1175
1176 DBGPR(" TC%u PFC mask=%#x\n", tc, mask);
1177 reg = MTL_TCPM0R + (MTL_TCPM_INC * (tc / MTL_TCPM_TC_PER_REG));
1178 reg_val = XGMAC_IOREAD(pdata, reg);
1179
1180 reg_val &= ~(0xff << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1181 reg_val |= (mask << ((tc % MTL_TCPM_TC_PER_REG) << 3));
1182
1183 XGMAC_IOWRITE(pdata, reg, reg_val);
1184 }
1185
1186 xgbe_config_flow_control(pdata);
1187}
1188
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001189static void xgbe_dev_xmit(struct xgbe_channel *channel)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001190{
1191 struct xgbe_prv_data *pdata = channel->pdata;
1192 struct xgbe_ring *ring = channel->tx_ring;
1193 struct xgbe_ring_data *rdata;
1194 struct xgbe_ring_desc *rdesc;
1195 struct xgbe_packet_data *packet = &ring->packet_data;
1196 unsigned int csum, tso, vlan;
1197 unsigned int tso_context, vlan_context;
1198 unsigned int tx_coalesce, tx_frames;
1199 int start_index = ring->cur;
1200 int i;
1201
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001202 DBGPR("-->xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001203
1204 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1205 CSUM_ENABLE);
1206 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1207 TSO_ENABLE);
1208 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1209 VLAN_CTAG);
1210
1211 if (tso && (packet->mss != ring->tx.cur_mss))
1212 tso_context = 1;
1213 else
1214 tso_context = 0;
1215
1216 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1217 vlan_context = 1;
1218 else
1219 vlan_context = 0;
1220
1221 tx_coalesce = (pdata->tx_usecs || pdata->tx_frames) ? 1 : 0;
1222 tx_frames = pdata->tx_frames;
1223 if (tx_coalesce && !channel->tx_timer_active)
1224 ring->coalesce_count = 0;
1225
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001226 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001227 rdesc = rdata->rdesc;
1228
1229 /* Create a context descriptor if this is a TSO packet */
1230 if (tso_context || vlan_context) {
1231 if (tso_context) {
1232 DBGPR(" TSO context descriptor, mss=%u\n",
1233 packet->mss);
1234
1235 /* Set the MSS size */
1236 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1237 MSS, packet->mss);
1238
1239 /* Mark it as a CONTEXT descriptor */
1240 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1241 CTXT, 1);
1242
1243 /* Indicate this descriptor contains the MSS */
1244 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1245 TCMSSV, 1);
1246
1247 ring->tx.cur_mss = packet->mss;
1248 }
1249
1250 if (vlan_context) {
1251 DBGPR(" VLAN context descriptor, ctag=%u\n",
1252 packet->vlan_ctag);
1253
1254 /* Mark it as a CONTEXT descriptor */
1255 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1256 CTXT, 1);
1257
1258 /* Set the VLAN tag */
1259 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1260 VT, packet->vlan_ctag);
1261
1262 /* Indicate this descriptor contains the VLAN tag */
1263 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1264 VLTV, 1);
1265
1266 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1267 }
1268
1269 ring->cur++;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001270 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001271 rdesc = rdata->rdesc;
1272 }
1273
1274 /* Update buffer address (for TSO this is the header) */
1275 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1276 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1277
1278 /* Update the buffer length */
1279 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1280 rdata->skb_dma_len);
1281
1282 /* VLAN tag insertion check */
1283 if (vlan)
1284 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1285 TX_NORMAL_DESC2_VLAN_INSERT);
1286
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001287 /* Timestamp enablement check */
1288 if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
1289 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
1290
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001291 /* Set IC bit based on Tx coalescing settings */
1292 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1293 if (tx_coalesce && (!tx_frames ||
1294 (++ring->coalesce_count % tx_frames)))
1295 /* Clear IC bit */
1296 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1297
1298 /* Mark it as First Descriptor */
1299 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1300
1301 /* Mark it as a NORMAL descriptor */
1302 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1303
1304 /* Set OWN bit if not the first descriptor */
1305 if (ring->cur != start_index)
1306 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1307
1308 if (tso) {
1309 /* Enable TSO */
1310 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1311 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1312 packet->tcp_payload_len);
1313 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1314 packet->tcp_header_len / 4);
1315 } else {
1316 /* Enable CRC and Pad Insertion */
1317 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1318
1319 /* Enable HW CSUM */
1320 if (csum)
1321 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1322 CIC, 0x3);
1323
1324 /* Set the total length to be transmitted */
1325 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1326 packet->length);
1327 }
1328
1329 for (i = ring->cur - start_index + 1; i < packet->rdesc_count; i++) {
1330 ring->cur++;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001331 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001332 rdesc = rdata->rdesc;
1333
1334 /* Update buffer address */
1335 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1336 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1337
1338 /* Update the buffer length */
1339 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1340 rdata->skb_dma_len);
1341
1342 /* Set IC bit based on Tx coalescing settings */
1343 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1344 if (tx_coalesce && (!tx_frames ||
1345 (++ring->coalesce_count % tx_frames)))
1346 /* Clear IC bit */
1347 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1348
1349 /* Set OWN bit */
1350 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1351
1352 /* Mark it as NORMAL descriptor */
1353 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1354
1355 /* Enable HW CSUM */
1356 if (csum)
1357 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1358 CIC, 0x3);
1359 }
1360
1361 /* Set LAST bit for the last descriptor */
1362 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1363
1364 /* In case the Tx DMA engine is running, make sure everything
1365 * is written to the descriptor(s) before setting the OWN bit
1366 * for the first descriptor
1367 */
1368 wmb();
1369
1370 /* Set OWN bit for the first descriptor */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001371 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001372 rdesc = rdata->rdesc;
1373 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1374
1375#ifdef XGMAC_ENABLE_TX_DESC_DUMP
1376 xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
1377#endif
1378
1379 /* Make sure ownership is written to the descriptor */
1380 wmb();
1381
1382 /* Issue a poll command to Tx DMA by writing address
1383 * of next immediate free descriptor */
1384 ring->cur++;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001385 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001386 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1387 lower_32_bits(rdata->rdesc_dma));
1388
1389 /* Start the Tx coalescing timer */
1390 if (tx_coalesce && !channel->tx_timer_active) {
1391 channel->tx_timer_active = 1;
1392 hrtimer_start(&channel->tx_timer,
1393 ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
1394 HRTIMER_MODE_REL);
1395 }
1396
1397 DBGPR(" %s: descriptors %u to %u written\n",
1398 channel->name, start_index & (ring->rdesc_count - 1),
1399 (ring->cur - 1) & (ring->rdesc_count - 1));
1400
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06001401 DBGPR("<--xgbe_dev_xmit\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001402}
1403
1404static int xgbe_dev_read(struct xgbe_channel *channel)
1405{
1406 struct xgbe_ring *ring = channel->rx_ring;
1407 struct xgbe_ring_data *rdata;
1408 struct xgbe_ring_desc *rdesc;
1409 struct xgbe_packet_data *packet = &ring->packet_data;
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001410 struct net_device *netdev = channel->pdata->netdev;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001411 unsigned int err, etlt;
1412
1413 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1414
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001415 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001416 rdesc = rdata->rdesc;
1417
1418 /* Check for data availability */
1419 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1420 return 1;
1421
1422#ifdef XGMAC_ENABLE_RX_DESC_DUMP
1423 xgbe_dump_rx_desc(ring, rdesc, ring->cur);
1424#endif
1425
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001426 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
1427 /* Timestamp Context Descriptor */
1428 xgbe_get_rx_tstamp(packet, rdesc);
1429
1430 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1431 CONTEXT, 1);
1432 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1433 CONTEXT_NEXT, 0);
1434 return 0;
1435 }
1436
1437 /* Normal Descriptor, be sure Context Descriptor bit is off */
1438 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
1439
1440 /* Indicate if a Context Descriptor is next */
1441 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
1442 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1443 CONTEXT_NEXT, 1);
1444
Lendacky, Thomas174fd252014-11-04 16:06:50 -06001445 /* Get the header length */
1446 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD))
1447 rdata->hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2,
1448 RX_NORMAL_DESC2, HL);
1449
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001450 /* Get the packet length */
1451 rdata->len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
1452
1453 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1454 /* Not all the data has been transferred for this packet */
1455 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1456 INCOMPLETE, 1);
1457 return 0;
1458 }
1459
1460 /* This is the last of the data for this packet */
1461 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1462 INCOMPLETE, 0);
1463
1464 /* Set checksum done indicator as appropriate */
1465 if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
1466 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1467 CSUM_DONE, 1);
1468
1469 /* Check for errors (only valid in last descriptor) */
1470 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1471 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1472 DBGPR(" err=%u, etlt=%#x\n", err, etlt);
1473
1474 if (!err || (err && !etlt)) {
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001475 if ((etlt == 0x09) &&
1476 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001477 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1478 VLAN_CTAG, 1);
1479 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1480 RX_NORMAL_DESC0,
1481 OVT);
1482 DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
1483 }
1484 } else {
1485 if ((etlt == 0x05) || (etlt == 0x06))
1486 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1487 CSUM_DONE, 0);
1488 else
1489 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1490 FRAME, 1);
1491 }
1492
1493 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1494 ring->cur & (ring->rdesc_count - 1), ring->cur);
1495
1496 return 0;
1497}
1498
1499static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1500{
1501 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1502 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1503}
1504
1505static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1506{
1507 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1508 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1509}
1510
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001511static int xgbe_enable_int(struct xgbe_channel *channel,
1512 enum xgbe_int int_id)
1513{
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001514 unsigned int dma_ch_ier;
1515
1516 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1517
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001518 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001519 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001520 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001521 break;
1522 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001523 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001524 break;
1525 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001526 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001527 break;
1528 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001529 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001530 break;
1531 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001532 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001533 break;
1534 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001535 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
1536 break;
1537 case XGMAC_INT_DMA_CH_SR_TI_RI:
1538 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
1539 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001540 break;
1541 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001542 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001543 break;
1544 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001545 dma_ch_ier |= channel->saved_ier;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001546 break;
1547 default:
1548 return -1;
1549 }
1550
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001551 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1552
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001553 return 0;
1554}
1555
1556static int xgbe_disable_int(struct xgbe_channel *channel,
1557 enum xgbe_int int_id)
1558{
1559 unsigned int dma_ch_ier;
1560
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001561 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1562
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001563 switch (int_id) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001564 case XGMAC_INT_DMA_CH_SR_TI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001565 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001566 break;
1567 case XGMAC_INT_DMA_CH_SR_TPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001568 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001569 break;
1570 case XGMAC_INT_DMA_CH_SR_TBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001571 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001572 break;
1573 case XGMAC_INT_DMA_CH_SR_RI:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001574 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001575 break;
1576 case XGMAC_INT_DMA_CH_SR_RBU:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001577 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001578 break;
1579 case XGMAC_INT_DMA_CH_SR_RPS:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001580 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
1581 break;
1582 case XGMAC_INT_DMA_CH_SR_TI_RI:
1583 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
1584 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001585 break;
1586 case XGMAC_INT_DMA_CH_SR_FBE:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001587 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001588 break;
1589 case XGMAC_INT_DMA_ALL:
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001590 channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001591 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001592 break;
1593 default:
1594 return -1;
1595 }
1596
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001597 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1598
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001599 return 0;
1600}
1601
1602static int xgbe_exit(struct xgbe_prv_data *pdata)
1603{
1604 unsigned int count = 2000;
1605
1606 DBGPR("-->xgbe_exit\n");
1607
1608 /* Issue a software reset */
1609 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1610 usleep_range(10, 15);
1611
1612 /* Poll Until Poll Condition */
1613 while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1614 usleep_range(500, 600);
1615
1616 if (!count)
1617 return -EBUSY;
1618
1619 DBGPR("<--xgbe_exit\n");
1620
1621 return 0;
1622}
1623
1624static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1625{
1626 unsigned int i, count;
1627
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -05001628 if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
1629 return 0;
1630
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001631 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001632 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1633
1634 /* Poll Until Poll Condition */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001635 for (i = 0; i < pdata->tx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001636 count = 2000;
1637 while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
1638 MTL_Q_TQOMR, FTQ))
1639 usleep_range(500, 600);
1640
1641 if (!count)
1642 return -EBUSY;
1643 }
1644
1645 return 0;
1646}
1647
1648static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1649{
1650 /* Set enhanced addressing mode */
1651 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1652
1653 /* Set the System Bus mode */
1654 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -05001655 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001656}
1657
1658static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1659{
1660 unsigned int arcache, awcache;
1661
1662 arcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001663 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
1664 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
1665 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
1666 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
1667 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
1668 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001669 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1670
1671 awcache = 0;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -05001672 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
1673 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
1674 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
1675 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
1676 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
1677 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
1678 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
1679 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001680 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1681}
1682
1683static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1684{
1685 unsigned int i;
1686
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001687 /* Set Tx to weighted round robin scheduling algorithm */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001688 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1689
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001690 /* Set Tx traffic classes to use WRR algorithm with equal weights */
1691 for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
1692 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
1693 MTL_TSA_ETS);
1694 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
1695 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001696
1697 /* Set Rx to strict priority algorithm */
1698 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1699}
1700
Lendacky, Thomasf076f452014-08-29 13:16:56 -05001701static unsigned int xgbe_calculate_per_queue_fifo(unsigned int fifo_size,
1702 unsigned int queue_count)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001703{
1704 unsigned int q_fifo_size = 0;
1705 enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1706
1707 /* Calculate Tx/Rx fifo share per queue */
1708 switch (fifo_size) {
1709 case 0:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001710 q_fifo_size = XGBE_FIFO_SIZE_B(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001711 break;
1712 case 1:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001713 q_fifo_size = XGBE_FIFO_SIZE_B(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001714 break;
1715 case 2:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001716 q_fifo_size = XGBE_FIFO_SIZE_B(512);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001717 break;
1718 case 3:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001719 q_fifo_size = XGBE_FIFO_SIZE_KB(1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001720 break;
1721 case 4:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001722 q_fifo_size = XGBE_FIFO_SIZE_KB(2);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001723 break;
1724 case 5:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001725 q_fifo_size = XGBE_FIFO_SIZE_KB(4);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001726 break;
1727 case 6:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001728 q_fifo_size = XGBE_FIFO_SIZE_KB(8);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001729 break;
1730 case 7:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001731 q_fifo_size = XGBE_FIFO_SIZE_KB(16);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001732 break;
1733 case 8:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001734 q_fifo_size = XGBE_FIFO_SIZE_KB(32);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001735 break;
1736 case 9:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001737 q_fifo_size = XGBE_FIFO_SIZE_KB(64);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001738 break;
1739 case 10:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001740 q_fifo_size = XGBE_FIFO_SIZE_KB(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001741 break;
1742 case 11:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001743 q_fifo_size = XGBE_FIFO_SIZE_KB(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001744 break;
1745 }
Lendacky, Thomasf076f452014-08-29 13:16:56 -05001746
1747 /* The configured value is not the actual amount of fifo RAM */
1748 q_fifo_size = min_t(unsigned int, XGBE_FIFO_MAX, q_fifo_size);
1749
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001750 q_fifo_size = q_fifo_size / queue_count;
1751
1752 /* Set the queue fifo size programmable value */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001753 if (q_fifo_size >= XGBE_FIFO_SIZE_KB(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001754 p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001755 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(128))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001756 p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001757 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(64))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001758 p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001759 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(32))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001760 p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001761 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(16))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001762 p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001763 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(8))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001764 p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001765 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(4))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001766 p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001767 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(2))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001768 p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001769 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(1))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001770 p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001771 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(512))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001772 p_fifo = XGMAC_MTL_FIFO_SIZE_512;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001773 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001774 p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1775
1776 return p_fifo;
1777}
1778
1779static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
1780{
1781 enum xgbe_mtl_fifo_size fifo_size;
1782 unsigned int i;
1783
1784 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001785 pdata->tx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001786
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001787 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001788 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
1789
1790 netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001791 pdata->tx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001792}
1793
1794static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
1795{
1796 enum xgbe_mtl_fifo_size fifo_size;
1797 unsigned int i;
1798
1799 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001800 pdata->rx_q_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001801
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001802 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001803 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
1804
1805 netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001806 pdata->rx_q_count, ((fifo_size + 1) * 256));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001807}
1808
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001809static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001810{
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001811 unsigned int qptc, qptc_extra, queue;
1812 unsigned int prio_queues;
1813 unsigned int ppq, ppq_extra, prio;
1814 unsigned int mask;
1815 unsigned int i, j, reg, reg_val;
1816
1817 /* Map the MTL Tx Queues to Traffic Classes
1818 * Note: Tx Queues >= Traffic Classes
1819 */
1820 qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
1821 qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
1822
1823 for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
1824 for (j = 0; j < qptc; j++) {
1825 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
1826 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1827 Q2TCMAP, i);
1828 pdata->q2tc_map[queue++] = i;
1829 }
1830
1831 if (i < qptc_extra) {
1832 DBGPR(" TXq%u mapped to TC%u\n", queue, i);
1833 XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
1834 Q2TCMAP, i);
1835 pdata->q2tc_map[queue++] = i;
1836 }
1837 }
1838
1839 /* Map the 8 VLAN priority values to available MTL Rx queues */
1840 prio_queues = min_t(unsigned int, IEEE_8021QAZ_MAX_TCS,
1841 pdata->rx_q_count);
1842 ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
1843 ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
1844
1845 reg = MAC_RQC2R;
1846 reg_val = 0;
1847 for (i = 0, prio = 0; i < prio_queues;) {
1848 mask = 0;
1849 for (j = 0; j < ppq; j++) {
1850 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
1851 mask |= (1 << prio);
1852 pdata->prio2q_map[prio++] = i;
1853 }
1854
1855 if (i < ppq_extra) {
1856 DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
1857 mask |= (1 << prio);
1858 pdata->prio2q_map[prio++] = i;
1859 }
1860
1861 reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
1862
1863 if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
1864 continue;
1865
1866 XGMAC_IOWRITE(pdata, reg, reg_val);
1867 reg += MAC_RQC2_INC;
1868 reg_val = 0;
1869 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001870
1871 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
1872 reg = MTL_RQDCM0R;
1873 reg_val = 0;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001874 for (i = 0; i < pdata->rx_q_count;) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001875 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
1876
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001877 if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001878 continue;
1879
1880 XGMAC_IOWRITE(pdata, reg, reg_val);
1881
1882 reg += MTL_RQDCM_INC;
1883 reg_val = 0;
1884 }
1885}
1886
1887static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
1888{
1889 unsigned int i;
1890
Lendacky, Thomas853eb162014-07-29 08:57:31 -05001891 for (i = 0; i < pdata->rx_q_count; i++) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001892 /* Activate flow control when less than 4k left in fifo */
1893 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
1894
1895 /* De-activate flow control when more than 6k left in fifo */
1896 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
1897 }
1898}
1899
1900static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
1901{
1902 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05001903
1904 /* Filtering is done using perfect filtering and hash filtering */
1905 if (pdata->hw_feat.hash_table_size) {
1906 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
1907 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
1908 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
1909 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001910}
1911
1912static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
1913{
1914 unsigned int val;
1915
1916 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
1917
1918 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1919}
1920
1921static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
1922{
1923 if (pdata->netdev->features & NETIF_F_RXCSUM)
1924 xgbe_enable_rx_csum(pdata);
1925 else
1926 xgbe_disable_rx_csum(pdata);
1927}
1928
1929static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
1930{
Lendacky, Thomas6e5eed02014-06-24 16:19:12 -05001931 /* Indicate that VLAN Tx CTAGs come from context descriptors */
1932 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
1933 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
1934
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05001935 /* Set the current VLAN Hash Table register value */
1936 xgbe_update_vlan_hash_table(pdata);
1937
1938 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
1939 xgbe_enable_rx_vlan_filtering(pdata);
1940 else
1941 xgbe_disable_rx_vlan_filtering(pdata);
1942
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001943 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
1944 xgbe_enable_rx_vlan_stripping(pdata);
1945 else
1946 xgbe_disable_rx_vlan_stripping(pdata);
1947}
1948
Lendacky, Thomas60265102014-09-05 18:02:30 -05001949static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
1950{
1951 bool read_hi;
1952 u64 val;
1953
1954 switch (reg_lo) {
1955 /* These registers are always 64 bit */
1956 case MMC_TXOCTETCOUNT_GB_LO:
1957 case MMC_TXOCTETCOUNT_G_LO:
1958 case MMC_RXOCTETCOUNT_GB_LO:
1959 case MMC_RXOCTETCOUNT_G_LO:
1960 read_hi = true;
1961 break;
1962
1963 default:
1964 read_hi = false;
1965 };
1966
1967 val = XGMAC_IOREAD(pdata, reg_lo);
1968
1969 if (read_hi)
1970 val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
1971
1972 return val;
1973}
1974
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001975static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
1976{
1977 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1978 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
1979
1980 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
1981 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05001982 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001983
1984 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
1985 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05001986 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001987
1988 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
1989 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05001990 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001991
1992 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
1993 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05001994 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001995
1996 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
1997 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05001998 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001999
2000 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
2001 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002002 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002003
2004 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
2005 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002006 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002007
2008 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
2009 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002010 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002011
2012 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
2013 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002014 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002015
2016 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
2017 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002018 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002019
2020 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
2021 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002022 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002023
2024 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
2025 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002026 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002027
2028 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
2029 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002030 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002031
2032 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
2033 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002034 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002035
2036 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
2037 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002038 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002039
2040 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
2041 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002042 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002043
2044 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
2045 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002046 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002047
2048 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
2049 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002050 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002051}
2052
2053static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
2054{
2055 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2056 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
2057
2058 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
2059 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002060 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002061
2062 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
2063 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002064 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002065
2066 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
2067 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002068 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002069
2070 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
2071 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002072 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002073
2074 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
2075 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002076 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002077
2078 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
2079 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002080 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002081
2082 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
2083 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002084 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002085
2086 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
2087 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002088 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002089
2090 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
2091 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002092 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002093
2094 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
2095 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002096 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002097
2098 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
2099 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002100 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002101
2102 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
2103 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002104 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002105
2106 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
2107 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002108 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002109
2110 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
2111 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002112 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002113
2114 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
2115 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002116 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002117
2118 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
2119 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002120 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002121
2122 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
2123 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002124 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002125
2126 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
2127 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002128 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002129
2130 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
2131 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002132 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002133
2134 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
2135 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002136 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002137
2138 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
2139 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002140 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002141
2142 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
2143 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002144 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002145
2146 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
2147 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002148 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002149}
2150
2151static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
2152{
2153 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
2154
2155 /* Freeze counters */
2156 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
2157
2158 stats->txoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002159 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002160
2161 stats->txframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002162 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002163
2164 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002165 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002166
2167 stats->txmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002168 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002169
2170 stats->tx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002171 xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002172
2173 stats->tx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002174 xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002175
2176 stats->tx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002177 xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002178
2179 stats->tx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002180 xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002181
2182 stats->tx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002183 xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002184
2185 stats->tx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002186 xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002187
2188 stats->txunicastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002189 xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002190
2191 stats->txmulticastframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002192 xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002193
2194 stats->txbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002195 xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002196
2197 stats->txunderflowerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002198 xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002199
2200 stats->txoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002201 xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002202
2203 stats->txframecount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002204 xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002205
2206 stats->txpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002207 xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002208
2209 stats->txvlanframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002210 xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002211
2212 stats->rxframecount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002213 xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002214
2215 stats->rxoctetcount_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002216 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002217
2218 stats->rxoctetcount_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002219 xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002220
2221 stats->rxbroadcastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002222 xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002223
2224 stats->rxmulticastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002225 xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002226
2227 stats->rxcrcerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002228 xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002229
2230 stats->rxrunterror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002231 xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002232
2233 stats->rxjabbererror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002234 xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002235
2236 stats->rxundersize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002237 xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002238
2239 stats->rxoversize_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002240 xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002241
2242 stats->rx64octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002243 xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002244
2245 stats->rx65to127octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002246 xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002247
2248 stats->rx128to255octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002249 xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002250
2251 stats->rx256to511octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002252 xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002253
2254 stats->rx512to1023octets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002255 xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002256
2257 stats->rx1024tomaxoctets_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002258 xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002259
2260 stats->rxunicastframes_g +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002261 xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002262
2263 stats->rxlengtherror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002264 xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002265
2266 stats->rxoutofrangetype +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002267 xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002268
2269 stats->rxpauseframes +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002270 xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002271
2272 stats->rxfifooverflow +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002273 xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002274
2275 stats->rxvlanframes_gb +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002276 xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002277
2278 stats->rxwatchdogerror +=
Lendacky, Thomas60265102014-09-05 18:02:30 -05002279 xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002280
2281 /* Un-freeze counters */
2282 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
2283}
2284
2285static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
2286{
2287 /* Set counters to reset on read */
2288 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
2289
2290 /* Reset the counters */
2291 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
2292}
2293
2294static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
2295{
2296 struct xgbe_channel *channel;
2297 unsigned int i;
2298
2299 /* Enable each Tx DMA channel */
2300 channel = pdata->channel;
2301 for (i = 0; i < pdata->channel_count; i++, channel++) {
2302 if (!channel->tx_ring)
2303 break;
2304
2305 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2306 }
2307
2308 /* Enable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002309 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002310 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
2311 MTL_Q_ENABLED);
2312
2313 /* Enable MAC Tx */
2314 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2315}
2316
2317static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
2318{
2319 struct xgbe_channel *channel;
2320 unsigned int i;
2321
2322 /* Disable MAC Tx */
2323 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2324
2325 /* Disable each Tx queue */
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002326 for (i = 0; i < pdata->tx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002327 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
2328
2329 /* Disable each Tx DMA channel */
2330 channel = pdata->channel;
2331 for (i = 0; i < pdata->channel_count; i++, channel++) {
2332 if (!channel->tx_ring)
2333 break;
2334
2335 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2336 }
2337}
2338
2339static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
2340{
2341 struct xgbe_channel *channel;
2342 unsigned int reg_val, i;
2343
2344 /* Enable each Rx DMA channel */
2345 channel = pdata->channel;
2346 for (i = 0; i < pdata->channel_count; i++, channel++) {
2347 if (!channel->rx_ring)
2348 break;
2349
2350 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2351 }
2352
2353 /* Enable each Rx queue */
2354 reg_val = 0;
Lendacky, Thomas853eb162014-07-29 08:57:31 -05002355 for (i = 0; i < pdata->rx_q_count; i++)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002356 reg_val |= (0x02 << (i << 1));
2357 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
2358
2359 /* Enable MAC Rx */
2360 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
2361 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
2362 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
2363 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
2364}
2365
2366static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
2367{
2368 struct xgbe_channel *channel;
2369 unsigned int i;
2370
2371 /* Disable MAC Rx */
2372 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
2373 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
2374 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
2375 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
2376
2377 /* Disable each Rx queue */
2378 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
2379
2380 /* Disable each Rx DMA channel */
2381 channel = pdata->channel;
2382 for (i = 0; i < pdata->channel_count; i++, channel++) {
2383 if (!channel->rx_ring)
2384 break;
2385
2386 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2387 }
2388}
2389
2390static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
2391{
2392 struct xgbe_channel *channel;
2393 unsigned int i;
2394
2395 /* Enable each Tx DMA channel */
2396 channel = pdata->channel;
2397 for (i = 0; i < pdata->channel_count; i++, channel++) {
2398 if (!channel->tx_ring)
2399 break;
2400
2401 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2402 }
2403
2404 /* Enable MAC Tx */
2405 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2406}
2407
2408static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
2409{
2410 struct xgbe_channel *channel;
2411 unsigned int i;
2412
2413 /* Disable MAC Tx */
2414 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2415
2416 /* Disable each Tx DMA channel */
2417 channel = pdata->channel;
2418 for (i = 0; i < pdata->channel_count; i++, channel++) {
2419 if (!channel->tx_ring)
2420 break;
2421
2422 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2423 }
2424}
2425
2426static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2427{
2428 struct xgbe_channel *channel;
2429 unsigned int i;
2430
2431 /* Enable each Rx DMA channel */
2432 channel = pdata->channel;
2433 for (i = 0; i < pdata->channel_count; i++, channel++) {
2434 if (!channel->rx_ring)
2435 break;
2436
2437 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2438 }
2439}
2440
2441static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2442{
2443 struct xgbe_channel *channel;
2444 unsigned int i;
2445
2446 /* Disable each Rx DMA channel */
2447 channel = pdata->channel;
2448 for (i = 0; i < pdata->channel_count; i++, channel++) {
2449 if (!channel->rx_ring)
2450 break;
2451
2452 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2453 }
2454}
2455
2456static int xgbe_init(struct xgbe_prv_data *pdata)
2457{
2458 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2459 int ret;
2460
2461 DBGPR("-->xgbe_init\n");
2462
2463 /* Flush Tx queues */
2464 ret = xgbe_flush_tx_queues(pdata);
2465 if (ret)
2466 return ret;
2467
2468 /*
2469 * Initialize DMA related features
2470 */
2471 xgbe_config_dma_bus(pdata);
2472 xgbe_config_dma_cache(pdata);
2473 xgbe_config_osp_mode(pdata);
2474 xgbe_config_pblx8(pdata);
2475 xgbe_config_tx_pbl_val(pdata);
2476 xgbe_config_rx_pbl_val(pdata);
2477 xgbe_config_rx_coalesce(pdata);
2478 xgbe_config_tx_coalesce(pdata);
2479 xgbe_config_rx_buffer_size(pdata);
2480 xgbe_config_tso_mode(pdata);
Lendacky, Thomas174fd252014-11-04 16:06:50 -06002481 xgbe_config_sph_mode(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002482 desc_if->wrapper_tx_desc_init(pdata);
2483 desc_if->wrapper_rx_desc_init(pdata);
2484 xgbe_enable_dma_interrupts(pdata);
2485
2486 /*
2487 * Initialize MTL related features
2488 */
2489 xgbe_config_mtl_mode(pdata);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002490 xgbe_config_queue_mapping(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002491 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2492 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2493 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2494 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2495 xgbe_config_tx_fifo_size(pdata);
2496 xgbe_config_rx_fifo_size(pdata);
2497 xgbe_config_flow_control_threshold(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002498 /*TODO: Error Packet and undersized good Packet forwarding enable
2499 (FEP and FUP)
2500 */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002501 xgbe_config_dcb_tc(pdata);
2502 xgbe_config_dcb_pfc(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002503 xgbe_enable_mtl_interrupts(pdata);
2504
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002505 /*
2506 * Initialize MAC related features
2507 */
2508 xgbe_config_mac_address(pdata);
2509 xgbe_config_jumbo_enable(pdata);
2510 xgbe_config_flow_control(pdata);
2511 xgbe_config_checksum_offload(pdata);
2512 xgbe_config_vlan_support(pdata);
2513 xgbe_config_mmc(pdata);
2514 xgbe_enable_mac_interrupts(pdata);
2515
2516 DBGPR("<--xgbe_init\n");
2517
2518 return 0;
2519}
2520
2521void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2522{
2523 DBGPR("-->xgbe_init_function_ptrs\n");
2524
2525 hw_if->tx_complete = xgbe_tx_complete;
2526
2527 hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
2528 hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -05002529 hw_if->add_mac_addresses = xgbe_add_mac_addresses;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002530 hw_if->set_mac_address = xgbe_set_mac_address;
2531
2532 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2533 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2534
2535 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2536 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002537 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
2538 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
2539 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002540
2541 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2542 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2543
2544 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2545 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2546 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2547
2548 hw_if->enable_tx = xgbe_enable_tx;
2549 hw_if->disable_tx = xgbe_disable_tx;
2550 hw_if->enable_rx = xgbe_enable_rx;
2551 hw_if->disable_rx = xgbe_disable_rx;
2552
2553 hw_if->powerup_tx = xgbe_powerup_tx;
2554 hw_if->powerdown_tx = xgbe_powerdown_tx;
2555 hw_if->powerup_rx = xgbe_powerup_rx;
2556 hw_if->powerdown_rx = xgbe_powerdown_rx;
2557
Lendacky, Thomasa9d41982014-11-04 16:06:32 -06002558 hw_if->dev_xmit = xgbe_dev_xmit;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002559 hw_if->dev_read = xgbe_dev_read;
2560 hw_if->enable_int = xgbe_enable_int;
2561 hw_if->disable_int = xgbe_disable_int;
2562 hw_if->init = xgbe_init;
2563 hw_if->exit = xgbe_exit;
2564
2565 /* Descriptor related Sequences have to be initialized here */
2566 hw_if->tx_desc_init = xgbe_tx_desc_init;
2567 hw_if->rx_desc_init = xgbe_rx_desc_init;
2568 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2569 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2570 hw_if->is_last_desc = xgbe_is_last_desc;
2571 hw_if->is_context_desc = xgbe_is_context_desc;
2572
2573 /* For FLOW ctrl */
2574 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2575 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2576
2577 /* For RX coalescing */
2578 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2579 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2580 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2581 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2582
2583 /* For RX and TX threshold config */
2584 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2585 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2586
2587 /* For RX and TX Store and Forward Mode config */
2588 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2589 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2590
2591 /* For TX DMA Operating on Second Frame config */
2592 hw_if->config_osp_mode = xgbe_config_osp_mode;
2593
2594 /* For RX and TX PBL config */
2595 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2596 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2597 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2598 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2599 hw_if->config_pblx8 = xgbe_config_pblx8;
2600
2601 /* For MMC statistics support */
2602 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2603 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2604 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2605
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05002606 /* For PTP config */
2607 hw_if->config_tstamp = xgbe_config_tstamp;
2608 hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
2609 hw_if->set_tstamp_time = xgbe_set_tstamp_time;
2610 hw_if->get_tstamp_time = xgbe_get_tstamp_time;
2611 hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
2612
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05002613 /* For Data Center Bridging config */
2614 hw_if->config_dcb_tc = xgbe_config_dcb_tc;
2615 hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
2616
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002617 DBGPR("<--xgbe_init_function_ptrs\n");
2618}