brintos

brintos / linux-shallow public Read only

0
0
Text · 24.3 KiB · 2df2af1 Raw
753 lines · c
1/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */2/* Copyright (C) 2017-2018 Netronome Systems, Inc. */3 4#ifndef NFP_FLOWER_CMSG_H5#define NFP_FLOWER_CMSG_H6 7#include <linux/bitfield.h>8#include <linux/skbuff.h>9#include <linux/types.h>10#include <net/geneve.h>11#include <net/gre.h>12#include <net/vxlan.h>13 14#include "../nfp_app.h"15#include "../nfpcore/nfp_cpp.h"16 17#define NFP_FLOWER_LAYER_EXT_META	BIT(0)18#define NFP_FLOWER_LAYER_PORT		BIT(1)19#define NFP_FLOWER_LAYER_MAC		BIT(2)20#define NFP_FLOWER_LAYER_TP		BIT(3)21#define NFP_FLOWER_LAYER_IPV4		BIT(4)22#define NFP_FLOWER_LAYER_IPV6		BIT(5)23#define NFP_FLOWER_LAYER_CT		BIT(6)24#define NFP_FLOWER_LAYER_VXLAN		BIT(7)25 26#define NFP_FLOWER_LAYER2_GRE		BIT(0)27#define NFP_FLOWER_LAYER2_QINQ		BIT(4)28#define NFP_FLOWER_LAYER2_GENEVE	BIT(5)29#define NFP_FLOWER_LAYER2_GENEVE_OP	BIT(6)30#define NFP_FLOWER_LAYER2_TUN_IPV6	BIT(7)31 32#define NFP_FLOWER_MASK_VLAN_PRIO	GENMASK(15, 13)33#define NFP_FLOWER_MASK_VLAN_PRESENT	BIT(12)34#define NFP_FLOWER_MASK_VLAN_VID	GENMASK(11, 0)35 36#define NFP_FLOWER_MASK_MPLS_LB		GENMASK(31, 12)37#define NFP_FLOWER_MASK_MPLS_TC		GENMASK(11, 9)38#define NFP_FLOWER_MASK_MPLS_BOS	BIT(8)39#define NFP_FLOWER_MASK_MPLS_Q		BIT(0)40 41#define NFP_FL_IP_FRAG_FIRST		BIT(7)42#define NFP_FL_IP_FRAGMENTED		BIT(6)43 44/* GRE Tunnel flags */45#define NFP_FL_GRE_FLAG_KEY		BIT(2)46 47/* Compressed HW representation of TCP Flags */48#define NFP_FL_TCP_FLAG_URG		BIT(4)49#define NFP_FL_TCP_FLAG_PSH		BIT(3)50#define NFP_FL_TCP_FLAG_RST		BIT(2)51#define NFP_FL_TCP_FLAG_SYN		BIT(1)52#define NFP_FL_TCP_FLAG_FIN		BIT(0)53 54#define NFP_FL_SC_ACT_DROP		0x8000000055#define NFP_FL_SC_ACT_USER		0x7D00000056#define NFP_FL_SC_ACT_POPV		0x6A00000057#define NFP_FL_SC_ACT_NULL		0x0000000058 59/* The maximum action list size (in bytes) supported by the NFP.60 */61#define NFP_FL_MAX_A_SIZ		121662#define NFP_FL_LW_SIZ			263 64/* Maximum allowed geneve options */65#define NFP_FL_MAX_GENEVE_OPT_ACT	3266#define NFP_FL_MAX_GENEVE_OPT_CNT	6467#define NFP_FL_MAX_GENEVE_OPT_KEY	3268#define NFP_FL_MAX_GENEVE_OPT_KEY_V6	869 70/* Action opcodes */71#define NFP_FL_ACTION_OPCODE_OUTPUT		072#define NFP_FL_ACTION_OPCODE_PUSH_VLAN		173#define NFP_FL_ACTION_OPCODE_POP_VLAN		274#define NFP_FL_ACTION_OPCODE_PUSH_MPLS		375#define NFP_FL_ACTION_OPCODE_POP_MPLS		476#define NFP_FL_ACTION_OPCODE_SET_TUNNEL		677#define NFP_FL_ACTION_OPCODE_SET_ETHERNET	778#define NFP_FL_ACTION_OPCODE_SET_MPLS		879#define NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS	980#define NFP_FL_ACTION_OPCODE_SET_IPV4_TTL_TOS	1081#define NFP_FL_ACTION_OPCODE_SET_IPV6_SRC	1182#define NFP_FL_ACTION_OPCODE_SET_IPV6_DST	1283#define NFP_FL_ACTION_OPCODE_SET_IPV6_TC_HL_FL	1384#define NFP_FL_ACTION_OPCODE_SET_UDP		1485#define NFP_FL_ACTION_OPCODE_SET_TCP		1586#define NFP_FL_ACTION_OPCODE_PRE_LAG		1687#define NFP_FL_ACTION_OPCODE_PRE_TUNNEL		1788#define NFP_FL_ACTION_OPCODE_METER		2489#define NFP_FL_ACTION_OPCODE_PUSH_GENEVE	2690#define NFP_FL_ACTION_OPCODE_NUM		3291 92#define NFP_FL_OUT_FLAGS_LAST		BIT(15)93#define NFP_FL_OUT_FLAGS_USE_TUN	BIT(4)94#define NFP_FL_OUT_FLAGS_TYPE_IDX	GENMASK(2, 0)95 96#define NFP_FL_PUSH_VLAN_PRIO		GENMASK(15, 13)97#define NFP_FL_PUSH_VLAN_VID		GENMASK(11, 0)98 99/* LAG ports */100#define NFP_FL_LAG_OUT			0xC0DE0000101 102/* Tunnel ports */103#define NFP_FL_PORT_TYPE_TUN		0x50000000104#define NFP_FL_TUNNEL_TYPE		GENMASK(7, 4)105#define NFP_FL_PRE_TUN_INDEX		GENMASK(2, 0)106 107#define NFP_FLOWER_WORKQ_MAX_SKBS	30000108 109/* Cmesg reply (empirical) timeout*/110#define NFP_FL_REPLY_TIMEOUT		msecs_to_jiffies(40)111 112#define nfp_flower_cmsg_warn(app, fmt, args...)                         \113	do {                                                            \114		if (net_ratelimit())                                    \115			nfp_warn((app)->cpp, fmt, ## args);             \116	} while (0)117 118enum nfp_flower_tun_type {119	NFP_FL_TUNNEL_NONE =	0,120	NFP_FL_TUNNEL_GRE =	1,121	NFP_FL_TUNNEL_VXLAN =	2,122	NFP_FL_TUNNEL_GENEVE =	4,123};124 125struct nfp_fl_act_head {126	u8 jump_id;127	u8 len_lw;128};129 130struct nfp_fl_set_eth {131	struct nfp_fl_act_head head;132	__be16 reserved;133	u8 eth_addr_mask[ETH_ALEN * 2];134	u8 eth_addr_val[ETH_ALEN * 2];135};136 137struct nfp_fl_set_ip4_addrs {138	struct nfp_fl_act_head head;139	__be16 reserved;140	__be32 ipv4_src_mask;141	__be32 ipv4_src;142	__be32 ipv4_dst_mask;143	__be32 ipv4_dst;144};145 146struct nfp_fl_set_ip4_ttl_tos {147	struct nfp_fl_act_head head;148	u8 ipv4_ttl_mask;149	u8 ipv4_tos_mask;150	u8 ipv4_ttl;151	u8 ipv4_tos;152	__be16 reserved;153};154 155struct nfp_fl_set_ipv6_tc_hl_fl {156	struct nfp_fl_act_head head;157	u8 ipv6_tc_mask;158	u8 ipv6_hop_limit_mask;159	__be16 reserved;160	u8 ipv6_tc;161	u8 ipv6_hop_limit;162	__be32 ipv6_label_mask;163	__be32 ipv6_label;164};165 166struct nfp_fl_set_ipv6_addr {167	struct nfp_fl_act_head head;168	__be16 reserved;169	struct {170		__be32 mask;171		__be32 exact;172	} ipv6[4];173};174 175struct nfp_fl_set_tport {176	struct nfp_fl_act_head head;177	__be16 reserved;178	u8 tp_port_mask[4];179	u8 tp_port_val[4];180};181 182struct nfp_fl_output {183	struct nfp_fl_act_head head;184	__be16 flags;185	__be32 port;186};187 188struct nfp_fl_push_vlan {189	struct nfp_fl_act_head head;190	__be16 reserved;191	__be16 vlan_tpid;192	__be16 vlan_tci;193};194 195struct nfp_fl_pop_vlan {196	struct nfp_fl_act_head head;197	__be16 reserved;198};199 200struct nfp_fl_pre_lag {201	struct nfp_fl_act_head head;202	__be16 group_id;203	u8 lag_version[3];204	u8 instance;205};206 207#define NFP_FL_PRE_LAG_VER_OFF	8208 209struct nfp_fl_pre_tunnel {210	struct nfp_fl_act_head head;211	__be16 flags;212	union {213		__be32 ipv4_dst;214		struct in6_addr ipv6_dst;215	};216};217 218#define NFP_FL_PRE_TUN_IPV6	BIT(0)219 220struct nfp_fl_set_tun {221	struct nfp_fl_act_head head;222	__be16 reserved;223	__be64 tun_id __packed;224	__be32 tun_type_index;225	__be16 tun_flags;226	u8 ttl;227	u8 tos;228	__be16 outer_vlan_tpid;229	__be16 outer_vlan_tci;230	u8 tun_len;231	u8 res2;232	__be16 tun_proto;233};234 235struct nfp_fl_push_geneve {236	struct nfp_fl_act_head head;237	__be16 reserved;238	__be16 class;239	u8 type;240	u8 length;241	u8 opt_data[];242};243 244struct nfp_fl_push_mpls {245	struct nfp_fl_act_head head;246	__be16 ethtype;247	__be32 lse;248};249 250struct nfp_fl_pop_mpls {251	struct nfp_fl_act_head head;252	__be16 ethtype;253};254 255struct nfp_fl_set_mpls {256	struct nfp_fl_act_head head;257	__be16 reserved;258	__be32 lse_mask;259	__be32 lse;260};261 262struct nfp_fl_meter {263	struct nfp_fl_act_head head;264	__be16 reserved;265	__be32 meter_id;266};267 268/* Metadata with L2 (1W/4B)269 * ----------------------------------------------------------------270 *    3                   2                   1271 *  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 0272 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+273 * |    key_type   |    mask_id    | PCP |p|   vlan outermost VID  |274 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+275 *                                 ^                               ^276 *                           NOTE: |             TCI               |277 *                                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+278 */279struct nfp_flower_meta_tci {280	u8 nfp_flow_key_layer;281	u8 mask_id;282	__be16 tci;283};284 285/* Extended metadata for additional key_layers (1W/4B)286 * ----------------------------------------------------------------287 *    3                   2                   1288 *  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 0289 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+290 * |                      nfp_flow_key_layer2                      |291 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+292 */293struct nfp_flower_ext_meta {294	__be32 nfp_flow_key_layer2;295};296 297/* Port details (1W/4B)298 * ----------------------------------------------------------------299 *    3                   2                   1300 *  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 0301 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+302 * |                         port_ingress                          |303 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+304 */305struct nfp_flower_in_port {306	__be32 in_port;307};308 309/* L2 details (4W/16B)310 *    3                   2                   1311 *  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 0312 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+313 * |                     mac_addr_dst, 31 - 0                      |314 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+315 * |      mac_addr_dst, 47 - 32    |     mac_addr_src, 15 - 0      |316 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+317 * |                     mac_addr_src, 47 - 16                     |318 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+319 * |       mpls outermost label            |  TC |B|   reserved  |q|320 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+321 */322struct nfp_flower_mac_mpls {323	u8 mac_dst[6];324	u8 mac_src[6];325	__be32 mpls_lse;326};327 328/* VLAN details (2W/8B)329 *    3                   2                   1330 *  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 0331 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+332 * |           outer_tpid          |           outer_tci           |333 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+334 * |           inner_tpid          |           inner_tci           |335 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+336 */337struct nfp_flower_vlan {338	__be16 outer_tpid;339	__be16 outer_tci;340	__be16 inner_tpid;341	__be16 inner_tci;342};343 344/* L4 ports (for UDP, TCP, SCTP) (1W/4B)345 *    3                   2                   1346 *  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 0347 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+348 * |            port_src           |           port_dst            |349 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+350 */351struct nfp_flower_tp_ports {352	__be16 port_src;353	__be16 port_dst;354};355 356struct nfp_flower_ip_ext {357	u8 tos;358	u8 proto;359	u8 ttl;360	u8 flags;361};362 363/* L3 IPv4 details (3W/12B)364 *    3                   2                   1365 *  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 0366 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+367 * |    DSCP   |ECN|   protocol    |      ttl      |     flags     |368 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+369 * |                        ipv4_addr_src                          |370 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+371 * |                        ipv4_addr_dst                          |372 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+373 */374struct nfp_flower_ipv4 {375	struct nfp_flower_ip_ext ip_ext;376	__be32 ipv4_src;377	__be32 ipv4_dst;378};379 380/* L3 IPv6 details (10W/40B)381 *    3                   2                   1382 *  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 0383 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+384 * |    DSCP   |ECN|   protocol    |      ttl      |     flags     |385 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+386 * |   ipv6_exthdr   | res |            ipv6_flow_label            |387 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+388 * |                  ipv6_addr_src,   31 - 0                      |389 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+390 * |                  ipv6_addr_src,  63 - 32                      |391 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+392 * |                  ipv6_addr_src,  95 - 64                      |393 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+394 * |                  ipv6_addr_src, 127 - 96                      |395 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+396 * |                  ipv6_addr_dst,   31 - 0                      |397 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+398 * |                  ipv6_addr_dst,  63 - 32                      |399 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+400 * |                  ipv6_addr_dst,  95 - 64                      |401 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+402 * |                  ipv6_addr_dst, 127 - 96                      |403 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+404 */405struct nfp_flower_ipv6 {406	struct nfp_flower_ip_ext ip_ext;407	__be32 ipv6_flow_label_exthdr;408	struct in6_addr ipv6_src;409	struct in6_addr ipv6_dst;410};411 412struct nfp_flower_tun_ipv4 {413	__be32 src;414	__be32 dst;415};416 417struct nfp_flower_tun_ipv6 {418	struct in6_addr src;419	struct in6_addr dst;420};421 422struct nfp_flower_tun_ip_ext {423	u8 tos;424	u8 ttl;425};426 427/* Flow Frame IPv4 UDP TUNNEL --> Tunnel details (4W/16B)428 * -----------------------------------------------------------------429 *    3                   2                   1430 *  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 0431 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+432 * |                         ipv4_addr_src                         |433 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+434 * |                         ipv4_addr_dst                         |435 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+436 * |           Reserved            |      tos      |      ttl      |437 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+438 * |                            Reserved                           |439 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+440 * |                     VNI                       |   Reserved    |441 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+442 */443struct nfp_flower_ipv4_udp_tun {444	struct nfp_flower_tun_ipv4 ipv4;445	__be16 reserved1;446	struct nfp_flower_tun_ip_ext ip_ext;447	__be32 reserved2;448	__be32 tun_id;449};450 451/* Flow Frame IPv6 UDP TUNNEL --> Tunnel details (11W/44B)452 * -----------------------------------------------------------------453 *    3                   2                   1454 *  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 0455 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+456 * |                  ipv6_addr_src,   31 - 0                      |457 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+458 * |                  ipv6_addr_src,  63 - 32                      |459 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+460 * |                  ipv6_addr_src,  95 - 64                      |461 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+462 * |                  ipv6_addr_src, 127 - 96                      |463 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+464 * |                  ipv6_addr_dst,   31 - 0                      |465 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+466 * |                  ipv6_addr_dst,  63 - 32                      |467 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+468 * |                  ipv6_addr_dst,  95 - 64                      |469 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+470 * |                  ipv6_addr_dst, 127 - 96                      |471 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+472 * |           Reserved            |      tos      |      ttl      |473 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+474 * |                            Reserved                           |475 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+476 * |                     VNI                       |   Reserved    |477 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+478 */479struct nfp_flower_ipv6_udp_tun {480	struct nfp_flower_tun_ipv6 ipv6;481	__be16 reserved1;482	struct nfp_flower_tun_ip_ext ip_ext;483	__be32 reserved2;484	__be32 tun_id;485};486 487/* Flow Frame GRE TUNNEL --> Tunnel details (6W/24B)488 * -----------------------------------------------------------------489 *    3                   2                   1490 *  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 0491 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+492 * |                         ipv4_addr_src                         |493 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+494 * |                         ipv4_addr_dst                         |495 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+496 * |           tun_flags           |       tos     |       ttl     |497 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+498 * |            Reserved           |           Ethertype           |499 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+500 * |                              Key                              |501 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+502 * |                           Reserved                            |503 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+504 */505 506struct nfp_flower_ipv4_gre_tun {507	struct nfp_flower_tun_ipv4 ipv4;508	__be16 tun_flags;509	struct nfp_flower_tun_ip_ext ip_ext;510	__be16 reserved1;511	__be16 ethertype;512	__be32 tun_key;513	__be32 reserved2;514};515 516/* Flow Frame GRE TUNNEL V6 --> Tunnel details (12W/48B)517 * -----------------------------------------------------------------518 *    3                   2                   1519 *  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 0520 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+521 * |                  ipv6_addr_src,   31 - 0                      |522 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+523 * |                  ipv6_addr_src,  63 - 32                      |524 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+525 * |                  ipv6_addr_src,  95 - 64                      |526 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+527 * |                  ipv6_addr_src, 127 - 96                      |528 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+529 * |                  ipv6_addr_dst,   31 - 0                      |530 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+531 * |                  ipv6_addr_dst,  63 - 32                      |532 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+533 * |                  ipv6_addr_dst,  95 - 64                      |534 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+535 * |                  ipv6_addr_dst, 127 - 96                      |536 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+537 * |           tun_flags           |       tos     |       ttl     |538 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+539 * |            Reserved           |           Ethertype           |540 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+541 * |                              Key                              |542 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+543 * |                           Reserved                            |544 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+545 */546struct nfp_flower_ipv6_gre_tun {547	struct nfp_flower_tun_ipv6 ipv6;548	__be16 tun_flags;549	struct nfp_flower_tun_ip_ext ip_ext;550	__be16 reserved1;551	__be16 ethertype;552	__be32 tun_key;553	__be32 reserved2;554};555 556struct nfp_flower_geneve_options {557	u8 data[NFP_FL_MAX_GENEVE_OPT_KEY];558};559 560#define NFP_FL_TUN_VNI_OFFSET 8561 562/* The base header for a control message packet.563 * Defines an 8-bit version, and an 8-bit type, padded564 * to a 32-bit word. Rest of the packet is type-specific.565 */566struct nfp_flower_cmsg_hdr {567	__be16 pad;568	u8 type;569	u8 version;570};571 572#define NFP_FLOWER_CMSG_HLEN		sizeof(struct nfp_flower_cmsg_hdr)573#define NFP_FLOWER_CMSG_VER1		1574 575/* Types defined for port related control messages  */576enum nfp_flower_cmsg_type_port {577	NFP_FLOWER_CMSG_TYPE_FLOW_ADD =		0,578	NFP_FLOWER_CMSG_TYPE_FLOW_MOD =		1,579	NFP_FLOWER_CMSG_TYPE_FLOW_DEL =		2,580	NFP_FLOWER_CMSG_TYPE_LAG_CONFIG =	4,581	NFP_FLOWER_CMSG_TYPE_PORT_REIFY =	6,582	NFP_FLOWER_CMSG_TYPE_MAC_REPR =		7,583	NFP_FLOWER_CMSG_TYPE_PORT_MOD =		8,584	NFP_FLOWER_CMSG_TYPE_MERGE_HINT =	9,585	NFP_FLOWER_CMSG_TYPE_NO_NEIGH =		10,586	NFP_FLOWER_CMSG_TYPE_TUN_MAC =		11,587	NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS =	12,588	NFP_FLOWER_CMSG_TYPE_TUN_NEIGH =	13,589	NFP_FLOWER_CMSG_TYPE_TUN_IPS =		14,590	NFP_FLOWER_CMSG_TYPE_FLOW_STATS =	15,591	NFP_FLOWER_CMSG_TYPE_PORT_ECHO =	16,592	NFP_FLOWER_CMSG_TYPE_QOS_MOD =		18,593	NFP_FLOWER_CMSG_TYPE_QOS_DEL =		19,594	NFP_FLOWER_CMSG_TYPE_QOS_STATS =	20,595	NFP_FLOWER_CMSG_TYPE_PRE_TUN_RULE =	21,596	NFP_FLOWER_CMSG_TYPE_TUN_IPS_V6 =	22,597	NFP_FLOWER_CMSG_TYPE_NO_NEIGH_V6 =	23,598	NFP_FLOWER_CMSG_TYPE_TUN_NEIGH_V6 =	24,599	NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS_V6 =	25,600	NFP_FLOWER_CMSG_TYPE_MAX =		32,601};602 603/* NFP_FLOWER_CMSG_TYPE_MAC_REPR */604struct nfp_flower_cmsg_mac_repr {605	u8 reserved[3];606	u8 num_ports;607	struct {608		u8 idx;609		u8 info;610		u8 nbi_port;611		u8 phys_port;612	} ports[];613};614 615#define NFP_FLOWER_CMSG_MAC_REPR_NBI		GENMASK(1, 0)616 617/* NFP_FLOWER_CMSG_TYPE_PORT_MOD */618struct nfp_flower_cmsg_portmod {619	__be32 portnum;620	u8 reserved;621	u8 info;622	__be16 mtu;623};624 625#define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK	BIT(0)626#define NFP_FLOWER_CMSG_PORTMOD_MTU_CHANGE_ONLY	BIT(1)627 628/* NFP_FLOWER_CMSG_TYPE_PORT_REIFY */629struct nfp_flower_cmsg_portreify {630	__be32 portnum;631	u16 reserved;632	__be16 info;633};634 635#define NFP_FLOWER_CMSG_PORTREIFY_INFO_EXIST	BIT(0)636 637/* NFP_FLOWER_CMSG_TYPE_FLOW_MERGE_HINT */638struct nfp_flower_cmsg_merge_hint {639	u8 reserved[3];640	u8 count;641	struct {642		__be32 host_ctx;643		__be64 host_cookie;644	} __packed flow[];645};646 647enum nfp_flower_cmsg_port_type {648	NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC =	0x0,649	NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT =	0x1,650	NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT =	0x2,651	NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT =  0x3,652};653 654enum nfp_flower_cmsg_port_vnic_type {655	NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF =	0x0,656	NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF =	0x1,657	NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL =	0x2,658};659 660#define NFP_FLOWER_CMSG_PORT_TYPE		GENMASK(31, 28)661#define NFP_FLOWER_CMSG_PORT_SYS_ID		GENMASK(27, 24)662#define NFP_FLOWER_CMSG_PORT_NFP_ID		GENMASK(23, 22)663#define NFP_FLOWER_CMSG_PORT_PCI		GENMASK(15, 14)664#define NFP_FLOWER_CMSG_PORT_VNIC_TYPE		GENMASK(13, 12)665#define NFP_FLOWER_CMSG_PORT_VNIC		GENMASK(11, 6)666#define NFP_FLOWER_CMSG_PORT_PCIE_Q		GENMASK(5, 0)667#define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM	GENMASK(7, 0)668 669static inline u32 nfp_flower_internal_port_get_port_id(u8 internal_port)670{671	return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, internal_port) |672		FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,673			   NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT);674}675 676static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)677{678	return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |679		FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,680			   NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);681}682 683static inline u32684nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,685			  u8 vnic, u8 q)686{687	return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |688		FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |689		FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |690		FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |691		FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,692			   NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);693}694 695static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb)696{697	return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN;698}699 700static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb)701{702	return skb->len - NFP_FLOWER_CMSG_HLEN;703}704 705static inline bool706nfp_fl_netdev_is_tunnel_type(struct net_device *netdev,707			     enum nfp_flower_tun_type tun_type)708{709	if (netif_is_vxlan(netdev))710		return tun_type == NFP_FL_TUNNEL_VXLAN;711	if (netif_is_gretap(netdev) || netif_is_ip6gretap(netdev))712		return tun_type == NFP_FL_TUNNEL_GRE;713	if (netif_is_geneve(netdev))714		return tun_type == NFP_FL_TUNNEL_GENEVE;715 716	return false;717}718 719static inline bool nfp_fl_is_netdev_to_offload(struct net_device *netdev)720{721	if (!netdev->rtnl_link_ops)722		return false;723	if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch"))724		return true;725	if (netif_is_vxlan(netdev))726		return true;727	if (netif_is_geneve(netdev))728		return true;729	if (netif_is_gretap(netdev))730		return true;731	if (netif_is_ip6gretap(netdev))732		return true;733 734	return false;735}736 737struct sk_buff *738nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);739void740nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,741			     unsigned int nbi, unsigned int nbi_port,742			     unsigned int phys_port);743int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok,744			    unsigned int mtu, bool mtu_only);745int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists);746void nfp_flower_cmsg_process_rx(struct work_struct *work);747void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);748struct sk_buff *749nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size,750		      enum nfp_flower_cmsg_type_port type, gfp_t flag);751 752#endif753