2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 2013-2014 Qlogic Corporation
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
34 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
44 #include "qls_inline.h"
51 qls_tx_comp(qla_host_t *ha, uint32_t txr_idx, q81_tx_mac_comp_t *tx_comp)
54 uint32_t tx_idx = tx_comp->tid_lo;
56 if (tx_idx >= NUM_TX_DESCRIPTORS) {
57 ha->qla_initiate_recovery = 1;
61 txb = &ha->tx_ring[txr_idx].tx_buf[tx_idx];
64 if_inc_counter(ha->ifp, IFCOUNTER_OPACKETS, 1);
65 bus_dmamap_sync(ha->tx_tag, txb->map,
66 BUS_DMASYNC_POSTWRITE);
67 bus_dmamap_unload(ha->tx_tag, txb->map);
73 ha->tx_ring[txr_idx].txr_done++;
75 if (ha->tx_ring[txr_idx].txr_done == NUM_TX_DESCRIPTORS)
76 ha->tx_ring[txr_idx].txr_done = 0;
80 qls_replenish_rx(qla_host_t *ha, uint32_t r_idx)
85 volatile q81_bq_addr_e_t *sbq_e;
87 rxr = &ha->rx_ring[r_idx];
90 sbq_e = rxr->sbq_vaddr;
94 rxb = &rxr->rx_buf[rxr->sbq_next];
96 if (rxb->m_head == NULL) {
97 if (qls_get_mbuf(ha, rxb, NULL) != 0) {
98 device_printf(ha->pci_dev,
99 "%s: qls_get_mbuf [0,%d,%d] failed\n",
100 __func__, rxr->sbq_next, r_idx);
106 if (rxb->m_head != NULL) {
107 sbq_e[rxr->sbq_next].addr_lo = (uint32_t)rxb->paddr;
108 sbq_e[rxr->sbq_next].addr_hi =
109 (uint32_t)(rxb->paddr >> 32);
112 if (rxr->sbq_next == NUM_RX_DESCRIPTORS)
119 if (rxr->sbq_free == 16) {
122 rxr->sbq_in = rxr->sbq_in & (NUM_RX_DESCRIPTORS - 1);
125 Q81_WR_SBQ_PROD_IDX(r_idx, (rxr->sbq_in));
131 qls_rx_comp(qla_host_t *ha, uint32_t rxr_idx, uint32_t cq_idx, q81_rx_t *cq_e)
135 device_t dev = ha->pci_dev;
136 struct mbuf *mp = NULL;
137 struct ifnet *ifp = ha->ifp;
138 struct lro_ctrl *lro;
139 struct ether_vlan_header *eh;
141 rxr = &ha->rx_ring[rxr_idx];
145 rxb = &rxr->rx_buf[rxr->rx_next];
147 if (!(cq_e->flags1 & Q81_RX_FLAGS1_DS)) {
148 device_printf(dev, "%s: DS bit not set \n", __func__);
151 if (rxb->paddr != cq_e->b_paddr) {
154 "%s: (rxb->paddr != cq_e->b_paddr)[%p, %p] \n",
155 __func__, (void *)rxb->paddr, (void *)cq_e->b_paddr);
157 Q81_SET_CQ_INVALID(cq_idx);
159 ha->qla_initiate_recovery = 1;
166 if ((cq_e->flags1 & Q81_RX_FLAGS1_ERR_MASK) == 0) {
172 device_printf(dev, "%s: mp == NULL\n", __func__);
174 mp->m_flags |= M_PKTHDR;
175 mp->m_pkthdr.len = cq_e->length;
176 mp->m_pkthdr.rcvif = ifp;
177 mp->m_len = cq_e->length;
179 eh = mtod(mp, struct ether_vlan_header *);
181 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
182 uint32_t *data = (uint32_t *)eh;
184 mp->m_pkthdr.ether_vtag = ntohs(eh->evl_tag);
185 mp->m_flags |= M_VLANTAG;
187 *(data + 3) = *(data + 2);
188 *(data + 2) = *(data + 1);
191 m_adj(mp, ETHER_VLAN_ENCAP_LEN);
194 if ((cq_e->flags1 & Q81_RX_FLAGS1_RSS_MATCH_MASK)) {
196 mp->m_pkthdr.flowid = cq_e->rss;
197 M_HASHTYPE_SET(mp, M_HASHTYPE_OPAQUE_HASH);
199 if (cq_e->flags0 & (Q81_RX_FLAGS0_TE |
200 Q81_RX_FLAGS0_NU | Q81_RX_FLAGS0_IE)) {
201 mp->m_pkthdr.csum_flags = 0;
203 mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED |
204 CSUM_IP_VALID | CSUM_DATA_VALID |
206 mp->m_pkthdr.csum_data = 0xFFFF;
208 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
210 if (lro->lro_cnt && (tcp_lro_rx(lro, mp, 0) == 0)) {
211 /* LRO packet has been successfully queued */
213 (*ifp->if_input)(ifp, mp);
217 device_printf(dev, "%s: err [0%08x]\n", __func__, cq_e->flags1);
223 if (rxr->rx_next == NUM_RX_DESCRIPTORS)
226 if ((rxr->rx_free + rxr->sbq_free) >= 16)
227 qls_replenish_rx(ha, rxr_idx);
233 qls_cq_isr(qla_host_t *ha, uint32_t cq_idx)
235 q81_cq_e_t *cq_e, *cq_b;
236 uint32_t i, cq_comp_idx;
237 int ret = 0, tx_comp_done = 0;
238 struct lro_ctrl *lro;
240 cq_b = ha->rx_ring[cq_idx].cq_base_vaddr;
241 lro = &ha->rx_ring[cq_idx].lro;
243 cq_comp_idx = *(ha->rx_ring[cq_idx].cqi_vaddr);
245 i = ha->rx_ring[cq_idx].cq_next;
247 while (i != cq_comp_idx) {
251 switch (cq_e->opcode) {
253 case Q81_IOCB_TX_MAC:
254 case Q81_IOCB_TX_TSO:
255 qls_tx_comp(ha, cq_idx, (q81_tx_mac_comp_t *)cq_e);
260 ret = qls_rx_comp(ha, cq_idx, i, (q81_rx_t *)cq_e);
267 device_printf(ha->pci_dev, "%s[%d %d 0x%x]: illegal \n",
268 __func__, i, (*(ha->rx_ring[cq_idx].cqi_vaddr)),
270 qls_dump_buf32(ha, __func__, cq_e,
271 (sizeof (q81_cq_e_t) >> 2));
276 if (i == NUM_CQ_ENTRIES)
283 if (i == cq_comp_idx) {
284 cq_comp_idx = *(ha->rx_ring[cq_idx].cqi_vaddr);
288 taskqueue_enqueue(ha->tx_tq, &ha->tx_task);
293 tcp_lro_flush_all(lro);
295 ha->rx_ring[cq_idx].cq_next = cq_comp_idx;
298 Q81_WR_CQ_CONS_IDX(cq_idx, (ha->rx_ring[cq_idx].cq_next));
301 taskqueue_enqueue(ha->tx_tq, &ha->tx_task);
307 qls_mbx_isr(qla_host_t *ha)
311 device_t dev = ha->pci_dev;
313 if (qls_mbx_rd_reg(ha, 0, &data) == 0) {
315 if ((data & 0xF000) == 0x4000) {
317 for (i = 1; i < Q81_NUM_MBX_REGISTERS; i++) {
318 if (qls_mbx_rd_reg(ha, i, &data))
323 } else if ((data & 0xF000) == 0x8000) {
328 for (i = 1; i < Q81_NUM_AEN_REGISTERS; i++) {
329 if (qls_mbx_rd_reg(ha, i, &data))
333 device_printf(dev,"%s: AEN "
334 "[0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
335 " 0x%08x 0x%08x 0x%08x 0x%08x]\n",
337 ha->aen[0], ha->aen[1], ha->aen[2],
338 ha->aen[3], ha->aen[4], ha->aen[5],
339 ha->aen[6], ha->aen[7], ha->aen[8]);
341 switch ((ha->aen[0] & 0xFFFF)) {
352 ha->link_hw_info = ha->aen[1];
356 ha->link_hw_info = 0;
362 WRITE_REG32(ha, Q81_CTL_HOST_CMD_STATUS, Q81_CTL_HCS_CMD_CLR_RTH_INTR);
370 qla_ivec_t *ivec = arg;
377 cq_idx = ivec->cq_idx;
380 status = READ_REG32(ha, Q81_CTL_STATUS);
382 if (status & Q81_CTL_STATUS_FE) {
383 device_printf(dev, "%s fatal error\n", __func__);
387 if ((cq_idx == 0) && (status & Q81_CTL_STATUS_PI)) {
391 status = READ_REG32(ha, Q81_CTL_INTR_STATUS1);
393 if (status & ( 0x1 << cq_idx))
394 qls_cq_isr(ha, cq_idx);
396 Q81_ENABLE_INTR(ha, cq_idx);