2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2011-2012 Qlogic Corporation
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
32 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
33 * Content: Contains Hardware dependent functions
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
43 #include "qla_inline.h"
48 static uint32_t sysctl_num_rds_rings = 2;
49 static uint32_t sysctl_num_sds_rings = 4;
55 static void qla_init_cntxt_regions(qla_host_t *ha);
56 static int qla_issue_cmd(qla_host_t *ha, qla_cdrp_t *cdrp);
57 static int qla_fw_cmd(qla_host_t *ha, void *fw_cmd, uint32_t size);
58 static int qla_config_mac_addr(qla_host_t *ha, uint8_t *mac_addr,
59 uint16_t cntxt_id, uint32_t add_multi);
60 static void qla_del_rcv_cntxt(qla_host_t *ha);
61 static int qla_init_rcv_cntxt(qla_host_t *ha);
62 static void qla_del_xmt_cntxt(qla_host_t *ha);
63 static int qla_init_xmt_cntxt(qla_host_t *ha);
64 static int qla_get_max_rds(qla_host_t *ha);
65 static int qla_get_max_sds(qla_host_t *ha);
66 static int qla_get_max_rules(qla_host_t *ha);
67 static int qla_get_max_rcv_cntxts(qla_host_t *ha);
68 static int qla_get_max_tx_cntxts(qla_host_t *ha);
69 static int qla_get_max_mtu(qla_host_t *ha);
70 static int qla_get_max_lro(qla_host_t *ha);
71 static int qla_get_flow_control(qla_host_t *ha);
72 static void qla_hw_tx_done_locked(qla_host_t *ha);
75 qla_get_msix_count(qla_host_t *ha)
77 return (sysctl_num_sds_rings);
81 * Name: qla_hw_add_sysctls
82 * Function: Add P3Plus specific sysctls
85 qla_hw_add_sysctls(qla_host_t *ha)
91 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
92 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
93 OID_AUTO, "num_rds_rings", CTLFLAG_RD, &sysctl_num_rds_rings,
94 sysctl_num_rds_rings, "Number of Rcv Descriptor Rings");
96 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
97 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
98 OID_AUTO, "num_sds_rings", CTLFLAG_RD, &sysctl_num_sds_rings,
99 sysctl_num_sds_rings, "Number of Status Descriptor Rings");
104 * Function: Frees the DMA'able memory allocated in qla_alloc_dma()
107 qla_free_dma(qla_host_t *ha)
111 if (ha->hw.dma_buf.flags.context) {
112 qla_free_dmabuf(ha, &ha->hw.dma_buf.context);
113 ha->hw.dma_buf.flags.context = 0;
116 if (ha->hw.dma_buf.flags.sds_ring) {
117 for (i = 0; i < ha->hw.num_sds_rings; i++)
118 qla_free_dmabuf(ha, &ha->hw.dma_buf.sds_ring[i]);
119 ha->hw.dma_buf.flags.sds_ring = 0;
122 if (ha->hw.dma_buf.flags.rds_ring) {
123 for (i = 0; i < ha->hw.num_rds_rings; i++)
124 qla_free_dmabuf(ha, &ha->hw.dma_buf.rds_ring[i]);
125 ha->hw.dma_buf.flags.rds_ring = 0;
128 if (ha->hw.dma_buf.flags.tx_ring) {
129 qla_free_dmabuf(ha, &ha->hw.dma_buf.tx_ring);
130 ha->hw.dma_buf.flags.tx_ring = 0;
135 * Name: qla_alloc_dma
136 * Function: Allocates DMA'able memory for Tx/Rx Rings, Tx/Rx Contexts.
139 qla_alloc_dma(qla_host_t *ha)
146 QL_DPRINT2((dev, "%s: enter\n", __func__));
148 ha->hw.num_rds_rings = (uint16_t)sysctl_num_rds_rings;
149 ha->hw.num_sds_rings = (uint16_t)sysctl_num_sds_rings;
152 * Allocate Transmit Ring
155 ha->hw.dma_buf.tx_ring.alignment = 8;
156 ha->hw.dma_buf.tx_ring.size =
157 (sizeof(q80_tx_cmd_t)) * NUM_TX_DESCRIPTORS;
159 if (qla_alloc_dmabuf(ha, &ha->hw.dma_buf.tx_ring)) {
160 device_printf(dev, "%s: tx ring alloc failed\n", __func__);
161 goto qla_alloc_dma_exit;
163 ha->hw.dma_buf.flags.tx_ring = 1;
165 QL_DPRINT2((dev, "%s: tx_ring phys %p virt %p\n",
166 __func__, (void *)(ha->hw.dma_buf.tx_ring.dma_addr),
167 ha->hw.dma_buf.tx_ring.dma_b));
169 * Allocate Receive Descriptor Rings
172 for (i = 0; i < ha->hw.num_rds_rings; i++) {
173 ha->hw.dma_buf.rds_ring[i].alignment = 8;
175 if (i == RDS_RING_INDEX_NORMAL) {
176 ha->hw.dma_buf.rds_ring[i].size =
177 (sizeof(q80_recv_desc_t)) * NUM_RX_DESCRIPTORS;
178 } else if (i == RDS_RING_INDEX_JUMBO) {
179 ha->hw.dma_buf.rds_ring[i].size =
180 (sizeof(q80_recv_desc_t)) *
181 NUM_RX_JUMBO_DESCRIPTORS;
185 if (qla_alloc_dmabuf(ha, &ha->hw.dma_buf.rds_ring[i])) {
186 QL_DPRINT4((dev, "%s: rds ring alloc failed\n",
189 for (j = 0; j < i; j++)
191 &ha->hw.dma_buf.rds_ring[j]);
193 goto qla_alloc_dma_exit;
195 QL_DPRINT4((dev, "%s: rx_ring[%d] phys %p virt %p\n",
197 (void *)(ha->hw.dma_buf.rds_ring[i].dma_addr),
198 ha->hw.dma_buf.rds_ring[i].dma_b));
200 ha->hw.dma_buf.flags.rds_ring = 1;
203 * Allocate Status Descriptor Rings
206 for (i = 0; i < ha->hw.num_sds_rings; i++) {
207 ha->hw.dma_buf.sds_ring[i].alignment = 8;
208 ha->hw.dma_buf.sds_ring[i].size =
209 (sizeof(q80_stat_desc_t)) * NUM_STATUS_DESCRIPTORS;
211 if (qla_alloc_dmabuf(ha, &ha->hw.dma_buf.sds_ring[i])) {
212 device_printf(dev, "%s: sds ring alloc failed\n",
215 for (j = 0; j < i; j++)
217 &ha->hw.dma_buf.sds_ring[j]);
219 goto qla_alloc_dma_exit;
221 QL_DPRINT4((dev, "%s: sds_ring[%d] phys %p virt %p\n",
223 (void *)(ha->hw.dma_buf.sds_ring[i].dma_addr),
224 ha->hw.dma_buf.sds_ring[i].dma_b));
226 ha->hw.dma_buf.flags.sds_ring = 1;
229 * Allocate Context Area
231 size = QL_ALIGN((sizeof (q80_tx_cntxt_req_t)), QL_BUFFER_ALIGN);
233 size += QL_ALIGN((sizeof (q80_tx_cntxt_rsp_t)), QL_BUFFER_ALIGN);
235 size += QL_ALIGN((sizeof (q80_rcv_cntxt_req_t)), QL_BUFFER_ALIGN);
237 size += QL_ALIGN((sizeof (q80_rcv_cntxt_rsp_t)), QL_BUFFER_ALIGN);
239 size += sizeof (uint32_t); /* for tx consumer index */
241 size = QL_ALIGN(size, PAGE_SIZE);
243 ha->hw.dma_buf.context.alignment = 8;
244 ha->hw.dma_buf.context.size = size;
246 if (qla_alloc_dmabuf(ha, &ha->hw.dma_buf.context)) {
247 device_printf(dev, "%s: context alloc failed\n", __func__);
248 goto qla_alloc_dma_exit;
250 ha->hw.dma_buf.flags.context = 1;
251 QL_DPRINT2((dev, "%s: context phys %p virt %p\n",
252 __func__, (void *)(ha->hw.dma_buf.context.dma_addr),
253 ha->hw.dma_buf.context.dma_b));
255 qla_init_cntxt_regions(ha);
265 * Name: qla_init_cntxt_regions
266 * Function: Initializes Tx/Rx Contexts.
269 qla_init_cntxt_regions(qla_host_t *ha)
272 q80_tx_cntxt_req_t *tx_cntxt_req;
273 q80_rcv_cntxt_req_t *rx_cntxt_req;
274 bus_addr_t phys_addr;
283 hw->tx_ring_base = hw->dma_buf.tx_ring.dma_b;
285 for (i = 0; i < ha->hw.num_sds_rings; i++)
286 hw->sds[i].sds_ring_base =
287 (q80_stat_desc_t *)hw->dma_buf.sds_ring[i].dma_b;
290 phys_addr = hw->dma_buf.context.dma_addr;
292 memset((void *)hw->dma_buf.context.dma_b, 0,
293 ha->hw.dma_buf.context.size);
296 (q80_tx_cntxt_req_t *)hw->dma_buf.context.dma_b;
297 hw->tx_cntxt_req_paddr = phys_addr;
299 size = QL_ALIGN((sizeof (q80_tx_cntxt_req_t)), QL_BUFFER_ALIGN);
302 (q80_tx_cntxt_rsp_t *)((uint8_t *)hw->tx_cntxt_req + size);
303 hw->tx_cntxt_rsp_paddr = hw->tx_cntxt_req_paddr + size;
305 size = QL_ALIGN((sizeof (q80_tx_cntxt_rsp_t)), QL_BUFFER_ALIGN);
308 (q80_rcv_cntxt_req_t *)((uint8_t *)hw->tx_cntxt_rsp + size);
309 hw->rx_cntxt_req_paddr = hw->tx_cntxt_rsp_paddr + size;
311 size = QL_ALIGN((sizeof (q80_rcv_cntxt_req_t)), QL_BUFFER_ALIGN);
314 (q80_rcv_cntxt_rsp_t *)((uint8_t *)hw->rx_cntxt_req + size);
315 hw->rx_cntxt_rsp_paddr = hw->rx_cntxt_req_paddr + size;
317 size = QL_ALIGN((sizeof (q80_rcv_cntxt_rsp_t)), QL_BUFFER_ALIGN);
319 hw->tx_cons = (uint32_t *)((uint8_t *)hw->rx_cntxt_rsp + size);
320 hw->tx_cons_paddr = hw->rx_cntxt_rsp_paddr + size;
323 * Initialize the Transmit Context Request so that we don't need to
324 * do it every time we need to create a context
326 tx_cntxt_req = hw->tx_cntxt_req;
328 tx_cntxt_req->rsp_dma_addr = qla_host_to_le64(hw->tx_cntxt_rsp_paddr);
330 tx_cntxt_req->cmd_cons_dma_addr = qla_host_to_le64(hw->tx_cons_paddr);
332 tx_cntxt_req->caps[0] = qla_host_to_le32((CNTXT_CAP0_BASEFW |
333 CNTXT_CAP0_LEGACY_MN | CNTXT_CAP0_LSO));
335 tx_cntxt_req->intr_mode = qla_host_to_le32(CNTXT_INTR_MODE_SHARED);
337 tx_cntxt_req->phys_addr =
338 qla_host_to_le64(hw->dma_buf.tx_ring.dma_addr);
340 tx_cntxt_req->num_entries = qla_host_to_le32(NUM_TX_DESCRIPTORS);
343 * Initialize the Receive Context Request
346 rx_cntxt_req = hw->rx_cntxt_req;
348 rx_cntxt_req->rx_req.rsp_dma_addr =
349 qla_host_to_le64(hw->rx_cntxt_rsp_paddr);
351 rx_cntxt_req->rx_req.caps[0] = qla_host_to_le32(CNTXT_CAP0_BASEFW |
352 CNTXT_CAP0_LEGACY_MN |
357 rx_cntxt_req->rx_req.intr_mode =
358 qla_host_to_le32(CNTXT_INTR_MODE_SHARED);
360 rx_cntxt_req->rx_req.rds_intr_mode =
361 qla_host_to_le32(CNTXT_INTR_MODE_UNIQUE);
363 rx_cntxt_req->rx_req.rds_ring_offset = 0;
364 rx_cntxt_req->rx_req.sds_ring_offset = qla_host_to_le32(
365 (hw->num_rds_rings * sizeof(q80_rq_rds_ring_t)));
366 rx_cntxt_req->rx_req.num_rds_rings =
367 qla_host_to_le16(hw->num_rds_rings);
368 rx_cntxt_req->rx_req.num_sds_rings =
369 qla_host_to_le16(hw->num_sds_rings);
371 for (i = 0; i < hw->num_rds_rings; i++) {
372 rx_cntxt_req->rds_req[i].phys_addr =
373 qla_host_to_le64(hw->dma_buf.rds_ring[i].dma_addr);
375 if (i == RDS_RING_INDEX_NORMAL) {
376 rx_cntxt_req->rds_req[i].buf_size =
377 qla_host_to_le64(MCLBYTES);
378 rx_cntxt_req->rds_req[i].size =
379 qla_host_to_le32(NUM_RX_DESCRIPTORS);
381 rx_cntxt_req->rds_req[i].buf_size =
382 qla_host_to_le64(MJUM9BYTES);
383 rx_cntxt_req->rds_req[i].size =
384 qla_host_to_le32(NUM_RX_JUMBO_DESCRIPTORS);
388 for (i = 0; i < hw->num_sds_rings; i++) {
389 rx_cntxt_req->sds_req[i].phys_addr =
390 qla_host_to_le64(hw->dma_buf.sds_ring[i].dma_addr);
391 rx_cntxt_req->sds_req[i].size =
392 qla_host_to_le32(NUM_STATUS_DESCRIPTORS);
393 rx_cntxt_req->sds_req[i].msi_index = qla_host_to_le16(i);
396 QL_DPRINT2((ha->pci_dev, "%s: tx_cntxt_req = %p paddr %p\n",
397 __func__, hw->tx_cntxt_req, (void *)hw->tx_cntxt_req_paddr));
398 QL_DPRINT2((ha->pci_dev, "%s: tx_cntxt_rsp = %p paddr %p\n",
399 __func__, hw->tx_cntxt_rsp, (void *)hw->tx_cntxt_rsp_paddr));
400 QL_DPRINT2((ha->pci_dev, "%s: rx_cntxt_req = %p paddr %p\n",
401 __func__, hw->rx_cntxt_req, (void *)hw->rx_cntxt_req_paddr));
402 QL_DPRINT2((ha->pci_dev, "%s: rx_cntxt_rsp = %p paddr %p\n",
403 __func__, hw->rx_cntxt_rsp, (void *)hw->rx_cntxt_rsp_paddr));
404 QL_DPRINT2((ha->pci_dev, "%s: tx_cons = %p paddr %p\n",
405 __func__, hw->tx_cons, (void *)hw->tx_cons_paddr));
409 * Name: qla_issue_cmd
410 * Function: Issues commands on the CDRP interface and returns responses.
413 qla_issue_cmd(qla_host_t *ha, qla_cdrp_t *cdrp)
417 uint32_t count = 400; /* 4 seconds or 400 10ms intervals */
423 signature = 0xcafe0000 | 0x0100 | ha->pci_func;
425 ret = qla_sem_lock(ha, Q8_SEM5_LOCK, 0, (uint32_t)ha->pci_func);
428 device_printf(dev, "%s: SEM5_LOCK lock failed\n", __func__);
432 WRITE_OFFSET32(ha, Q8_NX_CDRP_SIGNATURE, signature);
434 WRITE_OFFSET32(ha, Q8_NX_CDRP_ARG1, (cdrp->cmd_arg1));
435 WRITE_OFFSET32(ha, Q8_NX_CDRP_ARG2, (cdrp->cmd_arg2));
436 WRITE_OFFSET32(ha, Q8_NX_CDRP_ARG3, (cdrp->cmd_arg3));
438 WRITE_OFFSET32(ha, Q8_NX_CDRP_CMD_RSP, cdrp->cmd);
441 qla_mdelay(__func__, 10);
443 data = READ_REG32(ha, Q8_NX_CDRP_CMD_RSP);
445 if ((!(data & 0x80000000)))
449 if ((!count) || (data != 1))
452 cdrp->rsp = READ_REG32(ha, Q8_NX_CDRP_CMD_RSP);
453 cdrp->rsp_arg1 = READ_REG32(ha, Q8_NX_CDRP_ARG1);
454 cdrp->rsp_arg2 = READ_REG32(ha, Q8_NX_CDRP_ARG2);
455 cdrp->rsp_arg3 = READ_REG32(ha, Q8_NX_CDRP_ARG3);
457 qla_sem_unlock(ha, Q8_SEM5_UNLOCK);
460 device_printf(dev, "%s: "
461 "cmd[0x%08x] = 0x%08x\n"
462 "\tsig[0x%08x] = 0x%08x\n"
463 "\targ1[0x%08x] = 0x%08x\n"
464 "\targ2[0x%08x] = 0x%08x\n"
465 "\targ3[0x%08x] = 0x%08x\n",
466 __func__, Q8_NX_CDRP_CMD_RSP, cdrp->cmd,
467 Q8_NX_CDRP_SIGNATURE, signature,
468 Q8_NX_CDRP_ARG1, cdrp->cmd_arg1,
469 Q8_NX_CDRP_ARG2, cdrp->cmd_arg2,
470 Q8_NX_CDRP_ARG3, cdrp->cmd_arg3);
472 device_printf(dev, "%s: exit (ret = 0x%x)\n"
473 "\t\t rsp = 0x%08x\n"
474 "\t\t arg1 = 0x%08x\n"
475 "\t\t arg2 = 0x%08x\n"
476 "\t\t arg3 = 0x%08x\n",
477 __func__, ret, cdrp->rsp,
478 cdrp->rsp_arg1, cdrp->rsp_arg2, cdrp->rsp_arg3);
484 #define QLA_TX_MIN_FREE 2
488 * Function: Issues firmware control commands on the Tx Ring.
491 qla_fw_cmd(qla_host_t *ha, void *fw_cmd, uint32_t size)
494 q80_tx_cmd_t *tx_cmd;
495 qla_hw_t *hw = &ha->hw;
502 if (hw->txr_free <= QLA_TX_MIN_FREE) {
504 qla_hw_tx_done_locked(ha);
505 if (hw->txr_free > QLA_TX_MIN_FREE)
509 qla_mdelay(__func__, 10);
512 if (hw->txr_free <= QLA_TX_MIN_FREE) {
514 device_printf(dev, "%s: xmit queue full\n", __func__);
518 tx_cmd = &hw->tx_ring_base[hw->txr_next];
520 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
522 bcopy(fw_cmd, tx_cmd, size);
524 hw->txr_next = (hw->txr_next + 1) & (NUM_TX_DESCRIPTORS - 1);
527 QL_UPDATE_TX_PRODUCER_INDEX(ha, hw->txr_next);
535 * Name: qla_config_rss
536 * Function: Configure RSS for the context/interface.
538 const uint64_t rss_key[] = { 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
539 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
540 0x255b0ec26d5a56daULL };
543 qla_config_rss(qla_host_t *ha, uint16_t cntxt_id)
545 qla_fw_cds_config_rss_t rss_config;
548 bzero(&rss_config, sizeof(qla_fw_cds_config_rss_t));
550 rss_config.hdr.cmd = Q8_FWCD_CNTRL_REQ;
551 rss_config.hdr.opcode = Q8_FWCD_OPCODE_CONFIG_RSS;
552 rss_config.hdr.cntxt_id = cntxt_id;
554 rss_config.hash_type = (Q8_FWCD_RSS_HASH_TYPE_IPV4_TCP_IP |
555 Q8_FWCD_RSS_HASH_TYPE_IPV6_TCP_IP);
556 rss_config.flags = Q8_FWCD_RSS_FLAGS_ENABLE_RSS;
558 rss_config.ind_tbl_mask = 0x7;
560 for (i = 0; i < 5; i++)
561 rss_config.rss_key[i] = rss_key[i];
563 ret = qla_fw_cmd(ha, &rss_config, sizeof(qla_fw_cds_config_rss_t));
569 * Name: qla_config_intr_coalesce
570 * Function: Configure Interrupt Coalescing.
573 qla_config_intr_coalesce(qla_host_t *ha, uint16_t cntxt_id, int tenable)
575 qla_fw_cds_config_intr_coalesc_t intr_coalesce;
578 bzero(&intr_coalesce, sizeof(qla_fw_cds_config_intr_coalesc_t));
580 intr_coalesce.hdr.cmd = Q8_FWCD_CNTRL_REQ;
581 intr_coalesce.hdr.opcode = Q8_FWCD_OPCODE_CONFIG_INTR_COALESCING;
582 intr_coalesce.hdr.cntxt_id = cntxt_id;
584 intr_coalesce.flags = 0x04;
585 intr_coalesce.max_rcv_pkts = 256;
586 intr_coalesce.max_rcv_usecs = 3;
587 intr_coalesce.max_snd_pkts = 64;
588 intr_coalesce.max_snd_usecs = 4;
591 intr_coalesce.usecs_to = 1000; /* 1 millisecond */
592 intr_coalesce.timer_type = Q8_FWCMD_INTR_COALESC_TIMER_PERIODIC;
593 intr_coalesce.sds_ring_bitmask =
594 Q8_FWCMD_INTR_COALESC_SDS_RING_0;
597 ret = qla_fw_cmd(ha, &intr_coalesce,
598 sizeof(qla_fw_cds_config_intr_coalesc_t));
605 * Name: qla_config_mac_addr
606 * Function: binds a MAC address to the context/interface.
607 * Can be unicast, multicast or broadcast.
610 qla_config_mac_addr(qla_host_t *ha, uint8_t *mac_addr, uint16_t cntxt_id,
613 qla_fw_cds_config_mac_addr_t mac_config;
616 // device_printf(ha->pci_dev,
617 // "%s: mac_addr %02x:%02x:%02x:%02x:%02x:%02x\n", __func__,
618 // mac_addr[0], mac_addr[1], mac_addr[2],
619 // mac_addr[3], mac_addr[4], mac_addr[5]);
621 bzero(&mac_config, sizeof(qla_fw_cds_config_mac_addr_t));
623 mac_config.hdr.cmd = Q8_FWCD_CNTRL_REQ;
624 mac_config.hdr.opcode = Q8_FWCD_OPCODE_CONFIG_MAC_ADDR;
625 mac_config.hdr.cntxt_id = cntxt_id;
628 mac_config.cmd = Q8_FWCD_ADD_MAC_ADDR;
630 mac_config.cmd = Q8_FWCD_DEL_MAC_ADDR;
631 bcopy(mac_addr, mac_config.mac_addr,6);
633 ret = qla_fw_cmd(ha, &mac_config, sizeof(qla_fw_cds_config_mac_addr_t));
640 * Name: qla_set_mac_rcv_mode
641 * Function: Enable/Disable AllMulticast and Promiscuous Modes.
644 qla_set_mac_rcv_mode(qla_host_t *ha, uint16_t cntxt_id, uint32_t mode)
646 qla_set_mac_rcv_mode_t rcv_mode;
649 bzero(&rcv_mode, sizeof(qla_set_mac_rcv_mode_t));
651 rcv_mode.hdr.cmd = Q8_FWCD_CNTRL_REQ;
652 rcv_mode.hdr.opcode = Q8_FWCD_OPCODE_CONFIG_MAC_RCV_MODE;
653 rcv_mode.hdr.cntxt_id = cntxt_id;
655 rcv_mode.mode = mode;
657 ret = qla_fw_cmd(ha, &rcv_mode, sizeof(qla_set_mac_rcv_mode_t));
663 qla_set_promisc(qla_host_t *ha)
665 (void)qla_set_mac_rcv_mode(ha,
666 (ha->hw.rx_cntxt_rsp)->rx_rsp.cntxt_id,
667 Q8_MAC_RCV_ENABLE_PROMISCUOUS);
671 qla_set_allmulti(qla_host_t *ha)
673 (void)qla_set_mac_rcv_mode(ha,
674 (ha->hw.rx_cntxt_rsp)->rx_rsp.cntxt_id,
675 Q8_MAC_RCV_ENABLE_ALLMULTI);
679 qla_reset_promisc_allmulti(qla_host_t *ha)
681 (void)qla_set_mac_rcv_mode(ha,
682 (ha->hw.rx_cntxt_rsp)->rx_rsp.cntxt_id,
683 Q8_MAC_RCV_RESET_PROMISC_ALLMULTI);
687 * Name: qla_config_ipv4_addr
688 * Function: Configures the Destination IP Addr for LRO.
691 qla_config_ipv4_addr(qla_host_t *ha, uint32_t ipv4_addr)
693 qla_config_ipv4_t ip_conf;
695 bzero(&ip_conf, sizeof(qla_config_ipv4_t));
697 ip_conf.hdr.cmd = Q8_FWCD_CNTRL_REQ;
698 ip_conf.hdr.opcode = Q8_FWCD_OPCODE_CONFIG_IPADDR;
699 ip_conf.hdr.cntxt_id = (ha->hw.rx_cntxt_rsp)->rx_rsp.cntxt_id;
701 ip_conf.cmd = (uint64_t)Q8_CONFIG_CMD_IP_ENABLE;
702 ip_conf.ipv4_addr = (uint64_t)ipv4_addr;
704 (void)qla_fw_cmd(ha, &ip_conf, sizeof(qla_config_ipv4_t));
711 * Function: Checks if the packet to be transmitted is a candidate for
712 * Large TCP Segment Offload. If yes, the appropriate fields in the Tx
713 * Ring Structure are plugged in.
716 qla_tx_tso(qla_host_t *ha, struct mbuf *mp, q80_tx_cmd_t *tx_cmd, uint8_t *hdr)
718 struct ether_vlan_header *eh;
719 struct ip *ip = NULL;
720 struct tcphdr *th = NULL;
721 uint32_t ehdrlen, hdrlen = 0, ip_hlen, tcp_hlen, tcp_opt_off;
722 uint16_t etype, opcode, offload = 1;
728 eh = mtod(mp, struct ether_vlan_header *);
730 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
731 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
732 etype = ntohs(eh->evl_proto);
734 ehdrlen = ETHER_HDR_LEN;
735 etype = ntohs(eh->evl_encap_proto);
741 tcp_opt_off = ehdrlen + sizeof(struct ip) +
742 sizeof(struct tcphdr);
744 if (mp->m_len < tcp_opt_off) {
745 m_copydata(mp, 0, tcp_opt_off, hdr);
746 ip = (struct ip *)hdr;
748 ip = (struct ip *)(mp->m_data + ehdrlen);
751 ip_hlen = ip->ip_hl << 2;
752 opcode = Q8_TX_CMD_OP_XMT_TCP_LSO;
754 if ((ip->ip_p != IPPROTO_TCP) ||
755 (ip_hlen != sizeof (struct ip))) {
758 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
763 QL_DPRINT8((dev, "%s: type!=ip\n", __func__));
771 tcp_hlen = th->th_off << 2;
774 hdrlen = ehdrlen + ip_hlen + tcp_hlen;
776 if (mp->m_len < hdrlen) {
777 if (mp->m_len < tcp_opt_off) {
778 if (tcp_hlen > sizeof(struct tcphdr)) {
779 m_copydata(mp, tcp_opt_off,
780 (tcp_hlen - sizeof(struct tcphdr)),
784 m_copydata(mp, 0, hdrlen, hdr);
788 if ((mp->m_pkthdr.csum_flags & CSUM_TSO) == 0) {
790 /* If TCP options are preset only time stamp option is supported */
791 if ((tcp_hlen - sizeof(struct tcphdr)) != 10)
795 if (mp->m_len < hdrlen) {
796 tcp_opt = &hdr[tcp_opt_off];
798 tcp_opt = (uint8_t *)(mp->m_data + tcp_opt_off);
801 if ((*tcp_opt != 0x01) || (*(tcp_opt + 1) != 0x01) ||
802 (*(tcp_opt + 2) != 0x08) ||
803 (*(tcp_opt + 3) != 10)) {
808 tx_cmd->mss = ha->max_frame_size - ETHER_CRC_LEN - hdrlen;
810 tx_cmd->mss = mp->m_pkthdr.tso_segsz;
813 tx_cmd->flags_opcode = opcode ;
814 tx_cmd->tcp_hdr_off = ip_hlen + ehdrlen;
815 tx_cmd->ip_hdr_off = ehdrlen;
816 tx_cmd->mss = mp->m_pkthdr.tso_segsz;
817 tx_cmd->total_hdr_len = hdrlen;
819 /* Check for Multicast least significant bit of MSB == 1 */
820 if (eh->evl_dhost[0] & 0x01) {
821 tx_cmd->flags_opcode = Q8_TX_CMD_FLAGS_MULTICAST;
824 if (mp->m_len < hdrlen) {
832 * Name: qla_tx_chksum
833 * Function: Checks if the packet to be transmitted is a candidate for
834 * TCP/UDP Checksum offload. If yes, the appropriate fields in the Tx
835 * Ring Structure are plugged in.
838 qla_tx_chksum(qla_host_t *ha, struct mbuf *mp, q80_tx_cmd_t *tx_cmd)
840 struct ether_vlan_header *eh;
843 uint32_t ehdrlen, ip_hlen;
844 uint16_t etype, opcode, offload = 1;
849 if ((mp->m_pkthdr.csum_flags & (CSUM_TCP|CSUM_UDP)) == 0)
852 eh = mtod(mp, struct ether_vlan_header *);
854 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
855 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
856 etype = ntohs(eh->evl_proto);
858 ehdrlen = ETHER_HDR_LEN;
859 etype = ntohs(eh->evl_encap_proto);
865 ip = (struct ip *)(mp->m_data + ehdrlen);
867 ip_hlen = sizeof (struct ip);
869 if (mp->m_len < (ehdrlen + ip_hlen)) {
870 device_printf(dev, "%s: ipv4 mlen\n", __func__);
875 if (ip->ip_p == IPPROTO_TCP)
876 opcode = Q8_TX_CMD_OP_XMT_TCP_CHKSUM;
877 else if (ip->ip_p == IPPROTO_UDP)
878 opcode = Q8_TX_CMD_OP_XMT_UDP_CHKSUM;
880 device_printf(dev, "%s: ipv4\n", __func__);
886 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
888 ip_hlen = sizeof(struct ip6_hdr);
890 if (mp->m_len < (ehdrlen + ip_hlen)) {
891 device_printf(dev, "%s: ipv6 mlen\n", __func__);
896 if (ip6->ip6_nxt == IPPROTO_TCP)
897 opcode = Q8_TX_CMD_OP_XMT_TCP_CHKSUM_IPV6;
898 else if (ip6->ip6_nxt == IPPROTO_UDP)
899 opcode = Q8_TX_CMD_OP_XMT_UDP_CHKSUM_IPV6;
901 device_printf(dev, "%s: ipv6\n", __func__);
913 tx_cmd->flags_opcode = opcode;
915 tx_cmd->tcp_hdr_off = ip_hlen + ehdrlen;
922 * Function: Transmits a packet. It first checks if the packet is a
923 * candidate for Large TCP Segment Offload and then for UDP/TCP checksum
924 * offload. If either of these creteria are not met, it is transmitted
925 * as a regular ethernet frame.
928 qla_hw_send(qla_host_t *ha, bus_dma_segment_t *segs, int nsegs,
929 uint32_t *tx_idx, struct mbuf *mp)
931 struct ether_vlan_header *eh;
932 qla_hw_t *hw = &ha->hw;
933 q80_tx_cmd_t *tx_cmd, tso_cmd;
934 bus_dma_segment_t *c_seg;
935 uint32_t num_tx_cmds, hdr_len = 0;
936 uint32_t total_length = 0, bytes, tx_cmd_count = 0;
939 uint8_t *src = NULL, *dst = NULL;
944 * Always make sure there is atleast one empty slot in the tx_ring
945 * tx_ring is considered full when there only one entry available
947 num_tx_cmds = (nsegs + (Q8_TX_CMD_MAX_SEGMENTS - 1)) >> 2;
949 total_length = mp->m_pkthdr.len;
950 if (total_length > QLA_MAX_TSO_FRAME_SIZE) {
951 device_printf(dev, "%s: total length exceeds maxlen(%d)\n",
952 __func__, total_length);
955 eh = mtod(mp, struct ether_vlan_header *);
957 if ((mp->m_pkthdr.len > ha->max_frame_size)||(nsegs > Q8_TX_MAX_SEGMENTS)) {
959 bzero((void *)&tso_cmd, sizeof(q80_tx_cmd_t));
961 src = ha->hw.frame_hdr;
962 ret = qla_tx_tso(ha, mp, &tso_cmd, src);
965 /* find the additional tx_cmd descriptors required */
967 hdr_len = tso_cmd.total_hdr_len;
969 bytes = sizeof(q80_tx_cmd_t) - Q8_TX_CMD_TSO_ALIGN;
970 bytes = QL_MIN(bytes, hdr_len);
976 bytes = QL_MIN((sizeof(q80_tx_cmd_t)), hdr_len);
980 hdr_len = tso_cmd.total_hdr_len;
987 if (hw->txr_free <= (num_tx_cmds + QLA_TX_MIN_FREE)) {
988 qla_hw_tx_done_locked(ha);
989 if (hw->txr_free <= (num_tx_cmds + QLA_TX_MIN_FREE)) {
990 QL_DPRINT8((dev, "%s: (hw->txr_free <= "
991 "(num_tx_cmds + QLA_TX_MIN_FREE))\n",
997 *tx_idx = hw->txr_next;
999 tx_cmd = &hw->tx_ring_base[hw->txr_next];
1002 if ((nsegs > Q8_TX_MAX_SEGMENTS) ||
1003 (mp->m_pkthdr.len > ha->max_frame_size)){
1005 "%s: (nsegs[%d, %d, 0x%b] > Q8_TX_MAX_SEGMENTS)\n",
1006 __func__, nsegs, mp->m_pkthdr.len,
1007 (int)mp->m_pkthdr.csum_flags, CSUM_BITS);
1008 qla_dump_buf8(ha, "qla_hw_send: wrong pkt",
1009 mtod(mp, char *), mp->m_len);
1012 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1013 if (qla_tx_chksum(ha, mp, tx_cmd) != 0)
1014 tx_cmd->flags_opcode = Q8_TX_CMD_OP_XMT_ETHER;
1016 bcopy(&tso_cmd, tx_cmd, sizeof(q80_tx_cmd_t));
1019 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN))
1020 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_VLAN_TAGGED;
1021 else if (mp->m_flags & M_VLANTAG) {
1022 tx_cmd->flags_opcode |= (Q8_TX_CMD_FLAGS_VLAN_TAGGED |
1023 Q8_TX_CMD_FLAGS_HW_VLAN_ID);
1024 tx_cmd->vlan_tci = mp->m_pkthdr.ether_vtag;
1028 tx_cmd->n_bufs = (uint8_t)nsegs;
1029 tx_cmd->data_len_lo = (uint8_t)(total_length & 0xFF);
1030 tx_cmd->data_len_hi = qla_host_to_le16(((uint16_t)(total_length >> 8)));
1031 tx_cmd->port_cntxtid = Q8_TX_CMD_PORT_CNXTID(ha->pci_func);
1036 for (i = 0; ((i < Q8_TX_CMD_MAX_SEGMENTS) && nsegs); i++) {
1040 tx_cmd->buf1_addr = c_seg->ds_addr;
1041 tx_cmd->buf1_len = c_seg->ds_len;
1045 tx_cmd->buf2_addr = c_seg->ds_addr;
1046 tx_cmd->buf2_len = c_seg->ds_len;
1050 tx_cmd->buf3_addr = c_seg->ds_addr;
1051 tx_cmd->buf3_len = c_seg->ds_len;
1055 tx_cmd->buf4_addr = c_seg->ds_addr;
1056 tx_cmd->buf4_len = c_seg->ds_len;
1064 hw->txr_next = (hw->txr_next + 1) & (NUM_TX_DESCRIPTORS - 1);
1070 tx_cmd = &hw->tx_ring_base[hw->txr_next];
1071 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1075 /* TSO : Copy the header in the following tx cmd descriptors */
1077 tx_cmd = &hw->tx_ring_base[hw->txr_next];
1078 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1080 bytes = sizeof(q80_tx_cmd_t) - Q8_TX_CMD_TSO_ALIGN;
1081 bytes = QL_MIN(bytes, hdr_len);
1083 dst = (uint8_t *)tx_cmd + Q8_TX_CMD_TSO_ALIGN;
1085 if (mp->m_flags & M_VLANTAG) {
1086 /* first copy the src/dst MAC addresses */
1087 bcopy(src, dst, (ETHER_ADDR_LEN * 2));
1088 dst += (ETHER_ADDR_LEN * 2);
1089 src += (ETHER_ADDR_LEN * 2);
1091 hdr_len -= (ETHER_ADDR_LEN * 2);
1093 *((uint16_t *)dst) = htons(ETHERTYPE_VLAN);
1095 *((uint16_t *)dst) = mp->m_pkthdr.ether_vtag;
1098 bytes -= ((ETHER_ADDR_LEN * 2) + 4);
1100 bcopy(src, dst, bytes);
1104 bcopy(src, dst, bytes);
1109 hw->txr_next = (hw->txr_next + 1) & (NUM_TX_DESCRIPTORS - 1);
1113 tx_cmd = &hw->tx_ring_base[hw->txr_next];
1114 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t));
1116 bytes = QL_MIN((sizeof(q80_tx_cmd_t)), hdr_len);
1118 bcopy(src, tx_cmd, bytes);
1122 (hw->txr_next + 1) & (NUM_TX_DESCRIPTORS - 1);
1127 hw->txr_free = hw->txr_free - tx_cmd_count;
1129 QL_UPDATE_TX_PRODUCER_INDEX(ha, hw->txr_next);
1130 QL_DPRINT8((dev, "%s: return\n", __func__));
1135 * Name: qla_del_hw_if
1136 * Function: Destroys the hardware specific entities corresponding to an
1137 * Ethernet Interface
1140 qla_del_hw_if(qla_host_t *ha)
1144 for (i = 0; i < ha->hw.num_sds_rings; i++)
1145 QL_DISABLE_INTERRUPTS(ha, i);
1147 qla_del_rcv_cntxt(ha);
1148 qla_del_xmt_cntxt(ha);
1150 ha->hw.flags.lro = 0;
1154 * Name: qla_init_hw_if
1155 * Function: Creates the hardware specific entities corresponding to an
1156 * Ethernet Interface - Transmit and Receive Contexts. Sets the MAC Address
1157 * corresponding to the interface. Enables LRO if allowed.
1160 qla_init_hw_if(qla_host_t *ha)
1164 uint8_t bcast_mac[6];
1166 qla_get_hw_caps(ha);
1170 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1171 bzero(ha->hw.dma_buf.sds_ring[i].dma_b,
1172 ha->hw.dma_buf.sds_ring[i].size);
1175 * Create Receive Context
1177 if (qla_init_rcv_cntxt(ha)) {
1181 ha->hw.rx_next = NUM_RX_DESCRIPTORS - 2;
1182 ha->hw.rxj_next = NUM_RX_JUMBO_DESCRIPTORS - 2;
1183 ha->hw.rx_in = ha->hw.rxj_in = 0;
1185 /* Update the RDS Producer Indices */
1186 QL_UPDATE_RDS_PRODUCER_INDEX(ha, 0, ha->hw.rx_next);
1187 QL_UPDATE_RDS_PRODUCER_INDEX(ha, 1, ha->hw.rxj_next);
1190 * Create Transmit Context
1192 if (qla_init_xmt_cntxt(ha)) {
1193 qla_del_rcv_cntxt(ha);
1197 qla_config_mac_addr(ha, ha->hw.mac_addr,
1198 (ha->hw.rx_cntxt_rsp)->rx_rsp.cntxt_id, 1);
1200 bcast_mac[0] = 0xFF; bcast_mac[1] = 0xFF; bcast_mac[2] = 0xFF;
1201 bcast_mac[3] = 0xFF; bcast_mac[4] = 0xFF; bcast_mac[5] = 0xFF;
1202 qla_config_mac_addr(ha, bcast_mac,
1203 (ha->hw.rx_cntxt_rsp)->rx_rsp.cntxt_id, 1);
1205 qla_config_rss(ha, (ha->hw.rx_cntxt_rsp)->rx_rsp.cntxt_id);
1207 qla_config_intr_coalesce(ha, (ha->hw.rx_cntxt_rsp)->rx_rsp.cntxt_id, 0);
1209 for (i = 0; i < ha->hw.num_sds_rings; i++)
1210 QL_ENABLE_INTERRUPTS(ha, i);
1216 * Name: qla_init_rcv_cntxt
1217 * Function: Creates the Receive Context.
1220 qla_init_rcv_cntxt(qla_host_t *ha)
1224 q80_rcv_cntxt_rsp_t *rsp;
1225 q80_stat_desc_t *sdesc;
1226 bus_addr_t phys_addr;
1228 qla_hw_t *hw = &ha->hw;
1233 * Create Receive Context
1236 for (i = 0; i < hw->num_sds_rings; i++) {
1237 sdesc = (q80_stat_desc_t *)&hw->sds[i].sds_ring_base[0];
1238 for (j = 0; j < NUM_STATUS_DESCRIPTORS; j++) {
1240 Q8_STAT_DESC_SET_OWNER(Q8_STAT_DESC_OWNER_FW);
1244 phys_addr = ha->hw.rx_cntxt_req_paddr;
1246 bzero(&cdrp, sizeof(qla_cdrp_t));
1248 cdrp.cmd = Q8_CMD_CREATE_RX_CNTXT;
1249 cdrp.cmd_arg1 = (uint32_t)(phys_addr >> 32);
1250 cdrp.cmd_arg2 = (uint32_t)(phys_addr);
1251 cdrp.cmd_arg3 = (uint32_t)(sizeof (q80_rcv_cntxt_req_t));
1253 if (qla_issue_cmd(ha, &cdrp)) {
1254 device_printf(dev, "%s: Q8_CMD_CREATE_RX_CNTXT failed\n",
1258 rsp = ha->hw.rx_cntxt_rsp;
1260 QL_DPRINT2((dev, "%s: rcv cntxt successful"
1261 " rds_ring_offset = 0x%08x"
1262 " sds_ring_offset = 0x%08x"
1263 " cntxt_state = 0x%08x"
1264 " funcs_per_port = 0x%08x"
1265 " num_rds_rings = 0x%04x"
1266 " num_sds_rings = 0x%04x"
1267 " cntxt_id = 0x%04x"
1268 " phys_port = 0x%02x"
1269 " virt_port = 0x%02x\n",
1271 rsp->rx_rsp.rds_ring_offset,
1272 rsp->rx_rsp.sds_ring_offset,
1273 rsp->rx_rsp.cntxt_state,
1274 rsp->rx_rsp.funcs_per_port,
1275 rsp->rx_rsp.num_rds_rings,
1276 rsp->rx_rsp.num_sds_rings,
1277 rsp->rx_rsp.cntxt_id,
1278 rsp->rx_rsp.phys_port,
1279 rsp->rx_rsp.virt_port));
1281 for (i = 0; i < ha->hw.num_rds_rings; i++) {
1283 "%s: rcv cntxt rds[%i].producer_reg = 0x%08x\n",
1284 __func__, i, rsp->rds_rsp[i].producer_reg));
1286 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1288 "%s: rcv cntxt sds[%i].consumer_reg = 0x%08x"
1289 " sds[%i].intr_mask_reg = 0x%08x\n",
1290 __func__, i, rsp->sds_rsp[i].consumer_reg,
1291 i, rsp->sds_rsp[i].intr_mask_reg));
1294 ha->hw.flags.init_rx_cnxt = 1;
1299 * Name: qla_del_rcv_cntxt
1300 * Function: Destroys the Receive Context.
1303 qla_del_rcv_cntxt(qla_host_t *ha)
1306 device_t dev = ha->pci_dev;
1308 if (!ha->hw.flags.init_rx_cnxt)
1311 bzero(&cdrp, sizeof(qla_cdrp_t));
1313 cdrp.cmd = Q8_CMD_DESTROY_RX_CNTXT;
1314 cdrp.cmd_arg1 = (uint32_t) (ha->hw.rx_cntxt_rsp)->rx_rsp.cntxt_id;
1316 if (qla_issue_cmd(ha, &cdrp)) {
1317 device_printf(dev, "%s: Q8_CMD_DESTROY_RX_CNTXT failed\n",
1320 ha->hw.flags.init_rx_cnxt = 0;
1324 * Name: qla_init_xmt_cntxt
1325 * Function: Creates the Transmit Context.
1328 qla_init_xmt_cntxt(qla_host_t *ha)
1330 bus_addr_t phys_addr;
1332 q80_tx_cntxt_rsp_t *tx_rsp;
1334 qla_hw_t *hw = &ha->hw;
1339 * Create Transmit Context
1341 phys_addr = ha->hw.tx_cntxt_req_paddr;
1342 tx_rsp = ha->hw.tx_cntxt_rsp;
1344 hw->txr_comp = hw->txr_next = 0;
1347 bzero(&cdrp, sizeof(qla_cdrp_t));
1349 cdrp.cmd = Q8_CMD_CREATE_TX_CNTXT;
1350 cdrp.cmd_arg1 = (uint32_t)(phys_addr >> 32);
1351 cdrp.cmd_arg2 = (uint32_t)(phys_addr);
1352 cdrp.cmd_arg3 = (uint32_t)(sizeof (q80_tx_cntxt_req_t));
1354 if (qla_issue_cmd(ha, &cdrp)) {
1355 device_printf(dev, "%s: Q8_CMD_CREATE_TX_CNTXT failed\n",
1359 ha->hw.tx_prod_reg = tx_rsp->producer_reg;
1361 QL_DPRINT2((dev, "%s: tx cntxt successful"
1362 " cntxt_state = 0x%08x "
1363 " cntxt_id = 0x%04x "
1364 " phys_port_id = 0x%02x "
1365 " virt_port_id = 0x%02x "
1366 " producer_reg = 0x%08x "
1367 " intr_mask_reg = 0x%08x\n",
1368 __func__, tx_rsp->cntxt_state, tx_rsp->cntxt_id,
1369 tx_rsp->phys_port_id, tx_rsp->virt_port_id,
1370 tx_rsp->producer_reg, tx_rsp->intr_mask_reg));
1372 ha->hw.txr_free = NUM_TX_DESCRIPTORS;
1374 ha->hw.flags.init_tx_cnxt = 1;
1379 * Name: qla_del_xmt_cntxt
1380 * Function: Destroys the Transmit Context.
1383 qla_del_xmt_cntxt(qla_host_t *ha)
1386 device_t dev = ha->pci_dev;
1388 if (!ha->hw.flags.init_tx_cnxt)
1391 bzero(&cdrp, sizeof(qla_cdrp_t));
1393 cdrp.cmd = Q8_CMD_DESTROY_TX_CNTXT;
1394 cdrp.cmd_arg1 = (uint32_t) (ha->hw.tx_cntxt_rsp)->cntxt_id;
1396 if (qla_issue_cmd(ha, &cdrp)) {
1397 device_printf(dev, "%s: Q8_CMD_DESTROY_TX_CNTXT failed\n",
1400 ha->hw.flags.init_tx_cnxt = 0;
1404 * Name: qla_get_max_rds
1405 * Function: Returns the maximum number of Receive Descriptor Rings per context.
1408 qla_get_max_rds(qla_host_t *ha)
1415 bzero(&cdrp, sizeof(qla_cdrp_t));
1417 cdrp.cmd = Q8_CMD_RD_MAX_RDS_PER_CNTXT;
1419 if (qla_issue_cmd(ha, &cdrp)) {
1420 device_printf(dev, "%s: Q8_CMD_RD_MAX_RDS_PER_CNTXT failed\n",
1424 ha->hw.max_rds_per_cntxt = cdrp.rsp_arg1;
1425 QL_DPRINT2((dev, "%s: max_rds_per_context 0x%08x\n",
1426 __func__, ha->hw.max_rds_per_cntxt));
1432 * Name: qla_get_max_sds
1433 * Function: Returns the maximum number of Status Descriptor Rings per context.
1436 qla_get_max_sds(qla_host_t *ha)
1443 bzero(&cdrp, sizeof(qla_cdrp_t));
1445 cdrp.cmd = Q8_CMD_RD_MAX_SDS_PER_CNTXT;
1447 if (qla_issue_cmd(ha, &cdrp)) {
1448 device_printf(dev, "%s: Q8_CMD_RD_MAX_RDS_PER_CNTXT failed\n",
1452 ha->hw.max_sds_per_cntxt = cdrp.rsp_arg1;
1453 QL_DPRINT2((dev, "%s: max_sds_per_context 0x%08x\n",
1454 __func__, ha->hw.max_sds_per_cntxt));
1460 * Name: qla_get_max_rules
1461 * Function: Returns the maximum number of Rules per context.
1464 qla_get_max_rules(qla_host_t *ha)
1471 bzero(&cdrp, sizeof(qla_cdrp_t));
1473 cdrp.cmd = Q8_CMD_RD_MAX_RULES_PER_CNTXT;
1475 if (qla_issue_cmd(ha, &cdrp)) {
1476 device_printf(dev, "%s: Q8_CMD_RD_MAX_RULES_PER_CNTXT failed\n",
1480 ha->hw.max_rules_per_cntxt = cdrp.rsp_arg1;
1481 QL_DPRINT2((dev, "%s: max_rules_per_cntxt 0x%08x\n",
1482 __func__, ha->hw.max_rules_per_cntxt));
1488 * Name: qla_get_max_rcv_cntxts
1489 * Function: Returns the maximum number of Receive Contexts supported.
1492 qla_get_max_rcv_cntxts(qla_host_t *ha)
1499 bzero(&cdrp, sizeof(qla_cdrp_t));
1501 cdrp.cmd = Q8_CMD_RD_MAX_RX_CNTXT;
1503 if (qla_issue_cmd(ha, &cdrp)) {
1504 device_printf(dev, "%s: Q8_CMD_RD_MAX_RX_CNTXT failed\n",
1508 ha->hw.max_rcv_cntxts = cdrp.rsp_arg1;
1509 QL_DPRINT2((dev, "%s: max_rcv_cntxts 0x%08x\n",
1510 __func__, ha->hw.max_rcv_cntxts));
1516 * Name: qla_get_max_tx_cntxts
1517 * Function: Returns the maximum number of Transmit Contexts supported.
1520 qla_get_max_tx_cntxts(qla_host_t *ha)
1527 bzero(&cdrp, sizeof(qla_cdrp_t));
1529 cdrp.cmd = Q8_CMD_RD_MAX_TX_CNTXT;
1531 if (qla_issue_cmd(ha, &cdrp)) {
1532 device_printf(dev, "%s: Q8_CMD_RD_MAX_TX_CNTXT failed\n",
1536 ha->hw.max_xmt_cntxts = cdrp.rsp_arg1;
1537 QL_DPRINT2((dev, "%s: max_xmt_cntxts 0x%08x\n",
1538 __func__, ha->hw.max_xmt_cntxts));
1544 * Name: qla_get_max_mtu
1545 * Function: Returns the MTU supported for a context.
1548 qla_get_max_mtu(qla_host_t *ha)
1555 bzero(&cdrp, sizeof(qla_cdrp_t));
1557 cdrp.cmd = Q8_CMD_RD_MAX_MTU;
1559 if (qla_issue_cmd(ha, &cdrp)) {
1560 device_printf(dev, "%s: Q8_CMD_RD_MAX_MTU failed\n", __func__);
1563 ha->hw.max_mtu = cdrp.rsp_arg1;
1564 QL_DPRINT2((dev, "%s: max_mtu 0x%08x\n", __func__,
1571 * Name: qla_set_max_mtu
1573 * Sets the maximum transfer unit size for the specified rcv context.
1576 qla_set_max_mtu(qla_host_t *ha, uint32_t mtu, uint16_t cntxt_id)
1583 bzero(&cdrp, sizeof(qla_cdrp_t));
1585 cdrp.cmd = Q8_CMD_SET_MTU;
1586 cdrp.cmd_arg1 = (uint32_t)cntxt_id;
1587 cdrp.cmd_arg2 = mtu;
1589 if (qla_issue_cmd(ha, &cdrp)) {
1590 device_printf(dev, "%s: Q8_CMD_RD_MAX_MTU failed\n", __func__);
1593 ha->hw.max_mtu = cdrp.rsp_arg1;
1599 * Name: qla_get_max_lro
1600 * Function: Returns the maximum number of TCP Connection which can be supported
1604 qla_get_max_lro(qla_host_t *ha)
1611 bzero(&cdrp, sizeof(qla_cdrp_t));
1613 cdrp.cmd = Q8_CMD_RD_MAX_LRO;
1615 if (qla_issue_cmd(ha, &cdrp)) {
1616 device_printf(dev, "%s: Q8_CMD_RD_MAX_LRO failed\n", __func__);
1619 ha->hw.max_lro = cdrp.rsp_arg1;
1620 QL_DPRINT2((dev, "%s: max_lro 0x%08x\n", __func__,
1627 * Name: qla_get_flow_control
1628 * Function: Returns the Receive/Transmit Flow Control (PAUSE) settings for
1632 qla_get_flow_control(qla_host_t *ha)
1639 bzero(&cdrp, sizeof(qla_cdrp_t));
1641 cdrp.cmd = Q8_CMD_GET_FLOW_CNTRL;
1643 if (qla_issue_cmd(ha, &cdrp)) {
1644 device_printf(dev, "%s: Q8_CMD_GET_FLOW_CNTRL failed\n",
1648 QL_DPRINT2((dev, "%s: flow control 0x%08x\n", __func__,
1655 * Name: qla_get_flow_control
1656 * Function: Retrieves hardware capabilities
1659 qla_get_hw_caps(qla_host_t *ha)
1661 //qla_read_mac_addr(ha);
1662 qla_get_max_rds(ha);
1663 qla_get_max_sds(ha);
1664 qla_get_max_rules(ha);
1665 qla_get_max_rcv_cntxts(ha);
1666 qla_get_max_tx_cntxts(ha);
1667 qla_get_max_mtu(ha);
1668 qla_get_max_lro(ha);
1669 qla_get_flow_control(ha);
1674 * Name: qla_hw_set_multi
1675 * Function: Sets the Multicast Addresses provided the host O.S into the
1676 * hardware (for the given interface)
1679 qla_hw_set_multi(qla_host_t *ha, uint8_t *mta, uint32_t mcnt,
1682 q80_rcv_cntxt_rsp_t *rsp;
1685 rsp = ha->hw.rx_cntxt_rsp;
1686 for (i = 0; i < mcnt; i++) {
1687 qla_config_mac_addr(ha, mta, rsp->rx_rsp.cntxt_id, add_multi);
1688 mta += Q8_MAC_ADDR_LEN;
1694 * Name: qla_hw_tx_done_locked
1695 * Function: Handle Transmit Completions
1698 qla_hw_tx_done_locked(qla_host_t *ha)
1701 qla_hw_t *hw = &ha->hw;
1702 uint32_t comp_idx, comp_count = 0;
1704 /* retrieve index of last entry in tx ring completed */
1705 comp_idx = qla_le32_to_host(*(hw->tx_cons));
1707 while (comp_idx != hw->txr_comp) {
1709 txb = &ha->tx_buf[hw->txr_comp];
1712 if (hw->txr_comp == NUM_TX_DESCRIPTORS)
1718 bus_dmamap_sync(ha->tx_tag, txb->map,
1719 BUS_DMASYNC_POSTWRITE);
1720 bus_dmamap_unload(ha->tx_tag, txb->map);
1721 bus_dmamap_destroy(ha->tx_tag, txb->map);
1722 m_freem(txb->m_head);
1724 txb->map = (bus_dmamap_t)0;
1729 hw->txr_free += comp_count;
1731 QL_DPRINT8((ha->pci_dev, "%s: return [c,f, p, pn][%d, %d, %d, %d]\n", __func__,
1732 hw->txr_comp, hw->txr_free, hw->txr_next, READ_REG32(ha, (ha->hw.tx_prod_reg + 0x1b2000))));
1738 * Name: qla_hw_tx_done
1739 * Function: Handle Transmit Completions
1742 qla_hw_tx_done(qla_host_t *ha)
1744 if (!mtx_trylock(&ha->tx_lock)) {
1745 QL_DPRINT8((ha->pci_dev,
1746 "%s: !mtx_trylock(&ha->tx_lock)\n", __func__));
1749 qla_hw_tx_done_locked(ha);
1751 if (ha->hw.txr_free > free_pkt_thres)
1752 ha->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1754 mtx_unlock(&ha->tx_lock);
1759 qla_update_link_state(qla_host_t *ha)
1761 uint32_t link_state;
1762 uint32_t prev_link_state;
1764 if (!(ha->ifp->if_drv_flags & IFF_DRV_RUNNING)) {
1765 ha->hw.flags.link_up = 0;
1768 link_state = READ_REG32(ha, Q8_LINK_STATE);
1770 prev_link_state = ha->hw.flags.link_up;
1772 if (ha->pci_func == 0)
1773 ha->hw.flags.link_up = (((link_state & 0xF) == 1)? 1 : 0);
1775 ha->hw.flags.link_up = ((((link_state >> 4)& 0xF) == 1)? 1 : 0);
1777 if (prev_link_state != ha->hw.flags.link_up) {
1778 if (ha->hw.flags.link_up) {
1779 if_link_state_change(ha->ifp, LINK_STATE_UP);
1781 if_link_state_change(ha->ifp, LINK_STATE_DOWN);
1787 qla_config_lro(qla_host_t *ha)
1790 qla_hw_t *hw = &ha->hw;
1791 struct lro_ctrl *lro;
1793 for (i = 0; i < hw->num_sds_rings; i++) {
1794 lro = &hw->sds[i].lro;
1795 if (tcp_lro_init(lro)) {
1796 device_printf(ha->pci_dev, "%s: tcp_lro_init failed\n",
1802 ha->flags.lro_init = 1;
1804 QL_DPRINT2((ha->pci_dev, "%s: LRO initialized\n", __func__));
1809 qla_free_lro(qla_host_t *ha)
1812 qla_hw_t *hw = &ha->hw;
1813 struct lro_ctrl *lro;
1815 if (!ha->flags.lro_init)
1818 for (i = 0; i < hw->num_sds_rings; i++) {
1819 lro = &hw->sds[i].lro;
1822 ha->flags.lro_init = 0;
1826 qla_hw_stop_rcv(qla_host_t *ha)
1828 int i, done, count = 100;
1832 for (i = 0; i < ha->hw.num_sds_rings; i++) {
1833 if (ha->hw.sds[i].rcv_active)
1839 qla_mdelay(__func__, 10);