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