David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ |
| 2 | /* |
| 3 | * Copyright 2018-2019 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 | }; |
| 44 | |
| 45 | /* Don't use anything other than atomic64 */ |
| 46 | struct efa_stats { |
| 47 | struct efa_sw_stats sw_stats; |
| 48 | atomic64_t keep_alive_rcvd; |
| 49 | }; |
| 50 | |
| 51 | struct efa_dev { |
| 52 | struct ib_device ibdev; |
| 53 | struct efa_com_dev edev; |
| 54 | struct pci_dev *pdev; |
| 55 | struct efa_com_get_device_attr_result dev_attr; |
| 56 | |
| 57 | u64 reg_bar_addr; |
| 58 | u64 reg_bar_len; |
| 59 | u64 mem_bar_addr; |
| 60 | u64 mem_bar_len; |
| 61 | u64 db_bar_addr; |
| 62 | u64 db_bar_len; |
| 63 | u8 addr[EFA_GID_SIZE]; |
| 64 | u32 mtu; |
| 65 | |
| 66 | int admin_msix_vector_idx; |
| 67 | struct efa_irq admin_irq; |
| 68 | |
| 69 | struct efa_stats stats; |
| 70 | }; |
| 71 | |
| 72 | struct efa_ucontext { |
| 73 | struct ib_ucontext ibucontext; |
| 74 | struct xarray mmap_xa; |
| 75 | u32 mmap_xa_page; |
| 76 | u16 uarn; |
| 77 | }; |
| 78 | |
| 79 | struct efa_pd { |
| 80 | struct ib_pd ibpd; |
| 81 | u16 pdn; |
| 82 | }; |
| 83 | |
| 84 | struct efa_mr { |
| 85 | struct ib_mr ibmr; |
| 86 | struct ib_umem *umem; |
| 87 | }; |
| 88 | |
| 89 | struct efa_cq { |
| 90 | struct ib_cq ibcq; |
| 91 | struct efa_ucontext *ucontext; |
| 92 | dma_addr_t dma_addr; |
| 93 | void *cpu_addr; |
| 94 | size_t size; |
| 95 | u16 cq_idx; |
| 96 | }; |
| 97 | |
| 98 | struct efa_qp { |
| 99 | struct ib_qp ibqp; |
| 100 | dma_addr_t rq_dma_addr; |
| 101 | void *rq_cpu_addr; |
| 102 | size_t rq_size; |
| 103 | enum ib_qp_state state; |
| 104 | u32 qp_handle; |
| 105 | u32 max_send_wr; |
| 106 | u32 max_recv_wr; |
| 107 | u32 max_send_sge; |
| 108 | u32 max_recv_sge; |
| 109 | u32 max_inline_data; |
| 110 | }; |
| 111 | |
| 112 | struct efa_ah { |
| 113 | struct ib_ah ibah; |
| 114 | u16 ah; |
| 115 | /* dest_addr */ |
| 116 | u8 id[EFA_GID_SIZE]; |
| 117 | }; |
| 118 | |
| 119 | int efa_query_device(struct ib_device *ibdev, |
| 120 | struct ib_device_attr *props, |
| 121 | struct ib_udata *udata); |
| 122 | int efa_query_port(struct ib_device *ibdev, u8 port, |
| 123 | struct ib_port_attr *props); |
| 124 | int efa_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, |
| 125 | int qp_attr_mask, |
| 126 | struct ib_qp_init_attr *qp_init_attr); |
| 127 | int efa_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 128 | union ib_gid *gid); |
| 129 | int efa_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 130 | u16 *pkey); |
| 131 | int efa_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); |
| 132 | void efa_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); |
| 133 | int efa_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata); |
| 134 | struct ib_qp *efa_create_qp(struct ib_pd *ibpd, |
| 135 | struct ib_qp_init_attr *init_attr, |
| 136 | struct ib_udata *udata); |
| 137 | void efa_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata); |
| 138 | int efa_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, |
| 139 | struct ib_udata *udata); |
| 140 | struct ib_mr *efa_reg_mr(struct ib_pd *ibpd, u64 start, u64 length, |
| 141 | u64 virt_addr, int access_flags, |
| 142 | struct ib_udata *udata); |
| 143 | int efa_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata); |
| 144 | int efa_get_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 145 | struct ib_port_immutable *immutable); |
| 146 | int efa_alloc_ucontext(struct ib_ucontext *ibucontext, struct ib_udata *udata); |
| 147 | void efa_dealloc_ucontext(struct ib_ucontext *ibucontext); |
| 148 | int efa_mmap(struct ib_ucontext *ibucontext, |
| 149 | struct vm_area_struct *vma); |
| 150 | int efa_create_ah(struct ib_ah *ibah, |
| 151 | struct rdma_ah_attr *ah_attr, |
| 152 | u32 flags, |
| 153 | struct ib_udata *udata); |
| 154 | void efa_destroy_ah(struct ib_ah *ibah, u32 flags); |
| 155 | int efa_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, |
| 156 | int qp_attr_mask, struct ib_udata *udata); |
| 157 | enum rdma_link_layer efa_port_link_layer(struct ib_device *ibdev, |
| 158 | u8 port_num); |
| 159 | struct rdma_hw_stats *efa_alloc_hw_stats(struct ib_device *ibdev, u8 port_num); |
| 160 | int efa_get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats, |
| 161 | u8 port_num, int index); |
| 162 | |
| 163 | #endif /* _EFA_H_ */ |