forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
....@@ -130,17 +130,18 @@
130130 /***********************misc routines*****************************/
131131
132132 /**
133
- * i40e_vc_disable_vf
133
+ * i40e_vc_reset_vf
134134 * @vf: pointer to the VF info
135
- *
136
- * Disable the VF through a SW reset.
135
+ * @notify_vf: notify vf about reset or not
136
+ * Reset VF handler.
137137 **/
138
-static inline void i40e_vc_disable_vf(struct i40e_vf *vf)
138
+static void i40e_vc_reset_vf(struct i40e_vf *vf, bool notify_vf)
139139 {
140140 struct i40e_pf *pf = vf->pf;
141141 int i;
142142
143
- i40e_vc_notify_vf_reset(vf);
143
+ if (notify_vf)
144
+ i40e_vc_notify_vf_reset(vf);
144145
145146 /* We want to ensure that an actual reset occurs initiated after this
146147 * function was called. However, we do not want to wait forever, so
....@@ -158,9 +159,14 @@
158159 usleep_range(10000, 20000);
159160 }
160161
161
- dev_warn(&vf->pf->pdev->dev,
162
- "Failed to initiate reset for VF %d after 200 milliseconds\n",
163
- vf->vf_id);
162
+ if (notify_vf)
163
+ dev_warn(&vf->pf->pdev->dev,
164
+ "Failed to initiate reset for VF %d after 200 milliseconds\n",
165
+ vf->vf_id);
166
+ else
167
+ dev_dbg(&vf->pf->pdev->dev,
168
+ "Failed to initiate reset for VF %d after 200 milliseconds\n",
169
+ vf->vf_id);
164170 }
165171
166172 /**
....@@ -446,7 +452,7 @@
446452 struct virtchnl_iwarp_qv_info *qv_info;
447453 u32 v_idx, i, reg_idx, reg;
448454 u32 next_q_idx, next_q_type;
449
- u32 msix_vf, size;
455
+ u32 msix_vf;
450456 int ret = 0;
451457
452458 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
....@@ -460,11 +466,10 @@
460466 goto err_out;
461467 }
462468
463
- size = sizeof(struct virtchnl_iwarp_qvlist_info) +
464
- (sizeof(struct virtchnl_iwarp_qv_info) *
465
- (qvlist_info->num_vectors - 1));
466469 kfree(vf->qvlist_info);
467
- vf->qvlist_info = kzalloc(size, GFP_KERNEL);
470
+ vf->qvlist_info = kzalloc(struct_size(vf->qvlist_info, qv_info,
471
+ qvlist_info->num_vectors - 1),
472
+ GFP_KERNEL);
468473 if (!vf->qvlist_info) {
469474 ret = -ENOMEM;
470475 goto err_out;
....@@ -476,13 +481,14 @@
476481 qv_info = &qvlist_info->qv_info[i];
477482 if (!qv_info)
478483 continue;
479
- v_idx = qv_info->v_idx;
480484
481485 /* Validate vector id belongs to this vf */
482
- if (!i40e_vc_isvalid_vector_id(vf, v_idx)) {
486
+ if (!i40e_vc_isvalid_vector_id(vf, qv_info->v_idx)) {
483487 ret = -EINVAL;
484488 goto err_free;
485489 }
490
+
491
+ v_idx = qv_info->v_idx;
486492
487493 vf->qvlist_info->qv_info[i] = *qv_info;
488494
....@@ -958,7 +964,6 @@
958964 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
959965 vf->lan_vsi_idx = 0;
960966 vf->lan_vsi_id = 0;
961
- vf->num_mac = 0;
962967 }
963968
964969 /* do the accounting and remove additional ADq VSI's */
....@@ -1111,6 +1116,240 @@
11111116 }
11121117
11131118 /**
1119
+ * __i40e_getnum_vf_vsi_vlan_filters
1120
+ * @vsi: pointer to the vsi
1121
+ *
1122
+ * called to get the number of VLANs offloaded on this VF
1123
+ **/
1124
+static int __i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
1125
+{
1126
+ struct i40e_mac_filter *f;
1127
+ u16 num_vlans = 0, bkt;
1128
+
1129
+ hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
1130
+ if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID)
1131
+ num_vlans++;
1132
+ }
1133
+
1134
+ return num_vlans;
1135
+}
1136
+
1137
+/**
1138
+ * i40e_getnum_vf_vsi_vlan_filters
1139
+ * @vsi: pointer to the vsi
1140
+ *
1141
+ * wrapper for __i40e_getnum_vf_vsi_vlan_filters() with spinlock held
1142
+ **/
1143
+static int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
1144
+{
1145
+ int num_vlans;
1146
+
1147
+ spin_lock_bh(&vsi->mac_filter_hash_lock);
1148
+ num_vlans = __i40e_getnum_vf_vsi_vlan_filters(vsi);
1149
+ spin_unlock_bh(&vsi->mac_filter_hash_lock);
1150
+
1151
+ return num_vlans;
1152
+}
1153
+
1154
+/**
1155
+ * i40e_get_vlan_list_sync
1156
+ * @vsi: pointer to the VSI
1157
+ * @num_vlans: number of VLANs in mac_filter_hash, returned to caller
1158
+ * @vlan_list: list of VLANs present in mac_filter_hash, returned to caller.
1159
+ * This array is allocated here, but has to be freed in caller.
1160
+ *
1161
+ * Called to get number of VLANs and VLAN list present in mac_filter_hash.
1162
+ **/
1163
+static void i40e_get_vlan_list_sync(struct i40e_vsi *vsi, u16 *num_vlans,
1164
+ s16 **vlan_list)
1165
+{
1166
+ struct i40e_mac_filter *f;
1167
+ int i = 0;
1168
+ int bkt;
1169
+
1170
+ spin_lock_bh(&vsi->mac_filter_hash_lock);
1171
+ *num_vlans = __i40e_getnum_vf_vsi_vlan_filters(vsi);
1172
+ *vlan_list = kcalloc(*num_vlans, sizeof(**vlan_list), GFP_ATOMIC);
1173
+ if (!(*vlan_list))
1174
+ goto err;
1175
+
1176
+ hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
1177
+ if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
1178
+ continue;
1179
+ (*vlan_list)[i++] = f->vlan;
1180
+ }
1181
+err:
1182
+ spin_unlock_bh(&vsi->mac_filter_hash_lock);
1183
+}
1184
+
1185
+/**
1186
+ * i40e_set_vsi_promisc
1187
+ * @vf: pointer to the VF struct
1188
+ * @seid: VSI number
1189
+ * @multi_enable: set MAC L2 layer multicast promiscuous enable/disable
1190
+ * for a given VLAN
1191
+ * @unicast_enable: set MAC L2 layer unicast promiscuous enable/disable
1192
+ * for a given VLAN
1193
+ * @vl: List of VLANs - apply filter for given VLANs
1194
+ * @num_vlans: Number of elements in @vl
1195
+ **/
1196
+static i40e_status
1197
+i40e_set_vsi_promisc(struct i40e_vf *vf, u16 seid, bool multi_enable,
1198
+ bool unicast_enable, s16 *vl, u16 num_vlans)
1199
+{
1200
+ i40e_status aq_ret, aq_tmp = 0;
1201
+ struct i40e_pf *pf = vf->pf;
1202
+ struct i40e_hw *hw = &pf->hw;
1203
+ int i;
1204
+
1205
+ /* No VLAN to set promisc on, set on VSI */
1206
+ if (!num_vlans || !vl) {
1207
+ aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, seid,
1208
+ multi_enable,
1209
+ NULL);
1210
+ if (aq_ret) {
1211
+ int aq_err = pf->hw.aq.asq_last_status;
1212
+
1213
+ dev_err(&pf->pdev->dev,
1214
+ "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
1215
+ vf->vf_id,
1216
+ i40e_stat_str(&pf->hw, aq_ret),
1217
+ i40e_aq_str(&pf->hw, aq_err));
1218
+
1219
+ return aq_ret;
1220
+ }
1221
+
1222
+ aq_ret = i40e_aq_set_vsi_unicast_promiscuous(hw, seid,
1223
+ unicast_enable,
1224
+ NULL, true);
1225
+
1226
+ if (aq_ret) {
1227
+ int aq_err = pf->hw.aq.asq_last_status;
1228
+
1229
+ dev_err(&pf->pdev->dev,
1230
+ "VF %d failed to set unicast promiscuous mode err %s aq_err %s\n",
1231
+ vf->vf_id,
1232
+ i40e_stat_str(&pf->hw, aq_ret),
1233
+ i40e_aq_str(&pf->hw, aq_err));
1234
+ }
1235
+
1236
+ return aq_ret;
1237
+ }
1238
+
1239
+ for (i = 0; i < num_vlans; i++) {
1240
+ aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, seid,
1241
+ multi_enable,
1242
+ vl[i], NULL);
1243
+ if (aq_ret) {
1244
+ int aq_err = pf->hw.aq.asq_last_status;
1245
+
1246
+ dev_err(&pf->pdev->dev,
1247
+ "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
1248
+ vf->vf_id,
1249
+ i40e_stat_str(&pf->hw, aq_ret),
1250
+ i40e_aq_str(&pf->hw, aq_err));
1251
+
1252
+ if (!aq_tmp)
1253
+ aq_tmp = aq_ret;
1254
+ }
1255
+
1256
+ aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, seid,
1257
+ unicast_enable,
1258
+ vl[i], NULL);
1259
+ if (aq_ret) {
1260
+ int aq_err = pf->hw.aq.asq_last_status;
1261
+
1262
+ dev_err(&pf->pdev->dev,
1263
+ "VF %d failed to set unicast promiscuous mode err %s aq_err %s\n",
1264
+ vf->vf_id,
1265
+ i40e_stat_str(&pf->hw, aq_ret),
1266
+ i40e_aq_str(&pf->hw, aq_err));
1267
+
1268
+ if (!aq_tmp)
1269
+ aq_tmp = aq_ret;
1270
+ }
1271
+ }
1272
+
1273
+ if (aq_tmp)
1274
+ aq_ret = aq_tmp;
1275
+
1276
+ return aq_ret;
1277
+}
1278
+
1279
+/**
1280
+ * i40e_config_vf_promiscuous_mode
1281
+ * @vf: pointer to the VF info
1282
+ * @vsi_id: VSI id
1283
+ * @allmulti: set MAC L2 layer multicast promiscuous enable/disable
1284
+ * @alluni: set MAC L2 layer unicast promiscuous enable/disable
1285
+ *
1286
+ * Called from the VF to configure the promiscuous mode of
1287
+ * VF vsis and from the VF reset path to reset promiscuous mode.
1288
+ **/
1289
+static i40e_status i40e_config_vf_promiscuous_mode(struct i40e_vf *vf,
1290
+ u16 vsi_id,
1291
+ bool allmulti,
1292
+ bool alluni)
1293
+{
1294
+ i40e_status aq_ret = I40E_SUCCESS;
1295
+ struct i40e_pf *pf = vf->pf;
1296
+ struct i40e_vsi *vsi;
1297
+ u16 num_vlans;
1298
+ s16 *vl;
1299
+
1300
+ vsi = i40e_find_vsi_from_id(pf, vsi_id);
1301
+ if (!i40e_vc_isvalid_vsi_id(vf, vsi_id) || !vsi)
1302
+ return I40E_ERR_PARAM;
1303
+
1304
+ if (vf->port_vlan_id) {
1305
+ aq_ret = i40e_set_vsi_promisc(vf, vsi->seid, allmulti,
1306
+ alluni, &vf->port_vlan_id, 1);
1307
+ return aq_ret;
1308
+ } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
1309
+ i40e_get_vlan_list_sync(vsi, &num_vlans, &vl);
1310
+
1311
+ if (!vl)
1312
+ return I40E_ERR_NO_MEMORY;
1313
+
1314
+ aq_ret = i40e_set_vsi_promisc(vf, vsi->seid, allmulti, alluni,
1315
+ vl, num_vlans);
1316
+ kfree(vl);
1317
+ return aq_ret;
1318
+ }
1319
+
1320
+ /* no VLANs to set on, set on VSI */
1321
+ aq_ret = i40e_set_vsi_promisc(vf, vsi->seid, allmulti, alluni,
1322
+ NULL, 0);
1323
+ return aq_ret;
1324
+}
1325
+
1326
+/**
1327
+ * i40e_sync_vfr_reset
1328
+ * @hw: pointer to hw struct
1329
+ * @vf_id: VF identifier
1330
+ *
1331
+ * Before trigger hardware reset, we need to know if no other process has
1332
+ * reserved the hardware for any reset operations. This check is done by
1333
+ * examining the status of the RSTAT1 register used to signal the reset.
1334
+ **/
1335
+static int i40e_sync_vfr_reset(struct i40e_hw *hw, int vf_id)
1336
+{
1337
+ u32 reg;
1338
+ int i;
1339
+
1340
+ for (i = 0; i < I40E_VFR_WAIT_COUNT; i++) {
1341
+ reg = rd32(hw, I40E_VFINT_ICR0_ENA(vf_id)) &
1342
+ I40E_VFINT_ICR0_ADMINQ_MASK;
1343
+ if (reg)
1344
+ return 0;
1345
+
1346
+ usleep_range(100, 200);
1347
+ }
1348
+
1349
+ return -EAGAIN;
1350
+}
1351
+
1352
+/**
11141353 * i40e_trigger_vf_reset
11151354 * @vf: pointer to the VF structure
11161355 * @flr: VFLR was issued or not
....@@ -1124,9 +1363,11 @@
11241363 struct i40e_pf *pf = vf->pf;
11251364 struct i40e_hw *hw = &pf->hw;
11261365 u32 reg, reg_idx, bit_idx;
1366
+ bool vf_active;
1367
+ u32 radq;
11271368
11281369 /* warn the VF */
1129
- clear_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
1370
+ vf_active = test_and_clear_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
11301371
11311372 /* Disable VF's configuration API during reset. The flag is re-enabled
11321373 * in i40e_alloc_vf_res(), when it's safe again to access VF's VSI.
....@@ -1140,7 +1381,19 @@
11401381 * just need to clean up, so don't hit the VFRTRIG register.
11411382 */
11421383 if (!flr) {
1143
- /* reset VF using VPGEN_VFRTRIG reg */
1384
+ /* Sync VFR reset before trigger next one */
1385
+ radq = rd32(hw, I40E_VFINT_ICR0_ENA(vf->vf_id)) &
1386
+ I40E_VFINT_ICR0_ADMINQ_MASK;
1387
+ if (vf_active && !radq)
1388
+ /* waiting for finish reset by virtual driver */
1389
+ if (i40e_sync_vfr_reset(hw, vf->vf_id))
1390
+ dev_info(&pf->pdev->dev,
1391
+ "Reset VF %d never finished\n",
1392
+ vf->vf_id);
1393
+
1394
+ /* Reset VF using VPGEN_VFRTRIG reg. It is also setting
1395
+ * in progress state in rstat1 register.
1396
+ */
11441397 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
11451398 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
11461399 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
....@@ -1170,6 +1423,9 @@
11701423 struct i40e_pf *pf = vf->pf;
11711424 struct i40e_hw *hw = &pf->hw;
11721425 u32 reg;
1426
+
1427
+ /* disable promisc modes in case they were enabled */
1428
+ i40e_config_vf_promiscuous_mode(vf, vf->lan_vsi_id, false, false);
11731429
11741430 /* free VF resources to begin resetting the VSI state */
11751431 i40e_free_vf_res(vf);
....@@ -1227,10 +1483,12 @@
12271483 if (test_bit(__I40E_VF_RESETS_DISABLED, pf->state))
12281484 return true;
12291485
1230
- /* If the VFs have been disabled, this means something else is
1231
- * resetting the VF, so we shouldn't continue.
1232
- */
1233
- if (test_and_set_bit(__I40E_VF_DISABLE, pf->state))
1486
+ /* Bail out if VFs are disabled. */
1487
+ if (test_bit(__I40E_VF_DISABLE, pf->state))
1488
+ return true;
1489
+
1490
+ /* If VF is being reset already we don't need to continue. */
1491
+ if (test_and_set_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
12341492 return true;
12351493
12361494 i40e_trigger_vf_reset(vf, flr);
....@@ -1267,7 +1525,8 @@
12671525 i40e_cleanup_reset_vf(vf);
12681526
12691527 i40e_flush(hw);
1270
- clear_bit(__I40E_VF_DISABLE, pf->state);
1528
+ usleep_range(20000, 40000);
1529
+ clear_bit(I40E_VF_STATE_RESETTING, &vf->vf_states);
12711530
12721531 return true;
12731532 }
....@@ -1300,8 +1559,12 @@
13001559 return false;
13011560
13021561 /* Begin reset on all VFs at once */
1303
- for (v = 0; v < pf->num_alloc_vfs; v++)
1304
- i40e_trigger_vf_reset(&pf->vf[v], flr);
1562
+ for (v = 0; v < pf->num_alloc_vfs; v++) {
1563
+ vf = &pf->vf[v];
1564
+ /* If VF is being reset no need to trigger reset again */
1565
+ if (!test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
1566
+ i40e_trigger_vf_reset(&pf->vf[v], flr);
1567
+ }
13051568
13061569 /* HW requires some time to make sure it can flush the FIFO for a VF
13071570 * when it resets it. Poll the VPGEN_VFRSTAT register for each VF in
....@@ -1317,9 +1580,11 @@
13171580 */
13181581 while (v < pf->num_alloc_vfs) {
13191582 vf = &pf->vf[v];
1320
- reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
1321
- if (!(reg & I40E_VPGEN_VFRSTAT_VFRD_MASK))
1322
- break;
1583
+ if (!test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states)) {
1584
+ reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
1585
+ if (!(reg & I40E_VPGEN_VFRSTAT_VFRD_MASK))
1586
+ break;
1587
+ }
13231588
13241589 /* If the current VF has finished resetting, move on
13251590 * to the next VF in sequence.
....@@ -1347,6 +1612,10 @@
13471612 if (pf->vf[v].lan_vsi_idx == 0)
13481613 continue;
13491614
1615
+ /* If VF is reset in another thread just continue */
1616
+ if (test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
1617
+ continue;
1618
+
13501619 i40e_vsi_stop_rings_no_wait(pf->vsi[pf->vf[v].lan_vsi_idx]);
13511620 }
13521621
....@@ -1358,6 +1627,10 @@
13581627 if (pf->vf[v].lan_vsi_idx == 0)
13591628 continue;
13601629
1630
+ /* If VF is reset in another thread just continue */
1631
+ if (test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
1632
+ continue;
1633
+
13611634 i40e_vsi_wait_queues_disabled(pf->vsi[pf->vf[v].lan_vsi_idx]);
13621635 }
13631636
....@@ -1367,10 +1640,16 @@
13671640 mdelay(50);
13681641
13691642 /* Finish the reset on each VF */
1370
- for (v = 0; v < pf->num_alloc_vfs; v++)
1643
+ for (v = 0; v < pf->num_alloc_vfs; v++) {
1644
+ /* If VF is reset in another thread just continue */
1645
+ if (test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
1646
+ continue;
1647
+
13711648 i40e_cleanup_reset_vf(&pf->vf[v]);
1649
+ }
13721650
13731651 i40e_flush(hw);
1652
+ usleep_range(20000, 40000);
13741653 clear_bit(__I40E_VF_DISABLE, pf->state);
13751654
13761655 return true;
....@@ -1575,13 +1854,20 @@
15751854 int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
15761855 {
15771856 struct i40e_pf *pf = pci_get_drvdata(pdev);
1857
+ int ret = 0;
1858
+
1859
+ if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
1860
+ dev_warn(&pdev->dev, "Unable to configure VFs, other operation is pending.\n");
1861
+ return -EAGAIN;
1862
+ }
15781863
15791864 if (num_vfs) {
15801865 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
15811866 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
15821867 i40e_do_reset_safe(pf, I40E_PF_RESET_AND_REBUILD_FLAG);
15831868 }
1584
- return i40e_pci_sriov_enable(pdev, num_vfs);
1869
+ ret = i40e_pci_sriov_enable(pdev, num_vfs);
1870
+ goto sriov_configure_out;
15851871 }
15861872
15871873 if (!pci_vfs_assigned(pf->pdev)) {
....@@ -1590,9 +1876,12 @@
15901876 i40e_do_reset_safe(pf, I40E_PF_RESET_AND_REBUILD_FLAG);
15911877 } else {
15921878 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1593
- return -EINVAL;
1879
+ ret = -EINVAL;
1880
+ goto sriov_configure_out;
15941881 }
1595
- return 0;
1882
+sriov_configure_out:
1883
+ clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
1884
+ return ret;
15961885 }
15971886
15981887 /***********************virtual channel routines******************/
....@@ -1623,25 +1912,6 @@
16231912 hw = &pf->hw;
16241913 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
16251914
1626
- /* single place to detect unsuccessful return values */
1627
- if (v_retval) {
1628
- vf->num_invalid_msgs++;
1629
- dev_info(&pf->pdev->dev, "VF %d failed opcode %d, retval: %d\n",
1630
- vf->vf_id, v_opcode, v_retval);
1631
- if (vf->num_invalid_msgs >
1632
- I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1633
- dev_err(&pf->pdev->dev,
1634
- "Number of invalid messages exceeded for VF %d\n",
1635
- vf->vf_id);
1636
- dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1637
- set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
1638
- }
1639
- } else {
1640
- vf->num_valid_msgs++;
1641
- /* reset the invalid counter, if a valid message is received. */
1642
- vf->num_invalid_msgs = 0;
1643
- }
1644
-
16451915 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
16461916 msg, msglen, NULL);
16471917 if (aq_ret) {
....@@ -1667,6 +1937,32 @@
16671937 i40e_status retval)
16681938 {
16691939 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1940
+}
1941
+
1942
+/**
1943
+ * i40e_sync_vf_state
1944
+ * @vf: pointer to the VF info
1945
+ * @state: VF state
1946
+ *
1947
+ * Called from a VF message to synchronize the service with a potential
1948
+ * VF reset state
1949
+ **/
1950
+static bool i40e_sync_vf_state(struct i40e_vf *vf, enum i40e_vf_states state)
1951
+{
1952
+ int i;
1953
+
1954
+ /* When handling some messages, it needs VF state to be set.
1955
+ * It is possible that this flag is cleared during VF reset,
1956
+ * so there is a need to wait until the end of the reset to
1957
+ * handle the request message correctly.
1958
+ */
1959
+ for (i = 0; i < I40E_VF_STATE_WAIT_COUNT; i++) {
1960
+ if (test_bit(state, &vf->vf_states))
1961
+ return true;
1962
+ usleep_range(10000, 20000);
1963
+ }
1964
+
1965
+ return test_bit(state, &vf->vf_states);
16701966 }
16711967
16721968 /**
....@@ -1713,6 +2009,25 @@
17132009 }
17142010
17152011 /**
2012
+ * i40e_vc_get_max_frame_size
2013
+ * @vf: pointer to the VF
2014
+ *
2015
+ * Max frame size is determined based on the current port's max frame size and
2016
+ * whether a port VLAN is configured on this VF. The VF is not aware whether
2017
+ * it's in a port VLAN so the PF needs to account for this in max frame size
2018
+ * checks and sending the max frame size to the VF.
2019
+ **/
2020
+static u16 i40e_vc_get_max_frame_size(struct i40e_vf *vf)
2021
+{
2022
+ u16 max_frame_size = vf->pf->hw.phy.link_info.max_frame_size;
2023
+
2024
+ if (vf->port_vlan_id)
2025
+ max_frame_size -= VLAN_HLEN;
2026
+
2027
+ return max_frame_size;
2028
+}
2029
+
2030
+/**
17162031 * i40e_vc_get_vf_resources_msg
17172032 * @vf: pointer to the VF info
17182033 * @msg: pointer to the msg buffer
....@@ -1726,17 +2041,15 @@
17262041 i40e_status aq_ret = 0;
17272042 struct i40e_vsi *vsi;
17282043 int num_vsis = 1;
1729
- int len = 0;
2044
+ size_t len = 0;
17302045 int ret;
17312046
1732
- if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
2047
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_INIT)) {
17332048 aq_ret = I40E_ERR_PARAM;
17342049 goto err;
17352050 }
17362051
1737
- len = (sizeof(struct virtchnl_vf_resource) +
1738
- sizeof(struct virtchnl_vsi_resource) * num_vsis);
1739
-
2052
+ len = struct_size(vfres, vsi_res, num_vsis);
17402053 vfres = kzalloc(len, GFP_KERNEL);
17412054 if (!vfres) {
17422055 aq_ret = I40E_ERR_NO_MEMORY;
....@@ -1814,6 +2127,7 @@
18142127 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
18152128 vfres->rss_key_size = I40E_HKEY_ARRAY_SIZE;
18162129 vfres->rss_lut_size = I40E_VF_HLUT_ARRAY_SIZE;
2130
+ vfres->max_mtu = i40e_vc_get_max_frame_size(vf);
18172131
18182132 if (vf->lan_vsi_idx) {
18192133 vfres->vsi_res[0].vsi_id = vf->lan_vsi_id;
....@@ -1837,179 +2151,84 @@
18372151 }
18382152
18392153 /**
1840
- * i40e_vc_reset_vf_msg
1841
- * @vf: pointer to the VF info
1842
- *
1843
- * called from the VF to reset itself,
1844
- * unlike other virtchnl messages, PF driver
1845
- * doesn't send the response back to the VF
1846
- **/
1847
-static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
1848
-{
1849
- if (test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
1850
- i40e_reset_vf(vf, false);
1851
-}
1852
-
1853
-/**
1854
- * i40e_getnum_vf_vsi_vlan_filters
1855
- * @vsi: pointer to the vsi
1856
- *
1857
- * called to get the number of VLANs offloaded on this VF
1858
- **/
1859
-static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
1860
-{
1861
- struct i40e_mac_filter *f;
1862
- int num_vlans = 0, bkt;
1863
-
1864
- hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
1865
- if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID)
1866
- num_vlans++;
1867
- }
1868
-
1869
- return num_vlans;
1870
-}
1871
-
1872
-/**
18732154 * i40e_vc_config_promiscuous_mode_msg
18742155 * @vf: pointer to the VF info
18752156 * @msg: pointer to the msg buffer
1876
- * @msglen: msg length
18772157 *
18782158 * called from the VF to configure the promiscuous mode of
18792159 * VF vsis
18802160 **/
1881
-static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1882
- u8 *msg, u16 msglen)
2161
+static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf, u8 *msg)
18832162 {
18842163 struct virtchnl_promisc_info *info =
18852164 (struct virtchnl_promisc_info *)msg;
18862165 struct i40e_pf *pf = vf->pf;
1887
- struct i40e_hw *hw = &pf->hw;
1888
- struct i40e_mac_filter *f;
18892166 i40e_status aq_ret = 0;
18902167 bool allmulti = false;
1891
- struct i40e_vsi *vsi;
18922168 bool alluni = false;
1893
- int aq_err = 0;
1894
- int bkt;
18952169
1896
- vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
1897
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
1898
- !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1899
- !vsi) {
2170
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
19002171 aq_ret = I40E_ERR_PARAM;
1901
- goto error_param;
2172
+ goto err_out;
19022173 }
19032174 if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
19042175 dev_err(&pf->pdev->dev,
19052176 "Unprivileged VF %d is attempting to configure promiscuous mode\n",
19062177 vf->vf_id);
1907
- /* Lie to the VF on purpose. */
2178
+
2179
+ /* Lie to the VF on purpose, because this is an error we can
2180
+ * ignore. Unprivileged VF is not a virtual channel error.
2181
+ */
19082182 aq_ret = 0;
1909
- goto error_param;
2183
+ goto err_out;
19102184 }
2185
+
2186
+ if (info->flags > I40E_MAX_VF_PROMISC_FLAGS) {
2187
+ aq_ret = I40E_ERR_PARAM;
2188
+ goto err_out;
2189
+ }
2190
+
2191
+ if (!i40e_vc_isvalid_vsi_id(vf, info->vsi_id)) {
2192
+ aq_ret = I40E_ERR_PARAM;
2193
+ goto err_out;
2194
+ }
2195
+
19112196 /* Multicast promiscuous handling*/
19122197 if (info->flags & FLAG_VF_MULTICAST_PROMISC)
19132198 allmulti = true;
19142199
1915
- if (vf->port_vlan_id) {
1916
- aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, vsi->seid,
1917
- allmulti,
1918
- vf->port_vlan_id,
1919
- NULL);
1920
- } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
1921
- hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
1922
- if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
1923
- continue;
1924
- aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw,
1925
- vsi->seid,
1926
- allmulti,
1927
- f->vlan,
1928
- NULL);
1929
- aq_err = pf->hw.aq.asq_last_status;
1930
- if (aq_ret) {
1931
- dev_err(&pf->pdev->dev,
1932
- "Could not add VLAN %d to multicast promiscuous domain err %s aq_err %s\n",
1933
- f->vlan,
1934
- i40e_stat_str(&pf->hw, aq_ret),
1935
- i40e_aq_str(&pf->hw, aq_err));
1936
- break;
1937
- }
1938
- }
1939
- } else {
1940
- aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1941
- allmulti, NULL);
1942
- aq_err = pf->hw.aq.asq_last_status;
1943
- if (aq_ret) {
1944
- dev_err(&pf->pdev->dev,
1945
- "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
1946
- vf->vf_id,
1947
- i40e_stat_str(&pf->hw, aq_ret),
1948
- i40e_aq_str(&pf->hw, aq_err));
1949
- goto error_param;
1950
- }
1951
- }
1952
-
1953
- if (!aq_ret) {
1954
- dev_info(&pf->pdev->dev,
1955
- "VF %d successfully set multicast promiscuous mode\n",
1956
- vf->vf_id);
1957
- if (allmulti)
1958
- set_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states);
1959
- else
1960
- clear_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states);
1961
- }
1962
-
19632200 if (info->flags & FLAG_VF_UNICAST_PROMISC)
19642201 alluni = true;
1965
- if (vf->port_vlan_id) {
1966
- aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, vsi->seid,
1967
- alluni,
1968
- vf->port_vlan_id,
1969
- NULL);
1970
- } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
1971
- hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
1972
- if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
1973
- continue;
1974
- aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw,
1975
- vsi->seid,
1976
- alluni,
1977
- f->vlan,
1978
- NULL);
1979
- aq_err = pf->hw.aq.asq_last_status;
1980
- if (aq_ret)
1981
- dev_err(&pf->pdev->dev,
1982
- "Could not add VLAN %d to Unicast promiscuous domain err %s aq_err %s\n",
1983
- f->vlan,
1984
- i40e_stat_str(&pf->hw, aq_ret),
1985
- i40e_aq_str(&pf->hw, aq_err));
1986
- }
1987
- } else {
1988
- aq_ret = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1989
- alluni, NULL,
1990
- true);
1991
- aq_err = pf->hw.aq.asq_last_status;
1992
- if (aq_ret) {
1993
- dev_err(&pf->pdev->dev,
1994
- "VF %d failed to set unicast promiscuous mode %8.8x err %s aq_err %s\n",
1995
- vf->vf_id, info->flags,
1996
- i40e_stat_str(&pf->hw, aq_ret),
1997
- i40e_aq_str(&pf->hw, aq_err));
1998
- goto error_param;
1999
- }
2000
- }
2202
+ aq_ret = i40e_config_vf_promiscuous_mode(vf, info->vsi_id, allmulti,
2203
+ alluni);
2204
+ if (aq_ret)
2205
+ goto err_out;
20012206
2002
- if (!aq_ret) {
2207
+ if (allmulti) {
2208
+ if (!test_and_set_bit(I40E_VF_STATE_MC_PROMISC,
2209
+ &vf->vf_states))
2210
+ dev_info(&pf->pdev->dev,
2211
+ "VF %d successfully set multicast promiscuous mode\n",
2212
+ vf->vf_id);
2213
+ } else if (test_and_clear_bit(I40E_VF_STATE_MC_PROMISC,
2214
+ &vf->vf_states))
20032215 dev_info(&pf->pdev->dev,
2004
- "VF %d successfully set unicast promiscuous mode\n",
2216
+ "VF %d successfully unset multicast promiscuous mode\n",
20052217 vf->vf_id);
2006
- if (alluni)
2007
- set_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states);
2008
- else
2009
- clear_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states);
2010
- }
20112218
2012
-error_param:
2219
+ if (alluni) {
2220
+ if (!test_and_set_bit(I40E_VF_STATE_UC_PROMISC,
2221
+ &vf->vf_states))
2222
+ dev_info(&pf->pdev->dev,
2223
+ "VF %d successfully set unicast promiscuous mode\n",
2224
+ vf->vf_id);
2225
+ } else if (test_and_clear_bit(I40E_VF_STATE_UC_PROMISC,
2226
+ &vf->vf_states))
2227
+ dev_info(&pf->pdev->dev,
2228
+ "VF %d successfully unset unicast promiscuous mode\n",
2229
+ vf->vf_id);
2230
+
2231
+err_out:
20132232 /* send the response to the VF */
20142233 return i40e_vc_send_resp_to_vf(vf,
20152234 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
....@@ -2020,37 +2239,58 @@
20202239 * i40e_vc_config_queues_msg
20212240 * @vf: pointer to the VF info
20222241 * @msg: pointer to the msg buffer
2023
- * @msglen: msg length
20242242 *
20252243 * called from the VF to configure the rx/tx
20262244 * queues
20272245 **/
2028
-static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2246
+static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg)
20292247 {
20302248 struct virtchnl_vsi_queue_config_info *qci =
20312249 (struct virtchnl_vsi_queue_config_info *)msg;
20322250 struct virtchnl_queue_pair_info *qpi;
2033
- struct i40e_pf *pf = vf->pf;
20342251 u16 vsi_id, vsi_queue_id = 0;
2252
+ struct i40e_pf *pf = vf->pf;
20352253 i40e_status aq_ret = 0;
20362254 int i, j = 0, idx = 0;
2255
+ struct i40e_vsi *vsi;
2256
+ u16 num_qps_all = 0;
2257
+
2258
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
2259
+ aq_ret = I40E_ERR_PARAM;
2260
+ goto error_param;
2261
+ }
2262
+
2263
+ if (!i40e_vc_isvalid_vsi_id(vf, qci->vsi_id)) {
2264
+ aq_ret = I40E_ERR_PARAM;
2265
+ goto error_param;
2266
+ }
2267
+
2268
+ if (qci->num_queue_pairs > I40E_MAX_VF_QUEUES) {
2269
+ aq_ret = I40E_ERR_PARAM;
2270
+ goto error_param;
2271
+ }
2272
+
2273
+ if (vf->adq_enabled) {
2274
+ for (i = 0; i < vf->num_tc; i++)
2275
+ num_qps_all += vf->ch[i].num_qps;
2276
+ if (num_qps_all != qci->num_queue_pairs) {
2277
+ aq_ret = I40E_ERR_PARAM;
2278
+ goto error_param;
2279
+ }
2280
+ }
20372281
20382282 vsi_id = qci->vsi_id;
2039
-
2040
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2041
- aq_ret = I40E_ERR_PARAM;
2042
- goto error_param;
2043
- }
2044
-
2045
- if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2046
- aq_ret = I40E_ERR_PARAM;
2047
- goto error_param;
2048
- }
20492283
20502284 for (i = 0; i < qci->num_queue_pairs; i++) {
20512285 qpi = &qci->qpair[i];
20522286
20532287 if (!vf->adq_enabled) {
2288
+ if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
2289
+ qpi->txq.queue_id)) {
2290
+ aq_ret = I40E_ERR_PARAM;
2291
+ goto error_param;
2292
+ }
2293
+
20542294 vsi_queue_id = qpi->txq.queue_id;
20552295
20562296 if (qpi->txq.vsi_id != qci->vsi_id ||
....@@ -2061,9 +2301,12 @@
20612301 }
20622302 }
20632303
2064
- if (!i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
2065
- aq_ret = I40E_ERR_PARAM;
2066
- goto error_param;
2304
+ if (vf->adq_enabled) {
2305
+ if (idx >= ARRAY_SIZE(vf->ch)) {
2306
+ aq_ret = I40E_ERR_NO_AVAILABLE_VSI;
2307
+ goto error_param;
2308
+ }
2309
+ vsi_id = vf->ch[idx].vsi_id;
20672310 }
20682311
20692312 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
....@@ -2078,8 +2321,12 @@
20782321 * VF does not know about these additional VSIs and all
20792322 * it cares is about its own queues. PF configures these queues
20802323 * to its appropriate VSIs based on TC mapping
2081
- **/
2324
+ */
20822325 if (vf->adq_enabled) {
2326
+ if (idx >= ARRAY_SIZE(vf->ch)) {
2327
+ aq_ret = I40E_ERR_NO_AVAILABLE_VSI;
2328
+ goto error_param;
2329
+ }
20832330 if (j == (vf->ch[idx].num_qps - 1)) {
20842331 idx++;
20852332 j = 0; /* resetting the queue count */
....@@ -2088,7 +2335,6 @@
20882335 j++;
20892336 vsi_queue_id++;
20902337 }
2091
- vsi_id = vf->ch[idx].vsi_id;
20922338 }
20932339 }
20942340 /* set vsi num_queue_pairs in use to num configured by VF */
....@@ -2096,9 +2342,15 @@
20962342 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs =
20972343 qci->num_queue_pairs;
20982344 } else {
2099
- for (i = 0; i < vf->num_tc; i++)
2100
- pf->vsi[vf->ch[i].vsi_idx]->num_queue_pairs =
2101
- vf->ch[i].num_qps;
2345
+ for (i = 0; i < vf->num_tc; i++) {
2346
+ vsi = pf->vsi[vf->ch[i].vsi_idx];
2347
+ vsi->num_queue_pairs = vf->ch[i].num_qps;
2348
+
2349
+ if (i40e_update_adq_vsi_queues(vsi, i)) {
2350
+ aq_ret = I40E_ERR_CONFIG;
2351
+ goto error_param;
2352
+ }
2353
+ }
21022354 }
21032355
21042356 error_param:
....@@ -2108,7 +2360,8 @@
21082360 }
21092361
21102362 /**
2111
- * i40e_validate_queue_map
2363
+ * i40e_validate_queue_map - check queue map is valid
2364
+ * @vf: the VF structure pointer
21122365 * @vsi_id: vsi id
21132366 * @queuemap: Tx or Rx queue map
21142367 *
....@@ -2138,35 +2391,39 @@
21382391 * i40e_vc_config_irq_map_msg
21392392 * @vf: pointer to the VF info
21402393 * @msg: pointer to the msg buffer
2141
- * @msglen: msg length
21422394 *
21432395 * called from the VF to configure the irq to
21442396 * queue map
21452397 **/
2146
-static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2398
+static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg)
21472399 {
21482400 struct virtchnl_irq_map_info *irqmap_info =
21492401 (struct virtchnl_irq_map_info *)msg;
21502402 struct virtchnl_vector_map *map;
2151
- u16 vsi_id, vector_id;
2403
+ u16 vsi_id;
21522404 i40e_status aq_ret = 0;
21532405 int i;
21542406
2155
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2407
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
2408
+ aq_ret = I40E_ERR_PARAM;
2409
+ goto error_param;
2410
+ }
2411
+
2412
+ if (irqmap_info->num_vectors >
2413
+ vf->pf->hw.func_caps.num_msix_vectors_vf) {
21562414 aq_ret = I40E_ERR_PARAM;
21572415 goto error_param;
21582416 }
21592417
21602418 for (i = 0; i < irqmap_info->num_vectors; i++) {
21612419 map = &irqmap_info->vecmap[i];
2162
- vector_id = map->vector_id;
2163
- vsi_id = map->vsi_id;
21642420 /* validate msg params */
2165
- if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
2166
- !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2421
+ if (!i40e_vc_isvalid_vector_id(vf, map->vector_id) ||
2422
+ !i40e_vc_isvalid_vsi_id(vf, map->vsi_id)) {
21672423 aq_ret = I40E_ERR_PARAM;
21682424 goto error_param;
21692425 }
2426
+ vsi_id = map->vsi_id;
21702427
21712428 if (i40e_validate_queue_map(vf, vsi_id, map->rxq_map)) {
21722429 aq_ret = I40E_ERR_PARAM;
....@@ -2232,19 +2489,33 @@
22322489 }
22332490
22342491 /**
2492
+ * i40e_vc_validate_vqs_bitmaps - validate Rx/Tx queue bitmaps from VIRTHCHNL
2493
+ * @vqs: virtchnl_queue_select structure containing bitmaps to validate
2494
+ *
2495
+ * Returns true if validation was successful, else false.
2496
+ */
2497
+static bool i40e_vc_validate_vqs_bitmaps(struct virtchnl_queue_select *vqs)
2498
+{
2499
+ if ((!vqs->rx_queues && !vqs->tx_queues) ||
2500
+ vqs->rx_queues >= BIT(I40E_MAX_VF_QUEUES) ||
2501
+ vqs->tx_queues >= BIT(I40E_MAX_VF_QUEUES))
2502
+ return false;
2503
+
2504
+ return true;
2505
+}
2506
+
2507
+/**
22352508 * i40e_vc_enable_queues_msg
22362509 * @vf: pointer to the VF info
22372510 * @msg: pointer to the msg buffer
2238
- * @msglen: msg length
22392511 *
22402512 * called from the VF to enable all or specific queue(s)
22412513 **/
2242
-static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2514
+static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg)
22432515 {
22442516 struct virtchnl_queue_select *vqs =
22452517 (struct virtchnl_queue_select *)msg;
22462518 struct i40e_pf *pf = vf->pf;
2247
- u16 vsi_id = vqs->vsi_id;
22482519 i40e_status aq_ret = 0;
22492520 int i;
22502521
....@@ -2253,12 +2524,12 @@
22532524 goto error_param;
22542525 }
22552526
2256
- if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2527
+ if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
22572528 aq_ret = I40E_ERR_PARAM;
22582529 goto error_param;
22592530 }
22602531
2261
- if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
2532
+ if (!i40e_vc_validate_vqs_bitmaps(vqs)) {
22622533 aq_ret = I40E_ERR_PARAM;
22632534 goto error_param;
22642535 }
....@@ -2294,19 +2565,18 @@
22942565 * i40e_vc_disable_queues_msg
22952566 * @vf: pointer to the VF info
22962567 * @msg: pointer to the msg buffer
2297
- * @msglen: msg length
22982568 *
22992569 * called from the VF to disable all or specific
23002570 * queue(s)
23012571 **/
2302
-static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2572
+static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg)
23032573 {
23042574 struct virtchnl_queue_select *vqs =
23052575 (struct virtchnl_queue_select *)msg;
23062576 struct i40e_pf *pf = vf->pf;
23072577 i40e_status aq_ret = 0;
23082578
2309
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2579
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
23102580 aq_ret = I40E_ERR_PARAM;
23112581 goto error_param;
23122582 }
....@@ -2316,7 +2586,7 @@
23162586 goto error_param;
23172587 }
23182588
2319
- if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
2589
+ if (!i40e_vc_validate_vqs_bitmaps(vqs)) {
23202590 aq_ret = I40E_ERR_PARAM;
23212591 goto error_param;
23222592 }
....@@ -2395,29 +2665,24 @@
23952665 * i40e_vc_request_queues_msg
23962666 * @vf: pointer to the VF info
23972667 * @msg: pointer to the msg buffer
2398
- * @msglen: msg length
23992668 *
24002669 * VFs get a default number of queues but can use this message to request a
24012670 * different number. If the request is successful, PF will reset the VF and
24022671 * return 0. If unsuccessful, PF will send message informing VF of number of
24032672 * available queues and return result of sending VF a message.
24042673 **/
2405
-static int i40e_vc_request_queues_msg(struct i40e_vf *vf, u8 *msg, int msglen)
2674
+static int i40e_vc_request_queues_msg(struct i40e_vf *vf, u8 *msg)
24062675 {
24072676 struct virtchnl_vf_res_request *vfres =
24082677 (struct virtchnl_vf_res_request *)msg;
2409
- int req_pairs = vfres->num_queue_pairs;
2410
- int cur_pairs = vf->num_queue_pairs;
2678
+ u16 req_pairs = vfres->num_queue_pairs;
2679
+ u8 cur_pairs = vf->num_queue_pairs;
24112680 struct i40e_pf *pf = vf->pf;
24122681
2413
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
2682
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE))
24142683 return -EINVAL;
24152684
2416
- if (req_pairs <= 0) {
2417
- dev_err(&pf->pdev->dev,
2418
- "VF %d tried to request %d queues. Ignoring.\n",
2419
- vf->vf_id, req_pairs);
2420
- } else if (req_pairs > I40E_MAX_VF_QUEUES) {
2685
+ if (req_pairs > I40E_MAX_VF_QUEUES) {
24212686 dev_err(&pf->pdev->dev,
24222687 "VF %d tried to request more than %d queues.\n",
24232688 vf->vf_id,
....@@ -2439,8 +2704,7 @@
24392704 } else {
24402705 /* successful request */
24412706 vf->num_req_queues = req_pairs;
2442
- i40e_vc_notify_vf_reset(vf);
2443
- i40e_reset_vf(vf, false);
2707
+ i40e_vc_reset_vf(vf, true);
24442708 return 0;
24452709 }
24462710
....@@ -2452,11 +2716,10 @@
24522716 * i40e_vc_get_stats_msg
24532717 * @vf: pointer to the VF info
24542718 * @msg: pointer to the msg buffer
2455
- * @msglen: msg length
24562719 *
24572720 * called from the VF to get vsi stats
24582721 **/
2459
-static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2722
+static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg)
24602723 {
24612724 struct virtchnl_queue_select *vqs =
24622725 (struct virtchnl_queue_select *)msg;
....@@ -2467,7 +2730,7 @@
24672730
24682731 memset(&stats, 0, sizeof(struct i40e_eth_stats));
24692732
2470
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2733
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
24712734 aq_ret = I40E_ERR_PARAM;
24722735 goto error_param;
24732736 }
....@@ -2495,7 +2758,7 @@
24952758 * MAC filters: 16 for multicast, 1 for MAC, 1 for broadcast
24962759 */
24972760 #define I40E_VC_MAX_MAC_ADDR_PER_VF (16 + 1 + 1)
2498
-#define I40E_VC_MAX_VLAN_PER_VF 8
2761
+#define I40E_VC_MAX_VLAN_PER_VF 16
24992762
25002763 /**
25012764 * i40e_check_vf_permission
....@@ -2518,20 +2781,12 @@
25182781 struct virtchnl_ether_addr_list *al)
25192782 {
25202783 struct i40e_pf *pf = vf->pf;
2784
+ struct i40e_vsi *vsi = pf->vsi[vf->lan_vsi_idx];
2785
+ int mac2add_cnt = 0;
25212786 int i;
25222787
2523
- /* If this VF is not privileged, then we can't add more than a limited
2524
- * number of addresses. Check to make sure that the additions do not
2525
- * push us over the limit.
2526
- */
2527
- if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
2528
- (vf->num_mac + al->num_elements) > I40E_VC_MAX_MAC_ADDR_PER_VF) {
2529
- dev_err(&pf->pdev->dev,
2530
- "Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
2531
- return -EPERM;
2532
- }
2533
-
25342788 for (i = 0; i < al->num_elements; i++) {
2789
+ struct i40e_mac_filter *f;
25352790 u8 *addr = al->list[i].addr;
25362791
25372792 if (is_broadcast_ether_addr(addr) ||
....@@ -2552,11 +2807,27 @@
25522807 !is_multicast_ether_addr(addr) && vf->pf_set_mac &&
25532808 !ether_addr_equal(addr, vf->default_lan_addr.addr)) {
25542809 dev_err(&pf->pdev->dev,
2555
- "VF attempting to override administratively set MAC address, reload the VF driver to resume normal operation\n");
2810
+ "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
25562811 return -EPERM;
25572812 }
2813
+
2814
+ /*count filters that really will be added*/
2815
+ f = i40e_find_mac(vsi, addr);
2816
+ if (!f)
2817
+ ++mac2add_cnt;
25582818 }
25592819
2820
+ /* If this VF is not privileged, then we can't add more than a limited
2821
+ * number of addresses. Check to make sure that the additions do not
2822
+ * push us over the limit.
2823
+ */
2824
+ if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
2825
+ (i40e_count_filters(vsi) + mac2add_cnt) >
2826
+ I40E_VC_MAX_MAC_ADDR_PER_VF) {
2827
+ dev_err(&pf->pdev->dev,
2828
+ "Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
2829
+ return -EPERM;
2830
+ }
25602831 return 0;
25612832 }
25622833
....@@ -2564,22 +2835,20 @@
25642835 * i40e_vc_add_mac_addr_msg
25652836 * @vf: pointer to the VF info
25662837 * @msg: pointer to the msg buffer
2567
- * @msglen: msg length
25682838 *
25692839 * add guest mac address filter
25702840 **/
2571
-static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2841
+static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg)
25722842 {
25732843 struct virtchnl_ether_addr_list *al =
25742844 (struct virtchnl_ether_addr_list *)msg;
25752845 struct i40e_pf *pf = vf->pf;
25762846 struct i40e_vsi *vsi = NULL;
2577
- u16 vsi_id = al->vsi_id;
25782847 i40e_status ret = 0;
25792848 int i;
25802849
2581
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2582
- !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2850
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE) ||
2851
+ !i40e_vc_isvalid_vsi_id(vf, al->vsi_id)) {
25832852 ret = I40E_ERR_PARAM;
25842853 goto error_param;
25852854 }
....@@ -2612,9 +2881,11 @@
26122881 ret = I40E_ERR_PARAM;
26132882 spin_unlock_bh(&vsi->mac_filter_hash_lock);
26142883 goto error_param;
2615
- } else {
2616
- vf->num_mac++;
26172884 }
2885
+ if (is_valid_ether_addr(al->list[i].addr) &&
2886
+ is_zero_ether_addr(vf->default_lan_addr.addr))
2887
+ ether_addr_copy(vf->default_lan_addr.addr,
2888
+ al->list[i].addr);
26182889 }
26192890 }
26202891 spin_unlock_bh(&vsi->mac_filter_hash_lock);
....@@ -2627,30 +2898,29 @@
26272898
26282899 error_param:
26292900 /* send the response to the VF */
2630
- return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
2631
- ret);
2901
+ return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
2902
+ ret, NULL, 0);
26322903 }
26332904
26342905 /**
26352906 * i40e_vc_del_mac_addr_msg
26362907 * @vf: pointer to the VF info
26372908 * @msg: pointer to the msg buffer
2638
- * @msglen: msg length
26392909 *
26402910 * remove guest mac address filter
26412911 **/
2642
-static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2912
+static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg)
26432913 {
26442914 struct virtchnl_ether_addr_list *al =
26452915 (struct virtchnl_ether_addr_list *)msg;
2916
+ bool was_unimac_deleted = false;
26462917 struct i40e_pf *pf = vf->pf;
26472918 struct i40e_vsi *vsi = NULL;
2648
- u16 vsi_id = al->vsi_id;
26492919 i40e_status ret = 0;
26502920 int i;
26512921
2652
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2653
- !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2922
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE) ||
2923
+ !i40e_vc_isvalid_vsi_id(vf, al->vsi_id)) {
26542924 ret = I40E_ERR_PARAM;
26552925 goto error_param;
26562926 }
....@@ -2663,16 +2933,8 @@
26632933 ret = I40E_ERR_INVALID_MAC_ADDR;
26642934 goto error_param;
26652935 }
2666
-
2667
- if (vf->pf_set_mac &&
2668
- ether_addr_equal(al->list[i].addr,
2669
- vf->default_lan_addr.addr)) {
2670
- dev_err(&pf->pdev->dev,
2671
- "MAC addr %pM has been set by PF, cannot delete it for VF %d, reset VF to change MAC addr\n",
2672
- vf->default_lan_addr.addr, vf->vf_id);
2673
- ret = I40E_ERR_PARAM;
2674
- goto error_param;
2675
- }
2936
+ if (ether_addr_equal(al->list[i].addr, vf->default_lan_addr.addr))
2937
+ was_unimac_deleted = true;
26762938 }
26772939 vsi = pf->vsi[vf->lan_vsi_idx];
26782940
....@@ -2683,8 +2945,6 @@
26832945 ret = I40E_ERR_INVALID_MAC_ADDR;
26842946 spin_unlock_bh(&vsi->mac_filter_hash_lock);
26852947 goto error_param;
2686
- } else {
2687
- vf->num_mac--;
26882948 }
26892949
26902950 spin_unlock_bh(&vsi->mac_filter_hash_lock);
....@@ -2695,27 +2955,40 @@
26952955 dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
26962956 vf->vf_id, ret);
26972957
2958
+ if (vf->trusted && was_unimac_deleted) {
2959
+ struct i40e_mac_filter *f;
2960
+ struct hlist_node *h;
2961
+ u8 *macaddr = NULL;
2962
+ int bkt;
2963
+
2964
+ /* set last unicast mac address as default */
2965
+ spin_lock_bh(&vsi->mac_filter_hash_lock);
2966
+ hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
2967
+ if (is_valid_ether_addr(f->macaddr))
2968
+ macaddr = f->macaddr;
2969
+ }
2970
+ if (macaddr)
2971
+ ether_addr_copy(vf->default_lan_addr.addr, macaddr);
2972
+ spin_unlock_bh(&vsi->mac_filter_hash_lock);
2973
+ }
26982974 error_param:
26992975 /* send the response to the VF */
2700
- return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
2701
- ret);
2976
+ return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR, ret);
27022977 }
27032978
27042979 /**
27052980 * i40e_vc_add_vlan_msg
27062981 * @vf: pointer to the VF info
27072982 * @msg: pointer to the msg buffer
2708
- * @msglen: msg length
27092983 *
27102984 * program guest vlan id
27112985 **/
2712
-static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2986
+static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg)
27132987 {
27142988 struct virtchnl_vlan_filter_list *vfl =
27152989 (struct virtchnl_vlan_filter_list *)msg;
27162990 struct i40e_pf *pf = vf->pf;
27172991 struct i40e_vsi *vsi = NULL;
2718
- u16 vsi_id = vfl->vsi_id;
27192992 i40e_status aq_ret = 0;
27202993 int i;
27212994
....@@ -2726,7 +2999,7 @@
27262999 goto error_param;
27273000 }
27283001 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2729
- !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
3002
+ !i40e_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
27303003 aq_ret = I40E_ERR_PARAM;
27313004 goto error_param;
27323005 }
....@@ -2778,22 +3051,20 @@
27783051 * i40e_vc_remove_vlan_msg
27793052 * @vf: pointer to the VF info
27803053 * @msg: pointer to the msg buffer
2781
- * @msglen: msg length
27823054 *
27833055 * remove programmed guest vlan id
27843056 **/
2785
-static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
3057
+static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg)
27863058 {
27873059 struct virtchnl_vlan_filter_list *vfl =
27883060 (struct virtchnl_vlan_filter_list *)msg;
27893061 struct i40e_pf *pf = vf->pf;
27903062 struct i40e_vsi *vsi = NULL;
2791
- u16 vsi_id = vfl->vsi_id;
27923063 i40e_status aq_ret = 0;
27933064 int i;
27943065
2795
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2796
- !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
3066
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE) ||
3067
+ !i40e_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
27973068 aq_ret = I40E_ERR_PARAM;
27983069 goto error_param;
27993070 }
....@@ -2807,7 +3078,8 @@
28073078
28083079 vsi = pf->vsi[vf->lan_vsi_idx];
28093080 if (vsi->info.pvid) {
2810
- aq_ret = I40E_ERR_PARAM;
3081
+ if (vfl->num_elements > 1 || vfl->vlan_id[0])
3082
+ aq_ret = I40E_ERR_PARAM;
28113083 goto error_param;
28123084 }
28133085
....@@ -2865,13 +3137,11 @@
28653137 * i40e_vc_iwarp_qvmap_msg
28663138 * @vf: pointer to the VF info
28673139 * @msg: pointer to the msg buffer
2868
- * @msglen: msg length
28693140 * @config: config qvmap or release it
28703141 *
28713142 * called from the VF for the iwarp msgs
28723143 **/
2873
-static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf *vf, u8 *msg, u16 msglen,
2874
- bool config)
3144
+static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf *vf, u8 *msg, bool config)
28753145 {
28763146 struct virtchnl_iwarp_qvlist_info *qvlist_info =
28773147 (struct virtchnl_iwarp_qvlist_info *)msg;
....@@ -2902,22 +3172,20 @@
29023172 * i40e_vc_config_rss_key
29033173 * @vf: pointer to the VF info
29043174 * @msg: pointer to the msg buffer
2905
- * @msglen: msg length
29063175 *
29073176 * Configure the VF's RSS key
29083177 **/
2909
-static int i40e_vc_config_rss_key(struct i40e_vf *vf, u8 *msg, u16 msglen)
3178
+static int i40e_vc_config_rss_key(struct i40e_vf *vf, u8 *msg)
29103179 {
29113180 struct virtchnl_rss_key *vrk =
29123181 (struct virtchnl_rss_key *)msg;
29133182 struct i40e_pf *pf = vf->pf;
29143183 struct i40e_vsi *vsi = NULL;
2915
- u16 vsi_id = vrk->vsi_id;
29163184 i40e_status aq_ret = 0;
29173185
2918
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2919
- !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
2920
- (vrk->key_len != I40E_HKEY_ARRAY_SIZE)) {
3186
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE) ||
3187
+ !i40e_vc_isvalid_vsi_id(vf, vrk->vsi_id) ||
3188
+ vrk->key_len != I40E_HKEY_ARRAY_SIZE) {
29213189 aq_ret = I40E_ERR_PARAM;
29223190 goto err;
29233191 }
....@@ -2934,25 +3202,30 @@
29343202 * i40e_vc_config_rss_lut
29353203 * @vf: pointer to the VF info
29363204 * @msg: pointer to the msg buffer
2937
- * @msglen: msg length
29383205 *
29393206 * Configure the VF's RSS LUT
29403207 **/
2941
-static int i40e_vc_config_rss_lut(struct i40e_vf *vf, u8 *msg, u16 msglen)
3208
+static int i40e_vc_config_rss_lut(struct i40e_vf *vf, u8 *msg)
29423209 {
29433210 struct virtchnl_rss_lut *vrl =
29443211 (struct virtchnl_rss_lut *)msg;
29453212 struct i40e_pf *pf = vf->pf;
29463213 struct i40e_vsi *vsi = NULL;
2947
- u16 vsi_id = vrl->vsi_id;
29483214 i40e_status aq_ret = 0;
3215
+ u16 i;
29493216
2950
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2951
- !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
2952
- (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE)) {
3217
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE) ||
3218
+ !i40e_vc_isvalid_vsi_id(vf, vrl->vsi_id) ||
3219
+ vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE) {
29533220 aq_ret = I40E_ERR_PARAM;
29543221 goto err;
29553222 }
3223
+
3224
+ for (i = 0; i < vrl->lut_entries; i++)
3225
+ if (vrl->lut[i] >= vf->num_queue_pairs) {
3226
+ aq_ret = I40E_ERR_PARAM;
3227
+ goto err;
3228
+ }
29563229
29573230 vsi = pf->vsi[vf->lan_vsi_idx];
29583231 aq_ret = i40e_config_rss(vsi, NULL, vrl->lut, I40E_VF_HLUT_ARRAY_SIZE);
....@@ -2966,18 +3239,17 @@
29663239 * i40e_vc_get_rss_hena
29673240 * @vf: pointer to the VF info
29683241 * @msg: pointer to the msg buffer
2969
- * @msglen: msg length
29703242 *
29713243 * Return the RSS HENA bits allowed by the hardware
29723244 **/
2973
-static int i40e_vc_get_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
3245
+static int i40e_vc_get_rss_hena(struct i40e_vf *vf, u8 *msg)
29743246 {
29753247 struct virtchnl_rss_hena *vrh = NULL;
29763248 struct i40e_pf *pf = vf->pf;
29773249 i40e_status aq_ret = 0;
29783250 int len = 0;
29793251
2980
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3252
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
29813253 aq_ret = I40E_ERR_PARAM;
29823254 goto err;
29833255 }
....@@ -3002,11 +3274,10 @@
30023274 * i40e_vc_set_rss_hena
30033275 * @vf: pointer to the VF info
30043276 * @msg: pointer to the msg buffer
3005
- * @msglen: msg length
30063277 *
30073278 * Set the RSS HENA bits for the VF
30083279 **/
3009
-static int i40e_vc_set_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
3280
+static int i40e_vc_set_rss_hena(struct i40e_vf *vf, u8 *msg)
30103281 {
30113282 struct virtchnl_rss_hena *vrh =
30123283 (struct virtchnl_rss_hena *)msg;
....@@ -3014,7 +3285,7 @@
30143285 struct i40e_hw *hw = &pf->hw;
30153286 i40e_status aq_ret = 0;
30163287
3017
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3288
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
30183289 aq_ret = I40E_ERR_PARAM;
30193290 goto err;
30203291 }
....@@ -3031,21 +3302,20 @@
30313302 * i40e_vc_enable_vlan_stripping
30323303 * @vf: pointer to the VF info
30333304 * @msg: pointer to the msg buffer
3034
- * @msglen: msg length
30353305 *
30363306 * Enable vlan header stripping for the VF
30373307 **/
3038
-static int i40e_vc_enable_vlan_stripping(struct i40e_vf *vf, u8 *msg,
3039
- u16 msglen)
3308
+static int i40e_vc_enable_vlan_stripping(struct i40e_vf *vf, u8 *msg)
30403309 {
3041
- struct i40e_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
30423310 i40e_status aq_ret = 0;
3311
+ struct i40e_vsi *vsi;
30433312
3044
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3313
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
30453314 aq_ret = I40E_ERR_PARAM;
30463315 goto err;
30473316 }
30483317
3318
+ vsi = vf->pf->vsi[vf->lan_vsi_idx];
30493319 i40e_vlan_stripping_enable(vsi);
30503320
30513321 /* send the response to the VF */
....@@ -3058,21 +3328,20 @@
30583328 * i40e_vc_disable_vlan_stripping
30593329 * @vf: pointer to the VF info
30603330 * @msg: pointer to the msg buffer
3061
- * @msglen: msg length
30623331 *
30633332 * Disable vlan header stripping for the VF
30643333 **/
3065
-static int i40e_vc_disable_vlan_stripping(struct i40e_vf *vf, u8 *msg,
3066
- u16 msglen)
3334
+static int i40e_vc_disable_vlan_stripping(struct i40e_vf *vf, u8 *msg)
30673335 {
3068
- struct i40e_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
30693336 i40e_status aq_ret = 0;
3337
+ struct i40e_vsi *vsi;
30703338
3071
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3339
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
30723340 aq_ret = I40E_ERR_PARAM;
30733341 goto err;
30743342 }
30753343
3344
+ vsi = vf->pf->vsi[vf->lan_vsi_idx];
30763345 i40e_vlan_stripping_disable(vsi);
30773346
30783347 /* send the response to the VF */
....@@ -3083,8 +3352,8 @@
30833352
30843353 /**
30853354 * i40e_validate_cloud_filter
3086
- * @mask: mask for TC filter
3087
- * @data: data for TC filter
3355
+ * @vf: pointer to VF structure
3356
+ * @tc_filter: pointer to filter requested
30883357 *
30893358 * This function validates cloud filter programmed as TC filter for ADq
30903359 **/
....@@ -3179,7 +3448,7 @@
31793448 }
31803449
31813450 if (mask.dst_port & data.dst_port) {
3182
- if (!data.dst_port || be16_to_cpu(data.dst_port) > 0xFFFF) {
3451
+ if (!data.dst_port) {
31833452 dev_info(&pf->pdev->dev, "VF %d: Invalid Dest port\n",
31843453 vf->vf_id);
31853454 goto err;
....@@ -3187,7 +3456,7 @@
31873456 }
31883457
31893458 if (mask.src_port & data.src_port) {
3190
- if (!data.src_port || be16_to_cpu(data.src_port) > 0xFFFF) {
3459
+ if (!data.src_port) {
31913460 dev_info(&pf->pdev->dev, "VF %d: Invalid Source port\n",
31923461 vf->vf_id);
31933462 goto err;
....@@ -3217,7 +3486,7 @@
32173486 /**
32183487 * i40e_find_vsi_from_seid - searches for the vsi with the given seid
32193488 * @vf: pointer to the VF info
3220
- * @seid - seid of the vsi it is searching for
3489
+ * @seid: seid of the vsi it is searching for
32213490 **/
32223491 static struct i40e_vsi *i40e_find_vsi_from_seid(struct i40e_vf *vf, u16 seid)
32233492 {
....@@ -3294,7 +3563,7 @@
32943563 i40e_status aq_ret = 0;
32953564 int i, ret;
32963565
3297
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3566
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
32983567 aq_ret = I40E_ERR_PARAM;
32993568 goto err;
33003569 }
....@@ -3425,7 +3694,7 @@
34253694 i40e_status aq_ret = 0;
34263695 int i, ret;
34273696
3428
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3697
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
34293698 aq_ret = I40E_ERR_PARAM;
34303699 goto err_out;
34313700 }
....@@ -3530,10 +3799,11 @@
35303799 (struct virtchnl_tc_info *)msg;
35313800 struct i40e_pf *pf = vf->pf;
35323801 struct i40e_link_status *ls = &pf->hw.phy.link_info;
3533
- int i, adq_request_qps = 0, speed = 0;
3802
+ int i, adq_request_qps = 0;
35343803 i40e_status aq_ret = 0;
3804
+ u64 speed = 0;
35353805
3536
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3806
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
35373807 aq_ret = I40E_ERR_PARAM;
35383808 goto err;
35393809 }
....@@ -3557,8 +3827,8 @@
35573827 /* max number of traffic classes for VF currently capped at 4 */
35583828 if (!tci->num_tc || tci->num_tc > I40E_MAX_VF_VSI) {
35593829 dev_err(&pf->pdev->dev,
3560
- "VF %d trying to set %u TCs, valid range 1-4 TCs per VF\n",
3561
- vf->vf_id, tci->num_tc);
3830
+ "VF %d trying to set %u TCs, valid range 1-%u TCs per VF\n",
3831
+ vf->vf_id, tci->num_tc, I40E_MAX_VF_VSI);
35623832 aq_ret = I40E_ERR_PARAM;
35633833 goto err;
35643834 }
....@@ -3568,8 +3838,9 @@
35683838 if (!tci->list[i].count ||
35693839 tci->list[i].count > I40E_DEFAULT_QUEUES_PER_VF) {
35703840 dev_err(&pf->pdev->dev,
3571
- "VF %d: TC %d trying to set %u queues, valid range 1-4 queues per TC\n",
3572
- vf->vf_id, i, tci->list[i].count);
3841
+ "VF %d: TC %d trying to set %u queues, valid range 1-%u queues per TC\n",
3842
+ vf->vf_id, i, tci->list[i].count,
3843
+ I40E_DEFAULT_QUEUES_PER_VF);
35733844 aq_ret = I40E_ERR_PARAM;
35743845 goto err;
35753846 }
....@@ -3641,8 +3912,7 @@
36413912 vf->adq_enabled = true;
36423913
36433914 /* reset the VF in order to allocate resources */
3644
- i40e_vc_notify_vf_reset(vf);
3645
- i40e_reset_vf(vf, false);
3915
+ i40e_vc_reset_vf(vf, true);
36463916
36473917 return I40E_SUCCESS;
36483918
....@@ -3662,7 +3932,7 @@
36623932 struct i40e_pf *pf = vf->pf;
36633933 i40e_status aq_ret = 0;
36643934
3665
- if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3935
+ if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
36663936 aq_ret = I40E_ERR_PARAM;
36673937 goto err;
36683938 }
....@@ -3682,8 +3952,7 @@
36823952 }
36833953
36843954 /* reset the VF in order to allocate resources */
3685
- i40e_vc_notify_vf_reset(vf);
3686
- i40e_reset_vf(vf, false);
3955
+ i40e_vc_reset_vf(vf, true);
36873956
36883957 return I40E_SUCCESS;
36893958
....@@ -3713,7 +3982,7 @@
37133982 int ret;
37143983
37153984 pf->vf_aq_requests++;
3716
- if (local_vf_id >= pf->num_alloc_vfs)
3985
+ if (local_vf_id < 0 || local_vf_id >= pf->num_alloc_vfs)
37173986 return -EINVAL;
37183987 vf = &(pf->vf[local_vf_id]);
37193988
....@@ -3724,25 +3993,12 @@
37243993 /* perform basic checks on the msg */
37253994 ret = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
37263995
3727
- /* perform additional checks specific to this driver */
3728
- if (v_opcode == VIRTCHNL_OP_CONFIG_RSS_KEY) {
3729
- struct virtchnl_rss_key *vrk = (struct virtchnl_rss_key *)msg;
3730
-
3731
- if (vrk->key_len != I40E_HKEY_ARRAY_SIZE)
3732
- ret = -EINVAL;
3733
- } else if (v_opcode == VIRTCHNL_OP_CONFIG_RSS_LUT) {
3734
- struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
3735
-
3736
- if (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE)
3737
- ret = -EINVAL;
3738
- }
3739
-
37403996 if (ret) {
37413997 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
37423998 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
37433999 local_vf_id, v_opcode, msglen);
37444000 switch (ret) {
3745
- case VIRTCHNL_ERR_PARAM:
4001
+ case VIRTCHNL_STATUS_ERR_PARAM:
37464002 return -EPERM;
37474003 default:
37484004 return -EINVAL;
....@@ -3758,69 +4014,69 @@
37584014 i40e_vc_notify_vf_link_state(vf);
37594015 break;
37604016 case VIRTCHNL_OP_RESET_VF:
3761
- i40e_vc_reset_vf_msg(vf);
4017
+ i40e_vc_reset_vf(vf, false);
37624018 ret = 0;
37634019 break;
37644020 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
3765
- ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
4021
+ ret = i40e_vc_config_promiscuous_mode_msg(vf, msg);
37664022 break;
37674023 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
3768
- ret = i40e_vc_config_queues_msg(vf, msg, msglen);
4024
+ ret = i40e_vc_config_queues_msg(vf, msg);
37694025 break;
37704026 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
3771
- ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
4027
+ ret = i40e_vc_config_irq_map_msg(vf, msg);
37724028 break;
37734029 case VIRTCHNL_OP_ENABLE_QUEUES:
3774
- ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
4030
+ ret = i40e_vc_enable_queues_msg(vf, msg);
37754031 i40e_vc_notify_vf_link_state(vf);
37764032 break;
37774033 case VIRTCHNL_OP_DISABLE_QUEUES:
3778
- ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
4034
+ ret = i40e_vc_disable_queues_msg(vf, msg);
37794035 break;
37804036 case VIRTCHNL_OP_ADD_ETH_ADDR:
3781
- ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
4037
+ ret = i40e_vc_add_mac_addr_msg(vf, msg);
37824038 break;
37834039 case VIRTCHNL_OP_DEL_ETH_ADDR:
3784
- ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
4040
+ ret = i40e_vc_del_mac_addr_msg(vf, msg);
37854041 break;
37864042 case VIRTCHNL_OP_ADD_VLAN:
3787
- ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
4043
+ ret = i40e_vc_add_vlan_msg(vf, msg);
37884044 break;
37894045 case VIRTCHNL_OP_DEL_VLAN:
3790
- ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
4046
+ ret = i40e_vc_remove_vlan_msg(vf, msg);
37914047 break;
37924048 case VIRTCHNL_OP_GET_STATS:
3793
- ret = i40e_vc_get_stats_msg(vf, msg, msglen);
4049
+ ret = i40e_vc_get_stats_msg(vf, msg);
37944050 break;
37954051 case VIRTCHNL_OP_IWARP:
37964052 ret = i40e_vc_iwarp_msg(vf, msg, msglen);
37974053 break;
37984054 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
3799
- ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, true);
4055
+ ret = i40e_vc_iwarp_qvmap_msg(vf, msg, true);
38004056 break;
38014057 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
3802
- ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, false);
4058
+ ret = i40e_vc_iwarp_qvmap_msg(vf, msg, false);
38034059 break;
38044060 case VIRTCHNL_OP_CONFIG_RSS_KEY:
3805
- ret = i40e_vc_config_rss_key(vf, msg, msglen);
4061
+ ret = i40e_vc_config_rss_key(vf, msg);
38064062 break;
38074063 case VIRTCHNL_OP_CONFIG_RSS_LUT:
3808
- ret = i40e_vc_config_rss_lut(vf, msg, msglen);
4064
+ ret = i40e_vc_config_rss_lut(vf, msg);
38094065 break;
38104066 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
3811
- ret = i40e_vc_get_rss_hena(vf, msg, msglen);
4067
+ ret = i40e_vc_get_rss_hena(vf, msg);
38124068 break;
38134069 case VIRTCHNL_OP_SET_RSS_HENA:
3814
- ret = i40e_vc_set_rss_hena(vf, msg, msglen);
4070
+ ret = i40e_vc_set_rss_hena(vf, msg);
38154071 break;
38164072 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
3817
- ret = i40e_vc_enable_vlan_stripping(vf, msg, msglen);
4073
+ ret = i40e_vc_enable_vlan_stripping(vf, msg);
38184074 break;
38194075 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
3820
- ret = i40e_vc_disable_vlan_stripping(vf, msg, msglen);
4076
+ ret = i40e_vc_disable_vlan_stripping(vf, msg);
38214077 break;
38224078 case VIRTCHNL_OP_REQUEST_QUEUES:
3823
- ret = i40e_vc_request_queues_msg(vf, msg, msglen);
4079
+ ret = i40e_vc_request_queues_msg(vf, msg);
38244080 break;
38254081 case VIRTCHNL_OP_ENABLE_CHANNELS:
38264082 ret = i40e_vc_add_qch_msg(vf, msg);
....@@ -3889,6 +4145,35 @@
38894145 }
38904146
38914147 /**
4148
+ * i40e_validate_vf
4149
+ * @pf: the physical function
4150
+ * @vf_id: VF identifier
4151
+ *
4152
+ * Check that the VF is enabled and the VSI exists.
4153
+ *
4154
+ * Returns 0 on success, negative on failure
4155
+ **/
4156
+static int i40e_validate_vf(struct i40e_pf *pf, int vf_id)
4157
+{
4158
+ struct i40e_vsi *vsi;
4159
+ struct i40e_vf *vf;
4160
+ int ret = 0;
4161
+
4162
+ if (vf_id >= pf->num_alloc_vfs) {
4163
+ dev_err(&pf->pdev->dev,
4164
+ "Invalid VF Identifier %d\n", vf_id);
4165
+ ret = -EINVAL;
4166
+ goto err_out;
4167
+ }
4168
+ vf = &pf->vf[vf_id];
4169
+ vsi = i40e_find_vsi_from_id(pf, vf->lan_vsi_id);
4170
+ if (!vsi)
4171
+ ret = -EINVAL;
4172
+err_out:
4173
+ return ret;
4174
+}
4175
+
4176
+/**
38924177 * i40e_ndo_set_vf_mac
38934178 * @netdev: network interface device structure
38944179 * @vf_id: VF identifier
....@@ -3908,20 +4193,23 @@
39084193 int bkt;
39094194 u8 i;
39104195
3911
- /* validate the request */
3912
- if (vf_id >= pf->num_alloc_vfs) {
3913
- dev_err(&pf->pdev->dev,
3914
- "Invalid VF Identifier %d\n", vf_id);
3915
- ret = -EINVAL;
3916
- goto error_param;
4196
+ if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
4197
+ dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n");
4198
+ return -EAGAIN;
39174199 }
39184200
3919
- vf = &(pf->vf[vf_id]);
3920
- vsi = pf->vsi[vf->lan_vsi_idx];
4201
+ /* validate the request */
4202
+ ret = i40e_validate_vf(pf, vf_id);
4203
+ if (ret)
4204
+ goto error_param;
4205
+
4206
+ vf = &pf->vf[vf_id];
39214207
39224208 /* When the VF is resetting wait until it is done.
39234209 * It can take up to 200 milliseconds,
39244210 * but wait for up to 300 milliseconds to be safe.
4211
+ * Acquire the VSI pointer only after the VF has been
4212
+ * properly initialized.
39254213 */
39264214 for (i = 0; i < 15; i++) {
39274215 if (test_bit(I40E_VF_STATE_INIT, &vf->vf_states))
....@@ -3934,6 +4222,7 @@
39344222 ret = -EAGAIN;
39354223 goto error_param;
39364224 }
4225
+ vsi = pf->vsi[vf->lan_vsi_idx];
39374226
39384227 if (is_multicast_ether_addr(mac)) {
39394228 dev_err(&pf->pdev->dev,
....@@ -3976,11 +4265,14 @@
39764265 mac, vf_id);
39774266 }
39784267
3979
- /* Force the VF driver stop so it has to reload with new MAC address */
3980
- i40e_vc_disable_vf(vf);
3981
- dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
4268
+ /* Force the VF interface down so it has to bring up with new MAC
4269
+ * address
4270
+ */
4271
+ i40e_vc_reset_vf(vf, true);
4272
+ dev_info(&pf->pdev->dev, "Bring down and up the VF interface to make this change effective.\n");
39824273
39834274 error_param:
4275
+ clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
39844276 return ret;
39854277 }
39864278
....@@ -3999,17 +4291,21 @@
39994291 {
40004292 u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
40014293 struct i40e_netdev_priv *np = netdev_priv(netdev);
4294
+ bool allmulti = false, alluni = false;
40024295 struct i40e_pf *pf = np->vsi->back;
40034296 struct i40e_vsi *vsi;
40044297 struct i40e_vf *vf;
40054298 int ret = 0;
40064299
4007
- /* validate the request */
4008
- if (vf_id >= pf->num_alloc_vfs) {
4009
- dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
4010
- ret = -EINVAL;
4011
- goto error_pvid;
4300
+ if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
4301
+ dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n");
4302
+ return -EAGAIN;
40124303 }
4304
+
4305
+ /* validate the request */
4306
+ ret = i40e_validate_vf(pf, vf_id);
4307
+ if (ret)
4308
+ goto error_pvid;
40134309
40144310 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
40154311 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
....@@ -4023,7 +4319,7 @@
40234319 goto error_pvid;
40244320 }
40254321
4026
- vf = &(pf->vf[vf_id]);
4322
+ vf = &pf->vf[vf_id];
40274323 vsi = pf->vsi[vf->lan_vsi_idx];
40284324 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
40294325 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
....@@ -4036,7 +4332,7 @@
40364332 /* duplicate request, so just return success */
40374333 goto error_pvid;
40384334
4039
- i40e_vc_disable_vf(vf);
4335
+ i40e_vc_reset_vf(vf, true);
40404336 /* During reset the VF got a new VSI, so refresh a pointer. */
40414337 vsi = pf->vsi[vf->lan_vsi_idx];
40424338 /* Locked once because multiple functions below iterate list */
....@@ -4070,6 +4366,15 @@
40704366 }
40714367
40724368 spin_unlock_bh(&vsi->mac_filter_hash_lock);
4369
+
4370
+ /* disable promisc modes in case they were enabled */
4371
+ ret = i40e_config_vf_promiscuous_mode(vf, vf->lan_vsi_id,
4372
+ allmulti, alluni);
4373
+ if (ret) {
4374
+ dev_err(&pf->pdev->dev, "Unable to config VF promiscuous mode\n");
4375
+ goto error_pvid;
4376
+ }
4377
+
40734378 if (vlan_id || qos)
40744379 ret = i40e_vsi_add_pvid(vsi, vlanprio);
40754380 else
....@@ -4096,6 +4401,12 @@
40964401
40974402 spin_unlock_bh(&vsi->mac_filter_hash_lock);
40984403
4404
+ if (test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states))
4405
+ alluni = true;
4406
+
4407
+ if (test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))
4408
+ allmulti = true;
4409
+
40994410 /* Schedule the worker thread to take care of applying changes */
41004411 i40e_service_event_schedule(vsi->back);
41014412
....@@ -4108,9 +4419,17 @@
41084419 * default LAN MAC address.
41094420 */
41104421 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
4422
+
4423
+ ret = i40e_config_vf_promiscuous_mode(vf, vsi->id, allmulti, alluni);
4424
+ if (ret) {
4425
+ dev_err(&pf->pdev->dev, "Unable to config vf promiscuous mode\n");
4426
+ goto error_pvid;
4427
+ }
4428
+
41114429 ret = 0;
41124430
41134431 error_pvid:
4432
+ clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
41144433 return ret;
41154434 }
41164435
....@@ -4132,20 +4451,24 @@
41324451 struct i40e_vf *vf;
41334452 int ret = 0;
41344453
4135
- /* validate the request */
4136
- if (vf_id >= pf->num_alloc_vfs) {
4137
- dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
4138
- ret = -EINVAL;
4139
- goto error;
4454
+ if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
4455
+ dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n");
4456
+ return -EAGAIN;
41404457 }
4458
+
4459
+ /* validate the request */
4460
+ ret = i40e_validate_vf(pf, vf_id);
4461
+ if (ret)
4462
+ goto error;
41414463
41424464 if (min_tx_rate) {
41434465 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
41444466 min_tx_rate, vf_id);
4145
- return -EINVAL;
4467
+ ret = -EINVAL;
4468
+ goto error;
41464469 }
41474470
4148
- vf = &(pf->vf[vf_id]);
4471
+ vf = &pf->vf[vf_id];
41494472 vsi = pf->vsi[vf->lan_vsi_idx];
41504473 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
41514474 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
....@@ -4160,6 +4483,7 @@
41604483
41614484 vf->tx_rate = max_tx_rate;
41624485 error:
4486
+ clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
41634487 return ret;
41644488 }
41654489
....@@ -4180,20 +4504,21 @@
41804504 struct i40e_vf *vf;
41814505 int ret = 0;
41824506
4183
- /* validate the request */
4184
- if (vf_id >= pf->num_alloc_vfs) {
4185
- dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
4186
- ret = -EINVAL;
4187
- goto error_param;
4507
+ if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
4508
+ dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n");
4509
+ return -EAGAIN;
41884510 }
41894511
4190
- vf = &(pf->vf[vf_id]);
4512
+ /* validate the request */
4513
+ ret = i40e_validate_vf(pf, vf_id);
4514
+ if (ret)
4515
+ goto error_param;
4516
+
4517
+ vf = &pf->vf[vf_id];
41914518 /* first vsi is always the LAN vsi */
41924519 vsi = pf->vsi[vf->lan_vsi_idx];
4193
- if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
4194
- dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
4195
- vf_id);
4196
- ret = -EAGAIN;
4520
+ if (!vsi) {
4521
+ ret = -ENOENT;
41974522 goto error_param;
41984523 }
41994524
....@@ -4217,6 +4542,7 @@
42174542 ret = 0;
42184543
42194544 error_param:
4545
+ clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
42204546 return ret;
42214547 }
42224548
....@@ -4237,6 +4563,11 @@
42374563 struct i40e_vf *vf;
42384564 int abs_vf_id;
42394565 int ret = 0;
4566
+
4567
+ if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
4568
+ dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n");
4569
+ return -EAGAIN;
4570
+ }
42404571
42414572 /* validate the request */
42424573 if (vf_id >= pf->num_alloc_vfs) {
....@@ -4281,6 +4612,7 @@
42814612 0, (u8 *)&pfe, sizeof(pfe), NULL);
42824613
42834614 error_out:
4615
+ clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
42844616 return ret;
42854617 }
42864618
....@@ -4301,6 +4633,11 @@
43014633 struct i40e_hw *hw = &pf->hw;
43024634 struct i40e_vf *vf;
43034635 int ret = 0;
4636
+
4637
+ if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
4638
+ dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n");
4639
+ return -EAGAIN;
4640
+ }
43044641
43054642 /* validate the request */
43064643 if (vf_id >= pf->num_alloc_vfs) {
....@@ -4335,6 +4672,7 @@
43354672 ret = -EIO;
43364673 }
43374674 out:
4675
+ clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
43384676 return ret;
43394677 }
43404678
....@@ -4353,15 +4691,22 @@
43534691 struct i40e_vf *vf;
43544692 int ret = 0;
43554693
4694
+ if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
4695
+ dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n");
4696
+ return -EAGAIN;
4697
+ }
4698
+
43564699 /* validate the request */
43574700 if (vf_id >= pf->num_alloc_vfs) {
43584701 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
4359
- return -EINVAL;
4702
+ ret = -EINVAL;
4703
+ goto out;
43604704 }
43614705
43624706 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
43634707 dev_err(&pf->pdev->dev, "Trusted VF not supported in MFP mode.\n");
4364
- return -EINVAL;
4708
+ ret = -EINVAL;
4709
+ goto out;
43654710 }
43664711
43674712 vf = &pf->vf[vf_id];
....@@ -4370,7 +4715,7 @@
43704715 goto out;
43714716
43724717 vf->trusted = setting;
4373
- i40e_vc_disable_vf(vf);
4718
+ i40e_vc_reset_vf(vf, true);
43744719 dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
43754720 vf_id, setting ? "" : "un");
43764721
....@@ -4384,5 +4729,54 @@
43844729 }
43854730
43864731 out:
4732
+ clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
43874733 return ret;
43884734 }
4735
+
4736
+/**
4737
+ * i40e_get_vf_stats - populate some stats for the VF
4738
+ * @netdev: the netdev of the PF
4739
+ * @vf_id: the host OS identifier (0-127)
4740
+ * @vf_stats: pointer to the OS memory to be initialized
4741
+ */
4742
+int i40e_get_vf_stats(struct net_device *netdev, int vf_id,
4743
+ struct ifla_vf_stats *vf_stats)
4744
+{
4745
+ struct i40e_netdev_priv *np = netdev_priv(netdev);
4746
+ struct i40e_pf *pf = np->vsi->back;
4747
+ struct i40e_eth_stats *stats;
4748
+ struct i40e_vsi *vsi;
4749
+ struct i40e_vf *vf;
4750
+
4751
+ /* validate the request */
4752
+ if (i40e_validate_vf(pf, vf_id))
4753
+ return -EINVAL;
4754
+
4755
+ vf = &pf->vf[vf_id];
4756
+ if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
4757
+ dev_err(&pf->pdev->dev, "VF %d in reset. Try again.\n", vf_id);
4758
+ return -EBUSY;
4759
+ }
4760
+
4761
+ vsi = pf->vsi[vf->lan_vsi_idx];
4762
+ if (!vsi)
4763
+ return -EINVAL;
4764
+
4765
+ i40e_update_eth_stats(vsi);
4766
+ stats = &vsi->eth_stats;
4767
+
4768
+ memset(vf_stats, 0, sizeof(*vf_stats));
4769
+
4770
+ vf_stats->rx_packets = stats->rx_unicast + stats->rx_broadcast +
4771
+ stats->rx_multicast;
4772
+ vf_stats->tx_packets = stats->tx_unicast + stats->tx_broadcast +
4773
+ stats->tx_multicast;
4774
+ vf_stats->rx_bytes = stats->rx_bytes;
4775
+ vf_stats->tx_bytes = stats->tx_bytes;
4776
+ vf_stats->broadcast = stats->rx_broadcast;
4777
+ vf_stats->multicast = stats->rx_multicast;
4778
+ vf_stats->rx_dropped = stats->rx_discards;
4779
+ vf_stats->tx_dropped = stats->tx_discards;
4780
+
4781
+ return 0;
4782
+}