2023-12-14 11:35:26

by Claudiu

[permalink] [raw]
Subject: [PATCH net 0/2] net: ravb: fixes for the ravb driver

From: Claudiu Beznea <[email protected]>

Hi,

Series adds two fixes for the ravb driver. Fixes adapt the code to comply
with the hardware manual requirements.

Thank you,
Claudiu Beznea

Claudiu Beznea (2):
net: ravb: Wait for operation mode to be applied
net: ravb: Check that GTI loading request is done

drivers/net/ethernet/renesas/ravb_main.c | 55 ++++++++++++++++++++----
1 file changed, 47 insertions(+), 8 deletions(-)

--
2.39.2


2023-12-14 11:35:41

by Claudiu

[permalink] [raw]
Subject: [PATCH net 1/2] net: ravb: Wait for operation mode to be applied

From: Claudiu Beznea <[email protected]>

CSR.OPS bits specify the current operating mode and (according to
documentation) they are updated when the operating mode change request
is processed. Thus, check CSR.OPS before proceeding.

Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
Fixes: 3e3d647715d4 ("ravb: add wake-on-lan support via magic packet")
Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
Signed-off-by: Claudiu Beznea <[email protected]>
---
drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++----
1 file changed, 39 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 9178f6d60e74..ce95eb5af354 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -683,8 +683,11 @@ static int ravb_dmac_init(struct net_device *ndev)

/* Setting the control will start the AVB-DMAC process. */
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
+ error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_OPERATION);
+ if (error)
+ netdev_err(ndev, "failed to switch device to operation mode\n");

- return 0;
+ return error;
}

static void ravb_get_tx_tstamp(struct net_device *ndev)
@@ -1744,6 +1747,18 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
return error;
}

+static int ravb_set_reset_mode(struct net_device *ndev)
+{
+ int error;
+
+ ravb_write(ndev, CCC_OPC_RESET, CCC);
+ error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_RESET);
+ if (error)
+ netdev_err(ndev, "failed to switch device to reset mode\n");
+
+ return error;
+}
+
/* Network device open function for Ethernet AVB */
static int ravb_open(struct net_device *ndev)
{
@@ -2551,10 +2566,11 @@ static int ravb_set_gti(struct net_device *ndev)
return 0;
}

-static void ravb_set_config_mode(struct net_device *ndev)
+static int ravb_set_config_mode(struct net_device *ndev)
{
struct ravb_private *priv = netdev_priv(ndev);
const struct ravb_hw_info *info = priv->info;
+ int error;

if (info->gptp) {
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
@@ -2566,6 +2582,12 @@ static void ravb_set_config_mode(struct net_device *ndev)
} else {
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
}
+
+ error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_CONFIG);
+ if (error)
+ netdev_err(ndev, "failed to switch device to config mode\n");
+
+ return error;
}

/* Set tx and rx clock internal delay modes */
@@ -2785,7 +2807,9 @@ static int ravb_probe(struct platform_device *pdev)
ndev->ethtool_ops = &ravb_ethtool_ops;

/* Set AVB config mode */
- ravb_set_config_mode(ndev);
+ error = ravb_set_config_mode(ndev);
+ if (error)
+ goto out_disable_refclk;

if (info->gptp || info->ccc_gac) {
/* Set GTI value */
@@ -2893,6 +2917,7 @@ static void ravb_remove(struct platform_device *pdev)
struct net_device *ndev = platform_get_drvdata(pdev);
struct ravb_private *priv = netdev_priv(ndev);
const struct ravb_hw_info *info = priv->info;
+ int error;

unregister_netdev(ndev);
if (info->nc_queues)
@@ -2908,8 +2933,9 @@ static void ravb_remove(struct platform_device *pdev)
dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
priv->desc_bat_dma);

- /* Set reset mode */
- ravb_write(ndev, CCC_OPC_RESET, CCC);
+ error = ravb_set_reset_mode(ndev);
+ if (error)
+ netdev_err(ndev, "Failed to reset ndev\n");

clk_disable_unprepare(priv->gptp_clk);
clk_disable_unprepare(priv->refclk);
@@ -2991,8 +3017,11 @@ static int __maybe_unused ravb_resume(struct device *dev)
int ret = 0;

/* If WoL is enabled set reset mode to rearm the WoL logic */
- if (priv->wol_enabled)
- ravb_write(ndev, CCC_OPC_RESET, CCC);
+ if (priv->wol_enabled) {
+ ret = ravb_set_reset_mode(ndev);
+ if (ret)
+ return ret;
+ }

/* All register have been reset to default values.
* Restore all registers which where setup at probe time and
@@ -3000,7 +3029,9 @@ static int __maybe_unused ravb_resume(struct device *dev)
*/

/* Set AVB config mode */
- ravb_set_config_mode(ndev);
+ ret = ravb_set_config_mode(ndev);
+ if (ret)
+ return ret;

if (info->gptp || info->ccc_gac) {
/* Set GTI value */
--
2.39.2

2023-12-14 11:35:42

by Claudiu

[permalink] [raw]
Subject: [PATCH net 2/2] net: ravb: Check that GTI loading request is done

From: Claudiu Beznea <[email protected]>

Hardware manual specifies the following for GCCR.LTI bit:
0: Setting completed
1: When written: Issue a configuration request.
When read: Completion of settings is pending

Thus, check the completion status when setting 1 to GCCR.LTI.

Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
Signed-off-by: Claudiu Beznea <[email protected]>
---
drivers/net/ethernet/renesas/ravb_main.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index ce95eb5af354..1c253403a297 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -2819,6 +2819,10 @@ static int ravb_probe(struct platform_device *pdev)

/* Request GTI loading */
ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
+ /* Check completion status. */
+ error = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
+ if (error)
+ goto out_disable_refclk;
}

if (info->internal_delay) {
@@ -3041,6 +3045,10 @@ static int __maybe_unused ravb_resume(struct device *dev)

/* Request GTI loading */
ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
+ /* Check completion status. */
+ ret = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
+ if (ret)
+ return ret;
}

if (info->internal_delay)
--
2.39.2

2023-12-14 12:12:39

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH net 1/2] net: ravb: Wait for operation mode to be applied

Hi Claudiu,

Thanks for your patch.

On 2023-12-14 13:31:36 +0200, Claudiu wrote:
> From: Claudiu Beznea <[email protected]>
>
> CSR.OPS bits specify the current operating mode and (according to
> documentation) they are updated when the operating mode change request
> is processed. Thus, check CSR.OPS before proceeding.
>
> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
> Fixes: 3e3d647715d4 ("ravb: add wake-on-lan support via magic packet")
> Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")

