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 | { |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 60 | /* |
| 61 | * rdmavt does not need to do anything special when it starts up. All it |
| 62 | * needs to do is sit and wait until a driver attempts registration. |
| 63 | */ |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | module_init(rvt_init); |
| 67 | |
| 68 | static void rvt_cleanup(void) |
| 69 | { |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 70 | /* |
| 71 | * Nothing to do at exit time either. The module won't be able to be |
| 72 | * removed until all drivers are gone which means all the dev structs |
| 73 | * are gone so there is really nothing to do. |
| 74 | */ |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 75 | } |
| 76 | module_exit(rvt_cleanup); |
| 77 | |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 78 | /** |
| 79 | * rvt_alloc_device - allocate rdi |
| 80 | * @size: how big of a structure to allocate |
| 81 | * @nports: number of ports to allocate array slots for |
| 82 | * |
| 83 | * Use IB core device alloc to allocate space for the rdi which is assumed to be |
| 84 | * inside of the ib_device. Any extra space that drivers require should be |
| 85 | * included in size. |
| 86 | * |
| 87 | * We also allocate a port array based on the number of ports. |
| 88 | * |
| 89 | * Return: pointer to allocated rdi |
| 90 | */ |
Dennis Dalessandro | ff6acd6 | 2016-01-22 13:04:45 -0800 | [diff] [blame] | 91 | struct rvt_dev_info *rvt_alloc_device(size_t size, int nports) |
| 92 | { |
| 93 | struct rvt_dev_info *rdi = ERR_PTR(-ENOMEM); |
| 94 | |
| 95 | rdi = (struct rvt_dev_info *)ib_alloc_device(size); |
| 96 | if (!rdi) |
| 97 | return rdi; |
| 98 | |
| 99 | rdi->ports = kcalloc(nports, |
| 100 | sizeof(struct rvt_ibport **), |
| 101 | GFP_KERNEL); |
| 102 | if (!rdi->ports) |
| 103 | ib_dealloc_device(&rdi->ibdev); |
| 104 | |
| 105 | return rdi; |
| 106 | } |
| 107 | EXPORT_SYMBOL(rvt_alloc_device); |
| 108 | |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 109 | static int rvt_query_device(struct ib_device *ibdev, |
| 110 | struct ib_device_attr *props, |
| 111 | struct ib_udata *uhw) |
| 112 | { |
Harish Chegondi | feaeb6e | 2016-01-22 12:50:36 -0800 | [diff] [blame] | 113 | struct rvt_dev_info *rdi = ib_to_rvt(ibdev); |
| 114 | |
| 115 | if (uhw->inlen || uhw->outlen) |
| 116 | return -EINVAL; |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 117 | /* |
Harish Chegondi | feaeb6e | 2016-01-22 12:50:36 -0800 | [diff] [blame] | 118 | * Return rvt_dev_info.dparms.props contents |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 119 | */ |
Harish Chegondi | feaeb6e | 2016-01-22 12:50:36 -0800 | [diff] [blame] | 120 | *props = rdi->dparms.props; |
| 121 | return 0; |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static int rvt_modify_device(struct ib_device *device, |
| 125 | int device_modify_mask, |
| 126 | struct ib_device_modify *device_modify) |
| 127 | { |
| 128 | /* |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 129 | * There is currently no need to supply this based on qib and hfi1. |
| 130 | * Future drivers may need to implement this though. |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 131 | */ |
| 132 | |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 133 | return -EOPNOTSUPP; |
| 134 | } |
| 135 | |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 136 | /** |
| 137 | * rvt_query_port: Passes the query port call to the driver |
| 138 | * @ibdev: Verbs IB dev |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 139 | * @port_num: port number, 1 based from ib core |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 140 | * @props: structure to hold returned properties |
| 141 | * |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 142 | * Return: 0 on success |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 143 | */ |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 144 | static int rvt_query_port(struct ib_device *ibdev, u8 port_num, |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 145 | struct ib_port_attr *props) |
| 146 | { |
Harish Chegondi | 61a650c | 2016-02-03 14:15:20 -0800 | [diff] [blame] | 147 | struct rvt_dev_info *rdi = ib_to_rvt(ibdev); |
| 148 | struct rvt_ibport *rvp; |
| 149 | int port_index = ibport_num_to_idx(ibdev, port_num); |
| 150 | |
| 151 | if (port_index < 0) |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 152 | return -EINVAL; |
| 153 | |
Harish Chegondi | 61a650c | 2016-02-03 14:15:20 -0800 | [diff] [blame] | 154 | rvp = rdi->ports[port_index]; |
| 155 | memset(props, 0, sizeof(*props)); |
| 156 | props->sm_lid = rvp->sm_lid; |
| 157 | props->sm_sl = rvp->sm_sl; |
| 158 | props->port_cap_flags = rvp->port_cap_flags; |
| 159 | props->max_msg_sz = 0x80000000; |
| 160 | props->pkey_tbl_len = rvt_get_npkeys(rdi); |
| 161 | props->bad_pkey_cntr = rvp->pkey_violations; |
| 162 | props->qkey_viol_cntr = rvp->qkey_violations; |
| 163 | props->subnet_timeout = rvp->subnet_timeout; |
| 164 | props->init_type_reply = 0; |
| 165 | |
| 166 | /* Populate the remaining ib_port_attr elements */ |
| 167 | return rdi->driver_f.query_port_state(rdi, port_num, props); |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * rvt_modify_port |
| 172 | * @ibdev: Verbs IB dev |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 173 | * @port_num: Port number, 1 based from ib core |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 174 | * @port_modify_mask: How to change the port |
| 175 | * @props: Structure to fill in |
| 176 | * |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 177 | * Return: 0 on success |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 178 | */ |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 179 | static int rvt_modify_port(struct ib_device *ibdev, u8 port_num, |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 180 | int port_modify_mask, struct ib_port_modify *props) |
| 181 | { |
Harish Chegondi | 61a650c | 2016-02-03 14:15:20 -0800 | [diff] [blame] | 182 | struct rvt_dev_info *rdi = ib_to_rvt(ibdev); |
| 183 | struct rvt_ibport *rvp; |
| 184 | int ret = 0; |
| 185 | int port_index = ibport_num_to_idx(ibdev, port_num); |
| 186 | |
| 187 | if (port_index < 0) |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 188 | return -EINVAL; |
| 189 | |
Harish Chegondi | 61a650c | 2016-02-03 14:15:20 -0800 | [diff] [blame] | 190 | rvp = rdi->ports[port_index]; |
| 191 | rvp->port_cap_flags |= props->set_port_cap_mask; |
| 192 | rvp->port_cap_flags &= ~props->clr_port_cap_mask; |
| 193 | |
| 194 | if (props->set_port_cap_mask || props->clr_port_cap_mask) |
| 195 | rdi->driver_f.cap_mask_chg(rdi, port_num); |
| 196 | if (port_modify_mask & IB_PORT_SHUTDOWN) |
| 197 | ret = rdi->driver_f.shut_down_port(rdi, port_num); |
| 198 | if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR) |
| 199 | rvp->qkey_violations = 0; |
| 200 | |
| 201 | return ret; |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 204 | /** |
| 205 | * rvt_query_pkey - Return a pkey from the table at a given index |
| 206 | * @ibdev: Verbs IB dev |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 207 | * @port_num: Port number, 1 based from ib core |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 208 | * @intex: Index into pkey table |
| 209 | * |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 210 | * Return: 0 on failure pkey otherwise |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 211 | */ |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 212 | 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] | 213 | u16 *pkey) |
| 214 | { |
| 215 | /* |
| 216 | * Driver will be responsible for keeping rvt_dev_info.pkey_table up to |
| 217 | * date. This function will just return that value. There is no need to |
| 218 | * lock, if a stale value is read and sent to the user so be it there is |
| 219 | * no way to protect against that anyway. |
| 220 | */ |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 221 | struct rvt_dev_info *rdi = ib_to_rvt(ibdev); |
| 222 | int port_index; |
| 223 | |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 224 | port_index = ibport_num_to_idx(ibdev, port_num); |
| 225 | if (port_index < 0) |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 226 | return -EINVAL; |
| 227 | |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 228 | if (index >= rvt_get_npkeys(rdi)) |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 229 | return -EINVAL; |
| 230 | |
| 231 | *pkey = rvt_get_pkey(rdi, port_index, index); |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 235 | /** |
| 236 | * rvt_query_gid - Return a gid from the table |
| 237 | * @ibdev: Verbs IB dev |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 238 | * @port_num: Port number, 1 based from ib core |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 239 | * @index: = Index in table |
| 240 | * @gid: Gid to return |
| 241 | * |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 242 | * Return: 0 on success |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 243 | */ |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 244 | static int rvt_query_gid(struct ib_device *ibdev, u8 port_num, |
Dennis Dalessandro | 1f02499 | 2016-02-03 14:15:11 -0800 | [diff] [blame] | 245 | int guid_index, union ib_gid *gid) |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 246 | { |
Dennis Dalessandro | 1f02499 | 2016-02-03 14:15:11 -0800 | [diff] [blame] | 247 | struct rvt_dev_info *rdi; |
| 248 | struct rvt_ibport *rvp; |
| 249 | int port_index; |
| 250 | |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 251 | /* |
| 252 | * Driver is responsible for updating the guid table. Which will be used |
| 253 | * to craft the return value. This will work similar to how query_pkey() |
| 254 | * is being done. |
| 255 | */ |
Dennis Dalessandro | 1f02499 | 2016-02-03 14:15:11 -0800 | [diff] [blame] | 256 | port_index = ibport_num_to_idx(ibdev, port_num); |
| 257 | if (port_index < 0) |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 258 | return -EINVAL; |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 259 | |
Dennis Dalessandro | 1f02499 | 2016-02-03 14:15:11 -0800 | [diff] [blame] | 260 | rdi = ib_to_rvt(ibdev); |
| 261 | rvp = rdi->ports[port_index]; |
| 262 | |
| 263 | gid->global.subnet_prefix = rvp->gid_prefix; |
| 264 | |
| 265 | return rdi->driver_f.get_guid_be(rdi, rvp, guid_index, |
| 266 | &gid->global.interface_id); |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Harish Chegondi | 6c43cf4 | 2016-01-22 12:50:05 -0800 | [diff] [blame] | 269 | struct rvt_ucontext { |
| 270 | struct ib_ucontext ibucontext; |
| 271 | }; |
| 272 | |
| 273 | static inline struct rvt_ucontext *to_iucontext(struct ib_ucontext |
| 274 | *ibucontext) |
| 275 | { |
| 276 | return container_of(ibucontext, struct rvt_ucontext, ibucontext); |
| 277 | } |
| 278 | |
Dennis Dalessandro | c4ed7d8 | 2016-01-06 09:55:39 -0800 | [diff] [blame] | 279 | /** |
| 280 | * rvt_alloc_ucontext - Allocate a user context |
| 281 | * @ibdev: Vers IB dev |
| 282 | * @data: User data allocated |
| 283 | */ |
| 284 | static struct ib_ucontext *rvt_alloc_ucontext(struct ib_device *ibdev, |
| 285 | struct ib_udata *udata) |
| 286 | { |
Harish Chegondi | 6c43cf4 | 2016-01-22 12:50:05 -0800 | [diff] [blame] | 287 | struct rvt_ucontext *context; |
| 288 | |
| 289 | context = kmalloc(sizeof(*context), GFP_KERNEL); |
| 290 | if (!context) |
| 291 | return ERR_PTR(-ENOMEM); |
| 292 | return &context->ibucontext; |
Dennis Dalessandro | c4ed7d8 | 2016-01-06 09:55:39 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
| 296 | *rvt_dealloc_ucontext - Free a user context |
| 297 | *@context - Free this |
| 298 | */ |
| 299 | static int rvt_dealloc_ucontext(struct ib_ucontext *context) |
| 300 | { |
Harish Chegondi | 6c43cf4 | 2016-01-22 12:50:05 -0800 | [diff] [blame] | 301 | kfree(to_iucontext(context)); |
| 302 | return 0; |
Dennis Dalessandro | c4ed7d8 | 2016-01-06 09:55:39 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Dennis Dalessandro | e6a8818 | 2016-01-06 09:59:38 -0800 | [diff] [blame] | 305 | static int rvt_get_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 306 | struct ib_port_immutable *immutable) |
| 307 | { |
Harish Chegondi | 61a650c | 2016-02-03 14:15:20 -0800 | [diff] [blame] | 308 | struct rvt_dev_info *rdi = ib_to_rvt(ibdev); |
| 309 | struct ib_port_attr attr; |
| 310 | int err, port_index; |
| 311 | |
| 312 | port_index = ibport_num_to_idx(ibdev, port_num); |
| 313 | if (port_index < 0) |
| 314 | return -EINVAL; |
| 315 | |
| 316 | err = rvt_query_port(ibdev, port_num, &attr); |
| 317 | if (err) |
| 318 | return err; |
| 319 | |
| 320 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 321 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 322 | immutable->core_cap_flags = rdi->dparms.core_cap_flags; |
| 323 | immutable->max_mad_size = rdi->dparms.max_mad_size; |
| 324 | |
| 325 | return 0; |
Dennis Dalessandro | e6a8818 | 2016-01-06 09:59:38 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Dennis Dalessandro | 4997870 | 2016-01-06 09:52:40 -0800 | [diff] [blame] | 328 | /* |
| 329 | * Check driver override. If driver passes a value use it, otherwise we use our |
| 330 | * own value. |
| 331 | */ |
| 332 | #define CHECK_DRIVER_OVERRIDE(rdi, x) \ |
| 333 | rdi->ibdev.x = rdi->ibdev.x ? : rvt_ ##x |
| 334 | |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 335 | /** |
| 336 | * rvt_register_device - register a driver |
| 337 | * @rdi: main dev structure for all of rdmavt operations |
| 338 | * |
| 339 | * It is up to drivers to allocate the rdi and fill in the appropriate |
| 340 | * information. |
| 341 | * |
| 342 | * Return: 0 on success otherwise an errno. |
| 343 | */ |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 344 | int rvt_register_device(struct rvt_dev_info *rdi) |
| 345 | { |
Dennis Dalessandro | b534875 | 2016-01-06 10:02:59 -0800 | [diff] [blame] | 346 | /* Validate that drivers have provided the right information */ |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 347 | int ret = 0; |
| 348 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 349 | if (!rdi) |
| 350 | return -EINVAL; |
| 351 | |
Dennis Dalessandro | b534875 | 2016-01-06 10:02:59 -0800 | [diff] [blame] | 352 | if ((!rdi->driver_f.port_callback) || |
| 353 | (!rdi->driver_f.get_card_name) || |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 354 | (!rdi->driver_f.get_pci_dev) || |
| 355 | (!rdi->driver_f.check_ah)) { |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 356 | pr_err("Driver not supporting req func\n"); |
Dennis Dalessandro | b534875 | 2016-01-06 10:02:59 -0800 | [diff] [blame] | 357 | return -EINVAL; |
| 358 | } |
| 359 | |
Dennis Dalessandro | 81ba39a | 2016-01-22 13:00:28 -0800 | [diff] [blame] | 360 | /* Once we get past here we can use rvt_pr macros and tracepoints */ |
| 361 | trace_rvt_dbg(rdi, "Driver attempting registration"); |
Dennis Dalessandro | 822514d | 2016-01-06 10:04:57 -0800 | [diff] [blame] | 362 | rvt_mmap_init(rdi); |
Dennis Dalessandro | b534875 | 2016-01-06 10:02:59 -0800 | [diff] [blame] | 363 | |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 364 | /* Dev Ops */ |
| 365 | CHECK_DRIVER_OVERRIDE(rdi, query_device); |
| 366 | CHECK_DRIVER_OVERRIDE(rdi, modify_device); |
Dennis Dalessandro | 765525c | 2016-01-06 09:54:07 -0800 | [diff] [blame] | 367 | CHECK_DRIVER_OVERRIDE(rdi, query_port); |
| 368 | CHECK_DRIVER_OVERRIDE(rdi, modify_port); |
Dennis Dalessandro | 3058864 | 2016-01-06 09:54:16 -0800 | [diff] [blame] | 369 | CHECK_DRIVER_OVERRIDE(rdi, query_pkey); |
Dennis Dalessandro | 2d092e1 | 2016-01-06 09:54:50 -0800 | [diff] [blame] | 370 | CHECK_DRIVER_OVERRIDE(rdi, query_gid); |
Dennis Dalessandro | c4ed7d8 | 2016-01-06 09:55:39 -0800 | [diff] [blame] | 371 | CHECK_DRIVER_OVERRIDE(rdi, alloc_ucontext); |
| 372 | CHECK_DRIVER_OVERRIDE(rdi, dealloc_ucontext); |
Dennis Dalessandro | e6a8818 | 2016-01-06 09:59:38 -0800 | [diff] [blame] | 373 | CHECK_DRIVER_OVERRIDE(rdi, get_port_immutable); |
Dennis Dalessandro | 19ef1ed | 2016-01-06 09:53:05 -0800 | [diff] [blame] | 374 | |
Dennis Dalessandro | b518d3e | 2016-01-06 09:56:15 -0800 | [diff] [blame] | 375 | /* Queue Pairs */ |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 376 | ret = rvt_driver_qp_init(rdi); |
| 377 | if (ret) { |
| 378 | pr_err("Error in driver QP init.\n"); |
| 379 | return -EINVAL; |
| 380 | } |
| 381 | |
Dennis Dalessandro | b518d3e | 2016-01-06 09:56:15 -0800 | [diff] [blame] | 382 | CHECK_DRIVER_OVERRIDE(rdi, create_qp); |
| 383 | CHECK_DRIVER_OVERRIDE(rdi, modify_qp); |
| 384 | CHECK_DRIVER_OVERRIDE(rdi, destroy_qp); |
| 385 | CHECK_DRIVER_OVERRIDE(rdi, query_qp); |
Dennis Dalessandro | 8cf4020 | 2016-01-06 10:01:17 -0800 | [diff] [blame] | 386 | CHECK_DRIVER_OVERRIDE(rdi, post_send); |
| 387 | CHECK_DRIVER_OVERRIDE(rdi, post_recv); |
| 388 | CHECK_DRIVER_OVERRIDE(rdi, post_srq_recv); |
Dennis Dalessandro | b518d3e | 2016-01-06 09:56:15 -0800 | [diff] [blame] | 389 | |
Dennis Dalessandro | 4c1e497 | 2016-01-06 09:56:41 -0800 | [diff] [blame] | 390 | /* Address Handle */ |
| 391 | CHECK_DRIVER_OVERRIDE(rdi, create_ah); |
| 392 | CHECK_DRIVER_OVERRIDE(rdi, destroy_ah); |
| 393 | CHECK_DRIVER_OVERRIDE(rdi, modify_ah); |
| 394 | CHECK_DRIVER_OVERRIDE(rdi, query_ah); |
Kamal Heib | 119a8e7 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 395 | spin_lock_init(&rdi->n_ahs_lock); |
| 396 | rdi->n_ahs_allocated = 0; |
Dennis Dalessandro | 4c1e497 | 2016-01-06 09:56:41 -0800 | [diff] [blame] | 397 | |
Dennis Dalessandro | aad9158 | 2016-01-06 09:57:58 -0800 | [diff] [blame] | 398 | /* Shared Receive Queue */ |
| 399 | CHECK_DRIVER_OVERRIDE(rdi, create_srq); |
| 400 | CHECK_DRIVER_OVERRIDE(rdi, modify_srq); |
| 401 | CHECK_DRIVER_OVERRIDE(rdi, destroy_srq); |
| 402 | CHECK_DRIVER_OVERRIDE(rdi, query_srq); |
Jubin John | b8f881b | 2016-02-03 14:14:36 -0800 | [diff] [blame] | 403 | rvt_driver_srq_init(rdi); |
Dennis Dalessandro | aad9158 | 2016-01-06 09:57:58 -0800 | [diff] [blame] | 404 | |
Dennis Dalessandro | 9fa2517 | 2016-01-06 09:58:23 -0800 | [diff] [blame] | 405 | /* Multicast */ |
Dennis Dalessandro | 4e74080 | 2016-01-22 13:00:55 -0800 | [diff] [blame] | 406 | rvt_driver_mcast_init(rdi); |
Dennis Dalessandro | 9fa2517 | 2016-01-06 09:58:23 -0800 | [diff] [blame] | 407 | CHECK_DRIVER_OVERRIDE(rdi, attach_mcast); |
| 408 | CHECK_DRIVER_OVERRIDE(rdi, detach_mcast); |
| 409 | |
Dennis Dalessandro | 2a055eb | 2016-01-06 09:57:21 -0800 | [diff] [blame] | 410 | /* Mem Region */ |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 411 | ret = rvt_driver_mr_init(rdi); |
| 412 | if (ret) { |
Dennis Dalessandro | 36055a0 | 2016-01-06 10:03:39 -0800 | [diff] [blame] | 413 | pr_err("Error in driver MR init.\n"); |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 414 | goto bail_no_mr; |
| 415 | } |
| 416 | |
Dennis Dalessandro | 2a055eb | 2016-01-06 09:57:21 -0800 | [diff] [blame] | 417 | CHECK_DRIVER_OVERRIDE(rdi, get_dma_mr); |
| 418 | CHECK_DRIVER_OVERRIDE(rdi, reg_user_mr); |
| 419 | CHECK_DRIVER_OVERRIDE(rdi, dereg_mr); |
| 420 | CHECK_DRIVER_OVERRIDE(rdi, alloc_mr); |
| 421 | CHECK_DRIVER_OVERRIDE(rdi, alloc_fmr); |
| 422 | CHECK_DRIVER_OVERRIDE(rdi, map_phys_fmr); |
| 423 | CHECK_DRIVER_OVERRIDE(rdi, unmap_fmr); |
| 424 | CHECK_DRIVER_OVERRIDE(rdi, dealloc_fmr); |
Dennis Dalessandro | dc21752 | 2016-01-06 09:59:04 -0800 | [diff] [blame] | 425 | CHECK_DRIVER_OVERRIDE(rdi, mmap); |
Dennis Dalessandro | 2a055eb | 2016-01-06 09:57:21 -0800 | [diff] [blame] | 426 | |
Dennis Dalessandro | cf16335 | 2016-01-06 10:00:42 -0800 | [diff] [blame] | 427 | /* Completion queues */ |
Dennis Dalessandro | 6f6387a | 2016-01-22 13:00:15 -0800 | [diff] [blame] | 428 | ret = rvt_driver_cq_init(rdi); |
| 429 | if (ret) { |
| 430 | pr_err("Error in driver CQ init.\n"); |
| 431 | goto bail_mr; |
| 432 | } |
Dennis Dalessandro | cf16335 | 2016-01-06 10:00:42 -0800 | [diff] [blame] | 433 | CHECK_DRIVER_OVERRIDE(rdi, create_cq); |
| 434 | CHECK_DRIVER_OVERRIDE(rdi, destroy_cq); |
| 435 | CHECK_DRIVER_OVERRIDE(rdi, poll_cq); |
| 436 | CHECK_DRIVER_OVERRIDE(rdi, req_notify_cq); |
| 437 | CHECK_DRIVER_OVERRIDE(rdi, resize_cq); |
| 438 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 439 | /* DMA Operations */ |
Dennis Dalessandro | c1b332b | 2016-01-06 09:51:18 -0800 | [diff] [blame] | 440 | rdi->ibdev.dma_ops = |
| 441 | rdi->ibdev.dma_ops ? : &rvt_default_dma_mapping_ops; |
| 442 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 443 | /* Protection Domain */ |
Dennis Dalessandro | 4997870 | 2016-01-06 09:52:40 -0800 | [diff] [blame] | 444 | CHECK_DRIVER_OVERRIDE(rdi, alloc_pd); |
| 445 | CHECK_DRIVER_OVERRIDE(rdi, dealloc_pd); |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 446 | spin_lock_init(&rdi->n_pds_lock); |
| 447 | rdi->n_pds_allocated = 0; |
| 448 | |
Dennis Dalessandro | 182285d | 2016-01-22 13:01:01 -0800 | [diff] [blame] | 449 | /* |
| 450 | * There are some things which could be set by underlying drivers but |
| 451 | * really should be up to rdmavt to set. For instance drivers can't know |
| 452 | * exactly which functions rdmavt supports, nor do they know the ABI |
| 453 | * version, so we do all of this sort of stuff here. |
| 454 | */ |
| 455 | rdi->ibdev.uverbs_abi_ver = RVT_UVERBS_ABI_VERSION; |
| 456 | rdi->ibdev.uverbs_cmd_mask = |
| 457 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 458 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 459 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 460 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 461 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 462 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 463 | (1ull << IB_USER_VERBS_CMD_MODIFY_AH) | |
| 464 | (1ull << IB_USER_VERBS_CMD_QUERY_AH) | |
| 465 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
| 466 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
| 467 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 468 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 469 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 470 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 471 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 472 | (1ull << IB_USER_VERBS_CMD_POLL_CQ) | |
| 473 | (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) | |
| 474 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 475 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 476 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 477 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 478 | (1ull << IB_USER_VERBS_CMD_POST_SEND) | |
| 479 | (1ull << IB_USER_VERBS_CMD_POST_RECV) | |
| 480 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 481 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 482 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 483 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 484 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 485 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 486 | (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV); |
| 487 | rdi->ibdev.node_type = RDMA_NODE_IB_CA; |
| 488 | rdi->ibdev.num_comp_vectors = 1; |
| 489 | |
Dennis Dalessandro | 8afd32e | 2016-01-06 09:51:48 -0800 | [diff] [blame] | 490 | /* We are now good to announce we exist */ |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 491 | ret = ib_register_device(&rdi->ibdev, rdi->driver_f.port_callback); |
| 492 | if (ret) { |
| 493 | rvt_pr_err(rdi, "Failed to register driver with ib core.\n"); |
Dennis Dalessandro | 6f6387a | 2016-01-22 13:00:15 -0800 | [diff] [blame] | 494 | goto bail_cq; |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 495 | } |
| 496 | |
Dennis Dalessandro | 3711baf | 2016-01-22 13:04:51 -0800 | [diff] [blame] | 497 | rvt_create_mad_agents(rdi); |
| 498 | |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 499 | rvt_pr_info(rdi, "Registration with rdmavt done.\n"); |
| 500 | return ret; |
| 501 | |
Dennis Dalessandro | 6f6387a | 2016-01-22 13:00:15 -0800 | [diff] [blame] | 502 | bail_cq: |
| 503 | rvt_cq_exit(rdi); |
| 504 | |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 505 | bail_mr: |
| 506 | rvt_mr_exit(rdi); |
| 507 | |
| 508 | bail_no_mr: |
Dennis Dalessandro | 0acb0cc | 2016-01-06 10:04:46 -0800 | [diff] [blame] | 509 | rvt_qp_exit(rdi); |
| 510 | |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 511 | return ret; |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 512 | } |
| 513 | EXPORT_SYMBOL(rvt_register_device); |
| 514 | |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 515 | /** |
| 516 | * rvt_unregister_device - remove a driver |
| 517 | * @rdi: rvt dev struct |
| 518 | */ |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 519 | void rvt_unregister_device(struct rvt_dev_info *rdi) |
| 520 | { |
Dennis Dalessandro | 81ba39a | 2016-01-22 13:00:28 -0800 | [diff] [blame] | 521 | trace_rvt_dbg(rdi, "Driver is unregistering."); |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 522 | if (!rdi) |
| 523 | return; |
| 524 | |
Dennis Dalessandro | 3711baf | 2016-01-22 13:04:51 -0800 | [diff] [blame] | 525 | rvt_free_mad_agents(rdi); |
| 526 | |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 527 | ib_unregister_device(&rdi->ibdev); |
Dennis Dalessandro | 6f6387a | 2016-01-22 13:00:15 -0800 | [diff] [blame] | 528 | rvt_cq_exit(rdi); |
Dennis Dalessandro | 7b1e209 | 2016-01-06 10:03:31 -0800 | [diff] [blame] | 529 | rvt_mr_exit(rdi); |
Dennis Dalessandro | 515667f | 2016-01-22 12:50:17 -0800 | [diff] [blame] | 530 | rvt_qp_exit(rdi); |
Dennis Dalessandro | 0194621 | 2016-01-06 09:50:24 -0800 | [diff] [blame] | 531 | } |
| 532 | EXPORT_SYMBOL(rvt_unregister_device); |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 533 | |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 534 | /** |
| 535 | * rvt_init_port - init internal data for driver port |
| 536 | * @rdi: rvt dev strut |
| 537 | * @port: rvt port |
| 538 | * @port_index: 0 based index of ports, different from IB core port num |
| 539 | * |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 540 | * Keep track of a list of ports. No need to have a detach port. |
| 541 | * They persist until the driver goes away. |
Dennis Dalessandro | 90793f7 | 2016-02-14 12:10:29 -0800 | [diff] [blame^] | 542 | * |
| 543 | * Return: always 0 |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 544 | */ |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 545 | 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] | 546 | int port_index, u16 *pkey_table) |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 547 | { |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 548 | |
Dennis Dalessandro | f1badc7 | 2016-02-03 14:15:02 -0800 | [diff] [blame] | 549 | rdi->ports[port_index] = port; |
| 550 | rdi->ports[port_index]->pkey_table = pkey_table; |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 551 | |
| 552 | return 0; |
Dennis Dalessandro | f3d01bb | 2016-01-06 10:04:13 -0800 | [diff] [blame] | 553 | } |
Dennis Dalessandro | 38ce2c6 | 2016-01-06 10:05:12 -0800 | [diff] [blame] | 554 | EXPORT_SYMBOL(rvt_init_port); |