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