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$");
36 #include <sys/param.h>
39 #include <sys/kernel.h>
41 #include <sys/module.h>
43 #include <sys/protosw.h>
44 #include <sys/domain.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 #include <sys/sglist.h>
48 #include <sys/taskqueue.h>
49 #include <netinet/in.h>
50 #include <netinet/in_pcb.h>
51 #include <netinet/ip.h>
52 #include <netinet/ip6.h>
54 #include <netinet/tcp_fsm.h>
55 #include <netinet/tcp_seq.h>
56 #include <netinet/tcp_var.h>
57 #include <netinet/toecore.h>
59 #include <security/mac/mac_framework.h>
62 #include <vm/vm_extern.h>
64 #include <vm/vm_map.h>
65 #include <vm/vm_page.h>
67 #include "common/common.h"
68 #include "common/t4_msg.h"
69 #include "common/t4_regs.h"
70 #include "common/t4_tcb.h"
71 #include "tom/t4_tom_l2t.h"
72 #include "tom/t4_tom.h"
74 VNET_DECLARE(int, tcp_do_autosndbuf);
75 #define V_tcp_do_autosndbuf VNET(tcp_do_autosndbuf)
76 VNET_DECLARE(int, tcp_autosndbuf_inc);
77 #define V_tcp_autosndbuf_inc VNET(tcp_autosndbuf_inc)
78 VNET_DECLARE(int, tcp_autosndbuf_max);
79 #define V_tcp_autosndbuf_max VNET(tcp_autosndbuf_max)
80 VNET_DECLARE(int, tcp_do_autorcvbuf);
81 #define V_tcp_do_autorcvbuf VNET(tcp_do_autorcvbuf)
82 VNET_DECLARE(int, tcp_autorcvbuf_inc);
83 #define V_tcp_autorcvbuf_inc VNET(tcp_autorcvbuf_inc)
84 VNET_DECLARE(int, tcp_autorcvbuf_max);
85 #define V_tcp_autorcvbuf_max VNET(tcp_autorcvbuf_max)
87 #define IS_AIOTX_MBUF(m) \
88 ((m)->m_flags & M_EXT && (m)->m_ext.ext_flags & EXT_FLAG_AIOTX)
90 static void t4_aiotx_cancel(struct kaiocb *job);
91 static void t4_aiotx_queue_toep(struct toepcb *toep);
94 aiotx_mbuf_pgoff(struct mbuf *m)
96 struct aiotx_buffer *ab;
98 MPASS(IS_AIOTX_MBUF(m));
99 ab = m->m_ext.ext_arg1;
100 return ((ab->ps.offset + (uintptr_t)m->m_ext.ext_arg2) % PAGE_SIZE);
104 aiotx_mbuf_pages(struct mbuf *m)
106 struct aiotx_buffer *ab;
109 MPASS(IS_AIOTX_MBUF(m));
110 ab = m->m_ext.ext_arg1;
111 npages = (ab->ps.offset + (uintptr_t)m->m_ext.ext_arg2) / PAGE_SIZE;
112 return (ab->ps.pages + npages);
116 send_flowc_wr(struct toepcb *toep, struct flowc_tx_params *ftxp)
119 struct fw_flowc_wr *flowc;
120 unsigned int nparams = ftxp ? 8 : 6, flowclen;
121 struct vi_info *vi = toep->vi;
122 struct port_info *pi = vi->pi;
123 struct adapter *sc = pi->adapter;
124 unsigned int pfvf = G_FW_VIID_PFN(vi->viid) << S_FW_VIID_PFN;
125 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
127 KASSERT(!(toep->flags & TPF_FLOWC_WR_SENT),
128 ("%s: flowc for tid %u sent already", __func__, toep->tid));
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 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
146 flowc->mnemval[0].val = htobe32(pfvf);
147 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
148 flowc->mnemval[1].val = htobe32(pi->tx_chan);
149 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
150 flowc->mnemval[2].val = htobe32(pi->tx_chan);
151 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
152 flowc->mnemval[3].val = htobe32(toep->ofld_rxq->iq.abs_id);
154 uint32_t sndbuf = min(ftxp->snd_space, sc->tt.sndbuf);
156 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
157 flowc->mnemval[4].val = htobe32(ftxp->snd_nxt);
158 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
159 flowc->mnemval[5].val = htobe32(ftxp->rcv_nxt);
160 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
161 flowc->mnemval[6].val = htobe32(sndbuf);
162 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
163 flowc->mnemval[7].val = htobe32(ftxp->mss);
166 "%s: tid %u, mss %u, sndbuf %u, snd_nxt 0x%x, rcv_nxt 0x%x",
167 __func__, toep->tid, ftxp->mss, sndbuf, ftxp->snd_nxt,
170 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDBUF;
171 flowc->mnemval[4].val = htobe32(512);
172 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_MSS;
173 flowc->mnemval[5].val = htobe32(512);
175 CTR2(KTR_CXGBE, "%s: tid %u", __func__, toep->tid);
178 txsd->tx_credits = howmany(flowclen, 16);
180 KASSERT(toep->tx_credits >= txsd->tx_credits && toep->txsd_avail > 0,
181 ("%s: not enough credits (%d)", __func__, toep->tx_credits));
182 toep->tx_credits -= txsd->tx_credits;
183 if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
187 toep->flags |= TPF_FLOWC_WR_SENT;
192 send_reset(struct adapter *sc, struct toepcb *toep, uint32_t snd_nxt)
195 struct cpl_abort_req *req;
197 struct inpcb *inp = toep->inp;
198 struct tcpcb *tp = intotcpcb(inp); /* don't use if INP_DROPPED */
200 INP_WLOCK_ASSERT(inp);
202 CTR6(KTR_CXGBE, "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x%s",
204 inp->inp_flags & INP_DROPPED ? "inp dropped" :
205 tcpstates[tp->t_state],
206 toep->flags, inp->inp_flags,
207 toep->flags & TPF_ABORT_SHUTDOWN ?
208 " (abort already in progress)" : "");
210 if (toep->flags & TPF_ABORT_SHUTDOWN)
211 return; /* abort already in progress */
213 toep->flags |= TPF_ABORT_SHUTDOWN;
215 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
216 ("%s: flowc_wr not sent for tid %d.", __func__, tid));
218 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
221 panic("%s: allocation failure.", __func__);
225 INIT_TP_WR_MIT_CPL(req, CPL_ABORT_REQ, tid);
226 if (inp->inp_flags & INP_DROPPED)
227 req->rsvd0 = htobe32(snd_nxt);
229 req->rsvd0 = htobe32(tp->snd_nxt);
230 req->rsvd1 = !(toep->flags & TPF_TX_DATA_SENT);
231 req->cmd = CPL_ABORT_SEND_RST;
234 * XXX: What's the correct way to tell that the inp hasn't been detached
235 * from its socket? Should I even be flushing the snd buffer here?
237 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
238 struct socket *so = inp->inp_socket;
240 if (so != NULL) /* because I'm not sure. See comment above */
241 sbflush(&so->so_snd);
244 t4_l2t_send(sc, wr, toep->l2te);
248 * Called when a connection is established to translate the TCP options
249 * reported by HW to FreeBSD's native format.
252 assign_rxopt(struct tcpcb *tp, unsigned int opt)
254 struct toepcb *toep = tp->t_toe;
255 struct inpcb *inp = tp->t_inpcb;
256 struct adapter *sc = td_adapter(toep->td);
259 INP_LOCK_ASSERT(inp);
261 if (inp->inp_inc.inc_flags & INC_ISIPV6)
262 n = sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
264 n = sizeof(struct ip) + sizeof(struct tcphdr);
265 tp->t_maxseg = sc->params.mtus[G_TCPOPT_MSS(opt)] - n;
267 CTR4(KTR_CXGBE, "%s: tid %d, mtu_idx %u (%u)", __func__, toep->tid,
268 G_TCPOPT_MSS(opt), sc->params.mtus[G_TCPOPT_MSS(opt)]);
270 if (G_TCPOPT_TSTAMP(opt)) {
271 tp->t_flags |= TF_RCVD_TSTMP; /* timestamps ok */
272 tp->ts_recent = 0; /* hmmm */
273 tp->ts_recent_age = tcp_ts_getticks();
276 if (G_TCPOPT_SACK(opt))
277 tp->t_flags |= TF_SACK_PERMIT; /* should already be set */
279 tp->t_flags &= ~TF_SACK_PERMIT; /* sack disallowed by peer */
281 if (G_TCPOPT_WSCALE_OK(opt))
282 tp->t_flags |= TF_RCVD_SCALE;
284 /* Doing window scaling? */
285 if ((tp->t_flags & (TF_RCVD_SCALE | TF_REQ_SCALE)) ==
286 (TF_RCVD_SCALE | TF_REQ_SCALE)) {
287 tp->rcv_scale = tp->request_r_scale;
288 tp->snd_scale = G_TCPOPT_SND_WSCALE(opt);
293 * Completes some final bits of initialization for just established connections
294 * and changes their state to TCPS_ESTABLISHED.
296 * The ISNs are from after the exchange of SYNs. i.e., the true ISN + 1.
299 make_established(struct toepcb *toep, uint32_t snd_isn, uint32_t rcv_isn,
302 struct inpcb *inp = toep->inp;
303 struct socket *so = inp->inp_socket;
304 struct tcpcb *tp = intotcpcb(inp);
306 uint32_t iss = be32toh(snd_isn) - 1; /* true ISS */
307 uint32_t irs = be32toh(rcv_isn) - 1; /* true IRS */
308 uint16_t tcpopt = be16toh(opt);
309 struct flowc_tx_params ftxp;
311 INP_WLOCK_ASSERT(inp);
312 KASSERT(tp->t_state == TCPS_SYN_SENT ||
313 tp->t_state == TCPS_SYN_RECEIVED,
314 ("%s: TCP state %s", __func__, tcpstates[tp->t_state]));
316 CTR6(KTR_CXGBE, "%s: tid %d, so %p, inp %p, tp %p, toep %p",
317 __func__, toep->tid, so, inp, tp, toep);
319 tp->t_state = TCPS_ESTABLISHED;
320 tp->t_starttime = ticks;
321 TCPSTAT_INC(tcps_connects);
325 tp->rcv_wnd = toep->rx_credits << 10;
326 tp->rcv_adv += tp->rcv_wnd;
327 tp->last_ack_sent = tp->rcv_nxt;
330 * If we were unable to send all rx credits via opt0, save the remainder
331 * in rx_credits so that they can be handed over with the next credit
334 SOCKBUF_LOCK(&so->so_rcv);
335 bufsize = select_rcv_wnd(so);
336 SOCKBUF_UNLOCK(&so->so_rcv);
337 toep->rx_credits = bufsize - tp->rcv_wnd;
341 tp->snd_una = iss + 1;
342 tp->snd_nxt = iss + 1;
343 tp->snd_max = iss + 1;
345 assign_rxopt(tp, tcpopt);
347 SOCKBUF_LOCK(&so->so_snd);
348 if (so->so_snd.sb_flags & SB_AUTOSIZE && V_tcp_do_autosndbuf)
349 bufsize = V_tcp_autosndbuf_max;
351 bufsize = sbspace(&so->so_snd);
352 SOCKBUF_UNLOCK(&so->so_snd);
354 ftxp.snd_nxt = tp->snd_nxt;
355 ftxp.rcv_nxt = tp->rcv_nxt;
356 ftxp.snd_space = bufsize;
357 ftxp.mss = tp->t_maxseg;
358 send_flowc_wr(toep, &ftxp);
364 send_rx_credits(struct adapter *sc, struct toepcb *toep, int credits)
367 struct cpl_rx_data_ack *req;
368 uint32_t dack = F_RX_DACK_CHANGE | V_RX_DACK_MODE(1);
370 KASSERT(credits >= 0, ("%s: %d credits", __func__, credits));
372 wr = alloc_wrqe(sizeof(*req), toep->ctrlq);
377 INIT_TP_WR_MIT_CPL(req, CPL_RX_DATA_ACK, toep->tid);
378 req->credit_dack = htobe32(dack | V_RX_CREDITS(credits));
385 t4_rcvd_locked(struct toedev *tod, struct tcpcb *tp)
387 struct adapter *sc = tod->tod_softc;
388 struct inpcb *inp = tp->t_inpcb;
389 struct socket *so = inp->inp_socket;
390 struct sockbuf *sb = &so->so_rcv;
391 struct toepcb *toep = tp->t_toe;
394 INP_WLOCK_ASSERT(inp);
396 SOCKBUF_LOCK_ASSERT(sb);
397 KASSERT(toep->sb_cc >= sbused(sb),
398 ("%s: sb %p has more data (%d) than last time (%d).",
399 __func__, sb, sbused(sb), toep->sb_cc));
401 toep->rx_credits += toep->sb_cc - sbused(sb);
402 toep->sb_cc = sbused(sb);
404 if (toep->rx_credits > 0 &&
405 (tp->rcv_wnd <= 32 * 1024 || toep->rx_credits >= 64 * 1024 ||
406 (toep->rx_credits >= 16 * 1024 && tp->rcv_wnd <= 128 * 1024) ||
407 toep->sb_cc + tp->rcv_wnd < sb->sb_lowat)) {
409 credits = send_rx_credits(sc, toep, toep->rx_credits);
410 toep->rx_credits -= credits;
411 tp->rcv_wnd += credits;
412 tp->rcv_adv += credits;
417 t4_rcvd(struct toedev *tod, struct tcpcb *tp)
419 struct inpcb *inp = tp->t_inpcb;
420 struct socket *so = inp->inp_socket;
421 struct sockbuf *sb = &so->so_rcv;
424 t4_rcvd_locked(tod, tp);
429 * Close a connection by sending a CPL_CLOSE_CON_REQ message.
432 close_conn(struct adapter *sc, struct toepcb *toep)
435 struct cpl_close_con_req *req;
436 unsigned int tid = toep->tid;
438 CTR3(KTR_CXGBE, "%s: tid %u%s", __func__, toep->tid,
439 toep->flags & TPF_FIN_SENT ? ", IGNORED" : "");
441 if (toep->flags & TPF_FIN_SENT)
444 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
445 ("%s: flowc_wr not sent for tid %u.", __func__, tid));
447 wr = alloc_wrqe(sizeof(*req), toep->ofld_txq);
450 panic("%s: allocation failure.", __func__);
454 req->wr.wr_hi = htonl(V_FW_WR_OP(FW_TP_WR) |
455 V_FW_WR_IMMDLEN(sizeof(*req) - sizeof(req->wr)));
456 req->wr.wr_mid = htonl(V_FW_WR_LEN16(howmany(sizeof(*req), 16)) |
457 V_FW_WR_FLOWID(tid));
458 req->wr.wr_lo = cpu_to_be64(0);
459 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
462 toep->flags |= TPF_FIN_SENT;
463 toep->flags &= ~TPF_SEND_FIN;
464 t4_l2t_send(sc, wr, toep->l2te);
469 #define MAX_OFLD_TX_CREDITS (SGE_MAX_WR_LEN / 16)
470 #define MIN_OFLD_TX_CREDITS (howmany(sizeof(struct fw_ofld_tx_data_wr) + 1, 16))
472 /* Maximum amount of immediate data we could stuff in a WR */
474 max_imm_payload(int tx_credits)
476 const int n = 2; /* Use only up to 2 desc for imm. data WR */
478 KASSERT(tx_credits >= 0 &&
479 tx_credits <= MAX_OFLD_TX_CREDITS,
480 ("%s: %d credits", __func__, tx_credits));
482 if (tx_credits < MIN_OFLD_TX_CREDITS)
485 if (tx_credits >= (n * EQ_ESIZE) / 16)
486 return ((n * EQ_ESIZE) - sizeof(struct fw_ofld_tx_data_wr));
488 return (tx_credits * 16 - sizeof(struct fw_ofld_tx_data_wr));
491 /* Maximum number of SGL entries we could stuff in a WR */
493 max_dsgl_nsegs(int tx_credits)
495 int nseg = 1; /* ulptx_sgl has room for 1, rest ulp_tx_sge_pair */
496 int sge_pair_credits = tx_credits - MIN_OFLD_TX_CREDITS;
498 KASSERT(tx_credits >= 0 &&
499 tx_credits <= MAX_OFLD_TX_CREDITS,
500 ("%s: %d credits", __func__, tx_credits));
502 if (tx_credits < MIN_OFLD_TX_CREDITS)
505 nseg += 2 * (sge_pair_credits * 16 / 24);
506 if ((sge_pair_credits * 16) % 24 == 16)
513 write_tx_wr(void *dst, struct toepcb *toep, unsigned int immdlen,
514 unsigned int plen, uint8_t credits, int shove, int ulp_submode, int txalign)
516 struct fw_ofld_tx_data_wr *txwr = dst;
518 txwr->op_to_immdlen = htobe32(V_WR_OP(FW_OFLD_TX_DATA_WR) |
519 V_FW_WR_IMMDLEN(immdlen));
520 txwr->flowid_len16 = htobe32(V_FW_WR_FLOWID(toep->tid) |
521 V_FW_WR_LEN16(credits));
522 txwr->lsodisable_to_flags = htobe32(V_TX_ULP_MODE(toep->ulp_mode) |
523 V_TX_ULP_SUBMODE(ulp_submode) | V_TX_URG(0) | V_TX_SHOVE(shove));
524 txwr->plen = htobe32(plen);
527 struct tcpcb *tp = intotcpcb(toep->inp);
529 if (plen < 2 * tp->t_maxseg || is_10G_port(toep->vi->pi))
530 txwr->lsodisable_to_flags |=
531 htobe32(F_FW_OFLD_TX_DATA_WR_LSODISABLE);
533 txwr->lsodisable_to_flags |=
534 htobe32(F_FW_OFLD_TX_DATA_WR_ALIGNPLD |
535 (tp->t_flags & TF_NODELAY ? 0 :
536 F_FW_OFLD_TX_DATA_WR_ALIGNPLDSHOVE));
541 * Generate a DSGL from a starting mbuf. The total number of segments and the
542 * maximum segments in any one mbuf are provided.
545 write_tx_sgl(void *dst, struct mbuf *start, struct mbuf *stop, int nsegs, int n)
548 struct ulptx_sgl *usgl = dst;
551 struct sglist_seg segs[n];
553 KASSERT(nsegs > 0, ("%s: nsegs 0", __func__));
555 sglist_init(&sg, n, segs);
556 usgl->cmd_nsge = htobe32(V_ULPTX_CMD(ULP_TX_SC_DSGL) |
557 V_ULPTX_NSGE(nsegs));
560 for (m = start; m != stop; m = m->m_next) {
561 if (IS_AIOTX_MBUF(m))
562 rc = sglist_append_vmpages(&sg, aiotx_mbuf_pages(m),
563 aiotx_mbuf_pgoff(m), m->m_len);
565 rc = sglist_append(&sg, mtod(m, void *), m->m_len);
566 if (__predict_false(rc != 0))
567 panic("%s: sglist_append %d", __func__, rc);
569 for (j = 0; j < sg.sg_nseg; i++, j++) {
571 usgl->len0 = htobe32(segs[j].ss_len);
572 usgl->addr0 = htobe64(segs[j].ss_paddr);
574 usgl->sge[i / 2].len[i & 1] =
575 htobe32(segs[j].ss_len);
576 usgl->sge[i / 2].addr[i & 1] =
577 htobe64(segs[j].ss_paddr);
586 usgl->sge[i / 2].len[1] = htobe32(0);
587 KASSERT(nsegs == 0, ("%s: nsegs %d, start %p, stop %p",
588 __func__, nsegs, start, stop));
592 * Max number of SGL entries an offload tx work request can have. This is 41
593 * (1 + 40) for a full 512B work request.
594 * fw_ofld_tx_data_wr(16B) + ulptx_sgl(16B, 1) + ulptx_sge_pair(480B, 40)
596 #define OFLD_SGL_LEN (41)
599 * Send data and/or a FIN to the peer.
601 * The socket's so_snd buffer consists of a stream of data starting with sb_mb
602 * and linked together with m_next. sb_sndptr, if set, is the last mbuf that
605 * drop indicates the number of bytes that should be dropped from the head of
606 * the send buffer. It is an optimization that lets do_fw4_ack avoid creating
607 * contention on the send buffer lock (before this change it used to do
608 * sowwakeup and then t4_push_frames right after that when recovering from tx
609 * stalls). When drop is set this function MUST drop the bytes and wake up any
613 t4_push_frames(struct adapter *sc, struct toepcb *toep, int drop)
615 struct mbuf *sndptr, *m, *sb_sndptr;
616 struct fw_ofld_tx_data_wr *txwr;
618 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
619 struct inpcb *inp = toep->inp;
620 struct tcpcb *tp = intotcpcb(inp);
621 struct socket *so = inp->inp_socket;
622 struct sockbuf *sb = &so->so_snd;
623 int tx_credits, shove, compl, sowwakeup;
624 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
625 bool aiotx_mbuf_seen;
627 INP_WLOCK_ASSERT(inp);
628 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
629 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
631 KASSERT(toep->ulp_mode == ULP_MODE_NONE ||
632 toep->ulp_mode == ULP_MODE_TCPDDP ||
633 toep->ulp_mode == ULP_MODE_RDMA,
634 ("%s: ulp_mode %u for toep %p", __func__, toep->ulp_mode, toep));
636 #ifdef VERBOSE_TRACES
637 CTR4(KTR_CXGBE, "%s: tid %d toep flags %#x tp flags %#x drop %d",
638 __func__, toep->tid, toep->flags, tp->t_flags);
640 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
644 * This function doesn't resume by itself. Someone else must clear the
645 * flag and call this function.
647 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
649 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
654 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
655 max_imm = max_imm_payload(tx_credits);
656 max_nsegs = max_dsgl_nsegs(tx_credits);
661 sbdrop_locked(sb, drop);
664 sb_sndptr = sb->sb_sndptr;
665 sndptr = sb_sndptr ? sb_sndptr->m_next : sb->sb_mb;
668 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
669 aiotx_mbuf_seen = false;
670 for (m = sndptr; m != NULL; m = m->m_next) {
673 if (IS_AIOTX_MBUF(m))
674 n = sglist_count_vmpages(aiotx_mbuf_pages(m),
675 aiotx_mbuf_pgoff(m), m->m_len);
677 n = sglist_count(mtod(m, void *), m->m_len);
682 /* This mbuf sent us _over_ the nsegs limit, back out */
683 if (plen > max_imm && nsegs > max_nsegs) {
687 /* Too few credits */
688 toep->flags |= TPF_TX_SUSPENDED;
694 sowwakeup_locked(so);
697 SOCKBUF_UNLOCK_ASSERT(sb);
703 if (IS_AIOTX_MBUF(m))
704 aiotx_mbuf_seen = true;
705 if (max_nsegs_1mbuf < n)
707 sb_sndptr = m; /* new sb->sb_sndptr if all goes well */
709 /* This mbuf put us right at the max_nsegs limit */
710 if (plen > max_imm && nsegs == max_nsegs) {
716 if (sbused(sb) > sb->sb_hiwat * 5 / 8 &&
717 toep->plen_nocompl + plen >= sb->sb_hiwat / 4)
722 if (sb->sb_flags & SB_AUTOSIZE &&
723 V_tcp_do_autosndbuf &&
724 sb->sb_hiwat < V_tcp_autosndbuf_max &&
725 sbused(sb) >= sb->sb_hiwat * 7 / 8) {
726 int newsize = min(sb->sb_hiwat + V_tcp_autosndbuf_inc,
727 V_tcp_autosndbuf_max);
729 if (!sbreserve_locked(sb, newsize, so, NULL))
730 sb->sb_flags &= ~SB_AUTOSIZE;
732 sowwakeup = 1; /* room available */
735 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
736 t4_aiotx_queue_toep(toep);
737 sowwakeup_locked(so);
740 SOCKBUF_UNLOCK_ASSERT(sb);
742 /* nothing to send */
745 ("%s: nothing to send, but m != NULL", __func__));
749 if (__predict_false(toep->flags & TPF_FIN_SENT))
750 panic("%s: excess tx.", __func__);
752 shove = m == NULL && !(tp->t_flags & TF_MORETOCOME);
753 if (plen <= max_imm && !aiotx_mbuf_seen) {
755 /* Immediate data tx */
757 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
760 /* XXX: how will we recover from this? */
761 toep->flags |= TPF_TX_SUSPENDED;
765 credits = howmany(wr->wr_len, 16);
766 write_tx_wr(txwr, toep, plen, plen, credits, shove, 0,
768 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
775 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
776 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
777 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
779 /* XXX: how will we recover from this? */
780 toep->flags |= TPF_TX_SUSPENDED;
784 credits = howmany(wr_len, 16);
785 write_tx_wr(txwr, toep, 0, plen, credits, shove, 0,
787 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
790 uint64_t *pad = (uint64_t *)
791 ((uintptr_t)txwr + wr_len);
796 KASSERT(toep->tx_credits >= credits,
797 ("%s: not enough credits", __func__));
799 toep->tx_credits -= credits;
800 toep->tx_nocompl += credits;
801 toep->plen_nocompl += plen;
802 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
803 toep->tx_nocompl >= toep->tx_total / 4)
806 if (compl || toep->ulp_mode == ULP_MODE_RDMA) {
807 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
808 toep->tx_nocompl = 0;
809 toep->plen_nocompl = 0;
816 KASSERT(sb_sndptr, ("%s: sb_sndptr is NULL", __func__));
817 sb->sb_sndptr = sb_sndptr;
820 toep->flags |= TPF_TX_DATA_SENT;
821 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
822 toep->flags |= TPF_TX_SUSPENDED;
824 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
826 txsd->tx_credits = credits;
828 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
830 txsd = &toep->txsd[0];
834 t4_l2t_send(sc, wr, toep->l2te);
837 /* Send a FIN if requested, but only if there's no more data to send */
838 if (m == NULL && toep->flags & TPF_SEND_FIN)
839 close_conn(sc, toep);
843 rqdrop_locked(struct mbufq *q, int plen)
848 m = mbufq_dequeue(q);
850 /* Too many credits. */
854 /* Partial credits. */
855 MPASS(plen >= m->m_pkthdr.len);
857 plen -= m->m_pkthdr.len;
863 t4_push_pdus(struct adapter *sc, struct toepcb *toep, int drop)
865 struct mbuf *sndptr, *m;
866 struct fw_ofld_tx_data_wr *txwr;
868 u_int plen, nsegs, credits, max_imm, max_nsegs, max_nsegs_1mbuf;
869 u_int adjusted_plen, ulp_submode;
870 struct inpcb *inp = toep->inp;
871 struct tcpcb *tp = intotcpcb(inp);
872 int tx_credits, shove;
873 struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
874 struct mbufq *pduq = &toep->ulp_pduq;
875 static const u_int ulp_extra_len[] = {0, 4, 4, 8};
877 INP_WLOCK_ASSERT(inp);
878 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
879 ("%s: flowc_wr not sent for tid %u.", __func__, toep->tid));
880 KASSERT(toep->ulp_mode == ULP_MODE_ISCSI,
881 ("%s: ulp_mode %u for toep %p", __func__, toep->ulp_mode, toep));
883 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN))
887 * This function doesn't resume by itself. Someone else must clear the
888 * flag and call this function.
890 if (__predict_false(toep->flags & TPF_TX_SUSPENDED)) {
892 ("%s: drop (%d) != 0 but tx is suspended", __func__, drop));
897 rqdrop_locked(&toep->ulp_pdu_reclaimq, drop);
899 while ((sndptr = mbufq_first(pduq)) != NULL) {
900 M_ASSERTPKTHDR(sndptr);
902 tx_credits = min(toep->tx_credits, MAX_OFLD_TX_CREDITS);
903 max_imm = max_imm_payload(tx_credits);
904 max_nsegs = max_dsgl_nsegs(tx_credits);
908 max_nsegs_1mbuf = 0; /* max # of SGL segments in any one mbuf */
909 for (m = sndptr; m != NULL; m = m->m_next) {
910 int n = sglist_count(mtod(m, void *), m->m_len);
916 * This mbuf would send us _over_ the nsegs limit.
917 * Suspend tx because the PDU can't be sent out.
919 if (plen > max_imm && nsegs > max_nsegs) {
920 toep->flags |= TPF_TX_SUSPENDED;
924 if (max_nsegs_1mbuf < n)
928 if (__predict_false(toep->flags & TPF_FIN_SENT))
929 panic("%s: excess tx.", __func__);
932 * We have a PDU to send. All of it goes out in one WR so 'm'
933 * is NULL. A PDU's length is always a multiple of 4.
936 MPASS((plen & 3) == 0);
937 MPASS(sndptr->m_pkthdr.len == plen);
939 shove = !(tp->t_flags & TF_MORETOCOME);
940 ulp_submode = mbuf_ulp_submode(sndptr);
941 MPASS(ulp_submode < nitems(ulp_extra_len));
944 * plen doesn't include header and data digests, which are
945 * generated and inserted in the right places by the TOE, but
946 * they do occupy TCP sequence space and need to be accounted
949 adjusted_plen = plen + ulp_extra_len[ulp_submode];
950 if (plen <= max_imm) {
952 /* Immediate data tx */
954 wr = alloc_wrqe(roundup2(sizeof(*txwr) + plen, 16),
957 /* XXX: how will we recover from this? */
958 toep->flags |= TPF_TX_SUSPENDED;
962 credits = howmany(wr->wr_len, 16);
963 write_tx_wr(txwr, toep, plen, adjusted_plen, credits,
964 shove, ulp_submode, sc->tt.tx_align);
965 m_copydata(sndptr, 0, plen, (void *)(txwr + 1));
971 wr_len = sizeof(*txwr) + sizeof(struct ulptx_sgl) +
972 ((3 * (nsegs - 1)) / 2 + ((nsegs - 1) & 1)) * 8;
973 wr = alloc_wrqe(roundup2(wr_len, 16), toep->ofld_txq);
975 /* XXX: how will we recover from this? */
976 toep->flags |= TPF_TX_SUSPENDED;
980 credits = howmany(wr_len, 16);
981 write_tx_wr(txwr, toep, 0, adjusted_plen, credits,
982 shove, ulp_submode, sc->tt.tx_align);
983 write_tx_sgl(txwr + 1, sndptr, m, nsegs,
986 uint64_t *pad = (uint64_t *)
987 ((uintptr_t)txwr + wr_len);
992 KASSERT(toep->tx_credits >= credits,
993 ("%s: not enough credits", __func__));
995 m = mbufq_dequeue(pduq);
997 mbufq_enqueue(&toep->ulp_pdu_reclaimq, m);
999 toep->tx_credits -= credits;
1000 toep->tx_nocompl += credits;
1001 toep->plen_nocompl += plen;
1002 if (toep->tx_credits <= toep->tx_total * 3 / 8 &&
1003 toep->tx_nocompl >= toep->tx_total / 4) {
1004 txwr->op_to_immdlen |= htobe32(F_FW_WR_COMPL);
1005 toep->tx_nocompl = 0;
1006 toep->plen_nocompl = 0;
1009 tp->snd_nxt += adjusted_plen;
1010 tp->snd_max += adjusted_plen;
1012 toep->flags |= TPF_TX_DATA_SENT;
1013 if (toep->tx_credits < MIN_OFLD_TX_CREDITS)
1014 toep->flags |= TPF_TX_SUSPENDED;
1016 KASSERT(toep->txsd_avail > 0, ("%s: no txsd", __func__));
1018 txsd->tx_credits = credits;
1020 if (__predict_false(++toep->txsd_pidx == toep->txsd_total)) {
1021 toep->txsd_pidx = 0;
1022 txsd = &toep->txsd[0];
1026 t4_l2t_send(sc, wr, toep->l2te);
1029 /* Send a FIN if requested, but only if there are no more PDUs to send */
1030 if (mbufq_first(pduq) == NULL && toep->flags & TPF_SEND_FIN)
1031 close_conn(sc, toep);
1035 t4_tod_output(struct toedev *tod, struct tcpcb *tp)
1037 struct adapter *sc = tod->tod_softc;
1039 struct inpcb *inp = tp->t_inpcb;
1041 struct toepcb *toep = tp->t_toe;
1043 INP_WLOCK_ASSERT(inp);
1044 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1045 ("%s: inp %p dropped.", __func__, inp));
1046 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1048 if (toep->ulp_mode == ULP_MODE_ISCSI)
1049 t4_push_pdus(sc, toep, 0);
1051 t4_push_frames(sc, toep, 0);
1057 t4_send_fin(struct toedev *tod, struct tcpcb *tp)
1059 struct adapter *sc = tod->tod_softc;
1061 struct inpcb *inp = tp->t_inpcb;
1063 struct toepcb *toep = tp->t_toe;
1065 INP_WLOCK_ASSERT(inp);
1066 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1067 ("%s: inp %p dropped.", __func__, inp));
1068 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1070 toep->flags |= TPF_SEND_FIN;
1071 if (tp->t_state >= TCPS_ESTABLISHED) {
1072 if (toep->ulp_mode == ULP_MODE_ISCSI)
1073 t4_push_pdus(sc, toep, 0);
1075 t4_push_frames(sc, toep, 0);
1082 t4_send_rst(struct toedev *tod, struct tcpcb *tp)
1084 struct adapter *sc = tod->tod_softc;
1085 #if defined(INVARIANTS)
1086 struct inpcb *inp = tp->t_inpcb;
1088 struct toepcb *toep = tp->t_toe;
1090 INP_WLOCK_ASSERT(inp);
1091 KASSERT((inp->inp_flags & INP_DROPPED) == 0,
1092 ("%s: inp %p dropped.", __func__, inp));
1093 KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
1096 KASSERT(toep->flags & TPF_FLOWC_WR_SENT,
1097 ("%s: flowc for tid %u [%s] not sent already",
1098 __func__, toep->tid, tcpstates[tp->t_state]));
1100 send_reset(sc, toep, 0);
1105 * Peer has sent us a FIN.
1108 do_peer_close(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1110 struct adapter *sc = iq->adapter;
1111 const struct cpl_peer_close *cpl = (const void *)(rss + 1);
1112 unsigned int tid = GET_TID(cpl);
1113 struct toepcb *toep = lookup_tid(sc, tid);
1114 struct inpcb *inp = toep->inp;
1115 struct tcpcb *tp = NULL;
1118 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1121 KASSERT(opcode == CPL_PEER_CLOSE,
1122 ("%s: unexpected opcode 0x%x", __func__, opcode));
1123 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1125 if (__predict_false(toep->flags & TPF_SYNQE)) {
1127 struct synq_entry *synqe = (void *)toep;
1129 INP_WLOCK(synqe->lctx->inp);
1130 if (synqe->flags & TPF_SYNQE_HAS_L2TE) {
1131 KASSERT(synqe->flags & TPF_ABORT_SHUTDOWN,
1132 ("%s: listen socket closed but tid %u not aborted.",
1136 * do_pass_accept_req is still running and will
1137 * eventually take care of this tid.
1140 INP_WUNLOCK(synqe->lctx->inp);
1142 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1147 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1149 CURVNET_SET(toep->vnet);
1150 INP_INFO_RLOCK(&V_tcbinfo);
1152 tp = intotcpcb(inp);
1154 CTR5(KTR_CXGBE, "%s: tid %u (%s), toep_flags 0x%x, inp %p", __func__,
1155 tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags, inp);
1157 if (toep->flags & TPF_ABORT_SHUTDOWN)
1160 tp->rcv_nxt++; /* FIN */
1162 so = inp->inp_socket;
1163 if (toep->ulp_mode == ULP_MODE_TCPDDP) {
1165 if (__predict_false(toep->ddp_flags &
1166 (DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE)))
1167 handle_ddp_close(toep, tp, cpl->rcv_nxt);
1172 if (toep->ulp_mode != ULP_MODE_RDMA) {
1173 KASSERT(tp->rcv_nxt == be32toh(cpl->rcv_nxt),
1174 ("%s: rcv_nxt mismatch: %u %u", __func__, tp->rcv_nxt,
1175 be32toh(cpl->rcv_nxt)));
1178 switch (tp->t_state) {
1179 case TCPS_SYN_RECEIVED:
1180 tp->t_starttime = ticks;
1183 case TCPS_ESTABLISHED:
1184 tp->t_state = TCPS_CLOSE_WAIT;
1187 case TCPS_FIN_WAIT_1:
1188 tp->t_state = TCPS_CLOSING;
1191 case TCPS_FIN_WAIT_2:
1193 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1194 INP_INFO_RUNLOCK(&V_tcbinfo);
1198 final_cpl_received(toep);
1202 log(LOG_ERR, "%s: TID %u received CPL_PEER_CLOSE in state %d\n",
1203 __func__, tid, tp->t_state);
1207 INP_INFO_RUNLOCK(&V_tcbinfo);
1213 * Peer has ACK'd our FIN.
1216 do_close_con_rpl(struct sge_iq *iq, const struct rss_header *rss,
1219 struct adapter *sc = iq->adapter;
1220 const struct cpl_close_con_rpl *cpl = (const void *)(rss + 1);
1221 unsigned int tid = GET_TID(cpl);
1222 struct toepcb *toep = lookup_tid(sc, tid);
1223 struct inpcb *inp = toep->inp;
1224 struct tcpcb *tp = NULL;
1225 struct socket *so = NULL;
1227 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1230 KASSERT(opcode == CPL_CLOSE_CON_RPL,
1231 ("%s: unexpected opcode 0x%x", __func__, opcode));
1232 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1233 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1235 CURVNET_SET(toep->vnet);
1236 INP_INFO_RLOCK(&V_tcbinfo);
1238 tp = intotcpcb(inp);
1240 CTR4(KTR_CXGBE, "%s: tid %u (%s), toep_flags 0x%x",
1241 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags);
1243 if (toep->flags & TPF_ABORT_SHUTDOWN)
1246 so = inp->inp_socket;
1247 tp->snd_una = be32toh(cpl->snd_nxt) - 1; /* exclude FIN */
1249 switch (tp->t_state) {
1250 case TCPS_CLOSING: /* see TCPS_FIN_WAIT_2 in do_peer_close too */
1253 INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */
1254 INP_INFO_RUNLOCK(&V_tcbinfo);
1258 final_cpl_received(toep); /* no more CPLs expected */
1266 case TCPS_FIN_WAIT_1:
1267 if (so->so_rcv.sb_state & SBS_CANTRCVMORE)
1268 soisdisconnected(so);
1269 tp->t_state = TCPS_FIN_WAIT_2;
1274 "%s: TID %u received CPL_CLOSE_CON_RPL in state %s\n",
1275 __func__, tid, tcpstates[tp->t_state]);
1279 INP_INFO_RUNLOCK(&V_tcbinfo);
1285 send_abort_rpl(struct adapter *sc, struct sge_wrq *ofld_txq, int tid,
1289 struct cpl_abort_rpl *cpl;
1291 wr = alloc_wrqe(sizeof(*cpl), ofld_txq);
1294 panic("%s: allocation failure.", __func__);
1298 INIT_TP_WR_MIT_CPL(cpl, CPL_ABORT_RPL, tid);
1299 cpl->cmd = rst_status;
1305 abort_status_to_errno(struct tcpcb *tp, unsigned int abort_reason)
1307 switch (abort_reason) {
1308 case CPL_ERR_BAD_SYN:
1309 case CPL_ERR_CONN_RESET:
1310 return (tp->t_state == TCPS_CLOSE_WAIT ? EPIPE : ECONNRESET);
1311 case CPL_ERR_XMIT_TIMEDOUT:
1312 case CPL_ERR_PERSIST_TIMEDOUT:
1313 case CPL_ERR_FINWAIT2_TIMEDOUT:
1314 case CPL_ERR_KEEPALIVE_TIMEDOUT:
1322 * TCP RST from the peer, timeout, or some other such critical error.
1325 do_abort_req(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1327 struct adapter *sc = iq->adapter;
1328 const struct cpl_abort_req_rss *cpl = (const void *)(rss + 1);
1329 unsigned int tid = GET_TID(cpl);
1330 struct toepcb *toep = lookup_tid(sc, tid);
1331 struct sge_wrq *ofld_txq = toep->ofld_txq;
1335 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1338 KASSERT(opcode == CPL_ABORT_REQ_RSS,
1339 ("%s: unexpected opcode 0x%x", __func__, opcode));
1340 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1342 if (toep->flags & TPF_SYNQE)
1343 return (do_abort_req_synqe(iq, rss, m));
1345 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1347 if (negative_advice(cpl->status)) {
1348 CTR4(KTR_CXGBE, "%s: negative advice %d for tid %d (0x%x)",
1349 __func__, cpl->status, tid, toep->flags);
1350 return (0); /* Ignore negative advice */
1354 CURVNET_SET(toep->vnet);
1355 INP_INFO_RLOCK(&V_tcbinfo); /* for tcp_close */
1358 tp = intotcpcb(inp);
1361 "%s: tid %d (%s), toep_flags 0x%x, inp_flags 0x%x, status %d",
1362 __func__, tid, tp ? tcpstates[tp->t_state] : "no tp", toep->flags,
1363 inp->inp_flags, cpl->status);
1366 * If we'd initiated an abort earlier the reply to it is responsible for
1367 * cleaning up resources. Otherwise we tear everything down right here
1368 * right now. We owe the T4 a CPL_ABORT_RPL no matter what.
1370 if (toep->flags & TPF_ABORT_SHUTDOWN) {
1374 toep->flags |= TPF_ABORT_SHUTDOWN;
1376 if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
1377 struct socket *so = inp->inp_socket;
1380 so_error_set(so, abort_status_to_errno(tp,
1384 INP_WLOCK(inp); /* re-acquire */
1387 final_cpl_received(toep);
1389 INP_INFO_RUNLOCK(&V_tcbinfo);
1391 send_abort_rpl(sc, ofld_txq, tid, CPL_ABORT_NO_RST);
1396 * Reply to the CPL_ABORT_REQ (send_reset)
1399 do_abort_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1401 struct adapter *sc = iq->adapter;
1402 const struct cpl_abort_rpl_rss *cpl = (const void *)(rss + 1);
1403 unsigned int tid = GET_TID(cpl);
1404 struct toepcb *toep = lookup_tid(sc, tid);
1405 struct inpcb *inp = toep->inp;
1407 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1410 KASSERT(opcode == CPL_ABORT_RPL_RSS,
1411 ("%s: unexpected opcode 0x%x", __func__, opcode));
1412 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1414 if (toep->flags & TPF_SYNQE)
1415 return (do_abort_rpl_synqe(iq, rss, m));
1417 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1419 CTR5(KTR_CXGBE, "%s: tid %u, toep %p, inp %p, status %d",
1420 __func__, tid, toep, inp, cpl->status);
1422 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1423 ("%s: wasn't expecting abort reply", __func__));
1426 final_cpl_received(toep);
1432 do_rx_data(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1434 struct adapter *sc = iq->adapter;
1435 const struct cpl_rx_data *cpl = mtod(m, const void *);
1436 unsigned int tid = GET_TID(cpl);
1437 struct toepcb *toep = lookup_tid(sc, tid);
1438 struct inpcb *inp = toep->inp;
1443 uint32_t ddp_placed = 0;
1445 if (__predict_false(toep->flags & TPF_SYNQE)) {
1447 struct synq_entry *synqe = (void *)toep;
1449 INP_WLOCK(synqe->lctx->inp);
1450 if (synqe->flags & TPF_SYNQE_HAS_L2TE) {
1451 KASSERT(synqe->flags & TPF_ABORT_SHUTDOWN,
1452 ("%s: listen socket closed but tid %u not aborted.",
1456 * do_pass_accept_req is still running and will
1457 * eventually take care of this tid.
1460 INP_WUNLOCK(synqe->lctx->inp);
1462 CTR4(KTR_CXGBE, "%s: tid %u, synqe %p (0x%x)", __func__, tid,
1468 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1470 /* strip off CPL header */
1471 m_adj(m, sizeof(*cpl));
1472 len = m->m_pkthdr.len;
1475 if (inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) {
1476 CTR4(KTR_CXGBE, "%s: tid %u, rx (%d bytes), inp_flags 0x%x",
1477 __func__, tid, len, inp->inp_flags);
1483 tp = intotcpcb(inp);
1485 if (__predict_false(tp->rcv_nxt != be32toh(cpl->seq)))
1486 ddp_placed = be32toh(cpl->seq) - tp->rcv_nxt;
1489 if (tp->rcv_wnd < len) {
1490 KASSERT(toep->ulp_mode == ULP_MODE_RDMA,
1491 ("%s: negative window size", __func__));
1495 tp->t_rcvtime = ticks;
1497 if (toep->ulp_mode == ULP_MODE_TCPDDP)
1499 so = inp_inpcbtosocket(inp);
1503 if (__predict_false(sb->sb_state & SBS_CANTRCVMORE)) {
1504 CTR3(KTR_CXGBE, "%s: tid %u, excess rx (%d bytes)",
1505 __func__, tid, len);
1508 if (toep->ulp_mode == ULP_MODE_TCPDDP)
1512 CURVNET_SET(toep->vnet);
1513 INP_INFO_RLOCK(&V_tcbinfo);
1515 tp = tcp_drop(tp, ECONNRESET);
1518 INP_INFO_RUNLOCK(&V_tcbinfo);
1524 /* receive buffer autosize */
1525 MPASS(toep->vnet == so->so_vnet);
1526 CURVNET_SET(toep->vnet);
1527 if (sb->sb_flags & SB_AUTOSIZE &&
1528 V_tcp_do_autorcvbuf &&
1529 sb->sb_hiwat < V_tcp_autorcvbuf_max &&
1530 len > (sbspace(sb) / 8 * 7)) {
1531 unsigned int hiwat = sb->sb_hiwat;
1532 unsigned int newsize = min(hiwat + V_tcp_autorcvbuf_inc,
1533 V_tcp_autorcvbuf_max);
1535 if (!sbreserve_locked(sb, newsize, so, NULL))
1536 sb->sb_flags &= ~SB_AUTOSIZE;
1538 toep->rx_credits += newsize - hiwat;
1541 if (toep->ddp_waiting_count != 0 || toep->ddp_active_count != 0)
1542 CTR3(KTR_CXGBE, "%s: tid %u, non-ddp rx (%d bytes)", __func__,
1545 if (toep->ulp_mode == ULP_MODE_TCPDDP) {
1546 int changed = !(toep->ddp_flags & DDP_ON) ^ cpl->ddp_off;
1549 if (toep->ddp_flags & DDP_SC_REQ)
1550 toep->ddp_flags ^= DDP_ON | DDP_SC_REQ;
1552 KASSERT(cpl->ddp_off == 1,
1553 ("%s: DDP switched on by itself.",
1556 /* Fell out of DDP mode */
1557 toep->ddp_flags &= ~DDP_ON;
1558 CTR1(KTR_CXGBE, "%s: fell out of DDP mode",
1561 insert_ddp_data(toep, ddp_placed);
1565 if (toep->ddp_flags & DDP_ON) {
1567 * CPL_RX_DATA with DDP on can only be an indicate.
1568 * Start posting queued AIO requests via DDP. The
1569 * payload that arrived in this indicate is appended
1570 * to the socket buffer as usual.
1572 handle_ddp_indicate(toep);
1576 KASSERT(toep->sb_cc >= sbused(sb),
1577 ("%s: sb %p has more data (%d) than last time (%d).",
1578 __func__, sb, sbused(sb), toep->sb_cc));
1579 toep->rx_credits += toep->sb_cc - sbused(sb);
1580 sbappendstream_locked(sb, m, 0);
1581 toep->sb_cc = sbused(sb);
1582 if (toep->rx_credits > 0 && toep->sb_cc + tp->rcv_wnd < sb->sb_lowat) {
1585 credits = send_rx_credits(sc, toep, toep->rx_credits);
1586 toep->rx_credits -= credits;
1587 tp->rcv_wnd += credits;
1588 tp->rcv_adv += credits;
1591 if (toep->ddp_waiting_count > 0 && sbavail(sb) != 0) {
1592 CTR2(KTR_CXGBE, "%s: tid %u queueing AIO task", __func__,
1594 ddp_queue_toep(toep);
1596 sorwakeup_locked(so);
1597 SOCKBUF_UNLOCK_ASSERT(sb);
1598 if (toep->ulp_mode == ULP_MODE_TCPDDP)
1606 #define S_CPL_FW4_ACK_OPCODE 24
1607 #define M_CPL_FW4_ACK_OPCODE 0xff
1608 #define V_CPL_FW4_ACK_OPCODE(x) ((x) << S_CPL_FW4_ACK_OPCODE)
1609 #define G_CPL_FW4_ACK_OPCODE(x) \
1610 (((x) >> S_CPL_FW4_ACK_OPCODE) & M_CPL_FW4_ACK_OPCODE)
1612 #define S_CPL_FW4_ACK_FLOWID 0
1613 #define M_CPL_FW4_ACK_FLOWID 0xffffff
1614 #define V_CPL_FW4_ACK_FLOWID(x) ((x) << S_CPL_FW4_ACK_FLOWID)
1615 #define G_CPL_FW4_ACK_FLOWID(x) \
1616 (((x) >> S_CPL_FW4_ACK_FLOWID) & M_CPL_FW4_ACK_FLOWID)
1618 #define S_CPL_FW4_ACK_CR 24
1619 #define M_CPL_FW4_ACK_CR 0xff
1620 #define V_CPL_FW4_ACK_CR(x) ((x) << S_CPL_FW4_ACK_CR)
1621 #define G_CPL_FW4_ACK_CR(x) (((x) >> S_CPL_FW4_ACK_CR) & M_CPL_FW4_ACK_CR)
1623 #define S_CPL_FW4_ACK_SEQVAL 0
1624 #define M_CPL_FW4_ACK_SEQVAL 0x1
1625 #define V_CPL_FW4_ACK_SEQVAL(x) ((x) << S_CPL_FW4_ACK_SEQVAL)
1626 #define G_CPL_FW4_ACK_SEQVAL(x) \
1627 (((x) >> S_CPL_FW4_ACK_SEQVAL) & M_CPL_FW4_ACK_SEQVAL)
1628 #define F_CPL_FW4_ACK_SEQVAL V_CPL_FW4_ACK_SEQVAL(1U)
1631 do_fw4_ack(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1633 struct adapter *sc = iq->adapter;
1634 const struct cpl_fw4_ack *cpl = (const void *)(rss + 1);
1635 unsigned int tid = G_CPL_FW4_ACK_FLOWID(be32toh(OPCODE_TID(cpl)));
1636 struct toepcb *toep = lookup_tid(sc, tid);
1640 uint8_t credits = cpl->credits;
1641 struct ofld_tx_sdesc *txsd;
1644 unsigned int opcode = G_CPL_FW4_ACK_OPCODE(be32toh(OPCODE_TID(cpl)));
1648 * Very unusual case: we'd sent a flowc + abort_req for a synq entry and
1649 * now this comes back carrying the credits for the flowc.
1651 if (__predict_false(toep->flags & TPF_SYNQE)) {
1652 KASSERT(toep->flags & TPF_ABORT_SHUTDOWN,
1653 ("%s: credits for a synq entry %p", __func__, toep));
1659 KASSERT(opcode == CPL_FW4_ACK,
1660 ("%s: unexpected opcode 0x%x", __func__, opcode));
1661 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1662 KASSERT(toep->tid == tid, ("%s: toep tid mismatch", __func__));
1666 if (__predict_false(toep->flags & TPF_ABORT_SHUTDOWN)) {
1671 KASSERT((inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) == 0,
1672 ("%s: inp_flags 0x%x", __func__, inp->inp_flags));
1674 tp = intotcpcb(inp);
1676 if (cpl->flags & CPL_FW4_ACK_FLAGS_SEQVAL) {
1677 tcp_seq snd_una = be32toh(cpl->snd_una);
1680 if (__predict_false(SEQ_LT(snd_una, tp->snd_una))) {
1682 "%s: unexpected seq# %x for TID %u, snd_una %x\n",
1683 __func__, snd_una, toep->tid, tp->snd_una);
1687 if (tp->snd_una != snd_una) {
1688 tp->snd_una = snd_una;
1689 tp->ts_recent_age = tcp_ts_getticks();
1693 #ifdef VERBOSE_TRACES
1694 CTR3(KTR_CXGBE, "%s: tid %d credits %u", __func__, tid, credits);
1696 so = inp->inp_socket;
1697 txsd = &toep->txsd[toep->txsd_cidx];
1700 KASSERT(credits >= txsd->tx_credits,
1701 ("%s: too many (or partial) credits", __func__));
1702 credits -= txsd->tx_credits;
1703 toep->tx_credits += txsd->tx_credits;
1707 KASSERT(toep->txsd_avail <= toep->txsd_total,
1708 ("%s: txsd avail > total", __func__));
1709 if (__predict_false(++toep->txsd_cidx == toep->txsd_total)) {
1710 txsd = &toep->txsd[0];
1711 toep->txsd_cidx = 0;
1715 if (toep->tx_credits == toep->tx_total) {
1716 toep->tx_nocompl = 0;
1717 toep->plen_nocompl = 0;
1720 if (toep->flags & TPF_TX_SUSPENDED &&
1721 toep->tx_credits >= toep->tx_total / 4) {
1722 #ifdef VERBOSE_TRACES
1723 CTR2(KTR_CXGBE, "%s: tid %d calling t4_push_frames", __func__,
1726 toep->flags &= ~TPF_TX_SUSPENDED;
1727 CURVNET_SET(toep->vnet);
1728 if (toep->ulp_mode == ULP_MODE_ISCSI)
1729 t4_push_pdus(sc, toep, plen);
1731 t4_push_frames(sc, toep, plen);
1733 } else if (plen > 0) {
1734 struct sockbuf *sb = &so->so_snd;
1739 if (toep->ulp_mode == ULP_MODE_ISCSI) {
1741 if (__predict_false(sbu > 0)) {
1743 * The data trasmitted before the tid's ULP mode
1744 * changed to ISCSI is still in so_snd.
1745 * Incoming credits should account for so_snd
1748 sbdrop_locked(sb, min(sbu, plen));
1749 plen -= min(sbu, plen);
1751 sowwakeup_locked(so); /* unlocks so_snd */
1752 rqdrop_locked(&toep->ulp_pdu_reclaimq, plen);
1754 #ifdef VERBOSE_TRACES
1755 CTR3(KTR_CXGBE, "%s: tid %d dropped %d bytes", __func__,
1758 sbdrop_locked(sb, plen);
1759 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
1760 t4_aiotx_queue_toep(toep);
1761 sowwakeup_locked(so); /* unlocks so_snd */
1763 SOCKBUF_UNLOCK_ASSERT(sb);
1772 do_set_tcb_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
1774 struct adapter *sc = iq->adapter;
1775 const struct cpl_set_tcb_rpl *cpl = (const void *)(rss + 1);
1776 unsigned int tid = GET_TID(cpl);
1777 struct toepcb *toep;
1779 unsigned int opcode = G_CPL_OPCODE(be32toh(OPCODE_TID(cpl)));
1782 KASSERT(opcode == CPL_SET_TCB_RPL,
1783 ("%s: unexpected opcode 0x%x", __func__, opcode));
1784 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
1785 MPASS(iq != &sc->sge.fwq);
1787 toep = lookup_tid(sc, tid);
1788 if (toep->ulp_mode == ULP_MODE_TCPDDP) {
1789 handle_ddp_tcb_rpl(toep, cpl);
1794 * TOM and/or other ULPs don't request replies for CPL_SET_TCB or
1795 * CPL_SET_TCB_FIELD requests. This can easily change and when it does
1796 * the dispatch code will go here.
1799 panic("%s: Unexpected CPL_SET_TCB_RPL for tid %u on iq %p", __func__,
1802 log(LOG_ERR, "%s: Unexpected CPL_SET_TCB_RPL for tid %u on iq %p\n",
1810 t4_set_tcb_field(struct adapter *sc, struct sge_wrq *wrq, int tid,
1811 uint16_t word, uint64_t mask, uint64_t val, int reply, int cookie, int iqid)
1814 struct cpl_set_tcb_field *req;
1816 MPASS((cookie & ~M_COOKIE) == 0);
1817 MPASS((iqid & ~M_QUEUENO) == 0);
1819 wr = alloc_wrqe(sizeof(*req), wrq);
1822 panic("%s: allocation failure.", __func__);
1826 INIT_TP_WR_MIT_CPL(req, CPL_SET_TCB_FIELD, tid);
1827 req->reply_ctrl = htobe16(V_QUEUENO(iqid));
1829 req->reply_ctrl |= htobe16(F_NO_REPLY);
1830 req->word_cookie = htobe16(V_WORD(word) | V_COOKIE(cookie));
1831 req->mask = htobe64(mask);
1832 req->val = htobe64(val);
1838 t4_init_cpl_io_handlers(void)
1841 t4_register_cpl_handler(CPL_PEER_CLOSE, do_peer_close);
1842 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, do_close_con_rpl);
1843 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, do_abort_req);
1844 t4_register_cpl_handler(CPL_ABORT_RPL_RSS, do_abort_rpl);
1845 t4_register_cpl_handler(CPL_RX_DATA, do_rx_data);
1846 t4_register_cpl_handler(CPL_FW4_ACK, do_fw4_ack);
1850 t4_uninit_cpl_io_handlers(void)
1853 t4_register_cpl_handler(CPL_PEER_CLOSE, NULL);
1854 t4_register_cpl_handler(CPL_CLOSE_CON_RPL, NULL);
1855 t4_register_cpl_handler(CPL_ABORT_REQ_RSS, NULL);
1856 t4_register_cpl_handler(CPL_ABORT_RPL_RSS, NULL);
1857 t4_register_cpl_handler(CPL_RX_DATA, NULL);
1858 t4_register_cpl_handler(CPL_FW4_ACK, NULL);
1862 * Use the 'backend3' field in AIO jobs to store the amount of data
1863 * sent by the AIO job so far and the 'backend4' field to hold an
1864 * error that should be reported when the job is completed.
1866 #define aio_sent backend3
1867 #define aio_error backend4
1869 #define jobtotid(job) \
1870 (((struct toepcb *)(so_sototcpcb((job)->fd_file->f_data)->t_toe))->tid)
1873 free_aiotx_buffer(struct aiotx_buffer *ab)
1879 if (refcount_release(&ab->refcount) == 0)
1883 error = job->aio_error;
1884 status = job->aio_sent;
1885 vm_page_unhold_pages(ab->ps.pages, ab->ps.npages);
1887 #ifdef VERBOSE_TRACES
1888 CTR5(KTR_CXGBE, "%s: tid %d completed %p len %ld, error %d", __func__,
1889 jobtotid(job), job, status, error);
1891 if (error == ECANCELED && status != 0)
1893 if (error == ECANCELED)
1896 aio_complete(job, -1, error);
1898 aio_complete(job, status, 0);
1902 t4_aiotx_mbuf_free(struct mbuf *m, void *buffer, void *arg)
1904 struct aiotx_buffer *ab = buffer;
1906 #ifdef VERBOSE_TRACES
1907 CTR3(KTR_CXGBE, "%s: completed %d bytes for tid %d", __func__,
1908 m->m_len, jobtotid(ab->job));
1910 free_aiotx_buffer(ab);
1914 * Hold the buffer backing an AIO request and return an AIO transmit
1918 hold_aio(struct kaiocb *job)
1920 struct aiotx_buffer *ab;
1923 vm_offset_t start, end, pgoff;
1926 MPASS(job->backend1 == NULL);
1929 * The AIO subsystem will cancel and drain all requests before
1930 * permitting a process to exit or exec, so p_vmspace should
1933 vm = job->userproc->p_vmspace;
1935 start = (uintptr_t)job->uaiocb.aio_buf;
1936 pgoff = start & PAGE_MASK;
1937 end = round_page(start + job->uaiocb.aio_nbytes);
1938 start = trunc_page(start);
1939 n = atop(end - start);
1941 ab = malloc(sizeof(*ab) + n * sizeof(vm_page_t), M_CXGBE, M_WAITOK |
1943 refcount_init(&ab->refcount, 1);
1944 ab->ps.pages = (vm_page_t *)(ab + 1);
1945 ab->ps.npages = vm_fault_quick_hold_pages(map, start, end - start,
1946 VM_PROT_WRITE, ab->ps.pages, n);
1947 if (ab->ps.npages < 0) {
1952 KASSERT(ab->ps.npages == n,
1953 ("hold_aio: page count mismatch: %d vs %d", ab->ps.npages, n));
1955 ab->ps.offset = pgoff;
1956 ab->ps.len = job->uaiocb.aio_nbytes;
1959 #ifdef VERBOSE_TRACES
1960 CTR5(KTR_CXGBE, "%s: tid %d, new pageset %p for job %p, npages %d",
1961 __func__, jobtotid(job), &ab->ps, job, ab->ps.npages);
1967 t4_aiotx_process_job(struct toepcb *toep, struct socket *so, struct kaiocb *job)
1972 struct aiotx_buffer *ab;
1977 bool moretocome, sendmore;
1979 sc = td_adapter(toep->td);
1987 error = mac_socket_check_send(fp->f_cred, so);
1993 error = hold_aio(job);
1999 /* Inline sosend_generic(). */
2003 error = sblock(sb, SBL_WAIT);
2007 m = m_get(M_WAITOK, MT_DATA);
2010 if (so->so_snd.sb_state & SBS_CANTSENDMORE) {
2013 if ((so->so_options & SO_NOSIGPIPE) == 0) {
2014 PROC_LOCK(job->userproc);
2015 kern_psignal(job->userproc, SIGPIPE);
2016 PROC_UNLOCK(job->userproc);
2022 error = so->so_error;
2028 if ((so->so_state & SS_ISCONNECTED) == 0) {
2034 if (sbspace(sb) < sb->sb_lowat) {
2035 MPASS(job->aio_sent == 0 || !(so->so_state & SS_NBIO));
2038 * Don't block if there is too little room in the socket
2039 * buffer. Instead, requeue the request.
2041 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2047 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2054 * Write as much data as the socket permits, but no more than a
2055 * a single sndbuf at a time.
2057 m->m_len = sbspace(sb);
2058 if (m->m_len > ab->ps.len - job->aio_sent) {
2059 m->m_len = ab->ps.len - job->aio_sent;
2063 if (m->m_len > sc->tt.sndbuf) {
2064 m->m_len = sc->tt.sndbuf;
2069 if (!TAILQ_EMPTY(&toep->aiotx_jobq))
2072 MPASS(m->m_len != 0);
2074 /* Inlined tcp_usr_send(). */
2078 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
2085 refcount_acquire(&ab->refcount);
2086 m_extadd(m, NULL, ab->ps.len, t4_aiotx_mbuf_free, ab,
2087 (void *)(uintptr_t)job->aio_sent, 0, EXT_NET_DRV);
2088 m->m_ext.ext_flags |= EXT_FLAG_AIOTX;
2089 job->aio_sent += m->m_len;
2091 sbappendstream(sb, m, 0);
2094 if (!(inp->inp_flags & INP_DROPPED)) {
2095 tp = intotcpcb(inp);
2097 tp->t_flags |= TF_MORETOCOME;
2098 error = tp->t_fb->tfb_tcp_output(tp);
2100 tp->t_flags &= ~TF_MORETOCOME;
2112 * If this is a non-blocking socket and the request has not
2113 * been fully completed, requeue it until the socket is ready
2116 if (job->aio_sent < job->uaiocb.aio_nbytes &&
2117 !(so->so_state & SS_NBIO)) {
2119 if (!aio_set_cancel_function(job, t4_aiotx_cancel)) {
2124 TAILQ_INSERT_HEAD(&toep->aiotx_jobq, job, list);
2129 * If the request will not be requeued, drop a reference on
2130 * the the aiotx buffer. Any mbufs in flight should still
2131 * contain a reference, but this drops the reference that the
2132 * job owns while it is waiting to queue mbufs to the socket.
2134 free_aiotx_buffer(ab);
2139 job->aio_error = error;
2140 free_aiotx_buffer(ab);
2142 MPASS(job->aio_sent == 0);
2143 aio_complete(job, -1, error);
2152 t4_aiotx_task(void *context, int pending)
2154 struct toepcb *toep = context;
2155 struct inpcb *inp = toep->inp;
2156 struct socket *so = inp->inp_socket;
2159 CURVNET_SET(toep->vnet);
2160 SOCKBUF_LOCK(&so->so_snd);
2161 while (!TAILQ_EMPTY(&toep->aiotx_jobq) && sowriteable(so)) {
2162 job = TAILQ_FIRST(&toep->aiotx_jobq);
2163 TAILQ_REMOVE(&toep->aiotx_jobq, job, list);
2164 if (!aio_clear_cancel_function(job))
2167 t4_aiotx_process_job(toep, so, job);
2169 toep->aiotx_task_active = false;
2170 SOCKBUF_UNLOCK(&so->so_snd);
2177 t4_aiotx_queue_toep(struct toepcb *toep)
2180 SOCKBUF_LOCK_ASSERT(&toep->inp->inp_socket->so_snd);
2181 #ifdef VERBOSE_TRACES
2182 CTR3(KTR_CXGBE, "%s: queueing aiotx task for tid %d, active = %s",
2183 __func__, toep->tid, toep->aiotx_task_active ? "true" : "false");
2185 if (toep->aiotx_task_active)
2187 toep->aiotx_task_active = true;
2189 soaio_enqueue(&toep->aiotx_task);
2193 t4_aiotx_cancel(struct kaiocb *job)
2195 struct aiotx_buffer *ab;
2199 struct toepcb *toep;
2201 so = job->fd_file->f_data;
2202 tp = so_sototcpcb(so);
2204 MPASS(job->uaiocb.aio_lio_opcode == LIO_WRITE);
2208 if (!aio_cancel_cleared(job))
2209 TAILQ_REMOVE(&toep->aiotx_jobq, job, list);
2214 free_aiotx_buffer(ab);
2220 t4_aio_queue_aiotx(struct socket *so, struct kaiocb *job)
2222 struct tcpcb *tp = so_sototcpcb(so);
2223 struct toepcb *toep = tp->t_toe;
2224 struct adapter *sc = td_adapter(toep->td);
2226 /* This only handles writes. */
2227 if (job->uaiocb.aio_lio_opcode != LIO_WRITE)
2228 return (EOPNOTSUPP);
2230 if (!sc->tt.tx_zcopy)
2231 return (EOPNOTSUPP);
2233 SOCKBUF_LOCK(&so->so_snd);
2234 #ifdef VERBOSE_TRACES
2235 CTR2(KTR_CXGBE, "%s: queueing %p", __func__, job);
2237 if (!aio_set_cancel_function(job, t4_aiotx_cancel))
2238 panic("new job was cancelled");
2239 TAILQ_INSERT_TAIL(&toep->aiotx_jobq, job, list);
2240 if (sowriteable(so))
2241 t4_aiotx_queue_toep(toep);
2242 SOCKBUF_UNLOCK(&so->so_snd);
2247 aiotx_init_toep(struct toepcb *toep)
2250 TAILQ_INIT(&toep->aiotx_jobq);
2251 TASK_INIT(&toep->aiotx_task, 0, t4_aiotx_task, toep);