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#ifndef _SIW_H 78c2ecf20Sopenharmony_ci#define _SIW_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <rdma/ib_verbs.h> 108c2ecf20Sopenharmony_ci#include <rdma/restrack.h> 118c2ecf20Sopenharmony_ci#include <linux/socket.h> 128c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 138c2ecf20Sopenharmony_ci#include <crypto/hash.h> 148c2ecf20Sopenharmony_ci#include <linux/crc32.h> 158c2ecf20Sopenharmony_ci#include <linux/crc32c.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <rdma/siw-abi.h> 188c2ecf20Sopenharmony_ci#include "iwarp.h" 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define SIW_VENDOR_ID 0x626d74 /* ascii 'bmt' for now */ 218c2ecf20Sopenharmony_ci#define SIW_VENDORT_PART_ID 0 228c2ecf20Sopenharmony_ci#define SIW_MAX_QP (1024 * 100) 238c2ecf20Sopenharmony_ci#define SIW_MAX_QP_WR (1024 * 32) 248c2ecf20Sopenharmony_ci#define SIW_MAX_ORD_QP 128 258c2ecf20Sopenharmony_ci#define SIW_MAX_IRD_QP 128 268c2ecf20Sopenharmony_ci#define SIW_MAX_SGE_PBL 256 /* max num sge's for PBL */ 278c2ecf20Sopenharmony_ci#define SIW_MAX_SGE_RD 1 /* iwarp limitation. we could relax */ 288c2ecf20Sopenharmony_ci#define SIW_MAX_CQ (1024 * 100) 298c2ecf20Sopenharmony_ci#define SIW_MAX_CQE (SIW_MAX_QP_WR * 100) 308c2ecf20Sopenharmony_ci#define SIW_MAX_MR (SIW_MAX_QP * 10) 318c2ecf20Sopenharmony_ci#define SIW_MAX_PD SIW_MAX_QP 328c2ecf20Sopenharmony_ci#define SIW_MAX_MW 0 /* to be set if MW's are supported */ 338c2ecf20Sopenharmony_ci#define SIW_MAX_SRQ SIW_MAX_QP 348c2ecf20Sopenharmony_ci#define SIW_MAX_SRQ_WR (SIW_MAX_QP_WR * 10) 358c2ecf20Sopenharmony_ci#define SIW_MAX_CONTEXT SIW_MAX_PD 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* Min number of bytes for using zero copy transmit */ 388c2ecf20Sopenharmony_ci#define SENDPAGE_THRESH PAGE_SIZE 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* Maximum number of frames which can be send in one SQ processing */ 418c2ecf20Sopenharmony_ci#define SQ_USER_MAXBURST 100 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* Maximum number of consecutive IRQ elements which get served 448c2ecf20Sopenharmony_ci * if SQ has pending work. Prevents starving local SQ processing 458c2ecf20Sopenharmony_ci * by serving peer Read Requests. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_ci#define SIW_IRQ_MAXBURST_SQ_ACTIVE 4 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistruct siw_dev_cap { 508c2ecf20Sopenharmony_ci int max_qp; 518c2ecf20Sopenharmony_ci int max_qp_wr; 528c2ecf20Sopenharmony_ci int max_ord; /* max. outbound read queue depth */ 538c2ecf20Sopenharmony_ci int max_ird; /* max. inbound read queue depth */ 548c2ecf20Sopenharmony_ci int max_sge; 558c2ecf20Sopenharmony_ci int max_sge_rd; 568c2ecf20Sopenharmony_ci int max_cq; 578c2ecf20Sopenharmony_ci int max_cqe; 588c2ecf20Sopenharmony_ci int max_mr; 598c2ecf20Sopenharmony_ci int max_pd; 608c2ecf20Sopenharmony_ci int max_mw; 618c2ecf20Sopenharmony_ci int max_srq; 628c2ecf20Sopenharmony_ci int max_srq_wr; 638c2ecf20Sopenharmony_ci int max_srq_sge; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistruct siw_pd { 678c2ecf20Sopenharmony_ci struct ib_pd base_pd; 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistruct siw_device { 718c2ecf20Sopenharmony_ci struct ib_device base_dev; 728c2ecf20Sopenharmony_ci struct net_device *netdev; 738c2ecf20Sopenharmony_ci struct siw_dev_cap attrs; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci u32 vendor_part_id; 768c2ecf20Sopenharmony_ci int numa_node; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci /* physical port state (only one port per device) */ 798c2ecf20Sopenharmony_ci enum ib_port_state state; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci spinlock_t lock; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci struct xarray qp_xa; 848c2ecf20Sopenharmony_ci struct xarray mem_xa; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci struct list_head cep_list; 878c2ecf20Sopenharmony_ci struct list_head qp_list; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci /* active objects statistics to enforce limits */ 908c2ecf20Sopenharmony_ci atomic_t num_qp; 918c2ecf20Sopenharmony_ci atomic_t num_cq; 928c2ecf20Sopenharmony_ci atomic_t num_pd; 938c2ecf20Sopenharmony_ci atomic_t num_mr; 948c2ecf20Sopenharmony_ci atomic_t num_srq; 958c2ecf20Sopenharmony_ci atomic_t num_ctx; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci struct work_struct netdev_down; 988c2ecf20Sopenharmony_ci}; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistruct siw_ucontext { 1018c2ecf20Sopenharmony_ci struct ib_ucontext base_ucontext; 1028c2ecf20Sopenharmony_ci struct siw_device *sdev; 1038c2ecf20Sopenharmony_ci}; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* 1068c2ecf20Sopenharmony_ci * The RDMA core does not define LOCAL_READ access, which is always 1078c2ecf20Sopenharmony_ci * enabled implictely. 1088c2ecf20Sopenharmony_ci */ 1098c2ecf20Sopenharmony_ci#define IWARP_ACCESS_MASK \ 1108c2ecf20Sopenharmony_ci (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE | \ 1118c2ecf20Sopenharmony_ci IB_ACCESS_REMOTE_READ) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* 1148c2ecf20Sopenharmony_ci * siw presentation of user memory registered as source 1158c2ecf20Sopenharmony_ci * or target of RDMA operations. 1168c2ecf20Sopenharmony_ci */ 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_cistruct siw_page_chunk { 1198c2ecf20Sopenharmony_ci struct page **plist; 1208c2ecf20Sopenharmony_ci}; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistruct siw_umem { 1238c2ecf20Sopenharmony_ci struct siw_page_chunk *page_chunk; 1248c2ecf20Sopenharmony_ci int num_pages; 1258c2ecf20Sopenharmony_ci bool writable; 1268c2ecf20Sopenharmony_ci u64 fp_addr; /* First page base address */ 1278c2ecf20Sopenharmony_ci struct mm_struct *owning_mm; 1288c2ecf20Sopenharmony_ci}; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistruct siw_pble { 1318c2ecf20Sopenharmony_ci dma_addr_t addr; /* Address of assigned buffer */ 1328c2ecf20Sopenharmony_ci unsigned int size; /* Size of this entry */ 1338c2ecf20Sopenharmony_ci unsigned long pbl_off; /* Total offset from start of PBL */ 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistruct siw_pbl { 1378c2ecf20Sopenharmony_ci unsigned int num_buf; 1388c2ecf20Sopenharmony_ci unsigned int max_buf; 1398c2ecf20Sopenharmony_ci struct siw_pble pbe[]; 1408c2ecf20Sopenharmony_ci}; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci/* 1438c2ecf20Sopenharmony_ci * Generic memory representation for registered siw memory. 1448c2ecf20Sopenharmony_ci * Memory lookup always via higher 24 bit of STag (STag index). 1458c2ecf20Sopenharmony_ci */ 1468c2ecf20Sopenharmony_cistruct siw_mem { 1478c2ecf20Sopenharmony_ci struct siw_device *sdev; 1488c2ecf20Sopenharmony_ci struct kref ref; 1498c2ecf20Sopenharmony_ci u64 va; /* VA of memory */ 1508c2ecf20Sopenharmony_ci u64 len; /* length of the memory buffer in bytes */ 1518c2ecf20Sopenharmony_ci u32 stag; /* iWarp memory access steering tag */ 1528c2ecf20Sopenharmony_ci u8 stag_valid; /* VALID or INVALID */ 1538c2ecf20Sopenharmony_ci u8 is_pbl; /* PBL or user space mem */ 1548c2ecf20Sopenharmony_ci u8 is_mw; /* Memory Region or Memory Window */ 1558c2ecf20Sopenharmony_ci enum ib_access_flags perms; /* local/remote READ & WRITE */ 1568c2ecf20Sopenharmony_ci union { 1578c2ecf20Sopenharmony_ci struct siw_umem *umem; 1588c2ecf20Sopenharmony_ci struct siw_pbl *pbl; 1598c2ecf20Sopenharmony_ci void *mem_obj; 1608c2ecf20Sopenharmony_ci }; 1618c2ecf20Sopenharmony_ci struct ib_pd *pd; 1628c2ecf20Sopenharmony_ci}; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistruct siw_mr { 1658c2ecf20Sopenharmony_ci struct ib_mr base_mr; 1668c2ecf20Sopenharmony_ci struct siw_mem *mem; 1678c2ecf20Sopenharmony_ci struct rcu_head rcu; 1688c2ecf20Sopenharmony_ci}; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci/* 1718c2ecf20Sopenharmony_ci * Error codes for local or remote 1728c2ecf20Sopenharmony_ci * access to registered memory 1738c2ecf20Sopenharmony_ci */ 1748c2ecf20Sopenharmony_cienum siw_access_state { 1758c2ecf20Sopenharmony_ci E_ACCESS_OK, 1768c2ecf20Sopenharmony_ci E_STAG_INVALID, 1778c2ecf20Sopenharmony_ci E_BASE_BOUNDS, 1788c2ecf20Sopenharmony_ci E_ACCESS_PERM, 1798c2ecf20Sopenharmony_ci E_PD_MISMATCH 1808c2ecf20Sopenharmony_ci}; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cienum siw_wr_state { 1838c2ecf20Sopenharmony_ci SIW_WR_IDLE, 1848c2ecf20Sopenharmony_ci SIW_WR_QUEUED, /* processing has not started yet */ 1858c2ecf20Sopenharmony_ci SIW_WR_INPROGRESS /* initiated processing of the WR */ 1868c2ecf20Sopenharmony_ci}; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci/* The WQE currently being processed (RX or TX) */ 1898c2ecf20Sopenharmony_cistruct siw_wqe { 1908c2ecf20Sopenharmony_ci /* Copy of applications SQE or RQE */ 1918c2ecf20Sopenharmony_ci union { 1928c2ecf20Sopenharmony_ci struct siw_sqe sqe; 1938c2ecf20Sopenharmony_ci struct siw_rqe rqe; 1948c2ecf20Sopenharmony_ci }; 1958c2ecf20Sopenharmony_ci struct siw_mem *mem[SIW_MAX_SGE]; /* per sge's resolved mem */ 1968c2ecf20Sopenharmony_ci enum siw_wr_state wr_status; 1978c2ecf20Sopenharmony_ci enum siw_wc_status wc_status; 1988c2ecf20Sopenharmony_ci u32 bytes; /* total bytes to process */ 1998c2ecf20Sopenharmony_ci u32 processed; /* bytes processed */ 2008c2ecf20Sopenharmony_ci}; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_cistruct siw_cq { 2038c2ecf20Sopenharmony_ci struct ib_cq base_cq; 2048c2ecf20Sopenharmony_ci spinlock_t lock; 2058c2ecf20Sopenharmony_ci struct siw_cq_ctrl *notify; 2068c2ecf20Sopenharmony_ci struct siw_cqe *queue; 2078c2ecf20Sopenharmony_ci u32 cq_put; 2088c2ecf20Sopenharmony_ci u32 cq_get; 2098c2ecf20Sopenharmony_ci u32 num_cqe; 2108c2ecf20Sopenharmony_ci struct rdma_user_mmap_entry *cq_entry; /* mmap info for CQE array */ 2118c2ecf20Sopenharmony_ci u32 id; /* For debugging only */ 2128c2ecf20Sopenharmony_ci}; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cienum siw_qp_state { 2158c2ecf20Sopenharmony_ci SIW_QP_STATE_IDLE, 2168c2ecf20Sopenharmony_ci SIW_QP_STATE_RTR, 2178c2ecf20Sopenharmony_ci SIW_QP_STATE_RTS, 2188c2ecf20Sopenharmony_ci SIW_QP_STATE_CLOSING, 2198c2ecf20Sopenharmony_ci SIW_QP_STATE_TERMINATE, 2208c2ecf20Sopenharmony_ci SIW_QP_STATE_ERROR, 2218c2ecf20Sopenharmony_ci SIW_QP_STATE_COUNT 2228c2ecf20Sopenharmony_ci}; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cienum siw_qp_flags { 2258c2ecf20Sopenharmony_ci SIW_RDMA_BIND_ENABLED = (1 << 0), 2268c2ecf20Sopenharmony_ci SIW_RDMA_WRITE_ENABLED = (1 << 1), 2278c2ecf20Sopenharmony_ci SIW_RDMA_READ_ENABLED = (1 << 2), 2288c2ecf20Sopenharmony_ci SIW_SIGNAL_ALL_WR = (1 << 3), 2298c2ecf20Sopenharmony_ci SIW_MPA_CRC = (1 << 4), 2308c2ecf20Sopenharmony_ci SIW_QP_IN_DESTROY = (1 << 5) 2318c2ecf20Sopenharmony_ci}; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_cienum siw_qp_attr_mask { 2348c2ecf20Sopenharmony_ci SIW_QP_ATTR_STATE = (1 << 0), 2358c2ecf20Sopenharmony_ci SIW_QP_ATTR_ACCESS_FLAGS = (1 << 1), 2368c2ecf20Sopenharmony_ci SIW_QP_ATTR_LLP_HANDLE = (1 << 2), 2378c2ecf20Sopenharmony_ci SIW_QP_ATTR_ORD = (1 << 3), 2388c2ecf20Sopenharmony_ci SIW_QP_ATTR_IRD = (1 << 4), 2398c2ecf20Sopenharmony_ci SIW_QP_ATTR_SQ_SIZE = (1 << 5), 2408c2ecf20Sopenharmony_ci SIW_QP_ATTR_RQ_SIZE = (1 << 6), 2418c2ecf20Sopenharmony_ci SIW_QP_ATTR_MPA = (1 << 7) 2428c2ecf20Sopenharmony_ci}; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_cistruct siw_srq { 2458c2ecf20Sopenharmony_ci struct ib_srq base_srq; 2468c2ecf20Sopenharmony_ci spinlock_t lock; 2478c2ecf20Sopenharmony_ci u32 max_sge; 2488c2ecf20Sopenharmony_ci u32 limit; /* low watermark for async event */ 2498c2ecf20Sopenharmony_ci struct siw_rqe *recvq; 2508c2ecf20Sopenharmony_ci u32 rq_put; 2518c2ecf20Sopenharmony_ci u32 rq_get; 2528c2ecf20Sopenharmony_ci u32 num_rqe; /* max # of wqe's allowed */ 2538c2ecf20Sopenharmony_ci struct rdma_user_mmap_entry *srq_entry; /* mmap info for SRQ array */ 2548c2ecf20Sopenharmony_ci bool armed:1; /* inform user if limit hit */ 2558c2ecf20Sopenharmony_ci bool is_kernel_res:1; /* true if kernel client */ 2568c2ecf20Sopenharmony_ci}; 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_cistruct siw_qp_attrs { 2598c2ecf20Sopenharmony_ci enum siw_qp_state state; 2608c2ecf20Sopenharmony_ci u32 sq_size; 2618c2ecf20Sopenharmony_ci u32 rq_size; 2628c2ecf20Sopenharmony_ci u32 orq_size; 2638c2ecf20Sopenharmony_ci u32 irq_size; 2648c2ecf20Sopenharmony_ci u32 sq_max_sges; 2658c2ecf20Sopenharmony_ci u32 rq_max_sges; 2668c2ecf20Sopenharmony_ci enum siw_qp_flags flags; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci struct socket *sk; 2698c2ecf20Sopenharmony_ci}; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cienum siw_tx_ctx { 2728c2ecf20Sopenharmony_ci SIW_SEND_HDR, /* start or continue sending HDR */ 2738c2ecf20Sopenharmony_ci SIW_SEND_DATA, /* start or continue sending DDP payload */ 2748c2ecf20Sopenharmony_ci SIW_SEND_TRAILER, /* start or continue sending TRAILER */ 2758c2ecf20Sopenharmony_ci SIW_SEND_SHORT_FPDU/* send whole FPDU hdr|data|trailer at once */ 2768c2ecf20Sopenharmony_ci}; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_cienum siw_rx_state { 2798c2ecf20Sopenharmony_ci SIW_GET_HDR, /* await new hdr or within hdr */ 2808c2ecf20Sopenharmony_ci SIW_GET_DATA_START, /* start of inbound DDP payload */ 2818c2ecf20Sopenharmony_ci SIW_GET_DATA_MORE, /* continuation of (misaligned) DDP payload */ 2828c2ecf20Sopenharmony_ci SIW_GET_TRAILER/* await new trailer or within trailer */ 2838c2ecf20Sopenharmony_ci}; 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_cistruct siw_rx_stream { 2868c2ecf20Sopenharmony_ci struct sk_buff *skb; 2878c2ecf20Sopenharmony_ci int skb_new; /* pending unread bytes in skb */ 2888c2ecf20Sopenharmony_ci int skb_offset; /* offset in skb */ 2898c2ecf20Sopenharmony_ci int skb_copied; /* processed bytes in skb */ 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci union iwarp_hdr hdr; 2928c2ecf20Sopenharmony_ci struct mpa_trailer trailer; 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci enum siw_rx_state state; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci /* 2978c2ecf20Sopenharmony_ci * For each FPDU, main RX loop runs through 3 stages: 2988c2ecf20Sopenharmony_ci * Receiving protocol headers, placing DDP payload and receiving 2998c2ecf20Sopenharmony_ci * trailer information (CRC + possibly padding). 3008c2ecf20Sopenharmony_ci * Next two variables keep state on receive status of the 3018c2ecf20Sopenharmony_ci * current FPDU part (hdr, data, trailer). 3028c2ecf20Sopenharmony_ci */ 3038c2ecf20Sopenharmony_ci int fpdu_part_rcvd; /* bytes in pkt part copied */ 3048c2ecf20Sopenharmony_ci int fpdu_part_rem; /* bytes in pkt part not seen */ 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci /* 3078c2ecf20Sopenharmony_ci * Next expected DDP MSN for each QN + 3088c2ecf20Sopenharmony_ci * expected steering tag + 3098c2ecf20Sopenharmony_ci * expected DDP tagget offset (all HBO) 3108c2ecf20Sopenharmony_ci */ 3118c2ecf20Sopenharmony_ci u32 ddp_msn[RDMAP_UNTAGGED_QN_COUNT]; 3128c2ecf20Sopenharmony_ci u32 ddp_stag; 3138c2ecf20Sopenharmony_ci u64 ddp_to; 3148c2ecf20Sopenharmony_ci u32 inval_stag; /* Stag to be invalidated */ 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci struct shash_desc *mpa_crc_hd; 3178c2ecf20Sopenharmony_ci u8 rx_suspend : 1; 3188c2ecf20Sopenharmony_ci u8 pad : 2; /* # of pad bytes expected */ 3198c2ecf20Sopenharmony_ci u8 rdmap_op : 4; /* opcode of current frame */ 3208c2ecf20Sopenharmony_ci}; 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_cistruct siw_rx_fpdu { 3238c2ecf20Sopenharmony_ci /* 3248c2ecf20Sopenharmony_ci * Local destination memory of inbound RDMA operation. 3258c2ecf20Sopenharmony_ci * Valid, according to wqe->wr_status 3268c2ecf20Sopenharmony_ci */ 3278c2ecf20Sopenharmony_ci struct siw_wqe wqe_active; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci unsigned int pbl_idx; /* Index into current PBL */ 3308c2ecf20Sopenharmony_ci unsigned int sge_idx; /* current sge in rx */ 3318c2ecf20Sopenharmony_ci unsigned int sge_off; /* already rcvd in curr. sge */ 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci char first_ddp_seg; /* this is the first DDP seg */ 3348c2ecf20Sopenharmony_ci char more_ddp_segs; /* more DDP segs expected */ 3358c2ecf20Sopenharmony_ci u8 prev_rdmap_op : 4; /* opcode of prev frame */ 3368c2ecf20Sopenharmony_ci}; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci/* 3398c2ecf20Sopenharmony_ci * Shorthands for short packets w/o payload 3408c2ecf20Sopenharmony_ci * to be transmitted more efficient. 3418c2ecf20Sopenharmony_ci */ 3428c2ecf20Sopenharmony_cistruct siw_send_pkt { 3438c2ecf20Sopenharmony_ci struct iwarp_send send; 3448c2ecf20Sopenharmony_ci __be32 crc; 3458c2ecf20Sopenharmony_ci}; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_cistruct siw_write_pkt { 3488c2ecf20Sopenharmony_ci struct iwarp_rdma_write write; 3498c2ecf20Sopenharmony_ci __be32 crc; 3508c2ecf20Sopenharmony_ci}; 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_cistruct siw_rreq_pkt { 3538c2ecf20Sopenharmony_ci struct iwarp_rdma_rreq rreq; 3548c2ecf20Sopenharmony_ci __be32 crc; 3558c2ecf20Sopenharmony_ci}; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_cistruct siw_rresp_pkt { 3588c2ecf20Sopenharmony_ci struct iwarp_rdma_rresp rresp; 3598c2ecf20Sopenharmony_ci __be32 crc; 3608c2ecf20Sopenharmony_ci}; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_cistruct siw_iwarp_tx { 3638c2ecf20Sopenharmony_ci union { 3648c2ecf20Sopenharmony_ci union iwarp_hdr hdr; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci /* Generic part of FPDU header */ 3678c2ecf20Sopenharmony_ci struct iwarp_ctrl ctrl; 3688c2ecf20Sopenharmony_ci struct iwarp_ctrl_untagged c_untagged; 3698c2ecf20Sopenharmony_ci struct iwarp_ctrl_tagged c_tagged; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci /* FPDU headers */ 3728c2ecf20Sopenharmony_ci struct iwarp_rdma_write rwrite; 3738c2ecf20Sopenharmony_ci struct iwarp_rdma_rreq rreq; 3748c2ecf20Sopenharmony_ci struct iwarp_rdma_rresp rresp; 3758c2ecf20Sopenharmony_ci struct iwarp_terminate terminate; 3768c2ecf20Sopenharmony_ci struct iwarp_send send; 3778c2ecf20Sopenharmony_ci struct iwarp_send_inv send_inv; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci /* complete short FPDUs */ 3808c2ecf20Sopenharmony_ci struct siw_send_pkt send_pkt; 3818c2ecf20Sopenharmony_ci struct siw_write_pkt write_pkt; 3828c2ecf20Sopenharmony_ci struct siw_rreq_pkt rreq_pkt; 3838c2ecf20Sopenharmony_ci struct siw_rresp_pkt rresp_pkt; 3848c2ecf20Sopenharmony_ci } pkt; 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci struct mpa_trailer trailer; 3878c2ecf20Sopenharmony_ci /* DDP MSN for untagged messages */ 3888c2ecf20Sopenharmony_ci u32 ddp_msn[RDMAP_UNTAGGED_QN_COUNT]; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci enum siw_tx_ctx state; 3918c2ecf20Sopenharmony_ci u16 ctrl_len; /* ddp+rdmap hdr */ 3928c2ecf20Sopenharmony_ci u16 ctrl_sent; 3938c2ecf20Sopenharmony_ci int burst; 3948c2ecf20Sopenharmony_ci int bytes_unsent; /* ddp payload bytes */ 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci struct shash_desc *mpa_crc_hd; 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci u8 do_crc : 1; /* do crc for segment */ 3998c2ecf20Sopenharmony_ci u8 use_sendpage : 1; /* send w/o copy */ 4008c2ecf20Sopenharmony_ci u8 tx_suspend : 1; /* stop sending DDP segs. */ 4018c2ecf20Sopenharmony_ci u8 pad : 2; /* # pad in current fpdu */ 4028c2ecf20Sopenharmony_ci u8 orq_fence : 1; /* ORQ full or Send fenced */ 4038c2ecf20Sopenharmony_ci u8 in_syscall : 1; /* TX out of user context */ 4048c2ecf20Sopenharmony_ci u8 zcopy_tx : 1; /* Use TCP_SENDPAGE if possible */ 4058c2ecf20Sopenharmony_ci u8 gso_seg_limit; /* Maximum segments for GSO, 0 = unbound */ 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci u16 fpdu_len; /* len of FPDU to tx */ 4088c2ecf20Sopenharmony_ci unsigned int tcp_seglen; /* remaining tcp seg space */ 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci struct siw_wqe wqe_active; 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci int pbl_idx; /* Index into current PBL */ 4138c2ecf20Sopenharmony_ci int sge_idx; /* current sge in tx */ 4148c2ecf20Sopenharmony_ci u32 sge_off; /* already sent in curr. sge */ 4158c2ecf20Sopenharmony_ci}; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_cistruct siw_qp { 4188c2ecf20Sopenharmony_ci struct ib_qp base_qp; 4198c2ecf20Sopenharmony_ci struct siw_device *sdev; 4208c2ecf20Sopenharmony_ci struct kref ref; 4218c2ecf20Sopenharmony_ci struct list_head devq; 4228c2ecf20Sopenharmony_ci int tx_cpu; 4238c2ecf20Sopenharmony_ci struct siw_qp_attrs attrs; 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci struct siw_cep *cep; 4268c2ecf20Sopenharmony_ci struct rw_semaphore state_lock; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci struct ib_pd *pd; 4298c2ecf20Sopenharmony_ci struct siw_cq *scq; 4308c2ecf20Sopenharmony_ci struct siw_cq *rcq; 4318c2ecf20Sopenharmony_ci struct siw_srq *srq; 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci struct siw_iwarp_tx tx_ctx; /* Transmit context */ 4348c2ecf20Sopenharmony_ci spinlock_t sq_lock; 4358c2ecf20Sopenharmony_ci struct siw_sqe *sendq; /* send queue element array */ 4368c2ecf20Sopenharmony_ci uint32_t sq_get; /* consumer index into sq array */ 4378c2ecf20Sopenharmony_ci uint32_t sq_put; /* kernel prod. index into sq array */ 4388c2ecf20Sopenharmony_ci struct llist_node tx_list; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci struct siw_sqe *orq; /* outbound read queue element array */ 4418c2ecf20Sopenharmony_ci spinlock_t orq_lock; 4428c2ecf20Sopenharmony_ci uint32_t orq_get; /* consumer index into orq array */ 4438c2ecf20Sopenharmony_ci uint32_t orq_put; /* shared producer index for ORQ */ 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci struct siw_rx_stream rx_stream; 4468c2ecf20Sopenharmony_ci struct siw_rx_fpdu *rx_fpdu; 4478c2ecf20Sopenharmony_ci struct siw_rx_fpdu rx_tagged; 4488c2ecf20Sopenharmony_ci struct siw_rx_fpdu rx_untagged; 4498c2ecf20Sopenharmony_ci spinlock_t rq_lock; 4508c2ecf20Sopenharmony_ci struct siw_rqe *recvq; /* recv queue element array */ 4518c2ecf20Sopenharmony_ci uint32_t rq_get; /* consumer index into rq array */ 4528c2ecf20Sopenharmony_ci uint32_t rq_put; /* kernel prod. index into rq array */ 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci struct siw_sqe *irq; /* inbound read queue element array */ 4558c2ecf20Sopenharmony_ci uint32_t irq_get; /* consumer index into irq array */ 4568c2ecf20Sopenharmony_ci uint32_t irq_put; /* producer index into irq array */ 4578c2ecf20Sopenharmony_ci int irq_burst; 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci struct { /* information to be carried in TERMINATE pkt, if valid */ 4608c2ecf20Sopenharmony_ci u8 valid; 4618c2ecf20Sopenharmony_ci u8 in_tx; 4628c2ecf20Sopenharmony_ci u8 layer : 4, etype : 4; 4638c2ecf20Sopenharmony_ci u8 ecode; 4648c2ecf20Sopenharmony_ci } term_info; 4658c2ecf20Sopenharmony_ci struct rdma_user_mmap_entry *sq_entry; /* mmap info for SQE array */ 4668c2ecf20Sopenharmony_ci struct rdma_user_mmap_entry *rq_entry; /* mmap info for RQE array */ 4678c2ecf20Sopenharmony_ci struct rcu_head rcu; 4688c2ecf20Sopenharmony_ci}; 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci/* helper macros */ 4718c2ecf20Sopenharmony_ci#define rx_qp(rx) container_of(rx, struct siw_qp, rx_stream) 4728c2ecf20Sopenharmony_ci#define tx_qp(tx) container_of(tx, struct siw_qp, tx_ctx) 4738c2ecf20Sopenharmony_ci#define tx_wqe(qp) (&(qp)->tx_ctx.wqe_active) 4748c2ecf20Sopenharmony_ci#define rx_wqe(rctx) (&(rctx)->wqe_active) 4758c2ecf20Sopenharmony_ci#define rx_mem(rctx) ((rctx)->wqe_active.mem[0]) 4768c2ecf20Sopenharmony_ci#define tx_type(wqe) ((wqe)->sqe.opcode) 4778c2ecf20Sopenharmony_ci#define rx_type(wqe) ((wqe)->rqe.opcode) 4788c2ecf20Sopenharmony_ci#define tx_flags(wqe) ((wqe)->sqe.flags) 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_cistruct iwarp_msg_info { 4818c2ecf20Sopenharmony_ci int hdr_len; 4828c2ecf20Sopenharmony_ci struct iwarp_ctrl ctrl; 4838c2ecf20Sopenharmony_ci int (*rx_data)(struct siw_qp *qp); 4848c2ecf20Sopenharmony_ci}; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_cistruct siw_user_mmap_entry { 4878c2ecf20Sopenharmony_ci struct rdma_user_mmap_entry rdma_entry; 4888c2ecf20Sopenharmony_ci void *address; 4898c2ecf20Sopenharmony_ci}; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci/* Global siw parameters. Currently set in siw_main.c */ 4928c2ecf20Sopenharmony_ciextern const bool zcopy_tx; 4938c2ecf20Sopenharmony_ciextern const bool try_gso; 4948c2ecf20Sopenharmony_ciextern const bool loopback_enabled; 4958c2ecf20Sopenharmony_ciextern const bool mpa_crc_required; 4968c2ecf20Sopenharmony_ciextern const bool mpa_crc_strict; 4978c2ecf20Sopenharmony_ciextern const bool siw_tcp_nagle; 4988c2ecf20Sopenharmony_ciextern u_char mpa_version; 4998c2ecf20Sopenharmony_ciextern const bool peer_to_peer; 5008c2ecf20Sopenharmony_ciextern struct task_struct *siw_tx_thread[]; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ciextern struct crypto_shash *siw_crypto_shash; 5038c2ecf20Sopenharmony_ciextern struct iwarp_msg_info iwarp_pktinfo[RDMAP_TERMINATE + 1]; 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci/* QP general functions */ 5068c2ecf20Sopenharmony_ciint siw_qp_modify(struct siw_qp *qp, struct siw_qp_attrs *attr, 5078c2ecf20Sopenharmony_ci enum siw_qp_attr_mask mask); 5088c2ecf20Sopenharmony_ciint siw_qp_mpa_rts(struct siw_qp *qp, enum mpa_v2_ctrl ctrl); 5098c2ecf20Sopenharmony_civoid siw_qp_llp_close(struct siw_qp *qp); 5108c2ecf20Sopenharmony_civoid siw_qp_cm_drop(struct siw_qp *qp, int schedule); 5118c2ecf20Sopenharmony_civoid siw_send_terminate(struct siw_qp *qp); 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_civoid siw_qp_get_ref(struct ib_qp *qp); 5148c2ecf20Sopenharmony_civoid siw_qp_put_ref(struct ib_qp *qp); 5158c2ecf20Sopenharmony_ciint siw_qp_add(struct siw_device *sdev, struct siw_qp *qp); 5168c2ecf20Sopenharmony_civoid siw_free_qp(struct kref *ref); 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_civoid siw_init_terminate(struct siw_qp *qp, enum term_elayer layer, 5198c2ecf20Sopenharmony_ci u8 etype, u8 ecode, int in_tx); 5208c2ecf20Sopenharmony_cienum ddp_ecode siw_tagged_error(enum siw_access_state state); 5218c2ecf20Sopenharmony_cienum rdmap_ecode siw_rdmap_error(enum siw_access_state state); 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_civoid siw_read_to_orq(struct siw_sqe *rreq, struct siw_sqe *sqe); 5248c2ecf20Sopenharmony_ciint siw_sqe_complete(struct siw_qp *qp, struct siw_sqe *sqe, u32 bytes, 5258c2ecf20Sopenharmony_ci enum siw_wc_status status); 5268c2ecf20Sopenharmony_ciint siw_rqe_complete(struct siw_qp *qp, struct siw_rqe *rqe, u32 bytes, 5278c2ecf20Sopenharmony_ci u32 inval_stag, enum siw_wc_status status); 5288c2ecf20Sopenharmony_civoid siw_qp_llp_data_ready(struct sock *sk); 5298c2ecf20Sopenharmony_civoid siw_qp_llp_write_space(struct sock *sk); 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci/* QP TX path functions */ 5328c2ecf20Sopenharmony_ciint siw_run_sq(void *arg); 5338c2ecf20Sopenharmony_ciint siw_qp_sq_process(struct siw_qp *qp); 5348c2ecf20Sopenharmony_ciint siw_sq_start(struct siw_qp *qp); 5358c2ecf20Sopenharmony_ciint siw_activate_tx(struct siw_qp *qp); 5368c2ecf20Sopenharmony_civoid siw_stop_tx_thread(int nr_cpu); 5378c2ecf20Sopenharmony_ciint siw_get_tx_cpu(struct siw_device *sdev); 5388c2ecf20Sopenharmony_civoid siw_put_tx_cpu(int cpu); 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci/* QP RX path functions */ 5418c2ecf20Sopenharmony_ciint siw_proc_send(struct siw_qp *qp); 5428c2ecf20Sopenharmony_ciint siw_proc_rreq(struct siw_qp *qp); 5438c2ecf20Sopenharmony_ciint siw_proc_rresp(struct siw_qp *qp); 5448c2ecf20Sopenharmony_ciint siw_proc_write(struct siw_qp *qp); 5458c2ecf20Sopenharmony_ciint siw_proc_terminate(struct siw_qp *qp); 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ciint siw_tcp_rx_data(read_descriptor_t *rd_desc, struct sk_buff *skb, 5488c2ecf20Sopenharmony_ci unsigned int off, size_t len); 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_cistatic inline void set_rx_fpdu_context(struct siw_qp *qp, u8 opcode) 5518c2ecf20Sopenharmony_ci{ 5528c2ecf20Sopenharmony_ci if (opcode == RDMAP_RDMA_WRITE || opcode == RDMAP_RDMA_READ_RESP) 5538c2ecf20Sopenharmony_ci qp->rx_fpdu = &qp->rx_tagged; 5548c2ecf20Sopenharmony_ci else 5558c2ecf20Sopenharmony_ci qp->rx_fpdu = &qp->rx_untagged; 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci qp->rx_stream.rdmap_op = opcode; 5588c2ecf20Sopenharmony_ci} 5598c2ecf20Sopenharmony_ci 5608c2ecf20Sopenharmony_cistatic inline struct siw_ucontext *to_siw_ctx(struct ib_ucontext *base_ctx) 5618c2ecf20Sopenharmony_ci{ 5628c2ecf20Sopenharmony_ci return container_of(base_ctx, struct siw_ucontext, base_ucontext); 5638c2ecf20Sopenharmony_ci} 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_cistatic inline struct siw_qp *to_siw_qp(struct ib_qp *base_qp) 5668c2ecf20Sopenharmony_ci{ 5678c2ecf20Sopenharmony_ci return container_of(base_qp, struct siw_qp, base_qp); 5688c2ecf20Sopenharmony_ci} 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_cistatic inline struct siw_cq *to_siw_cq(struct ib_cq *base_cq) 5718c2ecf20Sopenharmony_ci{ 5728c2ecf20Sopenharmony_ci return container_of(base_cq, struct siw_cq, base_cq); 5738c2ecf20Sopenharmony_ci} 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_cistatic inline struct siw_srq *to_siw_srq(struct ib_srq *base_srq) 5768c2ecf20Sopenharmony_ci{ 5778c2ecf20Sopenharmony_ci return container_of(base_srq, struct siw_srq, base_srq); 5788c2ecf20Sopenharmony_ci} 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_cistatic inline struct siw_device *to_siw_dev(struct ib_device *base_dev) 5818c2ecf20Sopenharmony_ci{ 5828c2ecf20Sopenharmony_ci return container_of(base_dev, struct siw_device, base_dev); 5838c2ecf20Sopenharmony_ci} 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_cistatic inline struct siw_mr *to_siw_mr(struct ib_mr *base_mr) 5868c2ecf20Sopenharmony_ci{ 5878c2ecf20Sopenharmony_ci return container_of(base_mr, struct siw_mr, base_mr); 5888c2ecf20Sopenharmony_ci} 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_cistatic inline struct siw_user_mmap_entry * 5918c2ecf20Sopenharmony_cito_siw_mmap_entry(struct rdma_user_mmap_entry *rdma_mmap) 5928c2ecf20Sopenharmony_ci{ 5938c2ecf20Sopenharmony_ci return container_of(rdma_mmap, struct siw_user_mmap_entry, rdma_entry); 5948c2ecf20Sopenharmony_ci} 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_cistatic inline struct siw_qp *siw_qp_id2obj(struct siw_device *sdev, int id) 5978c2ecf20Sopenharmony_ci{ 5988c2ecf20Sopenharmony_ci struct siw_qp *qp; 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci rcu_read_lock(); 6018c2ecf20Sopenharmony_ci qp = xa_load(&sdev->qp_xa, id); 6028c2ecf20Sopenharmony_ci if (likely(qp && kref_get_unless_zero(&qp->ref))) { 6038c2ecf20Sopenharmony_ci rcu_read_unlock(); 6048c2ecf20Sopenharmony_ci return qp; 6058c2ecf20Sopenharmony_ci } 6068c2ecf20Sopenharmony_ci rcu_read_unlock(); 6078c2ecf20Sopenharmony_ci return NULL; 6088c2ecf20Sopenharmony_ci} 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_cistatic inline u32 qp_id(struct siw_qp *qp) 6118c2ecf20Sopenharmony_ci{ 6128c2ecf20Sopenharmony_ci return qp->base_qp.qp_num; 6138c2ecf20Sopenharmony_ci} 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_cistatic inline void siw_qp_get(struct siw_qp *qp) 6168c2ecf20Sopenharmony_ci{ 6178c2ecf20Sopenharmony_ci kref_get(&qp->ref); 6188c2ecf20Sopenharmony_ci} 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_cistatic inline void siw_qp_put(struct siw_qp *qp) 6218c2ecf20Sopenharmony_ci{ 6228c2ecf20Sopenharmony_ci kref_put(&qp->ref, siw_free_qp); 6238c2ecf20Sopenharmony_ci} 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_cistatic inline int siw_sq_empty(struct siw_qp *qp) 6268c2ecf20Sopenharmony_ci{ 6278c2ecf20Sopenharmony_ci struct siw_sqe *sqe = &qp->sendq[qp->sq_get % qp->attrs.sq_size]; 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci return READ_ONCE(sqe->flags) == 0; 6308c2ecf20Sopenharmony_ci} 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_cistatic inline struct siw_sqe *sq_get_next(struct siw_qp *qp) 6338c2ecf20Sopenharmony_ci{ 6348c2ecf20Sopenharmony_ci struct siw_sqe *sqe = &qp->sendq[qp->sq_get % qp->attrs.sq_size]; 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci if (READ_ONCE(sqe->flags) & SIW_WQE_VALID) 6378c2ecf20Sopenharmony_ci return sqe; 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci return NULL; 6408c2ecf20Sopenharmony_ci} 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_cistatic inline struct siw_sqe *orq_get_current(struct siw_qp *qp) 6438c2ecf20Sopenharmony_ci{ 6448c2ecf20Sopenharmony_ci return &qp->orq[qp->orq_get % qp->attrs.orq_size]; 6458c2ecf20Sopenharmony_ci} 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_cistatic inline struct siw_sqe *orq_get_free(struct siw_qp *qp) 6488c2ecf20Sopenharmony_ci{ 6498c2ecf20Sopenharmony_ci struct siw_sqe *orq_e = &qp->orq[qp->orq_put % qp->attrs.orq_size]; 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci if (READ_ONCE(orq_e->flags) == 0) 6528c2ecf20Sopenharmony_ci return orq_e; 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci return NULL; 6558c2ecf20Sopenharmony_ci} 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_cistatic inline int siw_orq_empty(struct siw_qp *qp) 6588c2ecf20Sopenharmony_ci{ 6598c2ecf20Sopenharmony_ci return qp->orq[qp->orq_get % qp->attrs.orq_size].flags == 0 ? 1 : 0; 6608c2ecf20Sopenharmony_ci} 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_cistatic inline struct siw_sqe *irq_alloc_free(struct siw_qp *qp) 6638c2ecf20Sopenharmony_ci{ 6648c2ecf20Sopenharmony_ci struct siw_sqe *irq_e = &qp->irq[qp->irq_put % qp->attrs.irq_size]; 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci if (READ_ONCE(irq_e->flags) == 0) { 6678c2ecf20Sopenharmony_ci qp->irq_put++; 6688c2ecf20Sopenharmony_ci return irq_e; 6698c2ecf20Sopenharmony_ci } 6708c2ecf20Sopenharmony_ci return NULL; 6718c2ecf20Sopenharmony_ci} 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_cistatic inline __wsum siw_csum_update(const void *buff, int len, __wsum sum) 6748c2ecf20Sopenharmony_ci{ 6758c2ecf20Sopenharmony_ci return (__force __wsum)crc32c((__force __u32)sum, buff, len); 6768c2ecf20Sopenharmony_ci} 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_cistatic inline __wsum siw_csum_combine(__wsum csum, __wsum csum2, int offset, 6798c2ecf20Sopenharmony_ci int len) 6808c2ecf20Sopenharmony_ci{ 6818c2ecf20Sopenharmony_ci return (__force __wsum)__crc32c_le_combine((__force __u32)csum, 6828c2ecf20Sopenharmony_ci (__force __u32)csum2, len); 6838c2ecf20Sopenharmony_ci} 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_cistatic inline void siw_crc_skb(struct siw_rx_stream *srx, unsigned int len) 6868c2ecf20Sopenharmony_ci{ 6878c2ecf20Sopenharmony_ci const struct skb_checksum_ops siw_cs_ops = { 6888c2ecf20Sopenharmony_ci .update = siw_csum_update, 6898c2ecf20Sopenharmony_ci .combine = siw_csum_combine, 6908c2ecf20Sopenharmony_ci }; 6918c2ecf20Sopenharmony_ci __wsum crc = *(u32 *)shash_desc_ctx(srx->mpa_crc_hd); 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci crc = __skb_checksum(srx->skb, srx->skb_offset, len, crc, 6948c2ecf20Sopenharmony_ci &siw_cs_ops); 6958c2ecf20Sopenharmony_ci *(u32 *)shash_desc_ctx(srx->mpa_crc_hd) = crc; 6968c2ecf20Sopenharmony_ci} 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci#define siw_dbg(ibdev, fmt, ...) \ 6998c2ecf20Sopenharmony_ci ibdev_dbg(ibdev, "%s: " fmt, __func__, ##__VA_ARGS__) 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci#define siw_dbg_qp(qp, fmt, ...) \ 7028c2ecf20Sopenharmony_ci ibdev_dbg(&qp->sdev->base_dev, "QP[%u] %s: " fmt, qp_id(qp), __func__, \ 7038c2ecf20Sopenharmony_ci ##__VA_ARGS__) 7048c2ecf20Sopenharmony_ci 7058c2ecf20Sopenharmony_ci#define siw_dbg_cq(cq, fmt, ...) \ 7068c2ecf20Sopenharmony_ci ibdev_dbg(cq->base_cq.device, "CQ[%u] %s: " fmt, cq->id, __func__, \ 7078c2ecf20Sopenharmony_ci ##__VA_ARGS__) 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci#define siw_dbg_pd(pd, fmt, ...) \ 7108c2ecf20Sopenharmony_ci ibdev_dbg(pd->device, "PD[%u] %s: " fmt, pd->res.id, __func__, \ 7118c2ecf20Sopenharmony_ci ##__VA_ARGS__) 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci#define siw_dbg_mem(mem, fmt, ...) \ 7148c2ecf20Sopenharmony_ci ibdev_dbg(&mem->sdev->base_dev, \ 7158c2ecf20Sopenharmony_ci "MEM[0x%08x] %s: " fmt, mem->stag, __func__, ##__VA_ARGS__) 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci#define siw_dbg_cep(cep, fmt, ...) \ 7188c2ecf20Sopenharmony_ci ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%pK] %s: " fmt, \ 7198c2ecf20Sopenharmony_ci cep, __func__, ##__VA_ARGS__) 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_civoid siw_cq_flush(struct siw_cq *cq); 7228c2ecf20Sopenharmony_civoid siw_sq_flush(struct siw_qp *qp); 7238c2ecf20Sopenharmony_civoid siw_rq_flush(struct siw_qp *qp); 7248c2ecf20Sopenharmony_ciint siw_reap_cqe(struct siw_cq *cq, struct ib_wc *wc); 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci#endif 727