I think the list of fixes tags can be reduced. The last item in the list
is the patch which adds the RAVB driver so what's the point of listing
the rest?

> Signed-off-by: Claudiu Beznea <[email protected]>
> ---
> drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++----
> 1 file changed, 39 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index 9178f6d60e74..ce95eb5af354 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -683,8 +683,11 @@ static int ravb_dmac_init(struct net_device *ndev)
>
> /* Setting the control will start the AVB-DMAC process. */
> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_OPERATION);
> + if (error)
> + netdev_err(ndev, "failed to switch device to operation mode\n");

As you add ravb_set_reset_mode() to compliment the existing
ravb_set_config_mode(), would it not be coherent to also add a
ravb_set_operation_mode() instead of open coding it here?

>
> - return 0;
> + return error;
> }
>
> static void ravb_get_tx_tstamp(struct net_device *ndev)
> @@ -1744,6 +1747,18 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
> return error;
> }
>
> +static int ravb_set_reset_mode(struct net_device *ndev)

nit: Maybe move this to be close to ravb_set_config_mode() to co-locate
all mode changing logic?

> +{
> + int error;
> +
> + ravb_write(ndev, CCC_OPC_RESET, CCC);
> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_RESET);
> + if (error)
> + netdev_err(ndev, "failed to switch device to reset mode\n");
> +
> + return error;
> +}
> +
> /* Network device open function for Ethernet AVB */
> static int ravb_open(struct net_device *ndev)
> {
> @@ -2551,10 +2566,11 @@ static int ravb_set_gti(struct net_device *ndev)
> return 0;
> }
>
> -static void ravb_set_config_mode(struct net_device *ndev)
> +static int ravb_set_config_mode(struct net_device *ndev)
> {
> struct ravb_private *priv = netdev_priv(ndev);
> const struct ravb_hw_info *info = priv->info;
> + int error;
>
> if (info->gptp) {
> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
> @@ -2566,6 +2582,12 @@ static void ravb_set_config_mode(struct net_device *ndev)
> } else {
> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
> }
> +
> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_CONFIG);
> + if (error)
> + netdev_err(ndev, "failed to switch device to config mode\n");
> +
> + return error;
> }
>
> /* Set tx and rx clock internal delay modes */
> @@ -2785,7 +2807,9 @@ static int ravb_probe(struct platform_device *pdev)
> ndev->ethtool_ops = &ravb_ethtool_ops;
>
> /* Set AVB config mode */
> - ravb_set_config_mode(ndev);
> + error = ravb_set_config_mode(ndev);
> + if (error)
> + goto out_disable_refclk;
>
> if (info->gptp || info->ccc_gac) {
> /* Set GTI value */
> @@ -2893,6 +2917,7 @@ static void ravb_remove(struct platform_device *pdev)
> struct net_device *ndev = platform_get_drvdata(pdev);
> struct ravb_private *priv = netdev_priv(ndev);
> const struct ravb_hw_info *info = priv->info;
> + int error;
>
> unregister_netdev(ndev);
> if (info->nc_queues)
> @@ -2908,8 +2933,9 @@ static void ravb_remove(struct platform_device *pdev)
> dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
> priv->desc_bat_dma);
>
> - /* Set reset mode */
> - ravb_write(ndev, CCC_OPC_RESET, CCC);
> + error = ravb_set_reset_mode(ndev);
> + if (error)
> + netdev_err(ndev, "Failed to reset ndev\n");
>
> clk_disable_unprepare(priv->gptp_clk);
> clk_disable_unprepare(priv->refclk);
> @@ -2991,8 +3017,11 @@ static int __maybe_unused ravb_resume(struct device *dev)
> int ret = 0;
>
> /* If WoL is enabled set reset mode to rearm the WoL logic */
> - if (priv->wol_enabled)
> - ravb_write(ndev, CCC_OPC_RESET, CCC);
> + if (priv->wol_enabled) {
> + ret = ravb_set_reset_mode(ndev);
> + if (ret)
> + return ret;
> + }
>
> /* All register have been reset to default values.
> * Restore all registers which where setup at probe time and
> @@ -3000,7 +3029,9 @@ static int __maybe_unused ravb_resume(struct device *dev)
> */
>
> /* Set AVB config mode */
> - ravb_set_config_mode(ndev);
> + ret = ravb_set_config_mode(ndev);
> + if (ret)
> + return ret;
>
> if (info->gptp || info->ccc_gac) {
> /* Set GTI value */
> --
> 2.39.2
>

--
Kind Regards,
Niklas Söderlund

2023-12-14 12:33:45

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH net 2/2] net: ravb: Check that GTI loading request is done

Hi Claudiu,

Thanks for your work.

On 2023-12-14 13:31:37 +0200, Claudiu wrote:
> From: Claudiu Beznea <[email protected]>
>
> Hardware manual specifies the following for GCCR.LTI bit:
> 0: Setting completed
> 1: When written: Issue a configuration request.
> When read: Completion of settings is pending

This is hard to parse at first glance, the last row have odd indentation
and the mixing of read and write info is odd. I know this reflects how
it's written in the datasheet, but at least there the indentation is
correct. Also missing here is the fact that only 1 can be written to the
bit.

>
> Thus, check the completion status when setting 1 to GCCR.LTI.

Can you describe in the commit why this fix is needed. I agree it is,
but would be nice to record why. As this have a fixes tags have you hit
an issue? Or are you correcting the driver based on the datasheet?

Maybe a more informative commit message could be to describe the change
and why it's needed instead of the register layout?

The driver do not wait for the confirmation of the configuring request
of the gPTP timer increment before moving on. Add a check to make sure
the request completes successfully.

>
> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
> Signed-off-by: Claudiu Beznea <[email protected]>
> ---
> drivers/net/ethernet/renesas/ravb_main.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index ce95eb5af354..1c253403a297 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -2819,6 +2819,10 @@ static int ravb_probe(struct platform_device *pdev)
>
> /* Request GTI loading */
> ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
> + /* Check completion status. */
> + error = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
> + if (error)
> + goto out_disable_refclk;

nit: Maybe create a helper for this so future fixes only need to be
addressed in one location?

> }
>
> if (info->internal_delay) {
> @@ -3041,6 +3045,10 @@ static int __maybe_unused ravb_resume(struct device *dev)
>
> /* Request GTI loading */
> ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
> + /* Check completion status. */
> + ret = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
> + if (ret)
> + return ret;
> }
>
> if (info->internal_delay)
> --
> 2.39.2
>

