| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. |
|---|
| 3 | 4 | * 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 | 5 | */ |
|---|
| 33 | 6 | |
|---|
| 34 | 7 | #include "rxe.h" |
|---|
| .. | .. |
|---|
| 53 | 26 | return len; |
|---|
| 54 | 27 | } |
|---|
| 55 | 28 | |
|---|
| 56 | | -static 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); /* down for unknown state */ |
|---|
| 68 | | -out: |
|---|
| 69 | | - return; |
|---|
| 70 | | -} |
|---|
| 71 | | - |
|---|
| 72 | 29 | static int rxe_param_set_add(const char *val, const struct kernel_param *kp) |
|---|
| 73 | 30 | { |
|---|
| 74 | 31 | int len; |
|---|
| 75 | 32 | int err = 0; |
|---|
| 76 | 33 | char intf[32]; |
|---|
| 77 | | - struct net_device *ndev = NULL; |
|---|
| 78 | | - struct rxe_dev *rxe; |
|---|
| 34 | + struct net_device *ndev; |
|---|
| 35 | + struct rxe_dev *exists; |
|---|
| 36 | + |
|---|
| 37 | + if (!rxe_initialized) { |
|---|
| 38 | + pr_err("Module parameters are not supported, use rdma link add or rxe_cfg\n"); |
|---|
| 39 | + return -EAGAIN; |
|---|
| 40 | + } |
|---|
| 79 | 41 | |
|---|
| 80 | 42 | len = sanitize_arg(val, intf, sizeof(intf)); |
|---|
| 81 | 43 | if (!len) { |
|---|
| 82 | 44 | pr_err("add: invalid interface name\n"); |
|---|
| 83 | | - err = -EINVAL; |
|---|
| 84 | | - goto err; |
|---|
| 45 | + return -EINVAL; |
|---|
| 85 | 46 | } |
|---|
| 86 | 47 | |
|---|
| 87 | 48 | ndev = dev_get_by_name(&init_net, intf); |
|---|
| 88 | 49 | if (!ndev) { |
|---|
| 89 | 50 | pr_err("interface %s not found\n", intf); |
|---|
| 90 | | - err = -EINVAL; |
|---|
| 51 | + return -EINVAL; |
|---|
| 52 | + } |
|---|
| 53 | + |
|---|
| 54 | + if (is_vlan_dev(ndev)) { |
|---|
| 55 | + pr_err("rxe creation allowed on top of a real device only\n"); |
|---|
| 56 | + err = -EPERM; |
|---|
| 91 | 57 | goto err; |
|---|
| 92 | 58 | } |
|---|
| 93 | 59 | |
|---|
| 94 | | - if (net_to_rxe(ndev)) { |
|---|
| 60 | + exists = rxe_get_dev_from_net(ndev); |
|---|
| 61 | + if (exists) { |
|---|
| 62 | + ib_device_put(&exists->ib_dev); |
|---|
| 95 | 63 | pr_err("already configured on %s\n", intf); |
|---|
| 96 | 64 | err = -EINVAL; |
|---|
| 97 | 65 | goto err; |
|---|
| 98 | 66 | } |
|---|
| 99 | 67 | |
|---|
| 100 | | - rxe = rxe_net_add(ndev); |
|---|
| 101 | | - if (!rxe) { |
|---|
| 68 | + err = rxe_net_add("rxe%d", ndev); |
|---|
| 69 | + if (err) { |
|---|
| 102 | 70 | pr_err("failed to add %s\n", intf); |
|---|
| 103 | | - err = -EINVAL; |
|---|
| 104 | 71 | goto err; |
|---|
| 105 | 72 | } |
|---|
| 106 | 73 | |
|---|
| 107 | | - rxe_set_port_state(ndev); |
|---|
| 108 | | - pr_info("added %s to %s\n", rxe->ib_dev.name, intf); |
|---|
| 109 | 74 | err: |
|---|
| 110 | | - if (ndev) |
|---|
| 111 | | - dev_put(ndev); |
|---|
| 75 | + dev_put(ndev); |
|---|
| 112 | 76 | return err; |
|---|
| 113 | 77 | } |
|---|
| 114 | 78 | |
|---|
| .. | .. |
|---|
| 116 | 80 | { |
|---|
| 117 | 81 | int len; |
|---|
| 118 | 82 | char intf[32]; |
|---|
| 119 | | - struct rxe_dev *rxe; |
|---|
| 83 | + struct ib_device *ib_dev; |
|---|
| 120 | 84 | |
|---|
| 121 | 85 | len = sanitize_arg(val, intf, sizeof(intf)); |
|---|
| 122 | 86 | if (!len) { |
|---|
| .. | .. |
|---|
| 126 | 90 | |
|---|
| 127 | 91 | if (strncmp("all", intf, len) == 0) { |
|---|
| 128 | 92 | pr_info("rxe_sys: remove all"); |
|---|
| 129 | | - rxe_remove_all(); |
|---|
| 93 | + ib_unregister_driver(RDMA_DRIVER_RXE); |
|---|
| 130 | 94 | return 0; |
|---|
| 131 | 95 | } |
|---|
| 132 | 96 | |
|---|
| 133 | | - rxe = get_rxe_by_name(intf); |
|---|
| 134 | | - |
|---|
| 135 | | - if (!rxe) { |
|---|
| 97 | + ib_dev = ib_device_get_by_name(intf, RDMA_DRIVER_RXE); |
|---|
| 98 | + if (!ib_dev) { |
|---|
| 136 | 99 | pr_err("not configured on %s\n", intf); |
|---|
| 137 | 100 | return -EINVAL; |
|---|
| 138 | 101 | } |
|---|
| 139 | 102 | |
|---|
| 140 | | - list_del(&rxe->list); |
|---|
| 141 | | - rxe_remove(rxe); |
|---|
| 103 | + ib_unregister_device_and_put(ib_dev); |
|---|
| 142 | 104 | |
|---|
| 143 | 105 | return 0; |
|---|
| 144 | 106 | } |
|---|
| .. | .. |
|---|
| 152 | 114 | }; |
|---|
| 153 | 115 | |
|---|
| 154 | 116 | module_param_cb(add, &rxe_add_ops, NULL, 0200); |
|---|
| 155 | | -MODULE_PARM_DESC(add, "Create RXE device over network interface"); |
|---|
| 117 | +MODULE_PARM_DESC(add, "DEPRECATED. Create RXE device over network interface"); |
|---|
| 156 | 118 | module_param_cb(remove, &rxe_remove_ops, NULL, 0200); |
|---|
| 157 | | -MODULE_PARM_DESC(remove, "Remove RXE device over network interface"); |
|---|
| 119 | +MODULE_PARM_DESC(remove, "DEPRECATED. Remove RXE device over network interface"); |
|---|