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);
138 FLOWC_PARAM(MSS, toep->params.emss);
140 FLOWC_PARAM(SNDNXT, tp->snd_nxt);
141 FLOWC_PARAM(RCVNXT, tp->rcv_nxt);
144 "%s: tid %u, mss %u, sndbuf %u, snd_nxt 0x%x, rcv_nxt 0x%x",
145 __func__, toep->tid, toep->params.emss, toep->params.sndbuf,
146 tp ? tp->snd_nxt : 0, tp ? tp->rcv_nxt : 0);
148 if (ulp_mode(toep) == ULP_MODE_TLS)
149 FLOWC_PARAM(ULP_MODE, ulp_mode(toep));
150 if (toep->tls.fcplenmax != 0)
151 FLOWC_PARAM(TXDATAPLEN_MAX, toep->tls.fcplenmax);
152 if (toep->params.tc_idx != -1)
153 FLOWC_PARAM(SCHEDCLASS, toep->params.tc_idx);
156 KASSERT(paramidx == nparams, ("nparams mismatch"));
158 txsd->tx_credits = howmany(flowclen, 16);
160 KASSERT(toep->tx_credits >= txsd->tx_credits && toep->txsd_avail > 0,
161 ("%s: not enough credits (%d)", __func__, toep->tx_credits));
162 toep->tx_credits -= txsd->tx_credits;
163 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
167 toep->flags |= TPF_FLOWC_WR_SENT;
173 * Input is Bytes/second (so_max_pacing_rate), chip counts in Kilobits/second.
176 update_tx_rate_limit(struct adapter *sc, struct toepcb *toep, u_int Bps)
179 const u_int kbps = (u_int) (uint64_t)Bps * 8ULL / 1000;
180 const int port_id = toep->vi->pi->port_id;
182 CTR3(KTR_CXGBE, "%s: tid %u, rate %uKbps", __func__, toep->tid, kbps);
188 rc = t4_reserve_cl_rl_kbps(sc, port_id, kbps, &tc_idx);
191 MPASS(tc_idx >= 0 && tc_idx < sc->chip_params->nsched_cls);
194 if (toep->params.tc_idx != tc_idx) {
196 struct fw_flowc_wr *flowc;
197 int nparams = 1, flowclen, flowclen16;
198 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
200 flowclen = sizeof(*flowc) + nparams * sizeof(struct
202 flowclen16 = howmany(flowclen, 16);
203 if (toep->tx_credits < flowclen16 || toep->txsd_avail == 0 ||
204 (wr = alloc_wrqe(roundup2(flowclen, 16), toep->ofld_txq)) == NULL) {
206 t4_release_cl_rl(sc, port_id, tc_idx);
211 memset(flowc, 0, wr->wr_len);
213 flowc->op_to_nparams = htobe32(V_FW_WR_OP(FW_FLOWC_WR) |
214 V_FW_FLOWC_WR_NPARAMS(nparams));
215 flowc->flowid_len16 = htonl(V_FW_WR_LEN16(flowclen16) |
216 V_FW_WR_FLOWID(toep->tid));
218 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
220 flowc->mnemval[0].val = htobe32(0xff);
222 flowc->mnemval[0].val = htobe32(tc_idx);
224 txsd->tx_credits = flowclen16;
226 toep->tx_credits -= txsd->tx_credits;
227 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
233 if (toep->params.tc_idx >= 0)
234 t4_release_cl_rl(sc, port_id, toep->params.tc_idx);
235 toep->params.tc_idx = tc_idx;
242 send_reset(struct adapter *sc, struct toepcb *toep, uint32_t snd_nxt)
245 struct cpl_abort_req *req;
247 struct inpcb *inp = toep->inp;
248 struct tcpcb *tp = intotcpcb(inp); /* don't use if INP_DROPPED */
250 INP_WLOCK_ASSERT(inp);
252 CTR6(KTR_CXGBE, "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x%s",
254 inp->inp_flags & INP_DROPPED ? "inp dropped" :
255 tcpstates[tp->t_state],
256 toep->flags, inp->inp_flags,
257 toep->flags & TPF_ABORT_SHUTDOWN ?
258 " (abort already in progress)" : "");
260 if (toep->flags & TPF_ABORT_SHUTDOWN)
261 return; /* abort already in progress */
263 toep->flags |= TPF_ABORT_SHUTDOWN;
265 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
266 ("%s: flowc_wr not sent for tid %d.", __func__, tid));
268 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
271 panic("%s: allocation failure.", __func__);
275 INIT_TP_WR_MIT_CPL(req, CPL_ABORT_REQ, tid);
276 if (inp->inp_flags & INP_DROPPED)
277 req->rsvd0 = htobe32(snd_nxt);
279 req->rsvd0 = htobe32(tp->snd_nxt);
280 req->rsvd1 = !(toep->flags & TPF_TX_DATA_SENT);
281 req->cmd = CPL_ABORT_SEND_RST;
284 * XXX: What's the correct way to tell that the inp hasn't been detached
285 * from its socket? Should I even be flushing the snd buffer here?
287 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
288 struct socket *so = inp->inp_socket;
290 if (so != NULL) /* because I'm not sure. See comment above */
291 sbflush(&so->so_snd);
294 t4_l2t_send(sc, wr, toep->l2te);
298 * Called when a connection is established to translate the TCP options
299 * reported by HW to FreeBSD's native format.
302 assign_rxopt(struct tcpcb *tp, uint16_t opt)
304 struct toepcb *toep = tp->t_toe;
305 struct inpcb *inp = tp->t_inpcb;
306 struct adapter *sc = td_adapter(toep->td);
308 INP_LOCK_ASSERT(inp);
310 toep->params.mtu_idx = G_TCPOPT_MSS(opt);
311 tp->t_maxseg = sc->params.mtus[toep->params.mtu_idx];
312 if (inp->inp_inc.inc_flags & INC_ISIPV6)
313 tp->t_maxseg -= sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
315 tp->t_maxseg -= sizeof(struct ip) + sizeof(struct tcphdr);
317 toep->params.emss = tp->t_maxseg;
318 if (G_TCPOPT_TSTAMP(opt)) {
319 toep->params.tstamp = 1;
320 toep->params.emss -= TCPOLEN_TSTAMP_APPA;
321 tp->t_flags |= TF_RCVD_TSTMP; /* timestamps ok */
322 tp->ts_recent = 0; /* hmmm */
323 tp->ts_recent_age = tcp_ts_getticks();
325 toep->params.tstamp = 0;
327 if (G_TCPOPT_SACK(opt)) {
328 toep->params.sack = 1;
329 tp->t_flags |= TF_SACK_PERMIT; /* should already be set */
331 toep->params.sack = 0;
332 tp->t_flags &= ~TF_SACK_PERMIT; /* sack disallowed by peer */
335 if (G_TCPOPT_WSCALE_OK(opt))
336 tp->t_flags |= TF_RCVD_SCALE;
338 /* Doing window scaling? */
339 if ((tp->t_flags & (TF_RCVD_SCALE | TF_REQ_SCALE)) ==
340 (TF_RCVD_SCALE | TF_REQ_SCALE)) {
341 tp->rcv_scale = tp->request_r_scale;
342 tp->snd_scale = G_TCPOPT_SND_WSCALE(opt);
344 toep->params.wscale = 0;
347 "assign_rxopt: tid %d, mtu_idx %u, emss %u, ts %u, sack %u, wscale %u",
348 toep->tid, toep->params.mtu_idx, toep->params.emss,
349 toep->params.tstamp, toep->params.sack, toep->params.wscale);
353 * Completes some final bits of initialization for just established connections
354 * and changes their state to TCPS_ESTABLISHED.
356 * The ISNs are from the exchange of SYNs.
359 make_established(struct toepcb *toep, uint32_t iss, uint32_t irs, uint16_t opt)
361 struct inpcb *inp = toep->inp;
362 struct socket *so = inp->inp_socket;
363 struct tcpcb *tp = intotcpcb(inp);
364 uint16_t tcpopt = be16toh(opt);
366 INP_WLOCK_ASSERT(inp);
367 KASSERT(tp->t_state == TCPS_SYN_SENT ||
368 tp->t_state == TCPS_SYN_RECEIVED,
369 ("%s: TCP state %s", __func__, tcpstates[tp->t_state]));
371 CTR6(KTR_CXGBE, "%s: tid %d, so %p, inp %p, tp %p, toep %p",
372 __func__, toep->tid, so, inp, tp, toep);
374 tcp_state_change(tp, TCPS_ESTABLISHED);
375 tp->t_starttime = ticks;
376 TCPSTAT_INC(tcps_connects);
380 tp->rcv_wnd = (u_int)toep->params.opt0_bufsize << 10;
381 tp->rcv_adv += tp->rcv_wnd;
382 tp->last_ack_sent = tp->rcv_nxt;
386 tp->snd_una = iss + 1;
387 tp->snd_nxt = iss + 1;
388 tp->snd_max = iss + 1;
390 assign_rxopt(tp, tcpopt);
391 send_flowc_wr(toep, tp);
397 send_rx_credits(struct adapter *sc, struct toepcb *toep, int credits)
400 struct cpl_rx_data_ack *req;
401 uint32_t dack = F_RX_DACK_CHANGE | V_RX_DACK_MODE(1);
403 KASSERT(credits >= 0, ("%s: %d credits", __func__, credits));
405 wr = alloc_wrqe(sizeof(*req), toep->ctrlq);
410 INIT_TP_WR_MIT_CPL(req, CPL_RX_DATA_ACK, toep->tid);
411 req->credit_dack = htobe32(dack | V_RX_CREDITS(credits));
418 send_rx_modulate(struct adapter *sc, struct toepcb *toep)
421 struct cpl_rx_data_ack *req;
423 wr = alloc_wrqe(sizeof(*req), toep->ctrlq);
428 INIT_TP_WR_MIT_CPL(req, CPL_RX_DATA_ACK, toep->tid);
429 req->credit_dack = htobe32(F_RX_MODULATE_RX);
435 t4_rcvd_locked(struct toedev *tod, struct tcpcb *tp)
437 struct adapter *sc = tod->tod_softc;
438 struct inpcb *inp = tp->t_inpcb;
439 struct socket *so = inp->inp_socket;
440 struct sockbuf *sb = &so->so_rcv;
441 struct toepcb *toep = tp->t_toe;
444 INP_WLOCK_ASSERT(inp);
445 SOCKBUF_LOCK_ASSERT(sb);
447 rx_credits = sbspace(sb) > tp->rcv_wnd ? sbspace(sb) - tp->rcv_wnd : 0;
448 if (ulp_mode(toep) == ULP_MODE_TLS) {
449 if (toep->tls.rcv_over >= rx_credits) {
450 toep->tls.rcv_over -= rx_credits;
453 rx_credits -= toep->tls.rcv_over;
454 toep->tls.rcv_over = 0;
458 if (rx_credits > 0 &&
459 (tp->rcv_wnd <= 32 * 1024 || rx_credits >= 64 * 1024 ||
460 (rx_credits >= 16 * 1024 && tp->rcv_wnd <= 128 * 1024) ||
461 sbused(sb) + tp->rcv_wnd < sb->sb_lowat)) {
462 rx_credits = send_rx_credits(sc, toep, rx_credits);
463 tp->rcv_wnd += rx_credits;
464 tp->rcv_adv += rx_credits;
465 } else if (toep->flags & TPF_FORCE_CREDITS)
466 send_rx_modulate(sc, toep);
470 t4_rcvd(struct toedev *tod, struct tcpcb *tp)
472 struct inpcb *inp = tp->t_inpcb;
473 struct socket *so = inp->inp_socket;
474 struct sockbuf *sb = &so->so_rcv;
477 t4_rcvd_locked(tod, tp);
482 * Close a connection by sending a CPL_CLOSE_CON_REQ message.
485 t4_close_conn(struct adapter *sc, struct toepcb *toep)
488 struct cpl_close_con_req *req;
489 unsigned int tid = toep->tid;
491 CTR3(KTR_CXGBE, "%s: tid %u%s", __func__, toep->tid,
492 toep->flags & TPF_FIN_SENT ? ", IGNORED" : "");
494 if (toep->flags & TPF_FIN_SENT)
497 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
498 ("%s: flowc_wr not sent for tid %u.", __func__, tid));
500 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
503 panic("%s: allocation failure.", __func__);
507 req->wr.wr_hi = htonl(V_FW_WR_OP(FW_TP_WR) |
508 V_FW_WR_IMMDLEN(sizeof(*req) - sizeof(req->wr)));
509 req->wr.wr_mid = htonl(V_FW_WR_LEN16(howmany(sizeof(*req), 16)) |
510 V_FW_WR_FLOWID(tid));
511 req->wr.wr_lo = cpu_to_be64(0);
512 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
515 toep->flags |= TPF_FIN_SENT;
516 toep->flags &= ~TPF_SEND_FIN;
517 t4_l2t_send(sc, wr, toep->l2te);
522 #define MAX_OFLD_TX_CREDITS (SGE_MAX_WR_LEN / 16)
523 #define MIN_OFLD_TX_CREDITS (howmany(sizeof(struct fw_ofld_tx_data_wr) + 1, 16))
525 /* Maximum amount of immediate data we could stuff in a WR */
527 max_imm_payload(int tx_credits)
529 const int n = 1; /* Use no more than one desc for imm. data WR */
531 KASSERT(tx_credits >= 0 &&
532 tx_credits <= MAX_OFLD_TX_CREDITS,
533 ("%s: %d credits", __func__, tx_credits));
535 if (tx_credits < MIN_OFLD_TX_CREDITS)
538 if (tx_credits >= (n * EQ_ESIZE) / 16)
539 return ((n * EQ_ESIZE) - sizeof(struct fw_ofld_tx_data_wr));
541 return (tx_credits * 16 - sizeof(struct fw_ofld_tx_data_wr));
544 /* Maximum number of SGL entries we could stuff in a WR */
546 max_dsgl_nsegs(int tx_credits)
548 int nseg = 1; /* ulptx_sgl has room for 1, rest ulp_tx_sge_pair */
549 int sge_pair_credits = tx_credits - MIN_OFLD_TX_CREDITS;
551 KASSERT(tx_credits >= 0 &&
552 tx_credits <= MAX_OFLD_TX_CREDITS,
553 ("%s: %d credits", __func__, tx_credits));
555 if (tx_credits < MIN_OFLD_TX_CREDITS)
558 nseg += 2 * (sge_pair_credits * 16 / 24);
559 if ((sge_pair_credits * 16) % 24 == 16)
566 write_tx_wr(void *dst, struct toepcb *toep, unsigned int immdlen,
567 unsigned int plen, uint8_t credits, int shove, int ulp_submode)
569 struct fw_ofld_tx_data_wr *txwr = dst;
571 txwr->op_to_immdlen = htobe32(V_WR_OP(FW_OFLD_TX_DATA_WR) |
572 V_FW_WR_IMMDLEN(immdlen));
573 txwr->flowid_len16 = htobe32(V_FW_WR_FLOWID(toep->tid) |
574 V_FW_WR_LEN16(credits));
575 txwr->lsodisable_to_flags = htobe32(V_TX_ULP_MODE(ulp_mode(toep)) |
576 V_TX_ULP_SUBMODE(ulp_submode) | V_TX_URG(0) | V_TX_SHOVE(shove));
577 txwr->plen = htobe32(plen);
579 if (toep->params.tx_align > 0) {
580 if (plen < 2 * toep->params.emss)
581 txwr->lsodisable_to_flags |=
582 htobe32(F_FW_OFLD_TX_DATA_WR_LSODISABLE);
584 txwr->lsodisable_to_flags |=
585 htobe32(F_FW_OFLD_TX_DATA_WR_ALIGNPLD |
586 (toep->params.nagle == 0 ? 0 :
587 F_FW_OFLD_TX_DATA_WR_ALIGNPLDSHOVE));
592 * Generate a DSGL from a starting mbuf. The total number of segments and the
593 * maximum segments in any one mbuf are provided.
596 write_tx_sgl(void *dst, struct mbuf *start, struct mbuf *stop, int nsegs, int n)
599 struct ulptx_sgl *usgl = dst;
602 struct sglist_seg segs[n];
604 KASSERT(nsegs > 0, ("%s: nsegs 0", __func__));
606 sglist_init(&sg, n, segs);
607 usgl->cmd_nsge = htobe32(V_ULPTX_CMD(ULP_TX_SC_DSGL) |
608 V_ULPTX_NSGE(nsegs));
611 for (m = start; m != stop; m = m->m_next) {
612 if (m->m_flags & M_NOMAP)
613 rc = sglist_append_mb_ext_pgs(&sg, m);
615 rc = sglist_append(&sg, mtod(m, void *), m->m_len);
616 if (__predict_false(rc != 0))
617 panic("%s: sglist_append %d", __func__, rc);
619 for (j = 0; j < sg.sg_nseg; i++, j++) {
621 usgl->len0 = htobe32(segs[j].ss_len);
622 usgl->addr0 = htobe64(segs[j].ss_paddr);
624 usgl->sge[i / 2].len[i & 1] =
625 htobe32(segs[j].ss_len);
626 usgl->sge[i / 2].addr[i & 1] =
627 htobe64(segs[j].ss_paddr);
636 usgl->sge[i / 2].len[1] = htobe32(0);
637 KASSERT(nsegs == 0, ("%s: nsegs %d, start %p, stop %p",
638 __func__, nsegs, start, stop));
642 * Max number of SGL entries an offload tx work request can have. This is 41
643 * (1 + 40) for a full 512B work request.
644 * fw_ofld_tx_data_wr(16B) + ulptx_sgl(16B, 1) + ulptx_sge_pair(480B, 40)
646 #define OFLD_SGL_LEN (41)
649 * Send data and/or a FIN to the peer.
651 * The socket's so_snd buffer consists of a stream of data starting with sb_mb
652 * and linked together with m_next. sb_sndptr, if set, is the last mbuf that
655 * drop indicates the number of bytes that should be dropped from the head of
656 * the send buffer. It is an optimization that lets do_fw4_ack avoid creating
657 * contention on the send buffer lock (before this change it used to do
658 * sowwakeup and then t4_push_frames right after that when recovering from tx
659 * stalls). When drop is set this function MUST drop the bytes and wake up any
663 t4_push_frames(struct adapter *sc, struct toepcb *toep, int drop)
665 struct mbuf *sndptr, *m, *sb_sndptr;
666 struct fw_ofld_tx_data_wr *txwr;
668 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
669 struct inpcb *inp = toep->inp;
670 struct tcpcb *tp = intotcpcb(inp);
671 struct socket *so = inp->inp_socket;
672 struct sockbuf *sb = &so->so_snd;
673 int tx_credits, shove, compl, sowwakeup;
674 struct ofld_tx_sdesc *txsd;
675 bool nomap_mbuf_seen;
677 INP_WLOCK_ASSERT(inp);
678 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
679 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
681 KASSERT(ulp_mode(toep) == ULP_MODE_NONE ||
682 ulp_mode(toep) == ULP_MODE_TCPDDP ||
683 ulp_mode(toep) == ULP_MODE_TLS ||
684 ulp_mode(toep) == ULP_MODE_RDMA,
685 ("%s: ulp_mode %u for toep %p", __func__, ulp_mode(toep), toep));
687 #ifdef VERBOSE_TRACES
688 CTR5(KTR_CXGBE, "%s: tid %d toep flags %#x tp flags %#x drop %d",
689 __func__, toep->tid, toep->flags, tp->t_flags, drop);
691 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
695 if (__predict_false(inp->inp_flags2 & INP_RATE_LIMIT_CHANGED) &&
696 (update_tx_rate_limit(sc, toep, so->so_max_pacing_rate) == 0)) {
697 inp->inp_flags2 &= ~INP_RATE_LIMIT_CHANGED;
702 * This function doesn't resume by itself. Someone else must clear the
703 * flag and call this function.
705 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
707 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
711 txsd = &toep->txsd[toep->txsd_pidx];
713 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
714 max_imm = max_imm_payload(tx_credits);
715 max_nsegs = max_dsgl_nsegs(tx_credits);
720 sbdrop_locked(sb, drop);
723 sb_sndptr = sb->sb_sndptr;
724 sndptr = sb_sndptr ? sb_sndptr->m_next : sb->sb_mb;
727 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
728 nomap_mbuf_seen = false;
729 for (m = sndptr; m != NULL; m = m->m_next) {
732 if (m->m_flags & M_NOMAP) {
734 if (m->m_ext.ext_pgs->tls != NULL) {
735 toep->flags |= TPF_KTLS;
738 t4_push_ktls(sc, toep, 0);
744 n = sglist_count_mb_ext_pgs(m);
746 n = sglist_count(mtod(m, void *), m->m_len);
751 /* This mbuf sent us _over_ the nsegs limit, back out */
752 if (plen > max_imm && nsegs > max_nsegs) {
756 /* Too few credits */
757 toep->flags |= TPF_TX_SUSPENDED;
761 t4_aiotx_queue_toep(so,
763 sowwakeup_locked(so);
766 SOCKBUF_UNLOCK_ASSERT(sb);
772 if (m->m_flags & M_NOMAP)
773 nomap_mbuf_seen = true;
774 if (max_nsegs_1mbuf < n)
776 sb_sndptr = m; /* new sb->sb_sndptr if all goes well */
778 /* This mbuf put us right at the max_nsegs limit */
779 if (plen > max_imm && nsegs == max_nsegs) {
785 if (sbused(sb) > sb->sb_hiwat * 5 / 8 &&
786 toep->plen_nocompl + plen >= sb->sb_hiwat / 4)
791 if (sb->sb_flags & SB_AUTOSIZE &&
792 V_tcp_do_autosndbuf &&
793 sb->sb_hiwat < V_tcp_autosndbuf_max &&
794 sbused(sb) >= sb->sb_hiwat * 7 / 8) {
795 int newsize = min(sb->sb_hiwat + V_tcp_autosndbuf_inc,
796 V_tcp_autosndbuf_max);
798 if (!sbreserve_locked(sb, newsize, so, NULL))
799 sb->sb_flags &= ~SB_AUTOSIZE;
801 sowwakeup = 1; /* room available */
804 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
805 t4_aiotx_queue_toep(so, toep);
806 sowwakeup_locked(so);
809 SOCKBUF_UNLOCK_ASSERT(sb);
811 /* nothing to send */
814 ("%s: nothing to send, but m != NULL", __func__));
818 if (__predict_false(toep->flags & TPF_FIN_SENT))
819 panic("%s: excess tx.", __func__);
821 shove = m == NULL && !(tp->t_flags & TF_MORETOCOME);
822 if (plen <= max_imm && !nomap_mbuf_seen) {
824 /* Immediate data tx */
826 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
829 /* XXX: how will we recover from this? */
830 toep->flags |= TPF_TX_SUSPENDED;
834 credits = howmany(wr->wr_len, 16);
835 write_tx_wr(txwr, toep, plen, plen, credits, shove, 0);
836 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
843 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
844 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
845 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
847 /* XXX: how will we recover from this? */
848 toep->flags |= TPF_TX_SUSPENDED;
852 credits = howmany(wr_len, 16);
853 write_tx_wr(txwr, toep, 0, plen, credits, shove, 0);
854 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
857 uint64_t *pad = (uint64_t *)
858 ((uintptr_t)txwr + wr_len);
863 KASSERT(toep->tx_credits >= credits,
864 ("%s: not enough credits", __func__));
866 toep->tx_credits -= credits;
867 toep->tx_nocompl += credits;
868 toep->plen_nocompl += plen;
869 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
870 toep->tx_nocompl >= toep->tx_total / 4)
873 if (compl || ulp_mode(toep) == ULP_MODE_RDMA) {
874 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
875 toep->tx_nocompl = 0;
876 toep->plen_nocompl = 0;
883 KASSERT(sb_sndptr, ("%s: sb_sndptr is NULL", __func__));
884 sb->sb_sndptr = sb_sndptr;
887 toep->flags |= TPF_TX_DATA_SENT;
888 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
889 toep->flags |= TPF_TX_SUSPENDED;
891 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
893 txsd->tx_credits = credits;
895 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
897 txsd = &toep->txsd[0];
901 t4_l2t_send(sc, wr, toep->l2te);
904 /* Send a FIN if requested, but only if there's no more data to send */
905 if (m == NULL && toep->flags & TPF_SEND_FIN)
906 t4_close_conn(sc, toep);
910 rqdrop_locked(struct mbufq *q, int plen)
915 m = mbufq_dequeue(q);
917 /* Too many credits. */
921 /* Partial credits. */
922 MPASS(plen >= m->m_pkthdr.len);
924 plen -= m->m_pkthdr.len;
930 t4_push_pdus(struct adapter *sc, struct toepcb *toep, int drop)
932 struct mbuf *sndptr, *m;
933 struct fw_ofld_tx_data_wr *txwr;
935 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
936 u_int adjusted_plen, ulp_submode;
937 struct inpcb *inp = toep->inp;
938 struct tcpcb *tp = intotcpcb(inp);
939 int tx_credits, shove;
940 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
941 struct mbufq *pduq = &toep->ulp_pduq;
942 static const u_int ulp_extra_len[] = {0, 4, 4, 8};
944 INP_WLOCK_ASSERT(inp);
945 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
946 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
947 KASSERT(ulp_mode(toep) == ULP_MODE_ISCSI,
948 ("%s: ulp_mode %u for toep %p", __func__, ulp_mode(toep), toep));
950 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
954 * This function doesn't resume by itself. Someone else must clear the
955 * flag and call this function.
957 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
959 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
964 rqdrop_locked(&toep->ulp_pdu_reclaimq, drop);
966 while ((sndptr = mbufq_first(pduq)) != NULL) {
967 M_ASSERTPKTHDR(sndptr);
969 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
970 max_imm = max_imm_payload(tx_credits);
971 max_nsegs = max_dsgl_nsegs(tx_credits);
975 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
976 for (m = sndptr; m != NULL; m = m->m_next) {
977 int n = sglist_count(mtod(m, void *), m->m_len);
983 * This mbuf would send us _over_ the nsegs limit.
984 * Suspend tx because the PDU can't be sent out.
986 if (plen > max_imm && nsegs > max_nsegs) {
987 toep->flags |= TPF_TX_SUSPENDED;
991 if (max_nsegs_1mbuf < n)
995 if (__predict_false(toep->flags & TPF_FIN_SENT))
996 panic("%s: excess tx.", __func__);
999 * We have a PDU to send. All of it goes out in one WR so 'm'
1000 * is NULL. A PDU's length is always a multiple of 4.
1003 MPASS((plen & 3) == 0);
1004 MPASS(sndptr->m_pkthdr.len == plen);
1006 shove = !(tp->t_flags & TF_MORETOCOME);
1007 ulp_submode = mbuf_ulp_submode(sndptr);
1008 MPASS(ulp_submode < nitems(ulp_extra_len));
1011 * plen doesn't include header and data digests, which are
1012 * generated and inserted in the right places by the TOE, but
1013 * they do occupy TCP sequence space and need to be accounted
1016 adjusted_plen = plen + ulp_extra_len[ulp_submode];
1017 if (plen <= max_imm) {
1019 /* Immediate data tx */
1021 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
1024 /* XXX: how will we recover from this? */
1025 toep->flags |= TPF_TX_SUSPENDED;
1029 credits = howmany(wr->wr_len, 16);
1030 write_tx_wr(txwr, toep, plen, adjusted_plen, credits,
1031 shove, ulp_submode);
1032 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
1038 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
1039 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
1040 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
1042 /* XXX: how will we recover from this? */
1043 toep->flags |= TPF_TX_SUSPENDED;
1047 credits = howmany(wr_len, 16);
1048 write_tx_wr(txwr, toep, 0, adjusted_plen, credits,
1049 shove, ulp_submode);
1050 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
1053 uint64_t *pad = (uint64_t *)
1054 ((uintptr_t)txwr + wr_len);
1059 KASSERT(toep->tx_credits >= credits,
1060 ("%s: not enough credits", __func__));
1062 m = mbufq_dequeue(pduq);
1064 mbufq_enqueue(&toep->ulp_pdu_reclaimq, m);
1066 toep->tx_credits -= credits;
1067 toep->tx_nocompl += credits;
1068 toep->plen_nocompl += plen;
1069 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
1070 toep->tx_nocompl >= toep->tx_total / 4) {
1071 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
1072 toep->tx_nocompl = 0;
1073 toep->plen_nocompl = 0;
1076 tp->snd_nxt += adjusted_plen;
1077 tp->snd_max += adjusted_plen;
1079 toep->flags |= TPF_TX_DATA_SENT;
1080 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
1081 toep->flags |= TPF_TX_SUSPENDED;
1083 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
1085 txsd->tx_credits = credits;
1087 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
1088 toep->txsd_pidx = 0;
1089 txsd = &toep->txsd[0];
1093 t4_l2t_send(sc, wr, toep->l2te);
1096 /* Send a FIN if requested, but only if there are no more PDUs to send */
1097 if (mbufq_first(pduq) == NULL && toep->flags & TPF_SEND_FIN)
1098 t4_close_conn(sc, toep);
1102 t4_push_data(struct adapter *sc, struct toepcb *toep, int drop)
1105 if (ulp_mode(toep) == ULP_MODE_ISCSI)
1106 t4_push_pdus(sc, toep, drop);
1107 else if (tls_tx_key(toep) && toep->tls.mode == TLS_MODE_TLSOM)
1108 t4_push_tls_records(sc, toep, drop);
1110 else if (toep->flags & TPF_KTLS)
1111 t4_push_ktls(sc, toep, drop);
1114 t4_push_frames(sc, toep, drop);
1118 t4_tod_output(struct toedev *tod, struct tcpcb *tp)
1120 struct adapter *sc = tod->tod_softc;
1122 struct inpcb *inp = tp->t_inpcb;
1124 struct toepcb *toep = tp->t_toe;
1126 INP_WLOCK_ASSERT(inp);
1127 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1128 ("%s: inp %p dropped.", __func__, inp));
1129 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1131 t4_push_data(sc, toep, 0);
1137 t4_send_fin(struct toedev *tod, struct tcpcb *tp)
1139 struct adapter *sc = tod->tod_softc;
1141 struct inpcb *inp = tp->t_inpcb;
1143 struct toepcb *toep = tp->t_toe;
1145 INP_WLOCK_ASSERT(inp);
1146 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1147 ("%s: inp %p dropped.", __func__, inp));
1148 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1150 toep->flags |= TPF_SEND_FIN;
1151 if (tp->t_state >= TCPS_ESTABLISHED)
1152 t4_push_data(sc, toep, 0);
1158 t4_send_rst(struct toedev *tod, struct tcpcb *tp)
1160 struct adapter *sc = tod->tod_softc;
1161 #if defined(INVARIANTS)
1162 struct inpcb *inp = tp->t_inpcb;
1164 struct toepcb *toep = tp->t_toe;
1166 INP_WLOCK_ASSERT(inp);
1167 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1168 ("%s: inp %p dropped.", __func__, inp));
1169 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1172 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
1173 ("%s: flowc for tid %u [%s] not sent already",
1174 __func__, toep->tid, tcpstates[tp->t_state]));
1176 send_reset(sc, toep, 0);
1181 * Peer has sent us a FIN.
1184 do_peer_close(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1186 struct adapter *sc = iq->adapter;
1187 const struct cpl_peer_close *cpl = (const void *)(rss + 1);
1188 unsigned int tid = GET_TID(cpl);
1189 struct toepcb *toep = lookup_tid(sc, tid);
1190 struct inpcb *inp = toep->inp;
1191 struct tcpcb *tp = NULL;
1193 struct epoch_tracker et;
1195 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1198 KASSERT(opcode == CPL_PEER_CLOSE,
1199 ("%s: unexpected opcode 0x%x", __func__, opcode));
1200 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1202 if (__predict_false(toep->flags & TPF_SYNQE)) {
1204 * do_pass_establish must have run before do_peer_close and if
1205 * this is still a synqe instead of a toepcb then the connection
1206 * must be getting aborted.
1208 MPASS(toep->flags & TPF_ABORT_SHUTDOWN);
1209 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1214 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1216 CURVNET_SET(toep->vnet);
1217 NET_EPOCH_ENTER(et);
1219 tp = intotcpcb(inp);
1222 "%s: tid %u (%s), toep_flags 0x%x, ddp_flags 0x%x, inp %p",
1223 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags,
1224 toep->ddp.flags, inp);
1226 if (toep->flags & TPF_ABORT_SHUTDOWN)
1229 tp->rcv_nxt++; /* FIN */
1231 so = inp->inp_socket;
1233 if (ulp_mode(toep) == ULP_MODE_TCPDDP) {
1235 if (__predict_false(toep->ddp.flags &
1236 (DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE)))
1237 handle_ddp_close(toep, tp, cpl->rcv_nxt);
1241 if (ulp_mode(toep) != ULP_MODE_RDMA) {
1242 KASSERT(tp->rcv_nxt == be32toh(cpl->rcv_nxt),
1243 ("%s: rcv_nxt mismatch: %u %u", __func__, tp->rcv_nxt,
1244 be32toh(cpl->rcv_nxt)));
1247 switch (tp->t_state) {
1248 case TCPS_SYN_RECEIVED:
1249 tp->t_starttime = ticks;
1252 case TCPS_ESTABLISHED:
1253 tcp_state_change(tp, TCPS_CLOSE_WAIT);
1256 case TCPS_FIN_WAIT_1:
1257 tcp_state_change(tp, TCPS_CLOSING);
1260 case TCPS_FIN_WAIT_2:
1262 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1267 final_cpl_received(toep);
1271 log(LOG_ERR, "%s: TID %u received CPL_PEER_CLOSE in state %d\n",
1272 __func__, tid, tp->t_state);
1282 * Peer has ACK'd our FIN.
1285 do_close_con_rpl(struct sge_iq *iq, const struct rss_header *rss,
1288 struct adapter *sc = iq->adapter;
1289 const struct cpl_close_con_rpl *cpl = (const void *)(rss + 1);
1290 unsigned int tid = GET_TID(cpl);
1291 struct toepcb *toep = lookup_tid(sc, tid);
1292 struct inpcb *inp = toep->inp;
1293 struct tcpcb *tp = NULL;
1294 struct socket *so = NULL;
1295 struct epoch_tracker et;
1297 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1300 KASSERT(opcode == CPL_CLOSE_CON_RPL,
1301 ("%s: unexpected opcode 0x%x", __func__, opcode));
1302 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1303 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1305 CURVNET_SET(toep->vnet);
1306 NET_EPOCH_ENTER(et);
1308 tp = intotcpcb(inp);
1310 CTR4(KTR_CXGBE, "%s: tid %u (%s), toep_flags 0x%x",
1311 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags);
1313 if (toep->flags & TPF_ABORT_SHUTDOWN)
1316 so = inp->inp_socket;
1317 tp->snd_una = be32toh(cpl->snd_nxt) - 1; /* exclude FIN */
1319 switch (tp->t_state) {
1320 case TCPS_CLOSING: /* see TCPS_FIN_WAIT_2 in do_peer_close too */
1323 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1328 final_cpl_received(toep); /* no more CPLs expected */
1336 case TCPS_FIN_WAIT_1:
1337 if (so->so_rcv.sb_state & SBS_CANTRCVMORE)
1338 soisdisconnected(so);
1339 tcp_state_change(tp, TCPS_FIN_WAIT_2);
1344 "%s: TID %u received CPL_CLOSE_CON_RPL in state %s\n",
1345 __func__, tid, tcpstates[tp->t_state]);
1355 send_abort_rpl(struct adapter *sc, struct sge_wrq *ofld_txq, int tid,
1359 struct cpl_abort_rpl *cpl;
1361 wr = alloc_wrqe(sizeof(*cpl), ofld_txq);
1364 panic("%s: allocation failure.", __func__);
1368 INIT_TP_WR_MIT_CPL(cpl, CPL_ABORT_RPL, tid);
1369 cpl->cmd = rst_status;
1375 abort_status_to_errno(struct tcpcb *tp, unsigned int abort_reason)
1377 switch (abort_reason) {
1378 case CPL_ERR_BAD_SYN:
1379 case CPL_ERR_CONN_RESET:
1380 return (tp->t_state == TCPS_CLOSE_WAIT ? EPIPE : ECONNRESET);
1381 case CPL_ERR_XMIT_TIMEDOUT:
1382 case CPL_ERR_PERSIST_TIMEDOUT:
1383 case CPL_ERR_FINWAIT2_TIMEDOUT:
1384 case CPL_ERR_KEEPALIVE_TIMEDOUT:
1392 * TCP RST from the peer, timeout, or some other such critical error.
1395 do_abort_req(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1397 struct adapter *sc = iq->adapter;
1398 const struct cpl_abort_req_rss *cpl = (const void *)(rss + 1);
1399 unsigned int tid = GET_TID(cpl);
1400 struct toepcb *toep = lookup_tid(sc, tid);
1401 struct sge_wrq *ofld_txq = toep->ofld_txq;
1404 struct epoch_tracker et;
1406 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1409 KASSERT(opcode == CPL_ABORT_REQ_RSS,
1410 ("%s: unexpected opcode 0x%x", __func__, opcode));
1411 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1413 if (toep->flags & TPF_SYNQE)
1414 return (do_abort_req_synqe(iq, rss, m));
1416 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1418 if (negative_advice(cpl->status)) {
1419 CTR4(KTR_CXGBE, "%s: negative advice %d for tid %d (0x%x)",
1420 __func__, cpl->status, tid, toep->flags);
1421 return (0); /* Ignore negative advice */
1425 CURVNET_SET(toep->vnet);
1426 NET_EPOCH_ENTER(et); /* for tcp_close */
1429 tp = intotcpcb(inp);
1432 "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x, status %d",
1433 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags,
1434 inp->inp_flags, cpl->status);
1437 * If we'd initiated an abort earlier the reply to it is responsible for
1438 * cleaning up resources. Otherwise we tear everything down right here
1439 * right now. We owe the T4 a CPL_ABORT_RPL no matter what.
1441 if (toep->flags & TPF_ABORT_SHUTDOWN) {
1445 toep->flags |= TPF_ABORT_SHUTDOWN;
1447 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
1448 struct socket *so = inp->inp_socket;
1451 so_error_set(so, abort_status_to_errno(tp,
1455 INP_WLOCK(inp); /* re-acquire */
1458 final_cpl_received(toep);
1462 send_abort_rpl(sc, ofld_txq, tid, CPL_ABORT_NO_RST);
1467 * Reply to the CPL_ABORT_REQ (send_reset)
1470 do_abort_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1472 struct adapter *sc = iq->adapter;
1473 const struct cpl_abort_rpl_rss *cpl = (const void *)(rss + 1);
1474 unsigned int tid = GET_TID(cpl);
1475 struct toepcb *toep = lookup_tid(sc, tid);
1476 struct inpcb *inp = toep->inp;
1478 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1481 KASSERT(opcode == CPL_ABORT_RPL_RSS,
1482 ("%s: unexpected opcode 0x%x", __func__, opcode));
1483 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1485 if (toep->flags & TPF_SYNQE)
1486 return (do_abort_rpl_synqe(iq, rss, m));
1488 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1490 CTR5(KTR_CXGBE, "%s: tid %u, toep %p, inp %p, status %d",
1491 __func__, tid, toep, inp, cpl->status);
1493 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1494 ("%s: wasn't expecting abort reply", __func__));
1497 final_cpl_received(toep);
1503 do_rx_data(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1505 struct adapter *sc = iq->adapter;
1506 const struct cpl_rx_data *cpl = mtod(m, const void *);
1507 unsigned int tid = GET_TID(cpl);
1508 struct toepcb *toep = lookup_tid(sc, tid);
1509 struct inpcb *inp = toep->inp;
1513 struct epoch_tracker et;
1514 int len, rx_credits;
1515 uint32_t ddp_placed = 0;
1517 if (__predict_false(toep->flags & TPF_SYNQE)) {
1519 * do_pass_establish must have run before do_rx_data and if this
1520 * is still a synqe instead of a toepcb then the connection must
1521 * be getting aborted.
1523 MPASS(toep->flags & TPF_ABORT_SHUTDOWN);
1524 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1530 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1532 /* strip off CPL header */
1533 m_adj(m, sizeof(*cpl));
1534 len = m->m_pkthdr.len;
1537 if (inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) {
1538 CTR4(KTR_CXGBE, "%s: tid %u, rx (%d bytes), inp_flags 0x%x",
1539 __func__, tid, len, inp->inp_flags);
1545 tp = intotcpcb(inp);
1547 if (__predict_false(tp->rcv_nxt != be32toh(cpl->seq)))
1548 ddp_placed = be32toh(cpl->seq) - tp->rcv_nxt;
1551 if (tp->rcv_wnd < len) {
1552 KASSERT(ulp_mode(toep) == ULP_MODE_RDMA,
1553 ("%s: negative window size", __func__));
1557 tp->t_rcvtime = ticks;
1559 if (ulp_mode(toep) == ULP_MODE_TCPDDP)
1561 so = inp_inpcbtosocket(inp);
1565 if (__predict_false(sb->sb_state & SBS_CANTRCVMORE)) {
1566 CTR3(KTR_CXGBE, "%s: tid %u, excess rx (%d bytes)",
1567 __func__, tid, len);
1570 if (ulp_mode(toep) == ULP_MODE_TCPDDP)
1574 CURVNET_SET(toep->vnet);
1575 NET_EPOCH_ENTER(et);
1577 tp = tcp_drop(tp, ECONNRESET);
1586 /* receive buffer autosize */
1587 MPASS(toep->vnet == so->so_vnet);
1588 CURVNET_SET(toep->vnet);
1589 if (sb->sb_flags & SB_AUTOSIZE &&
1590 V_tcp_do_autorcvbuf &&
1591 sb->sb_hiwat < V_tcp_autorcvbuf_max &&
1592 len > (sbspace(sb) / 8 * 7)) {
1593 unsigned int hiwat = sb->sb_hiwat;
1594 unsigned int newsize = min(hiwat + sc->tt.autorcvbuf_inc,
1595 V_tcp_autorcvbuf_max);
1597 if (!sbreserve_locked(sb, newsize, so, NULL))
1598 sb->sb_flags &= ~SB_AUTOSIZE;
1601 if (ulp_mode(toep) == ULP_MODE_TCPDDP) {
1602 int changed = !(toep->ddp.flags & DDP_ON) ^ cpl->ddp_off;
1604 if (toep->ddp.waiting_count != 0 || toep->ddp.active_count != 0)
1605 CTR3(KTR_CXGBE, "%s: tid %u, non-ddp rx (%d bytes)",
1606 __func__, tid, len);
1609 if (toep->ddp.flags & DDP_SC_REQ)
1610 toep->ddp.flags ^= DDP_ON | DDP_SC_REQ;
1612 KASSERT(cpl->ddp_off == 1,
1613 ("%s: DDP switched on by itself.",
1616 /* Fell out of DDP mode */
1617 toep->ddp.flags &= ~DDP_ON;
1618 CTR1(KTR_CXGBE, "%s: fell out of DDP mode",
1621 insert_ddp_data(toep, ddp_placed);
1625 if (toep->ddp.flags & DDP_ON) {
1627 * CPL_RX_DATA with DDP on can only be an indicate.
1628 * Start posting queued AIO requests via DDP. The
1629 * payload that arrived in this indicate is appended
1630 * to the socket buffer as usual.
1632 handle_ddp_indicate(toep);
1636 sbappendstream_locked(sb, m, 0);
1637 rx_credits = sbspace(sb) > tp->rcv_wnd ? sbspace(sb) - tp->rcv_wnd : 0;
1638 if (rx_credits > 0 && sbused(sb) + tp->rcv_wnd < sb->sb_lowat) {
1639 rx_credits = send_rx_credits(sc, toep, rx_credits);
1640 tp->rcv_wnd += rx_credits;
1641 tp->rcv_adv += rx_credits;
1644 if (ulp_mode(toep) == ULP_MODE_TCPDDP && toep->ddp.waiting_count > 0 &&
1646 CTR2(KTR_CXGBE, "%s: tid %u queueing AIO task", __func__,
1648 ddp_queue_toep(toep);
1650 sorwakeup_locked(so);
1651 SOCKBUF_UNLOCK_ASSERT(sb);
1652 if (ulp_mode(toep) == ULP_MODE_TCPDDP)
1661 do_fw4_ack(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1663 struct adapter *sc = iq->adapter;
1664 const struct cpl_fw4_ack *cpl = (const void *)(rss + 1);
1665 unsigned int tid = G_CPL_FW4_ACK_FLOWID(be32toh(OPCODE_TID(cpl)));
1666 struct toepcb *toep = lookup_tid(sc, tid);
1670 uint8_t credits = cpl->credits;
1671 struct ofld_tx_sdesc *txsd;
1674 unsigned int opcode = G_CPL_FW4_ACK_OPCODE(be32toh(OPCODE_TID(cpl)));
1678 * Very unusual case: we'd sent a flowc + abort_req for a synq entry and
1679 * now this comes back carrying the credits for the flowc.
1681 if (__predict_false(toep->flags & TPF_SYNQE)) {
1682 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1683 ("%s: credits for a synq entry %p", __func__, toep));
1689 KASSERT(opcode == CPL_FW4_ACK,
1690 ("%s: unexpected opcode 0x%x", __func__, opcode));
1691 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1692 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1696 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN)) {
1701 KASSERT((inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) == 0,
1702 ("%s: inp_flags 0x%x", __func__, inp->inp_flags));
1704 tp = intotcpcb(inp);
1706 if (cpl->flags & CPL_FW4_ACK_FLAGS_SEQVAL) {
1707 tcp_seq snd_una = be32toh(cpl->snd_una);
1710 if (__predict_false(SEQ_LT(snd_una, tp->snd_una))) {
1712 "%s: unexpected seq# %x for TID %u, snd_una %x\n",
1713 __func__, snd_una, toep->tid, tp->snd_una);
1717 if (tp->snd_una != snd_una) {
1718 tp->snd_una = snd_una;
1719 tp->ts_recent_age = tcp_ts_getticks();
1723 #ifdef VERBOSE_TRACES
1724 CTR3(KTR_CXGBE, "%s: tid %d credits %u", __func__, tid, credits);
1726 so = inp->inp_socket;
1727 txsd = &toep->txsd[toep->txsd_cidx];
1730 KASSERT(credits >= txsd->tx_credits,
1731 ("%s: too many (or partial) credits", __func__));
1732 credits -= txsd->tx_credits;
1733 toep->tx_credits += txsd->tx_credits;
1735 if (txsd->iv_buffer) {
1736 free(txsd->iv_buffer, M_CXGBE);
1737 txsd->iv_buffer = NULL;
1741 KASSERT(toep->txsd_avail <= toep->txsd_total,
1742 ("%s: txsd avail > total", __func__));
1743 if (__predict_false(++toep->txsd_cidx == toep->txsd_total)) {
1744 txsd = &toep->txsd[0];
1745 toep->txsd_cidx = 0;
1749 if (toep->tx_credits == toep->tx_total) {
1750 toep->tx_nocompl = 0;
1751 toep->plen_nocompl = 0;
1754 if (toep->flags & TPF_TX_SUSPENDED &&
1755 toep->tx_credits >= toep->tx_total / 4) {
1756 #ifdef VERBOSE_TRACES
1757 CTR2(KTR_CXGBE, "%s: tid %d calling t4_push_frames", __func__,
1760 toep->flags &= ~TPF_TX_SUSPENDED;
1761 CURVNET_SET(toep->vnet);
1762 t4_push_data(sc, toep, plen);
1764 } else if (plen > 0) {
1765 struct sockbuf *sb = &so->so_snd;
1770 if (ulp_mode(toep) == ULP_MODE_ISCSI) {
1772 if (__predict_false(sbu > 0)) {
1774 * The data trasmitted before the tid's ULP mode
1775 * changed to ISCSI is still in so_snd.
1776 * Incoming credits should account for so_snd
1779 sbdrop_locked(sb, min(sbu, plen));
1780 plen -= min(sbu, plen);
1782 sowwakeup_locked(so); /* unlocks so_snd */
1783 rqdrop_locked(&toep->ulp_pdu_reclaimq, plen);
1785 #ifdef VERBOSE_TRACES
1786 CTR3(KTR_CXGBE, "%s: tid %d dropped %d bytes", __func__,
1789 sbdrop_locked(sb, plen);
1790 if (tls_tx_key(toep) &&
1791 toep->tls.mode == TLS_MODE_TLSOM) {
1792 struct tls_ofld_info *tls_ofld = &toep->tls;
1794 MPASS(tls_ofld->sb_off >= plen);
1795 tls_ofld->sb_off -= plen;
1797 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
1798 t4_aiotx_queue_toep(so, toep);
1799 sowwakeup_locked(so); /* unlocks so_snd */
1801 SOCKBUF_UNLOCK_ASSERT(sb);
1810 t4_set_tcb_field(struct adapter *sc, struct sge_wrq *wrq, struct toepcb *toep,
1811 uint16_t word, uint64_t mask, uint64_t val, int reply, int cookie)
1814 struct cpl_set_tcb_field *req;
1815 struct ofld_tx_sdesc *txsd;
1817 MPASS((cookie & ~M_COOKIE) == 0);
1819 MPASS(cookie != CPL_COOKIE_RESERVED);
1822 wr = alloc_wrqe(sizeof(*req), wrq);
1825 panic("%s: allocation failure.", __func__);
1829 INIT_TP_WR_MIT_CPL(req, CPL_SET_TCB_FIELD, toep->tid);
1830 req->reply_ctrl = htobe16(V_QUEUENO(toep->ofld_rxq->iq.abs_id));
1832 req->reply_ctrl |= htobe16(F_NO_REPLY);
1833 req->word_cookie = htobe16(V_WORD(word) | V_COOKIE(cookie));
1834 req->mask = htobe64(mask);
1835 req->val = htobe64(val);
1836 if ((wrq->eq.flags & EQ_TYPEMASK) == EQ_OFLD) {
1837 txsd = &toep->txsd[toep->txsd_pidx];
1838 txsd->tx_credits = howmany(sizeof(*req), 16);
1840 KASSERT(toep->tx_credits >= txsd->tx_credits &&
1841 toep->txsd_avail > 0,
1842 ("%s: not enough credits (%d)", __func__,
1844 toep->tx_credits -= txsd->tx_credits;
1845 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
1846 toep->txsd_pidx = 0;
1854 t4_init_cpl_io_handlers(void)
1857 t4_register_cpl_handler(CPL_PEER_CLOSE, do_peer_close);
1858 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, do_close_con_rpl);
1859 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, do_abort_req);
1860 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS, do_abort_rpl,
1862 t4_register_cpl_handler(CPL_RX_DATA, do_rx_data);
1863 t4_register_shared_cpl_handler(CPL_FW4_ACK, do_fw4_ack, CPL_COOKIE_TOM);
1867 t4_uninit_cpl_io_handlers(void)
1870 t4_register_cpl_handler(CPL_PEER_CLOSE, NULL);
1871 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, NULL);
1872 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, NULL);
1873 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS, NULL, CPL_COOKIE_TOM);
1874 t4_register_cpl_handler(CPL_RX_DATA, NULL);
1875 t4_register_shared_cpl_handler(CPL_FW4_ACK, NULL, CPL_COOKIE_TOM);
1879 * Use the 'backend1' field in AIO jobs to hold an error that should
1880 * be reported when the job is completed, the 'backend3' field to
1881 * store the amount of data sent by the AIO job so far, and the
1882 * 'backend4' field to hold a reference count on the job.
1884 * Each unmapped mbuf holds a reference on the job as does the queue
1885 * so long as the job is queued.
1887 #define aio_error backend1
1888 #define aio_sent backend3
1889 #define aio_refs backend4
1891 #define jobtotid(job) \
1892 (((struct toepcb *)(so_sototcpcb((job)->fd_file->f_data)->t_toe))->tid)
1895 aiotx_free_job(struct kaiocb *job)
1900 if (refcount_release(&job->aio_refs) == 0)
1903 error = (intptr_t)job->aio_error;
1904 status = job->aio_sent;
1905 #ifdef VERBOSE_TRACES
1906 CTR5(KTR_CXGBE, "%s: tid %d completed %p len %ld, error %d", __func__,
1907 jobtotid(job), job, status, error);
1909 if (error != 0 && status != 0)
1911 if (error == ECANCELED)
1914 aio_complete(job, -1, error);
1917 aio_complete(job, status, 0);
1922 aiotx_free_pgs(struct mbuf *m)
1924 struct mbuf_ext_pgs *ext_pgs;
1928 MBUF_EXT_PGS_ASSERT(m);
1929 ext_pgs = m->m_ext.ext_pgs;
1930 job = m->m_ext.ext_arg1;
1931 #ifdef VERBOSE_TRACES
1932 CTR3(KTR_CXGBE, "%s: completed %d bytes for tid %d", __func__,
1933 m->m_len, jobtotid(job));
1936 for (int i = 0; i < ext_pgs->npgs; i++) {
1937 pg = PHYS_TO_VM_PAGE(ext_pgs->pa[i]);
1938 vm_page_unwire(pg, PQ_ACTIVE);
1941 aiotx_free_job(job);
1945 * Allocate a chain of unmapped mbufs describing the next 'len' bytes
1948 static struct mbuf *
1949 alloc_aiotx_mbuf(struct kaiocb *job, int len)
1952 vm_page_t pgs[MBUF_PEXT_MAX_PGS];
1953 struct mbuf *m, *top, *last;
1954 struct mbuf_ext_pgs *ext_pgs;
1957 int i, mlen, npages, pgoff;
1959 KASSERT(job->aio_sent + len <= job->uaiocb.aio_nbytes,
1960 ("%s(%p, %d): request to send beyond end of buffer", __func__,
1964 * The AIO subsystem will cancel and drain all requests before
1965 * permitting a process to exit or exec, so p_vmspace should
1968 vm = job->userproc->p_vmspace;
1970 start = (uintptr_t)job->uaiocb.aio_buf + job->aio_sent;
1971 pgoff = start & PAGE_MASK;
1976 mlen = imin(len, MBUF_PEXT_MAX_PGS * PAGE_SIZE - pgoff);
1977 KASSERT(mlen == len || ((start + mlen) & PAGE_MASK) == 0,
1978 ("%s: next start (%#jx + %#x) is not page aligned",
1979 __func__, (uintmax_t)start, mlen));
1981 npages = vm_fault_quick_hold_pages(map, start, mlen,
1982 VM_PROT_WRITE, pgs, nitems(pgs));
1986 m = mb_alloc_ext_pgs(M_WAITOK, false, aiotx_free_pgs);
1988 vm_page_unhold_pages(pgs, npages);
1992 ext_pgs = m->m_ext.ext_pgs;
1993 ext_pgs->first_pg_off = pgoff;
1994 ext_pgs->npgs = npages;
1996 KASSERT(mlen + pgoff <= PAGE_SIZE,
1997 ("%s: single page is too large (off %d len %d)",
1998 __func__, pgoff, mlen));
1999 ext_pgs->last_pg_len = mlen;
2001 ext_pgs->last_pg_len = mlen - (PAGE_SIZE - pgoff) -
2002 (npages - 2) * PAGE_SIZE;
2004 for (i = 0; i < npages; i++)
2005 ext_pgs->pa[i] = VM_PAGE_TO_PHYS(pgs[i]);
2008 m->m_ext.ext_size = npages * PAGE_SIZE;
2009 m->m_ext.ext_arg1 = job;
2010 refcount_acquire(&job->aio_refs);
2012 #ifdef VERBOSE_TRACES
2013 CTR5(KTR_CXGBE, "%s: tid %d, new mbuf %p for job %p, npages %d",
2014 __func__, jobtotid(job), m, job, npages);
2032 t4_aiotx_process_job(struct toepcb *toep, struct socket *so, struct kaiocb *job)
2040 bool moretocome, sendmore;
2048 error = mac_socket_check_send(fp->f_cred, so);
2053 /* Inline sosend_generic(). */
2055 error = sblock(sb, SBL_WAIT);
2060 if (so->so_snd.sb_state & SBS_CANTSENDMORE) {
2063 if ((so->so_options & SO_NOSIGPIPE) == 0) {
2064 PROC_LOCK(job->userproc);
2065 kern_psignal(job->userproc, SIGPIPE);
2066 PROC_UNLOCK(job->userproc);
2072 error = so->so_error;
2078 if ((so->so_state & SS_ISCONNECTED) == 0) {
2084 if (sbspace(sb) < sb->sb_lowat) {
2085 MPASS(job->aio_sent == 0 || !(so->so_state & SS_NBIO));
2088 * Don't block if there is too little room in the socket
2089 * buffer. Instead, requeue the request.
2091 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2097 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2104 * Write as much data as the socket permits, but no more than a
2105 * a single sndbuf at a time.
2108 if (len > job->uaiocb.aio_nbytes - job->aio_sent) {
2109 len = job->uaiocb.aio_nbytes - job->aio_sent;
2113 if (len > toep->params.sndbuf) {
2114 len = toep->params.sndbuf;
2119 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
2124 m = alloc_aiotx_mbuf(job, len);
2131 /* Inlined tcp_usr_send(). */
2135 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
2142 job->aio_sent += m_length(m, NULL);
2144 sbappendstream(sb, m, 0);
2147 if (!(inp->inp_flags & INP_DROPPED)) {
2148 tp = intotcpcb(inp);
2150 tp->t_flags |= TF_MORETOCOME;
2151 error = tp->t_fb->tfb_tcp_output(tp);
2153 tp->t_flags &= ~TF_MORETOCOME;
2165 * If this is a blocking socket and the request has not been
2166 * fully completed, requeue it until the socket is ready
2169 if (job->aio_sent < job->uaiocb.aio_nbytes &&
2170 !(so->so_state & SS_NBIO)) {
2172 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2177 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2182 * If the request will not be requeued, drop the queue's
2183 * reference to the job. Any mbufs in flight should still
2184 * hold a reference, but this drops the reference that the
2185 * queue owns while it is waiting to queue mbufs to the
2188 aiotx_free_job(job);
2192 job->aio_error = (void *)(intptr_t)error;
2193 aiotx_free_job(job);
2201 t4_aiotx_task(void *context, int pending)
2203 struct toepcb *toep = context;
2207 so = toep->aiotx_so;
2208 CURVNET_SET(toep->vnet);
2209 SOCKBUF_LOCK(&so->so_snd);
2210 while (!TAILQ_EMPTY(&toep->aiotx_jobq) && sowriteable(so)) {
2211 job = TAILQ_FIRST(&toep->aiotx_jobq);
2212 TAILQ_REMOVE(&toep->aiotx_jobq, job, list);
2213 if (!aio_clear_cancel_function(job))
2216 t4_aiotx_process_job(toep, so, job);
2218 toep->aiotx_so = NULL;
2219 SOCKBUF_UNLOCK(&so->so_snd);
2228 t4_aiotx_queue_toep(struct socket *so, struct toepcb *toep)
2231 SOCKBUF_LOCK_ASSERT(&toep->inp->inp_socket->so_snd);
2232 #ifdef VERBOSE_TRACES
2233 CTR3(KTR_CXGBE, "%s: queueing aiotx task for tid %d, active = %s",
2234 __func__, toep->tid, toep->aiotx_so != NULL ? "true" : "false");
2236 if (toep->aiotx_so != NULL)
2239 toep->aiotx_so = so;
2241 soaio_enqueue(&toep->aiotx_task);
2245 t4_aiotx_cancel(struct kaiocb *job)
2250 struct toepcb *toep;
2252 so = job->fd_file->f_data;
2253 tp = so_sototcpcb(so);
2255 MPASS(job->uaiocb.aio_lio_opcode == LIO_WRITE);
2259 if (!aio_cancel_cleared(job))
2260 TAILQ_REMOVE(&toep->aiotx_jobq, job, list);
2263 job->aio_error = (void *)(intptr_t)ECANCELED;
2264 aiotx_free_job(job);
2268 t4_aio_queue_aiotx(struct socket *so, struct kaiocb *job)
2270 struct tcpcb *tp = so_sototcpcb(so);
2271 struct toepcb *toep = tp->t_toe;
2272 struct adapter *sc = td_adapter(toep->td);
2274 /* This only handles writes. */
2275 if (job->uaiocb.aio_lio_opcode != LIO_WRITE)
2276 return (EOPNOTSUPP);
2278 if (!sc->tt.tx_zcopy)
2279 return (EOPNOTSUPP);
2281 if (tls_tx_key(toep))
2282 return (EOPNOTSUPP);
2284 SOCKBUF_LOCK(&so->so_snd);
2285 #ifdef VERBOSE_TRACES
2286 CTR3(KTR_CXGBE, "%s: queueing %p for tid %u", __func__, job, toep->tid);
2288 if (!aio_set_cancel_function(job, t4_aiotx_cancel))
2289 panic("new job was cancelled");
2290 refcount_init(&job->aio_refs, 1);
2291 TAILQ_INSERT_TAIL(&toep->aiotx_jobq, job, list);
2292 if (sowriteable(so))
2293 t4_aiotx_queue_toep(so, toep);
2294 SOCKBUF_UNLOCK(&so->so_snd);
2299 aiotx_init_toep(struct toepcb *toep)
2302 TAILQ_INIT(&toep->aiotx_jobq);
2303 TASK_INIT(&toep->aiotx_task, 0, t4_aiotx_task, toep);