--
Kind Regards,
Niklas Söderlund

2023-12-14 12:39:59

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH net 1/2] net: ravb: Wait for operation mode to be applied

On 2023-12-14 14:25:57 +0200, claudiu beznea wrote:
> Hi, Niklas,
>
> On 14.12.2023 14:11, Niklas Söderlund wrote:
> > Hi Claudiu,
> >
> > Thanks for your patch.
> >
> > On 2023-12-14 13:31:36 +0200, Claudiu wrote:
> >> From: Claudiu Beznea <[email protected]>
> >>
> >> CSR.OPS bits specify the current operating mode and (according to
> >> documentation) they are updated when the operating mode change request
> >> is processed. Thus, check CSR.OPS before proceeding.
> >>
> >> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
> >> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
> >> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
> >> Fixes: 3e3d647715d4 ("ravb: add wake-on-lan support via magic packet")
> >> Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
> >
> > I think the list of fixes tags can be reduced. The last item in the list
> > is the patch which adds the RAVB driver so what's the point of listing
> > the rest?
>
> In commit c156633f1353 ("Renesas Ethernet AVB driver proper") different
> features that were touched by the rest of commits in the fixes list might
> not be present. So, it might be possible that this patch to not be
> back-portable to c156633f1353 ("Renesas Ethernet AVB driver proper") but to
> other commits in the list.

All the other commits depends on commit c156633f1353 ("Renesas Ethernet
AVB driver proper"). It would be hard to add wake-on-lan to a driver
that do not exists :-)

I do not feel strongly about this so keep it as if if you wish, I just
think it looks odd.

>
> >
> >> Signed-off-by: Claudiu Beznea <[email protected]>
> >> ---
> >> drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++----
> >> 1 file changed, 39 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> >> index 9178f6d60e74..ce95eb5af354 100644
> >> --- a/drivers/net/ethernet/renesas/ravb_main.c
> >> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> >> @@ -683,8 +683,11 @@ static int ravb_dmac_init(struct net_device *ndev)
> >>
> >> /* Setting the control will start the AVB-DMAC process. */
> >> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
> >> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_OPERATION);
> >> + if (error)
> >> + netdev_err(ndev, "failed to switch device to operation mode\n");
> >
> > As you add ravb_set_reset_mode() to compliment the existing
> > ravb_set_config_mode(), would it not be coherent to also add a
> > ravb_set_operation_mode() instead of open coding it here?
>
> CSR_OPS_OPERATION is set only in this place. Reset is done in more than one
> place. Due to this I've added a function for it.

OK. Then maybe add a generic change mode operation like rswitch do in
rswitch_gwca_change_mode() ? That way you ensure any future mode changes
will always confirm the change is successful ? I'm a but worried that
future changes might forget to add the ravb_wait() to confirm a mode
change is successful and a good helper could avoid that.

>
> >
> >>
> >> - return 0;
> >> + return error;
> >> }
> >>
> >> static void ravb_get_tx_tstamp(struct net_device *ndev)
> >> @@ -1744,6 +1747,18 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
> >> return error;
> >> }
> >>
> >> +static int ravb_set_reset_mode(struct net_device *ndev)
> >
> > nit: Maybe move this to be close to ravb_set_config_mode() to co-locate
> > all mode changing logic?
>
> I've did this but not in this patch. It could be found on the final version
> of the driver proposed by
> https://lore.kernel.org/all/[email protected]/

Why not add it in the final intended location straight away then moving
it around in a later patch? This just makes the later patch harder to
review as it moves more code around.

>
> Thank you for your review,
> Claudiu Beznea
>
> >
> >> +{
> >> + int error;
> >> +
> >> + ravb_write(ndev, CCC_OPC_RESET, CCC);
> >> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_RESET);
> >> + if (error)
> >> + netdev_err(ndev, "failed to switch device to reset mode\n");
> >> +
> >> + return error;
> >> +}
> >> +
> >> /* Network device open function for Ethernet AVB */
> >> static int ravb_open(struct net_device *ndev)
> >> {
> >> @@ -2551,10 +2566,11 @@ static int ravb_set_gti(struct net_device *ndev)
> >> return 0;
> >> }
> >>
> >> -static void ravb_set_config_mode(struct net_device *ndev)
> >> +static int ravb_set_config_mode(struct net_device *ndev)
> >> {
> >> struct ravb_private *priv = netdev_priv(ndev);
> >> const struct ravb_hw_info *info = priv->info;
> >> + int error;
> >>
> >> if (info->gptp) {
> >> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
> >> @@ -2566,6 +2582,12 @@ static void ravb_set_config_mode(struct net_device *ndev)
> >> } else {
> >> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
> >> }
> >> +
> >> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_CONFIG);
> >> + if (error)
> >> + netdev_err(ndev, "failed to switch device to config mode\n");
> >> +
> >> + return error;
> >> }
> >>
> >> /* Set tx and rx clock internal delay modes */
> >> @@ -2785,7 +2807,9 @@ static int ravb_probe(struct platform_device *pdev)
> >> ndev->ethtool_ops = &ravb_ethtool_ops;
> >>
> >> /* Set AVB config mode */
> >> - ravb_set_config_mode(ndev);
> >> + error = ravb_set_config_mode(ndev);
> >> + if (error)
> >> + goto out_disable_refclk;
> >>
> >> if (info->gptp || info->ccc_gac) {
> >> /* Set GTI value */
> >> @@ -2893,6 +2917,7 @@ static void ravb_remove(struct platform_device *pdev)
> >> struct net_device *ndev = platform_get_drvdata(pdev);
> >> struct ravb_private *priv = netdev_priv(ndev);
> >> const struct ravb_hw_info *info = priv->info;
> >> + int error;
> >>
> >> unregister_netdev(ndev);
> >> if (info->nc_queues)
> >> @@ -2908,8 +2933,9 @@ static void ravb_remove(struct platform_device *pdev)
> >> dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
> >> priv->desc_bat_dma);
> >>
> >> - /* Set reset mode */
> >> - ravb_write(ndev, CCC_OPC_RESET, CCC);
> >> + error = ravb_set_reset_mode(ndev);
> >> + if (error)
> >> + netdev_err(ndev, "Failed to reset ndev\n");
> >>
> >> clk_disable_unprepare(priv->gptp_clk);
> >> clk_disable_unprepare(priv->refclk);
> >> @@ -2991,8 +3017,11 @@ static int __maybe_unused ravb_resume(struct device *dev)
> >> int ret = 0;
> >>
> >> /* If WoL is enabled set reset mode to rearm the WoL logic */
> >> - if (priv->wol_enabled)
> >> - ravb_write(ndev, CCC_OPC_RESET, CCC);
> >> + if (priv->wol_enabled) {
> >> + ret = ravb_set_reset_mode(ndev);
> >> + if (ret)
> >> + return ret;
> >> + }
> >>
> >> /* All register have been reset to default values.
> >> * Restore all registers which where setup at probe time and
> >> @@ -3000,7 +3029,9 @@ static int __maybe_unused ravb_resume(struct device *dev)
> >> */
> >>
> >> /* Set AVB config mode */
> >> - ravb_set_config_mode(ndev);
> >> + ret = ravb_set_config_mode(ndev);
> >> + if (ret)
> >> + return ret;
> >>
> >> if (info->gptp || info->ccc_gac) {
> >> /* Set GTI value */
> >> --
> >> 2.39.2
> >>
> >

--
Kind Regards,
Niklas Söderlund

2023-12-14 19:57:34

by Sergey Shtylyov

[permalink] [raw]
Subject: Re: [PATCH net 1/2] net: ravb: Wait for operation mode to be applied

resetOn 12/14/23 2:31 PM, Claudiu wrote:

> From: Claudiu Beznea <[email protected]>
>
> CSR.OPS bits specify the current operating mode and (according to
> documentation) they are updated when the operating mode change request
> is processed. Thus, check CSR.OPS before proceeding.

The manuals I have indeed say we need to check CSR.OPS... But we only
need to wait iff we transfer from the operation mode to the config mode...

> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
> Fixes: 3e3d647715d4 ("ravb: add wake-on-lan support via magic packet")
> Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")

Hm, that long list does look weird...

> Signed-off-by: Claudiu Beznea <[email protected]>
> ---
> drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++----
> 1 file changed, 39 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index 9178f6d60e74..ce95eb5af354 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -683,8 +683,11 @@ static int ravb_dmac_init(struct net_device *ndev)
>
> /* Setting the control will start the AVB-DMAC process. */
> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_OPERATION);
> + if (error)
> + netdev_err(ndev, "failed to switch device to operation mode\n");

