@@ -1375,6 +1375,99 @@ static void ice_vc_notify_vf_reset(struct ice_vf *vf)
1375
1375
NULL );
1376
1376
}
1377
1377
1378
+ /**
1379
+ * ice_init_vf_vsi_res - initialize/setup VF VSI resources
1380
+ * @vf: VF to initialize/setup the VSI for
1381
+ *
1382
+ * This function creates a VSI for the VF, adds a VLAN 0 filter, and sets up the
1383
+ * VF VSI's broadcast filter and is only used during initial VF creation.
1384
+ */
1385
+ static int ice_init_vf_vsi_res (struct ice_vf * vf )
1386
+ {
1387
+ struct ice_pf * pf = vf -> pf ;
1388
+ u8 broadcast [ETH_ALEN ];
1389
+ enum ice_status status ;
1390
+ struct ice_vsi * vsi ;
1391
+ struct device * dev ;
1392
+ int err ;
1393
+
1394
+ vf -> first_vector_idx = ice_calc_vf_first_vector_idx (pf , vf );
1395
+
1396
+ dev = ice_pf_to_dev (pf );
1397
+ vsi = ice_vf_vsi_setup (pf , pf -> hw .port_info , vf -> vf_id );
1398
+ if (!vsi ) {
1399
+ dev_err (dev , "Failed to create VF VSI\n" );
1400
+ return - ENOMEM ;
1401
+ }
1402
+
1403
+ vf -> lan_vsi_idx = vsi -> idx ;
1404
+ vf -> lan_vsi_num = vsi -> vsi_num ;
1405
+
1406
+ err = ice_vsi_add_vlan (vsi , 0 , ICE_FWD_TO_VSI );
1407
+ if (err ) {
1408
+ dev_warn (dev , "Failed to add VLAN 0 filter for VF %d\n" ,
1409
+ vf -> vf_id );
1410
+ goto release_vsi ;
1411
+ }
1412
+
1413
+ eth_broadcast_addr (broadcast );
1414
+ status = ice_fltr_add_mac (vsi , broadcast , ICE_FWD_TO_VSI );
1415
+ if (status ) {
1416
+ dev_err (dev , "Failed to add broadcast MAC filter for VF %d, status %s\n" ,
1417
+ vf -> vf_id , ice_stat_str (status ));
1418
+ err = ice_status_to_errno (status );
1419
+ goto release_vsi ;
1420
+ }
1421
+
1422
+ vf -> num_mac = 1 ;
1423
+
1424
+ return 0 ;
1425
+
1426
+ release_vsi :
1427
+ ice_vsi_release (vsi );
1428
+ return err ;
1429
+ }
1430
+
1431
+ /**
1432
+ * ice_start_vfs - start VFs so they are ready to be used by SR-IOV
1433
+ * @pf: PF the VFs are associated with
1434
+ */
1435
+ static int ice_start_vfs (struct ice_pf * pf )
1436
+ {
1437
+ struct ice_hw * hw = & pf -> hw ;
1438
+ int retval , i ;
1439
+
1440
+ ice_for_each_vf (pf , i ) {
1441
+ struct ice_vf * vf = & pf -> vf [i ];
1442
+
1443
+ ice_clear_vf_reset_trigger (vf );
1444
+
1445
+ retval = ice_init_vf_vsi_res (vf );
1446
+ if (retval ) {
1447
+ dev_err (ice_pf_to_dev (pf ), "Failed to initialize VSI resources for VF %d, error %d\n" ,
1448
+ vf -> vf_id , retval );
1449
+ goto teardown ;
1450
+ }
1451
+
1452
+ set_bit (ICE_VF_STATE_INIT , vf -> vf_states );
1453
+ ice_ena_vf_mappings (vf );
1454
+ wr32 (hw , VFGEN_RSTAT (vf -> vf_id ), VIRTCHNL_VFR_VFACTIVE );
1455
+ }
1456
+
1457
+ ice_flush (hw );
1458
+ return 0 ;
1459
+
1460
+ teardown :
1461
+ for (i = i - 1 ; i >= 0 ; i -- ) {
1462
+ struct ice_vf * vf = & pf -> vf [i ];
1463
+
1464
+ ice_dis_vf_mappings (vf );
1465
+ ice_vsi_release (pf -> vsi [vf -> lan_vsi_idx ]);
1466
+ }
1467
+
1468
+ return retval ;
1469
+ }
1470
+
1378
1471
/**
1379
1472
* ice_alloc_vfs - Allocate and set up VFs resources
1380
1473
* @pf: pointer to the PF structure
@@ -1407,6 +1500,13 @@ static int ice_alloc_vfs(struct ice_pf *pf, u16 num_alloc_vfs)
1407
1500
pf -> vf = vfs ;
1408
1501
pf -> num_alloc_vfs = num_alloc_vfs ;
1409
1502
1503
+ if (ice_set_per_vf_res (pf )) {
1504
+ dev_err (dev , "Not enough resources for %d VFs, try with fewer number of VFs\n" ,
1505
+ num_alloc_vfs );
1506
+ ret = - ENOSPC ;
1507
+ goto err_unroll_sriov ;
1508
+ }
1509
+
1410
1510
/* apply default profile */
1411
1511
ice_for_each_vf (pf , i ) {
1412
1512
vfs [i ].pf = pf ;
@@ -1416,15 +1516,17 @@ static int ice_alloc_vfs(struct ice_pf *pf, u16 num_alloc_vfs)
1416
1516
/* assign default capabilities */
1417
1517
set_bit (ICE_VIRTCHNL_VF_CAP_L2 , & vfs [i ].vf_caps );
1418
1518
vfs [i ].spoofchk = true;
1519
+ vfs [i ].num_vf_qs = pf -> num_qps_per_vf ;
1419
1520
}
1420
1521
1421
- /* VF resources get allocated with initialization */
1422
- if (! ice_config_res_vfs ( pf )) {
1423
- ret = - EIO ;
1522
+ if ( ice_start_vfs ( pf )) {
1523
+ dev_err ( dev , "Failed to start VF(s)\n" );
1524
+ ret = - EAGAIN ;
1424
1525
goto err_unroll_sriov ;
1425
1526
}
1426
1527
1427
- return ret ;
1528
+ clear_bit (__ICE_VF_DIS , pf -> state );
1529
+ return 0 ;
1428
1530
1429
1531
err_unroll_sriov :
1430
1532
pf -> vf = NULL ;
0 commit comments