xref: /linux/include/uapi/rdma/rdma_user_rxe.h (revision 353b7a55dcaf5fb8758e09ebe2ddf5f3adbac7c5)
1d50e14abSJason Gunthorpe /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR Linux-OpenIB) */
28700e3e7SMoni Shoua /*
38700e3e7SMoni Shoua  * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
48700e3e7SMoni Shoua  *
58700e3e7SMoni Shoua  * This software is available to you under a choice of one of two
68700e3e7SMoni Shoua  * licenses.  You may choose to be licensed under the terms of the GNU
78700e3e7SMoni Shoua  * General Public License (GPL) Version 2, available from the file
88700e3e7SMoni Shoua  * COPYING in the main directory of this source tree, or the
98700e3e7SMoni Shoua  * OpenIB.org BSD license below:
108700e3e7SMoni Shoua  *
118700e3e7SMoni Shoua  *     Redistribution and use in source and binary forms, with or
128700e3e7SMoni Shoua  *     without modification, are permitted provided that the following
138700e3e7SMoni Shoua  *     conditions are met:
148700e3e7SMoni Shoua  *
158700e3e7SMoni Shoua  *	- Redistributions of source code must retain the above
168700e3e7SMoni Shoua  *	  copyright notice, this list of conditions and the following
178700e3e7SMoni Shoua  *	  disclaimer.
188700e3e7SMoni Shoua  *
198700e3e7SMoni Shoua  *	- Redistributions in binary form must reproduce the above
208700e3e7SMoni Shoua  *	  copyright notice, this list of conditions and the following
218700e3e7SMoni Shoua  *	  disclaimer in the documentation and/or other materials
228700e3e7SMoni Shoua  *	  provided with the distribution.
238700e3e7SMoni Shoua  *
248700e3e7SMoni Shoua  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
258700e3e7SMoni Shoua  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
268700e3e7SMoni Shoua  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
278700e3e7SMoni Shoua  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
288700e3e7SMoni Shoua  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
298700e3e7SMoni Shoua  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
308700e3e7SMoni Shoua  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
318700e3e7SMoni Shoua  * SOFTWARE.
328700e3e7SMoni Shoua  */
338700e3e7SMoni Shoua 
348700e3e7SMoni Shoua #ifndef RDMA_USER_RXE_H
358700e3e7SMoni Shoua #define RDMA_USER_RXE_H
368700e3e7SMoni Shoua 
378700e3e7SMoni Shoua #include <linux/types.h>
387061f28dSJason Gunthorpe #include <linux/socket.h>
397061f28dSJason Gunthorpe #include <linux/in.h>
407061f28dSJason Gunthorpe #include <linux/in6.h>
418700e3e7SMoni Shoua 
42e0d696d2SJason Gunthorpe enum {
43e0d696d2SJason Gunthorpe 	RXE_NETWORK_TYPE_IPV4 = 1,
44e0d696d2SJason Gunthorpe 	RXE_NETWORK_TYPE_IPV6 = 2,
45e0d696d2SJason Gunthorpe };
46e0d696d2SJason Gunthorpe 
478700e3e7SMoni Shoua union rxe_gid {
488700e3e7SMoni Shoua 	__u8	raw[16];
498700e3e7SMoni Shoua 	struct {
508700e3e7SMoni Shoua 		__be64	subnet_prefix;
518700e3e7SMoni Shoua 		__be64	interface_id;
528700e3e7SMoni Shoua 	} global;
538700e3e7SMoni Shoua };
548700e3e7SMoni Shoua 
558700e3e7SMoni Shoua struct rxe_global_route {
568700e3e7SMoni Shoua 	union rxe_gid	dgid;
578700e3e7SMoni Shoua 	__u32		flow_label;
588700e3e7SMoni Shoua 	__u8		sgid_index;
598700e3e7SMoni Shoua 	__u8		hop_limit;
608700e3e7SMoni Shoua 	__u8		traffic_class;
618700e3e7SMoni Shoua };
628700e3e7SMoni Shoua 
638700e3e7SMoni Shoua struct rxe_av {
648700e3e7SMoni Shoua 	__u8			port_num;
65e0d696d2SJason Gunthorpe 	/* From RXE_NETWORK_TYPE_* */
668700e3e7SMoni Shoua 	__u8			network_type;
67668aa15bSKamal Heib 	__u8			dmac[6];
688700e3e7SMoni Shoua 	struct rxe_global_route	grh;
698700e3e7SMoni Shoua 	union {
708700e3e7SMoni Shoua 		struct sockaddr_in	_sockaddr_in;
718700e3e7SMoni Shoua 		struct sockaddr_in6	_sockaddr_in6;
728700e3e7SMoni Shoua 	} sgid_addr, dgid_addr;
738700e3e7SMoni Shoua };
748700e3e7SMoni Shoua 
758700e3e7SMoni Shoua struct rxe_send_wr {
7626b99066SJason Gunthorpe 	__aligned_u64		wr_id;
778700e3e7SMoni Shoua 	__u32			num_sge;
788700e3e7SMoni Shoua 	__u32			opcode;
798700e3e7SMoni Shoua 	__u32			send_flags;
808700e3e7SMoni Shoua 	union {
818700e3e7SMoni Shoua 		__be32		imm_data;
828700e3e7SMoni Shoua 		__u32		invalidate_rkey;
838700e3e7SMoni Shoua 	} ex;
848700e3e7SMoni Shoua 	union {
858700e3e7SMoni Shoua 		struct {
8626b99066SJason Gunthorpe 			__aligned_u64 remote_addr;
878700e3e7SMoni Shoua 			__u32	rkey;
8838b48808SJason Gunthorpe 			__u32	reserved;
898700e3e7SMoni Shoua 		} rdma;
908700e3e7SMoni Shoua 		struct {
9126b99066SJason Gunthorpe 			__aligned_u64 remote_addr;
9226b99066SJason Gunthorpe 			__aligned_u64 compare_add;
9326b99066SJason Gunthorpe 			__aligned_u64 swap;
948700e3e7SMoni Shoua 			__u32	rkey;
9538b48808SJason Gunthorpe 			__u32	reserved;
968700e3e7SMoni Shoua 		} atomic;
978700e3e7SMoni Shoua 		struct {
988700e3e7SMoni Shoua 			__u32	remote_qpn;
998700e3e7SMoni Shoua 			__u32	remote_qkey;
1008700e3e7SMoni Shoua 			__u16	pkey_index;
1018700e3e7SMoni Shoua 		} ud;
102*660a5936SBob Pearson 		struct {
103*660a5936SBob Pearson 			__aligned_u64	addr;
104*660a5936SBob Pearson 			__aligned_u64	length;
105*660a5936SBob Pearson 			__u32		mr_lkey;
106*660a5936SBob Pearson 			__u32		mw_rkey;
107*660a5936SBob Pearson 			__u32		rkey;
108*660a5936SBob Pearson 			__u32		access;
109*660a5936SBob Pearson 		} mw;
110f2e9bfacSJason Gunthorpe 		/* reg is only used by the kernel and is not part of the uapi */
111*660a5936SBob Pearson #ifdef __KERNEL__
1128700e3e7SMoni Shoua 		struct {
113f2e9bfacSJason Gunthorpe 			union {
1148700e3e7SMoni Shoua 				struct ib_mr *mr;
11526b99066SJason Gunthorpe 				__aligned_u64 reserved;
116f2e9bfacSJason Gunthorpe 			};
1178700e3e7SMoni Shoua 			__u32	     key;
118f2e9bfacSJason Gunthorpe 			__u32	     access;
1198700e3e7SMoni Shoua 		} reg;
120*660a5936SBob Pearson #endif
1218700e3e7SMoni Shoua 	} wr;
1228700e3e7SMoni Shoua };
1238700e3e7SMoni Shoua 
1248700e3e7SMoni Shoua struct rxe_sge {
12526b99066SJason Gunthorpe 	__aligned_u64 addr;
1268700e3e7SMoni Shoua 	__u32	length;
1278700e3e7SMoni Shoua 	__u32	lkey;
1288700e3e7SMoni Shoua };
1298700e3e7SMoni Shoua 
1308700e3e7SMoni Shoua struct mminfo {
13126b99066SJason Gunthorpe 	__aligned_u64		offset;
1328700e3e7SMoni Shoua 	__u32			size;
1338700e3e7SMoni Shoua 	__u32			pad;
1348700e3e7SMoni Shoua };
1358700e3e7SMoni Shoua 
1368700e3e7SMoni Shoua struct rxe_dma_info {
1378700e3e7SMoni Shoua 	__u32			length;
1388700e3e7SMoni Shoua 	__u32			resid;
1398700e3e7SMoni Shoua 	__u32			cur_sge;
1408700e3e7SMoni Shoua 	__u32			num_sge;
1418700e3e7SMoni Shoua 	__u32			sge_offset;
142f2e9bfacSJason Gunthorpe 	__u32			reserved;
1438700e3e7SMoni Shoua 	union {
1448700e3e7SMoni Shoua 		__u8		inline_data[0];
1458700e3e7SMoni Shoua 		struct rxe_sge	sge[0];
1468700e3e7SMoni Shoua 	};
1478700e3e7SMoni Shoua };
1488700e3e7SMoni Shoua 
1498700e3e7SMoni Shoua struct rxe_send_wqe {
1508700e3e7SMoni Shoua 	struct rxe_send_wr	wr;
1518700e3e7SMoni Shoua 	struct rxe_av		av;
1528700e3e7SMoni Shoua 	__u32			status;
1538700e3e7SMoni Shoua 	__u32			state;
15426b99066SJason Gunthorpe 	__aligned_u64		iova;
1558700e3e7SMoni Shoua 	__u32			mask;
1568700e3e7SMoni Shoua 	__u32			first_psn;
1578700e3e7SMoni Shoua 	__u32			last_psn;
1588700e3e7SMoni Shoua 	__u32			ack_length;
1598700e3e7SMoni Shoua 	__u32			ssn;
1608700e3e7SMoni Shoua 	__u32			has_rd_atomic;
1618700e3e7SMoni Shoua 	struct rxe_dma_info	dma;
1628700e3e7SMoni Shoua };
1638700e3e7SMoni Shoua 
1648700e3e7SMoni Shoua struct rxe_recv_wqe {
16526b99066SJason Gunthorpe 	__aligned_u64		wr_id;
1668700e3e7SMoni Shoua 	__u32			num_sge;
1678700e3e7SMoni Shoua 	__u32			padding;
1688700e3e7SMoni Shoua 	struct rxe_dma_info	dma;
1698700e3e7SMoni Shoua };
1708700e3e7SMoni Shoua 
1710c43ab37SJason Gunthorpe struct rxe_create_cq_resp {
1720c43ab37SJason Gunthorpe 	struct mminfo mi;
1730c43ab37SJason Gunthorpe };
1740c43ab37SJason Gunthorpe 
1750c43ab37SJason Gunthorpe struct rxe_resize_cq_resp {
1760c43ab37SJason Gunthorpe 	struct mminfo mi;
1770c43ab37SJason Gunthorpe };
1780c43ab37SJason Gunthorpe 
1790c43ab37SJason Gunthorpe struct rxe_create_qp_resp {
1800c43ab37SJason Gunthorpe 	struct mminfo rq_mi;
1810c43ab37SJason Gunthorpe 	struct mminfo sq_mi;
1820c43ab37SJason Gunthorpe };
1830c43ab37SJason Gunthorpe 
1840c43ab37SJason Gunthorpe struct rxe_create_srq_resp {
1850c43ab37SJason Gunthorpe 	struct mminfo mi;
1860c43ab37SJason Gunthorpe 	__u32 srq_num;
187f2e9bfacSJason Gunthorpe 	__u32 reserved;
1880c43ab37SJason Gunthorpe };
1890c43ab37SJason Gunthorpe 
1900c43ab37SJason Gunthorpe struct rxe_modify_srq_cmd {
19126b99066SJason Gunthorpe 	__aligned_u64 mmap_info_addr;
1920c43ab37SJason Gunthorpe };
1930c43ab37SJason Gunthorpe 
194d21a1240SBob Pearson /* This data structure is stored at the base of work and
195d21a1240SBob Pearson  * completion queues shared between user space and kernel space.
196d21a1240SBob Pearson  * It contains the producer and consumer indices. Is also
197d21a1240SBob Pearson  * contains a copy of the queue size parameters for user space
198d21a1240SBob Pearson  * to use but the kernel must use the parameters in the
199d21a1240SBob Pearson  * rxe_queue struct. For performance reasons arrange to have
200d21a1240SBob Pearson  * producer and consumer indices in separate cache lines
201d21a1240SBob Pearson  * the kernel should always mask the indices to avoid accessing
202d21a1240SBob Pearson  * memory outside of the data area
203d21a1240SBob Pearson  */
204d21a1240SBob Pearson struct rxe_queue_buf {
205d21a1240SBob Pearson 	__u32			log2_elem_size;
206d21a1240SBob Pearson 	__u32			index_mask;
207d21a1240SBob Pearson 	__u32			pad_1[30];
208d21a1240SBob Pearson 	__u32			producer_index;
209d21a1240SBob Pearson 	__u32			pad_2[31];
210d21a1240SBob Pearson 	__u32			consumer_index;
211d21a1240SBob Pearson 	__u32			pad_3[31];
212d21a1240SBob Pearson 	__u8			data[];
213d21a1240SBob Pearson };
214d21a1240SBob Pearson 
2158700e3e7SMoni Shoua #endif /* RDMA_USER_RXE_H */
216