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_FLOWER_CMSG_H 35 #define NFP_FLOWER_CMSG_H 36 37 #include <linux/bitfield.h> 38 #include <linux/skbuff.h> 39 #include <linux/types.h> 40 41 #include "../nfp_app.h" 42 43 #define NFP_FLOWER_LAYER_META BIT(0) 44 #define NFP_FLOWER_LAYER_PORT BIT(1) 45 #define NFP_FLOWER_LAYER_MAC BIT(2) 46 #define NFP_FLOWER_LAYER_TP BIT(3) 47 #define NFP_FLOWER_LAYER_IPV4 BIT(4) 48 #define NFP_FLOWER_LAYER_IPV6 BIT(5) 49 #define NFP_FLOWER_LAYER_CT BIT(6) 50 #define NFP_FLOWER_LAYER_VXLAN BIT(7) 51 52 #define NFP_FLOWER_LAYER_ETHER BIT(3) 53 #define NFP_FLOWER_LAYER_ARP BIT(4) 54 55 #define NFP_FLOWER_MASK_VLAN_PRIO GENMASK(15, 13) 56 #define NFP_FLOWER_MASK_VLAN_CFI BIT(12) 57 #define NFP_FLOWER_MASK_VLAN_VID GENMASK(11, 0) 58 59 #define NFP_FL_SC_ACT_DROP 0x80000000 60 #define NFP_FL_SC_ACT_USER 0x7D000000 61 #define NFP_FL_SC_ACT_POPV 0x6A000000 62 #define NFP_FL_SC_ACT_NULL 0x00000000 63 64 /* The maximum action list size (in bytes) supported by the NFP. 65 */ 66 #define NFP_FL_MAX_A_SIZ 1216 67 #define NFP_FL_LW_SIZ 2 68 69 /* Action opcodes */ 70 #define NFP_FL_ACTION_OPCODE_OUTPUT 0 71 #define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1 72 #define NFP_FL_ACTION_OPCODE_POP_VLAN 2 73 #define NFP_FL_ACTION_OPCODE_NUM 32 74 75 #define NFP_FL_ACT_JMP_ID GENMASK(15, 8) 76 #define NFP_FL_ACT_LEN_LW GENMASK(7, 0) 77 78 #define NFP_FL_OUT_FLAGS_LAST BIT(15) 79 #define NFP_FL_OUT_FLAGS_USE_TUN BIT(4) 80 #define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0) 81 82 #define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13) 83 #define NFP_FL_PUSH_VLAN_CFI BIT(12) 84 #define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0) 85 86 struct nfp_fl_output { 87 __be16 a_op; 88 __be16 flags; 89 __be32 port; 90 }; 91 92 struct nfp_fl_push_vlan { 93 __be16 a_op; 94 __be16 reserved; 95 __be16 vlan_tpid; 96 __be16 vlan_tci; 97 }; 98 99 struct nfp_fl_pop_vlan { 100 __be16 a_op; 101 __be16 reserved; 102 }; 103 104 /* Metadata without L2 (1W/4B) 105 * ---------------------------------------------------------------- 106 * 3 2 1 107 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 108 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 109 * | key_layers | mask_id | reserved | 110 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 111 */ 112 struct nfp_flower_meta_one { 113 u8 nfp_flow_key_layer; 114 u8 mask_id; 115 u16 reserved; 116 }; 117 118 /* Metadata with L2 (1W/4B) 119 * ---------------------------------------------------------------- 120 * 3 2 1 121 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 122 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 123 * | key_type | mask_id | PCP |p| vlan outermost VID | 124 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 125 * ^ ^ 126 * NOTE: | TCI | 127 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 128 */ 129 struct nfp_flower_meta_two { 130 u8 nfp_flow_key_layer; 131 u8 mask_id; 132 __be16 tci; 133 }; 134 135 /* Port details (1W/4B) 136 * ---------------------------------------------------------------- 137 * 3 2 1 138 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 139 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 140 * | port_ingress | 141 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 142 */ 143 struct nfp_flower_in_port { 144 __be32 in_port; 145 }; 146 147 /* L2 details (4W/16B) 148 * 3 2 1 149 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 150 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 151 * | mac_addr_dst, 31 - 0 | 152 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 153 * | mac_addr_dst, 47 - 32 | mac_addr_src, 15 - 0 | 154 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 155 * | mac_addr_src, 47 - 16 | 156 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 157 * | mpls outermost label | TC |B| reserved |q| 158 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 159 */ 160 struct nfp_flower_mac_mpls { 161 u8 mac_dst[6]; 162 u8 mac_src[6]; 163 __be32 mpls_lse; 164 }; 165 166 /* L4 ports (for UDP, TCP, SCTP) (1W/4B) 167 * 3 2 1 168 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 169 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 170 * | port_src | port_dst | 171 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 172 */ 173 struct nfp_flower_tp_ports { 174 __be16 port_src; 175 __be16 port_dst; 176 }; 177 178 /* L3 IPv4 details (3W/12B) 179 * 3 2 1 180 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 181 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 182 * | DSCP |ECN| protocol | reserved | 183 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 184 * | ipv4_addr_src | 185 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 186 * | ipv4_addr_dst | 187 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 188 */ 189 struct nfp_flower_ipv4 { 190 u8 tos; 191 u8 proto; 192 u8 ttl; 193 u8 reserved; 194 __be32 ipv4_src; 195 __be32 ipv4_dst; 196 }; 197 198 /* L3 IPv6 details (10W/40B) 199 * 3 2 1 200 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 201 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 202 * | DSCP |ECN| protocol | reserved | 203 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 204 * | ipv6_exthdr | res | ipv6_flow_label | 205 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 206 * | ipv6_addr_src, 31 - 0 | 207 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 208 * | ipv6_addr_src, 63 - 32 | 209 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 210 * | ipv6_addr_src, 95 - 64 | 211 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 212 * | ipv6_addr_src, 127 - 96 | 213 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 214 * | ipv6_addr_dst, 31 - 0 | 215 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 216 * | ipv6_addr_dst, 63 - 32 | 217 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 218 * | ipv6_addr_dst, 95 - 64 | 219 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 220 * | ipv6_addr_dst, 127 - 96 | 221 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 222 */ 223 struct nfp_flower_ipv6 { 224 u8 tos; 225 u8 proto; 226 u8 ttl; 227 u8 reserved; 228 __be32 ipv6_flow_label_exthdr; 229 struct in6_addr ipv6_src; 230 struct in6_addr ipv6_dst; 231 }; 232 233 /* The base header for a control message packet. 234 * Defines an 8-bit version, and an 8-bit type, padded 235 * to a 32-bit word. Rest of the packet is type-specific. 236 */ 237 struct nfp_flower_cmsg_hdr { 238 __be16 pad; 239 u8 type; 240 u8 version; 241 }; 242 243 #define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr) 244 #define NFP_FLOWER_CMSG_VER1 1 245 246 /* Types defined for port related control messages */ 247 enum nfp_flower_cmsg_type_port { 248 NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0, 249 NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2, 250 NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7, 251 NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8, 252 NFP_FLOWER_CMSG_TYPE_FLOW_STATS = 15, 253 NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16, 254 NFP_FLOWER_CMSG_TYPE_MAX = 32, 255 }; 256 257 /* NFP_FLOWER_CMSG_TYPE_MAC_REPR */ 258 struct nfp_flower_cmsg_mac_repr { 259 u8 reserved[3]; 260 u8 num_ports; 261 struct { 262 u8 idx; 263 u8 info; 264 u8 nbi_port; 265 u8 phys_port; 266 } ports[0]; 267 }; 268 269 #define NFP_FLOWER_CMSG_MAC_REPR_NBI GENMASK(1, 0) 270 271 /* NFP_FLOWER_CMSG_TYPE_PORT_MOD */ 272 struct nfp_flower_cmsg_portmod { 273 __be32 portnum; 274 u8 reserved; 275 u8 info; 276 __be16 mtu; 277 }; 278 279 #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0) 280 281 enum nfp_flower_cmsg_port_type { 282 NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0, 283 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1, 284 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2, 285 }; 286 287 enum nfp_flower_cmsg_port_vnic_type { 288 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0, 289 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1, 290 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2, 291 }; 292 293 #define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28) 294 #define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24) 295 #define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22) 296 #define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14) 297 #define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12) 298 #define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6) 299 #define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0) 300 #define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0) 301 302 static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port) 303 { 304 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) | 305 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE, 306 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT); 307 } 308 309 static inline u32 310 nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type, 311 u8 vnic, u8 q) 312 { 313 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) | 314 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) | 315 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) | 316 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) | 317 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE, 318 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT); 319 } 320 321 static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb) 322 { 323 return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN; 324 } 325 326 struct sk_buff * 327 nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports); 328 void 329 nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx, 330 unsigned int nbi, unsigned int nbi_port, 331 unsigned int phys_port); 332 int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok); 333 void nfp_flower_cmsg_process_rx(struct work_struct *work); 334 void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb); 335 struct sk_buff * 336 nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size, 337 enum nfp_flower_cmsg_type_port type); 338 339 #endif 340