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_ratelimit.h"
38 #include <sys/param.h>
41 #include <sys/kernel.h>
43 #include <sys/module.h>
45 #include <sys/protosw.h>
46 #include <sys/domain.h>
47 #include <sys/socket.h>
48 #include <sys/socketvar.h>
49 #include <sys/sglist.h>
50 #include <sys/taskqueue.h>
51 #include <netinet/in.h>
52 #include <netinet/in_pcb.h>
53 #include <netinet/ip.h>
54 #include <netinet/ip6.h>
56 #include <netinet/tcp_fsm.h>
57 #include <netinet/tcp_seq.h>
58 #include <netinet/tcp_var.h>
59 #include <netinet/toecore.h>
61 #include <security/mac/mac_framework.h>
64 #include <vm/vm_extern.h>
66 #include <vm/vm_map.h>
67 #include <vm/vm_page.h>
69 #include "common/common.h"
70 #include "common/t4_msg.h"
71 #include "common/t4_regs.h"
72 #include "common/t4_tcb.h"
73 #include "tom/t4_tom_l2t.h"
74 #include "tom/t4_tom.h"
76 static void t4_aiotx_cancel(struct kaiocb *job);
77 static void t4_aiotx_queue_toep(struct socket *so, struct toepcb *toep);
80 send_flowc_wr(struct toepcb *toep, struct tcpcb *tp)
83 struct fw_flowc_wr *flowc;
84 unsigned int nparams, flowclen, paramidx;
85 struct vi_info *vi = toep->vi;
86 struct port_info *pi = vi->pi;
87 struct adapter *sc = pi->adapter;
88 unsigned int pfvf = sc->pf << S_FW_VIID_PFN;
89 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
91 KASSERT(!(toep->flags & TPF_FLOWC_WR_SENT),
92 ("%s: flowc for tid %u sent already", __func__, toep->tid));
98 if (ulp_mode(toep) == ULP_MODE_TLS)
100 if (toep->tls.fcplenmax != 0)
102 if (toep->params.tc_idx != -1) {
103 MPASS(toep->params.tc_idx >= 0 &&
104 toep->params.tc_idx < sc->chip_params->nsched_cls);
108 flowclen = sizeof(*flowc) + nparams * sizeof(struct fw_flowc_mnemval);
110 wr = alloc_wrqe(roundup2(flowclen, 16), toep->ofld_txq);
113 panic("%s: allocation failure.", __func__);
116 memset(flowc, 0, wr->wr_len);
118 flowc->op_to_nparams = htobe32(V_FW_WR_OP(FW_FLOWC_WR) |
119 V_FW_FLOWC_WR_NPARAMS(nparams));
120 flowc->flowid_len16 = htonl(V_FW_WR_LEN16(howmany(flowclen, 16)) |
121 V_FW_WR_FLOWID(toep->tid));
123 #define FLOWC_PARAM(__m, __v) \
125 flowc->mnemval[paramidx].mnemonic = FW_FLOWC_MNEM_##__m; \
126 flowc->mnemval[paramidx].val = htobe32(__v); \
132 FLOWC_PARAM(PFNVFN, pfvf);
133 FLOWC_PARAM(CH, pi->tx_chan);
134 FLOWC_PARAM(PORT, pi->tx_chan);
135 FLOWC_PARAM(IQID, toep->ofld_rxq->iq.abs_id);
136 FLOWC_PARAM(SNDBUF, toep->params.sndbuf);
137 FLOWC_PARAM(MSS, toep->params.emss);
139 FLOWC_PARAM(SNDNXT, tp->snd_nxt);
140 FLOWC_PARAM(RCVNXT, tp->rcv_nxt);
143 "%s: tid %u, mss %u, sndbuf %u, snd_nxt 0x%x, rcv_nxt 0x%x",
144 __func__, toep->tid, toep->params.emss, toep->params.sndbuf,
145 tp ? tp->snd_nxt : 0, tp ? tp->rcv_nxt : 0);
147 if (ulp_mode(toep) == ULP_MODE_TLS)
148 FLOWC_PARAM(ULP_MODE, ulp_mode(toep));
149 if (toep->tls.fcplenmax != 0)
150 FLOWC_PARAM(TXDATAPLEN_MAX, toep->tls.fcplenmax);
151 if (toep->params.tc_idx != -1)
152 FLOWC_PARAM(SCHEDCLASS, toep->params.tc_idx);
155 KASSERT(paramidx == nparams, ("nparams mismatch"));
157 txsd->tx_credits = howmany(flowclen, 16);
159 KASSERT(toep->tx_credits >= txsd->tx_credits && toep->txsd_avail > 0,
160 ("%s: not enough credits (%d)", __func__, toep->tx_credits));
161 toep->tx_credits -= txsd->tx_credits;
162 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
166 toep->flags |= TPF_FLOWC_WR_SENT;
172 * Input is Bytes/second (so_max_pacing_rate), chip counts in Kilobits/second.
175 update_tx_rate_limit(struct adapter *sc, struct toepcb *toep, u_int Bps)
178 const u_int kbps = (u_int) (uint64_t)Bps * 8ULL / 1000;
179 const int port_id = toep->vi->pi->port_id;
181 CTR3(KTR_CXGBE, "%s: tid %u, rate %uKbps", __func__, toep->tid, kbps);
187 rc = t4_reserve_cl_rl_kbps(sc, port_id, kbps, &tc_idx);
190 MPASS(tc_idx >= 0 && tc_idx < sc->chip_params->nsched_cls);
193 if (toep->params.tc_idx != tc_idx) {
195 struct fw_flowc_wr *flowc;
196 int nparams = 1, flowclen, flowclen16;
197 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
199 flowclen = sizeof(*flowc) + nparams * sizeof(struct
201 flowclen16 = howmany(flowclen, 16);
202 if (toep->tx_credits < flowclen16 || toep->txsd_avail == 0 ||
203 (wr = alloc_wrqe(roundup2(flowclen, 16), toep->ofld_txq)) == NULL) {
205 t4_release_cl_rl(sc, port_id, tc_idx);
210 memset(flowc, 0, wr->wr_len);
212 flowc->op_to_nparams = htobe32(V_FW_WR_OP(FW_FLOWC_WR) |
213 V_FW_FLOWC_WR_NPARAMS(nparams));
214 flowc->flowid_len16 = htonl(V_FW_WR_LEN16(flowclen16) |
215 V_FW_WR_FLOWID(toep->tid));
217 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
219 flowc->mnemval[0].val = htobe32(0xff);
221 flowc->mnemval[0].val = htobe32(tc_idx);
223 txsd->tx_credits = flowclen16;
225 toep->tx_credits -= txsd->tx_credits;
226 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
232 if (toep->params.tc_idx >= 0)
233 t4_release_cl_rl(sc, port_id, toep->params.tc_idx);
234 toep->params.tc_idx = tc_idx;
241 send_reset(struct adapter *sc, struct toepcb *toep, uint32_t snd_nxt)
244 struct cpl_abort_req *req;
246 struct inpcb *inp = toep->inp;
247 struct tcpcb *tp = intotcpcb(inp); /* don't use if INP_DROPPED */
249 INP_WLOCK_ASSERT(inp);
251 CTR6(KTR_CXGBE, "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x%s",
253 inp->inp_flags & INP_DROPPED ? "inp dropped" :
254 tcpstates[tp->t_state],
255 toep->flags, inp->inp_flags,
256 toep->flags & TPF_ABORT_SHUTDOWN ?
257 " (abort already in progress)" : "");
259 if (toep->flags & TPF_ABORT_SHUTDOWN)
260 return; /* abort already in progress */
262 toep->flags |= TPF_ABORT_SHUTDOWN;
264 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
265 ("%s: flowc_wr not sent for tid %d.", __func__, tid));
267 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
270 panic("%s: allocation failure.", __func__);
274 INIT_TP_WR_MIT_CPL(req, CPL_ABORT_REQ, tid);
275 if (inp->inp_flags & INP_DROPPED)
276 req->rsvd0 = htobe32(snd_nxt);
278 req->rsvd0 = htobe32(tp->snd_nxt);
279 req->rsvd1 = !(toep->flags & TPF_TX_DATA_SENT);
280 req->cmd = CPL_ABORT_SEND_RST;
283 * XXX: What's the correct way to tell that the inp hasn't been detached
284 * from its socket? Should I even be flushing the snd buffer here?
286 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
287 struct socket *so = inp->inp_socket;
289 if (so != NULL) /* because I'm not sure. See comment above */
290 sbflush(&so->so_snd);
293 t4_l2t_send(sc, wr, toep->l2te);
297 * Called when a connection is established to translate the TCP options
298 * reported by HW to FreeBSD's native format.
301 assign_rxopt(struct tcpcb *tp, uint16_t opt)
303 struct toepcb *toep = tp->t_toe;
304 struct inpcb *inp = tp->t_inpcb;
305 struct adapter *sc = td_adapter(toep->td);
307 INP_LOCK_ASSERT(inp);
309 toep->params.mtu_idx = G_TCPOPT_MSS(opt);
310 tp->t_maxseg = sc->params.mtus[toep->params.mtu_idx];
311 if (inp->inp_inc.inc_flags & INC_ISIPV6)
312 tp->t_maxseg -= sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
314 tp->t_maxseg -= sizeof(struct ip) + sizeof(struct tcphdr);
316 toep->params.emss = tp->t_maxseg;
317 if (G_TCPOPT_TSTAMP(opt)) {
318 toep->params.tstamp = 1;
319 toep->params.emss -= TCPOLEN_TSTAMP_APPA;
320 tp->t_flags |= TF_RCVD_TSTMP; /* timestamps ok */
321 tp->ts_recent = 0; /* hmmm */
322 tp->ts_recent_age = tcp_ts_getticks();
324 toep->params.tstamp = 0;
326 if (G_TCPOPT_SACK(opt)) {
327 toep->params.sack = 1;
328 tp->t_flags |= TF_SACK_PERMIT; /* should already be set */
330 toep->params.sack = 0;
331 tp->t_flags &= ~TF_SACK_PERMIT; /* sack disallowed by peer */
334 if (G_TCPOPT_WSCALE_OK(opt))
335 tp->t_flags |= TF_RCVD_SCALE;
337 /* Doing window scaling? */
338 if ((tp->t_flags & (TF_RCVD_SCALE | TF_REQ_SCALE)) ==
339 (TF_RCVD_SCALE | TF_REQ_SCALE)) {
340 tp->rcv_scale = tp->request_r_scale;
341 tp->snd_scale = G_TCPOPT_SND_WSCALE(opt);
343 toep->params.wscale = 0;
346 "assign_rxopt: tid %d, mtu_idx %u, emss %u, ts %u, sack %u, wscale %u",
347 toep->tid, toep->params.mtu_idx, toep->params.emss,
348 toep->params.tstamp, toep->params.sack, toep->params.wscale);
352 * Completes some final bits of initialization for just established connections
353 * and changes their state to TCPS_ESTABLISHED.
355 * The ISNs are from the exchange of SYNs.
358 make_established(struct toepcb *toep, uint32_t iss, uint32_t irs, uint16_t opt)
360 struct inpcb *inp = toep->inp;
361 struct socket *so = inp->inp_socket;
362 struct tcpcb *tp = intotcpcb(inp);
363 uint16_t tcpopt = be16toh(opt);
365 INP_WLOCK_ASSERT(inp);
366 KASSERT(tp->t_state == TCPS_SYN_SENT ||
367 tp->t_state == TCPS_SYN_RECEIVED,
368 ("%s: TCP state %s", __func__, tcpstates[tp->t_state]));
370 CTR6(KTR_CXGBE, "%s: tid %d, so %p, inp %p, tp %p, toep %p",
371 __func__, toep->tid, so, inp, tp, toep);
373 tcp_state_change(tp, TCPS_ESTABLISHED);
374 tp->t_starttime = ticks;
375 TCPSTAT_INC(tcps_connects);
379 tp->rcv_wnd = (u_int)toep->params.opt0_bufsize << 10;
380 tp->rcv_adv += tp->rcv_wnd;
381 tp->last_ack_sent = tp->rcv_nxt;
385 tp->snd_una = iss + 1;
386 tp->snd_nxt = iss + 1;
387 tp->snd_max = iss + 1;
389 assign_rxopt(tp, tcpopt);
390 send_flowc_wr(toep, tp);
396 send_rx_credits(struct adapter *sc, struct toepcb *toep, int credits)
399 struct cpl_rx_data_ack *req;
400 uint32_t dack = F_RX_DACK_CHANGE | V_RX_DACK_MODE(1);
402 KASSERT(credits >= 0, ("%s: %d credits", __func__, credits));
404 wr = alloc_wrqe(sizeof(*req), toep->ctrlq);
409 INIT_TP_WR_MIT_CPL(req, CPL_RX_DATA_ACK, toep->tid);
410 req->credit_dack = htobe32(dack | V_RX_CREDITS(credits));
417 send_rx_modulate(struct adapter *sc, struct toepcb *toep)
420 struct cpl_rx_data_ack *req;
422 wr = alloc_wrqe(sizeof(*req), toep->ctrlq);
427 INIT_TP_WR_MIT_CPL(req, CPL_RX_DATA_ACK, toep->tid);
428 req->credit_dack = htobe32(F_RX_MODULATE_RX);
434 t4_rcvd_locked(struct toedev *tod, struct tcpcb *tp)
436 struct adapter *sc = tod->tod_softc;
437 struct inpcb *inp = tp->t_inpcb;
438 struct socket *so = inp->inp_socket;
439 struct sockbuf *sb = &so->so_rcv;
440 struct toepcb *toep = tp->t_toe;
443 INP_WLOCK_ASSERT(inp);
444 SOCKBUF_LOCK_ASSERT(sb);
446 rx_credits = sbspace(sb) > tp->rcv_wnd ? sbspace(sb) - tp->rcv_wnd : 0;
447 if (ulp_mode(toep) == ULP_MODE_TLS) {
448 if (toep->tls.rcv_over >= rx_credits) {
449 toep->tls.rcv_over -= rx_credits;
452 rx_credits -= toep->tls.rcv_over;
453 toep->tls.rcv_over = 0;
457 if (rx_credits > 0 &&
458 (tp->rcv_wnd <= 32 * 1024 || rx_credits >= 64 * 1024 ||
459 (rx_credits >= 16 * 1024 && tp->rcv_wnd <= 128 * 1024) ||
460 sbused(sb) + tp->rcv_wnd < sb->sb_lowat)) {
461 rx_credits = send_rx_credits(sc, toep, rx_credits);
462 tp->rcv_wnd += rx_credits;
463 tp->rcv_adv += rx_credits;
464 } else if (toep->flags & TPF_FORCE_CREDITS)
465 send_rx_modulate(sc, toep);
469 t4_rcvd(struct toedev *tod, struct tcpcb *tp)
471 struct inpcb *inp = tp->t_inpcb;
472 struct socket *so = inp->inp_socket;
473 struct sockbuf *sb = &so->so_rcv;
476 t4_rcvd_locked(tod, tp);
481 * Close a connection by sending a CPL_CLOSE_CON_REQ message.
484 t4_close_conn(struct adapter *sc, struct toepcb *toep)
487 struct cpl_close_con_req *req;
488 unsigned int tid = toep->tid;
490 CTR3(KTR_CXGBE, "%s: tid %u%s", __func__, toep->tid,
491 toep->flags & TPF_FIN_SENT ? ", IGNORED" : "");
493 if (toep->flags & TPF_FIN_SENT)
496 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
497 ("%s: flowc_wr not sent for tid %u.", __func__, tid));
499 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
502 panic("%s: allocation failure.", __func__);
506 req->wr.wr_hi = htonl(V_FW_WR_OP(FW_TP_WR) |
507 V_FW_WR_IMMDLEN(sizeof(*req) - sizeof(req->wr)));
508 req->wr.wr_mid = htonl(V_FW_WR_LEN16(howmany(sizeof(*req), 16)) |
509 V_FW_WR_FLOWID(tid));
510 req->wr.wr_lo = cpu_to_be64(0);
511 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
514 toep->flags |= TPF_FIN_SENT;
515 toep->flags &= ~TPF_SEND_FIN;
516 t4_l2t_send(sc, wr, toep->l2te);
521 #define MAX_OFLD_TX_CREDITS (SGE_MAX_WR_LEN / 16)
522 #define MIN_OFLD_TX_CREDITS (howmany(sizeof(struct fw_ofld_tx_data_wr) + 1, 16))
524 /* Maximum amount of immediate data we could stuff in a WR */
526 max_imm_payload(int tx_credits)
528 const int n = 1; /* Use no more than one desc for imm. data WR */
530 KASSERT(tx_credits >= 0 &&
531 tx_credits <= MAX_OFLD_TX_CREDITS,
532 ("%s: %d credits", __func__, tx_credits));
534 if (tx_credits < MIN_OFLD_TX_CREDITS)
537 if (tx_credits >= (n * EQ_ESIZE) / 16)
538 return ((n * EQ_ESIZE) - sizeof(struct fw_ofld_tx_data_wr));
540 return (tx_credits * 16 - sizeof(struct fw_ofld_tx_data_wr));
543 /* Maximum number of SGL entries we could stuff in a WR */
545 max_dsgl_nsegs(int tx_credits)
547 int nseg = 1; /* ulptx_sgl has room for 1, rest ulp_tx_sge_pair */
548 int sge_pair_credits = tx_credits - MIN_OFLD_TX_CREDITS;
550 KASSERT(tx_credits >= 0 &&
551 tx_credits <= MAX_OFLD_TX_CREDITS,
552 ("%s: %d credits", __func__, tx_credits));
554 if (tx_credits < MIN_OFLD_TX_CREDITS)
557 nseg += 2 * (sge_pair_credits * 16 / 24);
558 if ((sge_pair_credits * 16) % 24 == 16)
565 write_tx_wr(void *dst, struct toepcb *toep, unsigned int immdlen,
566 unsigned int plen, uint8_t credits, int shove, int ulp_submode)
568 struct fw_ofld_tx_data_wr *txwr = dst;
570 txwr->op_to_immdlen = htobe32(V_WR_OP(FW_OFLD_TX_DATA_WR) |
571 V_FW_WR_IMMDLEN(immdlen));
572 txwr->flowid_len16 = htobe32(V_FW_WR_FLOWID(toep->tid) |
573 V_FW_WR_LEN16(credits));
574 txwr->lsodisable_to_flags = htobe32(V_TX_ULP_MODE(ulp_mode(toep)) |
575 V_TX_ULP_SUBMODE(ulp_submode) | V_TX_URG(0) | V_TX_SHOVE(shove));
576 txwr->plen = htobe32(plen);
578 if (toep->params.tx_align > 0) {
579 if (plen < 2 * toep->params.emss)
580 txwr->lsodisable_to_flags |=
581 htobe32(F_FW_OFLD_TX_DATA_WR_LSODISABLE);
583 txwr->lsodisable_to_flags |=
584 htobe32(F_FW_OFLD_TX_DATA_WR_ALIGNPLD |
585 (toep->params.nagle == 0 ? 0 :
586 F_FW_OFLD_TX_DATA_WR_ALIGNPLDSHOVE));
591 * Generate a DSGL from a starting mbuf. The total number of segments and the
592 * maximum segments in any one mbuf are provided.
595 write_tx_sgl(void *dst, struct mbuf *start, struct mbuf *stop, int nsegs, int n)
598 struct ulptx_sgl *usgl = dst;
601 struct sglist_seg segs[n];
603 KASSERT(nsegs > 0, ("%s: nsegs 0", __func__));
605 sglist_init(&sg, n, segs);
606 usgl->cmd_nsge = htobe32(V_ULPTX_CMD(ULP_TX_SC_DSGL) |
607 V_ULPTX_NSGE(nsegs));
610 for (m = start; m != stop; m = m->m_next) {
611 if (m->m_flags & M_NOMAP)
612 rc = sglist_append_mb_ext_pgs(&sg, m);
614 rc = sglist_append(&sg, mtod(m, void *), m->m_len);
615 if (__predict_false(rc != 0))
616 panic("%s: sglist_append %d", __func__, rc);
618 for (j = 0; j < sg.sg_nseg; i++, j++) {
620 usgl->len0 = htobe32(segs[j].ss_len);
621 usgl->addr0 = htobe64(segs[j].ss_paddr);
623 usgl->sge[i / 2].len[i & 1] =
624 htobe32(segs[j].ss_len);
625 usgl->sge[i / 2].addr[i & 1] =
626 htobe64(segs[j].ss_paddr);
635 usgl->sge[i / 2].len[1] = htobe32(0);
636 KASSERT(nsegs == 0, ("%s: nsegs %d, start %p, stop %p",
637 __func__, nsegs, start, stop));
641 * Max number of SGL entries an offload tx work request can have. This is 41
642 * (1 + 40) for a full 512B work request.
643 * fw_ofld_tx_data_wr(16B) + ulptx_sgl(16B, 1) + ulptx_sge_pair(480B, 40)
645 #define OFLD_SGL_LEN (41)
648 * Send data and/or a FIN to the peer.
650 * The socket's so_snd buffer consists of a stream of data starting with sb_mb
651 * and linked together with m_next. sb_sndptr, if set, is the last mbuf that
654 * drop indicates the number of bytes that should be dropped from the head of
655 * the send buffer. It is an optimization that lets do_fw4_ack avoid creating
656 * contention on the send buffer lock (before this change it used to do
657 * sowwakeup and then t4_push_frames right after that when recovering from tx
658 * stalls). When drop is set this function MUST drop the bytes and wake up any
662 t4_push_frames(struct adapter *sc, struct toepcb *toep, int drop)
664 struct mbuf *sndptr, *m, *sb_sndptr;
665 struct fw_ofld_tx_data_wr *txwr;
667 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
668 struct inpcb *inp = toep->inp;
669 struct tcpcb *tp = intotcpcb(inp);
670 struct socket *so = inp->inp_socket;
671 struct sockbuf *sb = &so->so_snd;
672 int tx_credits, shove, compl, sowwakeup;
673 struct ofld_tx_sdesc *txsd;
674 bool nomap_mbuf_seen;
676 INP_WLOCK_ASSERT(inp);
677 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
678 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
680 KASSERT(ulp_mode(toep) == ULP_MODE_NONE ||
681 ulp_mode(toep) == ULP_MODE_TCPDDP ||
682 ulp_mode(toep) == ULP_MODE_TLS ||
683 ulp_mode(toep) == ULP_MODE_RDMA,
684 ("%s: ulp_mode %u for toep %p", __func__, ulp_mode(toep), toep));
686 #ifdef VERBOSE_TRACES
687 CTR5(KTR_CXGBE, "%s: tid %d toep flags %#x tp flags %#x drop %d",
688 __func__, toep->tid, toep->flags, tp->t_flags, drop);
690 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
694 if (__predict_false(inp->inp_flags2 & INP_RATE_LIMIT_CHANGED) &&
695 (update_tx_rate_limit(sc, toep, so->so_max_pacing_rate) == 0)) {
696 inp->inp_flags2 &= ~INP_RATE_LIMIT_CHANGED;
701 * This function doesn't resume by itself. Someone else must clear the
702 * flag and call this function.
704 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
706 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
710 txsd = &toep->txsd[toep->txsd_pidx];
712 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
713 max_imm = max_imm_payload(tx_credits);
714 max_nsegs = max_dsgl_nsegs(tx_credits);
719 sbdrop_locked(sb, drop);
722 sb_sndptr = sb->sb_sndptr;
723 sndptr = sb_sndptr ? sb_sndptr->m_next : sb->sb_mb;
726 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
727 nomap_mbuf_seen = false;
728 for (m = sndptr; m != NULL; m = m->m_next) {
731 if (m->m_flags & M_NOMAP)
732 n = sglist_count_mb_ext_pgs(m);
734 n = sglist_count(mtod(m, void *), m->m_len);
739 /* This mbuf sent us _over_ the nsegs limit, back out */
740 if (plen > max_imm && nsegs > max_nsegs) {
744 /* Too few credits */
745 toep->flags |= TPF_TX_SUSPENDED;
749 t4_aiotx_queue_toep(so,
751 sowwakeup_locked(so);
754 SOCKBUF_UNLOCK_ASSERT(sb);
760 if (m->m_flags & M_NOMAP)
761 nomap_mbuf_seen = true;
762 if (max_nsegs_1mbuf < n)
764 sb_sndptr = m; /* new sb->sb_sndptr if all goes well */
766 /* This mbuf put us right at the max_nsegs limit */
767 if (plen > max_imm && nsegs == max_nsegs) {
773 if (sbused(sb) > sb->sb_hiwat * 5 / 8 &&
774 toep->plen_nocompl + plen >= sb->sb_hiwat / 4)
779 if (sb->sb_flags & SB_AUTOSIZE &&
780 V_tcp_do_autosndbuf &&
781 sb->sb_hiwat < V_tcp_autosndbuf_max &&
782 sbused(sb) >= sb->sb_hiwat * 7 / 8) {
783 int newsize = min(sb->sb_hiwat + V_tcp_autosndbuf_inc,
784 V_tcp_autosndbuf_max);
786 if (!sbreserve_locked(sb, newsize, so, NULL))
787 sb->sb_flags &= ~SB_AUTOSIZE;
789 sowwakeup = 1; /* room available */
792 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
793 t4_aiotx_queue_toep(so, toep);
794 sowwakeup_locked(so);
797 SOCKBUF_UNLOCK_ASSERT(sb);
799 /* nothing to send */
802 ("%s: nothing to send, but m != NULL", __func__));
806 if (__predict_false(toep->flags & TPF_FIN_SENT))
807 panic("%s: excess tx.", __func__);
809 shove = m == NULL && !(tp->t_flags & TF_MORETOCOME);
810 if (plen <= max_imm && !nomap_mbuf_seen) {
812 /* Immediate data tx */
814 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
817 /* XXX: how will we recover from this? */
818 toep->flags |= TPF_TX_SUSPENDED;
822 credits = howmany(wr->wr_len, 16);
823 write_tx_wr(txwr, toep, plen, plen, credits, shove, 0);
824 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
831 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
832 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
833 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
835 /* XXX: how will we recover from this? */
836 toep->flags |= TPF_TX_SUSPENDED;
840 credits = howmany(wr_len, 16);
841 write_tx_wr(txwr, toep, 0, plen, credits, shove, 0);
842 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
845 uint64_t *pad = (uint64_t *)
846 ((uintptr_t)txwr + wr_len);
851 KASSERT(toep->tx_credits >= credits,
852 ("%s: not enough credits", __func__));
854 toep->tx_credits -= credits;
855 toep->tx_nocompl += credits;
856 toep->plen_nocompl += plen;
857 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
858 toep->tx_nocompl >= toep->tx_total / 4)
861 if (compl || ulp_mode(toep) == ULP_MODE_RDMA) {
862 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
863 toep->tx_nocompl = 0;
864 toep->plen_nocompl = 0;
871 KASSERT(sb_sndptr, ("%s: sb_sndptr is NULL", __func__));
872 sb->sb_sndptr = sb_sndptr;
875 toep->flags |= TPF_TX_DATA_SENT;
876 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
877 toep->flags |= TPF_TX_SUSPENDED;
879 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
881 txsd->tx_credits = credits;
883 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
885 txsd = &toep->txsd[0];
889 t4_l2t_send(sc, wr, toep->l2te);
892 /* Send a FIN if requested, but only if there's no more data to send */
893 if (m == NULL && toep->flags & TPF_SEND_FIN)
894 t4_close_conn(sc, toep);
898 rqdrop_locked(struct mbufq *q, int plen)
903 m = mbufq_dequeue(q);
905 /* Too many credits. */
909 /* Partial credits. */
910 MPASS(plen >= m->m_pkthdr.len);
912 plen -= m->m_pkthdr.len;
918 t4_push_pdus(struct adapter *sc, struct toepcb *toep, int drop)
920 struct mbuf *sndptr, *m;
921 struct fw_ofld_tx_data_wr *txwr;
923 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
924 u_int adjusted_plen, ulp_submode;
925 struct inpcb *inp = toep->inp;
926 struct tcpcb *tp = intotcpcb(inp);
927 int tx_credits, shove;
928 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
929 struct mbufq *pduq = &toep->ulp_pduq;
930 static const u_int ulp_extra_len[] = {0, 4, 4, 8};
932 INP_WLOCK_ASSERT(inp);
933 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
934 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
935 KASSERT(ulp_mode(toep) == ULP_MODE_ISCSI,
936 ("%s: ulp_mode %u for toep %p", __func__, ulp_mode(toep), toep));
938 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
942 * This function doesn't resume by itself. Someone else must clear the
943 * flag and call this function.
945 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
947 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
952 rqdrop_locked(&toep->ulp_pdu_reclaimq, drop);
954 while ((sndptr = mbufq_first(pduq)) != NULL) {
955 M_ASSERTPKTHDR(sndptr);
957 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
958 max_imm = max_imm_payload(tx_credits);
959 max_nsegs = max_dsgl_nsegs(tx_credits);
963 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
964 for (m = sndptr; m != NULL; m = m->m_next) {
965 int n = sglist_count(mtod(m, void *), m->m_len);
971 * This mbuf would send us _over_ the nsegs limit.
972 * Suspend tx because the PDU can't be sent out.
974 if (plen > max_imm && nsegs > max_nsegs) {
975 toep->flags |= TPF_TX_SUSPENDED;
979 if (max_nsegs_1mbuf < n)
983 if (__predict_false(toep->flags & TPF_FIN_SENT))
984 panic("%s: excess tx.", __func__);
987 * We have a PDU to send. All of it goes out in one WR so 'm'
988 * is NULL. A PDU's length is always a multiple of 4.
991 MPASS((plen & 3) == 0);
992 MPASS(sndptr->m_pkthdr.len == plen);
994 shove = !(tp->t_flags & TF_MORETOCOME);
995 ulp_submode = mbuf_ulp_submode(sndptr);
996 MPASS(ulp_submode < nitems(ulp_extra_len));
999 * plen doesn't include header and data digests, which are
1000 * generated and inserted in the right places by the TOE, but
1001 * they do occupy TCP sequence space and need to be accounted
1004 adjusted_plen = plen + ulp_extra_len[ulp_submode];
1005 if (plen <= max_imm) {
1007 /* Immediate data tx */
1009 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
1012 /* XXX: how will we recover from this? */
1013 toep->flags |= TPF_TX_SUSPENDED;
1017 credits = howmany(wr->wr_len, 16);
1018 write_tx_wr(txwr, toep, plen, adjusted_plen, credits,
1019 shove, ulp_submode);
1020 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
1026 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
1027 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
1028 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
1030 /* XXX: how will we recover from this? */
1031 toep->flags |= TPF_TX_SUSPENDED;
1035 credits = howmany(wr_len, 16);
1036 write_tx_wr(txwr, toep, 0, adjusted_plen, credits,
1037 shove, ulp_submode);
1038 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
1041 uint64_t *pad = (uint64_t *)
1042 ((uintptr_t)txwr + wr_len);
1047 KASSERT(toep->tx_credits >= credits,
1048 ("%s: not enough credits", __func__));
1050 m = mbufq_dequeue(pduq);
1052 mbufq_enqueue(&toep->ulp_pdu_reclaimq, m);
1054 toep->tx_credits -= credits;
1055 toep->tx_nocompl += credits;
1056 toep->plen_nocompl += plen;
1057 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
1058 toep->tx_nocompl >= toep->tx_total / 4) {
1059 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
1060 toep->tx_nocompl = 0;
1061 toep->plen_nocompl = 0;
1064 tp->snd_nxt += adjusted_plen;
1065 tp->snd_max += adjusted_plen;
1067 toep->flags |= TPF_TX_DATA_SENT;
1068 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
1069 toep->flags |= TPF_TX_SUSPENDED;
1071 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
1073 txsd->tx_credits = credits;
1075 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
1076 toep->txsd_pidx = 0;
1077 txsd = &toep->txsd[0];
1081 t4_l2t_send(sc, wr, toep->l2te);
1084 /* Send a FIN if requested, but only if there are no more PDUs to send */
1085 if (mbufq_first(pduq) == NULL && toep->flags & TPF_SEND_FIN)
1086 t4_close_conn(sc, toep);
1090 t4_tod_output(struct toedev *tod, struct tcpcb *tp)
1092 struct adapter *sc = tod->tod_softc;
1094 struct inpcb *inp = tp->t_inpcb;
1096 struct toepcb *toep = tp->t_toe;
1098 INP_WLOCK_ASSERT(inp);
1099 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1100 ("%s: inp %p dropped.", __func__, inp));
1101 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1103 if (ulp_mode(toep) == ULP_MODE_ISCSI)
1104 t4_push_pdus(sc, toep, 0);
1105 else if (tls_tx_key(toep))
1106 t4_push_tls_records(sc, toep, 0);
1108 t4_push_frames(sc, toep, 0);
1114 t4_send_fin(struct toedev *tod, struct tcpcb *tp)
1116 struct adapter *sc = tod->tod_softc;
1118 struct inpcb *inp = tp->t_inpcb;
1120 struct toepcb *toep = tp->t_toe;
1122 INP_WLOCK_ASSERT(inp);
1123 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1124 ("%s: inp %p dropped.", __func__, inp));
1125 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1127 toep->flags |= TPF_SEND_FIN;
1128 if (tp->t_state >= TCPS_ESTABLISHED) {
1129 if (ulp_mode(toep) == ULP_MODE_ISCSI)
1130 t4_push_pdus(sc, toep, 0);
1131 else if (tls_tx_key(toep))
1132 t4_push_tls_records(sc, toep, 0);
1134 t4_push_frames(sc, toep, 0);
1141 t4_send_rst(struct toedev *tod, struct tcpcb *tp)
1143 struct adapter *sc = tod->tod_softc;
1144 #if defined(INVARIANTS)
1145 struct inpcb *inp = tp->t_inpcb;
1147 struct toepcb *toep = tp->t_toe;
1149 INP_WLOCK_ASSERT(inp);
1150 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1151 ("%s: inp %p dropped.", __func__, inp));
1152 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1155 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
1156 ("%s: flowc for tid %u [%s] not sent already",
1157 __func__, toep->tid, tcpstates[tp->t_state]));
1159 send_reset(sc, toep, 0);
1164 * Peer has sent us a FIN.
1167 do_peer_close(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1169 struct adapter *sc = iq->adapter;
1170 const struct cpl_peer_close *cpl = (const void *)(rss + 1);
1171 unsigned int tid = GET_TID(cpl);
1172 struct toepcb *toep = lookup_tid(sc, tid);
1173 struct inpcb *inp = toep->inp;
1174 struct tcpcb *tp = NULL;
1176 struct epoch_tracker et;
1178 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1181 KASSERT(opcode == CPL_PEER_CLOSE,
1182 ("%s: unexpected opcode 0x%x", __func__, opcode));
1183 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1185 if (__predict_false(toep->flags & TPF_SYNQE)) {
1187 * do_pass_establish must have run before do_peer_close and if
1188 * this is still a synqe instead of a toepcb then the connection
1189 * must be getting aborted.
1191 MPASS(toep->flags & TPF_ABORT_SHUTDOWN);
1192 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1197 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1199 CURVNET_SET(toep->vnet);
1200 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1202 tp = intotcpcb(inp);
1205 "%s: tid %u (%s), toep_flags 0x%x, ddp_flags 0x%x, inp %p",
1206 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags,
1207 toep->ddp.flags, inp);
1209 if (toep->flags & TPF_ABORT_SHUTDOWN)
1212 tp->rcv_nxt++; /* FIN */
1214 so = inp->inp_socket;
1216 if (ulp_mode(toep) == ULP_MODE_TCPDDP) {
1218 if (__predict_false(toep->ddp.flags &
1219 (DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE)))
1220 handle_ddp_close(toep, tp, cpl->rcv_nxt);
1224 if (ulp_mode(toep) != ULP_MODE_RDMA) {
1225 KASSERT(tp->rcv_nxt == be32toh(cpl->rcv_nxt),
1226 ("%s: rcv_nxt mismatch: %u %u", __func__, tp->rcv_nxt,
1227 be32toh(cpl->rcv_nxt)));
1230 switch (tp->t_state) {
1231 case TCPS_SYN_RECEIVED:
1232 tp->t_starttime = ticks;
1235 case TCPS_ESTABLISHED:
1236 tcp_state_change(tp, TCPS_CLOSE_WAIT);
1239 case TCPS_FIN_WAIT_1:
1240 tcp_state_change(tp, TCPS_CLOSING);
1243 case TCPS_FIN_WAIT_2:
1245 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1246 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1250 final_cpl_received(toep);
1254 log(LOG_ERR, "%s: TID %u received CPL_PEER_CLOSE in state %d\n",
1255 __func__, tid, tp->t_state);
1259 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1265 * Peer has ACK'd our FIN.
1268 do_close_con_rpl(struct sge_iq *iq, const struct rss_header *rss,
1271 struct adapter *sc = iq->adapter;
1272 const struct cpl_close_con_rpl *cpl = (const void *)(rss + 1);
1273 unsigned int tid = GET_TID(cpl);
1274 struct toepcb *toep = lookup_tid(sc, tid);
1275 struct inpcb *inp = toep->inp;
1276 struct tcpcb *tp = NULL;
1277 struct socket *so = NULL;
1278 struct epoch_tracker et;
1280 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1283 KASSERT(opcode == CPL_CLOSE_CON_RPL,
1284 ("%s: unexpected opcode 0x%x", __func__, opcode));
1285 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1286 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1288 CURVNET_SET(toep->vnet);
1289 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1291 tp = intotcpcb(inp);
1293 CTR4(KTR_CXGBE, "%s: tid %u (%s), toep_flags 0x%x",
1294 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags);
1296 if (toep->flags & TPF_ABORT_SHUTDOWN)
1299 so = inp->inp_socket;
1300 tp->snd_una = be32toh(cpl->snd_nxt) - 1; /* exclude FIN */
1302 switch (tp->t_state) {
1303 case TCPS_CLOSING: /* see TCPS_FIN_WAIT_2 in do_peer_close too */
1306 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1307 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1311 final_cpl_received(toep); /* no more CPLs expected */
1319 case TCPS_FIN_WAIT_1:
1320 if (so->so_rcv.sb_state & SBS_CANTRCVMORE)
1321 soisdisconnected(so);
1322 tcp_state_change(tp, TCPS_FIN_WAIT_2);
1327 "%s: TID %u received CPL_CLOSE_CON_RPL in state %s\n",
1328 __func__, tid, tcpstates[tp->t_state]);
1332 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1338 send_abort_rpl(struct adapter *sc, struct sge_wrq *ofld_txq, int tid,
1342 struct cpl_abort_rpl *cpl;
1344 wr = alloc_wrqe(sizeof(*cpl), ofld_txq);
1347 panic("%s: allocation failure.", __func__);
1351 INIT_TP_WR_MIT_CPL(cpl, CPL_ABORT_RPL, tid);
1352 cpl->cmd = rst_status;
1358 abort_status_to_errno(struct tcpcb *tp, unsigned int abort_reason)
1360 switch (abort_reason) {
1361 case CPL_ERR_BAD_SYN:
1362 case CPL_ERR_CONN_RESET:
1363 return (tp->t_state == TCPS_CLOSE_WAIT ? EPIPE : ECONNRESET);
1364 case CPL_ERR_XMIT_TIMEDOUT:
1365 case CPL_ERR_PERSIST_TIMEDOUT:
1366 case CPL_ERR_FINWAIT2_TIMEDOUT:
1367 case CPL_ERR_KEEPALIVE_TIMEDOUT:
1375 * TCP RST from the peer, timeout, or some other such critical error.
1378 do_abort_req(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1380 struct adapter *sc = iq->adapter;
1381 const struct cpl_abort_req_rss *cpl = (const void *)(rss + 1);
1382 unsigned int tid = GET_TID(cpl);
1383 struct toepcb *toep = lookup_tid(sc, tid);
1384 struct sge_wrq *ofld_txq = toep->ofld_txq;
1387 struct epoch_tracker et;
1389 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1392 KASSERT(opcode == CPL_ABORT_REQ_RSS,
1393 ("%s: unexpected opcode 0x%x", __func__, opcode));
1394 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1396 if (toep->flags & TPF_SYNQE)
1397 return (do_abort_req_synqe(iq, rss, m));
1399 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1401 if (negative_advice(cpl->status)) {
1402 CTR4(KTR_CXGBE, "%s: negative advice %d for tid %d (0x%x)",
1403 __func__, cpl->status, tid, toep->flags);
1404 return (0); /* Ignore negative advice */
1408 CURVNET_SET(toep->vnet);
1409 INP_INFO_RLOCK_ET(&V_tcbinfo, et); /* for tcp_close */
1412 tp = intotcpcb(inp);
1415 "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x, status %d",
1416 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags,
1417 inp->inp_flags, cpl->status);
1420 * If we'd initiated an abort earlier the reply to it is responsible for
1421 * cleaning up resources. Otherwise we tear everything down right here
1422 * right now. We owe the T4 a CPL_ABORT_RPL no matter what.
1424 if (toep->flags & TPF_ABORT_SHUTDOWN) {
1428 toep->flags |= TPF_ABORT_SHUTDOWN;
1430 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
1431 struct socket *so = inp->inp_socket;
1434 so_error_set(so, abort_status_to_errno(tp,
1438 INP_WLOCK(inp); /* re-acquire */
1441 final_cpl_received(toep);
1443 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1445 send_abort_rpl(sc, ofld_txq, tid, CPL_ABORT_NO_RST);
1450 * Reply to the CPL_ABORT_REQ (send_reset)
1453 do_abort_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1455 struct adapter *sc = iq->adapter;
1456 const struct cpl_abort_rpl_rss *cpl = (const void *)(rss + 1);
1457 unsigned int tid = GET_TID(cpl);
1458 struct toepcb *toep = lookup_tid(sc, tid);
1459 struct inpcb *inp = toep->inp;
1461 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1464 KASSERT(opcode == CPL_ABORT_RPL_RSS,
1465 ("%s: unexpected opcode 0x%x", __func__, opcode));
1466 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1468 if (toep->flags & TPF_SYNQE)
1469 return (do_abort_rpl_synqe(iq, rss, m));
1471 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1473 CTR5(KTR_CXGBE, "%s: tid %u, toep %p, inp %p, status %d",
1474 __func__, tid, toep, inp, cpl->status);
1476 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1477 ("%s: wasn't expecting abort reply", __func__));
1480 final_cpl_received(toep);
1486 do_rx_data(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1488 struct adapter *sc = iq->adapter;
1489 const struct cpl_rx_data *cpl = mtod(m, const void *);
1490 unsigned int tid = GET_TID(cpl);
1491 struct toepcb *toep = lookup_tid(sc, tid);
1492 struct inpcb *inp = toep->inp;
1496 struct epoch_tracker et;
1497 int len, rx_credits;
1498 uint32_t ddp_placed = 0;
1500 if (__predict_false(toep->flags & TPF_SYNQE)) {
1502 * do_pass_establish must have run before do_rx_data and if this
1503 * is still a synqe instead of a toepcb then the connection must
1504 * be getting aborted.
1506 MPASS(toep->flags & TPF_ABORT_SHUTDOWN);
1507 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1513 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1515 /* strip off CPL header */
1516 m_adj(m, sizeof(*cpl));
1517 len = m->m_pkthdr.len;
1520 if (inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) {
1521 CTR4(KTR_CXGBE, "%s: tid %u, rx (%d bytes), inp_flags 0x%x",
1522 __func__, tid, len, inp->inp_flags);
1528 tp = intotcpcb(inp);
1530 if (__predict_false(tp->rcv_nxt != be32toh(cpl->seq)))
1531 ddp_placed = be32toh(cpl->seq) - tp->rcv_nxt;
1534 if (tp->rcv_wnd < len) {
1535 KASSERT(ulp_mode(toep) == ULP_MODE_RDMA,
1536 ("%s: negative window size", __func__));
1540 tp->t_rcvtime = ticks;
1542 if (ulp_mode(toep) == ULP_MODE_TCPDDP)
1544 so = inp_inpcbtosocket(inp);
1548 if (__predict_false(sb->sb_state & SBS_CANTRCVMORE)) {
1549 CTR3(KTR_CXGBE, "%s: tid %u, excess rx (%d bytes)",
1550 __func__, tid, len);
1553 if (ulp_mode(toep) == ULP_MODE_TCPDDP)
1557 CURVNET_SET(toep->vnet);
1558 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1560 tp = tcp_drop(tp, ECONNRESET);
1563 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1569 /* receive buffer autosize */
1570 MPASS(toep->vnet == so->so_vnet);
1571 CURVNET_SET(toep->vnet);
1572 if (sb->sb_flags & SB_AUTOSIZE &&
1573 V_tcp_do_autorcvbuf &&
1574 sb->sb_hiwat < V_tcp_autorcvbuf_max &&
1575 len > (sbspace(sb) / 8 * 7)) {
1576 unsigned int hiwat = sb->sb_hiwat;
1577 unsigned int newsize = min(hiwat + sc->tt.autorcvbuf_inc,
1578 V_tcp_autorcvbuf_max);
1580 if (!sbreserve_locked(sb, newsize, so, NULL))
1581 sb->sb_flags &= ~SB_AUTOSIZE;
1584 if (ulp_mode(toep) == ULP_MODE_TCPDDP) {
1585 int changed = !(toep->ddp.flags & DDP_ON) ^ cpl->ddp_off;
1587 if (toep->ddp.waiting_count != 0 || toep->ddp.active_count != 0)
1588 CTR3(KTR_CXGBE, "%s: tid %u, non-ddp rx (%d bytes)",
1589 __func__, tid, len);
1592 if (toep->ddp.flags & DDP_SC_REQ)
1593 toep->ddp.flags ^= DDP_ON | DDP_SC_REQ;
1595 KASSERT(cpl->ddp_off == 1,
1596 ("%s: DDP switched on by itself.",
1599 /* Fell out of DDP mode */
1600 toep->ddp.flags &= ~DDP_ON;
1601 CTR1(KTR_CXGBE, "%s: fell out of DDP mode",
1604 insert_ddp_data(toep, ddp_placed);
1608 if (toep->ddp.flags & DDP_ON) {
1610 * CPL_RX_DATA with DDP on can only be an indicate.
1611 * Start posting queued AIO requests via DDP. The
1612 * payload that arrived in this indicate is appended
1613 * to the socket buffer as usual.
1615 handle_ddp_indicate(toep);
1619 sbappendstream_locked(sb, m, 0);
1620 rx_credits = sbspace(sb) > tp->rcv_wnd ? sbspace(sb) - tp->rcv_wnd : 0;
1621 if (rx_credits > 0 && sbused(sb) + tp->rcv_wnd < sb->sb_lowat) {
1622 rx_credits = send_rx_credits(sc, toep, rx_credits);
1623 tp->rcv_wnd += rx_credits;
1624 tp->rcv_adv += rx_credits;
1627 if (ulp_mode(toep) == ULP_MODE_TCPDDP && toep->ddp.waiting_count > 0 &&
1629 CTR2(KTR_CXGBE, "%s: tid %u queueing AIO task", __func__,
1631 ddp_queue_toep(toep);
1633 sorwakeup_locked(so);
1634 SOCKBUF_UNLOCK_ASSERT(sb);
1635 if (ulp_mode(toep) == ULP_MODE_TCPDDP)
1644 do_fw4_ack(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1646 struct adapter *sc = iq->adapter;
1647 const struct cpl_fw4_ack *cpl = (const void *)(rss + 1);
1648 unsigned int tid = G_CPL_FW4_ACK_FLOWID(be32toh(OPCODE_TID(cpl)));
1649 struct toepcb *toep = lookup_tid(sc, tid);
1653 uint8_t credits = cpl->credits;
1654 struct ofld_tx_sdesc *txsd;
1657 unsigned int opcode = G_CPL_FW4_ACK_OPCODE(be32toh(OPCODE_TID(cpl)));
1661 * Very unusual case: we'd sent a flowc + abort_req for a synq entry and
1662 * now this comes back carrying the credits for the flowc.
1664 if (__predict_false(toep->flags & TPF_SYNQE)) {
1665 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1666 ("%s: credits for a synq entry %p", __func__, toep));
1672 KASSERT(opcode == CPL_FW4_ACK,
1673 ("%s: unexpected opcode 0x%x", __func__, opcode));
1674 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1675 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1679 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN)) {
1684 KASSERT((inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) == 0,
1685 ("%s: inp_flags 0x%x", __func__, inp->inp_flags));
1687 tp = intotcpcb(inp);
1689 if (cpl->flags & CPL_FW4_ACK_FLAGS_SEQVAL) {
1690 tcp_seq snd_una = be32toh(cpl->snd_una);
1693 if (__predict_false(SEQ_LT(snd_una, tp->snd_una))) {
1695 "%s: unexpected seq# %x for TID %u, snd_una %x\n",
1696 __func__, snd_una, toep->tid, tp->snd_una);
1700 if (tp->snd_una != snd_una) {
1701 tp->snd_una = snd_una;
1702 tp->ts_recent_age = tcp_ts_getticks();
1706 #ifdef VERBOSE_TRACES
1707 CTR3(KTR_CXGBE, "%s: tid %d credits %u", __func__, tid, credits);
1709 so = inp->inp_socket;
1710 txsd = &toep->txsd[toep->txsd_cidx];
1713 KASSERT(credits >= txsd->tx_credits,
1714 ("%s: too many (or partial) credits", __func__));
1715 credits -= txsd->tx_credits;
1716 toep->tx_credits += txsd->tx_credits;
1718 if (txsd->iv_buffer) {
1719 free(txsd->iv_buffer, M_CXGBE);
1720 txsd->iv_buffer = NULL;
1724 KASSERT(toep->txsd_avail <= toep->txsd_total,
1725 ("%s: txsd avail > total", __func__));
1726 if (__predict_false(++toep->txsd_cidx == toep->txsd_total)) {
1727 txsd = &toep->txsd[0];
1728 toep->txsd_cidx = 0;
1732 if (toep->tx_credits == toep->tx_total) {
1733 toep->tx_nocompl = 0;
1734 toep->plen_nocompl = 0;
1737 if (toep->flags & TPF_TX_SUSPENDED &&
1738 toep->tx_credits >= toep->tx_total / 4) {
1739 #ifdef VERBOSE_TRACES
1740 CTR2(KTR_CXGBE, "%s: tid %d calling t4_push_frames", __func__,
1743 toep->flags &= ~TPF_TX_SUSPENDED;
1744 CURVNET_SET(toep->vnet);
1745 if (ulp_mode(toep) == ULP_MODE_ISCSI)
1746 t4_push_pdus(sc, toep, plen);
1747 else if (tls_tx_key(toep))
1748 t4_push_tls_records(sc, toep, plen);
1750 t4_push_frames(sc, toep, plen);
1752 } else if (plen > 0) {
1753 struct sockbuf *sb = &so->so_snd;
1758 if (ulp_mode(toep) == ULP_MODE_ISCSI) {
1760 if (__predict_false(sbu > 0)) {
1762 * The data trasmitted before the tid's ULP mode
1763 * changed to ISCSI is still in so_snd.
1764 * Incoming credits should account for so_snd
1767 sbdrop_locked(sb, min(sbu, plen));
1768 plen -= min(sbu, plen);
1770 sowwakeup_locked(so); /* unlocks so_snd */
1771 rqdrop_locked(&toep->ulp_pdu_reclaimq, plen);
1773 #ifdef VERBOSE_TRACES
1774 CTR3(KTR_CXGBE, "%s: tid %d dropped %d bytes", __func__,
1777 sbdrop_locked(sb, plen);
1778 if (tls_tx_key(toep)) {
1779 struct tls_ofld_info *tls_ofld = &toep->tls;
1781 MPASS(tls_ofld->sb_off >= plen);
1782 tls_ofld->sb_off -= plen;
1784 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
1785 t4_aiotx_queue_toep(so, toep);
1786 sowwakeup_locked(so); /* unlocks so_snd */
1788 SOCKBUF_UNLOCK_ASSERT(sb);
1797 t4_set_tcb_field(struct adapter *sc, struct sge_wrq *wrq, struct toepcb *toep,
1798 uint16_t word, uint64_t mask, uint64_t val, int reply, int cookie)
1801 struct cpl_set_tcb_field *req;
1802 struct ofld_tx_sdesc *txsd;
1804 MPASS((cookie & ~M_COOKIE) == 0);
1806 MPASS(cookie != CPL_COOKIE_RESERVED);
1809 wr = alloc_wrqe(sizeof(*req), wrq);
1812 panic("%s: allocation failure.", __func__);
1816 INIT_TP_WR_MIT_CPL(req, CPL_SET_TCB_FIELD, toep->tid);
1817 req->reply_ctrl = htobe16(V_QUEUENO(toep->ofld_rxq->iq.abs_id));
1819 req->reply_ctrl |= htobe16(F_NO_REPLY);
1820 req->word_cookie = htobe16(V_WORD(word) | V_COOKIE(cookie));
1821 req->mask = htobe64(mask);
1822 req->val = htobe64(val);
1823 if ((wrq->eq.flags & EQ_TYPEMASK) == EQ_OFLD) {
1824 txsd = &toep->txsd[toep->txsd_pidx];
1825 txsd->tx_credits = howmany(sizeof(*req), 16);
1827 KASSERT(toep->tx_credits >= txsd->tx_credits &&
1828 toep->txsd_avail > 0,
1829 ("%s: not enough credits (%d)", __func__,
1831 toep->tx_credits -= txsd->tx_credits;
1832 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
1833 toep->txsd_pidx = 0;
1841 t4_init_cpl_io_handlers(void)
1844 t4_register_cpl_handler(CPL_PEER_CLOSE, do_peer_close);
1845 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, do_close_con_rpl);
1846 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, do_abort_req);
1847 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS, do_abort_rpl,
1849 t4_register_cpl_handler(CPL_RX_DATA, do_rx_data);
1850 t4_register_shared_cpl_handler(CPL_FW4_ACK, do_fw4_ack, CPL_COOKIE_TOM);
1854 t4_uninit_cpl_io_handlers(void)
1857 t4_register_cpl_handler(CPL_PEER_CLOSE, NULL);
1858 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, NULL);
1859 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, NULL);
1860 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS, NULL, CPL_COOKIE_TOM);
1861 t4_register_cpl_handler(CPL_RX_DATA, NULL);
1862 t4_register_shared_cpl_handler(CPL_FW4_ACK, NULL, CPL_COOKIE_TOM);
1866 * Use the 'backend1' field in AIO jobs to hold an error that should
1867 * be reported when the job is completed, the 'backend3' field to
1868 * store the amount of data sent by the AIO job so far, and the
1869 * 'backend4' field to hold a reference count on the job.
1871 * Each unmapped mbuf holds a reference on the job as does the queue
1872 * so long as the job is queued.
1874 #define aio_error backend1
1875 #define aio_sent backend3
1876 #define aio_refs backend4
1878 #define jobtotid(job) \
1879 (((struct toepcb *)(so_sototcpcb((job)->fd_file->f_data)->t_toe))->tid)
1882 aiotx_free_job(struct kaiocb *job)
1887 if (refcount_release(&job->aio_refs) == 0)
1890 error = (intptr_t)job->aio_error;
1891 status = job->aio_sent;
1892 #ifdef VERBOSE_TRACES
1893 CTR5(KTR_CXGBE, "%s: tid %d completed %p len %ld, error %d", __func__,
1894 jobtotid(job), job, status, error);
1896 if (error != 0 && status != 0)
1898 if (error == ECANCELED)
1901 aio_complete(job, -1, error);
1904 aio_complete(job, status, 0);
1909 aiotx_free_pgs(struct mbuf *m)
1911 struct mbuf_ext_pgs *ext_pgs;
1916 MBUF_EXT_PGS_ASSERT(m);
1917 ext_pgs = m->m_ext.ext_pgs;
1918 job = m->m_ext.ext_arg1;
1919 #ifdef VERBOSE_TRACES
1920 CTR3(KTR_CXGBE, "%s: completed %d bytes for tid %d", __func__,
1921 m->m_len, jobtotid(job));
1925 for (int i = 0; i < ext_pgs->npgs; i++) {
1926 pg = PHYS_TO_VM_PAGE(ext_pgs->pa[i]);
1927 vm_page_change_lock(pg, &mtx);
1928 vm_page_unwire(pg, PQ_ACTIVE);
1933 aiotx_free_job(job);
1937 * Allocate a chain of unmapped mbufs describing the next 'len' bytes
1940 static struct mbuf *
1941 alloc_aiotx_mbuf(struct kaiocb *job, int len)
1944 vm_page_t pgs[MBUF_PEXT_MAX_PGS];
1945 struct mbuf *m, *top, *last;
1946 struct mbuf_ext_pgs *ext_pgs;
1949 int i, mlen, npages, pgoff;
1951 KASSERT(job->aio_sent + len <= job->uaiocb.aio_nbytes,
1952 ("%s(%p, %d): request to send beyond end of buffer", __func__,
1956 * The AIO subsystem will cancel and drain all requests before
1957 * permitting a process to exit or exec, so p_vmspace should
1960 vm = job->userproc->p_vmspace;
1962 start = (uintptr_t)job->uaiocb.aio_buf + job->aio_sent;
1963 pgoff = start & PAGE_MASK;
1968 mlen = imin(len, MBUF_PEXT_MAX_PGS * PAGE_SIZE - pgoff);
1969 KASSERT(mlen == len || ((start + mlen) & PAGE_MASK) == 0,
1970 ("%s: next start (%#jx + %#x) is not page aligned",
1971 __func__, (uintmax_t)start, mlen));
1973 npages = vm_fault_quick_hold_pages(map, start, mlen,
1974 VM_PROT_WRITE, pgs, nitems(pgs));
1978 m = mb_alloc_ext_pgs(M_WAITOK, false, aiotx_free_pgs);
1980 vm_page_unhold_pages(pgs, npages);
1984 ext_pgs = m->m_ext.ext_pgs;
1985 ext_pgs->first_pg_off = pgoff;
1986 ext_pgs->npgs = npages;
1988 KASSERT(mlen + pgoff <= PAGE_SIZE,
1989 ("%s: single page is too large (off %d len %d)",
1990 __func__, pgoff, mlen));
1991 ext_pgs->last_pg_len = mlen;
1993 ext_pgs->last_pg_len = mlen - (PAGE_SIZE - pgoff) -
1994 (npages - 2) * PAGE_SIZE;
1996 for (i = 0; i < npages; i++)
1997 ext_pgs->pa[i] = VM_PAGE_TO_PHYS(pgs[i]);
2000 m->m_ext.ext_size = npages * PAGE_SIZE;
2001 m->m_ext.ext_arg1 = job;
2002 refcount_acquire(&job->aio_refs);
2004 #ifdef VERBOSE_TRACES
2005 CTR5(KTR_CXGBE, "%s: tid %d, new mbuf %p for job %p, npages %d",
2006 __func__, jobtotid(job), m, job, npages);
2024 t4_aiotx_process_job(struct toepcb *toep, struct socket *so, struct kaiocb *job)
2032 bool moretocome, sendmore;
2040 error = mac_socket_check_send(fp->f_cred, so);
2045 /* Inline sosend_generic(). */
2047 error = sblock(sb, SBL_WAIT);
2052 if (so->so_snd.sb_state & SBS_CANTSENDMORE) {
2055 if ((so->so_options & SO_NOSIGPIPE) == 0) {
2056 PROC_LOCK(job->userproc);
2057 kern_psignal(job->userproc, SIGPIPE);
2058 PROC_UNLOCK(job->userproc);
2064 error = so->so_error;
2070 if ((so->so_state & SS_ISCONNECTED) == 0) {
2076 if (sbspace(sb) < sb->sb_lowat) {
2077 MPASS(job->aio_sent == 0 || !(so->so_state & SS_NBIO));
2080 * Don't block if there is too little room in the socket
2081 * buffer. Instead, requeue the request.
2083 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2089 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2096 * Write as much data as the socket permits, but no more than a
2097 * a single sndbuf at a time.
2100 if (len > job->uaiocb.aio_nbytes - job->aio_sent) {
2101 len = job->uaiocb.aio_nbytes - job->aio_sent;
2105 if (len > toep->params.sndbuf) {
2106 len = toep->params.sndbuf;
2111 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
2116 m = alloc_aiotx_mbuf(job, len);
2123 /* Inlined tcp_usr_send(). */
2127 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
2134 job->aio_sent += m_length(m, NULL);
2136 sbappendstream(sb, m, 0);
2139 if (!(inp->inp_flags & INP_DROPPED)) {
2140 tp = intotcpcb(inp);
2142 tp->t_flags |= TF_MORETOCOME;
2143 error = tp->t_fb->tfb_tcp_output(tp);
2145 tp->t_flags &= ~TF_MORETOCOME;
2157 * If this is a blocking socket and the request has not been
2158 * fully completed, requeue it until the socket is ready
2161 if (job->aio_sent < job->uaiocb.aio_nbytes &&
2162 !(so->so_state & SS_NBIO)) {
2164 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2169 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2174 * If the request will not be requeued, drop the queue's
2175 * reference to the job. Any mbufs in flight should still
2176 * hold a reference, but this drops the reference that the
2177 * queue owns while it is waiting to queue mbufs to the
2180 aiotx_free_job(job);
2184 job->aio_error = (void *)(intptr_t)error;
2185 aiotx_free_job(job);
2193 t4_aiotx_task(void *context, int pending)
2195 struct toepcb *toep = context;
2199 so = toep->aiotx_so;
2200 CURVNET_SET(toep->vnet);
2201 SOCKBUF_LOCK(&so->so_snd);
2202 while (!TAILQ_EMPTY(&toep->aiotx_jobq) && sowriteable(so)) {
2203 job = TAILQ_FIRST(&toep->aiotx_jobq);
2204 TAILQ_REMOVE(&toep->aiotx_jobq, job, list);
2205 if (!aio_clear_cancel_function(job))
2208 t4_aiotx_process_job(toep, so, job);
2210 toep->aiotx_so = NULL;
2211 SOCKBUF_UNLOCK(&so->so_snd);
2220 t4_aiotx_queue_toep(struct socket *so, struct toepcb *toep)
2223 SOCKBUF_LOCK_ASSERT(&toep->inp->inp_socket->so_snd);
2224 #ifdef VERBOSE_TRACES
2225 CTR3(KTR_CXGBE, "%s: queueing aiotx task for tid %d, active = %s",
2226 __func__, toep->tid, toep->aiotx_so != NULL ? "true" : "false");
2228 if (toep->aiotx_so != NULL)
2231 toep->aiotx_so = so;
2233 soaio_enqueue(&toep->aiotx_task);
2237 t4_aiotx_cancel(struct kaiocb *job)
2242 struct toepcb *toep;
2244 so = job->fd_file->f_data;
2245 tp = so_sototcpcb(so);
2247 MPASS(job->uaiocb.aio_lio_opcode == LIO_WRITE);
2251 if (!aio_cancel_cleared(job))
2252 TAILQ_REMOVE(&toep->aiotx_jobq, job, list);
2255 job->aio_error = (void *)(intptr_t)ECANCELED;
2256 aiotx_free_job(job);
2260 t4_aio_queue_aiotx(struct socket *so, struct kaiocb *job)
2262 struct tcpcb *tp = so_sototcpcb(so);
2263 struct toepcb *toep = tp->t_toe;
2264 struct adapter *sc = td_adapter(toep->td);
2266 /* This only handles writes. */
2267 if (job->uaiocb.aio_lio_opcode != LIO_WRITE)
2268 return (EOPNOTSUPP);
2270 if (!sc->tt.tx_zcopy)
2271 return (EOPNOTSUPP);
2273 if (tls_tx_key(toep))
2274 return (EOPNOTSUPP);
2276 SOCKBUF_LOCK(&so->so_snd);
2277 #ifdef VERBOSE_TRACES
2278 CTR3(KTR_CXGBE, "%s: queueing %p for tid %u", __func__, job, toep->tid);
2280 if (!aio_set_cancel_function(job, t4_aiotx_cancel))
2281 panic("new job was cancelled");
2282 refcount_init(&job->aio_refs, 1);
2283 TAILQ_INSERT_TAIL(&toep->aiotx_jobq, job, list);
2284 if (sowriteable(so))
2285 t4_aiotx_queue_toep(so, toep);
2286 SOCKBUF_UNLOCK(&so->so_snd);
2291 aiotx_init_toep(struct toepcb *toep)
2294 TAILQ_INIT(&toep->aiotx_jobq);
2295 TASK_INIT(&toep->aiotx_task, 0, t4_aiotx_task, toep);