0001
0002
0003
0004 #include "ice_virtchnl.h"
0005 #include "ice_vf_lib_private.h"
0006 #include "ice.h"
0007 #include "ice_base.h"
0008 #include "ice_lib.h"
0009 #include "ice_fltr.h"
0010 #include "ice_virtchnl_allowlist.h"
0011 #include "ice_vf_vsi_vlan_ops.h"
0012 #include "ice_vlan.h"
0013 #include "ice_flex_pipe.h"
0014 #include "ice_dcb_lib.h"
0015
0016 #define FIELD_SELECTOR(proto_hdr_field) \
0017 BIT((proto_hdr_field) & PROTO_HDR_FIELD_MASK)
0018
0019 struct ice_vc_hdr_match_type {
0020 u32 vc_hdr;
0021 u32 ice_hdr;
0022 };
0023
0024 static const struct ice_vc_hdr_match_type ice_vc_hdr_list[] = {
0025 {VIRTCHNL_PROTO_HDR_NONE, ICE_FLOW_SEG_HDR_NONE},
0026 {VIRTCHNL_PROTO_HDR_ETH, ICE_FLOW_SEG_HDR_ETH},
0027 {VIRTCHNL_PROTO_HDR_S_VLAN, ICE_FLOW_SEG_HDR_VLAN},
0028 {VIRTCHNL_PROTO_HDR_C_VLAN, ICE_FLOW_SEG_HDR_VLAN},
0029 {VIRTCHNL_PROTO_HDR_IPV4, ICE_FLOW_SEG_HDR_IPV4 |
0030 ICE_FLOW_SEG_HDR_IPV_OTHER},
0031 {VIRTCHNL_PROTO_HDR_IPV6, ICE_FLOW_SEG_HDR_IPV6 |
0032 ICE_FLOW_SEG_HDR_IPV_OTHER},
0033 {VIRTCHNL_PROTO_HDR_TCP, ICE_FLOW_SEG_HDR_TCP},
0034 {VIRTCHNL_PROTO_HDR_UDP, ICE_FLOW_SEG_HDR_UDP},
0035 {VIRTCHNL_PROTO_HDR_SCTP, ICE_FLOW_SEG_HDR_SCTP},
0036 {VIRTCHNL_PROTO_HDR_PPPOE, ICE_FLOW_SEG_HDR_PPPOE},
0037 {VIRTCHNL_PROTO_HDR_GTPU_IP, ICE_FLOW_SEG_HDR_GTPU_IP},
0038 {VIRTCHNL_PROTO_HDR_GTPU_EH, ICE_FLOW_SEG_HDR_GTPU_EH},
0039 {VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
0040 ICE_FLOW_SEG_HDR_GTPU_DWN},
0041 {VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
0042 ICE_FLOW_SEG_HDR_GTPU_UP},
0043 {VIRTCHNL_PROTO_HDR_L2TPV3, ICE_FLOW_SEG_HDR_L2TPV3},
0044 {VIRTCHNL_PROTO_HDR_ESP, ICE_FLOW_SEG_HDR_ESP},
0045 {VIRTCHNL_PROTO_HDR_AH, ICE_FLOW_SEG_HDR_AH},
0046 {VIRTCHNL_PROTO_HDR_PFCP, ICE_FLOW_SEG_HDR_PFCP_SESSION},
0047 };
0048
0049 struct ice_vc_hash_field_match_type {
0050 u32 vc_hdr;
0051
0052
0053 u32 vc_hash_field;
0054
0055
0056 u64 ice_hash_field;
0057
0058
0059 };
0060
0061 static const struct
0062 ice_vc_hash_field_match_type ice_vc_hash_field_list[] = {
0063 {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC),
0064 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_SA)},
0065 {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST),
0066 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_DA)},
0067 {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC) |
0068 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST),
0069 ICE_FLOW_HASH_ETH},
0070 {VIRTCHNL_PROTO_HDR_ETH,
0071 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE),
0072 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_TYPE)},
0073 {VIRTCHNL_PROTO_HDR_S_VLAN,
0074 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_S_VLAN_ID),
0075 BIT_ULL(ICE_FLOW_FIELD_IDX_S_VLAN)},
0076 {VIRTCHNL_PROTO_HDR_C_VLAN,
0077 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_C_VLAN_ID),
0078 BIT_ULL(ICE_FLOW_FIELD_IDX_C_VLAN)},
0079 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC),
0080 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
0081 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST),
0082 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
0083 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
0084 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST),
0085 ICE_FLOW_HASH_IPV4},
0086 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
0087 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
0088 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
0089 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
0090 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) |
0091 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
0092 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
0093 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
0094 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
0095 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) |
0096 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
0097 ICE_FLOW_HASH_IPV4 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
0098 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
0099 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
0100 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC),
0101 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
0102 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST),
0103 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
0104 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
0105 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST),
0106 ICE_FLOW_HASH_IPV6},
0107 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
0108 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
0109 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
0110 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
0111 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) |
0112 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
0113 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
0114 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
0115 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
0116 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) |
0117 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
0118 ICE_FLOW_HASH_IPV6 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
0119 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
0120 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
0121 {VIRTCHNL_PROTO_HDR_TCP,
0122 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT),
0123 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
0124 {VIRTCHNL_PROTO_HDR_TCP,
0125 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT),
0126 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
0127 {VIRTCHNL_PROTO_HDR_TCP,
0128 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT) |
0129 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT),
0130 ICE_FLOW_HASH_TCP_PORT},
0131 {VIRTCHNL_PROTO_HDR_UDP,
0132 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT),
0133 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
0134 {VIRTCHNL_PROTO_HDR_UDP,
0135 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT),
0136 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
0137 {VIRTCHNL_PROTO_HDR_UDP,
0138 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT) |
0139 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT),
0140 ICE_FLOW_HASH_UDP_PORT},
0141 {VIRTCHNL_PROTO_HDR_SCTP,
0142 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT),
0143 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
0144 {VIRTCHNL_PROTO_HDR_SCTP,
0145 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT),
0146 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
0147 {VIRTCHNL_PROTO_HDR_SCTP,
0148 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT) |
0149 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT),
0150 ICE_FLOW_HASH_SCTP_PORT},
0151 {VIRTCHNL_PROTO_HDR_PPPOE,
0152 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID),
0153 BIT_ULL(ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID)},
0154 {VIRTCHNL_PROTO_HDR_GTPU_IP,
0155 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_GTPU_IP_TEID),
0156 BIT_ULL(ICE_FLOW_FIELD_IDX_GTPU_IP_TEID)},
0157 {VIRTCHNL_PROTO_HDR_L2TPV3,
0158 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID),
0159 BIT_ULL(ICE_FLOW_FIELD_IDX_L2TPV3_SESS_ID)},
0160 {VIRTCHNL_PROTO_HDR_ESP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ESP_SPI),
0161 BIT_ULL(ICE_FLOW_FIELD_IDX_ESP_SPI)},
0162 {VIRTCHNL_PROTO_HDR_AH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_AH_SPI),
0163 BIT_ULL(ICE_FLOW_FIELD_IDX_AH_SPI)},
0164 {VIRTCHNL_PROTO_HDR_PFCP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PFCP_SEID),
0165 BIT_ULL(ICE_FLOW_FIELD_IDX_PFCP_SEID)},
0166 };
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 static void
0177 ice_vc_vf_broadcast(struct ice_pf *pf, enum virtchnl_ops v_opcode,
0178 enum virtchnl_status_code v_retval, u8 *msg, u16 msglen)
0179 {
0180 struct ice_hw *hw = &pf->hw;
0181 struct ice_vf *vf;
0182 unsigned int bkt;
0183
0184 mutex_lock(&pf->vfs.table_lock);
0185 ice_for_each_vf(pf, bkt, vf) {
0186
0187 if (!test_bit(ICE_VF_STATE_INIT, vf->vf_states) &&
0188 !test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
0189 continue;
0190
0191
0192
0193
0194 ice_aq_send_msg_to_vf(hw, vf->vf_id, v_opcode, v_retval, msg,
0195 msglen, NULL);
0196 }
0197 mutex_unlock(&pf->vfs.table_lock);
0198 }
0199
0200
0201
0202
0203
0204
0205
0206
0207 static void
0208 ice_set_pfe_link(struct ice_vf *vf, struct virtchnl_pf_event *pfe,
0209 int ice_link_speed, bool link_up)
0210 {
0211 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
0212 pfe->event_data.link_event_adv.link_status = link_up;
0213
0214 pfe->event_data.link_event_adv.link_speed =
0215 ice_conv_link_speed_to_virtchnl(true, ice_link_speed);
0216 } else {
0217 pfe->event_data.link_event.link_status = link_up;
0218
0219 pfe->event_data.link_event.link_speed =
0220 (enum virtchnl_link_speed)
0221 ice_conv_link_speed_to_virtchnl(false, ice_link_speed);
0222 }
0223 }
0224
0225
0226
0227
0228
0229
0230
0231 void ice_vc_notify_vf_link_state(struct ice_vf *vf)
0232 {
0233 struct virtchnl_pf_event pfe = { 0 };
0234 struct ice_hw *hw = &vf->pf->hw;
0235
0236 pfe.event = VIRTCHNL_EVENT_LINK_CHANGE;
0237 pfe.severity = PF_EVENT_SEVERITY_INFO;
0238
0239 if (ice_is_vf_link_up(vf))
0240 ice_set_pfe_link(vf, &pfe,
0241 hw->port_info->phy.link_info.link_speed, true);
0242 else
0243 ice_set_pfe_link(vf, &pfe, ICE_AQ_LINK_SPEED_UNKNOWN, false);
0244
0245 ice_aq_send_msg_to_vf(hw, vf->vf_id, VIRTCHNL_OP_EVENT,
0246 VIRTCHNL_STATUS_SUCCESS, (u8 *)&pfe,
0247 sizeof(pfe), NULL);
0248 }
0249
0250
0251
0252
0253
0254 void ice_vc_notify_link_state(struct ice_pf *pf)
0255 {
0256 struct ice_vf *vf;
0257 unsigned int bkt;
0258
0259 mutex_lock(&pf->vfs.table_lock);
0260 ice_for_each_vf(pf, bkt, vf)
0261 ice_vc_notify_vf_link_state(vf);
0262 mutex_unlock(&pf->vfs.table_lock);
0263 }
0264
0265
0266
0267
0268
0269
0270
0271 void ice_vc_notify_reset(struct ice_pf *pf)
0272 {
0273 struct virtchnl_pf_event pfe;
0274
0275 if (!ice_has_vfs(pf))
0276 return;
0277
0278 pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
0279 pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
0280 ice_vc_vf_broadcast(pf, VIRTCHNL_OP_EVENT, VIRTCHNL_STATUS_SUCCESS,
0281 (u8 *)&pfe, sizeof(struct virtchnl_pf_event));
0282 }
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294 int
0295 ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
0296 enum virtchnl_status_code v_retval, u8 *msg, u16 msglen)
0297 {
0298 struct device *dev;
0299 struct ice_pf *pf;
0300 int aq_ret;
0301
0302 pf = vf->pf;
0303 dev = ice_pf_to_dev(pf);
0304
0305 aq_ret = ice_aq_send_msg_to_vf(&pf->hw, vf->vf_id, v_opcode, v_retval,
0306 msg, msglen, NULL);
0307 if (aq_ret && pf->hw.mailboxq.sq_last_status != ICE_AQ_RC_ENOSYS) {
0308 dev_info(dev, "Unable to send the message to VF %d ret %d aq_err %s\n",
0309 vf->vf_id, aq_ret,
0310 ice_aq_str(pf->hw.mailboxq.sq_last_status));
0311 return -EIO;
0312 }
0313
0314 return 0;
0315 }
0316
0317
0318
0319
0320
0321
0322
0323
0324 static int ice_vc_get_ver_msg(struct ice_vf *vf, u8 *msg)
0325 {
0326 struct virtchnl_version_info info = {
0327 VIRTCHNL_VERSION_MAJOR, VIRTCHNL_VERSION_MINOR
0328 };
0329
0330 vf->vf_ver = *(struct virtchnl_version_info *)msg;
0331
0332 if (VF_IS_V10(&vf->vf_ver))
0333 info.minor = VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
0334
0335 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION,
0336 VIRTCHNL_STATUS_SUCCESS, (u8 *)&info,
0337 sizeof(struct virtchnl_version_info));
0338 }
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349 static u16 ice_vc_get_max_frame_size(struct ice_vf *vf)
0350 {
0351 struct ice_port_info *pi = ice_vf_get_port_info(vf);
0352 u16 max_frame_size;
0353
0354 max_frame_size = pi->phy.link_info.max_frame_size;
0355
0356 if (ice_vf_is_port_vlan_ena(vf))
0357 max_frame_size -= VLAN_HLEN;
0358
0359 return max_frame_size;
0360 }
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371 static u32
0372 ice_vc_get_vlan_caps(struct ice_hw *hw, struct ice_vf *vf, struct ice_vsi *vsi,
0373 u32 driver_caps)
0374 {
0375 if (ice_is_eswitch_mode_switchdev(vf->pf))
0376
0377 return 0;
0378
0379 if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
0380
0381 return VIRTCHNL_VF_OFFLOAD_VLAN_V2;
0382 } else if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN) {
0383
0384
0385
0386
0387
0388
0389 if (ice_is_dvm_ena(hw) && ice_vf_is_port_vlan_ena(vf)) {
0390 return VIRTCHNL_VF_OFFLOAD_VLAN;
0391 } else if (!ice_is_dvm_ena(hw) &&
0392 !ice_vf_is_port_vlan_ena(vf)) {
0393
0394
0395
0396
0397 ice_vf_vsi_cfg_svm_legacy_vlan_mode(vsi);
0398 return VIRTCHNL_VF_OFFLOAD_VLAN;
0399 } else if (ice_is_dvm_ena(hw)) {
0400
0401
0402
0403 ice_vf_vsi_cfg_dvm_legacy_vlan_mode(vsi);
0404 }
0405 }
0406
0407 return 0;
0408 }
0409
0410
0411
0412
0413
0414
0415
0416
0417 static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg)
0418 {
0419 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
0420 struct virtchnl_vf_resource *vfres = NULL;
0421 struct ice_hw *hw = &vf->pf->hw;
0422 struct ice_vsi *vsi;
0423 int len = 0;
0424 int ret;
0425
0426 if (ice_check_vf_init(vf)) {
0427 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0428 goto err;
0429 }
0430
0431 len = sizeof(struct virtchnl_vf_resource);
0432
0433 vfres = kzalloc(len, GFP_KERNEL);
0434 if (!vfres) {
0435 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
0436 len = 0;
0437 goto err;
0438 }
0439 if (VF_IS_V11(&vf->vf_ver))
0440 vf->driver_caps = *(u32 *)msg;
0441 else
0442 vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 |
0443 VIRTCHNL_VF_OFFLOAD_RSS_REG |
0444 VIRTCHNL_VF_OFFLOAD_VLAN;
0445
0446 vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
0447 vsi = ice_get_vf_vsi(vf);
0448 if (!vsi) {
0449 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0450 goto err;
0451 }
0452
0453 vfres->vf_cap_flags |= ice_vc_get_vlan_caps(hw, vf, vsi,
0454 vf->driver_caps);
0455
0456 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
0457 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
0458 } else {
0459 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_AQ)
0460 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_AQ;
0461 else
0462 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_REG;
0463 }
0464
0465 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
0466 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_FDIR_PF;
0467
0468 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
0469 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
0470
0471 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
0472 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
0473
0474 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)
0475 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
0476
0477 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING)
0478 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
0479
0480 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
0481 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
0482
0483 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
0484 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
0485
0486 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
0487 vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
0488
0489 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF)
0490 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
0491
0492 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_USO)
0493 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_USO;
0494
0495 vfres->num_vsis = 1;
0496
0497 vfres->num_queue_pairs = vsi->num_txq;
0498 vfres->max_vectors = vf->pf->vfs.num_msix_per;
0499 vfres->rss_key_size = ICE_VSIQF_HKEY_ARRAY_SIZE;
0500 vfres->rss_lut_size = ICE_VSIQF_HLUT_ARRAY_SIZE;
0501 vfres->max_mtu = ice_vc_get_max_frame_size(vf);
0502
0503 vfres->vsi_res[0].vsi_id = vf->lan_vsi_num;
0504 vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
0505 vfres->vsi_res[0].num_queue_pairs = vsi->num_txq;
0506 ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
0507 vf->hw_lan_addr.addr);
0508
0509
0510 vf->driver_caps = vfres->vf_cap_flags;
0511
0512 ice_vc_set_caps_allowlist(vf);
0513 ice_vc_set_working_allowlist(vf);
0514
0515 set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
0516
0517 err:
0518
0519 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES, v_ret,
0520 (u8 *)vfres, len);
0521
0522 kfree(vfres);
0523 return ret;
0524 }
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534 static void ice_vc_reset_vf_msg(struct ice_vf *vf)
0535 {
0536 if (test_bit(ICE_VF_STATE_INIT, vf->vf_states))
0537 ice_reset_vf(vf, 0);
0538 }
0539
0540
0541
0542
0543
0544
0545
0546
0547 bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id)
0548 {
0549 struct ice_pf *pf = vf->pf;
0550 struct ice_vsi *vsi;
0551
0552 vsi = ice_find_vsi(pf, vsi_id);
0553
0554 return (vsi && (vsi->vf == vf));
0555 }
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565 static bool ice_vc_isvalid_q_id(struct ice_vf *vf, u16 vsi_id, u8 qid)
0566 {
0567 struct ice_vsi *vsi = ice_find_vsi(vf->pf, vsi_id);
0568
0569 return (vsi && (qid < vsi->alloc_txq));
0570 }
0571
0572
0573
0574
0575
0576
0577
0578
0579 static bool ice_vc_isvalid_ring_len(u16 ring_len)
0580 {
0581 return ring_len == 0 ||
0582 (ring_len >= ICE_MIN_NUM_DESC &&
0583 ring_len <= ICE_MAX_NUM_DESC &&
0584 !(ring_len % ICE_REQ_DESC_MULTIPLE));
0585 }
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596 bool
0597 ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto)
0598 {
0599 bool is_ipv4 = false;
0600 bool is_ipv6 = false;
0601 bool is_udp = false;
0602 u16 ptype = -1;
0603 int i = 0;
0604
0605 while (i < proto->count &&
0606 proto->proto_hdr[i].type != VIRTCHNL_PROTO_HDR_NONE) {
0607 switch (proto->proto_hdr[i].type) {
0608 case VIRTCHNL_PROTO_HDR_ETH:
0609 ptype = ICE_PTYPE_MAC_PAY;
0610 break;
0611 case VIRTCHNL_PROTO_HDR_IPV4:
0612 ptype = ICE_PTYPE_IPV4_PAY;
0613 is_ipv4 = true;
0614 break;
0615 case VIRTCHNL_PROTO_HDR_IPV6:
0616 ptype = ICE_PTYPE_IPV6_PAY;
0617 is_ipv6 = true;
0618 break;
0619 case VIRTCHNL_PROTO_HDR_UDP:
0620 if (is_ipv4)
0621 ptype = ICE_PTYPE_IPV4_UDP_PAY;
0622 else if (is_ipv6)
0623 ptype = ICE_PTYPE_IPV6_UDP_PAY;
0624 is_udp = true;
0625 break;
0626 case VIRTCHNL_PROTO_HDR_TCP:
0627 if (is_ipv4)
0628 ptype = ICE_PTYPE_IPV4_TCP_PAY;
0629 else if (is_ipv6)
0630 ptype = ICE_PTYPE_IPV6_TCP_PAY;
0631 break;
0632 case VIRTCHNL_PROTO_HDR_SCTP:
0633 if (is_ipv4)
0634 ptype = ICE_PTYPE_IPV4_SCTP_PAY;
0635 else if (is_ipv6)
0636 ptype = ICE_PTYPE_IPV6_SCTP_PAY;
0637 break;
0638 case VIRTCHNL_PROTO_HDR_GTPU_IP:
0639 case VIRTCHNL_PROTO_HDR_GTPU_EH:
0640 if (is_ipv4)
0641 ptype = ICE_MAC_IPV4_GTPU;
0642 else if (is_ipv6)
0643 ptype = ICE_MAC_IPV6_GTPU;
0644 goto out;
0645 case VIRTCHNL_PROTO_HDR_L2TPV3:
0646 if (is_ipv4)
0647 ptype = ICE_MAC_IPV4_L2TPV3;
0648 else if (is_ipv6)
0649 ptype = ICE_MAC_IPV6_L2TPV3;
0650 goto out;
0651 case VIRTCHNL_PROTO_HDR_ESP:
0652 if (is_ipv4)
0653 ptype = is_udp ? ICE_MAC_IPV4_NAT_T_ESP :
0654 ICE_MAC_IPV4_ESP;
0655 else if (is_ipv6)
0656 ptype = is_udp ? ICE_MAC_IPV6_NAT_T_ESP :
0657 ICE_MAC_IPV6_ESP;
0658 goto out;
0659 case VIRTCHNL_PROTO_HDR_AH:
0660 if (is_ipv4)
0661 ptype = ICE_MAC_IPV4_AH;
0662 else if (is_ipv6)
0663 ptype = ICE_MAC_IPV6_AH;
0664 goto out;
0665 case VIRTCHNL_PROTO_HDR_PFCP:
0666 if (is_ipv4)
0667 ptype = ICE_MAC_IPV4_PFCP_SESSION;
0668 else if (is_ipv6)
0669 ptype = ICE_MAC_IPV6_PFCP_SESSION;
0670 goto out;
0671 default:
0672 break;
0673 }
0674 i++;
0675 }
0676
0677 out:
0678 return ice_hw_ptype_ena(&vf->pf->hw, ptype);
0679 }
0680
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696 static bool
0697 ice_vc_parse_rss_cfg(struct ice_hw *hw, struct virtchnl_rss_cfg *rss_cfg,
0698 u32 *addl_hdrs, u64 *hash_flds)
0699 {
0700 const struct ice_vc_hash_field_match_type *hf_list;
0701 const struct ice_vc_hdr_match_type *hdr_list;
0702 int i, hf_list_len, hdr_list_len;
0703
0704 hf_list = ice_vc_hash_field_list;
0705 hf_list_len = ARRAY_SIZE(ice_vc_hash_field_list);
0706 hdr_list = ice_vc_hdr_list;
0707 hdr_list_len = ARRAY_SIZE(ice_vc_hdr_list);
0708
0709 for (i = 0; i < rss_cfg->proto_hdrs.count; i++) {
0710 struct virtchnl_proto_hdr *proto_hdr =
0711 &rss_cfg->proto_hdrs.proto_hdr[i];
0712 bool hdr_found = false;
0713 int j;
0714
0715
0716 for (j = 0; j < hdr_list_len; j++) {
0717 struct ice_vc_hdr_match_type hdr_map = hdr_list[j];
0718
0719 if (proto_hdr->type == hdr_map.vc_hdr) {
0720 *addl_hdrs |= hdr_map.ice_hdr;
0721 hdr_found = true;
0722 }
0723 }
0724
0725 if (!hdr_found)
0726 return false;
0727
0728
0729
0730
0731 for (j = 0; j < hf_list_len; j++) {
0732 struct ice_vc_hash_field_match_type hf_map = hf_list[j];
0733
0734 if (proto_hdr->type == hf_map.vc_hdr &&
0735 proto_hdr->field_selector == hf_map.vc_hash_field) {
0736 *hash_flds |= hf_map.ice_hash_field;
0737 break;
0738 }
0739 }
0740 }
0741
0742 return true;
0743 }
0744
0745
0746
0747
0748
0749
0750
0751
0752
0753 static bool ice_vf_adv_rss_offload_ena(u32 caps)
0754 {
0755 return !!(caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF);
0756 }
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766 static int ice_vc_handle_rss_cfg(struct ice_vf *vf, u8 *msg, bool add)
0767 {
0768 u32 v_opcode = add ? VIRTCHNL_OP_ADD_RSS_CFG : VIRTCHNL_OP_DEL_RSS_CFG;
0769 struct virtchnl_rss_cfg *rss_cfg = (struct virtchnl_rss_cfg *)msg;
0770 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
0771 struct device *dev = ice_pf_to_dev(vf->pf);
0772 struct ice_hw *hw = &vf->pf->hw;
0773 struct ice_vsi *vsi;
0774
0775 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
0776 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS is not supported by the PF\n",
0777 vf->vf_id);
0778 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
0779 goto error_param;
0780 }
0781
0782 if (!ice_vf_adv_rss_offload_ena(vf->driver_caps)) {
0783 dev_dbg(dev, "VF %d attempting to configure RSS, but Advanced RSS offload is not supported\n",
0784 vf->vf_id);
0785 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0786 goto error_param;
0787 }
0788
0789 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
0790 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0791 goto error_param;
0792 }
0793
0794 if (rss_cfg->proto_hdrs.count > VIRTCHNL_MAX_NUM_PROTO_HDRS ||
0795 rss_cfg->rss_algorithm < VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC ||
0796 rss_cfg->rss_algorithm > VIRTCHNL_RSS_ALG_XOR_SYMMETRIC) {
0797 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS configuration is not valid\n",
0798 vf->vf_id);
0799 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0800 goto error_param;
0801 }
0802
0803 vsi = ice_get_vf_vsi(vf);
0804 if (!vsi) {
0805 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0806 goto error_param;
0807 }
0808
0809 if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
0810 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0811 goto error_param;
0812 }
0813
0814 if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_R_ASYMMETRIC) {
0815 struct ice_vsi_ctx *ctx;
0816 u8 lut_type, hash_type;
0817 int status;
0818
0819 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
0820 hash_type = add ? ICE_AQ_VSI_Q_OPT_RSS_XOR :
0821 ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
0822
0823 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
0824 if (!ctx) {
0825 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
0826 goto error_param;
0827 }
0828
0829 ctx->info.q_opt_rss = ((lut_type <<
0830 ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
0831 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
0832 (hash_type &
0833 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
0834
0835
0836 ctx->info.q_opt_rss |= (vsi->info.q_opt_rss &
0837 ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
0838 ctx->info.q_opt_tc = vsi->info.q_opt_tc;
0839 ctx->info.q_opt_flags = vsi->info.q_opt_rss;
0840
0841 ctx->info.valid_sections =
0842 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
0843
0844 status = ice_update_vsi(hw, vsi->idx, ctx, NULL);
0845 if (status) {
0846 dev_err(dev, "update VSI for RSS failed, err %d aq_err %s\n",
0847 status, ice_aq_str(hw->adminq.sq_last_status));
0848 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0849 } else {
0850 vsi->info.q_opt_rss = ctx->info.q_opt_rss;
0851 }
0852
0853 kfree(ctx);
0854 } else {
0855 u32 addl_hdrs = ICE_FLOW_SEG_HDR_NONE;
0856 u64 hash_flds = ICE_HASH_INVALID;
0857
0858 if (!ice_vc_parse_rss_cfg(hw, rss_cfg, &addl_hdrs,
0859 &hash_flds)) {
0860 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0861 goto error_param;
0862 }
0863
0864 if (add) {
0865 if (ice_add_rss_cfg(hw, vsi->idx, hash_flds,
0866 addl_hdrs)) {
0867 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0868 dev_err(dev, "ice_add_rss_cfg failed for vsi = %d, v_ret = %d\n",
0869 vsi->vsi_num, v_ret);
0870 }
0871 } else {
0872 int status;
0873
0874 status = ice_rem_rss_cfg(hw, vsi->idx, hash_flds,
0875 addl_hdrs);
0876
0877
0878
0879
0880 if (status && status != -ENOENT) {
0881 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0882 dev_err(dev, "ice_rem_rss_cfg failed for VF ID:%d, error:%d\n",
0883 vf->vf_id, status);
0884 }
0885 }
0886 }
0887
0888 error_param:
0889 return ice_vc_send_msg_to_vf(vf, v_opcode, v_ret, NULL, 0);
0890 }
0891
0892
0893
0894
0895
0896
0897
0898
0899 static int ice_vc_config_rss_key(struct ice_vf *vf, u8 *msg)
0900 {
0901 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
0902 struct virtchnl_rss_key *vrk =
0903 (struct virtchnl_rss_key *)msg;
0904 struct ice_vsi *vsi;
0905
0906 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
0907 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0908 goto error_param;
0909 }
0910
0911 if (!ice_vc_isvalid_vsi_id(vf, vrk->vsi_id)) {
0912 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0913 goto error_param;
0914 }
0915
0916 if (vrk->key_len != ICE_VSIQF_HKEY_ARRAY_SIZE) {
0917 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0918 goto error_param;
0919 }
0920
0921 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
0922 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0923 goto error_param;
0924 }
0925
0926 vsi = ice_get_vf_vsi(vf);
0927 if (!vsi) {
0928 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0929 goto error_param;
0930 }
0931
0932 if (ice_set_rss_key(vsi, vrk->key))
0933 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
0934 error_param:
0935 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY, v_ret,
0936 NULL, 0);
0937 }
0938
0939
0940
0941
0942
0943
0944
0945
0946 static int ice_vc_config_rss_lut(struct ice_vf *vf, u8 *msg)
0947 {
0948 struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
0949 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
0950 struct ice_vsi *vsi;
0951
0952 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
0953 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0954 goto error_param;
0955 }
0956
0957 if (!ice_vc_isvalid_vsi_id(vf, vrl->vsi_id)) {
0958 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0959 goto error_param;
0960 }
0961
0962 if (vrl->lut_entries != ICE_VSIQF_HLUT_ARRAY_SIZE) {
0963 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0964 goto error_param;
0965 }
0966
0967 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
0968 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0969 goto error_param;
0970 }
0971
0972 vsi = ice_get_vf_vsi(vf);
0973 if (!vsi) {
0974 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
0975 goto error_param;
0976 }
0977
0978 if (ice_set_rss_lut(vsi, vrl->lut, ICE_VSIQF_HLUT_ARRAY_SIZE))
0979 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
0980 error_param:
0981 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT, v_ret,
0982 NULL, 0);
0983 }
0984
0985
0986
0987
0988
0989
0990
0991
0992 static int ice_vc_cfg_promiscuous_mode_msg(struct ice_vf *vf, u8 *msg)
0993 {
0994 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
0995 bool rm_promisc, alluni = false, allmulti = false;
0996 struct virtchnl_promisc_info *info =
0997 (struct virtchnl_promisc_info *)msg;
0998 struct ice_vsi_vlan_ops *vlan_ops;
0999 int mcast_err = 0, ucast_err = 0;
1000 struct ice_pf *pf = vf->pf;
1001 struct ice_vsi *vsi;
1002 u8 mcast_m, ucast_m;
1003 struct device *dev;
1004 int ret = 0;
1005
1006 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1007 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1008 goto error_param;
1009 }
1010
1011 if (!ice_vc_isvalid_vsi_id(vf, info->vsi_id)) {
1012 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1013 goto error_param;
1014 }
1015
1016 vsi = ice_get_vf_vsi(vf);
1017 if (!vsi) {
1018 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1019 goto error_param;
1020 }
1021
1022 dev = ice_pf_to_dev(pf);
1023 if (!ice_is_vf_trusted(vf)) {
1024 dev_err(dev, "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1025 vf->vf_id);
1026
1027 goto error_param;
1028 }
1029
1030 if (info->flags & FLAG_VF_UNICAST_PROMISC)
1031 alluni = true;
1032
1033 if (info->flags & FLAG_VF_MULTICAST_PROMISC)
1034 allmulti = true;
1035
1036 rm_promisc = !allmulti && !alluni;
1037
1038 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
1039 if (rm_promisc)
1040 ret = vlan_ops->ena_rx_filtering(vsi);
1041 else
1042 ret = vlan_ops->dis_rx_filtering(vsi);
1043 if (ret) {
1044 dev_err(dev, "Failed to configure VLAN pruning in promiscuous mode\n");
1045 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1046 goto error_param;
1047 }
1048
1049 ice_vf_get_promisc_masks(vf, vsi, &ucast_m, &mcast_m);
1050
1051 if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) {
1052 if (alluni) {
1053
1054 ret = ice_set_dflt_vsi(vsi);
1055 } else {
1056
1057 if (ice_is_dflt_vsi_in_use(vsi->port_info))
1058 ret = ice_clear_dflt_vsi(vsi);
1059 }
1060
1061
1062
1063
1064 if (allmulti)
1065 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1066 else
1067 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1068
1069 if (ret) {
1070 dev_err(dev, "Turning on/off promiscuous mode for VF %d failed, error: %d\n",
1071 vf->vf_id, ret);
1072 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1073 goto error_param;
1074 }
1075 } else {
1076 if (alluni)
1077 ucast_err = ice_vf_set_vsi_promisc(vf, vsi, ucast_m);
1078 else
1079 ucast_err = ice_vf_clear_vsi_promisc(vf, vsi, ucast_m);
1080
1081 if (allmulti)
1082 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1083 else
1084 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1085
1086 if (ucast_err || mcast_err)
1087 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1088 }
1089
1090 if (!mcast_err) {
1091 if (allmulti &&
1092 !test_and_set_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
1093 dev_info(dev, "VF %u successfully set multicast promiscuous mode\n",
1094 vf->vf_id);
1095 else if (!allmulti &&
1096 test_and_clear_bit(ICE_VF_STATE_MC_PROMISC,
1097 vf->vf_states))
1098 dev_info(dev, "VF %u successfully unset multicast promiscuous mode\n",
1099 vf->vf_id);
1100 } else {
1101 dev_err(dev, "Error while modifying multicast promiscuous mode for VF %u, error: %d\n",
1102 vf->vf_id, mcast_err);
1103 }
1104
1105 if (!ucast_err) {
1106 if (alluni &&
1107 !test_and_set_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
1108 dev_info(dev, "VF %u successfully set unicast promiscuous mode\n",
1109 vf->vf_id);
1110 else if (!alluni &&
1111 test_and_clear_bit(ICE_VF_STATE_UC_PROMISC,
1112 vf->vf_states))
1113 dev_info(dev, "VF %u successfully unset unicast promiscuous mode\n",
1114 vf->vf_id);
1115 } else {
1116 dev_err(dev, "Error while modifying unicast promiscuous mode for VF %u, error: %d\n",
1117 vf->vf_id, ucast_err);
1118 }
1119
1120 error_param:
1121 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1122 v_ret, NULL, 0);
1123 }
1124
1125
1126
1127
1128
1129
1130
1131
1132 static int ice_vc_get_stats_msg(struct ice_vf *vf, u8 *msg)
1133 {
1134 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1135 struct virtchnl_queue_select *vqs =
1136 (struct virtchnl_queue_select *)msg;
1137 struct ice_eth_stats stats = { 0 };
1138 struct ice_vsi *vsi;
1139
1140 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1141 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1142 goto error_param;
1143 }
1144
1145 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1146 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1147 goto error_param;
1148 }
1149
1150 vsi = ice_get_vf_vsi(vf);
1151 if (!vsi) {
1152 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1153 goto error_param;
1154 }
1155
1156 ice_update_eth_stats(vsi);
1157
1158 stats = vsi->eth_stats;
1159
1160 error_param:
1161
1162 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, v_ret,
1163 (u8 *)&stats, sizeof(stats));
1164 }
1165
1166
1167
1168
1169
1170
1171
1172 static bool ice_vc_validate_vqs_bitmaps(struct virtchnl_queue_select *vqs)
1173 {
1174 if ((!vqs->rx_queues && !vqs->tx_queues) ||
1175 vqs->rx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF) ||
1176 vqs->tx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF))
1177 return false;
1178
1179 return true;
1180 }
1181
1182
1183
1184
1185
1186
1187 static void ice_vf_ena_txq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1188 {
1189 struct ice_hw *hw = &vsi->back->hw;
1190 u32 pfq = vsi->txq_map[q_idx];
1191 u32 reg;
1192
1193 reg = rd32(hw, QINT_TQCTL(pfq));
1194
1195
1196
1197
1198
1199 if (!(reg & QINT_TQCTL_MSIX_INDX_M))
1200 return;
1201
1202 wr32(hw, QINT_TQCTL(pfq), reg | QINT_TQCTL_CAUSE_ENA_M);
1203 }
1204
1205
1206
1207
1208
1209
1210 static void ice_vf_ena_rxq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1211 {
1212 struct ice_hw *hw = &vsi->back->hw;
1213 u32 pfq = vsi->rxq_map[q_idx];
1214 u32 reg;
1215
1216 reg = rd32(hw, QINT_RQCTL(pfq));
1217
1218
1219
1220
1221
1222 if (!(reg & QINT_RQCTL_MSIX_INDX_M))
1223 return;
1224
1225 wr32(hw, QINT_RQCTL(pfq), reg | QINT_RQCTL_CAUSE_ENA_M);
1226 }
1227
1228
1229
1230
1231
1232
1233
1234
1235 static int ice_vc_ena_qs_msg(struct ice_vf *vf, u8 *msg)
1236 {
1237 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1238 struct virtchnl_queue_select *vqs =
1239 (struct virtchnl_queue_select *)msg;
1240 struct ice_vsi *vsi;
1241 unsigned long q_map;
1242 u16 vf_q_id;
1243
1244 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1245 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1246 goto error_param;
1247 }
1248
1249 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1250 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1251 goto error_param;
1252 }
1253
1254 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1255 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1256 goto error_param;
1257 }
1258
1259 vsi = ice_get_vf_vsi(vf);
1260 if (!vsi) {
1261 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1262 goto error_param;
1263 }
1264
1265
1266
1267
1268
1269 q_map = vqs->rx_queues;
1270 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1271 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1272 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1273 goto error_param;
1274 }
1275
1276
1277 if (test_bit(vf_q_id, vf->rxq_ena))
1278 continue;
1279
1280 if (ice_vsi_ctrl_one_rx_ring(vsi, true, vf_q_id, true)) {
1281 dev_err(ice_pf_to_dev(vsi->back), "Failed to enable Rx ring %d on VSI %d\n",
1282 vf_q_id, vsi->vsi_num);
1283 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1284 goto error_param;
1285 }
1286
1287 ice_vf_ena_rxq_interrupt(vsi, vf_q_id);
1288 set_bit(vf_q_id, vf->rxq_ena);
1289 }
1290
1291 q_map = vqs->tx_queues;
1292 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1293 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1294 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1295 goto error_param;
1296 }
1297
1298
1299 if (test_bit(vf_q_id, vf->txq_ena))
1300 continue;
1301
1302 ice_vf_ena_txq_interrupt(vsi, vf_q_id);
1303 set_bit(vf_q_id, vf->txq_ena);
1304 }
1305
1306
1307 if (v_ret == VIRTCHNL_STATUS_SUCCESS)
1308 set_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1309
1310 error_param:
1311
1312 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES, v_ret,
1313 NULL, 0);
1314 }
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326 static int
1327 ice_vf_vsi_dis_single_txq(struct ice_vf *vf, struct ice_vsi *vsi, u16 q_id)
1328 {
1329 struct ice_txq_meta txq_meta = { 0 };
1330 struct ice_tx_ring *ring;
1331 int err;
1332
1333 if (!test_bit(q_id, vf->txq_ena))
1334 dev_dbg(ice_pf_to_dev(vsi->back), "Queue %u on VSI %u is not enabled, but stopping it anyway\n",
1335 q_id, vsi->vsi_num);
1336
1337 ring = vsi->tx_rings[q_id];
1338 if (!ring)
1339 return -EINVAL;
1340
1341 ice_fill_txq_meta(vsi, ring, &txq_meta);
1342
1343 err = ice_vsi_stop_tx_ring(vsi, ICE_NO_RESET, vf->vf_id, ring, &txq_meta);
1344 if (err) {
1345 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Tx ring %d on VSI %d\n",
1346 q_id, vsi->vsi_num);
1347 return err;
1348 }
1349
1350
1351 clear_bit(q_id, vf->txq_ena);
1352
1353 return 0;
1354 }
1355
1356
1357
1358
1359
1360
1361
1362
1363 static int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg)
1364 {
1365 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1366 struct virtchnl_queue_select *vqs =
1367 (struct virtchnl_queue_select *)msg;
1368 struct ice_vsi *vsi;
1369 unsigned long q_map;
1370 u16 vf_q_id;
1371
1372 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) &&
1373 !test_bit(ICE_VF_STATE_QS_ENA, vf->vf_states)) {
1374 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1375 goto error_param;
1376 }
1377
1378 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1379 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1380 goto error_param;
1381 }
1382
1383 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1384 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1385 goto error_param;
1386 }
1387
1388 vsi = ice_get_vf_vsi(vf);
1389 if (!vsi) {
1390 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1391 goto error_param;
1392 }
1393
1394 if (vqs->tx_queues) {
1395 q_map = vqs->tx_queues;
1396
1397 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1398 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1399 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1400 goto error_param;
1401 }
1402
1403 if (ice_vf_vsi_dis_single_txq(vf, vsi, vf_q_id)) {
1404 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1405 goto error_param;
1406 }
1407 }
1408 }
1409
1410 q_map = vqs->rx_queues;
1411
1412 if (q_map &&
1413 bitmap_equal(&q_map, vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF)) {
1414 if (ice_vsi_stop_all_rx_rings(vsi)) {
1415 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop all Rx rings on VSI %d\n",
1416 vsi->vsi_num);
1417 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1418 goto error_param;
1419 }
1420
1421 bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF);
1422 } else if (q_map) {
1423 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1424 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1425 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1426 goto error_param;
1427 }
1428
1429
1430 if (!test_bit(vf_q_id, vf->rxq_ena))
1431 continue;
1432
1433 if (ice_vsi_ctrl_one_rx_ring(vsi, false, vf_q_id,
1434 true)) {
1435 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Rx ring %d on VSI %d\n",
1436 vf_q_id, vsi->vsi_num);
1437 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1438 goto error_param;
1439 }
1440
1441
1442 clear_bit(vf_q_id, vf->rxq_ena);
1443 }
1444 }
1445
1446
1447 if (v_ret == VIRTCHNL_STATUS_SUCCESS && ice_vf_has_no_qs_ena(vf))
1448 clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1449
1450 error_param:
1451
1452 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES, v_ret,
1453 NULL, 0);
1454 }
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465 static int
1466 ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi, u16 vector_id,
1467 struct virtchnl_vector_map *map,
1468 struct ice_q_vector *q_vector)
1469 {
1470 u16 vsi_q_id, vsi_q_id_idx;
1471 unsigned long qmap;
1472
1473 q_vector->num_ring_rx = 0;
1474 q_vector->num_ring_tx = 0;
1475
1476 qmap = map->rxq_map;
1477 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1478 vsi_q_id = vsi_q_id_idx;
1479
1480 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id))
1481 return VIRTCHNL_STATUS_ERR_PARAM;
1482
1483 q_vector->num_ring_rx++;
1484 q_vector->rx.itr_idx = map->rxitr_idx;
1485 vsi->rx_rings[vsi_q_id]->q_vector = q_vector;
1486 ice_cfg_rxq_interrupt(vsi, vsi_q_id, vector_id,
1487 q_vector->rx.itr_idx);
1488 }
1489
1490 qmap = map->txq_map;
1491 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1492 vsi_q_id = vsi_q_id_idx;
1493
1494 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id))
1495 return VIRTCHNL_STATUS_ERR_PARAM;
1496
1497 q_vector->num_ring_tx++;
1498 q_vector->tx.itr_idx = map->txitr_idx;
1499 vsi->tx_rings[vsi_q_id]->q_vector = q_vector;
1500 ice_cfg_txq_interrupt(vsi, vsi_q_id, vector_id,
1501 q_vector->tx.itr_idx);
1502 }
1503
1504 return VIRTCHNL_STATUS_SUCCESS;
1505 }
1506
1507
1508
1509
1510
1511
1512
1513
1514 static int ice_vc_cfg_irq_map_msg(struct ice_vf *vf, u8 *msg)
1515 {
1516 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1517 u16 num_q_vectors_mapped, vsi_id, vector_id;
1518 struct virtchnl_irq_map_info *irqmap_info;
1519 struct virtchnl_vector_map *map;
1520 struct ice_pf *pf = vf->pf;
1521 struct ice_vsi *vsi;
1522 int i;
1523
1524 irqmap_info = (struct virtchnl_irq_map_info *)msg;
1525 num_q_vectors_mapped = irqmap_info->num_vectors;
1526
1527
1528
1529
1530
1531 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1532 pf->vfs.num_msix_per < num_q_vectors_mapped ||
1533 !num_q_vectors_mapped) {
1534 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1535 goto error_param;
1536 }
1537
1538 vsi = ice_get_vf_vsi(vf);
1539 if (!vsi) {
1540 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1541 goto error_param;
1542 }
1543
1544 for (i = 0; i < num_q_vectors_mapped; i++) {
1545 struct ice_q_vector *q_vector;
1546
1547 map = &irqmap_info->vecmap[i];
1548
1549 vector_id = map->vector_id;
1550 vsi_id = map->vsi_id;
1551
1552
1553
1554 if (!(vector_id < pf->vfs.num_msix_per) ||
1555 !ice_vc_isvalid_vsi_id(vf, vsi_id) ||
1556 (!vector_id && (map->rxq_map || map->txq_map))) {
1557 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1558 goto error_param;
1559 }
1560
1561
1562 if (!vector_id)
1563 continue;
1564
1565
1566
1567
1568 q_vector = vsi->q_vectors[vector_id - ICE_NONQ_VECS_VF];
1569 if (!q_vector) {
1570 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1571 goto error_param;
1572 }
1573
1574
1575 v_ret = (enum virtchnl_status_code)
1576 ice_cfg_interrupt(vf, vsi, vector_id, map, q_vector);
1577 if (v_ret)
1578 goto error_param;
1579 }
1580
1581 error_param:
1582
1583 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP, v_ret,
1584 NULL, 0);
1585 }
1586
1587
1588
1589
1590
1591
1592
1593
1594 static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
1595 {
1596 struct virtchnl_vsi_queue_config_info *qci =
1597 (struct virtchnl_vsi_queue_config_info *)msg;
1598 struct virtchnl_queue_pair_info *qpi;
1599 struct ice_pf *pf = vf->pf;
1600 struct ice_vsi *vsi;
1601 int i = -1, q_idx;
1602
1603 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
1604 goto error_param;
1605
1606 if (!ice_vc_isvalid_vsi_id(vf, qci->vsi_id))
1607 goto error_param;
1608
1609 vsi = ice_get_vf_vsi(vf);
1610 if (!vsi)
1611 goto error_param;
1612
1613 if (qci->num_queue_pairs > ICE_MAX_RSS_QS_PER_VF ||
1614 qci->num_queue_pairs > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
1615 dev_err(ice_pf_to_dev(pf), "VF-%d requesting more than supported number of queues: %d\n",
1616 vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
1617 goto error_param;
1618 }
1619
1620 for (i = 0; i < qci->num_queue_pairs; i++) {
1621 qpi = &qci->qpair[i];
1622 if (qpi->txq.vsi_id != qci->vsi_id ||
1623 qpi->rxq.vsi_id != qci->vsi_id ||
1624 qpi->rxq.queue_id != qpi->txq.queue_id ||
1625 qpi->txq.headwb_enabled ||
1626 !ice_vc_isvalid_ring_len(qpi->txq.ring_len) ||
1627 !ice_vc_isvalid_ring_len(qpi->rxq.ring_len) ||
1628 !ice_vc_isvalid_q_id(vf, qci->vsi_id, qpi->txq.queue_id)) {
1629 goto error_param;
1630 }
1631
1632 q_idx = qpi->rxq.queue_id;
1633
1634
1635
1636
1637 if (q_idx >= vsi->alloc_txq || q_idx >= vsi->alloc_rxq) {
1638 goto error_param;
1639 }
1640
1641
1642 if (qpi->txq.ring_len > 0) {
1643 vsi->tx_rings[i]->dma = qpi->txq.dma_ring_addr;
1644 vsi->tx_rings[i]->count = qpi->txq.ring_len;
1645
1646
1647 if (ice_vf_vsi_dis_single_txq(vf, vsi, q_idx))
1648 goto error_param;
1649
1650
1651 if (ice_vsi_cfg_single_txq(vsi, vsi->tx_rings, q_idx)) {
1652 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure TX queue %d\n",
1653 vf->vf_id, i);
1654 goto error_param;
1655 }
1656 }
1657
1658
1659 if (qpi->rxq.ring_len > 0) {
1660 u16 max_frame_size = ice_vc_get_max_frame_size(vf);
1661
1662 vsi->rx_rings[i]->dma = qpi->rxq.dma_ring_addr;
1663 vsi->rx_rings[i]->count = qpi->rxq.ring_len;
1664
1665 if (qpi->rxq.databuffer_size != 0 &&
1666 (qpi->rxq.databuffer_size > ((16 * 1024) - 128) ||
1667 qpi->rxq.databuffer_size < 1024))
1668 goto error_param;
1669 vsi->rx_buf_len = qpi->rxq.databuffer_size;
1670 vsi->rx_rings[i]->rx_buf_len = vsi->rx_buf_len;
1671 if (qpi->rxq.max_pkt_size > max_frame_size ||
1672 qpi->rxq.max_pkt_size < 64)
1673 goto error_param;
1674
1675 vsi->max_frame = qpi->rxq.max_pkt_size;
1676
1677
1678
1679
1680 if (ice_vf_is_port_vlan_ena(vf))
1681 vsi->max_frame += VLAN_HLEN;
1682
1683 if (ice_vsi_cfg_single_rxq(vsi, q_idx)) {
1684 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure RX queue %d\n",
1685 vf->vf_id, i);
1686 goto error_param;
1687 }
1688 }
1689 }
1690
1691
1692 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1693 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
1694 error_param:
1695
1696 for (; i >= 0; i--) {
1697 if (ice_vsi_ctrl_one_rx_ring(vsi, false, i, true))
1698 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable RX queue %d\n",
1699 vf->vf_id, i);
1700 if (ice_vf_vsi_dis_single_txq(vf, vsi, i))
1701 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable TX queue %d\n",
1702 vf->vf_id, i);
1703 }
1704
1705
1706 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1707 VIRTCHNL_STATUS_ERR_PARAM, NULL, 0);
1708 }
1709
1710
1711
1712
1713
1714
1715
1716 static bool ice_can_vf_change_mac(struct ice_vf *vf)
1717 {
1718
1719
1720
1721
1722 if (vf->pf_set_mac && !ice_is_vf_trusted(vf))
1723 return false;
1724
1725 return true;
1726 }
1727
1728
1729
1730
1731
1732 static u8
1733 ice_vc_ether_addr_type(struct virtchnl_ether_addr *vc_ether_addr)
1734 {
1735 return (vc_ether_addr->type & VIRTCHNL_ETHER_ADDR_TYPE_MASK);
1736 }
1737
1738
1739
1740
1741
1742 static bool
1743 ice_is_vc_addr_legacy(struct virtchnl_ether_addr *vc_ether_addr)
1744 {
1745 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1746
1747 return (type == VIRTCHNL_ETHER_ADDR_LEGACY);
1748 }
1749
1750
1751
1752
1753
1754
1755
1756
1757 static bool
1758 ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused *vc_ether_addr)
1759 {
1760 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1761
1762 return (type == VIRTCHNL_ETHER_ADDR_PRIMARY);
1763 }
1764
1765
1766
1767
1768
1769
1770 static void
1771 ice_vfhw_mac_add(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1772 {
1773 u8 *mac_addr = vc_ether_addr->addr;
1774
1775 if (!is_valid_ether_addr(mac_addr))
1776 return;
1777
1778
1779
1780
1781
1782 if ((ice_is_vc_addr_legacy(vc_ether_addr) &&
1783 is_zero_ether_addr(vf->hw_lan_addr.addr)) ||
1784 ice_is_vc_addr_primary(vc_ether_addr)) {
1785 ether_addr_copy(vf->dev_lan_addr.addr, mac_addr);
1786 ether_addr_copy(vf->hw_lan_addr.addr, mac_addr);
1787 }
1788
1789
1790
1791
1792
1793
1794
1795 if (ice_is_vc_addr_legacy(vc_ether_addr)) {
1796 ether_addr_copy(vf->legacy_last_added_umac.addr,
1797 mac_addr);
1798 vf->legacy_last_added_umac.time_modified = jiffies;
1799 }
1800 }
1801
1802
1803
1804
1805
1806
1807
1808 static int
1809 ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1810 struct virtchnl_ether_addr *vc_ether_addr)
1811 {
1812 struct device *dev = ice_pf_to_dev(vf->pf);
1813 u8 *mac_addr = vc_ether_addr->addr;
1814 int ret;
1815
1816
1817 if (ether_addr_equal(mac_addr, vf->dev_lan_addr.addr))
1818 return 0;
1819
1820 if (is_unicast_ether_addr(mac_addr) && !ice_can_vf_change_mac(vf)) {
1821 dev_err(dev, "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
1822 return -EPERM;
1823 }
1824
1825 ret = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1826 if (ret == -EEXIST) {
1827 dev_dbg(dev, "MAC %pM already exists for VF %d\n", mac_addr,
1828 vf->vf_id);
1829
1830
1831
1832 } else if (ret) {
1833 dev_err(dev, "Failed to add MAC %pM for VF %d\n, error %d\n",
1834 mac_addr, vf->vf_id, ret);
1835 return ret;
1836 } else {
1837 vf->num_mac++;
1838 }
1839
1840 ice_vfhw_mac_add(vf, vc_ether_addr);
1841
1842 return ret;
1843 }
1844
1845
1846
1847
1848
1849 static bool ice_is_legacy_umac_expired(struct ice_time_mac *last_added_umac)
1850 {
1851 #define ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME msecs_to_jiffies(3000)
1852 return time_is_before_jiffies(last_added_umac->time_modified +
1853 ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME);
1854 }
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864 static void
1865 ice_update_legacy_cached_mac(struct ice_vf *vf,
1866 struct virtchnl_ether_addr *vc_ether_addr)
1867 {
1868 if (!ice_is_vc_addr_legacy(vc_ether_addr) ||
1869 ice_is_legacy_umac_expired(&vf->legacy_last_added_umac))
1870 return;
1871
1872 ether_addr_copy(vf->dev_lan_addr.addr, vf->legacy_last_added_umac.addr);
1873 ether_addr_copy(vf->hw_lan_addr.addr, vf->legacy_last_added_umac.addr);
1874 }
1875
1876
1877
1878
1879
1880
1881 static void
1882 ice_vfhw_mac_del(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1883 {
1884 u8 *mac_addr = vc_ether_addr->addr;
1885
1886 if (!is_valid_ether_addr(mac_addr) ||
1887 !ether_addr_equal(vf->dev_lan_addr.addr, mac_addr))
1888 return;
1889
1890
1891
1892
1893
1894
1895 eth_zero_addr(vf->dev_lan_addr.addr);
1896
1897 ice_update_legacy_cached_mac(vf, vc_ether_addr);
1898 }
1899
1900
1901
1902
1903
1904
1905
1906 static int
1907 ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1908 struct virtchnl_ether_addr *vc_ether_addr)
1909 {
1910 struct device *dev = ice_pf_to_dev(vf->pf);
1911 u8 *mac_addr = vc_ether_addr->addr;
1912 int status;
1913
1914 if (!ice_can_vf_change_mac(vf) &&
1915 ether_addr_equal(vf->dev_lan_addr.addr, mac_addr))
1916 return 0;
1917
1918 status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1919 if (status == -ENOENT) {
1920 dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr,
1921 vf->vf_id);
1922 return -ENOENT;
1923 } else if (status) {
1924 dev_err(dev, "Failed to delete MAC %pM for VF %d, error %d\n",
1925 mac_addr, vf->vf_id, status);
1926 return -EIO;
1927 }
1928
1929 ice_vfhw_mac_del(vf, vc_ether_addr);
1930
1931 vf->num_mac--;
1932
1933 return 0;
1934 }
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944 static int
1945 ice_vc_handle_mac_addr_msg(struct ice_vf *vf, u8 *msg, bool set)
1946 {
1947 int (*ice_vc_cfg_mac)
1948 (struct ice_vf *vf, struct ice_vsi *vsi,
1949 struct virtchnl_ether_addr *virtchnl_ether_addr);
1950 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1951 struct virtchnl_ether_addr_list *al =
1952 (struct virtchnl_ether_addr_list *)msg;
1953 struct ice_pf *pf = vf->pf;
1954 enum virtchnl_ops vc_op;
1955 struct ice_vsi *vsi;
1956 int i;
1957
1958 if (set) {
1959 vc_op = VIRTCHNL_OP_ADD_ETH_ADDR;
1960 ice_vc_cfg_mac = ice_vc_add_mac_addr;
1961 } else {
1962 vc_op = VIRTCHNL_OP_DEL_ETH_ADDR;
1963 ice_vc_cfg_mac = ice_vc_del_mac_addr;
1964 }
1965
1966 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1967 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
1968 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1969 goto handle_mac_exit;
1970 }
1971
1972
1973
1974
1975
1976 if (set && !ice_is_vf_trusted(vf) &&
1977 (vf->num_mac + al->num_elements) > ICE_MAX_MACADDR_PER_VF) {
1978 dev_err(ice_pf_to_dev(pf), "Can't add more MAC addresses, because VF-%d is not trusted, switch the VF to trusted mode in order to add more functionalities\n",
1979 vf->vf_id);
1980 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1981 goto handle_mac_exit;
1982 }
1983
1984 vsi = ice_get_vf_vsi(vf);
1985 if (!vsi) {
1986 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1987 goto handle_mac_exit;
1988 }
1989
1990 for (i = 0; i < al->num_elements; i++) {
1991 u8 *mac_addr = al->list[i].addr;
1992 int result;
1993
1994 if (is_broadcast_ether_addr(mac_addr) ||
1995 is_zero_ether_addr(mac_addr))
1996 continue;
1997
1998 result = ice_vc_cfg_mac(vf, vsi, &al->list[i]);
1999 if (result == -EEXIST || result == -ENOENT) {
2000 continue;
2001 } else if (result) {
2002 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
2003 goto handle_mac_exit;
2004 }
2005 }
2006
2007 handle_mac_exit:
2008
2009 return ice_vc_send_msg_to_vf(vf, vc_op, v_ret, NULL, 0);
2010 }
2011
2012
2013
2014
2015
2016
2017
2018
2019 static int ice_vc_add_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2020 {
2021 return ice_vc_handle_mac_addr_msg(vf, msg, true);
2022 }
2023
2024
2025
2026
2027
2028
2029
2030
2031 static int ice_vc_del_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2032 {
2033 return ice_vc_handle_mac_addr_msg(vf, msg, false);
2034 }
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046 static int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg)
2047 {
2048 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2049 struct virtchnl_vf_res_request *vfres =
2050 (struct virtchnl_vf_res_request *)msg;
2051 u16 req_queues = vfres->num_queue_pairs;
2052 struct ice_pf *pf = vf->pf;
2053 u16 max_allowed_vf_queues;
2054 u16 tx_rx_queue_left;
2055 struct device *dev;
2056 u16 cur_queues;
2057
2058 dev = ice_pf_to_dev(pf);
2059 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2060 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2061 goto error_param;
2062 }
2063
2064 cur_queues = vf->num_vf_qs;
2065 tx_rx_queue_left = min_t(u16, ice_get_avail_txq_count(pf),
2066 ice_get_avail_rxq_count(pf));
2067 max_allowed_vf_queues = tx_rx_queue_left + cur_queues;
2068 if (!req_queues) {
2069 dev_err(dev, "VF %d tried to request 0 queues. Ignoring.\n",
2070 vf->vf_id);
2071 } else if (req_queues > ICE_MAX_RSS_QS_PER_VF) {
2072 dev_err(dev, "VF %d tried to request more than %d queues.\n",
2073 vf->vf_id, ICE_MAX_RSS_QS_PER_VF);
2074 vfres->num_queue_pairs = ICE_MAX_RSS_QS_PER_VF;
2075 } else if (req_queues > cur_queues &&
2076 req_queues - cur_queues > tx_rx_queue_left) {
2077 dev_warn(dev, "VF %d requested %u more queues, but only %u left.\n",
2078 vf->vf_id, req_queues - cur_queues, tx_rx_queue_left);
2079 vfres->num_queue_pairs = min_t(u16, max_allowed_vf_queues,
2080 ICE_MAX_RSS_QS_PER_VF);
2081 } else {
2082
2083 vf->num_req_qs = req_queues;
2084 ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
2085 dev_info(dev, "VF %d granted request of %u queues.\n",
2086 vf->vf_id, req_queues);
2087 return 0;
2088 }
2089
2090 error_param:
2091
2092 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES,
2093 v_ret, (u8 *)vfres, sizeof(*vfres));
2094 }
2095
2096
2097
2098
2099
2100
2101
2102 static bool ice_vf_vlan_offload_ena(u32 caps)
2103 {
2104 return !!(caps & VIRTCHNL_VF_OFFLOAD_VLAN);
2105 }
2106
2107
2108
2109
2110
2111 static bool ice_is_vlan_promisc_allowed(struct ice_vf *vf)
2112 {
2113 if ((test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
2114 test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) &&
2115 test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, vf->pf->flags))
2116 return true;
2117
2118 return false;
2119 }
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129 static int ice_vf_ena_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2130 {
2131 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2132 int status;
2133
2134 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2135 vlan->vid);
2136 if (status && status != -EEXIST)
2137 return status;
2138
2139 return 0;
2140 }
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150 static int ice_vf_dis_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2151 {
2152 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2153 int status;
2154
2155 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2156 vlan->vid);
2157 if (status && status != -ENOENT)
2158 return status;
2159
2160 return 0;
2161 }
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174 static bool ice_vf_has_max_vlans(struct ice_vf *vf, struct ice_vsi *vsi)
2175 {
2176 if (ice_is_vf_trusted(vf))
2177 return false;
2178
2179 #define ICE_VF_ADDED_VLAN_ZERO_FLTRS 1
2180 return ((ice_vsi_num_non_zero_vlans(vsi) +
2181 ICE_VF_ADDED_VLAN_ZERO_FLTRS) >= ICE_MAX_VLAN_PER_VF);
2182 }
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192 static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v)
2193 {
2194 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2195 struct virtchnl_vlan_filter_list *vfl =
2196 (struct virtchnl_vlan_filter_list *)msg;
2197 struct ice_pf *pf = vf->pf;
2198 bool vlan_promisc = false;
2199 struct ice_vsi *vsi;
2200 struct device *dev;
2201 int status = 0;
2202 int i;
2203
2204 dev = ice_pf_to_dev(pf);
2205 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2206 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2207 goto error_param;
2208 }
2209
2210 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2211 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2212 goto error_param;
2213 }
2214
2215 if (!ice_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
2216 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2217 goto error_param;
2218 }
2219
2220 for (i = 0; i < vfl->num_elements; i++) {
2221 if (vfl->vlan_id[i] >= VLAN_N_VID) {
2222 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2223 dev_err(dev, "invalid VF VLAN id %d\n",
2224 vfl->vlan_id[i]);
2225 goto error_param;
2226 }
2227 }
2228
2229 vsi = ice_get_vf_vsi(vf);
2230 if (!vsi) {
2231 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2232 goto error_param;
2233 }
2234
2235 if (add_v && ice_vf_has_max_vlans(vf, vsi)) {
2236 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2237 vf->vf_id);
2238
2239
2240
2241 goto error_param;
2242 }
2243
2244
2245
2246
2247 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&pf->hw)) {
2248 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2249 goto error_param;
2250 }
2251
2252
2253
2254
2255
2256 vlan_promisc = ice_is_vlan_promisc_allowed(vf) &&
2257 !ice_is_dvm_ena(&pf->hw) &&
2258 !ice_vf_is_port_vlan_ena(vf);
2259
2260 if (add_v) {
2261 for (i = 0; i < vfl->num_elements; i++) {
2262 u16 vid = vfl->vlan_id[i];
2263 struct ice_vlan vlan;
2264
2265 if (ice_vf_has_max_vlans(vf, vsi)) {
2266 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2267 vf->vf_id);
2268
2269
2270
2271
2272 goto error_param;
2273 }
2274
2275
2276
2277
2278
2279 if (!vid)
2280 continue;
2281
2282 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2283 status = vsi->inner_vlan_ops.add_vlan(vsi, &vlan);
2284 if (status) {
2285 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2286 goto error_param;
2287 }
2288
2289
2290 if (!vlan_promisc && vid && !ice_is_dvm_ena(&pf->hw)) {
2291 if (vf->spoofchk) {
2292 status = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
2293 if (status) {
2294 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2295 dev_err(dev, "Enable VLAN anti-spoofing on VLAN ID: %d failed error-%d\n",
2296 vid, status);
2297 goto error_param;
2298 }
2299 }
2300 if (vsi->inner_vlan_ops.ena_rx_filtering(vsi)) {
2301 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2302 dev_err(dev, "Enable VLAN pruning on VLAN ID: %d failed error-%d\n",
2303 vid, status);
2304 goto error_param;
2305 }
2306 } else if (vlan_promisc) {
2307 status = ice_vf_ena_vlan_promisc(vsi, &vlan);
2308 if (status) {
2309 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2310 dev_err(dev, "Enable Unicast/multicast promiscuous mode on VLAN ID:%d failed error-%d\n",
2311 vid, status);
2312 }
2313 }
2314 }
2315 } else {
2316
2317
2318
2319
2320
2321
2322
2323 int num_vf_vlan;
2324
2325 num_vf_vlan = vsi->num_vlan;
2326 for (i = 0; i < vfl->num_elements && i < num_vf_vlan; i++) {
2327 u16 vid = vfl->vlan_id[i];
2328 struct ice_vlan vlan;
2329
2330
2331
2332
2333
2334 if (!vid)
2335 continue;
2336
2337 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2338 status = vsi->inner_vlan_ops.del_vlan(vsi, &vlan);
2339 if (status) {
2340 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2341 goto error_param;
2342 }
2343
2344
2345 if (!ice_vsi_has_non_zero_vlans(vsi)) {
2346 vsi->inner_vlan_ops.dis_tx_filtering(vsi);
2347 vsi->inner_vlan_ops.dis_rx_filtering(vsi);
2348 }
2349
2350 if (vlan_promisc)
2351 ice_vf_dis_vlan_promisc(vsi, &vlan);
2352 }
2353 }
2354
2355 error_param:
2356
2357 if (add_v)
2358 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, v_ret,
2359 NULL, 0);
2360 else
2361 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, v_ret,
2362 NULL, 0);
2363 }
2364
2365
2366
2367
2368
2369
2370
2371
2372 static int ice_vc_add_vlan_msg(struct ice_vf *vf, u8 *msg)
2373 {
2374 return ice_vc_process_vlan_msg(vf, msg, true);
2375 }
2376
2377
2378
2379
2380
2381
2382
2383
2384 static int ice_vc_remove_vlan_msg(struct ice_vf *vf, u8 *msg)
2385 {
2386 return ice_vc_process_vlan_msg(vf, msg, false);
2387 }
2388
2389
2390
2391
2392
2393
2394
2395 static int ice_vc_ena_vlan_stripping(struct ice_vf *vf)
2396 {
2397 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2398 struct ice_vsi *vsi;
2399
2400 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2401 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2402 goto error_param;
2403 }
2404
2405 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2406 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2407 goto error_param;
2408 }
2409
2410 vsi = ice_get_vf_vsi(vf);
2411 if (!vsi) {
2412 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2413 goto error_param;
2414 }
2415
2416 if (vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q))
2417 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2418
2419 error_param:
2420 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
2421 v_ret, NULL, 0);
2422 }
2423
2424
2425
2426
2427
2428
2429
2430 static int ice_vc_dis_vlan_stripping(struct ice_vf *vf)
2431 {
2432 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2433 struct ice_vsi *vsi;
2434
2435 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2436 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2437 goto error_param;
2438 }
2439
2440 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2441 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2442 goto error_param;
2443 }
2444
2445 vsi = ice_get_vf_vsi(vf);
2446 if (!vsi) {
2447 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2448 goto error_param;
2449 }
2450
2451 if (vsi->inner_vlan_ops.dis_stripping(vsi))
2452 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2453
2454 error_param:
2455 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
2456 v_ret, NULL, 0);
2457 }
2458
2459
2460
2461
2462
2463
2464
2465
2466 static int ice_vf_init_vlan_stripping(struct ice_vf *vf)
2467 {
2468 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
2469
2470 if (!vsi)
2471 return -EINVAL;
2472
2473
2474
2475
2476 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&vsi->back->hw))
2477 return 0;
2478
2479 if (ice_vf_vlan_offload_ena(vf->driver_caps))
2480 return vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q);
2481 else
2482 return vsi->inner_vlan_ops.dis_stripping(vsi);
2483 }
2484
2485 static u16 ice_vc_get_max_vlan_fltrs(struct ice_vf *vf)
2486 {
2487 if (vf->trusted)
2488 return VLAN_N_VID;
2489 else
2490 return ICE_MAX_VLAN_PER_VF;
2491 }
2492
2493
2494
2495
2496
2497
2498
2499
2500 static bool ice_vf_outer_vlan_not_allowed(struct ice_vf *vf)
2501 {
2502 if (ice_vf_is_port_vlan_ena(vf))
2503 return true;
2504
2505 return false;
2506 }
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518 static void
2519 ice_vc_set_dvm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2520 {
2521 struct virtchnl_vlan_supported_caps *supported_caps;
2522
2523 if (ice_vf_outer_vlan_not_allowed(vf)) {
2524
2525
2526
2527
2528 supported_caps = &caps->filtering.filtering_support;
2529 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2530
2531 supported_caps = &caps->offloads.stripping_support;
2532 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2533 VIRTCHNL_VLAN_TOGGLE |
2534 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2535 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2536
2537 supported_caps = &caps->offloads.insertion_support;
2538 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2539 VIRTCHNL_VLAN_TOGGLE |
2540 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2541 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2542
2543 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2544 caps->offloads.ethertype_match =
2545 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2546 } else {
2547 supported_caps = &caps->filtering.filtering_support;
2548 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2549 supported_caps->outer = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2550 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2551 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2552 VIRTCHNL_VLAN_ETHERTYPE_AND;
2553 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2554 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2555 VIRTCHNL_VLAN_ETHERTYPE_9100;
2556
2557 supported_caps = &caps->offloads.stripping_support;
2558 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2559 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2560 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2561 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2562 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2563 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2564 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2565 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2566 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2;
2567
2568 supported_caps = &caps->offloads.insertion_support;
2569 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2570 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2571 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2572 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2573 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2574 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2575 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2576 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2577 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2;
2578
2579 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2580
2581 caps->offloads.ethertype_match =
2582 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2583 }
2584
2585 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2586 }
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599 static void
2600 ice_vc_set_svm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2601 {
2602 struct virtchnl_vlan_supported_caps *supported_caps;
2603
2604 if (ice_vf_is_port_vlan_ena(vf)) {
2605 supported_caps = &caps->filtering.filtering_support;
2606 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2607 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2608
2609 supported_caps = &caps->offloads.stripping_support;
2610 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2611 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2612
2613 supported_caps = &caps->offloads.insertion_support;
2614 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2615 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2616
2617 caps->offloads.ethertype_init = VIRTCHNL_VLAN_UNSUPPORTED;
2618 caps->offloads.ethertype_match = VIRTCHNL_VLAN_UNSUPPORTED;
2619 caps->filtering.max_filters = 0;
2620 } else {
2621 supported_caps = &caps->filtering.filtering_support;
2622 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100;
2623 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2624 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2625
2626 supported_caps = &caps->offloads.stripping_support;
2627 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2628 VIRTCHNL_VLAN_TOGGLE |
2629 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2630 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2631
2632 supported_caps = &caps->offloads.insertion_support;
2633 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2634 VIRTCHNL_VLAN_TOGGLE |
2635 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2636 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2637
2638 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2639 caps->offloads.ethertype_match =
2640 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2641 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2642 }
2643 }
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655 static int ice_vc_get_offload_vlan_v2_caps(struct ice_vf *vf)
2656 {
2657 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2658 struct virtchnl_vlan_caps *caps = NULL;
2659 int err, len = 0;
2660
2661 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2662 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2663 goto out;
2664 }
2665
2666 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
2667 if (!caps) {
2668 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2669 goto out;
2670 }
2671 len = sizeof(*caps);
2672
2673 if (ice_is_dvm_ena(&vf->pf->hw))
2674 ice_vc_set_dvm_caps(vf, caps);
2675 else
2676 ice_vc_set_svm_caps(vf, caps);
2677
2678
2679 memcpy(&vf->vlan_v2_caps, caps, sizeof(*caps));
2680
2681 out:
2682 err = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
2683 v_ret, (u8 *)caps, len);
2684 kfree(caps);
2685 return err;
2686 }
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696 static bool ice_vc_validate_vlan_tpid(u16 filtering_caps, u16 tpid)
2697 {
2698 enum virtchnl_vlan_support vlan_ethertype = VIRTCHNL_VLAN_UNSUPPORTED;
2699
2700 switch (tpid) {
2701 case ETH_P_8021Q:
2702 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
2703 break;
2704 case ETH_P_8021AD:
2705 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
2706 break;
2707 case ETH_P_QINQ1:
2708 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_9100;
2709 break;
2710 }
2711
2712 if (!(filtering_caps & vlan_ethertype))
2713 return false;
2714
2715 return true;
2716 }
2717
2718
2719
2720
2721
2722
2723
2724
2725 static bool ice_vc_is_valid_vlan(struct virtchnl_vlan *vc_vlan)
2726 {
2727 if (!vc_vlan->tci || !vc_vlan->tpid)
2728 return false;
2729
2730 return true;
2731 }
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741 static bool
2742 ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps *vfc,
2743 struct virtchnl_vlan_filter_list_v2 *vfl)
2744 {
2745 u16 i;
2746
2747 if (!vfl->num_elements)
2748 return false;
2749
2750 for (i = 0; i < vfl->num_elements; i++) {
2751 struct virtchnl_vlan_supported_caps *filtering_support =
2752 &vfc->filtering_support;
2753 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2754 struct virtchnl_vlan *outer = &vlan_fltr->outer;
2755 struct virtchnl_vlan *inner = &vlan_fltr->inner;
2756
2757 if ((ice_vc_is_valid_vlan(outer) &&
2758 filtering_support->outer == VIRTCHNL_VLAN_UNSUPPORTED) ||
2759 (ice_vc_is_valid_vlan(inner) &&
2760 filtering_support->inner == VIRTCHNL_VLAN_UNSUPPORTED))
2761 return false;
2762
2763 if ((outer->tci_mask &&
2764 !(filtering_support->outer & VIRTCHNL_VLAN_FILTER_MASK)) ||
2765 (inner->tci_mask &&
2766 !(filtering_support->inner & VIRTCHNL_VLAN_FILTER_MASK)))
2767 return false;
2768
2769 if (((outer->tci & VLAN_PRIO_MASK) &&
2770 !(filtering_support->outer & VIRTCHNL_VLAN_PRIO)) ||
2771 ((inner->tci & VLAN_PRIO_MASK) &&
2772 !(filtering_support->inner & VIRTCHNL_VLAN_PRIO)))
2773 return false;
2774
2775 if ((ice_vc_is_valid_vlan(outer) &&
2776 !ice_vc_validate_vlan_tpid(filtering_support->outer,
2777 outer->tpid)) ||
2778 (ice_vc_is_valid_vlan(inner) &&
2779 !ice_vc_validate_vlan_tpid(filtering_support->inner,
2780 inner->tpid)))
2781 return false;
2782 }
2783
2784 return true;
2785 }
2786
2787
2788
2789
2790
2791 static struct ice_vlan ice_vc_to_vlan(struct virtchnl_vlan *vc_vlan)
2792 {
2793 struct ice_vlan vlan = { 0 };
2794
2795 vlan.prio = (vc_vlan->tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
2796 vlan.vid = vc_vlan->tci & VLAN_VID_MASK;
2797 vlan.tpid = vc_vlan->tpid;
2798
2799 return vlan;
2800 }
2801
2802
2803
2804
2805
2806
2807
2808 static int
2809 ice_vc_vlan_action(struct ice_vsi *vsi,
2810 int (*vlan_action)(struct ice_vsi *, struct ice_vlan *),
2811 struct ice_vlan *vlan)
2812 {
2813 int err;
2814
2815 err = vlan_action(vsi, vlan);
2816 if (err)
2817 return err;
2818
2819 return 0;
2820 }
2821
2822
2823
2824
2825
2826
2827
2828 static int
2829 ice_vc_del_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
2830 struct virtchnl_vlan_filter_list_v2 *vfl)
2831 {
2832 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
2833 int err;
2834 u16 i;
2835
2836 for (i = 0; i < vfl->num_elements; i++) {
2837 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2838 struct virtchnl_vlan *vc_vlan;
2839
2840 vc_vlan = &vlan_fltr->outer;
2841 if (ice_vc_is_valid_vlan(vc_vlan)) {
2842 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2843
2844 err = ice_vc_vlan_action(vsi,
2845 vsi->outer_vlan_ops.del_vlan,
2846 &vlan);
2847 if (err)
2848 return err;
2849
2850 if (vlan_promisc)
2851 ice_vf_dis_vlan_promisc(vsi, &vlan);
2852
2853
2854 if (!ice_vsi_has_non_zero_vlans(vsi) && ice_is_dvm_ena(&vsi->back->hw)) {
2855 err = vsi->outer_vlan_ops.dis_tx_filtering(vsi);
2856 if (err)
2857 return err;
2858 }
2859 }
2860
2861 vc_vlan = &vlan_fltr->inner;
2862 if (ice_vc_is_valid_vlan(vc_vlan)) {
2863 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2864
2865 err = ice_vc_vlan_action(vsi,
2866 vsi->inner_vlan_ops.del_vlan,
2867 &vlan);
2868 if (err)
2869 return err;
2870
2871
2872
2873
2874 if (!ice_is_dvm_ena(&vsi->back->hw)) {
2875 if (vlan_promisc)
2876 ice_vf_dis_vlan_promisc(vsi, &vlan);
2877
2878
2879 if (!ice_vsi_has_non_zero_vlans(vsi)) {
2880 err = vsi->inner_vlan_ops.dis_tx_filtering(vsi);
2881 if (err)
2882 return err;
2883 }
2884 }
2885 }
2886 }
2887
2888 return 0;
2889 }
2890
2891
2892
2893
2894
2895
2896 static int ice_vc_remove_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
2897 {
2898 struct virtchnl_vlan_filter_list_v2 *vfl =
2899 (struct virtchnl_vlan_filter_list_v2 *)msg;
2900 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2901 struct ice_vsi *vsi;
2902
2903 if (!ice_vc_validate_vlan_filter_list(&vf->vlan_v2_caps.filtering,
2904 vfl)) {
2905 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2906 goto out;
2907 }
2908
2909 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
2910 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2911 goto out;
2912 }
2913
2914 vsi = ice_get_vf_vsi(vf);
2915 if (!vsi) {
2916 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2917 goto out;
2918 }
2919
2920 if (ice_vc_del_vlans(vf, vsi, vfl))
2921 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2922
2923 out:
2924 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN_V2, v_ret, NULL,
2925 0);
2926 }
2927
2928
2929
2930
2931
2932
2933
2934 static int
2935 ice_vc_add_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
2936 struct virtchnl_vlan_filter_list_v2 *vfl)
2937 {
2938 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
2939 int err;
2940 u16 i;
2941
2942 for (i = 0; i < vfl->num_elements; i++) {
2943 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2944 struct virtchnl_vlan *vc_vlan;
2945
2946 vc_vlan = &vlan_fltr->outer;
2947 if (ice_vc_is_valid_vlan(vc_vlan)) {
2948 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2949
2950 err = ice_vc_vlan_action(vsi,
2951 vsi->outer_vlan_ops.add_vlan,
2952 &vlan);
2953 if (err)
2954 return err;
2955
2956 if (vlan_promisc) {
2957 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
2958 if (err)
2959 return err;
2960 }
2961
2962
2963 if (vf->spoofchk && vlan.vid && ice_is_dvm_ena(&vsi->back->hw)) {
2964 err = vsi->outer_vlan_ops.ena_tx_filtering(vsi);
2965 if (err)
2966 return err;
2967 }
2968 }
2969
2970 vc_vlan = &vlan_fltr->inner;
2971 if (ice_vc_is_valid_vlan(vc_vlan)) {
2972 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2973
2974 err = ice_vc_vlan_action(vsi,
2975 vsi->inner_vlan_ops.add_vlan,
2976 &vlan);
2977 if (err)
2978 return err;
2979
2980
2981
2982
2983 if (!ice_is_dvm_ena(&vsi->back->hw)) {
2984 if (vlan_promisc) {
2985 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
2986 if (err)
2987 return err;
2988 }
2989
2990
2991 if (vf->spoofchk && vlan.vid) {
2992 err = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
2993 if (err)
2994 return err;
2995 }
2996 }
2997 }
2998 }
2999
3000 return 0;
3001 }
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013 static bool
3014 ice_vc_validate_add_vlan_filter_list(struct ice_vsi *vsi,
3015 struct virtchnl_vlan_filtering_caps *vfc,
3016 struct virtchnl_vlan_filter_list_v2 *vfl)
3017 {
3018 u16 num_requested_filters = ice_vsi_num_non_zero_vlans(vsi) +
3019 vfl->num_elements;
3020
3021 if (num_requested_filters > vfc->max_filters)
3022 return false;
3023
3024 return ice_vc_validate_vlan_filter_list(vfc, vfl);
3025 }
3026
3027
3028
3029
3030
3031
3032 static int ice_vc_add_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
3033 {
3034 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3035 struct virtchnl_vlan_filter_list_v2 *vfl =
3036 (struct virtchnl_vlan_filter_list_v2 *)msg;
3037 struct ice_vsi *vsi;
3038
3039 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3040 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3041 goto out;
3042 }
3043
3044 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
3045 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3046 goto out;
3047 }
3048
3049 vsi = ice_get_vf_vsi(vf);
3050 if (!vsi) {
3051 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3052 goto out;
3053 }
3054
3055 if (!ice_vc_validate_add_vlan_filter_list(vsi,
3056 &vf->vlan_v2_caps.filtering,
3057 vfl)) {
3058 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3059 goto out;
3060 }
3061
3062 if (ice_vc_add_vlans(vf, vsi, vfl))
3063 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3064
3065 out:
3066 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN_V2, v_ret, NULL,
3067 0);
3068 }
3069
3070
3071
3072
3073
3074
3075 static bool
3076 ice_vc_valid_vlan_setting(u32 negotiated_settings, u32 ethertype_setting)
3077 {
3078 if (ethertype_setting && !(negotiated_settings & ethertype_setting))
3079 return false;
3080
3081
3082
3083
3084 if (!(negotiated_settings & VIRTCHNL_VLAN_ETHERTYPE_AND) &&
3085 hweight32(ethertype_setting) > 1)
3086 return false;
3087
3088
3089 if (!(negotiated_settings & VIRTCHNL_VLAN_TOGGLE))
3090 return false;
3091
3092 return true;
3093 }
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104 static bool
3105 ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps *caps,
3106 struct virtchnl_vlan_setting *msg)
3107 {
3108 if ((!msg->outer_ethertype_setting &&
3109 !msg->inner_ethertype_setting) ||
3110 (!caps->outer && !caps->inner))
3111 return false;
3112
3113 if (msg->outer_ethertype_setting &&
3114 !ice_vc_valid_vlan_setting(caps->outer,
3115 msg->outer_ethertype_setting))
3116 return false;
3117
3118 if (msg->inner_ethertype_setting &&
3119 !ice_vc_valid_vlan_setting(caps->inner,
3120 msg->inner_ethertype_setting))
3121 return false;
3122
3123 return true;
3124 }
3125
3126
3127
3128
3129
3130
3131 static int ice_vc_get_tpid(u32 ethertype_setting, u16 *tpid)
3132 {
3133 switch (ethertype_setting) {
3134 case VIRTCHNL_VLAN_ETHERTYPE_8100:
3135 *tpid = ETH_P_8021Q;
3136 break;
3137 case VIRTCHNL_VLAN_ETHERTYPE_88A8:
3138 *tpid = ETH_P_8021AD;
3139 break;
3140 case VIRTCHNL_VLAN_ETHERTYPE_9100:
3141 *tpid = ETH_P_QINQ1;
3142 break;
3143 default:
3144 *tpid = 0;
3145 return -EINVAL;
3146 }
3147
3148 return 0;
3149 }
3150
3151
3152
3153
3154
3155
3156
3157 static int
3158 ice_vc_ena_vlan_offload(struct ice_vsi *vsi,
3159 int (*ena_offload)(struct ice_vsi *vsi, u16 tpid),
3160 u32 ethertype_setting)
3161 {
3162 u16 tpid;
3163 int err;
3164
3165 err = ice_vc_get_tpid(ethertype_setting, &tpid);
3166 if (err)
3167 return err;
3168
3169 err = ena_offload(vsi, tpid);
3170 if (err)
3171 return err;
3172
3173 return 0;
3174 }
3175
3176 #define ICE_L2TSEL_QRX_CONTEXT_REG_IDX 3
3177 #define ICE_L2TSEL_BIT_OFFSET 23
3178 enum ice_l2tsel {
3179 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND,
3180 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1,
3181 };
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192 static void ice_vsi_update_l2tsel(struct ice_vsi *vsi, enum ice_l2tsel l2tsel)
3193 {
3194 struct ice_hw *hw = &vsi->back->hw;
3195 u32 l2tsel_bit;
3196 int i;
3197
3198 if (l2tsel == ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND)
3199 l2tsel_bit = 0;
3200 else
3201 l2tsel_bit = BIT(ICE_L2TSEL_BIT_OFFSET);
3202
3203 for (i = 0; i < vsi->alloc_rxq; i++) {
3204 u16 pfq = vsi->rxq_map[i];
3205 u32 qrx_context_offset;
3206 u32 regval;
3207
3208 qrx_context_offset =
3209 QRX_CONTEXT(ICE_L2TSEL_QRX_CONTEXT_REG_IDX, pfq);
3210
3211 regval = rd32(hw, qrx_context_offset);
3212 regval &= ~BIT(ICE_L2TSEL_BIT_OFFSET);
3213 regval |= l2tsel_bit;
3214 wr32(hw, qrx_context_offset, regval);
3215 }
3216 }
3217
3218
3219
3220
3221
3222
3223
3224
3225 static int ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3226 {
3227 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3228 struct virtchnl_vlan_supported_caps *stripping_support;
3229 struct virtchnl_vlan_setting *strip_msg =
3230 (struct virtchnl_vlan_setting *)msg;
3231 u32 ethertype_setting;
3232 struct ice_vsi *vsi;
3233
3234 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3235 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3236 goto out;
3237 }
3238
3239 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3240 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3241 goto out;
3242 }
3243
3244 vsi = ice_get_vf_vsi(vf);
3245 if (!vsi) {
3246 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3247 goto out;
3248 }
3249
3250 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3251 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3252 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3253 goto out;
3254 }
3255
3256 ethertype_setting = strip_msg->outer_ethertype_setting;
3257 if (ethertype_setting) {
3258 if (ice_vc_ena_vlan_offload(vsi,
3259 vsi->outer_vlan_ops.ena_stripping,
3260 ethertype_setting)) {
3261 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3262 goto out;
3263 } else {
3264 enum ice_l2tsel l2tsel =
3265 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND;
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275 ice_vsi_update_l2tsel(vsi, l2tsel);
3276 }
3277 }
3278
3279 ethertype_setting = strip_msg->inner_ethertype_setting;
3280 if (ethertype_setting &&
3281 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_stripping,
3282 ethertype_setting)) {
3283 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3284 goto out;
3285 }
3286
3287 out:
3288 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
3289 v_ret, NULL, 0);
3290 }
3291
3292
3293
3294
3295
3296
3297
3298
3299 static int ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3300 {
3301 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3302 struct virtchnl_vlan_supported_caps *stripping_support;
3303 struct virtchnl_vlan_setting *strip_msg =
3304 (struct virtchnl_vlan_setting *)msg;
3305 u32 ethertype_setting;
3306 struct ice_vsi *vsi;
3307
3308 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3309 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3310 goto out;
3311 }
3312
3313 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3314 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3315 goto out;
3316 }
3317
3318 vsi = ice_get_vf_vsi(vf);
3319 if (!vsi) {
3320 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3321 goto out;
3322 }
3323
3324 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3325 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3326 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3327 goto out;
3328 }
3329
3330 ethertype_setting = strip_msg->outer_ethertype_setting;
3331 if (ethertype_setting) {
3332 if (vsi->outer_vlan_ops.dis_stripping(vsi)) {
3333 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3334 goto out;
3335 } else {
3336 enum ice_l2tsel l2tsel =
3337 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1;
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347 ice_vsi_update_l2tsel(vsi, l2tsel);
3348 }
3349 }
3350
3351 ethertype_setting = strip_msg->inner_ethertype_setting;
3352 if (ethertype_setting && vsi->inner_vlan_ops.dis_stripping(vsi)) {
3353 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3354 goto out;
3355 }
3356
3357 out:
3358 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
3359 v_ret, NULL, 0);
3360 }
3361
3362
3363
3364
3365
3366
3367
3368
3369 static int ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3370 {
3371 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3372 struct virtchnl_vlan_supported_caps *insertion_support;
3373 struct virtchnl_vlan_setting *insertion_msg =
3374 (struct virtchnl_vlan_setting *)msg;
3375 u32 ethertype_setting;
3376 struct ice_vsi *vsi;
3377
3378 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3379 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3380 goto out;
3381 }
3382
3383 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3384 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3385 goto out;
3386 }
3387
3388 vsi = ice_get_vf_vsi(vf);
3389 if (!vsi) {
3390 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3391 goto out;
3392 }
3393
3394 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3395 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3396 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3397 goto out;
3398 }
3399
3400 ethertype_setting = insertion_msg->outer_ethertype_setting;
3401 if (ethertype_setting &&
3402 ice_vc_ena_vlan_offload(vsi, vsi->outer_vlan_ops.ena_insertion,
3403 ethertype_setting)) {
3404 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3405 goto out;
3406 }
3407
3408 ethertype_setting = insertion_msg->inner_ethertype_setting;
3409 if (ethertype_setting &&
3410 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_insertion,
3411 ethertype_setting)) {
3412 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3413 goto out;
3414 }
3415
3416 out:
3417 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
3418 v_ret, NULL, 0);
3419 }
3420
3421
3422
3423
3424
3425
3426
3427
3428 static int ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3429 {
3430 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3431 struct virtchnl_vlan_supported_caps *insertion_support;
3432 struct virtchnl_vlan_setting *insertion_msg =
3433 (struct virtchnl_vlan_setting *)msg;
3434 u32 ethertype_setting;
3435 struct ice_vsi *vsi;
3436
3437 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3438 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3439 goto out;
3440 }
3441
3442 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3443 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3444 goto out;
3445 }
3446
3447 vsi = ice_get_vf_vsi(vf);
3448 if (!vsi) {
3449 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3450 goto out;
3451 }
3452
3453 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3454 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3455 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3456 goto out;
3457 }
3458
3459 ethertype_setting = insertion_msg->outer_ethertype_setting;
3460 if (ethertype_setting && vsi->outer_vlan_ops.dis_insertion(vsi)) {
3461 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3462 goto out;
3463 }
3464
3465 ethertype_setting = insertion_msg->inner_ethertype_setting;
3466 if (ethertype_setting && vsi->inner_vlan_ops.dis_insertion(vsi)) {
3467 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3468 goto out;
3469 }
3470
3471 out:
3472 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
3473 v_ret, NULL, 0);
3474 }
3475
3476 static const struct ice_virtchnl_ops ice_virtchnl_dflt_ops = {
3477 .get_ver_msg = ice_vc_get_ver_msg,
3478 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3479 .reset_vf = ice_vc_reset_vf_msg,
3480 .add_mac_addr_msg = ice_vc_add_mac_addr_msg,
3481 .del_mac_addr_msg = ice_vc_del_mac_addr_msg,
3482 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3483 .ena_qs_msg = ice_vc_ena_qs_msg,
3484 .dis_qs_msg = ice_vc_dis_qs_msg,
3485 .request_qs_msg = ice_vc_request_qs_msg,
3486 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3487 .config_rss_key = ice_vc_config_rss_key,
3488 .config_rss_lut = ice_vc_config_rss_lut,
3489 .get_stats_msg = ice_vc_get_stats_msg,
3490 .cfg_promiscuous_mode_msg = ice_vc_cfg_promiscuous_mode_msg,
3491 .add_vlan_msg = ice_vc_add_vlan_msg,
3492 .remove_vlan_msg = ice_vc_remove_vlan_msg,
3493 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3494 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3495 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3496 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3497 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3498 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3499 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3500 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3501 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3502 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3503 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3504 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3505 };
3506
3507
3508
3509
3510
3511 void ice_virtchnl_set_dflt_ops(struct ice_vf *vf)
3512 {
3513 vf->virtchnl_ops = &ice_virtchnl_dflt_ops;
3514 }
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525 static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
3526 {
3527 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3528 struct virtchnl_ether_addr_list *al =
3529 (struct virtchnl_ether_addr_list *)msg;
3530 struct ice_vsi *vsi;
3531 struct ice_pf *pf;
3532 int i;
3533
3534 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
3535 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
3536 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3537 goto handle_mac_exit;
3538 }
3539
3540 pf = vf->pf;
3541
3542 vsi = ice_get_vf_vsi(vf);
3543 if (!vsi) {
3544 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3545 goto handle_mac_exit;
3546 }
3547
3548 for (i = 0; i < al->num_elements; i++) {
3549 u8 *mac_addr = al->list[i].addr;
3550 int result;
3551
3552 if (!is_unicast_ether_addr(mac_addr) ||
3553 ether_addr_equal(mac_addr, vf->hw_lan_addr.addr))
3554 continue;
3555
3556 if (vf->pf_set_mac) {
3557 dev_err(ice_pf_to_dev(pf), "VF attempting to override administratively set MAC address\n");
3558 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
3559 goto handle_mac_exit;
3560 }
3561
3562 result = ice_eswitch_add_vf_mac_rule(pf, vf, mac_addr);
3563 if (result) {
3564 dev_err(ice_pf_to_dev(pf), "Failed to add MAC %pM for VF %d\n, error %d\n",
3565 mac_addr, vf->vf_id, result);
3566 goto handle_mac_exit;
3567 }
3568
3569 ice_vfhw_mac_add(vf, &al->list[i]);
3570 vf->num_mac++;
3571 break;
3572 }
3573
3574 handle_mac_exit:
3575 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
3576 v_ret, NULL, 0);
3577 }
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587 static int
3588 ice_vc_repr_del_mac(struct ice_vf __always_unused *vf, u8 __always_unused *msg)
3589 {
3590 struct virtchnl_ether_addr_list *al =
3591 (struct virtchnl_ether_addr_list *)msg;
3592
3593 ice_update_legacy_cached_mac(vf, &al->list[0]);
3594
3595 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
3596 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3597 }
3598
3599 static int
3600 ice_vc_repr_cfg_promiscuous_mode(struct ice_vf *vf, u8 __always_unused *msg)
3601 {
3602 dev_dbg(ice_pf_to_dev(vf->pf),
3603 "Can't config promiscuous mode in switchdev mode for VF %d\n",
3604 vf->vf_id);
3605 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
3606 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3607 NULL, 0);
3608 }
3609
3610 static const struct ice_virtchnl_ops ice_virtchnl_repr_ops = {
3611 .get_ver_msg = ice_vc_get_ver_msg,
3612 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3613 .reset_vf = ice_vc_reset_vf_msg,
3614 .add_mac_addr_msg = ice_vc_repr_add_mac,
3615 .del_mac_addr_msg = ice_vc_repr_del_mac,
3616 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3617 .ena_qs_msg = ice_vc_ena_qs_msg,
3618 .dis_qs_msg = ice_vc_dis_qs_msg,
3619 .request_qs_msg = ice_vc_request_qs_msg,
3620 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3621 .config_rss_key = ice_vc_config_rss_key,
3622 .config_rss_lut = ice_vc_config_rss_lut,
3623 .get_stats_msg = ice_vc_get_stats_msg,
3624 .cfg_promiscuous_mode_msg = ice_vc_repr_cfg_promiscuous_mode,
3625 .add_vlan_msg = ice_vc_add_vlan_msg,
3626 .remove_vlan_msg = ice_vc_remove_vlan_msg,
3627 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3628 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3629 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3630 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3631 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3632 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3633 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3634 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3635 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3636 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3637 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3638 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3639 };
3640
3641
3642
3643
3644
3645 void ice_virtchnl_set_repr_ops(struct ice_vf *vf)
3646 {
3647 vf->virtchnl_ops = &ice_virtchnl_repr_ops;
3648 }
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
3659 {
3660 u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
3661 s16 vf_id = le16_to_cpu(event->desc.retval);
3662 const struct ice_virtchnl_ops *ops;
3663 u16 msglen = event->msg_len;
3664 u8 *msg = event->msg_buf;
3665 struct ice_vf *vf = NULL;
3666 struct device *dev;
3667 int err = 0;
3668
3669 dev = ice_pf_to_dev(pf);
3670
3671 vf = ice_get_vf_by_id(pf, vf_id);
3672 if (!vf) {
3673 dev_err(dev, "Unable to locate VF for message from VF ID %d, opcode %d, len %d\n",
3674 vf_id, v_opcode, msglen);
3675 return;
3676 }
3677
3678 mutex_lock(&vf->cfg_lock);
3679
3680
3681 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) {
3682 err = -EPERM;
3683 goto error_handler;
3684 }
3685
3686 ops = vf->virtchnl_ops;
3687
3688
3689 err = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
3690 if (err) {
3691 if (err == VIRTCHNL_STATUS_ERR_PARAM)
3692 err = -EPERM;
3693 else
3694 err = -EINVAL;
3695 }
3696
3697 error_handler:
3698 if (err) {
3699 ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
3700 NULL, 0);
3701 dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n",
3702 vf_id, v_opcode, msglen, err);
3703 goto finish;
3704 }
3705
3706 if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
3707 ice_vc_send_msg_to_vf(vf, v_opcode,
3708 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
3709 0);
3710 goto finish;
3711 }
3712
3713 switch (v_opcode) {
3714 case VIRTCHNL_OP_VERSION:
3715 err = ops->get_ver_msg(vf, msg);
3716 break;
3717 case VIRTCHNL_OP_GET_VF_RESOURCES:
3718 err = ops->get_vf_res_msg(vf, msg);
3719 if (ice_vf_init_vlan_stripping(vf))
3720 dev_dbg(dev, "Failed to initialize VLAN stripping for VF %d\n",
3721 vf->vf_id);
3722 ice_vc_notify_vf_link_state(vf);
3723 break;
3724 case VIRTCHNL_OP_RESET_VF:
3725 ops->reset_vf(vf);
3726 break;
3727 case VIRTCHNL_OP_ADD_ETH_ADDR:
3728 err = ops->add_mac_addr_msg(vf, msg);
3729 break;
3730 case VIRTCHNL_OP_DEL_ETH_ADDR:
3731 err = ops->del_mac_addr_msg(vf, msg);
3732 break;
3733 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
3734 err = ops->cfg_qs_msg(vf, msg);
3735 break;
3736 case VIRTCHNL_OP_ENABLE_QUEUES:
3737 err = ops->ena_qs_msg(vf, msg);
3738 ice_vc_notify_vf_link_state(vf);
3739 break;
3740 case VIRTCHNL_OP_DISABLE_QUEUES:
3741 err = ops->dis_qs_msg(vf, msg);
3742 break;
3743 case VIRTCHNL_OP_REQUEST_QUEUES:
3744 err = ops->request_qs_msg(vf, msg);
3745 break;
3746 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
3747 err = ops->cfg_irq_map_msg(vf, msg);
3748 break;
3749 case VIRTCHNL_OP_CONFIG_RSS_KEY:
3750 err = ops->config_rss_key(vf, msg);
3751 break;
3752 case VIRTCHNL_OP_CONFIG_RSS_LUT:
3753 err = ops->config_rss_lut(vf, msg);
3754 break;
3755 case VIRTCHNL_OP_GET_STATS:
3756 err = ops->get_stats_msg(vf, msg);
3757 break;
3758 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
3759 err = ops->cfg_promiscuous_mode_msg(vf, msg);
3760 break;
3761 case VIRTCHNL_OP_ADD_VLAN:
3762 err = ops->add_vlan_msg(vf, msg);
3763 break;
3764 case VIRTCHNL_OP_DEL_VLAN:
3765 err = ops->remove_vlan_msg(vf, msg);
3766 break;
3767 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
3768 err = ops->ena_vlan_stripping(vf);
3769 break;
3770 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
3771 err = ops->dis_vlan_stripping(vf);
3772 break;
3773 case VIRTCHNL_OP_ADD_FDIR_FILTER:
3774 err = ops->add_fdir_fltr_msg(vf, msg);
3775 break;
3776 case VIRTCHNL_OP_DEL_FDIR_FILTER:
3777 err = ops->del_fdir_fltr_msg(vf, msg);
3778 break;
3779 case VIRTCHNL_OP_ADD_RSS_CFG:
3780 err = ops->handle_rss_cfg_msg(vf, msg, true);
3781 break;
3782 case VIRTCHNL_OP_DEL_RSS_CFG:
3783 err = ops->handle_rss_cfg_msg(vf, msg, false);
3784 break;
3785 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
3786 err = ops->get_offload_vlan_v2_caps(vf);
3787 break;
3788 case VIRTCHNL_OP_ADD_VLAN_V2:
3789 err = ops->add_vlan_v2_msg(vf, msg);
3790 break;
3791 case VIRTCHNL_OP_DEL_VLAN_V2:
3792 err = ops->remove_vlan_v2_msg(vf, msg);
3793 break;
3794 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
3795 err = ops->ena_vlan_stripping_v2_msg(vf, msg);
3796 break;
3797 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
3798 err = ops->dis_vlan_stripping_v2_msg(vf, msg);
3799 break;
3800 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
3801 err = ops->ena_vlan_insertion_v2_msg(vf, msg);
3802 break;
3803 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
3804 err = ops->dis_vlan_insertion_v2_msg(vf, msg);
3805 break;
3806 case VIRTCHNL_OP_UNKNOWN:
3807 default:
3808 dev_err(dev, "Unsupported opcode %d from VF %d\n", v_opcode,
3809 vf_id);
3810 err = ice_vc_send_msg_to_vf(vf, v_opcode,
3811 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3812 NULL, 0);
3813 break;
3814 }
3815 if (err) {
3816
3817
3818
3819 dev_info(dev, "PF failed to honor VF %d, opcode %d, error %d\n",
3820 vf_id, v_opcode, err);
3821 }
3822
3823 finish:
3824 mutex_unlock(&vf->cfg_lock);
3825 ice_put_vf(vf);
3826 }