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