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 toepcb *toep);
80 aiotx_mbuf_pgoff(struct mbuf *m)
82 struct aiotx_buffer *ab;
84 MPASS(IS_AIOTX_MBUF(m));
85 ab = m->m_ext.ext_arg1;
86 return ((ab->ps.offset + (uintptr_t)m->m_ext.ext_arg2) % PAGE_SIZE);
90 aiotx_mbuf_pages(struct mbuf *m)
92 struct aiotx_buffer *ab;
95 MPASS(IS_AIOTX_MBUF(m));
96 ab = m->m_ext.ext_arg1;
97 npages = (ab->ps.offset + (uintptr_t)m->m_ext.ext_arg2) / PAGE_SIZE;
98 return (ab->ps.pages + npages);
102 send_flowc_wr(struct toepcb *toep, struct flowc_tx_params *ftxp)
105 struct fw_flowc_wr *flowc;
106 unsigned int nparams, flowclen, paramidx;
107 struct vi_info *vi = toep->vi;
108 struct port_info *pi = vi->pi;
109 struct adapter *sc = pi->adapter;
110 unsigned int pfvf = sc->pf << S_FW_VIID_PFN;
111 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
113 KASSERT(!(toep->flags & TPF_FLOWC_WR_SENT),
114 ("%s: flowc for tid %u sent already", __func__, toep->tid));
120 if (toep->ulp_mode == ULP_MODE_TLS)
122 if (toep->tls.fcplenmax != 0)
124 if (toep->tc_idx != -1) {
125 MPASS(toep->tc_idx >= 0 &&
126 toep->tc_idx < sc->chip_params->nsched_cls);
130 flowclen = sizeof(*flowc) + nparams * sizeof(struct fw_flowc_mnemval);
132 wr = alloc_wrqe(roundup2(flowclen, 16), toep->ofld_txq);
135 panic("%s: allocation failure.", __func__);
138 memset(flowc, 0, wr->wr_len);
140 flowc->op_to_nparams = htobe32(V_FW_WR_OP(FW_FLOWC_WR) |
141 V_FW_FLOWC_WR_NPARAMS(nparams));
142 flowc->flowid_len16 = htonl(V_FW_WR_LEN16(howmany(flowclen, 16)) |
143 V_FW_WR_FLOWID(toep->tid));
145 #define FLOWC_PARAM(__m, __v) \
147 flowc->mnemval[paramidx].mnemonic = FW_FLOWC_MNEM_##__m; \
148 flowc->mnemval[paramidx].val = htobe32(__v); \
154 FLOWC_PARAM(PFNVFN, pfvf);
155 FLOWC_PARAM(CH, pi->tx_chan);
156 FLOWC_PARAM(PORT, pi->tx_chan);
157 FLOWC_PARAM(IQID, toep->ofld_rxq->iq.abs_id);
159 uint32_t sndbuf = min(ftxp->snd_space, sc->tt.sndbuf);
161 FLOWC_PARAM(SNDNXT, ftxp->snd_nxt);
162 FLOWC_PARAM(RCVNXT, ftxp->rcv_nxt);
163 FLOWC_PARAM(SNDBUF, sndbuf);
164 FLOWC_PARAM(MSS, ftxp->mss);
167 "%s: tid %u, mss %u, sndbuf %u, snd_nxt 0x%x, rcv_nxt 0x%x",
168 __func__, toep->tid, ftxp->mss, sndbuf, ftxp->snd_nxt,
171 FLOWC_PARAM(SNDBUF, 512);
172 FLOWC_PARAM(MSS, 512);
174 CTR2(KTR_CXGBE, "%s: tid %u", __func__, toep->tid);
176 if (toep->ulp_mode == ULP_MODE_TLS)
177 FLOWC_PARAM(ULP_MODE, toep->ulp_mode);
178 if (toep->tls.fcplenmax != 0)
179 FLOWC_PARAM(TXDATAPLEN_MAX, toep->tls.fcplenmax);
180 if (toep->tc_idx != -1)
181 FLOWC_PARAM(SCHEDCLASS, toep->tc_idx);
184 KASSERT(paramidx == nparams, ("nparams mismatch"));
186 txsd->tx_credits = howmany(flowclen, 16);
188 KASSERT(toep->tx_credits >= txsd->tx_credits && toep->txsd_avail > 0,
189 ("%s: not enough credits (%d)", __func__, toep->tx_credits));
190 toep->tx_credits -= txsd->tx_credits;
191 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
195 toep->flags |= TPF_FLOWC_WR_SENT;
201 * Input is Bytes/second (so_max_pacing_rate), chip counts in Kilobits/second.
204 update_tx_rate_limit(struct adapter *sc, struct toepcb *toep, u_int Bps)
207 const u_int kbps = (u_int) (uint64_t)Bps * 8ULL / 1000;
208 const int port_id = toep->vi->pi->port_id;
210 CTR3(KTR_CXGBE, "%s: tid %u, rate %uKbps", __func__, toep->tid, kbps);
216 rc = t4_reserve_cl_rl_kbps(sc, port_id, kbps, &tc_idx);
219 MPASS(tc_idx >= 0 && tc_idx < sc->chip_params->nsched_cls);
222 if (toep->tc_idx != tc_idx) {
224 struct fw_flowc_wr *flowc;
225 int nparams = 1, flowclen, flowclen16;
226 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
228 flowclen = sizeof(*flowc) + nparams * sizeof(struct
230 flowclen16 = howmany(flowclen, 16);
231 if (toep->tx_credits < flowclen16 || toep->txsd_avail == 0 ||
232 (wr = alloc_wrqe(roundup2(flowclen, 16), toep->ofld_txq)) == NULL) {
234 t4_release_cl_rl(sc, port_id, tc_idx);
239 memset(flowc, 0, wr->wr_len);
241 flowc->op_to_nparams = htobe32(V_FW_WR_OP(FW_FLOWC_WR) |
242 V_FW_FLOWC_WR_NPARAMS(nparams));
243 flowc->flowid_len16 = htonl(V_FW_WR_LEN16(flowclen16) |
244 V_FW_WR_FLOWID(toep->tid));
246 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
248 flowc->mnemval[0].val = htobe32(0xff);
250 flowc->mnemval[0].val = htobe32(tc_idx);
252 txsd->tx_credits = flowclen16;
254 toep->tx_credits -= txsd->tx_credits;
255 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
261 if (toep->tc_idx >= 0)
262 t4_release_cl_rl(sc, port_id, toep->tc_idx);
263 toep->tc_idx = tc_idx;
270 send_reset(struct adapter *sc, struct toepcb *toep, uint32_t snd_nxt)
273 struct cpl_abort_req *req;
275 struct inpcb *inp = toep->inp;
276 struct tcpcb *tp = intotcpcb(inp); /* don't use if INP_DROPPED */
278 INP_WLOCK_ASSERT(inp);
280 CTR6(KTR_CXGBE, "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x%s",
282 inp->inp_flags & INP_DROPPED ? "inp dropped" :
283 tcpstates[tp->t_state],
284 toep->flags, inp->inp_flags,
285 toep->flags & TPF_ABORT_SHUTDOWN ?
286 " (abort already in progress)" : "");
288 if (toep->flags & TPF_ABORT_SHUTDOWN)
289 return; /* abort already in progress */
291 toep->flags |= TPF_ABORT_SHUTDOWN;
293 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
294 ("%s: flowc_wr not sent for tid %d.", __func__, tid));
296 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
299 panic("%s: allocation failure.", __func__);
303 INIT_TP_WR_MIT_CPL(req, CPL_ABORT_REQ, tid);
304 if (inp->inp_flags & INP_DROPPED)
305 req->rsvd0 = htobe32(snd_nxt);
307 req->rsvd0 = htobe32(tp->snd_nxt);
308 req->rsvd1 = !(toep->flags & TPF_TX_DATA_SENT);
309 req->cmd = CPL_ABORT_SEND_RST;
312 * XXX: What's the correct way to tell that the inp hasn't been detached
313 * from its socket? Should I even be flushing the snd buffer here?
315 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
316 struct socket *so = inp->inp_socket;
318 if (so != NULL) /* because I'm not sure. See comment above */
319 sbflush(&so->so_snd);
322 t4_l2t_send(sc, wr, toep->l2te);
326 * Called when a connection is established to translate the TCP options
327 * reported by HW to FreeBSD's native format.
330 assign_rxopt(struct tcpcb *tp, unsigned int opt)
332 struct toepcb *toep = tp->t_toe;
333 struct inpcb *inp = tp->t_inpcb;
334 struct adapter *sc = td_adapter(toep->td);
337 INP_LOCK_ASSERT(inp);
339 if (inp->inp_inc.inc_flags & INC_ISIPV6)
340 n = sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
342 n = sizeof(struct ip) + sizeof(struct tcphdr);
343 tp->t_maxseg = sc->params.mtus[G_TCPOPT_MSS(opt)] - n;
345 if (G_TCPOPT_TSTAMP(opt)) {
346 tp->t_flags |= TF_RCVD_TSTMP; /* timestamps ok */
347 tp->ts_recent = 0; /* hmmm */
348 tp->ts_recent_age = tcp_ts_getticks();
349 tp->t_maxseg -= TCPOLEN_TSTAMP_APPA;
352 CTR5(KTR_CXGBE, "%s: tid %d, mtu_idx %u (%u), mss %u", __func__,
353 toep->tid, G_TCPOPT_MSS(opt), sc->params.mtus[G_TCPOPT_MSS(opt)],
356 if (G_TCPOPT_SACK(opt))
357 tp->t_flags |= TF_SACK_PERMIT; /* should already be set */
359 tp->t_flags &= ~TF_SACK_PERMIT; /* sack disallowed by peer */
361 if (G_TCPOPT_WSCALE_OK(opt))
362 tp->t_flags |= TF_RCVD_SCALE;
364 /* Doing window scaling? */
365 if ((tp->t_flags & (TF_RCVD_SCALE | TF_REQ_SCALE)) ==
366 (TF_RCVD_SCALE | TF_REQ_SCALE)) {
367 tp->rcv_scale = tp->request_r_scale;
368 tp->snd_scale = G_TCPOPT_SND_WSCALE(opt);
373 * Completes some final bits of initialization for just established connections
374 * and changes their state to TCPS_ESTABLISHED.
376 * The ISNs are from the exchange of SYNs.
379 make_established(struct toepcb *toep, uint32_t iss, uint32_t irs, uint16_t opt)
381 struct inpcb *inp = toep->inp;
382 struct socket *so = inp->inp_socket;
383 struct tcpcb *tp = intotcpcb(inp);
385 uint16_t tcpopt = be16toh(opt);
386 struct flowc_tx_params ftxp;
388 INP_WLOCK_ASSERT(inp);
389 KASSERT(tp->t_state == TCPS_SYN_SENT ||
390 tp->t_state == TCPS_SYN_RECEIVED,
391 ("%s: TCP state %s", __func__, tcpstates[tp->t_state]));
393 CTR6(KTR_CXGBE, "%s: tid %d, so %p, inp %p, tp %p, toep %p",
394 __func__, toep->tid, so, inp, tp, toep);
396 tcp_state_change(tp, TCPS_ESTABLISHED);
397 tp->t_starttime = ticks;
398 TCPSTAT_INC(tcps_connects);
402 tp->rcv_wnd = toep->opt0_rcv_bufsize << 10;
403 tp->rcv_adv += tp->rcv_wnd;
404 tp->last_ack_sent = tp->rcv_nxt;
408 tp->snd_una = iss + 1;
409 tp->snd_nxt = iss + 1;
410 tp->snd_max = iss + 1;
412 assign_rxopt(tp, tcpopt);
414 SOCKBUF_LOCK(&so->so_snd);
415 if (so->so_snd.sb_flags & SB_AUTOSIZE && V_tcp_do_autosndbuf)
416 bufsize = V_tcp_autosndbuf_max;
418 bufsize = sbspace(&so->so_snd);
419 SOCKBUF_UNLOCK(&so->so_snd);
421 ftxp.snd_nxt = tp->snd_nxt;
422 ftxp.rcv_nxt = tp->rcv_nxt;
423 ftxp.snd_space = bufsize;
424 ftxp.mss = tp->t_maxseg;
425 send_flowc_wr(toep, &ftxp);
431 send_rx_credits(struct adapter *sc, struct toepcb *toep, int credits)
434 struct cpl_rx_data_ack *req;
435 uint32_t dack = F_RX_DACK_CHANGE | V_RX_DACK_MODE(1);
437 KASSERT(credits >= 0, ("%s: %d credits", __func__, credits));
439 wr = alloc_wrqe(sizeof(*req), toep->ctrlq);
444 INIT_TP_WR_MIT_CPL(req, CPL_RX_DATA_ACK, toep->tid);
445 req->credit_dack = htobe32(dack | V_RX_CREDITS(credits));
452 send_rx_modulate(struct adapter *sc, struct toepcb *toep)
455 struct cpl_rx_data_ack *req;
457 wr = alloc_wrqe(sizeof(*req), toep->ctrlq);
462 INIT_TP_WR_MIT_CPL(req, CPL_RX_DATA_ACK, toep->tid);
463 req->credit_dack = htobe32(F_RX_MODULATE_RX);
469 t4_rcvd_locked(struct toedev *tod, struct tcpcb *tp)
471 struct adapter *sc = tod->tod_softc;
472 struct inpcb *inp = tp->t_inpcb;
473 struct socket *so = inp->inp_socket;
474 struct sockbuf *sb = &so->so_rcv;
475 struct toepcb *toep = tp->t_toe;
478 INP_WLOCK_ASSERT(inp);
479 SOCKBUF_LOCK_ASSERT(sb);
481 rx_credits = sbspace(sb) > tp->rcv_wnd ? sbspace(sb) - tp->rcv_wnd : 0;
482 if (toep->ulp_mode == ULP_MODE_TLS) {
483 if (toep->tls.rcv_over >= rx_credits) {
484 toep->tls.rcv_over -= rx_credits;
487 rx_credits -= toep->tls.rcv_over;
488 toep->tls.rcv_over = 0;
492 if (rx_credits > 0 &&
493 (tp->rcv_wnd <= 32 * 1024 || rx_credits >= 64 * 1024 ||
494 (rx_credits >= 16 * 1024 && tp->rcv_wnd <= 128 * 1024) ||
495 sbused(sb) + tp->rcv_wnd < sb->sb_lowat)) {
496 rx_credits = send_rx_credits(sc, toep, rx_credits);
497 tp->rcv_wnd += rx_credits;
498 tp->rcv_adv += rx_credits;
499 } else if (toep->flags & TPF_FORCE_CREDITS)
500 send_rx_modulate(sc, toep);
504 t4_rcvd(struct toedev *tod, struct tcpcb *tp)
506 struct inpcb *inp = tp->t_inpcb;
507 struct socket *so = inp->inp_socket;
508 struct sockbuf *sb = &so->so_rcv;
511 t4_rcvd_locked(tod, tp);
516 * Close a connection by sending a CPL_CLOSE_CON_REQ message.
519 t4_close_conn(struct adapter *sc, struct toepcb *toep)
522 struct cpl_close_con_req *req;
523 unsigned int tid = toep->tid;
525 CTR3(KTR_CXGBE, "%s: tid %u%s", __func__, toep->tid,
526 toep->flags & TPF_FIN_SENT ? ", IGNORED" : "");
528 if (toep->flags & TPF_FIN_SENT)
531 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
532 ("%s: flowc_wr not sent for tid %u.", __func__, tid));
534 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
537 panic("%s: allocation failure.", __func__);
541 req->wr.wr_hi = htonl(V_FW_WR_OP(FW_TP_WR) |
542 V_FW_WR_IMMDLEN(sizeof(*req) - sizeof(req->wr)));
543 req->wr.wr_mid = htonl(V_FW_WR_LEN16(howmany(sizeof(*req), 16)) |
544 V_FW_WR_FLOWID(tid));
545 req->wr.wr_lo = cpu_to_be64(0);
546 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
549 toep->flags |= TPF_FIN_SENT;
550 toep->flags &= ~TPF_SEND_FIN;
551 t4_l2t_send(sc, wr, toep->l2te);
556 #define MAX_OFLD_TX_CREDITS (SGE_MAX_WR_LEN / 16)
557 #define MIN_OFLD_TX_CREDITS (howmany(sizeof(struct fw_ofld_tx_data_wr) + 1, 16))
559 /* Maximum amount of immediate data we could stuff in a WR */
561 max_imm_payload(int tx_credits)
563 const int n = 2; /* Use only up to 2 desc for imm. data WR */
565 KASSERT(tx_credits >= 0 &&
566 tx_credits <= MAX_OFLD_TX_CREDITS,
567 ("%s: %d credits", __func__, tx_credits));
569 if (tx_credits < MIN_OFLD_TX_CREDITS)
572 if (tx_credits >= (n * EQ_ESIZE) / 16)
573 return ((n * EQ_ESIZE) - sizeof(struct fw_ofld_tx_data_wr));
575 return (tx_credits * 16 - sizeof(struct fw_ofld_tx_data_wr));
578 /* Maximum number of SGL entries we could stuff in a WR */
580 max_dsgl_nsegs(int tx_credits)
582 int nseg = 1; /* ulptx_sgl has room for 1, rest ulp_tx_sge_pair */
583 int sge_pair_credits = tx_credits - MIN_OFLD_TX_CREDITS;
585 KASSERT(tx_credits >= 0 &&
586 tx_credits <= MAX_OFLD_TX_CREDITS,
587 ("%s: %d credits", __func__, tx_credits));
589 if (tx_credits < MIN_OFLD_TX_CREDITS)
592 nseg += 2 * (sge_pair_credits * 16 / 24);
593 if ((sge_pair_credits * 16) % 24 == 16)
600 write_tx_wr(void *dst, struct toepcb *toep, unsigned int immdlen,
601 unsigned int plen, uint8_t credits, int shove, int ulp_submode, int txalign)
603 struct fw_ofld_tx_data_wr *txwr = dst;
605 txwr->op_to_immdlen = htobe32(V_WR_OP(FW_OFLD_TX_DATA_WR) |
606 V_FW_WR_IMMDLEN(immdlen));
607 txwr->flowid_len16 = htobe32(V_FW_WR_FLOWID(toep->tid) |
608 V_FW_WR_LEN16(credits));
609 txwr->lsodisable_to_flags = htobe32(V_TX_ULP_MODE(toep->ulp_mode) |
610 V_TX_ULP_SUBMODE(ulp_submode) | V_TX_URG(0) | V_TX_SHOVE(shove));
611 txwr->plen = htobe32(plen);
614 struct tcpcb *tp = intotcpcb(toep->inp);
616 if (plen < 2 * tp->t_maxseg)
617 txwr->lsodisable_to_flags |=
618 htobe32(F_FW_OFLD_TX_DATA_WR_LSODISABLE);
620 txwr->lsodisable_to_flags |=
621 htobe32(F_FW_OFLD_TX_DATA_WR_ALIGNPLD |
622 (tp->t_flags & TF_NODELAY ? 0 :
623 F_FW_OFLD_TX_DATA_WR_ALIGNPLDSHOVE));
628 * Generate a DSGL from a starting mbuf. The total number of segments and the
629 * maximum segments in any one mbuf are provided.
632 write_tx_sgl(void *dst, struct mbuf *start, struct mbuf *stop, int nsegs, int n)
635 struct ulptx_sgl *usgl = dst;
638 struct sglist_seg segs[n];
640 KASSERT(nsegs > 0, ("%s: nsegs 0", __func__));
642 sglist_init(&sg, n, segs);
643 usgl->cmd_nsge = htobe32(V_ULPTX_CMD(ULP_TX_SC_DSGL) |
644 V_ULPTX_NSGE(nsegs));
647 for (m = start; m != stop; m = m->m_next) {
648 if (IS_AIOTX_MBUF(m))
649 rc = sglist_append_vmpages(&sg, aiotx_mbuf_pages(m),
650 aiotx_mbuf_pgoff(m), m->m_len);
652 rc = sglist_append(&sg, mtod(m, void *), m->m_len);
653 if (__predict_false(rc != 0))
654 panic("%s: sglist_append %d", __func__, rc);
656 for (j = 0; j < sg.sg_nseg; i++, j++) {
658 usgl->len0 = htobe32(segs[j].ss_len);
659 usgl->addr0 = htobe64(segs[j].ss_paddr);
661 usgl->sge[i / 2].len[i & 1] =
662 htobe32(segs[j].ss_len);
663 usgl->sge[i / 2].addr[i & 1] =
664 htobe64(segs[j].ss_paddr);
673 usgl->sge[i / 2].len[1] = htobe32(0);
674 KASSERT(nsegs == 0, ("%s: nsegs %d, start %p, stop %p",
675 __func__, nsegs, start, stop));
679 * Max number of SGL entries an offload tx work request can have. This is 41
680 * (1 + 40) for a full 512B work request.
681 * fw_ofld_tx_data_wr(16B) + ulptx_sgl(16B, 1) + ulptx_sge_pair(480B, 40)
683 #define OFLD_SGL_LEN (41)
686 * Send data and/or a FIN to the peer.
688 * The socket's so_snd buffer consists of a stream of data starting with sb_mb
689 * and linked together with m_next. sb_sndptr, if set, is the last mbuf that
692 * drop indicates the number of bytes that should be dropped from the head of
693 * the send buffer. It is an optimization that lets do_fw4_ack avoid creating
694 * contention on the send buffer lock (before this change it used to do
695 * sowwakeup and then t4_push_frames right after that when recovering from tx
696 * stalls). When drop is set this function MUST drop the bytes and wake up any
700 t4_push_frames(struct adapter *sc, struct toepcb *toep, int drop)
702 struct mbuf *sndptr, *m, *sb_sndptr;
703 struct fw_ofld_tx_data_wr *txwr;
705 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
706 struct inpcb *inp = toep->inp;
707 struct tcpcb *tp = intotcpcb(inp);
708 struct socket *so = inp->inp_socket;
709 struct sockbuf *sb = &so->so_snd;
710 int tx_credits, shove, compl, sowwakeup;
711 struct ofld_tx_sdesc *txsd;
712 bool aiotx_mbuf_seen;
714 INP_WLOCK_ASSERT(inp);
715 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
716 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
718 KASSERT(toep->ulp_mode == ULP_MODE_NONE ||
719 toep->ulp_mode == ULP_MODE_TCPDDP ||
720 toep->ulp_mode == ULP_MODE_TLS ||
721 toep->ulp_mode == ULP_MODE_RDMA,
722 ("%s: ulp_mode %u for toep %p", __func__, toep->ulp_mode, toep));
724 #ifdef VERBOSE_TRACES
725 CTR4(KTR_CXGBE, "%s: tid %d toep flags %#x tp flags %#x drop %d",
726 __func__, toep->tid, toep->flags, tp->t_flags);
728 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
732 if (__predict_false(inp->inp_flags2 & INP_RATE_LIMIT_CHANGED) &&
733 (update_tx_rate_limit(sc, toep, so->so_max_pacing_rate) == 0)) {
734 inp->inp_flags2 &= ~INP_RATE_LIMIT_CHANGED;
739 * This function doesn't resume by itself. Someone else must clear the
740 * flag and call this function.
742 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
744 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
748 txsd = &toep->txsd[toep->txsd_pidx];
750 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
751 max_imm = max_imm_payload(tx_credits);
752 max_nsegs = max_dsgl_nsegs(tx_credits);
757 sbdrop_locked(sb, drop);
760 sb_sndptr = sb->sb_sndptr;
761 sndptr = sb_sndptr ? sb_sndptr->m_next : sb->sb_mb;
764 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
765 aiotx_mbuf_seen = false;
766 for (m = sndptr; m != NULL; m = m->m_next) {
769 if (IS_AIOTX_MBUF(m))
770 n = sglist_count_vmpages(aiotx_mbuf_pages(m),
771 aiotx_mbuf_pgoff(m), m->m_len);
773 n = sglist_count(mtod(m, void *), m->m_len);
778 /* This mbuf sent us _over_ the nsegs limit, back out */
779 if (plen > max_imm && nsegs > max_nsegs) {
783 /* Too few credits */
784 toep->flags |= TPF_TX_SUSPENDED;
790 sowwakeup_locked(so);
793 SOCKBUF_UNLOCK_ASSERT(sb);
799 if (IS_AIOTX_MBUF(m))
800 aiotx_mbuf_seen = true;
801 if (max_nsegs_1mbuf < n)
803 sb_sndptr = m; /* new sb->sb_sndptr if all goes well */
805 /* This mbuf put us right at the max_nsegs limit */
806 if (plen > max_imm && nsegs == max_nsegs) {
812 if (sbused(sb) > sb->sb_hiwat * 5 / 8 &&
813 toep->plen_nocompl + plen >= sb->sb_hiwat / 4)
818 if (sb->sb_flags & SB_AUTOSIZE &&
819 V_tcp_do_autosndbuf &&
820 sb->sb_hiwat < V_tcp_autosndbuf_max &&
821 sbused(sb) >= sb->sb_hiwat * 7 / 8) {
822 int newsize = min(sb->sb_hiwat + V_tcp_autosndbuf_inc,
823 V_tcp_autosndbuf_max);
825 if (!sbreserve_locked(sb, newsize, so, NULL))
826 sb->sb_flags &= ~SB_AUTOSIZE;
828 sowwakeup = 1; /* room available */
831 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
832 t4_aiotx_queue_toep(toep);
833 sowwakeup_locked(so);
836 SOCKBUF_UNLOCK_ASSERT(sb);
838 /* nothing to send */
841 ("%s: nothing to send, but m != NULL", __func__));
845 if (__predict_false(toep->flags & TPF_FIN_SENT))
846 panic("%s: excess tx.", __func__);
848 shove = m == NULL && !(tp->t_flags & TF_MORETOCOME);
849 if (plen <= max_imm && !aiotx_mbuf_seen) {
851 /* Immediate data tx */
853 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
856 /* XXX: how will we recover from this? */
857 toep->flags |= TPF_TX_SUSPENDED;
861 credits = howmany(wr->wr_len, 16);
862 write_tx_wr(txwr, toep, plen, plen, credits, shove, 0,
864 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
871 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
872 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
873 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
875 /* XXX: how will we recover from this? */
876 toep->flags |= TPF_TX_SUSPENDED;
880 credits = howmany(wr_len, 16);
881 write_tx_wr(txwr, toep, 0, plen, credits, shove, 0,
883 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
886 uint64_t *pad = (uint64_t *)
887 ((uintptr_t)txwr + wr_len);
892 KASSERT(toep->tx_credits >= credits,
893 ("%s: not enough credits", __func__));
895 toep->tx_credits -= credits;
896 toep->tx_nocompl += credits;
897 toep->plen_nocompl += plen;
898 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
899 toep->tx_nocompl >= toep->tx_total / 4)
902 if (compl || toep->ulp_mode == ULP_MODE_RDMA) {
903 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
904 toep->tx_nocompl = 0;
905 toep->plen_nocompl = 0;
912 KASSERT(sb_sndptr, ("%s: sb_sndptr is NULL", __func__));
913 sb->sb_sndptr = sb_sndptr;
916 toep->flags |= TPF_TX_DATA_SENT;
917 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
918 toep->flags |= TPF_TX_SUSPENDED;
920 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
922 txsd->tx_credits = credits;
924 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
926 txsd = &toep->txsd[0];
930 t4_l2t_send(sc, wr, toep->l2te);
933 /* Send a FIN if requested, but only if there's no more data to send */
934 if (m == NULL && toep->flags & TPF_SEND_FIN)
935 t4_close_conn(sc, toep);
939 rqdrop_locked(struct mbufq *q, int plen)
944 m = mbufq_dequeue(q);
946 /* Too many credits. */
950 /* Partial credits. */
951 MPASS(plen >= m->m_pkthdr.len);
953 plen -= m->m_pkthdr.len;
959 t4_push_pdus(struct adapter *sc, struct toepcb *toep, int drop)
961 struct mbuf *sndptr, *m;
962 struct fw_ofld_tx_data_wr *txwr;
964 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
965 u_int adjusted_plen, ulp_submode;
966 struct inpcb *inp = toep->inp;
967 struct tcpcb *tp = intotcpcb(inp);
968 int tx_credits, shove;
969 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
970 struct mbufq *pduq = &toep->ulp_pduq;
971 static const u_int ulp_extra_len[] = {0, 4, 4, 8};
973 INP_WLOCK_ASSERT(inp);
974 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
975 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
976 KASSERT(toep->ulp_mode == ULP_MODE_ISCSI,
977 ("%s: ulp_mode %u for toep %p", __func__, toep->ulp_mode, toep));
979 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
983 * This function doesn't resume by itself. Someone else must clear the
984 * flag and call this function.
986 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
988 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
993 rqdrop_locked(&toep->ulp_pdu_reclaimq, drop);
995 while ((sndptr = mbufq_first(pduq)) != NULL) {
996 M_ASSERTPKTHDR(sndptr);
998 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
999 max_imm = max_imm_payload(tx_credits);
1000 max_nsegs = max_dsgl_nsegs(tx_credits);
1004 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
1005 for (m = sndptr; m != NULL; m = m->m_next) {
1006 int n = sglist_count(mtod(m, void *), m->m_len);
1012 * This mbuf would send us _over_ the nsegs limit.
1013 * Suspend tx because the PDU can't be sent out.
1015 if (plen > max_imm && nsegs > max_nsegs) {
1016 toep->flags |= TPF_TX_SUSPENDED;
1020 if (max_nsegs_1mbuf < n)
1021 max_nsegs_1mbuf = n;
1024 if (__predict_false(toep->flags & TPF_FIN_SENT))
1025 panic("%s: excess tx.", __func__);
1028 * We have a PDU to send. All of it goes out in one WR so 'm'
1029 * is NULL. A PDU's length is always a multiple of 4.
1032 MPASS((plen & 3) == 0);
1033 MPASS(sndptr->m_pkthdr.len == plen);
1035 shove = !(tp->t_flags & TF_MORETOCOME);
1036 ulp_submode = mbuf_ulp_submode(sndptr);
1037 MPASS(ulp_submode < nitems(ulp_extra_len));
1040 * plen doesn't include header and data digests, which are
1041 * generated and inserted in the right places by the TOE, but
1042 * they do occupy TCP sequence space and need to be accounted
1045 adjusted_plen = plen + ulp_extra_len[ulp_submode];
1046 if (plen <= max_imm) {
1048 /* Immediate data tx */
1050 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
1053 /* XXX: how will we recover from this? */
1054 toep->flags |= TPF_TX_SUSPENDED;
1058 credits = howmany(wr->wr_len, 16);
1059 write_tx_wr(txwr, toep, plen, adjusted_plen, credits,
1060 shove, ulp_submode, sc->tt.tx_align);
1061 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
1067 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
1068 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
1069 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
1071 /* XXX: how will we recover from this? */
1072 toep->flags |= TPF_TX_SUSPENDED;
1076 credits = howmany(wr_len, 16);
1077 write_tx_wr(txwr, toep, 0, adjusted_plen, credits,
1078 shove, ulp_submode, sc->tt.tx_align);
1079 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
1082 uint64_t *pad = (uint64_t *)
1083 ((uintptr_t)txwr + wr_len);
1088 KASSERT(toep->tx_credits >= credits,
1089 ("%s: not enough credits", __func__));
1091 m = mbufq_dequeue(pduq);
1093 mbufq_enqueue(&toep->ulp_pdu_reclaimq, m);
1095 toep->tx_credits -= credits;
1096 toep->tx_nocompl += credits;
1097 toep->plen_nocompl += plen;
1098 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
1099 toep->tx_nocompl >= toep->tx_total / 4) {
1100 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
1101 toep->tx_nocompl = 0;
1102 toep->plen_nocompl = 0;
1105 tp->snd_nxt += adjusted_plen;
1106 tp->snd_max += adjusted_plen;
1108 toep->flags |= TPF_TX_DATA_SENT;
1109 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
1110 toep->flags |= TPF_TX_SUSPENDED;
1112 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
1114 txsd->tx_credits = credits;
1116 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
1117 toep->txsd_pidx = 0;
1118 txsd = &toep->txsd[0];
1122 t4_l2t_send(sc, wr, toep->l2te);
1125 /* Send a FIN if requested, but only if there are no more PDUs to send */
1126 if (mbufq_first(pduq) == NULL && toep->flags & TPF_SEND_FIN)
1127 t4_close_conn(sc, toep);
1131 t4_tod_output(struct toedev *tod, struct tcpcb *tp)
1133 struct adapter *sc = tod->tod_softc;
1135 struct inpcb *inp = tp->t_inpcb;
1137 struct toepcb *toep = tp->t_toe;
1139 INP_WLOCK_ASSERT(inp);
1140 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1141 ("%s: inp %p dropped.", __func__, inp));
1142 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1144 if (toep->ulp_mode == ULP_MODE_ISCSI)
1145 t4_push_pdus(sc, toep, 0);
1146 else if (tls_tx_key(toep))
1147 t4_push_tls_records(sc, toep, 0);
1149 t4_push_frames(sc, toep, 0);
1155 t4_send_fin(struct toedev *tod, struct tcpcb *tp)
1157 struct adapter *sc = tod->tod_softc;
1159 struct inpcb *inp = tp->t_inpcb;
1161 struct toepcb *toep = tp->t_toe;
1163 INP_WLOCK_ASSERT(inp);
1164 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1165 ("%s: inp %p dropped.", __func__, inp));
1166 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1168 toep->flags |= TPF_SEND_FIN;
1169 if (tp->t_state >= TCPS_ESTABLISHED) {
1170 if (toep->ulp_mode == ULP_MODE_ISCSI)
1171 t4_push_pdus(sc, toep, 0);
1172 else if (tls_tx_key(toep))
1173 t4_push_tls_records(sc, toep, 0);
1175 t4_push_frames(sc, toep, 0);
1182 t4_send_rst(struct toedev *tod, struct tcpcb *tp)
1184 struct adapter *sc = tod->tod_softc;
1185 #if defined(INVARIANTS)
1186 struct inpcb *inp = tp->t_inpcb;
1188 struct toepcb *toep = tp->t_toe;
1190 INP_WLOCK_ASSERT(inp);
1191 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1192 ("%s: inp %p dropped.", __func__, inp));
1193 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1196 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
1197 ("%s: flowc for tid %u [%s] not sent already",
1198 __func__, toep->tid, tcpstates[tp->t_state]));
1200 send_reset(sc, toep, 0);
1205 * Peer has sent us a FIN.
1208 do_peer_close(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1210 struct adapter *sc = iq->adapter;
1211 const struct cpl_peer_close *cpl = (const void *)(rss + 1);
1212 unsigned int tid = GET_TID(cpl);
1213 struct toepcb *toep = lookup_tid(sc, tid);
1214 struct inpcb *inp = toep->inp;
1215 struct tcpcb *tp = NULL;
1217 struct epoch_tracker et;
1219 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1222 KASSERT(opcode == CPL_PEER_CLOSE,
1223 ("%s: unexpected opcode 0x%x", __func__, opcode));
1224 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1226 if (__predict_false(toep->flags & TPF_SYNQE)) {
1228 * do_pass_establish must have run before do_peer_close and if
1229 * this is still a synqe instead of a toepcb then the connection
1230 * must be getting aborted.
1232 MPASS(toep->flags & TPF_ABORT_SHUTDOWN);
1233 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1238 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1240 CURVNET_SET(toep->vnet);
1241 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1243 tp = intotcpcb(inp);
1245 CTR5(KTR_CXGBE, "%s: tid %u (%s), toep_flags 0x%x, inp %p", __func__,
1246 tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags, inp);
1248 if (toep->flags & TPF_ABORT_SHUTDOWN)
1251 tp->rcv_nxt++; /* FIN */
1253 so = inp->inp_socket;
1254 if (toep->ulp_mode == ULP_MODE_TCPDDP) {
1256 if (__predict_false(toep->ddp.flags &
1257 (DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE)))
1258 handle_ddp_close(toep, tp, cpl->rcv_nxt);
1263 if (toep->ulp_mode != ULP_MODE_RDMA) {
1264 KASSERT(tp->rcv_nxt == be32toh(cpl->rcv_nxt),
1265 ("%s: rcv_nxt mismatch: %u %u", __func__, tp->rcv_nxt,
1266 be32toh(cpl->rcv_nxt)));
1269 switch (tp->t_state) {
1270 case TCPS_SYN_RECEIVED:
1271 tp->t_starttime = ticks;
1274 case TCPS_ESTABLISHED:
1275 tcp_state_change(tp, TCPS_CLOSE_WAIT);
1278 case TCPS_FIN_WAIT_1:
1279 tcp_state_change(tp, TCPS_CLOSING);
1282 case TCPS_FIN_WAIT_2:
1284 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1285 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1289 final_cpl_received(toep);
1293 log(LOG_ERR, "%s: TID %u received CPL_PEER_CLOSE in state %d\n",
1294 __func__, tid, tp->t_state);
1298 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1304 * Peer has ACK'd our FIN.
1307 do_close_con_rpl(struct sge_iq *iq, const struct rss_header *rss,
1310 struct adapter *sc = iq->adapter;
1311 const struct cpl_close_con_rpl *cpl = (const void *)(rss + 1);
1312 unsigned int tid = GET_TID(cpl);
1313 struct toepcb *toep = lookup_tid(sc, tid);
1314 struct inpcb *inp = toep->inp;
1315 struct tcpcb *tp = NULL;
1316 struct socket *so = NULL;
1317 struct epoch_tracker et;
1319 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1322 KASSERT(opcode == CPL_CLOSE_CON_RPL,
1323 ("%s: unexpected opcode 0x%x", __func__, opcode));
1324 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1325 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1327 CURVNET_SET(toep->vnet);
1328 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1330 tp = intotcpcb(inp);
1332 CTR4(KTR_CXGBE, "%s: tid %u (%s), toep_flags 0x%x",
1333 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags);
1335 if (toep->flags & TPF_ABORT_SHUTDOWN)
1338 so = inp->inp_socket;
1339 tp->snd_una = be32toh(cpl->snd_nxt) - 1; /* exclude FIN */
1341 switch (tp->t_state) {
1342 case TCPS_CLOSING: /* see TCPS_FIN_WAIT_2 in do_peer_close too */
1345 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1346 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1350 final_cpl_received(toep); /* no more CPLs expected */
1358 case TCPS_FIN_WAIT_1:
1359 if (so->so_rcv.sb_state & SBS_CANTRCVMORE)
1360 soisdisconnected(so);
1361 tcp_state_change(tp, TCPS_FIN_WAIT_2);
1366 "%s: TID %u received CPL_CLOSE_CON_RPL in state %s\n",
1367 __func__, tid, tcpstates[tp->t_state]);
1371 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1377 send_abort_rpl(struct adapter *sc, struct sge_wrq *ofld_txq, int tid,
1381 struct cpl_abort_rpl *cpl;
1383 wr = alloc_wrqe(sizeof(*cpl), ofld_txq);
1386 panic("%s: allocation failure.", __func__);
1390 INIT_TP_WR_MIT_CPL(cpl, CPL_ABORT_RPL, tid);
1391 cpl->cmd = rst_status;
1397 abort_status_to_errno(struct tcpcb *tp, unsigned int abort_reason)
1399 switch (abort_reason) {
1400 case CPL_ERR_BAD_SYN:
1401 case CPL_ERR_CONN_RESET:
1402 return (tp->t_state == TCPS_CLOSE_WAIT ? EPIPE : ECONNRESET);
1403 case CPL_ERR_XMIT_TIMEDOUT:
1404 case CPL_ERR_PERSIST_TIMEDOUT:
1405 case CPL_ERR_FINWAIT2_TIMEDOUT:
1406 case CPL_ERR_KEEPALIVE_TIMEDOUT:
1414 * TCP RST from the peer, timeout, or some other such critical error.
1417 do_abort_req(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1419 struct adapter *sc = iq->adapter;
1420 const struct cpl_abort_req_rss *cpl = (const void *)(rss + 1);
1421 unsigned int tid = GET_TID(cpl);
1422 struct toepcb *toep = lookup_tid(sc, tid);
1423 struct sge_wrq *ofld_txq = toep->ofld_txq;
1426 struct epoch_tracker et;
1428 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1431 KASSERT(opcode == CPL_ABORT_REQ_RSS,
1432 ("%s: unexpected opcode 0x%x", __func__, opcode));
1433 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1435 if (toep->flags & TPF_SYNQE)
1436 return (do_abort_req_synqe(iq, rss, m));
1438 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1440 if (negative_advice(cpl->status)) {
1441 CTR4(KTR_CXGBE, "%s: negative advice %d for tid %d (0x%x)",
1442 __func__, cpl->status, tid, toep->flags);
1443 return (0); /* Ignore negative advice */
1447 CURVNET_SET(toep->vnet);
1448 INP_INFO_RLOCK_ET(&V_tcbinfo, et); /* for tcp_close */
1451 tp = intotcpcb(inp);
1454 "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x, status %d",
1455 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags,
1456 inp->inp_flags, cpl->status);
1459 * If we'd initiated an abort earlier the reply to it is responsible for
1460 * cleaning up resources. Otherwise we tear everything down right here
1461 * right now. We owe the T4 a CPL_ABORT_RPL no matter what.
1463 if (toep->flags & TPF_ABORT_SHUTDOWN) {
1467 toep->flags |= TPF_ABORT_SHUTDOWN;
1469 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
1470 struct socket *so = inp->inp_socket;
1473 so_error_set(so, abort_status_to_errno(tp,
1477 INP_WLOCK(inp); /* re-acquire */
1480 final_cpl_received(toep);
1482 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1484 send_abort_rpl(sc, ofld_txq, tid, CPL_ABORT_NO_RST);
1489 * Reply to the CPL_ABORT_REQ (send_reset)
1492 do_abort_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1494 struct adapter *sc = iq->adapter;
1495 const struct cpl_abort_rpl_rss *cpl = (const void *)(rss + 1);
1496 unsigned int tid = GET_TID(cpl);
1497 struct toepcb *toep = lookup_tid(sc, tid);
1498 struct inpcb *inp = toep->inp;
1500 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1503 KASSERT(opcode == CPL_ABORT_RPL_RSS,
1504 ("%s: unexpected opcode 0x%x", __func__, opcode));
1505 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1507 if (toep->flags & TPF_SYNQE)
1508 return (do_abort_rpl_synqe(iq, rss, m));
1510 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1512 CTR5(KTR_CXGBE, "%s: tid %u, toep %p, inp %p, status %d",
1513 __func__, tid, toep, inp, cpl->status);
1515 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1516 ("%s: wasn't expecting abort reply", __func__));
1519 final_cpl_received(toep);
1525 do_rx_data(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1527 struct adapter *sc = iq->adapter;
1528 const struct cpl_rx_data *cpl = mtod(m, const void *);
1529 unsigned int tid = GET_TID(cpl);
1530 struct toepcb *toep = lookup_tid(sc, tid);
1531 struct inpcb *inp = toep->inp;
1535 struct epoch_tracker et;
1536 int len, rx_credits;
1537 uint32_t ddp_placed = 0;
1539 if (__predict_false(toep->flags & TPF_SYNQE)) {
1541 * do_pass_establish must have run before do_rx_data and if this
1542 * is still a synqe instead of a toepcb then the connection must
1543 * be getting aborted.
1545 MPASS(toep->flags & TPF_ABORT_SHUTDOWN);
1546 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1552 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1554 /* strip off CPL header */
1555 m_adj(m, sizeof(*cpl));
1556 len = m->m_pkthdr.len;
1559 if (inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) {
1560 CTR4(KTR_CXGBE, "%s: tid %u, rx (%d bytes), inp_flags 0x%x",
1561 __func__, tid, len, inp->inp_flags);
1567 tp = intotcpcb(inp);
1569 if (__predict_false(tp->rcv_nxt != be32toh(cpl->seq)))
1570 ddp_placed = be32toh(cpl->seq) - tp->rcv_nxt;
1573 if (tp->rcv_wnd < len) {
1574 KASSERT(toep->ulp_mode == ULP_MODE_RDMA,
1575 ("%s: negative window size", __func__));
1579 tp->t_rcvtime = ticks;
1581 if (toep->ulp_mode == ULP_MODE_TCPDDP)
1583 so = inp_inpcbtosocket(inp);
1587 if (__predict_false(sb->sb_state & SBS_CANTRCVMORE)) {
1588 CTR3(KTR_CXGBE, "%s: tid %u, excess rx (%d bytes)",
1589 __func__, tid, len);
1592 if (toep->ulp_mode == ULP_MODE_TCPDDP)
1596 CURVNET_SET(toep->vnet);
1597 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1599 tp = tcp_drop(tp, ECONNRESET);
1602 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1608 /* receive buffer autosize */
1609 MPASS(toep->vnet == so->so_vnet);
1610 CURVNET_SET(toep->vnet);
1611 if (sb->sb_flags & SB_AUTOSIZE &&
1612 V_tcp_do_autorcvbuf &&
1613 sb->sb_hiwat < V_tcp_autorcvbuf_max &&
1614 len > (sbspace(sb) / 8 * 7)) {
1615 unsigned int hiwat = sb->sb_hiwat;
1616 unsigned int newsize = min(hiwat + sc->tt.autorcvbuf_inc,
1617 V_tcp_autorcvbuf_max);
1619 if (!sbreserve_locked(sb, newsize, so, NULL))
1620 sb->sb_flags &= ~SB_AUTOSIZE;
1623 if (toep->ulp_mode == ULP_MODE_TCPDDP) {
1624 int changed = !(toep->ddp.flags & DDP_ON) ^ cpl->ddp_off;
1626 if (toep->ddp.waiting_count != 0 || toep->ddp.active_count != 0)
1627 CTR3(KTR_CXGBE, "%s: tid %u, non-ddp rx (%d bytes)",
1628 __func__, tid, len);
1631 if (toep->ddp.flags & DDP_SC_REQ)
1632 toep->ddp.flags ^= DDP_ON | DDP_SC_REQ;
1634 KASSERT(cpl->ddp_off == 1,
1635 ("%s: DDP switched on by itself.",
1638 /* Fell out of DDP mode */
1639 toep->ddp.flags &= ~DDP_ON;
1640 CTR1(KTR_CXGBE, "%s: fell out of DDP mode",
1643 insert_ddp_data(toep, ddp_placed);
1647 if (toep->ddp.flags & DDP_ON) {
1649 * CPL_RX_DATA with DDP on can only be an indicate.
1650 * Start posting queued AIO requests via DDP. The
1651 * payload that arrived in this indicate is appended
1652 * to the socket buffer as usual.
1654 handle_ddp_indicate(toep);
1658 sbappendstream_locked(sb, m, 0);
1659 rx_credits = sbspace(sb) > tp->rcv_wnd ? sbspace(sb) - tp->rcv_wnd : 0;
1660 if (rx_credits > 0 && sbused(sb) + tp->rcv_wnd < sb->sb_lowat) {
1661 rx_credits = send_rx_credits(sc, toep, rx_credits);
1662 tp->rcv_wnd += rx_credits;
1663 tp->rcv_adv += rx_credits;
1666 if (toep->ulp_mode == ULP_MODE_TCPDDP && toep->ddp.waiting_count > 0 &&
1668 CTR2(KTR_CXGBE, "%s: tid %u queueing AIO task", __func__,
1670 ddp_queue_toep(toep);
1672 sorwakeup_locked(so);
1673 SOCKBUF_UNLOCK_ASSERT(sb);
1674 if (toep->ulp_mode == ULP_MODE_TCPDDP)
1683 do_fw4_ack(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1685 struct adapter *sc = iq->adapter;
1686 const struct cpl_fw4_ack *cpl = (const void *)(rss + 1);
1687 unsigned int tid = G_CPL_FW4_ACK_FLOWID(be32toh(OPCODE_TID(cpl)));
1688 struct toepcb *toep = lookup_tid(sc, tid);
1692 uint8_t credits = cpl->credits;
1693 struct ofld_tx_sdesc *txsd;
1696 unsigned int opcode = G_CPL_FW4_ACK_OPCODE(be32toh(OPCODE_TID(cpl)));
1700 * Very unusual case: we'd sent a flowc + abort_req for a synq entry and
1701 * now this comes back carrying the credits for the flowc.
1703 if (__predict_false(toep->flags & TPF_SYNQE)) {
1704 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1705 ("%s: credits for a synq entry %p", __func__, toep));
1711 KASSERT(opcode == CPL_FW4_ACK,
1712 ("%s: unexpected opcode 0x%x", __func__, opcode));
1713 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1714 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1718 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN)) {
1723 KASSERT((inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) == 0,
1724 ("%s: inp_flags 0x%x", __func__, inp->inp_flags));
1726 tp = intotcpcb(inp);
1728 if (cpl->flags & CPL_FW4_ACK_FLAGS_SEQVAL) {
1729 tcp_seq snd_una = be32toh(cpl->snd_una);
1732 if (__predict_false(SEQ_LT(snd_una, tp->snd_una))) {
1734 "%s: unexpected seq# %x for TID %u, snd_una %x\n",
1735 __func__, snd_una, toep->tid, tp->snd_una);
1739 if (tp->snd_una != snd_una) {
1740 tp->snd_una = snd_una;
1741 tp->ts_recent_age = tcp_ts_getticks();
1745 #ifdef VERBOSE_TRACES
1746 CTR3(KTR_CXGBE, "%s: tid %d credits %u", __func__, tid, credits);
1748 so = inp->inp_socket;
1749 txsd = &toep->txsd[toep->txsd_cidx];
1752 KASSERT(credits >= txsd->tx_credits,
1753 ("%s: too many (or partial) credits", __func__));
1754 credits -= txsd->tx_credits;
1755 toep->tx_credits += txsd->tx_credits;
1757 if (txsd->iv_buffer) {
1758 free(txsd->iv_buffer, M_CXGBE);
1759 txsd->iv_buffer = NULL;
1763 KASSERT(toep->txsd_avail <= toep->txsd_total,
1764 ("%s: txsd avail > total", __func__));
1765 if (__predict_false(++toep->txsd_cidx == toep->txsd_total)) {
1766 txsd = &toep->txsd[0];
1767 toep->txsd_cidx = 0;
1771 if (toep->tx_credits == toep->tx_total) {
1772 toep->tx_nocompl = 0;
1773 toep->plen_nocompl = 0;
1776 if (toep->flags & TPF_TX_SUSPENDED &&
1777 toep->tx_credits >= toep->tx_total / 4) {
1778 #ifdef VERBOSE_TRACES
1779 CTR2(KTR_CXGBE, "%s: tid %d calling t4_push_frames", __func__,
1782 toep->flags &= ~TPF_TX_SUSPENDED;
1783 CURVNET_SET(toep->vnet);
1784 if (toep->ulp_mode == ULP_MODE_ISCSI)
1785 t4_push_pdus(sc, toep, plen);
1786 else if (tls_tx_key(toep))
1787 t4_push_tls_records(sc, toep, plen);
1789 t4_push_frames(sc, toep, plen);
1791 } else if (plen > 0) {
1792 struct sockbuf *sb = &so->so_snd;
1797 if (toep->ulp_mode == ULP_MODE_ISCSI) {
1799 if (__predict_false(sbu > 0)) {
1801 * The data trasmitted before the tid's ULP mode
1802 * changed to ISCSI is still in so_snd.
1803 * Incoming credits should account for so_snd
1806 sbdrop_locked(sb, min(sbu, plen));
1807 plen -= min(sbu, plen);
1809 sowwakeup_locked(so); /* unlocks so_snd */
1810 rqdrop_locked(&toep->ulp_pdu_reclaimq, plen);
1812 #ifdef VERBOSE_TRACES
1813 CTR3(KTR_CXGBE, "%s: tid %d dropped %d bytes", __func__,
1816 sbdrop_locked(sb, plen);
1817 if (tls_tx_key(toep)) {
1818 struct tls_ofld_info *tls_ofld = &toep->tls;
1820 MPASS(tls_ofld->sb_off >= plen);
1821 tls_ofld->sb_off -= plen;
1823 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
1824 t4_aiotx_queue_toep(toep);
1825 sowwakeup_locked(so); /* unlocks so_snd */
1827 SOCKBUF_UNLOCK_ASSERT(sb);
1836 t4_set_tcb_field(struct adapter *sc, struct sge_wrq *wrq, struct toepcb *toep,
1837 uint16_t word, uint64_t mask, uint64_t val, int reply, int cookie)
1840 struct cpl_set_tcb_field *req;
1841 struct ofld_tx_sdesc *txsd;
1843 MPASS((cookie & ~M_COOKIE) == 0);
1845 MPASS(cookie != CPL_COOKIE_RESERVED);
1848 wr = alloc_wrqe(sizeof(*req), wrq);
1851 panic("%s: allocation failure.", __func__);
1855 INIT_TP_WR_MIT_CPL(req, CPL_SET_TCB_FIELD, toep->tid);
1856 req->reply_ctrl = htobe16(V_QUEUENO(toep->ofld_rxq->iq.abs_id));
1858 req->reply_ctrl |= htobe16(F_NO_REPLY);
1859 req->word_cookie = htobe16(V_WORD(word) | V_COOKIE(cookie));
1860 req->mask = htobe64(mask);
1861 req->val = htobe64(val);
1862 if ((wrq->eq.flags & EQ_TYPEMASK) == EQ_OFLD) {
1863 txsd = &toep->txsd[toep->txsd_pidx];
1864 txsd->tx_credits = howmany(sizeof(*req), 16);
1866 KASSERT(toep->tx_credits >= txsd->tx_credits &&
1867 toep->txsd_avail > 0,
1868 ("%s: not enough credits (%d)", __func__,
1870 toep->tx_credits -= txsd->tx_credits;
1871 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
1872 toep->txsd_pidx = 0;
1880 t4_init_cpl_io_handlers(void)
1883 t4_register_cpl_handler(CPL_PEER_CLOSE, do_peer_close);
1884 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, do_close_con_rpl);
1885 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, do_abort_req);
1886 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS, do_abort_rpl,
1888 t4_register_cpl_handler(CPL_RX_DATA, do_rx_data);
1889 t4_register_shared_cpl_handler(CPL_FW4_ACK, do_fw4_ack, CPL_COOKIE_TOM);
1893 t4_uninit_cpl_io_handlers(void)
1896 t4_register_cpl_handler(CPL_PEER_CLOSE, NULL);
1897 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, NULL);
1898 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, NULL);
1899 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS, NULL, CPL_COOKIE_TOM);
1900 t4_register_cpl_handler(CPL_RX_DATA, NULL);
1901 t4_register_shared_cpl_handler(CPL_FW4_ACK, NULL, CPL_COOKIE_TOM);
1905 * Use the 'backend3' field in AIO jobs to store the amount of data
1906 * sent by the AIO job so far and the 'backend4' field to hold an
1907 * error that should be reported when the job is completed.
1909 #define aio_sent backend3
1910 #define aio_error backend4
1912 #define jobtotid(job) \
1913 (((struct toepcb *)(so_sototcpcb((job)->fd_file->f_data)->t_toe))->tid)
1916 free_aiotx_buffer(struct aiotx_buffer *ab)
1922 if (refcount_release(&ab->refcount) == 0)
1926 error = job->aio_error;
1927 status = job->aio_sent;
1928 vm_page_unhold_pages(ab->ps.pages, ab->ps.npages);
1930 #ifdef VERBOSE_TRACES
1931 CTR5(KTR_CXGBE, "%s: tid %d completed %p len %ld, error %d", __func__,
1932 jobtotid(job), job, status, error);
1934 if (error == ECANCELED && status != 0)
1936 if (error == ECANCELED)
1939 aio_complete(job, -1, error);
1941 aio_complete(job, status, 0);
1945 t4_aiotx_mbuf_free(struct mbuf *m)
1947 struct aiotx_buffer *ab = m->m_ext.ext_arg1;
1949 #ifdef VERBOSE_TRACES
1950 CTR3(KTR_CXGBE, "%s: completed %d bytes for tid %d", __func__,
1951 m->m_len, jobtotid(ab->job));
1953 free_aiotx_buffer(ab);
1957 * Hold the buffer backing an AIO request and return an AIO transmit
1961 hold_aio(struct kaiocb *job)
1963 struct aiotx_buffer *ab;
1966 vm_offset_t start, end, pgoff;
1969 MPASS(job->backend1 == NULL);
1972 * The AIO subsystem will cancel and drain all requests before
1973 * permitting a process to exit or exec, so p_vmspace should
1976 vm = job->userproc->p_vmspace;
1978 start = (uintptr_t)job->uaiocb.aio_buf;
1979 pgoff = start & PAGE_MASK;
1980 end = round_page(start + job->uaiocb.aio_nbytes);
1981 start = trunc_page(start);
1982 n = atop(end - start);
1984 ab = malloc(sizeof(*ab) + n * sizeof(vm_page_t), M_CXGBE, M_WAITOK |
1986 refcount_init(&ab->refcount, 1);
1987 ab->ps.pages = (vm_page_t *)(ab + 1);
1988 ab->ps.npages = vm_fault_quick_hold_pages(map, start, end - start,
1989 VM_PROT_WRITE, ab->ps.pages, n);
1990 if (ab->ps.npages < 0) {
1995 KASSERT(ab->ps.npages == n,
1996 ("hold_aio: page count mismatch: %d vs %d", ab->ps.npages, n));
1998 ab->ps.offset = pgoff;
1999 ab->ps.len = job->uaiocb.aio_nbytes;
2002 #ifdef VERBOSE_TRACES
2003 CTR5(KTR_CXGBE, "%s: tid %d, new pageset %p for job %p, npages %d",
2004 __func__, jobtotid(job), &ab->ps, job, ab->ps.npages);
2010 t4_aiotx_process_job(struct toepcb *toep, struct socket *so, struct kaiocb *job)
2015 struct aiotx_buffer *ab;
2020 bool moretocome, sendmore;
2022 sc = td_adapter(toep->td);
2030 error = mac_socket_check_send(fp->f_cred, so);
2036 error = hold_aio(job);
2042 /* Inline sosend_generic(). */
2046 error = sblock(sb, SBL_WAIT);
2050 m = m_get(M_WAITOK, MT_DATA);
2053 if (so->so_snd.sb_state & SBS_CANTSENDMORE) {
2056 if ((so->so_options & SO_NOSIGPIPE) == 0) {
2057 PROC_LOCK(job->userproc);
2058 kern_psignal(job->userproc, SIGPIPE);
2059 PROC_UNLOCK(job->userproc);
2065 error = so->so_error;
2071 if ((so->so_state & SS_ISCONNECTED) == 0) {
2077 if (sbspace(sb) < sb->sb_lowat) {
2078 MPASS(job->aio_sent == 0 || !(so->so_state & SS_NBIO));
2081 * Don't block if there is too little room in the socket
2082 * buffer. Instead, requeue the request.
2084 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2090 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2097 * Write as much data as the socket permits, but no more than a
2098 * a single sndbuf at a time.
2100 m->m_len = sbspace(sb);
2101 if (m->m_len > ab->ps.len - job->aio_sent) {
2102 m->m_len = ab->ps.len - job->aio_sent;
2106 if (m->m_len > sc->tt.sndbuf) {
2107 m->m_len = sc->tt.sndbuf;
2112 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
2115 MPASS(m->m_len != 0);
2117 /* Inlined tcp_usr_send(). */
2121 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
2128 refcount_acquire(&ab->refcount);
2129 m_extadd(m, NULL, ab->ps.len, t4_aiotx_mbuf_free, ab,
2130 (void *)(uintptr_t)job->aio_sent, 0, EXT_NET_DRV);
2131 m->m_ext.ext_flags |= EXT_FLAG_AIOTX;
2132 job->aio_sent += m->m_len;
2134 sbappendstream(sb, m, 0);
2137 if (!(inp->inp_flags & INP_DROPPED)) {
2138 tp = intotcpcb(inp);
2140 tp->t_flags |= TF_MORETOCOME;
2141 error = tp->t_fb->tfb_tcp_output(tp);
2143 tp->t_flags &= ~TF_MORETOCOME;
2155 * If this is a non-blocking socket and the request has not
2156 * been fully completed, requeue it until the socket is ready
2159 if (job->aio_sent < job->uaiocb.aio_nbytes &&
2160 !(so->so_state & SS_NBIO)) {
2162 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2167 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2172 * If the request will not be requeued, drop a reference on
2173 * the aiotx buffer. Any mbufs in flight should still
2174 * contain a reference, but this drops the reference that the
2175 * job owns while it is waiting to queue mbufs to the socket.
2177 free_aiotx_buffer(ab);
2182 job->aio_error = error;
2183 free_aiotx_buffer(ab);
2185 MPASS(job->aio_sent == 0);
2186 aio_complete(job, -1, error);
2195 t4_aiotx_task(void *context, int pending)
2197 struct toepcb *toep = context;
2198 struct inpcb *inp = toep->inp;
2199 struct socket *so = inp->inp_socket;
2202 CURVNET_SET(toep->vnet);
2203 SOCKBUF_LOCK(&so->so_snd);
2204 while (!TAILQ_EMPTY(&toep->aiotx_jobq) && sowriteable(so)) {
2205 job = TAILQ_FIRST(&toep->aiotx_jobq);
2206 TAILQ_REMOVE(&toep->aiotx_jobq, job, list);
2207 if (!aio_clear_cancel_function(job))
2210 t4_aiotx_process_job(toep, so, job);
2212 toep->aiotx_task_active = false;
2213 SOCKBUF_UNLOCK(&so->so_snd);
2220 t4_aiotx_queue_toep(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_task_active ? "true" : "false");
2228 if (toep->aiotx_task_active)
2230 toep->aiotx_task_active = true;
2232 soaio_enqueue(&toep->aiotx_task);
2236 t4_aiotx_cancel(struct kaiocb *job)
2238 struct aiotx_buffer *ab;
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);
2257 free_aiotx_buffer(ab);
2263 t4_aio_queue_aiotx(struct socket *so, struct kaiocb *job)
2265 struct tcpcb *tp = so_sototcpcb(so);
2266 struct toepcb *toep = tp->t_toe;
2267 struct adapter *sc = td_adapter(toep->td);
2269 /* This only handles writes. */
2270 if (job->uaiocb.aio_lio_opcode != LIO_WRITE)
2271 return (EOPNOTSUPP);
2273 if (!sc->tt.tx_zcopy)
2274 return (EOPNOTSUPP);
2276 if (tls_tx_key(toep))
2277 return (EOPNOTSUPP);
2279 SOCKBUF_LOCK(&so->so_snd);
2280 #ifdef VERBOSE_TRACES
2281 CTR2(KTR_CXGBE, "%s: queueing %p", __func__, job);
2283 if (!aio_set_cancel_function(job, t4_aiotx_cancel))
2284 panic("new job was cancelled");
2285 TAILQ_INSERT_TAIL(&toep->aiotx_jobq, job, list);
2286 if (sowriteable(so))
2287 t4_aiotx_queue_toep(toep);
2288 SOCKBUF_UNLOCK(&so->so_snd);
2293 aiotx_init_toep(struct toepcb *toep)
2296 TAILQ_INIT(&toep->aiotx_jobq);
2297 TASK_INIT(&toep->aiotx_task, 0, t4_aiotx_task, toep);