1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) */
229c8d9ebSAdit Ranadive /*
329c8d9ebSAdit Ranadive  * Copyright (c) 2012-2016 VMware, Inc.  All rights reserved.
429c8d9ebSAdit Ranadive  *
529c8d9ebSAdit Ranadive  * This program is free software; you can redistribute it and/or
629c8d9ebSAdit Ranadive  * modify it under the terms of EITHER the GNU General Public License
729c8d9ebSAdit Ranadive  * version 2 as published by the Free Software Foundation or the BSD
829c8d9ebSAdit Ranadive  * 2-Clause License. This program is distributed in the hope that it
929c8d9ebSAdit Ranadive  * will be useful, but WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED
1029c8d9ebSAdit Ranadive  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1129c8d9ebSAdit Ranadive  * See the GNU General Public License version 2 for more details at
1229c8d9ebSAdit Ranadive  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html.
1329c8d9ebSAdit Ranadive  *
1429c8d9ebSAdit Ranadive  * You should have received a copy of the GNU General Public License
1529c8d9ebSAdit Ranadive  * along with this program available in the file COPYING in the main
1629c8d9ebSAdit Ranadive  * directory of this source tree.
1729c8d9ebSAdit Ranadive  *
1829c8d9ebSAdit Ranadive  * The BSD 2-Clause License
1929c8d9ebSAdit Ranadive  *
2029c8d9ebSAdit Ranadive  *     Redistribution and use in source and binary forms, with or
2129c8d9ebSAdit Ranadive  *     without modification, are permitted provided that the following
2229c8d9ebSAdit Ranadive  *     conditions are met:
2329c8d9ebSAdit Ranadive  *
2429c8d9ebSAdit Ranadive  *      - Redistributions of source code must retain the above
2529c8d9ebSAdit Ranadive  *        copyright notice, this list of conditions and the following
2629c8d9ebSAdit Ranadive  *        disclaimer.
2729c8d9ebSAdit Ranadive  *
2829c8d9ebSAdit Ranadive  *      - Redistributions in binary form must reproduce the above
2929c8d9ebSAdit Ranadive  *        copyright notice, this list of conditions and the following
3029c8d9ebSAdit Ranadive  *        disclaimer in the documentation and/or other materials
3129c8d9ebSAdit Ranadive  *        provided with the distribution.
3229c8d9ebSAdit Ranadive  *
3329c8d9ebSAdit Ranadive  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3429c8d9ebSAdit Ranadive  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3529c8d9ebSAdit Ranadive  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
3629c8d9ebSAdit Ranadive  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
3729c8d9ebSAdit Ranadive  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
3829c8d9ebSAdit Ranadive  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3929c8d9ebSAdit Ranadive  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
4029c8d9ebSAdit Ranadive  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4129c8d9ebSAdit Ranadive  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4229c8d9ebSAdit Ranadive  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4329c8d9ebSAdit Ranadive  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
4429c8d9ebSAdit Ranadive  * OF THE POSSIBILITY OF SUCH DAMAGE.
4529c8d9ebSAdit Ranadive  */
4629c8d9ebSAdit Ranadive 
4729c8d9ebSAdit Ranadive #ifndef __VMW_PVRDMA_ABI_H__
4829c8d9ebSAdit Ranadive #define __VMW_PVRDMA_ABI_H__
4929c8d9ebSAdit Ranadive 
5029c8d9ebSAdit Ranadive #include <linux/types.h>
5129c8d9ebSAdit Ranadive 
5229c8d9ebSAdit Ranadive #define PVRDMA_UVERBS_ABI_VERSION	3		/* ABI Version. */
5329c8d9ebSAdit Ranadive #define PVRDMA_UAR_HANDLE_MASK		0x00FFFFFF	/* Bottom 24 bits. */
5429c8d9ebSAdit Ranadive #define PVRDMA_UAR_QP_OFFSET		0		/* QP doorbell. */
55d2acafeaSBryan Tan #define PVRDMA_UAR_QP_SEND		(1 << 30)	/* Send bit. */
56d2acafeaSBryan Tan #define PVRDMA_UAR_QP_RECV		(1 << 31)	/* Recv bit. */
5729c8d9ebSAdit Ranadive #define PVRDMA_UAR_CQ_OFFSET		4		/* CQ doorbell. */
58d2acafeaSBryan Tan #define PVRDMA_UAR_CQ_ARM_SOL		(1 << 29)	/* Arm solicited bit. */
59d2acafeaSBryan Tan #define PVRDMA_UAR_CQ_ARM		(1 << 30)	/* Arm bit. */
60d2acafeaSBryan Tan #define PVRDMA_UAR_CQ_POLL		(1 << 31)	/* Poll bit. */
61926aae27SBryan Tan #define PVRDMA_UAR_SRQ_OFFSET		8		/* SRQ doorbell. */
62d2acafeaSBryan Tan #define PVRDMA_UAR_SRQ_RECV		(1 << 30)	/* Recv bit. */
6329c8d9ebSAdit Ranadive 
6429c8d9ebSAdit Ranadive enum pvrdma_wr_opcode {
6529c8d9ebSAdit Ranadive 	PVRDMA_WR_RDMA_WRITE,
6629c8d9ebSAdit Ranadive 	PVRDMA_WR_RDMA_WRITE_WITH_IMM,
6729c8d9ebSAdit Ranadive 	PVRDMA_WR_SEND,
6829c8d9ebSAdit Ranadive 	PVRDMA_WR_SEND_WITH_IMM,
6929c8d9ebSAdit Ranadive 	PVRDMA_WR_RDMA_READ,
7029c8d9ebSAdit Ranadive 	PVRDMA_WR_ATOMIC_CMP_AND_SWP,
7129c8d9ebSAdit Ranadive 	PVRDMA_WR_ATOMIC_FETCH_AND_ADD,
7229c8d9ebSAdit Ranadive 	PVRDMA_WR_LSO,
7329c8d9ebSAdit Ranadive 	PVRDMA_WR_SEND_WITH_INV,
7429c8d9ebSAdit Ranadive 	PVRDMA_WR_RDMA_READ_WITH_INV,
7529c8d9ebSAdit Ranadive 	PVRDMA_WR_LOCAL_INV,
7629c8d9ebSAdit Ranadive 	PVRDMA_WR_FAST_REG_MR,
7729c8d9ebSAdit Ranadive 	PVRDMA_WR_MASKED_ATOMIC_CMP_AND_SWP,
7829c8d9ebSAdit Ranadive 	PVRDMA_WR_MASKED_ATOMIC_FETCH_AND_ADD,
7929c8d9ebSAdit Ranadive 	PVRDMA_WR_BIND_MW,
8029c8d9ebSAdit Ranadive 	PVRDMA_WR_REG_SIG_MR,
8129c8d9ebSAdit Ranadive };
8229c8d9ebSAdit Ranadive 
8329c8d9ebSAdit Ranadive enum pvrdma_wc_status {
8429c8d9ebSAdit Ranadive 	PVRDMA_WC_SUCCESS,
8529c8d9ebSAdit Ranadive 	PVRDMA_WC_LOC_LEN_ERR,
8629c8d9ebSAdit Ranadive 	PVRDMA_WC_LOC_QP_OP_ERR,
8729c8d9ebSAdit Ranadive 	PVRDMA_WC_LOC_EEC_OP_ERR,
8829c8d9ebSAdit Ranadive 	PVRDMA_WC_LOC_PROT_ERR,
8929c8d9ebSAdit Ranadive 	PVRDMA_WC_WR_FLUSH_ERR,
9029c8d9ebSAdit Ranadive 	PVRDMA_WC_MW_BIND_ERR,
9129c8d9ebSAdit Ranadive 	PVRDMA_WC_BAD_RESP_ERR,
9229c8d9ebSAdit Ranadive 	PVRDMA_WC_LOC_ACCESS_ERR,
9329c8d9ebSAdit Ranadive 	PVRDMA_WC_REM_INV_REQ_ERR,
9429c8d9ebSAdit Ranadive 	PVRDMA_WC_REM_ACCESS_ERR,
9529c8d9ebSAdit Ranadive 	PVRDMA_WC_REM_OP_ERR,
9629c8d9ebSAdit Ranadive 	PVRDMA_WC_RETRY_EXC_ERR,
9729c8d9ebSAdit Ranadive 	PVRDMA_WC_RNR_RETRY_EXC_ERR,
9829c8d9ebSAdit Ranadive 	PVRDMA_WC_LOC_RDD_VIOL_ERR,
9929c8d9ebSAdit Ranadive 	PVRDMA_WC_REM_INV_RD_REQ_ERR,
10029c8d9ebSAdit Ranadive 	PVRDMA_WC_REM_ABORT_ERR,
10129c8d9ebSAdit Ranadive 	PVRDMA_WC_INV_EECN_ERR,
10229c8d9ebSAdit Ranadive 	PVRDMA_WC_INV_EEC_STATE_ERR,
10329c8d9ebSAdit Ranadive 	PVRDMA_WC_FATAL_ERR,
10429c8d9ebSAdit Ranadive 	PVRDMA_WC_RESP_TIMEOUT_ERR,
10529c8d9ebSAdit Ranadive 	PVRDMA_WC_GENERAL_ERR,
10629c8d9ebSAdit Ranadive };
10729c8d9ebSAdit Ranadive 
10829c8d9ebSAdit Ranadive enum pvrdma_wc_opcode {
10929c8d9ebSAdit Ranadive 	PVRDMA_WC_SEND,
11029c8d9ebSAdit Ranadive 	PVRDMA_WC_RDMA_WRITE,
11129c8d9ebSAdit Ranadive 	PVRDMA_WC_RDMA_READ,
11229c8d9ebSAdit Ranadive 	PVRDMA_WC_COMP_SWAP,
11329c8d9ebSAdit Ranadive 	PVRDMA_WC_FETCH_ADD,
11429c8d9ebSAdit Ranadive 	PVRDMA_WC_BIND_MW,
11529c8d9ebSAdit Ranadive 	PVRDMA_WC_LSO,
11629c8d9ebSAdit Ranadive 	PVRDMA_WC_LOCAL_INV,
11729c8d9ebSAdit Ranadive 	PVRDMA_WC_FAST_REG_MR,
11829c8d9ebSAdit Ranadive 	PVRDMA_WC_MASKED_COMP_SWAP,
11929c8d9ebSAdit Ranadive 	PVRDMA_WC_MASKED_FETCH_ADD,
12029c8d9ebSAdit Ranadive 	PVRDMA_WC_RECV = 1 << 7,
12129c8d9ebSAdit Ranadive 	PVRDMA_WC_RECV_RDMA_WITH_IMM,
12229c8d9ebSAdit Ranadive };
12329c8d9ebSAdit Ranadive 
12429c8d9ebSAdit Ranadive enum pvrdma_wc_flags {
12529c8d9ebSAdit Ranadive 	PVRDMA_WC_GRH			= 1 << 0,
12629c8d9ebSAdit Ranadive 	PVRDMA_WC_WITH_IMM		= 1 << 1,
12729c8d9ebSAdit Ranadive 	PVRDMA_WC_WITH_INVALIDATE	= 1 << 2,
12829c8d9ebSAdit Ranadive 	PVRDMA_WC_IP_CSUM_OK		= 1 << 3,
12929c8d9ebSAdit Ranadive 	PVRDMA_WC_WITH_SMAC		= 1 << 4,
13029c8d9ebSAdit Ranadive 	PVRDMA_WC_WITH_VLAN		= 1 << 5,
13172f9b089SAditya Sarwade 	PVRDMA_WC_WITH_NETWORK_HDR_TYPE	= 1 << 6,
13272f9b089SAditya Sarwade 	PVRDMA_WC_FLAGS_MAX		= PVRDMA_WC_WITH_NETWORK_HDR_TYPE,
13329c8d9ebSAdit Ranadive };
13429c8d9ebSAdit Ranadive 
13529c8d9ebSAdit Ranadive struct pvrdma_alloc_ucontext_resp {
13629c8d9ebSAdit Ranadive 	__u32 qp_tab_size;
13729c8d9ebSAdit Ranadive 	__u32 reserved;
13829c8d9ebSAdit Ranadive };
13929c8d9ebSAdit Ranadive 
14029c8d9ebSAdit Ranadive struct pvrdma_alloc_pd_resp {
14129c8d9ebSAdit Ranadive 	__u32 pdn;
14229c8d9ebSAdit Ranadive 	__u32 reserved;
14329c8d9ebSAdit Ranadive };
14429c8d9ebSAdit Ranadive 
14529c8d9ebSAdit Ranadive struct pvrdma_create_cq {
14626b99066SJason Gunthorpe 	__aligned_u64 buf_addr;
14729c8d9ebSAdit Ranadive 	__u32 buf_size;
14829c8d9ebSAdit Ranadive 	__u32 reserved;
14929c8d9ebSAdit Ranadive };
15029c8d9ebSAdit Ranadive 
15129c8d9ebSAdit Ranadive struct pvrdma_create_cq_resp {
15229c8d9ebSAdit Ranadive 	__u32 cqn;
15329c8d9ebSAdit Ranadive 	__u32 reserved;
15429c8d9ebSAdit Ranadive };
15529c8d9ebSAdit Ranadive 
15629c8d9ebSAdit Ranadive struct pvrdma_resize_cq {
15726b99066SJason Gunthorpe 	__aligned_u64 buf_addr;
15829c8d9ebSAdit Ranadive 	__u32 buf_size;
15929c8d9ebSAdit Ranadive 	__u32 reserved;
16029c8d9ebSAdit Ranadive };
16129c8d9ebSAdit Ranadive 
16229c8d9ebSAdit Ranadive struct pvrdma_create_srq {
16326b99066SJason Gunthorpe 	__aligned_u64 buf_addr;
1648b10ba78SBryan Tan 	__u32 buf_size;
1658b10ba78SBryan Tan 	__u32 reserved;
16629c8d9ebSAdit Ranadive };
16729c8d9ebSAdit Ranadive 
16829c8d9ebSAdit Ranadive struct pvrdma_create_srq_resp {
16929c8d9ebSAdit Ranadive 	__u32 srqn;
17029c8d9ebSAdit Ranadive 	__u32 reserved;
17129c8d9ebSAdit Ranadive };
17229c8d9ebSAdit Ranadive 
17329c8d9ebSAdit Ranadive struct pvrdma_create_qp {
17426b99066SJason Gunthorpe 	__aligned_u64 rbuf_addr;
17526b99066SJason Gunthorpe 	__aligned_u64 sbuf_addr;
17629c8d9ebSAdit Ranadive 	__u32 rbuf_size;
17729c8d9ebSAdit Ranadive 	__u32 sbuf_size;
17826b99066SJason Gunthorpe 	__aligned_u64 qp_addr;
17929c8d9ebSAdit Ranadive };
18029c8d9ebSAdit Ranadive 
18129c8d9ebSAdit Ranadive /* PVRDMA masked atomic compare and swap */
18229c8d9ebSAdit Ranadive struct pvrdma_ex_cmp_swap {
18326b99066SJason Gunthorpe 	__aligned_u64 swap_val;
18426b99066SJason Gunthorpe 	__aligned_u64 compare_val;
18526b99066SJason Gunthorpe 	__aligned_u64 swap_mask;
18626b99066SJason Gunthorpe 	__aligned_u64 compare_mask;
18729c8d9ebSAdit Ranadive };
18829c8d9ebSAdit Ranadive 
18929c8d9ebSAdit Ranadive /* PVRDMA masked atomic fetch and add */
19029c8d9ebSAdit Ranadive struct pvrdma_ex_fetch_add {
19126b99066SJason Gunthorpe 	__aligned_u64 add_val;
19226b99066SJason Gunthorpe 	__aligned_u64 field_boundary;
19329c8d9ebSAdit Ranadive };
19429c8d9ebSAdit Ranadive 
19529c8d9ebSAdit Ranadive /* PVRDMA address vector. */
19629c8d9ebSAdit Ranadive struct pvrdma_av {
19729c8d9ebSAdit Ranadive 	__u32 port_pd;
19829c8d9ebSAdit Ranadive 	__u32 sl_tclass_flowlabel;
19929c8d9ebSAdit Ranadive 	__u8 dgid[16];
20029c8d9ebSAdit Ranadive 	__u8 src_path_bits;
20129c8d9ebSAdit Ranadive 	__u8 gid_index;
20229c8d9ebSAdit Ranadive 	__u8 stat_rate;
20329c8d9ebSAdit Ranadive 	__u8 hop_limit;
20429c8d9ebSAdit Ranadive 	__u8 dmac[6];
20529c8d9ebSAdit Ranadive 	__u8 reserved[6];
20629c8d9ebSAdit Ranadive };
20729c8d9ebSAdit Ranadive 
20829c8d9ebSAdit Ranadive /* PVRDMA scatter/gather entry */
20929c8d9ebSAdit Ranadive struct pvrdma_sge {
21026b99066SJason Gunthorpe 	__aligned_u64 addr;
21129c8d9ebSAdit Ranadive 	__u32   length;
21229c8d9ebSAdit Ranadive 	__u32   lkey;
21329c8d9ebSAdit Ranadive };
21429c8d9ebSAdit Ranadive 
21529c8d9ebSAdit Ranadive /* PVRDMA receive queue work request */
21629c8d9ebSAdit Ranadive struct pvrdma_rq_wqe_hdr {
21726b99066SJason Gunthorpe 	__aligned_u64 wr_id;		/* wr id */
21829c8d9ebSAdit Ranadive 	__u32 num_sge;		/* size of s/g array */
21929c8d9ebSAdit Ranadive 	__u32 total_len;	/* reserved */
22029c8d9ebSAdit Ranadive };
22129c8d9ebSAdit Ranadive /* Use pvrdma_sge (ib_sge) for receive queue s/g array elements. */
22229c8d9ebSAdit Ranadive 
22329c8d9ebSAdit Ranadive /* PVRDMA send queue work request */
22429c8d9ebSAdit Ranadive struct pvrdma_sq_wqe_hdr {
22526b99066SJason Gunthorpe 	__aligned_u64 wr_id;		/* wr id */
22629c8d9ebSAdit Ranadive 	__u32 num_sge;		/* size of s/g array */
22729c8d9ebSAdit Ranadive 	__u32 total_len;	/* reserved */
22829c8d9ebSAdit Ranadive 	__u32 opcode;		/* operation type */
22929c8d9ebSAdit Ranadive 	__u32 send_flags;	/* wr flags */
23029c8d9ebSAdit Ranadive 	union {
231cc47dd68SJason Gunthorpe 		__be32 imm_data;
23229c8d9ebSAdit Ranadive 		__u32 invalidate_rkey;
23329c8d9ebSAdit Ranadive 	} ex;
23429c8d9ebSAdit Ranadive 	__u32 reserved;
23529c8d9ebSAdit Ranadive 	union {
23629c8d9ebSAdit Ranadive 		struct {
23726b99066SJason Gunthorpe 			__aligned_u64 remote_addr;
23829c8d9ebSAdit Ranadive 			__u32 rkey;
23929c8d9ebSAdit Ranadive 			__u8 reserved[4];
24029c8d9ebSAdit Ranadive 		} rdma;
24129c8d9ebSAdit Ranadive 		struct {
24226b99066SJason Gunthorpe 			__aligned_u64 remote_addr;
24326b99066SJason Gunthorpe 			__aligned_u64 compare_add;
24426b99066SJason Gunthorpe 			__aligned_u64 swap;
24529c8d9ebSAdit Ranadive 			__u32 rkey;
24629c8d9ebSAdit Ranadive 			__u32 reserved;
24729c8d9ebSAdit Ranadive 		} atomic;
24829c8d9ebSAdit Ranadive 		struct {
24926b99066SJason Gunthorpe 			__aligned_u64 remote_addr;
25029c8d9ebSAdit Ranadive 			__u32 log_arg_sz;
25129c8d9ebSAdit Ranadive 			__u32 rkey;
25229c8d9ebSAdit Ranadive 			union {
25329c8d9ebSAdit Ranadive 				struct pvrdma_ex_cmp_swap  cmp_swap;
25429c8d9ebSAdit Ranadive 				struct pvrdma_ex_fetch_add fetch_add;
25529c8d9ebSAdit Ranadive 			} wr_data;
25629c8d9ebSAdit Ranadive 		} masked_atomics;
25729c8d9ebSAdit Ranadive 		struct {
25826b99066SJason Gunthorpe 			__aligned_u64 iova_start;
25926b99066SJason Gunthorpe 			__aligned_u64 pl_pdir_dma;
26029c8d9ebSAdit Ranadive 			__u32 page_shift;
26129c8d9ebSAdit Ranadive 			__u32 page_list_len;
26229c8d9ebSAdit Ranadive 			__u32 length;
26329c8d9ebSAdit Ranadive 			__u32 access_flags;
26429c8d9ebSAdit Ranadive 			__u32 rkey;
26538b48808SJason Gunthorpe 			__u32 reserved;
26629c8d9ebSAdit Ranadive 		} fast_reg;
26729c8d9ebSAdit Ranadive 		struct {
26829c8d9ebSAdit Ranadive 			__u32 remote_qpn;
26929c8d9ebSAdit Ranadive 			__u32 remote_qkey;
27029c8d9ebSAdit Ranadive 			struct pvrdma_av av;
27129c8d9ebSAdit Ranadive 		} ud;
27229c8d9ebSAdit Ranadive 	} wr;
27329c8d9ebSAdit Ranadive };
27429c8d9ebSAdit Ranadive /* Use pvrdma_sge (ib_sge) for send queue s/g array elements. */
27529c8d9ebSAdit Ranadive 
27629c8d9ebSAdit Ranadive /* Completion queue element. */
27729c8d9ebSAdit Ranadive struct pvrdma_cqe {
27826b99066SJason Gunthorpe 	__aligned_u64 wr_id;
27926b99066SJason Gunthorpe 	__aligned_u64 qp;
28029c8d9ebSAdit Ranadive 	__u32 opcode;
28129c8d9ebSAdit Ranadive 	__u32 status;
28229c8d9ebSAdit Ranadive 	__u32 byte_len;
283cc47dd68SJason Gunthorpe 	__be32 imm_data;
28429c8d9ebSAdit Ranadive 	__u32 src_qp;
28529c8d9ebSAdit Ranadive 	__u32 wc_flags;
28629c8d9ebSAdit Ranadive 	__u32 vendor_err;
28729c8d9ebSAdit Ranadive 	__u16 pkey_index;
28829c8d9ebSAdit Ranadive 	__u16 slid;
28929c8d9ebSAdit Ranadive 	__u8 sl;
29029c8d9ebSAdit Ranadive 	__u8 dlid_path_bits;
29129c8d9ebSAdit Ranadive 	__u8 port_num;
29229c8d9ebSAdit Ranadive 	__u8 smac[6];
29372f9b089SAditya Sarwade 	__u8 network_hdr_type;
29472f9b089SAditya Sarwade 	__u8 reserved2[6]; /* Pad to next power of 2 (64). */
29529c8d9ebSAdit Ranadive };
29629c8d9ebSAdit Ranadive 
29729c8d9ebSAdit Ranadive #endif /* __VMW_PVRDMA_ABI_H__ */
298