[net-next,1/1] net: stmmac: check CBS input values before configuration

Message ID 20231027061114.3792619-1-yi.fang.gan@intel.com
State New
Headers
Series [net-next,1/1] net: stmmac: check CBS input values before configuration |

Commit Message

Gan, Yi Fang Oct. 27, 2023, 6:11 a.m. UTC
  From: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>

Add check for below conditions before proceeding to configuration.
A message will be prompted if the input value is invalid.

Idleslope minus sendslope should equal speed_div.
Idleslope is always a positive value.
Sendslope is always a negative value.
Hicredit is always a positive value.
Locredit is always a negative value.

Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
Signed-off-by: Gan, Yi Fang <yi.fang.gan@intel.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Wojciech Drewek Oct. 27, 2023, 10:07 a.m. UTC | #1
On 27.10.2023 08:11, Gan Yi Fang wrote:
> From: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
> 
> Add check for below conditions before proceeding to configuration.
> A message will be prompted if the input value is invalid.
> 
> Idleslope minus sendslope should equal speed_div.
> Idleslope is always a positive value.
> Sendslope is always a negative value.
> Hicredit is always a positive value.
> Locredit is always a negative value.

Can those values be equal to 0? The code allows it but the commit msg doesn't mention that.
Some drivers does not allow 0, lan966x_cbs_add e.g. Would be good to double check that.

> 
> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
> Signed-off-by: Gan, Yi Fang <yi.fang.gan@intel.com>
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> index ac41ef4cbd2f..e8a079946f84 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> @@ -381,6 +381,11 @@ static int tc_setup_cbs(struct stmmac_priv *priv,
>  		return -EOPNOTSUPP;
>  	}
>  
> +	if ((qopt->idleslope - qopt->sendslope != speed_div) ||
> +	    qopt->idleslope < 0 || qopt->sendslope > 0 ||
> +	    qopt->hicredit < 0 || qopt->locredit > 0)
> +		return -EINVAL;
> +
>  	mode_to_use = priv->plat->tx_queues_cfg[queue].mode_to_use;
>  	if (mode_to_use == MTL_QUEUE_DCB && qopt->enable) {
>  		ret = stmmac_dma_qmode(priv, priv->ioaddr, queue, MTL_QUEUE_AVB);
  
Gan, Yi Fang Oct. 31, 2023, 3:11 a.m. UTC | #2
Hi,

Value zero is allowed. I will update V2 with the commit msg updated.

Best regards,
Gan Yi Fang

> -----Original Message-----
> From: Drewek, Wojciech <wojciech.drewek@intel.com>
> Sent: Friday, October 27, 2023 6:08 PM
> To: Gan, Yi Fang <yi.fang.gan@intel.com>; Alexandre Torgue
> <alexandre.torgue@foss.st.com>; Jose Abreu <joabreu@synopsys.com>;
> David S . Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Maxime Coquelin <mcoquelin.stm32@gmail.com>;
> netdev@vger.kernel.org; linux-stm32@st-md-mailman.stormreply.com; linux-
> arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org
> Cc: Looi, Hong Aun <hong.aun.looi@intel.com>; Voon, Weifeng
> <weifeng.voon@intel.com>; Song, Yoong Siang
> <yoong.siang.song@intel.com>; Sit, Michael Wei Hong
> <michael.wei.hong.sit@intel.com>
> Subject: Re: [PATCH net-next 1/1] net: stmmac: check CBS input values before
> configuration
> 
> 
> 
> On 27.10.2023 08:11, Gan Yi Fang wrote:
> > From: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
> >
> > Add check for below conditions before proceeding to configuration.
> > A message will be prompted if the input value is invalid.
> >
> > Idleslope minus sendslope should equal speed_div.
> > Idleslope is always a positive value.
> > Sendslope is always a negative value.
> > Hicredit is always a positive value.
> > Locredit is always a negative value.
> 
> Can those values be equal to 0? The code allows it but the commit msg
> doesn't mention that.
> Some drivers does not allow 0, lan966x_cbs_add e.g. Would be good to
> double check that.
> 
> >
> > Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
> > Signed-off-by: Gan, Yi Fang <yi.fang.gan@intel.com>
> > ---
> >  drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> > index ac41ef4cbd2f..e8a079946f84 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> > @@ -381,6 +381,11 @@ static int tc_setup_cbs(struct stmmac_priv *priv,
> >  		return -EOPNOTSUPP;
> >  	}
> >
> > +	if ((qopt->idleslope - qopt->sendslope != speed_div) ||
> > +	    qopt->idleslope < 0 || qopt->sendslope > 0 ||
> > +	    qopt->hicredit < 0 || qopt->locredit > 0)
> > +		return -EINVAL;
> > +
> >  	mode_to_use = priv->plat->tx_queues_cfg[queue].mode_to_use;
> >  	if (mode_to_use == MTL_QUEUE_DCB && qopt->enable) {
> >  		ret = stmmac_dma_qmode(priv, priv->ioaddr, queue,
> MTL_QUEUE_AVB);
  

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
index ac41ef4cbd2f..e8a079946f84 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
@@ -381,6 +381,11 @@  static int tc_setup_cbs(struct stmmac_priv *priv,
 		return -EOPNOTSUPP;
 	}
 
+	if ((qopt->idleslope - qopt->sendslope != speed_div) ||
+	    qopt->idleslope < 0 || qopt->sendslope > 0 ||
+	    qopt->hicredit < 0 || qopt->locredit > 0)
+		return -EINVAL;
+
 	mode_to_use = priv->plat->tx_queues_cfg[queue].mode_to_use;
 	if (mode_to_use == MTL_QUEUE_DCB && qopt->enable) {
 		ret = stmmac_dma_qmode(priv, priv->ioaddr, queue, MTL_QUEUE_AVB);