1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
10 /* Copy argument and remove trailing CR. Return the new length. */
11 static int sanitize_arg(const char *val
, char *intf
, int intf_len
)
19 for (len
= 0; len
< intf_len
- 1 && val
[len
] && val
[len
] != '\n'; len
++)
23 if (len
== 0 || (val
[len
] != 0 && val
[len
] != '\n'))
29 static int rxe_param_set_add(const char *val
, const struct kernel_param
*kp
)
34 struct net_device
*ndev
;
35 struct rxe_dev
*exists
;
37 if (!rxe_initialized
) {
38 pr_err("Module parameters are not supported, use rdma link add or rxe_cfg\n");
42 len
= sanitize_arg(val
, intf
, sizeof(intf
));
44 pr_err("add: invalid interface name\n");
48 ndev
= dev_get_by_name(&init_net
, intf
);
50 pr_err("interface %s not found\n", intf
);
54 if (is_vlan_dev(ndev
)) {
55 pr_err("rxe creation allowed on top of a real device only\n");
60 exists
= rxe_get_dev_from_net(ndev
);
62 ib_device_put(&exists
->ib_dev
);
63 pr_err("already configured on %s\n", intf
);
68 err
= rxe_net_add("rxe%d", ndev
);
70 pr_err("failed to add %s\n", intf
);
79 static int rxe_param_set_remove(const char *val
, const struct kernel_param
*kp
)
83 struct ib_device
*ib_dev
;
85 len
= sanitize_arg(val
, intf
, sizeof(intf
));
87 pr_err("add: invalid interface name\n");
91 if (strncmp("all", intf
, len
) == 0) {
92 pr_info("rxe_sys: remove all");
93 ib_unregister_driver(RDMA_DRIVER_RXE
);
97 ib_dev
= ib_device_get_by_name(intf
, RDMA_DRIVER_RXE
);
99 pr_err("not configured on %s\n", intf
);
103 ib_unregister_device_and_put(ib_dev
);
108 static const struct kernel_param_ops rxe_add_ops
= {
109 .set
= rxe_param_set_add
,
112 static const struct kernel_param_ops rxe_remove_ops
= {
113 .set
= rxe_param_set_remove
,
116 module_param_cb(add
, &rxe_add_ops
, NULL
, 0200);
117 MODULE_PARM_DESC(add
, "DEPRECATED. Create RXE device over network interface");
118 module_param_cb(remove
, &rxe_remove_ops
, NULL
, 0200);
119 MODULE_PARM_DESC(remove
, "DEPRECATED. Remove RXE device over network interface");