107 lines · c
1// SPDX-License-Identifier: GPL-2.02/* Copyright (C) 2019-2021, Intel Corporation. */3 4#include "ice_pf_vsi_vlan_ops.h"5#include "ice_vf_vsi_vlan_ops.h"6#include "ice_sf_vsi_vlan_ops.h"7#include "ice_lib.h"8#include "ice.h"9 10static int11op_unsupported_vlan_arg(struct ice_vsi * __always_unused vsi,12 struct ice_vlan * __always_unused vlan)13{14 return -EOPNOTSUPP;15}16 17static int18op_unsupported_tpid_arg(struct ice_vsi *__always_unused vsi,19 u16 __always_unused tpid)20{21 return -EOPNOTSUPP;22}23 24static int op_unsupported(struct ice_vsi *__always_unused vsi)25{26 return -EOPNOTSUPP;27}28 29/* If any new ops are added to the VSI VLAN ops interface then an unsupported30 * implementation should be set here.31 */32static struct ice_vsi_vlan_ops ops_unsupported = {33 .add_vlan = op_unsupported_vlan_arg,34 .del_vlan = op_unsupported_vlan_arg,35 .ena_stripping = op_unsupported_tpid_arg,36 .dis_stripping = op_unsupported,37 .ena_insertion = op_unsupported_tpid_arg,38 .dis_insertion = op_unsupported,39 .ena_rx_filtering = op_unsupported,40 .dis_rx_filtering = op_unsupported,41 .ena_tx_filtering = op_unsupported,42 .dis_tx_filtering = op_unsupported,43 .set_port_vlan = op_unsupported_vlan_arg,44};45 46/**47 * ice_vsi_init_unsupported_vlan_ops - init all VSI VLAN ops to unsupported48 * @vsi: VSI to initialize VSI VLAN ops to unsupported for49 *50 * By default all inner and outer VSI VLAN ops return -EOPNOTSUPP. This was done51 * as oppsed to leaving the ops null to prevent unexpected crashes. Instead if52 * an unsupported VSI VLAN op is called it will just return -EOPNOTSUPP.53 *54 */55static void ice_vsi_init_unsupported_vlan_ops(struct ice_vsi *vsi)56{57 vsi->outer_vlan_ops = ops_unsupported;58 vsi->inner_vlan_ops = ops_unsupported;59}60 61/**62 * ice_vsi_init_vlan_ops - initialize type specific VSI VLAN ops63 * @vsi: VSI to initialize ops for64 *65 * If any VSI types are added and/or require different ops than the PF or VF VSI66 * then they will have to add a case here to handle that. Also, VSI type67 * specific files should be added in the same manner that was done for PF VSI.68 */69void ice_vsi_init_vlan_ops(struct ice_vsi *vsi)70{71 /* Initialize all VSI types to have unsupported VSI VLAN ops */72 ice_vsi_init_unsupported_vlan_ops(vsi);73 74 switch (vsi->type) {75 case ICE_VSI_PF:76 ice_pf_vsi_init_vlan_ops(vsi);77 break;78 case ICE_VSI_VF:79 ice_vf_vsi_init_vlan_ops(vsi);80 break;81 case ICE_VSI_SF:82 ice_sf_vsi_init_vlan_ops(vsi);83 break;84 default:85 dev_dbg(ice_pf_to_dev(vsi->back), "%s does not support VLAN operations\n",86 ice_vsi_type_str(vsi->type));87 break;88 }89}90 91/**92 * ice_get_compat_vsi_vlan_ops - Get VSI VLAN ops based on VLAN mode93 * @vsi: VSI used to get the VSI VLAN ops94 *95 * This function is meant to be used when the caller doesn't know which VLAN ops96 * to use (i.e. inner or outer). This allows backward compatibility for VLANs97 * since most of the Outer VSI VLAN functins are not supported when98 * the device is configured in Single VLAN Mode (SVM).99 */100struct ice_vsi_vlan_ops *ice_get_compat_vsi_vlan_ops(struct ice_vsi *vsi)101{102 if (ice_is_dvm_ena(&vsi->back->hw))103 return &vsi->outer_vlan_ops;104 else105 return &vsi->inner_vlan_ops;106}107