]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - drivers/net/ethernet/nvidia/eqos/drv.c
net: eqos: Register PTP callback at correct place
[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                 DBGPR_PTP("-->eqos registering get_ptp function\n");
3947                 /* Register broadcasting MAC timestamp to clients */
3948                 tegra_register_hwtime_source(hw_if->get_systime);
3949         }
3950
3951         DBGPR_PTP("config.flags = %#x, tx_type = %#x, rx_filter = %#x\n",
3952                   config.flags, config.tx_type, config.rx_filter);
3953
3954         DBGPR_PTP("<--eqos_handle_hwtstamp_ioctl\n");
3955
3956         return (copy_to_user(ifr->ifr_data, &config,
3957                              sizeof(struct hwtstamp_config))) ? -EFAULT : 0;
3958 }
3959
3960 /*!
3961  * \brief Driver IOCTL routine
3962  *
3963  * \details This function is invoked by kernel when a user request an ioctl
3964  * which can't be handled by the generic interface code. Following operations
3965  * are performed in this functions.
3966  * - Configuring the PMT module.
3967  * - Configuring TX and RX PBL.
3968  * - Configuring the TX and RX FIFO threshold level.
3969  * - Configuring the TX and RX OSF mode.
3970  *
3971  * \param[in] dev â€“ pointer to net device structure.
3972  * \param[in] ifr â€“ pointer to IOCTL specific structure.
3973  * \param[in] cmd â€“ IOCTL command.
3974  *
3975  * \return int
3976  *
3977  * \retval 0 - success
3978  * \retval negative - failure
3979  */
3980
3981 static int eqos_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
3982 {
3983         struct eqos_prv_data *pdata = netdev_priv(dev);
3984         struct ifr_data_struct *req = ifr->ifr_ifru.ifru_data;
3985         struct mii_ioctl_data *data = if_mii(ifr);
3986         unsigned int reg_val = 0;
3987         int ret = 0;
3988
3989         pr_debug("-->eqos_ioctl\n");
3990
3991         if ((!netif_running(dev)) || (!pdata->phydev)) {
3992                 pr_debug("<--eqos_ioctl - error\n");
3993                 return -EINVAL;
3994         }
3995
3996         spin_lock(&pdata->lock);
3997         switch (cmd) {
3998         case SIOCGMIIPHY:
3999                 data->phy_id = pdata->phyaddr;
4000                 pr_err("PHY ID: SIOCGMIIPHY\n");
4001                 break;
4002
4003         case SIOCGMIIREG:
4004                 ret =
4005                     eqos_mdio_read_direct(pdata, pdata->phyaddr,
4006                                           (data->reg_num & 0x1F), &reg_val);
4007                 if (ret)
4008                         ret = -EIO;
4009
4010                 data->val_out = reg_val;
4011                 pr_err("PHY ID: SIOCGMIIREG reg:%#x reg_val:%#x\n",
4012                        (data->reg_num & 0x1F), reg_val);
4013                 break;
4014
4015         case SIOCSMIIREG:
4016                 pr_err("PHY ID: SIOCSMIIPHY\n");
4017                 break;
4018
4019         case EQOS_PRV_IOCTL:
4020                 ret = eqos_handle_prv_ioctl(pdata, req);
4021                 req->command_error = ret;
4022                 break;
4023
4024         case EQOS_PRV_TS_IOCTL:
4025                 ret = eqos_handle_prv_ts_ioctl(pdata, ifr);
4026                 break;
4027
4028         case SIOCSHWTSTAMP:
4029                 ret = eqos_handle_hwtstamp_ioctl(pdata, ifr);
4030                 break;
4031
4032         default:
4033                 ret = -EOPNOTSUPP;
4034                 pr_err("Unsupported IOCTL call\n");
4035         }
4036         spin_unlock(&pdata->lock);
4037
4038         pr_debug("<--eqos_ioctl\n");
4039
4040         return ret;
4041 }
4042
4043 /*!
4044 * \brief API to change MTU.
4045 *
4046 * \details This function is invoked by upper layer when user changes
4047 * MTU (Maximum Transfer Unit). The MTU is used by the Network layer
4048 * to driver packet transmission. Ethernet has a default MTU of
4049 * 1500Bytes. This value can be changed with ifconfig -
4050 * ifconfig <interface_name> mtu <new_mtu_value>
4051 *
4052 * \param[in] dev - pointer to net_device structure
4053 * \param[in] new_mtu - the new MTU for the device.
4054 *
4055 * \return integer
4056 *
4057 * \retval 0 - on success and -ve on failure.
4058 */
4059
4060 static INT eqos_change_mtu(struct net_device *dev, INT new_mtu)
4061 {
4062         struct eqos_prv_data *pdata = netdev_priv(dev);
4063         struct platform_device *pdev = pdata->pdev;
4064         int max_frame = (new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
4065
4066         pr_debug("-->eqos_change_mtu: new_mtu:%d\n", new_mtu);
4067
4068 #ifdef EQOS_CONFIG_PGTEST
4069         dev_err(&pdev->dev, "jumbo frames not supported with PG test\n");
4070         return -EOPNOTSUPP;
4071 #endif
4072         if (pdata->dt_cfg.use_multi_q) {
4073                 dev_err(&pdev->dev,
4074                         "mtu cannot be modified in multi queue mode\n");
4075                 return -EOPNOTSUPP;
4076         }
4077         if ((new_mtu != 1500) && (new_mtu != 4074) && (new_mtu != 9000)) {
4078                 dev_err(&pdev->dev, "valid mtus are 1500, 4074, or 9000\n");
4079                 return -EINVAL;
4080         }
4081         if (max_frame > (pdata->dt_cfg.phy_max_frame_size)) {
4082                 dev_err(&pdev->dev, "mtu exceeds phy max frame size of %d",
4083                         pdata->dt_cfg.phy_max_frame_size);
4084                 return -EINVAL;
4085         }
4086         if (dev->mtu == new_mtu) {
4087                 dev_err(&pdev->dev, "already configured to mtu %d\n", new_mtu);
4088                 return 0;
4089         }
4090
4091         dev_info(&pdev->dev, "changing MTU from %d to %d\n", dev->mtu, new_mtu);
4092
4093         mutex_lock(&pdata->hw_change_lock);
4094         if (!pdata->hw_stopped)
4095                 eqos_stop_dev(pdata);
4096
4097         if (max_frame <= 2048) {
4098                 pdata->rx_buffer_len = 2048;
4099         } else {
4100                 pdata->rx_buffer_len = ALIGN_SIZE(max_frame);
4101         }
4102         pdata->rx_max_frame_size = max_frame;
4103
4104         dev->mtu = new_mtu;
4105
4106         if (!pdata->hw_stopped)
4107                 eqos_start_dev(pdata);
4108
4109         mutex_unlock(&pdata->hw_change_lock);
4110
4111         pr_debug("<--eqos_change_mtu\n");
4112
4113         return 0;
4114 }
4115
4116 #ifdef EQOS_QUEUE_SELECT_ALGO
4117 u16 eqos_select_queue(struct net_device *dev,
4118                       struct sk_buff *skb, void *accel_priv,
4119                       select_queue_fallback_t fallback)
4120 {
4121         int  txqueue_select = -1;
4122         struct eqos_prv_data *pdata = netdev_priv(dev);
4123         struct eqos_cfg *pdt_cfg = (struct eqos_cfg *)&pdata->dt_cfg;
4124         UINT i;
4125
4126         pr_debug("-->eqos_select_queue\n");
4127
4128         for (i = 0; i <= EQOS_TX_QUEUE_CNT; i++) {
4129                 if (pdt_cfg->q_prio[i] == skb->priority) {
4130                         txqueue_select = i;
4131                         break;
4132                 }
4133         }
4134
4135         if (txqueue_select < 0)
4136                 txqueue_select = 0;
4137
4138         pr_debug("<--eqos_select_queue txqueue-select:%d\n", txqueue_select);
4139
4140         return txqueue_select;
4141 }
4142 #endif
4143
4144 unsigned int crc32_snps_le(unsigned int initval, unsigned char *data,
4145                            unsigned int size)
4146 {
4147         unsigned int crc = initval;
4148         unsigned int poly = 0x04c11db7;
4149         unsigned int temp = 0;
4150         unsigned char my_data = 0;
4151         int bit_count;
4152         for (bit_count = 0; bit_count < size; bit_count++) {
4153                 if ((bit_count % 8) == 0)
4154                         my_data = data[bit_count / 8];
4155                 DBGPR_FILTER("%s my_data = %x crc=%x\n", __func__, my_data,
4156                              crc);
4157                 temp = ((crc >> 31) ^ my_data) & 0x1;
4158                 crc <<= 1;
4159                 if (temp != 0)
4160                         crc ^= poly;
4161                 my_data >>= 1;
4162         }
4163         DBGPR_FILTER("%s my_data = %x crc=%x\n", __func__, my_data, crc);
4164         return ~crc;
4165 }
4166
4167 /*!
4168 * \brief API to delete vid to HW filter.
4169 *
4170 * \details This function is invoked by upper layer when a VLAN id is removed.
4171 * This function deletes the VLAN id from the HW filter.
4172 * vlan id can be removed with vconfig -
4173 * vconfig rem <interface_name > <vlan_id>
4174 *
4175 * \param[in] dev - pointer to net_device structure
4176 * \param[in] vid - vlan id to be removed.
4177 *
4178 * \return void
4179 */
4180 static int eqos_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
4181 {
4182         struct eqos_prv_data *pdata = netdev_priv(dev);
4183         struct hw_if_struct *hw_if = &(pdata->hw_if);
4184         unsigned short new_index, old_index;
4185         int crc32_val = 0;
4186         unsigned int enb_12bit_vhash;
4187
4188         pr_err("-->eqos_vlan_rx_kill_vid: vid = %d\n", vid);
4189
4190         if (pdata->vlan_hash_filtering) {
4191                 crc32_val =
4192                     (bitrev32(~crc32_le(~0, (unsigned char *)&vid, 2)) >> 28);
4193
4194                 enb_12bit_vhash = hw_if->get_vlan_tag_comparison();
4195                 if (enb_12bit_vhash) {
4196                         /* neget 4-bit crc value for 12-bit VLAN hash comparison */
4197                         new_index = (1 << (~crc32_val & 0xF));
4198                 } else {
4199                         new_index = (1 << (crc32_val & 0xF));
4200                 }
4201
4202                 old_index = hw_if->get_vlan_hash_table_reg();
4203                 old_index &= ~new_index;
4204                 hw_if->update_vlan_hash_table_reg(old_index);
4205                 pdata->vlan_ht_or_id = old_index;
4206         } else {
4207                 /* By default, receive only VLAN pkt with VID = 1
4208                  * becasue writting 0 will pass all VLAN pkt */
4209                 hw_if->update_vlan_id(1);
4210                 pdata->vlan_ht_or_id = 1;
4211         }
4212
4213         pr_err("<--eqos_vlan_rx_kill_vid\n");
4214
4215         /* FIXME: Check if any errors need to be returned in case of failure */
4216         return 0;
4217 }
4218
4219 static int eqos_set_mac_address(struct net_device *dev, void *p)
4220 {
4221         if (is_valid_ether_addr(dev->dev_addr))
4222                 return -EOPNOTSUPP;
4223         else
4224                 return eth_mac_addr(dev, p);
4225 }
4226
4227 /*!
4228 * \brief API to add vid to HW filter.
4229 *
4230 * \details This function is invoked by upper layer when a new VALN id is
4231 * registered. This function updates the HW filter with new VLAN id.
4232 * New vlan id can be added with vconfig -
4233 * vconfig add <interface_name > <vlan_id>
4234 *
4235 * \param[in] dev - pointer to net_device structure
4236 * \param[in] vid - new vlan id.
4237 *
4238 * \return void
4239 */
4240 static int eqos_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
4241 {
4242         struct eqos_prv_data *pdata = netdev_priv(dev);
4243         struct hw_if_struct *hw_if = &(pdata->hw_if);
4244         unsigned short new_index, old_index;
4245         int crc32_val = 0;
4246         unsigned int enb_12bit_vhash;
4247
4248         pr_err("-->eqos_vlan_rx_add_vid: vid = %d\n", vid);
4249
4250         if (pdata->vlan_hash_filtering) {
4251                 /* The upper 4 bits of the calculated CRC are used to
4252                  * index the content of the VLAN Hash Table Reg.
4253                  * */
4254                 crc32_val =
4255                     (bitrev32(~crc32_le(~0, (unsigned char *)&vid, 2)) >> 28);
4256
4257                 /* These 4(0xF) bits determines the bit within the
4258                  * VLAN Hash Table Reg 0
4259                  * */
4260                 enb_12bit_vhash = hw_if->get_vlan_tag_comparison();
4261                 if (enb_12bit_vhash) {
4262                         /* neget 4-bit crc value for 12-bit VLAN hash comparison */
4263                         new_index = (1 << (~crc32_val & 0xF));
4264                 } else {
4265                         new_index = (1 << (crc32_val & 0xF));
4266                 }
4267
4268                 old_index = hw_if->get_vlan_hash_table_reg();
4269                 old_index |= new_index;
4270                 hw_if->update_vlan_hash_table_reg(old_index);
4271                 pdata->vlan_ht_or_id = old_index;
4272         } else {
4273                 hw_if->update_vlan_id(vid);
4274                 pdata->vlan_ht_or_id = vid;
4275         }
4276
4277         pr_err("<--eqos_vlan_rx_add_vid\n");
4278
4279         /* FIXME: Check if any errors need to be returned in case of failure */
4280         return 0;
4281 }
4282
4283 /*!
4284  * \brief API called to put device in powerdown mode
4285  *
4286  * \details This function is invoked by ioctl function when the user issues an
4287  * ioctl command to move the device to power down state. Following operations
4288  * are performed in this function.
4289  * - stop the phy.
4290  * - stop the queue.
4291  * - Disable napi.
4292  * - Stop DMA TX and RX process.
4293  * - Enable power down mode using PMT module.
4294  *
4295  * \param[in] dev â€“ pointer to net device structure.
4296  * \param[in] wakeup_type â€“ remote wake-on-lan or magic packet.
4297  * \param[in] caller â€“ netif_detach gets called conditionally based
4298  *                     on caller, IOCTL or DRIVER-suspend
4299  *
4300  * \return int
4301  *
4302  * \retval zero on success and -ve number on failure.
4303  */
4304
4305 INT eqos_powerdown(struct net_device *dev, UINT wakeup_type, UINT caller)
4306 {
4307         struct eqos_prv_data *pdata = netdev_priv(dev);
4308         struct hw_if_struct *hw_if = &(pdata->hw_if);
4309
4310         pr_debug("-->eqos_powerdown\n");
4311
4312         if (!dev || !netif_running(dev) ||
4313             (caller == EQOS_IOCTL_CONTEXT && pdata->power_down)) {
4314                 pr_err
4315                     ("Device is already powered down and will powerup for %s\n",
4316                      EQOS_POWER_DOWN_TYPE(pdata));
4317                 pr_debug("<--eqos_powerdown\n");
4318                 return -EINVAL;
4319         }
4320
4321         if (pdata->phydev)
4322                 phy_stop(pdata->phydev);
4323
4324         spin_lock(&pdata->pmt_lock);
4325
4326         if (caller == EQOS_DRIVER_CONTEXT)
4327                 netif_device_detach(dev);
4328
4329         netif_tx_disable(dev);
4330         eqos_all_ch_napi_disable(pdata);
4331
4332         /* stop DMA TX/RX */
4333         eqos_stop_all_ch_tx_dma(pdata);
4334         eqos_stop_all_ch_rx_dma(pdata);
4335
4336         /* enable power down mode by programming the PMT regs */
4337         if (wakeup_type & EQOS_REMOTE_WAKEUP)
4338                 hw_if->enable_remote_pmt();
4339         if (wakeup_type & EQOS_MAGIC_WAKEUP)
4340                 hw_if->enable_magic_pmt();
4341         pdata->power_down_type = wakeup_type;
4342
4343         if (caller == EQOS_IOCTL_CONTEXT)
4344                 pdata->power_down = 1;
4345
4346         spin_unlock(&pdata->pmt_lock);
4347
4348         pr_debug("<--eqos_powerdown\n");
4349
4350         return 0;
4351 }
4352
4353 /*!
4354  * \brief API to powerup the device
4355  *
4356  * \details This function is invoked by ioctl function when the user issues an
4357  * ioctl command to move the device to out of power down state. Following
4358  * operations are performed in this function.
4359  * - Wakeup the device using PMT module if supported.
4360  * - Starts the phy.
4361  * - Enable MAC and DMA TX and RX process.
4362  * - Enable napi.
4363  * - Starts the queue.
4364  *
4365  * \param[in] dev â€“ pointer to net device structure.
4366  * \param[in] caller â€“ netif_attach gets called conditionally based
4367  *                     on caller, IOCTL or DRIVER-suspend
4368  *
4369  * \return int
4370  *
4371  * \retval zero on success and -ve number on failure.
4372  */
4373
4374 INT eqos_powerup(struct net_device *dev, UINT caller)
4375 {
4376         struct eqos_prv_data *pdata = netdev_priv(dev);
4377         struct hw_if_struct *hw_if = &(pdata->hw_if);
4378
4379         pr_debug("-->eqos_powerup\n");
4380
4381         if (!dev || !netif_running(dev) ||
4382             (caller == EQOS_IOCTL_CONTEXT && !pdata->power_down)) {
4383                 pr_err("Device is already powered up\n");
4384                 return -EINVAL;
4385         }
4386
4387         spin_lock(&pdata->pmt_lock);
4388
4389         if (pdata->power_down_type & EQOS_MAGIC_WAKEUP) {
4390                 hw_if->disable_magic_pmt();
4391                 pdata->power_down_type &= ~EQOS_MAGIC_WAKEUP;
4392         }
4393
4394         if (pdata->power_down_type & EQOS_REMOTE_WAKEUP) {
4395                 hw_if->disable_remote_pmt();
4396                 pdata->power_down_type &= ~EQOS_REMOTE_WAKEUP;
4397         }
4398
4399         pdata->power_down = 0;
4400
4401         if (pdata->phydev)
4402                 phy_start(pdata->phydev);
4403
4404         /* enable MAC TX/RX */
4405         hw_if->start_mac_tx_rx();
4406
4407         /* enable DMA TX/RX */
4408         eqos_start_all_ch_tx_dma(pdata);
4409         eqos_start_all_ch_rx_dma(pdata);
4410
4411         if (caller == EQOS_DRIVER_CONTEXT)
4412                 netif_device_attach(dev);
4413
4414         eqos_napi_enable_mq(pdata);
4415
4416         netif_tx_start_all_queues(dev);
4417
4418         spin_unlock(&pdata->pmt_lock);
4419
4420         pr_debug("<--eqos_powerup\n");
4421
4422         return 0;
4423 }
4424
4425 /*!
4426  * \brief API to configure remote wakeup
4427  *
4428  * \details This function is invoked by ioctl function when the user issues an
4429  * ioctl command to move the device to power down state using remote wakeup.
4430  *
4431  * \param[in] dev â€“ pointer to net device structure.
4432  * \param[in] req â€“ pointer to ioctl data structure.
4433  *
4434  * \return int
4435  *
4436  * \retval zero on success and -ve number on failure.
4437  */
4438
4439 INT eqos_configure_remotewakeup(struct net_device *dev,
4440                                 struct ifr_data_struct *req)
4441 {
4442         struct eqos_prv_data *pdata = netdev_priv(dev);
4443         struct hw_if_struct *hw_if = &(pdata->hw_if);
4444
4445         if (!dev || !netif_running(dev) || !pdata->hw_feat.rwk_sel
4446             || pdata->power_down) {
4447                 pr_err
4448                     ("Device is already powered down and will powerup for %s\n",
4449                      EQOS_POWER_DOWN_TYPE(pdata));
4450                 return -EINVAL;
4451         }
4452
4453         hw_if->configure_rwk_filter(req->rwk_filter_values,
4454                                     req->rwk_filter_length);
4455
4456         eqos_powerdown(dev, EQOS_REMOTE_WAKEUP, EQOS_IOCTL_CONTEXT);
4457
4458         return 0;
4459 }
4460
4461 /*!
4462  * \details This function is invoked by ioctl function when the user issues an
4463  * ioctl command to change the RX DMA PBL value. This function will program
4464  * the device to configure the user specified RX PBL value.
4465  *
4466  * \param[in] pdata â€“ pointer to private data structure.
4467  * \param[in] rx_pbl â€“ RX DMA pbl value to be programmed.
4468  *
4469  * \return void
4470  *
4471  * \retval none
4472  */
4473
4474 static void eqos_config_rx_pbl(struct eqos_prv_data *pdata,
4475                                UINT rx_pbl, UINT qinx)
4476 {
4477         struct hw_if_struct *hw_if = &(pdata->hw_if);
4478         UINT pblx8_val = 0;
4479
4480         pr_debug("-->eqos_config_rx_pbl: %d\n", rx_pbl);
4481
4482         switch (rx_pbl) {
4483         case EQOS_PBL_1:
4484         case EQOS_PBL_2:
4485         case EQOS_PBL_4:
4486         case EQOS_PBL_8:
4487         case EQOS_PBL_16:
4488         case EQOS_PBL_32:
4489                 hw_if->config_rx_pbl_val(qinx, rx_pbl);
4490                 hw_if->config_pblx8(qinx, 0);
4491                 break;
4492         case EQOS_PBL_64:
4493         case EQOS_PBL_128:
4494         case EQOS_PBL_256:
4495                 hw_if->config_rx_pbl_val(qinx, rx_pbl / 8);
4496                 hw_if->config_pblx8(qinx, 1);
4497                 pblx8_val = 1;
4498                 break;
4499         }
4500
4501         switch (pblx8_val) {
4502         case 0:
4503                 pr_err("Tx PBL[%d] value: %d\n",
4504                        qinx, hw_if->get_tx_pbl_val(qinx));
4505                 pr_err("Rx PBL[%d] value: %d\n",
4506                        qinx, hw_if->get_rx_pbl_val(qinx));
4507                 break;
4508         case 1:
4509                 pr_err("Tx PBL[%d] value: %d\n",
4510                        qinx, (hw_if->get_tx_pbl_val(qinx) * 8));
4511                 pr_err("Rx PBL[%d] value: %d\n",
4512                        qinx, (hw_if->get_rx_pbl_val(qinx) * 8));
4513                 break;
4514         }
4515
4516         pr_debug("<--eqos_config_rx_pbl\n");
4517 }
4518
4519 /*!
4520  * \details This function is invoked by ioctl function when the user issues an
4521  * ioctl command to change the TX DMA PBL value. This function will program
4522  * the device to configure the user specified TX PBL value.
4523  *
4524  * \param[in] pdata â€“ pointer to private data structure.
4525  * \param[in] tx_pbl â€“ TX DMA pbl value to be programmed.
4526  *
4527  * \return void
4528  *
4529  * \retval none
4530  */
4531
4532 static void eqos_config_tx_pbl(struct eqos_prv_data *pdata,
4533                                UINT tx_pbl, UINT qinx)
4534 {
4535         struct hw_if_struct *hw_if = &(pdata->hw_if);
4536         UINT pblx8_val = 0;
4537
4538         pr_debug("-->eqos_config_tx_pbl: %d\n", tx_pbl);
4539
4540         switch (tx_pbl) {
4541         case EQOS_PBL_1:
4542         case EQOS_PBL_2:
4543         case EQOS_PBL_4:
4544         case EQOS_PBL_8:
4545         case EQOS_PBL_16:
4546         case EQOS_PBL_32:
4547                 hw_if->config_tx_pbl_val(qinx, tx_pbl);
4548                 hw_if->config_pblx8(qinx, 0);
4549                 break;
4550         case EQOS_PBL_64:
4551         case EQOS_PBL_128:
4552         case EQOS_PBL_256:
4553                 hw_if->config_tx_pbl_val(qinx, tx_pbl / 8);
4554                 hw_if->config_pblx8(qinx, 1);
4555                 pblx8_val = 1;
4556                 break;
4557         }
4558
4559         switch (pblx8_val) {
4560         case 0:
4561                 pr_err("Tx PBL[%d] value: %d\n",
4562                        qinx, hw_if->get_tx_pbl_val(qinx));
4563                 pr_err("Rx PBL[%d] value: %d\n",
4564                        qinx, hw_if->get_rx_pbl_val(qinx));
4565                 break;
4566         case 1:
4567                 pr_err("Tx PBL[%d] value: %d\n",
4568                        qinx, (hw_if->get_tx_pbl_val(qinx) * 8));
4569                 pr_err("Rx PBL[%d] value: %d\n",
4570                        qinx, (hw_if->get_rx_pbl_val(qinx) * 8));
4571                 break;
4572         }
4573
4574         pr_debug("<--eqos_config_tx_pbl\n");
4575 }
4576
4577 /*!
4578  * \details This function is invoked by ioctl function when the user issues an
4579  * ioctl command to select the DCB algorithm.
4580  *
4581  * \param[in] pdata â€“ pointer to private data structure.
4582  * \param[in] req â€“ pointer to ioctl data structure.
4583  *
4584  * \return void
4585  *
4586  * \retval none
4587  */
4588
4589 static void eqos_program_dcb_algorithm(struct eqos_prv_data *pdata,
4590                                        struct ifr_data_struct *req)
4591 {
4592         struct eqos_dcb_algorithm l_dcb_struct, *u_dcb_struct =
4593             (struct eqos_dcb_algorithm *)req->ptr;
4594         struct hw_if_struct *hw_if = &pdata->hw_if;
4595
4596         pr_debug("-->eqos_program_dcb_algorithm\n");
4597
4598         if (copy_from_user(&l_dcb_struct, u_dcb_struct,
4599                            sizeof(struct eqos_dcb_algorithm)))
4600                 pr_err("Failed to fetch DCB Struct info from user\n");
4601
4602         hw_if->set_tx_queue_operating_mode(l_dcb_struct.qinx,
4603                                            (UINT) l_dcb_struct.op_mode);
4604         hw_if->set_dcb_algorithm(l_dcb_struct.algorithm);
4605         hw_if->set_dcb_queue_weight(l_dcb_struct.qinx, l_dcb_struct.weight);
4606
4607         pr_debug("<--eqos_program_dcb_algorithm\n");
4608
4609         return;
4610 }
4611
4612 /*!
4613  * \details This function is invoked by ioctl function when the user issues an
4614  * ioctl command to select the AVB algorithm. This function also configures other
4615  * parameters like send and idle slope, high and low credit.
4616  *
4617  * \param[in] pdata â€“ pointer to private data structure.
4618  * \param[in] req â€“ pointer to ioctl data structure.
4619  *
4620  * \return void
4621  *
4622  * \retval none
4623  */
4624
4625 static void eqos_program_avb_algorithm(struct eqos_prv_data *pdata,
4626                                        struct ifr_data_struct *req)
4627 {
4628         struct eqos_avb_algorithm l_avb_struct, *u_avb_struct =
4629             (struct eqos_avb_algorithm *)req->ptr;
4630         struct hw_if_struct *hw_if = &pdata->hw_if;
4631
4632         pr_debug("-->eqos_program_avb_algorithm\n");
4633
4634         if (copy_from_user(&l_avb_struct, u_avb_struct,
4635                            sizeof(struct eqos_avb_algorithm)))
4636                 pr_err("Failed to fetch AVB Struct info from user\n");
4637
4638         hw_if->set_tx_queue_operating_mode(l_avb_struct.qinx,
4639                                            (UINT) l_avb_struct.op_mode);
4640         hw_if->set_avb_algorithm(l_avb_struct.qinx, l_avb_struct.algorithm);
4641         hw_if->config_credit_control(l_avb_struct.qinx, l_avb_struct.cc);
4642         hw_if->config_send_slope(l_avb_struct.qinx, l_avb_struct.send_slope);
4643         hw_if->config_idle_slope(l_avb_struct.qinx, l_avb_struct.idle_slope);
4644         hw_if->config_high_credit(l_avb_struct.qinx, l_avb_struct.hi_credit);
4645         hw_if->config_low_credit(l_avb_struct.qinx, l_avb_struct.low_credit);
4646
4647         pr_debug("<--eqos_program_avb_algorithm\n");
4648
4649         return;
4650 }
4651
4652 /*!
4653 * \brief API to read the registers & prints the value.
4654 * \details This function will read all the device register except
4655 * data register & prints the values.
4656 *
4657 * \return none
4658 */
4659 #if 0
4660 void dbgpr_regs(void)
4661 {
4662         UINT val0;
4663         UINT val1;
4664         UINT val2;
4665         UINT val3;
4666         UINT val4;
4667         UINT val5;
4668
4669         MAC_PMTCSR_RD(val0);
4670         MMC_RXICMP_ERR_OCTETS_RD(val1);
4671         MMC_RXICMP_GD_OCTETS_RD(val2);
4672         MMC_RXTCP_ERR_OCTETS_RD(val3);
4673         MMC_RXTCP_GD_OCTETS_RD(val4);
4674         MMC_RXUDP_ERR_OCTETS_RD(val5);
4675
4676         pr_debug("dbgpr_regs: MAC_PMTCSR:%#x\n"
4677               "dbgpr_regs: MMC_RXICMP_ERR_OCTETS:%#x\n"
4678               "dbgpr_regs: MMC_RXICMP_GD_OCTETS:%#x\n"
4679               "dbgpr_regs: MMC_RXTCP_ERR_OCTETS:%#x\n"
4680               "dbgpr_regs: MMC_RXTCP_GD_OCTETS:%#x\n"
4681               "dbgpr_regs: MMC_RXUDP_ERR_OCTETS:%#x\n",
4682               val0, val1, val2, val3, val4, val5);
4683
4684         MMC_RXUDP_GD_OCTETS_RD(val0);
4685         MMC_RXIPV6_NOPAY_OCTETS_RD(val1);
4686         MMC_RXIPV6_HDRERR_OCTETS_RD(val2);
4687         MMC_RXIPV6_GD_OCTETS_RD(val3);
4688         MMC_RXIPV4_UDSBL_OCTETS_RD(val4);
4689         MMC_RXIPV4_FRAG_OCTETS_RD(val5);
4690
4691         pr_debug("dbgpr_regs: MMC_RXUDP_GD_OCTETS:%#x\n"
4692               "dbgpr_regs: MMC_RXIPV6_NOPAY_OCTETS:%#x\n"
4693               "dbgpr_regs: MMC_RXIPV6_HDRERR_OCTETS:%#x\n"
4694               "dbgpr_regs: MMC_RXIPV6_GD_OCTETS:%#x\n"
4695               "dbgpr_regs: MMC_RXIPV4_UDSBL_OCTETS:%#x\n"
4696               "dbgpr_regs: MMC_RXIPV4_FRAG_OCTETS:%#x\n",
4697               val0, val1, val2, val3, val4, val5);
4698
4699         MMC_RXIPV4_NOPAY_OCTETS_RD(val0);
4700         MMC_RXIPV4_HDRERR_OCTETS_RD(val1);
4701         MMC_RXIPV4_GD_OCTETS_RD(val2);
4702         MMC_RXICMP_ERR_PKTS_RD(val3);
4703         MMC_RXICMP_GD_PKTS_RD(val4);
4704         MMC_RXTCP_ERR_PKTS_RD(val5);
4705
4706         pr_debug("dbgpr_regs: MMC_RXIPV4_NOPAY_OCTETS:%#x\n"
4707               "dbgpr_regs: MMC_RXIPV4_HDRERR_OCTETS:%#x\n"
4708               "dbgpr_regs: MMC_RXIPV4_GD_OCTETS:%#x\n"
4709               "dbgpr_regs: MMC_RXICMP_ERR_PKTS:%#x\n"
4710               "dbgpr_regs: MMC_RXICMP_GD_PKTS:%#x\n"
4711               "dbgpr_regs: MMC_RXTCP_ERR_PKTS:%#x\n",
4712               val0, val1, val2, val3, val4, val5);
4713
4714         MMC_RXTCP_GD_PKTS_RD(val0);
4715         MMC_RXUDP_ERR_PKTS_RD(val1);
4716         MMC_RXUDP_GD_PKTS_RD(val2);
4717         MMC_RXIPV6_NOPAY_PKTS_RD(val3);
4718         MMC_RXIPV6_HDRERR_PKTS_RD(val4);
4719         MMC_RXIPV6_GD_PKTS_RD(val5);
4720
4721         pr_debug("dbgpr_regs: MMC_RXTCP_GD_PKTS:%#x\n"
4722               "dbgpr_regs: MMC_RXUDP_ERR_PKTS:%#x\n"
4723               "dbgpr_regs: MMC_RXUDP_GD_PKTS:%#x\n"
4724               "dbgpr_regs: MMC_RXIPV6_NOPAY_PKTS:%#x\n"
4725               "dbgpr_regs: MMC_RXIPV6_HDRERR_PKTS:%#x\n"
4726               "dbgpr_regs: MMC_RXIPV6_GD_PKTS:%#x\n",
4727               val0, val1, val2, val3, val4, val5);
4728
4729         MMC_RXIPV4_UBSBL_PKTS_RD(val0);
4730         MMC_RXIPV4_FRAG_PKTS_RD(val1);
4731         MMC_RXIPV4_NOPAY_PKTS_RD(val2);
4732         MMC_RXIPV4_HDRERR_PKTS_RD(val3);
4733         MMC_RXIPV4_GD_PKTS_RD(val4);
4734         MMC_RXCTRLPACKETS_G_RD(val5);
4735
4736         pr_debug("dbgpr_regs: MMC_RXIPV4_UBSBL_PKTS:%#x\n"
4737               "dbgpr_regs: MMC_RXIPV4_FRAG_PKTS:%#x\n"
4738               "dbgpr_regs: MMC_RXIPV4_NOPAY_PKTS:%#x\n"
4739               "dbgpr_regs: MMC_RXIPV4_HDRERR_PKTS:%#x\n"
4740               "dbgpr_regs: MMC_RXIPV4_GD_PKTS:%#x\n"
4741               "dbgpr_regs: MMC_RXCTRLPACKETS_G:%#x\n",
4742               val0, val1, val2, val3, val4, val5);
4743
4744         MMC_RXRCVERROR_RD(val0);
4745         MMC_RXWATCHDOGERROR_RD(val1);
4746         MMC_RXVLANPACKETS_GB_RD(val2);
4747         MMC_RXFIFOOVERFLOW_RD(val3);
4748         MMC_RXPAUSEPACKETS_RD(val4);
4749         MMC_RXOUTOFRANGETYPE_RD(val5);
4750
4751         pr_debug("dbgpr_regs: MMC_RXRCVERROR:%#x\n"
4752               "dbgpr_regs: MMC_RXWATCHDOGERROR:%#x\n"
4753               "dbgpr_regs: MMC_RXVLANPACKETS_GB:%#x\n"
4754               "dbgpr_regs: MMC_RXFIFOOVERFLOW:%#x\n"
4755               "dbgpr_regs: MMC_RXPAUSEPACKETS:%#x\n"
4756               "dbgpr_regs: MMC_RXOUTOFRANGETYPE:%#x\n",
4757               val0, val1, val2, val3, val4, val5);
4758
4759         MMC_RXLENGTHERROR_RD(val0);
4760         MMC_RXUNICASTPACKETS_G_RD(val1);
4761         MMC_RX1024TOMAXOCTETS_GB_RD(val2);
4762         MMC_RX512TO1023OCTETS_GB_RD(val3);
4763         MMC_RX256TO511OCTETS_GB_RD(val4);
4764         MMC_RX128TO255OCTETS_GB_RD(val5);
4765
4766         pr_debug("dbgpr_regs: MMC_RXLENGTHERROR:%#x\n"
4767               "dbgpr_regs: MMC_RXUNICASTPACKETS_G:%#x\n"
4768               "dbgpr_regs: MMC_RX1024TOMAXOCTETS_GB:%#x\n"
4769               "dbgpr_regs: MMC_RX512TO1023OCTETS_GB:%#x\n"
4770               "dbgpr_regs: MMC_RX256TO511OCTETS_GB:%#x\n"
4771               "dbgpr_regs: MMC_RX128TO255OCTETS_GB:%#x\n",
4772               val0, val1, val2, val3, val4, val5);
4773
4774         MMC_RX65TO127OCTETS_GB_RD(val0);
4775         MMC_RX64OCTETS_GB_RD(val1);
4776         MMC_RXOVERSIZE_G_RD(val2);
4777         MMC_RXUNDERSIZE_G_RD(val3);
4778         MMC_RXJABBERERROR_RD(val4);
4779         MMC_RXRUNTERROR_RD(val5);
4780
4781         pr_debug("dbgpr_regs: MMC_RX65TO127OCTETS_GB:%#x\n"
4782               "dbgpr_regs: MMC_RX64OCTETS_GB:%#x\n"
4783               "dbgpr_regs: MMC_RXOVERSIZE_G:%#x\n"
4784               "dbgpr_regs: MMC_RXUNDERSIZE_G:%#x\n"
4785               "dbgpr_regs: MMC_RXJABBERERROR:%#x\n"
4786               "dbgpr_regs: MMC_RXRUNTERROR:%#x\n",
4787               val0, val1, val2, val3, val4, val5);
4788
4789         MMC_RXALIGNMENTERROR_RD(val0);
4790         MMC_RXCRCERROR_RD(val1);
4791         MMC_RXMULTICASTPACKETS_G_RD(val2);
4792         MMC_RXBROADCASTPACKETS_G_RD(val3);
4793         MMC_RXOCTETCOUNT_G_RD(val4);
4794         MMC_RXOCTETCOUNT_GB_RD(val5);
4795
4796         pr_debug("dbgpr_regs: MMC_RXALIGNMENTERROR:%#x\n"
4797               "dbgpr_regs: MMC_RXCRCERROR:%#x\n"
4798               "dbgpr_regs: MMC_RXMULTICASTPACKETS_G:%#x\n"
4799               "dbgpr_regs: MMC_RXBROADCASTPACKETS_G:%#x\n"
4800               "dbgpr_regs: MMC_RXOCTETCOUNT_G:%#x\n"
4801               "dbgpr_regs: MMC_RXOCTETCOUNT_GB:%#x\n",
4802               val0, val1, val2, val3, val4, val5);
4803
4804         MMC_RXPACKETCOUNT_GB_RD(val0);
4805         MMC_TXOVERSIZE_G_RD(val1);
4806         MMC_TXVLANPACKETS_G_RD(val2);
4807         MMC_TXPAUSEPACKETS_RD(val3);
4808         MMC_TXEXCESSDEF_RD(val4);
4809         MMC_TXPACKETSCOUNT_G_RD(val5);
4810
4811         pr_debug("dbgpr_regs: MMC_RXPACKETCOUNT_GB:%#x\n"
4812               "dbgpr_regs: MMC_TXOVERSIZE_G:%#x\n"
4813               "dbgpr_regs: MMC_TXVLANPACKETS_G:%#x\n"
4814               "dbgpr_regs: MMC_TXPAUSEPACKETS:%#x\n"
4815               "dbgpr_regs: MMC_TXEXCESSDEF:%#x\n"
4816               "dbgpr_regs: MMC_TXPACKETSCOUNT_G:%#x\n",
4817               val0, val1, val2, val3, val4, val5);
4818
4819         MMC_TXOCTETCOUNT_G_RD(val0);
4820         MMC_TXCARRIERERROR_RD(val1);
4821         MMC_TXEXESSCOL_RD(val2);
4822         MMC_TXLATECOL_RD(val3);
4823         MMC_TXDEFERRED_RD(val4);
4824         MMC_TXMULTICOL_G_RD(val5);
4825
4826         pr_debug("dbgpr_regs: MMC_TXOCTETCOUNT_G:%#x\n"
4827               "dbgpr_regs: MMC_TXCARRIERERROR:%#x\n"
4828               "dbgpr_regs: MMC_TXEXESSCOL:%#x\n"
4829               "dbgpr_regs: MMC_TXLATECOL:%#x\n"
4830               "dbgpr_regs: MMC_TXDEFERRED:%#x\n"
4831               "dbgpr_regs: MMC_TXMULTICOL_G:%#x\n",
4832               val0, val1, val2, val3, val4, val5);
4833
4834         MMC_TXSINGLECOL_G_RD(val0);
4835         MMC_TXUNDERFLOWERROR_RD(val1);
4836         MMC_TXBROADCASTPACKETS_GB_RD(val2);
4837         MMC_TXMULTICASTPACKETS_GB_RD(val3);
4838         MMC_TXUNICASTPACKETS_GB_RD(val4);
4839         MMC_TX1024TOMAXOCTETS_GB_RD(val5);
4840
4841         pr_debug("dbgpr_regs: MMC_TXSINGLECOL_G:%#x\n"
4842               "dbgpr_regs: MMC_TXUNDERFLOWERROR:%#x\n"
4843               "dbgpr_regs: MMC_TXBROADCASTPACKETS_GB:%#x\n"
4844               "dbgpr_regs: MMC_TXMULTICASTPACKETS_GB:%#x\n"
4845               "dbgpr_regs: MMC_TXUNICASTPACKETS_GB:%#x\n"
4846               "dbgpr_regs: MMC_TX1024TOMAXOCTETS_GB:%#x\n",
4847               val0, val1, val2, val3, val4, val5);
4848
4849         MMC_TX512TO1023OCTETS_GB_RD(val0);
4850         MMC_TX256TO511OCTETS_GB_RD(val1);
4851         MMC_TX128TO255OCTETS_GB_RD(val2);
4852         MMC_TX65TO127OCTETS_GB_RD(val3);
4853         MMC_TX64OCTETS_GB_RD(val4);
4854         MMC_TXMULTICASTPACKETS_G_RD(val5);
4855
4856         pr_debug("dbgpr_regs: MMC_TX512TO1023OCTETS_GB:%#x\n"
4857               "dbgpr_regs: MMC_TX256TO511OCTETS_GB:%#x\n"
4858               "dbgpr_regs: MMC_TX128TO255OCTETS_GB:%#x\n"
4859               "dbgpr_regs: MMC_TX65TO127OCTETS_GB:%#x\n"
4860               "dbgpr_regs: MMC_TX64OCTETS_GB:%#x\n"
4861               "dbgpr_regs: MMC_TXMULTICASTPACKETS_G:%#x\n",
4862               val0, val1, val2, val3, val4, val5);
4863
4864         MMC_TXBROADCASTPACKETS_G_RD(val0);
4865         MMC_TXPACKETCOUNT_GB_RD(val1);
4866         MMC_TXOCTETCOUNT_GB_RD(val2);
4867         MMC_IPC_INTR_RX_RD(val3);
4868         MMC_IPC_INTR_MASK_RX_RD(val4);
4869         MMC_INTR_MASK_TX_RD(val5);
4870
4871         pr_debug("dbgpr_regs: MMC_TXBROADCASTPACKETS_G:%#x\n"
4872               "dbgpr_regs: MMC_TXPACKETCOUNT_GB:%#x\n"
4873               "dbgpr_regs: MMC_TXOCTETCOUNT_GB:%#x\n"
4874               "dbgpr_regs: MMC_IPC_INTR_RX:%#x\n"
4875               "dbgpr_regs: MMC_IPC_INTR_MASK_RX:%#x\n"
4876               "dbgpr_regs: MMC_INTR_MASK_TX:%#x\n",
4877               val0, val1, val2, val3, val4, val5);
4878
4879         MMC_INTR_MASK_RX_RD(val0);
4880         MMC_INTR_TX_RD(val1);
4881         MMC_INTR_RX_RD(val2);
4882         MMC_CNTRL_RD(val3);
4883         MAC_MA1LR_RD(val4);
4884         MAC_MA1HR_RD(val5);
4885
4886         pr_debug("dbgpr_regs: MMC_INTR_MASK_RX:%#x\n"
4887               "dbgpr_regs: MMC_INTR_TX:%#x\n"
4888               "dbgpr_regs: MMC_INTR_RX:%#x\n"
4889               "dbgpr_regs: MMC_CNTRL:%#x\n"
4890               "dbgpr_regs: MAC_MA1LR:%#x\n"
4891               "dbgpr_regs: MAC_MA1HR:%#x\n",
4892               val0, val1, val2, val3, val4, val5);
4893
4894         MAC_MA0LR_RD(val0);
4895         MAC_MA0HR_RD(val1);
4896         MAC_GPIOR_RD(val2);
4897         MAC_GMIIDR_RD(val3);
4898         MAC_GMIIAR_RD(val4);
4899         MAC_HFR2_RD(val5);
4900
4901         pr_debug("dbgpr_regs: MAC_MA0LR:%#x\n"
4902               "dbgpr_regs: MAC_MA0HR:%#x\n"
4903               "dbgpr_regs: MAC_GPIOR:%#x\n"
4904               "dbgpr_regs: MAC_GMIIDR:%#x\n"
4905               "dbgpr_regs: MAC_GMIIAR:%#x\n"
4906               "dbgpr_regs: MAC_HFR2:%#x\n", val0, val1, val2, val3, val4, val5);
4907
4908         MAC_HFR1_RD(val0);
4909         MAC_HFR0_RD(val1);
4910         MAC_MDR_RD(val2);
4911         MAC_VR_RD(val3);
4912         MAC_HTR7_RD(val4);
4913         MAC_HTR6_RD(val5);
4914
4915         pr_debug("dbgpr_regs: MAC_HFR1:%#x\n"
4916               "dbgpr_regs: MAC_HFR0:%#x\n"
4917               "dbgpr_regs: MAC_MDR:%#x\n"
4918               "dbgpr_regs: MAC_VR:%#x\n"
4919               "dbgpr_regs: MAC_HTR7:%#x\n"
4920               "dbgpr_regs: MAC_HTR6:%#x\n", val0, val1, val2, val3, val4, val5);
4921
4922         MAC_HTR5_RD(val0);
4923         MAC_HTR4_RD(val1);
4924         MAC_HTR3_RD(val2);
4925         MAC_HTR2_RD(val3);
4926         MAC_HTR1_RD(val4);
4927         MAC_HTR0_RD(val5);
4928
4929         pr_debug("dbgpr_regs: MAC_HTR5:%#x\n"
4930               "dbgpr_regs: MAC_HTR4:%#x\n"
4931               "dbgpr_regs: MAC_HTR3:%#x\n"
4932               "dbgpr_regs: MAC_HTR2:%#x\n"
4933               "dbgpr_regs: MAC_HTR1:%#x\n"
4934               "dbgpr_regs: MAC_HTR0:%#x\n", val0, val1, val2, val3, val4, val5);
4935
4936         DMA_RIWTR7_RD(val0);
4937         DMA_RIWTR6_RD(val1);
4938         DMA_RIWTR5_RD(val2);
4939         DMA_RIWTR4_RD(val3);
4940         DMA_RIWTR3_RD(val4);
4941         DMA_RIWTR2_RD(val5);
4942
4943         pr_debug("dbgpr_regs: DMA_RIWTR7:%#x\n"
4944               "dbgpr_regs: DMA_RIWTR6:%#x\n"
4945               "dbgpr_regs: DMA_RIWTR5:%#x\n"
4946               "dbgpr_regs: DMA_RIWTR4:%#x\n"
4947               "dbgpr_regs: DMA_RIWTR3:%#x\n"
4948               "dbgpr_regs: DMA_RIWTR2:%#x\n",
4949               val0, val1, val2, val3, val4, val5);
4950
4951         DMA_RIWTR1_RD(val0);
4952         DMA_RIWTR0_RD(val1);
4953         DMA_RDRLR7_RD(val2);
4954         DMA_RDRLR6_RD(val3);
4955         DMA_RDRLR5_RD(val4);
4956         DMA_RDRLR4_RD(val5);
4957
4958         pr_debug("dbgpr_regs: DMA_RIWTR1:%#x\n"
4959               "dbgpr_regs: DMA_RIWTR0:%#x\n"
4960               "dbgpr_regs: DMA_RDRLR7:%#x\n"
4961               "dbgpr_regs: DMA_RDRLR6:%#x\n"
4962               "dbgpr_regs: DMA_RDRLR5:%#x\n"
4963               "dbgpr_regs: DMA_RDRLR4:%#x\n",
4964               val0, val1, val2, val3, val4, val5);
4965
4966         DMA_RDRLR3_RD(val0);
4967         DMA_RDRLR2_RD(val1);
4968         DMA_RDRLR1_RD(val2);
4969         DMA_RDRLR0_RD(val3);
4970         DMA_TDRLR7_RD(val4);
4971         DMA_TDRLR6_RD(val5);
4972
4973         pr_debug("dbgpr_regs: DMA_RDRLR3:%#x\n"
4974               "dbgpr_regs: DMA_RDRLR2:%#x\n"
4975               "dbgpr_regs: DMA_RDRLR1:%#x\n"
4976               "dbgpr_regs: DMA_RDRLR0:%#x\n"
4977               "dbgpr_regs: DMA_TDRLR7:%#x\n"
4978               "dbgpr_regs: DMA_TDRLR6:%#x\n",
4979               val0, val1, val2, val3, val4, val5);
4980
4981         DMA_TDRLR5_RD(val0);
4982         DMA_TDRLR4_RD(val1);
4983         DMA_TDRLR3_RD(val2);
4984         DMA_TDRLR2_RD(val3);
4985         DMA_TDRLR1_RD(val4);
4986         DMA_TDRLR0_RD(val5);
4987
4988         pr_debug("dbgpr_regs: DMA_TDRLR5:%#x\n"
4989               "dbgpr_regs: DMA_TDRLR4:%#x\n"
4990               "dbgpr_regs: DMA_TDRLR3:%#x\n"
4991               "dbgpr_regs: DMA_TDRLR2:%#x\n"
4992               "dbgpr_regs: DMA_TDRLR1:%#x\n"
4993               "dbgpr_regs: DMA_TDRLR0:%#x\n",
4994               val0, val1, val2, val3, val4, val5);
4995
4996         DMA_RDTP_RPDR7_RD(val0);
4997         DMA_RDTP_RPDR6_RD(val1);
4998         DMA_RDTP_RPDR5_RD(val2);
4999         DMA_RDTP_RPDR4_RD(val3);
5000         DMA_RDTP_RPDR3_RD(val4);
5001         DMA_RDTP_RPDR2_RD(val5);
5002
5003         pr_debug("dbgpr_regs: DMA_RDTP_RPDR7:%#x\n"
5004               "dbgpr_regs: DMA_RDTP_RPDR6:%#x\n"
5005               "dbgpr_regs: DMA_RDTP_RPDR5:%#x\n"
5006               "dbgpr_regs: DMA_RDTP_RPDR4:%#x\n"
5007               "dbgpr_regs: DMA_RDTP_RPDR3:%#x\n"
5008               "dbgpr_regs: DMA_RDTP_RPDR2:%#x\n",
5009               val0, val1, val2, val3, val4, val5);
5010
5011         DMA_RDTP_RPDR1_RD(val0);
5012         DMA_RDTP_RPDR0_RD(val1);
5013         DMA_TDTP_TPDR7_RD(val2);
5014         DMA_TDTP_TPDR6_RD(val3);
5015         DMA_TDTP_TPDR5_RD(val4);
5016         DMA_TDTP_TPDR4_RD(val5);
5017
5018         pr_debug("dbgpr_regs: DMA_RDTP_RPDR1:%#x\n"
5019               "dbgpr_regs: DMA_RDTP_RPDR0:%#x\n"
5020               "dbgpr_regs: DMA_TDTP_TPDR7:%#x\n"
5021               "dbgpr_regs: DMA_TDTP_TPDR6:%#x\n"
5022               "dbgpr_regs: DMA_TDTP_TPDR5:%#x\n"
5023               "dbgpr_regs: DMA_TDTP_TPDR4:%#x\n",
5024               val0, val1, val2, val3, val4, val5);
5025
5026         DMA_TDTP_TPDR3_RD(val0);
5027         DMA_TDTP_TPDR2_RD(val1);
5028         DMA_TDTP_TPDR1_RD(val2);
5029         DMA_TDTP_TPDR0_RD(val3);
5030         DMA_RDLAR7_RD(val4);
5031         DMA_RDLAR6_RD(val5);
5032
5033         pr_debug("dbgpr_regs: DMA_TDTP_TPDR3:%#x\n"
5034               "dbgpr_regs: DMA_TDTP_TPDR2:%#x\n"
5035               "dbgpr_regs: DMA_TDTP_TPDR1:%#x\n"
5036               "dbgpr_regs: DMA_TDTP_TPDR0:%#x\n"
5037               "dbgpr_regs: DMA_RDLAR7:%#x\n"
5038               "dbgpr_regs: DMA_RDLAR6:%#x\n",
5039               val0, val1, val2, val3, val4, val5);
5040
5041         DMA_RDLAR5_RD(val0);
5042         DMA_RDLAR4_RD(val1);
5043         DMA_RDLAR3_RD(val2);
5044         DMA_RDLAR2_RD(val3);
5045         DMA_RDLAR1_RD(val4);
5046         DMA_RDLAR0_RD(val5);
5047
5048         pr_debug("dbgpr_regs: DMA_RDLAR5:%#x\n"
5049               "dbgpr_regs: DMA_RDLAR4:%#x\n"
5050               "dbgpr_regs: DMA_RDLAR3:%#x\n"
5051               "dbgpr_regs: DMA_RDLAR2:%#x\n"
5052               "dbgpr_regs: DMA_RDLAR1:%#x\n"
5053               "dbgpr_regs: DMA_RDLAR0:%#x\n",
5054               val0, val1, val2, val3, val4, val5);
5055
5056         DMA_TDLAR7_RD(val0);
5057         DMA_TDLAR6_RD(val1);
5058         DMA_TDLAR5_RD(val2);
5059         DMA_TDLAR4_RD(val3);
5060         DMA_TDLAR3_RD(val4);
5061         DMA_TDLAR2_RD(val5);
5062
5063         pr_debug("dbgpr_regs: DMA_TDLAR7:%#x\n"
5064               "dbgpr_regs: DMA_TDLAR6:%#x\n"
5065               "dbgpr_regs: DMA_TDLAR5:%#x\n"
5066               "dbgpr_regs: DMA_TDLAR4:%#x\n"
5067               "dbgpr_regs: DMA_TDLAR3:%#x\n"
5068               "dbgpr_regs: DMA_TDLAR2:%#x\n",
5069               val0, val1, val2, val3, val4, val5);
5070
5071         DMA_TDLAR1_RD(val0);
5072         DMA_TDLAR0_RD(val1);
5073         DMA_IER7_RD(val2);
5074         DMA_IER6_RD(val3);
5075         DMA_IER5_RD(val4);
5076         DMA_IER4_RD(val5);
5077
5078         pr_debug("dbgpr_regs: DMA_TDLAR1:%#x\n"
5079               "dbgpr_regs: DMA_TDLAR0:%#x\n"
5080               "dbgpr_regs: DMA_IER7:%#x\n"
5081               "dbgpr_regs: DMA_IER6:%#x\n"
5082               "dbgpr_regs: DMA_IER5:%#x\n"
5083               "dbgpr_regs: DMA_IER4:%#x\n", val0, val1, val2, val3, val4, val5);
5084
5085         DMA_IER3_RD(val0);
5086         DMA_IER2_RD(val1);
5087         DMA_IER1_RD(val2);
5088         DMA_IER0_RD(val3);
5089         MAC_IMR_RD(val4);
5090         MAC_ISR_RD(val5);
5091
5092         pr_debug("dbgpr_regs: DMA_IER3:%#x\n"
5093               "dbgpr_regs: DMA_IER2:%#x\n"
5094               "dbgpr_regs: DMA_IER1:%#x\n"
5095               "dbgpr_regs: DMA_IER0:%#x\n"
5096               "dbgpr_regs: MAC_IMR:%#x\n"
5097               "dbgpr_regs: MAC_ISR:%#x\n", val0, val1, val2, val3, val4, val5);
5098
5099         MTL_ISR_RD(val0);
5100         DMA_SR7_RD(val1);
5101         DMA_SR6_RD(val2);
5102         DMA_SR5_RD(val3);
5103         DMA_SR4_RD(val4);
5104         DMA_SR3_RD(val5);
5105
5106         pr_debug("dbgpr_regs: MTL_ISR:%#x\n"
5107               "dbgpr_regs: DMA_SR7:%#x\n"
5108               "dbgpr_regs: DMA_SR6:%#x\n"
5109               "dbgpr_regs: DMA_SR5:%#x\n"
5110               "dbgpr_regs: DMA_SR4:%#x\n"
5111               "dbgpr_regs: DMA_SR3:%#x\n", val0, val1, val2, val3, val4, val5);
5112
5113         DMA_SR2_RD(val0);
5114         DMA_SR1_RD(val1);
5115         DMA_SR0_RD(val2);
5116         DMA_ISR_RD(val3);
5117         DMA_DSR2_RD(val4);
5118         DMA_DSR1_RD(val5);
5119
5120         pr_debug("dbgpr_regs: DMA_SR2:%#x\n"
5121               "dbgpr_regs: DMA_SR1:%#x\n"
5122               "dbgpr_regs: DMA_SR0:%#x\n"
5123               "dbgpr_regs: DMA_ISR:%#x\n"
5124               "dbgpr_regs: DMA_DSR2:%#x\n"
5125               "dbgpr_regs: DMA_DSR1:%#x\n", val0, val1, val2, val3, val4, val5);
5126
5127         DMA_DSR0_RD(val0);
5128         MTL_Q0RDR_RD(val1);
5129         MTL_Q0ESR_RD(val2);
5130         MTL_Q0TDR_RD(val3);
5131         DMA_CHRBAR7_RD(val4);
5132         DMA_CHRBAR6_RD(val5);
5133
5134         pr_debug("dbgpr_regs: DMA_DSR0:%#x\n"
5135               "dbgpr_regs: MTL_Q0RDR:%#x\n"
5136               "dbgpr_regs: MTL_Q0ESR:%#x\n"
5137               "dbgpr_regs: MTL_Q0TDR:%#x\n"
5138               "dbgpr_regs: DMA_CHRBAR7:%#x\n"
5139               "dbgpr_regs: DMA_CHRBAR6:%#x\n",
5140               val0, val1, val2, val3, val4, val5);
5141
5142         DMA_CHRBAR5_RD(val0);
5143         DMA_CHRBAR4_RD(val1);
5144         DMA_CHRBAR3_RD(val2);
5145         DMA_CHRBAR2_RD(val3);
5146         DMA_CHRBAR1_RD(val4);
5147         DMA_CHRBAR0_RD(val5);
5148
5149         pr_debug("dbgpr_regs: DMA_CHRBAR5:%#x\n"
5150               "dbgpr_regs: DMA_CHRBAR4:%#x\n"
5151               "dbgpr_regs: DMA_CHRBAR3:%#x\n"
5152               "dbgpr_regs: DMA_CHRBAR2:%#x\n"
5153               "dbgpr_regs: DMA_CHRBAR1:%#x\n"
5154               "dbgpr_regs: DMA_CHRBAR0:%#x\n",
5155               val0, val1, val2, val3, val4, val5);
5156
5157         DMA_CHTBAR7_RD(val0);
5158         DMA_CHTBAR6_RD(val1);
5159         DMA_CHTBAR5_RD(val2);
5160         DMA_CHTBAR4_RD(val3);
5161         DMA_CHTBAR3_RD(val4);
5162         DMA_CHTBAR2_RD(val5);
5163
5164         pr_debug("dbgpr_regs: DMA_CHTBAR7:%#x\n"
5165               "dbgpr_regs: DMA_CHTBAR6:%#x\n"
5166               "dbgpr_regs: DMA_CHTBAR5:%#x\n"
5167               "dbgpr_regs: DMA_CHTBAR4:%#x\n"
5168               "dbgpr_regs: DMA_CHTBAR3:%#x\n"
5169               "dbgpr_regs: DMA_CHTBAR2:%#x\n",
5170               val0, val1, val2, val3, val4, val5);
5171
5172         DMA_CHTBAR1_RD(val0);
5173         DMA_CHTBAR0_RD(val1);
5174         DMA_CHRDR7_RD(val2);
5175         DMA_CHRDR6_RD(val3);
5176         DMA_CHRDR5_RD(val4);
5177         DMA_CHRDR4_RD(val5);
5178
5179         pr_debug("dbgpr_regs: DMA_CHTBAR1:%#x\n"
5180               "dbgpr_regs: DMA_CHTBAR0:%#x\n"
5181               "dbgpr_regs: DMA_CHRDR7:%#x\n"
5182               "dbgpr_regs: DMA_CHRDR6:%#x\n"
5183               "dbgpr_regs: DMA_CHRDR5:%#x\n"
5184               "dbgpr_regs: DMA_CHRDR4:%#x\n",
5185               val0, val1, val2, val3, val4, val5);
5186
5187         DMA_CHRDR3_RD(val0);
5188         DMA_CHRDR2_RD(val1);
5189         DMA_CHRDR1_RD(val2);
5190         DMA_CHRDR0_RD(val3);
5191         DMA_CHTDR7_RD(val4);
5192         DMA_CHTDR6_RD(val5);
5193
5194         pr_debug("dbgpr_regs: DMA_CHRDR3:%#x\n"
5195               "dbgpr_regs: DMA_CHRDR2:%#x\n"
5196               "dbgpr_regs: DMA_CHRDR1:%#x\n"
5197               "dbgpr_regs: DMA_CHRDR0:%#x\n"
5198               "dbgpr_regs: DMA_CHTDR7:%#x\n"
5199               "dbgpr_regs: DMA_CHTDR6:%#x\n",
5200               val0, val1, val2, val3, val4, val5);
5201
5202         DMA_CHTDR5_RD(val0);
5203         DMA_CHTDR4_RD(val1);
5204         DMA_CHTDR3_RD(val2);
5205         DMA_CHTDR2_RD(val3);
5206         DMA_CHTDR1_RD(val4);
5207         DMA_CHTDR0_RD(val5);
5208
5209         pr_debug("dbgpr_regs: DMA_CHTDR5:%#x\n"
5210               "dbgpr_regs: DMA_CHTDR4:%#x\n"
5211               "dbgpr_regs: DMA_CHTDR3:%#x\n"
5212               "dbgpr_regs: DMA_CHTDR2:%#x\n"
5213               "dbgpr_regs: DMA_CHTDR1:%#x\n"
5214               "dbgpr_regs: DMA_CHTDR0:%#x\n",
5215               val0, val1, val2, val3, val4, val5);
5216
5217         DMA_SFCSR7_RD(val0);
5218         DMA_SFCSR6_RD(val1);
5219         DMA_SFCSR5_RD(val2);
5220         DMA_SFCSR4_RD(val3);
5221         DMA_SFCSR3_RD(val4);
5222         DMA_SFCSR2_RD(val5);
5223
5224         pr_debug("dbgpr_regs: DMA_SFCSR7:%#x\n"
5225               "dbgpr_regs: DMA_SFCSR6:%#x\n"
5226               "dbgpr_regs: DMA_SFCSR5:%#x\n"
5227               "dbgpr_regs: DMA_SFCSR4:%#x\n"
5228               "dbgpr_regs: DMA_SFCSR3:%#x\n"
5229               "dbgpr_regs: DMA_SFCSR2:%#x\n",
5230               val0, val1, val2, val3, val4, val5);
5231
5232         DMA_SFCSR1_RD(val0);
5233         DMA_SFCSR0_RD(val1);
5234         MAC_IVLANTIRR_RD(val2);
5235         MAC_VLANTIRR_RD(val3);
5236         MAC_VLANHTR_RD(val4);
5237         MAC_VLANTR_RD(val5);
5238
5239         pr_debug("dbgpr_regs: DMA_SFCSR1:%#x\n"
5240               "dbgpr_regs: DMA_SFCSR0:%#x\n"
5241               "dbgpr_regs: MAC_IVLANTIRR:%#x\n"
5242               "dbgpr_regs: MAC_VLANTIRR:%#x\n"
5243               "dbgpr_regs: MAC_VLANHTR:%#x\n"
5244               "dbgpr_regs: MAC_VLANTR:%#x\n",
5245               val0, val1, val2, val3, val4, val5);
5246
5247         DMA_SBUS_RD(val0);
5248         DMA_BMR_RD(val1);
5249         MTL_Q0RCR_RD(val2);
5250         MTL_Q0OCR_RD(val3);
5251         MTL_Q0ROMR_RD(val4);
5252         MTL_Q0QR_RD(val5);
5253
5254         pr_debug("dbgpr_regs: DMA_SBUS:%#x\n"
5255               "dbgpr_regs: DMA_BMR:%#x\n"
5256               "dbgpr_regs: MTL_Q0RCR:%#x\n"
5257               "dbgpr_regs: MTL_Q0OCR:%#x\n"
5258               "dbgpr_regs: MTL_Q0ROMR:%#x\n"
5259               "dbgpr_regs: MTL_Q0QR:%#x\n", val0, val1, val2, val3, val4, val5);
5260
5261         MTL_Q0ECR_RD(val0);
5262         MTL_Q0UCR_RD(val1);
5263         MTL_Q0TOMR_RD(val2);
5264         MTL_RQDCM1R_RD(val3);
5265         MTL_RQDCM0R_RD(val4);
5266         MTL_FDDR_RD(val5);
5267
5268         pr_debug("dbgpr_regs: MTL_Q0ECR:%#x\n"
5269               "dbgpr_regs: MTL_Q0UCR:%#x\n"
5270               "dbgpr_regs: MTL_Q0TOMR:%#x\n"
5271               "dbgpr_regs: MTL_RQDCM1R:%#x\n"
5272               "dbgpr_regs: MTL_RQDCM0R:%#x\n"
5273               "dbgpr_regs: MTL_FDDR:%#x\n", val0, val1, val2, val3, val4, val5);
5274
5275         MTL_FDACS_RD(val0);
5276         MTL_OMR_RD(val1);
5277         MAC_RQC1R_RD(val2);
5278         MAC_RQC0R_RD(val3);
5279         MAC_TQPM1R_RD(val4);
5280         MAC_TQPM0R_RD(val5);
5281
5282         pr_debug("dbgpr_regs: MTL_FDACS:%#x\n"
5283               "dbgpr_regs: MTL_OMR:%#x\n"
5284               "dbgpr_regs: MAC_RQC1R:%#x\n"
5285               "dbgpr_regs: MAC_RQC0R:%#x\n"
5286               "dbgpr_regs: MAC_TQPM1R:%#x\n"
5287               "dbgpr_regs: MAC_TQPM0R:%#x\n",
5288               val0, val1, val2, val3, val4, val5);
5289
5290         MAC_RFCR_RD(val0);
5291         MAC_QTFCR7_RD(val1);
5292         MAC_QTFCR6_RD(val2);
5293         MAC_QTFCR5_RD(val3);
5294         MAC_QTFCR4_RD(val4);
5295         MAC_QTFCR3_RD(val5);
5296
5297         pr_debug("dbgpr_regs: MAC_RFCR:%#x\n"
5298               "dbgpr_regs: MAC_QTFCR7:%#x\n"
5299               "dbgpr_regs: MAC_QTFCR6:%#x\n"
5300               "dbgpr_regs: MAC_QTFCR5:%#x\n"
5301               "dbgpr_regs: MAC_QTFCR4:%#x\n"
5302               "dbgpr_regs: MAC_QTFCR3:%#x\n",
5303               val0, val1, val2, val3, val4, val5);
5304
5305         MAC_QTFCR2_RD(val0);
5306         MAC_QTFCR1_RD(val1);
5307         MAC_Q0TFCR_RD(val2);
5308         DMA_AXI4CR7_RD(val3);
5309         DMA_AXI4CR6_RD(val4);
5310         DMA_AXI4CR5_RD(val5);
5311
5312         pr_debug("dbgpr_regs: MAC_QTFCR2:%#x\n"
5313               "dbgpr_regs: MAC_QTFCR1:%#x\n"
5314               "dbgpr_regs: MAC_Q0TFCR:%#x\n"
5315               "dbgpr_regs: DMA_AXI4CR7:%#x\n"
5316               "dbgpr_regs: DMA_AXI4CR6:%#x\n"
5317               "dbgpr_regs: DMA_AXI4CR5:%#x\n",
5318               val0, val1, val2, val3, val4, val5);
5319
5320         DMA_AXI4CR4_RD(val0);
5321         DMA_AXI4CR3_RD(val1);
5322         DMA_AXI4CR2_RD(val2);
5323         DMA_AXI4CR1_RD(val3);
5324         DMA_AXI4CR0_RD(val4);
5325         DMA_RCR7_RD(val5);
5326
5327         pr_debug("dbgpr_regs: DMA_AXI4CR4:%#x\n"
5328               "dbgpr_regs: DMA_AXI4CR3:%#x\n"
5329               "dbgpr_regs: DMA_AXI4CR2:%#x\n"
5330               "dbgpr_regs: DMA_AXI4CR1:%#x\n"
5331               "dbgpr_regs: DMA_AXI4CR0:%#x\n"
5332               "dbgpr_regs: DMA_RCR7:%#x\n", val0, val1, val2, val3, val4, val5);
5333
5334         DMA_RCR6_RD(val0);
5335         DMA_RCR5_RD(val1);
5336         DMA_RCR4_RD(val2);
5337         DMA_RCR3_RD(val3);
5338         DMA_RCR2_RD(val4);
5339         DMA_RCR1_RD(val5);
5340
5341         pr_debug("dbgpr_regs: DMA_RCR6:%#x\n"
5342               "dbgpr_regs: DMA_RCR5:%#x\n"
5343               "dbgpr_regs: DMA_RCR4:%#x\n"
5344               "dbgpr_regs: DMA_RCR3:%#x\n"
5345               "dbgpr_regs: DMA_RCR2:%#x\n"
5346               "dbgpr_regs: DMA_RCR1:%#x\n", val0, val1, val2, val3, val4, val5);
5347
5348         DMA_RCR0_RD(val0);
5349         DMA_TCR7_RD(val1);
5350         DMA_TCR6_RD(val2);
5351         DMA_TCR5_RD(val3);
5352         DMA_TCR4_RD(val4);
5353         DMA_TCR3_RD(val5);
5354
5355         pr_debug("dbgpr_regs: DMA_RCR0:%#x\n"
5356               "dbgpr_regs: DMA_TCR7:%#x\n"
5357               "dbgpr_regs: DMA_TCR6:%#x\n"
5358               "dbgpr_regs: DMA_TCR5:%#x\n"
5359               "dbgpr_regs: DMA_TCR4:%#x\n"
5360               "dbgpr_regs: DMA_TCR3:%#x\n", val0, val1, val2, val3, val4, val5);
5361
5362         DMA_TCR2_RD(val0);
5363         DMA_TCR1_RD(val1);
5364         DMA_TCR0_RD(val2);
5365         DMA_CR7_RD(val3);
5366         DMA_CR6_RD(val4);
5367         DMA_CR5_RD(val5);
5368
5369         pr_debug("dbgpr_regs: DMA_TCR2:%#x\n"
5370               "dbgpr_regs: DMA_TCR1:%#x\n"
5371               "dbgpr_regs: DMA_TCR0:%#x\n"
5372               "dbgpr_regs: DMA_CR7:%#x\n"
5373               "dbgpr_regs: DMA_CR6:%#x\n"
5374               "dbgpr_regs: DMA_CR5:%#x\n", val0, val1, val2, val3, val4, val5);
5375
5376         DMA_CR4_RD(val0);
5377         DMA_CR3_RD(val1);
5378         DMA_CR2_RD(val2);
5379         DMA_CR1_RD(val3);
5380         DMA_CR0_RD(val4);
5381         MAC_WTR_RD(val5);
5382
5383         pr_debug("dbgpr_regs: DMA_CR4:%#x\n"
5384               "dbgpr_regs: DMA_CR3:%#x\n"
5385               "dbgpr_regs: DMA_CR2:%#x\n"
5386               "dbgpr_regs: DMA_CR1:%#x\n"
5387               "dbgpr_regs: DMA_CR0:%#x\n"
5388               "dbgpr_regs: MAC_WTR:%#x\n", val0, val1, val2, val3, val4, val5);
5389
5390         MAC_MPFR_RD(val0);
5391         MAC_MECR_RD(val1);
5392         MAC_MCR_RD(val2);
5393
5394         pr_debug("dbgpr_regs: MAC_MPFR:%#x\n"
5395               "dbgpr_regs: MAC_MECR:%#x\n"
5396               "dbgpr_regs: MAC_MCR:%#x\n", val0, val1, val2);
5397
5398         return;
5399 }
5400 #endif
5401
5402 /*!
5403  * \details This function is invoked by eqos_start_xmit and
5404  * process_tx_completions function for dumping the TX descriptor contents
5405  * which are prepared for packet transmission and which are transmitted by
5406  * device. It is mainly used during development phase for debug purpose. Use
5407  * of these function may affect the performance during normal operation.
5408  *
5409  * \param[in] pdata â€“ pointer to private data structure.
5410  * \param[in] first_desc_idx â€“ first descriptor index for the current
5411  *              transfer.
5412  * \param[in] last_desc_idx â€“ last descriptor index for the current transfer.
5413  * \param[in] flag â€“ to indicate from which function it is called.
5414  *
5415  * \return void
5416  */
5417
5418 void dump_tx_desc(struct eqos_prv_data *pdata, int first_desc_idx,
5419                   int last_desc_idx, int flag, UINT qinx)
5420 {
5421         int i;
5422         struct s_tx_desc *desc = NULL;
5423         UINT ctxt;
5424
5425         if (first_desc_idx == last_desc_idx) {
5426                 desc = GET_TX_DESC_PTR(qinx, first_desc_idx);
5427
5428                 TX_NORMAL_DESC_TDES3_CTXT_RD(desc->tdes3, ctxt);
5429
5430                 pr_err("\n%s[%02d %4p %03d %s] = %#x:%#x:%#x:%#x\n",
5431                        (ctxt == 1) ? "TX_CONTXT_DESC" : "ptx_desc",
5432                        qinx, desc, first_desc_idx,
5433                        ((flag == 1) ? "QUEUED FOR TRANSMISSION" :
5434                         ((flag ==
5435                           0) ? "FREED/FETCHED BY DEVICE" : "DEBUG DESC DUMP")),
5436                        desc->tdes0, desc->tdes1, desc->tdes2, desc->tdes3);
5437         } else {
5438                 int lp_cnt;
5439                 if (first_desc_idx > last_desc_idx)
5440                         lp_cnt = last_desc_idx + TX_DESC_CNT - first_desc_idx;
5441                 else
5442                         lp_cnt = last_desc_idx - first_desc_idx;
5443
5444                 for (i = first_desc_idx; lp_cnt >= 0; lp_cnt--) {
5445                         desc = GET_TX_DESC_PTR(qinx, i);
5446
5447                         TX_NORMAL_DESC_TDES3_CTXT_RD(desc->tdes3, ctxt);
5448
5449                         pr_err("\n%s[%02d %4p %03d %s] = %#x:%#x:%#x:%#x\n",
5450                                (ctxt ==
5451                                 1) ? "TX_CONTXT_DESC" : "ptx_desc", qinx,
5452                                desc, i,
5453                                ((flag ==
5454                                  1) ? "QUEUED FOR TRANSMISSION" :
5455                                 "FREED/FETCHED BY DEVICE"), desc->tdes0,
5456                                desc->tdes1, desc->tdes2, desc->tdes3);
5457                         INCR_TX_DESC_INDEX(i, 1);
5458                 }
5459         }
5460 }
5461
5462 /*!
5463  * \details This function is invoked by poll function for dumping the
5464  * RX descriptor contents. It is mainly used during development phase for
5465  * debug purpose. Use of these function may affect the performance during
5466  * normal operation
5467  *
5468  * \param[in] pdata â€“ pointer to private data structure.
5469  *
5470  * \return void
5471  */
5472
5473 void dump_rx_desc(UINT qinx, struct s_rx_desc *desc, int desc_idx)
5474 {
5475         pr_err("\nprx_desc[%02d %4p %03d RECEIVED FROM DEVICE]"
5476                " = %#x:%#x:%#x:%#x",
5477                qinx, desc, desc_idx, desc->rdes0, desc->rdes1,
5478                desc->rdes2, desc->rdes3);
5479 }
5480
5481 /*!
5482  * \details This function is invoked by start_xmit and poll function for
5483  * dumping the content of packet to be transmitted by device or received
5484  * from device. It is mainly used during development phase for debug purpose.
5485  * Use of these functions may affect the performance during normal operation.
5486  *
5487  * \param[in] skb â€“ pointer to socket buffer structure.
5488  * \param[in] len â€“ length of packet to be transmitted/received.
5489  * \param[in] tx_rx â€“ packet to be transmitted or received.
5490  * \param[in] desc_idx â€“ descriptor index to be used for transmission or
5491  *                      reception of packet.
5492  *
5493  * \return void
5494  */
5495
5496 void print_pkt(struct sk_buff *skb, int len, bool tx_rx, int desc_idx)
5497 {
5498         int i, j = 0;
5499         unsigned char *buf = skb->data;
5500
5501         pr_err
5502             ("\n\n/***********************************************************/\n");
5503
5504         pr_err("%s pkt of %d Bytes [DESC index = %d]\n\n",
5505                (tx_rx ? "TX" : "RX"), len, desc_idx);
5506         pr_err("Dst MAC addr(6 bytes)\n");
5507         for (i = 0; i < 6; i++)
5508                 printk("%#.2x%s", buf[i], (((i == 5) ? "" : ":")));
5509         pr_err("\nSrc MAC addr(6 bytes)\n");
5510         for (i = 6; i <= 11; i++)
5511                 printk("%#.2x%s", buf[i], (((i == 11) ? "" : ":")));
5512         i = (buf[12] << 8 | buf[13]);
5513         pr_err("\nType/Length(2 bytes)\n%#x", i);
5514
5515         pr_err("\nPay Load : %d bytes\n", (len - 14));
5516         for (i = 14, j = 1; i < len; i++, j++) {
5517                 printk("%#.2x%s", buf[i], (((i == (len - 1)) ? "" : ":")));
5518                 if ((j % 16) == 0)
5519                         pr_err("");
5520         }
5521
5522         pr_err
5523             ("/*************************************************************/\n\n");
5524 }
5525
5526 /*!
5527  * \details This function is invoked by probe function. This function will
5528  * initialize default receive coalesce parameters and sw timer value and store
5529  * it in respective receive data structure.
5530  *
5531  * \param[in] pdata â€“ pointer to private data structure.
5532  *
5533  * \return void
5534  */
5535
5536 void eqos_init_rx_coalesce(struct eqos_prv_data *pdata)
5537 {
5538         struct rx_ring *prx_ring = NULL;
5539         UINT i;
5540
5541         pr_debug("-->eqos_init_rx_coalesce\n");
5542
5543         for (i = 0; i < EQOS_RX_QUEUE_CNT; i++) {
5544                 prx_ring = GET_RX_WRAPPER_DESC(i);
5545
5546                 prx_ring->use_riwt = 1;
5547                 prx_ring->rx_coal_frames = EQOS_RX_MAX_FRAMES;
5548                 prx_ring->rx_riwt =
5549                     eqos_usec2riwt(EQOS_OPTIMAL_DMA_RIWT_USEC, pdata);
5550         }
5551
5552         pr_debug("<--eqos_init_rx_coalesce\n");
5553 }
5554
5555 /*!
5556  * \details This function is invoked by open() function. This function will
5557  * clear MMC structure.
5558  *
5559  * \param[in] pdata â€“ pointer to private data structure.
5560  *
5561  * \return void
5562  */
5563
5564 static void eqos_mmc_setup(struct eqos_prv_data *pdata)
5565 {
5566         pr_debug("-->eqos_mmc_setup\n");
5567
5568         if (pdata->hw_feat.mmc_sel) {
5569                 memset(&pdata->mmc, 0, sizeof(struct eqos_mmc_counters));
5570         } else
5571                 pr_err("No MMC/RMON module available in the HW\n");
5572
5573         pr_debug("<--eqos_mmc_setup\n");
5574 }
5575
5576 inline unsigned int eqos_reg_read(volatile ULONG *ptr)
5577 {
5578         return ioread32((void *)ptr);
5579 }
5580
5581 /*!
5582  * \details This function is invoked by ethtool function when user wants to
5583  * read MMC counters. This function will read the MMC if supported by core
5584  * and store it in eqos_mmc_counters structure. By default all the
5585  * MMC are programmed "read on reset" hence all the fields of the
5586  * eqos_mmc_counters are incremented.
5587  *
5588  * open() function. This function will
5589  * initialize MMC control register ie it disable all MMC interrupt and all
5590  * MMC register are configured to clear on read.
5591  *
5592  * \param[in] pdata â€“ pointer to private data structure.
5593  *
5594  * \return void
5595  */
5596
5597 void eqos_mmc_read(struct eqos_mmc_counters *mmc)
5598 {
5599         pr_debug("-->eqos_mmc_read\n");
5600
5601         /* MMC TX counter registers */
5602         mmc->mmc_tx_octetcount_gb += eqos_reg_read(MMC_TXOCTETCOUNT_GB_OFFSET);
5603         mmc->mmc_tx_framecount_gb += eqos_reg_read(MMC_TXPACKETCOUNT_GB_OFFSET);
5604         mmc->mmc_tx_broadcastframe_g +=
5605             eqos_reg_read(MMC_TXBROADCASTPACKETS_G_OFFSET);
5606         mmc->mmc_tx_multicastframe_g +=
5607             eqos_reg_read(MMC_TXMULTICASTPACKETS_G_OFFSET);
5608         mmc->mmc_tx_64_octets_gb += eqos_reg_read(MMC_TX64OCTETS_GB_OFFSET);
5609         mmc->mmc_tx_65_to_127_octets_gb +=
5610             eqos_reg_read(MMC_TX65TO127OCTETS_GB_OFFSET);
5611         mmc->mmc_tx_128_to_255_octets_gb +=
5612             eqos_reg_read(MMC_TX128TO255OCTETS_GB_OFFSET);
5613         mmc->mmc_tx_256_to_511_octets_gb +=
5614             eqos_reg_read(MMC_TX256TO511OCTETS_GB_OFFSET);
5615         mmc->mmc_tx_512_to_1023_octets_gb +=
5616             eqos_reg_read(MMC_TX512TO1023OCTETS_GB_OFFSET);
5617         mmc->mmc_tx_1024_to_max_octets_gb +=
5618             eqos_reg_read(MMC_TX1024TOMAXOCTETS_GB_OFFSET);
5619         mmc->mmc_tx_unicast_gb += eqos_reg_read(MMC_TXUNICASTPACKETS_GB_OFFSET);
5620         mmc->mmc_tx_multicast_gb +=
5621             eqos_reg_read(MMC_TXMULTICASTPACKETS_GB_OFFSET);
5622         mmc->mmc_tx_broadcast_gb +=
5623             eqos_reg_read(MMC_TXBROADCASTPACKETS_GB_OFFSET);
5624         mmc->mmc_tx_underflow_error +=
5625             eqos_reg_read(MMC_TXUNDERFLOWERROR_OFFSET);
5626         mmc->mmc_tx_singlecol_g += eqos_reg_read(MMC_TXSINGLECOL_G_OFFSET);
5627         mmc->mmc_tx_multicol_g += eqos_reg_read(MMC_TXMULTICOL_G_OFFSET);
5628         mmc->mmc_tx_deferred += eqos_reg_read(MMC_TXDEFERRED_OFFSET);
5629         mmc->mmc_tx_latecol += eqos_reg_read(MMC_TXLATECOL_OFFSET);
5630         mmc->mmc_tx_exesscol += eqos_reg_read(MMC_TXEXESSCOL_OFFSET);
5631         mmc->mmc_tx_carrier_error += eqos_reg_read(MMC_TXCARRIERERROR_OFFSET);
5632         mmc->mmc_tx_octetcount_g += eqos_reg_read(MMC_TXOCTETCOUNT_G_OFFSET);
5633         mmc->mmc_tx_framecount_g += eqos_reg_read(MMC_TXPACKETSCOUNT_G_OFFSET);
5634         mmc->mmc_tx_excessdef += eqos_reg_read(MMC_TXEXCESSDEF_OFFSET);
5635         mmc->mmc_tx_pause_frame += eqos_reg_read(MMC_TXPAUSEPACKETS_OFFSET);
5636         mmc->mmc_tx_vlan_frame_g += eqos_reg_read(MMC_TXVLANPACKETS_G_OFFSET);
5637         mmc->mmc_tx_osize_frame_g += eqos_reg_read(MMC_TXOVERSIZE_G_OFFSET);
5638
5639         /* MMC RX counter registers */
5640         mmc->mmc_rx_framecount_gb += eqos_reg_read(MMC_RXPACKETCOUNT_GB_OFFSET);
5641         mmc->mmc_rx_octetcount_gb += eqos_reg_read(MMC_RXOCTETCOUNT_GB_OFFSET);
5642         mmc->mmc_rx_octetcount_g += eqos_reg_read(MMC_RXOCTETCOUNT_G_OFFSET);
5643         mmc->mmc_rx_broadcastframe_g +=
5644             eqos_reg_read(MMC_RXBROADCASTPACKETS_G_OFFSET);
5645         mmc->mmc_rx_multicastframe_g +=
5646             eqos_reg_read(MMC_RXMULTICASTPACKETS_G_OFFSET);
5647         mmc->mmc_rx_crc_errror += eqos_reg_read(MMC_RXCRCERROR_OFFSET);
5648         mmc->mmc_rx_align_error += eqos_reg_read(MMC_RXALIGNMENTERROR_OFFSET);
5649         mmc->mmc_rx_run_error += eqos_reg_read(MMC_RXRUNTERROR_OFFSET);
5650         mmc->mmc_rx_jabber_error += eqos_reg_read(MMC_RXJABBERERROR_OFFSET);
5651         mmc->mmc_rx_undersize_g += eqos_reg_read(MMC_RXUNDERSIZE_G_OFFSET);
5652         mmc->mmc_rx_oversize_g += eqos_reg_read(MMC_RXOVERSIZE_G_OFFSET);
5653         mmc->mmc_rx_64_octets_gb += eqos_reg_read(MMC_RX64OCTETS_GB_OFFSET);
5654         mmc->mmc_rx_65_to_127_octets_gb +=
5655             eqos_reg_read(MMC_RX65TO127OCTETS_GB_OFFSET);
5656         mmc->mmc_rx_128_to_255_octets_gb +=
5657             eqos_reg_read(MMC_RX128TO255OCTETS_GB_OFFSET);
5658         mmc->mmc_rx_256_to_511_octets_gb +=
5659             eqos_reg_read(MMC_RX256TO511OCTETS_GB_OFFSET);
5660         mmc->mmc_rx_512_to_1023_octets_gb +=
5661             eqos_reg_read(MMC_RX512TO1023OCTETS_GB_OFFSET);
5662         mmc->mmc_rx_1024_to_max_octets_gb +=
5663             eqos_reg_read(MMC_RX1024TOMAXOCTETS_GB_OFFSET);
5664         mmc->mmc_rx_unicast_g += eqos_reg_read(MMC_RXUNICASTPACKETS_G_OFFSET);
5665         mmc->mmc_rx_length_error += eqos_reg_read(MMC_RXLENGTHERROR_OFFSET);
5666         mmc->mmc_rx_outofrangetype +=
5667             eqos_reg_read(MMC_RXOUTOFRANGETYPE_OFFSET);
5668         mmc->mmc_rx_pause_frames += eqos_reg_read(MMC_RXPAUSEPACKETS_OFFSET);
5669         mmc->mmc_rx_fifo_overflow += eqos_reg_read(MMC_RXFIFOOVERFLOW_OFFSET);
5670         mmc->mmc_rx_vlan_frames_gb +=
5671             eqos_reg_read(MMC_RXVLANPACKETS_GB_OFFSET);
5672         mmc->mmc_rx_watchdog_error += eqos_reg_read(MMC_RXWATCHDOGERROR_OFFSET);
5673         mmc->mmc_rx_receive_error += eqos_reg_read(MMC_RXRCVERROR_OFFSET);
5674         mmc->mmc_rx_ctrl_frames_g += eqos_reg_read(MMC_RXCTRLPACKETS_G_OFFSET);
5675
5676         /* IPC */
5677         mmc->mmc_rx_ipc_intr_mask += eqos_reg_read(MMC_IPC_INTR_MASK_RX_OFFSET);
5678         mmc->mmc_rx_ipc_intr += eqos_reg_read(MMC_IPC_INTR_RX_OFFSET);
5679
5680         /* IPv4 */
5681         mmc->mmc_rx_ipv4_gd += eqos_reg_read(MMC_RXIPV4_GD_PKTS_OFFSET);
5682         mmc->mmc_rx_ipv4_hderr += eqos_reg_read(MMC_RXIPV4_HDRERR_PKTS_OFFSET);
5683         mmc->mmc_rx_ipv4_nopay += eqos_reg_read(MMC_RXIPV4_NOPAY_PKTS_OFFSET);
5684         mmc->mmc_rx_ipv4_frag += eqos_reg_read(MMC_RXIPV4_FRAG_PKTS_OFFSET);
5685         mmc->mmc_rx_ipv4_udsbl += eqos_reg_read(MMC_RXIPV4_UBSBL_PKTS_OFFSET);
5686
5687         /* IPV6 */
5688         mmc->mmc_rx_ipv6_gd += eqos_reg_read(MMC_RXIPV6_GD_PKTS_OFFSET);
5689         mmc->mmc_rx_ipv6_hderr += eqos_reg_read(MMC_RXIPV6_HDRERR_PKTS_OFFSET);
5690         mmc->mmc_rx_ipv6_nopay += eqos_reg_read(MMC_RXIPV6_NOPAY_PKTS_OFFSET);
5691
5692         /* Protocols */
5693         mmc->mmc_rx_udp_gd += eqos_reg_read(MMC_RXUDP_GD_PKTS_OFFSET);
5694         mmc->mmc_rx_udp_err += eqos_reg_read(MMC_RXUDP_ERR_PKTS_OFFSET);
5695         mmc->mmc_rx_tcp_gd += eqos_reg_read(MMC_RXTCP_GD_PKTS_OFFSET);
5696         mmc->mmc_rx_tcp_err += eqos_reg_read(MMC_RXTCP_ERR_PKTS_OFFSET);
5697         mmc->mmc_rx_icmp_gd += eqos_reg_read(MMC_RXICMP_GD_PKTS_OFFSET);
5698         mmc->mmc_rx_icmp_err += eqos_reg_read(MMC_RXICMP_ERR_PKTS_OFFSET);
5699
5700         /* IPv4 */
5701         mmc->mmc_rx_ipv4_gd_octets +=
5702             eqos_reg_read(MMC_RXIPV4_GD_OCTETS_OFFSET);
5703         mmc->mmc_rx_ipv4_hderr_octets +=
5704             eqos_reg_read(MMC_RXIPV4_HDRERR_OCTETS_OFFSET);
5705         mmc->mmc_rx_ipv4_nopay_octets +=
5706             eqos_reg_read(MMC_RXIPV4_NOPAY_OCTETS_OFFSET);
5707         mmc->mmc_rx_ipv4_frag_octets +=
5708             eqos_reg_read(MMC_RXIPV4_FRAG_OCTETS_OFFSET);
5709         mmc->mmc_rx_ipv4_udsbl_octets +=
5710             eqos_reg_read(MMC_RXIPV4_UDSBL_OCTETS_OFFSET);
5711
5712         /* IPV6 */
5713         mmc->mmc_rx_ipv6_gd_octets +=
5714             eqos_reg_read(MMC_RXIPV6_GD_OCTETS_OFFSET);
5715         mmc->mmc_rx_ipv6_hderr_octets +=
5716             eqos_reg_read(MMC_RXIPV6_HDRERR_OCTETS_OFFSET);
5717         mmc->mmc_rx_ipv6_nopay_octets +=
5718             eqos_reg_read(MMC_RXIPV6_NOPAY_OCTETS_OFFSET);
5719
5720         /* Protocols */
5721         mmc->mmc_rx_udp_gd_octets += eqos_reg_read(MMC_RXUDP_GD_OCTETS_OFFSET);
5722         mmc->mmc_rx_udp_err_octets +=
5723             eqos_reg_read(MMC_RXUDP_ERR_OCTETS_OFFSET);
5724         mmc->mmc_rx_tcp_gd_octets += eqos_reg_read(MMC_RXTCP_GD_OCTETS_OFFSET);
5725         mmc->mmc_rx_tcp_err_octets +=
5726             eqos_reg_read(MMC_RXTCP_ERR_OCTETS_OFFSET);
5727         mmc->mmc_rx_icmp_gd_octets +=
5728             eqos_reg_read(MMC_RXICMP_GD_OCTETS_OFFSET);
5729         mmc->mmc_rx_icmp_err_octets +=
5730             eqos_reg_read(MMC_RXICMP_ERR_OCTETS_OFFSET);
5731
5732         pr_debug("<--eqos_mmc_read\n");
5733 }
5734
5735 static const struct net_device_ops eqos_netdev_ops = {
5736         .ndo_open = eqos_open,
5737         .ndo_stop = eqos_close,
5738         .ndo_start_xmit = eqos_start_xmit,
5739         .ndo_get_stats = eqos_get_stats,
5740         .ndo_set_rx_mode = eqos_set_rx_mode,
5741         .ndo_set_features = eqos_set_features,
5742         .ndo_do_ioctl = eqos_ioctl,
5743         .ndo_change_mtu = eqos_change_mtu,
5744 #ifdef EQOS_QUEUE_SELECT_ALGO
5745         .ndo_select_queue = eqos_select_queue,
5746 #endif
5747         .ndo_vlan_rx_add_vid = eqos_vlan_rx_add_vid,
5748         .ndo_vlan_rx_kill_vid = eqos_vlan_rx_kill_vid,
5749         .ndo_set_mac_address = eqos_set_mac_address,
5750 };
5751
5752 struct net_device_ops *eqos_get_netdev_ops(void)
5753 {
5754         return (struct net_device_ops *)&eqos_netdev_ops;
5755 }
5756
5757
5758 static void eqos_disable_all_irqs(struct eqos_prv_data *pdata)
5759 {
5760         struct hw_if_struct *hw_if = &pdata->hw_if;
5761         int i;
5762
5763         pr_debug("-->%s()\n", __func__);
5764
5765         for (i = 0; i < pdata->num_chans; i++)
5766                 hw_if->disable_chan_interrupts(i, pdata);
5767
5768         /* disable mac interrupts */
5769         MAC_IMR_WR(0);
5770
5771         /* ensure irqs are not executing */
5772         synchronize_irq(pdata->common_irq);
5773         for (i = 0; i < pdata->num_chans; i++) {
5774                 if (pdata->rx_irq_alloc_mask & (1 << i))
5775                         synchronize_irq(pdata->rx_irqs[i]);
5776                 if (pdata->tx_irq_alloc_mask & (1 << i))
5777                         synchronize_irq(pdata->tx_irqs[i]);
5778         }
5779
5780         pr_debug("<--%s()\n", __func__);
5781 }
5782
5783 void eqos_stop_dev(struct eqos_prv_data *pdata)
5784 {
5785         struct hw_if_struct *hw_if = &pdata->hw_if;
5786         struct desc_if_struct *desc_if = &pdata->desc_if;
5787         int i;
5788
5789         pr_debug("-->%s()\n", __func__);
5790
5791 #ifdef CONFIG_TEGRA_PTP_NOTIFIER
5792         /* Unregister broadcasting MAC timestamp to clients */
5793         tegra_unregister_hwtime_source();
5794 #endif
5795
5796         if (pdata->phydev && pdata->phydev->drv &&
5797             pdata->phydev->drv->low_power_mode) {
5798                 pdata->phydev->drv->low_power_mode(pdata->phydev, true);
5799                 if (!pdata->suspended)
5800                         phy_stop_interrupts(pdata->phydev);
5801         } else if (pdata->phydev) {
5802                 /* stop the PHY */
5803                 phy_stop(pdata->phydev);
5804                 gpio_set_value(pdata->phy_reset_gpio, 0);
5805         }
5806
5807         /* Stop the PHY state machine */
5808         if (pdata->phydev)
5809                 phy_stop_machine(pdata->phydev);
5810
5811         /* turn off sources of data into dev */
5812         netif_tx_disable(pdata->dev);
5813
5814         hw_if->stop_mac_rx();
5815         eqos_disable_all_irqs(pdata);
5816         eqos_all_ch_napi_disable(pdata);
5817
5818         /* Ensure no tx thread is running.  We have
5819          * already prevented any new callers of or tx thread above.
5820          * Below will allow any remaining tx threads to complete.
5821          */
5822         for (i = 0; i < pdata->num_chans; i++) {
5823                 spin_lock(&pdata->chinfo[i].chan_tx_lock);
5824                 spin_unlock(&pdata->chinfo[i].chan_tx_lock);
5825         }
5826
5827         /* stop DMA TX */
5828         eqos_stop_all_ch_tx_dma(pdata);
5829
5830         /* disable MAC TX */
5831         hw_if->stop_mac_tx();
5832
5833         /* stop DMA RX */
5834         eqos_stop_all_ch_rx_dma(pdata);
5835
5836         del_timer_sync(&pdata->eee_ctrl_timer);
5837
5838         /* return tx skbs */
5839         desc_if->tx_skb_free_mem(pdata, pdata->num_chans);
5840
5841         /* free rx skb's */
5842         desc_if->rx_skb_free_mem(pdata, pdata->num_chans);
5843
5844         pr_debug("<--%s()\n", __func__);
5845 }
5846
5847 void eqos_start_dev(struct eqos_prv_data *pdata)
5848 {
5849         struct hw_if_struct *hw_if = &pdata->hw_if;
5850         struct desc_if_struct *desc_if = &pdata->desc_if;
5851
5852         pr_debug("-->%s()\n", __func__);
5853
5854         if (pdata->phydev->drv->low_power_mode) {
5855                 /* reset the PHY Broadcom PHY needs minimum of 2us delay */
5856                 pr_debug("%s(): exit from iddq-lp mode\n", __func__);
5857                 gpio_set_value(pdata->phy_reset_gpio, 0);
5858                 usleep_range(10, 11);
5859                 gpio_set_value(pdata->phy_reset_gpio, 1);
5860                 pdata->phydev->drv->low_power_mode(pdata->phydev, false);
5861         } else if (!gpio_get_value(pdata->phy_reset_gpio))
5862         {
5863                 /* deassert phy reset */
5864                 gpio_set_value(pdata->phy_reset_gpio, 1);
5865         }
5866
5867         /* issue CAR reset to device */
5868         hw_if->car_reset(pdata);
5869         hw_if->pad_calibrate(pdata);
5870
5871         if (pdata->phydev->drv->low_power_mode) {
5872                 if (pdata->suspended == 0 && netif_running(pdata->dev))
5873                         phy_start_interrupts(pdata->phydev);
5874         }
5875
5876         /* default configuration */
5877         eqos_default_common_confs(pdata);
5878         eqos_default_tx_confs(pdata);
5879         eqos_default_rx_confs(pdata);
5880         eqos_configure_rx_fun_ptr(pdata);
5881
5882         desc_if->wrapper_tx_desc_init(pdata);
5883         desc_if->wrapper_rx_desc_init(pdata);
5884
5885         eqos_napi_enable_mq(pdata);
5886
5887         eqos_set_rx_mode(pdata->dev);
5888         eqos_mmc_setup(pdata);
5889
5890         /* initializes MAC and DMA */
5891         hw_if->init(pdata);
5892
5893         MAC_1US_TIC_WR(pdata->csr_clock_speed - 1);
5894
5895         if (pdata->hw_feat.pcs_sel)
5896                 hw_if->control_an(1, 0);
5897
5898         if (pdata->phydev) {
5899                 pdata->oldlink = 0;
5900                 pdata->speed = 0;
5901                 pdata->oldduplex = -1;
5902
5903                 phy_start(pdata->phydev);
5904                 phy_start_machine(pdata->phydev);
5905         }
5906 #ifdef EQOS_ENABLE_EEE
5907         if (pdata->phydev)
5908                 pdata->eee_enabled = eqos_eee_init(pdata);
5909         else
5910                 pdata->eee_enabled = false;
5911 #else
5912         pdata->eee_enabled = false;
5913 #endif
5914
5915         if (pdata->phydev)
5916                 netif_tx_start_all_queues(pdata->dev);
5917
5918         pr_debug("<--%s()\n", __func__);
5919 }
5920
5921 void eqos_iso_work(struct work_struct *work)
5922 {
5923         struct eqos_prv_data *pdata =
5924             container_of(work, struct eqos_prv_data, iso_work);
5925         struct phy_device *phydev = pdata->phydev;
5926         struct eqos_cfg *pdt_cfg = (struct eqos_cfg *)&pdata->dt_cfg;
5927         int ret;
5928         uint iso_bw;
5929
5930         pr_debug("-->%s()\n", __func__);
5931
5932         if (pdt_cfg->eth_iso_enable) {
5933                 if (phydev->link)
5934                         iso_bw = pdata->dt_cfg.iso_bw;
5935                 else
5936                         iso_bw = 0;
5937
5938                 ret = tegra_isomgr_reserve(pdata->isomgr_handle, iso_bw, 0);
5939                 if (!ret) {
5940                         dev_err(&pdata->pdev->dev,
5941                                 "EQOS ISO BW %d reservation failed with %d\n",
5942                                 iso_bw, ret);
5943                         return;
5944                 }
5945
5946                 ret = tegra_isomgr_realize(pdata->isomgr_handle);
5947                 if (!ret)
5948                         dev_err(&pdata->pdev->dev,
5949                                 "EQOS ISO BW realize failed with %d\n", ret);
5950         }
5951
5952         pr_debug("<--%s()\n", __func__);
5953 }
5954 void eqos_fbe_work(struct work_struct *work)
5955 {
5956         struct eqos_prv_data *pdata =
5957             container_of(work, struct eqos_prv_data, fbe_work);
5958         int i;
5959         u32 dma_sr_reg;
5960
5961         pr_debug("-->%s()\n", __func__);
5962
5963         mutex_lock(&pdata->hw_change_lock);
5964         if (pdata->hw_stopped)
5965                 goto out;
5966
5967         i = 0;
5968         while (pdata->fbe_chan_mask) {
5969                 if (pdata->fbe_chan_mask & 1) {
5970                         DMA_SR_RD(i, dma_sr_reg);
5971
5972                         dev_err(&pdata->pdev->dev,
5973                                 "Fatal Bus Error on chan %d, SRreg=0x%.8x\n",
5974                                 i, dma_sr_reg);
5975                 }
5976                 pdata->fbe_chan_mask >>= 1;
5977                 i++;
5978         }
5979         eqos_stop_dev(pdata);
5980         eqos_start_dev(pdata);
5981 out:
5982         mutex_unlock(&pdata->hw_change_lock);
5983
5984         pr_debug("<--%s()\n", __func__);
5985 }