1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
3 
4 #ifndef _ICE_SWITCH_H_
5 #define _ICE_SWITCH_H_
6 
7 #include "ice_common.h"
8 
9 #define ICE_SW_CFG_MAX_BUF_LEN 2048
10 #define ICE_DFLT_VSI_INVAL 0xff
11 #define ICE_VSI_INVAL_ID 0xffff
12 
13 /* VSI context structure for add/get/update/free operations */
14 struct ice_vsi_ctx {
15 	u16 vsi_num;
16 	u16 vsis_allocd;
17 	u16 vsis_unallocated;
18 	u16 flags;
19 	struct ice_aqc_vsi_props info;
20 	u8 alloc_from_pool;
21 };
22 
23 enum ice_sw_fwd_act_type {
24 	ICE_FWD_TO_VSI = 0,
25 	ICE_FWD_TO_VSI_LIST, /* Do not use this when adding filter */
26 	ICE_FWD_TO_Q,
27 	ICE_FWD_TO_QGRP,
28 	ICE_DROP_PACKET,
29 	ICE_INVAL_ACT
30 };
31 
32 /* Switch recipe ID enum values are specific to hardware */
33 enum ice_sw_lkup_type {
34 	ICE_SW_LKUP_ETHERTYPE = 0,
35 	ICE_SW_LKUP_MAC = 1,
36 	ICE_SW_LKUP_MAC_VLAN = 2,
37 	ICE_SW_LKUP_PROMISC = 3,
38 	ICE_SW_LKUP_VLAN = 4,
39 	ICE_SW_LKUP_DFLT = 5,
40 	ICE_SW_LKUP_ETHERTYPE_MAC = 8,
41 	ICE_SW_LKUP_PROMISC_VLAN = 9,
42 };
43 
44 struct ice_fltr_info {
45 	/* Look up information: how to look up packet */
46 	enum ice_sw_lkup_type lkup_type;
47 	/* Forward action: filter action to do after lookup */
48 	enum ice_sw_fwd_act_type fltr_act;
49 	/* rule ID returned by firmware once filter rule is created */
50 	u16 fltr_rule_id;
51 	u16 flag;
52 #define ICE_FLTR_RX		BIT(0)
53 #define ICE_FLTR_TX		BIT(1)
54 #define ICE_FLTR_TX_RX		(ICE_FLTR_RX | ICE_FLTR_TX)
55 
56 	/* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
57 	u16 src;
58 
59 	union {
60 		struct {
61 			u8 mac_addr[ETH_ALEN];
62 		} mac;
63 		struct {
64 			u8 mac_addr[ETH_ALEN];
65 			u16 vlan_id;
66 		} mac_vlan;
67 		struct {
68 			u16 vlan_id;
69 		} vlan;
70 		/* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
71 		 * if just using ethertype as filter. Set lkup_type as
72 		 * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
73 		 * passed in as filter.
74 		 */
75 		struct {
76 			u16 ethertype;
77 			u8 mac_addr[ETH_ALEN]; /* optional */
78 		} ethertype_mac;
79 	} l_data;
80 
81 	/* Depending on filter action */
82 	union {
83 		/* queue id in case of ICE_FWD_TO_Q and starting
84 		 * queue id in case of ICE_FWD_TO_QGRP.
85 		 */
86 		u16 q_id:11;
87 		u16 vsi_id:10;
88 		u16 vsi_list_id:10;
89 	} fwd_id;
90 
91 	/* Set to num_queues if action is ICE_FWD_TO_QGRP. This field
92 	 * determines the range of queues the packet needs to be forwarded to
93 	 */
94 	u8 qgrp_size;
95 
96 	/* Rule creations populate these indicators basing on the switch type */
97 	u8 lb_en;	/* Indicate if packet can be looped back */
98 	u8 lan_en;	/* Indicate if packet can be forwarded to the uplink */
99 };
100 
101 /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list id */
102 struct ice_vsi_list_map_info {
103 	struct list_head list_entry;
104 	DECLARE_BITMAP(vsi_map, ICE_MAX_VSI);
105 	u16 vsi_list_id;
106 };
107 
108 enum ice_sw_fltr_status {
109 	ICE_FLTR_STATUS_NEW = 0,
110 	ICE_FLTR_STATUS_FW_SUCCESS,
111 	ICE_FLTR_STATUS_FW_FAIL,
112 };
113 
114 struct ice_fltr_list_entry {
115 	struct list_head list_entry;
116 	enum ice_sw_fltr_status status;
117 	struct ice_fltr_info fltr_info;
118 };
119 
120 /* This defines an entry in the list that maintains MAC or VLAN membership
121  * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
122  * VLAN. As an optimization the VSI list should be created only when a
123  * second VSI becomes a subscriber to the VLAN address.
124  */
125 struct ice_fltr_mgmt_list_entry {
126 	/* back pointer to VSI list id to VSI list mapping */
127 	struct ice_vsi_list_map_info *vsi_list_info;
128 	u16 vsi_count;
129 #define ICE_INVAL_LG_ACT_INDEX 0xffff
130 	u16 lg_act_idx;
131 #define ICE_INVAL_SW_MARKER_ID 0xffff
132 	u16 sw_marker_id;
133 	struct list_head list_entry;
134 	struct ice_fltr_info fltr_info;
135 #define ICE_INVAL_COUNTER_ID 0xff
136 	u8 counter_index;
137 };
138 
139 /* VSI related commands */
140 enum ice_status
141 ice_aq_add_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
142 	       struct ice_sq_cd *cd);
143 enum ice_status
144 ice_aq_update_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
145 		  struct ice_sq_cd *cd);
146 enum ice_status
147 ice_aq_free_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
148 		bool keep_vsi_alloc, struct ice_sq_cd *cd);
149 
150 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw);
151 
152 /* Switch/bridge related commands */
153 enum ice_status ice_add_mac(struct ice_hw *hw, struct list_head *m_lst);
154 enum ice_status ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst);
155 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_id);
156 enum ice_status ice_add_vlan(struct ice_hw *hw, struct list_head *m_list);
157 enum ice_status ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list);
158 enum ice_status
159 ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_id, bool set, u8 direction);
160 
161 #endif /* _ICE_SWITCH_H_ */
162