xref: /linux/drivers/net/ethernet/intel/ice/ice_eswitch_br.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2023, Intel Corporation. */
3 
4 #ifndef _ICE_ESWITCH_BR_H_
5 #define _ICE_ESWITCH_BR_H_
6 
7 #include <linux/rhashtable.h>
8 #include <linux/workqueue.h>
9 
10 struct ice_esw_br_fdb_data {
11 	unsigned char addr[ETH_ALEN];
12 	u16 vid;
13 };
14 
15 struct ice_esw_br_flow {
16 	struct ice_rule_query_data *fwd_rule;
17 	struct ice_rule_query_data *guard_rule;
18 };
19 
20 enum {
21 	ICE_ESWITCH_BR_FDB_ADDED_BY_USER = BIT(0),
22 };
23 
24 struct ice_esw_br_fdb_entry {
25 	struct ice_esw_br_fdb_data data;
26 	struct rhash_head ht_node;
27 	struct list_head list;
28 
29 	int flags;
30 
31 	struct net_device *dev;
32 	struct ice_esw_br_port *br_port;
33 	struct ice_esw_br_flow *flow;
34 
35 	unsigned long last_use;
36 };
37 
38 enum ice_esw_br_port_type {
39 	ICE_ESWITCH_BR_UPLINK_PORT = 0,
40 	ICE_ESWITCH_BR_VF_REPR_PORT = 1,
41 };
42 
43 struct ice_esw_br_port {
44 	struct ice_esw_br *bridge;
45 	struct ice_vsi *vsi;
46 	enum ice_esw_br_port_type type;
47 	u16 vsi_idx;
48 	u16 pvid;
49 	u32 repr_id;
50 	struct xarray vlans;
51 };
52 
53 enum {
54 	ICE_ESWITCH_BR_VLAN_FILTERING = BIT(0),
55 };
56 
57 struct ice_esw_br {
58 	struct ice_esw_br_offloads *br_offloads;
59 	struct xarray ports;
60 
61 	struct rhashtable fdb_ht;
62 	struct list_head fdb_list;
63 
64 	int ifindex;
65 	u32 flags;
66 	unsigned long ageing_time;
67 };
68 
69 struct ice_esw_br_offloads {
70 	struct ice_pf *pf;
71 	struct ice_esw_br *bridge;
72 	struct notifier_block netdev_nb;
73 	struct notifier_block switchdev_blk;
74 	struct notifier_block switchdev_nb;
75 
76 	struct workqueue_struct *wq;
77 	struct delayed_work update_work;
78 };
79 
80 struct ice_esw_br_fdb_work {
81 	struct work_struct work;
82 	struct switchdev_notifier_fdb_info fdb_info;
83 	struct net_device *dev;
84 	unsigned long event;
85 };
86 
87 struct ice_esw_br_vlan {
88 	u16 vid;
89 	u16 flags;
90 };
91 
92 #define ice_nb_to_br_offloads(nb, nb_name) \
93 	container_of(nb, \
94 		     struct ice_esw_br_offloads, \
95 		     nb_name)
96 
97 #define ice_work_to_br_offloads(w) \
98 	container_of(w, \
99 		     struct ice_esw_br_offloads, \
100 		     update_work.work)
101 
102 #define ice_work_to_fdb_work(w) \
103 	container_of(w, \
104 		     struct ice_esw_br_fdb_work, \
105 		     work)
106 
107 static inline bool ice_eswitch_br_is_vid_valid(u16 vid)
108 {
109 	/* In trunk VLAN mode, for untagged traffic the bridge sends requests
110 	 * to offload VLAN 1 with pvid and untagged flags set. Since these
111 	 * flags are not supported, add a MAC filter instead.
112 	 */
113 	return vid > 1;
114 }
115 
116 void
117 ice_eswitch_br_offloads_deinit(struct ice_pf *pf);
118 int
119 ice_eswitch_br_offloads_init(struct ice_pf *pf);
120 void ice_eswitch_br_fdb_flush(struct ice_esw_br *bridge);
121 
122 #endif /* _ICE_ESWITCH_BR_H_ */
123