This source file includes following definitions.
- sanitize_arg
- rxe_param_set_add
- rxe_param_set_remove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include "rxe.h"
35 #include "rxe_net.h"
36
37
38 static int sanitize_arg(const char *val, char *intf, int intf_len)
39 {
40 int len;
41
42 if (!val)
43 return 0;
44
45
46 for (len = 0; len < intf_len - 1 && val[len] && val[len] != '\n'; len++)
47 intf[len] = val[len];
48 intf[len] = 0;
49
50 if (len == 0 || (val[len] != 0 && val[len] != '\n'))
51 return 0;
52
53 return len;
54 }
55
56 static int rxe_param_set_add(const char *val, const struct kernel_param *kp)
57 {
58 int len;
59 int err = 0;
60 char intf[32];
61 struct net_device *ndev;
62 struct rxe_dev *exists;
63
64 len = sanitize_arg(val, intf, sizeof(intf));
65 if (!len) {
66 pr_err("add: invalid interface name\n");
67 return -EINVAL;
68 }
69
70 ndev = dev_get_by_name(&init_net, intf);
71 if (!ndev) {
72 pr_err("interface %s not found\n", intf);
73 return -EINVAL;
74 }
75
76 exists = rxe_get_dev_from_net(ndev);
77 if (exists) {
78 ib_device_put(&exists->ib_dev);
79 pr_err("already configured on %s\n", intf);
80 err = -EINVAL;
81 goto err;
82 }
83
84 err = rxe_net_add("rxe%d", ndev);
85 if (err) {
86 pr_err("failed to add %s\n", intf);
87 goto err;
88 }
89
90 err:
91 dev_put(ndev);
92 return err;
93 }
94
95 static int rxe_param_set_remove(const char *val, const struct kernel_param *kp)
96 {
97 int len;
98 char intf[32];
99 struct ib_device *ib_dev;
100
101 len = sanitize_arg(val, intf, sizeof(intf));
102 if (!len) {
103 pr_err("add: invalid interface name\n");
104 return -EINVAL;
105 }
106
107 if (strncmp("all", intf, len) == 0) {
108 pr_info("rxe_sys: remove all");
109 ib_unregister_driver(RDMA_DRIVER_RXE);
110 return 0;
111 }
112
113 ib_dev = ib_device_get_by_name(intf, RDMA_DRIVER_RXE);
114 if (!ib_dev) {
115 pr_err("not configured on %s\n", intf);
116 return -EINVAL;
117 }
118
119 ib_unregister_device_and_put(ib_dev);
120
121 return 0;
122 }
123
124 static const struct kernel_param_ops rxe_add_ops = {
125 .set = rxe_param_set_add,
126 };
127
128 static const struct kernel_param_ops rxe_remove_ops = {
129 .set = rxe_param_set_remove,
130 };
131
132 module_param_cb(add, &rxe_add_ops, NULL, 0200);
133 MODULE_PARM_DESC(add, "DEPRECATED. Create RXE device over network interface");
134 module_param_cb(remove, &rxe_remove_ops, NULL, 0200);
135 MODULE_PARM_DESC(remove, "DEPRECATED. Remove RXE device over network interface");