2 * Copyright (c) 2013-2016 Qlogic Corporation
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.
30 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
40 #include "ql_inline.h"
47 * Some PCI Configuration Space Related Defines
50 #ifndef PCI_VENDOR_QLOGIC
51 #define PCI_VENDOR_QLOGIC 0x1077
54 #ifndef PCI_PRODUCT_QLOGIC_ISP8030
55 #define PCI_PRODUCT_QLOGIC_ISP8030 0x8030
58 #define PCI_QLOGIC_ISP8030 \
59 ((PCI_PRODUCT_QLOGIC_ISP8030 << 16) | PCI_VENDOR_QLOGIC)
64 static int qla_alloc_parent_dma_tag(qla_host_t *ha);
65 static void qla_free_parent_dma_tag(qla_host_t *ha);
66 static int qla_alloc_xmt_bufs(qla_host_t *ha);
67 static void qla_free_xmt_bufs(qla_host_t *ha);
68 static int qla_alloc_rcv_bufs(qla_host_t *ha);
69 static void qla_free_rcv_bufs(qla_host_t *ha);
70 static void qla_clear_tx_buf(qla_host_t *ha, qla_tx_buf_t *txb);
72 static void qla_init_ifnet(device_t dev, qla_host_t *ha);
73 static int qla_sysctl_get_stats(SYSCTL_HANDLER_ARGS);
74 static int qla_sysctl_get_link_status(SYSCTL_HANDLER_ARGS);
75 static void qla_release(qla_host_t *ha);
76 static void qla_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs,
78 static void qla_stop(qla_host_t *ha);
79 static int qla_send(qla_host_t *ha, struct mbuf **m_headp);
80 static void qla_tx_done(void *context, int pending);
81 static void qla_get_peer(qla_host_t *ha);
82 static void qla_error_recovery(void *context, int pending);
83 static void qla_async_event(void *context, int pending);
86 * Hooks to the Operating Systems
88 static int qla_pci_probe (device_t);
89 static int qla_pci_attach (device_t);
90 static int qla_pci_detach (device_t);
92 static void qla_init(void *arg);
93 static int qla_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
94 static int qla_media_change(struct ifnet *ifp);
95 static void qla_media_status(struct ifnet *ifp, struct ifmediareq *ifmr);
96 static void qla_start(struct ifnet *ifp);
98 static device_method_t qla_pci_methods[] = {
99 /* Device interface */
100 DEVMETHOD(device_probe, qla_pci_probe),
101 DEVMETHOD(device_attach, qla_pci_attach),
102 DEVMETHOD(device_detach, qla_pci_detach),
106 static driver_t qla_pci_driver = {
107 "ql", qla_pci_methods, sizeof (qla_host_t),
110 static devclass_t qla83xx_devclass;
112 DRIVER_MODULE(qla83xx, pci, qla_pci_driver, qla83xx_devclass, 0, 0);
114 MODULE_DEPEND(qla83xx, pci, 1, 1, 1);
115 MODULE_DEPEND(qla83xx, ether, 1, 1, 1);
117 MALLOC_DEFINE(M_QLA83XXBUF, "qla83xxbuf", "Buffers for qla83xx driver");
119 #define QL_STD_REPLENISH_THRES 0
120 #define QL_JUMBO_REPLENISH_THRES 32
123 static char dev_str[64];
124 static char ver_str[64];
127 * Name: qla_pci_probe
128 * Function: Validate the PCI device to be a QLA80XX device
131 qla_pci_probe(device_t dev)
133 switch ((pci_get_device(dev) << 16) | (pci_get_vendor(dev))) {
134 case PCI_QLOGIC_ISP8030:
135 snprintf(dev_str, sizeof(dev_str), "%s v%d.%d.%d",
136 "Qlogic ISP 83xx PCI CNA Adapter-Ethernet Function",
137 QLA_VERSION_MAJOR, QLA_VERSION_MINOR,
139 snprintf(ver_str, sizeof(ver_str), "v%d.%d.%d",
140 QLA_VERSION_MAJOR, QLA_VERSION_MINOR,
142 device_set_desc(dev, dev_str);
149 printf("%s: %s\n ", __func__, dev_str);
151 return (BUS_PROBE_DEFAULT);
155 qla_add_sysctls(qla_host_t *ha)
157 device_t dev = ha->pci_dev;
159 SYSCTL_ADD_STRING(device_get_sysctl_ctx(dev),
160 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
161 OID_AUTO, "version", CTLFLAG_RD,
162 ver_str, 0, "Driver Version");
164 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
165 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
166 OID_AUTO, "stats", CTLTYPE_INT | CTLFLAG_RW,
168 qla_sysctl_get_stats, "I", "Statistics");
170 SYSCTL_ADD_STRING(device_get_sysctl_ctx(dev),
171 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
172 OID_AUTO, "fw_version", CTLFLAG_RD,
173 ha->fw_ver_str, 0, "firmware version");
175 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
176 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
177 OID_AUTO, "link_status", CTLTYPE_INT | CTLFLAG_RW,
179 qla_sysctl_get_link_status, "I", "Link Status");
182 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
183 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
184 OID_AUTO, "debug", CTLFLAG_RW,
185 &ha->dbg_level, ha->dbg_level, "Debug Level");
187 ha->std_replenish = QL_STD_REPLENISH_THRES;
188 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
189 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
190 OID_AUTO, "std_replenish", CTLFLAG_RW,
191 &ha->std_replenish, ha->std_replenish,
192 "Threshold for Replenishing Standard Frames");
194 SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev),
195 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
196 OID_AUTO, "ipv4_lro",
197 CTLFLAG_RD, &ha->ipv4_lro,
198 "number of ipv4 lro completions");
200 SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev),
201 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
202 OID_AUTO, "ipv6_lro",
203 CTLFLAG_RD, &ha->ipv6_lro,
204 "number of ipv6 lro completions");
206 SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev),
207 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
208 OID_AUTO, "tx_tso_frames",
209 CTLFLAG_RD, &ha->tx_tso_frames,
210 "number of Tx TSO Frames");
212 SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev),
213 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
214 OID_AUTO, "hw_vlan_tx_frames",
215 CTLFLAG_RD, &ha->hw_vlan_tx_frames,
216 "number of Tx VLAN Frames");
222 qla_watchdog(void *arg)
224 qla_host_t *ha = arg;
228 qla_hw_tx_cntxt_t *hw_tx_cntxt;
233 if (ha->flags.qla_watchdog_exit) {
234 ha->qla_watchdog_exited = 1;
237 ha->qla_watchdog_exited = 0;
239 if (!ha->flags.qla_watchdog_pause) {
240 if (ql_hw_check_health(ha) || ha->qla_initiate_recovery ||
241 (ha->msg_from_peer == QL_PEER_MSG_RESET)) {
242 ha->qla_watchdog_paused = 1;
243 ha->flags.qla_watchdog_pause = 1;
244 ha->qla_initiate_recovery = 0;
246 taskqueue_enqueue(ha->err_tq, &ha->err_task);
247 } else if (ha->flags.qla_interface_up) {
249 if (ha->async_event) {
251 taskqueue_enqueue(ha->async_event_tq,
252 &ha->async_event_task);
255 for (i = 0; i < ha->hw.num_tx_rings; i++) {
256 hw_tx_cntxt = &hw->tx_cntxt[i];
257 if (qla_le32_to_host(*(hw_tx_cntxt->tx_cons)) !=
258 hw_tx_cntxt->txr_comp) {
259 taskqueue_enqueue(ha->tx_tq,
265 if ((ifp->if_snd.ifq_head != NULL) && QL_RUNNING(ifp)) {
266 taskqueue_enqueue(ha->tx_tq, &ha->tx_task);
268 ha->qla_watchdog_paused = 0;
270 ha->qla_watchdog_paused = 0;
273 ha->qla_watchdog_paused = 1;
276 ha->watchdog_ticks = ha->watchdog_ticks++ % 1000;
277 callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS,
282 * Name: qla_pci_attach
283 * Function: attaches the device to the operating system
286 qla_pci_attach(device_t dev)
288 qla_host_t *ha = NULL;
291 uint32_t num_rcvq = 0;
293 if ((ha = device_get_softc(dev)) == NULL) {
294 device_printf(dev, "cannot get softc\n");
298 memset(ha, 0, sizeof (qla_host_t));
300 if (pci_get_device(dev) != PCI_PRODUCT_QLOGIC_ISP8030) {
301 device_printf(dev, "device is not ISP8030\n");
305 ha->pci_func = pci_get_function(dev) & 0x1;
309 pci_enable_busmaster(dev);
311 ha->reg_rid = PCIR_BAR(0);
312 ha->pci_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &ha->reg_rid,
315 if (ha->pci_reg == NULL) {
316 device_printf(dev, "unable to map any ports\n");
317 goto qla_pci_attach_err;
320 rsrc_len = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
323 mtx_init(&ha->hw_lock, "qla83xx_hw_lock", MTX_NETWORK_LOCK, MTX_SPIN);
325 mtx_init(&ha->tx_lock, "qla83xx_tx_lock", MTX_NETWORK_LOCK, MTX_DEF);
328 ql_hw_add_sysctls(ha);
330 ha->flags.lock_init = 1;
332 ha->reg_rid1 = PCIR_BAR(2);
333 ha->pci_reg1 = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
334 &ha->reg_rid1, RF_ACTIVE);
336 ha->msix_count = pci_msix_count(dev);
338 if (ha->msix_count < (ha->hw.num_sds_rings + 1)) {
339 device_printf(dev, "%s: msix_count[%d] not enough\n", __func__,
341 goto qla_pci_attach_err;
344 QL_DPRINT2(ha, (dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x"
345 " msix_count 0x%x pci_reg %p\n", __func__, ha,
346 ha->pci_func, rsrc_len, ha->msix_count, ha->pci_reg));
348 /* initialize hardware */
349 if (ql_init_hw(ha)) {
350 device_printf(dev, "%s: ql_init_hw failed\n", __func__);
351 goto qla_pci_attach_err;
354 device_printf(dev, "%s: firmware[%d.%d.%d.%d]\n", __func__,
355 ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub,
357 snprintf(ha->fw_ver_str, sizeof(ha->fw_ver_str), "%d.%d.%d.%d",
358 ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub,
361 if (qla_get_nic_partition(ha, NULL, &num_rcvq)) {
362 device_printf(dev, "%s: qla_get_nic_partition failed\n",
364 goto qla_pci_attach_err;
366 device_printf(dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x"
367 " msix_count 0x%x pci_reg %p num_rcvq = %d\n", __func__, ha,
368 ha->pci_func, rsrc_len, ha->msix_count, ha->pci_reg, num_rcvq);
371 #ifdef QL_ENABLE_ISCSI_TLV
372 if ((ha->msix_count < 64) || (num_rcvq != 32)) {
373 ha->hw.num_sds_rings = 15;
374 ha->hw.num_tx_rings = 32;
376 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
377 ha->hw.num_rds_rings = ha->hw.num_sds_rings;
379 ha->msix_count = ha->hw.num_sds_rings + 1;
381 if (pci_alloc_msix(dev, &ha->msix_count)) {
382 device_printf(dev, "%s: pci_alloc_msi[%d] failed\n", __func__,
385 goto qla_pci_attach_err;
389 ha->mbx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
391 (RF_ACTIVE | RF_SHAREABLE));
392 if (ha->mbx_irq == NULL) {
393 device_printf(dev, "could not allocate mbx interrupt\n");
394 goto qla_pci_attach_err;
396 if (bus_setup_intr(dev, ha->mbx_irq, (INTR_TYPE_NET | INTR_MPSAFE),
397 NULL, ql_mbx_isr, ha, &ha->mbx_handle)) {
398 device_printf(dev, "could not setup mbx interrupt\n");
399 goto qla_pci_attach_err;
402 for (i = 0; i < ha->hw.num_sds_rings; i++) {
403 ha->irq_vec[i].sds_idx = i;
404 ha->irq_vec[i].ha = ha;
405 ha->irq_vec[i].irq_rid = 2 + i;
407 ha->irq_vec[i].irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
408 &ha->irq_vec[i].irq_rid,
409 (RF_ACTIVE | RF_SHAREABLE));
411 if (ha->irq_vec[i].irq == NULL) {
412 device_printf(dev, "could not allocate interrupt\n");
413 goto qla_pci_attach_err;
415 if (bus_setup_intr(dev, ha->irq_vec[i].irq,
416 (INTR_TYPE_NET | INTR_MPSAFE),
417 NULL, ql_isr, &ha->irq_vec[i],
418 &ha->irq_vec[i].handle)) {
419 device_printf(dev, "could not setup interrupt\n");
420 goto qla_pci_attach_err;
424 printf("%s: mp__ncpus %d sds %d rds %d msi-x %d\n", __func__, mp_ncpus,
425 ha->hw.num_sds_rings, ha->hw.num_rds_rings, ha->msix_count);
427 ql_read_mac_addr(ha);
429 /* allocate parent dma tag */
430 if (qla_alloc_parent_dma_tag(ha)) {
431 device_printf(dev, "%s: qla_alloc_parent_dma_tag failed\n",
433 goto qla_pci_attach_err;
436 /* alloc all dma buffers */
437 if (ql_alloc_dma(ha)) {
438 device_printf(dev, "%s: ql_alloc_dma failed\n", __func__);
439 goto qla_pci_attach_err;
443 if (ql_minidump_init(ha) != 0) {
444 device_printf(dev, "%s: ql_minidump_init failed\n", __func__);
445 goto qla_pci_attach_err;
447 /* create the o.s ethernet interface */
448 qla_init_ifnet(dev, ha);
450 ha->flags.qla_watchdog_active = 1;
451 ha->flags.qla_watchdog_pause = 0;
454 TASK_INIT(&ha->tx_task, 0, qla_tx_done, ha);
455 ha->tx_tq = taskqueue_create_fast("qla_txq", M_NOWAIT,
456 taskqueue_thread_enqueue, &ha->tx_tq);
457 taskqueue_start_threads(&ha->tx_tq, 1, PI_NET, "%s txq",
458 device_get_nameunit(ha->pci_dev));
460 callout_init(&ha->tx_callout, TRUE);
461 ha->flags.qla_callout_init = 1;
463 /* create ioctl device interface */
464 if (ql_make_cdev(ha)) {
465 device_printf(dev, "%s: ql_make_cdev failed\n", __func__);
466 goto qla_pci_attach_err;
469 callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS,
472 TASK_INIT(&ha->err_task, 0, qla_error_recovery, ha);
473 ha->err_tq = taskqueue_create_fast("qla_errq", M_NOWAIT,
474 taskqueue_thread_enqueue, &ha->err_tq);
475 taskqueue_start_threads(&ha->err_tq, 1, PI_NET, "%s errq",
476 device_get_nameunit(ha->pci_dev));
478 TASK_INIT(&ha->async_event_task, 0, qla_async_event, ha);
479 ha->async_event_tq = taskqueue_create_fast("qla_asyncq", M_NOWAIT,
480 taskqueue_thread_enqueue, &ha->async_event_tq);
481 taskqueue_start_threads(&ha->async_event_tq, 1, PI_NET, "%s asyncq",
482 device_get_nameunit(ha->pci_dev));
484 QL_DPRINT2(ha, (dev, "%s: exit 0\n", __func__));
491 QL_DPRINT2(ha, (dev, "%s: exit ENXIO\n", __func__));
496 * Name: qla_pci_detach
497 * Function: Unhooks the device from the operating system
500 qla_pci_detach(device_t dev)
502 qla_host_t *ha = NULL;
505 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
507 if ((ha = device_get_softc(dev)) == NULL) {
508 device_printf(dev, "cannot get softc\n");
514 (void)QLA_LOCK(ha, __func__, 0);
516 QLA_UNLOCK(ha, __func__);
520 QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
526 * SYSCTL Related Callbacks
529 qla_sysctl_get_stats(SYSCTL_HANDLER_ARGS)
534 err = sysctl_handle_int(oidp, &ret, 0, req);
536 if (err || !req->newptr)
540 ha = (qla_host_t *)arg1;
546 qla_sysctl_get_link_status(SYSCTL_HANDLER_ARGS)
551 err = sysctl_handle_int(oidp, &ret, 0, req);
553 if (err || !req->newptr)
557 ha = (qla_host_t *)arg1;
558 ql_hw_link_status(ha);
565 * Function: Releases the resources allocated for the device
568 qla_release(qla_host_t *ha)
575 if (ha->async_event_tq) {
576 taskqueue_drain(ha->async_event_tq, &ha->async_event_task);
577 taskqueue_free(ha->async_event_tq);
581 taskqueue_drain(ha->err_tq, &ha->err_task);
582 taskqueue_free(ha->err_tq);
586 taskqueue_drain(ha->tx_tq, &ha->tx_task);
587 taskqueue_free(ha->tx_tq);
592 if (ha->flags.qla_watchdog_active) {
593 ha->flags.qla_watchdog_exit = 1;
595 while (ha->qla_watchdog_exited == 0)
596 qla_mdelay(__func__, 1);
599 if (ha->flags.qla_callout_init)
600 callout_stop(&ha->tx_callout);
603 ether_ifdetach(ha->ifp);
606 qla_free_parent_dma_tag(ha);
609 (void)bus_teardown_intr(dev, ha->mbx_irq, ha->mbx_handle);
612 (void) bus_release_resource(dev, SYS_RES_IRQ, ha->mbx_irq_rid,
615 for (i = 0; i < ha->hw.num_sds_rings; i++) {
617 if (ha->irq_vec[i].handle) {
618 (void)bus_teardown_intr(dev, ha->irq_vec[i].irq,
619 ha->irq_vec[i].handle);
622 if (ha->irq_vec[i].irq) {
623 (void)bus_release_resource(dev, SYS_RES_IRQ,
624 ha->irq_vec[i].irq_rid,
630 pci_release_msi(dev);
632 if (ha->flags.lock_init) {
633 mtx_destroy(&ha->tx_lock);
634 mtx_destroy(&ha->hw_lock);
638 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid,
642 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid1,
647 * DMA Related Functions
651 qla_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
653 *((bus_addr_t *)arg) = 0;
656 printf("%s: bus_dmamap_load failed (%d)\n", __func__, error);
660 *((bus_addr_t *)arg) = segs[0].ds_addr;
666 ql_alloc_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf)
674 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
676 ret = bus_dma_tag_create(
677 ha->parent_tag,/* parent */
679 ((bus_size_t)(1ULL << 32)),/* boundary */
680 BUS_SPACE_MAXADDR, /* lowaddr */
681 BUS_SPACE_MAXADDR, /* highaddr */
682 NULL, NULL, /* filter, filterarg */
683 dma_buf->size, /* maxsize */
685 dma_buf->size, /* maxsegsize */
687 NULL, NULL, /* lockfunc, lockarg */
691 device_printf(dev, "%s: could not create dma tag\n", __func__);
692 goto ql_alloc_dmabuf_exit;
694 ret = bus_dmamem_alloc(dma_buf->dma_tag,
695 (void **)&dma_buf->dma_b,
696 (BUS_DMA_ZERO | BUS_DMA_COHERENT | BUS_DMA_NOWAIT),
699 bus_dma_tag_destroy(dma_buf->dma_tag);
700 device_printf(dev, "%s: bus_dmamem_alloc failed\n", __func__);
701 goto ql_alloc_dmabuf_exit;
704 ret = bus_dmamap_load(dma_buf->dma_tag,
709 &b_addr, BUS_DMA_NOWAIT);
711 if (ret || !b_addr) {
712 bus_dma_tag_destroy(dma_buf->dma_tag);
713 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b,
716 goto ql_alloc_dmabuf_exit;
719 dma_buf->dma_addr = b_addr;
721 ql_alloc_dmabuf_exit:
722 QL_DPRINT2(ha, (dev, "%s: exit ret 0x%08x tag %p map %p b %p sz 0x%x\n",
723 __func__, ret, (void *)dma_buf->dma_tag,
724 (void *)dma_buf->dma_map, (void *)dma_buf->dma_b,
731 ql_free_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf)
733 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b, dma_buf->dma_map);
734 bus_dma_tag_destroy(dma_buf->dma_tag);
738 qla_alloc_parent_dma_tag(qla_host_t *ha)
746 * Allocate parent DMA Tag
748 ret = bus_dma_tag_create(
749 bus_get_dma_tag(dev), /* parent */
750 1,((bus_size_t)(1ULL << 32)),/* alignment, boundary */
751 BUS_SPACE_MAXADDR, /* lowaddr */
752 BUS_SPACE_MAXADDR, /* highaddr */
753 NULL, NULL, /* filter, filterarg */
754 BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
756 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
758 NULL, NULL, /* lockfunc, lockarg */
762 device_printf(dev, "%s: could not create parent dma tag\n",
767 ha->flags.parent_tag = 1;
773 qla_free_parent_dma_tag(qla_host_t *ha)
775 if (ha->flags.parent_tag) {
776 bus_dma_tag_destroy(ha->parent_tag);
777 ha->flags.parent_tag = 0;
782 * Name: qla_init_ifnet
783 * Function: Creates the Network Device Interface and Registers it with the O.S
787 qla_init_ifnet(device_t dev, qla_host_t *ha)
791 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
793 ifp = ha->ifp = if_alloc(IFT_ETHER);
796 panic("%s: cannot if_alloc()\n", device_get_nameunit(dev));
798 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
800 ifp->if_baudrate = IF_Gbps(10);
801 ifp->if_capabilities = IFCAP_LINKSTATE;
802 ifp->if_mtu = ETHERMTU;
804 ifp->if_init = qla_init;
806 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
807 ifp->if_ioctl = qla_ioctl;
808 ifp->if_start = qla_start;
810 IFQ_SET_MAXLEN(&ifp->if_snd, qla_get_ifq_snd_maxlen(ha));
811 ifp->if_snd.ifq_drv_maxlen = qla_get_ifq_snd_maxlen(ha);
812 IFQ_SET_READY(&ifp->if_snd);
814 ha->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
816 ether_ifattach(ifp, qla_get_mac_addr(ha));
818 ifp->if_capabilities = IFCAP_HWCSUM |
822 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
823 ifp->if_capabilities |= IFCAP_VLAN_HWTSO;
825 ifp->if_capenable = ifp->if_capabilities;
827 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
829 ifmedia_init(&ha->media, IFM_IMASK, qla_media_change, qla_media_status);
831 ifmedia_add(&ha->media, (IFM_ETHER | qla_get_optics(ha) | IFM_FDX), 0,
833 ifmedia_add(&ha->media, (IFM_ETHER | IFM_AUTO), 0, NULL);
835 ifmedia_set(&ha->media, (IFM_ETHER | IFM_AUTO));
837 QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
843 qla_init_locked(qla_host_t *ha)
845 struct ifnet *ifp = ha->ifp;
849 if (qla_alloc_xmt_bufs(ha) != 0)
852 qla_confirm_9kb_enable(ha);
854 if (qla_alloc_rcv_bufs(ha) != 0)
857 bcopy(IF_LLADDR(ha->ifp), ha->hw.mac_addr, ETHER_ADDR_LEN);
859 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_TSO;
861 ha->flags.stop_rcv = 0;
862 if (ql_init_hw_if(ha) == 0) {
864 ifp->if_drv_flags |= IFF_DRV_RUNNING;
865 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
866 ha->flags.qla_watchdog_pause = 0;
867 ha->hw_vlan_tx_frames = 0;
868 ha->tx_tso_frames = 0;
869 ha->flags.qla_interface_up = 1;
880 ha = (qla_host_t *)arg;
882 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
884 (void)QLA_LOCK(ha, __func__, 0);
886 QLA_UNLOCK(ha, __func__);
888 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
892 qla_set_multi(qla_host_t *ha, uint32_t add_multi)
894 uint8_t mta[Q8_MAX_NUM_MULTICAST_ADDRS * Q8_MAC_ADDR_LEN];
895 struct ifmultiaddr *ifma;
897 struct ifnet *ifp = ha->ifp;
902 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
904 if (ifma->ifma_addr->sa_family != AF_LINK)
907 if (mcnt == Q8_MAX_NUM_MULTICAST_ADDRS)
910 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
911 &mta[mcnt * Q8_MAC_ADDR_LEN], Q8_MAC_ADDR_LEN);
916 if_maddr_runlock(ifp);
918 if (QLA_LOCK(ha, __func__, 1) == 0) {
919 ret = ql_hw_set_multi(ha, mta, mcnt, add_multi);
920 QLA_UNLOCK(ha, __func__);
927 qla_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
930 struct ifreq *ifr = (struct ifreq *)data;
931 struct ifaddr *ifa = (struct ifaddr *)data;
934 ha = (qla_host_t *)ifp->if_softc;
938 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFADDR (0x%lx)\n",
941 if (ifa->ifa_addr->sa_family == AF_INET) {
942 ifp->if_flags |= IFF_UP;
943 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
944 (void)QLA_LOCK(ha, __func__, 0);
946 QLA_UNLOCK(ha, __func__);
948 QL_DPRINT4(ha, (ha->pci_dev,
949 "%s: SIOCSIFADDR (0x%lx) ipv4 [0x%08x]\n",
951 ntohl(IA_SIN(ifa)->sin_addr.s_addr)));
953 arp_ifinit(ifp, ifa);
955 ether_ioctl(ifp, cmd, data);
960 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFMTU (0x%lx)\n",
963 if (ifr->ifr_mtu > QLA_MAX_MTU) {
966 (void) QLA_LOCK(ha, __func__, 0);
967 ifp->if_mtu = ifr->ifr_mtu;
969 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
970 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
971 ret = ql_set_max_mtu(ha, ha->max_frame_size,
972 ha->hw.rcv_cntxt_id);
975 if (ifp->if_mtu > ETHERMTU)
976 ha->std_replenish = QL_JUMBO_REPLENISH_THRES;
978 ha->std_replenish = QL_STD_REPLENISH_THRES;
981 QLA_UNLOCK(ha, __func__);
990 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFFLAGS (0x%lx)\n",
993 (void)QLA_LOCK(ha, __func__, 0);
995 if (ifp->if_flags & IFF_UP) {
996 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
997 if ((ifp->if_flags ^ ha->if_flags) &
999 ret = ql_set_promisc(ha);
1000 } else if ((ifp->if_flags ^ ha->if_flags) &
1002 ret = ql_set_allmulti(ha);
1005 qla_init_locked(ha);
1006 ha->max_frame_size = ifp->if_mtu +
1007 ETHER_HDR_LEN + ETHER_CRC_LEN;
1008 ret = ql_set_max_mtu(ha, ha->max_frame_size,
1009 ha->hw.rcv_cntxt_id);
1012 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1014 ha->if_flags = ifp->if_flags;
1017 QLA_UNLOCK(ha, __func__);
1021 QL_DPRINT4(ha, (ha->pci_dev,
1022 "%s: %s (0x%lx)\n", __func__, "SIOCADDMULTI", cmd));
1024 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1025 if (qla_set_multi(ha, 1))
1031 QL_DPRINT4(ha, (ha->pci_dev,
1032 "%s: %s (0x%lx)\n", __func__, "SIOCDELMULTI", cmd));
1034 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1035 if (qla_set_multi(ha, 0))
1042 QL_DPRINT4(ha, (ha->pci_dev,
1043 "%s: SIOCSIFMEDIA/SIOCGIFMEDIA (0x%lx)\n",
1045 ret = ifmedia_ioctl(ifp, ifr, &ha->media, cmd);
1050 int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1052 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFCAP (0x%lx)\n",
1055 if (mask & IFCAP_HWCSUM)
1056 ifp->if_capenable ^= IFCAP_HWCSUM;
1057 if (mask & IFCAP_TSO4)
1058 ifp->if_capenable ^= IFCAP_TSO4;
1059 if (mask & IFCAP_VLAN_HWTAGGING)
1060 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1061 if (mask & IFCAP_VLAN_HWTSO)
1062 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1064 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
1067 VLAN_CAPABILITIES(ifp);
1072 QL_DPRINT4(ha, (ha->pci_dev, "%s: default (0x%lx)\n",
1074 ret = ether_ioctl(ifp, cmd, data);
1082 qla_media_change(struct ifnet *ifp)
1085 struct ifmedia *ifm;
1088 ha = (qla_host_t *)ifp->if_softc;
1090 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1094 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1097 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1103 qla_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
1107 ha = (qla_host_t *)ifp->if_softc;
1109 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1111 ifmr->ifm_status = IFM_AVALID;
1112 ifmr->ifm_active = IFM_ETHER;
1114 ql_update_link_state(ha);
1115 if (ha->hw.link_up) {
1116 ifmr->ifm_status |= IFM_ACTIVE;
1117 ifmr->ifm_active |= (IFM_FDX | qla_get_optics(ha));
1120 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit (%s)\n", __func__,\
1121 (ha->hw.link_up ? "link_up" : "link_down")));
1127 qla_start(struct ifnet *ifp)
1129 struct mbuf *m_head;
1130 qla_host_t *ha = (qla_host_t *)ifp->if_softc;
1132 QL_DPRINT8(ha, (ha->pci_dev, "%s: enter\n", __func__));
1134 if (!mtx_trylock(&ha->tx_lock)) {
1135 QL_DPRINT8(ha, (ha->pci_dev,
1136 "%s: mtx_trylock(&ha->tx_lock) failed\n", __func__));
1140 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
1143 (ha->pci_dev, "%s: !IFF_DRV_RUNNING\n", __func__));
1148 if (!ha->hw.link_up || !ha->watchdog_ticks)
1149 ql_update_link_state(ha);
1151 if (!ha->hw.link_up) {
1152 QL_DPRINT8(ha, (ha->pci_dev, "%s: link down\n", __func__));
1157 while (ifp->if_snd.ifq_head != NULL) {
1158 IF_DEQUEUE(&ifp->if_snd, m_head);
1160 if (m_head == NULL) {
1161 QL_DPRINT8(ha, (ha->pci_dev, "%s: m_head == NULL\n",
1166 if (qla_send(ha, &m_head)) {
1169 QL_DPRINT8(ha, (ha->pci_dev, "%s: PREPEND\n", __func__));
1170 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1171 IF_PREPEND(&ifp->if_snd, m_head);
1174 /* Send a copy of the frame to the BPF listener */
1175 ETHER_BPF_MTAP(ifp, m_head);
1178 QL_DPRINT8(ha, (ha->pci_dev, "%s: exit\n", __func__));
1183 qla_send(qla_host_t *ha, struct mbuf **m_headp)
1185 bus_dma_segment_t segs[QLA_MAX_SEGMENTS];
1190 struct mbuf *m_head = *m_headp;
1191 uint32_t txr_idx = ha->txr_idx;
1192 uint32_t iscsi_pdu = 0;
1194 QL_DPRINT8(ha, (ha->pci_dev, "%s: enter\n", __func__));
1196 /* check if flowid is set */
1198 if (M_HASHTYPE_GET(m_head) != M_HASHTYPE_NONE) {
1199 #ifdef QL_ENABLE_ISCSI_TLV
1200 if (qla_iscsi_pdu(ha, m_head) == 0) {
1202 txr_idx = m_head->m_pkthdr.flowid &
1203 ((ha->hw.num_tx_rings >> 1) - 1);
1205 txr_idx = m_head->m_pkthdr.flowid &
1206 (ha->hw.num_tx_rings - 1);
1209 txr_idx = m_head->m_pkthdr.flowid & (ha->hw.num_tx_rings - 1);
1210 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
1214 tx_idx = ha->hw.tx_cntxt[txr_idx].txr_next;
1215 map = ha->tx_ring[txr_idx].tx_buf[tx_idx].map;
1217 ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head, segs, &nsegs,
1224 QL_DPRINT8(ha, (ha->pci_dev, "%s: EFBIG [%d]\n", __func__,
1225 m_head->m_pkthdr.len));
1227 m = m_defrag(m_head, M_NOWAIT);
1229 ha->err_tx_defrag++;
1232 device_printf(ha->pci_dev,
1233 "%s: m_defrag() = NULL [%d]\n",
1240 if ((ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head,
1241 segs, &nsegs, BUS_DMA_NOWAIT))) {
1243 ha->err_tx_dmamap_load++;
1245 device_printf(ha->pci_dev,
1246 "%s: bus_dmamap_load_mbuf_sg failed0[%d, %d]\n",
1247 __func__, ret, m_head->m_pkthdr.len);
1249 if (ret != ENOMEM) {
1258 ha->err_tx_dmamap_load++;
1260 device_printf(ha->pci_dev,
1261 "%s: bus_dmamap_load_mbuf_sg failed1[%d, %d]\n",
1262 __func__, ret, m_head->m_pkthdr.len);
1264 if (ret != ENOMEM) {
1271 QL_ASSERT(ha, (nsegs != 0), ("qla_send: empty packet"));
1273 bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_PREWRITE);
1275 if (!(ret = ql_hw_send(ha, segs, nsegs, tx_idx, m_head, txr_idx,
1277 ha->tx_ring[txr_idx].count++;
1278 ha->tx_ring[txr_idx].tx_buf[tx_idx].m_head = m_head;
1280 if (ret == EINVAL) {
1287 QL_DPRINT8(ha, (ha->pci_dev, "%s: exit\n", __func__));
1292 qla_stop(qla_host_t *ha)
1294 struct ifnet *ifp = ha->ifp;
1299 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
1300 QLA_TX_LOCK(ha); QLA_TX_UNLOCK(ha);
1302 ha->flags.qla_watchdog_pause = 1;
1304 while (!ha->qla_watchdog_paused)
1305 qla_mdelay(__func__, 1);
1307 ha->flags.qla_interface_up = 0;
1313 qla_free_xmt_bufs(ha);
1314 qla_free_rcv_bufs(ha);
1320 * Buffer Management Functions for Transmit and Receive Rings
1323 qla_alloc_xmt_bufs(qla_host_t *ha)
1329 if (bus_dma_tag_create(NULL, /* parent */
1330 1, 0, /* alignment, bounds */
1331 BUS_SPACE_MAXADDR, /* lowaddr */
1332 BUS_SPACE_MAXADDR, /* highaddr */
1333 NULL, NULL, /* filter, filterarg */
1334 QLA_MAX_TSO_FRAME_SIZE, /* maxsize */
1335 QLA_MAX_SEGMENTS, /* nsegments */
1336 PAGE_SIZE, /* maxsegsize */
1337 BUS_DMA_ALLOCNOW, /* flags */
1338 NULL, /* lockfunc */
1339 NULL, /* lockfuncarg */
1341 device_printf(ha->pci_dev, "%s: tx_tag alloc failed\n",
1346 for (i = 0; i < ha->hw.num_tx_rings; i++) {
1347 bzero((void *)ha->tx_ring[i].tx_buf,
1348 (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS));
1351 for (j = 0; j < ha->hw.num_tx_rings; j++) {
1352 for (i = 0; i < NUM_TX_DESCRIPTORS; i++) {
1354 txb = &ha->tx_ring[j].tx_buf[i];
1356 if ((ret = bus_dmamap_create(ha->tx_tag,
1357 BUS_DMA_NOWAIT, &txb->map))) {
1359 ha->err_tx_dmamap_create++;
1360 device_printf(ha->pci_dev,
1361 "%s: bus_dmamap_create failed[%d]\n",
1364 qla_free_xmt_bufs(ha);
1375 * Release mbuf after it sent on the wire
1378 qla_clear_tx_buf(qla_host_t *ha, qla_tx_buf_t *txb)
1380 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1382 if (txb->m_head && txb->map) {
1384 bus_dmamap_unload(ha->tx_tag, txb->map);
1386 m_freem(txb->m_head);
1391 bus_dmamap_destroy(ha->tx_tag, txb->map);
1393 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1397 qla_free_xmt_bufs(qla_host_t *ha)
1401 for (j = 0; j < ha->hw.num_tx_rings; j++) {
1402 for (i = 0; i < NUM_TX_DESCRIPTORS; i++)
1403 qla_clear_tx_buf(ha, &ha->tx_ring[j].tx_buf[i]);
1406 if (ha->tx_tag != NULL) {
1407 bus_dma_tag_destroy(ha->tx_tag);
1411 for (i = 0; i < ha->hw.num_tx_rings; i++) {
1412 bzero((void *)ha->tx_ring[i].tx_buf,
1413 (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS));
1420 qla_alloc_rcv_std(qla_host_t *ha)
1422 int i, j, k, r, ret = 0;
1424 qla_rx_ring_t *rx_ring;
1426 for (r = 0; r < ha->hw.num_rds_rings; r++) {
1428 rx_ring = &ha->rx_ring[r];
1430 for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1432 rxb = &rx_ring->rx_buf[i];
1434 ret = bus_dmamap_create(ha->rx_tag, BUS_DMA_NOWAIT,
1438 device_printf(ha->pci_dev,
1439 "%s: dmamap[%d, %d] failed\n",
1442 for (k = 0; k < r; k++) {
1443 for (j = 0; j < NUM_RX_DESCRIPTORS;
1445 rxb = &ha->rx_ring[k].rx_buf[j];
1446 bus_dmamap_destroy(ha->rx_tag,
1451 for (j = 0; j < i; j++) {
1452 bus_dmamap_destroy(ha->rx_tag,
1453 rx_ring->rx_buf[j].map);
1455 goto qla_alloc_rcv_std_err;
1460 qla_init_hw_rcv_descriptors(ha);
1463 for (r = 0; r < ha->hw.num_rds_rings; r++) {
1465 rx_ring = &ha->rx_ring[r];
1467 for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1468 rxb = &rx_ring->rx_buf[i];
1470 if (!(ret = ql_get_mbuf(ha, rxb, NULL))) {
1472 * set the physical address in the
1473 * corresponding descriptor entry in the
1474 * receive ring/queue for the hba
1476 qla_set_hw_rcv_desc(ha, r, i, rxb->handle,
1478 (rxb->m_head)->m_pkthdr.len);
1480 device_printf(ha->pci_dev,
1481 "%s: ql_get_mbuf [%d, %d] failed\n",
1483 bus_dmamap_destroy(ha->rx_tag, rxb->map);
1484 goto qla_alloc_rcv_std_err;
1490 qla_alloc_rcv_std_err:
1495 qla_free_rcv_std(qla_host_t *ha)
1500 for (r = 0; r < ha->hw.num_rds_rings; r++) {
1501 for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1502 rxb = &ha->rx_ring[r].rx_buf[i];
1503 if (rxb->m_head != NULL) {
1504 bus_dmamap_unload(ha->rx_tag, rxb->map);
1505 bus_dmamap_destroy(ha->rx_tag, rxb->map);
1506 m_freem(rxb->m_head);
1515 qla_alloc_rcv_bufs(qla_host_t *ha)
1519 if (bus_dma_tag_create(NULL, /* parent */
1520 1, 0, /* alignment, bounds */
1521 BUS_SPACE_MAXADDR, /* lowaddr */
1522 BUS_SPACE_MAXADDR, /* highaddr */
1523 NULL, NULL, /* filter, filterarg */
1524 MJUM9BYTES, /* maxsize */
1526 MJUM9BYTES, /* maxsegsize */
1527 BUS_DMA_ALLOCNOW, /* flags */
1528 NULL, /* lockfunc */
1529 NULL, /* lockfuncarg */
1532 device_printf(ha->pci_dev, "%s: rx_tag alloc failed\n",
1538 bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS));
1540 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1541 ha->hw.sds[i].sdsr_next = 0;
1542 ha->hw.sds[i].rxb_free = NULL;
1543 ha->hw.sds[i].rx_free = 0;
1546 ret = qla_alloc_rcv_std(ha);
1552 qla_free_rcv_bufs(qla_host_t *ha)
1556 qla_free_rcv_std(ha);
1558 if (ha->rx_tag != NULL) {
1559 bus_dma_tag_destroy(ha->rx_tag);
1563 bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS));
1565 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1566 ha->hw.sds[i].sdsr_next = 0;
1567 ha->hw.sds[i].rxb_free = NULL;
1568 ha->hw.sds[i].rx_free = 0;
1575 ql_get_mbuf(qla_host_t *ha, qla_rx_buf_t *rxb, struct mbuf *nmp)
1577 register struct mbuf *mp = nmp;
1581 bus_dma_segment_t segs[1];
1582 int nsegs, mbuf_size;
1584 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1588 if (ha->hw.enable_9kb)
1589 mbuf_size = MJUM9BYTES;
1591 mbuf_size = MCLBYTES;
1595 if (ha->hw.enable_9kb)
1596 mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, mbuf_size);
1598 mp = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
1603 device_printf(ha->pci_dev,
1604 "%s: m_getcl failed\n", __func__);
1605 goto exit_ql_get_mbuf;
1607 mp->m_len = mp->m_pkthdr.len = mbuf_size;
1609 mp->m_len = mp->m_pkthdr.len = mbuf_size;
1610 mp->m_data = mp->m_ext.ext_buf;
1614 offset = (uint32_t)((unsigned long long)mp->m_data & 0x7ULL);
1616 offset = 8 - offset;
1621 * Using memory from the mbuf cluster pool, invoke the bus_dma
1622 * machinery to arrange the memory mapping.
1624 ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, rxb->map,
1625 mp, segs, &nsegs, BUS_DMA_NOWAIT);
1626 rxb->paddr = segs[0].ds_addr;
1628 if (ret || !rxb->paddr || (nsegs != 1)) {
1631 device_printf(ha->pci_dev,
1632 "%s: bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
1633 __func__, ret, (long long unsigned int)rxb->paddr,
1636 goto exit_ql_get_mbuf;
1639 bus_dmamap_sync(ha->rx_tag, rxb->map, BUS_DMASYNC_PREREAD);
1642 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = 0x%08x\n", __func__, ret));
1647 qla_tx_done(void *context, int pending)
1649 qla_host_t *ha = context;
1657 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
1658 QL_DPRINT8(ha, (ha->pci_dev, "%s: !IFF_DRV_RUNNING\n", __func__));
1667 qla_get_peer(qla_host_t *ha)
1671 int my_slot = pci_get_slot(ha->pci_dev);
1673 if (device_get_children(device_get_parent(ha->pci_dev), &peers, &count))
1676 for (i = 0; i < count; i++) {
1677 slot = pci_get_slot(peers[i]);
1679 if ((slot >= 0) && (slot == my_slot) &&
1680 (pci_get_device(peers[i]) ==
1681 pci_get_device(ha->pci_dev))) {
1682 if (ha->pci_dev != peers[i])
1683 ha->peer_dev = peers[i];
1689 qla_send_msg_to_peer(qla_host_t *ha, uint32_t msg_to_peer)
1691 qla_host_t *ha_peer;
1694 if ((ha_peer = device_get_softc(ha->peer_dev)) != NULL) {
1696 ha_peer->msg_from_peer = msg_to_peer;
1702 qla_error_recovery(void *context, int pending)
1704 qla_host_t *ha = context;
1705 uint32_t msecs_100 = 100;
1706 struct ifnet *ifp = ha->ifp;
1708 (void)QLA_LOCK(ha, __func__, 0);
1710 if (ha->flags.qla_interface_up) {
1712 ha->hw.imd_compl = 1;
1713 qla_mdelay(__func__, 300);
1717 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
1718 QLA_TX_LOCK(ha); QLA_TX_UNLOCK(ha);
1721 QLA_UNLOCK(ha, __func__);
1723 if ((ha->pci_func & 0x1) == 0) {
1725 if (!ha->msg_from_peer) {
1726 qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET);
1728 while ((ha->msg_from_peer != QL_PEER_MSG_ACK) &&
1730 qla_mdelay(__func__, 100);
1733 ha->msg_from_peer = 0;
1735 (void)QLA_LOCK(ha, __func__, 0);
1737 QLA_UNLOCK(ha, __func__);
1739 (void) ql_init_hw(ha);
1741 (void)QLA_LOCK(ha, __func__, 0);
1742 if (ha->flags.qla_interface_up) {
1743 qla_free_xmt_bufs(ha);
1744 qla_free_rcv_bufs(ha);
1746 QLA_UNLOCK(ha, __func__);
1748 qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK);
1751 if (ha->msg_from_peer == QL_PEER_MSG_RESET) {
1753 ha->msg_from_peer = 0;
1755 qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK);
1757 qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET);
1760 while ((ha->msg_from_peer != QL_PEER_MSG_ACK) && msecs_100--)
1761 qla_mdelay(__func__, 100);
1762 ha->msg_from_peer = 0;
1764 (void) ql_init_hw(ha);
1766 (void)QLA_LOCK(ha, __func__, 0);
1767 if (ha->flags.qla_interface_up) {
1768 qla_free_xmt_bufs(ha);
1769 qla_free_rcv_bufs(ha);
1771 QLA_UNLOCK(ha, __func__);
1774 (void)QLA_LOCK(ha, __func__, 0);
1776 if (ha->flags.qla_interface_up) {
1777 if (qla_alloc_xmt_bufs(ha) != 0) {
1778 QLA_UNLOCK(ha, __func__);
1781 qla_confirm_9kb_enable(ha);
1783 if (qla_alloc_rcv_bufs(ha) != 0) {
1784 QLA_UNLOCK(ha, __func__);
1788 ha->flags.stop_rcv = 0;
1789 if (ql_init_hw_if(ha) == 0) {
1791 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1792 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1793 ha->flags.qla_watchdog_pause = 0;
1796 ha->flags.qla_watchdog_pause = 0;
1798 QLA_UNLOCK(ha, __func__);
1802 qla_async_event(void *context, int pending)
1804 qla_host_t *ha = context;
1806 (void)QLA_LOCK(ha, __func__, 0);
1807 qla_hw_async_event(ha);
1808 QLA_UNLOCK(ha, __func__);