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