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 
10 /* Kernel's enum bpf_reg_type is not uABI so people may change it breaking
11  * our FW ABI.  In that case we will do translation in the driver.
12  */
13 #define NFP_BPF_SCALAR_VALUE		1
14 #define NFP_BPF_MAP_VALUE		4
15 #define NFP_BPF_STACK			6
16 #define NFP_BPF_PACKET_DATA		8
17 
18 enum bpf_cap_tlv_type {
19 	NFP_BPF_CAP_TYPE_FUNC		= 1,
20 	NFP_BPF_CAP_TYPE_ADJUST_HEAD	= 2,
21 	NFP_BPF_CAP_TYPE_MAPS		= 3,
22 	NFP_BPF_CAP_TYPE_RANDOM		= 4,
23 	NFP_BPF_CAP_TYPE_QUEUE_SELECT	= 5,
24 	NFP_BPF_CAP_TYPE_ADJUST_TAIL	= 6,
25 	NFP_BPF_CAP_TYPE_ABI_VERSION	= 7,
26 };
27 
28 struct nfp_bpf_cap_tlv_func {
29 	__le32 func_id;
30 	__le32 func_addr;
31 };
32 
33 struct nfp_bpf_cap_tlv_adjust_head {
34 	__le32 flags;
35 	__le32 off_min;
36 	__le32 off_max;
37 	__le32 guaranteed_sub;
38 	__le32 guaranteed_add;
39 };
40 
41 #define NFP_BPF_ADJUST_HEAD_NO_META	BIT(0)
42 
43 struct nfp_bpf_cap_tlv_maps {
44 	__le32 types;
45 	__le32 max_maps;
46 	__le32 max_elems;
47 	__le32 max_key_sz;
48 	__le32 max_val_sz;
49 	__le32 max_elem_sz;
50 };
51 
52 /*
53  * Types defined for map related control messages
54  */
55 #define CMSG_MAP_ABI_VERSION		1
56 
57 enum nfp_bpf_cmsg_type {
58 	CMSG_TYPE_MAP_ALLOC	= 1,
59 	CMSG_TYPE_MAP_FREE	= 2,
60 	CMSG_TYPE_MAP_LOOKUP	= 3,
61 	CMSG_TYPE_MAP_UPDATE	= 4,
62 	CMSG_TYPE_MAP_DELETE	= 5,
63 	CMSG_TYPE_MAP_GETNEXT	= 6,
64 	CMSG_TYPE_MAP_GETFIRST	= 7,
65 	CMSG_TYPE_BPF_EVENT	= 8,
66 	__CMSG_TYPE_MAP_MAX,
67 };
68 
69 #define CMSG_TYPE_MAP_REPLY_BIT		7
70 #define __CMSG_REPLY(req)		(BIT(CMSG_TYPE_MAP_REPLY_BIT) | (req))
71 
72 /* BPF ABIv2 fixed-length control message fields */
73 #define CMSG_MAP_KEY_LW			16
74 #define CMSG_MAP_VALUE_LW		16
75 
76 enum nfp_bpf_cmsg_status {
77 	CMSG_RC_SUCCESS			= 0,
78 	CMSG_RC_ERR_MAP_FD		= 1,
79 	CMSG_RC_ERR_MAP_NOENT		= 2,
80 	CMSG_RC_ERR_MAP_ERR		= 3,
81 	CMSG_RC_ERR_MAP_PARSE		= 4,
82 	CMSG_RC_ERR_MAP_EXIST		= 5,
83 	CMSG_RC_ERR_MAP_NOMEM		= 6,
84 	CMSG_RC_ERR_MAP_E2BIG		= 7,
85 };
86 
87 struct cmsg_hdr {
88 	u8 type;
89 	u8 ver;
90 	__be16 tag;
91 };
92 
93 struct cmsg_reply_map_simple {
94 	struct cmsg_hdr hdr;
95 	__be32 rc;
96 };
97 
98 struct cmsg_req_map_alloc_tbl {
99 	struct cmsg_hdr hdr;
100 	__be32 key_size;		/* in bytes */
101 	__be32 value_size;		/* in bytes */
102 	__be32 max_entries;
103 	__be32 map_type;
104 	__be32 map_flags;		/* reserved */
105 };
106 
107 struct cmsg_reply_map_alloc_tbl {
108 	struct cmsg_reply_map_simple reply_hdr;
109 	__be32 tid;
110 };
111 
112 struct cmsg_req_map_free_tbl {
113 	struct cmsg_hdr hdr;
114 	__be32 tid;
115 };
116 
117 struct cmsg_reply_map_free_tbl {
118 	struct cmsg_reply_map_simple reply_hdr;
119 	__be32 count;
120 };
121 
122 struct cmsg_req_map_op {
123 	struct cmsg_hdr hdr;
124 	__be32 tid;
125 	__be32 count;
126 	__be32 flags;
127 	u8 data[0];
128 };
129 
130 struct cmsg_reply_map_op {
131 	struct cmsg_reply_map_simple reply_hdr;
132 	__be32 count;
133 	__be32 resv;
134 	u8 data[0];
135 };
136 
137 struct cmsg_bpf_event {
138 	struct cmsg_hdr hdr;
139 	__be32 cpu_id;
140 	__be64 map_ptr;
141 	__be32 data_size;
142 	__be32 pkt_size;
143 	u8 data[0];
144 };
145 #endif
146