Skip to content

Commit 0a06382

Browse files
Maxim Mikityanskiyborkmann
authored andcommitted
net/mlx5e: Encapsulate open/close queues into a function
Create new functions mlx5e_{open,close}_queues to encapsulate opening and closing RQs and SQs, and call the new functions from mlx5e_{open,close}_channel. It simplifies the existing functions a bit and prepares them for the upcoming AF_XDP changes. Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com> Signed-off-by: Tariq Toukan <tariqt@mellanox.com> Acked-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent a011b49 commit 0a06382

File tree

1 file changed

+73
-52
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+73
-52
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 73 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,49 +1768,16 @@ static void mlx5e_free_xps_cpumask(struct mlx5e_channel *c)
17681768
free_cpumask_var(c->xps_cpumask);
17691769
}
17701770

1771-
static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1772-
struct mlx5e_params *params,
1773-
struct mlx5e_channel_param *cparam,
1774-
struct mlx5e_channel **cp)
1771+
static int mlx5e_open_queues(struct mlx5e_channel *c,
1772+
struct mlx5e_params *params,
1773+
struct mlx5e_channel_param *cparam)
17751774
{
1776-
int cpu = cpumask_first(mlx5_comp_irq_get_affinity_mask(priv->mdev, ix));
17771775
struct net_dim_cq_moder icocq_moder = {0, 0};
1778-
struct net_device *netdev = priv->netdev;
1779-
struct mlx5e_channel *c;
1780-
unsigned int irq;
17811776
int err;
1782-
int eqn;
1783-
1784-
err = mlx5_vector2eqn(priv->mdev, ix, &eqn, &irq);
1785-
if (err)
1786-
return err;
1787-
1788-
c = kvzalloc_node(sizeof(*c), GFP_KERNEL, cpu_to_node(cpu));
1789-
if (!c)
1790-
return -ENOMEM;
1791-
1792-
c->priv = priv;
1793-
c->mdev = priv->mdev;
1794-
c->tstamp = &priv->tstamp;
1795-
c->ix = ix;
1796-
c->cpu = cpu;
1797-
c->pdev = priv->mdev->device;
1798-
c->netdev = priv->netdev;
1799-
c->mkey_be = cpu_to_be32(priv->mdev->mlx5e_res.mkey.key);
1800-
c->num_tc = params->num_tc;
1801-
c->xdp = !!params->xdp_prog;
1802-
c->stats = &priv->channel_stats[ix].ch;
1803-
c->irq_desc = irq_to_desc(irq);
1804-
1805-
err = mlx5e_alloc_xps_cpumask(c, params);
1806-
if (err)
1807-
goto err_free_channel;
1808-
1809-
netif_napi_add(netdev, &c->napi, mlx5e_napi_poll, 64);
18101777

18111778
err = mlx5e_open_cq(c, icocq_moder, &cparam->icosq_cq, &c->icosq.cq);
18121779
if (err)
1813-
goto err_napi_del;
1780+
return err;
18141781

18151782
err = mlx5e_open_tx_cqs(c, params, cparam);
18161783
if (err)
@@ -1855,8 +1822,6 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
18551822
if (err)
18561823
goto err_close_rq;
18571824

1858-
*cp = c;
1859-
18601825
return 0;
18611826

18621827
err_close_rq:
@@ -1874,6 +1839,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
18741839

18751840
err_disable_napi:
18761841
napi_disable(&c->napi);
1842+
18771843
if (c->xdp)
18781844
mlx5e_close_cq(&c->rq_xdpsq.cq);
18791845

@@ -1889,6 +1855,73 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
18891855
err_close_icosq_cq:
18901856
mlx5e_close_cq(&c->icosq.cq);
18911857

1858+
return err;
1859+
}
1860+
1861+
static void mlx5e_close_queues(struct mlx5e_channel *c)
1862+
{
1863+
mlx5e_close_xdpsq(&c->xdpsq);
1864+
mlx5e_close_rq(&c->rq);
1865+
if (c->xdp)
1866+
mlx5e_close_xdpsq(&c->rq_xdpsq);
1867+
mlx5e_close_sqs(c);
1868+
mlx5e_close_icosq(&c->icosq);
1869+
napi_disable(&c->napi);
1870+
if (c->xdp)
1871+
mlx5e_close_cq(&c->rq_xdpsq.cq);
1872+
mlx5e_close_cq(&c->rq.cq);
1873+
mlx5e_close_cq(&c->xdpsq.cq);
1874+
mlx5e_close_tx_cqs(c);
1875+
mlx5e_close_cq(&c->icosq.cq);
1876+
}
1877+
1878+
static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1879+
struct mlx5e_params *params,
1880+
struct mlx5e_channel_param *cparam,
1881+
struct mlx5e_channel **cp)
1882+
{
1883+
int cpu = cpumask_first(mlx5_comp_irq_get_affinity_mask(priv->mdev, ix));
1884+
struct net_device *netdev = priv->netdev;
1885+
struct mlx5e_channel *c;
1886+
unsigned int irq;
1887+
int err;
1888+
int eqn;
1889+
1890+
err = mlx5_vector2eqn(priv->mdev, ix, &eqn, &irq);
1891+
if (err)
1892+
return err;
1893+
1894+
c = kvzalloc_node(sizeof(*c), GFP_KERNEL, cpu_to_node(cpu));
1895+
if (!c)
1896+
return -ENOMEM;
1897+
1898+
c->priv = priv;
1899+
c->mdev = priv->mdev;
1900+
c->tstamp = &priv->tstamp;
1901+
c->ix = ix;
1902+
c->cpu = cpu;
1903+
c->pdev = priv->mdev->device;
1904+
c->netdev = priv->netdev;
1905+
c->mkey_be = cpu_to_be32(priv->mdev->mlx5e_res.mkey.key);
1906+
c->num_tc = params->num_tc;
1907+
c->xdp = !!params->xdp_prog;
1908+
c->stats = &priv->channel_stats[ix].ch;
1909+
c->irq_desc = irq_to_desc(irq);
1910+
1911+
err = mlx5e_alloc_xps_cpumask(c, params);
1912+
if (err)
1913+
goto err_free_channel;
1914+
1915+
netif_napi_add(netdev, &c->napi, mlx5e_napi_poll, 64);
1916+
1917+
err = mlx5e_open_queues(c, params, cparam);
1918+
if (unlikely(err))
1919+
goto err_napi_del;
1920+
1921+
*cp = c;
1922+
1923+
return 0;
1924+
18921925
err_napi_del:
18931926
netif_napi_del(&c->napi);
18941927
mlx5e_free_xps_cpumask(c);
@@ -1920,19 +1953,7 @@ static void mlx5e_deactivate_channel(struct mlx5e_channel *c)
19201953

19211954
static void mlx5e_close_channel(struct mlx5e_channel *c)
19221955
{
1923-
mlx5e_close_xdpsq(&c->xdpsq);
1924-
mlx5e_close_rq(&c->rq);
1925-
if (c->xdp)
1926-
mlx5e_close_xdpsq(&c->rq_xdpsq);
1927-
mlx5e_close_sqs(c);
1928-
mlx5e_close_icosq(&c->icosq);
1929-
napi_disable(&c->napi);
1930-
if (c->xdp)
1931-
mlx5e_close_cq(&c->rq_xdpsq.cq);
1932-
mlx5e_close_cq(&c->rq.cq);
1933-
mlx5e_close_cq(&c->xdpsq.cq);
1934-
mlx5e_close_tx_cqs(c);
1935-
mlx5e_close_cq(&c->icosq.cq);
1956+
mlx5e_close_queues(c);
19361957
netif_napi_del(&c->napi);
19371958
mlx5e_free_xps_cpumask(c);
19381959

0 commit comments

Comments
 (0)