Skip to content

Commit 07309a0

Browse files
refactormanJeff Kirsher
authored andcommitted
ice: Move common functions out of ice_main.c part 5/7
This patch continues 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_clear ice_vsi_close ice_vsi_free_arrays ice_vsi_map_rings_to_vectors Signed-off-by: Anirudh Venkataramanan <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 28c2a64 commit 07309a0

File tree

3 files changed

+141
-132
lines changed

3 files changed

+141
-132
lines changed

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

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,71 @@ void ice_vsi_delete(struct ice_vsi *vsi)
341341
vsi->vsi_num);
342342
}
343343

344+
/**
345+
* ice_vsi_free_arrays - clean up VSI resources
346+
* @vsi: pointer to VSI being cleared
347+
* @free_qvectors: bool to specify if q_vectors should be deallocated
348+
*/
349+
void ice_vsi_free_arrays(struct ice_vsi *vsi, bool free_qvectors)
350+
{
351+
struct ice_pf *pf = vsi->back;
352+
353+
/* free the ring and vector containers */
354+
if (free_qvectors && vsi->q_vectors) {
355+
devm_kfree(&pf->pdev->dev, vsi->q_vectors);
356+
vsi->q_vectors = NULL;
357+
}
358+
if (vsi->tx_rings) {
359+
devm_kfree(&pf->pdev->dev, vsi->tx_rings);
360+
vsi->tx_rings = NULL;
361+
}
362+
if (vsi->rx_rings) {
363+
devm_kfree(&pf->pdev->dev, vsi->rx_rings);
364+
vsi->rx_rings = NULL;
365+
}
366+
}
367+
368+
/**
369+
* ice_vsi_clear - clean up and deallocate the provided VSI
370+
* @vsi: pointer to VSI being cleared
371+
*
372+
* This deallocates the VSI's queue resources, removes it from the PF's
373+
* VSI array if necessary, and deallocates the VSI
374+
*
375+
* Returns 0 on success, negative on failure
376+
*/
377+
int ice_vsi_clear(struct ice_vsi *vsi)
378+
{
379+
struct ice_pf *pf = NULL;
380+
381+
if (!vsi)
382+
return 0;
383+
384+
if (!vsi->back)
385+
return -EINVAL;
386+
387+
pf = vsi->back;
388+
389+
if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
390+
dev_dbg(&pf->pdev->dev, "vsi does not exist at pf->vsi[%d]\n",
391+
vsi->idx);
392+
return -EINVAL;
393+
}
394+
395+
mutex_lock(&pf->sw_mutex);
396+
/* updates the PF for this cleared VSI */
397+
398+
pf->vsi[vsi->idx] = NULL;
399+
if (vsi->idx < pf->next_vsi)
400+
pf->next_vsi = vsi->idx;
401+
402+
ice_vsi_free_arrays(vsi, true);
403+
mutex_unlock(&pf->sw_mutex);
404+
devm_kfree(&pf->pdev->dev, vsi);
405+
406+
return 0;
407+
}
408+
344409
/**
345410
* ice_msix_clean_rings - MSIX mode Interrupt Handler
346411
* @irq: interrupt number
@@ -700,6 +765,60 @@ int ice_vsi_alloc_rings(struct ice_vsi *vsi)
700765
return -ENOMEM;
701766
}
702767

768+
/**
769+
* ice_vsi_map_rings_to_vectors - Map VSI rings to interrupt vectors
770+
* @vsi: the VSI being configured
771+
*
772+
* This function maps descriptor rings to the queue-specific vectors allotted
773+
* through the MSI-X enabling code. On a constrained vector budget, we map Tx
774+
* and Rx rings to the vector as "efficiently" as possible.
775+
*/
776+
void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
777+
{
778+
int q_vectors = vsi->num_q_vectors;
779+
int tx_rings_rem, rx_rings_rem;
780+
int v_id;
781+
782+
/* initially assigning remaining rings count to VSIs num queue value */
783+
tx_rings_rem = vsi->num_txq;
784+
rx_rings_rem = vsi->num_rxq;
785+
786+
for (v_id = 0; v_id < q_vectors; v_id++) {
787+
struct ice_q_vector *q_vector = vsi->q_vectors[v_id];
788+
int tx_rings_per_v, rx_rings_per_v, q_id, q_base;
789+
790+
/* Tx rings mapping to vector */
791+
tx_rings_per_v = DIV_ROUND_UP(tx_rings_rem, q_vectors - v_id);
792+
q_vector->num_ring_tx = tx_rings_per_v;
793+
q_vector->tx.ring = NULL;
794+
q_base = vsi->num_txq - tx_rings_rem;
795+
796+
for (q_id = q_base; q_id < (q_base + tx_rings_per_v); q_id++) {
797+
struct ice_ring *tx_ring = vsi->tx_rings[q_id];
798+
799+
tx_ring->q_vector = q_vector;
800+
tx_ring->next = q_vector->tx.ring;
801+
q_vector->tx.ring = tx_ring;
802+
}
803+
tx_rings_rem -= tx_rings_per_v;
804+
805+
/* Rx rings mapping to vector */
806+
rx_rings_per_v = DIV_ROUND_UP(rx_rings_rem, q_vectors - v_id);
807+
q_vector->num_ring_rx = rx_rings_per_v;
808+
q_vector->rx.ring = NULL;
809+
q_base = vsi->num_rxq - rx_rings_rem;
810+
811+
for (q_id = q_base; q_id < (q_base + rx_rings_per_v); q_id++) {
812+
struct ice_ring *rx_ring = vsi->rx_rings[q_id];
813+
814+
rx_ring->q_vector = q_vector;
815+
rx_ring->next = q_vector->rx.ring;
816+
q_vector->rx.ring = rx_ring;
817+
}
818+
rx_rings_rem -= rx_rings_per_v;
819+
}
820+
}
821+
703822
/**
704823
* ice_add_mac_to_list - Add a mac address filter entry to the list
705824
* @vsi: the VSI to be forwarded to
@@ -1385,6 +1504,20 @@ void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
13851504
ice_free_rx_ring(vsi->rx_rings[i]);
13861505
}
13871506

1507+
/**
1508+
* ice_vsi_close - Shut down a VSI
1509+
* @vsi: the VSI being shut down
1510+
*/
1511+
void ice_vsi_close(struct ice_vsi *vsi)
1512+
{
1513+
if (!test_and_set_bit(__ICE_DOWN, vsi->state))
1514+
ice_down(vsi);
1515+
1516+
ice_vsi_free_irq(vsi);
1517+
ice_vsi_free_tx_rings(vsi);
1518+
ice_vsi_free_rx_rings(vsi);
1519+
}
1520+
13881521
/**
13891522
* ice_free_res - free a block of resources
13901523
* @res: pointer to the resource

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

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

77
#include "ice.h"
88

9+
void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi);
10+
911
int ice_vsi_alloc_rings(struct ice_vsi *vsi);
1012

1113
void ice_vsi_set_rss_params(struct ice_vsi *vsi);
@@ -16,6 +18,8 @@ int ice_get_free_slot(void *array, int size, int curr);
1618

1719
int ice_vsi_init(struct ice_vsi *vsi);
1820

21+
void ice_vsi_free_arrays(struct ice_vsi *vsi, bool free_qvectors);
22+
1923
void ice_vsi_clear_rings(struct ice_vsi *vsi);
2024

2125
int ice_vsi_alloc_arrays(struct ice_vsi *vsi, bool alloc_qvectors);
@@ -51,6 +55,10 @@ int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena);
5155

5256
void ice_vsi_delete(struct ice_vsi *vsi);
5357

58+
int ice_vsi_clear(struct ice_vsi *vsi);
59+
60+
void ice_vsi_close(struct ice_vsi *vsi);
61+
5462
int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id);
5563

5664
int

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

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,60 +1313,6 @@ static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
13131313
return ret;
13141314
}
13151315

1316-
/**
1317-
* ice_vsi_map_rings_to_vectors - Map VSI rings to interrupt vectors
1318-
* @vsi: the VSI being configured
1319-
*
1320-
* This function maps descriptor rings to the queue-specific vectors allotted
1321-
* through the MSI-X enabling code. On a constrained vector budget, we map Tx
1322-
* and Rx rings to the vector as "efficiently" as possible.
1323-
*/
1324-
static void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
1325-
{
1326-
int q_vectors = vsi->num_q_vectors;
1327-
int tx_rings_rem, rx_rings_rem;
1328-
int v_id;
1329-
1330-
/* initially assigning remaining rings count to VSIs num queue value */
1331-
tx_rings_rem = vsi->num_txq;
1332-
rx_rings_rem = vsi->num_rxq;
1333-
1334-
for (v_id = 0; v_id < q_vectors; v_id++) {
1335-
struct ice_q_vector *q_vector = vsi->q_vectors[v_id];
1336-
int tx_rings_per_v, rx_rings_per_v, q_id, q_base;
1337-
1338-
/* Tx rings mapping to vector */
1339-
tx_rings_per_v = DIV_ROUND_UP(tx_rings_rem, q_vectors - v_id);
1340-
q_vector->num_ring_tx = tx_rings_per_v;
1341-
q_vector->tx.ring = NULL;
1342-
q_base = vsi->num_txq - tx_rings_rem;
1343-
1344-
for (q_id = q_base; q_id < (q_base + tx_rings_per_v); q_id++) {
1345-
struct ice_ring *tx_ring = vsi->tx_rings[q_id];
1346-
1347-
tx_ring->q_vector = q_vector;
1348-
tx_ring->next = q_vector->tx.ring;
1349-
q_vector->tx.ring = tx_ring;
1350-
}
1351-
tx_rings_rem -= tx_rings_per_v;
1352-
1353-
/* Rx rings mapping to vector */
1354-
rx_rings_per_v = DIV_ROUND_UP(rx_rings_rem, q_vectors - v_id);
1355-
q_vector->num_ring_rx = rx_rings_per_v;
1356-
q_vector->rx.ring = NULL;
1357-
q_base = vsi->num_rxq - rx_rings_rem;
1358-
1359-
for (q_id = q_base; q_id < (q_base + rx_rings_per_v); q_id++) {
1360-
struct ice_ring *rx_ring = vsi->rx_rings[q_id];
1361-
1362-
rx_ring->q_vector = q_vector;
1363-
rx_ring->next = q_vector->rx.ring;
1364-
q_vector->rx.ring = rx_ring;
1365-
}
1366-
rx_rings_rem -= rx_rings_per_v;
1367-
}
1368-
}
1369-
13701316
/**
13711317
* ice_vsi_alloc - Allocates the next available struct vsi in the PF
13721318
* @pf: board private structure
@@ -1770,71 +1716,6 @@ static int ice_cfg_netdev(struct ice_vsi *vsi)
17701716
return 0;
17711717
}
17721718

1773-
/**
1774-
* ice_vsi_free_arrays - clean up vsi resources
1775-
* @vsi: pointer to VSI being cleared
1776-
* @free_qvectors: bool to specify if q_vectors should be deallocated
1777-
*/
1778-
static void ice_vsi_free_arrays(struct ice_vsi *vsi, bool free_qvectors)
1779-
{
1780-
struct ice_pf *pf = vsi->back;
1781-
1782-
/* free the ring and vector containers */
1783-
if (free_qvectors && vsi->q_vectors) {
1784-
devm_kfree(&pf->pdev->dev, vsi->q_vectors);
1785-
vsi->q_vectors = NULL;
1786-
}
1787-
if (vsi->tx_rings) {
1788-
devm_kfree(&pf->pdev->dev, vsi->tx_rings);
1789-
vsi->tx_rings = NULL;
1790-
}
1791-
if (vsi->rx_rings) {
1792-
devm_kfree(&pf->pdev->dev, vsi->rx_rings);
1793-
vsi->rx_rings = NULL;
1794-
}
1795-
}
1796-
1797-
/**
1798-
* ice_vsi_clear - clean up and deallocate the provided vsi
1799-
* @vsi: pointer to VSI being cleared
1800-
*
1801-
* This deallocates the vsi's queue resources, removes it from the PF's
1802-
* VSI array if necessary, and deallocates the VSI
1803-
*
1804-
* Returns 0 on success, negative on failure
1805-
*/
1806-
static int ice_vsi_clear(struct ice_vsi *vsi)
1807-
{
1808-
struct ice_pf *pf = NULL;
1809-
1810-
if (!vsi)
1811-
return 0;
1812-
1813-
if (!vsi->back)
1814-
return -EINVAL;
1815-
1816-
pf = vsi->back;
1817-
1818-
if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
1819-
dev_dbg(&pf->pdev->dev, "vsi does not exist at pf->vsi[%d]\n",
1820-
vsi->idx);
1821-
return -EINVAL;
1822-
}
1823-
1824-
mutex_lock(&pf->sw_mutex);
1825-
/* updates the PF for this cleared vsi */
1826-
1827-
pf->vsi[vsi->idx] = NULL;
1828-
if (vsi->idx < pf->next_vsi)
1829-
pf->next_vsi = vsi->idx;
1830-
1831-
ice_vsi_free_arrays(vsi, true);
1832-
mutex_unlock(&pf->sw_mutex);
1833-
devm_kfree(&pf->pdev->dev, vsi);
1834-
1835-
return 0;
1836-
}
1837-
18381719
/**
18391720
* ice_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
18401721
* @vsi: the VSI being configured
@@ -3709,19 +3590,6 @@ static int ice_vsi_open(struct ice_vsi *vsi)
37093590
return err;
37103591
}
37113592

3712-
/**
3713-
* ice_vsi_close - Shut down a VSI
3714-
* @vsi: the VSI being shut down
3715-
*/
3716-
static void ice_vsi_close(struct ice_vsi *vsi)
3717-
{
3718-
if (!test_and_set_bit(__ICE_DOWN, vsi->state))
3719-
ice_down(vsi);
3720-
3721-
ice_vsi_free_irq(vsi);
3722-
ice_vsi_free_tx_rings(vsi);
3723-
ice_vsi_free_rx_rings(vsi);
3724-
}
37253593

37263594
/**
37273595
* ice_rss_clean - Delete RSS related VSI structures that hold user inputs

0 commit comments

Comments
 (0)