hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/infiniband/sw/rxe/rxe.c
....@@ -1,36 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
12 /*
23 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
34 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
4
- *
5
- * This software is available to you under a choice of one of two
6
- * licenses. You may choose to be licensed under the terms of the GNU
7
- * General Public License (GPL) Version 2, available from the file
8
- * COPYING in the main directory of this source tree, or the
9
- * OpenIB.org BSD license below:
10
- *
11
- * Redistribution and use in source and binary forms, with or
12
- * without modification, are permitted provided that the following
13
- * conditions are met:
14
- *
15
- * - Redistributions of source code must retain the above
16
- * copyright notice, this list of conditions and the following
17
- * disclaimer.
18
- *
19
- * - Redistributions in binary form must reproduce the above
20
- * copyright notice, this list of conditions and the following
21
- * disclaimer in the documentation and/or other materials
22
- * provided with the distribution.
23
- *
24
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
- * SOFTWARE.
325 */
336
7
+#include <rdma/rdma_netlink.h>
348 #include <net/addrconf.h>
359 #include "rxe.h"
3610 #include "rxe_loc.h"
....@@ -39,19 +13,15 @@
3913 MODULE_DESCRIPTION("Soft RDMA transport");
4014 MODULE_LICENSE("Dual BSD/GPL");
4115
42
-/* free resources for all ports on a device */
43
-static void rxe_cleanup_ports(struct rxe_dev *rxe)
44
-{
45
- kfree(rxe->port.pkey_tbl);
46
- rxe->port.pkey_tbl = NULL;
47
-
48
-}
16
+bool rxe_initialized;
4917
5018 /* free resources for a rxe device all objects created for this device must
5119 * have been destroyed
5220 */
53
-static void rxe_cleanup(struct rxe_dev *rxe)
21
+void rxe_dealloc(struct ib_device *ib_dev)
5422 {
23
+ struct rxe_dev *rxe = container_of(ib_dev, struct rxe_dev, ib_dev);
24
+
5525 rxe_pool_cleanup(&rxe->uc_pool);
5626 rxe_pool_cleanup(&rxe->pd_pool);
5727 rxe_pool_cleanup(&rxe->ah_pool);
....@@ -63,18 +33,8 @@
6333 rxe_pool_cleanup(&rxe->mc_grp_pool);
6434 rxe_pool_cleanup(&rxe->mc_elem_pool);
6535
66
- rxe_cleanup_ports(rxe);
67
-
68
- crypto_free_shash(rxe->tfm);
69
-}
70
-
71
-/* called when all references have been dropped */
72
-void rxe_release(struct kref *kref)
73
-{
74
- struct rxe_dev *rxe = container_of(kref, struct rxe_dev, ref_cnt);
75
-
76
- rxe_cleanup(rxe);
77
- ib_dealloc_device(&rxe->ib_dev);
36
+ if (rxe->tfm)
37
+ crypto_free_shash(rxe->tfm);
7838 }
7939
8040 /* initialize rxe device parameters */
....@@ -82,12 +42,9 @@
8242 {
8343 rxe->max_inline_data = RXE_MAX_INLINE_DATA;
8444
85
- rxe->attr.fw_ver = RXE_FW_VER;
45
+ rxe->attr.vendor_id = RXE_VENDOR_ID;
8646 rxe->attr.max_mr_size = RXE_MAX_MR_SIZE;
8747 rxe->attr.page_size_cap = RXE_PAGE_SIZE_CAP;
88
- rxe->attr.vendor_id = RXE_VENDOR_ID;
89
- rxe->attr.vendor_part_id = RXE_VENDOR_PART_ID;
90
- rxe->attr.hw_ver = RXE_HW_VER;
9148 rxe->attr.max_qp = RXE_MAX_QP;
9249 rxe->attr.max_qp_wr = RXE_MAX_QP_WR;
9350 rxe->attr.device_cap_flags = RXE_DEVICE_CAP_FLAGS;
....@@ -99,22 +56,13 @@
9956 rxe->attr.max_mr = RXE_MAX_MR;
10057 rxe->attr.max_pd = RXE_MAX_PD;
10158 rxe->attr.max_qp_rd_atom = RXE_MAX_QP_RD_ATOM;
102
- rxe->attr.max_ee_rd_atom = RXE_MAX_EE_RD_ATOM;
10359 rxe->attr.max_res_rd_atom = RXE_MAX_RES_RD_ATOM;
10460 rxe->attr.max_qp_init_rd_atom = RXE_MAX_QP_INIT_RD_ATOM;
105
- rxe->attr.max_ee_init_rd_atom = RXE_MAX_EE_INIT_RD_ATOM;
106
- rxe->attr.atomic_cap = RXE_ATOMIC_CAP;
107
- rxe->attr.max_ee = RXE_MAX_EE;
108
- rxe->attr.max_rdd = RXE_MAX_RDD;
109
- rxe->attr.max_mw = RXE_MAX_MW;
110
- rxe->attr.max_raw_ipv6_qp = RXE_MAX_RAW_IPV6_QP;
111
- rxe->attr.max_raw_ethy_qp = RXE_MAX_RAW_ETHY_QP;
61
+ rxe->attr.atomic_cap = IB_ATOMIC_HCA;
11262 rxe->attr.max_mcast_grp = RXE_MAX_MCAST_GRP;
11363 rxe->attr.max_mcast_qp_attach = RXE_MAX_MCAST_QP_ATTACH;
11464 rxe->attr.max_total_mcast_qp_attach = RXE_MAX_TOT_MCAST_QP_ATTACH;
11565 rxe->attr.max_ah = RXE_MAX_AH;
116
- rxe->attr.max_fmr = RXE_MAX_FMR;
117
- rxe->attr.max_map_per_fmr = RXE_MAX_MAP_PER_FMR;
11866 rxe->attr.max_srq = RXE_MAX_SRQ;
11967 rxe->attr.max_srq_wr = RXE_MAX_SRQ_WR;
12068 rxe->attr.max_srq_sge = RXE_MAX_SRQ_SGE;
....@@ -128,11 +76,11 @@
12876 }
12977
13078 /* initialize port attributes */
131
-static int rxe_init_port_param(struct rxe_port *port)
79
+static void rxe_init_port_param(struct rxe_port *port)
13280 {
133
- port->attr.state = RXE_PORT_STATE;
134
- port->attr.max_mtu = RXE_PORT_MAX_MTU;
135
- port->attr.active_mtu = RXE_PORT_ACTIVE_MTU;
81
+ port->attr.state = IB_PORT_DOWN;
82
+ port->attr.max_mtu = IB_MTU_4096;
83
+ port->attr.active_mtu = IB_MTU_256;
13684 port->attr.gid_tbl_len = RXE_PORT_GID_TBL_LEN;
13785 port->attr.port_cap_flags = RXE_PORT_PORT_CAP_FLAGS;
13886 port->attr.max_msg_sz = RXE_PORT_MAX_MSG_SZ;
....@@ -149,35 +97,21 @@
14997 port->attr.active_width = RXE_PORT_ACTIVE_WIDTH;
15098 port->attr.active_speed = RXE_PORT_ACTIVE_SPEED;
15199 port->attr.phys_state = RXE_PORT_PHYS_STATE;
152
- port->mtu_cap =
153
- ib_mtu_enum_to_int(RXE_PORT_ACTIVE_MTU);
100
+ port->mtu_cap = ib_mtu_enum_to_int(IB_MTU_256);
154101 port->subnet_prefix = cpu_to_be64(RXE_PORT_SUBNET_PREFIX);
155
-
156
- return 0;
157102 }
158103
159104 /* initialize port state, note IB convention that HCA ports are always
160105 * numbered from 1
161106 */
162
-static int rxe_init_ports(struct rxe_dev *rxe)
107
+static void rxe_init_ports(struct rxe_dev *rxe)
163108 {
164109 struct rxe_port *port = &rxe->port;
165110
166111 rxe_init_port_param(port);
167
-
168
- port->pkey_tbl = kcalloc(port->attr.pkey_tbl_len,
169
- sizeof(*port->pkey_tbl), GFP_KERNEL);
170
-
171
- if (!port->pkey_tbl)
172
- return -ENOMEM;
173
-
174
- port->pkey_tbl[0] = 0xffff;
175112 addrconf_addr_eui48((unsigned char *)&port->port_guid,
176113 rxe->ndev->dev_addr);
177
-
178114 spin_lock_init(&port->port_lock);
179
-
180
- return 0;
181115 }
182116
183117 /* init pools of managed objects */
....@@ -267,28 +201,20 @@
267201 /* init default device parameters */
268202 rxe_init_device_param(rxe);
269203
270
- err = rxe_init_ports(rxe);
271
- if (err)
272
- goto err1;
204
+ rxe_init_ports(rxe);
273205
274206 err = rxe_init_pools(rxe);
275207 if (err)
276
- goto err2;
208
+ return err;
277209
278210 /* init pending mmap list */
279211 spin_lock_init(&rxe->mmap_offset_lock);
280212 spin_lock_init(&rxe->pending_lock);
281213 INIT_LIST_HEAD(&rxe->pending_mmaps);
282
- INIT_LIST_HEAD(&rxe->list);
283214
284215 mutex_init(&rxe->usdev_lock);
285216
286217 return 0;
287
-
288
-err2:
289
- rxe_cleanup_ports(rxe);
290
-err1:
291
- return err;
292218 }
293219
294220 void rxe_set_mtu(struct rxe_dev *rxe, unsigned int ndev_mtu)
....@@ -299,7 +225,7 @@
299225 mtu = eth_mtu_int_to_enum(ndev_mtu);
300226
301227 /* Make sure that new MTU in range */
302
- mtu = mtu ? min_t(enum ib_mtu, mtu, RXE_PORT_MAX_MTU) : IB_MTU_256;
228
+ mtu = mtu ? min_t(enum ib_mtu, mtu, IB_MTU_4096) : IB_MTU_256;
303229
304230 port->attr.active_mtu = mtu;
305231 port->mtu_cap = ib_mtu_enum_to_int(mtu);
....@@ -308,64 +234,77 @@
308234 /* called by ifc layer to create new rxe device.
309235 * The caller should allocate memory for rxe by calling ib_alloc_device.
310236 */
311
-int rxe_add(struct rxe_dev *rxe, unsigned int mtu)
237
+int rxe_add(struct rxe_dev *rxe, unsigned int mtu, const char *ibdev_name)
312238 {
313239 int err;
314240
315
- kref_init(&rxe->ref_cnt);
316
-
317241 err = rxe_init(rxe);
318242 if (err)
319
- goto err1;
243
+ return err;
320244
321245 rxe_set_mtu(rxe, mtu);
322246
323
- err = rxe_register_device(rxe);
324
- if (err)
325
- goto err1;
247
+ return rxe_register_device(rxe, ibdev_name);
248
+}
326249
327
- return 0;
250
+static int rxe_newlink(const char *ibdev_name, struct net_device *ndev)
251
+{
252
+ struct rxe_dev *exists;
253
+ int err = 0;
328254
329
-err1:
330
- rxe_dev_put(rxe);
255
+ if (is_vlan_dev(ndev)) {
256
+ pr_err("rxe creation allowed on top of a real device only\n");
257
+ err = -EPERM;
258
+ goto err;
259
+ }
260
+
261
+ exists = rxe_get_dev_from_net(ndev);
262
+ if (exists) {
263
+ ib_device_put(&exists->ib_dev);
264
+ pr_err("already configured on %s\n", ndev->name);
265
+ err = -EEXIST;
266
+ goto err;
267
+ }
268
+
269
+ err = rxe_net_add(ibdev_name, ndev);
270
+ if (err) {
271
+ pr_err("failed to add %s\n", ndev->name);
272
+ goto err;
273
+ }
274
+err:
331275 return err;
332276 }
333277
334
-/* called by the ifc layer to remove a device */
335
-void rxe_remove(struct rxe_dev *rxe)
336
-{
337
- rxe_unregister_device(rxe);
338
-
339
- rxe_dev_put(rxe);
340
-}
278
+static struct rdma_link_ops rxe_link_ops = {
279
+ .type = "rxe",
280
+ .newlink = rxe_newlink,
281
+};
341282
342283 static int __init rxe_module_init(void)
343284 {
344285 int err;
345286
346
- /* initialize slab caches for managed objects */
347
- err = rxe_cache_init();
348
- if (err) {
349
- pr_err("unable to init object pools\n");
350
- return err;
351
- }
352
-
353287 err = rxe_net_init();
354288 if (err)
355289 return err;
356290
291
+ rdma_link_register(&rxe_link_ops);
292
+ rxe_initialized = true;
357293 pr_info("loaded\n");
358294 return 0;
359295 }
360296
361297 static void __exit rxe_module_exit(void)
362298 {
363
- rxe_remove_all();
299
+ rdma_link_unregister(&rxe_link_ops);
300
+ ib_unregister_driver(RDMA_DRIVER_RXE);
364301 rxe_net_exit();
365
- rxe_cache_exit();
366302
303
+ rxe_initialized = false;
367304 pr_info("unloaded\n");
368305 }
369306
370307 late_initcall(rxe_module_init);
371308 module_exit(rxe_module_exit);
309
+
310
+MODULE_ALIAS_RDMA_LINK("rxe");