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);
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;
272 ha->qla_watchdog_paused = 1;
275 ha->watchdog_ticks = ha->watchdog_ticks++ % 1000;
276 callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS,
281 * Name: qla_pci_attach
282 * Function: attaches the device to the operating system
285 qla_pci_attach(device_t dev)
287 qla_host_t *ha = NULL;
290 uint32_t num_rcvq = 0;
292 if ((ha = device_get_softc(dev)) == NULL) {
293 device_printf(dev, "cannot get softc\n");
297 memset(ha, 0, sizeof (qla_host_t));
299 if (pci_get_device(dev) != PCI_PRODUCT_QLOGIC_ISP8030) {
300 device_printf(dev, "device is not ISP8030\n");
304 ha->pci_func = pci_get_function(dev);
308 pci_enable_busmaster(dev);
310 ha->reg_rid = PCIR_BAR(0);
311 ha->pci_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &ha->reg_rid,
314 if (ha->pci_reg == NULL) {
315 device_printf(dev, "unable to map any ports\n");
316 goto qla_pci_attach_err;
319 rsrc_len = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
322 mtx_init(&ha->hw_lock, "qla83xx_hw_lock", MTX_NETWORK_LOCK, MTX_DEF);
324 mtx_init(&ha->tx_lock, "qla83xx_tx_lock", MTX_NETWORK_LOCK, MTX_DEF);
327 ql_hw_add_sysctls(ha);
329 ha->flags.lock_init = 1;
331 ha->reg_rid1 = PCIR_BAR(2);
332 ha->pci_reg1 = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
333 &ha->reg_rid1, RF_ACTIVE);
335 ha->msix_count = pci_msix_count(dev);
337 if (ha->msix_count < (ha->hw.num_sds_rings + 1)) {
338 device_printf(dev, "%s: msix_count[%d] not enough\n", __func__,
340 goto qla_pci_attach_err;
343 QL_DPRINT2(ha, (dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x"
344 " msix_count 0x%x pci_reg %p\n", __func__, ha,
345 ha->pci_func, rsrc_len, ha->msix_count, ha->pci_reg));
347 /* initialize hardware */
348 if (ql_init_hw(ha)) {
349 device_printf(dev, "%s: ql_init_hw failed\n", __func__);
350 goto qla_pci_attach_err;
353 device_printf(dev, "%s: firmware[%d.%d.%d.%d]\n", __func__,
354 ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub,
356 snprintf(ha->fw_ver_str, sizeof(ha->fw_ver_str), "%d.%d.%d.%d",
357 ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub,
360 if (qla_get_nic_partition(ha, NULL, &num_rcvq)) {
361 device_printf(dev, "%s: qla_get_nic_partition failed\n",
363 goto qla_pci_attach_err;
365 device_printf(dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x"
366 " msix_count 0x%x pci_reg %p num_rcvq = %d\n", __func__, ha,
367 ha->pci_func, rsrc_len, ha->msix_count, ha->pci_reg, num_rcvq);
370 #ifdef QL_ENABLE_ISCSI_TLV
371 if ((ha->msix_count < 64) || (num_rcvq != 32)) {
372 ha->hw.num_sds_rings = 15;
373 ha->hw.num_tx_rings = 32;
375 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
376 ha->hw.num_rds_rings = ha->hw.num_sds_rings;
378 ha->msix_count = ha->hw.num_sds_rings + 1;
380 if (pci_alloc_msix(dev, &ha->msix_count)) {
381 device_printf(dev, "%s: pci_alloc_msi[%d] failed\n", __func__,
384 goto qla_pci_attach_err;
388 ha->mbx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
390 (RF_ACTIVE | RF_SHAREABLE));
391 if (ha->mbx_irq == NULL) {
392 device_printf(dev, "could not allocate mbx interrupt\n");
393 goto qla_pci_attach_err;
395 if (bus_setup_intr(dev, ha->mbx_irq, (INTR_TYPE_NET | INTR_MPSAFE),
396 NULL, ql_mbx_isr, ha, &ha->mbx_handle)) {
397 device_printf(dev, "could not setup mbx interrupt\n");
398 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 /* create the o.s ethernet interface */
444 qla_init_ifnet(dev, ha);
446 ha->flags.qla_watchdog_active = 1;
447 ha->flags.qla_watchdog_pause = 1;
450 TASK_INIT(&ha->tx_task, 0, qla_tx_done, ha);
451 ha->tx_tq = taskqueue_create_fast("qla_txq", M_NOWAIT,
452 taskqueue_thread_enqueue, &ha->tx_tq);
453 taskqueue_start_threads(&ha->tx_tq, 1, PI_NET, "%s txq",
454 device_get_nameunit(ha->pci_dev));
456 callout_init(&ha->tx_callout, 1);
457 ha->flags.qla_callout_init = 1;
459 /* create ioctl device interface */
460 if (ql_make_cdev(ha)) {
461 device_printf(dev, "%s: ql_make_cdev failed\n", __func__);
462 goto qla_pci_attach_err;
465 callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS,
468 TASK_INIT(&ha->err_task, 0, qla_error_recovery, ha);
469 ha->err_tq = taskqueue_create_fast("qla_errq", M_NOWAIT,
470 taskqueue_thread_enqueue, &ha->err_tq);
471 taskqueue_start_threads(&ha->err_tq, 1, PI_NET, "%s errq",
472 device_get_nameunit(ha->pci_dev));
474 TASK_INIT(&ha->async_event_task, 0, qla_async_event, ha);
475 ha->async_event_tq = taskqueue_create_fast("qla_asyncq", M_NOWAIT,
476 taskqueue_thread_enqueue, &ha->async_event_tq);
477 taskqueue_start_threads(&ha->async_event_tq, 1, PI_NET, "%s asyncq",
478 device_get_nameunit(ha->pci_dev));
480 QL_DPRINT2(ha, (dev, "%s: exit 0\n", __func__));
487 QL_DPRINT2(ha, (dev, "%s: exit ENXIO\n", __func__));
492 * Name: qla_pci_detach
493 * Function: Unhooks the device from the operating system
496 qla_pci_detach(device_t dev)
498 qla_host_t *ha = NULL;
501 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
503 if ((ha = device_get_softc(dev)) == NULL) {
504 device_printf(dev, "cannot get softc\n");
510 (void)QLA_LOCK(ha, __func__, 0);
512 QLA_UNLOCK(ha, __func__);
516 QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
522 * SYSCTL Related Callbacks
525 qla_sysctl_get_stats(SYSCTL_HANDLER_ARGS)
530 err = sysctl_handle_int(oidp, &ret, 0, req);
532 if (err || !req->newptr)
536 ha = (qla_host_t *)arg1;
542 qla_sysctl_get_link_status(SYSCTL_HANDLER_ARGS)
547 err = sysctl_handle_int(oidp, &ret, 0, req);
549 if (err || !req->newptr)
553 ha = (qla_host_t *)arg1;
554 ql_hw_link_status(ha);
561 * Function: Releases the resources allocated for the device
564 qla_release(qla_host_t *ha)
571 if (ha->async_event_tq) {
572 taskqueue_drain(ha->async_event_tq, &ha->async_event_task);
573 taskqueue_free(ha->async_event_tq);
577 taskqueue_drain(ha->err_tq, &ha->err_task);
578 taskqueue_free(ha->err_tq);
582 taskqueue_drain(ha->tx_tq, &ha->tx_task);
583 taskqueue_free(ha->tx_tq);
588 if (ha->flags.qla_watchdog_active) {
589 ha->flags.qla_watchdog_exit = 1;
591 while (ha->qla_watchdog_exited == 0)
592 qla_mdelay(__func__, 1);
595 if (ha->flags.qla_callout_init)
596 callout_stop(&ha->tx_callout);
599 ether_ifdetach(ha->ifp);
602 qla_free_parent_dma_tag(ha);
605 (void)bus_teardown_intr(dev, ha->mbx_irq, ha->mbx_handle);
608 (void) bus_release_resource(dev, SYS_RES_IRQ, ha->mbx_irq_rid,
611 for (i = 0; i < ha->hw.num_sds_rings; i++) {
613 if (ha->irq_vec[i].handle) {
614 (void)bus_teardown_intr(dev, ha->irq_vec[i].irq,
615 ha->irq_vec[i].handle);
618 if (ha->irq_vec[i].irq) {
619 (void)bus_release_resource(dev, SYS_RES_IRQ,
620 ha->irq_vec[i].irq_rid,
626 pci_release_msi(dev);
628 if (ha->flags.lock_init) {
629 mtx_destroy(&ha->tx_lock);
630 mtx_destroy(&ha->hw_lock);
634 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid,
638 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid1,
643 * DMA Related Functions
647 qla_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
649 *((bus_addr_t *)arg) = 0;
652 printf("%s: bus_dmamap_load failed (%d)\n", __func__, error);
656 *((bus_addr_t *)arg) = segs[0].ds_addr;
662 ql_alloc_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf)
670 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
672 ret = bus_dma_tag_create(
673 ha->parent_tag,/* parent */
675 ((bus_size_t)(1ULL << 32)),/* boundary */
676 BUS_SPACE_MAXADDR, /* lowaddr */
677 BUS_SPACE_MAXADDR, /* highaddr */
678 NULL, NULL, /* filter, filterarg */
679 dma_buf->size, /* maxsize */
681 dma_buf->size, /* maxsegsize */
683 NULL, NULL, /* lockfunc, lockarg */
687 device_printf(dev, "%s: could not create dma tag\n", __func__);
688 goto ql_alloc_dmabuf_exit;
690 ret = bus_dmamem_alloc(dma_buf->dma_tag,
691 (void **)&dma_buf->dma_b,
692 (BUS_DMA_ZERO | BUS_DMA_COHERENT | BUS_DMA_NOWAIT),
695 bus_dma_tag_destroy(dma_buf->dma_tag);
696 device_printf(dev, "%s: bus_dmamem_alloc failed\n", __func__);
697 goto ql_alloc_dmabuf_exit;
700 ret = bus_dmamap_load(dma_buf->dma_tag,
705 &b_addr, BUS_DMA_NOWAIT);
707 if (ret || !b_addr) {
708 bus_dma_tag_destroy(dma_buf->dma_tag);
709 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b,
712 goto ql_alloc_dmabuf_exit;
715 dma_buf->dma_addr = b_addr;
717 ql_alloc_dmabuf_exit:
718 QL_DPRINT2(ha, (dev, "%s: exit ret 0x%08x tag %p map %p b %p sz 0x%x\n",
719 __func__, ret, (void *)dma_buf->dma_tag,
720 (void *)dma_buf->dma_map, (void *)dma_buf->dma_b,
727 ql_free_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf)
729 bus_dmamap_unload(dma_buf->dma_tag, dma_buf->dma_map);
730 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b, dma_buf->dma_map);
731 bus_dma_tag_destroy(dma_buf->dma_tag);
735 qla_alloc_parent_dma_tag(qla_host_t *ha)
743 * Allocate parent DMA Tag
745 ret = bus_dma_tag_create(
746 bus_get_dma_tag(dev), /* parent */
747 1,((bus_size_t)(1ULL << 32)),/* alignment, boundary */
748 BUS_SPACE_MAXADDR, /* lowaddr */
749 BUS_SPACE_MAXADDR, /* highaddr */
750 NULL, NULL, /* filter, filterarg */
751 BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
753 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
755 NULL, NULL, /* lockfunc, lockarg */
759 device_printf(dev, "%s: could not create parent dma tag\n",
764 ha->flags.parent_tag = 1;
770 qla_free_parent_dma_tag(qla_host_t *ha)
772 if (ha->flags.parent_tag) {
773 bus_dma_tag_destroy(ha->parent_tag);
774 ha->flags.parent_tag = 0;
779 * Name: qla_init_ifnet
780 * Function: Creates the Network Device Interface and Registers it with the O.S
784 qla_init_ifnet(device_t dev, qla_host_t *ha)
788 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
790 ifp = ha->ifp = if_alloc(IFT_ETHER);
793 panic("%s: cannot if_alloc()\n", device_get_nameunit(dev));
795 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
797 ifp->if_baudrate = IF_Gbps(10);
798 ifp->if_capabilities = IFCAP_LINKSTATE;
800 ifp->if_init = qla_init;
802 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
803 ifp->if_ioctl = qla_ioctl;
804 ifp->if_start = qla_start;
806 IFQ_SET_MAXLEN(&ifp->if_snd, qla_get_ifq_snd_maxlen(ha));
807 ifp->if_snd.ifq_drv_maxlen = qla_get_ifq_snd_maxlen(ha);
808 IFQ_SET_READY(&ifp->if_snd);
810 ha->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
812 ether_ifattach(ifp, qla_get_mac_addr(ha));
814 ifp->if_capabilities = IFCAP_HWCSUM |
818 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
819 ifp->if_capabilities |= IFCAP_VLAN_HWTSO;
821 ifp->if_capenable = ifp->if_capabilities;
823 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
825 ifmedia_init(&ha->media, IFM_IMASK, qla_media_change, qla_media_status);
827 ifmedia_add(&ha->media, (IFM_ETHER | qla_get_optics(ha) | IFM_FDX), 0,
829 ifmedia_add(&ha->media, (IFM_ETHER | IFM_AUTO), 0, NULL);
831 ifmedia_set(&ha->media, (IFM_ETHER | IFM_AUTO));
833 QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
839 qla_init_locked(qla_host_t *ha)
841 struct ifnet *ifp = ha->ifp;
845 if (qla_alloc_xmt_bufs(ha) != 0)
848 qla_confirm_9kb_enable(ha);
850 if (qla_alloc_rcv_bufs(ha) != 0)
853 bcopy(IF_LLADDR(ha->ifp), ha->hw.mac_addr, ETHER_ADDR_LEN);
855 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_TSO;
857 ha->flags.stop_rcv = 0;
858 if (ql_init_hw_if(ha) == 0) {
860 ifp->if_drv_flags |= IFF_DRV_RUNNING;
861 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
862 ha->flags.qla_watchdog_pause = 0;
863 ha->hw_vlan_tx_frames = 0;
864 ha->tx_tso_frames = 0;
875 ha = (qla_host_t *)arg;
877 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
879 (void)QLA_LOCK(ha, __func__, 0);
881 QLA_UNLOCK(ha, __func__);
883 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
887 qla_set_multi(qla_host_t *ha, uint32_t add_multi)
889 uint8_t mta[Q8_MAX_NUM_MULTICAST_ADDRS * Q8_MAC_ADDR_LEN];
890 struct ifmultiaddr *ifma;
892 struct ifnet *ifp = ha->ifp;
897 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
899 if (ifma->ifma_addr->sa_family != AF_LINK)
902 if (mcnt == Q8_MAX_NUM_MULTICAST_ADDRS)
905 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
906 &mta[mcnt * Q8_MAC_ADDR_LEN], Q8_MAC_ADDR_LEN);
911 if_maddr_runlock(ifp);
913 if (QLA_LOCK(ha, __func__, 1) == 0) {
914 ret = ql_hw_set_multi(ha, mta, mcnt, add_multi);
915 QLA_UNLOCK(ha, __func__);
922 qla_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
925 struct ifreq *ifr = (struct ifreq *)data;
926 struct ifaddr *ifa = (struct ifaddr *)data;
929 ha = (qla_host_t *)ifp->if_softc;
933 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFADDR (0x%lx)\n",
936 if (ifa->ifa_addr->sa_family == AF_INET) {
937 ifp->if_flags |= IFF_UP;
938 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
939 (void)QLA_LOCK(ha, __func__, 0);
941 QLA_UNLOCK(ha, __func__);
943 QL_DPRINT4(ha, (ha->pci_dev,
944 "%s: SIOCSIFADDR (0x%lx) ipv4 [0x%08x]\n",
946 ntohl(IA_SIN(ifa)->sin_addr.s_addr)));
948 arp_ifinit(ifp, ifa);
950 ether_ioctl(ifp, cmd, data);
955 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFMTU (0x%lx)\n",
958 if (ifr->ifr_mtu > QLA_MAX_MTU) {
961 (void) QLA_LOCK(ha, __func__, 0);
962 ifp->if_mtu = ifr->ifr_mtu;
964 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
965 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
966 ret = ql_set_max_mtu(ha, ha->max_frame_size,
967 ha->hw.rcv_cntxt_id);
970 if (ifp->if_mtu > ETHERMTU)
971 ha->std_replenish = QL_JUMBO_REPLENISH_THRES;
973 ha->std_replenish = QL_STD_REPLENISH_THRES;
976 QLA_UNLOCK(ha, __func__);
985 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFFLAGS (0x%lx)\n",
988 (void)QLA_LOCK(ha, __func__, 0);
990 if (ifp->if_flags & IFF_UP) {
991 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
992 if ((ifp->if_flags ^ ha->if_flags) &
994 ret = ql_set_promisc(ha);
995 } else if ((ifp->if_flags ^ ha->if_flags) &
997 ret = ql_set_allmulti(ha);
1000 qla_init_locked(ha);
1001 ha->max_frame_size = ifp->if_mtu +
1002 ETHER_HDR_LEN + ETHER_CRC_LEN;
1003 ret = ql_set_max_mtu(ha, ha->max_frame_size,
1004 ha->hw.rcv_cntxt_id);
1007 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1009 ha->if_flags = ifp->if_flags;
1012 QLA_UNLOCK(ha, __func__);
1016 QL_DPRINT4(ha, (ha->pci_dev,
1017 "%s: %s (0x%lx)\n", __func__, "SIOCADDMULTI", cmd));
1019 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1020 if (qla_set_multi(ha, 1))
1026 QL_DPRINT4(ha, (ha->pci_dev,
1027 "%s: %s (0x%lx)\n", __func__, "SIOCDELMULTI", cmd));
1029 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1030 if (qla_set_multi(ha, 0))
1037 QL_DPRINT4(ha, (ha->pci_dev,
1038 "%s: SIOCSIFMEDIA/SIOCGIFMEDIA (0x%lx)\n",
1040 ret = ifmedia_ioctl(ifp, ifr, &ha->media, cmd);
1045 int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1047 QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFCAP (0x%lx)\n",
1050 if (mask & IFCAP_HWCSUM)
1051 ifp->if_capenable ^= IFCAP_HWCSUM;
1052 if (mask & IFCAP_TSO4)
1053 ifp->if_capenable ^= IFCAP_TSO4;
1054 if (mask & IFCAP_VLAN_HWTAGGING)
1055 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1056 if (mask & IFCAP_VLAN_HWTSO)
1057 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1059 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
1062 VLAN_CAPABILITIES(ifp);
1067 QL_DPRINT4(ha, (ha->pci_dev, "%s: default (0x%lx)\n",
1069 ret = ether_ioctl(ifp, cmd, data);
1077 qla_media_change(struct ifnet *ifp)
1080 struct ifmedia *ifm;
1083 ha = (qla_host_t *)ifp->if_softc;
1085 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1089 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1092 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1098 qla_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
1102 ha = (qla_host_t *)ifp->if_softc;
1104 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1106 ifmr->ifm_status = IFM_AVALID;
1107 ifmr->ifm_active = IFM_ETHER;
1109 ql_update_link_state(ha);
1110 if (ha->hw.link_up) {
1111 ifmr->ifm_status |= IFM_ACTIVE;
1112 ifmr->ifm_active |= (IFM_FDX | qla_get_optics(ha));
1115 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit (%s)\n", __func__,\
1116 (ha->hw.link_up ? "link_up" : "link_down")));
1122 qla_start(struct ifnet *ifp)
1124 struct mbuf *m_head;
1125 qla_host_t *ha = (qla_host_t *)ifp->if_softc;
1127 QL_DPRINT8(ha, (ha->pci_dev, "%s: enter\n", __func__));
1129 if (!mtx_trylock(&ha->tx_lock)) {
1130 QL_DPRINT8(ha, (ha->pci_dev,
1131 "%s: mtx_trylock(&ha->tx_lock) failed\n", __func__));
1135 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
1138 (ha->pci_dev, "%s: !IFF_DRV_RUNNING\n", __func__));
1143 if (!ha->hw.link_up || !ha->watchdog_ticks)
1144 ql_update_link_state(ha);
1146 if (!ha->hw.link_up) {
1147 QL_DPRINT8(ha, (ha->pci_dev, "%s: link down\n", __func__));
1152 while (ifp->if_snd.ifq_head != NULL) {
1153 IF_DEQUEUE(&ifp->if_snd, m_head);
1155 if (m_head == NULL) {
1156 QL_DPRINT8(ha, (ha->pci_dev, "%s: m_head == NULL\n",
1161 if (qla_send(ha, &m_head)) {
1164 QL_DPRINT8(ha, (ha->pci_dev, "%s: PREPEND\n", __func__));
1165 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1166 IF_PREPEND(&ifp->if_snd, m_head);
1169 /* Send a copy of the frame to the BPF listener */
1170 ETHER_BPF_MTAP(ifp, m_head);
1173 QL_DPRINT8(ha, (ha->pci_dev, "%s: exit\n", __func__));
1178 qla_send(qla_host_t *ha, struct mbuf **m_headp)
1180 bus_dma_segment_t segs[QLA_MAX_SEGMENTS];
1185 struct mbuf *m_head = *m_headp;
1186 uint32_t txr_idx = ha->txr_idx;
1187 uint32_t iscsi_pdu = 0;
1189 QL_DPRINT8(ha, (ha->pci_dev, "%s: enter\n", __func__));
1191 /* check if flowid is set */
1193 if (M_HASHTYPE_GET(m_head) != M_HASHTYPE_NONE) {
1194 #ifdef QL_ENABLE_ISCSI_TLV
1195 if (qla_iscsi_pdu(ha, m_head) == 0) {
1197 txr_idx = m_head->m_pkthdr.flowid &
1198 ((ha->hw.num_tx_rings >> 1) - 1);
1200 txr_idx = m_head->m_pkthdr.flowid &
1201 (ha->hw.num_tx_rings - 1);
1204 txr_idx = m_head->m_pkthdr.flowid & (ha->hw.num_tx_rings - 1);
1205 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
1209 tx_idx = ha->hw.tx_cntxt[txr_idx].txr_next;
1210 map = ha->tx_ring[txr_idx].tx_buf[tx_idx].map;
1212 ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head, segs, &nsegs,
1219 QL_DPRINT8(ha, (ha->pci_dev, "%s: EFBIG [%d]\n", __func__,
1220 m_head->m_pkthdr.len));
1222 m = m_defrag(m_head, M_NOWAIT);
1224 ha->err_tx_defrag++;
1227 device_printf(ha->pci_dev,
1228 "%s: m_defrag() = NULL [%d]\n",
1235 if ((ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head,
1236 segs, &nsegs, BUS_DMA_NOWAIT))) {
1238 ha->err_tx_dmamap_load++;
1240 device_printf(ha->pci_dev,
1241 "%s: bus_dmamap_load_mbuf_sg failed0[%d, %d]\n",
1242 __func__, ret, m_head->m_pkthdr.len);
1244 if (ret != ENOMEM) {
1253 ha->err_tx_dmamap_load++;
1255 device_printf(ha->pci_dev,
1256 "%s: bus_dmamap_load_mbuf_sg failed1[%d, %d]\n",
1257 __func__, ret, m_head->m_pkthdr.len);
1259 if (ret != ENOMEM) {
1266 QL_ASSERT(ha, (nsegs != 0), ("qla_send: empty packet"));
1268 bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_PREWRITE);
1270 if (!(ret = ql_hw_send(ha, segs, nsegs, tx_idx, m_head, txr_idx,
1272 ha->tx_ring[txr_idx].count++;
1273 ha->tx_ring[txr_idx].tx_buf[tx_idx].m_head = m_head;
1275 if (ret == EINVAL) {
1282 QL_DPRINT8(ha, (ha->pci_dev, "%s: exit\n", __func__));
1287 qla_stop(qla_host_t *ha)
1289 struct ifnet *ifp = ha->ifp;
1294 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
1296 ha->flags.qla_watchdog_pause = 1;
1298 while (!ha->qla_watchdog_paused)
1299 qla_mdelay(__func__, 1);
1301 ha->flags.stop_rcv = 1;
1306 qla_free_xmt_bufs(ha);
1307 qla_free_rcv_bufs(ha);
1313 * Buffer Management Functions for Transmit and Receive Rings
1316 qla_alloc_xmt_bufs(qla_host_t *ha)
1322 if (bus_dma_tag_create(NULL, /* parent */
1323 1, 0, /* alignment, bounds */
1324 BUS_SPACE_MAXADDR, /* lowaddr */
1325 BUS_SPACE_MAXADDR, /* highaddr */
1326 NULL, NULL, /* filter, filterarg */
1327 QLA_MAX_TSO_FRAME_SIZE, /* maxsize */
1328 QLA_MAX_SEGMENTS, /* nsegments */
1329 PAGE_SIZE, /* maxsegsize */
1330 BUS_DMA_ALLOCNOW, /* flags */
1331 NULL, /* lockfunc */
1332 NULL, /* lockfuncarg */
1334 device_printf(ha->pci_dev, "%s: tx_tag alloc failed\n",
1339 for (i = 0; i < ha->hw.num_tx_rings; i++) {
1340 bzero((void *)ha->tx_ring[i].tx_buf,
1341 (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS));
1344 for (j = 0; j < ha->hw.num_tx_rings; j++) {
1345 for (i = 0; i < NUM_TX_DESCRIPTORS; i++) {
1347 txb = &ha->tx_ring[j].tx_buf[i];
1349 if ((ret = bus_dmamap_create(ha->tx_tag,
1350 BUS_DMA_NOWAIT, &txb->map))) {
1352 ha->err_tx_dmamap_create++;
1353 device_printf(ha->pci_dev,
1354 "%s: bus_dmamap_create failed[%d]\n",
1357 qla_free_xmt_bufs(ha);
1368 * Release mbuf after it sent on the wire
1371 qla_clear_tx_buf(qla_host_t *ha, qla_tx_buf_t *txb)
1373 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1375 if (txb->m_head && txb->map) {
1377 bus_dmamap_unload(ha->tx_tag, txb->map);
1379 m_freem(txb->m_head);
1384 bus_dmamap_destroy(ha->tx_tag, txb->map);
1386 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1390 qla_free_xmt_bufs(qla_host_t *ha)
1394 for (j = 0; j < ha->hw.num_tx_rings; j++) {
1395 for (i = 0; i < NUM_TX_DESCRIPTORS; i++)
1396 qla_clear_tx_buf(ha, &ha->tx_ring[j].tx_buf[i]);
1399 if (ha->tx_tag != NULL) {
1400 bus_dma_tag_destroy(ha->tx_tag);
1404 for (i = 0; i < ha->hw.num_tx_rings; i++) {
1405 bzero((void *)ha->tx_ring[i].tx_buf,
1406 (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS));
1413 qla_alloc_rcv_std(qla_host_t *ha)
1415 int i, j, k, r, ret = 0;
1417 qla_rx_ring_t *rx_ring;
1419 for (r = 0; r < ha->hw.num_rds_rings; r++) {
1421 rx_ring = &ha->rx_ring[r];
1423 for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1425 rxb = &rx_ring->rx_buf[i];
1427 ret = bus_dmamap_create(ha->rx_tag, BUS_DMA_NOWAIT,
1431 device_printf(ha->pci_dev,
1432 "%s: dmamap[%d, %d] failed\n",
1435 for (k = 0; k < r; k++) {
1436 for (j = 0; j < NUM_RX_DESCRIPTORS;
1438 rxb = &ha->rx_ring[k].rx_buf[j];
1439 bus_dmamap_destroy(ha->rx_tag,
1444 for (j = 0; j < i; j++) {
1445 bus_dmamap_destroy(ha->rx_tag,
1446 rx_ring->rx_buf[j].map);
1448 goto qla_alloc_rcv_std_err;
1453 qla_init_hw_rcv_descriptors(ha);
1456 for (r = 0; r < ha->hw.num_rds_rings; r++) {
1458 rx_ring = &ha->rx_ring[r];
1460 for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1461 rxb = &rx_ring->rx_buf[i];
1463 if (!(ret = ql_get_mbuf(ha, rxb, NULL))) {
1465 * set the physical address in the
1466 * corresponding descriptor entry in the
1467 * receive ring/queue for the hba
1469 qla_set_hw_rcv_desc(ha, r, i, rxb->handle,
1471 (rxb->m_head)->m_pkthdr.len);
1473 device_printf(ha->pci_dev,
1474 "%s: ql_get_mbuf [%d, %d] failed\n",
1476 bus_dmamap_destroy(ha->rx_tag, rxb->map);
1477 goto qla_alloc_rcv_std_err;
1483 qla_alloc_rcv_std_err:
1488 qla_free_rcv_std(qla_host_t *ha)
1493 for (r = 0; r < ha->hw.num_rds_rings; r++) {
1494 for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1495 rxb = &ha->rx_ring[r].rx_buf[i];
1496 if (rxb->m_head != NULL) {
1497 bus_dmamap_unload(ha->rx_tag, rxb->map);
1498 bus_dmamap_destroy(ha->rx_tag, rxb->map);
1499 m_freem(rxb->m_head);
1508 qla_alloc_rcv_bufs(qla_host_t *ha)
1512 if (bus_dma_tag_create(NULL, /* parent */
1513 1, 0, /* alignment, bounds */
1514 BUS_SPACE_MAXADDR, /* lowaddr */
1515 BUS_SPACE_MAXADDR, /* highaddr */
1516 NULL, NULL, /* filter, filterarg */
1517 MJUM9BYTES, /* maxsize */
1519 MJUM9BYTES, /* maxsegsize */
1520 BUS_DMA_ALLOCNOW, /* flags */
1521 NULL, /* lockfunc */
1522 NULL, /* lockfuncarg */
1525 device_printf(ha->pci_dev, "%s: rx_tag alloc failed\n",
1531 bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS));
1533 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1534 ha->hw.sds[i].sdsr_next = 0;
1535 ha->hw.sds[i].rxb_free = NULL;
1536 ha->hw.sds[i].rx_free = 0;
1539 ret = qla_alloc_rcv_std(ha);
1545 qla_free_rcv_bufs(qla_host_t *ha)
1549 qla_free_rcv_std(ha);
1551 if (ha->rx_tag != NULL) {
1552 bus_dma_tag_destroy(ha->rx_tag);
1556 bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS));
1558 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1559 ha->hw.sds[i].sdsr_next = 0;
1560 ha->hw.sds[i].rxb_free = NULL;
1561 ha->hw.sds[i].rx_free = 0;
1568 ql_get_mbuf(qla_host_t *ha, qla_rx_buf_t *rxb, struct mbuf *nmp)
1570 register struct mbuf *mp = nmp;
1574 bus_dma_segment_t segs[1];
1575 int nsegs, mbuf_size;
1577 QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1581 if (ha->hw.enable_9kb)
1582 mbuf_size = MJUM9BYTES;
1584 mbuf_size = MCLBYTES;
1588 if (ha->hw.enable_9kb)
1589 mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, mbuf_size);
1591 mp = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
1596 device_printf(ha->pci_dev,
1597 "%s: m_getcl failed\n", __func__);
1598 goto exit_ql_get_mbuf;
1600 mp->m_len = mp->m_pkthdr.len = mbuf_size;
1602 mp->m_len = mp->m_pkthdr.len = mbuf_size;
1603 mp->m_data = mp->m_ext.ext_buf;
1607 offset = (uint32_t)((unsigned long long)mp->m_data & 0x7ULL);
1609 offset = 8 - offset;
1614 * Using memory from the mbuf cluster pool, invoke the bus_dma
1615 * machinery to arrange the memory mapping.
1617 ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, rxb->map,
1618 mp, segs, &nsegs, BUS_DMA_NOWAIT);
1619 rxb->paddr = segs[0].ds_addr;
1621 if (ret || !rxb->paddr || (nsegs != 1)) {
1624 device_printf(ha->pci_dev,
1625 "%s: bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
1626 __func__, ret, (long long unsigned int)rxb->paddr,
1629 goto exit_ql_get_mbuf;
1632 bus_dmamap_sync(ha->rx_tag, rxb->map, BUS_DMASYNC_PREREAD);
1635 QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = 0x%08x\n", __func__, ret));
1640 qla_tx_done(void *context, int pending)
1642 qla_host_t *ha = context;
1650 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
1651 QL_DPRINT8(ha, (ha->pci_dev, "%s: !IFF_DRV_RUNNING\n", __func__));
1660 qla_get_peer(qla_host_t *ha)
1664 int my_slot = pci_get_slot(ha->pci_dev);
1666 if (device_get_children(device_get_parent(ha->pci_dev), &peers, &count))
1669 for (i = 0; i < count; i++) {
1670 slot = pci_get_slot(peers[i]);
1672 if ((slot >= 0) && (slot == my_slot) &&
1673 (pci_get_device(peers[i]) ==
1674 pci_get_device(ha->pci_dev))) {
1675 if (ha->pci_dev != peers[i])
1676 ha->peer_dev = peers[i];
1682 qla_send_msg_to_peer(qla_host_t *ha, uint32_t msg_to_peer)
1684 qla_host_t *ha_peer;
1687 if ((ha_peer = device_get_softc(ha->peer_dev)) != NULL) {
1689 ha_peer->msg_from_peer = msg_to_peer;
1695 qla_error_recovery(void *context, int pending)
1697 qla_host_t *ha = context;
1698 uint32_t msecs_100 = 100;
1699 struct ifnet *ifp = ha->ifp;
1701 (void)QLA_LOCK(ha, __func__, 0);
1703 ha->hw.imd_compl = 1;
1704 qla_mdelay(__func__, 300);
1706 ha->flags.stop_rcv = 1;
1710 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
1712 QLA_UNLOCK(ha, __func__);
1714 if ((ha->pci_func & 0x1) == 0) {
1716 if (!ha->msg_from_peer) {
1717 qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET);
1719 while ((ha->msg_from_peer != QL_PEER_MSG_ACK) &&
1721 qla_mdelay(__func__, 100);
1724 ha->msg_from_peer = 0;
1728 (void) ql_init_hw(ha);
1729 qla_free_xmt_bufs(ha);
1730 qla_free_rcv_bufs(ha);
1732 qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK);
1735 if (ha->msg_from_peer == QL_PEER_MSG_RESET) {
1737 ha->msg_from_peer = 0;
1739 qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK);
1741 qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET);
1744 while ((ha->msg_from_peer != QL_PEER_MSG_ACK) && msecs_100--)
1745 qla_mdelay(__func__, 100);
1746 ha->msg_from_peer = 0;
1748 (void) ql_init_hw(ha);
1749 qla_free_xmt_bufs(ha);
1750 qla_free_rcv_bufs(ha);
1752 (void)QLA_LOCK(ha, __func__, 0);
1754 if (qla_alloc_xmt_bufs(ha) != 0) {
1755 QLA_UNLOCK(ha, __func__);
1758 qla_confirm_9kb_enable(ha);
1760 if (qla_alloc_rcv_bufs(ha) != 0) {
1761 QLA_UNLOCK(ha, __func__);
1765 ha->flags.stop_rcv = 0;
1766 if (ql_init_hw_if(ha) == 0) {
1768 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1769 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1770 ha->flags.qla_watchdog_pause = 0;
1773 QLA_UNLOCK(ha, __func__);
1777 qla_async_event(void *context, int pending)
1779 qla_host_t *ha = context;
1781 (void)QLA_LOCK(ha, __func__, 0);
1782 qla_hw_async_event(ha);
1783 QLA_UNLOCK(ha, __func__);