2 * Copyright (c) 2013-2016 Qlogic Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
30 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
31 * Content: Contains Hardware dependant functions
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
40 #include "ql_inline.h"
49 static void qla_del_rcv_cntxt(qla_host_t *ha);
50 static int qla_init_rcv_cntxt(qla_host_t *ha);
51 static void qla_del_xmt_cntxt(qla_host_t *ha);
52 static int qla_init_xmt_cntxt(qla_host_t *ha);
53 static void qla_hw_tx_done_locked(qla_host_t *ha, uint32_t txr_idx);
54 static int qla_mbx_cmd(qla_host_t *ha, uint32_t *h_mbox, uint32_t n_hmbox,
55 uint32_t *fw_mbox, uint32_t n_fwmbox, uint32_t no_pause);
56 static int qla_config_intr_cntxt(qla_host_t *ha, uint32_t start_idx,
57 uint32_t num_intrs, uint32_t create);
58 static int qla_config_rss(qla_host_t *ha, uint16_t cntxt_id);
59 static int qla_config_intr_coalesce(qla_host_t *ha, uint16_t cntxt_id,
60 int tenable, int rcv);
61 static int qla_set_mac_rcv_mode(qla_host_t *ha, uint32_t mode);
62 static int qla_link_event_req(qla_host_t *ha, uint16_t cntxt_id);
64 static int qla_tx_tso(qla_host_t *ha, struct mbuf *mp, q80_tx_cmd_t *tx_cmd,
66 static int qla_hw_add_all_mcast(qla_host_t *ha);
67 static int qla_hw_del_all_mcast(qla_host_t *ha);
68 static int qla_add_rcv_rings(qla_host_t *ha, uint32_t sds_idx, uint32_t nsds);
70 static int qla_init_nic_func(qla_host_t *ha);
71 static int qla_stop_nic_func(qla_host_t *ha);
72 static int qla_query_fw_dcbx_caps(qla_host_t *ha);
73 static int qla_set_port_config(qla_host_t *ha, uint32_t cfg_bits);
74 static int qla_get_port_config(qla_host_t *ha, uint32_t *cfg_bits);
75 static void qla_get_quick_stats(qla_host_t *ha);
77 static int qla_minidump_init(qla_host_t *ha);
78 static void qla_minidump_free(qla_host_t *ha);
82 qla_sysctl_get_drvr_stats(SYSCTL_HANDLER_ARGS)
88 err = sysctl_handle_int(oidp, &ret, 0, req);
90 if (err || !req->newptr)
95 ha = (qla_host_t *)arg1;
97 for (i = 0; i < ha->hw.num_sds_rings; i++)
98 device_printf(ha->pci_dev,
99 "%s: sds_ring[%d] = %p\n", __func__,i,
100 (void *)ha->hw.sds[i].intr_count);
102 for (i = 0; i < ha->hw.num_tx_rings; i++)
103 device_printf(ha->pci_dev,
104 "%s: tx[%d] = %p\n", __func__,i,
105 (void *)ha->tx_ring[i].count);
107 for (i = 0; i < ha->hw.num_rds_rings; i++)
108 device_printf(ha->pci_dev,
109 "%s: rds_ring[%d] = %p\n", __func__,i,
110 (void *)ha->hw.rds[i].count);
112 device_printf(ha->pci_dev, "%s: lro_pkt_count = %p\n", __func__,
113 (void *)ha->lro_pkt_count);
115 device_printf(ha->pci_dev, "%s: lro_bytes = %p\n", __func__,
116 (void *)ha->lro_bytes);
118 #ifdef QL_ENABLE_ISCSI_TLV
119 device_printf(ha->pci_dev, "%s: iscsi_pkts = %p\n", __func__,
120 (void *)ha->hw.iscsi_pkt_count);
121 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
128 qla_sysctl_get_quick_stats(SYSCTL_HANDLER_ARGS)
133 err = sysctl_handle_int(oidp, &ret, 0, req);
135 if (err || !req->newptr)
139 ha = (qla_host_t *)arg1;
140 qla_get_quick_stats(ha);
148 qla_stop_pegs(qla_host_t *ha)
152 ql_rdwr_indreg32(ha, Q8_CRB_PEG_0, &val, 0);
153 ql_rdwr_indreg32(ha, Q8_CRB_PEG_1, &val, 0);
154 ql_rdwr_indreg32(ha, Q8_CRB_PEG_2, &val, 0);
155 ql_rdwr_indreg32(ha, Q8_CRB_PEG_3, &val, 0);
156 ql_rdwr_indreg32(ha, Q8_CRB_PEG_4, &val, 0);
157 device_printf(ha->pci_dev, "%s PEGS HALTED!!!!!\n", __func__);
161 qla_sysctl_stop_pegs(SYSCTL_HANDLER_ARGS)
166 err = sysctl_handle_int(oidp, &ret, 0, req);
169 if (err || !req->newptr)
173 ha = (qla_host_t *)arg1;
174 (void)QLA_LOCK(ha, __func__, 0);
176 QLA_UNLOCK(ha, __func__);
181 #endif /* #ifdef QL_DBG */
184 qla_validate_set_port_cfg_bit(uint32_t bits)
186 if ((bits & 0xF) > 1)
189 if (((bits >> 4) & 0xF) > 2)
192 if (((bits >> 8) & 0xF) > 2)
199 qla_sysctl_port_cfg(SYSCTL_HANDLER_ARGS)
205 err = sysctl_handle_int(oidp, &ret, 0, req);
207 if (err || !req->newptr)
210 if ((qla_validate_set_port_cfg_bit((uint32_t)ret) == 0)) {
212 ha = (qla_host_t *)arg1;
214 err = qla_get_port_config(ha, &cfg_bits);
217 goto qla_sysctl_set_port_cfg_exit;
220 cfg_bits |= Q8_PORT_CFG_BITS_DCBX_ENABLE;
222 cfg_bits &= ~Q8_PORT_CFG_BITS_DCBX_ENABLE;
226 cfg_bits &= ~Q8_PORT_CFG_BITS_PAUSE_CFG_MASK;
228 if ((ret & 0xF) == 0) {
229 cfg_bits |= Q8_PORT_CFG_BITS_PAUSE_DISABLED;
230 } else if ((ret & 0xF) == 1){
231 cfg_bits |= Q8_PORT_CFG_BITS_PAUSE_STD;
233 cfg_bits |= Q8_PORT_CFG_BITS_PAUSE_PPM;
237 cfg_bits &= ~Q8_PORT_CFG_BITS_STDPAUSE_DIR_MASK;
240 cfg_bits |= Q8_PORT_CFG_BITS_STDPAUSE_XMT_RCV;
241 } else if (ret == 1){
242 cfg_bits |= Q8_PORT_CFG_BITS_STDPAUSE_XMT;
244 cfg_bits |= Q8_PORT_CFG_BITS_STDPAUSE_RCV;
247 err = qla_set_port_config(ha, cfg_bits);
249 ha = (qla_host_t *)arg1;
251 err = qla_get_port_config(ha, &cfg_bits);
254 qla_sysctl_set_port_cfg_exit:
259 * Name: ql_hw_add_sysctls
260 * Function: Add P3Plus specific sysctls
263 ql_hw_add_sysctls(qla_host_t *ha)
269 ha->hw.num_sds_rings = MAX_SDS_RINGS;
270 ha->hw.num_rds_rings = MAX_RDS_RINGS;
271 ha->hw.num_tx_rings = NUM_TX_RINGS;
273 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
274 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
275 OID_AUTO, "num_rds_rings", CTLFLAG_RD, &ha->hw.num_rds_rings,
276 ha->hw.num_rds_rings, "Number of Rcv Descriptor Rings");
278 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
279 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
280 OID_AUTO, "num_sds_rings", CTLFLAG_RD, &ha->hw.num_sds_rings,
281 ha->hw.num_sds_rings, "Number of Status Descriptor Rings");
283 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
284 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
285 OID_AUTO, "num_tx_rings", CTLFLAG_RD, &ha->hw.num_tx_rings,
286 ha->hw.num_tx_rings, "Number of Transmit Rings");
288 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
289 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
290 OID_AUTO, "tx_ring_index", CTLFLAG_RW, &ha->txr_idx,
291 ha->txr_idx, "Tx Ring Used");
293 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
294 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
295 OID_AUTO, "drvr_stats", CTLTYPE_INT | CTLFLAG_RW,
297 qla_sysctl_get_drvr_stats, "I", "Driver Maintained Statistics");
299 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
300 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
301 OID_AUTO, "quick_stats", CTLTYPE_INT | CTLFLAG_RW,
303 qla_sysctl_get_quick_stats, "I", "Quick Statistics");
305 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
306 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
307 OID_AUTO, "max_tx_segs", CTLFLAG_RD, &ha->hw.max_tx_segs,
308 ha->hw.max_tx_segs, "Max # of Segments in a non-TSO pkt");
310 ha->hw.sds_cidx_thres = 32;
311 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
312 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
313 OID_AUTO, "sds_cidx_thres", CTLFLAG_RW, &ha->hw.sds_cidx_thres,
314 ha->hw.sds_cidx_thres,
315 "Number of SDS entries to process before updating"
316 " SDS Ring Consumer Index");
318 ha->hw.rds_pidx_thres = 32;
319 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
320 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
321 OID_AUTO, "rds_pidx_thres", CTLFLAG_RW, &ha->hw.rds_pidx_thres,
322 ha->hw.rds_pidx_thres,
323 "Number of Rcv Rings Entries to post before updating"
324 " RDS Ring Producer Index");
326 ha->hw.rcv_intr_coalesce = (3 << 16) | 256;
327 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
328 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
329 OID_AUTO, "rcv_intr_coalesce", CTLFLAG_RW,
330 &ha->hw.rcv_intr_coalesce,
331 ha->hw.rcv_intr_coalesce,
332 "Rcv Intr Coalescing Parameters\n"
333 "\tbits 15:0 max packets\n"
334 "\tbits 31:16 max micro-seconds to wait\n"
336 "\tifconfig <if> down && ifconfig <if> up\n"
337 "\tto take effect \n");
339 ha->hw.xmt_intr_coalesce = (64 << 16) | 64;
340 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
341 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
342 OID_AUTO, "xmt_intr_coalesce", CTLFLAG_RW,
343 &ha->hw.xmt_intr_coalesce,
344 ha->hw.xmt_intr_coalesce,
345 "Xmt Intr Coalescing Parameters\n"
346 "\tbits 15:0 max packets\n"
347 "\tbits 31:16 max micro-seconds to wait\n"
349 "\tifconfig <if> down && ifconfig <if> up\n"
350 "\tto take effect \n");
352 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
353 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
354 OID_AUTO, "port_cfg", CTLTYPE_INT | CTLFLAG_RW,
356 qla_sysctl_port_cfg, "I",
357 "Set Port Configuration if values below "
358 "otherwise Get Port Configuration\n"
359 "\tBits 0-3 ; 1 = DCBX Enable; 0 = DCBX Disable\n"
360 "\tBits 4-7 : 0 = no pause; 1 = std ; 2 = ppm \n"
361 "\tBits 8-11: std pause cfg; 0 = xmt and rcv;"
362 " 1 = xmt only; 2 = rcv only;\n"
365 ha->hw.enable_9kb = 1;
367 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
368 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
369 OID_AUTO, "enable_9kb", CTLFLAG_RW, &ha->hw.enable_9kb,
370 ha->hw.enable_9kb, "Enable 9Kbyte Buffers when MTU = 9000");
372 ha->hw.mdump_active = 0;
373 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
374 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
375 OID_AUTO, "minidump_active", CTLFLAG_RW, &ha->hw.mdump_active,
377 "Minidump Utility is Active \n"
378 "\t 0 = Minidump Utility is not active\n"
379 "\t 1 = Minidump Utility is retrieved on this port\n"
380 "\t 2 = Minidump Utility is retrieved on the other port\n");
382 ha->hw.mdump_start = 0;
383 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
384 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
385 OID_AUTO, "minidump_start", CTLFLAG_RW,
386 &ha->hw.mdump_start, ha->hw.mdump_start,
387 "Minidump Utility can start minidump process");
391 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
392 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
393 OID_AUTO, "err_inject",
394 CTLFLAG_RW, &ha->err_inject, ha->err_inject,
395 "Error to be injected\n"
396 "\t\t\t 0: No Errors\n"
397 "\t\t\t 1: rcv: rxb struct invalid\n"
398 "\t\t\t 2: rcv: mp == NULL\n"
399 "\t\t\t 3: lro: rxb struct invalid\n"
400 "\t\t\t 4: lro: mp == NULL\n"
401 "\t\t\t 5: rcv: num handles invalid\n"
402 "\t\t\t 6: reg: indirect reg rd_wr failure\n"
403 "\t\t\t 7: ocm: offchip memory rd_wr failure\n"
404 "\t\t\t 8: mbx: mailbox command failure\n"
405 "\t\t\t 9: heartbeat failure\n"
406 "\t\t\t A: temperature failure\n" );
408 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
409 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
410 OID_AUTO, "peg_stop", CTLTYPE_INT | CTLFLAG_RW,
412 qla_sysctl_stop_pegs, "I", "Peg Stop");
414 #endif /* #ifdef QL_DBG */
416 ha->hw.user_pri_nic = 0;
417 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
418 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
419 OID_AUTO, "user_pri_nic", CTLFLAG_RW, &ha->hw.user_pri_nic,
421 "VLAN Tag User Priority for Normal Ethernet Packets");
423 ha->hw.user_pri_iscsi = 4;
424 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
425 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
426 OID_AUTO, "user_pri_iscsi", CTLFLAG_RW, &ha->hw.user_pri_iscsi,
427 ha->hw.user_pri_iscsi,
428 "VLAN Tag User Priority for iSCSI Packets");
433 ql_hw_link_status(qla_host_t *ha)
435 device_printf(ha->pci_dev, "cable_oui\t\t 0x%08x\n", ha->hw.cable_oui);
437 if (ha->hw.link_up) {
438 device_printf(ha->pci_dev, "link Up\n");
440 device_printf(ha->pci_dev, "link Down\n");
443 if (ha->hw.flags.fduplex) {
444 device_printf(ha->pci_dev, "Full Duplex\n");
446 device_printf(ha->pci_dev, "Half Duplex\n");
449 if (ha->hw.flags.autoneg) {
450 device_printf(ha->pci_dev, "Auto Negotiation Enabled\n");
452 device_printf(ha->pci_dev, "Auto Negotiation Disabled\n");
455 switch (ha->hw.link_speed) {
457 device_printf(ha->pci_dev, "link speed\t\t 10Gps\n");
461 device_printf(ha->pci_dev, "link speed\t\t 1Gps\n");
465 device_printf(ha->pci_dev, "link speed\t\t 100Mbps\n");
469 device_printf(ha->pci_dev, "link speed\t\t Unknown\n");
473 switch (ha->hw.module_type) {
476 device_printf(ha->pci_dev, "Module Type 10GBase-LRM\n");
480 device_printf(ha->pci_dev, "Module Type 10GBase-LR\n");
484 device_printf(ha->pci_dev, "Module Type 10GBase-SR\n");
488 device_printf(ha->pci_dev,
489 "Module Type 10GE Passive Copper(Compliant)[%d m]\n",
490 ha->hw.cable_length);
494 device_printf(ha->pci_dev, "Module Type 10GE Active"
495 " Limiting Copper(Compliant)[%d m]\n",
496 ha->hw.cable_length);
500 device_printf(ha->pci_dev,
501 "Module Type 10GE Passive Copper"
502 " (Legacy, Best Effort)[%d m]\n",
503 ha->hw.cable_length);
507 device_printf(ha->pci_dev, "Module Type 1000Base-SX\n");
511 device_printf(ha->pci_dev, "Module Type 1000Base-LX\n");
515 device_printf(ha->pci_dev, "Module Type 1000Base-CX\n");
519 device_printf(ha->pci_dev, "Module Type 1000Base-T\n");
523 device_printf(ha->pci_dev, "Module Type 1GE Passive Copper"
524 "(Legacy, Best Effort)\n");
528 device_printf(ha->pci_dev, "Unknown Module Type 0x%x\n",
533 if (ha->hw.link_faults == 1)
534 device_printf(ha->pci_dev, "SFP Power Fault\n");
539 * Function: Frees the DMA'able memory allocated in ql_alloc_dma()
542 ql_free_dma(qla_host_t *ha)
546 if (ha->hw.dma_buf.flags.sds_ring) {
547 for (i = 0; i < ha->hw.num_sds_rings; i++) {
548 ql_free_dmabuf(ha, &ha->hw.dma_buf.sds_ring[i]);
550 ha->hw.dma_buf.flags.sds_ring = 0;
553 if (ha->hw.dma_buf.flags.rds_ring) {
554 for (i = 0; i < ha->hw.num_rds_rings; i++) {
555 ql_free_dmabuf(ha, &ha->hw.dma_buf.rds_ring[i]);
557 ha->hw.dma_buf.flags.rds_ring = 0;
560 if (ha->hw.dma_buf.flags.tx_ring) {
561 ql_free_dmabuf(ha, &ha->hw.dma_buf.tx_ring);
562 ha->hw.dma_buf.flags.tx_ring = 0;
564 qla_minidump_free(ha);
569 * Function: Allocates DMA'able memory for Tx/Rx Rings, Tx/Rx Contexts.
572 ql_alloc_dma(qla_host_t *ha)
575 uint32_t i, j, size, tx_ring_size;
577 qla_hw_tx_cntxt_t *tx_cntxt;
583 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
587 * Allocate Transmit Ring
589 tx_ring_size = (sizeof(q80_tx_cmd_t) * NUM_TX_DESCRIPTORS);
590 size = (tx_ring_size * ha->hw.num_tx_rings);
592 hw->dma_buf.tx_ring.alignment = 8;
593 hw->dma_buf.tx_ring.size = size + PAGE_SIZE;
595 if (ql_alloc_dmabuf(ha, &hw->dma_buf.tx_ring)) {
596 device_printf(dev, "%s: tx ring alloc failed\n", __func__);
597 goto ql_alloc_dma_exit;
600 vaddr = (uint8_t *)hw->dma_buf.tx_ring.dma_b;
601 paddr = hw->dma_buf.tx_ring.dma_addr;
603 for (i = 0; i < ha->hw.num_tx_rings; i++) {
604 tx_cntxt = (qla_hw_tx_cntxt_t *)&hw->tx_cntxt[i];
606 tx_cntxt->tx_ring_base = (q80_tx_cmd_t *)vaddr;
607 tx_cntxt->tx_ring_paddr = paddr;
609 vaddr += tx_ring_size;
610 paddr += tx_ring_size;
613 for (i = 0; i < ha->hw.num_tx_rings; i++) {
614 tx_cntxt = (qla_hw_tx_cntxt_t *)&hw->tx_cntxt[i];
616 tx_cntxt->tx_cons = (uint32_t *)vaddr;
617 tx_cntxt->tx_cons_paddr = paddr;
619 vaddr += sizeof (uint32_t);
620 paddr += sizeof (uint32_t);
623 ha->hw.dma_buf.flags.tx_ring = 1;
625 QL_DPRINT2(ha, (dev, "%s: tx_ring phys %p virt %p\n",
626 __func__, (void *)(hw->dma_buf.tx_ring.dma_addr),
627 hw->dma_buf.tx_ring.dma_b));
629 * Allocate Receive Descriptor Rings
632 for (i = 0; i < hw->num_rds_rings; i++) {
634 hw->dma_buf.rds_ring[i].alignment = 8;
635 hw->dma_buf.rds_ring[i].size =
636 (sizeof(q80_recv_desc_t)) * NUM_RX_DESCRIPTORS;
638 if (ql_alloc_dmabuf(ha, &hw->dma_buf.rds_ring[i])) {
639 device_printf(dev, "%s: rds ring[%d] alloc failed\n",
642 for (j = 0; j < i; j++)
643 ql_free_dmabuf(ha, &hw->dma_buf.rds_ring[j]);
645 goto ql_alloc_dma_exit;
647 QL_DPRINT4(ha, (dev, "%s: rx_ring[%d] phys %p virt %p\n",
648 __func__, i, (void *)(hw->dma_buf.rds_ring[i].dma_addr),
649 hw->dma_buf.rds_ring[i].dma_b));
652 hw->dma_buf.flags.rds_ring = 1;
655 * Allocate Status Descriptor Rings
658 for (i = 0; i < hw->num_sds_rings; i++) {
659 hw->dma_buf.sds_ring[i].alignment = 8;
660 hw->dma_buf.sds_ring[i].size =
661 (sizeof(q80_stat_desc_t)) * NUM_STATUS_DESCRIPTORS;
663 if (ql_alloc_dmabuf(ha, &hw->dma_buf.sds_ring[i])) {
664 device_printf(dev, "%s: sds ring alloc failed\n",
667 for (j = 0; j < i; j++)
668 ql_free_dmabuf(ha, &hw->dma_buf.sds_ring[j]);
670 goto ql_alloc_dma_exit;
672 QL_DPRINT4(ha, (dev, "%s: sds_ring[%d] phys %p virt %p\n",
674 (void *)(hw->dma_buf.sds_ring[i].dma_addr),
675 hw->dma_buf.sds_ring[i].dma_b));
677 for (i = 0; i < hw->num_sds_rings; i++) {
678 hw->sds[i].sds_ring_base =
679 (q80_stat_desc_t *)hw->dma_buf.sds_ring[i].dma_b;
682 hw->dma_buf.flags.sds_ring = 1;
691 #define Q8_MBX_MSEC_DELAY 5000
694 qla_mbx_cmd(qla_host_t *ha, uint32_t *h_mbox, uint32_t n_hmbox,
695 uint32_t *fw_mbox, uint32_t n_fwmbox, uint32_t no_pause)
701 if (QL_ERR_INJECT(ha, INJCT_MBX_CMD_FAILURE)) {
703 ha->qla_initiate_recovery = 1;
704 goto exit_qla_mbx_cmd;
710 i = Q8_MBX_MSEC_DELAY;
713 data = READ_REG32(ha, Q8_HOST_MBOX_CNTRL);
719 qla_mdelay(__func__, 1);
725 device_printf(ha->pci_dev, "%s: host_mbx_cntrl 0x%08x\n",
728 ha->qla_initiate_recovery = 1;
729 goto exit_qla_mbx_cmd;
732 for (i = 0; i < n_hmbox; i++) {
733 WRITE_REG32(ha, (Q8_HOST_MBOX0 + (i << 2)), *h_mbox);
737 WRITE_REG32(ha, Q8_HOST_MBOX_CNTRL, 0x1);
740 i = Q8_MBX_MSEC_DELAY;
742 data = READ_REG32(ha, Q8_FW_MBOX_CNTRL);
744 if ((data & 0x3) == 1) {
745 data = READ_REG32(ha, Q8_FW_MBOX0);
746 if ((data & 0xF000) != 0x8000)
752 qla_mdelay(__func__, 1);
757 device_printf(ha->pci_dev, "%s: fw_mbx_cntrl 0x%08x\n",
760 ha->qla_initiate_recovery = 1;
761 goto exit_qla_mbx_cmd;
764 for (i = 0; i < n_fwmbox; i++) {
765 *fw_mbox++ = READ_REG32(ha, (Q8_FW_MBOX0 + (i << 2)));
768 WRITE_REG32(ha, Q8_FW_MBOX_CNTRL, 0x0);
769 WRITE_REG32(ha, ha->hw.mbx_intr_mask_offset, 0x0);
776 qla_get_nic_partition(qla_host_t *ha, uint32_t *supports_9kb,
780 device_t dev = ha->pci_dev;
782 bzero(ha->hw.mbox, (sizeof (uint32_t) * Q8_NUM_MBOX));
786 mbox[0] = Q8_MBX_GET_NIC_PARTITION | (0x2 << 16) | (0x2 << 29);
788 if (qla_mbx_cmd(ha, mbox, 2, mbox, 19, 0)) {
789 device_printf(dev, "%s: failed0\n", __func__);
794 if (supports_9kb != NULL) {
795 if (mbox[16] & 0x80) /* bit 7 of mbox 16 */
801 if (num_rcvq != NULL)
802 *num_rcvq = ((mbox[6] >> 16) & 0xFFFF);
804 if ((err != 1) && (err != 0)) {
805 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
812 qla_config_intr_cntxt(qla_host_t *ha, uint32_t start_idx, uint32_t num_intrs,
816 device_t dev = ha->pci_dev;
817 q80_config_intr_t *c_intr;
818 q80_config_intr_rsp_t *c_intr_rsp;
820 c_intr = (q80_config_intr_t *)ha->hw.mbox;
821 bzero(c_intr, (sizeof (q80_config_intr_t)));
823 c_intr->opcode = Q8_MBX_CONFIG_INTR;
825 c_intr->count_version = (sizeof (q80_config_intr_t) >> 2);
826 c_intr->count_version |= Q8_MBX_CMD_VERSION;
828 c_intr->nentries = num_intrs;
830 for (i = 0; i < num_intrs; i++) {
832 c_intr->intr[i].cmd_type = Q8_MBX_CONFIG_INTR_CREATE;
833 c_intr->intr[i].msix_index = start_idx + 1 + i;
835 c_intr->intr[i].cmd_type = Q8_MBX_CONFIG_INTR_DELETE;
836 c_intr->intr[i].msix_index =
837 ha->hw.intr_id[(start_idx + i)];
840 c_intr->intr[i].cmd_type |= Q8_MBX_CONFIG_INTR_TYPE_MSI_X;
843 if (qla_mbx_cmd(ha, (uint32_t *)c_intr,
844 (sizeof (q80_config_intr_t) >> 2),
845 ha->hw.mbox, (sizeof (q80_config_intr_rsp_t) >> 2), 0)) {
846 device_printf(dev, "%s: failed0\n", __func__);
850 c_intr_rsp = (q80_config_intr_rsp_t *)ha->hw.mbox;
852 err = Q8_MBX_RSP_STATUS(c_intr_rsp->regcnt_status);
855 device_printf(dev, "%s: failed1 [0x%08x, %d]\n", __func__, err,
856 c_intr_rsp->nentries);
858 for (i = 0; i < c_intr_rsp->nentries; i++) {
859 device_printf(dev, "%s: [%d]:[0x%x 0x%x 0x%x]\n",
861 c_intr_rsp->intr[i].status,
862 c_intr_rsp->intr[i].intr_id,
863 c_intr_rsp->intr[i].intr_src);
869 for (i = 0; ((i < num_intrs) && create); i++) {
870 if (!c_intr_rsp->intr[i].status) {
871 ha->hw.intr_id[(start_idx + i)] =
872 c_intr_rsp->intr[i].intr_id;
873 ha->hw.intr_src[(start_idx + i)] =
874 c_intr_rsp->intr[i].intr_src;
882 * Name: qla_config_rss
883 * Function: Configure RSS for the context/interface.
885 static const uint64_t rss_key[] = { 0xbeac01fa6a42b73bULL,
886 0x8030f20c77cb2da3ULL,
887 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
888 0x255b0ec26d5a56daULL };
891 qla_config_rss(qla_host_t *ha, uint16_t cntxt_id)
893 q80_config_rss_t *c_rss;
894 q80_config_rss_rsp_t *c_rss_rsp;
896 device_t dev = ha->pci_dev;
898 c_rss = (q80_config_rss_t *)ha->hw.mbox;
899 bzero(c_rss, (sizeof (q80_config_rss_t)));
901 c_rss->opcode = Q8_MBX_CONFIG_RSS;
903 c_rss->count_version = (sizeof (q80_config_rss_t) >> 2);
904 c_rss->count_version |= Q8_MBX_CMD_VERSION;
906 c_rss->hash_type = (Q8_MBX_RSS_HASH_TYPE_IPV4_TCP_IP |
907 Q8_MBX_RSS_HASH_TYPE_IPV6_TCP_IP);
908 //c_rss->hash_type = (Q8_MBX_RSS_HASH_TYPE_IPV4_TCP |
909 // Q8_MBX_RSS_HASH_TYPE_IPV6_TCP);
911 c_rss->flags = Q8_MBX_RSS_FLAGS_ENABLE_RSS;
912 c_rss->flags |= Q8_MBX_RSS_FLAGS_USE_IND_TABLE;
914 c_rss->indtbl_mask = Q8_MBX_RSS_INDTBL_MASK;
916 c_rss->indtbl_mask |= Q8_MBX_RSS_FLAGS_MULTI_RSS_VALID;
917 c_rss->flags |= Q8_MBX_RSS_FLAGS_TYPE_CRSS;
919 c_rss->cntxt_id = cntxt_id;
921 for (i = 0; i < 5; i++) {
922 c_rss->rss_key[i] = rss_key[i];
925 if (qla_mbx_cmd(ha, (uint32_t *)c_rss,
926 (sizeof (q80_config_rss_t) >> 2),
927 ha->hw.mbox, (sizeof(q80_config_rss_rsp_t) >> 2), 0)) {
928 device_printf(dev, "%s: failed0\n", __func__);
931 c_rss_rsp = (q80_config_rss_rsp_t *)ha->hw.mbox;
933 err = Q8_MBX_RSP_STATUS(c_rss_rsp->regcnt_status);
936 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
943 qla_set_rss_ind_table(qla_host_t *ha, uint32_t start_idx, uint32_t count,
944 uint16_t cntxt_id, uint8_t *ind_table)
946 q80_config_rss_ind_table_t *c_rss_ind;
947 q80_config_rss_ind_table_rsp_t *c_rss_ind_rsp;
949 device_t dev = ha->pci_dev;
951 if ((count > Q8_RSS_IND_TBL_SIZE) ||
952 ((start_idx + count - 1) > Q8_RSS_IND_TBL_MAX_IDX)) {
953 device_printf(dev, "%s: illegal count [%d, %d]\n", __func__,
958 c_rss_ind = (q80_config_rss_ind_table_t *)ha->hw.mbox;
959 bzero(c_rss_ind, sizeof (q80_config_rss_ind_table_t));
961 c_rss_ind->opcode = Q8_MBX_CONFIG_RSS_TABLE;
962 c_rss_ind->count_version = (sizeof (q80_config_rss_ind_table_t) >> 2);
963 c_rss_ind->count_version |= Q8_MBX_CMD_VERSION;
965 c_rss_ind->start_idx = start_idx;
966 c_rss_ind->end_idx = start_idx + count - 1;
967 c_rss_ind->cntxt_id = cntxt_id;
968 bcopy(ind_table, c_rss_ind->ind_table, count);
970 if (qla_mbx_cmd(ha, (uint32_t *)c_rss_ind,
971 (sizeof (q80_config_rss_ind_table_t) >> 2), ha->hw.mbox,
972 (sizeof(q80_config_rss_ind_table_rsp_t) >> 2), 0)) {
973 device_printf(dev, "%s: failed0\n", __func__);
977 c_rss_ind_rsp = (q80_config_rss_ind_table_rsp_t *)ha->hw.mbox;
978 err = Q8_MBX_RSP_STATUS(c_rss_ind_rsp->regcnt_status);
981 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
988 * Name: qla_config_intr_coalesce
989 * Function: Configure Interrupt Coalescing.
992 qla_config_intr_coalesce(qla_host_t *ha, uint16_t cntxt_id, int tenable,
995 q80_config_intr_coalesc_t *intrc;
996 q80_config_intr_coalesc_rsp_t *intrc_rsp;
998 device_t dev = ha->pci_dev;
1000 intrc = (q80_config_intr_coalesc_t *)ha->hw.mbox;
1001 bzero(intrc, (sizeof (q80_config_intr_coalesc_t)));
1003 intrc->opcode = Q8_MBX_CONFIG_INTR_COALESCE;
1004 intrc->count_version = (sizeof (q80_config_intr_coalesc_t) >> 2);
1005 intrc->count_version |= Q8_MBX_CMD_VERSION;
1008 intrc->flags = Q8_MBX_INTRC_FLAGS_RCV;
1009 intrc->max_pkts = ha->hw.rcv_intr_coalesce & 0xFFFF;
1010 intrc->max_mswait = (ha->hw.rcv_intr_coalesce >> 16) & 0xFFFF;
1012 intrc->flags = Q8_MBX_INTRC_FLAGS_XMT;
1013 intrc->max_pkts = ha->hw.xmt_intr_coalesce & 0xFFFF;
1014 intrc->max_mswait = (ha->hw.xmt_intr_coalesce >> 16) & 0xFFFF;
1017 intrc->cntxt_id = cntxt_id;
1020 intrc->flags |= Q8_MBX_INTRC_FLAGS_PERIODIC;
1021 intrc->timer_type = Q8_MBX_INTRC_TIMER_PERIODIC;
1023 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1024 intrc->sds_ring_mask |= (1 << i);
1026 intrc->ms_timeout = 1000;
1029 if (qla_mbx_cmd(ha, (uint32_t *)intrc,
1030 (sizeof (q80_config_intr_coalesc_t) >> 2),
1031 ha->hw.mbox, (sizeof(q80_config_intr_coalesc_rsp_t) >> 2), 0)) {
1032 device_printf(dev, "%s: failed0\n", __func__);
1035 intrc_rsp = (q80_config_intr_coalesc_rsp_t *)ha->hw.mbox;
1037 err = Q8_MBX_RSP_STATUS(intrc_rsp->regcnt_status);
1040 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
1049 * Name: qla_config_mac_addr
1050 * Function: binds a MAC address to the context/interface.
1051 * Can be unicast, multicast or broadcast.
1054 qla_config_mac_addr(qla_host_t *ha, uint8_t *mac_addr, uint32_t add_mac)
1056 q80_config_mac_addr_t *cmac;
1057 q80_config_mac_addr_rsp_t *cmac_rsp;
1059 device_t dev = ha->pci_dev;
1061 cmac = (q80_config_mac_addr_t *)ha->hw.mbox;
1062 bzero(cmac, (sizeof (q80_config_mac_addr_t)));
1064 cmac->opcode = Q8_MBX_CONFIG_MAC_ADDR;
1065 cmac->count_version = sizeof (q80_config_mac_addr_t) >> 2;
1066 cmac->count_version |= Q8_MBX_CMD_VERSION;
1069 cmac->cmd = Q8_MBX_CMAC_CMD_ADD_MAC_ADDR;
1071 cmac->cmd = Q8_MBX_CMAC_CMD_DEL_MAC_ADDR;
1073 cmac->cmd |= Q8_MBX_CMAC_CMD_CAM_INGRESS;
1075 cmac->nmac_entries = 1;
1076 cmac->cntxt_id = ha->hw.rcv_cntxt_id;
1077 bcopy(mac_addr, cmac->mac_addr[0].addr, 6);
1079 if (qla_mbx_cmd(ha, (uint32_t *)cmac,
1080 (sizeof (q80_config_mac_addr_t) >> 2),
1081 ha->hw.mbox, (sizeof(q80_config_mac_addr_rsp_t) >> 2), 1)) {
1082 device_printf(dev, "%s: %s failed0\n", __func__,
1083 (add_mac ? "Add" : "Del"));
1086 cmac_rsp = (q80_config_mac_addr_rsp_t *)ha->hw.mbox;
1088 err = Q8_MBX_RSP_STATUS(cmac_rsp->regcnt_status);
1091 device_printf(dev, "%s: %s "
1092 "%02x:%02x:%02x:%02x:%02x:%02x failed1 [0x%08x]\n",
1093 __func__, (add_mac ? "Add" : "Del"),
1094 mac_addr[0], mac_addr[1], mac_addr[2],
1095 mac_addr[3], mac_addr[4], mac_addr[5], err);
1104 * Name: qla_set_mac_rcv_mode
1105 * Function: Enable/Disable AllMulticast and Promiscous Modes.
1108 qla_set_mac_rcv_mode(qla_host_t *ha, uint32_t mode)
1110 q80_config_mac_rcv_mode_t *rcv_mode;
1112 q80_config_mac_rcv_mode_rsp_t *rcv_mode_rsp;
1113 device_t dev = ha->pci_dev;
1115 rcv_mode = (q80_config_mac_rcv_mode_t *)ha->hw.mbox;
1116 bzero(rcv_mode, (sizeof (q80_config_mac_rcv_mode_t)));
1118 rcv_mode->opcode = Q8_MBX_CONFIG_MAC_RX_MODE;
1119 rcv_mode->count_version = sizeof (q80_config_mac_rcv_mode_t) >> 2;
1120 rcv_mode->count_version |= Q8_MBX_CMD_VERSION;
1122 rcv_mode->mode = mode;
1124 rcv_mode->cntxt_id = ha->hw.rcv_cntxt_id;
1126 if (qla_mbx_cmd(ha, (uint32_t *)rcv_mode,
1127 (sizeof (q80_config_mac_rcv_mode_t) >> 2),
1128 ha->hw.mbox, (sizeof(q80_config_mac_rcv_mode_rsp_t) >> 2), 1)) {
1129 device_printf(dev, "%s: failed0\n", __func__);
1132 rcv_mode_rsp = (q80_config_mac_rcv_mode_rsp_t *)ha->hw.mbox;
1134 err = Q8_MBX_RSP_STATUS(rcv_mode_rsp->regcnt_status);
1137 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
1145 ql_set_promisc(qla_host_t *ha)
1149 ha->hw.mac_rcv_mode |= Q8_MBX_MAC_RCV_PROMISC_ENABLE;
1150 ret = qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode);
1155 qla_reset_promisc(qla_host_t *ha)
1157 ha->hw.mac_rcv_mode &= ~Q8_MBX_MAC_RCV_PROMISC_ENABLE;
1158 (void)qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode);
1162 ql_set_allmulti(qla_host_t *ha)
1166 ha->hw.mac_rcv_mode |= Q8_MBX_MAC_ALL_MULTI_ENABLE;
1167 ret = qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode);
1172 qla_reset_allmulti(qla_host_t *ha)
1174 ha->hw.mac_rcv_mode &= ~Q8_MBX_MAC_ALL_MULTI_ENABLE;
1175 (void)qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode);
1179 * Name: ql_set_max_mtu
1181 * Sets the maximum transfer unit size for the specified rcv context.
1184 ql_set_max_mtu(qla_host_t *ha, uint32_t mtu, uint16_t cntxt_id)
1187 q80_set_max_mtu_t *max_mtu;
1188 q80_set_max_mtu_rsp_t *max_mtu_rsp;
1193 max_mtu = (q80_set_max_mtu_t *)ha->hw.mbox;
1194 bzero(max_mtu, (sizeof (q80_set_max_mtu_t)));
1196 max_mtu->opcode = Q8_MBX_SET_MAX_MTU;
1197 max_mtu->count_version = (sizeof (q80_set_max_mtu_t) >> 2);
1198 max_mtu->count_version |= Q8_MBX_CMD_VERSION;
1200 max_mtu->cntxt_id = cntxt_id;
1203 if (qla_mbx_cmd(ha, (uint32_t *)max_mtu,
1204 (sizeof (q80_set_max_mtu_t) >> 2),
1205 ha->hw.mbox, (sizeof (q80_set_max_mtu_rsp_t) >> 2), 1)) {
1206 device_printf(dev, "%s: failed\n", __func__);
1210 max_mtu_rsp = (q80_set_max_mtu_rsp_t *)ha->hw.mbox;
1212 err = Q8_MBX_RSP_STATUS(max_mtu_rsp->regcnt_status);
1215 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
1222 qla_link_event_req(qla_host_t *ha, uint16_t cntxt_id)
1225 q80_link_event_t *lnk;
1226 q80_link_event_rsp_t *lnk_rsp;
1231 lnk = (q80_link_event_t *)ha->hw.mbox;
1232 bzero(lnk, (sizeof (q80_link_event_t)));
1234 lnk->opcode = Q8_MBX_LINK_EVENT_REQ;
1235 lnk->count_version = (sizeof (q80_link_event_t) >> 2);
1236 lnk->count_version |= Q8_MBX_CMD_VERSION;
1238 lnk->cntxt_id = cntxt_id;
1239 lnk->cmd = Q8_LINK_EVENT_CMD_ENABLE_ASYNC;
1241 if (qla_mbx_cmd(ha, (uint32_t *)lnk, (sizeof (q80_link_event_t) >> 2),
1242 ha->hw.mbox, (sizeof (q80_link_event_rsp_t) >> 2), 0)) {
1243 device_printf(dev, "%s: failed\n", __func__);
1247 lnk_rsp = (q80_link_event_rsp_t *)ha->hw.mbox;
1249 err = Q8_MBX_RSP_STATUS(lnk_rsp->regcnt_status);
1252 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
1259 qla_config_fw_lro(qla_host_t *ha, uint16_t cntxt_id)
1262 q80_config_fw_lro_t *fw_lro;
1263 q80_config_fw_lro_rsp_t *fw_lro_rsp;
1268 fw_lro = (q80_config_fw_lro_t *)ha->hw.mbox;
1269 bzero(fw_lro, sizeof(q80_config_fw_lro_t));
1271 fw_lro->opcode = Q8_MBX_CONFIG_FW_LRO;
1272 fw_lro->count_version = (sizeof (q80_config_fw_lro_t) >> 2);
1273 fw_lro->count_version |= Q8_MBX_CMD_VERSION;
1275 fw_lro->flags |= Q8_MBX_FW_LRO_IPV4 | Q8_MBX_FW_LRO_IPV4_WO_DST_IP_CHK;
1276 fw_lro->flags |= Q8_MBX_FW_LRO_IPV6 | Q8_MBX_FW_LRO_IPV6_WO_DST_IP_CHK;
1278 fw_lro->cntxt_id = cntxt_id;
1280 if (qla_mbx_cmd(ha, (uint32_t *)fw_lro,
1281 (sizeof (q80_config_fw_lro_t) >> 2),
1282 ha->hw.mbox, (sizeof (q80_config_fw_lro_rsp_t) >> 2), 0)) {
1283 device_printf(dev, "%s: failed\n", __func__);
1287 fw_lro_rsp = (q80_config_fw_lro_rsp_t *)ha->hw.mbox;
1289 err = Q8_MBX_RSP_STATUS(fw_lro_rsp->regcnt_status);
1292 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
1299 qla_xmt_stats(qla_host_t *ha, q80_xmt_stats_t *xstat, int i)
1301 device_t dev = ha->pci_dev;
1303 if (i < ha->hw.num_tx_rings) {
1304 device_printf(dev, "%s[%d]: total_bytes\t\t%" PRIu64 "\n",
1305 __func__, i, xstat->total_bytes);
1306 device_printf(dev, "%s[%d]: total_pkts\t\t%" PRIu64 "\n",
1307 __func__, i, xstat->total_pkts);
1308 device_printf(dev, "%s[%d]: errors\t\t%" PRIu64 "\n",
1309 __func__, i, xstat->errors);
1310 device_printf(dev, "%s[%d]: pkts_dropped\t%" PRIu64 "\n",
1311 __func__, i, xstat->pkts_dropped);
1312 device_printf(dev, "%s[%d]: switch_pkts\t\t%" PRIu64 "\n",
1313 __func__, i, xstat->switch_pkts);
1314 device_printf(dev, "%s[%d]: num_buffers\t\t%" PRIu64 "\n",
1315 __func__, i, xstat->num_buffers);
1317 device_printf(dev, "%s: total_bytes\t\t\t%" PRIu64 "\n",
1318 __func__, xstat->total_bytes);
1319 device_printf(dev, "%s: total_pkts\t\t\t%" PRIu64 "\n",
1320 __func__, xstat->total_pkts);
1321 device_printf(dev, "%s: errors\t\t\t%" PRIu64 "\n",
1322 __func__, xstat->errors);
1323 device_printf(dev, "%s: pkts_dropped\t\t\t%" PRIu64 "\n",
1324 __func__, xstat->pkts_dropped);
1325 device_printf(dev, "%s: switch_pkts\t\t\t%" PRIu64 "\n",
1326 __func__, xstat->switch_pkts);
1327 device_printf(dev, "%s: num_buffers\t\t\t%" PRIu64 "\n",
1328 __func__, xstat->num_buffers);
1333 qla_rcv_stats(qla_host_t *ha, q80_rcv_stats_t *rstat)
1335 device_t dev = ha->pci_dev;
1337 device_printf(dev, "%s: total_bytes\t\t\t%" PRIu64 "\n", __func__,
1338 rstat->total_bytes);
1339 device_printf(dev, "%s: total_pkts\t\t\t%" PRIu64 "\n", __func__,
1341 device_printf(dev, "%s: lro_pkt_count\t\t%" PRIu64 "\n", __func__,
1342 rstat->lro_pkt_count);
1343 device_printf(dev, "%s: sw_pkt_count\t\t\t%" PRIu64 "\n", __func__,
1344 rstat->sw_pkt_count);
1345 device_printf(dev, "%s: ip_chksum_err\t\t%" PRIu64 "\n", __func__,
1346 rstat->ip_chksum_err);
1347 device_printf(dev, "%s: pkts_wo_acntxts\t\t%" PRIu64 "\n", __func__,
1348 rstat->pkts_wo_acntxts);
1349 device_printf(dev, "%s: pkts_dropped_no_sds_card\t%" PRIu64 "\n",
1350 __func__, rstat->pkts_dropped_no_sds_card);
1351 device_printf(dev, "%s: pkts_dropped_no_sds_host\t%" PRIu64 "\n",
1352 __func__, rstat->pkts_dropped_no_sds_host);
1353 device_printf(dev, "%s: oversized_pkts\t\t%" PRIu64 "\n", __func__,
1354 rstat->oversized_pkts);
1355 device_printf(dev, "%s: pkts_dropped_no_rds\t\t%" PRIu64 "\n",
1356 __func__, rstat->pkts_dropped_no_rds);
1357 device_printf(dev, "%s: unxpctd_mcast_pkts\t\t%" PRIu64 "\n",
1358 __func__, rstat->unxpctd_mcast_pkts);
1359 device_printf(dev, "%s: re1_fbq_error\t\t%" PRIu64 "\n", __func__,
1360 rstat->re1_fbq_error);
1361 device_printf(dev, "%s: invalid_mac_addr\t\t%" PRIu64 "\n", __func__,
1362 rstat->invalid_mac_addr);
1363 device_printf(dev, "%s: rds_prime_trys\t\t%" PRIu64 "\n", __func__,
1364 rstat->rds_prime_trys);
1365 device_printf(dev, "%s: rds_prime_success\t\t%" PRIu64 "\n", __func__,
1366 rstat->rds_prime_success);
1367 device_printf(dev, "%s: lro_flows_added\t\t%" PRIu64 "\n", __func__,
1368 rstat->lro_flows_added);
1369 device_printf(dev, "%s: lro_flows_deleted\t\t%" PRIu64 "\n", __func__,
1370 rstat->lro_flows_deleted);
1371 device_printf(dev, "%s: lro_flows_active\t\t%" PRIu64 "\n", __func__,
1372 rstat->lro_flows_active);
1373 device_printf(dev, "%s: pkts_droped_unknown\t\t%" PRIu64 "\n",
1374 __func__, rstat->pkts_droped_unknown);
1378 qla_mac_stats(qla_host_t *ha, q80_mac_stats_t *mstat)
1380 device_t dev = ha->pci_dev;
1382 device_printf(dev, "%s: xmt_frames\t\t\t%" PRIu64 "\n", __func__,
1384 device_printf(dev, "%s: xmt_bytes\t\t\t%" PRIu64 "\n", __func__,
1386 device_printf(dev, "%s: xmt_mcast_pkts\t\t%" PRIu64 "\n", __func__,
1387 mstat->xmt_mcast_pkts);
1388 device_printf(dev, "%s: xmt_bcast_pkts\t\t%" PRIu64 "\n", __func__,
1389 mstat->xmt_bcast_pkts);
1390 device_printf(dev, "%s: xmt_pause_frames\t\t%" PRIu64 "\n", __func__,
1391 mstat->xmt_pause_frames);
1392 device_printf(dev, "%s: xmt_cntrl_pkts\t\t%" PRIu64 "\n", __func__,
1393 mstat->xmt_cntrl_pkts);
1394 device_printf(dev, "%s: xmt_pkt_lt_64bytes\t\t%" PRIu64 "\n",
1395 __func__, mstat->xmt_pkt_lt_64bytes);
1396 device_printf(dev, "%s: xmt_pkt_lt_127bytes\t\t%" PRIu64 "\n",
1397 __func__, mstat->xmt_pkt_lt_127bytes);
1398 device_printf(dev, "%s: xmt_pkt_lt_255bytes\t\t%" PRIu64 "\n",
1399 __func__, mstat->xmt_pkt_lt_255bytes);
1400 device_printf(dev, "%s: xmt_pkt_lt_511bytes\t\t%" PRIu64 "\n",
1401 __func__, mstat->xmt_pkt_lt_511bytes);
1402 device_printf(dev, "%s: xmt_pkt_lt_1023bytes\t\t%" PRIu64 "\n",
1403 __func__, mstat->xmt_pkt_lt_1023bytes);
1404 device_printf(dev, "%s: xmt_pkt_lt_1518bytes\t\t%" PRIu64 "\n",
1405 __func__, mstat->xmt_pkt_lt_1518bytes);
1406 device_printf(dev, "%s: xmt_pkt_gt_1518bytes\t\t%" PRIu64 "\n",
1407 __func__, mstat->xmt_pkt_gt_1518bytes);
1409 device_printf(dev, "%s: rcv_frames\t\t\t%" PRIu64 "\n", __func__,
1411 device_printf(dev, "%s: rcv_bytes\t\t\t%" PRIu64 "\n", __func__,
1413 device_printf(dev, "%s: rcv_mcast_pkts\t\t%" PRIu64 "\n", __func__,
1414 mstat->rcv_mcast_pkts);
1415 device_printf(dev, "%s: rcv_bcast_pkts\t\t%" PRIu64 "\n", __func__,
1416 mstat->rcv_bcast_pkts);
1417 device_printf(dev, "%s: rcv_pause_frames\t\t%" PRIu64 "\n", __func__,
1418 mstat->rcv_pause_frames);
1419 device_printf(dev, "%s: rcv_cntrl_pkts\t\t%" PRIu64 "\n", __func__,
1420 mstat->rcv_cntrl_pkts);
1421 device_printf(dev, "%s: rcv_pkt_lt_64bytes\t\t%" PRIu64 "\n",
1422 __func__, mstat->rcv_pkt_lt_64bytes);
1423 device_printf(dev, "%s: rcv_pkt_lt_127bytes\t\t%" PRIu64 "\n",
1424 __func__, mstat->rcv_pkt_lt_127bytes);
1425 device_printf(dev, "%s: rcv_pkt_lt_255bytes\t\t%" PRIu64 "\n",
1426 __func__, mstat->rcv_pkt_lt_255bytes);
1427 device_printf(dev, "%s: rcv_pkt_lt_511bytes\t\t%" PRIu64 "\n",
1428 __func__, mstat->rcv_pkt_lt_511bytes);
1429 device_printf(dev, "%s: rcv_pkt_lt_1023bytes\t\t%" PRIu64 "\n",
1430 __func__, mstat->rcv_pkt_lt_1023bytes);
1431 device_printf(dev, "%s: rcv_pkt_lt_1518bytes\t\t%" PRIu64 "\n",
1432 __func__, mstat->rcv_pkt_lt_1518bytes);
1433 device_printf(dev, "%s: rcv_pkt_gt_1518bytes\t\t%" PRIu64 "\n",
1434 __func__, mstat->rcv_pkt_gt_1518bytes);
1436 device_printf(dev, "%s: rcv_len_error\t\t%" PRIu64 "\n", __func__,
1437 mstat->rcv_len_error);
1438 device_printf(dev, "%s: rcv_len_small\t\t%" PRIu64 "\n", __func__,
1439 mstat->rcv_len_small);
1440 device_printf(dev, "%s: rcv_len_large\t\t%" PRIu64 "\n", __func__,
1441 mstat->rcv_len_large);
1442 device_printf(dev, "%s: rcv_jabber\t\t\t%" PRIu64 "\n", __func__,
1444 device_printf(dev, "%s: rcv_dropped\t\t\t%" PRIu64 "\n", __func__,
1445 mstat->rcv_dropped);
1446 device_printf(dev, "%s: fcs_error\t\t\t%" PRIu64 "\n", __func__,
1448 device_printf(dev, "%s: align_error\t\t\t%" PRIu64 "\n", __func__,
1449 mstat->align_error);
1454 qla_get_hw_stats(qla_host_t *ha, uint32_t cmd, uint32_t rsp_size)
1457 q80_get_stats_t *stat;
1458 q80_get_stats_rsp_t *stat_rsp;
1463 stat = (q80_get_stats_t *)ha->hw.mbox;
1464 bzero(stat, (sizeof (q80_get_stats_t)));
1466 stat->opcode = Q8_MBX_GET_STATS;
1467 stat->count_version = 2;
1468 stat->count_version |= Q8_MBX_CMD_VERSION;
1472 if (qla_mbx_cmd(ha, (uint32_t *)stat, 2,
1473 ha->hw.mbox, (rsp_size >> 2), 0)) {
1474 device_printf(dev, "%s: failed\n", __func__);
1478 stat_rsp = (q80_get_stats_rsp_t *)ha->hw.mbox;
1480 err = Q8_MBX_RSP_STATUS(stat_rsp->regcnt_status);
1490 ql_get_stats(qla_host_t *ha)
1492 q80_get_stats_rsp_t *stat_rsp;
1493 q80_mac_stats_t *mstat;
1494 q80_xmt_stats_t *xstat;
1495 q80_rcv_stats_t *rstat;
1499 stat_rsp = (q80_get_stats_rsp_t *)ha->hw.mbox;
1501 * Get MAC Statistics
1503 cmd = Q8_GET_STATS_CMD_TYPE_MAC;
1504 // cmd |= Q8_GET_STATS_CMD_CLEAR;
1506 cmd |= ((ha->pci_func & 0x1) << 16);
1508 if (qla_get_hw_stats(ha, cmd, sizeof (q80_get_stats_rsp_t)) == 0) {
1509 mstat = (q80_mac_stats_t *)&stat_rsp->u.mac;
1510 qla_mac_stats(ha, mstat);
1512 device_printf(ha->pci_dev, "%s: mac failed [0x%08x]\n",
1513 __func__, ha->hw.mbox[0]);
1516 * Get RCV Statistics
1518 cmd = Q8_GET_STATS_CMD_RCV | Q8_GET_STATS_CMD_TYPE_CNTXT;
1519 // cmd |= Q8_GET_STATS_CMD_CLEAR;
1520 cmd |= (ha->hw.rcv_cntxt_id << 16);
1522 if (qla_get_hw_stats(ha, cmd, sizeof (q80_get_stats_rsp_t)) == 0) {
1523 rstat = (q80_rcv_stats_t *)&stat_rsp->u.rcv;
1524 qla_rcv_stats(ha, rstat);
1526 device_printf(ha->pci_dev, "%s: rcv failed [0x%08x]\n",
1527 __func__, ha->hw.mbox[0]);
1530 * Get XMT Statistics
1532 for (i = 0 ; i < ha->hw.num_tx_rings; i++) {
1533 cmd = Q8_GET_STATS_CMD_XMT | Q8_GET_STATS_CMD_TYPE_CNTXT;
1534 // cmd |= Q8_GET_STATS_CMD_CLEAR;
1535 cmd |= (ha->hw.tx_cntxt[i].tx_cntxt_id << 16);
1537 if (qla_get_hw_stats(ha, cmd, sizeof(q80_get_stats_rsp_t))
1539 xstat = (q80_xmt_stats_t *)&stat_rsp->u.xmt;
1540 qla_xmt_stats(ha, xstat, i);
1542 device_printf(ha->pci_dev, "%s: xmt failed [0x%08x]\n",
1543 __func__, ha->hw.mbox[0]);
1550 qla_get_quick_stats(qla_host_t *ha)
1552 q80_get_mac_rcv_xmt_stats_rsp_t *stat_rsp;
1553 q80_mac_stats_t *mstat;
1554 q80_xmt_stats_t *xstat;
1555 q80_rcv_stats_t *rstat;
1558 stat_rsp = (q80_get_mac_rcv_xmt_stats_rsp_t *)ha->hw.mbox;
1560 cmd = Q8_GET_STATS_CMD_TYPE_ALL;
1561 // cmd |= Q8_GET_STATS_CMD_CLEAR;
1563 // cmd |= ((ha->pci_func & 0x3) << 16);
1564 cmd |= (0xFFFF << 16);
1566 if (qla_get_hw_stats(ha, cmd,
1567 sizeof (q80_get_mac_rcv_xmt_stats_rsp_t)) == 0) {
1569 mstat = (q80_mac_stats_t *)&stat_rsp->mac;
1570 rstat = (q80_rcv_stats_t *)&stat_rsp->rcv;
1571 xstat = (q80_xmt_stats_t *)&stat_rsp->xmt;
1572 qla_mac_stats(ha, mstat);
1573 qla_rcv_stats(ha, rstat);
1574 qla_xmt_stats(ha, xstat, ha->hw.num_tx_rings);
1576 device_printf(ha->pci_dev, "%s: failed [0x%08x]\n",
1577 __func__, ha->hw.mbox[0]);
1584 * Function: Checks if the packet to be transmitted is a candidate for
1585 * Large TCP Segment Offload. If yes, the appropriate fields in the Tx
1586 * Ring Structure are plugged in.
1589 qla_tx_tso(qla_host_t *ha, struct mbuf *mp, q80_tx_cmd_t *tx_cmd, uint8_t *hdr)
1591 struct ether_vlan_header *eh;
1592 struct ip *ip = NULL;
1593 struct ip6_hdr *ip6 = NULL;
1594 struct tcphdr *th = NULL;
1595 uint32_t ehdrlen, hdrlen, ip_hlen, tcp_hlen, tcp_opt_off;
1596 uint16_t etype, opcode, offload = 1;
1602 eh = mtod(mp, struct ether_vlan_header *);
1604 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
1605 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
1606 etype = ntohs(eh->evl_proto);
1608 ehdrlen = ETHER_HDR_LEN;
1609 etype = ntohs(eh->evl_encap_proto);
1617 tcp_opt_off = ehdrlen + sizeof(struct ip) +
1618 sizeof(struct tcphdr);
1620 if (mp->m_len < tcp_opt_off) {
1621 m_copydata(mp, 0, tcp_opt_off, hdr);
1622 ip = (struct ip *)(hdr + ehdrlen);
1624 ip = (struct ip *)(mp->m_data + ehdrlen);
1627 ip_hlen = ip->ip_hl << 2;
1628 opcode = Q8_TX_CMD_OP_XMT_TCP_LSO;
1631 if ((ip->ip_p != IPPROTO_TCP) ||
1632 (ip_hlen != sizeof (struct ip))){
1633 /* IP Options are not supported */
1637 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
1641 case ETHERTYPE_IPV6:
1643 tcp_opt_off = ehdrlen + sizeof(struct ip6_hdr) +
1644 sizeof (struct tcphdr);
1646 if (mp->m_len < tcp_opt_off) {
1647 m_copydata(mp, 0, tcp_opt_off, hdr);
1648 ip6 = (struct ip6_hdr *)(hdr + ehdrlen);
1650 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
1653 ip_hlen = sizeof(struct ip6_hdr);
1654 opcode = Q8_TX_CMD_OP_XMT_TCP_LSO_IPV6;
1656 if (ip6->ip6_nxt != IPPROTO_TCP) {
1657 //device_printf(dev, "%s: ipv6\n", __func__);
1660 th = (struct tcphdr *)((caddr_t)ip6 + ip_hlen);
1664 QL_DPRINT8(ha, (dev, "%s: type!=ip\n", __func__));
1672 tcp_hlen = th->th_off << 2;
1673 hdrlen = ehdrlen + ip_hlen + tcp_hlen;
1675 if (mp->m_len < hdrlen) {
1676 if (mp->m_len < tcp_opt_off) {
1677 if (tcp_hlen > sizeof(struct tcphdr)) {
1678 m_copydata(mp, tcp_opt_off,
1679 (tcp_hlen - sizeof(struct tcphdr)),
1683 m_copydata(mp, 0, hdrlen, hdr);
1687 tx_cmd->mss = mp->m_pkthdr.tso_segsz;
1689 tx_cmd->flags_opcode = opcode ;
1690 tx_cmd->tcp_hdr_off = ip_hlen + ehdrlen;
1691 tx_cmd->total_hdr_len = hdrlen;
1693 /* Check for Multicast least significant bit of MSB == 1 */
1694 if (eh->evl_dhost[0] & 0x01) {
1695 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_MULTICAST;
1698 if (mp->m_len < hdrlen) {
1699 printf("%d\n", hdrlen);
1707 * Name: qla_tx_chksum
1708 * Function: Checks if the packet to be transmitted is a candidate for
1709 * TCP/UDP Checksum offload. If yes, the appropriate fields in the Tx
1710 * Ring Structure are plugged in.
1713 qla_tx_chksum(qla_host_t *ha, struct mbuf *mp, uint32_t *op_code,
1714 uint32_t *tcp_hdr_off)
1716 struct ether_vlan_header *eh;
1718 struct ip6_hdr *ip6;
1719 uint32_t ehdrlen, ip_hlen;
1720 uint16_t etype, opcode, offload = 1;
1722 uint8_t buf[sizeof(struct ip6_hdr)];
1728 if ((mp->m_pkthdr.csum_flags & (CSUM_TCP|CSUM_UDP)) == 0)
1731 eh = mtod(mp, struct ether_vlan_header *);
1733 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
1734 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
1735 etype = ntohs(eh->evl_proto);
1737 ehdrlen = ETHER_HDR_LEN;
1738 etype = ntohs(eh->evl_encap_proto);
1744 ip = (struct ip *)(mp->m_data + ehdrlen);
1746 ip_hlen = sizeof (struct ip);
1748 if (mp->m_len < (ehdrlen + ip_hlen)) {
1749 m_copydata(mp, ehdrlen, sizeof(struct ip), buf);
1750 ip = (struct ip *)buf;
1753 if (ip->ip_p == IPPROTO_TCP)
1754 opcode = Q8_TX_CMD_OP_XMT_TCP_CHKSUM;
1755 else if (ip->ip_p == IPPROTO_UDP)
1756 opcode = Q8_TX_CMD_OP_XMT_UDP_CHKSUM;
1758 //device_printf(dev, "%s: ipv4\n", __func__);
1763 case ETHERTYPE_IPV6:
1764 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
1766 ip_hlen = sizeof(struct ip6_hdr);
1768 if (mp->m_len < (ehdrlen + ip_hlen)) {
1769 m_copydata(mp, ehdrlen, sizeof (struct ip6_hdr),
1771 ip6 = (struct ip6_hdr *)buf;
1774 if (ip6->ip6_nxt == IPPROTO_TCP)
1775 opcode = Q8_TX_CMD_OP_XMT_TCP_CHKSUM_IPV6;
1776 else if (ip6->ip6_nxt == IPPROTO_UDP)
1777 opcode = Q8_TX_CMD_OP_XMT_UDP_CHKSUM_IPV6;
1779 //device_printf(dev, "%s: ipv6\n", __func__);
1792 *tcp_hdr_off = (ip_hlen + ehdrlen);
1797 #define QLA_TX_MIN_FREE 2
1800 * Function: Transmits a packet. It first checks if the packet is a
1801 * candidate for Large TCP Segment Offload and then for UDP/TCP checksum
1802 * offload. If either of these creteria are not met, it is transmitted
1803 * as a regular ethernet frame.
1806 ql_hw_send(qla_host_t *ha, bus_dma_segment_t *segs, int nsegs,
1807 uint32_t tx_idx, struct mbuf *mp, uint32_t txr_idx, uint32_t iscsi_pdu)
1809 struct ether_vlan_header *eh;
1810 qla_hw_t *hw = &ha->hw;
1811 q80_tx_cmd_t *tx_cmd, tso_cmd;
1812 bus_dma_segment_t *c_seg;
1813 uint32_t num_tx_cmds, hdr_len = 0;
1814 uint32_t total_length = 0, bytes, tx_cmd_count = 0, txr_next;
1817 uint8_t *src = NULL, *dst = NULL;
1818 uint8_t frame_hdr[QL_FRAME_HDR_SIZE];
1819 uint32_t op_code = 0;
1820 uint32_t tcp_hdr_off = 0;
1825 * Always make sure there is atleast one empty slot in the tx_ring
1826 * tx_ring is considered full when there only one entry available
1828 num_tx_cmds = (nsegs + (Q8_TX_CMD_MAX_SEGMENTS - 1)) >> 2;
1830 total_length = mp->m_pkthdr.len;
1831 if (total_length > QLA_MAX_TSO_FRAME_SIZE) {
1832 device_printf(dev, "%s: total length exceeds maxlen(%d)\n",
1833 __func__, total_length);
1836 eh = mtod(mp, struct ether_vlan_header *);
1838 if (mp->m_pkthdr.csum_flags & CSUM_TSO) {
1840 bzero((void *)&tso_cmd, sizeof(q80_tx_cmd_t));
1843 ret = qla_tx_tso(ha, mp, &tso_cmd, src);
1846 /* find the additional tx_cmd descriptors required */
1848 if (mp->m_flags & M_VLANTAG)
1849 tso_cmd.total_hdr_len += ETHER_VLAN_ENCAP_LEN;
1851 hdr_len = tso_cmd.total_hdr_len;
1853 bytes = sizeof(q80_tx_cmd_t) - Q8_TX_CMD_TSO_ALIGN;
1854 bytes = QL_MIN(bytes, hdr_len);
1860 bytes = QL_MIN((sizeof(q80_tx_cmd_t)), hdr_len);
1864 hdr_len = tso_cmd.total_hdr_len;
1867 src = (uint8_t *)eh;
1871 (void)qla_tx_chksum(ha, mp, &op_code, &tcp_hdr_off);
1875 ha->hw.iscsi_pkt_count++;
1877 if (hw->tx_cntxt[txr_idx].txr_free <= (num_tx_cmds + QLA_TX_MIN_FREE)) {
1878 qla_hw_tx_done_locked(ha, txr_idx);
1879 if (hw->tx_cntxt[txr_idx].txr_free <=
1880 (num_tx_cmds + QLA_TX_MIN_FREE)) {
1881 QL_DPRINT8(ha, (dev, "%s: (hw->txr_free <= "
1882 "(num_tx_cmds + QLA_TX_MIN_FREE))\n",
1888 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[tx_idx];
1890 if (!(mp->m_pkthdr.csum_flags & CSUM_TSO)) {
1892 if (nsegs > ha->hw.max_tx_segs)
1893 ha->hw.max_tx_segs = nsegs;
1895 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1898 tx_cmd->flags_opcode = op_code;
1899 tx_cmd->tcp_hdr_off = tcp_hdr_off;
1902 tx_cmd->flags_opcode = Q8_TX_CMD_OP_XMT_ETHER;
1905 bcopy(&tso_cmd, tx_cmd, sizeof(q80_tx_cmd_t));
1906 ha->tx_tso_frames++;
1909 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
1910 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_VLAN_TAGGED;
1913 eh->evl_tag |= ha->hw.user_pri_iscsi << 13;
1915 } else if (mp->m_flags & M_VLANTAG) {
1917 if (hdr_len) { /* TSO */
1918 tx_cmd->flags_opcode |= (Q8_TX_CMD_FLAGS_VLAN_TAGGED |
1919 Q8_TX_CMD_FLAGS_HW_VLAN_ID);
1920 tx_cmd->tcp_hdr_off += ETHER_VLAN_ENCAP_LEN;
1922 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_HW_VLAN_ID;
1924 ha->hw_vlan_tx_frames++;
1925 tx_cmd->vlan_tci = mp->m_pkthdr.ether_vtag;
1928 tx_cmd->vlan_tci |= ha->hw.user_pri_iscsi << 13;
1929 mp->m_pkthdr.ether_vtag = tx_cmd->vlan_tci;
1934 tx_cmd->n_bufs = (uint8_t)nsegs;
1935 tx_cmd->data_len_lo = (uint8_t)(total_length & 0xFF);
1936 tx_cmd->data_len_hi = qla_host_to_le16(((uint16_t)(total_length >> 8)));
1937 tx_cmd->cntxtid = Q8_TX_CMD_PORT_CNXTID(ha->pci_func);
1942 for (i = 0; ((i < Q8_TX_CMD_MAX_SEGMENTS) && nsegs); i++) {
1946 tx_cmd->buf1_addr = c_seg->ds_addr;
1947 tx_cmd->buf1_len = c_seg->ds_len;
1951 tx_cmd->buf2_addr = c_seg->ds_addr;
1952 tx_cmd->buf2_len = c_seg->ds_len;
1956 tx_cmd->buf3_addr = c_seg->ds_addr;
1957 tx_cmd->buf3_len = c_seg->ds_len;
1961 tx_cmd->buf4_addr = c_seg->ds_addr;
1962 tx_cmd->buf4_len = c_seg->ds_len;
1970 txr_next = hw->tx_cntxt[txr_idx].txr_next =
1971 (hw->tx_cntxt[txr_idx].txr_next + 1) &
1972 (NUM_TX_DESCRIPTORS - 1);
1978 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[txr_next];
1979 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1982 if (mp->m_pkthdr.csum_flags & CSUM_TSO) {
1984 /* TSO : Copy the header in the following tx cmd descriptors */
1986 txr_next = hw->tx_cntxt[txr_idx].txr_next;
1988 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[txr_next];
1989 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1991 bytes = sizeof(q80_tx_cmd_t) - Q8_TX_CMD_TSO_ALIGN;
1992 bytes = QL_MIN(bytes, hdr_len);
1994 dst = (uint8_t *)tx_cmd + Q8_TX_CMD_TSO_ALIGN;
1996 if (mp->m_flags & M_VLANTAG) {
1997 /* first copy the src/dst MAC addresses */
1998 bcopy(src, dst, (ETHER_ADDR_LEN * 2));
1999 dst += (ETHER_ADDR_LEN * 2);
2000 src += (ETHER_ADDR_LEN * 2);
2002 *((uint16_t *)dst) = htons(ETHERTYPE_VLAN);
2004 *((uint16_t *)dst) = htons(mp->m_pkthdr.ether_vtag);
2007 /* bytes left in src header */
2008 hdr_len -= ((ETHER_ADDR_LEN * 2) +
2009 ETHER_VLAN_ENCAP_LEN);
2011 /* bytes left in TxCmd Entry */
2012 bytes -= ((ETHER_ADDR_LEN * 2) + ETHER_VLAN_ENCAP_LEN);
2015 bcopy(src, dst, bytes);
2019 bcopy(src, dst, bytes);
2024 txr_next = hw->tx_cntxt[txr_idx].txr_next =
2025 (hw->tx_cntxt[txr_idx].txr_next + 1) &
2026 (NUM_TX_DESCRIPTORS - 1);
2030 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[txr_next];
2031 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
2033 bytes = QL_MIN((sizeof(q80_tx_cmd_t)), hdr_len);
2035 bcopy(src, tx_cmd, bytes);
2039 txr_next = hw->tx_cntxt[txr_idx].txr_next =
2040 (hw->tx_cntxt[txr_idx].txr_next + 1) &
2041 (NUM_TX_DESCRIPTORS - 1);
2046 hw->tx_cntxt[txr_idx].txr_free =
2047 hw->tx_cntxt[txr_idx].txr_free - tx_cmd_count;
2049 QL_UPDATE_TX_PRODUCER_INDEX(ha, hw->tx_cntxt[txr_idx].txr_next,\
2051 QL_DPRINT8(ha, (dev, "%s: return\n", __func__));
2058 #define Q8_CONFIG_IND_TBL_SIZE 32 /* < Q8_RSS_IND_TBL_SIZE and power of 2 */
2060 qla_config_rss_ind_table(qla_host_t *ha)
2063 uint8_t rss_ind_tbl[Q8_CONFIG_IND_TBL_SIZE];
2066 for (i = 0; i < Q8_CONFIG_IND_TBL_SIZE; i++) {
2067 rss_ind_tbl[i] = i % ha->hw.num_sds_rings;
2070 for (i = 0; i <= Q8_RSS_IND_TBL_MAX_IDX ;
2071 i = i + Q8_CONFIG_IND_TBL_SIZE) {
2073 if ((i + Q8_CONFIG_IND_TBL_SIZE) > Q8_RSS_IND_TBL_MAX_IDX) {
2074 count = Q8_RSS_IND_TBL_MAX_IDX - i + 1;
2076 count = Q8_CONFIG_IND_TBL_SIZE;
2079 if (qla_set_rss_ind_table(ha, i, count, ha->hw.rcv_cntxt_id,
2088 * Name: ql_del_hw_if
2089 * Function: Destroys the hardware specific entities corresponding to an
2090 * Ethernet Interface
2093 ql_del_hw_if(qla_host_t *ha)
2098 (void)qla_stop_nic_func(ha);
2100 qla_del_rcv_cntxt(ha);
2101 qla_del_xmt_cntxt(ha);
2103 if (ha->hw.flags.init_intr_cnxt) {
2104 for (i = 0; i < ha->hw.num_sds_rings; ) {
2106 if ((i + Q8_MAX_INTR_VECTORS) < ha->hw.num_sds_rings)
2107 num_msix = Q8_MAX_INTR_VECTORS;
2109 num_msix = ha->hw.num_sds_rings - i;
2110 qla_config_intr_cntxt(ha, i, num_msix, 0);
2115 ha->hw.flags.init_intr_cnxt = 0;
2121 qla_confirm_9kb_enable(qla_host_t *ha)
2123 uint32_t supports_9kb = 0;
2125 ha->hw.mbx_intr_mask_offset = READ_REG32(ha, Q8_MBOX_INT_MASK_MSIX);
2127 /* Use MSI-X vector 0; Enable Firmware Mailbox Interrupt */
2128 WRITE_REG32(ha, Q8_MBOX_INT_ENABLE, BIT_2);
2129 WRITE_REG32(ha, ha->hw.mbx_intr_mask_offset, 0x0);
2131 qla_get_nic_partition(ha, &supports_9kb, NULL);
2134 ha->hw.enable_9kb = 0;
2141 * Name: ql_init_hw_if
2142 * Function: Creates the hardware specific entities corresponding to an
2143 * Ethernet Interface - Transmit and Receive Contexts. Sets the MAC Address
2144 * corresponding to the interface. Enables LRO if allowed.
2147 ql_init_hw_if(qla_host_t *ha)
2151 uint8_t bcast_mac[6];
2157 for (i = 0; i < ha->hw.num_sds_rings; i++) {
2158 bzero(ha->hw.dma_buf.sds_ring[i].dma_b,
2159 ha->hw.dma_buf.sds_ring[i].size);
2162 for (i = 0; i < ha->hw.num_sds_rings; ) {
2164 if ((i + Q8_MAX_INTR_VECTORS) < ha->hw.num_sds_rings)
2165 num_msix = Q8_MAX_INTR_VECTORS;
2167 num_msix = ha->hw.num_sds_rings - i;
2169 if (qla_config_intr_cntxt(ha, i, num_msix, 1)) {
2175 for (i = 0; i < num_msix; ) {
2176 qla_config_intr_cntxt(ha, i,
2177 Q8_MAX_INTR_VECTORS, 0);
2178 i += Q8_MAX_INTR_VECTORS;
2187 ha->hw.flags.init_intr_cnxt = 1;
2189 if (ha->hw.mdump_init == 0) {
2190 qla_minidump_init(ha);
2194 * Create Receive Context
2196 if (qla_init_rcv_cntxt(ha)) {
2200 for (i = 0; i < ha->hw.num_rds_rings; i++) {
2201 rdesc = &ha->hw.rds[i];
2202 rdesc->rx_next = NUM_RX_DESCRIPTORS - 2;
2204 /* Update the RDS Producer Indices */
2205 QL_UPDATE_RDS_PRODUCER_INDEX(ha, rdesc->prod_std,\
2211 * Create Transmit Context
2213 if (qla_init_xmt_cntxt(ha)) {
2214 qla_del_rcv_cntxt(ha);
2217 ha->hw.max_tx_segs = 0;
2219 if (qla_config_mac_addr(ha, ha->hw.mac_addr, 1))
2222 ha->hw.flags.unicast_mac = 1;
2224 bcast_mac[0] = 0xFF; bcast_mac[1] = 0xFF; bcast_mac[2] = 0xFF;
2225 bcast_mac[3] = 0xFF; bcast_mac[4] = 0xFF; bcast_mac[5] = 0xFF;
2227 if (qla_config_mac_addr(ha, bcast_mac, 1))
2230 ha->hw.flags.bcast_mac = 1;
2233 * program any cached multicast addresses
2235 if (qla_hw_add_all_mcast(ha))
2238 if (qla_config_rss(ha, ha->hw.rcv_cntxt_id))
2241 if (qla_config_rss_ind_table(ha))
2244 if (qla_config_intr_coalesce(ha, ha->hw.rcv_cntxt_id, 0, 1))
2247 if (qla_link_event_req(ha, ha->hw.rcv_cntxt_id))
2250 if (qla_config_fw_lro(ha, ha->hw.rcv_cntxt_id))
2253 if (qla_init_nic_func(ha))
2256 if (qla_query_fw_dcbx_caps(ha))
2259 for (i = 0; i < ha->hw.num_sds_rings; i++)
2260 QL_ENABLE_INTERRUPTS(ha, i);
2266 qla_map_sds_to_rds(qla_host_t *ha, uint32_t start_idx, uint32_t num_idx)
2268 device_t dev = ha->pci_dev;
2269 q80_rq_map_sds_to_rds_t *map_rings;
2270 q80_rsp_map_sds_to_rds_t *map_rings_rsp;
2272 qla_hw_t *hw = &ha->hw;
2274 map_rings = (q80_rq_map_sds_to_rds_t *)ha->hw.mbox;
2275 bzero(map_rings, sizeof(q80_rq_map_sds_to_rds_t));
2277 map_rings->opcode = Q8_MBX_MAP_SDS_TO_RDS;
2278 map_rings->count_version = (sizeof (q80_rq_map_sds_to_rds_t) >> 2);
2279 map_rings->count_version |= Q8_MBX_CMD_VERSION;
2281 map_rings->cntxt_id = hw->rcv_cntxt_id;
2282 map_rings->num_rings = num_idx;
2284 for (i = 0; i < num_idx; i++) {
2285 map_rings->sds_rds[i].sds_ring = i + start_idx;
2286 map_rings->sds_rds[i].rds_ring = i + start_idx;
2289 if (qla_mbx_cmd(ha, (uint32_t *)map_rings,
2290 (sizeof (q80_rq_map_sds_to_rds_t) >> 2),
2291 ha->hw.mbox, (sizeof(q80_rsp_add_rcv_rings_t) >> 2), 0)) {
2292 device_printf(dev, "%s: failed0\n", __func__);
2296 map_rings_rsp = (q80_rsp_map_sds_to_rds_t *)ha->hw.mbox;
2298 err = Q8_MBX_RSP_STATUS(map_rings_rsp->regcnt_status);
2301 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2309 * Name: qla_init_rcv_cntxt
2310 * Function: Creates the Receive Context.
2313 qla_init_rcv_cntxt(qla_host_t *ha)
2315 q80_rq_rcv_cntxt_t *rcntxt;
2316 q80_rsp_rcv_cntxt_t *rcntxt_rsp;
2317 q80_stat_desc_t *sdesc;
2319 qla_hw_t *hw = &ha->hw;
2322 uint32_t rcntxt_sds_rings;
2323 uint32_t rcntxt_rds_rings;
2329 * Create Receive Context
2332 for (i = 0; i < hw->num_sds_rings; i++) {
2333 sdesc = (q80_stat_desc_t *)&hw->sds[i].sds_ring_base[0];
2335 for (j = 0; j < NUM_STATUS_DESCRIPTORS; j++) {
2336 sdesc->data[0] = 1ULL;
2337 sdesc->data[1] = 1ULL;
2341 rcntxt_sds_rings = hw->num_sds_rings;
2342 if (hw->num_sds_rings > MAX_RCNTXT_SDS_RINGS)
2343 rcntxt_sds_rings = MAX_RCNTXT_SDS_RINGS;
2345 rcntxt_rds_rings = hw->num_rds_rings;
2347 if (hw->num_rds_rings > MAX_RDS_RING_SETS)
2348 rcntxt_rds_rings = MAX_RDS_RING_SETS;
2350 rcntxt = (q80_rq_rcv_cntxt_t *)ha->hw.mbox;
2351 bzero(rcntxt, (sizeof (q80_rq_rcv_cntxt_t)));
2353 rcntxt->opcode = Q8_MBX_CREATE_RX_CNTXT;
2354 rcntxt->count_version = (sizeof (q80_rq_rcv_cntxt_t) >> 2);
2355 rcntxt->count_version |= Q8_MBX_CMD_VERSION;
2357 rcntxt->cap0 = Q8_RCV_CNTXT_CAP0_BASEFW |
2358 Q8_RCV_CNTXT_CAP0_LRO |
2359 Q8_RCV_CNTXT_CAP0_HW_LRO |
2360 Q8_RCV_CNTXT_CAP0_RSS |
2361 Q8_RCV_CNTXT_CAP0_SGL_LRO;
2363 if (ha->hw.enable_9kb)
2364 rcntxt->cap0 |= Q8_RCV_CNTXT_CAP0_SINGLE_JUMBO;
2366 rcntxt->cap0 |= Q8_RCV_CNTXT_CAP0_SGL_JUMBO;
2368 if (ha->hw.num_rds_rings > 1) {
2369 rcntxt->nrds_sets_rings = rcntxt_rds_rings | (1 << 5);
2370 rcntxt->cap0 |= Q8_RCV_CNTXT_CAP0_MULTI_RDS;
2372 rcntxt->nrds_sets_rings = 0x1 | (1 << 5);
2374 rcntxt->nsds_rings = rcntxt_sds_rings;
2376 rcntxt->rds_producer_mode = Q8_RCV_CNTXT_RDS_PROD_MODE_UNIQUE;
2378 rcntxt->rcv_vpid = 0;
2380 for (i = 0; i < rcntxt_sds_rings; i++) {
2381 rcntxt->sds[i].paddr =
2382 qla_host_to_le64(hw->dma_buf.sds_ring[i].dma_addr);
2383 rcntxt->sds[i].size =
2384 qla_host_to_le32(NUM_STATUS_DESCRIPTORS);
2385 if (ha->msix_count == 2) {
2386 rcntxt->sds[i].intr_id =
2387 qla_host_to_le16(hw->intr_id[0]);
2388 rcntxt->sds[i].intr_src_bit = qla_host_to_le16((i));
2390 rcntxt->sds[i].intr_id =
2391 qla_host_to_le16(hw->intr_id[i]);
2392 rcntxt->sds[i].intr_src_bit = qla_host_to_le16(0);
2396 for (i = 0; i < rcntxt_rds_rings; i++) {
2397 rcntxt->rds[i].paddr_std =
2398 qla_host_to_le64(hw->dma_buf.rds_ring[i].dma_addr);
2400 if (ha->hw.enable_9kb)
2401 rcntxt->rds[i].std_bsize =
2402 qla_host_to_le64(MJUM9BYTES);
2404 rcntxt->rds[i].std_bsize = qla_host_to_le64(MCLBYTES);
2406 rcntxt->rds[i].std_nentries =
2407 qla_host_to_le32(NUM_RX_DESCRIPTORS);
2410 if (qla_mbx_cmd(ha, (uint32_t *)rcntxt,
2411 (sizeof (q80_rq_rcv_cntxt_t) >> 2),
2412 ha->hw.mbox, (sizeof(q80_rsp_rcv_cntxt_t) >> 2), 0)) {
2413 device_printf(dev, "%s: failed0\n", __func__);
2417 rcntxt_rsp = (q80_rsp_rcv_cntxt_t *)ha->hw.mbox;
2419 err = Q8_MBX_RSP_STATUS(rcntxt_rsp->regcnt_status);
2422 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2426 for (i = 0; i < rcntxt_sds_rings; i++) {
2427 hw->sds[i].sds_consumer = rcntxt_rsp->sds_cons[i];
2430 for (i = 0; i < rcntxt_rds_rings; i++) {
2431 hw->rds[i].prod_std = rcntxt_rsp->rds[i].prod_std;
2434 hw->rcv_cntxt_id = rcntxt_rsp->cntxt_id;
2436 ha->hw.flags.init_rx_cnxt = 1;
2438 if (hw->num_sds_rings > MAX_RCNTXT_SDS_RINGS) {
2440 for (i = MAX_RCNTXT_SDS_RINGS; i < hw->num_sds_rings;) {
2442 if ((i + MAX_RCNTXT_SDS_RINGS) < hw->num_sds_rings)
2443 max_idx = MAX_RCNTXT_SDS_RINGS;
2445 max_idx = hw->num_sds_rings - i;
2447 err = qla_add_rcv_rings(ha, i, max_idx);
2455 if (hw->num_rds_rings > 1) {
2457 for (i = 0; i < hw->num_rds_rings; ) {
2459 if ((i + MAX_SDS_TO_RDS_MAP) < hw->num_rds_rings)
2460 max_idx = MAX_SDS_TO_RDS_MAP;
2462 max_idx = hw->num_rds_rings - i;
2464 err = qla_map_sds_to_rds(ha, i, max_idx);
2476 qla_add_rcv_rings(qla_host_t *ha, uint32_t sds_idx, uint32_t nsds)
2478 device_t dev = ha->pci_dev;
2479 q80_rq_add_rcv_rings_t *add_rcv;
2480 q80_rsp_add_rcv_rings_t *add_rcv_rsp;
2482 qla_hw_t *hw = &ha->hw;
2484 add_rcv = (q80_rq_add_rcv_rings_t *)ha->hw.mbox;
2485 bzero(add_rcv, sizeof (q80_rq_add_rcv_rings_t));
2487 add_rcv->opcode = Q8_MBX_ADD_RX_RINGS;
2488 add_rcv->count_version = (sizeof (q80_rq_add_rcv_rings_t) >> 2);
2489 add_rcv->count_version |= Q8_MBX_CMD_VERSION;
2491 add_rcv->nrds_sets_rings = nsds | (1 << 5);
2492 add_rcv->nsds_rings = nsds;
2493 add_rcv->cntxt_id = hw->rcv_cntxt_id;
2495 for (i = 0; i < nsds; i++) {
2499 add_rcv->sds[i].paddr =
2500 qla_host_to_le64(hw->dma_buf.sds_ring[j].dma_addr);
2502 add_rcv->sds[i].size =
2503 qla_host_to_le32(NUM_STATUS_DESCRIPTORS);
2505 if (ha->msix_count == 2) {
2506 add_rcv->sds[i].intr_id =
2507 qla_host_to_le16(hw->intr_id[0]);
2508 add_rcv->sds[i].intr_src_bit = qla_host_to_le16(j);
2510 add_rcv->sds[i].intr_id =
2511 qla_host_to_le16(hw->intr_id[j]);
2512 add_rcv->sds[i].intr_src_bit = qla_host_to_le16(0);
2516 for (i = 0; (i < nsds); i++) {
2519 add_rcv->rds[i].paddr_std =
2520 qla_host_to_le64(hw->dma_buf.rds_ring[j].dma_addr);
2522 if (ha->hw.enable_9kb)
2523 add_rcv->rds[i].std_bsize =
2524 qla_host_to_le64(MJUM9BYTES);
2526 add_rcv->rds[i].std_bsize = qla_host_to_le64(MCLBYTES);
2528 add_rcv->rds[i].std_nentries =
2529 qla_host_to_le32(NUM_RX_DESCRIPTORS);
2533 if (qla_mbx_cmd(ha, (uint32_t *)add_rcv,
2534 (sizeof (q80_rq_add_rcv_rings_t) >> 2),
2535 ha->hw.mbox, (sizeof(q80_rsp_add_rcv_rings_t) >> 2), 0)) {
2536 device_printf(dev, "%s: failed0\n", __func__);
2540 add_rcv_rsp = (q80_rsp_add_rcv_rings_t *)ha->hw.mbox;
2542 err = Q8_MBX_RSP_STATUS(add_rcv_rsp->regcnt_status);
2545 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2549 for (i = 0; i < nsds; i++) {
2550 hw->sds[(i + sds_idx)].sds_consumer = add_rcv_rsp->sds_cons[i];
2553 for (i = 0; i < nsds; i++) {
2554 hw->rds[(i + sds_idx)].prod_std = add_rcv_rsp->rds[i].prod_std;
2561 * Name: qla_del_rcv_cntxt
2562 * Function: Destroys the Receive Context.
2565 qla_del_rcv_cntxt(qla_host_t *ha)
2567 device_t dev = ha->pci_dev;
2568 q80_rcv_cntxt_destroy_t *rcntxt;
2569 q80_rcv_cntxt_destroy_rsp_t *rcntxt_rsp;
2571 uint8_t bcast_mac[6];
2573 if (!ha->hw.flags.init_rx_cnxt)
2576 if (qla_hw_del_all_mcast(ha))
2579 if (ha->hw.flags.bcast_mac) {
2581 bcast_mac[0] = 0xFF; bcast_mac[1] = 0xFF; bcast_mac[2] = 0xFF;
2582 bcast_mac[3] = 0xFF; bcast_mac[4] = 0xFF; bcast_mac[5] = 0xFF;
2584 if (qla_config_mac_addr(ha, bcast_mac, 0))
2586 ha->hw.flags.bcast_mac = 0;
2590 if (ha->hw.flags.unicast_mac) {
2591 if (qla_config_mac_addr(ha, ha->hw.mac_addr, 0))
2593 ha->hw.flags.unicast_mac = 0;
2596 rcntxt = (q80_rcv_cntxt_destroy_t *)ha->hw.mbox;
2597 bzero(rcntxt, (sizeof (q80_rcv_cntxt_destroy_t)));
2599 rcntxt->opcode = Q8_MBX_DESTROY_RX_CNTXT;
2600 rcntxt->count_version = (sizeof (q80_rcv_cntxt_destroy_t) >> 2);
2601 rcntxt->count_version |= Q8_MBX_CMD_VERSION;
2603 rcntxt->cntxt_id = ha->hw.rcv_cntxt_id;
2605 if (qla_mbx_cmd(ha, (uint32_t *)rcntxt,
2606 (sizeof (q80_rcv_cntxt_destroy_t) >> 2),
2607 ha->hw.mbox, (sizeof(q80_rcv_cntxt_destroy_rsp_t) >> 2), 0)) {
2608 device_printf(dev, "%s: failed0\n", __func__);
2611 rcntxt_rsp = (q80_rcv_cntxt_destroy_rsp_t *)ha->hw.mbox;
2613 err = Q8_MBX_RSP_STATUS(rcntxt_rsp->regcnt_status);
2616 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2619 ha->hw.flags.init_rx_cnxt = 0;
2624 * Name: qla_init_xmt_cntxt
2625 * Function: Creates the Transmit Context.
2628 qla_init_xmt_cntxt_i(qla_host_t *ha, uint32_t txr_idx)
2631 qla_hw_t *hw = &ha->hw;
2632 q80_rq_tx_cntxt_t *tcntxt;
2633 q80_rsp_tx_cntxt_t *tcntxt_rsp;
2635 qla_hw_tx_cntxt_t *hw_tx_cntxt;
2637 hw_tx_cntxt = &hw->tx_cntxt[txr_idx];
2642 * Create Transmit Context
2644 tcntxt = (q80_rq_tx_cntxt_t *)ha->hw.mbox;
2645 bzero(tcntxt, (sizeof (q80_rq_tx_cntxt_t)));
2647 tcntxt->opcode = Q8_MBX_CREATE_TX_CNTXT;
2648 tcntxt->count_version = (sizeof (q80_rq_tx_cntxt_t) >> 2);
2649 tcntxt->count_version |= Q8_MBX_CMD_VERSION;
2651 #ifdef QL_ENABLE_ISCSI_TLV
2653 tcntxt->cap0 = Q8_TX_CNTXT_CAP0_BASEFW | Q8_TX_CNTXT_CAP0_LSO |
2654 Q8_TX_CNTXT_CAP0_TC;
2656 if (txr_idx >= (ha->hw.num_tx_rings >> 1)) {
2657 tcntxt->traffic_class = 1;
2662 tcntxt->cap0 = Q8_TX_CNTXT_CAP0_BASEFW | Q8_TX_CNTXT_CAP0_LSO;
2664 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
2666 tcntxt->ntx_rings = 1;
2668 tcntxt->tx_ring[0].paddr =
2669 qla_host_to_le64(hw_tx_cntxt->tx_ring_paddr);
2670 tcntxt->tx_ring[0].tx_consumer =
2671 qla_host_to_le64(hw_tx_cntxt->tx_cons_paddr);
2672 tcntxt->tx_ring[0].nentries = qla_host_to_le16(NUM_TX_DESCRIPTORS);
2674 tcntxt->tx_ring[0].intr_id = qla_host_to_le16(hw->intr_id[0]);
2675 tcntxt->tx_ring[0].intr_src_bit = qla_host_to_le16(0);
2678 hw_tx_cntxt->txr_free = NUM_TX_DESCRIPTORS;
2679 hw_tx_cntxt->txr_next = hw_tx_cntxt->txr_comp = 0;
2681 if (qla_mbx_cmd(ha, (uint32_t *)tcntxt,
2682 (sizeof (q80_rq_tx_cntxt_t) >> 2),
2684 (sizeof(q80_rsp_tx_cntxt_t) >> 2), 0)) {
2685 device_printf(dev, "%s: failed0\n", __func__);
2688 tcntxt_rsp = (q80_rsp_tx_cntxt_t *)ha->hw.mbox;
2690 err = Q8_MBX_RSP_STATUS(tcntxt_rsp->regcnt_status);
2693 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2697 hw_tx_cntxt->tx_prod_reg = tcntxt_rsp->tx_ring[0].prod_index;
2698 hw_tx_cntxt->tx_cntxt_id = tcntxt_rsp->tx_ring[0].cntxt_id;
2700 if (qla_config_intr_coalesce(ha, hw_tx_cntxt->tx_cntxt_id, 0, 0))
2708 * Name: qla_del_xmt_cntxt
2709 * Function: Destroys the Transmit Context.
2712 qla_del_xmt_cntxt_i(qla_host_t *ha, uint32_t txr_idx)
2714 device_t dev = ha->pci_dev;
2715 q80_tx_cntxt_destroy_t *tcntxt;
2716 q80_tx_cntxt_destroy_rsp_t *tcntxt_rsp;
2719 tcntxt = (q80_tx_cntxt_destroy_t *)ha->hw.mbox;
2720 bzero(tcntxt, (sizeof (q80_tx_cntxt_destroy_t)));
2722 tcntxt->opcode = Q8_MBX_DESTROY_TX_CNTXT;
2723 tcntxt->count_version = (sizeof (q80_tx_cntxt_destroy_t) >> 2);
2724 tcntxt->count_version |= Q8_MBX_CMD_VERSION;
2726 tcntxt->cntxt_id = ha->hw.tx_cntxt[txr_idx].tx_cntxt_id;
2728 if (qla_mbx_cmd(ha, (uint32_t *)tcntxt,
2729 (sizeof (q80_tx_cntxt_destroy_t) >> 2),
2730 ha->hw.mbox, (sizeof (q80_tx_cntxt_destroy_rsp_t) >> 2), 0)) {
2731 device_printf(dev, "%s: failed0\n", __func__);
2734 tcntxt_rsp = (q80_tx_cntxt_destroy_rsp_t *)ha->hw.mbox;
2736 err = Q8_MBX_RSP_STATUS(tcntxt_rsp->regcnt_status);
2739 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2746 qla_del_xmt_cntxt(qla_host_t *ha)
2750 if (!ha->hw.flags.init_tx_cnxt)
2753 for (i = 0; i < ha->hw.num_tx_rings; i++) {
2754 if (qla_del_xmt_cntxt_i(ha, i))
2757 ha->hw.flags.init_tx_cnxt = 0;
2761 qla_init_xmt_cntxt(qla_host_t *ha)
2765 for (i = 0; i < ha->hw.num_tx_rings; i++) {
2766 if (qla_init_xmt_cntxt_i(ha, i) != 0) {
2767 for (j = 0; j < i; j++)
2768 qla_del_xmt_cntxt_i(ha, j);
2772 ha->hw.flags.init_tx_cnxt = 1;
2777 qla_hw_add_all_mcast(qla_host_t *ha)
2781 nmcast = ha->hw.nmcast;
2783 for (i = 0 ; ((i < Q8_MAX_NUM_MULTICAST_ADDRS) && nmcast); i++) {
2784 if ((ha->hw.mcast[i].addr[0] != 0) ||
2785 (ha->hw.mcast[i].addr[1] != 0) ||
2786 (ha->hw.mcast[i].addr[2] != 0) ||
2787 (ha->hw.mcast[i].addr[3] != 0) ||
2788 (ha->hw.mcast[i].addr[4] != 0) ||
2789 (ha->hw.mcast[i].addr[5] != 0)) {
2791 if (qla_config_mac_addr(ha, ha->hw.mcast[i].addr, 1)) {
2792 device_printf(ha->pci_dev, "%s: failed\n",
2804 qla_hw_del_all_mcast(qla_host_t *ha)
2808 nmcast = ha->hw.nmcast;
2810 for (i = 0 ; ((i < Q8_MAX_NUM_MULTICAST_ADDRS) && nmcast); i++) {
2811 if ((ha->hw.mcast[i].addr[0] != 0) ||
2812 (ha->hw.mcast[i].addr[1] != 0) ||
2813 (ha->hw.mcast[i].addr[2] != 0) ||
2814 (ha->hw.mcast[i].addr[3] != 0) ||
2815 (ha->hw.mcast[i].addr[4] != 0) ||
2816 (ha->hw.mcast[i].addr[5] != 0)) {
2818 if (qla_config_mac_addr(ha, ha->hw.mcast[i].addr, 0))
2828 qla_hw_add_mcast(qla_host_t *ha, uint8_t *mta)
2832 for (i = 0; i < Q8_MAX_NUM_MULTICAST_ADDRS; i++) {
2834 if (QL_MAC_CMP(ha->hw.mcast[i].addr, mta) == 0)
2835 return 0; /* its been already added */
2838 for (i = 0; i < Q8_MAX_NUM_MULTICAST_ADDRS; i++) {
2840 if ((ha->hw.mcast[i].addr[0] == 0) &&
2841 (ha->hw.mcast[i].addr[1] == 0) &&
2842 (ha->hw.mcast[i].addr[2] == 0) &&
2843 (ha->hw.mcast[i].addr[3] == 0) &&
2844 (ha->hw.mcast[i].addr[4] == 0) &&
2845 (ha->hw.mcast[i].addr[5] == 0)) {
2847 if (qla_config_mac_addr(ha, mta, 1))
2850 bcopy(mta, ha->hw.mcast[i].addr, Q8_MAC_ADDR_LEN);
2860 qla_hw_del_mcast(qla_host_t *ha, uint8_t *mta)
2864 for (i = 0; i < Q8_MAX_NUM_MULTICAST_ADDRS; i++) {
2865 if (QL_MAC_CMP(ha->hw.mcast[i].addr, mta) == 0) {
2867 if (qla_config_mac_addr(ha, mta, 0))
2870 ha->hw.mcast[i].addr[0] = 0;
2871 ha->hw.mcast[i].addr[1] = 0;
2872 ha->hw.mcast[i].addr[2] = 0;
2873 ha->hw.mcast[i].addr[3] = 0;
2874 ha->hw.mcast[i].addr[4] = 0;
2875 ha->hw.mcast[i].addr[5] = 0;
2886 * Name: ql_hw_set_multi
2887 * Function: Sets the Multicast Addresses provided the host O.S into the
2888 * hardware (for the given interface)
2891 ql_hw_set_multi(qla_host_t *ha, uint8_t *mcast, uint32_t mcnt,
2895 uint8_t *mta = mcast;
2898 for (i = 0; i < mcnt; i++) {
2900 ret = qla_hw_add_mcast(ha, mta);
2904 ret = qla_hw_del_mcast(ha, mta);
2909 mta += Q8_MAC_ADDR_LEN;
2915 * Name: qla_hw_tx_done_locked
2916 * Function: Handle Transmit Completions
2919 qla_hw_tx_done_locked(qla_host_t *ha, uint32_t txr_idx)
2922 qla_hw_t *hw = &ha->hw;
2923 uint32_t comp_idx, comp_count = 0;
2924 qla_hw_tx_cntxt_t *hw_tx_cntxt;
2926 hw_tx_cntxt = &hw->tx_cntxt[txr_idx];
2928 /* retrieve index of last entry in tx ring completed */
2929 comp_idx = qla_le32_to_host(*(hw_tx_cntxt->tx_cons));
2931 while (comp_idx != hw_tx_cntxt->txr_comp) {
2933 txb = &ha->tx_ring[txr_idx].tx_buf[hw_tx_cntxt->txr_comp];
2935 hw_tx_cntxt->txr_comp++;
2936 if (hw_tx_cntxt->txr_comp == NUM_TX_DESCRIPTORS)
2937 hw_tx_cntxt->txr_comp = 0;
2942 ha->ifp->if_opackets++;
2944 bus_dmamap_sync(ha->tx_tag, txb->map,
2945 BUS_DMASYNC_POSTWRITE);
2946 bus_dmamap_unload(ha->tx_tag, txb->map);
2947 m_freem(txb->m_head);
2953 hw_tx_cntxt->txr_free += comp_count;
2958 * Name: ql_hw_tx_done
2959 * Function: Handle Transmit Completions
2962 ql_hw_tx_done(qla_host_t *ha)
2967 if (!mtx_trylock(&ha->tx_lock)) {
2968 QL_DPRINT8(ha, (ha->pci_dev,
2969 "%s: !mtx_trylock(&ha->tx_lock)\n", __func__));
2972 for (i = 0; i < ha->hw.num_tx_rings; i++) {
2973 qla_hw_tx_done_locked(ha, i);
2974 if (ha->hw.tx_cntxt[i].txr_free <= (NUM_TX_DESCRIPTORS >> 1))
2979 ha->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2986 ql_update_link_state(qla_host_t *ha)
2988 uint32_t link_state;
2989 uint32_t prev_link_state;
2991 if (!(ha->ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2995 link_state = READ_REG32(ha, Q8_LINK_STATE);
2997 prev_link_state = ha->hw.link_up;
2999 if (ha->pci_func == 0)
3000 ha->hw.link_up = (((link_state & 0xF) == 1)? 1 : 0);
3002 ha->hw.link_up = ((((link_state >> 4)& 0xF) == 1)? 1 : 0);
3004 if (prev_link_state != ha->hw.link_up) {
3005 if (ha->hw.link_up) {
3006 if_link_state_change(ha->ifp, LINK_STATE_UP);
3008 if_link_state_change(ha->ifp, LINK_STATE_DOWN);
3015 ql_hw_stop_rcv(qla_host_t *ha)
3017 int i, done, count = 100;
3021 for (i = 0; i < ha->hw.num_sds_rings; i++) {
3022 if (ha->hw.sds[i].rcv_active)
3028 qla_mdelay(__func__, 10);
3032 device_printf(ha->pci_dev, "%s: Counter expired.\n", __func__);
3038 ql_hw_check_health(qla_host_t *ha)
3042 ha->hw.health_count++;
3044 if (ha->hw.health_count < 1000)
3047 ha->hw.health_count = 0;
3049 val = READ_REG32(ha, Q8_ASIC_TEMPERATURE);
3051 if (((val & 0xFFFF) == 2) || ((val & 0xFFFF) == 3) ||
3052 (QL_ERR_INJECT(ha, INJCT_TEMPERATURE_FAILURE))) {
3053 device_printf(ha->pci_dev, "%s: Temperature Alert [0x%08x]\n",
3058 val = READ_REG32(ha, Q8_FIRMWARE_HEARTBEAT);
3060 if ((val != ha->hw.hbeat_value) &&
3061 (!(QL_ERR_INJECT(ha, INJCT_HEARTBEAT_FAILURE)))) {
3062 ha->hw.hbeat_value = val;
3065 device_printf(ha->pci_dev, "%s: Heartbeat Failue [0x%08x]\n",
3072 qla_init_nic_func(qla_host_t *ha)
3075 q80_init_nic_func_t *init_nic;
3076 q80_init_nic_func_rsp_t *init_nic_rsp;
3081 init_nic = (q80_init_nic_func_t *)ha->hw.mbox;
3082 bzero(init_nic, sizeof(q80_init_nic_func_t));
3084 init_nic->opcode = Q8_MBX_INIT_NIC_FUNC;
3085 init_nic->count_version = (sizeof (q80_init_nic_func_t) >> 2);
3086 init_nic->count_version |= Q8_MBX_CMD_VERSION;
3088 init_nic->options = Q8_INIT_NIC_REG_DCBX_CHNG_AEN;
3089 init_nic->options |= Q8_INIT_NIC_REG_SFP_CHNG_AEN;
3090 init_nic->options |= Q8_INIT_NIC_REG_IDC_AEN;
3092 //qla_dump_buf8(ha, __func__, init_nic, sizeof (q80_init_nic_func_t));
3093 if (qla_mbx_cmd(ha, (uint32_t *)init_nic,
3094 (sizeof (q80_init_nic_func_t) >> 2),
3095 ha->hw.mbox, (sizeof (q80_init_nic_func_rsp_t) >> 2), 0)) {
3096 device_printf(dev, "%s: failed\n", __func__);
3100 init_nic_rsp = (q80_init_nic_func_rsp_t *)ha->hw.mbox;
3101 // qla_dump_buf8(ha, __func__, init_nic_rsp, sizeof (q80_init_nic_func_rsp_t));
3103 err = Q8_MBX_RSP_STATUS(init_nic_rsp->regcnt_status);
3106 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3113 qla_stop_nic_func(qla_host_t *ha)
3116 q80_stop_nic_func_t *stop_nic;
3117 q80_stop_nic_func_rsp_t *stop_nic_rsp;
3122 stop_nic = (q80_stop_nic_func_t *)ha->hw.mbox;
3123 bzero(stop_nic, sizeof(q80_stop_nic_func_t));
3125 stop_nic->opcode = Q8_MBX_STOP_NIC_FUNC;
3126 stop_nic->count_version = (sizeof (q80_stop_nic_func_t) >> 2);
3127 stop_nic->count_version |= Q8_MBX_CMD_VERSION;
3129 stop_nic->options = Q8_STOP_NIC_DEREG_DCBX_CHNG_AEN;
3130 stop_nic->options |= Q8_STOP_NIC_DEREG_SFP_CHNG_AEN;
3132 //qla_dump_buf8(ha, __func__, stop_nic, sizeof (q80_stop_nic_func_t));
3133 if (qla_mbx_cmd(ha, (uint32_t *)stop_nic,
3134 (sizeof (q80_stop_nic_func_t) >> 2),
3135 ha->hw.mbox, (sizeof (q80_stop_nic_func_rsp_t) >> 2), 0)) {
3136 device_printf(dev, "%s: failed\n", __func__);
3140 stop_nic_rsp = (q80_stop_nic_func_rsp_t *)ha->hw.mbox;
3141 //qla_dump_buf8(ha, __func__, stop_nic_rsp, sizeof (q80_stop_nic_func_rsp_ t));
3143 err = Q8_MBX_RSP_STATUS(stop_nic_rsp->regcnt_status);
3146 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3153 qla_query_fw_dcbx_caps(qla_host_t *ha)
3156 q80_query_fw_dcbx_caps_t *fw_dcbx;
3157 q80_query_fw_dcbx_caps_rsp_t *fw_dcbx_rsp;
3162 fw_dcbx = (q80_query_fw_dcbx_caps_t *)ha->hw.mbox;
3163 bzero(fw_dcbx, sizeof(q80_query_fw_dcbx_caps_t));
3165 fw_dcbx->opcode = Q8_MBX_GET_FW_DCBX_CAPS;
3166 fw_dcbx->count_version = (sizeof (q80_query_fw_dcbx_caps_t) >> 2);
3167 fw_dcbx->count_version |= Q8_MBX_CMD_VERSION;
3169 ql_dump_buf8(ha, __func__, fw_dcbx, sizeof (q80_query_fw_dcbx_caps_t));
3170 if (qla_mbx_cmd(ha, (uint32_t *)fw_dcbx,
3171 (sizeof (q80_query_fw_dcbx_caps_t) >> 2),
3172 ha->hw.mbox, (sizeof (q80_query_fw_dcbx_caps_rsp_t) >> 2), 0)) {
3173 device_printf(dev, "%s: failed\n", __func__);
3177 fw_dcbx_rsp = (q80_query_fw_dcbx_caps_rsp_t *)ha->hw.mbox;
3178 ql_dump_buf8(ha, __func__, fw_dcbx_rsp,
3179 sizeof (q80_query_fw_dcbx_caps_rsp_t));
3181 err = Q8_MBX_RSP_STATUS(fw_dcbx_rsp->regcnt_status);
3184 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3191 qla_idc_ack(qla_host_t *ha, uint32_t aen_mb1, uint32_t aen_mb2,
3192 uint32_t aen_mb3, uint32_t aen_mb4)
3195 q80_idc_ack_t *idc_ack;
3196 q80_idc_ack_rsp_t *idc_ack_rsp;
3202 idc_ack = (q80_idc_ack_t *)ha->hw.mbox;
3203 bzero(idc_ack, sizeof(q80_idc_ack_t));
3205 idc_ack->opcode = Q8_MBX_IDC_ACK;
3206 idc_ack->count_version = (sizeof (q80_idc_ack_t) >> 2);
3207 idc_ack->count_version |= Q8_MBX_CMD_VERSION;
3209 idc_ack->aen_mb1 = aen_mb1;
3210 idc_ack->aen_mb2 = aen_mb2;
3211 idc_ack->aen_mb3 = aen_mb3;
3212 idc_ack->aen_mb4 = aen_mb4;
3214 ha->hw.imd_compl= 0;
3216 if (qla_mbx_cmd(ha, (uint32_t *)idc_ack,
3217 (sizeof (q80_idc_ack_t) >> 2),
3218 ha->hw.mbox, (sizeof (q80_idc_ack_rsp_t) >> 2), 0)) {
3219 device_printf(dev, "%s: failed\n", __func__);
3223 idc_ack_rsp = (q80_idc_ack_rsp_t *)ha->hw.mbox;
3225 err = Q8_MBX_RSP_STATUS(idc_ack_rsp->regcnt_status);
3228 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3232 while (count && !ha->hw.imd_compl) {
3233 qla_mdelay(__func__, 100);
3240 device_printf(dev, "%s: count %d\n", __func__, count);
3246 qla_set_port_config(qla_host_t *ha, uint32_t cfg_bits)
3249 q80_set_port_cfg_t *pcfg;
3250 q80_set_port_cfg_rsp_t *pfg_rsp;
3256 pcfg = (q80_set_port_cfg_t *)ha->hw.mbox;
3257 bzero(pcfg, sizeof(q80_set_port_cfg_t));
3259 pcfg->opcode = Q8_MBX_SET_PORT_CONFIG;
3260 pcfg->count_version = (sizeof (q80_set_port_cfg_t) >> 2);
3261 pcfg->count_version |= Q8_MBX_CMD_VERSION;
3263 pcfg->cfg_bits = cfg_bits;
3265 device_printf(dev, "%s: cfg_bits"
3266 " [STD_PAUSE_DIR, PAUSE_TYPE, DCBX]"
3267 " [0x%x, 0x%x, 0x%x]\n", __func__,
3268 ((cfg_bits & Q8_PORT_CFG_BITS_STDPAUSE_DIR_MASK)>>20),
3269 ((cfg_bits & Q8_PORT_CFG_BITS_PAUSE_CFG_MASK) >> 5),
3270 ((cfg_bits & Q8_PORT_CFG_BITS_DCBX_ENABLE) ? 1: 0));
3272 ha->hw.imd_compl= 0;
3274 if (qla_mbx_cmd(ha, (uint32_t *)pcfg,
3275 (sizeof (q80_set_port_cfg_t) >> 2),
3276 ha->hw.mbox, (sizeof (q80_set_port_cfg_rsp_t) >> 2), 0)) {
3277 device_printf(dev, "%s: failed\n", __func__);
3281 pfg_rsp = (q80_set_port_cfg_rsp_t *)ha->hw.mbox;
3283 err = Q8_MBX_RSP_STATUS(pfg_rsp->regcnt_status);
3285 if (err == Q8_MBX_RSP_IDC_INTRMD_RSP) {
3286 while (count && !ha->hw.imd_compl) {
3287 qla_mdelay(__func__, 100);
3291 device_printf(dev, "%s: count %d\n", __func__, count);
3298 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3307 qla_get_minidump_tmplt_size(qla_host_t *ha, uint32_t *size)
3310 device_t dev = ha->pci_dev;
3311 q80_config_md_templ_size_t *md_size;
3312 q80_config_md_templ_size_rsp_t *md_size_rsp;
3314 #ifdef QL_LDFLASH_FW
3316 *size = ql83xx_minidump_len;
3319 #endif /* #ifdef QL_LDFLASH_FW */
3321 md_size = (q80_config_md_templ_size_t *) ha->hw.mbox;
3322 bzero(md_size, sizeof(q80_config_md_templ_size_t));
3324 md_size->opcode = Q8_MBX_GET_MINIDUMP_TMPLT_SIZE;
3325 md_size->count_version = (sizeof (q80_config_md_templ_size_t) >> 2);
3326 md_size->count_version |= Q8_MBX_CMD_VERSION;
3328 if (qla_mbx_cmd(ha, (uint32_t *) md_size,
3329 (sizeof(q80_config_md_templ_size_t) >> 2), ha->hw.mbox,
3330 (sizeof(q80_config_md_templ_size_rsp_t) >> 2), 0)) {
3332 device_printf(dev, "%s: failed\n", __func__);
3337 md_size_rsp = (q80_config_md_templ_size_rsp_t *) ha->hw.mbox;
3339 err = Q8_MBX_RSP_STATUS(md_size_rsp->regcnt_status);
3342 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3346 *size = md_size_rsp->templ_size;
3352 qla_get_port_config(qla_host_t *ha, uint32_t *cfg_bits)
3355 q80_get_port_cfg_t *pcfg;
3356 q80_get_port_cfg_rsp_t *pcfg_rsp;
3361 pcfg = (q80_get_port_cfg_t *)ha->hw.mbox;
3362 bzero(pcfg, sizeof(q80_get_port_cfg_t));
3364 pcfg->opcode = Q8_MBX_GET_PORT_CONFIG;
3365 pcfg->count_version = (sizeof (q80_get_port_cfg_t) >> 2);
3366 pcfg->count_version |= Q8_MBX_CMD_VERSION;
3368 if (qla_mbx_cmd(ha, (uint32_t *)pcfg,
3369 (sizeof (q80_get_port_cfg_t) >> 2),
3370 ha->hw.mbox, (sizeof (q80_get_port_cfg_rsp_t) >> 2), 0)) {
3371 device_printf(dev, "%s: failed\n", __func__);
3375 pcfg_rsp = (q80_get_port_cfg_rsp_t *)ha->hw.mbox;
3377 err = Q8_MBX_RSP_STATUS(pcfg_rsp->regcnt_status);
3380 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3384 device_printf(dev, "%s: [cfg_bits, port type]"
3385 " [0x%08x, 0x%02x] [STD_PAUSE_DIR, PAUSE_TYPE, DCBX]"
3386 " [0x%x, 0x%x, 0x%x]\n", __func__,
3387 pcfg_rsp->cfg_bits, pcfg_rsp->phys_port_type,
3388 ((pcfg_rsp->cfg_bits & Q8_PORT_CFG_BITS_STDPAUSE_DIR_MASK)>>20),
3389 ((pcfg_rsp->cfg_bits & Q8_PORT_CFG_BITS_PAUSE_CFG_MASK) >> 5),
3390 ((pcfg_rsp->cfg_bits & Q8_PORT_CFG_BITS_DCBX_ENABLE) ? 1: 0)
3393 *cfg_bits = pcfg_rsp->cfg_bits;
3399 qla_iscsi_pdu(qla_host_t *ha, struct mbuf *mp)
3401 struct ether_vlan_header *eh;
3403 struct ip *ip = NULL;
3404 struct ip6_hdr *ip6 = NULL;
3405 struct tcphdr *th = NULL;
3408 uint8_t buf[sizeof(struct ip6_hdr)];
3410 eh = mtod(mp, struct ether_vlan_header *);
3412 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3413 hdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3414 etype = ntohs(eh->evl_proto);
3416 hdrlen = ETHER_HDR_LEN;
3417 etype = ntohs(eh->evl_encap_proto);
3420 if (etype == ETHERTYPE_IP) {
3422 offset = (hdrlen + sizeof (struct ip));
3424 if (mp->m_len >= offset) {
3425 ip = (struct ip *)(mp->m_data + hdrlen);
3427 m_copydata(mp, hdrlen, sizeof (struct ip), buf);
3428 ip = (struct ip *)buf;
3431 if (ip->ip_p == IPPROTO_TCP) {
3433 hdrlen += ip->ip_hl << 2;
3434 offset = hdrlen + 4;
3436 if (mp->m_len >= offset) {
3437 th = (struct tcphdr *)(mp->m_data + hdrlen);;
3439 m_copydata(mp, hdrlen, 4, buf);
3440 th = (struct tcphdr *)buf;
3444 } else if (etype == ETHERTYPE_IPV6) {
3446 offset = (hdrlen + sizeof (struct ip6_hdr));
3448 if (mp->m_len >= offset) {
3449 ip6 = (struct ip6_hdr *)(mp->m_data + hdrlen);
3451 m_copydata(mp, hdrlen, sizeof (struct ip6_hdr), buf);
3452 ip6 = (struct ip6_hdr *)buf;
3455 if (ip6->ip6_nxt == IPPROTO_TCP) {
3457 hdrlen += sizeof(struct ip6_hdr);
3458 offset = hdrlen + 4;
3460 if (mp->m_len >= offset) {
3461 th = (struct tcphdr *)(mp->m_data + hdrlen);;
3463 m_copydata(mp, hdrlen, 4, buf);
3464 th = (struct tcphdr *)buf;
3470 if ((th->th_sport == htons(3260)) ||
3471 (th->th_dport == htons(3260)))
3478 qla_hw_async_event(qla_host_t *ha)
3480 switch (ha->hw.aen_mb0) {
3482 (void)qla_idc_ack(ha, ha->hw.aen_mb1, ha->hw.aen_mb2,
3483 ha->hw.aen_mb3, ha->hw.aen_mb4);
3494 #ifdef QL_LDFLASH_FW
3496 qla_get_minidump_template(qla_host_t *ha)
3499 device_t dev = ha->pci_dev;
3500 q80_config_md_templ_cmd_t *md_templ;
3501 q80_config_md_templ_cmd_rsp_t *md_templ_rsp;
3503 md_templ = (q80_config_md_templ_cmd_t *) ha->hw.mbox;
3504 bzero(md_templ, (sizeof (q80_config_md_templ_cmd_t)));
3506 md_templ->opcode = Q8_MBX_GET_MINIDUMP_TMPLT;
3507 md_templ->count_version = ( sizeof(q80_config_md_templ_cmd_t) >> 2);
3508 md_templ->count_version |= Q8_MBX_CMD_VERSION;
3510 md_templ->buf_addr = ha->hw.dma_buf.minidump.dma_addr;
3511 md_templ->buff_size = ha->hw.dma_buf.minidump.size;
3513 if (qla_mbx_cmd(ha, (uint32_t *) md_templ,
3514 (sizeof(q80_config_md_templ_cmd_t) >> 2),
3516 (sizeof(q80_config_md_templ_cmd_rsp_t) >> 2), 0)) {
3518 device_printf(dev, "%s: failed\n", __func__);
3523 md_templ_rsp = (q80_config_md_templ_cmd_rsp_t *) ha->hw.mbox;
3525 err = Q8_MBX_RSP_STATUS(md_templ_rsp->regcnt_status);
3528 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3535 #endif /* #ifdef QL_LDFLASH_FW */
3538 qla_minidump_init(qla_host_t *ha)
3541 uint32_t template_size = 0;
3542 device_t dev = ha->pci_dev;
3545 * Get Minidump Template Size
3547 ret = qla_get_minidump_tmplt_size(ha, &template_size);
3549 if (ret || (template_size == 0)) {
3550 device_printf(dev, "%s: failed [%d, %d]\n", __func__, ret,
3556 * Allocate Memory for Minidump Template
3559 ha->hw.dma_buf.minidump.alignment = 8;
3560 ha->hw.dma_buf.minidump.size = template_size;
3562 #ifdef QL_LDFLASH_FW
3563 if (ql_alloc_dmabuf(ha, &ha->hw.dma_buf.minidump)) {
3565 device_printf(dev, "%s: minidump dma alloc failed\n", __func__);
3569 ha->hw.dma_buf.flags.minidump = 1;
3572 * Retrieve Minidump Template
3574 ret = qla_get_minidump_template(ha);
3576 ha->hw.dma_buf.minidump.dma_b = ql83xx_minidump;
3577 #endif /* #ifdef QL_LDFLASH_FW */
3580 qla_minidump_free(ha);
3582 ha->hw.mdump_init = 1;
3590 qla_minidump_free(qla_host_t *ha)
3592 ha->hw.mdump_init = 0;
3593 if (ha->hw.dma_buf.flags.minidump) {
3594 ha->hw.dma_buf.flags.minidump = 0;
3595 ql_free_dmabuf(ha, &ha->hw.dma_buf.minidump);
3601 ql_minidump(qla_host_t *ha)
3603 uint32_t delay = 6000;
3605 if (!ha->hw.mdump_init)
3608 if (!ha->hw.mdump_active)
3611 if (ha->hw.mdump_active == 1) {
3612 ha->hw.mdump_start_seq_index = ql_stop_sequence(ha);
3613 ha->hw.mdump_start = 1;
3616 while (delay-- && ha->hw.mdump_active) {
3617 qla_mdelay(__func__, 100);
3619 ha->hw.mdump_start = 0;
3620 ql_start_sequence(ha, ha->hw.mdump_start_seq_index);