xref: /linux/drivers/net/ethernet/netronome/nfp/bpf/fw.h (revision 44f57d78)
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
3 
4 #ifndef NFP_BPF_FW_H
5 #define NFP_BPF_FW_H 1
6 
7 #include <linux/bitops.h>
8 #include <linux/types.h>
9 #include "../ccm.h"
10 
11 /* Kernel's enum bpf_reg_type is not uABI so people may change it breaking
12  * our FW ABI.  In that case we will do translation in the driver.
13  */
14 #define NFP_BPF_SCALAR_VALUE		1
15 #define NFP_BPF_MAP_VALUE		4
16 #define NFP_BPF_STACK			6
17 #define NFP_BPF_PACKET_DATA		8
18 
19 enum bpf_cap_tlv_type {
20 	NFP_BPF_CAP_TYPE_FUNC		= 1,
21 	NFP_BPF_CAP_TYPE_ADJUST_HEAD	= 2,
22 	NFP_BPF_CAP_TYPE_MAPS		= 3,
23 	NFP_BPF_CAP_TYPE_RANDOM		= 4,
24 	NFP_BPF_CAP_TYPE_QUEUE_SELECT	= 5,
25 	NFP_BPF_CAP_TYPE_ADJUST_TAIL	= 6,
26 	NFP_BPF_CAP_TYPE_ABI_VERSION	= 7,
27 };
28 
29 struct nfp_bpf_cap_tlv_func {
30 	__le32 func_id;
31 	__le32 func_addr;
32 };
33 
34 struct nfp_bpf_cap_tlv_adjust_head {
35 	__le32 flags;
36 	__le32 off_min;
37 	__le32 off_max;
38 	__le32 guaranteed_sub;
39 	__le32 guaranteed_add;
40 };
41 
42 #define NFP_BPF_ADJUST_HEAD_NO_META	BIT(0)
43 
44 struct nfp_bpf_cap_tlv_maps {
45 	__le32 types;
46 	__le32 max_maps;
47 	__le32 max_elems;
48 	__le32 max_key_sz;
49 	__le32 max_val_sz;
50 	__le32 max_elem_sz;
51 };
52 
53 /*
54  * Types defined for map related control messages
55  */
56 
57 /* BPF ABIv2 fixed-length control message fields */
58 #define CMSG_MAP_KEY_LW			16
59 #define CMSG_MAP_VALUE_LW		16
60 
61 enum nfp_bpf_cmsg_status {
62 	CMSG_RC_SUCCESS			= 0,
63 	CMSG_RC_ERR_MAP_FD		= 1,
64 	CMSG_RC_ERR_MAP_NOENT		= 2,
65 	CMSG_RC_ERR_MAP_ERR		= 3,
66 	CMSG_RC_ERR_MAP_PARSE		= 4,
67 	CMSG_RC_ERR_MAP_EXIST		= 5,
68 	CMSG_RC_ERR_MAP_NOMEM		= 6,
69 	CMSG_RC_ERR_MAP_E2BIG		= 7,
70 };
71 
72 struct cmsg_reply_map_simple {
73 	struct nfp_ccm_hdr hdr;
74 	__be32 rc;
75 };
76 
77 struct cmsg_req_map_alloc_tbl {
78 	struct nfp_ccm_hdr hdr;
79 	__be32 key_size;		/* in bytes */
80 	__be32 value_size;		/* in bytes */
81 	__be32 max_entries;
82 	__be32 map_type;
83 	__be32 map_flags;		/* reserved */
84 };
85 
86 struct cmsg_reply_map_alloc_tbl {
87 	struct cmsg_reply_map_simple reply_hdr;
88 	__be32 tid;
89 };
90 
91 struct cmsg_req_map_free_tbl {
92 	struct nfp_ccm_hdr hdr;
93 	__be32 tid;
94 };
95 
96 struct cmsg_reply_map_free_tbl {
97 	struct cmsg_reply_map_simple reply_hdr;
98 	__be32 count;
99 };
100 
101 struct cmsg_req_map_op {
102 	struct nfp_ccm_hdr hdr;
103 	__be32 tid;
104 	__be32 count;
105 	__be32 flags;
106 	u8 data[0];
107 };
108 
109 struct cmsg_reply_map_op {
110 	struct cmsg_reply_map_simple reply_hdr;
111 	__be32 count;
112 	__be32 resv;
113 	u8 data[0];
114 };
115 
116 struct cmsg_bpf_event {
117 	struct nfp_ccm_hdr hdr;
118 	__be32 cpu_id;
119 	__be64 map_ptr;
120 	__be32 data_size;
121 	__be32 pkt_size;
122 	u8 data[0];
123 };
124 #endif
125