2 * Copyright (c) 2010-2011 Solarflare Communications, Inc.
5 * This software was developed in part by Philip Paeps under contract for
6 * Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * 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 AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 /* Theory of operation:
32 * Tx queues allocation and mapping
34 * One Tx queue with enabled checksum offload is allocated per Rx channel
35 * (event queue). Also 2 Tx queues (one without checksum offload and one
36 * with IP checksum offload only) are allocated and bound to event queue 0.
37 * sfxge_txq_type is used as Tx queue label.
39 * So, event queue plus label mapping to Tx queue index is:
40 * if event queue index is 0, TxQ-index = TxQ-label * [0..SFXGE_TXQ_NTYPES)
41 * else TxQ-index = SFXGE_TXQ_NTYPES + EvQ-index - 1
42 * See sfxge_get_txq_by_label() sfxge_ev.c
45 #include <sys/cdefs.h>
46 __FBSDID("$FreeBSD$");
48 #include <sys/types.h>
51 #include <sys/socket.h>
52 #include <sys/sysctl.h>
53 #include <sys/syslog.h>
56 #include <net/ethernet.h>
58 #include <net/if_vlan_var.h>
60 #include <netinet/in.h>
61 #include <netinet/ip.h>
62 #include <netinet/ip6.h>
63 #include <netinet/tcp.h>
65 #include "common/efx.h"
70 /* Set the block level to ensure there is space to generate a
71 * large number of descriptors for TSO. With minimum MSS and
72 * maximum mbuf length we might need more than a ring-ful of
73 * descriptors, but this should not happen in practice except
74 * due to deliberate attack. In that case we will truncate
75 * the output at a packet boundary.
77 #define SFXGE_TSO_MAX_DESC \
78 (SFXGE_TSO_MAX_SEGS * 2 + SFXGE_TX_MAPPING_MAX_SEG - 1)
79 #define SFXGE_TXQ_BLOCK_LEVEL(_entries) ((_entries) - SFXGE_TSO_MAX_DESC)
83 #define SFXGE_PARAM_TX_DPL_GET_MAX SFXGE_PARAM(tx_dpl_get_max)
84 static int sfxge_tx_dpl_get_max = SFXGE_TX_DPL_GET_PKT_LIMIT_DEFAULT;
85 TUNABLE_INT(SFXGE_PARAM_TX_DPL_GET_MAX, &sfxge_tx_dpl_get_max);
86 SYSCTL_INT(_hw_sfxge, OID_AUTO, tx_dpl_get_max, CTLFLAG_RDTUN,
87 &sfxge_tx_dpl_get_max, 0,
88 "Maximum number of any packets in deferred packet get-list");
90 #define SFXGE_PARAM_TX_DPL_GET_NON_TCP_MAX \
91 SFXGE_PARAM(tx_dpl_get_non_tcp_max)
92 static int sfxge_tx_dpl_get_non_tcp_max =
93 SFXGE_TX_DPL_GET_NON_TCP_PKT_LIMIT_DEFAULT;
94 TUNABLE_INT(SFXGE_PARAM_TX_DPL_GET_NON_TCP_MAX, &sfxge_tx_dpl_get_non_tcp_max);
95 SYSCTL_INT(_hw_sfxge, OID_AUTO, tx_dpl_get_non_tcp_max, CTLFLAG_RDTUN,
96 &sfxge_tx_dpl_get_non_tcp_max, 0,
97 "Maximum number of non-TCP packets in deferred packet get-list");
99 #define SFXGE_PARAM_TX_DPL_PUT_MAX SFXGE_PARAM(tx_dpl_put_max)
100 static int sfxge_tx_dpl_put_max = SFXGE_TX_DPL_PUT_PKT_LIMIT_DEFAULT;
101 TUNABLE_INT(SFXGE_PARAM_TX_DPL_PUT_MAX, &sfxge_tx_dpl_put_max);
102 SYSCTL_INT(_hw_sfxge, OID_AUTO, tx_dpl_put_max, CTLFLAG_RDTUN,
103 &sfxge_tx_dpl_put_max, 0,
104 "Maximum number of any packets in deferred packet put-list");
109 /* Forward declarations. */
110 static void sfxge_tx_qdpl_service(struct sfxge_txq *txq);
111 static void sfxge_tx_qlist_post(struct sfxge_txq *txq);
112 static void sfxge_tx_qunblock(struct sfxge_txq *txq);
113 static int sfxge_tx_queue_tso(struct sfxge_txq *txq, struct mbuf *mbuf,
114 const bus_dma_segment_t *dma_seg, int n_dma_seg);
117 sfxge_tx_qcomplete(struct sfxge_txq *txq, struct sfxge_evq *evq)
119 unsigned int completed;
121 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
123 completed = txq->completed;
124 while (completed != txq->pending) {
125 struct sfxge_tx_mapping *stmp;
128 id = completed++ & txq->ptr_mask;
130 stmp = &txq->stmp[id];
131 if (stmp->flags & TX_BUF_UNMAP) {
132 bus_dmamap_unload(txq->packet_dma_tag, stmp->map);
133 if (stmp->flags & TX_BUF_MBUF) {
134 struct mbuf *m = stmp->u.mbuf;
139 free(stmp->u.heap_buf, M_SFXGE);
144 txq->completed = completed;
146 /* Check whether we need to unblock the queue. */
151 level = txq->added - txq->completed;
152 if (level <= SFXGE_TXQ_UNBLOCK_LEVEL(txq->entries))
153 sfxge_tx_qunblock(txq);
160 sfxge_is_mbuf_non_tcp(struct mbuf *mbuf)
162 /* Absense of TCP checksum flags does not mean that it is non-TCP
163 * but it should be true if user wants to achieve high throughput.
165 return (!(mbuf->m_pkthdr.csum_flags & (CSUM_IP_TCP | CSUM_IP6_TCP)));
169 * Reorder the put list and append it to the get list.
172 sfxge_tx_qdpl_swizzle(struct sfxge_txq *txq)
174 struct sfxge_tx_dpl *stdp;
175 struct mbuf *mbuf, *get_next, **get_tailp;
176 volatile uintptr_t *putp;
179 unsigned int non_tcp_count;
181 SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
185 /* Acquire the put list. */
186 putp = &stdp->std_put;
187 put = atomic_readandclear_ptr(putp);
193 /* Reverse the put list. */
194 get_tailp = &mbuf->m_nextpkt;
200 struct mbuf *put_next;
202 non_tcp_count += sfxge_is_mbuf_non_tcp(mbuf);
203 put_next = mbuf->m_nextpkt;
204 mbuf->m_nextpkt = get_next;
209 } while (mbuf != NULL);
211 /* Append the reversed put list to the get list. */
212 KASSERT(*get_tailp == NULL, ("*get_tailp != NULL"));
213 *stdp->std_getp = get_next;
214 stdp->std_getp = get_tailp;
215 stdp->std_get_count += count;
216 stdp->std_get_non_tcp_count += non_tcp_count;
219 #endif /* SFXGE_HAVE_MQ */
222 sfxge_tx_qreap(struct sfxge_txq *txq)
224 SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
226 txq->reaped = txq->completed;
230 sfxge_tx_qlist_post(struct sfxge_txq *txq)
232 unsigned int old_added;
236 SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
238 KASSERT(txq->n_pend_desc != 0, ("txq->n_pend_desc == 0"));
239 KASSERT(txq->n_pend_desc <= SFXGE_TSO_MAX_DESC,
240 ("txq->n_pend_desc too large"));
241 KASSERT(!txq->blocked, ("txq->blocked"));
243 old_added = txq->added;
245 /* Post the fragment list. */
246 rc = efx_tx_qpost(txq->common, txq->pend_desc, txq->n_pend_desc,
247 txq->reaped, &txq->added);
248 KASSERT(rc == 0, ("efx_tx_qpost() failed"));
250 /* If efx_tx_qpost() had to refragment, our information about
251 * buffers to free may be associated with the wrong
254 KASSERT(txq->added - old_added == txq->n_pend_desc,
255 ("efx_tx_qpost() refragmented descriptors"));
257 level = txq->added - txq->reaped;
258 KASSERT(level <= txq->entries, ("overfilled TX queue"));
260 /* Clear the fragment list. */
261 txq->n_pend_desc = 0;
263 /* Have we reached the block level? */
264 if (level < SFXGE_TXQ_BLOCK_LEVEL(txq->entries))
267 /* Reap, and check again */
269 level = txq->added - txq->reaped;
270 if (level < SFXGE_TXQ_BLOCK_LEVEL(txq->entries))
276 * Avoid a race with completion interrupt handling that could leave
281 level = txq->added - txq->reaped;
282 if (level < SFXGE_TXQ_BLOCK_LEVEL(txq->entries)) {
288 static int sfxge_tx_queue_mbuf(struct sfxge_txq *txq, struct mbuf *mbuf)
290 bus_dmamap_t *used_map;
292 bus_dma_segment_t dma_seg[SFXGE_TX_MAPPING_MAX_SEG];
294 struct sfxge_tx_mapping *stmp;
300 KASSERT(!txq->blocked, ("txq->blocked"));
302 if (mbuf->m_pkthdr.csum_flags & CSUM_TSO)
303 prefetch_read_many(mbuf->m_data);
305 if (txq->init_state != SFXGE_TXQ_STARTED) {
310 /* Load the packet for DMA. */
311 id = txq->added & txq->ptr_mask;
312 stmp = &txq->stmp[id];
313 rc = bus_dmamap_load_mbuf_sg(txq->packet_dma_tag, stmp->map,
314 mbuf, dma_seg, &n_dma_seg, 0);
317 struct mbuf *new_mbuf = m_collapse(mbuf, M_NOWAIT,
318 SFXGE_TX_MAPPING_MAX_SEG);
319 if (new_mbuf == NULL)
323 rc = bus_dmamap_load_mbuf_sg(txq->packet_dma_tag,
325 dma_seg, &n_dma_seg, 0);
330 /* Make the packet visible to the hardware. */
331 bus_dmamap_sync(txq->packet_dma_tag, stmp->map, BUS_DMASYNC_PREWRITE);
333 used_map = &stmp->map;
335 if (mbuf->m_pkthdr.csum_flags & CSUM_TSO) {
336 rc = sfxge_tx_queue_tso(txq, mbuf, dma_seg, n_dma_seg);
339 stmp = &txq->stmp[rc];
341 /* Add the mapping to the fragment list, and set flags
346 desc = &txq->pend_desc[i];
347 desc->eb_addr = dma_seg[i].ds_addr;
348 desc->eb_size = dma_seg[i].ds_len;
349 if (i == n_dma_seg - 1) {
357 if (__predict_false(stmp ==
358 &txq->stmp[txq->ptr_mask]))
359 stmp = &txq->stmp[0];
363 txq->n_pend_desc = n_dma_seg;
367 * If the mapping required more than one descriptor
368 * then we need to associate the DMA map with the last
369 * descriptor, not the first.
371 if (used_map != &stmp->map) {
373 stmp->map = *used_map;
378 stmp->flags = TX_BUF_UNMAP | TX_BUF_MBUF;
380 /* Post the fragment list. */
381 sfxge_tx_qlist_post(txq);
386 bus_dmamap_unload(txq->packet_dma_tag, *used_map);
388 /* Drop the packet on the floor. */
398 * Drain the deferred packet list into the transmit queue.
401 sfxge_tx_qdpl_drain(struct sfxge_txq *txq)
403 struct sfxge_softc *sc;
404 struct sfxge_tx_dpl *stdp;
405 struct mbuf *mbuf, *next;
407 unsigned int non_tcp_count;
411 SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
417 prefetch_read_many(sc->enp);
418 prefetch_read_many(txq->common);
420 mbuf = stdp->std_get;
421 count = stdp->std_get_count;
422 non_tcp_count = stdp->std_get_non_tcp_count;
424 if (count > stdp->std_get_hiwat)
425 stdp->std_get_hiwat = count;
428 KASSERT(mbuf != NULL, ("mbuf == NULL"));
430 next = mbuf->m_nextpkt;
431 mbuf->m_nextpkt = NULL;
433 ETHER_BPF_MTAP(sc->ifnet, mbuf); /* packet capture */
436 prefetch_read_many(next);
438 rc = sfxge_tx_queue_mbuf(txq, mbuf);
440 non_tcp_count -= sfxge_is_mbuf_non_tcp(mbuf);
448 /* Push the fragments to the hardware in batches. */
449 if (txq->added - pushed >= SFXGE_TX_BATCH) {
450 efx_tx_qpush(txq->common, txq->added);
456 KASSERT(mbuf == NULL, ("mbuf != NULL"));
457 KASSERT(non_tcp_count == 0,
458 ("inconsistent TCP/non-TCP detection"));
459 stdp->std_get = NULL;
460 stdp->std_get_count = 0;
461 stdp->std_get_non_tcp_count = 0;
462 stdp->std_getp = &stdp->std_get;
464 stdp->std_get = mbuf;
465 stdp->std_get_count = count;
466 stdp->std_get_non_tcp_count = non_tcp_count;
469 if (txq->added != pushed)
470 efx_tx_qpush(txq->common, txq->added);
472 KASSERT(txq->blocked || stdp->std_get_count == 0,
473 ("queue unblocked but count is non-zero"));
476 #define SFXGE_TX_QDPL_PENDING(_txq) \
477 ((_txq)->dpl.std_put != 0)
480 * Service the deferred packet list.
482 * NOTE: drops the txq mutex!
485 sfxge_tx_qdpl_service(struct sfxge_txq *txq)
487 SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
490 if (SFXGE_TX_QDPL_PENDING(txq))
491 sfxge_tx_qdpl_swizzle(txq);
494 sfxge_tx_qdpl_drain(txq);
496 SFXGE_TXQ_UNLOCK(txq);
497 } while (SFXGE_TX_QDPL_PENDING(txq) &&
498 SFXGE_TXQ_TRYLOCK(txq));
502 * Put a packet on the deferred packet list.
504 * If we are called with the txq lock held, we put the packet on the "get
505 * list", otherwise we atomically push it on the "put list". The swizzle
506 * function takes care of ordering.
508 * The length of the put list is bounded by SFXGE_TX_MAX_DEFFERED. We
509 * overload the csum_data field in the mbuf to keep track of this length
510 * because there is no cheap alternative to avoid races.
513 sfxge_tx_qdpl_put(struct sfxge_txq *txq, struct mbuf *mbuf, int locked)
515 struct sfxge_tx_dpl *stdp;
519 KASSERT(mbuf->m_nextpkt == NULL, ("mbuf->m_nextpkt != NULL"));
522 SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
524 sfxge_tx_qdpl_swizzle(txq);
526 if (stdp->std_get_count >= stdp->std_get_max) {
530 if (sfxge_is_mbuf_non_tcp(mbuf)) {
531 if (stdp->std_get_non_tcp_count >=
532 stdp->std_get_non_tcp_max) {
533 txq->get_non_tcp_overflow++;
536 stdp->std_get_non_tcp_count++;
539 *(stdp->std_getp) = mbuf;
540 stdp->std_getp = &mbuf->m_nextpkt;
541 stdp->std_get_count++;
543 volatile uintptr_t *putp;
548 putp = &stdp->std_put;
549 new = (uintptr_t)mbuf;
554 struct mbuf *mp = (struct mbuf *)old;
555 old_len = mp->m_pkthdr.csum_data;
558 if (old_len >= stdp->std_put_max) {
559 atomic_add_long(&txq->put_overflow, 1);
562 mbuf->m_pkthdr.csum_data = old_len + 1;
563 mbuf->m_nextpkt = (void *)old;
564 } while (atomic_cmpset_ptr(putp, old, new) == 0);
571 * Called from if_transmit - will try to grab the txq lock and enqueue to the
572 * put list if it succeeds, otherwise will push onto the defer list.
575 sfxge_tx_packet_add(struct sfxge_txq *txq, struct mbuf *m)
580 if (!SFXGE_LINK_UP(txq->sc)) {
582 atomic_add_long(&txq->netdown_drops, 1);
587 * Try to grab the txq lock. If we are able to get the lock,
588 * the packet will be appended to the "get list" of the deferred
589 * packet list. Otherwise, it will be pushed on the "put list".
591 locked = SFXGE_TXQ_TRYLOCK(txq);
593 if (sfxge_tx_qdpl_put(txq, m, locked) != 0) {
595 SFXGE_TXQ_UNLOCK(txq);
601 * Try to grab the lock again.
603 * If we are able to get the lock, we need to process the deferred
604 * packet list. If we are not able to get the lock, another thread
605 * is processing the list.
608 locked = SFXGE_TXQ_TRYLOCK(txq);
611 /* Try to service the list. */
612 sfxge_tx_qdpl_service(txq);
613 /* Lock has been dropped. */
624 sfxge_tx_qdpl_flush(struct sfxge_txq *txq)
626 struct sfxge_tx_dpl *stdp = &txq->dpl;
627 struct mbuf *mbuf, *next;
631 sfxge_tx_qdpl_swizzle(txq);
632 for (mbuf = stdp->std_get; mbuf != NULL; mbuf = next) {
633 next = mbuf->m_nextpkt;
636 stdp->std_get = NULL;
637 stdp->std_get_count = 0;
638 stdp->std_get_non_tcp_count = 0;
639 stdp->std_getp = &stdp->std_get;
641 SFXGE_TXQ_UNLOCK(txq);
645 sfxge_if_qflush(struct ifnet *ifp)
647 struct sfxge_softc *sc;
652 for (i = 0; i < sc->txq_count; i++)
653 sfxge_tx_qdpl_flush(sc->txq[i]);
657 * TX start -- called by the stack.
660 sfxge_if_transmit(struct ifnet *ifp, struct mbuf *m)
662 struct sfxge_softc *sc;
663 struct sfxge_txq *txq;
666 sc = (struct sfxge_softc *)ifp->if_softc;
668 KASSERT(ifp->if_flags & IFF_UP, ("interface not up"));
670 /* Pick the desired transmit queue. */
671 if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | CSUM_TSO)) {
674 if (m->m_flags & M_FLOWID) {
675 uint32_t hash = m->m_pkthdr.flowid;
677 index = sc->rx_indir_table[hash % SFXGE_RX_SCALE_MAX];
679 txq = sc->txq[SFXGE_TXQ_IP_TCP_UDP_CKSUM + index];
680 } else if (m->m_pkthdr.csum_flags & CSUM_DELAY_IP) {
681 txq = sc->txq[SFXGE_TXQ_IP_CKSUM];
683 txq = sc->txq[SFXGE_TXQ_NON_CKSUM];
686 rc = sfxge_tx_packet_add(txq, m);
691 #else /* !SFXGE_HAVE_MQ */
693 static void sfxge_if_start_locked(struct ifnet *ifp)
695 struct sfxge_softc *sc = ifp->if_softc;
696 struct sfxge_txq *txq;
698 unsigned int pushed[SFXGE_TXQ_NTYPES];
699 unsigned int q_index;
701 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) !=
705 if (!sc->port.link_up)
708 for (q_index = 0; q_index < SFXGE_TXQ_NTYPES; q_index++) {
709 txq = sc->txq[q_index];
710 pushed[q_index] = txq->added;
713 while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
714 IFQ_DRV_DEQUEUE(&ifp->if_snd, mbuf);
718 ETHER_BPF_MTAP(ifp, mbuf); /* packet capture */
720 /* Pick the desired transmit queue. */
721 if (mbuf->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | CSUM_TSO))
722 q_index = SFXGE_TXQ_IP_TCP_UDP_CKSUM;
723 else if (mbuf->m_pkthdr.csum_flags & CSUM_DELAY_IP)
724 q_index = SFXGE_TXQ_IP_CKSUM;
726 q_index = SFXGE_TXQ_NON_CKSUM;
727 txq = sc->txq[q_index];
729 if (sfxge_tx_queue_mbuf(txq, mbuf) != 0)
733 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
737 /* Push the fragments to the hardware in batches. */
738 if (txq->added - pushed[q_index] >= SFXGE_TX_BATCH) {
739 efx_tx_qpush(txq->common, txq->added);
740 pushed[q_index] = txq->added;
744 for (q_index = 0; q_index < SFXGE_TXQ_NTYPES; q_index++) {
745 txq = sc->txq[q_index];
746 if (txq->added != pushed[q_index])
747 efx_tx_qpush(txq->common, txq->added);
751 void sfxge_if_start(struct ifnet *ifp)
753 struct sfxge_softc *sc = ifp->if_softc;
755 SFXGE_TXQ_LOCK(sc->txq[0]);
756 sfxge_if_start_locked(ifp);
757 SFXGE_TXQ_UNLOCK(sc->txq[0]);
761 sfxge_tx_qdpl_service(struct sfxge_txq *txq)
763 struct ifnet *ifp = txq->sc->ifnet;
765 SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
766 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
767 sfxge_if_start_locked(ifp);
768 SFXGE_TXQ_UNLOCK(txq);
771 #endif /* SFXGE_HAVE_MQ */
774 * Software "TSO". Not quite as good as doing it in hardware, but
775 * still faster than segmenting in the stack.
778 struct sfxge_tso_state {
779 /* Output position */
780 unsigned out_len; /* Remaining length in current segment */
781 unsigned seqnum; /* Current sequence number */
782 unsigned packet_space; /* Remaining space in current packet */
785 uint64_t dma_addr; /* DMA address of current position */
786 unsigned in_len; /* Remaining length in current mbuf */
788 const struct mbuf *mbuf; /* Input mbuf (head of chain) */
789 u_short protocol; /* Network protocol (after VLAN decap) */
790 ssize_t nh_off; /* Offset of network header */
791 ssize_t tcph_off; /* Offset of TCP header */
792 unsigned header_len; /* Number of bytes of header */
793 unsigned seg_size; /* TCP segment size */
796 static const struct ip *tso_iph(const struct sfxge_tso_state *tso)
798 KASSERT(tso->protocol == htons(ETHERTYPE_IP),
799 ("tso_iph() in non-IPv4 state"));
800 return (const struct ip *)(tso->mbuf->m_data + tso->nh_off);
802 static __unused const struct ip6_hdr *tso_ip6h(const struct sfxge_tso_state *tso)
804 KASSERT(tso->protocol == htons(ETHERTYPE_IPV6),
805 ("tso_ip6h() in non-IPv6 state"));
806 return (const struct ip6_hdr *)(tso->mbuf->m_data + tso->nh_off);
808 static const struct tcphdr *tso_tcph(const struct sfxge_tso_state *tso)
810 return (const struct tcphdr *)(tso->mbuf->m_data + tso->tcph_off);
813 /* Size of preallocated TSO header buffers. Larger blocks must be
814 * allocated from the heap.
816 #define TSOH_STD_SIZE 128
818 /* At most half the descriptors in the queue at any time will refer to
819 * a TSO header buffer, since they must always be followed by a
820 * payload descriptor referring to an mbuf.
822 #define TSOH_COUNT(_txq_entries) ((_txq_entries) / 2u)
823 #define TSOH_PER_PAGE (PAGE_SIZE / TSOH_STD_SIZE)
824 #define TSOH_PAGE_COUNT(_txq_entries) \
825 ((TSOH_COUNT(_txq_entries) + TSOH_PER_PAGE - 1) / TSOH_PER_PAGE)
827 static int tso_init(struct sfxge_txq *txq)
829 struct sfxge_softc *sc = txq->sc;
830 unsigned int tsoh_page_count = TSOH_PAGE_COUNT(sc->txq_entries);
833 /* Allocate TSO header buffers */
834 txq->tsoh_buffer = malloc(tsoh_page_count * sizeof(txq->tsoh_buffer[0]),
837 for (i = 0; i < tsoh_page_count; i++) {
838 rc = sfxge_dma_alloc(sc, PAGE_SIZE, &txq->tsoh_buffer[i]);
847 sfxge_dma_free(&txq->tsoh_buffer[i]);
848 free(txq->tsoh_buffer, M_SFXGE);
849 txq->tsoh_buffer = NULL;
853 static void tso_fini(struct sfxge_txq *txq)
857 if (txq->tsoh_buffer != NULL) {
858 for (i = 0; i < TSOH_PAGE_COUNT(txq->sc->txq_entries); i++)
859 sfxge_dma_free(&txq->tsoh_buffer[i]);
860 free(txq->tsoh_buffer, M_SFXGE);
864 static void tso_start(struct sfxge_tso_state *tso, struct mbuf *mbuf)
866 struct ether_header *eh = mtod(mbuf, struct ether_header *);
867 const struct tcphdr *th;
868 struct tcphdr th_copy;
872 /* Find network protocol and header */
873 tso->protocol = eh->ether_type;
874 if (tso->protocol == htons(ETHERTYPE_VLAN)) {
875 struct ether_vlan_header *veh =
876 mtod(mbuf, struct ether_vlan_header *);
877 tso->protocol = veh->evl_proto;
878 tso->nh_off = sizeof(*veh);
880 tso->nh_off = sizeof(*eh);
883 /* Find TCP header */
884 if (tso->protocol == htons(ETHERTYPE_IP)) {
885 KASSERT(tso_iph(tso)->ip_p == IPPROTO_TCP,
886 ("TSO required on non-TCP packet"));
887 tso->tcph_off = tso->nh_off + 4 * tso_iph(tso)->ip_hl;
889 KASSERT(tso->protocol == htons(ETHERTYPE_IPV6),
890 ("TSO required on non-IP packet"));
891 KASSERT(tso_ip6h(tso)->ip6_nxt == IPPROTO_TCP,
892 ("TSO required on non-TCP packet"));
893 tso->tcph_off = tso->nh_off + sizeof(struct ip6_hdr);
896 KASSERT(mbuf->m_len >= tso->tcph_off,
897 ("network header is fragmented in mbuf"));
898 /* We need TCP header including flags (window is the next) */
899 if (mbuf->m_len < tso->tcph_off + offsetof(struct tcphdr, th_win)) {
900 m_copydata(tso->mbuf, tso->tcph_off, sizeof(th_copy),
907 tso->header_len = tso->tcph_off + 4 * th->th_off;
908 tso->seg_size = mbuf->m_pkthdr.tso_segsz;
910 tso->seqnum = ntohl(th->th_seq);
912 /* These flags must not be duplicated */
913 KASSERT(!(th->th_flags & (TH_URG | TH_SYN | TH_RST)),
914 ("incompatible TCP flag on TSO packet"));
916 tso->out_len = mbuf->m_pkthdr.len - tso->header_len;
920 * tso_fill_packet_with_fragment - form descriptors for the current fragment
922 * Form descriptors for the current fragment, until we reach the end
923 * of fragment or end-of-packet. Return 0 on success, 1 if not enough
926 static void tso_fill_packet_with_fragment(struct sfxge_txq *txq,
927 struct sfxge_tso_state *tso)
932 if (tso->in_len == 0 || tso->packet_space == 0)
935 KASSERT(tso->in_len > 0, ("TSO input length went negative"));
936 KASSERT(tso->packet_space > 0, ("TSO packet space went negative"));
938 n = min(tso->in_len, tso->packet_space);
940 tso->packet_space -= n;
944 desc = &txq->pend_desc[txq->n_pend_desc++];
945 desc->eb_addr = tso->dma_addr;
947 desc->eb_eop = tso->out_len == 0 || tso->packet_space == 0;
952 /* Callback from bus_dmamap_load() for long TSO headers. */
953 static void tso_map_long_header(void *dma_addr_ret,
954 bus_dma_segment_t *segs, int nseg,
957 *(uint64_t *)dma_addr_ret = ((__predict_true(error == 0) &&
958 __predict_true(nseg == 1)) ?
963 * tso_start_new_packet - generate a new header and prepare for the new packet
965 * Generate a new header and prepare for the new packet. Return 0 on
966 * success, or an error code if failed to alloc header.
968 static int tso_start_new_packet(struct sfxge_txq *txq,
969 struct sfxge_tso_state *tso,
972 struct sfxge_tx_mapping *stmp = &txq->stmp[id];
973 struct tcphdr *tsoh_th;
981 /* Allocate a DMA-mapped header buffer. */
982 if (__predict_true(tso->header_len <= TSOH_STD_SIZE)) {
983 unsigned int page_index = (id / 2) / TSOH_PER_PAGE;
984 unsigned int buf_index = (id / 2) % TSOH_PER_PAGE;
986 header = (txq->tsoh_buffer[page_index].esm_base +
987 buf_index * TSOH_STD_SIZE);
988 dma_addr = (txq->tsoh_buffer[page_index].esm_addr +
989 buf_index * TSOH_STD_SIZE);
990 map = txq->tsoh_buffer[page_index].esm_map;
994 /* We cannot use bus_dmamem_alloc() as that may sleep */
995 header = malloc(tso->header_len, M_SFXGE, M_NOWAIT);
996 if (__predict_false(!header))
998 rc = bus_dmamap_load(txq->packet_dma_tag, stmp->map,
999 header, tso->header_len,
1000 tso_map_long_header, &dma_addr,
1002 if (__predict_false(dma_addr == 0)) {
1004 /* Succeeded but got >1 segment */
1005 bus_dmamap_unload(txq->packet_dma_tag,
1009 free(header, M_SFXGE);
1014 txq->tso_long_headers++;
1015 stmp->u.heap_buf = header;
1016 stmp->flags = TX_BUF_UNMAP;
1019 tsoh_th = (struct tcphdr *)(header + tso->tcph_off);
1021 /* Copy and update the headers. */
1022 m_copydata(tso->mbuf, 0, tso->header_len, header);
1024 tsoh_th->th_seq = htonl(tso->seqnum);
1025 tso->seqnum += tso->seg_size;
1026 if (tso->out_len > tso->seg_size) {
1027 /* This packet will not finish the TSO burst. */
1028 ip_length = tso->header_len - tso->nh_off + tso->seg_size;
1029 tsoh_th->th_flags &= ~(TH_FIN | TH_PUSH);
1031 /* This packet will be the last in the TSO burst. */
1032 ip_length = tso->header_len - tso->nh_off + tso->out_len;
1035 if (tso->protocol == htons(ETHERTYPE_IP)) {
1036 struct ip *tsoh_iph = (struct ip *)(header + tso->nh_off);
1037 tsoh_iph->ip_len = htons(ip_length);
1038 /* XXX We should increment ip_id, but FreeBSD doesn't
1039 * currently allocate extra IDs for multiple segments.
1042 struct ip6_hdr *tsoh_iph =
1043 (struct ip6_hdr *)(header + tso->nh_off);
1044 tsoh_iph->ip6_plen = htons(ip_length - sizeof(*tsoh_iph));
1047 /* Make the header visible to the hardware. */
1048 bus_dmamap_sync(txq->packet_dma_tag, map, BUS_DMASYNC_PREWRITE);
1050 tso->packet_space = tso->seg_size;
1053 /* Form a descriptor for this header. */
1054 desc = &txq->pend_desc[txq->n_pend_desc++];
1055 desc->eb_addr = dma_addr;
1056 desc->eb_size = tso->header_len;
1063 sfxge_tx_queue_tso(struct sfxge_txq *txq, struct mbuf *mbuf,
1064 const bus_dma_segment_t *dma_seg, int n_dma_seg)
1066 struct sfxge_tso_state tso;
1067 unsigned int id, next_id;
1068 unsigned skipped = 0;
1070 tso_start(&tso, mbuf);
1072 while (dma_seg->ds_len + skipped <= tso.header_len) {
1073 skipped += dma_seg->ds_len;
1075 KASSERT(n_dma_seg, ("no payload found in TSO packet"));
1078 tso.in_len = dma_seg->ds_len + (tso.header_len - skipped);
1079 tso.dma_addr = dma_seg->ds_addr + (tso.header_len - skipped);
1081 id = txq->added & txq->ptr_mask;
1082 if (__predict_false(tso_start_new_packet(txq, &tso, id)))
1086 id = (id + 1) & txq->ptr_mask;
1087 tso_fill_packet_with_fragment(txq, &tso);
1089 /* Move onto the next fragment? */
1090 if (tso.in_len == 0) {
1095 tso.in_len = dma_seg->ds_len;
1096 tso.dma_addr = dma_seg->ds_addr;
1099 /* End of packet? */
1100 if (tso.packet_space == 0) {
1101 /* If the queue is now full due to tiny MSS,
1102 * or we can't create another header, discard
1103 * the remainder of the input mbuf but do not
1104 * roll back the work we have done.
1106 if (txq->n_pend_desc >
1107 SFXGE_TSO_MAX_DESC - (1 + SFXGE_TX_MAPPING_MAX_SEG)) {
1108 txq->tso_pdrop_too_many++;
1111 next_id = (id + 1) & txq->ptr_mask;
1112 if (__predict_false(tso_start_new_packet(txq, &tso,
1114 txq->tso_pdrop_no_rsrc++;
1126 sfxge_tx_qunblock(struct sfxge_txq *txq)
1128 struct sfxge_softc *sc;
1129 struct sfxge_evq *evq;
1132 evq = sc->evq[txq->evq_index];
1134 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
1136 if (txq->init_state != SFXGE_TXQ_STARTED)
1139 SFXGE_TXQ_LOCK(txq);
1144 level = txq->added - txq->completed;
1145 if (level <= SFXGE_TXQ_UNBLOCK_LEVEL(txq->entries)) {
1146 /* reaped must be in sync with blocked */
1147 sfxge_tx_qreap(txq);
1152 sfxge_tx_qdpl_service(txq);
1153 /* note: lock has been dropped */
1157 sfxge_tx_qflush_done(struct sfxge_txq *txq)
1160 txq->flush_state = SFXGE_FLUSH_DONE;
1164 sfxge_tx_qstop(struct sfxge_softc *sc, unsigned int index)
1166 struct sfxge_txq *txq;
1167 struct sfxge_evq *evq;
1170 txq = sc->txq[index];
1171 evq = sc->evq[txq->evq_index];
1173 SFXGE_TXQ_LOCK(txq);
1175 KASSERT(txq->init_state == SFXGE_TXQ_STARTED,
1176 ("txq->init_state != SFXGE_TXQ_STARTED"));
1178 txq->init_state = SFXGE_TXQ_INITIALIZED;
1179 txq->flush_state = SFXGE_FLUSH_PENDING;
1181 /* Flush the transmit queue. */
1182 efx_tx_qflush(txq->common);
1184 SFXGE_TXQ_UNLOCK(txq);
1188 /* Spin for 100ms. */
1191 if (txq->flush_state != SFXGE_FLUSH_PENDING)
1193 } while (++count < 20);
1195 SFXGE_EVQ_LOCK(evq);
1196 SFXGE_TXQ_LOCK(txq);
1198 KASSERT(txq->flush_state != SFXGE_FLUSH_FAILED,
1199 ("txq->flush_state == SFXGE_FLUSH_FAILED"));
1201 txq->flush_state = SFXGE_FLUSH_DONE;
1204 txq->pending = txq->added;
1206 sfxge_tx_qcomplete(txq, evq);
1207 KASSERT(txq->completed == txq->added,
1208 ("txq->completed != txq->added"));
1210 sfxge_tx_qreap(txq);
1211 KASSERT(txq->reaped == txq->completed,
1212 ("txq->reaped != txq->completed"));
1219 /* Destroy the common code transmit queue. */
1220 efx_tx_qdestroy(txq->common);
1223 efx_sram_buf_tbl_clear(sc->enp, txq->buf_base_id,
1224 EFX_TXQ_NBUFS(sc->txq_entries));
1226 SFXGE_EVQ_UNLOCK(evq);
1227 SFXGE_TXQ_UNLOCK(txq);
1231 sfxge_tx_qstart(struct sfxge_softc *sc, unsigned int index)
1233 struct sfxge_txq *txq;
1236 struct sfxge_evq *evq;
1239 txq = sc->txq[index];
1241 evq = sc->evq[txq->evq_index];
1243 KASSERT(txq->init_state == SFXGE_TXQ_INITIALIZED,
1244 ("txq->init_state != SFXGE_TXQ_INITIALIZED"));
1245 KASSERT(evq->init_state == SFXGE_EVQ_STARTED,
1246 ("evq->init_state != SFXGE_EVQ_STARTED"));
1248 /* Program the buffer table. */
1249 if ((rc = efx_sram_buf_tbl_set(sc->enp, txq->buf_base_id, esmp,
1250 EFX_TXQ_NBUFS(sc->txq_entries))) != 0)
1253 /* Determine the kind of queue we are creating. */
1254 switch (txq->type) {
1255 case SFXGE_TXQ_NON_CKSUM:
1258 case SFXGE_TXQ_IP_CKSUM:
1259 flags = EFX_CKSUM_IPV4;
1261 case SFXGE_TXQ_IP_TCP_UDP_CKSUM:
1262 flags = EFX_CKSUM_IPV4 | EFX_CKSUM_TCPUDP;
1265 KASSERT(0, ("Impossible TX queue"));
1270 /* Create the common code transmit queue. */
1271 if ((rc = efx_tx_qcreate(sc->enp, index, txq->type, esmp,
1272 sc->txq_entries, txq->buf_base_id, flags, evq->common,
1273 &txq->common)) != 0)
1276 SFXGE_TXQ_LOCK(txq);
1278 /* Enable the transmit queue. */
1279 efx_tx_qenable(txq->common);
1281 txq->init_state = SFXGE_TXQ_STARTED;
1283 SFXGE_TXQ_UNLOCK(txq);
1288 efx_sram_buf_tbl_clear(sc->enp, txq->buf_base_id,
1289 EFX_TXQ_NBUFS(sc->txq_entries));
1294 sfxge_tx_stop(struct sfxge_softc *sc)
1298 index = sc->txq_count;
1299 while (--index >= 0)
1300 sfxge_tx_qstop(sc, index);
1302 /* Tear down the transmit module */
1303 efx_tx_fini(sc->enp);
1307 sfxge_tx_start(struct sfxge_softc *sc)
1312 /* Initialize the common code transmit module. */
1313 if ((rc = efx_tx_init(sc->enp)) != 0)
1316 for (index = 0; index < sc->txq_count; index++) {
1317 if ((rc = sfxge_tx_qstart(sc, index)) != 0)
1324 while (--index >= 0)
1325 sfxge_tx_qstop(sc, index);
1327 efx_tx_fini(sc->enp);
1333 * Destroy a transmit queue.
1336 sfxge_tx_qfini(struct sfxge_softc *sc, unsigned int index)
1338 struct sfxge_txq *txq;
1341 txq = sc->txq[index];
1343 KASSERT(txq->init_state == SFXGE_TXQ_INITIALIZED,
1344 ("txq->init_state != SFXGE_TXQ_INITIALIZED"));
1346 if (txq->type == SFXGE_TXQ_IP_TCP_UDP_CKSUM)
1349 /* Free the context arrays. */
1350 free(txq->pend_desc, M_SFXGE);
1351 nmaps = sc->txq_entries;
1352 while (nmaps-- != 0)
1353 bus_dmamap_destroy(txq->packet_dma_tag, txq->stmp[nmaps].map);
1354 free(txq->stmp, M_SFXGE);
1356 /* Release DMA memory mapping. */
1357 sfxge_dma_free(&txq->mem);
1359 sc->txq[index] = NULL;
1361 #ifdef SFXGE_HAVE_MQ
1362 SFXGE_TXQ_LOCK_DESTROY(txq);
1369 sfxge_tx_qinit(struct sfxge_softc *sc, unsigned int txq_index,
1370 enum sfxge_txq_type type, unsigned int evq_index)
1373 struct sysctl_oid *txq_node;
1374 struct sfxge_txq *txq;
1375 struct sfxge_evq *evq;
1376 #ifdef SFXGE_HAVE_MQ
1377 struct sfxge_tx_dpl *stdp;
1383 txq = malloc(sizeof(struct sfxge_txq), M_SFXGE, M_ZERO | M_WAITOK);
1385 txq->entries = sc->txq_entries;
1386 txq->ptr_mask = txq->entries - 1;
1388 sc->txq[txq_index] = txq;
1391 evq = sc->evq[evq_index];
1393 /* Allocate and zero DMA space for the descriptor ring. */
1394 if ((rc = sfxge_dma_alloc(sc, EFX_TXQ_SIZE(sc->txq_entries), esmp)) != 0)
1396 (void)memset(esmp->esm_base, 0, EFX_TXQ_SIZE(sc->txq_entries));
1398 /* Allocate buffer table entries. */
1399 sfxge_sram_buf_tbl_alloc(sc, EFX_TXQ_NBUFS(sc->txq_entries),
1402 /* Create a DMA tag for packet mappings. */
1403 if (bus_dma_tag_create(sc->parent_dma_tag, 1, 0x1000,
1404 MIN(0x3FFFFFFFFFFFUL, BUS_SPACE_MAXADDR), BUS_SPACE_MAXADDR, NULL,
1405 NULL, 0x11000, SFXGE_TX_MAPPING_MAX_SEG, 0x1000, 0, NULL, NULL,
1406 &txq->packet_dma_tag) != 0) {
1407 device_printf(sc->dev, "Couldn't allocate txq DMA tag\n");
1412 /* Allocate pending descriptor array for batching writes. */
1413 txq->pend_desc = malloc(sizeof(efx_buffer_t) * sc->txq_entries,
1414 M_SFXGE, M_ZERO | M_WAITOK);
1416 /* Allocate and initialise mbuf DMA mapping array. */
1417 txq->stmp = malloc(sizeof(struct sfxge_tx_mapping) * sc->txq_entries,
1418 M_SFXGE, M_ZERO | M_WAITOK);
1419 for (nmaps = 0; nmaps < sc->txq_entries; nmaps++) {
1420 rc = bus_dmamap_create(txq->packet_dma_tag, 0,
1421 &txq->stmp[nmaps].map);
1426 snprintf(name, sizeof(name), "%u", txq_index);
1427 txq_node = SYSCTL_ADD_NODE(
1428 device_get_sysctl_ctx(sc->dev),
1429 SYSCTL_CHILDREN(sc->txqs_node),
1430 OID_AUTO, name, CTLFLAG_RD, NULL, "");
1431 if (txq_node == NULL) {
1436 if (type == SFXGE_TXQ_IP_TCP_UDP_CKSUM &&
1437 (rc = tso_init(txq)) != 0)
1440 #ifdef SFXGE_HAVE_MQ
1441 if (sfxge_tx_dpl_get_max <= 0) {
1442 log(LOG_ERR, "%s=%d must be greater than 0",
1443 SFXGE_PARAM_TX_DPL_GET_MAX, sfxge_tx_dpl_get_max);
1445 goto fail_tx_dpl_get_max;
1447 if (sfxge_tx_dpl_get_non_tcp_max <= 0) {
1448 log(LOG_ERR, "%s=%d must be greater than 0",
1449 SFXGE_PARAM_TX_DPL_GET_NON_TCP_MAX,
1450 sfxge_tx_dpl_get_non_tcp_max);
1452 goto fail_tx_dpl_get_max;
1454 if (sfxge_tx_dpl_put_max < 0) {
1455 log(LOG_ERR, "%s=%d must be greater or equal to 0",
1456 SFXGE_PARAM_TX_DPL_PUT_MAX, sfxge_tx_dpl_put_max);
1458 goto fail_tx_dpl_put_max;
1461 /* Initialize the deferred packet list. */
1463 stdp->std_put_max = sfxge_tx_dpl_put_max;
1464 stdp->std_get_max = sfxge_tx_dpl_get_max;
1465 stdp->std_get_non_tcp_max = sfxge_tx_dpl_get_non_tcp_max;
1466 stdp->std_getp = &stdp->std_get;
1468 SFXGE_TXQ_LOCK_INIT(txq, device_get_nameunit(sc->dev), txq_index);
1470 SYSCTL_ADD_UINT(device_get_sysctl_ctx(sc->dev),
1471 SYSCTL_CHILDREN(txq_node), OID_AUTO,
1472 "dpl_get_count", CTLFLAG_RD | CTLFLAG_STATS,
1473 &stdp->std_get_count, 0, "");
1474 SYSCTL_ADD_UINT(device_get_sysctl_ctx(sc->dev),
1475 SYSCTL_CHILDREN(txq_node), OID_AUTO,
1476 "dpl_get_non_tcp_count", CTLFLAG_RD | CTLFLAG_STATS,
1477 &stdp->std_get_non_tcp_count, 0, "");
1478 SYSCTL_ADD_UINT(device_get_sysctl_ctx(sc->dev),
1479 SYSCTL_CHILDREN(txq_node), OID_AUTO,
1480 "dpl_get_hiwat", CTLFLAG_RD | CTLFLAG_STATS,
1481 &stdp->std_get_hiwat, 0, "");
1485 txq->evq_index = evq_index;
1486 txq->txq_index = txq_index;
1487 txq->init_state = SFXGE_TXQ_INITIALIZED;
1491 fail_tx_dpl_put_max:
1492 fail_tx_dpl_get_max:
1495 free(txq->pend_desc, M_SFXGE);
1497 while (nmaps-- != 0)
1498 bus_dmamap_destroy(txq->packet_dma_tag, txq->stmp[nmaps].map);
1499 free(txq->stmp, M_SFXGE);
1500 bus_dma_tag_destroy(txq->packet_dma_tag);
1503 sfxge_dma_free(esmp);
1508 static const struct {
1511 } sfxge_tx_stats[] = {
1512 #define SFXGE_TX_STAT(name, member) \
1513 { #name, offsetof(struct sfxge_txq, member) }
1514 SFXGE_TX_STAT(tso_bursts, tso_bursts),
1515 SFXGE_TX_STAT(tso_packets, tso_packets),
1516 SFXGE_TX_STAT(tso_long_headers, tso_long_headers),
1517 SFXGE_TX_STAT(tso_pdrop_too_many, tso_pdrop_too_many),
1518 SFXGE_TX_STAT(tso_pdrop_no_rsrc, tso_pdrop_no_rsrc),
1519 SFXGE_TX_STAT(tx_collapses, collapses),
1520 SFXGE_TX_STAT(tx_drops, drops),
1521 SFXGE_TX_STAT(tx_get_overflow, get_overflow),
1522 SFXGE_TX_STAT(tx_get_non_tcp_overflow, get_non_tcp_overflow),
1523 SFXGE_TX_STAT(tx_put_overflow, put_overflow),
1524 SFXGE_TX_STAT(tx_netdown_drops, netdown_drops),
1528 sfxge_tx_stat_handler(SYSCTL_HANDLER_ARGS)
1530 struct sfxge_softc *sc = arg1;
1531 unsigned int id = arg2;
1535 /* Sum across all TX queues */
1537 for (index = 0; index < sc->txq_count; index++)
1538 sum += *(unsigned long *)((caddr_t)sc->txq[index] +
1539 sfxge_tx_stats[id].offset);
1541 return (SYSCTL_OUT(req, &sum, sizeof(sum)));
1545 sfxge_tx_stat_init(struct sfxge_softc *sc)
1547 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev);
1548 struct sysctl_oid_list *stat_list;
1551 stat_list = SYSCTL_CHILDREN(sc->stats_node);
1553 for (id = 0; id < nitems(sfxge_tx_stats); id++) {
1556 OID_AUTO, sfxge_tx_stats[id].name,
1557 CTLTYPE_ULONG|CTLFLAG_RD,
1558 sc, id, sfxge_tx_stat_handler, "LU",
1564 sfxge_tx_fini(struct sfxge_softc *sc)
1568 index = sc->txq_count;
1569 while (--index >= 0)
1570 sfxge_tx_qfini(sc, index);
1577 sfxge_tx_init(struct sfxge_softc *sc)
1579 struct sfxge_intr *intr;
1585 KASSERT(intr->state == SFXGE_INTR_INITIALIZED,
1586 ("intr->state != SFXGE_INTR_INITIALIZED"));
1588 #ifdef SFXGE_HAVE_MQ
1589 sc->txq_count = SFXGE_TXQ_NTYPES - 1 + sc->intr.n_alloc;
1591 sc->txq_count = SFXGE_TXQ_NTYPES;
1594 sc->txqs_node = SYSCTL_ADD_NODE(
1595 device_get_sysctl_ctx(sc->dev),
1596 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)),
1597 OID_AUTO, "txq", CTLFLAG_RD, NULL, "Tx queues");
1598 if (sc->txqs_node == NULL) {
1603 /* Initialize the transmit queues */
1604 if ((rc = sfxge_tx_qinit(sc, SFXGE_TXQ_NON_CKSUM,
1605 SFXGE_TXQ_NON_CKSUM, 0)) != 0)
1608 if ((rc = sfxge_tx_qinit(sc, SFXGE_TXQ_IP_CKSUM,
1609 SFXGE_TXQ_IP_CKSUM, 0)) != 0)
1613 index < sc->txq_count - SFXGE_TXQ_NTYPES + 1;
1615 if ((rc = sfxge_tx_qinit(sc, SFXGE_TXQ_NTYPES - 1 + index,
1616 SFXGE_TXQ_IP_TCP_UDP_CKSUM, index)) != 0)
1620 sfxge_tx_stat_init(sc);
1625 while (--index >= 0)
1626 sfxge_tx_qfini(sc, SFXGE_TXQ_IP_TCP_UDP_CKSUM + index);
1628 sfxge_tx_qfini(sc, SFXGE_TXQ_IP_CKSUM);
1631 sfxge_tx_qfini(sc, SFXGE_TXQ_NON_CKSUM);