1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
3 * Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
9 #include <linux/bitops.h>
10 #include <linux/interrupt.h>
11 #include <linux/pci.h>
13 #include <rdma/efa-abi.h>
14 #include <rdma/ib_verbs.h>
16 #include "efa_com_cmd.h"
18 #define DRV_MODULE_NAME "efa"
19 #define DEVICE_NAME "Elastic Fabric Adapter (EFA)"
21 #define EFA_IRQNAME_SIZE 40
23 #define EFA_MGMNT_MSIX_VEC_IDX 0
24 #define EFA_COMP_EQS_VEC_BASE 1
27 irq_handler_t handler
;
31 cpumask_t affinity_hint_mask
;
32 char name
[EFA_IRQNAME_SIZE
];
35 /* Don't use anything other than atomic64 */
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
;
44 atomic64_t keep_alive_rcvd
;
48 struct ib_device ibdev
;
49 struct efa_com_dev edev
;
51 struct efa_com_get_device_attr_result dev_attr
;
60 unsigned int num_irq_vectors
;
61 int admin_msix_vector_idx
;
62 struct efa_irq admin_irq
;
64 struct efa_stats stats
;
66 /* Array of completion EQs */
70 /* Only stores CQs with interrupts enabled */
75 struct ib_ucontext ibucontext
;
84 struct efa_mr_interconnect_info
{
88 u8 recv_ic_id_valid
: 1;
89 u8 rdma_read_ic_id_valid
: 1;
90 u8 rdma_recv_ic_id_valid
: 1;
96 struct efa_mr_interconnect_info ic_info
;
101 struct efa_ucontext
*ucontext
;
104 struct rdma_user_mmap_entry
*mmap_entry
;
105 struct rdma_user_mmap_entry
*db_mmap_entry
;
108 /* NULL when no interrupts requested */
114 dma_addr_t rq_dma_addr
;
117 enum ib_qp_state state
;
119 /* Used for saving mmap_xa entries */
120 struct rdma_user_mmap_entry
*sq_db_mmap_entry
;
121 struct rdma_user_mmap_entry
*llq_desc_mmap_entry
;
122 struct rdma_user_mmap_entry
*rq_db_mmap_entry
;
123 struct rdma_user_mmap_entry
*rq_mmap_entry
;
141 struct efa_com_eq eeq
;
145 int efa_query_device(struct ib_device
*ibdev
,
146 struct ib_device_attr
*props
,
147 struct ib_udata
*udata
);
148 int efa_query_port(struct ib_device
*ibdev
, u32 port
,
149 struct ib_port_attr
*props
);
150 int efa_query_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*qp_attr
,
152 struct ib_qp_init_attr
*qp_init_attr
);
153 int efa_query_gid(struct ib_device
*ibdev
, u32 port
, int index
,
155 int efa_query_pkey(struct ib_device
*ibdev
, u32 port
, u16 index
,
157 int efa_alloc_pd(struct ib_pd
*ibpd
, struct ib_udata
*udata
);
158 int efa_dealloc_pd(struct ib_pd
*ibpd
, struct ib_udata
*udata
);
159 int efa_destroy_qp(struct ib_qp
*ibqp
, struct ib_udata
*udata
);
160 int efa_create_qp(struct ib_qp
*ibqp
, struct ib_qp_init_attr
*init_attr
,
161 struct ib_udata
*udata
);
162 int efa_destroy_cq(struct ib_cq
*ibcq
, struct ib_udata
*udata
);
163 int efa_create_cq(struct ib_cq
*ibcq
, const struct ib_cq_init_attr
*attr
,
164 struct uverbs_attr_bundle
*attrs
);
165 struct ib_mr
*efa_reg_mr(struct ib_pd
*ibpd
, u64 start
, u64 length
,
166 u64 virt_addr
, int access_flags
,
167 struct ib_udata
*udata
);
168 struct ib_mr
*efa_reg_user_mr_dmabuf(struct ib_pd
*ibpd
, u64 start
,
169 u64 length
, u64 virt_addr
,
170 int fd
, int access_flags
,
171 struct uverbs_attr_bundle
*attrs
);
172 int efa_dereg_mr(struct ib_mr
*ibmr
, struct ib_udata
*udata
);
173 int efa_get_port_immutable(struct ib_device
*ibdev
, u32 port_num
,
174 struct ib_port_immutable
*immutable
);
175 int efa_alloc_ucontext(struct ib_ucontext
*ibucontext
, struct ib_udata
*udata
);
176 void efa_dealloc_ucontext(struct ib_ucontext
*ibucontext
);
177 int efa_mmap(struct ib_ucontext
*ibucontext
,
178 struct vm_area_struct
*vma
);
179 void efa_mmap_free(struct rdma_user_mmap_entry
*rdma_entry
);
180 int efa_create_ah(struct ib_ah
*ibah
,
181 struct rdma_ah_init_attr
*init_attr
,
182 struct ib_udata
*udata
);
183 int efa_destroy_ah(struct ib_ah
*ibah
, u32 flags
);
184 int efa_modify_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*qp_attr
,
185 int qp_attr_mask
, struct ib_udata
*udata
);
186 enum rdma_link_layer
efa_port_link_layer(struct ib_device
*ibdev
,
188 struct rdma_hw_stats
*efa_alloc_hw_port_stats(struct ib_device
*ibdev
, u32 port_num
);
189 struct rdma_hw_stats
*efa_alloc_hw_device_stats(struct ib_device
*ibdev
);
190 int efa_get_hw_stats(struct ib_device
*ibdev
, struct rdma_hw_stats
*stats
,
191 u32 port_num
, int index
);