Commit 0e1a4d42 authored by Breno Leitao's avatar Breno Leitao Committed by Jakub Kicinski

crypto: caam: Unembed net_dev structure in dpaa2

Embedding net_device into structures prohibits the usage of flexible
arrays in the net_device structure. For more details, see the discussion
at [1].

Un-embed the net_devices from struct dpaa2_caam_priv_per_cpu by
converting them into pointers, and allocating them dynamically. Use the
leverage alloc_netdev_dummy() to allocate the net_device object at
dpaa2_dpseci_setup().

The free of the device occurs at dpaa2_dpseci_disable().

Link: https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ [1]
Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
Link: https://patch.msgid.link/20240702185557.3699991-5-leitao@debian.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 82c81e74
...@@ -4990,11 +4990,23 @@ static int dpaa2_dpseci_congestion_setup(struct dpaa2_caam_priv *priv, ...@@ -4990,11 +4990,23 @@ static int dpaa2_dpseci_congestion_setup(struct dpaa2_caam_priv *priv,
return err; return err;
} }
static void free_dpaa2_pcpu_netdev(struct dpaa2_caam_priv *priv, const cpumask_t *cpus)
{
struct dpaa2_caam_priv_per_cpu *ppriv;
int i;
for_each_cpu(i, cpus) {
ppriv = per_cpu_ptr(priv->ppriv, i);
free_netdev(ppriv->net_dev);
}
}
static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev) static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
{ {
struct device *dev = &ls_dev->dev; struct device *dev = &ls_dev->dev;
struct dpaa2_caam_priv *priv; struct dpaa2_caam_priv *priv;
struct dpaa2_caam_priv_per_cpu *ppriv; struct dpaa2_caam_priv_per_cpu *ppriv;
cpumask_t clean_mask;
int err, cpu; int err, cpu;
u8 i; u8 i;
...@@ -5073,6 +5085,7 @@ static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev) ...@@ -5073,6 +5085,7 @@ static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
} }
} }
cpumask_clear(&clean_mask);
i = 0; i = 0;
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
u8 j; u8 j;
...@@ -5096,15 +5109,23 @@ static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev) ...@@ -5096,15 +5109,23 @@ static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
priv->rx_queue_attr[j].fqid, priv->rx_queue_attr[j].fqid,
priv->tx_queue_attr[j].fqid); priv->tx_queue_attr[j].fqid);
ppriv->net_dev.dev = *dev; ppriv->net_dev = alloc_netdev_dummy(0);
INIT_LIST_HEAD(&ppriv->net_dev.napi_list); if (!ppriv->net_dev) {
netif_napi_add_tx_weight(&ppriv->net_dev, &ppriv->napi, err = -ENOMEM;
goto err_alloc_netdev;
}
cpumask_set_cpu(cpu, &clean_mask);
ppriv->net_dev->dev = *dev;
netif_napi_add_tx_weight(ppriv->net_dev, &ppriv->napi,
dpaa2_dpseci_poll, dpaa2_dpseci_poll,
DPAA2_CAAM_NAPI_WEIGHT); DPAA2_CAAM_NAPI_WEIGHT);
} }
return 0; return 0;
err_alloc_netdev:
free_dpaa2_pcpu_netdev(priv, &clean_mask);
err_get_rx_queue: err_get_rx_queue:
dpaa2_dpseci_congestion_free(priv); dpaa2_dpseci_congestion_free(priv);
err_get_vers: err_get_vers:
...@@ -5153,6 +5174,7 @@ static int __cold dpaa2_dpseci_disable(struct dpaa2_caam_priv *priv) ...@@ -5153,6 +5174,7 @@ static int __cold dpaa2_dpseci_disable(struct dpaa2_caam_priv *priv)
ppriv = per_cpu_ptr(priv->ppriv, i); ppriv = per_cpu_ptr(priv->ppriv, i);
napi_disable(&ppriv->napi); napi_disable(&ppriv->napi);
netif_napi_del(&ppriv->napi); netif_napi_del(&ppriv->napi);
free_netdev(ppriv->net_dev);
} }
return 0; return 0;
......
...@@ -81,7 +81,7 @@ struct dpaa2_caam_priv { ...@@ -81,7 +81,7 @@ struct dpaa2_caam_priv {
*/ */
struct dpaa2_caam_priv_per_cpu { struct dpaa2_caam_priv_per_cpu {
struct napi_struct napi; struct napi_struct napi;
struct net_device net_dev; struct net_device *net_dev;
int req_fqid; int req_fqid;
int rsp_fqid; int rsp_fqid;
int prio; int prio;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment