xref: /openbmc/linux/drivers/net/ethernet/sfc/tc.h (revision ac73d4bf2cdaf2cb8a43df8ee4a5c066d2c5d7b4)
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 struct efx_tc_action_set {
19 	u16 deliver:1;
20 	u32 dest_mport;
21 	u32 fw_id; /* index of this entry in firmware actions table */
22 	struct list_head list;
23 };
24 
25 struct efx_tc_match_fields {
26 	/* L1 */
27 	u32 ingress_port;
28 	u8 recirc_id;
29 };
30 
31 struct efx_tc_match {
32 	struct efx_tc_match_fields value;
33 	struct efx_tc_match_fields mask;
34 };
35 
36 struct efx_tc_action_set_list {
37 	struct list_head list;
38 	u32 fw_id;
39 };
40 
41 struct efx_tc_flow_rule {
42 	unsigned long cookie;
43 	struct rhash_head linkage;
44 	struct efx_tc_match match;
45 	struct efx_tc_action_set_list acts;
46 	u32 fw_id;
47 };
48 
49 enum efx_tc_rule_prios {
50 	EFX_TC_PRIO_TC, /* Rule inserted by TC */
51 	EFX_TC_PRIO_DFLT, /* Default switch rule; one of efx_tc_default_rules */
52 	EFX_TC_PRIO__NUM
53 };
54 
55 /**
56  * struct efx_tc_state - control plane data for TC offload
57  *
58  * @caps: MAE capabilities reported by MCDI
59  * @block_list: List of &struct efx_tc_block_binding
60  * @mutex: Used to serialise operations on TC hashtables
61  * @match_action_ht: Hashtable of TC match-action rules
62  * @reps_mport_id: MAE port allocated for representor RX
63  * @reps_filter_uc: VNIC filter for representor unicast RX (promisc)
64  * @reps_filter_mc: VNIC filter for representor multicast RX (allmulti)
65  * @reps_mport_vport_id: vport_id for representor RX filters
66  * @dflt: Match-action rules for default switching; at priority
67  *	%EFX_TC_PRIO_DFLT.  Named by *ingress* port
68  * @dflt.pf: rule for traffic ingressing from PF (egresses to wire)
69  * @dflt.wire: rule for traffic ingressing from wire (egresses to PF)
70  * @up: have TC datastructures been set up?
71  */
72 struct efx_tc_state {
73 	struct mae_caps *caps;
74 	struct list_head block_list;
75 	struct mutex mutex;
76 	struct rhashtable match_action_ht;
77 	u32 reps_mport_id, reps_mport_vport_id;
78 	s32 reps_filter_uc, reps_filter_mc;
79 	struct {
80 		struct efx_tc_flow_rule pf;
81 		struct efx_tc_flow_rule wire;
82 	} dflt;
83 	bool up;
84 };
85 
86 struct efx_rep;
87 
88 int efx_tc_configure_default_rule_rep(struct efx_rep *efv);
89 void efx_tc_deconfigure_default_rule(struct efx_nic *efx,
90 				     struct efx_tc_flow_rule *rule);
91 int efx_tc_flower(struct efx_nic *efx, struct net_device *net_dev,
92 		  struct flow_cls_offload *tc, struct efx_rep *efv);
93 
94 int efx_tc_insert_rep_filters(struct efx_nic *efx);
95 void efx_tc_remove_rep_filters(struct efx_nic *efx);
96 
97 int efx_init_tc(struct efx_nic *efx);
98 void efx_fini_tc(struct efx_nic *efx);
99 
100 int efx_init_struct_tc(struct efx_nic *efx);
101 void efx_fini_struct_tc(struct efx_nic *efx);
102 
103 #endif /* EFX_TC_H */
104