• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
3  * 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.
32  */
33 
34 #include "rxe.h"
35 #include "rxe_net.h"
36 
37 /* Copy argument and remove trailing CR. Return the new length. */
sanitize_arg(const char * val,char * intf,int intf_len)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 	/* Remove newline. */
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 
rxe_param_set_add(const char * val,const struct kernel_param * kp)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 	if (!rxe_initialized) {
65 		pr_err("Module parameters are not supported, use rdma link add or rxe_cfg\n");
66 		return -EAGAIN;
67 	}
68 
69 	len = sanitize_arg(val, intf, sizeof(intf));
70 	if (!len) {
71 		pr_err("add: invalid interface name\n");
72 		return -EINVAL;
73 	}
74 
75 	ndev = dev_get_by_name(&init_net, intf);
76 	if (!ndev) {
77 		pr_err("interface %s not found\n", intf);
78 		return -EINVAL;
79 	}
80 
81 	exists = rxe_get_dev_from_net(ndev);
82 	if (exists) {
83 		ib_device_put(&exists->ib_dev);
84 		pr_err("already configured on %s\n", intf);
85 		err = -EINVAL;
86 		goto err;
87 	}
88 
89 	err = rxe_net_add("rxe%d", ndev);
90 	if (err) {
91 		pr_err("failed to add %s\n", intf);
92 		goto err;
93 	}
94 
95 err:
96 	dev_put(ndev);
97 	return err;
98 }
99 
rxe_param_set_remove(const char * val,const struct kernel_param * kp)100 static int rxe_param_set_remove(const char *val, const struct kernel_param *kp)
101 {
102 	int len;
103 	char intf[32];
104 	struct ib_device *ib_dev;
105 
106 	len = sanitize_arg(val, intf, sizeof(intf));
107 	if (!len) {
108 		pr_err("add: invalid interface name\n");
109 		return -EINVAL;
110 	}
111 
112 	if (strncmp("all", intf, len) == 0) {
113 		pr_info("rxe_sys: remove all");
114 		ib_unregister_driver(RDMA_DRIVER_RXE);
115 		return 0;
116 	}
117 
118 	ib_dev = ib_device_get_by_name(intf, RDMA_DRIVER_RXE);
119 	if (!ib_dev) {
120 		pr_err("not configured on %s\n", intf);
121 		return -EINVAL;
122 	}
123 
124 	ib_unregister_device_and_put(ib_dev);
125 
126 	return 0;
127 }
128 
129 static const struct kernel_param_ops rxe_add_ops = {
130 	.set = rxe_param_set_add,
131 };
132 
133 static const struct kernel_param_ops rxe_remove_ops = {
134 	.set = rxe_param_set_remove,
135 };
136 
137 module_param_cb(add, &rxe_add_ops, NULL, 0200);
138 MODULE_PARM_DESC(add, "DEPRECATED.  Create RXE device over network interface");
139 module_param_cb(remove, &rxe_remove_ops, NULL, 0200);
140 MODULE_PARM_DESC(remove, "DEPRECATED.  Remove RXE device over network interface");
141