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.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
40 #include "ql_inline.h"
45 static void qla_replenish_normal_rx(qla_host_t *ha, qla_sds_t *sdsp,
49 qla_rcv_error(qla_host_t *ha)
52 ha->qla_initiate_recovery = 1;
58 * Function: Handles normal ethernet frames received
61 qla_rx_intr(qla_host_t *ha, qla_sgl_rcv_t *sgc, uint32_t sds_idx)
64 struct mbuf *mp = NULL, *mpf = NULL, *mpl = NULL;
65 struct ifnet *ifp = ha->ifp;
67 struct ether_vlan_header *eh;
68 uint32_t i, rem_len = 0;
70 qla_rx_ring_t *rx_ring;
73 lro = &ha->hw.sds[sds_idx].lro;
75 if (ha->hw.num_rds_rings > 1)
78 ha->hw.rds[r_idx].count++;
80 sdsp = &ha->hw.sds[sds_idx];
81 rx_ring = &ha->rx_ring[r_idx];
83 for (i = 0; i < sgc->num_handles; i++) {
84 rxb = &rx_ring->rx_buf[sgc->handle[i] & 0x7FFF];
86 QL_ASSERT(ha, (rxb != NULL),
87 ("%s: [sds_idx]=[%d] rxb != NULL\n", __func__,\
90 if ((rxb == NULL) || QL_ERR_INJECT(ha, INJCT_RX_RXB_INVAL)) {
92 device_printf(ha->pci_dev,
93 "%s invalid rxb[%d, %d, 0x%04x]\n",
94 __func__, sds_idx, i, sgc->handle[i]);
103 QL_ASSERT(ha, (mp != NULL),
104 ("%s: [sds_idx]=[%d] mp != NULL\n", __func__,\
107 bus_dmamap_sync(ha->rx_tag, rxb->map, BUS_DMASYNC_POSTREAD);
110 rxb->next = sdsp->rxb_free;
111 sdsp->rxb_free = rxb;
114 if ((mp == NULL) || QL_ERR_INJECT(ha, INJCT_RX_MP_NULL)) {
116 device_printf(ha->pci_dev,
117 "%s mp == NULL [%d, %d, 0x%04x]\n",
118 __func__, sds_idx, i, sgc->handle[i]);
125 mp->m_flags |= M_PKTHDR;
126 mp->m_pkthdr.len = sgc->pkt_length;
127 mp->m_pkthdr.rcvif = ifp;
128 rem_len = mp->m_pkthdr.len;
130 mp->m_flags &= ~M_PKTHDR;
133 rem_len = rem_len - mp->m_len;
137 mpl->m_len = rem_len;
139 eh = mtod(mpf, struct ether_vlan_header *);
141 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
142 uint32_t *data = (uint32_t *)eh;
144 mpf->m_pkthdr.ether_vtag = ntohs(eh->evl_tag);
145 mpf->m_flags |= M_VLANTAG;
147 *(data + 3) = *(data + 2);
148 *(data + 2) = *(data + 1);
151 m_adj(mpf, ETHER_VLAN_ENCAP_LEN);
154 if (sgc->chksum_status == Q8_STAT_DESC_STATUS_CHKSUM_OK) {
155 mpf->m_pkthdr.csum_flags = CSUM_IP_CHECKED | CSUM_IP_VALID |
156 CSUM_DATA_VALID | CSUM_PSEUDO_HDR;
157 mpf->m_pkthdr.csum_data = 0xFFFF;
159 mpf->m_pkthdr.csum_flags = 0;
164 mpf->m_pkthdr.flowid = sgc->rss_hash;
165 mpf->m_flags |= M_FLOWID;
167 #if __FreeBSD_version >= 1100000
168 M_HASHTYPE_SET(mpf, M_HASHTYPE_OPAQUE_HASH);
170 #if (__FreeBSD_version >= 903511 && __FreeBSD_version < 1100000)
171 M_HASHTYPE_SET(mpf, M_HASHTYPE_OPAQUE);
173 M_HASHTYPE_SET(mpf, M_HASHTYPE_NONE);
175 #endif /* #if __FreeBSD_version >= 1100000 */
177 if (ha->hw.enable_soft_lro) {
179 #if (__FreeBSD_version >= 1100101)
181 tcp_lro_queue_mbuf(lro, mpf);
184 if (tcp_lro_rx(lro, mpf, 0))
185 (*ifp->if_input)(ifp, mpf);
187 #endif /* #if (__FreeBSD_version >= 1100101) */
191 (*ifp->if_input)(ifp, mpf);
194 if (sdsp->rx_free > ha->std_replenish)
195 qla_replenish_normal_rx(ha, sdsp, r_idx);
200 #define QLA_TCP_HDR_SIZE 20
201 #define QLA_TCP_TS_OPTION_SIZE 12
205 * Function: Handles normal ethernet frames received
208 qla_lro_intr(qla_host_t *ha, qla_sgl_lro_t *sgc, uint32_t sds_idx)
211 struct mbuf *mp = NULL, *mpf = NULL, *mpl = NULL;
212 struct ifnet *ifp = ha->ifp;
214 struct ether_vlan_header *eh;
215 uint32_t i, rem_len = 0, pkt_length, iplen;
217 struct ip *ip = NULL;
218 struct ip6_hdr *ip6 = NULL;
221 qla_rx_ring_t *rx_ring;
223 if (ha->hw.num_rds_rings > 1)
226 ha->hw.rds[r_idx].count++;
228 rx_ring = &ha->rx_ring[r_idx];
230 ha->hw.rds[r_idx].lro_pkt_count++;
232 sdsp = &ha->hw.sds[sds_idx];
234 pkt_length = sgc->payload_length + sgc->l4_offset;
236 if (sgc->flags & Q8_LRO_COMP_TS) {
237 pkt_length += QLA_TCP_HDR_SIZE + QLA_TCP_TS_OPTION_SIZE;
239 pkt_length += QLA_TCP_HDR_SIZE;
241 ha->hw.rds[r_idx].lro_bytes += pkt_length;
243 for (i = 0; i < sgc->num_handles; i++) {
244 rxb = &rx_ring->rx_buf[sgc->handle[i] & 0x7FFF];
246 QL_ASSERT(ha, (rxb != NULL),
247 ("%s: [sds_idx]=[%d] rxb != NULL\n", __func__,\
250 if ((rxb == NULL) || QL_ERR_INJECT(ha, INJCT_LRO_RXB_INVAL)) {
252 device_printf(ha->pci_dev,
253 "%s invalid rxb[%d, %d, 0x%04x]\n",
254 __func__, sds_idx, i, sgc->handle[i]);
263 QL_ASSERT(ha, (mp != NULL),
264 ("%s: [sds_idx]=[%d] mp != NULL\n", __func__,\
267 bus_dmamap_sync(ha->rx_tag, rxb->map, BUS_DMASYNC_POSTREAD);
270 rxb->next = sdsp->rxb_free;
271 sdsp->rxb_free = rxb;
274 if ((mp == NULL) || QL_ERR_INJECT(ha, INJCT_LRO_MP_NULL)) {
276 device_printf(ha->pci_dev,
277 "%s mp == NULL [%d, %d, 0x%04x]\n",
278 __func__, sds_idx, i, sgc->handle[i]);
285 mp->m_flags |= M_PKTHDR;
286 mp->m_pkthdr.len = pkt_length;
287 mp->m_pkthdr.rcvif = ifp;
288 rem_len = mp->m_pkthdr.len;
290 mp->m_flags &= ~M_PKTHDR;
293 rem_len = rem_len - mp->m_len;
297 mpl->m_len = rem_len;
299 th = (struct tcphdr *)(mpf->m_data + sgc->l4_offset);
301 if (sgc->flags & Q8_LRO_COMP_PUSH_BIT)
302 th->th_flags |= TH_PUSH;
304 m_adj(mpf, sgc->l2_offset);
306 eh = mtod(mpf, struct ether_vlan_header *);
308 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
309 uint32_t *data = (uint32_t *)eh;
311 mpf->m_pkthdr.ether_vtag = ntohs(eh->evl_tag);
312 mpf->m_flags |= M_VLANTAG;
314 *(data + 3) = *(data + 2);
315 *(data + 2) = *(data + 1);
318 m_adj(mpf, ETHER_VLAN_ENCAP_LEN);
320 etype = ntohs(eh->evl_proto);
322 etype = ntohs(eh->evl_encap_proto);
325 if (etype == ETHERTYPE_IP) {
326 ip = (struct ip *)(mpf->m_data + ETHER_HDR_LEN);
328 iplen = (ip->ip_hl << 2) + (th->th_off << 2) +
331 ip->ip_len = htons(iplen);
335 M_HASHTYPE_SET(mpf, M_HASHTYPE_RSS_TCP_IPV4);
337 } else if (etype == ETHERTYPE_IPV6) {
338 ip6 = (struct ip6_hdr *)(mpf->m_data + ETHER_HDR_LEN);
340 iplen = (th->th_off << 2) + sgc->payload_length;
342 ip6->ip6_plen = htons(iplen);
346 M_HASHTYPE_SET(mpf, M_HASHTYPE_RSS_TCP_IPV6);
351 if (sdsp->rx_free > ha->std_replenish)
352 qla_replenish_normal_rx(ha, sdsp, r_idx);
356 mpf->m_pkthdr.csum_flags = CSUM_IP_CHECKED | CSUM_IP_VALID |
357 CSUM_DATA_VALID | CSUM_PSEUDO_HDR;
358 mpf->m_pkthdr.csum_data = 0xFFFF;
360 mpf->m_pkthdr.flowid = sgc->rss_hash;
361 mpf->m_flags |= M_FLOWID;
365 (*ifp->if_input)(ifp, mpf);
367 if (sdsp->rx_free > ha->std_replenish)
368 qla_replenish_normal_rx(ha, sdsp, r_idx);
374 qla_rcv_cont_sds(qla_host_t *ha, uint32_t sds_idx, uint32_t comp_idx,
375 uint32_t dcount, uint16_t *handle, uint16_t *nhandles)
378 uint16_t num_handles;
379 q80_stat_desc_t *sdesc;
385 for (i = 0; i < dcount; i++) {
386 comp_idx = (comp_idx + 1) & (NUM_STATUS_DESCRIPTORS-1);
387 sdesc = (q80_stat_desc_t *)
388 &ha->hw.sds[sds_idx].sds_ring_base[comp_idx];
390 opcode = Q8_STAT_DESC_OPCODE((sdesc->data[1]));
393 device_printf(ha->pci_dev, "%s: opcode=0 %p %p\n",
394 __func__, (void *)sdesc->data[0],
395 (void *)sdesc->data[1]);
399 num_handles = Q8_SGL_STAT_DESC_NUM_HANDLES((sdesc->data[1]));
401 device_printf(ha->pci_dev, "%s: opcode=0 %p %p\n",
402 __func__, (void *)sdesc->data[0],
403 (void *)sdesc->data[1]);
407 if (QL_ERR_INJECT(ha, INJCT_NUM_HNDLE_INVALID))
410 switch (num_handles) {
413 *handle++ = Q8_SGL_STAT_DESC_HANDLE1((sdesc->data[0]));
417 *handle++ = Q8_SGL_STAT_DESC_HANDLE1((sdesc->data[0]));
418 *handle++ = Q8_SGL_STAT_DESC_HANDLE2((sdesc->data[0]));
422 *handle++ = Q8_SGL_STAT_DESC_HANDLE1((sdesc->data[0]));
423 *handle++ = Q8_SGL_STAT_DESC_HANDLE2((sdesc->data[0]));
424 *handle++ = Q8_SGL_STAT_DESC_HANDLE3((sdesc->data[0]));
428 *handle++ = Q8_SGL_STAT_DESC_HANDLE1((sdesc->data[0]));
429 *handle++ = Q8_SGL_STAT_DESC_HANDLE2((sdesc->data[0]));
430 *handle++ = Q8_SGL_STAT_DESC_HANDLE3((sdesc->data[0]));
431 *handle++ = Q8_SGL_STAT_DESC_HANDLE4((sdesc->data[0]));
435 *handle++ = Q8_SGL_STAT_DESC_HANDLE1((sdesc->data[0]));
436 *handle++ = Q8_SGL_STAT_DESC_HANDLE2((sdesc->data[0]));
437 *handle++ = Q8_SGL_STAT_DESC_HANDLE3((sdesc->data[0]));
438 *handle++ = Q8_SGL_STAT_DESC_HANDLE4((sdesc->data[0]));
439 *handle++ = Q8_SGL_STAT_DESC_HANDLE5((sdesc->data[1]));
443 *handle++ = Q8_SGL_STAT_DESC_HANDLE1((sdesc->data[0]));
444 *handle++ = Q8_SGL_STAT_DESC_HANDLE2((sdesc->data[0]));
445 *handle++ = Q8_SGL_STAT_DESC_HANDLE3((sdesc->data[0]));
446 *handle++ = Q8_SGL_STAT_DESC_HANDLE4((sdesc->data[0]));
447 *handle++ = Q8_SGL_STAT_DESC_HANDLE5((sdesc->data[1]));
448 *handle++ = Q8_SGL_STAT_DESC_HANDLE6((sdesc->data[1]));
452 *handle++ = Q8_SGL_STAT_DESC_HANDLE1((sdesc->data[0]));
453 *handle++ = Q8_SGL_STAT_DESC_HANDLE2((sdesc->data[0]));
454 *handle++ = Q8_SGL_STAT_DESC_HANDLE3((sdesc->data[0]));
455 *handle++ = Q8_SGL_STAT_DESC_HANDLE4((sdesc->data[0]));
456 *handle++ = Q8_SGL_STAT_DESC_HANDLE5((sdesc->data[1]));
457 *handle++ = Q8_SGL_STAT_DESC_HANDLE6((sdesc->data[1]));
458 *handle++ = Q8_SGL_STAT_DESC_HANDLE7((sdesc->data[1]));
462 device_printf(ha->pci_dev,
463 "%s: invalid num handles %p %p\n",
464 __func__, (void *)sdesc->data[0],
465 (void *)sdesc->data[1]);
468 ("%s: %s [nh, sds, d0, d1]=[%d, %d, %p, %p]\n",
469 __func__, "invalid num handles", sds_idx, num_handles,
470 (void *)sdesc->data[0],(void *)sdesc->data[1]));
475 *nhandles = *nhandles + num_handles;
482 * Function: Main Interrupt Service Routine
485 ql_rcv_isr(qla_host_t *ha, uint32_t sds_idx, uint32_t count)
489 uint32_t comp_idx, c_idx = 0, desc_count = 0, opcode;
490 volatile q80_stat_desc_t *sdesc, *sdesc0 = NULL;
494 uint32_t sds_replenish_threshold = 0;
501 hw->sds[sds_idx].rcv_active = 1;
503 hw->sds[sds_idx].rcv_active = 0;
507 QL_DPRINT2(ha, (dev, "%s: [%d]enter\n", __func__, sds_idx));
512 comp_idx = hw->sds[sds_idx].sdsr_next;
514 while (count-- && !ha->stop_rcv) {
516 sdesc = (q80_stat_desc_t *)
517 &hw->sds[sds_idx].sds_ring_base[comp_idx];
519 opcode = Q8_STAT_DESC_OPCODE((sdesc->data[1]));
526 case Q8_STAT_DESC_OPCODE_RCV_PKT:
530 bzero(&sgc, sizeof(qla_sgl_comp_t));
533 Q8_STAT_DESC_TOTAL_LENGTH((sdesc->data[0]));
534 sgc.rcv.num_handles = 1;
536 Q8_STAT_DESC_HANDLE((sdesc->data[0]));
537 sgc.rcv.chksum_status =
538 Q8_STAT_DESC_STATUS((sdesc->data[1]));
541 Q8_STAT_DESC_RSS_HASH((sdesc->data[0]));
543 if (Q8_STAT_DESC_VLAN((sdesc->data[1]))) {
545 Q8_STAT_DESC_VLAN_ID((sdesc->data[1]));
547 qla_rx_intr(ha, &sgc.rcv, sds_idx);
550 case Q8_STAT_DESC_OPCODE_SGL_RCV:
553 Q8_STAT_DESC_COUNT_SGL_RCV((sdesc->data[1]));
555 if (desc_count > 1) {
556 c_idx = (comp_idx + desc_count -1) &
557 (NUM_STATUS_DESCRIPTORS-1);
558 sdesc0 = (q80_stat_desc_t *)
559 &hw->sds[sds_idx].sds_ring_base[c_idx];
561 if (Q8_STAT_DESC_OPCODE((sdesc0->data[1])) !=
562 Q8_STAT_DESC_OPCODE_CONT) {
568 bzero(&sgc, sizeof(qla_sgl_comp_t));
571 Q8_STAT_DESC_TOTAL_LENGTH_SGL_RCV(\
573 sgc.rcv.chksum_status =
574 Q8_STAT_DESC_STATUS((sdesc->data[1]));
577 Q8_STAT_DESC_RSS_HASH((sdesc->data[0]));
579 if (Q8_STAT_DESC_VLAN((sdesc->data[1]))) {
581 Q8_STAT_DESC_VLAN_ID((sdesc->data[1]));
584 QL_ASSERT(ha, (desc_count <= 2) ,\
585 ("%s: [sds_idx, data0, data1]="\
586 "%d, %p, %p]\n", __func__, sds_idx,\
587 (void *)sdesc->data[0],\
588 (void *)sdesc->data[1]));
590 sgc.rcv.num_handles = 1;
592 Q8_STAT_DESC_HANDLE((sdesc->data[0]));
594 if (qla_rcv_cont_sds(ha, sds_idx, comp_idx, desc_count,
595 &sgc.rcv.handle[1], &nhandles)) {
597 "%s: [sds_idx, dcount, data0, data1]="
598 "[%d, %d, 0x%llx, 0x%llx]\n",
599 __func__, sds_idx, desc_count,
600 (long long unsigned int)sdesc->data[0],
601 (long long unsigned int)sdesc->data[1]);
606 sgc.rcv.num_handles += nhandles;
608 qla_rx_intr(ha, &sgc.rcv, sds_idx);
612 case Q8_STAT_DESC_OPCODE_SGL_LRO:
615 Q8_STAT_DESC_COUNT_SGL_LRO((sdesc->data[1]));
617 if (desc_count > 1) {
618 c_idx = (comp_idx + desc_count -1) &
619 (NUM_STATUS_DESCRIPTORS-1);
620 sdesc0 = (q80_stat_desc_t *)
621 &hw->sds[sds_idx].sds_ring_base[c_idx];
623 if (Q8_STAT_DESC_OPCODE((sdesc0->data[1])) !=
624 Q8_STAT_DESC_OPCODE_CONT) {
629 bzero(&sgc, sizeof(qla_sgl_comp_t));
631 sgc.lro.payload_length =
632 Q8_STAT_DESC_TOTAL_LENGTH_SGL_RCV((sdesc->data[0]));
635 Q8_STAT_DESC_RSS_HASH((sdesc->data[0]));
637 sgc.lro.num_handles = 1;
639 Q8_STAT_DESC_HANDLE((sdesc->data[0]));
641 if (Q8_SGL_LRO_STAT_TS((sdesc->data[1])))
642 sgc.lro.flags |= Q8_LRO_COMP_TS;
644 if (Q8_SGL_LRO_STAT_PUSH_BIT((sdesc->data[1])))
645 sgc.lro.flags |= Q8_LRO_COMP_PUSH_BIT;
648 Q8_SGL_LRO_STAT_L2_OFFSET((sdesc->data[1]));
650 Q8_SGL_LRO_STAT_L4_OFFSET((sdesc->data[1]));
652 if (Q8_STAT_DESC_VLAN((sdesc->data[1]))) {
654 Q8_STAT_DESC_VLAN_ID((sdesc->data[1]));
657 QL_ASSERT(ha, (desc_count <= 7) ,\
658 ("%s: [sds_idx, data0, data1]="\
659 "[%d, 0x%llx, 0x%llx]\n",\
661 (long long unsigned int)sdesc->data[0],\
662 (long long unsigned int)sdesc->data[1]));
664 if (qla_rcv_cont_sds(ha, sds_idx, comp_idx,
665 desc_count, &sgc.lro.handle[1], &nhandles)) {
667 "%s: [sds_idx, data0, data1]="\
668 "[%d, 0x%llx, 0x%llx]\n",\
670 (long long unsigned int)sdesc->data[0],\
671 (long long unsigned int)sdesc->data[1]);
677 sgc.lro.num_handles += nhandles;
679 if (qla_lro_intr(ha, &sgc.lro, sds_idx)) {
681 "%s: [sds_idx, data0, data1]="\
682 "[%d, 0x%llx, 0x%llx]\n",\
684 (long long unsigned int)sdesc->data[0],\
685 (long long unsigned int)sdesc->data[1]);
687 "%s: [comp_idx, c_idx, dcount, nhndls]="\
688 "[%d, %d, %d, %d]\n",\
689 __func__, comp_idx, c_idx, desc_count,
690 sgc.lro.num_handles);
691 if (desc_count > 1) {
693 "%s: [sds_idx, data0, data1]="\
694 "[%d, 0x%llx, 0x%llx]\n",\
696 (long long unsigned int)sdesc0->data[0],\
697 (long long unsigned int)sdesc0->data[1]);
704 device_printf(dev, "%s: default 0x%llx!\n", __func__,
705 (long long unsigned int)sdesc->data[0]);
712 sds_replenish_threshold += desc_count;
715 while (desc_count--) {
716 sdesc->data[0] = 0ULL;
717 sdesc->data[1] = 0ULL;
718 comp_idx = (comp_idx + 1) & (NUM_STATUS_DESCRIPTORS-1);
719 sdesc = (q80_stat_desc_t *)
720 &hw->sds[sds_idx].sds_ring_base[comp_idx];
723 if (sds_replenish_threshold > ha->hw.sds_cidx_thres) {
724 sds_replenish_threshold = 0;
725 if (hw->sds[sds_idx].sdsr_next != comp_idx) {
726 QL_UPDATE_SDS_CONSUMER_INDEX(ha, sds_idx,\
729 hw->sds[sds_idx].sdsr_next = comp_idx;
733 if (ha->hw.enable_soft_lro) {
734 struct lro_ctrl *lro;
736 lro = &ha->hw.sds[sds_idx].lro;
738 #if (__FreeBSD_version >= 1100101)
740 tcp_lro_flush_all(lro);
743 struct lro_entry *queued;
745 while ((!SLIST_EMPTY(&lro->lro_active))) {
746 queued = SLIST_FIRST(&lro->lro_active);
747 SLIST_REMOVE_HEAD(&lro->lro_active, next);
748 tcp_lro_flush(lro, queued);
751 #endif /* #if (__FreeBSD_version >= 1100101) */
756 goto ql_rcv_isr_exit;
758 if (hw->sds[sds_idx].sdsr_next != comp_idx) {
759 QL_UPDATE_SDS_CONSUMER_INDEX(ha, sds_idx, comp_idx);
760 hw->sds[sds_idx].sdsr_next = comp_idx;
762 if (ha->hw.num_rds_rings > 1)
765 sdsp = &ha->hw.sds[sds_idx];
767 if (sdsp->rx_free > ha->std_replenish)
768 qla_replenish_normal_rx(ha, sdsp, r_idx);
771 sdesc = (q80_stat_desc_t *)&hw->sds[sds_idx].sds_ring_base[comp_idx];
772 opcode = Q8_STAT_DESC_OPCODE((sdesc->data[1]));
778 hw->sds[sds_idx].rcv_active = 0;
784 ql_mbx_isr(void *arg)
788 uint32_t prev_link_state;
793 device_printf(ha->pci_dev, "%s: arg == NULL\n", __func__);
797 data = READ_REG32(ha, Q8_FW_MBOX_CNTRL);
798 if ((data & 0x3) != 0x1) {
799 WRITE_REG32(ha, ha->hw.mbx_intr_mask_offset, 0);
803 data = READ_REG32(ha, Q8_FW_MBOX0);
805 if ((data & 0xF000) != 0x8000)
808 data = data & 0xFFFF;
812 case 0x8001: /* It's an AEN */
814 ha->hw.cable_oui = READ_REG32(ha, (Q8_FW_MBOX0 + 4));
816 data = READ_REG32(ha, (Q8_FW_MBOX0 + 8));
817 ha->hw.cable_length = data & 0xFFFF;
820 ha->hw.link_speed = data & 0xFFF;
822 data = READ_REG32(ha, (Q8_FW_MBOX0 + 12));
824 prev_link_state = ha->hw.link_up;
825 ha->hw.link_up = (((data & 0xFF) == 0) ? 0 : 1);
827 if (prev_link_state != ha->hw.link_up) {
829 if_link_state_change(ha->ifp, LINK_STATE_UP);
831 if_link_state_change(ha->ifp, LINK_STATE_DOWN);
835 ha->hw.module_type = ((data >> 8) & 0xFF);
836 ha->hw.flags.fduplex = (((data & 0xFF0000) == 0) ? 0 : 1);
837 ha->hw.flags.autoneg = (((data & 0xFF000000) == 0) ? 0 : 1);
839 data = READ_REG32(ha, (Q8_FW_MBOX0 + 16));
840 ha->hw.flags.loopback_mode = data & 0x03;
842 ha->hw.link_faults = (data >> 3) & 0xFF;
852 ha->hw.aen_mb0 = 0x8101;
853 ha->hw.aen_mb1 = READ_REG32(ha, (Q8_FW_MBOX0 + 4));
854 ha->hw.aen_mb2 = READ_REG32(ha, (Q8_FW_MBOX0 + 8));
855 ha->hw.aen_mb3 = READ_REG32(ha, (Q8_FW_MBOX0 + 12));
856 ha->hw.aen_mb4 = READ_REG32(ha, (Q8_FW_MBOX0 + 16));
860 /* for now just dump the registers */
864 ombx[0] = READ_REG32(ha, (Q8_FW_MBOX0 + 4));
865 ombx[1] = READ_REG32(ha, (Q8_FW_MBOX0 + 8));
866 ombx[2] = READ_REG32(ha, (Q8_FW_MBOX0 + 12));
867 ombx[3] = READ_REG32(ha, (Q8_FW_MBOX0 + 16));
868 ombx[4] = READ_REG32(ha, (Q8_FW_MBOX0 + 20));
870 device_printf(ha->pci_dev, "%s: "
871 "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
872 __func__, data, ombx[0], ombx[1], ombx[2],
879 /* sfp insertion aen */
880 device_printf(ha->pci_dev, "%s: sfp inserted [0x%08x]\n",
881 __func__, READ_REG32(ha, (Q8_FW_MBOX0 + 4)));
885 /* sfp removal aen */
886 device_printf(ha->pci_dev, "%s: sfp removed]\n", __func__);
893 ombx[0] = READ_REG32(ha, (Q8_FW_MBOX0 + 4));
894 ombx[1] = READ_REG32(ha, (Q8_FW_MBOX0 + 8));
895 ombx[2] = READ_REG32(ha, (Q8_FW_MBOX0 + 12));
897 device_printf(ha->pci_dev, "%s: "
898 "0x%08x 0x%08x 0x%08x 0x%08x \n",
899 __func__, data, ombx[0], ombx[1], ombx[2]);
904 device_printf(ha->pci_dev, "%s: AEN[0x%08x]\n", __func__, data);
907 WRITE_REG32(ha, Q8_FW_MBOX_CNTRL, 0x0);
908 WRITE_REG32(ha, ha->hw.mbx_intr_mask_offset, 0x0);
914 qla_replenish_normal_rx(qla_host_t *ha, qla_sds_t *sdsp, uint32_t r_idx)
917 int count = sdsp->rx_free;
921 /* we can play with this value via a sysctl */
922 uint32_t replenish_thresh = ha->hw.rds_pidx_thres;
924 rdesc = &ha->hw.rds[r_idx];
926 rx_next = rdesc->rx_next;
929 rxb = sdsp->rxb_free;
934 sdsp->rxb_free = rxb->next;
937 if (ql_get_mbuf(ha, rxb, NULL) == 0) {
938 qla_set_hw_rcv_desc(ha, r_idx, rdesc->rx_in,
940 rxb->paddr, (rxb->m_head)->m_pkthdr.len);
942 if (rdesc->rx_in == NUM_RX_DESCRIPTORS)
945 if (rdesc->rx_next == NUM_RX_DESCRIPTORS)
948 device_printf(ha->pci_dev,
949 "%s: qla_get_mbuf [(%d),(%d),(%d)] failed\n",
950 __func__, r_idx, rdesc->rx_in, rxb->handle);
953 rxb->next = sdsp->rxb_free;
954 sdsp->rxb_free = rxb;
959 if (replenish_thresh-- == 0) {
960 QL_UPDATE_RDS_PRODUCER_INDEX(ha, rdesc->prod_std,
962 rx_next = rdesc->rx_next;
963 replenish_thresh = ha->hw.rds_pidx_thres;
967 if (rx_next != rdesc->rx_next) {
968 QL_UPDATE_RDS_PRODUCER_INDEX(ha, rdesc->prod_std,
976 qla_ivec_t *ivec = arg;
987 if ((idx = ivec->sds_idx) >= ha->hw.num_sds_rings)
990 fp = &ha->tx_fp[idx];
991 hw->sds[idx].intr_count++;
993 if ((fp->fp_taskqueue != NULL) &&
994 (ifp->if_drv_flags & IFF_DRV_RUNNING))
995 taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);