1 /* 2 * Copyright (C) 2017 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 enum bpf_cap_tlv_type { 41 NFP_BPF_CAP_TYPE_FUNC = 1, 42 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; 49 }; 50 51 struct nfp_bpf_cap_tlv_adjust_head { 52 __le32 flags; 53 __le32 off_min; 54 __le32 off_max; 55 __le32 guaranteed_sub; 56 __le32 guaranteed_add; 57 }; 58 59 #define NFP_BPF_ADJUST_HEAD_NO_META BIT(0) 60 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 70 /* 71 * Types defined for map related control messages 72 */ 73 #define CMSG_MAP_ABI_VERSION 1 74 75 enum nfp_bpf_cmsg_type { 76 CMSG_TYPE_MAP_ALLOC = 1, 77 CMSG_TYPE_MAP_FREE = 2, 78 CMSG_TYPE_MAP_LOOKUP = 3, 79 CMSG_TYPE_MAP_UPDATE = 4, 80 CMSG_TYPE_MAP_DELETE = 5, 81 CMSG_TYPE_MAP_GETNEXT = 6, 82 CMSG_TYPE_MAP_GETFIRST = 7, 83 __CMSG_TYPE_MAP_MAX, 84 }; 85 86 #define CMSG_TYPE_MAP_REPLY_BIT 7 87 #define __CMSG_REPLY(req) (BIT(CMSG_TYPE_MAP_REPLY_BIT) | (req)) 88 89 #define CMSG_MAP_KEY_LW 16 90 #define CMSG_MAP_VALUE_LW 16 91 92 enum nfp_bpf_cmsg_status { 93 CMSG_RC_SUCCESS = 0, 94 CMSG_RC_ERR_MAP_FD = 1, 95 CMSG_RC_ERR_MAP_NOENT = 2, 96 CMSG_RC_ERR_MAP_ERR = 3, 97 CMSG_RC_ERR_MAP_PARSE = 4, 98 CMSG_RC_ERR_MAP_EXIST = 5, 99 CMSG_RC_ERR_MAP_NOMEM = 6, 100 CMSG_RC_ERR_MAP_E2BIG = 7, 101 }; 102 103 struct cmsg_hdr { 104 u8 type; 105 u8 ver; 106 __be16 tag; 107 }; 108 109 struct cmsg_reply_map_simple { 110 struct cmsg_hdr hdr; 111 __be32 rc; 112 }; 113 114 struct cmsg_req_map_alloc_tbl { 115 struct cmsg_hdr hdr; 116 __be32 key_size; /* in bytes */ 117 __be32 value_size; /* in bytes */ 118 __be32 max_entries; 119 __be32 map_type; 120 __be32 map_flags; /* reserved */ 121 }; 122 123 struct cmsg_reply_map_alloc_tbl { 124 struct cmsg_reply_map_simple reply_hdr; 125 __be32 tid; 126 }; 127 128 struct cmsg_req_map_free_tbl { 129 struct cmsg_hdr hdr; 130 __be32 tid; 131 }; 132 133 struct cmsg_reply_map_free_tbl { 134 struct cmsg_reply_map_simple reply_hdr; 135 __be32 count; 136 }; 137 138 struct cmsg_key_value_pair { 139 __be32 key[CMSG_MAP_KEY_LW]; 140 __be32 value[CMSG_MAP_VALUE_LW]; 141 }; 142 143 struct cmsg_req_map_op { 144 struct cmsg_hdr hdr; 145 __be32 tid; 146 __be32 count; 147 __be32 flags; 148 struct cmsg_key_value_pair elem[0]; 149 }; 150 151 struct cmsg_reply_map_op { 152 struct cmsg_reply_map_simple reply_hdr; 153 __be32 count; 154 __be32 resv; 155 struct cmsg_key_value_pair elem[0]; 156 }; 157 #endif 158