0001
0002
0003
0004 #include "ice_vf_lib_private.h"
0005 #include "ice.h"
0006 #include "ice_lib.h"
0007 #include "ice_fltr.h"
0008 #include "ice_virtchnl_allowlist.h"
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id)
0026 {
0027 struct ice_vf *vf;
0028
0029 rcu_read_lock();
0030 hash_for_each_possible_rcu(pf->vfs.table, vf, entry, vf_id) {
0031 if (vf->vf_id == vf_id) {
0032 struct ice_vf *found;
0033
0034 if (kref_get_unless_zero(&vf->refcnt))
0035 found = vf;
0036 else
0037 found = NULL;
0038
0039 rcu_read_unlock();
0040 return found;
0041 }
0042 }
0043 rcu_read_unlock();
0044
0045 return NULL;
0046 }
0047
0048
0049
0050
0051
0052
0053
0054
0055 static void ice_release_vf(struct kref *ref)
0056 {
0057 struct ice_vf *vf = container_of(ref, struct ice_vf, refcnt);
0058
0059 vf->vf_ops->free(vf);
0060 }
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 void ice_put_vf(struct ice_vf *vf)
0074 {
0075 kref_put(&vf->refcnt, ice_release_vf);
0076 }
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 bool ice_has_vfs(struct ice_pf *pf)
0088 {
0089
0090
0091
0092 return !hash_empty(pf->vfs.table);
0093 }
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103 u16 ice_get_num_vfs(struct ice_pf *pf)
0104 {
0105 struct ice_vf *vf;
0106 unsigned int bkt;
0107 u16 num_vfs = 0;
0108
0109 rcu_read_lock();
0110 ice_for_each_vf_rcu(pf, bkt, vf)
0111 num_vfs++;
0112 rcu_read_unlock();
0113
0114 return num_vfs;
0115 }
0116
0117
0118
0119
0120
0121 struct ice_vsi *ice_get_vf_vsi(struct ice_vf *vf)
0122 {
0123 if (vf->lan_vsi_idx == ICE_NO_VSI)
0124 return NULL;
0125
0126 return vf->pf->vsi[vf->lan_vsi_idx];
0127 }
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 bool ice_is_vf_disabled(struct ice_vf *vf)
0142 {
0143 struct ice_pf *pf = vf->pf;
0144
0145 return (test_bit(ICE_VF_DIS, pf->state) ||
0146 test_bit(ICE_VF_STATE_DIS, vf->vf_states));
0147 }
0148
0149
0150
0151
0152
0153
0154
0155
0156 static void ice_wait_on_vf_reset(struct ice_vf *vf)
0157 {
0158 int i;
0159
0160 for (i = 0; i < ICE_MAX_VF_RESET_TRIES; i++) {
0161 if (test_bit(ICE_VF_STATE_INIT, vf->vf_states))
0162 break;
0163 msleep(ICE_MAX_VF_RESET_SLEEP_MS);
0164 }
0165 }
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 int ice_check_vf_ready_for_cfg(struct ice_vf *vf)
0176 {
0177 ice_wait_on_vf_reset(vf);
0178
0179 if (ice_is_vf_disabled(vf))
0180 return -EINVAL;
0181
0182 if (ice_check_vf_init(vf))
0183 return -EBUSY;
0184
0185 return 0;
0186 }
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198 static void ice_trigger_vf_reset(struct ice_vf *vf, bool is_vflr, bool is_pfr)
0199 {
0200
0201 clear_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
0202
0203
0204
0205
0206 clear_bit(ICE_VF_STATE_INIT, vf->vf_states);
0207
0208
0209
0210
0211
0212
0213 if (!is_pfr)
0214 vf->vf_ops->clear_mbx_register(vf);
0215
0216 vf->vf_ops->trigger_reset_register(vf, is_vflr);
0217 }
0218
0219 static void ice_vf_clear_counters(struct ice_vf *vf)
0220 {
0221 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
0222
0223 if (vsi)
0224 vsi->num_vlan = 0;
0225
0226 vf->num_mac = 0;
0227 memset(&vf->mdd_tx_events, 0, sizeof(vf->mdd_tx_events));
0228 memset(&vf->mdd_rx_events, 0, sizeof(vf->mdd_rx_events));
0229 }
0230
0231
0232
0233
0234
0235
0236
0237
0238 static void ice_vf_pre_vsi_rebuild(struct ice_vf *vf)
0239 {
0240 ice_vf_clear_counters(vf);
0241 vf->vf_ops->clear_reset_trigger(vf);
0242 }
0243
0244
0245
0246
0247
0248
0249
0250
0251 static int ice_vf_rebuild_vsi(struct ice_vf *vf)
0252 {
0253 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
0254 struct ice_pf *pf = vf->pf;
0255
0256 if (WARN_ON(!vsi))
0257 return -EINVAL;
0258
0259 if (ice_vsi_rebuild(vsi, true)) {
0260 dev_err(ice_pf_to_dev(pf), "failed to rebuild VF %d VSI\n",
0261 vf->vf_id);
0262 return -EIO;
0263 }
0264
0265
0266
0267 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
0268 vf->lan_vsi_num = vsi->vsi_num;
0269
0270 return 0;
0271 }
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281 bool ice_is_any_vf_in_unicast_promisc(struct ice_pf *pf)
0282 {
0283 bool is_vf_promisc = false;
0284 struct ice_vf *vf;
0285 unsigned int bkt;
0286
0287 rcu_read_lock();
0288 ice_for_each_vf_rcu(pf, bkt, vf) {
0289
0290 if (test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states)) {
0291 is_vf_promisc = true;
0292 break;
0293 }
0294 }
0295 rcu_read_unlock();
0296
0297 return is_vf_promisc;
0298 }
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310 void
0311 ice_vf_get_promisc_masks(struct ice_vf *vf, struct ice_vsi *vsi,
0312 u8 *ucast_m, u8 *mcast_m)
0313 {
0314 if (ice_vf_is_port_vlan_ena(vf) ||
0315 ice_vsi_has_non_zero_vlans(vsi)) {
0316 *mcast_m = ICE_MCAST_VLAN_PROMISC_BITS;
0317 *ucast_m = ICE_UCAST_VLAN_PROMISC_BITS;
0318 } else {
0319 *mcast_m = ICE_MCAST_PROMISC_BITS;
0320 *ucast_m = ICE_UCAST_PROMISC_BITS;
0321 }
0322 }
0323
0324
0325
0326
0327
0328
0329
0330
0331 static int
0332 ice_vf_clear_all_promisc_modes(struct ice_vf *vf, struct ice_vsi *vsi)
0333 {
0334 struct ice_pf *pf = vf->pf;
0335 u8 ucast_m, mcast_m;
0336 int ret = 0;
0337
0338 ice_vf_get_promisc_masks(vf, vsi, &ucast_m, &mcast_m);
0339 if (test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states)) {
0340 if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) {
0341 if (ice_is_dflt_vsi_in_use(vsi->port_info))
0342 ret = ice_clear_dflt_vsi(vsi);
0343 } else {
0344 ret = ice_vf_clear_vsi_promisc(vf, vsi, ucast_m);
0345 }
0346
0347 if (ret) {
0348 dev_err(ice_pf_to_dev(vf->pf), "Disabling promiscuous mode failed\n");
0349 } else {
0350 clear_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states);
0351 dev_info(ice_pf_to_dev(vf->pf), "Disabling promiscuous mode succeeded\n");
0352 }
0353 }
0354
0355 if (test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) {
0356 ret = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
0357 if (ret) {
0358 dev_err(ice_pf_to_dev(vf->pf), "Disabling allmulticast mode failed\n");
0359 } else {
0360 clear_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states);
0361 dev_info(ice_pf_to_dev(vf->pf), "Disabling allmulticast mode succeeded\n");
0362 }
0363 }
0364 return ret;
0365 }
0366
0367
0368
0369
0370
0371
0372
0373 int
0374 ice_vf_set_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m)
0375 {
0376 struct ice_hw *hw = &vsi->back->hw;
0377 int status;
0378
0379 if (ice_vf_is_port_vlan_ena(vf))
0380 status = ice_fltr_set_vsi_promisc(hw, vsi->idx, promisc_m,
0381 ice_vf_get_port_vlan_id(vf));
0382 else if (ice_vsi_has_non_zero_vlans(vsi))
0383 status = ice_fltr_set_vlan_vsi_promisc(hw, vsi, promisc_m);
0384 else
0385 status = ice_fltr_set_vsi_promisc(hw, vsi->idx, promisc_m, 0);
0386
0387 if (status && status != -EEXIST) {
0388 dev_err(ice_pf_to_dev(vsi->back), "enable Tx/Rx filter promiscuous mode on VF-%u failed, error: %d\n",
0389 vf->vf_id, status);
0390 return status;
0391 }
0392
0393 return 0;
0394 }
0395
0396
0397
0398
0399
0400
0401
0402 int
0403 ice_vf_clear_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m)
0404 {
0405 struct ice_hw *hw = &vsi->back->hw;
0406 int status;
0407
0408 if (ice_vf_is_port_vlan_ena(vf))
0409 status = ice_fltr_clear_vsi_promisc(hw, vsi->idx, promisc_m,
0410 ice_vf_get_port_vlan_id(vf));
0411 else if (ice_vsi_has_non_zero_vlans(vsi))
0412 status = ice_fltr_clear_vlan_vsi_promisc(hw, vsi, promisc_m);
0413 else
0414 status = ice_fltr_clear_vsi_promisc(hw, vsi->idx, promisc_m, 0);
0415
0416 if (status && status != -ENOENT) {
0417 dev_err(ice_pf_to_dev(vsi->back), "disable Tx/Rx filter promiscuous mode on VF-%u failed, error: %d\n",
0418 vf->vf_id, status);
0419 return status;
0420 }
0421
0422 return 0;
0423 }
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436 void ice_reset_all_vfs(struct ice_pf *pf)
0437 {
0438 struct device *dev = ice_pf_to_dev(pf);
0439 struct ice_hw *hw = &pf->hw;
0440 struct ice_vf *vf;
0441 unsigned int bkt;
0442
0443
0444 if (!ice_has_vfs(pf))
0445 return;
0446
0447 mutex_lock(&pf->vfs.table_lock);
0448
0449
0450 ice_for_each_vf(pf, bkt, vf)
0451 if (ice_mbx_clear_malvf(&hw->mbx_snapshot, pf->vfs.malvfs,
0452 ICE_MAX_SRIOV_VFS, vf->vf_id))
0453 dev_dbg(dev, "failed to clear malicious VF state for VF %u\n",
0454 vf->vf_id);
0455
0456
0457 if (test_and_set_bit(ICE_VF_DIS, pf->state)) {
0458 mutex_unlock(&pf->vfs.table_lock);
0459 return;
0460 }
0461
0462
0463 ice_for_each_vf(pf, bkt, vf)
0464 ice_trigger_vf_reset(vf, true, true);
0465
0466
0467
0468
0469
0470 ice_for_each_vf(pf, bkt, vf) {
0471 if (!vf->vf_ops->poll_reset_status(vf)) {
0472
0473
0474
0475
0476 dev_warn(dev, "VF %u reset check timeout\n", vf->vf_id);
0477 break;
0478 }
0479 }
0480
0481
0482 ice_for_each_vf(pf, bkt, vf) {
0483 mutex_lock(&vf->cfg_lock);
0484
0485 vf->driver_caps = 0;
0486 ice_vc_set_default_allowlist(vf);
0487
0488 ice_vf_fdir_exit(vf);
0489 ice_vf_fdir_init(vf);
0490
0491
0492
0493 if (vf->ctrl_vsi_idx != ICE_NO_VSI)
0494 ice_vf_ctrl_invalidate_vsi(vf);
0495
0496 ice_vf_pre_vsi_rebuild(vf);
0497 ice_vf_rebuild_vsi(vf);
0498 vf->vf_ops->post_vsi_rebuild(vf);
0499
0500 mutex_unlock(&vf->cfg_lock);
0501 }
0502
0503 if (ice_is_eswitch_mode_switchdev(pf))
0504 if (ice_eswitch_rebuild(pf))
0505 dev_warn(dev, "eswitch rebuild failed\n");
0506
0507 ice_flush(hw);
0508 clear_bit(ICE_VF_DIS, pf->state);
0509
0510 mutex_unlock(&pf->vfs.table_lock);
0511 }
0512
0513
0514
0515
0516
0517 static void ice_notify_vf_reset(struct ice_vf *vf)
0518 {
0519 struct ice_hw *hw = &vf->pf->hw;
0520 struct virtchnl_pf_event pfe;
0521
0522
0523
0524
0525 if ((!test_bit(ICE_VF_STATE_INIT, vf->vf_states) &&
0526 !test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) ||
0527 test_bit(ICE_VF_STATE_DIS, vf->vf_states))
0528 return;
0529
0530 pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
0531 pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
0532 ice_aq_send_msg_to_vf(hw, vf->vf_id, VIRTCHNL_OP_EVENT,
0533 VIRTCHNL_STATUS_SUCCESS, (u8 *)&pfe, sizeof(pfe),
0534 NULL);
0535 }
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551 int ice_reset_vf(struct ice_vf *vf, u32 flags)
0552 {
0553 struct ice_pf *pf = vf->pf;
0554 struct ice_vsi *vsi;
0555 struct device *dev;
0556 struct ice_hw *hw;
0557 int err = 0;
0558 bool rsd;
0559
0560 dev = ice_pf_to_dev(pf);
0561 hw = &pf->hw;
0562
0563 if (flags & ICE_VF_RESET_NOTIFY)
0564 ice_notify_vf_reset(vf);
0565
0566 if (test_bit(ICE_VF_RESETS_DISABLED, pf->state)) {
0567 dev_dbg(dev, "Trying to reset VF %d, but all VF resets are disabled\n",
0568 vf->vf_id);
0569 return 0;
0570 }
0571
0572 if (ice_is_vf_disabled(vf)) {
0573 vsi = ice_get_vf_vsi(vf);
0574 if (!vsi) {
0575 dev_dbg(dev, "VF is already removed\n");
0576 return -EINVAL;
0577 }
0578 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, vf->vf_id);
0579 ice_vsi_stop_all_rx_rings(vsi);
0580 dev_dbg(dev, "VF is already disabled, there is no need for resetting it, telling VM, all is fine %d\n",
0581 vf->vf_id);
0582 return 0;
0583 }
0584
0585 if (flags & ICE_VF_RESET_LOCK)
0586 mutex_lock(&vf->cfg_lock);
0587 else
0588 lockdep_assert_held(&vf->cfg_lock);
0589
0590
0591 set_bit(ICE_VF_STATE_DIS, vf->vf_states);
0592 ice_trigger_vf_reset(vf, flags & ICE_VF_RESET_VFLR, false);
0593
0594 vsi = ice_get_vf_vsi(vf);
0595 if (WARN_ON(!vsi)) {
0596 err = -EIO;
0597 goto out_unlock;
0598 }
0599
0600 ice_dis_vf_qs(vf);
0601
0602
0603
0604
0605 ice_dis_vsi_txq(vsi->port_info, vsi->idx, 0, 0, NULL, NULL,
0606 NULL, vf->vf_ops->reset_type, vf->vf_id, NULL);
0607
0608
0609
0610
0611 rsd = vf->vf_ops->poll_reset_status(vf);
0612
0613
0614
0615
0616 if (!rsd)
0617 dev_warn(dev, "VF reset check timeout on VF %d\n", vf->vf_id);
0618
0619 vf->driver_caps = 0;
0620 ice_vc_set_default_allowlist(vf);
0621
0622
0623
0624
0625 ice_vf_clear_all_promisc_modes(vf, vsi);
0626
0627 ice_eswitch_del_vf_mac_rule(vf);
0628
0629 ice_vf_fdir_exit(vf);
0630 ice_vf_fdir_init(vf);
0631
0632
0633
0634 if (vf->ctrl_vsi_idx != ICE_NO_VSI)
0635 ice_vf_ctrl_vsi_release(vf);
0636
0637 ice_vf_pre_vsi_rebuild(vf);
0638
0639 if (vf->vf_ops->vsi_rebuild(vf)) {
0640 dev_err(dev, "Failed to release and setup the VF%u's VSI\n",
0641 vf->vf_id);
0642 err = -EFAULT;
0643 goto out_unlock;
0644 }
0645
0646 vf->vf_ops->post_vsi_rebuild(vf);
0647 vsi = ice_get_vf_vsi(vf);
0648 if (WARN_ON(!vsi)) {
0649 err = -EINVAL;
0650 goto out_unlock;
0651 }
0652
0653 ice_eswitch_update_repr(vsi);
0654 ice_eswitch_replay_vf_mac_rule(vf);
0655
0656
0657 if (ice_mbx_clear_malvf(&hw->mbx_snapshot, pf->vfs.malvfs,
0658 ICE_MAX_SRIOV_VFS, vf->vf_id))
0659 dev_dbg(dev, "failed to clear malicious VF state for VF %u\n",
0660 vf->vf_id);
0661
0662 out_unlock:
0663 if (flags & ICE_VF_RESET_LOCK)
0664 mutex_unlock(&vf->cfg_lock);
0665
0666 return err;
0667 }
0668
0669
0670
0671
0672
0673 void ice_set_vf_state_qs_dis(struct ice_vf *vf)
0674 {
0675
0676 bitmap_zero(vf->txq_ena, ICE_MAX_RSS_QS_PER_VF);
0677 bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF);
0678 clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
0679 }
0680
0681
0682
0683
0684
0685
0686
0687 void ice_dis_vf_qs(struct ice_vf *vf)
0688 {
0689 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
0690
0691 if (WARN_ON(!vsi))
0692 return;
0693
0694 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, vf->vf_id);
0695 ice_vsi_stop_all_rx_rings(vsi);
0696 ice_set_vf_state_qs_dis(vf);
0697 }
0698
0699
0700
0701
0702
0703 int ice_check_vf_init(struct ice_vf *vf)
0704 {
0705 struct ice_pf *pf = vf->pf;
0706
0707 if (!test_bit(ICE_VF_STATE_INIT, vf->vf_states)) {
0708 dev_err(ice_pf_to_dev(pf), "VF ID: %u in reset. Try again.\n",
0709 vf->vf_id);
0710 return -EBUSY;
0711 }
0712 return 0;
0713 }
0714
0715
0716
0717
0718
0719 struct ice_port_info *ice_vf_get_port_info(struct ice_vf *vf)
0720 {
0721 return vf->pf->hw.port_info;
0722 }
0723
0724
0725
0726
0727
0728
0729
0730
0731 static int ice_cfg_mac_antispoof(struct ice_vsi *vsi, bool enable)
0732 {
0733 struct ice_vsi_ctx *ctx;
0734 int err;
0735
0736 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
0737 if (!ctx)
0738 return -ENOMEM;
0739
0740 ctx->info.sec_flags = vsi->info.sec_flags;
0741 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
0742
0743 if (enable)
0744 ctx->info.sec_flags |= ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF;
0745 else
0746 ctx->info.sec_flags &= ~ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF;
0747
0748 err = ice_update_vsi(&vsi->back->hw, vsi->idx, ctx, NULL);
0749 if (err)
0750 dev_err(ice_pf_to_dev(vsi->back), "Failed to configure Tx MAC anti-spoof %s for VSI %d, error %d\n",
0751 enable ? "ON" : "OFF", vsi->vsi_num, err);
0752 else
0753 vsi->info.sec_flags = ctx->info.sec_flags;
0754
0755 kfree(ctx);
0756
0757 return err;
0758 }
0759
0760
0761
0762
0763
0764 static int ice_vsi_ena_spoofchk(struct ice_vsi *vsi)
0765 {
0766 struct ice_vsi_vlan_ops *vlan_ops;
0767 int err = 0;
0768
0769 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
0770
0771
0772 if (vsi->type != ICE_VSI_VF || ice_vsi_has_non_zero_vlans(vsi)) {
0773 err = vlan_ops->ena_tx_filtering(vsi);
0774 if (err)
0775 return err;
0776 }
0777
0778 return ice_cfg_mac_antispoof(vsi, true);
0779 }
0780
0781
0782
0783
0784
0785 static int ice_vsi_dis_spoofchk(struct ice_vsi *vsi)
0786 {
0787 struct ice_vsi_vlan_ops *vlan_ops;
0788 int err;
0789
0790 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
0791
0792 err = vlan_ops->dis_tx_filtering(vsi);
0793 if (err)
0794 return err;
0795
0796 return ice_cfg_mac_antispoof(vsi, false);
0797 }
0798
0799
0800
0801
0802
0803
0804 int ice_vsi_apply_spoofchk(struct ice_vsi *vsi, bool enable)
0805 {
0806 int err;
0807
0808 if (enable)
0809 err = ice_vsi_ena_spoofchk(vsi);
0810 else
0811 err = ice_vsi_dis_spoofchk(vsi);
0812
0813 return err;
0814 }
0815
0816
0817
0818
0819
0820 bool ice_is_vf_trusted(struct ice_vf *vf)
0821 {
0822 return test_bit(ICE_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
0823 }
0824
0825
0826
0827
0828
0829
0830
0831
0832 bool ice_vf_has_no_qs_ena(struct ice_vf *vf)
0833 {
0834 return (!bitmap_weight(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF) &&
0835 !bitmap_weight(vf->txq_ena, ICE_MAX_RSS_QS_PER_VF));
0836 }
0837
0838
0839
0840
0841
0842 bool ice_is_vf_link_up(struct ice_vf *vf)
0843 {
0844 struct ice_port_info *pi = ice_vf_get_port_info(vf);
0845
0846 if (ice_check_vf_init(vf))
0847 return false;
0848
0849 if (ice_vf_has_no_qs_ena(vf))
0850 return false;
0851 else if (vf->link_forced)
0852 return vf->link_up;
0853 else
0854 return pi->phy.link_info.link_info &
0855 ICE_AQ_LINK_UP;
0856 }
0857
0858
0859
0860
0861
0862 static void ice_vf_set_host_trust_cfg(struct ice_vf *vf)
0863 {
0864 if (vf->trusted)
0865 set_bit(ICE_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
0866 else
0867 clear_bit(ICE_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
0868 }
0869
0870
0871
0872
0873
0874
0875
0876
0877 static int ice_vf_rebuild_host_mac_cfg(struct ice_vf *vf)
0878 {
0879 struct device *dev = ice_pf_to_dev(vf->pf);
0880 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
0881 u8 broadcast[ETH_ALEN];
0882 int status;
0883
0884 if (WARN_ON(!vsi))
0885 return -EINVAL;
0886
0887 if (ice_is_eswitch_mode_switchdev(vf->pf))
0888 return 0;
0889
0890 eth_broadcast_addr(broadcast);
0891 status = ice_fltr_add_mac(vsi, broadcast, ICE_FWD_TO_VSI);
0892 if (status) {
0893 dev_err(dev, "failed to add broadcast MAC filter for VF %u, error %d\n",
0894 vf->vf_id, status);
0895 return status;
0896 }
0897
0898 vf->num_mac++;
0899
0900 if (is_valid_ether_addr(vf->hw_lan_addr.addr)) {
0901 status = ice_fltr_add_mac(vsi, vf->hw_lan_addr.addr,
0902 ICE_FWD_TO_VSI);
0903 if (status) {
0904 dev_err(dev, "failed to add default unicast MAC filter %pM for VF %u, error %d\n",
0905 &vf->hw_lan_addr.addr[0], vf->vf_id,
0906 status);
0907 return status;
0908 }
0909 vf->num_mac++;
0910
0911 ether_addr_copy(vf->dev_lan_addr.addr, vf->hw_lan_addr.addr);
0912 }
0913
0914 return 0;
0915 }
0916
0917
0918
0919
0920
0921
0922
0923
0924
0925 static int ice_vf_rebuild_host_vlan_cfg(struct ice_vf *vf, struct ice_vsi *vsi)
0926 {
0927 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
0928 struct device *dev = ice_pf_to_dev(vf->pf);
0929 int err;
0930
0931 if (ice_vf_is_port_vlan_ena(vf)) {
0932 err = vlan_ops->set_port_vlan(vsi, &vf->port_vlan_info);
0933 if (err) {
0934 dev_err(dev, "failed to configure port VLAN via VSI parameters for VF %u, error %d\n",
0935 vf->vf_id, err);
0936 return err;
0937 }
0938
0939 err = vlan_ops->add_vlan(vsi, &vf->port_vlan_info);
0940 } else {
0941 err = ice_vsi_add_vlan_zero(vsi);
0942 }
0943
0944 if (err) {
0945 dev_err(dev, "failed to add VLAN %u filter for VF %u during VF rebuild, error %d\n",
0946 ice_vf_is_port_vlan_ena(vf) ?
0947 ice_vf_get_port_vlan_id(vf) : 0, vf->vf_id, err);
0948 return err;
0949 }
0950
0951 err = vlan_ops->ena_rx_filtering(vsi);
0952 if (err)
0953 dev_warn(dev, "failed to enable Rx VLAN filtering for VF %d VSI %d during VF rebuild, error %d\n",
0954 vf->vf_id, vsi->idx, err);
0955
0956 return 0;
0957 }
0958
0959
0960
0961
0962
0963
0964
0965
0966 static int ice_vf_rebuild_host_tx_rate_cfg(struct ice_vf *vf)
0967 {
0968 struct device *dev = ice_pf_to_dev(vf->pf);
0969 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
0970 int err;
0971
0972 if (WARN_ON(!vsi))
0973 return -EINVAL;
0974
0975 if (vf->min_tx_rate) {
0976 err = ice_set_min_bw_limit(vsi, (u64)vf->min_tx_rate * 1000);
0977 if (err) {
0978 dev_err(dev, "failed to set min Tx rate to %d Mbps for VF %u, error %d\n",
0979 vf->min_tx_rate, vf->vf_id, err);
0980 return err;
0981 }
0982 }
0983
0984 if (vf->max_tx_rate) {
0985 err = ice_set_max_bw_limit(vsi, (u64)vf->max_tx_rate * 1000);
0986 if (err) {
0987 dev_err(dev, "failed to set max Tx rate to %d Mbps for VF %u, error %d\n",
0988 vf->max_tx_rate, vf->vf_id, err);
0989 return err;
0990 }
0991 }
0992
0993 return 0;
0994 }
0995
0996
0997
0998
0999
1000
1001
1002
1003 static void ice_vf_rebuild_aggregator_node_cfg(struct ice_vsi *vsi)
1004 {
1005 struct ice_pf *pf = vsi->back;
1006 struct device *dev;
1007 int status;
1008
1009 if (!vsi->agg_node)
1010 return;
1011
1012 dev = ice_pf_to_dev(pf);
1013 if (vsi->agg_node->num_vsis == ICE_MAX_VSIS_IN_AGG_NODE) {
1014 dev_dbg(dev,
1015 "agg_id %u already has reached max_num_vsis %u\n",
1016 vsi->agg_node->agg_id, vsi->agg_node->num_vsis);
1017 return;
1018 }
1019
1020 status = ice_move_vsi_to_agg(pf->hw.port_info, vsi->agg_node->agg_id,
1021 vsi->idx, vsi->tc_cfg.ena_tc);
1022 if (status)
1023 dev_dbg(dev, "unable to move VSI idx %u into aggregator %u node",
1024 vsi->idx, vsi->agg_node->agg_id);
1025 else
1026 vsi->agg_node->num_vsis++;
1027 }
1028
1029
1030
1031
1032
1033 void ice_vf_rebuild_host_cfg(struct ice_vf *vf)
1034 {
1035 struct device *dev = ice_pf_to_dev(vf->pf);
1036 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
1037
1038 if (WARN_ON(!vsi))
1039 return;
1040
1041 ice_vf_set_host_trust_cfg(vf);
1042
1043 if (ice_vf_rebuild_host_mac_cfg(vf))
1044 dev_err(dev, "failed to rebuild default MAC configuration for VF %d\n",
1045 vf->vf_id);
1046
1047 if (ice_vf_rebuild_host_vlan_cfg(vf, vsi))
1048 dev_err(dev, "failed to rebuild VLAN configuration for VF %u\n",
1049 vf->vf_id);
1050
1051 if (ice_vf_rebuild_host_tx_rate_cfg(vf))
1052 dev_err(dev, "failed to rebuild Tx rate limiting configuration for VF %u\n",
1053 vf->vf_id);
1054
1055 if (ice_vsi_apply_spoofchk(vsi, vf->spoofchk))
1056 dev_err(dev, "failed to rebuild spoofchk configuration for VF %d\n",
1057 vf->vf_id);
1058
1059
1060 ice_vf_rebuild_aggregator_node_cfg(vsi);
1061 }
1062
1063
1064
1065
1066
1067 void ice_vf_ctrl_invalidate_vsi(struct ice_vf *vf)
1068 {
1069 vf->ctrl_vsi_idx = ICE_NO_VSI;
1070 }
1071
1072
1073
1074
1075
1076 void ice_vf_ctrl_vsi_release(struct ice_vf *vf)
1077 {
1078 ice_vsi_release(vf->pf->vsi[vf->ctrl_vsi_idx]);
1079 ice_vf_ctrl_invalidate_vsi(vf);
1080 }
1081
1082
1083
1084
1085
1086
1087
1088
1089 struct ice_vsi *ice_vf_ctrl_vsi_setup(struct ice_vf *vf)
1090 {
1091 struct ice_port_info *pi = ice_vf_get_port_info(vf);
1092 struct ice_pf *pf = vf->pf;
1093 struct ice_vsi *vsi;
1094
1095 vsi = ice_vsi_setup(pf, pi, ICE_VSI_CTRL, vf, NULL);
1096 if (!vsi) {
1097 dev_err(ice_pf_to_dev(pf), "Failed to create VF control VSI\n");
1098 ice_vf_ctrl_invalidate_vsi(vf);
1099 }
1100
1101 return vsi;
1102 }
1103
1104
1105
1106
1107
1108 void ice_vf_invalidate_vsi(struct ice_vf *vf)
1109 {
1110 vf->lan_vsi_idx = ICE_NO_VSI;
1111 vf->lan_vsi_num = ICE_NO_VSI;
1112 }
1113
1114
1115
1116
1117
1118
1119
1120
1121 void ice_vf_set_initialized(struct ice_vf *vf)
1122 {
1123 ice_set_vf_state_qs_dis(vf);
1124 clear_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states);
1125 clear_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states);
1126 clear_bit(ICE_VF_STATE_DIS, vf->vf_states);
1127 set_bit(ICE_VF_STATE_INIT, vf->vf_states);
1128 memset(&vf->vlan_v2_caps, 0, sizeof(vf->vlan_v2_caps));
1129 }