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
38static 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
56static void rxe_set_port_state(struct net_device *ndev)
57{
58 struct rxe_dev *rxe = net_to_rxe(ndev);
59 bool is_up = netif_running(ndev) && netif_carrier_ok(ndev);
60
61 if (!rxe)
62 goto out;
63
64 if (is_up)
65 rxe_port_up(rxe);
66 else
67 rxe_port_down(rxe);
68out:
69 return;
70}
71
72static int rxe_param_set_add(const char *val, const struct kernel_param *kp)
73{
74 int len;
75 int err = 0;
76 char intf[32];
77 struct net_device *ndev = NULL;
78 struct rxe_dev *rxe;
79
80 len = sanitize_arg(val, intf, sizeof(intf));
81 if (!len) {
82 pr_err("add: invalid interface name\n");
83 err = -EINVAL;
84 goto err;
85 }
86
87 ndev = dev_get_by_name(&init_net, intf);
88 if (!ndev) {
89 pr_err("interface %s not found\n", intf);
90 err = -EINVAL;
91 goto err;
92 }
93
94 if (net_to_rxe(ndev)) {
95 pr_err("already configured on %s\n", intf);
96 err = -EINVAL;
97 goto err;
98 }
99
100 rxe = rxe_net_add(ndev);
101 if (!rxe) {
102 pr_err("failed to add %s\n", intf);
103 err = -EINVAL;
104 goto err;
105 }
106
107 rxe_set_port_state(ndev);
108 pr_info("added %s to %s\n", rxe->ib_dev.name, intf);
109err:
110 if (ndev)
111 dev_put(ndev);
112 return err;
113}
114
115static int rxe_param_set_remove(const char *val, const struct kernel_param *kp)
116{
117 int len;
118 char intf[32];
119 struct rxe_dev *rxe;
120
121 len = sanitize_arg(val, intf, sizeof(intf));
122 if (!len) {
123 pr_err("add: invalid interface name\n");
124 return -EINVAL;
125 }
126
127 if (strncmp("all", intf, len) == 0) {
128 pr_info("rxe_sys: remove all");
129 rxe_remove_all();
130 return 0;
131 }
132
133 rxe = get_rxe_by_name(intf);
134
135 if (!rxe) {
136 pr_err("not configured on %s\n", intf);
137 return -EINVAL;
138 }
139
140 list_del(&rxe->list);
141 rxe_remove(rxe);
142
143 return 0;
144}
145
146static const struct kernel_param_ops rxe_add_ops = {
147 .set = rxe_param_set_add,
148};
149
150static const struct kernel_param_ops rxe_remove_ops = {
151 .set = rxe_param_set_remove,
152};
153
154module_param_cb(add, &rxe_add_ops, NULL, 0200);
155MODULE_PARM_DESC(add, "Create RXE device over network interface");
156module_param_cb(remove, &rxe_remove_ops, NULL, 0200);
157MODULE_PARM_DESC(remove, "Remove RXE device over network interface");
158