It doesn't look like ravb_wait() is needed here...
And besides, this pattern seems repetitive and worth factoring out into
a single function.

[...]
> @@ -1744,6 +1747,18 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
> return error;
> }
>
> +static int ravb_set_reset_mode(struct net_device *ndev)
> +{
> + int error;
> +
> + ravb_write(ndev, CCC_OPC_RESET, CCC);
> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_RESET);
> + if (error)
> + netdev_err(ndev, "failed to switch device to reset mode\n");
> +
> + return error;
> +}
> +

Again, ravb_wait() call doesn't seem necessary here...

[...]

MBR, Sergey

2023-12-14 20:22:40

by Sergey Shtylyov

[permalink] [raw]
Subject: Re: [PATCH net 2/2] net: ravb: Check that GTI loading request is done

On 12/14/23 2:31 PM, Claudiu wrote:

> From: Claudiu Beznea <[email protected]>
>
> Hardware manual specifies the following for GCCR.LTI bit:
> 0: Setting completed
> 1: When written: Issue a configuration request.
> When read: Completion of settings is pending
>
> Thus, check the completion status when setting 1 to GCCR.LTI.

But do we really need to? Seems quite dubious... currently we
just let it the loading complete asynchronously...

> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
> Signed-off-by: Claudiu Beznea <[email protected]>
> ---
> drivers/net/ethernet/renesas/ravb_main.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index ce95eb5af354..1c253403a297 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -2819,6 +2819,10 @@ static int ravb_probe(struct platform_device *pdev)
>
> /* Request GTI loading */
> ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
> + /* Check completion status. */
> + error = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
> + if (error)
> + goto out_disable_refclk;
> }
>
> if (info->internal_delay) {
> @@ -3041,6 +3045,10 @@ static int __maybe_unused ravb_resume(struct device *dev)
>
> /* Request GTI loading */
> ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
> + /* Check completion status. */
> + ret = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
> + if (ret)
> + return ret;
> }
>
> if (info->internal_delay)
>

BTW, seems worth factoring out into a separate function...

MBR, Sergey

2023-12-15 11:39:06

by Claudiu

[permalink] [raw]
Subject: Re: [PATCH net 2/2] net: ravb: Check that GTI loading request is done



On 14.12.2023 14:33, Niklas Söderlund wrote:
> Hi Claudiu,
>
> Thanks for your work.
>
> On 2023-12-14 13:31:37 +0200, Claudiu wrote:
>> From: Claudiu Beznea <[email protected]>
>>
>> Hardware manual specifies the following for GCCR.LTI bit:
>> 0: Setting completed
>> 1: When written: Issue a configuration request.
>> When read: Completion of settings is pending
>
> This is hard to parse at first glance, the last row have odd indentation
> and the mixing of read and write info is odd. I know this reflects how
> it's written in the datasheet, but at least there the indentation is
> correct. Also missing here is the fact that only 1 can be written to the
> bit.
>
>>
>> Thus, check the completion status when setting 1 to GCCR.LTI.
>
> Can you describe in the commit why this fix is needed. I agree it is,
> but would be nice to record why. As this have a fixes tags have you hit
> an issue? Or are you correcting the driver based on the datasheet?

Yes, this is a issue I faced while working on runtime PM support for this
driver.

>
> Maybe a more informative commit message could be to describe the change
> and why it's needed instead of the register layout?

ok

>
> The driver do not wait for the confirmation of the configuring request
> of the gPTP timer increment before moving on. Add a check to make sure
> the request completes successfully.
>
>>
>> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
>> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
>> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
>> Signed-off-by: Claudiu Beznea <[email protected]>
>> ---
>> drivers/net/ethernet/renesas/ravb_main.c | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
>> index ce95eb5af354..1c253403a297 100644
>> --- a/drivers/net/ethernet/renesas/ravb_main.c
>> +++ b/drivers/net/ethernet/renesas/ravb_main.c
>> @@ -2819,6 +2819,10 @@ static int ravb_probe(struct platform_device *pdev)
>>
>> /* Request GTI loading */
>> ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
>> + /* Check completion status. */
>> + error = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
>> + if (error)
>> + goto out_disable_refclk;
>
> nit: Maybe create a helper for this so future fixes only need to be
> addressed in one location?

The code intended for runtime PM support addresses this.

