]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - drivers/net/ethernet/nvidia/eqos/drv.c
9e095028c9397f70cf7b1707b36299f410b56e91
[hercules2020/nv-tegra/linux-4.4.git] / drivers / net / ethernet / nvidia / eqos / drv.c
1 /* =========================================================================
2  * The Synopsys DWC ETHER QOS Software Driver and documentation (hereinafter
3  * "Software") is an unsupported proprietary work of Synopsys, Inc. unless
4  * otherwise expressly agreed to in writing between Synopsys and you.
5  *
6  * The Software IS NOT an item of Licensed Software or Licensed Product under
7  * any End User Software License Agreement or Agreement for Licensed Product
8  * with Synopsys or any supplement thereto.  Permission is hereby granted,
9  * free of charge, to any person obtaining a copy of this software annotated
10  * with this license and the Software, to deal in the Software without
11  * restriction, including without limitation the rights to use, copy, modify,
12  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
13  * and to permit persons to whom the Software is furnished to do so, subject
14  * to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29  * DAMAGE.
30  * ========================================================================= */
31 /*
32  * Copyright (c) 2015-2017, NVIDIA CORPORATION.  All rights reserved.
33  *
34  * This program is free software; you can redistribute it and/or modify it
35  * under the terms and conditions of the GNU General Public License,
36  * version 2, as published by the Free Software Foundation.
37  *
38  * This program is distributed in the hope it will be useful, but WITHOUT
39  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
40  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
41  * more details.
42  */
43 /*!@file: eqos_drv.c
44  * @brief: Driver functions.
45  */
46
47 #include <linux/gpio.h>
48 #include <linux/time.h>
49 #include "yheader.h"
50 #include "yapphdr.h"
51 #include "drv.h"
52
53 extern ULONG eqos_base_addr;
54 #include "yregacc.h"
55 #include "nvregacc.h"
56 #include <linux/inet_lro.h>
57 #include <soc/tegra/chip-id.h>
58
59 static INT eqos_status;
60 static int handle_txrx_completions(struct eqos_prv_data *pdata, int qinx);
61
62 /* raw spinlock to get HW PTP time and kernel time atomically */
63 static DEFINE_RAW_SPINLOCK(eqos_ts_lock);
64
65 /* SA(Source Address) operations on TX */
66 unsigned char mac_addr0[6] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
67 unsigned char mac_addr1[6] = { 0x00, 0x66, 0x77, 0x88, 0x99, 0xaa };
68
69 /* module parameters for configuring the queue modes
70  * set default mode as GENERIC
71  * */
72 /* Value of "2" enables mtl tx q */
73 static int q_op_mode[EQOS_MAX_TX_QUEUE_CNT] = {
74         2,
75         2,
76         2,
77         2,
78         2,
79         2,
80         2,
81         2
82 };
83
84 /* Store the IRQ names to be used by /proc/interrupts */
85 static char irq_names[8][32];
86
87 module_param_array(q_op_mode, int, NULL, S_IRUGO | S_IWUSR);
88 MODULE_PARM_DESC(q_op_mode,
89                  "MTL queue operation mode [0-DISABLED, 1-AVB, 2-DCB, 3-GENERIC]");
90
91 void eqos_stop_all_ch_tx_dma(struct eqos_prv_data *pdata)
92 {
93         struct hw_if_struct *hw_if = &(pdata->hw_if);
94         UINT qinx;
95
96         pr_debug("-->eqos_stop_all_ch_tx_dma\n");
97
98         for (qinx = 0; qinx < EQOS_TX_QUEUE_CNT; qinx++)
99                 hw_if->stop_dma_tx(pdata, qinx);
100
101         pr_debug("<--eqos_stop_all_ch_tx_dma\n");
102 }
103
104 static int is_ptp_addr(char *addr)
105 {
106         if ((addr[0] == PTP1_MAC0) &&
107             (addr[1] == PTP1_MAC1) &&
108             (addr[2] == PTP1_MAC2) &&
109             (addr[3] == PTP1_MAC3) &&
110             (addr[4] == PTP1_MAC4) && (addr[5] == PTP1_MAC5))
111                 return 1;
112         else if ((addr[0] == PTP2_MAC0) &&
113                  (addr[1] == PTP2_MAC1) &&
114                  (addr[2] == PTP2_MAC2) &&
115                  (addr[3] == PTP2_MAC3) &&
116                  (addr[4] == PTP2_MAC4) && (addr[5] == PTP2_MAC5))
117                 return 1;
118         else
119                 return 0;
120 }
121
122 /*Check if Channel 0 is PTP and has data 0xee
123   Check if Channel 1 is AV and has data 0xbb or 0xcc
124   Check if Channel 2 is AV and has data 0xdd*/
125 #ifdef ENABLE_CHANNEL_DATA_CHECK
126 static void check_channel_data(struct sk_buff *skb, unsigned int qinx,
127         int is_rx)
128 {
129         if (((qinx == 0) &&
130                 ((*(((short *)skb->data) + 6)  & 0xFFFF) == 0xF788) &&
131                 ((*(((char *)skb->data) + 80) & 0xFF) != 0xee)) ||
132            ((qinx == 1) &&
133                 ((*(((short *)skb->data) + 6)  & 0xFFFF) == 0xF022) &&
134                 (((*(((char *)skb->data) + 80) & 0xFF) != 0xbb) &&
135                 ((*(((char *)skb->data) + 80) & 0xFF) != 0xcc))) ||
136            ((qinx == 2) &&
137                 ((*(((short *)skb->data) + 6) & 0xFFFF) == 0xF022) &&
138                 ((*(((char *)skb->data) + 80) & 0xFF) != 0xdd))) {
139                         while (1)
140                 pr_err("Incorrect %s data 0x%x in Q %d\n",
141                 ((is_rx) ? "RX" : "TX"), *(((char *)skb->data) + 80), qinx);
142         }
143 }
144 #endif
145
146 static void eqos_stop_all_ch_rx_dma(struct eqos_prv_data *pdata)
147 {
148         struct hw_if_struct *hw_if = &(pdata->hw_if);
149         UINT qinx;
150
151         pr_debug("-->eqos_stop_all_ch_rx_dma\n");
152
153         for (qinx = 0; qinx < EQOS_RX_QUEUE_CNT; qinx++)
154                 hw_if->stop_dma_rx(qinx);
155
156         pr_debug("<--eqos_stop_all_ch_rx_dma\n");
157 }
158
159 static void eqos_start_all_ch_tx_dma(struct eqos_prv_data *pdata)
160 {
161         struct hw_if_struct *hw_if = &(pdata->hw_if);
162         UINT i;
163
164         pr_debug("-->eqos_start_all_ch_tx_dma\n");
165
166         for (i = 0; i < EQOS_TX_QUEUE_CNT; i++)
167                 hw_if->start_dma_tx(i);
168
169         pr_debug("<--eqos_start_all_ch_tx_dma\n");
170 }
171
172 static void eqos_start_all_ch_rx_dma(struct eqos_prv_data *pdata)
173 {
174         struct hw_if_struct *hw_if = &(pdata->hw_if);
175         UINT i;
176
177         pr_debug("-->eqos_start_all_ch_rx_dma\n");
178
179         for (i = 0; i < EQOS_RX_QUEUE_CNT; i++)
180                 hw_if->start_dma_rx(i);
181
182         pr_debug("<--eqos_start_all_ch_rx_dma\n");
183 }
184
185 static void eqos_napi_enable_mq(struct eqos_prv_data *pdata)
186 {
187         struct eqos_rx_queue *rx_queue = NULL;
188         int qinx;
189
190         pr_debug("-->eqos_napi_enable_mq\n");
191
192         for (qinx = 0; qinx < EQOS_RX_QUEUE_CNT; qinx++) {
193                 rx_queue = GET_RX_QUEUE_PTR(qinx);
194                 napi_enable(&rx_queue->napi);
195         }
196
197         pr_debug("<--eqos_napi_enable_mq\n");
198 }
199
200 static void eqos_all_ch_napi_disable(struct eqos_prv_data *pdata)
201 {
202         struct eqos_rx_queue *rx_queue = NULL;
203         int qinx;
204
205         pr_debug("-->eqos_napi_disable\n");
206
207         for (qinx = 0; qinx < EQOS_RX_QUEUE_CNT; qinx++) {
208                 rx_queue = GET_RX_QUEUE_PTR(qinx);
209                 napi_disable(&rx_queue->napi);
210         }
211
212         pr_debug("<--eqos_napi_disable\n");
213 }
214
215 void eqos_disable_all_ch_rx_interrpt(struct eqos_prv_data *pdata)
216 {
217         struct hw_if_struct *hw_if = &(pdata->hw_if);
218         UINT qinx;
219
220         pr_debug("-->eqos_disable_all_ch_rx_interrpt\n");
221
222         for (qinx = 0; qinx < EQOS_RX_QUEUE_CNT; qinx++)
223                 hw_if->disable_rx_interrupt(qinx, pdata);
224
225         pr_debug("<--eqos_disable_all_ch_rx_interrpt\n");
226 }
227
228 void eqos_enable_all_ch_rx_interrpt(struct eqos_prv_data *pdata)
229 {
230         struct hw_if_struct *hw_if = &(pdata->hw_if);
231         UINT qinx;
232
233         pr_debug("-->eqos_enable_all_ch_rx_interrpt\n");
234
235         for (qinx = 0; qinx < EQOS_RX_QUEUE_CNT; qinx++)
236                 hw_if->enable_rx_interrupt(qinx, pdata);
237
238         pr_debug("<--eqos_enable_all_ch_rx_interrpt\n");
239 }
240
241 void handle_non_ti_ri_chan_intrs(struct eqos_prv_data *pdata, int qinx)
242 {
243         ULONG dma_sr;
244         ULONG dma_ier;
245
246         pr_debug("-->%s(), chan=%d\n", __func__, qinx);
247
248         DMA_SR_RD(qinx, dma_sr);
249
250         DMA_IER_RD(qinx, dma_ier);
251
252         pr_debug("DMA_SR[%d] = %#lx, DMA_IER= %#lx\n", qinx, dma_sr, dma_ier);
253
254         /*on ufpga, update of DMA_IER is really slow, such that interrupt
255          * would happen, but read of IER returns old value.  This would
256          * cause driver to return when there really was an interrupt asserted.
257          * so for now, comment this out.
258          */
259         /* process only those interrupts which we
260          * have enabled.
261          */
262         if (!(tegra_platform_is_unit_fpga()))
263                 dma_sr = (dma_sr & dma_ier);
264
265         /* mask off ri and ti */
266         dma_sr &= ~(((0x1) << 6) | 1);
267
268         if (dma_sr == 0)
269                 return;
270
271         /* ack non ti/ri ints */
272         DMA_SR_WR(qinx, dma_sr);
273
274         if ((GET_VALUE(dma_sr, DMA_SR_RBU_LPOS, DMA_SR_RBU_HPOS) & 1))
275                 pdata->xstats.rx_buf_unavailable_irq_n[qinx]++;
276
277         if (tegra_platform_is_unit_fpga())
278                 dma_sr = (dma_sr & dma_ier);
279
280         if (GET_VALUE(dma_sr, DMA_SR_TPS_LPOS, DMA_SR_TPS_HPOS) & 1) {
281                 pdata->xstats.tx_process_stopped_irq_n[qinx]++;
282                 eqos_status = -E_DMA_SR_TPS;
283         }
284         if (GET_VALUE(dma_sr, DMA_SR_TBU_LPOS, DMA_SR_TBU_HPOS) & 1) {
285                 pdata->xstats.tx_buf_unavailable_irq_n[qinx]++;
286                 eqos_status = -E_DMA_SR_TBU;
287         }
288         if (GET_VALUE(dma_sr, DMA_SR_RPS_LPOS, DMA_SR_RPS_HPOS) & 1) {
289                 pdata->xstats.rx_process_stopped_irq_n[qinx]++;
290                 eqos_status = -E_DMA_SR_RPS;
291         }
292         if (GET_VALUE(dma_sr, DMA_SR_RWT_LPOS, DMA_SR_RWT_HPOS) & 1) {
293                 pdata->xstats.rx_watchdog_irq_n++;
294                 eqos_status = S_DMA_SR_RWT;
295         }
296         if (GET_VALUE(dma_sr, DMA_SR_FBE_LPOS, DMA_SR_FBE_HPOS) & 1) {
297                 pdata->xstats.fatal_bus_error_irq_n++;
298                 pdata->fbe_chan_mask |= (1 << qinx);
299                 eqos_status = -E_DMA_SR_FBE;
300                 schedule_work(&pdata->fbe_work);
301         }
302
303         pr_debug("<--%s()\n", __func__);
304 }
305
306 void handle_ti_ri_chan_intrs(struct eqos_prv_data *pdata,
307                              int qinx, int *pnapi_sched)
308 {
309         ULONG dma_sr;
310         ULONG dma_ier;
311         u32 ch_crtl_reg;
312         u32 ch_stat_reg;
313         struct hw_if_struct *hw_if = &(pdata->hw_if);
314
315         struct eqos_rx_queue *rx_queue = NULL;
316
317         pr_debug("-->%s(), chan=%d\n", __func__, qinx);
318
319         rx_queue = GET_RX_QUEUE_PTR(qinx);
320
321         DMA_SR_RD(qinx, dma_sr);
322
323         DMA_IER_RD(qinx, dma_ier);
324         VIRT_INTR_CH_STAT_RD(qinx, ch_stat_reg);
325         VIRT_INTR_CH_CRTL_RD(qinx, ch_crtl_reg);
326
327         pr_debug("DMA_SR[%d] = %#lx, DMA_IER= %#lx\n", qinx, dma_sr, dma_ier);
328
329         pr_debug("VIRT_INTR_CH_STAT[%d] = %#x, VIRT_INTR_CH_CRTL= %#x\n",
330               qinx, ch_stat_reg, ch_crtl_reg);
331
332         /*on ufpga, update of DMA_IER is really slow, such that interrupt
333          * would happen, but read of IER returns old value.  This would
334          * cause driver to return when there really was an interrupt asserted.
335          * so for now, comment this out.
336          */
337         /* process only those interrupts which we
338          * have enabled.
339          */
340         if (!(tegra_platform_is_unit_fpga()))
341                 ch_stat_reg &= ch_crtl_reg;
342
343         if (ch_stat_reg == 0)
344                 return;
345
346         if (ch_stat_reg & VIRT_INTR_CH_CRTL_RX_WR_MASK) {
347                 DMA_SR_WR(qinx, ((0x1) << 6) | ((0x1) << 15));
348                 VIRT_INTR_CH_STAT_WR(qinx, VIRT_INTR_CH_CRTL_RX_WR_MASK);
349                 pdata->xstats.rx_normal_irq_n[qinx]++;
350         }
351
352         if (tegra_platform_is_unit_fpga())
353                 ch_stat_reg &= ch_crtl_reg;
354
355         if (ch_stat_reg & VIRT_INTR_CH_CRTL_TX_WR_MASK) {
356                 DMA_SR_WR(qinx, ((0x1) << 0) | ((0x1) << 15));
357                 VIRT_INTR_CH_STAT_WR(qinx, VIRT_INTR_CH_CRTL_TX_WR_MASK);
358                 pdata->xstats.tx_normal_irq_n[qinx]++;
359         }
360
361         if (likely(napi_schedule_prep(&rx_queue->napi))) {
362                 hw_if->disable_chan_interrupts(qinx, pdata);
363                 __napi_schedule(&rx_queue->napi);
364         } else {
365                 /* Do nothing here. */
366                 pr_alert("Ethernet Interrupt while in poll!\n");
367         }
368         pr_debug("<--%s()\n", __func__);
369 }
370
371 void handle_mac_intrs(struct eqos_prv_data *pdata, ULONG dma_isr)
372 {
373         ULONG mac_imr;
374         ULONG mac_pmtcsr;
375         ULONG mac_ans = 0;
376         ULONG mac_pcs = 0;
377         ULONG mac_isr;
378         struct net_device *dev = pdata->dev;
379
380         pr_debug("-->%s()\n", __func__);
381
382         MAC_ISR_RD(mac_isr);
383
384         /* Handle MAC interrupts */
385         if (GET_VALUE(dma_isr, DMA_ISR_MACIS_LPOS, DMA_ISR_MACIS_HPOS) & 1) {
386                 /* handle only those MAC interrupts which are enabled */
387                 MAC_IMR_RD(mac_imr);
388                 mac_isr = (mac_isr & mac_imr);
389
390                 /* PMT interrupt
391                  * RemoteWake and MagicPacket events will be received by PHY supporting
392                  * these features on silicon and can be used to wake up Tegra.
393                  * Still let the below code be here in case we ever get this interrupt.
394                  */
395                 if (GET_VALUE(mac_isr, MAC_ISR_PMTIS_LPOS, MAC_ISR_PMTIS_HPOS) &
396                     1) {
397                         pdata->xstats.pmt_irq_n++;
398                         eqos_status = S_MAC_ISR_PMTIS;
399                         MAC_PMTCSR_RD(mac_pmtcsr);
400                         pr_debug("commonisr: PMTCSR : %#lx\n", mac_pmtcsr);
401                         if (pdata->power_down)
402                                 eqos_powerup(pdata->dev, EQOS_IOCTL_CONTEXT);
403                 }
404
405                 /* RGMII/SMII interrupt */
406                 if (GET_VALUE
407                     (mac_isr, MAC_ISR_RGSMIIS_LPOS, MAC_ISR_RGSMIIS_HPOS) & 1) {
408                         MAC_PCS_RD(mac_pcs);
409                         pr_debug("RGMII/SMII interrupt: MAC_PCS = %#lx\n",
410                                mac_pcs);
411 #ifdef HWA_NV_1637630
412
413 #else
414                         /* Comment out this block of code(1637630)
415                          * as it was preventing 10mb to work.
416                          */
417                         if ((mac_pcs & 0x80000) == 0x80000) {
418                                 pdata->pcs_link = 1;
419                                 netif_carrier_on(dev);
420                                 if ((mac_pcs & 0x10000) == 0x10000) {
421                                         pdata->pcs_duplex = 1;
422                                         hw_if->set_full_duplex();
423                                 } else {
424                                         pdata->pcs_duplex = 0;
425                                         hw_if->set_half_duplex();
426                                 }
427
428                                 if ((mac_pcs & 0x60000) == 0x0) {
429                                         pdata->pcs_speed = SPEED_10;
430                                         hw_if->set_mii_speed_10();
431                                 } else if ((mac_pcs & 0x60000) == 0x20000) {
432                                         pdata->pcs_speed = SPEED_100;
433                                         hw_if->set_mii_speed_100();
434                                 } else if ((mac_pcs & 0x60000) == 0x30000) {
435                                         pdata->pcs_speed = SPEED_1000;
436                                         hw_if->set_gmii_speed();
437                                 }
438                                 pr_err("Link is UP:%dMbps & %s duplex\n",
439                                        pdata->pcs_speed,
440                                        pdata->pcs_duplex ? "Full" : "Half");
441                         } else {
442                                 pr_err("Link is Down\n");
443                                 pdata->pcs_link = 0;
444                                 netif_carrier_off(dev);
445                         }
446 #endif
447                 }
448
449                 /* PCS Link Status interrupt */
450                 if (GET_VALUE
451                     (mac_isr, MAC_ISR_PCSLCHGIS_LPOS,
452                      MAC_ISR_PCSLCHGIS_HPOS) & 1) {
453                         pr_err("PCS Link Status interrupt\n");
454                         MAC_ANS_RD(mac_ans);
455                         if (GET_VALUE(mac_ans, MAC_ANS_LS_LPOS, MAC_ANS_LS_HPOS)
456                             & 1) {
457                                 pr_err("Link: Up\n");
458                                 netif_carrier_on(dev);
459                                 pdata->pcs_link = 1;
460                         } else {
461                                 pr_err("Link: Down\n");
462                                 netif_carrier_off(dev);
463                                 pdata->pcs_link = 0;
464                         }
465                 }
466
467                 /* PCS Auto-Negotiation Complete interrupt */
468                 if (GET_VALUE
469                     (mac_isr, MAC_ISR_PCSANCIS_LPOS,
470                      MAC_ISR_PCSANCIS_HPOS) & 1) {
471                         pr_err("PCS Auto-Negotiation Complete interrupt\n");
472                         MAC_ANS_RD(mac_ans);
473                 }
474
475                 /* EEE interrupts */
476                 if (GET_VALUE(mac_isr, MAC_ISR_LPI_LPOS, MAC_ISR_LPI_HPOS) & 1) {
477                         eqos_handle_eee_interrupt(pdata);
478                 }
479         }
480
481         pr_debug("<--%s()\n", __func__);
482 }
483
484
485 /*!
486 * Only used when multi irq is enabled
487 */
488
489 irqreturn_t eqos_common_isr(int irq, void *device_id)
490 {
491         ULONG dma_isr;
492         struct eqos_prv_data *pdata = (struct eqos_prv_data *)device_id;
493         UINT qinx;
494
495         pr_debug("-->%s()\n", __func__);
496
497         DMA_ISR_RD(dma_isr);
498         if (dma_isr == 0x0)
499                 return IRQ_NONE;
500
501         pr_debug("DMA_ISR = %#lx\n", dma_isr);
502
503         if (dma_isr & 0xf)
504                 for (qinx = 0; qinx < EQOS_TX_QUEUE_CNT; qinx++)
505                         handle_non_ti_ri_chan_intrs(pdata, qinx);
506
507         handle_mac_intrs(pdata, dma_isr);
508
509         pr_debug("<--%s()\n", __func__);
510
511         return IRQ_HANDLED;
512
513 }
514
515 /* Only used when multi irq is enabled.
516  * Will only handle tx/rx for one channel.
517  */
518 irqreturn_t eqos_ch_isr(int irq, void *device_id)
519 {
520         struct eqos_prv_data *pdata = (struct eqos_prv_data *)device_id;
521         uint i;
522         int qinx = -1;
523         int napi_sched = 0;
524
525         i = smp_processor_id();
526
527         if ((irq == pdata->rx_irqs[0]) || (irq == pdata->tx_irqs[0]))
528                 qinx = 0;
529         else if ((irq == pdata->rx_irqs[1]) || (irq == pdata->tx_irqs[1]))
530                 qinx = 1;
531         else if ((irq == pdata->rx_irqs[2]) || (irq == pdata->tx_irqs[2]))
532                 qinx = 2;
533         else if ((irq == pdata->rx_irqs[3]) || (irq == pdata->tx_irqs[3]))
534                 qinx = 3;
535
536         pr_debug("-->%s(): cpu=%d, chan=%d\n", __func__, i, qinx);
537
538         if (qinx != -1) {
539                 handle_ti_ri_chan_intrs(pdata, qinx, &napi_sched);
540         } else {
541                 pr_debug("%s(): irq %d not handled\n", __func__, irq);
542                 return IRQ_NONE;
543         }
544
545         spin_lock(&pdata->chinfo[qinx].irq_lock);
546         handle_ti_ri_chan_intrs(pdata, qinx, &napi_sched);
547         spin_unlock(&pdata->chinfo[qinx].irq_lock);
548
549         pr_debug("<--%s()\n", __func__);
550
551         return IRQ_HANDLED;
552
553 }
554
555 /*!
556 * \brief API to get all hw features.
557 *
558 * \details This function is used to check what are all the different
559 * features the device supports.
560 *
561 * \param[in] pdata - pointer to driver private structure
562 *
563 * \return none
564 */
565
566 void eqos_get_all_hw_features(struct eqos_prv_data *pdata)
567 {
568         unsigned int mac_hfr0;
569         unsigned int mac_hfr1;
570         unsigned int mac_hfr2;
571
572         pr_debug("-->eqos_get_all_hw_features\n");
573
574         MAC_HFR0_RD(mac_hfr0);
575         MAC_HFR1_RD(mac_hfr1);
576         MAC_HFR2_RD(mac_hfr2);
577
578         memset(&pdata->hw_feat, 0, sizeof(pdata->hw_feat));
579         pdata->hw_feat.mii_sel = ((mac_hfr0 >> 0) & MAC_HFR0_MIISEL_MASK);
580         pdata->hw_feat.gmii_sel = ((mac_hfr0 >> 1) & MAC_HFR0_GMIISEL_MASK);
581         pdata->hw_feat.hd_sel = ((mac_hfr0 >> 2) & MAC_HFR0_HDSEL_MASK);
582         pdata->hw_feat.pcs_sel = ((mac_hfr0 >> 3) & MAC_HFR0_PCSSEL_MASK);
583         pdata->hw_feat.vlan_hash_en = 0;
584         pdata->hw_feat.sma_sel = ((mac_hfr0 >> 5) & MAC_HFR0_SMASEL_MASK);
585         pdata->hw_feat.rwk_sel = ((mac_hfr0 >> 6) & MAC_HFR0_RWKSEL_MASK);
586         pdata->hw_feat.mgk_sel = ((mac_hfr0 >> 7) & MAC_HFR0_MGKSEL_MASK);
587         pdata->hw_feat.mmc_sel = ((mac_hfr0 >> 8) & MAC_HFR0_MMCSEL_MASK);
588         pdata->hw_feat.arp_offld_en =
589             ((mac_hfr0 >> 9) & MAC_HFR0_ARPOFFLDEN_MASK);
590         pdata->hw_feat.ts_sel = ((mac_hfr0 >> 12) & MAC_HFR0_TSSSEL_MASK);
591         pdata->hw_feat.eee_sel = ((mac_hfr0 >> 13) & MAC_HFR0_EEESEL_MASK);
592         pdata->hw_feat.tx_coe_sel = ((mac_hfr0 >> 14) & MAC_HFR0_TXCOESEL_MASK);
593         pdata->hw_feat.rx_coe_sel = ((mac_hfr0 >> 16) & MAC_HFR0_RXCOE_MASK);
594         pdata->hw_feat.mac_addr16_sel =
595             ((mac_hfr0 >> 18) & MAC_HFR0_ADDMACADRSEL_MASK);
596         pdata->hw_feat.mac_addr32_sel =
597             ((mac_hfr0 >> 23) & MAC_HFR0_MACADR32SEL_MASK);
598         pdata->hw_feat.mac_addr64_sel =
599             ((mac_hfr0 >> 24) & MAC_HFR0_MACADR64SEL_MASK);
600         pdata->hw_feat.tsstssel = ((mac_hfr0 >> 25) & MAC_HFR0_TSINTSEL_MASK);
601         pdata->hw_feat.sa_vlan_ins =
602             ((mac_hfr0 >> 27) & MAC_HFR0_SAVLANINS_MASK);
603         pdata->hw_feat.act_phy_sel =
604             ((mac_hfr0 >> 28) & MAC_HFR0_ACTPHYSEL_MASK);
605
606         pdata->hw_feat.rx_fifo_size =
607             ((mac_hfr1 >> 0) & MAC_HFR1_RXFIFOSIZE_MASK);
608         pdata->hw_feat.tx_fifo_size =
609             ((mac_hfr1 >> 6) & MAC_HFR1_TXFIFOSIZE_MASK);
610         pdata->hw_feat.adv_ts_hword =
611             ((mac_hfr1 >> 13) & MAC_HFR1_ADVTHWORD_MASK);
612         pdata->hw_feat.dcb_en = ((mac_hfr1 >> 16) & MAC_HFR1_DCBEN_MASK);
613         pdata->hw_feat.sph_en = ((mac_hfr1 >> 17) & MAC_HFR1_SPHEN_MASK);
614         pdata->hw_feat.tso_en = ((mac_hfr1 >> 18) & MAC_HFR1_TSOEN_MASK);
615         pdata->hw_feat.dma_debug_gen =
616             ((mac_hfr1 >> 19) & MAC_HFR1_DMADEBUGEN_MASK);
617         pdata->hw_feat.av_sel = ((mac_hfr1 >> 20) & MAC_HFR1_AVSEL_MASK);
618         pdata->hw_feat.lp_mode_en = ((mac_hfr1 >> 23) & MAC_HFR1_LPMODEEN_MASK);
619 #ifdef ENABLE_PERFECT_L2_FILTER
620         pdata->hw_feat.hash_tbl_sz = 0;
621 #else
622         pdata->hw_feat.hash_tbl_sz =
623             ((mac_hfr1 >> 24) & MAC_HFR1_HASHTBLSZ_MASK);
624 #endif
625         pdata->hw_feat.l3l4_filter_num =
626             ((mac_hfr1 >> 27) & MAC_HFR1_L3L4FILTERNUM_MASK);
627
628         pdata->hw_feat.rx_q_cnt = ((mac_hfr2 >> 0) & MAC_HFR2_RXQCNT_MASK);
629         pdata->hw_feat.tx_q_cnt = ((mac_hfr2 >> 6) & MAC_HFR2_TXQCNT_MASK);
630         pdata->hw_feat.rx_ch_cnt = ((mac_hfr2 >> 12) & MAC_HFR2_RXCHCNT_MASK);
631         pdata->hw_feat.tx_ch_cnt = ((mac_hfr2 >> 18) & MAC_HFR2_TXCHCNT_MASK);
632         pdata->hw_feat.pps_out_num =
633             ((mac_hfr2 >> 24) & MAC_HFR2_PPSOUTNUM_MASK);
634         pdata->hw_feat.aux_snap_num =
635             ((mac_hfr2 >> 28) & MAC_HFR2_AUXSNAPNUM_MASK);
636
637         if (pdata->hw_feat.mac_addr64_sel)
638                 pdata->max_addr_reg_cnt = 128;
639         else if (pdata->hw_feat.mac_addr32_sel)
640                 pdata->max_addr_reg_cnt = 64;
641         else if (pdata->hw_feat.mac_addr16_sel)
642                 pdata->max_addr_reg_cnt = 32;
643         else
644                 pdata->max_addr_reg_cnt = 1;
645
646         switch (pdata->hw_feat.hash_tbl_sz) {
647         case 0:
648                 pdata->max_hash_table_size = 0;
649                 break;
650         case 1:
651                 pdata->max_hash_table_size = 64;
652                 break;
653         case 2:
654                 pdata->max_hash_table_size = 128;
655                 break;
656         case 3:
657                 pdata->max_hash_table_size = 256;
658                 break;
659         }
660
661         pr_debug("<--eqos_get_all_hw_features\n");
662 }
663
664 /*!
665 * \brief API to print all hw features.
666 *
667 * \details This function is used to print all the device feature.
668 *
669 * \param[in] pdata - pointer to driver private structure
670 *
671 * \return none
672 */
673
674 void eqos_print_all_hw_features(struct eqos_prv_data *pdata)
675 {
676         char *str = NULL;
677
678         pr_debug("-->eqos_print_all_hw_features\n");
679
680         pr_err("\n");
681         pr_err("=====================================================/\n");
682         pr_err("\n");
683         pr_err("10/100 Mbps Support                         : %s\n",
684                pdata->hw_feat.mii_sel ? "YES" : "NO");
685         pr_err("1000 Mbps Support                           : %s\n",
686                pdata->hw_feat.gmii_sel ? "YES" : "NO");
687         pr_err("Half-duplex Support                         : %s\n",
688                pdata->hw_feat.hd_sel ? "YES" : "NO");
689         pr_err("PCS Registers(TBI/SGMII/RTBI PHY interface) : %s\n",
690                pdata->hw_feat.pcs_sel ? "YES" : "NO");
691         pr_err("VLAN Hash Filter Selected                   : %s\n",
692                pdata->hw_feat.vlan_hash_en ? "YES" : "NO");
693         pdata->vlan_hash_filtering = pdata->hw_feat.vlan_hash_en;
694         pr_err("SMA (MDIO) Interface                        : %s\n",
695                pdata->hw_feat.sma_sel ? "YES" : "NO");
696         pr_err("PMT Remote Wake-up Packet Enable            : %s\n",
697                pdata->hw_feat.rwk_sel ? "YES" : "NO");
698         pr_err("PMT Magic Packet Enable                     : %s\n",
699                pdata->hw_feat.mgk_sel ? "YES" : "NO");
700         pr_err("RMON/MMC Module Enable                      : %s\n",
701                pdata->hw_feat.mmc_sel ? "YES" : "NO");
702         pr_err("ARP Offload Enabled                         : %s\n",
703                pdata->hw_feat.arp_offld_en ? "YES" : "NO");
704         pr_err("IEEE 1588-2008 Timestamp Enabled            : %s\n",
705                pdata->hw_feat.ts_sel ? "YES" : "NO");
706         pr_err("Energy Efficient Ethernet Enabled           : %s\n",
707                pdata->hw_feat.eee_sel ? "YES" : "NO");
708         pr_err("Transmit Checksum Offload Enabled           : %s\n",
709                pdata->hw_feat.tx_coe_sel ? "YES" : "NO");
710         pr_err("Receive Checksum Offload Enabled            : %s\n",
711                pdata->hw_feat.rx_coe_sel ? "YES" : "NO");
712         pr_err("MAC Addresses 16–31 Selected                : %s\n",
713                pdata->hw_feat.mac_addr16_sel ? "YES" : "NO");
714         pr_err("MAC Addresses 32–63 Selected                : %s\n",
715                pdata->hw_feat.mac_addr32_sel ? "YES" : "NO");
716         pr_err("MAC Addresses 64–127 Selected               : %s\n",
717                pdata->hw_feat.mac_addr64_sel ? "YES" : "NO");
718
719         switch (pdata->hw_feat.tsstssel) {
720         case 0:
721                 str = "RESERVED";
722                 break;
723         case 1:
724                 str = "INTERNAL";
725                 break;
726         case 2:
727                 str = "EXTERNAL";
728                 break;
729         case 3:
730                 str = "BOTH";
731                 break;
732         }
733         pr_err("Timestamp System Time Source                : %s\n", str);
734         pr_err("Source Address or VLAN Insertion Enable     : %s\n",
735                pdata->hw_feat.sa_vlan_ins ? "YES" : "NO");
736
737         switch (pdata->hw_feat.act_phy_sel) {
738         case 0:
739                 str = "GMII/MII";
740                 break;
741         case 1:
742                 str = "RGMII";
743                 break;
744         case 2:
745                 str = "SGMII";
746                 break;
747         case 3:
748                 str = "TBI";
749                 break;
750         case 4:
751                 str = "RMII";
752                 break;
753         case 5:
754                 str = "RTBI";
755                 break;
756         case 6:
757                 str = "SMII";
758                 break;
759         case 7:
760                 str = "RevMII";
761                 break;
762         default:
763                 str = "RESERVED";
764         }
765         pr_err("Active PHY Selected                         : %s\n", str);
766
767         switch (pdata->hw_feat.rx_fifo_size) {
768         case 0:
769                 str = "128 bytes";
770                 break;
771         case 1:
772                 str = "256 bytes";
773                 break;
774         case 2:
775                 str = "512 bytes";
776                 break;
777         case 3:
778                 str = "1 KBytes";
779                 break;
780         case 4:
781                 str = "2 KBytes";
782                 break;
783         case 5:
784                 str = "4 KBytes";
785                 break;
786         case 6:
787                 str = "8 KBytes";
788                 break;
789         case 7:
790                 str = "16 KBytes";
791                 break;
792         case 8:
793                 str = "32 kBytes";
794                 break;
795         case 9:
796                 str = "64 KBytes";
797                 break;
798         case 10:
799                 str = "128 KBytes";
800                 break;
801         case 11:
802                 str = "256 KBytes";
803                 break;
804         default:
805                 str = "RESERVED";
806         }
807         pr_err("MTL Receive FIFO Size                       : %s\n", str);
808
809         switch (pdata->hw_feat.tx_fifo_size) {
810         case 0:
811                 str = "128 bytes";
812                 break;
813         case 1:
814                 str = "256 bytes";
815                 break;
816         case 2:
817                 str = "512 bytes";
818                 break;
819         case 3:
820                 str = "1 KBytes";
821                 break;
822         case 4:
823                 str = "2 KBytes";
824                 break;
825         case 5:
826                 str = "4 KBytes";
827                 break;
828         case 6:
829                 str = "8 KBytes";
830                 break;
831         case 7:
832                 str = "16 KBytes";
833                 break;
834         case 8:
835                 str = "32 kBytes";
836                 break;
837         case 9:
838                 str = "64 KBytes";
839                 break;
840         case 10:
841                 str = "128 KBytes";
842                 break;
843         case 11:
844                 str = "256 KBytes";
845                 break;
846         default:
847                 str = "RESERVED";
848         }
849         pr_err("MTL Transmit FIFO Size                       : %s\n", str);
850         pr_err("IEEE 1588 High Word Register Enable          : %s\n",
851                pdata->hw_feat.adv_ts_hword ? "YES" : "NO");
852         pr_err("DCB Feature Enable                           : %s\n",
853                pdata->hw_feat.dcb_en ? "YES" : "NO");
854         pr_err("Split Header Feature Enable                  : %s\n",
855                pdata->hw_feat.sph_en ? "YES" : "NO");
856         pr_err("TCP Segmentation Offload Enable              : %s\n",
857                pdata->hw_feat.tso_en ? "YES" : "NO");
858         pr_err("DMA Debug Registers Enabled                  : %s\n",
859                pdata->hw_feat.dma_debug_gen ? "YES" : "NO");
860         pr_err("AV Feature Enabled                           : %s\n",
861                pdata->hw_feat.av_sel ? "YES" : "NO");
862         pr_err("Low Power Mode Enabled                       : %s\n",
863                pdata->hw_feat.lp_mode_en ? "YES" : "NO");
864
865         switch (pdata->hw_feat.hash_tbl_sz) {
866         case 0:
867                 str = "No hash table selected";
868                 break;
869         case 1:
870                 str = "64";
871                 break;
872         case 2:
873                 str = "128";
874                 break;
875         case 3:
876                 str = "256";
877                 break;
878         }
879         pr_err("Hash Table Size                              : %s\n", str);
880         pr_err
881             ("Total number of L3 or L4 Filters             : %d L3/L4 Filter\n",
882              pdata->hw_feat.l3l4_filter_num);
883         pr_err("Number of MTL Receive Queues                 : %d\n",
884                (pdata->hw_feat.rx_q_cnt + 1));
885         pr_err("Number of MTL Transmit Queues                : %d\n",
886                (pdata->hw_feat.tx_q_cnt + 1));
887         pr_err("Number of DMA Receive Channels               : %d\n",
888                (pdata->hw_feat.rx_ch_cnt + 1));
889         pr_err("Number of DMA Transmit Channels              : %d\n",
890                (pdata->hw_feat.tx_ch_cnt + 1));
891
892         switch (pdata->hw_feat.pps_out_num) {
893         case 0:
894                 str = "No PPS output";
895                 break;
896         case 1:
897                 str = "1 PPS output";
898                 break;
899         case 2:
900                 str = "2 PPS output";
901                 break;
902         case 3:
903                 str = "3 PPS output";
904                 break;
905         case 4:
906                 str = "4 PPS output";
907                 break;
908         default:
909                 str = "RESERVED";
910         }
911         pr_err("Number of PPS Outputs                        : %s\n", str);
912
913         switch (pdata->hw_feat.aux_snap_num) {
914         case 0:
915                 str = "No auxillary input";
916                 break;
917         case 1:
918                 str = "1 auxillary input";
919                 break;
920         case 2:
921                 str = "2 auxillary input";
922                 break;
923         case 3:
924                 str = "3 auxillary input";
925                 break;
926         case 4:
927                 str = "4 auxillary input";
928                 break;
929         default:
930                 str = "RESERVED";
931         }
932         pr_err("Number of Auxiliary Snapshot Inputs          : %s", str);
933
934         pr_err("\n");
935         pr_err("=====================================================/\n");
936
937         pr_debug("<--eqos_print_all_hw_features\n");
938 }
939
940 /*!
941  * \brief allcation of Rx skb's for default rx mode.
942  *
943  * \details This function is invoked by other api's for
944  * allocating the Rx skb's with default Rx mode.
945  *
946  * \param[in] pdata â€“ pointer to private data structure.
947  * \param[in] buffer â€“ pointer to wrapper receive buffer data structure.
948  * \param[in] gfp â€“ the type of memory allocation.
949  *
950  * \return int
951  *
952  * \retval 0 on success and -ve number on failure.
953  */
954
955 static int eqos_alloc_rx_buf(struct eqos_prv_data *pdata,
956                              struct rx_swcx_desc *prx_swcx_desc, gfp_t gfp)
957 {
958         struct sk_buff *skb = prx_swcx_desc->skb;
959
960         pr_debug("-->eqos_alloc_rx_buf\n");
961
962         if (skb) {
963                 skb_trim(skb, 0);
964                 if (prx_swcx_desc->dma)
965                         goto skip_mapping;
966                 goto map_skb;
967         }
968
969         skb =
970             __netdev_alloc_skb_ip_align(pdata->dev, pdata->rx_buffer_len, gfp);
971         if (skb == NULL) {
972                 prx_swcx_desc->skb = NULL;
973                 pr_err("Failed to allocate skb\n");
974                 return -ENOMEM;
975         }
976         prx_swcx_desc->skb = skb;
977         prx_swcx_desc->len = pdata->rx_buffer_len;
978
979  map_skb:
980         prx_swcx_desc->dma = dma_map_single(&pdata->pdev->dev, skb->data,
981                                      pdata->rx_buffer_len,
982                                      DMA_FROM_DEVICE);
983         if (dma_mapping_error(&pdata->pdev->dev, prx_swcx_desc->dma)) {
984                 pr_err("failed to do the RX dma map\n");
985                 return -ENOMEM;
986         }
987
988 skip_mapping:
989         prx_swcx_desc->mapped_as_page = Y_FALSE;
990
991         pr_debug("<--eqos_alloc_rx_buf\n");
992
993         return 0;
994 }
995
996 /*!
997  * \brief api to configure Rx function pointer after reset.
998  *
999  * \details This function will initialize the receive function pointers
1000  * which are used for allocating skb's and receiving the packets based
1001  * Rx mode - default.
1002  *
1003  * \param[in] pdata â€“ pointer to private data structure.
1004  *
1005  * \return void
1006  */
1007
1008 static void eqos_configure_rx_fun_ptr(struct eqos_prv_data *pdata)
1009 {
1010         pr_debug("-->eqos_configure_rx_fun_ptr\n");
1011
1012         pdata->process_rx_completions = process_rx_completions;
1013         pdata->alloc_rx_buf = eqos_alloc_rx_buf;
1014
1015         pr_debug("<--eqos_configure_rx_fun_ptr\n");
1016 }
1017
1018 /*!
1019  * \brief api to initialize default values.
1020  *
1021  * \details This function is used to initialize differnet parameters to
1022  * default values which are common parameters between Tx and Rx path.
1023  *
1024  * \param[in] pdata â€“ pointer to private data structure.
1025  *
1026  * \return void
1027  */
1028
1029 static void eqos_default_common_confs(struct eqos_prv_data *pdata)
1030 {
1031         pr_debug("-->eqos_default_common_confs\n");
1032
1033         pdata->drop_tx_pktburstcnt = 1;
1034         pdata->mac_enable_count = 0;
1035         pdata->incr_incrx = EQOS_INCR_ENABLE;
1036         pdata->flow_ctrl = EQOS_FLOW_CTRL_TX_RX;
1037         pdata->oldflow_ctrl = EQOS_FLOW_CTRL_TX_RX;
1038         pdata->power_down = 0;
1039         pdata->tx_sa_ctrl_via_desc = EQOS_SA0_NONE;
1040         pdata->tx_sa_ctrl_via_reg = EQOS_SA0_NONE;
1041         pdata->hwts_tx_en = 0;
1042         pdata->hwts_rx_en = 0;
1043         pdata->l3_l4_filter = 0;
1044         pdata->l2_filtering_mode = !!pdata->hw_feat.hash_tbl_sz;
1045         pdata->tx_path_in_lpi_mode = 0;
1046         pdata->use_lpi_tx_automate = true;
1047         pdata->eee_active = 0;
1048         pdata->one_nsec_accuracy = 1;
1049
1050         pr_debug("<--eqos_default_common_confs\n");
1051 }
1052
1053 /*!
1054  * \brief api to initialize Tx parameters.
1055  *
1056  * \details This function is used to initialize all Tx
1057  * parameters to default values on reset.
1058  *
1059  * \param[in] pdata â€“ pointer to private data structure.
1060  * \param[in] qinx â€“ DMA channel/queue number to be initialized.
1061  *
1062  * \return void
1063  */
1064
1065 static void eqos_default_tx_confs_single_q(struct eqos_prv_data *pdata,
1066                                            UINT qinx)
1067 {
1068         struct eqos_tx_queue *queue_data = GET_TX_QUEUE_PTR(qinx);
1069         struct tx_ring *ptx_ring =
1070             GET_TX_WRAPPER_DESC(qinx);
1071
1072         pr_debug("-->eqos_default_tx_confs_single_q\n");
1073
1074         queue_data->q_op_mode = q_op_mode[qinx];
1075
1076         ptx_ring->tx_threshold_val = EQOS_TX_THRESHOLD_32;
1077         ptx_ring->tsf_on = EQOS_TSF_ENABLE;
1078         ptx_ring->osf_on = EQOS_OSF_ENABLE;
1079         ptx_ring->tx_pbl = EQOS_PBL_16;
1080         ptx_ring->tx_vlan_tag_via_reg = Y_FALSE;
1081         ptx_ring->tx_vlan_tag_ctrl = EQOS_TX_VLAN_TAG_INSERT;
1082         ptx_ring->vlan_tag_present = 0;
1083         ptx_ring->context_setup = 0;
1084         ptx_ring->default_mss = 0;
1085
1086         pr_debug("<--eqos_default_tx_confs_single_q\n");
1087 }
1088
1089 /*!
1090  * \brief api to initialize Rx parameters.
1091  *
1092  * \details This function is used to initialize all Rx
1093  * parameters to default values on reset.
1094  *
1095  * \param[in] pdata â€“ pointer to private data structure.
1096  * \param[in] qinx â€“ DMA queue/channel number to be initialized.
1097  *
1098  * \return void
1099  */
1100
1101 static void eqos_default_rx_confs_single_q(struct eqos_prv_data *pdata,
1102                                            UINT qinx)
1103 {
1104         struct rx_ring *prx_ring =
1105             GET_RX_WRAPPER_DESC(qinx);
1106
1107         pr_debug("-->eqos_default_rx_confs_single_q\n");
1108
1109         prx_ring->rx_threshold_val = EQOS_RX_THRESHOLD_64;
1110         prx_ring->rsf_on = EQOS_RSF_DISABLE;
1111         prx_ring->rx_pbl = EQOS_PBL_16;
1112         prx_ring->rx_outer_vlan_strip = EQOS_RX_VLAN_STRIP_ALWAYS;
1113         prx_ring->rx_inner_vlan_strip = EQOS_RX_VLAN_STRIP_ALWAYS;
1114
1115         pr_debug("<--eqos_default_rx_confs_single_q\n");
1116 }
1117
1118 static void eqos_default_tx_confs(struct eqos_prv_data *pdata)
1119 {
1120         UINT qinx;
1121
1122         pr_debug("-->eqos_default_tx_confs\n");
1123
1124         for (qinx = 0; qinx < EQOS_TX_QUEUE_CNT; qinx++) {
1125                 eqos_default_tx_confs_single_q(pdata, qinx);
1126         }
1127
1128         pr_debug("<--eqos_default_tx_confs\n");
1129 }
1130
1131 static void eqos_default_rx_confs(struct eqos_prv_data *pdata)
1132 {
1133         UINT qinx;
1134
1135         pr_debug("-->eqos_default_rx_confs\n");
1136
1137         for (qinx = 0; qinx < EQOS_RX_QUEUE_CNT; qinx++) {
1138                 eqos_default_rx_confs_single_q(pdata, qinx);
1139         }
1140
1141         pr_debug("<--eqos_default_rx_confs\n");
1142 }
1143
1144 void free_txrx_irqs(struct eqos_prv_data *pdata)
1145 {
1146         uint i;
1147
1148         pr_debug("-->%s()\n", __func__);
1149
1150         free_irq(pdata->common_irq, pdata);
1151
1152         for (i = 0; i < pdata->num_chans; i++) {
1153                 if (pdata->rx_irq_alloc_mask & (1 << i)) {
1154                         irq_set_affinity_hint(pdata->rx_irqs[i], NULL);
1155                         free_irq(pdata->rx_irqs[i], pdata);
1156                 }
1157                 if (pdata->tx_irq_alloc_mask & (1 << i)) {
1158                         irq_set_affinity_hint(pdata->tx_irqs[i], NULL);
1159                         free_irq(pdata->tx_irqs[i], pdata);
1160                 }
1161         }
1162
1163         pr_debug("<--%s()\n", __func__);
1164 }
1165
1166 int request_txrx_irqs(struct eqos_prv_data *pdata)
1167 {
1168         int ret = Y_SUCCESS;
1169         uint i, j = 0;
1170         struct chan_data *pchinfo;
1171         struct platform_device *pdev = pdata->pdev;
1172
1173         pr_debug("-->%s()\n", __func__);
1174
1175         pdata->irq_number = pdata->dev->irq;
1176
1177         ret = request_irq(pdata->common_irq,
1178                           eqos_common_isr, IRQF_SHARED, "ether_qos.common_irq", pdata);
1179         if (ret != Y_SUCCESS) {
1180                 pr_err("Unable to register  %d\n", pdata->common_irq);
1181                 ret = -EBUSY;
1182                 goto err_common_irq;
1183         }
1184
1185         for (i = 0; i < pdata->num_chans; i++) {
1186
1187                 snprintf(irq_names[j], 32, "%s.rx%d", dev_name(&pdev->dev), i);
1188                 ret = request_irq(pdata->rx_irqs[i],
1189                                   eqos_ch_isr, 0, irq_names[j++], pdata);
1190                 if (ret != 0) {
1191                         pr_err("Unable to register  %d\n", pdata->rx_irqs[i]);
1192                         ret = -EBUSY;
1193                         goto err_chan_irq;
1194                 }
1195                 snprintf(irq_names[j], 32, "%s.tx%d", dev_name(&pdev->dev), i);
1196                 ret = request_irq(pdata->tx_irqs[i],
1197                                   eqos_ch_isr, 0, irq_names[j++], pdata);
1198                 if (ret != 0) {
1199                         pr_err("Unable to register  %d\n", pdata->tx_irqs[i]);
1200                         ret = -EBUSY;
1201                         goto err_chan_irq;
1202                 }
1203                 pchinfo = &pdata->chinfo[i];
1204
1205                 irq_set_affinity_hint(pdata->rx_irqs[i],
1206                                       cpumask_of(pchinfo->cpu));
1207                 pdata->rx_irq_alloc_mask |= (1 << i);
1208
1209                 irq_set_affinity_hint(pdata->tx_irqs[i],
1210                                       cpumask_of(pchinfo->cpu));
1211                 pdata->tx_irq_alloc_mask |= (1 << i);
1212         }
1213         pr_debug("<--%s()\n", __func__);
1214
1215         return ret;
1216
1217  err_chan_irq:
1218         free_txrx_irqs(pdata);
1219         free_irq(pdata->common_irq, pdata);
1220
1221  err_common_irq:
1222         pr_debug("<--%s(): error\n", __func__);
1223         return ret;
1224 }
1225
1226
1227 /*!
1228 * \brief API to open a deivce for data transmission & reception.
1229 *
1230 * \details Opens the interface. The interface is opned whenever
1231 * ifconfig activates it. The open method should register any
1232 * system resource it needs like I/O ports, IRQ, DMA, etc,
1233 * turn on the hardware, and perform any other setup your device requires.
1234 *
1235 * \param[in] dev - pointer to net_device structure
1236 *
1237 * \return integer
1238 *
1239 * \retval 0 on success & negative number on failure.
1240 */
1241
1242 static int eqos_open(struct net_device *dev)
1243 {
1244         struct eqos_prv_data *pdata = netdev_priv(dev);
1245         int ret = Y_SUCCESS;
1246         struct desc_if_struct *desc_if = &pdata->desc_if;
1247
1248         pr_debug("-->eqos_open\n");
1249
1250         if (!is_valid_ether_addr(dev->dev_addr))
1251                 return -EADDRNOTAVAIL;
1252
1253         ret = request_txrx_irqs(pdata);
1254         if (ret != Y_SUCCESS)
1255                 goto err_irq_0;
1256
1257         ret = desc_if->alloc_buff_and_desc(pdata);
1258         if (ret < 0) {
1259                 dev_err(&pdata->pdev->dev,
1260                         "Failed to allocate buffer/descriptor memory\n");
1261                 ret = -ENOMEM;
1262                 goto err_out_desc_buf_alloc_failed;
1263         }
1264
1265         mutex_lock(&pdata->hw_change_lock);
1266         eqos_start_dev(pdata);
1267
1268         pdata->hw_stopped = false;
1269         mutex_unlock(&pdata->hw_change_lock);
1270
1271         pr_debug("<--%s()\n", __func__);
1272         return Y_SUCCESS;
1273
1274  err_out_desc_buf_alloc_failed:
1275         free_txrx_irqs(pdata);
1276
1277  err_irq_0:
1278         pr_debug("<--%s()\n", __func__);
1279         return ret;
1280 }
1281
1282 /*!
1283 * \brief API to close a device.
1284 *
1285 * \details Stops the interface. The interface is stopped when it is brought
1286 * down. This function should reverse operations performed at open time.
1287 *
1288 * \param[in] dev - pointer to net_device structure
1289 *
1290 * \return integer
1291 *
1292 * \retval 0 on success & negative number on failure.
1293 */
1294
1295 static int eqos_close(struct net_device *dev)
1296 {
1297         struct eqos_prv_data *pdata = netdev_priv(dev);
1298         struct desc_if_struct *desc_if = &pdata->desc_if;
1299
1300         pr_debug("-->%s\n", __func__);
1301
1302         mutex_lock(&pdata->hw_change_lock);
1303         eqos_stop_dev(pdata);
1304
1305         desc_if->free_buff_and_desc(pdata);
1306         free_txrx_irqs(pdata);
1307
1308         pdata->hw_stopped = true;
1309         mutex_unlock(&pdata->hw_change_lock);
1310
1311         /* cancel iso work */
1312         cancel_work_sync(&pdata->iso_work);
1313         /* Cancel FBE handling work */
1314         cancel_work_sync(&pdata->fbe_work);
1315
1316         pr_debug("<--%s\n", __func__);
1317         return Y_SUCCESS;
1318 }
1319
1320 /*!
1321 * \brief API to configure the multicast address in device.
1322 *
1323 * \details This function collects all the multicast addresse
1324 * and updates the device.
1325 *
1326 * \param[in] dev - pointer to net_device structure.
1327 *
1328 * \retval 0 if perfect filtering is seleted & 1 if hash
1329 * filtering is seleted.
1330 */
1331 static int eqos_prepare_mc_list(struct net_device *dev)
1332 {
1333         struct eqos_prv_data *pdata = netdev_priv(dev);
1334         struct hw_if_struct *hw_if = &(pdata->hw_if);
1335         u32 mc_filter[EQOS_HTR_CNT];
1336         struct netdev_hw_addr *ha = NULL;
1337         int crc32_val = 0;
1338         int ret = 0, i = 1;
1339
1340         DBGPR_FILTER("-->eqos_prepare_mc_list\n");
1341
1342         if (pdata->l2_filtering_mode) {
1343                 DBGPR_FILTER
1344                     ("select HASH FILTERING for mc addresses: mc_count = %d\n",
1345                      netdev_mc_count(dev));
1346                 ret = 1;
1347                 memset(mc_filter, 0, sizeof(mc_filter));
1348
1349                 if (pdata->max_hash_table_size == 64) {
1350                         netdev_for_each_mc_addr(ha, dev) {
1351                                 DBGPR_FILTER
1352                                     ("mc addr[%d] = %#x:%#x:%#x:%#x:%#x:%#x\n",
1353                                      i++, ha->addr[0], ha->addr[1], ha->addr[2],
1354                                      ha->addr[3], ha->addr[4], ha->addr[5]);
1355                                 /* The upper 6 bits of the calculated CRC are used to
1356                                  * index the content of the Hash Table Reg 0 and 1.
1357                                  * */
1358                                 crc32_val =
1359                                     (bitrev32(~crc32_le(~0, ha->addr, 6)) >>
1360                                      26);
1361                                 /* The most significant bit determines the register
1362                                  * to use (Hash Table Reg X, X = 0 and 1) while the
1363                                  * other 5(0x1F) bits determines the bit within the
1364                                  * selected register
1365                                  * */
1366                                 mc_filter[crc32_val >> 5] |=
1367                                     (1 << (crc32_val & 0x1F));
1368                         }
1369                 } else if (pdata->max_hash_table_size == 128) {
1370                         netdev_for_each_mc_addr(ha, dev) {
1371                                 DBGPR_FILTER
1372                                     ("mc addr[%d] = %#x:%#x:%#x:%#x:%#x:%#x\n",
1373                                      i++, ha->addr[0], ha->addr[1], ha->addr[2],
1374                                      ha->addr[3], ha->addr[4], ha->addr[5]);
1375                                 /* The upper 7 bits of the calculated CRC are used to
1376                                  * index the content of the Hash Table Reg 0,1,2 and 3.
1377                                  * */
1378                                 crc32_val =
1379                                     (bitrev32(~crc32_le(~0, ha->addr, 6)) >>
1380                                      25);
1381
1382                                 pr_err("crc_le = %#x, crc_be = %#x\n",
1383                                        bitrev32(~crc32_le(~0, ha->addr, 6)),
1384                                        bitrev32(~crc32_be(~0, ha->addr, 6)));
1385
1386                                 /* The most significant 2 bits determines the register
1387                                  * to use (Hash Table Reg X, X = 0,1,2 and 3) while the
1388                                  * other 5(0x1F) bits determines the bit within the
1389                                  * selected register
1390                                  * */
1391                                 mc_filter[crc32_val >> 5] |=
1392                                     (1 << (crc32_val & 0x1F));
1393                         }
1394                 } else if (pdata->max_hash_table_size == 256) {
1395                         netdev_for_each_mc_addr(ha, dev) {
1396                                 DBGPR_FILTER
1397                                     ("mc addr[%d] = %#x:%#x:%#x:%#x:%#x:%#x\n",
1398                                      i++, ha->addr[0], ha->addr[1], ha->addr[2],
1399                                      ha->addr[3], ha->addr[4], ha->addr[5]);
1400                                 /* The upper 8 bits of the calculated CRC are used to
1401                                  * index the content of the Hash Table Reg 0,1,2,3,4,
1402                                  * 5,6, and 7.
1403                                  * */
1404                                 crc32_val =
1405                                     (bitrev32(~crc32_le(~0, ha->addr, 6)) >>
1406                                      24);
1407                                 /* The most significant 3 bits determines the register
1408                                  * to use (Hash Table Reg X, X = 0,1,2,3,4,5,6 and 7) while
1409                                  * the other 5(0x1F) bits determines the bit within the
1410                                  * selected register
1411                                  * */
1412                                 mc_filter[crc32_val >> 5] |=
1413                                     (1 << (crc32_val & 0x1F));
1414                         }
1415                 }
1416
1417                 for (i = 0; i < EQOS_HTR_CNT; i++)
1418                         hw_if->update_hash_table_reg(i, mc_filter[i]);
1419
1420         } else {
1421                 DBGPR_FILTER
1422                     ("select PERFECT FILTERING for mc addresses, mc_count = %d, max_addr_reg_cnt = %d\n",
1423                      netdev_mc_count(dev), pdata->max_addr_reg_cnt);
1424
1425                 netdev_for_each_mc_addr(ha, dev) {
1426                         DBGPR_FILTER("mc addr[%d] = %#x:%#x:%#x:%#x:%#x:%#x\n",
1427                                      i,
1428                                      ha->addr[0], ha->addr[1], ha->addr[2],
1429                                      ha->addr[3], ha->addr[4], ha->addr[5]);
1430                         if (i < 32)
1431                                 hw_if->update_mac_addr1_31_low_high_reg(i,
1432                                                                         ha->
1433                                                                         addr);
1434                         else
1435                                 hw_if->update_mac_addr32_127_low_high_reg(i,
1436                                                                           ha->
1437                                                                           addr);
1438
1439                         if ((pdata->ptp_cfg.use_tagged_ptp) &&
1440                             (is_ptp_addr(ha->addr)))
1441                                 hw_if->config_ptp_channel(pdata->ptp_cfg.
1442                                                           ptp_dma_ch_id, i);
1443
1444                         i++;
1445                 }
1446         }
1447
1448         DBGPR_FILTER("<--eqos_prepare_mc_list\n");
1449
1450         return ret;
1451 }
1452
1453 /*!
1454 * \brief API to configure the unicast address in device.
1455 *
1456 * \details This function collects all the unicast addresses
1457 * and updates the device.
1458 *
1459 * \param[in] dev - pointer to net_device structure.
1460 *
1461 * \retval 0 if perfect filtering is seleted  & 1 if hash
1462 * filtering is seleted.
1463 */
1464 static int eqos_prepare_uc_list(struct net_device *dev)
1465 {
1466         struct eqos_prv_data *pdata = netdev_priv(dev);
1467         struct hw_if_struct *hw_if = &(pdata->hw_if);
1468         u32 uc_filter[EQOS_HTR_CNT];
1469         struct netdev_hw_addr *ha = NULL;
1470         int crc32_val = 0;
1471         int ret = 0, i = 1;
1472
1473         DBGPR_FILTER("-->eqos_prepare_uc_list\n");
1474
1475         if (pdata->l2_filtering_mode) {
1476                 DBGPR_FILTER
1477                     ("select HASH FILTERING for uc addresses: uc_count = %d\n",
1478                      netdev_uc_count(dev));
1479                 ret = 1;
1480                 memset(uc_filter, 0, sizeof(uc_filter));
1481
1482                 if (pdata->max_hash_table_size == 64) {
1483                         netdev_for_each_uc_addr(ha, dev) {
1484                                 DBGPR_FILTER
1485                                     ("uc addr[%d] = %#x:%#x:%#x:%#x:%#x:%#x\n",
1486                                      i++, ha->addr[0], ha->addr[1], ha->addr[2],
1487                                      ha->addr[3], ha->addr[4], ha->addr[5]);
1488                                 crc32_val =
1489                                     (bitrev32(~crc32_le(~0, ha->addr, 6)) >>
1490                                      26);
1491                                 uc_filter[crc32_val >> 5] |=
1492                                     (1 << (crc32_val & 0x1F));
1493                         }
1494                 } else if (pdata->max_hash_table_size == 128) {
1495                         netdev_for_each_uc_addr(ha, dev) {
1496                                 DBGPR_FILTER
1497                                     ("uc addr[%d] = %#x:%#x:%#x:%#x:%#x:%#x\n",
1498                                      i++, ha->addr[0], ha->addr[1], ha->addr[2],
1499                                      ha->addr[3], ha->addr[4], ha->addr[5]);
1500                                 crc32_val =
1501                                     (bitrev32(~crc32_le(~0, ha->addr, 6)) >>
1502                                      25);
1503                                 uc_filter[crc32_val >> 5] |=
1504                                     (1 << (crc32_val & 0x1F));
1505                         }
1506                 } else if (pdata->max_hash_table_size == 256) {
1507                         netdev_for_each_uc_addr(ha, dev) {
1508                                 DBGPR_FILTER
1509                                     ("uc addr[%d] = %#x:%#x:%#x:%#x:%#x:%#x\n",
1510                                      i++, ha->addr[0], ha->addr[1], ha->addr[2],
1511                                      ha->addr[3], ha->addr[4], ha->addr[5]);
1512                                 crc32_val =
1513                                     (bitrev32(~crc32_le(~0, ha->addr, 6)) >>
1514                                      24);
1515                                 uc_filter[crc32_val >> 5] |=
1516                                     (1 << (crc32_val & 0x1F));
1517                         }
1518                 }
1519
1520                 /* configure hash value of real/default interface also */
1521                 DBGPR_FILTER
1522                     ("real/default dev_addr = %#x:%#x:%#x:%#x:%#x:%#x\n",
1523                      dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1524                      dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1525
1526                 if (pdata->max_hash_table_size == 64) {
1527                         crc32_val =
1528                             (bitrev32(~crc32_le(~0, dev->dev_addr, 6)) >> 26);
1529                         uc_filter[crc32_val >> 5] |= (1 << (crc32_val & 0x1F));
1530                 } else if (pdata->max_hash_table_size == 128) {
1531                         crc32_val =
1532                             (bitrev32(~crc32_le(~0, dev->dev_addr, 6)) >> 25);
1533                         uc_filter[crc32_val >> 5] |= (1 << (crc32_val & 0x1F));
1534
1535                 } else if (pdata->max_hash_table_size == 256) {
1536                         crc32_val =
1537                             (bitrev32(~crc32_le(~0, dev->dev_addr, 6)) >> 24);
1538                         uc_filter[crc32_val >> 5] |= (1 << (crc32_val & 0x1F));
1539                 }
1540
1541                 for (i = 0; i < EQOS_HTR_CNT; i++)
1542                         hw_if->update_hash_table_reg(i, uc_filter[i]);
1543
1544         } else {
1545                 DBGPR_FILTER
1546                     ("select PERFECT FILTERING for uc addresses: uc_count = %d\n",
1547                      netdev_uc_count(dev));
1548
1549                 netdev_for_each_uc_addr(ha, dev) {
1550                         DBGPR_FILTER("uc addr[%d] = %#x:%#x:%#x:%#x:%#x:%#x\n",
1551                                      i, ha->addr[0], ha->addr[1], ha->addr[2],
1552                                      ha->addr[3], ha->addr[4], ha->addr[5]);
1553                         if (i < 32)
1554                                 hw_if->update_mac_addr1_31_low_high_reg(i,
1555                                                                         ha->
1556                                                                         addr);
1557                         else
1558                                 hw_if->update_mac_addr32_127_low_high_reg(i,
1559                                                                           ha->
1560                                                                           addr);
1561                         i++;
1562                 }
1563         }
1564
1565         DBGPR_FILTER("<--eqos_prepare_uc_list\n");
1566
1567         return ret;
1568 }
1569
1570 /*!
1571 * \brief API to set the device receive mode
1572 *
1573 * \details The set_multicast_list function is called when the multicast list
1574 * for the device changes and when the flags change.
1575 *
1576 * \param[in] dev - pointer to net_device structure.
1577 *
1578 * \return void
1579 */
1580 static void eqos_set_rx_mode(struct net_device *dev)
1581 {
1582         struct eqos_prv_data *pdata = netdev_priv(dev);
1583         struct hw_if_struct *hw_if = &(pdata->hw_if);
1584         unsigned char pr_mode = 0;
1585         unsigned char huc_mode = 0;
1586         unsigned char hmc_mode = 0;
1587         unsigned char pm_mode = 0;
1588         unsigned char hpf_mode = 0;
1589         int mode, i;
1590
1591         DBGPR_FILTER("-->eqos_set_rx_mode\n");
1592
1593         spin_lock(&pdata->lock);
1594
1595         if (dev->flags & IFF_PROMISC) {
1596                 DBGPR_FILTER
1597                     ("PROMISCUOUS MODE (Accept all packets irrespective of DA)\n");
1598                 pr_mode = 1;
1599 #ifdef ENABLE_PERFECT_L2_FILTER
1600         } else if ((dev->flags & IFF_ALLMULTI)) {
1601 #else
1602         } else if ((dev->flags & IFF_ALLMULTI) ||
1603                    (netdev_mc_count(dev) > (pdata->max_hash_table_size))) {
1604 #endif
1605                 DBGPR_FILTER("pass all multicast pkt\n");
1606                 pm_mode = 1;
1607                 if (pdata->max_hash_table_size) {
1608                         for (i = 0; i < EQOS_HTR_CNT; i++)
1609                                 hw_if->update_hash_table_reg(i, 0xffffffff);
1610                 }
1611         } else if (!netdev_mc_empty(dev)) {
1612                 DBGPR_FILTER("pass list of multicast pkt\n");
1613                 if ((netdev_mc_count(dev) > (pdata->max_addr_reg_cnt - 1)) &&
1614                     (!pdata->max_hash_table_size)) {
1615                         /* switch to PROMISCUOUS mode */
1616                         pr_mode = 1;
1617                 } else {
1618                         mode = eqos_prepare_mc_list(dev);
1619                         if (mode) {
1620                                 /* Hash filtering for multicast */
1621                                 hmc_mode = 1;
1622                         } else {
1623                                 /* Perfect filtering for multicast */
1624                                 hmc_mode = 0;
1625                                 hpf_mode = 1;
1626                         }
1627                 }
1628         }
1629
1630         /* Handle multiple unicast addresses */
1631         if ((netdev_uc_count(dev) > (pdata->max_addr_reg_cnt - 1)) &&
1632             (!pdata->max_hash_table_size)) {
1633                 /* switch to PROMISCUOUS mode */
1634                 pr_mode = 1;
1635         } else if (!netdev_uc_empty(dev)) {
1636                 mode = eqos_prepare_uc_list(dev);
1637                 if (mode) {
1638                         /* Hash filtering for unicast */
1639                         huc_mode = 1;
1640                 } else {
1641                         /* Perfect filtering for unicast */
1642                         huc_mode = 0;
1643                         hpf_mode = 1;
1644                 }
1645         }
1646
1647         hw_if->config_mac_pkt_filter_reg(pr_mode, huc_mode,
1648                                          hmc_mode, pm_mode, hpf_mode);
1649
1650         spin_unlock(&pdata->lock);
1651
1652         pr_debug("<--eqos_set_rx_mode\n");
1653 }
1654
1655
1656 /*!
1657 * \brief API to transmit the packets
1658 *
1659 * \details The start_xmit function initiates the transmission of a packet.
1660 * The full packet (protocol headers and all) is contained in a socket buffer
1661 * (sk_buff) structure.
1662 *
1663 * \param[in] skb - pointer to sk_buff structure
1664 * \param[in] dev - pointer to net_device structure
1665 *
1666 * \return integer
1667 *
1668 * \retval 0
1669 */
1670
1671 static int eqos_start_xmit(struct sk_buff *skb, struct net_device *dev)
1672 {
1673         struct eqos_prv_data *pdata = netdev_priv(dev);
1674         UINT qinx = skb_get_queue_mapping(skb);
1675
1676         struct tx_ring *ptx_ring = GET_TX_WRAPPER_DESC(qinx);
1677         struct s_tx_pkt_features *tx_pkt_features = GET_TX_PKT_FEATURES_PTR(qinx);
1678
1679         int cnt = 0;
1680         struct hw_if_struct *hw_if = &pdata->hw_if;
1681         struct desc_if_struct *desc_if = &pdata->desc_if;
1682         INT retval = NETDEV_TX_OK;
1683         int tso;
1684
1685         pr_debug("-->eqos_start_xmit: skb->len = %d, qinx = %u\n", skb->len, qinx);
1686
1687         if (ptx_ring->tx_pkt_queued > (TX_DESC_CNT >> 2))
1688                 process_tx_completions(pdata->dev, pdata, qinx);
1689
1690         spin_lock(&pdata->chinfo[qinx].chan_tx_lock);
1691
1692         if (skb->len <= 0) {
1693                 dev_kfree_skb_any(skb);
1694                 pr_err("%s : Empty skb received from stack\n", dev->name);
1695                 goto tx_netdev_return;
1696         }
1697
1698
1699         memset(tx_pkt_features, 0, sizeof(struct s_tx_pkt_features));
1700
1701 #ifdef EQOS_ENABLE_VLAN_TAG
1702         ptx_ring->vlan_tag_present = 0;
1703 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)
1704         if (vlan_tx_tag_present(skb)) {
1705                 USHORT vlan_tag = vlan_tx_tag_get(skb);
1706 #else
1707         if (skb_vlan_tag_present(skb)) {
1708                 USHORT vlan_tag = skb_vlan_tag_get(skb);
1709 #endif
1710                 vlan_tag |= (skb->priority << 13);
1711                 ptx_ring->vlan_tag_present = 1;
1712                 if (vlan_tag != ptx_ring->vlan_tag_id ||
1713                     ptx_ring->context_setup == 1) {
1714                         ptx_ring->vlan_tag_id = vlan_tag;
1715                         if (Y_TRUE == ptx_ring->tx_vlan_tag_via_reg) {
1716                                 pr_err("VLAN control info update via reg\n");
1717                                 hw_if->enable_vlan_reg_control(ptx_ring);
1718                         } else {
1719                                 hw_if->enable_vlan_desc_control(pdata);
1720                                 TX_PKT_FEATURES_PKT_ATTRIBUTES_VLAN_PKT_WR
1721                                     (tx_pkt_features->pkt_attributes, 1);
1722                                 TX_PKT_FEATURES_VLAN_TAG_VT_WR
1723                                     (tx_pkt_features->vlan_tag, vlan_tag);
1724                         }
1725                 }
1726                 pdata->xstats.tx_vlan_pkt_n++;
1727         }
1728 #endif
1729
1730         /* check for hw tstamping */
1731         if (pdata->hw_feat.tsstssel && pdata->hwts_tx_en) {
1732                 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) {
1733                         /* declare that device is doing timestamping */
1734                         skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
1735                         TX_PKT_FEATURES_PKT_ATTRIBUTES_PTP_ENABLE_WR
1736                             (tx_pkt_features->pkt_attributes, 1);
1737                         DBGPR_PTP
1738                             ("Got PTP pkt to transmit [qinx = %d, cur_tx = %d]\n",
1739                              qinx, ptx_ring->cur_tx);
1740                 }
1741         }
1742
1743         tso = desc_if->handle_tso(dev, skb);
1744         if (tso < 0) {
1745                 pr_err("Unable to handle TSO\n");
1746                 dev_kfree_skb_any(skb);
1747                 retval = NETDEV_TX_OK;
1748                 goto tx_netdev_return;
1749         }
1750         if (tso) {
1751                 pdata->xstats.tx_tso_pkt_n++;
1752                 TX_PKT_FEATURES_PKT_ATTRIBUTES_TSO_ENABLE_WR(tx_pkt_features->
1753                                                              pkt_attributes, 1);
1754         } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1755                 TX_PKT_FEATURES_PKT_ATTRIBUTES_CSUM_ENABLE_WR(tx_pkt_features->
1756                                                               pkt_attributes,
1757                                                               1);
1758         }
1759
1760         cnt = desc_if->tx_swcx_alloc(dev, skb);
1761         if (cnt <= 0) {
1762                 if (cnt == 0) {
1763                         ptx_ring->queue_stopped = 1;
1764                         netif_stop_subqueue(dev, qinx);
1765                         pr_debug("%s(): TX ring full for queue %d\n",
1766                               __func__, qinx);
1767                         retval = NETDEV_TX_BUSY;
1768                         goto tx_netdev_return;
1769                 }
1770                 dev_kfree_skb_any(skb);
1771                 retval = NETDEV_TX_OK;
1772                 goto tx_netdev_return;
1773         }
1774
1775         dev->trans_start = jiffies;
1776
1777         ptx_ring->free_desc_cnt -= cnt;
1778         ptx_ring->tx_pkt_queued += cnt;
1779
1780 #ifdef EQOS_ENABLE_TX_PKT_DUMP
1781         print_pkt(skb, skb->len, 1, (ptx_ring->cur_tx - 1));
1782 #endif
1783
1784 #ifdef ENABLE_CHANNEL_DATA_CHECK
1785         check_channel_data(skb, qinx, 0);
1786 #endif
1787
1788         if ((pdata->eee_enabled) && (pdata->tx_path_in_lpi_mode) &&
1789             (!pdata->use_lpi_tx_automate))
1790                 eqos_disable_eee_mode(pdata);
1791
1792         /* fallback to software time stamping if core doesn't
1793          * support hardware time stamping */
1794         if ((pdata->hw_feat.tsstssel == 0) || (pdata->hwts_tx_en == 0))
1795                 skb_tx_timestamp(skb);
1796
1797         /* configure required descriptor fields for transmission */
1798         hw_if->pre_xmit(pdata, qinx);
1799
1800  tx_netdev_return:
1801         spin_unlock(&pdata->chinfo[qinx].chan_tx_lock);
1802
1803         pr_debug("<--eqos_start_xmit\n");
1804
1805         return retval;
1806 }
1807
1808 static void eqos_print_rx_tstamp_info(struct s_rx_desc *rxdesc,
1809                                       unsigned int qinx)
1810 {
1811         u32 ptp_status = 0;
1812         u32 pkt_type = 0;
1813         char *tstamp_dropped = NULL;
1814         char *tstamp_available = NULL;
1815         char *ptp_version = NULL;
1816         char *ptp_pkt_type = NULL;
1817         char *ptp_msg_type = NULL;
1818
1819         DBGPR_PTP("-->eqos_print_rx_tstamp_info\n");
1820
1821         /* status in rdes1 is not valid */
1822         if (!(rxdesc->rdes3 & EQOS_RDESC3_RS1V))
1823                 return;
1824
1825         ptp_status = rxdesc->rdes1;
1826         tstamp_dropped = ((ptp_status & 0x8000) ? "YES" : "NO");
1827         tstamp_available = ((ptp_status & 0x4000) ? "YES" : "NO");
1828         ptp_version =
1829             ((ptp_status & 0x2000) ? "v2 (1588-2008)" : "v1 (1588-2002)");
1830         ptp_pkt_type =
1831             ((ptp_status & 0x1000) ? "ptp over Eth" : "ptp over IPv4/6");
1832
1833         pkt_type = ((ptp_status & 0xF00) >> 8);
1834         switch (pkt_type) {
1835         case 0:
1836                 ptp_msg_type = "NO PTP msg received";
1837                 break;
1838         case 1:
1839                 ptp_msg_type = "SYNC";
1840                 break;
1841         case 2:
1842                 ptp_msg_type = "Follow_Up";
1843                 break;
1844         case 3:
1845                 ptp_msg_type = "Delay_Req";
1846                 break;
1847         case 4:
1848                 ptp_msg_type = "Delay_Resp";
1849                 break;
1850         case 5:
1851                 ptp_msg_type = "Pdelay_Req";
1852                 break;
1853         case 6:
1854                 ptp_msg_type = "Pdelay_Resp";
1855                 break;
1856         case 7:
1857                 ptp_msg_type = "Pdelay_Resp_Follow_up";
1858                 break;
1859         case 8:
1860                 ptp_msg_type = "Announce";
1861                 break;
1862         case 9:
1863                 ptp_msg_type = "Management";
1864                 break;
1865         case 10:
1866                 ptp_msg_type = "Signaling";
1867                 break;
1868         case 11:
1869         case 12:
1870         case 13:
1871         case 14:
1872                 ptp_msg_type = "Reserved";
1873                 break;
1874         case 15:
1875                 ptp_msg_type = "PTP pkr with Reserved Msg Type";
1876                 break;
1877         }
1878
1879         DBGPR_PTP("Rx timestamp detail for queue %d\n"
1880                   "tstamp dropped    = %s\n"
1881                   "tstamp available  = %s\n"
1882                   "PTP version       = %s\n"
1883                   "PTP Pkt Type      = %s\n"
1884                   "PTP Msg Type      = %s\n",
1885                   qinx, tstamp_dropped, tstamp_available,
1886                   ptp_version, ptp_pkt_type, ptp_msg_type);
1887
1888         DBGPR_PTP("<--eqos_print_rx_tstamp_info\n");
1889 }
1890
1891 /*!
1892 * \brief API to get rx time stamp value.
1893 *
1894 * \details This function will read received packet's timestamp from
1895 * the descriptor and pass it to stack and also perform some sanity checks.
1896 *
1897 * \param[in] pdata - pointer to private data structure.
1898 * \param[in] skb - pointer to sk_buff structure.
1899 * \param[in] prx_ring - pointer to wrapper receive descriptor structure.
1900 * \param[in] qinx - Queue/Channel number.
1901 *
1902 * \return integer
1903 *
1904 * \retval 0 if no context descriptor
1905 * \retval 1 if timestamp is valid
1906 * \retval 2 if time stamp is corrupted
1907 */
1908
1909 static unsigned char eqos_get_rx_hwtstamp(struct eqos_prv_data *pdata,
1910                                           struct sk_buff *skb,
1911                                           struct rx_ring
1912                                           *prx_ring, unsigned int qinx)
1913 {
1914         struct s_rx_desc *prx_desc =
1915             GET_RX_DESC_PTR(qinx, prx_ring->cur_rx);
1916         struct s_rx_context_desc *rx_context_desc = NULL;
1917         struct hw_if_struct *hw_if = &(pdata->hw_if);
1918         struct skb_shared_hwtstamps *shhwtstamp = NULL;
1919         u64 ns;
1920         int retry, ret;
1921
1922         DBGPR_PTP("-->eqos_get_rx_hwtstamp\n");
1923
1924         eqos_print_rx_tstamp_info(prx_desc, qinx);
1925
1926         prx_ring->dirty_rx++;
1927         INCR_RX_DESC_INDEX(prx_ring->cur_rx, 1);
1928         rx_context_desc = GET_RX_DESC_PTR(qinx, prx_ring->cur_rx);
1929
1930         DBGPR_PTP("\nRX_CONTEX_DESC[%d %4p %d RECEIVED FROM DEVICE]"
1931                   " = %#x:%#x:%#x:%#x",
1932                   qinx, rx_context_desc, prx_ring->cur_rx,
1933                   rx_context_desc->rdes0, rx_context_desc->rdes1,
1934                   rx_context_desc->rdes2, rx_context_desc->rdes3);
1935
1936         /* check rx tsatmp */
1937         for (retry = 0; retry < 10; retry++) {
1938                 ret = hw_if->get_rx_tstamp_status(rx_context_desc);
1939                 if (ret == 1) {
1940                         /* time stamp is valid */
1941                         break;
1942                 } else if (ret == 0) {
1943                         pr_err("Device has not yet updated the context "
1944                                "desc to hold Rx time stamp(retry = %d)\n",
1945                                retry);
1946                 } else {
1947                         pr_err
1948                             ("Error: Rx time stamp is corrupted(retry = %d)\n",
1949                              retry);
1950                         return 2;
1951                 }
1952         }
1953
1954         if (retry == 10) {
1955                 pr_err("Device has not yet updated the context "
1956                        "desc to hold Rx time stamp(retry = %d)\n", retry);
1957                 prx_ring->dirty_rx--;
1958                 DECR_RX_DESC_INDEX(prx_ring->cur_rx);
1959                 return 0;
1960         }
1961
1962         pdata->xstats.rx_timestamp_captured_n++;
1963         /* get valid tstamp */
1964         ns = hw_if->get_rx_tstamp(rx_context_desc);
1965
1966         shhwtstamp = skb_hwtstamps(skb);
1967         memset(shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
1968         shhwtstamp->hwtstamp = ns_to_ktime(ns);
1969
1970         DBGPR_PTP("<--eqos_get_rx_hwtstamp\n");
1971
1972         return 1;
1973 }
1974
1975 /*!
1976 * \brief API to get tx time stamp value.
1977 *
1978 * \details This function will read timestamp from the descriptor
1979 * and pass it to stack and also perform some sanity checks.
1980 *
1981 * \param[in] pdata - pointer to private data structure.
1982 * \param[in] txdesc - pointer to transmit descriptor structure.
1983 * \param[in] skb - pointer to sk_buff structure.
1984 *
1985 * \return integer
1986 *
1987 * \retval 1 if time stamp is taken
1988 * \retval 0 if time stamp in not taken/valid
1989 */
1990
1991 static unsigned int eqos_get_tx_hwtstamp(struct eqos_prv_data *pdata,
1992                                          struct s_tx_desc *txdesc,
1993                                          struct sk_buff *skb)
1994 {
1995         struct hw_if_struct *hw_if = &(pdata->hw_if);
1996         struct skb_shared_hwtstamps shhwtstamp;
1997         u64 ns;
1998
1999         DBGPR_PTP("-->eqos_get_tx_hwtstamp\n");
2000
2001         if (hw_if->drop_tx_status_enabled() == 0) {
2002                 /* check tx tstamp status */
2003                 if (!hw_if->get_tx_tstamp_status(txdesc)) {
2004                         pr_err
2005                             ("tx timestamp is not captured for this packet\n");
2006                         return 0;
2007                 }
2008
2009                 /* get the valid tstamp */
2010                 ns = hw_if->get_tx_tstamp(txdesc);
2011         } else {
2012                 /* drop tx status mode is enabled, hence read time
2013                  * stamp from register instead of descriptor */
2014
2015                 /* check tx tstamp status */
2016                 if (!hw_if->get_tx_tstamp_status_via_reg()) {
2017                         pr_err
2018                             ("tx timestamp is not captured for this packet\n");
2019                         return 0;
2020                 }
2021
2022                 /* get the valid tstamp */
2023                 ns = hw_if->get_tx_tstamp_via_reg();
2024         }
2025
2026         pdata->xstats.tx_timestamp_captured_n++;
2027         memset(&shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
2028         shhwtstamp.hwtstamp = ns_to_ktime(ns);
2029         /* pass tstamp to stack */
2030         skb_tstamp_tx(skb, &shhwtstamp);
2031
2032         DBGPR_PTP("<--eqos_get_tx_hwtstamp\n");
2033
2034         return 1;
2035 }
2036
2037 /*!
2038 * \brief API to update the tx status.
2039 *
2040 * \details This function is called in isr handler once after getting
2041 * transmit complete interrupt to update the transmited packet status
2042 * and it does some house keeping work like updating the
2043 * private data structure variables.
2044 *
2045 * \param[in] dev - pointer to net_device structure
2046 * \param[in] pdata - pointer to private data structure.
2047 *
2048 * \return void
2049 */
2050
2051 static void process_tx_completions(struct net_device *dev,
2052                                    struct eqos_prv_data *pdata, UINT qinx)
2053 {
2054         struct tx_ring *ptx_ring =
2055             GET_TX_WRAPPER_DESC(qinx);
2056         struct s_tx_desc *ptx_desc = NULL;
2057         struct tx_swcx_desc *ptx_swcx_desc = NULL;
2058         struct hw_if_struct *hw_if = &(pdata->hw_if);
2059         struct desc_if_struct *desc_if = &(pdata->desc_if);
2060         int err_incremented;
2061         unsigned int tstamp_taken = 0;
2062
2063         pr_debug("-->%s(): ptx_ring->tx_pkt_queued = %d"
2064               " dirty_tx = %d, qinx = %u\n",
2065               __func__,
2066               ptx_ring->tx_pkt_queued, ptx_ring->dirty_tx, qinx);
2067
2068         spin_lock(&pdata->chinfo[qinx].chan_tx_lock);
2069
2070         pdata->xstats.tx_clean_n[qinx]++;
2071         while (ptx_ring->tx_pkt_queued > 0) {
2072                 ptx_desc = GET_TX_DESC_PTR(qinx, ptx_ring->dirty_tx);
2073                 ptx_swcx_desc = GET_TX_BUF_PTR(qinx, ptx_ring->dirty_tx);
2074                 tstamp_taken = 0;
2075
2076                 if (!hw_if->tx_complete(ptx_desc))
2077                         break;
2078
2079 #ifdef EQOS_ENABLE_TX_DESC_DUMP
2080                 dump_tx_desc(pdata, ptx_ring->dirty_tx, ptx_ring->dirty_tx,
2081                              0, qinx);
2082 #endif
2083
2084                 /* update the tx error if any by looking at last segment
2085                  * for NORMAL descriptors
2086                  * */
2087                 if ((hw_if->get_tx_desc_ls(ptx_desc)) &&
2088                     !(hw_if->get_tx_desc_ctxt(ptx_desc))) {
2089                         if (ptx_swcx_desc->skb == NULL) {
2090                                 dev_err(&pdata->pdev->dev,
2091                                 "NULL SKB in process_tx_completions()\n");
2092                         }
2093                         /* check whether skb support hw tstamp */
2094                         if ((pdata->hw_feat.tsstssel) &&
2095                             (skb_shinfo(ptx_swcx_desc->skb)->
2096                              tx_flags & SKBTX_IN_PROGRESS)) {
2097                                 tstamp_taken =
2098                                     eqos_get_tx_hwtstamp(pdata, ptx_desc,
2099                                                          ptx_swcx_desc->skb);
2100                                 if (tstamp_taken) {
2101                                         DBGPR_PTP
2102                                             ("passed tx timestamp to stack[qinx = %d, dirty_tx = %d]\n",
2103                                              qinx, ptx_ring->dirty_tx);
2104                                 }
2105                         }
2106
2107                         err_incremented = 0;
2108                         if (hw_if->tx_window_error) {
2109                                 if (hw_if->tx_window_error(ptx_desc)) {
2110                                         err_incremented = 1;
2111                                         dev->stats.tx_window_errors++;
2112                                 }
2113                         }
2114                         if (hw_if->tx_aborted_error) {
2115                                 if (hw_if->tx_aborted_error(ptx_desc)) {
2116                                         err_incremented = 1;
2117                                         dev->stats.tx_aborted_errors++;
2118                                         if (hw_if->tx_handle_aborted_error)
2119                                                 hw_if->
2120                                                     tx_handle_aborted_error
2121                                                     (ptx_desc);
2122                                 }
2123                         }
2124                         if (hw_if->tx_carrier_lost_error) {
2125                                 if (hw_if->tx_carrier_lost_error(ptx_desc)) {
2126                                         err_incremented = 1;
2127                                         dev->stats.tx_carrier_errors++;
2128                                 }
2129                         }
2130                         if (hw_if->tx_fifo_underrun) {
2131                                 if (hw_if->tx_fifo_underrun(ptx_desc)) {
2132                                         err_incremented = 1;
2133                                         dev->stats.tx_fifo_errors++;
2134                                         if (hw_if->tx_update_fifo_threshold)
2135                                                 hw_if->
2136                                                     tx_update_fifo_threshold
2137                                                     (ptx_desc);
2138                                 }
2139                         }
2140                         if (hw_if->tx_get_collision_count)
2141                                 dev->stats.collisions +=
2142                                     hw_if->tx_get_collision_count(ptx_desc);
2143
2144                         if (err_incremented == 1)
2145                                 dev->stats.tx_errors++;
2146
2147                         pdata->xstats.q_tx_pkt_n[qinx]++;
2148                         pdata->xstats.tx_pkt_n++;
2149                         dev->stats.tx_packets++;
2150                 }
2151                 dev->stats.tx_bytes += ptx_swcx_desc->len;
2152                 desc_if->tx_swcx_free(pdata, ptx_swcx_desc);
2153
2154                 /* reset the descriptor so that driver/host can reuse it */
2155                 hw_if->tx_desc_reset(ptx_ring->dirty_tx, pdata, qinx);
2156
2157                 INCR_TX_DESC_INDEX(ptx_ring->dirty_tx, 1);
2158                 ptx_ring->free_desc_cnt++;
2159                 ptx_ring->tx_pkt_queued--;
2160         }
2161
2162         if ((ptx_ring->queue_stopped == 1) && (ptx_ring->free_desc_cnt > 0)) {
2163                 ptx_ring->queue_stopped = 0;
2164                 netif_wake_subqueue(dev, qinx);
2165         }
2166
2167         if ((pdata->eee_enabled) && (!pdata->tx_path_in_lpi_mode) &&
2168             (!pdata->use_lpi_tx_automate)) {
2169                 eqos_enable_eee_mode(pdata);
2170                 mod_timer(&pdata->eee_ctrl_timer,
2171                           EQOS_LPI_TIMER(EQOS_DEFAULT_LPI_TIMER));
2172         }
2173
2174         spin_unlock(&pdata->chinfo[qinx].chan_tx_lock);
2175
2176         pr_debug("<--%s(): ptx_ring->tx_pkt_queued = %d\n",
2177               __func__, ptx_ring->tx_pkt_queued);
2178 }
2179
2180 #ifdef YDEBUG_FILTER
2181 static void eqos_check_rx_filter_status(struct s_rx_desc *prx_desc)
2182 {
2183         u32 rdes2 = prx_desc->rdes2;
2184         u32 rdes3 = prx_desc->rdes3;
2185
2186         /* Receive Status rdes2 Valid ? */
2187         if ((rdes3 & 0x8000000) == 0x8000000) {
2188                 if ((rdes2 & 0x400) == 0x400)
2189                         pr_err("ARP pkt received\n");
2190                 if ((rdes2 & 0x800) == 0x800)
2191                         pr_err("ARP reply not generated\n");
2192                 if ((rdes2 & 0x8000) == 0x8000)
2193                         pr_err("VLAN pkt passed VLAN filter\n");
2194                 if ((rdes2 & 0x10000) == 0x10000)
2195                         pr_err("SA Address filter fail\n");
2196                 if ((rdes2 & 0x20000) == 0x20000)
2197                         pr_err("DA Addess filter fail\n");
2198                 if ((rdes2 & 0x40000) == 0x40000)
2199                         pr_err
2200                             ("pkt passed the HASH filter in MAC and HASH value = %#x\n",
2201                              (rdes2 >> 19) & 0xff);
2202                 if ((rdes2 & 0x8000000) == 0x8000000)
2203                         pr_err("L3 filter(%d) Match\n", ((rdes2 >> 29) & 0x7));
2204                 if ((rdes2 & 0x10000000) == 0x10000000)
2205                         pr_err("L4 filter(%d) Match\n", ((rdes2 >> 29) & 0x7));
2206         }
2207 }
2208 #endif                          /* YDEBUG_FILTER */
2209
2210 /* pass skb to upper layer */
2211 static void eqos_receive_skb(struct eqos_prv_data *pdata,
2212                              struct net_device *dev, struct sk_buff *skb,
2213                              UINT qinx)
2214 {
2215         struct eqos_rx_queue *rx_queue = GET_RX_QUEUE_PTR(qinx);
2216
2217         skb_record_rx_queue(skb, qinx);
2218         skb->dev = dev;
2219         skb->protocol = eth_type_trans(skb, dev);
2220
2221         if (dev->features & NETIF_F_GRO) {
2222                 napi_gro_receive(&rx_queue->napi, skb);
2223         } else if ((dev->features & NETIF_F_LRO) &&
2224                    (skb->ip_summed == CHECKSUM_UNNECESSARY)) {
2225                 lro_receive_skb(&rx_queue->lro_mgr, skb, (void *)pdata);
2226                 rx_queue->lro_flush_needed = 1;
2227         } else {
2228                 netif_receive_skb(skb);
2229         }
2230 }
2231
2232 /* Receive Checksum Offload configuration */
2233 static inline void eqos_config_rx_csum(struct eqos_prv_data *pdata,
2234                                        struct sk_buff *skb,
2235                                        struct s_rx_desc *prx_desc)
2236 {
2237         UINT rdes1;
2238
2239         skb->ip_summed = CHECKSUM_NONE;
2240
2241         if ((pdata->dev_state & NETIF_F_RXCSUM) == NETIF_F_RXCSUM) {
2242                 /* Receive Status rdes1 Valid ? */
2243                 if ((prx_desc->rdes3 & EQOS_RDESC3_RS1V)) {
2244                         /* check(rdes1.IPCE bit) whether device has done csum correctly or not */
2245                         RX_NORMAL_DESC_RDES1_RD(prx_desc->rdes1, rdes1);
2246                         if ((rdes1 & 0xC8) == 0x0)
2247                                 skb->ip_summed = CHECKSUM_UNNECESSARY;  /* csum done by device */
2248                 }
2249         }
2250 }
2251
2252 static inline void eqos_get_rx_vlan(struct eqos_prv_data *pdata,
2253                                     struct sk_buff *skb,
2254                                     struct s_rx_desc *prx_desc)
2255 {
2256         USHORT vlan_tag = 0;
2257
2258         if ((pdata->dev_state & NETIF_F_HW_VLAN_CTAG_RX) ==
2259             NETIF_F_HW_VLAN_CTAG_RX) {
2260                 /* Receive Status rdes0 Valid ? */
2261                 if ((prx_desc->rdes3 & EQOS_RDESC3_RS0V)) {
2262                         /* device received frame with VLAN Tag or
2263                          * double VLAN Tag ? */
2264                         if (((prx_desc->rdes3 & EQOS_RDESC3_LT) ==
2265                              0x40000) ||
2266                              ((prx_desc->rdes3 & EQOS_RDESC3_LT) ==
2267                                 0x50000)) {
2268                                 vlan_tag = prx_desc->rdes0 & 0xffff;
2269                                 /* insert VLAN tag into skb */
2270                                 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
2271                                                        vlan_tag);
2272                                 pdata->xstats.rx_vlan_pkt_n++;
2273                         }
2274                 }
2275         }
2276 }
2277
2278 /* This api check for payload type and returns
2279  * 1 if payload load is TCP else returns 0;
2280  * */
2281 static int eqos_check_for_tcp_payload(struct s_rx_desc *rxdesc)
2282 {
2283         u32 pt_type = 0;
2284         int ret = 0;
2285
2286         if (rxdesc->rdes3 & EQOS_RDESC3_RS1V) {
2287                 pt_type = rxdesc->rdes1 & EQOS_RDESC1_PT;
2288                 if (pt_type == EQOS_RDESC1_PT_TCP)
2289                         ret = 1;
2290         }
2291
2292         return ret;
2293 }
2294
2295 /*!
2296 * \brief API to pass the Rx packets to stack if default mode
2297 * is enabled.
2298 *
2299 * \details This function is invoked by main NAPI function in default
2300 * Rx mode. This function checks the
2301 * device descriptor for the packets and passes it to stack if any packtes
2302 * are received by device.
2303 *
2304 * \param[in] pdata - pointer to private data structure.
2305 * \param[in] quota - maximum no. of packets that we are allowed to pass
2306 * to into the kernel.
2307 * \param[in] qinx - DMA channel/queue no. to be checked for packet.
2308 *
2309 * \return integer
2310 *
2311 * \retval number of packets received.
2312 */
2313
2314 static int process_rx_completions(struct eqos_prv_data *pdata,
2315                                   int quota, UINT qinx)
2316 {
2317         struct rx_ring *prx_ring =
2318             GET_RX_WRAPPER_DESC(qinx);
2319         struct net_device *dev = pdata->dev;
2320         struct desc_if_struct *desc_if = &pdata->desc_if;
2321         struct hw_if_struct *hw_if = &(pdata->hw_if);
2322         struct sk_buff *skb = NULL;
2323         int received = 0;
2324         struct rx_swcx_desc *prx_swcx_desc = NULL;
2325         struct s_rx_desc *prx_desc = NULL;
2326         UINT pkt_len;
2327         UINT err_bits = EQOS_RDESC3_ES_BITS;
2328         u32 sw_cur_rx_desc_addr = 0;
2329         u32 hw_cur_rx_desc_addr = 0;
2330
2331         int ret;
2332
2333         pr_debug("-->%s(): qinx = %u, quota = %d\n", __func__, qinx, quota);
2334
2335         hw_cur_rx_desc_addr = prx_ring->hw_last_rx_desc_addr;
2336         while (received < quota) {
2337                 prx_swcx_desc = GET_RX_BUF_PTR(qinx, prx_ring->cur_rx);
2338                 prx_desc = GET_RX_DESC_PTR(qinx, prx_ring->cur_rx);
2339
2340                 sw_cur_rx_desc_addr =
2341                         GET_RX_DESC_DMA_ADDR(qinx, prx_ring->cur_rx);
2342
2343                 /* check for data availability */
2344                 if (!(prx_desc->rdes3 & EQOS_RDESC3_OWN) &&
2345                     prx_swcx_desc->skb) {
2346                         if (hw_cur_rx_desc_addr == sw_cur_rx_desc_addr) {
2347                                 DMA_CHRDR_RD(qinx,
2348                                              prx_ring->hw_last_rx_desc_addr);
2349                                 if (prx_ring->hw_last_rx_desc_addr ==
2350                                     hw_cur_rx_desc_addr)
2351                                         break;
2352                                 hw_cur_rx_desc_addr =
2353                                         prx_ring->hw_last_rx_desc_addr;
2354                         }
2355 #ifdef EQOS_ENABLE_RX_DESC_DUMP
2356                         dump_rx_desc(qinx, prx_desc, prx_ring->cur_rx);
2357 #endif
2358                         /* assign it to new skb */
2359                         skb = prx_swcx_desc->skb;
2360                         prx_swcx_desc->skb = NULL;
2361
2362                         dma_unmap_single(&pdata->pdev->dev, prx_swcx_desc->dma,
2363                                          pdata->rx_buffer_len,
2364                                          DMA_FROM_DEVICE);
2365                         prx_swcx_desc->dma = 0;
2366
2367                         /* get the packet length */
2368                         pkt_len = (prx_desc->rdes3 & EQOS_RDESC3_PL);
2369
2370 #ifdef EQOS_ENABLE_RX_PKT_DUMP
2371                         print_pkt(skb, pkt_len, 0, (prx_ring->cur_rx));
2372 #endif
2373
2374 #ifdef ENABLE_CHANNEL_DATA_CHECK
2375                         check_channel_data(skb, qinx, 1);
2376 #endif
2377
2378                         /* check for bad/oversized packet,
2379                          * error is valid only for last descriptor
2380                          * (OWN + LD bit set).
2381                          */
2382                         if (tegra_platform_is_unit_fpga())
2383                                 err_bits = EQOS_RDESC3_CRC | EQOS_RDESC3_OF;
2384
2385                         if (!(prx_desc->rdes3 & err_bits) &&
2386                             (prx_desc->rdes3 & EQOS_RDESC3_LD)) {
2387                                 /* pkt_len = pkt_len - 4; *//* CRC stripping */
2388
2389                                 /* code added for copybreak, this should improve
2390                                  * performance for small pkts with large amount
2391                                  * of reassembly being done in the stack
2392                                  */
2393                                 if (pkt_len < EQOS_COPYBREAK_DEFAULT) {
2394                                         struct sk_buff *new_skb =
2395                                             netdev_alloc_skb_ip_align(dev,
2396                                                                       pkt_len);
2397                                         if (new_skb) {
2398                                                 skb_copy_to_linear_data_offset
2399                                                     (new_skb, -NET_IP_ALIGN,
2400                                                      (skb->data - NET_IP_ALIGN),
2401                                                      (pkt_len + NET_IP_ALIGN));
2402                                                 /* recycle actual desc skb */
2403                                                 prx_swcx_desc->skb = skb;
2404                                                 skb = new_skb;
2405                                         } else {
2406                                                 /* just continue the old skb */
2407                                         }
2408                                 }
2409                                 skb_put(skb, pkt_len);
2410
2411                                 eqos_config_rx_csum(pdata, skb, prx_desc);
2412
2413 #ifdef EQOS_ENABLE_VLAN_TAG
2414                                 eqos_get_rx_vlan(pdata, skb, prx_desc);
2415 #endif
2416
2417 #ifdef YDEBUG_FILTER
2418                                 eqos_check_rx_filter_status(prx_desc);
2419 #endif
2420
2421                                 if (pdata->hw_feat.tsstssel &&
2422                                     pdata->hwts_rx_en &&
2423                                     hw_if->
2424                                     rx_tstamp_available(prx_desc)) {
2425                                         /* get rx tstamp if available */
2426                                         ret = eqos_get_rx_hwtstamp(pdata, skb,
2427                                                                    prx_ring,
2428                                                                    qinx);
2429                                         if (ret == 0) {
2430                                                 /* device has not yet updated
2431                                                  * the CONTEXT desc to hold the
2432                                                  * time stamp, hence delay the
2433                                                  * packet reception
2434                                                  */
2435                                                 prx_swcx_desc->skb = skb;
2436                                                 prx_swcx_desc->dma =
2437                                                     dma_map_single(&pdata->
2438                                                         pdev->dev,
2439                                                         skb->data,
2440                                                         pdata->rx_buffer_len,
2441                                                         DMA_FROM_DEVICE);
2442
2443                                                 if (dma_mapping_error
2444                                                     (&pdata->pdev->dev,
2445                                                      prx_swcx_desc->dma))
2446                                                         pr_err
2447                                                             ("failed to do the RX dma map\n");
2448                                                 goto rx_tstmp_failed;
2449                                         }
2450                                 }
2451
2452                                 if (!(dev->features & NETIF_F_GRO) &&
2453                                     (dev->features & NETIF_F_LRO)) {
2454                                         pdata->tcp_pkt =
2455                                             eqos_check_for_tcp_payload
2456                                             (prx_desc);
2457                                 }
2458
2459                                 dev->last_rx = jiffies;
2460                                 /* update the statistics */
2461                                 dev->stats.rx_packets++;
2462                                 dev->stats.rx_bytes += skb->len;
2463                                 eqos_receive_skb(pdata, dev, skb, qinx);
2464                                 received++;
2465                         } else {
2466                                 dump_rx_desc(qinx, prx_desc,
2467                                              prx_ring->cur_rx);
2468                                 if (!(prx_desc->rdes3 & EQOS_RDESC3_LD))
2469                                         pr_debug("Received oversized pkt,"
2470                                               "spanned across multiple desc\n");
2471
2472                                 /* recycle skb */
2473                                 prx_swcx_desc->skb = skb;
2474                                 dev->stats.rx_errors++;
2475                                 eqos_update_rx_errors(dev,
2476                                                       prx_desc->rdes3);
2477                         }
2478
2479                         prx_ring->dirty_rx++;
2480                         if (prx_ring->dirty_rx >=
2481                             prx_ring->skb_realloc_threshold)
2482                                 desc_if->realloc_skb(pdata, qinx);
2483
2484                         INCR_RX_DESC_INDEX(prx_ring->cur_rx, 1);
2485                 } else {
2486                         /* no more data to read */
2487                         break;
2488                 }
2489         }
2490
2491  rx_tstmp_failed:
2492
2493         if (prx_ring->dirty_rx)
2494                 desc_if->realloc_skb(pdata, qinx);
2495
2496         pr_debug("<--%s(): received = %d, qinx=%d\n", __func__, received, qinx);
2497
2498         return received;
2499 }
2500
2501 /*!
2502 * \brief API to update the rx status.
2503 *
2504 * \details This function is called in poll function to update the
2505 * status of received packets.
2506 *
2507 * \param[in] dev - pointer to net_device structure.
2508 * \param[in] rx_status - value of received packet status.
2509 *
2510 * \return void.
2511 */
2512
2513 void eqos_update_rx_errors(struct net_device *dev, unsigned int rx_status)
2514 {
2515         pr_debug("-->eqos_update_rx_errors\n");
2516
2517         /* received pkt with crc error */
2518         if ((rx_status & 0x1000000))
2519                 dev->stats.rx_crc_errors++;
2520
2521         /* received frame alignment */
2522         if ((rx_status & 0x100000))
2523                 dev->stats.rx_frame_errors++;
2524
2525         /* receiver fifo overrun */
2526         if ((rx_status & 0x200000))
2527                 dev->stats.rx_fifo_errors++;
2528
2529         pr_debug("<--eqos_update_rx_errors\n");
2530 }
2531
2532 static int handle_txrx_completions(struct eqos_prv_data *pdata, int qinx)
2533 {
2534         struct eqos_rx_queue *rx_queue;
2535         int received = 0;
2536         int budget = pdata->dt_cfg.chan_napi_quota[qinx];
2537
2538         pr_debug("-->%s(): chan=%d\n", __func__, qinx);
2539
2540         rx_queue = GET_RX_QUEUE_PTR(qinx);
2541
2542         /* check for tx descriptor status */
2543         process_tx_completions(pdata->dev, pdata, qinx);
2544         rx_queue->lro_flush_needed = 0;
2545
2546         received = pdata->process_rx_completions(pdata, budget, qinx);
2547
2548         pdata->xstats.rx_pkt_n += received;
2549         pdata->xstats.q_rx_pkt_n[qinx] += received;
2550
2551         if (rx_queue->lro_flush_needed)
2552                 lro_flush_all(&rx_queue->lro_mgr);
2553
2554         pr_debug("<--%s():\n", __func__);
2555
2556         return received;
2557 }
2558
2559 static void do_txrx_post_processing(struct eqos_prv_data *pdata,
2560                                     struct napi_struct *napi,
2561                                     int received, int budget)
2562 {
2563         struct eqos_rx_queue *rx_queue;
2564         int qinx = 0;
2565         struct hw_if_struct *hw_if = &(pdata->hw_if);
2566
2567         pr_debug("-->%s():\n", __func__);
2568
2569         /* If we processed all pkts, we are done;
2570          * tell the kernel & re-enable interrupt
2571          */
2572         if (received < budget) {
2573                 rx_queue = container_of(napi, struct eqos_rx_queue, napi);
2574                 qinx = rx_queue->chan_num;
2575                 hw_if = &pdata->hw_if;
2576                 if (pdata->dev->features & NETIF_F_GRO) {
2577                         /* to turn off polling */
2578                         napi_complete(napi);
2579
2580                         /* Enable RX interrupt */
2581                         hw_if->enable_chan_interrupts(qinx, pdata);
2582                 } else {
2583
2584                         spin_lock(&pdata->lock);
2585                         __napi_complete(napi);
2586
2587                         /* Enable RX interrupt */
2588                         hw_if->enable_chan_interrupts(qinx, pdata);
2589
2590                         spin_unlock(&pdata->lock);
2591                 }
2592         }
2593         pr_debug("<--%s():\n", __func__);
2594 }
2595
2596
2597 int eqos_napi_mq(struct napi_struct *napi, int budget)
2598 {
2599         struct eqos_rx_queue *rx_queue =
2600             container_of(napi, struct eqos_rx_queue, napi);
2601         struct eqos_prv_data *pdata = rx_queue->pdata;
2602
2603         int qinx = rx_queue->chan_num;
2604         int received = 0;
2605
2606         pr_debug("-->%s(): budget = %d\n", __func__, budget);
2607
2608         pdata->xstats.napi_poll_n++;
2609         received = handle_txrx_completions(pdata, qinx);
2610
2611         do_txrx_post_processing(pdata, napi, received,
2612                                 pdata->dt_cfg.chan_napi_quota[qinx]);
2613
2614         pr_debug("<--%s()\n", __func__);
2615
2616         return received;
2617 }
2618
2619 /*!
2620 * \brief API to return the device/interface status.
2621 *
2622 * \details The get_stats function is called whenever an application needs to
2623 * get statistics for the interface. For example, this happend when ifconfig
2624 * or netstat -i is run.
2625 *
2626 * \param[in] dev - pointer to net_device structure.
2627 *
2628 * \return net_device_stats structure
2629 *
2630 * \retval net_device_stats - returns pointer to net_device_stats structure.
2631 */
2632
2633 static struct net_device_stats *eqos_get_stats(struct net_device *dev)
2634 {
2635
2636         return &dev->stats;
2637 }
2638
2639
2640 /*!
2641  * \brief User defined parameter setting API
2642  *
2643  * \details This function is invoked by kernel to update the device
2644  * configuration to new features. This function supports enabling and
2645  * disabling of TX and RX csum features.
2646  *
2647  * \param[in] dev â€“ pointer to net device structure.
2648  * \param[in] features â€“ device feature to be enabled/disabled.
2649  *
2650  * \return int
2651  *
2652  * \retval 0
2653  */
2654
2655 static int eqos_set_features(struct net_device *dev, netdev_features_t features)
2656 {
2657         struct eqos_prv_data *pdata = netdev_priv(dev);
2658         struct hw_if_struct *hw_if = &(pdata->hw_if);
2659         UINT dev_rxcsum_enable;
2660 #ifdef EQOS_ENABLE_VLAN_TAG
2661         UINT dev_rxvlan_enable, dev_txvlan_enable;
2662 #endif
2663         pr_debug("-->eqos_set_features\n");
2664
2665         if (pdata->hw_feat.rx_coe_sel) {
2666                 dev_rxcsum_enable = !!(pdata->dev_state & NETIF_F_RXCSUM);
2667
2668                 if (((features & NETIF_F_RXCSUM) == NETIF_F_RXCSUM)
2669                     && !dev_rxcsum_enable) {
2670                         hw_if->enable_rx_csum();
2671                         pdata->dev_state |= NETIF_F_RXCSUM;
2672                         pr_err("State change - rxcsum enable\n");
2673                 } else if (((features & NETIF_F_RXCSUM) == 0)
2674                            && dev_rxcsum_enable) {
2675                         hw_if->disable_rx_csum();
2676                         pdata->dev_state &= ~NETIF_F_RXCSUM;
2677                         pr_err("State change - rxcsum disable\n");
2678                 }
2679         }
2680 #ifdef EQOS_ENABLE_VLAN_TAG
2681         dev_rxvlan_enable = !!(pdata->dev_state & NETIF_F_HW_VLAN_CTAG_RX);
2682         if (((features & NETIF_F_HW_VLAN_CTAG_RX) == NETIF_F_HW_VLAN_CTAG_RX)
2683             && !dev_rxvlan_enable) {
2684                 pdata->dev_state |= NETIF_F_HW_VLAN_CTAG_RX;
2685                 hw_if->
2686                     config_rx_outer_vlan_stripping(EQOS_RX_VLAN_STRIP_ALWAYS);
2687                 pr_err("State change - rxvlan enable\n");
2688         } else if (((features & NETIF_F_HW_VLAN_CTAG_RX) == 0) &&
2689                    dev_rxvlan_enable) {
2690                 pdata->dev_state &= ~NETIF_F_HW_VLAN_CTAG_RX;
2691                 hw_if->config_rx_outer_vlan_stripping(EQOS_RX_NO_VLAN_STRIP);
2692                 pr_err("State change - rxvlan disable\n");
2693         }
2694
2695         dev_txvlan_enable = !!(pdata->dev_state & NETIF_F_HW_VLAN_CTAG_TX);
2696         if (((features & NETIF_F_HW_VLAN_CTAG_TX) == NETIF_F_HW_VLAN_CTAG_TX)
2697             && !dev_txvlan_enable) {
2698                 pdata->dev_state |= NETIF_F_HW_VLAN_CTAG_TX;
2699                 pr_err("State change - txvlan enable\n");
2700         } else if (((features & NETIF_F_HW_VLAN_CTAG_TX) == 0) &&
2701                    dev_txvlan_enable) {
2702                 pdata->dev_state &= ~NETIF_F_HW_VLAN_CTAG_TX;
2703                 pr_err("State change - txvlan disable\n");
2704         }
2705 #endif                          /* EQOS_ENABLE_VLAN_TAG */
2706
2707         pr_debug("<--eqos_set_features\n");
2708
2709         return 0;
2710 }
2711
2712 /*!
2713  * \details This function is invoked by ioctl function when user issues
2714  * an ioctl command to enable/disable L3/L4 filtering.
2715  *
2716  * \param[in] dev â€“ pointer to net device structure.
2717  * \param[in] flags â€“ flag to indicate whether L3/L4 filtering to be
2718  *                  enabled/disabled.
2719  *
2720  * \return integer
2721  *
2722  * \retval zero on success and -ve number on failure.
2723  */
2724 static int eqos_config_l3_l4_filtering(struct net_device *dev,
2725                                        unsigned int flags)
2726 {
2727         struct eqos_prv_data *pdata = netdev_priv(dev);
2728         struct hw_if_struct *hw_if = &(pdata->hw_if);
2729         int ret = 0;
2730
2731         DBGPR_FILTER("-->eqos_config_l3_l4_filtering\n");
2732
2733         if (flags && pdata->l3_l4_filter) {
2734                 pr_err("L3/L4 filtering is already enabled\n");
2735                 return -EINVAL;
2736         }
2737
2738         if (!flags && !pdata->l3_l4_filter) {
2739                 pr_err("L3/L4 filtering is already disabled\n");
2740                 return -EINVAL;
2741         }
2742
2743         pdata->l3_l4_filter = !!flags;
2744         hw_if->config_l3_l4_filter_enable(pdata->l3_l4_filter);
2745
2746         DBGPR_FILTER("Succesfully %s L3/L4 filtering\n",
2747                      (flags ? "ENABLED" : "DISABLED"));
2748
2749         DBGPR_FILTER("<--eqos_config_l3_l4_filtering\n");
2750
2751         return ret;
2752 }
2753
2754 /*!
2755  * \details This function is invoked by ioctl function when user issues an
2756  * ioctl command to configure L3(IPv4) filtering. This function does following,
2757  * - enable/disable IPv4 filtering.
2758  * - select source/destination address matching.
2759  * - select perfect/inverse matching.
2760  * - Update the IPv4 address into MAC register.
2761  *
2762  * \param[in] dev â€“ pointer to net device structure.
2763  * \param[in] req â€“ pointer to IOCTL specific structure.
2764  *
2765  * \return integer
2766  *
2767  * \retval zero on success and -ve number on failure.
2768  */
2769 static int eqos_config_ip4_filters(struct net_device *dev,
2770                                    struct ifr_data_struct *req)
2771 {
2772         struct eqos_prv_data *pdata = netdev_priv(dev);
2773         struct hw_if_struct *hw_if = &(pdata->hw_if);
2774         struct eqos_l3_l4_filter *u_l3_filter =
2775             (struct eqos_l3_l4_filter *)req->ptr;
2776         struct eqos_l3_l4_filter l_l3_filter;
2777         int ret = 0;
2778
2779         DBGPR_FILTER("-->eqos_config_ip4_filters\n");
2780
2781         if (pdata->hw_feat.l3l4_filter_num == 0)
2782                 return EQOS_NO_HW_SUPPORT;
2783
2784         if (copy_from_user(&l_l3_filter, u_l3_filter,
2785                            sizeof(struct eqos_l3_l4_filter)))
2786                 return -EFAULT;
2787
2788         if ((l_l3_filter.filter_no + 1) > pdata->hw_feat.l3l4_filter_num) {
2789                 pr_err("%d filter is not supported in the HW\n",
2790                        l_l3_filter.filter_no);
2791                 return EQOS_NO_HW_SUPPORT;
2792         }
2793
2794         if (!pdata->l3_l4_filter) {
2795                 hw_if->config_l3_l4_filter_enable(1);
2796                 pdata->l3_l4_filter = 1;
2797         }
2798
2799         /* configure the L3 filters */
2800         hw_if->config_l3_filters(l_l3_filter.filter_no,
2801                                  l_l3_filter.filter_enb_dis, 0,
2802                                  l_l3_filter.src_dst_addr_match,
2803                                  l_l3_filter.perfect_inverse_match);
2804
2805         if (!l_l3_filter.src_dst_addr_match)
2806                 hw_if->update_ip4_addr0(l_l3_filter.filter_no,
2807                                         l_l3_filter.ip4_addr);
2808         else
2809                 hw_if->update_ip4_addr1(l_l3_filter.filter_no,
2810                                         l_l3_filter.ip4_addr);
2811
2812         DBGPR_FILTER
2813             ("Successfully %s IPv4 %s %s addressing filtering on %d filter\n",
2814              (l_l3_filter.filter_enb_dis ? "ENABLED" : "DISABLED"),
2815              (l_l3_filter.perfect_inverse_match ? "INVERSE" : "PERFECT"),
2816              (l_l3_filter.src_dst_addr_match ? "DESTINATION" : "SOURCE"),
2817              l_l3_filter.filter_no);
2818
2819         DBGPR_FILTER("<--eqos_config_ip4_filters\n");
2820
2821         return ret;
2822 }
2823
2824 /*!
2825  * \details This function is invoked by ioctl function when user issues an
2826  * ioctl command to configure L3(IPv6) filtering. This function does following,
2827  * - enable/disable IPv6 filtering.
2828  * - select source/destination address matching.
2829  * - select perfect/inverse matching.
2830  * - Update the IPv6 address into MAC register.
2831  *
2832  * \param[in] dev â€“ pointer to net device structure.
2833  * \param[in] req â€“ pointer to IOCTL specific structure.
2834  *
2835  * \return integer
2836  *
2837  * \retval zero on success and -ve number on failure.
2838  */
2839 static int eqos_config_ip6_filters(struct net_device *dev,
2840                                    struct ifr_data_struct *req)
2841 {
2842         struct eqos_prv_data *pdata = netdev_priv(dev);
2843         struct hw_if_struct *hw_if = &(pdata->hw_if);
2844         struct eqos_l3_l4_filter *u_l3_filter =
2845             (struct eqos_l3_l4_filter *)req->ptr;
2846         struct eqos_l3_l4_filter l_l3_filter;
2847         int ret = 0;
2848
2849         DBGPR_FILTER("-->eqos_config_ip6_filters\n");
2850
2851         if (pdata->hw_feat.l3l4_filter_num == 0)
2852                 return EQOS_NO_HW_SUPPORT;
2853
2854         if (copy_from_user(&l_l3_filter, u_l3_filter,
2855                            sizeof(struct eqos_l3_l4_filter)))
2856                 return -EFAULT;
2857
2858         if ((l_l3_filter.filter_no + 1) > pdata->hw_feat.l3l4_filter_num) {
2859                 pr_err("%d filter is not supported in the HW\n",
2860                        l_l3_filter.filter_no);
2861                 return EQOS_NO_HW_SUPPORT;
2862         }
2863
2864         if (!pdata->l3_l4_filter) {
2865                 hw_if->config_l3_l4_filter_enable(1);
2866                 pdata->l3_l4_filter = 1;
2867         }
2868
2869         /* configure the L3 filters */
2870         hw_if->config_l3_filters(l_l3_filter.filter_no,
2871                                  l_l3_filter.filter_enb_dis, 1,
2872                                  l_l3_filter.src_dst_addr_match,
2873                                  l_l3_filter.perfect_inverse_match);
2874
2875         hw_if->update_ip6_addr(l_l3_filter.filter_no, l_l3_filter.ip6_addr);
2876
2877         DBGPR_FILTER
2878             ("Successfully %s IPv6 %s %s addressing filtering on %d filter\n",
2879              (l_l3_filter.filter_enb_dis ? "ENABLED" : "DISABLED"),
2880              (l_l3_filter.perfect_inverse_match ? "INVERSE" : "PERFECT"),
2881              (l_l3_filter.src_dst_addr_match ? "DESTINATION" : "SOURCE"),
2882              l_l3_filter.filter_no);
2883
2884         DBGPR_FILTER("<--eqos_config_ip6_filters\n");
2885
2886         return ret;
2887 }
2888
2889 /*!
2890  * \details This function is invoked by ioctl function when user issues an
2891  * ioctl command to configure L4(TCP/UDP) filtering. This function does following,
2892  * - enable/disable L4 filtering.
2893  * - select TCP/UDP filtering.
2894  * - select source/destination port matching.
2895  * - select perfect/inverse matching.
2896  * - Update the port number into MAC register.
2897  *
2898  * \param[in] dev â€“ pointer to net device structure.
2899  * \param[in] req â€“ pointer to IOCTL specific structure.
2900  * \param[in] tcp_udp â€“ flag to indicate TCP/UDP filtering.
2901  *
2902  * \return integer
2903  *
2904  * \retval zero on success and -ve number on failure.
2905  */
2906 static int eqos_config_tcp_udp_filters(struct net_device *dev,
2907                                        struct ifr_data_struct *req, int tcp_udp)
2908 {
2909         struct eqos_prv_data *pdata = netdev_priv(dev);
2910         struct hw_if_struct *hw_if = &(pdata->hw_if);
2911         struct eqos_l3_l4_filter *u_l4_filter =
2912             (struct eqos_l3_l4_filter *)req->ptr;
2913         struct eqos_l3_l4_filter l_l4_filter;
2914         int ret = 0;
2915
2916         DBGPR_FILTER("-->eqos_config_tcp_udp_filters\n");
2917
2918         if (pdata->hw_feat.l3l4_filter_num == 0)
2919                 return EQOS_NO_HW_SUPPORT;
2920
2921         if (copy_from_user(&l_l4_filter, u_l4_filter,
2922                            sizeof(struct eqos_l3_l4_filter)))
2923                 return -EFAULT;
2924
2925         if ((l_l4_filter.filter_no + 1) > pdata->hw_feat.l3l4_filter_num) {
2926                 pr_err("%d filter is not supported in the HW\n",
2927                        l_l4_filter.filter_no);
2928                 return EQOS_NO_HW_SUPPORT;
2929         }
2930
2931         if (!pdata->l3_l4_filter) {
2932                 hw_if->config_l3_l4_filter_enable(1);
2933                 pdata->l3_l4_filter = 1;
2934         }
2935
2936         /* configure the L4 filters */
2937         hw_if->config_l4_filters(l_l4_filter.filter_no,
2938                                  l_l4_filter.filter_enb_dis,
2939                                  tcp_udp,
2940                                  l_l4_filter.src_dst_addr_match,
2941                                  l_l4_filter.perfect_inverse_match);
2942
2943         if (l_l4_filter.src_dst_addr_match)
2944                 hw_if->update_l4_da_port_no(l_l4_filter.filter_no,
2945                                             l_l4_filter.port_no);
2946         else
2947                 hw_if->update_l4_sa_port_no(l_l4_filter.filter_no,
2948                                             l_l4_filter.port_no);
2949
2950         DBGPR_FILTER
2951             ("Successfully %s %s %s %s Port number filtering on %d filter\n",
2952              (l_l4_filter.filter_enb_dis ? "ENABLED" : "DISABLED"),
2953              (tcp_udp ? "UDP" : "TCP"),
2954              (l_l4_filter.perfect_inverse_match ? "INVERSE" : "PERFECT"),
2955              (l_l4_filter.src_dst_addr_match ? "DESTINATION" : "SOURCE"),
2956              l_l4_filter.filter_no);
2957
2958         DBGPR_FILTER("<--eqos_config_tcp_udp_filters\n");
2959
2960         return ret;
2961 }
2962
2963 /*!
2964  * \details This function is invoked by ioctl function when user issues an
2965  * ioctl command to configure VALN filtering. This function does following,
2966  * - enable/disable VLAN filtering.
2967  * - select perfect/hash filtering.
2968  *
2969  * \param[in] dev â€“ pointer to net device structure.
2970  * \param[in] req â€“ pointer to IOCTL specific structure.
2971  *
2972  * \return integer
2973  *
2974  * \retval zero on success and -ve number on failure.
2975  */
2976 static int eqos_config_vlan_filter(struct net_device *dev,
2977                                    struct ifr_data_struct *req)
2978 {
2979         struct eqos_prv_data *pdata = netdev_priv(dev);
2980         struct hw_if_struct *hw_if = &(pdata->hw_if);
2981         struct eqos_vlan_filter *u_vlan_filter =
2982             (struct eqos_vlan_filter *)req->ptr;
2983         struct eqos_vlan_filter l_vlan_filter;
2984         int ret = 0;
2985
2986         DBGPR_FILTER("-->eqos_config_vlan_filter\n");
2987
2988         if (copy_from_user(&l_vlan_filter, u_vlan_filter,
2989                            sizeof(struct eqos_vlan_filter)))
2990                 return -EFAULT;
2991
2992         if ((l_vlan_filter.perfect_hash) && (pdata->hw_feat.vlan_hash_en == 0)) {
2993                 pr_err("VLAN HASH filtering is not supported\n");
2994                 return EQOS_NO_HW_SUPPORT;
2995         }
2996
2997         /* configure the vlan filter */
2998         hw_if->config_vlan_filtering(l_vlan_filter.filter_enb_dis,
2999                                      l_vlan_filter.perfect_hash,
3000                                      l_vlan_filter.perfect_inverse_match);
3001         pdata->vlan_hash_filtering = l_vlan_filter.perfect_hash;
3002
3003         DBGPR_FILTER("Successfully %s VLAN %s filtering and %s matching\n",
3004                      (l_vlan_filter.filter_enb_dis ? "ENABLED" : "DISABLED"),
3005                      (l_vlan_filter.perfect_hash ? "HASH" : "PERFECT"),
3006                      (l_vlan_filter.
3007                       perfect_inverse_match ? "INVERSE" : "PERFECT"));
3008
3009         DBGPR_FILTER("<--eqos_config_vlan_filter\n");
3010
3011         return ret;
3012 }
3013
3014 /*!
3015  * \details This function is invoked by ioctl function when user issues an
3016  * ioctl command to enable/disable ARP offloading feature.
3017  *
3018  * \param[in] dev â€“ pointer to net device structure.
3019  * \param[in] req â€“ pointer to IOCTL specific structure.
3020  *
3021  * \return integer
3022  *
3023  * \retval zero on success and -ve number on failure.
3024  */
3025 static int eqos_config_arp_offload(struct net_device *dev,
3026                                    struct ifr_data_struct *req)
3027 {
3028         struct eqos_prv_data *pdata = netdev_priv(dev);
3029         struct hw_if_struct *hw_if = &(pdata->hw_if);
3030         struct eqos_arp_offload *u_arp_offload =
3031             (struct eqos_arp_offload *)req->ptr;
3032         struct eqos_arp_offload l_arp_offload;
3033         int ret = 0;
3034
3035         pr_err("-->eqos_config_arp_offload\n");
3036
3037         if (pdata->hw_feat.arp_offld_en == 0)
3038                 return EQOS_NO_HW_SUPPORT;
3039
3040         if (copy_from_user(&l_arp_offload, u_arp_offload,
3041                            sizeof(struct eqos_arp_offload)))
3042                 return -EFAULT;
3043
3044         /* configure the L3 filters */
3045         hw_if->config_arp_offload(req->flags);
3046         hw_if->update_arp_offload_ip_addr(l_arp_offload.ip_addr);
3047         pdata->arp_offload = req->flags;
3048
3049         pr_err("Successfully %s arp Offload\n",
3050                (req->flags ? "ENABLED" : "DISABLED"));
3051
3052         pr_err("<--eqos_config_arp_offload\n");
3053
3054         return ret;
3055 }
3056
3057 /*!
3058  * \details This function is invoked by ioctl function when user issues an
3059  * ioctl command to configure L2 destination addressing filtering mode. This
3060  * function dose following,
3061  * - selects perfect/hash filtering.
3062  * - selects perfect/inverse matching.
3063  *
3064  * \param[in] dev â€“ pointer to net device structure.
3065  * \param[in] req â€“ pointer to IOCTL specific structure.
3066  *
3067  * \return integer
3068  *
3069  * \retval zero on success and -ve number on failure.
3070  */
3071 static int eqos_confing_l2_da_filter(struct net_device *dev,
3072                                      struct ifr_data_struct *req)
3073 {
3074         struct eqos_prv_data *pdata = netdev_priv(dev);
3075         struct hw_if_struct *hw_if = &(pdata->hw_if);
3076         struct eqos_l2_da_filter *u_l2_da_filter =
3077             (struct eqos_l2_da_filter *)req->ptr;
3078         struct eqos_l2_da_filter l_l2_da_filter;
3079         int ret = 0;
3080
3081         DBGPR_FILTER("-->eqos_confing_l2_da_filter\n");
3082
3083         if (copy_from_user(&l_l2_da_filter, u_l2_da_filter,
3084                            sizeof(struct eqos_l2_da_filter)))
3085                 return -EFAULT;
3086
3087         if (l_l2_da_filter.perfect_hash) {
3088                 if (pdata->hw_feat.hash_tbl_sz > 0)
3089                         pdata->l2_filtering_mode = 1;
3090                 else
3091                         ret = EQOS_NO_HW_SUPPORT;
3092         } else {
3093                 if (pdata->max_addr_reg_cnt > 1)
3094                         pdata->l2_filtering_mode = 0;
3095                 else
3096                         ret = EQOS_NO_HW_SUPPORT;
3097         }
3098
3099         /* configure L2 DA perfect/inverse_matching */
3100         hw_if->config_l2_da_perfect_inverse_match(l_l2_da_filter.
3101                                                   perfect_inverse_match);
3102
3103         DBGPR_FILTER
3104             ("Successfully selected L2 %s filtering and %s DA matching\n",
3105              (l_l2_da_filter.perfect_hash ? "HASH" : "PERFECT"),
3106              (l_l2_da_filter.perfect_inverse_match ? "INVERSE" : "PERFECT"));
3107
3108         DBGPR_FILTER("<--eqos_confing_l2_da_filter\n");
3109
3110         return ret;
3111 }
3112
3113 /*!
3114  * \details This function is invoked by ioctl function when user issues
3115  * an ioctl command to enable/disable mac loopback mode.
3116  *
3117  * \param[in] dev â€“ pointer to net device structure.
3118  * \param[in] flags â€“ flag to indicate whether mac loopback mode to be
3119  *                  enabled/disabled.
3120  *
3121  * \return integer
3122  *
3123  * \retval zero on success and -ve number on failure.
3124  */
3125 int eqos_config_mac_loopback_mode(struct net_device *dev,
3126                                   unsigned int flags)
3127 {
3128         struct eqos_prv_data *pdata = netdev_priv(dev);
3129         struct hw_if_struct *hw_if = &(pdata->hw_if);
3130         int ret = 0;
3131
3132         pr_debug("-->eqos_config_mac_loopback_mode\n");
3133
3134         if (flags && pdata->mac_loopback_mode) {
3135                 pr_err("MAC loopback mode is already enabled\n");
3136                 return -EINVAL;
3137         }
3138         if (!flags && !pdata->mac_loopback_mode) {
3139                 pr_err("MAC loopback mode is already disabled\n");
3140                 return -EINVAL;
3141         }
3142         pdata->mac_loopback_mode = !!flags;
3143         hw_if->config_mac_loopback_mode(flags);
3144
3145         pr_err("Succesfully %s MAC loopback mode\n",
3146                (flags ? "enabled" : "disabled"));
3147
3148         pr_debug("<--eqos_config_mac_loopback_mode\n");
3149
3150         return ret;
3151 }
3152
3153 static VOID eqos_config_timer_registers(struct eqos_prv_data *pdata)
3154 {
3155         struct timespec now;
3156         struct hw_if_struct *hw_if = &(pdata->hw_if);
3157         u64 temp;
3158
3159         pr_debug("-->eqos_config_timer_registers\n");
3160
3161         /* program Sub Second Increment Reg */
3162         hw_if->config_sub_second_increment(EQOS_SYSCLOCK);
3163
3164         /* formula is :
3165          * addend = 2^32/freq_div_ratio;
3166          *
3167          * where, freq_div_ratio = EQOS_SYSCLOCK/50MHz
3168          *
3169          * hence, addend = ((2^32) * 50MHz)/EQOS_SYSCLOCK;
3170          *
3171          * NOTE: EQOS_SYSCLOCK should be >= 50MHz to
3172          *       achive 20ns accuracy.
3173          *
3174          * 2^x * y == (y << x), hence
3175          * 2^32 * 6250000 ==> (6250000 << 32)
3176          * */
3177         temp = (u64) (62500000ULL << 32);
3178         pdata->default_addend = div_u64(temp, 125000000);
3179
3180         hw_if->config_addend(pdata->default_addend);
3181
3182         /* initialize system time */
3183         getnstimeofday(&now);
3184         hw_if->init_systime(now.tv_sec, now.tv_nsec);
3185
3186         pr_debug("-->eqos_config_timer_registers\n");
3187 }
3188
3189 /*!
3190  * \details This function is invoked by ioctl function when user issues
3191  * an ioctl command to configure PTP offloading feature.
3192  *
3193  * \param[in] pdata - pointer to private data structure.
3194  * \param[in] flags â€“ Each bit in this variable carry some information related
3195  *                    double vlan processing.
3196  *
3197  * \return integer
3198  *
3199  * \retval zero on success and -ve number on failure.
3200  */
3201 static int eqos_config_ptpoffload(struct eqos_prv_data *pdata,
3202                                   struct eqos_config_ptpoffloading *u_conf_ptp)
3203 {
3204         UINT pto_cntrl;
3205         UINT mac_tcr;
3206         struct eqos_config_ptpoffloading l_conf_ptp;
3207         struct hw_if_struct *hw_if = &(pdata->hw_if);
3208
3209         if (copy_from_user(&l_conf_ptp, u_conf_ptp,
3210                            sizeof(struct eqos_config_ptpoffloading))) {
3211                 pr_err("Failed to fetch Double vlan Struct info from user\n");
3212                 return EQOS_CONFIG_FAIL;
3213         }
3214
3215         pr_err("-->eqos_config_ptpoffload - %d\n", l_conf_ptp.mode);
3216
3217         pto_cntrl = MAC_PTOCR_PTOEN;    /* enable ptp offloading */
3218         mac_tcr = MAC_TCR_TSENA | MAC_TCR_TSIPENA | MAC_TCR_TSVER2ENA
3219             | MAC_TCR_TSCFUPDT | MAC_TCR_TSCTRLSSR;
3220         if (l_conf_ptp.mode == EQOS_PTP_ORDINARY_SLAVE) {
3221
3222                 mac_tcr |= MAC_TCR_TSEVENTENA;
3223                 pdata->ptp_offloading_mode = EQOS_PTP_ORDINARY_SLAVE;
3224
3225         } else if (l_conf_ptp.mode == EQOS_PTP_TRASPARENT_SLAVE) {
3226
3227                 pto_cntrl |= MAC_PTOCR_APDREQEN;
3228                 mac_tcr |= MAC_TCR_TSEVENTENA;
3229                 mac_tcr |= MAC_TCR_SNAPTYPSEL_1;
3230                 pdata->ptp_offloading_mode = EQOS_PTP_TRASPARENT_SLAVE;
3231
3232         } else if (l_conf_ptp.mode == EQOS_PTP_ORDINARY_MASTER) {
3233
3234                 pto_cntrl |= MAC_PTOCR_ASYNCEN;
3235                 mac_tcr |= MAC_TCR_TSEVENTENA;
3236                 mac_tcr |= MAC_TCR_TSMASTERENA;
3237                 pdata->ptp_offloading_mode = EQOS_PTP_ORDINARY_MASTER;
3238
3239         } else if (l_conf_ptp.mode == EQOS_PTP_TRASPARENT_MASTER) {
3240
3241                 pto_cntrl |= MAC_PTOCR_ASYNCEN | MAC_PTOCR_APDREQEN;
3242                 mac_tcr |= MAC_TCR_SNAPTYPSEL_1;
3243                 mac_tcr |= MAC_TCR_TSEVENTENA;
3244                 mac_tcr |= MAC_TCR_TSMASTERENA;
3245                 pdata->ptp_offloading_mode = EQOS_PTP_TRASPARENT_MASTER;
3246
3247         } else if (l_conf_ptp.mode == EQOS_PTP_PEER_TO_PEER_TRANSPARENT) {
3248
3249                 pto_cntrl |= MAC_PTOCR_APDREQEN;
3250                 mac_tcr |= MAC_TCR_SNAPTYPSEL_3;
3251                 pdata->ptp_offloading_mode = EQOS_PTP_PEER_TO_PEER_TRANSPARENT;
3252         }
3253
3254         pdata->ptp_offload = 1;
3255         if (l_conf_ptp.en_dis == EQOS_PTP_OFFLOADING_DISABLE) {
3256                 pto_cntrl = 0;
3257                 mac_tcr = 0;
3258                 pdata->ptp_offload = 0;
3259         }
3260
3261         pto_cntrl |= (l_conf_ptp.domain_num << 8);
3262         hw_if->config_hw_time_stamping(mac_tcr);
3263         eqos_config_timer_registers(pdata);
3264         hw_if->config_ptpoffload_engine(pto_cntrl, l_conf_ptp.mc_uc);
3265
3266         pr_err("<--eqos_config_ptpoffload\n");
3267
3268         return Y_SUCCESS;
3269 }
3270
3271 /*!
3272  * \details This function is invoked by ioctl function when user issues
3273  * an ioctl command to enable/disable pfc.
3274  *
3275  * \param[in] dev â€“ pointer to net device structure.
3276  * \param[in] flags â€“ flag to indicate whether pfc to be enabled/disabled.
3277  *
3278  * \return integer
3279  *
3280  * \retval zero on success and -ve number on failure.
3281  */
3282 static int eqos_config_pfc(struct net_device *dev, unsigned int flags)
3283 {
3284         struct eqos_prv_data *pdata = netdev_priv(dev);
3285         struct hw_if_struct *hw_if = &(pdata->hw_if);
3286         int ret = 0;
3287
3288         pr_debug("-->eqos_config_pfc\n");
3289
3290         if (!pdata->hw_feat.dcb_en) {
3291                 pr_err("PFC is not supported\n");
3292                 return EQOS_NO_HW_SUPPORT;
3293         }
3294
3295         hw_if->config_pfc(flags);
3296
3297         pr_err("Succesfully %s PFC(Priority Based Flow Control)\n",
3298                (flags ? "enabled" : "disabled"));
3299
3300         pr_debug("<--eqos_config_pfc\n");
3301
3302         return ret;
3303 }
3304
3305 static int eqos_handle_prv_ts_ioctl(struct eqos_prv_data *pdata,
3306                                     struct ifreq *ifr)
3307 {
3308         struct hw_if_struct *hw_if = &pdata->hw_if;
3309         struct ifr_data_timestamp_struct req;
3310         unsigned long flags;
3311         u64 ns;
3312         u32 reminder;
3313         int ret = 0;
3314
3315         pr_debug("-->eqos_handle_prv_ts_ioctl\n");
3316
3317         if (copy_from_user(&req, ifr->ifr_data, sizeof(req)))
3318                 return -EFAULT;
3319
3320         raw_spin_lock_irqsave(&eqos_ts_lock, flags);
3321
3322         switch (req.clockid) {
3323         case CLOCK_REALTIME:
3324                 ktime_get_real_ts(&req.kernel_ts);
3325                 break;
3326
3327         case CLOCK_MONOTONIC:
3328                 ktime_get_ts(&req.kernel_ts);
3329                 break;
3330
3331         default:
3332                 ret = -EINVAL;
3333                 pr_err("Unsupported clockid\n");
3334         }
3335
3336         raw_spin_lock(&pdata->ptp_lock);
3337
3338         ns = hw_if->get_systime();
3339
3340         raw_spin_unlock(&pdata->ptp_lock);
3341
3342         raw_spin_unlock_irqrestore(&eqos_ts_lock, flags);
3343
3344         req.hw_ptp_ts.tv_sec = div_u64_rem(ns, 1000000000ULL, &reminder);
3345         req.hw_ptp_ts.tv_nsec = reminder;
3346
3347         pr_debug("<--eqos_ptp_get_time: tv_sec = %ld, tv_nsec = %ld\n",
3348                  req.hw_ptp_ts.tv_sec, req.hw_ptp_ts.tv_nsec);
3349
3350         if (copy_to_user(ifr->ifr_data, &req, sizeof(req)))
3351                 return -EFAULT;
3352
3353         pr_debug("<--eqos_handle_prv_ts_ioctl\n");
3354
3355         return ret;
3356 }
3357
3358 /*!
3359  * \brief Driver IOCTL routine
3360  *
3361  * \details This function is invoked by main ioctl function when
3362  * users request to configure various device features like,
3363  * PMT module, TX and RX PBL, TX and RX FIFO threshold level,
3364  * TX and RX OSF mode, SA insert/replacement, L2/L3/L4 and
3365  * VLAN filtering, AVB/DCB algorithm etc.
3366  *
3367  * \param[in] pdata â€“ pointer to private data structure.
3368  * \param[in] req â€“ pointer to ioctl structure.
3369  *
3370  * \return int
3371  *
3372  * \retval 0 - success
3373  * \retval negative - failure
3374  */
3375
3376 static int eqos_handle_prv_ioctl(struct eqos_prv_data *pdata,
3377                                  struct ifr_data_struct *req)
3378 {
3379         unsigned int qinx = req->qinx;
3380         struct tx_ring *ptx_ring =
3381             GET_TX_WRAPPER_DESC(qinx);
3382         struct rx_ring *prx_ring =
3383             GET_RX_WRAPPER_DESC(qinx);
3384         struct hw_if_struct *hw_if = &(pdata->hw_if);
3385         struct net_device *dev = pdata->dev;
3386         int ret = 0;
3387
3388         pr_debug("-->eqos_handle_prv_ioctl\n");
3389
3390         if (qinx > EQOS_QUEUE_CNT) {
3391                 pr_err("Queue number %d is invalid\n"
3392                        "Hardware has only %d Tx/Rx Queues\n",
3393                        qinx, EQOS_QUEUE_CNT);
3394                 ret = EQOS_NO_HW_SUPPORT;
3395                 return ret;
3396         }
3397
3398         switch (req->cmd) {
3399         case EQOS_POWERUP_MAGIC_CMD:
3400                 if (pdata->hw_feat.mgk_sel) {
3401                         ret = eqos_powerup(dev, EQOS_IOCTL_CONTEXT);
3402                         if (ret == 0)
3403                                 ret = EQOS_CONFIG_SUCCESS;
3404                         else
3405                                 ret = EQOS_CONFIG_FAIL;
3406                 } else {
3407                         ret = EQOS_NO_HW_SUPPORT;
3408                 }
3409                 break;
3410
3411         case EQOS_POWERDOWN_MAGIC_CMD:
3412                 if (pdata->hw_feat.mgk_sel) {
3413                         ret =
3414                             eqos_powerdown(dev,
3415                                            EQOS_MAGIC_WAKEUP,
3416                                            EQOS_IOCTL_CONTEXT);
3417                         if (ret == 0)
3418                                 ret = EQOS_CONFIG_SUCCESS;
3419                         else
3420                                 ret = EQOS_CONFIG_FAIL;
3421                 } else {
3422                         ret = EQOS_NO_HW_SUPPORT;
3423                 }
3424                 break;
3425
3426         case EQOS_POWERUP_REMOTE_WAKEUP_CMD:
3427                 if (pdata->hw_feat.rwk_sel) {
3428                         ret = eqos_powerup(dev, EQOS_IOCTL_CONTEXT);
3429                         if (ret == 0)
3430                                 ret = EQOS_CONFIG_SUCCESS;
3431                         else
3432                                 ret = EQOS_CONFIG_FAIL;
3433                 } else {
3434                         ret = EQOS_NO_HW_SUPPORT;
3435                 }
3436                 break;
3437
3438         case EQOS_POWERDOWN_REMOTE_WAKEUP_CMD:
3439                 if (pdata->hw_feat.rwk_sel) {
3440                         ret = eqos_configure_remotewakeup(dev, req);
3441                         if (ret == 0)
3442                                 ret = EQOS_CONFIG_SUCCESS;
3443                         else
3444                                 ret = EQOS_CONFIG_FAIL;
3445                 } else {
3446                         ret = EQOS_NO_HW_SUPPORT;
3447                 }
3448                 break;
3449
3450         case EQOS_RX_THRESHOLD_CMD:
3451                 prx_ring->rx_threshold_val = req->flags;
3452                 hw_if->config_rx_threshold(qinx,
3453                                            prx_ring->rx_threshold_val);
3454                 pr_err("Configured Rx threshold with %d\n",
3455                        prx_ring->rx_threshold_val);
3456                 break;
3457
3458         case EQOS_TX_THRESHOLD_CMD:
3459                 ptx_ring->tx_threshold_val = req->flags;
3460                 hw_if->config_tx_threshold(qinx,
3461                                            ptx_ring->tx_threshold_val);
3462                 pr_err("Configured Tx threshold with %d\n",
3463                        ptx_ring->tx_threshold_val);
3464                 break;
3465
3466         case EQOS_RSF_CMD:
3467                 prx_ring->rsf_on = req->flags;
3468                 hw_if->config_rsf_mode(qinx, prx_ring->rsf_on);
3469                 pr_err("Receive store and forward mode %s\n",
3470                        (prx_ring->rsf_on) ? "enabled" : "disabled");
3471                 break;
3472
3473         case EQOS_TSF_CMD:
3474                 ptx_ring->tsf_on = req->flags;
3475                 hw_if->config_tsf_mode(qinx, ptx_ring->tsf_on);
3476                 pr_err("Transmit store and forward mode %s\n",
3477                        (ptx_ring->tsf_on) ? "enabled" : "disabled");
3478                 break;
3479
3480         case EQOS_OSF_CMD:
3481                 ptx_ring->osf_on = req->flags;
3482                 hw_if->config_osf_mode(qinx, ptx_ring->osf_on);
3483                 pr_err("Transmit DMA OSF mode is %s\n",
3484                        (ptx_ring->osf_on) ? "enabled" : "disabled");
3485                 break;
3486
3487         case EQOS_INCR_INCRX_CMD:
3488                 pdata->incr_incrx = req->flags;
3489                 hw_if->config_incr_incrx_mode(pdata->incr_incrx);
3490                 pr_err("%s mode is enabled\n",
3491                        (pdata->incr_incrx) ? "INCRX" : "INCR");
3492                 break;
3493
3494         case EQOS_RX_PBL_CMD:
3495                 prx_ring->rx_pbl = req->flags;
3496                 eqos_config_rx_pbl(pdata, prx_ring->rx_pbl, qinx);
3497                 break;
3498
3499         case EQOS_TX_PBL_CMD:
3500                 ptx_ring->tx_pbl = req->flags;
3501                 eqos_config_tx_pbl(pdata, ptx_ring->tx_pbl, qinx);
3502                 break;
3503
3504         case EQOS_PTPOFFLOADING_CMD:
3505                 if (pdata->hw_feat.tsstssel) {
3506                         ret = eqos_config_ptpoffload(pdata, req->ptr);
3507                 } else {
3508                         pr_err("No HW support for PTP\n");
3509                         ret = EQOS_NO_HW_SUPPORT;
3510                 }
3511                 break;
3512
3513         case EQOS_SA0_DESC_CMD:
3514                 if (pdata->hw_feat.sa_vlan_ins) {
3515                         pdata->tx_sa_ctrl_via_desc = req->flags;
3516                         pdata->tx_sa_ctrl_via_reg = EQOS_SA0_NONE;
3517                         if (req->flags == EQOS_SA0_NONE) {
3518                                 memcpy(pdata->mac_addr, pdata->dev->dev_addr,
3519                                        EQOS_MAC_ADDR_LEN);
3520                         } else {
3521                                 memcpy(pdata->mac_addr, mac_addr0,
3522                                        EQOS_MAC_ADDR_LEN);
3523                         }
3524                         hw_if->configure_mac_addr0_reg(pdata->mac_addr);
3525                         hw_if->configure_sa_via_reg(pdata->tx_sa_ctrl_via_reg);
3526                         pr_err
3527                             ("SA will use MAC0 with descriptor for configuration %d\n",
3528                              pdata->tx_sa_ctrl_via_desc);
3529                 } else {
3530                         pr_err
3531                             ("Device doesn't supports SA Insertion/Replacement\n");
3532                         ret = EQOS_NO_HW_SUPPORT;
3533                 }
3534                 break;
3535
3536         case EQOS_SA1_DESC_CMD:
3537                 if (pdata->hw_feat.sa_vlan_ins) {
3538                         pdata->tx_sa_ctrl_via_desc = req->flags;
3539                         pdata->tx_sa_ctrl_via_reg = EQOS_SA1_NONE;
3540                         if (req->flags == EQOS_SA1_NONE) {
3541                                 memcpy(pdata->mac_addr, pdata->dev->dev_addr,
3542                                        EQOS_MAC_ADDR_LEN);
3543                         } else {
3544                                 memcpy(pdata->mac_addr, mac_addr1,
3545                                        EQOS_MAC_ADDR_LEN);
3546                         }
3547                         hw_if->configure_mac_addr1_reg(pdata->mac_addr);
3548                         hw_if->configure_sa_via_reg(pdata->tx_sa_ctrl_via_reg);
3549                         pr_err
3550                             ("SA will use MAC1 with descriptor for configuration %d\n",
3551                              pdata->tx_sa_ctrl_via_desc);
3552                 } else {
3553                         pr_err
3554                             ("Device doesn't supports SA Insertion/Replacement\n");
3555                         ret = EQOS_NO_HW_SUPPORT;
3556                 }
3557                 break;
3558
3559         case EQOS_SA0_REG_CMD:
3560                 if (pdata->hw_feat.sa_vlan_ins) {
3561                         pdata->tx_sa_ctrl_via_reg = req->flags;
3562                         pdata->tx_sa_ctrl_via_desc = EQOS_SA0_NONE;
3563                         if (req->flags == EQOS_SA0_NONE) {
3564                                 memcpy(pdata->mac_addr, pdata->dev->dev_addr,
3565                                        EQOS_MAC_ADDR_LEN);
3566                         } else {
3567                                 memcpy(pdata->mac_addr, mac_addr0,
3568                                        EQOS_MAC_ADDR_LEN);
3569                         }
3570                         hw_if->configure_mac_addr0_reg(pdata->mac_addr);
3571                         hw_if->configure_sa_via_reg(pdata->tx_sa_ctrl_via_reg);
3572                         pr_err
3573                             ("SA will use MAC0 with register for configuration %d\n",
3574                              pdata->tx_sa_ctrl_via_desc);
3575                 } else {
3576                         pr_err
3577                             ("Device doesn't supports SA Insertion/Replacement\n");
3578                         ret = EQOS_NO_HW_SUPPORT;
3579                 }
3580                 break;
3581
3582         case EQOS_SA1_REG_CMD:
3583                 if (pdata->hw_feat.sa_vlan_ins) {
3584                         pdata->tx_sa_ctrl_via_reg = req->flags;
3585                         pdata->tx_sa_ctrl_via_desc = EQOS_SA1_NONE;
3586                         if (req->flags == EQOS_SA1_NONE) {
3587                                 memcpy(pdata->mac_addr, pdata->dev->dev_addr,
3588                                        EQOS_MAC_ADDR_LEN);
3589                         } else {
3590                                 memcpy(pdata->mac_addr, mac_addr1,
3591                                        EQOS_MAC_ADDR_LEN);
3592                         }
3593                         hw_if->configure_mac_addr1_reg(pdata->mac_addr);
3594                         hw_if->configure_sa_via_reg(pdata->tx_sa_ctrl_via_reg);
3595                         pr_err
3596                             ("SA will use MAC1 with register for configuration %d\n",
3597                              pdata->tx_sa_ctrl_via_desc);
3598                 } else {
3599                         pr_err
3600                             ("Device doesn't supports SA Insertion/Replacement\n");
3601                         ret = EQOS_NO_HW_SUPPORT;
3602                 }
3603                 break;
3604
3605         case EQOS_SETUP_CONTEXT_DESCRIPTOR:
3606                 if (pdata->hw_feat.sa_vlan_ins) {
3607                         ptx_ring->context_setup = req->context_setup;
3608                         if (ptx_ring->context_setup == 1) {
3609                                 pr_err("Context descriptor will be transmitted"
3610                                        " with every normal descriptor on %d DMA Channel\n",
3611                                        qinx);
3612                         } else {
3613                                 pr_err("Context descriptor will be setup"
3614                                        " only if VLAN id changes %d\n", qinx);
3615                         }
3616                 } else {
3617                         pr_err("Device doesn't support VLAN operations\n");
3618                         ret = EQOS_NO_HW_SUPPORT;
3619                 }
3620                 break;
3621
3622         case EQOS_GET_RX_QCNT:
3623                 req->qinx = EQOS_RX_QUEUE_CNT;
3624                 break;
3625
3626         case EQOS_GET_TX_QCNT:
3627                 req->qinx = EQOS_TX_QUEUE_CNT;
3628                 break;
3629
3630         case EQOS_GET_CONNECTED_SPEED:
3631                 req->connected_speed = pdata->speed;
3632                 break;
3633
3634         case EQOS_DCB_ALGORITHM:
3635                 eqos_program_dcb_algorithm(pdata, req);
3636                 break;
3637
3638         case EQOS_AVB_ALGORITHM:
3639                 eqos_program_avb_algorithm(pdata, req);
3640                 break;
3641
3642         case EQOS_L3_L4_FILTER_CMD:
3643                 if (pdata->hw_feat.l3l4_filter_num > 0) {
3644                         ret = eqos_config_l3_l4_filtering(dev, req->flags);
3645                         if (ret == 0)
3646                                 ret = EQOS_CONFIG_SUCCESS;
3647                         else
3648                                 ret = EQOS_CONFIG_FAIL;
3649                 } else {
3650                         ret = EQOS_NO_HW_SUPPORT;
3651                 }
3652                 break;
3653         case EQOS_IPV4_FILTERING_CMD:
3654                 ret = eqos_config_ip4_filters(dev, req);
3655                 break;
3656         case EQOS_IPV6_FILTERING_CMD:
3657                 ret = eqos_config_ip6_filters(dev, req);
3658                 break;
3659         case EQOS_UDP_FILTERING_CMD:
3660                 ret = eqos_config_tcp_udp_filters(dev, req, 1);
3661                 break;
3662         case EQOS_TCP_FILTERING_CMD:
3663                 ret = eqos_config_tcp_udp_filters(dev, req, 0);
3664                 break;
3665         case EQOS_VLAN_FILTERING_CMD:
3666                 ret = eqos_config_vlan_filter(dev, req);
3667                 break;
3668         case EQOS_L2_DA_FILTERING_CMD:
3669                 ret = eqos_confing_l2_da_filter(dev, req);
3670                 break;
3671         case EQOS_ARP_OFFLOAD_CMD:
3672                 ret = eqos_config_arp_offload(dev, req);
3673                 break;
3674         case EQOS_AXI_PBL_CMD:
3675                 pdata->axi_pbl = req->flags;
3676                 hw_if->config_axi_pbl_val(pdata->axi_pbl);
3677                 pr_err("AXI PBL value: %d\n", pdata->axi_pbl);
3678                 break;
3679         case EQOS_AXI_WORL_CMD:
3680                 pdata->axi_worl = req->flags;
3681                 hw_if->config_axi_worl_val(pdata->axi_worl);
3682                 pr_err("AXI WORL value: %d\n", pdata->axi_worl);
3683                 break;
3684         case EQOS_AXI_RORL_CMD:
3685                 pdata->axi_rorl = req->flags;
3686                 hw_if->config_axi_rorl_val(pdata->axi_rorl);
3687                 pr_err("AXI RORL value: %d\n", pdata->axi_rorl);
3688                 break;
3689         case EQOS_MAC_LOOPBACK_MODE_CMD:
3690                 ret = eqos_config_mac_loopback_mode(dev, req->flags);
3691                 if (ret == 0)
3692                         ret = EQOS_CONFIG_SUCCESS;
3693                 else
3694                         ret = EQOS_CONFIG_FAIL;
3695                 break;
3696         case EQOS_PFC_CMD:
3697                 ret = eqos_config_pfc(dev, req->flags);
3698                 break;
3699         case EQOS_PHY_LOOPBACK:
3700                 ret = eqos_handle_phy_loopback(pdata, (void *)req);
3701                 break;
3702         case EQOS_MEM_ISO_TEST:
3703                 ret = eqos_handle_mem_iso_ioctl(pdata, (void *)req);
3704                 break;
3705         case EQOS_CSR_ISO_TEST:
3706                 ret = eqos_handle_csr_iso_ioctl(pdata, (void *)req);
3707                 break;
3708         default:
3709                 ret = -EOPNOTSUPP;
3710                 pr_err("Unsupported command call\n");
3711         }
3712
3713         pr_debug("<--eqos_handle_prv_ioctl\n");
3714
3715         return ret;
3716 }
3717
3718 /*!
3719  * \brief control hw timestamping.
3720  *
3721  * \details This function is used to configure the MAC to enable/disable both
3722  * outgoing(Tx) and incoming(Rx) packets time stamping based on user input.
3723  *
3724  * \param[in] pdata â€“ pointer to private data structure.
3725  * \param[in] ifr â€“ pointer to IOCTL specific structure.
3726  *
3727  * \return int
3728  *
3729  * \retval 0 - success
3730  * \retval negative - failure
3731  */
3732
3733 static int eqos_handle_hwtstamp_ioctl(struct eqos_prv_data *pdata,
3734                                       struct ifreq *ifr)
3735 {
3736         struct hw_if_struct *hw_if = &(pdata->hw_if);
3737         struct hwtstamp_config config;
3738         u32 ptp_v2 = 0;
3739         u32 tstamp_all = 0;
3740         u32 ptp_over_ipv4_udp = 0;
3741         u32 ptp_over_ipv6_udp = 0;
3742         u32 ptp_over_ethernet = 0;
3743         u32 snap_type_sel = 0;
3744         u32 ts_master_en = 0;
3745         u32 ts_event_en = 0;
3746         u32 av_8021asm_en = 0;
3747         u32 mac_tcr = 0;
3748         u64 temp = 0;
3749         struct timespec now;
3750
3751         DBGPR_PTP("-->eqos_handle_hwtstamp_ioctl\n");
3752
3753         if (!pdata->hw_feat.tsstssel) {
3754                 pr_err("No hw timestamping is available in this core\n");
3755                 return -EOPNOTSUPP;
3756         }
3757
3758         if (copy_from_user(&config, ifr->ifr_data,
3759                            sizeof(struct hwtstamp_config)))
3760                 return -EFAULT;
3761
3762         DBGPR_PTP("config.flags = %#x, tx_type = %#x, rx_filter = %#x\n",
3763                   config.flags, config.tx_type, config.rx_filter);
3764
3765         /* reserved for future extensions */
3766         if (config.flags)
3767                 return -EINVAL;
3768
3769         switch (config.tx_type) {
3770         case HWTSTAMP_TX_OFF:
3771                 pdata->hwts_tx_en = 0;
3772                 break;
3773         case HWTSTAMP_TX_ON:
3774                 pdata->hwts_tx_en = 1;
3775                 break;
3776         default:
3777                 return -ERANGE;
3778         }
3779
3780         switch (config.rx_filter) {
3781                 /* time stamp no incoming packet at all */
3782         case HWTSTAMP_FILTER_NONE:
3783                 config.rx_filter = HWTSTAMP_FILTER_NONE;
3784                 break;
3785
3786                 /* PTP v1, UDP, any kind of event packet */
3787         case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3788                 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
3789                 /* take time stamp for all event messages */
3790                 snap_type_sel = MAC_TCR_SNAPTYPSEL_1;
3791
3792                 ptp_over_ipv4_udp = MAC_TCR_TSIPV4ENA;
3793                 ptp_over_ipv6_udp = MAC_TCR_TSIPV6ENA;
3794                 break;
3795
3796                 /* PTP v1, UDP, Sync packet */
3797         case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3798                 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC;
3799                 /* take time stamp for SYNC messages only */
3800                 ts_event_en = MAC_TCR_TSEVENTENA;
3801
3802                 ptp_over_ipv4_udp = MAC_TCR_TSIPV4ENA;
3803                 ptp_over_ipv6_udp = MAC_TCR_TSIPV6ENA;
3804                 break;
3805
3806                 /* PTP v1, UDP, Delay_req packet */
3807         case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3808                 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ;
3809                 /* take time stamp for Delay_Req messages only */
3810                 ts_master_en = MAC_TCR_TSMASTERENA;
3811                 ts_event_en = MAC_TCR_TSEVENTENA;
3812
3813                 ptp_over_ipv4_udp = MAC_TCR_TSIPV4ENA;
3814                 ptp_over_ipv6_udp = MAC_TCR_TSIPV6ENA;
3815                 break;
3816
3817                 /* PTP v2, UDP, any kind of event packet */
3818         case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3819                 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
3820                 ptp_v2 = MAC_TCR_TSVER2ENA;
3821                 /* take time stamp for all event messages */
3822                 snap_type_sel = MAC_TCR_SNAPTYPSEL_1;
3823
3824                 ptp_over_ipv4_udp = MAC_TCR_TSIPV4ENA;
3825                 ptp_over_ipv6_udp = MAC_TCR_TSIPV6ENA;
3826                 break;
3827
3828                 /* PTP v2, UDP, Sync packet */
3829         case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3830                 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_SYNC;
3831                 ptp_v2 = MAC_TCR_TSVER2ENA;
3832                 /* take time stamp for SYNC messages only */
3833                 ts_event_en = MAC_TCR_TSEVENTENA;
3834
3835                 ptp_over_ipv4_udp = MAC_TCR_TSIPV4ENA;
3836                 ptp_over_ipv6_udp = MAC_TCR_TSIPV6ENA;
3837                 break;
3838
3839                 /* PTP v2, UDP, Delay_req packet */
3840         case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3841                 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ;
3842                 ptp_v2 = MAC_TCR_TSVER2ENA;
3843                 /* take time stamp for Delay_Req messages only */
3844                 ts_master_en = MAC_TCR_TSMASTERENA;
3845                 ts_event_en = MAC_TCR_TSEVENTENA;
3846
3847                 ptp_over_ipv4_udp = MAC_TCR_TSIPV4ENA;
3848                 ptp_over_ipv6_udp = MAC_TCR_TSIPV6ENA;
3849                 break;
3850
3851                 /* PTP v2/802.AS1, any layer, any kind of event packet */
3852         case HWTSTAMP_FILTER_PTP_V2_EVENT:
3853                 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3854                 ptp_v2 = MAC_TCR_TSVER2ENA;
3855                 /* take time stamp for all event messages */
3856                 snap_type_sel = MAC_TCR_SNAPTYPSEL_1;
3857
3858                 ptp_over_ipv4_udp = MAC_TCR_TSIPV4ENA;
3859                 ptp_over_ipv6_udp = MAC_TCR_TSIPV6ENA;
3860                 ptp_over_ethernet = MAC_TCR_TSIPENA;
3861                 /* for VLAN tagged PTP, AV8021ASMEN bit should not be set */
3862 #ifdef DWC_1588_VLAN_UNTAGGED
3863                 av_8021asm_en = MAC_TCR_AV8021ASMEN;
3864 #endif
3865                 break;
3866
3867                 /* PTP v2/802.AS1, any layer, Sync packet */
3868         case HWTSTAMP_FILTER_PTP_V2_SYNC:
3869                 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC;
3870                 ptp_v2 = MAC_TCR_TSVER2ENA;
3871                 /* take time stamp for SYNC messages only */
3872                 ts_event_en = MAC_TCR_TSEVENTENA;
3873
3874                 ptp_over_ipv4_udp = MAC_TCR_TSIPV4ENA;
3875                 ptp_over_ipv6_udp = MAC_TCR_TSIPV6ENA;
3876                 ptp_over_ethernet = MAC_TCR_TSIPENA;
3877                 av_8021asm_en = MAC_TCR_AV8021ASMEN;
3878                 break;
3879
3880                 /* PTP v2/802.AS1, any layer, Delay_req packet */
3881         case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3882                 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ;
3883                 ptp_v2 = MAC_TCR_TSVER2ENA;
3884                 /* take time stamp for Delay_Req messages only */
3885                 ts_master_en = MAC_TCR_TSMASTERENA;
3886                 ts_event_en = MAC_TCR_TSEVENTENA;
3887
3888                 ptp_over_ipv4_udp = MAC_TCR_TSIPV4ENA;
3889                 ptp_over_ipv6_udp = MAC_TCR_TSIPV6ENA;
3890                 ptp_over_ethernet = MAC_TCR_TSIPENA;
3891                 av_8021asm_en = MAC_TCR_AV8021ASMEN;
3892                 break;
3893
3894                 /* time stamp any incoming packet */
3895         case HWTSTAMP_FILTER_ALL:
3896                 config.rx_filter = HWTSTAMP_FILTER_ALL;
3897                 tstamp_all = MAC_TCR_TSENALL;
3898                 break;
3899
3900         default:
3901                 return -ERANGE;
3902         }
3903         pdata->hwts_rx_en =
3904             ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1);
3905
3906         if (!pdata->hwts_tx_en && !pdata->hwts_rx_en) {
3907                 /* disable hw time stamping */
3908                 hw_if->config_hw_time_stamping(mac_tcr);
3909         } else {
3910                 mac_tcr =
3911                     (MAC_TCR_TSENA | MAC_TCR_TSCFUPDT | MAC_TCR_TSCTRLSSR |
3912                      tstamp_all | ptp_v2 | ptp_over_ethernet | ptp_over_ipv6_udp
3913                      | ptp_over_ipv4_udp | ts_event_en | ts_master_en |
3914                      snap_type_sel | av_8021asm_en);
3915
3916                 if (!pdata->one_nsec_accuracy)
3917                         mac_tcr &= ~MAC_TCR_TSCTRLSSR;
3918
3919                 hw_if->config_hw_time_stamping(mac_tcr);
3920
3921                 /* program Sub Second Increment Reg */
3922                 hw_if->config_sub_second_increment(EQOS_SYSCLOCK);
3923
3924                 /* formula is :
3925                  * addend = 2^32/freq_div_ratio;
3926                  *
3927                  * where, freq_div_ratio = EQOS_SYSCLOCK/50MHz
3928                  *
3929                  * hence, addend = ((2^32) * 50MHz)/EQOS_SYSCLOCK;
3930                  *
3931                  * NOTE: EQOS_SYSCLOCK should be >= 50MHz to
3932                  *       achive 20ns accuracy.
3933                  *
3934                  * 2^x * y == (y << x), hence
3935                  * 2^32 * 6250000 ==> (6250000 << 32)
3936                  * */
3937                 temp = (u64) (62500000ULL << 32);
3938                 pdata->default_addend = div_u64(temp, 125000000);
3939
3940                 hw_if->config_addend(pdata->default_addend);
3941
3942                 /* initialize system time */
3943                 getnstimeofday(&now);
3944                 hw_if->init_systime(now.tv_sec, now.tv_nsec);
3945         }
3946
3947         DBGPR_PTP("config.flags = %#x, tx_type = %#x, rx_filter = %#x\n",
3948                   config.flags, config.tx_type, config.rx_filter);
3949
3950         DBGPR_PTP("<--eqos_handle_hwtstamp_ioctl\n");
3951
3952         return (copy_to_user(ifr->ifr_data, &config,
3953                              sizeof(struct hwtstamp_config))) ? -EFAULT : 0;
3954 }
3955
3956 /*!
3957  * \brief Driver IOCTL routine
3958  *
3959  * \details This function is invoked by kernel when a user request an ioctl
3960  * which can't be handled by the generic interface code. Following operations
3961  * are performed in this functions.
3962  * - Configuring the PMT module.
3963  * - Configuring TX and RX PBL.
3964  * - Configuring the TX and RX FIFO threshold level.
3965  * - Configuring the TX and RX OSF mode.
3966  *
3967  * \param[in] dev â€“ pointer to net device structure.
3968  * \param[in] ifr â€“ pointer to IOCTL specific structure.
3969  * \param[in] cmd â€“ IOCTL command.
3970  *
3971  * \return int
3972  *
3973  * \retval 0 - success
3974  * \retval negative - failure
3975  */
3976
3977 static int eqos_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
3978 {
3979         struct eqos_prv_data *pdata = netdev_priv(dev);
3980         struct ifr_data_struct *req = ifr->ifr_ifru.ifru_data;
3981         struct mii_ioctl_data *data = if_mii(ifr);
3982         unsigned int reg_val = 0;
3983         int ret = 0;
3984
3985         pr_debug("-->eqos_ioctl\n");
3986
3987         if ((!netif_running(dev)) || (!pdata->phydev)) {
3988                 pr_debug("<--eqos_ioctl - error\n");
3989                 return -EINVAL;
3990         }
3991
3992         spin_lock(&pdata->lock);
3993         switch (cmd) {
3994         case SIOCGMIIPHY:
3995                 data->phy_id = pdata->phyaddr;
3996                 pr_err("PHY ID: SIOCGMIIPHY\n");
3997                 break;
3998
3999         case SIOCGMIIREG:
4000                 ret =
4001                     eqos_mdio_read_direct(pdata, pdata->phyaddr,
4002                                           (data->reg_num & 0x1F), &reg_val);
4003                 if (ret)
4004                         ret = -EIO;
4005
4006                 data->val_out = reg_val;
4007                 pr_err("PHY ID: SIOCGMIIREG reg:%#x reg_val:%#x\n",
4008                        (data->reg_num & 0x1F), reg_val);
4009                 break;
4010
4011         case SIOCSMIIREG:
4012                 pr_err("PHY ID: SIOCSMIIPHY\n");
4013                 break;
4014
4015         case EQOS_PRV_IOCTL:
4016                 ret = eqos_handle_prv_ioctl(pdata, req);
4017                 req->command_error = ret;
4018                 break;
4019
4020         case EQOS_PRV_TS_IOCTL:
4021                 ret = eqos_handle_prv_ts_ioctl(pdata, ifr);
4022                 break;
4023
4024         case SIOCSHWTSTAMP:
4025                 ret = eqos_handle_hwtstamp_ioctl(pdata, ifr);
4026                 break;
4027
4028         default:
4029                 ret = -EOPNOTSUPP;
4030                 pr_err("Unsupported IOCTL call\n");
4031         }
4032         spin_unlock(&pdata->lock);
4033
4034         pr_debug("<--eqos_ioctl\n");
4035
4036         return ret;
4037 }
4038
4039 /*!
4040 * \brief API to change MTU.
4041 *
4042 * \details This function is invoked by upper layer when user changes
4043 * MTU (Maximum Transfer Unit). The MTU is used by the Network layer
4044 * to driver packet transmission. Ethernet has a default MTU of
4045 * 1500Bytes. This value can be changed with ifconfig -
4046 * ifconfig <interface_name> mtu <new_mtu_value>
4047 *
4048 * \param[in] dev - pointer to net_device structure
4049 * \param[in] new_mtu - the new MTU for the device.
4050 *
4051 * \return integer
4052 *
4053 * \retval 0 - on success and -ve on failure.
4054 */
4055
4056 static INT eqos_change_mtu(struct net_device *dev, INT new_mtu)
4057 {
4058         struct eqos_prv_data *pdata = netdev_priv(dev);
4059         struct platform_device *pdev = pdata->pdev;
4060         int max_frame = (new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
4061
4062         pr_debug("-->eqos_change_mtu: new_mtu:%d\n", new_mtu);
4063
4064 #ifdef EQOS_CONFIG_PGTEST
4065         dev_err(&pdev->dev, "jumbo frames not supported with PG test\n");
4066         return -EOPNOTSUPP;
4067 #endif
4068         if (pdata->dt_cfg.use_multi_q) {
4069                 dev_err(&pdev->dev,
4070                         "mtu cannot be modified in multi queue mode\n");
4071                 return -EOPNOTSUPP;
4072         }
4073         if ((new_mtu != 1500) && (new_mtu != 4074) && (new_mtu != 9000)) {
4074                 dev_err(&pdev->dev, "valid mtus are 1500, 4074, or 9000\n");
4075                 return -EINVAL;
4076         }
4077         if (max_frame > (pdata->dt_cfg.phy_max_frame_size)) {
4078                 dev_err(&pdev->dev, "mtu exceeds phy max frame size of %d",
4079                         pdata->dt_cfg.phy_max_frame_size);
4080                 return -EINVAL;
4081         }
4082         if (dev->mtu == new_mtu) {
4083                 dev_err(&pdev->dev, "already configured to mtu %d\n", new_mtu);
4084                 return 0;
4085         }
4086
4087         dev_info(&pdev->dev, "changing MTU from %d to %d\n", dev->mtu, new_mtu);
4088
4089         mutex_lock(&pdata->hw_change_lock);
4090         if (!pdata->hw_stopped)
4091                 eqos_stop_dev(pdata);
4092
4093         if (max_frame <= 2048) {
4094                 pdata->rx_buffer_len = 2048;
4095         } else {
4096                 pdata->rx_buffer_len = ALIGN_SIZE(max_frame);
4097         }
4098         pdata->rx_max_frame_size = max_frame;
4099
4100         dev->mtu = new_mtu;
4101
4102         if (!pdata->hw_stopped)
4103                 eqos_start_dev(pdata);
4104
4105         mutex_unlock(&pdata->hw_change_lock);
4106
4107         pr_debug("<--eqos_change_mtu\n");
4108
4109         return 0;
4110 }
4111
4112 #ifdef EQOS_QUEUE_SELECT_ALGO
4113 u16 eqos_select_queue(struct net_device *dev,
4114                       struct sk_buff *skb, void *accel_priv,
4115                       select_queue_fallback_t fallback)
4116 {
4117         int  txqueue_select = -1;
4118         struct eqos_prv_data *pdata = netdev_priv(dev);
4119         struct eqos_cfg *pdt_cfg = (struct eqos_cfg *)&pdata->dt_cfg;
4120         UINT i;
4121
4122         pr_debug("-->eqos_select_queue\n");
4123
4124         for (i = 0; i <= EQOS_TX_QUEUE_CNT; i++) {
4125                 if (pdt_cfg->q_prio[i] == skb->priority) {
4126                         txqueue_select = i;
4127                         break;
4128                 }
4129         }
4130
4131         if (txqueue_select < 0)
4132                 txqueue_select = 0;
4133
4134         pr_debug("<--eqos_select_queue txqueue-select:%d\n", txqueue_select);
4135
4136         return txqueue_select;
4137 }
4138 #endif
4139
4140 unsigned int crc32_snps_le(unsigned int initval, unsigned char *data,
4141                            unsigned int size)
4142 {
4143         unsigned int crc = initval;
4144         unsigned int poly = 0x04c11db7;
4145         unsigned int temp = 0;
4146         unsigned char my_data = 0;
4147         int bit_count;
4148         for (bit_count = 0; bit_count < size; bit_count++) {
4149                 if ((bit_count % 8) == 0)
4150                         my_data = data[bit_count / 8];
4151                 DBGPR_FILTER("%s my_data = %x crc=%x\n", __func__, my_data,
4152                              crc);
4153                 temp = ((crc >> 31) ^ my_data) & 0x1;
4154                 crc <<= 1;
4155                 if (temp != 0)
4156                         crc ^= poly;
4157                 my_data >>= 1;
4158         }
4159         DBGPR_FILTER("%s my_data = %x crc=%x\n", __func__, my_data, crc);
4160         return ~crc;
4161 }
4162
4163 /*!
4164 * \brief API to delete vid to HW filter.
4165 *
4166 * \details This function is invoked by upper layer when a VLAN id is removed.
4167 * This function deletes the VLAN id from the HW filter.
4168 * vlan id can be removed with vconfig -
4169 * vconfig rem <interface_name > <vlan_id>
4170 *
4171 * \param[in] dev - pointer to net_device structure
4172 * \param[in] vid - vlan id to be removed.
4173 *
4174 * \return void
4175 */
4176 static int eqos_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
4177 {
4178         struct eqos_prv_data *pdata = netdev_priv(dev);
4179         struct hw_if_struct *hw_if = &(pdata->hw_if);
4180         unsigned short new_index, old_index;
4181         int crc32_val = 0;
4182         unsigned int enb_12bit_vhash;
4183
4184         pr_err("-->eqos_vlan_rx_kill_vid: vid = %d\n", vid);
4185
4186         if (pdata->vlan_hash_filtering) {
4187                 crc32_val =
4188                     (bitrev32(~crc32_le(~0, (unsigned char *)&vid, 2)) >> 28);
4189
4190                 enb_12bit_vhash = hw_if->get_vlan_tag_comparison();
4191                 if (enb_12bit_vhash) {
4192                         /* neget 4-bit crc value for 12-bit VLAN hash comparison */
4193                         new_index = (1 << (~crc32_val & 0xF));
4194                 } else {
4195                         new_index = (1 << (crc32_val & 0xF));
4196                 }
4197
4198                 old_index = hw_if->get_vlan_hash_table_reg();
4199                 old_index &= ~new_index;
4200                 hw_if->update_vlan_hash_table_reg(old_index);
4201                 pdata->vlan_ht_or_id = old_index;
4202         } else {
4203                 /* By default, receive only VLAN pkt with VID = 1
4204                  * becasue writting 0 will pass all VLAN pkt */
4205                 hw_if->update_vlan_id(1);
4206                 pdata->vlan_ht_or_id = 1;
4207         }
4208
4209         pr_err("<--eqos_vlan_rx_kill_vid\n");
4210
4211         /* FIXME: Check if any errors need to be returned in case of failure */
4212         return 0;
4213 }
4214
4215 static int eqos_set_mac_address(struct net_device *dev, void *p)
4216 {
4217         if (is_valid_ether_addr(dev->dev_addr))
4218                 return -EOPNOTSUPP;
4219         else
4220                 return eth_mac_addr(dev, p);
4221 }
4222
4223 /*!
4224 * \brief API to add vid to HW filter.
4225 *
4226 * \details This function is invoked by upper layer when a new VALN id is
4227 * registered. This function updates the HW filter with new VLAN id.
4228 * New vlan id can be added with vconfig -
4229 * vconfig add <interface_name > <vlan_id>
4230 *
4231 * \param[in] dev - pointer to net_device structure
4232 * \param[in] vid - new vlan id.
4233 *
4234 * \return void
4235 */
4236 static int eqos_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
4237 {
4238         struct eqos_prv_data *pdata = netdev_priv(dev);
4239         struct hw_if_struct *hw_if = &(pdata->hw_if);
4240         unsigned short new_index, old_index;
4241         int crc32_val = 0;
4242         unsigned int enb_12bit_vhash;
4243
4244         pr_err("-->eqos_vlan_rx_add_vid: vid = %d\n", vid);
4245
4246         if (pdata->vlan_hash_filtering) {
4247                 /* The upper 4 bits of the calculated CRC are used to
4248                  * index the content of the VLAN Hash Table Reg.
4249                  * */
4250                 crc32_val =
4251                     (bitrev32(~crc32_le(~0, (unsigned char *)&vid, 2)) >> 28);
4252
4253                 /* These 4(0xF) bits determines the bit within the
4254                  * VLAN Hash Table Reg 0
4255                  * */
4256                 enb_12bit_vhash = hw_if->get_vlan_tag_comparison();
4257                 if (enb_12bit_vhash) {
4258                         /* neget 4-bit crc value for 12-bit VLAN hash comparison */
4259                         new_index = (1 << (~crc32_val & 0xF));
4260                 } else {
4261                         new_index = (1 << (crc32_val & 0xF));
4262                 }
4263
4264                 old_index = hw_if->get_vlan_hash_table_reg();
4265                 old_index |= new_index;
4266                 hw_if->update_vlan_hash_table_reg(old_index);
4267                 pdata->vlan_ht_or_id = old_index;
4268         } else {
4269                 hw_if->update_vlan_id(vid);
4270                 pdata->vlan_ht_or_id = vid;
4271         }
4272
4273         pr_err("<--eqos_vlan_rx_add_vid\n");
4274
4275         /* FIXME: Check if any errors need to be returned in case of failure */
4276         return 0;
4277 }
4278
4279 /*!
4280  * \brief API called to put device in powerdown mode
4281  *
4282  * \details This function is invoked by ioctl function when the user issues an
4283  * ioctl command to move the device to power down state. Following operations
4284  * are performed in this function.
4285  * - stop the phy.
4286  * - stop the queue.
4287  * - Disable napi.
4288  * - Stop DMA TX and RX process.
4289  * - Enable power down mode using PMT module.
4290  *
4291  * \param[in] dev â€“ pointer to net device structure.
4292  * \param[in] wakeup_type â€“ remote wake-on-lan or magic packet.
4293  * \param[in] caller â€“ netif_detach gets called conditionally based
4294  *                     on caller, IOCTL or DRIVER-suspend
4295  *
4296  * \return int
4297  *
4298  * \retval zero on success and -ve number on failure.
4299  */
4300
4301 INT eqos_powerdown(struct net_device *dev, UINT wakeup_type, UINT caller)
4302 {
4303         struct eqos_prv_data *pdata = netdev_priv(dev);
4304         struct hw_if_struct *hw_if = &(pdata->hw_if);
4305
4306         pr_debug("-->eqos_powerdown\n");
4307
4308         if (!dev || !netif_running(dev) ||
4309             (caller == EQOS_IOCTL_CONTEXT && pdata->power_down)) {
4310                 pr_err
4311                     ("Device is already powered down and will powerup for %s\n",
4312                      EQOS_POWER_DOWN_TYPE(pdata));
4313                 pr_debug("<--eqos_powerdown\n");
4314                 return -EINVAL;
4315         }
4316
4317         if (pdata->phydev)
4318                 phy_stop(pdata->phydev);
4319
4320         spin_lock(&pdata->pmt_lock);
4321
4322         if (caller == EQOS_DRIVER_CONTEXT)
4323                 netif_device_detach(dev);
4324
4325         netif_tx_disable(dev);
4326         eqos_all_ch_napi_disable(pdata);
4327
4328         /* stop DMA TX/RX */
4329         eqos_stop_all_ch_tx_dma(pdata);
4330         eqos_stop_all_ch_rx_dma(pdata);
4331
4332         /* enable power down mode by programming the PMT regs */
4333         if (wakeup_type & EQOS_REMOTE_WAKEUP)
4334                 hw_if->enable_remote_pmt();
4335         if (wakeup_type & EQOS_MAGIC_WAKEUP)
4336                 hw_if->enable_magic_pmt();
4337         pdata->power_down_type = wakeup_type;
4338
4339         if (caller == EQOS_IOCTL_CONTEXT)
4340                 pdata->power_down = 1;
4341
4342         spin_unlock(&pdata->pmt_lock);
4343
4344         pr_debug("<--eqos_powerdown\n");
4345
4346         return 0;
4347 }
4348
4349 /*!
4350  * \brief API to powerup the device
4351  *
4352  * \details This function is invoked by ioctl function when the user issues an
4353  * ioctl command to move the device to out of power down state. Following
4354  * operations are performed in this function.
4355  * - Wakeup the device using PMT module if supported.
4356  * - Starts the phy.
4357  * - Enable MAC and DMA TX and RX process.
4358  * - Enable napi.
4359  * - Starts the queue.
4360  *
4361  * \param[in] dev â€“ pointer to net device structure.
4362  * \param[in] caller â€“ netif_attach gets called conditionally based
4363  *                     on caller, IOCTL or DRIVER-suspend
4364  *
4365  * \return int
4366  *
4367  * \retval zero on success and -ve number on failure.
4368  */
4369
4370 INT eqos_powerup(struct net_device *dev, UINT caller)
4371 {
4372         struct eqos_prv_data *pdata = netdev_priv(dev);
4373         struct hw_if_struct *hw_if = &(pdata->hw_if);
4374
4375         pr_debug("-->eqos_powerup\n");
4376
4377         if (!dev || !netif_running(dev) ||
4378             (caller == EQOS_IOCTL_CONTEXT && !pdata->power_down)) {
4379                 pr_err("Device is already powered up\n");
4380                 return -EINVAL;
4381         }
4382
4383         spin_lock(&pdata->pmt_lock);
4384
4385         if (pdata->power_down_type & EQOS_MAGIC_WAKEUP) {
4386                 hw_if->disable_magic_pmt();
4387                 pdata->power_down_type &= ~EQOS_MAGIC_WAKEUP;
4388         }
4389
4390         if (pdata->power_down_type & EQOS_REMOTE_WAKEUP) {
4391                 hw_if->disable_remote_pmt();
4392                 pdata->power_down_type &= ~EQOS_REMOTE_WAKEUP;
4393         }
4394
4395         pdata->power_down = 0;
4396
4397         if (pdata->phydev)
4398                 phy_start(pdata->phydev);
4399
4400         /* enable MAC TX/RX */
4401         hw_if->start_mac_tx_rx();
4402
4403         /* enable DMA TX/RX */
4404         eqos_start_all_ch_tx_dma(pdata);
4405         eqos_start_all_ch_rx_dma(pdata);
4406
4407         if (caller == EQOS_DRIVER_CONTEXT)
4408                 netif_device_attach(dev);
4409
4410         eqos_napi_enable_mq(pdata);
4411
4412         netif_tx_start_all_queues(dev);
4413
4414         spin_unlock(&pdata->pmt_lock);
4415
4416         pr_debug("<--eqos_powerup\n");
4417
4418         return 0;
4419 }
4420
4421 /*!
4422  * \brief API to configure remote wakeup
4423  *
4424  * \details This function is invoked by ioctl function when the user issues an
4425  * ioctl command to move the device to power down state using remote wakeup.
4426  *
4427  * \param[in] dev â€“ pointer to net device structure.
4428  * \param[in] req â€“ pointer to ioctl data structure.
4429  *
4430  * \return int
4431  *
4432  * \retval zero on success and -ve number on failure.
4433  */
4434
4435 INT eqos_configure_remotewakeup(struct net_device *dev,
4436                                 struct ifr_data_struct *req)
4437 {
4438         struct eqos_prv_data *pdata = netdev_priv(dev);
4439         struct hw_if_struct *hw_if = &(pdata->hw_if);
4440
4441         if (!dev || !netif_running(dev) || !pdata->hw_feat.rwk_sel
4442             || pdata->power_down) {
4443                 pr_err
4444                     ("Device is already powered down and will powerup for %s\n",
4445                      EQOS_POWER_DOWN_TYPE(pdata));
4446                 return -EINVAL;
4447         }
4448
4449         hw_if->configure_rwk_filter(req->rwk_filter_values,
4450                                     req->rwk_filter_length);
4451
4452         eqos_powerdown(dev, EQOS_REMOTE_WAKEUP, EQOS_IOCTL_CONTEXT);
4453
4454         return 0;
4455 }
4456
4457 /*!
4458  * \details This function is invoked by ioctl function when the user issues an
4459  * ioctl command to change the RX DMA PBL value. This function will program
4460  * the device to configure the user specified RX PBL value.
4461  *
4462  * \param[in] pdata â€“ pointer to private data structure.
4463  * \param[in] rx_pbl â€“ RX DMA pbl value to be programmed.
4464  *
4465  * \return void
4466  *
4467  * \retval none
4468  */
4469
4470 static void eqos_config_rx_pbl(struct eqos_prv_data *pdata,
4471                                UINT rx_pbl, UINT qinx)
4472 {
4473         struct hw_if_struct *hw_if = &(pdata->hw_if);
4474         UINT pblx8_val = 0;
4475
4476         pr_debug("-->eqos_config_rx_pbl: %d\n", rx_pbl);
4477
4478         switch (rx_pbl) {
4479         case EQOS_PBL_1:
4480         case EQOS_PBL_2:
4481         case EQOS_PBL_4:
4482         case EQOS_PBL_8:
4483         case EQOS_PBL_16:
4484         case EQOS_PBL_32:
4485                 hw_if->config_rx_pbl_val(qinx, rx_pbl);
4486                 hw_if->config_pblx8(qinx, 0);
4487                 break;
4488         case EQOS_PBL_64:
4489         case EQOS_PBL_128:
4490         case EQOS_PBL_256:
4491                 hw_if->config_rx_pbl_val(qinx, rx_pbl / 8);
4492                 hw_if->config_pblx8(qinx, 1);
4493                 pblx8_val = 1;
4494                 break;
4495         }
4496
4497         switch (pblx8_val) {
4498         case 0:
4499                 pr_err("Tx PBL[%d] value: %d\n",
4500                        qinx, hw_if->get_tx_pbl_val(qinx));
4501                 pr_err("Rx PBL[%d] value: %d\n",
4502                        qinx, hw_if->get_rx_pbl_val(qinx));
4503                 break;
4504         case 1:
4505                 pr_err("Tx PBL[%d] value: %d\n",
4506                        qinx, (hw_if->get_tx_pbl_val(qinx) * 8));
4507                 pr_err("Rx PBL[%d] value: %d\n",
4508                        qinx, (hw_if->get_rx_pbl_val(qinx) * 8));
4509                 break;
4510         }
4511
4512         pr_debug("<--eqos_config_rx_pbl\n");
4513 }
4514
4515 /*!
4516  * \details This function is invoked by ioctl function when the user issues an
4517  * ioctl command to change the TX DMA PBL value. This function will program
4518  * the device to configure the user specified TX PBL value.
4519  *
4520  * \param[in] pdata â€“ pointer to private data structure.
4521  * \param[in] tx_pbl â€“ TX DMA pbl value to be programmed.
4522  *
4523  * \return void
4524  *
4525  * \retval none
4526  */
4527
4528 static void eqos_config_tx_pbl(struct eqos_prv_data *pdata,
4529                                UINT tx_pbl, UINT qinx)
4530 {
4531         struct hw_if_struct *hw_if = &(pdata->hw_if);
4532         UINT pblx8_val = 0;
4533
4534         pr_debug("-->eqos_config_tx_pbl: %d\n", tx_pbl);
4535
4536         switch (tx_pbl) {
4537         case EQOS_PBL_1:
4538         case EQOS_PBL_2:
4539         case EQOS_PBL_4:
4540         case EQOS_PBL_8:
4541         case EQOS_PBL_16:
4542         case EQOS_PBL_32:
4543                 hw_if->config_tx_pbl_val(qinx, tx_pbl);
4544                 hw_if->config_pblx8(qinx, 0);
4545                 break;
4546         case EQOS_PBL_64:
4547         case EQOS_PBL_128:
4548         case EQOS_PBL_256:
4549                 hw_if->config_tx_pbl_val(qinx, tx_pbl / 8);
4550                 hw_if->config_pblx8(qinx, 1);
4551                 pblx8_val = 1;
4552                 break;
4553         }
4554
4555         switch (pblx8_val) {
4556         case 0:
4557                 pr_err("Tx PBL[%d] value: %d\n",
4558                        qinx, hw_if->get_tx_pbl_val(qinx));
4559                 pr_err("Rx PBL[%d] value: %d\n",
4560                        qinx, hw_if->get_rx_pbl_val(qinx));
4561                 break;
4562         case 1:
4563                 pr_err("Tx PBL[%d] value: %d\n",
4564                        qinx, (hw_if->get_tx_pbl_val(qinx) * 8));
4565                 pr_err("Rx PBL[%d] value: %d\n",
4566                        qinx, (hw_if->get_rx_pbl_val(qinx) * 8));
4567                 break;
4568         }
4569
4570         pr_debug("<--eqos_config_tx_pbl\n");
4571 }
4572
4573 /*!
4574  * \details This function is invoked by ioctl function when the user issues an
4575  * ioctl command to select the DCB algorithm.
4576  *
4577  * \param[in] pdata â€“ pointer to private data structure.
4578  * \param[in] req â€“ pointer to ioctl data structure.
4579  *
4580  * \return void
4581  *
4582  * \retval none
4583  */
4584
4585 static void eqos_program_dcb_algorithm(struct eqos_prv_data *pdata,
4586                                        struct ifr_data_struct *req)
4587 {
4588         struct eqos_dcb_algorithm l_dcb_struct, *u_dcb_struct =
4589             (struct eqos_dcb_algorithm *)req->ptr;
4590         struct hw_if_struct *hw_if = &pdata->hw_if;
4591
4592         pr_debug("-->eqos_program_dcb_algorithm\n");
4593
4594         if (copy_from_user(&l_dcb_struct, u_dcb_struct,
4595                            sizeof(struct eqos_dcb_algorithm)))
4596                 pr_err("Failed to fetch DCB Struct info from user\n");
4597
4598         hw_if->set_tx_queue_operating_mode(l_dcb_struct.qinx,
4599                                            (UINT) l_dcb_struct.op_mode);
4600         hw_if->set_dcb_algorithm(l_dcb_struct.algorithm);
4601         hw_if->set_dcb_queue_weight(l_dcb_struct.qinx, l_dcb_struct.weight);
4602
4603         pr_debug("<--eqos_program_dcb_algorithm\n");
4604
4605         return;
4606 }
4607
4608 /*!
4609  * \details This function is invoked by ioctl function when the user issues an
4610  * ioctl command to select the AVB algorithm. This function also configures other
4611  * parameters like send and idle slope, high and low credit.
4612  *
4613  * \param[in] pdata â€“ pointer to private data structure.
4614  * \param[in] req â€“ pointer to ioctl data structure.
4615  *
4616  * \return void
4617  *
4618  * \retval none
4619  */
4620
4621 static void eqos_program_avb_algorithm(struct eqos_prv_data *pdata,
4622                                        struct ifr_data_struct *req)
4623 {
4624         struct eqos_avb_algorithm l_avb_struct, *u_avb_struct =
4625             (struct eqos_avb_algorithm *)req->ptr;
4626         struct hw_if_struct *hw_if = &pdata->hw_if;
4627
4628         pr_debug("-->eqos_program_avb_algorithm\n");
4629
4630         if (copy_from_user(&l_avb_struct, u_avb_struct,
4631                            sizeof(struct eqos_avb_algorithm)))
4632                 pr_err("Failed to fetch AVB Struct info from user\n");
4633
4634         hw_if->set_tx_queue_operating_mode(l_avb_struct.qinx,
4635                                            (UINT) l_avb_struct.op_mode);
4636         hw_if->set_avb_algorithm(l_avb_struct.qinx, l_avb_struct.algorithm);
4637         hw_if->config_credit_control(l_avb_struct.qinx, l_avb_struct.cc);
4638         hw_if->config_send_slope(l_avb_struct.qinx, l_avb_struct.send_slope);
4639         hw_if->config_idle_slope(l_avb_struct.qinx, l_avb_struct.idle_slope);
4640         hw_if->config_high_credit(l_avb_struct.qinx, l_avb_struct.hi_credit);
4641         hw_if->config_low_credit(l_avb_struct.qinx, l_avb_struct.low_credit);
4642
4643         pr_debug("<--eqos_program_avb_algorithm\n");
4644
4645         return;
4646 }
4647
4648 /*!
4649 * \brief API to read the registers & prints the value.
4650 * \details This function will read all the device register except
4651 * data register & prints the values.
4652 *
4653 * \return none
4654 */
4655 #if 0
4656 void dbgpr_regs(void)
4657 {
4658         UINT val0;
4659         UINT val1;
4660         UINT val2;
4661         UINT val3;
4662         UINT val4;
4663         UINT val5;
4664
4665         MAC_PMTCSR_RD(val0);
4666         MMC_RXICMP_ERR_OCTETS_RD(val1);
4667         MMC_RXICMP_GD_OCTETS_RD(val2);
4668         MMC_RXTCP_ERR_OCTETS_RD(val3);
4669         MMC_RXTCP_GD_OCTETS_RD(val4);
4670         MMC_RXUDP_ERR_OCTETS_RD(val5);
4671
4672         pr_debug("dbgpr_regs: MAC_PMTCSR:%#x\n"
4673               "dbgpr_regs: MMC_RXICMP_ERR_OCTETS:%#x\n"
4674               "dbgpr_regs: MMC_RXICMP_GD_OCTETS:%#x\n"
4675               "dbgpr_regs: MMC_RXTCP_ERR_OCTETS:%#x\n"
4676               "dbgpr_regs: MMC_RXTCP_GD_OCTETS:%#x\n"
4677               "dbgpr_regs: MMC_RXUDP_ERR_OCTETS:%#x\n",
4678               val0, val1, val2, val3, val4, val5);
4679
4680         MMC_RXUDP_GD_OCTETS_RD(val0);
4681         MMC_RXIPV6_NOPAY_OCTETS_RD(val1);
4682         MMC_RXIPV6_HDRERR_OCTETS_RD(val2);
4683         MMC_RXIPV6_GD_OCTETS_RD(val3);
4684         MMC_RXIPV4_UDSBL_OCTETS_RD(val4);
4685         MMC_RXIPV4_FRAG_OCTETS_RD(val5);
4686
4687         pr_debug("dbgpr_regs: MMC_RXUDP_GD_OCTETS:%#x\n"
4688               "dbgpr_regs: MMC_RXIPV6_NOPAY_OCTETS:%#x\n"
4689               "dbgpr_regs: MMC_RXIPV6_HDRERR_OCTETS:%#x\n"
4690               "dbgpr_regs: MMC_RXIPV6_GD_OCTETS:%#x\n"
4691               "dbgpr_regs: MMC_RXIPV4_UDSBL_OCTETS:%#x\n"
4692               "dbgpr_regs: MMC_RXIPV4_FRAG_OCTETS:%#x\n",
4693               val0, val1, val2, val3, val4, val5);
4694
4695         MMC_RXIPV4_NOPAY_OCTETS_RD(val0);
4696         MMC_RXIPV4_HDRERR_OCTETS_RD(val1);
4697         MMC_RXIPV4_GD_OCTETS_RD(val2);
4698         MMC_RXICMP_ERR_PKTS_RD(val3);
4699         MMC_RXICMP_GD_PKTS_RD(val4);
4700         MMC_RXTCP_ERR_PKTS_RD(val5);
4701
4702         pr_debug("dbgpr_regs: MMC_RXIPV4_NOPAY_OCTETS:%#x\n"
4703               "dbgpr_regs: MMC_RXIPV4_HDRERR_OCTETS:%#x\n"
4704               "dbgpr_regs: MMC_RXIPV4_GD_OCTETS:%#x\n"
4705               "dbgpr_regs: MMC_RXICMP_ERR_PKTS:%#x\n"
4706               "dbgpr_regs: MMC_RXICMP_GD_PKTS:%#x\n"
4707               "dbgpr_regs: MMC_RXTCP_ERR_PKTS:%#x\n",
4708               val0, val1, val2, val3, val4, val5);
4709
4710         MMC_RXTCP_GD_PKTS_RD(val0);
4711         MMC_RXUDP_ERR_PKTS_RD(val1);
4712         MMC_RXUDP_GD_PKTS_RD(val2);
4713         MMC_RXIPV6_NOPAY_PKTS_RD(val3);
4714         MMC_RXIPV6_HDRERR_PKTS_RD(val4);
4715         MMC_RXIPV6_GD_PKTS_RD(val5);
4716
4717         pr_debug("dbgpr_regs: MMC_RXTCP_GD_PKTS:%#x\n"
4718               "dbgpr_regs: MMC_RXUDP_ERR_PKTS:%#x\n"
4719               "dbgpr_regs: MMC_RXUDP_GD_PKTS:%#x\n"
4720               "dbgpr_regs: MMC_RXIPV6_NOPAY_PKTS:%#x\n"
4721               "dbgpr_regs: MMC_RXIPV6_HDRERR_PKTS:%#x\n"
4722               "dbgpr_regs: MMC_RXIPV6_GD_PKTS:%#x\n",
4723               val0, val1, val2, val3, val4, val5);
4724
4725         MMC_RXIPV4_UBSBL_PKTS_RD(val0);
4726         MMC_RXIPV4_FRAG_PKTS_RD(val1);
4727         MMC_RXIPV4_NOPAY_PKTS_RD(val2);
4728         MMC_RXIPV4_HDRERR_PKTS_RD(val3);
4729         MMC_RXIPV4_GD_PKTS_RD(val4);
4730         MMC_RXCTRLPACKETS_G_RD(val5);
4731
4732         pr_debug("dbgpr_regs: MMC_RXIPV4_UBSBL_PKTS:%#x\n"
4733               "dbgpr_regs: MMC_RXIPV4_FRAG_PKTS:%#x\n"
4734               "dbgpr_regs: MMC_RXIPV4_NOPAY_PKTS:%#x\n"
4735               "dbgpr_regs: MMC_RXIPV4_HDRERR_PKTS:%#x\n"
4736               "dbgpr_regs: MMC_RXIPV4_GD_PKTS:%#x\n"
4737               "dbgpr_regs: MMC_RXCTRLPACKETS_G:%#x\n",
4738               val0, val1, val2, val3, val4, val5);
4739
4740         MMC_RXRCVERROR_RD(val0);
4741         MMC_RXWATCHDOGERROR_RD(val1);
4742         MMC_RXVLANPACKETS_GB_RD(val2);
4743         MMC_RXFIFOOVERFLOW_RD(val3);
4744         MMC_RXPAUSEPACKETS_RD(val4);
4745         MMC_RXOUTOFRANGETYPE_RD(val5);
4746
4747         pr_debug("dbgpr_regs: MMC_RXRCVERROR:%#x\n"
4748               "dbgpr_regs: MMC_RXWATCHDOGERROR:%#x\n"
4749               "dbgpr_regs: MMC_RXVLANPACKETS_GB:%#x\n"
4750               "dbgpr_regs: MMC_RXFIFOOVERFLOW:%#x\n"
4751               "dbgpr_regs: MMC_RXPAUSEPACKETS:%#x\n"
4752               "dbgpr_regs: MMC_RXOUTOFRANGETYPE:%#x\n",
4753               val0, val1, val2, val3, val4, val5);
4754
4755         MMC_RXLENGTHERROR_RD(val0);
4756         MMC_RXUNICASTPACKETS_G_RD(val1);
4757         MMC_RX1024TOMAXOCTETS_GB_RD(val2);
4758         MMC_RX512TO1023OCTETS_GB_RD(val3);
4759         MMC_RX256TO511OCTETS_GB_RD(val4);
4760         MMC_RX128TO255OCTETS_GB_RD(val5);
4761
4762         pr_debug("dbgpr_regs: MMC_RXLENGTHERROR:%#x\n"
4763               "dbgpr_regs: MMC_RXUNICASTPACKETS_G:%#x\n"
4764               "dbgpr_regs: MMC_RX1024TOMAXOCTETS_GB:%#x\n"
4765               "dbgpr_regs: MMC_RX512TO1023OCTETS_GB:%#x\n"
4766               "dbgpr_regs: MMC_RX256TO511OCTETS_GB:%#x\n"
4767               "dbgpr_regs: MMC_RX128TO255OCTETS_GB:%#x\n",
4768               val0, val1, val2, val3, val4, val5);
4769
4770         MMC_RX65TO127OCTETS_GB_RD(val0);
4771         MMC_RX64OCTETS_GB_RD(val1);
4772         MMC_RXOVERSIZE_G_RD(val2);
4773         MMC_RXUNDERSIZE_G_RD(val3);
4774         MMC_RXJABBERERROR_RD(val4);
4775         MMC_RXRUNTERROR_RD(val5);
4776
4777         pr_debug("dbgpr_regs: MMC_RX65TO127OCTETS_GB:%#x\n"
4778               "dbgpr_regs: MMC_RX64OCTETS_GB:%#x\n"
4779               "dbgpr_regs: MMC_RXOVERSIZE_G:%#x\n"
4780               "dbgpr_regs: MMC_RXUNDERSIZE_G:%#x\n"
4781               "dbgpr_regs: MMC_RXJABBERERROR:%#x\n"
4782               "dbgpr_regs: MMC_RXRUNTERROR:%#x\n",
4783               val0, val1, val2, val3, val4, val5);
4784
4785         MMC_RXALIGNMENTERROR_RD(val0);
4786         MMC_RXCRCERROR_RD(val1);
4787         MMC_RXMULTICASTPACKETS_G_RD(val2);
4788         MMC_RXBROADCASTPACKETS_G_RD(val3);
4789         MMC_RXOCTETCOUNT_G_RD(val4);
4790         MMC_RXOCTETCOUNT_GB_RD(val5);
4791
4792         pr_debug("dbgpr_regs: MMC_RXALIGNMENTERROR:%#x\n"
4793               "dbgpr_regs: MMC_RXCRCERROR:%#x\n"
4794               "dbgpr_regs: MMC_RXMULTICASTPACKETS_G:%#x\n"
4795               "dbgpr_regs: MMC_RXBROADCASTPACKETS_G:%#x\n"
4796               "dbgpr_regs: MMC_RXOCTETCOUNT_G:%#x\n"
4797               "dbgpr_regs: MMC_RXOCTETCOUNT_GB:%#x\n",
4798               val0, val1, val2, val3, val4, val5);
4799
4800         MMC_RXPACKETCOUNT_GB_RD(val0);
4801         MMC_TXOVERSIZE_G_RD(val1);
4802         MMC_TXVLANPACKETS_G_RD(val2);
4803         MMC_TXPAUSEPACKETS_RD(val3);
4804         MMC_TXEXCESSDEF_RD(val4);
4805         MMC_TXPACKETSCOUNT_G_RD(val5);
4806
4807         pr_debug("dbgpr_regs: MMC_RXPACKETCOUNT_GB:%#x\n"
4808               "dbgpr_regs: MMC_TXOVERSIZE_G:%#x\n"
4809               "dbgpr_regs: MMC_TXVLANPACKETS_G:%#x\n"
4810               "dbgpr_regs: MMC_TXPAUSEPACKETS:%#x\n"
4811               "dbgpr_regs: MMC_TXEXCESSDEF:%#x\n"
4812               "dbgpr_regs: MMC_TXPACKETSCOUNT_G:%#x\n",
4813               val0, val1, val2, val3, val4, val5);
4814
4815         MMC_TXOCTETCOUNT_G_RD(val0);
4816         MMC_TXCARRIERERROR_RD(val1);
4817         MMC_TXEXESSCOL_RD(val2);
4818         MMC_TXLATECOL_RD(val3);
4819         MMC_TXDEFERRED_RD(val4);
4820         MMC_TXMULTICOL_G_RD(val5);
4821
4822         pr_debug("dbgpr_regs: MMC_TXOCTETCOUNT_G:%#x\n"
4823               "dbgpr_regs: MMC_TXCARRIERERROR:%#x\n"
4824               "dbgpr_regs: MMC_TXEXESSCOL:%#x\n"
4825               "dbgpr_regs: MMC_TXLATECOL:%#x\n"
4826               "dbgpr_regs: MMC_TXDEFERRED:%#x\n"
4827               "dbgpr_regs: MMC_TXMULTICOL_G:%#x\n",
4828               val0, val1, val2, val3, val4, val5);
4829
4830         MMC_TXSINGLECOL_G_RD(val0);
4831         MMC_TXUNDERFLOWERROR_RD(val1);
4832         MMC_TXBROADCASTPACKETS_GB_RD(val2);
4833         MMC_TXMULTICASTPACKETS_GB_RD(val3);
4834         MMC_TXUNICASTPACKETS_GB_RD(val4);
4835         MMC_TX1024TOMAXOCTETS_GB_RD(val5);
4836
4837         pr_debug("dbgpr_regs: MMC_TXSINGLECOL_G:%#x\n"
4838               "dbgpr_regs: MMC_TXUNDERFLOWERROR:%#x\n"
4839               "dbgpr_regs: MMC_TXBROADCASTPACKETS_GB:%#x\n"
4840               "dbgpr_regs: MMC_TXMULTICASTPACKETS_GB:%#x\n"
4841               "dbgpr_regs: MMC_TXUNICASTPACKETS_GB:%#x\n"
4842               "dbgpr_regs: MMC_TX1024TOMAXOCTETS_GB:%#x\n",
4843               val0, val1, val2, val3, val4, val5);
4844
4845         MMC_TX512TO1023OCTETS_GB_RD(val0);
4846         MMC_TX256TO511OCTETS_GB_RD(val1);
4847         MMC_TX128TO255OCTETS_GB_RD(val2);
4848         MMC_TX65TO127OCTETS_GB_RD(val3);
4849         MMC_TX64OCTETS_GB_RD(val4);
4850         MMC_TXMULTICASTPACKETS_G_RD(val5);
4851
4852         pr_debug("dbgpr_regs: MMC_TX512TO1023OCTETS_GB:%#x\n"
4853               "dbgpr_regs: MMC_TX256TO511OCTETS_GB:%#x\n"
4854               "dbgpr_regs: MMC_TX128TO255OCTETS_GB:%#x\n"
4855               "dbgpr_regs: MMC_TX65TO127OCTETS_GB:%#x\n"
4856               "dbgpr_regs: MMC_TX64OCTETS_GB:%#x\n"
4857               "dbgpr_regs: MMC_TXMULTICASTPACKETS_G:%#x\n",
4858               val0, val1, val2, val3, val4, val5);
4859
4860         MMC_TXBROADCASTPACKETS_G_RD(val0);
4861         MMC_TXPACKETCOUNT_GB_RD(val1);
4862         MMC_TXOCTETCOUNT_GB_RD(val2);
4863         MMC_IPC_INTR_RX_RD(val3);
4864         MMC_IPC_INTR_MASK_RX_RD(val4);
4865         MMC_INTR_MASK_TX_RD(val5);
4866
4867         pr_debug("dbgpr_regs: MMC_TXBROADCASTPACKETS_G:%#x\n"
4868               "dbgpr_regs: MMC_TXPACKETCOUNT_GB:%#x\n"
4869               "dbgpr_regs: MMC_TXOCTETCOUNT_GB:%#x\n"
4870               "dbgpr_regs: MMC_IPC_INTR_RX:%#x\n"
4871               "dbgpr_regs: MMC_IPC_INTR_MASK_RX:%#x\n"
4872               "dbgpr_regs: MMC_INTR_MASK_TX:%#x\n",
4873               val0, val1, val2, val3, val4, val5);
4874
4875         MMC_INTR_MASK_RX_RD(val0);
4876         MMC_INTR_TX_RD(val1);
4877         MMC_INTR_RX_RD(val2);
4878         MMC_CNTRL_RD(val3);
4879         MAC_MA1LR_RD(val4);
4880         MAC_MA1HR_RD(val5);
4881
4882         pr_debug("dbgpr_regs: MMC_INTR_MASK_RX:%#x\n"
4883               "dbgpr_regs: MMC_INTR_TX:%#x\n"
4884               "dbgpr_regs: MMC_INTR_RX:%#x\n"
4885               "dbgpr_regs: MMC_CNTRL:%#x\n"
4886               "dbgpr_regs: MAC_MA1LR:%#x\n"
4887               "dbgpr_regs: MAC_MA1HR:%#x\n",
4888               val0, val1, val2, val3, val4, val5);
4889
4890         MAC_MA0LR_RD(val0);
4891         MAC_MA0HR_RD(val1);
4892         MAC_GPIOR_RD(val2);
4893         MAC_GMIIDR_RD(val3);
4894         MAC_GMIIAR_RD(val4);
4895         MAC_HFR2_RD(val5);
4896
4897         pr_debug("dbgpr_regs: MAC_MA0LR:%#x\n"
4898               "dbgpr_regs: MAC_MA0HR:%#x\n"
4899               "dbgpr_regs: MAC_GPIOR:%#x\n"
4900               "dbgpr_regs: MAC_GMIIDR:%#x\n"
4901               "dbgpr_regs: MAC_GMIIAR:%#x\n"
4902               "dbgpr_regs: MAC_HFR2:%#x\n", val0, val1, val2, val3, val4, val5);
4903
4904         MAC_HFR1_RD(val0);
4905         MAC_HFR0_RD(val1);
4906         MAC_MDR_RD(val2);
4907         MAC_VR_RD(val3);
4908         MAC_HTR7_RD(val4);
4909         MAC_HTR6_RD(val5);
4910
4911         pr_debug("dbgpr_regs: MAC_HFR1:%#x\n"
4912               "dbgpr_regs: MAC_HFR0:%#x\n"
4913               "dbgpr_regs: MAC_MDR:%#x\n"
4914               "dbgpr_regs: MAC_VR:%#x\n"
4915               "dbgpr_regs: MAC_HTR7:%#x\n"
4916               "dbgpr_regs: MAC_HTR6:%#x\n", val0, val1, val2, val3, val4, val5);
4917
4918         MAC_HTR5_RD(val0);
4919         MAC_HTR4_RD(val1);
4920         MAC_HTR3_RD(val2);
4921         MAC_HTR2_RD(val3);
4922         MAC_HTR1_RD(val4);
4923         MAC_HTR0_RD(val5);
4924
4925         pr_debug("dbgpr_regs: MAC_HTR5:%#x\n"
4926               "dbgpr_regs: MAC_HTR4:%#x\n"
4927               "dbgpr_regs: MAC_HTR3:%#x\n"
4928               "dbgpr_regs: MAC_HTR2:%#x\n"
4929               "dbgpr_regs: MAC_HTR1:%#x\n"
4930               "dbgpr_regs: MAC_HTR0:%#x\n", val0, val1, val2, val3, val4, val5);
4931
4932         DMA_RIWTR7_RD(val0);
4933         DMA_RIWTR6_RD(val1);
4934         DMA_RIWTR5_RD(val2);
4935         DMA_RIWTR4_RD(val3);
4936         DMA_RIWTR3_RD(val4);
4937         DMA_RIWTR2_RD(val5);
4938
4939         pr_debug("dbgpr_regs: DMA_RIWTR7:%#x\n"
4940               "dbgpr_regs: DMA_RIWTR6:%#x\n"
4941               "dbgpr_regs: DMA_RIWTR5:%#x\n"
4942               "dbgpr_regs: DMA_RIWTR4:%#x\n"
4943               "dbgpr_regs: DMA_RIWTR3:%#x\n"
4944               "dbgpr_regs: DMA_RIWTR2:%#x\n",
4945               val0, val1, val2, val3, val4, val5);
4946
4947         DMA_RIWTR1_RD(val0);
4948         DMA_RIWTR0_RD(val1);
4949         DMA_RDRLR7_RD(val2);
4950         DMA_RDRLR6_RD(val3);
4951         DMA_RDRLR5_RD(val4);
4952         DMA_RDRLR4_RD(val5);
4953
4954         pr_debug("dbgpr_regs: DMA_RIWTR1:%#x\n"
4955               "dbgpr_regs: DMA_RIWTR0:%#x\n"
4956               "dbgpr_regs: DMA_RDRLR7:%#x\n"
4957               "dbgpr_regs: DMA_RDRLR6:%#x\n"
4958               "dbgpr_regs: DMA_RDRLR5:%#x\n"
4959               "dbgpr_regs: DMA_RDRLR4:%#x\n",
4960               val0, val1, val2, val3, val4, val5);
4961
4962         DMA_RDRLR3_RD(val0);
4963         DMA_RDRLR2_RD(val1);
4964         DMA_RDRLR1_RD(val2);
4965         DMA_RDRLR0_RD(val3);
4966         DMA_TDRLR7_RD(val4);
4967         DMA_TDRLR6_RD(val5);
4968
4969         pr_debug("dbgpr_regs: DMA_RDRLR3:%#x\n"
4970               "dbgpr_regs: DMA_RDRLR2:%#x\n"
4971               "dbgpr_regs: DMA_RDRLR1:%#x\n"
4972               "dbgpr_regs: DMA_RDRLR0:%#x\n"
4973               "dbgpr_regs: DMA_TDRLR7:%#x\n"
4974               "dbgpr_regs: DMA_TDRLR6:%#x\n",
4975               val0, val1, val2, val3, val4, val5);
4976
4977         DMA_TDRLR5_RD(val0);
4978         DMA_TDRLR4_RD(val1);
4979         DMA_TDRLR3_RD(val2);
4980         DMA_TDRLR2_RD(val3);
4981         DMA_TDRLR1_RD(val4);
4982         DMA_TDRLR0_RD(val5);
4983
4984         pr_debug("dbgpr_regs: DMA_TDRLR5:%#x\n"
4985               "dbgpr_regs: DMA_TDRLR4:%#x\n"
4986               "dbgpr_regs: DMA_TDRLR3:%#x\n"
4987               "dbgpr_regs: DMA_TDRLR2:%#x\n"
4988               "dbgpr_regs: DMA_TDRLR1:%#x\n"
4989               "dbgpr_regs: DMA_TDRLR0:%#x\n",
4990               val0, val1, val2, val3, val4, val5);
4991
4992         DMA_RDTP_RPDR7_RD(val0);
4993         DMA_RDTP_RPDR6_RD(val1);
4994         DMA_RDTP_RPDR5_RD(val2);
4995         DMA_RDTP_RPDR4_RD(val3);
4996         DMA_RDTP_RPDR3_RD(val4);
4997         DMA_RDTP_RPDR2_RD(val5);
4998
4999         pr_debug("dbgpr_regs: DMA_RDTP_RPDR7:%#x\n"
5000               "dbgpr_regs: DMA_RDTP_RPDR6:%#x\n"
5001               "dbgpr_regs: DMA_RDTP_RPDR5:%#x\n"
5002               "dbgpr_regs: DMA_RDTP_RPDR4:%#x\n"
5003               "dbgpr_regs: DMA_RDTP_RPDR3:%#x\n"
5004               "dbgpr_regs: DMA_RDTP_RPDR2:%#x\n",
5005               val0, val1, val2, val3, val4, val5);
5006
5007         DMA_RDTP_RPDR1_RD(val0);
5008         DMA_RDTP_RPDR0_RD(val1);
5009         DMA_TDTP_TPDR7_RD(val2);
5010         DMA_TDTP_TPDR6_RD(val3);
5011         DMA_TDTP_TPDR5_RD(val4);
5012         DMA_TDTP_TPDR4_RD(val5);
5013
5014         pr_debug("dbgpr_regs: DMA_RDTP_RPDR1:%#x\n"
5015               "dbgpr_regs: DMA_RDTP_RPDR0:%#x\n"
5016               "dbgpr_regs: DMA_TDTP_TPDR7:%#x\n"
5017               "dbgpr_regs: DMA_TDTP_TPDR6:%#x\n"
5018               "dbgpr_regs: DMA_TDTP_TPDR5:%#x\n"
5019               "dbgpr_regs: DMA_TDTP_TPDR4:%#x\n",
5020               val0, val1, val2, val3, val4, val5);
5021
5022         DMA_TDTP_TPDR3_RD(val0);
5023         DMA_TDTP_TPDR2_RD(val1);
5024         DMA_TDTP_TPDR1_RD(val2);
5025         DMA_TDTP_TPDR0_RD(val3);
5026         DMA_RDLAR7_RD(val4);
5027         DMA_RDLAR6_RD(val5);
5028
5029         pr_debug("dbgpr_regs: DMA_TDTP_TPDR3:%#x\n"
5030               "dbgpr_regs: DMA_TDTP_TPDR2:%#x\n"
5031               "dbgpr_regs: DMA_TDTP_TPDR1:%#x\n"
5032               "dbgpr_regs: DMA_TDTP_TPDR0:%#x\n"
5033               "dbgpr_regs: DMA_RDLAR7:%#x\n"
5034               "dbgpr_regs: DMA_RDLAR6:%#x\n",
5035               val0, val1, val2, val3, val4, val5);
5036
5037         DMA_RDLAR5_RD(val0);
5038         DMA_RDLAR4_RD(val1);
5039         DMA_RDLAR3_RD(val2);
5040         DMA_RDLAR2_RD(val3);
5041         DMA_RDLAR1_RD(val4);
5042         DMA_RDLAR0_RD(val5);
5043
5044         pr_debug("dbgpr_regs: DMA_RDLAR5:%#x\n"
5045               "dbgpr_regs: DMA_RDLAR4:%#x\n"
5046               "dbgpr_regs: DMA_RDLAR3:%#x\n"
5047               "dbgpr_regs: DMA_RDLAR2:%#x\n"
5048               "dbgpr_regs: DMA_RDLAR1:%#x\n"
5049               "dbgpr_regs: DMA_RDLAR0:%#x\n",
5050               val0, val1, val2, val3, val4, val5);
5051
5052         DMA_TDLAR7_RD(val0);
5053         DMA_TDLAR6_RD(val1);
5054         DMA_TDLAR5_RD(val2);
5055         DMA_TDLAR4_RD(val3);
5056         DMA_TDLAR3_RD(val4);
5057         DMA_TDLAR2_RD(val5);
5058
5059         pr_debug("dbgpr_regs: DMA_TDLAR7:%#x\n"
5060               "dbgpr_regs: DMA_TDLAR6:%#x\n"
5061               "dbgpr_regs: DMA_TDLAR5:%#x\n"
5062               "dbgpr_regs: DMA_TDLAR4:%#x\n"
5063               "dbgpr_regs: DMA_TDLAR3:%#x\n"
5064               "dbgpr_regs: DMA_TDLAR2:%#x\n",
5065               val0, val1, val2, val3, val4, val5);
5066
5067         DMA_TDLAR1_RD(val0);
5068         DMA_TDLAR0_RD(val1);
5069         DMA_IER7_RD(val2);
5070         DMA_IER6_RD(val3);
5071         DMA_IER5_RD(val4);
5072         DMA_IER4_RD(val5);
5073
5074         pr_debug("dbgpr_regs: DMA_TDLAR1:%#x\n"
5075               "dbgpr_regs: DMA_TDLAR0:%#x\n"
5076               "dbgpr_regs: DMA_IER7:%#x\n"
5077               "dbgpr_regs: DMA_IER6:%#x\n"
5078               "dbgpr_regs: DMA_IER5:%#x\n"
5079               "dbgpr_regs: DMA_IER4:%#x\n", val0, val1, val2, val3, val4, val5);
5080
5081         DMA_IER3_RD(val0);
5082         DMA_IER2_RD(val1);
5083         DMA_IER1_RD(val2);
5084         DMA_IER0_RD(val3);
5085         MAC_IMR_RD(val4);
5086         MAC_ISR_RD(val5);
5087
5088         pr_debug("dbgpr_regs: DMA_IER3:%#x\n"
5089               "dbgpr_regs: DMA_IER2:%#x\n"
5090               "dbgpr_regs: DMA_IER1:%#x\n"
5091               "dbgpr_regs: DMA_IER0:%#x\n"
5092               "dbgpr_regs: MAC_IMR:%#x\n"
5093               "dbgpr_regs: MAC_ISR:%#x\n", val0, val1, val2, val3, val4, val5);
5094
5095         MTL_ISR_RD(val0);
5096         DMA_SR7_RD(val1);
5097         DMA_SR6_RD(val2);
5098         DMA_SR5_RD(val3);
5099         DMA_SR4_RD(val4);
5100         DMA_SR3_RD(val5);
5101
5102         pr_debug("dbgpr_regs: MTL_ISR:%#x\n"
5103               "dbgpr_regs: DMA_SR7:%#x\n"
5104               "dbgpr_regs: DMA_SR6:%#x\n"
5105               "dbgpr_regs: DMA_SR5:%#x\n"
5106               "dbgpr_regs: DMA_SR4:%#x\n"
5107               "dbgpr_regs: DMA_SR3:%#x\n", val0, val1, val2, val3, val4, val5);
5108
5109         DMA_SR2_RD(val0);
5110         DMA_SR1_RD(val1);
5111         DMA_SR0_RD(val2);
5112         DMA_ISR_RD(val3);
5113         DMA_DSR2_RD(val4);
5114         DMA_DSR1_RD(val5);
5115
5116         pr_debug("dbgpr_regs: DMA_SR2:%#x\n"
5117               "dbgpr_regs: DMA_SR1:%#x\n"
5118               "dbgpr_regs: DMA_SR0:%#x\n"
5119               "dbgpr_regs: DMA_ISR:%#x\n"
5120               "dbgpr_regs: DMA_DSR2:%#x\n"
5121               "dbgpr_regs: DMA_DSR1:%#x\n", val0, val1, val2, val3, val4, val5);
5122
5123         DMA_DSR0_RD(val0);
5124         MTL_Q0RDR_RD(val1);
5125         MTL_Q0ESR_RD(val2);
5126         MTL_Q0TDR_RD(val3);
5127         DMA_CHRBAR7_RD(val4);
5128         DMA_CHRBAR6_RD(val5);
5129
5130         pr_debug("dbgpr_regs: DMA_DSR0:%#x\n"
5131               "dbgpr_regs: MTL_Q0RDR:%#x\n"
5132               "dbgpr_regs: MTL_Q0ESR:%#x\n"
5133               "dbgpr_regs: MTL_Q0TDR:%#x\n"
5134               "dbgpr_regs: DMA_CHRBAR7:%#x\n"
5135               "dbgpr_regs: DMA_CHRBAR6:%#x\n",
5136               val0, val1, val2, val3, val4, val5);
5137
5138         DMA_CHRBAR5_RD(val0);
5139         DMA_CHRBAR4_RD(val1);
5140         DMA_CHRBAR3_RD(val2);
5141         DMA_CHRBAR2_RD(val3);
5142         DMA_CHRBAR1_RD(val4);
5143         DMA_CHRBAR0_RD(val5);
5144
5145         pr_debug("dbgpr_regs: DMA_CHRBAR5:%#x\n"
5146               "dbgpr_regs: DMA_CHRBAR4:%#x\n"
5147               "dbgpr_regs: DMA_CHRBAR3:%#x\n"
5148               "dbgpr_regs: DMA_CHRBAR2:%#x\n"
5149               "dbgpr_regs: DMA_CHRBAR1:%#x\n"
5150               "dbgpr_regs: DMA_CHRBAR0:%#x\n",
5151               val0, val1, val2, val3, val4, val5);
5152
5153         DMA_CHTBAR7_RD(val0);
5154         DMA_CHTBAR6_RD(val1);
5155         DMA_CHTBAR5_RD(val2);
5156         DMA_CHTBAR4_RD(val3);
5157         DMA_CHTBAR3_RD(val4);
5158         DMA_CHTBAR2_RD(val5);
5159
5160         pr_debug("dbgpr_regs: DMA_CHTBAR7:%#x\n"
5161               "dbgpr_regs: DMA_CHTBAR6:%#x\n"
5162               "dbgpr_regs: DMA_CHTBAR5:%#x\n"
5163               "dbgpr_regs: DMA_CHTBAR4:%#x\n"
5164               "dbgpr_regs: DMA_CHTBAR3:%#x\n"
5165               "dbgpr_regs: DMA_CHTBAR2:%#x\n",
5166               val0, val1, val2, val3, val4, val5);
5167
5168         DMA_CHTBAR1_RD(val0);
5169         DMA_CHTBAR0_RD(val1);
5170         DMA_CHRDR7_RD(val2);
5171         DMA_CHRDR6_RD(val3);
5172         DMA_CHRDR5_RD(val4);
5173         DMA_CHRDR4_RD(val5);
5174
5175         pr_debug("dbgpr_regs: DMA_CHTBAR1:%#x\n"
5176               "dbgpr_regs: DMA_CHTBAR0:%#x\n"
5177               "dbgpr_regs: DMA_CHRDR7:%#x\n"
5178               "dbgpr_regs: DMA_CHRDR6:%#x\n"
5179               "dbgpr_regs: DMA_CHRDR5:%#x\n"
5180               "dbgpr_regs: DMA_CHRDR4:%#x\n",
5181               val0, val1, val2, val3, val4, val5);
5182
5183         DMA_CHRDR3_RD(val0);
5184         DMA_CHRDR2_RD(val1);
5185         DMA_CHRDR1_RD(val2);
5186         DMA_CHRDR0_RD(val3);
5187         DMA_CHTDR7_RD(val4);
5188         DMA_CHTDR6_RD(val5);
5189
5190         pr_debug("dbgpr_regs: DMA_CHRDR3:%#x\n"
5191               "dbgpr_regs: DMA_CHRDR2:%#x\n"
5192               "dbgpr_regs: DMA_CHRDR1:%#x\n"
5193               "dbgpr_regs: DMA_CHRDR0:%#x\n"
5194               "dbgpr_regs: DMA_CHTDR7:%#x\n"
5195               "dbgpr_regs: DMA_CHTDR6:%#x\n",
5196               val0, val1, val2, val3, val4, val5);
5197
5198         DMA_CHTDR5_RD(val0);
5199         DMA_CHTDR4_RD(val1);
5200         DMA_CHTDR3_RD(val2);
5201         DMA_CHTDR2_RD(val3);
5202         DMA_CHTDR1_RD(val4);
5203         DMA_CHTDR0_RD(val5);
5204
5205         pr_debug("dbgpr_regs: DMA_CHTDR5:%#x\n"
5206               "dbgpr_regs: DMA_CHTDR4:%#x\n"
5207               "dbgpr_regs: DMA_CHTDR3:%#x\n"
5208               "dbgpr_regs: DMA_CHTDR2:%#x\n"
5209               "dbgpr_regs: DMA_CHTDR1:%#x\n"
5210               "dbgpr_regs: DMA_CHTDR0:%#x\n",
5211               val0, val1, val2, val3, val4, val5);
5212
5213         DMA_SFCSR7_RD(val0);
5214         DMA_SFCSR6_RD(val1);
5215         DMA_SFCSR5_RD(val2);
5216         DMA_SFCSR4_RD(val3);
5217         DMA_SFCSR3_RD(val4);
5218         DMA_SFCSR2_RD(val5);
5219
5220         pr_debug("dbgpr_regs: DMA_SFCSR7:%#x\n"
5221               "dbgpr_regs: DMA_SFCSR6:%#x\n"
5222               "dbgpr_regs: DMA_SFCSR5:%#x\n"
5223               "dbgpr_regs: DMA_SFCSR4:%#x\n"
5224               "dbgpr_regs: DMA_SFCSR3:%#x\n"
5225               "dbgpr_regs: DMA_SFCSR2:%#x\n",
5226               val0, val1, val2, val3, val4, val5);
5227
5228         DMA_SFCSR1_RD(val0);
5229         DMA_SFCSR0_RD(val1);
5230         MAC_IVLANTIRR_RD(val2);
5231         MAC_VLANTIRR_RD(val3);
5232         MAC_VLANHTR_RD(val4);
5233         MAC_VLANTR_RD(val5);
5234
5235         pr_debug("dbgpr_regs: DMA_SFCSR1:%#x\n"
5236               "dbgpr_regs: DMA_SFCSR0:%#x\n"
5237               "dbgpr_regs: MAC_IVLANTIRR:%#x\n"
5238               "dbgpr_regs: MAC_VLANTIRR:%#x\n"
5239               "dbgpr_regs: MAC_VLANHTR:%#x\n"
5240               "dbgpr_regs: MAC_VLANTR:%#x\n",
5241               val0, val1, val2, val3, val4, val5);
5242
5243         DMA_SBUS_RD(val0);
5244         DMA_BMR_RD(val1);
5245         MTL_Q0RCR_RD(val2);
5246         MTL_Q0OCR_RD(val3);
5247         MTL_Q0ROMR_RD(val4);
5248         MTL_Q0QR_RD(val5);
5249
5250         pr_debug("dbgpr_regs: DMA_SBUS:%#x\n"
5251               "dbgpr_regs: DMA_BMR:%#x\n"
5252               "dbgpr_regs: MTL_Q0RCR:%#x\n"
5253               "dbgpr_regs: MTL_Q0OCR:%#x\n"
5254               "dbgpr_regs: MTL_Q0ROMR:%#x\n"
5255               "dbgpr_regs: MTL_Q0QR:%#x\n", val0, val1, val2, val3, val4, val5);
5256
5257         MTL_Q0ECR_RD(val0);
5258         MTL_Q0UCR_RD(val1);
5259         MTL_Q0TOMR_RD(val2);
5260         MTL_RQDCM1R_RD(val3);
5261         MTL_RQDCM0R_RD(val4);
5262         MTL_FDDR_RD(val5);
5263
5264         pr_debug("dbgpr_regs: MTL_Q0ECR:%#x\n"
5265               "dbgpr_regs: MTL_Q0UCR:%#x\n"
5266               "dbgpr_regs: MTL_Q0TOMR:%#x\n"
5267               "dbgpr_regs: MTL_RQDCM1R:%#x\n"
5268               "dbgpr_regs: MTL_RQDCM0R:%#x\n"
5269               "dbgpr_regs: MTL_FDDR:%#x\n", val0, val1, val2, val3, val4, val5);
5270
5271         MTL_FDACS_RD(val0);
5272         MTL_OMR_RD(val1);
5273         MAC_RQC1R_RD(val2);
5274         MAC_RQC0R_RD(val3);
5275         MAC_TQPM1R_RD(val4);
5276         MAC_TQPM0R_RD(val5);
5277
5278         pr_debug("dbgpr_regs: MTL_FDACS:%#x\n"
5279               "dbgpr_regs: MTL_OMR:%#x\n"
5280               "dbgpr_regs: MAC_RQC1R:%#x\n"
5281               "dbgpr_regs: MAC_RQC0R:%#x\n"
5282               "dbgpr_regs: MAC_TQPM1R:%#x\n"
5283               "dbgpr_regs: MAC_TQPM0R:%#x\n",
5284               val0, val1, val2, val3, val4, val5);
5285
5286         MAC_RFCR_RD(val0);
5287         MAC_QTFCR7_RD(val1);
5288         MAC_QTFCR6_RD(val2);
5289         MAC_QTFCR5_RD(val3);
5290         MAC_QTFCR4_RD(val4);
5291         MAC_QTFCR3_RD(val5);
5292
5293         pr_debug("dbgpr_regs: MAC_RFCR:%#x\n"
5294               "dbgpr_regs: MAC_QTFCR7:%#x\n"
5295               "dbgpr_regs: MAC_QTFCR6:%#x\n"
5296               "dbgpr_regs: MAC_QTFCR5:%#x\n"
5297               "dbgpr_regs: MAC_QTFCR4:%#x\n"
5298               "dbgpr_regs: MAC_QTFCR3:%#x\n",
5299               val0, val1, val2, val3, val4, val5);
5300
5301         MAC_QTFCR2_RD(val0);
5302         MAC_QTFCR1_RD(val1);
5303         MAC_Q0TFCR_RD(val2);
5304         DMA_AXI4CR7_RD(val3);
5305         DMA_AXI4CR6_RD(val4);
5306         DMA_AXI4CR5_RD(val5);
5307
5308         pr_debug("dbgpr_regs: MAC_QTFCR2:%#x\n"
5309               "dbgpr_regs: MAC_QTFCR1:%#x\n"
5310               "dbgpr_regs: MAC_Q0TFCR:%#x\n"
5311               "dbgpr_regs: DMA_AXI4CR7:%#x\n"
5312               "dbgpr_regs: DMA_AXI4CR6:%#x\n"
5313               "dbgpr_regs: DMA_AXI4CR5:%#x\n",
5314               val0, val1, val2, val3, val4, val5);
5315
5316         DMA_AXI4CR4_RD(val0);
5317         DMA_AXI4CR3_RD(val1);
5318         DMA_AXI4CR2_RD(val2);
5319         DMA_AXI4CR1_RD(val3);
5320         DMA_AXI4CR0_RD(val4);
5321         DMA_RCR7_RD(val5);
5322
5323         pr_debug("dbgpr_regs: DMA_AXI4CR4:%#x\n"
5324               "dbgpr_regs: DMA_AXI4CR3:%#x\n"
5325               "dbgpr_regs: DMA_AXI4CR2:%#x\n"
5326               "dbgpr_regs: DMA_AXI4CR1:%#x\n"
5327               "dbgpr_regs: DMA_AXI4CR0:%#x\n"
5328               "dbgpr_regs: DMA_RCR7:%#x\n", val0, val1, val2, val3, val4, val5);
5329
5330         DMA_RCR6_RD(val0);
5331         DMA_RCR5_RD(val1);
5332         DMA_RCR4_RD(val2);
5333         DMA_RCR3_RD(val3);
5334         DMA_RCR2_RD(val4);
5335         DMA_RCR1_RD(val5);
5336
5337         pr_debug("dbgpr_regs: DMA_RCR6:%#x\n"
5338               "dbgpr_regs: DMA_RCR5:%#x\n"
5339               "dbgpr_regs: DMA_RCR4:%#x\n"
5340               "dbgpr_regs: DMA_RCR3:%#x\n"
5341               "dbgpr_regs: DMA_RCR2:%#x\n"
5342               "dbgpr_regs: DMA_RCR1:%#x\n", val0, val1, val2, val3, val4, val5);
5343
5344         DMA_RCR0_RD(val0);
5345         DMA_TCR7_RD(val1);
5346         DMA_TCR6_RD(val2);
5347         DMA_TCR5_RD(val3);
5348         DMA_TCR4_RD(val4);
5349         DMA_TCR3_RD(val5);
5350
5351         pr_debug("dbgpr_regs: DMA_RCR0:%#x\n"
5352               "dbgpr_regs: DMA_TCR7:%#x\n"
5353               "dbgpr_regs: DMA_TCR6:%#x\n"
5354               "dbgpr_regs: DMA_TCR5:%#x\n"
5355               "dbgpr_regs: DMA_TCR4:%#x\n"
5356               "dbgpr_regs: DMA_TCR3:%#x\n", val0, val1, val2, val3, val4, val5);
5357
5358         DMA_TCR2_RD(val0);
5359         DMA_TCR1_RD(val1);
5360         DMA_TCR0_RD(val2);
5361         DMA_CR7_RD(val3);
5362         DMA_CR6_RD(val4);
5363         DMA_CR5_RD(val5);
5364
5365         pr_debug("dbgpr_regs: DMA_TCR2:%#x\n"
5366               "dbgpr_regs: DMA_TCR1:%#x\n"
5367               "dbgpr_regs: DMA_TCR0:%#x\n"
5368               "dbgpr_regs: DMA_CR7:%#x\n"
5369               "dbgpr_regs: DMA_CR6:%#x\n"
5370               "dbgpr_regs: DMA_CR5:%#x\n", val0, val1, val2, val3, val4, val5);
5371
5372         DMA_CR4_RD(val0);
5373         DMA_CR3_RD(val1);
5374         DMA_CR2_RD(val2);
5375         DMA_CR1_RD(val3);
5376         DMA_CR0_RD(val4);
5377         MAC_WTR_RD(val5);
5378
5379         pr_debug("dbgpr_regs: DMA_CR4:%#x\n"
5380               "dbgpr_regs: DMA_CR3:%#x\n"
5381               "dbgpr_regs: DMA_CR2:%#x\n"
5382               "dbgpr_regs: DMA_CR1:%#x\n"
5383               "dbgpr_regs: DMA_CR0:%#x\n"
5384               "dbgpr_regs: MAC_WTR:%#x\n", val0, val1, val2, val3, val4, val5);
5385
5386         MAC_MPFR_RD(val0);
5387         MAC_MECR_RD(val1);
5388         MAC_MCR_RD(val2);
5389
5390         pr_debug("dbgpr_regs: MAC_MPFR:%#x\n"
5391               "dbgpr_regs: MAC_MECR:%#x\n"
5392               "dbgpr_regs: MAC_MCR:%#x\n", val0, val1, val2);
5393
5394         return;
5395 }
5396 #endif
5397
5398 /*!
5399  * \details This function is invoked by eqos_start_xmit and
5400  * process_tx_completions function for dumping the TX descriptor contents
5401  * which are prepared for packet transmission and which are transmitted by
5402  * device. It is mainly used during development phase for debug purpose. Use
5403  * of these function may affect the performance during normal operation.
5404  *
5405  * \param[in] pdata â€“ pointer to private data structure.
5406  * \param[in] first_desc_idx â€“ first descriptor index for the current
5407  *              transfer.
5408  * \param[in] last_desc_idx â€“ last descriptor index for the current transfer.
5409  * \param[in] flag â€“ to indicate from which function it is called.
5410  *
5411  * \return void
5412  */
5413
5414 void dump_tx_desc(struct eqos_prv_data *pdata, int first_desc_idx,
5415                   int last_desc_idx, int flag, UINT qinx)
5416 {
5417         int i;
5418         struct s_tx_desc *desc = NULL;
5419         UINT ctxt;
5420
5421         if (first_desc_idx == last_desc_idx) {
5422                 desc = GET_TX_DESC_PTR(qinx, first_desc_idx);
5423
5424                 TX_NORMAL_DESC_TDES3_CTXT_RD(desc->tdes3, ctxt);
5425
5426                 pr_err("\n%s[%02d %4p %03d %s] = %#x:%#x:%#x:%#x\n",
5427                        (ctxt == 1) ? "TX_CONTXT_DESC" : "ptx_desc",
5428                        qinx, desc, first_desc_idx,
5429                        ((flag == 1) ? "QUEUED FOR TRANSMISSION" :
5430                         ((flag ==
5431                           0) ? "FREED/FETCHED BY DEVICE" : "DEBUG DESC DUMP")),
5432                        desc->tdes0, desc->tdes1, desc->tdes2, desc->tdes3);
5433         } else {
5434                 int lp_cnt;
5435                 if (first_desc_idx > last_desc_idx)
5436                         lp_cnt = last_desc_idx + TX_DESC_CNT - first_desc_idx;
5437                 else
5438                         lp_cnt = last_desc_idx - first_desc_idx;
5439
5440                 for (i = first_desc_idx; lp_cnt >= 0; lp_cnt--) {
5441                         desc = GET_TX_DESC_PTR(qinx, i);
5442
5443                         TX_NORMAL_DESC_TDES3_CTXT_RD(desc->tdes3, ctxt);
5444
5445                         pr_err("\n%s[%02d %4p %03d %s] = %#x:%#x:%#x:%#x\n",
5446                                (ctxt ==
5447                                 1) ? "TX_CONTXT_DESC" : "ptx_desc", qinx,
5448                                desc, i,
5449                                ((flag ==
5450                                  1) ? "QUEUED FOR TRANSMISSION" :
5451                                 "FREED/FETCHED BY DEVICE"), desc->tdes0,
5452                                desc->tdes1, desc->tdes2, desc->tdes3);
5453                         INCR_TX_DESC_INDEX(i, 1);
5454                 }
5455         }
5456 }
5457
5458 /*!
5459  * \details This function is invoked by poll function for dumping the
5460  * RX descriptor contents. It is mainly used during development phase for
5461  * debug purpose. Use of these function may affect the performance during
5462  * normal operation
5463  *
5464  * \param[in] pdata â€“ pointer to private data structure.
5465  *
5466  * \return void
5467  */
5468
5469 void dump_rx_desc(UINT qinx, struct s_rx_desc *desc, int desc_idx)
5470 {
5471         pr_err("\nprx_desc[%02d %4p %03d RECEIVED FROM DEVICE]"
5472                " = %#x:%#x:%#x:%#x",
5473                qinx, desc, desc_idx, desc->rdes0, desc->rdes1,
5474                desc->rdes2, desc->rdes3);
5475 }
5476
5477 /*!
5478  * \details This function is invoked by start_xmit and poll function for
5479  * dumping the content of packet to be transmitted by device or received
5480  * from device. It is mainly used during development phase for debug purpose.
5481  * Use of these functions may affect the performance during normal operation.
5482  *
5483  * \param[in] skb â€“ pointer to socket buffer structure.
5484  * \param[in] len â€“ length of packet to be transmitted/received.
5485  * \param[in] tx_rx â€“ packet to be transmitted or received.
5486  * \param[in] desc_idx â€“ descriptor index to be used for transmission or
5487  *                      reception of packet.
5488  *
5489  * \return void
5490  */
5491
5492 void print_pkt(struct sk_buff *skb, int len, bool tx_rx, int desc_idx)
5493 {
5494         int i, j = 0;
5495         unsigned char *buf = skb->data;
5496
5497         pr_err
5498             ("\n\n/***********************************************************/\n");
5499
5500         pr_err("%s pkt of %d Bytes [DESC index = %d]\n\n",
5501                (tx_rx ? "TX" : "RX"), len, desc_idx);
5502         pr_err("Dst MAC addr(6 bytes)\n");
5503         for (i = 0; i < 6; i++)
5504                 printk("%#.2x%s", buf[i], (((i == 5) ? "" : ":")));
5505         pr_err("\nSrc MAC addr(6 bytes)\n");
5506         for (i = 6; i <= 11; i++)
5507                 printk("%#.2x%s", buf[i], (((i == 11) ? "" : ":")));
5508         i = (buf[12] << 8 | buf[13]);
5509         pr_err("\nType/Length(2 bytes)\n%#x", i);
5510
5511         pr_err("\nPay Load : %d bytes\n", (len - 14));
5512         for (i = 14, j = 1; i < len; i++, j++) {
5513                 printk("%#.2x%s", buf[i], (((i == (len - 1)) ? "" : ":")));
5514                 if ((j % 16) == 0)
5515                         pr_err("");
5516         }
5517
5518         pr_err
5519             ("/*************************************************************/\n\n");
5520 }
5521
5522 /*!
5523  * \details This function is invoked by probe function. This function will
5524  * initialize default receive coalesce parameters and sw timer value and store
5525  * it in respective receive data structure.
5526  *
5527  * \param[in] pdata â€“ pointer to private data structure.
5528  *
5529  * \return void
5530  */
5531
5532 void eqos_init_rx_coalesce(struct eqos_prv_data *pdata)
5533 {
5534         struct rx_ring *prx_ring = NULL;
5535         UINT i;
5536
5537         pr_debug("-->eqos_init_rx_coalesce\n");
5538
5539         for (i = 0; i < EQOS_RX_QUEUE_CNT; i++) {
5540                 prx_ring = GET_RX_WRAPPER_DESC(i);
5541
5542                 prx_ring->use_riwt = 1;
5543                 prx_ring->rx_coal_frames = EQOS_RX_MAX_FRAMES;
5544                 prx_ring->rx_riwt =
5545                     eqos_usec2riwt(EQOS_OPTIMAL_DMA_RIWT_USEC, pdata);
5546         }
5547
5548         pr_debug("<--eqos_init_rx_coalesce\n");
5549 }
5550
5551 /*!
5552  * \details This function is invoked by open() function. This function will
5553  * clear MMC structure.
5554  *
5555  * \param[in] pdata â€“ pointer to private data structure.
5556  *
5557  * \return void
5558  */
5559
5560 static void eqos_mmc_setup(struct eqos_prv_data *pdata)
5561 {
5562         pr_debug("-->eqos_mmc_setup\n");
5563
5564         if (pdata->hw_feat.mmc_sel) {
5565                 memset(&pdata->mmc, 0, sizeof(struct eqos_mmc_counters));
5566         } else
5567                 pr_err("No MMC/RMON module available in the HW\n");
5568
5569         pr_debug("<--eqos_mmc_setup\n");
5570 }
5571
5572 inline unsigned int eqos_reg_read(volatile ULONG *ptr)
5573 {
5574         return ioread32((void *)ptr);
5575 }
5576
5577 /*!
5578  * \details This function is invoked by ethtool function when user wants to
5579  * read MMC counters. This function will read the MMC if supported by core
5580  * and store it in eqos_mmc_counters structure. By default all the
5581  * MMC are programmed "read on reset" hence all the fields of the
5582  * eqos_mmc_counters are incremented.
5583  *
5584  * open() function. This function will
5585  * initialize MMC control register ie it disable all MMC interrupt and all
5586  * MMC register are configured to clear on read.
5587  *
5588  * \param[in] pdata â€“ pointer to private data structure.
5589  *
5590  * \return void
5591  */
5592
5593 void eqos_mmc_read(struct eqos_mmc_counters *mmc)
5594 {
5595         pr_debug("-->eqos_mmc_read\n");
5596
5597         /* MMC TX counter registers */
5598         mmc->mmc_tx_octetcount_gb += eqos_reg_read(MMC_TXOCTETCOUNT_GB_OFFSET);
5599         mmc->mmc_tx_framecount_gb += eqos_reg_read(MMC_TXPACKETCOUNT_GB_OFFSET);
5600         mmc->mmc_tx_broadcastframe_g +=
5601             eqos_reg_read(MMC_TXBROADCASTPACKETS_G_OFFSET);
5602         mmc->mmc_tx_multicastframe_g +=
5603             eqos_reg_read(MMC_TXMULTICASTPACKETS_G_OFFSET);
5604         mmc->mmc_tx_64_octets_gb += eqos_reg_read(MMC_TX64OCTETS_GB_OFFSET);
5605         mmc->mmc_tx_65_to_127_octets_gb +=
5606             eqos_reg_read(MMC_TX65TO127OCTETS_GB_OFFSET);
5607         mmc->mmc_tx_128_to_255_octets_gb +=
5608             eqos_reg_read(MMC_TX128TO255OCTETS_GB_OFFSET);
5609         mmc->mmc_tx_256_to_511_octets_gb +=
5610             eqos_reg_read(MMC_TX256TO511OCTETS_GB_OFFSET);
5611         mmc->mmc_tx_512_to_1023_octets_gb +=
5612             eqos_reg_read(MMC_TX512TO1023OCTETS_GB_OFFSET);
5613         mmc->mmc_tx_1024_to_max_octets_gb +=
5614             eqos_reg_read(MMC_TX1024TOMAXOCTETS_GB_OFFSET);
5615         mmc->mmc_tx_unicast_gb += eqos_reg_read(MMC_TXUNICASTPACKETS_GB_OFFSET);
5616         mmc->mmc_tx_multicast_gb +=
5617             eqos_reg_read(MMC_TXMULTICASTPACKETS_GB_OFFSET);
5618         mmc->mmc_tx_broadcast_gb +=
5619             eqos_reg_read(MMC_TXBROADCASTPACKETS_GB_OFFSET);
5620         mmc->mmc_tx_underflow_error +=
5621             eqos_reg_read(MMC_TXUNDERFLOWERROR_OFFSET);
5622         mmc->mmc_tx_singlecol_g += eqos_reg_read(MMC_TXSINGLECOL_G_OFFSET);
5623         mmc->mmc_tx_multicol_g += eqos_reg_read(MMC_TXMULTICOL_G_OFFSET);
5624         mmc->mmc_tx_deferred += eqos_reg_read(MMC_TXDEFERRED_OFFSET);
5625         mmc->mmc_tx_latecol += eqos_reg_read(MMC_TXLATECOL_OFFSET);
5626         mmc->mmc_tx_exesscol += eqos_reg_read(MMC_TXEXESSCOL_OFFSET);
5627         mmc->mmc_tx_carrier_error += eqos_reg_read(MMC_TXCARRIERERROR_OFFSET);
5628         mmc->mmc_tx_octetcount_g += eqos_reg_read(MMC_TXOCTETCOUNT_G_OFFSET);
5629         mmc->mmc_tx_framecount_g += eqos_reg_read(MMC_TXPACKETSCOUNT_G_OFFSET);
5630         mmc->mmc_tx_excessdef += eqos_reg_read(MMC_TXEXCESSDEF_OFFSET);
5631         mmc->mmc_tx_pause_frame += eqos_reg_read(MMC_TXPAUSEPACKETS_OFFSET);
5632         mmc->mmc_tx_vlan_frame_g += eqos_reg_read(MMC_TXVLANPACKETS_G_OFFSET);
5633         mmc->mmc_tx_osize_frame_g += eqos_reg_read(MMC_TXOVERSIZE_G_OFFSET);
5634
5635         /* MMC RX counter registers */
5636         mmc->mmc_rx_framecount_gb += eqos_reg_read(MMC_RXPACKETCOUNT_GB_OFFSET);
5637         mmc->mmc_rx_octetcount_gb += eqos_reg_read(MMC_RXOCTETCOUNT_GB_OFFSET);
5638         mmc->mmc_rx_octetcount_g += eqos_reg_read(MMC_RXOCTETCOUNT_G_OFFSET);
5639         mmc->mmc_rx_broadcastframe_g +=
5640             eqos_reg_read(MMC_RXBROADCASTPACKETS_G_OFFSET);
5641         mmc->mmc_rx_multicastframe_g +=
5642             eqos_reg_read(MMC_RXMULTICASTPACKETS_G_OFFSET);
5643         mmc->mmc_rx_crc_errror += eqos_reg_read(MMC_RXCRCERROR_OFFSET);
5644         mmc->mmc_rx_align_error += eqos_reg_read(MMC_RXALIGNMENTERROR_OFFSET);
5645         mmc->mmc_rx_run_error += eqos_reg_read(MMC_RXRUNTERROR_OFFSET);
5646         mmc->mmc_rx_jabber_error += eqos_reg_read(MMC_RXJABBERERROR_OFFSET);
5647         mmc->mmc_rx_undersize_g += eqos_reg_read(MMC_RXUNDERSIZE_G_OFFSET);
5648         mmc->mmc_rx_oversize_g += eqos_reg_read(MMC_RXOVERSIZE_G_OFFSET);
5649         mmc->mmc_rx_64_octets_gb += eqos_reg_read(MMC_RX64OCTETS_GB_OFFSET);
5650         mmc->mmc_rx_65_to_127_octets_gb +=
5651             eqos_reg_read(MMC_RX65TO127OCTETS_GB_OFFSET);
5652         mmc->mmc_rx_128_to_255_octets_gb +=
5653             eqos_reg_read(MMC_RX128TO255OCTETS_GB_OFFSET);
5654         mmc->mmc_rx_256_to_511_octets_gb +=
5655             eqos_reg_read(MMC_RX256TO511OCTETS_GB_OFFSET);
5656         mmc->mmc_rx_512_to_1023_octets_gb +=
5657             eqos_reg_read(MMC_RX512TO1023OCTETS_GB_OFFSET);
5658         mmc->mmc_rx_1024_to_max_octets_gb +=
5659             eqos_reg_read(MMC_RX1024TOMAXOCTETS_GB_OFFSET);
5660         mmc->mmc_rx_unicast_g += eqos_reg_read(MMC_RXUNICASTPACKETS_G_OFFSET);
5661         mmc->mmc_rx_length_error += eqos_reg_read(MMC_RXLENGTHERROR_OFFSET);
5662         mmc->mmc_rx_outofrangetype +=
5663             eqos_reg_read(MMC_RXOUTOFRANGETYPE_OFFSET);
5664         mmc->mmc_rx_pause_frames += eqos_reg_read(MMC_RXPAUSEPACKETS_OFFSET);
5665         mmc->mmc_rx_fifo_overflow += eqos_reg_read(MMC_RXFIFOOVERFLOW_OFFSET);
5666         mmc->mmc_rx_vlan_frames_gb +=
5667             eqos_reg_read(MMC_RXVLANPACKETS_GB_OFFSET);
5668         mmc->mmc_rx_watchdog_error += eqos_reg_read(MMC_RXWATCHDOGERROR_OFFSET);
5669         mmc->mmc_rx_receive_error += eqos_reg_read(MMC_RXRCVERROR_OFFSET);
5670         mmc->mmc_rx_ctrl_frames_g += eqos_reg_read(MMC_RXCTRLPACKETS_G_OFFSET);
5671
5672         /* IPC */
5673         mmc->mmc_rx_ipc_intr_mask += eqos_reg_read(MMC_IPC_INTR_MASK_RX_OFFSET);
5674         mmc->mmc_rx_ipc_intr += eqos_reg_read(MMC_IPC_INTR_RX_OFFSET);
5675
5676         /* IPv4 */
5677         mmc->mmc_rx_ipv4_gd += eqos_reg_read(MMC_RXIPV4_GD_PKTS_OFFSET);
5678         mmc->mmc_rx_ipv4_hderr += eqos_reg_read(MMC_RXIPV4_HDRERR_PKTS_OFFSET);
5679         mmc->mmc_rx_ipv4_nopay += eqos_reg_read(MMC_RXIPV4_NOPAY_PKTS_OFFSET);
5680         mmc->mmc_rx_ipv4_frag += eqos_reg_read(MMC_RXIPV4_FRAG_PKTS_OFFSET);
5681         mmc->mmc_rx_ipv4_udsbl += eqos_reg_read(MMC_RXIPV4_UBSBL_PKTS_OFFSET);
5682
5683         /* IPV6 */
5684         mmc->mmc_rx_ipv6_gd += eqos_reg_read(MMC_RXIPV6_GD_PKTS_OFFSET);
5685         mmc->mmc_rx_ipv6_hderr += eqos_reg_read(MMC_RXIPV6_HDRERR_PKTS_OFFSET);
5686         mmc->mmc_rx_ipv6_nopay += eqos_reg_read(MMC_RXIPV6_NOPAY_PKTS_OFFSET);
5687
5688         /* Protocols */
5689         mmc->mmc_rx_udp_gd += eqos_reg_read(MMC_RXUDP_GD_PKTS_OFFSET);
5690         mmc->mmc_rx_udp_err += eqos_reg_read(MMC_RXUDP_ERR_PKTS_OFFSET);
5691         mmc->mmc_rx_tcp_gd += eqos_reg_read(MMC_RXTCP_GD_PKTS_OFFSET);
5692         mmc->mmc_rx_tcp_err += eqos_reg_read(MMC_RXTCP_ERR_PKTS_OFFSET);
5693         mmc->mmc_rx_icmp_gd += eqos_reg_read(MMC_RXICMP_GD_PKTS_OFFSET);
5694         mmc->mmc_rx_icmp_err += eqos_reg_read(MMC_RXICMP_ERR_PKTS_OFFSET);
5695
5696         /* IPv4 */
5697         mmc->mmc_rx_ipv4_gd_octets +=
5698             eqos_reg_read(MMC_RXIPV4_GD_OCTETS_OFFSET);
5699         mmc->mmc_rx_ipv4_hderr_octets +=
5700             eqos_reg_read(MMC_RXIPV4_HDRERR_OCTETS_OFFSET);
5701         mmc->mmc_rx_ipv4_nopay_octets +=
5702             eqos_reg_read(MMC_RXIPV4_NOPAY_OCTETS_OFFSET);
5703         mmc->mmc_rx_ipv4_frag_octets +=
5704             eqos_reg_read(MMC_RXIPV4_FRAG_OCTETS_OFFSET);
5705         mmc->mmc_rx_ipv4_udsbl_octets +=
5706             eqos_reg_read(MMC_RXIPV4_UDSBL_OCTETS_OFFSET);
5707
5708         /* IPV6 */
5709         mmc->mmc_rx_ipv6_gd_octets +=
5710             eqos_reg_read(MMC_RXIPV6_GD_OCTETS_OFFSET);
5711         mmc->mmc_rx_ipv6_hderr_octets +=
5712             eqos_reg_read(MMC_RXIPV6_HDRERR_OCTETS_OFFSET);
5713         mmc->mmc_rx_ipv6_nopay_octets +=
5714             eqos_reg_read(MMC_RXIPV6_NOPAY_OCTETS_OFFSET);
5715
5716         /* Protocols */
5717         mmc->mmc_rx_udp_gd_octets += eqos_reg_read(MMC_RXUDP_GD_OCTETS_OFFSET);
5718         mmc->mmc_rx_udp_err_octets +=
5719             eqos_reg_read(MMC_RXUDP_ERR_OCTETS_OFFSET);
5720         mmc->mmc_rx_tcp_gd_octets += eqos_reg_read(MMC_RXTCP_GD_OCTETS_OFFSET);
5721         mmc->mmc_rx_tcp_err_octets +=
5722             eqos_reg_read(MMC_RXTCP_ERR_OCTETS_OFFSET);
5723         mmc->mmc_rx_icmp_gd_octets +=
5724             eqos_reg_read(MMC_RXICMP_GD_OCTETS_OFFSET);
5725         mmc->mmc_rx_icmp_err_octets +=
5726             eqos_reg_read(MMC_RXICMP_ERR_OCTETS_OFFSET);
5727
5728         pr_debug("<--eqos_mmc_read\n");
5729 }
5730
5731 static const struct net_device_ops eqos_netdev_ops = {
5732         .ndo_open = eqos_open,
5733         .ndo_stop = eqos_close,
5734         .ndo_start_xmit = eqos_start_xmit,
5735         .ndo_get_stats = eqos_get_stats,
5736         .ndo_set_rx_mode = eqos_set_rx_mode,
5737         .ndo_set_features = eqos_set_features,
5738         .ndo_do_ioctl = eqos_ioctl,
5739         .ndo_change_mtu = eqos_change_mtu,
5740 #ifdef EQOS_QUEUE_SELECT_ALGO
5741         .ndo_select_queue = eqos_select_queue,
5742 #endif
5743         .ndo_vlan_rx_add_vid = eqos_vlan_rx_add_vid,
5744         .ndo_vlan_rx_kill_vid = eqos_vlan_rx_kill_vid,
5745         .ndo_set_mac_address = eqos_set_mac_address,
5746 };
5747
5748 struct net_device_ops *eqos_get_netdev_ops(void)
5749 {
5750         return (struct net_device_ops *)&eqos_netdev_ops;
5751 }
5752
5753
5754 static void eqos_disable_all_irqs(struct eqos_prv_data *pdata)
5755 {
5756         struct hw_if_struct *hw_if = &pdata->hw_if;
5757         int i;
5758
5759         pr_debug("-->%s()\n", __func__);
5760
5761         for (i = 0; i < pdata->num_chans; i++)
5762                 hw_if->disable_chan_interrupts(i, pdata);
5763
5764         /* disable mac interrupts */
5765         MAC_IMR_WR(0);
5766
5767         /* ensure irqs are not executing */
5768         synchronize_irq(pdata->common_irq);
5769         for (i = 0; i < pdata->num_chans; i++) {
5770                 if (pdata->rx_irq_alloc_mask & (1 << i))
5771                         synchronize_irq(pdata->rx_irqs[i]);
5772                 if (pdata->tx_irq_alloc_mask & (1 << i))
5773                         synchronize_irq(pdata->tx_irqs[i]);
5774         }
5775
5776         pr_debug("<--%s()\n", __func__);
5777 }
5778
5779 void eqos_stop_dev(struct eqos_prv_data *pdata)
5780 {
5781         struct hw_if_struct *hw_if = &pdata->hw_if;
5782         struct desc_if_struct *desc_if = &pdata->desc_if;
5783         int i;
5784
5785         pr_debug("-->%s()\n", __func__);
5786
5787 #ifdef CONFIG_TEGRA_PTP_NOTIFIER
5788         /* Unregister broadcasting MAC timestamp to clients */
5789         tegra_unregister_hwtime_source();
5790 #endif
5791
5792         if (pdata->phydev && pdata->phydev->drv &&
5793             pdata->phydev->drv->low_power_mode) {
5794                 pdata->phydev->drv->low_power_mode(pdata->phydev, true);
5795                 if (!pdata->suspended)
5796                         phy_stop_interrupts(pdata->phydev);
5797         } else if (pdata->phydev) {
5798                 /* stop the PHY */
5799                 phy_stop(pdata->phydev);
5800                 gpio_set_value(pdata->phy_reset_gpio, 0);
5801         }
5802
5803         /* Stop the PHY state machine */
5804         if (pdata->phydev)
5805                 phy_stop_machine(pdata->phydev);
5806
5807         /* turn off sources of data into dev */
5808         netif_tx_disable(pdata->dev);
5809
5810         hw_if->stop_mac_rx();
5811         eqos_disable_all_irqs(pdata);
5812         eqos_all_ch_napi_disable(pdata);
5813
5814         /* Ensure no tx thread is running.  We have
5815          * already prevented any new callers of or tx thread above.
5816          * Below will allow any remaining tx threads to complete.
5817          */
5818         for (i = 0; i < pdata->num_chans; i++) {
5819                 spin_lock(&pdata->chinfo[i].chan_tx_lock);
5820                 spin_unlock(&pdata->chinfo[i].chan_tx_lock);
5821         }
5822
5823         /* stop DMA TX */
5824         eqos_stop_all_ch_tx_dma(pdata);
5825
5826         /* disable MAC TX */
5827         hw_if->stop_mac_tx();
5828
5829         /* stop DMA RX */
5830         eqos_stop_all_ch_rx_dma(pdata);
5831
5832         del_timer_sync(&pdata->eee_ctrl_timer);
5833
5834         /* return tx skbs */
5835         desc_if->tx_skb_free_mem(pdata, pdata->num_chans);
5836
5837         /* free rx skb's */
5838         desc_if->rx_skb_free_mem(pdata, pdata->num_chans);
5839
5840         pr_debug("<--%s()\n", __func__);
5841 }
5842
5843 void eqos_start_dev(struct eqos_prv_data *pdata)
5844 {
5845         struct hw_if_struct *hw_if = &pdata->hw_if;
5846         struct desc_if_struct *desc_if = &pdata->desc_if;
5847
5848         pr_debug("-->%s()\n", __func__);
5849
5850         if (pdata->phydev->drv->low_power_mode) {
5851                 /* reset the PHY Broadcom PHY needs minimum of 2us delay */
5852                 pr_debug("%s(): exit from iddq-lp mode\n", __func__);
5853                 gpio_set_value(pdata->phy_reset_gpio, 0);
5854                 usleep_range(10, 11);
5855                 gpio_set_value(pdata->phy_reset_gpio, 1);
5856                 pdata->phydev->drv->low_power_mode(pdata->phydev, false);
5857         } else if (!gpio_get_value(pdata->phy_reset_gpio))
5858         {
5859                 /* deassert phy reset */
5860                 gpio_set_value(pdata->phy_reset_gpio, 1);
5861         }
5862
5863         /* issue CAR reset to device */
5864         hw_if->car_reset(pdata);
5865         hw_if->pad_calibrate(pdata);
5866
5867         if (pdata->phydev->drv->low_power_mode) {
5868                 if (pdata->suspended == 0 && netif_running(pdata->dev))
5869                         phy_start_interrupts(pdata->phydev);
5870         }
5871
5872         /* default configuration */
5873         eqos_default_common_confs(pdata);
5874         eqos_default_tx_confs(pdata);
5875         eqos_default_rx_confs(pdata);
5876         eqos_configure_rx_fun_ptr(pdata);
5877
5878         desc_if->wrapper_tx_desc_init(pdata);
5879         desc_if->wrapper_rx_desc_init(pdata);
5880
5881         eqos_napi_enable_mq(pdata);
5882
5883         eqos_set_rx_mode(pdata->dev);
5884         eqos_mmc_setup(pdata);
5885
5886         /* initializes MAC and DMA */
5887         hw_if->init(pdata);
5888
5889         MAC_1US_TIC_WR(pdata->csr_clock_speed - 1);
5890
5891         if (pdata->hw_feat.pcs_sel)
5892                 hw_if->control_an(1, 0);
5893
5894         if (pdata->phydev) {
5895                 pdata->oldlink = 0;
5896                 pdata->speed = 0;
5897                 pdata->oldduplex = -1;
5898
5899                 phy_start(pdata->phydev);
5900                 phy_start_machine(pdata->phydev);
5901         }
5902 #ifdef EQOS_ENABLE_EEE
5903         if (pdata->phydev)
5904                 pdata->eee_enabled = eqos_eee_init(pdata);
5905         else
5906                 pdata->eee_enabled = false;
5907 #else
5908         pdata->eee_enabled = false;
5909 #endif
5910
5911         if (pdata->phydev)
5912                 netif_tx_start_all_queues(pdata->dev);
5913
5914         pr_debug("<--%s()\n", __func__);
5915 }
5916
5917 void eqos_iso_work(struct work_struct *work)
5918 {
5919         struct eqos_prv_data *pdata =
5920             container_of(work, struct eqos_prv_data, iso_work);
5921         struct phy_device *phydev = pdata->phydev;
5922         struct eqos_cfg *pdt_cfg = (struct eqos_cfg *)&pdata->dt_cfg;
5923         int ret;
5924         uint iso_bw;
5925
5926         pr_debug("-->%s()\n", __func__);
5927
5928         if (pdt_cfg->eth_iso_enable) {
5929                 if (phydev->link)
5930                         iso_bw = pdata->dt_cfg.iso_bw;
5931                 else
5932                         iso_bw = 0;
5933
5934                 ret = tegra_isomgr_reserve(pdata->isomgr_handle, iso_bw, 0);
5935                 if (!ret) {
5936                         dev_err(&pdata->pdev->dev,
5937                                 "EQOS ISO BW %d reservation failed with %d\n",
5938                                 iso_bw, ret);
5939                         return;
5940                 }
5941
5942                 ret = tegra_isomgr_realize(pdata->isomgr_handle);
5943                 if (!ret)
5944                         dev_err(&pdata->pdev->dev,
5945                                 "EQOS ISO BW realize failed with %d\n", ret);
5946         }
5947
5948         pr_debug("<--%s()\n", __func__);
5949 }
5950 void eqos_fbe_work(struct work_struct *work)
5951 {
5952         struct eqos_prv_data *pdata =
5953             container_of(work, struct eqos_prv_data, fbe_work);
5954         int i;
5955         u32 dma_sr_reg;
5956
5957         pr_debug("-->%s()\n", __func__);
5958
5959         mutex_lock(&pdata->hw_change_lock);
5960         if (pdata->hw_stopped)
5961                 goto out;
5962
5963         i = 0;
5964         while (pdata->fbe_chan_mask) {
5965                 if (pdata->fbe_chan_mask & 1) {
5966                         DMA_SR_RD(i, dma_sr_reg);
5967
5968                         dev_err(&pdata->pdev->dev,
5969                                 "Fatal Bus Error on chan %d, SRreg=0x%.8x\n",
5970                                 i, dma_sr_reg);
5971                 }
5972                 pdata->fbe_chan_mask >>= 1;
5973                 i++;
5974         }
5975         eqos_stop_dev(pdata);
5976         eqos_start_dev(pdata);
5977 out:
5978         mutex_unlock(&pdata->hw_change_lock);
5979
5980         pr_debug("<--%s()\n", __func__);
5981 }