18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci/* Authors: Bernard Metzler <bmt@zurich.ibm.com> */
48c2ecf20Sopenharmony_ci/* Copyright (c) 2008-2019, IBM Corporation */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/errno.h>
78c2ecf20Sopenharmony_ci#include <linux/types.h>
88c2ecf20Sopenharmony_ci#include <linux/net.h>
98c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
108c2ecf20Sopenharmony_ci#include <linux/highmem.h>
118c2ecf20Sopenharmony_ci#include <net/tcp.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <rdma/iw_cm.h>
148c2ecf20Sopenharmony_ci#include <rdma/ib_verbs.h>
158c2ecf20Sopenharmony_ci#include <rdma/ib_user_verbs.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "siw.h"
188c2ecf20Sopenharmony_ci#include "siw_verbs.h"
198c2ecf20Sopenharmony_ci#include "siw_mem.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define MAX_HDR_INLINE					\
228c2ecf20Sopenharmony_ci	(((uint32_t)(sizeof(struct siw_rreq_pkt) -	\
238c2ecf20Sopenharmony_ci		     sizeof(struct iwarp_send))) & 0xF8)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic struct page *siw_get_pblpage(struct siw_mem *mem, u64 addr, int *idx)
268c2ecf20Sopenharmony_ci{
278c2ecf20Sopenharmony_ci	struct siw_pbl *pbl = mem->pbl;
288c2ecf20Sopenharmony_ci	u64 offset = addr - mem->va;
298c2ecf20Sopenharmony_ci	dma_addr_t paddr = siw_pbl_get_buffer(pbl, offset, NULL, idx);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	if (paddr)
328c2ecf20Sopenharmony_ci		return virt_to_page((void *)(uintptr_t)paddr);
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	return NULL;
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/*
388c2ecf20Sopenharmony_ci * Copy short payload at provided destination payload address
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_cistatic int siw_try_1seg(struct siw_iwarp_tx *c_tx, void *paddr)
418c2ecf20Sopenharmony_ci{
428c2ecf20Sopenharmony_ci	struct siw_wqe *wqe = &c_tx->wqe_active;
438c2ecf20Sopenharmony_ci	struct siw_sge *sge = &wqe->sqe.sge[0];
448c2ecf20Sopenharmony_ci	u32 bytes = sge->length;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	if (bytes > MAX_HDR_INLINE || wqe->sqe.num_sge != 1)
478c2ecf20Sopenharmony_ci		return MAX_HDR_INLINE + 1;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	if (!bytes)
508c2ecf20Sopenharmony_ci		return 0;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	if (tx_flags(wqe) & SIW_WQE_INLINE) {
538c2ecf20Sopenharmony_ci		memcpy(paddr, &wqe->sqe.sge[1], bytes);
548c2ecf20Sopenharmony_ci	} else {
558c2ecf20Sopenharmony_ci		struct siw_mem *mem = wqe->mem[0];
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci		if (!mem->mem_obj) {
588c2ecf20Sopenharmony_ci			/* Kernel client using kva */
598c2ecf20Sopenharmony_ci			memcpy(paddr,
608c2ecf20Sopenharmony_ci			       (const void *)(uintptr_t)sge->laddr, bytes);
618c2ecf20Sopenharmony_ci		} else if (c_tx->in_syscall) {
628c2ecf20Sopenharmony_ci			if (copy_from_user(paddr, u64_to_user_ptr(sge->laddr),
638c2ecf20Sopenharmony_ci					   bytes))
648c2ecf20Sopenharmony_ci				return -EFAULT;
658c2ecf20Sopenharmony_ci		} else {
668c2ecf20Sopenharmony_ci			unsigned int off = sge->laddr & ~PAGE_MASK;
678c2ecf20Sopenharmony_ci			struct page *p;
688c2ecf20Sopenharmony_ci			char *buffer;
698c2ecf20Sopenharmony_ci			int pbl_idx = 0;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci			if (!mem->is_pbl)
728c2ecf20Sopenharmony_ci				p = siw_get_upage(mem->umem, sge->laddr);
738c2ecf20Sopenharmony_ci			else
748c2ecf20Sopenharmony_ci				p = siw_get_pblpage(mem, sge->laddr, &pbl_idx);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci			if (unlikely(!p))
778c2ecf20Sopenharmony_ci				return -EFAULT;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci			buffer = kmap(p);
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci			if (likely(PAGE_SIZE - off >= bytes)) {
828c2ecf20Sopenharmony_ci				memcpy(paddr, buffer + off, bytes);
838c2ecf20Sopenharmony_ci			} else {
848c2ecf20Sopenharmony_ci				unsigned long part = bytes - (PAGE_SIZE - off);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci				memcpy(paddr, buffer + off, part);
878c2ecf20Sopenharmony_ci				kunmap(p);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci				if (!mem->is_pbl)
908c2ecf20Sopenharmony_ci					p = siw_get_upage(mem->umem,
918c2ecf20Sopenharmony_ci							  sge->laddr + part);
928c2ecf20Sopenharmony_ci				else
938c2ecf20Sopenharmony_ci					p = siw_get_pblpage(mem,
948c2ecf20Sopenharmony_ci							    sge->laddr + part,
958c2ecf20Sopenharmony_ci							    &pbl_idx);
968c2ecf20Sopenharmony_ci				if (unlikely(!p))
978c2ecf20Sopenharmony_ci					return -EFAULT;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci				buffer = kmap(p);
1008c2ecf20Sopenharmony_ci				memcpy(paddr + part, buffer, bytes - part);
1018c2ecf20Sopenharmony_ci			}
1028c2ecf20Sopenharmony_ci			kunmap(p);
1038c2ecf20Sopenharmony_ci		}
1048c2ecf20Sopenharmony_ci	}
1058c2ecf20Sopenharmony_ci	return (int)bytes;
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define PKT_FRAGMENTED 1
1098c2ecf20Sopenharmony_ci#define PKT_COMPLETE 0
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci/*
1128c2ecf20Sopenharmony_ci * siw_qp_prepare_tx()
1138c2ecf20Sopenharmony_ci *
1148c2ecf20Sopenharmony_ci * Prepare tx state for sending out one fpdu. Builds complete pkt
1158c2ecf20Sopenharmony_ci * if no user data or only immediate data are present.
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci * returns PKT_COMPLETE if complete pkt built, PKT_FRAGMENTED otherwise.
1188c2ecf20Sopenharmony_ci */
1198c2ecf20Sopenharmony_cistatic int siw_qp_prepare_tx(struct siw_iwarp_tx *c_tx)
1208c2ecf20Sopenharmony_ci{
1218c2ecf20Sopenharmony_ci	struct siw_wqe *wqe = &c_tx->wqe_active;
1228c2ecf20Sopenharmony_ci	char *crc = NULL;
1238c2ecf20Sopenharmony_ci	int data = 0;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	switch (tx_type(wqe)) {
1268c2ecf20Sopenharmony_ci	case SIW_OP_READ:
1278c2ecf20Sopenharmony_ci	case SIW_OP_READ_LOCAL_INV:
1288c2ecf20Sopenharmony_ci		memcpy(&c_tx->pkt.ctrl,
1298c2ecf20Sopenharmony_ci		       &iwarp_pktinfo[RDMAP_RDMA_READ_REQ].ctrl,
1308c2ecf20Sopenharmony_ci		       sizeof(struct iwarp_ctrl));
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci		c_tx->pkt.rreq.rsvd = 0;
1338c2ecf20Sopenharmony_ci		c_tx->pkt.rreq.ddp_qn = htonl(RDMAP_UNTAGGED_QN_RDMA_READ);
1348c2ecf20Sopenharmony_ci		c_tx->pkt.rreq.ddp_msn =
1358c2ecf20Sopenharmony_ci			htonl(++c_tx->ddp_msn[RDMAP_UNTAGGED_QN_RDMA_READ]);
1368c2ecf20Sopenharmony_ci		c_tx->pkt.rreq.ddp_mo = 0;
1378c2ecf20Sopenharmony_ci		c_tx->pkt.rreq.sink_stag = htonl(wqe->sqe.sge[0].lkey);
1388c2ecf20Sopenharmony_ci		c_tx->pkt.rreq.sink_to =
1398c2ecf20Sopenharmony_ci			cpu_to_be64(wqe->sqe.sge[0].laddr);
1408c2ecf20Sopenharmony_ci		c_tx->pkt.rreq.source_stag = htonl(wqe->sqe.rkey);
1418c2ecf20Sopenharmony_ci		c_tx->pkt.rreq.source_to = cpu_to_be64(wqe->sqe.raddr);
1428c2ecf20Sopenharmony_ci		c_tx->pkt.rreq.read_size = htonl(wqe->sqe.sge[0].length);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci		c_tx->ctrl_len = sizeof(struct iwarp_rdma_rreq);
1458c2ecf20Sopenharmony_ci		crc = (char *)&c_tx->pkt.rreq_pkt.crc;
1468c2ecf20Sopenharmony_ci		break;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	case SIW_OP_SEND:
1498c2ecf20Sopenharmony_ci		if (tx_flags(wqe) & SIW_WQE_SOLICITED)
1508c2ecf20Sopenharmony_ci			memcpy(&c_tx->pkt.ctrl,
1518c2ecf20Sopenharmony_ci			       &iwarp_pktinfo[RDMAP_SEND_SE].ctrl,
1528c2ecf20Sopenharmony_ci			       sizeof(struct iwarp_ctrl));
1538c2ecf20Sopenharmony_ci		else
1548c2ecf20Sopenharmony_ci			memcpy(&c_tx->pkt.ctrl, &iwarp_pktinfo[RDMAP_SEND].ctrl,
1558c2ecf20Sopenharmony_ci			       sizeof(struct iwarp_ctrl));
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci		c_tx->pkt.send.ddp_qn = RDMAP_UNTAGGED_QN_SEND;
1588c2ecf20Sopenharmony_ci		c_tx->pkt.send.ddp_msn =
1598c2ecf20Sopenharmony_ci			htonl(++c_tx->ddp_msn[RDMAP_UNTAGGED_QN_SEND]);
1608c2ecf20Sopenharmony_ci		c_tx->pkt.send.ddp_mo = 0;
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci		c_tx->pkt.send_inv.inval_stag = 0;
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci		c_tx->ctrl_len = sizeof(struct iwarp_send);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci		crc = (char *)&c_tx->pkt.send_pkt.crc;
1678c2ecf20Sopenharmony_ci		data = siw_try_1seg(c_tx, crc);
1688c2ecf20Sopenharmony_ci		break;
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	case SIW_OP_SEND_REMOTE_INV:
1718c2ecf20Sopenharmony_ci		if (tx_flags(wqe) & SIW_WQE_SOLICITED)
1728c2ecf20Sopenharmony_ci			memcpy(&c_tx->pkt.ctrl,
1738c2ecf20Sopenharmony_ci			       &iwarp_pktinfo[RDMAP_SEND_SE_INVAL].ctrl,
1748c2ecf20Sopenharmony_ci			       sizeof(struct iwarp_ctrl));
1758c2ecf20Sopenharmony_ci		else
1768c2ecf20Sopenharmony_ci			memcpy(&c_tx->pkt.ctrl,
1778c2ecf20Sopenharmony_ci			       &iwarp_pktinfo[RDMAP_SEND_INVAL].ctrl,
1788c2ecf20Sopenharmony_ci			       sizeof(struct iwarp_ctrl));
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci		c_tx->pkt.send.ddp_qn = RDMAP_UNTAGGED_QN_SEND;
1818c2ecf20Sopenharmony_ci		c_tx->pkt.send.ddp_msn =
1828c2ecf20Sopenharmony_ci			htonl(++c_tx->ddp_msn[RDMAP_UNTAGGED_QN_SEND]);
1838c2ecf20Sopenharmony_ci		c_tx->pkt.send.ddp_mo = 0;
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci		c_tx->pkt.send_inv.inval_stag = cpu_to_be32(wqe->sqe.rkey);
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci		c_tx->ctrl_len = sizeof(struct iwarp_send_inv);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci		crc = (char *)&c_tx->pkt.send_pkt.crc;
1908c2ecf20Sopenharmony_ci		data = siw_try_1seg(c_tx, crc);
1918c2ecf20Sopenharmony_ci		break;
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	case SIW_OP_WRITE:
1948c2ecf20Sopenharmony_ci		memcpy(&c_tx->pkt.ctrl, &iwarp_pktinfo[RDMAP_RDMA_WRITE].ctrl,
1958c2ecf20Sopenharmony_ci		       sizeof(struct iwarp_ctrl));
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci		c_tx->pkt.rwrite.sink_stag = htonl(wqe->sqe.rkey);
1988c2ecf20Sopenharmony_ci		c_tx->pkt.rwrite.sink_to = cpu_to_be64(wqe->sqe.raddr);
1998c2ecf20Sopenharmony_ci		c_tx->ctrl_len = sizeof(struct iwarp_rdma_write);
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci		crc = (char *)&c_tx->pkt.write_pkt.crc;
2028c2ecf20Sopenharmony_ci		data = siw_try_1seg(c_tx, crc);
2038c2ecf20Sopenharmony_ci		break;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	case SIW_OP_READ_RESPONSE:
2068c2ecf20Sopenharmony_ci		memcpy(&c_tx->pkt.ctrl,
2078c2ecf20Sopenharmony_ci		       &iwarp_pktinfo[RDMAP_RDMA_READ_RESP].ctrl,
2088c2ecf20Sopenharmony_ci		       sizeof(struct iwarp_ctrl));
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci		/* NBO */
2118c2ecf20Sopenharmony_ci		c_tx->pkt.rresp.sink_stag = cpu_to_be32(wqe->sqe.rkey);
2128c2ecf20Sopenharmony_ci		c_tx->pkt.rresp.sink_to = cpu_to_be64(wqe->sqe.raddr);
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci		c_tx->ctrl_len = sizeof(struct iwarp_rdma_rresp);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci		crc = (char *)&c_tx->pkt.write_pkt.crc;
2178c2ecf20Sopenharmony_ci		data = siw_try_1seg(c_tx, crc);
2188c2ecf20Sopenharmony_ci		break;
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	default:
2218c2ecf20Sopenharmony_ci		siw_dbg_qp(tx_qp(c_tx), "stale wqe type %d\n", tx_type(wqe));
2228c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
2238c2ecf20Sopenharmony_ci	}
2248c2ecf20Sopenharmony_ci	if (unlikely(data < 0))
2258c2ecf20Sopenharmony_ci		return data;
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	c_tx->ctrl_sent = 0;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	if (data <= MAX_HDR_INLINE) {
2308c2ecf20Sopenharmony_ci		if (data) {
2318c2ecf20Sopenharmony_ci			wqe->processed = data;
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci			c_tx->pkt.ctrl.mpa_len =
2348c2ecf20Sopenharmony_ci				htons(c_tx->ctrl_len + data - MPA_HDR_SIZE);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci			/* Add pad, if needed */
2378c2ecf20Sopenharmony_ci			data += -(int)data & 0x3;
2388c2ecf20Sopenharmony_ci			/* advance CRC location after payload */
2398c2ecf20Sopenharmony_ci			crc += data;
2408c2ecf20Sopenharmony_ci			c_tx->ctrl_len += data;
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci			if (!(c_tx->pkt.ctrl.ddp_rdmap_ctrl & DDP_FLAG_TAGGED))
2438c2ecf20Sopenharmony_ci				c_tx->pkt.c_untagged.ddp_mo = 0;
2448c2ecf20Sopenharmony_ci			else
2458c2ecf20Sopenharmony_ci				c_tx->pkt.c_tagged.ddp_to =
2468c2ecf20Sopenharmony_ci					cpu_to_be64(wqe->sqe.raddr);
2478c2ecf20Sopenharmony_ci		}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci		*(u32 *)crc = 0;
2508c2ecf20Sopenharmony_ci		/*
2518c2ecf20Sopenharmony_ci		 * Do complete CRC if enabled and short packet
2528c2ecf20Sopenharmony_ci		 */
2538c2ecf20Sopenharmony_ci		if (c_tx->mpa_crc_hd) {
2548c2ecf20Sopenharmony_ci			crypto_shash_init(c_tx->mpa_crc_hd);
2558c2ecf20Sopenharmony_ci			if (crypto_shash_update(c_tx->mpa_crc_hd,
2568c2ecf20Sopenharmony_ci						(u8 *)&c_tx->pkt,
2578c2ecf20Sopenharmony_ci						c_tx->ctrl_len))
2588c2ecf20Sopenharmony_ci				return -EINVAL;
2598c2ecf20Sopenharmony_ci			crypto_shash_final(c_tx->mpa_crc_hd, (u8 *)crc);
2608c2ecf20Sopenharmony_ci		}
2618c2ecf20Sopenharmony_ci		c_tx->ctrl_len += MPA_CRC_SIZE;
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci		return PKT_COMPLETE;
2648c2ecf20Sopenharmony_ci	}
2658c2ecf20Sopenharmony_ci	c_tx->ctrl_len += MPA_CRC_SIZE;
2668c2ecf20Sopenharmony_ci	c_tx->sge_idx = 0;
2678c2ecf20Sopenharmony_ci	c_tx->sge_off = 0;
2688c2ecf20Sopenharmony_ci	c_tx->pbl_idx = 0;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	/*
2718c2ecf20Sopenharmony_ci	 * Allow direct sending out of user buffer if WR is non signalled
2728c2ecf20Sopenharmony_ci	 * and payload is over threshold.
2738c2ecf20Sopenharmony_ci	 * Per RDMA verbs, the application should not change the send buffer
2748c2ecf20Sopenharmony_ci	 * until the work completed. In iWarp, work completion is only
2758c2ecf20Sopenharmony_ci	 * local delivery to TCP. TCP may reuse the buffer for
2768c2ecf20Sopenharmony_ci	 * retransmission. Changing unsent data also breaks the CRC,
2778c2ecf20Sopenharmony_ci	 * if applied.
2788c2ecf20Sopenharmony_ci	 */
2798c2ecf20Sopenharmony_ci	if (c_tx->zcopy_tx && wqe->bytes >= SENDPAGE_THRESH &&
2808c2ecf20Sopenharmony_ci	    !(tx_flags(wqe) & SIW_WQE_SIGNALLED))
2818c2ecf20Sopenharmony_ci		c_tx->use_sendpage = 1;
2828c2ecf20Sopenharmony_ci	else
2838c2ecf20Sopenharmony_ci		c_tx->use_sendpage = 0;
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	return PKT_FRAGMENTED;
2868c2ecf20Sopenharmony_ci}
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci/*
2898c2ecf20Sopenharmony_ci * Send out one complete control type FPDU, or header of FPDU carrying
2908c2ecf20Sopenharmony_ci * data. Used for fixed sized packets like Read.Requests or zero length
2918c2ecf20Sopenharmony_ci * SENDs, WRITEs, READ.Responses, or header only.
2928c2ecf20Sopenharmony_ci */
2938c2ecf20Sopenharmony_cistatic int siw_tx_ctrl(struct siw_iwarp_tx *c_tx, struct socket *s,
2948c2ecf20Sopenharmony_ci			      int flags)
2958c2ecf20Sopenharmony_ci{
2968c2ecf20Sopenharmony_ci	struct msghdr msg = { .msg_flags = flags };
2978c2ecf20Sopenharmony_ci	struct kvec iov = { .iov_base =
2988c2ecf20Sopenharmony_ci				    (char *)&c_tx->pkt.ctrl + c_tx->ctrl_sent,
2998c2ecf20Sopenharmony_ci			    .iov_len = c_tx->ctrl_len - c_tx->ctrl_sent };
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	int rv = kernel_sendmsg(s, &msg, &iov, 1,
3028c2ecf20Sopenharmony_ci				c_tx->ctrl_len - c_tx->ctrl_sent);
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	if (rv >= 0) {
3058c2ecf20Sopenharmony_ci		c_tx->ctrl_sent += rv;
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci		if (c_tx->ctrl_sent == c_tx->ctrl_len)
3088c2ecf20Sopenharmony_ci			rv = 0;
3098c2ecf20Sopenharmony_ci		else
3108c2ecf20Sopenharmony_ci			rv = -EAGAIN;
3118c2ecf20Sopenharmony_ci	}
3128c2ecf20Sopenharmony_ci	return rv;
3138c2ecf20Sopenharmony_ci}
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci/*
3168c2ecf20Sopenharmony_ci * 0copy TCP transmit interface: Use do_tcp_sendpages.
3178c2ecf20Sopenharmony_ci *
3188c2ecf20Sopenharmony_ci * Using sendpage to push page by page appears to be less efficient
3198c2ecf20Sopenharmony_ci * than using sendmsg, even if data are copied.
3208c2ecf20Sopenharmony_ci *
3218c2ecf20Sopenharmony_ci * A general performance limitation might be the extra four bytes
3228c2ecf20Sopenharmony_ci * trailer checksum segment to be pushed after user data.
3238c2ecf20Sopenharmony_ci */
3248c2ecf20Sopenharmony_cistatic int siw_tcp_sendpages(struct socket *s, struct page **page, int offset,
3258c2ecf20Sopenharmony_ci			     size_t size)
3268c2ecf20Sopenharmony_ci{
3278c2ecf20Sopenharmony_ci	struct sock *sk = s->sk;
3288c2ecf20Sopenharmony_ci	int i = 0, rv = 0, sent = 0,
3298c2ecf20Sopenharmony_ci	    flags = MSG_MORE | MSG_DONTWAIT | MSG_SENDPAGE_NOTLAST;
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci	while (size) {
3328c2ecf20Sopenharmony_ci		size_t bytes = min_t(size_t, PAGE_SIZE - offset, size);
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci		if (size + offset <= PAGE_SIZE)
3358c2ecf20Sopenharmony_ci			flags = MSG_MORE | MSG_DONTWAIT;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci		tcp_rate_check_app_limited(sk);
3388c2ecf20Sopenharmony_citry_page_again:
3398c2ecf20Sopenharmony_ci		lock_sock(sk);
3408c2ecf20Sopenharmony_ci		rv = do_tcp_sendpages(sk, page[i], offset, bytes, flags);
3418c2ecf20Sopenharmony_ci		release_sock(sk);
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci		if (rv > 0) {
3448c2ecf20Sopenharmony_ci			size -= rv;
3458c2ecf20Sopenharmony_ci			sent += rv;
3468c2ecf20Sopenharmony_ci			if (rv != bytes) {
3478c2ecf20Sopenharmony_ci				offset += rv;
3488c2ecf20Sopenharmony_ci				bytes -= rv;
3498c2ecf20Sopenharmony_ci				goto try_page_again;
3508c2ecf20Sopenharmony_ci			}
3518c2ecf20Sopenharmony_ci			offset = 0;
3528c2ecf20Sopenharmony_ci		} else {
3538c2ecf20Sopenharmony_ci			if (rv == -EAGAIN || rv == 0)
3548c2ecf20Sopenharmony_ci				break;
3558c2ecf20Sopenharmony_ci			return rv;
3568c2ecf20Sopenharmony_ci		}
3578c2ecf20Sopenharmony_ci		i++;
3588c2ecf20Sopenharmony_ci	}
3598c2ecf20Sopenharmony_ci	return sent;
3608c2ecf20Sopenharmony_ci}
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci/*
3638c2ecf20Sopenharmony_ci * siw_0copy_tx()
3648c2ecf20Sopenharmony_ci *
3658c2ecf20Sopenharmony_ci * Pushes list of pages to TCP socket. If pages from multiple
3668c2ecf20Sopenharmony_ci * SGE's, all referenced pages of each SGE are pushed in one
3678c2ecf20Sopenharmony_ci * shot.
3688c2ecf20Sopenharmony_ci */
3698c2ecf20Sopenharmony_cistatic int siw_0copy_tx(struct socket *s, struct page **page,
3708c2ecf20Sopenharmony_ci			struct siw_sge *sge, unsigned int offset,
3718c2ecf20Sopenharmony_ci			unsigned int size)
3728c2ecf20Sopenharmony_ci{
3738c2ecf20Sopenharmony_ci	int i = 0, sent = 0, rv;
3748c2ecf20Sopenharmony_ci	int sge_bytes = min(sge->length - offset, size);
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	offset = (sge->laddr + offset) & ~PAGE_MASK;
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci	while (sent != size) {
3798c2ecf20Sopenharmony_ci		rv = siw_tcp_sendpages(s, &page[i], offset, sge_bytes);
3808c2ecf20Sopenharmony_ci		if (rv >= 0) {
3818c2ecf20Sopenharmony_ci			sent += rv;
3828c2ecf20Sopenharmony_ci			if (size == sent || sge_bytes > rv)
3838c2ecf20Sopenharmony_ci				break;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci			i += PAGE_ALIGN(sge_bytes + offset) >> PAGE_SHIFT;
3868c2ecf20Sopenharmony_ci			sge++;
3878c2ecf20Sopenharmony_ci			sge_bytes = min(sge->length, size - sent);
3888c2ecf20Sopenharmony_ci			offset = sge->laddr & ~PAGE_MASK;
3898c2ecf20Sopenharmony_ci		} else {
3908c2ecf20Sopenharmony_ci			sent = rv;
3918c2ecf20Sopenharmony_ci			break;
3928c2ecf20Sopenharmony_ci		}
3938c2ecf20Sopenharmony_ci	}
3948c2ecf20Sopenharmony_ci	return sent;
3958c2ecf20Sopenharmony_ci}
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci#define MAX_TRAILER (MPA_CRC_SIZE + 4)
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_cistatic void siw_unmap_pages(struct page **pp, unsigned long kmap_mask)
4008c2ecf20Sopenharmony_ci{
4018c2ecf20Sopenharmony_ci	while (kmap_mask) {
4028c2ecf20Sopenharmony_ci		if (kmap_mask & BIT(0))
4038c2ecf20Sopenharmony_ci			kunmap(*pp);
4048c2ecf20Sopenharmony_ci		pp++;
4058c2ecf20Sopenharmony_ci		kmap_mask >>= 1;
4068c2ecf20Sopenharmony_ci	}
4078c2ecf20Sopenharmony_ci}
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci/*
4108c2ecf20Sopenharmony_ci * siw_tx_hdt() tries to push a complete packet to TCP where all
4118c2ecf20Sopenharmony_ci * packet fragments are referenced by the elements of one iovec.
4128c2ecf20Sopenharmony_ci * For the data portion, each involved page must be referenced by
4138c2ecf20Sopenharmony_ci * one extra element. All sge's data can be non-aligned to page
4148c2ecf20Sopenharmony_ci * boundaries. Two more elements are referencing iWARP header
4158c2ecf20Sopenharmony_ci * and trailer:
4168c2ecf20Sopenharmony_ci * MAX_ARRAY = 64KB/PAGE_SIZE + 1 + (2 * (SIW_MAX_SGE - 1) + HDR + TRL
4178c2ecf20Sopenharmony_ci */
4188c2ecf20Sopenharmony_ci#define MAX_ARRAY ((0xffff / PAGE_SIZE) + 1 + (2 * (SIW_MAX_SGE - 1) + 2))
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci/*
4218c2ecf20Sopenharmony_ci * Write out iov referencing hdr, data and trailer of current FPDU.
4228c2ecf20Sopenharmony_ci * Update transmit state dependent on write return status
4238c2ecf20Sopenharmony_ci */
4248c2ecf20Sopenharmony_cistatic int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s)
4258c2ecf20Sopenharmony_ci{
4268c2ecf20Sopenharmony_ci	struct siw_wqe *wqe = &c_tx->wqe_active;
4278c2ecf20Sopenharmony_ci	struct siw_sge *sge = &wqe->sqe.sge[c_tx->sge_idx];
4288c2ecf20Sopenharmony_ci	struct kvec iov[MAX_ARRAY];
4298c2ecf20Sopenharmony_ci	struct page *page_array[MAX_ARRAY];
4308c2ecf20Sopenharmony_ci	struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_EOR };
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci	int seg = 0, do_crc = c_tx->do_crc, is_kva = 0, rv;
4338c2ecf20Sopenharmony_ci	unsigned int data_len = c_tx->bytes_unsent, hdr_len = 0, trl_len = 0,
4348c2ecf20Sopenharmony_ci		     sge_off = c_tx->sge_off, sge_idx = c_tx->sge_idx,
4358c2ecf20Sopenharmony_ci		     pbl_idx = c_tx->pbl_idx;
4368c2ecf20Sopenharmony_ci	unsigned long kmap_mask = 0L;
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci	if (c_tx->state == SIW_SEND_HDR) {
4398c2ecf20Sopenharmony_ci		if (c_tx->use_sendpage) {
4408c2ecf20Sopenharmony_ci			rv = siw_tx_ctrl(c_tx, s, MSG_DONTWAIT | MSG_MORE);
4418c2ecf20Sopenharmony_ci			if (rv)
4428c2ecf20Sopenharmony_ci				goto done;
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci			c_tx->state = SIW_SEND_DATA;
4458c2ecf20Sopenharmony_ci		} else {
4468c2ecf20Sopenharmony_ci			iov[0].iov_base =
4478c2ecf20Sopenharmony_ci				(char *)&c_tx->pkt.ctrl + c_tx->ctrl_sent;
4488c2ecf20Sopenharmony_ci			iov[0].iov_len = hdr_len =
4498c2ecf20Sopenharmony_ci				c_tx->ctrl_len - c_tx->ctrl_sent;
4508c2ecf20Sopenharmony_ci			seg = 1;
4518c2ecf20Sopenharmony_ci		}
4528c2ecf20Sopenharmony_ci	}
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci	wqe->processed += data_len;
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	while (data_len) { /* walk the list of SGE's */
4578c2ecf20Sopenharmony_ci		unsigned int sge_len = min(sge->length - sge_off, data_len);
4588c2ecf20Sopenharmony_ci		unsigned int fp_off = (sge->laddr + sge_off) & ~PAGE_MASK;
4598c2ecf20Sopenharmony_ci		struct siw_mem *mem;
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci		if (!(tx_flags(wqe) & SIW_WQE_INLINE)) {
4628c2ecf20Sopenharmony_ci			mem = wqe->mem[sge_idx];
4638c2ecf20Sopenharmony_ci			is_kva = mem->mem_obj == NULL ? 1 : 0;
4648c2ecf20Sopenharmony_ci		} else {
4658c2ecf20Sopenharmony_ci			is_kva = 1;
4668c2ecf20Sopenharmony_ci		}
4678c2ecf20Sopenharmony_ci		if (is_kva && !c_tx->use_sendpage) {
4688c2ecf20Sopenharmony_ci			/*
4698c2ecf20Sopenharmony_ci			 * tx from kernel virtual address: either inline data
4708c2ecf20Sopenharmony_ci			 * or memory region with assigned kernel buffer
4718c2ecf20Sopenharmony_ci			 */
4728c2ecf20Sopenharmony_ci			iov[seg].iov_base =
4738c2ecf20Sopenharmony_ci				(void *)(uintptr_t)(sge->laddr + sge_off);
4748c2ecf20Sopenharmony_ci			iov[seg].iov_len = sge_len;
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci			if (do_crc)
4778c2ecf20Sopenharmony_ci				crypto_shash_update(c_tx->mpa_crc_hd,
4788c2ecf20Sopenharmony_ci						    iov[seg].iov_base,
4798c2ecf20Sopenharmony_ci						    sge_len);
4808c2ecf20Sopenharmony_ci			sge_off += sge_len;
4818c2ecf20Sopenharmony_ci			data_len -= sge_len;
4828c2ecf20Sopenharmony_ci			seg++;
4838c2ecf20Sopenharmony_ci			goto sge_done;
4848c2ecf20Sopenharmony_ci		}
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci		while (sge_len) {
4878c2ecf20Sopenharmony_ci			size_t plen = min((int)PAGE_SIZE - fp_off, sge_len);
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci			if (!is_kva) {
4908c2ecf20Sopenharmony_ci				struct page *p;
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci				if (mem->is_pbl)
4938c2ecf20Sopenharmony_ci					p = siw_get_pblpage(
4948c2ecf20Sopenharmony_ci						mem, sge->laddr + sge_off,
4958c2ecf20Sopenharmony_ci						&pbl_idx);
4968c2ecf20Sopenharmony_ci				else
4978c2ecf20Sopenharmony_ci					p = siw_get_upage(mem->umem,
4988c2ecf20Sopenharmony_ci							  sge->laddr + sge_off);
4998c2ecf20Sopenharmony_ci				if (unlikely(!p)) {
5008c2ecf20Sopenharmony_ci					siw_unmap_pages(page_array, kmap_mask);
5018c2ecf20Sopenharmony_ci					wqe->processed -= c_tx->bytes_unsent;
5028c2ecf20Sopenharmony_ci					rv = -EFAULT;
5038c2ecf20Sopenharmony_ci					goto done_crc;
5048c2ecf20Sopenharmony_ci				}
5058c2ecf20Sopenharmony_ci				page_array[seg] = p;
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci				if (!c_tx->use_sendpage) {
5088c2ecf20Sopenharmony_ci					iov[seg].iov_base = kmap(p) + fp_off;
5098c2ecf20Sopenharmony_ci					iov[seg].iov_len = plen;
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci					/* Remember for later kunmap() */
5128c2ecf20Sopenharmony_ci					kmap_mask |= BIT(seg);
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci					if (do_crc)
5158c2ecf20Sopenharmony_ci						crypto_shash_update(
5168c2ecf20Sopenharmony_ci							c_tx->mpa_crc_hd,
5178c2ecf20Sopenharmony_ci							iov[seg].iov_base,
5188c2ecf20Sopenharmony_ci							plen);
5198c2ecf20Sopenharmony_ci				} else if (do_crc) {
5208c2ecf20Sopenharmony_ci					crypto_shash_update(c_tx->mpa_crc_hd,
5218c2ecf20Sopenharmony_ci							    kmap(p) + fp_off,
5228c2ecf20Sopenharmony_ci							    plen);
5238c2ecf20Sopenharmony_ci					kunmap(p);
5248c2ecf20Sopenharmony_ci				}
5258c2ecf20Sopenharmony_ci			} else {
5268c2ecf20Sopenharmony_ci				/*
5278c2ecf20Sopenharmony_ci				 * Cast to an uintptr_t to preserve all 64 bits
5288c2ecf20Sopenharmony_ci				 * in sge->laddr.
5298c2ecf20Sopenharmony_ci				 */
5308c2ecf20Sopenharmony_ci				uintptr_t va = (uintptr_t)(sge->laddr + sge_off);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci				/*
5338c2ecf20Sopenharmony_ci				 * virt_to_page() takes a (void *) pointer
5348c2ecf20Sopenharmony_ci				 * so cast to a (void *) meaning it will be 64
5358c2ecf20Sopenharmony_ci				 * bits on a 64 bit platform and 32 bits on a
5368c2ecf20Sopenharmony_ci				 * 32 bit platform.
5378c2ecf20Sopenharmony_ci				 */
5388c2ecf20Sopenharmony_ci				page_array[seg] = virt_to_page((void *)(va & PAGE_MASK));
5398c2ecf20Sopenharmony_ci				if (do_crc)
5408c2ecf20Sopenharmony_ci					crypto_shash_update(
5418c2ecf20Sopenharmony_ci						c_tx->mpa_crc_hd,
5428c2ecf20Sopenharmony_ci						(void *)va,
5438c2ecf20Sopenharmony_ci						plen);
5448c2ecf20Sopenharmony_ci			}
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci			sge_len -= plen;
5478c2ecf20Sopenharmony_ci			sge_off += plen;
5488c2ecf20Sopenharmony_ci			data_len -= plen;
5498c2ecf20Sopenharmony_ci			fp_off = 0;
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_ci			if (++seg >= (int)MAX_ARRAY) {
5528c2ecf20Sopenharmony_ci				siw_dbg_qp(tx_qp(c_tx), "to many fragments\n");
5538c2ecf20Sopenharmony_ci				siw_unmap_pages(page_array, kmap_mask);
5548c2ecf20Sopenharmony_ci				wqe->processed -= c_tx->bytes_unsent;
5558c2ecf20Sopenharmony_ci				rv = -EMSGSIZE;
5568c2ecf20Sopenharmony_ci				goto done_crc;
5578c2ecf20Sopenharmony_ci			}
5588c2ecf20Sopenharmony_ci		}
5598c2ecf20Sopenharmony_cisge_done:
5608c2ecf20Sopenharmony_ci		/* Update SGE variables at end of SGE */
5618c2ecf20Sopenharmony_ci		if (sge_off == sge->length &&
5628c2ecf20Sopenharmony_ci		    (data_len != 0 || wqe->processed < wqe->bytes)) {
5638c2ecf20Sopenharmony_ci			sge_idx++;
5648c2ecf20Sopenharmony_ci			sge++;
5658c2ecf20Sopenharmony_ci			sge_off = 0;
5668c2ecf20Sopenharmony_ci		}
5678c2ecf20Sopenharmony_ci	}
5688c2ecf20Sopenharmony_ci	/* trailer */
5698c2ecf20Sopenharmony_ci	if (likely(c_tx->state != SIW_SEND_TRAILER)) {
5708c2ecf20Sopenharmony_ci		iov[seg].iov_base = &c_tx->trailer.pad[4 - c_tx->pad];
5718c2ecf20Sopenharmony_ci		iov[seg].iov_len = trl_len = MAX_TRAILER - (4 - c_tx->pad);
5728c2ecf20Sopenharmony_ci	} else {
5738c2ecf20Sopenharmony_ci		iov[seg].iov_base = &c_tx->trailer.pad[c_tx->ctrl_sent];
5748c2ecf20Sopenharmony_ci		iov[seg].iov_len = trl_len = MAX_TRAILER - c_tx->ctrl_sent;
5758c2ecf20Sopenharmony_ci	}
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci	if (c_tx->pad) {
5788c2ecf20Sopenharmony_ci		*(u32 *)c_tx->trailer.pad = 0;
5798c2ecf20Sopenharmony_ci		if (do_crc)
5808c2ecf20Sopenharmony_ci			crypto_shash_update(c_tx->mpa_crc_hd,
5818c2ecf20Sopenharmony_ci				(u8 *)&c_tx->trailer.crc - c_tx->pad,
5828c2ecf20Sopenharmony_ci				c_tx->pad);
5838c2ecf20Sopenharmony_ci	}
5848c2ecf20Sopenharmony_ci	if (!c_tx->mpa_crc_hd)
5858c2ecf20Sopenharmony_ci		c_tx->trailer.crc = 0;
5868c2ecf20Sopenharmony_ci	else if (do_crc)
5878c2ecf20Sopenharmony_ci		crypto_shash_final(c_tx->mpa_crc_hd, (u8 *)&c_tx->trailer.crc);
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci	data_len = c_tx->bytes_unsent;
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci	if (c_tx->use_sendpage) {
5928c2ecf20Sopenharmony_ci		rv = siw_0copy_tx(s, page_array, &wqe->sqe.sge[c_tx->sge_idx],
5938c2ecf20Sopenharmony_ci				  c_tx->sge_off, data_len);
5948c2ecf20Sopenharmony_ci		if (rv == data_len) {
5958c2ecf20Sopenharmony_ci			rv = kernel_sendmsg(s, &msg, &iov[seg], 1, trl_len);
5968c2ecf20Sopenharmony_ci			if (rv > 0)
5978c2ecf20Sopenharmony_ci				rv += data_len;
5988c2ecf20Sopenharmony_ci			else
5998c2ecf20Sopenharmony_ci				rv = data_len;
6008c2ecf20Sopenharmony_ci		}
6018c2ecf20Sopenharmony_ci	} else {
6028c2ecf20Sopenharmony_ci		rv = kernel_sendmsg(s, &msg, iov, seg + 1,
6038c2ecf20Sopenharmony_ci				    hdr_len + data_len + trl_len);
6048c2ecf20Sopenharmony_ci		siw_unmap_pages(page_array, kmap_mask);
6058c2ecf20Sopenharmony_ci	}
6068c2ecf20Sopenharmony_ci	if (rv < (int)hdr_len) {
6078c2ecf20Sopenharmony_ci		/* Not even complete hdr pushed or negative rv */
6088c2ecf20Sopenharmony_ci		wqe->processed -= data_len;
6098c2ecf20Sopenharmony_ci		if (rv >= 0) {
6108c2ecf20Sopenharmony_ci			c_tx->ctrl_sent += rv;
6118c2ecf20Sopenharmony_ci			rv = -EAGAIN;
6128c2ecf20Sopenharmony_ci		}
6138c2ecf20Sopenharmony_ci		goto done_crc;
6148c2ecf20Sopenharmony_ci	}
6158c2ecf20Sopenharmony_ci	rv -= hdr_len;
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	if (rv >= (int)data_len) {
6188c2ecf20Sopenharmony_ci		/* all user data pushed to TCP or no data to push */
6198c2ecf20Sopenharmony_ci		if (data_len > 0 && wqe->processed < wqe->bytes) {
6208c2ecf20Sopenharmony_ci			/* Save the current state for next tx */
6218c2ecf20Sopenharmony_ci			c_tx->sge_idx = sge_idx;
6228c2ecf20Sopenharmony_ci			c_tx->sge_off = sge_off;
6238c2ecf20Sopenharmony_ci			c_tx->pbl_idx = pbl_idx;
6248c2ecf20Sopenharmony_ci		}
6258c2ecf20Sopenharmony_ci		rv -= data_len;
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci		if (rv == trl_len) /* all pushed */
6288c2ecf20Sopenharmony_ci			rv = 0;
6298c2ecf20Sopenharmony_ci		else {
6308c2ecf20Sopenharmony_ci			c_tx->state = SIW_SEND_TRAILER;
6318c2ecf20Sopenharmony_ci			c_tx->ctrl_len = MAX_TRAILER;
6328c2ecf20Sopenharmony_ci			c_tx->ctrl_sent = rv + 4 - c_tx->pad;
6338c2ecf20Sopenharmony_ci			c_tx->bytes_unsent = 0;
6348c2ecf20Sopenharmony_ci			rv = -EAGAIN;
6358c2ecf20Sopenharmony_ci		}
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ci	} else if (data_len > 0) {
6388c2ecf20Sopenharmony_ci		/* Maybe some user data pushed to TCP */
6398c2ecf20Sopenharmony_ci		c_tx->state = SIW_SEND_DATA;
6408c2ecf20Sopenharmony_ci		wqe->processed -= data_len - rv;
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci		if (rv) {
6438c2ecf20Sopenharmony_ci			/*
6448c2ecf20Sopenharmony_ci			 * Some bytes out. Recompute tx state based
6458c2ecf20Sopenharmony_ci			 * on old state and bytes pushed
6468c2ecf20Sopenharmony_ci			 */
6478c2ecf20Sopenharmony_ci			unsigned int sge_unsent;
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci			c_tx->bytes_unsent -= rv;
6508c2ecf20Sopenharmony_ci			sge = &wqe->sqe.sge[c_tx->sge_idx];
6518c2ecf20Sopenharmony_ci			sge_unsent = sge->length - c_tx->sge_off;
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci			while (sge_unsent <= rv) {
6548c2ecf20Sopenharmony_ci				rv -= sge_unsent;
6558c2ecf20Sopenharmony_ci				c_tx->sge_idx++;
6568c2ecf20Sopenharmony_ci				c_tx->sge_off = 0;
6578c2ecf20Sopenharmony_ci				sge++;
6588c2ecf20Sopenharmony_ci				sge_unsent = sge->length;
6598c2ecf20Sopenharmony_ci			}
6608c2ecf20Sopenharmony_ci			c_tx->sge_off += rv;
6618c2ecf20Sopenharmony_ci		}
6628c2ecf20Sopenharmony_ci		rv = -EAGAIN;
6638c2ecf20Sopenharmony_ci	}
6648c2ecf20Sopenharmony_cidone_crc:
6658c2ecf20Sopenharmony_ci	c_tx->do_crc = 0;
6668c2ecf20Sopenharmony_cidone:
6678c2ecf20Sopenharmony_ci	return rv;
6688c2ecf20Sopenharmony_ci}
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_cistatic void siw_update_tcpseg(struct siw_iwarp_tx *c_tx,
6718c2ecf20Sopenharmony_ci				     struct socket *s)
6728c2ecf20Sopenharmony_ci{
6738c2ecf20Sopenharmony_ci	struct tcp_sock *tp = tcp_sk(s->sk);
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci	if (tp->gso_segs) {
6768c2ecf20Sopenharmony_ci		if (c_tx->gso_seg_limit == 0)
6778c2ecf20Sopenharmony_ci			c_tx->tcp_seglen = tp->mss_cache * tp->gso_segs;
6788c2ecf20Sopenharmony_ci		else
6798c2ecf20Sopenharmony_ci			c_tx->tcp_seglen =
6808c2ecf20Sopenharmony_ci				tp->mss_cache *
6818c2ecf20Sopenharmony_ci				min_t(u16, c_tx->gso_seg_limit, tp->gso_segs);
6828c2ecf20Sopenharmony_ci	} else {
6838c2ecf20Sopenharmony_ci		c_tx->tcp_seglen = tp->mss_cache;
6848c2ecf20Sopenharmony_ci	}
6858c2ecf20Sopenharmony_ci	/* Loopback may give odd numbers */
6868c2ecf20Sopenharmony_ci	c_tx->tcp_seglen &= 0xfffffff8;
6878c2ecf20Sopenharmony_ci}
6888c2ecf20Sopenharmony_ci
6898c2ecf20Sopenharmony_ci/*
6908c2ecf20Sopenharmony_ci * siw_prepare_fpdu()
6918c2ecf20Sopenharmony_ci *
6928c2ecf20Sopenharmony_ci * Prepares transmit context to send out one FPDU if FPDU will contain
6938c2ecf20Sopenharmony_ci * user data and user data are not immediate data.
6948c2ecf20Sopenharmony_ci * Computes maximum FPDU length to fill up TCP MSS if possible.
6958c2ecf20Sopenharmony_ci *
6968c2ecf20Sopenharmony_ci * @qp:		QP from which to transmit
6978c2ecf20Sopenharmony_ci * @wqe:	Current WQE causing transmission
6988c2ecf20Sopenharmony_ci *
6998c2ecf20Sopenharmony_ci * TODO: Take into account real available sendspace on socket
7008c2ecf20Sopenharmony_ci *       to avoid header misalignment due to send pausing within
7018c2ecf20Sopenharmony_ci *       fpdu transmission
7028c2ecf20Sopenharmony_ci */
7038c2ecf20Sopenharmony_cistatic void siw_prepare_fpdu(struct siw_qp *qp, struct siw_wqe *wqe)
7048c2ecf20Sopenharmony_ci{
7058c2ecf20Sopenharmony_ci	struct siw_iwarp_tx *c_tx = &qp->tx_ctx;
7068c2ecf20Sopenharmony_ci	int data_len;
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	c_tx->ctrl_len =
7098c2ecf20Sopenharmony_ci		iwarp_pktinfo[__rdmap_get_opcode(&c_tx->pkt.ctrl)].hdr_len;
7108c2ecf20Sopenharmony_ci	c_tx->ctrl_sent = 0;
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci	/*
7138c2ecf20Sopenharmony_ci	 * Update target buffer offset if any
7148c2ecf20Sopenharmony_ci	 */
7158c2ecf20Sopenharmony_ci	if (!(c_tx->pkt.ctrl.ddp_rdmap_ctrl & DDP_FLAG_TAGGED))
7168c2ecf20Sopenharmony_ci		/* Untagged message */
7178c2ecf20Sopenharmony_ci		c_tx->pkt.c_untagged.ddp_mo = cpu_to_be32(wqe->processed);
7188c2ecf20Sopenharmony_ci	else /* Tagged message */
7198c2ecf20Sopenharmony_ci		c_tx->pkt.c_tagged.ddp_to =
7208c2ecf20Sopenharmony_ci			cpu_to_be64(wqe->sqe.raddr + wqe->processed);
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci	data_len = wqe->bytes - wqe->processed;
7238c2ecf20Sopenharmony_ci	if (data_len + c_tx->ctrl_len + MPA_CRC_SIZE > c_tx->tcp_seglen) {
7248c2ecf20Sopenharmony_ci		/* Trim DDP payload to fit into current TCP segment */
7258c2ecf20Sopenharmony_ci		data_len = c_tx->tcp_seglen - (c_tx->ctrl_len + MPA_CRC_SIZE);
7268c2ecf20Sopenharmony_ci		c_tx->pkt.ctrl.ddp_rdmap_ctrl &= ~DDP_FLAG_LAST;
7278c2ecf20Sopenharmony_ci		c_tx->pad = 0;
7288c2ecf20Sopenharmony_ci	} else {
7298c2ecf20Sopenharmony_ci		c_tx->pkt.ctrl.ddp_rdmap_ctrl |= DDP_FLAG_LAST;
7308c2ecf20Sopenharmony_ci		c_tx->pad = -data_len & 0x3;
7318c2ecf20Sopenharmony_ci	}
7328c2ecf20Sopenharmony_ci	c_tx->bytes_unsent = data_len;
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci	c_tx->pkt.ctrl.mpa_len =
7358c2ecf20Sopenharmony_ci		htons(c_tx->ctrl_len + data_len - MPA_HDR_SIZE);
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci	/*
7388c2ecf20Sopenharmony_ci	 * Init MPA CRC computation
7398c2ecf20Sopenharmony_ci	 */
7408c2ecf20Sopenharmony_ci	if (c_tx->mpa_crc_hd) {
7418c2ecf20Sopenharmony_ci		crypto_shash_init(c_tx->mpa_crc_hd);
7428c2ecf20Sopenharmony_ci		crypto_shash_update(c_tx->mpa_crc_hd, (u8 *)&c_tx->pkt,
7438c2ecf20Sopenharmony_ci				    c_tx->ctrl_len);
7448c2ecf20Sopenharmony_ci		c_tx->do_crc = 1;
7458c2ecf20Sopenharmony_ci	}
7468c2ecf20Sopenharmony_ci}
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci/*
7498c2ecf20Sopenharmony_ci * siw_check_sgl_tx()
7508c2ecf20Sopenharmony_ci *
7518c2ecf20Sopenharmony_ci * Check permissions for a list of SGE's (SGL).
7528c2ecf20Sopenharmony_ci * A successful check will have all memory referenced
7538c2ecf20Sopenharmony_ci * for transmission resolved and assigned to the WQE.
7548c2ecf20Sopenharmony_ci *
7558c2ecf20Sopenharmony_ci * @pd:		Protection Domain SGL should belong to
7568c2ecf20Sopenharmony_ci * @wqe:	WQE to be checked
7578c2ecf20Sopenharmony_ci * @perms:	requested access permissions
7588c2ecf20Sopenharmony_ci *
7598c2ecf20Sopenharmony_ci */
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_cistatic int siw_check_sgl_tx(struct ib_pd *pd, struct siw_wqe *wqe,
7628c2ecf20Sopenharmony_ci			    enum ib_access_flags perms)
7638c2ecf20Sopenharmony_ci{
7648c2ecf20Sopenharmony_ci	struct siw_sge *sge = &wqe->sqe.sge[0];
7658c2ecf20Sopenharmony_ci	int i, len, num_sge = wqe->sqe.num_sge;
7668c2ecf20Sopenharmony_ci
7678c2ecf20Sopenharmony_ci	if (unlikely(num_sge > SIW_MAX_SGE))
7688c2ecf20Sopenharmony_ci		return -EINVAL;
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci	for (i = 0, len = 0; num_sge; num_sge--, i++, sge++) {
7718c2ecf20Sopenharmony_ci		/*
7728c2ecf20Sopenharmony_ci		 * rdma verbs: do not check stag for a zero length sge
7738c2ecf20Sopenharmony_ci		 */
7748c2ecf20Sopenharmony_ci		if (sge->length) {
7758c2ecf20Sopenharmony_ci			int rv = siw_check_sge(pd, sge, &wqe->mem[i], perms, 0,
7768c2ecf20Sopenharmony_ci					       sge->length);
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci			if (unlikely(rv != E_ACCESS_OK))
7798c2ecf20Sopenharmony_ci				return rv;
7808c2ecf20Sopenharmony_ci		}
7818c2ecf20Sopenharmony_ci		len += sge->length;
7828c2ecf20Sopenharmony_ci	}
7838c2ecf20Sopenharmony_ci	return len;
7848c2ecf20Sopenharmony_ci}
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci/*
7878c2ecf20Sopenharmony_ci * siw_qp_sq_proc_tx()
7888c2ecf20Sopenharmony_ci *
7898c2ecf20Sopenharmony_ci * Process one WQE which needs transmission on the wire.
7908c2ecf20Sopenharmony_ci */
7918c2ecf20Sopenharmony_cistatic int siw_qp_sq_proc_tx(struct siw_qp *qp, struct siw_wqe *wqe)
7928c2ecf20Sopenharmony_ci{
7938c2ecf20Sopenharmony_ci	struct siw_iwarp_tx *c_tx = &qp->tx_ctx;
7948c2ecf20Sopenharmony_ci	struct socket *s = qp->attrs.sk;
7958c2ecf20Sopenharmony_ci	int rv = 0, burst_len = qp->tx_ctx.burst;
7968c2ecf20Sopenharmony_ci	enum rdmap_ecode ecode = RDMAP_ECODE_CATASTROPHIC_STREAM;
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci	if (unlikely(wqe->wr_status == SIW_WR_IDLE))
7998c2ecf20Sopenharmony_ci		return 0;
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_ci	if (!burst_len)
8028c2ecf20Sopenharmony_ci		burst_len = SQ_USER_MAXBURST;
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci	if (wqe->wr_status == SIW_WR_QUEUED) {
8058c2ecf20Sopenharmony_ci		if (!(wqe->sqe.flags & SIW_WQE_INLINE)) {
8068c2ecf20Sopenharmony_ci			if (tx_type(wqe) == SIW_OP_READ_RESPONSE)
8078c2ecf20Sopenharmony_ci				wqe->sqe.num_sge = 1;
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci			if (tx_type(wqe) != SIW_OP_READ &&
8108c2ecf20Sopenharmony_ci			    tx_type(wqe) != SIW_OP_READ_LOCAL_INV) {
8118c2ecf20Sopenharmony_ci				/*
8128c2ecf20Sopenharmony_ci				 * Reference memory to be tx'd w/o checking
8138c2ecf20Sopenharmony_ci				 * access for LOCAL_READ permission, since
8148c2ecf20Sopenharmony_ci				 * not defined in RDMA core.
8158c2ecf20Sopenharmony_ci				 */
8168c2ecf20Sopenharmony_ci				rv = siw_check_sgl_tx(qp->pd, wqe, 0);
8178c2ecf20Sopenharmony_ci				if (rv < 0) {
8188c2ecf20Sopenharmony_ci					if (tx_type(wqe) ==
8198c2ecf20Sopenharmony_ci					    SIW_OP_READ_RESPONSE)
8208c2ecf20Sopenharmony_ci						ecode = siw_rdmap_error(-rv);
8218c2ecf20Sopenharmony_ci					rv = -EINVAL;
8228c2ecf20Sopenharmony_ci					goto tx_error;
8238c2ecf20Sopenharmony_ci				}
8248c2ecf20Sopenharmony_ci				wqe->bytes = rv;
8258c2ecf20Sopenharmony_ci			} else {
8268c2ecf20Sopenharmony_ci				wqe->bytes = 0;
8278c2ecf20Sopenharmony_ci			}
8288c2ecf20Sopenharmony_ci		} else {
8298c2ecf20Sopenharmony_ci			wqe->bytes = wqe->sqe.sge[0].length;
8308c2ecf20Sopenharmony_ci			if (!rdma_is_kernel_res(&qp->base_qp.res)) {
8318c2ecf20Sopenharmony_ci				if (wqe->bytes > SIW_MAX_INLINE) {
8328c2ecf20Sopenharmony_ci					rv = -EINVAL;
8338c2ecf20Sopenharmony_ci					goto tx_error;
8348c2ecf20Sopenharmony_ci				}
8358c2ecf20Sopenharmony_ci				wqe->sqe.sge[0].laddr =
8368c2ecf20Sopenharmony_ci					(u64)(uintptr_t)&wqe->sqe.sge[1];
8378c2ecf20Sopenharmony_ci			}
8388c2ecf20Sopenharmony_ci		}
8398c2ecf20Sopenharmony_ci		wqe->wr_status = SIW_WR_INPROGRESS;
8408c2ecf20Sopenharmony_ci		wqe->processed = 0;
8418c2ecf20Sopenharmony_ci
8428c2ecf20Sopenharmony_ci		siw_update_tcpseg(c_tx, s);
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci		rv = siw_qp_prepare_tx(c_tx);
8458c2ecf20Sopenharmony_ci		if (rv == PKT_FRAGMENTED) {
8468c2ecf20Sopenharmony_ci			c_tx->state = SIW_SEND_HDR;
8478c2ecf20Sopenharmony_ci			siw_prepare_fpdu(qp, wqe);
8488c2ecf20Sopenharmony_ci		} else if (rv == PKT_COMPLETE) {
8498c2ecf20Sopenharmony_ci			c_tx->state = SIW_SEND_SHORT_FPDU;
8508c2ecf20Sopenharmony_ci		} else {
8518c2ecf20Sopenharmony_ci			goto tx_error;
8528c2ecf20Sopenharmony_ci		}
8538c2ecf20Sopenharmony_ci	}
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_cinext_segment:
8568c2ecf20Sopenharmony_ci	siw_dbg_qp(qp, "wr type %d, state %d, data %u, sent %u, id %llx\n",
8578c2ecf20Sopenharmony_ci		   tx_type(wqe), wqe->wr_status, wqe->bytes, wqe->processed,
8588c2ecf20Sopenharmony_ci		   wqe->sqe.id);
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci	if (--burst_len == 0) {
8618c2ecf20Sopenharmony_ci		rv = -EINPROGRESS;
8628c2ecf20Sopenharmony_ci		goto tx_done;
8638c2ecf20Sopenharmony_ci	}
8648c2ecf20Sopenharmony_ci	if (c_tx->state == SIW_SEND_SHORT_FPDU) {
8658c2ecf20Sopenharmony_ci		enum siw_opcode tx_type = tx_type(wqe);
8668c2ecf20Sopenharmony_ci		unsigned int msg_flags;
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_ci		if (siw_sq_empty(qp) || !siw_tcp_nagle || burst_len == 1)
8698c2ecf20Sopenharmony_ci			/*
8708c2ecf20Sopenharmony_ci			 * End current TCP segment, if SQ runs empty,
8718c2ecf20Sopenharmony_ci			 * or siw_tcp_nagle is not set, or we bail out
8728c2ecf20Sopenharmony_ci			 * soon due to no burst credit left.
8738c2ecf20Sopenharmony_ci			 */
8748c2ecf20Sopenharmony_ci			msg_flags = MSG_DONTWAIT;
8758c2ecf20Sopenharmony_ci		else
8768c2ecf20Sopenharmony_ci			msg_flags = MSG_DONTWAIT | MSG_MORE;
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci		rv = siw_tx_ctrl(c_tx, s, msg_flags);
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_ci		if (!rv && tx_type != SIW_OP_READ &&
8818c2ecf20Sopenharmony_ci		    tx_type != SIW_OP_READ_LOCAL_INV)
8828c2ecf20Sopenharmony_ci			wqe->processed = wqe->bytes;
8838c2ecf20Sopenharmony_ci
8848c2ecf20Sopenharmony_ci		goto tx_done;
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_ci	} else {
8878c2ecf20Sopenharmony_ci		rv = siw_tx_hdt(c_tx, s);
8888c2ecf20Sopenharmony_ci	}
8898c2ecf20Sopenharmony_ci	if (!rv) {
8908c2ecf20Sopenharmony_ci		/*
8918c2ecf20Sopenharmony_ci		 * One segment sent. Processing completed if last
8928c2ecf20Sopenharmony_ci		 * segment, Do next segment otherwise.
8938c2ecf20Sopenharmony_ci		 */
8948c2ecf20Sopenharmony_ci		if (unlikely(c_tx->tx_suspend)) {
8958c2ecf20Sopenharmony_ci			/*
8968c2ecf20Sopenharmony_ci			 * Verbs, 6.4.: Try stopping sending after a full
8978c2ecf20Sopenharmony_ci			 * DDP segment if the connection goes down
8988c2ecf20Sopenharmony_ci			 * (== peer halfclose)
8998c2ecf20Sopenharmony_ci			 */
9008c2ecf20Sopenharmony_ci			rv = -ECONNABORTED;
9018c2ecf20Sopenharmony_ci			goto tx_done;
9028c2ecf20Sopenharmony_ci		}
9038c2ecf20Sopenharmony_ci		if (c_tx->pkt.ctrl.ddp_rdmap_ctrl & DDP_FLAG_LAST) {
9048c2ecf20Sopenharmony_ci			siw_dbg_qp(qp, "WQE completed\n");
9058c2ecf20Sopenharmony_ci			goto tx_done;
9068c2ecf20Sopenharmony_ci		}
9078c2ecf20Sopenharmony_ci		c_tx->state = SIW_SEND_HDR;
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci		siw_update_tcpseg(c_tx, s);
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_ci		siw_prepare_fpdu(qp, wqe);
9128c2ecf20Sopenharmony_ci		goto next_segment;
9138c2ecf20Sopenharmony_ci	}
9148c2ecf20Sopenharmony_citx_done:
9158c2ecf20Sopenharmony_ci	qp->tx_ctx.burst = burst_len;
9168c2ecf20Sopenharmony_ci	return rv;
9178c2ecf20Sopenharmony_ci
9188c2ecf20Sopenharmony_citx_error:
9198c2ecf20Sopenharmony_ci	if (ecode != RDMAP_ECODE_CATASTROPHIC_STREAM)
9208c2ecf20Sopenharmony_ci		siw_init_terminate(qp, TERM_ERROR_LAYER_RDMAP,
9218c2ecf20Sopenharmony_ci				   RDMAP_ETYPE_REMOTE_PROTECTION, ecode, 1);
9228c2ecf20Sopenharmony_ci	else
9238c2ecf20Sopenharmony_ci		siw_init_terminate(qp, TERM_ERROR_LAYER_RDMAP,
9248c2ecf20Sopenharmony_ci				   RDMAP_ETYPE_CATASTROPHIC,
9258c2ecf20Sopenharmony_ci				   RDMAP_ECODE_UNSPECIFIED, 1);
9268c2ecf20Sopenharmony_ci	return rv;
9278c2ecf20Sopenharmony_ci}
9288c2ecf20Sopenharmony_ci
9298c2ecf20Sopenharmony_cistatic int siw_fastreg_mr(struct ib_pd *pd, struct siw_sqe *sqe)
9308c2ecf20Sopenharmony_ci{
9318c2ecf20Sopenharmony_ci	struct ib_mr *base_mr = (struct ib_mr *)(uintptr_t)sqe->base_mr;
9328c2ecf20Sopenharmony_ci	struct siw_device *sdev = to_siw_dev(pd->device);
9338c2ecf20Sopenharmony_ci	struct siw_mem *mem;
9348c2ecf20Sopenharmony_ci	int rv = 0;
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ci	siw_dbg_pd(pd, "STag 0x%08x\n", sqe->rkey);
9378c2ecf20Sopenharmony_ci
9388c2ecf20Sopenharmony_ci	if (unlikely(!base_mr)) {
9398c2ecf20Sopenharmony_ci		pr_warn("siw: fastreg: STag 0x%08x unknown\n", sqe->rkey);
9408c2ecf20Sopenharmony_ci		return -EINVAL;
9418c2ecf20Sopenharmony_ci	}
9428c2ecf20Sopenharmony_ci
9438c2ecf20Sopenharmony_ci	if (unlikely(base_mr->rkey >> 8 != sqe->rkey  >> 8)) {
9448c2ecf20Sopenharmony_ci		pr_warn("siw: fastreg: STag 0x%08x: bad MR\n", sqe->rkey);
9458c2ecf20Sopenharmony_ci		return -EINVAL;
9468c2ecf20Sopenharmony_ci	}
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci	mem = siw_mem_id2obj(sdev, sqe->rkey  >> 8);
9498c2ecf20Sopenharmony_ci	if (unlikely(!mem)) {
9508c2ecf20Sopenharmony_ci		pr_warn("siw: fastreg: STag 0x%08x unknown\n", sqe->rkey);
9518c2ecf20Sopenharmony_ci		return -EINVAL;
9528c2ecf20Sopenharmony_ci	}
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_ci	if (unlikely(mem->pd != pd)) {
9558c2ecf20Sopenharmony_ci		pr_warn("siw: fastreg: PD mismatch\n");
9568c2ecf20Sopenharmony_ci		rv = -EINVAL;
9578c2ecf20Sopenharmony_ci		goto out;
9588c2ecf20Sopenharmony_ci	}
9598c2ecf20Sopenharmony_ci	if (unlikely(mem->stag_valid)) {
9608c2ecf20Sopenharmony_ci		pr_warn("siw: fastreg: STag 0x%08x already valid\n", sqe->rkey);
9618c2ecf20Sopenharmony_ci		rv = -EINVAL;
9628c2ecf20Sopenharmony_ci		goto out;
9638c2ecf20Sopenharmony_ci	}
9648c2ecf20Sopenharmony_ci	/* Refresh STag since user may have changed key part */
9658c2ecf20Sopenharmony_ci	mem->stag = sqe->rkey;
9668c2ecf20Sopenharmony_ci	mem->perms = sqe->access;
9678c2ecf20Sopenharmony_ci
9688c2ecf20Sopenharmony_ci	siw_dbg_mem(mem, "STag 0x%08x now valid\n", sqe->rkey);
9698c2ecf20Sopenharmony_ci	mem->va = base_mr->iova;
9708c2ecf20Sopenharmony_ci	mem->stag_valid = 1;
9718c2ecf20Sopenharmony_ciout:
9728c2ecf20Sopenharmony_ci	siw_mem_put(mem);
9738c2ecf20Sopenharmony_ci	return rv;
9748c2ecf20Sopenharmony_ci}
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_cistatic int siw_qp_sq_proc_local(struct siw_qp *qp, struct siw_wqe *wqe)
9778c2ecf20Sopenharmony_ci{
9788c2ecf20Sopenharmony_ci	int rv;
9798c2ecf20Sopenharmony_ci
9808c2ecf20Sopenharmony_ci	switch (tx_type(wqe)) {
9818c2ecf20Sopenharmony_ci	case SIW_OP_REG_MR:
9828c2ecf20Sopenharmony_ci		rv = siw_fastreg_mr(qp->pd, &wqe->sqe);
9838c2ecf20Sopenharmony_ci		break;
9848c2ecf20Sopenharmony_ci
9858c2ecf20Sopenharmony_ci	case SIW_OP_INVAL_STAG:
9868c2ecf20Sopenharmony_ci		rv = siw_invalidate_stag(qp->pd, wqe->sqe.rkey);
9878c2ecf20Sopenharmony_ci		break;
9888c2ecf20Sopenharmony_ci
9898c2ecf20Sopenharmony_ci	default:
9908c2ecf20Sopenharmony_ci		rv = -EINVAL;
9918c2ecf20Sopenharmony_ci	}
9928c2ecf20Sopenharmony_ci	return rv;
9938c2ecf20Sopenharmony_ci}
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci/*
9968c2ecf20Sopenharmony_ci * siw_qp_sq_process()
9978c2ecf20Sopenharmony_ci *
9988c2ecf20Sopenharmony_ci * Core TX path routine for RDMAP/DDP/MPA using a TCP kernel socket.
9998c2ecf20Sopenharmony_ci * Sends RDMAP payload for the current SQ WR @wqe of @qp in one or more
10008c2ecf20Sopenharmony_ci * MPA FPDUs, each containing a DDP segment.
10018c2ecf20Sopenharmony_ci *
10028c2ecf20Sopenharmony_ci * SQ processing may occur in user context as a result of posting
10038c2ecf20Sopenharmony_ci * new WQE's or from siw_sq_work_handler() context. Processing in
10048c2ecf20Sopenharmony_ci * user context is limited to non-kernel verbs users.
10058c2ecf20Sopenharmony_ci *
10068c2ecf20Sopenharmony_ci * SQ processing may get paused anytime, possibly in the middle of a WR
10078c2ecf20Sopenharmony_ci * or FPDU, if insufficient send space is available. SQ processing
10088c2ecf20Sopenharmony_ci * gets resumed from siw_sq_work_handler(), if send space becomes
10098c2ecf20Sopenharmony_ci * available again.
10108c2ecf20Sopenharmony_ci *
10118c2ecf20Sopenharmony_ci * Must be called with the QP state read-locked.
10128c2ecf20Sopenharmony_ci *
10138c2ecf20Sopenharmony_ci * Note:
10148c2ecf20Sopenharmony_ci * An outbound RREQ can be satisfied by the corresponding RRESP
10158c2ecf20Sopenharmony_ci * _before_ it gets assigned to the ORQ. This happens regularly
10168c2ecf20Sopenharmony_ci * in RDMA READ via loopback case. Since both outbound RREQ and
10178c2ecf20Sopenharmony_ci * inbound RRESP can be handled by the same CPU, locking the ORQ
10188c2ecf20Sopenharmony_ci * is dead-lock prone and thus not an option. With that, the
10198c2ecf20Sopenharmony_ci * RREQ gets assigned to the ORQ _before_ being sent - see
10208c2ecf20Sopenharmony_ci * siw_activate_tx() - and pulled back in case of send failure.
10218c2ecf20Sopenharmony_ci */
10228c2ecf20Sopenharmony_ciint siw_qp_sq_process(struct siw_qp *qp)
10238c2ecf20Sopenharmony_ci{
10248c2ecf20Sopenharmony_ci	struct siw_wqe *wqe = tx_wqe(qp);
10258c2ecf20Sopenharmony_ci	enum siw_opcode tx_type;
10268c2ecf20Sopenharmony_ci	unsigned long flags;
10278c2ecf20Sopenharmony_ci	int rv = 0;
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_ci	siw_dbg_qp(qp, "enter for type %d\n", tx_type(wqe));
10308c2ecf20Sopenharmony_ci
10318c2ecf20Sopenharmony_cinext_wqe:
10328c2ecf20Sopenharmony_ci	/*
10338c2ecf20Sopenharmony_ci	 * Stop QP processing if SQ state changed
10348c2ecf20Sopenharmony_ci	 */
10358c2ecf20Sopenharmony_ci	if (unlikely(qp->tx_ctx.tx_suspend)) {
10368c2ecf20Sopenharmony_ci		siw_dbg_qp(qp, "tx suspended\n");
10378c2ecf20Sopenharmony_ci		goto done;
10388c2ecf20Sopenharmony_ci	}
10398c2ecf20Sopenharmony_ci	tx_type = tx_type(wqe);
10408c2ecf20Sopenharmony_ci
10418c2ecf20Sopenharmony_ci	if (tx_type <= SIW_OP_READ_RESPONSE)
10428c2ecf20Sopenharmony_ci		rv = siw_qp_sq_proc_tx(qp, wqe);
10438c2ecf20Sopenharmony_ci	else
10448c2ecf20Sopenharmony_ci		rv = siw_qp_sq_proc_local(qp, wqe);
10458c2ecf20Sopenharmony_ci
10468c2ecf20Sopenharmony_ci	if (!rv) {
10478c2ecf20Sopenharmony_ci		/*
10488c2ecf20Sopenharmony_ci		 * WQE processing done
10498c2ecf20Sopenharmony_ci		 */
10508c2ecf20Sopenharmony_ci		switch (tx_type) {
10518c2ecf20Sopenharmony_ci		case SIW_OP_SEND:
10528c2ecf20Sopenharmony_ci		case SIW_OP_SEND_REMOTE_INV:
10538c2ecf20Sopenharmony_ci		case SIW_OP_WRITE:
10548c2ecf20Sopenharmony_ci			siw_wqe_put_mem(wqe, tx_type);
10558c2ecf20Sopenharmony_ci			fallthrough;
10568c2ecf20Sopenharmony_ci
10578c2ecf20Sopenharmony_ci		case SIW_OP_INVAL_STAG:
10588c2ecf20Sopenharmony_ci		case SIW_OP_REG_MR:
10598c2ecf20Sopenharmony_ci			if (tx_flags(wqe) & SIW_WQE_SIGNALLED)
10608c2ecf20Sopenharmony_ci				siw_sqe_complete(qp, &wqe->sqe, wqe->bytes,
10618c2ecf20Sopenharmony_ci						 SIW_WC_SUCCESS);
10628c2ecf20Sopenharmony_ci			break;
10638c2ecf20Sopenharmony_ci
10648c2ecf20Sopenharmony_ci		case SIW_OP_READ:
10658c2ecf20Sopenharmony_ci		case SIW_OP_READ_LOCAL_INV:
10668c2ecf20Sopenharmony_ci			/*
10678c2ecf20Sopenharmony_ci			 * already enqueued to ORQ queue
10688c2ecf20Sopenharmony_ci			 */
10698c2ecf20Sopenharmony_ci			break;
10708c2ecf20Sopenharmony_ci
10718c2ecf20Sopenharmony_ci		case SIW_OP_READ_RESPONSE:
10728c2ecf20Sopenharmony_ci			siw_wqe_put_mem(wqe, tx_type);
10738c2ecf20Sopenharmony_ci			break;
10748c2ecf20Sopenharmony_ci
10758c2ecf20Sopenharmony_ci		default:
10768c2ecf20Sopenharmony_ci			WARN(1, "undefined WQE type %d\n", tx_type);
10778c2ecf20Sopenharmony_ci			rv = -EINVAL;
10788c2ecf20Sopenharmony_ci			goto done;
10798c2ecf20Sopenharmony_ci		}
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci		spin_lock_irqsave(&qp->sq_lock, flags);
10828c2ecf20Sopenharmony_ci		wqe->wr_status = SIW_WR_IDLE;
10838c2ecf20Sopenharmony_ci		rv = siw_activate_tx(qp);
10848c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&qp->sq_lock, flags);
10858c2ecf20Sopenharmony_ci
10868c2ecf20Sopenharmony_ci		if (rv <= 0)
10878c2ecf20Sopenharmony_ci			goto done;
10888c2ecf20Sopenharmony_ci
10898c2ecf20Sopenharmony_ci		goto next_wqe;
10908c2ecf20Sopenharmony_ci
10918c2ecf20Sopenharmony_ci	} else if (rv == -EAGAIN) {
10928c2ecf20Sopenharmony_ci		siw_dbg_qp(qp, "sq paused: hd/tr %d of %d, data %d\n",
10938c2ecf20Sopenharmony_ci			   qp->tx_ctx.ctrl_sent, qp->tx_ctx.ctrl_len,
10948c2ecf20Sopenharmony_ci			   qp->tx_ctx.bytes_unsent);
10958c2ecf20Sopenharmony_ci		rv = 0;
10968c2ecf20Sopenharmony_ci		goto done;
10978c2ecf20Sopenharmony_ci	} else if (rv == -EINPROGRESS) {
10988c2ecf20Sopenharmony_ci		rv = siw_sq_start(qp);
10998c2ecf20Sopenharmony_ci		goto done;
11008c2ecf20Sopenharmony_ci	} else {
11018c2ecf20Sopenharmony_ci		/*
11028c2ecf20Sopenharmony_ci		 * WQE processing failed.
11038c2ecf20Sopenharmony_ci		 * Verbs 8.3.2:
11048c2ecf20Sopenharmony_ci		 * o It turns any WQE into a signalled WQE.
11058c2ecf20Sopenharmony_ci		 * o Local catastrophic error must be surfaced
11068c2ecf20Sopenharmony_ci		 * o QP must be moved into Terminate state: done by code
11078c2ecf20Sopenharmony_ci		 *   doing socket state change processing
11088c2ecf20Sopenharmony_ci		 *
11098c2ecf20Sopenharmony_ci		 * o TODO: Termination message must be sent.
11108c2ecf20Sopenharmony_ci		 * o TODO: Implement more precise work completion errors,
11118c2ecf20Sopenharmony_ci		 *         see enum ib_wc_status in ib_verbs.h
11128c2ecf20Sopenharmony_ci		 */
11138c2ecf20Sopenharmony_ci		siw_dbg_qp(qp, "wqe type %d processing failed: %d\n",
11148c2ecf20Sopenharmony_ci			   tx_type(wqe), rv);
11158c2ecf20Sopenharmony_ci
11168c2ecf20Sopenharmony_ci		spin_lock_irqsave(&qp->sq_lock, flags);
11178c2ecf20Sopenharmony_ci		/*
11188c2ecf20Sopenharmony_ci		 * RREQ may have already been completed by inbound RRESP!
11198c2ecf20Sopenharmony_ci		 */
11208c2ecf20Sopenharmony_ci		if ((tx_type == SIW_OP_READ ||
11218c2ecf20Sopenharmony_ci		     tx_type == SIW_OP_READ_LOCAL_INV) && qp->attrs.orq_size) {
11228c2ecf20Sopenharmony_ci			/* Cleanup pending entry in ORQ */
11238c2ecf20Sopenharmony_ci			qp->orq_put--;
11248c2ecf20Sopenharmony_ci			qp->orq[qp->orq_put % qp->attrs.orq_size].flags = 0;
11258c2ecf20Sopenharmony_ci		}
11268c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&qp->sq_lock, flags);
11278c2ecf20Sopenharmony_ci		/*
11288c2ecf20Sopenharmony_ci		 * immediately suspends further TX processing
11298c2ecf20Sopenharmony_ci		 */
11308c2ecf20Sopenharmony_ci		if (!qp->tx_ctx.tx_suspend)
11318c2ecf20Sopenharmony_ci			siw_qp_cm_drop(qp, 0);
11328c2ecf20Sopenharmony_ci
11338c2ecf20Sopenharmony_ci		switch (tx_type) {
11348c2ecf20Sopenharmony_ci		case SIW_OP_SEND:
11358c2ecf20Sopenharmony_ci		case SIW_OP_SEND_REMOTE_INV:
11368c2ecf20Sopenharmony_ci		case SIW_OP_SEND_WITH_IMM:
11378c2ecf20Sopenharmony_ci		case SIW_OP_WRITE:
11388c2ecf20Sopenharmony_ci		case SIW_OP_READ:
11398c2ecf20Sopenharmony_ci		case SIW_OP_READ_LOCAL_INV:
11408c2ecf20Sopenharmony_ci			siw_wqe_put_mem(wqe, tx_type);
11418c2ecf20Sopenharmony_ci			fallthrough;
11428c2ecf20Sopenharmony_ci
11438c2ecf20Sopenharmony_ci		case SIW_OP_INVAL_STAG:
11448c2ecf20Sopenharmony_ci		case SIW_OP_REG_MR:
11458c2ecf20Sopenharmony_ci			siw_sqe_complete(qp, &wqe->sqe, wqe->bytes,
11468c2ecf20Sopenharmony_ci					 SIW_WC_LOC_QP_OP_ERR);
11478c2ecf20Sopenharmony_ci
11488c2ecf20Sopenharmony_ci			siw_qp_event(qp, IB_EVENT_QP_FATAL);
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_ci			break;
11518c2ecf20Sopenharmony_ci
11528c2ecf20Sopenharmony_ci		case SIW_OP_READ_RESPONSE:
11538c2ecf20Sopenharmony_ci			siw_dbg_qp(qp, "proc. read.response failed: %d\n", rv);
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci			siw_qp_event(qp, IB_EVENT_QP_REQ_ERR);
11568c2ecf20Sopenharmony_ci
11578c2ecf20Sopenharmony_ci			siw_wqe_put_mem(wqe, SIW_OP_READ_RESPONSE);
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci			break;
11608c2ecf20Sopenharmony_ci
11618c2ecf20Sopenharmony_ci		default:
11628c2ecf20Sopenharmony_ci			WARN(1, "undefined WQE type %d\n", tx_type);
11638c2ecf20Sopenharmony_ci			rv = -EINVAL;
11648c2ecf20Sopenharmony_ci		}
11658c2ecf20Sopenharmony_ci		wqe->wr_status = SIW_WR_IDLE;
11668c2ecf20Sopenharmony_ci	}
11678c2ecf20Sopenharmony_cidone:
11688c2ecf20Sopenharmony_ci	return rv;
11698c2ecf20Sopenharmony_ci}
11708c2ecf20Sopenharmony_ci
11718c2ecf20Sopenharmony_cistatic void siw_sq_resume(struct siw_qp *qp)
11728c2ecf20Sopenharmony_ci{
11738c2ecf20Sopenharmony_ci	if (down_read_trylock(&qp->state_lock)) {
11748c2ecf20Sopenharmony_ci		if (likely(qp->attrs.state == SIW_QP_STATE_RTS &&
11758c2ecf20Sopenharmony_ci			   !qp->tx_ctx.tx_suspend)) {
11768c2ecf20Sopenharmony_ci			int rv = siw_qp_sq_process(qp);
11778c2ecf20Sopenharmony_ci
11788c2ecf20Sopenharmony_ci			up_read(&qp->state_lock);
11798c2ecf20Sopenharmony_ci
11808c2ecf20Sopenharmony_ci			if (unlikely(rv < 0)) {
11818c2ecf20Sopenharmony_ci				siw_dbg_qp(qp, "SQ task failed: err %d\n", rv);
11828c2ecf20Sopenharmony_ci
11838c2ecf20Sopenharmony_ci				if (!qp->tx_ctx.tx_suspend)
11848c2ecf20Sopenharmony_ci					siw_qp_cm_drop(qp, 0);
11858c2ecf20Sopenharmony_ci			}
11868c2ecf20Sopenharmony_ci		} else {
11878c2ecf20Sopenharmony_ci			up_read(&qp->state_lock);
11888c2ecf20Sopenharmony_ci		}
11898c2ecf20Sopenharmony_ci	} else {
11908c2ecf20Sopenharmony_ci		siw_dbg_qp(qp, "Resume SQ while QP locked\n");
11918c2ecf20Sopenharmony_ci	}
11928c2ecf20Sopenharmony_ci	siw_qp_put(qp);
11938c2ecf20Sopenharmony_ci}
11948c2ecf20Sopenharmony_ci
11958c2ecf20Sopenharmony_cistruct tx_task_t {
11968c2ecf20Sopenharmony_ci	struct llist_head active;
11978c2ecf20Sopenharmony_ci	wait_queue_head_t waiting;
11988c2ecf20Sopenharmony_ci};
11998c2ecf20Sopenharmony_ci
12008c2ecf20Sopenharmony_cistatic DEFINE_PER_CPU(struct tx_task_t, siw_tx_task_g);
12018c2ecf20Sopenharmony_ci
12028c2ecf20Sopenharmony_civoid siw_stop_tx_thread(int nr_cpu)
12038c2ecf20Sopenharmony_ci{
12048c2ecf20Sopenharmony_ci	kthread_stop(siw_tx_thread[nr_cpu]);
12058c2ecf20Sopenharmony_ci	wake_up(&per_cpu(siw_tx_task_g, nr_cpu).waiting);
12068c2ecf20Sopenharmony_ci}
12078c2ecf20Sopenharmony_ci
12088c2ecf20Sopenharmony_ciint siw_run_sq(void *data)
12098c2ecf20Sopenharmony_ci{
12108c2ecf20Sopenharmony_ci	const int nr_cpu = (unsigned int)(long)data;
12118c2ecf20Sopenharmony_ci	struct llist_node *active;
12128c2ecf20Sopenharmony_ci	struct siw_qp *qp;
12138c2ecf20Sopenharmony_ci	struct tx_task_t *tx_task = &per_cpu(siw_tx_task_g, nr_cpu);
12148c2ecf20Sopenharmony_ci
12158c2ecf20Sopenharmony_ci	init_llist_head(&tx_task->active);
12168c2ecf20Sopenharmony_ci	init_waitqueue_head(&tx_task->waiting);
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci	while (1) {
12198c2ecf20Sopenharmony_ci		struct llist_node *fifo_list = NULL;
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci		wait_event_interruptible(tx_task->waiting,
12228c2ecf20Sopenharmony_ci					 !llist_empty(&tx_task->active) ||
12238c2ecf20Sopenharmony_ci						 kthread_should_stop());
12248c2ecf20Sopenharmony_ci
12258c2ecf20Sopenharmony_ci		if (kthread_should_stop())
12268c2ecf20Sopenharmony_ci			break;
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci		active = llist_del_all(&tx_task->active);
12298c2ecf20Sopenharmony_ci		/*
12308c2ecf20Sopenharmony_ci		 * llist_del_all returns a list with newest entry first.
12318c2ecf20Sopenharmony_ci		 * Re-order list for fairness among QP's.
12328c2ecf20Sopenharmony_ci		 */
12338c2ecf20Sopenharmony_ci		while (active) {
12348c2ecf20Sopenharmony_ci			struct llist_node *tmp = active;
12358c2ecf20Sopenharmony_ci
12368c2ecf20Sopenharmony_ci			active = llist_next(active);
12378c2ecf20Sopenharmony_ci			tmp->next = fifo_list;
12388c2ecf20Sopenharmony_ci			fifo_list = tmp;
12398c2ecf20Sopenharmony_ci		}
12408c2ecf20Sopenharmony_ci		while (fifo_list) {
12418c2ecf20Sopenharmony_ci			qp = container_of(fifo_list, struct siw_qp, tx_list);
12428c2ecf20Sopenharmony_ci			fifo_list = llist_next(fifo_list);
12438c2ecf20Sopenharmony_ci			qp->tx_list.next = NULL;
12448c2ecf20Sopenharmony_ci
12458c2ecf20Sopenharmony_ci			siw_sq_resume(qp);
12468c2ecf20Sopenharmony_ci		}
12478c2ecf20Sopenharmony_ci	}
12488c2ecf20Sopenharmony_ci	active = llist_del_all(&tx_task->active);
12498c2ecf20Sopenharmony_ci	if (active) {
12508c2ecf20Sopenharmony_ci		llist_for_each_entry(qp, active, tx_list) {
12518c2ecf20Sopenharmony_ci			qp->tx_list.next = NULL;
12528c2ecf20Sopenharmony_ci			siw_sq_resume(qp);
12538c2ecf20Sopenharmony_ci		}
12548c2ecf20Sopenharmony_ci	}
12558c2ecf20Sopenharmony_ci	return 0;
12568c2ecf20Sopenharmony_ci}
12578c2ecf20Sopenharmony_ci
12588c2ecf20Sopenharmony_ciint siw_sq_start(struct siw_qp *qp)
12598c2ecf20Sopenharmony_ci{
12608c2ecf20Sopenharmony_ci	if (tx_wqe(qp)->wr_status == SIW_WR_IDLE)
12618c2ecf20Sopenharmony_ci		return 0;
12628c2ecf20Sopenharmony_ci
12638c2ecf20Sopenharmony_ci	if (unlikely(!cpu_online(qp->tx_cpu))) {
12648c2ecf20Sopenharmony_ci		siw_put_tx_cpu(qp->tx_cpu);
12658c2ecf20Sopenharmony_ci		qp->tx_cpu = siw_get_tx_cpu(qp->sdev);
12668c2ecf20Sopenharmony_ci		if (qp->tx_cpu < 0) {
12678c2ecf20Sopenharmony_ci			pr_warn("siw: no tx cpu available\n");
12688c2ecf20Sopenharmony_ci
12698c2ecf20Sopenharmony_ci			return -EIO;
12708c2ecf20Sopenharmony_ci		}
12718c2ecf20Sopenharmony_ci	}
12728c2ecf20Sopenharmony_ci	siw_qp_get(qp);
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_ci	llist_add(&qp->tx_list, &per_cpu(siw_tx_task_g, qp->tx_cpu).active);
12758c2ecf20Sopenharmony_ci
12768c2ecf20Sopenharmony_ci	wake_up(&per_cpu(siw_tx_task_g, qp->tx_cpu).waiting);
12778c2ecf20Sopenharmony_ci
12788c2ecf20Sopenharmony_ci	return 0;
12798c2ecf20Sopenharmony_ci}
1280