.. | .. |
---|
1 | | -/* |
---|
2 | | - * Copyright (C) 2017-2018 Netronome Systems, Inc. |
---|
3 | | - * |
---|
4 | | - * This software is dual licensed under the GNU General License Version 2, |
---|
5 | | - * June 1991 as shown in the file COPYING in the top-level directory of this |
---|
6 | | - * source tree or the BSD 2-Clause License provided below. You have the |
---|
7 | | - * option to license this software under the complete terms of either license. |
---|
8 | | - * |
---|
9 | | - * The BSD 2-Clause License: |
---|
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 | | - * 1. Redistributions of source code must retain the above |
---|
16 | | - * copyright notice, this list of conditions and the following |
---|
17 | | - * disclaimer. |
---|
18 | | - * |
---|
19 | | - * 2. 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 | | - */ |
---|
| 1 | +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) |
---|
| 2 | +/* Copyright (C) 2017-2018 Netronome Systems, Inc. */ |
---|
33 | 3 | |
---|
34 | 4 | #include <linux/bug.h> |
---|
35 | 5 | #include <linux/lockdep.h> |
---|
.. | .. |
---|
59 | 29 | [NFP_APP_ACTIVE_BUFFER_MGMT_NIC] = &app_abm, |
---|
60 | 30 | #endif |
---|
61 | 31 | }; |
---|
| 32 | + |
---|
| 33 | +void nfp_check_rhashtable_empty(void *ptr, void *arg) |
---|
| 34 | +{ |
---|
| 35 | + WARN_ON_ONCE(1); |
---|
| 36 | +} |
---|
62 | 37 | |
---|
63 | 38 | struct nfp_app *nfp_app_from_netdev(struct net_device *netdev) |
---|
64 | 39 | { |
---|
.. | .. |
---|
156 | 131 | struct nfp_reprs *old; |
---|
157 | 132 | |
---|
158 | 133 | old = nfp_reprs_get_locked(app, type); |
---|
| 134 | + rtnl_lock(); |
---|
159 | 135 | rcu_assign_pointer(app->reprs[type], reprs); |
---|
| 136 | + rtnl_unlock(); |
---|
160 | 137 | |
---|
161 | 138 | return old; |
---|
162 | 139 | } |
---|
163 | 140 | |
---|
| 141 | +static void |
---|
| 142 | +nfp_app_netdev_feat_change(struct nfp_app *app, struct net_device *netdev) |
---|
| 143 | +{ |
---|
| 144 | + struct nfp_net *nn; |
---|
| 145 | + unsigned int type; |
---|
| 146 | + |
---|
| 147 | + if (!nfp_netdev_is_nfp_net(netdev)) |
---|
| 148 | + return; |
---|
| 149 | + nn = netdev_priv(netdev); |
---|
| 150 | + if (nn->app != app) |
---|
| 151 | + return; |
---|
| 152 | + |
---|
| 153 | + for (type = 0; type < __NFP_REPR_TYPE_MAX; type++) { |
---|
| 154 | + struct nfp_reprs *reprs; |
---|
| 155 | + unsigned int i; |
---|
| 156 | + |
---|
| 157 | + reprs = rtnl_dereference(app->reprs[type]); |
---|
| 158 | + if (!reprs) |
---|
| 159 | + continue; |
---|
| 160 | + |
---|
| 161 | + for (i = 0; i < reprs->num_reprs; i++) { |
---|
| 162 | + struct net_device *repr; |
---|
| 163 | + |
---|
| 164 | + repr = rtnl_dereference(reprs->reprs[i]); |
---|
| 165 | + if (!repr) |
---|
| 166 | + continue; |
---|
| 167 | + |
---|
| 168 | + nfp_repr_transfer_features(repr, netdev); |
---|
| 169 | + } |
---|
| 170 | + } |
---|
| 171 | +} |
---|
| 172 | + |
---|
| 173 | +static int |
---|
| 174 | +nfp_app_netdev_event(struct notifier_block *nb, unsigned long event, void *ptr) |
---|
| 175 | +{ |
---|
| 176 | + struct net_device *netdev; |
---|
| 177 | + struct nfp_app *app; |
---|
| 178 | + |
---|
| 179 | + netdev = netdev_notifier_info_to_dev(ptr); |
---|
| 180 | + app = container_of(nb, struct nfp_app, netdev_nb); |
---|
| 181 | + |
---|
| 182 | + /* Handle events common code is interested in */ |
---|
| 183 | + switch (event) { |
---|
| 184 | + case NETDEV_FEAT_CHANGE: |
---|
| 185 | + nfp_app_netdev_feat_change(app, netdev); |
---|
| 186 | + break; |
---|
| 187 | + } |
---|
| 188 | + |
---|
| 189 | + /* Call offload specific handlers */ |
---|
| 190 | + if (app->type->netdev_event) |
---|
| 191 | + return app->type->netdev_event(app, netdev, event, ptr); |
---|
| 192 | + return NOTIFY_DONE; |
---|
| 193 | +} |
---|
| 194 | + |
---|
| 195 | +int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl) |
---|
| 196 | +{ |
---|
| 197 | + int err; |
---|
| 198 | + |
---|
| 199 | + app->ctrl = ctrl; |
---|
| 200 | + |
---|
| 201 | + if (app->type->start) { |
---|
| 202 | + err = app->type->start(app); |
---|
| 203 | + if (err) |
---|
| 204 | + return err; |
---|
| 205 | + } |
---|
| 206 | + |
---|
| 207 | + app->netdev_nb.notifier_call = nfp_app_netdev_event; |
---|
| 208 | + err = register_netdevice_notifier(&app->netdev_nb); |
---|
| 209 | + if (err) |
---|
| 210 | + goto err_app_stop; |
---|
| 211 | + |
---|
| 212 | + return 0; |
---|
| 213 | + |
---|
| 214 | +err_app_stop: |
---|
| 215 | + if (app->type->stop) |
---|
| 216 | + app->type->stop(app); |
---|
| 217 | + return err; |
---|
| 218 | +} |
---|
| 219 | + |
---|
| 220 | +void nfp_app_stop(struct nfp_app *app) |
---|
| 221 | +{ |
---|
| 222 | + unregister_netdevice_notifier(&app->netdev_nb); |
---|
| 223 | + |
---|
| 224 | + if (app->type->stop) |
---|
| 225 | + app->type->stop(app); |
---|
| 226 | +} |
---|
| 227 | + |
---|
164 | 228 | struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id) |
---|
165 | 229 | { |
---|
166 | 230 | struct nfp_app *app; |
---|