Commit | Line | Data |
---|---|---|
7ac9ebd5 | 1 | /* |
630a4d38 | 2 | * Copyright (C) 2017-2018 Netronome Systems, Inc. |
7ac9ebd5 JK |
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 | */ | |
33 | ||
4c7787ba | 34 | #include <linux/bug.h> |
e1740fb6 JK |
35 | #include <linux/lockdep.h> |
36 | #include <linux/rcupdate.h> | |
02082701 | 37 | #include <linux/skbuff.h> |
7ac9ebd5 JK |
38 | #include <linux/slab.h> |
39 | ||
8aa0cb00 | 40 | #include "nfpcore/nfp_cpp.h" |
76abc0f6 | 41 | #include "nfpcore/nfp_nffw.h" |
7ac9ebd5 JK |
42 | #include "nfp_app.h" |
43 | #include "nfp_main.h" | |
9e4c2cfc | 44 | #include "nfp_net.h" |
5de73ee4 | 45 | #include "nfp_net_repr.h" |
7ac9ebd5 | 46 | |
8aa0cb00 | 47 | static const struct nfp_app_type *apps[] = { |
2c4197a0 | 48 | [NFP_APP_CORE_NIC] = &app_nic, |
43b45245 | 49 | #ifdef CONFIG_BPF_SYSCALL |
2c4197a0 | 50 | [NFP_APP_BPF_NIC] = &app_bpf, |
43b45245 JK |
51 | #else |
52 | [NFP_APP_BPF_NIC] = &app_nic, | |
53 | #endif | |
57ae676e | 54 | #ifdef CONFIG_NFP_APP_FLOWER |
2c4197a0 | 55 | [NFP_APP_FLOWER_NIC] = &app_flower, |
57ae676e | 56 | #endif |
8aa0cb00 JK |
57 | }; |
58 | ||
9e4c2cfc JK |
59 | struct nfp_app *nfp_app_from_netdev(struct net_device *netdev) |
60 | { | |
61 | if (nfp_netdev_is_nfp_net(netdev)) { | |
62 | struct nfp_net *nn = netdev_priv(netdev); | |
63 | ||
64 | return nn->app; | |
65 | } | |
66 | ||
67 | if (nfp_netdev_is_nfp_repr(netdev)) { | |
68 | struct nfp_repr *repr = netdev_priv(netdev); | |
69 | ||
70 | return repr->app; | |
71 | } | |
72 | ||
73 | WARN(1, "Unknown netdev type for nfp_app\n"); | |
74 | ||
75 | return NULL; | |
76 | } | |
77 | ||
76abc0f6 JK |
78 | const char *nfp_app_mip_name(struct nfp_app *app) |
79 | { | |
80 | if (!app || !app->pf->mip) | |
81 | return ""; | |
82 | return nfp_mip_name(app->pf->mip); | |
83 | } | |
84 | ||
948faa46 SH |
85 | struct sk_buff * |
86 | nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size, gfp_t priority) | |
02082701 JK |
87 | { |
88 | struct sk_buff *skb; | |
89 | ||
90 | if (nfp_app_ctrl_has_meta(app)) | |
91 | size += 8; | |
92 | ||
948faa46 | 93 | skb = alloc_skb(size, priority); |
02082701 JK |
94 | if (!skb) |
95 | return NULL; | |
96 | ||
97 | if (nfp_app_ctrl_has_meta(app)) | |
98 | skb_reserve(skb, 8); | |
99 | ||
100 | return skb; | |
101 | } | |
102 | ||
e1740fb6 JK |
103 | struct nfp_reprs * |
104 | nfp_reprs_get_locked(struct nfp_app *app, enum nfp_repr_type type) | |
105 | { | |
106 | return rcu_dereference_protected(app->reprs[type], | |
107 | lockdep_is_held(&app->pf->lock)); | |
108 | } | |
109 | ||
5de73ee4 SH |
110 | struct nfp_reprs * |
111 | nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type, | |
112 | struct nfp_reprs *reprs) | |
113 | { | |
114 | struct nfp_reprs *old; | |
115 | ||
e1740fb6 | 116 | old = nfp_reprs_get_locked(app, type); |
5de73ee4 SH |
117 | rcu_assign_pointer(app->reprs[type], reprs); |
118 | ||
5de73ee4 SH |
119 | return old; |
120 | } | |
121 | ||
8aa0cb00 | 122 | struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id) |
7ac9ebd5 JK |
123 | { |
124 | struct nfp_app *app; | |
8aa0cb00 | 125 | |
2c4197a0 | 126 | if (id >= ARRAY_SIZE(apps) || !apps[id]) { |
bf245f1f | 127 | nfp_err(pf->cpp, "unknown FW app ID 0x%02hhx, driver too old or support for FW not built in\n", id); |
8aa0cb00 JK |
128 | return ERR_PTR(-EINVAL); |
129 | } | |
130 | ||
2c4197a0 | 131 | if (WARN_ON(!apps[id]->name || !apps[id]->vnic_alloc)) |
8aa0cb00 | 132 | return ERR_PTR(-EINVAL); |
7ac9ebd5 JK |
133 | |
134 | app = kzalloc(sizeof(*app), GFP_KERNEL); | |
135 | if (!app) | |
136 | return ERR_PTR(-ENOMEM); | |
137 | ||
138 | app->pf = pf; | |
139 | app->cpp = pf->cpp; | |
140 | app->pdev = pf->pdev; | |
2c4197a0 | 141 | app->type = apps[id]; |
7ac9ebd5 JK |
142 | |
143 | return app; | |
144 | } | |
145 | ||
146 | void nfp_app_free(struct nfp_app *app) | |
147 | { | |
148 | kfree(app); | |
149 | } |