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");
390 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
391 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
392 OID_AUTO, "err_inject",
393 CTLFLAG_RW, &ha->err_inject, ha->err_inject,
394 "Error to be injected\n"
395 "\t\t\t 0: No Errors\n"
396 "\t\t\t 1: rcv: rxb struct invalid\n"
397 "\t\t\t 2: rcv: mp == NULL\n"
398 "\t\t\t 3: lro: rxb struct invalid\n"
399 "\t\t\t 4: lro: mp == NULL\n"
400 "\t\t\t 5: rcv: num handles invalid\n"
401 "\t\t\t 6: reg: indirect reg rd_wr failure\n"
402 "\t\t\t 7: ocm: offchip memory rd_wr failure\n"
403 "\t\t\t 8: mbx: mailbox command failure\n"
404 "\t\t\t 9: heartbeat failure\n"
405 "\t\t\t A: temperature failure\n" );
407 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
408 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
409 OID_AUTO, "peg_stop", CTLTYPE_INT | CTLFLAG_RW,
411 qla_sysctl_stop_pegs, "I", "Peg Stop");
413 #endif /* #ifdef QL_DBG */
415 ha->hw.user_pri_nic = 0;
416 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
417 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
418 OID_AUTO, "user_pri_nic", CTLFLAG_RW, &ha->hw.user_pri_nic,
420 "VLAN Tag User Priority for Normal Ethernet Packets");
422 ha->hw.user_pri_iscsi = 4;
423 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
424 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
425 OID_AUTO, "user_pri_iscsi", CTLFLAG_RW, &ha->hw.user_pri_iscsi,
426 ha->hw.user_pri_iscsi,
427 "VLAN Tag User Priority for iSCSI Packets");
432 ql_hw_link_status(qla_host_t *ha)
434 device_printf(ha->pci_dev, "cable_oui\t\t 0x%08x\n", ha->hw.cable_oui);
436 if (ha->hw.link_up) {
437 device_printf(ha->pci_dev, "link Up\n");
439 device_printf(ha->pci_dev, "link Down\n");
442 if (ha->hw.flags.fduplex) {
443 device_printf(ha->pci_dev, "Full Duplex\n");
445 device_printf(ha->pci_dev, "Half Duplex\n");
448 if (ha->hw.flags.autoneg) {
449 device_printf(ha->pci_dev, "Auto Negotiation Enabled\n");
451 device_printf(ha->pci_dev, "Auto Negotiation Disabled\n");
454 switch (ha->hw.link_speed) {
456 device_printf(ha->pci_dev, "link speed\t\t 10Gps\n");
460 device_printf(ha->pci_dev, "link speed\t\t 1Gps\n");
464 device_printf(ha->pci_dev, "link speed\t\t 100Mbps\n");
468 device_printf(ha->pci_dev, "link speed\t\t Unknown\n");
472 switch (ha->hw.module_type) {
475 device_printf(ha->pci_dev, "Module Type 10GBase-LRM\n");
479 device_printf(ha->pci_dev, "Module Type 10GBase-LR\n");
483 device_printf(ha->pci_dev, "Module Type 10GBase-SR\n");
487 device_printf(ha->pci_dev,
488 "Module Type 10GE Passive Copper(Compliant)[%d m]\n",
489 ha->hw.cable_length);
493 device_printf(ha->pci_dev, "Module Type 10GE Active"
494 " Limiting Copper(Compliant)[%d m]\n",
495 ha->hw.cable_length);
499 device_printf(ha->pci_dev,
500 "Module Type 10GE Passive Copper"
501 " (Legacy, Best Effort)[%d m]\n",
502 ha->hw.cable_length);
506 device_printf(ha->pci_dev, "Module Type 1000Base-SX\n");
510 device_printf(ha->pci_dev, "Module Type 1000Base-LX\n");
514 device_printf(ha->pci_dev, "Module Type 1000Base-CX\n");
518 device_printf(ha->pci_dev, "Module Type 1000Base-T\n");
522 device_printf(ha->pci_dev, "Module Type 1GE Passive Copper"
523 "(Legacy, Best Effort)\n");
527 device_printf(ha->pci_dev, "Unknown Module Type 0x%x\n",
532 if (ha->hw.link_faults == 1)
533 device_printf(ha->pci_dev, "SFP Power Fault\n");
538 * Function: Frees the DMA'able memory allocated in ql_alloc_dma()
541 ql_free_dma(qla_host_t *ha)
545 if (ha->hw.dma_buf.flags.sds_ring) {
546 for (i = 0; i < ha->hw.num_sds_rings; i++) {
547 ql_free_dmabuf(ha, &ha->hw.dma_buf.sds_ring[i]);
549 ha->hw.dma_buf.flags.sds_ring = 0;
552 if (ha->hw.dma_buf.flags.rds_ring) {
553 for (i = 0; i < ha->hw.num_rds_rings; i++) {
554 ql_free_dmabuf(ha, &ha->hw.dma_buf.rds_ring[i]);
556 ha->hw.dma_buf.flags.rds_ring = 0;
559 if (ha->hw.dma_buf.flags.tx_ring) {
560 ql_free_dmabuf(ha, &ha->hw.dma_buf.tx_ring);
561 ha->hw.dma_buf.flags.tx_ring = 0;
563 qla_minidump_free(ha);
568 * Function: Allocates DMA'able memory for Tx/Rx Rings, Tx/Rx Contexts.
571 ql_alloc_dma(qla_host_t *ha)
574 uint32_t i, j, size, tx_ring_size;
576 qla_hw_tx_cntxt_t *tx_cntxt;
582 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__));
586 * Allocate Transmit Ring
588 tx_ring_size = (sizeof(q80_tx_cmd_t) * NUM_TX_DESCRIPTORS);
589 size = (tx_ring_size * ha->hw.num_tx_rings);
591 hw->dma_buf.tx_ring.alignment = 8;
592 hw->dma_buf.tx_ring.size = size + PAGE_SIZE;
594 if (ql_alloc_dmabuf(ha, &hw->dma_buf.tx_ring)) {
595 device_printf(dev, "%s: tx ring alloc failed\n", __func__);
596 goto ql_alloc_dma_exit;
599 vaddr = (uint8_t *)hw->dma_buf.tx_ring.dma_b;
600 paddr = hw->dma_buf.tx_ring.dma_addr;
602 for (i = 0; i < ha->hw.num_tx_rings; i++) {
603 tx_cntxt = (qla_hw_tx_cntxt_t *)&hw->tx_cntxt[i];
605 tx_cntxt->tx_ring_base = (q80_tx_cmd_t *)vaddr;
606 tx_cntxt->tx_ring_paddr = paddr;
608 vaddr += tx_ring_size;
609 paddr += tx_ring_size;
612 for (i = 0; i < ha->hw.num_tx_rings; i++) {
613 tx_cntxt = (qla_hw_tx_cntxt_t *)&hw->tx_cntxt[i];
615 tx_cntxt->tx_cons = (uint32_t *)vaddr;
616 tx_cntxt->tx_cons_paddr = paddr;
618 vaddr += sizeof (uint32_t);
619 paddr += sizeof (uint32_t);
622 ha->hw.dma_buf.flags.tx_ring = 1;
624 QL_DPRINT2(ha, (dev, "%s: tx_ring phys %p virt %p\n",
625 __func__, (void *)(hw->dma_buf.tx_ring.dma_addr),
626 hw->dma_buf.tx_ring.dma_b));
628 * Allocate Receive Descriptor Rings
631 for (i = 0; i < hw->num_rds_rings; i++) {
633 hw->dma_buf.rds_ring[i].alignment = 8;
634 hw->dma_buf.rds_ring[i].size =
635 (sizeof(q80_recv_desc_t)) * NUM_RX_DESCRIPTORS;
637 if (ql_alloc_dmabuf(ha, &hw->dma_buf.rds_ring[i])) {
638 device_printf(dev, "%s: rds ring[%d] alloc failed\n",
641 for (j = 0; j < i; j++)
642 ql_free_dmabuf(ha, &hw->dma_buf.rds_ring[j]);
644 goto ql_alloc_dma_exit;
646 QL_DPRINT4(ha, (dev, "%s: rx_ring[%d] phys %p virt %p\n",
647 __func__, i, (void *)(hw->dma_buf.rds_ring[i].dma_addr),
648 hw->dma_buf.rds_ring[i].dma_b));
651 hw->dma_buf.flags.rds_ring = 1;
654 * Allocate Status Descriptor Rings
657 for (i = 0; i < hw->num_sds_rings; i++) {
658 hw->dma_buf.sds_ring[i].alignment = 8;
659 hw->dma_buf.sds_ring[i].size =
660 (sizeof(q80_stat_desc_t)) * NUM_STATUS_DESCRIPTORS;
662 if (ql_alloc_dmabuf(ha, &hw->dma_buf.sds_ring[i])) {
663 device_printf(dev, "%s: sds ring alloc failed\n",
666 for (j = 0; j < i; j++)
667 ql_free_dmabuf(ha, &hw->dma_buf.sds_ring[j]);
669 goto ql_alloc_dma_exit;
671 QL_DPRINT4(ha, (dev, "%s: sds_ring[%d] phys %p virt %p\n",
673 (void *)(hw->dma_buf.sds_ring[i].dma_addr),
674 hw->dma_buf.sds_ring[i].dma_b));
676 for (i = 0; i < hw->num_sds_rings; i++) {
677 hw->sds[i].sds_ring_base =
678 (q80_stat_desc_t *)hw->dma_buf.sds_ring[i].dma_b;
681 hw->dma_buf.flags.sds_ring = 1;
690 #define Q8_MBX_MSEC_DELAY 5000
693 qla_mbx_cmd(qla_host_t *ha, uint32_t *h_mbox, uint32_t n_hmbox,
694 uint32_t *fw_mbox, uint32_t n_fwmbox, uint32_t no_pause)
700 if (QL_ERR_INJECT(ha, INJCT_MBX_CMD_FAILURE)) {
702 ha->qla_initiate_recovery = 1;
703 goto exit_qla_mbx_cmd;
709 i = Q8_MBX_MSEC_DELAY;
712 data = READ_REG32(ha, Q8_HOST_MBOX_CNTRL);
718 qla_mdelay(__func__, 1);
724 device_printf(ha->pci_dev, "%s: host_mbx_cntrl 0x%08x\n",
727 ha->qla_initiate_recovery = 1;
728 goto exit_qla_mbx_cmd;
731 for (i = 0; i < n_hmbox; i++) {
732 WRITE_REG32(ha, (Q8_HOST_MBOX0 + (i << 2)), *h_mbox);
736 WRITE_REG32(ha, Q8_HOST_MBOX_CNTRL, 0x1);
739 i = Q8_MBX_MSEC_DELAY;
741 data = READ_REG32(ha, Q8_FW_MBOX_CNTRL);
743 if ((data & 0x3) == 1) {
744 data = READ_REG32(ha, Q8_FW_MBOX0);
745 if ((data & 0xF000) != 0x8000)
751 qla_mdelay(__func__, 1);
756 device_printf(ha->pci_dev, "%s: fw_mbx_cntrl 0x%08x\n",
759 ha->qla_initiate_recovery = 1;
760 goto exit_qla_mbx_cmd;
763 for (i = 0; i < n_fwmbox; i++) {
764 *fw_mbox++ = READ_REG32(ha, (Q8_FW_MBOX0 + (i << 2)));
767 WRITE_REG32(ha, Q8_FW_MBOX_CNTRL, 0x0);
768 WRITE_REG32(ha, ha->hw.mbx_intr_mask_offset, 0x0);
775 qla_get_nic_partition(qla_host_t *ha, uint32_t *supports_9kb,
779 device_t dev = ha->pci_dev;
781 bzero(ha->hw.mbox, (sizeof (uint32_t) * Q8_NUM_MBOX));
785 mbox[0] = Q8_MBX_GET_NIC_PARTITION | (0x2 << 16) | (0x2 << 29);
787 if (qla_mbx_cmd(ha, mbox, 2, mbox, 19, 0)) {
788 device_printf(dev, "%s: failed0\n", __func__);
793 if (supports_9kb != NULL) {
794 if (mbox[16] & 0x80) /* bit 7 of mbox 16 */
800 if (num_rcvq != NULL)
801 *num_rcvq = ((mbox[6] >> 16) & 0xFFFF);
803 if ((err != 1) && (err != 0)) {
804 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
811 qla_config_intr_cntxt(qla_host_t *ha, uint32_t start_idx, uint32_t num_intrs,
815 device_t dev = ha->pci_dev;
816 q80_config_intr_t *c_intr;
817 q80_config_intr_rsp_t *c_intr_rsp;
819 c_intr = (q80_config_intr_t *)ha->hw.mbox;
820 bzero(c_intr, (sizeof (q80_config_intr_t)));
822 c_intr->opcode = Q8_MBX_CONFIG_INTR;
824 c_intr->count_version = (sizeof (q80_config_intr_t) >> 2);
825 c_intr->count_version |= Q8_MBX_CMD_VERSION;
827 c_intr->nentries = num_intrs;
829 for (i = 0; i < num_intrs; i++) {
831 c_intr->intr[i].cmd_type = Q8_MBX_CONFIG_INTR_CREATE;
832 c_intr->intr[i].msix_index = start_idx + 1 + i;
834 c_intr->intr[i].cmd_type = Q8_MBX_CONFIG_INTR_DELETE;
835 c_intr->intr[i].msix_index =
836 ha->hw.intr_id[(start_idx + i)];
839 c_intr->intr[i].cmd_type |= Q8_MBX_CONFIG_INTR_TYPE_MSI_X;
842 if (qla_mbx_cmd(ha, (uint32_t *)c_intr,
843 (sizeof (q80_config_intr_t) >> 2),
844 ha->hw.mbox, (sizeof (q80_config_intr_rsp_t) >> 2), 0)) {
845 device_printf(dev, "%s: failed0\n", __func__);
849 c_intr_rsp = (q80_config_intr_rsp_t *)ha->hw.mbox;
851 err = Q8_MBX_RSP_STATUS(c_intr_rsp->regcnt_status);
854 device_printf(dev, "%s: failed1 [0x%08x, %d]\n", __func__, err,
855 c_intr_rsp->nentries);
857 for (i = 0; i < c_intr_rsp->nentries; i++) {
858 device_printf(dev, "%s: [%d]:[0x%x 0x%x 0x%x]\n",
860 c_intr_rsp->intr[i].status,
861 c_intr_rsp->intr[i].intr_id,
862 c_intr_rsp->intr[i].intr_src);
868 for (i = 0; ((i < num_intrs) && create); i++) {
869 if (!c_intr_rsp->intr[i].status) {
870 ha->hw.intr_id[(start_idx + i)] =
871 c_intr_rsp->intr[i].intr_id;
872 ha->hw.intr_src[(start_idx + i)] =
873 c_intr_rsp->intr[i].intr_src;
881 * Name: qla_config_rss
882 * Function: Configure RSS for the context/interface.
884 static const uint64_t rss_key[] = { 0xbeac01fa6a42b73bULL,
885 0x8030f20c77cb2da3ULL,
886 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
887 0x255b0ec26d5a56daULL };
890 qla_config_rss(qla_host_t *ha, uint16_t cntxt_id)
892 q80_config_rss_t *c_rss;
893 q80_config_rss_rsp_t *c_rss_rsp;
895 device_t dev = ha->pci_dev;
897 c_rss = (q80_config_rss_t *)ha->hw.mbox;
898 bzero(c_rss, (sizeof (q80_config_rss_t)));
900 c_rss->opcode = Q8_MBX_CONFIG_RSS;
902 c_rss->count_version = (sizeof (q80_config_rss_t) >> 2);
903 c_rss->count_version |= Q8_MBX_CMD_VERSION;
905 c_rss->hash_type = (Q8_MBX_RSS_HASH_TYPE_IPV4_TCP_IP |
906 Q8_MBX_RSS_HASH_TYPE_IPV6_TCP_IP);
907 //c_rss->hash_type = (Q8_MBX_RSS_HASH_TYPE_IPV4_TCP |
908 // Q8_MBX_RSS_HASH_TYPE_IPV6_TCP);
910 c_rss->flags = Q8_MBX_RSS_FLAGS_ENABLE_RSS;
911 c_rss->flags |= Q8_MBX_RSS_FLAGS_USE_IND_TABLE;
913 c_rss->indtbl_mask = Q8_MBX_RSS_INDTBL_MASK;
915 c_rss->indtbl_mask |= Q8_MBX_RSS_FLAGS_MULTI_RSS_VALID;
916 c_rss->flags |= Q8_MBX_RSS_FLAGS_TYPE_CRSS;
918 c_rss->cntxt_id = cntxt_id;
920 for (i = 0; i < 5; i++) {
921 c_rss->rss_key[i] = rss_key[i];
924 if (qla_mbx_cmd(ha, (uint32_t *)c_rss,
925 (sizeof (q80_config_rss_t) >> 2),
926 ha->hw.mbox, (sizeof(q80_config_rss_rsp_t) >> 2), 0)) {
927 device_printf(dev, "%s: failed0\n", __func__);
930 c_rss_rsp = (q80_config_rss_rsp_t *)ha->hw.mbox;
932 err = Q8_MBX_RSP_STATUS(c_rss_rsp->regcnt_status);
935 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
942 qla_set_rss_ind_table(qla_host_t *ha, uint32_t start_idx, uint32_t count,
943 uint16_t cntxt_id, uint8_t *ind_table)
945 q80_config_rss_ind_table_t *c_rss_ind;
946 q80_config_rss_ind_table_rsp_t *c_rss_ind_rsp;
948 device_t dev = ha->pci_dev;
950 if ((count > Q8_RSS_IND_TBL_SIZE) ||
951 ((start_idx + count - 1) > Q8_RSS_IND_TBL_MAX_IDX)) {
952 device_printf(dev, "%s: illegal count [%d, %d]\n", __func__,
957 c_rss_ind = (q80_config_rss_ind_table_t *)ha->hw.mbox;
958 bzero(c_rss_ind, sizeof (q80_config_rss_ind_table_t));
960 c_rss_ind->opcode = Q8_MBX_CONFIG_RSS_TABLE;
961 c_rss_ind->count_version = (sizeof (q80_config_rss_ind_table_t) >> 2);
962 c_rss_ind->count_version |= Q8_MBX_CMD_VERSION;
964 c_rss_ind->start_idx = start_idx;
965 c_rss_ind->end_idx = start_idx + count - 1;
966 c_rss_ind->cntxt_id = cntxt_id;
967 bcopy(ind_table, c_rss_ind->ind_table, count);
969 if (qla_mbx_cmd(ha, (uint32_t *)c_rss_ind,
970 (sizeof (q80_config_rss_ind_table_t) >> 2), ha->hw.mbox,
971 (sizeof(q80_config_rss_ind_table_rsp_t) >> 2), 0)) {
972 device_printf(dev, "%s: failed0\n", __func__);
976 c_rss_ind_rsp = (q80_config_rss_ind_table_rsp_t *)ha->hw.mbox;
977 err = Q8_MBX_RSP_STATUS(c_rss_ind_rsp->regcnt_status);
980 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
987 * Name: qla_config_intr_coalesce
988 * Function: Configure Interrupt Coalescing.
991 qla_config_intr_coalesce(qla_host_t *ha, uint16_t cntxt_id, int tenable,
994 q80_config_intr_coalesc_t *intrc;
995 q80_config_intr_coalesc_rsp_t *intrc_rsp;
997 device_t dev = ha->pci_dev;
999 intrc = (q80_config_intr_coalesc_t *)ha->hw.mbox;
1000 bzero(intrc, (sizeof (q80_config_intr_coalesc_t)));
1002 intrc->opcode = Q8_MBX_CONFIG_INTR_COALESCE;
1003 intrc->count_version = (sizeof (q80_config_intr_coalesc_t) >> 2);
1004 intrc->count_version |= Q8_MBX_CMD_VERSION;
1007 intrc->flags = Q8_MBX_INTRC_FLAGS_RCV;
1008 intrc->max_pkts = ha->hw.rcv_intr_coalesce & 0xFFFF;
1009 intrc->max_mswait = (ha->hw.rcv_intr_coalesce >> 16) & 0xFFFF;
1011 intrc->flags = Q8_MBX_INTRC_FLAGS_XMT;
1012 intrc->max_pkts = ha->hw.xmt_intr_coalesce & 0xFFFF;
1013 intrc->max_mswait = (ha->hw.xmt_intr_coalesce >> 16) & 0xFFFF;
1016 intrc->cntxt_id = cntxt_id;
1019 intrc->flags |= Q8_MBX_INTRC_FLAGS_PERIODIC;
1020 intrc->timer_type = Q8_MBX_INTRC_TIMER_PERIODIC;
1022 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1023 intrc->sds_ring_mask |= (1 << i);
1025 intrc->ms_timeout = 1000;
1028 if (qla_mbx_cmd(ha, (uint32_t *)intrc,
1029 (sizeof (q80_config_intr_coalesc_t) >> 2),
1030 ha->hw.mbox, (sizeof(q80_config_intr_coalesc_rsp_t) >> 2), 0)) {
1031 device_printf(dev, "%s: failed0\n", __func__);
1034 intrc_rsp = (q80_config_intr_coalesc_rsp_t *)ha->hw.mbox;
1036 err = Q8_MBX_RSP_STATUS(intrc_rsp->regcnt_status);
1039 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
1048 * Name: qla_config_mac_addr
1049 * Function: binds a MAC address to the context/interface.
1050 * Can be unicast, multicast or broadcast.
1053 qla_config_mac_addr(qla_host_t *ha, uint8_t *mac_addr, uint32_t add_mac)
1055 q80_config_mac_addr_t *cmac;
1056 q80_config_mac_addr_rsp_t *cmac_rsp;
1058 device_t dev = ha->pci_dev;
1060 cmac = (q80_config_mac_addr_t *)ha->hw.mbox;
1061 bzero(cmac, (sizeof (q80_config_mac_addr_t)));
1063 cmac->opcode = Q8_MBX_CONFIG_MAC_ADDR;
1064 cmac->count_version = sizeof (q80_config_mac_addr_t) >> 2;
1065 cmac->count_version |= Q8_MBX_CMD_VERSION;
1068 cmac->cmd = Q8_MBX_CMAC_CMD_ADD_MAC_ADDR;
1070 cmac->cmd = Q8_MBX_CMAC_CMD_DEL_MAC_ADDR;
1072 cmac->cmd |= Q8_MBX_CMAC_CMD_CAM_INGRESS;
1074 cmac->nmac_entries = 1;
1075 cmac->cntxt_id = ha->hw.rcv_cntxt_id;
1076 bcopy(mac_addr, cmac->mac_addr[0].addr, 6);
1078 if (qla_mbx_cmd(ha, (uint32_t *)cmac,
1079 (sizeof (q80_config_mac_addr_t) >> 2),
1080 ha->hw.mbox, (sizeof(q80_config_mac_addr_rsp_t) >> 2), 1)) {
1081 device_printf(dev, "%s: %s failed0\n", __func__,
1082 (add_mac ? "Add" : "Del"));
1085 cmac_rsp = (q80_config_mac_addr_rsp_t *)ha->hw.mbox;
1087 err = Q8_MBX_RSP_STATUS(cmac_rsp->regcnt_status);
1090 device_printf(dev, "%s: %s "
1091 "%02x:%02x:%02x:%02x:%02x:%02x failed1 [0x%08x]\n",
1092 __func__, (add_mac ? "Add" : "Del"),
1093 mac_addr[0], mac_addr[1], mac_addr[2],
1094 mac_addr[3], mac_addr[4], mac_addr[5], err);
1103 * Name: qla_set_mac_rcv_mode
1104 * Function: Enable/Disable AllMulticast and Promiscous Modes.
1107 qla_set_mac_rcv_mode(qla_host_t *ha, uint32_t mode)
1109 q80_config_mac_rcv_mode_t *rcv_mode;
1111 q80_config_mac_rcv_mode_rsp_t *rcv_mode_rsp;
1112 device_t dev = ha->pci_dev;
1114 rcv_mode = (q80_config_mac_rcv_mode_t *)ha->hw.mbox;
1115 bzero(rcv_mode, (sizeof (q80_config_mac_rcv_mode_t)));
1117 rcv_mode->opcode = Q8_MBX_CONFIG_MAC_RX_MODE;
1118 rcv_mode->count_version = sizeof (q80_config_mac_rcv_mode_t) >> 2;
1119 rcv_mode->count_version |= Q8_MBX_CMD_VERSION;
1121 rcv_mode->mode = mode;
1123 rcv_mode->cntxt_id = ha->hw.rcv_cntxt_id;
1125 if (qla_mbx_cmd(ha, (uint32_t *)rcv_mode,
1126 (sizeof (q80_config_mac_rcv_mode_t) >> 2),
1127 ha->hw.mbox, (sizeof(q80_config_mac_rcv_mode_rsp_t) >> 2), 1)) {
1128 device_printf(dev, "%s: failed0\n", __func__);
1131 rcv_mode_rsp = (q80_config_mac_rcv_mode_rsp_t *)ha->hw.mbox;
1133 err = Q8_MBX_RSP_STATUS(rcv_mode_rsp->regcnt_status);
1136 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
1144 ql_set_promisc(qla_host_t *ha)
1148 ha->hw.mac_rcv_mode |= Q8_MBX_MAC_RCV_PROMISC_ENABLE;
1149 ret = qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode);
1154 qla_reset_promisc(qla_host_t *ha)
1156 ha->hw.mac_rcv_mode &= ~Q8_MBX_MAC_RCV_PROMISC_ENABLE;
1157 (void)qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode);
1161 ql_set_allmulti(qla_host_t *ha)
1165 ha->hw.mac_rcv_mode |= Q8_MBX_MAC_ALL_MULTI_ENABLE;
1166 ret = qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode);
1171 qla_reset_allmulti(qla_host_t *ha)
1173 ha->hw.mac_rcv_mode &= ~Q8_MBX_MAC_ALL_MULTI_ENABLE;
1174 (void)qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode);
1178 * Name: ql_set_max_mtu
1180 * Sets the maximum transfer unit size for the specified rcv context.
1183 ql_set_max_mtu(qla_host_t *ha, uint32_t mtu, uint16_t cntxt_id)
1186 q80_set_max_mtu_t *max_mtu;
1187 q80_set_max_mtu_rsp_t *max_mtu_rsp;
1192 max_mtu = (q80_set_max_mtu_t *)ha->hw.mbox;
1193 bzero(max_mtu, (sizeof (q80_set_max_mtu_t)));
1195 max_mtu->opcode = Q8_MBX_SET_MAX_MTU;
1196 max_mtu->count_version = (sizeof (q80_set_max_mtu_t) >> 2);
1197 max_mtu->count_version |= Q8_MBX_CMD_VERSION;
1199 max_mtu->cntxt_id = cntxt_id;
1202 if (qla_mbx_cmd(ha, (uint32_t *)max_mtu,
1203 (sizeof (q80_set_max_mtu_t) >> 2),
1204 ha->hw.mbox, (sizeof (q80_set_max_mtu_rsp_t) >> 2), 1)) {
1205 device_printf(dev, "%s: failed\n", __func__);
1209 max_mtu_rsp = (q80_set_max_mtu_rsp_t *)ha->hw.mbox;
1211 err = Q8_MBX_RSP_STATUS(max_mtu_rsp->regcnt_status);
1214 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
1221 qla_link_event_req(qla_host_t *ha, uint16_t cntxt_id)
1224 q80_link_event_t *lnk;
1225 q80_link_event_rsp_t *lnk_rsp;
1230 lnk = (q80_link_event_t *)ha->hw.mbox;
1231 bzero(lnk, (sizeof (q80_link_event_t)));
1233 lnk->opcode = Q8_MBX_LINK_EVENT_REQ;
1234 lnk->count_version = (sizeof (q80_link_event_t) >> 2);
1235 lnk->count_version |= Q8_MBX_CMD_VERSION;
1237 lnk->cntxt_id = cntxt_id;
1238 lnk->cmd = Q8_LINK_EVENT_CMD_ENABLE_ASYNC;
1240 if (qla_mbx_cmd(ha, (uint32_t *)lnk, (sizeof (q80_link_event_t) >> 2),
1241 ha->hw.mbox, (sizeof (q80_link_event_rsp_t) >> 2), 0)) {
1242 device_printf(dev, "%s: failed\n", __func__);
1246 lnk_rsp = (q80_link_event_rsp_t *)ha->hw.mbox;
1248 err = Q8_MBX_RSP_STATUS(lnk_rsp->regcnt_status);
1251 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
1258 qla_config_fw_lro(qla_host_t *ha, uint16_t cntxt_id)
1261 q80_config_fw_lro_t *fw_lro;
1262 q80_config_fw_lro_rsp_t *fw_lro_rsp;
1267 fw_lro = (q80_config_fw_lro_t *)ha->hw.mbox;
1268 bzero(fw_lro, sizeof(q80_config_fw_lro_t));
1270 fw_lro->opcode = Q8_MBX_CONFIG_FW_LRO;
1271 fw_lro->count_version = (sizeof (q80_config_fw_lro_t) >> 2);
1272 fw_lro->count_version |= Q8_MBX_CMD_VERSION;
1274 fw_lro->flags |= Q8_MBX_FW_LRO_IPV4 | Q8_MBX_FW_LRO_IPV4_WO_DST_IP_CHK;
1275 fw_lro->flags |= Q8_MBX_FW_LRO_IPV6 | Q8_MBX_FW_LRO_IPV6_WO_DST_IP_CHK;
1277 fw_lro->cntxt_id = cntxt_id;
1279 if (qla_mbx_cmd(ha, (uint32_t *)fw_lro,
1280 (sizeof (q80_config_fw_lro_t) >> 2),
1281 ha->hw.mbox, (sizeof (q80_config_fw_lro_rsp_t) >> 2), 0)) {
1282 device_printf(dev, "%s: failed\n", __func__);
1286 fw_lro_rsp = (q80_config_fw_lro_rsp_t *)ha->hw.mbox;
1288 err = Q8_MBX_RSP_STATUS(fw_lro_rsp->regcnt_status);
1291 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
1298 qla_xmt_stats(qla_host_t *ha, q80_xmt_stats_t *xstat, int i)
1300 device_t dev = ha->pci_dev;
1302 if (i < ha->hw.num_tx_rings) {
1303 device_printf(dev, "%s[%d]: total_bytes\t\t%" PRIu64 "\n",
1304 __func__, i, xstat->total_bytes);
1305 device_printf(dev, "%s[%d]: total_pkts\t\t%" PRIu64 "\n",
1306 __func__, i, xstat->total_pkts);
1307 device_printf(dev, "%s[%d]: errors\t\t%" PRIu64 "\n",
1308 __func__, i, xstat->errors);
1309 device_printf(dev, "%s[%d]: pkts_dropped\t%" PRIu64 "\n",
1310 __func__, i, xstat->pkts_dropped);
1311 device_printf(dev, "%s[%d]: switch_pkts\t\t%" PRIu64 "\n",
1312 __func__, i, xstat->switch_pkts);
1313 device_printf(dev, "%s[%d]: num_buffers\t\t%" PRIu64 "\n",
1314 __func__, i, xstat->num_buffers);
1316 device_printf(dev, "%s: total_bytes\t\t\t%" PRIu64 "\n",
1317 __func__, xstat->total_bytes);
1318 device_printf(dev, "%s: total_pkts\t\t\t%" PRIu64 "\n",
1319 __func__, xstat->total_pkts);
1320 device_printf(dev, "%s: errors\t\t\t%" PRIu64 "\n",
1321 __func__, xstat->errors);
1322 device_printf(dev, "%s: pkts_dropped\t\t\t%" PRIu64 "\n",
1323 __func__, xstat->pkts_dropped);
1324 device_printf(dev, "%s: switch_pkts\t\t\t%" PRIu64 "\n",
1325 __func__, xstat->switch_pkts);
1326 device_printf(dev, "%s: num_buffers\t\t\t%" PRIu64 "\n",
1327 __func__, xstat->num_buffers);
1332 qla_rcv_stats(qla_host_t *ha, q80_rcv_stats_t *rstat)
1334 device_t dev = ha->pci_dev;
1336 device_printf(dev, "%s: total_bytes\t\t\t%" PRIu64 "\n", __func__,
1337 rstat->total_bytes);
1338 device_printf(dev, "%s: total_pkts\t\t\t%" PRIu64 "\n", __func__,
1340 device_printf(dev, "%s: lro_pkt_count\t\t%" PRIu64 "\n", __func__,
1341 rstat->lro_pkt_count);
1342 device_printf(dev, "%s: sw_pkt_count\t\t\t%" PRIu64 "\n", __func__,
1343 rstat->sw_pkt_count);
1344 device_printf(dev, "%s: ip_chksum_err\t\t%" PRIu64 "\n", __func__,
1345 rstat->ip_chksum_err);
1346 device_printf(dev, "%s: pkts_wo_acntxts\t\t%" PRIu64 "\n", __func__,
1347 rstat->pkts_wo_acntxts);
1348 device_printf(dev, "%s: pkts_dropped_no_sds_card\t%" PRIu64 "\n",
1349 __func__, rstat->pkts_dropped_no_sds_card);
1350 device_printf(dev, "%s: pkts_dropped_no_sds_host\t%" PRIu64 "\n",
1351 __func__, rstat->pkts_dropped_no_sds_host);
1352 device_printf(dev, "%s: oversized_pkts\t\t%" PRIu64 "\n", __func__,
1353 rstat->oversized_pkts);
1354 device_printf(dev, "%s: pkts_dropped_no_rds\t\t%" PRIu64 "\n",
1355 __func__, rstat->pkts_dropped_no_rds);
1356 device_printf(dev, "%s: unxpctd_mcast_pkts\t\t%" PRIu64 "\n",
1357 __func__, rstat->unxpctd_mcast_pkts);
1358 device_printf(dev, "%s: re1_fbq_error\t\t%" PRIu64 "\n", __func__,
1359 rstat->re1_fbq_error);
1360 device_printf(dev, "%s: invalid_mac_addr\t\t%" PRIu64 "\n", __func__,
1361 rstat->invalid_mac_addr);
1362 device_printf(dev, "%s: rds_prime_trys\t\t%" PRIu64 "\n", __func__,
1363 rstat->rds_prime_trys);
1364 device_printf(dev, "%s: rds_prime_success\t\t%" PRIu64 "\n", __func__,
1365 rstat->rds_prime_success);
1366 device_printf(dev, "%s: lro_flows_added\t\t%" PRIu64 "\n", __func__,
1367 rstat->lro_flows_added);
1368 device_printf(dev, "%s: lro_flows_deleted\t\t%" PRIu64 "\n", __func__,
1369 rstat->lro_flows_deleted);
1370 device_printf(dev, "%s: lro_flows_active\t\t%" PRIu64 "\n", __func__,
1371 rstat->lro_flows_active);
1372 device_printf(dev, "%s: pkts_droped_unknown\t\t%" PRIu64 "\n",
1373 __func__, rstat->pkts_droped_unknown);
1377 qla_mac_stats(qla_host_t *ha, q80_mac_stats_t *mstat)
1379 device_t dev = ha->pci_dev;
1381 device_printf(dev, "%s: xmt_frames\t\t\t%" PRIu64 "\n", __func__,
1383 device_printf(dev, "%s: xmt_bytes\t\t\t%" PRIu64 "\n", __func__,
1385 device_printf(dev, "%s: xmt_mcast_pkts\t\t%" PRIu64 "\n", __func__,
1386 mstat->xmt_mcast_pkts);
1387 device_printf(dev, "%s: xmt_bcast_pkts\t\t%" PRIu64 "\n", __func__,
1388 mstat->xmt_bcast_pkts);
1389 device_printf(dev, "%s: xmt_pause_frames\t\t%" PRIu64 "\n", __func__,
1390 mstat->xmt_pause_frames);
1391 device_printf(dev, "%s: xmt_cntrl_pkts\t\t%" PRIu64 "\n", __func__,
1392 mstat->xmt_cntrl_pkts);
1393 device_printf(dev, "%s: xmt_pkt_lt_64bytes\t\t%" PRIu64 "\n",
1394 __func__, mstat->xmt_pkt_lt_64bytes);
1395 device_printf(dev, "%s: xmt_pkt_lt_127bytes\t\t%" PRIu64 "\n",
1396 __func__, mstat->xmt_pkt_lt_127bytes);
1397 device_printf(dev, "%s: xmt_pkt_lt_255bytes\t\t%" PRIu64 "\n",
1398 __func__, mstat->xmt_pkt_lt_255bytes);
1399 device_printf(dev, "%s: xmt_pkt_lt_511bytes\t\t%" PRIu64 "\n",
1400 __func__, mstat->xmt_pkt_lt_511bytes);
1401 device_printf(dev, "%s: xmt_pkt_lt_1023bytes\t\t%" PRIu64 "\n",
1402 __func__, mstat->xmt_pkt_lt_1023bytes);
1403 device_printf(dev, "%s: xmt_pkt_lt_1518bytes\t\t%" PRIu64 "\n",
1404 __func__, mstat->xmt_pkt_lt_1518bytes);
1405 device_printf(dev, "%s: xmt_pkt_gt_1518bytes\t\t%" PRIu64 "\n",
1406 __func__, mstat->xmt_pkt_gt_1518bytes);
1408 device_printf(dev, "%s: rcv_frames\t\t\t%" PRIu64 "\n", __func__,
1410 device_printf(dev, "%s: rcv_bytes\t\t\t%" PRIu64 "\n", __func__,
1412 device_printf(dev, "%s: rcv_mcast_pkts\t\t%" PRIu64 "\n", __func__,
1413 mstat->rcv_mcast_pkts);
1414 device_printf(dev, "%s: rcv_bcast_pkts\t\t%" PRIu64 "\n", __func__,
1415 mstat->rcv_bcast_pkts);
1416 device_printf(dev, "%s: rcv_pause_frames\t\t%" PRIu64 "\n", __func__,
1417 mstat->rcv_pause_frames);
1418 device_printf(dev, "%s: rcv_cntrl_pkts\t\t%" PRIu64 "\n", __func__,
1419 mstat->rcv_cntrl_pkts);
1420 device_printf(dev, "%s: rcv_pkt_lt_64bytes\t\t%" PRIu64 "\n",
1421 __func__, mstat->rcv_pkt_lt_64bytes);
1422 device_printf(dev, "%s: rcv_pkt_lt_127bytes\t\t%" PRIu64 "\n",
1423 __func__, mstat->rcv_pkt_lt_127bytes);
1424 device_printf(dev, "%s: rcv_pkt_lt_255bytes\t\t%" PRIu64 "\n",
1425 __func__, mstat->rcv_pkt_lt_255bytes);
1426 device_printf(dev, "%s: rcv_pkt_lt_511bytes\t\t%" PRIu64 "\n",
1427 __func__, mstat->rcv_pkt_lt_511bytes);
1428 device_printf(dev, "%s: rcv_pkt_lt_1023bytes\t\t%" PRIu64 "\n",
1429 __func__, mstat->rcv_pkt_lt_1023bytes);
1430 device_printf(dev, "%s: rcv_pkt_lt_1518bytes\t\t%" PRIu64 "\n",
1431 __func__, mstat->rcv_pkt_lt_1518bytes);
1432 device_printf(dev, "%s: rcv_pkt_gt_1518bytes\t\t%" PRIu64 "\n",
1433 __func__, mstat->rcv_pkt_gt_1518bytes);
1435 device_printf(dev, "%s: rcv_len_error\t\t%" PRIu64 "\n", __func__,
1436 mstat->rcv_len_error);
1437 device_printf(dev, "%s: rcv_len_small\t\t%" PRIu64 "\n", __func__,
1438 mstat->rcv_len_small);
1439 device_printf(dev, "%s: rcv_len_large\t\t%" PRIu64 "\n", __func__,
1440 mstat->rcv_len_large);
1441 device_printf(dev, "%s: rcv_jabber\t\t\t%" PRIu64 "\n", __func__,
1443 device_printf(dev, "%s: rcv_dropped\t\t\t%" PRIu64 "\n", __func__,
1444 mstat->rcv_dropped);
1445 device_printf(dev, "%s: fcs_error\t\t\t%" PRIu64 "\n", __func__,
1447 device_printf(dev, "%s: align_error\t\t\t%" PRIu64 "\n", __func__,
1448 mstat->align_error);
1453 qla_get_hw_stats(qla_host_t *ha, uint32_t cmd, uint32_t rsp_size)
1456 q80_get_stats_t *stat;
1457 q80_get_stats_rsp_t *stat_rsp;
1462 stat = (q80_get_stats_t *)ha->hw.mbox;
1463 bzero(stat, (sizeof (q80_get_stats_t)));
1465 stat->opcode = Q8_MBX_GET_STATS;
1466 stat->count_version = 2;
1467 stat->count_version |= Q8_MBX_CMD_VERSION;
1471 if (qla_mbx_cmd(ha, (uint32_t *)stat, 2,
1472 ha->hw.mbox, (rsp_size >> 2), 0)) {
1473 device_printf(dev, "%s: failed\n", __func__);
1477 stat_rsp = (q80_get_stats_rsp_t *)ha->hw.mbox;
1479 err = Q8_MBX_RSP_STATUS(stat_rsp->regcnt_status);
1489 ql_get_stats(qla_host_t *ha)
1491 q80_get_stats_rsp_t *stat_rsp;
1492 q80_mac_stats_t *mstat;
1493 q80_xmt_stats_t *xstat;
1494 q80_rcv_stats_t *rstat;
1498 stat_rsp = (q80_get_stats_rsp_t *)ha->hw.mbox;
1500 * Get MAC Statistics
1502 cmd = Q8_GET_STATS_CMD_TYPE_MAC;
1503 // cmd |= Q8_GET_STATS_CMD_CLEAR;
1505 cmd |= ((ha->pci_func & 0x1) << 16);
1507 if (qla_get_hw_stats(ha, cmd, sizeof (q80_get_stats_rsp_t)) == 0) {
1508 mstat = (q80_mac_stats_t *)&stat_rsp->u.mac;
1509 qla_mac_stats(ha, mstat);
1511 device_printf(ha->pci_dev, "%s: mac failed [0x%08x]\n",
1512 __func__, ha->hw.mbox[0]);
1515 * Get RCV Statistics
1517 cmd = Q8_GET_STATS_CMD_RCV | Q8_GET_STATS_CMD_TYPE_CNTXT;
1518 // cmd |= Q8_GET_STATS_CMD_CLEAR;
1519 cmd |= (ha->hw.rcv_cntxt_id << 16);
1521 if (qla_get_hw_stats(ha, cmd, sizeof (q80_get_stats_rsp_t)) == 0) {
1522 rstat = (q80_rcv_stats_t *)&stat_rsp->u.rcv;
1523 qla_rcv_stats(ha, rstat);
1525 device_printf(ha->pci_dev, "%s: rcv failed [0x%08x]\n",
1526 __func__, ha->hw.mbox[0]);
1529 * Get XMT Statistics
1531 for (i = 0 ; i < ha->hw.num_tx_rings; i++) {
1532 cmd = Q8_GET_STATS_CMD_XMT | Q8_GET_STATS_CMD_TYPE_CNTXT;
1533 // cmd |= Q8_GET_STATS_CMD_CLEAR;
1534 cmd |= (ha->hw.tx_cntxt[i].tx_cntxt_id << 16);
1536 if (qla_get_hw_stats(ha, cmd, sizeof(q80_get_stats_rsp_t))
1538 xstat = (q80_xmt_stats_t *)&stat_rsp->u.xmt;
1539 qla_xmt_stats(ha, xstat, i);
1541 device_printf(ha->pci_dev, "%s: xmt failed [0x%08x]\n",
1542 __func__, ha->hw.mbox[0]);
1549 qla_get_quick_stats(qla_host_t *ha)
1551 q80_get_mac_rcv_xmt_stats_rsp_t *stat_rsp;
1552 q80_mac_stats_t *mstat;
1553 q80_xmt_stats_t *xstat;
1554 q80_rcv_stats_t *rstat;
1557 stat_rsp = (q80_get_mac_rcv_xmt_stats_rsp_t *)ha->hw.mbox;
1559 cmd = Q8_GET_STATS_CMD_TYPE_ALL;
1560 // cmd |= Q8_GET_STATS_CMD_CLEAR;
1562 // cmd |= ((ha->pci_func & 0x3) << 16);
1563 cmd |= (0xFFFF << 16);
1565 if (qla_get_hw_stats(ha, cmd,
1566 sizeof (q80_get_mac_rcv_xmt_stats_rsp_t)) == 0) {
1568 mstat = (q80_mac_stats_t *)&stat_rsp->mac;
1569 rstat = (q80_rcv_stats_t *)&stat_rsp->rcv;
1570 xstat = (q80_xmt_stats_t *)&stat_rsp->xmt;
1571 qla_mac_stats(ha, mstat);
1572 qla_rcv_stats(ha, rstat);
1573 qla_xmt_stats(ha, xstat, ha->hw.num_tx_rings);
1575 device_printf(ha->pci_dev, "%s: failed [0x%08x]\n",
1576 __func__, ha->hw.mbox[0]);
1583 * Function: Checks if the packet to be transmitted is a candidate for
1584 * Large TCP Segment Offload. If yes, the appropriate fields in the Tx
1585 * Ring Structure are plugged in.
1588 qla_tx_tso(qla_host_t *ha, struct mbuf *mp, q80_tx_cmd_t *tx_cmd, uint8_t *hdr)
1590 struct ether_vlan_header *eh;
1591 struct ip *ip = NULL;
1592 struct ip6_hdr *ip6 = NULL;
1593 struct tcphdr *th = NULL;
1594 uint32_t ehdrlen, hdrlen, ip_hlen, tcp_hlen, tcp_opt_off;
1595 uint16_t etype, opcode, offload = 1;
1601 eh = mtod(mp, struct ether_vlan_header *);
1603 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
1604 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
1605 etype = ntohs(eh->evl_proto);
1607 ehdrlen = ETHER_HDR_LEN;
1608 etype = ntohs(eh->evl_encap_proto);
1616 tcp_opt_off = ehdrlen + sizeof(struct ip) +
1617 sizeof(struct tcphdr);
1619 if (mp->m_len < tcp_opt_off) {
1620 m_copydata(mp, 0, tcp_opt_off, hdr);
1621 ip = (struct ip *)(hdr + ehdrlen);
1623 ip = (struct ip *)(mp->m_data + ehdrlen);
1626 ip_hlen = ip->ip_hl << 2;
1627 opcode = Q8_TX_CMD_OP_XMT_TCP_LSO;
1630 if ((ip->ip_p != IPPROTO_TCP) ||
1631 (ip_hlen != sizeof (struct ip))){
1632 /* IP Options are not supported */
1636 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
1640 case ETHERTYPE_IPV6:
1642 tcp_opt_off = ehdrlen + sizeof(struct ip6_hdr) +
1643 sizeof (struct tcphdr);
1645 if (mp->m_len < tcp_opt_off) {
1646 m_copydata(mp, 0, tcp_opt_off, hdr);
1647 ip6 = (struct ip6_hdr *)(hdr + ehdrlen);
1649 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
1652 ip_hlen = sizeof(struct ip6_hdr);
1653 opcode = Q8_TX_CMD_OP_XMT_TCP_LSO_IPV6;
1655 if (ip6->ip6_nxt != IPPROTO_TCP) {
1656 //device_printf(dev, "%s: ipv6\n", __func__);
1659 th = (struct tcphdr *)((caddr_t)ip6 + ip_hlen);
1663 QL_DPRINT8(ha, (dev, "%s: type!=ip\n", __func__));
1671 tcp_hlen = th->th_off << 2;
1672 hdrlen = ehdrlen + ip_hlen + tcp_hlen;
1674 if (mp->m_len < hdrlen) {
1675 if (mp->m_len < tcp_opt_off) {
1676 if (tcp_hlen > sizeof(struct tcphdr)) {
1677 m_copydata(mp, tcp_opt_off,
1678 (tcp_hlen - sizeof(struct tcphdr)),
1682 m_copydata(mp, 0, hdrlen, hdr);
1686 tx_cmd->mss = mp->m_pkthdr.tso_segsz;
1688 tx_cmd->flags_opcode = opcode ;
1689 tx_cmd->tcp_hdr_off = ip_hlen + ehdrlen;
1690 tx_cmd->total_hdr_len = hdrlen;
1692 /* Check for Multicast least significant bit of MSB == 1 */
1693 if (eh->evl_dhost[0] & 0x01) {
1694 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_MULTICAST;
1697 if (mp->m_len < hdrlen) {
1698 printf("%d\n", hdrlen);
1706 * Name: qla_tx_chksum
1707 * Function: Checks if the packet to be transmitted is a candidate for
1708 * TCP/UDP Checksum offload. If yes, the appropriate fields in the Tx
1709 * Ring Structure are plugged in.
1712 qla_tx_chksum(qla_host_t *ha, struct mbuf *mp, uint32_t *op_code,
1713 uint32_t *tcp_hdr_off)
1715 struct ether_vlan_header *eh;
1717 struct ip6_hdr *ip6;
1718 uint32_t ehdrlen, ip_hlen;
1719 uint16_t etype, opcode, offload = 1;
1721 uint8_t buf[sizeof(struct ip6_hdr)];
1727 if ((mp->m_pkthdr.csum_flags & (CSUM_TCP|CSUM_UDP)) == 0)
1730 eh = mtod(mp, struct ether_vlan_header *);
1732 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
1733 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
1734 etype = ntohs(eh->evl_proto);
1736 ehdrlen = ETHER_HDR_LEN;
1737 etype = ntohs(eh->evl_encap_proto);
1743 ip = (struct ip *)(mp->m_data + ehdrlen);
1745 ip_hlen = sizeof (struct ip);
1747 if (mp->m_len < (ehdrlen + ip_hlen)) {
1748 m_copydata(mp, ehdrlen, sizeof(struct ip), buf);
1749 ip = (struct ip *)buf;
1752 if (ip->ip_p == IPPROTO_TCP)
1753 opcode = Q8_TX_CMD_OP_XMT_TCP_CHKSUM;
1754 else if (ip->ip_p == IPPROTO_UDP)
1755 opcode = Q8_TX_CMD_OP_XMT_UDP_CHKSUM;
1757 //device_printf(dev, "%s: ipv4\n", __func__);
1762 case ETHERTYPE_IPV6:
1763 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
1765 ip_hlen = sizeof(struct ip6_hdr);
1767 if (mp->m_len < (ehdrlen + ip_hlen)) {
1768 m_copydata(mp, ehdrlen, sizeof (struct ip6_hdr),
1770 ip6 = (struct ip6_hdr *)buf;
1773 if (ip6->ip6_nxt == IPPROTO_TCP)
1774 opcode = Q8_TX_CMD_OP_XMT_TCP_CHKSUM_IPV6;
1775 else if (ip6->ip6_nxt == IPPROTO_UDP)
1776 opcode = Q8_TX_CMD_OP_XMT_UDP_CHKSUM_IPV6;
1778 //device_printf(dev, "%s: ipv6\n", __func__);
1791 *tcp_hdr_off = (ip_hlen + ehdrlen);
1796 #define QLA_TX_MIN_FREE 2
1799 * Function: Transmits a packet. It first checks if the packet is a
1800 * candidate for Large TCP Segment Offload and then for UDP/TCP checksum
1801 * offload. If either of these creteria are not met, it is transmitted
1802 * as a regular ethernet frame.
1805 ql_hw_send(qla_host_t *ha, bus_dma_segment_t *segs, int nsegs,
1806 uint32_t tx_idx, struct mbuf *mp, uint32_t txr_idx, uint32_t iscsi_pdu)
1808 struct ether_vlan_header *eh;
1809 qla_hw_t *hw = &ha->hw;
1810 q80_tx_cmd_t *tx_cmd, tso_cmd;
1811 bus_dma_segment_t *c_seg;
1812 uint32_t num_tx_cmds, hdr_len = 0;
1813 uint32_t total_length = 0, bytes, tx_cmd_count = 0, txr_next;
1816 uint8_t *src = NULL, *dst = NULL;
1817 uint8_t frame_hdr[QL_FRAME_HDR_SIZE];
1818 uint32_t op_code = 0;
1819 uint32_t tcp_hdr_off = 0;
1824 * Always make sure there is atleast one empty slot in the tx_ring
1825 * tx_ring is considered full when there only one entry available
1827 num_tx_cmds = (nsegs + (Q8_TX_CMD_MAX_SEGMENTS - 1)) >> 2;
1829 total_length = mp->m_pkthdr.len;
1830 if (total_length > QLA_MAX_TSO_FRAME_SIZE) {
1831 device_printf(dev, "%s: total length exceeds maxlen(%d)\n",
1832 __func__, total_length);
1835 eh = mtod(mp, struct ether_vlan_header *);
1837 if (mp->m_pkthdr.csum_flags & CSUM_TSO) {
1839 bzero((void *)&tso_cmd, sizeof(q80_tx_cmd_t));
1842 ret = qla_tx_tso(ha, mp, &tso_cmd, src);
1845 /* find the additional tx_cmd descriptors required */
1847 if (mp->m_flags & M_VLANTAG)
1848 tso_cmd.total_hdr_len += ETHER_VLAN_ENCAP_LEN;
1850 hdr_len = tso_cmd.total_hdr_len;
1852 bytes = sizeof(q80_tx_cmd_t) - Q8_TX_CMD_TSO_ALIGN;
1853 bytes = QL_MIN(bytes, hdr_len);
1859 bytes = QL_MIN((sizeof(q80_tx_cmd_t)), hdr_len);
1863 hdr_len = tso_cmd.total_hdr_len;
1866 src = (uint8_t *)eh;
1870 (void)qla_tx_chksum(ha, mp, &op_code, &tcp_hdr_off);
1874 ha->hw.iscsi_pkt_count++;
1876 if (hw->tx_cntxt[txr_idx].txr_free <= (num_tx_cmds + QLA_TX_MIN_FREE)) {
1877 qla_hw_tx_done_locked(ha, txr_idx);
1878 if (hw->tx_cntxt[txr_idx].txr_free <=
1879 (num_tx_cmds + QLA_TX_MIN_FREE)) {
1880 QL_DPRINT8(ha, (dev, "%s: (hw->txr_free <= "
1881 "(num_tx_cmds + QLA_TX_MIN_FREE))\n",
1887 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[tx_idx];
1889 if (!(mp->m_pkthdr.csum_flags & CSUM_TSO)) {
1891 if (nsegs > ha->hw.max_tx_segs)
1892 ha->hw.max_tx_segs = nsegs;
1894 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1897 tx_cmd->flags_opcode = op_code;
1898 tx_cmd->tcp_hdr_off = tcp_hdr_off;
1901 tx_cmd->flags_opcode = Q8_TX_CMD_OP_XMT_ETHER;
1904 bcopy(&tso_cmd, tx_cmd, sizeof(q80_tx_cmd_t));
1905 ha->tx_tso_frames++;
1908 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
1909 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_VLAN_TAGGED;
1912 eh->evl_tag |= ha->hw.user_pri_iscsi << 13;
1914 } else if (mp->m_flags & M_VLANTAG) {
1916 if (hdr_len) { /* TSO */
1917 tx_cmd->flags_opcode |= (Q8_TX_CMD_FLAGS_VLAN_TAGGED |
1918 Q8_TX_CMD_FLAGS_HW_VLAN_ID);
1919 tx_cmd->tcp_hdr_off += ETHER_VLAN_ENCAP_LEN;
1921 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_HW_VLAN_ID;
1923 ha->hw_vlan_tx_frames++;
1924 tx_cmd->vlan_tci = mp->m_pkthdr.ether_vtag;
1927 tx_cmd->vlan_tci |= ha->hw.user_pri_iscsi << 13;
1928 mp->m_pkthdr.ether_vtag = tx_cmd->vlan_tci;
1933 tx_cmd->n_bufs = (uint8_t)nsegs;
1934 tx_cmd->data_len_lo = (uint8_t)(total_length & 0xFF);
1935 tx_cmd->data_len_hi = qla_host_to_le16(((uint16_t)(total_length >> 8)));
1936 tx_cmd->cntxtid = Q8_TX_CMD_PORT_CNXTID(ha->pci_func);
1941 for (i = 0; ((i < Q8_TX_CMD_MAX_SEGMENTS) && nsegs); i++) {
1945 tx_cmd->buf1_addr = c_seg->ds_addr;
1946 tx_cmd->buf1_len = c_seg->ds_len;
1950 tx_cmd->buf2_addr = c_seg->ds_addr;
1951 tx_cmd->buf2_len = c_seg->ds_len;
1955 tx_cmd->buf3_addr = c_seg->ds_addr;
1956 tx_cmd->buf3_len = c_seg->ds_len;
1960 tx_cmd->buf4_addr = c_seg->ds_addr;
1961 tx_cmd->buf4_len = c_seg->ds_len;
1969 txr_next = hw->tx_cntxt[txr_idx].txr_next =
1970 (hw->tx_cntxt[txr_idx].txr_next + 1) &
1971 (NUM_TX_DESCRIPTORS - 1);
1977 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[txr_next];
1978 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1981 if (mp->m_pkthdr.csum_flags & CSUM_TSO) {
1983 /* TSO : Copy the header in the following tx cmd descriptors */
1985 txr_next = hw->tx_cntxt[txr_idx].txr_next;
1987 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[txr_next];
1988 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1990 bytes = sizeof(q80_tx_cmd_t) - Q8_TX_CMD_TSO_ALIGN;
1991 bytes = QL_MIN(bytes, hdr_len);
1993 dst = (uint8_t *)tx_cmd + Q8_TX_CMD_TSO_ALIGN;
1995 if (mp->m_flags & M_VLANTAG) {
1996 /* first copy the src/dst MAC addresses */
1997 bcopy(src, dst, (ETHER_ADDR_LEN * 2));
1998 dst += (ETHER_ADDR_LEN * 2);
1999 src += (ETHER_ADDR_LEN * 2);
2001 *((uint16_t *)dst) = htons(ETHERTYPE_VLAN);
2003 *((uint16_t *)dst) = htons(mp->m_pkthdr.ether_vtag);
2006 /* bytes left in src header */
2007 hdr_len -= ((ETHER_ADDR_LEN * 2) +
2008 ETHER_VLAN_ENCAP_LEN);
2010 /* bytes left in TxCmd Entry */
2011 bytes -= ((ETHER_ADDR_LEN * 2) + ETHER_VLAN_ENCAP_LEN);
2014 bcopy(src, dst, bytes);
2018 bcopy(src, dst, bytes);
2023 txr_next = hw->tx_cntxt[txr_idx].txr_next =
2024 (hw->tx_cntxt[txr_idx].txr_next + 1) &
2025 (NUM_TX_DESCRIPTORS - 1);
2029 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[txr_next];
2030 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
2032 bytes = QL_MIN((sizeof(q80_tx_cmd_t)), hdr_len);
2034 bcopy(src, tx_cmd, bytes);
2038 txr_next = hw->tx_cntxt[txr_idx].txr_next =
2039 (hw->tx_cntxt[txr_idx].txr_next + 1) &
2040 (NUM_TX_DESCRIPTORS - 1);
2045 hw->tx_cntxt[txr_idx].txr_free =
2046 hw->tx_cntxt[txr_idx].txr_free - tx_cmd_count;
2048 QL_UPDATE_TX_PRODUCER_INDEX(ha, hw->tx_cntxt[txr_idx].txr_next,\
2050 QL_DPRINT8(ha, (dev, "%s: return\n", __func__));
2057 #define Q8_CONFIG_IND_TBL_SIZE 32 /* < Q8_RSS_IND_TBL_SIZE and power of 2 */
2059 qla_config_rss_ind_table(qla_host_t *ha)
2062 uint8_t rss_ind_tbl[Q8_CONFIG_IND_TBL_SIZE];
2065 for (i = 0; i < Q8_CONFIG_IND_TBL_SIZE; i++) {
2066 rss_ind_tbl[i] = i % ha->hw.num_sds_rings;
2069 for (i = 0; i <= Q8_RSS_IND_TBL_MAX_IDX ;
2070 i = i + Q8_CONFIG_IND_TBL_SIZE) {
2072 if ((i + Q8_CONFIG_IND_TBL_SIZE) > Q8_RSS_IND_TBL_MAX_IDX) {
2073 count = Q8_RSS_IND_TBL_MAX_IDX - i + 1;
2075 count = Q8_CONFIG_IND_TBL_SIZE;
2078 if (qla_set_rss_ind_table(ha, i, count, ha->hw.rcv_cntxt_id,
2087 * Name: ql_del_hw_if
2088 * Function: Destroys the hardware specific entities corresponding to an
2089 * Ethernet Interface
2092 ql_del_hw_if(qla_host_t *ha)
2097 (void)qla_stop_nic_func(ha);
2099 qla_del_rcv_cntxt(ha);
2100 qla_del_xmt_cntxt(ha);
2102 if (ha->hw.flags.init_intr_cnxt) {
2103 for (i = 0; i < ha->hw.num_sds_rings; ) {
2105 if ((i + Q8_MAX_INTR_VECTORS) < ha->hw.num_sds_rings)
2106 num_msix = Q8_MAX_INTR_VECTORS;
2108 num_msix = ha->hw.num_sds_rings - i;
2109 qla_config_intr_cntxt(ha, i, num_msix, 0);
2114 ha->hw.flags.init_intr_cnxt = 0;
2120 qla_confirm_9kb_enable(qla_host_t *ha)
2122 uint32_t supports_9kb = 0;
2124 ha->hw.mbx_intr_mask_offset = READ_REG32(ha, Q8_MBOX_INT_MASK_MSIX);
2126 /* Use MSI-X vector 0; Enable Firmware Mailbox Interrupt */
2127 WRITE_REG32(ha, Q8_MBOX_INT_ENABLE, BIT_2);
2128 WRITE_REG32(ha, ha->hw.mbx_intr_mask_offset, 0x0);
2130 qla_get_nic_partition(ha, &supports_9kb, NULL);
2133 ha->hw.enable_9kb = 0;
2140 * Name: ql_init_hw_if
2141 * Function: Creates the hardware specific entities corresponding to an
2142 * Ethernet Interface - Transmit and Receive Contexts. Sets the MAC Address
2143 * corresponding to the interface. Enables LRO if allowed.
2146 ql_init_hw_if(qla_host_t *ha)
2150 uint8_t bcast_mac[6];
2156 for (i = 0; i < ha->hw.num_sds_rings; i++) {
2157 bzero(ha->hw.dma_buf.sds_ring[i].dma_b,
2158 ha->hw.dma_buf.sds_ring[i].size);
2161 for (i = 0; i < ha->hw.num_sds_rings; ) {
2163 if ((i + Q8_MAX_INTR_VECTORS) < ha->hw.num_sds_rings)
2164 num_msix = Q8_MAX_INTR_VECTORS;
2166 num_msix = ha->hw.num_sds_rings - i;
2168 if (qla_config_intr_cntxt(ha, i, num_msix, 1)) {
2174 for (i = 0; i < num_msix; ) {
2175 qla_config_intr_cntxt(ha, i,
2176 Q8_MAX_INTR_VECTORS, 0);
2177 i += Q8_MAX_INTR_VECTORS;
2186 ha->hw.flags.init_intr_cnxt = 1;
2188 if (ha->hw.mdump_init == 0) {
2189 qla_minidump_init(ha);
2193 * Create Receive Context
2195 if (qla_init_rcv_cntxt(ha)) {
2199 for (i = 0; i < ha->hw.num_rds_rings; i++) {
2200 rdesc = &ha->hw.rds[i];
2201 rdesc->rx_next = NUM_RX_DESCRIPTORS - 2;
2203 /* Update the RDS Producer Indices */
2204 QL_UPDATE_RDS_PRODUCER_INDEX(ha, rdesc->prod_std,\
2210 * Create Transmit Context
2212 if (qla_init_xmt_cntxt(ha)) {
2213 qla_del_rcv_cntxt(ha);
2216 ha->hw.max_tx_segs = 0;
2218 if (qla_config_mac_addr(ha, ha->hw.mac_addr, 1))
2221 ha->hw.flags.unicast_mac = 1;
2223 bcast_mac[0] = 0xFF; bcast_mac[1] = 0xFF; bcast_mac[2] = 0xFF;
2224 bcast_mac[3] = 0xFF; bcast_mac[4] = 0xFF; bcast_mac[5] = 0xFF;
2226 if (qla_config_mac_addr(ha, bcast_mac, 1))
2229 ha->hw.flags.bcast_mac = 1;
2232 * program any cached multicast addresses
2234 if (qla_hw_add_all_mcast(ha))
2237 if (qla_config_rss(ha, ha->hw.rcv_cntxt_id))
2240 if (qla_config_rss_ind_table(ha))
2243 if (qla_config_intr_coalesce(ha, ha->hw.rcv_cntxt_id, 0, 1))
2246 if (qla_link_event_req(ha, ha->hw.rcv_cntxt_id))
2249 if (qla_config_fw_lro(ha, ha->hw.rcv_cntxt_id))
2252 if (qla_init_nic_func(ha))
2255 if (qla_query_fw_dcbx_caps(ha))
2258 for (i = 0; i < ha->hw.num_sds_rings; i++)
2259 QL_ENABLE_INTERRUPTS(ha, i);
2265 qla_map_sds_to_rds(qla_host_t *ha, uint32_t start_idx, uint32_t num_idx)
2267 device_t dev = ha->pci_dev;
2268 q80_rq_map_sds_to_rds_t *map_rings;
2269 q80_rsp_map_sds_to_rds_t *map_rings_rsp;
2271 qla_hw_t *hw = &ha->hw;
2273 map_rings = (q80_rq_map_sds_to_rds_t *)ha->hw.mbox;
2274 bzero(map_rings, sizeof(q80_rq_map_sds_to_rds_t));
2276 map_rings->opcode = Q8_MBX_MAP_SDS_TO_RDS;
2277 map_rings->count_version = (sizeof (q80_rq_map_sds_to_rds_t) >> 2);
2278 map_rings->count_version |= Q8_MBX_CMD_VERSION;
2280 map_rings->cntxt_id = hw->rcv_cntxt_id;
2281 map_rings->num_rings = num_idx;
2283 for (i = 0; i < num_idx; i++) {
2284 map_rings->sds_rds[i].sds_ring = i + start_idx;
2285 map_rings->sds_rds[i].rds_ring = i + start_idx;
2288 if (qla_mbx_cmd(ha, (uint32_t *)map_rings,
2289 (sizeof (q80_rq_map_sds_to_rds_t) >> 2),
2290 ha->hw.mbox, (sizeof(q80_rsp_add_rcv_rings_t) >> 2), 0)) {
2291 device_printf(dev, "%s: failed0\n", __func__);
2295 map_rings_rsp = (q80_rsp_map_sds_to_rds_t *)ha->hw.mbox;
2297 err = Q8_MBX_RSP_STATUS(map_rings_rsp->regcnt_status);
2300 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2308 * Name: qla_init_rcv_cntxt
2309 * Function: Creates the Receive Context.
2312 qla_init_rcv_cntxt(qla_host_t *ha)
2314 q80_rq_rcv_cntxt_t *rcntxt;
2315 q80_rsp_rcv_cntxt_t *rcntxt_rsp;
2316 q80_stat_desc_t *sdesc;
2318 qla_hw_t *hw = &ha->hw;
2321 uint32_t rcntxt_sds_rings;
2322 uint32_t rcntxt_rds_rings;
2328 * Create Receive Context
2331 for (i = 0; i < hw->num_sds_rings; i++) {
2332 sdesc = (q80_stat_desc_t *)&hw->sds[i].sds_ring_base[0];
2334 for (j = 0; j < NUM_STATUS_DESCRIPTORS; j++) {
2335 sdesc->data[0] = 1ULL;
2336 sdesc->data[1] = 1ULL;
2340 rcntxt_sds_rings = hw->num_sds_rings;
2341 if (hw->num_sds_rings > MAX_RCNTXT_SDS_RINGS)
2342 rcntxt_sds_rings = MAX_RCNTXT_SDS_RINGS;
2344 rcntxt_rds_rings = hw->num_rds_rings;
2346 if (hw->num_rds_rings > MAX_RDS_RING_SETS)
2347 rcntxt_rds_rings = MAX_RDS_RING_SETS;
2349 rcntxt = (q80_rq_rcv_cntxt_t *)ha->hw.mbox;
2350 bzero(rcntxt, (sizeof (q80_rq_rcv_cntxt_t)));
2352 rcntxt->opcode = Q8_MBX_CREATE_RX_CNTXT;
2353 rcntxt->count_version = (sizeof (q80_rq_rcv_cntxt_t) >> 2);
2354 rcntxt->count_version |= Q8_MBX_CMD_VERSION;
2356 rcntxt->cap0 = Q8_RCV_CNTXT_CAP0_BASEFW |
2357 Q8_RCV_CNTXT_CAP0_LRO |
2358 Q8_RCV_CNTXT_CAP0_HW_LRO |
2359 Q8_RCV_CNTXT_CAP0_RSS |
2360 Q8_RCV_CNTXT_CAP0_SGL_LRO;
2362 if (ha->hw.enable_9kb)
2363 rcntxt->cap0 |= Q8_RCV_CNTXT_CAP0_SINGLE_JUMBO;
2365 rcntxt->cap0 |= Q8_RCV_CNTXT_CAP0_SGL_JUMBO;
2367 if (ha->hw.num_rds_rings > 1) {
2368 rcntxt->nrds_sets_rings = rcntxt_rds_rings | (1 << 5);
2369 rcntxt->cap0 |= Q8_RCV_CNTXT_CAP0_MULTI_RDS;
2371 rcntxt->nrds_sets_rings = 0x1 | (1 << 5);
2373 rcntxt->nsds_rings = rcntxt_sds_rings;
2375 rcntxt->rds_producer_mode = Q8_RCV_CNTXT_RDS_PROD_MODE_UNIQUE;
2377 rcntxt->rcv_vpid = 0;
2379 for (i = 0; i < rcntxt_sds_rings; i++) {
2380 rcntxt->sds[i].paddr =
2381 qla_host_to_le64(hw->dma_buf.sds_ring[i].dma_addr);
2382 rcntxt->sds[i].size =
2383 qla_host_to_le32(NUM_STATUS_DESCRIPTORS);
2384 if (ha->msix_count == 2) {
2385 rcntxt->sds[i].intr_id =
2386 qla_host_to_le16(hw->intr_id[0]);
2387 rcntxt->sds[i].intr_src_bit = qla_host_to_le16((i));
2389 rcntxt->sds[i].intr_id =
2390 qla_host_to_le16(hw->intr_id[i]);
2391 rcntxt->sds[i].intr_src_bit = qla_host_to_le16(0);
2395 for (i = 0; i < rcntxt_rds_rings; i++) {
2396 rcntxt->rds[i].paddr_std =
2397 qla_host_to_le64(hw->dma_buf.rds_ring[i].dma_addr);
2399 if (ha->hw.enable_9kb)
2400 rcntxt->rds[i].std_bsize =
2401 qla_host_to_le64(MJUM9BYTES);
2403 rcntxt->rds[i].std_bsize = qla_host_to_le64(MCLBYTES);
2405 rcntxt->rds[i].std_nentries =
2406 qla_host_to_le32(NUM_RX_DESCRIPTORS);
2409 if (qla_mbx_cmd(ha, (uint32_t *)rcntxt,
2410 (sizeof (q80_rq_rcv_cntxt_t) >> 2),
2411 ha->hw.mbox, (sizeof(q80_rsp_rcv_cntxt_t) >> 2), 0)) {
2412 device_printf(dev, "%s: failed0\n", __func__);
2416 rcntxt_rsp = (q80_rsp_rcv_cntxt_t *)ha->hw.mbox;
2418 err = Q8_MBX_RSP_STATUS(rcntxt_rsp->regcnt_status);
2421 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2425 for (i = 0; i < rcntxt_sds_rings; i++) {
2426 hw->sds[i].sds_consumer = rcntxt_rsp->sds_cons[i];
2429 for (i = 0; i < rcntxt_rds_rings; i++) {
2430 hw->rds[i].prod_std = rcntxt_rsp->rds[i].prod_std;
2433 hw->rcv_cntxt_id = rcntxt_rsp->cntxt_id;
2435 ha->hw.flags.init_rx_cnxt = 1;
2437 if (hw->num_sds_rings > MAX_RCNTXT_SDS_RINGS) {
2439 for (i = MAX_RCNTXT_SDS_RINGS; i < hw->num_sds_rings;) {
2441 if ((i + MAX_RCNTXT_SDS_RINGS) < hw->num_sds_rings)
2442 max_idx = MAX_RCNTXT_SDS_RINGS;
2444 max_idx = hw->num_sds_rings - i;
2446 err = qla_add_rcv_rings(ha, i, max_idx);
2454 if (hw->num_rds_rings > 1) {
2456 for (i = 0; i < hw->num_rds_rings; ) {
2458 if ((i + MAX_SDS_TO_RDS_MAP) < hw->num_rds_rings)
2459 max_idx = MAX_SDS_TO_RDS_MAP;
2461 max_idx = hw->num_rds_rings - i;
2463 err = qla_map_sds_to_rds(ha, i, max_idx);
2475 qla_add_rcv_rings(qla_host_t *ha, uint32_t sds_idx, uint32_t nsds)
2477 device_t dev = ha->pci_dev;
2478 q80_rq_add_rcv_rings_t *add_rcv;
2479 q80_rsp_add_rcv_rings_t *add_rcv_rsp;
2481 qla_hw_t *hw = &ha->hw;
2483 add_rcv = (q80_rq_add_rcv_rings_t *)ha->hw.mbox;
2484 bzero(add_rcv, sizeof (q80_rq_add_rcv_rings_t));
2486 add_rcv->opcode = Q8_MBX_ADD_RX_RINGS;
2487 add_rcv->count_version = (sizeof (q80_rq_add_rcv_rings_t) >> 2);
2488 add_rcv->count_version |= Q8_MBX_CMD_VERSION;
2490 add_rcv->nrds_sets_rings = nsds | (1 << 5);
2491 add_rcv->nsds_rings = nsds;
2492 add_rcv->cntxt_id = hw->rcv_cntxt_id;
2494 for (i = 0; i < nsds; i++) {
2498 add_rcv->sds[i].paddr =
2499 qla_host_to_le64(hw->dma_buf.sds_ring[j].dma_addr);
2501 add_rcv->sds[i].size =
2502 qla_host_to_le32(NUM_STATUS_DESCRIPTORS);
2504 if (ha->msix_count == 2) {
2505 add_rcv->sds[i].intr_id =
2506 qla_host_to_le16(hw->intr_id[0]);
2507 add_rcv->sds[i].intr_src_bit = qla_host_to_le16(j);
2509 add_rcv->sds[i].intr_id =
2510 qla_host_to_le16(hw->intr_id[j]);
2511 add_rcv->sds[i].intr_src_bit = qla_host_to_le16(0);
2515 for (i = 0; (i < nsds); i++) {
2518 add_rcv->rds[i].paddr_std =
2519 qla_host_to_le64(hw->dma_buf.rds_ring[j].dma_addr);
2521 if (ha->hw.enable_9kb)
2522 add_rcv->rds[i].std_bsize =
2523 qla_host_to_le64(MJUM9BYTES);
2525 add_rcv->rds[i].std_bsize = qla_host_to_le64(MCLBYTES);
2527 add_rcv->rds[i].std_nentries =
2528 qla_host_to_le32(NUM_RX_DESCRIPTORS);
2532 if (qla_mbx_cmd(ha, (uint32_t *)add_rcv,
2533 (sizeof (q80_rq_add_rcv_rings_t) >> 2),
2534 ha->hw.mbox, (sizeof(q80_rsp_add_rcv_rings_t) >> 2), 0)) {
2535 device_printf(dev, "%s: failed0\n", __func__);
2539 add_rcv_rsp = (q80_rsp_add_rcv_rings_t *)ha->hw.mbox;
2541 err = Q8_MBX_RSP_STATUS(add_rcv_rsp->regcnt_status);
2544 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2548 for (i = 0; i < nsds; i++) {
2549 hw->sds[(i + sds_idx)].sds_consumer = add_rcv_rsp->sds_cons[i];
2552 for (i = 0; i < nsds; i++) {
2553 hw->rds[(i + sds_idx)].prod_std = add_rcv_rsp->rds[i].prod_std;
2560 * Name: qla_del_rcv_cntxt
2561 * Function: Destroys the Receive Context.
2564 qla_del_rcv_cntxt(qla_host_t *ha)
2566 device_t dev = ha->pci_dev;
2567 q80_rcv_cntxt_destroy_t *rcntxt;
2568 q80_rcv_cntxt_destroy_rsp_t *rcntxt_rsp;
2570 uint8_t bcast_mac[6];
2572 if (!ha->hw.flags.init_rx_cnxt)
2575 if (qla_hw_del_all_mcast(ha))
2578 if (ha->hw.flags.bcast_mac) {
2580 bcast_mac[0] = 0xFF; bcast_mac[1] = 0xFF; bcast_mac[2] = 0xFF;
2581 bcast_mac[3] = 0xFF; bcast_mac[4] = 0xFF; bcast_mac[5] = 0xFF;
2583 if (qla_config_mac_addr(ha, bcast_mac, 0))
2585 ha->hw.flags.bcast_mac = 0;
2589 if (ha->hw.flags.unicast_mac) {
2590 if (qla_config_mac_addr(ha, ha->hw.mac_addr, 0))
2592 ha->hw.flags.unicast_mac = 0;
2595 rcntxt = (q80_rcv_cntxt_destroy_t *)ha->hw.mbox;
2596 bzero(rcntxt, (sizeof (q80_rcv_cntxt_destroy_t)));
2598 rcntxt->opcode = Q8_MBX_DESTROY_RX_CNTXT;
2599 rcntxt->count_version = (sizeof (q80_rcv_cntxt_destroy_t) >> 2);
2600 rcntxt->count_version |= Q8_MBX_CMD_VERSION;
2602 rcntxt->cntxt_id = ha->hw.rcv_cntxt_id;
2604 if (qla_mbx_cmd(ha, (uint32_t *)rcntxt,
2605 (sizeof (q80_rcv_cntxt_destroy_t) >> 2),
2606 ha->hw.mbox, (sizeof(q80_rcv_cntxt_destroy_rsp_t) >> 2), 0)) {
2607 device_printf(dev, "%s: failed0\n", __func__);
2610 rcntxt_rsp = (q80_rcv_cntxt_destroy_rsp_t *)ha->hw.mbox;
2612 err = Q8_MBX_RSP_STATUS(rcntxt_rsp->regcnt_status);
2615 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2618 ha->hw.flags.init_rx_cnxt = 0;
2623 * Name: qla_init_xmt_cntxt
2624 * Function: Creates the Transmit Context.
2627 qla_init_xmt_cntxt_i(qla_host_t *ha, uint32_t txr_idx)
2630 qla_hw_t *hw = &ha->hw;
2631 q80_rq_tx_cntxt_t *tcntxt;
2632 q80_rsp_tx_cntxt_t *tcntxt_rsp;
2634 qla_hw_tx_cntxt_t *hw_tx_cntxt;
2636 hw_tx_cntxt = &hw->tx_cntxt[txr_idx];
2641 * Create Transmit Context
2643 tcntxt = (q80_rq_tx_cntxt_t *)ha->hw.mbox;
2644 bzero(tcntxt, (sizeof (q80_rq_tx_cntxt_t)));
2646 tcntxt->opcode = Q8_MBX_CREATE_TX_CNTXT;
2647 tcntxt->count_version = (sizeof (q80_rq_tx_cntxt_t) >> 2);
2648 tcntxt->count_version |= Q8_MBX_CMD_VERSION;
2650 #ifdef QL_ENABLE_ISCSI_TLV
2652 tcntxt->cap0 = Q8_TX_CNTXT_CAP0_BASEFW | Q8_TX_CNTXT_CAP0_LSO |
2653 Q8_TX_CNTXT_CAP0_TC;
2655 if (txr_idx >= (ha->hw.num_tx_rings >> 1)) {
2656 tcntxt->traffic_class = 1;
2661 tcntxt->cap0 = Q8_TX_CNTXT_CAP0_BASEFW | Q8_TX_CNTXT_CAP0_LSO;
2663 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */
2665 tcntxt->ntx_rings = 1;
2667 tcntxt->tx_ring[0].paddr =
2668 qla_host_to_le64(hw_tx_cntxt->tx_ring_paddr);
2669 tcntxt->tx_ring[0].tx_consumer =
2670 qla_host_to_le64(hw_tx_cntxt->tx_cons_paddr);
2671 tcntxt->tx_ring[0].nentries = qla_host_to_le16(NUM_TX_DESCRIPTORS);
2673 tcntxt->tx_ring[0].intr_id = qla_host_to_le16(hw->intr_id[0]);
2674 tcntxt->tx_ring[0].intr_src_bit = qla_host_to_le16(0);
2677 hw_tx_cntxt->txr_free = NUM_TX_DESCRIPTORS;
2678 hw_tx_cntxt->txr_next = hw_tx_cntxt->txr_comp = 0;
2680 if (qla_mbx_cmd(ha, (uint32_t *)tcntxt,
2681 (sizeof (q80_rq_tx_cntxt_t) >> 2),
2683 (sizeof(q80_rsp_tx_cntxt_t) >> 2), 0)) {
2684 device_printf(dev, "%s: failed0\n", __func__);
2687 tcntxt_rsp = (q80_rsp_tx_cntxt_t *)ha->hw.mbox;
2689 err = Q8_MBX_RSP_STATUS(tcntxt_rsp->regcnt_status);
2692 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2696 hw_tx_cntxt->tx_prod_reg = tcntxt_rsp->tx_ring[0].prod_index;
2697 hw_tx_cntxt->tx_cntxt_id = tcntxt_rsp->tx_ring[0].cntxt_id;
2699 if (qla_config_intr_coalesce(ha, hw_tx_cntxt->tx_cntxt_id, 0, 0))
2707 * Name: qla_del_xmt_cntxt
2708 * Function: Destroys the Transmit Context.
2711 qla_del_xmt_cntxt_i(qla_host_t *ha, uint32_t txr_idx)
2713 device_t dev = ha->pci_dev;
2714 q80_tx_cntxt_destroy_t *tcntxt;
2715 q80_tx_cntxt_destroy_rsp_t *tcntxt_rsp;
2718 tcntxt = (q80_tx_cntxt_destroy_t *)ha->hw.mbox;
2719 bzero(tcntxt, (sizeof (q80_tx_cntxt_destroy_t)));
2721 tcntxt->opcode = Q8_MBX_DESTROY_TX_CNTXT;
2722 tcntxt->count_version = (sizeof (q80_tx_cntxt_destroy_t) >> 2);
2723 tcntxt->count_version |= Q8_MBX_CMD_VERSION;
2725 tcntxt->cntxt_id = ha->hw.tx_cntxt[txr_idx].tx_cntxt_id;
2727 if (qla_mbx_cmd(ha, (uint32_t *)tcntxt,
2728 (sizeof (q80_tx_cntxt_destroy_t) >> 2),
2729 ha->hw.mbox, (sizeof (q80_tx_cntxt_destroy_rsp_t) >> 2), 0)) {
2730 device_printf(dev, "%s: failed0\n", __func__);
2733 tcntxt_rsp = (q80_tx_cntxt_destroy_rsp_t *)ha->hw.mbox;
2735 err = Q8_MBX_RSP_STATUS(tcntxt_rsp->regcnt_status);
2738 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err);
2745 qla_del_xmt_cntxt(qla_host_t *ha)
2749 if (!ha->hw.flags.init_tx_cnxt)
2752 for (i = 0; i < ha->hw.num_tx_rings; i++) {
2753 if (qla_del_xmt_cntxt_i(ha, i))
2756 ha->hw.flags.init_tx_cnxt = 0;
2760 qla_init_xmt_cntxt(qla_host_t *ha)
2764 for (i = 0; i < ha->hw.num_tx_rings; i++) {
2765 if (qla_init_xmt_cntxt_i(ha, i) != 0) {
2766 for (j = 0; j < i; j++)
2767 qla_del_xmt_cntxt_i(ha, j);
2771 ha->hw.flags.init_tx_cnxt = 1;
2776 qla_hw_add_all_mcast(qla_host_t *ha)
2780 nmcast = ha->hw.nmcast;
2782 for (i = 0 ; ((i < Q8_MAX_NUM_MULTICAST_ADDRS) && nmcast); i++) {
2783 if ((ha->hw.mcast[i].addr[0] != 0) ||
2784 (ha->hw.mcast[i].addr[1] != 0) ||
2785 (ha->hw.mcast[i].addr[2] != 0) ||
2786 (ha->hw.mcast[i].addr[3] != 0) ||
2787 (ha->hw.mcast[i].addr[4] != 0) ||
2788 (ha->hw.mcast[i].addr[5] != 0)) {
2790 if (qla_config_mac_addr(ha, ha->hw.mcast[i].addr, 1)) {
2791 device_printf(ha->pci_dev, "%s: failed\n",
2803 qla_hw_del_all_mcast(qla_host_t *ha)
2807 nmcast = ha->hw.nmcast;
2809 for (i = 0 ; ((i < Q8_MAX_NUM_MULTICAST_ADDRS) && nmcast); i++) {
2810 if ((ha->hw.mcast[i].addr[0] != 0) ||
2811 (ha->hw.mcast[i].addr[1] != 0) ||
2812 (ha->hw.mcast[i].addr[2] != 0) ||
2813 (ha->hw.mcast[i].addr[3] != 0) ||
2814 (ha->hw.mcast[i].addr[4] != 0) ||
2815 (ha->hw.mcast[i].addr[5] != 0)) {
2817 if (qla_config_mac_addr(ha, ha->hw.mcast[i].addr, 0))
2827 qla_hw_add_mcast(qla_host_t *ha, uint8_t *mta)
2831 for (i = 0; i < Q8_MAX_NUM_MULTICAST_ADDRS; i++) {
2833 if (QL_MAC_CMP(ha->hw.mcast[i].addr, mta) == 0)
2834 return 0; /* its been already added */
2837 for (i = 0; i < Q8_MAX_NUM_MULTICAST_ADDRS; i++) {
2839 if ((ha->hw.mcast[i].addr[0] == 0) &&
2840 (ha->hw.mcast[i].addr[1] == 0) &&
2841 (ha->hw.mcast[i].addr[2] == 0) &&
2842 (ha->hw.mcast[i].addr[3] == 0) &&
2843 (ha->hw.mcast[i].addr[4] == 0) &&
2844 (ha->hw.mcast[i].addr[5] == 0)) {
2846 if (qla_config_mac_addr(ha, mta, 1))
2849 bcopy(mta, ha->hw.mcast[i].addr, Q8_MAC_ADDR_LEN);
2859 qla_hw_del_mcast(qla_host_t *ha, uint8_t *mta)
2863 for (i = 0; i < Q8_MAX_NUM_MULTICAST_ADDRS; i++) {
2864 if (QL_MAC_CMP(ha->hw.mcast[i].addr, mta) == 0) {
2866 if (qla_config_mac_addr(ha, mta, 0))
2869 ha->hw.mcast[i].addr[0] = 0;
2870 ha->hw.mcast[i].addr[1] = 0;
2871 ha->hw.mcast[i].addr[2] = 0;
2872 ha->hw.mcast[i].addr[3] = 0;
2873 ha->hw.mcast[i].addr[4] = 0;
2874 ha->hw.mcast[i].addr[5] = 0;
2885 * Name: ql_hw_set_multi
2886 * Function: Sets the Multicast Addresses provided the host O.S into the
2887 * hardware (for the given interface)
2890 ql_hw_set_multi(qla_host_t *ha, uint8_t *mcast, uint32_t mcnt,
2894 uint8_t *mta = mcast;
2897 for (i = 0; i < mcnt; i++) {
2899 ret = qla_hw_add_mcast(ha, mta);
2903 ret = qla_hw_del_mcast(ha, mta);
2908 mta += Q8_MAC_ADDR_LEN;
2914 * Name: qla_hw_tx_done_locked
2915 * Function: Handle Transmit Completions
2918 qla_hw_tx_done_locked(qla_host_t *ha, uint32_t txr_idx)
2921 qla_hw_t *hw = &ha->hw;
2922 uint32_t comp_idx, comp_count = 0;
2923 qla_hw_tx_cntxt_t *hw_tx_cntxt;
2925 hw_tx_cntxt = &hw->tx_cntxt[txr_idx];
2927 /* retrieve index of last entry in tx ring completed */
2928 comp_idx = qla_le32_to_host(*(hw_tx_cntxt->tx_cons));
2930 while (comp_idx != hw_tx_cntxt->txr_comp) {
2932 txb = &ha->tx_ring[txr_idx].tx_buf[hw_tx_cntxt->txr_comp];
2934 hw_tx_cntxt->txr_comp++;
2935 if (hw_tx_cntxt->txr_comp == NUM_TX_DESCRIPTORS)
2936 hw_tx_cntxt->txr_comp = 0;
2941 ha->ifp->if_opackets++;
2943 bus_dmamap_sync(ha->tx_tag, txb->map,
2944 BUS_DMASYNC_POSTWRITE);
2945 bus_dmamap_unload(ha->tx_tag, txb->map);
2946 m_freem(txb->m_head);
2952 hw_tx_cntxt->txr_free += comp_count;
2957 * Name: ql_hw_tx_done
2958 * Function: Handle Transmit Completions
2961 ql_hw_tx_done(qla_host_t *ha)
2966 if (!mtx_trylock(&ha->tx_lock)) {
2967 QL_DPRINT8(ha, (ha->pci_dev,
2968 "%s: !mtx_trylock(&ha->tx_lock)\n", __func__));
2971 for (i = 0; i < ha->hw.num_tx_rings; i++) {
2972 qla_hw_tx_done_locked(ha, i);
2973 if (ha->hw.tx_cntxt[i].txr_free <= (NUM_TX_DESCRIPTORS >> 1))
2978 ha->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2985 ql_update_link_state(qla_host_t *ha)
2987 uint32_t link_state;
2988 uint32_t prev_link_state;
2990 if (!(ha->ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2994 link_state = READ_REG32(ha, Q8_LINK_STATE);
2996 prev_link_state = ha->hw.link_up;
2998 if (ha->pci_func == 0)
2999 ha->hw.link_up = (((link_state & 0xF) == 1)? 1 : 0);
3001 ha->hw.link_up = ((((link_state >> 4)& 0xF) == 1)? 1 : 0);
3003 if (prev_link_state != ha->hw.link_up) {
3004 if (ha->hw.link_up) {
3005 if_link_state_change(ha->ifp, LINK_STATE_UP);
3007 if_link_state_change(ha->ifp, LINK_STATE_DOWN);
3014 ql_hw_stop_rcv(qla_host_t *ha)
3016 int i, done, count = 100;
3020 for (i = 0; i < ha->hw.num_sds_rings; i++) {
3021 if (ha->hw.sds[i].rcv_active)
3027 qla_mdelay(__func__, 10);
3031 device_printf(ha->pci_dev, "%s: Counter expired.\n", __func__);
3037 ql_hw_check_health(qla_host_t *ha)
3041 ha->hw.health_count++;
3043 if (ha->hw.health_count < 1000)
3046 ha->hw.health_count = 0;
3048 val = READ_REG32(ha, Q8_ASIC_TEMPERATURE);
3050 if (((val & 0xFFFF) == 2) || ((val & 0xFFFF) == 3) ||
3051 (QL_ERR_INJECT(ha, INJCT_TEMPERATURE_FAILURE))) {
3052 device_printf(ha->pci_dev, "%s: Temperature Alert [0x%08x]\n",
3057 val = READ_REG32(ha, Q8_FIRMWARE_HEARTBEAT);
3059 if ((val != ha->hw.hbeat_value) &&
3060 (!(QL_ERR_INJECT(ha, INJCT_TEMPERATURE_FAILURE)))) {
3061 ha->hw.hbeat_value = val;
3064 device_printf(ha->pci_dev, "%s: Heartbeat Failue [0x%08x]\n",
3071 qla_init_nic_func(qla_host_t *ha)
3074 q80_init_nic_func_t *init_nic;
3075 q80_init_nic_func_rsp_t *init_nic_rsp;
3080 init_nic = (q80_init_nic_func_t *)ha->hw.mbox;
3081 bzero(init_nic, sizeof(q80_init_nic_func_t));
3083 init_nic->opcode = Q8_MBX_INIT_NIC_FUNC;
3084 init_nic->count_version = (sizeof (q80_init_nic_func_t) >> 2);
3085 init_nic->count_version |= Q8_MBX_CMD_VERSION;
3087 init_nic->options = Q8_INIT_NIC_REG_DCBX_CHNG_AEN;
3088 init_nic->options |= Q8_INIT_NIC_REG_SFP_CHNG_AEN;
3089 init_nic->options |= Q8_INIT_NIC_REG_IDC_AEN;
3091 //qla_dump_buf8(ha, __func__, init_nic, sizeof (q80_init_nic_func_t));
3092 if (qla_mbx_cmd(ha, (uint32_t *)init_nic,
3093 (sizeof (q80_init_nic_func_t) >> 2),
3094 ha->hw.mbox, (sizeof (q80_init_nic_func_rsp_t) >> 2), 0)) {
3095 device_printf(dev, "%s: failed\n", __func__);
3099 init_nic_rsp = (q80_init_nic_func_rsp_t *)ha->hw.mbox;
3100 // qla_dump_buf8(ha, __func__, init_nic_rsp, sizeof (q80_init_nic_func_rsp_t));
3102 err = Q8_MBX_RSP_STATUS(init_nic_rsp->regcnt_status);
3105 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3112 qla_stop_nic_func(qla_host_t *ha)
3115 q80_stop_nic_func_t *stop_nic;
3116 q80_stop_nic_func_rsp_t *stop_nic_rsp;
3121 stop_nic = (q80_stop_nic_func_t *)ha->hw.mbox;
3122 bzero(stop_nic, sizeof(q80_stop_nic_func_t));
3124 stop_nic->opcode = Q8_MBX_STOP_NIC_FUNC;
3125 stop_nic->count_version = (sizeof (q80_stop_nic_func_t) >> 2);
3126 stop_nic->count_version |= Q8_MBX_CMD_VERSION;
3128 stop_nic->options = Q8_STOP_NIC_DEREG_DCBX_CHNG_AEN;
3129 stop_nic->options |= Q8_STOP_NIC_DEREG_SFP_CHNG_AEN;
3131 //qla_dump_buf8(ha, __func__, stop_nic, sizeof (q80_stop_nic_func_t));
3132 if (qla_mbx_cmd(ha, (uint32_t *)stop_nic,
3133 (sizeof (q80_stop_nic_func_t) >> 2),
3134 ha->hw.mbox, (sizeof (q80_stop_nic_func_rsp_t) >> 2), 0)) {
3135 device_printf(dev, "%s: failed\n", __func__);
3139 stop_nic_rsp = (q80_stop_nic_func_rsp_t *)ha->hw.mbox;
3140 //qla_dump_buf8(ha, __func__, stop_nic_rsp, sizeof (q80_stop_nic_func_rsp_ t));
3142 err = Q8_MBX_RSP_STATUS(stop_nic_rsp->regcnt_status);
3145 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3152 qla_query_fw_dcbx_caps(qla_host_t *ha)
3155 q80_query_fw_dcbx_caps_t *fw_dcbx;
3156 q80_query_fw_dcbx_caps_rsp_t *fw_dcbx_rsp;
3161 fw_dcbx = (q80_query_fw_dcbx_caps_t *)ha->hw.mbox;
3162 bzero(fw_dcbx, sizeof(q80_query_fw_dcbx_caps_t));
3164 fw_dcbx->opcode = Q8_MBX_GET_FW_DCBX_CAPS;
3165 fw_dcbx->count_version = (sizeof (q80_query_fw_dcbx_caps_t) >> 2);
3166 fw_dcbx->count_version |= Q8_MBX_CMD_VERSION;
3168 ql_dump_buf8(ha, __func__, fw_dcbx, sizeof (q80_query_fw_dcbx_caps_t));
3169 if (qla_mbx_cmd(ha, (uint32_t *)fw_dcbx,
3170 (sizeof (q80_query_fw_dcbx_caps_t) >> 2),
3171 ha->hw.mbox, (sizeof (q80_query_fw_dcbx_caps_rsp_t) >> 2), 0)) {
3172 device_printf(dev, "%s: failed\n", __func__);
3176 fw_dcbx_rsp = (q80_query_fw_dcbx_caps_rsp_t *)ha->hw.mbox;
3177 ql_dump_buf8(ha, __func__, fw_dcbx_rsp,
3178 sizeof (q80_query_fw_dcbx_caps_rsp_t));
3180 err = Q8_MBX_RSP_STATUS(fw_dcbx_rsp->regcnt_status);
3183 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3190 qla_idc_ack(qla_host_t *ha, uint32_t aen_mb1, uint32_t aen_mb2,
3191 uint32_t aen_mb3, uint32_t aen_mb4)
3194 q80_idc_ack_t *idc_ack;
3195 q80_idc_ack_rsp_t *idc_ack_rsp;
3201 idc_ack = (q80_idc_ack_t *)ha->hw.mbox;
3202 bzero(idc_ack, sizeof(q80_idc_ack_t));
3204 idc_ack->opcode = Q8_MBX_IDC_ACK;
3205 idc_ack->count_version = (sizeof (q80_idc_ack_t) >> 2);
3206 idc_ack->count_version |= Q8_MBX_CMD_VERSION;
3208 idc_ack->aen_mb1 = aen_mb1;
3209 idc_ack->aen_mb2 = aen_mb2;
3210 idc_ack->aen_mb3 = aen_mb3;
3211 idc_ack->aen_mb4 = aen_mb4;
3213 ha->hw.imd_compl= 0;
3215 if (qla_mbx_cmd(ha, (uint32_t *)idc_ack,
3216 (sizeof (q80_idc_ack_t) >> 2),
3217 ha->hw.mbox, (sizeof (q80_idc_ack_rsp_t) >> 2), 0)) {
3218 device_printf(dev, "%s: failed\n", __func__);
3222 idc_ack_rsp = (q80_idc_ack_rsp_t *)ha->hw.mbox;
3224 err = Q8_MBX_RSP_STATUS(idc_ack_rsp->regcnt_status);
3227 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3231 while (count && !ha->hw.imd_compl) {
3232 qla_mdelay(__func__, 100);
3239 device_printf(dev, "%s: count %d\n", __func__, count);
3245 qla_set_port_config(qla_host_t *ha, uint32_t cfg_bits)
3248 q80_set_port_cfg_t *pcfg;
3249 q80_set_port_cfg_rsp_t *pfg_rsp;
3255 pcfg = (q80_set_port_cfg_t *)ha->hw.mbox;
3256 bzero(pcfg, sizeof(q80_set_port_cfg_t));
3258 pcfg->opcode = Q8_MBX_SET_PORT_CONFIG;
3259 pcfg->count_version = (sizeof (q80_set_port_cfg_t) >> 2);
3260 pcfg->count_version |= Q8_MBX_CMD_VERSION;
3262 pcfg->cfg_bits = cfg_bits;
3264 device_printf(dev, "%s: cfg_bits"
3265 " [STD_PAUSE_DIR, PAUSE_TYPE, DCBX]"
3266 " [0x%x, 0x%x, 0x%x]\n", __func__,
3267 ((cfg_bits & Q8_PORT_CFG_BITS_STDPAUSE_DIR_MASK)>>20),
3268 ((cfg_bits & Q8_PORT_CFG_BITS_PAUSE_CFG_MASK) >> 5),
3269 ((cfg_bits & Q8_PORT_CFG_BITS_DCBX_ENABLE) ? 1: 0));
3271 ha->hw.imd_compl= 0;
3273 if (qla_mbx_cmd(ha, (uint32_t *)pcfg,
3274 (sizeof (q80_set_port_cfg_t) >> 2),
3275 ha->hw.mbox, (sizeof (q80_set_port_cfg_rsp_t) >> 2), 0)) {
3276 device_printf(dev, "%s: failed\n", __func__);
3280 pfg_rsp = (q80_set_port_cfg_rsp_t *)ha->hw.mbox;
3282 err = Q8_MBX_RSP_STATUS(pfg_rsp->regcnt_status);
3284 if (err == Q8_MBX_RSP_IDC_INTRMD_RSP) {
3285 while (count && !ha->hw.imd_compl) {
3286 qla_mdelay(__func__, 100);
3290 device_printf(dev, "%s: count %d\n", __func__, count);
3297 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3306 qla_get_minidump_tmplt_size(qla_host_t *ha, uint32_t *size)
3309 device_t dev = ha->pci_dev;
3310 q80_config_md_templ_size_t *md_size;
3311 q80_config_md_templ_size_rsp_t *md_size_rsp;
3313 #ifdef QL_LDFLASH_FW
3315 *size = ql83xx_minidump_len;
3318 #endif /* #ifdef QL_LDFLASH_FW */
3320 md_size = (q80_config_md_templ_size_t *) ha->hw.mbox;
3321 bzero(md_size, sizeof(q80_config_md_templ_size_t));
3323 md_size->opcode = Q8_MBX_GET_MINIDUMP_TMPLT_SIZE;
3324 md_size->count_version = (sizeof (q80_config_md_templ_size_t) >> 2);
3325 md_size->count_version |= Q8_MBX_CMD_VERSION;
3327 if (qla_mbx_cmd(ha, (uint32_t *) md_size,
3328 (sizeof(q80_config_md_templ_size_t) >> 2), ha->hw.mbox,
3329 (sizeof(q80_config_md_templ_size_rsp_t) >> 2), 0)) {
3331 device_printf(dev, "%s: failed\n", __func__);
3336 md_size_rsp = (q80_config_md_templ_size_rsp_t *) ha->hw.mbox;
3338 err = Q8_MBX_RSP_STATUS(md_size_rsp->regcnt_status);
3341 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3345 *size = md_size_rsp->templ_size;
3351 qla_get_port_config(qla_host_t *ha, uint32_t *cfg_bits)
3354 q80_get_port_cfg_t *pcfg;
3355 q80_get_port_cfg_rsp_t *pcfg_rsp;
3360 pcfg = (q80_get_port_cfg_t *)ha->hw.mbox;
3361 bzero(pcfg, sizeof(q80_get_port_cfg_t));
3363 pcfg->opcode = Q8_MBX_GET_PORT_CONFIG;
3364 pcfg->count_version = (sizeof (q80_get_port_cfg_t) >> 2);
3365 pcfg->count_version |= Q8_MBX_CMD_VERSION;
3367 if (qla_mbx_cmd(ha, (uint32_t *)pcfg,
3368 (sizeof (q80_get_port_cfg_t) >> 2),
3369 ha->hw.mbox, (sizeof (q80_get_port_cfg_rsp_t) >> 2), 0)) {
3370 device_printf(dev, "%s: failed\n", __func__);
3374 pcfg_rsp = (q80_get_port_cfg_rsp_t *)ha->hw.mbox;
3376 err = Q8_MBX_RSP_STATUS(pcfg_rsp->regcnt_status);
3379 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3383 device_printf(dev, "%s: [cfg_bits, port type]"
3384 " [0x%08x, 0x%02x] [STD_PAUSE_DIR, PAUSE_TYPE, DCBX]"
3385 " [0x%x, 0x%x, 0x%x]\n", __func__,
3386 pcfg_rsp->cfg_bits, pcfg_rsp->phys_port_type,
3387 ((pcfg_rsp->cfg_bits & Q8_PORT_CFG_BITS_STDPAUSE_DIR_MASK)>>20),
3388 ((pcfg_rsp->cfg_bits & Q8_PORT_CFG_BITS_PAUSE_CFG_MASK) >> 5),
3389 ((pcfg_rsp->cfg_bits & Q8_PORT_CFG_BITS_DCBX_ENABLE) ? 1: 0)
3392 *cfg_bits = pcfg_rsp->cfg_bits;
3398 qla_iscsi_pdu(qla_host_t *ha, struct mbuf *mp)
3400 struct ether_vlan_header *eh;
3402 struct ip *ip = NULL;
3403 struct ip6_hdr *ip6 = NULL;
3404 struct tcphdr *th = NULL;
3407 uint8_t buf[sizeof(struct ip6_hdr)];
3409 eh = mtod(mp, struct ether_vlan_header *);
3411 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3412 hdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3413 etype = ntohs(eh->evl_proto);
3415 hdrlen = ETHER_HDR_LEN;
3416 etype = ntohs(eh->evl_encap_proto);
3419 if (etype == ETHERTYPE_IP) {
3421 offset = (hdrlen + sizeof (struct ip));
3423 if (mp->m_len >= offset) {
3424 ip = (struct ip *)(mp->m_data + hdrlen);
3426 m_copydata(mp, hdrlen, sizeof (struct ip), buf);
3427 ip = (struct ip *)buf;
3430 if (ip->ip_p == IPPROTO_TCP) {
3432 hdrlen += ip->ip_hl << 2;
3433 offset = hdrlen + 4;
3435 if (mp->m_len >= offset) {
3436 th = (struct tcphdr *)(mp->m_data + hdrlen);;
3438 m_copydata(mp, hdrlen, 4, buf);
3439 th = (struct tcphdr *)buf;
3443 } else if (etype == ETHERTYPE_IPV6) {
3445 offset = (hdrlen + sizeof (struct ip6_hdr));
3447 if (mp->m_len >= offset) {
3448 ip6 = (struct ip6_hdr *)(mp->m_data + hdrlen);
3450 m_copydata(mp, hdrlen, sizeof (struct ip6_hdr), buf);
3451 ip6 = (struct ip6_hdr *)buf;
3454 if (ip6->ip6_nxt == IPPROTO_TCP) {
3456 hdrlen += sizeof(struct ip6_hdr);
3457 offset = hdrlen + 4;
3459 if (mp->m_len >= offset) {
3460 th = (struct tcphdr *)(mp->m_data + hdrlen);;
3462 m_copydata(mp, hdrlen, 4, buf);
3463 th = (struct tcphdr *)buf;
3469 if ((th->th_sport == htons(3260)) ||
3470 (th->th_dport == htons(3260)))
3477 qla_hw_async_event(qla_host_t *ha)
3479 switch (ha->hw.aen_mb0) {
3481 (void)qla_idc_ack(ha, ha->hw.aen_mb1, ha->hw.aen_mb2,
3482 ha->hw.aen_mb3, ha->hw.aen_mb4);
3493 #ifdef QL_LDFLASH_FW
3495 qla_get_minidump_template(qla_host_t *ha)
3498 device_t dev = ha->pci_dev;
3499 q80_config_md_templ_cmd_t *md_templ;
3500 q80_config_md_templ_cmd_rsp_t *md_templ_rsp;
3502 md_templ = (q80_config_md_templ_cmd_t *) ha->hw.mbox;
3503 bzero(md_templ, (sizeof (q80_config_md_templ_cmd_t)));
3505 md_templ->opcode = Q8_MBX_GET_MINIDUMP_TMPLT;
3506 md_templ->count_version = ( sizeof(q80_config_md_templ_cmd_t) >> 2);
3507 md_templ->count_version |= Q8_MBX_CMD_VERSION;
3509 md_templ->buf_addr = ha->hw.dma_buf.minidump.dma_addr;
3510 md_templ->buff_size = ha->hw.dma_buf.minidump.size;
3512 if (qla_mbx_cmd(ha, (uint32_t *) md_templ,
3513 (sizeof(q80_config_md_templ_cmd_t) >> 2),
3515 (sizeof(q80_config_md_templ_cmd_rsp_t) >> 2), 0)) {
3517 device_printf(dev, "%s: failed\n", __func__);
3522 md_templ_rsp = (q80_config_md_templ_cmd_rsp_t *) ha->hw.mbox;
3524 err = Q8_MBX_RSP_STATUS(md_templ_rsp->regcnt_status);
3527 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err);
3534 #endif /* #ifdef QL_LDFLASH_FW */
3537 qla_minidump_init(qla_host_t *ha)
3540 uint32_t template_size = 0;
3541 device_t dev = ha->pci_dev;
3544 * Get Minidump Template Size
3546 ret = qla_get_minidump_tmplt_size(ha, &template_size);
3548 if (ret || (template_size == 0)) {
3549 device_printf(dev, "%s: failed [%d, %d]\n", __func__, ret,
3555 * Allocate Memory for Minidump Template
3558 ha->hw.dma_buf.minidump.alignment = 8;
3559 ha->hw.dma_buf.minidump.size = template_size;
3561 #ifdef QL_LDFLASH_FW
3562 if (ql_alloc_dmabuf(ha, &ha->hw.dma_buf.minidump)) {
3564 device_printf(dev, "%s: minidump dma alloc failed\n", __func__);
3568 ha->hw.dma_buf.flags.minidump = 1;
3571 * Retrieve Minidump Template
3573 ret = qla_get_minidump_template(ha);
3575 ha->hw.dma_buf.minidump.dma_b = ql83xx_minidump;
3576 #endif /* #ifdef QL_LDFLASH_FW */
3579 qla_minidump_free(ha);
3581 ha->hw.mdump_init = 1;
3589 qla_minidump_free(qla_host_t *ha)
3591 ha->hw.mdump_init = 0;
3592 if (ha->hw.dma_buf.flags.minidump) {
3593 ha->hw.dma_buf.flags.minidump = 0;
3594 ql_free_dmabuf(ha, &ha->hw.dma_buf.minidump);
3600 ql_minidump(qla_host_t *ha)
3602 uint32_t delay = 6000;
3604 if (!ha->hw.mdump_init)
3607 if (!ha->hw.mdump_active)
3610 if (ha->hw.mdump_active == 1) {
3611 ha->hw.mdump_start_seq_index = ql_stop_sequence(ha);
3612 ha->hw.mdump_start = 1;
3615 while (delay-- && ha->hw.mdump_active) {
3616 qla_mdelay(__func__, 100);
3618 ha->hw.mdump_start = 0;
3619 ql_start_sequence(ha, ha->hw.mdump_start_seq_index);