2 * Copyright (c) 2017-2018 Cavium, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
31 * Author : David C Somayajulu, Cavium, Inc., San Jose, CA 95131.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
40 #include "ecore_gtt_reg_addr.h"
42 #include "ecore_chain.h"
43 #include "ecore_status.h"
45 #include "ecore_rt_defs.h"
46 #include "ecore_init_ops.h"
47 #include "ecore_int.h"
48 #include "ecore_cxt.h"
49 #include "ecore_spq.h"
50 #include "ecore_init_fw_funcs.h"
51 #include "ecore_sp_commands.h"
52 #include "ecore_dev_api.h"
53 #include "ecore_l2_api.h"
54 #include "ecore_mcp.h"
55 #include "ecore_hw_defs.h"
56 #include "mcp_public.h"
57 #include "ecore_iro.h"
59 #include "ecore_dev_api.h"
60 #include "ecore_dbg_fw_funcs.h"
62 #include "qlnx_ioctl.h"
72 * ioctl related functions
74 static void qlnx_add_sysctls(qlnx_host_t *ha);
79 static void qlnx_release(qlnx_host_t *ha);
80 static void qlnx_fp_isr(void *arg);
81 static void qlnx_init_ifnet(device_t dev, qlnx_host_t *ha);
82 static void qlnx_init(void *arg);
83 static void qlnx_init_locked(qlnx_host_t *ha);
84 static int qlnx_set_multi(qlnx_host_t *ha, uint32_t add_multi);
85 static int qlnx_set_promisc(qlnx_host_t *ha);
86 static int qlnx_set_allmulti(qlnx_host_t *ha);
87 static int qlnx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
88 static int qlnx_media_change(struct ifnet *ifp);
89 static void qlnx_media_status(struct ifnet *ifp, struct ifmediareq *ifmr);
90 static void qlnx_stop(qlnx_host_t *ha);
91 static int qlnx_send(qlnx_host_t *ha, struct qlnx_fastpath *fp,
92 struct mbuf **m_headp);
93 static int qlnx_get_ifq_snd_maxlen(qlnx_host_t *ha);
94 static uint32_t qlnx_get_optics(qlnx_host_t *ha,
95 struct qlnx_link_output *if_link);
96 static int qlnx_transmit(struct ifnet *ifp, struct mbuf *mp);
97 static void qlnx_qflush(struct ifnet *ifp);
99 static int qlnx_alloc_parent_dma_tag(qlnx_host_t *ha);
100 static void qlnx_free_parent_dma_tag(qlnx_host_t *ha);
101 static int qlnx_alloc_tx_dma_tag(qlnx_host_t *ha);
102 static void qlnx_free_tx_dma_tag(qlnx_host_t *ha);
103 static int qlnx_alloc_rx_dma_tag(qlnx_host_t *ha);
104 static void qlnx_free_rx_dma_tag(qlnx_host_t *ha);
106 static int qlnx_get_mfw_version(qlnx_host_t *ha, uint32_t *mfw_ver);
107 static int qlnx_get_flash_size(qlnx_host_t *ha, uint32_t *flash_size);
109 static int qlnx_nic_setup(struct ecore_dev *cdev,
110 struct ecore_pf_params *func_params);
111 static int qlnx_nic_start(struct ecore_dev *cdev);
112 static int qlnx_slowpath_start(qlnx_host_t *ha);
113 static int qlnx_slowpath_stop(qlnx_host_t *ha);
114 static int qlnx_init_hw(qlnx_host_t *ha);
115 static void qlnx_set_id(struct ecore_dev *cdev, char name[NAME_SIZE],
116 char ver_str[VER_SIZE]);
117 static void qlnx_unload(qlnx_host_t *ha);
118 static int qlnx_load(qlnx_host_t *ha);
119 static void qlnx_hw_set_multi(qlnx_host_t *ha, uint8_t *mta, uint32_t mcnt,
121 static void qlnx_dump_buf8(qlnx_host_t *ha, const char *msg, void *dbuf,
123 static int qlnx_alloc_rx_buffer(qlnx_host_t *ha, struct qlnx_rx_queue *rxq);
124 static void qlnx_reuse_rx_data(struct qlnx_rx_queue *rxq);
125 static void qlnx_update_rx_prod(struct ecore_hwfn *p_hwfn,
126 struct qlnx_rx_queue *rxq);
127 static int qlnx_set_rx_accept_filter(qlnx_host_t *ha, uint8_t filter);
128 static int qlnx_grc_dumpsize(qlnx_host_t *ha, uint32_t *num_dwords,
130 static int qlnx_idle_chk_size(qlnx_host_t *ha, uint32_t *num_dwords,
132 static void qlnx_timer(void *arg);
133 static int qlnx_alloc_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp);
134 static void qlnx_free_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp);
135 static void qlnx_trigger_dump(qlnx_host_t *ha);
136 static void qlnx_tx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp,
137 struct qlnx_tx_queue *txq);
138 static int qlnx_rx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp, int budget,
140 static void qlnx_fp_taskqueue(void *context, int pending);
141 static void qlnx_sample_storm_stats(qlnx_host_t *ha);
142 static int qlnx_alloc_tpa_mbuf(qlnx_host_t *ha, uint16_t rx_buf_size,
143 struct qlnx_agg_info *tpa);
144 static void qlnx_free_tpa_mbuf(qlnx_host_t *ha, struct qlnx_agg_info *tpa);
146 #if __FreeBSD_version >= 1100000
147 static uint64_t qlnx_get_counter(if_t ifp, ift_counter cnt);
152 * Hooks to the Operating Systems
154 static int qlnx_pci_probe (device_t);
155 static int qlnx_pci_attach (device_t);
156 static int qlnx_pci_detach (device_t);
158 static device_method_t qlnx_pci_methods[] = {
159 /* Device interface */
160 DEVMETHOD(device_probe, qlnx_pci_probe),
161 DEVMETHOD(device_attach, qlnx_pci_attach),
162 DEVMETHOD(device_detach, qlnx_pci_detach),
166 static driver_t qlnx_pci_driver = {
167 "ql", qlnx_pci_methods, sizeof (qlnx_host_t),
170 static devclass_t qlnx_devclass;
172 MODULE_VERSION(if_qlnxe,1);
173 DRIVER_MODULE(if_qlnxe, pci, qlnx_pci_driver, qlnx_devclass, 0, 0);
175 MODULE_DEPEND(if_qlnxe, pci, 1, 1, 1);
176 MODULE_DEPEND(if_qlnxe, ether, 1, 1, 1);
178 MALLOC_DEFINE(M_QLNXBUF, "qlnxbuf", "Buffers for qlnx driver");
181 char qlnx_dev_str[64];
182 char qlnx_ver_str[VER_SIZE];
183 char qlnx_name_str[NAME_SIZE];
186 * Some PCI Configuration Space Related Defines
189 #ifndef PCI_VENDOR_QLOGIC
190 #define PCI_VENDOR_QLOGIC 0x1077
193 /* 40G Adapter QLE45xxx*/
194 #ifndef QLOGIC_PCI_DEVICE_ID_1634
195 #define QLOGIC_PCI_DEVICE_ID_1634 0x1634
198 /* 100G Adapter QLE45xxx*/
199 #ifndef QLOGIC_PCI_DEVICE_ID_1644
200 #define QLOGIC_PCI_DEVICE_ID_1644 0x1644
203 /* 25G Adapter QLE45xxx*/
204 #ifndef QLOGIC_PCI_DEVICE_ID_1656
205 #define QLOGIC_PCI_DEVICE_ID_1656 0x1656
208 /* 50G Adapter QLE45xxx*/
209 #ifndef QLOGIC_PCI_DEVICE_ID_1654
210 #define QLOGIC_PCI_DEVICE_ID_1654 0x1654
214 qlnx_valid_device(device_t dev)
218 device_id = pci_get_device(dev);
220 if ((device_id == QLOGIC_PCI_DEVICE_ID_1634) ||
221 (device_id == QLOGIC_PCI_DEVICE_ID_1644) ||
222 (device_id == QLOGIC_PCI_DEVICE_ID_1656) ||
223 (device_id == QLOGIC_PCI_DEVICE_ID_1654))
230 * Name: qlnx_pci_probe
231 * Function: Validate the PCI device to be a QLA80XX device
234 qlnx_pci_probe(device_t dev)
236 snprintf(qlnx_ver_str, sizeof(qlnx_ver_str), "v%d.%d.%d",
237 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR, QLNX_VERSION_BUILD);
238 snprintf(qlnx_name_str, sizeof(qlnx_name_str), "qlnx");
240 if (pci_get_vendor(dev) != PCI_VENDOR_QLOGIC) {
244 switch (pci_get_device(dev)) {
246 case QLOGIC_PCI_DEVICE_ID_1644:
247 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
248 "Qlogic 100GbE PCI CNA Adapter-Ethernet Function",
249 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
251 device_set_desc_copy(dev, qlnx_dev_str);
255 case QLOGIC_PCI_DEVICE_ID_1634:
256 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
257 "Qlogic 40GbE PCI CNA Adapter-Ethernet Function",
258 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
260 device_set_desc_copy(dev, qlnx_dev_str);
264 case QLOGIC_PCI_DEVICE_ID_1656:
265 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
266 "Qlogic 25GbE PCI CNA Adapter-Ethernet Function",
267 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
269 device_set_desc_copy(dev, qlnx_dev_str);
273 case QLOGIC_PCI_DEVICE_ID_1654:
274 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
275 "Qlogic 50GbE PCI CNA Adapter-Ethernet Function",
276 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
278 device_set_desc_copy(dev, qlnx_dev_str);
286 return (BUS_PROBE_DEFAULT);
291 qlnx_sp_intr(void *arg)
293 struct ecore_hwfn *p_hwfn;
299 if (p_hwfn == NULL) {
300 printf("%s: spurious slowpath intr\n", __func__);
304 ha = (qlnx_host_t *)p_hwfn->p_dev;
306 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
308 for (i = 0; i < ha->cdev.num_hwfns; i++) {
309 if (&ha->cdev.hwfns[i] == p_hwfn) {
310 taskqueue_enqueue(ha->sp_taskqueue[i], &ha->sp_task[i]);
314 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
320 qlnx_sp_taskqueue(void *context, int pending)
322 struct ecore_hwfn *p_hwfn;
326 if (p_hwfn != NULL) {
333 qlnx_create_sp_taskqueues(qlnx_host_t *ha)
338 for (i = 0; i < ha->cdev.num_hwfns; i++) {
340 struct ecore_hwfn *p_hwfn = &ha->cdev.hwfns[i];
342 bzero(tq_name, sizeof (tq_name));
343 snprintf(tq_name, sizeof (tq_name), "ql_sp_tq_%d", i);
345 TASK_INIT(&ha->sp_task[i], 0, qlnx_sp_taskqueue, p_hwfn);
347 ha->sp_taskqueue[i] = taskqueue_create_fast(tq_name, M_NOWAIT,
348 taskqueue_thread_enqueue, &ha->sp_taskqueue[i]);
350 if (ha->sp_taskqueue[i] == NULL)
353 taskqueue_start_threads(&ha->sp_taskqueue[i], 1, PI_NET, "%s",
356 QL_DPRINT1(ha, (ha->pci_dev, "%s: %p\n", __func__,
357 ha->sp_taskqueue[i]));
364 qlnx_destroy_sp_taskqueues(qlnx_host_t *ha)
368 for (i = 0; i < ha->cdev.num_hwfns; i++) {
369 if (ha->sp_taskqueue[i] != NULL) {
370 taskqueue_drain(ha->sp_taskqueue[i], &ha->sp_task[i]);
371 taskqueue_free(ha->sp_taskqueue[i]);
378 qlnx_fp_taskqueue(void *context, int pending)
380 struct qlnx_fastpath *fp;
391 ha = (qlnx_host_t *)fp->edev;
395 mtx_lock(&fp->tx_mtx);
397 if (((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
398 IFF_DRV_RUNNING) || (!ha->link_up)) {
400 mtx_unlock(&fp->tx_mtx);
401 goto qlnx_fp_taskqueue_exit;
404 (void)qlnx_tx_int(ha, fp, fp->txq[0]);
406 mp = drbr_peek(ifp, fp->tx_br);
410 ret = qlnx_send(ha, fp, &mp);
415 drbr_putback(ifp, fp->tx_br, mp);
417 fp->tx_pkts_processed++;
418 drbr_advance(ifp, fp->tx_br);
421 mtx_unlock(&fp->tx_mtx);
423 goto qlnx_fp_taskqueue_exit;
426 drbr_advance(ifp, fp->tx_br);
427 fp->tx_pkts_transmitted++;
428 fp->tx_pkts_processed++;
431 mp = drbr_peek(ifp, fp->tx_br);
434 (void)qlnx_tx_int(ha, fp, fp->txq[0]);
436 mtx_unlock(&fp->tx_mtx);
438 qlnx_fp_taskqueue_exit:
440 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = %d\n", __func__, ret));
445 qlnx_create_fp_taskqueues(qlnx_host_t *ha)
449 struct qlnx_fastpath *fp;
451 for (i = 0; i < ha->num_rss; i++) {
453 fp = &ha->fp_array[i];
455 bzero(tq_name, sizeof (tq_name));
456 snprintf(tq_name, sizeof (tq_name), "ql_fp_tq_%d", i);
458 TASK_INIT(&fp->fp_task, 0, qlnx_fp_taskqueue, fp);
460 fp->fp_taskqueue = taskqueue_create_fast(tq_name, M_NOWAIT,
461 taskqueue_thread_enqueue,
464 if (fp->fp_taskqueue == NULL)
467 taskqueue_start_threads(&fp->fp_taskqueue, 1, PI_NET, "%s",
470 QL_DPRINT1(ha, (ha->pci_dev, "%s: %p\n", __func__,
478 qlnx_destroy_fp_taskqueues(qlnx_host_t *ha)
481 struct qlnx_fastpath *fp;
483 for (i = 0; i < ha->num_rss; i++) {
485 fp = &ha->fp_array[i];
487 if (fp->fp_taskqueue != NULL) {
489 taskqueue_drain(fp->fp_taskqueue, &fp->fp_task);
490 taskqueue_free(fp->fp_taskqueue);
491 fp->fp_taskqueue = NULL;
498 qlnx_drain_fp_taskqueues(qlnx_host_t *ha)
501 struct qlnx_fastpath *fp;
503 for (i = 0; i < ha->num_rss; i++) {
504 fp = &ha->fp_array[i];
506 if (fp->fp_taskqueue != NULL) {
507 taskqueue_drain(fp->fp_taskqueue, &fp->fp_task);
514 * Name: qlnx_pci_attach
515 * Function: attaches the device to the operating system
518 qlnx_pci_attach(device_t dev)
520 qlnx_host_t *ha = NULL;
521 uint32_t rsrc_len_reg = 0;
522 uint32_t rsrc_len_dbells = 0;
523 uint32_t rsrc_len_msix = 0;
527 if ((ha = device_get_softc(dev)) == NULL) {
528 device_printf(dev, "cannot get softc\n");
532 memset(ha, 0, sizeof (qlnx_host_t));
534 if (qlnx_valid_device(dev) != 0) {
535 device_printf(dev, "device is not valid device\n");
538 ha->pci_func = pci_get_function(dev);
542 mtx_init(&ha->hw_lock, "qlnx_hw_lock", MTX_NETWORK_LOCK, MTX_DEF);
543 mtx_init(&ha->tx_lock, "qlnx_tx_lock", MTX_NETWORK_LOCK, MTX_DEF);
545 ha->flags.lock_init = 1;
547 pci_enable_busmaster(dev);
553 ha->reg_rid = PCIR_BAR(0);
554 ha->pci_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &ha->reg_rid,
557 if (ha->pci_reg == NULL) {
558 device_printf(dev, "unable to map BAR0\n");
559 goto qlnx_pci_attach_err;
562 rsrc_len_reg = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
565 ha->dbells_rid = PCIR_BAR(2);
566 ha->pci_dbells = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
567 &ha->dbells_rid, RF_ACTIVE);
569 if (ha->pci_dbells == NULL) {
570 device_printf(dev, "unable to map BAR1\n");
571 goto qlnx_pci_attach_err;
574 rsrc_len_dbells = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
577 ha->dbells_phys_addr = (uint64_t)
578 bus_get_resource_start(dev, SYS_RES_MEMORY, ha->dbells_rid);;
579 ha->dbells_size = rsrc_len_dbells;
581 ha->msix_rid = PCIR_BAR(4);
582 ha->msix_bar = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
583 &ha->msix_rid, RF_ACTIVE);
585 if (ha->msix_bar == NULL) {
586 device_printf(dev, "unable to map BAR2\n");
587 goto qlnx_pci_attach_err;
590 rsrc_len_msix = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
596 if (qlnx_alloc_parent_dma_tag(ha))
597 goto qlnx_pci_attach_err;
599 if (qlnx_alloc_tx_dma_tag(ha))
600 goto qlnx_pci_attach_err;
602 if (qlnx_alloc_rx_dma_tag(ha))
603 goto qlnx_pci_attach_err;
606 if (qlnx_init_hw(ha) != 0)
607 goto qlnx_pci_attach_err;
610 * Allocate MSI-x vectors
612 ha->num_rss = QLNX_MAX_RSS;
613 ha->num_tc = QLNX_MAX_TC;
615 ha->msix_count = pci_msix_count(dev);
617 if (ha->msix_count > (mp_ncpus + ha->cdev.num_hwfns))
618 ha->msix_count = mp_ncpus + ha->cdev.num_hwfns;
620 if (!ha->msix_count ||
621 (ha->msix_count < (ha->cdev.num_hwfns + 1 ))) {
622 device_printf(dev, "%s: msix_count[%d] not enough\n", __func__,
624 goto qlnx_pci_attach_err;
627 if (ha->msix_count > (ha->num_rss + ha->cdev.num_hwfns ))
628 ha->msix_count = ha->num_rss + ha->cdev.num_hwfns;
630 ha->num_rss = ha->msix_count - ha->cdev.num_hwfns;
632 QL_DPRINT1(ha, (dev, "%s:\n\t\t\tpci_reg [%p, 0x%08x 0x%08x]"
633 "\n\t\t\tdbells [%p, 0x%08x 0x%08x]"
634 "\n\t\t\tmsix [%p, 0x%08x 0x%08x 0x%x 0x%x]"
635 "\n\t\t\t[ncpus = %d][num_rss = 0x%x] [num_tc = 0x%x]\n",
636 __func__, ha->pci_reg, rsrc_len_reg,
637 ha->reg_rid, ha->pci_dbells, rsrc_len_dbells, ha->dbells_rid,
638 ha->msix_bar, rsrc_len_msix, ha->msix_rid, pci_msix_count(dev),
639 ha->msix_count, mp_ncpus, ha->num_rss, ha->num_tc));
641 if (pci_alloc_msix(dev, &ha->msix_count)) {
642 device_printf(dev, "%s: pci_alloc_msix[%d] failed\n", __func__,
645 goto qlnx_pci_attach_err;
649 * Initialize slow path interrupt and task queue
651 if (qlnx_create_sp_taskqueues(ha) != 0)
652 goto qlnx_pci_attach_err;
654 for (i = 0; i < ha->cdev.num_hwfns; i++) {
656 struct ecore_hwfn *p_hwfn = &ha->cdev.hwfns[i];
658 ha->sp_irq_rid[i] = i + 1;
659 ha->sp_irq[i] = bus_alloc_resource_any(dev, SYS_RES_IRQ,
661 (RF_ACTIVE | RF_SHAREABLE));
662 if (ha->sp_irq[i] == NULL) {
664 "could not allocate mbx interrupt\n");
665 goto qlnx_pci_attach_err;
668 if (bus_setup_intr(dev, ha->sp_irq[i],
669 (INTR_TYPE_NET | INTR_MPSAFE), NULL,
670 qlnx_sp_intr, p_hwfn, &ha->sp_handle[i])) {
672 "could not setup slow path interrupt\n");
673 goto qlnx_pci_attach_err;
676 QL_DPRINT1(ha, (dev, "%s: p_hwfn [%p] sp_irq_rid %d"
677 " sp_irq %p sp_handle %p\n", __func__, p_hwfn,
678 ha->sp_irq_rid[i], ha->sp_irq[i], ha->sp_handle[i]));
683 * initialize fast path interrupt
685 if (qlnx_create_fp_taskqueues(ha) != 0)
686 goto qlnx_pci_attach_err;
688 for (i = 0; i < ha->num_rss; i++) {
689 ha->irq_vec[i].rss_idx = i;
690 ha->irq_vec[i].ha = ha;
691 ha->irq_vec[i].irq_rid = (1 + ha->cdev.num_hwfns) + i;
693 ha->irq_vec[i].irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
694 &ha->irq_vec[i].irq_rid,
695 (RF_ACTIVE | RF_SHAREABLE));
697 if (ha->irq_vec[i].irq == NULL) {
699 "could not allocate interrupt[%d]\n", i);
700 goto qlnx_pci_attach_err;
703 if (qlnx_alloc_tx_br(ha, &ha->fp_array[i])) {
704 device_printf(dev, "could not allocate tx_br[%d]\n", i);
705 goto qlnx_pci_attach_err;
710 callout_init(&ha->qlnx_callout, 1);
711 ha->flags.callout_init = 1;
713 for (i = 0; i < ha->cdev.num_hwfns; i++) {
715 if (qlnx_grc_dumpsize(ha, &ha->grcdump_size[i], i) != 0)
716 goto qlnx_pci_attach_err;
717 if (ha->grcdump_size[i] == 0)
718 goto qlnx_pci_attach_err;
720 ha->grcdump_size[i] = ha->grcdump_size[i] << 2;
721 QL_DPRINT1(ha, (dev, "grcdump_size[%d] = 0x%08x\n",
722 i, ha->grcdump_size[i]));
724 ha->grcdump[i] = qlnx_zalloc(ha->grcdump_size[i]);
725 if (ha->grcdump[i] == NULL) {
726 device_printf(dev, "grcdump alloc[%d] failed\n", i);
727 goto qlnx_pci_attach_err;
730 if (qlnx_idle_chk_size(ha, &ha->idle_chk_size[i], i) != 0)
731 goto qlnx_pci_attach_err;
732 if (ha->idle_chk_size[i] == 0)
733 goto qlnx_pci_attach_err;
735 ha->idle_chk_size[i] = ha->idle_chk_size[i] << 2;
736 QL_DPRINT1(ha, (dev, "idle_chk_size[%d] = 0x%08x\n",
737 i, ha->idle_chk_size[i]));
739 ha->idle_chk[i] = qlnx_zalloc(ha->idle_chk_size[i]);
741 if (ha->idle_chk[i] == NULL) {
742 device_printf(dev, "idle_chk alloc failed\n");
743 goto qlnx_pci_attach_err;
747 if (qlnx_slowpath_start(ha) != 0) {
749 qlnx_mdelay(__func__, 1000);
750 qlnx_trigger_dump(ha);
752 goto qlnx_pci_attach_err0;
754 ha->flags.slowpath_start = 1;
756 if (qlnx_get_flash_size(ha, &ha->flash_size) != 0) {
757 qlnx_mdelay(__func__, 1000);
758 qlnx_trigger_dump(ha);
760 goto qlnx_pci_attach_err0;
763 if (qlnx_get_mfw_version(ha, &mfw_ver) != 0) {
764 qlnx_mdelay(__func__, 1000);
765 qlnx_trigger_dump(ha);
767 goto qlnx_pci_attach_err0;
769 snprintf(ha->mfw_ver, sizeof(ha->mfw_ver), "%d.%d.%d.%d",
770 ((mfw_ver >> 24) & 0xFF), ((mfw_ver >> 16) & 0xFF),
771 ((mfw_ver >> 8) & 0xFF), (mfw_ver & 0xFF));
772 snprintf(ha->stormfw_ver, sizeof(ha->stormfw_ver), "%d.%d.%d.%d",
773 FW_MAJOR_VERSION, FW_MINOR_VERSION, FW_REVISION_VERSION,
774 FW_ENGINEERING_VERSION);
776 QL_DPRINT1(ha, (dev, "%s: STORM_FW version %s MFW version %s\n",
777 __func__, ha->stormfw_ver, ha->mfw_ver));
779 qlnx_init_ifnet(dev, ha);
784 qlnx_add_sysctls(ha);
786 qlnx_pci_attach_err0:
788 * create ioctl device interface
790 if (qlnx_make_cdev(ha)) {
791 device_printf(dev, "%s: ql_make_cdev failed\n", __func__);
792 goto qlnx_pci_attach_err;
795 QL_DPRINT2(ha, (dev, "%s: success\n", __func__));
807 * Name: qlnx_pci_detach
808 * Function: Unhooks the device from the operating system
811 qlnx_pci_detach(device_t dev)
813 qlnx_host_t *ha = NULL;
815 if ((ha = device_get_softc(dev)) == NULL) {
816 device_printf(dev, "cannot get softc\n");
830 qlnx_init_hw(qlnx_host_t *ha)
833 struct ecore_hw_prepare_params params;
835 ecore_init_struct(&ha->cdev);
837 /* ha->dp_module = ECORE_MSG_PROBE |
843 ha->dp_level = ECORE_LEVEL_VERBOSE;*/
844 ha->dp_level = ECORE_LEVEL_NOTICE;
846 ecore_init_dp(&ha->cdev, ha->dp_module, ha->dp_level, ha->pci_dev);
848 ha->cdev.regview = ha->pci_reg;
849 ha->cdev.doorbells = ha->pci_dbells;
850 ha->cdev.db_phys_addr = ha->dbells_phys_addr;
851 ha->cdev.db_size = ha->dbells_size;
853 bzero(¶ms, sizeof (struct ecore_hw_prepare_params));
855 ha->personality = ECORE_PCI_DEFAULT;
857 params.personality = ha->personality;
859 params.drv_resc_alloc = false;
860 params.chk_reg_fifo = false;
861 params.initiate_pf_flr = true;
864 ecore_hw_prepare(&ha->cdev, ¶ms);
866 qlnx_set_id(&ha->cdev, qlnx_name_str, qlnx_ver_str);
872 qlnx_release(qlnx_host_t *ha)
879 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
881 for (i = 0; i < QLNX_MAX_HW_FUNCS; i++) {
882 if (ha->idle_chk[i] != NULL) {
883 free(ha->idle_chk[i], M_QLNXBUF);
884 ha->idle_chk[i] = NULL;
887 if (ha->grcdump[i] != NULL) {
888 free(ha->grcdump[i], M_QLNXBUF);
889 ha->grcdump[i] = NULL;
893 if (ha->flags.callout_init)
894 callout_drain(&ha->qlnx_callout);
896 if (ha->flags.slowpath_start) {
897 qlnx_slowpath_stop(ha);
900 ecore_hw_remove(&ha->cdev);
905 ether_ifdetach(ha->ifp);
907 qlnx_free_tx_dma_tag(ha);
909 qlnx_free_rx_dma_tag(ha);
911 qlnx_free_parent_dma_tag(ha);
913 for (i = 0; i < ha->num_rss; i++) {
914 struct qlnx_fastpath *fp = &ha->fp_array[i];
916 if (ha->irq_vec[i].handle) {
917 (void)bus_teardown_intr(dev, ha->irq_vec[i].irq,
918 ha->irq_vec[i].handle);
921 if (ha->irq_vec[i].irq) {
922 (void)bus_release_resource(dev, SYS_RES_IRQ,
923 ha->irq_vec[i].irq_rid,
927 qlnx_free_tx_br(ha, fp);
929 qlnx_destroy_fp_taskqueues(ha);
931 for (i = 0; i < ha->cdev.num_hwfns; i++) {
932 if (ha->sp_handle[i])
933 (void)bus_teardown_intr(dev, ha->sp_irq[i],
937 (void) bus_release_resource(dev, SYS_RES_IRQ,
938 ha->sp_irq_rid[i], ha->sp_irq[i]);
941 qlnx_destroy_sp_taskqueues(ha);
944 pci_release_msi(dev);
946 if (ha->flags.lock_init) {
947 mtx_destroy(&ha->tx_lock);
948 mtx_destroy(&ha->hw_lock);
952 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid,
956 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->dbells_rid,
960 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->msix_rid,
963 QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
968 qlnx_trigger_dump(qlnx_host_t *ha)
973 ha->ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
975 QL_DPRINT2(ha, (ha->pci_dev, "%s: start\n", __func__));
977 for (i = 0; i < ha->cdev.num_hwfns; i++) {
978 qlnx_grc_dump(ha, &ha->grcdump_dwords[i], i);
979 qlnx_idle_chk(ha, &ha->idle_chk_dwords[i], i);
982 QL_DPRINT2(ha, (ha->pci_dev, "%s: end\n", __func__));
988 qlnx_trigger_dump_sysctl(SYSCTL_HANDLER_ARGS)
993 err = sysctl_handle_int(oidp, &ret, 0, req);
995 if (err || !req->newptr)
999 ha = (qlnx_host_t *)arg1;
1000 qlnx_trigger_dump(ha);
1006 qlnx_set_tx_coalesce(SYSCTL_HANDLER_ARGS)
1008 int err, i, ret = 0, usecs = 0;
1010 struct ecore_hwfn *p_hwfn;
1011 struct qlnx_fastpath *fp;
1013 err = sysctl_handle_int(oidp, &usecs, 0, req);
1015 if (err || !req->newptr || !usecs || (usecs > 255))
1018 ha = (qlnx_host_t *)arg1;
1020 for (i = 0; i < ha->num_rss; i++) {
1022 p_hwfn = &ha->cdev.hwfns[(i % ha->cdev.num_hwfns)];
1024 fp = &ha->fp_array[i];
1026 if (fp->txq[0]->handle != NULL) {
1027 ret = ecore_set_queue_coalesce(p_hwfn, 0,
1028 (uint16_t)usecs, fp->txq[0]->handle);
1033 ha->tx_coalesce_usecs = (uint8_t)usecs;
1039 qlnx_set_rx_coalesce(SYSCTL_HANDLER_ARGS)
1041 int err, i, ret = 0, usecs = 0;
1043 struct ecore_hwfn *p_hwfn;
1044 struct qlnx_fastpath *fp;
1046 err = sysctl_handle_int(oidp, &usecs, 0, req);
1048 if (err || !req->newptr || !usecs || (usecs > 255))
1051 ha = (qlnx_host_t *)arg1;
1053 for (i = 0; i < ha->num_rss; i++) {
1055 p_hwfn = &ha->cdev.hwfns[(i % ha->cdev.num_hwfns)];
1057 fp = &ha->fp_array[i];
1059 if (fp->rxq->handle != NULL) {
1060 ret = ecore_set_queue_coalesce(p_hwfn, (uint16_t)usecs,
1061 0, fp->rxq->handle);
1066 ha->rx_coalesce_usecs = (uint8_t)usecs;
1072 qlnx_add_sp_stats_sysctls(qlnx_host_t *ha)
1074 struct sysctl_ctx_list *ctx;
1075 struct sysctl_oid_list *children;
1076 struct sysctl_oid *ctx_oid;
1078 ctx = device_get_sysctl_ctx(ha->pci_dev);
1079 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev));
1081 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "spstat",
1082 CTLFLAG_RD, NULL, "spstat");
1083 children = SYSCTL_CHILDREN(ctx_oid);
1085 SYSCTL_ADD_QUAD(ctx, children,
1086 OID_AUTO, "sp_interrupts",
1087 CTLFLAG_RD, &ha->sp_interrupts,
1088 "No. of slowpath interrupts");
1094 qlnx_add_fp_stats_sysctls(qlnx_host_t *ha)
1096 struct sysctl_ctx_list *ctx;
1097 struct sysctl_oid_list *children;
1098 struct sysctl_oid_list *node_children;
1099 struct sysctl_oid *ctx_oid;
1101 uint8_t name_str[16];
1103 ctx = device_get_sysctl_ctx(ha->pci_dev);
1104 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev));
1106 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "fpstat",
1107 CTLFLAG_RD, NULL, "fpstat");
1108 children = SYSCTL_CHILDREN(ctx_oid);
1110 for (i = 0; i < ha->num_rss; i++) {
1112 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str)));
1113 snprintf(name_str, sizeof(name_str), "%d", i);
1115 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, name_str,
1116 CTLFLAG_RD, NULL, name_str);
1117 node_children = SYSCTL_CHILDREN(ctx_oid);
1121 SYSCTL_ADD_QUAD(ctx, node_children,
1122 OID_AUTO, "tx_pkts_processed",
1123 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_processed,
1124 "No. of packets processed for transmission");
1126 SYSCTL_ADD_QUAD(ctx, node_children,
1127 OID_AUTO, "tx_pkts_freed",
1128 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_freed,
1129 "No. of freed packets");
1131 SYSCTL_ADD_QUAD(ctx, node_children,
1132 OID_AUTO, "tx_pkts_transmitted",
1133 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_transmitted,
1134 "No. of transmitted packets");
1136 SYSCTL_ADD_QUAD(ctx, node_children,
1137 OID_AUTO, "tx_pkts_completed",
1138 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_completed,
1139 "No. of transmit completions");
1141 SYSCTL_ADD_QUAD(ctx, node_children,
1142 OID_AUTO, "tx_lso_wnd_min_len",
1143 CTLFLAG_RD, &ha->fp_array[i].tx_lso_wnd_min_len,
1144 "tx_lso_wnd_min_len");
1146 SYSCTL_ADD_QUAD(ctx, node_children,
1147 OID_AUTO, "tx_defrag",
1148 CTLFLAG_RD, &ha->fp_array[i].tx_defrag,
1151 SYSCTL_ADD_QUAD(ctx, node_children,
1152 OID_AUTO, "tx_nsegs_gt_elem_left",
1153 CTLFLAG_RD, &ha->fp_array[i].tx_nsegs_gt_elem_left,
1154 "tx_nsegs_gt_elem_left");
1156 SYSCTL_ADD_UINT(ctx, node_children,
1157 OID_AUTO, "tx_tso_max_nsegs",
1158 CTLFLAG_RD, &ha->fp_array[i].tx_tso_max_nsegs,
1159 ha->fp_array[i].tx_tso_max_nsegs, "tx_tso_max_nsegs");
1161 SYSCTL_ADD_UINT(ctx, node_children,
1162 OID_AUTO, "tx_tso_min_nsegs",
1163 CTLFLAG_RD, &ha->fp_array[i].tx_tso_min_nsegs,
1164 ha->fp_array[i].tx_tso_min_nsegs, "tx_tso_min_nsegs");
1166 SYSCTL_ADD_UINT(ctx, node_children,
1167 OID_AUTO, "tx_tso_max_pkt_len",
1168 CTLFLAG_RD, &ha->fp_array[i].tx_tso_max_pkt_len,
1169 ha->fp_array[i].tx_tso_max_pkt_len,
1170 "tx_tso_max_pkt_len");
1172 SYSCTL_ADD_UINT(ctx, node_children,
1173 OID_AUTO, "tx_tso_min_pkt_len",
1174 CTLFLAG_RD, &ha->fp_array[i].tx_tso_min_pkt_len,
1175 ha->fp_array[i].tx_tso_min_pkt_len,
1176 "tx_tso_min_pkt_len");
1178 for (j = 0; j < QLNX_FP_MAX_SEGS; j++) {
1180 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str)));
1181 snprintf(name_str, sizeof(name_str),
1182 "tx_pkts_nseg_%02d", (j+1));
1184 SYSCTL_ADD_QUAD(ctx, node_children,
1185 OID_AUTO, name_str, CTLFLAG_RD,
1186 &ha->fp_array[i].tx_pkts[j], name_str);
1189 SYSCTL_ADD_QUAD(ctx, node_children,
1190 OID_AUTO, "err_tx_nsegs_gt_elem_left",
1191 CTLFLAG_RD, &ha->fp_array[i].err_tx_nsegs_gt_elem_left,
1192 "err_tx_nsegs_gt_elem_left");
1194 SYSCTL_ADD_QUAD(ctx, node_children,
1195 OID_AUTO, "err_tx_dmamap_create",
1196 CTLFLAG_RD, &ha->fp_array[i].err_tx_dmamap_create,
1197 "err_tx_dmamap_create");
1199 SYSCTL_ADD_QUAD(ctx, node_children,
1200 OID_AUTO, "err_tx_defrag_dmamap_load",
1201 CTLFLAG_RD, &ha->fp_array[i].err_tx_defrag_dmamap_load,
1202 "err_tx_defrag_dmamap_load");
1204 SYSCTL_ADD_QUAD(ctx, node_children,
1205 OID_AUTO, "err_tx_non_tso_max_seg",
1206 CTLFLAG_RD, &ha->fp_array[i].err_tx_non_tso_max_seg,
1207 "err_tx_non_tso_max_seg");
1209 SYSCTL_ADD_QUAD(ctx, node_children,
1210 OID_AUTO, "err_tx_dmamap_load",
1211 CTLFLAG_RD, &ha->fp_array[i].err_tx_dmamap_load,
1212 "err_tx_dmamap_load");
1214 SYSCTL_ADD_QUAD(ctx, node_children,
1215 OID_AUTO, "err_tx_defrag",
1216 CTLFLAG_RD, &ha->fp_array[i].err_tx_defrag,
1219 SYSCTL_ADD_QUAD(ctx, node_children,
1220 OID_AUTO, "err_tx_free_pkt_null",
1221 CTLFLAG_RD, &ha->fp_array[i].err_tx_free_pkt_null,
1222 "err_tx_free_pkt_null");
1224 SYSCTL_ADD_QUAD(ctx, node_children,
1225 OID_AUTO, "err_tx_cons_idx_conflict",
1226 CTLFLAG_RD, &ha->fp_array[i].err_tx_cons_idx_conflict,
1227 "err_tx_cons_idx_conflict");
1229 #ifdef QLNX_TRACE_LRO_CNT
1230 SYSCTL_ADD_QUAD(ctx, node_children,
1231 OID_AUTO, "lro_cnt_64",
1232 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_64,
1235 SYSCTL_ADD_QUAD(ctx, node_children,
1236 OID_AUTO, "lro_cnt_128",
1237 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_128,
1240 SYSCTL_ADD_QUAD(ctx, node_children,
1241 OID_AUTO, "lro_cnt_256",
1242 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_256,
1245 SYSCTL_ADD_QUAD(ctx, node_children,
1246 OID_AUTO, "lro_cnt_512",
1247 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_512,
1250 SYSCTL_ADD_QUAD(ctx, node_children,
1251 OID_AUTO, "lro_cnt_1024",
1252 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_1024,
1254 #endif /* #ifdef QLNX_TRACE_LRO_CNT */
1258 SYSCTL_ADD_QUAD(ctx, node_children,
1259 OID_AUTO, "rx_pkts",
1260 CTLFLAG_RD, &ha->fp_array[i].rx_pkts,
1261 "No. of received packets");
1263 SYSCTL_ADD_QUAD(ctx, node_children,
1264 OID_AUTO, "tpa_start",
1265 CTLFLAG_RD, &ha->fp_array[i].tpa_start,
1266 "No. of tpa_start packets");
1268 SYSCTL_ADD_QUAD(ctx, node_children,
1269 OID_AUTO, "tpa_cont",
1270 CTLFLAG_RD, &ha->fp_array[i].tpa_cont,
1271 "No. of tpa_cont packets");
1273 SYSCTL_ADD_QUAD(ctx, node_children,
1274 OID_AUTO, "tpa_end",
1275 CTLFLAG_RD, &ha->fp_array[i].tpa_end,
1276 "No. of tpa_end packets");
1278 SYSCTL_ADD_QUAD(ctx, node_children,
1279 OID_AUTO, "err_m_getcl",
1280 CTLFLAG_RD, &ha->fp_array[i].err_m_getcl,
1283 SYSCTL_ADD_QUAD(ctx, node_children,
1284 OID_AUTO, "err_m_getjcl",
1285 CTLFLAG_RD, &ha->fp_array[i].err_m_getjcl,
1288 SYSCTL_ADD_QUAD(ctx, node_children,
1289 OID_AUTO, "err_rx_hw_errors",
1290 CTLFLAG_RD, &ha->fp_array[i].err_rx_hw_errors,
1291 "err_rx_hw_errors");
1293 SYSCTL_ADD_QUAD(ctx, node_children,
1294 OID_AUTO, "err_rx_alloc_errors",
1295 CTLFLAG_RD, &ha->fp_array[i].err_rx_alloc_errors,
1296 "err_rx_alloc_errors");
1303 qlnx_add_hw_stats_sysctls(qlnx_host_t *ha)
1305 struct sysctl_ctx_list *ctx;
1306 struct sysctl_oid_list *children;
1307 struct sysctl_oid *ctx_oid;
1309 ctx = device_get_sysctl_ctx(ha->pci_dev);
1310 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev));
1312 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "hwstat",
1313 CTLFLAG_RD, NULL, "hwstat");
1314 children = SYSCTL_CHILDREN(ctx_oid);
1316 SYSCTL_ADD_QUAD(ctx, children,
1317 OID_AUTO, "no_buff_discards",
1318 CTLFLAG_RD, &ha->hw_stats.common.no_buff_discards,
1319 "No. of packets discarded due to lack of buffer");
1321 SYSCTL_ADD_QUAD(ctx, children,
1322 OID_AUTO, "packet_too_big_discard",
1323 CTLFLAG_RD, &ha->hw_stats.common.packet_too_big_discard,
1324 "No. of packets discarded because packet was too big");
1326 SYSCTL_ADD_QUAD(ctx, children,
1327 OID_AUTO, "ttl0_discard",
1328 CTLFLAG_RD, &ha->hw_stats.common.ttl0_discard,
1331 SYSCTL_ADD_QUAD(ctx, children,
1332 OID_AUTO, "rx_ucast_bytes",
1333 CTLFLAG_RD, &ha->hw_stats.common.rx_ucast_bytes,
1336 SYSCTL_ADD_QUAD(ctx, children,
1337 OID_AUTO, "rx_mcast_bytes",
1338 CTLFLAG_RD, &ha->hw_stats.common.rx_mcast_bytes,
1341 SYSCTL_ADD_QUAD(ctx, children,
1342 OID_AUTO, "rx_bcast_bytes",
1343 CTLFLAG_RD, &ha->hw_stats.common.rx_bcast_bytes,
1346 SYSCTL_ADD_QUAD(ctx, children,
1347 OID_AUTO, "rx_ucast_pkts",
1348 CTLFLAG_RD, &ha->hw_stats.common.rx_ucast_pkts,
1351 SYSCTL_ADD_QUAD(ctx, children,
1352 OID_AUTO, "rx_mcast_pkts",
1353 CTLFLAG_RD, &ha->hw_stats.common.rx_mcast_pkts,
1356 SYSCTL_ADD_QUAD(ctx, children,
1357 OID_AUTO, "rx_bcast_pkts",
1358 CTLFLAG_RD, &ha->hw_stats.common.rx_bcast_pkts,
1361 SYSCTL_ADD_QUAD(ctx, children,
1362 OID_AUTO, "mftag_filter_discards",
1363 CTLFLAG_RD, &ha->hw_stats.common.mftag_filter_discards,
1364 "mftag_filter_discards");
1366 SYSCTL_ADD_QUAD(ctx, children,
1367 OID_AUTO, "mac_filter_discards",
1368 CTLFLAG_RD, &ha->hw_stats.common.mac_filter_discards,
1369 "mac_filter_discards");
1371 SYSCTL_ADD_QUAD(ctx, children,
1372 OID_AUTO, "tx_ucast_bytes",
1373 CTLFLAG_RD, &ha->hw_stats.common.tx_ucast_bytes,
1376 SYSCTL_ADD_QUAD(ctx, children,
1377 OID_AUTO, "tx_mcast_bytes",
1378 CTLFLAG_RD, &ha->hw_stats.common.tx_mcast_bytes,
1381 SYSCTL_ADD_QUAD(ctx, children,
1382 OID_AUTO, "tx_bcast_bytes",
1383 CTLFLAG_RD, &ha->hw_stats.common.tx_bcast_bytes,
1386 SYSCTL_ADD_QUAD(ctx, children,
1387 OID_AUTO, "tx_ucast_pkts",
1388 CTLFLAG_RD, &ha->hw_stats.common.tx_ucast_pkts,
1391 SYSCTL_ADD_QUAD(ctx, children,
1392 OID_AUTO, "tx_mcast_pkts",
1393 CTLFLAG_RD, &ha->hw_stats.common.tx_mcast_pkts,
1396 SYSCTL_ADD_QUAD(ctx, children,
1397 OID_AUTO, "tx_bcast_pkts",
1398 CTLFLAG_RD, &ha->hw_stats.common.tx_bcast_pkts,
1401 SYSCTL_ADD_QUAD(ctx, children,
1402 OID_AUTO, "tx_err_drop_pkts",
1403 CTLFLAG_RD, &ha->hw_stats.common.tx_err_drop_pkts,
1404 "tx_err_drop_pkts");
1406 SYSCTL_ADD_QUAD(ctx, children,
1407 OID_AUTO, "tpa_coalesced_pkts",
1408 CTLFLAG_RD, &ha->hw_stats.common.tpa_coalesced_pkts,
1409 "tpa_coalesced_pkts");
1411 SYSCTL_ADD_QUAD(ctx, children,
1412 OID_AUTO, "tpa_coalesced_events",
1413 CTLFLAG_RD, &ha->hw_stats.common.tpa_coalesced_events,
1414 "tpa_coalesced_events");
1416 SYSCTL_ADD_QUAD(ctx, children,
1417 OID_AUTO, "tpa_aborts_num",
1418 CTLFLAG_RD, &ha->hw_stats.common.tpa_aborts_num,
1421 SYSCTL_ADD_QUAD(ctx, children,
1422 OID_AUTO, "tpa_not_coalesced_pkts",
1423 CTLFLAG_RD, &ha->hw_stats.common.tpa_not_coalesced_pkts,
1424 "tpa_not_coalesced_pkts");
1426 SYSCTL_ADD_QUAD(ctx, children,
1427 OID_AUTO, "tpa_coalesced_bytes",
1428 CTLFLAG_RD, &ha->hw_stats.common.tpa_coalesced_bytes,
1429 "tpa_coalesced_bytes");
1431 SYSCTL_ADD_QUAD(ctx, children,
1432 OID_AUTO, "rx_64_byte_packets",
1433 CTLFLAG_RD, &ha->hw_stats.common.rx_64_byte_packets,
1434 "rx_64_byte_packets");
1436 SYSCTL_ADD_QUAD(ctx, children,
1437 OID_AUTO, "rx_65_to_127_byte_packets",
1438 CTLFLAG_RD, &ha->hw_stats.common.rx_65_to_127_byte_packets,
1439 "rx_65_to_127_byte_packets");
1441 SYSCTL_ADD_QUAD(ctx, children,
1442 OID_AUTO, "rx_128_to_255_byte_packets",
1443 CTLFLAG_RD, &ha->hw_stats.common.rx_128_to_255_byte_packets,
1444 "rx_128_to_255_byte_packets");
1446 SYSCTL_ADD_QUAD(ctx, children,
1447 OID_AUTO, "rx_256_to_511_byte_packets",
1448 CTLFLAG_RD, &ha->hw_stats.common.rx_256_to_511_byte_packets,
1449 "rx_256_to_511_byte_packets");
1451 SYSCTL_ADD_QUAD(ctx, children,
1452 OID_AUTO, "rx_512_to_1023_byte_packets",
1453 CTLFLAG_RD, &ha->hw_stats.common.rx_512_to_1023_byte_packets,
1454 "rx_512_to_1023_byte_packets");
1456 SYSCTL_ADD_QUAD(ctx, children,
1457 OID_AUTO, "rx_1024_to_1518_byte_packets",
1458 CTLFLAG_RD, &ha->hw_stats.common.rx_1024_to_1518_byte_packets,
1459 "rx_1024_to_1518_byte_packets");
1461 SYSCTL_ADD_QUAD(ctx, children,
1462 OID_AUTO, "rx_1519_to_1522_byte_packets",
1463 CTLFLAG_RD, &ha->hw_stats.bb.rx_1519_to_1522_byte_packets,
1464 "rx_1519_to_1522_byte_packets");
1466 SYSCTL_ADD_QUAD(ctx, children,
1467 OID_AUTO, "rx_1523_to_2047_byte_packets",
1468 CTLFLAG_RD, &ha->hw_stats.bb.rx_1519_to_2047_byte_packets,
1469 "rx_1523_to_2047_byte_packets");
1471 SYSCTL_ADD_QUAD(ctx, children,
1472 OID_AUTO, "rx_2048_to_4095_byte_packets",
1473 CTLFLAG_RD, &ha->hw_stats.bb.rx_2048_to_4095_byte_packets,
1474 "rx_2048_to_4095_byte_packets");
1476 SYSCTL_ADD_QUAD(ctx, children,
1477 OID_AUTO, "rx_4096_to_9216_byte_packets",
1478 CTLFLAG_RD, &ha->hw_stats.bb.rx_4096_to_9216_byte_packets,
1479 "rx_4096_to_9216_byte_packets");
1481 SYSCTL_ADD_QUAD(ctx, children,
1482 OID_AUTO, "rx_9217_to_16383_byte_packets",
1483 CTLFLAG_RD, &ha->hw_stats.bb.rx_9217_to_16383_byte_packets,
1484 "rx_9217_to_16383_byte_packets");
1486 SYSCTL_ADD_QUAD(ctx, children,
1487 OID_AUTO, "rx_crc_errors",
1488 CTLFLAG_RD, &ha->hw_stats.common.rx_crc_errors,
1491 SYSCTL_ADD_QUAD(ctx, children,
1492 OID_AUTO, "rx_mac_crtl_frames",
1493 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_crtl_frames,
1494 "rx_mac_crtl_frames");
1496 SYSCTL_ADD_QUAD(ctx, children,
1497 OID_AUTO, "rx_pause_frames",
1498 CTLFLAG_RD, &ha->hw_stats.common.rx_pause_frames,
1501 SYSCTL_ADD_QUAD(ctx, children,
1502 OID_AUTO, "rx_pfc_frames",
1503 CTLFLAG_RD, &ha->hw_stats.common.rx_pfc_frames,
1506 SYSCTL_ADD_QUAD(ctx, children,
1507 OID_AUTO, "rx_align_errors",
1508 CTLFLAG_RD, &ha->hw_stats.common.rx_align_errors,
1511 SYSCTL_ADD_QUAD(ctx, children,
1512 OID_AUTO, "rx_carrier_errors",
1513 CTLFLAG_RD, &ha->hw_stats.common.rx_carrier_errors,
1514 "rx_carrier_errors");
1516 SYSCTL_ADD_QUAD(ctx, children,
1517 OID_AUTO, "rx_oversize_packets",
1518 CTLFLAG_RD, &ha->hw_stats.common.rx_oversize_packets,
1519 "rx_oversize_packets");
1521 SYSCTL_ADD_QUAD(ctx, children,
1522 OID_AUTO, "rx_jabbers",
1523 CTLFLAG_RD, &ha->hw_stats.common.rx_jabbers,
1526 SYSCTL_ADD_QUAD(ctx, children,
1527 OID_AUTO, "rx_undersize_packets",
1528 CTLFLAG_RD, &ha->hw_stats.common.rx_undersize_packets,
1529 "rx_undersize_packets");
1531 SYSCTL_ADD_QUAD(ctx, children,
1532 OID_AUTO, "rx_fragments",
1533 CTLFLAG_RD, &ha->hw_stats.common.rx_fragments,
1536 SYSCTL_ADD_QUAD(ctx, children,
1537 OID_AUTO, "tx_64_byte_packets",
1538 CTLFLAG_RD, &ha->hw_stats.common.tx_64_byte_packets,
1539 "tx_64_byte_packets");
1541 SYSCTL_ADD_QUAD(ctx, children,
1542 OID_AUTO, "tx_65_to_127_byte_packets",
1543 CTLFLAG_RD, &ha->hw_stats.common.tx_65_to_127_byte_packets,
1544 "tx_65_to_127_byte_packets");
1546 SYSCTL_ADD_QUAD(ctx, children,
1547 OID_AUTO, "tx_128_to_255_byte_packets",
1548 CTLFLAG_RD, &ha->hw_stats.common.tx_128_to_255_byte_packets,
1549 "tx_128_to_255_byte_packets");
1551 SYSCTL_ADD_QUAD(ctx, children,
1552 OID_AUTO, "tx_256_to_511_byte_packets",
1553 CTLFLAG_RD, &ha->hw_stats.common.tx_256_to_511_byte_packets,
1554 "tx_256_to_511_byte_packets");
1556 SYSCTL_ADD_QUAD(ctx, children,
1557 OID_AUTO, "tx_512_to_1023_byte_packets",
1558 CTLFLAG_RD, &ha->hw_stats.common.tx_512_to_1023_byte_packets,
1559 "tx_512_to_1023_byte_packets");
1561 SYSCTL_ADD_QUAD(ctx, children,
1562 OID_AUTO, "tx_1024_to_1518_byte_packets",
1563 CTLFLAG_RD, &ha->hw_stats.common.tx_1024_to_1518_byte_packets,
1564 "tx_1024_to_1518_byte_packets");
1566 SYSCTL_ADD_QUAD(ctx, children,
1567 OID_AUTO, "tx_1519_to_2047_byte_packets",
1568 CTLFLAG_RD, &ha->hw_stats.bb.tx_1519_to_2047_byte_packets,
1569 "tx_1519_to_2047_byte_packets");
1571 SYSCTL_ADD_QUAD(ctx, children,
1572 OID_AUTO, "tx_2048_to_4095_byte_packets",
1573 CTLFLAG_RD, &ha->hw_stats.bb.tx_2048_to_4095_byte_packets,
1574 "tx_2048_to_4095_byte_packets");
1576 SYSCTL_ADD_QUAD(ctx, children,
1577 OID_AUTO, "tx_4096_to_9216_byte_packets",
1578 CTLFLAG_RD, &ha->hw_stats.bb.tx_4096_to_9216_byte_packets,
1579 "tx_4096_to_9216_byte_packets");
1581 SYSCTL_ADD_QUAD(ctx, children,
1582 OID_AUTO, "tx_9217_to_16383_byte_packets",
1583 CTLFLAG_RD, &ha->hw_stats.bb.tx_9217_to_16383_byte_packets,
1584 "tx_9217_to_16383_byte_packets");
1586 SYSCTL_ADD_QUAD(ctx, children,
1587 OID_AUTO, "tx_pause_frames",
1588 CTLFLAG_RD, &ha->hw_stats.common.tx_pause_frames,
1591 SYSCTL_ADD_QUAD(ctx, children,
1592 OID_AUTO, "tx_pfc_frames",
1593 CTLFLAG_RD, &ha->hw_stats.common.tx_pfc_frames,
1596 SYSCTL_ADD_QUAD(ctx, children,
1597 OID_AUTO, "tx_lpi_entry_count",
1598 CTLFLAG_RD, &ha->hw_stats.bb.tx_lpi_entry_count,
1599 "tx_lpi_entry_count");
1601 SYSCTL_ADD_QUAD(ctx, children,
1602 OID_AUTO, "tx_total_collisions",
1603 CTLFLAG_RD, &ha->hw_stats.bb.tx_total_collisions,
1604 "tx_total_collisions");
1606 SYSCTL_ADD_QUAD(ctx, children,
1607 OID_AUTO, "brb_truncates",
1608 CTLFLAG_RD, &ha->hw_stats.common.brb_truncates,
1611 SYSCTL_ADD_QUAD(ctx, children,
1612 OID_AUTO, "brb_discards",
1613 CTLFLAG_RD, &ha->hw_stats.common.brb_discards,
1616 SYSCTL_ADD_QUAD(ctx, children,
1617 OID_AUTO, "rx_mac_bytes",
1618 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_bytes,
1621 SYSCTL_ADD_QUAD(ctx, children,
1622 OID_AUTO, "rx_mac_uc_packets",
1623 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_uc_packets,
1624 "rx_mac_uc_packets");
1626 SYSCTL_ADD_QUAD(ctx, children,
1627 OID_AUTO, "rx_mac_mc_packets",
1628 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_mc_packets,
1629 "rx_mac_mc_packets");
1631 SYSCTL_ADD_QUAD(ctx, children,
1632 OID_AUTO, "rx_mac_bc_packets",
1633 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_bc_packets,
1634 "rx_mac_bc_packets");
1636 SYSCTL_ADD_QUAD(ctx, children,
1637 OID_AUTO, "rx_mac_frames_ok",
1638 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_frames_ok,
1639 "rx_mac_frames_ok");
1641 SYSCTL_ADD_QUAD(ctx, children,
1642 OID_AUTO, "tx_mac_bytes",
1643 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_bytes,
1646 SYSCTL_ADD_QUAD(ctx, children,
1647 OID_AUTO, "tx_mac_uc_packets",
1648 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_uc_packets,
1649 "tx_mac_uc_packets");
1651 SYSCTL_ADD_QUAD(ctx, children,
1652 OID_AUTO, "tx_mac_mc_packets",
1653 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_mc_packets,
1654 "tx_mac_mc_packets");
1656 SYSCTL_ADD_QUAD(ctx, children,
1657 OID_AUTO, "tx_mac_bc_packets",
1658 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_bc_packets,
1659 "tx_mac_bc_packets");
1661 SYSCTL_ADD_QUAD(ctx, children,
1662 OID_AUTO, "tx_mac_ctrl_frames",
1663 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_ctrl_frames,
1664 "tx_mac_ctrl_frames");
1669 qlnx_add_sysctls(qlnx_host_t *ha)
1671 device_t dev = ha->pci_dev;
1672 struct sysctl_ctx_list *ctx;
1673 struct sysctl_oid_list *children;
1675 ctx = device_get_sysctl_ctx(dev);
1676 children = SYSCTL_CHILDREN(device_get_sysctl_tree(dev));
1678 qlnx_add_fp_stats_sysctls(ha);
1679 qlnx_add_sp_stats_sysctls(ha);
1680 qlnx_add_hw_stats_sysctls(ha);
1682 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "Driver_Version",
1683 CTLFLAG_RD, qlnx_ver_str, 0,
1686 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "STORMFW_Version",
1687 CTLFLAG_RD, ha->stormfw_ver, 0,
1688 "STORM Firmware Version");
1690 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "MFW_Version",
1691 CTLFLAG_RD, ha->mfw_ver, 0,
1692 "Management Firmware Version");
1694 SYSCTL_ADD_UINT(ctx, children,
1695 OID_AUTO, "personality", CTLFLAG_RD,
1696 &ha->personality, ha->personality,
1697 "\tpersonality = 0 => Ethernet Only\n"
1698 "\tpersonality = 3 => Ethernet and RoCE\n"
1699 "\tpersonality = 4 => Ethernet and iWARP\n"
1700 "\tpersonality = 6 => Default in Shared Memory\n");
1704 SYSCTL_ADD_UINT(ctx, children,
1705 OID_AUTO, "debug", CTLFLAG_RW,
1706 &ha->dbg_level, ha->dbg_level, "Debug Level");
1709 SYSCTL_ADD_UINT(ctx, children,
1710 OID_AUTO, "dp_level", CTLFLAG_RW,
1711 &ha->dp_level, ha->dp_level, "DP Level");
1714 SYSCTL_ADD_UINT(ctx, children,
1715 OID_AUTO, "dp_module", CTLFLAG_RW,
1716 &ha->dp_module, ha->dp_module, "DP Module");
1720 SYSCTL_ADD_UINT(ctx, children,
1721 OID_AUTO, "err_inject", CTLFLAG_RW,
1722 &ha->err_inject, ha->err_inject, "Error Inject");
1724 ha->storm_stats_enable = 0;
1726 SYSCTL_ADD_UINT(ctx, children,
1727 OID_AUTO, "storm_stats_enable", CTLFLAG_RW,
1728 &ha->storm_stats_enable, ha->storm_stats_enable,
1729 "Enable Storm Statistics Gathering");
1731 ha->storm_stats_index = 0;
1733 SYSCTL_ADD_UINT(ctx, children,
1734 OID_AUTO, "storm_stats_index", CTLFLAG_RD,
1735 &ha->storm_stats_index, ha->storm_stats_index,
1736 "Enable Storm Statistics Gathering Current Index");
1738 ha->grcdump_taken = 0;
1739 SYSCTL_ADD_UINT(ctx, children,
1740 OID_AUTO, "grcdump_taken", CTLFLAG_RD,
1741 &ha->grcdump_taken, ha->grcdump_taken, "grcdump_taken");
1743 ha->idle_chk_taken = 0;
1744 SYSCTL_ADD_UINT(ctx, children,
1745 OID_AUTO, "idle_chk_taken", CTLFLAG_RD,
1746 &ha->idle_chk_taken, ha->idle_chk_taken, "idle_chk_taken");
1748 SYSCTL_ADD_UINT(ctx, children,
1749 OID_AUTO, "rx_coalesce_usecs", CTLFLAG_RD,
1750 &ha->rx_coalesce_usecs, ha->rx_coalesce_usecs,
1751 "rx_coalesce_usecs");
1753 SYSCTL_ADD_UINT(ctx, children,
1754 OID_AUTO, "tx_coalesce_usecs", CTLFLAG_RD,
1755 &ha->tx_coalesce_usecs, ha->tx_coalesce_usecs,
1756 "tx_coalesce_usecs");
1758 ha->rx_pkt_threshold = 32;
1759 SYSCTL_ADD_UINT(ctx, children,
1760 OID_AUTO, "rx_pkt_threshold", CTLFLAG_RW,
1761 &ha->rx_pkt_threshold, ha->rx_pkt_threshold,
1762 "No. of Rx Pkts to process at a time");
1764 ha->rx_jumbo_buf_eq_mtu = 0;
1765 SYSCTL_ADD_UINT(ctx, children,
1766 OID_AUTO, "rx_jumbo_buf_eq_mtu", CTLFLAG_RW,
1767 &ha->rx_jumbo_buf_eq_mtu, ha->rx_jumbo_buf_eq_mtu,
1768 "== 0 => Rx Jumbo buffers are capped to 4Kbytes\n"
1769 "otherwise Rx Jumbo buffers are set to >= MTU size\n");
1771 SYSCTL_ADD_PROC(ctx, children,
1772 OID_AUTO, "trigger_dump", CTLTYPE_INT | CTLFLAG_RW,
1774 qlnx_trigger_dump_sysctl, "I", "trigger_dump");
1776 SYSCTL_ADD_PROC(ctx, children,
1777 OID_AUTO, "set_rx_coalesce_usecs", CTLTYPE_INT | CTLFLAG_RW,
1779 qlnx_set_rx_coalesce, "I",
1780 "rx interrupt coalesce period microseconds");
1782 SYSCTL_ADD_PROC(ctx, children,
1783 OID_AUTO, "set_tx_coalesce_usecs", CTLTYPE_INT | CTLFLAG_RW,
1785 qlnx_set_tx_coalesce, "I",
1786 "tx interrupt coalesce period microseconds");
1788 SYSCTL_ADD_QUAD(ctx, children,
1789 OID_AUTO, "err_illegal_intr", CTLFLAG_RD,
1790 &ha->err_illegal_intr, "err_illegal_intr");
1792 SYSCTL_ADD_QUAD(ctx, children,
1793 OID_AUTO, "err_fp_null", CTLFLAG_RD,
1794 &ha->err_fp_null, "err_fp_null");
1796 SYSCTL_ADD_QUAD(ctx, children,
1797 OID_AUTO, "err_get_proto_invalid_type", CTLFLAG_RD,
1798 &ha->err_get_proto_invalid_type, "err_get_proto_invalid_type");
1804 /*****************************************************************************
1805 * Operating System Network Interface Functions
1806 *****************************************************************************/
1809 qlnx_init_ifnet(device_t dev, qlnx_host_t *ha)
1814 ifp = ha->ifp = if_alloc(IFT_ETHER);
1817 panic("%s: cannot if_alloc()\n", device_get_nameunit(dev));
1819 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1821 device_id = pci_get_device(ha->pci_dev);
1823 #if __FreeBSD_version >= 1000000
1825 if (device_id == QLOGIC_PCI_DEVICE_ID_1634)
1826 ifp->if_baudrate = IF_Gbps(40);
1827 else if (device_id == QLOGIC_PCI_DEVICE_ID_1656)
1828 ifp->if_baudrate = IF_Gbps(25);
1829 else if (device_id == QLOGIC_PCI_DEVICE_ID_1654)
1830 ifp->if_baudrate = IF_Gbps(50);
1831 else if (device_id == QLOGIC_PCI_DEVICE_ID_1644)
1832 ifp->if_baudrate = IF_Gbps(100);
1834 ifp->if_capabilities = IFCAP_LINKSTATE;
1836 ifp->if_mtu = ETHERMTU;
1837 ifp->if_baudrate = (1 * 1000 * 1000 *1000);
1839 #endif /* #if __FreeBSD_version >= 1000000 */
1841 ifp->if_init = qlnx_init;
1843 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1844 ifp->if_ioctl = qlnx_ioctl;
1845 ifp->if_transmit = qlnx_transmit;
1846 ifp->if_qflush = qlnx_qflush;
1848 IFQ_SET_MAXLEN(&ifp->if_snd, qlnx_get_ifq_snd_maxlen(ha));
1849 ifp->if_snd.ifq_drv_maxlen = qlnx_get_ifq_snd_maxlen(ha);
1850 IFQ_SET_READY(&ifp->if_snd);
1852 #if __FreeBSD_version >= 1100036
1853 if_setgetcounterfn(ifp, qlnx_get_counter);
1856 ha->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
1858 memcpy(ha->primary_mac, qlnx_get_mac_addr(ha), ETH_ALEN);
1859 ether_ifattach(ifp, ha->primary_mac);
1860 bcopy(IF_LLADDR(ha->ifp), ha->primary_mac, ETHER_ADDR_LEN);
1862 ifp->if_capabilities = IFCAP_HWCSUM;
1863 ifp->if_capabilities |= IFCAP_JUMBO_MTU;
1865 ifp->if_capabilities |= IFCAP_VLAN_MTU;
1866 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING;
1867 ifp->if_capabilities |= IFCAP_VLAN_HWFILTER;
1868 ifp->if_capabilities |= IFCAP_VLAN_HWCSUM;
1869 ifp->if_capabilities |= IFCAP_VLAN_HWTSO;
1870 ifp->if_capabilities |= IFCAP_TSO4;
1871 ifp->if_capabilities |= IFCAP_TSO6;
1872 ifp->if_capabilities |= IFCAP_LRO;
1874 ifp->if_capenable = ifp->if_capabilities;
1876 ifp->if_hwassist = CSUM_IP;
1877 ifp->if_hwassist |= CSUM_TCP | CSUM_UDP;
1878 ifp->if_hwassist |= CSUM_TCP_IPV6 | CSUM_UDP_IPV6;
1879 ifp->if_hwassist |= CSUM_TSO;
1881 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
1883 ifmedia_init(&ha->media, IFM_IMASK, qlnx_media_change,\
1886 if (device_id == QLOGIC_PCI_DEVICE_ID_1634) {
1887 ifmedia_add(&ha->media, (IFM_ETHER | IFM_40G_LR4), 0, NULL);
1888 ifmedia_add(&ha->media, (IFM_ETHER | IFM_40G_SR4), 0, NULL);
1889 ifmedia_add(&ha->media, (IFM_ETHER | IFM_40G_CR4), 0, NULL);
1890 } else if (device_id == QLOGIC_PCI_DEVICE_ID_1656) {
1891 ifmedia_add(&ha->media, (IFM_ETHER | QLNX_IFM_25G_SR), 0, NULL);
1892 ifmedia_add(&ha->media, (IFM_ETHER | QLNX_IFM_25G_CR), 0, NULL);
1893 } else if (device_id == QLOGIC_PCI_DEVICE_ID_1654) {
1894 ifmedia_add(&ha->media, (IFM_ETHER | IFM_50G_KR2), 0, NULL);
1895 ifmedia_add(&ha->media, (IFM_ETHER | IFM_50G_CR2), 0, NULL);
1896 } else if (device_id == QLOGIC_PCI_DEVICE_ID_1644) {
1897 ifmedia_add(&ha->media,
1898 (IFM_ETHER | QLNX_IFM_100G_LR4), 0, NULL);
1899 ifmedia_add(&ha->media,
1900 (IFM_ETHER | QLNX_IFM_100G_SR4), 0, NULL);
1901 ifmedia_add(&ha->media,
1902 (IFM_ETHER | QLNX_IFM_100G_CR4), 0, NULL);
1905 ifmedia_add(&ha->media, (IFM_ETHER | IFM_FDX), 0, NULL);
1906 ifmedia_add(&ha->media, (IFM_ETHER | IFM_AUTO), 0, NULL);
1909 ifmedia_set(&ha->media, (IFM_ETHER | IFM_AUTO));
1911 QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
1917 qlnx_init_locked(qlnx_host_t *ha)
1919 struct ifnet *ifp = ha->ifp;
1923 if (qlnx_load(ha) == 0) {
1924 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1925 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1932 qlnx_init(void *arg)
1936 ha = (qlnx_host_t *)arg;
1938 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1941 qlnx_init_locked(ha);
1944 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1950 qlnx_config_mcast_mac_addr(qlnx_host_t *ha, uint8_t *mac_addr, uint32_t add_mac)
1952 struct ecore_filter_mcast *mcast;
1953 struct ecore_dev *cdev;
1958 mcast = &ha->ecore_mcast;
1959 bzero(mcast, sizeof(struct ecore_filter_mcast));
1962 mcast->opcode = ECORE_FILTER_ADD;
1964 mcast->opcode = ECORE_FILTER_REMOVE;
1966 mcast->num_mc_addrs = 1;
1967 memcpy(mcast->mac, mac_addr, ETH_ALEN);
1969 rc = ecore_filter_mcast_cmd(cdev, mcast, ECORE_SPQ_MODE_CB, NULL);
1975 qlnx_hw_add_mcast(qlnx_host_t *ha, uint8_t *mta)
1979 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
1981 if (QL_MAC_CMP(ha->mcast[i].addr, mta) == 0)
1982 return 0; /* its been already added */
1985 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
1987 if ((ha->mcast[i].addr[0] == 0) &&
1988 (ha->mcast[i].addr[1] == 0) &&
1989 (ha->mcast[i].addr[2] == 0) &&
1990 (ha->mcast[i].addr[3] == 0) &&
1991 (ha->mcast[i].addr[4] == 0) &&
1992 (ha->mcast[i].addr[5] == 0)) {
1994 if (qlnx_config_mcast_mac_addr(ha, mta, 1))
1997 bcopy(mta, ha->mcast[i].addr, ETH_ALEN);
2007 qlnx_hw_del_mcast(qlnx_host_t *ha, uint8_t *mta)
2011 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
2012 if (QL_MAC_CMP(ha->mcast[i].addr, mta) == 0) {
2014 if (qlnx_config_mcast_mac_addr(ha, mta, 0))
2017 ha->mcast[i].addr[0] = 0;
2018 ha->mcast[i].addr[1] = 0;
2019 ha->mcast[i].addr[2] = 0;
2020 ha->mcast[i].addr[3] = 0;
2021 ha->mcast[i].addr[4] = 0;
2022 ha->mcast[i].addr[5] = 0;
2033 * Name: qls_hw_set_multi
2034 * Function: Sets the Multicast Addresses provided the host O.S into the
2035 * hardware (for the given interface)
2038 qlnx_hw_set_multi(qlnx_host_t *ha, uint8_t *mta, uint32_t mcnt,
2043 for (i = 0; i < mcnt; i++) {
2045 if (qlnx_hw_add_mcast(ha, mta))
2048 if (qlnx_hw_del_mcast(ha, mta))
2052 mta += ETHER_HDR_LEN;
2058 #define QLNX_MCAST_ADDRS_SIZE (QLNX_MAX_NUM_MULTICAST_ADDRS * ETHER_HDR_LEN)
2060 qlnx_set_multi(qlnx_host_t *ha, uint32_t add_multi)
2062 uint8_t mta[QLNX_MCAST_ADDRS_SIZE];
2063 struct ifmultiaddr *ifma;
2065 struct ifnet *ifp = ha->ifp;
2068 if_maddr_rlock(ifp);
2070 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
2072 if (ifma->ifma_addr->sa_family != AF_LINK)
2075 if (mcnt == QLNX_MAX_NUM_MULTICAST_ADDRS)
2078 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
2079 &mta[mcnt * ETHER_HDR_LEN], ETHER_HDR_LEN);
2084 if_maddr_runlock(ifp);
2087 qlnx_hw_set_multi(ha, mta, mcnt, add_multi);
2094 qlnx_set_promisc(qlnx_host_t *ha)
2099 filter = ha->filter;
2100 filter |= ECORE_ACCEPT_MCAST_UNMATCHED;
2101 filter |= ECORE_ACCEPT_UCAST_UNMATCHED;
2103 rc = qlnx_set_rx_accept_filter(ha, filter);
2108 qlnx_set_allmulti(qlnx_host_t *ha)
2113 filter = ha->filter;
2114 filter |= ECORE_ACCEPT_MCAST_UNMATCHED;
2115 rc = qlnx_set_rx_accept_filter(ha, filter);
2122 qlnx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
2125 struct ifreq *ifr = (struct ifreq *)data;
2126 struct ifaddr *ifa = (struct ifaddr *)data;
2129 ha = (qlnx_host_t *)ifp->if_softc;
2133 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFADDR (0x%lx)\n",
2136 if (ifa->ifa_addr->sa_family == AF_INET) {
2137 ifp->if_flags |= IFF_UP;
2138 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2140 qlnx_init_locked(ha);
2143 QL_DPRINT4(ha, (ha->pci_dev,
2144 "%s: SIOCSIFADDR (0x%lx) ipv4 [0x%08x]\n",
2146 ntohl(IA_SIN(ifa)->sin_addr.s_addr)));
2148 arp_ifinit(ifp, ifa);
2150 ether_ioctl(ifp, cmd, data);
2155 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFMTU (0x%lx)\n",
2158 if (ifr->ifr_mtu > QLNX_MAX_MTU) {
2162 ifp->if_mtu = ifr->ifr_mtu;
2163 ha->max_frame_size =
2164 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
2165 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2166 qlnx_init_locked(ha);
2175 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFFLAGS (0x%lx)\n",
2180 if (ifp->if_flags & IFF_UP) {
2181 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2182 if ((ifp->if_flags ^ ha->if_flags) &
2184 ret = qlnx_set_promisc(ha);
2185 } else if ((ifp->if_flags ^ ha->if_flags) &
2187 ret = qlnx_set_allmulti(ha);
2190 ha->max_frame_size = ifp->if_mtu +
2191 ETHER_HDR_LEN + ETHER_CRC_LEN;
2192 qlnx_init_locked(ha);
2195 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2197 ha->if_flags = ifp->if_flags;
2204 QL_DPRINT4(ha, (ha->pci_dev,
2205 "%s: %s (0x%lx)\n", __func__, "SIOCADDMULTI", cmd));
2207 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2208 if (qlnx_set_multi(ha, 1))
2214 QL_DPRINT4(ha, (ha->pci_dev,
2215 "%s: %s (0x%lx)\n", __func__, "SIOCDELMULTI", cmd));
2217 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2218 if (qlnx_set_multi(ha, 0))
2225 QL_DPRINT4(ha, (ha->pci_dev,
2226 "%s: SIOCSIFMEDIA/SIOCGIFMEDIA (0x%lx)\n",
2228 ret = ifmedia_ioctl(ifp, ifr, &ha->media, cmd);
2233 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
2235 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFCAP (0x%lx)\n",
2238 if (mask & IFCAP_HWCSUM)
2239 ifp->if_capenable ^= IFCAP_HWCSUM;
2240 if (mask & IFCAP_TSO4)
2241 ifp->if_capenable ^= IFCAP_TSO4;
2242 if (mask & IFCAP_TSO6)
2243 ifp->if_capenable ^= IFCAP_TSO6;
2244 if (mask & IFCAP_VLAN_HWTAGGING)
2245 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
2246 if (mask & IFCAP_VLAN_HWTSO)
2247 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
2248 if (mask & IFCAP_LRO)
2249 ifp->if_capenable ^= IFCAP_LRO;
2251 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
2254 VLAN_CAPABILITIES(ifp);
2257 #if (__FreeBSD_version >= 1100101)
2261 struct ifi2creq i2c;
2262 struct ecore_hwfn *p_hwfn = &ha->cdev.hwfns[0];
2263 struct ecore_ptt *p_ptt;
2265 ret = copyin(ifr->ifr_data, &i2c, sizeof(i2c));
2270 if ((i2c.len > sizeof (i2c.data)) ||
2271 (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2)) {
2276 p_ptt = ecore_ptt_acquire(p_hwfn);
2279 QL_DPRINT1(ha, (ha->pci_dev, "%s :"
2280 " ecore_ptt_acquire failed\n", __func__));
2285 ret = ecore_mcp_phy_sfp_read(p_hwfn, p_ptt,
2286 (ha->pci_func & 0x1), i2c.dev_addr, i2c.offset,
2287 i2c.len, &i2c.data[0]);
2289 ecore_ptt_release(p_hwfn, p_ptt);
2296 ret = copyout(&i2c, ifr->ifr_data, sizeof(i2c));
2298 QL_DPRINT8(ha, (ha->pci_dev, "SIOCGI2C copyout ret = %d"
2299 " len = %d addr = 0x%02x offset = 0x%04x"
2300 " data[0..7]=0x%02x 0x%02x 0x%02x 0x%02x 0x%02x"
2301 " 0x%02x 0x%02x 0x%02x\n",
2302 ret, i2c.len, i2c.dev_addr, i2c.offset,
2303 i2c.data[0], i2c.data[1], i2c.data[2], i2c.data[3],
2304 i2c.data[4], i2c.data[5], i2c.data[6], i2c.data[7]));
2307 #endif /* #if (__FreeBSD_version >= 1100101) */
2310 QL_DPRINT4(ha, (ha->pci_dev, "%s: default (0x%lx)\n",
2312 ret = ether_ioctl(ifp, cmd, data);
2320 qlnx_media_change(struct ifnet *ifp)
2323 struct ifmedia *ifm;
2326 ha = (qlnx_host_t *)ifp->if_softc;
2328 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
2332 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
2335 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
2341 qlnx_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
2345 ha = (qlnx_host_t *)ifp->if_softc;
2347 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
2349 ifmr->ifm_status = IFM_AVALID;
2350 ifmr->ifm_active = IFM_ETHER;
2353 ifmr->ifm_status |= IFM_ACTIVE;
2355 (IFM_FDX | qlnx_get_optics(ha, &ha->if_link));
2357 if (ha->if_link.link_partner_caps &
2358 (QLNX_LINK_CAP_Pause | QLNX_LINK_CAP_Asym_Pause))
2360 (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE);
2363 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit (%s)\n", __func__,
2364 (ha->link_up ? "link_up" : "link_down")));
2371 qlnx_free_tx_pkt(qlnx_host_t *ha, struct qlnx_fastpath *fp,
2372 struct qlnx_tx_queue *txq)
2378 struct eth_tx_bd *tx_data_bd;
2379 struct eth_tx_1st_bd *first_bd;
2382 idx = txq->sw_tx_cons;
2383 mp = txq->sw_tx_ring[idx].mp;
2384 map = txq->sw_tx_ring[idx].map;
2386 if ((mp == NULL) || QL_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_MBUF_NULL)){
2388 QL_RESET_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_MBUF_NULL);
2390 QL_DPRINT1(ha, (ha->pci_dev, "%s: (mp == NULL) "
2392 " ecore_prod_idx = 0x%x"
2393 " ecore_cons_idx = 0x%x"
2394 " hw_bd_cons = 0x%x"
2395 " txq_db_last = 0x%x"
2396 " elem_left = 0x%x\n",
2399 ecore_chain_get_prod_idx(&txq->tx_pbl),
2400 ecore_chain_get_cons_idx(&txq->tx_pbl),
2401 le16toh(*txq->hw_cons_ptr),
2403 ecore_chain_get_elem_left(&txq->tx_pbl)));
2405 fp->err_tx_free_pkt_null++;
2408 qlnx_trigger_dump(ha);
2413 QLNX_INC_OPACKETS((ha->ifp));
2414 QLNX_INC_OBYTES((ha->ifp), (mp->m_pkthdr.len));
2416 bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_POSTWRITE);
2417 bus_dmamap_unload(ha->tx_tag, map);
2419 fp->tx_pkts_freed++;
2420 fp->tx_pkts_completed++;
2425 first_bd = (struct eth_tx_1st_bd *)ecore_chain_consume(&txq->tx_pbl);
2426 nbds = first_bd->data.nbds;
2428 // BD_SET_UNMAP_ADDR_LEN(first_bd, 0, 0);
2430 for (i = 1; i < nbds; i++) {
2431 tx_data_bd = ecore_chain_consume(&txq->tx_pbl);
2432 // BD_SET_UNMAP_ADDR_LEN(tx_data_bd, 0, 0);
2434 txq->sw_tx_ring[idx].flags = 0;
2435 txq->sw_tx_ring[idx].mp = NULL;
2436 txq->sw_tx_ring[idx].map = (bus_dmamap_t)0;
2442 qlnx_tx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp,
2443 struct qlnx_tx_queue *txq)
2449 hw_bd_cons = le16toh(*txq->hw_cons_ptr);
2451 while (hw_bd_cons !=
2452 (ecore_cons_idx = ecore_chain_get_cons_idx(&txq->tx_pbl))) {
2454 if (hw_bd_cons < ecore_cons_idx) {
2455 diff = (1 << 16) - (ecore_cons_idx - hw_bd_cons);
2457 diff = hw_bd_cons - ecore_cons_idx;
2459 if ((diff > TX_RING_SIZE) ||
2460 QL_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_DIFF)){
2462 QL_RESET_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_DIFF);
2464 QL_DPRINT1(ha, (ha->pci_dev, "%s: (diff = 0x%x) "
2466 " ecore_prod_idx = 0x%x"
2467 " ecore_cons_idx = 0x%x"
2468 " hw_bd_cons = 0x%x"
2469 " txq_db_last = 0x%x"
2470 " elem_left = 0x%x\n",
2473 ecore_chain_get_prod_idx(&txq->tx_pbl),
2474 ecore_chain_get_cons_idx(&txq->tx_pbl),
2475 le16toh(*txq->hw_cons_ptr),
2477 ecore_chain_get_elem_left(&txq->tx_pbl)));
2479 fp->err_tx_cons_idx_conflict++;
2482 qlnx_trigger_dump(ha);
2485 qlnx_free_tx_pkt(ha, fp, txq);
2487 txq->sw_tx_cons = (txq->sw_tx_cons + 1) & (TX_RING_SIZE - 1);
2493 qlnx_transmit(struct ifnet *ifp, struct mbuf *mp)
2495 qlnx_host_t *ha = (qlnx_host_t *)ifp->if_softc;
2496 struct qlnx_fastpath *fp;
2497 int rss_id = 0, ret = 0;
2499 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
2501 #if __FreeBSD_version >= 1100000
2502 if (M_HASHTYPE_GET(mp) != M_HASHTYPE_NONE)
2504 if (mp->m_flags & M_FLOWID)
2506 rss_id = (mp->m_pkthdr.flowid % ECORE_RSS_IND_TABLE_SIZE) %
2509 fp = &ha->fp_array[rss_id];
2511 if (fp->tx_br == NULL) {
2513 goto qlnx_transmit_exit;
2517 ret = drbr_enqueue(ifp, fp->tx_br, mp);
2520 if (fp->fp_taskqueue != NULL)
2521 taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
2527 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = %d\n", __func__, ret));
2532 qlnx_qflush(struct ifnet *ifp)
2535 struct qlnx_fastpath *fp;
2539 ha = (qlnx_host_t *)ifp->if_softc;
2541 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
2543 for (rss_id = 0; rss_id < ha->num_rss; rss_id++) {
2545 fp = &ha->fp_array[rss_id];
2551 mtx_lock(&fp->tx_mtx);
2553 while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) {
2554 fp->tx_pkts_freed++;
2557 mtx_unlock(&fp->tx_mtx);
2560 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
2566 qlnx_txq_doorbell_wr32(qlnx_host_t *ha, void *reg_addr, uint32_t value)
2568 struct ecore_dev *cdev;
2573 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)cdev->doorbells);
2575 bus_write_4(ha->pci_dbells, offset, value);
2576 bus_barrier(ha->pci_reg, 0, 0, BUS_SPACE_BARRIER_READ);
2577 bus_barrier(ha->pci_dbells, 0, 0, BUS_SPACE_BARRIER_READ);
2583 qlnx_tcp_offset(qlnx_host_t *ha, struct mbuf *mp)
2585 struct ether_vlan_header *eh = NULL;
2586 struct ip *ip = NULL;
2587 struct ip6_hdr *ip6 = NULL;
2588 struct tcphdr *th = NULL;
2589 uint32_t ehdrlen = 0, ip_hlen = 0, offset = 0;
2592 uint8_t buf[sizeof(struct ip6_hdr)];
2596 eh = mtod(mp, struct ether_vlan_header *);
2598 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
2599 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
2600 etype = ntohs(eh->evl_proto);
2602 ehdrlen = ETHER_HDR_LEN;
2603 etype = ntohs(eh->evl_encap_proto);
2609 ip = (struct ip *)(mp->m_data + ehdrlen);
2611 ip_hlen = sizeof (struct ip);
2613 if (mp->m_len < (ehdrlen + ip_hlen)) {
2614 m_copydata(mp, ehdrlen, sizeof(struct ip), buf);
2615 ip = (struct ip *)buf;
2618 th = (struct tcphdr *)(ip + 1);
2619 offset = ip_hlen + ehdrlen + (th->th_off << 2);
2622 case ETHERTYPE_IPV6:
2623 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
2625 ip_hlen = sizeof(struct ip6_hdr);
2627 if (mp->m_len < (ehdrlen + ip_hlen)) {
2628 m_copydata(mp, ehdrlen, sizeof (struct ip6_hdr),
2630 ip6 = (struct ip6_hdr *)buf;
2632 th = (struct tcphdr *)(ip6 + 1);
2633 offset = ip_hlen + ehdrlen + (th->th_off << 2);
2644 qlnx_tso_check(struct qlnx_fastpath *fp, bus_dma_segment_t *segs, int nsegs,
2648 uint32_t sum, nbds_in_hdr = 1;
2649 bus_dma_segment_t *t_segs = segs;
2651 /* count the number of segments spanned by TCP header */
2654 while ((i < nsegs) && (offset > t_segs->ds_len)) {
2656 offset = offset - t_segs->ds_len;
2661 while (nsegs >= QLNX_MAX_SEGMENTS_NON_TSO) {
2665 for (i = 0; i < (ETH_TX_LSO_WINDOW_BDS_NUM - nbds_in_hdr); i++){
2666 sum += segs->ds_len;
2670 if (sum < ETH_TX_LSO_WINDOW_MIN_LEN) {
2671 fp->tx_lso_wnd_min_len++;
2675 nsegs -= QLNX_MAX_SEGMENTS_NON_TSO;
2682 qlnx_send(qlnx_host_t *ha, struct qlnx_fastpath *fp, struct mbuf **m_headp)
2684 bus_dma_segment_t *segs;
2685 bus_dmamap_t map = 0;
2688 struct mbuf *m_head = *m_headp;
2693 struct qlnx_tx_queue *txq;
2695 struct eth_tx_1st_bd *first_bd;
2696 struct eth_tx_2nd_bd *second_bd;
2697 struct eth_tx_3rd_bd *third_bd;
2698 struct eth_tx_bd *tx_data_bd;
2701 uint32_t nbds_in_hdr = 0;
2702 uint32_t offset = 0;
2704 QL_DPRINT8(ha, (ha->pci_dev, "%s: enter\n", __func__));
2715 idx = txq->sw_tx_prod;
2717 map = txq->sw_tx_ring[idx].map;
2720 ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head, segs, &nsegs,
2723 #ifdef QLNX_TRACE_TSO_PKT_LEN
2725 if (!fp->tx_tso_min_pkt_len) {
2726 fp->tx_tso_min_pkt_len = m_head->m_pkthdr.len;
2727 fp->tx_tso_min_pkt_len = m_head->m_pkthdr.len;
2729 if (fp->tx_tso_min_pkt_len > m_head->m_pkthdr.len)
2730 fp->tx_tso_min_pkt_len = m_head->m_pkthdr.len;
2731 if (fp->tx_tso_max_pkt_len < m_head->m_pkthdr.len)
2732 fp->tx_tso_max_pkt_len = m_head->m_pkthdr.len;
2735 #endif /* #ifdef QLNX_TRACE_TSO_PKT_LEN */
2737 if (m_head->m_pkthdr.csum_flags & CSUM_TSO)
2738 offset = qlnx_tcp_offset(ha, m_head);
2740 if ((ret == EFBIG) ||
2741 ((nsegs > QLNX_MAX_SEGMENTS_NON_TSO) && (
2742 (!(m_head->m_pkthdr.csum_flags & CSUM_TSO)) ||
2743 ((m_head->m_pkthdr.csum_flags & CSUM_TSO) &&
2744 qlnx_tso_check(fp, segs, nsegs, offset))))) {
2748 QL_DPRINT8(ha, (ha->pci_dev, "%s: EFBIG [%d]\n", __func__,
2749 m_head->m_pkthdr.len));
2753 m = m_defrag(m_head, M_NOWAIT);
2755 fp->err_tx_defrag++;
2756 fp->tx_pkts_freed++;
2759 QL_DPRINT1(ha, (ha->pci_dev,
2760 "%s: m_defrag() = NULL [%d]\n",
2768 if ((ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head,
2769 segs, &nsegs, BUS_DMA_NOWAIT))) {
2771 fp->err_tx_defrag_dmamap_load++;
2773 QL_DPRINT1(ha, (ha->pci_dev,
2774 "%s: bus_dmamap_load_mbuf_sg failed0[%d, %d]\n",
2775 __func__, ret, m_head->m_pkthdr.len));
2777 fp->tx_pkts_freed++;
2784 if ((nsegs > QLNX_MAX_SEGMENTS_NON_TSO) &&
2785 !(m_head->m_pkthdr.csum_flags & CSUM_TSO)) {
2787 fp->err_tx_non_tso_max_seg++;
2789 QL_DPRINT1(ha, (ha->pci_dev,
2790 "%s: (%d) nsegs too many for non-TSO[%d, %d]\n",
2791 __func__, ret, nsegs, m_head->m_pkthdr.len));
2793 fp->tx_pkts_freed++;
2799 if (m_head->m_pkthdr.csum_flags & CSUM_TSO)
2800 offset = qlnx_tcp_offset(ha, m_head);
2804 fp->err_tx_dmamap_load++;
2806 QL_DPRINT1(ha, (ha->pci_dev,
2807 "%s: bus_dmamap_load_mbuf_sg failed1[%d, %d]\n",
2808 __func__, ret, m_head->m_pkthdr.len));
2810 fp->tx_pkts_freed++;
2816 QL_ASSERT(ha, (nsegs != 0), ("qlnx_send: empty packet"));
2818 #ifdef QLNX_TRACE_TSO_PKT_LEN
2820 if (nsegs < QLNX_FP_MAX_SEGS)
2821 fp->tx_pkts[(nsegs - 1)]++;
2823 fp->tx_pkts[(QLNX_FP_MAX_SEGS - 1)]++;
2825 #endif /* #ifdef QLNX_TRACE_TSO_PKT_LEN */
2827 if ((nsegs + QLNX_TX_ELEM_RESERVE) >
2828 (int)(elem_left = ecore_chain_get_elem_left(&txq->tx_pbl))) {
2830 QL_DPRINT1(ha, (ha->pci_dev, "%s: (%d, 0x%x) insuffient BDs"
2831 "in chain[%d] trying to free packets\n",
2832 __func__, nsegs, elem_left, fp->rss_id));
2834 fp->tx_nsegs_gt_elem_left++;
2836 (void)qlnx_tx_int(ha, fp, txq);
2838 if ((nsegs + QLNX_TX_ELEM_RESERVE) > (int)(elem_left =
2839 ecore_chain_get_elem_left(&txq->tx_pbl))) {
2841 QL_DPRINT1(ha, (ha->pci_dev,
2842 "%s: (%d, 0x%x) insuffient BDs in chain[%d]\n",
2843 __func__, nsegs, elem_left, fp->rss_id));
2845 fp->err_tx_nsegs_gt_elem_left++;
2846 ha->storm_stats_enable = 1;
2851 bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_PREWRITE);
2853 txq->sw_tx_ring[idx].mp = m_head;
2855 first_bd = (struct eth_tx_1st_bd *)ecore_chain_produce(&txq->tx_pbl);
2857 memset(first_bd, 0, sizeof(*first_bd));
2859 first_bd->data.bd_flags.bitfields =
2860 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
2862 BD_SET_UNMAP_ADDR_LEN(first_bd, segs->ds_addr, segs->ds_len);
2866 if (m_head->m_pkthdr.csum_flags & CSUM_IP) {
2867 first_bd->data.bd_flags.bitfields |=
2868 (1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT);
2871 if (m_head->m_pkthdr.csum_flags & (CSUM_UDP | CSUM_TCP)) {
2872 first_bd->data.bd_flags.bitfields |=
2873 (1 << ETH_TX_1ST_BD_FLAGS_L4_CSUM_SHIFT);
2876 if (m_head->m_flags & M_VLANTAG) {
2877 first_bd->data.vlan = m_head->m_pkthdr.ether_vtag;
2878 first_bd->data.bd_flags.bitfields |=
2879 (1 << ETH_TX_1ST_BD_FLAGS_VLAN_INSERTION_SHIFT);
2882 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
2884 first_bd->data.bd_flags.bitfields |=
2885 (1 << ETH_TX_1ST_BD_FLAGS_LSO_SHIFT);
2886 first_bd->data.bd_flags.bitfields |=
2887 (1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT);
2891 if (offset == segs->ds_len) {
2892 BD_SET_UNMAP_ADDR_LEN(first_bd, segs->ds_addr, offset);
2896 second_bd = (struct eth_tx_2nd_bd *)
2897 ecore_chain_produce(&txq->tx_pbl);
2898 memset(second_bd, 0, sizeof(*second_bd));
2901 if (seg_idx < nsegs) {
2902 BD_SET_UNMAP_ADDR_LEN(second_bd, \
2903 (segs->ds_addr), (segs->ds_len));
2908 third_bd = (struct eth_tx_3rd_bd *)
2909 ecore_chain_produce(&txq->tx_pbl);
2910 memset(third_bd, 0, sizeof(*third_bd));
2911 third_bd->data.lso_mss = m_head->m_pkthdr.tso_segsz;
2912 third_bd->data.bitfields |=
2913 (nbds_in_hdr<<ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
2916 if (seg_idx < nsegs) {
2917 BD_SET_UNMAP_ADDR_LEN(third_bd, \
2918 (segs->ds_addr), (segs->ds_len));
2923 for (; seg_idx < nsegs; seg_idx++) {
2924 tx_data_bd = (struct eth_tx_bd *)
2925 ecore_chain_produce(&txq->tx_pbl);
2926 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
2927 BD_SET_UNMAP_ADDR_LEN(tx_data_bd, \
2934 } else if (offset < segs->ds_len) {
2935 BD_SET_UNMAP_ADDR_LEN(first_bd, segs->ds_addr, offset);
2937 second_bd = (struct eth_tx_2nd_bd *)
2938 ecore_chain_produce(&txq->tx_pbl);
2939 memset(second_bd, 0, sizeof(*second_bd));
2940 BD_SET_UNMAP_ADDR_LEN(second_bd, \
2941 (segs->ds_addr + offset),\
2942 (segs->ds_len - offset));
2946 third_bd = (struct eth_tx_3rd_bd *)
2947 ecore_chain_produce(&txq->tx_pbl);
2948 memset(third_bd, 0, sizeof(*third_bd));
2950 BD_SET_UNMAP_ADDR_LEN(third_bd, \
2953 third_bd->data.lso_mss = m_head->m_pkthdr.tso_segsz;
2954 third_bd->data.bitfields |=
2955 (nbds_in_hdr<<ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
2959 for (seg_idx = 2; seg_idx < nsegs; seg_idx++) {
2960 tx_data_bd = (struct eth_tx_bd *)
2961 ecore_chain_produce(&txq->tx_pbl);
2962 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
2963 BD_SET_UNMAP_ADDR_LEN(tx_data_bd, \
2971 offset = offset - segs->ds_len;
2974 for (seg_idx = 1; seg_idx < nsegs; seg_idx++) {
2979 tx_data_bd = (struct eth_tx_bd *)
2980 ecore_chain_produce(&txq->tx_pbl);
2981 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
2983 if (second_bd == NULL) {
2984 second_bd = (struct eth_tx_2nd_bd *)
2986 } else if (third_bd == NULL) {
2987 third_bd = (struct eth_tx_3rd_bd *)
2991 if (offset && (offset < segs->ds_len)) {
2992 BD_SET_UNMAP_ADDR_LEN(tx_data_bd,\
2993 segs->ds_addr, offset);
2995 tx_data_bd = (struct eth_tx_bd *)
2996 ecore_chain_produce(&txq->tx_pbl);
2998 memset(tx_data_bd, 0,
2999 sizeof(*tx_data_bd));
3001 if (second_bd == NULL) {
3003 (struct eth_tx_2nd_bd *)tx_data_bd;
3004 } else if (third_bd == NULL) {
3006 (struct eth_tx_3rd_bd *)tx_data_bd;
3008 BD_SET_UNMAP_ADDR_LEN(tx_data_bd,\
3009 (segs->ds_addr + offset), \
3010 (segs->ds_len - offset));
3015 offset = offset - segs->ds_len;
3016 BD_SET_UNMAP_ADDR_LEN(tx_data_bd,\
3017 segs->ds_addr, segs->ds_len);
3023 if (third_bd == NULL) {
3024 third_bd = (struct eth_tx_3rd_bd *)
3025 ecore_chain_produce(&txq->tx_pbl);
3026 memset(third_bd, 0, sizeof(*third_bd));
3029 third_bd->data.lso_mss = m_head->m_pkthdr.tso_segsz;
3030 third_bd->data.bitfields |=
3031 (nbds_in_hdr<<ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
3035 for (seg_idx = 1; seg_idx < nsegs; seg_idx++) {
3036 tx_data_bd = (struct eth_tx_bd *)
3037 ecore_chain_produce(&txq->tx_pbl);
3038 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
3039 BD_SET_UNMAP_ADDR_LEN(tx_data_bd, segs->ds_addr,\
3044 first_bd->data.bitfields =
3045 (m_head->m_pkthdr.len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK)
3046 << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
3047 first_bd->data.bitfields =
3048 htole16(first_bd->data.bitfields);
3052 first_bd->data.nbds = nbd;
3054 #ifdef QLNX_TRACE_TSO_PKT_LEN
3056 if (fp->tx_tso_max_nsegs < nsegs)
3057 fp->tx_tso_max_nsegs = nsegs;
3059 if ((nsegs < fp->tx_tso_min_nsegs) || (!fp->tx_tso_min_nsegs))
3060 fp->tx_tso_min_nsegs = nsegs;
3062 #endif /* #ifdef QLNX_TRACE_TSO_PKT_LEN */
3064 txq->sw_tx_ring[idx].nsegs = nsegs;
3065 txq->sw_tx_prod = (txq->sw_tx_prod + 1) & (TX_RING_SIZE - 1);
3067 txq->tx_db.data.bd_prod =
3068 htole16(ecore_chain_get_prod_idx(&txq->tx_pbl));
3070 qlnx_txq_doorbell_wr32(ha, txq->doorbell_addr, txq->tx_db.raw);
3072 QL_DPRINT8(ha, (ha->pci_dev, "%s: exit\n", __func__));
3077 qlnx_stop(qlnx_host_t *ha)
3079 struct ifnet *ifp = ha->ifp;
3085 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
3088 * We simply lock and unlock each fp->tx_mtx to
3089 * propagate the if_drv_flags
3090 * state to each tx thread
3092 if (ha->state == QLNX_STATE_OPEN) {
3093 for (i = 0; i < ha->num_rss; i++) {
3094 struct qlnx_fastpath *fp = &ha->fp_array[i];
3096 mtx_lock(&fp->tx_mtx);
3097 mtx_unlock(&fp->tx_mtx);
3099 if (fp->fp_taskqueue != NULL)
3100 taskqueue_enqueue(fp->fp_taskqueue,
3111 qlnx_get_ifq_snd_maxlen(qlnx_host_t *ha)
3113 return(TX_RING_SIZE - 1);
3117 qlnx_get_mac_addr(qlnx_host_t *ha)
3119 struct ecore_hwfn *p_hwfn;
3121 p_hwfn = &ha->cdev.hwfns[0];
3122 return (p_hwfn->hw_info.hw_mac_addr);
3126 qlnx_get_optics(qlnx_host_t *ha, struct qlnx_link_output *if_link)
3128 uint32_t ifm_type = 0;
3130 switch (if_link->media_type) {
3132 case MEDIA_MODULE_FIBER:
3133 case MEDIA_UNSPECIFIED:
3134 if (if_link->speed == (100 * 1000))
3135 ifm_type = QLNX_IFM_100G_SR4;
3136 else if (if_link->speed == (40 * 1000))
3137 ifm_type = IFM_40G_SR4;
3138 else if (if_link->speed == (25 * 1000))
3139 ifm_type = QLNX_IFM_25G_SR;
3142 case MEDIA_DA_TWINAX:
3143 if (if_link->speed == (100 * 1000))
3144 ifm_type = QLNX_IFM_100G_CR4;
3145 else if (if_link->speed == (40 * 1000))
3146 ifm_type = IFM_40G_CR4;
3147 else if (if_link->speed == (25 * 1000))
3148 ifm_type = QLNX_IFM_25G_CR;
3152 ifm_type = IFM_UNKNOWN;
3160 /*****************************************************************************
3161 * Interrupt Service Functions
3162 *****************************************************************************/
3165 qlnx_rx_jumbo_chain(qlnx_host_t *ha, struct qlnx_fastpath *fp,
3166 struct mbuf *mp_head, uint16_t len)
3168 struct mbuf *mp, *mpf, *mpl;
3169 struct sw_rx_data *sw_rx_data;
3170 struct qlnx_rx_queue *rxq;
3171 uint16_t len_in_buffer;
3174 mpf = mpl = mp = NULL;
3178 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3180 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3181 mp = sw_rx_data->data;
3184 QL_DPRINT1(ha, (ha->pci_dev, "%s: mp = NULL\n",
3186 fp->err_rx_mp_null++;
3188 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3195 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3196 BUS_DMASYNC_POSTREAD);
3198 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3200 QL_DPRINT1(ha, (ha->pci_dev,
3201 "%s: New buffer allocation failed, dropping"
3202 " incoming packet and reusing its buffer\n",
3205 qlnx_reuse_rx_data(rxq);
3206 fp->err_rx_alloc_errors++;
3213 ecore_chain_consume(&rxq->rx_bd_ring);
3215 if (len > rxq->rx_buf_size)
3216 len_in_buffer = rxq->rx_buf_size;
3218 len_in_buffer = len;
3220 len = len - len_in_buffer;
3222 mp->m_flags &= ~M_PKTHDR;
3224 mp->m_len = len_in_buffer;
3235 mp_head->m_next = mpf;
3241 qlnx_tpa_start(qlnx_host_t *ha,
3242 struct qlnx_fastpath *fp,
3243 struct qlnx_rx_queue *rxq,
3244 struct eth_fast_path_rx_tpa_start_cqe *cqe)
3247 struct ifnet *ifp = ha->ifp;
3249 struct mbuf *mpf = NULL, *mpl = NULL, *mpc = NULL;
3250 struct sw_rx_data *sw_rx_data;
3253 struct eth_rx_bd *rx_bd;
3256 #if __FreeBSD_version >= 1100000
3258 #endif /* #if __FreeBSD_version >= 1100000 */
3261 agg_index = cqe->tpa_agg_index;
3263 QL_DPRINT7(ha, (dev, "%s[%d]: enter\n "
3265 "\t bitfields = 0x%x\n"
3266 "\t seg_len = 0x%x\n"
3267 "\t pars_flags = 0x%x\n"
3268 "\t vlan_tag = 0x%x\n"
3269 "\t rss_hash = 0x%x\n"
3270 "\t len_on_first_bd = 0x%x\n"
3271 "\t placement_offset = 0x%x\n"
3272 "\t tpa_agg_index = 0x%x\n"
3273 "\t header_len = 0x%x\n"
3274 "\t ext_bd_len_list[0] = 0x%x\n"
3275 "\t ext_bd_len_list[1] = 0x%x\n"
3276 "\t ext_bd_len_list[2] = 0x%x\n"
3277 "\t ext_bd_len_list[3] = 0x%x\n"
3278 "\t ext_bd_len_list[4] = 0x%x\n",
3279 __func__, fp->rss_id, cqe->type, cqe->bitfields, cqe->seg_len,
3280 cqe->pars_flags.flags, cqe->vlan_tag,
3281 cqe->rss_hash, cqe->len_on_first_bd, cqe->placement_offset,
3282 cqe->tpa_agg_index, cqe->header_len,
3283 cqe->ext_bd_len_list[0], cqe->ext_bd_len_list[1],
3284 cqe->ext_bd_len_list[2], cqe->ext_bd_len_list[3],
3285 cqe->ext_bd_len_list[4]));
3287 if (agg_index >= ETH_TPA_MAX_AGGS_NUM) {
3288 fp->err_rx_tpa_invalid_agg_num++;
3292 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3293 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map, BUS_DMASYNC_POSTREAD);
3294 mp = sw_rx_data->data;
3296 QL_DPRINT7(ha, (dev, "%s[%d]: mp = %p \n ", __func__, fp->rss_id, mp));
3299 QL_DPRINT7(ha, (dev, "%s[%d]: mp = NULL\n", __func__,
3301 fp->err_rx_mp_null++;
3302 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3307 if ((le16toh(cqe->pars_flags.flags)) & CQE_FLAGS_ERR) {
3309 QL_DPRINT7(ha, (dev, "%s[%d]: CQE in CONS = %u has error,"
3310 " flags = %x, dropping incoming packet\n", __func__,
3311 fp->rss_id, rxq->sw_rx_cons,
3312 le16toh(cqe->pars_flags.flags)));
3314 fp->err_rx_hw_errors++;
3316 qlnx_reuse_rx_data(rxq);
3318 QLNX_INC_IERRORS(ifp);
3323 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3325 QL_DPRINT7(ha, (dev, "%s[%d]: New buffer allocation failed,"
3326 " dropping incoming packet and reusing its buffer\n",
3327 __func__, fp->rss_id));
3329 fp->err_rx_alloc_errors++;
3330 QLNX_INC_IQDROPS(ifp);
3333 * Load the tpa mbuf into the rx ring and save the
3337 map = sw_rx_data->map;
3338 addr = sw_rx_data->dma_addr;
3340 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_prod];
3342 sw_rx_data->data = rxq->tpa_info[agg_index].rx_buf.data;
3343 sw_rx_data->dma_addr = rxq->tpa_info[agg_index].rx_buf.dma_addr;
3344 sw_rx_data->map = rxq->tpa_info[agg_index].rx_buf.map;
3346 rxq->tpa_info[agg_index].rx_buf.data = mp;
3347 rxq->tpa_info[agg_index].rx_buf.dma_addr = addr;
3348 rxq->tpa_info[agg_index].rx_buf.map = map;
3350 rx_bd = (struct eth_rx_bd *)
3351 ecore_chain_produce(&rxq->rx_bd_ring);
3353 rx_bd->addr.hi = htole32(U64_HI(sw_rx_data->dma_addr));
3354 rx_bd->addr.lo = htole32(U64_LO(sw_rx_data->dma_addr));
3356 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3357 BUS_DMASYNC_PREREAD);
3359 rxq->sw_rx_prod = (rxq->sw_rx_prod + 1) & (RX_RING_SIZE - 1);
3360 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3362 ecore_chain_consume(&rxq->rx_bd_ring);
3364 /* Now reuse any buffers posted in ext_bd_len_list */
3365 for (i = 0; i < ETH_TPA_CQE_START_LEN_LIST_SIZE; i++) {
3367 if (cqe->ext_bd_len_list[i] == 0)
3370 qlnx_reuse_rx_data(rxq);
3373 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_ERROR;
3377 if (rxq->tpa_info[agg_index].agg_state != QLNX_AGG_STATE_NONE) {
3379 QL_DPRINT7(ha, (dev, "%s[%d]: invalid aggregation state,"
3380 " dropping incoming packet and reusing its buffer\n",
3381 __func__, fp->rss_id));
3383 QLNX_INC_IQDROPS(ifp);
3385 /* if we already have mbuf head in aggregation free it */
3386 if (rxq->tpa_info[agg_index].mpf) {
3387 m_freem(rxq->tpa_info[agg_index].mpf);
3388 rxq->tpa_info[agg_index].mpl = NULL;
3390 rxq->tpa_info[agg_index].mpf = mp;
3391 rxq->tpa_info[agg_index].mpl = NULL;
3393 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3394 ecore_chain_consume(&rxq->rx_bd_ring);
3396 /* Now reuse any buffers posted in ext_bd_len_list */
3397 for (i = 0; i < ETH_TPA_CQE_START_LEN_LIST_SIZE; i++) {
3399 if (cqe->ext_bd_len_list[i] == 0)
3402 qlnx_reuse_rx_data(rxq);
3404 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_ERROR;
3410 * first process the ext_bd_len_list
3411 * if this fails then we simply drop the packet
3413 ecore_chain_consume(&rxq->rx_bd_ring);
3414 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3416 for (i = 0; i < ETH_TPA_CQE_START_LEN_LIST_SIZE; i++) {
3418 QL_DPRINT7(ha, (dev, "%s[%d]: 4\n ", __func__, fp->rss_id));
3420 if (cqe->ext_bd_len_list[i] == 0)
3423 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3424 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3425 BUS_DMASYNC_POSTREAD);
3427 mpc = sw_rx_data->data;
3430 QL_DPRINT7(ha, (ha->pci_dev, "%s[%d]: mpc = NULL\n",
3431 __func__, fp->rss_id));
3432 fp->err_rx_mp_null++;
3436 rxq->tpa_info[agg_index].agg_state =
3437 QLNX_AGG_STATE_ERROR;
3438 ecore_chain_consume(&rxq->rx_bd_ring);
3440 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3444 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3445 QL_DPRINT7(ha, (dev,
3446 "%s[%d]: New buffer allocation failed, dropping"
3447 " incoming packet and reusing its buffer\n",
3448 __func__, fp->rss_id));
3450 qlnx_reuse_rx_data(rxq);
3456 rxq->tpa_info[agg_index].agg_state =
3457 QLNX_AGG_STATE_ERROR;
3459 ecore_chain_consume(&rxq->rx_bd_ring);
3461 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3466 mpc->m_flags &= ~M_PKTHDR;
3468 mpc->m_len = cqe->ext_bd_len_list[i];
3474 mpl->m_len = ha->rx_buf_size;
3479 ecore_chain_consume(&rxq->rx_bd_ring);
3481 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3484 if (rxq->tpa_info[agg_index].agg_state != QLNX_AGG_STATE_NONE) {
3486 QL_DPRINT7(ha, (dev, "%s[%d]: invalid aggregation state,"
3487 " dropping incoming packet and reusing its buffer\n",
3488 __func__, fp->rss_id));
3490 QLNX_INC_IQDROPS(ifp);
3492 rxq->tpa_info[agg_index].mpf = mp;
3493 rxq->tpa_info[agg_index].mpl = NULL;
3498 rxq->tpa_info[agg_index].placement_offset = cqe->placement_offset;
3501 mp->m_len = ha->rx_buf_size;
3503 rxq->tpa_info[agg_index].mpf = mp;
3504 rxq->tpa_info[agg_index].mpl = mpl;
3506 mp->m_len = cqe->len_on_first_bd + cqe->placement_offset;
3507 rxq->tpa_info[agg_index].mpf = mp;
3508 rxq->tpa_info[agg_index].mpl = mp;
3512 mp->m_flags |= M_PKTHDR;
3514 /* assign packet to this interface interface */
3515 mp->m_pkthdr.rcvif = ifp;
3517 /* assume no hardware checksum has complated */
3518 mp->m_pkthdr.csum_flags = 0;
3520 //mp->m_pkthdr.flowid = fp->rss_id;
3521 mp->m_pkthdr.flowid = cqe->rss_hash;
3523 #if __FreeBSD_version >= 1100000
3525 hash_type = cqe->bitfields &
3526 (ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_MASK <<
3527 ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_SHIFT);
3529 switch (hash_type) {
3531 case RSS_HASH_TYPE_IPV4:
3532 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV4);
3535 case RSS_HASH_TYPE_TCP_IPV4:
3536 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV4);
3539 case RSS_HASH_TYPE_IPV6:
3540 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV6);
3543 case RSS_HASH_TYPE_TCP_IPV6:
3544 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV6);
3548 M_HASHTYPE_SET(mp, M_HASHTYPE_OPAQUE);
3553 mp->m_flags |= M_FLOWID;
3556 mp->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED | CSUM_IP_VALID |
3557 CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
3559 mp->m_pkthdr.csum_data = 0xFFFF;
3561 if (CQE_HAS_VLAN(cqe->pars_flags.flags)) {
3562 mp->m_pkthdr.ether_vtag = le16toh(cqe->vlan_tag);
3563 mp->m_flags |= M_VLANTAG;
3566 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_START;
3568 QL_DPRINT7(ha, (dev, "%s[%d]: 5\n" "\tagg_state = %d\n"
3569 "\t mpf = %p mpl = %p\n", __func__, fp->rss_id,
3570 rxq->tpa_info[agg_index].agg_state,
3571 rxq->tpa_info[agg_index].mpf, rxq->tpa_info[agg_index].mpl));
3577 qlnx_tpa_cont(qlnx_host_t *ha, struct qlnx_fastpath *fp,
3578 struct qlnx_rx_queue *rxq,
3579 struct eth_fast_path_rx_tpa_cont_cqe *cqe)
3581 struct sw_rx_data *sw_rx_data;
3583 struct mbuf *mpf = NULL, *mpl = NULL, *mpc = NULL;
3590 QL_DPRINT7(ha, (dev, "%s[%d]: enter\n "
3592 "\t tpa_agg_index = 0x%x\n"
3593 "\t len_list[0] = 0x%x\n"
3594 "\t len_list[1] = 0x%x\n"
3595 "\t len_list[2] = 0x%x\n"
3596 "\t len_list[3] = 0x%x\n"
3597 "\t len_list[4] = 0x%x\n"
3598 "\t len_list[5] = 0x%x\n",
3599 __func__, fp->rss_id, cqe->type, cqe->tpa_agg_index,
3600 cqe->len_list[0], cqe->len_list[1], cqe->len_list[2],
3601 cqe->len_list[3], cqe->len_list[4], cqe->len_list[5]));
3603 agg_index = cqe->tpa_agg_index;
3605 if (agg_index >= ETH_TPA_MAX_AGGS_NUM) {
3606 QL_DPRINT7(ha, (dev, "%s[%d]: 0\n ", __func__, fp->rss_id));
3607 fp->err_rx_tpa_invalid_agg_num++;
3612 for (i = 0; i < ETH_TPA_CQE_CONT_LEN_LIST_SIZE; i++) {
3614 QL_DPRINT7(ha, (dev, "%s[%d]: 1\n ", __func__, fp->rss_id));
3616 if (cqe->len_list[i] == 0)
3619 if (rxq->tpa_info[agg_index].agg_state !=
3620 QLNX_AGG_STATE_START) {
3621 qlnx_reuse_rx_data(rxq);
3625 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3626 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3627 BUS_DMASYNC_POSTREAD);
3629 mpc = sw_rx_data->data;
3633 QL_DPRINT7(ha, (dev, "%s[%d]: mpc = NULL\n",
3634 __func__, fp->rss_id));
3636 fp->err_rx_mp_null++;
3640 rxq->tpa_info[agg_index].agg_state =
3641 QLNX_AGG_STATE_ERROR;
3642 ecore_chain_consume(&rxq->rx_bd_ring);
3644 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3648 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3650 QL_DPRINT7(ha, (dev,
3651 "%s[%d]: New buffer allocation failed, dropping"
3652 " incoming packet and reusing its buffer\n",
3653 __func__, fp->rss_id));
3655 qlnx_reuse_rx_data(rxq);
3661 rxq->tpa_info[agg_index].agg_state =
3662 QLNX_AGG_STATE_ERROR;
3664 ecore_chain_consume(&rxq->rx_bd_ring);
3666 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3671 mpc->m_flags &= ~M_PKTHDR;
3673 mpc->m_len = cqe->len_list[i];
3679 mpl->m_len = ha->rx_buf_size;
3684 ecore_chain_consume(&rxq->rx_bd_ring);
3686 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3689 QL_DPRINT7(ha, (dev, "%s[%d]: 2\n" "\tmpf = %p mpl = %p\n",
3690 __func__, fp->rss_id, mpf, mpl));
3693 mp = rxq->tpa_info[agg_index].mpl;
3694 mp->m_len = ha->rx_buf_size;
3696 rxq->tpa_info[agg_index].mpl = mpl;
3703 qlnx_tpa_end(qlnx_host_t *ha, struct qlnx_fastpath *fp,
3704 struct qlnx_rx_queue *rxq,
3705 struct eth_fast_path_rx_tpa_end_cqe *cqe)
3707 struct sw_rx_data *sw_rx_data;
3709 struct mbuf *mpf = NULL, *mpl = NULL, *mpc = NULL;
3713 struct ifnet *ifp = ha->ifp;
3718 QL_DPRINT7(ha, (dev, "%s[%d]: enter\n "
3720 "\t tpa_agg_index = 0x%x\n"
3721 "\t total_packet_len = 0x%x\n"
3722 "\t num_of_bds = 0x%x\n"
3723 "\t end_reason = 0x%x\n"
3724 "\t num_of_coalesced_segs = 0x%x\n"
3725 "\t ts_delta = 0x%x\n"
3726 "\t len_list[0] = 0x%x\n"
3727 "\t len_list[1] = 0x%x\n"
3728 "\t len_list[2] = 0x%x\n"
3729 "\t len_list[3] = 0x%x\n",
3730 __func__, fp->rss_id, cqe->type, cqe->tpa_agg_index,
3731 cqe->total_packet_len, cqe->num_of_bds,
3732 cqe->end_reason, cqe->num_of_coalesced_segs, cqe->ts_delta,
3733 cqe->len_list[0], cqe->len_list[1], cqe->len_list[2],
3736 agg_index = cqe->tpa_agg_index;
3738 if (agg_index >= ETH_TPA_MAX_AGGS_NUM) {
3740 QL_DPRINT7(ha, (dev, "%s[%d]: 0\n ", __func__, fp->rss_id));
3742 fp->err_rx_tpa_invalid_agg_num++;
3747 for (i = 0; i < ETH_TPA_CQE_END_LEN_LIST_SIZE; i++) {
3749 QL_DPRINT7(ha, (dev, "%s[%d]: 1\n ", __func__, fp->rss_id));
3751 if (cqe->len_list[i] == 0)
3754 if (rxq->tpa_info[agg_index].agg_state !=
3755 QLNX_AGG_STATE_START) {
3757 QL_DPRINT7(ha, (dev, "%s[%d]: 2\n ", __func__,
3760 qlnx_reuse_rx_data(rxq);
3764 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3765 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3766 BUS_DMASYNC_POSTREAD);
3768 mpc = sw_rx_data->data;
3772 QL_DPRINT7(ha, (dev, "%s[%d]: mpc = NULL\n",
3773 __func__, fp->rss_id));
3775 fp->err_rx_mp_null++;
3779 rxq->tpa_info[agg_index].agg_state =
3780 QLNX_AGG_STATE_ERROR;
3781 ecore_chain_consume(&rxq->rx_bd_ring);
3783 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3787 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3788 QL_DPRINT7(ha, (dev,
3789 "%s[%d]: New buffer allocation failed, dropping"
3790 " incoming packet and reusing its buffer\n",
3791 __func__, fp->rss_id));
3793 qlnx_reuse_rx_data(rxq);
3799 rxq->tpa_info[agg_index].agg_state =
3800 QLNX_AGG_STATE_ERROR;
3802 ecore_chain_consume(&rxq->rx_bd_ring);
3804 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3809 mpc->m_flags &= ~M_PKTHDR;
3811 mpc->m_len = cqe->len_list[i];
3817 mpl->m_len = ha->rx_buf_size;
3822 ecore_chain_consume(&rxq->rx_bd_ring);
3824 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3827 QL_DPRINT7(ha, (dev, "%s[%d]: 5\n ", __func__, fp->rss_id));
3831 QL_DPRINT7(ha, (dev, "%s[%d]: 6\n ", __func__, fp->rss_id));
3833 mp = rxq->tpa_info[agg_index].mpl;
3834 mp->m_len = ha->rx_buf_size;
3838 if (rxq->tpa_info[agg_index].agg_state != QLNX_AGG_STATE_START) {
3840 QL_DPRINT7(ha, (dev, "%s[%d]: 7\n ", __func__, fp->rss_id));
3842 if (rxq->tpa_info[agg_index].mpf != NULL)
3843 m_freem(rxq->tpa_info[agg_index].mpf);
3844 rxq->tpa_info[agg_index].mpf = NULL;
3845 rxq->tpa_info[agg_index].mpl = NULL;
3846 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_NONE;
3850 mp = rxq->tpa_info[agg_index].mpf;
3851 m_adj(mp, rxq->tpa_info[agg_index].placement_offset);
3852 mp->m_pkthdr.len = cqe->total_packet_len;
3854 if (mp->m_next == NULL)
3855 mp->m_len = mp->m_pkthdr.len;
3857 /* compute the total packet length */
3859 while (mpf != NULL) {
3864 if (cqe->total_packet_len > len) {
3865 mpl = rxq->tpa_info[agg_index].mpl;
3866 mpl->m_len += (cqe->total_packet_len - len);
3870 QLNX_INC_IPACKETS(ifp);
3871 QLNX_INC_IBYTES(ifp, (cqe->total_packet_len));
3873 QL_DPRINT7(ha, (dev, "%s[%d]: 8 csum_data = 0x%x csum_flags = 0x%lx\n "
3874 "m_len = 0x%x m_pkthdr_len = 0x%x\n",
3875 __func__, fp->rss_id, mp->m_pkthdr.csum_data,
3876 mp->m_pkthdr.csum_flags, mp->m_len, mp->m_pkthdr.len));
3878 (*ifp->if_input)(ifp, mp);
3880 rxq->tpa_info[agg_index].mpf = NULL;
3881 rxq->tpa_info[agg_index].mpl = NULL;
3882 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_NONE;
3884 return (cqe->num_of_coalesced_segs);
3888 qlnx_rx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp, int budget,
3891 uint16_t hw_comp_cons, sw_comp_cons;
3893 struct qlnx_rx_queue *rxq = fp->rxq;
3894 struct ifnet *ifp = ha->ifp;
3895 struct ecore_dev *cdev = &ha->cdev;
3896 struct ecore_hwfn *p_hwfn;
3898 #ifdef QLNX_SOFT_LRO
3899 struct lro_ctrl *lro;
3902 #endif /* #ifdef QLNX_SOFT_LRO */
3904 hw_comp_cons = le16toh(*rxq->hw_cons_ptr);
3905 sw_comp_cons = ecore_chain_get_cons_idx(&rxq->rx_comp_ring);
3907 p_hwfn = &ha->cdev.hwfns[(fp->rss_id % cdev->num_hwfns)];
3909 /* Memory barrier to prevent the CPU from doing speculative reads of CQE
3910 * / BD in the while-loop before reading hw_comp_cons. If the CQE is
3911 * read before it is written by FW, then FW writes CQE and SB, and then
3912 * the CPU reads the hw_comp_cons, it will use an old CQE.
3915 /* Loop to complete all indicated BDs */
3916 while (sw_comp_cons != hw_comp_cons) {
3917 union eth_rx_cqe *cqe;
3918 struct eth_fast_path_rx_reg_cqe *fp_cqe;
3919 struct sw_rx_data *sw_rx_data;
3920 register struct mbuf *mp;
3921 enum eth_rx_cqe_type cqe_type;
3922 uint16_t len, pad, len_on_first_bd;
3924 #if __FreeBSD_version >= 1100000
3926 #endif /* #if __FreeBSD_version >= 1100000 */
3928 /* Get the CQE from the completion ring */
3929 cqe = (union eth_rx_cqe *)
3930 ecore_chain_consume(&rxq->rx_comp_ring);
3931 cqe_type = cqe->fast_path_regular.type;
3933 if (cqe_type == ETH_RX_CQE_TYPE_SLOW_PATH) {
3934 QL_DPRINT3(ha, (ha->pci_dev, "Got a slowath CQE\n"));
3936 ecore_eth_cqe_completion(p_hwfn,
3937 (struct eth_slow_path_rx_cqe *)cqe);
3941 if (cqe_type != ETH_RX_CQE_TYPE_REGULAR) {
3945 case ETH_RX_CQE_TYPE_TPA_START:
3946 qlnx_tpa_start(ha, fp, rxq,
3947 &cqe->fast_path_tpa_start);
3951 case ETH_RX_CQE_TYPE_TPA_CONT:
3952 qlnx_tpa_cont(ha, fp, rxq,
3953 &cqe->fast_path_tpa_cont);
3957 case ETH_RX_CQE_TYPE_TPA_END:
3958 rx_pkt += qlnx_tpa_end(ha, fp, rxq,
3959 &cqe->fast_path_tpa_end);
3970 /* Get the data from the SW ring */
3971 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3972 mp = sw_rx_data->data;
3975 QL_DPRINT1(ha, (ha->pci_dev, "%s: mp = NULL\n",
3977 fp->err_rx_mp_null++;
3979 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3982 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3983 BUS_DMASYNC_POSTREAD);
3986 fp_cqe = &cqe->fast_path_regular;/* MK CR TPA check assembly */
3987 len = le16toh(fp_cqe->pkt_len);
3988 pad = fp_cqe->placement_offset;
3991 (ha->pci_dev, "CQE type = %x, flags = %x, vlan = %x,"
3992 " len %u, parsing flags = %d pad = %d\n",
3993 cqe_type, fp_cqe->bitfields,
3994 le16toh(fp_cqe->vlan_tag),
3995 len, le16toh(fp_cqe->pars_flags.flags), pad));
3997 data = mtod(mp, uint8_t *);
4001 qlnx_dump_buf8(ha, __func__, data, len);
4003 /* For every Rx BD consumed, we allocate a new BD so the BD ring
4004 * is always with a fixed size. If allocation fails, we take the
4005 * consumed BD and return it to the ring in the PROD position.
4006 * The packet that was received on that BD will be dropped (and
4007 * not passed to the upper stack).
4009 /* If this is an error packet then drop it */
4010 if ((le16toh(cqe->fast_path_regular.pars_flags.flags)) &
4013 QL_DPRINT1(ha, (ha->pci_dev,
4014 "CQE in CONS = %u has error, flags = %x,"
4015 " dropping incoming packet\n", sw_comp_cons,
4016 le16toh(cqe->fast_path_regular.pars_flags.flags)));
4018 fp->err_rx_hw_errors++;
4020 qlnx_reuse_rx_data(rxq);
4022 QLNX_INC_IERRORS(ifp);
4027 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
4029 QL_DPRINT1(ha, (ha->pci_dev,
4030 "New buffer allocation failed, dropping"
4031 " incoming packet and reusing its buffer\n"));
4033 qlnx_reuse_rx_data(rxq);
4035 fp->err_rx_alloc_errors++;
4037 QLNX_INC_IQDROPS(ifp);
4042 ecore_chain_consume(&rxq->rx_bd_ring);
4044 len_on_first_bd = fp_cqe->len_on_first_bd;
4046 mp->m_pkthdr.len = len;
4049 (ha->pci_dev, "%s: len = %d len_on_first_bd = %d\n",
4050 __func__, len, len_on_first_bd));
4052 if ((len > 60 ) && (len > len_on_first_bd)) {
4054 mp->m_len = len_on_first_bd;
4056 if (qlnx_rx_jumbo_chain(ha, fp, mp,
4057 (len - len_on_first_bd)) != 0) {
4061 QLNX_INC_IQDROPS(ifp);
4066 } else if (len_on_first_bd < len) {
4067 fp->err_rx_jumbo_chain_pkts++;
4072 mp->m_flags |= M_PKTHDR;
4074 /* assign packet to this interface interface */
4075 mp->m_pkthdr.rcvif = ifp;
4077 /* assume no hardware checksum has complated */
4078 mp->m_pkthdr.csum_flags = 0;
4080 mp->m_pkthdr.flowid = fp_cqe->rss_hash;
4082 #if __FreeBSD_version >= 1100000
4084 hash_type = fp_cqe->bitfields &
4085 (ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_MASK <<
4086 ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_SHIFT);
4088 switch (hash_type) {
4090 case RSS_HASH_TYPE_IPV4:
4091 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV4);
4094 case RSS_HASH_TYPE_TCP_IPV4:
4095 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV4);
4098 case RSS_HASH_TYPE_IPV6:
4099 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV6);
4102 case RSS_HASH_TYPE_TCP_IPV6:
4103 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV6);
4107 M_HASHTYPE_SET(mp, M_HASHTYPE_OPAQUE);
4112 mp->m_flags |= M_FLOWID;
4115 if (CQE_L3_PACKET(fp_cqe->pars_flags.flags)) {
4116 mp->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
4119 if (!(CQE_IP_HDR_ERR(fp_cqe->pars_flags.flags))) {
4120 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
4123 if (CQE_L4_HAS_CSUM(fp_cqe->pars_flags.flags)) {
4124 mp->m_pkthdr.csum_data = 0xFFFF;
4125 mp->m_pkthdr.csum_flags |=
4126 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
4129 if (CQE_HAS_VLAN(fp_cqe->pars_flags.flags)) {
4130 mp->m_pkthdr.ether_vtag = le16toh(fp_cqe->vlan_tag);
4131 mp->m_flags |= M_VLANTAG;
4134 QLNX_INC_IPACKETS(ifp);
4135 QLNX_INC_IBYTES(ifp, len);
4137 #ifdef QLNX_SOFT_LRO
4141 #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
4143 tcp_lro_queue_mbuf(lro, mp);
4147 if (tcp_lro_rx(lro, mp, 0))
4148 (*ifp->if_input)(ifp, mp);
4150 #endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
4153 (*ifp->if_input)(ifp, mp);
4157 (*ifp->if_input)(ifp, mp);
4159 #endif /* #ifdef QLNX_SOFT_LRO */
4163 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
4165 next_cqe: /* don't consume bd rx buffer */
4166 ecore_chain_recycle_consumed(&rxq->rx_comp_ring);
4167 sw_comp_cons = ecore_chain_get_cons_idx(&rxq->rx_comp_ring);
4169 /* CR TPA - revisit how to handle budget in TPA perhaps
4170 increase on "end" */
4171 if (rx_pkt == budget)
4173 } /* repeat while sw_comp_cons != hw_comp_cons... */
4175 /* Update producers */
4176 qlnx_update_rx_prod(p_hwfn, rxq);
4182 * fast path interrupt
4186 qlnx_fp_isr(void *arg)
4188 qlnx_ivec_t *ivec = arg;
4190 struct qlnx_fastpath *fp = NULL;
4191 int idx, lro_enable, tc;
4192 int rx_int = 0, total_rx_count = 0;
4195 lro_enable = ha->ifp->if_capenable & IFCAP_LRO;
4197 if (ha->state != QLNX_STATE_OPEN) {
4201 idx = ivec->rss_idx;
4203 if ((idx = ivec->rss_idx) >= ha->num_rss) {
4204 QL_DPRINT1(ha, (ha->pci_dev, "%s: illegal interrupt[%d]\n",
4206 ha->err_illegal_intr++;
4209 fp = &ha->fp_array[idx];
4212 QL_DPRINT1(ha, (ha->pci_dev, "%s: fp_array[%d] NULL\n",
4216 ecore_sb_ack(fp->sb_info, IGU_INT_DISABLE, 0);
4219 for (tc = 0; tc < ha->num_tc; tc++) {
4220 if (mtx_trylock(&fp->tx_mtx)) {
4221 qlnx_tx_int(ha, fp, fp->txq[tc]);
4222 mtx_unlock(&fp->tx_mtx);
4226 rx_int = qlnx_rx_int(ha, fp, ha->rx_pkt_threshold,
4230 fp->rx_pkts += rx_int;
4231 total_rx_count += rx_int;
4237 #ifdef QLNX_SOFT_LRO
4239 struct lro_ctrl *lro;
4241 lro = &fp->rxq->lro;
4243 if (lro_enable && total_rx_count) {
4245 #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
4247 #ifdef QLNX_TRACE_LRO_CNT
4248 if (lro->lro_mbuf_count & ~1023)
4250 else if (lro->lro_mbuf_count & ~511)
4252 else if (lro->lro_mbuf_count & ~255)
4254 else if (lro->lro_mbuf_count & ~127)
4256 else if (lro->lro_mbuf_count & ~63)
4258 #endif /* #ifdef QLNX_TRACE_LRO_CNT */
4260 tcp_lro_flush_all(lro);
4263 struct lro_entry *queued;
4265 while ((!SLIST_EMPTY(&lro->lro_active))) {
4266 queued = SLIST_FIRST(&lro->lro_active);
4267 SLIST_REMOVE_HEAD(&lro->lro_active, \
4269 tcp_lro_flush(lro, queued);
4271 #endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
4274 #endif /* #ifdef QLNX_SOFT_LRO */
4276 if (fp->fp_taskqueue != NULL)
4277 taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
4279 ecore_sb_update_sb_idx(fp->sb_info);
4281 ecore_sb_ack(fp->sb_info, IGU_INT_ENABLE, 1);
4291 * slow path interrupt processing function
4292 * can be invoked in polled mode or in interrupt mode via taskqueue.
4295 qlnx_sp_isr(void *arg)
4297 struct ecore_hwfn *p_hwfn;
4302 ha = (qlnx_host_t *)p_hwfn->p_dev;
4304 ha->sp_interrupts++;
4306 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
4308 ecore_int_sp_dpc(p_hwfn);
4310 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
4315 /*****************************************************************************
4316 * Support Functions for DMA'able Memory
4317 *****************************************************************************/
4320 qlnx_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
4322 *((bus_addr_t *)arg) = 0;
4325 printf("%s: bus_dmamap_load failed (%d)\n", __func__, error);
4329 *((bus_addr_t *)arg) = segs[0].ds_addr;
4335 qlnx_alloc_dmabuf(qlnx_host_t *ha, qlnx_dma_t *dma_buf)
4343 ret = bus_dma_tag_create(
4344 ha->parent_tag,/* parent */
4346 ((bus_size_t)(1ULL << 32)),/* boundary */
4347 BUS_SPACE_MAXADDR, /* lowaddr */
4348 BUS_SPACE_MAXADDR, /* highaddr */
4349 NULL, NULL, /* filter, filterarg */
4350 dma_buf->size, /* maxsize */
4352 dma_buf->size, /* maxsegsize */
4354 NULL, NULL, /* lockfunc, lockarg */
4359 (dev, "%s: could not create dma tag\n", __func__));
4360 goto qlnx_alloc_dmabuf_exit;
4362 ret = bus_dmamem_alloc(dma_buf->dma_tag,
4363 (void **)&dma_buf->dma_b,
4364 (BUS_DMA_ZERO | BUS_DMA_COHERENT | BUS_DMA_NOWAIT),
4367 bus_dma_tag_destroy(dma_buf->dma_tag);
4369 (dev, "%s: bus_dmamem_alloc failed\n", __func__));
4370 goto qlnx_alloc_dmabuf_exit;
4373 ret = bus_dmamap_load(dma_buf->dma_tag,
4377 qlnx_dmamap_callback,
4378 &b_addr, BUS_DMA_NOWAIT);
4380 if (ret || !b_addr) {
4381 bus_dma_tag_destroy(dma_buf->dma_tag);
4382 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b,
4385 goto qlnx_alloc_dmabuf_exit;
4388 dma_buf->dma_addr = b_addr;
4390 qlnx_alloc_dmabuf_exit:
4396 qlnx_free_dmabuf(qlnx_host_t *ha, qlnx_dma_t *dma_buf)
4398 bus_dmamap_unload(dma_buf->dma_tag, dma_buf->dma_map);
4399 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b, dma_buf->dma_map);
4400 bus_dma_tag_destroy(dma_buf->dma_tag);
4405 qlnx_dma_alloc_coherent(void *ecore_dev, bus_addr_t *phys, uint32_t size)
4412 ha = (qlnx_host_t *)ecore_dev;
4415 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4417 memset(&dma_buf, 0, sizeof (qlnx_dma_t));
4419 dma_buf.size = size + PAGE_SIZE;
4420 dma_buf.alignment = 8;
4422 if (qlnx_alloc_dmabuf((qlnx_host_t *)ecore_dev, &dma_buf) != 0)
4424 bzero((uint8_t *)dma_buf.dma_b, dma_buf.size);
4426 *phys = dma_buf.dma_addr;
4428 dma_p = (qlnx_dma_t *)((uint8_t *)dma_buf.dma_b + size);
4430 memcpy(dma_p, &dma_buf, sizeof(qlnx_dma_t));
4432 QL_DPRINT5(ha, (dev, "%s: [%p %p %p %p 0x%08x ]\n", __func__,
4433 (void *)dma_buf.dma_map, (void *)dma_buf.dma_tag,
4434 dma_buf.dma_b, (void *)dma_buf.dma_addr, size));
4436 return (dma_buf.dma_b);
4440 qlnx_dma_free_coherent(void *ecore_dev, void *v_addr, bus_addr_t phys,
4443 qlnx_dma_t dma_buf, *dma_p;
4447 ha = (qlnx_host_t *)ecore_dev;
4453 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4455 dma_p = (qlnx_dma_t *)((uint8_t *)v_addr + size);
4457 QL_DPRINT5(ha, (dev, "%s: [%p %p %p %p 0x%08x ]\n", __func__,
4458 (void *)dma_p->dma_map, (void *)dma_p->dma_tag,
4459 dma_p->dma_b, (void *)dma_p->dma_addr, size));
4463 qlnx_free_dmabuf((qlnx_host_t *)ecore_dev, &dma_buf);
4468 qlnx_alloc_parent_dma_tag(qlnx_host_t *ha)
4476 * Allocate parent DMA Tag
4478 ret = bus_dma_tag_create(
4479 bus_get_dma_tag(dev), /* parent */
4480 1,((bus_size_t)(1ULL << 32)),/* alignment, boundary */
4481 BUS_SPACE_MAXADDR, /* lowaddr */
4482 BUS_SPACE_MAXADDR, /* highaddr */
4483 NULL, NULL, /* filter, filterarg */
4484 BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
4486 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
4488 NULL, NULL, /* lockfunc, lockarg */
4492 QL_DPRINT1(ha, (dev, "%s: could not create parent dma tag\n",
4497 ha->flags.parent_tag = 1;
4503 qlnx_free_parent_dma_tag(qlnx_host_t *ha)
4505 if (ha->parent_tag != NULL) {
4506 bus_dma_tag_destroy(ha->parent_tag);
4507 ha->parent_tag = NULL;
4513 qlnx_alloc_tx_dma_tag(qlnx_host_t *ha)
4515 if (bus_dma_tag_create(NULL, /* parent */
4516 1, 0, /* alignment, bounds */
4517 BUS_SPACE_MAXADDR, /* lowaddr */
4518 BUS_SPACE_MAXADDR, /* highaddr */
4519 NULL, NULL, /* filter, filterarg */
4520 QLNX_MAX_TSO_FRAME_SIZE, /* maxsize */
4521 QLNX_MAX_SEGMENTS, /* nsegments */
4522 (PAGE_SIZE * 4), /* maxsegsize */
4523 BUS_DMA_ALLOCNOW, /* flags */
4524 NULL, /* lockfunc */
4525 NULL, /* lockfuncarg */
4528 QL_DPRINT1(ha, (ha->pci_dev, "%s: tx_tag alloc failed\n",
4537 qlnx_free_tx_dma_tag(qlnx_host_t *ha)
4539 if (ha->tx_tag != NULL) {
4540 bus_dma_tag_destroy(ha->tx_tag);
4547 qlnx_alloc_rx_dma_tag(qlnx_host_t *ha)
4549 if (bus_dma_tag_create(NULL, /* parent */
4550 1, 0, /* alignment, bounds */
4551 BUS_SPACE_MAXADDR, /* lowaddr */
4552 BUS_SPACE_MAXADDR, /* highaddr */
4553 NULL, NULL, /* filter, filterarg */
4554 MJUM9BYTES, /* maxsize */
4556 MJUM9BYTES, /* maxsegsize */
4557 BUS_DMA_ALLOCNOW, /* flags */
4558 NULL, /* lockfunc */
4559 NULL, /* lockfuncarg */
4562 QL_DPRINT1(ha, (ha->pci_dev, "%s: rx_tag alloc failed\n",
4571 qlnx_free_rx_dma_tag(qlnx_host_t *ha)
4573 if (ha->rx_tag != NULL) {
4574 bus_dma_tag_destroy(ha->rx_tag);
4580 /*********************************
4581 * Exported functions
4582 *********************************/
4584 qlnx_pci_bus_get_bar_size(void *ecore_dev, uint8_t bar_id)
4588 bar_id = bar_id * 2;
4590 bar_size = bus_get_resource_count(((qlnx_host_t *)ecore_dev)->pci_dev,
4598 qlnx_pci_read_config_byte(void *ecore_dev, uint32_t pci_reg, uint8_t *reg_value)
4600 *reg_value = pci_read_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4606 qlnx_pci_read_config_word(void *ecore_dev, uint32_t pci_reg,
4607 uint16_t *reg_value)
4609 *reg_value = pci_read_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4615 qlnx_pci_read_config_dword(void *ecore_dev, uint32_t pci_reg,
4616 uint32_t *reg_value)
4618 *reg_value = pci_read_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4624 qlnx_pci_write_config_byte(void *ecore_dev, uint32_t pci_reg, uint8_t reg_value)
4626 pci_write_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4627 pci_reg, reg_value, 1);
4632 qlnx_pci_write_config_word(void *ecore_dev, uint32_t pci_reg,
4635 pci_write_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4636 pci_reg, reg_value, 2);
4641 qlnx_pci_write_config_dword(void *ecore_dev, uint32_t pci_reg,
4644 pci_write_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4645 pci_reg, reg_value, 4);
4651 qlnx_pci_find_capability(void *ecore_dev, int cap)
4655 if (pci_find_cap(((qlnx_host_t *)ecore_dev)->pci_dev, PCIY_EXPRESS,
4659 QL_DPRINT1(((qlnx_host_t *)ecore_dev),
4660 (((qlnx_host_t *)ecore_dev)->pci_dev,
4661 "%s: failed\n", __func__));
4667 qlnx_reg_rd32(void *hwfn, uint32_t reg_addr)
4670 struct ecore_dev *cdev;
4671 struct ecore_hwfn *p_hwfn;
4675 cdev = p_hwfn->p_dev;
4677 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->regview) -
4678 (uint8_t *)(cdev->regview)) + reg_addr;
4680 data32 = bus_read_4(((qlnx_host_t *)cdev)->pci_reg, reg_addr);
4686 qlnx_reg_wr32(void *hwfn, uint32_t reg_addr, uint32_t value)
4688 struct ecore_dev *cdev;
4689 struct ecore_hwfn *p_hwfn;
4693 cdev = p_hwfn->p_dev;
4695 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->regview) -
4696 (uint8_t *)(cdev->regview)) + reg_addr;
4698 bus_write_4(((qlnx_host_t *)cdev)->pci_reg, reg_addr, value);
4704 qlnx_reg_wr16(void *hwfn, uint32_t reg_addr, uint16_t value)
4706 struct ecore_dev *cdev;
4707 struct ecore_hwfn *p_hwfn;
4711 cdev = p_hwfn->p_dev;
4713 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->regview) -
4714 (uint8_t *)(cdev->regview)) + reg_addr;
4716 bus_write_2(((qlnx_host_t *)cdev)->pci_reg, reg_addr, value);
4722 qlnx_dbell_wr32(void *hwfn, uint32_t reg_addr, uint32_t value)
4724 struct ecore_dev *cdev;
4725 struct ecore_hwfn *p_hwfn;
4729 cdev = p_hwfn->p_dev;
4731 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->doorbells) -
4732 (uint8_t *)(cdev->doorbells)) + reg_addr;
4734 bus_write_4(((qlnx_host_t *)cdev)->pci_dbells, reg_addr, value);
4740 qlnx_direct_reg_rd32(void *p_hwfn, uint32_t *reg_addr)
4744 struct ecore_dev *cdev;
4746 cdev = ((struct ecore_hwfn *)p_hwfn)->p_dev;
4747 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)(cdev->regview));
4749 data32 = bus_read_4(((qlnx_host_t *)cdev)->pci_reg, offset);
4755 qlnx_direct_reg_wr32(void *p_hwfn, void *reg_addr, uint32_t value)
4758 struct ecore_dev *cdev;
4760 cdev = ((struct ecore_hwfn *)p_hwfn)->p_dev;
4761 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)(cdev->regview));
4763 bus_write_4(((qlnx_host_t *)cdev)->pci_reg, offset, value);
4769 qlnx_zalloc(uint32_t size)
4773 va = malloc((unsigned long)size, M_QLNXBUF, M_NOWAIT);
4775 return ((void *)va);
4779 qlnx_barrier(void *p_hwfn)
4783 ha = (qlnx_host_t *)((struct ecore_hwfn *)p_hwfn)->p_dev;
4784 bus_barrier(ha->pci_reg, 0, 0, BUS_SPACE_BARRIER_WRITE);
4788 qlnx_link_update(void *p_hwfn)
4791 int prev_link_state;
4793 ha = (qlnx_host_t *)((struct ecore_hwfn *)p_hwfn)->p_dev;
4795 qlnx_fill_link(p_hwfn, &ha->if_link);
4797 prev_link_state = ha->link_up;
4798 ha->link_up = ha->if_link.link_up;
4800 if (prev_link_state != ha->link_up) {
4802 if_link_state_change(ha->ifp, LINK_STATE_UP);
4804 if_link_state_change(ha->ifp, LINK_STATE_DOWN);
4811 qlnx_fill_link(struct ecore_hwfn *hwfn, struct qlnx_link_output *if_link)
4813 struct ecore_mcp_link_params link_params;
4814 struct ecore_mcp_link_state link_state;
4816 memset(if_link, 0, sizeof(*if_link));
4817 memset(&link_params, 0, sizeof(struct ecore_mcp_link_params));
4818 memset(&link_state, 0, sizeof(struct ecore_mcp_link_state));
4820 /* Prepare source inputs */
4821 /* we only deal with physical functions */
4822 memcpy(&link_params, ecore_mcp_get_link_params(hwfn),
4823 sizeof(link_params));
4824 memcpy(&link_state, ecore_mcp_get_link_state(hwfn),
4825 sizeof(link_state));
4827 ecore_mcp_get_media_type(hwfn->p_dev, &if_link->media_type);
4829 /* Set the link parameters to pass to protocol driver */
4830 if (link_state.link_up) {
4831 if_link->link_up = true;
4832 if_link->speed = link_state.speed;
4835 if_link->supported_caps = QLNX_LINK_CAP_FIBRE;
4837 if (link_params.speed.autoneg)
4838 if_link->supported_caps |= QLNX_LINK_CAP_Autoneg;
4840 if (link_params.pause.autoneg ||
4841 (link_params.pause.forced_rx && link_params.pause.forced_tx))
4842 if_link->supported_caps |= QLNX_LINK_CAP_Asym_Pause;
4844 if (link_params.pause.autoneg || link_params.pause.forced_rx ||
4845 link_params.pause.forced_tx)
4846 if_link->supported_caps |= QLNX_LINK_CAP_Pause;
4848 if (link_params.speed.advertised_speeds &
4849 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
4850 if_link->supported_caps |= QLNX_LINK_CAP_1000baseT_Half |
4851 QLNX_LINK_CAP_1000baseT_Full;
4853 if (link_params.speed.advertised_speeds &
4854 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
4855 if_link->supported_caps |= QLNX_LINK_CAP_10000baseKR_Full;
4857 if (link_params.speed.advertised_speeds &
4858 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
4859 if_link->supported_caps |= QLNX_LINK_CAP_25000baseKR_Full;
4861 if (link_params.speed.advertised_speeds &
4862 NVM_CFG1_PORT_DRV_LINK_SPEED_40G)
4863 if_link->supported_caps |= QLNX_LINK_CAP_40000baseLR4_Full;
4865 if (link_params.speed.advertised_speeds &
4866 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
4867 if_link->supported_caps |= QLNX_LINK_CAP_50000baseKR2_Full;
4869 if (link_params.speed.advertised_speeds &
4870 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
4871 if_link->supported_caps |= QLNX_LINK_CAP_100000baseKR4_Full;
4873 if_link->advertised_caps = if_link->supported_caps;
4875 if_link->autoneg = link_params.speed.autoneg;
4876 if_link->duplex = QLNX_LINK_DUPLEX;
4878 /* Link partner capabilities */
4880 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_1G_HD)
4881 if_link->link_partner_caps |= QLNX_LINK_CAP_1000baseT_Half;
4883 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_1G_FD)
4884 if_link->link_partner_caps |= QLNX_LINK_CAP_1000baseT_Full;
4886 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_10G)
4887 if_link->link_partner_caps |= QLNX_LINK_CAP_10000baseKR_Full;
4889 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_25G)
4890 if_link->link_partner_caps |= QLNX_LINK_CAP_25000baseKR_Full;
4892 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_40G)
4893 if_link->link_partner_caps |= QLNX_LINK_CAP_40000baseLR4_Full;
4895 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_50G)
4896 if_link->link_partner_caps |= QLNX_LINK_CAP_50000baseKR2_Full;
4898 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_100G)
4899 if_link->link_partner_caps |= QLNX_LINK_CAP_100000baseKR4_Full;
4901 if (link_state.an_complete)
4902 if_link->link_partner_caps |= QLNX_LINK_CAP_Autoneg;
4904 if (link_state.partner_adv_pause)
4905 if_link->link_partner_caps |= QLNX_LINK_CAP_Pause;
4907 if ((link_state.partner_adv_pause ==
4908 ECORE_LINK_PARTNER_ASYMMETRIC_PAUSE) ||
4909 (link_state.partner_adv_pause ==
4910 ECORE_LINK_PARTNER_BOTH_PAUSE))
4911 if_link->link_partner_caps |= QLNX_LINK_CAP_Asym_Pause;
4917 qlnx_nic_setup(struct ecore_dev *cdev, struct ecore_pf_params *func_params)
4921 for (i = 0; i < cdev->num_hwfns; i++) {
4922 struct ecore_hwfn *p_hwfn = &cdev->hwfns[i];
4923 p_hwfn->pf_params = *func_params;
4926 rc = ecore_resc_alloc(cdev);
4928 goto qlnx_nic_setup_exit;
4930 ecore_resc_setup(cdev);
4932 qlnx_nic_setup_exit:
4938 qlnx_nic_start(struct ecore_dev *cdev)
4941 struct ecore_hw_init_params params;
4943 bzero(¶ms, sizeof (struct ecore_hw_init_params));
4945 params.p_tunn = NULL;
4946 params.b_hw_start = true;
4947 params.int_mode = cdev->int_mode;
4948 params.allow_npar_tx_switch = true;
4949 params.bin_fw_data = NULL;
4951 rc = ecore_hw_init(cdev, ¶ms);
4953 ecore_resc_free(cdev);
4961 qlnx_slowpath_start(qlnx_host_t *ha)
4963 struct ecore_dev *cdev;
4964 struct ecore_pf_params pf_params;
4967 memset(&pf_params, 0, sizeof(struct ecore_pf_params));
4968 pf_params.eth_pf_params.num_cons =
4969 (ha->num_rss) * (ha->num_tc + 1);
4973 rc = qlnx_nic_setup(cdev, &pf_params);
4975 goto qlnx_slowpath_start_exit;
4977 cdev->int_mode = ECORE_INT_MODE_MSIX;
4978 cdev->int_coalescing_mode = ECORE_COAL_MODE_ENABLE;
4980 #ifdef QLNX_MAX_COALESCE
4981 cdev->rx_coalesce_usecs = 255;
4982 cdev->tx_coalesce_usecs = 255;
4985 rc = qlnx_nic_start(cdev);
4987 ha->rx_coalesce_usecs = cdev->rx_coalesce_usecs;
4988 ha->tx_coalesce_usecs = cdev->tx_coalesce_usecs;
4990 qlnx_slowpath_start_exit:
4996 qlnx_slowpath_stop(qlnx_host_t *ha)
4998 struct ecore_dev *cdev;
4999 device_t dev = ha->pci_dev;
5004 ecore_hw_stop(cdev);
5006 for (i = 0; i < ha->cdev.num_hwfns; i++) {
5008 if (ha->sp_handle[i])
5009 (void)bus_teardown_intr(dev, ha->sp_irq[i],
5012 ha->sp_handle[i] = NULL;
5015 (void) bus_release_resource(dev, SYS_RES_IRQ,
5016 ha->sp_irq_rid[i], ha->sp_irq[i]);
5017 ha->sp_irq[i] = NULL;
5020 ecore_resc_free(cdev);
5026 qlnx_set_id(struct ecore_dev *cdev, char name[NAME_SIZE],
5027 char ver_str[VER_SIZE])
5031 memcpy(cdev->name, name, NAME_SIZE);
5033 for_each_hwfn(cdev, i) {
5034 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
5037 cdev->drv_type = DRV_ID_DRV_TYPE_FREEBSD;
5043 qlnx_get_protocol_stats(void *cdev, int proto_type, void *proto_stats)
5045 enum ecore_mcp_protocol_type type;
5046 union ecore_mcp_protocol_stats *stats;
5047 struct ecore_eth_stats eth_stats;
5050 dev = ((qlnx_host_t *)cdev)->pci_dev;
5051 stats = proto_stats;
5055 case ECORE_MCP_LAN_STATS:
5056 ecore_get_vport_stats((struct ecore_dev *)cdev, ð_stats);
5057 stats->lan_stats.ucast_rx_pkts = eth_stats.common.rx_ucast_pkts;
5058 stats->lan_stats.ucast_tx_pkts = eth_stats.common.tx_ucast_pkts;
5059 stats->lan_stats.fcs_err = -1;
5063 ((qlnx_host_t *)cdev)->err_get_proto_invalid_type++;
5065 QL_DPRINT1(((qlnx_host_t *)cdev),
5066 (dev, "%s: invalid protocol type 0x%x\n", __func__,
5074 qlnx_get_mfw_version(qlnx_host_t *ha, uint32_t *mfw_ver)
5076 struct ecore_hwfn *p_hwfn;
5077 struct ecore_ptt *p_ptt;
5079 p_hwfn = &ha->cdev.hwfns[0];
5080 p_ptt = ecore_ptt_acquire(p_hwfn);
5082 if (p_ptt == NULL) {
5083 QL_DPRINT1(ha, (ha->pci_dev,
5084 "%s : ecore_ptt_acquire failed\n", __func__));
5087 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, mfw_ver, NULL);
5089 ecore_ptt_release(p_hwfn, p_ptt);
5095 qlnx_get_flash_size(qlnx_host_t *ha, uint32_t *flash_size)
5097 struct ecore_hwfn *p_hwfn;
5098 struct ecore_ptt *p_ptt;
5100 p_hwfn = &ha->cdev.hwfns[0];
5101 p_ptt = ecore_ptt_acquire(p_hwfn);
5103 if (p_ptt == NULL) {
5104 QL_DPRINT1(ha, (ha->pci_dev,
5105 "%s : ecore_ptt_acquire failed\n", __func__));
5108 ecore_mcp_get_flash_size(p_hwfn, p_ptt, flash_size);
5110 ecore_ptt_release(p_hwfn, p_ptt);
5116 qlnx_alloc_mem_arrays(qlnx_host_t *ha)
5118 struct ecore_dev *cdev;
5122 bzero(&ha->txq_array[0], (sizeof(struct qlnx_tx_queue) * QLNX_MAX_RSS));
5123 bzero(&ha->rxq_array[0], (sizeof(struct qlnx_rx_queue) * QLNX_MAX_RSS));
5124 bzero(&ha->sb_array[0], (sizeof(struct ecore_sb_info) * QLNX_MAX_RSS));
5130 qlnx_init_fp(qlnx_host_t *ha)
5132 int rss_id, txq_array_index, tc;
5134 for (rss_id = 0; rss_id < ha->num_rss; rss_id++) {
5136 struct qlnx_fastpath *fp = &ha->fp_array[rss_id];
5138 fp->rss_id = rss_id;
5140 fp->sb_info = &ha->sb_array[rss_id];
5141 fp->rxq = &ha->rxq_array[rss_id];
5142 fp->rxq->rxq_id = rss_id;
5144 for (tc = 0; tc < ha->num_tc; tc++) {
5145 txq_array_index = tc * ha->num_rss + rss_id;
5146 fp->txq[tc] = &ha->txq_array[txq_array_index];
5147 fp->txq[tc]->index = txq_array_index;
5150 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d", qlnx_name_str,
5153 /* reset all the statistics counters */
5155 fp->tx_pkts_processed = 0;
5156 fp->tx_pkts_freed = 0;
5157 fp->tx_pkts_transmitted = 0;
5158 fp->tx_pkts_completed = 0;
5159 fp->tx_lso_wnd_min_len = 0;
5161 fp->tx_nsegs_gt_elem_left = 0;
5162 fp->tx_tso_max_nsegs = 0;
5163 fp->tx_tso_min_nsegs = 0;
5164 fp->err_tx_nsegs_gt_elem_left = 0;
5165 fp->err_tx_dmamap_create = 0;
5166 fp->err_tx_defrag_dmamap_load = 0;
5167 fp->err_tx_non_tso_max_seg = 0;
5168 fp->err_tx_dmamap_load = 0;
5169 fp->err_tx_defrag = 0;
5170 fp->err_tx_free_pkt_null = 0;
5171 fp->err_tx_cons_idx_conflict = 0;
5174 fp->err_m_getcl = 0;
5175 fp->err_m_getjcl = 0;
5181 qlnx_free_mem_sb(qlnx_host_t *ha, struct ecore_sb_info *sb_info)
5183 struct ecore_dev *cdev;
5187 if (sb_info->sb_virt) {
5188 OSAL_DMA_FREE_COHERENT(cdev, ((void *)sb_info->sb_virt),
5189 (sb_info->sb_phys), (sizeof(*sb_info->sb_virt)));
5190 sb_info->sb_virt = NULL;
5195 qlnx_sb_init(struct ecore_dev *cdev, struct ecore_sb_info *sb_info,
5196 void *sb_virt_addr, bus_addr_t sb_phy_addr, u16 sb_id)
5198 struct ecore_hwfn *p_hwfn;
5202 hwfn_index = sb_id % cdev->num_hwfns;
5203 p_hwfn = &cdev->hwfns[hwfn_index];
5204 rel_sb_id = sb_id / cdev->num_hwfns;
5206 QL_DPRINT2(((qlnx_host_t *)cdev), (((qlnx_host_t *)cdev)->pci_dev,
5207 "%s: hwfn_index = %d p_hwfn = %p sb_id = 0x%x rel_sb_id = 0x%x "
5208 "sb_info = %p sb_virt_addr = %p sb_phy_addr = %p\n",
5209 __func__, hwfn_index, p_hwfn, sb_id, rel_sb_id, sb_info,
5210 sb_virt_addr, (void *)sb_phy_addr));
5212 rc = ecore_int_sb_init(p_hwfn, p_hwfn->p_main_ptt, sb_info,
5213 sb_virt_addr, sb_phy_addr, rel_sb_id);
5218 /* This function allocates fast-path status block memory */
5220 qlnx_alloc_mem_sb(qlnx_host_t *ha, struct ecore_sb_info *sb_info, u16 sb_id)
5222 struct status_block *sb_virt;
5226 struct ecore_dev *cdev;
5230 size = sizeof(*sb_virt);
5231 sb_virt = OSAL_DMA_ALLOC_COHERENT(cdev, (&sb_phys), size);
5234 QL_DPRINT1(ha, (ha->pci_dev,
5235 "%s: Status block allocation failed\n", __func__));
5239 rc = qlnx_sb_init(cdev, sb_info, sb_virt, sb_phys, sb_id);
5241 QL_DPRINT1(ha, (ha->pci_dev, "%s: failed\n", __func__));
5242 OSAL_DMA_FREE_COHERENT(cdev, sb_virt, sb_phys, size);
5249 qlnx_free_rx_buffers(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5252 struct sw_rx_data *rx_buf;
5254 for (i = 0; i < rxq->num_rx_buffers; i++) {
5256 rx_buf = &rxq->sw_rx_ring[i];
5258 if (rx_buf->data != NULL) {
5259 if (rx_buf->map != NULL) {
5260 bus_dmamap_unload(ha->rx_tag, rx_buf->map);
5261 bus_dmamap_destroy(ha->rx_tag, rx_buf->map);
5264 m_freem(rx_buf->data);
5265 rx_buf->data = NULL;
5272 qlnx_free_mem_rxq(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5274 struct ecore_dev *cdev;
5279 qlnx_free_rx_buffers(ha, rxq);
5281 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
5282 qlnx_free_tpa_mbuf(ha, &rxq->tpa_info[i]);
5283 if (rxq->tpa_info[i].mpf != NULL)
5284 m_freem(rxq->tpa_info[i].mpf);
5287 bzero((void *)&rxq->sw_rx_ring[0],
5288 (sizeof (struct sw_rx_data) * RX_RING_SIZE));
5290 /* Free the real RQ ring used by FW */
5291 if (rxq->rx_bd_ring.p_virt_addr) {
5292 ecore_chain_free(cdev, &rxq->rx_bd_ring);
5293 rxq->rx_bd_ring.p_virt_addr = NULL;
5296 /* Free the real completion ring used by FW */
5297 if (rxq->rx_comp_ring.p_virt_addr &&
5298 rxq->rx_comp_ring.pbl_sp.p_virt_table) {
5299 ecore_chain_free(cdev, &rxq->rx_comp_ring);
5300 rxq->rx_comp_ring.p_virt_addr = NULL;
5301 rxq->rx_comp_ring.pbl_sp.p_virt_table = NULL;
5304 #ifdef QLNX_SOFT_LRO
5306 struct lro_ctrl *lro;
5311 #endif /* #ifdef QLNX_SOFT_LRO */
5317 qlnx_alloc_rx_buffer(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5319 register struct mbuf *mp;
5320 uint16_t rx_buf_size;
5321 struct sw_rx_data *sw_rx_data;
5322 struct eth_rx_bd *rx_bd;
5323 dma_addr_t dma_addr;
5325 bus_dma_segment_t segs[1];
5328 struct ecore_dev *cdev;
5332 rx_buf_size = rxq->rx_buf_size;
5334 mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, rx_buf_size);
5337 QL_DPRINT1(ha, (ha->pci_dev,
5338 "%s : Failed to allocate Rx data\n", __func__));
5342 mp->m_len = mp->m_pkthdr.len = rx_buf_size;
5344 map = (bus_dmamap_t)0;
5346 ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, map, mp, segs, &nsegs,
5348 dma_addr = segs[0].ds_addr;
5350 if (ret || !dma_addr || (nsegs != 1)) {
5352 QL_DPRINT1(ha, (ha->pci_dev,
5353 "%s: bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
5354 __func__, ret, (long long unsigned int)dma_addr,
5359 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_prod];
5360 sw_rx_data->data = mp;
5361 sw_rx_data->dma_addr = dma_addr;
5362 sw_rx_data->map = map;
5364 /* Advance PROD and get BD pointer */
5365 rx_bd = (struct eth_rx_bd *)ecore_chain_produce(&rxq->rx_bd_ring);
5366 rx_bd->addr.hi = htole32(U64_HI(dma_addr));
5367 rx_bd->addr.lo = htole32(U64_LO(dma_addr));
5368 bus_dmamap_sync(ha->rx_tag, map, BUS_DMASYNC_PREREAD);
5370 rxq->sw_rx_prod = (rxq->sw_rx_prod + 1) & (RX_RING_SIZE - 1);
5376 qlnx_alloc_tpa_mbuf(qlnx_host_t *ha, uint16_t rx_buf_size,
5377 struct qlnx_agg_info *tpa)
5380 dma_addr_t dma_addr;
5382 bus_dma_segment_t segs[1];
5385 struct sw_rx_data *rx_buf;
5387 mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, rx_buf_size);
5390 QL_DPRINT1(ha, (ha->pci_dev,
5391 "%s : Failed to allocate Rx data\n", __func__));
5395 mp->m_len = mp->m_pkthdr.len = rx_buf_size;
5397 map = (bus_dmamap_t)0;
5399 ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, map, mp, segs, &nsegs,
5401 dma_addr = segs[0].ds_addr;
5403 if (ret || !dma_addr || (nsegs != 1)) {
5405 QL_DPRINT1(ha, (ha->pci_dev,
5406 "%s: bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
5407 __func__, ret, (long long unsigned int)dma_addr,
5412 rx_buf = &tpa->rx_buf;
5414 memset(rx_buf, 0, sizeof (struct sw_rx_data));
5417 rx_buf->dma_addr = dma_addr;
5420 bus_dmamap_sync(ha->rx_tag, map, BUS_DMASYNC_PREREAD);
5426 qlnx_free_tpa_mbuf(qlnx_host_t *ha, struct qlnx_agg_info *tpa)
5428 struct sw_rx_data *rx_buf;
5430 rx_buf = &tpa->rx_buf;
5432 if (rx_buf->data != NULL) {
5433 if (rx_buf->map != NULL) {
5434 bus_dmamap_unload(ha->rx_tag, rx_buf->map);
5435 bus_dmamap_destroy(ha->rx_tag, rx_buf->map);
5438 m_freem(rx_buf->data);
5439 rx_buf->data = NULL;
5444 /* This function allocates all memory needed per Rx queue */
5446 qlnx_alloc_mem_rxq(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5448 int i, rc, num_allocated;
5450 struct ecore_dev *cdev;
5455 rxq->num_rx_buffers = RX_RING_SIZE;
5457 rxq->rx_buf_size = ha->rx_buf_size;
5459 /* Allocate the parallel driver ring for Rx buffers */
5460 bzero((void *)&rxq->sw_rx_ring[0],
5461 (sizeof (struct sw_rx_data) * RX_RING_SIZE));
5463 /* Allocate FW Rx ring */
5465 rc = ecore_chain_alloc(cdev,
5466 ECORE_CHAIN_USE_TO_CONSUME_PRODUCE,
5467 ECORE_CHAIN_MODE_NEXT_PTR,
5468 ECORE_CHAIN_CNT_TYPE_U16,
5470 sizeof(struct eth_rx_bd),
5471 &rxq->rx_bd_ring, NULL);
5476 /* Allocate FW completion ring */
5477 rc = ecore_chain_alloc(cdev,
5478 ECORE_CHAIN_USE_TO_CONSUME,
5479 ECORE_CHAIN_MODE_PBL,
5480 ECORE_CHAIN_CNT_TYPE_U16,
5482 sizeof(union eth_rx_cqe),
5483 &rxq->rx_comp_ring, NULL);
5488 /* Allocate buffers for the Rx ring */
5490 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
5491 rc = qlnx_alloc_tpa_mbuf(ha, rxq->rx_buf_size,
5498 for (i = 0; i < rxq->num_rx_buffers; i++) {
5499 rc = qlnx_alloc_rx_buffer(ha, rxq);
5504 if (!num_allocated) {
5505 QL_DPRINT1(ha, (ha->pci_dev,
5506 "%s: Rx buffers allocation failed\n", __func__));
5508 } else if (num_allocated < rxq->num_rx_buffers) {
5509 QL_DPRINT1(ha, (ha->pci_dev,
5510 "%s: Allocated less buffers than"
5511 " desired (%d allocated)\n", __func__, num_allocated));
5514 #ifdef QLNX_SOFT_LRO
5517 struct lro_ctrl *lro;
5521 #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
5522 if (tcp_lro_init_args(lro, ifp, 0, rxq->num_rx_buffers)) {
5523 QL_DPRINT1(ha, (ha->pci_dev,
5524 "%s: tcp_lro_init[%d] failed\n",
5525 __func__, rxq->rxq_id));
5529 if (tcp_lro_init(lro)) {
5530 QL_DPRINT1(ha, (ha->pci_dev,
5531 "%s: tcp_lro_init[%d] failed\n",
5532 __func__, rxq->rxq_id));
5535 #endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
5539 #endif /* #ifdef QLNX_SOFT_LRO */
5543 qlnx_free_mem_rxq(ha, rxq);
5549 qlnx_free_mem_txq(qlnx_host_t *ha, struct qlnx_fastpath *fp,
5550 struct qlnx_tx_queue *txq)
5552 struct ecore_dev *cdev;
5556 bzero((void *)&txq->sw_tx_ring[0],
5557 (sizeof (struct sw_tx_bd) * TX_RING_SIZE));
5559 /* Free the real RQ ring used by FW */
5560 if (txq->tx_pbl.p_virt_addr) {
5561 ecore_chain_free(cdev, &txq->tx_pbl);
5562 txq->tx_pbl.p_virt_addr = NULL;
5567 /* This function allocates all memory needed per Tx queue */
5569 qlnx_alloc_mem_txq(qlnx_host_t *ha, struct qlnx_fastpath *fp,
5570 struct qlnx_tx_queue *txq)
5572 int ret = ECORE_SUCCESS;
5573 union eth_tx_bd_types *p_virt;
5574 struct ecore_dev *cdev;
5578 bzero((void *)&txq->sw_tx_ring[0],
5579 (sizeof (struct sw_tx_bd) * TX_RING_SIZE));
5581 /* Allocate the real Tx ring to be used by FW */
5582 ret = ecore_chain_alloc(cdev,
5583 ECORE_CHAIN_USE_TO_CONSUME_PRODUCE,
5584 ECORE_CHAIN_MODE_PBL,
5585 ECORE_CHAIN_CNT_TYPE_U16,
5588 &txq->tx_pbl, NULL);
5590 if (ret != ECORE_SUCCESS) {
5594 txq->num_tx_buffers = TX_RING_SIZE;
5599 qlnx_free_mem_txq(ha, fp, txq);
5604 qlnx_free_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5607 struct ifnet *ifp = ha->ifp;
5609 if (mtx_initialized(&fp->tx_mtx)) {
5611 if (fp->tx_br != NULL) {
5613 mtx_lock(&fp->tx_mtx);
5615 while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) {
5616 fp->tx_pkts_freed++;
5620 mtx_unlock(&fp->tx_mtx);
5622 buf_ring_free(fp->tx_br, M_DEVBUF);
5625 mtx_destroy(&fp->tx_mtx);
5631 qlnx_free_mem_fp(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5635 qlnx_free_mem_sb(ha, fp->sb_info);
5637 qlnx_free_mem_rxq(ha, fp->rxq);
5639 for (tc = 0; tc < ha->num_tc; tc++)
5640 qlnx_free_mem_txq(ha, fp, fp->txq[tc]);
5646 qlnx_alloc_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5648 snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
5649 "qlnx%d_fp%d_tx_mq_lock", ha->dev_unit, fp->rss_id);
5651 mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
5653 fp->tx_br = buf_ring_alloc(TX_RING_SIZE, M_DEVBUF,
5654 M_NOWAIT, &fp->tx_mtx);
5655 if (fp->tx_br == NULL) {
5656 QL_DPRINT1(ha, (ha->pci_dev, "buf_ring_alloc failed for "
5657 " fp[%d, %d]\n", ha->dev_unit, fp->rss_id));
5664 qlnx_alloc_mem_fp(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5668 rc = qlnx_alloc_mem_sb(ha, fp->sb_info, fp->rss_id);
5672 if (ha->rx_jumbo_buf_eq_mtu) {
5673 if (ha->max_frame_size <= MCLBYTES)
5674 ha->rx_buf_size = MCLBYTES;
5675 else if (ha->max_frame_size <= MJUMPAGESIZE)
5676 ha->rx_buf_size = MJUMPAGESIZE;
5677 else if (ha->max_frame_size <= MJUM9BYTES)
5678 ha->rx_buf_size = MJUM9BYTES;
5679 else if (ha->max_frame_size <= MJUM16BYTES)
5680 ha->rx_buf_size = MJUM16BYTES;
5682 if (ha->max_frame_size <= MCLBYTES)
5683 ha->rx_buf_size = MCLBYTES;
5685 ha->rx_buf_size = MJUMPAGESIZE;
5688 rc = qlnx_alloc_mem_rxq(ha, fp->rxq);
5692 for (tc = 0; tc < ha->num_tc; tc++) {
5693 rc = qlnx_alloc_mem_txq(ha, fp, fp->txq[tc]);
5701 qlnx_free_mem_fp(ha, fp);
5706 qlnx_free_mem_load(qlnx_host_t *ha)
5709 struct ecore_dev *cdev;
5713 for (i = 0; i < ha->num_rss; i++) {
5714 struct qlnx_fastpath *fp = &ha->fp_array[i];
5716 qlnx_free_mem_fp(ha, fp);
5722 qlnx_alloc_mem_load(qlnx_host_t *ha)
5726 for (rss_id = 0; rss_id < ha->num_rss; rss_id++) {
5727 struct qlnx_fastpath *fp = &ha->fp_array[rss_id];
5729 rc = qlnx_alloc_mem_fp(ha, fp);
5737 qlnx_start_vport(struct ecore_dev *cdev,
5741 u8 inner_vlan_removal_en_flg,
5746 struct ecore_sp_vport_start_params vport_start_params = { 0 };
5749 ha = (qlnx_host_t *)cdev;
5751 vport_start_params.remove_inner_vlan = inner_vlan_removal_en_flg;
5752 vport_start_params.tx_switching = 0;
5753 vport_start_params.handle_ptp_pkts = 0;
5754 vport_start_params.only_untagged = 0;
5755 vport_start_params.drop_ttl0 = drop_ttl0_flg;
5757 vport_start_params.tpa_mode =
5758 (hw_lro_enable ? ECORE_TPA_MODE_RSC : ECORE_TPA_MODE_NONE);
5759 vport_start_params.max_buffers_per_cqe = QLNX_TPA_MAX_AGG_BUFFERS;
5761 vport_start_params.vport_id = vport_id;
5762 vport_start_params.mtu = mtu;
5765 QL_DPRINT2(ha, (ha->pci_dev, "%s: setting mtu to %d\n", __func__, mtu));
5767 for_each_hwfn(cdev, i) {
5768 struct ecore_hwfn *p_hwfn = &cdev->hwfns[i];
5770 vport_start_params.concrete_fid = p_hwfn->hw_info.concrete_fid;
5771 vport_start_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
5773 rc = ecore_sp_vport_start(p_hwfn, &vport_start_params);
5776 QL_DPRINT1(ha, (ha->pci_dev,
5777 "%s: Failed to start VPORT V-PORT %d "
5778 "with MTU %d\n", __func__, vport_id, mtu));
5782 ecore_hw_start_fastpath(p_hwfn);
5784 QL_DPRINT2(ha, (ha->pci_dev,
5785 "%s: Started V-PORT %d with MTU %d\n",
5786 __func__, vport_id, mtu));
5793 qlnx_update_vport(struct ecore_dev *cdev,
5794 struct qlnx_update_vport_params *params)
5796 struct ecore_sp_vport_update_params sp_params;
5797 int rc, i, j, fp_index;
5798 struct ecore_hwfn *p_hwfn;
5799 struct ecore_rss_params *rss;
5800 qlnx_host_t *ha = (qlnx_host_t *)cdev;
5801 struct qlnx_fastpath *fp;
5803 memset(&sp_params, 0, sizeof(sp_params));
5804 /* Translate protocol params into sp params */
5805 sp_params.vport_id = params->vport_id;
5807 sp_params.update_vport_active_rx_flg =
5808 params->update_vport_active_rx_flg;
5809 sp_params.vport_active_rx_flg = params->vport_active_rx_flg;
5811 sp_params.update_vport_active_tx_flg =
5812 params->update_vport_active_tx_flg;
5813 sp_params.vport_active_tx_flg = params->vport_active_tx_flg;
5815 sp_params.update_inner_vlan_removal_flg =
5816 params->update_inner_vlan_removal_flg;
5817 sp_params.inner_vlan_removal_flg = params->inner_vlan_removal_flg;
5819 sp_params.sge_tpa_params = params->sge_tpa_params;
5821 /* RSS - is a bit tricky, since upper-layer isn't familiar with hwfns.
5822 * We need to re-fix the rss values per engine for CMT.
5825 sp_params.rss_params = params->rss_params;
5827 for_each_hwfn(cdev, i) {
5829 p_hwfn = &cdev->hwfns[i];
5831 if ((cdev->num_hwfns > 1) &&
5832 params->rss_params->update_rss_config &&
5833 params->rss_params->rss_enable) {
5835 rss = params->rss_params;
5837 for (j = 0; j < ECORE_RSS_IND_TABLE_SIZE; j++) {
5839 fp_index = ((cdev->num_hwfns * j) + i) %
5842 fp = &ha->fp_array[fp_index];
5843 rss->rss_ind_table[j] = fp->rxq->handle;
5846 for (j = 0; j < ECORE_RSS_IND_TABLE_SIZE;) {
5847 QL_DPRINT3(ha, (ha->pci_dev,
5848 "%p %p %p %p %p %p %p %p \n",
5849 rss->rss_ind_table[j],
5850 rss->rss_ind_table[j+1],
5851 rss->rss_ind_table[j+2],
5852 rss->rss_ind_table[j+3],
5853 rss->rss_ind_table[j+4],
5854 rss->rss_ind_table[j+5],
5855 rss->rss_ind_table[j+6],
5856 rss->rss_ind_table[j+7]));
5861 sp_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
5862 rc = ecore_sp_vport_update(p_hwfn, &sp_params,
5863 ECORE_SPQ_MODE_EBLOCK, NULL);
5865 QL_DPRINT1(ha, (ha->pci_dev,
5866 "%s:Failed to update VPORT\n", __func__));
5870 QL_DPRINT2(ha, (ha->pci_dev,
5871 "%s: Updated V-PORT %d: tx_active_flag %d,"
5872 "rx_active_flag %d [tx_update %d], [rx_update %d]\n",
5874 params->vport_id, params->vport_active_tx_flg,
5875 params->vport_active_rx_flg,
5876 params->update_vport_active_tx_flg,
5877 params->update_vport_active_rx_flg));
5884 qlnx_reuse_rx_data(struct qlnx_rx_queue *rxq)
5886 struct eth_rx_bd *rx_bd_cons =
5887 ecore_chain_consume(&rxq->rx_bd_ring);
5888 struct eth_rx_bd *rx_bd_prod =
5889 ecore_chain_produce(&rxq->rx_bd_ring);
5890 struct sw_rx_data *sw_rx_data_cons =
5891 &rxq->sw_rx_ring[rxq->sw_rx_cons];
5892 struct sw_rx_data *sw_rx_data_prod =
5893 &rxq->sw_rx_ring[rxq->sw_rx_prod];
5895 sw_rx_data_prod->data = sw_rx_data_cons->data;
5896 memcpy(rx_bd_prod, rx_bd_cons, sizeof(struct eth_rx_bd));
5898 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
5899 rxq->sw_rx_prod = (rxq->sw_rx_prod + 1) & (RX_RING_SIZE - 1);
5905 qlnx_update_rx_prod(struct ecore_hwfn *p_hwfn, struct qlnx_rx_queue *rxq)
5911 struct eth_rx_prod_data rx_prod_data;
5915 bd_prod = ecore_chain_get_prod_idx(&rxq->rx_bd_ring);
5916 cqe_prod = ecore_chain_get_prod_idx(&rxq->rx_comp_ring);
5918 /* Update producers */
5919 rx_prods.rx_prod_data.bd_prod = htole16(bd_prod);
5920 rx_prods.rx_prod_data.cqe_prod = htole16(cqe_prod);
5922 /* Make sure that the BD and SGE data is updated before updating the
5923 * producers since FW might read the BD/SGE right after the producer
5928 internal_ram_wr(p_hwfn, rxq->hw_rxq_prod_addr,
5929 sizeof(rx_prods), &rx_prods.data32);
5931 /* mmiowb is needed to synchronize doorbell writes from more than one
5932 * processor. It guarantees that the write arrives to the device before
5933 * the napi lock is released and another qlnx_poll is called (possibly
5934 * on another CPU). Without this barrier, the next doorbell can bypass
5935 * this doorbell. This is applicable to IA64/Altix systems.
5942 static uint32_t qlnx_hash_key[] = {
5943 ((0x6d << 24)|(0x5a << 16)|(0x56 << 8)|0xda),
5944 ((0x25 << 24)|(0x5b << 16)|(0x0e << 8)|0xc2),
5945 ((0x41 << 24)|(0x67 << 16)|(0x25 << 8)|0x3d),
5946 ((0x43 << 24)|(0xa3 << 16)|(0x8f << 8)|0xb0),
5947 ((0xd0 << 24)|(0xca << 16)|(0x2b << 8)|0xcb),
5948 ((0xae << 24)|(0x7b << 16)|(0x30 << 8)|0xb4),
5949 ((0x77 << 24)|(0xcb << 16)|(0x2d << 8)|0xa3),
5950 ((0x80 << 24)|(0x30 << 16)|(0xf2 << 8)|0x0c),
5951 ((0x6a << 24)|(0x42 << 16)|(0xb7 << 8)|0x3b),
5952 ((0xbe << 24)|(0xac << 16)|(0x01 << 8)|0xfa)};
5955 qlnx_start_queues(qlnx_host_t *ha)
5957 int rc, tc, i, vport_id = 0,
5958 drop_ttl0_flg = 1, vlan_removal_en = 1,
5959 tx_switching = 0, hw_lro_enable = 0;
5960 struct ecore_dev *cdev = &ha->cdev;
5961 struct ecore_rss_params *rss_params = &ha->rss_params;
5962 struct qlnx_update_vport_params vport_update_params;
5964 struct ecore_hwfn *p_hwfn;
5965 struct ecore_sge_tpa_params tpa_params;
5966 struct ecore_queue_start_common_params qparams;
5967 struct qlnx_fastpath *fp;
5972 QL_DPRINT1(ha, (ha->pci_dev,
5973 "%s: Cannot update V-VPORT as active as there"
5974 " are no Rx queues\n", __func__));
5978 #ifndef QLNX_SOFT_LRO
5979 hw_lro_enable = ifp->if_capenable & IFCAP_LRO;
5980 #endif /* #ifndef QLNX_SOFT_LRO */
5982 rc = qlnx_start_vport(cdev, vport_id, ifp->if_mtu, drop_ttl0_flg,
5983 vlan_removal_en, tx_switching, hw_lro_enable);
5986 QL_DPRINT1(ha, (ha->pci_dev,
5987 "%s: Start V-PORT failed %d\n", __func__, rc));
5991 QL_DPRINT2(ha, (ha->pci_dev,
5992 "%s: Start vport ramrod passed,"
5993 " vport_id = %d, MTU = %d, vlan_removal_en = %d\n", __func__,
5994 vport_id, (int)(ifp->if_mtu + 0xe), vlan_removal_en));
5997 struct ecore_rxq_start_ret_params rx_ret_params;
5998 struct ecore_txq_start_ret_params tx_ret_params;
6000 fp = &ha->fp_array[i];
6001 p_hwfn = &cdev->hwfns[(fp->rss_id % cdev->num_hwfns)];
6003 bzero(&qparams, sizeof(struct ecore_queue_start_common_params));
6004 bzero(&rx_ret_params,
6005 sizeof (struct ecore_rxq_start_ret_params));
6007 qparams.queue_id = i ;
6008 qparams.vport_id = vport_id;
6009 qparams.stats_id = vport_id;
6010 qparams.p_sb = fp->sb_info;
6011 qparams.sb_idx = RX_PI;
6014 rc = ecore_eth_rx_queue_start(p_hwfn,
6015 p_hwfn->hw_info.opaque_fid,
6017 fp->rxq->rx_buf_size, /* bd_max_bytes */
6018 /* bd_chain_phys_addr */
6019 fp->rxq->rx_bd_ring.p_phys_addr,
6021 ecore_chain_get_pbl_phys(&fp->rxq->rx_comp_ring),
6023 ecore_chain_get_page_cnt(&fp->rxq->rx_comp_ring),
6027 QL_DPRINT1(ha, (ha->pci_dev,
6028 "%s: Start RXQ #%d failed %d\n", __func__,
6033 fp->rxq->hw_rxq_prod_addr = rx_ret_params.p_prod;
6034 fp->rxq->handle = rx_ret_params.p_handle;
6035 fp->rxq->hw_cons_ptr =
6036 &fp->sb_info->sb_virt->pi_array[RX_PI];
6038 qlnx_update_rx_prod(p_hwfn, fp->rxq);
6040 for (tc = 0; tc < ha->num_tc; tc++) {
6041 struct qlnx_tx_queue *txq = fp->txq[tc];
6044 sizeof(struct ecore_queue_start_common_params));
6045 bzero(&tx_ret_params,
6046 sizeof (struct ecore_txq_start_ret_params));
6048 qparams.queue_id = txq->index / cdev->num_hwfns ;
6049 qparams.vport_id = vport_id;
6050 qparams.stats_id = vport_id;
6051 qparams.p_sb = fp->sb_info;
6052 qparams.sb_idx = TX_PI(tc);
6054 rc = ecore_eth_tx_queue_start(p_hwfn,
6055 p_hwfn->hw_info.opaque_fid,
6057 /* bd_chain_phys_addr */
6058 ecore_chain_get_pbl_phys(&txq->tx_pbl),
6059 ecore_chain_get_page_cnt(&txq->tx_pbl),
6063 QL_DPRINT1(ha, (ha->pci_dev,
6064 "%s: Start TXQ #%d failed %d\n",
6065 __func__, txq->index, rc));
6069 txq->doorbell_addr = tx_ret_params.p_doorbell;
6070 txq->handle = tx_ret_params.p_handle;
6073 &fp->sb_info->sb_virt->pi_array[TX_PI(tc)];
6074 SET_FIELD(txq->tx_db.data.params,
6075 ETH_DB_DATA_DEST, DB_DEST_XCM);
6076 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD,
6078 SET_FIELD(txq->tx_db.data.params,
6079 ETH_DB_DATA_AGG_VAL_SEL,
6080 DQ_XCM_ETH_TX_BD_PROD_CMD);
6082 txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
6086 /* Fill struct with RSS params */
6087 if (ha->num_rss > 1) {
6089 rss_params->update_rss_config = 1;
6090 rss_params->rss_enable = 1;
6091 rss_params->update_rss_capabilities = 1;
6092 rss_params->update_rss_ind_table = 1;
6093 rss_params->update_rss_key = 1;
6094 rss_params->rss_caps = ECORE_RSS_IPV4 | ECORE_RSS_IPV6 |
6095 ECORE_RSS_IPV4_TCP | ECORE_RSS_IPV6_TCP;
6096 rss_params->rss_table_size_log = 7; /* 2^7 = 128 */
6098 for (i = 0; i < ECORE_RSS_IND_TABLE_SIZE; i++) {
6099 fp = &ha->fp_array[(i % ha->num_rss)];
6100 rss_params->rss_ind_table[i] = fp->rxq->handle;
6103 for (i = 0; i < ECORE_RSS_KEY_SIZE; i++)
6104 rss_params->rss_key[i] = (__le32)qlnx_hash_key[i];
6107 memset(rss_params, 0, sizeof(*rss_params));
6111 /* Prepare and send the vport enable */
6112 memset(&vport_update_params, 0, sizeof(vport_update_params));
6113 vport_update_params.vport_id = vport_id;
6114 vport_update_params.update_vport_active_tx_flg = 1;
6115 vport_update_params.vport_active_tx_flg = 1;
6116 vport_update_params.update_vport_active_rx_flg = 1;
6117 vport_update_params.vport_active_rx_flg = 1;
6118 vport_update_params.rss_params = rss_params;
6119 vport_update_params.update_inner_vlan_removal_flg = 1;
6120 vport_update_params.inner_vlan_removal_flg = 1;
6122 if (hw_lro_enable) {
6123 memset(&tpa_params, 0, sizeof (struct ecore_sge_tpa_params));
6125 tpa_params.max_buffers_per_cqe = QLNX_TPA_MAX_AGG_BUFFERS;
6127 tpa_params.update_tpa_en_flg = 1;
6128 tpa_params.tpa_ipv4_en_flg = 1;
6129 tpa_params.tpa_ipv6_en_flg = 1;
6131 tpa_params.update_tpa_param_flg = 1;
6132 tpa_params.tpa_pkt_split_flg = 0;
6133 tpa_params.tpa_hdr_data_split_flg = 0;
6134 tpa_params.tpa_gro_consistent_flg = 0;
6135 tpa_params.tpa_max_aggs_num = ETH_TPA_MAX_AGGS_NUM;
6136 tpa_params.tpa_max_size = (uint16_t)(-1);
6137 tpa_params.tpa_min_size_to_start = ifp->if_mtu/2;
6138 tpa_params.tpa_min_size_to_cont = ifp->if_mtu/2;
6140 vport_update_params.sge_tpa_params = &tpa_params;
6143 rc = qlnx_update_vport(cdev, &vport_update_params);
6145 QL_DPRINT1(ha, (ha->pci_dev,
6146 "%s: Update V-PORT failed %d\n", __func__, rc));
6154 qlnx_drain_txq(qlnx_host_t *ha, struct qlnx_fastpath *fp,
6155 struct qlnx_tx_queue *txq)
6157 uint16_t hw_bd_cons;
6158 uint16_t ecore_cons_idx;
6160 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
6162 hw_bd_cons = le16toh(*txq->hw_cons_ptr);
6164 while (hw_bd_cons !=
6165 (ecore_cons_idx = ecore_chain_get_cons_idx(&txq->tx_pbl))) {
6167 mtx_lock(&fp->tx_mtx);
6169 (void)qlnx_tx_int(ha, fp, txq);
6171 mtx_unlock(&fp->tx_mtx);
6173 qlnx_mdelay(__func__, 2);
6175 hw_bd_cons = le16toh(*txq->hw_cons_ptr);
6178 QL_DPRINT2(ha, (ha->pci_dev, "%s[%d, %d]: done\n", __func__,
6179 fp->rss_id, txq->index));
6185 qlnx_stop_queues(qlnx_host_t *ha)
6187 struct qlnx_update_vport_params vport_update_params;
6188 struct ecore_dev *cdev;
6189 struct qlnx_fastpath *fp;
6194 /* Disable the vport */
6196 memset(&vport_update_params, 0, sizeof(vport_update_params));
6198 vport_update_params.vport_id = 0;
6199 vport_update_params.update_vport_active_tx_flg = 1;
6200 vport_update_params.vport_active_tx_flg = 0;
6201 vport_update_params.update_vport_active_rx_flg = 1;
6202 vport_update_params.vport_active_rx_flg = 0;
6203 vport_update_params.rss_params = &ha->rss_params;
6204 vport_update_params.rss_params->update_rss_config = 0;
6205 vport_update_params.rss_params->rss_enable = 0;
6206 vport_update_params.update_inner_vlan_removal_flg = 0;
6207 vport_update_params.inner_vlan_removal_flg = 0;
6209 rc = qlnx_update_vport(cdev, &vport_update_params);
6211 QL_DPRINT1(ha, (ha->pci_dev, "%s:Failed to update vport\n",
6216 /* Flush Tx queues. If needed, request drain from MCP */
6218 fp = &ha->fp_array[i];
6220 for (tc = 0; tc < ha->num_tc; tc++) {
6221 struct qlnx_tx_queue *txq = fp->txq[tc];
6223 rc = qlnx_drain_txq(ha, fp, txq);
6229 /* Stop all Queues in reverse order*/
6230 for (i = ha->num_rss - 1; i >= 0; i--) {
6232 struct ecore_hwfn *p_hwfn = &cdev->hwfns[(i % cdev->num_hwfns)];
6234 fp = &ha->fp_array[i];
6236 /* Stop the Tx Queue(s)*/
6237 for (tc = 0; tc < ha->num_tc; tc++) {
6240 tx_queue_id = tc * ha->num_rss + i;
6241 rc = ecore_eth_tx_queue_stop(p_hwfn,
6242 fp->txq[tc]->handle);
6245 QL_DPRINT1(ha, (ha->pci_dev,
6246 "%s: Failed to stop TXQ #%d\n",
6247 __func__, tx_queue_id));
6252 /* Stop the Rx Queue*/
6253 rc = ecore_eth_rx_queue_stop(p_hwfn, fp->rxq->handle, false,
6256 QL_DPRINT1(ha, (ha->pci_dev,
6257 "%s: Failed to stop RXQ #%d\n", __func__, i));
6262 /* Stop the vport */
6263 for_each_hwfn(cdev, i) {
6265 struct ecore_hwfn *p_hwfn = &cdev->hwfns[i];
6267 rc = ecore_sp_vport_stop(p_hwfn, p_hwfn->hw_info.opaque_fid, 0);
6270 QL_DPRINT1(ha, (ha->pci_dev,
6271 "%s: Failed to stop VPORT\n", __func__));
6280 qlnx_set_ucast_rx_mac(qlnx_host_t *ha,
6281 enum ecore_filter_opcode opcode,
6282 unsigned char mac[ETH_ALEN])
6284 struct ecore_filter_ucast ucast;
6285 struct ecore_dev *cdev;
6290 bzero(&ucast, sizeof(struct ecore_filter_ucast));
6292 ucast.opcode = opcode;
6293 ucast.type = ECORE_FILTER_MAC;
6294 ucast.is_rx_filter = 1;
6295 ucast.vport_to_add_to = 0;
6296 memcpy(&ucast.mac[0], mac, ETH_ALEN);
6298 rc = ecore_filter_ucast_cmd(cdev, &ucast, ECORE_SPQ_MODE_CB, NULL);
6304 qlnx_remove_all_ucast_mac(qlnx_host_t *ha)
6306 struct ecore_filter_ucast ucast;
6307 struct ecore_dev *cdev;
6310 bzero(&ucast, sizeof(struct ecore_filter_ucast));
6312 ucast.opcode = ECORE_FILTER_REPLACE;
6313 ucast.type = ECORE_FILTER_MAC;
6314 ucast.is_rx_filter = 1;
6318 rc = ecore_filter_ucast_cmd(cdev, &ucast, ECORE_SPQ_MODE_CB, NULL);
6324 qlnx_remove_all_mcast_mac(qlnx_host_t *ha)
6326 struct ecore_filter_mcast *mcast;
6327 struct ecore_dev *cdev;
6332 mcast = &ha->ecore_mcast;
6333 bzero(mcast, sizeof(struct ecore_filter_mcast));
6335 mcast->opcode = ECORE_FILTER_REMOVE;
6337 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
6339 if (ha->mcast[i].addr[0] || ha->mcast[i].addr[1] ||
6340 ha->mcast[i].addr[2] || ha->mcast[i].addr[3] ||
6341 ha->mcast[i].addr[4] || ha->mcast[i].addr[5]) {
6343 memcpy(&mcast->mac[i], &ha->mcast[i].addr[0], ETH_ALEN);
6344 mcast->num_mc_addrs++;
6347 mcast = &ha->ecore_mcast;
6349 rc = ecore_filter_mcast_cmd(cdev, mcast, ECORE_SPQ_MODE_CB, NULL);
6351 bzero(ha->mcast, (sizeof(qlnx_mcast_t) * QLNX_MAX_NUM_MULTICAST_ADDRS));
6358 qlnx_clean_filters(qlnx_host_t *ha)
6362 /* Remove all unicast macs */
6363 rc = qlnx_remove_all_ucast_mac(ha);
6367 /* Remove all multicast macs */
6368 rc = qlnx_remove_all_mcast_mac(ha);
6372 rc = qlnx_set_ucast_rx_mac(ha, ECORE_FILTER_FLUSH, ha->primary_mac);
6378 qlnx_set_rx_accept_filter(qlnx_host_t *ha, uint8_t filter)
6380 struct ecore_filter_accept_flags accept;
6382 struct ecore_dev *cdev;
6386 bzero(&accept, sizeof(struct ecore_filter_accept_flags));
6388 accept.update_rx_mode_config = 1;
6389 accept.rx_accept_filter = filter;
6391 accept.update_tx_mode_config = 1;
6392 accept.tx_accept_filter = ECORE_ACCEPT_UCAST_MATCHED |
6393 ECORE_ACCEPT_MCAST_MATCHED | ECORE_ACCEPT_BCAST;
6395 rc = ecore_filter_accept_cmd(cdev, 0, accept, false, false,
6396 ECORE_SPQ_MODE_CB, NULL);
6402 qlnx_set_rx_mode(qlnx_host_t *ha)
6407 rc = qlnx_set_ucast_rx_mac(ha, ECORE_FILTER_REPLACE, ha->primary_mac);
6411 rc = qlnx_remove_all_mcast_mac(ha);
6415 filter = ECORE_ACCEPT_UCAST_MATCHED |
6416 ECORE_ACCEPT_MCAST_MATCHED |
6418 ha->filter = filter;
6420 rc = qlnx_set_rx_accept_filter(ha, filter);
6426 qlnx_set_link(qlnx_host_t *ha, bool link_up)
6429 struct ecore_dev *cdev;
6430 struct ecore_hwfn *hwfn;
6431 struct ecore_ptt *ptt;
6435 for_each_hwfn(cdev, i) {
6437 hwfn = &cdev->hwfns[i];
6439 ptt = ecore_ptt_acquire(hwfn);
6443 rc = ecore_mcp_set_link(hwfn, ptt, link_up);
6445 ecore_ptt_release(hwfn, ptt);
6453 #if __FreeBSD_version >= 1100000
6455 qlnx_get_counter(if_t ifp, ift_counter cnt)
6460 ha = (qlnx_host_t *)if_getsoftc(ifp);
6464 case IFCOUNTER_IPACKETS:
6465 count = ha->hw_stats.common.rx_ucast_pkts +
6466 ha->hw_stats.common.rx_mcast_pkts +
6467 ha->hw_stats.common.rx_bcast_pkts;
6470 case IFCOUNTER_IERRORS:
6471 count = ha->hw_stats.common.rx_crc_errors +
6472 ha->hw_stats.common.rx_align_errors +
6473 ha->hw_stats.common.rx_oversize_packets +
6474 ha->hw_stats.common.rx_undersize_packets;
6477 case IFCOUNTER_OPACKETS:
6478 count = ha->hw_stats.common.tx_ucast_pkts +
6479 ha->hw_stats.common.tx_mcast_pkts +
6480 ha->hw_stats.common.tx_bcast_pkts;
6483 case IFCOUNTER_OERRORS:
6484 count = ha->hw_stats.common.tx_err_drop_pkts;
6487 case IFCOUNTER_COLLISIONS:
6490 case IFCOUNTER_IBYTES:
6491 count = ha->hw_stats.common.rx_ucast_bytes +
6492 ha->hw_stats.common.rx_mcast_bytes +
6493 ha->hw_stats.common.rx_bcast_bytes;
6496 case IFCOUNTER_OBYTES:
6497 count = ha->hw_stats.common.tx_ucast_bytes +
6498 ha->hw_stats.common.tx_mcast_bytes +
6499 ha->hw_stats.common.tx_bcast_bytes;
6502 case IFCOUNTER_IMCASTS:
6503 count = ha->hw_stats.common.rx_mcast_bytes;
6506 case IFCOUNTER_OMCASTS:
6507 count = ha->hw_stats.common.tx_mcast_bytes;
6510 case IFCOUNTER_IQDROPS:
6511 case IFCOUNTER_OQDROPS:
6512 case IFCOUNTER_NOPROTO:
6515 return (if_get_counter_default(ifp, cnt));
6523 qlnx_timer(void *arg)
6527 ha = (qlnx_host_t *)arg;
6529 ecore_get_vport_stats(&ha->cdev, &ha->hw_stats);
6531 if (ha->storm_stats_enable)
6532 qlnx_sample_storm_stats(ha);
6534 callout_reset(&ha->qlnx_callout, hz, qlnx_timer, ha);
6540 qlnx_load(qlnx_host_t *ha)
6544 struct ecore_dev *cdev;
6550 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
6552 rc = qlnx_alloc_mem_arrays(ha);
6554 goto qlnx_load_exit0;
6558 rc = qlnx_alloc_mem_load(ha);
6560 goto qlnx_load_exit1;
6562 QL_DPRINT2(ha, (dev, "%s: Allocated %d RSS queues on %d TC/s\n",
6563 __func__, ha->num_rss, ha->num_tc));
6565 for (i = 0; i < ha->num_rss; i++) {
6567 if ((rc = bus_setup_intr(dev, ha->irq_vec[i].irq,
6568 (INTR_TYPE_NET | INTR_MPSAFE),
6569 NULL, qlnx_fp_isr, &ha->irq_vec[i],
6570 &ha->irq_vec[i].handle))) {
6572 QL_DPRINT1(ha, (dev, "could not setup interrupt\n"));
6574 goto qlnx_load_exit2;
6577 QL_DPRINT2(ha, (dev, "%s: rss_id = %d irq_rid %d"
6578 " irq %p handle %p\n", __func__, i,
6579 ha->irq_vec[i].irq_rid,
6580 ha->irq_vec[i].irq, ha->irq_vec[i].handle));
6582 bus_bind_intr(dev, ha->irq_vec[i].irq, (i % mp_ncpus));
6585 rc = qlnx_start_queues(ha);
6587 goto qlnx_load_exit2;
6589 QL_DPRINT2(ha, (dev, "%s: Start VPORT, RXQ and TXQ succeeded\n",
6592 /* Add primary mac and set Rx filters */
6593 rc = qlnx_set_rx_mode(ha);
6595 goto qlnx_load_exit2;
6597 /* Ask for link-up using current configuration */
6598 qlnx_set_link(ha, true);
6600 ha->state = QLNX_STATE_OPEN;
6602 bzero(&ha->hw_stats, sizeof(struct ecore_eth_stats));
6604 if (ha->flags.callout_init)
6605 callout_reset(&ha->qlnx_callout, hz, qlnx_timer, ha);
6607 goto qlnx_load_exit0;
6610 qlnx_free_mem_load(ha);
6616 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit [%d]\n", __func__, rc));
6621 qlnx_drain_soft_lro(qlnx_host_t *ha)
6623 #ifdef QLNX_SOFT_LRO
6631 if (ifp->if_capenable & IFCAP_LRO) {
6633 for (i = 0; i < ha->num_rss; i++) {
6635 struct qlnx_fastpath *fp = &ha->fp_array[i];
6636 struct lro_ctrl *lro;
6638 lro = &fp->rxq->lro;
6640 #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
6642 tcp_lro_flush_all(lro);
6645 struct lro_entry *queued;
6647 while ((!SLIST_EMPTY(&lro->lro_active))){
6648 queued = SLIST_FIRST(&lro->lro_active);
6649 SLIST_REMOVE_HEAD(&lro->lro_active, next);
6650 tcp_lro_flush(lro, queued);
6653 #endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
6658 #endif /* #ifdef QLNX_SOFT_LRO */
6664 qlnx_unload(qlnx_host_t *ha)
6666 struct ecore_dev *cdev;
6673 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
6675 if (ha->state == QLNX_STATE_OPEN) {
6677 qlnx_set_link(ha, false);
6678 qlnx_clean_filters(ha);
6679 qlnx_stop_queues(ha);
6680 ecore_hw_stop_fastpath(cdev);
6682 for (i = 0; i < ha->num_rss; i++) {
6683 if (ha->irq_vec[i].handle) {
6684 (void)bus_teardown_intr(dev,
6686 ha->irq_vec[i].handle);
6687 ha->irq_vec[i].handle = NULL;
6691 qlnx_drain_fp_taskqueues(ha);
6692 qlnx_drain_soft_lro(ha);
6693 qlnx_free_mem_load(ha);
6696 if (ha->flags.callout_init)
6697 callout_drain(&ha->qlnx_callout);
6699 qlnx_mdelay(__func__, 1000);
6701 ha->state = QLNX_STATE_CLOSED;
6703 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
6708 qlnx_grc_dumpsize(qlnx_host_t *ha, uint32_t *num_dwords, int hwfn_index)
6711 struct ecore_hwfn *p_hwfn;
6712 struct ecore_ptt *p_ptt;
6714 ecore_dbg_set_app_ver(ecore_dbg_get_fw_func_ver());
6716 p_hwfn = &ha->cdev.hwfns[hwfn_index];
6717 p_ptt = ecore_ptt_acquire(p_hwfn);
6720 QL_DPRINT1(ha, (ha->pci_dev, "%s: ecore_ptt_acquire failed\n",
6725 rval = ecore_dbg_grc_get_dump_buf_size(p_hwfn, p_ptt, num_dwords);
6727 if (rval == DBG_STATUS_OK)
6730 QL_DPRINT1(ha, (ha->pci_dev,
6731 "%s : ecore_dbg_grc_get_dump_buf_size failed [0x%x]\n",
6735 ecore_ptt_release(p_hwfn, p_ptt);
6741 qlnx_idle_chk_size(qlnx_host_t *ha, uint32_t *num_dwords, int hwfn_index)
6744 struct ecore_hwfn *p_hwfn;
6745 struct ecore_ptt *p_ptt;
6747 ecore_dbg_set_app_ver(ecore_dbg_get_fw_func_ver());
6749 p_hwfn = &ha->cdev.hwfns[hwfn_index];
6750 p_ptt = ecore_ptt_acquire(p_hwfn);
6753 QL_DPRINT1(ha, (ha->pci_dev, "%s: ecore_ptt_acquire failed\n",
6758 rval = ecore_dbg_idle_chk_get_dump_buf_size(p_hwfn, p_ptt, num_dwords);
6760 if (rval == DBG_STATUS_OK)
6763 QL_DPRINT1(ha, (ha->pci_dev, "%s : "
6764 "ecore_dbg_idle_chk_get_dump_buf_size failed [0x%x]\n",
6768 ecore_ptt_release(p_hwfn, p_ptt);
6775 qlnx_sample_storm_stats(qlnx_host_t *ha)
6778 struct ecore_dev *cdev;
6779 qlnx_storm_stats_t *s_stats;
6781 struct ecore_ptt *p_ptt;
6782 struct ecore_hwfn *hwfn;
6784 if (ha->storm_stats_index >= QLNX_STORM_STATS_SAMPLES_PER_HWFN) {
6785 ha->storm_stats_enable = 0;
6791 for_each_hwfn(cdev, i) {
6793 hwfn = &cdev->hwfns[i];
6795 p_ptt = ecore_ptt_acquire(hwfn);
6799 index = ha->storm_stats_index +
6800 (i * QLNX_STORM_STATS_SAMPLES_PER_HWFN);
6802 s_stats = &ha->storm_stats[index];
6805 reg = XSEM_REG_FAST_MEMORY +
6806 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6807 s_stats->xstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6809 reg = XSEM_REG_FAST_MEMORY +
6810 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6811 s_stats->xstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6813 reg = XSEM_REG_FAST_MEMORY +
6814 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6815 s_stats->xstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6817 reg = XSEM_REG_FAST_MEMORY +
6818 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6819 s_stats->xstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6822 reg = YSEM_REG_FAST_MEMORY +
6823 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6824 s_stats->ystorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6826 reg = YSEM_REG_FAST_MEMORY +
6827 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6828 s_stats->ystorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6830 reg = YSEM_REG_FAST_MEMORY +
6831 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6832 s_stats->ystorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6834 reg = YSEM_REG_FAST_MEMORY +
6835 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6836 s_stats->ystorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6839 reg = PSEM_REG_FAST_MEMORY +
6840 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6841 s_stats->pstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6843 reg = PSEM_REG_FAST_MEMORY +
6844 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6845 s_stats->pstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6847 reg = PSEM_REG_FAST_MEMORY +
6848 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6849 s_stats->pstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6851 reg = PSEM_REG_FAST_MEMORY +
6852 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6853 s_stats->pstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6856 reg = TSEM_REG_FAST_MEMORY +
6857 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6858 s_stats->tstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6860 reg = TSEM_REG_FAST_MEMORY +
6861 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6862 s_stats->tstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6864 reg = TSEM_REG_FAST_MEMORY +
6865 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6866 s_stats->tstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6868 reg = TSEM_REG_FAST_MEMORY +
6869 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6870 s_stats->tstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6873 reg = MSEM_REG_FAST_MEMORY +
6874 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6875 s_stats->mstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6877 reg = MSEM_REG_FAST_MEMORY +
6878 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6879 s_stats->mstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6881 reg = MSEM_REG_FAST_MEMORY +
6882 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6883 s_stats->mstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6885 reg = MSEM_REG_FAST_MEMORY +
6886 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6887 s_stats->mstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6890 reg = USEM_REG_FAST_MEMORY +
6891 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6892 s_stats->ustorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6894 reg = USEM_REG_FAST_MEMORY +
6895 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6896 s_stats->ustorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6898 reg = USEM_REG_FAST_MEMORY +
6899 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6900 s_stats->ustorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6902 reg = USEM_REG_FAST_MEMORY +
6903 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6904 s_stats->ustorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6906 ecore_ptt_release(hwfn, p_ptt);
6909 ha->storm_stats_index++;
6915 * Name: qlnx_dump_buf8
6916 * Function: dumps a buffer as bytes
6919 qlnx_dump_buf8(qlnx_host_t *ha, const char *msg, void *dbuf, uint32_t len)
6928 device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
6931 device_printf(dev,"0x%08x:"
6932 " %02x %02x %02x %02x %02x %02x %02x %02x"
6933 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
6934 buf[0], buf[1], buf[2], buf[3],
6935 buf[4], buf[5], buf[6], buf[7],
6936 buf[8], buf[9], buf[10], buf[11],
6937 buf[12], buf[13], buf[14], buf[15]);
6944 device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
6947 device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
6950 device_printf(dev,"0x%08x: %02x %02x %02x\n",
6951 i, buf[0], buf[1], buf[2]);
6954 device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
6955 buf[0], buf[1], buf[2], buf[3]);
6958 device_printf(dev,"0x%08x:"
6959 " %02x %02x %02x %02x %02x\n", i,
6960 buf[0], buf[1], buf[2], buf[3], buf[4]);
6963 device_printf(dev,"0x%08x:"
6964 " %02x %02x %02x %02x %02x %02x\n", i,
6965 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
6968 device_printf(dev,"0x%08x:"
6969 " %02x %02x %02x %02x %02x %02x %02x\n", i,
6970 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
6973 device_printf(dev,"0x%08x:"
6974 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
6975 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6979 device_printf(dev,"0x%08x:"
6980 " %02x %02x %02x %02x %02x %02x %02x %02x"
6982 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6986 device_printf(dev,"0x%08x:"
6987 " %02x %02x %02x %02x %02x %02x %02x %02x"
6989 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6990 buf[7], buf[8], buf[9]);
6993 device_printf(dev,"0x%08x:"
6994 " %02x %02x %02x %02x %02x %02x %02x %02x"
6995 " %02x %02x %02x\n", i,
6996 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6997 buf[7], buf[8], buf[9], buf[10]);
7000 device_printf(dev,"0x%08x:"
7001 " %02x %02x %02x %02x %02x %02x %02x %02x"
7002 " %02x %02x %02x %02x\n", i,
7003 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
7004 buf[7], buf[8], buf[9], buf[10], buf[11]);
7007 device_printf(dev,"0x%08x:"
7008 " %02x %02x %02x %02x %02x %02x %02x %02x"
7009 " %02x %02x %02x %02x %02x\n", i,
7010 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
7011 buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
7014 device_printf(dev,"0x%08x:"
7015 " %02x %02x %02x %02x %02x %02x %02x %02x"
7016 " %02x %02x %02x %02x %02x %02x\n", i,
7017 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
7018 buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
7022 device_printf(dev,"0x%08x:"
7023 " %02x %02x %02x %02x %02x %02x %02x %02x"
7024 " %02x %02x %02x %02x %02x %02x %02x\n", i,
7025 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
7026 buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
7033 device_printf(dev, "%s: %s dump end\n", __func__, msg);