2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012, 2015 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_kern_tls.h"
36 #include "opt_ratelimit.h"
39 #include <sys/param.h>
42 #include <sys/kernel.h>
44 #include <sys/module.h>
46 #include <sys/protosw.h>
47 #include <sys/domain.h>
48 #include <sys/socket.h>
49 #include <sys/socketvar.h>
50 #include <sys/sglist.h>
51 #include <sys/taskqueue.h>
52 #include <netinet/in.h>
53 #include <netinet/in_pcb.h>
54 #include <netinet/ip.h>
55 #include <netinet/ip6.h>
57 #include <netinet/tcp_fsm.h>
58 #include <netinet/tcp_seq.h>
59 #include <netinet/tcp_var.h>
60 #include <netinet/toecore.h>
62 #include <security/mac/mac_framework.h>
65 #include <vm/vm_extern.h>
67 #include <vm/vm_map.h>
68 #include <vm/vm_page.h>
70 #include "common/common.h"
71 #include "common/t4_msg.h"
72 #include "common/t4_regs.h"
73 #include "common/t4_tcb.h"
74 #include "tom/t4_tom_l2t.h"
75 #include "tom/t4_tom.h"
77 static void t4_aiotx_cancel(struct kaiocb *job);
78 static void t4_aiotx_queue_toep(struct socket *so, struct toepcb *toep);
81 send_flowc_wr(struct toepcb *toep, struct tcpcb *tp)
84 struct fw_flowc_wr *flowc;
85 unsigned int nparams, flowclen, paramidx;
86 struct vi_info *vi = toep->vi;
87 struct port_info *pi = vi->pi;
88 struct adapter *sc = pi->adapter;
89 unsigned int pfvf = sc->pf << S_FW_VIID_PFN;
90 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
92 KASSERT(!(toep->flags & TPF_FLOWC_WR_SENT),
93 ("%s: flowc for tid %u sent already", __func__, toep->tid));
99 if (ulp_mode(toep) == ULP_MODE_TLS)
101 if (toep->tls.fcplenmax != 0)
103 if (toep->params.tc_idx != -1) {
104 MPASS(toep->params.tc_idx >= 0 &&
105 toep->params.tc_idx < sc->chip_params->nsched_cls);
109 flowclen = sizeof(*flowc) + nparams * sizeof(struct fw_flowc_mnemval);
111 wr = alloc_wrqe(roundup2(flowclen, 16), toep->ofld_txq);
114 panic("%s: allocation failure.", __func__);
117 memset(flowc, 0, wr->wr_len);
119 flowc->op_to_nparams = htobe32(V_FW_WR_OP(FW_FLOWC_WR) |
120 V_FW_FLOWC_WR_NPARAMS(nparams));
121 flowc->flowid_len16 = htonl(V_FW_WR_LEN16(howmany(flowclen, 16)) |
122 V_FW_WR_FLOWID(toep->tid));
124 #define FLOWC_PARAM(__m, __v) \
126 flowc->mnemval[paramidx].mnemonic = FW_FLOWC_MNEM_##__m; \
127 flowc->mnemval[paramidx].val = htobe32(__v); \
133 FLOWC_PARAM(PFNVFN, pfvf);
134 FLOWC_PARAM(CH, pi->tx_chan);
135 FLOWC_PARAM(PORT, pi->tx_chan);
136 FLOWC_PARAM(IQID, toep->ofld_rxq->iq.abs_id);
137 FLOWC_PARAM(SNDBUF, toep->params.sndbuf);
139 FLOWC_PARAM(MSS, toep->params.emss);
140 FLOWC_PARAM(SNDNXT, tp->snd_nxt);
141 FLOWC_PARAM(RCVNXT, tp->rcv_nxt);
143 FLOWC_PARAM(MSS, 512);
145 "%s: tid %u, mss %u, sndbuf %u, snd_nxt 0x%x, rcv_nxt 0x%x",
146 __func__, toep->tid, toep->params.emss, toep->params.sndbuf,
147 tp ? tp->snd_nxt : 0, tp ? tp->rcv_nxt : 0);
149 if (ulp_mode(toep) == ULP_MODE_TLS)
150 FLOWC_PARAM(ULP_MODE, ulp_mode(toep));
151 if (toep->tls.fcplenmax != 0)
152 FLOWC_PARAM(TXDATAPLEN_MAX, toep->tls.fcplenmax);
153 if (toep->params.tc_idx != -1)
154 FLOWC_PARAM(SCHEDCLASS, toep->params.tc_idx);
157 KASSERT(paramidx == nparams, ("nparams mismatch"));
159 txsd->tx_credits = howmany(flowclen, 16);
161 KASSERT(toep->tx_credits >= txsd->tx_credits && toep->txsd_avail > 0,
162 ("%s: not enough credits (%d)", __func__, toep->tx_credits));
163 toep->tx_credits -= txsd->tx_credits;
164 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
168 toep->flags |= TPF_FLOWC_WR_SENT;
174 * Input is Bytes/second (so_max_pacing_rate), chip counts in Kilobits/second.
177 update_tx_rate_limit(struct adapter *sc, struct toepcb *toep, u_int Bps)
180 const u_int kbps = (u_int) (uint64_t)Bps * 8ULL / 1000;
181 const int port_id = toep->vi->pi->port_id;
183 CTR3(KTR_CXGBE, "%s: tid %u, rate %uKbps", __func__, toep->tid, kbps);
189 rc = t4_reserve_cl_rl_kbps(sc, port_id, kbps, &tc_idx);
192 MPASS(tc_idx >= 0 && tc_idx < sc->chip_params->nsched_cls);
195 if (toep->params.tc_idx != tc_idx) {
197 struct fw_flowc_wr *flowc;
198 int nparams = 1, flowclen, flowclen16;
199 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
201 flowclen = sizeof(*flowc) + nparams * sizeof(struct
203 flowclen16 = howmany(flowclen, 16);
204 if (toep->tx_credits < flowclen16 || toep->txsd_avail == 0 ||
205 (wr = alloc_wrqe(roundup2(flowclen, 16), toep->ofld_txq)) == NULL) {
207 t4_release_cl_rl(sc, port_id, tc_idx);
212 memset(flowc, 0, wr->wr_len);
214 flowc->op_to_nparams = htobe32(V_FW_WR_OP(FW_FLOWC_WR) |
215 V_FW_FLOWC_WR_NPARAMS(nparams));
216 flowc->flowid_len16 = htonl(V_FW_WR_LEN16(flowclen16) |
217 V_FW_WR_FLOWID(toep->tid));
219 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
221 flowc->mnemval[0].val = htobe32(0xff);
223 flowc->mnemval[0].val = htobe32(tc_idx);
225 txsd->tx_credits = flowclen16;
227 toep->tx_credits -= txsd->tx_credits;
228 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
234 if (toep->params.tc_idx >= 0)
235 t4_release_cl_rl(sc, port_id, toep->params.tc_idx);
236 toep->params.tc_idx = tc_idx;
243 send_reset(struct adapter *sc, struct toepcb *toep, uint32_t snd_nxt)
246 struct cpl_abort_req *req;
248 struct inpcb *inp = toep->inp;
249 struct tcpcb *tp = intotcpcb(inp); /* don't use if INP_DROPPED */
251 INP_WLOCK_ASSERT(inp);
253 CTR6(KTR_CXGBE, "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x%s",
255 inp->inp_flags & INP_DROPPED ? "inp dropped" :
256 tcpstates[tp->t_state],
257 toep->flags, inp->inp_flags,
258 toep->flags & TPF_ABORT_SHUTDOWN ?
259 " (abort already in progress)" : "");
261 if (toep->flags & TPF_ABORT_SHUTDOWN)
262 return; /* abort already in progress */
264 toep->flags |= TPF_ABORT_SHUTDOWN;
266 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
267 ("%s: flowc_wr not sent for tid %d.", __func__, tid));
269 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
272 panic("%s: allocation failure.", __func__);
276 INIT_TP_WR_MIT_CPL(req, CPL_ABORT_REQ, tid);
277 if (inp->inp_flags & INP_DROPPED)
278 req->rsvd0 = htobe32(snd_nxt);
280 req->rsvd0 = htobe32(tp->snd_nxt);
281 req->rsvd1 = !(toep->flags & TPF_TX_DATA_SENT);
282 req->cmd = CPL_ABORT_SEND_RST;
285 * XXX: What's the correct way to tell that the inp hasn't been detached
286 * from its socket? Should I even be flushing the snd buffer here?
288 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
289 struct socket *so = inp->inp_socket;
291 if (so != NULL) /* because I'm not sure. See comment above */
292 sbflush(&so->so_snd);
295 t4_l2t_send(sc, wr, toep->l2te);
299 * Called when a connection is established to translate the TCP options
300 * reported by HW to FreeBSD's native format.
303 assign_rxopt(struct tcpcb *tp, uint16_t opt)
305 struct toepcb *toep = tp->t_toe;
306 struct inpcb *inp = tp->t_inpcb;
307 struct adapter *sc = td_adapter(toep->td);
309 INP_LOCK_ASSERT(inp);
311 toep->params.mtu_idx = G_TCPOPT_MSS(opt);
312 tp->t_maxseg = sc->params.mtus[toep->params.mtu_idx];
313 if (inp->inp_inc.inc_flags & INC_ISIPV6)
314 tp->t_maxseg -= sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
316 tp->t_maxseg -= sizeof(struct ip) + sizeof(struct tcphdr);
318 toep->params.emss = tp->t_maxseg;
319 if (G_TCPOPT_TSTAMP(opt)) {
320 toep->params.tstamp = 1;
321 toep->params.emss -= TCPOLEN_TSTAMP_APPA;
322 tp->t_flags |= TF_RCVD_TSTMP; /* timestamps ok */
323 tp->ts_recent = 0; /* hmmm */
324 tp->ts_recent_age = tcp_ts_getticks();
326 toep->params.tstamp = 0;
328 if (G_TCPOPT_SACK(opt)) {
329 toep->params.sack = 1;
330 tp->t_flags |= TF_SACK_PERMIT; /* should already be set */
332 toep->params.sack = 0;
333 tp->t_flags &= ~TF_SACK_PERMIT; /* sack disallowed by peer */
336 if (G_TCPOPT_WSCALE_OK(opt))
337 tp->t_flags |= TF_RCVD_SCALE;
339 /* Doing window scaling? */
340 if ((tp->t_flags & (TF_RCVD_SCALE | TF_REQ_SCALE)) ==
341 (TF_RCVD_SCALE | TF_REQ_SCALE)) {
342 tp->rcv_scale = tp->request_r_scale;
343 tp->snd_scale = G_TCPOPT_SND_WSCALE(opt);
345 toep->params.wscale = 0;
348 "assign_rxopt: tid %d, mtu_idx %u, emss %u, ts %u, sack %u, wscale %u",
349 toep->tid, toep->params.mtu_idx, toep->params.emss,
350 toep->params.tstamp, toep->params.sack, toep->params.wscale);
354 * Completes some final bits of initialization for just established connections
355 * and changes their state to TCPS_ESTABLISHED.
357 * The ISNs are from the exchange of SYNs.
360 make_established(struct toepcb *toep, uint32_t iss, uint32_t irs, uint16_t opt)
362 struct inpcb *inp = toep->inp;
363 struct socket *so = inp->inp_socket;
364 struct tcpcb *tp = intotcpcb(inp);
365 uint16_t tcpopt = be16toh(opt);
367 INP_WLOCK_ASSERT(inp);
368 KASSERT(tp->t_state == TCPS_SYN_SENT ||
369 tp->t_state == TCPS_SYN_RECEIVED,
370 ("%s: TCP state %s", __func__, tcpstates[tp->t_state]));
372 CTR6(KTR_CXGBE, "%s: tid %d, so %p, inp %p, tp %p, toep %p",
373 __func__, toep->tid, so, inp, tp, toep);
375 tcp_state_change(tp, TCPS_ESTABLISHED);
376 tp->t_starttime = ticks;
377 TCPSTAT_INC(tcps_connects);
381 tp->rcv_wnd = (u_int)toep->params.opt0_bufsize << 10;
382 tp->rcv_adv += tp->rcv_wnd;
383 tp->last_ack_sent = tp->rcv_nxt;
387 tp->snd_una = iss + 1;
388 tp->snd_nxt = iss + 1;
389 tp->snd_max = iss + 1;
391 assign_rxopt(tp, tcpopt);
392 send_flowc_wr(toep, tp);
398 send_rx_credits(struct adapter *sc, struct toepcb *toep, int credits)
401 struct cpl_rx_data_ack *req;
402 uint32_t dack = F_RX_DACK_CHANGE | V_RX_DACK_MODE(1);
404 KASSERT(credits >= 0, ("%s: %d credits", __func__, credits));
406 wr = alloc_wrqe(sizeof(*req), toep->ctrlq);
411 INIT_TP_WR_MIT_CPL(req, CPL_RX_DATA_ACK, toep->tid);
412 req->credit_dack = htobe32(dack | V_RX_CREDITS(credits));
419 send_rx_modulate(struct adapter *sc, struct toepcb *toep)
422 struct cpl_rx_data_ack *req;
424 wr = alloc_wrqe(sizeof(*req), toep->ctrlq);
429 INIT_TP_WR_MIT_CPL(req, CPL_RX_DATA_ACK, toep->tid);
430 req->credit_dack = htobe32(F_RX_MODULATE_RX);
436 t4_rcvd_locked(struct toedev *tod, struct tcpcb *tp)
438 struct adapter *sc = tod->tod_softc;
439 struct inpcb *inp = tp->t_inpcb;
440 struct socket *so = inp->inp_socket;
441 struct sockbuf *sb = &so->so_rcv;
442 struct toepcb *toep = tp->t_toe;
445 INP_WLOCK_ASSERT(inp);
446 SOCKBUF_LOCK_ASSERT(sb);
448 rx_credits = sbspace(sb) > tp->rcv_wnd ? sbspace(sb) - tp->rcv_wnd : 0;
449 if (ulp_mode(toep) == ULP_MODE_TLS) {
450 if (toep->tls.rcv_over >= rx_credits) {
451 toep->tls.rcv_over -= rx_credits;
454 rx_credits -= toep->tls.rcv_over;
455 toep->tls.rcv_over = 0;
459 if (rx_credits > 0 &&
460 (tp->rcv_wnd <= 32 * 1024 || rx_credits >= 64 * 1024 ||
461 (rx_credits >= 16 * 1024 && tp->rcv_wnd <= 128 * 1024) ||
462 sbused(sb) + tp->rcv_wnd < sb->sb_lowat)) {
463 rx_credits = send_rx_credits(sc, toep, rx_credits);
464 tp->rcv_wnd += rx_credits;
465 tp->rcv_adv += rx_credits;
466 } else if (toep->flags & TPF_FORCE_CREDITS)
467 send_rx_modulate(sc, toep);
471 t4_rcvd(struct toedev *tod, struct tcpcb *tp)
473 struct inpcb *inp = tp->t_inpcb;
474 struct socket *so = inp->inp_socket;
475 struct sockbuf *sb = &so->so_rcv;
478 t4_rcvd_locked(tod, tp);
483 * Close a connection by sending a CPL_CLOSE_CON_REQ message.
486 t4_close_conn(struct adapter *sc, struct toepcb *toep)
489 struct cpl_close_con_req *req;
490 unsigned int tid = toep->tid;
492 CTR3(KTR_CXGBE, "%s: tid %u%s", __func__, toep->tid,
493 toep->flags & TPF_FIN_SENT ? ", IGNORED" : "");
495 if (toep->flags & TPF_FIN_SENT)
498 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
499 ("%s: flowc_wr not sent for tid %u.", __func__, tid));
501 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
504 panic("%s: allocation failure.", __func__);
508 req->wr.wr_hi = htonl(V_FW_WR_OP(FW_TP_WR) |
509 V_FW_WR_IMMDLEN(sizeof(*req) - sizeof(req->wr)));
510 req->wr.wr_mid = htonl(V_FW_WR_LEN16(howmany(sizeof(*req), 16)) |
511 V_FW_WR_FLOWID(tid));
512 req->wr.wr_lo = cpu_to_be64(0);
513 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
516 toep->flags |= TPF_FIN_SENT;
517 toep->flags &= ~TPF_SEND_FIN;
518 t4_l2t_send(sc, wr, toep->l2te);
523 #define MAX_OFLD_TX_CREDITS (SGE_MAX_WR_LEN / 16)
524 #define MIN_OFLD_TX_CREDITS (howmany(sizeof(struct fw_ofld_tx_data_wr) + 1, 16))
526 /* Maximum amount of immediate data we could stuff in a WR */
528 max_imm_payload(int tx_credits)
530 const int n = 1; /* Use no more than one desc for imm. data WR */
532 KASSERT(tx_credits >= 0 &&
533 tx_credits <= MAX_OFLD_TX_CREDITS,
534 ("%s: %d credits", __func__, tx_credits));
536 if (tx_credits < MIN_OFLD_TX_CREDITS)
539 if (tx_credits >= (n * EQ_ESIZE) / 16)
540 return ((n * EQ_ESIZE) - sizeof(struct fw_ofld_tx_data_wr));
542 return (tx_credits * 16 - sizeof(struct fw_ofld_tx_data_wr));
545 /* Maximum number of SGL entries we could stuff in a WR */
547 max_dsgl_nsegs(int tx_credits)
549 int nseg = 1; /* ulptx_sgl has room for 1, rest ulp_tx_sge_pair */
550 int sge_pair_credits = tx_credits - MIN_OFLD_TX_CREDITS;
552 KASSERT(tx_credits >= 0 &&
553 tx_credits <= MAX_OFLD_TX_CREDITS,
554 ("%s: %d credits", __func__, tx_credits));
556 if (tx_credits < MIN_OFLD_TX_CREDITS)
559 nseg += 2 * (sge_pair_credits * 16 / 24);
560 if ((sge_pair_credits * 16) % 24 == 16)
567 write_tx_wr(void *dst, struct toepcb *toep, unsigned int immdlen,
568 unsigned int plen, uint8_t credits, int shove, int ulp_submode)
570 struct fw_ofld_tx_data_wr *txwr = dst;
572 txwr->op_to_immdlen = htobe32(V_WR_OP(FW_OFLD_TX_DATA_WR) |
573 V_FW_WR_IMMDLEN(immdlen));
574 txwr->flowid_len16 = htobe32(V_FW_WR_FLOWID(toep->tid) |
575 V_FW_WR_LEN16(credits));
576 txwr->lsodisable_to_flags = htobe32(V_TX_ULP_MODE(ulp_mode(toep)) |
577 V_TX_ULP_SUBMODE(ulp_submode) | V_TX_URG(0) | V_TX_SHOVE(shove));
578 txwr->plen = htobe32(plen);
580 if (toep->params.tx_align > 0) {
581 if (plen < 2 * toep->params.emss)
582 txwr->lsodisable_to_flags |=
583 htobe32(F_FW_OFLD_TX_DATA_WR_LSODISABLE);
585 txwr->lsodisable_to_flags |=
586 htobe32(F_FW_OFLD_TX_DATA_WR_ALIGNPLD |
587 (toep->params.nagle == 0 ? 0 :
588 F_FW_OFLD_TX_DATA_WR_ALIGNPLDSHOVE));
593 * Generate a DSGL from a starting mbuf. The total number of segments and the
594 * maximum segments in any one mbuf are provided.
597 write_tx_sgl(void *dst, struct mbuf *start, struct mbuf *stop, int nsegs, int n)
600 struct ulptx_sgl *usgl = dst;
603 struct sglist_seg segs[n];
605 KASSERT(nsegs > 0, ("%s: nsegs 0", __func__));
607 sglist_init(&sg, n, segs);
608 usgl->cmd_nsge = htobe32(V_ULPTX_CMD(ULP_TX_SC_DSGL) |
609 V_ULPTX_NSGE(nsegs));
612 for (m = start; m != stop; m = m->m_next) {
613 if (m->m_flags & M_NOMAP)
614 rc = sglist_append_mb_ext_pgs(&sg, m);
616 rc = sglist_append(&sg, mtod(m, void *), m->m_len);
617 if (__predict_false(rc != 0))
618 panic("%s: sglist_append %d", __func__, rc);
620 for (j = 0; j < sg.sg_nseg; i++, j++) {
622 usgl->len0 = htobe32(segs[j].ss_len);
623 usgl->addr0 = htobe64(segs[j].ss_paddr);
625 usgl->sge[i / 2].len[i & 1] =
626 htobe32(segs[j].ss_len);
627 usgl->sge[i / 2].addr[i & 1] =
628 htobe64(segs[j].ss_paddr);
637 usgl->sge[i / 2].len[1] = htobe32(0);
638 KASSERT(nsegs == 0, ("%s: nsegs %d, start %p, stop %p",
639 __func__, nsegs, start, stop));
643 * Max number of SGL entries an offload tx work request can have. This is 41
644 * (1 + 40) for a full 512B work request.
645 * fw_ofld_tx_data_wr(16B) + ulptx_sgl(16B, 1) + ulptx_sge_pair(480B, 40)
647 #define OFLD_SGL_LEN (41)
650 * Send data and/or a FIN to the peer.
652 * The socket's so_snd buffer consists of a stream of data starting with sb_mb
653 * and linked together with m_next. sb_sndptr, if set, is the last mbuf that
656 * drop indicates the number of bytes that should be dropped from the head of
657 * the send buffer. It is an optimization that lets do_fw4_ack avoid creating
658 * contention on the send buffer lock (before this change it used to do
659 * sowwakeup and then t4_push_frames right after that when recovering from tx
660 * stalls). When drop is set this function MUST drop the bytes and wake up any
664 t4_push_frames(struct adapter *sc, struct toepcb *toep, int drop)
666 struct mbuf *sndptr, *m, *sb_sndptr;
667 struct fw_ofld_tx_data_wr *txwr;
669 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
670 struct inpcb *inp = toep->inp;
671 struct tcpcb *tp = intotcpcb(inp);
672 struct socket *so = inp->inp_socket;
673 struct sockbuf *sb = &so->so_snd;
674 int tx_credits, shove, compl, sowwakeup;
675 struct ofld_tx_sdesc *txsd;
676 bool nomap_mbuf_seen;
678 INP_WLOCK_ASSERT(inp);
679 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
680 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
682 KASSERT(ulp_mode(toep) == ULP_MODE_NONE ||
683 ulp_mode(toep) == ULP_MODE_TCPDDP ||
684 ulp_mode(toep) == ULP_MODE_TLS ||
685 ulp_mode(toep) == ULP_MODE_RDMA,
686 ("%s: ulp_mode %u for toep %p", __func__, ulp_mode(toep), toep));
688 #ifdef VERBOSE_TRACES
689 CTR5(KTR_CXGBE, "%s: tid %d toep flags %#x tp flags %#x drop %d",
690 __func__, toep->tid, toep->flags, tp->t_flags, drop);
692 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
696 if (__predict_false(inp->inp_flags2 & INP_RATE_LIMIT_CHANGED) &&
697 (update_tx_rate_limit(sc, toep, so->so_max_pacing_rate) == 0)) {
698 inp->inp_flags2 &= ~INP_RATE_LIMIT_CHANGED;
703 * This function doesn't resume by itself. Someone else must clear the
704 * flag and call this function.
706 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
708 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
712 txsd = &toep->txsd[toep->txsd_pidx];
714 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
715 max_imm = max_imm_payload(tx_credits);
716 max_nsegs = max_dsgl_nsegs(tx_credits);
721 sbdrop_locked(sb, drop);
724 sb_sndptr = sb->sb_sndptr;
725 sndptr = sb_sndptr ? sb_sndptr->m_next : sb->sb_mb;
728 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
729 nomap_mbuf_seen = false;
730 for (m = sndptr; m != NULL; m = m->m_next) {
733 if (m->m_flags & M_NOMAP) {
735 if (m->m_ext.ext_pgs->tls != NULL) {
736 toep->flags |= TPF_KTLS;
739 t4_push_ktls(sc, toep, 0);
745 n = sglist_count_mb_ext_pgs(m);
747 n = sglist_count(mtod(m, void *), m->m_len);
752 /* This mbuf sent us _over_ the nsegs limit, back out */
753 if (plen > max_imm && nsegs > max_nsegs) {
757 /* Too few credits */
758 toep->flags |= TPF_TX_SUSPENDED;
762 t4_aiotx_queue_toep(so,
764 sowwakeup_locked(so);
767 SOCKBUF_UNLOCK_ASSERT(sb);
773 if (m->m_flags & M_NOMAP)
774 nomap_mbuf_seen = true;
775 if (max_nsegs_1mbuf < n)
777 sb_sndptr = m; /* new sb->sb_sndptr if all goes well */
779 /* This mbuf put us right at the max_nsegs limit */
780 if (plen > max_imm && nsegs == max_nsegs) {
786 if (sbused(sb) > sb->sb_hiwat * 5 / 8 &&
787 toep->plen_nocompl + plen >= sb->sb_hiwat / 4)
792 if (sb->sb_flags & SB_AUTOSIZE &&
793 V_tcp_do_autosndbuf &&
794 sb->sb_hiwat < V_tcp_autosndbuf_max &&
795 sbused(sb) >= sb->sb_hiwat * 7 / 8) {
796 int newsize = min(sb->sb_hiwat + V_tcp_autosndbuf_inc,
797 V_tcp_autosndbuf_max);
799 if (!sbreserve_locked(sb, newsize, so, NULL))
800 sb->sb_flags &= ~SB_AUTOSIZE;
802 sowwakeup = 1; /* room available */
805 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
806 t4_aiotx_queue_toep(so, toep);
807 sowwakeup_locked(so);
810 SOCKBUF_UNLOCK_ASSERT(sb);
812 /* nothing to send */
815 ("%s: nothing to send, but m != NULL", __func__));
819 if (__predict_false(toep->flags & TPF_FIN_SENT))
820 panic("%s: excess tx.", __func__);
822 shove = m == NULL && !(tp->t_flags & TF_MORETOCOME);
823 if (plen <= max_imm && !nomap_mbuf_seen) {
825 /* Immediate data tx */
827 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
830 /* XXX: how will we recover from this? */
831 toep->flags |= TPF_TX_SUSPENDED;
835 credits = howmany(wr->wr_len, 16);
836 write_tx_wr(txwr, toep, plen, plen, credits, shove, 0);
837 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
844 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
845 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
846 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
848 /* XXX: how will we recover from this? */
849 toep->flags |= TPF_TX_SUSPENDED;
853 credits = howmany(wr_len, 16);
854 write_tx_wr(txwr, toep, 0, plen, credits, shove, 0);
855 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
858 uint64_t *pad = (uint64_t *)
859 ((uintptr_t)txwr + wr_len);
864 KASSERT(toep->tx_credits >= credits,
865 ("%s: not enough credits", __func__));
867 toep->tx_credits -= credits;
868 toep->tx_nocompl += credits;
869 toep->plen_nocompl += plen;
870 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
871 toep->tx_nocompl >= toep->tx_total / 4)
874 if (compl || ulp_mode(toep) == ULP_MODE_RDMA) {
875 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
876 toep->tx_nocompl = 0;
877 toep->plen_nocompl = 0;
884 KASSERT(sb_sndptr, ("%s: sb_sndptr is NULL", __func__));
885 sb->sb_sndptr = sb_sndptr;
888 toep->flags |= TPF_TX_DATA_SENT;
889 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
890 toep->flags |= TPF_TX_SUSPENDED;
892 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
894 txsd->tx_credits = credits;
896 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
898 txsd = &toep->txsd[0];
902 t4_l2t_send(sc, wr, toep->l2te);
905 /* Send a FIN if requested, but only if there's no more data to send */
906 if (m == NULL && toep->flags & TPF_SEND_FIN)
907 t4_close_conn(sc, toep);
911 rqdrop_locked(struct mbufq *q, int plen)
916 m = mbufq_dequeue(q);
918 /* Too many credits. */
922 /* Partial credits. */
923 MPASS(plen >= m->m_pkthdr.len);
925 plen -= m->m_pkthdr.len;
931 t4_push_pdus(struct adapter *sc, struct toepcb *toep, int drop)
933 struct mbuf *sndptr, *m;
934 struct fw_ofld_tx_data_wr *txwr;
936 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
937 u_int adjusted_plen, ulp_submode;
938 struct inpcb *inp = toep->inp;
939 struct tcpcb *tp = intotcpcb(inp);
940 int tx_credits, shove;
941 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
942 struct mbufq *pduq = &toep->ulp_pduq;
943 static const u_int ulp_extra_len[] = {0, 4, 4, 8};
945 INP_WLOCK_ASSERT(inp);
946 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
947 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
948 KASSERT(ulp_mode(toep) == ULP_MODE_ISCSI,
949 ("%s: ulp_mode %u for toep %p", __func__, ulp_mode(toep), toep));
951 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
955 * This function doesn't resume by itself. Someone else must clear the
956 * flag and call this function.
958 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
960 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
965 rqdrop_locked(&toep->ulp_pdu_reclaimq, drop);
967 while ((sndptr = mbufq_first(pduq)) != NULL) {
968 M_ASSERTPKTHDR(sndptr);
970 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
971 max_imm = max_imm_payload(tx_credits);
972 max_nsegs = max_dsgl_nsegs(tx_credits);
976 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
977 for (m = sndptr; m != NULL; m = m->m_next) {
978 int n = sglist_count(mtod(m, void *), m->m_len);
984 * This mbuf would send us _over_ the nsegs limit.
985 * Suspend tx because the PDU can't be sent out.
987 if (plen > max_imm && nsegs > max_nsegs) {
988 toep->flags |= TPF_TX_SUSPENDED;
992 if (max_nsegs_1mbuf < n)
996 if (__predict_false(toep->flags & TPF_FIN_SENT))
997 panic("%s: excess tx.", __func__);
1000 * We have a PDU to send. All of it goes out in one WR so 'm'
1001 * is NULL. A PDU's length is always a multiple of 4.
1004 MPASS((plen & 3) == 0);
1005 MPASS(sndptr->m_pkthdr.len == plen);
1007 shove = !(tp->t_flags & TF_MORETOCOME);
1008 ulp_submode = mbuf_ulp_submode(sndptr);
1009 MPASS(ulp_submode < nitems(ulp_extra_len));
1012 * plen doesn't include header and data digests, which are
1013 * generated and inserted in the right places by the TOE, but
1014 * they do occupy TCP sequence space and need to be accounted
1017 adjusted_plen = plen + ulp_extra_len[ulp_submode];
1018 if (plen <= max_imm) {
1020 /* Immediate data tx */
1022 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
1025 /* XXX: how will we recover from this? */
1026 toep->flags |= TPF_TX_SUSPENDED;
1030 credits = howmany(wr->wr_len, 16);
1031 write_tx_wr(txwr, toep, plen, adjusted_plen, credits,
1032 shove, ulp_submode);
1033 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
1039 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
1040 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
1041 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
1043 /* XXX: how will we recover from this? */
1044 toep->flags |= TPF_TX_SUSPENDED;
1048 credits = howmany(wr_len, 16);
1049 write_tx_wr(txwr, toep, 0, adjusted_plen, credits,
1050 shove, ulp_submode);
1051 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
1054 uint64_t *pad = (uint64_t *)
1055 ((uintptr_t)txwr + wr_len);
1060 KASSERT(toep->tx_credits >= credits,
1061 ("%s: not enough credits", __func__));
1063 m = mbufq_dequeue(pduq);
1065 mbufq_enqueue(&toep->ulp_pdu_reclaimq, m);
1067 toep->tx_credits -= credits;
1068 toep->tx_nocompl += credits;
1069 toep->plen_nocompl += plen;
1070 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
1071 toep->tx_nocompl >= toep->tx_total / 4) {
1072 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
1073 toep->tx_nocompl = 0;
1074 toep->plen_nocompl = 0;
1077 tp->snd_nxt += adjusted_plen;
1078 tp->snd_max += adjusted_plen;
1080 toep->flags |= TPF_TX_DATA_SENT;
1081 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
1082 toep->flags |= TPF_TX_SUSPENDED;
1084 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
1086 txsd->tx_credits = credits;
1088 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
1089 toep->txsd_pidx = 0;
1090 txsd = &toep->txsd[0];
1094 t4_l2t_send(sc, wr, toep->l2te);
1097 /* Send a FIN if requested, but only if there are no more PDUs to send */
1098 if (mbufq_first(pduq) == NULL && toep->flags & TPF_SEND_FIN)
1099 t4_close_conn(sc, toep);
1103 t4_push_data(struct adapter *sc, struct toepcb *toep, int drop)
1106 if (ulp_mode(toep) == ULP_MODE_ISCSI)
1107 t4_push_pdus(sc, toep, drop);
1108 else if (tls_tx_key(toep) && toep->tls.mode == TLS_MODE_TLSOM)
1109 t4_push_tls_records(sc, toep, drop);
1111 else if (toep->flags & TPF_KTLS)
1112 t4_push_ktls(sc, toep, drop);
1115 t4_push_frames(sc, toep, drop);
1119 t4_tod_output(struct toedev *tod, struct tcpcb *tp)
1121 struct adapter *sc = tod->tod_softc;
1123 struct inpcb *inp = tp->t_inpcb;
1125 struct toepcb *toep = tp->t_toe;
1127 INP_WLOCK_ASSERT(inp);
1128 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1129 ("%s: inp %p dropped.", __func__, inp));
1130 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1132 t4_push_data(sc, toep, 0);
1138 t4_send_fin(struct toedev *tod, struct tcpcb *tp)
1140 struct adapter *sc = tod->tod_softc;
1142 struct inpcb *inp = tp->t_inpcb;
1144 struct toepcb *toep = tp->t_toe;
1146 INP_WLOCK_ASSERT(inp);
1147 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1148 ("%s: inp %p dropped.", __func__, inp));
1149 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1151 toep->flags |= TPF_SEND_FIN;
1152 if (tp->t_state >= TCPS_ESTABLISHED)
1153 t4_push_data(sc, toep, 0);
1159 t4_send_rst(struct toedev *tod, struct tcpcb *tp)
1161 struct adapter *sc = tod->tod_softc;
1162 #if defined(INVARIANTS)
1163 struct inpcb *inp = tp->t_inpcb;
1165 struct toepcb *toep = tp->t_toe;
1167 INP_WLOCK_ASSERT(inp);
1168 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1169 ("%s: inp %p dropped.", __func__, inp));
1170 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1173 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
1174 ("%s: flowc for tid %u [%s] not sent already",
1175 __func__, toep->tid, tcpstates[tp->t_state]));
1177 send_reset(sc, toep, 0);
1182 * Peer has sent us a FIN.
1185 do_peer_close(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1187 struct adapter *sc = iq->adapter;
1188 const struct cpl_peer_close *cpl = (const void *)(rss + 1);
1189 unsigned int tid = GET_TID(cpl);
1190 struct toepcb *toep = lookup_tid(sc, tid);
1191 struct inpcb *inp = toep->inp;
1192 struct tcpcb *tp = NULL;
1194 struct epoch_tracker et;
1196 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1199 KASSERT(opcode == CPL_PEER_CLOSE,
1200 ("%s: unexpected opcode 0x%x", __func__, opcode));
1201 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1203 if (__predict_false(toep->flags & TPF_SYNQE)) {
1205 * do_pass_establish must have run before do_peer_close and if
1206 * this is still a synqe instead of a toepcb then the connection
1207 * must be getting aborted.
1209 MPASS(toep->flags & TPF_ABORT_SHUTDOWN);
1210 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1215 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1217 CURVNET_SET(toep->vnet);
1218 NET_EPOCH_ENTER(et);
1220 tp = intotcpcb(inp);
1223 "%s: tid %u (%s), toep_flags 0x%x, ddp_flags 0x%x, inp %p",
1224 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags,
1225 toep->ddp.flags, inp);
1227 if (toep->flags & TPF_ABORT_SHUTDOWN)
1230 tp->rcv_nxt++; /* FIN */
1232 so = inp->inp_socket;
1234 if (ulp_mode(toep) == ULP_MODE_TCPDDP) {
1236 if (__predict_false(toep->ddp.flags &
1237 (DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE)))
1238 handle_ddp_close(toep, tp, cpl->rcv_nxt);
1242 if (ulp_mode(toep) != ULP_MODE_RDMA) {
1243 KASSERT(tp->rcv_nxt == be32toh(cpl->rcv_nxt),
1244 ("%s: rcv_nxt mismatch: %u %u", __func__, tp->rcv_nxt,
1245 be32toh(cpl->rcv_nxt)));
1248 switch (tp->t_state) {
1249 case TCPS_SYN_RECEIVED:
1250 tp->t_starttime = ticks;
1253 case TCPS_ESTABLISHED:
1254 tcp_state_change(tp, TCPS_CLOSE_WAIT);
1257 case TCPS_FIN_WAIT_1:
1258 tcp_state_change(tp, TCPS_CLOSING);
1261 case TCPS_FIN_WAIT_2:
1263 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1268 final_cpl_received(toep);
1272 log(LOG_ERR, "%s: TID %u received CPL_PEER_CLOSE in state %d\n",
1273 __func__, tid, tp->t_state);
1283 * Peer has ACK'd our FIN.
1286 do_close_con_rpl(struct sge_iq *iq, const struct rss_header *rss,
1289 struct adapter *sc = iq->adapter;
1290 const struct cpl_close_con_rpl *cpl = (const void *)(rss + 1);
1291 unsigned int tid = GET_TID(cpl);
1292 struct toepcb *toep = lookup_tid(sc, tid);
1293 struct inpcb *inp = toep->inp;
1294 struct tcpcb *tp = NULL;
1295 struct socket *so = NULL;
1296 struct epoch_tracker et;
1298 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1301 KASSERT(opcode == CPL_CLOSE_CON_RPL,
1302 ("%s: unexpected opcode 0x%x", __func__, opcode));
1303 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1304 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1306 CURVNET_SET(toep->vnet);
1307 NET_EPOCH_ENTER(et);
1309 tp = intotcpcb(inp);
1311 CTR4(KTR_CXGBE, "%s: tid %u (%s), toep_flags 0x%x",
1312 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags);
1314 if (toep->flags & TPF_ABORT_SHUTDOWN)
1317 so = inp->inp_socket;
1318 tp->snd_una = be32toh(cpl->snd_nxt) - 1; /* exclude FIN */
1320 switch (tp->t_state) {
1321 case TCPS_CLOSING: /* see TCPS_FIN_WAIT_2 in do_peer_close too */
1324 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1329 final_cpl_received(toep); /* no more CPLs expected */
1337 case TCPS_FIN_WAIT_1:
1338 if (so->so_rcv.sb_state & SBS_CANTRCVMORE)
1339 soisdisconnected(so);
1340 tcp_state_change(tp, TCPS_FIN_WAIT_2);
1345 "%s: TID %u received CPL_CLOSE_CON_RPL in state %s\n",
1346 __func__, tid, tcpstates[tp->t_state]);
1356 send_abort_rpl(struct adapter *sc, struct sge_wrq *ofld_txq, int tid,
1360 struct cpl_abort_rpl *cpl;
1362 wr = alloc_wrqe(sizeof(*cpl), ofld_txq);
1365 panic("%s: allocation failure.", __func__);
1369 INIT_TP_WR_MIT_CPL(cpl, CPL_ABORT_RPL, tid);
1370 cpl->cmd = rst_status;
1376 abort_status_to_errno(struct tcpcb *tp, unsigned int abort_reason)
1378 switch (abort_reason) {
1379 case CPL_ERR_BAD_SYN:
1380 case CPL_ERR_CONN_RESET:
1381 return (tp->t_state == TCPS_CLOSE_WAIT ? EPIPE : ECONNRESET);
1382 case CPL_ERR_XMIT_TIMEDOUT:
1383 case CPL_ERR_PERSIST_TIMEDOUT:
1384 case CPL_ERR_FINWAIT2_TIMEDOUT:
1385 case CPL_ERR_KEEPALIVE_TIMEDOUT:
1393 * TCP RST from the peer, timeout, or some other such critical error.
1396 do_abort_req(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1398 struct adapter *sc = iq->adapter;
1399 const struct cpl_abort_req_rss *cpl = (const void *)(rss + 1);
1400 unsigned int tid = GET_TID(cpl);
1401 struct toepcb *toep = lookup_tid(sc, tid);
1402 struct sge_wrq *ofld_txq = toep->ofld_txq;
1405 struct epoch_tracker et;
1407 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1410 KASSERT(opcode == CPL_ABORT_REQ_RSS,
1411 ("%s: unexpected opcode 0x%x", __func__, opcode));
1412 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1414 if (toep->flags & TPF_SYNQE)
1415 return (do_abort_req_synqe(iq, rss, m));
1417 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1419 if (negative_advice(cpl->status)) {
1420 CTR4(KTR_CXGBE, "%s: negative advice %d for tid %d (0x%x)",
1421 __func__, cpl->status, tid, toep->flags);
1422 return (0); /* Ignore negative advice */
1426 CURVNET_SET(toep->vnet);
1427 NET_EPOCH_ENTER(et); /* for tcp_close */
1430 tp = intotcpcb(inp);
1433 "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x, status %d",
1434 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags,
1435 inp->inp_flags, cpl->status);
1438 * If we'd initiated an abort earlier the reply to it is responsible for
1439 * cleaning up resources. Otherwise we tear everything down right here
1440 * right now. We owe the T4 a CPL_ABORT_RPL no matter what.
1442 if (toep->flags & TPF_ABORT_SHUTDOWN) {
1446 toep->flags |= TPF_ABORT_SHUTDOWN;
1448 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
1449 struct socket *so = inp->inp_socket;
1452 so_error_set(so, abort_status_to_errno(tp,
1456 INP_WLOCK(inp); /* re-acquire */
1459 final_cpl_received(toep);
1463 send_abort_rpl(sc, ofld_txq, tid, CPL_ABORT_NO_RST);
1468 * Reply to the CPL_ABORT_REQ (send_reset)
1471 do_abort_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1473 struct adapter *sc = iq->adapter;
1474 const struct cpl_abort_rpl_rss *cpl = (const void *)(rss + 1);
1475 unsigned int tid = GET_TID(cpl);
1476 struct toepcb *toep = lookup_tid(sc, tid);
1477 struct inpcb *inp = toep->inp;
1479 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1482 KASSERT(opcode == CPL_ABORT_RPL_RSS,
1483 ("%s: unexpected opcode 0x%x", __func__, opcode));
1484 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1486 if (toep->flags & TPF_SYNQE)
1487 return (do_abort_rpl_synqe(iq, rss, m));
1489 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1491 CTR5(KTR_CXGBE, "%s: tid %u, toep %p, inp %p, status %d",
1492 __func__, tid, toep, inp, cpl->status);
1494 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1495 ("%s: wasn't expecting abort reply", __func__));
1498 final_cpl_received(toep);
1504 do_rx_data(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1506 struct adapter *sc = iq->adapter;
1507 const struct cpl_rx_data *cpl = mtod(m, const void *);
1508 unsigned int tid = GET_TID(cpl);
1509 struct toepcb *toep = lookup_tid(sc, tid);
1510 struct inpcb *inp = toep->inp;
1514 struct epoch_tracker et;
1515 int len, rx_credits;
1516 uint32_t ddp_placed = 0;
1518 if (__predict_false(toep->flags & TPF_SYNQE)) {
1520 * do_pass_establish must have run before do_rx_data and if this
1521 * is still a synqe instead of a toepcb then the connection must
1522 * be getting aborted.
1524 MPASS(toep->flags & TPF_ABORT_SHUTDOWN);
1525 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1531 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1533 /* strip off CPL header */
1534 m_adj(m, sizeof(*cpl));
1535 len = m->m_pkthdr.len;
1538 if (inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) {
1539 CTR4(KTR_CXGBE, "%s: tid %u, rx (%d bytes), inp_flags 0x%x",
1540 __func__, tid, len, inp->inp_flags);
1546 tp = intotcpcb(inp);
1548 if (__predict_false(tp->rcv_nxt != be32toh(cpl->seq)))
1549 ddp_placed = be32toh(cpl->seq) - tp->rcv_nxt;
1552 if (tp->rcv_wnd < len) {
1553 KASSERT(ulp_mode(toep) == ULP_MODE_RDMA,
1554 ("%s: negative window size", __func__));
1558 tp->t_rcvtime = ticks;
1560 if (ulp_mode(toep) == ULP_MODE_TCPDDP)
1562 so = inp_inpcbtosocket(inp);
1566 if (__predict_false(sb->sb_state & SBS_CANTRCVMORE)) {
1567 CTR3(KTR_CXGBE, "%s: tid %u, excess rx (%d bytes)",
1568 __func__, tid, len);
1571 if (ulp_mode(toep) == ULP_MODE_TCPDDP)
1575 CURVNET_SET(toep->vnet);
1576 NET_EPOCH_ENTER(et);
1578 tp = tcp_drop(tp, ECONNRESET);
1587 /* receive buffer autosize */
1588 MPASS(toep->vnet == so->so_vnet);
1589 CURVNET_SET(toep->vnet);
1590 if (sb->sb_flags & SB_AUTOSIZE &&
1591 V_tcp_do_autorcvbuf &&
1592 sb->sb_hiwat < V_tcp_autorcvbuf_max &&
1593 len > (sbspace(sb) / 8 * 7)) {
1594 unsigned int hiwat = sb->sb_hiwat;
1595 unsigned int newsize = min(hiwat + sc->tt.autorcvbuf_inc,
1596 V_tcp_autorcvbuf_max);
1598 if (!sbreserve_locked(sb, newsize, so, NULL))
1599 sb->sb_flags &= ~SB_AUTOSIZE;
1602 if (ulp_mode(toep) == ULP_MODE_TCPDDP) {
1603 int changed = !(toep->ddp.flags & DDP_ON) ^ cpl->ddp_off;
1605 if (toep->ddp.waiting_count != 0 || toep->ddp.active_count != 0)
1606 CTR3(KTR_CXGBE, "%s: tid %u, non-ddp rx (%d bytes)",
1607 __func__, tid, len);
1610 if (toep->ddp.flags & DDP_SC_REQ)
1611 toep->ddp.flags ^= DDP_ON | DDP_SC_REQ;
1613 KASSERT(cpl->ddp_off == 1,
1614 ("%s: DDP switched on by itself.",
1617 /* Fell out of DDP mode */
1618 toep->ddp.flags &= ~DDP_ON;
1619 CTR1(KTR_CXGBE, "%s: fell out of DDP mode",
1622 insert_ddp_data(toep, ddp_placed);
1626 if (toep->ddp.flags & DDP_ON) {
1628 * CPL_RX_DATA with DDP on can only be an indicate.
1629 * Start posting queued AIO requests via DDP. The
1630 * payload that arrived in this indicate is appended
1631 * to the socket buffer as usual.
1633 handle_ddp_indicate(toep);
1637 sbappendstream_locked(sb, m, 0);
1638 rx_credits = sbspace(sb) > tp->rcv_wnd ? sbspace(sb) - tp->rcv_wnd : 0;
1639 if (rx_credits > 0 && sbused(sb) + tp->rcv_wnd < sb->sb_lowat) {
1640 rx_credits = send_rx_credits(sc, toep, rx_credits);
1641 tp->rcv_wnd += rx_credits;
1642 tp->rcv_adv += rx_credits;
1645 if (ulp_mode(toep) == ULP_MODE_TCPDDP && toep->ddp.waiting_count > 0 &&
1647 CTR2(KTR_CXGBE, "%s: tid %u queueing AIO task", __func__,
1649 ddp_queue_toep(toep);
1651 sorwakeup_locked(so);
1652 SOCKBUF_UNLOCK_ASSERT(sb);
1653 if (ulp_mode(toep) == ULP_MODE_TCPDDP)
1662 do_fw4_ack(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1664 struct adapter *sc = iq->adapter;
1665 const struct cpl_fw4_ack *cpl = (const void *)(rss + 1);
1666 unsigned int tid = G_CPL_FW4_ACK_FLOWID(be32toh(OPCODE_TID(cpl)));
1667 struct toepcb *toep = lookup_tid(sc, tid);
1671 uint8_t credits = cpl->credits;
1672 struct ofld_tx_sdesc *txsd;
1675 unsigned int opcode = G_CPL_FW4_ACK_OPCODE(be32toh(OPCODE_TID(cpl)));
1679 * Very unusual case: we'd sent a flowc + abort_req for a synq entry and
1680 * now this comes back carrying the credits for the flowc.
1682 if (__predict_false(toep->flags & TPF_SYNQE)) {
1683 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1684 ("%s: credits for a synq entry %p", __func__, toep));
1690 KASSERT(opcode == CPL_FW4_ACK,
1691 ("%s: unexpected opcode 0x%x", __func__, opcode));
1692 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1693 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1697 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN)) {
1702 KASSERT((inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) == 0,
1703 ("%s: inp_flags 0x%x", __func__, inp->inp_flags));
1705 tp = intotcpcb(inp);
1707 if (cpl->flags & CPL_FW4_ACK_FLAGS_SEQVAL) {
1708 tcp_seq snd_una = be32toh(cpl->snd_una);
1711 if (__predict_false(SEQ_LT(snd_una, tp->snd_una))) {
1713 "%s: unexpected seq# %x for TID %u, snd_una %x\n",
1714 __func__, snd_una, toep->tid, tp->snd_una);
1718 if (tp->snd_una != snd_una) {
1719 tp->snd_una = snd_una;
1720 tp->ts_recent_age = tcp_ts_getticks();
1724 #ifdef VERBOSE_TRACES
1725 CTR3(KTR_CXGBE, "%s: tid %d credits %u", __func__, tid, credits);
1727 so = inp->inp_socket;
1728 txsd = &toep->txsd[toep->txsd_cidx];
1731 KASSERT(credits >= txsd->tx_credits,
1732 ("%s: too many (or partial) credits", __func__));
1733 credits -= txsd->tx_credits;
1734 toep->tx_credits += txsd->tx_credits;
1736 if (txsd->iv_buffer) {
1737 free(txsd->iv_buffer, M_CXGBE);
1738 txsd->iv_buffer = NULL;
1742 KASSERT(toep->txsd_avail <= toep->txsd_total,
1743 ("%s: txsd avail > total", __func__));
1744 if (__predict_false(++toep->txsd_cidx == toep->txsd_total)) {
1745 txsd = &toep->txsd[0];
1746 toep->txsd_cidx = 0;
1750 if (toep->tx_credits == toep->tx_total) {
1751 toep->tx_nocompl = 0;
1752 toep->plen_nocompl = 0;
1755 if (toep->flags & TPF_TX_SUSPENDED &&
1756 toep->tx_credits >= toep->tx_total / 4) {
1757 #ifdef VERBOSE_TRACES
1758 CTR2(KTR_CXGBE, "%s: tid %d calling t4_push_frames", __func__,
1761 toep->flags &= ~TPF_TX_SUSPENDED;
1762 CURVNET_SET(toep->vnet);
1763 t4_push_data(sc, toep, plen);
1765 } else if (plen > 0) {
1766 struct sockbuf *sb = &so->so_snd;
1771 if (ulp_mode(toep) == ULP_MODE_ISCSI) {
1773 if (__predict_false(sbu > 0)) {
1775 * The data trasmitted before the tid's ULP mode
1776 * changed to ISCSI is still in so_snd.
1777 * Incoming credits should account for so_snd
1780 sbdrop_locked(sb, min(sbu, plen));
1781 plen -= min(sbu, plen);
1783 sowwakeup_locked(so); /* unlocks so_snd */
1784 rqdrop_locked(&toep->ulp_pdu_reclaimq, plen);
1786 #ifdef VERBOSE_TRACES
1787 CTR3(KTR_CXGBE, "%s: tid %d dropped %d bytes", __func__,
1790 sbdrop_locked(sb, plen);
1791 if (tls_tx_key(toep) &&
1792 toep->tls.mode == TLS_MODE_TLSOM) {
1793 struct tls_ofld_info *tls_ofld = &toep->tls;
1795 MPASS(tls_ofld->sb_off >= plen);
1796 tls_ofld->sb_off -= plen;
1798 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
1799 t4_aiotx_queue_toep(so, toep);
1800 sowwakeup_locked(so); /* unlocks so_snd */
1802 SOCKBUF_UNLOCK_ASSERT(sb);
1811 t4_set_tcb_field(struct adapter *sc, struct sge_wrq *wrq, struct toepcb *toep,
1812 uint16_t word, uint64_t mask, uint64_t val, int reply, int cookie)
1815 struct cpl_set_tcb_field *req;
1816 struct ofld_tx_sdesc *txsd;
1818 MPASS((cookie & ~M_COOKIE) == 0);
1820 MPASS(cookie != CPL_COOKIE_RESERVED);
1823 wr = alloc_wrqe(sizeof(*req), wrq);
1826 panic("%s: allocation failure.", __func__);
1830 INIT_TP_WR_MIT_CPL(req, CPL_SET_TCB_FIELD, toep->tid);
1831 req->reply_ctrl = htobe16(V_QUEUENO(toep->ofld_rxq->iq.abs_id));
1833 req->reply_ctrl |= htobe16(F_NO_REPLY);
1834 req->word_cookie = htobe16(V_WORD(word) | V_COOKIE(cookie));
1835 req->mask = htobe64(mask);
1836 req->val = htobe64(val);
1837 if ((wrq->eq.flags & EQ_TYPEMASK) == EQ_OFLD) {
1838 txsd = &toep->txsd[toep->txsd_pidx];
1839 txsd->tx_credits = howmany(sizeof(*req), 16);
1841 KASSERT(toep->tx_credits >= txsd->tx_credits &&
1842 toep->txsd_avail > 0,
1843 ("%s: not enough credits (%d)", __func__,
1845 toep->tx_credits -= txsd->tx_credits;
1846 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
1847 toep->txsd_pidx = 0;
1855 t4_init_cpl_io_handlers(void)
1858 t4_register_cpl_handler(CPL_PEER_CLOSE, do_peer_close);
1859 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, do_close_con_rpl);
1860 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, do_abort_req);
1861 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS, do_abort_rpl,
1863 t4_register_cpl_handler(CPL_RX_DATA, do_rx_data);
1864 t4_register_shared_cpl_handler(CPL_FW4_ACK, do_fw4_ack, CPL_COOKIE_TOM);
1868 t4_uninit_cpl_io_handlers(void)
1871 t4_register_cpl_handler(CPL_PEER_CLOSE, NULL);
1872 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, NULL);
1873 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, NULL);
1874 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS, NULL, CPL_COOKIE_TOM);
1875 t4_register_cpl_handler(CPL_RX_DATA, NULL);
1876 t4_register_shared_cpl_handler(CPL_FW4_ACK, NULL, CPL_COOKIE_TOM);
1880 * Use the 'backend1' field in AIO jobs to hold an error that should
1881 * be reported when the job is completed, the 'backend3' field to
1882 * store the amount of data sent by the AIO job so far, and the
1883 * 'backend4' field to hold a reference count on the job.
1885 * Each unmapped mbuf holds a reference on the job as does the queue
1886 * so long as the job is queued.
1888 #define aio_error backend1
1889 #define aio_sent backend3
1890 #define aio_refs backend4
1892 #define jobtotid(job) \
1893 (((struct toepcb *)(so_sototcpcb((job)->fd_file->f_data)->t_toe))->tid)
1896 aiotx_free_job(struct kaiocb *job)
1901 if (refcount_release(&job->aio_refs) == 0)
1904 error = (intptr_t)job->aio_error;
1905 status = job->aio_sent;
1906 #ifdef VERBOSE_TRACES
1907 CTR5(KTR_CXGBE, "%s: tid %d completed %p len %ld, error %d", __func__,
1908 jobtotid(job), job, status, error);
1910 if (error != 0 && status != 0)
1912 if (error == ECANCELED)
1915 aio_complete(job, -1, error);
1918 aio_complete(job, status, 0);
1923 aiotx_free_pgs(struct mbuf *m)
1925 struct mbuf_ext_pgs *ext_pgs;
1929 MBUF_EXT_PGS_ASSERT(m);
1930 ext_pgs = m->m_ext.ext_pgs;
1931 job = m->m_ext.ext_arg1;
1932 #ifdef VERBOSE_TRACES
1933 CTR3(KTR_CXGBE, "%s: completed %d bytes for tid %d", __func__,
1934 m->m_len, jobtotid(job));
1937 for (int i = 0; i < ext_pgs->npgs; i++) {
1938 pg = PHYS_TO_VM_PAGE(ext_pgs->pa[i]);
1939 vm_page_unwire(pg, PQ_ACTIVE);
1942 aiotx_free_job(job);
1946 * Allocate a chain of unmapped mbufs describing the next 'len' bytes
1949 static struct mbuf *
1950 alloc_aiotx_mbuf(struct kaiocb *job, int len)
1953 vm_page_t pgs[MBUF_PEXT_MAX_PGS];
1954 struct mbuf *m, *top, *last;
1955 struct mbuf_ext_pgs *ext_pgs;
1958 int i, mlen, npages, pgoff;
1960 KASSERT(job->aio_sent + len <= job->uaiocb.aio_nbytes,
1961 ("%s(%p, %d): request to send beyond end of buffer", __func__,
1965 * The AIO subsystem will cancel and drain all requests before
1966 * permitting a process to exit or exec, so p_vmspace should
1969 vm = job->userproc->p_vmspace;
1971 start = (uintptr_t)job->uaiocb.aio_buf + job->aio_sent;
1972 pgoff = start & PAGE_MASK;
1977 mlen = imin(len, MBUF_PEXT_MAX_PGS * PAGE_SIZE - pgoff);
1978 KASSERT(mlen == len || ((start + mlen) & PAGE_MASK) == 0,
1979 ("%s: next start (%#jx + %#x) is not page aligned",
1980 __func__, (uintmax_t)start, mlen));
1982 npages = vm_fault_quick_hold_pages(map, start, mlen,
1983 VM_PROT_WRITE, pgs, nitems(pgs));
1987 m = mb_alloc_ext_pgs(M_WAITOK, false, aiotx_free_pgs);
1989 vm_page_unhold_pages(pgs, npages);
1993 ext_pgs = m->m_ext.ext_pgs;
1994 ext_pgs->first_pg_off = pgoff;
1995 ext_pgs->npgs = npages;
1997 KASSERT(mlen + pgoff <= PAGE_SIZE,
1998 ("%s: single page is too large (off %d len %d)",
1999 __func__, pgoff, mlen));
2000 ext_pgs->last_pg_len = mlen;
2002 ext_pgs->last_pg_len = mlen - (PAGE_SIZE - pgoff) -
2003 (npages - 2) * PAGE_SIZE;
2005 for (i = 0; i < npages; i++)
2006 ext_pgs->pa[i] = VM_PAGE_TO_PHYS(pgs[i]);
2009 m->m_ext.ext_size = npages * PAGE_SIZE;
2010 m->m_ext.ext_arg1 = job;
2011 refcount_acquire(&job->aio_refs);
2013 #ifdef VERBOSE_TRACES
2014 CTR5(KTR_CXGBE, "%s: tid %d, new mbuf %p for job %p, npages %d",
2015 __func__, jobtotid(job), m, job, npages);
2033 t4_aiotx_process_job(struct toepcb *toep, struct socket *so, struct kaiocb *job)
2041 bool moretocome, sendmore;
2049 error = mac_socket_check_send(fp->f_cred, so);
2054 /* Inline sosend_generic(). */
2056 error = sblock(sb, SBL_WAIT);
2061 if (so->so_snd.sb_state & SBS_CANTSENDMORE) {
2064 if ((so->so_options & SO_NOSIGPIPE) == 0) {
2065 PROC_LOCK(job->userproc);
2066 kern_psignal(job->userproc, SIGPIPE);
2067 PROC_UNLOCK(job->userproc);
2073 error = so->so_error;
2079 if ((so->so_state & SS_ISCONNECTED) == 0) {
2085 if (sbspace(sb) < sb->sb_lowat) {
2086 MPASS(job->aio_sent == 0 || !(so->so_state & SS_NBIO));
2089 * Don't block if there is too little room in the socket
2090 * buffer. Instead, requeue the request.
2092 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2098 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2105 * Write as much data as the socket permits, but no more than a
2106 * a single sndbuf at a time.
2109 if (len > job->uaiocb.aio_nbytes - job->aio_sent) {
2110 len = job->uaiocb.aio_nbytes - job->aio_sent;
2114 if (len > toep->params.sndbuf) {
2115 len = toep->params.sndbuf;
2120 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
2125 m = alloc_aiotx_mbuf(job, len);
2132 /* Inlined tcp_usr_send(). */
2136 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
2143 job->aio_sent += m_length(m, NULL);
2145 sbappendstream(sb, m, 0);
2148 if (!(inp->inp_flags & INP_DROPPED)) {
2149 tp = intotcpcb(inp);
2151 tp->t_flags |= TF_MORETOCOME;
2152 error = tp->t_fb->tfb_tcp_output(tp);
2154 tp->t_flags &= ~TF_MORETOCOME;
2166 * If this is a blocking socket and the request has not been
2167 * fully completed, requeue it until the socket is ready
2170 if (job->aio_sent < job->uaiocb.aio_nbytes &&
2171 !(so->so_state & SS_NBIO)) {
2173 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2178 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2183 * If the request will not be requeued, drop the queue's
2184 * reference to the job. Any mbufs in flight should still
2185 * hold a reference, but this drops the reference that the
2186 * queue owns while it is waiting to queue mbufs to the
2189 aiotx_free_job(job);
2193 job->aio_error = (void *)(intptr_t)error;
2194 aiotx_free_job(job);
2202 t4_aiotx_task(void *context, int pending)
2204 struct toepcb *toep = context;
2208 so = toep->aiotx_so;
2209 CURVNET_SET(toep->vnet);
2210 SOCKBUF_LOCK(&so->so_snd);
2211 while (!TAILQ_EMPTY(&toep->aiotx_jobq) && sowriteable(so)) {
2212 job = TAILQ_FIRST(&toep->aiotx_jobq);
2213 TAILQ_REMOVE(&toep->aiotx_jobq, job, list);
2214 if (!aio_clear_cancel_function(job))
2217 t4_aiotx_process_job(toep, so, job);
2219 toep->aiotx_so = NULL;
2220 SOCKBUF_UNLOCK(&so->so_snd);
2229 t4_aiotx_queue_toep(struct socket *so, struct toepcb *toep)
2232 SOCKBUF_LOCK_ASSERT(&toep->inp->inp_socket->so_snd);
2233 #ifdef VERBOSE_TRACES
2234 CTR3(KTR_CXGBE, "%s: queueing aiotx task for tid %d, active = %s",
2235 __func__, toep->tid, toep->aiotx_so != NULL ? "true" : "false");
2237 if (toep->aiotx_so != NULL)
2240 toep->aiotx_so = so;
2242 soaio_enqueue(&toep->aiotx_task);
2246 t4_aiotx_cancel(struct kaiocb *job)
2251 struct toepcb *toep;
2253 so = job->fd_file->f_data;
2254 tp = so_sototcpcb(so);
2256 MPASS(job->uaiocb.aio_lio_opcode == LIO_WRITE);
2260 if (!aio_cancel_cleared(job))
2261 TAILQ_REMOVE(&toep->aiotx_jobq, job, list);
2264 job->aio_error = (void *)(intptr_t)ECANCELED;
2265 aiotx_free_job(job);
2269 t4_aio_queue_aiotx(struct socket *so, struct kaiocb *job)
2271 struct tcpcb *tp = so_sototcpcb(so);
2272 struct toepcb *toep = tp->t_toe;
2273 struct adapter *sc = td_adapter(toep->td);
2275 /* This only handles writes. */
2276 if (job->uaiocb.aio_lio_opcode != LIO_WRITE)
2277 return (EOPNOTSUPP);
2279 if (!sc->tt.tx_zcopy)
2280 return (EOPNOTSUPP);
2282 if (tls_tx_key(toep))
2283 return (EOPNOTSUPP);
2285 SOCKBUF_LOCK(&so->so_snd);
2286 #ifdef VERBOSE_TRACES
2287 CTR3(KTR_CXGBE, "%s: queueing %p for tid %u", __func__, job, toep->tid);
2289 if (!aio_set_cancel_function(job, t4_aiotx_cancel))
2290 panic("new job was cancelled");
2291 refcount_init(&job->aio_refs, 1);
2292 TAILQ_INSERT_TAIL(&toep->aiotx_jobq, job, list);
2293 if (sowriteable(so))
2294 t4_aiotx_queue_toep(so, toep);
2295 SOCKBUF_UNLOCK(&so->so_snd);
2300 aiotx_init_toep(struct toepcb *toep)
2303 TAILQ_INIT(&toep->aiotx_jobq);
2304 TASK_INIT(&toep->aiotx_task, 0, t4_aiotx_task, toep);