1718cf2ccSPedro F. Giffuni /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
435291c22SDavid C Somayajulu * Copyright (c) 2013-2016 Qlogic Corporation
5f10a77bbSDavid C Somayajulu * All rights reserved.
6f10a77bbSDavid C Somayajulu *
7f10a77bbSDavid C Somayajulu * Redistribution and use in source and binary forms, with or without
8f10a77bbSDavid C Somayajulu * modification, are permitted provided that the following conditions
9f10a77bbSDavid C Somayajulu * are met:
10f10a77bbSDavid C Somayajulu *
11f10a77bbSDavid C Somayajulu * 1. Redistributions of source code must retain the above copyright
12f10a77bbSDavid C Somayajulu * notice, this list of conditions and the following disclaimer.
13f10a77bbSDavid C Somayajulu * 2. Redistributions in binary form must reproduce the above copyright
14f10a77bbSDavid C Somayajulu * notice, this list of conditions and the following disclaimer in the
15f10a77bbSDavid C Somayajulu * documentation and/or other materials provided with the distribution.
16f10a77bbSDavid C Somayajulu *
17f10a77bbSDavid C Somayajulu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18f10a77bbSDavid C Somayajulu * and ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19f10a77bbSDavid C Somayajulu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20f10a77bbSDavid C Somayajulu * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21f10a77bbSDavid C Somayajulu * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22f10a77bbSDavid C Somayajulu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23f10a77bbSDavid C Somayajulu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24f10a77bbSDavid C Somayajulu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25f10a77bbSDavid C Somayajulu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26f10a77bbSDavid C Somayajulu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27f10a77bbSDavid C Somayajulu * POSSIBILITY OF SUCH DAMAGE.
28f10a77bbSDavid C Somayajulu */
29f10a77bbSDavid C Somayajulu
30f10a77bbSDavid C Somayajulu /*
31f10a77bbSDavid C Somayajulu * File: ql_os.c
32f10a77bbSDavid C Somayajulu * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
33f10a77bbSDavid C Somayajulu */
34f10a77bbSDavid C Somayajulu
35f10a77bbSDavid C Somayajulu #include <sys/cdefs.h>
36f10a77bbSDavid C Somayajulu #include "ql_os.h"
37f10a77bbSDavid C Somayajulu #include "ql_hw.h"
38f10a77bbSDavid C Somayajulu #include "ql_def.h"
39f10a77bbSDavid C Somayajulu #include "ql_inline.h"
40f10a77bbSDavid C Somayajulu #include "ql_ver.h"
41f10a77bbSDavid C Somayajulu #include "ql_glbl.h"
42f10a77bbSDavid C Somayajulu #include "ql_dbg.h"
43f10a77bbSDavid C Somayajulu #include <sys/smp.h>
44f10a77bbSDavid C Somayajulu
45f10a77bbSDavid C Somayajulu /*
46f10a77bbSDavid C Somayajulu * Some PCI Configuration Space Related Defines
47f10a77bbSDavid C Somayajulu */
48f10a77bbSDavid C Somayajulu
49f10a77bbSDavid C Somayajulu #ifndef PCI_VENDOR_QLOGIC
50f10a77bbSDavid C Somayajulu #define PCI_VENDOR_QLOGIC 0x1077
51f10a77bbSDavid C Somayajulu #endif
52f10a77bbSDavid C Somayajulu
53f10a77bbSDavid C Somayajulu #ifndef PCI_PRODUCT_QLOGIC_ISP8030
54f10a77bbSDavid C Somayajulu #define PCI_PRODUCT_QLOGIC_ISP8030 0x8030
55f10a77bbSDavid C Somayajulu #endif
56f10a77bbSDavid C Somayajulu
57f10a77bbSDavid C Somayajulu #define PCI_QLOGIC_ISP8030 \
58f10a77bbSDavid C Somayajulu ((PCI_PRODUCT_QLOGIC_ISP8030 << 16) | PCI_VENDOR_QLOGIC)
59f10a77bbSDavid C Somayajulu
60f10a77bbSDavid C Somayajulu /*
61f10a77bbSDavid C Somayajulu * static functions
62f10a77bbSDavid C Somayajulu */
63f10a77bbSDavid C Somayajulu static int qla_alloc_parent_dma_tag(qla_host_t *ha);
64f10a77bbSDavid C Somayajulu static void qla_free_parent_dma_tag(qla_host_t *ha);
65f10a77bbSDavid C Somayajulu static int qla_alloc_xmt_bufs(qla_host_t *ha);
66f10a77bbSDavid C Somayajulu static void qla_free_xmt_bufs(qla_host_t *ha);
67f10a77bbSDavid C Somayajulu static int qla_alloc_rcv_bufs(qla_host_t *ha);
68f10a77bbSDavid C Somayajulu static void qla_free_rcv_bufs(qla_host_t *ha);
69f10a77bbSDavid C Somayajulu static void qla_clear_tx_buf(qla_host_t *ha, qla_tx_buf_t *txb);
70f10a77bbSDavid C Somayajulu
71f10a77bbSDavid C Somayajulu static void qla_init_ifnet(device_t dev, qla_host_t *ha);
72f10a77bbSDavid C Somayajulu static int qla_sysctl_get_link_status(SYSCTL_HANDLER_ARGS);
73f10a77bbSDavid C Somayajulu static void qla_release(qla_host_t *ha);
74f10a77bbSDavid C Somayajulu static void qla_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs,
75f10a77bbSDavid C Somayajulu int error);
76f10a77bbSDavid C Somayajulu static void qla_stop(qla_host_t *ha);
77f10a77bbSDavid C Somayajulu static void qla_get_peer(qla_host_t *ha);
78f10a77bbSDavid C Somayajulu static void qla_error_recovery(void *context, int pending);
7935291c22SDavid C Somayajulu static void qla_async_event(void *context, int pending);
807fb51846SDavid C Somayajulu static void qla_stats(void *context, int pending);
81b89f2279SDavid C Somayajulu static int qla_send(qla_host_t *ha, struct mbuf **m_headp, uint32_t txr_idx,
82b89f2279SDavid C Somayajulu uint32_t iscsi_pdu);
83f10a77bbSDavid C Somayajulu
84f10a77bbSDavid C Somayajulu /*
85f10a77bbSDavid C Somayajulu * Hooks to the Operating Systems
86f10a77bbSDavid C Somayajulu */
87f10a77bbSDavid C Somayajulu static int qla_pci_probe (device_t);
88f10a77bbSDavid C Somayajulu static int qla_pci_attach (device_t);
89f10a77bbSDavid C Somayajulu static int qla_pci_detach (device_t);
90f10a77bbSDavid C Somayajulu
91f10a77bbSDavid C Somayajulu static void qla_init(void *arg);
9254ab3b4aSJustin Hibbits static int qla_ioctl(if_t ifp, u_long cmd, caddr_t data);
9354ab3b4aSJustin Hibbits static int qla_media_change(if_t ifp);
9454ab3b4aSJustin Hibbits static void qla_media_status(if_t ifp, struct ifmediareq *ifmr);
95b89f2279SDavid C Somayajulu
9654ab3b4aSJustin Hibbits static int qla_transmit(if_t ifp, struct mbuf *mp);
9754ab3b4aSJustin Hibbits static void qla_qflush(if_t ifp);
98b89f2279SDavid C Somayajulu static int qla_alloc_tx_br(qla_host_t *ha, qla_tx_fp_t *tx_fp);
99b89f2279SDavid C Somayajulu static void qla_free_tx_br(qla_host_t *ha, qla_tx_fp_t *tx_fp);
100b89f2279SDavid C Somayajulu static int qla_create_fp_taskqueues(qla_host_t *ha);
101b89f2279SDavid C Somayajulu static void qla_destroy_fp_taskqueues(qla_host_t *ha);
102b89f2279SDavid C Somayajulu static void qla_drain_fp_taskqueues(qla_host_t *ha);
103f10a77bbSDavid C Somayajulu
104f10a77bbSDavid C Somayajulu static device_method_t qla_pci_methods[] = {
105f10a77bbSDavid C Somayajulu /* Device interface */
106f10a77bbSDavid C Somayajulu DEVMETHOD(device_probe, qla_pci_probe),
107f10a77bbSDavid C Somayajulu DEVMETHOD(device_attach, qla_pci_attach),
108f10a77bbSDavid C Somayajulu DEVMETHOD(device_detach, qla_pci_detach),
109f10a77bbSDavid C Somayajulu { 0, 0 }
110f10a77bbSDavid C Somayajulu };
111f10a77bbSDavid C Somayajulu
112f10a77bbSDavid C Somayajulu static driver_t qla_pci_driver = {
113f10a77bbSDavid C Somayajulu "ql", qla_pci_methods, sizeof (qla_host_t),
114f10a77bbSDavid C Somayajulu };
115f10a77bbSDavid C Somayajulu
1162f87208eSJohn Baldwin DRIVER_MODULE(qla83xx, pci, qla_pci_driver, 0, 0);
117f10a77bbSDavid C Somayajulu
118f10a77bbSDavid C Somayajulu MODULE_DEPEND(qla83xx, pci, 1, 1, 1);
119f10a77bbSDavid C Somayajulu MODULE_DEPEND(qla83xx, ether, 1, 1, 1);
120f10a77bbSDavid C Somayajulu
121f10a77bbSDavid C Somayajulu MALLOC_DEFINE(M_QLA83XXBUF, "qla83xxbuf", "Buffers for qla83xx driver");
122f10a77bbSDavid C Somayajulu
123f10a77bbSDavid C Somayajulu #define QL_STD_REPLENISH_THRES 0
124f10a77bbSDavid C Somayajulu #define QL_JUMBO_REPLENISH_THRES 32
125f10a77bbSDavid C Somayajulu
126f10a77bbSDavid C Somayajulu static char dev_str[64];
12735291c22SDavid C Somayajulu static char ver_str[64];
128f10a77bbSDavid C Somayajulu
129f10a77bbSDavid C Somayajulu /*
130f10a77bbSDavid C Somayajulu * Name: qla_pci_probe
131f10a77bbSDavid C Somayajulu * Function: Validate the PCI device to be a QLA80XX device
132f10a77bbSDavid C Somayajulu */
133f10a77bbSDavid C Somayajulu static int
qla_pci_probe(device_t dev)134f10a77bbSDavid C Somayajulu qla_pci_probe(device_t dev)
135f10a77bbSDavid C Somayajulu {
136f10a77bbSDavid C Somayajulu switch ((pci_get_device(dev) << 16) | (pci_get_vendor(dev))) {
137f10a77bbSDavid C Somayajulu case PCI_QLOGIC_ISP8030:
138f10a77bbSDavid C Somayajulu snprintf(dev_str, sizeof(dev_str), "%s v%d.%d.%d",
139f10a77bbSDavid C Somayajulu "Qlogic ISP 83xx PCI CNA Adapter-Ethernet Function",
140f10a77bbSDavid C Somayajulu QLA_VERSION_MAJOR, QLA_VERSION_MINOR,
141f10a77bbSDavid C Somayajulu QLA_VERSION_BUILD);
14235291c22SDavid C Somayajulu snprintf(ver_str, sizeof(ver_str), "v%d.%d.%d",
14335291c22SDavid C Somayajulu QLA_VERSION_MAJOR, QLA_VERSION_MINOR,
14435291c22SDavid C Somayajulu QLA_VERSION_BUILD);
145f10a77bbSDavid C Somayajulu device_set_desc(dev, dev_str);
146f10a77bbSDavid C Somayajulu break;
147f10a77bbSDavid C Somayajulu default:
148f10a77bbSDavid C Somayajulu return (ENXIO);
149f10a77bbSDavid C Somayajulu }
150f10a77bbSDavid C Somayajulu
151f10a77bbSDavid C Somayajulu if (bootverbose)
152f10a77bbSDavid C Somayajulu printf("%s: %s\n ", __func__, dev_str);
153f10a77bbSDavid C Somayajulu
154f10a77bbSDavid C Somayajulu return (BUS_PROBE_DEFAULT);
155f10a77bbSDavid C Somayajulu }
156f10a77bbSDavid C Somayajulu
157f10a77bbSDavid C Somayajulu static void
qla_add_sysctls(qla_host_t * ha)158f10a77bbSDavid C Somayajulu qla_add_sysctls(qla_host_t *ha)
159f10a77bbSDavid C Somayajulu {
160f10a77bbSDavid C Somayajulu device_t dev = ha->pci_dev;
161f10a77bbSDavid C Somayajulu
16235291c22SDavid C Somayajulu SYSCTL_ADD_STRING(device_get_sysctl_ctx(dev),
16335291c22SDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
16435291c22SDavid C Somayajulu OID_AUTO, "version", CTLFLAG_RD,
16535291c22SDavid C Somayajulu ver_str, 0, "Driver Version");
16635291c22SDavid C Somayajulu
167f10a77bbSDavid C Somayajulu SYSCTL_ADD_STRING(device_get_sysctl_ctx(dev),
168f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
169f10a77bbSDavid C Somayajulu OID_AUTO, "fw_version", CTLFLAG_RD,
170f0188618SHans Petter Selasky ha->fw_ver_str, 0, "firmware version");
171f10a77bbSDavid C Somayajulu
172f10a77bbSDavid C Somayajulu SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1737029da5cSPawel Biernacki SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1747029da5cSPawel Biernacki "link_status", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
1757029da5cSPawel Biernacki (void *)ha, 0, qla_sysctl_get_link_status, "I", "Link Status");
176f10a77bbSDavid C Somayajulu
177f10a77bbSDavid C Somayajulu ha->dbg_level = 0;
178f10a77bbSDavid C Somayajulu SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
179f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
180f10a77bbSDavid C Somayajulu OID_AUTO, "debug", CTLFLAG_RW,
181f10a77bbSDavid C Somayajulu &ha->dbg_level, ha->dbg_level, "Debug Level");
182f10a77bbSDavid C Somayajulu
1831faeac0fSDavid C Somayajulu ha->enable_minidump = 1;
1841faeac0fSDavid C Somayajulu SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
1851faeac0fSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
1861faeac0fSDavid C Somayajulu OID_AUTO, "enable_minidump", CTLFLAG_RW,
1871faeac0fSDavid C Somayajulu &ha->enable_minidump, ha->enable_minidump,
188b65c0c07SDavid C Somayajulu "Minidump retrival prior to error recovery "
189b65c0c07SDavid C Somayajulu "is enabled only when this is set");
190b65c0c07SDavid C Somayajulu
191b65c0c07SDavid C Somayajulu ha->enable_driverstate_dump = 1;
192b65c0c07SDavid C Somayajulu SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
193b65c0c07SDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
194b65c0c07SDavid C Somayajulu OID_AUTO, "enable_driverstate_dump", CTLFLAG_RW,
195b65c0c07SDavid C Somayajulu &ha->enable_driverstate_dump, ha->enable_driverstate_dump,
196b65c0c07SDavid C Somayajulu "Driver State retrival prior to error recovery "
197b65c0c07SDavid C Somayajulu "is enabled only when this is set");
198b65c0c07SDavid C Somayajulu
199b65c0c07SDavid C Somayajulu ha->enable_error_recovery = 1;
200b65c0c07SDavid C Somayajulu SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
201b65c0c07SDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
202b65c0c07SDavid C Somayajulu OID_AUTO, "enable_error_recovery", CTLFLAG_RW,
203b65c0c07SDavid C Somayajulu &ha->enable_error_recovery, ha->enable_error_recovery,
204b65c0c07SDavid C Somayajulu "when set error recovery is enabled on fatal errors "
205b65c0c07SDavid C Somayajulu "otherwise the port is turned offline");
206b65c0c07SDavid C Somayajulu
207b65c0c07SDavid C Somayajulu ha->ms_delay_after_init = 1000;
208b65c0c07SDavid C Somayajulu SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
209b65c0c07SDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
210b65c0c07SDavid C Somayajulu OID_AUTO, "ms_delay_after_init", CTLFLAG_RW,
211b65c0c07SDavid C Somayajulu &ha->ms_delay_after_init, ha->ms_delay_after_init,
212b65c0c07SDavid C Somayajulu "millisecond delay after hw_init");
2131faeac0fSDavid C Somayajulu
214f10a77bbSDavid C Somayajulu ha->std_replenish = QL_STD_REPLENISH_THRES;
215f10a77bbSDavid C Somayajulu SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
216f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
217f10a77bbSDavid C Somayajulu OID_AUTO, "std_replenish", CTLFLAG_RW,
218f10a77bbSDavid C Somayajulu &ha->std_replenish, ha->std_replenish,
219f10a77bbSDavid C Somayajulu "Threshold for Replenishing Standard Frames");
220f10a77bbSDavid C Somayajulu
221f10a77bbSDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev),
222f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
223f10a77bbSDavid C Somayajulu OID_AUTO, "ipv4_lro",
224f10a77bbSDavid C Somayajulu CTLFLAG_RD, &ha->ipv4_lro,
225f10a77bbSDavid C Somayajulu "number of ipv4 lro completions");
226f10a77bbSDavid C Somayajulu
227f10a77bbSDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev),
228f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
229f10a77bbSDavid C Somayajulu OID_AUTO, "ipv6_lro",
230f10a77bbSDavid C Somayajulu CTLFLAG_RD, &ha->ipv6_lro,
231f10a77bbSDavid C Somayajulu "number of ipv6 lro completions");
232f10a77bbSDavid C Somayajulu
233f10a77bbSDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev),
234f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
235f10a77bbSDavid C Somayajulu OID_AUTO, "tx_tso_frames",
236f10a77bbSDavid C Somayajulu CTLFLAG_RD, &ha->tx_tso_frames,
237f10a77bbSDavid C Somayajulu "number of Tx TSO Frames");
238f10a77bbSDavid C Somayajulu
239f10a77bbSDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev),
240f10a77bbSDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
241f10a77bbSDavid C Somayajulu OID_AUTO, "hw_vlan_tx_frames",
242f10a77bbSDavid C Somayajulu CTLFLAG_RD, &ha->hw_vlan_tx_frames,
243f10a77bbSDavid C Somayajulu "number of Tx VLAN Frames");
244f10a77bbSDavid C Somayajulu
2457fb51846SDavid C Somayajulu SYSCTL_ADD_QUAD(device_get_sysctl_ctx(dev),
2467fb51846SDavid C Somayajulu SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
2477fb51846SDavid C Somayajulu OID_AUTO, "hw_lock_failed",
2487fb51846SDavid C Somayajulu CTLFLAG_RD, &ha->hw_lock_failed,
2497fb51846SDavid C Somayajulu "number of hw_lock failures");
2507fb51846SDavid C Somayajulu
251f10a77bbSDavid C Somayajulu return;
252f10a77bbSDavid C Somayajulu }
253f10a77bbSDavid C Somayajulu
254f10a77bbSDavid C Somayajulu static void
qla_watchdog(void * arg)255f10a77bbSDavid C Somayajulu qla_watchdog(void *arg)
256f10a77bbSDavid C Somayajulu {
257f10a77bbSDavid C Somayajulu qla_host_t *ha = arg;
25854ab3b4aSJustin Hibbits if_t ifp;
259f10a77bbSDavid C Somayajulu
260f10a77bbSDavid C Somayajulu ifp = ha->ifp;
261f10a77bbSDavid C Somayajulu
2627fb51846SDavid C Somayajulu if (ha->qla_watchdog_exit) {
263f10a77bbSDavid C Somayajulu ha->qla_watchdog_exited = 1;
264f10a77bbSDavid C Somayajulu return;
265f10a77bbSDavid C Somayajulu }
266f10a77bbSDavid C Somayajulu ha->qla_watchdog_exited = 0;
267f10a77bbSDavid C Somayajulu
2687fb51846SDavid C Somayajulu if (!ha->qla_watchdog_pause) {
269b65c0c07SDavid C Somayajulu if (!ha->offline &&
270b65c0c07SDavid C Somayajulu (ql_hw_check_health(ha) || ha->qla_initiate_recovery ||
271b65c0c07SDavid C Somayajulu (ha->msg_from_peer == QL_PEER_MSG_RESET))) {
27254ab3b4aSJustin Hibbits if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
273b65c0c07SDavid C Somayajulu ql_update_link_state(ha);
274b65c0c07SDavid C Somayajulu
275b65c0c07SDavid C Somayajulu if (ha->enable_error_recovery) {
276f10a77bbSDavid C Somayajulu ha->qla_watchdog_paused = 1;
2777fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 1;
278f10a77bbSDavid C Somayajulu ha->err_inject = 0;
279da834d52SDavid C Somayajulu device_printf(ha->pci_dev,
2807fb51846SDavid C Somayajulu "%s: taskqueue_enqueue(err_task) \n",
2817fb51846SDavid C Somayajulu __func__);
282f10a77bbSDavid C Somayajulu taskqueue_enqueue(ha->err_tq, &ha->err_task);
283b65c0c07SDavid C Somayajulu } else {
284b65c0c07SDavid C Somayajulu if (ifp != NULL)
28554ab3b4aSJustin Hibbits if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
286b65c0c07SDavid C Somayajulu ha->offline = 1;
2877fb51846SDavid C Somayajulu }
288b65c0c07SDavid C Somayajulu return;
2897fb51846SDavid C Somayajulu
290b65c0c07SDavid C Somayajulu } else {
291b65c0c07SDavid C Somayajulu if (ha->qla_interface_up) {
2927fb51846SDavid C Somayajulu ha->watchdog_ticks++;
2937fb51846SDavid C Somayajulu
2947fb51846SDavid C Somayajulu if (ha->watchdog_ticks > 1000)
2957fb51846SDavid C Somayajulu ha->watchdog_ticks = 0;
2967fb51846SDavid C Somayajulu
2977fb51846SDavid C Somayajulu if (!ha->watchdog_ticks && QL_RUNNING(ifp)) {
298b65c0c07SDavid C Somayajulu taskqueue_enqueue(ha->stats_tq,
299b65c0c07SDavid C Somayajulu &ha->stats_task);
3007fb51846SDavid C Somayajulu }
30135291c22SDavid C Somayajulu
30235291c22SDavid C Somayajulu if (ha->async_event) {
30335291c22SDavid C Somayajulu taskqueue_enqueue(ha->async_event_tq,
30435291c22SDavid C Somayajulu &ha->async_event_task);
30535291c22SDavid C Somayajulu }
306f10a77bbSDavid C Somayajulu }
3076a62bec0SDavid C Somayajulu ha->qla_watchdog_paused = 0;
308f10a77bbSDavid C Somayajulu }
309f10a77bbSDavid C Somayajulu } else {
310f10a77bbSDavid C Somayajulu ha->qla_watchdog_paused = 1;
311f10a77bbSDavid C Somayajulu }
312f10a77bbSDavid C Somayajulu
313f10a77bbSDavid C Somayajulu callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS,
314f10a77bbSDavid C Somayajulu qla_watchdog, ha);
315f10a77bbSDavid C Somayajulu }
316f10a77bbSDavid C Somayajulu
317f10a77bbSDavid C Somayajulu /*
318f10a77bbSDavid C Somayajulu * Name: qla_pci_attach
319f10a77bbSDavid C Somayajulu * Function: attaches the device to the operating system
320f10a77bbSDavid C Somayajulu */
321f10a77bbSDavid C Somayajulu static int
qla_pci_attach(device_t dev)322f10a77bbSDavid C Somayajulu qla_pci_attach(device_t dev)
323f10a77bbSDavid C Somayajulu {
324f10a77bbSDavid C Somayajulu qla_host_t *ha = NULL;
325*3d6c7ee8SFuqian Huang uint32_t rsrc_len __unused;
326f10a77bbSDavid C Somayajulu int i;
32735291c22SDavid C Somayajulu uint32_t num_rcvq = 0;
328f10a77bbSDavid C Somayajulu
329f10a77bbSDavid C Somayajulu if ((ha = device_get_softc(dev)) == NULL) {
330f10a77bbSDavid C Somayajulu device_printf(dev, "cannot get softc\n");
331f10a77bbSDavid C Somayajulu return (ENOMEM);
332f10a77bbSDavid C Somayajulu }
333f10a77bbSDavid C Somayajulu
334f10a77bbSDavid C Somayajulu memset(ha, 0, sizeof (qla_host_t));
335f10a77bbSDavid C Somayajulu
336f10a77bbSDavid C Somayajulu if (pci_get_device(dev) != PCI_PRODUCT_QLOGIC_ISP8030) {
337f10a77bbSDavid C Somayajulu device_printf(dev, "device is not ISP8030\n");
338f10a77bbSDavid C Somayajulu return (ENXIO);
339f10a77bbSDavid C Somayajulu }
340f10a77bbSDavid C Somayajulu
3416a62bec0SDavid C Somayajulu ha->pci_func = pci_get_function(dev) & 0x1;
342f10a77bbSDavid C Somayajulu
343f10a77bbSDavid C Somayajulu ha->pci_dev = dev;
344f10a77bbSDavid C Somayajulu
345f10a77bbSDavid C Somayajulu pci_enable_busmaster(dev);
346f10a77bbSDavid C Somayajulu
347f10a77bbSDavid C Somayajulu ha->reg_rid = PCIR_BAR(0);
348f10a77bbSDavid C Somayajulu ha->pci_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &ha->reg_rid,
349f10a77bbSDavid C Somayajulu RF_ACTIVE);
350f10a77bbSDavid C Somayajulu
351f10a77bbSDavid C Somayajulu if (ha->pci_reg == NULL) {
352f10a77bbSDavid C Somayajulu device_printf(dev, "unable to map any ports\n");
353f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
354f10a77bbSDavid C Somayajulu }
355f10a77bbSDavid C Somayajulu
356f10a77bbSDavid C Somayajulu rsrc_len = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
357f10a77bbSDavid C Somayajulu ha->reg_rid);
358f10a77bbSDavid C Somayajulu
359b89f2279SDavid C Somayajulu mtx_init(&ha->hw_lock, "qla83xx_hw_lock", MTX_NETWORK_LOCK, MTX_DEF);
360b65c0c07SDavid C Somayajulu mtx_init(&ha->sp_log_lock, "qla83xx_sp_log_lock", MTX_NETWORK_LOCK, MTX_DEF);
3617fb51846SDavid C Somayajulu ha->flags.lock_init = 1;
362f10a77bbSDavid C Somayajulu
363f10a77bbSDavid C Somayajulu qla_add_sysctls(ha);
364f10a77bbSDavid C Somayajulu
3657fb51846SDavid C Somayajulu ha->hw.num_sds_rings = MAX_SDS_RINGS;
3667fb51846SDavid C Somayajulu ha->hw.num_rds_rings = MAX_RDS_RINGS;
3677fb51846SDavid C Somayajulu ha->hw.num_tx_rings = NUM_TX_RINGS;
368f10a77bbSDavid C Somayajulu
369f10a77bbSDavid C Somayajulu ha->reg_rid1 = PCIR_BAR(2);
370f10a77bbSDavid C Somayajulu ha->pci_reg1 = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
371f10a77bbSDavid C Somayajulu &ha->reg_rid1, RF_ACTIVE);
372f10a77bbSDavid C Somayajulu
373f10a77bbSDavid C Somayajulu ha->msix_count = pci_msix_count(dev);
374f10a77bbSDavid C Somayajulu
3757fb51846SDavid C Somayajulu if (ha->msix_count < 1 ) {
376f10a77bbSDavid C Somayajulu device_printf(dev, "%s: msix_count[%d] not enough\n", __func__,
377f10a77bbSDavid C Somayajulu ha->msix_count);
378f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
379f10a77bbSDavid C Somayajulu }
380f10a77bbSDavid C Somayajulu
3817fb51846SDavid C Somayajulu if (ha->msix_count < (ha->hw.num_sds_rings + 1)) {
3827fb51846SDavid C Somayajulu ha->hw.num_sds_rings = ha->msix_count - 1;
3837fb51846SDavid C Somayajulu }
3847fb51846SDavid C Somayajulu
385f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x"
386b89f2279SDavid C Somayajulu " msix_count 0x%x pci_reg %p pci_reg1 %p\n", __func__, ha,
387b89f2279SDavid C Somayajulu ha->pci_func, rsrc_len, ha->msix_count, ha->pci_reg,
388b89f2279SDavid C Somayajulu ha->pci_reg1));
389f10a77bbSDavid C Somayajulu
39035291c22SDavid C Somayajulu /* initialize hardware */
39135291c22SDavid C Somayajulu if (ql_init_hw(ha)) {
39235291c22SDavid C Somayajulu device_printf(dev, "%s: ql_init_hw failed\n", __func__);
39335291c22SDavid C Somayajulu goto qla_pci_attach_err;
39435291c22SDavid C Somayajulu }
39535291c22SDavid C Somayajulu
39635291c22SDavid C Somayajulu device_printf(dev, "%s: firmware[%d.%d.%d.%d]\n", __func__,
39735291c22SDavid C Somayajulu ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub,
39835291c22SDavid C Somayajulu ha->fw_ver_build);
39935291c22SDavid C Somayajulu snprintf(ha->fw_ver_str, sizeof(ha->fw_ver_str), "%d.%d.%d.%d",
40035291c22SDavid C Somayajulu ha->fw_ver_major, ha->fw_ver_minor, ha->fw_ver_sub,
40135291c22SDavid C Somayajulu ha->fw_ver_build);
40235291c22SDavid C Somayajulu
40335291c22SDavid C Somayajulu if (qla_get_nic_partition(ha, NULL, &num_rcvq)) {
40435291c22SDavid C Somayajulu device_printf(dev, "%s: qla_get_nic_partition failed\n",
40535291c22SDavid C Somayajulu __func__);
40635291c22SDavid C Somayajulu goto qla_pci_attach_err;
40735291c22SDavid C Somayajulu }
408*3d6c7ee8SFuqian Huang QL_DPRINT2(ha, (dev, "%s: ha %p pci_func 0x%x rsrc_count 0x%08x"
409b89f2279SDavid C Somayajulu " msix_count 0x%x pci_reg %p pci_reg1 %p num_rcvq = %d\n",
410b89f2279SDavid C Somayajulu __func__, ha, ha->pci_func, rsrc_len, ha->msix_count,
411*3d6c7ee8SFuqian Huang ha->pci_reg, ha->pci_reg1, num_rcvq));
41235291c22SDavid C Somayajulu
4137fb51846SDavid C Somayajulu if ((ha->msix_count < 64) || (num_rcvq != 32)) {
4147fb51846SDavid C Somayajulu if (ha->hw.num_sds_rings > 15) {
4157fb51846SDavid C Somayajulu ha->hw.num_sds_rings = 15;
4167fb51846SDavid C Somayajulu }
4177fb51846SDavid C Somayajulu }
4187fb51846SDavid C Somayajulu
4197fb51846SDavid C Somayajulu ha->hw.num_rds_rings = ha->hw.num_sds_rings;
4207fb51846SDavid C Somayajulu ha->hw.num_tx_rings = ha->hw.num_sds_rings;
42135291c22SDavid C Somayajulu
42235291c22SDavid C Somayajulu #ifdef QL_ENABLE_ISCSI_TLV
423b89f2279SDavid C Somayajulu ha->hw.num_tx_rings = ha->hw.num_sds_rings * 2;
42435291c22SDavid C Somayajulu #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
4257fb51846SDavid C Somayajulu
4267fb51846SDavid C Somayajulu ql_hw_add_sysctls(ha);
42735291c22SDavid C Somayajulu
428f10a77bbSDavid C Somayajulu ha->msix_count = ha->hw.num_sds_rings + 1;
429f10a77bbSDavid C Somayajulu
430f10a77bbSDavid C Somayajulu if (pci_alloc_msix(dev, &ha->msix_count)) {
431f10a77bbSDavid C Somayajulu device_printf(dev, "%s: pci_alloc_msi[%d] failed\n", __func__,
432f10a77bbSDavid C Somayajulu ha->msix_count);
433f10a77bbSDavid C Somayajulu ha->msix_count = 0;
434f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
435f10a77bbSDavid C Somayajulu }
436f10a77bbSDavid C Somayajulu
437f10a77bbSDavid C Somayajulu ha->mbx_irq_rid = 1;
438f10a77bbSDavid C Somayajulu ha->mbx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
439f10a77bbSDavid C Somayajulu &ha->mbx_irq_rid,
440f10a77bbSDavid C Somayajulu (RF_ACTIVE | RF_SHAREABLE));
441f10a77bbSDavid C Somayajulu if (ha->mbx_irq == NULL) {
442f10a77bbSDavid C Somayajulu device_printf(dev, "could not allocate mbx interrupt\n");
443f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
444f10a77bbSDavid C Somayajulu }
445f10a77bbSDavid C Somayajulu if (bus_setup_intr(dev, ha->mbx_irq, (INTR_TYPE_NET | INTR_MPSAFE),
446f10a77bbSDavid C Somayajulu NULL, ql_mbx_isr, ha, &ha->mbx_handle)) {
447f10a77bbSDavid C Somayajulu device_printf(dev, "could not setup mbx interrupt\n");
448f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
449f10a77bbSDavid C Somayajulu }
450f10a77bbSDavid C Somayajulu
451f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
452f10a77bbSDavid C Somayajulu ha->irq_vec[i].sds_idx = i;
453f10a77bbSDavid C Somayajulu ha->irq_vec[i].ha = ha;
454f10a77bbSDavid C Somayajulu ha->irq_vec[i].irq_rid = 2 + i;
455f10a77bbSDavid C Somayajulu
456f10a77bbSDavid C Somayajulu ha->irq_vec[i].irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
457f10a77bbSDavid C Somayajulu &ha->irq_vec[i].irq_rid,
458f10a77bbSDavid C Somayajulu (RF_ACTIVE | RF_SHAREABLE));
459f10a77bbSDavid C Somayajulu
460f10a77bbSDavid C Somayajulu if (ha->irq_vec[i].irq == NULL) {
461f10a77bbSDavid C Somayajulu device_printf(dev, "could not allocate interrupt\n");
462f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
463f10a77bbSDavid C Somayajulu }
464f10a77bbSDavid C Somayajulu if (bus_setup_intr(dev, ha->irq_vec[i].irq,
465f10a77bbSDavid C Somayajulu (INTR_TYPE_NET | INTR_MPSAFE),
466f10a77bbSDavid C Somayajulu NULL, ql_isr, &ha->irq_vec[i],
467f10a77bbSDavid C Somayajulu &ha->irq_vec[i].handle)) {
468f10a77bbSDavid C Somayajulu device_printf(dev, "could not setup interrupt\n");
469f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
470f10a77bbSDavid C Somayajulu }
471b89f2279SDavid C Somayajulu
472b89f2279SDavid C Somayajulu ha->tx_fp[i].ha = ha;
473b89f2279SDavid C Somayajulu ha->tx_fp[i].txr_idx = i;
474b89f2279SDavid C Somayajulu
475b89f2279SDavid C Somayajulu if (qla_alloc_tx_br(ha, &ha->tx_fp[i])) {
476b89f2279SDavid C Somayajulu device_printf(dev, "%s: could not allocate tx_br[%d]\n",
477b89f2279SDavid C Somayajulu __func__, i);
478b89f2279SDavid C Somayajulu goto qla_pci_attach_err;
479f10a77bbSDavid C Somayajulu }
480b89f2279SDavid C Somayajulu }
481b89f2279SDavid C Somayajulu
482b89f2279SDavid C Somayajulu if (qla_create_fp_taskqueues(ha) != 0)
483b89f2279SDavid C Somayajulu goto qla_pci_attach_err;
484f10a77bbSDavid C Somayajulu
485f10a77bbSDavid C Somayajulu printf("%s: mp__ncpus %d sds %d rds %d msi-x %d\n", __func__, mp_ncpus,
486f10a77bbSDavid C Somayajulu ha->hw.num_sds_rings, ha->hw.num_rds_rings, ha->msix_count);
487f10a77bbSDavid C Somayajulu
488f10a77bbSDavid C Somayajulu ql_read_mac_addr(ha);
489f10a77bbSDavid C Somayajulu
490f10a77bbSDavid C Somayajulu /* allocate parent dma tag */
491f10a77bbSDavid C Somayajulu if (qla_alloc_parent_dma_tag(ha)) {
492f10a77bbSDavid C Somayajulu device_printf(dev, "%s: qla_alloc_parent_dma_tag failed\n",
493f10a77bbSDavid C Somayajulu __func__);
494f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
495f10a77bbSDavid C Somayajulu }
496f10a77bbSDavid C Somayajulu
497f10a77bbSDavid C Somayajulu /* alloc all dma buffers */
498f10a77bbSDavid C Somayajulu if (ql_alloc_dma(ha)) {
499f10a77bbSDavid C Somayajulu device_printf(dev, "%s: ql_alloc_dma failed\n", __func__);
500f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
501f10a77bbSDavid C Somayajulu }
502f10a77bbSDavid C Somayajulu qla_get_peer(ha);
503f10a77bbSDavid C Somayajulu
5046a62bec0SDavid C Somayajulu if (ql_minidump_init(ha) != 0) {
5056a62bec0SDavid C Somayajulu device_printf(dev, "%s: ql_minidump_init failed\n", __func__);
5066a62bec0SDavid C Somayajulu goto qla_pci_attach_err;
5076a62bec0SDavid C Somayajulu }
508ab142b3fSDavid C Somayajulu ql_alloc_drvr_state_buffer(ha);
509b65c0c07SDavid C Somayajulu ql_alloc_sp_log_buffer(ha);
510f10a77bbSDavid C Somayajulu /* create the o.s ethernet interface */
511f10a77bbSDavid C Somayajulu qla_init_ifnet(dev, ha);
512f10a77bbSDavid C Somayajulu
513f10a77bbSDavid C Somayajulu ha->flags.qla_watchdog_active = 1;
5147fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 0;
515f10a77bbSDavid C Somayajulu
5166a62bec0SDavid C Somayajulu callout_init(&ha->tx_callout, TRUE);
517f10a77bbSDavid C Somayajulu ha->flags.qla_callout_init = 1;
518f10a77bbSDavid C Somayajulu
519f10a77bbSDavid C Somayajulu /* create ioctl device interface */
520f10a77bbSDavid C Somayajulu if (ql_make_cdev(ha)) {
521f10a77bbSDavid C Somayajulu device_printf(dev, "%s: ql_make_cdev failed\n", __func__);
522f10a77bbSDavid C Somayajulu goto qla_pci_attach_err;
523f10a77bbSDavid C Somayajulu }
524f10a77bbSDavid C Somayajulu
525f10a77bbSDavid C Somayajulu callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS,
526f10a77bbSDavid C Somayajulu qla_watchdog, ha);
527f10a77bbSDavid C Somayajulu
528f10a77bbSDavid C Somayajulu TASK_INIT(&ha->err_task, 0, qla_error_recovery, ha);
529da834d52SDavid C Somayajulu ha->err_tq = taskqueue_create("qla_errq", M_NOWAIT,
530f10a77bbSDavid C Somayajulu taskqueue_thread_enqueue, &ha->err_tq);
531f10a77bbSDavid C Somayajulu taskqueue_start_threads(&ha->err_tq, 1, PI_NET, "%s errq",
532f10a77bbSDavid C Somayajulu device_get_nameunit(ha->pci_dev));
533f10a77bbSDavid C Somayajulu
53435291c22SDavid C Somayajulu TASK_INIT(&ha->async_event_task, 0, qla_async_event, ha);
535da834d52SDavid C Somayajulu ha->async_event_tq = taskqueue_create("qla_asyncq", M_NOWAIT,
53635291c22SDavid C Somayajulu taskqueue_thread_enqueue, &ha->async_event_tq);
53735291c22SDavid C Somayajulu taskqueue_start_threads(&ha->async_event_tq, 1, PI_NET, "%s asyncq",
53835291c22SDavid C Somayajulu device_get_nameunit(ha->pci_dev));
53935291c22SDavid C Somayajulu
5407fb51846SDavid C Somayajulu TASK_INIT(&ha->stats_task, 0, qla_stats, ha);
5417fb51846SDavid C Somayajulu ha->stats_tq = taskqueue_create("qla_statsq", M_NOWAIT,
5427fb51846SDavid C Somayajulu taskqueue_thread_enqueue, &ha->stats_tq);
5437fb51846SDavid C Somayajulu taskqueue_start_threads(&ha->stats_tq, 1, PI_NET, "%s taskq",
5447fb51846SDavid C Somayajulu device_get_nameunit(ha->pci_dev));
5457fb51846SDavid C Somayajulu
546f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit 0\n", __func__));
547f10a77bbSDavid C Somayajulu return (0);
548f10a77bbSDavid C Somayajulu
549f10a77bbSDavid C Somayajulu qla_pci_attach_err:
550f10a77bbSDavid C Somayajulu
551f10a77bbSDavid C Somayajulu qla_release(ha);
552f10a77bbSDavid C Somayajulu
5537fb51846SDavid C Somayajulu if (ha->flags.lock_init) {
5547fb51846SDavid C Somayajulu mtx_destroy(&ha->hw_lock);
555b65c0c07SDavid C Somayajulu mtx_destroy(&ha->sp_log_lock);
5567fb51846SDavid C Somayajulu }
5577fb51846SDavid C Somayajulu
558f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit ENXIO\n", __func__));
559f10a77bbSDavid C Somayajulu return (ENXIO);
560f10a77bbSDavid C Somayajulu }
561f10a77bbSDavid C Somayajulu
562f10a77bbSDavid C Somayajulu /*
563f10a77bbSDavid C Somayajulu * Name: qla_pci_detach
564f10a77bbSDavid C Somayajulu * Function: Unhooks the device from the operating system
565f10a77bbSDavid C Somayajulu */
566f10a77bbSDavid C Somayajulu static int
qla_pci_detach(device_t dev)567f10a77bbSDavid C Somayajulu qla_pci_detach(device_t dev)
568f10a77bbSDavid C Somayajulu {
569f10a77bbSDavid C Somayajulu qla_host_t *ha = NULL;
57054ab3b4aSJustin Hibbits if_t ifp;
571f10a77bbSDavid C Somayajulu
572f10a77bbSDavid C Somayajulu if ((ha = device_get_softc(dev)) == NULL) {
573f10a77bbSDavid C Somayajulu device_printf(dev, "cannot get softc\n");
574f10a77bbSDavid C Somayajulu return (ENOMEM);
575f10a77bbSDavid C Somayajulu }
576f10a77bbSDavid C Somayajulu
5777fb51846SDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
5787fb51846SDavid C Somayajulu
579f10a77bbSDavid C Somayajulu ifp = ha->ifp;
580f10a77bbSDavid C Somayajulu
58154ab3b4aSJustin Hibbits if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
5827fb51846SDavid C Somayajulu QLA_LOCK(ha, __func__, -1, 0);
5837fb51846SDavid C Somayajulu
5847fb51846SDavid C Somayajulu ha->qla_detach_active = 1;
585f10a77bbSDavid C Somayajulu qla_stop(ha);
586f10a77bbSDavid C Somayajulu
587f10a77bbSDavid C Somayajulu qla_release(ha);
588f10a77bbSDavid C Somayajulu
5897fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__);
5907fb51846SDavid C Somayajulu
5917fb51846SDavid C Somayajulu if (ha->flags.lock_init) {
5927fb51846SDavid C Somayajulu mtx_destroy(&ha->hw_lock);
593b65c0c07SDavid C Somayajulu mtx_destroy(&ha->sp_log_lock);
5947fb51846SDavid C Somayajulu }
5957fb51846SDavid C Somayajulu
596f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
597f10a77bbSDavid C Somayajulu
598f10a77bbSDavid C Somayajulu return (0);
599f10a77bbSDavid C Somayajulu }
600f10a77bbSDavid C Somayajulu
601f10a77bbSDavid C Somayajulu /*
602f10a77bbSDavid C Somayajulu * SYSCTL Related Callbacks
603f10a77bbSDavid C Somayajulu */
604f10a77bbSDavid C Somayajulu static int
qla_sysctl_get_link_status(SYSCTL_HANDLER_ARGS)605f10a77bbSDavid C Somayajulu qla_sysctl_get_link_status(SYSCTL_HANDLER_ARGS)
606f10a77bbSDavid C Somayajulu {
607f10a77bbSDavid C Somayajulu int err, ret = 0;
608f10a77bbSDavid C Somayajulu qla_host_t *ha;
609f10a77bbSDavid C Somayajulu
610f10a77bbSDavid C Somayajulu err = sysctl_handle_int(oidp, &ret, 0, req);
611f10a77bbSDavid C Somayajulu
612f10a77bbSDavid C Somayajulu if (err || !req->newptr)
613f10a77bbSDavid C Somayajulu return (err);
614f10a77bbSDavid C Somayajulu
615f10a77bbSDavid C Somayajulu if (ret == 1) {
616f10a77bbSDavid C Somayajulu ha = (qla_host_t *)arg1;
617f10a77bbSDavid C Somayajulu ql_hw_link_status(ha);
618f10a77bbSDavid C Somayajulu }
619f10a77bbSDavid C Somayajulu return (err);
620f10a77bbSDavid C Somayajulu }
621f10a77bbSDavid C Somayajulu
622f10a77bbSDavid C Somayajulu /*
623f10a77bbSDavid C Somayajulu * Name: qla_release
624f10a77bbSDavid C Somayajulu * Function: Releases the resources allocated for the device
625f10a77bbSDavid C Somayajulu */
626f10a77bbSDavid C Somayajulu static void
qla_release(qla_host_t * ha)627f10a77bbSDavid C Somayajulu qla_release(qla_host_t *ha)
628f10a77bbSDavid C Somayajulu {
629f10a77bbSDavid C Somayajulu device_t dev;
630f10a77bbSDavid C Somayajulu int i;
631f10a77bbSDavid C Somayajulu
632f10a77bbSDavid C Somayajulu dev = ha->pci_dev;
633f10a77bbSDavid C Somayajulu
63435291c22SDavid C Somayajulu if (ha->async_event_tq) {
635b65c0c07SDavid C Somayajulu taskqueue_drain_all(ha->async_event_tq);
63635291c22SDavid C Somayajulu taskqueue_free(ha->async_event_tq);
63735291c22SDavid C Somayajulu }
63835291c22SDavid C Somayajulu
639f10a77bbSDavid C Somayajulu if (ha->err_tq) {
640b65c0c07SDavid C Somayajulu taskqueue_drain_all(ha->err_tq);
641f10a77bbSDavid C Somayajulu taskqueue_free(ha->err_tq);
642f10a77bbSDavid C Somayajulu }
643f10a77bbSDavid C Somayajulu
6447fb51846SDavid C Somayajulu if (ha->stats_tq) {
645b65c0c07SDavid C Somayajulu taskqueue_drain_all(ha->stats_tq);
6467fb51846SDavid C Somayajulu taskqueue_free(ha->stats_tq);
6477fb51846SDavid C Somayajulu }
6487fb51846SDavid C Somayajulu
649f10a77bbSDavid C Somayajulu ql_del_cdev(ha);
650f10a77bbSDavid C Somayajulu
651f10a77bbSDavid C Somayajulu if (ha->flags.qla_watchdog_active) {
6527fb51846SDavid C Somayajulu ha->qla_watchdog_exit = 1;
653f10a77bbSDavid C Somayajulu
654f10a77bbSDavid C Somayajulu while (ha->qla_watchdog_exited == 0)
655f10a77bbSDavid C Somayajulu qla_mdelay(__func__, 1);
656f10a77bbSDavid C Somayajulu }
657f10a77bbSDavid C Somayajulu
658f10a77bbSDavid C Somayajulu if (ha->flags.qla_callout_init)
659f10a77bbSDavid C Somayajulu callout_stop(&ha->tx_callout);
660f10a77bbSDavid C Somayajulu
661f10a77bbSDavid C Somayajulu if (ha->ifp != NULL)
662f10a77bbSDavid C Somayajulu ether_ifdetach(ha->ifp);
663f10a77bbSDavid C Somayajulu
664ab142b3fSDavid C Somayajulu ql_free_drvr_state_buffer(ha);
665b65c0c07SDavid C Somayajulu ql_free_sp_log_buffer(ha);
666f10a77bbSDavid C Somayajulu ql_free_dma(ha);
667f10a77bbSDavid C Somayajulu qla_free_parent_dma_tag(ha);
668f10a77bbSDavid C Somayajulu
669f10a77bbSDavid C Somayajulu if (ha->mbx_handle)
670f10a77bbSDavid C Somayajulu (void)bus_teardown_intr(dev, ha->mbx_irq, ha->mbx_handle);
671f10a77bbSDavid C Somayajulu
672f10a77bbSDavid C Somayajulu if (ha->mbx_irq)
673f10a77bbSDavid C Somayajulu (void) bus_release_resource(dev, SYS_RES_IRQ, ha->mbx_irq_rid,
674f10a77bbSDavid C Somayajulu ha->mbx_irq);
675f10a77bbSDavid C Somayajulu
676f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
677f10a77bbSDavid C Somayajulu if (ha->irq_vec[i].handle) {
678f10a77bbSDavid C Somayajulu (void)bus_teardown_intr(dev, ha->irq_vec[i].irq,
679f10a77bbSDavid C Somayajulu ha->irq_vec[i].handle);
680f10a77bbSDavid C Somayajulu }
681f10a77bbSDavid C Somayajulu
682f10a77bbSDavid C Somayajulu if (ha->irq_vec[i].irq) {
683f10a77bbSDavid C Somayajulu (void)bus_release_resource(dev, SYS_RES_IRQ,
684f10a77bbSDavid C Somayajulu ha->irq_vec[i].irq_rid,
685f10a77bbSDavid C Somayajulu ha->irq_vec[i].irq);
686f10a77bbSDavid C Somayajulu }
687b89f2279SDavid C Somayajulu
688b89f2279SDavid C Somayajulu qla_free_tx_br(ha, &ha->tx_fp[i]);
689f10a77bbSDavid C Somayajulu }
690b89f2279SDavid C Somayajulu qla_destroy_fp_taskqueues(ha);
691f10a77bbSDavid C Somayajulu
692f10a77bbSDavid C Somayajulu if (ha->msix_count)
693f10a77bbSDavid C Somayajulu pci_release_msi(dev);
694f10a77bbSDavid C Somayajulu
695f10a77bbSDavid C Somayajulu if (ha->pci_reg)
696f10a77bbSDavid C Somayajulu (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid,
697f10a77bbSDavid C Somayajulu ha->pci_reg);
698f10a77bbSDavid C Somayajulu
699f10a77bbSDavid C Somayajulu if (ha->pci_reg1)
700f10a77bbSDavid C Somayajulu (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid1,
701f10a77bbSDavid C Somayajulu ha->pci_reg1);
7027fb51846SDavid C Somayajulu
7037fb51846SDavid C Somayajulu return;
704f10a77bbSDavid C Somayajulu }
705f10a77bbSDavid C Somayajulu
706f10a77bbSDavid C Somayajulu /*
707f10a77bbSDavid C Somayajulu * DMA Related Functions
708f10a77bbSDavid C Somayajulu */
709f10a77bbSDavid C Somayajulu
710f10a77bbSDavid C Somayajulu static void
qla_dmamap_callback(void * arg,bus_dma_segment_t * segs,int nsegs,int error)711f10a77bbSDavid C Somayajulu qla_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
712f10a77bbSDavid C Somayajulu {
713f10a77bbSDavid C Somayajulu *((bus_addr_t *)arg) = 0;
714f10a77bbSDavid C Somayajulu
715f10a77bbSDavid C Somayajulu if (error) {
716f10a77bbSDavid C Somayajulu printf("%s: bus_dmamap_load failed (%d)\n", __func__, error);
717f10a77bbSDavid C Somayajulu return;
718f10a77bbSDavid C Somayajulu }
719f10a77bbSDavid C Somayajulu
720f10a77bbSDavid C Somayajulu *((bus_addr_t *)arg) = segs[0].ds_addr;
721f10a77bbSDavid C Somayajulu
722f10a77bbSDavid C Somayajulu return;
723f10a77bbSDavid C Somayajulu }
724f10a77bbSDavid C Somayajulu
725f10a77bbSDavid C Somayajulu int
ql_alloc_dmabuf(qla_host_t * ha,qla_dma_t * dma_buf)726f10a77bbSDavid C Somayajulu ql_alloc_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf)
727f10a77bbSDavid C Somayajulu {
728f10a77bbSDavid C Somayajulu int ret = 0;
729f10a77bbSDavid C Somayajulu device_t dev;
730f10a77bbSDavid C Somayajulu bus_addr_t b_addr;
731f10a77bbSDavid C Somayajulu
732f10a77bbSDavid C Somayajulu dev = ha->pci_dev;
733f10a77bbSDavid C Somayajulu
734f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
735f10a77bbSDavid C Somayajulu
736f10a77bbSDavid C Somayajulu ret = bus_dma_tag_create(
737f10a77bbSDavid C Somayajulu ha->parent_tag,/* parent */
738f10a77bbSDavid C Somayajulu dma_buf->alignment,
739f10a77bbSDavid C Somayajulu ((bus_size_t)(1ULL << 32)),/* boundary */
740f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* lowaddr */
741f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* highaddr */
742f10a77bbSDavid C Somayajulu NULL, NULL, /* filter, filterarg */
743f10a77bbSDavid C Somayajulu dma_buf->size, /* maxsize */
744f10a77bbSDavid C Somayajulu 1, /* nsegments */
745f10a77bbSDavid C Somayajulu dma_buf->size, /* maxsegsize */
746f10a77bbSDavid C Somayajulu 0, /* flags */
747f10a77bbSDavid C Somayajulu NULL, NULL, /* lockfunc, lockarg */
748f10a77bbSDavid C Somayajulu &dma_buf->dma_tag);
749f10a77bbSDavid C Somayajulu
750f10a77bbSDavid C Somayajulu if (ret) {
751f10a77bbSDavid C Somayajulu device_printf(dev, "%s: could not create dma tag\n", __func__);
752f10a77bbSDavid C Somayajulu goto ql_alloc_dmabuf_exit;
753f10a77bbSDavid C Somayajulu }
754f10a77bbSDavid C Somayajulu ret = bus_dmamem_alloc(dma_buf->dma_tag,
755f10a77bbSDavid C Somayajulu (void **)&dma_buf->dma_b,
756f10a77bbSDavid C Somayajulu (BUS_DMA_ZERO | BUS_DMA_COHERENT | BUS_DMA_NOWAIT),
757f10a77bbSDavid C Somayajulu &dma_buf->dma_map);
758f10a77bbSDavid C Somayajulu if (ret) {
759f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(dma_buf->dma_tag);
760f10a77bbSDavid C Somayajulu device_printf(dev, "%s: bus_dmamem_alloc failed\n", __func__);
761f10a77bbSDavid C Somayajulu goto ql_alloc_dmabuf_exit;
762f10a77bbSDavid C Somayajulu }
763f10a77bbSDavid C Somayajulu
764f10a77bbSDavid C Somayajulu ret = bus_dmamap_load(dma_buf->dma_tag,
765f10a77bbSDavid C Somayajulu dma_buf->dma_map,
766f10a77bbSDavid C Somayajulu dma_buf->dma_b,
767f10a77bbSDavid C Somayajulu dma_buf->size,
768f10a77bbSDavid C Somayajulu qla_dmamap_callback,
769f10a77bbSDavid C Somayajulu &b_addr, BUS_DMA_NOWAIT);
770f10a77bbSDavid C Somayajulu
771f10a77bbSDavid C Somayajulu if (ret || !b_addr) {
772f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(dma_buf->dma_tag);
773f10a77bbSDavid C Somayajulu bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b,
774f10a77bbSDavid C Somayajulu dma_buf->dma_map);
775f10a77bbSDavid C Somayajulu ret = -1;
776f10a77bbSDavid C Somayajulu goto ql_alloc_dmabuf_exit;
777f10a77bbSDavid C Somayajulu }
778f10a77bbSDavid C Somayajulu
779f10a77bbSDavid C Somayajulu dma_buf->dma_addr = b_addr;
780f10a77bbSDavid C Somayajulu
781f10a77bbSDavid C Somayajulu ql_alloc_dmabuf_exit:
782f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit ret 0x%08x tag %p map %p b %p sz 0x%x\n",
783f10a77bbSDavid C Somayajulu __func__, ret, (void *)dma_buf->dma_tag,
784f10a77bbSDavid C Somayajulu (void *)dma_buf->dma_map, (void *)dma_buf->dma_b,
785f10a77bbSDavid C Somayajulu dma_buf->size));
786f10a77bbSDavid C Somayajulu
787f10a77bbSDavid C Somayajulu return ret;
788f10a77bbSDavid C Somayajulu }
789f10a77bbSDavid C Somayajulu
790f10a77bbSDavid C Somayajulu void
ql_free_dmabuf(qla_host_t * ha,qla_dma_t * dma_buf)791f10a77bbSDavid C Somayajulu ql_free_dmabuf(qla_host_t *ha, qla_dma_t *dma_buf)
792f10a77bbSDavid C Somayajulu {
79308d82f85SDavid C Somayajulu bus_dmamap_unload(dma_buf->dma_tag, dma_buf->dma_map);
794f10a77bbSDavid C Somayajulu bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b, dma_buf->dma_map);
795f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(dma_buf->dma_tag);
796f10a77bbSDavid C Somayajulu }
797f10a77bbSDavid C Somayajulu
798f10a77bbSDavid C Somayajulu static int
qla_alloc_parent_dma_tag(qla_host_t * ha)799f10a77bbSDavid C Somayajulu qla_alloc_parent_dma_tag(qla_host_t *ha)
800f10a77bbSDavid C Somayajulu {
801f10a77bbSDavid C Somayajulu int ret;
802f10a77bbSDavid C Somayajulu device_t dev;
803f10a77bbSDavid C Somayajulu
804f10a77bbSDavid C Somayajulu dev = ha->pci_dev;
805f10a77bbSDavid C Somayajulu
806f10a77bbSDavid C Somayajulu /*
807f10a77bbSDavid C Somayajulu * Allocate parent DMA Tag
808f10a77bbSDavid C Somayajulu */
809f10a77bbSDavid C Somayajulu ret = bus_dma_tag_create(
810f10a77bbSDavid C Somayajulu bus_get_dma_tag(dev), /* parent */
811f10a77bbSDavid C Somayajulu 1,((bus_size_t)(1ULL << 32)),/* alignment, boundary */
812f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* lowaddr */
813f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* highaddr */
814f10a77bbSDavid C Somayajulu NULL, NULL, /* filter, filterarg */
815f10a77bbSDavid C Somayajulu BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
816f10a77bbSDavid C Somayajulu 0, /* nsegments */
817f10a77bbSDavid C Somayajulu BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
818f10a77bbSDavid C Somayajulu 0, /* flags */
819f10a77bbSDavid C Somayajulu NULL, NULL, /* lockfunc, lockarg */
820f10a77bbSDavid C Somayajulu &ha->parent_tag);
821f10a77bbSDavid C Somayajulu
822f10a77bbSDavid C Somayajulu if (ret) {
823f10a77bbSDavid C Somayajulu device_printf(dev, "%s: could not create parent dma tag\n",
824f10a77bbSDavid C Somayajulu __func__);
825f10a77bbSDavid C Somayajulu return (-1);
826f10a77bbSDavid C Somayajulu }
827f10a77bbSDavid C Somayajulu
828f10a77bbSDavid C Somayajulu ha->flags.parent_tag = 1;
829f10a77bbSDavid C Somayajulu
830f10a77bbSDavid C Somayajulu return (0);
831f10a77bbSDavid C Somayajulu }
832f10a77bbSDavid C Somayajulu
833f10a77bbSDavid C Somayajulu static void
qla_free_parent_dma_tag(qla_host_t * ha)834f10a77bbSDavid C Somayajulu qla_free_parent_dma_tag(qla_host_t *ha)
835f10a77bbSDavid C Somayajulu {
836f10a77bbSDavid C Somayajulu if (ha->flags.parent_tag) {
837f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(ha->parent_tag);
838f10a77bbSDavid C Somayajulu ha->flags.parent_tag = 0;
839f10a77bbSDavid C Somayajulu }
840f10a77bbSDavid C Somayajulu }
841f10a77bbSDavid C Somayajulu
842f10a77bbSDavid C Somayajulu /*
843f10a77bbSDavid C Somayajulu * Name: qla_init_ifnet
844f10a77bbSDavid C Somayajulu * Function: Creates the Network Device Interface and Registers it with the O.S
845f10a77bbSDavid C Somayajulu */
846f10a77bbSDavid C Somayajulu
847f10a77bbSDavid C Somayajulu static void
qla_init_ifnet(device_t dev,qla_host_t * ha)848f10a77bbSDavid C Somayajulu qla_init_ifnet(device_t dev, qla_host_t *ha)
849f10a77bbSDavid C Somayajulu {
85054ab3b4aSJustin Hibbits if_t ifp;
851f10a77bbSDavid C Somayajulu
852f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
853f10a77bbSDavid C Somayajulu
854f10a77bbSDavid C Somayajulu ifp = ha->ifp = if_alloc(IFT_ETHER);
855f10a77bbSDavid C Somayajulu if_initname(ifp, device_get_name(dev), device_get_unit(dev));
856f10a77bbSDavid C Somayajulu
85754ab3b4aSJustin Hibbits if_setbaudrate(ifp, IF_Gbps(10));
85854ab3b4aSJustin Hibbits if_setcapabilities(ifp, IFCAP_LINKSTATE);
85954ab3b4aSJustin Hibbits if_setmtu(ifp, ETHERMTU);
860f10a77bbSDavid C Somayajulu
86154ab3b4aSJustin Hibbits if_setinitfn(ifp, qla_init);
86254ab3b4aSJustin Hibbits if_setsoftc(ifp, ha);
86354ab3b4aSJustin Hibbits if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
86454ab3b4aSJustin Hibbits if_setioctlfn(ifp, qla_ioctl);
865b89f2279SDavid C Somayajulu
86654ab3b4aSJustin Hibbits if_settransmitfn(ifp, qla_transmit);
86754ab3b4aSJustin Hibbits if_setqflushfn(ifp, qla_qflush);
868f10a77bbSDavid C Somayajulu
86954ab3b4aSJustin Hibbits if_setsendqlen(ifp, qla_get_ifq_snd_maxlen(ha));
87054ab3b4aSJustin Hibbits if_setsendqready(ifp);
871f10a77bbSDavid C Somayajulu
87254ab3b4aSJustin Hibbits ha->max_frame_size = if_getmtu(ifp) + ETHER_HDR_LEN + ETHER_CRC_LEN;
873f10a77bbSDavid C Somayajulu
874f10a77bbSDavid C Somayajulu ether_ifattach(ifp, qla_get_mac_addr(ha));
875f10a77bbSDavid C Somayajulu
87654ab3b4aSJustin Hibbits if_setcapabilitiesbit(ifp, IFCAP_HWCSUM |
877f10a77bbSDavid C Somayajulu IFCAP_TSO4 |
878b65c0c07SDavid C Somayajulu IFCAP_TSO6 |
879b89f2279SDavid C Somayajulu IFCAP_JUMBO_MTU |
880b89f2279SDavid C Somayajulu IFCAP_VLAN_HWTAGGING |
881b89f2279SDavid C Somayajulu IFCAP_VLAN_MTU |
882b89f2279SDavid C Somayajulu IFCAP_VLAN_HWTSO |
88354ab3b4aSJustin Hibbits IFCAP_LRO, 0);
884f10a77bbSDavid C Somayajulu
88554ab3b4aSJustin Hibbits if_setcapenable(ifp, if_getcapabilities(ifp));
886f10a77bbSDavid C Somayajulu
88754ab3b4aSJustin Hibbits if_setifheaderlen(ifp, sizeof(struct ether_vlan_header));
888f10a77bbSDavid C Somayajulu
889f10a77bbSDavid C Somayajulu ifmedia_init(&ha->media, IFM_IMASK, qla_media_change, qla_media_status);
890f10a77bbSDavid C Somayajulu
891f10a77bbSDavid C Somayajulu ifmedia_add(&ha->media, (IFM_ETHER | qla_get_optics(ha) | IFM_FDX), 0,
892f10a77bbSDavid C Somayajulu NULL);
893f10a77bbSDavid C Somayajulu ifmedia_add(&ha->media, (IFM_ETHER | IFM_AUTO), 0, NULL);
894f10a77bbSDavid C Somayajulu
895f10a77bbSDavid C Somayajulu ifmedia_set(&ha->media, (IFM_ETHER | IFM_AUTO));
896f10a77bbSDavid C Somayajulu
897f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (dev, "%s: exit\n", __func__));
898f10a77bbSDavid C Somayajulu
899f10a77bbSDavid C Somayajulu return;
900f10a77bbSDavid C Somayajulu }
901f10a77bbSDavid C Somayajulu
902f10a77bbSDavid C Somayajulu static void
qla_init_locked(qla_host_t * ha)903f10a77bbSDavid C Somayajulu qla_init_locked(qla_host_t *ha)
904f10a77bbSDavid C Somayajulu {
90554ab3b4aSJustin Hibbits if_t ifp = ha->ifp;
906f10a77bbSDavid C Somayajulu
907b65c0c07SDavid C Somayajulu ql_sp_log(ha, 14, 0, 0, 0, 0, 0, 0);
908b65c0c07SDavid C Somayajulu
909f10a77bbSDavid C Somayajulu qla_stop(ha);
910f10a77bbSDavid C Somayajulu
911f10a77bbSDavid C Somayajulu if (qla_alloc_xmt_bufs(ha) != 0)
912f10a77bbSDavid C Somayajulu return;
913f10a77bbSDavid C Somayajulu
91435291c22SDavid C Somayajulu qla_confirm_9kb_enable(ha);
91535291c22SDavid C Somayajulu
916f10a77bbSDavid C Somayajulu if (qla_alloc_rcv_bufs(ha) != 0)
917f10a77bbSDavid C Somayajulu return;
918f10a77bbSDavid C Somayajulu
91954ab3b4aSJustin Hibbits bcopy(if_getlladdr(ha->ifp), ha->hw.mac_addr, ETHER_ADDR_LEN);
920f10a77bbSDavid C Somayajulu
92154ab3b4aSJustin Hibbits if_sethwassist(ifp, CSUM_TCP | CSUM_UDP | CSUM_TSO);
92254ab3b4aSJustin Hibbits if_sethwassistbits(ifp, CSUM_TCP_IPV6 | CSUM_UDP_IPV6, 0);
923f10a77bbSDavid C Somayajulu
9247fb51846SDavid C Somayajulu ha->stop_rcv = 0;
925f10a77bbSDavid C Somayajulu if (ql_init_hw_if(ha) == 0) {
926f10a77bbSDavid C Somayajulu ifp = ha->ifp;
92754ab3b4aSJustin Hibbits if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
928f10a77bbSDavid C Somayajulu ha->hw_vlan_tx_frames = 0;
929f10a77bbSDavid C Somayajulu ha->tx_tso_frames = 0;
9307fb51846SDavid C Somayajulu ha->qla_interface_up = 1;
9317fb51846SDavid C Somayajulu ql_update_link_state(ha);
932b65c0c07SDavid C Somayajulu } else {
933b65c0c07SDavid C Somayajulu if (ha->hw.sp_log_stop_events & Q8_SP_LOG_STOP_IF_START_FAILURE)
934b65c0c07SDavid C Somayajulu ha->hw.sp_log_stop = -1;
935f10a77bbSDavid C Somayajulu }
936f10a77bbSDavid C Somayajulu
937b65c0c07SDavid C Somayajulu ha->qla_watchdog_pause = 0;
938b65c0c07SDavid C Somayajulu
939f10a77bbSDavid C Somayajulu return;
940f10a77bbSDavid C Somayajulu }
941f10a77bbSDavid C Somayajulu
942f10a77bbSDavid C Somayajulu static void
qla_init(void * arg)943f10a77bbSDavid C Somayajulu qla_init(void *arg)
944f10a77bbSDavid C Somayajulu {
945f10a77bbSDavid C Somayajulu qla_host_t *ha;
946f10a77bbSDavid C Somayajulu
947f10a77bbSDavid C Somayajulu ha = (qla_host_t *)arg;
948f10a77bbSDavid C Somayajulu
949f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
950f10a77bbSDavid C Somayajulu
9517fb51846SDavid C Somayajulu if (QLA_LOCK(ha, __func__, -1, 0) != 0)
9527fb51846SDavid C Somayajulu return;
9537fb51846SDavid C Somayajulu
954f10a77bbSDavid C Somayajulu qla_init_locked(ha);
9557fb51846SDavid C Somayajulu
9567fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__);
957f10a77bbSDavid C Somayajulu
958f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
959f10a77bbSDavid C Somayajulu }
960f10a77bbSDavid C Somayajulu
961a4589b2dSGleb Smirnoff static u_int
qla_copy_maddr(void * arg,struct sockaddr_dl * sdl,u_int mcnt)962a4589b2dSGleb Smirnoff qla_copy_maddr(void *arg, struct sockaddr_dl *sdl, u_int mcnt)
963a4589b2dSGleb Smirnoff {
964a4589b2dSGleb Smirnoff uint8_t *mta = arg;
965a4589b2dSGleb Smirnoff
966a4589b2dSGleb Smirnoff if (mcnt == Q8_MAX_NUM_MULTICAST_ADDRS)
967a4589b2dSGleb Smirnoff return (0);
968a4589b2dSGleb Smirnoff
969a4589b2dSGleb Smirnoff bcopy(LLADDR(sdl), &mta[mcnt * Q8_MAC_ADDR_LEN], Q8_MAC_ADDR_LEN);
970a4589b2dSGleb Smirnoff
971a4589b2dSGleb Smirnoff return (1);
972a4589b2dSGleb Smirnoff }
973a4589b2dSGleb Smirnoff
974f10a77bbSDavid C Somayajulu static int
qla_set_multi(qla_host_t * ha,uint32_t add_multi)975f10a77bbSDavid C Somayajulu qla_set_multi(qla_host_t *ha, uint32_t add_multi)
976f10a77bbSDavid C Somayajulu {
977f10a77bbSDavid C Somayajulu uint8_t mta[Q8_MAX_NUM_MULTICAST_ADDRS * Q8_MAC_ADDR_LEN];
978f10a77bbSDavid C Somayajulu int mcnt = 0;
97954ab3b4aSJustin Hibbits if_t ifp = ha->ifp;
980f10a77bbSDavid C Somayajulu int ret = 0;
981f10a77bbSDavid C Somayajulu
982a4589b2dSGleb Smirnoff mcnt = if_foreach_llmaddr(ifp, qla_copy_maddr, mta);
983f10a77bbSDavid C Somayajulu
9847fb51846SDavid C Somayajulu if (QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT,
9857fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP) != 0)
9867fb51846SDavid C Somayajulu return (-1);
9877fb51846SDavid C Somayajulu
98854ab3b4aSJustin Hibbits ql_sp_log(ha, 12, 4, if_getdrvflags(ifp),
98954ab3b4aSJustin Hibbits (if_getdrvflags(ifp) & IFF_DRV_RUNNING),
990b65c0c07SDavid C Somayajulu add_multi, (uint32_t)mcnt, 0);
991b65c0c07SDavid C Somayajulu
99254ab3b4aSJustin Hibbits if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
99361fb8de9SDavid C Somayajulu if (!add_multi) {
99461fb8de9SDavid C Somayajulu ret = qla_hw_del_all_mcast(ha);
99561fb8de9SDavid C Somayajulu
99661fb8de9SDavid C Somayajulu if (ret)
99761fb8de9SDavid C Somayajulu device_printf(ha->pci_dev,
99861fb8de9SDavid C Somayajulu "%s: qla_hw_del_all_mcast() failed\n",
99961fb8de9SDavid C Somayajulu __func__);
100061fb8de9SDavid C Somayajulu }
100161fb8de9SDavid C Somayajulu
100261fb8de9SDavid C Somayajulu if (!ret)
100361fb8de9SDavid C Somayajulu ret = ql_hw_set_multi(ha, mta, mcnt, 1);
100477d57b28SDavid C Somayajulu }
10057fb51846SDavid C Somayajulu
10067fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__);
1007f10a77bbSDavid C Somayajulu
1008f10a77bbSDavid C Somayajulu return (ret);
1009f10a77bbSDavid C Somayajulu }
1010f10a77bbSDavid C Somayajulu
1011f10a77bbSDavid C Somayajulu static int
qla_ioctl(if_t ifp,u_long cmd,caddr_t data)101254ab3b4aSJustin Hibbits qla_ioctl(if_t ifp, u_long cmd, caddr_t data)
1013f10a77bbSDavid C Somayajulu {
1014f10a77bbSDavid C Somayajulu int ret = 0;
1015f10a77bbSDavid C Somayajulu struct ifreq *ifr = (struct ifreq *)data;
1016618aa8cdSJohn Baldwin #ifdef INET
1017f10a77bbSDavid C Somayajulu struct ifaddr *ifa = (struct ifaddr *)data;
1018618aa8cdSJohn Baldwin #endif
1019f10a77bbSDavid C Somayajulu qla_host_t *ha;
1020f10a77bbSDavid C Somayajulu
102154ab3b4aSJustin Hibbits ha = (qla_host_t *)if_getsoftc(ifp);
1022b65c0c07SDavid C Somayajulu if (ha->offline || ha->qla_initiate_recovery)
1023b65c0c07SDavid C Somayajulu return (ret);
1024f10a77bbSDavid C Somayajulu
1025f10a77bbSDavid C Somayajulu switch (cmd) {
1026f10a77bbSDavid C Somayajulu case SIOCSIFADDR:
1027f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFADDR (0x%lx)\n",
1028f10a77bbSDavid C Somayajulu __func__, cmd));
1029f10a77bbSDavid C Somayajulu
1030618aa8cdSJohn Baldwin #ifdef INET
1031f10a77bbSDavid C Somayajulu if (ifa->ifa_addr->sa_family == AF_INET) {
10327fb51846SDavid C Somayajulu ret = QLA_LOCK(ha, __func__,
10337fb51846SDavid C Somayajulu QLA_LOCK_DEFAULT_MS_TIMEOUT,
10347fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP);
10357fb51846SDavid C Somayajulu if (ret)
10367fb51846SDavid C Somayajulu break;
10377fb51846SDavid C Somayajulu
103854ab3b4aSJustin Hibbits if_setflagbits(ifp, IFF_UP, 0);
10397fb51846SDavid C Somayajulu
104054ab3b4aSJustin Hibbits ql_sp_log(ha, 8, 3, if_getdrvflags(ifp),
104154ab3b4aSJustin Hibbits (if_getdrvflags(ifp) & IFF_DRV_RUNNING),
1042b65c0c07SDavid C Somayajulu ntohl(IA_SIN(ifa)->sin_addr.s_addr), 0, 0);
1043b65c0c07SDavid C Somayajulu
104454ab3b4aSJustin Hibbits if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) {
1045f10a77bbSDavid C Somayajulu qla_init_locked(ha);
1046f10a77bbSDavid C Somayajulu }
10477fb51846SDavid C Somayajulu
10487fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__);
1049f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev,
1050f10a77bbSDavid C Somayajulu "%s: SIOCSIFADDR (0x%lx) ipv4 [0x%08x]\n",
1051f10a77bbSDavid C Somayajulu __func__, cmd,
1052f10a77bbSDavid C Somayajulu ntohl(IA_SIN(ifa)->sin_addr.s_addr)));
1053f10a77bbSDavid C Somayajulu
1054f10a77bbSDavid C Somayajulu arp_ifinit(ifp, ifa);
1055618aa8cdSJohn Baldwin break;
1056f10a77bbSDavid C Somayajulu }
1057618aa8cdSJohn Baldwin #endif
1058618aa8cdSJohn Baldwin ether_ioctl(ifp, cmd, data);
1059f10a77bbSDavid C Somayajulu break;
1060f10a77bbSDavid C Somayajulu
1061f10a77bbSDavid C Somayajulu case SIOCSIFMTU:
1062f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFMTU (0x%lx)\n",
1063f10a77bbSDavid C Somayajulu __func__, cmd));
1064f10a77bbSDavid C Somayajulu
1065f10a77bbSDavid C Somayajulu if (ifr->ifr_mtu > QLA_MAX_MTU) {
1066f10a77bbSDavid C Somayajulu ret = EINVAL;
1067f10a77bbSDavid C Somayajulu } else {
10687fb51846SDavid C Somayajulu ret = QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT,
10697fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP);
10707fb51846SDavid C Somayajulu
10717fb51846SDavid C Somayajulu if (ret)
10727fb51846SDavid C Somayajulu break;
10739a5f7854SDavid C Somayajulu
107454ab3b4aSJustin Hibbits if_setmtu(ifp, ifr->ifr_mtu);
1075f10a77bbSDavid C Somayajulu ha->max_frame_size =
107654ab3b4aSJustin Hibbits if_getmtu(ifp) + ETHER_HDR_LEN + ETHER_CRC_LEN;
10779a5f7854SDavid C Somayajulu
107854ab3b4aSJustin Hibbits ql_sp_log(ha, 9, 4, if_getdrvflags(ifp),
107954ab3b4aSJustin Hibbits (if_getdrvflags(ifp) & IFF_DRV_RUNNING),
108054ab3b4aSJustin Hibbits ha->max_frame_size, if_getmtu(ifp), 0);
1081b65c0c07SDavid C Somayajulu
108254ab3b4aSJustin Hibbits if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
1083b5c2be72SDavid C Somayajulu qla_init_locked(ha);
1084f10a77bbSDavid C Somayajulu }
1085f10a77bbSDavid C Somayajulu
108654ab3b4aSJustin Hibbits if (if_getmtu(ifp) > ETHERMTU)
1087f10a77bbSDavid C Somayajulu ha->std_replenish = QL_JUMBO_REPLENISH_THRES;
1088f10a77bbSDavid C Somayajulu else
1089f10a77bbSDavid C Somayajulu ha->std_replenish = QL_STD_REPLENISH_THRES;
1090f10a77bbSDavid C Somayajulu
1091f10a77bbSDavid C Somayajulu
10927fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__);
1093f10a77bbSDavid C Somayajulu }
1094f10a77bbSDavid C Somayajulu
1095f10a77bbSDavid C Somayajulu break;
1096f10a77bbSDavid C Somayajulu
1097f10a77bbSDavid C Somayajulu case SIOCSIFFLAGS:
1098f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFFLAGS (0x%lx)\n",
1099f10a77bbSDavid C Somayajulu __func__, cmd));
1100f10a77bbSDavid C Somayajulu
11017fb51846SDavid C Somayajulu ret = QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT,
11027fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP);
11037fb51846SDavid C Somayajulu
11047fb51846SDavid C Somayajulu if (ret)
11057fb51846SDavid C Somayajulu break;
1106f10a77bbSDavid C Somayajulu
110754ab3b4aSJustin Hibbits ql_sp_log(ha, 10, 4, if_getdrvflags(ifp),
110854ab3b4aSJustin Hibbits (if_getdrvflags(ifp) & IFF_DRV_RUNNING),
110954ab3b4aSJustin Hibbits ha->if_flags, if_getflags(ifp), 0);
1110b65c0c07SDavid C Somayajulu
111154ab3b4aSJustin Hibbits if (if_getflags(ifp) & IFF_UP) {
111254ab3b4aSJustin Hibbits ha->max_frame_size = if_getmtu(ifp) +
11137fb51846SDavid C Somayajulu ETHER_HDR_LEN + ETHER_CRC_LEN;
11147fb51846SDavid C Somayajulu qla_init_locked(ha);
11157fb51846SDavid C Somayajulu
111654ab3b4aSJustin Hibbits if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
111754ab3b4aSJustin Hibbits if ((if_getflags(ifp) ^ ha->if_flags) &
1118f10a77bbSDavid C Somayajulu IFF_PROMISC) {
1119f10a77bbSDavid C Somayajulu ret = ql_set_promisc(ha);
112054ab3b4aSJustin Hibbits } else if ((if_getflags(ifp) ^ ha->if_flags) &
1121f10a77bbSDavid C Somayajulu IFF_ALLMULTI) {
1122f10a77bbSDavid C Somayajulu ret = ql_set_allmulti(ha);
1123f10a77bbSDavid C Somayajulu }
1124f10a77bbSDavid C Somayajulu }
1125f10a77bbSDavid C Somayajulu } else {
112654ab3b4aSJustin Hibbits if (if_getdrvflags(ifp) & IFF_DRV_RUNNING)
1127f10a77bbSDavid C Somayajulu qla_stop(ha);
112854ab3b4aSJustin Hibbits ha->if_flags = if_getflags(ifp);
1129f10a77bbSDavid C Somayajulu }
1130f10a77bbSDavid C Somayajulu
11317fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__);
1132f10a77bbSDavid C Somayajulu break;
1133f10a77bbSDavid C Somayajulu
1134f10a77bbSDavid C Somayajulu case SIOCADDMULTI:
1135f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev,
1136f10a77bbSDavid C Somayajulu "%s: %s (0x%lx)\n", __func__, "SIOCADDMULTI", cmd));
1137f10a77bbSDavid C Somayajulu
1138f10a77bbSDavid C Somayajulu if (qla_set_multi(ha, 1))
1139f10a77bbSDavid C Somayajulu ret = EINVAL;
1140f10a77bbSDavid C Somayajulu break;
1141f10a77bbSDavid C Somayajulu
1142f10a77bbSDavid C Somayajulu case SIOCDELMULTI:
1143f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev,
1144f10a77bbSDavid C Somayajulu "%s: %s (0x%lx)\n", __func__, "SIOCDELMULTI", cmd));
1145f10a77bbSDavid C Somayajulu
1146f10a77bbSDavid C Somayajulu if (qla_set_multi(ha, 0))
1147f10a77bbSDavid C Somayajulu ret = EINVAL;
1148f10a77bbSDavid C Somayajulu break;
1149f10a77bbSDavid C Somayajulu
1150f10a77bbSDavid C Somayajulu case SIOCSIFMEDIA:
1151f10a77bbSDavid C Somayajulu case SIOCGIFMEDIA:
1152f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev,
1153f10a77bbSDavid C Somayajulu "%s: SIOCSIFMEDIA/SIOCGIFMEDIA (0x%lx)\n",
1154f10a77bbSDavid C Somayajulu __func__, cmd));
1155f10a77bbSDavid C Somayajulu ret = ifmedia_ioctl(ifp, ifr, &ha->media, cmd);
1156f10a77bbSDavid C Somayajulu break;
1157f10a77bbSDavid C Somayajulu
1158f10a77bbSDavid C Somayajulu case SIOCSIFCAP:
1159f10a77bbSDavid C Somayajulu {
116054ab3b4aSJustin Hibbits int mask = ifr->ifr_reqcap ^ if_getcapenable(ifp);
1161f10a77bbSDavid C Somayajulu
1162f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: SIOCSIFCAP (0x%lx)\n",
1163f10a77bbSDavid C Somayajulu __func__, cmd));
1164f10a77bbSDavid C Somayajulu
1165f10a77bbSDavid C Somayajulu if (mask & IFCAP_HWCSUM)
116654ab3b4aSJustin Hibbits if_togglecapenable(ifp, IFCAP_HWCSUM);
1167f10a77bbSDavid C Somayajulu if (mask & IFCAP_TSO4)
116854ab3b4aSJustin Hibbits if_togglecapenable(ifp, IFCAP_TSO4);
11697fb51846SDavid C Somayajulu if (mask & IFCAP_TSO6)
117054ab3b4aSJustin Hibbits if_togglecapenable(ifp, IFCAP_TSO6);
1171f10a77bbSDavid C Somayajulu if (mask & IFCAP_VLAN_HWTAGGING)
117254ab3b4aSJustin Hibbits if_togglecapenable(ifp, IFCAP_VLAN_HWTAGGING);
1173f10a77bbSDavid C Somayajulu if (mask & IFCAP_VLAN_HWTSO)
117454ab3b4aSJustin Hibbits if_togglecapenable(ifp, IFCAP_VLAN_HWTSO);
1175a7c62c11SDavid C Somayajulu if (mask & IFCAP_LRO)
117654ab3b4aSJustin Hibbits if_togglecapenable(ifp, IFCAP_LRO);
1177f10a77bbSDavid C Somayajulu
117854ab3b4aSJustin Hibbits if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
11797fb51846SDavid C Somayajulu ret = QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT,
11807fb51846SDavid C Somayajulu QLA_LOCK_NO_SLEEP);
1181f10a77bbSDavid C Somayajulu
11827fb51846SDavid C Somayajulu if (ret)
11837fb51846SDavid C Somayajulu break;
11847fb51846SDavid C Somayajulu
118554ab3b4aSJustin Hibbits ql_sp_log(ha, 11, 4, if_getdrvflags(ifp),
118654ab3b4aSJustin Hibbits (if_getdrvflags(ifp) & IFF_DRV_RUNNING),
118754ab3b4aSJustin Hibbits mask, if_getcapenable(ifp), 0);
1188b65c0c07SDavid C Somayajulu
11897fb51846SDavid C Somayajulu qla_init_locked(ha);
11907fb51846SDavid C Somayajulu
11917fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__);
11927fb51846SDavid C Somayajulu }
1193f10a77bbSDavid C Somayajulu VLAN_CAPABILITIES(ifp);
1194f10a77bbSDavid C Somayajulu break;
1195f10a77bbSDavid C Somayajulu }
1196f10a77bbSDavid C Somayajulu
1197f10a77bbSDavid C Somayajulu default:
1198f10a77bbSDavid C Somayajulu QL_DPRINT4(ha, (ha->pci_dev, "%s: default (0x%lx)\n",
1199f10a77bbSDavid C Somayajulu __func__, cmd));
1200f10a77bbSDavid C Somayajulu ret = ether_ioctl(ifp, cmd, data);
1201f10a77bbSDavid C Somayajulu break;
1202f10a77bbSDavid C Somayajulu }
1203f10a77bbSDavid C Somayajulu
1204f10a77bbSDavid C Somayajulu return (ret);
1205f10a77bbSDavid C Somayajulu }
1206f10a77bbSDavid C Somayajulu
1207f10a77bbSDavid C Somayajulu static int
qla_media_change(if_t ifp)120854ab3b4aSJustin Hibbits qla_media_change(if_t ifp)
1209f10a77bbSDavid C Somayajulu {
1210f10a77bbSDavid C Somayajulu qla_host_t *ha;
1211f10a77bbSDavid C Somayajulu struct ifmedia *ifm;
1212f10a77bbSDavid C Somayajulu int ret = 0;
1213f10a77bbSDavid C Somayajulu
121454ab3b4aSJustin Hibbits ha = (qla_host_t *)if_getsoftc(ifp);
1215f10a77bbSDavid C Somayajulu
1216f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1217f10a77bbSDavid C Somayajulu
1218f10a77bbSDavid C Somayajulu ifm = &ha->media;
1219f10a77bbSDavid C Somayajulu
1220f10a77bbSDavid C Somayajulu if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1221f10a77bbSDavid C Somayajulu ret = EINVAL;
1222f10a77bbSDavid C Somayajulu
1223f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1224f10a77bbSDavid C Somayajulu
1225f10a77bbSDavid C Somayajulu return (ret);
1226f10a77bbSDavid C Somayajulu }
1227f10a77bbSDavid C Somayajulu
1228f10a77bbSDavid C Somayajulu static void
qla_media_status(if_t ifp,struct ifmediareq * ifmr)122954ab3b4aSJustin Hibbits qla_media_status(if_t ifp, struct ifmediareq *ifmr)
1230f10a77bbSDavid C Somayajulu {
1231f10a77bbSDavid C Somayajulu qla_host_t *ha;
1232f10a77bbSDavid C Somayajulu
123354ab3b4aSJustin Hibbits ha = (qla_host_t *)if_getsoftc(ifp);
1234f10a77bbSDavid C Somayajulu
1235f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1236f10a77bbSDavid C Somayajulu
1237f10a77bbSDavid C Somayajulu ifmr->ifm_status = IFM_AVALID;
1238f10a77bbSDavid C Somayajulu ifmr->ifm_active = IFM_ETHER;
1239f10a77bbSDavid C Somayajulu
1240f10a77bbSDavid C Somayajulu ql_update_link_state(ha);
1241f10a77bbSDavid C Somayajulu if (ha->hw.link_up) {
1242f10a77bbSDavid C Somayajulu ifmr->ifm_status |= IFM_ACTIVE;
1243f10a77bbSDavid C Somayajulu ifmr->ifm_active |= (IFM_FDX | qla_get_optics(ha));
1244f10a77bbSDavid C Somayajulu }
1245f10a77bbSDavid C Somayajulu
1246f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit (%s)\n", __func__,\
1247f10a77bbSDavid C Somayajulu (ha->hw.link_up ? "link_up" : "link_down")));
1248f10a77bbSDavid C Somayajulu
1249f10a77bbSDavid C Somayajulu return;
1250f10a77bbSDavid C Somayajulu }
1251f10a77bbSDavid C Somayajulu
1252f10a77bbSDavid C Somayajulu static int
qla_send(qla_host_t * ha,struct mbuf ** m_headp,uint32_t txr_idx,uint32_t iscsi_pdu)1253b89f2279SDavid C Somayajulu qla_send(qla_host_t *ha, struct mbuf **m_headp, uint32_t txr_idx,
1254b89f2279SDavid C Somayajulu uint32_t iscsi_pdu)
1255f10a77bbSDavid C Somayajulu {
1256f10a77bbSDavid C Somayajulu bus_dma_segment_t segs[QLA_MAX_SEGMENTS];
1257f10a77bbSDavid C Somayajulu bus_dmamap_t map;
1258f10a77bbSDavid C Somayajulu int nsegs;
1259f10a77bbSDavid C Somayajulu int ret = -1;
1260f10a77bbSDavid C Somayajulu uint32_t tx_idx;
1261f10a77bbSDavid C Somayajulu struct mbuf *m_head = *m_headp;
1262f10a77bbSDavid C Somayajulu
1263f10a77bbSDavid C Somayajulu QL_DPRINT8(ha, (ha->pci_dev, "%s: enter\n", __func__));
1264f10a77bbSDavid C Somayajulu
1265f10a77bbSDavid C Somayajulu tx_idx = ha->hw.tx_cntxt[txr_idx].txr_next;
1266c6acf96aSDavid C Somayajulu
1267971e53c9SDavid C Somayajulu if ((NULL != ha->tx_ring[txr_idx].tx_buf[tx_idx].m_head) ||
1268971e53c9SDavid C Somayajulu (QL_ERR_INJECT(ha, INJCT_TXBUF_MBUF_NON_NULL))){
1269c6acf96aSDavid C Somayajulu QL_ASSERT(ha, 0, ("%s [%d]: txr_idx = %d tx_idx = %d "\
1270c6acf96aSDavid C Somayajulu "mbuf = %p\n", __func__, __LINE__, txr_idx, tx_idx,\
1271c6acf96aSDavid C Somayajulu ha->tx_ring[txr_idx].tx_buf[tx_idx].m_head));
1272971e53c9SDavid C Somayajulu
1273*3d6c7ee8SFuqian Huang QL_DPRINT2(ha, (ha->pci_dev, "%s [%d]: txr_idx = %d tx_idx = %d "
1274971e53c9SDavid C Somayajulu "mbuf = %p\n", __func__, __LINE__, txr_idx, tx_idx,
1275*3d6c7ee8SFuqian Huang ha->tx_ring[txr_idx].tx_buf[tx_idx].m_head));
1276971e53c9SDavid C Somayajulu
1277c6acf96aSDavid C Somayajulu if (m_head)
1278c6acf96aSDavid C Somayajulu m_freem(m_head);
1279c6acf96aSDavid C Somayajulu *m_headp = NULL;
1280971e53c9SDavid C Somayajulu QL_INITIATE_RECOVERY(ha);
1281c6acf96aSDavid C Somayajulu return (ret);
1282c6acf96aSDavid C Somayajulu }
1283c6acf96aSDavid C Somayajulu
1284f10a77bbSDavid C Somayajulu map = ha->tx_ring[txr_idx].tx_buf[tx_idx].map;
1285f10a77bbSDavid C Somayajulu
1286f10a77bbSDavid C Somayajulu ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head, segs, &nsegs,
1287f10a77bbSDavid C Somayajulu BUS_DMA_NOWAIT);
1288f10a77bbSDavid C Somayajulu
1289f10a77bbSDavid C Somayajulu if (ret == EFBIG) {
1290f10a77bbSDavid C Somayajulu struct mbuf *m;
1291f10a77bbSDavid C Somayajulu
1292f10a77bbSDavid C Somayajulu QL_DPRINT8(ha, (ha->pci_dev, "%s: EFBIG [%d]\n", __func__,
1293f10a77bbSDavid C Somayajulu m_head->m_pkthdr.len));
1294f10a77bbSDavid C Somayajulu
1295f10a77bbSDavid C Somayajulu m = m_defrag(m_head, M_NOWAIT);
1296f10a77bbSDavid C Somayajulu if (m == NULL) {
1297f10a77bbSDavid C Somayajulu ha->err_tx_defrag++;
1298f10a77bbSDavid C Somayajulu m_freem(m_head);
1299f10a77bbSDavid C Somayajulu *m_headp = NULL;
1300f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev,
1301f10a77bbSDavid C Somayajulu "%s: m_defrag() = NULL [%d]\n",
1302f10a77bbSDavid C Somayajulu __func__, ret);
1303f10a77bbSDavid C Somayajulu return (ENOBUFS);
1304f10a77bbSDavid C Somayajulu }
1305f10a77bbSDavid C Somayajulu m_head = m;
1306f10a77bbSDavid C Somayajulu *m_headp = m_head;
1307f10a77bbSDavid C Somayajulu
1308f10a77bbSDavid C Somayajulu if ((ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head,
1309f10a77bbSDavid C Somayajulu segs, &nsegs, BUS_DMA_NOWAIT))) {
1310f10a77bbSDavid C Somayajulu ha->err_tx_dmamap_load++;
1311f10a77bbSDavid C Somayajulu
1312f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev,
1313f10a77bbSDavid C Somayajulu "%s: bus_dmamap_load_mbuf_sg failed0[%d, %d]\n",
1314f10a77bbSDavid C Somayajulu __func__, ret, m_head->m_pkthdr.len);
1315f10a77bbSDavid C Somayajulu
1316f10a77bbSDavid C Somayajulu if (ret != ENOMEM) {
1317f10a77bbSDavid C Somayajulu m_freem(m_head);
1318f10a77bbSDavid C Somayajulu *m_headp = NULL;
1319f10a77bbSDavid C Somayajulu }
1320f10a77bbSDavid C Somayajulu return (ret);
1321f10a77bbSDavid C Somayajulu }
1322f10a77bbSDavid C Somayajulu
1323f10a77bbSDavid C Somayajulu } else if (ret) {
1324f10a77bbSDavid C Somayajulu ha->err_tx_dmamap_load++;
1325f10a77bbSDavid C Somayajulu
1326f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev,
1327f10a77bbSDavid C Somayajulu "%s: bus_dmamap_load_mbuf_sg failed1[%d, %d]\n",
1328f10a77bbSDavid C Somayajulu __func__, ret, m_head->m_pkthdr.len);
1329f10a77bbSDavid C Somayajulu
1330f10a77bbSDavid C Somayajulu if (ret != ENOMEM) {
1331f10a77bbSDavid C Somayajulu m_freem(m_head);
1332f10a77bbSDavid C Somayajulu *m_headp = NULL;
1333f10a77bbSDavid C Somayajulu }
1334f10a77bbSDavid C Somayajulu return (ret);
1335f10a77bbSDavid C Somayajulu }
1336f10a77bbSDavid C Somayajulu
1337f10a77bbSDavid C Somayajulu QL_ASSERT(ha, (nsegs != 0), ("qla_send: empty packet"));
1338f10a77bbSDavid C Somayajulu
1339f10a77bbSDavid C Somayajulu bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_PREWRITE);
1340f10a77bbSDavid C Somayajulu
134135291c22SDavid C Somayajulu if (!(ret = ql_hw_send(ha, segs, nsegs, tx_idx, m_head, txr_idx,
134235291c22SDavid C Somayajulu iscsi_pdu))) {
1343f10a77bbSDavid C Somayajulu ha->tx_ring[txr_idx].count++;
13447fb51846SDavid C Somayajulu if (iscsi_pdu)
13457fb51846SDavid C Somayajulu ha->tx_ring[txr_idx].iscsi_pkt_count++;
1346f10a77bbSDavid C Somayajulu ha->tx_ring[txr_idx].tx_buf[tx_idx].m_head = m_head;
1347f10a77bbSDavid C Somayajulu } else {
1348203f9d18SDavid C Somayajulu bus_dmamap_unload(ha->tx_tag, map);
1349f10a77bbSDavid C Somayajulu if (ret == EINVAL) {
1350f10a77bbSDavid C Somayajulu if (m_head)
1351f10a77bbSDavid C Somayajulu m_freem(m_head);
1352f10a77bbSDavid C Somayajulu *m_headp = NULL;
1353f10a77bbSDavid C Somayajulu }
1354f10a77bbSDavid C Somayajulu }
1355f10a77bbSDavid C Somayajulu
1356f10a77bbSDavid C Somayajulu QL_DPRINT8(ha, (ha->pci_dev, "%s: exit\n", __func__));
1357f10a77bbSDavid C Somayajulu return (ret);
1358f10a77bbSDavid C Somayajulu }
1359f10a77bbSDavid C Somayajulu
1360b89f2279SDavid C Somayajulu static int
qla_alloc_tx_br(qla_host_t * ha,qla_tx_fp_t * fp)1361b89f2279SDavid C Somayajulu qla_alloc_tx_br(qla_host_t *ha, qla_tx_fp_t *fp)
1362b89f2279SDavid C Somayajulu {
1363b89f2279SDavid C Somayajulu snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
1364b89f2279SDavid C Somayajulu "qla%d_fp%d_tx_mq_lock", ha->pci_func, fp->txr_idx);
1365b89f2279SDavid C Somayajulu
1366b89f2279SDavid C Somayajulu mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
1367b89f2279SDavid C Somayajulu
1368b89f2279SDavid C Somayajulu fp->tx_br = buf_ring_alloc(NUM_TX_DESCRIPTORS, M_DEVBUF,
1369b89f2279SDavid C Somayajulu M_NOWAIT, &fp->tx_mtx);
1370b89f2279SDavid C Somayajulu if (fp->tx_br == NULL) {
1371b89f2279SDavid C Somayajulu QL_DPRINT1(ha, (ha->pci_dev, "buf_ring_alloc failed for "
1372b89f2279SDavid C Somayajulu " fp[%d, %d]\n", ha->pci_func, fp->txr_idx));
1373b89f2279SDavid C Somayajulu return (-ENOMEM);
1374b89f2279SDavid C Somayajulu }
1375b89f2279SDavid C Somayajulu return 0;
1376b89f2279SDavid C Somayajulu }
1377b89f2279SDavid C Somayajulu
1378b89f2279SDavid C Somayajulu static void
qla_free_tx_br(qla_host_t * ha,qla_tx_fp_t * fp)1379b89f2279SDavid C Somayajulu qla_free_tx_br(qla_host_t *ha, qla_tx_fp_t *fp)
1380b89f2279SDavid C Somayajulu {
1381b89f2279SDavid C Somayajulu struct mbuf *mp;
138254ab3b4aSJustin Hibbits if_t ifp = ha->ifp;
1383b89f2279SDavid C Somayajulu
1384b89f2279SDavid C Somayajulu if (mtx_initialized(&fp->tx_mtx)) {
1385b89f2279SDavid C Somayajulu if (fp->tx_br != NULL) {
1386b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx);
1387b89f2279SDavid C Somayajulu
1388b89f2279SDavid C Somayajulu while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) {
1389b89f2279SDavid C Somayajulu m_freem(mp);
1390b89f2279SDavid C Somayajulu }
1391b89f2279SDavid C Somayajulu
1392b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx);
1393b89f2279SDavid C Somayajulu
1394b89f2279SDavid C Somayajulu buf_ring_free(fp->tx_br, M_DEVBUF);
1395b89f2279SDavid C Somayajulu fp->tx_br = NULL;
1396b89f2279SDavid C Somayajulu }
1397b89f2279SDavid C Somayajulu mtx_destroy(&fp->tx_mtx);
1398b89f2279SDavid C Somayajulu }
1399b89f2279SDavid C Somayajulu return;
1400b89f2279SDavid C Somayajulu }
1401b89f2279SDavid C Somayajulu
1402b89f2279SDavid C Somayajulu static void
qla_fp_taskqueue(void * context,int pending)1403b89f2279SDavid C Somayajulu qla_fp_taskqueue(void *context, int pending)
1404b89f2279SDavid C Somayajulu {
1405b89f2279SDavid C Somayajulu qla_tx_fp_t *fp;
1406b89f2279SDavid C Somayajulu qla_host_t *ha;
140754ab3b4aSJustin Hibbits if_t ifp;
1408971e53c9SDavid C Somayajulu struct mbuf *mp = NULL;
1409971e53c9SDavid C Somayajulu int ret = 0;
1410b89f2279SDavid C Somayajulu uint32_t txr_idx;
1411b89f2279SDavid C Somayajulu uint32_t iscsi_pdu = 0;
14127fb51846SDavid C Somayajulu uint32_t rx_pkts_left = -1;
1413b89f2279SDavid C Somayajulu
1414b89f2279SDavid C Somayajulu fp = context;
1415b89f2279SDavid C Somayajulu
1416b89f2279SDavid C Somayajulu if (fp == NULL)
1417b89f2279SDavid C Somayajulu return;
1418b89f2279SDavid C Somayajulu
1419b89f2279SDavid C Somayajulu ha = (qla_host_t *)fp->ha;
1420b89f2279SDavid C Somayajulu
1421b89f2279SDavid C Somayajulu ifp = ha->ifp;
1422b89f2279SDavid C Somayajulu
1423b89f2279SDavid C Somayajulu txr_idx = fp->txr_idx;
1424b89f2279SDavid C Somayajulu
1425b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx);
1426b89f2279SDavid C Somayajulu
142754ab3b4aSJustin Hibbits if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING) || (!ha->hw.link_up)) {
1428b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx);
1429b89f2279SDavid C Somayajulu goto qla_fp_taskqueue_exit;
1430b89f2279SDavid C Somayajulu }
1431b89f2279SDavid C Somayajulu
1432203f9d18SDavid C Somayajulu while (rx_pkts_left && !ha->stop_rcv &&
143354ab3b4aSJustin Hibbits (if_getdrvflags(ifp) & IFF_DRV_RUNNING) && ha->hw.link_up) {
1434b89f2279SDavid C Somayajulu rx_pkts_left = ql_rcv_isr(ha, fp->txr_idx, 64);
1435b89f2279SDavid C Somayajulu
1436b89f2279SDavid C Somayajulu #ifdef QL_ENABLE_ISCSI_TLV
1437b89f2279SDavid C Somayajulu ql_hw_tx_done_locked(ha, fp->txr_idx);
1438b89f2279SDavid C Somayajulu ql_hw_tx_done_locked(ha, (fp->txr_idx + (ha->hw.num_tx_rings >> 1)));
1439b89f2279SDavid C Somayajulu #else
1440b89f2279SDavid C Somayajulu ql_hw_tx_done_locked(ha, fp->txr_idx);
1441b89f2279SDavid C Somayajulu #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
1442b89f2279SDavid C Somayajulu
1443b89f2279SDavid C Somayajulu mp = drbr_peek(ifp, fp->tx_br);
1444b89f2279SDavid C Somayajulu
1445b89f2279SDavid C Somayajulu while (mp != NULL) {
1446b89f2279SDavid C Somayajulu if (M_HASHTYPE_GET(mp) != M_HASHTYPE_NONE) {
1447b89f2279SDavid C Somayajulu #ifdef QL_ENABLE_ISCSI_TLV
1448b89f2279SDavid C Somayajulu if (ql_iscsi_pdu(ha, mp) == 0) {
14497fb51846SDavid C Somayajulu txr_idx = txr_idx +
14507fb51846SDavid C Somayajulu (ha->hw.num_tx_rings >> 1);
1451b89f2279SDavid C Somayajulu iscsi_pdu = 1;
14527fb51846SDavid C Somayajulu } else {
14537fb51846SDavid C Somayajulu iscsi_pdu = 0;
14547fb51846SDavid C Somayajulu txr_idx = fp->txr_idx;
1455b89f2279SDavid C Somayajulu }
1456b89f2279SDavid C Somayajulu #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
1457b89f2279SDavid C Somayajulu }
1458b89f2279SDavid C Somayajulu
1459b89f2279SDavid C Somayajulu ret = qla_send(ha, &mp, txr_idx, iscsi_pdu);
1460b89f2279SDavid C Somayajulu
1461b89f2279SDavid C Somayajulu if (ret) {
1462b89f2279SDavid C Somayajulu if (mp != NULL)
1463b89f2279SDavid C Somayajulu drbr_putback(ifp, fp->tx_br, mp);
1464b89f2279SDavid C Somayajulu else {
1465b89f2279SDavid C Somayajulu drbr_advance(ifp, fp->tx_br);
1466b89f2279SDavid C Somayajulu }
1467b89f2279SDavid C Somayajulu
1468b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx);
1469b89f2279SDavid C Somayajulu
1470b89f2279SDavid C Somayajulu goto qla_fp_taskqueue_exit0;
1471b89f2279SDavid C Somayajulu } else {
1472b89f2279SDavid C Somayajulu drbr_advance(ifp, fp->tx_br);
1473b89f2279SDavid C Somayajulu }
1474b89f2279SDavid C Somayajulu
1475203f9d18SDavid C Somayajulu /* Send a copy of the frame to the BPF listener */
1476203f9d18SDavid C Somayajulu ETHER_BPF_MTAP(ifp, mp);
1477971e53c9SDavid C Somayajulu
147854ab3b4aSJustin Hibbits if (((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) ||
1479971e53c9SDavid C Somayajulu (!ha->hw.link_up))
1480203f9d18SDavid C Somayajulu break;
1481203f9d18SDavid C Somayajulu
1482b89f2279SDavid C Somayajulu mp = drbr_peek(ifp, fp->tx_br);
1483b89f2279SDavid C Somayajulu }
14847fb51846SDavid C Somayajulu }
1485b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx);
1486b89f2279SDavid C Somayajulu
148754ab3b4aSJustin Hibbits if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0)
1488971e53c9SDavid C Somayajulu goto qla_fp_taskqueue_exit;
1489971e53c9SDavid C Somayajulu
1490b89f2279SDavid C Somayajulu qla_fp_taskqueue_exit0:
1491b89f2279SDavid C Somayajulu
1492b89f2279SDavid C Somayajulu if (rx_pkts_left || ((mp != NULL) && ret)) {
1493b89f2279SDavid C Somayajulu taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
1494b89f2279SDavid C Somayajulu } else {
14957fb51846SDavid C Somayajulu if (!ha->stop_rcv) {
1496b89f2279SDavid C Somayajulu QL_ENABLE_INTERRUPTS(ha, fp->txr_idx);
1497b89f2279SDavid C Somayajulu }
1498b89f2279SDavid C Somayajulu }
1499b89f2279SDavid C Somayajulu
1500b89f2279SDavid C Somayajulu qla_fp_taskqueue_exit:
1501b89f2279SDavid C Somayajulu
1502b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = %d\n", __func__, ret));
1503b89f2279SDavid C Somayajulu return;
1504b89f2279SDavid C Somayajulu }
1505b89f2279SDavid C Somayajulu
1506b89f2279SDavid C Somayajulu static int
qla_create_fp_taskqueues(qla_host_t * ha)1507b89f2279SDavid C Somayajulu qla_create_fp_taskqueues(qla_host_t *ha)
1508b89f2279SDavid C Somayajulu {
1509b89f2279SDavid C Somayajulu int i;
1510b89f2279SDavid C Somayajulu uint8_t tq_name[32];
1511b89f2279SDavid C Somayajulu
1512b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
1513b89f2279SDavid C Somayajulu qla_tx_fp_t *fp = &ha->tx_fp[i];
1514b89f2279SDavid C Somayajulu
1515b89f2279SDavid C Somayajulu bzero(tq_name, sizeof (tq_name));
1516b89f2279SDavid C Somayajulu snprintf(tq_name, sizeof (tq_name), "ql_fp_tq_%d", i);
1517b89f2279SDavid C Somayajulu
15186c3e93cbSGleb Smirnoff NET_TASK_INIT(&fp->fp_task, 0, qla_fp_taskqueue, fp);
1519b89f2279SDavid C Somayajulu
1520b89f2279SDavid C Somayajulu fp->fp_taskqueue = taskqueue_create_fast(tq_name, M_NOWAIT,
1521b89f2279SDavid C Somayajulu taskqueue_thread_enqueue,
1522b89f2279SDavid C Somayajulu &fp->fp_taskqueue);
1523b89f2279SDavid C Somayajulu
1524b89f2279SDavid C Somayajulu if (fp->fp_taskqueue == NULL)
1525b89f2279SDavid C Somayajulu return (-1);
1526b89f2279SDavid C Somayajulu
1527b89f2279SDavid C Somayajulu taskqueue_start_threads(&fp->fp_taskqueue, 1, PI_NET, "%s",
1528b89f2279SDavid C Somayajulu tq_name);
1529b89f2279SDavid C Somayajulu
1530b89f2279SDavid C Somayajulu QL_DPRINT1(ha, (ha->pci_dev, "%s: %p\n", __func__,
1531b89f2279SDavid C Somayajulu fp->fp_taskqueue));
1532b89f2279SDavid C Somayajulu }
1533b89f2279SDavid C Somayajulu
1534b89f2279SDavid C Somayajulu return (0);
1535b89f2279SDavid C Somayajulu }
1536b89f2279SDavid C Somayajulu
1537b89f2279SDavid C Somayajulu static void
qla_destroy_fp_taskqueues(qla_host_t * ha)1538b89f2279SDavid C Somayajulu qla_destroy_fp_taskqueues(qla_host_t *ha)
1539b89f2279SDavid C Somayajulu {
1540b89f2279SDavid C Somayajulu int i;
1541b89f2279SDavid C Somayajulu
1542b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
1543b89f2279SDavid C Somayajulu qla_tx_fp_t *fp = &ha->tx_fp[i];
1544b89f2279SDavid C Somayajulu
1545b89f2279SDavid C Somayajulu if (fp->fp_taskqueue != NULL) {
1546b65c0c07SDavid C Somayajulu taskqueue_drain_all(fp->fp_taskqueue);
1547b89f2279SDavid C Somayajulu taskqueue_free(fp->fp_taskqueue);
1548b89f2279SDavid C Somayajulu fp->fp_taskqueue = NULL;
1549b89f2279SDavid C Somayajulu }
1550b89f2279SDavid C Somayajulu }
1551b89f2279SDavid C Somayajulu return;
1552b89f2279SDavid C Somayajulu }
1553b89f2279SDavid C Somayajulu
1554b89f2279SDavid C Somayajulu static void
qla_drain_fp_taskqueues(qla_host_t * ha)1555b89f2279SDavid C Somayajulu qla_drain_fp_taskqueues(qla_host_t *ha)
1556b89f2279SDavid C Somayajulu {
1557b89f2279SDavid C Somayajulu int i;
1558b89f2279SDavid C Somayajulu
1559b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
1560b89f2279SDavid C Somayajulu qla_tx_fp_t *fp = &ha->tx_fp[i];
1561b89f2279SDavid C Somayajulu
1562b89f2279SDavid C Somayajulu if (fp->fp_taskqueue != NULL) {
1563b65c0c07SDavid C Somayajulu taskqueue_drain_all(fp->fp_taskqueue);
1564b89f2279SDavid C Somayajulu }
1565b89f2279SDavid C Somayajulu }
1566b89f2279SDavid C Somayajulu return;
1567b89f2279SDavid C Somayajulu }
1568b89f2279SDavid C Somayajulu
1569b89f2279SDavid C Somayajulu static int
qla_transmit(if_t ifp,struct mbuf * mp)157054ab3b4aSJustin Hibbits qla_transmit(if_t ifp, struct mbuf *mp)
1571b89f2279SDavid C Somayajulu {
157254ab3b4aSJustin Hibbits qla_host_t *ha = (qla_host_t *)if_getsoftc(ifp);
1573b89f2279SDavid C Somayajulu qla_tx_fp_t *fp;
1574b89f2279SDavid C Somayajulu int rss_id = 0;
1575b89f2279SDavid C Somayajulu int ret = 0;
1576b89f2279SDavid C Somayajulu
1577b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1578b89f2279SDavid C Somayajulu
1579b89f2279SDavid C Somayajulu if (M_HASHTYPE_GET(mp) != M_HASHTYPE_NONE)
1580b89f2279SDavid C Somayajulu rss_id = (mp->m_pkthdr.flowid & Q8_RSS_IND_TBL_MAX_IDX) %
1581b89f2279SDavid C Somayajulu ha->hw.num_sds_rings;
1582b89f2279SDavid C Somayajulu fp = &ha->tx_fp[rss_id];
1583b89f2279SDavid C Somayajulu
1584b89f2279SDavid C Somayajulu if (fp->tx_br == NULL) {
1585b89f2279SDavid C Somayajulu ret = EINVAL;
1586b89f2279SDavid C Somayajulu goto qla_transmit_exit;
1587b89f2279SDavid C Somayajulu }
1588b89f2279SDavid C Somayajulu
1589b89f2279SDavid C Somayajulu if (mp != NULL) {
1590b89f2279SDavid C Somayajulu ret = drbr_enqueue(ifp, fp->tx_br, mp);
1591b89f2279SDavid C Somayajulu }
1592b89f2279SDavid C Somayajulu
1593b89f2279SDavid C Somayajulu if (fp->fp_taskqueue != NULL)
1594b89f2279SDavid C Somayajulu taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
1595b89f2279SDavid C Somayajulu
1596b89f2279SDavid C Somayajulu ret = 0;
1597b89f2279SDavid C Somayajulu
1598b89f2279SDavid C Somayajulu qla_transmit_exit:
1599b89f2279SDavid C Somayajulu
1600b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = %d\n", __func__, ret));
1601b89f2279SDavid C Somayajulu return ret;
1602b89f2279SDavid C Somayajulu }
1603b89f2279SDavid C Somayajulu
1604b89f2279SDavid C Somayajulu static void
qla_qflush(if_t ifp)160554ab3b4aSJustin Hibbits qla_qflush(if_t ifp)
1606b89f2279SDavid C Somayajulu {
1607b89f2279SDavid C Somayajulu int i;
1608b89f2279SDavid C Somayajulu qla_tx_fp_t *fp;
1609b89f2279SDavid C Somayajulu struct mbuf *mp;
1610b89f2279SDavid C Somayajulu qla_host_t *ha;
1611b89f2279SDavid C Somayajulu
161254ab3b4aSJustin Hibbits ha = (qla_host_t *)if_getsoftc(ifp);
1613b89f2279SDavid C Somayajulu
1614b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1615b89f2279SDavid C Somayajulu
1616b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
1617b89f2279SDavid C Somayajulu fp = &ha->tx_fp[i];
1618b89f2279SDavid C Somayajulu
1619b89f2279SDavid C Somayajulu if (fp == NULL)
1620b89f2279SDavid C Somayajulu continue;
1621b89f2279SDavid C Somayajulu
1622b89f2279SDavid C Somayajulu if (fp->tx_br) {
1623b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx);
1624b89f2279SDavid C Somayajulu
1625b89f2279SDavid C Somayajulu while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) {
1626b89f2279SDavid C Somayajulu m_freem(mp);
1627b89f2279SDavid C Somayajulu }
1628b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx);
1629b89f2279SDavid C Somayajulu }
1630b89f2279SDavid C Somayajulu }
1631b89f2279SDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1632b89f2279SDavid C Somayajulu
1633b89f2279SDavid C Somayajulu return;
1634b89f2279SDavid C Somayajulu }
1635b89f2279SDavid C Somayajulu
1636f10a77bbSDavid C Somayajulu static void
qla_stop(qla_host_t * ha)1637f10a77bbSDavid C Somayajulu qla_stop(qla_host_t *ha)
1638f10a77bbSDavid C Somayajulu {
163954ab3b4aSJustin Hibbits if_t ifp = ha->ifp;
1640b89f2279SDavid C Somayajulu int i = 0;
1641f10a77bbSDavid C Somayajulu
1642b65c0c07SDavid C Somayajulu ql_sp_log(ha, 13, 0, 0, 0, 0, 0, 0);
1643b65c0c07SDavid C Somayajulu
164454ab3b4aSJustin Hibbits if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
16457fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 1;
1646b89f2279SDavid C Somayajulu
1647b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
1648b89f2279SDavid C Somayajulu qla_tx_fp_t *fp;
1649b89f2279SDavid C Somayajulu
1650b89f2279SDavid C Somayajulu fp = &ha->tx_fp[i];
1651b89f2279SDavid C Somayajulu
1652b89f2279SDavid C Somayajulu if (fp == NULL)
1653b89f2279SDavid C Somayajulu continue;
1654b89f2279SDavid C Somayajulu
1655b89f2279SDavid C Somayajulu if (fp->tx_br != NULL) {
1656b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx);
1657b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx);
1658b89f2279SDavid C Somayajulu }
1659b89f2279SDavid C Somayajulu }
1660f10a77bbSDavid C Somayajulu
16617fb51846SDavid C Somayajulu while (!ha->qla_watchdog_paused)
1662f10a77bbSDavid C Somayajulu qla_mdelay(__func__, 1);
1663f10a77bbSDavid C Somayajulu
16647fb51846SDavid C Somayajulu ha->qla_interface_up = 0;
16656a62bec0SDavid C Somayajulu
1666b89f2279SDavid C Somayajulu qla_drain_fp_taskqueues(ha);
1667f10a77bbSDavid C Somayajulu
1668f10a77bbSDavid C Somayajulu ql_del_hw_if(ha);
1669f10a77bbSDavid C Somayajulu
1670f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(ha);
1671f10a77bbSDavid C Somayajulu qla_free_rcv_bufs(ha);
1672f10a77bbSDavid C Somayajulu
1673f10a77bbSDavid C Somayajulu return;
1674f10a77bbSDavid C Somayajulu }
1675f10a77bbSDavid C Somayajulu
1676f10a77bbSDavid C Somayajulu /*
1677f10a77bbSDavid C Somayajulu * Buffer Management Functions for Transmit and Receive Rings
1678f10a77bbSDavid C Somayajulu */
1679f10a77bbSDavid C Somayajulu static int
qla_alloc_xmt_bufs(qla_host_t * ha)1680f10a77bbSDavid C Somayajulu qla_alloc_xmt_bufs(qla_host_t *ha)
1681f10a77bbSDavid C Somayajulu {
1682f10a77bbSDavid C Somayajulu int ret = 0;
1683f10a77bbSDavid C Somayajulu uint32_t i, j;
1684f10a77bbSDavid C Somayajulu qla_tx_buf_t *txb;
1685f10a77bbSDavid C Somayajulu
1686f10a77bbSDavid C Somayajulu if (bus_dma_tag_create(NULL, /* parent */
1687f10a77bbSDavid C Somayajulu 1, 0, /* alignment, bounds */
1688f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* lowaddr */
1689f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* highaddr */
1690f10a77bbSDavid C Somayajulu NULL, NULL, /* filter, filterarg */
1691f10a77bbSDavid C Somayajulu QLA_MAX_TSO_FRAME_SIZE, /* maxsize */
1692f10a77bbSDavid C Somayajulu QLA_MAX_SEGMENTS, /* nsegments */
1693f10a77bbSDavid C Somayajulu PAGE_SIZE, /* maxsegsize */
1694f10a77bbSDavid C Somayajulu BUS_DMA_ALLOCNOW, /* flags */
1695f10a77bbSDavid C Somayajulu NULL, /* lockfunc */
1696f10a77bbSDavid C Somayajulu NULL, /* lockfuncarg */
1697f10a77bbSDavid C Somayajulu &ha->tx_tag)) {
1698f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, "%s: tx_tag alloc failed\n",
1699f10a77bbSDavid C Somayajulu __func__);
1700f10a77bbSDavid C Somayajulu return (ENOMEM);
1701f10a77bbSDavid C Somayajulu }
1702f10a77bbSDavid C Somayajulu
1703f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_tx_rings; i++) {
1704f10a77bbSDavid C Somayajulu bzero((void *)ha->tx_ring[i].tx_buf,
1705f10a77bbSDavid C Somayajulu (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS));
1706f10a77bbSDavid C Somayajulu }
1707f10a77bbSDavid C Somayajulu
1708f10a77bbSDavid C Somayajulu for (j = 0; j < ha->hw.num_tx_rings; j++) {
1709f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_TX_DESCRIPTORS; i++) {
1710f10a77bbSDavid C Somayajulu txb = &ha->tx_ring[j].tx_buf[i];
1711f10a77bbSDavid C Somayajulu
1712f10a77bbSDavid C Somayajulu if ((ret = bus_dmamap_create(ha->tx_tag,
1713f10a77bbSDavid C Somayajulu BUS_DMA_NOWAIT, &txb->map))) {
1714f10a77bbSDavid C Somayajulu ha->err_tx_dmamap_create++;
1715f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev,
1716f10a77bbSDavid C Somayajulu "%s: bus_dmamap_create failed[%d]\n",
1717f10a77bbSDavid C Somayajulu __func__, ret);
1718f10a77bbSDavid C Somayajulu
1719f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(ha);
1720f10a77bbSDavid C Somayajulu
1721f10a77bbSDavid C Somayajulu return (ret);
1722f10a77bbSDavid C Somayajulu }
1723f10a77bbSDavid C Somayajulu }
1724f10a77bbSDavid C Somayajulu }
1725f10a77bbSDavid C Somayajulu
1726f10a77bbSDavid C Somayajulu return 0;
1727f10a77bbSDavid C Somayajulu }
1728f10a77bbSDavid C Somayajulu
1729f10a77bbSDavid C Somayajulu /*
1730f10a77bbSDavid C Somayajulu * Release mbuf after it sent on the wire
1731f10a77bbSDavid C Somayajulu */
1732f10a77bbSDavid C Somayajulu static void
qla_clear_tx_buf(qla_host_t * ha,qla_tx_buf_t * txb)1733f10a77bbSDavid C Somayajulu qla_clear_tx_buf(qla_host_t *ha, qla_tx_buf_t *txb)
1734f10a77bbSDavid C Somayajulu {
1735f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1736f10a77bbSDavid C Somayajulu
1737203f9d18SDavid C Somayajulu if (txb->m_head) {
1738203f9d18SDavid C Somayajulu bus_dmamap_sync(ha->tx_tag, txb->map,
1739203f9d18SDavid C Somayajulu BUS_DMASYNC_POSTWRITE);
1740f10a77bbSDavid C Somayajulu
1741f10a77bbSDavid C Somayajulu bus_dmamap_unload(ha->tx_tag, txb->map);
1742f10a77bbSDavid C Somayajulu
1743f10a77bbSDavid C Somayajulu m_freem(txb->m_head);
1744f10a77bbSDavid C Somayajulu txb->m_head = NULL;
1745203f9d18SDavid C Somayajulu
1746203f9d18SDavid C Somayajulu bus_dmamap_destroy(ha->tx_tag, txb->map);
1747203f9d18SDavid C Somayajulu txb->map = NULL;
1748f10a77bbSDavid C Somayajulu }
1749f10a77bbSDavid C Somayajulu
1750203f9d18SDavid C Somayajulu if (txb->map) {
1751203f9d18SDavid C Somayajulu bus_dmamap_unload(ha->tx_tag, txb->map);
1752f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->tx_tag, txb->map);
1753203f9d18SDavid C Somayajulu txb->map = NULL;
1754203f9d18SDavid C Somayajulu }
1755f10a77bbSDavid C Somayajulu
1756f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit\n", __func__));
1757f10a77bbSDavid C Somayajulu }
1758f10a77bbSDavid C Somayajulu
1759f10a77bbSDavid C Somayajulu static void
qla_free_xmt_bufs(qla_host_t * ha)1760f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(qla_host_t *ha)
1761f10a77bbSDavid C Somayajulu {
1762f10a77bbSDavid C Somayajulu int i, j;
1763f10a77bbSDavid C Somayajulu
1764f10a77bbSDavid C Somayajulu for (j = 0; j < ha->hw.num_tx_rings; j++) {
1765f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_TX_DESCRIPTORS; i++)
1766f10a77bbSDavid C Somayajulu qla_clear_tx_buf(ha, &ha->tx_ring[j].tx_buf[i]);
1767f10a77bbSDavid C Somayajulu }
1768f10a77bbSDavid C Somayajulu
1769f10a77bbSDavid C Somayajulu if (ha->tx_tag != NULL) {
1770f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(ha->tx_tag);
1771f10a77bbSDavid C Somayajulu ha->tx_tag = NULL;
1772f10a77bbSDavid C Somayajulu }
1773f10a77bbSDavid C Somayajulu
1774f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_tx_rings; i++) {
1775f10a77bbSDavid C Somayajulu bzero((void *)ha->tx_ring[i].tx_buf,
1776f10a77bbSDavid C Somayajulu (sizeof(qla_tx_buf_t) * NUM_TX_DESCRIPTORS));
1777f10a77bbSDavid C Somayajulu }
1778f10a77bbSDavid C Somayajulu return;
1779f10a77bbSDavid C Somayajulu }
1780f10a77bbSDavid C Somayajulu
1781f10a77bbSDavid C Somayajulu static int
qla_alloc_rcv_std(qla_host_t * ha)1782f10a77bbSDavid C Somayajulu qla_alloc_rcv_std(qla_host_t *ha)
1783f10a77bbSDavid C Somayajulu {
1784f10a77bbSDavid C Somayajulu int i, j, k, r, ret = 0;
1785f10a77bbSDavid C Somayajulu qla_rx_buf_t *rxb;
1786f10a77bbSDavid C Somayajulu qla_rx_ring_t *rx_ring;
1787f10a77bbSDavid C Somayajulu
1788f10a77bbSDavid C Somayajulu for (r = 0; r < ha->hw.num_rds_rings; r++) {
1789f10a77bbSDavid C Somayajulu rx_ring = &ha->rx_ring[r];
1790f10a77bbSDavid C Somayajulu
1791f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1792f10a77bbSDavid C Somayajulu rxb = &rx_ring->rx_buf[i];
1793f10a77bbSDavid C Somayajulu
1794f10a77bbSDavid C Somayajulu ret = bus_dmamap_create(ha->rx_tag, BUS_DMA_NOWAIT,
1795f10a77bbSDavid C Somayajulu &rxb->map);
1796f10a77bbSDavid C Somayajulu
1797f10a77bbSDavid C Somayajulu if (ret) {
1798f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev,
1799f10a77bbSDavid C Somayajulu "%s: dmamap[%d, %d] failed\n",
1800f10a77bbSDavid C Somayajulu __func__, r, i);
1801f10a77bbSDavid C Somayajulu
1802f10a77bbSDavid C Somayajulu for (k = 0; k < r; k++) {
1803f10a77bbSDavid C Somayajulu for (j = 0; j < NUM_RX_DESCRIPTORS;
1804f10a77bbSDavid C Somayajulu j++) {
1805f10a77bbSDavid C Somayajulu rxb = &ha->rx_ring[k].rx_buf[j];
1806f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->rx_tag,
1807f10a77bbSDavid C Somayajulu rxb->map);
1808f10a77bbSDavid C Somayajulu }
1809f10a77bbSDavid C Somayajulu }
1810f10a77bbSDavid C Somayajulu
1811f10a77bbSDavid C Somayajulu for (j = 0; j < i; j++) {
1812f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->rx_tag,
1813f10a77bbSDavid C Somayajulu rx_ring->rx_buf[j].map);
1814f10a77bbSDavid C Somayajulu }
1815f10a77bbSDavid C Somayajulu goto qla_alloc_rcv_std_err;
1816f10a77bbSDavid C Somayajulu }
1817f10a77bbSDavid C Somayajulu }
1818f10a77bbSDavid C Somayajulu }
1819f10a77bbSDavid C Somayajulu
1820f10a77bbSDavid C Somayajulu qla_init_hw_rcv_descriptors(ha);
1821f10a77bbSDavid C Somayajulu
1822f10a77bbSDavid C Somayajulu for (r = 0; r < ha->hw.num_rds_rings; r++) {
1823f10a77bbSDavid C Somayajulu rx_ring = &ha->rx_ring[r];
1824f10a77bbSDavid C Somayajulu
1825f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1826f10a77bbSDavid C Somayajulu rxb = &rx_ring->rx_buf[i];
1827f10a77bbSDavid C Somayajulu rxb->handle = i;
1828f10a77bbSDavid C Somayajulu if (!(ret = ql_get_mbuf(ha, rxb, NULL))) {
1829f10a77bbSDavid C Somayajulu /*
1830f10a77bbSDavid C Somayajulu * set the physical address in the
1831f10a77bbSDavid C Somayajulu * corresponding descriptor entry in the
1832f10a77bbSDavid C Somayajulu * receive ring/queue for the hba
1833f10a77bbSDavid C Somayajulu */
1834f10a77bbSDavid C Somayajulu qla_set_hw_rcv_desc(ha, r, i, rxb->handle,
1835f10a77bbSDavid C Somayajulu rxb->paddr,
1836f10a77bbSDavid C Somayajulu (rxb->m_head)->m_pkthdr.len);
1837f10a77bbSDavid C Somayajulu } else {
1838f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev,
1839f10a77bbSDavid C Somayajulu "%s: ql_get_mbuf [%d, %d] failed\n",
1840f10a77bbSDavid C Somayajulu __func__, r, i);
1841f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->rx_tag, rxb->map);
1842f10a77bbSDavid C Somayajulu goto qla_alloc_rcv_std_err;
1843f10a77bbSDavid C Somayajulu }
1844f10a77bbSDavid C Somayajulu }
1845f10a77bbSDavid C Somayajulu }
1846f10a77bbSDavid C Somayajulu return 0;
1847f10a77bbSDavid C Somayajulu
1848f10a77bbSDavid C Somayajulu qla_alloc_rcv_std_err:
1849f10a77bbSDavid C Somayajulu return (-1);
1850f10a77bbSDavid C Somayajulu }
1851f10a77bbSDavid C Somayajulu
1852f10a77bbSDavid C Somayajulu static void
qla_free_rcv_std(qla_host_t * ha)1853f10a77bbSDavid C Somayajulu qla_free_rcv_std(qla_host_t *ha)
1854f10a77bbSDavid C Somayajulu {
1855f10a77bbSDavid C Somayajulu int i, r;
1856f10a77bbSDavid C Somayajulu qla_rx_buf_t *rxb;
1857f10a77bbSDavid C Somayajulu
1858f10a77bbSDavid C Somayajulu for (r = 0; r < ha->hw.num_rds_rings; r++) {
1859f10a77bbSDavid C Somayajulu for (i = 0; i < NUM_RX_DESCRIPTORS; i++) {
1860f10a77bbSDavid C Somayajulu rxb = &ha->rx_ring[r].rx_buf[i];
1861f10a77bbSDavid C Somayajulu if (rxb->m_head != NULL) {
1862f10a77bbSDavid C Somayajulu bus_dmamap_unload(ha->rx_tag, rxb->map);
1863f10a77bbSDavid C Somayajulu bus_dmamap_destroy(ha->rx_tag, rxb->map);
1864f10a77bbSDavid C Somayajulu m_freem(rxb->m_head);
1865f10a77bbSDavid C Somayajulu rxb->m_head = NULL;
1866f10a77bbSDavid C Somayajulu }
1867f10a77bbSDavid C Somayajulu }
1868f10a77bbSDavid C Somayajulu }
1869f10a77bbSDavid C Somayajulu return;
1870f10a77bbSDavid C Somayajulu }
1871f10a77bbSDavid C Somayajulu
1872f10a77bbSDavid C Somayajulu static int
qla_alloc_rcv_bufs(qla_host_t * ha)1873f10a77bbSDavid C Somayajulu qla_alloc_rcv_bufs(qla_host_t *ha)
1874f10a77bbSDavid C Somayajulu {
1875f10a77bbSDavid C Somayajulu int i, ret = 0;
1876f10a77bbSDavid C Somayajulu
1877f10a77bbSDavid C Somayajulu if (bus_dma_tag_create(NULL, /* parent */
1878f10a77bbSDavid C Somayajulu 1, 0, /* alignment, bounds */
1879f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* lowaddr */
1880f10a77bbSDavid C Somayajulu BUS_SPACE_MAXADDR, /* highaddr */
1881f10a77bbSDavid C Somayajulu NULL, NULL, /* filter, filterarg */
1882f10a77bbSDavid C Somayajulu MJUM9BYTES, /* maxsize */
1883f10a77bbSDavid C Somayajulu 1, /* nsegments */
1884f10a77bbSDavid C Somayajulu MJUM9BYTES, /* maxsegsize */
1885f10a77bbSDavid C Somayajulu BUS_DMA_ALLOCNOW, /* flags */
1886f10a77bbSDavid C Somayajulu NULL, /* lockfunc */
1887f10a77bbSDavid C Somayajulu NULL, /* lockfuncarg */
1888f10a77bbSDavid C Somayajulu &ha->rx_tag)) {
1889f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev, "%s: rx_tag alloc failed\n",
1890f10a77bbSDavid C Somayajulu __func__);
1891f10a77bbSDavid C Somayajulu
1892f10a77bbSDavid C Somayajulu return (ENOMEM);
1893f10a77bbSDavid C Somayajulu }
1894f10a77bbSDavid C Somayajulu
1895f10a77bbSDavid C Somayajulu bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS));
1896f10a77bbSDavid C Somayajulu
1897f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
1898f10a77bbSDavid C Somayajulu ha->hw.sds[i].sdsr_next = 0;
1899f10a77bbSDavid C Somayajulu ha->hw.sds[i].rxb_free = NULL;
1900f10a77bbSDavid C Somayajulu ha->hw.sds[i].rx_free = 0;
1901f10a77bbSDavid C Somayajulu }
1902f10a77bbSDavid C Somayajulu
1903f10a77bbSDavid C Somayajulu ret = qla_alloc_rcv_std(ha);
1904f10a77bbSDavid C Somayajulu
1905f10a77bbSDavid C Somayajulu return (ret);
1906f10a77bbSDavid C Somayajulu }
1907f10a77bbSDavid C Somayajulu
1908f10a77bbSDavid C Somayajulu static void
qla_free_rcv_bufs(qla_host_t * ha)1909f10a77bbSDavid C Somayajulu qla_free_rcv_bufs(qla_host_t *ha)
1910f10a77bbSDavid C Somayajulu {
1911f10a77bbSDavid C Somayajulu int i;
1912f10a77bbSDavid C Somayajulu
1913f10a77bbSDavid C Somayajulu qla_free_rcv_std(ha);
1914f10a77bbSDavid C Somayajulu
1915f10a77bbSDavid C Somayajulu if (ha->rx_tag != NULL) {
1916f10a77bbSDavid C Somayajulu bus_dma_tag_destroy(ha->rx_tag);
1917f10a77bbSDavid C Somayajulu ha->rx_tag = NULL;
1918f10a77bbSDavid C Somayajulu }
1919f10a77bbSDavid C Somayajulu
1920f10a77bbSDavid C Somayajulu bzero((void *)ha->rx_ring, (sizeof(qla_rx_ring_t) * MAX_RDS_RINGS));
1921f10a77bbSDavid C Somayajulu
1922f10a77bbSDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
1923f10a77bbSDavid C Somayajulu ha->hw.sds[i].sdsr_next = 0;
1924f10a77bbSDavid C Somayajulu ha->hw.sds[i].rxb_free = NULL;
1925f10a77bbSDavid C Somayajulu ha->hw.sds[i].rx_free = 0;
1926f10a77bbSDavid C Somayajulu }
1927f10a77bbSDavid C Somayajulu
1928f10a77bbSDavid C Somayajulu return;
1929f10a77bbSDavid C Somayajulu }
1930f10a77bbSDavid C Somayajulu
1931f10a77bbSDavid C Somayajulu int
ql_get_mbuf(qla_host_t * ha,qla_rx_buf_t * rxb,struct mbuf * nmp)1932f10a77bbSDavid C Somayajulu ql_get_mbuf(qla_host_t *ha, qla_rx_buf_t *rxb, struct mbuf *nmp)
1933f10a77bbSDavid C Somayajulu {
19347fb51846SDavid C Somayajulu register struct mbuf *mp = nmp;
1935f10a77bbSDavid C Somayajulu int ret = 0;
1936f10a77bbSDavid C Somayajulu uint32_t offset;
1937f10a77bbSDavid C Somayajulu bus_dma_segment_t segs[1];
193835291c22SDavid C Somayajulu int nsegs, mbuf_size;
1939f10a77bbSDavid C Somayajulu
1940f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: enter\n", __func__));
1941f10a77bbSDavid C Somayajulu
194235291c22SDavid C Somayajulu if (ha->hw.enable_9kb)
194335291c22SDavid C Somayajulu mbuf_size = MJUM9BYTES;
194435291c22SDavid C Somayajulu else
194535291c22SDavid C Somayajulu mbuf_size = MCLBYTES;
194635291c22SDavid C Somayajulu
1947f10a77bbSDavid C Somayajulu if (mp == NULL) {
194800caeec7SDavid C Somayajulu if (QL_ERR_INJECT(ha, INJCT_M_GETCL_M_GETJCL_FAILURE))
194900caeec7SDavid C Somayajulu return(-1);
195000caeec7SDavid C Somayajulu
195135291c22SDavid C Somayajulu if (ha->hw.enable_9kb)
195235291c22SDavid C Somayajulu mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, mbuf_size);
195335291c22SDavid C Somayajulu else
1954f10a77bbSDavid C Somayajulu mp = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
1955f10a77bbSDavid C Somayajulu
1956f10a77bbSDavid C Somayajulu if (mp == NULL) {
1957f10a77bbSDavid C Somayajulu ha->err_m_getcl++;
1958f10a77bbSDavid C Somayajulu ret = ENOBUFS;
1959f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev,
1960f10a77bbSDavid C Somayajulu "%s: m_getcl failed\n", __func__);
1961f10a77bbSDavid C Somayajulu goto exit_ql_get_mbuf;
1962f10a77bbSDavid C Somayajulu }
196335291c22SDavid C Somayajulu mp->m_len = mp->m_pkthdr.len = mbuf_size;
1964f10a77bbSDavid C Somayajulu } else {
196535291c22SDavid C Somayajulu mp->m_len = mp->m_pkthdr.len = mbuf_size;
1966f10a77bbSDavid C Somayajulu mp->m_data = mp->m_ext.ext_buf;
1967f10a77bbSDavid C Somayajulu mp->m_next = NULL;
1968f10a77bbSDavid C Somayajulu }
1969f10a77bbSDavid C Somayajulu
1970f10a77bbSDavid C Somayajulu offset = (uint32_t)((unsigned long long)mp->m_data & 0x7ULL);
1971f10a77bbSDavid C Somayajulu if (offset) {
1972f10a77bbSDavid C Somayajulu offset = 8 - offset;
1973f10a77bbSDavid C Somayajulu m_adj(mp, offset);
1974f10a77bbSDavid C Somayajulu }
1975f10a77bbSDavid C Somayajulu
1976f10a77bbSDavid C Somayajulu /*
1977f10a77bbSDavid C Somayajulu * Using memory from the mbuf cluster pool, invoke the bus_dma
1978f10a77bbSDavid C Somayajulu * machinery to arrange the memory mapping.
1979f10a77bbSDavid C Somayajulu */
1980f10a77bbSDavid C Somayajulu ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, rxb->map,
1981f10a77bbSDavid C Somayajulu mp, segs, &nsegs, BUS_DMA_NOWAIT);
1982f10a77bbSDavid C Somayajulu rxb->paddr = segs[0].ds_addr;
1983f10a77bbSDavid C Somayajulu
1984f10a77bbSDavid C Somayajulu if (ret || !rxb->paddr || (nsegs != 1)) {
1985f10a77bbSDavid C Somayajulu m_free(mp);
1986f10a77bbSDavid C Somayajulu rxb->m_head = NULL;
1987f10a77bbSDavid C Somayajulu device_printf(ha->pci_dev,
1988f10a77bbSDavid C Somayajulu "%s: bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
1989f10a77bbSDavid C Somayajulu __func__, ret, (long long unsigned int)rxb->paddr,
1990f10a77bbSDavid C Somayajulu nsegs);
1991f10a77bbSDavid C Somayajulu ret = -1;
1992f10a77bbSDavid C Somayajulu goto exit_ql_get_mbuf;
1993f10a77bbSDavid C Somayajulu }
1994f10a77bbSDavid C Somayajulu rxb->m_head = mp;
1995f10a77bbSDavid C Somayajulu bus_dmamap_sync(ha->rx_tag, rxb->map, BUS_DMASYNC_PREREAD);
1996f10a77bbSDavid C Somayajulu
1997f10a77bbSDavid C Somayajulu exit_ql_get_mbuf:
1998f10a77bbSDavid C Somayajulu QL_DPRINT2(ha, (ha->pci_dev, "%s: exit ret = 0x%08x\n", __func__, ret));
1999f10a77bbSDavid C Somayajulu return (ret);
2000f10a77bbSDavid C Somayajulu }
2001f10a77bbSDavid C Somayajulu
2002f10a77bbSDavid C Somayajulu static void
qla_get_peer(qla_host_t * ha)2003f10a77bbSDavid C Somayajulu qla_get_peer(qla_host_t *ha)
2004f10a77bbSDavid C Somayajulu {
2005f10a77bbSDavid C Somayajulu device_t *peers;
2006f10a77bbSDavid C Somayajulu int count, i, slot;
2007f10a77bbSDavid C Somayajulu int my_slot = pci_get_slot(ha->pci_dev);
2008f10a77bbSDavid C Somayajulu
2009f10a77bbSDavid C Somayajulu if (device_get_children(device_get_parent(ha->pci_dev), &peers, &count))
2010f10a77bbSDavid C Somayajulu return;
2011f10a77bbSDavid C Somayajulu
2012f10a77bbSDavid C Somayajulu for (i = 0; i < count; i++) {
2013f10a77bbSDavid C Somayajulu slot = pci_get_slot(peers[i]);
2014f10a77bbSDavid C Somayajulu
2015f10a77bbSDavid C Somayajulu if ((slot >= 0) && (slot == my_slot) &&
2016f10a77bbSDavid C Somayajulu (pci_get_device(peers[i]) ==
2017f10a77bbSDavid C Somayajulu pci_get_device(ha->pci_dev))) {
2018f10a77bbSDavid C Somayajulu if (ha->pci_dev != peers[i])
2019f10a77bbSDavid C Somayajulu ha->peer_dev = peers[i];
2020f10a77bbSDavid C Somayajulu }
2021f10a77bbSDavid C Somayajulu }
2022f10a77bbSDavid C Somayajulu }
2023f10a77bbSDavid C Somayajulu
2024f10a77bbSDavid C Somayajulu static void
qla_send_msg_to_peer(qla_host_t * ha,uint32_t msg_to_peer)2025f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(qla_host_t *ha, uint32_t msg_to_peer)
2026f10a77bbSDavid C Somayajulu {
2027f10a77bbSDavid C Somayajulu qla_host_t *ha_peer;
2028f10a77bbSDavid C Somayajulu
2029f10a77bbSDavid C Somayajulu if (ha->peer_dev) {
2030f10a77bbSDavid C Somayajulu if ((ha_peer = device_get_softc(ha->peer_dev)) != NULL) {
2031f10a77bbSDavid C Somayajulu ha_peer->msg_from_peer = msg_to_peer;
2032f10a77bbSDavid C Somayajulu }
2033f10a77bbSDavid C Somayajulu }
2034f10a77bbSDavid C Somayajulu }
2035f10a77bbSDavid C Somayajulu
2036b65c0c07SDavid C Somayajulu void
qla_set_error_recovery(qla_host_t * ha)2037b65c0c07SDavid C Somayajulu qla_set_error_recovery(qla_host_t *ha)
2038b65c0c07SDavid C Somayajulu {
203954ab3b4aSJustin Hibbits if_t ifp = ha->ifp;
2040b65c0c07SDavid C Somayajulu
2041b65c0c07SDavid C Somayajulu if (!cold && ha->enable_error_recovery) {
2042b65c0c07SDavid C Somayajulu if (ifp)
204354ab3b4aSJustin Hibbits if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
2044b65c0c07SDavid C Somayajulu ha->qla_initiate_recovery = 1;
2045b65c0c07SDavid C Somayajulu } else
2046b65c0c07SDavid C Somayajulu ha->offline = 1;
2047b65c0c07SDavid C Somayajulu return;
2048b65c0c07SDavid C Somayajulu }
2049b65c0c07SDavid C Somayajulu
2050f10a77bbSDavid C Somayajulu static void
qla_error_recovery(void * context,int pending)2051f10a77bbSDavid C Somayajulu qla_error_recovery(void *context, int pending)
2052f10a77bbSDavid C Somayajulu {
2053f10a77bbSDavid C Somayajulu qla_host_t *ha = context;
2054b65c0c07SDavid C Somayajulu uint32_t msecs_100 = 400;
205554ab3b4aSJustin Hibbits if_t ifp = ha->ifp;
2056b89f2279SDavid C Somayajulu int i = 0;
2057f10a77bbSDavid C Somayajulu
2058b65c0c07SDavid C Somayajulu device_printf(ha->pci_dev, "%s: enter\n", __func__);
205935291c22SDavid C Somayajulu ha->hw.imd_compl = 1;
2060423ec132SDavid C Somayajulu
2061b65c0c07SDavid C Somayajulu taskqueue_drain_all(ha->stats_tq);
2062b65c0c07SDavid C Somayajulu taskqueue_drain_all(ha->async_event_tq);
2063b65c0c07SDavid C Somayajulu
20647fb51846SDavid C Somayajulu if (QLA_LOCK(ha, __func__, -1, 0) != 0)
20657fb51846SDavid C Somayajulu return;
206635291c22SDavid C Somayajulu
2067b65c0c07SDavid C Somayajulu device_printf(ha->pci_dev, "%s: ts_usecs = %ld start\n",
2068b65c0c07SDavid C Somayajulu __func__, qla_get_usec_timestamp());
20697fb51846SDavid C Somayajulu
20707fb51846SDavid C Somayajulu if (ha->qla_interface_up) {
20717fb51846SDavid C Somayajulu qla_mdelay(__func__, 300);
20727fb51846SDavid C Somayajulu
207354ab3b4aSJustin Hibbits
2074b89f2279SDavid C Somayajulu
2075b89f2279SDavid C Somayajulu for (i = 0; i < ha->hw.num_sds_rings; i++) {
2076b89f2279SDavid C Somayajulu qla_tx_fp_t *fp;
2077b89f2279SDavid C Somayajulu
2078b89f2279SDavid C Somayajulu fp = &ha->tx_fp[i];
2079b89f2279SDavid C Somayajulu
2080b89f2279SDavid C Somayajulu if (fp == NULL)
2081b89f2279SDavid C Somayajulu continue;
2082b89f2279SDavid C Somayajulu
2083b89f2279SDavid C Somayajulu if (fp->tx_br != NULL) {
2084b89f2279SDavid C Somayajulu mtx_lock(&fp->tx_mtx);
2085b89f2279SDavid C Somayajulu mtx_unlock(&fp->tx_mtx);
2086b89f2279SDavid C Somayajulu }
2087b89f2279SDavid C Somayajulu }
20886a62bec0SDavid C Somayajulu }
2089f10a77bbSDavid C Somayajulu
209077d57b28SDavid C Somayajulu qla_drain_fp_taskqueues(ha);
209177d57b28SDavid C Somayajulu
2092f10a77bbSDavid C Somayajulu if ((ha->pci_func & 0x1) == 0) {
2093bcafe874SDavid C Somayajulu if (!ha->msg_from_peer) {
2094f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET);
2095f10a77bbSDavid C Somayajulu
2096bcafe874SDavid C Somayajulu while ((ha->msg_from_peer != QL_PEER_MSG_ACK) &&
2097bcafe874SDavid C Somayajulu msecs_100--)
2098f10a77bbSDavid C Somayajulu qla_mdelay(__func__, 100);
2099bcafe874SDavid C Somayajulu }
2100f10a77bbSDavid C Somayajulu
2101f10a77bbSDavid C Somayajulu ha->msg_from_peer = 0;
2102f10a77bbSDavid C Somayajulu
21031faeac0fSDavid C Somayajulu if (ha->enable_minidump)
210467ffef6bSDavid C Somayajulu ql_minidump(ha);
21059a5f7854SDavid C Somayajulu
2106b65c0c07SDavid C Somayajulu if (ha->enable_driverstate_dump)
2107b65c0c07SDavid C Somayajulu ql_capture_drvr_state(ha);
2108b65c0c07SDavid C Somayajulu
2109b65c0c07SDavid C Somayajulu if (ql_init_hw(ha)) {
2110b65c0c07SDavid C Somayajulu device_printf(ha->pci_dev,
2111b65c0c07SDavid C Somayajulu "%s: ts_usecs = %ld exit: ql_init_hw failed\n",
2112b65c0c07SDavid C Somayajulu __func__, qla_get_usec_timestamp());
2113b65c0c07SDavid C Somayajulu ha->offline = 1;
2114b65c0c07SDavid C Somayajulu goto qla_error_recovery_exit;
2115b65c0c07SDavid C Somayajulu }
21166a62bec0SDavid C Somayajulu
21177fb51846SDavid C Somayajulu if (ha->qla_interface_up) {
2118f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(ha);
2119f10a77bbSDavid C Somayajulu qla_free_rcv_bufs(ha);
21206a62bec0SDavid C Somayajulu }
21219a5f7854SDavid C Somayajulu
2122b65c0c07SDavid C Somayajulu if (!QL_ERR_INJECT(ha, INJCT_PEER_PORT_FAILURE_ERR_RECOVERY))
2123f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK);
2124f10a77bbSDavid C Somayajulu
2125f10a77bbSDavid C Somayajulu } else {
2126f10a77bbSDavid C Somayajulu if (ha->msg_from_peer == QL_PEER_MSG_RESET) {
2127f10a77bbSDavid C Somayajulu ha->msg_from_peer = 0;
2128f10a77bbSDavid C Somayajulu
2129b65c0c07SDavid C Somayajulu if (!QL_ERR_INJECT(ha, INJCT_PEER_PORT_FAILURE_ERR_RECOVERY))
2130f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(ha, QL_PEER_MSG_ACK);
2131f10a77bbSDavid C Somayajulu } else {
2132f10a77bbSDavid C Somayajulu qla_send_msg_to_peer(ha, QL_PEER_MSG_RESET);
2133f10a77bbSDavid C Somayajulu }
2134f10a77bbSDavid C Somayajulu
2135f10a77bbSDavid C Somayajulu while ((ha->msg_from_peer != QL_PEER_MSG_ACK) && msecs_100--)
2136f10a77bbSDavid C Somayajulu qla_mdelay(__func__, 100);
2137f10a77bbSDavid C Somayajulu ha->msg_from_peer = 0;
2138f10a77bbSDavid C Somayajulu
2139b65c0c07SDavid C Somayajulu if (ha->enable_driverstate_dump)
2140b65c0c07SDavid C Somayajulu ql_capture_drvr_state(ha);
21416a62bec0SDavid C Somayajulu
2142b65c0c07SDavid C Somayajulu if (msecs_100 == 0) {
2143b65c0c07SDavid C Somayajulu device_printf(ha->pci_dev,
2144b65c0c07SDavid C Somayajulu "%s: ts_usecs = %ld exit: QL_PEER_MSG_ACK not received\n",
2145b65c0c07SDavid C Somayajulu __func__, qla_get_usec_timestamp());
2146b65c0c07SDavid C Somayajulu ha->offline = 1;
2147b65c0c07SDavid C Somayajulu goto qla_error_recovery_exit;
2148b65c0c07SDavid C Somayajulu }
2149b65c0c07SDavid C Somayajulu
2150b65c0c07SDavid C Somayajulu if (ql_init_hw(ha)) {
2151b65c0c07SDavid C Somayajulu device_printf(ha->pci_dev,
2152b65c0c07SDavid C Somayajulu "%s: ts_usecs = %ld exit: ql_init_hw failed\n",
2153b65c0c07SDavid C Somayajulu __func__, qla_get_usec_timestamp());
2154b65c0c07SDavid C Somayajulu ha->offline = 1;
2155b65c0c07SDavid C Somayajulu goto qla_error_recovery_exit;
2156b65c0c07SDavid C Somayajulu }
21579a5f7854SDavid C Somayajulu
21587fb51846SDavid C Somayajulu if (ha->qla_interface_up) {
2159f10a77bbSDavid C Somayajulu qla_free_xmt_bufs(ha);
2160f10a77bbSDavid C Somayajulu qla_free_rcv_bufs(ha);
2161f10a77bbSDavid C Somayajulu }
21626a62bec0SDavid C Somayajulu }
21636a62bec0SDavid C Somayajulu
2164b65c0c07SDavid C Somayajulu qla_mdelay(__func__, ha->ms_delay_after_init);
2165b65c0c07SDavid C Somayajulu
2166b65c0c07SDavid C Somayajulu *((uint32_t *)&ha->hw.flags) = 0;
2167b65c0c07SDavid C Somayajulu ha->qla_initiate_recovery = 0;
2168b65c0c07SDavid C Somayajulu
21697fb51846SDavid C Somayajulu if (ha->qla_interface_up) {
2170f10a77bbSDavid C Somayajulu if (qla_alloc_xmt_bufs(ha) != 0) {
2171b65c0c07SDavid C Somayajulu ha->offline = 1;
21727fb51846SDavid C Somayajulu goto qla_error_recovery_exit;
2173f10a77bbSDavid C Somayajulu }
2174b65c0c07SDavid C Somayajulu
217535291c22SDavid C Somayajulu qla_confirm_9kb_enable(ha);
2176f10a77bbSDavid C Somayajulu
2177f10a77bbSDavid C Somayajulu if (qla_alloc_rcv_bufs(ha) != 0) {
2178b65c0c07SDavid C Somayajulu ha->offline = 1;
21797fb51846SDavid C Somayajulu goto qla_error_recovery_exit;
2180f10a77bbSDavid C Somayajulu }
2181f10a77bbSDavid C Somayajulu
21827fb51846SDavid C Somayajulu ha->stop_rcv = 0;
21839a5f7854SDavid C Somayajulu
2184f10a77bbSDavid C Somayajulu if (ql_init_hw_if(ha) == 0) {
2185f10a77bbSDavid C Somayajulu ifp = ha->ifp;
218654ab3b4aSJustin Hibbits if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
21877fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 0;
2188b65c0c07SDavid C Somayajulu ql_update_link_state(ha);
2189b65c0c07SDavid C Somayajulu } else {
2190b65c0c07SDavid C Somayajulu ha->offline = 1;
2191b65c0c07SDavid C Somayajulu
2192b65c0c07SDavid C Somayajulu if (ha->hw.sp_log_stop_events &
2193b65c0c07SDavid C Somayajulu Q8_SP_LOG_STOP_IF_START_FAILURE)
2194b65c0c07SDavid C Somayajulu ha->hw.sp_log_stop = -1;
2195f10a77bbSDavid C Somayajulu }
2196b65c0c07SDavid C Somayajulu } else {
21977fb51846SDavid C Somayajulu ha->qla_watchdog_pause = 0;
2198b65c0c07SDavid C Somayajulu }
2199f10a77bbSDavid C Somayajulu
22007fb51846SDavid C Somayajulu qla_error_recovery_exit:
22017fb51846SDavid C Somayajulu
2202b65c0c07SDavid C Somayajulu if (ha->offline ) {
2203b65c0c07SDavid C Somayajulu device_printf(ha->pci_dev, "%s: ts_usecs = %ld port offline\n",
2204b65c0c07SDavid C Somayajulu __func__, qla_get_usec_timestamp());
2205b65c0c07SDavid C Somayajulu if (ha->hw.sp_log_stop_events &
2206b65c0c07SDavid C Somayajulu Q8_SP_LOG_STOP_ERR_RECOVERY_FAILURE)
2207b65c0c07SDavid C Somayajulu ha->hw.sp_log_stop = -1;
2208b65c0c07SDavid C Somayajulu }
2209b65c0c07SDavid C Somayajulu
22107fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__);
22117fb51846SDavid C Somayajulu
2212b65c0c07SDavid C Somayajulu if (!ha->offline)
22137fb51846SDavid C Somayajulu callout_reset(&ha->tx_callout, QLA_WATCHDOG_CALLOUT_TICKS,
22147fb51846SDavid C Somayajulu qla_watchdog, ha);
2215b65c0c07SDavid C Somayajulu
2216b65c0c07SDavid C Somayajulu device_printf(ha->pci_dev,
2217b65c0c07SDavid C Somayajulu "%s: ts_usecs = %ld exit\n",
2218b65c0c07SDavid C Somayajulu __func__, qla_get_usec_timestamp());
22197fb51846SDavid C Somayajulu return;
2220f10a77bbSDavid C Somayajulu }
2221f10a77bbSDavid C Somayajulu
222235291c22SDavid C Somayajulu static void
qla_async_event(void * context,int pending)222335291c22SDavid C Somayajulu qla_async_event(void *context, int pending)
222435291c22SDavid C Somayajulu {
222535291c22SDavid C Somayajulu qla_host_t *ha = context;
222635291c22SDavid C Somayajulu
22277fb51846SDavid C Somayajulu if (QLA_LOCK(ha, __func__, -1, 0) != 0)
22287fb51846SDavid C Somayajulu return;
22297fb51846SDavid C Somayajulu
22307fb51846SDavid C Somayajulu if (ha->async_event) {
22317fb51846SDavid C Somayajulu ha->async_event = 0;
223235291c22SDavid C Somayajulu qla_hw_async_event(ha);
22337fb51846SDavid C Somayajulu }
22347fb51846SDavid C Somayajulu
22357fb51846SDavid C Somayajulu QLA_UNLOCK(ha, __func__);
22367fb51846SDavid C Somayajulu
22377fb51846SDavid C Somayajulu return;
22387fb51846SDavid C Somayajulu }
22397fb51846SDavid C Somayajulu
22407fb51846SDavid C Somayajulu static void
qla_stats(void * context,int pending)22417fb51846SDavid C Somayajulu qla_stats(void *context, int pending)
22427fb51846SDavid C Somayajulu {
22437fb51846SDavid C Somayajulu qla_host_t *ha;
22447fb51846SDavid C Somayajulu
22457fb51846SDavid C Somayajulu ha = context;
22467fb51846SDavid C Somayajulu
22477fb51846SDavid C Somayajulu ql_get_stats(ha);
2248b65c0c07SDavid C Somayajulu
22497fb51846SDavid C Somayajulu return;
225035291c22SDavid C Somayajulu }
2251