>
>> }
>>
>> if (info->internal_delay) {
>> @@ -3041,6 +3045,10 @@ static int __maybe_unused ravb_resume(struct device *dev)
>>
>> /* Request GTI loading */
>> ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
>> + /* Check completion status. */
>> + ret = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
>> + if (ret)
>> + return ret;
>> }
>>
>> if (info->internal_delay)
>> --
>> 2.39.2
>>
>

2023-12-15 15:00:17

by Claudiu

[permalink] [raw]
Subject: Re: [PATCH net 2/2] net: ravb: Check that GTI loading request is done



On 14.12.2023 22:22, Sergey Shtylyov wrote:
> On 12/14/23 2:31 PM, Claudiu wrote:
>
>> From: Claudiu Beznea <[email protected]>
>>
>> Hardware manual specifies the following for GCCR.LTI bit:
>> 0: Setting completed
>> 1: When written: Issue a configuration request.
>> When read: Completion of settings is pending
>>
>> Thus, check the completion status when setting 1 to GCCR.LTI.
>
> But do we really need to? Seems quite dubious... currently we
> just let it the loading complete asynchronously...

Now, thinking again at it... we should be safe w/o it (even though I said
we need it in a previous thread, I think I was wrong).

>
>> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
>> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
>> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
>> Signed-off-by: Claudiu Beznea <[email protected]>
>> ---
>> drivers/net/ethernet/renesas/ravb_main.c | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
>> index ce95eb5af354..1c253403a297 100644
>> --- a/drivers/net/ethernet/renesas/ravb_main.c
>> +++ b/drivers/net/ethernet/renesas/ravb_main.c
>> @@ -2819,6 +2819,10 @@ static int ravb_probe(struct platform_device *pdev)
>>
>> /* Request GTI loading */
>> ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
>> + /* Check completion status. */
>> + error = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
>> + if (error)
>> + goto out_disable_refclk;
>> }
>>
>> if (info->internal_delay) {
>> @@ -3041,6 +3045,10 @@ static int __maybe_unused ravb_resume(struct device *dev)
>>
>> /* Request GTI loading */
>> ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
>> + /* Check completion status. */
>> + ret = ravb_wait(ndev, GCCR, GCCR_LTI, 0);
>> + if (ret)
>> + return ret;
>> }
>>
>> if (info->internal_delay)
>>
>
> BTW, seems worth factoring out into a separate function...
>
> MBR, Sergey

2023-12-16 11:50:54

by Claudiu

[permalink] [raw]
Subject: Re: [PATCH net 1/2] net: ravb: Wait for operation mode to be applied



On 14.12.2023 21:41, Sergey Shtylyov wrote:
> resetOn 12/14/23 2:31 PM, Claudiu wrote:
>
>> From: Claudiu Beznea <[email protected]>
>>
>> CSR.OPS bits specify the current operating mode and (according to
>> documentation) they are updated when the operating mode change request
>> is processed. Thus, check CSR.OPS before proceeding.
>
> The manuals I have indeed say we need to check CSR.OPS... But we only
> need to wait iff we transfer from the operation mode to the config mode...

RZ/G3S manual say about CSR.OPS "These bits are updated when an operating
mode changes is processed". From this I get we need to check it for any mode.

Also, on configuration procedure (of RZ/G3S) it say CSR.OPS need to be
checked when switching from reset -> config.

>
>> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
>> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
>> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
>> Fixes: 3e3d647715d4 ("ravb: add wake-on-lan support via magic packet")
>> Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
>
> Hm, that long list does look weird...

OK, then I'll limit it to only c156633f1353 ("Renesas Ethernet AVB driver
proper"). Niklas also suggested this.

>
>> Signed-off-by: Claudiu Beznea <[email protected]>
>> ---
>> drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++----
>> 1 file changed, 39 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
>> index 9178f6d60e74..ce95eb5af354 100644
>> --- a/drivers/net/ethernet/renesas/ravb_main.c
>> +++ b/drivers/net/ethernet/renesas/ravb_main.c
>> @@ -683,8 +683,11 @@ static int ravb_dmac_init(struct net_device *ndev)
>>
>> /* Setting the control will start the AVB-DMAC process. */
>> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_OPERATION);
>> + if (error)
>> + netdev_err(ndev, "failed to switch device to operation mode\n");
>
> It doesn't look like ravb_wait() is needed here...
> And besides, this pattern seems repetitive and worth factoring out into
> a single function.

In the final version of the driver proposed by RPM series it is gone. I
tried to keep the fixes simple. I'll update it as Niklas also suggested this.

>
> [...]
>> @@ -1744,6 +1747,18 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
>> return error;
>> }
>>
>> +static int ravb_set_reset_mode(struct net_device *ndev)
>> +{
>> + int error;
>> +
>> + ravb_write(ndev, CCC_OPC_RESET, CCC);
>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_RESET);
>> + if (error)
>> + netdev_err(ndev, "failed to switch device to reset mode\n");
>> +
>> + return error;
>> +}
>> +
>
> Again, ravb_wait() call doesn't seem necessary here...

Ok. I followed the guideline from the description of CSR.OPS. Let me know
if you want to keep it or not. I think I haven't saw any issues w/o this.

>
> [...]
>
> MBR, Sergey

2023-12-16 11:53:04

by Claudiu

[permalink] [raw]
Subject: Re: [PATCH net 1/2] net: ravb: Wait for operation mode to be applied

Hi, Niklas,

On 14.12.2023 14:11, Niklas Söderlund wrote:
> Hi Claudiu,
>
> Thanks for your patch.
>
> On 2023-12-14 13:31:36 +0200, Claudiu wrote:
>> From: Claudiu Beznea <[email protected]>
>>
>> CSR.OPS bits specify the current operating mode and (according to
>> documentation) they are updated when the operating mode change request
>> is processed. Thus, check CSR.OPS before proceeding.
>>
>> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
>> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
>> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
>> Fixes: 3e3d647715d4 ("ravb: add wake-on-lan support via magic packet")
>> Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
>
> I think the list of fixes tags can be reduced. The last item in the list
> is the patch which adds the RAVB driver so what's the point of listing
> the rest?

In commit c156633f1353 ("Renesas Ethernet AVB driver proper") different
features that were touched by the rest of commits in the fixes list might
not be present. So, it might be possible that this patch to not be
back-portable to c156633f1353 ("Renesas Ethernet AVB driver proper") but to
other commits in the list.

