1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (C) 2022, Intel Corporation. */ 3 4 #include "ice_virtchnl.h" 5 #include "ice_vf_lib_private.h" 6 #include "ice.h" 7 #include "ice_base.h" 8 #include "ice_lib.h" 9 #include "ice_fltr.h" 10 #include "ice_virtchnl_allowlist.h" 11 #include "ice_vf_vsi_vlan_ops.h" 12 #include "ice_vlan.h" 13 #include "ice_flex_pipe.h" 14 #include "ice_dcb_lib.h" 15 16 #define FIELD_SELECTOR(proto_hdr_field) \ 17 BIT((proto_hdr_field) & PROTO_HDR_FIELD_MASK) 18 19 struct ice_vc_hdr_match_type { 20 u32 vc_hdr; /* virtchnl headers (VIRTCHNL_PROTO_HDR_XXX) */ 21 u32 ice_hdr; /* ice headers (ICE_FLOW_SEG_HDR_XXX) */ 22 }; 23 24 static const struct ice_vc_hdr_match_type ice_vc_hdr_list[] = { 25 {VIRTCHNL_PROTO_HDR_NONE, ICE_FLOW_SEG_HDR_NONE}, 26 {VIRTCHNL_PROTO_HDR_ETH, ICE_FLOW_SEG_HDR_ETH}, 27 {VIRTCHNL_PROTO_HDR_S_VLAN, ICE_FLOW_SEG_HDR_VLAN}, 28 {VIRTCHNL_PROTO_HDR_C_VLAN, ICE_FLOW_SEG_HDR_VLAN}, 29 {VIRTCHNL_PROTO_HDR_IPV4, ICE_FLOW_SEG_HDR_IPV4 | 30 ICE_FLOW_SEG_HDR_IPV_OTHER}, 31 {VIRTCHNL_PROTO_HDR_IPV6, ICE_FLOW_SEG_HDR_IPV6 | 32 ICE_FLOW_SEG_HDR_IPV_OTHER}, 33 {VIRTCHNL_PROTO_HDR_TCP, ICE_FLOW_SEG_HDR_TCP}, 34 {VIRTCHNL_PROTO_HDR_UDP, ICE_FLOW_SEG_HDR_UDP}, 35 {VIRTCHNL_PROTO_HDR_SCTP, ICE_FLOW_SEG_HDR_SCTP}, 36 {VIRTCHNL_PROTO_HDR_PPPOE, ICE_FLOW_SEG_HDR_PPPOE}, 37 {VIRTCHNL_PROTO_HDR_GTPU_IP, ICE_FLOW_SEG_HDR_GTPU_IP}, 38 {VIRTCHNL_PROTO_HDR_GTPU_EH, ICE_FLOW_SEG_HDR_GTPU_EH}, 39 {VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN, 40 ICE_FLOW_SEG_HDR_GTPU_DWN}, 41 {VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP, 42 ICE_FLOW_SEG_HDR_GTPU_UP}, 43 {VIRTCHNL_PROTO_HDR_L2TPV3, ICE_FLOW_SEG_HDR_L2TPV3}, 44 {VIRTCHNL_PROTO_HDR_ESP, ICE_FLOW_SEG_HDR_ESP}, 45 {VIRTCHNL_PROTO_HDR_AH, ICE_FLOW_SEG_HDR_AH}, 46 {VIRTCHNL_PROTO_HDR_PFCP, ICE_FLOW_SEG_HDR_PFCP_SESSION}, 47 }; 48 49 struct ice_vc_hash_field_match_type { 50 u32 vc_hdr; /* virtchnl headers 51 * (VIRTCHNL_PROTO_HDR_XXX) 52 */ 53 u32 vc_hash_field; /* virtchnl hash fields selector 54 * FIELD_SELECTOR((VIRTCHNL_PROTO_HDR_ETH_XXX)) 55 */ 56 u64 ice_hash_field; /* ice hash fields 57 * (BIT_ULL(ICE_FLOW_FIELD_IDX_XXX)) 58 */ 59 }; 60 61 static const struct 62 ice_vc_hash_field_match_type ice_vc_hash_field_list[] = { 63 {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC), 64 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_SA)}, 65 {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST), 66 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_DA)}, 67 {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC) | 68 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST), 69 ICE_FLOW_HASH_ETH}, 70 {VIRTCHNL_PROTO_HDR_ETH, 71 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE), 72 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_TYPE)}, 73 {VIRTCHNL_PROTO_HDR_S_VLAN, 74 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_S_VLAN_ID), 75 BIT_ULL(ICE_FLOW_FIELD_IDX_S_VLAN)}, 76 {VIRTCHNL_PROTO_HDR_C_VLAN, 77 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_C_VLAN_ID), 78 BIT_ULL(ICE_FLOW_FIELD_IDX_C_VLAN)}, 79 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC), 80 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)}, 81 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST), 82 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)}, 83 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) | 84 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST), 85 ICE_FLOW_HASH_IPV4}, 86 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) | 87 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT), 88 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | 89 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)}, 90 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) | 91 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT), 92 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) | 93 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)}, 94 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) | 95 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) | 96 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT), 97 ICE_FLOW_HASH_IPV4 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)}, 98 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT), 99 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)}, 100 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC), 101 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)}, 102 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST), 103 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)}, 104 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) | 105 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST), 106 ICE_FLOW_HASH_IPV6}, 107 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) | 108 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT), 109 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | 110 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)}, 111 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) | 112 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT), 113 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) | 114 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)}, 115 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) | 116 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) | 117 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT), 118 ICE_FLOW_HASH_IPV6 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)}, 119 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT), 120 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)}, 121 {VIRTCHNL_PROTO_HDR_TCP, 122 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT), 123 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)}, 124 {VIRTCHNL_PROTO_HDR_TCP, 125 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT), 126 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)}, 127 {VIRTCHNL_PROTO_HDR_TCP, 128 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT) | 129 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT), 130 ICE_FLOW_HASH_TCP_PORT}, 131 {VIRTCHNL_PROTO_HDR_UDP, 132 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT), 133 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)}, 134 {VIRTCHNL_PROTO_HDR_UDP, 135 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT), 136 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)}, 137 {VIRTCHNL_PROTO_HDR_UDP, 138 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT) | 139 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT), 140 ICE_FLOW_HASH_UDP_PORT}, 141 {VIRTCHNL_PROTO_HDR_SCTP, 142 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT), 143 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)}, 144 {VIRTCHNL_PROTO_HDR_SCTP, 145 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT), 146 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)}, 147 {VIRTCHNL_PROTO_HDR_SCTP, 148 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT) | 149 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT), 150 ICE_FLOW_HASH_SCTP_PORT}, 151 {VIRTCHNL_PROTO_HDR_PPPOE, 152 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID), 153 BIT_ULL(ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID)}, 154 {VIRTCHNL_PROTO_HDR_GTPU_IP, 155 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_GTPU_IP_TEID), 156 BIT_ULL(ICE_FLOW_FIELD_IDX_GTPU_IP_TEID)}, 157 {VIRTCHNL_PROTO_HDR_L2TPV3, 158 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID), 159 BIT_ULL(ICE_FLOW_FIELD_IDX_L2TPV3_SESS_ID)}, 160 {VIRTCHNL_PROTO_HDR_ESP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ESP_SPI), 161 BIT_ULL(ICE_FLOW_FIELD_IDX_ESP_SPI)}, 162 {VIRTCHNL_PROTO_HDR_AH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_AH_SPI), 163 BIT_ULL(ICE_FLOW_FIELD_IDX_AH_SPI)}, 164 {VIRTCHNL_PROTO_HDR_PFCP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PFCP_SEID), 165 BIT_ULL(ICE_FLOW_FIELD_IDX_PFCP_SEID)}, 166 }; 167 168 /** 169 * ice_vc_vf_broadcast - Broadcast a message to all VFs on PF 170 * @pf: pointer to the PF structure 171 * @v_opcode: operation code 172 * @v_retval: return value 173 * @msg: pointer to the msg buffer 174 * @msglen: msg length 175 */ 176 static void 177 ice_vc_vf_broadcast(struct ice_pf *pf, enum virtchnl_ops v_opcode, 178 enum virtchnl_status_code v_retval, u8 *msg, u16 msglen) 179 { 180 struct ice_hw *hw = &pf->hw; 181 struct ice_vf *vf; 182 unsigned int bkt; 183 184 mutex_lock(&pf->vfs.table_lock); 185 ice_for_each_vf(pf, bkt, vf) { 186 /* Not all vfs are enabled so skip the ones that are not */ 187 if (!test_bit(ICE_VF_STATE_INIT, vf->vf_states) && 188 !test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) 189 continue; 190 191 /* Ignore return value on purpose - a given VF may fail, but 192 * we need to keep going and send to all of them 193 */ 194 ice_aq_send_msg_to_vf(hw, vf->vf_id, v_opcode, v_retval, msg, 195 msglen, NULL); 196 } 197 mutex_unlock(&pf->vfs.table_lock); 198 } 199 200 /** 201 * ice_set_pfe_link - Set the link speed/status of the virtchnl_pf_event 202 * @vf: pointer to the VF structure 203 * @pfe: pointer to the virtchnl_pf_event to set link speed/status for 204 * @ice_link_speed: link speed specified by ICE_AQ_LINK_SPEED_* 205 * @link_up: whether or not to set the link up/down 206 */ 207 static void 208 ice_set_pfe_link(struct ice_vf *vf, struct virtchnl_pf_event *pfe, 209 int ice_link_speed, bool link_up) 210 { 211 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) { 212 pfe->event_data.link_event_adv.link_status = link_up; 213 /* Speed in Mbps */ 214 pfe->event_data.link_event_adv.link_speed = 215 ice_conv_link_speed_to_virtchnl(true, ice_link_speed); 216 } else { 217 pfe->event_data.link_event.link_status = link_up; 218 /* Legacy method for virtchnl link speeds */ 219 pfe->event_data.link_event.link_speed = 220 (enum virtchnl_link_speed) 221 ice_conv_link_speed_to_virtchnl(false, ice_link_speed); 222 } 223 } 224 225 /** 226 * ice_vc_notify_vf_link_state - Inform a VF of link status 227 * @vf: pointer to the VF structure 228 * 229 * send a link status message to a single VF 230 */ 231 void ice_vc_notify_vf_link_state(struct ice_vf *vf) 232 { 233 struct virtchnl_pf_event pfe = { 0 }; 234 struct ice_hw *hw = &vf->pf->hw; 235 236 pfe.event = VIRTCHNL_EVENT_LINK_CHANGE; 237 pfe.severity = PF_EVENT_SEVERITY_INFO; 238 239 if (ice_is_vf_link_up(vf)) 240 ice_set_pfe_link(vf, &pfe, 241 hw->port_info->phy.link_info.link_speed, true); 242 else 243 ice_set_pfe_link(vf, &pfe, ICE_AQ_LINK_SPEED_UNKNOWN, false); 244 245 ice_aq_send_msg_to_vf(hw, vf->vf_id, VIRTCHNL_OP_EVENT, 246 VIRTCHNL_STATUS_SUCCESS, (u8 *)&pfe, 247 sizeof(pfe), NULL); 248 } 249 250 /** 251 * ice_vc_notify_link_state - Inform all VFs on a PF of link status 252 * @pf: pointer to the PF structure 253 */ 254 void ice_vc_notify_link_state(struct ice_pf *pf) 255 { 256 struct ice_vf *vf; 257 unsigned int bkt; 258 259 mutex_lock(&pf->vfs.table_lock); 260 ice_for_each_vf(pf, bkt, vf) 261 ice_vc_notify_vf_link_state(vf); 262 mutex_unlock(&pf->vfs.table_lock); 263 } 264 265 /** 266 * ice_vc_notify_reset - Send pending reset message to all VFs 267 * @pf: pointer to the PF structure 268 * 269 * indicate a pending reset to all VFs on a given PF 270 */ 271 void ice_vc_notify_reset(struct ice_pf *pf) 272 { 273 struct virtchnl_pf_event pfe; 274 275 if (!ice_has_vfs(pf)) 276 return; 277 278 pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING; 279 pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM; 280 ice_vc_vf_broadcast(pf, VIRTCHNL_OP_EVENT, VIRTCHNL_STATUS_SUCCESS, 281 (u8 *)&pfe, sizeof(struct virtchnl_pf_event)); 282 } 283 284 /** 285 * ice_vc_send_msg_to_vf - Send message to VF 286 * @vf: pointer to the VF info 287 * @v_opcode: virtual channel opcode 288 * @v_retval: virtual channel return value 289 * @msg: pointer to the msg buffer 290 * @msglen: msg length 291 * 292 * send msg to VF 293 */ 294 int 295 ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode, 296 enum virtchnl_status_code v_retval, u8 *msg, u16 msglen) 297 { 298 struct device *dev; 299 struct ice_pf *pf; 300 int aq_ret; 301 302 pf = vf->pf; 303 dev = ice_pf_to_dev(pf); 304 305 aq_ret = ice_aq_send_msg_to_vf(&pf->hw, vf->vf_id, v_opcode, v_retval, 306 msg, msglen, NULL); 307 if (aq_ret && pf->hw.mailboxq.sq_last_status != ICE_AQ_RC_ENOSYS) { 308 dev_info(dev, "Unable to send the message to VF %d ret %d aq_err %s\n", 309 vf->vf_id, aq_ret, 310 ice_aq_str(pf->hw.mailboxq.sq_last_status)); 311 return -EIO; 312 } 313 314 return 0; 315 } 316 317 /** 318 * ice_vc_get_ver_msg 319 * @vf: pointer to the VF info 320 * @msg: pointer to the msg buffer 321 * 322 * called from the VF to request the API version used by the PF 323 */ 324 static int ice_vc_get_ver_msg(struct ice_vf *vf, u8 *msg) 325 { 326 struct virtchnl_version_info info = { 327 VIRTCHNL_VERSION_MAJOR, VIRTCHNL_VERSION_MINOR 328 }; 329 330 vf->vf_ver = *(struct virtchnl_version_info *)msg; 331 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */ 332 if (VF_IS_V10(&vf->vf_ver)) 333 info.minor = VIRTCHNL_VERSION_MINOR_NO_VF_CAPS; 334 335 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION, 336 VIRTCHNL_STATUS_SUCCESS, (u8 *)&info, 337 sizeof(struct virtchnl_version_info)); 338 } 339 340 /** 341 * ice_vc_get_max_frame_size - get max frame size allowed for VF 342 * @vf: VF used to determine max frame size 343 * 344 * Max frame size is determined based on the current port's max frame size and 345 * whether a port VLAN is configured on this VF. The VF is not aware whether 346 * it's in a port VLAN so the PF needs to account for this in max frame size 347 * checks and sending the max frame size to the VF. 348 */ 349 static u16 ice_vc_get_max_frame_size(struct ice_vf *vf) 350 { 351 struct ice_port_info *pi = ice_vf_get_port_info(vf); 352 u16 max_frame_size; 353 354 max_frame_size = pi->phy.link_info.max_frame_size; 355 356 if (ice_vf_is_port_vlan_ena(vf)) 357 max_frame_size -= VLAN_HLEN; 358 359 return max_frame_size; 360 } 361 362 /** 363 * ice_vc_get_vf_res_msg 364 * @vf: pointer to the VF info 365 * @msg: pointer to the msg buffer 366 * 367 * called from the VF to request its resources 368 */ 369 static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg) 370 { 371 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 372 struct virtchnl_vf_resource *vfres = NULL; 373 struct ice_hw *hw = &vf->pf->hw; 374 struct ice_vsi *vsi; 375 int len = 0; 376 int ret; 377 378 if (ice_check_vf_init(vf)) { 379 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 380 goto err; 381 } 382 383 len = sizeof(struct virtchnl_vf_resource); 384 385 vfres = kzalloc(len, GFP_KERNEL); 386 if (!vfres) { 387 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY; 388 len = 0; 389 goto err; 390 } 391 if (VF_IS_V11(&vf->vf_ver)) 392 vf->driver_caps = *(u32 *)msg; 393 else 394 vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 | 395 VIRTCHNL_VF_OFFLOAD_RSS_REG | 396 VIRTCHNL_VF_OFFLOAD_VLAN; 397 398 vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2; 399 vsi = ice_get_vf_vsi(vf); 400 if (!vsi) { 401 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 402 goto err; 403 } 404 405 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN_V2) { 406 /* VLAN offloads based on current device configuration */ 407 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN_V2; 408 } else if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN) { 409 /* allow VF to negotiate VIRTCHNL_VF_OFFLOAD explicitly for 410 * these two conditions, which amounts to guest VLAN filtering 411 * and offloads being based on the inner VLAN or the 412 * inner/single VLAN respectively and don't allow VF to 413 * negotiate VIRTCHNL_VF_OFFLOAD in any other cases 414 */ 415 if (ice_is_dvm_ena(hw) && ice_vf_is_port_vlan_ena(vf)) { 416 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN; 417 } else if (!ice_is_dvm_ena(hw) && 418 !ice_vf_is_port_vlan_ena(vf)) { 419 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN; 420 /* configure backward compatible support for VFs that 421 * only support VIRTCHNL_VF_OFFLOAD_VLAN, the PF is 422 * configured in SVM, and no port VLAN is configured 423 */ 424 ice_vf_vsi_cfg_svm_legacy_vlan_mode(vsi); 425 } else if (ice_is_dvm_ena(hw)) { 426 /* configure software offloaded VLAN support when DVM 427 * is enabled, but no port VLAN is enabled 428 */ 429 ice_vf_vsi_cfg_dvm_legacy_vlan_mode(vsi); 430 } 431 } 432 433 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF) { 434 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF; 435 } else { 436 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_AQ) 437 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_AQ; 438 else 439 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_REG; 440 } 441 442 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_FDIR_PF) 443 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_FDIR_PF; 444 445 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2) 446 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2; 447 448 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP) 449 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP; 450 451 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM) 452 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM; 453 454 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING) 455 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING; 456 457 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) 458 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR; 459 460 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES) 461 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES; 462 463 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) 464 vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_ADV_LINK_SPEED; 465 466 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF) 467 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF; 468 469 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_USO) 470 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_USO; 471 472 vfres->num_vsis = 1; 473 /* Tx and Rx queue are equal for VF */ 474 vfres->num_queue_pairs = vsi->num_txq; 475 vfres->max_vectors = vf->pf->vfs.num_msix_per; 476 vfres->rss_key_size = ICE_VSIQF_HKEY_ARRAY_SIZE; 477 vfres->rss_lut_size = ICE_VSIQF_HLUT_ARRAY_SIZE; 478 vfres->max_mtu = ice_vc_get_max_frame_size(vf); 479 480 vfres->vsi_res[0].vsi_id = vf->lan_vsi_num; 481 vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV; 482 vfres->vsi_res[0].num_queue_pairs = vsi->num_txq; 483 ether_addr_copy(vfres->vsi_res[0].default_mac_addr, 484 vf->hw_lan_addr.addr); 485 486 /* match guest capabilities */ 487 vf->driver_caps = vfres->vf_cap_flags; 488 489 ice_vc_set_caps_allowlist(vf); 490 ice_vc_set_working_allowlist(vf); 491 492 set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states); 493 494 err: 495 /* send the response back to the VF */ 496 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES, v_ret, 497 (u8 *)vfres, len); 498 499 kfree(vfres); 500 return ret; 501 } 502 503 /** 504 * ice_vc_reset_vf_msg 505 * @vf: pointer to the VF info 506 * 507 * called from the VF to reset itself, 508 * unlike other virtchnl messages, PF driver 509 * doesn't send the response back to the VF 510 */ 511 static void ice_vc_reset_vf_msg(struct ice_vf *vf) 512 { 513 if (test_bit(ICE_VF_STATE_INIT, vf->vf_states)) 514 ice_reset_vf(vf, 0); 515 } 516 517 /** 518 * ice_find_vsi_from_id 519 * @pf: the PF structure to search for the VSI 520 * @id: ID of the VSI it is searching for 521 * 522 * searches for the VSI with the given ID 523 */ 524 static struct ice_vsi *ice_find_vsi_from_id(struct ice_pf *pf, u16 id) 525 { 526 int i; 527 528 ice_for_each_vsi(pf, i) 529 if (pf->vsi[i] && pf->vsi[i]->vsi_num == id) 530 return pf->vsi[i]; 531 532 return NULL; 533 } 534 535 /** 536 * ice_vc_isvalid_vsi_id 537 * @vf: pointer to the VF info 538 * @vsi_id: VF relative VSI ID 539 * 540 * check for the valid VSI ID 541 */ 542 bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id) 543 { 544 struct ice_pf *pf = vf->pf; 545 struct ice_vsi *vsi; 546 547 vsi = ice_find_vsi_from_id(pf, vsi_id); 548 549 return (vsi && (vsi->vf == vf)); 550 } 551 552 /** 553 * ice_vc_isvalid_q_id 554 * @vf: pointer to the VF info 555 * @vsi_id: VSI ID 556 * @qid: VSI relative queue ID 557 * 558 * check for the valid queue ID 559 */ 560 static bool ice_vc_isvalid_q_id(struct ice_vf *vf, u16 vsi_id, u8 qid) 561 { 562 struct ice_vsi *vsi = ice_find_vsi_from_id(vf->pf, vsi_id); 563 /* allocated Tx and Rx queues should be always equal for VF VSI */ 564 return (vsi && (qid < vsi->alloc_txq)); 565 } 566 567 /** 568 * ice_vc_isvalid_ring_len 569 * @ring_len: length of ring 570 * 571 * check for the valid ring count, should be multiple of ICE_REQ_DESC_MULTIPLE 572 * or zero 573 */ 574 static bool ice_vc_isvalid_ring_len(u16 ring_len) 575 { 576 return ring_len == 0 || 577 (ring_len >= ICE_MIN_NUM_DESC && 578 ring_len <= ICE_MAX_NUM_DESC && 579 !(ring_len % ICE_REQ_DESC_MULTIPLE)); 580 } 581 582 /** 583 * ice_vc_validate_pattern 584 * @vf: pointer to the VF info 585 * @proto: virtchnl protocol headers 586 * 587 * validate the pattern is supported or not. 588 * 589 * Return: true on success, false on error. 590 */ 591 bool 592 ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto) 593 { 594 bool is_ipv4 = false; 595 bool is_ipv6 = false; 596 bool is_udp = false; 597 u16 ptype = -1; 598 int i = 0; 599 600 while (i < proto->count && 601 proto->proto_hdr[i].type != VIRTCHNL_PROTO_HDR_NONE) { 602 switch (proto->proto_hdr[i].type) { 603 case VIRTCHNL_PROTO_HDR_ETH: 604 ptype = ICE_PTYPE_MAC_PAY; 605 break; 606 case VIRTCHNL_PROTO_HDR_IPV4: 607 ptype = ICE_PTYPE_IPV4_PAY; 608 is_ipv4 = true; 609 break; 610 case VIRTCHNL_PROTO_HDR_IPV6: 611 ptype = ICE_PTYPE_IPV6_PAY; 612 is_ipv6 = true; 613 break; 614 case VIRTCHNL_PROTO_HDR_UDP: 615 if (is_ipv4) 616 ptype = ICE_PTYPE_IPV4_UDP_PAY; 617 else if (is_ipv6) 618 ptype = ICE_PTYPE_IPV6_UDP_PAY; 619 is_udp = true; 620 break; 621 case VIRTCHNL_PROTO_HDR_TCP: 622 if (is_ipv4) 623 ptype = ICE_PTYPE_IPV4_TCP_PAY; 624 else if (is_ipv6) 625 ptype = ICE_PTYPE_IPV6_TCP_PAY; 626 break; 627 case VIRTCHNL_PROTO_HDR_SCTP: 628 if (is_ipv4) 629 ptype = ICE_PTYPE_IPV4_SCTP_PAY; 630 else if (is_ipv6) 631 ptype = ICE_PTYPE_IPV6_SCTP_PAY; 632 break; 633 case VIRTCHNL_PROTO_HDR_GTPU_IP: 634 case VIRTCHNL_PROTO_HDR_GTPU_EH: 635 if (is_ipv4) 636 ptype = ICE_MAC_IPV4_GTPU; 637 else if (is_ipv6) 638 ptype = ICE_MAC_IPV6_GTPU; 639 goto out; 640 case VIRTCHNL_PROTO_HDR_L2TPV3: 641 if (is_ipv4) 642 ptype = ICE_MAC_IPV4_L2TPV3; 643 else if (is_ipv6) 644 ptype = ICE_MAC_IPV6_L2TPV3; 645 goto out; 646 case VIRTCHNL_PROTO_HDR_ESP: 647 if (is_ipv4) 648 ptype = is_udp ? ICE_MAC_IPV4_NAT_T_ESP : 649 ICE_MAC_IPV4_ESP; 650 else if (is_ipv6) 651 ptype = is_udp ? ICE_MAC_IPV6_NAT_T_ESP : 652 ICE_MAC_IPV6_ESP; 653 goto out; 654 case VIRTCHNL_PROTO_HDR_AH: 655 if (is_ipv4) 656 ptype = ICE_MAC_IPV4_AH; 657 else if (is_ipv6) 658 ptype = ICE_MAC_IPV6_AH; 659 goto out; 660 case VIRTCHNL_PROTO_HDR_PFCP: 661 if (is_ipv4) 662 ptype = ICE_MAC_IPV4_PFCP_SESSION; 663 else if (is_ipv6) 664 ptype = ICE_MAC_IPV6_PFCP_SESSION; 665 goto out; 666 default: 667 break; 668 } 669 i++; 670 } 671 672 out: 673 return ice_hw_ptype_ena(&vf->pf->hw, ptype); 674 } 675 676 /** 677 * ice_vc_parse_rss_cfg - parses hash fields and headers from 678 * a specific virtchnl RSS cfg 679 * @hw: pointer to the hardware 680 * @rss_cfg: pointer to the virtchnl RSS cfg 681 * @addl_hdrs: pointer to the protocol header fields (ICE_FLOW_SEG_HDR_*) 682 * to configure 683 * @hash_flds: pointer to the hash bit fields (ICE_FLOW_HASH_*) to configure 684 * 685 * Return true if all the protocol header and hash fields in the RSS cfg could 686 * be parsed, else return false 687 * 688 * This function parses the virtchnl RSS cfg to be the intended 689 * hash fields and the intended header for RSS configuration 690 */ 691 static bool 692 ice_vc_parse_rss_cfg(struct ice_hw *hw, struct virtchnl_rss_cfg *rss_cfg, 693 u32 *addl_hdrs, u64 *hash_flds) 694 { 695 const struct ice_vc_hash_field_match_type *hf_list; 696 const struct ice_vc_hdr_match_type *hdr_list; 697 int i, hf_list_len, hdr_list_len; 698 699 hf_list = ice_vc_hash_field_list; 700 hf_list_len = ARRAY_SIZE(ice_vc_hash_field_list); 701 hdr_list = ice_vc_hdr_list; 702 hdr_list_len = ARRAY_SIZE(ice_vc_hdr_list); 703 704 for (i = 0; i < rss_cfg->proto_hdrs.count; i++) { 705 struct virtchnl_proto_hdr *proto_hdr = 706 &rss_cfg->proto_hdrs.proto_hdr[i]; 707 bool hdr_found = false; 708 int j; 709 710 /* Find matched ice headers according to virtchnl headers. */ 711 for (j = 0; j < hdr_list_len; j++) { 712 struct ice_vc_hdr_match_type hdr_map = hdr_list[j]; 713 714 if (proto_hdr->type == hdr_map.vc_hdr) { 715 *addl_hdrs |= hdr_map.ice_hdr; 716 hdr_found = true; 717 } 718 } 719 720 if (!hdr_found) 721 return false; 722 723 /* Find matched ice hash fields according to 724 * virtchnl hash fields. 725 */ 726 for (j = 0; j < hf_list_len; j++) { 727 struct ice_vc_hash_field_match_type hf_map = hf_list[j]; 728 729 if (proto_hdr->type == hf_map.vc_hdr && 730 proto_hdr->field_selector == hf_map.vc_hash_field) { 731 *hash_flds |= hf_map.ice_hash_field; 732 break; 733 } 734 } 735 } 736 737 return true; 738 } 739 740 /** 741 * ice_vf_adv_rss_offload_ena - determine if capabilities support advanced 742 * RSS offloads 743 * @caps: VF driver negotiated capabilities 744 * 745 * Return true if VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF capability is set, 746 * else return false 747 */ 748 static bool ice_vf_adv_rss_offload_ena(u32 caps) 749 { 750 return !!(caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF); 751 } 752 753 /** 754 * ice_vc_handle_rss_cfg 755 * @vf: pointer to the VF info 756 * @msg: pointer to the message buffer 757 * @add: add a RSS config if true, otherwise delete a RSS config 758 * 759 * This function adds/deletes a RSS config 760 */ 761 static int ice_vc_handle_rss_cfg(struct ice_vf *vf, u8 *msg, bool add) 762 { 763 u32 v_opcode = add ? VIRTCHNL_OP_ADD_RSS_CFG : VIRTCHNL_OP_DEL_RSS_CFG; 764 struct virtchnl_rss_cfg *rss_cfg = (struct virtchnl_rss_cfg *)msg; 765 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 766 struct device *dev = ice_pf_to_dev(vf->pf); 767 struct ice_hw *hw = &vf->pf->hw; 768 struct ice_vsi *vsi; 769 770 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) { 771 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS is not supported by the PF\n", 772 vf->vf_id); 773 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED; 774 goto error_param; 775 } 776 777 if (!ice_vf_adv_rss_offload_ena(vf->driver_caps)) { 778 dev_dbg(dev, "VF %d attempting to configure RSS, but Advanced RSS offload is not supported\n", 779 vf->vf_id); 780 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 781 goto error_param; 782 } 783 784 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 785 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 786 goto error_param; 787 } 788 789 if (rss_cfg->proto_hdrs.count > VIRTCHNL_MAX_NUM_PROTO_HDRS || 790 rss_cfg->rss_algorithm < VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC || 791 rss_cfg->rss_algorithm > VIRTCHNL_RSS_ALG_XOR_SYMMETRIC) { 792 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS configuration is not valid\n", 793 vf->vf_id); 794 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 795 goto error_param; 796 } 797 798 vsi = ice_get_vf_vsi(vf); 799 if (!vsi) { 800 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 801 goto error_param; 802 } 803 804 if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) { 805 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 806 goto error_param; 807 } 808 809 if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_R_ASYMMETRIC) { 810 struct ice_vsi_ctx *ctx; 811 u8 lut_type, hash_type; 812 int status; 813 814 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI; 815 hash_type = add ? ICE_AQ_VSI_Q_OPT_RSS_XOR : 816 ICE_AQ_VSI_Q_OPT_RSS_TPLZ; 817 818 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 819 if (!ctx) { 820 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY; 821 goto error_param; 822 } 823 824 ctx->info.q_opt_rss = ((lut_type << 825 ICE_AQ_VSI_Q_OPT_RSS_LUT_S) & 826 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) | 827 (hash_type & 828 ICE_AQ_VSI_Q_OPT_RSS_HASH_M); 829 830 /* Preserve existing queueing option setting */ 831 ctx->info.q_opt_rss |= (vsi->info.q_opt_rss & 832 ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M); 833 ctx->info.q_opt_tc = vsi->info.q_opt_tc; 834 ctx->info.q_opt_flags = vsi->info.q_opt_rss; 835 836 ctx->info.valid_sections = 837 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID); 838 839 status = ice_update_vsi(hw, vsi->idx, ctx, NULL); 840 if (status) { 841 dev_err(dev, "update VSI for RSS failed, err %d aq_err %s\n", 842 status, ice_aq_str(hw->adminq.sq_last_status)); 843 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 844 } else { 845 vsi->info.q_opt_rss = ctx->info.q_opt_rss; 846 } 847 848 kfree(ctx); 849 } else { 850 u32 addl_hdrs = ICE_FLOW_SEG_HDR_NONE; 851 u64 hash_flds = ICE_HASH_INVALID; 852 853 if (!ice_vc_parse_rss_cfg(hw, rss_cfg, &addl_hdrs, 854 &hash_flds)) { 855 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 856 goto error_param; 857 } 858 859 if (add) { 860 if (ice_add_rss_cfg(hw, vsi->idx, hash_flds, 861 addl_hdrs)) { 862 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 863 dev_err(dev, "ice_add_rss_cfg failed for vsi = %d, v_ret = %d\n", 864 vsi->vsi_num, v_ret); 865 } 866 } else { 867 int status; 868 869 status = ice_rem_rss_cfg(hw, vsi->idx, hash_flds, 870 addl_hdrs); 871 /* We just ignore -ENOENT, because if two configurations 872 * share the same profile remove one of them actually 873 * removes both, since the profile is deleted. 874 */ 875 if (status && status != -ENOENT) { 876 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 877 dev_err(dev, "ice_rem_rss_cfg failed for VF ID:%d, error:%d\n", 878 vf->vf_id, status); 879 } 880 } 881 } 882 883 error_param: 884 return ice_vc_send_msg_to_vf(vf, v_opcode, v_ret, NULL, 0); 885 } 886 887 /** 888 * ice_vc_config_rss_key 889 * @vf: pointer to the VF info 890 * @msg: pointer to the msg buffer 891 * 892 * Configure the VF's RSS key 893 */ 894 static int ice_vc_config_rss_key(struct ice_vf *vf, u8 *msg) 895 { 896 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 897 struct virtchnl_rss_key *vrk = 898 (struct virtchnl_rss_key *)msg; 899 struct ice_vsi *vsi; 900 901 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 902 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 903 goto error_param; 904 } 905 906 if (!ice_vc_isvalid_vsi_id(vf, vrk->vsi_id)) { 907 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 908 goto error_param; 909 } 910 911 if (vrk->key_len != ICE_VSIQF_HKEY_ARRAY_SIZE) { 912 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 913 goto error_param; 914 } 915 916 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) { 917 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 918 goto error_param; 919 } 920 921 vsi = ice_get_vf_vsi(vf); 922 if (!vsi) { 923 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 924 goto error_param; 925 } 926 927 if (ice_set_rss_key(vsi, vrk->key)) 928 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR; 929 error_param: 930 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY, v_ret, 931 NULL, 0); 932 } 933 934 /** 935 * ice_vc_config_rss_lut 936 * @vf: pointer to the VF info 937 * @msg: pointer to the msg buffer 938 * 939 * Configure the VF's RSS LUT 940 */ 941 static int ice_vc_config_rss_lut(struct ice_vf *vf, u8 *msg) 942 { 943 struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg; 944 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 945 struct ice_vsi *vsi; 946 947 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 948 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 949 goto error_param; 950 } 951 952 if (!ice_vc_isvalid_vsi_id(vf, vrl->vsi_id)) { 953 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 954 goto error_param; 955 } 956 957 if (vrl->lut_entries != ICE_VSIQF_HLUT_ARRAY_SIZE) { 958 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 959 goto error_param; 960 } 961 962 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) { 963 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 964 goto error_param; 965 } 966 967 vsi = ice_get_vf_vsi(vf); 968 if (!vsi) { 969 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 970 goto error_param; 971 } 972 973 if (ice_set_rss_lut(vsi, vrl->lut, ICE_VSIQF_HLUT_ARRAY_SIZE)) 974 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR; 975 error_param: 976 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT, v_ret, 977 NULL, 0); 978 } 979 980 /** 981 * ice_vc_cfg_promiscuous_mode_msg 982 * @vf: pointer to the VF info 983 * @msg: pointer to the msg buffer 984 * 985 * called from the VF to configure VF VSIs promiscuous mode 986 */ 987 static int ice_vc_cfg_promiscuous_mode_msg(struct ice_vf *vf, u8 *msg) 988 { 989 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 990 bool rm_promisc, alluni = false, allmulti = false; 991 struct virtchnl_promisc_info *info = 992 (struct virtchnl_promisc_info *)msg; 993 struct ice_vsi_vlan_ops *vlan_ops; 994 int mcast_err = 0, ucast_err = 0; 995 struct ice_pf *pf = vf->pf; 996 struct ice_vsi *vsi; 997 struct device *dev; 998 int ret = 0; 999 1000 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 1001 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1002 goto error_param; 1003 } 1004 1005 if (!ice_vc_isvalid_vsi_id(vf, info->vsi_id)) { 1006 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1007 goto error_param; 1008 } 1009 1010 vsi = ice_get_vf_vsi(vf); 1011 if (!vsi) { 1012 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1013 goto error_param; 1014 } 1015 1016 dev = ice_pf_to_dev(pf); 1017 if (!ice_is_vf_trusted(vf)) { 1018 dev_err(dev, "Unprivileged VF %d is attempting to configure promiscuous mode\n", 1019 vf->vf_id); 1020 /* Leave v_ret alone, lie to the VF on purpose. */ 1021 goto error_param; 1022 } 1023 1024 if (info->flags & FLAG_VF_UNICAST_PROMISC) 1025 alluni = true; 1026 1027 if (info->flags & FLAG_VF_MULTICAST_PROMISC) 1028 allmulti = true; 1029 1030 rm_promisc = !allmulti && !alluni; 1031 1032 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi); 1033 if (rm_promisc) 1034 ret = vlan_ops->ena_rx_filtering(vsi); 1035 else 1036 ret = vlan_ops->dis_rx_filtering(vsi); 1037 if (ret) { 1038 dev_err(dev, "Failed to configure VLAN pruning in promiscuous mode\n"); 1039 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1040 goto error_param; 1041 } 1042 1043 if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) { 1044 bool set_dflt_vsi = alluni || allmulti; 1045 1046 if (set_dflt_vsi && !ice_is_dflt_vsi_in_use(pf->first_sw)) 1047 /* only attempt to set the default forwarding VSI if 1048 * it's not currently set 1049 */ 1050 ret = ice_set_dflt_vsi(pf->first_sw, vsi); 1051 else if (!set_dflt_vsi && 1052 ice_is_vsi_dflt_vsi(pf->first_sw, vsi)) 1053 /* only attempt to free the default forwarding VSI if we 1054 * are the owner 1055 */ 1056 ret = ice_clear_dflt_vsi(pf->first_sw); 1057 1058 if (ret) { 1059 dev_err(dev, "%sable VF %d as the default VSI failed, error %d\n", 1060 set_dflt_vsi ? "en" : "dis", vf->vf_id, ret); 1061 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR; 1062 goto error_param; 1063 } 1064 } else { 1065 u8 mcast_m, ucast_m; 1066 1067 if (ice_vf_is_port_vlan_ena(vf) || 1068 ice_vsi_has_non_zero_vlans(vsi)) { 1069 mcast_m = ICE_MCAST_VLAN_PROMISC_BITS; 1070 ucast_m = ICE_UCAST_VLAN_PROMISC_BITS; 1071 } else { 1072 mcast_m = ICE_MCAST_PROMISC_BITS; 1073 ucast_m = ICE_UCAST_PROMISC_BITS; 1074 } 1075 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 } 1101 1102 if (!ucast_err) { 1103 if (alluni && 1104 !test_and_set_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states)) 1105 dev_info(dev, "VF %u successfully set unicast promiscuous mode\n", 1106 vf->vf_id); 1107 else if (!alluni && 1108 test_and_clear_bit(ICE_VF_STATE_UC_PROMISC, 1109 vf->vf_states)) 1110 dev_info(dev, "VF %u successfully unset unicast promiscuous mode\n", 1111 vf->vf_id); 1112 } 1113 1114 error_param: 1115 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, 1116 v_ret, NULL, 0); 1117 } 1118 1119 /** 1120 * ice_vc_get_stats_msg 1121 * @vf: pointer to the VF info 1122 * @msg: pointer to the msg buffer 1123 * 1124 * called from the VF to get VSI stats 1125 */ 1126 static int ice_vc_get_stats_msg(struct ice_vf *vf, u8 *msg) 1127 { 1128 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 1129 struct virtchnl_queue_select *vqs = 1130 (struct virtchnl_queue_select *)msg; 1131 struct ice_eth_stats stats = { 0 }; 1132 struct ice_vsi *vsi; 1133 1134 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 1135 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1136 goto error_param; 1137 } 1138 1139 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) { 1140 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1141 goto error_param; 1142 } 1143 1144 vsi = ice_get_vf_vsi(vf); 1145 if (!vsi) { 1146 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1147 goto error_param; 1148 } 1149 1150 ice_update_eth_stats(vsi); 1151 1152 stats = vsi->eth_stats; 1153 1154 error_param: 1155 /* send the response to the VF */ 1156 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, v_ret, 1157 (u8 *)&stats, sizeof(stats)); 1158 } 1159 1160 /** 1161 * ice_vc_validate_vqs_bitmaps - validate Rx/Tx queue bitmaps from VIRTCHNL 1162 * @vqs: virtchnl_queue_select structure containing bitmaps to validate 1163 * 1164 * Return true on successful validation, else false 1165 */ 1166 static bool ice_vc_validate_vqs_bitmaps(struct virtchnl_queue_select *vqs) 1167 { 1168 if ((!vqs->rx_queues && !vqs->tx_queues) || 1169 vqs->rx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF) || 1170 vqs->tx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF)) 1171 return false; 1172 1173 return true; 1174 } 1175 1176 /** 1177 * ice_vf_ena_txq_interrupt - enable Tx queue interrupt via QINT_TQCTL 1178 * @vsi: VSI of the VF to configure 1179 * @q_idx: VF queue index used to determine the queue in the PF's space 1180 */ 1181 static void ice_vf_ena_txq_interrupt(struct ice_vsi *vsi, u32 q_idx) 1182 { 1183 struct ice_hw *hw = &vsi->back->hw; 1184 u32 pfq = vsi->txq_map[q_idx]; 1185 u32 reg; 1186 1187 reg = rd32(hw, QINT_TQCTL(pfq)); 1188 1189 /* MSI-X index 0 in the VF's space is always for the OICR, which means 1190 * this is most likely a poll mode VF driver, so don't enable an 1191 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP 1192 */ 1193 if (!(reg & QINT_TQCTL_MSIX_INDX_M)) 1194 return; 1195 1196 wr32(hw, QINT_TQCTL(pfq), reg | QINT_TQCTL_CAUSE_ENA_M); 1197 } 1198 1199 /** 1200 * ice_vf_ena_rxq_interrupt - enable Tx queue interrupt via QINT_RQCTL 1201 * @vsi: VSI of the VF to configure 1202 * @q_idx: VF queue index used to determine the queue in the PF's space 1203 */ 1204 static void ice_vf_ena_rxq_interrupt(struct ice_vsi *vsi, u32 q_idx) 1205 { 1206 struct ice_hw *hw = &vsi->back->hw; 1207 u32 pfq = vsi->rxq_map[q_idx]; 1208 u32 reg; 1209 1210 reg = rd32(hw, QINT_RQCTL(pfq)); 1211 1212 /* MSI-X index 0 in the VF's space is always for the OICR, which means 1213 * this is most likely a poll mode VF driver, so don't enable an 1214 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP 1215 */ 1216 if (!(reg & QINT_RQCTL_MSIX_INDX_M)) 1217 return; 1218 1219 wr32(hw, QINT_RQCTL(pfq), reg | QINT_RQCTL_CAUSE_ENA_M); 1220 } 1221 1222 /** 1223 * ice_vc_ena_qs_msg 1224 * @vf: pointer to the VF info 1225 * @msg: pointer to the msg buffer 1226 * 1227 * called from the VF to enable all or specific queue(s) 1228 */ 1229 static int ice_vc_ena_qs_msg(struct ice_vf *vf, u8 *msg) 1230 { 1231 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 1232 struct virtchnl_queue_select *vqs = 1233 (struct virtchnl_queue_select *)msg; 1234 struct ice_vsi *vsi; 1235 unsigned long q_map; 1236 u16 vf_q_id; 1237 1238 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 1239 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1240 goto error_param; 1241 } 1242 1243 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) { 1244 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1245 goto error_param; 1246 } 1247 1248 if (!ice_vc_validate_vqs_bitmaps(vqs)) { 1249 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1250 goto error_param; 1251 } 1252 1253 vsi = ice_get_vf_vsi(vf); 1254 if (!vsi) { 1255 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1256 goto error_param; 1257 } 1258 1259 /* Enable only Rx rings, Tx rings were enabled by the FW when the 1260 * Tx queue group list was configured and the context bits were 1261 * programmed using ice_vsi_cfg_txqs 1262 */ 1263 q_map = vqs->rx_queues; 1264 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) { 1265 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) { 1266 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1267 goto error_param; 1268 } 1269 1270 /* Skip queue if enabled */ 1271 if (test_bit(vf_q_id, vf->rxq_ena)) 1272 continue; 1273 1274 if (ice_vsi_ctrl_one_rx_ring(vsi, true, vf_q_id, true)) { 1275 dev_err(ice_pf_to_dev(vsi->back), "Failed to enable Rx ring %d on VSI %d\n", 1276 vf_q_id, vsi->vsi_num); 1277 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1278 goto error_param; 1279 } 1280 1281 ice_vf_ena_rxq_interrupt(vsi, vf_q_id); 1282 set_bit(vf_q_id, vf->rxq_ena); 1283 } 1284 1285 q_map = vqs->tx_queues; 1286 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) { 1287 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) { 1288 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1289 goto error_param; 1290 } 1291 1292 /* Skip queue if enabled */ 1293 if (test_bit(vf_q_id, vf->txq_ena)) 1294 continue; 1295 1296 ice_vf_ena_txq_interrupt(vsi, vf_q_id); 1297 set_bit(vf_q_id, vf->txq_ena); 1298 } 1299 1300 /* Set flag to indicate that queues are enabled */ 1301 if (v_ret == VIRTCHNL_STATUS_SUCCESS) 1302 set_bit(ICE_VF_STATE_QS_ENA, vf->vf_states); 1303 1304 error_param: 1305 /* send the response to the VF */ 1306 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES, v_ret, 1307 NULL, 0); 1308 } 1309 1310 /** 1311 * ice_vf_vsi_dis_single_txq - disable a single Tx queue 1312 * @vf: VF to disable queue for 1313 * @vsi: VSI for the VF 1314 * @q_id: VF relative (0-based) queue ID 1315 * 1316 * Attempt to disable the Tx queue passed in. If the Tx queue was successfully 1317 * disabled then clear q_id bit in the enabled queues bitmap and return 1318 * success. Otherwise return error. 1319 */ 1320 static int 1321 ice_vf_vsi_dis_single_txq(struct ice_vf *vf, struct ice_vsi *vsi, u16 q_id) 1322 { 1323 struct ice_txq_meta txq_meta = { 0 }; 1324 struct ice_tx_ring *ring; 1325 int err; 1326 1327 if (!test_bit(q_id, vf->txq_ena)) 1328 dev_dbg(ice_pf_to_dev(vsi->back), "Queue %u on VSI %u is not enabled, but stopping it anyway\n", 1329 q_id, vsi->vsi_num); 1330 1331 ring = vsi->tx_rings[q_id]; 1332 if (!ring) 1333 return -EINVAL; 1334 1335 ice_fill_txq_meta(vsi, ring, &txq_meta); 1336 1337 err = ice_vsi_stop_tx_ring(vsi, ICE_NO_RESET, vf->vf_id, ring, &txq_meta); 1338 if (err) { 1339 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Tx ring %d on VSI %d\n", 1340 q_id, vsi->vsi_num); 1341 return err; 1342 } 1343 1344 /* Clear enabled queues flag */ 1345 clear_bit(q_id, vf->txq_ena); 1346 1347 return 0; 1348 } 1349 1350 /** 1351 * ice_vc_dis_qs_msg 1352 * @vf: pointer to the VF info 1353 * @msg: pointer to the msg buffer 1354 * 1355 * called from the VF to disable all or specific queue(s) 1356 */ 1357 static int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg) 1358 { 1359 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 1360 struct virtchnl_queue_select *vqs = 1361 (struct virtchnl_queue_select *)msg; 1362 struct ice_vsi *vsi; 1363 unsigned long q_map; 1364 u16 vf_q_id; 1365 1366 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) && 1367 !test_bit(ICE_VF_STATE_QS_ENA, vf->vf_states)) { 1368 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1369 goto error_param; 1370 } 1371 1372 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) { 1373 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1374 goto error_param; 1375 } 1376 1377 if (!ice_vc_validate_vqs_bitmaps(vqs)) { 1378 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1379 goto error_param; 1380 } 1381 1382 vsi = ice_get_vf_vsi(vf); 1383 if (!vsi) { 1384 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1385 goto error_param; 1386 } 1387 1388 if (vqs->tx_queues) { 1389 q_map = vqs->tx_queues; 1390 1391 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) { 1392 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) { 1393 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1394 goto error_param; 1395 } 1396 1397 if (ice_vf_vsi_dis_single_txq(vf, vsi, vf_q_id)) { 1398 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1399 goto error_param; 1400 } 1401 } 1402 } 1403 1404 q_map = vqs->rx_queues; 1405 /* speed up Rx queue disable by batching them if possible */ 1406 if (q_map && 1407 bitmap_equal(&q_map, vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF)) { 1408 if (ice_vsi_stop_all_rx_rings(vsi)) { 1409 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop all Rx rings on VSI %d\n", 1410 vsi->vsi_num); 1411 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1412 goto error_param; 1413 } 1414 1415 bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF); 1416 } else if (q_map) { 1417 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) { 1418 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) { 1419 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1420 goto error_param; 1421 } 1422 1423 /* Skip queue if not enabled */ 1424 if (!test_bit(vf_q_id, vf->rxq_ena)) 1425 continue; 1426 1427 if (ice_vsi_ctrl_one_rx_ring(vsi, false, vf_q_id, 1428 true)) { 1429 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Rx ring %d on VSI %d\n", 1430 vf_q_id, vsi->vsi_num); 1431 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1432 goto error_param; 1433 } 1434 1435 /* Clear enabled queues flag */ 1436 clear_bit(vf_q_id, vf->rxq_ena); 1437 } 1438 } 1439 1440 /* Clear enabled queues flag */ 1441 if (v_ret == VIRTCHNL_STATUS_SUCCESS && ice_vf_has_no_qs_ena(vf)) 1442 clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states); 1443 1444 error_param: 1445 /* send the response to the VF */ 1446 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES, v_ret, 1447 NULL, 0); 1448 } 1449 1450 /** 1451 * ice_cfg_interrupt 1452 * @vf: pointer to the VF info 1453 * @vsi: the VSI being configured 1454 * @vector_id: vector ID 1455 * @map: vector map for mapping vectors to queues 1456 * @q_vector: structure for interrupt vector 1457 * configure the IRQ to queue map 1458 */ 1459 static int 1460 ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi, u16 vector_id, 1461 struct virtchnl_vector_map *map, 1462 struct ice_q_vector *q_vector) 1463 { 1464 u16 vsi_q_id, vsi_q_id_idx; 1465 unsigned long qmap; 1466 1467 q_vector->num_ring_rx = 0; 1468 q_vector->num_ring_tx = 0; 1469 1470 qmap = map->rxq_map; 1471 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) { 1472 vsi_q_id = vsi_q_id_idx; 1473 1474 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id)) 1475 return VIRTCHNL_STATUS_ERR_PARAM; 1476 1477 q_vector->num_ring_rx++; 1478 q_vector->rx.itr_idx = map->rxitr_idx; 1479 vsi->rx_rings[vsi_q_id]->q_vector = q_vector; 1480 ice_cfg_rxq_interrupt(vsi, vsi_q_id, vector_id, 1481 q_vector->rx.itr_idx); 1482 } 1483 1484 qmap = map->txq_map; 1485 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) { 1486 vsi_q_id = vsi_q_id_idx; 1487 1488 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id)) 1489 return VIRTCHNL_STATUS_ERR_PARAM; 1490 1491 q_vector->num_ring_tx++; 1492 q_vector->tx.itr_idx = map->txitr_idx; 1493 vsi->tx_rings[vsi_q_id]->q_vector = q_vector; 1494 ice_cfg_txq_interrupt(vsi, vsi_q_id, vector_id, 1495 q_vector->tx.itr_idx); 1496 } 1497 1498 return VIRTCHNL_STATUS_SUCCESS; 1499 } 1500 1501 /** 1502 * ice_vc_cfg_irq_map_msg 1503 * @vf: pointer to the VF info 1504 * @msg: pointer to the msg buffer 1505 * 1506 * called from the VF to configure the IRQ to queue map 1507 */ 1508 static int ice_vc_cfg_irq_map_msg(struct ice_vf *vf, u8 *msg) 1509 { 1510 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 1511 u16 num_q_vectors_mapped, vsi_id, vector_id; 1512 struct virtchnl_irq_map_info *irqmap_info; 1513 struct virtchnl_vector_map *map; 1514 struct ice_pf *pf = vf->pf; 1515 struct ice_vsi *vsi; 1516 int i; 1517 1518 irqmap_info = (struct virtchnl_irq_map_info *)msg; 1519 num_q_vectors_mapped = irqmap_info->num_vectors; 1520 1521 /* Check to make sure number of VF vectors mapped is not greater than 1522 * number of VF vectors originally allocated, and check that 1523 * there is actually at least a single VF queue vector mapped 1524 */ 1525 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) || 1526 pf->vfs.num_msix_per < num_q_vectors_mapped || 1527 !num_q_vectors_mapped) { 1528 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1529 goto error_param; 1530 } 1531 1532 vsi = ice_get_vf_vsi(vf); 1533 if (!vsi) { 1534 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1535 goto error_param; 1536 } 1537 1538 for (i = 0; i < num_q_vectors_mapped; i++) { 1539 struct ice_q_vector *q_vector; 1540 1541 map = &irqmap_info->vecmap[i]; 1542 1543 vector_id = map->vector_id; 1544 vsi_id = map->vsi_id; 1545 /* vector_id is always 0-based for each VF, and can never be 1546 * larger than or equal to the max allowed interrupts per VF 1547 */ 1548 if (!(vector_id < pf->vfs.num_msix_per) || 1549 !ice_vc_isvalid_vsi_id(vf, vsi_id) || 1550 (!vector_id && (map->rxq_map || map->txq_map))) { 1551 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1552 goto error_param; 1553 } 1554 1555 /* No need to map VF miscellaneous or rogue vector */ 1556 if (!vector_id) 1557 continue; 1558 1559 /* Subtract non queue vector from vector_id passed by VF 1560 * to get actual number of VSI queue vector array index 1561 */ 1562 q_vector = vsi->q_vectors[vector_id - ICE_NONQ_VECS_VF]; 1563 if (!q_vector) { 1564 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1565 goto error_param; 1566 } 1567 1568 /* lookout for the invalid queue index */ 1569 v_ret = (enum virtchnl_status_code) 1570 ice_cfg_interrupt(vf, vsi, vector_id, map, q_vector); 1571 if (v_ret) 1572 goto error_param; 1573 } 1574 1575 error_param: 1576 /* send the response to the VF */ 1577 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP, v_ret, 1578 NULL, 0); 1579 } 1580 1581 /** 1582 * ice_vc_cfg_qs_msg 1583 * @vf: pointer to the VF info 1584 * @msg: pointer to the msg buffer 1585 * 1586 * called from the VF to configure the Rx/Tx queues 1587 */ 1588 static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg) 1589 { 1590 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 1591 struct virtchnl_vsi_queue_config_info *qci = 1592 (struct virtchnl_vsi_queue_config_info *)msg; 1593 struct virtchnl_queue_pair_info *qpi; 1594 struct ice_pf *pf = vf->pf; 1595 struct ice_vsi *vsi; 1596 int i, q_idx; 1597 1598 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 1599 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1600 goto error_param; 1601 } 1602 1603 if (!ice_vc_isvalid_vsi_id(vf, qci->vsi_id)) { 1604 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1605 goto error_param; 1606 } 1607 1608 vsi = ice_get_vf_vsi(vf); 1609 if (!vsi) { 1610 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1611 goto error_param; 1612 } 1613 1614 if (qci->num_queue_pairs > ICE_MAX_RSS_QS_PER_VF || 1615 qci->num_queue_pairs > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) { 1616 dev_err(ice_pf_to_dev(pf), "VF-%d requesting more than supported number of queues: %d\n", 1617 vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)); 1618 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1619 goto error_param; 1620 } 1621 1622 for (i = 0; i < qci->num_queue_pairs; i++) { 1623 qpi = &qci->qpair[i]; 1624 if (qpi->txq.vsi_id != qci->vsi_id || 1625 qpi->rxq.vsi_id != qci->vsi_id || 1626 qpi->rxq.queue_id != qpi->txq.queue_id || 1627 qpi->txq.headwb_enabled || 1628 !ice_vc_isvalid_ring_len(qpi->txq.ring_len) || 1629 !ice_vc_isvalid_ring_len(qpi->rxq.ring_len) || 1630 !ice_vc_isvalid_q_id(vf, qci->vsi_id, qpi->txq.queue_id)) { 1631 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1632 goto error_param; 1633 } 1634 1635 q_idx = qpi->rxq.queue_id; 1636 1637 /* make sure selected "q_idx" is in valid range of queues 1638 * for selected "vsi" 1639 */ 1640 if (q_idx >= vsi->alloc_txq || q_idx >= vsi->alloc_rxq) { 1641 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1642 goto error_param; 1643 } 1644 1645 /* copy Tx queue info from VF into VSI */ 1646 if (qpi->txq.ring_len > 0) { 1647 vsi->tx_rings[i]->dma = qpi->txq.dma_ring_addr; 1648 vsi->tx_rings[i]->count = qpi->txq.ring_len; 1649 1650 /* Disable any existing queue first */ 1651 if (ice_vf_vsi_dis_single_txq(vf, vsi, q_idx)) { 1652 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1653 goto error_param; 1654 } 1655 1656 /* Configure a queue with the requested settings */ 1657 if (ice_vsi_cfg_single_txq(vsi, vsi->tx_rings, q_idx)) { 1658 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1659 goto error_param; 1660 } 1661 } 1662 1663 /* copy Rx queue info from VF into VSI */ 1664 if (qpi->rxq.ring_len > 0) { 1665 u16 max_frame_size = ice_vc_get_max_frame_size(vf); 1666 1667 vsi->rx_rings[i]->dma = qpi->rxq.dma_ring_addr; 1668 vsi->rx_rings[i]->count = qpi->rxq.ring_len; 1669 1670 if (qpi->rxq.databuffer_size != 0 && 1671 (qpi->rxq.databuffer_size > ((16 * 1024) - 128) || 1672 qpi->rxq.databuffer_size < 1024)) { 1673 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1674 goto error_param; 1675 } 1676 vsi->rx_buf_len = qpi->rxq.databuffer_size; 1677 vsi->rx_rings[i]->rx_buf_len = vsi->rx_buf_len; 1678 if (qpi->rxq.max_pkt_size > max_frame_size || 1679 qpi->rxq.max_pkt_size < 64) { 1680 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1681 goto error_param; 1682 } 1683 1684 vsi->max_frame = qpi->rxq.max_pkt_size; 1685 /* add space for the port VLAN since the VF driver is 1686 * not expected to account for it in the MTU 1687 * calculation 1688 */ 1689 if (ice_vf_is_port_vlan_ena(vf)) 1690 vsi->max_frame += VLAN_HLEN; 1691 1692 if (ice_vsi_cfg_single_rxq(vsi, q_idx)) { 1693 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1694 goto error_param; 1695 } 1696 } 1697 } 1698 1699 error_param: 1700 /* send the response to the VF */ 1701 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES, v_ret, 1702 NULL, 0); 1703 } 1704 1705 /** 1706 * ice_can_vf_change_mac 1707 * @vf: pointer to the VF info 1708 * 1709 * Return true if the VF is allowed to change its MAC filters, false otherwise 1710 */ 1711 static bool ice_can_vf_change_mac(struct ice_vf *vf) 1712 { 1713 /* If the VF MAC address has been set administratively (via the 1714 * ndo_set_vf_mac command), then deny permission to the VF to 1715 * add/delete unicast MAC addresses, unless the VF is trusted 1716 */ 1717 if (vf->pf_set_mac && !ice_is_vf_trusted(vf)) 1718 return false; 1719 1720 return true; 1721 } 1722 1723 /** 1724 * ice_vc_ether_addr_type - get type of virtchnl_ether_addr 1725 * @vc_ether_addr: used to extract the type 1726 */ 1727 static u8 1728 ice_vc_ether_addr_type(struct virtchnl_ether_addr *vc_ether_addr) 1729 { 1730 return (vc_ether_addr->type & VIRTCHNL_ETHER_ADDR_TYPE_MASK); 1731 } 1732 1733 /** 1734 * ice_is_vc_addr_legacy - check if the MAC address is from an older VF 1735 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type 1736 */ 1737 static bool 1738 ice_is_vc_addr_legacy(struct virtchnl_ether_addr *vc_ether_addr) 1739 { 1740 u8 type = ice_vc_ether_addr_type(vc_ether_addr); 1741 1742 return (type == VIRTCHNL_ETHER_ADDR_LEGACY); 1743 } 1744 1745 /** 1746 * ice_is_vc_addr_primary - check if the MAC address is the VF's primary MAC 1747 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type 1748 * 1749 * This function should only be called when the MAC address in 1750 * virtchnl_ether_addr is a valid unicast MAC 1751 */ 1752 static bool 1753 ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused *vc_ether_addr) 1754 { 1755 u8 type = ice_vc_ether_addr_type(vc_ether_addr); 1756 1757 return (type == VIRTCHNL_ETHER_ADDR_PRIMARY); 1758 } 1759 1760 /** 1761 * ice_vfhw_mac_add - update the VF's cached hardware MAC if allowed 1762 * @vf: VF to update 1763 * @vc_ether_addr: structure from VIRTCHNL with MAC to add 1764 */ 1765 static void 1766 ice_vfhw_mac_add(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr) 1767 { 1768 u8 *mac_addr = vc_ether_addr->addr; 1769 1770 if (!is_valid_ether_addr(mac_addr)) 1771 return; 1772 1773 /* only allow legacy VF drivers to set the device and hardware MAC if it 1774 * is zero and allow new VF drivers to set the hardware MAC if the type 1775 * was correctly specified over VIRTCHNL 1776 */ 1777 if ((ice_is_vc_addr_legacy(vc_ether_addr) && 1778 is_zero_ether_addr(vf->hw_lan_addr.addr)) || 1779 ice_is_vc_addr_primary(vc_ether_addr)) { 1780 ether_addr_copy(vf->dev_lan_addr.addr, mac_addr); 1781 ether_addr_copy(vf->hw_lan_addr.addr, mac_addr); 1782 } 1783 1784 /* hardware and device MACs are already set, but its possible that the 1785 * VF driver sent the VIRTCHNL_OP_ADD_ETH_ADDR message before the 1786 * VIRTCHNL_OP_DEL_ETH_ADDR when trying to update its MAC, so save it 1787 * away for the legacy VF driver case as it will be updated in the 1788 * delete flow for this case 1789 */ 1790 if (ice_is_vc_addr_legacy(vc_ether_addr)) { 1791 ether_addr_copy(vf->legacy_last_added_umac.addr, 1792 mac_addr); 1793 vf->legacy_last_added_umac.time_modified = jiffies; 1794 } 1795 } 1796 1797 /** 1798 * ice_vc_add_mac_addr - attempt to add the MAC address passed in 1799 * @vf: pointer to the VF info 1800 * @vsi: pointer to the VF's VSI 1801 * @vc_ether_addr: VIRTCHNL MAC address structure used to add MAC 1802 */ 1803 static int 1804 ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi, 1805 struct virtchnl_ether_addr *vc_ether_addr) 1806 { 1807 struct device *dev = ice_pf_to_dev(vf->pf); 1808 u8 *mac_addr = vc_ether_addr->addr; 1809 int ret; 1810 1811 /* device MAC already added */ 1812 if (ether_addr_equal(mac_addr, vf->dev_lan_addr.addr)) 1813 return 0; 1814 1815 if (is_unicast_ether_addr(mac_addr) && !ice_can_vf_change_mac(vf)) { 1816 dev_err(dev, "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n"); 1817 return -EPERM; 1818 } 1819 1820 ret = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI); 1821 if (ret == -EEXIST) { 1822 dev_dbg(dev, "MAC %pM already exists for VF %d\n", mac_addr, 1823 vf->vf_id); 1824 /* don't return since we might need to update 1825 * the primary MAC in ice_vfhw_mac_add() below 1826 */ 1827 } else if (ret) { 1828 dev_err(dev, "Failed to add MAC %pM for VF %d\n, error %d\n", 1829 mac_addr, vf->vf_id, ret); 1830 return ret; 1831 } else { 1832 vf->num_mac++; 1833 } 1834 1835 ice_vfhw_mac_add(vf, vc_ether_addr); 1836 1837 return ret; 1838 } 1839 1840 /** 1841 * ice_is_legacy_umac_expired - check if last added legacy unicast MAC expired 1842 * @last_added_umac: structure used to check expiration 1843 */ 1844 static bool ice_is_legacy_umac_expired(struct ice_time_mac *last_added_umac) 1845 { 1846 #define ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME msecs_to_jiffies(3000) 1847 return time_is_before_jiffies(last_added_umac->time_modified + 1848 ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME); 1849 } 1850 1851 /** 1852 * ice_update_legacy_cached_mac - update cached hardware MAC for legacy VF 1853 * @vf: VF to update 1854 * @vc_ether_addr: structure from VIRTCHNL with MAC to check 1855 * 1856 * only update cached hardware MAC for legacy VF drivers on delete 1857 * because we cannot guarantee order/type of MAC from the VF driver 1858 */ 1859 static void 1860 ice_update_legacy_cached_mac(struct ice_vf *vf, 1861 struct virtchnl_ether_addr *vc_ether_addr) 1862 { 1863 if (!ice_is_vc_addr_legacy(vc_ether_addr) || 1864 ice_is_legacy_umac_expired(&vf->legacy_last_added_umac)) 1865 return; 1866 1867 ether_addr_copy(vf->dev_lan_addr.addr, vf->legacy_last_added_umac.addr); 1868 ether_addr_copy(vf->hw_lan_addr.addr, vf->legacy_last_added_umac.addr); 1869 } 1870 1871 /** 1872 * ice_vfhw_mac_del - update the VF's cached hardware MAC if allowed 1873 * @vf: VF to update 1874 * @vc_ether_addr: structure from VIRTCHNL with MAC to delete 1875 */ 1876 static void 1877 ice_vfhw_mac_del(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr) 1878 { 1879 u8 *mac_addr = vc_ether_addr->addr; 1880 1881 if (!is_valid_ether_addr(mac_addr) || 1882 !ether_addr_equal(vf->dev_lan_addr.addr, mac_addr)) 1883 return; 1884 1885 /* allow the device MAC to be repopulated in the add flow and don't 1886 * clear the hardware MAC (i.e. hw_lan_addr.addr) here as that is meant 1887 * to be persistent on VM reboot and across driver unload/load, which 1888 * won't work if we clear the hardware MAC here 1889 */ 1890 eth_zero_addr(vf->dev_lan_addr.addr); 1891 1892 ice_update_legacy_cached_mac(vf, vc_ether_addr); 1893 } 1894 1895 /** 1896 * ice_vc_del_mac_addr - attempt to delete the MAC address passed in 1897 * @vf: pointer to the VF info 1898 * @vsi: pointer to the VF's VSI 1899 * @vc_ether_addr: VIRTCHNL MAC address structure used to delete MAC 1900 */ 1901 static int 1902 ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi, 1903 struct virtchnl_ether_addr *vc_ether_addr) 1904 { 1905 struct device *dev = ice_pf_to_dev(vf->pf); 1906 u8 *mac_addr = vc_ether_addr->addr; 1907 int status; 1908 1909 if (!ice_can_vf_change_mac(vf) && 1910 ether_addr_equal(vf->dev_lan_addr.addr, mac_addr)) 1911 return 0; 1912 1913 status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI); 1914 if (status == -ENOENT) { 1915 dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr, 1916 vf->vf_id); 1917 return -ENOENT; 1918 } else if (status) { 1919 dev_err(dev, "Failed to delete MAC %pM for VF %d, error %d\n", 1920 mac_addr, vf->vf_id, status); 1921 return -EIO; 1922 } 1923 1924 ice_vfhw_mac_del(vf, vc_ether_addr); 1925 1926 vf->num_mac--; 1927 1928 return 0; 1929 } 1930 1931 /** 1932 * ice_vc_handle_mac_addr_msg 1933 * @vf: pointer to the VF info 1934 * @msg: pointer to the msg buffer 1935 * @set: true if MAC filters are being set, false otherwise 1936 * 1937 * add guest MAC address filter 1938 */ 1939 static int 1940 ice_vc_handle_mac_addr_msg(struct ice_vf *vf, u8 *msg, bool set) 1941 { 1942 int (*ice_vc_cfg_mac) 1943 (struct ice_vf *vf, struct ice_vsi *vsi, 1944 struct virtchnl_ether_addr *virtchnl_ether_addr); 1945 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 1946 struct virtchnl_ether_addr_list *al = 1947 (struct virtchnl_ether_addr_list *)msg; 1948 struct ice_pf *pf = vf->pf; 1949 enum virtchnl_ops vc_op; 1950 struct ice_vsi *vsi; 1951 int i; 1952 1953 if (set) { 1954 vc_op = VIRTCHNL_OP_ADD_ETH_ADDR; 1955 ice_vc_cfg_mac = ice_vc_add_mac_addr; 1956 } else { 1957 vc_op = VIRTCHNL_OP_DEL_ETH_ADDR; 1958 ice_vc_cfg_mac = ice_vc_del_mac_addr; 1959 } 1960 1961 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) || 1962 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) { 1963 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1964 goto handle_mac_exit; 1965 } 1966 1967 /* If this VF is not privileged, then we can't add more than a 1968 * limited number of addresses. Check to make sure that the 1969 * additions do not push us over the limit. 1970 */ 1971 if (set && !ice_is_vf_trusted(vf) && 1972 (vf->num_mac + al->num_elements) > ICE_MAX_MACADDR_PER_VF) { 1973 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", 1974 vf->vf_id); 1975 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1976 goto handle_mac_exit; 1977 } 1978 1979 vsi = ice_get_vf_vsi(vf); 1980 if (!vsi) { 1981 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 1982 goto handle_mac_exit; 1983 } 1984 1985 for (i = 0; i < al->num_elements; i++) { 1986 u8 *mac_addr = al->list[i].addr; 1987 int result; 1988 1989 if (is_broadcast_ether_addr(mac_addr) || 1990 is_zero_ether_addr(mac_addr)) 1991 continue; 1992 1993 result = ice_vc_cfg_mac(vf, vsi, &al->list[i]); 1994 if (result == -EEXIST || result == -ENOENT) { 1995 continue; 1996 } else if (result) { 1997 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR; 1998 goto handle_mac_exit; 1999 } 2000 } 2001 2002 handle_mac_exit: 2003 /* send the response to the VF */ 2004 return ice_vc_send_msg_to_vf(vf, vc_op, v_ret, NULL, 0); 2005 } 2006 2007 /** 2008 * ice_vc_add_mac_addr_msg 2009 * @vf: pointer to the VF info 2010 * @msg: pointer to the msg buffer 2011 * 2012 * add guest MAC address filter 2013 */ 2014 static int ice_vc_add_mac_addr_msg(struct ice_vf *vf, u8 *msg) 2015 { 2016 return ice_vc_handle_mac_addr_msg(vf, msg, true); 2017 } 2018 2019 /** 2020 * ice_vc_del_mac_addr_msg 2021 * @vf: pointer to the VF info 2022 * @msg: pointer to the msg buffer 2023 * 2024 * remove guest MAC address filter 2025 */ 2026 static int ice_vc_del_mac_addr_msg(struct ice_vf *vf, u8 *msg) 2027 { 2028 return ice_vc_handle_mac_addr_msg(vf, msg, false); 2029 } 2030 2031 /** 2032 * ice_vc_request_qs_msg 2033 * @vf: pointer to the VF info 2034 * @msg: pointer to the msg buffer 2035 * 2036 * VFs get a default number of queues but can use this message to request a 2037 * different number. If the request is successful, PF will reset the VF and 2038 * return 0. If unsuccessful, PF will send message informing VF of number of 2039 * available queue pairs via virtchnl message response to VF. 2040 */ 2041 static int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg) 2042 { 2043 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 2044 struct virtchnl_vf_res_request *vfres = 2045 (struct virtchnl_vf_res_request *)msg; 2046 u16 req_queues = vfres->num_queue_pairs; 2047 struct ice_pf *pf = vf->pf; 2048 u16 max_allowed_vf_queues; 2049 u16 tx_rx_queue_left; 2050 struct device *dev; 2051 u16 cur_queues; 2052 2053 dev = ice_pf_to_dev(pf); 2054 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 2055 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2056 goto error_param; 2057 } 2058 2059 cur_queues = vf->num_vf_qs; 2060 tx_rx_queue_left = min_t(u16, ice_get_avail_txq_count(pf), 2061 ice_get_avail_rxq_count(pf)); 2062 max_allowed_vf_queues = tx_rx_queue_left + cur_queues; 2063 if (!req_queues) { 2064 dev_err(dev, "VF %d tried to request 0 queues. Ignoring.\n", 2065 vf->vf_id); 2066 } else if (req_queues > ICE_MAX_RSS_QS_PER_VF) { 2067 dev_err(dev, "VF %d tried to request more than %d queues.\n", 2068 vf->vf_id, ICE_MAX_RSS_QS_PER_VF); 2069 vfres->num_queue_pairs = ICE_MAX_RSS_QS_PER_VF; 2070 } else if (req_queues > cur_queues && 2071 req_queues - cur_queues > tx_rx_queue_left) { 2072 dev_warn(dev, "VF %d requested %u more queues, but only %u left.\n", 2073 vf->vf_id, req_queues - cur_queues, tx_rx_queue_left); 2074 vfres->num_queue_pairs = min_t(u16, max_allowed_vf_queues, 2075 ICE_MAX_RSS_QS_PER_VF); 2076 } else { 2077 /* request is successful, then reset VF */ 2078 vf->num_req_qs = req_queues; 2079 ice_reset_vf(vf, ICE_VF_RESET_NOTIFY); 2080 dev_info(dev, "VF %d granted request of %u queues.\n", 2081 vf->vf_id, req_queues); 2082 return 0; 2083 } 2084 2085 error_param: 2086 /* send the response to the VF */ 2087 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES, 2088 v_ret, (u8 *)vfres, sizeof(*vfres)); 2089 } 2090 2091 /** 2092 * ice_vf_vlan_offload_ena - determine if capabilities support VLAN offloads 2093 * @caps: VF driver negotiated capabilities 2094 * 2095 * Return true if VIRTCHNL_VF_OFFLOAD_VLAN capability is set, else return false 2096 */ 2097 static bool ice_vf_vlan_offload_ena(u32 caps) 2098 { 2099 return !!(caps & VIRTCHNL_VF_OFFLOAD_VLAN); 2100 } 2101 2102 /** 2103 * ice_is_vlan_promisc_allowed - check if VLAN promiscuous config is allowed 2104 * @vf: VF used to determine if VLAN promiscuous config is allowed 2105 */ 2106 static bool ice_is_vlan_promisc_allowed(struct ice_vf *vf) 2107 { 2108 if ((test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) || 2109 test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) && 2110 test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, vf->pf->flags)) 2111 return true; 2112 2113 return false; 2114 } 2115 2116 /** 2117 * ice_vf_ena_vlan_promisc - Enable Tx/Rx VLAN promiscuous for the VLAN 2118 * @vsi: VF's VSI used to enable VLAN promiscuous mode 2119 * @vlan: VLAN used to enable VLAN promiscuous 2120 * 2121 * This function should only be called if VLAN promiscuous mode is allowed, 2122 * which can be determined via ice_is_vlan_promisc_allowed(). 2123 */ 2124 static int ice_vf_ena_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan) 2125 { 2126 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX; 2127 int status; 2128 2129 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m, 2130 vlan->vid); 2131 if (status && status != -EEXIST) 2132 return status; 2133 2134 return 0; 2135 } 2136 2137 /** 2138 * ice_vf_dis_vlan_promisc - Disable Tx/Rx VLAN promiscuous for the VLAN 2139 * @vsi: VF's VSI used to disable VLAN promiscuous mode for 2140 * @vlan: VLAN used to disable VLAN promiscuous 2141 * 2142 * This function should only be called if VLAN promiscuous mode is allowed, 2143 * which can be determined via ice_is_vlan_promisc_allowed(). 2144 */ 2145 static int ice_vf_dis_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan) 2146 { 2147 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX; 2148 int status; 2149 2150 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m, 2151 vlan->vid); 2152 if (status && status != -ENOENT) 2153 return status; 2154 2155 return 0; 2156 } 2157 2158 /** 2159 * ice_vf_has_max_vlans - check if VF already has the max allowed VLAN filters 2160 * @vf: VF to check against 2161 * @vsi: VF's VSI 2162 * 2163 * If the VF is trusted then the VF is allowed to add as many VLANs as it 2164 * wants to, so return false. 2165 * 2166 * When the VF is untrusted compare the number of non-zero VLANs + 1 to the max 2167 * allowed VLANs for an untrusted VF. Return the result of this comparison. 2168 */ 2169 static bool ice_vf_has_max_vlans(struct ice_vf *vf, struct ice_vsi *vsi) 2170 { 2171 if (ice_is_vf_trusted(vf)) 2172 return false; 2173 2174 #define ICE_VF_ADDED_VLAN_ZERO_FLTRS 1 2175 return ((ice_vsi_num_non_zero_vlans(vsi) + 2176 ICE_VF_ADDED_VLAN_ZERO_FLTRS) >= ICE_MAX_VLAN_PER_VF); 2177 } 2178 2179 /** 2180 * ice_vc_process_vlan_msg 2181 * @vf: pointer to the VF info 2182 * @msg: pointer to the msg buffer 2183 * @add_v: Add VLAN if true, otherwise delete VLAN 2184 * 2185 * Process virtchnl op to add or remove programmed guest VLAN ID 2186 */ 2187 static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v) 2188 { 2189 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 2190 struct virtchnl_vlan_filter_list *vfl = 2191 (struct virtchnl_vlan_filter_list *)msg; 2192 struct ice_pf *pf = vf->pf; 2193 bool vlan_promisc = false; 2194 struct ice_vsi *vsi; 2195 struct device *dev; 2196 int status = 0; 2197 int i; 2198 2199 dev = ice_pf_to_dev(pf); 2200 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 2201 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2202 goto error_param; 2203 } 2204 2205 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) { 2206 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2207 goto error_param; 2208 } 2209 2210 if (!ice_vc_isvalid_vsi_id(vf, vfl->vsi_id)) { 2211 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2212 goto error_param; 2213 } 2214 2215 for (i = 0; i < vfl->num_elements; i++) { 2216 if (vfl->vlan_id[i] >= VLAN_N_VID) { 2217 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2218 dev_err(dev, "invalid VF VLAN id %d\n", 2219 vfl->vlan_id[i]); 2220 goto error_param; 2221 } 2222 } 2223 2224 vsi = ice_get_vf_vsi(vf); 2225 if (!vsi) { 2226 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2227 goto error_param; 2228 } 2229 2230 if (add_v && ice_vf_has_max_vlans(vf, vsi)) { 2231 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n", 2232 vf->vf_id); 2233 /* There is no need to let VF know about being not trusted, 2234 * so we can just return success message here 2235 */ 2236 goto error_param; 2237 } 2238 2239 /* in DVM a VF can add/delete inner VLAN filters when 2240 * VIRTCHNL_VF_OFFLOAD_VLAN is negotiated, so only reject in SVM 2241 */ 2242 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&pf->hw)) { 2243 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2244 goto error_param; 2245 } 2246 2247 /* in DVM VLAN promiscuous is based on the outer VLAN, which would be 2248 * the port VLAN if VIRTCHNL_VF_OFFLOAD_VLAN was negotiated, so only 2249 * allow vlan_promisc = true in SVM and if no port VLAN is configured 2250 */ 2251 vlan_promisc = ice_is_vlan_promisc_allowed(vf) && 2252 !ice_is_dvm_ena(&pf->hw) && 2253 !ice_vf_is_port_vlan_ena(vf); 2254 2255 if (add_v) { 2256 for (i = 0; i < vfl->num_elements; i++) { 2257 u16 vid = vfl->vlan_id[i]; 2258 struct ice_vlan vlan; 2259 2260 if (ice_vf_has_max_vlans(vf, vsi)) { 2261 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n", 2262 vf->vf_id); 2263 /* There is no need to let VF know about being 2264 * not trusted, so we can just return success 2265 * message here as well. 2266 */ 2267 goto error_param; 2268 } 2269 2270 /* we add VLAN 0 by default for each VF so we can enable 2271 * Tx VLAN anti-spoof without triggering MDD events so 2272 * we don't need to add it again here 2273 */ 2274 if (!vid) 2275 continue; 2276 2277 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0); 2278 status = vsi->inner_vlan_ops.add_vlan(vsi, &vlan); 2279 if (status) { 2280 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2281 goto error_param; 2282 } 2283 2284 /* Enable VLAN filtering on first non-zero VLAN */ 2285 if (!vlan_promisc && vid && !ice_is_dvm_ena(&pf->hw)) { 2286 if (vsi->inner_vlan_ops.ena_rx_filtering(vsi)) { 2287 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2288 dev_err(dev, "Enable VLAN pruning on VLAN ID: %d failed error-%d\n", 2289 vid, status); 2290 goto error_param; 2291 } 2292 } else if (vlan_promisc) { 2293 status = ice_vf_ena_vlan_promisc(vsi, &vlan); 2294 if (status) { 2295 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2296 dev_err(dev, "Enable Unicast/multicast promiscuous mode on VLAN ID:%d failed error-%d\n", 2297 vid, status); 2298 } 2299 } 2300 } 2301 } else { 2302 /* In case of non_trusted VF, number of VLAN elements passed 2303 * to PF for removal might be greater than number of VLANs 2304 * filter programmed for that VF - So, use actual number of 2305 * VLANS added earlier with add VLAN opcode. In order to avoid 2306 * removing VLAN that doesn't exist, which result to sending 2307 * erroneous failed message back to the VF 2308 */ 2309 int num_vf_vlan; 2310 2311 num_vf_vlan = vsi->num_vlan; 2312 for (i = 0; i < vfl->num_elements && i < num_vf_vlan; i++) { 2313 u16 vid = vfl->vlan_id[i]; 2314 struct ice_vlan vlan; 2315 2316 /* we add VLAN 0 by default for each VF so we can enable 2317 * Tx VLAN anti-spoof without triggering MDD events so 2318 * we don't want a VIRTCHNL request to remove it 2319 */ 2320 if (!vid) 2321 continue; 2322 2323 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0); 2324 status = vsi->inner_vlan_ops.del_vlan(vsi, &vlan); 2325 if (status) { 2326 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2327 goto error_param; 2328 } 2329 2330 /* Disable VLAN filtering when only VLAN 0 is left */ 2331 if (!ice_vsi_has_non_zero_vlans(vsi)) 2332 vsi->inner_vlan_ops.dis_rx_filtering(vsi); 2333 2334 if (vlan_promisc) 2335 ice_vf_dis_vlan_promisc(vsi, &vlan); 2336 } 2337 } 2338 2339 error_param: 2340 /* send the response to the VF */ 2341 if (add_v) 2342 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, v_ret, 2343 NULL, 0); 2344 else 2345 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, v_ret, 2346 NULL, 0); 2347 } 2348 2349 /** 2350 * ice_vc_add_vlan_msg 2351 * @vf: pointer to the VF info 2352 * @msg: pointer to the msg buffer 2353 * 2354 * Add and program guest VLAN ID 2355 */ 2356 static int ice_vc_add_vlan_msg(struct ice_vf *vf, u8 *msg) 2357 { 2358 return ice_vc_process_vlan_msg(vf, msg, true); 2359 } 2360 2361 /** 2362 * ice_vc_remove_vlan_msg 2363 * @vf: pointer to the VF info 2364 * @msg: pointer to the msg buffer 2365 * 2366 * remove programmed guest VLAN ID 2367 */ 2368 static int ice_vc_remove_vlan_msg(struct ice_vf *vf, u8 *msg) 2369 { 2370 return ice_vc_process_vlan_msg(vf, msg, false); 2371 } 2372 2373 /** 2374 * ice_vc_ena_vlan_stripping 2375 * @vf: pointer to the VF info 2376 * 2377 * Enable VLAN header stripping for a given VF 2378 */ 2379 static int ice_vc_ena_vlan_stripping(struct ice_vf *vf) 2380 { 2381 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 2382 struct ice_vsi *vsi; 2383 2384 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 2385 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2386 goto error_param; 2387 } 2388 2389 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) { 2390 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2391 goto error_param; 2392 } 2393 2394 vsi = ice_get_vf_vsi(vf); 2395 if (vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q)) 2396 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2397 2398 error_param: 2399 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, 2400 v_ret, NULL, 0); 2401 } 2402 2403 /** 2404 * ice_vc_dis_vlan_stripping 2405 * @vf: pointer to the VF info 2406 * 2407 * Disable VLAN header stripping for a given VF 2408 */ 2409 static int ice_vc_dis_vlan_stripping(struct ice_vf *vf) 2410 { 2411 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 2412 struct ice_vsi *vsi; 2413 2414 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 2415 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2416 goto error_param; 2417 } 2418 2419 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) { 2420 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2421 goto error_param; 2422 } 2423 2424 vsi = ice_get_vf_vsi(vf); 2425 if (!vsi) { 2426 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2427 goto error_param; 2428 } 2429 2430 if (vsi->inner_vlan_ops.dis_stripping(vsi)) 2431 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2432 2433 error_param: 2434 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, 2435 v_ret, NULL, 0); 2436 } 2437 2438 /** 2439 * ice_vf_init_vlan_stripping - enable/disable VLAN stripping on initialization 2440 * @vf: VF to enable/disable VLAN stripping for on initialization 2441 * 2442 * Set the default for VLAN stripping based on whether a port VLAN is configured 2443 * and the current VLAN mode of the device. 2444 */ 2445 static int ice_vf_init_vlan_stripping(struct ice_vf *vf) 2446 { 2447 struct ice_vsi *vsi = ice_get_vf_vsi(vf); 2448 2449 if (!vsi) 2450 return -EINVAL; 2451 2452 /* don't modify stripping if port VLAN is configured in SVM since the 2453 * port VLAN is based on the inner/single VLAN in SVM 2454 */ 2455 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&vsi->back->hw)) 2456 return 0; 2457 2458 if (ice_vf_vlan_offload_ena(vf->driver_caps)) 2459 return vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q); 2460 else 2461 return vsi->inner_vlan_ops.dis_stripping(vsi); 2462 } 2463 2464 static u16 ice_vc_get_max_vlan_fltrs(struct ice_vf *vf) 2465 { 2466 if (vf->trusted) 2467 return VLAN_N_VID; 2468 else 2469 return ICE_MAX_VLAN_PER_VF; 2470 } 2471 2472 /** 2473 * ice_vf_outer_vlan_not_allowed - check if outer VLAN can be used 2474 * @vf: VF that being checked for 2475 * 2476 * When the device is in double VLAN mode, check whether or not the outer VLAN 2477 * is allowed. 2478 */ 2479 static bool ice_vf_outer_vlan_not_allowed(struct ice_vf *vf) 2480 { 2481 if (ice_vf_is_port_vlan_ena(vf)) 2482 return true; 2483 2484 return false; 2485 } 2486 2487 /** 2488 * ice_vc_set_dvm_caps - set VLAN capabilities when the device is in DVM 2489 * @vf: VF that capabilities are being set for 2490 * @caps: VLAN capabilities to populate 2491 * 2492 * Determine VLAN capabilities support based on whether a port VLAN is 2493 * configured. If a port VLAN is configured then the VF should use the inner 2494 * filtering/offload capabilities since the port VLAN is using the outer VLAN 2495 * capabilies. 2496 */ 2497 static void 2498 ice_vc_set_dvm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps) 2499 { 2500 struct virtchnl_vlan_supported_caps *supported_caps; 2501 2502 if (ice_vf_outer_vlan_not_allowed(vf)) { 2503 /* until support for inner VLAN filtering is added when a port 2504 * VLAN is configured, only support software offloaded inner 2505 * VLANs when a port VLAN is confgured in DVM 2506 */ 2507 supported_caps = &caps->filtering.filtering_support; 2508 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED; 2509 2510 supported_caps = &caps->offloads.stripping_support; 2511 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 | 2512 VIRTCHNL_VLAN_TOGGLE | 2513 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1; 2514 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED; 2515 2516 supported_caps = &caps->offloads.insertion_support; 2517 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 | 2518 VIRTCHNL_VLAN_TOGGLE | 2519 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1; 2520 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED; 2521 2522 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100; 2523 caps->offloads.ethertype_match = 2524 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION; 2525 } else { 2526 supported_caps = &caps->filtering.filtering_support; 2527 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED; 2528 supported_caps->outer = VIRTCHNL_VLAN_ETHERTYPE_8100 | 2529 VIRTCHNL_VLAN_ETHERTYPE_88A8 | 2530 VIRTCHNL_VLAN_ETHERTYPE_9100 | 2531 VIRTCHNL_VLAN_ETHERTYPE_AND; 2532 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100 | 2533 VIRTCHNL_VLAN_ETHERTYPE_88A8 | 2534 VIRTCHNL_VLAN_ETHERTYPE_9100; 2535 2536 supported_caps = &caps->offloads.stripping_support; 2537 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE | 2538 VIRTCHNL_VLAN_ETHERTYPE_8100 | 2539 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1; 2540 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE | 2541 VIRTCHNL_VLAN_ETHERTYPE_8100 | 2542 VIRTCHNL_VLAN_ETHERTYPE_88A8 | 2543 VIRTCHNL_VLAN_ETHERTYPE_9100 | 2544 VIRTCHNL_VLAN_ETHERTYPE_XOR | 2545 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2; 2546 2547 supported_caps = &caps->offloads.insertion_support; 2548 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE | 2549 VIRTCHNL_VLAN_ETHERTYPE_8100 | 2550 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1; 2551 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE | 2552 VIRTCHNL_VLAN_ETHERTYPE_8100 | 2553 VIRTCHNL_VLAN_ETHERTYPE_88A8 | 2554 VIRTCHNL_VLAN_ETHERTYPE_9100 | 2555 VIRTCHNL_VLAN_ETHERTYPE_XOR | 2556 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2; 2557 2558 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100; 2559 2560 caps->offloads.ethertype_match = 2561 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION; 2562 } 2563 2564 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf); 2565 } 2566 2567 /** 2568 * ice_vc_set_svm_caps - set VLAN capabilities when the device is in SVM 2569 * @vf: VF that capabilities are being set for 2570 * @caps: VLAN capabilities to populate 2571 * 2572 * Determine VLAN capabilities support based on whether a port VLAN is 2573 * configured. If a port VLAN is configured then the VF does not have any VLAN 2574 * filtering or offload capabilities since the port VLAN is using the inner VLAN 2575 * capabilities in single VLAN mode (SVM). Otherwise allow the VF to use inner 2576 * VLAN fitlering and offload capabilities. 2577 */ 2578 static void 2579 ice_vc_set_svm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps) 2580 { 2581 struct virtchnl_vlan_supported_caps *supported_caps; 2582 2583 if (ice_vf_is_port_vlan_ena(vf)) { 2584 supported_caps = &caps->filtering.filtering_support; 2585 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED; 2586 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED; 2587 2588 supported_caps = &caps->offloads.stripping_support; 2589 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED; 2590 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED; 2591 2592 supported_caps = &caps->offloads.insertion_support; 2593 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED; 2594 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED; 2595 2596 caps->offloads.ethertype_init = VIRTCHNL_VLAN_UNSUPPORTED; 2597 caps->offloads.ethertype_match = VIRTCHNL_VLAN_UNSUPPORTED; 2598 caps->filtering.max_filters = 0; 2599 } else { 2600 supported_caps = &caps->filtering.filtering_support; 2601 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100; 2602 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED; 2603 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100; 2604 2605 supported_caps = &caps->offloads.stripping_support; 2606 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 | 2607 VIRTCHNL_VLAN_TOGGLE | 2608 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1; 2609 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED; 2610 2611 supported_caps = &caps->offloads.insertion_support; 2612 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 | 2613 VIRTCHNL_VLAN_TOGGLE | 2614 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1; 2615 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED; 2616 2617 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100; 2618 caps->offloads.ethertype_match = 2619 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION; 2620 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf); 2621 } 2622 } 2623 2624 /** 2625 * ice_vc_get_offload_vlan_v2_caps - determine VF's VLAN capabilities 2626 * @vf: VF to determine VLAN capabilities for 2627 * 2628 * This will only be called if the VF and PF successfully negotiated 2629 * VIRTCHNL_VF_OFFLOAD_VLAN_V2. 2630 * 2631 * Set VLAN capabilities based on the current VLAN mode and whether a port VLAN 2632 * is configured or not. 2633 */ 2634 static int ice_vc_get_offload_vlan_v2_caps(struct ice_vf *vf) 2635 { 2636 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 2637 struct virtchnl_vlan_caps *caps = NULL; 2638 int err, len = 0; 2639 2640 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 2641 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2642 goto out; 2643 } 2644 2645 caps = kzalloc(sizeof(*caps), GFP_KERNEL); 2646 if (!caps) { 2647 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY; 2648 goto out; 2649 } 2650 len = sizeof(*caps); 2651 2652 if (ice_is_dvm_ena(&vf->pf->hw)) 2653 ice_vc_set_dvm_caps(vf, caps); 2654 else 2655 ice_vc_set_svm_caps(vf, caps); 2656 2657 /* store negotiated caps to prevent invalid VF messages */ 2658 memcpy(&vf->vlan_v2_caps, caps, sizeof(*caps)); 2659 2660 out: 2661 err = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS, 2662 v_ret, (u8 *)caps, len); 2663 kfree(caps); 2664 return err; 2665 } 2666 2667 /** 2668 * ice_vc_validate_vlan_tpid - validate VLAN TPID 2669 * @filtering_caps: negotiated/supported VLAN filtering capabilities 2670 * @tpid: VLAN TPID used for validation 2671 * 2672 * Convert the VLAN TPID to a VIRTCHNL_VLAN_ETHERTYPE_* and then compare against 2673 * the negotiated/supported filtering caps to see if the VLAN TPID is valid. 2674 */ 2675 static bool ice_vc_validate_vlan_tpid(u16 filtering_caps, u16 tpid) 2676 { 2677 enum virtchnl_vlan_support vlan_ethertype = VIRTCHNL_VLAN_UNSUPPORTED; 2678 2679 switch (tpid) { 2680 case ETH_P_8021Q: 2681 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100; 2682 break; 2683 case ETH_P_8021AD: 2684 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8; 2685 break; 2686 case ETH_P_QINQ1: 2687 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_9100; 2688 break; 2689 } 2690 2691 if (!(filtering_caps & vlan_ethertype)) 2692 return false; 2693 2694 return true; 2695 } 2696 2697 /** 2698 * ice_vc_is_valid_vlan - validate the virtchnl_vlan 2699 * @vc_vlan: virtchnl_vlan to validate 2700 * 2701 * If the VLAN TCI and VLAN TPID are 0, then this filter is invalid, so return 2702 * false. Otherwise return true. 2703 */ 2704 static bool ice_vc_is_valid_vlan(struct virtchnl_vlan *vc_vlan) 2705 { 2706 if (!vc_vlan->tci || !vc_vlan->tpid) 2707 return false; 2708 2709 return true; 2710 } 2711 2712 /** 2713 * ice_vc_validate_vlan_filter_list - validate the filter list from the VF 2714 * @vfc: negotiated/supported VLAN filtering capabilities 2715 * @vfl: VLAN filter list from VF to validate 2716 * 2717 * Validate all of the filters in the VLAN filter list from the VF. If any of 2718 * the checks fail then return false. Otherwise return true. 2719 */ 2720 static bool 2721 ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps *vfc, 2722 struct virtchnl_vlan_filter_list_v2 *vfl) 2723 { 2724 u16 i; 2725 2726 if (!vfl->num_elements) 2727 return false; 2728 2729 for (i = 0; i < vfl->num_elements; i++) { 2730 struct virtchnl_vlan_supported_caps *filtering_support = 2731 &vfc->filtering_support; 2732 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i]; 2733 struct virtchnl_vlan *outer = &vlan_fltr->outer; 2734 struct virtchnl_vlan *inner = &vlan_fltr->inner; 2735 2736 if ((ice_vc_is_valid_vlan(outer) && 2737 filtering_support->outer == VIRTCHNL_VLAN_UNSUPPORTED) || 2738 (ice_vc_is_valid_vlan(inner) && 2739 filtering_support->inner == VIRTCHNL_VLAN_UNSUPPORTED)) 2740 return false; 2741 2742 if ((outer->tci_mask && 2743 !(filtering_support->outer & VIRTCHNL_VLAN_FILTER_MASK)) || 2744 (inner->tci_mask && 2745 !(filtering_support->inner & VIRTCHNL_VLAN_FILTER_MASK))) 2746 return false; 2747 2748 if (((outer->tci & VLAN_PRIO_MASK) && 2749 !(filtering_support->outer & VIRTCHNL_VLAN_PRIO)) || 2750 ((inner->tci & VLAN_PRIO_MASK) && 2751 !(filtering_support->inner & VIRTCHNL_VLAN_PRIO))) 2752 return false; 2753 2754 if ((ice_vc_is_valid_vlan(outer) && 2755 !ice_vc_validate_vlan_tpid(filtering_support->outer, 2756 outer->tpid)) || 2757 (ice_vc_is_valid_vlan(inner) && 2758 !ice_vc_validate_vlan_tpid(filtering_support->inner, 2759 inner->tpid))) 2760 return false; 2761 } 2762 2763 return true; 2764 } 2765 2766 /** 2767 * ice_vc_to_vlan - transform from struct virtchnl_vlan to struct ice_vlan 2768 * @vc_vlan: struct virtchnl_vlan to transform 2769 */ 2770 static struct ice_vlan ice_vc_to_vlan(struct virtchnl_vlan *vc_vlan) 2771 { 2772 struct ice_vlan vlan = { 0 }; 2773 2774 vlan.prio = (vc_vlan->tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; 2775 vlan.vid = vc_vlan->tci & VLAN_VID_MASK; 2776 vlan.tpid = vc_vlan->tpid; 2777 2778 return vlan; 2779 } 2780 2781 /** 2782 * ice_vc_vlan_action - action to perform on the virthcnl_vlan 2783 * @vsi: VF's VSI used to perform the action 2784 * @vlan_action: function to perform the action with (i.e. add/del) 2785 * @vlan: VLAN filter to perform the action with 2786 */ 2787 static int 2788 ice_vc_vlan_action(struct ice_vsi *vsi, 2789 int (*vlan_action)(struct ice_vsi *, struct ice_vlan *), 2790 struct ice_vlan *vlan) 2791 { 2792 int err; 2793 2794 err = vlan_action(vsi, vlan); 2795 if (err) 2796 return err; 2797 2798 return 0; 2799 } 2800 2801 /** 2802 * ice_vc_del_vlans - delete VLAN(s) from the virtchnl filter list 2803 * @vf: VF used to delete the VLAN(s) 2804 * @vsi: VF's VSI used to delete the VLAN(s) 2805 * @vfl: virthchnl filter list used to delete the filters 2806 */ 2807 static int 2808 ice_vc_del_vlans(struct ice_vf *vf, struct ice_vsi *vsi, 2809 struct virtchnl_vlan_filter_list_v2 *vfl) 2810 { 2811 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf); 2812 int err; 2813 u16 i; 2814 2815 for (i = 0; i < vfl->num_elements; i++) { 2816 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i]; 2817 struct virtchnl_vlan *vc_vlan; 2818 2819 vc_vlan = &vlan_fltr->outer; 2820 if (ice_vc_is_valid_vlan(vc_vlan)) { 2821 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan); 2822 2823 err = ice_vc_vlan_action(vsi, 2824 vsi->outer_vlan_ops.del_vlan, 2825 &vlan); 2826 if (err) 2827 return err; 2828 2829 if (vlan_promisc) 2830 ice_vf_dis_vlan_promisc(vsi, &vlan); 2831 } 2832 2833 vc_vlan = &vlan_fltr->inner; 2834 if (ice_vc_is_valid_vlan(vc_vlan)) { 2835 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan); 2836 2837 err = ice_vc_vlan_action(vsi, 2838 vsi->inner_vlan_ops.del_vlan, 2839 &vlan); 2840 if (err) 2841 return err; 2842 2843 /* no support for VLAN promiscuous on inner VLAN unless 2844 * we are in Single VLAN Mode (SVM) 2845 */ 2846 if (!ice_is_dvm_ena(&vsi->back->hw) && vlan_promisc) 2847 ice_vf_dis_vlan_promisc(vsi, &vlan); 2848 } 2849 } 2850 2851 return 0; 2852 } 2853 2854 /** 2855 * ice_vc_remove_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_DEL_VLAN_V2 2856 * @vf: VF the message was received from 2857 * @msg: message received from the VF 2858 */ 2859 static int ice_vc_remove_vlan_v2_msg(struct ice_vf *vf, u8 *msg) 2860 { 2861 struct virtchnl_vlan_filter_list_v2 *vfl = 2862 (struct virtchnl_vlan_filter_list_v2 *)msg; 2863 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 2864 struct ice_vsi *vsi; 2865 2866 if (!ice_vc_validate_vlan_filter_list(&vf->vlan_v2_caps.filtering, 2867 vfl)) { 2868 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2869 goto out; 2870 } 2871 2872 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) { 2873 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2874 goto out; 2875 } 2876 2877 vsi = ice_get_vf_vsi(vf); 2878 if (!vsi) { 2879 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2880 goto out; 2881 } 2882 2883 if (ice_vc_del_vlans(vf, vsi, vfl)) 2884 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2885 2886 out: 2887 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN_V2, v_ret, NULL, 2888 0); 2889 } 2890 2891 /** 2892 * ice_vc_add_vlans - add VLAN(s) from the virtchnl filter list 2893 * @vf: VF used to add the VLAN(s) 2894 * @vsi: VF's VSI used to add the VLAN(s) 2895 * @vfl: virthchnl filter list used to add the filters 2896 */ 2897 static int 2898 ice_vc_add_vlans(struct ice_vf *vf, struct ice_vsi *vsi, 2899 struct virtchnl_vlan_filter_list_v2 *vfl) 2900 { 2901 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf); 2902 int err; 2903 u16 i; 2904 2905 for (i = 0; i < vfl->num_elements; i++) { 2906 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i]; 2907 struct virtchnl_vlan *vc_vlan; 2908 2909 vc_vlan = &vlan_fltr->outer; 2910 if (ice_vc_is_valid_vlan(vc_vlan)) { 2911 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan); 2912 2913 err = ice_vc_vlan_action(vsi, 2914 vsi->outer_vlan_ops.add_vlan, 2915 &vlan); 2916 if (err) 2917 return err; 2918 2919 if (vlan_promisc) { 2920 err = ice_vf_ena_vlan_promisc(vsi, &vlan); 2921 if (err) 2922 return err; 2923 } 2924 } 2925 2926 vc_vlan = &vlan_fltr->inner; 2927 if (ice_vc_is_valid_vlan(vc_vlan)) { 2928 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan); 2929 2930 err = ice_vc_vlan_action(vsi, 2931 vsi->inner_vlan_ops.add_vlan, 2932 &vlan); 2933 if (err) 2934 return err; 2935 2936 /* no support for VLAN promiscuous on inner VLAN unless 2937 * we are in Single VLAN Mode (SVM) 2938 */ 2939 if (!ice_is_dvm_ena(&vsi->back->hw) && vlan_promisc) { 2940 err = ice_vf_ena_vlan_promisc(vsi, &vlan); 2941 if (err) 2942 return err; 2943 } 2944 } 2945 } 2946 2947 return 0; 2948 } 2949 2950 /** 2951 * ice_vc_validate_add_vlan_filter_list - validate add filter list from the VF 2952 * @vsi: VF VSI used to get number of existing VLAN filters 2953 * @vfc: negotiated/supported VLAN filtering capabilities 2954 * @vfl: VLAN filter list from VF to validate 2955 * 2956 * Validate all of the filters in the VLAN filter list from the VF during the 2957 * VIRTCHNL_OP_ADD_VLAN_V2 opcode. If any of the checks fail then return false. 2958 * Otherwise return true. 2959 */ 2960 static bool 2961 ice_vc_validate_add_vlan_filter_list(struct ice_vsi *vsi, 2962 struct virtchnl_vlan_filtering_caps *vfc, 2963 struct virtchnl_vlan_filter_list_v2 *vfl) 2964 { 2965 u16 num_requested_filters = vsi->num_vlan + vfl->num_elements; 2966 2967 if (num_requested_filters > vfc->max_filters) 2968 return false; 2969 2970 return ice_vc_validate_vlan_filter_list(vfc, vfl); 2971 } 2972 2973 /** 2974 * ice_vc_add_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_ADD_VLAN_V2 2975 * @vf: VF the message was received from 2976 * @msg: message received from the VF 2977 */ 2978 static int ice_vc_add_vlan_v2_msg(struct ice_vf *vf, u8 *msg) 2979 { 2980 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 2981 struct virtchnl_vlan_filter_list_v2 *vfl = 2982 (struct virtchnl_vlan_filter_list_v2 *)msg; 2983 struct ice_vsi *vsi; 2984 2985 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 2986 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2987 goto out; 2988 } 2989 2990 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) { 2991 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2992 goto out; 2993 } 2994 2995 vsi = ice_get_vf_vsi(vf); 2996 if (!vsi) { 2997 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 2998 goto out; 2999 } 3000 3001 if (!ice_vc_validate_add_vlan_filter_list(vsi, 3002 &vf->vlan_v2_caps.filtering, 3003 vfl)) { 3004 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3005 goto out; 3006 } 3007 3008 if (ice_vc_add_vlans(vf, vsi, vfl)) 3009 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3010 3011 out: 3012 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN_V2, v_ret, NULL, 3013 0); 3014 } 3015 3016 /** 3017 * ice_vc_valid_vlan_setting - validate VLAN setting 3018 * @negotiated_settings: negotiated VLAN settings during VF init 3019 * @ethertype_setting: ethertype(s) requested for the VLAN setting 3020 */ 3021 static bool 3022 ice_vc_valid_vlan_setting(u32 negotiated_settings, u32 ethertype_setting) 3023 { 3024 if (ethertype_setting && !(negotiated_settings & ethertype_setting)) 3025 return false; 3026 3027 /* only allow a single VIRTCHNL_VLAN_ETHERTYPE if 3028 * VIRTHCNL_VLAN_ETHERTYPE_AND is not negotiated/supported 3029 */ 3030 if (!(negotiated_settings & VIRTCHNL_VLAN_ETHERTYPE_AND) && 3031 hweight32(ethertype_setting) > 1) 3032 return false; 3033 3034 /* ability to modify the VLAN setting was not negotiated */ 3035 if (!(negotiated_settings & VIRTCHNL_VLAN_TOGGLE)) 3036 return false; 3037 3038 return true; 3039 } 3040 3041 /** 3042 * ice_vc_valid_vlan_setting_msg - validate the VLAN setting message 3043 * @caps: negotiated VLAN settings during VF init 3044 * @msg: message to validate 3045 * 3046 * Used to validate any VLAN virtchnl message sent as a 3047 * virtchnl_vlan_setting structure. Validates the message against the 3048 * negotiated/supported caps during VF driver init. 3049 */ 3050 static bool 3051 ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps *caps, 3052 struct virtchnl_vlan_setting *msg) 3053 { 3054 if ((!msg->outer_ethertype_setting && 3055 !msg->inner_ethertype_setting) || 3056 (!caps->outer && !caps->inner)) 3057 return false; 3058 3059 if (msg->outer_ethertype_setting && 3060 !ice_vc_valid_vlan_setting(caps->outer, 3061 msg->outer_ethertype_setting)) 3062 return false; 3063 3064 if (msg->inner_ethertype_setting && 3065 !ice_vc_valid_vlan_setting(caps->inner, 3066 msg->inner_ethertype_setting)) 3067 return false; 3068 3069 return true; 3070 } 3071 3072 /** 3073 * ice_vc_get_tpid - transform from VIRTCHNL_VLAN_ETHERTYPE_* to VLAN TPID 3074 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* used to get VLAN TPID 3075 * @tpid: VLAN TPID to populate 3076 */ 3077 static int ice_vc_get_tpid(u32 ethertype_setting, u16 *tpid) 3078 { 3079 switch (ethertype_setting) { 3080 case VIRTCHNL_VLAN_ETHERTYPE_8100: 3081 *tpid = ETH_P_8021Q; 3082 break; 3083 case VIRTCHNL_VLAN_ETHERTYPE_88A8: 3084 *tpid = ETH_P_8021AD; 3085 break; 3086 case VIRTCHNL_VLAN_ETHERTYPE_9100: 3087 *tpid = ETH_P_QINQ1; 3088 break; 3089 default: 3090 *tpid = 0; 3091 return -EINVAL; 3092 } 3093 3094 return 0; 3095 } 3096 3097 /** 3098 * ice_vc_ena_vlan_offload - enable VLAN offload based on the ethertype_setting 3099 * @vsi: VF's VSI used to enable the VLAN offload 3100 * @ena_offload: function used to enable the VLAN offload 3101 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* to enable offloads for 3102 */ 3103 static int 3104 ice_vc_ena_vlan_offload(struct ice_vsi *vsi, 3105 int (*ena_offload)(struct ice_vsi *vsi, u16 tpid), 3106 u32 ethertype_setting) 3107 { 3108 u16 tpid; 3109 int err; 3110 3111 err = ice_vc_get_tpid(ethertype_setting, &tpid); 3112 if (err) 3113 return err; 3114 3115 err = ena_offload(vsi, tpid); 3116 if (err) 3117 return err; 3118 3119 return 0; 3120 } 3121 3122 #define ICE_L2TSEL_QRX_CONTEXT_REG_IDX 3 3123 #define ICE_L2TSEL_BIT_OFFSET 23 3124 enum ice_l2tsel { 3125 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND, 3126 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1, 3127 }; 3128 3129 /** 3130 * ice_vsi_update_l2tsel - update l2tsel field for all Rx rings on this VSI 3131 * @vsi: VSI used to update l2tsel on 3132 * @l2tsel: l2tsel setting requested 3133 * 3134 * Use the l2tsel setting to update all of the Rx queue context bits for l2tsel. 3135 * This will modify which descriptor field the first offloaded VLAN will be 3136 * stripped into. 3137 */ 3138 static void ice_vsi_update_l2tsel(struct ice_vsi *vsi, enum ice_l2tsel l2tsel) 3139 { 3140 struct ice_hw *hw = &vsi->back->hw; 3141 u32 l2tsel_bit; 3142 int i; 3143 3144 if (l2tsel == ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND) 3145 l2tsel_bit = 0; 3146 else 3147 l2tsel_bit = BIT(ICE_L2TSEL_BIT_OFFSET); 3148 3149 for (i = 0; i < vsi->alloc_rxq; i++) { 3150 u16 pfq = vsi->rxq_map[i]; 3151 u32 qrx_context_offset; 3152 u32 regval; 3153 3154 qrx_context_offset = 3155 QRX_CONTEXT(ICE_L2TSEL_QRX_CONTEXT_REG_IDX, pfq); 3156 3157 regval = rd32(hw, qrx_context_offset); 3158 regval &= ~BIT(ICE_L2TSEL_BIT_OFFSET); 3159 regval |= l2tsel_bit; 3160 wr32(hw, qrx_context_offset, regval); 3161 } 3162 } 3163 3164 /** 3165 * ice_vc_ena_vlan_stripping_v2_msg 3166 * @vf: VF the message was received from 3167 * @msg: message received from the VF 3168 * 3169 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 3170 */ 3171 static int ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg) 3172 { 3173 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 3174 struct virtchnl_vlan_supported_caps *stripping_support; 3175 struct virtchnl_vlan_setting *strip_msg = 3176 (struct virtchnl_vlan_setting *)msg; 3177 u32 ethertype_setting; 3178 struct ice_vsi *vsi; 3179 3180 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 3181 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3182 goto out; 3183 } 3184 3185 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) { 3186 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3187 goto out; 3188 } 3189 3190 vsi = ice_get_vf_vsi(vf); 3191 if (!vsi) { 3192 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3193 goto out; 3194 } 3195 3196 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support; 3197 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) { 3198 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3199 goto out; 3200 } 3201 3202 ethertype_setting = strip_msg->outer_ethertype_setting; 3203 if (ethertype_setting) { 3204 if (ice_vc_ena_vlan_offload(vsi, 3205 vsi->outer_vlan_ops.ena_stripping, 3206 ethertype_setting)) { 3207 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3208 goto out; 3209 } else { 3210 enum ice_l2tsel l2tsel = 3211 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND; 3212 3213 /* PF tells the VF that the outer VLAN tag is always 3214 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and 3215 * inner is always extracted to 3216 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to 3217 * support outer stripping so the first tag always ends 3218 * up in L2TAG2_2ND and the second/inner tag, if 3219 * enabled, is extracted in L2TAG1. 3220 */ 3221 ice_vsi_update_l2tsel(vsi, l2tsel); 3222 } 3223 } 3224 3225 ethertype_setting = strip_msg->inner_ethertype_setting; 3226 if (ethertype_setting && 3227 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_stripping, 3228 ethertype_setting)) { 3229 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3230 goto out; 3231 } 3232 3233 out: 3234 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2, 3235 v_ret, NULL, 0); 3236 } 3237 3238 /** 3239 * ice_vc_dis_vlan_stripping_v2_msg 3240 * @vf: VF the message was received from 3241 * @msg: message received from the VF 3242 * 3243 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 3244 */ 3245 static int ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg) 3246 { 3247 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 3248 struct virtchnl_vlan_supported_caps *stripping_support; 3249 struct virtchnl_vlan_setting *strip_msg = 3250 (struct virtchnl_vlan_setting *)msg; 3251 u32 ethertype_setting; 3252 struct ice_vsi *vsi; 3253 3254 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 3255 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3256 goto out; 3257 } 3258 3259 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) { 3260 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3261 goto out; 3262 } 3263 3264 vsi = ice_get_vf_vsi(vf); 3265 if (!vsi) { 3266 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3267 goto out; 3268 } 3269 3270 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support; 3271 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) { 3272 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3273 goto out; 3274 } 3275 3276 ethertype_setting = strip_msg->outer_ethertype_setting; 3277 if (ethertype_setting) { 3278 if (vsi->outer_vlan_ops.dis_stripping(vsi)) { 3279 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3280 goto out; 3281 } else { 3282 enum ice_l2tsel l2tsel = 3283 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1; 3284 3285 /* PF tells the VF that the outer VLAN tag is always 3286 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and 3287 * inner is always extracted to 3288 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to 3289 * support inner stripping while outer stripping is 3290 * disabled so that the first and only tag is extracted 3291 * in L2TAG1. 3292 */ 3293 ice_vsi_update_l2tsel(vsi, l2tsel); 3294 } 3295 } 3296 3297 ethertype_setting = strip_msg->inner_ethertype_setting; 3298 if (ethertype_setting && vsi->inner_vlan_ops.dis_stripping(vsi)) { 3299 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3300 goto out; 3301 } 3302 3303 out: 3304 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2, 3305 v_ret, NULL, 0); 3306 } 3307 3308 /** 3309 * ice_vc_ena_vlan_insertion_v2_msg 3310 * @vf: VF the message was received from 3311 * @msg: message received from the VF 3312 * 3313 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 3314 */ 3315 static int ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg) 3316 { 3317 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 3318 struct virtchnl_vlan_supported_caps *insertion_support; 3319 struct virtchnl_vlan_setting *insertion_msg = 3320 (struct virtchnl_vlan_setting *)msg; 3321 u32 ethertype_setting; 3322 struct ice_vsi *vsi; 3323 3324 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 3325 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3326 goto out; 3327 } 3328 3329 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) { 3330 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3331 goto out; 3332 } 3333 3334 vsi = ice_get_vf_vsi(vf); 3335 if (!vsi) { 3336 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3337 goto out; 3338 } 3339 3340 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support; 3341 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) { 3342 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3343 goto out; 3344 } 3345 3346 ethertype_setting = insertion_msg->outer_ethertype_setting; 3347 if (ethertype_setting && 3348 ice_vc_ena_vlan_offload(vsi, vsi->outer_vlan_ops.ena_insertion, 3349 ethertype_setting)) { 3350 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3351 goto out; 3352 } 3353 3354 ethertype_setting = insertion_msg->inner_ethertype_setting; 3355 if (ethertype_setting && 3356 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_insertion, 3357 ethertype_setting)) { 3358 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3359 goto out; 3360 } 3361 3362 out: 3363 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2, 3364 v_ret, NULL, 0); 3365 } 3366 3367 /** 3368 * ice_vc_dis_vlan_insertion_v2_msg 3369 * @vf: VF the message was received from 3370 * @msg: message received from the VF 3371 * 3372 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 3373 */ 3374 static int ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg) 3375 { 3376 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 3377 struct virtchnl_vlan_supported_caps *insertion_support; 3378 struct virtchnl_vlan_setting *insertion_msg = 3379 (struct virtchnl_vlan_setting *)msg; 3380 u32 ethertype_setting; 3381 struct ice_vsi *vsi; 3382 3383 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { 3384 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3385 goto out; 3386 } 3387 3388 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) { 3389 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3390 goto out; 3391 } 3392 3393 vsi = ice_get_vf_vsi(vf); 3394 if (!vsi) { 3395 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3396 goto out; 3397 } 3398 3399 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support; 3400 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) { 3401 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3402 goto out; 3403 } 3404 3405 ethertype_setting = insertion_msg->outer_ethertype_setting; 3406 if (ethertype_setting && vsi->outer_vlan_ops.dis_insertion(vsi)) { 3407 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3408 goto out; 3409 } 3410 3411 ethertype_setting = insertion_msg->inner_ethertype_setting; 3412 if (ethertype_setting && vsi->inner_vlan_ops.dis_insertion(vsi)) { 3413 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3414 goto out; 3415 } 3416 3417 out: 3418 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2, 3419 v_ret, NULL, 0); 3420 } 3421 3422 static const struct ice_virtchnl_ops ice_virtchnl_dflt_ops = { 3423 .get_ver_msg = ice_vc_get_ver_msg, 3424 .get_vf_res_msg = ice_vc_get_vf_res_msg, 3425 .reset_vf = ice_vc_reset_vf_msg, 3426 .add_mac_addr_msg = ice_vc_add_mac_addr_msg, 3427 .del_mac_addr_msg = ice_vc_del_mac_addr_msg, 3428 .cfg_qs_msg = ice_vc_cfg_qs_msg, 3429 .ena_qs_msg = ice_vc_ena_qs_msg, 3430 .dis_qs_msg = ice_vc_dis_qs_msg, 3431 .request_qs_msg = ice_vc_request_qs_msg, 3432 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg, 3433 .config_rss_key = ice_vc_config_rss_key, 3434 .config_rss_lut = ice_vc_config_rss_lut, 3435 .get_stats_msg = ice_vc_get_stats_msg, 3436 .cfg_promiscuous_mode_msg = ice_vc_cfg_promiscuous_mode_msg, 3437 .add_vlan_msg = ice_vc_add_vlan_msg, 3438 .remove_vlan_msg = ice_vc_remove_vlan_msg, 3439 .ena_vlan_stripping = ice_vc_ena_vlan_stripping, 3440 .dis_vlan_stripping = ice_vc_dis_vlan_stripping, 3441 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg, 3442 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr, 3443 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr, 3444 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps, 3445 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg, 3446 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg, 3447 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg, 3448 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg, 3449 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg, 3450 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg, 3451 }; 3452 3453 /** 3454 * ice_virtchnl_set_dflt_ops - Switch to default virtchnl ops 3455 * @vf: the VF to switch ops 3456 */ 3457 void ice_virtchnl_set_dflt_ops(struct ice_vf *vf) 3458 { 3459 vf->virtchnl_ops = &ice_virtchnl_dflt_ops; 3460 } 3461 3462 /** 3463 * ice_vc_repr_add_mac 3464 * @vf: pointer to VF 3465 * @msg: virtchannel message 3466 * 3467 * When port representors are created, we do not add MAC rule 3468 * to firmware, we store it so that PF could report same 3469 * MAC as VF. 3470 */ 3471 static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg) 3472 { 3473 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; 3474 struct virtchnl_ether_addr_list *al = 3475 (struct virtchnl_ether_addr_list *)msg; 3476 struct ice_vsi *vsi; 3477 struct ice_pf *pf; 3478 int i; 3479 3480 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) || 3481 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) { 3482 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3483 goto handle_mac_exit; 3484 } 3485 3486 pf = vf->pf; 3487 3488 vsi = ice_get_vf_vsi(vf); 3489 if (!vsi) { 3490 v_ret = VIRTCHNL_STATUS_ERR_PARAM; 3491 goto handle_mac_exit; 3492 } 3493 3494 for (i = 0; i < al->num_elements; i++) { 3495 u8 *mac_addr = al->list[i].addr; 3496 int result; 3497 3498 if (!is_unicast_ether_addr(mac_addr) || 3499 ether_addr_equal(mac_addr, vf->hw_lan_addr.addr)) 3500 continue; 3501 3502 if (vf->pf_set_mac) { 3503 dev_err(ice_pf_to_dev(pf), "VF attempting to override administratively set MAC address\n"); 3504 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED; 3505 goto handle_mac_exit; 3506 } 3507 3508 result = ice_eswitch_add_vf_mac_rule(pf, vf, mac_addr); 3509 if (result) { 3510 dev_err(ice_pf_to_dev(pf), "Failed to add MAC %pM for VF %d\n, error %d\n", 3511 mac_addr, vf->vf_id, result); 3512 goto handle_mac_exit; 3513 } 3514 3515 ice_vfhw_mac_add(vf, &al->list[i]); 3516 vf->num_mac++; 3517 break; 3518 } 3519 3520 handle_mac_exit: 3521 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR, 3522 v_ret, NULL, 0); 3523 } 3524 3525 /** 3526 * ice_vc_repr_del_mac - response with success for deleting MAC 3527 * @vf: pointer to VF 3528 * @msg: virtchannel message 3529 * 3530 * Respond with success to not break normal VF flow. 3531 * For legacy VF driver try to update cached MAC address. 3532 */ 3533 static int 3534 ice_vc_repr_del_mac(struct ice_vf __always_unused *vf, u8 __always_unused *msg) 3535 { 3536 struct virtchnl_ether_addr_list *al = 3537 (struct virtchnl_ether_addr_list *)msg; 3538 3539 ice_update_legacy_cached_mac(vf, &al->list[0]); 3540 3541 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR, 3542 VIRTCHNL_STATUS_SUCCESS, NULL, 0); 3543 } 3544 3545 static int ice_vc_repr_add_vlan(struct ice_vf *vf, u8 __always_unused *msg) 3546 { 3547 dev_dbg(ice_pf_to_dev(vf->pf), 3548 "Can't add VLAN in switchdev mode for VF %d\n", vf->vf_id); 3549 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, 3550 VIRTCHNL_STATUS_SUCCESS, NULL, 0); 3551 } 3552 3553 static int ice_vc_repr_del_vlan(struct ice_vf *vf, u8 __always_unused *msg) 3554 { 3555 dev_dbg(ice_pf_to_dev(vf->pf), 3556 "Can't delete VLAN in switchdev mode for VF %d\n", vf->vf_id); 3557 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, 3558 VIRTCHNL_STATUS_SUCCESS, NULL, 0); 3559 } 3560 3561 static int ice_vc_repr_ena_vlan_stripping(struct ice_vf *vf) 3562 { 3563 dev_dbg(ice_pf_to_dev(vf->pf), 3564 "Can't enable VLAN stripping in switchdev mode for VF %d\n", 3565 vf->vf_id); 3566 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, 3567 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, 3568 NULL, 0); 3569 } 3570 3571 static int ice_vc_repr_dis_vlan_stripping(struct ice_vf *vf) 3572 { 3573 dev_dbg(ice_pf_to_dev(vf->pf), 3574 "Can't disable VLAN stripping in switchdev mode for VF %d\n", 3575 vf->vf_id); 3576 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, 3577 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, 3578 NULL, 0); 3579 } 3580 3581 static int 3582 ice_vc_repr_cfg_promiscuous_mode(struct ice_vf *vf, u8 __always_unused *msg) 3583 { 3584 dev_dbg(ice_pf_to_dev(vf->pf), 3585 "Can't config promiscuous mode in switchdev mode for VF %d\n", 3586 vf->vf_id); 3587 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, 3588 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, 3589 NULL, 0); 3590 } 3591 3592 static const struct ice_virtchnl_ops ice_virtchnl_repr_ops = { 3593 .get_ver_msg = ice_vc_get_ver_msg, 3594 .get_vf_res_msg = ice_vc_get_vf_res_msg, 3595 .reset_vf = ice_vc_reset_vf_msg, 3596 .add_mac_addr_msg = ice_vc_repr_add_mac, 3597 .del_mac_addr_msg = ice_vc_repr_del_mac, 3598 .cfg_qs_msg = ice_vc_cfg_qs_msg, 3599 .ena_qs_msg = ice_vc_ena_qs_msg, 3600 .dis_qs_msg = ice_vc_dis_qs_msg, 3601 .request_qs_msg = ice_vc_request_qs_msg, 3602 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg, 3603 .config_rss_key = ice_vc_config_rss_key, 3604 .config_rss_lut = ice_vc_config_rss_lut, 3605 .get_stats_msg = ice_vc_get_stats_msg, 3606 .cfg_promiscuous_mode_msg = ice_vc_repr_cfg_promiscuous_mode, 3607 .add_vlan_msg = ice_vc_repr_add_vlan, 3608 .remove_vlan_msg = ice_vc_repr_del_vlan, 3609 .ena_vlan_stripping = ice_vc_repr_ena_vlan_stripping, 3610 .dis_vlan_stripping = ice_vc_repr_dis_vlan_stripping, 3611 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg, 3612 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr, 3613 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr, 3614 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps, 3615 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg, 3616 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg, 3617 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg, 3618 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg, 3619 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg, 3620 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg, 3621 }; 3622 3623 /** 3624 * ice_virtchnl_set_repr_ops - Switch to representor virtchnl ops 3625 * @vf: the VF to switch ops 3626 */ 3627 void ice_virtchnl_set_repr_ops(struct ice_vf *vf) 3628 { 3629 vf->virtchnl_ops = &ice_virtchnl_repr_ops; 3630 } 3631 3632 /** 3633 * ice_vc_process_vf_msg - Process request from VF 3634 * @pf: pointer to the PF structure 3635 * @event: pointer to the AQ event 3636 * 3637 * called from the common asq/arq handler to 3638 * process request from VF 3639 */ 3640 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) 3641 { 3642 u32 v_opcode = le32_to_cpu(event->desc.cookie_high); 3643 s16 vf_id = le16_to_cpu(event->desc.retval); 3644 const struct ice_virtchnl_ops *ops; 3645 u16 msglen = event->msg_len; 3646 u8 *msg = event->msg_buf; 3647 struct ice_vf *vf = NULL; 3648 struct device *dev; 3649 int err = 0; 3650 3651 dev = ice_pf_to_dev(pf); 3652 3653 vf = ice_get_vf_by_id(pf, vf_id); 3654 if (!vf) { 3655 dev_err(dev, "Unable to locate VF for message from VF ID %d, opcode %d, len %d\n", 3656 vf_id, v_opcode, msglen); 3657 return; 3658 } 3659 3660 mutex_lock(&vf->cfg_lock); 3661 3662 /* Check if VF is disabled. */ 3663 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) { 3664 err = -EPERM; 3665 goto error_handler; 3666 } 3667 3668 ops = vf->virtchnl_ops; 3669 3670 /* Perform basic checks on the msg */ 3671 err = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen); 3672 if (err) { 3673 if (err == VIRTCHNL_STATUS_ERR_PARAM) 3674 err = -EPERM; 3675 else 3676 err = -EINVAL; 3677 } 3678 3679 error_handler: 3680 if (err) { 3681 ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM, 3682 NULL, 0); 3683 dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n", 3684 vf_id, v_opcode, msglen, err); 3685 goto finish; 3686 } 3687 3688 if (!ice_vc_is_opcode_allowed(vf, v_opcode)) { 3689 ice_vc_send_msg_to_vf(vf, v_opcode, 3690 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL, 3691 0); 3692 goto finish; 3693 } 3694 3695 switch (v_opcode) { 3696 case VIRTCHNL_OP_VERSION: 3697 err = ops->get_ver_msg(vf, msg); 3698 break; 3699 case VIRTCHNL_OP_GET_VF_RESOURCES: 3700 err = ops->get_vf_res_msg(vf, msg); 3701 if (ice_vf_init_vlan_stripping(vf)) 3702 dev_dbg(dev, "Failed to initialize VLAN stripping for VF %d\n", 3703 vf->vf_id); 3704 ice_vc_notify_vf_link_state(vf); 3705 break; 3706 case VIRTCHNL_OP_RESET_VF: 3707 ops->reset_vf(vf); 3708 break; 3709 case VIRTCHNL_OP_ADD_ETH_ADDR: 3710 err = ops->add_mac_addr_msg(vf, msg); 3711 break; 3712 case VIRTCHNL_OP_DEL_ETH_ADDR: 3713 err = ops->del_mac_addr_msg(vf, msg); 3714 break; 3715 case VIRTCHNL_OP_CONFIG_VSI_QUEUES: 3716 err = ops->cfg_qs_msg(vf, msg); 3717 break; 3718 case VIRTCHNL_OP_ENABLE_QUEUES: 3719 err = ops->ena_qs_msg(vf, msg); 3720 ice_vc_notify_vf_link_state(vf); 3721 break; 3722 case VIRTCHNL_OP_DISABLE_QUEUES: 3723 err = ops->dis_qs_msg(vf, msg); 3724 break; 3725 case VIRTCHNL_OP_REQUEST_QUEUES: 3726 err = ops->request_qs_msg(vf, msg); 3727 break; 3728 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 3729 err = ops->cfg_irq_map_msg(vf, msg); 3730 break; 3731 case VIRTCHNL_OP_CONFIG_RSS_KEY: 3732 err = ops->config_rss_key(vf, msg); 3733 break; 3734 case VIRTCHNL_OP_CONFIG_RSS_LUT: 3735 err = ops->config_rss_lut(vf, msg); 3736 break; 3737 case VIRTCHNL_OP_GET_STATS: 3738 err = ops->get_stats_msg(vf, msg); 3739 break; 3740 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 3741 err = ops->cfg_promiscuous_mode_msg(vf, msg); 3742 break; 3743 case VIRTCHNL_OP_ADD_VLAN: 3744 err = ops->add_vlan_msg(vf, msg); 3745 break; 3746 case VIRTCHNL_OP_DEL_VLAN: 3747 err = ops->remove_vlan_msg(vf, msg); 3748 break; 3749 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 3750 err = ops->ena_vlan_stripping(vf); 3751 break; 3752 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 3753 err = ops->dis_vlan_stripping(vf); 3754 break; 3755 case VIRTCHNL_OP_ADD_FDIR_FILTER: 3756 err = ops->add_fdir_fltr_msg(vf, msg); 3757 break; 3758 case VIRTCHNL_OP_DEL_FDIR_FILTER: 3759 err = ops->del_fdir_fltr_msg(vf, msg); 3760 break; 3761 case VIRTCHNL_OP_ADD_RSS_CFG: 3762 err = ops->handle_rss_cfg_msg(vf, msg, true); 3763 break; 3764 case VIRTCHNL_OP_DEL_RSS_CFG: 3765 err = ops->handle_rss_cfg_msg(vf, msg, false); 3766 break; 3767 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: 3768 err = ops->get_offload_vlan_v2_caps(vf); 3769 break; 3770 case VIRTCHNL_OP_ADD_VLAN_V2: 3771 err = ops->add_vlan_v2_msg(vf, msg); 3772 break; 3773 case VIRTCHNL_OP_DEL_VLAN_V2: 3774 err = ops->remove_vlan_v2_msg(vf, msg); 3775 break; 3776 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2: 3777 err = ops->ena_vlan_stripping_v2_msg(vf, msg); 3778 break; 3779 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2: 3780 err = ops->dis_vlan_stripping_v2_msg(vf, msg); 3781 break; 3782 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2: 3783 err = ops->ena_vlan_insertion_v2_msg(vf, msg); 3784 break; 3785 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2: 3786 err = ops->dis_vlan_insertion_v2_msg(vf, msg); 3787 break; 3788 case VIRTCHNL_OP_UNKNOWN: 3789 default: 3790 dev_err(dev, "Unsupported opcode %d from VF %d\n", v_opcode, 3791 vf_id); 3792 err = ice_vc_send_msg_to_vf(vf, v_opcode, 3793 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, 3794 NULL, 0); 3795 break; 3796 } 3797 if (err) { 3798 /* Helper function cares less about error return values here 3799 * as it is busy with pending work. 3800 */ 3801 dev_info(dev, "PF failed to honor VF %d, opcode %d, error %d\n", 3802 vf_id, v_opcode, err); 3803 } 3804 3805 finish: 3806 mutex_unlock(&vf->cfg_lock); 3807 ice_put_vf(vf); 3808 } 3809