Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 1 | /* |
Dennis Dalessandro | fe31419 | 2016-01-22 13:04:58 -0800 | [diff] [blame] | 2 | * Copyright(c) 2016 Intel Corporation. |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 3 | * |
| 4 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 5 | * redistributing this file, you may do so under either license. |
| 6 | * |
| 7 | * GPL LICENSE SUMMARY |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * BSD LICENSE |
| 19 | * |
| 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * |
| 24 | * - Redistributions of source code must retain the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer. |
| 26 | * - Redistributions in binary form must reproduce the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer in |
| 28 | * the documentation and/or other materials provided with the |
| 29 | * distribution. |
| 30 | * - Neither the name of Intel Corporation nor the names of its |
| 31 | * contributors may be used to endorse or promote products derived |
| 32 | * from this software without specific prior written permission. |
| 33 | * |
| 34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 35 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 37 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 38 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 41 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 42 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | #include <linux/module.h> |
| 49 | #include <linux/kernel.h> |
| 50 | #include "vt.h" |
Dennis Dalessandro | 81ba39a | 2016-01-22 13:00:28 -0800 | [diff] [blame] | 51 | #include "trace.h" |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 52 | |
Dennis Dalessandro | 182285d | 2016-01-22 13:01:01 -0800 | [diff] [blame] | 53 | #define RVT_UVERBS_ABI_VERSION 2 |
| 54 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 55 | MODULE_LICENSE("Dual BSD/GPL"); |
| 56 | MODULE_DESCRIPTION("RDMA Verbs Transport Library"); |
| 57 | |
| 58 | static int rvt_init(void) |
| 59 | { |
| 60 | /* Do any work needed prior to drivers calling for registration*/ |
| 61 | return 0; |
| 62 | } |
| 63 | module_init(rvt_init); |
| 64 | |
| 65 | static void rvt_cleanup(void) |
| 66 | { |
| 67 | } |
| 68 | module_exit(rvt_cleanup); |
| 69 | |
Dennis Dalessandro | ff6acd6 | 2016-01-22 13:04:45 -0800 | [diff] [blame] | 70 | struct rvt_dev_info *rvt_alloc_device(size_t size, int nports) |
| 71 | { |
| 72 | struct rvt_dev_info *rdi = ERR_PTR(-ENOMEM); |
| 73 | |
| 74 | rdi = (struct rvt_dev_info *)ib_alloc_device(size); |
| 75 | if (!rdi) |
| 76 | return rdi; |
| 77 | |
| 78 | rdi->ports = kcalloc(nports, |
| 79 | sizeof(struct rvt_ibport **), |
| 80 | GFP_KERNEL); |
| 81 | if (!rdi->ports) |
| 82 | ib_dealloc_device(&rdi->ibdev); |
| 83 | |
| 84 | return rdi; |
| 85 | } |
| 86 | EXPORT_SYMBOL(rvt_alloc_device); |
| 87 | |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 88 | static int rvt_query_device(struct ib_device *ibdev, |
| 89 | struct ib_device_attr *props, |
| 90 | struct ib_udata *uhw) |
| 91 | { |
Harish Chegondi | feaeb6e | 2016-01-22 12:50:36 -0800 | [diff] [blame] | 92 | struct rvt_dev_info *rdi = ib_to_rvt(ibdev); |
| 93 | |
| 94 | if (uhw->inlen || uhw->outlen) |
| 95 | return -EINVAL; |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 96 | /* |
Harish Chegondi | feaeb6e | 2016-01-22 12:50:36 -0800 | [diff] [blame] | 97 | * Return rvt_dev_info.dparms.props contents |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 98 | */ |
Harish Chegondi | feaeb6e | 2016-01-22 12:50:36 -0800 | [diff] [blame] | 99 | *props = rdi->dparms.props; |
| 100 | return 0; |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static int rvt_modify_device(struct ib_device *device, |
| 104 | int device_modify_mask, |
| 105 | struct ib_device_modify *device_modify) |
| 106 | { |
| 107 | /* |
| 108 | * Change dev props. Planned support is for node desc change and sys |
| 109 | * guid change only. This matches hfi1 and qib behavior. Other drivers |
| 110 | * that support existing modifications will need to add their support. |
| 111 | */ |
| 112 | |
| 113 | /* |
| 114 | * VT-DRIVER-API: node_desc_change() |
| 115 | * VT-DRIVER-API: sys_guid_change() |
| 116 | */ |
| 117 | return -EOPNOTSUPP; |
| 118 | } |
| 119 | |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 120 | /** |
| 121 | * rvt_query_port: Passes the query port call to the driver |
| 122 | * @ibdev: Verbs IB dev |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 123 | * @port_num: port number, 1 based from ib core |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 124 | * @props: structure to hold returned properties |
| 125 | * |
| 126 | * Returns 0 on success |
| 127 | */ |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 128 | static int rvt_query_port(struct ib_device *ibdev, u8 port_num, |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 129 | struct ib_port_attr *props) |
| 130 | { |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 131 | if (ibport_num_to_idx(ibdev, port_num) < 0) |
| 132 | return -EINVAL; |
| 133 | |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 134 | /* |
| 135 | * VT-DRIVER-API: query_port_state() |
| 136 | * driver returns pretty much everything in ib_port_attr |
| 137 | */ |
| 138 | return -EOPNOTSUPP; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * rvt_modify_port |
| 143 | * @ibdev: Verbs IB dev |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 144 | * @port_num: Port number, 1 based from ib core |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 145 | * @port_modify_mask: How to change the port |
| 146 | * @props: Structure to fill in |
| 147 | * |
| 148 | * Returns 0 on success |
| 149 | */ |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 150 | static int rvt_modify_port(struct ib_device *ibdev, u8 port_num, |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 151 | int port_modify_mask, struct ib_port_modify *props) |
| 152 | { |
| 153 | /* |
| 154 | * VT-DRIVER-API: set_link_state() |
| 155 | * driver will set the link state using the IB enumeration |
| 156 | * |
| 157 | * VT-DRIVER-API: clear_qkey_violations() |
| 158 | * clears driver private qkey counter |
| 159 | * |
| 160 | * VT-DRIVER-API: get_lid() |
| 161 | * driver needs to return the LID |
| 162 | * |
| 163 | * TBD: send_trap() and post_mad_send() need examined to see where they |
| 164 | * fit in. |
| 165 | */ |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 166 | if (ibport_num_to_idx(ibdev, port_num) < 0) |
| 167 | return -EINVAL; |
| 168 | |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 169 | return -EOPNOTSUPP; |
| 170 | } |
| 171 | |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 172 | /** |
| 173 | * rvt_query_pkey - Return a pkey from the table at a given index |
| 174 | * @ibdev: Verbs IB dev |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 175 | * @port_num: Port number, 1 based from ib core |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 176 | * @intex: Index into pkey table |
| 177 | * |
| 178 | * Returns 0 on failure pkey otherwise |
| 179 | */ |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 180 | static int rvt_query_pkey(struct ib_device *ibdev, u8 port_num, u16 index, |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 181 | u16 *pkey) |
| 182 | { |
| 183 | /* |
| 184 | * Driver will be responsible for keeping rvt_dev_info.pkey_table up to |
| 185 | * date. This function will just return that value. There is no need to |
| 186 | * lock, if a stale value is read and sent to the user so be it there is |
| 187 | * no way to protect against that anyway. |
| 188 | */ |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 189 | struct rvt_dev_info *rdi = ib_to_rvt(ibdev); |
| 190 | int port_index; |
| 191 | |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 192 | port_index = ibport_num_to_idx(ibdev, port_num); |
| 193 | if (port_index < 0) |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 194 | return -EINVAL; |
| 195 | |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 196 | if (index >= rvt_get_npkeys(rdi)) |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 197 | return -EINVAL; |
| 198 | |
| 199 | *pkey = rvt_get_pkey(rdi, port_index, index); |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 200 | return 0; |
| 201 | } |
| 202 | |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 203 | /** |
| 204 | * rvt_query_gid - Return a gid from the table |
| 205 | * @ibdev: Verbs IB dev |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 206 | * @port_num: Port number, 1 based from ib core |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 207 | * @index: = Index in table |
| 208 | * @gid: Gid to return |
| 209 | * |
| 210 | * Returns 0 on success |
| 211 | */ |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 212 | static int rvt_query_gid(struct ib_device *ibdev, u8 port_num, |
Dennis Dalessandro | 1f02499 | 2016-02-03 14:15:11 -0800 | [diff] [blame^] | 213 | int guid_index, union ib_gid *gid) |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 214 | { |
Dennis Dalessandro | 1f02499 | 2016-02-03 14:15:11 -0800 | [diff] [blame^] | 215 | struct rvt_dev_info *rdi; |
| 216 | struct rvt_ibport *rvp; |
| 217 | int port_index; |
| 218 | |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 219 | /* |
| 220 | * Driver is responsible for updating the guid table. Which will be used |
| 221 | * to craft the return value. This will work similar to how query_pkey() |
| 222 | * is being done. |
| 223 | */ |
Dennis Dalessandro | 1f02499 | 2016-02-03 14:15:11 -0800 | [diff] [blame^] | 224 | port_index = ibport_num_to_idx(ibdev, port_num); |
| 225 | if (port_index < 0) |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 226 | return -EINVAL; |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 227 | |
Dennis Dalessandro | 1f02499 | 2016-02-03 14:15:11 -0800 | [diff] [blame^] | 228 | rdi = ib_to_rvt(ibdev); |
| 229 | rvp = rdi->ports[port_index]; |
| 230 | |
| 231 | gid->global.subnet_prefix = rvp->gid_prefix; |
| 232 | |
| 233 | return rdi->driver_f.get_guid_be(rdi, rvp, guid_index, |
| 234 | &gid->global.interface_id); |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Harish Chegondi | 6c43cf4 | 2016-01-22 12:50:05 -0800 | [diff] [blame] | 237 | struct rvt_ucontext { |
| 238 | struct ib_ucontext ibucontext; |
| 239 | }; |
| 240 | |
| 241 | static inline struct rvt_ucontext *to_iucontext(struct ib_ucontext |
| 242 | *ibucontext) |
| 243 | { |
| 244 | return container_of(ibucontext, struct rvt_ucontext, ibucontext); |
| 245 | } |
| 246 | |
Dennis Dalessandro | c4ed7d8 | 2016-01-06 09:55:39 -0800 | [diff] [blame] | 247 | /** |
| 248 | * rvt_alloc_ucontext - Allocate a user context |
| 249 | * @ibdev: Vers IB dev |
| 250 | * @data: User data allocated |
| 251 | */ |
| 252 | static struct ib_ucontext *rvt_alloc_ucontext(struct ib_device *ibdev, |
| 253 | struct ib_udata *udata) |
| 254 | { |
Harish Chegondi | 6c43cf4 | 2016-01-22 12:50:05 -0800 | [diff] [blame] | 255 | struct rvt_ucontext *context; |
| 256 | |
| 257 | context = kmalloc(sizeof(*context), GFP_KERNEL); |
| 258 | if (!context) |
| 259 | return ERR_PTR(-ENOMEM); |
| 260 | return &context->ibucontext; |
Dennis Dalessandro | c4ed7d8 | 2016-01-06 09:55:39 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /** |
| 264 | *rvt_dealloc_ucontext - Free a user context |
| 265 | *@context - Free this |
| 266 | */ |
| 267 | static int rvt_dealloc_ucontext(struct ib_ucontext *context) |
| 268 | { |
Harish Chegondi | 6c43cf4 | 2016-01-22 12:50:05 -0800 | [diff] [blame] | 269 | kfree(to_iucontext(context)); |
| 270 | return 0; |
Dennis Dalessandro | c4ed7d8 | 2016-01-06 09:55:39 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Dennis Dalessandro | e6a8818 | 2016-01-06 09:59:38 -0800 | [diff] [blame] | 273 | static int rvt_get_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 274 | struct ib_port_immutable *immutable) |
| 275 | { |
| 276 | return -EOPNOTSUPP; |
| 277 | } |
| 278 | |
Dennis Dalessandro | 4997870 | 2016-01-06 09:52:40 -0800 | [diff] [blame] | 279 | /* |
| 280 | * Check driver override. If driver passes a value use it, otherwise we use our |
| 281 | * own value. |
| 282 | */ |
| 283 | #define CHECK_DRIVER_OVERRIDE(rdi, x) \ |
| 284 | rdi->ibdev.x = rdi->ibdev.x ? : rvt_ ##x |
| 285 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 286 | int rvt_register_device(struct rvt_dev_info *rdi) |
| 287 | { |
Dennis Dalessandro | b534875 | 2016-01-06 10:02:59 -0800 | [diff] [blame] | 288 | /* Validate that drivers have provided the right information */ |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 289 | int ret = 0; |
| 290 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 291 | if (!rdi) |
| 292 | return -EINVAL; |
| 293 | |
Dennis Dalessandro | b534875 | 2016-01-06 10:02:59 -0800 | [diff] [blame] | 294 | if ((!rdi->driver_f.port_callback) || |
| 295 | (!rdi->driver_f.get_card_name) || |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 296 | (!rdi->driver_f.get_pci_dev) || |
| 297 | (!rdi->driver_f.check_ah)) { |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 298 | pr_err("Driver not supporting req func\n"); |
Dennis Dalessandro | b534875 | 2016-01-06 10:02:59 -0800 | [diff] [blame] | 299 | return -EINVAL; |
| 300 | } |
| 301 | |
Dennis Dalessandro | 81ba39a | 2016-01-22 13:00:28 -0800 | [diff] [blame] | 302 | /* Once we get past here we can use rvt_pr macros and tracepoints */ |
| 303 | trace_rvt_dbg(rdi, "Driver attempting registration"); |
Dennis Dalessandro | 822514d | 2016-01-06 10:04:57 -0800 | [diff] [blame] | 304 | rvt_mmap_init(rdi); |
Dennis Dalessandro | b534875 | 2016-01-06 10:02:59 -0800 | [diff] [blame] | 305 | |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 306 | /* Dev Ops */ |
| 307 | CHECK_DRIVER_OVERRIDE(rdi, query_device); |
| 308 | CHECK_DRIVER_OVERRIDE(rdi, modify_device); |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 309 | CHECK_DRIVER_OVERRIDE(rdi, query_port); |
| 310 | CHECK_DRIVER_OVERRIDE(rdi, modify_port); |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 311 | CHECK_DRIVER_OVERRIDE(rdi, query_pkey); |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 312 | CHECK_DRIVER_OVERRIDE(rdi, query_gid); |
Dennis Dalessandro | c4ed7d8 | 2016-01-06 09:55:39 -0800 | [diff] [blame] | 313 | CHECK_DRIVER_OVERRIDE(rdi, alloc_ucontext); |
| 314 | CHECK_DRIVER_OVERRIDE(rdi, dealloc_ucontext); |
Dennis Dalessandro | e6a8818 | 2016-01-06 09:59:38 -0800 | [diff] [blame] | 315 | CHECK_DRIVER_OVERRIDE(rdi, get_port_immutable); |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 316 | |
Dennis Dalessandro | b518d3e | 2016-01-06 09:56:15 -0800 | [diff] [blame] | 317 | /* Queue Pairs */ |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 318 | ret = rvt_driver_qp_init(rdi); |
| 319 | if (ret) { |
| 320 | pr_err("Error in driver QP init.\n"); |
| 321 | return -EINVAL; |
| 322 | } |
| 323 | |
Dennis Dalessandro | b518d3e | 2016-01-06 09:56:15 -0800 | [diff] [blame] | 324 | CHECK_DRIVER_OVERRIDE(rdi, create_qp); |
| 325 | CHECK_DRIVER_OVERRIDE(rdi, modify_qp); |
| 326 | CHECK_DRIVER_OVERRIDE(rdi, destroy_qp); |
| 327 | CHECK_DRIVER_OVERRIDE(rdi, query_qp); |
Dennis Dalessandro | 8cf4020 | 2016-01-06 10:01:17 -0800 | [diff] [blame] | 328 | CHECK_DRIVER_OVERRIDE(rdi, post_send); |
| 329 | CHECK_DRIVER_OVERRIDE(rdi, post_recv); |
| 330 | CHECK_DRIVER_OVERRIDE(rdi, post_srq_recv); |
Dennis Dalessandro | b518d3e | 2016-01-06 09:56:15 -0800 | [diff] [blame] | 331 | |
Dennis Dalessandro | 4c1e497 | 2016-01-06 09:56:41 -0800 | [diff] [blame] | 332 | /* Address Handle */ |
| 333 | CHECK_DRIVER_OVERRIDE(rdi, create_ah); |
| 334 | CHECK_DRIVER_OVERRIDE(rdi, destroy_ah); |
| 335 | CHECK_DRIVER_OVERRIDE(rdi, modify_ah); |
| 336 | CHECK_DRIVER_OVERRIDE(rdi, query_ah); |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 337 | spin_lock_init(&rdi->n_ahs_lock); |
| 338 | rdi->n_ahs_allocated = 0; |
Dennis Dalessandro | 4c1e497 | 2016-01-06 09:56:41 -0800 | [diff] [blame] | 339 | |
Dennis Dalessandro | aad9158 | 2016-01-06 09:57:58 -0800 | [diff] [blame] | 340 | /* Shared Receive Queue */ |
| 341 | CHECK_DRIVER_OVERRIDE(rdi, create_srq); |
| 342 | CHECK_DRIVER_OVERRIDE(rdi, modify_srq); |
| 343 | CHECK_DRIVER_OVERRIDE(rdi, destroy_srq); |
| 344 | CHECK_DRIVER_OVERRIDE(rdi, query_srq); |
Jubin John | b8f881b | 2016-02-03 14:14:36 -0800 | [diff] [blame] | 345 | rvt_driver_srq_init(rdi); |
Dennis Dalessandro | aad9158 | 2016-01-06 09:57:58 -0800 | [diff] [blame] | 346 | |
Dennis Dalessandro | 9fa2517 | 2016-01-06 09:58:23 -0800 | [diff] [blame] | 347 | /* Multicast */ |
Dennis Dalessandro | 4e74080 | 2016-01-22 13:00:55 -0800 | [diff] [blame] | 348 | rvt_driver_mcast_init(rdi); |
Dennis Dalessandro | 9fa2517 | 2016-01-06 09:58:23 -0800 | [diff] [blame] | 349 | CHECK_DRIVER_OVERRIDE(rdi, attach_mcast); |
| 350 | CHECK_DRIVER_OVERRIDE(rdi, detach_mcast); |
| 351 | |
Dennis Dalessandro | 2a055eb | 2016-01-06 09:57:21 -0800 | [diff] [blame] | 352 | /* Mem Region */ |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 353 | ret = rvt_driver_mr_init(rdi); |
| 354 | if (ret) { |
Dennis Dalessandro | 36055a0 | 2016-01-06 10:03:39 -0800 | [diff] [blame] | 355 | pr_err("Error in driver MR init.\n"); |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 356 | goto bail_no_mr; |
| 357 | } |
| 358 | |
Dennis Dalessandro | 2a055eb | 2016-01-06 09:57:21 -0800 | [diff] [blame] | 359 | CHECK_DRIVER_OVERRIDE(rdi, get_dma_mr); |
| 360 | CHECK_DRIVER_OVERRIDE(rdi, reg_user_mr); |
| 361 | CHECK_DRIVER_OVERRIDE(rdi, dereg_mr); |
| 362 | CHECK_DRIVER_OVERRIDE(rdi, alloc_mr); |
| 363 | CHECK_DRIVER_OVERRIDE(rdi, alloc_fmr); |
| 364 | CHECK_DRIVER_OVERRIDE(rdi, map_phys_fmr); |
| 365 | CHECK_DRIVER_OVERRIDE(rdi, unmap_fmr); |
| 366 | CHECK_DRIVER_OVERRIDE(rdi, dealloc_fmr); |
Dennis Dalessandro | dc21752 | 2016-01-06 09:59:04 -0800 | [diff] [blame] | 367 | CHECK_DRIVER_OVERRIDE(rdi, mmap); |
Dennis Dalessandro | 2a055eb | 2016-01-06 09:57:21 -0800 | [diff] [blame] | 368 | |
Dennis Dalessandro | cf16335 | 2016-01-06 10:00:42 -0800 | [diff] [blame] | 369 | /* Completion queues */ |
Dennis Dalessandro | 6f6387a | 2016-01-22 13:00:15 -0800 | [diff] [blame] | 370 | ret = rvt_driver_cq_init(rdi); |
| 371 | if (ret) { |
| 372 | pr_err("Error in driver CQ init.\n"); |
| 373 | goto bail_mr; |
| 374 | } |
Dennis Dalessandro | cf16335 | 2016-01-06 10:00:42 -0800 | [diff] [blame] | 375 | CHECK_DRIVER_OVERRIDE(rdi, create_cq); |
| 376 | CHECK_DRIVER_OVERRIDE(rdi, destroy_cq); |
| 377 | CHECK_DRIVER_OVERRIDE(rdi, poll_cq); |
| 378 | CHECK_DRIVER_OVERRIDE(rdi, req_notify_cq); |
| 379 | CHECK_DRIVER_OVERRIDE(rdi, resize_cq); |
| 380 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 381 | /* DMA Operations */ |
Dennis Dalessandro | c1b332b | 2016-01-06 09:51:18 -0800 | [diff] [blame] | 382 | rdi->ibdev.dma_ops = |
| 383 | rdi->ibdev.dma_ops ? : &rvt_default_dma_mapping_ops; |
| 384 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 385 | /* Protection Domain */ |
Dennis Dalessandro | 4997870 | 2016-01-06 09:52:40 -0800 | [diff] [blame] | 386 | CHECK_DRIVER_OVERRIDE(rdi, alloc_pd); |
| 387 | CHECK_DRIVER_OVERRIDE(rdi, dealloc_pd); |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 388 | spin_lock_init(&rdi->n_pds_lock); |
| 389 | rdi->n_pds_allocated = 0; |
| 390 | |
Dennis Dalessandro | 182285d | 2016-01-22 13:01:01 -0800 | [diff] [blame] | 391 | /* |
| 392 | * There are some things which could be set by underlying drivers but |
| 393 | * really should be up to rdmavt to set. For instance drivers can't know |
| 394 | * exactly which functions rdmavt supports, nor do they know the ABI |
| 395 | * version, so we do all of this sort of stuff here. |
| 396 | */ |
| 397 | rdi->ibdev.uverbs_abi_ver = RVT_UVERBS_ABI_VERSION; |
| 398 | rdi->ibdev.uverbs_cmd_mask = |
| 399 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 400 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 401 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 402 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 403 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 404 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 405 | (1ull << IB_USER_VERBS_CMD_MODIFY_AH) | |
| 406 | (1ull << IB_USER_VERBS_CMD_QUERY_AH) | |
| 407 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
| 408 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
| 409 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 410 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 411 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 412 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 413 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 414 | (1ull << IB_USER_VERBS_CMD_POLL_CQ) | |
| 415 | (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) | |
| 416 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 417 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 418 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 419 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 420 | (1ull << IB_USER_VERBS_CMD_POST_SEND) | |
| 421 | (1ull << IB_USER_VERBS_CMD_POST_RECV) | |
| 422 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 423 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 424 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 425 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 426 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 427 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 428 | (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV); |
| 429 | rdi->ibdev.node_type = RDMA_NODE_IB_CA; |
| 430 | rdi->ibdev.num_comp_vectors = 1; |
| 431 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 432 | /* We are now good to announce we exist */ |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 433 | ret = ib_register_device(&rdi->ibdev, rdi->driver_f.port_callback); |
| 434 | if (ret) { |
| 435 | rvt_pr_err(rdi, "Failed to register driver with ib core.\n"); |
Dennis Dalessandro | 6f6387a | 2016-01-22 13:00:15 -0800 | [diff] [blame] | 436 | goto bail_cq; |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Dennis Dalessandro | 3711baf | 2016-01-22 13:04:51 -0800 | [diff] [blame] | 439 | rvt_create_mad_agents(rdi); |
| 440 | |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 441 | rvt_pr_info(rdi, "Registration with rdmavt done.\n"); |
| 442 | return ret; |
| 443 | |
Dennis Dalessandro | 6f6387a | 2016-01-22 13:00:15 -0800 | [diff] [blame] | 444 | bail_cq: |
| 445 | rvt_cq_exit(rdi); |
| 446 | |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 447 | bail_mr: |
| 448 | rvt_mr_exit(rdi); |
| 449 | |
| 450 | bail_no_mr: |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 451 | rvt_qp_exit(rdi); |
| 452 | |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 453 | return ret; |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 454 | } |
| 455 | EXPORT_SYMBOL(rvt_register_device); |
| 456 | |
| 457 | void rvt_unregister_device(struct rvt_dev_info *rdi) |
| 458 | { |
Dennis Dalessandro | 81ba39a | 2016-01-22 13:00:28 -0800 | [diff] [blame] | 459 | trace_rvt_dbg(rdi, "Driver is unregistering."); |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 460 | if (!rdi) |
| 461 | return; |
| 462 | |
Dennis Dalessandro | 3711baf | 2016-01-22 13:04:51 -0800 | [diff] [blame] | 463 | rvt_free_mad_agents(rdi); |
| 464 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 465 | ib_unregister_device(&rdi->ibdev); |
Dennis Dalessandro | 6f6387a | 2016-01-22 13:00:15 -0800 | [diff] [blame] | 466 | rvt_cq_exit(rdi); |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 467 | rvt_mr_exit(rdi); |
Dennis Dalessandro | 515667f | 2016-01-22 12:50:17 -0800 | [diff] [blame] | 468 | rvt_qp_exit(rdi); |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 469 | } |
| 470 | EXPORT_SYMBOL(rvt_unregister_device); |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 471 | |
| 472 | /* |
| 473 | * Keep track of a list of ports. No need to have a detach port. |
| 474 | * They persist until the driver goes away. |
| 475 | */ |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 476 | int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port, |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 477 | int port_index, u16 *pkey_table) |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 478 | { |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 479 | |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 480 | rdi->ports[port_index] = port; |
| 481 | rdi->ports[port_index]->pkey_table = pkey_table; |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 482 | |
| 483 | return 0; |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 484 | } |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 485 | EXPORT_SYMBOL(rvt_init_port); |