Skip to content

Commit 9d080d5

Browse files
Jakub Kicinskiborkmann
authored andcommitted
nfp: bpf: parse function call and map capabilities
Parse helper function and supported map FW TLV capabilities. Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent ff3d43f commit 9d080d5

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

drivers/net/ethernet/netronome/nfp/bpf/fw.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@
3838
#include <linux/types.h>
3939

4040
enum bpf_cap_tlv_type {
41+
NFP_BPF_CAP_TYPE_FUNC = 1,
4142
NFP_BPF_CAP_TYPE_ADJUST_HEAD = 2,
43+
NFP_BPF_CAP_TYPE_MAPS = 3,
44+
};
45+
46+
struct nfp_bpf_cap_tlv_func {
47+
__le32 func_id;
48+
__le32 func_addr;
4249
};
4350

4451
struct nfp_bpf_cap_tlv_adjust_head {
@@ -51,6 +58,15 @@ struct nfp_bpf_cap_tlv_adjust_head {
5158

5259
#define NFP_BPF_ADJUST_HEAD_NO_META BIT(0)
5360

61+
struct nfp_bpf_cap_tlv_maps {
62+
__le32 types;
63+
__le32 max_maps;
64+
__le32 max_elems;
65+
__le32 max_key_sz;
66+
__le32 max_val_sz;
67+
__le32 max_elem_sz;
68+
};
69+
5470
/*
5571
* Types defined for map related control messages
5672
*/

drivers/net/ethernet/netronome/nfp/bpf/main.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,45 @@ nfp_bpf_parse_cap_adjust_head(struct nfp_app_bpf *bpf, void __iomem *value,
251251
return 0;
252252
}
253253

254+
static int
255+
nfp_bpf_parse_cap_func(struct nfp_app_bpf *bpf, void __iomem *value, u32 length)
256+
{
257+
struct nfp_bpf_cap_tlv_func __iomem *cap = value;
258+
259+
if (length < sizeof(*cap)) {
260+
nfp_err(bpf->app->cpp, "truncated function TLV: %d\n", length);
261+
return -EINVAL;
262+
}
263+
264+
switch (readl(&cap->func_id)) {
265+
case BPF_FUNC_map_lookup_elem:
266+
bpf->helpers.map_lookup = readl(&cap->func_addr);
267+
break;
268+
}
269+
270+
return 0;
271+
}
272+
273+
static int
274+
nfp_bpf_parse_cap_maps(struct nfp_app_bpf *bpf, void __iomem *value, u32 length)
275+
{
276+
struct nfp_bpf_cap_tlv_maps __iomem *cap = value;
277+
278+
if (length < sizeof(*cap)) {
279+
nfp_err(bpf->app->cpp, "truncated maps TLV: %d\n", length);
280+
return -EINVAL;
281+
}
282+
283+
bpf->maps.types = readl(&cap->types);
284+
bpf->maps.max_maps = readl(&cap->max_maps);
285+
bpf->maps.max_elems = readl(&cap->max_elems);
286+
bpf->maps.max_key_sz = readl(&cap->max_key_sz);
287+
bpf->maps.max_val_sz = readl(&cap->max_val_sz);
288+
bpf->maps.max_elem_sz = readl(&cap->max_elem_sz);
289+
290+
return 0;
291+
}
292+
254293
static int nfp_bpf_parse_capabilities(struct nfp_app *app)
255294
{
256295
struct nfp_cpp *cpp = app->pf->cpp;
@@ -276,11 +315,19 @@ static int nfp_bpf_parse_capabilities(struct nfp_app *app)
276315
goto err_release_free;
277316

278317
switch (type) {
318+
case NFP_BPF_CAP_TYPE_FUNC:
319+
if (nfp_bpf_parse_cap_func(app->priv, value, length))
320+
goto err_release_free;
321+
break;
279322
case NFP_BPF_CAP_TYPE_ADJUST_HEAD:
280323
if (nfp_bpf_parse_cap_adjust_head(app->priv, value,
281324
length))
282325
goto err_release_free;
283326
break;
327+
case NFP_BPF_CAP_TYPE_MAPS:
328+
if (nfp_bpf_parse_cap_maps(app->priv, value, length))
329+
goto err_release_free;
330+
break;
284331
default:
285332
nfp_dbg(cpp, "unknown BPF capability: %d\n", type);
286333
break;

drivers/net/ethernet/netronome/nfp/bpf/main.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ enum pkt_vec {
112112
* @off_max: maximum packet offset within buffer required
113113
* @guaranteed_sub: amount of negative adjustment guaranteed possible
114114
* @guaranteed_add: amount of positive adjustment guaranteed possible
115+
*
116+
* @maps: map capability
117+
* @types: supported map types
118+
* @max_maps: max number of maps supported
119+
* @max_elems: max number of entries in each map
120+
* @max_key_sz: max size of map key
121+
* @max_val_sz: max size of map value
122+
* @max_elem_sz: max size of map entry (key + value)
123+
*
124+
* @helpers: helper addressess for various calls
125+
* @map_lookup: map lookup helper address
115126
*/
116127
struct nfp_app_bpf {
117128
struct nfp_app *app;
@@ -132,6 +143,19 @@ struct nfp_app_bpf {
132143
int guaranteed_sub;
133144
int guaranteed_add;
134145
} adjust_head;
146+
147+
struct {
148+
u32 types;
149+
u32 max_maps;
150+
u32 max_elems;
151+
u32 max_key_sz;
152+
u32 max_val_sz;
153+
u32 max_elem_sz;
154+
} maps;
155+
156+
struct {
157+
u32 map_lookup;
158+
} helpers;
135159
};
136160

137161
/**

0 commit comments

Comments
 (0)