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 	u16 pvid;
46 	struct xarray vlans;
47 };
48 
49 enum {
50 	ICE_ESWITCH_BR_VLAN_FILTERING = BIT(0),
51 };
52 
53 struct ice_esw_br {
54 	struct ice_esw_br_offloads *br_offloads;
55 	struct xarray ports;
56 
57 	struct rhashtable fdb_ht;
58 	struct list_head fdb_list;
59 
60 	int ifindex;
61 	u32 flags;
62 };
63 
64 struct ice_esw_br_offloads {
65 	struct ice_pf *pf;
66 	struct ice_esw_br *bridge;
67 	struct notifier_block netdev_nb;
68 	struct notifier_block switchdev_blk;
69 	struct notifier_block switchdev_nb;
70 
71 	struct workqueue_struct *wq;
72 };
73 
74 struct ice_esw_br_fdb_work {
75 	struct work_struct work;
76 	struct switchdev_notifier_fdb_info fdb_info;
77 	struct net_device *dev;
78 	unsigned long event;
79 };
80 
81 struct ice_esw_br_vlan {
82 	u16 vid;
83 	u16 flags;
84 };
85 
86 #define ice_nb_to_br_offloads(nb, nb_name) \
87 	container_of(nb, \
88 		     struct ice_esw_br_offloads, \
89 		     nb_name)
90 
91 #define ice_work_to_fdb_work(w) \
92 	container_of(w, \
93 		     struct ice_esw_br_fdb_work, \
94 		     work)
95 
96 static inline bool ice_eswitch_br_is_vid_valid(u16 vid)
97 {
98 	/* In trunk VLAN mode, for untagged traffic the bridge sends requests
99 	 * to offload VLAN 1 with pvid and untagged flags set. Since these
100 	 * flags are not supported, add a MAC filter instead.
101 	 */
102 	return vid > 1;
103 }
104 
105 void
106 ice_eswitch_br_offloads_deinit(struct ice_pf *pf);
107 int
108 ice_eswitch_br_offloads_init(struct ice_pf *pf);
109 
110 #endif /* _ICE_ESWITCH_BR_H_ */
111