blob: 2c7d582e0859b3bf567c6964ca376bffab856c92 [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, Thomasc5aa9e32014-06-05 09:15:06 -0500120
121#include "xgbe.h"
122#include "xgbe-common.h"
123
124
125static 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
133 rate = clk_get_rate(pdata->sysclock);
134
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
156 rate = clk_get_rate(pdata->sysclock);
157
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
249 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
250 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
259 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
260 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
270 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
271 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
281 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
282 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
338static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
339{
340 unsigned int max_q_count, q_count;
341 unsigned int reg, reg_val;
342 unsigned int i;
343
344 /* Clear MTL flow control */
345 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
346 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
347
348 /* Clear MAC flow control */
349 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
350 q_count = min_t(unsigned int, pdata->hw_feat.rx_q_cnt, max_q_count);
351 reg = MAC_Q0TFCR;
352 for (i = 0; i < q_count; i++) {
353 reg_val = XGMAC_IOREAD(pdata, reg);
354 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
355 XGMAC_IOWRITE(pdata, reg, reg_val);
356
357 reg += MAC_QTFCR_INC;
358 }
359
360 return 0;
361}
362
363static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
364{
365 unsigned int max_q_count, q_count;
366 unsigned int reg, reg_val;
367 unsigned int i;
368
369 /* Set MTL flow control */
370 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
371 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 1);
372
373 /* Set MAC flow control */
374 max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
375 q_count = min_t(unsigned int, pdata->hw_feat.rx_q_cnt, max_q_count);
376 reg = MAC_Q0TFCR;
377 for (i = 0; i < q_count; i++) {
378 reg_val = XGMAC_IOREAD(pdata, reg);
379
380 /* Enable transmit flow control */
381 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
382 /* Set pause time */
383 XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
384
385 XGMAC_IOWRITE(pdata, reg, reg_val);
386
387 reg += MAC_QTFCR_INC;
388 }
389
390 return 0;
391}
392
393static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
394{
395 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
396
397 return 0;
398}
399
400static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
401{
402 XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
403
404 return 0;
405}
406
407static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
408{
409 if (pdata->tx_pause)
410 xgbe_enable_tx_flow_control(pdata);
411 else
412 xgbe_disable_tx_flow_control(pdata);
413
414 return 0;
415}
416
417static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
418{
419 if (pdata->rx_pause)
420 xgbe_enable_rx_flow_control(pdata);
421 else
422 xgbe_disable_rx_flow_control(pdata);
423
424 return 0;
425}
426
427static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
428{
429 xgbe_config_tx_flow_control(pdata);
430 xgbe_config_rx_flow_control(pdata);
431}
432
433static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
434{
435 struct xgbe_channel *channel;
436 unsigned int dma_ch_isr, dma_ch_ier;
437 unsigned int i;
438
439 channel = pdata->channel;
440 for (i = 0; i < pdata->channel_count; i++, channel++) {
441 /* Clear all the interrupts which are set */
442 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
443 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
444
445 /* Clear all interrupt enable bits */
446 dma_ch_ier = 0;
447
448 /* Enable following interrupts
449 * NIE - Normal Interrupt Summary Enable
450 * AIE - Abnormal Interrupt Summary Enable
451 * FBEE - Fatal Bus Error Enable
452 */
453 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
454 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
455 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
456
457 if (channel->tx_ring) {
458 /* Enable the following Tx interrupts
459 * TIE - Transmit Interrupt Enable (unless polling)
460 */
461 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
462 }
463 if (channel->rx_ring) {
464 /* Enable following Rx interrupts
465 * RBUE - Receive Buffer Unavailable Enable
466 * RIE - Receive Interrupt Enable
467 */
468 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
469 XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
470 }
471
472 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
473 }
474}
475
476static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
477{
478 unsigned int mtl_q_isr;
479 unsigned int q_count, i;
480
481 q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
482 for (i = 0; i < q_count; i++) {
483 /* Clear all the interrupts which are set */
484 mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
485 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
486
487 /* No MTL interrupts to be enabled */
488 XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, 0);
489 }
490}
491
492static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
493{
494 /* No MAC interrupts to be enabled */
495 XGMAC_IOWRITE(pdata, MAC_IER, 0);
496
497 /* Enable all counter interrupts */
498 XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xff);
499 XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xff);
500}
501
502static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
503{
504 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
505
506 return 0;
507}
508
509static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
510{
511 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
512
513 return 0;
514}
515
516static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
517{
518 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
519
520 return 0;
521}
522
523static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
524 unsigned int enable)
525{
526 unsigned int val = enable ? 1 : 0;
527
528 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
529 return 0;
530
531 DBGPR(" %s promiscuous mode\n", enable ? "entering" : "leaving");
532 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
533
534 return 0;
535}
536
537static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
538 unsigned int enable)
539{
540 unsigned int val = enable ? 1 : 0;
541
542 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
543 return 0;
544
545 DBGPR(" %s allmulti mode\n", enable ? "entering" : "leaving");
546 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
547
548 return 0;
549}
550
551static int xgbe_set_addn_mac_addrs(struct xgbe_prv_data *pdata,
552 unsigned int am_mode)
553{
554 struct netdev_hw_addr *ha;
555 unsigned int mac_reg;
556 unsigned int mac_addr_hi, mac_addr_lo;
557 u8 *mac_addr;
558 unsigned int i;
559
560 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0);
561 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 0);
562
563 i = 0;
564 mac_reg = MAC_MACA1HR;
565
566 netdev_for_each_uc_addr(ha, pdata->netdev) {
567 mac_addr_lo = 0;
568 mac_addr_hi = 0;
569 mac_addr = (u8 *)&mac_addr_lo;
570 mac_addr[0] = ha->addr[0];
571 mac_addr[1] = ha->addr[1];
572 mac_addr[2] = ha->addr[2];
573 mac_addr[3] = ha->addr[3];
574 mac_addr = (u8 *)&mac_addr_hi;
575 mac_addr[0] = ha->addr[4];
576 mac_addr[1] = ha->addr[5];
577
578 DBGPR(" adding unicast address %pM at 0x%04x\n",
579 ha->addr, mac_reg);
580
581 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
582
583 XGMAC_IOWRITE(pdata, mac_reg, mac_addr_hi);
584 mac_reg += MAC_MACA_INC;
585 XGMAC_IOWRITE(pdata, mac_reg, mac_addr_lo);
586 mac_reg += MAC_MACA_INC;
587
588 i++;
589 }
590
591 if (!am_mode) {
592 netdev_for_each_mc_addr(ha, pdata->netdev) {
593 mac_addr_lo = 0;
594 mac_addr_hi = 0;
595 mac_addr = (u8 *)&mac_addr_lo;
596 mac_addr[0] = ha->addr[0];
597 mac_addr[1] = ha->addr[1];
598 mac_addr[2] = ha->addr[2];
599 mac_addr[3] = ha->addr[3];
600 mac_addr = (u8 *)&mac_addr_hi;
601 mac_addr[0] = ha->addr[4];
602 mac_addr[1] = ha->addr[5];
603
604 DBGPR(" adding multicast address %pM at 0x%04x\n",
605 ha->addr, mac_reg);
606
607 XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
608
609 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
614 i++;
615 }
616 }
617
618 /* Clear remaining additional MAC address entries */
619 for (; i < pdata->hw_feat.addn_mac; i++) {
620 XGMAC_IOWRITE(pdata, mac_reg, 0);
621 mac_reg += MAC_MACA_INC;
622 XGMAC_IOWRITE(pdata, mac_reg, 0);
623 mac_reg += MAC_MACA_INC;
624 }
625
626 return 0;
627}
628
629static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
630{
631 unsigned int mac_addr_hi, mac_addr_lo;
632
633 mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
634 mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
635 (addr[1] << 8) | (addr[0] << 0);
636
637 XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
638 XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
639
640 return 0;
641}
642
643static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
644 int mmd_reg)
645{
646 unsigned int mmd_address;
647 int mmd_data;
648
649 if (mmd_reg & MII_ADDR_C45)
650 mmd_address = mmd_reg & ~MII_ADDR_C45;
651 else
652 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
653
654 /* The PCS registers are accessed using mmio. The underlying APB3
655 * management interface uses indirect addressing to access the MMD
656 * register sets. This requires accessing of the PCS register in two
657 * phases, an address phase and a data phase.
658 *
659 * The mmio interface is based on 32-bit offsets and values. All
660 * register offsets must therefore be adjusted by left shifting the
661 * offset 2 bits and reading 32 bits of data.
662 */
663 mutex_lock(&pdata->xpcs_mutex);
664 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
665 mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
666 mutex_unlock(&pdata->xpcs_mutex);
667
668 return mmd_data;
669}
670
671static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
672 int mmd_reg, int mmd_data)
673{
674 unsigned int mmd_address;
675
676 if (mmd_reg & MII_ADDR_C45)
677 mmd_address = mmd_reg & ~MII_ADDR_C45;
678 else
679 mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
680
681 /* The PCS registers are accessed using mmio. The underlying APB3
682 * management interface uses indirect addressing to access the MMD
683 * register sets. This requires accessing of the PCS register in two
684 * phases, an address phase and a data phase.
685 *
686 * The mmio interface is based on 32-bit offsets and values. All
687 * register offsets must therefore be adjusted by left shifting the
688 * offset 2 bits and reading 32 bits of data.
689 */
690 mutex_lock(&pdata->xpcs_mutex);
691 XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
692 XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
693 mutex_unlock(&pdata->xpcs_mutex);
694}
695
696static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
697{
698 return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
699}
700
701static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
702{
703 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
704
705 return 0;
706}
707
708static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
709{
710 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
711
712 return 0;
713}
714
715static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
716{
717 /* Put the VLAN tag in the Rx descriptor */
718 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
719
720 /* Don't check the VLAN type */
721 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
722
723 /* Check only C-TAG (0x8100) packets */
724 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
725
726 /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
727 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
728
729 /* Enable VLAN tag stripping */
730 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
731
732 return 0;
733}
734
735static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
736{
737 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
738
739 return 0;
740}
741
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500742static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
743{
744 /* Enable VLAN filtering */
745 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
746
747 /* Enable VLAN Hash Table filtering */
748 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
749
750 /* Disable VLAN tag inverse matching */
751 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
752
753 /* Only filter on the lower 12-bits of the VLAN tag */
754 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
755
756 /* In order for the VLAN Hash Table filtering to be effective,
757 * the VLAN tag identifier in the VLAN Tag Register must not
758 * be zero. Set the VLAN tag identifier to "1" to enable the
759 * VLAN Hash Table filtering. This implies that a VLAN tag of
760 * 1 will always pass filtering.
761 */
762 XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
763
764 return 0;
765}
766
767static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
768{
769 /* Disable VLAN filtering */
770 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
771
772 return 0;
773}
774
775#ifndef CRCPOLY_LE
776#define CRCPOLY_LE 0xedb88320
777#endif
778static u32 xgbe_vid_crc32_le(__le16 vid_le)
779{
780 u32 poly = CRCPOLY_LE;
781 u32 crc = ~0;
782 u32 temp = 0;
783 unsigned char *data = (unsigned char *)&vid_le;
784 unsigned char data_byte = 0;
785 int i, bits;
786
787 bits = get_bitmask_order(VLAN_VID_MASK);
788 for (i = 0; i < bits; i++) {
789 if ((i % 8) == 0)
790 data_byte = data[i / 8];
791
792 temp = ((crc & 1) ^ data_byte) & 1;
793 crc >>= 1;
794 data_byte >>= 1;
795
796 if (temp)
797 crc ^= poly;
798 }
799
800 return crc;
801}
802
803static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
804{
805 u32 crc;
806 u16 vid;
807 __le16 vid_le;
808 u16 vlan_hash_table = 0;
809
810 /* Generate the VLAN Hash Table value */
811 for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
812 /* Get the CRC32 value of the VLAN ID */
813 vid_le = cpu_to_le16(vid);
814 crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
815
816 vlan_hash_table |= (1 << crc);
817 }
818
819 /* Set the VLAN Hash Table filtering register */
820 XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
821
822 return 0;
823}
824
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500825static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
826{
827 struct xgbe_ring_desc *rdesc = rdata->rdesc;
828
829 /* Reset the Tx descriptor
830 * Set buffer 1 (lo) address to zero
831 * Set buffer 1 (hi) address to zero
832 * Reset all other control bits (IC, TTSE, B2L & B1L)
833 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
834 */
835 rdesc->desc0 = 0;
836 rdesc->desc1 = 0;
837 rdesc->desc2 = 0;
838 rdesc->desc3 = 0;
839}
840
841static void xgbe_tx_desc_init(struct xgbe_channel *channel)
842{
843 struct xgbe_ring *ring = channel->tx_ring;
844 struct xgbe_ring_data *rdata;
845 struct xgbe_ring_desc *rdesc;
846 int i;
847 int start_index = ring->cur;
848
849 DBGPR("-->tx_desc_init\n");
850
851 /* Initialze all descriptors */
852 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500853 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500854 rdesc = rdata->rdesc;
855
856 /* Initialize Tx descriptor
857 * Set buffer 1 (lo) address to zero
858 * Set buffer 1 (hi) address to zero
859 * Reset all other control bits (IC, TTSE, B2L & B1L)
860 * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC,
861 * etc)
862 */
863 rdesc->desc0 = 0;
864 rdesc->desc1 = 0;
865 rdesc->desc2 = 0;
866 rdesc->desc3 = 0;
867 }
868
869 /* Make sure everything is written to the descriptor(s) before
870 * telling the device about them
871 */
872 wmb();
873
874 /* Update the total number of Tx descriptors */
875 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
876
877 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500878 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500879 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
880 upper_32_bits(rdata->rdesc_dma));
881 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
882 lower_32_bits(rdata->rdesc_dma));
883
884 DBGPR("<--tx_desc_init\n");
885}
886
887static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
888{
889 struct xgbe_ring_desc *rdesc = rdata->rdesc;
890
891 /* Reset the Rx descriptor
892 * Set buffer 1 (lo) address to dma address (lo)
893 * Set buffer 1 (hi) address to dma address (hi)
894 * Set buffer 2 (lo) address to zero
895 * Set buffer 2 (hi) address to zero and set control bits
896 * OWN and INTE
897 */
898 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
899 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
900 rdesc->desc2 = 0;
901
902 rdesc->desc3 = 0;
903 if (rdata->interrupt)
904 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
905
906 /* Since the Rx DMA engine is likely running, make sure everything
907 * is written to the descriptor(s) before setting the OWN bit
908 * for the descriptor
909 */
910 wmb();
911
912 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
913
914 /* Make sure ownership is written to the descriptor */
915 wmb();
916}
917
918static void xgbe_rx_desc_init(struct xgbe_channel *channel)
919{
920 struct xgbe_prv_data *pdata = channel->pdata;
921 struct xgbe_ring *ring = channel->rx_ring;
922 struct xgbe_ring_data *rdata;
923 struct xgbe_ring_desc *rdesc;
924 unsigned int start_index = ring->cur;
925 unsigned int rx_coalesce, rx_frames;
926 unsigned int i;
927
928 DBGPR("-->rx_desc_init\n");
929
930 rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
931 rx_frames = pdata->rx_frames;
932
933 /* Initialize all descriptors */
934 for (i = 0; i < ring->rdesc_count; i++) {
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500935 rdata = XGBE_GET_DESC_DATA(ring, i);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500936 rdesc = rdata->rdesc;
937
938 /* Initialize Rx descriptor
939 * Set buffer 1 (lo) address to dma address (lo)
940 * Set buffer 1 (hi) address to dma address (hi)
941 * Set buffer 2 (lo) address to zero
942 * Set buffer 2 (hi) address to zero and set control
943 * bits OWN and INTE appropriateley
944 */
945 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
946 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
947 rdesc->desc2 = 0;
948 rdesc->desc3 = 0;
949 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
950 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
951 rdata->interrupt = 1;
952 if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames))) {
953 /* Clear interrupt on completion bit */
954 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE,
955 0);
956 rdata->interrupt = 0;
957 }
958 }
959
960 /* Make sure everything is written to the descriptors before
961 * telling the device about them
962 */
963 wmb();
964
965 /* Update the total number of Rx descriptors */
966 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
967
968 /* Update the starting address of descriptor ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500969 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500970 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
971 upper_32_bits(rdata->rdesc_dma));
972 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
973 lower_32_bits(rdata->rdesc_dma));
974
975 /* Update the Rx Descriptor Tail Pointer */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500976 rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500977 XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
978 lower_32_bits(rdata->rdesc_dma));
979
980 DBGPR("<--rx_desc_init\n");
981}
982
983static void xgbe_pre_xmit(struct xgbe_channel *channel)
984{
985 struct xgbe_prv_data *pdata = channel->pdata;
986 struct xgbe_ring *ring = channel->tx_ring;
987 struct xgbe_ring_data *rdata;
988 struct xgbe_ring_desc *rdesc;
989 struct xgbe_packet_data *packet = &ring->packet_data;
990 unsigned int csum, tso, vlan;
991 unsigned int tso_context, vlan_context;
992 unsigned int tx_coalesce, tx_frames;
993 int start_index = ring->cur;
994 int i;
995
996 DBGPR("-->xgbe_pre_xmit\n");
997
998 csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
999 CSUM_ENABLE);
1000 tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1001 TSO_ENABLE);
1002 vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
1003 VLAN_CTAG);
1004
1005 if (tso && (packet->mss != ring->tx.cur_mss))
1006 tso_context = 1;
1007 else
1008 tso_context = 0;
1009
1010 if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
1011 vlan_context = 1;
1012 else
1013 vlan_context = 0;
1014
1015 tx_coalesce = (pdata->tx_usecs || pdata->tx_frames) ? 1 : 0;
1016 tx_frames = pdata->tx_frames;
1017 if (tx_coalesce && !channel->tx_timer_active)
1018 ring->coalesce_count = 0;
1019
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001020 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001021 rdesc = rdata->rdesc;
1022
1023 /* Create a context descriptor if this is a TSO packet */
1024 if (tso_context || vlan_context) {
1025 if (tso_context) {
1026 DBGPR(" TSO context descriptor, mss=%u\n",
1027 packet->mss);
1028
1029 /* Set the MSS size */
1030 XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
1031 MSS, packet->mss);
1032
1033 /* Mark it as a CONTEXT descriptor */
1034 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1035 CTXT, 1);
1036
1037 /* Indicate this descriptor contains the MSS */
1038 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1039 TCMSSV, 1);
1040
1041 ring->tx.cur_mss = packet->mss;
1042 }
1043
1044 if (vlan_context) {
1045 DBGPR(" VLAN context descriptor, ctag=%u\n",
1046 packet->vlan_ctag);
1047
1048 /* Mark it as a CONTEXT descriptor */
1049 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1050 CTXT, 1);
1051
1052 /* Set the VLAN tag */
1053 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1054 VT, packet->vlan_ctag);
1055
1056 /* Indicate this descriptor contains the VLAN tag */
1057 XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
1058 VLTV, 1);
1059
1060 ring->tx.cur_vlan_ctag = packet->vlan_ctag;
1061 }
1062
1063 ring->cur++;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001064 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001065 rdesc = rdata->rdesc;
1066 }
1067
1068 /* Update buffer address (for TSO this is the header) */
1069 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1070 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1071
1072 /* Update the buffer length */
1073 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1074 rdata->skb_dma_len);
1075
1076 /* VLAN tag insertion check */
1077 if (vlan)
1078 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
1079 TX_NORMAL_DESC2_VLAN_INSERT);
1080
1081 /* Set IC bit based on Tx coalescing settings */
1082 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1083 if (tx_coalesce && (!tx_frames ||
1084 (++ring->coalesce_count % tx_frames)))
1085 /* Clear IC bit */
1086 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1087
1088 /* Mark it as First Descriptor */
1089 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1090
1091 /* Mark it as a NORMAL descriptor */
1092 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1093
1094 /* Set OWN bit if not the first descriptor */
1095 if (ring->cur != start_index)
1096 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1097
1098 if (tso) {
1099 /* Enable TSO */
1100 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1101 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1102 packet->tcp_payload_len);
1103 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1104 packet->tcp_header_len / 4);
1105 } else {
1106 /* Enable CRC and Pad Insertion */
1107 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1108
1109 /* Enable HW CSUM */
1110 if (csum)
1111 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1112 CIC, 0x3);
1113
1114 /* Set the total length to be transmitted */
1115 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1116 packet->length);
1117 }
1118
1119 for (i = ring->cur - start_index + 1; i < packet->rdesc_count; i++) {
1120 ring->cur++;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001121 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001122 rdesc = rdata->rdesc;
1123
1124 /* Update buffer address */
1125 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1126 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1127
1128 /* Update the buffer length */
1129 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1130 rdata->skb_dma_len);
1131
1132 /* Set IC bit based on Tx coalescing settings */
1133 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1134 if (tx_coalesce && (!tx_frames ||
1135 (++ring->coalesce_count % tx_frames)))
1136 /* Clear IC bit */
1137 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1138
1139 /* Set OWN bit */
1140 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1141
1142 /* Mark it as NORMAL descriptor */
1143 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1144
1145 /* Enable HW CSUM */
1146 if (csum)
1147 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1148 CIC, 0x3);
1149 }
1150
1151 /* Set LAST bit for the last descriptor */
1152 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1153
1154 /* In case the Tx DMA engine is running, make sure everything
1155 * is written to the descriptor(s) before setting the OWN bit
1156 * for the first descriptor
1157 */
1158 wmb();
1159
1160 /* Set OWN bit for the first descriptor */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001161 rdata = XGBE_GET_DESC_DATA(ring, start_index);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001162 rdesc = rdata->rdesc;
1163 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1164
1165#ifdef XGMAC_ENABLE_TX_DESC_DUMP
1166 xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
1167#endif
1168
1169 /* Make sure ownership is written to the descriptor */
1170 wmb();
1171
1172 /* Issue a poll command to Tx DMA by writing address
1173 * of next immediate free descriptor */
1174 ring->cur++;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001175 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001176 XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1177 lower_32_bits(rdata->rdesc_dma));
1178
1179 /* Start the Tx coalescing timer */
1180 if (tx_coalesce && !channel->tx_timer_active) {
1181 channel->tx_timer_active = 1;
1182 hrtimer_start(&channel->tx_timer,
1183 ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
1184 HRTIMER_MODE_REL);
1185 }
1186
1187 DBGPR(" %s: descriptors %u to %u written\n",
1188 channel->name, start_index & (ring->rdesc_count - 1),
1189 (ring->cur - 1) & (ring->rdesc_count - 1));
1190
1191 DBGPR("<--xgbe_pre_xmit\n");
1192}
1193
1194static int xgbe_dev_read(struct xgbe_channel *channel)
1195{
1196 struct xgbe_ring *ring = channel->rx_ring;
1197 struct xgbe_ring_data *rdata;
1198 struct xgbe_ring_desc *rdesc;
1199 struct xgbe_packet_data *packet = &ring->packet_data;
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001200 struct net_device *netdev = channel->pdata->netdev;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001201 unsigned int err, etlt;
1202
1203 DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1204
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001205 rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001206 rdesc = rdata->rdesc;
1207
1208 /* Check for data availability */
1209 if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1210 return 1;
1211
1212#ifdef XGMAC_ENABLE_RX_DESC_DUMP
1213 xgbe_dump_rx_desc(ring, rdesc, ring->cur);
1214#endif
1215
1216 /* Get the packet length */
1217 rdata->len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
1218
1219 if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1220 /* Not all the data has been transferred for this packet */
1221 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1222 INCOMPLETE, 1);
1223 return 0;
1224 }
1225
1226 /* This is the last of the data for this packet */
1227 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1228 INCOMPLETE, 0);
1229
1230 /* Set checksum done indicator as appropriate */
1231 if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
1232 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1233 CSUM_DONE, 1);
1234
1235 /* Check for errors (only valid in last descriptor) */
1236 err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1237 etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1238 DBGPR(" err=%u, etlt=%#x\n", err, etlt);
1239
1240 if (!err || (err && !etlt)) {
Lendacky, Thomasc52e9c62014-06-24 16:19:18 -05001241 if ((etlt == 0x09) &&
1242 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001243 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1244 VLAN_CTAG, 1);
1245 packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1246 RX_NORMAL_DESC0,
1247 OVT);
1248 DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
1249 }
1250 } else {
1251 if ((etlt == 0x05) || (etlt == 0x06))
1252 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1253 CSUM_DONE, 0);
1254 else
1255 XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1256 FRAME, 1);
1257 }
1258
1259 DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1260 ring->cur & (ring->rdesc_count - 1), ring->cur);
1261
1262 return 0;
1263}
1264
1265static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1266{
1267 /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1268 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1269}
1270
1271static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1272{
1273 /* Rx and Tx share LD bit, so check TDES3.LD bit */
1274 return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1275}
1276
1277static void xgbe_save_interrupt_status(struct xgbe_channel *channel,
1278 enum xgbe_int_state int_state)
1279{
1280 unsigned int dma_ch_ier;
1281
1282 if (int_state == XGMAC_INT_STATE_SAVE) {
1283 channel->saved_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001284 channel->saved_ier &= XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001285 } else {
1286 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1287 dma_ch_ier |= channel->saved_ier;
1288 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1289 }
1290}
1291
1292static int xgbe_enable_int(struct xgbe_channel *channel,
1293 enum xgbe_int int_id)
1294{
1295 switch (int_id) {
1296 case XGMAC_INT_DMA_ISR_DC0IS:
1297 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 1);
1298 break;
1299 case XGMAC_INT_DMA_CH_SR_TI:
1300 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 1);
1301 break;
1302 case XGMAC_INT_DMA_CH_SR_TPS:
1303 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TXSE, 1);
1304 break;
1305 case XGMAC_INT_DMA_CH_SR_TBU:
1306 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TBUE, 1);
1307 break;
1308 case XGMAC_INT_DMA_CH_SR_RI:
1309 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RIE, 1);
1310 break;
1311 case XGMAC_INT_DMA_CH_SR_RBU:
1312 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RBUE, 1);
1313 break;
1314 case XGMAC_INT_DMA_CH_SR_RPS:
1315 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RSE, 1);
1316 break;
1317 case XGMAC_INT_DMA_CH_SR_FBE:
1318 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, FBEE, 1);
1319 break;
1320 case XGMAC_INT_DMA_ALL:
1321 xgbe_save_interrupt_status(channel, XGMAC_INT_STATE_RESTORE);
1322 break;
1323 default:
1324 return -1;
1325 }
1326
1327 return 0;
1328}
1329
1330static int xgbe_disable_int(struct xgbe_channel *channel,
1331 enum xgbe_int int_id)
1332{
1333 unsigned int dma_ch_ier;
1334
1335 switch (int_id) {
1336 case XGMAC_INT_DMA_ISR_DC0IS:
1337 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 0);
1338 break;
1339 case XGMAC_INT_DMA_CH_SR_TI:
1340 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 0);
1341 break;
1342 case XGMAC_INT_DMA_CH_SR_TPS:
1343 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TXSE, 0);
1344 break;
1345 case XGMAC_INT_DMA_CH_SR_TBU:
1346 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TBUE, 0);
1347 break;
1348 case XGMAC_INT_DMA_CH_SR_RI:
1349 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RIE, 0);
1350 break;
1351 case XGMAC_INT_DMA_CH_SR_RBU:
1352 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RBUE, 0);
1353 break;
1354 case XGMAC_INT_DMA_CH_SR_RPS:
1355 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RSE, 0);
1356 break;
1357 case XGMAC_INT_DMA_CH_SR_FBE:
1358 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, FBEE, 0);
1359 break;
1360 case XGMAC_INT_DMA_ALL:
1361 xgbe_save_interrupt_status(channel, XGMAC_INT_STATE_SAVE);
1362
1363 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001364 dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001365 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1366 break;
1367 default:
1368 return -1;
1369 }
1370
1371 return 0;
1372}
1373
1374static int xgbe_exit(struct xgbe_prv_data *pdata)
1375{
1376 unsigned int count = 2000;
1377
1378 DBGPR("-->xgbe_exit\n");
1379
1380 /* Issue a software reset */
1381 XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1382 usleep_range(10, 15);
1383
1384 /* Poll Until Poll Condition */
1385 while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1386 usleep_range(500, 600);
1387
1388 if (!count)
1389 return -EBUSY;
1390
1391 DBGPR("<--xgbe_exit\n");
1392
1393 return 0;
1394}
1395
1396static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1397{
1398 unsigned int i, count;
1399
1400 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1401 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1402
1403 /* Poll Until Poll Condition */
1404 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++) {
1405 count = 2000;
1406 while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
1407 MTL_Q_TQOMR, FTQ))
1408 usleep_range(500, 600);
1409
1410 if (!count)
1411 return -EBUSY;
1412 }
1413
1414 return 0;
1415}
1416
1417static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1418{
1419 /* Set enhanced addressing mode */
1420 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1421
1422 /* Set the System Bus mode */
1423 XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
1424}
1425
1426static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1427{
1428 unsigned int arcache, awcache;
1429
1430 arcache = 0;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001431 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, XGBE_DMA_ARCACHE);
1432 XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, XGBE_DMA_ARDOMAIN);
1433 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, XGBE_DMA_ARCACHE);
1434 XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, XGBE_DMA_ARDOMAIN);
1435 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, XGBE_DMA_ARCACHE);
1436 XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, XGBE_DMA_ARDOMAIN);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001437 XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1438
1439 awcache = 0;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001440 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, XGBE_DMA_AWCACHE);
1441 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, XGBE_DMA_AWDOMAIN);
1442 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, XGBE_DMA_AWCACHE);
1443 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, XGBE_DMA_AWDOMAIN);
1444 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, XGBE_DMA_AWCACHE);
1445 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, XGBE_DMA_AWDOMAIN);
1446 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, XGBE_DMA_AWCACHE);
1447 XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, XGBE_DMA_AWDOMAIN);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001448 XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1449}
1450
1451static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1452{
1453 unsigned int i;
1454
1455 /* Set Tx to weighted round robin scheduling algorithm (when
1456 * traffic class is using ETS algorithm)
1457 */
1458 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1459
1460 /* Set Tx traffic classes to strict priority algorithm */
1461 for (i = 0; i < XGBE_TC_CNT; i++)
1462 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, MTL_TSA_SP);
1463
1464 /* Set Rx to strict priority algorithm */
1465 XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1466}
1467
1468static unsigned int xgbe_calculate_per_queue_fifo(unsigned long fifo_size,
1469 unsigned char queue_count)
1470{
1471 unsigned int q_fifo_size = 0;
1472 enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1473
1474 /* Calculate Tx/Rx fifo share per queue */
1475 switch (fifo_size) {
1476 case 0:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001477 q_fifo_size = XGBE_FIFO_SIZE_B(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001478 break;
1479 case 1:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001480 q_fifo_size = XGBE_FIFO_SIZE_B(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001481 break;
1482 case 2:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001483 q_fifo_size = XGBE_FIFO_SIZE_B(512);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001484 break;
1485 case 3:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001486 q_fifo_size = XGBE_FIFO_SIZE_KB(1);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001487 break;
1488 case 4:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001489 q_fifo_size = XGBE_FIFO_SIZE_KB(2);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001490 break;
1491 case 5:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001492 q_fifo_size = XGBE_FIFO_SIZE_KB(4);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001493 break;
1494 case 6:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001495 q_fifo_size = XGBE_FIFO_SIZE_KB(8);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001496 break;
1497 case 7:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001498 q_fifo_size = XGBE_FIFO_SIZE_KB(16);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001499 break;
1500 case 8:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001501 q_fifo_size = XGBE_FIFO_SIZE_KB(32);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001502 break;
1503 case 9:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001504 q_fifo_size = XGBE_FIFO_SIZE_KB(64);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001505 break;
1506 case 10:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001507 q_fifo_size = XGBE_FIFO_SIZE_KB(128);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001508 break;
1509 case 11:
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001510 q_fifo_size = XGBE_FIFO_SIZE_KB(256);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001511 break;
1512 }
1513 q_fifo_size = q_fifo_size / queue_count;
1514
1515 /* Set the queue fifo size programmable value */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001516 if (q_fifo_size >= XGBE_FIFO_SIZE_KB(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001517 p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001518 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(128))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001519 p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001520 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(64))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001521 p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001522 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(32))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001523 p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001524 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(16))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001525 p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001526 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(8))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001527 p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001528 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(4))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001529 p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001530 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(2))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001531 p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001532 else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(1))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001533 p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001534 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(512))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001535 p_fifo = XGMAC_MTL_FIFO_SIZE_512;
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -05001536 else if (q_fifo_size >= XGBE_FIFO_SIZE_B(256))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001537 p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1538
1539 return p_fifo;
1540}
1541
1542static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
1543{
1544 enum xgbe_mtl_fifo_size fifo_size;
1545 unsigned int i;
1546
1547 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
1548 pdata->hw_feat.tx_q_cnt);
1549
1550 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1551 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
1552
1553 netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
1554 pdata->hw_feat.tx_q_cnt, ((fifo_size + 1) * 256));
1555}
1556
1557static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
1558{
1559 enum xgbe_mtl_fifo_size fifo_size;
1560 unsigned int i;
1561
1562 fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
1563 pdata->hw_feat.rx_q_cnt);
1564
1565 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
1566 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
1567
1568 netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
1569 pdata->hw_feat.rx_q_cnt, ((fifo_size + 1) * 256));
1570}
1571
1572static void xgbe_config_rx_queue_mapping(struct xgbe_prv_data *pdata)
1573{
1574 unsigned int i, reg, reg_val;
1575 unsigned int q_count = pdata->hw_feat.rx_q_cnt;
1576
1577 /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
1578 reg = MTL_RQDCM0R;
1579 reg_val = 0;
1580 for (i = 0; i < q_count;) {
1581 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
1582
1583 if ((i % MTL_RQDCM_Q_PER_REG) && (i != q_count))
1584 continue;
1585
1586 XGMAC_IOWRITE(pdata, reg, reg_val);
1587
1588 reg += MTL_RQDCM_INC;
1589 reg_val = 0;
1590 }
1591}
1592
1593static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
1594{
1595 unsigned int i;
1596
1597 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++) {
1598 /* Activate flow control when less than 4k left in fifo */
1599 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
1600
1601 /* De-activate flow control when more than 6k left in fifo */
1602 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
1603 }
1604}
1605
1606static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
1607{
1608 xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
1609}
1610
1611static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
1612{
1613 unsigned int val;
1614
1615 val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
1616
1617 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1618}
1619
1620static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
1621{
1622 if (pdata->netdev->features & NETIF_F_RXCSUM)
1623 xgbe_enable_rx_csum(pdata);
1624 else
1625 xgbe_disable_rx_csum(pdata);
1626}
1627
1628static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
1629{
Lendacky, Thomas6e5eed02014-06-24 16:19:12 -05001630 /* Indicate that VLAN Tx CTAGs come from context descriptors */
1631 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
1632 XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
1633
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05001634 /* Set the current VLAN Hash Table register value */
1635 xgbe_update_vlan_hash_table(pdata);
1636
1637 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
1638 xgbe_enable_rx_vlan_filtering(pdata);
1639 else
1640 xgbe_disable_rx_vlan_filtering(pdata);
1641
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001642 if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
1643 xgbe_enable_rx_vlan_stripping(pdata);
1644 else
1645 xgbe_disable_rx_vlan_stripping(pdata);
1646}
1647
1648static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
1649{
1650 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1651 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
1652
1653 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
1654 stats->txoctetcount_gb +=
1655 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
1656
1657 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
1658 stats->txframecount_gb +=
1659 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
1660
1661 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
1662 stats->txbroadcastframes_g +=
1663 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1664
1665 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
1666 stats->txmulticastframes_g +=
1667 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1668
1669 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
1670 stats->tx64octets_gb +=
1671 XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
1672
1673 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
1674 stats->tx65to127octets_gb +=
1675 XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
1676
1677 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
1678 stats->tx128to255octets_gb +=
1679 XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
1680
1681 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
1682 stats->tx256to511octets_gb +=
1683 XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
1684
1685 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
1686 stats->tx512to1023octets_gb +=
1687 XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1688
1689 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
1690 stats->tx1024tomaxoctets_gb +=
1691 XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1692
1693 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
1694 stats->txunicastframes_gb +=
1695 XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
1696
1697 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
1698 stats->txmulticastframes_gb +=
1699 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
1700
1701 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
1702 stats->txbroadcastframes_g +=
1703 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
1704
1705 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
1706 stats->txunderflowerror +=
1707 XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
1708
1709 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
1710 stats->txoctetcount_g +=
1711 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
1712
1713 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
1714 stats->txframecount_g +=
1715 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
1716
1717 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
1718 stats->txpauseframes +=
1719 XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
1720
1721 if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
1722 stats->txvlanframes_g +=
1723 XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
1724}
1725
1726static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
1727{
1728 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1729 unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
1730
1731 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
1732 stats->rxframecount_gb +=
1733 XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
1734
1735 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
1736 stats->rxoctetcount_gb +=
1737 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
1738
1739 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
1740 stats->rxoctetcount_g +=
1741 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
1742
1743 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
1744 stats->rxbroadcastframes_g +=
1745 XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
1746
1747 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
1748 stats->rxmulticastframes_g +=
1749 XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
1750
1751 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
1752 stats->rxcrcerror +=
1753 XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
1754
1755 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
1756 stats->rxrunterror +=
1757 XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
1758
1759 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
1760 stats->rxjabbererror +=
1761 XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
1762
1763 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
1764 stats->rxundersize_g +=
1765 XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
1766
1767 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
1768 stats->rxoversize_g +=
1769 XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
1770
1771 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
1772 stats->rx64octets_gb +=
1773 XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
1774
1775 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
1776 stats->rx65to127octets_gb +=
1777 XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
1778
1779 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
1780 stats->rx128to255octets_gb +=
1781 XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
1782
1783 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
1784 stats->rx256to511octets_gb +=
1785 XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
1786
1787 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
1788 stats->rx512to1023octets_gb +=
1789 XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
1790
1791 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
1792 stats->rx1024tomaxoctets_gb +=
1793 XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
1794
1795 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
1796 stats->rxunicastframes_g +=
1797 XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
1798
1799 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
1800 stats->rxlengtherror +=
1801 XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
1802
1803 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
1804 stats->rxoutofrangetype +=
1805 XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
1806
1807 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
1808 stats->rxpauseframes +=
1809 XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
1810
1811 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
1812 stats->rxfifooverflow +=
1813 XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
1814
1815 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
1816 stats->rxvlanframes_gb +=
1817 XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
1818
1819 if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
1820 stats->rxwatchdogerror +=
1821 XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
1822}
1823
1824static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
1825{
1826 struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1827
1828 /* Freeze counters */
1829 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
1830
1831 stats->txoctetcount_gb +=
1832 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
1833
1834 stats->txframecount_gb +=
1835 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
1836
1837 stats->txbroadcastframes_g +=
1838 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1839
1840 stats->txmulticastframes_g +=
1841 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1842
1843 stats->tx64octets_gb +=
1844 XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
1845
1846 stats->tx65to127octets_gb +=
1847 XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
1848
1849 stats->tx128to255octets_gb +=
1850 XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
1851
1852 stats->tx256to511octets_gb +=
1853 XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
1854
1855 stats->tx512to1023octets_gb +=
1856 XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1857
1858 stats->tx1024tomaxoctets_gb +=
1859 XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1860
1861 stats->txunicastframes_gb +=
1862 XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
1863
1864 stats->txmulticastframes_gb +=
1865 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
1866
1867 stats->txbroadcastframes_g +=
1868 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
1869
1870 stats->txunderflowerror +=
1871 XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
1872
1873 stats->txoctetcount_g +=
1874 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
1875
1876 stats->txframecount_g +=
1877 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
1878
1879 stats->txpauseframes +=
1880 XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
1881
1882 stats->txvlanframes_g +=
1883 XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
1884
1885 stats->rxframecount_gb +=
1886 XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
1887
1888 stats->rxoctetcount_gb +=
1889 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
1890
1891 stats->rxoctetcount_g +=
1892 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
1893
1894 stats->rxbroadcastframes_g +=
1895 XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
1896
1897 stats->rxmulticastframes_g +=
1898 XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
1899
1900 stats->rxcrcerror +=
1901 XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
1902
1903 stats->rxrunterror +=
1904 XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
1905
1906 stats->rxjabbererror +=
1907 XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
1908
1909 stats->rxundersize_g +=
1910 XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
1911
1912 stats->rxoversize_g +=
1913 XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
1914
1915 stats->rx64octets_gb +=
1916 XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
1917
1918 stats->rx65to127octets_gb +=
1919 XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
1920
1921 stats->rx128to255octets_gb +=
1922 XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
1923
1924 stats->rx256to511octets_gb +=
1925 XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
1926
1927 stats->rx512to1023octets_gb +=
1928 XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
1929
1930 stats->rx1024tomaxoctets_gb +=
1931 XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
1932
1933 stats->rxunicastframes_g +=
1934 XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
1935
1936 stats->rxlengtherror +=
1937 XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
1938
1939 stats->rxoutofrangetype +=
1940 XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
1941
1942 stats->rxpauseframes +=
1943 XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
1944
1945 stats->rxfifooverflow +=
1946 XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
1947
1948 stats->rxvlanframes_gb +=
1949 XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
1950
1951 stats->rxwatchdogerror +=
1952 XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
1953
1954 /* Un-freeze counters */
1955 XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
1956}
1957
1958static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
1959{
1960 /* Set counters to reset on read */
1961 XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
1962
1963 /* Reset the counters */
1964 XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
1965}
1966
1967static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
1968{
1969 struct xgbe_channel *channel;
1970 unsigned int i;
1971
1972 /* Enable each Tx DMA channel */
1973 channel = pdata->channel;
1974 for (i = 0; i < pdata->channel_count; i++, channel++) {
1975 if (!channel->tx_ring)
1976 break;
1977
1978 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
1979 }
1980
1981 /* Enable each Tx queue */
1982 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1983 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
1984 MTL_Q_ENABLED);
1985
1986 /* Enable MAC Tx */
1987 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
1988}
1989
1990static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
1991{
1992 struct xgbe_channel *channel;
1993 unsigned int i;
1994
1995 /* Disable MAC Tx */
1996 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
1997
1998 /* Disable each Tx queue */
1999 for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
2000 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
2001
2002 /* Disable each Tx DMA channel */
2003 channel = pdata->channel;
2004 for (i = 0; i < pdata->channel_count; i++, channel++) {
2005 if (!channel->tx_ring)
2006 break;
2007
2008 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2009 }
2010}
2011
2012static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
2013{
2014 struct xgbe_channel *channel;
2015 unsigned int reg_val, i;
2016
2017 /* Enable each Rx DMA channel */
2018 channel = pdata->channel;
2019 for (i = 0; i < pdata->channel_count; i++, channel++) {
2020 if (!channel->rx_ring)
2021 break;
2022
2023 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2024 }
2025
2026 /* Enable each Rx queue */
2027 reg_val = 0;
2028 for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
2029 reg_val |= (0x02 << (i << 1));
2030 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
2031
2032 /* Enable MAC Rx */
2033 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
2034 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
2035 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
2036 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
2037}
2038
2039static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
2040{
2041 struct xgbe_channel *channel;
2042 unsigned int i;
2043
2044 /* Disable MAC Rx */
2045 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
2046 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
2047 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
2048 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
2049
2050 /* Disable each Rx queue */
2051 XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
2052
2053 /* Disable each Rx DMA channel */
2054 channel = pdata->channel;
2055 for (i = 0; i < pdata->channel_count; i++, channel++) {
2056 if (!channel->rx_ring)
2057 break;
2058
2059 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2060 }
2061}
2062
2063static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
2064{
2065 struct xgbe_channel *channel;
2066 unsigned int i;
2067
2068 /* Enable each Tx DMA channel */
2069 channel = pdata->channel;
2070 for (i = 0; i < pdata->channel_count; i++, channel++) {
2071 if (!channel->tx_ring)
2072 break;
2073
2074 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
2075 }
2076
2077 /* Enable MAC Tx */
2078 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
2079}
2080
2081static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
2082{
2083 struct xgbe_channel *channel;
2084 unsigned int i;
2085
2086 /* Disable MAC Tx */
2087 XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
2088
2089 /* Disable each Tx DMA channel */
2090 channel = pdata->channel;
2091 for (i = 0; i < pdata->channel_count; i++, channel++) {
2092 if (!channel->tx_ring)
2093 break;
2094
2095 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
2096 }
2097}
2098
2099static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2100{
2101 struct xgbe_channel *channel;
2102 unsigned int i;
2103
2104 /* Enable each Rx DMA channel */
2105 channel = pdata->channel;
2106 for (i = 0; i < pdata->channel_count; i++, channel++) {
2107 if (!channel->rx_ring)
2108 break;
2109
2110 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2111 }
2112}
2113
2114static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2115{
2116 struct xgbe_channel *channel;
2117 unsigned int i;
2118
2119 /* Disable each Rx DMA channel */
2120 channel = pdata->channel;
2121 for (i = 0; i < pdata->channel_count; i++, channel++) {
2122 if (!channel->rx_ring)
2123 break;
2124
2125 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2126 }
2127}
2128
2129static int xgbe_init(struct xgbe_prv_data *pdata)
2130{
2131 struct xgbe_desc_if *desc_if = &pdata->desc_if;
2132 int ret;
2133
2134 DBGPR("-->xgbe_init\n");
2135
2136 /* Flush Tx queues */
2137 ret = xgbe_flush_tx_queues(pdata);
2138 if (ret)
2139 return ret;
2140
2141 /*
2142 * Initialize DMA related features
2143 */
2144 xgbe_config_dma_bus(pdata);
2145 xgbe_config_dma_cache(pdata);
2146 xgbe_config_osp_mode(pdata);
2147 xgbe_config_pblx8(pdata);
2148 xgbe_config_tx_pbl_val(pdata);
2149 xgbe_config_rx_pbl_val(pdata);
2150 xgbe_config_rx_coalesce(pdata);
2151 xgbe_config_tx_coalesce(pdata);
2152 xgbe_config_rx_buffer_size(pdata);
2153 xgbe_config_tso_mode(pdata);
2154 desc_if->wrapper_tx_desc_init(pdata);
2155 desc_if->wrapper_rx_desc_init(pdata);
2156 xgbe_enable_dma_interrupts(pdata);
2157
2158 /*
2159 * Initialize MTL related features
2160 */
2161 xgbe_config_mtl_mode(pdata);
2162 xgbe_config_rx_queue_mapping(pdata);
2163 /*TODO: Program the priorities mapped to the Selected Traffic Classes
2164 in MTL_TC_Prty_Map0-3 registers */
2165 xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2166 xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2167 xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2168 xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2169 xgbe_config_tx_fifo_size(pdata);
2170 xgbe_config_rx_fifo_size(pdata);
2171 xgbe_config_flow_control_threshold(pdata);
2172 /*TODO: Queue to Traffic Class Mapping (Q2TCMAP) */
2173 /*TODO: Error Packet and undersized good Packet forwarding enable
2174 (FEP and FUP)
2175 */
2176 xgbe_enable_mtl_interrupts(pdata);
2177
2178 /* Transmit Class Weight */
2179 XGMAC_IOWRITE_BITS(pdata, MTL_Q_TCQWR, QW, 0x10);
2180
2181 /*
2182 * Initialize MAC related features
2183 */
2184 xgbe_config_mac_address(pdata);
2185 xgbe_config_jumbo_enable(pdata);
2186 xgbe_config_flow_control(pdata);
2187 xgbe_config_checksum_offload(pdata);
2188 xgbe_config_vlan_support(pdata);
2189 xgbe_config_mmc(pdata);
2190 xgbe_enable_mac_interrupts(pdata);
2191
2192 DBGPR("<--xgbe_init\n");
2193
2194 return 0;
2195}
2196
2197void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2198{
2199 DBGPR("-->xgbe_init_function_ptrs\n");
2200
2201 hw_if->tx_complete = xgbe_tx_complete;
2202
2203 hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
2204 hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
2205 hw_if->set_addn_mac_addrs = xgbe_set_addn_mac_addrs;
2206 hw_if->set_mac_address = xgbe_set_mac_address;
2207
2208 hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2209 hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2210
2211 hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2212 hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
Lendacky, Thomas801c62d2014-06-24 16:19:24 -05002213 hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
2214 hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
2215 hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05002216
2217 hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2218 hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2219
2220 hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2221 hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2222 hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2223
2224 hw_if->enable_tx = xgbe_enable_tx;
2225 hw_if->disable_tx = xgbe_disable_tx;
2226 hw_if->enable_rx = xgbe_enable_rx;
2227 hw_if->disable_rx = xgbe_disable_rx;
2228
2229 hw_if->powerup_tx = xgbe_powerup_tx;
2230 hw_if->powerdown_tx = xgbe_powerdown_tx;
2231 hw_if->powerup_rx = xgbe_powerup_rx;
2232 hw_if->powerdown_rx = xgbe_powerdown_rx;
2233
2234 hw_if->pre_xmit = xgbe_pre_xmit;
2235 hw_if->dev_read = xgbe_dev_read;
2236 hw_if->enable_int = xgbe_enable_int;
2237 hw_if->disable_int = xgbe_disable_int;
2238 hw_if->init = xgbe_init;
2239 hw_if->exit = xgbe_exit;
2240
2241 /* Descriptor related Sequences have to be initialized here */
2242 hw_if->tx_desc_init = xgbe_tx_desc_init;
2243 hw_if->rx_desc_init = xgbe_rx_desc_init;
2244 hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2245 hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2246 hw_if->is_last_desc = xgbe_is_last_desc;
2247 hw_if->is_context_desc = xgbe_is_context_desc;
2248
2249 /* For FLOW ctrl */
2250 hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2251 hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2252
2253 /* For RX coalescing */
2254 hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2255 hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2256 hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2257 hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2258
2259 /* For RX and TX threshold config */
2260 hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2261 hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2262
2263 /* For RX and TX Store and Forward Mode config */
2264 hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2265 hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2266
2267 /* For TX DMA Operating on Second Frame config */
2268 hw_if->config_osp_mode = xgbe_config_osp_mode;
2269
2270 /* For RX and TX PBL config */
2271 hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2272 hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2273 hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2274 hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2275 hw_if->config_pblx8 = xgbe_config_pblx8;
2276
2277 /* For MMC statistics support */
2278 hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2279 hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2280 hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2281
2282 DBGPR("<--xgbe_init_function_ptrs\n");
2283}