1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2019-2021, Intel Corporation. */
4 #include "ice_common.h"
7 * ice_pkg_get_supported_vlan_mode - determine if DDP supports Double VLAN mode
8 * @hw: pointer to the HW struct
9 * @dvm: output variable to determine if DDP supports DVM(true) or SVM(false)
12 ice_pkg_get_supported_vlan_mode(struct ice_hw *hw, bool *dvm)
14 u16 meta_init_size = sizeof(struct ice_meta_init_section);
15 struct ice_meta_init_section *sect;
16 struct ice_buf_build *bld;
19 /* if anything fails, we assume there is no DVM support */
22 bld = ice_pkg_buf_alloc_single_section(hw,
23 ICE_SID_RXPARSER_METADATA_INIT,
24 meta_init_size, (void **)§);
28 /* only need to read a single section */
29 sect->count = cpu_to_le16(1);
30 sect->offset = cpu_to_le16(ICE_META_VLAN_MODE_ENTRY);
32 status = ice_aq_upload_section(hw,
33 (struct ice_buf_hdr *)ice_pkg_buf(bld),
34 ICE_PKG_BUF_SIZE, NULL);
36 DECLARE_BITMAP(entry, ICE_META_INIT_BITS);
37 u32 arr[ICE_META_INIT_DW_CNT];
40 /* convert to host bitmap format */
41 for (i = 0; i < ICE_META_INIT_DW_CNT; i++)
42 arr[i] = le32_to_cpu(sect->entry.bm[i]);
44 bitmap_from_arr32(entry, arr, (u16)ICE_META_INIT_BITS);
46 /* check if DVM is supported */
47 *dvm = test_bit(ICE_META_VLAN_MODE_BIT, entry);
50 ice_pkg_buf_free(hw, bld);
56 * ice_aq_get_vlan_mode - get the VLAN mode of the device
57 * @hw: pointer to the HW structure
58 * @get_params: structure FW fills in based on the current VLAN mode config
60 * Get VLAN Mode Parameters (0x020D)
63 ice_aq_get_vlan_mode(struct ice_hw *hw,
64 struct ice_aqc_get_vlan_mode *get_params)
66 struct ice_aq_desc desc;
71 ice_fill_dflt_direct_cmd_desc(&desc,
72 ice_aqc_opc_get_vlan_mode_parameters);
74 return ice_aq_send_cmd(hw, &desc, get_params, sizeof(*get_params),
79 * ice_aq_is_dvm_ena - query FW to check if double VLAN mode is enabled
80 * @hw: pointer to the HW structure
82 * Returns true if the hardware/firmware is configured in double VLAN mode,
83 * else return false signaling that the hardware/firmware is configured in
86 * Also, return false if this call fails for any reason (i.e. firmware doesn't
87 * support this AQ call).
89 static bool ice_aq_is_dvm_ena(struct ice_hw *hw)
91 struct ice_aqc_get_vlan_mode get_params = { 0 };
94 status = ice_aq_get_vlan_mode(hw, &get_params);
96 ice_debug(hw, ICE_DBG_AQ, "Failed to get VLAN mode, status %d\n",
101 return (get_params.vlan_mode & ICE_AQ_VLAN_MODE_DVM_ENA);
105 * ice_is_dvm_ena - check if double VLAN mode is enabled
106 * @hw: pointer to the HW structure
108 * The device is configured in single or double VLAN mode on initialization and
109 * this cannot be dynamically changed during runtime. Based on this there is no
110 * need to make an AQ call every time the driver needs to know the VLAN mode.
111 * Instead, use the cached VLAN mode.
113 bool ice_is_dvm_ena(struct ice_hw *hw)
119 * ice_cache_vlan_mode - cache VLAN mode after DDP is downloaded
120 * @hw: pointer to the HW structure
122 * This is only called after downloading the DDP and after the global
123 * configuration lock has been released because all ports on a device need to
124 * cache the VLAN mode.
126 static void ice_cache_vlan_mode(struct ice_hw *hw)
128 hw->dvm_ena = ice_aq_is_dvm_ena(hw) ? true : false;
132 * ice_pkg_supports_dvm - find out if DDP supports DVM
133 * @hw: pointer to the HW structure
135 static bool ice_pkg_supports_dvm(struct ice_hw *hw)
137 bool pkg_supports_dvm;
140 status = ice_pkg_get_supported_vlan_mode(hw, &pkg_supports_dvm);
142 ice_debug(hw, ICE_DBG_PKG, "Failed to get supported VLAN mode, status %d\n",
147 return pkg_supports_dvm;
151 * ice_fw_supports_dvm - find out if FW supports DVM
152 * @hw: pointer to the HW structure
154 static bool ice_fw_supports_dvm(struct ice_hw *hw)
156 struct ice_aqc_get_vlan_mode get_vlan_mode = { 0 };
159 /* If firmware returns success, then it supports DVM, else it only
162 status = ice_aq_get_vlan_mode(hw, &get_vlan_mode);
164 ice_debug(hw, ICE_DBG_NVM, "Failed to get VLAN mode, status %d\n",
173 * ice_is_dvm_supported - check if Double VLAN Mode is supported
174 * @hw: pointer to the hardware structure
176 * Returns true if Double VLAN Mode (DVM) is supported and false if only Single
177 * VLAN Mode (SVM) is supported. In order for DVM to be supported the DDP and
178 * firmware must support it, otherwise only SVM is supported. This function
179 * should only be called while the global config lock is held and after the
180 * package has been successfully downloaded.
182 static bool ice_is_dvm_supported(struct ice_hw *hw)
184 if (!ice_pkg_supports_dvm(hw)) {
185 ice_debug(hw, ICE_DBG_PKG, "DDP doesn't support DVM\n");
189 if (!ice_fw_supports_dvm(hw)) {
190 ice_debug(hw, ICE_DBG_PKG, "FW doesn't support DVM\n");
197 #define ICE_EXTERNAL_VLAN_ID_FV_IDX 11
198 #define ICE_SW_LKUP_VLAN_LOC_LKUP_IDX 1
199 #define ICE_SW_LKUP_VLAN_PKT_FLAGS_LKUP_IDX 2
200 #define ICE_SW_LKUP_PROMISC_VLAN_LOC_LKUP_IDX 2
201 #define ICE_PKT_FLAGS_0_TO_15_FV_IDX 1
202 static struct ice_update_recipe_lkup_idx_params ice_dvm_dflt_recipes[] = {
204 /* Update recipe ICE_SW_LKUP_VLAN to filter based on the
205 * outer/single VLAN in DVM
207 .rid = ICE_SW_LKUP_VLAN,
208 .fv_idx = ICE_EXTERNAL_VLAN_ID_FV_IDX,
209 .ignore_valid = true,
211 .mask_valid = false, /* use pre-existing mask */
212 .lkup_idx = ICE_SW_LKUP_VLAN_LOC_LKUP_IDX,
215 /* Update recipe ICE_SW_LKUP_VLAN to filter based on the VLAN
216 * packet flags to support VLAN filtering on multiple VLAN
217 * ethertypes (i.e. 0x8100 and 0x88a8) in DVM
219 .rid = ICE_SW_LKUP_VLAN,
220 .fv_idx = ICE_PKT_FLAGS_0_TO_15_FV_IDX,
221 .ignore_valid = false,
222 .mask = ICE_PKT_VLAN_MASK,
224 .lkup_idx = ICE_SW_LKUP_VLAN_PKT_FLAGS_LKUP_IDX,
227 /* Update recipe ICE_SW_LKUP_PROMISC_VLAN to filter based on the
228 * outer/single VLAN in DVM
230 .rid = ICE_SW_LKUP_PROMISC_VLAN,
231 .fv_idx = ICE_EXTERNAL_VLAN_ID_FV_IDX,
232 .ignore_valid = true,
234 .mask_valid = false, /* use pre-existing mask */
235 .lkup_idx = ICE_SW_LKUP_PROMISC_VLAN_LOC_LKUP_IDX,
240 * ice_dvm_update_dflt_recipes - update default switch recipes in DVM
241 * @hw: hardware structure used to update the recipes
243 static int ice_dvm_update_dflt_recipes(struct ice_hw *hw)
247 for (i = 0; i < ARRAY_SIZE(ice_dvm_dflt_recipes); i++) {
248 struct ice_update_recipe_lkup_idx_params *params;
251 params = &ice_dvm_dflt_recipes[i];
253 status = ice_update_recipe_lkup_idx(hw, params);
255 ice_debug(hw, ICE_DBG_INIT, "Failed to update RID %d lkup_idx %d fv_idx %d mask_valid %s mask 0x%04x\n",
256 params->rid, params->lkup_idx, params->fv_idx,
257 params->mask_valid ? "true" : "false",
267 * ice_aq_set_vlan_mode - set the VLAN mode of the device
268 * @hw: pointer to the HW structure
269 * @set_params: requested VLAN mode configuration
271 * Set VLAN Mode Parameters (0x020C)
274 ice_aq_set_vlan_mode(struct ice_hw *hw,
275 struct ice_aqc_set_vlan_mode *set_params)
277 u8 rdma_packet, mng_vlan_prot_id;
278 struct ice_aq_desc desc;
283 if (set_params->l2tag_prio_tagging > ICE_AQ_VLAN_PRIO_TAG_MAX)
286 rdma_packet = set_params->rdma_packet;
287 if (rdma_packet != ICE_AQ_SVM_VLAN_RDMA_PKT_FLAG_SETTING &&
288 rdma_packet != ICE_AQ_DVM_VLAN_RDMA_PKT_FLAG_SETTING)
291 mng_vlan_prot_id = set_params->mng_vlan_prot_id;
292 if (mng_vlan_prot_id != ICE_AQ_VLAN_MNG_PROTOCOL_ID_OUTER &&
293 mng_vlan_prot_id != ICE_AQ_VLAN_MNG_PROTOCOL_ID_INNER)
296 ice_fill_dflt_direct_cmd_desc(&desc,
297 ice_aqc_opc_set_vlan_mode_parameters);
298 desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
300 return ice_aq_send_cmd(hw, &desc, set_params, sizeof(*set_params),
305 * ice_set_dvm - sets up software and hardware for double VLAN mode
306 * @hw: pointer to the hardware structure
308 static int ice_set_dvm(struct ice_hw *hw)
310 struct ice_aqc_set_vlan_mode params = { 0 };
313 params.l2tag_prio_tagging = ICE_AQ_VLAN_PRIO_TAG_OUTER_CTAG;
314 params.rdma_packet = ICE_AQ_DVM_VLAN_RDMA_PKT_FLAG_SETTING;
315 params.mng_vlan_prot_id = ICE_AQ_VLAN_MNG_PROTOCOL_ID_OUTER;
317 status = ice_aq_set_vlan_mode(hw, ¶ms);
319 ice_debug(hw, ICE_DBG_INIT, "Failed to set double VLAN mode parameters, status %d\n",
324 status = ice_dvm_update_dflt_recipes(hw);
326 ice_debug(hw, ICE_DBG_INIT, "Failed to update default recipes for double VLAN mode, status %d\n",
331 status = ice_aq_set_port_params(hw->port_info, true, NULL);
333 ice_debug(hw, ICE_DBG_INIT, "Failed to set port in double VLAN mode, status %d\n",
338 status = ice_set_dvm_boost_entries(hw);
340 ice_debug(hw, ICE_DBG_INIT, "Failed to set boost TCAM entries for double VLAN mode, status %d\n",
349 * ice_set_svm - set single VLAN mode
350 * @hw: pointer to the HW structure
352 static int ice_set_svm(struct ice_hw *hw)
354 struct ice_aqc_set_vlan_mode *set_params;
357 status = ice_aq_set_port_params(hw->port_info, false, NULL);
359 ice_debug(hw, ICE_DBG_INIT, "Failed to set port parameters for single VLAN mode\n");
363 set_params = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*set_params),
368 /* default configuration for SVM configurations */
369 set_params->l2tag_prio_tagging = ICE_AQ_VLAN_PRIO_TAG_INNER_CTAG;
370 set_params->rdma_packet = ICE_AQ_SVM_VLAN_RDMA_PKT_FLAG_SETTING;
371 set_params->mng_vlan_prot_id = ICE_AQ_VLAN_MNG_PROTOCOL_ID_INNER;
373 status = ice_aq_set_vlan_mode(hw, set_params);
375 ice_debug(hw, ICE_DBG_INIT, "Failed to configure port in single VLAN mode\n");
377 devm_kfree(ice_hw_to_dev(hw), set_params);
383 * @hw: pointer to the HW structure
385 int ice_set_vlan_mode(struct ice_hw *hw)
387 if (!ice_is_dvm_supported(hw))
390 if (!ice_set_dvm(hw))
393 return ice_set_svm(hw);
397 * ice_print_dvm_not_supported - print if DDP and/or FW doesn't support DVM
398 * @hw: pointer to the HW structure
400 * The purpose of this function is to print that QinQ is not supported due to
401 * incompatibilty from the DDP and/or FW. This will give a hint to the user to
402 * update one and/or both components if they expect QinQ functionality.
404 static void ice_print_dvm_not_supported(struct ice_hw *hw)
406 bool pkg_supports_dvm = ice_pkg_supports_dvm(hw);
407 bool fw_supports_dvm = ice_fw_supports_dvm(hw);
409 if (!fw_supports_dvm && !pkg_supports_dvm)
410 dev_info(ice_hw_to_dev(hw), "QinQ functionality cannot be enabled on this device. Update your DDP package and NVM to versions that support QinQ.\n");
411 else if (!pkg_supports_dvm)
412 dev_info(ice_hw_to_dev(hw), "QinQ functionality cannot be enabled on this device. Update your DDP package to a version that supports QinQ.\n");
413 else if (!fw_supports_dvm)
414 dev_info(ice_hw_to_dev(hw), "QinQ functionality cannot be enabled on this device. Update your NVM to a version that supports QinQ.\n");
418 * ice_post_pkg_dwnld_vlan_mode_cfg - configure VLAN mode after DDP download
419 * @hw: pointer to the HW structure
421 * This function is meant to configure any VLAN mode specific functionality
422 * after the global configuration lock has been released and the DDP has been
425 * Since only one PF downloads the DDP and configures the VLAN mode there needs
426 * to be a way to configure the other PFs after the DDP has been downloaded and
427 * the global configuration lock has been released. All such code should go in
430 void ice_post_pkg_dwnld_vlan_mode_cfg(struct ice_hw *hw)
432 ice_cache_vlan_mode(hw);
434 if (ice_is_dvm_ena(hw))
435 ice_change_proto_id_to_dvm();
437 ice_print_dvm_not_supported(hw);