Skip to content

Commit 37bb839

Browse files
refactormanJeff Kirsher
authored andcommitted
ice: Move common functions out of ice_main.c part 7/7
This patch completes the code move out of ice_main.c The following top level functions and related dependency functions) were moved to ice_lib.c: ice_vsi_setup ice_vsi_cfg_tc The following functions were made static again: ice_vsi_setup_vector_base ice_vsi_alloc_q_vectors ice_vsi_get_qs void ice_vsi_map_rings_to_vectors ice_vsi_alloc_rings ice_vsi_set_rss_params ice_vsi_set_num_qs ice_get_free_slot ice_vsi_init ice_vsi_alloc_arrays Signed-off-by: Anirudh Venkataramanan <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent df0f847 commit 37bb839

File tree

3 files changed

+249
-282
lines changed

3 files changed

+249
-282
lines changed

drivers/net/ethernet/intel/ice/ice_lib.c

Lines changed: 243 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static int ice_vsi_ctrl_rx_rings(struct ice_vsi *vsi, bool ena)
233233
* On error: returns error code (negative)
234234
* On success: returns 0
235235
*/
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)
237237
{
238238
struct ice_pf *pf = vsi->back;
239239

@@ -274,7 +274,7 @@ int ice_vsi_alloc_arrays(struct ice_vsi *vsi, bool alloc_qvectors)
274274
*
275275
* Return 0 on success and a negative value on error
276276
*/
277-
void ice_vsi_set_num_qs(struct ice_vsi *vsi)
277+
static void ice_vsi_set_num_qs(struct ice_vsi *vsi)
278278
{
279279
struct ice_pf *pf = vsi->back;
280280

@@ -301,7 +301,7 @@ void ice_vsi_set_num_qs(struct ice_vsi *vsi)
301301
* void * is being used to keep the functionality generic. This lets us use this
302302
* function on any array of pointers.
303303
*/
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)
305305
{
306306
int **tmp_array = (int **)array;
307307
int next;
@@ -423,6 +423,70 @@ irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
423423
return IRQ_HANDLED;
424424
}
425425

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+
426490
/**
427491
* ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI
428492
* @vsi: the VSI getting queues
@@ -533,7 +597,7 @@ static int ice_vsi_get_qs_scatter(struct ice_vsi *vsi)
533597
*
534598
* Returns 0 on success and a negative value on error
535599
*/
536-
int ice_vsi_get_qs(struct ice_vsi *vsi)
600+
static int ice_vsi_get_qs(struct ice_vsi *vsi)
537601
{
538602
int ret = 0;
539603

@@ -602,7 +666,7 @@ static void ice_rss_clean(struct ice_vsi *vsi)
602666
* ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
603667
* @vsi: the VSI being configured
604668
*/
605-
void ice_vsi_set_rss_params(struct ice_vsi *vsi)
669+
static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
606670
{
607671
struct ice_hw_common_caps *cap;
608672
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)
793857
* This initializes a VSI context depending on the VSI type to be added and
794858
* passes it down to the add_vsi aq command to create a new VSI.
795859
*/
796-
int ice_vsi_init(struct ice_vsi *vsi)
860+
static int ice_vsi_init(struct ice_vsi *vsi)
797861
{
798862
struct ice_vsi_ctx ctxt = { 0 };
799863
struct ice_pf *pf = vsi->back;
@@ -922,7 +986,7 @@ static int ice_vsi_alloc_q_vector(struct ice_vsi *vsi, int v_idx)
922986
* We allocate one q_vector per queue interrupt. If allocation fails we
923987
* return -ENOMEM.
924988
*/
925-
int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
989+
static int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
926990
{
927991
struct ice_pf *pf = vsi->back;
928992
int v_idx = 0, num_q_vectors;
@@ -970,7 +1034,7 @@ int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
9701034
*
9711035
* Returns 0 on success or negative on failure
9721036
*/
973-
int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
1037+
static int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
9741038
{
9751039
struct ice_pf *pf = vsi->back;
9761040
int num_q_vectors = 0;
@@ -1038,7 +1102,7 @@ static void ice_vsi_clear_rings(struct ice_vsi *vsi)
10381102
* ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
10391103
* @vsi: VSI which is having rings allocated
10401104
*/
1041-
int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1105+
static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
10421106
{
10431107
struct ice_pf *pf = vsi->back;
10441108
int i;
@@ -1096,7 +1160,7 @@ int ice_vsi_alloc_rings(struct ice_vsi *vsi)
10961160
* through the MSI-X enabling code. On a constrained vector budget, we map Tx
10971161
* and Rx rings to the vector as "efficiently" as possible.
10981162
*/
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)
11001164
{
11011165
int q_vectors = vsi->num_q_vectors;
11021166
int tx_rings_rem, rx_rings_rem;
@@ -1142,6 +1206,69 @@ void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
11421206
}
11431207
}
11441208

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+
11451272
/**
11461273
* ice_add_mac_to_list - Add a mac address filter entry to the list
11471274
* @vsi: the VSI to be forwarded to
@@ -1722,6 +1849,112 @@ int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena)
17221849
return -EIO;
17231850
}
17241851

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+
17251958
/**
17261959
* ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
17271960
* @vsi: the VSI being cleaned up

drivers/net/ethernet/intel/ice/ice_lib.h

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,6 @@
66

77
#include "ice.h"
88

9-
int ice_vsi_setup_vector_base(struct ice_vsi *vsi);
10-
11-
int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi);
12-
13-
int ice_vsi_get_qs(struct ice_vsi *vsi);
14-
15-
void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi);
16-
17-
int ice_vsi_alloc_rings(struct ice_vsi *vsi);
18-
19-
void ice_vsi_set_rss_params(struct ice_vsi *vsi);
20-
21-
void ice_vsi_set_num_qs(struct ice_vsi *vsi);
22-
23-
int ice_get_free_slot(void *array, int size, int curr);
24-
25-
int ice_vsi_init(struct ice_vsi *vsi);
26-
27-
int ice_vsi_alloc_arrays(struct ice_vsi *vsi, bool alloc_qvectors);
28-
299
int ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
3010
const u8 *macaddr);
3111

@@ -59,6 +39,10 @@ void ice_vsi_delete(struct ice_vsi *vsi);
5939

6040
int ice_vsi_clear(struct ice_vsi *vsi);
6141

42+
struct ice_vsi *
43+
ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
44+
enum ice_vsi_type type, u16 vf_id);
45+
6246
int ice_vsi_release(struct ice_vsi *vsi);
6347

6448
void ice_vsi_close(struct ice_vsi *vsi);
@@ -84,5 +68,7 @@ void ice_vsi_free_rx_rings(struct ice_vsi *vsi);
8468

8569
void ice_vsi_free_tx_rings(struct ice_vsi *vsi);
8670

71+
int ice_vsi_cfg_tc(struct ice_vsi *vsi, u8 ena_tc);
72+
8773
irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data);
8874
#endif /* !_ICE_LIB_H_ */

0 commit comments

Comments
 (0)