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 | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 72 | #define RVT_MAX_PKEY_VALUES 16 |
| 73 | |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 74 | struct rvt_ibport { |
| 75 | struct rvt_qp __rcu *qp[2]; |
| 76 | struct ib_mad_agent *send_agent; /* agent for SMI (traps) */ |
| 77 | struct rb_root mcast_tree; |
| 78 | spinlock_t lock; /* protect changes in this struct */ |
| 79 | |
| 80 | /* non-zero when timer is set */ |
| 81 | unsigned long mkey_lease_timeout; |
| 82 | unsigned long trap_timeout; |
| 83 | __be64 gid_prefix; /* in network order */ |
| 84 | __be64 mkey; |
| 85 | u64 tid; |
| 86 | u32 port_cap_flags; |
| 87 | u32 pma_sample_start; |
| 88 | u32 pma_sample_interval; |
| 89 | __be16 pma_counter_select[5]; |
| 90 | u16 pma_tag; |
| 91 | u16 mkey_lease_period; |
| 92 | u16 sm_lid; |
| 93 | u8 sm_sl; |
| 94 | u8 mkeyprot; |
| 95 | u8 subnet_timeout; |
| 96 | u8 vl_high_limit; |
| 97 | |
| 98 | /* |
| 99 | * Driver is expected to keep these up to date. These |
| 100 | * counters are informational only and not required to be |
| 101 | * completely accurate. |
| 102 | */ |
| 103 | u64 n_rc_resends; |
| 104 | u64 n_seq_naks; |
| 105 | u64 n_rdma_seq; |
| 106 | u64 n_rnr_naks; |
| 107 | u64 n_other_naks; |
| 108 | u64 n_loop_pkts; |
| 109 | u64 n_pkt_drops; |
| 110 | u64 n_vl15_dropped; |
| 111 | u64 n_rc_timeouts; |
| 112 | u64 n_dmawait; |
| 113 | u64 n_unaligned; |
| 114 | u64 n_rc_dupreq; |
| 115 | u64 n_rc_seqnak; |
| 116 | u16 pkey_violations; |
| 117 | u16 qkey_violations; |
| 118 | u16 mkey_violations; |
| 119 | |
| 120 | /* Hot-path per CPU counters to avoid cacheline trading to update */ |
| 121 | u64 z_rc_acks; |
| 122 | u64 z_rc_qacks; |
| 123 | u64 z_rc_delayed_comp; |
| 124 | u64 __percpu *rc_acks; |
| 125 | u64 __percpu *rc_qacks; |
| 126 | u64 __percpu *rc_delayed_comp; |
| 127 | |
| 128 | void *priv; /* driver private data */ |
| 129 | |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 130 | /* |
| 131 | * The pkey table is allocated and maintained by the driver. Drivers |
| 132 | * need to have access to this before registering with rdmav. However |
| 133 | * rdmavt will need access to it so drivers need to proviee this during |
| 134 | * the attach port API call. |
| 135 | */ |
| 136 | u16 *pkey_table; |
| 137 | |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 138 | /* TODO: Move sm_ah and smi_ah into here as well*/ |
| 139 | }; |
| 140 | |
Dennis Dalessandro | ca889e8 | 2016-01-06 10:02:41 -0800 | [diff] [blame] | 141 | /* |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 142 | * Things that are driver specific, module parameters in hfi1 and qib |
| 143 | */ |
| 144 | struct rvt_driver_params { |
Dennis Dalessandro | b1070a7 | 2016-01-06 09:52:19 -0800 | [diff] [blame] | 145 | /* |
| 146 | * driver required fields: |
| 147 | * node_guid |
| 148 | * phys_port_cnt |
| 149 | * dma_device |
| 150 | * owner |
| 151 | * driver optional fields (rvt will provide generic value if blank): |
| 152 | * name |
| 153 | * node_desc |
| 154 | * rvt fields, driver value ignored: |
| 155 | * uverbs_abi_ver |
| 156 | * node_type |
| 157 | * num_comp_vectors |
| 158 | * uverbs_cmd_mask |
| 159 | */ |
| 160 | struct ib_device_attr props; |
| 161 | |
| 162 | /* |
| 163 | * Drivers will need to support a number of notifications to rvt in |
| 164 | * accordance with certain events. This structure should contain a mask |
| 165 | * of the supported events. Such events that the rvt may need to know |
| 166 | * about include: |
| 167 | * port errors |
| 168 | * port active |
| 169 | * lid change |
| 170 | * sm change |
| 171 | * client reregister |
| 172 | * pkey change |
| 173 | * |
| 174 | * There may also be other events that the rvt layers needs to know |
| 175 | * about this is not an exhaustive list. Some events though rvt does not |
| 176 | * need to rely on the driver for such as completion queue error. |
| 177 | */ |
| 178 | int rvt_signal_supported; |
| 179 | |
| 180 | /* |
| 181 | * Anything driver specific that is not covered by props |
| 182 | * For instance special module parameters. Goes here. |
| 183 | */ |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 184 | unsigned int lkey_table_size; |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 185 | unsigned int qp_table_size; |
| 186 | int qpn_start; |
| 187 | int qpn_inc; |
| 188 | int qpn_res_start; |
| 189 | int qpn_res_end; |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 190 | int nports; |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 191 | int npkeys; |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 192 | u8 qos_shift; |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | /* Protection domain */ |
| 196 | struct rvt_pd { |
| 197 | struct ib_pd ibpd; |
| 198 | int user; /* non-zero if created from user space */ |
| 199 | }; |
| 200 | |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 201 | /* Address handle */ |
| 202 | struct rvt_ah { |
| 203 | struct ib_ah ibah; |
| 204 | struct ib_ah_attr attr; |
| 205 | atomic_t refcount; |
Dennis Dalessandro | b036db8 | 2016-01-06 10:04:23 -0800 | [diff] [blame] | 206 | u8 vl; |
| 207 | u8 log_pmtu; |
| 208 | }; |
| 209 | |
| 210 | struct rvt_dev_info; |
| 211 | struct rvt_driver_provided { |
| 212 | /* |
| 213 | * The work to create port files in /sys/class Infiniband is different |
| 214 | * depending on the driver. This should not be extracted away and |
| 215 | * instead drivers are responsible for setting the correct callback for |
| 216 | * this. |
| 217 | */ |
| 218 | |
| 219 | /* -------------------*/ |
| 220 | /* Required functions */ |
| 221 | /* -------------------*/ |
| 222 | int (*port_callback)(struct ib_device *, u8, struct kobject *); |
| 223 | const char * (*get_card_name)(struct rvt_dev_info *rdi); |
| 224 | struct pci_dev * (*get_pci_dev)(struct rvt_dev_info *rdi); |
Dennis Dalessandro | 515667f | 2016-01-22 12:50:17 -0800 | [diff] [blame] | 225 | unsigned (*free_all_qps)(struct rvt_dev_info *rdi); |
| 226 | void * (*qp_priv_alloc)(struct rvt_dev_info *rdi, struct rvt_qp *qp); |
| 227 | void (*qp_priv_free)(struct rvt_dev_info *rdi, struct rvt_qp *qp); |
| 228 | void (*notify_qp_reset)(struct rvt_qp *qp); |
Dennis Dalessandro | b036db8 | 2016-01-06 10:04:23 -0800 | [diff] [blame] | 229 | |
| 230 | /*--------------------*/ |
| 231 | /* Optional functions */ |
| 232 | /*--------------------*/ |
| 233 | int (*check_ah)(struct ib_device *, struct ib_ah_attr *); |
| 234 | void (*notify_new_ah)(struct ib_device *, struct ib_ah_attr *, |
| 235 | struct rvt_ah *); |
Dennis Dalessandro | 515667f | 2016-01-22 12:50:17 -0800 | [diff] [blame] | 236 | int (*alloc_qpn)(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt, |
| 237 | enum ib_qp_type type, u8 port); |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 238 | }; |
| 239 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 240 | struct rvt_dev_info { |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 241 | struct ib_device ibdev; /* Keep this first. Nothing above here */ |
| 242 | |
Dennis Dalessandro | b1070a7 | 2016-01-06 09:52:19 -0800 | [diff] [blame] | 243 | /* |
| 244 | * Prior to calling for registration the driver will be responsible for |
| 245 | * allocating space for this structure. |
| 246 | * |
| 247 | * The driver will also be responsible for filling in certain members of |
Harish Chegondi | feaeb6e | 2016-01-22 12:50:36 -0800 | [diff] [blame^] | 248 | * dparms.props. The driver needs to fill in dparms exactly as it would |
| 249 | * want values reported to a ULP. This will be returned to the caller |
| 250 | * in rdmavt's device. The driver should also therefore refrain from |
| 251 | * modifying this directly after registration with rdmavt. |
Dennis Dalessandro | b1070a7 | 2016-01-06 09:52:19 -0800 | [diff] [blame] | 252 | */ |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 253 | |
Dennis Dalessandro | b1070a7 | 2016-01-06 09:52:19 -0800 | [diff] [blame] | 254 | /* Driver specific properties */ |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 255 | struct rvt_driver_params dparms; |
Dennis Dalessandro | b1070a7 | 2016-01-06 09:52:19 -0800 | [diff] [blame] | 256 | |
Dennis Dalessandro | b92a756 | 2016-01-06 10:01:42 -0800 | [diff] [blame] | 257 | struct rvt_mregion __rcu *dma_mr; |
| 258 | struct rvt_lkey_table lkey_table; |
| 259 | |
Dennis Dalessandro | aec5778 | 2016-01-06 10:02:52 -0800 | [diff] [blame] | 260 | /* Driver specific helper functions */ |
| 261 | struct rvt_driver_provided driver_f; |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 262 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 263 | /* Internal use */ |
| 264 | int n_pds_allocated; |
| 265 | spinlock_t n_pds_lock; /* Protect pd allocated count */ |
Dennis Dalessandro | 0b8a8aa | 2016-01-06 10:03:07 -0800 | [diff] [blame] | 266 | |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 267 | int n_ahs_allocated; |
| 268 | spinlock_t n_ahs_lock; /* Protect ah allocated count */ |
| 269 | |
Dennis Dalessandro | 0b8a8aa | 2016-01-06 10:03:07 -0800 | [diff] [blame] | 270 | int flags; |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 271 | struct rvt_ibport **ports; |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 272 | |
Dennis Dalessandro | 515667f | 2016-01-22 12:50:17 -0800 | [diff] [blame] | 273 | /* QP */ |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 274 | struct rvt_qp_ibdev *qp_dev; |
Dennis Dalessandro | 515667f | 2016-01-22 12:50:17 -0800 | [diff] [blame] | 275 | u32 n_qps_allocated; /* number of QPs allocated for device */ |
| 276 | spinlock_t n_qps_lock; /* keep track of number of qps */ |
Dennis Dalessandro | 822514d | 2016-01-06 10:04:57 -0800 | [diff] [blame] | 277 | |
| 278 | /* memory maps */ |
| 279 | struct list_head pending_mmaps; |
| 280 | spinlock_t mmap_offset_lock; /* protect mmap_offset */ |
| 281 | u32 mmap_offset; |
| 282 | spinlock_t pending_lock; /* protect pending mmap list */ |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 283 | }; |
| 284 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 285 | static inline struct rvt_pd *ibpd_to_rvtpd(struct ib_pd *ibpd) |
| 286 | { |
| 287 | return container_of(ibpd, struct rvt_pd, ibpd); |
| 288 | } |
| 289 | |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 290 | static inline struct rvt_ah *ibah_to_rvtah(struct ib_ah *ibah) |
| 291 | { |
| 292 | return container_of(ibah, struct rvt_ah, ibah); |
| 293 | } |
| 294 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 295 | static inline struct rvt_dev_info *ib_to_rvt(struct ib_device *ibdev) |
| 296 | { |
| 297 | return container_of(ibdev, struct rvt_dev_info, ibdev); |
| 298 | } |
| 299 | |
Dennis Dalessandro | 70a1a35 | 2016-01-06 10:04:06 -0800 | [diff] [blame] | 300 | static inline struct rvt_srq *ibsrq_to_rvtsrq(struct ib_srq *ibsrq) |
| 301 | { |
| 302 | return container_of(ibsrq, struct rvt_srq, ibsrq); |
| 303 | } |
| 304 | |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 305 | static inline unsigned rvt_get_npkeys(struct rvt_dev_info *rdi) |
| 306 | { |
| 307 | /* |
| 308 | * All ports have same number of pkeys. |
| 309 | */ |
| 310 | return rdi->dparms.npkeys; |
| 311 | } |
| 312 | |
| 313 | /* |
| 314 | * Return the indexed PKEY from the port PKEY table. |
| 315 | */ |
| 316 | static inline u16 rvt_get_pkey(struct rvt_dev_info *rdi, |
| 317 | int port_index, |
| 318 | unsigned index) |
| 319 | { |
| 320 | if (index >= rvt_get_npkeys(rdi)) |
| 321 | return 0; |
| 322 | else |
| 323 | return rdi->ports[port_index]->pkey_table[index]; |
| 324 | } |
| 325 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 326 | int rvt_register_device(struct rvt_dev_info *rvd); |
| 327 | void rvt_unregister_device(struct rvt_dev_info *rvd); |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 328 | int rvt_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr); |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 329 | int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port, |
| 330 | int portnum, u16 *pkey_table); |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 331 | int rvt_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge, |
| 332 | u32 len, u64 vaddr, u32 rkey, int acc); |
| 333 | int rvt_lkey_ok(struct rvt_lkey_table *rkt, struct rvt_pd *pd, |
| 334 | struct rvt_sge *isge, struct ib_sge *sge, int acc); |
Dennis Dalessandro | 822514d | 2016-01-06 10:04:57 -0800 | [diff] [blame] | 335 | int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma); |
| 336 | void rvt_release_mmap_info(struct kref *ref); |
| 337 | struct rvt_mmap_info *rvt_create_mmap_info(struct rvt_dev_info *rdi, |
| 338 | u32 size, |
| 339 | struct ib_ucontext *context, |
| 340 | void *obj); |
| 341 | void rvt_update_mmap_info(struct rvt_dev_info *rdi, struct rvt_mmap_info *ip, |
| 342 | u32 size, void *obj); |
| 343 | |
Dennis Dalessandro | 5a9cf6f | 2016-01-22 12:50:24 -0800 | [diff] [blame] | 344 | /* Temporary export */ |
| 345 | void rvt_reset_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, |
| 346 | enum ib_qp_type type); |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 347 | #endif /* DEF_RDMA_VT_H */ |