xref: /openbmc/linux/drivers/infiniband/hw/efa/efa.h (revision c8ed9fc9)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
2 /*
3  * Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All rights reserved.
4  */
5 
6 #ifndef _EFA_H_
7 #define _EFA_H_
8 
9 #include <linux/bitops.h>
10 #include <linux/interrupt.h>
11 #include <linux/pci.h>
12 
13 #include <rdma/efa-abi.h>
14 #include <rdma/ib_verbs.h>
15 
16 #include "efa_com_cmd.h"
17 
18 #define DRV_MODULE_NAME         "efa"
19 #define DEVICE_NAME             "Elastic Fabric Adapter (EFA)"
20 
21 #define EFA_IRQNAME_SIZE        40
22 
23 /* 1 for AENQ + ADMIN */
24 #define EFA_NUM_MSIX_VEC                  1
25 #define EFA_MGMNT_MSIX_VEC_IDX            0
26 
27 struct efa_irq {
28 	irq_handler_t handler;
29 	void *data;
30 	int cpu;
31 	u32 vector;
32 	cpumask_t affinity_hint_mask;
33 	char name[EFA_IRQNAME_SIZE];
34 };
35 
36 struct efa_sw_stats {
37 	atomic64_t alloc_pd_err;
38 	atomic64_t create_qp_err;
39 	atomic64_t create_cq_err;
40 	atomic64_t reg_mr_err;
41 	atomic64_t alloc_ucontext_err;
42 	atomic64_t create_ah_err;
43 	atomic64_t mmap_err;
44 };
45 
46 /* Don't use anything other than atomic64 */
47 struct efa_stats {
48 	struct efa_sw_stats sw_stats;
49 	atomic64_t keep_alive_rcvd;
50 };
51 
52 struct efa_dev {
53 	struct ib_device ibdev;
54 	struct efa_com_dev edev;
55 	struct pci_dev *pdev;
56 	struct efa_com_get_device_attr_result dev_attr;
57 
58 	u64 reg_bar_addr;
59 	u64 reg_bar_len;
60 	u64 mem_bar_addr;
61 	u64 mem_bar_len;
62 	u64 db_bar_addr;
63 	u64 db_bar_len;
64 
65 	int admin_msix_vector_idx;
66 	struct efa_irq admin_irq;
67 
68 	struct efa_stats stats;
69 };
70 
71 struct efa_ucontext {
72 	struct ib_ucontext ibucontext;
73 	u16 uarn;
74 };
75 
76 struct efa_pd {
77 	struct ib_pd ibpd;
78 	u16 pdn;
79 };
80 
81 struct efa_mr {
82 	struct ib_mr ibmr;
83 	struct ib_umem *umem;
84 };
85 
86 struct efa_cq {
87 	struct ib_cq ibcq;
88 	struct efa_ucontext *ucontext;
89 	dma_addr_t dma_addr;
90 	void *cpu_addr;
91 	struct rdma_user_mmap_entry *mmap_entry;
92 	size_t size;
93 	u16 cq_idx;
94 };
95 
96 struct efa_qp {
97 	struct ib_qp ibqp;
98 	dma_addr_t rq_dma_addr;
99 	void *rq_cpu_addr;
100 	size_t rq_size;
101 	enum ib_qp_state state;
102 
103 	/* Used for saving mmap_xa entries */
104 	struct rdma_user_mmap_entry *sq_db_mmap_entry;
105 	struct rdma_user_mmap_entry *llq_desc_mmap_entry;
106 	struct rdma_user_mmap_entry *rq_db_mmap_entry;
107 	struct rdma_user_mmap_entry *rq_mmap_entry;
108 
109 	u32 qp_handle;
110 	u32 max_send_wr;
111 	u32 max_recv_wr;
112 	u32 max_send_sge;
113 	u32 max_recv_sge;
114 	u32 max_inline_data;
115 };
116 
117 struct efa_ah {
118 	struct ib_ah ibah;
119 	u16 ah;
120 	/* dest_addr */
121 	u8 id[EFA_GID_SIZE];
122 };
123 
124 int efa_query_device(struct ib_device *ibdev,
125 		     struct ib_device_attr *props,
126 		     struct ib_udata *udata);
127 int efa_query_port(struct ib_device *ibdev, u8 port,
128 		   struct ib_port_attr *props);
129 int efa_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr,
130 		 int qp_attr_mask,
131 		 struct ib_qp_init_attr *qp_init_attr);
132 int efa_query_gid(struct ib_device *ibdev, u8 port, int index,
133 		  union ib_gid *gid);
134 int efa_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
135 		   u16 *pkey);
136 int efa_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata);
137 void efa_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata);
138 int efa_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata);
139 struct ib_qp *efa_create_qp(struct ib_pd *ibpd,
140 			    struct ib_qp_init_attr *init_attr,
141 			    struct ib_udata *udata);
142 void efa_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata);
143 int efa_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
144 		  struct ib_udata *udata);
145 struct ib_mr *efa_reg_mr(struct ib_pd *ibpd, u64 start, u64 length,
146 			 u64 virt_addr, int access_flags,
147 			 struct ib_udata *udata);
148 int efa_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata);
149 int efa_get_port_immutable(struct ib_device *ibdev, u8 port_num,
150 			   struct ib_port_immutable *immutable);
151 int efa_alloc_ucontext(struct ib_ucontext *ibucontext, struct ib_udata *udata);
152 void efa_dealloc_ucontext(struct ib_ucontext *ibucontext);
153 int efa_mmap(struct ib_ucontext *ibucontext,
154 	     struct vm_area_struct *vma);
155 void efa_mmap_free(struct rdma_user_mmap_entry *rdma_entry);
156 int efa_create_ah(struct ib_ah *ibah,
157 		  struct rdma_ah_init_attr *init_attr,
158 		  struct ib_udata *udata);
159 void efa_destroy_ah(struct ib_ah *ibah, u32 flags);
160 int efa_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr,
161 		  int qp_attr_mask, struct ib_udata *udata);
162 enum rdma_link_layer efa_port_link_layer(struct ib_device *ibdev,
163 					 u8 port_num);
164 struct rdma_hw_stats *efa_alloc_hw_stats(struct ib_device *ibdev, u8 port_num);
165 int efa_get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats,
166 		     u8 port_num, int index);
167 
168 #endif /* _EFA_H_ */
169