@@ -233,7 +233,7 @@ static int ice_vsi_ctrl_rx_rings(struct ice_vsi *vsi, bool ena)
233
233
* On error: returns error code (negative)
234
234
* On success: returns 0
235
235
*/
236
- int ice_vsi_alloc_arrays (struct ice_vsi * vsi , bool alloc_qvectors )
236
+ static int ice_vsi_alloc_arrays (struct ice_vsi * vsi , bool alloc_qvectors )
237
237
{
238
238
struct ice_pf * pf = vsi -> back ;
239
239
@@ -274,7 +274,7 @@ int ice_vsi_alloc_arrays(struct ice_vsi *vsi, bool alloc_qvectors)
274
274
*
275
275
* Return 0 on success and a negative value on error
276
276
*/
277
- void ice_vsi_set_num_qs (struct ice_vsi * vsi )
277
+ static void ice_vsi_set_num_qs (struct ice_vsi * vsi )
278
278
{
279
279
struct ice_pf * pf = vsi -> back ;
280
280
@@ -301,7 +301,7 @@ void ice_vsi_set_num_qs(struct ice_vsi *vsi)
301
301
* void * is being used to keep the functionality generic. This lets us use this
302
302
* function on any array of pointers.
303
303
*/
304
- int ice_get_free_slot (void * array , int size , int curr )
304
+ static int ice_get_free_slot (void * array , int size , int curr )
305
305
{
306
306
int * * tmp_array = (int * * )array ;
307
307
int next ;
@@ -423,6 +423,70 @@ irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
423
423
return IRQ_HANDLED ;
424
424
}
425
425
426
+ /**
427
+ * ice_vsi_alloc - Allocates the next available struct VSI in the PF
428
+ * @pf: board private structure
429
+ * @type: type of VSI
430
+ *
431
+ * returns a pointer to a VSI on success, NULL on failure.
432
+ */
433
+ static struct ice_vsi * ice_vsi_alloc (struct ice_pf * pf , enum ice_vsi_type type )
434
+ {
435
+ struct ice_vsi * vsi = NULL ;
436
+
437
+ /* Need to protect the allocation of the VSIs at the PF level */
438
+ mutex_lock (& pf -> sw_mutex );
439
+
440
+ /* If we have already allocated our maximum number of VSIs,
441
+ * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
442
+ * is available to be populated
443
+ */
444
+ if (pf -> next_vsi == ICE_NO_VSI ) {
445
+ dev_dbg (& pf -> pdev -> dev , "out of VSI slots!\n" );
446
+ goto unlock_pf ;
447
+ }
448
+
449
+ vsi = devm_kzalloc (& pf -> pdev -> dev , sizeof (* vsi ), GFP_KERNEL );
450
+ if (!vsi )
451
+ goto unlock_pf ;
452
+
453
+ vsi -> type = type ;
454
+ vsi -> back = pf ;
455
+ set_bit (__ICE_DOWN , vsi -> state );
456
+ vsi -> idx = pf -> next_vsi ;
457
+ vsi -> work_lmt = ICE_DFLT_IRQ_WORK ;
458
+
459
+ ice_vsi_set_num_qs (vsi );
460
+
461
+ switch (vsi -> type ) {
462
+ case ICE_VSI_PF :
463
+ if (ice_vsi_alloc_arrays (vsi , true))
464
+ goto err_rings ;
465
+
466
+ /* Setup default MSIX irq handler for VSI */
467
+ vsi -> irq_handler = ice_msix_clean_rings ;
468
+ break ;
469
+ default :
470
+ dev_warn (& pf -> pdev -> dev , "Unknown VSI type %d\n" , vsi -> type );
471
+ goto unlock_pf ;
472
+ }
473
+
474
+ /* fill VSI slot in the PF struct */
475
+ pf -> vsi [pf -> next_vsi ] = vsi ;
476
+
477
+ /* prepare pf->next_vsi for next use */
478
+ pf -> next_vsi = ice_get_free_slot (pf -> vsi , pf -> num_alloc_vsi ,
479
+ pf -> next_vsi );
480
+ goto unlock_pf ;
481
+
482
+ err_rings :
483
+ devm_kfree (& pf -> pdev -> dev , vsi );
484
+ vsi = NULL ;
485
+ unlock_pf :
486
+ mutex_unlock (& pf -> sw_mutex );
487
+ return vsi ;
488
+ }
489
+
426
490
/**
427
491
* ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI
428
492
* @vsi: the VSI getting queues
@@ -533,7 +597,7 @@ static int ice_vsi_get_qs_scatter(struct ice_vsi *vsi)
533
597
*
534
598
* Returns 0 on success and a negative value on error
535
599
*/
536
- int ice_vsi_get_qs (struct ice_vsi * vsi )
600
+ static int ice_vsi_get_qs (struct ice_vsi * vsi )
537
601
{
538
602
int ret = 0 ;
539
603
@@ -602,7 +666,7 @@ static void ice_rss_clean(struct ice_vsi *vsi)
602
666
* ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
603
667
* @vsi: the VSI being configured
604
668
*/
605
- void ice_vsi_set_rss_params (struct ice_vsi * vsi )
669
+ static void ice_vsi_set_rss_params (struct ice_vsi * vsi )
606
670
{
607
671
struct ice_hw_common_caps * cap ;
608
672
struct ice_pf * pf = vsi -> back ;
@@ -793,7 +857,7 @@ static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
793
857
* This initializes a VSI context depending on the VSI type to be added and
794
858
* passes it down to the add_vsi aq command to create a new VSI.
795
859
*/
796
- int ice_vsi_init (struct ice_vsi * vsi )
860
+ static int ice_vsi_init (struct ice_vsi * vsi )
797
861
{
798
862
struct ice_vsi_ctx ctxt = { 0 };
799
863
struct ice_pf * pf = vsi -> back ;
@@ -922,7 +986,7 @@ static int ice_vsi_alloc_q_vector(struct ice_vsi *vsi, int v_idx)
922
986
* We allocate one q_vector per queue interrupt. If allocation fails we
923
987
* return -ENOMEM.
924
988
*/
925
- int ice_vsi_alloc_q_vectors (struct ice_vsi * vsi )
989
+ static int ice_vsi_alloc_q_vectors (struct ice_vsi * vsi )
926
990
{
927
991
struct ice_pf * pf = vsi -> back ;
928
992
int v_idx = 0 , num_q_vectors ;
@@ -970,7 +1034,7 @@ int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
970
1034
*
971
1035
* Returns 0 on success or negative on failure
972
1036
*/
973
- int ice_vsi_setup_vector_base (struct ice_vsi * vsi )
1037
+ static int ice_vsi_setup_vector_base (struct ice_vsi * vsi )
974
1038
{
975
1039
struct ice_pf * pf = vsi -> back ;
976
1040
int num_q_vectors = 0 ;
@@ -1038,7 +1102,7 @@ static void ice_vsi_clear_rings(struct ice_vsi *vsi)
1038
1102
* ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1039
1103
* @vsi: VSI which is having rings allocated
1040
1104
*/
1041
- int ice_vsi_alloc_rings (struct ice_vsi * vsi )
1105
+ static int ice_vsi_alloc_rings (struct ice_vsi * vsi )
1042
1106
{
1043
1107
struct ice_pf * pf = vsi -> back ;
1044
1108
int i ;
@@ -1096,7 +1160,7 @@ int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1096
1160
* through the MSI-X enabling code. On a constrained vector budget, we map Tx
1097
1161
* and Rx rings to the vector as "efficiently" as possible.
1098
1162
*/
1099
- void ice_vsi_map_rings_to_vectors (struct ice_vsi * vsi )
1163
+ static void ice_vsi_map_rings_to_vectors (struct ice_vsi * vsi )
1100
1164
{
1101
1165
int q_vectors = vsi -> num_q_vectors ;
1102
1166
int tx_rings_rem , rx_rings_rem ;
@@ -1142,6 +1206,69 @@ void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
1142
1206
}
1143
1207
}
1144
1208
1209
+ /**
1210
+ * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1211
+ * @vsi: VSI to be configured
1212
+ */
1213
+ static int ice_vsi_cfg_rss_lut_key (struct ice_vsi * vsi )
1214
+ {
1215
+ u8 seed [ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE ];
1216
+ struct ice_aqc_get_set_rss_keys * key ;
1217
+ struct ice_pf * pf = vsi -> back ;
1218
+ enum ice_status status ;
1219
+ int err = 0 ;
1220
+ u8 * lut ;
1221
+
1222
+ vsi -> rss_size = min_t (int , vsi -> rss_size , vsi -> num_rxq );
1223
+
1224
+ lut = devm_kzalloc (& pf -> pdev -> dev , vsi -> rss_table_size , GFP_KERNEL );
1225
+ if (!lut )
1226
+ return - ENOMEM ;
1227
+
1228
+ if (vsi -> rss_lut_user )
1229
+ memcpy (lut , vsi -> rss_lut_user , vsi -> rss_table_size );
1230
+ else
1231
+ ice_fill_rss_lut (lut , vsi -> rss_table_size , vsi -> rss_size );
1232
+
1233
+ status = ice_aq_set_rss_lut (& pf -> hw , vsi -> vsi_num , vsi -> rss_lut_type ,
1234
+ lut , vsi -> rss_table_size );
1235
+
1236
+ if (status ) {
1237
+ dev_err (& vsi -> back -> pdev -> dev ,
1238
+ "set_rss_lut failed, error %d\n" , status );
1239
+ err = - EIO ;
1240
+ goto ice_vsi_cfg_rss_exit ;
1241
+ }
1242
+
1243
+ key = devm_kzalloc (& vsi -> back -> pdev -> dev , sizeof (* key ), GFP_KERNEL );
1244
+ if (!key ) {
1245
+ err = - ENOMEM ;
1246
+ goto ice_vsi_cfg_rss_exit ;
1247
+ }
1248
+
1249
+ if (vsi -> rss_hkey_user )
1250
+ memcpy (seed , vsi -> rss_hkey_user ,
1251
+ ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE );
1252
+ else
1253
+ netdev_rss_key_fill ((void * )seed ,
1254
+ ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE );
1255
+ memcpy (& key -> standard_rss_key , seed ,
1256
+ ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE );
1257
+
1258
+ status = ice_aq_set_rss_key (& pf -> hw , vsi -> vsi_num , key );
1259
+
1260
+ if (status ) {
1261
+ dev_err (& vsi -> back -> pdev -> dev , "set_rss_key failed, error %d\n" ,
1262
+ status );
1263
+ err = - EIO ;
1264
+ }
1265
+
1266
+ devm_kfree (& pf -> pdev -> dev , key );
1267
+ ice_vsi_cfg_rss_exit :
1268
+ devm_kfree (& pf -> pdev -> dev , lut );
1269
+ return err ;
1270
+ }
1271
+
1145
1272
/**
1146
1273
* ice_add_mac_to_list - Add a mac address filter entry to the list
1147
1274
* @vsi: the VSI to be forwarded to
@@ -1722,6 +1849,112 @@ int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena)
1722
1849
return - EIO ;
1723
1850
}
1724
1851
1852
+ /**
1853
+ * ice_vsi_setup - Set up a VSI by a given type
1854
+ * @pf: board private structure
1855
+ * @pi: pointer to the port_info instance
1856
+ * @type: VSI type
1857
+ * @vf_id: defines VF id to which this VSI connects. This field is meant to be
1858
+ * used only for ICE_VSI_VF VSI type. For other VSI types, should
1859
+ * fill-in ICE_INVAL_VFID as input.
1860
+ *
1861
+ * This allocates the sw VSI structure and its queue resources.
1862
+ *
1863
+ * Returns pointer to the successfully allocated and configured VSI sw struct on
1864
+ * success, NULL on failure.
1865
+ */
1866
+ struct ice_vsi *
1867
+ ice_vsi_setup (struct ice_pf * pf , struct ice_port_info * pi ,
1868
+ enum ice_vsi_type type , u16 __always_unused vf_id )
1869
+ {
1870
+ u16 max_txqs [ICE_MAX_TRAFFIC_CLASS ] = { 0 };
1871
+ struct device * dev = & pf -> pdev -> dev ;
1872
+ struct ice_vsi * vsi ;
1873
+ int ret , i ;
1874
+
1875
+ vsi = ice_vsi_alloc (pf , type );
1876
+ if (!vsi ) {
1877
+ dev_err (dev , "could not allocate VSI\n" );
1878
+ return NULL ;
1879
+ }
1880
+
1881
+ vsi -> port_info = pi ;
1882
+ vsi -> vsw = pf -> first_sw ;
1883
+
1884
+ if (ice_vsi_get_qs (vsi )) {
1885
+ dev_err (dev , "Failed to allocate queues. vsi->idx = %d\n" ,
1886
+ vsi -> idx );
1887
+ goto unroll_get_qs ;
1888
+ }
1889
+
1890
+ /* set RSS capabilities */
1891
+ ice_vsi_set_rss_params (vsi );
1892
+
1893
+ /* create the VSI */
1894
+ ret = ice_vsi_init (vsi );
1895
+ if (ret )
1896
+ goto unroll_get_qs ;
1897
+
1898
+ switch (vsi -> type ) {
1899
+ case ICE_VSI_PF :
1900
+ ret = ice_vsi_alloc_q_vectors (vsi );
1901
+ if (ret )
1902
+ goto unroll_vsi_init ;
1903
+
1904
+ ret = ice_vsi_setup_vector_base (vsi );
1905
+ if (ret )
1906
+ goto unroll_alloc_q_vector ;
1907
+
1908
+ ret = ice_vsi_alloc_rings (vsi );
1909
+ if (ret )
1910
+ goto unroll_vector_base ;
1911
+
1912
+ ice_vsi_map_rings_to_vectors (vsi );
1913
+
1914
+ /* Do not exit if configuring RSS had an issue, at least
1915
+ * receive traffic on first queue. Hence no need to capture
1916
+ * return value
1917
+ */
1918
+ if (test_bit (ICE_FLAG_RSS_ENA , pf -> flags ))
1919
+ ice_vsi_cfg_rss_lut_key (vsi );
1920
+ break ;
1921
+ default :
1922
+ /* if VSI type is not recognized, clean up the resources and
1923
+ * exit
1924
+ */
1925
+ goto unroll_vsi_init ;
1926
+ }
1927
+
1928
+ ice_vsi_set_tc_cfg (vsi );
1929
+
1930
+ /* configure VSI nodes based on number of queues and TC's */
1931
+ for (i = 0 ; i < vsi -> tc_cfg .numtc ; i ++ )
1932
+ max_txqs [i ] = vsi -> num_txq ;
1933
+
1934
+ ret = ice_cfg_vsi_lan (vsi -> port_info , vsi -> vsi_num ,
1935
+ vsi -> tc_cfg .ena_tc , max_txqs );
1936
+ if (ret ) {
1937
+ dev_info (& pf -> pdev -> dev , "Failed VSI lan queue config\n" );
1938
+ goto unroll_vector_base ;
1939
+ }
1940
+
1941
+ return vsi ;
1942
+
1943
+ unroll_vector_base :
1944
+ ice_free_res (vsi -> back -> irq_tracker , vsi -> base_vector , vsi -> idx );
1945
+ unroll_alloc_q_vector :
1946
+ ice_vsi_free_q_vectors (vsi );
1947
+ unroll_vsi_init :
1948
+ ice_vsi_delete (vsi );
1949
+ unroll_get_qs :
1950
+ ice_vsi_put_qs (vsi );
1951
+ pf -> q_left_tx += vsi -> alloc_txq ;
1952
+ pf -> q_left_rx += vsi -> alloc_rxq ;
1953
+ ice_vsi_clear (vsi );
1954
+
1955
+ return NULL ;
1956
+ }
1957
+
1725
1958
/**
1726
1959
* ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
1727
1960
* @vsi: the VSI being cleaned up
0 commit comments