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 device_printf(ha->pci_dev,
247 "%s: taskqueue_enqueue(err_task) \n", __func__);
248 taskqueue_enqueue(ha->err_tq, &ha->err_task);
249 } else if (ha->flags.qla_interface_up) {
251 if (ha->async_event) {
253 taskqueue_enqueue(ha->async_event_tq,
254 &ha->async_event_task);
257 for (i = 0; i < ha->hw.num_tx_rings; i++) {
258 hw_tx_cntxt = &hw->tx_cntxt[i];
259 if (qla_le32_to_host(*(hw_tx_cntxt->tx_cons)) !=
260 hw_tx_cntxt->txr_comp) {
261 taskqueue_enqueue(ha->tx_tq,
267 if ((ifp->if_snd.ifq_head != NULL) && QL_RUNNING(ifp)) {
268 taskqueue_enqueue(ha->tx_tq, &ha->tx_task);
270 ha->qla_watchdog_paused = 0;
272 ha->qla_watchdog_paused = 0;
275 ha->qla_watchdog_paused = 1;
278 ha->watchdog_ticks = ha->watchdog_ticks++ % 1000;
279 callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS,
284 * Name: qla_pci_attach
285 * Function: attaches the device to the operating system
288 qla_pci_attach(device_t dev)
290 qla_host_t *ha = NULL;
293 uint32_t num_rcvq = 0;
295 if ((ha = device_get_softc(dev)) == NULL) {
296 device_printf(dev, "cannot get softc\n");
300 memset(ha, 0, sizeof (qla_host_t));
302 if (pci_get_device(dev) != PCI_PRODUCT_QLOGIC_ISP8030) {
303 device_printf(dev, "device is not ISP8030\n");
307 ha->pci_func = pci_get_function(dev) & 0x1;
311 pci_enable_busmaster(dev);
313 ha->reg_rid = PCIR_BAR(0);
314 ha->pci_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &ha->reg_rid,
317 if (ha->pci_reg == NULL) {
318 device_printf(dev, "unable to map any ports\n");
319 goto qla_pci_attach_err;
322 rsrc_len = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
325 mtx_init(&ha->hw_lock, "qla83xx_hw_lock", MTX_NETWORK_LOCK, MTX_SPIN);
327 mtx_init(&ha->tx_lock, "qla83xx_tx_lock", MTX_NETWORK_LOCK, MTX_DEF);
330 ql_hw_add_sysctls(ha);
332 ha->flags.lock_init = 1;
334 ha->reg_rid1 = PCIR_BAR(2);
335 ha->pci_reg1 = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
336 &ha->reg_rid1, RF_ACTIVE);
338 ha->msix_count = pci_msix_count(dev);
340 if (ha->msix_count < (ha->hw.num_sds_rings + 1)) {
341 device_printf(dev, "%s: msix_count[%d] not enough\n", __func__,
343 goto qla_pci_attach_err;
346 QL_DPRINT2(ha, (dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x"
347 " msix_count 0x%x pci_reg %p\n", __func__, ha,
348 ha->pci_func, rsrc_len, ha->msix_count, ha->pci_reg));
350 /* initialize hardware */
351 if (ql_init_hw(ha)) {
352 device_printf(dev, "%s: ql_init_hw failed\n", __func__);
353 goto qla_pci_attach_err;
356 device_printf(dev, "%s: firmware[%d.%d.%d.%d]\n", __func__,
357 ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub,
359 snprintf(ha->fw_ver_str, sizeof(ha->fw_ver_str), "%d.%d.%d.%d",
360 ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub,
363 if (qla_get_nic_partition(ha, NULL, &num_rcvq)) {
364 device_printf(dev, "%s: qla_get_nic_partition failed\n",
366 goto qla_pci_attach_err;
368 device_printf(dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x"
369 " msix_count 0x%x pci_reg %p num_rcvq = %d\n", __func__, ha,
370 ha->pci_func, rsrc_len, ha->msix_count, ha->pci_reg, num_rcvq);
373 #ifdef QL_ENABLE_ISCSI_TLV
374 if ((ha->msix_count < 64) || (num_rcvq != 32)) {
375 ha->hw.num_sds_rings = 15;
376 ha->hw.num_tx_rings = 32;
378 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
379 ha->hw.num_rds_rings = ha->hw.num_sds_rings;
381 ha->msix_count = ha->hw.num_sds_rings + 1;
383 if (pci_alloc_msix(dev, &ha->msix_count)) {
384 device_printf(dev, "%s: pci_alloc_msi[%d] failed\n", __func__,
387 goto qla_pci_attach_err;
391 ha->mbx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
393 (RF_ACTIVE | RF_SHAREABLE));
394 if (ha->mbx_irq == NULL) {
395 device_printf(dev, "could not allocate mbx interrupt\n");
396 goto qla_pci_attach_err;
398 if (bus_setup_intr(dev, ha->mbx_irq, (INTR_TYPE_NET | INTR_MPSAFE),
399 NULL, ql_mbx_isr, ha, &ha->mbx_handle)) {
400 device_printf(dev, "could not setup mbx interrupt\n");
401 goto qla_pci_attach_err;
404 for (i = 0; i < ha->hw.num_sds_rings; i++) {
405 ha->irq_vec[i].sds_idx = i;
406 ha->irq_vec[i].ha = ha;
407 ha->irq_vec[i].irq_rid = 2 + i;
409 ha->irq_vec[i].irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
410 &ha->irq_vec[i].irq_rid,
411 (RF_ACTIVE | RF_SHAREABLE));
413 if (ha->irq_vec[i].irq == NULL) {
414 device_printf(dev, "could not allocate interrupt\n");
415 goto qla_pci_attach_err;
417 if (bus_setup_intr(dev, ha->irq_vec[i].irq,
418 (INTR_TYPE_NET | INTR_MPSAFE),
419 NULL, ql_isr, &ha->irq_vec[i],
420 &ha->irq_vec[i].handle)) {
421 device_printf(dev, "could not setup interrupt\n");
422 goto qla_pci_attach_err;
426 printf("%s: mp__ncpus %d sds %d rds %d msi-x %d\n", __func__, mp_ncpus,
427 ha->hw.num_sds_rings, ha->hw.num_rds_rings, ha->msix_count);
429 ql_read_mac_addr(ha);
431 /* allocate parent dma tag */
432 if (qla_alloc_parent_dma_tag(ha)) {
433 device_printf(dev, "%s: qla_alloc_parent_dma_tag failed\n",
435 goto qla_pci_attach_err;
438 /* alloc all dma buffers */
439 if (ql_alloc_dma(ha)) {
440 device_printf(dev, "%s: ql_alloc_dma failed\n", __func__);
441 goto qla_pci_attach_err;
445 if (ql_minidump_init(ha) != 0) {
446 device_printf(dev, "%s: ql_minidump_init failed\n", __func__);
447 goto qla_pci_attach_err;
449 /* create the o.s ethernet interface */
450 qla_init_ifnet(dev, ha);
452 ha->flags.qla_watchdog_active = 1;
453 ha->flags.qla_watchdog_pause = 0;
456 TASK_INIT(&ha->tx_task, 0, qla_tx_done, ha);
457 ha->tx_tq = taskqueue_create("qla_txq", M_NOWAIT,
458 taskqueue_thread_enqueue, &ha->tx_tq);
459 taskqueue_start_threads(&ha->tx_tq, 1, PI_NET, "%s txq",
460 device_get_nameunit(ha->pci_dev));
462 callout_init(&ha->tx_callout, TRUE);
463 ha->flags.qla_callout_init = 1;
465 /* create ioctl device interface */
466 if (ql_make_cdev(ha)) {
467 device_printf(dev, "%s: ql_make_cdev failed\n", __func__);
468 goto qla_pci_attach_err;
471 callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS,
474 TASK_INIT(&ha->err_task, 0, qla_error_recovery, ha);
475 ha->err_tq = taskqueue_create("qla_errq", M_NOWAIT,
476 taskqueue_thread_enqueue, &ha->err_tq);
477 taskqueue_start_threads(&ha->err_tq, 1, PI_NET, "%s errq",
478 device_get_nameunit(ha->pci_dev));
480 TASK_INIT(&ha->async_event_task, 0, qla_async_event, ha);
481 ha->async_event_tq = taskqueue_create("qla_asyncq", M_NOWAIT,
482 taskqueue_thread_enqueue, &ha->async_event_tq);
483 taskqueue_start_threads(&ha->async_event_tq, 1, PI_NET, "%s asyncq",
484 device_get_nameunit(ha->pci_dev));
486 QL_DPRINT2(ha, (dev, "%s: exit 0\n", __func__));
493 QL_DPRINT2(ha, (dev, "%s: exit ENXIO\n", __func__));
498 * Name: qla_pci_detach
499 * Function: Unhooks the device from the operating system
502 qla_pci_detach(device_t dev)
504 qla_host_t *ha = NULL;
507 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
509 if ((ha = device_get_softc(dev)) == NULL) {
510 device_printf(dev, "cannot get softc\n");
516 (void)QLA_LOCK(ha, __func__, 0);
518 QLA_UNLOCK(ha, __func__);
522 QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
528 * SYSCTL Related Callbacks
531 qla_sysctl_get_stats(SYSCTL_HANDLER_ARGS)
536 err = sysctl_handle_int(oidp, &ret, 0, req);
538 if (err || !req->newptr)
542 ha = (qla_host_t *)arg1;
548 qla_sysctl_get_link_status(SYSCTL_HANDLER_ARGS)
553 err = sysctl_handle_int(oidp, &ret, 0, req);
555 if (err || !req->newptr)
559 ha = (qla_host_t *)arg1;
560 ql_hw_link_status(ha);
567 * Function: Releases the resources allocated for the device
570 qla_release(qla_host_t *ha)
577 if (ha->async_event_tq) {
578 taskqueue_drain(ha->async_event_tq, &ha->async_event_task);
579 taskqueue_free(ha->async_event_tq);
583 taskqueue_drain(ha->err_tq, &ha->err_task);
584 taskqueue_free(ha->err_tq);
588 taskqueue_drain(ha->tx_tq, &ha->tx_task);
589 taskqueue_free(ha->tx_tq);
594 if (ha->flags.qla_watchdog_active) {
595 ha->flags.qla_watchdog_exit = 1;
597 while (ha->qla_watchdog_exited == 0)
598 qla_mdelay(__func__, 1);
601 if (ha->flags.qla_callout_init)
602 callout_stop(&ha->tx_callout);
605 ether_ifdetach(ha->ifp);
608 qla_free_parent_dma_tag(ha);
611 (void)bus_teardown_intr(dev, ha->mbx_irq, ha->mbx_handle);
614 (void) bus_release_resource(dev, SYS_RES_IRQ, ha->mbx_irq_rid,
617 for (i = 0; i < ha->hw.num_sds_rings; i++) {
619 if (ha->irq_vec[i].handle) {
620 (void)bus_teardown_intr(dev, ha->irq_vec[i].irq,
621 ha->irq_vec[i].handle);
624 if (ha->irq_vec[i].irq) {
625 (void)bus_release_resource(dev, SYS_RES_IRQ,
626 ha->irq_vec[i].irq_rid,
632 pci_release_msi(dev);
634 if (ha->flags.lock_init) {
635 mtx_destroy(&ha->tx_lock);
636 mtx_destroy(&ha->hw_lock);
640 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid,
644 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid1,
649 * DMA Related Functions
653 qla_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
655 *((bus_addr_t *)arg) = 0;
658 printf("%s: bus_dmamap_load failed (%d)\n", __func__, error);
662 *((bus_addr_t *)arg) = segs[0].ds_addr;
668 ql_alloc_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf)
676 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
678 ret = bus_dma_tag_create(
679 ha->parent_tag,/* parent */
681 ((bus_size_t)(1ULL << 32)),/* boundary */
682 BUS_SPACE_MAXADDR, /* lowaddr */
683 BUS_SPACE_MAXADDR, /* highaddr */
684 NULL, NULL, /* filter, filterarg */
685 dma_buf->size, /* maxsize */
687 dma_buf->size, /* maxsegsize */
689 NULL, NULL, /* lockfunc, lockarg */
693 device_printf(dev, "%s: could not create dma tag\n", __func__);
694 goto ql_alloc_dmabuf_exit;
696 ret = bus_dmamem_alloc(dma_buf->dma_tag,
697 (void **)&dma_buf->dma_b,
698 (BUS_DMA_ZERO | BUS_DMA_COHERENT | BUS_DMA_NOWAIT),
701 bus_dma_tag_destroy(dma_buf->dma_tag);
702 device_printf(dev, "%s: bus_dmamem_alloc failed\n", __func__);
703 goto ql_alloc_dmabuf_exit;
706 ret = bus_dmamap_load(dma_buf->dma_tag,
711 &b_addr, BUS_DMA_NOWAIT);
713 if (ret || !b_addr) {
714 bus_dma_tag_destroy(dma_buf->dma_tag);
715 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b,
718 goto ql_alloc_dmabuf_exit;
721 dma_buf->dma_addr = b_addr;
723 ql_alloc_dmabuf_exit:
724 QL_DPRINT2(ha, (dev, "%s: exit ret 0x%08x tag %p map %p b %p sz 0x%x\n",
725 __func__, ret, (void *)dma_buf->dma_tag,
726 (void *)dma_buf->dma_map, (void *)dma_buf->dma_b,
733 ql_free_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf)
735 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b, dma_buf->dma_map);
736 bus_dma_tag_destroy(dma_buf->dma_tag);
740 qla_alloc_parent_dma_tag(qla_host_t *ha)
748 * Allocate parent DMA Tag
750 ret = bus_dma_tag_create(
751 bus_get_dma_tag(dev), /* parent */
752 1,((bus_size_t)(1ULL << 32)),/* alignment, boundary */
753 BUS_SPACE_MAXADDR, /* lowaddr */
754 BUS_SPACE_MAXADDR, /* highaddr */
755 NULL, NULL, /* filter, filterarg */
756 BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
758 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
760 NULL, NULL, /* lockfunc, lockarg */
764 device_printf(dev, "%s: could not create parent dma tag\n",
769 ha->flags.parent_tag = 1;
775 qla_free_parent_dma_tag(qla_host_t *ha)
777 if (ha->flags.parent_tag) {
778 bus_dma_tag_destroy(ha->parent_tag);
779 ha->flags.parent_tag = 0;
784 * Name: qla_init_ifnet
785 * Function: Creates the Network Device Interface and Registers it with the O.S
789 qla_init_ifnet(device_t dev, qla_host_t *ha)
793 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
795 ifp = ha->ifp = if_alloc(IFT_ETHER);
798 panic("%s: cannot if_alloc()\n", device_get_nameunit(dev));
800 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
802 #if __FreeBSD_version >= 1000000
803 if_initbaudrate(ifp, IF_Gbps(10));
804 ifp->if_capabilities = IFCAP_LINKSTATE;
806 ifp->if_mtu = ETHERMTU;
807 ifp->if_baudrate = (1 * 1000 * 1000 *1000);
809 #endif /* #if __FreeBSD_version >= 1000000 */
811 ifp->if_init = qla_init;
813 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
814 ifp->if_ioctl = qla_ioctl;
815 ifp->if_start = qla_start;
817 IFQ_SET_MAXLEN(&ifp->if_snd, qla_get_ifq_snd_maxlen(ha));
818 ifp->if_snd.ifq_drv_maxlen = qla_get_ifq_snd_maxlen(ha);
819 IFQ_SET_READY(&ifp->if_snd);
821 ha->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
823 ether_ifattach(ifp, qla_get_mac_addr(ha));
825 ifp->if_capabilities = IFCAP_HWCSUM |
829 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
830 ifp->if_capabilities |= IFCAP_VLAN_HWTSO;
832 ifp->if_capenable = ifp->if_capabilities;
834 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
836 ifmedia_init(&ha->media, IFM_IMASK, qla_media_change, qla_media_status);
838 ifmedia_add(&ha->media, (IFM_ETHER | qla_get_optics(ha) | IFM_FDX), 0,
840 ifmedia_add(&ha->media, (IFM_ETHER | IFM_AUTO), 0, NULL);
842 ifmedia_set(&ha->media, (IFM_ETHER | IFM_AUTO));
844 QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
850 qla_init_locked(qla_host_t *ha)
852 struct ifnet *ifp = ha->ifp;
856 if (qla_alloc_xmt_bufs(ha) != 0)
859 qla_confirm_9kb_enable(ha);
861 if (qla_alloc_rcv_bufs(ha) != 0)
864 bcopy(IF_LLADDR(ha->ifp), ha->hw.mac_addr, ETHER_ADDR_LEN);
866 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_TSO;
868 ha->flags.stop_rcv = 0;
869 if (ql_init_hw_if(ha) == 0) {
871 ifp->if_drv_flags |= IFF_DRV_RUNNING;
872 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
873 ha->flags.qla_watchdog_pause = 0;
874 ha->hw_vlan_tx_frames = 0;
875 ha->tx_tso_frames = 0;
876 ha->flags.qla_interface_up = 1;
887 ha = (qla_host_t *)arg;
889 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
891 (void)QLA_LOCK(ha, __func__, 0);
893 QLA_UNLOCK(ha, __func__);
895 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
899 qla_set_multi(qla_host_t *ha, uint32_t add_multi)
901 uint8_t mta[Q8_MAX_NUM_MULTICAST_ADDRS * Q8_MAC_ADDR_LEN];
902 struct ifmultiaddr *ifma;
904 struct ifnet *ifp = ha->ifp;
909 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
911 if (ifma->ifma_addr->sa_family != AF_LINK)
914 if (mcnt == Q8_MAX_NUM_MULTICAST_ADDRS)
917 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
918 &mta[mcnt * Q8_MAC_ADDR_LEN], Q8_MAC_ADDR_LEN);
923 if_maddr_runlock(ifp);
925 if (QLA_LOCK(ha, __func__, 1) == 0) {
926 ret = ql_hw_set_multi(ha, mta, mcnt, add_multi);
927 QLA_UNLOCK(ha, __func__);
934 qla_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
937 struct ifreq *ifr = (struct ifreq *)data;
938 struct ifaddr *ifa = (struct ifaddr *)data;
941 ha = (qla_host_t *)ifp->if_softc;
945 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFADDR (0x%lx)\n",
948 if (ifa->ifa_addr->sa_family == AF_INET) {
949 ifp->if_flags |= IFF_UP;
950 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
951 (void)QLA_LOCK(ha, __func__, 0);
953 QLA_UNLOCK(ha, __func__);
955 QL_DPRINT4(ha, (ha->pci_dev,
956 "%s: SIOCSIFADDR (0x%lx) ipv4 [0x%08x]\n",
958 ntohl(IA_SIN(ifa)->sin_addr.s_addr)));
960 arp_ifinit(ifp, ifa);
962 ether_ioctl(ifp, cmd, data);
967 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFMTU (0x%lx)\n",
970 if (ifr->ifr_mtu > QLA_MAX_MTU) {
973 (void) QLA_LOCK(ha, __func__, 0);
974 ifp->if_mtu = ifr->ifr_mtu;
976 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
977 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
978 ret = ql_set_max_mtu(ha, ha->max_frame_size,
979 ha->hw.rcv_cntxt_id);
982 if (ifp->if_mtu > ETHERMTU)
983 ha->std_replenish = QL_JUMBO_REPLENISH_THRES;
985 ha->std_replenish = QL_STD_REPLENISH_THRES;
988 QLA_UNLOCK(ha, __func__);
997 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFFLAGS (0x%lx)\n",
1000 (void)QLA_LOCK(ha, __func__, 0);
1002 if (ifp->if_flags & IFF_UP) {
1003 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
1004 if ((ifp->if_flags ^ ha->if_flags) &
1006 ret = ql_set_promisc(ha);
1007 } else if ((ifp->if_flags ^ ha->if_flags) &
1009 ret = ql_set_allmulti(ha);
1012 qla_init_locked(ha);
1013 ha->max_frame_size = ifp->if_mtu +
1014 ETHER_HDR_LEN + ETHER_CRC_LEN;
1015 ret = ql_set_max_mtu(ha, ha->max_frame_size,
1016 ha->hw.rcv_cntxt_id);
1019 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1021 ha->if_flags = ifp->if_flags;
1024 QLA_UNLOCK(ha, __func__);
1028 QL_DPRINT4(ha, (ha->pci_dev,
1029 "%s: %s (0x%lx)\n", __func__, "SIOCADDMULTI", cmd));
1031 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1032 if (qla_set_multi(ha, 1))
1038 QL_DPRINT4(ha, (ha->pci_dev,
1039 "%s: %s (0x%lx)\n", __func__, "SIOCDELMULTI", cmd));
1041 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1042 if (qla_set_multi(ha, 0))
1049 QL_DPRINT4(ha, (ha->pci_dev,
1050 "%s: SIOCSIFMEDIA/SIOCGIFMEDIA (0x%lx)\n",
1052 ret = ifmedia_ioctl(ifp, ifr, &ha->media, cmd);
1057 int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1059 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFCAP (0x%lx)\n",
1062 if (mask & IFCAP_HWCSUM)
1063 ifp->if_capenable ^= IFCAP_HWCSUM;
1064 if (mask & IFCAP_TSO4)
1065 ifp->if_capenable ^= IFCAP_TSO4;
1066 if (mask & IFCAP_VLAN_HWTAGGING)
1067 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1068 if (mask & IFCAP_VLAN_HWTSO)
1069 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1071 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
1074 VLAN_CAPABILITIES(ifp);
1079 QL_DPRINT4(ha, (ha->pci_dev, "%s: default (0x%lx)\n",
1081 ret = ether_ioctl(ifp, cmd, data);
1089 qla_media_change(struct ifnet *ifp)
1092 struct ifmedia *ifm;
1095 ha = (qla_host_t *)ifp->if_softc;
1097 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1101 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1104 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1110 qla_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
1114 ha = (qla_host_t *)ifp->if_softc;
1116 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1118 ifmr->ifm_status = IFM_AVALID;
1119 ifmr->ifm_active = IFM_ETHER;
1121 ql_update_link_state(ha);
1122 if (ha->hw.link_up) {
1123 ifmr->ifm_status |= IFM_ACTIVE;
1124 ifmr->ifm_active |= (IFM_FDX | qla_get_optics(ha));
1127 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit (%s)\n", __func__,\
1128 (ha->hw.link_up ? "link_up" : "link_down")));
1134 qla_start(struct ifnet *ifp)
1136 struct mbuf *m_head;
1137 qla_host_t *ha = (qla_host_t *)ifp->if_softc;
1139 QL_DPRINT8(ha, (ha->pci_dev, "%s: enter\n", __func__));
1141 if (!mtx_trylock(&ha->tx_lock)) {
1142 QL_DPRINT8(ha, (ha->pci_dev,
1143 "%s: mtx_trylock(&ha->tx_lock) failed\n", __func__));
1147 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
1150 (ha->pci_dev, "%s: !IFF_DRV_RUNNING\n", __func__));
1155 if (!ha->hw.link_up || !ha->watchdog_ticks)
1156 ql_update_link_state(ha);
1158 if (!ha->hw.link_up) {
1159 QL_DPRINT8(ha, (ha->pci_dev, "%s: link down\n", __func__));
1164 while (ifp->if_snd.ifq_head != NULL) {
1165 IF_DEQUEUE(&ifp->if_snd, m_head);
1167 if (m_head == NULL) {
1168 QL_DPRINT8(ha, (ha->pci_dev, "%s: m_head == NULL\n",
1173 if (qla_send(ha, &m_head)) {
1176 QL_DPRINT8(ha, (ha->pci_dev, "%s: PREPEND\n", __func__));
1177 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1178 IF_PREPEND(&ifp->if_snd, m_head);
1181 /* Send a copy of the frame to the BPF listener */
1182 ETHER_BPF_MTAP(ifp, m_head);
1185 QL_DPRINT8(ha, (ha->pci_dev, "%s: exit\n", __func__));
1190 qla_send(qla_host_t *ha, struct mbuf **m_headp)
1192 bus_dma_segment_t segs[QLA_MAX_SEGMENTS];
1197 struct mbuf *m_head = *m_headp;
1198 uint32_t txr_idx = ha->txr_idx;
1199 uint32_t iscsi_pdu = 0;
1201 QL_DPRINT8(ha, (ha->pci_dev, "%s: enter\n", __func__));
1203 if (m_head->m_flags & M_FLOWID) {
1204 #ifdef QL_ENABLE_ISCSI_TLV
1205 if (qla_iscsi_pdu(ha, m_head) == 0) {
1207 txr_idx = m_head->m_pkthdr.flowid &
1208 ((ha->hw.num_tx_rings >> 1) - 1);
1210 txr_idx = m_head->m_pkthdr.flowid &
1211 (ha->hw.num_tx_rings - 1);
1214 txr_idx = m_head->m_pkthdr.flowid & (ha->hw.num_tx_rings - 1);
1215 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
1219 tx_idx = ha->hw.tx_cntxt[txr_idx].txr_next;
1220 map = ha->tx_ring[txr_idx].tx_buf[tx_idx].map;
1222 ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head, segs, &nsegs,
1229 QL_DPRINT8(ha, (ha->pci_dev, "%s: EFBIG [%d]\n", __func__,
1230 m_head->m_pkthdr.len));
1232 m = m_defrag(m_head, M_NOWAIT);
1234 ha->err_tx_defrag++;
1237 device_printf(ha->pci_dev,
1238 "%s: m_defrag() = NULL [%d]\n",
1245 if ((ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head,
1246 segs, &nsegs, BUS_DMA_NOWAIT))) {
1248 ha->err_tx_dmamap_load++;
1250 device_printf(ha->pci_dev,
1251 "%s: bus_dmamap_load_mbuf_sg failed0[%d, %d]\n",
1252 __func__, ret, m_head->m_pkthdr.len);
1254 if (ret != ENOMEM) {
1263 ha->err_tx_dmamap_load++;
1265 device_printf(ha->pci_dev,
1266 "%s: bus_dmamap_load_mbuf_sg failed1[%d, %d]\n",
1267 __func__, ret, m_head->m_pkthdr.len);
1269 if (ret != ENOMEM) {
1276 QL_ASSERT(ha, (nsegs != 0), ("qla_send: empty packet"));
1278 bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_PREWRITE);
1280 if (!(ret = ql_hw_send(ha, segs, nsegs, tx_idx, m_head, txr_idx,
1282 ha->tx_ring[txr_idx].count++;
1283 ha->tx_ring[txr_idx].tx_buf[tx_idx].m_head = m_head;
1285 if (ret == EINVAL) {
1292 QL_DPRINT8(ha, (ha->pci_dev, "%s: exit\n", __func__));
1297 qla_stop(qla_host_t *ha)
1299 struct ifnet *ifp = ha->ifp;
1304 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
1305 QLA_TX_LOCK(ha); QLA_TX_UNLOCK(ha);
1307 ha->flags.qla_watchdog_pause = 1;
1309 while (!ha->qla_watchdog_paused)
1310 qla_mdelay(__func__, 1);
1312 ha->flags.qla_interface_up = 0;
1318 qla_free_xmt_bufs(ha);
1319 qla_free_rcv_bufs(ha);
1325 * Buffer Management Functions for Transmit and Receive Rings
1328 qla_alloc_xmt_bufs(qla_host_t *ha)
1334 if (bus_dma_tag_create(NULL, /* parent */
1335 1, 0, /* alignment, bounds */
1336 BUS_SPACE_MAXADDR, /* lowaddr */
1337 BUS_SPACE_MAXADDR, /* highaddr */
1338 NULL, NULL, /* filter, filterarg */
1339 QLA_MAX_TSO_FRAME_SIZE, /* maxsize */
1340 QLA_MAX_SEGMENTS, /* nsegments */
1341 PAGE_SIZE, /* maxsegsize */
1342 BUS_DMA_ALLOCNOW, /* flags */
1343 NULL, /* lockfunc */
1344 NULL, /* lockfuncarg */
1346 device_printf(ha->pci_dev, "%s: tx_tag alloc failed\n",
1351 for (i = 0; i < ha->hw.num_tx_rings; i++) {
1352 bzero((void *)ha->tx_ring[i].tx_buf,
1353 (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS));
1356 for (j = 0; j < ha->hw.num_tx_rings; j++) {
1357 for (i = 0; i < NUM_TX_DESCRIPTORS; i++) {
1359 txb = &ha->tx_ring[j].tx_buf[i];
1361 if ((ret = bus_dmamap_create(ha->tx_tag,
1362 BUS_DMA_NOWAIT, &txb->map))) {
1364 ha->err_tx_dmamap_create++;
1365 device_printf(ha->pci_dev,
1366 "%s: bus_dmamap_create failed[%d]\n",
1369 qla_free_xmt_bufs(ha);
1380 * Release mbuf after it sent on the wire
1383 qla_clear_tx_buf(qla_host_t *ha, qla_tx_buf_t *txb)
1385 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1387 if (txb->m_head && txb->map) {
1389 bus_dmamap_unload(ha->tx_tag, txb->map);
1391 m_freem(txb->m_head);
1396 bus_dmamap_destroy(ha->tx_tag, txb->map);
1398 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1402 qla_free_xmt_bufs(qla_host_t *ha)
1406 for (j = 0; j < ha->hw.num_tx_rings; j++) {
1407 for (i = 0; i < NUM_TX_DESCRIPTORS; i++)
1408 qla_clear_tx_buf(ha, &ha->tx_ring[j].tx_buf[i]);
1411 if (ha->tx_tag != NULL) {
1412 bus_dma_tag_destroy(ha->tx_tag);
1416 for (i = 0; i < ha->hw.num_tx_rings; i++) {
1417 bzero((void *)ha->tx_ring[i].tx_buf,
1418 (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS));
1425 qla_alloc_rcv_std(qla_host_t *ha)
1427 int i, j, k, r, ret = 0;
1429 qla_rx_ring_t *rx_ring;
1431 for (r = 0; r < ha->hw.num_rds_rings; r++) {
1433 rx_ring = &ha->rx_ring[r];
1435 for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1437 rxb = &rx_ring->rx_buf[i];
1439 ret = bus_dmamap_create(ha->rx_tag, BUS_DMA_NOWAIT,
1443 device_printf(ha->pci_dev,
1444 "%s: dmamap[%d, %d] failed\n",
1447 for (k = 0; k < r; k++) {
1448 for (j = 0; j < NUM_RX_DESCRIPTORS;
1450 rxb = &ha->rx_ring[k].rx_buf[j];
1451 bus_dmamap_destroy(ha->rx_tag,
1456 for (j = 0; j < i; j++) {
1457 bus_dmamap_destroy(ha->rx_tag,
1458 rx_ring->rx_buf[j].map);
1460 goto qla_alloc_rcv_std_err;
1465 qla_init_hw_rcv_descriptors(ha);
1468 for (r = 0; r < ha->hw.num_rds_rings; r++) {
1470 rx_ring = &ha->rx_ring[r];
1472 for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1473 rxb = &rx_ring->rx_buf[i];
1475 if (!(ret = ql_get_mbuf(ha, rxb, NULL))) {
1477 * set the physical address in the
1478 * corresponding descriptor entry in the
1479 * receive ring/queue for the hba
1481 qla_set_hw_rcv_desc(ha, r, i, rxb->handle,
1483 (rxb->m_head)->m_pkthdr.len);
1485 device_printf(ha->pci_dev,
1486 "%s: ql_get_mbuf [%d, %d] failed\n",
1488 bus_dmamap_destroy(ha->rx_tag, rxb->map);
1489 goto qla_alloc_rcv_std_err;
1495 qla_alloc_rcv_std_err:
1500 qla_free_rcv_std(qla_host_t *ha)
1505 for (r = 0; r < ha->hw.num_rds_rings; r++) {
1506 for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1507 rxb = &ha->rx_ring[r].rx_buf[i];
1508 if (rxb->m_head != NULL) {
1509 bus_dmamap_unload(ha->rx_tag, rxb->map);
1510 bus_dmamap_destroy(ha->rx_tag, rxb->map);
1511 m_freem(rxb->m_head);
1520 qla_alloc_rcv_bufs(qla_host_t *ha)
1524 if (bus_dma_tag_create(NULL, /* parent */
1525 1, 0, /* alignment, bounds */
1526 BUS_SPACE_MAXADDR, /* lowaddr */
1527 BUS_SPACE_MAXADDR, /* highaddr */
1528 NULL, NULL, /* filter, filterarg */
1529 MJUM9BYTES, /* maxsize */
1531 MJUM9BYTES, /* maxsegsize */
1532 BUS_DMA_ALLOCNOW, /* flags */
1533 NULL, /* lockfunc */
1534 NULL, /* lockfuncarg */
1537 device_printf(ha->pci_dev, "%s: rx_tag alloc failed\n",
1543 bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS));
1545 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1546 ha->hw.sds[i].sdsr_next = 0;
1547 ha->hw.sds[i].rxb_free = NULL;
1548 ha->hw.sds[i].rx_free = 0;
1551 ret = qla_alloc_rcv_std(ha);
1557 qla_free_rcv_bufs(qla_host_t *ha)
1561 qla_free_rcv_std(ha);
1563 if (ha->rx_tag != NULL) {
1564 bus_dma_tag_destroy(ha->rx_tag);
1568 bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS));
1570 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1571 ha->hw.sds[i].sdsr_next = 0;
1572 ha->hw.sds[i].rxb_free = NULL;
1573 ha->hw.sds[i].rx_free = 0;
1580 ql_get_mbuf(qla_host_t *ha, qla_rx_buf_t *rxb, struct mbuf *nmp)
1582 register struct mbuf *mp = nmp;
1586 bus_dma_segment_t segs[1];
1587 int nsegs, mbuf_size;
1589 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1593 if (ha->hw.enable_9kb)
1594 mbuf_size = MJUM9BYTES;
1596 mbuf_size = MCLBYTES;
1600 if (QL_ERR_INJECT(ha, INJCT_M_GETCL_M_GETJCL_FAILURE))
1603 if (ha->hw.enable_9kb)
1604 mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, mbuf_size);
1606 mp = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
1611 device_printf(ha->pci_dev,
1612 "%s: m_getcl failed\n", __func__);
1613 goto exit_ql_get_mbuf;
1615 mp->m_len = mp->m_pkthdr.len = mbuf_size;
1617 mp->m_len = mp->m_pkthdr.len = mbuf_size;
1618 mp->m_data = mp->m_ext.ext_buf;
1622 offset = (uint32_t)((unsigned long long)mp->m_data & 0x7ULL);
1624 offset = 8 - offset;
1629 * Using memory from the mbuf cluster pool, invoke the bus_dma
1630 * machinery to arrange the memory mapping.
1632 ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, rxb->map,
1633 mp, segs, &nsegs, BUS_DMA_NOWAIT);
1634 rxb->paddr = segs[0].ds_addr;
1636 if (ret || !rxb->paddr || (nsegs != 1)) {
1639 device_printf(ha->pci_dev,
1640 "%s: bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
1641 __func__, ret, (long long unsigned int)rxb->paddr,
1644 goto exit_ql_get_mbuf;
1647 bus_dmamap_sync(ha->rx_tag, rxb->map, BUS_DMASYNC_PREREAD);
1650 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = 0x%08x\n", __func__, ret));
1655 qla_tx_done(void *context, int pending)
1657 qla_host_t *ha = context;
1665 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
1666 QL_DPRINT8(ha, (ha->pci_dev, "%s: !IFF_DRV_RUNNING\n", __func__));
1675 qla_get_peer(qla_host_t *ha)
1679 int my_slot = pci_get_slot(ha->pci_dev);
1681 if (device_get_children(device_get_parent(ha->pci_dev), &peers, &count))
1684 for (i = 0; i < count; i++) {
1685 slot = pci_get_slot(peers[i]);
1687 if ((slot >= 0) && (slot == my_slot) &&
1688 (pci_get_device(peers[i]) ==
1689 pci_get_device(ha->pci_dev))) {
1690 if (ha->pci_dev != peers[i])
1691 ha->peer_dev = peers[i];
1697 qla_send_msg_to_peer(qla_host_t *ha, uint32_t msg_to_peer)
1699 qla_host_t *ha_peer;
1702 if ((ha_peer = device_get_softc(ha->peer_dev)) != NULL) {
1704 ha_peer->msg_from_peer = msg_to_peer;
1710 qla_error_recovery(void *context, int pending)
1712 qla_host_t *ha = context;
1713 uint32_t msecs_100 = 100;
1714 struct ifnet *ifp = ha->ifp;
1716 (void)QLA_LOCK(ha, __func__, 0);
1718 if (ha->flags.qla_interface_up) {
1720 ha->hw.imd_compl = 1;
1721 qla_mdelay(__func__, 300);
1725 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
1726 QLA_TX_LOCK(ha); QLA_TX_UNLOCK(ha);
1729 QLA_UNLOCK(ha, __func__);
1731 if ((ha->pci_func & 0x1) == 0) {
1733 if (!ha->msg_from_peer) {
1734 qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET);
1736 while ((ha->msg_from_peer != QL_PEER_MSG_ACK) &&
1738 qla_mdelay(__func__, 100);
1741 ha->msg_from_peer = 0;
1743 (void)QLA_LOCK(ha, __func__, 0);
1745 QLA_UNLOCK(ha, __func__);
1747 (void) ql_init_hw(ha);
1749 (void)QLA_LOCK(ha, __func__, 0);
1750 if (ha->flags.qla_interface_up) {
1751 qla_free_xmt_bufs(ha);
1752 qla_free_rcv_bufs(ha);
1754 QLA_UNLOCK(ha, __func__);
1756 qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK);
1759 if (ha->msg_from_peer == QL_PEER_MSG_RESET) {
1761 ha->msg_from_peer = 0;
1763 qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK);
1765 qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET);
1768 while ((ha->msg_from_peer != QL_PEER_MSG_ACK) && msecs_100--)
1769 qla_mdelay(__func__, 100);
1770 ha->msg_from_peer = 0;
1772 (void) ql_init_hw(ha);
1774 (void)QLA_LOCK(ha, __func__, 0);
1775 if (ha->flags.qla_interface_up) {
1776 qla_free_xmt_bufs(ha);
1777 qla_free_rcv_bufs(ha);
1779 QLA_UNLOCK(ha, __func__);
1782 (void)QLA_LOCK(ha, __func__, 0);
1784 if (ha->flags.qla_interface_up) {
1785 if (qla_alloc_xmt_bufs(ha) != 0) {
1786 QLA_UNLOCK(ha, __func__);
1789 qla_confirm_9kb_enable(ha);
1791 if (qla_alloc_rcv_bufs(ha) != 0) {
1792 QLA_UNLOCK(ha, __func__);
1796 ha->flags.stop_rcv = 0;
1797 if (ql_init_hw_if(ha) == 0) {
1799 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1800 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1801 ha->flags.qla_watchdog_pause = 0;
1804 ha->flags.qla_watchdog_pause = 0;
1806 QLA_UNLOCK(ha, __func__);
1810 qla_async_event(void *context, int pending)
1812 qla_host_t *ha = context;
1814 (void)QLA_LOCK(ha, __func__, 0);
1815 qla_hw_async_event(ha);
1816 QLA_UNLOCK(ha, __func__);