1f10a77bbSDavid C Somayajulu /* 235291c22SDavid C Somayajulu * Copyright (c) 2013-2016 Qlogic Corporation 3f10a77bbSDavid C Somayajulu * All rights reserved. 4f10a77bbSDavid C Somayajulu * 5f10a77bbSDavid C Somayajulu * Redistribution and use in source and binary forms, with or without 6f10a77bbSDavid C Somayajulu * modification, are permitted provided that the following conditions 7f10a77bbSDavid C Somayajulu * are met: 8f10a77bbSDavid C Somayajulu * 9f10a77bbSDavid C Somayajulu * 1. Redistributions of source code must retain the above copyright 10f10a77bbSDavid C Somayajulu * notice, this list of conditions and the following disclaimer. 11f10a77bbSDavid C Somayajulu * 2. Redistributions in binary form must reproduce the above copyright 12f10a77bbSDavid C Somayajulu * notice, this list of conditions and the following disclaimer in the 13f10a77bbSDavid C Somayajulu * documentation and/or other materials provided with the distribution. 14f10a77bbSDavid C Somayajulu * 15f10a77bbSDavid C Somayajulu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16f10a77bbSDavid C Somayajulu * and ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17f10a77bbSDavid C Somayajulu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18f10a77bbSDavid C Somayajulu * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19f10a77bbSDavid C Somayajulu * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20f10a77bbSDavid C Somayajulu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21f10a77bbSDavid C Somayajulu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22f10a77bbSDavid C Somayajulu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23f10a77bbSDavid C Somayajulu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24f10a77bbSDavid C Somayajulu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25f10a77bbSDavid C Somayajulu * POSSIBILITY OF SUCH DAMAGE. 26f10a77bbSDavid C Somayajulu */ 27f10a77bbSDavid C Somayajulu 28f10a77bbSDavid C Somayajulu /* 29f10a77bbSDavid C Somayajulu * File: ql_os.c 30f10a77bbSDavid C Somayajulu * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656. 31f10a77bbSDavid C Somayajulu */ 32f10a77bbSDavid C Somayajulu 33f10a77bbSDavid C Somayajulu #include <sys/cdefs.h> 34f10a77bbSDavid C Somayajulu __FBSDID("$FreeBSD$"); 35f10a77bbSDavid C Somayajulu 36f10a77bbSDavid C Somayajulu 37f10a77bbSDavid C Somayajulu #include "ql_os.h" 38f10a77bbSDavid C Somayajulu #include "ql_hw.h" 39f10a77bbSDavid C Somayajulu #include "ql_def.h" 40f10a77bbSDavid C Somayajulu #include "ql_inline.h" 41f10a77bbSDavid C Somayajulu #include "ql_ver.h" 42f10a77bbSDavid C Somayajulu #include "ql_glbl.h" 43f10a77bbSDavid C Somayajulu #include "ql_dbg.h" 44f10a77bbSDavid C Somayajulu #include <sys/smp.h> 45f10a77bbSDavid C Somayajulu 46f10a77bbSDavid C Somayajulu /* 47f10a77bbSDavid C Somayajulu * Some PCI Configuration Space Related Defines 48f10a77bbSDavid C Somayajulu */ 49f10a77bbSDavid C Somayajulu 50f10a77bbSDavid C Somayajulu #ifndef PCI_VENDOR_QLOGIC 51f10a77bbSDavid C Somayajulu #define PCI_VENDOR_QLOGIC 0x1077 52f10a77bbSDavid C Somayajulu #endif 53f10a77bbSDavid C Somayajulu 54f10a77bbSDavid C Somayajulu #ifndef PCI_PRODUCT_QLOGIC_ISP8030 55f10a77bbSDavid C Somayajulu #define PCI_PRODUCT_QLOGIC_ISP8030 0x8030 56f10a77bbSDavid C Somayajulu #endif 57f10a77bbSDavid C Somayajulu 58f10a77bbSDavid C Somayajulu #define PCI_QLOGIC_ISP8030 \ 59f10a77bbSDavid C Somayajulu ((PCI_PRODUCT_QLOGIC_ISP8030 << 16) | PCI_VENDOR_QLOGIC) 60f10a77bbSDavid C Somayajulu 61f10a77bbSDavid C Somayajulu /* 62f10a77bbSDavid C Somayajulu * static functions 63f10a77bbSDavid C Somayajulu */ 64f10a77bbSDavid C Somayajulu static int qla_alloc_parent_dma_tag(qla_host_t *ha); 65f10a77bbSDavid C Somayajulu static void qla_free_parent_dma_tag(qla_host_t *ha); 66f10a77bbSDavid C Somayajulu static int qla_alloc_xmt_bufs(qla_host_t *ha); 67f10a77bbSDavid C Somayajulu static void qla_free_xmt_bufs(qla_host_t *ha); 68f10a77bbSDavid C Somayajulu static int qla_alloc_rcv_bufs(qla_host_t *ha); 69f10a77bbSDavid C Somayajulu static void qla_free_rcv_bufs(qla_host_t *ha); 70f10a77bbSDavid C Somayajulu static void qla_clear_tx_buf(qla_host_t *ha, qla_tx_buf_t *txb); 71f10a77bbSDavid C Somayajulu 72f10a77bbSDavid C Somayajulu static void qla_init_ifnet(device_t dev, qla_host_t *ha); 73f10a77bbSDavid C Somayajulu static int qla_sysctl_get_link_status(SYSCTL_HANDLER_ARGS); 74f10a77bbSDavid C Somayajulu static void qla_release(qla_host_t *ha); 75f10a77bbSDavid C Somayajulu static void qla_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, 76f10a77bbSDavid C Somayajulu int error); 77f10a77bbSDavid C Somayajulu static void qla_stop(qla_host_t *ha); 78f10a77bbSDavid C Somayajulu static void qla_get_peer(qla_host_t *ha); 79f10a77bbSDavid C Somayajulu static void qla_error_recovery(void *context, int pending); 8035291c22SDavid C Somayajulu static void qla_async_event(void *context, int pending); 817fb51846SDavid C Somayajulu static void qla_stats(void *context, int pending); 82b89f2279SDavid C Somayajulu static int qla_send(qla_host_t *ha, struct mbuf **m_headp, uint32_t txr_idx, 83b89f2279SDavid C Somayajulu uint32_t iscsi_pdu); 84f10a77bbSDavid C Somayajulu 85f10a77bbSDavid C Somayajulu /* 86f10a77bbSDavid C Somayajulu * Hooks to the Operating Systems 87f10a77bbSDavid C Somayajulu */ 88f10a77bbSDavid C Somayajulu static int qla_pci_probe (device_t); 89f10a77bbSDavid C Somayajulu static int qla_pci_attach (device_t); 90f10a77bbSDavid C Somayajulu static int qla_pci_detach (device_t); 91f10a77bbSDavid C Somayajulu 92f10a77bbSDavid C Somayajulu static void qla_init(void *arg); 93f10a77bbSDavid C Somayajulu static int qla_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); 94f10a77bbSDavid C Somayajulu static int qla_media_change(struct ifnet *ifp); 95f10a77bbSDavid C Somayajulu static void qla_media_status(struct ifnet *ifp, struct ifmediareq *ifmr); 96b89f2279SDavid C Somayajulu 97b89f2279SDavid C Somayajulu static int qla_transmit(struct ifnet *ifp, struct mbuf *mp); 98b89f2279SDavid C Somayajulu static void qla_qflush(struct ifnet *ifp); 99b89f2279SDavid C Somayajulu static int qla_alloc_tx_br(qla_host_t *ha, qla_tx_fp_t *tx_fp); 100b89f2279SDavid C Somayajulu static void qla_free_tx_br(qla_host_t *ha, qla_tx_fp_t *tx_fp); 101b89f2279SDavid C Somayajulu static int qla_create_fp_taskqueues(qla_host_t *ha); 102b89f2279SDavid C Somayajulu static void qla_destroy_fp_taskqueues(qla_host_t *ha); 103b89f2279SDavid C Somayajulu static void qla_drain_fp_taskqueues(qla_host_t *ha); 104f10a77bbSDavid C Somayajulu 105f10a77bbSDavid C Somayajulu static device_method_t qla_pci_methods[] = { 106f10a77bbSDavid C Somayajulu /* Device interface */ 107f10a77bbSDavid C Somayajulu DEVMETHOD(device_probe, qla_pci_probe), 108f10a77bbSDavid C Somayajulu DEVMETHOD(device_attach, qla_pci_attach), 109f10a77bbSDavid C Somayajulu DEVMETHOD(device_detach, qla_pci_detach), 110f10a77bbSDavid C Somayajulu { 0, 0 } 111f10a77bbSDavid C Somayajulu }; 112f10a77bbSDavid C Somayajulu 113f10a77bbSDavid C Somayajulu static driver_t qla_pci_driver = { 114f10a77bbSDavid C Somayajulu "ql", qla_pci_methods, sizeof (qla_host_t), 115f10a77bbSDavid C Somayajulu }; 116f10a77bbSDavid C Somayajulu 117f10a77bbSDavid C Somayajulu static devclass_t qla83xx_devclass; 118f10a77bbSDavid C Somayajulu 119f10a77bbSDavid C Somayajulu DRIVER_MODULE(qla83xx, pci, qla_pci_driver, qla83xx_devclass, 0, 0); 120f10a77bbSDavid C Somayajulu 121f10a77bbSDavid C Somayajulu MODULE_DEPEND(qla83xx, pci, 1, 1, 1); 122f10a77bbSDavid C Somayajulu MODULE_DEPEND(qla83xx, ether, 1, 1, 1); 123f10a77bbSDavid C Somayajulu 124f10a77bbSDavid C Somayajulu MALLOC_DEFINE(M_QLA83XXBUF, "qla83xxbuf", "Buffers for qla83xx driver"); 125f10a77bbSDavid C Somayajulu 126f10a77bbSDavid C Somayajulu #define QL_STD_REPLENISH_THRES 0 127f10a77bbSDavid C Somayajulu #define QL_JUMBO_REPLENISH_THRES 32 128f10a77bbSDavid C Somayajulu 129f10a77bbSDavid C Somayajulu 130f10a77bbSDavid C Somayajulu static char dev_str[64]; 13135291c22SDavid C Somayajulu static char ver_str[64]; 132f10a77bbSDavid C Somayajulu 133f10a77bbSDavid C Somayajulu /* 134f10a77bbSDavid C Somayajulu * Name: qla_pci_probe 135f10a77bbSDavid C Somayajulu * Function: Validate the PCI device to be a QLA80XX device 136f10a77bbSDavid C Somayajulu */ 137f10a77bbSDavid C Somayajulu static int 138f10a77bbSDavid C Somayajulu qla_pci_probe(device_t dev) 139f10a77bbSDavid C Somayajulu { 140f10a77bbSDavid C Somayajulu switch ((pci_get_device(dev) << 16) | (pci_get_vendor(dev))) { 141f10a77bbSDavid C Somayajulu case PCI_QLOGIC_ISP8030: 142f10a77bbSDavid C Somayajulu snprintf(dev_str, sizeof(dev_str), "%s v%d.%d.%d", 143f10a77bbSDavid C Somayajulu "Qlogic ISP 83xx PCI CNA Adapter-Ethernet Function", 144f10a77bbSDavid C Somayajulu QLA_VERSION_MAJOR, QLA_VERSION_MINOR, 145f10a77bbSDavid C Somayajulu QLA_VERSION_BUILD); 14635291c22SDavid C Somayajulu snprintf(ver_str, sizeof(ver_str), "v%d.%d.%d", 14735291c22SDavid C Somayajulu QLA_VERSION_MAJOR, QLA_VERSION_MINOR, 14835291c22SDavid C Somayajulu QLA_VERSION_BUILD); 149f10a77bbSDavid C Somayajulu device_set_desc(dev, dev_str); 150f10a77bbSDavid C Somayajulu break; 151f10a77bbSDavid C Somayajulu default: 152f10a77bbSDavid C Somayajulu return (ENXIO); 153f10a77bbSDavid C Somayajulu } 154f10a77bbSDavid C Somayajulu 155f10a77bbSDavid C Somayajulu if (bootverbose) 156f10a77bbSDavid C Somayajulu printf("%s: %s\n ", __func__, dev_str); 157f10a77bbSDavid C Somayajulu 158f10a77bbSDavid C Somayajulu return (BUS_PROBE_DEFAULT); 159f10a77bbSDavid C Somayajulu } 160f10a77bbSDavid C Somayajulu 161f10a77bbSDavid C Somayajulu static void 162f10a77bbSDavid C Somayajulu qla_add_sysctls(qla_host_t *ha) 163f10a77bbSDavid C Somayajulu { 164f10a77bbSDavid C Somayajulu device_t dev = ha->pci_dev; 165f10a77bbSDavid C Somayajulu 16635291c22SDavid C Somayajulu SYSCTL_ADD_STRING(device_get_sysctl_ctx(dev), 16735291c22SDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 16835291c22SDavid C Somayajulu OID_AUTO, "version", CTLFLAG_RD, 16935291c22SDavid C Somayajulu ver_str, 0, "Driver Version"); 17035291c22SDavid C Somayajulu 171f10a77bbSDavid C Somayajulu SYSCTL_ADD_STRING(device_get_sysctl_ctx(dev), 172f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 173f10a77bbSDavid C Somayajulu OID_AUTO, "fw_version", CTLFLAG_RD, 174f0188618SHans Petter Selasky ha->fw_ver_str, 0, "firmware version"); 175f10a77bbSDavid C Somayajulu 176f10a77bbSDavid C Somayajulu SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 177f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 178f10a77bbSDavid C Somayajulu OID_AUTO, "link_status", CTLTYPE_INT | CTLFLAG_RW, 179f10a77bbSDavid C Somayajulu (void *)ha, 0, 180f10a77bbSDavid C Somayajulu qla_sysctl_get_link_status, "I", "Link Status"); 181f10a77bbSDavid C Somayajulu 182f10a77bbSDavid C Somayajulu ha->dbg_level = 0; 183f10a77bbSDavid C Somayajulu SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 184f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 185f10a77bbSDavid C Somayajulu OID_AUTO, "debug", CTLFLAG_RW, 186f10a77bbSDavid C Somayajulu &ha->dbg_level, ha->dbg_level, "Debug Level"); 187f10a77bbSDavid C Somayajulu 1881faeac0fSDavid C Somayajulu ha->enable_minidump = 1; 1891faeac0fSDavid C Somayajulu SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1901faeac0fSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1911faeac0fSDavid C Somayajulu OID_AUTO, "enable_minidump", CTLFLAG_RW, 1921faeac0fSDavid C Somayajulu &ha->enable_minidump, ha->enable_minidump, 1931faeac0fSDavid C Somayajulu "Minidump retrival is enabled only when this is set"); 1941faeac0fSDavid C Somayajulu 195f10a77bbSDavid C Somayajulu ha->std_replenish = QL_STD_REPLENISH_THRES; 196f10a77bbSDavid C Somayajulu SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 197f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 198f10a77bbSDavid C Somayajulu OID_AUTO, "std_replenish", CTLFLAG_RW, 199f10a77bbSDavid C Somayajulu &ha->std_replenish, ha->std_replenish, 200f10a77bbSDavid C Somayajulu "Threshold for Replenishing Standard Frames"); 201f10a77bbSDavid C Somayajulu 202f10a77bbSDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev), 203f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 204f10a77bbSDavid C Somayajulu OID_AUTO, "ipv4_lro", 205f10a77bbSDavid C Somayajulu CTLFLAG_RD, &ha->ipv4_lro, 206f10a77bbSDavid C Somayajulu "number of ipv4 lro completions"); 207f10a77bbSDavid C Somayajulu 208f10a77bbSDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev), 209f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 210f10a77bbSDavid C Somayajulu OID_AUTO, "ipv6_lro", 211f10a77bbSDavid C Somayajulu CTLFLAG_RD, &ha->ipv6_lro, 212f10a77bbSDavid C Somayajulu "number of ipv6 lro completions"); 213f10a77bbSDavid C Somayajulu 214f10a77bbSDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev), 215f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 216f10a77bbSDavid C Somayajulu OID_AUTO, "tx_tso_frames", 217f10a77bbSDavid C Somayajulu CTLFLAG_RD, &ha->tx_tso_frames, 218f10a77bbSDavid C Somayajulu "number of Tx TSO Frames"); 219f10a77bbSDavid C Somayajulu 220f10a77bbSDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev), 221f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 222f10a77bbSDavid C Somayajulu OID_AUTO, "hw_vlan_tx_frames", 223f10a77bbSDavid C Somayajulu CTLFLAG_RD, &ha->hw_vlan_tx_frames, 224f10a77bbSDavid C Somayajulu "number of Tx VLAN Frames"); 225f10a77bbSDavid C Somayajulu 2267fb51846SDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev), 2277fb51846SDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 2287fb51846SDavid C Somayajulu OID_AUTO, "hw_lock_failed", 2297fb51846SDavid C Somayajulu CTLFLAG_RD, &ha->hw_lock_failed, 2307fb51846SDavid C Somayajulu "number of hw_lock failures"); 2317fb51846SDavid C Somayajulu 232f10a77bbSDavid C Somayajulu return; 233f10a77bbSDavid C Somayajulu } 234f10a77bbSDavid C Somayajulu 235f10a77bbSDavid C Somayajulu static void 236f10a77bbSDavid C Somayajulu qla_watchdog(void *arg) 237f10a77bbSDavid C Somayajulu { 238f10a77bbSDavid C Somayajulu qla_host_t *ha = arg; 239f10a77bbSDavid C Somayajulu qla_hw_t *hw; 240f10a77bbSDavid C Somayajulu struct ifnet *ifp; 241f10a77bbSDavid C Somayajulu 242f10a77bbSDavid C Somayajulu hw = &ha->hw; 243f10a77bbSDavid C Somayajulu ifp = ha->ifp; 244f10a77bbSDavid C Somayajulu 2457fb51846SDavid C Somayajulu if (ha->qla_watchdog_exit) { 246f10a77bbSDavid C Somayajulu ha->qla_watchdog_exited = 1; 247f10a77bbSDavid C Somayajulu return; 248f10a77bbSDavid C Somayajulu } 249f10a77bbSDavid C Somayajulu ha->qla_watchdog_exited = 0; 250f10a77bbSDavid C Somayajulu 2517fb51846SDavid C Somayajulu if (!ha->qla_watchdog_pause) { 252f10a77bbSDavid C Somayajulu if (ql_hw_check_health(ha) || ha->qla_initiate_recovery || 253f10a77bbSDavid C Somayajulu (ha->msg_from_peer == QL_PEER_MSG_RESET)) { 2547fb51846SDavid C Somayajulu 2557fb51846SDavid C Somayajulu if (!(ha->dbg_level & 0x8000)) { 256f10a77bbSDavid C Somayajulu ha->qla_watchdog_paused = 1; 2577fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 1; 258f10a77bbSDavid C Somayajulu ha->qla_initiate_recovery = 0; 259f10a77bbSDavid C Somayajulu ha->err_inject = 0; 260da834d52SDavid C Somayajulu device_printf(ha->pci_dev, 2617fb51846SDavid C Somayajulu "%s: taskqueue_enqueue(err_task) \n", 2627fb51846SDavid C Somayajulu __func__); 263f10a77bbSDavid C Somayajulu taskqueue_enqueue(ha->err_tq, &ha->err_task); 2647fb51846SDavid C Somayajulu return; 2657fb51846SDavid C Somayajulu } 2667fb51846SDavid C Somayajulu 2677fb51846SDavid C Somayajulu } else if (ha->qla_interface_up) { 2687fb51846SDavid C Somayajulu 2697fb51846SDavid C Somayajulu ha->watchdog_ticks++; 2707fb51846SDavid C Somayajulu 2717fb51846SDavid C Somayajulu if (ha->watchdog_ticks > 1000) 2727fb51846SDavid C Somayajulu ha->watchdog_ticks = 0; 2737fb51846SDavid C Somayajulu 2747fb51846SDavid C Somayajulu if (!ha->watchdog_ticks && QL_RUNNING(ifp)) { 2757fb51846SDavid C Somayajulu taskqueue_enqueue(ha->stats_tq, &ha->stats_task); 2767fb51846SDavid C Somayajulu } 27735291c22SDavid C Somayajulu 27835291c22SDavid C Somayajulu if (ha->async_event) { 27935291c22SDavid C Somayajulu taskqueue_enqueue(ha->async_event_tq, 28035291c22SDavid C Somayajulu &ha->async_event_task); 28135291c22SDavid C Somayajulu } 28235291c22SDavid C Somayajulu 2837fb51846SDavid C Somayajulu #if 0 2847fb51846SDavid C Somayajulu for (i = 0; ((i < ha->hw.num_sds_rings) && 2857fb51846SDavid C Somayajulu !ha->watchdog_ticks); i++) { 286b89f2279SDavid C Somayajulu qla_tx_fp_t *fp = &ha->tx_fp[i]; 287b89f2279SDavid C Somayajulu 288b89f2279SDavid C Somayajulu if (fp->fp_taskqueue != NULL) 289b89f2279SDavid C Somayajulu taskqueue_enqueue(fp->fp_taskqueue, 290b89f2279SDavid C Somayajulu &fp->fp_task); 291f10a77bbSDavid C Somayajulu } 2927fb51846SDavid C Somayajulu #endif 293f10a77bbSDavid C Somayajulu ha->qla_watchdog_paused = 0; 2946a62bec0SDavid C Somayajulu } else { 2956a62bec0SDavid C Somayajulu ha->qla_watchdog_paused = 0; 296f10a77bbSDavid C Somayajulu } 297f10a77bbSDavid C Somayajulu } else { 298f10a77bbSDavid C Somayajulu ha->qla_watchdog_paused = 1; 299f10a77bbSDavid C Somayajulu } 300f10a77bbSDavid C Somayajulu 301f10a77bbSDavid C Somayajulu callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS, 302f10a77bbSDavid C Somayajulu qla_watchdog, ha); 303f10a77bbSDavid C Somayajulu } 304f10a77bbSDavid C Somayajulu 305f10a77bbSDavid C Somayajulu /* 306f10a77bbSDavid C Somayajulu * Name: qla_pci_attach 307f10a77bbSDavid C Somayajulu * Function: attaches the device to the operating system 308f10a77bbSDavid C Somayajulu */ 309f10a77bbSDavid C Somayajulu static int 310f10a77bbSDavid C Somayajulu qla_pci_attach(device_t dev) 311f10a77bbSDavid C Somayajulu { 312f10a77bbSDavid C Somayajulu qla_host_t *ha = NULL; 313f10a77bbSDavid C Somayajulu uint32_t rsrc_len; 314f10a77bbSDavid C Somayajulu int i; 31535291c22SDavid C Somayajulu uint32_t num_rcvq = 0; 316f10a77bbSDavid C Somayajulu 317f10a77bbSDavid C Somayajulu if ((ha = device_get_softc(dev)) == NULL) { 318f10a77bbSDavid C Somayajulu device_printf(dev, "cannot get softc\n"); 319f10a77bbSDavid C Somayajulu return (ENOMEM); 320f10a77bbSDavid C Somayajulu } 321f10a77bbSDavid C Somayajulu 322f10a77bbSDavid C Somayajulu memset(ha, 0, sizeof (qla_host_t)); 323f10a77bbSDavid C Somayajulu 324f10a77bbSDavid C Somayajulu if (pci_get_device(dev) != PCI_PRODUCT_QLOGIC_ISP8030) { 325f10a77bbSDavid C Somayajulu device_printf(dev, "device is not ISP8030\n"); 326f10a77bbSDavid C Somayajulu return (ENXIO); 327f10a77bbSDavid C Somayajulu } 328f10a77bbSDavid C Somayajulu 3296a62bec0SDavid C Somayajulu ha->pci_func = pci_get_function(dev) & 0x1; 330f10a77bbSDavid C Somayajulu 331f10a77bbSDavid C Somayajulu ha->pci_dev = dev; 332f10a77bbSDavid C Somayajulu 333f10a77bbSDavid C Somayajulu pci_enable_busmaster(dev); 334f10a77bbSDavid C Somayajulu 335f10a77bbSDavid C Somayajulu ha->reg_rid = PCIR_BAR(0); 336f10a77bbSDavid C Somayajulu ha->pci_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &ha->reg_rid, 337f10a77bbSDavid C Somayajulu RF_ACTIVE); 338f10a77bbSDavid C Somayajulu 339f10a77bbSDavid C Somayajulu if (ha->pci_reg == NULL) { 340f10a77bbSDavid C Somayajulu device_printf(dev, "unable to map any ports\n"); 341f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 342f10a77bbSDavid C Somayajulu } 343f10a77bbSDavid C Somayajulu 344f10a77bbSDavid C Somayajulu rsrc_len = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY, 345f10a77bbSDavid C Somayajulu ha->reg_rid); 346f10a77bbSDavid C Somayajulu 347b89f2279SDavid C Somayajulu mtx_init(&ha->hw_lock, "qla83xx_hw_lock", MTX_NETWORK_LOCK, MTX_DEF); 3487fb51846SDavid C Somayajulu ha->flags.lock_init = 1; 349f10a77bbSDavid C Somayajulu 350f10a77bbSDavid C Somayajulu qla_add_sysctls(ha); 351f10a77bbSDavid C Somayajulu 3527fb51846SDavid C Somayajulu ha->hw.num_sds_rings = MAX_SDS_RINGS; 3537fb51846SDavid C Somayajulu ha->hw.num_rds_rings = MAX_RDS_RINGS; 3547fb51846SDavid C Somayajulu ha->hw.num_tx_rings = NUM_TX_RINGS; 355f10a77bbSDavid C Somayajulu 356f10a77bbSDavid C Somayajulu ha->reg_rid1 = PCIR_BAR(2); 357f10a77bbSDavid C Somayajulu ha->pci_reg1 = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 358f10a77bbSDavid C Somayajulu &ha->reg_rid1, RF_ACTIVE); 359f10a77bbSDavid C Somayajulu 360f10a77bbSDavid C Somayajulu ha->msix_count = pci_msix_count(dev); 361f10a77bbSDavid C Somayajulu 3627fb51846SDavid C Somayajulu if (ha->msix_count < 1 ) { 363f10a77bbSDavid C Somayajulu device_printf(dev, "%s: msix_count[%d] not enough\n", __func__, 364f10a77bbSDavid C Somayajulu ha->msix_count); 365f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 366f10a77bbSDavid C Somayajulu } 367f10a77bbSDavid C Somayajulu 3687fb51846SDavid C Somayajulu if (ha->msix_count < (ha->hw.num_sds_rings + 1)) { 3697fb51846SDavid C Somayajulu ha->hw.num_sds_rings = ha->msix_count - 1; 3707fb51846SDavid C Somayajulu } 3717fb51846SDavid C Somayajulu 372f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x" 373b89f2279SDavid C Somayajulu " msix_count 0x%x pci_reg %p pci_reg1 %p\n", __func__, ha, 374b89f2279SDavid C Somayajulu ha->pci_func, rsrc_len, ha->msix_count, ha->pci_reg, 375b89f2279SDavid C Somayajulu ha->pci_reg1)); 376f10a77bbSDavid C Somayajulu 37735291c22SDavid C Somayajulu /* initialize hardware */ 37835291c22SDavid C Somayajulu if (ql_init_hw(ha)) { 37935291c22SDavid C Somayajulu device_printf(dev, "%s: ql_init_hw failed\n", __func__); 38035291c22SDavid C Somayajulu goto qla_pci_attach_err; 38135291c22SDavid C Somayajulu } 38235291c22SDavid C Somayajulu 38335291c22SDavid C Somayajulu device_printf(dev, "%s: firmware[%d.%d.%d.%d]\n", __func__, 38435291c22SDavid C Somayajulu ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub, 38535291c22SDavid C Somayajulu ha->fw_ver_build); 38635291c22SDavid C Somayajulu snprintf(ha->fw_ver_str, sizeof(ha->fw_ver_str), "%d.%d.%d.%d", 38735291c22SDavid C Somayajulu ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub, 38835291c22SDavid C Somayajulu ha->fw_ver_build); 38935291c22SDavid C Somayajulu 39035291c22SDavid C Somayajulu if (qla_get_nic_partition(ha, NULL, &num_rcvq)) { 39135291c22SDavid C Somayajulu device_printf(dev, "%s: qla_get_nic_partition failed\n", 39235291c22SDavid C Somayajulu __func__); 39335291c22SDavid C Somayajulu goto qla_pci_attach_err; 39435291c22SDavid C Somayajulu } 39535291c22SDavid C Somayajulu device_printf(dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x" 396b89f2279SDavid C Somayajulu " msix_count 0x%x pci_reg %p pci_reg1 %p num_rcvq = %d\n", 397b89f2279SDavid C Somayajulu __func__, ha, ha->pci_func, rsrc_len, ha->msix_count, 398b89f2279SDavid C Somayajulu ha->pci_reg, ha->pci_reg1, num_rcvq); 39935291c22SDavid C Somayajulu 4007fb51846SDavid C Somayajulu if ((ha->msix_count < 64) || (num_rcvq != 32)) { 4017fb51846SDavid C Somayajulu if (ha->hw.num_sds_rings > 15) { 4027fb51846SDavid C Somayajulu ha->hw.num_sds_rings = 15; 4037fb51846SDavid C Somayajulu } 4047fb51846SDavid C Somayajulu } 4057fb51846SDavid C Somayajulu 4067fb51846SDavid C Somayajulu ha->hw.num_rds_rings = ha->hw.num_sds_rings; 4077fb51846SDavid C Somayajulu ha->hw.num_tx_rings = ha->hw.num_sds_rings; 40835291c22SDavid C Somayajulu 40935291c22SDavid C Somayajulu #ifdef QL_ENABLE_ISCSI_TLV 410b89f2279SDavid C Somayajulu ha->hw.num_tx_rings = ha->hw.num_sds_rings * 2; 41135291c22SDavid C Somayajulu #endif /* #ifdef QL_ENABLE_ISCSI_TLV */ 4127fb51846SDavid C Somayajulu 4137fb51846SDavid C Somayajulu ql_hw_add_sysctls(ha); 41435291c22SDavid C Somayajulu 415f10a77bbSDavid C Somayajulu ha->msix_count = ha->hw.num_sds_rings + 1; 416f10a77bbSDavid C Somayajulu 417f10a77bbSDavid C Somayajulu if (pci_alloc_msix(dev, &ha->msix_count)) { 418f10a77bbSDavid C Somayajulu device_printf(dev, "%s: pci_alloc_msi[%d] failed\n", __func__, 419f10a77bbSDavid C Somayajulu ha->msix_count); 420f10a77bbSDavid C Somayajulu ha->msix_count = 0; 421f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 422f10a77bbSDavid C Somayajulu } 423f10a77bbSDavid C Somayajulu 424f10a77bbSDavid C Somayajulu ha->mbx_irq_rid = 1; 425f10a77bbSDavid C Somayajulu ha->mbx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, 426f10a77bbSDavid C Somayajulu &ha->mbx_irq_rid, 427f10a77bbSDavid C Somayajulu (RF_ACTIVE | RF_SHAREABLE)); 428f10a77bbSDavid C Somayajulu if (ha->mbx_irq == NULL) { 429f10a77bbSDavid C Somayajulu device_printf(dev, "could not allocate mbx interrupt\n"); 430f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 431f10a77bbSDavid C Somayajulu } 432f10a77bbSDavid C Somayajulu if (bus_setup_intr(dev, ha->mbx_irq, (INTR_TYPE_NET | INTR_MPSAFE), 433f10a77bbSDavid C Somayajulu NULL, ql_mbx_isr, ha, &ha->mbx_handle)) { 434f10a77bbSDavid C Somayajulu device_printf(dev, "could not setup mbx interrupt\n"); 435f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 436f10a77bbSDavid C Somayajulu } 437f10a77bbSDavid C Somayajulu 438f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 439f10a77bbSDavid C Somayajulu ha->irq_vec[i].sds_idx = i; 440f10a77bbSDavid C Somayajulu ha->irq_vec[i].ha = ha; 441f10a77bbSDavid C Somayajulu ha->irq_vec[i].irq_rid = 2 + i; 442f10a77bbSDavid C Somayajulu 443f10a77bbSDavid C Somayajulu ha->irq_vec[i].irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, 444f10a77bbSDavid C Somayajulu &ha->irq_vec[i].irq_rid, 445f10a77bbSDavid C Somayajulu (RF_ACTIVE | RF_SHAREABLE)); 446f10a77bbSDavid C Somayajulu 447f10a77bbSDavid C Somayajulu if (ha->irq_vec[i].irq == NULL) { 448f10a77bbSDavid C Somayajulu device_printf(dev, "could not allocate interrupt\n"); 449f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 450f10a77bbSDavid C Somayajulu } 451f10a77bbSDavid C Somayajulu if (bus_setup_intr(dev, ha->irq_vec[i].irq, 452f10a77bbSDavid C Somayajulu (INTR_TYPE_NET | INTR_MPSAFE), 453f10a77bbSDavid C Somayajulu NULL, ql_isr, &ha->irq_vec[i], 454f10a77bbSDavid C Somayajulu &ha->irq_vec[i].handle)) { 455f10a77bbSDavid C Somayajulu device_printf(dev, "could not setup interrupt\n"); 456f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 457f10a77bbSDavid C Somayajulu } 458b89f2279SDavid C Somayajulu 459b89f2279SDavid C Somayajulu ha->tx_fp[i].ha = ha; 460b89f2279SDavid C Somayajulu ha->tx_fp[i].txr_idx = i; 461b89f2279SDavid C Somayajulu 462b89f2279SDavid C Somayajulu if (qla_alloc_tx_br(ha, &ha->tx_fp[i])) { 463b89f2279SDavid C Somayajulu device_printf(dev, "%s: could not allocate tx_br[%d]\n", 464b89f2279SDavid C Somayajulu __func__, i); 465b89f2279SDavid C Somayajulu goto qla_pci_attach_err; 466f10a77bbSDavid C Somayajulu } 467b89f2279SDavid C Somayajulu } 468b89f2279SDavid C Somayajulu 469b89f2279SDavid C Somayajulu if (qla_create_fp_taskqueues(ha) != 0) 470b89f2279SDavid C Somayajulu goto qla_pci_attach_err; 471f10a77bbSDavid C Somayajulu 472f10a77bbSDavid C Somayajulu printf("%s: mp__ncpus %d sds %d rds %d msi-x %d\n", __func__, mp_ncpus, 473f10a77bbSDavid C Somayajulu ha->hw.num_sds_rings, ha->hw.num_rds_rings, ha->msix_count); 474f10a77bbSDavid C Somayajulu 475f10a77bbSDavid C Somayajulu ql_read_mac_addr(ha); 476f10a77bbSDavid C Somayajulu 477f10a77bbSDavid C Somayajulu /* allocate parent dma tag */ 478f10a77bbSDavid C Somayajulu if (qla_alloc_parent_dma_tag(ha)) { 479f10a77bbSDavid C Somayajulu device_printf(dev, "%s: qla_alloc_parent_dma_tag failed\n", 480f10a77bbSDavid C Somayajulu __func__); 481f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 482f10a77bbSDavid C Somayajulu } 483f10a77bbSDavid C Somayajulu 484f10a77bbSDavid C Somayajulu /* alloc all dma buffers */ 485f10a77bbSDavid C Somayajulu if (ql_alloc_dma(ha)) { 486f10a77bbSDavid C Somayajulu device_printf(dev, "%s: ql_alloc_dma failed\n", __func__); 487f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 488f10a77bbSDavid C Somayajulu } 489f10a77bbSDavid C Somayajulu qla_get_peer(ha); 490f10a77bbSDavid C Somayajulu 4916a62bec0SDavid C Somayajulu if (ql_minidump_init(ha) != 0) { 4926a62bec0SDavid C Somayajulu device_printf(dev, "%s: ql_minidump_init failed\n", __func__); 4936a62bec0SDavid C Somayajulu goto qla_pci_attach_err; 4946a62bec0SDavid C Somayajulu } 495f10a77bbSDavid C Somayajulu /* create the o.s ethernet interface */ 496f10a77bbSDavid C Somayajulu qla_init_ifnet(dev, ha); 497f10a77bbSDavid C Somayajulu 498f10a77bbSDavid C Somayajulu ha->flags.qla_watchdog_active = 1; 4997fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 0; 500f10a77bbSDavid C Somayajulu 5016a62bec0SDavid C Somayajulu callout_init(&ha->tx_callout, TRUE); 502f10a77bbSDavid C Somayajulu ha->flags.qla_callout_init = 1; 503f10a77bbSDavid C Somayajulu 504f10a77bbSDavid C Somayajulu /* create ioctl device interface */ 505f10a77bbSDavid C Somayajulu if (ql_make_cdev(ha)) { 506f10a77bbSDavid C Somayajulu device_printf(dev, "%s: ql_make_cdev failed\n", __func__); 507f10a77bbSDavid C Somayajulu goto qla_pci_attach_err; 508f10a77bbSDavid C Somayajulu } 509f10a77bbSDavid C Somayajulu 510f10a77bbSDavid C Somayajulu callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS, 511f10a77bbSDavid C Somayajulu qla_watchdog, ha); 512f10a77bbSDavid C Somayajulu 513f10a77bbSDavid C Somayajulu TASK_INIT(&ha->err_task, 0, qla_error_recovery, ha); 514da834d52SDavid C Somayajulu ha->err_tq = taskqueue_create("qla_errq", M_NOWAIT, 515f10a77bbSDavid C Somayajulu taskqueue_thread_enqueue, &ha->err_tq); 516f10a77bbSDavid C Somayajulu taskqueue_start_threads(&ha->err_tq, 1, PI_NET, "%s errq", 517f10a77bbSDavid C Somayajulu device_get_nameunit(ha->pci_dev)); 518f10a77bbSDavid C Somayajulu 51935291c22SDavid C Somayajulu TASK_INIT(&ha->async_event_task, 0, qla_async_event, ha); 520da834d52SDavid C Somayajulu ha->async_event_tq = taskqueue_create("qla_asyncq", M_NOWAIT, 52135291c22SDavid C Somayajulu taskqueue_thread_enqueue, &ha->async_event_tq); 52235291c22SDavid C Somayajulu taskqueue_start_threads(&ha->async_event_tq, 1, PI_NET, "%s asyncq", 52335291c22SDavid C Somayajulu device_get_nameunit(ha->pci_dev)); 52435291c22SDavid C Somayajulu 5257fb51846SDavid C Somayajulu TASK_INIT(&ha->stats_task, 0, qla_stats, ha); 5267fb51846SDavid C Somayajulu ha->stats_tq = taskqueue_create("qla_statsq", M_NOWAIT, 5277fb51846SDavid C Somayajulu taskqueue_thread_enqueue, &ha->stats_tq); 5287fb51846SDavid C Somayajulu taskqueue_start_threads(&ha->stats_tq, 1, PI_NET, "%s taskq", 5297fb51846SDavid C Somayajulu device_get_nameunit(ha->pci_dev)); 5307fb51846SDavid C Somayajulu 531f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit 0\n", __func__)); 532f10a77bbSDavid C Somayajulu return (0); 533f10a77bbSDavid C Somayajulu 534f10a77bbSDavid C Somayajulu qla_pci_attach_err: 535f10a77bbSDavid C Somayajulu 536f10a77bbSDavid C Somayajulu qla_release(ha); 537f10a77bbSDavid C Somayajulu 5387fb51846SDavid C Somayajulu if (ha->flags.lock_init) { 5397fb51846SDavid C Somayajulu mtx_destroy(&ha->hw_lock); 5407fb51846SDavid C Somayajulu } 5417fb51846SDavid C Somayajulu 542f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit ENXIO\n", __func__)); 543f10a77bbSDavid C Somayajulu return (ENXIO); 544f10a77bbSDavid C Somayajulu } 545f10a77bbSDavid C Somayajulu 546f10a77bbSDavid C Somayajulu /* 547f10a77bbSDavid C Somayajulu * Name: qla_pci_detach 548f10a77bbSDavid C Somayajulu * Function: Unhooks the device from the operating system 549f10a77bbSDavid C Somayajulu */ 550f10a77bbSDavid C Somayajulu static int 551f10a77bbSDavid C Somayajulu qla_pci_detach(device_t dev) 552f10a77bbSDavid C Somayajulu { 553f10a77bbSDavid C Somayajulu qla_host_t *ha = NULL; 554f10a77bbSDavid C Somayajulu struct ifnet *ifp; 555f10a77bbSDavid C Somayajulu 556f10a77bbSDavid C Somayajulu 557f10a77bbSDavid C Somayajulu if ((ha = device_get_softc(dev)) == NULL) { 558f10a77bbSDavid C Somayajulu device_printf(dev, "cannot get softc\n"); 559f10a77bbSDavid C Somayajulu return (ENOMEM); 560f10a77bbSDavid C Somayajulu } 561f10a77bbSDavid C Somayajulu 5627fb51846SDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: enter\n", __func__)); 5637fb51846SDavid C Somayajulu 564f10a77bbSDavid C Somayajulu ifp = ha->ifp; 565f10a77bbSDavid C Somayajulu 5667fb51846SDavid C Somayajulu ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 5677fb51846SDavid C Somayajulu QLA_LOCK(ha, __func__, -1, 0); 5687fb51846SDavid C Somayajulu 5697fb51846SDavid C Somayajulu ha->qla_detach_active = 1; 570f10a77bbSDavid C Somayajulu qla_stop(ha); 571f10a77bbSDavid C Somayajulu 572f10a77bbSDavid C Somayajulu qla_release(ha); 573f10a77bbSDavid C Somayajulu 5747fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__); 5757fb51846SDavid C Somayajulu 5767fb51846SDavid C Somayajulu if (ha->flags.lock_init) { 5777fb51846SDavid C Somayajulu mtx_destroy(&ha->hw_lock); 5787fb51846SDavid C Somayajulu } 5797fb51846SDavid C Somayajulu 580f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit\n", __func__)); 581f10a77bbSDavid C Somayajulu 582f10a77bbSDavid C Somayajulu return (0); 583f10a77bbSDavid C Somayajulu } 584f10a77bbSDavid C Somayajulu 585f10a77bbSDavid C Somayajulu /* 586f10a77bbSDavid C Somayajulu * SYSCTL Related Callbacks 587f10a77bbSDavid C Somayajulu */ 588f10a77bbSDavid C Somayajulu static int 589f10a77bbSDavid C Somayajulu qla_sysctl_get_link_status(SYSCTL_HANDLER_ARGS) 590f10a77bbSDavid C Somayajulu { 591f10a77bbSDavid C Somayajulu int err, ret = 0; 592f10a77bbSDavid C Somayajulu qla_host_t *ha; 593f10a77bbSDavid C Somayajulu 594f10a77bbSDavid C Somayajulu err = sysctl_handle_int(oidp, &ret, 0, req); 595f10a77bbSDavid C Somayajulu 596f10a77bbSDavid C Somayajulu if (err || !req->newptr) 597f10a77bbSDavid C Somayajulu return (err); 598f10a77bbSDavid C Somayajulu 599f10a77bbSDavid C Somayajulu if (ret == 1) { 600f10a77bbSDavid C Somayajulu ha = (qla_host_t *)arg1; 601f10a77bbSDavid C Somayajulu ql_hw_link_status(ha); 602f10a77bbSDavid C Somayajulu } 603f10a77bbSDavid C Somayajulu return (err); 604f10a77bbSDavid C Somayajulu } 605f10a77bbSDavid C Somayajulu 606f10a77bbSDavid C Somayajulu /* 607f10a77bbSDavid C Somayajulu * Name: qla_release 608f10a77bbSDavid C Somayajulu * Function: Releases the resources allocated for the device 609f10a77bbSDavid C Somayajulu */ 610f10a77bbSDavid C Somayajulu static void 611f10a77bbSDavid C Somayajulu qla_release(qla_host_t *ha) 612f10a77bbSDavid C Somayajulu { 613f10a77bbSDavid C Somayajulu device_t dev; 614f10a77bbSDavid C Somayajulu int i; 615f10a77bbSDavid C Somayajulu 616f10a77bbSDavid C Somayajulu dev = ha->pci_dev; 617f10a77bbSDavid C Somayajulu 61835291c22SDavid C Somayajulu if (ha->async_event_tq) { 61935291c22SDavid C Somayajulu taskqueue_drain(ha->async_event_tq, &ha->async_event_task); 62035291c22SDavid C Somayajulu taskqueue_free(ha->async_event_tq); 62135291c22SDavid C Somayajulu } 62235291c22SDavid C Somayajulu 623f10a77bbSDavid C Somayajulu if (ha->err_tq) { 624f10a77bbSDavid C Somayajulu taskqueue_drain(ha->err_tq, &ha->err_task); 625f10a77bbSDavid C Somayajulu taskqueue_free(ha->err_tq); 626f10a77bbSDavid C Somayajulu } 627f10a77bbSDavid C Somayajulu 6287fb51846SDavid C Somayajulu if (ha->stats_tq) { 6297fb51846SDavid C Somayajulu taskqueue_drain(ha->stats_tq, &ha->stats_task); 6307fb51846SDavid C Somayajulu taskqueue_free(ha->stats_tq); 6317fb51846SDavid C Somayajulu } 6327fb51846SDavid C Somayajulu 633f10a77bbSDavid C Somayajulu ql_del_cdev(ha); 634f10a77bbSDavid C Somayajulu 635f10a77bbSDavid C Somayajulu if (ha->flags.qla_watchdog_active) { 6367fb51846SDavid C Somayajulu ha->qla_watchdog_exit = 1; 637f10a77bbSDavid C Somayajulu 638f10a77bbSDavid C Somayajulu while (ha->qla_watchdog_exited == 0) 639f10a77bbSDavid C Somayajulu qla_mdelay(__func__, 1); 640f10a77bbSDavid C Somayajulu } 641f10a77bbSDavid C Somayajulu 642f10a77bbSDavid C Somayajulu if (ha->flags.qla_callout_init) 643f10a77bbSDavid C Somayajulu callout_stop(&ha->tx_callout); 644f10a77bbSDavid C Somayajulu 645f10a77bbSDavid C Somayajulu if (ha->ifp != NULL) 646f10a77bbSDavid C Somayajulu ether_ifdetach(ha->ifp); 647f10a77bbSDavid C Somayajulu 648f10a77bbSDavid C Somayajulu ql_free_dma(ha); 649f10a77bbSDavid C Somayajulu qla_free_parent_dma_tag(ha); 650f10a77bbSDavid C Somayajulu 651f10a77bbSDavid C Somayajulu if (ha->mbx_handle) 652f10a77bbSDavid C Somayajulu (void)bus_teardown_intr(dev, ha->mbx_irq, ha->mbx_handle); 653f10a77bbSDavid C Somayajulu 654f10a77bbSDavid C Somayajulu if (ha->mbx_irq) 655f10a77bbSDavid C Somayajulu (void) bus_release_resource(dev, SYS_RES_IRQ, ha->mbx_irq_rid, 656f10a77bbSDavid C Somayajulu ha->mbx_irq); 657f10a77bbSDavid C Somayajulu 658f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 659f10a77bbSDavid C Somayajulu 660f10a77bbSDavid C Somayajulu if (ha->irq_vec[i].handle) { 661f10a77bbSDavid C Somayajulu (void)bus_teardown_intr(dev, ha->irq_vec[i].irq, 662f10a77bbSDavid C Somayajulu ha->irq_vec[i].handle); 663f10a77bbSDavid C Somayajulu } 664f10a77bbSDavid C Somayajulu 665f10a77bbSDavid C Somayajulu if (ha->irq_vec[i].irq) { 666f10a77bbSDavid C Somayajulu (void)bus_release_resource(dev, SYS_RES_IRQ, 667f10a77bbSDavid C Somayajulu ha->irq_vec[i].irq_rid, 668f10a77bbSDavid C Somayajulu ha->irq_vec[i].irq); 669f10a77bbSDavid C Somayajulu } 670b89f2279SDavid C Somayajulu 671b89f2279SDavid C Somayajulu qla_free_tx_br(ha, &ha->tx_fp[i]); 672f10a77bbSDavid C Somayajulu } 673b89f2279SDavid C Somayajulu qla_destroy_fp_taskqueues(ha); 674f10a77bbSDavid C Somayajulu 675f10a77bbSDavid C Somayajulu if (ha->msix_count) 676f10a77bbSDavid C Somayajulu pci_release_msi(dev); 677f10a77bbSDavid C Somayajulu 6787fb51846SDavid C Somayajulu // if (ha->flags.lock_init) { 6797fb51846SDavid C Somayajulu // mtx_destroy(&ha->hw_lock); 6807fb51846SDavid C Somayajulu // } 681f10a77bbSDavid C Somayajulu 682f10a77bbSDavid C Somayajulu if (ha->pci_reg) 683f10a77bbSDavid C Somayajulu (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid, 684f10a77bbSDavid C Somayajulu ha->pci_reg); 685f10a77bbSDavid C Somayajulu 686f10a77bbSDavid C Somayajulu if (ha->pci_reg1) 687f10a77bbSDavid C Somayajulu (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid1, 688f10a77bbSDavid C Somayajulu ha->pci_reg1); 6897fb51846SDavid C Somayajulu 6907fb51846SDavid C Somayajulu return; 691f10a77bbSDavid C Somayajulu } 692f10a77bbSDavid C Somayajulu 693f10a77bbSDavid C Somayajulu /* 694f10a77bbSDavid C Somayajulu * DMA Related Functions 695f10a77bbSDavid C Somayajulu */ 696f10a77bbSDavid C Somayajulu 697f10a77bbSDavid C Somayajulu static void 698f10a77bbSDavid C Somayajulu qla_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error) 699f10a77bbSDavid C Somayajulu { 700f10a77bbSDavid C Somayajulu *((bus_addr_t *)arg) = 0; 701f10a77bbSDavid C Somayajulu 702f10a77bbSDavid C Somayajulu if (error) { 703f10a77bbSDavid C Somayajulu printf("%s: bus_dmamap_load failed (%d)\n", __func__, error); 704f10a77bbSDavid C Somayajulu return; 705f10a77bbSDavid C Somayajulu } 706f10a77bbSDavid C Somayajulu 707f10a77bbSDavid C Somayajulu *((bus_addr_t *)arg) = segs[0].ds_addr; 708f10a77bbSDavid C Somayajulu 709f10a77bbSDavid C Somayajulu return; 710f10a77bbSDavid C Somayajulu } 711f10a77bbSDavid C Somayajulu 712f10a77bbSDavid C Somayajulu int 713f10a77bbSDavid C Somayajulu ql_alloc_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf) 714f10a77bbSDavid C Somayajulu { 715f10a77bbSDavid C Somayajulu int ret = 0; 716f10a77bbSDavid C Somayajulu device_t dev; 717f10a77bbSDavid C Somayajulu bus_addr_t b_addr; 718f10a77bbSDavid C Somayajulu 719f10a77bbSDavid C Somayajulu dev = ha->pci_dev; 720f10a77bbSDavid C Somayajulu 721f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: enter\n", __func__)); 722f10a77bbSDavid C Somayajulu 723f10a77bbSDavid C Somayajulu ret = bus_dma_tag_create( 724f10a77bbSDavid C Somayajulu ha->parent_tag,/* parent */ 725f10a77bbSDavid C Somayajulu dma_buf->alignment, 726f10a77bbSDavid C Somayajulu ((bus_size_t)(1ULL << 32)),/* boundary */ 727f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* lowaddr */ 728f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* highaddr */ 729f10a77bbSDavid C Somayajulu NULL, NULL, /* filter, filterarg */ 730f10a77bbSDavid C Somayajulu dma_buf->size, /* maxsize */ 731f10a77bbSDavid C Somayajulu 1, /* nsegments */ 732f10a77bbSDavid C Somayajulu dma_buf->size, /* maxsegsize */ 733f10a77bbSDavid C Somayajulu 0, /* flags */ 734f10a77bbSDavid C Somayajulu NULL, NULL, /* lockfunc, lockarg */ 735f10a77bbSDavid C Somayajulu &dma_buf->dma_tag); 736f10a77bbSDavid C Somayajulu 737f10a77bbSDavid C Somayajulu if (ret) { 738f10a77bbSDavid C Somayajulu device_printf(dev, "%s: could not create dma tag\n", __func__); 739f10a77bbSDavid C Somayajulu goto ql_alloc_dmabuf_exit; 740f10a77bbSDavid C Somayajulu } 741f10a77bbSDavid C Somayajulu ret = bus_dmamem_alloc(dma_buf->dma_tag, 742f10a77bbSDavid C Somayajulu (void **)&dma_buf->dma_b, 743f10a77bbSDavid C Somayajulu (BUS_DMA_ZERO | BUS_DMA_COHERENT | BUS_DMA_NOWAIT), 744f10a77bbSDavid C Somayajulu &dma_buf->dma_map); 745f10a77bbSDavid C Somayajulu if (ret) { 746f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(dma_buf->dma_tag); 747f10a77bbSDavid C Somayajulu device_printf(dev, "%s: bus_dmamem_alloc failed\n", __func__); 748f10a77bbSDavid C Somayajulu goto ql_alloc_dmabuf_exit; 749f10a77bbSDavid C Somayajulu } 750f10a77bbSDavid C Somayajulu 751f10a77bbSDavid C Somayajulu ret = bus_dmamap_load(dma_buf->dma_tag, 752f10a77bbSDavid C Somayajulu dma_buf->dma_map, 753f10a77bbSDavid C Somayajulu dma_buf->dma_b, 754f10a77bbSDavid C Somayajulu dma_buf->size, 755f10a77bbSDavid C Somayajulu qla_dmamap_callback, 756f10a77bbSDavid C Somayajulu &b_addr, BUS_DMA_NOWAIT); 757f10a77bbSDavid C Somayajulu 758f10a77bbSDavid C Somayajulu if (ret || !b_addr) { 759f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(dma_buf->dma_tag); 760f10a77bbSDavid C Somayajulu bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b, 761f10a77bbSDavid C Somayajulu dma_buf->dma_map); 762f10a77bbSDavid C Somayajulu ret = -1; 763f10a77bbSDavid C Somayajulu goto ql_alloc_dmabuf_exit; 764f10a77bbSDavid C Somayajulu } 765f10a77bbSDavid C Somayajulu 766f10a77bbSDavid C Somayajulu dma_buf->dma_addr = b_addr; 767f10a77bbSDavid C Somayajulu 768f10a77bbSDavid C Somayajulu ql_alloc_dmabuf_exit: 769f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit ret 0x%08x tag %p map %p b %p sz 0x%x\n", 770f10a77bbSDavid C Somayajulu __func__, ret, (void *)dma_buf->dma_tag, 771f10a77bbSDavid C Somayajulu (void *)dma_buf->dma_map, (void *)dma_buf->dma_b, 772f10a77bbSDavid C Somayajulu dma_buf->size)); 773f10a77bbSDavid C Somayajulu 774f10a77bbSDavid C Somayajulu return ret; 775f10a77bbSDavid C Somayajulu } 776f10a77bbSDavid C Somayajulu 777f10a77bbSDavid C Somayajulu void 778f10a77bbSDavid C Somayajulu ql_free_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf) 779f10a77bbSDavid C Somayajulu { 78008d82f85SDavid C Somayajulu bus_dmamap_unload(dma_buf->dma_tag, dma_buf->dma_map); 781f10a77bbSDavid C Somayajulu bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b, dma_buf->dma_map); 782f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(dma_buf->dma_tag); 783f10a77bbSDavid C Somayajulu } 784f10a77bbSDavid C Somayajulu 785f10a77bbSDavid C Somayajulu static int 786f10a77bbSDavid C Somayajulu qla_alloc_parent_dma_tag(qla_host_t *ha) 787f10a77bbSDavid C Somayajulu { 788f10a77bbSDavid C Somayajulu int ret; 789f10a77bbSDavid C Somayajulu device_t dev; 790f10a77bbSDavid C Somayajulu 791f10a77bbSDavid C Somayajulu dev = ha->pci_dev; 792f10a77bbSDavid C Somayajulu 793f10a77bbSDavid C Somayajulu /* 794f10a77bbSDavid C Somayajulu * Allocate parent DMA Tag 795f10a77bbSDavid C Somayajulu */ 796f10a77bbSDavid C Somayajulu ret = bus_dma_tag_create( 797f10a77bbSDavid C Somayajulu bus_get_dma_tag(dev), /* parent */ 798f10a77bbSDavid C Somayajulu 1,((bus_size_t)(1ULL << 32)),/* alignment, boundary */ 799f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* lowaddr */ 800f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* highaddr */ 801f10a77bbSDavid C Somayajulu NULL, NULL, /* filter, filterarg */ 802f10a77bbSDavid C Somayajulu BUS_SPACE_MAXSIZE_32BIT,/* maxsize */ 803f10a77bbSDavid C Somayajulu 0, /* nsegments */ 804f10a77bbSDavid C Somayajulu BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */ 805f10a77bbSDavid C Somayajulu 0, /* flags */ 806f10a77bbSDavid C Somayajulu NULL, NULL, /* lockfunc, lockarg */ 807f10a77bbSDavid C Somayajulu &ha->parent_tag); 808f10a77bbSDavid C Somayajulu 809f10a77bbSDavid C Somayajulu if (ret) { 810f10a77bbSDavid C Somayajulu device_printf(dev, "%s: could not create parent dma tag\n", 811f10a77bbSDavid C Somayajulu __func__); 812f10a77bbSDavid C Somayajulu return (-1); 813f10a77bbSDavid C Somayajulu } 814f10a77bbSDavid C Somayajulu 815f10a77bbSDavid C Somayajulu ha->flags.parent_tag = 1; 816f10a77bbSDavid C Somayajulu 817f10a77bbSDavid C Somayajulu return (0); 818f10a77bbSDavid C Somayajulu } 819f10a77bbSDavid C Somayajulu 820f10a77bbSDavid C Somayajulu static void 821f10a77bbSDavid C Somayajulu qla_free_parent_dma_tag(qla_host_t *ha) 822f10a77bbSDavid C Somayajulu { 823f10a77bbSDavid C Somayajulu if (ha->flags.parent_tag) { 824f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(ha->parent_tag); 825f10a77bbSDavid C Somayajulu ha->flags.parent_tag = 0; 826f10a77bbSDavid C Somayajulu } 827f10a77bbSDavid C Somayajulu } 828f10a77bbSDavid C Somayajulu 829f10a77bbSDavid C Somayajulu /* 830f10a77bbSDavid C Somayajulu * Name: qla_init_ifnet 831f10a77bbSDavid C Somayajulu * Function: Creates the Network Device Interface and Registers it with the O.S 832f10a77bbSDavid C Somayajulu */ 833f10a77bbSDavid C Somayajulu 834f10a77bbSDavid C Somayajulu static void 835f10a77bbSDavid C Somayajulu qla_init_ifnet(device_t dev, qla_host_t *ha) 836f10a77bbSDavid C Somayajulu { 837f10a77bbSDavid C Somayajulu struct ifnet *ifp; 838f10a77bbSDavid C Somayajulu 839f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: enter\n", __func__)); 840f10a77bbSDavid C Somayajulu 841f10a77bbSDavid C Somayajulu ifp = ha->ifp = if_alloc(IFT_ETHER); 842f10a77bbSDavid C Somayajulu 843f10a77bbSDavid C Somayajulu if (ifp == NULL) 844f10a77bbSDavid C Somayajulu panic("%s: cannot if_alloc()\n", device_get_nameunit(dev)); 845f10a77bbSDavid C Somayajulu 846f10a77bbSDavid C Somayajulu if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 847f10a77bbSDavid C Somayajulu 848b245f96cSGleb Smirnoff ifp->if_baudrate = IF_Gbps(10); 849f10a77bbSDavid C Somayajulu ifp->if_capabilities = IFCAP_LINKSTATE; 8506a62bec0SDavid C Somayajulu ifp->if_mtu = ETHERMTU; 851f10a77bbSDavid C Somayajulu 852f10a77bbSDavid C Somayajulu ifp->if_init = qla_init; 853f10a77bbSDavid C Somayajulu ifp->if_softc = ha; 854f10a77bbSDavid C Somayajulu ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 855f10a77bbSDavid C Somayajulu ifp->if_ioctl = qla_ioctl; 856b89f2279SDavid C Somayajulu 857b89f2279SDavid C Somayajulu ifp->if_transmit = qla_transmit; 858b89f2279SDavid C Somayajulu ifp->if_qflush = qla_qflush; 859f10a77bbSDavid C Somayajulu 860f10a77bbSDavid C Somayajulu IFQ_SET_MAXLEN(&ifp->if_snd, qla_get_ifq_snd_maxlen(ha)); 861f10a77bbSDavid C Somayajulu ifp->if_snd.ifq_drv_maxlen = qla_get_ifq_snd_maxlen(ha); 862f10a77bbSDavid C Somayajulu IFQ_SET_READY(&ifp->if_snd); 863f10a77bbSDavid C Somayajulu 864f10a77bbSDavid C Somayajulu ha->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; 865f10a77bbSDavid C Somayajulu 866f10a77bbSDavid C Somayajulu ether_ifattach(ifp, qla_get_mac_addr(ha)); 867f10a77bbSDavid C Somayajulu 868b89f2279SDavid C Somayajulu ifp->if_capabilities |= IFCAP_HWCSUM | 869f10a77bbSDavid C Somayajulu IFCAP_TSO4 | 870b89f2279SDavid C Somayajulu IFCAP_JUMBO_MTU | 871b89f2279SDavid C Somayajulu IFCAP_VLAN_HWTAGGING | 872b89f2279SDavid C Somayajulu IFCAP_VLAN_MTU | 873b89f2279SDavid C Somayajulu IFCAP_VLAN_HWTSO | 874b89f2279SDavid C Somayajulu IFCAP_LRO; 875f10a77bbSDavid C Somayajulu 876f10a77bbSDavid C Somayajulu ifp->if_capenable = ifp->if_capabilities; 877f10a77bbSDavid C Somayajulu 8781bffa951SGleb Smirnoff ifp->if_hdrlen = sizeof(struct ether_vlan_header); 879f10a77bbSDavid C Somayajulu 880f10a77bbSDavid C Somayajulu ifmedia_init(&ha->media, IFM_IMASK, qla_media_change, qla_media_status); 881f10a77bbSDavid C Somayajulu 882f10a77bbSDavid C Somayajulu ifmedia_add(&ha->media, (IFM_ETHER | qla_get_optics(ha) | IFM_FDX), 0, 883f10a77bbSDavid C Somayajulu NULL); 884f10a77bbSDavid C Somayajulu ifmedia_add(&ha->media, (IFM_ETHER | IFM_AUTO), 0, NULL); 885f10a77bbSDavid C Somayajulu 886f10a77bbSDavid C Somayajulu ifmedia_set(&ha->media, (IFM_ETHER | IFM_AUTO)); 887f10a77bbSDavid C Somayajulu 888f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit\n", __func__)); 889f10a77bbSDavid C Somayajulu 890f10a77bbSDavid C Somayajulu return; 891f10a77bbSDavid C Somayajulu } 892f10a77bbSDavid C Somayajulu 893f10a77bbSDavid C Somayajulu static void 894f10a77bbSDavid C Somayajulu qla_init_locked(qla_host_t *ha) 895f10a77bbSDavid C Somayajulu { 896f10a77bbSDavid C Somayajulu struct ifnet *ifp = ha->ifp; 897f10a77bbSDavid C Somayajulu 898f10a77bbSDavid C Somayajulu qla_stop(ha); 899f10a77bbSDavid C Somayajulu 900f10a77bbSDavid C Somayajulu if (qla_alloc_xmt_bufs(ha) != 0) 901f10a77bbSDavid C Somayajulu return; 902f10a77bbSDavid C Somayajulu 90335291c22SDavid C Somayajulu qla_confirm_9kb_enable(ha); 90435291c22SDavid C Somayajulu 905f10a77bbSDavid C Somayajulu if (qla_alloc_rcv_bufs(ha) != 0) 906f10a77bbSDavid C Somayajulu return; 907f10a77bbSDavid C Somayajulu 908f10a77bbSDavid C Somayajulu bcopy(IF_LLADDR(ha->ifp), ha->hw.mac_addr, ETHER_ADDR_LEN); 909f10a77bbSDavid C Somayajulu 910f10a77bbSDavid C Somayajulu ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_TSO; 9117fb51846SDavid C Somayajulu ifp->if_hwassist |= CSUM_TCP_IPV6 | CSUM_UDP_IPV6; 912f10a77bbSDavid C Somayajulu 9137fb51846SDavid C Somayajulu ha->stop_rcv = 0; 914f10a77bbSDavid C Somayajulu if (ql_init_hw_if(ha) == 0) { 915f10a77bbSDavid C Somayajulu ifp = ha->ifp; 916f10a77bbSDavid C Somayajulu ifp->if_drv_flags |= IFF_DRV_RUNNING; 9177fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 0; 918f10a77bbSDavid C Somayajulu ha->hw_vlan_tx_frames = 0; 919f10a77bbSDavid C Somayajulu ha->tx_tso_frames = 0; 9207fb51846SDavid C Somayajulu ha->qla_interface_up = 1; 9217fb51846SDavid C Somayajulu ql_update_link_state(ha); 922f10a77bbSDavid C Somayajulu } 923f10a77bbSDavid C Somayajulu 924f10a77bbSDavid C Somayajulu return; 925f10a77bbSDavid C Somayajulu } 926f10a77bbSDavid C Somayajulu 927f10a77bbSDavid C Somayajulu static void 928f10a77bbSDavid C Somayajulu qla_init(void *arg) 929f10a77bbSDavid C Somayajulu { 930f10a77bbSDavid C Somayajulu qla_host_t *ha; 931f10a77bbSDavid C Somayajulu 932f10a77bbSDavid C Somayajulu ha = (qla_host_t *)arg; 933f10a77bbSDavid C Somayajulu 934f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__)); 935f10a77bbSDavid C Somayajulu 9367fb51846SDavid C Somayajulu if (QLA_LOCK(ha, __func__, -1, 0) != 0) 9377fb51846SDavid C Somayajulu return; 9387fb51846SDavid C Somayajulu 939f10a77bbSDavid C Somayajulu qla_init_locked(ha); 9407fb51846SDavid C Somayajulu 9417fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__); 942f10a77bbSDavid C Somayajulu 943f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__)); 944f10a77bbSDavid C Somayajulu } 945f10a77bbSDavid C Somayajulu 946f10a77bbSDavid C Somayajulu static int 947f10a77bbSDavid C Somayajulu qla_set_multi(qla_host_t *ha, uint32_t add_multi) 948f10a77bbSDavid C Somayajulu { 949f10a77bbSDavid C Somayajulu uint8_t mta[Q8_MAX_NUM_MULTICAST_ADDRS * Q8_MAC_ADDR_LEN]; 950f10a77bbSDavid C Somayajulu struct ifmultiaddr *ifma; 951f10a77bbSDavid C Somayajulu int mcnt = 0; 952f10a77bbSDavid C Somayajulu struct ifnet *ifp = ha->ifp; 953f10a77bbSDavid C Somayajulu int ret = 0; 954f10a77bbSDavid C Somayajulu 955f10a77bbSDavid C Somayajulu if_maddr_rlock(ifp); 956f10a77bbSDavid C Somayajulu 957f10a77bbSDavid C Somayajulu TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 958f10a77bbSDavid C Somayajulu 959f10a77bbSDavid C Somayajulu if (ifma->ifma_addr->sa_family != AF_LINK) 960f10a77bbSDavid C Somayajulu continue; 961f10a77bbSDavid C Somayajulu 962f10a77bbSDavid C Somayajulu if (mcnt == Q8_MAX_NUM_MULTICAST_ADDRS) 963f10a77bbSDavid C Somayajulu break; 964f10a77bbSDavid C Somayajulu 965f10a77bbSDavid C Somayajulu bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr), 966f10a77bbSDavid C Somayajulu &mta[mcnt * Q8_MAC_ADDR_LEN], Q8_MAC_ADDR_LEN); 967f10a77bbSDavid C Somayajulu 968f10a77bbSDavid C Somayajulu mcnt++; 969f10a77bbSDavid C Somayajulu } 970f10a77bbSDavid C Somayajulu 971f10a77bbSDavid C Somayajulu if_maddr_runlock(ifp); 972f10a77bbSDavid C Somayajulu 9737fb51846SDavid C Somayajulu if (QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 9747fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP) != 0) 9757fb51846SDavid C Somayajulu return (-1); 9767fb51846SDavid C Somayajulu 97777d57b28SDavid C Somayajulu if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 978*61fb8de9SDavid C Somayajulu 979*61fb8de9SDavid C Somayajulu if (!add_multi) { 980*61fb8de9SDavid C Somayajulu ret = qla_hw_del_all_mcast(ha); 981*61fb8de9SDavid C Somayajulu 982*61fb8de9SDavid C Somayajulu if (ret) 983*61fb8de9SDavid C Somayajulu device_printf(ha->pci_dev, 984*61fb8de9SDavid C Somayajulu "%s: qla_hw_del_all_mcast() failed\n", 985*61fb8de9SDavid C Somayajulu __func__); 986*61fb8de9SDavid C Somayajulu } 987*61fb8de9SDavid C Somayajulu 988*61fb8de9SDavid C Somayajulu if (!ret) 989*61fb8de9SDavid C Somayajulu ret = ql_hw_set_multi(ha, mta, mcnt, 1); 990*61fb8de9SDavid C Somayajulu 99177d57b28SDavid C Somayajulu } 9927fb51846SDavid C Somayajulu 9937fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__); 994f10a77bbSDavid C Somayajulu 995f10a77bbSDavid C Somayajulu return (ret); 996f10a77bbSDavid C Somayajulu } 997f10a77bbSDavid C Somayajulu 998f10a77bbSDavid C Somayajulu static int 999f10a77bbSDavid C Somayajulu qla_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 1000f10a77bbSDavid C Somayajulu { 1001f10a77bbSDavid C Somayajulu int ret = 0; 1002f10a77bbSDavid C Somayajulu struct ifreq *ifr = (struct ifreq *)data; 1003f10a77bbSDavid C Somayajulu struct ifaddr *ifa = (struct ifaddr *)data; 1004f10a77bbSDavid C Somayajulu qla_host_t *ha; 1005f10a77bbSDavid C Somayajulu 1006f10a77bbSDavid C Somayajulu ha = (qla_host_t *)ifp->if_softc; 1007f10a77bbSDavid C Somayajulu 1008f10a77bbSDavid C Somayajulu switch (cmd) { 1009f10a77bbSDavid C Somayajulu case SIOCSIFADDR: 1010f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFADDR (0x%lx)\n", 1011f10a77bbSDavid C Somayajulu __func__, cmd)); 1012f10a77bbSDavid C Somayajulu 1013f10a77bbSDavid C Somayajulu if (ifa->ifa_addr->sa_family == AF_INET) { 10147fb51846SDavid C Somayajulu 10157fb51846SDavid C Somayajulu ret = QLA_LOCK(ha, __func__, 10167fb51846SDavid C Somayajulu QLA_LOCK_DEFAULT_MS_TIMEOUT, 10177fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP); 10187fb51846SDavid C Somayajulu if (ret) 10197fb51846SDavid C Somayajulu break; 10207fb51846SDavid C Somayajulu 1021f10a77bbSDavid C Somayajulu ifp->if_flags |= IFF_UP; 10227fb51846SDavid C Somayajulu 1023f10a77bbSDavid C Somayajulu if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { 1024f10a77bbSDavid C Somayajulu qla_init_locked(ha); 1025f10a77bbSDavid C Somayajulu } 10267fb51846SDavid C Somayajulu 10277fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__); 1028f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, 1029f10a77bbSDavid C Somayajulu "%s: SIOCSIFADDR (0x%lx) ipv4 [0x%08x]\n", 1030f10a77bbSDavid C Somayajulu __func__, cmd, 1031f10a77bbSDavid C Somayajulu ntohl(IA_SIN(ifa)->sin_addr.s_addr))); 1032f10a77bbSDavid C Somayajulu 1033f10a77bbSDavid C Somayajulu arp_ifinit(ifp, ifa); 1034f10a77bbSDavid C Somayajulu } else { 1035f10a77bbSDavid C Somayajulu ether_ioctl(ifp, cmd, data); 1036f10a77bbSDavid C Somayajulu } 1037f10a77bbSDavid C Somayajulu break; 1038f10a77bbSDavid C Somayajulu 1039f10a77bbSDavid C Somayajulu case SIOCSIFMTU: 1040f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFMTU (0x%lx)\n", 1041f10a77bbSDavid C Somayajulu __func__, cmd)); 1042f10a77bbSDavid C Somayajulu 1043f10a77bbSDavid C Somayajulu if (ifr->ifr_mtu > QLA_MAX_MTU) { 1044f10a77bbSDavid C Somayajulu ret = EINVAL; 1045f10a77bbSDavid C Somayajulu } else { 10467fb51846SDavid C Somayajulu ret = QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 10477fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP); 10487fb51846SDavid C Somayajulu 10497fb51846SDavid C Somayajulu if (ret) 10507fb51846SDavid C Somayajulu break; 10519a5f7854SDavid C Somayajulu 1052f10a77bbSDavid C Somayajulu ifp->if_mtu = ifr->ifr_mtu; 1053f10a77bbSDavid C Somayajulu ha->max_frame_size = 1054f10a77bbSDavid C Somayajulu ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; 10559a5f7854SDavid C Somayajulu 10567fb51846SDavid C Somayajulu if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 1057b5c2be72SDavid C Somayajulu qla_init_locked(ha); 1058f10a77bbSDavid C Somayajulu } 1059f10a77bbSDavid C Somayajulu 1060f10a77bbSDavid C Somayajulu if (ifp->if_mtu > ETHERMTU) 1061f10a77bbSDavid C Somayajulu ha->std_replenish = QL_JUMBO_REPLENISH_THRES; 1062f10a77bbSDavid C Somayajulu else 1063f10a77bbSDavid C Somayajulu ha->std_replenish = QL_STD_REPLENISH_THRES; 1064f10a77bbSDavid C Somayajulu 1065f10a77bbSDavid C Somayajulu 10667fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__); 1067f10a77bbSDavid C Somayajulu } 1068f10a77bbSDavid C Somayajulu 1069f10a77bbSDavid C Somayajulu break; 1070f10a77bbSDavid C Somayajulu 1071f10a77bbSDavid C Somayajulu case SIOCSIFFLAGS: 1072f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFFLAGS (0x%lx)\n", 1073f10a77bbSDavid C Somayajulu __func__, cmd)); 1074f10a77bbSDavid C Somayajulu 10757fb51846SDavid C Somayajulu ret = QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 10767fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP); 10777fb51846SDavid C Somayajulu 10787fb51846SDavid C Somayajulu if (ret) 10797fb51846SDavid C Somayajulu break; 1080f10a77bbSDavid C Somayajulu 1081f10a77bbSDavid C Somayajulu if (ifp->if_flags & IFF_UP) { 10827fb51846SDavid C Somayajulu 10837fb51846SDavid C Somayajulu ha->max_frame_size = ifp->if_mtu + 10847fb51846SDavid C Somayajulu ETHER_HDR_LEN + ETHER_CRC_LEN; 10857fb51846SDavid C Somayajulu qla_init_locked(ha); 10867fb51846SDavid C Somayajulu 10877fb51846SDavid C Somayajulu if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 1088f10a77bbSDavid C Somayajulu if ((ifp->if_flags ^ ha->if_flags) & 1089f10a77bbSDavid C Somayajulu IFF_PROMISC) { 1090f10a77bbSDavid C Somayajulu ret = ql_set_promisc(ha); 1091f10a77bbSDavid C Somayajulu } else if ((ifp->if_flags ^ ha->if_flags) & 1092f10a77bbSDavid C Somayajulu IFF_ALLMULTI) { 1093f10a77bbSDavid C Somayajulu ret = ql_set_allmulti(ha); 1094f10a77bbSDavid C Somayajulu } 1095f10a77bbSDavid C Somayajulu } 1096f10a77bbSDavid C Somayajulu } else { 1097f10a77bbSDavid C Somayajulu if (ifp->if_drv_flags & IFF_DRV_RUNNING) 1098f10a77bbSDavid C Somayajulu qla_stop(ha); 1099f10a77bbSDavid C Somayajulu ha->if_flags = ifp->if_flags; 1100f10a77bbSDavid C Somayajulu } 1101f10a77bbSDavid C Somayajulu 11027fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__); 1103f10a77bbSDavid C Somayajulu break; 1104f10a77bbSDavid C Somayajulu 1105f10a77bbSDavid C Somayajulu case SIOCADDMULTI: 1106f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, 1107f10a77bbSDavid C Somayajulu "%s: %s (0x%lx)\n", __func__, "SIOCADDMULTI", cmd)); 1108f10a77bbSDavid C Somayajulu 1109f10a77bbSDavid C Somayajulu if (qla_set_multi(ha, 1)) 1110f10a77bbSDavid C Somayajulu ret = EINVAL; 1111f10a77bbSDavid C Somayajulu break; 1112f10a77bbSDavid C Somayajulu 1113f10a77bbSDavid C Somayajulu case SIOCDELMULTI: 1114f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, 1115f10a77bbSDavid C Somayajulu "%s: %s (0x%lx)\n", __func__, "SIOCDELMULTI", cmd)); 1116f10a77bbSDavid C Somayajulu 1117f10a77bbSDavid C Somayajulu if (qla_set_multi(ha, 0)) 1118f10a77bbSDavid C Somayajulu ret = EINVAL; 1119f10a77bbSDavid C Somayajulu break; 1120f10a77bbSDavid C Somayajulu 1121f10a77bbSDavid C Somayajulu case SIOCSIFMEDIA: 1122f10a77bbSDavid C Somayajulu case SIOCGIFMEDIA: 1123f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, 1124f10a77bbSDavid C Somayajulu "%s: SIOCSIFMEDIA/SIOCGIFMEDIA (0x%lx)\n", 1125f10a77bbSDavid C Somayajulu __func__, cmd)); 1126f10a77bbSDavid C Somayajulu ret = ifmedia_ioctl(ifp, ifr, &ha->media, cmd); 1127f10a77bbSDavid C Somayajulu break; 1128f10a77bbSDavid C Somayajulu 1129f10a77bbSDavid C Somayajulu case SIOCSIFCAP: 1130f10a77bbSDavid C Somayajulu { 1131f10a77bbSDavid C Somayajulu int mask = ifr->ifr_reqcap ^ ifp->if_capenable; 1132f10a77bbSDavid C Somayajulu 1133f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFCAP (0x%lx)\n", 1134f10a77bbSDavid C Somayajulu __func__, cmd)); 1135f10a77bbSDavid C Somayajulu 1136f10a77bbSDavid C Somayajulu if (mask & IFCAP_HWCSUM) 1137f10a77bbSDavid C Somayajulu ifp->if_capenable ^= IFCAP_HWCSUM; 1138f10a77bbSDavid C Somayajulu if (mask & IFCAP_TSO4) 1139f10a77bbSDavid C Somayajulu ifp->if_capenable ^= IFCAP_TSO4; 11407fb51846SDavid C Somayajulu if (mask & IFCAP_TSO6) 11417fb51846SDavid C Somayajulu ifp->if_capenable ^= IFCAP_TSO6; 1142f10a77bbSDavid C Somayajulu if (mask & IFCAP_VLAN_HWTAGGING) 1143f10a77bbSDavid C Somayajulu ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING; 1144f10a77bbSDavid C Somayajulu if (mask & IFCAP_VLAN_HWTSO) 1145f10a77bbSDavid C Somayajulu ifp->if_capenable ^= IFCAP_VLAN_HWTSO; 1146a7c62c11SDavid C Somayajulu if (mask & IFCAP_LRO) 1147a7c62c11SDavid C Somayajulu ifp->if_capenable ^= IFCAP_LRO; 1148f10a77bbSDavid C Somayajulu 11497fb51846SDavid C Somayajulu if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 11507fb51846SDavid C Somayajulu ret = QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 11517fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP); 1152f10a77bbSDavid C Somayajulu 11537fb51846SDavid C Somayajulu if (ret) 11547fb51846SDavid C Somayajulu break; 11557fb51846SDavid C Somayajulu 11567fb51846SDavid C Somayajulu qla_init_locked(ha); 11577fb51846SDavid C Somayajulu 11587fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__); 11597fb51846SDavid C Somayajulu 11607fb51846SDavid C Somayajulu } 1161f10a77bbSDavid C Somayajulu VLAN_CAPABILITIES(ifp); 1162f10a77bbSDavid C Somayajulu break; 1163f10a77bbSDavid C Somayajulu } 1164f10a77bbSDavid C Somayajulu 1165f10a77bbSDavid C Somayajulu default: 1166f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: default (0x%lx)\n", 1167f10a77bbSDavid C Somayajulu __func__, cmd)); 1168f10a77bbSDavid C Somayajulu ret = ether_ioctl(ifp, cmd, data); 1169f10a77bbSDavid C Somayajulu break; 1170f10a77bbSDavid C Somayajulu } 1171f10a77bbSDavid C Somayajulu 1172f10a77bbSDavid C Somayajulu return (ret); 1173f10a77bbSDavid C Somayajulu } 1174f10a77bbSDavid C Somayajulu 1175f10a77bbSDavid C Somayajulu static int 1176f10a77bbSDavid C Somayajulu qla_media_change(struct ifnet *ifp) 1177f10a77bbSDavid C Somayajulu { 1178f10a77bbSDavid C Somayajulu qla_host_t *ha; 1179f10a77bbSDavid C Somayajulu struct ifmedia *ifm; 1180f10a77bbSDavid C Somayajulu int ret = 0; 1181f10a77bbSDavid C Somayajulu 1182f10a77bbSDavid C Somayajulu ha = (qla_host_t *)ifp->if_softc; 1183f10a77bbSDavid C Somayajulu 1184f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__)); 1185f10a77bbSDavid C Somayajulu 1186f10a77bbSDavid C Somayajulu ifm = &ha->media; 1187f10a77bbSDavid C Somayajulu 1188f10a77bbSDavid C Somayajulu if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 1189f10a77bbSDavid C Somayajulu ret = EINVAL; 1190f10a77bbSDavid C Somayajulu 1191f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__)); 1192f10a77bbSDavid C Somayajulu 1193f10a77bbSDavid C Somayajulu return (ret); 1194f10a77bbSDavid C Somayajulu } 1195f10a77bbSDavid C Somayajulu 1196f10a77bbSDavid C Somayajulu static void 1197f10a77bbSDavid C Somayajulu qla_media_status(struct ifnet *ifp, struct ifmediareq *ifmr) 1198f10a77bbSDavid C Somayajulu { 1199f10a77bbSDavid C Somayajulu qla_host_t *ha; 1200f10a77bbSDavid C Somayajulu 1201f10a77bbSDavid C Somayajulu ha = (qla_host_t *)ifp->if_softc; 1202f10a77bbSDavid C Somayajulu 1203f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__)); 1204f10a77bbSDavid C Somayajulu 1205f10a77bbSDavid C Somayajulu ifmr->ifm_status = IFM_AVALID; 1206f10a77bbSDavid C Somayajulu ifmr->ifm_active = IFM_ETHER; 1207f10a77bbSDavid C Somayajulu 1208f10a77bbSDavid C Somayajulu ql_update_link_state(ha); 1209f10a77bbSDavid C Somayajulu if (ha->hw.link_up) { 1210f10a77bbSDavid C Somayajulu ifmr->ifm_status |= IFM_ACTIVE; 1211f10a77bbSDavid C Somayajulu ifmr->ifm_active |= (IFM_FDX | qla_get_optics(ha)); 1212f10a77bbSDavid C Somayajulu } 1213f10a77bbSDavid C Somayajulu 1214f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit (%s)\n", __func__,\ 1215f10a77bbSDavid C Somayajulu (ha->hw.link_up ? "link_up" : "link_down"))); 1216f10a77bbSDavid C Somayajulu 1217f10a77bbSDavid C Somayajulu return; 1218f10a77bbSDavid C Somayajulu } 1219f10a77bbSDavid C Somayajulu 1220f10a77bbSDavid C Somayajulu 1221f10a77bbSDavid C Somayajulu static int 1222b89f2279SDavid C Somayajulu qla_send(qla_host_t *ha, struct mbuf **m_headp, uint32_t txr_idx, 1223b89f2279SDavid C Somayajulu uint32_t iscsi_pdu) 1224f10a77bbSDavid C Somayajulu { 1225f10a77bbSDavid C Somayajulu bus_dma_segment_t segs[QLA_MAX_SEGMENTS]; 1226f10a77bbSDavid C Somayajulu bus_dmamap_t map; 1227f10a77bbSDavid C Somayajulu int nsegs; 1228f10a77bbSDavid C Somayajulu int ret = -1; 1229f10a77bbSDavid C Somayajulu uint32_t tx_idx; 1230f10a77bbSDavid C Somayajulu struct mbuf *m_head = *m_headp; 1231f10a77bbSDavid C Somayajulu 1232f10a77bbSDavid C Somayajulu QL_DPRINT8(ha, (ha->pci_dev, "%s: enter\n", __func__)); 1233f10a77bbSDavid C Somayajulu 1234f10a77bbSDavid C Somayajulu tx_idx = ha->hw.tx_cntxt[txr_idx].txr_next; 1235f10a77bbSDavid C Somayajulu map = ha->tx_ring[txr_idx].tx_buf[tx_idx].map; 1236f10a77bbSDavid C Somayajulu 1237f10a77bbSDavid C Somayajulu ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head, segs, &nsegs, 1238f10a77bbSDavid C Somayajulu BUS_DMA_NOWAIT); 1239f10a77bbSDavid C Somayajulu 1240f10a77bbSDavid C Somayajulu if (ret == EFBIG) { 1241f10a77bbSDavid C Somayajulu 1242f10a77bbSDavid C Somayajulu struct mbuf *m; 1243f10a77bbSDavid C Somayajulu 1244f10a77bbSDavid C Somayajulu QL_DPRINT8(ha, (ha->pci_dev, "%s: EFBIG [%d]\n", __func__, 1245f10a77bbSDavid C Somayajulu m_head->m_pkthdr.len)); 1246f10a77bbSDavid C Somayajulu 1247f10a77bbSDavid C Somayajulu m = m_defrag(m_head, M_NOWAIT); 1248f10a77bbSDavid C Somayajulu if (m == NULL) { 1249f10a77bbSDavid C Somayajulu ha->err_tx_defrag++; 1250f10a77bbSDavid C Somayajulu m_freem(m_head); 1251f10a77bbSDavid C Somayajulu *m_headp = NULL; 1252f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, 1253f10a77bbSDavid C Somayajulu "%s: m_defrag() = NULL [%d]\n", 1254f10a77bbSDavid C Somayajulu __func__, ret); 1255f10a77bbSDavid C Somayajulu return (ENOBUFS); 1256f10a77bbSDavid C Somayajulu } 1257f10a77bbSDavid C Somayajulu m_head = m; 1258f10a77bbSDavid C Somayajulu *m_headp = m_head; 1259f10a77bbSDavid C Somayajulu 1260f10a77bbSDavid C Somayajulu if ((ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head, 1261f10a77bbSDavid C Somayajulu segs, &nsegs, BUS_DMA_NOWAIT))) { 1262f10a77bbSDavid C Somayajulu 1263f10a77bbSDavid C Somayajulu ha->err_tx_dmamap_load++; 1264f10a77bbSDavid C Somayajulu 1265f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, 1266f10a77bbSDavid C Somayajulu "%s: bus_dmamap_load_mbuf_sg failed0[%d, %d]\n", 1267f10a77bbSDavid C Somayajulu __func__, ret, m_head->m_pkthdr.len); 1268f10a77bbSDavid C Somayajulu 1269f10a77bbSDavid C Somayajulu if (ret != ENOMEM) { 1270f10a77bbSDavid C Somayajulu m_freem(m_head); 1271f10a77bbSDavid C Somayajulu *m_headp = NULL; 1272f10a77bbSDavid C Somayajulu } 1273f10a77bbSDavid C Somayajulu return (ret); 1274f10a77bbSDavid C Somayajulu } 1275f10a77bbSDavid C Somayajulu 1276f10a77bbSDavid C Somayajulu } else if (ret) { 1277f10a77bbSDavid C Somayajulu 1278f10a77bbSDavid C Somayajulu ha->err_tx_dmamap_load++; 1279f10a77bbSDavid C Somayajulu 1280f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, 1281f10a77bbSDavid C Somayajulu "%s: bus_dmamap_load_mbuf_sg failed1[%d, %d]\n", 1282f10a77bbSDavid C Somayajulu __func__, ret, m_head->m_pkthdr.len); 1283f10a77bbSDavid C Somayajulu 1284f10a77bbSDavid C Somayajulu if (ret != ENOMEM) { 1285f10a77bbSDavid C Somayajulu m_freem(m_head); 1286f10a77bbSDavid C Somayajulu *m_headp = NULL; 1287f10a77bbSDavid C Somayajulu } 1288f10a77bbSDavid C Somayajulu return (ret); 1289f10a77bbSDavid C Somayajulu } 1290f10a77bbSDavid C Somayajulu 1291f10a77bbSDavid C Somayajulu QL_ASSERT(ha, (nsegs != 0), ("qla_send: empty packet")); 1292f10a77bbSDavid C Somayajulu 1293f10a77bbSDavid C Somayajulu bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_PREWRITE); 1294f10a77bbSDavid C Somayajulu 129535291c22SDavid C Somayajulu if (!(ret = ql_hw_send(ha, segs, nsegs, tx_idx, m_head, txr_idx, 129635291c22SDavid C Somayajulu iscsi_pdu))) { 1297f10a77bbSDavid C Somayajulu ha->tx_ring[txr_idx].count++; 12987fb51846SDavid C Somayajulu if (iscsi_pdu) 12997fb51846SDavid C Somayajulu ha->tx_ring[txr_idx].iscsi_pkt_count++; 1300f10a77bbSDavid C Somayajulu ha->tx_ring[txr_idx].tx_buf[tx_idx].m_head = m_head; 1301f10a77bbSDavid C Somayajulu } else { 1302203f9d18SDavid C Somayajulu bus_dmamap_unload(ha->tx_tag, map); 1303f10a77bbSDavid C Somayajulu if (ret == EINVAL) { 1304f10a77bbSDavid C Somayajulu if (m_head) 1305f10a77bbSDavid C Somayajulu m_freem(m_head); 1306f10a77bbSDavid C Somayajulu *m_headp = NULL; 1307f10a77bbSDavid C Somayajulu } 1308f10a77bbSDavid C Somayajulu } 1309f10a77bbSDavid C Somayajulu 1310f10a77bbSDavid C Somayajulu QL_DPRINT8(ha, (ha->pci_dev, "%s: exit\n", __func__)); 1311f10a77bbSDavid C Somayajulu return (ret); 1312f10a77bbSDavid C Somayajulu } 1313f10a77bbSDavid C Somayajulu 1314b89f2279SDavid C Somayajulu static int 1315b89f2279SDavid C Somayajulu qla_alloc_tx_br(qla_host_t *ha, qla_tx_fp_t *fp) 1316b89f2279SDavid C Somayajulu { 1317b89f2279SDavid C Somayajulu snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name), 1318b89f2279SDavid C Somayajulu "qla%d_fp%d_tx_mq_lock", ha->pci_func, fp->txr_idx); 1319b89f2279SDavid C Somayajulu 1320b89f2279SDavid C Somayajulu mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF); 1321b89f2279SDavid C Somayajulu 1322b89f2279SDavid C Somayajulu fp->tx_br = buf_ring_alloc(NUM_TX_DESCRIPTORS, M_DEVBUF, 1323b89f2279SDavid C Somayajulu M_NOWAIT, &fp->tx_mtx); 1324b89f2279SDavid C Somayajulu if (fp->tx_br == NULL) { 1325b89f2279SDavid C Somayajulu QL_DPRINT1(ha, (ha->pci_dev, "buf_ring_alloc failed for " 1326b89f2279SDavid C Somayajulu " fp[%d, %d]\n", ha->pci_func, fp->txr_idx)); 1327b89f2279SDavid C Somayajulu return (-ENOMEM); 1328b89f2279SDavid C Somayajulu } 1329b89f2279SDavid C Somayajulu return 0; 1330b89f2279SDavid C Somayajulu } 1331b89f2279SDavid C Somayajulu 1332b89f2279SDavid C Somayajulu static void 1333b89f2279SDavid C Somayajulu qla_free_tx_br(qla_host_t *ha, qla_tx_fp_t *fp) 1334b89f2279SDavid C Somayajulu { 1335b89f2279SDavid C Somayajulu struct mbuf *mp; 1336b89f2279SDavid C Somayajulu struct ifnet *ifp = ha->ifp; 1337b89f2279SDavid C Somayajulu 1338b89f2279SDavid C Somayajulu if (mtx_initialized(&fp->tx_mtx)) { 1339b89f2279SDavid C Somayajulu 1340b89f2279SDavid C Somayajulu if (fp->tx_br != NULL) { 1341b89f2279SDavid C Somayajulu 1342b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx); 1343b89f2279SDavid C Somayajulu 1344b89f2279SDavid C Somayajulu while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) { 1345b89f2279SDavid C Somayajulu m_freem(mp); 1346b89f2279SDavid C Somayajulu } 1347b89f2279SDavid C Somayajulu 1348b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx); 1349b89f2279SDavid C Somayajulu 1350b89f2279SDavid C Somayajulu buf_ring_free(fp->tx_br, M_DEVBUF); 1351b89f2279SDavid C Somayajulu fp->tx_br = NULL; 1352b89f2279SDavid C Somayajulu } 1353b89f2279SDavid C Somayajulu mtx_destroy(&fp->tx_mtx); 1354b89f2279SDavid C Somayajulu } 1355b89f2279SDavid C Somayajulu return; 1356b89f2279SDavid C Somayajulu } 1357b89f2279SDavid C Somayajulu 1358b89f2279SDavid C Somayajulu static void 1359b89f2279SDavid C Somayajulu qla_fp_taskqueue(void *context, int pending) 1360b89f2279SDavid C Somayajulu { 1361b89f2279SDavid C Somayajulu qla_tx_fp_t *fp; 1362b89f2279SDavid C Somayajulu qla_host_t *ha; 1363b89f2279SDavid C Somayajulu struct ifnet *ifp; 1364b89f2279SDavid C Somayajulu struct mbuf *mp; 1365b89f2279SDavid C Somayajulu int ret; 1366b89f2279SDavid C Somayajulu uint32_t txr_idx; 1367b89f2279SDavid C Somayajulu uint32_t iscsi_pdu = 0; 13687fb51846SDavid C Somayajulu uint32_t rx_pkts_left = -1; 1369b89f2279SDavid C Somayajulu 1370b89f2279SDavid C Somayajulu fp = context; 1371b89f2279SDavid C Somayajulu 1372b89f2279SDavid C Somayajulu if (fp == NULL) 1373b89f2279SDavid C Somayajulu return; 1374b89f2279SDavid C Somayajulu 1375b89f2279SDavid C Somayajulu ha = (qla_host_t *)fp->ha; 1376b89f2279SDavid C Somayajulu 1377b89f2279SDavid C Somayajulu ifp = ha->ifp; 1378b89f2279SDavid C Somayajulu 1379b89f2279SDavid C Somayajulu txr_idx = fp->txr_idx; 1380b89f2279SDavid C Somayajulu 1381b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx); 1382b89f2279SDavid C Somayajulu 13837fb51846SDavid C Somayajulu if (!(ifp->if_drv_flags & IFF_DRV_RUNNING) || (!ha->hw.link_up)) { 1384b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx); 1385b89f2279SDavid C Somayajulu goto qla_fp_taskqueue_exit; 1386b89f2279SDavid C Somayajulu } 1387b89f2279SDavid C Somayajulu 1388203f9d18SDavid C Somayajulu while (rx_pkts_left && !ha->stop_rcv && 1389203f9d18SDavid C Somayajulu (ifp->if_drv_flags & IFF_DRV_RUNNING)) { 1390b89f2279SDavid C Somayajulu rx_pkts_left = ql_rcv_isr(ha, fp->txr_idx, 64); 1391b89f2279SDavid C Somayajulu 1392b89f2279SDavid C Somayajulu #ifdef QL_ENABLE_ISCSI_TLV 1393b89f2279SDavid C Somayajulu ql_hw_tx_done_locked(ha, fp->txr_idx); 1394b89f2279SDavid C Somayajulu ql_hw_tx_done_locked(ha, (fp->txr_idx + (ha->hw.num_tx_rings >> 1))); 1395b89f2279SDavid C Somayajulu #else 1396b89f2279SDavid C Somayajulu ql_hw_tx_done_locked(ha, fp->txr_idx); 1397b89f2279SDavid C Somayajulu #endif /* #ifdef QL_ENABLE_ISCSI_TLV */ 1398b89f2279SDavid C Somayajulu 1399b89f2279SDavid C Somayajulu mp = drbr_peek(ifp, fp->tx_br); 1400b89f2279SDavid C Somayajulu 1401b89f2279SDavid C Somayajulu while (mp != NULL) { 1402b89f2279SDavid C Somayajulu 1403b89f2279SDavid C Somayajulu if (M_HASHTYPE_GET(mp) != M_HASHTYPE_NONE) { 1404b89f2279SDavid C Somayajulu #ifdef QL_ENABLE_ISCSI_TLV 1405b89f2279SDavid C Somayajulu if (ql_iscsi_pdu(ha, mp) == 0) { 14067fb51846SDavid C Somayajulu txr_idx = txr_idx + 14077fb51846SDavid C Somayajulu (ha->hw.num_tx_rings >> 1); 1408b89f2279SDavid C Somayajulu iscsi_pdu = 1; 14097fb51846SDavid C Somayajulu } else { 14107fb51846SDavid C Somayajulu iscsi_pdu = 0; 14117fb51846SDavid C Somayajulu txr_idx = fp->txr_idx; 1412b89f2279SDavid C Somayajulu } 1413b89f2279SDavid C Somayajulu #endif /* #ifdef QL_ENABLE_ISCSI_TLV */ 1414b89f2279SDavid C Somayajulu } 1415b89f2279SDavid C Somayajulu 1416b89f2279SDavid C Somayajulu ret = qla_send(ha, &mp, txr_idx, iscsi_pdu); 1417b89f2279SDavid C Somayajulu 1418b89f2279SDavid C Somayajulu if (ret) { 1419b89f2279SDavid C Somayajulu if (mp != NULL) 1420b89f2279SDavid C Somayajulu drbr_putback(ifp, fp->tx_br, mp); 1421b89f2279SDavid C Somayajulu else { 1422b89f2279SDavid C Somayajulu drbr_advance(ifp, fp->tx_br); 1423b89f2279SDavid C Somayajulu } 1424b89f2279SDavid C Somayajulu 1425b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx); 1426b89f2279SDavid C Somayajulu 1427b89f2279SDavid C Somayajulu goto qla_fp_taskqueue_exit0; 1428b89f2279SDavid C Somayajulu } else { 1429b89f2279SDavid C Somayajulu drbr_advance(ifp, fp->tx_br); 1430b89f2279SDavid C Somayajulu } 1431b89f2279SDavid C Somayajulu 1432203f9d18SDavid C Somayajulu /* Send a copy of the frame to the BPF listener */ 1433203f9d18SDavid C Somayajulu ETHER_BPF_MTAP(ifp, mp); 1434203f9d18SDavid C Somayajulu if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) 1435203f9d18SDavid C Somayajulu break; 1436203f9d18SDavid C Somayajulu 1437b89f2279SDavid C Somayajulu mp = drbr_peek(ifp, fp->tx_br); 1438b89f2279SDavid C Somayajulu } 14397fb51846SDavid C Somayajulu } 1440b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx); 1441b89f2279SDavid C Somayajulu 1442b89f2279SDavid C Somayajulu qla_fp_taskqueue_exit0: 1443b89f2279SDavid C Somayajulu 1444b89f2279SDavid C Somayajulu if (rx_pkts_left || ((mp != NULL) && ret)) { 1445b89f2279SDavid C Somayajulu taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task); 1446b89f2279SDavid C Somayajulu } else { 14477fb51846SDavid C Somayajulu if (!ha->stop_rcv) { 1448b89f2279SDavid C Somayajulu QL_ENABLE_INTERRUPTS(ha, fp->txr_idx); 1449b89f2279SDavid C Somayajulu } 1450b89f2279SDavid C Somayajulu } 1451b89f2279SDavid C Somayajulu 1452b89f2279SDavid C Somayajulu qla_fp_taskqueue_exit: 1453b89f2279SDavid C Somayajulu 1454b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = %d\n", __func__, ret)); 1455b89f2279SDavid C Somayajulu return; 1456b89f2279SDavid C Somayajulu } 1457b89f2279SDavid C Somayajulu 1458b89f2279SDavid C Somayajulu static int 1459b89f2279SDavid C Somayajulu qla_create_fp_taskqueues(qla_host_t *ha) 1460b89f2279SDavid C Somayajulu { 1461b89f2279SDavid C Somayajulu int i; 1462b89f2279SDavid C Somayajulu uint8_t tq_name[32]; 1463b89f2279SDavid C Somayajulu 1464b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 1465b89f2279SDavid C Somayajulu 1466b89f2279SDavid C Somayajulu qla_tx_fp_t *fp = &ha->tx_fp[i]; 1467b89f2279SDavid C Somayajulu 1468b89f2279SDavid C Somayajulu bzero(tq_name, sizeof (tq_name)); 1469b89f2279SDavid C Somayajulu snprintf(tq_name, sizeof (tq_name), "ql_fp_tq_%d", i); 1470b89f2279SDavid C Somayajulu 1471b89f2279SDavid C Somayajulu TASK_INIT(&fp->fp_task, 0, qla_fp_taskqueue, fp); 1472b89f2279SDavid C Somayajulu 1473b89f2279SDavid C Somayajulu fp->fp_taskqueue = taskqueue_create_fast(tq_name, M_NOWAIT, 1474b89f2279SDavid C Somayajulu taskqueue_thread_enqueue, 1475b89f2279SDavid C Somayajulu &fp->fp_taskqueue); 1476b89f2279SDavid C Somayajulu 1477b89f2279SDavid C Somayajulu if (fp->fp_taskqueue == NULL) 1478b89f2279SDavid C Somayajulu return (-1); 1479b89f2279SDavid C Somayajulu 1480b89f2279SDavid C Somayajulu taskqueue_start_threads(&fp->fp_taskqueue, 1, PI_NET, "%s", 1481b89f2279SDavid C Somayajulu tq_name); 1482b89f2279SDavid C Somayajulu 1483b89f2279SDavid C Somayajulu QL_DPRINT1(ha, (ha->pci_dev, "%s: %p\n", __func__, 1484b89f2279SDavid C Somayajulu fp->fp_taskqueue)); 1485b89f2279SDavid C Somayajulu } 1486b89f2279SDavid C Somayajulu 1487b89f2279SDavid C Somayajulu return (0); 1488b89f2279SDavid C Somayajulu } 1489b89f2279SDavid C Somayajulu 1490b89f2279SDavid C Somayajulu static void 1491b89f2279SDavid C Somayajulu qla_destroy_fp_taskqueues(qla_host_t *ha) 1492b89f2279SDavid C Somayajulu { 1493b89f2279SDavid C Somayajulu int i; 1494b89f2279SDavid C Somayajulu 1495b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 1496b89f2279SDavid C Somayajulu 1497b89f2279SDavid C Somayajulu qla_tx_fp_t *fp = &ha->tx_fp[i]; 1498b89f2279SDavid C Somayajulu 1499b89f2279SDavid C Somayajulu if (fp->fp_taskqueue != NULL) { 1500b89f2279SDavid C Somayajulu taskqueue_drain(fp->fp_taskqueue, &fp->fp_task); 1501b89f2279SDavid C Somayajulu taskqueue_free(fp->fp_taskqueue); 1502b89f2279SDavid C Somayajulu fp->fp_taskqueue = NULL; 1503b89f2279SDavid C Somayajulu } 1504b89f2279SDavid C Somayajulu } 1505b89f2279SDavid C Somayajulu return; 1506b89f2279SDavid C Somayajulu } 1507b89f2279SDavid C Somayajulu 1508b89f2279SDavid C Somayajulu static void 1509b89f2279SDavid C Somayajulu qla_drain_fp_taskqueues(qla_host_t *ha) 1510b89f2279SDavid C Somayajulu { 1511b89f2279SDavid C Somayajulu int i; 1512b89f2279SDavid C Somayajulu 1513b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 1514b89f2279SDavid C Somayajulu qla_tx_fp_t *fp = &ha->tx_fp[i]; 1515b89f2279SDavid C Somayajulu 1516b89f2279SDavid C Somayajulu if (fp->fp_taskqueue != NULL) { 1517b89f2279SDavid C Somayajulu taskqueue_drain(fp->fp_taskqueue, &fp->fp_task); 1518b89f2279SDavid C Somayajulu } 1519b89f2279SDavid C Somayajulu } 1520b89f2279SDavid C Somayajulu return; 1521b89f2279SDavid C Somayajulu } 1522b89f2279SDavid C Somayajulu 1523b89f2279SDavid C Somayajulu static int 1524b89f2279SDavid C Somayajulu qla_transmit(struct ifnet *ifp, struct mbuf *mp) 1525b89f2279SDavid C Somayajulu { 1526b89f2279SDavid C Somayajulu qla_host_t *ha = (qla_host_t *)ifp->if_softc; 1527b89f2279SDavid C Somayajulu qla_tx_fp_t *fp; 1528b89f2279SDavid C Somayajulu int rss_id = 0; 1529b89f2279SDavid C Somayajulu int ret = 0; 1530b89f2279SDavid C Somayajulu 1531b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__)); 1532b89f2279SDavid C Somayajulu 1533b89f2279SDavid C Somayajulu #if __FreeBSD_version >= 1100000 1534b89f2279SDavid C Somayajulu if (M_HASHTYPE_GET(mp) != M_HASHTYPE_NONE) 1535b89f2279SDavid C Somayajulu #else 1536b89f2279SDavid C Somayajulu if (mp->m_flags & M_FLOWID) 1537b89f2279SDavid C Somayajulu #endif 1538b89f2279SDavid C Somayajulu rss_id = (mp->m_pkthdr.flowid & Q8_RSS_IND_TBL_MAX_IDX) % 1539b89f2279SDavid C Somayajulu ha->hw.num_sds_rings; 1540b89f2279SDavid C Somayajulu fp = &ha->tx_fp[rss_id]; 1541b89f2279SDavid C Somayajulu 1542b89f2279SDavid C Somayajulu if (fp->tx_br == NULL) { 1543b89f2279SDavid C Somayajulu ret = EINVAL; 1544b89f2279SDavid C Somayajulu goto qla_transmit_exit; 1545b89f2279SDavid C Somayajulu } 1546b89f2279SDavid C Somayajulu 1547b89f2279SDavid C Somayajulu if (mp != NULL) { 1548b89f2279SDavid C Somayajulu ret = drbr_enqueue(ifp, fp->tx_br, mp); 1549b89f2279SDavid C Somayajulu } 1550b89f2279SDavid C Somayajulu 1551b89f2279SDavid C Somayajulu if (fp->fp_taskqueue != NULL) 1552b89f2279SDavid C Somayajulu taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task); 1553b89f2279SDavid C Somayajulu 1554b89f2279SDavid C Somayajulu ret = 0; 1555b89f2279SDavid C Somayajulu 1556b89f2279SDavid C Somayajulu qla_transmit_exit: 1557b89f2279SDavid C Somayajulu 1558b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = %d\n", __func__, ret)); 1559b89f2279SDavid C Somayajulu return ret; 1560b89f2279SDavid C Somayajulu } 1561b89f2279SDavid C Somayajulu 1562b89f2279SDavid C Somayajulu static void 1563b89f2279SDavid C Somayajulu qla_qflush(struct ifnet *ifp) 1564b89f2279SDavid C Somayajulu { 1565b89f2279SDavid C Somayajulu int i; 1566b89f2279SDavid C Somayajulu qla_tx_fp_t *fp; 1567b89f2279SDavid C Somayajulu struct mbuf *mp; 1568b89f2279SDavid C Somayajulu qla_host_t *ha; 1569b89f2279SDavid C Somayajulu 1570b89f2279SDavid C Somayajulu ha = (qla_host_t *)ifp->if_softc; 1571b89f2279SDavid C Somayajulu 1572b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__)); 1573b89f2279SDavid C Somayajulu 1574b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 1575b89f2279SDavid C Somayajulu 1576b89f2279SDavid C Somayajulu fp = &ha->tx_fp[i]; 1577b89f2279SDavid C Somayajulu 1578b89f2279SDavid C Somayajulu if (fp == NULL) 1579b89f2279SDavid C Somayajulu continue; 1580b89f2279SDavid C Somayajulu 1581b89f2279SDavid C Somayajulu if (fp->tx_br) { 1582b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx); 1583b89f2279SDavid C Somayajulu 1584b89f2279SDavid C Somayajulu while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) { 1585b89f2279SDavid C Somayajulu m_freem(mp); 1586b89f2279SDavid C Somayajulu } 1587b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx); 1588b89f2279SDavid C Somayajulu } 1589b89f2279SDavid C Somayajulu } 1590b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__)); 1591b89f2279SDavid C Somayajulu 1592b89f2279SDavid C Somayajulu return; 1593b89f2279SDavid C Somayajulu } 1594b89f2279SDavid C Somayajulu 1595f10a77bbSDavid C Somayajulu static void 1596f10a77bbSDavid C Somayajulu qla_stop(qla_host_t *ha) 1597f10a77bbSDavid C Somayajulu { 1598f10a77bbSDavid C Somayajulu struct ifnet *ifp = ha->ifp; 1599f10a77bbSDavid C Somayajulu device_t dev; 1600b89f2279SDavid C Somayajulu int i = 0; 1601f10a77bbSDavid C Somayajulu 1602f10a77bbSDavid C Somayajulu dev = ha->pci_dev; 1603f10a77bbSDavid C Somayajulu 16047fb51846SDavid C Somayajulu ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 16057fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 1; 1606b89f2279SDavid C Somayajulu 1607b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 1608b89f2279SDavid C Somayajulu qla_tx_fp_t *fp; 1609b89f2279SDavid C Somayajulu 1610b89f2279SDavid C Somayajulu fp = &ha->tx_fp[i]; 1611b89f2279SDavid C Somayajulu 1612b89f2279SDavid C Somayajulu if (fp == NULL) 1613b89f2279SDavid C Somayajulu continue; 1614b89f2279SDavid C Somayajulu 1615b89f2279SDavid C Somayajulu if (fp->tx_br != NULL) { 1616b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx); 1617b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx); 1618b89f2279SDavid C Somayajulu } 1619b89f2279SDavid C Somayajulu } 1620f10a77bbSDavid C Somayajulu 16217fb51846SDavid C Somayajulu while (!ha->qla_watchdog_paused) 1622f10a77bbSDavid C Somayajulu qla_mdelay(__func__, 1); 1623f10a77bbSDavid C Somayajulu 16247fb51846SDavid C Somayajulu ha->qla_interface_up = 0; 16256a62bec0SDavid C Somayajulu 1626b89f2279SDavid C Somayajulu qla_drain_fp_taskqueues(ha); 1627f10a77bbSDavid C Somayajulu 1628f10a77bbSDavid C Somayajulu ql_del_hw_if(ha); 1629f10a77bbSDavid C Somayajulu 1630f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(ha); 1631f10a77bbSDavid C Somayajulu qla_free_rcv_bufs(ha); 1632f10a77bbSDavid C Somayajulu 1633f10a77bbSDavid C Somayajulu return; 1634f10a77bbSDavid C Somayajulu } 1635f10a77bbSDavid C Somayajulu 1636f10a77bbSDavid C Somayajulu /* 1637f10a77bbSDavid C Somayajulu * Buffer Management Functions for Transmit and Receive Rings 1638f10a77bbSDavid C Somayajulu */ 1639f10a77bbSDavid C Somayajulu static int 1640f10a77bbSDavid C Somayajulu qla_alloc_xmt_bufs(qla_host_t *ha) 1641f10a77bbSDavid C Somayajulu { 1642f10a77bbSDavid C Somayajulu int ret = 0; 1643f10a77bbSDavid C Somayajulu uint32_t i, j; 1644f10a77bbSDavid C Somayajulu qla_tx_buf_t *txb; 1645f10a77bbSDavid C Somayajulu 1646f10a77bbSDavid C Somayajulu if (bus_dma_tag_create(NULL, /* parent */ 1647f10a77bbSDavid C Somayajulu 1, 0, /* alignment, bounds */ 1648f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* lowaddr */ 1649f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* highaddr */ 1650f10a77bbSDavid C Somayajulu NULL, NULL, /* filter, filterarg */ 1651f10a77bbSDavid C Somayajulu QLA_MAX_TSO_FRAME_SIZE, /* maxsize */ 1652f10a77bbSDavid C Somayajulu QLA_MAX_SEGMENTS, /* nsegments */ 1653f10a77bbSDavid C Somayajulu PAGE_SIZE, /* maxsegsize */ 1654f10a77bbSDavid C Somayajulu BUS_DMA_ALLOCNOW, /* flags */ 1655f10a77bbSDavid C Somayajulu NULL, /* lockfunc */ 1656f10a77bbSDavid C Somayajulu NULL, /* lockfuncarg */ 1657f10a77bbSDavid C Somayajulu &ha->tx_tag)) { 1658f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, "%s: tx_tag alloc failed\n", 1659f10a77bbSDavid C Somayajulu __func__); 1660f10a77bbSDavid C Somayajulu return (ENOMEM); 1661f10a77bbSDavid C Somayajulu } 1662f10a77bbSDavid C Somayajulu 1663f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_tx_rings; i++) { 1664f10a77bbSDavid C Somayajulu bzero((void *)ha->tx_ring[i].tx_buf, 1665f10a77bbSDavid C Somayajulu (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS)); 1666f10a77bbSDavid C Somayajulu } 1667f10a77bbSDavid C Somayajulu 1668f10a77bbSDavid C Somayajulu for (j = 0; j < ha->hw.num_tx_rings; j++) { 1669f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_TX_DESCRIPTORS; i++) { 1670f10a77bbSDavid C Somayajulu 1671f10a77bbSDavid C Somayajulu txb = &ha->tx_ring[j].tx_buf[i]; 1672f10a77bbSDavid C Somayajulu 1673f10a77bbSDavid C Somayajulu if ((ret = bus_dmamap_create(ha->tx_tag, 1674f10a77bbSDavid C Somayajulu BUS_DMA_NOWAIT, &txb->map))) { 1675f10a77bbSDavid C Somayajulu 1676f10a77bbSDavid C Somayajulu ha->err_tx_dmamap_create++; 1677f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, 1678f10a77bbSDavid C Somayajulu "%s: bus_dmamap_create failed[%d]\n", 1679f10a77bbSDavid C Somayajulu __func__, ret); 1680f10a77bbSDavid C Somayajulu 1681f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(ha); 1682f10a77bbSDavid C Somayajulu 1683f10a77bbSDavid C Somayajulu return (ret); 1684f10a77bbSDavid C Somayajulu } 1685f10a77bbSDavid C Somayajulu } 1686f10a77bbSDavid C Somayajulu } 1687f10a77bbSDavid C Somayajulu 1688f10a77bbSDavid C Somayajulu return 0; 1689f10a77bbSDavid C Somayajulu } 1690f10a77bbSDavid C Somayajulu 1691f10a77bbSDavid C Somayajulu /* 1692f10a77bbSDavid C Somayajulu * Release mbuf after it sent on the wire 1693f10a77bbSDavid C Somayajulu */ 1694f10a77bbSDavid C Somayajulu static void 1695f10a77bbSDavid C Somayajulu qla_clear_tx_buf(qla_host_t *ha, qla_tx_buf_t *txb) 1696f10a77bbSDavid C Somayajulu { 1697f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__)); 1698f10a77bbSDavid C Somayajulu 1699203f9d18SDavid C Somayajulu if (txb->m_head) { 1700203f9d18SDavid C Somayajulu bus_dmamap_sync(ha->tx_tag, txb->map, 1701203f9d18SDavid C Somayajulu BUS_DMASYNC_POSTWRITE); 1702f10a77bbSDavid C Somayajulu 1703f10a77bbSDavid C Somayajulu bus_dmamap_unload(ha->tx_tag, txb->map); 1704f10a77bbSDavid C Somayajulu 1705f10a77bbSDavid C Somayajulu m_freem(txb->m_head); 1706f10a77bbSDavid C Somayajulu txb->m_head = NULL; 1707203f9d18SDavid C Somayajulu 1708203f9d18SDavid C Somayajulu bus_dmamap_destroy(ha->tx_tag, txb->map); 1709203f9d18SDavid C Somayajulu txb->map = NULL; 1710f10a77bbSDavid C Somayajulu } 1711f10a77bbSDavid C Somayajulu 1712203f9d18SDavid C Somayajulu if (txb->map) { 1713203f9d18SDavid C Somayajulu bus_dmamap_unload(ha->tx_tag, txb->map); 1714f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->tx_tag, txb->map); 1715203f9d18SDavid C Somayajulu txb->map = NULL; 1716203f9d18SDavid C Somayajulu } 1717f10a77bbSDavid C Somayajulu 1718f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__)); 1719f10a77bbSDavid C Somayajulu } 1720f10a77bbSDavid C Somayajulu 1721f10a77bbSDavid C Somayajulu static void 1722f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(qla_host_t *ha) 1723f10a77bbSDavid C Somayajulu { 1724f10a77bbSDavid C Somayajulu int i, j; 1725f10a77bbSDavid C Somayajulu 1726f10a77bbSDavid C Somayajulu for (j = 0; j < ha->hw.num_tx_rings; j++) { 1727f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_TX_DESCRIPTORS; i++) 1728f10a77bbSDavid C Somayajulu qla_clear_tx_buf(ha, &ha->tx_ring[j].tx_buf[i]); 1729f10a77bbSDavid C Somayajulu } 1730f10a77bbSDavid C Somayajulu 1731f10a77bbSDavid C Somayajulu if (ha->tx_tag != NULL) { 1732f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(ha->tx_tag); 1733f10a77bbSDavid C Somayajulu ha->tx_tag = NULL; 1734f10a77bbSDavid C Somayajulu } 1735f10a77bbSDavid C Somayajulu 1736f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_tx_rings; i++) { 1737f10a77bbSDavid C Somayajulu bzero((void *)ha->tx_ring[i].tx_buf, 1738f10a77bbSDavid C Somayajulu (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS)); 1739f10a77bbSDavid C Somayajulu } 1740f10a77bbSDavid C Somayajulu return; 1741f10a77bbSDavid C Somayajulu } 1742f10a77bbSDavid C Somayajulu 1743f10a77bbSDavid C Somayajulu 1744f10a77bbSDavid C Somayajulu static int 1745f10a77bbSDavid C Somayajulu qla_alloc_rcv_std(qla_host_t *ha) 1746f10a77bbSDavid C Somayajulu { 1747f10a77bbSDavid C Somayajulu int i, j, k, r, ret = 0; 1748f10a77bbSDavid C Somayajulu qla_rx_buf_t *rxb; 1749f10a77bbSDavid C Somayajulu qla_rx_ring_t *rx_ring; 1750f10a77bbSDavid C Somayajulu 1751f10a77bbSDavid C Somayajulu for (r = 0; r < ha->hw.num_rds_rings; r++) { 1752f10a77bbSDavid C Somayajulu 1753f10a77bbSDavid C Somayajulu rx_ring = &ha->rx_ring[r]; 1754f10a77bbSDavid C Somayajulu 1755f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_RX_DESCRIPTORS; i++) { 1756f10a77bbSDavid C Somayajulu 1757f10a77bbSDavid C Somayajulu rxb = &rx_ring->rx_buf[i]; 1758f10a77bbSDavid C Somayajulu 1759f10a77bbSDavid C Somayajulu ret = bus_dmamap_create(ha->rx_tag, BUS_DMA_NOWAIT, 1760f10a77bbSDavid C Somayajulu &rxb->map); 1761f10a77bbSDavid C Somayajulu 1762f10a77bbSDavid C Somayajulu if (ret) { 1763f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, 1764f10a77bbSDavid C Somayajulu "%s: dmamap[%d, %d] failed\n", 1765f10a77bbSDavid C Somayajulu __func__, r, i); 1766f10a77bbSDavid C Somayajulu 1767f10a77bbSDavid C Somayajulu for (k = 0; k < r; k++) { 1768f10a77bbSDavid C Somayajulu for (j = 0; j < NUM_RX_DESCRIPTORS; 1769f10a77bbSDavid C Somayajulu j++) { 1770f10a77bbSDavid C Somayajulu rxb = &ha->rx_ring[k].rx_buf[j]; 1771f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->rx_tag, 1772f10a77bbSDavid C Somayajulu rxb->map); 1773f10a77bbSDavid C Somayajulu } 1774f10a77bbSDavid C Somayajulu } 1775f10a77bbSDavid C Somayajulu 1776f10a77bbSDavid C Somayajulu for (j = 0; j < i; j++) { 1777f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->rx_tag, 1778f10a77bbSDavid C Somayajulu rx_ring->rx_buf[j].map); 1779f10a77bbSDavid C Somayajulu } 1780f10a77bbSDavid C Somayajulu goto qla_alloc_rcv_std_err; 1781f10a77bbSDavid C Somayajulu } 1782f10a77bbSDavid C Somayajulu } 1783f10a77bbSDavid C Somayajulu } 1784f10a77bbSDavid C Somayajulu 1785f10a77bbSDavid C Somayajulu qla_init_hw_rcv_descriptors(ha); 1786f10a77bbSDavid C Somayajulu 1787f10a77bbSDavid C Somayajulu 1788f10a77bbSDavid C Somayajulu for (r = 0; r < ha->hw.num_rds_rings; r++) { 1789f10a77bbSDavid C Somayajulu 1790f10a77bbSDavid C Somayajulu rx_ring = &ha->rx_ring[r]; 1791f10a77bbSDavid C Somayajulu 1792f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_RX_DESCRIPTORS; i++) { 1793f10a77bbSDavid C Somayajulu rxb = &rx_ring->rx_buf[i]; 1794f10a77bbSDavid C Somayajulu rxb->handle = i; 1795f10a77bbSDavid C Somayajulu if (!(ret = ql_get_mbuf(ha, rxb, NULL))) { 1796f10a77bbSDavid C Somayajulu /* 1797f10a77bbSDavid C Somayajulu * set the physical address in the 1798f10a77bbSDavid C Somayajulu * corresponding descriptor entry in the 1799f10a77bbSDavid C Somayajulu * receive ring/queue for the hba 1800f10a77bbSDavid C Somayajulu */ 1801f10a77bbSDavid C Somayajulu qla_set_hw_rcv_desc(ha, r, i, rxb->handle, 1802f10a77bbSDavid C Somayajulu rxb->paddr, 1803f10a77bbSDavid C Somayajulu (rxb->m_head)->m_pkthdr.len); 1804f10a77bbSDavid C Somayajulu } else { 1805f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, 1806f10a77bbSDavid C Somayajulu "%s: ql_get_mbuf [%d, %d] failed\n", 1807f10a77bbSDavid C Somayajulu __func__, r, i); 1808f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->rx_tag, rxb->map); 1809f10a77bbSDavid C Somayajulu goto qla_alloc_rcv_std_err; 1810f10a77bbSDavid C Somayajulu } 1811f10a77bbSDavid C Somayajulu } 1812f10a77bbSDavid C Somayajulu } 1813f10a77bbSDavid C Somayajulu return 0; 1814f10a77bbSDavid C Somayajulu 1815f10a77bbSDavid C Somayajulu qla_alloc_rcv_std_err: 1816f10a77bbSDavid C Somayajulu return (-1); 1817f10a77bbSDavid C Somayajulu } 1818f10a77bbSDavid C Somayajulu 1819f10a77bbSDavid C Somayajulu static void 1820f10a77bbSDavid C Somayajulu qla_free_rcv_std(qla_host_t *ha) 1821f10a77bbSDavid C Somayajulu { 1822f10a77bbSDavid C Somayajulu int i, r; 1823f10a77bbSDavid C Somayajulu qla_rx_buf_t *rxb; 1824f10a77bbSDavid C Somayajulu 1825f10a77bbSDavid C Somayajulu for (r = 0; r < ha->hw.num_rds_rings; r++) { 1826f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_RX_DESCRIPTORS; i++) { 1827f10a77bbSDavid C Somayajulu rxb = &ha->rx_ring[r].rx_buf[i]; 1828f10a77bbSDavid C Somayajulu if (rxb->m_head != NULL) { 1829f10a77bbSDavid C Somayajulu bus_dmamap_unload(ha->rx_tag, rxb->map); 1830f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->rx_tag, rxb->map); 1831f10a77bbSDavid C Somayajulu m_freem(rxb->m_head); 1832f10a77bbSDavid C Somayajulu rxb->m_head = NULL; 1833f10a77bbSDavid C Somayajulu } 1834f10a77bbSDavid C Somayajulu } 1835f10a77bbSDavid C Somayajulu } 1836f10a77bbSDavid C Somayajulu return; 1837f10a77bbSDavid C Somayajulu } 1838f10a77bbSDavid C Somayajulu 1839f10a77bbSDavid C Somayajulu static int 1840f10a77bbSDavid C Somayajulu qla_alloc_rcv_bufs(qla_host_t *ha) 1841f10a77bbSDavid C Somayajulu { 1842f10a77bbSDavid C Somayajulu int i, ret = 0; 1843f10a77bbSDavid C Somayajulu 1844f10a77bbSDavid C Somayajulu if (bus_dma_tag_create(NULL, /* parent */ 1845f10a77bbSDavid C Somayajulu 1, 0, /* alignment, bounds */ 1846f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* lowaddr */ 1847f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* highaddr */ 1848f10a77bbSDavid C Somayajulu NULL, NULL, /* filter, filterarg */ 1849f10a77bbSDavid C Somayajulu MJUM9BYTES, /* maxsize */ 1850f10a77bbSDavid C Somayajulu 1, /* nsegments */ 1851f10a77bbSDavid C Somayajulu MJUM9BYTES, /* maxsegsize */ 1852f10a77bbSDavid C Somayajulu BUS_DMA_ALLOCNOW, /* flags */ 1853f10a77bbSDavid C Somayajulu NULL, /* lockfunc */ 1854f10a77bbSDavid C Somayajulu NULL, /* lockfuncarg */ 1855f10a77bbSDavid C Somayajulu &ha->rx_tag)) { 1856f10a77bbSDavid C Somayajulu 1857f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, "%s: rx_tag alloc failed\n", 1858f10a77bbSDavid C Somayajulu __func__); 1859f10a77bbSDavid C Somayajulu 1860f10a77bbSDavid C Somayajulu return (ENOMEM); 1861f10a77bbSDavid C Somayajulu } 1862f10a77bbSDavid C Somayajulu 1863f10a77bbSDavid C Somayajulu bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS)); 1864f10a77bbSDavid C Somayajulu 1865f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 1866f10a77bbSDavid C Somayajulu ha->hw.sds[i].sdsr_next = 0; 1867f10a77bbSDavid C Somayajulu ha->hw.sds[i].rxb_free = NULL; 1868f10a77bbSDavid C Somayajulu ha->hw.sds[i].rx_free = 0; 1869f10a77bbSDavid C Somayajulu } 1870f10a77bbSDavid C Somayajulu 1871f10a77bbSDavid C Somayajulu ret = qla_alloc_rcv_std(ha); 1872f10a77bbSDavid C Somayajulu 1873f10a77bbSDavid C Somayajulu return (ret); 1874f10a77bbSDavid C Somayajulu } 1875f10a77bbSDavid C Somayajulu 1876f10a77bbSDavid C Somayajulu static void 1877f10a77bbSDavid C Somayajulu qla_free_rcv_bufs(qla_host_t *ha) 1878f10a77bbSDavid C Somayajulu { 1879f10a77bbSDavid C Somayajulu int i; 1880f10a77bbSDavid C Somayajulu 1881f10a77bbSDavid C Somayajulu qla_free_rcv_std(ha); 1882f10a77bbSDavid C Somayajulu 1883f10a77bbSDavid C Somayajulu if (ha->rx_tag != NULL) { 1884f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(ha->rx_tag); 1885f10a77bbSDavid C Somayajulu ha->rx_tag = NULL; 1886f10a77bbSDavid C Somayajulu } 1887f10a77bbSDavid C Somayajulu 1888f10a77bbSDavid C Somayajulu bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS)); 1889f10a77bbSDavid C Somayajulu 1890f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 1891f10a77bbSDavid C Somayajulu ha->hw.sds[i].sdsr_next = 0; 1892f10a77bbSDavid C Somayajulu ha->hw.sds[i].rxb_free = NULL; 1893f10a77bbSDavid C Somayajulu ha->hw.sds[i].rx_free = 0; 1894f10a77bbSDavid C Somayajulu } 1895f10a77bbSDavid C Somayajulu 1896f10a77bbSDavid C Somayajulu return; 1897f10a77bbSDavid C Somayajulu } 1898f10a77bbSDavid C Somayajulu 1899f10a77bbSDavid C Somayajulu int 1900f10a77bbSDavid C Somayajulu ql_get_mbuf(qla_host_t *ha, qla_rx_buf_t *rxb, struct mbuf *nmp) 1901f10a77bbSDavid C Somayajulu { 19027fb51846SDavid C Somayajulu register struct mbuf *mp = nmp; 1903f10a77bbSDavid C Somayajulu struct ifnet *ifp; 1904f10a77bbSDavid C Somayajulu int ret = 0; 1905f10a77bbSDavid C Somayajulu uint32_t offset; 1906f10a77bbSDavid C Somayajulu bus_dma_segment_t segs[1]; 190735291c22SDavid C Somayajulu int nsegs, mbuf_size; 1908f10a77bbSDavid C Somayajulu 1909f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__)); 1910f10a77bbSDavid C Somayajulu 1911f10a77bbSDavid C Somayajulu ifp = ha->ifp; 1912f10a77bbSDavid C Somayajulu 191335291c22SDavid C Somayajulu if (ha->hw.enable_9kb) 191435291c22SDavid C Somayajulu mbuf_size = MJUM9BYTES; 191535291c22SDavid C Somayajulu else 191635291c22SDavid C Somayajulu mbuf_size = MCLBYTES; 191735291c22SDavid C Somayajulu 1918f10a77bbSDavid C Somayajulu if (mp == NULL) { 1919f10a77bbSDavid C Somayajulu 192000caeec7SDavid C Somayajulu if (QL_ERR_INJECT(ha, INJCT_M_GETCL_M_GETJCL_FAILURE)) 192100caeec7SDavid C Somayajulu return(-1); 192200caeec7SDavid C Somayajulu 192335291c22SDavid C Somayajulu if (ha->hw.enable_9kb) 192435291c22SDavid C Somayajulu mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, mbuf_size); 192535291c22SDavid C Somayajulu else 1926f10a77bbSDavid C Somayajulu mp = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); 1927f10a77bbSDavid C Somayajulu 1928f10a77bbSDavid C Somayajulu if (mp == NULL) { 1929f10a77bbSDavid C Somayajulu ha->err_m_getcl++; 1930f10a77bbSDavid C Somayajulu ret = ENOBUFS; 1931f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, 1932f10a77bbSDavid C Somayajulu "%s: m_getcl failed\n", __func__); 1933f10a77bbSDavid C Somayajulu goto exit_ql_get_mbuf; 1934f10a77bbSDavid C Somayajulu } 193535291c22SDavid C Somayajulu mp->m_len = mp->m_pkthdr.len = mbuf_size; 1936f10a77bbSDavid C Somayajulu } else { 193735291c22SDavid C Somayajulu mp->m_len = mp->m_pkthdr.len = mbuf_size; 1938f10a77bbSDavid C Somayajulu mp->m_data = mp->m_ext.ext_buf; 1939f10a77bbSDavid C Somayajulu mp->m_next = NULL; 1940f10a77bbSDavid C Somayajulu } 1941f10a77bbSDavid C Somayajulu 1942f10a77bbSDavid C Somayajulu offset = (uint32_t)((unsigned long long)mp->m_data & 0x7ULL); 1943f10a77bbSDavid C Somayajulu if (offset) { 1944f10a77bbSDavid C Somayajulu offset = 8 - offset; 1945f10a77bbSDavid C Somayajulu m_adj(mp, offset); 1946f10a77bbSDavid C Somayajulu } 1947f10a77bbSDavid C Somayajulu 1948f10a77bbSDavid C Somayajulu /* 1949f10a77bbSDavid C Somayajulu * Using memory from the mbuf cluster pool, invoke the bus_dma 1950f10a77bbSDavid C Somayajulu * machinery to arrange the memory mapping. 1951f10a77bbSDavid C Somayajulu */ 1952f10a77bbSDavid C Somayajulu ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, rxb->map, 1953f10a77bbSDavid C Somayajulu mp, segs, &nsegs, BUS_DMA_NOWAIT); 1954f10a77bbSDavid C Somayajulu rxb->paddr = segs[0].ds_addr; 1955f10a77bbSDavid C Somayajulu 1956f10a77bbSDavid C Somayajulu if (ret || !rxb->paddr || (nsegs != 1)) { 1957f10a77bbSDavid C Somayajulu m_free(mp); 1958f10a77bbSDavid C Somayajulu rxb->m_head = NULL; 1959f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, 1960f10a77bbSDavid C Somayajulu "%s: bus_dmamap_load failed[%d, 0x%016llx, %d]\n", 1961f10a77bbSDavid C Somayajulu __func__, ret, (long long unsigned int)rxb->paddr, 1962f10a77bbSDavid C Somayajulu nsegs); 1963f10a77bbSDavid C Somayajulu ret = -1; 1964f10a77bbSDavid C Somayajulu goto exit_ql_get_mbuf; 1965f10a77bbSDavid C Somayajulu } 1966f10a77bbSDavid C Somayajulu rxb->m_head = mp; 1967f10a77bbSDavid C Somayajulu bus_dmamap_sync(ha->rx_tag, rxb->map, BUS_DMASYNC_PREREAD); 1968f10a77bbSDavid C Somayajulu 1969f10a77bbSDavid C Somayajulu exit_ql_get_mbuf: 1970f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = 0x%08x\n", __func__, ret)); 1971f10a77bbSDavid C Somayajulu return (ret); 1972f10a77bbSDavid C Somayajulu } 1973f10a77bbSDavid C Somayajulu 1974f10a77bbSDavid C Somayajulu 1975f10a77bbSDavid C Somayajulu static void 1976f10a77bbSDavid C Somayajulu qla_get_peer(qla_host_t *ha) 1977f10a77bbSDavid C Somayajulu { 1978f10a77bbSDavid C Somayajulu device_t *peers; 1979f10a77bbSDavid C Somayajulu int count, i, slot; 1980f10a77bbSDavid C Somayajulu int my_slot = pci_get_slot(ha->pci_dev); 1981f10a77bbSDavid C Somayajulu 1982f10a77bbSDavid C Somayajulu if (device_get_children(device_get_parent(ha->pci_dev), &peers, &count)) 1983f10a77bbSDavid C Somayajulu return; 1984f10a77bbSDavid C Somayajulu 1985f10a77bbSDavid C Somayajulu for (i = 0; i < count; i++) { 1986f10a77bbSDavid C Somayajulu slot = pci_get_slot(peers[i]); 1987f10a77bbSDavid C Somayajulu 1988f10a77bbSDavid C Somayajulu if ((slot >= 0) && (slot == my_slot) && 1989f10a77bbSDavid C Somayajulu (pci_get_device(peers[i]) == 1990f10a77bbSDavid C Somayajulu pci_get_device(ha->pci_dev))) { 1991f10a77bbSDavid C Somayajulu if (ha->pci_dev != peers[i]) 1992f10a77bbSDavid C Somayajulu ha->peer_dev = peers[i]; 1993f10a77bbSDavid C Somayajulu } 1994f10a77bbSDavid C Somayajulu } 1995f10a77bbSDavid C Somayajulu } 1996f10a77bbSDavid C Somayajulu 1997f10a77bbSDavid C Somayajulu static void 1998f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(qla_host_t *ha, uint32_t msg_to_peer) 1999f10a77bbSDavid C Somayajulu { 2000f10a77bbSDavid C Somayajulu qla_host_t *ha_peer; 2001f10a77bbSDavid C Somayajulu 2002f10a77bbSDavid C Somayajulu if (ha->peer_dev) { 2003f10a77bbSDavid C Somayajulu if ((ha_peer = device_get_softc(ha->peer_dev)) != NULL) { 2004f10a77bbSDavid C Somayajulu 2005f10a77bbSDavid C Somayajulu ha_peer->msg_from_peer = msg_to_peer; 2006f10a77bbSDavid C Somayajulu } 2007f10a77bbSDavid C Somayajulu } 2008f10a77bbSDavid C Somayajulu } 2009f10a77bbSDavid C Somayajulu 2010f10a77bbSDavid C Somayajulu static void 2011f10a77bbSDavid C Somayajulu qla_error_recovery(void *context, int pending) 2012f10a77bbSDavid C Somayajulu { 2013f10a77bbSDavid C Somayajulu qla_host_t *ha = context; 2014f10a77bbSDavid C Somayajulu uint32_t msecs_100 = 100; 2015f10a77bbSDavid C Somayajulu struct ifnet *ifp = ha->ifp; 2016b89f2279SDavid C Somayajulu int i = 0; 2017f10a77bbSDavid C Somayajulu 20187fb51846SDavid C Somayajulu device_printf(ha->pci_dev, "%s: \n", __func__); 201935291c22SDavid C Somayajulu ha->hw.imd_compl = 1; 2020423ec132SDavid C Somayajulu 20217fb51846SDavid C Somayajulu if (QLA_LOCK(ha, __func__, -1, 0) != 0) 20227fb51846SDavid C Somayajulu return; 202335291c22SDavid C Somayajulu 20247fb51846SDavid C Somayajulu device_printf(ha->pci_dev, "%s: enter\n", __func__); 20257fb51846SDavid C Somayajulu 20267fb51846SDavid C Somayajulu if (ha->qla_interface_up) { 20277fb51846SDavid C Somayajulu 20287fb51846SDavid C Somayajulu qla_mdelay(__func__, 300); 20297fb51846SDavid C Somayajulu 20307fb51846SDavid C Somayajulu ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 2031b89f2279SDavid C Somayajulu 2032b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) { 2033b89f2279SDavid C Somayajulu qla_tx_fp_t *fp; 2034b89f2279SDavid C Somayajulu 2035b89f2279SDavid C Somayajulu fp = &ha->tx_fp[i]; 2036b89f2279SDavid C Somayajulu 2037b89f2279SDavid C Somayajulu if (fp == NULL) 2038b89f2279SDavid C Somayajulu continue; 2039b89f2279SDavid C Somayajulu 2040b89f2279SDavid C Somayajulu if (fp->tx_br != NULL) { 2041b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx); 2042b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx); 2043b89f2279SDavid C Somayajulu } 2044b89f2279SDavid C Somayajulu } 20456a62bec0SDavid C Somayajulu } 2046f10a77bbSDavid C Somayajulu 2047f10a77bbSDavid C Somayajulu 204877d57b28SDavid C Somayajulu qla_drain_fp_taskqueues(ha); 204977d57b28SDavid C Somayajulu 2050f10a77bbSDavid C Somayajulu if ((ha->pci_func & 0x1) == 0) { 2051f10a77bbSDavid C Somayajulu 2052bcafe874SDavid C Somayajulu if (!ha->msg_from_peer) { 2053f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET); 2054f10a77bbSDavid C Somayajulu 2055bcafe874SDavid C Somayajulu while ((ha->msg_from_peer != QL_PEER_MSG_ACK) && 2056bcafe874SDavid C Somayajulu msecs_100--) 2057f10a77bbSDavid C Somayajulu qla_mdelay(__func__, 100); 2058bcafe874SDavid C Somayajulu } 2059f10a77bbSDavid C Somayajulu 2060f10a77bbSDavid C Somayajulu ha->msg_from_peer = 0; 2061f10a77bbSDavid C Somayajulu 20621faeac0fSDavid C Somayajulu if (ha->enable_minidump) 206367ffef6bSDavid C Somayajulu ql_minidump(ha); 20649a5f7854SDavid C Somayajulu 2065f10a77bbSDavid C Somayajulu (void) ql_init_hw(ha); 20666a62bec0SDavid C Somayajulu 20677fb51846SDavid C Somayajulu if (ha->qla_interface_up) { 2068f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(ha); 2069f10a77bbSDavid C Somayajulu qla_free_rcv_bufs(ha); 20706a62bec0SDavid C Somayajulu } 20719a5f7854SDavid C Somayajulu 2072f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK); 2073f10a77bbSDavid C Somayajulu 2074f10a77bbSDavid C Somayajulu } else { 2075f10a77bbSDavid C Somayajulu if (ha->msg_from_peer == QL_PEER_MSG_RESET) { 2076f10a77bbSDavid C Somayajulu 2077f10a77bbSDavid C Somayajulu ha->msg_from_peer = 0; 2078f10a77bbSDavid C Somayajulu 2079f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK); 2080f10a77bbSDavid C Somayajulu } else { 2081f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET); 2082f10a77bbSDavid C Somayajulu } 2083f10a77bbSDavid C Somayajulu 2084f10a77bbSDavid C Somayajulu while ((ha->msg_from_peer != QL_PEER_MSG_ACK) && msecs_100--) 2085f10a77bbSDavid C Somayajulu qla_mdelay(__func__, 100); 2086f10a77bbSDavid C Somayajulu ha->msg_from_peer = 0; 2087f10a77bbSDavid C Somayajulu 2088f10a77bbSDavid C Somayajulu (void) ql_init_hw(ha); 20896a62bec0SDavid C Somayajulu 20907fb51846SDavid C Somayajulu qla_mdelay(__func__, 1000); 20919a5f7854SDavid C Somayajulu 20927fb51846SDavid C Somayajulu if (ha->qla_interface_up) { 2093f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(ha); 2094f10a77bbSDavid C Somayajulu qla_free_rcv_bufs(ha); 2095f10a77bbSDavid C Somayajulu } 20966a62bec0SDavid C Somayajulu } 20976a62bec0SDavid C Somayajulu 20987fb51846SDavid C Somayajulu if (ha->qla_interface_up) { 20999a5f7854SDavid C Somayajulu 2100f10a77bbSDavid C Somayajulu if (qla_alloc_xmt_bufs(ha) != 0) { 21017fb51846SDavid C Somayajulu goto qla_error_recovery_exit; 2102f10a77bbSDavid C Somayajulu } 210335291c22SDavid C Somayajulu qla_confirm_9kb_enable(ha); 2104f10a77bbSDavid C Somayajulu 2105f10a77bbSDavid C Somayajulu if (qla_alloc_rcv_bufs(ha) != 0) { 21067fb51846SDavid C Somayajulu goto qla_error_recovery_exit; 2107f10a77bbSDavid C Somayajulu } 2108f10a77bbSDavid C Somayajulu 21097fb51846SDavid C Somayajulu ha->stop_rcv = 0; 21109a5f7854SDavid C Somayajulu 2111f10a77bbSDavid C Somayajulu if (ql_init_hw_if(ha) == 0) { 2112f10a77bbSDavid C Somayajulu ifp = ha->ifp; 2113f10a77bbSDavid C Somayajulu ifp->if_drv_flags |= IFF_DRV_RUNNING; 21147fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 0; 2115f10a77bbSDavid C Somayajulu } 21166a62bec0SDavid C Somayajulu } else 21177fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 0; 2118f10a77bbSDavid C Somayajulu 21197fb51846SDavid C Somayajulu qla_error_recovery_exit: 21207fb51846SDavid C Somayajulu 21217fb51846SDavid C Somayajulu device_printf(ha->pci_dev, "%s: exit\n", __func__); 21227fb51846SDavid C Somayajulu 21237fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__); 21247fb51846SDavid C Somayajulu 21257fb51846SDavid C Somayajulu callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS, 21267fb51846SDavid C Somayajulu qla_watchdog, ha); 21277fb51846SDavid C Somayajulu return; 2128f10a77bbSDavid C Somayajulu } 2129f10a77bbSDavid C Somayajulu 213035291c22SDavid C Somayajulu static void 213135291c22SDavid C Somayajulu qla_async_event(void *context, int pending) 213235291c22SDavid C Somayajulu { 213335291c22SDavid C Somayajulu qla_host_t *ha = context; 213435291c22SDavid C Somayajulu 21357fb51846SDavid C Somayajulu if (QLA_LOCK(ha, __func__, -1, 0) != 0) 21367fb51846SDavid C Somayajulu return; 21377fb51846SDavid C Somayajulu 21387fb51846SDavid C Somayajulu if (ha->async_event) { 21397fb51846SDavid C Somayajulu ha->async_event = 0; 214035291c22SDavid C Somayajulu qla_hw_async_event(ha); 21417fb51846SDavid C Somayajulu } 21427fb51846SDavid C Somayajulu 21437fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__); 21447fb51846SDavid C Somayajulu 21457fb51846SDavid C Somayajulu return; 21467fb51846SDavid C Somayajulu } 21477fb51846SDavid C Somayajulu 21487fb51846SDavid C Somayajulu static void 21497fb51846SDavid C Somayajulu qla_stats(void *context, int pending) 21507fb51846SDavid C Somayajulu { 21517fb51846SDavid C Somayajulu qla_host_t *ha; 21527fb51846SDavid C Somayajulu 21537fb51846SDavid C Somayajulu ha = context; 21547fb51846SDavid C Somayajulu 21557fb51846SDavid C Somayajulu ql_get_stats(ha); 21567fb51846SDavid C Somayajulu return; 215735291c22SDavid C Somayajulu } 215835291c22SDavid C Somayajulu 2159