]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/amd/xgbe/xgbe-dev.c
36bc86efc8893757f422ef260f4cd06264ef2919
[karo-tx-linux.git] / drivers / net / ethernet / amd / xgbe / xgbe-dev.c
1 /*
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>
119 #include <asm/cputype.h>
120
121 #include "xgbe.h"
122 #include "xgbe-common.h"
123
124
125 static 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
148 static 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
171 static 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
184 static 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
189 static 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
206 static 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
211 static 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
228 static 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
245 static 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
255 static 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
265 static 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
276 static 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
287 static 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
304 static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
305 {
306         return 0;
307 }
308
309 static 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
324 static 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
338 static 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
363 static 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
393 static 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
400 static 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
407 static 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
417 static 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
427 static 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
433 static 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
476 static 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
492 static 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
502 static 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
509 static 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
516 static 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
523 static 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
537 static 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
551 static 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
629 static 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
643 static 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
671 static 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
696 static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
697 {
698         return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
699 }
700
701 static 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
708 static 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
715 static 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
735 static 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
742 static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
743 {
744         struct xgbe_ring_desc *rdesc = rdata->rdesc;
745
746         /* Reset the Tx descriptor
747          *   Set buffer 1 (lo) address to zero
748          *   Set buffer 1 (hi) address to zero
749          *   Reset all other control bits (IC, TTSE, B2L & B1L)
750          *   Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
751          */
752         rdesc->desc0 = 0;
753         rdesc->desc1 = 0;
754         rdesc->desc2 = 0;
755         rdesc->desc3 = 0;
756 }
757
758 static void xgbe_tx_desc_init(struct xgbe_channel *channel)
759 {
760         struct xgbe_ring *ring = channel->tx_ring;
761         struct xgbe_ring_data *rdata;
762         struct xgbe_ring_desc *rdesc;
763         int i;
764         int start_index = ring->cur;
765
766         DBGPR("-->tx_desc_init\n");
767
768         /* Initialze all descriptors */
769         for (i = 0; i < ring->rdesc_count; i++) {
770                 rdata = GET_DESC_DATA(ring, i);
771                 rdesc = rdata->rdesc;
772
773                 /* Initialize Tx descriptor
774                  *   Set buffer 1 (lo) address to zero
775                  *   Set buffer 1 (hi) address to zero
776                  *   Reset all other control bits (IC, TTSE, B2L & B1L)
777                  *   Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC,
778                  *     etc)
779                  */
780                 rdesc->desc0 = 0;
781                 rdesc->desc1 = 0;
782                 rdesc->desc2 = 0;
783                 rdesc->desc3 = 0;
784         }
785
786         /* Make sure everything is written to the descriptor(s) before
787          * telling the device about them
788          */
789         wmb();
790
791         /* Update the total number of Tx descriptors */
792         XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
793
794         /* Update the starting address of descriptor ring */
795         rdata = GET_DESC_DATA(ring, start_index);
796         XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
797                           upper_32_bits(rdata->rdesc_dma));
798         XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
799                           lower_32_bits(rdata->rdesc_dma));
800
801         DBGPR("<--tx_desc_init\n");
802 }
803
804 static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
805 {
806         struct xgbe_ring_desc *rdesc = rdata->rdesc;
807
808         /* Reset the Rx descriptor
809          *   Set buffer 1 (lo) address to dma address (lo)
810          *   Set buffer 1 (hi) address to dma address (hi)
811          *   Set buffer 2 (lo) address to zero
812          *   Set buffer 2 (hi) address to zero and set control bits
813          *     OWN and INTE
814          */
815         rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
816         rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
817         rdesc->desc2 = 0;
818
819         rdesc->desc3 = 0;
820         if (rdata->interrupt)
821                 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
822
823         /* Since the Rx DMA engine is likely running, make sure everything
824          * is written to the descriptor(s) before setting the OWN bit
825          * for the descriptor
826          */
827         wmb();
828
829         XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
830
831         /* Make sure ownership is written to the descriptor */
832         wmb();
833 }
834
835 static void xgbe_rx_desc_init(struct xgbe_channel *channel)
836 {
837         struct xgbe_prv_data *pdata = channel->pdata;
838         struct xgbe_ring *ring = channel->rx_ring;
839         struct xgbe_ring_data *rdata;
840         struct xgbe_ring_desc *rdesc;
841         unsigned int start_index = ring->cur;
842         unsigned int rx_coalesce, rx_frames;
843         unsigned int i;
844
845         DBGPR("-->rx_desc_init\n");
846
847         rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
848         rx_frames = pdata->rx_frames;
849
850         /* Initialize all descriptors */
851         for (i = 0; i < ring->rdesc_count; i++) {
852                 rdata = GET_DESC_DATA(ring, i);
853                 rdesc = rdata->rdesc;
854
855                 /* Initialize Rx descriptor
856                  *   Set buffer 1 (lo) address to dma address (lo)
857                  *   Set buffer 1 (hi) address to dma address (hi)
858                  *   Set buffer 2 (lo) address to zero
859                  *   Set buffer 2 (hi) address to zero and set control
860                  *     bits OWN and INTE appropriateley
861                  */
862                 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
863                 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
864                 rdesc->desc2 = 0;
865                 rdesc->desc3 = 0;
866                 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
867                 XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
868                 rdata->interrupt = 1;
869                 if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames))) {
870                         /* Clear interrupt on completion bit */
871                         XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE,
872                                           0);
873                         rdata->interrupt = 0;
874                 }
875         }
876
877         /* Make sure everything is written to the descriptors before
878          * telling the device about them
879          */
880         wmb();
881
882         /* Update the total number of Rx descriptors */
883         XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
884
885         /* Update the starting address of descriptor ring */
886         rdata = GET_DESC_DATA(ring, start_index);
887         XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
888                           upper_32_bits(rdata->rdesc_dma));
889         XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
890                           lower_32_bits(rdata->rdesc_dma));
891
892         /* Update the Rx Descriptor Tail Pointer */
893         rdata = GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
894         XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
895                           lower_32_bits(rdata->rdesc_dma));
896
897         DBGPR("<--rx_desc_init\n");
898 }
899
900 static void xgbe_pre_xmit(struct xgbe_channel *channel)
901 {
902         struct xgbe_prv_data *pdata = channel->pdata;
903         struct xgbe_ring *ring = channel->tx_ring;
904         struct xgbe_ring_data *rdata;
905         struct xgbe_ring_desc *rdesc;
906         struct xgbe_packet_data *packet = &ring->packet_data;
907         unsigned int csum, tso, vlan;
908         unsigned int tso_context, vlan_context;
909         unsigned int tx_coalesce, tx_frames;
910         int start_index = ring->cur;
911         int i;
912
913         DBGPR("-->xgbe_pre_xmit\n");
914
915         csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
916                               CSUM_ENABLE);
917         tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
918                              TSO_ENABLE);
919         vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
920                               VLAN_CTAG);
921
922         if (tso && (packet->mss != ring->tx.cur_mss))
923                 tso_context = 1;
924         else
925                 tso_context = 0;
926
927         if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
928                 vlan_context = 1;
929         else
930                 vlan_context = 0;
931
932         tx_coalesce = (pdata->tx_usecs || pdata->tx_frames) ? 1 : 0;
933         tx_frames = pdata->tx_frames;
934         if (tx_coalesce && !channel->tx_timer_active)
935                 ring->coalesce_count = 0;
936
937         rdata = GET_DESC_DATA(ring, ring->cur);
938         rdesc = rdata->rdesc;
939
940         /* Create a context descriptor if this is a TSO packet */
941         if (tso_context || vlan_context) {
942                 if (tso_context) {
943                         DBGPR("  TSO context descriptor, mss=%u\n",
944                               packet->mss);
945
946                         /* Set the MSS size */
947                         XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
948                                           MSS, packet->mss);
949
950                         /* Mark it as a CONTEXT descriptor */
951                         XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
952                                           CTXT, 1);
953
954                         /* Indicate this descriptor contains the MSS */
955                         XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
956                                           TCMSSV, 1);
957
958                         ring->tx.cur_mss = packet->mss;
959                 }
960
961                 if (vlan_context) {
962                         DBGPR("  VLAN context descriptor, ctag=%u\n",
963                               packet->vlan_ctag);
964
965                         /* Mark it as a CONTEXT descriptor */
966                         XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
967                                           CTXT, 1);
968
969                         /* Set the VLAN tag */
970                         XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
971                                           VT, packet->vlan_ctag);
972
973                         /* Indicate this descriptor contains the VLAN tag */
974                         XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
975                                           VLTV, 1);
976
977                         ring->tx.cur_vlan_ctag = packet->vlan_ctag;
978                 }
979
980                 ring->cur++;
981                 rdata = GET_DESC_DATA(ring, ring->cur);
982                 rdesc = rdata->rdesc;
983         }
984
985         /* Update buffer address (for TSO this is the header) */
986         rdesc->desc0 =  cpu_to_le32(lower_32_bits(rdata->skb_dma));
987         rdesc->desc1 =  cpu_to_le32(upper_32_bits(rdata->skb_dma));
988
989         /* Update the buffer length */
990         XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
991                           rdata->skb_dma_len);
992
993         /* VLAN tag insertion check */
994         if (vlan)
995                 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
996                                   TX_NORMAL_DESC2_VLAN_INSERT);
997
998         /* Set IC bit based on Tx coalescing settings */
999         XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1000         if (tx_coalesce && (!tx_frames ||
1001                             (++ring->coalesce_count % tx_frames)))
1002                 /* Clear IC bit */
1003                 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1004
1005         /* Mark it as First Descriptor */
1006         XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
1007
1008         /* Mark it as a NORMAL descriptor */
1009         XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1010
1011         /* Set OWN bit if not the first descriptor */
1012         if (ring->cur != start_index)
1013                 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1014
1015         if (tso) {
1016                 /* Enable TSO */
1017                 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
1018                 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
1019                                   packet->tcp_payload_len);
1020                 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
1021                                   packet->tcp_header_len / 4);
1022         } else {
1023                 /* Enable CRC and Pad Insertion */
1024                 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
1025
1026                 /* Enable HW CSUM */
1027                 if (csum)
1028                         XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1029                                           CIC, 0x3);
1030
1031                 /* Set the total length to be transmitted */
1032                 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
1033                                   packet->length);
1034         }
1035
1036         for (i = ring->cur - start_index + 1; i < packet->rdesc_count; i++) {
1037                 ring->cur++;
1038                 rdata = GET_DESC_DATA(ring, ring->cur);
1039                 rdesc = rdata->rdesc;
1040
1041                 /* Update buffer address */
1042                 rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
1043                 rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
1044
1045                 /* Update the buffer length */
1046                 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
1047                                   rdata->skb_dma_len);
1048
1049                 /* Set IC bit based on Tx coalescing settings */
1050                 XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
1051                 if (tx_coalesce && (!tx_frames ||
1052                                     (++ring->coalesce_count % tx_frames)))
1053                         /* Clear IC bit */
1054                         XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
1055
1056                 /* Set OWN bit */
1057                 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1058
1059                 /* Mark it as NORMAL descriptor */
1060                 XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
1061
1062                 /* Enable HW CSUM */
1063                 if (csum)
1064                         XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
1065                                           CIC, 0x3);
1066         }
1067
1068         /* Set LAST bit for the last descriptor */
1069         XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
1070
1071         /* In case the Tx DMA engine is running, make sure everything
1072          * is written to the descriptor(s) before setting the OWN bit
1073          * for the first descriptor
1074          */
1075         wmb();
1076
1077         /* Set OWN bit for the first descriptor */
1078         rdata = GET_DESC_DATA(ring, start_index);
1079         rdesc = rdata->rdesc;
1080         XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
1081
1082 #ifdef XGMAC_ENABLE_TX_DESC_DUMP
1083         xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
1084 #endif
1085
1086         /* Make sure ownership is written to the descriptor */
1087         wmb();
1088
1089         /* Issue a poll command to Tx DMA by writing address
1090          * of next immediate free descriptor */
1091         ring->cur++;
1092         rdata = GET_DESC_DATA(ring, ring->cur);
1093         XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
1094                           lower_32_bits(rdata->rdesc_dma));
1095
1096         /* Start the Tx coalescing timer */
1097         if (tx_coalesce && !channel->tx_timer_active) {
1098                 channel->tx_timer_active = 1;
1099                 hrtimer_start(&channel->tx_timer,
1100                               ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
1101                               HRTIMER_MODE_REL);
1102         }
1103
1104         DBGPR("  %s: descriptors %u to %u written\n",
1105               channel->name, start_index & (ring->rdesc_count - 1),
1106               (ring->cur - 1) & (ring->rdesc_count - 1));
1107
1108         DBGPR("<--xgbe_pre_xmit\n");
1109 }
1110
1111 static int xgbe_dev_read(struct xgbe_channel *channel)
1112 {
1113         struct xgbe_ring *ring = channel->rx_ring;
1114         struct xgbe_ring_data *rdata;
1115         struct xgbe_ring_desc *rdesc;
1116         struct xgbe_packet_data *packet = &ring->packet_data;
1117         unsigned int err, etlt;
1118
1119         DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
1120
1121         rdata = GET_DESC_DATA(ring, ring->cur);
1122         rdesc = rdata->rdesc;
1123
1124         /* Check for data availability */
1125         if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
1126                 return 1;
1127
1128 #ifdef XGMAC_ENABLE_RX_DESC_DUMP
1129         xgbe_dump_rx_desc(ring, rdesc, ring->cur);
1130 #endif
1131
1132         /* Get the packet length */
1133         rdata->len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
1134
1135         if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
1136                 /* Not all the data has been transferred for this packet */
1137                 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1138                                INCOMPLETE, 1);
1139                 return 0;
1140         }
1141
1142         /* This is the last of the data for this packet */
1143         XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1144                        INCOMPLETE, 0);
1145
1146         /* Set checksum done indicator as appropriate */
1147         if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
1148                 XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1149                                CSUM_DONE, 1);
1150
1151         /* Check for errors (only valid in last descriptor) */
1152         err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
1153         etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
1154         DBGPR("  err=%u, etlt=%#x\n", err, etlt);
1155
1156         if (!err || (err && !etlt)) {
1157                 if (etlt == 0x09) {
1158                         XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1159                                        VLAN_CTAG, 1);
1160                         packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
1161                                                               RX_NORMAL_DESC0,
1162                                                               OVT);
1163                         DBGPR("  vlan-ctag=0x%04x\n", packet->vlan_ctag);
1164                 }
1165         } else {
1166                 if ((etlt == 0x05) || (etlt == 0x06))
1167                         XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
1168                                        CSUM_DONE, 0);
1169                 else
1170                         XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
1171                                        FRAME, 1);
1172         }
1173
1174         DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
1175               ring->cur & (ring->rdesc_count - 1), ring->cur);
1176
1177         return 0;
1178 }
1179
1180 static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
1181 {
1182         /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
1183         return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
1184 }
1185
1186 static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
1187 {
1188         /* Rx and Tx share LD bit, so check TDES3.LD bit */
1189         return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
1190 }
1191
1192 static void xgbe_save_interrupt_status(struct xgbe_channel *channel,
1193                                        enum xgbe_int_state int_state)
1194 {
1195         unsigned int dma_ch_ier;
1196
1197         if (int_state == XGMAC_INT_STATE_SAVE) {
1198                 channel->saved_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1199                 channel->saved_ier &= DMA_INTERRUPT_MASK;
1200         } else {
1201                 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1202                 dma_ch_ier |= channel->saved_ier;
1203                 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1204         }
1205 }
1206
1207 static int xgbe_enable_int(struct xgbe_channel *channel,
1208                            enum xgbe_int int_id)
1209 {
1210         switch (int_id) {
1211         case XGMAC_INT_DMA_ISR_DC0IS:
1212                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 1);
1213                 break;
1214         case XGMAC_INT_DMA_CH_SR_TI:
1215                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 1);
1216                 break;
1217         case XGMAC_INT_DMA_CH_SR_TPS:
1218                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TXSE, 1);
1219                 break;
1220         case XGMAC_INT_DMA_CH_SR_TBU:
1221                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TBUE, 1);
1222                 break;
1223         case XGMAC_INT_DMA_CH_SR_RI:
1224                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RIE, 1);
1225                 break;
1226         case XGMAC_INT_DMA_CH_SR_RBU:
1227                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RBUE, 1);
1228                 break;
1229         case XGMAC_INT_DMA_CH_SR_RPS:
1230                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RSE, 1);
1231                 break;
1232         case XGMAC_INT_DMA_CH_SR_FBE:
1233                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, FBEE, 1);
1234                 break;
1235         case XGMAC_INT_DMA_ALL:
1236                 xgbe_save_interrupt_status(channel, XGMAC_INT_STATE_RESTORE);
1237                 break;
1238         default:
1239                 return -1;
1240         }
1241
1242         return 0;
1243 }
1244
1245 static int xgbe_disable_int(struct xgbe_channel *channel,
1246                             enum xgbe_int int_id)
1247 {
1248         unsigned int dma_ch_ier;
1249
1250         switch (int_id) {
1251         case XGMAC_INT_DMA_ISR_DC0IS:
1252                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 0);
1253                 break;
1254         case XGMAC_INT_DMA_CH_SR_TI:
1255                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 0);
1256                 break;
1257         case XGMAC_INT_DMA_CH_SR_TPS:
1258                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TXSE, 0);
1259                 break;
1260         case XGMAC_INT_DMA_CH_SR_TBU:
1261                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TBUE, 0);
1262                 break;
1263         case XGMAC_INT_DMA_CH_SR_RI:
1264                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RIE, 0);
1265                 break;
1266         case XGMAC_INT_DMA_CH_SR_RBU:
1267                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RBUE, 0);
1268                 break;
1269         case XGMAC_INT_DMA_CH_SR_RPS:
1270                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RSE, 0);
1271                 break;
1272         case XGMAC_INT_DMA_CH_SR_FBE:
1273                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, FBEE, 0);
1274                 break;
1275         case XGMAC_INT_DMA_ALL:
1276                 xgbe_save_interrupt_status(channel, XGMAC_INT_STATE_SAVE);
1277
1278                 dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
1279                 dma_ch_ier &= ~DMA_INTERRUPT_MASK;
1280                 XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
1281                 break;
1282         default:
1283                 return -1;
1284         }
1285
1286         return 0;
1287 }
1288
1289 static int xgbe_exit(struct xgbe_prv_data *pdata)
1290 {
1291         unsigned int count = 2000;
1292
1293         DBGPR("-->xgbe_exit\n");
1294
1295         /* Issue a software reset */
1296         XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
1297         usleep_range(10, 15);
1298
1299         /* Poll Until Poll Condition */
1300         while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
1301                 usleep_range(500, 600);
1302
1303         if (!count)
1304                 return -EBUSY;
1305
1306         DBGPR("<--xgbe_exit\n");
1307
1308         return 0;
1309 }
1310
1311 static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
1312 {
1313         unsigned int i, count;
1314
1315         for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1316                 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
1317
1318         /* Poll Until Poll Condition */
1319         for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++) {
1320                 count = 2000;
1321                 while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
1322                                                         MTL_Q_TQOMR, FTQ))
1323                         usleep_range(500, 600);
1324
1325                 if (!count)
1326                         return -EBUSY;
1327         }
1328
1329         return 0;
1330 }
1331
1332 static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
1333 {
1334         /* Set enhanced addressing mode */
1335         XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
1336
1337         /* Set the System Bus mode */
1338         XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
1339 }
1340
1341 static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
1342 {
1343         unsigned int arcache, awcache;
1344
1345         arcache = 0;
1346         XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, DMA_ARCACHE_SETTING);
1347         XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, DMA_ARDOMAIN_SETTING);
1348         XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, DMA_ARCACHE_SETTING);
1349         XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, DMA_ARDOMAIN_SETTING);
1350         XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, DMA_ARCACHE_SETTING);
1351         XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, DMA_ARDOMAIN_SETTING);
1352         XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
1353
1354         awcache = 0;
1355         XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, DMA_AWCACHE_SETTING);
1356         XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, DMA_AWDOMAIN_SETTING);
1357         XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, DMA_AWCACHE_SETTING);
1358         XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, DMA_AWDOMAIN_SETTING);
1359         XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, DMA_AWCACHE_SETTING);
1360         XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, DMA_AWDOMAIN_SETTING);
1361         XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, DMA_AWCACHE_SETTING);
1362         XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, DMA_AWDOMAIN_SETTING);
1363         XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
1364 }
1365
1366 static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
1367 {
1368         unsigned int i;
1369
1370         /* Set Tx to weighted round robin scheduling algorithm (when
1371          * traffic class is using ETS algorithm)
1372          */
1373         XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
1374
1375         /* Set Tx traffic classes to strict priority algorithm */
1376         for (i = 0; i < XGBE_TC_CNT; i++)
1377                 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, MTL_TSA_SP);
1378
1379         /* Set Rx to strict priority algorithm */
1380         XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
1381 }
1382
1383 static unsigned int xgbe_calculate_per_queue_fifo(unsigned long fifo_size,
1384                                                   unsigned char queue_count)
1385 {
1386         unsigned int q_fifo_size = 0;
1387         enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1388
1389         /* Calculate Tx/Rx fifo share per queue */
1390         switch (fifo_size) {
1391         case 0:
1392                 q_fifo_size = FIFO_SIZE_B(128);
1393                 break;
1394         case 1:
1395                 q_fifo_size = FIFO_SIZE_B(256);
1396                 break;
1397         case 2:
1398                 q_fifo_size = FIFO_SIZE_B(512);
1399                 break;
1400         case 3:
1401                 q_fifo_size = FIFO_SIZE_KB(1);
1402                 break;
1403         case 4:
1404                 q_fifo_size = FIFO_SIZE_KB(2);
1405                 break;
1406         case 5:
1407                 q_fifo_size = FIFO_SIZE_KB(4);
1408                 break;
1409         case 6:
1410                 q_fifo_size = FIFO_SIZE_KB(8);
1411                 break;
1412         case 7:
1413                 q_fifo_size = FIFO_SIZE_KB(16);
1414                 break;
1415         case 8:
1416                 q_fifo_size = FIFO_SIZE_KB(32);
1417                 break;
1418         case 9:
1419                 q_fifo_size = FIFO_SIZE_KB(64);
1420                 break;
1421         case 10:
1422                 q_fifo_size = FIFO_SIZE_KB(128);
1423                 break;
1424         case 11:
1425                 q_fifo_size = FIFO_SIZE_KB(256);
1426                 break;
1427         }
1428         q_fifo_size = q_fifo_size / queue_count;
1429
1430         /* Set the queue fifo size programmable value */
1431         if (q_fifo_size >= FIFO_SIZE_KB(256))
1432                 p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
1433         else if (q_fifo_size >= FIFO_SIZE_KB(128))
1434                 p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
1435         else if (q_fifo_size >= FIFO_SIZE_KB(64))
1436                 p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
1437         else if (q_fifo_size >= FIFO_SIZE_KB(32))
1438                 p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
1439         else if (q_fifo_size >= FIFO_SIZE_KB(16))
1440                 p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
1441         else if (q_fifo_size >= FIFO_SIZE_KB(8))
1442                 p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
1443         else if (q_fifo_size >= FIFO_SIZE_KB(4))
1444                 p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
1445         else if (q_fifo_size >= FIFO_SIZE_KB(2))
1446                 p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
1447         else if (q_fifo_size >= FIFO_SIZE_KB(1))
1448                 p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
1449         else if (q_fifo_size >= FIFO_SIZE_B(512))
1450                 p_fifo = XGMAC_MTL_FIFO_SIZE_512;
1451         else if (q_fifo_size >= FIFO_SIZE_B(256))
1452                 p_fifo = XGMAC_MTL_FIFO_SIZE_256;
1453
1454         return p_fifo;
1455 }
1456
1457 static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
1458 {
1459         enum xgbe_mtl_fifo_size fifo_size;
1460         unsigned int i;
1461
1462         fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
1463                                                   pdata->hw_feat.tx_q_cnt);
1464
1465         for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1466                 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
1467
1468         netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
1469                       pdata->hw_feat.tx_q_cnt, ((fifo_size + 1) * 256));
1470 }
1471
1472 static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
1473 {
1474         enum xgbe_mtl_fifo_size fifo_size;
1475         unsigned int i;
1476
1477         fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
1478                                                   pdata->hw_feat.rx_q_cnt);
1479
1480         for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
1481                 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
1482
1483         netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
1484                       pdata->hw_feat.rx_q_cnt, ((fifo_size + 1) * 256));
1485 }
1486
1487 static void xgbe_config_rx_queue_mapping(struct xgbe_prv_data *pdata)
1488 {
1489         unsigned int i, reg, reg_val;
1490         unsigned int q_count = pdata->hw_feat.rx_q_cnt;
1491
1492         /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
1493         reg = MTL_RQDCM0R;
1494         reg_val = 0;
1495         for (i = 0; i < q_count;) {
1496                 reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
1497
1498                 if ((i % MTL_RQDCM_Q_PER_REG) && (i != q_count))
1499                         continue;
1500
1501                 XGMAC_IOWRITE(pdata, reg, reg_val);
1502
1503                 reg += MTL_RQDCM_INC;
1504                 reg_val = 0;
1505         }
1506 }
1507
1508 static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
1509 {
1510         unsigned int i;
1511
1512         for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++) {
1513                 /* Activate flow control when less than 4k left in fifo */
1514                 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
1515
1516                 /* De-activate flow control when more than 6k left in fifo */
1517                 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
1518         }
1519 }
1520
1521 static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
1522 {
1523         xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
1524 }
1525
1526 static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
1527 {
1528         unsigned int val;
1529
1530         val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
1531
1532         XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1533 }
1534
1535 static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
1536 {
1537         if (pdata->netdev->features & NETIF_F_RXCSUM)
1538                 xgbe_enable_rx_csum(pdata);
1539         else
1540                 xgbe_disable_rx_csum(pdata);
1541 }
1542
1543 static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
1544 {
1545         if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
1546                 xgbe_enable_rx_vlan_stripping(pdata);
1547         else
1548                 xgbe_disable_rx_vlan_stripping(pdata);
1549 }
1550
1551 static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
1552 {
1553         struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1554         unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
1555
1556         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
1557                 stats->txoctetcount_gb +=
1558                         XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
1559
1560         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
1561                 stats->txframecount_gb +=
1562                         XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
1563
1564         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
1565                 stats->txbroadcastframes_g +=
1566                         XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1567
1568         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
1569                 stats->txmulticastframes_g +=
1570                         XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1571
1572         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
1573                 stats->tx64octets_gb +=
1574                         XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
1575
1576         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
1577                 stats->tx65to127octets_gb +=
1578                         XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
1579
1580         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
1581                 stats->tx128to255octets_gb +=
1582                         XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
1583
1584         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
1585                 stats->tx256to511octets_gb +=
1586                         XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
1587
1588         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
1589                 stats->tx512to1023octets_gb +=
1590                         XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1591
1592         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
1593                 stats->tx1024tomaxoctets_gb +=
1594                         XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1595
1596         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
1597                 stats->txunicastframes_gb +=
1598                         XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
1599
1600         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
1601                 stats->txmulticastframes_gb +=
1602                         XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
1603
1604         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
1605                 stats->txbroadcastframes_g +=
1606                         XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
1607
1608         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
1609                 stats->txunderflowerror +=
1610                         XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
1611
1612         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
1613                 stats->txoctetcount_g +=
1614                         XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
1615
1616         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
1617                 stats->txframecount_g +=
1618                         XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
1619
1620         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
1621                 stats->txpauseframes +=
1622                         XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
1623
1624         if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
1625                 stats->txvlanframes_g +=
1626                         XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
1627 }
1628
1629 static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
1630 {
1631         struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1632         unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
1633
1634         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
1635                 stats->rxframecount_gb +=
1636                         XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
1637
1638         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
1639                 stats->rxoctetcount_gb +=
1640                         XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
1641
1642         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
1643                 stats->rxoctetcount_g +=
1644                         XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
1645
1646         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
1647                 stats->rxbroadcastframes_g +=
1648                         XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
1649
1650         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
1651                 stats->rxmulticastframes_g +=
1652                         XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
1653
1654         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
1655                 stats->rxcrcerror +=
1656                         XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
1657
1658         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
1659                 stats->rxrunterror +=
1660                         XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
1661
1662         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
1663                 stats->rxjabbererror +=
1664                         XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
1665
1666         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
1667                 stats->rxundersize_g +=
1668                         XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
1669
1670         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
1671                 stats->rxoversize_g +=
1672                         XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
1673
1674         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
1675                 stats->rx64octets_gb +=
1676                         XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
1677
1678         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
1679                 stats->rx65to127octets_gb +=
1680                         XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
1681
1682         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
1683                 stats->rx128to255octets_gb +=
1684                         XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
1685
1686         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
1687                 stats->rx256to511octets_gb +=
1688                         XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
1689
1690         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
1691                 stats->rx512to1023octets_gb +=
1692                         XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
1693
1694         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
1695                 stats->rx1024tomaxoctets_gb +=
1696                         XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
1697
1698         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
1699                 stats->rxunicastframes_g +=
1700                         XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
1701
1702         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
1703                 stats->rxlengtherror +=
1704                         XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
1705
1706         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
1707                 stats->rxoutofrangetype +=
1708                         XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
1709
1710         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
1711                 stats->rxpauseframes +=
1712                         XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
1713
1714         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
1715                 stats->rxfifooverflow +=
1716                         XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
1717
1718         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
1719                 stats->rxvlanframes_gb +=
1720                         XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
1721
1722         if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
1723                 stats->rxwatchdogerror +=
1724                         XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
1725 }
1726
1727 static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
1728 {
1729         struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
1730
1731         /* Freeze counters */
1732         XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
1733
1734         stats->txoctetcount_gb +=
1735                 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
1736
1737         stats->txframecount_gb +=
1738                 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
1739
1740         stats->txbroadcastframes_g +=
1741                 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
1742
1743         stats->txmulticastframes_g +=
1744                 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
1745
1746         stats->tx64octets_gb +=
1747                 XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
1748
1749         stats->tx65to127octets_gb +=
1750                 XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
1751
1752         stats->tx128to255octets_gb +=
1753                 XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
1754
1755         stats->tx256to511octets_gb +=
1756                 XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
1757
1758         stats->tx512to1023octets_gb +=
1759                 XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
1760
1761         stats->tx1024tomaxoctets_gb +=
1762                 XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
1763
1764         stats->txunicastframes_gb +=
1765                 XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
1766
1767         stats->txmulticastframes_gb +=
1768                 XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
1769
1770         stats->txbroadcastframes_g +=
1771                 XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
1772
1773         stats->txunderflowerror +=
1774                 XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
1775
1776         stats->txoctetcount_g +=
1777                 XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
1778
1779         stats->txframecount_g +=
1780                 XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
1781
1782         stats->txpauseframes +=
1783                 XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
1784
1785         stats->txvlanframes_g +=
1786                 XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
1787
1788         stats->rxframecount_gb +=
1789                 XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
1790
1791         stats->rxoctetcount_gb +=
1792                 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
1793
1794         stats->rxoctetcount_g +=
1795                 XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
1796
1797         stats->rxbroadcastframes_g +=
1798                 XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
1799
1800         stats->rxmulticastframes_g +=
1801                 XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
1802
1803         stats->rxcrcerror +=
1804                 XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
1805
1806         stats->rxrunterror +=
1807                 XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
1808
1809         stats->rxjabbererror +=
1810                 XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
1811
1812         stats->rxundersize_g +=
1813                 XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
1814
1815         stats->rxoversize_g +=
1816                 XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
1817
1818         stats->rx64octets_gb +=
1819                 XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
1820
1821         stats->rx65to127octets_gb +=
1822                 XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
1823
1824         stats->rx128to255octets_gb +=
1825                 XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
1826
1827         stats->rx256to511octets_gb +=
1828                 XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
1829
1830         stats->rx512to1023octets_gb +=
1831                 XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
1832
1833         stats->rx1024tomaxoctets_gb +=
1834                 XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
1835
1836         stats->rxunicastframes_g +=
1837                 XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
1838
1839         stats->rxlengtherror +=
1840                 XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
1841
1842         stats->rxoutofrangetype +=
1843                 XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
1844
1845         stats->rxpauseframes +=
1846                 XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
1847
1848         stats->rxfifooverflow +=
1849                 XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
1850
1851         stats->rxvlanframes_gb +=
1852                 XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
1853
1854         stats->rxwatchdogerror +=
1855                 XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
1856
1857         /* Un-freeze counters */
1858         XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
1859 }
1860
1861 static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
1862 {
1863         /* Set counters to reset on read */
1864         XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
1865
1866         /* Reset the counters */
1867         XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
1868 }
1869
1870 static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
1871 {
1872         struct xgbe_channel *channel;
1873         unsigned int i;
1874
1875         /* Enable each Tx DMA channel */
1876         channel = pdata->channel;
1877         for (i = 0; i < pdata->channel_count; i++, channel++) {
1878                 if (!channel->tx_ring)
1879                         break;
1880
1881                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
1882         }
1883
1884         /* Enable each Tx queue */
1885         for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1886                 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
1887                                        MTL_Q_ENABLED);
1888
1889         /* Enable MAC Tx */
1890         XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
1891 }
1892
1893 static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
1894 {
1895         struct xgbe_channel *channel;
1896         unsigned int i;
1897
1898         /* Disable MAC Tx */
1899         XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
1900
1901         /* Disable each Tx queue */
1902         for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
1903                 XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
1904
1905         /* Disable each Tx DMA channel */
1906         channel = pdata->channel;
1907         for (i = 0; i < pdata->channel_count; i++, channel++) {
1908                 if (!channel->tx_ring)
1909                         break;
1910
1911                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
1912         }
1913 }
1914
1915 static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
1916 {
1917         struct xgbe_channel *channel;
1918         unsigned int reg_val, i;
1919
1920         /* Enable each Rx DMA channel */
1921         channel = pdata->channel;
1922         for (i = 0; i < pdata->channel_count; i++, channel++) {
1923                 if (!channel->rx_ring)
1924                         break;
1925
1926                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
1927         }
1928
1929         /* Enable each Rx queue */
1930         reg_val = 0;
1931         for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
1932                 reg_val |= (0x02 << (i << 1));
1933         XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
1934
1935         /* Enable MAC Rx */
1936         XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
1937         XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
1938         XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
1939         XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
1940 }
1941
1942 static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
1943 {
1944         struct xgbe_channel *channel;
1945         unsigned int i;
1946
1947         /* Disable MAC Rx */
1948         XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
1949         XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
1950         XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
1951         XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
1952
1953         /* Disable each Rx queue */
1954         XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
1955
1956         /* Disable each Rx DMA channel */
1957         channel = pdata->channel;
1958         for (i = 0; i < pdata->channel_count; i++, channel++) {
1959                 if (!channel->rx_ring)
1960                         break;
1961
1962                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
1963         }
1964 }
1965
1966 static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
1967 {
1968         struct xgbe_channel *channel;
1969         unsigned int i;
1970
1971         /* Enable each Tx DMA channel */
1972         channel = pdata->channel;
1973         for (i = 0; i < pdata->channel_count; i++, channel++) {
1974                 if (!channel->tx_ring)
1975                         break;
1976
1977                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
1978         }
1979
1980         /* Enable MAC Tx */
1981         XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
1982 }
1983
1984 static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
1985 {
1986         struct xgbe_channel *channel;
1987         unsigned int i;
1988
1989         /* Disable MAC Tx */
1990         XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
1991
1992         /* Disable each Tx DMA channel */
1993         channel = pdata->channel;
1994         for (i = 0; i < pdata->channel_count; i++, channel++) {
1995                 if (!channel->tx_ring)
1996                         break;
1997
1998                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
1999         }
2000 }
2001
2002 static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
2003 {
2004         struct xgbe_channel *channel;
2005         unsigned int i;
2006
2007         /* Enable each Rx DMA channel */
2008         channel = pdata->channel;
2009         for (i = 0; i < pdata->channel_count; i++, channel++) {
2010                 if (!channel->rx_ring)
2011                         break;
2012
2013                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
2014         }
2015 }
2016
2017 static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
2018 {
2019         struct xgbe_channel *channel;
2020         unsigned int i;
2021
2022         /* Disable each Rx DMA channel */
2023         channel = pdata->channel;
2024         for (i = 0; i < pdata->channel_count; i++, channel++) {
2025                 if (!channel->rx_ring)
2026                         break;
2027
2028                 XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
2029         }
2030 }
2031
2032 static int xgbe_init(struct xgbe_prv_data *pdata)
2033 {
2034         struct xgbe_desc_if *desc_if = &pdata->desc_if;
2035         int ret;
2036
2037         DBGPR("-->xgbe_init\n");
2038
2039         /* Flush Tx queues */
2040         ret = xgbe_flush_tx_queues(pdata);
2041         if (ret)
2042                 return ret;
2043
2044         /*
2045          * Initialize DMA related features
2046          */
2047         xgbe_config_dma_bus(pdata);
2048         xgbe_config_dma_cache(pdata);
2049         xgbe_config_osp_mode(pdata);
2050         xgbe_config_pblx8(pdata);
2051         xgbe_config_tx_pbl_val(pdata);
2052         xgbe_config_rx_pbl_val(pdata);
2053         xgbe_config_rx_coalesce(pdata);
2054         xgbe_config_tx_coalesce(pdata);
2055         xgbe_config_rx_buffer_size(pdata);
2056         xgbe_config_tso_mode(pdata);
2057         desc_if->wrapper_tx_desc_init(pdata);
2058         desc_if->wrapper_rx_desc_init(pdata);
2059         xgbe_enable_dma_interrupts(pdata);
2060
2061         /*
2062          * Initialize MTL related features
2063          */
2064         xgbe_config_mtl_mode(pdata);
2065         xgbe_config_rx_queue_mapping(pdata);
2066         /*TODO: Program the priorities mapped to the Selected Traffic Classes
2067                 in MTL_TC_Prty_Map0-3 registers */
2068         xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
2069         xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
2070         xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
2071         xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
2072         xgbe_config_tx_fifo_size(pdata);
2073         xgbe_config_rx_fifo_size(pdata);
2074         xgbe_config_flow_control_threshold(pdata);
2075         /*TODO: Queue to Traffic Class Mapping (Q2TCMAP) */
2076         /*TODO: Error Packet and undersized good Packet forwarding enable
2077                 (FEP and FUP)
2078          */
2079         xgbe_enable_mtl_interrupts(pdata);
2080
2081         /* Transmit Class Weight */
2082         XGMAC_IOWRITE_BITS(pdata, MTL_Q_TCQWR, QW, 0x10);
2083
2084         /*
2085          * Initialize MAC related features
2086          */
2087         xgbe_config_mac_address(pdata);
2088         xgbe_config_jumbo_enable(pdata);
2089         xgbe_config_flow_control(pdata);
2090         xgbe_config_checksum_offload(pdata);
2091         xgbe_config_vlan_support(pdata);
2092         xgbe_config_mmc(pdata);
2093         xgbe_enable_mac_interrupts(pdata);
2094
2095         DBGPR("<--xgbe_init\n");
2096
2097         return 0;
2098 }
2099
2100 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
2101 {
2102         DBGPR("-->xgbe_init_function_ptrs\n");
2103
2104         hw_if->tx_complete = xgbe_tx_complete;
2105
2106         hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
2107         hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
2108         hw_if->set_addn_mac_addrs = xgbe_set_addn_mac_addrs;
2109         hw_if->set_mac_address = xgbe_set_mac_address;
2110
2111         hw_if->enable_rx_csum = xgbe_enable_rx_csum;
2112         hw_if->disable_rx_csum = xgbe_disable_rx_csum;
2113
2114         hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
2115         hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
2116
2117         hw_if->read_mmd_regs = xgbe_read_mmd_regs;
2118         hw_if->write_mmd_regs = xgbe_write_mmd_regs;
2119
2120         hw_if->set_gmii_speed = xgbe_set_gmii_speed;
2121         hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
2122         hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
2123
2124         hw_if->enable_tx = xgbe_enable_tx;
2125         hw_if->disable_tx = xgbe_disable_tx;
2126         hw_if->enable_rx = xgbe_enable_rx;
2127         hw_if->disable_rx = xgbe_disable_rx;
2128
2129         hw_if->powerup_tx = xgbe_powerup_tx;
2130         hw_if->powerdown_tx = xgbe_powerdown_tx;
2131         hw_if->powerup_rx = xgbe_powerup_rx;
2132         hw_if->powerdown_rx = xgbe_powerdown_rx;
2133
2134         hw_if->pre_xmit = xgbe_pre_xmit;
2135         hw_if->dev_read = xgbe_dev_read;
2136         hw_if->enable_int = xgbe_enable_int;
2137         hw_if->disable_int = xgbe_disable_int;
2138         hw_if->init = xgbe_init;
2139         hw_if->exit = xgbe_exit;
2140
2141         /* Descriptor related Sequences have to be initialized here */
2142         hw_if->tx_desc_init = xgbe_tx_desc_init;
2143         hw_if->rx_desc_init = xgbe_rx_desc_init;
2144         hw_if->tx_desc_reset = xgbe_tx_desc_reset;
2145         hw_if->rx_desc_reset = xgbe_rx_desc_reset;
2146         hw_if->is_last_desc = xgbe_is_last_desc;
2147         hw_if->is_context_desc = xgbe_is_context_desc;
2148
2149         /* For FLOW ctrl */
2150         hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
2151         hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
2152
2153         /* For RX coalescing */
2154         hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
2155         hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
2156         hw_if->usec_to_riwt = xgbe_usec_to_riwt;
2157         hw_if->riwt_to_usec = xgbe_riwt_to_usec;
2158
2159         /* For RX and TX threshold config */
2160         hw_if->config_rx_threshold = xgbe_config_rx_threshold;
2161         hw_if->config_tx_threshold = xgbe_config_tx_threshold;
2162
2163         /* For RX and TX Store and Forward Mode config */
2164         hw_if->config_rsf_mode = xgbe_config_rsf_mode;
2165         hw_if->config_tsf_mode = xgbe_config_tsf_mode;
2166
2167         /* For TX DMA Operating on Second Frame config */
2168         hw_if->config_osp_mode = xgbe_config_osp_mode;
2169
2170         /* For RX and TX PBL config */
2171         hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
2172         hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
2173         hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
2174         hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
2175         hw_if->config_pblx8 = xgbe_config_pblx8;
2176
2177         /* For MMC statistics support */
2178         hw_if->tx_mmc_int = xgbe_tx_mmc_int;
2179         hw_if->rx_mmc_int = xgbe_rx_mmc_int;
2180         hw_if->read_mmc_stats = xgbe_read_mmc_stats;
2181
2182         DBGPR("<--xgbe_init_function_ptrs\n");
2183 }