1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2021 Intel Corporation
5 #include "ice_common.h"
8 * ice_pkg_get_supported_vlan_mode - chk if DDP supports Double VLAN mode (DVM)
9 * @hw: pointer to the HW struct
10 * @dvm: output variable to determine if DDP supports DVM(true) or SVM(false)
12 static enum ice_status
13 ice_pkg_get_supported_vlan_mode(struct ice_hw *hw, bool *dvm)
15 u16 meta_init_size = sizeof(struct ice_meta_init_section);
16 struct ice_meta_init_section *sect;
17 struct ice_buf_build *bld;
18 enum ice_status status;
20 /* if anything fails, we assume there is no DVM support */
23 bld = ice_pkg_buf_alloc_single_section(hw,
24 ICE_SID_RXPARSER_METADATA_INIT,
25 meta_init_size, (void **)§);
27 return ICE_ERR_NO_MEMORY;
29 /* only need to read a single section */
30 sect->count = CPU_TO_LE16(1);
31 sect->offset = CPU_TO_LE16(ICE_META_VLAN_MODE_ENTRY);
33 status = ice_aq_upload_section(hw,
34 (struct ice_buf_hdr *)ice_pkg_buf(bld),
35 ICE_PKG_BUF_SIZE, NULL);
37 ice_declare_bitmap(entry, ICE_META_INIT_BITS);
38 u32 arr[ICE_META_INIT_DW_CNT];
41 /* convert to host bitmap format */
42 for (i = 0; i < ICE_META_INIT_DW_CNT; i++)
43 arr[i] = LE32_TO_CPU(sect->entry[0].bm[i]);
45 ice_bitmap_from_array32(entry, arr, (u16)ICE_META_INIT_BITS);
47 /* check if DVM is supported */
48 *dvm = ice_is_bit_set(entry, ICE_META_VLAN_MODE_BIT);
51 ice_pkg_buf_free(hw, bld);
57 * ice_aq_get_vlan_mode - get the VLAN mode of the device
58 * @hw: pointer to the HW structure
59 * @get_params: structure FW fills in based on the current VLAN mode config
61 * Get VLAN Mode Parameters (0x020D)
63 static enum ice_status
64 ice_aq_get_vlan_mode(struct ice_hw *hw,
65 struct ice_aqc_get_vlan_mode *get_params)
67 struct ice_aq_desc desc;
72 ice_fill_dflt_direct_cmd_desc(&desc,
73 ice_aqc_opc_get_vlan_mode_parameters);
75 return ice_aq_send_cmd(hw, &desc, get_params, sizeof(*get_params),
80 * ice_aq_is_dvm_ena - query FW to check if double VLAN mode is enabled
81 * @hw: pointer to the HW structure
83 * Returns true if the hardware/firmware is configured in double VLAN mode,
84 * else return false signaling that the hardware/firmware is configured in
87 * Also, return false if this call fails for any reason (i.e. firmware doesn't
88 * support this AQ call).
90 static bool ice_aq_is_dvm_ena(struct ice_hw *hw)
92 struct ice_aqc_get_vlan_mode get_params = { 0 };
93 enum ice_status status;
95 status = ice_aq_get_vlan_mode(hw, &get_params);
97 ice_debug(hw, ICE_DBG_AQ, "Failed to get VLAN mode, status %d\n",
102 return (get_params.vlan_mode & ICE_AQ_VLAN_MODE_DVM_ENA);
106 * ice_is_dvm_ena - check if double VLAN mode is enabled
107 * @hw: pointer to the HW structure
109 * The device is configured in single or double VLAN mode on initialization and
110 * this cannot be dynamically changed during runtime. Based on this there is no
111 * need to make an AQ call every time the driver needs to know the VLAN mode.
112 * Instead, use the cached VLAN mode.
114 bool ice_is_dvm_ena(struct ice_hw *hw)
120 * ice_cache_vlan_mode - cache VLAN mode after DDP is downloaded
121 * @hw: pointer to the HW structure
123 * This is only called after downloading the DDP and after the global
124 * configuration lock has been released because all ports on a device need to
125 * cache the VLAN mode.
127 void ice_cache_vlan_mode(struct ice_hw *hw)
129 hw->dvm_ena = ice_aq_is_dvm_ena(hw) ? true : false;
133 * ice_is_dvm_supported - check if Double VLAN Mode is supported
134 * @hw: pointer to the hardware structure
136 * Returns true if Double VLAN Mode (DVM) is supported and false if only Single
137 * VLAN Mode (SVM) is supported. In order for DVM to be supported the DDP and
138 * firmware must support it, otherwise only SVM is supported. This function
139 * should only be called while the global config lock is held and after the
140 * package has been successfully downloaded.
142 static bool ice_is_dvm_supported(struct ice_hw *hw)
144 struct ice_aqc_get_vlan_mode get_vlan_mode = { 0 };
145 enum ice_status status;
146 bool pkg_supports_dvm;
148 status = ice_pkg_get_supported_vlan_mode(hw, &pkg_supports_dvm);
150 ice_debug(hw, ICE_DBG_PKG, "Failed to get supported VLAN mode, status %d\n",
155 if (!pkg_supports_dvm)
158 /* If firmware returns success, then it supports DVM, else it only
161 status = ice_aq_get_vlan_mode(hw, &get_vlan_mode);
163 ice_debug(hw, ICE_DBG_NVM, "Failed to get VLAN mode, status %d\n",
171 #define ICE_EXTERNAL_VLAN_ID_FV_IDX 11
172 #define ICE_SW_LKUP_VLAN_LOC_LKUP_IDX 1
173 #define ICE_SW_LKUP_VLAN_PKT_FLAGS_LKUP_IDX 2
174 #define ICE_SW_LKUP_PROMISC_VLAN_LOC_LKUP_IDX 2
175 #define ICE_PKT_FLAGS_0_TO_15_FV_IDX 1
176 #define ICE_PKT_FLAGS_0_TO_15_VLAN_FLAGS_MASK 0xD000
177 static struct ice_update_recipe_lkup_idx_params ice_dvm_dflt_recipes[] = {
179 /* Update recipe ICE_SW_LKUP_VLAN to filter based on the
180 * outer/single VLAN in DVM
182 .rid = ICE_SW_LKUP_VLAN,
183 .fv_idx = ICE_EXTERNAL_VLAN_ID_FV_IDX,
184 .ignore_valid = true,
186 .mask_valid = false, /* use pre-existing mask */
187 .lkup_idx = ICE_SW_LKUP_VLAN_LOC_LKUP_IDX,
190 /* Update recipe ICE_SW_LKUP_VLAN to filter based on the VLAN
191 * packet flags to support VLAN filtering on multiple VLAN
192 * ethertypes (i.e. 0x8100 and 0x88a8) in DVM
194 .rid = ICE_SW_LKUP_VLAN,
195 .fv_idx = ICE_PKT_FLAGS_0_TO_15_FV_IDX,
196 .ignore_valid = false,
197 .mask = ICE_PKT_FLAGS_0_TO_15_VLAN_FLAGS_MASK,
199 .lkup_idx = ICE_SW_LKUP_VLAN_PKT_FLAGS_LKUP_IDX,
202 /* Update recipe ICE_SW_LKUP_PROMISC_VLAN to filter based on the
203 * outer/single VLAN in DVM
205 .rid = ICE_SW_LKUP_PROMISC_VLAN,
206 .fv_idx = ICE_EXTERNAL_VLAN_ID_FV_IDX,
207 .ignore_valid = true,
209 .mask_valid = false, /* use pre-existing mask */
210 .lkup_idx = ICE_SW_LKUP_PROMISC_VLAN_LOC_LKUP_IDX,
215 * ice_dvm_update_dflt_recipes - update default switch recipes in DVM
216 * @hw: hardware structure used to update the recipes
218 static enum ice_status ice_dvm_update_dflt_recipes(struct ice_hw *hw)
222 for (i = 0; i < ARRAY_SIZE(ice_dvm_dflt_recipes); i++) {
223 struct ice_update_recipe_lkup_idx_params *params;
224 enum ice_status status;
226 params = &ice_dvm_dflt_recipes[i];
228 status = ice_update_recipe_lkup_idx(hw, params);
230 ice_debug(hw, ICE_DBG_INIT, "Failed to update RID %d lkup_idx %d fv_idx %d mask_valid %s mask 0x%04x\n",
231 params->rid, params->lkup_idx, params->fv_idx,
232 params->mask_valid ? "true" : "false",
242 * ice_aq_set_vlan_mode - set the VLAN mode of the device
243 * @hw: pointer to the HW structure
244 * @set_params: requested VLAN mode configuration
246 * Set VLAN Mode Parameters (0x020C)
248 static enum ice_status
249 ice_aq_set_vlan_mode(struct ice_hw *hw,
250 struct ice_aqc_set_vlan_mode *set_params)
252 u8 rdma_packet, mng_vlan_prot_id;
253 struct ice_aq_desc desc;
256 return ICE_ERR_PARAM;
258 if (set_params->l2tag_prio_tagging > ICE_AQ_VLAN_PRIO_TAG_MAX)
259 return ICE_ERR_PARAM;
261 rdma_packet = set_params->rdma_packet;
262 if (rdma_packet != ICE_AQ_SVM_VLAN_RDMA_PKT_FLAG_SETTING &&
263 rdma_packet != ICE_AQ_DVM_VLAN_RDMA_PKT_FLAG_SETTING)
264 return ICE_ERR_PARAM;
266 mng_vlan_prot_id = set_params->mng_vlan_prot_id;
267 if (mng_vlan_prot_id != ICE_AQ_VLAN_MNG_PROTOCOL_ID_OUTER &&
268 mng_vlan_prot_id != ICE_AQ_VLAN_MNG_PROTOCOL_ID_INNER)
269 return ICE_ERR_PARAM;
271 ice_fill_dflt_direct_cmd_desc(&desc,
272 ice_aqc_opc_set_vlan_mode_parameters);
273 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
275 return ice_aq_send_cmd(hw, &desc, set_params, sizeof(*set_params),
280 * ice_set_dvm - sets up software and hardware for double VLAN mode
281 * @hw: pointer to the hardware structure
283 static enum ice_status ice_set_dvm(struct ice_hw *hw)
285 struct ice_aqc_set_vlan_mode params = { 0 };
286 enum ice_status status;
288 params.l2tag_prio_tagging = ICE_AQ_VLAN_PRIO_TAG_OUTER_CTAG;
289 params.rdma_packet = ICE_AQ_DVM_VLAN_RDMA_PKT_FLAG_SETTING;
290 params.mng_vlan_prot_id = ICE_AQ_VLAN_MNG_PROTOCOL_ID_OUTER;
292 status = ice_aq_set_vlan_mode(hw, ¶ms);
294 ice_debug(hw, ICE_DBG_INIT, "Failed to set double VLAN mode parameters, status %d\n",
299 status = ice_dvm_update_dflt_recipes(hw);
301 ice_debug(hw, ICE_DBG_INIT, "Failed to update default recipes for double VLAN mode, status %d\n",
306 status = ice_aq_set_port_params(hw->port_info, 0, false, false, true,
309 ice_debug(hw, ICE_DBG_INIT, "Failed to set port in double VLAN mode, status %d\n",
314 status = ice_set_dvm_boost_entries(hw);
316 ice_debug(hw, ICE_DBG_INIT, "Failed to set boost TCAM entries for double VLAN mode, status %d\n",
325 * ice_set_svm - set single VLAN mode
326 * @hw: pointer to the HW structure
328 static enum ice_status ice_set_svm(struct ice_hw *hw)
330 struct ice_aqc_set_vlan_mode *set_params;
331 enum ice_status status;
333 status = ice_aq_set_port_params(hw->port_info, 0, false, false, false, NULL);
335 ice_debug(hw, ICE_DBG_INIT, "Failed to set port parameters for single VLAN mode\n");
339 set_params = (struct ice_aqc_set_vlan_mode *)
340 ice_malloc(hw, sizeof(*set_params));
342 return ICE_ERR_NO_MEMORY;
344 /* default configuration for SVM configurations */
345 set_params->l2tag_prio_tagging = ICE_AQ_VLAN_PRIO_TAG_INNER_CTAG;
346 set_params->rdma_packet = ICE_AQ_SVM_VLAN_RDMA_PKT_FLAG_SETTING;
347 set_params->mng_vlan_prot_id = ICE_AQ_VLAN_MNG_PROTOCOL_ID_INNER;
349 status = ice_aq_set_vlan_mode(hw, set_params);
351 ice_debug(hw, ICE_DBG_INIT, "Failed to configure port in single VLAN mode\n");
353 ice_free(hw, set_params);
359 * @hw: pointer to the HW structure
361 enum ice_status ice_set_vlan_mode(struct ice_hw *hw)
363 /* DCF only has the ability to query the VLAN mode. Setting the VLAN
364 * mode is done by the PF.
369 if (!ice_is_dvm_supported(hw))
372 if (!ice_set_dvm(hw))
375 return ice_set_svm(hw);