diff mbox series

[2/8] ravb: Fillup ravb_rx_ring_free_gbeth() stub

Message ID 20211001164305.8999-3-biju.das.jz@bp.renesas.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Fillup stubs for Gigabit Ethernet driver support | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Biju Das Oct. 1, 2021, 4:42 p.m. UTC
Fillup ravb_rx_ring_free_gbeth() function to support RZ/G2L.

This patch also renames ravb_rx_ring_free to ravb_rx_ring_free_rcar
to be consistent with the naming convention used in sh_eth driver.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
RFC->v1:
 * renamed "rgeth" to "gbeth".
 * renamed ravb_rx_ring_free to ravb_rx_ring_free_rcar
---
 drivers/net/ethernet/renesas/ravb.h      |  1 +
 drivers/net/ethernet/renesas/ravb_main.c | 41 ++++++++++++++++++++----
 2 files changed, 36 insertions(+), 6 deletions(-)

Comments

Sergey Shtylyov Oct. 4, 2021, 8:29 p.m. UTC | #1
On 10/1/21 7:42 PM, Biju Das wrote:

> Fillup ravb_rx_ring_free_gbeth() function to support RZ/G2L.
> 
> This patch also renames ravb_rx_ring_free to ravb_rx_ring_free_rcar
> to be consistent with the naming convention used in sh_eth driver.
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> ---
> RFC->v1:
>  * renamed "rgeth" to "gbeth".
>  * renamed ravb_rx_ring_free to ravb_rx_ring_free_rcar
> ---
>  drivers/net/ethernet/renesas/ravb.h      |  1 +
>  drivers/net/ethernet/renesas/ravb_main.c | 41 ++++++++++++++++++++----
>  2 files changed, 36 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
> index b147c4a0dc0b..1a73f960d918 100644
> --- a/drivers/net/ethernet/renesas/ravb.h
> +++ b/drivers/net/ethernet/renesas/ravb.h
> @@ -1077,6 +1077,7 @@ struct ravb_private {
>  	unsigned int num_tx_desc;	/* TX descriptors per packet */
>  
>  	int duplex;
> +	struct ravb_rx_desc *gbeth_rx_ring[NUM_RX_QUEUE];

   GBEther only has 1 RX queue, right?
   And please move the declaration closer to ravb_private::rx_ring.

[...]
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index 0d1e3f7d8c33..6ef55f1cf306 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
[...]
> @@ -1084,16 +1104,25 @@ static int ravb_poll(struct napi_struct *napi, int budget)
>  	struct net_device *ndev = napi->dev;
>  	struct ravb_private *priv = netdev_priv(ndev);
>  	const struct ravb_hw_info *info = priv->info;
> +	struct ravb_rx_desc *desc;
>  	unsigned long flags;
>  	int q = napi - priv->napi;
>  	int mask = BIT(q);
>  	int quota = budget;
> +	unsigned int entry;
> +	bool non_gptp = !(info->gptp || info->ccc_gac);

   Just no_gptp? Or maybe gptp, seems even better?

>  
> +	if (non_gptp) {
> +		entry = priv->cur_rx[q] % priv->num_rx_ring[q];
> +		desc = &priv->gbeth_rx_ring[q][entry];
> +	}
>  	/* Processing RX Descriptor Ring */
>  	/* Clear RX interrupt */
>  	ravb_write(ndev, ~(mask | RIS0_RESERVED), RIS0);
> -	if (ravb_rx(ndev, &quota, q))
> -		goto out;
> +	if (!non_gptp || desc->die_dt != DT_FEMPTY) {
> +		if (ravb_rx(ndev, &quota, q))
> +			goto out;
> +	}
>  
>  	/* Processing TX Descriptor Ring */
>  	spin_lock_irqsave(&priv->lock, flags);
[...]

MBR, Sergey
Biju Das Oct. 5, 2021, 6:06 a.m. UTC | #2
Hi Sergey,

> Subject: Re: [PATCH 2/8] ravb: Fillup ravb_rx_ring_free_gbeth() stub
> 
> On 10/1/21 7:42 PM, Biju Das wrote:
> 
> > Fillup ravb_rx_ring_free_gbeth() function to support RZ/G2L.
> >
> > This patch also renames ravb_rx_ring_free to ravb_rx_ring_free_rcar to
> > be consistent with the naming convention used in sh_eth driver.
> >
> > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> > Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> > ---
> > RFC->v1:
> >  * renamed "rgeth" to "gbeth".
> >  * renamed ravb_rx_ring_free to ravb_rx_ring_free_rcar
> > ---
> >  drivers/net/ethernet/renesas/ravb.h      |  1 +
> >  drivers/net/ethernet/renesas/ravb_main.c | 41
> > ++++++++++++++++++++----
> >  2 files changed, 36 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/renesas/ravb.h
> > b/drivers/net/ethernet/renesas/ravb.h
> > index b147c4a0dc0b..1a73f960d918 100644
> > --- a/drivers/net/ethernet/renesas/ravb.h
> > +++ b/drivers/net/ethernet/renesas/ravb.h
> > @@ -1077,6 +1077,7 @@ struct ravb_private {
> >  	unsigned int num_tx_desc;	/* TX descriptors per packet */
> >
> >  	int duplex;
> > +	struct ravb_rx_desc *gbeth_rx_ring[NUM_RX_QUEUE];
> 
>    GBEther only has 1 RX queue, right?
>    And please move the declaration closer to ravb_private::rx_ring.

Ok. Will move it and declare it as struct ravb_rx_desc *gbeth_rx_ring;
Also I am planning to add alloc patch first then free. So this change will go to
alloc patch.

> 
> [...]
> > diff --git a/drivers/net/ethernet/renesas/ravb_main.c
> > b/drivers/net/ethernet/renesas/ravb_main.c
> > index 0d1e3f7d8c33..6ef55f1cf306 100644
> > --- a/drivers/net/ethernet/renesas/ravb_main.c
> > +++ b/drivers/net/ethernet/renesas/ravb_main.c
> [...]
> > @@ -1084,16 +1104,25 @@ static int ravb_poll(struct napi_struct *napi,
> int budget)
> >  	struct net_device *ndev = napi->dev;
> >  	struct ravb_private *priv = netdev_priv(ndev);
> >  	const struct ravb_hw_info *info = priv->info;
> > +	struct ravb_rx_desc *desc;
> >  	unsigned long flags;
> >  	int q = napi - priv->napi;
> >  	int mask = BIT(q);
> >  	int quota = budget;
> > +	unsigned int entry;
> > +	bool non_gptp = !(info->gptp || info->ccc_gac);
> 
>    Just no_gptp? Or maybe gptp, seems even better?

OK. Will use gptp.

Regards,
Biju

> 
> >
> > +	if (non_gptp) {
> > +		entry = priv->cur_rx[q] % priv->num_rx_ring[q];
> > +		desc = &priv->gbeth_rx_ring[q][entry];
> > +	}
> >  	/* Processing RX Descriptor Ring */
> >  	/* Clear RX interrupt */
> >  	ravb_write(ndev, ~(mask | RIS0_RESERVED), RIS0);
> > -	if (ravb_rx(ndev, &quota, q))
> > -		goto out;
> > +	if (!non_gptp || desc->die_dt != DT_FEMPTY) {
> > +		if (ravb_rx(ndev, &quota, q))
> > +			goto out;
> > +	}
> >
> >  	/* Processing TX Descriptor Ring */
> >  	spin_lock_irqsave(&priv->lock, flags);
> [...]
> 
> MBR, Sergey
diff mbox series

Patch

diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
index b147c4a0dc0b..1a73f960d918 100644
--- a/drivers/net/ethernet/renesas/ravb.h
+++ b/drivers/net/ethernet/renesas/ravb.h
@@ -1077,6 +1077,7 @@  struct ravb_private {
 	unsigned int num_tx_desc;	/* TX descriptors per packet */
 
 	int duplex;
+	struct ravb_rx_desc *gbeth_rx_ring[NUM_RX_QUEUE];
 
 	const struct ravb_hw_info *info;
 	struct reset_control *rstc;
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 0d1e3f7d8c33..6ef55f1cf306 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -236,10 +236,30 @@  static int ravb_tx_free(struct net_device *ndev, int q, bool free_txed_only)
 
 static void ravb_rx_ring_free_gbeth(struct net_device *ndev, int q)
 {
-	/* Place holder */
+	struct ravb_private *priv = netdev_priv(ndev);
+	unsigned int ring_size;
+	unsigned int i;
+
+	if (!priv->gbeth_rx_ring[q])
+		return;
+
+	for (i = 0; i < priv->num_rx_ring[q]; i++) {
+		struct ravb_rx_desc *desc = &priv->gbeth_rx_ring[q][i];
+
+		if (!dma_mapping_error(ndev->dev.parent,
+				       le32_to_cpu(desc->dptr)))
+			dma_unmap_single(ndev->dev.parent,
+					 le32_to_cpu(desc->dptr),
+					 GBETH_RX_BUFF_MAX,
+					 DMA_FROM_DEVICE);
+	}
+	ring_size = sizeof(struct ravb_rx_desc) * (priv->num_rx_ring[q] + 1);
+	dma_free_coherent(ndev->dev.parent, ring_size, priv->gbeth_rx_ring[q],
+			  priv->rx_desc_dma[q]);
+	priv->gbeth_rx_ring[q] = NULL;
 }
 
-static void ravb_rx_ring_free(struct net_device *ndev, int q)
+static void ravb_rx_ring_free_rcar(struct net_device *ndev, int q)
 {
 	struct ravb_private *priv = netdev_priv(ndev);
 	unsigned int ring_size;
@@ -1084,16 +1104,25 @@  static int ravb_poll(struct napi_struct *napi, int budget)
 	struct net_device *ndev = napi->dev;
 	struct ravb_private *priv = netdev_priv(ndev);
 	const struct ravb_hw_info *info = priv->info;
+	struct ravb_rx_desc *desc;
 	unsigned long flags;
 	int q = napi - priv->napi;
 	int mask = BIT(q);
 	int quota = budget;
+	unsigned int entry;
+	bool non_gptp = !(info->gptp || info->ccc_gac);
 
+	if (non_gptp) {
+		entry = priv->cur_rx[q] % priv->num_rx_ring[q];
+		desc = &priv->gbeth_rx_ring[q][entry];
+	}
 	/* Processing RX Descriptor Ring */
 	/* Clear RX interrupt */
 	ravb_write(ndev, ~(mask | RIS0_RESERVED), RIS0);
-	if (ravb_rx(ndev, &quota, q))
-		goto out;
+	if (!non_gptp || desc->die_dt != DT_FEMPTY) {
+		if (ravb_rx(ndev, &quota, q))
+			goto out;
+	}
 
 	/* Processing TX Descriptor Ring */
 	spin_lock_irqsave(&priv->lock, flags);
@@ -2173,7 +2202,7 @@  static int ravb_mdio_release(struct ravb_private *priv)
 }
 
 static const struct ravb_hw_info ravb_gen3_hw_info = {
-	.rx_ring_free = ravb_rx_ring_free,
+	.rx_ring_free = ravb_rx_ring_free_rcar,
 	.rx_ring_format = ravb_rx_ring_format,
 	.alloc_rx_desc = ravb_alloc_rx_desc,
 	.receive = ravb_rcar_rx,
@@ -2198,7 +2227,7 @@  static const struct ravb_hw_info ravb_gen3_hw_info = {
 };
 
 static const struct ravb_hw_info ravb_gen2_hw_info = {
-	.rx_ring_free = ravb_rx_ring_free,
+	.rx_ring_free = ravb_rx_ring_free_rcar,
 	.rx_ring_format = ravb_rx_ring_format,
 	.alloc_rx_desc = ravb_alloc_rx_desc,
 	.receive = ravb_rcar_rx,