Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 1 | #ifndef DEF_RDMA_VT_H |
| 2 | #define DEF_RDMA_VT_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright(c) 2015 Intel Corporation. |
| 6 | * |
| 7 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 8 | * redistributing this file, you may do so under either license. |
| 9 | * |
| 10 | * GPL LICENSE SUMMARY |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of version 2 of the GNU General Public License as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * BSD LICENSE |
| 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: |
| 26 | * |
| 27 | * - Redistributions of source code must retain the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer. |
| 29 | * - Redistributions in binary form must reproduce the above copyright |
| 30 | * notice, this list of conditions and the following disclaimer in |
| 31 | * the documentation and/or other materials provided with the |
| 32 | * distribution. |
| 33 | * - Neither the name of Intel Corporation nor the names of its |
| 34 | * contributors may be used to endorse or promote products derived |
| 35 | * from this software without specific prior written permission. |
| 36 | * |
| 37 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 38 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 39 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 40 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 41 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 43 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 44 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 45 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 46 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 47 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 48 | * |
| 49 | */ |
| 50 | |
| 51 | /* |
| 52 | * Structure that low level drivers will populate in order to register with the |
| 53 | * rdmavt layer. |
| 54 | */ |
| 55 | |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 56 | #include <linux/spinlock.h> |
| 57 | #include <linux/list.h> |
Dennis Dalessandro | b4e6439 | 2016-01-06 10:04:31 -0800 | [diff] [blame] | 58 | #include <rdma/ib_verbs.h> |
| 59 | #include <rdma/rdmavt_mr.h> |
| 60 | #include <rdma/rdmavt_qp.h> |
Kamal Heib | f2f3421 | 2016-01-06 10:03:47 -0800 | [diff] [blame] | 61 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 62 | /* |
Dennis Dalessandro | 0b8a8aa | 2016-01-06 10:03:07 -0800 | [diff] [blame] | 63 | * For some of the IBTA objects there will likely be some |
| 64 | * initializations required. We need flags to determine whether it is OK |
| 65 | * for rdmavt to do this or not. This does not imply any functions of a |
| 66 | * partiuclar IBTA object are overridden. |
| 67 | */ |
| 68 | #define RVT_FLAG_MR_INIT_DRIVER BIT(1) |
| 69 | #define RVT_FLAG_QP_INIT_DRIVER BIT(2) |
| 70 | #define RVT_FLAG_CQ_INIT_DRIVER BIT(3) |
| 71 | |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 72 | struct rvt_ibport { |
| 73 | struct rvt_qp __rcu *qp[2]; |
| 74 | struct ib_mad_agent *send_agent; /* agent for SMI (traps) */ |
| 75 | struct rb_root mcast_tree; |
| 76 | spinlock_t lock; /* protect changes in this struct */ |
| 77 | |
| 78 | /* non-zero when timer is set */ |
| 79 | unsigned long mkey_lease_timeout; |
| 80 | unsigned long trap_timeout; |
| 81 | __be64 gid_prefix; /* in network order */ |
| 82 | __be64 mkey; |
| 83 | u64 tid; |
| 84 | u32 port_cap_flags; |
| 85 | u32 pma_sample_start; |
| 86 | u32 pma_sample_interval; |
| 87 | __be16 pma_counter_select[5]; |
| 88 | u16 pma_tag; |
| 89 | u16 mkey_lease_period; |
| 90 | u16 sm_lid; |
| 91 | u8 sm_sl; |
| 92 | u8 mkeyprot; |
| 93 | u8 subnet_timeout; |
| 94 | u8 vl_high_limit; |
| 95 | |
| 96 | /* |
| 97 | * Driver is expected to keep these up to date. These |
| 98 | * counters are informational only and not required to be |
| 99 | * completely accurate. |
| 100 | */ |
| 101 | u64 n_rc_resends; |
| 102 | u64 n_seq_naks; |
| 103 | u64 n_rdma_seq; |
| 104 | u64 n_rnr_naks; |
| 105 | u64 n_other_naks; |
| 106 | u64 n_loop_pkts; |
| 107 | u64 n_pkt_drops; |
| 108 | u64 n_vl15_dropped; |
| 109 | u64 n_rc_timeouts; |
| 110 | u64 n_dmawait; |
| 111 | u64 n_unaligned; |
| 112 | u64 n_rc_dupreq; |
| 113 | u64 n_rc_seqnak; |
| 114 | u16 pkey_violations; |
| 115 | u16 qkey_violations; |
| 116 | u16 mkey_violations; |
| 117 | |
| 118 | /* Hot-path per CPU counters to avoid cacheline trading to update */ |
| 119 | u64 z_rc_acks; |
| 120 | u64 z_rc_qacks; |
| 121 | u64 z_rc_delayed_comp; |
| 122 | u64 __percpu *rc_acks; |
| 123 | u64 __percpu *rc_qacks; |
| 124 | u64 __percpu *rc_delayed_comp; |
| 125 | |
| 126 | void *priv; /* driver private data */ |
| 127 | |
| 128 | /* TODO: Move sm_ah and smi_ah into here as well*/ |
| 129 | }; |
| 130 | |
Dennis Dalessandro | ca889e8 | 2016-01-06 10:02:41 -0800 | [diff] [blame] | 131 | /* |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 132 | * Things that are driver specific, module parameters in hfi1 and qib |
| 133 | */ |
| 134 | struct rvt_driver_params { |
Dennis Dalessandro | b1070a7 | 2016-01-06 09:52:19 -0800 | [diff] [blame] | 135 | /* |
| 136 | * driver required fields: |
| 137 | * node_guid |
| 138 | * phys_port_cnt |
| 139 | * dma_device |
| 140 | * owner |
| 141 | * driver optional fields (rvt will provide generic value if blank): |
| 142 | * name |
| 143 | * node_desc |
| 144 | * rvt fields, driver value ignored: |
| 145 | * uverbs_abi_ver |
| 146 | * node_type |
| 147 | * num_comp_vectors |
| 148 | * uverbs_cmd_mask |
| 149 | */ |
| 150 | struct ib_device_attr props; |
| 151 | |
| 152 | /* |
| 153 | * Drivers will need to support a number of notifications to rvt in |
| 154 | * accordance with certain events. This structure should contain a mask |
| 155 | * of the supported events. Such events that the rvt may need to know |
| 156 | * about include: |
| 157 | * port errors |
| 158 | * port active |
| 159 | * lid change |
| 160 | * sm change |
| 161 | * client reregister |
| 162 | * pkey change |
| 163 | * |
| 164 | * There may also be other events that the rvt layers needs to know |
| 165 | * about this is not an exhaustive list. Some events though rvt does not |
| 166 | * need to rely on the driver for such as completion queue error. |
| 167 | */ |
| 168 | int rvt_signal_supported; |
| 169 | |
| 170 | /* |
| 171 | * Anything driver specific that is not covered by props |
| 172 | * For instance special module parameters. Goes here. |
| 173 | */ |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 174 | unsigned int lkey_table_size; |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 175 | unsigned int qp_table_size; |
| 176 | int qpn_start; |
| 177 | int qpn_inc; |
| 178 | int qpn_res_start; |
| 179 | int qpn_res_end; |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 180 | int nports; |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 181 | u8 qos_shift; |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | /* Protection domain */ |
| 185 | struct rvt_pd { |
| 186 | struct ib_pd ibpd; |
| 187 | int user; /* non-zero if created from user space */ |
| 188 | }; |
| 189 | |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 190 | /* Address handle */ |
| 191 | struct rvt_ah { |
| 192 | struct ib_ah ibah; |
| 193 | struct ib_ah_attr attr; |
| 194 | atomic_t refcount; |
Dennis Dalessandro | b036db8 | 2016-01-06 10:04:23 -0800 | [diff] [blame] | 195 | u8 vl; |
| 196 | u8 log_pmtu; |
| 197 | }; |
| 198 | |
| 199 | struct rvt_dev_info; |
| 200 | struct rvt_driver_provided { |
| 201 | /* |
| 202 | * The work to create port files in /sys/class Infiniband is different |
| 203 | * depending on the driver. This should not be extracted away and |
| 204 | * instead drivers are responsible for setting the correct callback for |
| 205 | * this. |
| 206 | */ |
| 207 | |
| 208 | /* -------------------*/ |
| 209 | /* Required functions */ |
| 210 | /* -------------------*/ |
| 211 | int (*port_callback)(struct ib_device *, u8, struct kobject *); |
| 212 | const char * (*get_card_name)(struct rvt_dev_info *rdi); |
| 213 | struct pci_dev * (*get_pci_dev)(struct rvt_dev_info *rdi); |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 214 | void (*free_all_qps)(struct rvt_dev_info *rdi); |
Dennis Dalessandro | b036db8 | 2016-01-06 10:04:23 -0800 | [diff] [blame] | 215 | |
| 216 | /*--------------------*/ |
| 217 | /* Optional functions */ |
| 218 | /*--------------------*/ |
| 219 | int (*check_ah)(struct ib_device *, struct ib_ah_attr *); |
| 220 | void (*notify_new_ah)(struct ib_device *, struct ib_ah_attr *, |
| 221 | struct rvt_ah *); |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 222 | }; |
| 223 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 224 | struct rvt_dev_info { |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 225 | struct ib_device ibdev; /* Keep this first. Nothing above here */ |
| 226 | |
Dennis Dalessandro | b1070a7 | 2016-01-06 09:52:19 -0800 | [diff] [blame] | 227 | /* |
| 228 | * Prior to calling for registration the driver will be responsible for |
| 229 | * allocating space for this structure. |
| 230 | * |
| 231 | * The driver will also be responsible for filling in certain members of |
| 232 | * dparms.props |
| 233 | */ |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 234 | |
Dennis Dalessandro | b1070a7 | 2016-01-06 09:52:19 -0800 | [diff] [blame] | 235 | /* Driver specific properties */ |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 236 | struct rvt_driver_params dparms; |
Dennis Dalessandro | b1070a7 | 2016-01-06 09:52:19 -0800 | [diff] [blame] | 237 | |
Dennis Dalessandro | b92a756 | 2016-01-06 10:01:42 -0800 | [diff] [blame] | 238 | struct rvt_mregion __rcu *dma_mr; |
| 239 | struct rvt_lkey_table lkey_table; |
| 240 | |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 241 | /* PKey Table goes here */ |
| 242 | |
Dennis Dalessandro | aec5778 | 2016-01-06 10:02:52 -0800 | [diff] [blame] | 243 | /* Driver specific helper functions */ |
| 244 | struct rvt_driver_provided driver_f; |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 245 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 246 | /* Internal use */ |
| 247 | int n_pds_allocated; |
| 248 | spinlock_t n_pds_lock; /* Protect pd allocated count */ |
Dennis Dalessandro | 0b8a8aa | 2016-01-06 10:03:07 -0800 | [diff] [blame] | 249 | |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 250 | int n_ahs_allocated; |
| 251 | spinlock_t n_ahs_lock; /* Protect ah allocated count */ |
| 252 | |
Dennis Dalessandro | 0b8a8aa | 2016-01-06 10:03:07 -0800 | [diff] [blame] | 253 | int flags; |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 254 | struct rvt_ibport **ports; |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 255 | |
| 256 | struct rvt_qp_ibdev *qp_dev; |
Dennis Dalessandro | 822514d | 2016-01-06 10:04:57 -0800 | [diff] [blame^] | 257 | |
| 258 | /* memory maps */ |
| 259 | struct list_head pending_mmaps; |
| 260 | spinlock_t mmap_offset_lock; /* protect mmap_offset */ |
| 261 | u32 mmap_offset; |
| 262 | spinlock_t pending_lock; /* protect pending mmap list */ |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 263 | }; |
| 264 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 265 | static inline struct rvt_pd *ibpd_to_rvtpd(struct ib_pd *ibpd) |
| 266 | { |
| 267 | return container_of(ibpd, struct rvt_pd, ibpd); |
| 268 | } |
| 269 | |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 270 | static inline struct rvt_ah *ibah_to_rvtah(struct ib_ah *ibah) |
| 271 | { |
| 272 | return container_of(ibah, struct rvt_ah, ibah); |
| 273 | } |
| 274 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 275 | static inline struct rvt_dev_info *ib_to_rvt(struct ib_device *ibdev) |
| 276 | { |
| 277 | return container_of(ibdev, struct rvt_dev_info, ibdev); |
| 278 | } |
| 279 | |
Dennis Dalessandro | 70a1a35 | 2016-01-06 10:04:06 -0800 | [diff] [blame] | 280 | static inline struct rvt_srq *ibsrq_to_rvtsrq(struct ib_srq *ibsrq) |
| 281 | { |
| 282 | return container_of(ibsrq, struct rvt_srq, ibsrq); |
| 283 | } |
| 284 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 285 | int rvt_register_device(struct rvt_dev_info *rvd); |
| 286 | void rvt_unregister_device(struct rvt_dev_info *rvd); |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 287 | int rvt_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr); |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 288 | void rvt_attach_port(struct rvt_dev_info *rdi, struct rvt_ibport *port, |
| 289 | int portnum); |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 290 | int rvt_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge, |
| 291 | u32 len, u64 vaddr, u32 rkey, int acc); |
| 292 | int rvt_lkey_ok(struct rvt_lkey_table *rkt, struct rvt_pd *pd, |
| 293 | struct rvt_sge *isge, struct ib_sge *sge, int acc); |
Dennis Dalessandro | 822514d | 2016-01-06 10:04:57 -0800 | [diff] [blame^] | 294 | int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma); |
| 295 | void rvt_release_mmap_info(struct kref *ref); |
| 296 | struct rvt_mmap_info *rvt_create_mmap_info(struct rvt_dev_info *rdi, |
| 297 | u32 size, |
| 298 | struct ib_ucontext *context, |
| 299 | void *obj); |
| 300 | void rvt_update_mmap_info(struct rvt_dev_info *rdi, struct rvt_mmap_info *ip, |
| 301 | u32 size, void *obj); |
| 302 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 303 | #endif /* DEF_RDMA_VT_H */ |