1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /**************************************************************************** 3 * Driver for Solarflare network controllers and boards 4 * Copyright 2019 Solarflare Communications Inc. 5 * Copyright 2020-2022 Xilinx Inc. 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 as published 9 * by the Free Software Foundation, incorporated herein by reference. 10 */ 11 12 #ifndef EFX_TC_H 13 #define EFX_TC_H 14 #include <net/flow_offload.h> 15 #include <linux/rhashtable.h> 16 #include "net_driver.h" 17 18 #define IS_ALL_ONES(v) (!(typeof (v))~(v)) 19 20 struct efx_tc_action_set { 21 u16 deliver:1; 22 u32 dest_mport; 23 u32 fw_id; /* index of this entry in firmware actions table */ 24 struct list_head list; 25 }; 26 27 struct efx_tc_match_fields { 28 /* L1 */ 29 u32 ingress_port; 30 u8 recirc_id; 31 /* L2 (inner when encap) */ 32 __be16 eth_proto; 33 __be16 vlan_tci[2], vlan_proto[2]; 34 u8 eth_saddr[ETH_ALEN], eth_daddr[ETH_ALEN]; 35 /* L3 (when IP) */ 36 u8 ip_proto, ip_tos, ip_ttl; 37 __be32 src_ip, dst_ip; 38 #ifdef CONFIG_IPV6 39 struct in6_addr src_ip6, dst_ip6; 40 #endif 41 bool ip_frag, ip_firstfrag; 42 /* L4 */ 43 __be16 l4_sport, l4_dport; /* Ports (UDP, TCP) */ 44 __be16 tcp_flags; 45 }; 46 47 struct efx_tc_match { 48 struct efx_tc_match_fields value; 49 struct efx_tc_match_fields mask; 50 }; 51 52 struct efx_tc_action_set_list { 53 struct list_head list; 54 u32 fw_id; 55 }; 56 57 struct efx_tc_flow_rule { 58 unsigned long cookie; 59 struct rhash_head linkage; 60 struct efx_tc_match match; 61 struct efx_tc_action_set_list acts; 62 u32 fw_id; 63 }; 64 65 enum efx_tc_rule_prios { 66 EFX_TC_PRIO_TC, /* Rule inserted by TC */ 67 EFX_TC_PRIO_DFLT, /* Default switch rule; one of efx_tc_default_rules */ 68 EFX_TC_PRIO__NUM 69 }; 70 71 /** 72 * struct efx_tc_state - control plane data for TC offload 73 * 74 * @caps: MAE capabilities reported by MCDI 75 * @block_list: List of &struct efx_tc_block_binding 76 * @mutex: Used to serialise operations on TC hashtables 77 * @match_action_ht: Hashtable of TC match-action rules 78 * @reps_mport_id: MAE port allocated for representor RX 79 * @reps_filter_uc: VNIC filter for representor unicast RX (promisc) 80 * @reps_filter_mc: VNIC filter for representor multicast RX (allmulti) 81 * @reps_mport_vport_id: vport_id for representor RX filters 82 * @dflt: Match-action rules for default switching; at priority 83 * %EFX_TC_PRIO_DFLT. Named by *ingress* port 84 * @dflt.pf: rule for traffic ingressing from PF (egresses to wire) 85 * @dflt.wire: rule for traffic ingressing from wire (egresses to PF) 86 * @up: have TC datastructures been set up? 87 */ 88 struct efx_tc_state { 89 struct mae_caps *caps; 90 struct list_head block_list; 91 struct mutex mutex; 92 struct rhashtable match_action_ht; 93 u32 reps_mport_id, reps_mport_vport_id; 94 s32 reps_filter_uc, reps_filter_mc; 95 struct { 96 struct efx_tc_flow_rule pf; 97 struct efx_tc_flow_rule wire; 98 } dflt; 99 bool up; 100 }; 101 102 struct efx_rep; 103 104 int efx_tc_configure_default_rule_rep(struct efx_rep *efv); 105 void efx_tc_deconfigure_default_rule(struct efx_nic *efx, 106 struct efx_tc_flow_rule *rule); 107 int efx_tc_flower(struct efx_nic *efx, struct net_device *net_dev, 108 struct flow_cls_offload *tc, struct efx_rep *efv); 109 110 int efx_tc_insert_rep_filters(struct efx_nic *efx); 111 void efx_tc_remove_rep_filters(struct efx_nic *efx); 112 113 int efx_init_tc(struct efx_nic *efx); 114 void efx_fini_tc(struct efx_nic *efx); 115 116 int efx_init_struct_tc(struct efx_nic *efx); 117 void efx_fini_struct_tc(struct efx_nic *efx); 118 119 #endif /* EFX_TC_H */ 120