>
>> Signed-off-by: Claudiu Beznea <[email protected]>
>> ---
>> drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++----
>> 1 file changed, 39 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
>> index 9178f6d60e74..ce95eb5af354 100644
>> --- a/drivers/net/ethernet/renesas/ravb_main.c
>> +++ b/drivers/net/ethernet/renesas/ravb_main.c
>> @@ -683,8 +683,11 @@ static int ravb_dmac_init(struct net_device *ndev)
>>
>> /* Setting the control will start the AVB-DMAC process. */
>> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_OPERATION);
>> + if (error)
>> + netdev_err(ndev, "failed to switch device to operation mode\n");
>
> As you add ravb_set_reset_mode() to compliment the existing
> ravb_set_config_mode(), would it not be coherent to also add a
> ravb_set_operation_mode() instead of open coding it here?

CSR_OPS_OPERATION is set only in this place. Reset is done in more than one
place. Due to this I've added a function for it.

>
>>
>> - return 0;
>> + return error;
>> }
>>
>> static void ravb_get_tx_tstamp(struct net_device *ndev)
>> @@ -1744,6 +1747,18 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
>> return error;
>> }
>>
>> +static int ravb_set_reset_mode(struct net_device *ndev)
>
> nit: Maybe move this to be close to ravb_set_config_mode() to co-locate
> all mode changing logic?

I've did this but not in this patch. It could be found on the final version
of the driver proposed by
https://lore.kernel.org/all/[email protected]/

Thank you for your review,
Claudiu Beznea

>
>> +{
>> + int error;
>> +
>> + ravb_write(ndev, CCC_OPC_RESET, CCC);
>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_RESET);
>> + if (error)
>> + netdev_err(ndev, "failed to switch device to reset mode\n");
>> +
>> + return error;
>> +}
>> +
>> /* Network device open function for Ethernet AVB */
>> static int ravb_open(struct net_device *ndev)
>> {
>> @@ -2551,10 +2566,11 @@ static int ravb_set_gti(struct net_device *ndev)
>> return 0;
>> }
>>
>> -static void ravb_set_config_mode(struct net_device *ndev)
>> +static int ravb_set_config_mode(struct net_device *ndev)
>> {
>> struct ravb_private *priv = netdev_priv(ndev);
>> const struct ravb_hw_info *info = priv->info;
>> + int error;
>>
>> if (info->gptp) {
>> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
>> @@ -2566,6 +2582,12 @@ static void ravb_set_config_mode(struct net_device *ndev)
>> } else {
>> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
>> }
>> +
>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_CONFIG);
>> + if (error)
>> + netdev_err(ndev, "failed to switch device to config mode\n");
>> +
>> + return error;
>> }
>>
>> /* Set tx and rx clock internal delay modes */
>> @@ -2785,7 +2807,9 @@ static int ravb_probe(struct platform_device *pdev)
>> ndev->ethtool_ops = &ravb_ethtool_ops;
>>
>> /* Set AVB config mode */
>> - ravb_set_config_mode(ndev);
>> + error = ravb_set_config_mode(ndev);
>> + if (error)
>> + goto out_disable_refclk;
>>
>> if (info->gptp || info->ccc_gac) {
>> /* Set GTI value */
>> @@ -2893,6 +2917,7 @@ static void ravb_remove(struct platform_device *pdev)
>> struct net_device *ndev = platform_get_drvdata(pdev);
>> struct ravb_private *priv = netdev_priv(ndev);
>> const struct ravb_hw_info *info = priv->info;
>> + int error;
>>
>> unregister_netdev(ndev);
>> if (info->nc_queues)
>> @@ -2908,8 +2933,9 @@ static void ravb_remove(struct platform_device *pdev)
>> dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
>> priv->desc_bat_dma);
>>
>> - /* Set reset mode */
>> - ravb_write(ndev, CCC_OPC_RESET, CCC);
>> + error = ravb_set_reset_mode(ndev);
>> + if (error)
>> + netdev_err(ndev, "Failed to reset ndev\n");
>>
>> clk_disable_unprepare(priv->gptp_clk);
>> clk_disable_unprepare(priv->refclk);
>> @@ -2991,8 +3017,11 @@ static int __maybe_unused ravb_resume(struct device *dev)
>> int ret = 0;
>>
>> /* If WoL is enabled set reset mode to rearm the WoL logic */
>> - if (priv->wol_enabled)
>> - ravb_write(ndev, CCC_OPC_RESET, CCC);
>> + if (priv->wol_enabled) {
>> + ret = ravb_set_reset_mode(ndev);
>> + if (ret)
>> + return ret;
>> + }
>>
>> /* All register have been reset to default values.
>> * Restore all registers which where setup at probe time and
>> @@ -3000,7 +3029,9 @@ static int __maybe_unused ravb_resume(struct device *dev)
>> */
>>
>> /* Set AVB config mode */
>> - ravb_set_config_mode(ndev);
>> + ret = ravb_set_config_mode(ndev);
>> + if (ret)
>> + return ret;
>>
>> if (info->gptp || info->ccc_gac) {
>> /* Set GTI value */
>> --
>> 2.39.2
>>
>

2023-12-16 11:54:00

by Claudiu

[permalink] [raw]
Subject: Re: [PATCH net 1/2] net: ravb: Wait for operation mode to be applied



On 14.12.2023 14:39, Niklas Söderlund wrote:
> On 2023-12-14 14:25:57 +0200, claudiu beznea wrote:
>> Hi, Niklas,
>>
>> On 14.12.2023 14:11, Niklas Söderlund wrote:
>>> Hi Claudiu,
>>>
>>> Thanks for your patch.
>>>
>>> On 2023-12-14 13:31:36 +0200, Claudiu wrote:
>>>> From: Claudiu Beznea <[email protected]>
>>>>
>>>> CSR.OPS bits specify the current operating mode and (according to
>>>> documentation) they are updated when the operating mode change request
>>>> is processed. Thus, check CSR.OPS before proceeding.
>>>>
>>>> Fixes: 568b3ce7a8ef ("ravb: factor out register bit twiddling code")
>>>> Fixes: 0184165b2f42 ("ravb: add sleep PM suspend/resume support")
>>>> Fixes: 7e09a052dc4e ("ravb: Exclude gPTP feature support for RZ/G2L")
>>>> Fixes: 3e3d647715d4 ("ravb: add wake-on-lan support via magic packet")
>>>> Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
>>>
>>> I think the list of fixes tags can be reduced. The last item in the list
>>> is the patch which adds the RAVB driver so what's the point of listing
>>> the rest?
>>
>> In commit c156633f1353 ("Renesas Ethernet AVB driver proper") different
>> features that were touched by the rest of commits in the fixes list might
>> not be present. So, it might be possible that this patch to not be
>> back-portable to c156633f1353 ("Renesas Ethernet AVB driver proper") but to
>> other commits in the list.
>
> All the other commits depends on commit c156633f1353 ("Renesas Ethernet
> AVB driver proper"). It would be hard to add wake-on-lan to a driver
> that do not exists :-)
>
> I do not feel strongly about this so keep it as if if you wish, I just
> think it looks odd.

I usually add here all the blamed commits. I can change it, I don't have
nothing against, this is how I did it till now.

>
>>
>>>
>>>> Signed-off-by: Claudiu Beznea <[email protected]>
>>>> ---
>>>> drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++----
>>>> 1 file changed, 39 insertions(+), 8 deletions(-)
>>>>
>>>> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
>>>> index 9178f6d60e74..ce95eb5af354 100644
>>>> --- a/drivers/net/ethernet/renesas/ravb_main.c
>>>> +++ b/drivers/net/ethernet/renesas/ravb_main.c
>>>> @@ -683,8 +683,11 @@ static int ravb_dmac_init(struct net_device *ndev)
>>>>
>>>> /* Setting the control will start the AVB-DMAC process. */
>>>> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
>>>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_OPERATION);
>>>> + if (error)
>>>> + netdev_err(ndev, "failed to switch device to operation mode\n");
>>>
>>> As you add ravb_set_reset_mode() to compliment the existing
>>> ravb_set_config_mode(), would it not be coherent to also add a
>>> ravb_set_operation_mode() instead of open coding it here?
>>
>> CSR_OPS_OPERATION is set only in this place. Reset is done in more than one
>> place. Due to this I've added a function for it.
>
> OK. Then maybe add a generic change mode operation like rswitch do in
> rswitch_gwca_change_mode() ? That way you ensure any future mode changes
> will always confirm the change is successful ? I'm a but worried that

