2 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
37 /* Copy argument and remove trailing CR. Return the new length. */
38 static int sanitize_arg(const char *val
, char *intf
, int intf_len
)
46 for (len
= 0; len
< intf_len
- 1 && val
[len
] && val
[len
] != '\n'; len
++)
50 if (len
== 0 || (val
[len
] != 0 && val
[len
] != '\n'))
56 static void rxe_set_port_state(struct net_device
*ndev
)
58 struct rxe_dev
*rxe
= net_to_rxe(ndev
);
59 bool is_up
= netif_running(ndev
) && netif_carrier_ok(ndev
);
67 rxe_port_down(rxe
); /* down for unknown state */
72 static int rxe_param_set_add(const char *val
, const struct kernel_param
*kp
)
77 struct net_device
*ndev
= NULL
;
80 len
= sanitize_arg(val
, intf
, sizeof(intf
));
82 pr_err("add: invalid interface name\n");
87 ndev
= dev_get_by_name(&init_net
, intf
);
89 pr_err("interface %s not found\n", intf
);
94 if (net_to_rxe(ndev
)) {
95 pr_err("already configured on %s\n", intf
);
100 rxe
= rxe_net_add(ndev
);
102 pr_err("failed to add %s\n", intf
);
107 rxe_set_port_state(ndev
);
108 pr_info("added %s to %s\n", rxe
->ib_dev
.name
, intf
);
115 static int rxe_param_set_remove(const char *val
, const struct kernel_param
*kp
)
121 len
= sanitize_arg(val
, intf
, sizeof(intf
));
123 pr_err("add: invalid interface name\n");
127 if (strncmp("all", intf
, len
) == 0) {
128 pr_info("rxe_sys: remove all");
133 rxe
= get_rxe_by_name(intf
);
136 pr_err("not configured on %s\n", intf
);
140 list_del(&rxe
->list
);
146 static const struct kernel_param_ops rxe_add_ops
= {
147 .set
= rxe_param_set_add
,
150 static const struct kernel_param_ops rxe_remove_ops
= {
151 .set
= rxe_param_set_remove
,
154 module_param_cb(add
, &rxe_add_ops
, NULL
, 0200);
155 MODULE_PARM_DESC(add
, "Create RXE device over network interface");
156 module_param_cb(remove
, &rxe_remove_ops
, NULL
, 0200);
157 MODULE_PARM_DESC(remove
, "Remove RXE device over network interface");