2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012 Chelsio Communications, Inc.
6 * Written by: Navdeep Parhar <np@FreeBSD.org>
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 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
34 #include "opt_inet6.h"
35 #include "opt_ratelimit.h"
37 #include <sys/param.h>
38 #include <sys/types.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
43 #include <sys/limits.h>
44 #include <sys/module.h>
45 #include <sys/protosw.h>
46 #include <sys/domain.h>
47 #include <sys/refcount.h>
48 #include <sys/rmlock.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
51 #include <sys/taskqueue.h>
53 #include <net/if_var.h>
54 #include <net/if_types.h>
55 #include <net/if_vlan_var.h>
56 #include <netinet/in.h>
57 #include <netinet/in_pcb.h>
58 #include <netinet/in_var.h>
59 #include <netinet/ip.h>
60 #include <netinet/ip6.h>
61 #include <netinet6/scope6_var.h>
63 #include <netinet/tcp_fsm.h>
64 #include <netinet/tcp_timer.h>
65 #include <netinet/tcp_var.h>
66 #include <netinet/toecore.h>
69 #include "common/common.h"
70 #include "common/t4_msg.h"
71 #include "common/t4_regs.h"
72 #include "common/t4_regs_values.h"
73 #include "common/t4_tcb.h"
75 #include "tom/t4_tom_l2t.h"
76 #include "tom/t4_tom.h"
77 #include "tom/t4_tls.h"
79 static struct protosw toe_protosw;
80 static struct pr_usrreqs toe_usrreqs;
82 static struct protosw toe6_protosw;
83 static struct pr_usrreqs toe6_usrreqs;
86 static int t4_tom_mod_load(void);
87 static int t4_tom_mod_unload(void);
88 static int t4_tom_modevent(module_t, int, void *);
90 /* ULD ops and helpers */
91 static int t4_tom_activate(struct adapter *);
92 static int t4_tom_deactivate(struct adapter *);
94 static struct uld_info tom_uld_info = {
96 .activate = t4_tom_activate,
97 .deactivate = t4_tom_deactivate,
100 static void release_offload_resources(struct toepcb *);
101 static int alloc_tid_tabs(struct tid_info *);
102 static void free_tid_tabs(struct tid_info *);
103 static void free_tom_data(struct adapter *, struct tom_data *);
104 static void reclaim_wr_resources(void *, int);
107 alloc_toepcb(struct vi_info *vi, int txqid, int rxqid, int flags)
109 struct port_info *pi = vi->pi;
110 struct adapter *sc = pi->adapter;
112 int tx_credits, txsd_total, len;
115 * The firmware counts tx work request credits in units of 16 bytes
116 * each. Reserve room for an ABORT_REQ so the driver never has to worry
117 * about tx credits if it wants to abort a connection.
119 tx_credits = sc->params.ofldq_wr_cred;
120 tx_credits -= howmany(sizeof(struct cpl_abort_req), 16);
123 * Shortest possible tx work request is a fw_ofld_tx_data_wr + 1 byte
124 * immediate payload, and firmware counts tx work request credits in
125 * units of 16 byte. Calculate the maximum work requests possible.
127 txsd_total = tx_credits /
128 howmany(sizeof(struct fw_ofld_tx_data_wr) + 1, 16);
130 KASSERT(txqid >= vi->first_ofld_txq &&
131 txqid < vi->first_ofld_txq + vi->nofldtxq,
132 ("%s: txqid %d for vi %p (first %d, n %d)", __func__, txqid, vi,
133 vi->first_ofld_txq, vi->nofldtxq));
135 KASSERT(rxqid >= vi->first_ofld_rxq &&
136 rxqid < vi->first_ofld_rxq + vi->nofldrxq,
137 ("%s: rxqid %d for vi %p (first %d, n %d)", __func__, rxqid, vi,
138 vi->first_ofld_rxq, vi->nofldrxq));
140 len = offsetof(struct toepcb, txsd) +
141 txsd_total * sizeof(struct ofld_tx_sdesc);
143 toep = malloc(len, M_CXGBE, M_ZERO | flags);
147 refcount_init(&toep->refcount, 1);
148 toep->td = sc->tom_softc;
151 toep->tx_total = tx_credits;
152 toep->tx_credits = tx_credits;
153 toep->ofld_txq = &sc->sge.ofld_txq[txqid];
154 toep->ofld_rxq = &sc->sge.ofld_rxq[rxqid];
155 toep->ctrlq = &sc->sge.ctrlq[pi->port_id];
156 mbufq_init(&toep->ulp_pduq, INT_MAX);
157 mbufq_init(&toep->ulp_pdu_reclaimq, INT_MAX);
158 toep->txsd_total = txsd_total;
159 toep->txsd_avail = txsd_total;
162 aiotx_init_toep(toep);
168 hold_toepcb(struct toepcb *toep)
171 refcount_acquire(&toep->refcount);
176 free_toepcb(struct toepcb *toep)
179 if (refcount_release(&toep->refcount) == 0)
182 KASSERT(!(toep->flags & TPF_ATTACHED),
183 ("%s: attached to an inpcb", __func__));
184 KASSERT(!(toep->flags & TPF_CPL_PENDING),
185 ("%s: CPL pending", __func__));
187 if (toep->ulp_mode == ULP_MODE_TCPDDP)
188 ddp_uninit_toep(toep);
189 tls_uninit_toep(toep);
194 * Set up the socket for TCP offload.
197 offload_socket(struct socket *so, struct toepcb *toep)
199 struct tom_data *td = toep->td;
200 struct inpcb *inp = sotoinpcb(so);
201 struct tcpcb *tp = intotcpcb(inp);
204 INP_WLOCK_ASSERT(inp);
209 sb->sb_flags |= SB_NOCOALESCE;
213 sb->sb_flags |= SB_NOCOALESCE;
214 if (inp->inp_vflag & INP_IPV6)
215 so->so_proto = &toe6_protosw;
217 so->so_proto = &toe_protosw;
223 tp->t_flags |= TF_TOE;
225 /* Install an extra hold on inp */
227 toep->flags |= TPF_ATTACHED;
230 /* Add the TOE PCB to the active list */
231 mtx_lock(&td->toep_list_lock);
232 TAILQ_INSERT_HEAD(&td->toep_list, toep, link);
233 mtx_unlock(&td->toep_list_lock);
236 /* This is _not_ the normal way to "unoffload" a socket. */
238 undo_offload_socket(struct socket *so)
240 struct inpcb *inp = sotoinpcb(so);
241 struct tcpcb *tp = intotcpcb(inp);
242 struct toepcb *toep = tp->t_toe;
243 struct tom_data *td = toep->td;
246 INP_WLOCK_ASSERT(inp);
250 sb->sb_flags &= ~SB_NOCOALESCE;
254 sb->sb_flags &= ~SB_NOCOALESCE;
259 tp->t_flags &= ~TF_TOE;
262 toep->flags &= ~TPF_ATTACHED;
263 if (in_pcbrele_wlocked(inp))
264 panic("%s: inp freed.", __func__);
266 mtx_lock(&td->toep_list_lock);
267 TAILQ_REMOVE(&td->toep_list, toep, link);
268 mtx_unlock(&td->toep_list_lock);
272 release_offload_resources(struct toepcb *toep)
274 struct tom_data *td = toep->td;
275 struct adapter *sc = td_adapter(td);
278 KASSERT(!(toep->flags & TPF_CPL_PENDING),
279 ("%s: %p has CPL pending.", __func__, toep));
280 KASSERT(!(toep->flags & TPF_ATTACHED),
281 ("%s: %p is still attached.", __func__, toep));
283 CTR5(KTR_CXGBE, "%s: toep %p (tid %d, l2te %p, ce %p)",
284 __func__, toep, tid, toep->l2te, toep->ce);
287 * These queues should have been emptied at approximately the same time
288 * that a normal connection's socket's so_snd would have been purged or
289 * drained. Do _not_ clean up here.
291 MPASS(mbufq_len(&toep->ulp_pduq) == 0);
292 MPASS(mbufq_len(&toep->ulp_pdu_reclaimq) == 0);
294 if (toep->ulp_mode == ULP_MODE_TCPDDP)
295 ddp_assert_empty(toep);
297 MPASS(TAILQ_EMPTY(&toep->aiotx_jobq));
300 t4_l2t_release(toep->l2te);
303 remove_tid(sc, tid, toep->ce ? 2 : 1);
304 release_tid(sc, tid, toep->ctrlq);
308 t4_release_lip(sc, toep->ce);
310 if (toep->tc_idx != -1)
311 t4_release_cl_rl(sc, toep->vi->pi->port_id, toep->tc_idx);
313 mtx_lock(&td->toep_list_lock);
314 TAILQ_REMOVE(&td->toep_list, toep, link);
315 mtx_unlock(&td->toep_list_lock);
321 * The kernel is done with the TCP PCB and this is our opportunity to unhook the
322 * toepcb hanging off of it. If the TOE driver is also done with the toepcb (no
323 * pending CPL) then it is time to release all resources tied to the toepcb.
325 * Also gets called when an offloaded active open fails and the TOM wants the
326 * kernel to take the TCP PCB back.
329 t4_pcb_detach(struct toedev *tod __unused, struct tcpcb *tp)
331 #if defined(KTR) || defined(INVARIANTS)
332 struct inpcb *inp = tp->t_inpcb;
334 struct toepcb *toep = tp->t_toe;
336 INP_WLOCK_ASSERT(inp);
338 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
339 KASSERT(toep->flags & TPF_ATTACHED,
340 ("%s: not attached", __func__));
343 if (tp->t_state == TCPS_SYN_SENT) {
344 CTR6(KTR_CXGBE, "%s: atid %d, toep %p (0x%x), inp %p (0x%x)",
345 __func__, toep->tid, toep, toep->flags, inp,
349 "t4_pcb_detach: tid %d (%s), toep %p (0x%x), inp %p (0x%x)",
350 toep->tid, tcpstates[tp->t_state], toep, toep->flags, inp,
356 tp->t_flags &= ~TF_TOE;
357 toep->flags &= ~TPF_ATTACHED;
359 if (!(toep->flags & TPF_CPL_PENDING))
360 release_offload_resources(toep);
364 * setsockopt handler.
367 t4_ctloutput(struct toedev *tod, struct tcpcb *tp, int dir, int name)
369 struct adapter *sc = tod->tod_softc;
370 struct toepcb *toep = tp->t_toe;
375 CTR4(KTR_CXGBE, "%s: tp %p, dir %u, name %u", __func__, tp, dir, name);
379 if (tp->t_state != TCPS_ESTABLISHED)
381 t4_set_tcb_field(sc, toep->ctrlq, toep, W_TCB_T_FLAGS,
382 V_TF_NAGLE(1), V_TF_NAGLE(tp->t_flags & TF_NODELAY ? 0 : 1),
390 static inline uint64_t
391 get_tcb_tflags(const uint64_t *tcb)
394 return ((be64toh(tcb[14]) << 32) | (be64toh(tcb[15]) >> 32));
397 static inline uint32_t
398 get_tcb_field(const uint64_t *tcb, u_int word, uint32_t mask, u_int shift)
400 #define LAST_WORD ((TCB_SIZE / 4) - 1)
405 MPASS(word <= LAST_WORD);
408 flit_idx = (LAST_WORD - word) / 2;
411 t1 = be64toh(tcb[flit_idx]) >> shift;
413 if (fls(mask) > 64 - shift) {
415 * Will spill over into the next logical flit, which is the flit
416 * before this one. The flit_idx before this one must be valid.
419 t2 = be64toh(tcb[flit_idx - 1]) << (64 - shift);
421 return ((t2 | t1) & mask);
424 #define GET_TCB_FIELD(tcb, F) \
425 get_tcb_field(tcb, W_TCB_##F, M_TCB_##F, S_TCB_##F)
428 * Issues a CPL_GET_TCB to read the entire TCB for the tid.
431 send_get_tcb(struct adapter *sc, u_int tid)
433 struct cpl_get_tcb *cpl;
434 struct wrq_cookie cookie;
436 MPASS(tid < sc->tids.ntids);
438 cpl = start_wrq_wr(&sc->sge.ctrlq[0], howmany(sizeof(*cpl), 16),
440 if (__predict_false(cpl == NULL))
442 bzero(cpl, sizeof(*cpl));
443 INIT_TP_WR(cpl, tid);
444 OPCODE_TID(cpl) = htobe32(MK_OPCODE_TID(CPL_GET_TCB, tid));
445 cpl->reply_ctrl = htobe16(V_REPLY_CHAN(0) |
446 V_QUEUENO(sc->sge.ofld_rxq[0].iq.cntxt_id));
448 commit_wrq_wr(&sc->sge.ctrlq[0], cpl, &cookie);
453 static struct tcb_histent *
454 alloc_tcb_histent(struct adapter *sc, u_int tid, int flags)
456 struct tcb_histent *te;
458 MPASS(flags == M_NOWAIT || flags == M_WAITOK);
460 te = malloc(sizeof(*te), M_CXGBE, M_ZERO | flags);
463 mtx_init(&te->te_lock, "TCB entry", NULL, MTX_DEF);
464 callout_init_mtx(&te->te_callout, &te->te_lock, 0);
472 free_tcb_histent(struct tcb_histent *te)
475 mtx_destroy(&te->te_lock);
480 * Start tracking the tid in the TCB history.
483 add_tid_to_history(struct adapter *sc, u_int tid)
485 struct tcb_histent *te = NULL;
486 struct tom_data *td = sc->tom_softc;
489 MPASS(tid < sc->tids.ntids);
491 if (td->tcb_history == NULL)
494 rw_wlock(&td->tcb_history_lock);
495 if (td->tcb_history[tid] != NULL) {
499 te = alloc_tcb_histent(sc, tid, M_NOWAIT);
504 mtx_lock(&te->te_lock);
505 rc = send_get_tcb(sc, tid);
507 te->te_flags |= TE_RPL_PENDING;
508 td->tcb_history[tid] = te;
512 mtx_unlock(&te->te_lock);
514 rw_wunlock(&td->tcb_history_lock);
519 remove_tcb_histent(struct tcb_histent *te)
521 struct adapter *sc = te->te_adapter;
522 struct tom_data *td = sc->tom_softc;
524 rw_assert(&td->tcb_history_lock, RA_WLOCKED);
525 mtx_assert(&te->te_lock, MA_OWNED);
526 MPASS(td->tcb_history[te->te_tid] == te);
528 td->tcb_history[te->te_tid] = NULL;
529 free_tcb_histent(te);
530 rw_wunlock(&td->tcb_history_lock);
533 static inline struct tcb_histent *
534 lookup_tcb_histent(struct adapter *sc, u_int tid, bool addrem)
536 struct tcb_histent *te;
537 struct tom_data *td = sc->tom_softc;
539 MPASS(tid < sc->tids.ntids);
541 if (td->tcb_history == NULL)
545 rw_wlock(&td->tcb_history_lock);
547 rw_rlock(&td->tcb_history_lock);
548 te = td->tcb_history[tid];
550 mtx_lock(&te->te_lock);
551 return (te); /* with both locks held */
554 rw_wunlock(&td->tcb_history_lock);
556 rw_runlock(&td->tcb_history_lock);
562 release_tcb_histent(struct tcb_histent *te)
564 struct adapter *sc = te->te_adapter;
565 struct tom_data *td = sc->tom_softc;
567 mtx_assert(&te->te_lock, MA_OWNED);
568 mtx_unlock(&te->te_lock);
569 rw_assert(&td->tcb_history_lock, RA_RLOCKED);
570 rw_runlock(&td->tcb_history_lock);
574 request_tcb(void *arg)
576 struct tcb_histent *te = arg;
578 mtx_assert(&te->te_lock, MA_OWNED);
580 /* Noone else is supposed to update the histent. */
581 MPASS(!(te->te_flags & TE_RPL_PENDING));
582 if (send_get_tcb(te->te_adapter, te->te_tid) == 0)
583 te->te_flags |= TE_RPL_PENDING;
585 callout_schedule(&te->te_callout, hz / 100);
589 update_tcb_histent(struct tcb_histent *te, const uint64_t *tcb)
591 struct tom_data *td = te->te_adapter->tom_softc;
592 uint64_t tflags = get_tcb_tflags(tcb);
595 if (GET_TCB_FIELD(tcb, SND_MAX_RAW) != GET_TCB_FIELD(tcb, SND_UNA_RAW)) {
596 if (GET_TCB_FIELD(tcb, T_RXTSHIFT) != 0)
598 if (GET_TCB_FIELD(tcb, T_DUPACKS) != 0)
599 sample |= TS_DUPACKS;
600 if (GET_TCB_FIELD(tcb, T_DUPACKS) >= td->dupack_threshold)
601 sample |= TS_FASTREXMT;
604 if (GET_TCB_FIELD(tcb, SND_MAX_RAW) != 0) {
607 sample |= TS_SND_BACKLOGGED; /* for whatever reason. */
609 snd_wnd = GET_TCB_FIELD(tcb, RCV_ADV);
610 if (tflags & V_TF_RECV_SCALE(1))
611 snd_wnd <<= GET_TCB_FIELD(tcb, RCV_SCALE);
612 if (GET_TCB_FIELD(tcb, SND_CWND) < snd_wnd)
613 sample |= TS_CWND_LIMITED; /* maybe due to CWND */
616 if (tflags & V_TF_CCTRL_ECN(1)) {
619 * CE marker on incoming IP hdr, echoing ECE back in the TCP
620 * hdr. Indicates congestion somewhere on the way from the peer
623 if (tflags & V_TF_CCTRL_ECE(1))
624 sample |= TS_ECN_ECE;
627 * ECE seen and CWR sent (or about to be sent). Might indicate
628 * congestion on the way to the peer. This node is reducing its
629 * congestion window in response.
631 if (tflags & (V_TF_CCTRL_CWR(1) | V_TF_CCTRL_RFR(1)))
632 sample |= TS_ECN_CWR;
635 te->te_sample[te->te_pidx] = sample;
636 if (++te->te_pidx == nitems(te->te_sample))
638 memcpy(te->te_tcb, tcb, TCB_SIZE);
639 te->te_flags |= TE_ACTIVE;
643 do_get_tcb_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
645 struct adapter *sc = iq->adapter;
646 const struct cpl_get_tcb_rpl *cpl = mtod(m, const void *);
647 const uint64_t *tcb = (const uint64_t *)(const void *)(cpl + 1);
648 struct tcb_histent *te;
649 const u_int tid = GET_TID(cpl);
652 remove = GET_TCB_FIELD(tcb, T_STATE) == TCPS_CLOSED;
653 te = lookup_tcb_histent(sc, tid, remove);
655 /* Not in the history. Who issued the GET_TCB for this? */
656 device_printf(sc->dev, "tcb %u: flags 0x%016jx, state %u, "
657 "srtt %u, sscale %u, rscale %u, cookie 0x%x\n", tid,
658 (uintmax_t)get_tcb_tflags(tcb), GET_TCB_FIELD(tcb, T_STATE),
659 GET_TCB_FIELD(tcb, T_SRTT), GET_TCB_FIELD(tcb, SND_SCALE),
660 GET_TCB_FIELD(tcb, RCV_SCALE), cpl->cookie);
664 MPASS(te->te_flags & TE_RPL_PENDING);
665 te->te_flags &= ~TE_RPL_PENDING;
667 remove_tcb_histent(te);
669 update_tcb_histent(te, tcb);
670 callout_reset(&te->te_callout, hz / 10, request_tcb, te);
671 release_tcb_histent(te);
679 fill_tcp_info_from_tcb(struct adapter *sc, uint64_t *tcb, struct tcp_info *ti)
683 ti->tcpi_state = GET_TCB_FIELD(tcb, T_STATE);
685 v = GET_TCB_FIELD(tcb, T_SRTT);
686 ti->tcpi_rtt = tcp_ticks_to_us(sc, v);
688 v = GET_TCB_FIELD(tcb, T_RTTVAR);
689 ti->tcpi_rttvar = tcp_ticks_to_us(sc, v);
691 ti->tcpi_snd_ssthresh = GET_TCB_FIELD(tcb, SND_SSTHRESH);
692 ti->tcpi_snd_cwnd = GET_TCB_FIELD(tcb, SND_CWND);
693 ti->tcpi_rcv_nxt = GET_TCB_FIELD(tcb, RCV_NXT);
695 v = GET_TCB_FIELD(tcb, TX_MAX);
696 ti->tcpi_snd_nxt = v - GET_TCB_FIELD(tcb, SND_NXT_RAW);
698 /* Receive window being advertised by us. */
699 ti->tcpi_rcv_wscale = GET_TCB_FIELD(tcb, SND_SCALE); /* Yes, SND. */
700 ti->tcpi_rcv_space = GET_TCB_FIELD(tcb, RCV_WND);
703 ti->tcpi_snd_wscale = GET_TCB_FIELD(tcb, RCV_SCALE); /* Yes, RCV. */
704 ti->tcpi_snd_wnd = GET_TCB_FIELD(tcb, RCV_ADV);
705 if (get_tcb_tflags(tcb) & V_TF_RECV_SCALE(1))
706 ti->tcpi_snd_wnd <<= ti->tcpi_snd_wscale;
708 ti->tcpi_snd_wscale = 0;
713 fill_tcp_info_from_history(struct adapter *sc, struct tcb_histent *te,
717 fill_tcp_info_from_tcb(sc, te->te_tcb, ti);
721 * Reads the TCB for the given tid using a memory window and copies it to 'buf'
722 * in the same format as CPL_GET_TCB_RPL.
725 read_tcb_using_memwin(struct adapter *sc, u_int tid, uint64_t *buf)
731 MPASS(tid < sc->tids.ntids);
733 addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE) + tid * TCB_SIZE;
734 rc = read_via_memwin(sc, 2, addr, (uint32_t *)buf, TCB_SIZE);
739 for (i = 0, j = TCB_SIZE - 16; i < j; i += 16, j -= 16) {
740 for (k = 0; k < 16; k++) {
742 tcb[i + k] = tcb[j + k];
749 fill_tcp_info(struct adapter *sc, u_int tid, struct tcp_info *ti)
751 uint64_t tcb[TCB_SIZE / sizeof(uint64_t)];
752 struct tcb_histent *te;
754 ti->tcpi_toe_tid = tid;
755 te = lookup_tcb_histent(sc, tid, false);
757 fill_tcp_info_from_history(sc, te, ti);
758 release_tcb_histent(te);
760 if (!(sc->debug_flags & DF_DISABLE_TCB_CACHE)) {
761 /* XXX: tell firmware to flush TCB cache. */
763 read_tcb_using_memwin(sc, tid, tcb);
764 fill_tcp_info_from_tcb(sc, tcb, ti);
769 * Called by the kernel to allow the TOE driver to "refine" values filled up in
770 * the tcp_info for an offloaded connection.
773 t4_tcp_info(struct toedev *tod, struct tcpcb *tp, struct tcp_info *ti)
775 struct adapter *sc = tod->tod_softc;
776 struct toepcb *toep = tp->t_toe;
778 INP_WLOCK_ASSERT(tp->t_inpcb);
781 fill_tcp_info(sc, toep->tid, ti);
785 * The TOE driver will not receive any more CPLs for the tid associated with the
786 * toepcb; release the hold on the inpcb.
789 final_cpl_received(struct toepcb *toep)
791 struct inpcb *inp = toep->inp;
793 KASSERT(inp != NULL, ("%s: inp is NULL", __func__));
794 INP_WLOCK_ASSERT(inp);
795 KASSERT(toep->flags & TPF_CPL_PENDING,
796 ("%s: CPL not pending already?", __func__));
798 CTR6(KTR_CXGBE, "%s: tid %d, toep %p (0x%x), inp %p (0x%x)",
799 __func__, toep->tid, toep, toep->flags, inp, inp->inp_flags);
801 if (toep->ulp_mode == ULP_MODE_TCPDDP)
802 release_ddp_resources(toep);
804 toep->flags &= ~TPF_CPL_PENDING;
805 mbufq_drain(&toep->ulp_pdu_reclaimq);
807 if (!(toep->flags & TPF_ATTACHED))
808 release_offload_resources(toep);
810 if (!in_pcbrele_wlocked(inp))
815 insert_tid(struct adapter *sc, int tid, void *ctx, int ntids)
817 struct tid_info *t = &sc->tids;
819 MPASS(tid >= t->tid_base);
820 MPASS(tid - t->tid_base < t->ntids);
822 t->tid_tab[tid - t->tid_base] = ctx;
823 atomic_add_int(&t->tids_in_use, ntids);
827 lookup_tid(struct adapter *sc, int tid)
829 struct tid_info *t = &sc->tids;
831 return (t->tid_tab[tid - t->tid_base]);
835 update_tid(struct adapter *sc, int tid, void *ctx)
837 struct tid_info *t = &sc->tids;
839 t->tid_tab[tid - t->tid_base] = ctx;
843 remove_tid(struct adapter *sc, int tid, int ntids)
845 struct tid_info *t = &sc->tids;
847 t->tid_tab[tid - t->tid_base] = NULL;
848 atomic_subtract_int(&t->tids_in_use, ntids);
852 * What mtu_idx to use, given a 4-tuple. Note that both s->mss and tcp_mssopt
853 * have the MSS that we should advertise in our SYN. Advertised MSS doesn't
854 * account for any TCP options so the effective MSS (only payload, no headers or
855 * options) could be different.
858 find_best_mtu_idx(struct adapter *sc, struct in_conninfo *inc,
859 struct offload_settings *s)
861 unsigned short *mtus = &sc->params.mtus[0];
866 mss = s->mss > 0 ? s->mss : tcp_mssopt(inc);
867 if (inc->inc_flags & INC_ISIPV6)
868 mtu = mss + sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
870 mtu = mss + sizeof(struct ip) + sizeof(struct tcphdr);
872 for (i = 0; i < NMTUS - 1 && mtus[i + 1] <= mtu; i++)
879 * Determine the receive window size for a socket.
882 select_rcv_wnd(struct socket *so)
886 SOCKBUF_LOCK_ASSERT(&so->so_rcv);
888 wnd = sbspace(&so->so_rcv);
889 if (wnd < MIN_RCV_WND)
892 return min(wnd, MAX_RCV_WND);
896 select_rcv_wscale(void)
899 unsigned long space = sb_max;
901 if (space > MAX_RCV_WND)
904 while (wscale < TCP_MAX_WINSHIFT && (TCP_MAXWIN << wscale) < space)
911 * socket so could be a listening socket too.
914 calc_opt0(struct socket *so, struct vi_info *vi, struct l2t_entry *e,
915 int mtu_idx, int rscale, int rx_credits, int ulp_mode,
916 struct offload_settings *s)
923 KASSERT(rx_credits <= M_RCV_BUFSIZ,
924 ("%s: rcv_bufsiz too high", __func__));
926 opt0 = F_TCAM_BYPASS | V_WND_SCALE(rscale) | V_MSS_IDX(mtu_idx) |
927 V_ULP_MODE(ulp_mode) | V_RCV_BUFSIZ(rx_credits) |
928 V_L2T_IDX(e->idx) | V_SMAC_SEL(vi->smt_idx) |
929 V_TX_CHAN(vi->pi->tx_chan);
931 keepalive = tcp_always_keepalive || so_options_get(so) & SO_KEEPALIVE;
932 opt0 |= V_KEEP_ALIVE(keepalive != 0);
935 struct inpcb *inp = sotoinpcb(so);
936 struct tcpcb *tp = intotcpcb(inp);
938 opt0 |= V_NAGLE((tp->t_flags & TF_NODELAY) == 0);
940 opt0 |= V_NAGLE(s->nagle != 0);
942 return htobe64(opt0);
946 select_ntuple(struct vi_info *vi, struct l2t_entry *e)
948 struct adapter *sc = vi->pi->adapter;
949 struct tp_params *tp = &sc->params.tp;
953 * Initialize each of the fields which we care about which are present
954 * in the Compressed Filter Tuple.
956 if (tp->vlan_shift >= 0 && EVL_VLANOFTAG(e->vlan) != CPL_L2T_VLAN_NONE)
957 ntuple |= (uint64_t)(F_FT_VLAN_VLD | e->vlan) << tp->vlan_shift;
959 if (tp->port_shift >= 0)
960 ntuple |= (uint64_t)e->lport << tp->port_shift;
962 if (tp->protocol_shift >= 0)
963 ntuple |= (uint64_t)IPPROTO_TCP << tp->protocol_shift;
965 if (tp->vnic_shift >= 0 && tp->ingress_config & F_VNIC) {
966 ntuple |= (uint64_t)(V_FT_VNID_ID_VF(vi->vin) |
967 V_FT_VNID_ID_PF(sc->pf) | V_FT_VNID_ID_VLD(vi->vfvld)) <<
972 return (htobe32((uint32_t)ntuple));
974 return (htobe64(V_FILTER_TUPLE(ntuple)));
978 is_tls_sock(struct socket *so, struct adapter *sc)
980 struct inpcb *inp = sotoinpcb(so);
983 /* XXX: Eventually add a SO_WANT_TLS socket option perhaps? */
986 for (i = 0; i < sc->tt.num_tls_rx_ports; i++) {
987 if (inp->inp_lport == htons(sc->tt.tls_rx_ports[i]) ||
988 inp->inp_fport == htons(sc->tt.tls_rx_ports[i])) {
998 select_ulp_mode(struct socket *so, struct adapter *sc,
999 struct offload_settings *s)
1002 if (can_tls_offload(sc) &&
1003 (s->tls > 0 || (s->tls < 0 && is_tls_sock(so, sc))))
1004 return (ULP_MODE_TLS);
1005 else if (s->ddp > 0 ||
1006 (s->ddp < 0 && sc->tt.ddp && (so->so_options & SO_NO_DDP) == 0))
1007 return (ULP_MODE_TCPDDP);
1009 return (ULP_MODE_NONE);
1013 set_ulp_mode(struct toepcb *toep, int ulp_mode)
1016 CTR4(KTR_CXGBE, "%s: toep %p (tid %d) ulp_mode %d",
1017 __func__, toep, toep->tid, ulp_mode);
1018 toep->ulp_mode = ulp_mode;
1019 tls_init_toep(toep);
1020 if (toep->ulp_mode == ULP_MODE_TCPDDP)
1021 ddp_init_toep(toep);
1025 negative_advice(int status)
1028 return (status == CPL_ERR_RTX_NEG_ADVICE ||
1029 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1030 status == CPL_ERR_KEEPALV_NEG_ADVICE);
1034 alloc_tid_tab(struct tid_info *t, int flags)
1037 MPASS(t->ntids > 0);
1038 MPASS(t->tid_tab == NULL);
1040 t->tid_tab = malloc(t->ntids * sizeof(*t->tid_tab), M_CXGBE,
1042 if (t->tid_tab == NULL)
1044 atomic_store_rel_int(&t->tids_in_use, 0);
1050 free_tid_tab(struct tid_info *t)
1053 KASSERT(t->tids_in_use == 0,
1054 ("%s: %d tids still in use.", __func__, t->tids_in_use));
1056 free(t->tid_tab, M_CXGBE);
1061 alloc_stid_tab(struct tid_info *t, int flags)
1064 MPASS(t->nstids > 0);
1065 MPASS(t->stid_tab == NULL);
1067 t->stid_tab = malloc(t->nstids * sizeof(*t->stid_tab), M_CXGBE,
1069 if (t->stid_tab == NULL)
1071 mtx_init(&t->stid_lock, "stid lock", NULL, MTX_DEF);
1072 t->stids_in_use = 0;
1073 TAILQ_INIT(&t->stids);
1074 t->nstids_free_head = t->nstids;
1080 free_stid_tab(struct tid_info *t)
1083 KASSERT(t->stids_in_use == 0,
1084 ("%s: %d tids still in use.", __func__, t->stids_in_use));
1086 if (mtx_initialized(&t->stid_lock))
1087 mtx_destroy(&t->stid_lock);
1088 free(t->stid_tab, M_CXGBE);
1093 free_tid_tabs(struct tid_info *t)
1102 alloc_tid_tabs(struct tid_info *t)
1106 rc = alloc_tid_tab(t, M_NOWAIT);
1110 rc = alloc_atid_tab(t, M_NOWAIT);
1114 rc = alloc_stid_tab(t, M_NOWAIT);
1125 alloc_tcb_history(struct adapter *sc, struct tom_data *td)
1128 if (sc->tids.ntids == 0 || sc->tids.ntids > 1024)
1130 rw_init(&td->tcb_history_lock, "TCB history");
1131 td->tcb_history = malloc(sc->tids.ntids * sizeof(*td->tcb_history),
1132 M_CXGBE, M_ZERO | M_NOWAIT);
1133 td->dupack_threshold = G_DUPACKTHRESH(t4_read_reg(sc, A_TP_PARA_REG0));
1137 free_tcb_history(struct adapter *sc, struct tom_data *td)
1142 if (td->tcb_history != NULL) {
1143 for (i = 0; i < sc->tids.ntids; i++) {
1144 MPASS(td->tcb_history[i] == NULL);
1148 free(td->tcb_history, M_CXGBE);
1149 if (rw_initialized(&td->tcb_history_lock))
1150 rw_destroy(&td->tcb_history_lock);
1154 free_tom_data(struct adapter *sc, struct tom_data *td)
1157 ASSERT_SYNCHRONIZED_OP(sc);
1159 KASSERT(TAILQ_EMPTY(&td->toep_list),
1160 ("%s: TOE PCB list is not empty.", __func__));
1161 KASSERT(td->lctx_count == 0,
1162 ("%s: lctx hash table is not empty.", __func__));
1164 t4_free_ppod_region(&td->pr);
1166 if (td->listen_mask != 0)
1167 hashdestroy(td->listen_hash, M_CXGBE, td->listen_mask);
1169 if (mtx_initialized(&td->unsent_wr_lock))
1170 mtx_destroy(&td->unsent_wr_lock);
1171 if (mtx_initialized(&td->lctx_hash_lock))
1172 mtx_destroy(&td->lctx_hash_lock);
1173 if (mtx_initialized(&td->toep_list_lock))
1174 mtx_destroy(&td->toep_list_lock);
1176 free_tcb_history(sc, td);
1177 free_tid_tabs(&sc->tids);
1182 prepare_pkt(int open_type, uint16_t vtag, struct inpcb *inp, int *pktlen,
1189 max(sizeof(struct ether_header), sizeof(struct ether_vlan_header)) +
1190 max(sizeof(struct ip), sizeof(struct ip6_hdr)) +
1191 sizeof(struct tcphdr);
1193 MPASS(open_type == OPEN_TYPE_ACTIVE || open_type == OPEN_TYPE_LISTEN);
1195 pkt = malloc(maxlen, M_CXGBE, M_ZERO | M_NOWAIT);
1199 ipv6 = inp->inp_vflag & INP_IPV6;
1202 if (EVL_VLANOFTAG(vtag) == 0xfff) {
1203 struct ether_header *eh = (void *)pkt;
1206 eh->ether_type = htons(ETHERTYPE_IPV6);
1208 eh->ether_type = htons(ETHERTYPE_IP);
1212 struct ether_vlan_header *evh = (void *)pkt;
1214 evh->evl_encap_proto = htons(ETHERTYPE_VLAN);
1215 evh->evl_tag = htons(vtag);
1217 evh->evl_proto = htons(ETHERTYPE_IPV6);
1219 evh->evl_proto = htons(ETHERTYPE_IP);
1221 len += sizeof(*evh);
1225 struct ip6_hdr *ip6 = (void *)&pkt[len];
1227 ip6->ip6_vfc = IPV6_VERSION;
1228 ip6->ip6_plen = htons(sizeof(struct tcphdr));
1229 ip6->ip6_nxt = IPPROTO_TCP;
1230 if (open_type == OPEN_TYPE_ACTIVE) {
1231 ip6->ip6_src = inp->in6p_laddr;
1232 ip6->ip6_dst = inp->in6p_faddr;
1233 } else if (open_type == OPEN_TYPE_LISTEN) {
1234 ip6->ip6_src = inp->in6p_laddr;
1235 ip6->ip6_dst = ip6->ip6_src;
1238 len += sizeof(*ip6);
1240 struct ip *ip = (void *)&pkt[len];
1242 ip->ip_v = IPVERSION;
1243 ip->ip_hl = sizeof(*ip) >> 2;
1244 ip->ip_tos = inp->inp_ip_tos;
1245 ip->ip_len = htons(sizeof(struct ip) + sizeof(struct tcphdr));
1246 ip->ip_ttl = inp->inp_ip_ttl;
1247 ip->ip_p = IPPROTO_TCP;
1248 if (open_type == OPEN_TYPE_ACTIVE) {
1249 ip->ip_src = inp->inp_laddr;
1250 ip->ip_dst = inp->inp_faddr;
1251 } else if (open_type == OPEN_TYPE_LISTEN) {
1252 ip->ip_src = inp->inp_laddr;
1253 ip->ip_dst = ip->ip_src;
1259 th = (void *)&pkt[len];
1260 if (open_type == OPEN_TYPE_ACTIVE) {
1261 th->th_sport = inp->inp_lport; /* network byte order already */
1262 th->th_dport = inp->inp_fport; /* ditto */
1263 } else if (open_type == OPEN_TYPE_LISTEN) {
1264 th->th_sport = inp->inp_lport; /* network byte order already */
1265 th->th_dport = th->th_sport;
1269 *pktlen = *buflen = len;
1273 const struct offload_settings *
1274 lookup_offload_policy(struct adapter *sc, int open_type, struct mbuf *m,
1275 uint16_t vtag, struct inpcb *inp)
1277 const struct t4_offload_policy *op;
1279 struct offload_rule *r;
1280 int i, matched, pktlen, buflen;
1281 static const struct offload_settings allow_offloading_settings = {
1296 static const struct offload_settings disallow_offloading_settings = {
1298 /* rest is irrelevant when offload is off. */
1301 rw_assert(&sc->policy_lock, RA_LOCKED);
1304 * If there's no Connection Offloading Policy attached to the device
1305 * then we need to return a default static policy. If
1306 * "cop_managed_offloading" is true, then we need to disallow
1307 * offloading until a COP is attached to the device. Otherwise we
1308 * allow offloading ...
1312 if (sc->tt.cop_managed_offloading)
1313 return (&disallow_offloading_settings);
1315 return (&allow_offloading_settings);
1318 switch (open_type) {
1319 case OPEN_TYPE_ACTIVE:
1320 case OPEN_TYPE_LISTEN:
1321 pkt = prepare_pkt(open_type, vtag, inp, &pktlen, &buflen);
1323 case OPEN_TYPE_PASSIVE:
1325 pkt = mtod(m, char *);
1326 MPASS(*pkt == CPL_PASS_ACCEPT_REQ);
1327 pkt += sizeof(struct cpl_pass_accept_req);
1328 pktlen = m->m_pkthdr.len - sizeof(struct cpl_pass_accept_req);
1329 buflen = m->m_len - sizeof(struct cpl_pass_accept_req);
1333 return (&disallow_offloading_settings);
1336 if (pkt == NULL || pktlen == 0 || buflen == 0)
1337 return (&disallow_offloading_settings);
1341 for (i = 0; i < op->nrules; i++, r++) {
1342 if (r->open_type != open_type &&
1343 r->open_type != OPEN_TYPE_DONTCARE) {
1346 matched = bpf_filter(r->bpf_prog.bf_insns, pkt, pktlen, buflen);
1351 if (open_type == OPEN_TYPE_ACTIVE || open_type == OPEN_TYPE_LISTEN)
1354 return (matched ? &r->settings : &disallow_offloading_settings);
1358 reclaim_wr_resources(void *arg, int count)
1360 struct tom_data *td = arg;
1361 STAILQ_HEAD(, wrqe) twr_list = STAILQ_HEAD_INITIALIZER(twr_list);
1362 struct cpl_act_open_req *cpl;
1363 u_int opcode, atid, tid;
1365 struct adapter *sc = td_adapter(td);
1367 mtx_lock(&td->unsent_wr_lock);
1368 STAILQ_SWAP(&td->unsent_wr_list, &twr_list, wrqe);
1369 mtx_unlock(&td->unsent_wr_lock);
1371 while ((wr = STAILQ_FIRST(&twr_list)) != NULL) {
1372 STAILQ_REMOVE_HEAD(&twr_list, link);
1375 opcode = GET_OPCODE(cpl);
1378 case CPL_ACT_OPEN_REQ:
1379 case CPL_ACT_OPEN_REQ6:
1380 atid = G_TID_TID(be32toh(OPCODE_TID(cpl)));
1381 CTR2(KTR_CXGBE, "%s: atid %u ", __func__, atid);
1382 act_open_failure_cleanup(sc, atid, EHOSTUNREACH);
1385 case CPL_PASS_ACCEPT_RPL:
1387 CTR2(KTR_CXGBE, "%s: tid %u ", __func__, tid);
1388 synack_failure_cleanup(sc, tid);
1392 log(LOG_ERR, "%s: leaked work request %p, wr_len %d, "
1393 "opcode %x\n", __func__, wr, wr->wr_len, opcode);
1394 /* WR not freed here; go look at it with a debugger. */
1400 * Ground control to Major TOM
1401 * Commencing countdown, engines on
1404 t4_tom_activate(struct adapter *sc)
1406 struct tom_data *td;
1411 ASSERT_SYNCHRONIZED_OP(sc);
1413 /* per-adapter softc for TOM */
1414 td = malloc(sizeof(*td), M_CXGBE, M_ZERO | M_NOWAIT);
1418 /* List of TOE PCBs and associated lock */
1419 mtx_init(&td->toep_list_lock, "PCB list lock", NULL, MTX_DEF);
1420 TAILQ_INIT(&td->toep_list);
1422 /* Listen context */
1423 mtx_init(&td->lctx_hash_lock, "lctx hash lock", NULL, MTX_DEF);
1424 td->listen_hash = hashinit_flags(LISTEN_HASH_SIZE, M_CXGBE,
1425 &td->listen_mask, HASH_NOWAIT);
1427 /* List of WRs for which L2 resolution failed */
1428 mtx_init(&td->unsent_wr_lock, "Unsent WR list lock", NULL, MTX_DEF);
1429 STAILQ_INIT(&td->unsent_wr_list);
1430 TASK_INIT(&td->reclaim_wr_resources, 0, reclaim_wr_resources, td);
1433 rc = alloc_tid_tabs(&sc->tids);
1437 rc = t4_init_ppod_region(&td->pr, &sc->vres.ddp,
1438 t4_read_reg(sc, A_ULP_RX_TDDP_PSZ), "TDDP page pods");
1441 t4_set_reg_field(sc, A_ULP_RX_TDDP_TAGMASK,
1442 V_TDDPTAGMASK(M_TDDPTAGMASK), td->pr.pr_tag_mask);
1444 alloc_tcb_history(sc, td);
1449 tod->tod_softc = sc;
1450 tod->tod_connect = t4_connect;
1451 tod->tod_listen_start = t4_listen_start;
1452 tod->tod_listen_stop = t4_listen_stop;
1453 tod->tod_rcvd = t4_rcvd;
1454 tod->tod_output = t4_tod_output;
1455 tod->tod_send_rst = t4_send_rst;
1456 tod->tod_send_fin = t4_send_fin;
1457 tod->tod_pcb_detach = t4_pcb_detach;
1458 tod->tod_l2_update = t4_l2_update;
1459 tod->tod_syncache_added = t4_syncache_added;
1460 tod->tod_syncache_removed = t4_syncache_removed;
1461 tod->tod_syncache_respond = t4_syncache_respond;
1462 tod->tod_offload_socket = t4_offload_socket;
1463 tod->tod_ctloutput = t4_ctloutput;
1464 tod->tod_tcp_info = t4_tcp_info;
1466 for_each_port(sc, i) {
1467 for_each_vi(sc->port[i], v, vi) {
1468 TOEDEV(vi->ifp) = &td->tod;
1473 register_toedev(sc->tom_softc);
1477 free_tom_data(sc, td);
1482 t4_tom_deactivate(struct adapter *sc)
1485 struct tom_data *td = sc->tom_softc;
1487 ASSERT_SYNCHRONIZED_OP(sc);
1490 return (0); /* XXX. KASSERT? */
1492 if (sc->offload_map != 0)
1493 return (EBUSY); /* at least one port has IFCAP_TOE enabled */
1495 if (uld_active(sc, ULD_IWARP) || uld_active(sc, ULD_ISCSI))
1496 return (EBUSY); /* both iWARP and iSCSI rely on the TOE. */
1498 mtx_lock(&td->toep_list_lock);
1499 if (!TAILQ_EMPTY(&td->toep_list))
1501 mtx_unlock(&td->toep_list_lock);
1503 mtx_lock(&td->lctx_hash_lock);
1504 if (td->lctx_count > 0)
1506 mtx_unlock(&td->lctx_hash_lock);
1508 taskqueue_drain(taskqueue_thread, &td->reclaim_wr_resources);
1509 mtx_lock(&td->unsent_wr_lock);
1510 if (!STAILQ_EMPTY(&td->unsent_wr_list))
1512 mtx_unlock(&td->unsent_wr_lock);
1515 unregister_toedev(sc->tom_softc);
1516 free_tom_data(sc, td);
1517 sc->tom_softc = NULL;
1524 t4_aio_queue_tom(struct socket *so, struct kaiocb *job)
1526 struct tcpcb *tp = so_sototcpcb(so);
1527 struct toepcb *toep = tp->t_toe;
1530 if (toep->ulp_mode == ULP_MODE_TCPDDP) {
1531 error = t4_aio_queue_ddp(so, job);
1532 if (error != EOPNOTSUPP)
1536 return (t4_aio_queue_aiotx(so, job));
1540 t4_ctloutput_tom(struct socket *so, struct sockopt *sopt)
1543 if (sopt->sopt_level != IPPROTO_TCP)
1544 return (tcp_ctloutput(so, sopt));
1546 switch (sopt->sopt_name) {
1547 case TCP_TLSOM_SET_TLS_CONTEXT:
1548 case TCP_TLSOM_GET_TLS_TOM:
1549 case TCP_TLSOM_CLR_TLS_TOM:
1550 case TCP_TLSOM_CLR_QUIES:
1551 return (t4_ctloutput_tls(so, sopt));
1553 return (tcp_ctloutput(so, sopt));
1558 t4_tom_mod_load(void)
1560 struct protosw *tcp_protosw, *tcp6_protosw;
1563 t4_register_cpl_handler(CPL_GET_TCB_RPL, do_get_tcb_rpl);
1564 t4_register_shared_cpl_handler(CPL_L2T_WRITE_RPL, do_l2t_write_rpl2,
1566 t4_init_connect_cpl_handlers();
1567 t4_init_listen_cpl_handlers();
1568 t4_init_cpl_io_handlers();
1573 tcp_protosw = pffindproto(PF_INET, IPPROTO_TCP, SOCK_STREAM);
1574 if (tcp_protosw == NULL)
1575 return (ENOPROTOOPT);
1576 bcopy(tcp_protosw, &toe_protosw, sizeof(toe_protosw));
1577 bcopy(tcp_protosw->pr_usrreqs, &toe_usrreqs, sizeof(toe_usrreqs));
1578 toe_usrreqs.pru_aio_queue = t4_aio_queue_tom;
1579 toe_protosw.pr_ctloutput = t4_ctloutput_tom;
1580 toe_protosw.pr_usrreqs = &toe_usrreqs;
1582 tcp6_protosw = pffindproto(PF_INET6, IPPROTO_TCP, SOCK_STREAM);
1583 if (tcp6_protosw == NULL)
1584 return (ENOPROTOOPT);
1585 bcopy(tcp6_protosw, &toe6_protosw, sizeof(toe6_protosw));
1586 bcopy(tcp6_protosw->pr_usrreqs, &toe6_usrreqs, sizeof(toe6_usrreqs));
1587 toe6_usrreqs.pru_aio_queue = t4_aio_queue_tom;
1588 toe6_protosw.pr_ctloutput = t4_ctloutput_tom;
1589 toe6_protosw.pr_usrreqs = &toe6_usrreqs;
1591 return (t4_register_uld(&tom_uld_info));
1595 tom_uninit(struct adapter *sc, void *arg __unused)
1597 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4tomun"))
1600 /* Try to free resources (works only if no port has IFCAP_TOE) */
1601 if (uld_active(sc, ULD_TOM))
1602 t4_deactivate_uld(sc, ULD_TOM);
1604 end_synchronized_op(sc, 0);
1608 t4_tom_mod_unload(void)
1610 t4_iterate(tom_uninit, NULL);
1612 if (t4_unregister_uld(&tom_uld_info) == EBUSY)
1615 t4_tls_mod_unload();
1616 t4_ddp_mod_unload();
1618 t4_uninit_connect_cpl_handlers();
1619 t4_uninit_listen_cpl_handlers();
1620 t4_uninit_cpl_io_handlers();
1621 t4_register_shared_cpl_handler(CPL_L2T_WRITE_RPL, NULL, CPL_COOKIE_TOM);
1625 #endif /* TCP_OFFLOAD */
1628 t4_tom_modevent(module_t mod, int cmd, void *arg)
1635 rc = t4_tom_mod_load();
1639 rc = t4_tom_mod_unload();
1646 printf("t4_tom: compiled without TCP_OFFLOAD support.\n");
1652 static moduledata_t t4_tom_moddata= {
1658 MODULE_VERSION(t4_tom, 1);
1659 MODULE_DEPEND(t4_tom, toecore, 1, 1, 1);
1660 MODULE_DEPEND(t4_tom, t4nex, 1, 1, 1);
1661 DECLARE_MODULE(t4_tom, t4_tom_moddata, SI_SUB_EXEC, SI_ORDER_ANY);