ravb_set_config_mode() does things depending on gPTP, CCC_GAC.
ravb_set_reset_mode() just set CCC_OPC and goes out. Doing it like this
will move logic out of ravb_set_config_mode() (AFAICT) which will lead to
even complicated code (AFAICT).

On top of that there is also ravb_config()... Maybe this one could be
merged with ravb_set_reset_mode()...

> future changes might forget to add the ravb_wait() to confirm a mode
> change is successful and a good helper could avoid that.

Review should help with this. There are other bits in other registers that
needs polling.

>
>>
>>>
>>>>
>>>> - return 0;
>>>> + return error;
>>>> }
>>>>
>>>> static void ravb_get_tx_tstamp(struct net_device *ndev)
>>>> @@ -1744,6 +1747,18 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
>>>> return error;
>>>> }
>>>>
>>>> +static int ravb_set_reset_mode(struct net_device *ndev)
>>>
>>> nit: Maybe move this to be close to ravb_set_config_mode() to co-locate
>>> all mode changing logic?
>>
>> I've did this but not in this patch. It could be found on the final version
>> of the driver proposed by
>> https://lore.kernel.org/all/[email protected]/
>
> Why not add it in the final intended location straight away then moving
> it around in a later patch?

I guess it was easier when formatted the patches (ones in this series and
the ones at [1]).

> This just makes the later patch harder to
> review as it moves more code around.
>
>>
>> Thank you for your review,
>> Claudiu Beznea
>>
>>>
>>>> +{
>>>> + int error;
>>>> +
>>>> + ravb_write(ndev, CCC_OPC_RESET, CCC);
>>>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_RESET);
>>>> + if (error)
>>>> + netdev_err(ndev, "failed to switch device to reset mode\n");
>>>> +
>>>> + return error;
>>>> +}
>>>> +
>>>> /* Network device open function for Ethernet AVB */
>>>> static int ravb_open(struct net_device *ndev)
>>>> {
>>>> @@ -2551,10 +2566,11 @@ static int ravb_set_gti(struct net_device *ndev)
>>>> return 0;
>>>> }
>>>>
>>>> -static void ravb_set_config_mode(struct net_device *ndev)
>>>> +static int ravb_set_config_mode(struct net_device *ndev)
>>>> {
>>>> struct ravb_private *priv = netdev_priv(ndev);
>>>> const struct ravb_hw_info *info = priv->info;
>>>> + int error;
>>>>
>>>> if (info->gptp) {
>>>> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
>>>> @@ -2566,6 +2582,12 @@ static void ravb_set_config_mode(struct net_device *ndev)
>>>> } else {
>>>> ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
>>>> }
>>>> +
>>>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_CONFIG);
>>>> + if (error)
>>>> + netdev_err(ndev, "failed to switch device to config mode\n");
>>>> +
>>>> + return error;
>>>> }
>>>>
>>>> /* Set tx and rx clock internal delay modes */
>>>> @@ -2785,7 +2807,9 @@ static int ravb_probe(struct platform_device *pdev)
>>>> ndev->ethtool_ops = &ravb_ethtool_ops;
>>>>
>>>> /* Set AVB config mode */
>>>> - ravb_set_config_mode(ndev);
>>>> + error = ravb_set_config_mode(ndev);
>>>> + if (error)
>>>> + goto out_disable_refclk;
>>>>
>>>> if (info->gptp || info->ccc_gac) {
>>>> /* Set GTI value */
>>>> @@ -2893,6 +2917,7 @@ static void ravb_remove(struct platform_device *pdev)
>>>> struct net_device *ndev = platform_get_drvdata(pdev);
>>>> struct ravb_private *priv = netdev_priv(ndev);
>>>> const struct ravb_hw_info *info = priv->info;
>>>> + int error;
>>>>
>>>> unregister_netdev(ndev);
>>>> if (info->nc_queues)
>>>> @@ -2908,8 +2933,9 @@ static void ravb_remove(struct platform_device *pdev)
>>>> dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
>>>> priv->desc_bat_dma);
>>>>
>>>> - /* Set reset mode */
>>>> - ravb_write(ndev, CCC_OPC_RESET, CCC);
>>>> + error = ravb_set_reset_mode(ndev);
>>>> + if (error)
>>>> + netdev_err(ndev, "Failed to reset ndev\n");
>>>>
>>>> clk_disable_unprepare(priv->gptp_clk);
>>>> clk_disable_unprepare(priv->refclk);
>>>> @@ -2991,8 +3017,11 @@ static int __maybe_unused ravb_resume(struct device *dev)
>>>> int ret = 0;
>>>>
>>>> /* If WoL is enabled set reset mode to rearm the WoL logic */
>>>> - if (priv->wol_enabled)
>>>> - ravb_write(ndev, CCC_OPC_RESET, CCC);
>>>> + if (priv->wol_enabled) {
>>>> + ret = ravb_set_reset_mode(ndev);
>>>> + if (ret)
>>>> + return ret;
>>>> + }
>>>>
>>>> /* All register have been reset to default values.
>>>> * Restore all registers which where setup at probe time and
>>>> @@ -3000,7 +3029,9 @@ static int __maybe_unused ravb_resume(struct device *dev)
>>>> */
>>>>
>>>> /* Set AVB config mode */
>>>> - ravb_set_config_mode(ndev);
>>>> + ret = ravb_set_config_mode(ndev);
>>>> + if (ret)
>>>> + return ret;
>>>>
>>>> if (info->gptp || info->ccc_gac) {
>>>> /* Set GTI value */
>>>> --
>>>> 2.39.2
>>>>
>>>
>

2023-12-19 16:50:42

by Sergey Shtylyov

[permalink] [raw]
Subject: Re: [PATCH net 1/2] net: ravb: Wait for operation mode to be applied

On 12/15/23 1:04 PM, claudiu beznea wrote:
[...]
>>> From: Claudiu Beznea <[email protected]>
>>>
>>> CSR.OPS bits specify the current operating mode and (according to
>>> documentation) they are updated when the operating mode change request
>>> is processed. Thus, check CSR.OPS before proceeding.
>>
>> The manuals I have indeed say we need to check CSR.OPS... But we only
>> need to wait iff we transfer from the operation mode to the config mode...
>
> RZ/G3S manual say about CSR.OPS "These bits are updated when an operating

I was unable to find the RZ/G3 manuals on ther Renesas' website... :-(

> mode changes is processed". From this I get we need to check it for any mode.

I don't argue with the (safety) checking of CSR.OPS, I was just pointing
out that the R-Car gen3 manual says that only transfer from operation to
the config mode happens after a considerable amount of time, other transfers
do happen immediately after updating CCC.OPC.

> Also, on configuration procedure (of RZ/G3S) it say CSR.OPS need to be
> checked when switching from reset -> config.

Just checked or waited on?
The R-car does have a specific algorithm for transferring from the operation
to the reset mode (you need to set CC.DTSR first and then wait for CSR.DTS to
clear before updating CCC.OPC)...

[...]

>>> Signed-off-by: Claudiu Beznea <[email protected]>
>>> ---
>>> drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++----
>>> 1 file changed, 39 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
>>> index 9178f6d60e74..ce95eb5af354 100644
>>> --- a/drivers/net/ethernet/renesas/ravb_main.c
>>> +++ b/drivers/net/ethernet/renesas/ravb_main.c
[...]
>>> @@ -1744,6 +1747,18 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
>>> return error;
>>> }
>>>
>>> +static int ravb_set_reset_mode(struct net_device *ndev)
>>> +{
>>> + int error;
>>> +
>>> + ravb_write(ndev, CCC_OPC_RESET, CCC);
>>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_RESET);
>>> + if (error)
>>> + netdev_err(ndev, "failed to switch device to reset mode\n");
>>> +
>>> + return error;
>>> +}
>>> +
>>
>> Again, ravb_wait() call doesn't seem necessary here...
>
> Ok. I followed the guideline from the description of CSR.OPS. Let me know
> if you want to keep it or not. I think I haven't saw any issues w/o this.

Yes, please remove the waiting.

[...]

MBR, Sergey

2023-12-20 11:35:01

by Claudiu

[permalink] [raw]
Subject: Re: [PATCH net 1/2] net: ravb: Wait for operation mode to be applied



On 19.12.2023 18:49, Sergey Shtylyov wrote:
> On 12/15/23 1:04 PM, claudiu beznea wrote:
> [...]
>>>> From: Claudiu Beznea <[email protected]>
>>>>
>>>> CSR.OPS bits specify the current operating mode and (according to
>>>> documentation) they are updated when the operating mode change request
>>>> is processed. Thus, check CSR.OPS before proceeding.
>>>
>>> The manuals I have indeed say we need to check CSR.OPS... But we only
>>> need to wait iff we transfer from the operation mode to the config mode...
>>
>> RZ/G3S manual say about CSR.OPS "These bits are updated when an operating
>
> I was unable to find the RZ/G3 manuals on ther Renesas' website... :-(
>
>> mode changes is processed". From this I get we need to check it for any mode.
>
> I don't argue with the (safety) checking of CSR.OPS, I was just pointing
> out that the R-Car gen3 manual says that only transfer from operation to
> the config mode happens after a considerable amount of time, other transfers
> do happen immediately after updating CCC.OPC.
>
>> Also, on configuration procedure (of RZ/G3S) it say CSR.OPS need to be
>> checked when switching from reset -> config.
>
> Just checked or waited on?

Manual say to check that the read value of CSR.OPS=2

> The R-car does have a specific algorithm for transferring from the operation
> to the reset mode (you need to set CC.DTSR first and then wait for CSR.DTS to
> clear before updating CCC.OPC)...

In the stop procedure chapter of RZ/G3S manual, as the setup of DMAC.CCC=0
is the last operation that needs to be done, it doesn't specify either that
CSR needs to be checked.

>
> [...]
>
>>>> Signed-off-by: Claudiu Beznea <[email protected]>
>>>> ---
>>>> drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++----
>>>> 1 file changed, 39 insertions(+), 8 deletions(-)
>>>>
>>>> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
>>>> index 9178f6d60e74..ce95eb5af354 100644
>>>> --- a/drivers/net/ethernet/renesas/ravb_main.c
>>>> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> [...]
>>>> @@ -1744,6 +1747,18 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
>>>> return error;
>>>> }
>>>>
>>>> +static int ravb_set_reset_mode(struct net_device *ndev)
>>>> +{
>>>> + int error;
>>>> +
>>>> + ravb_write(ndev, CCC_OPC_RESET, CCC);
>>>> + error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_RESET);
>>>> + if (error)
>>>> + netdev_err(ndev, "failed to switch device to reset mode\n");
>>>> +
>>>> + return error;
>>>> +}
>>>> +
>>>
>>> Again, ravb_wait() call doesn't seem necessary here...
>>
>> Ok. I followed the guideline from the description of CSR.OPS. Let me know
>> if you want to keep it or not. I think I haven't saw any issues w/o this.
>
> Yes, please remove the waiting.
>
> [...]
>
> MBR, Sergey