diff mbox series

[net-next,v4,10/10] net: sunhme: Consolidate common probe tasks

Message ID 20230324175136.321588-11-seanga2@gmail.com (mailing list archive)
State Accepted
Commit ecdcd0428c594f6a6ee157fafb4c6265785be054
Delegated to: Netdev Maintainers
Headers show
Series net: sunhme: Probe/IRQ cleanups | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch warning CHECK: Please don't use multiple blank lines
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sean Anderson March 24, 2023, 5:51 p.m. UTC
Most of the second half of the PCI/SBUS probe functions are the same.
Consolidate them into a common function.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v4:
- Use correct SBUS/PCI accessors
- Rework hme_version to set the default in pci/sbus_probe and override it (if
  necessary) in common_probe

 drivers/net/ethernet/sun/sunhme.c | 157 ++++++++++++------------------
 1 file changed, 64 insertions(+), 93 deletions(-)

Comments

Simon Horman March 25, 2023, 9:10 a.m. UTC | #1
On Fri, Mar 24, 2023 at 01:51:36PM -0400, Sean Anderson wrote:
> Most of the second half of the PCI/SBUS probe functions are the same.
> Consolidate them into a common function.
> 
> Signed-off-by: Sean Anderson <seanga2@gmail.com>

Hi Sean,

overall this looks good.
But I (still?) have some concerns about handling hm_revision.

...

> diff --git a/drivers/net/ethernet/sun/sunhme.c b/drivers/net/ethernet/sun/sunhme.c
> index bd1925f575c4..ec85aef35bf9 100644
> --- a/drivers/net/ethernet/sun/sunhme.c
> +++ b/drivers/net/ethernet/sun/sunhme.c
> @@ -2430,6 +2430,58 @@ static void happy_meal_addr_init(struct happy_meal *hp,
>  	}
>  }
>  
> +static int happy_meal_common_probe(struct happy_meal *hp,
> +				   struct device_node *dp)
> +{
> +	struct net_device *dev = hp->dev;
> +	int err;
> +
> +#ifdef CONFIG_SPARC
> +	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision);

Previously the logic, for SPARC for PCI went something like this:

	/* in happy_meal_pci_probe() */
	hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
	if (hp->hm_revision == 0xff)
		hp->hm_revision = 0xc0 | (pdev->revision & 0x0f);

Now it goes something like this:

	/* in happy_meal_pci_probe() */
	hp->hm_revision = 0xc0 | (pdev->revision & 0x0f);
	/* in happy_meal_common_probe() */
	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision); 

Is this intentional?

Likewise, for sbus (which implies SPARC) the logic was something like:

	/* in happy_meal_sbus_probe_one() */
	hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
	if (hp->hm_revision == 0xff)
		 hp->hm_revision = 0xa0;

And now goes something like this:

	/* in happy_meal_pci_probe() */
	hp->hm_revision = 0xa0;
	/* in happy_meal_common_probe() */
	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision); 

> +#endif
> +
> +	/* Now enable the feature flags we can. */
> +	if (hp->hm_revision == 0x20 || hp->hm_revision == 0x21)
> +		hp->happy_flags |= HFLAG_20_21;
> +	else if (hp->hm_revision != 0xa0)
> +		hp->happy_flags |= HFLAG_NOT_A0;
> +
> +	hp->happy_block = dmam_alloc_coherent(hp->dma_dev, PAGE_SIZE,
> +					      &hp->hblock_dvma, GFP_KERNEL);
> +	if (!hp->happy_block)
> +		return -ENOMEM;
> +
> +	/* Force check of the link first time we are brought up. */
> +	hp->linkcheck = 0;
> +
> +	/* Force timer state to 'asleep' with count of zero. */
> +	hp->timer_state = asleep;
> +	hp->timer_ticks = 0;
> +
> +	timer_setup(&hp->happy_timer, happy_meal_timer, 0);
> +
> +	dev->netdev_ops = &hme_netdev_ops;
> +	dev->watchdog_timeo = 5 * HZ;
> +	dev->ethtool_ops = &hme_ethtool_ops;
> +
> +	/* Happy Meal can do it all... */
> +	dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM;
> +	dev->features |= dev->hw_features | NETIF_F_RXCSUM;
> +
> +

nit: one blank line is enough.

> +	/* Grrr, Happy Meal comes up by default not advertising
> +	 * full duplex 100baseT capabilities, fix this.
> +	 */
> +	spin_lock_irq(&hp->happy_lock);
> +	happy_meal_set_initial_advertisement(hp);
> +	spin_unlock_irq(&hp->happy_lock);
> +
> +	err = devm_register_netdev(hp->dma_dev, dev);
> +	if (err)
> +		dev_err(hp->dma_dev, "Cannot register net device, aborting.\n");
> +	return err;
> +}
> +

...
Sean Anderson March 25, 2023, 4:06 p.m. UTC | #2
On 3/25/23 05:10, Simon Horman wrote:
> On Fri, Mar 24, 2023 at 01:51:36PM -0400, Sean Anderson wrote:
>> Most of the second half of the PCI/SBUS probe functions are the same.
>> Consolidate them into a common function.
>>
>> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> 
> Hi Sean,
> 
> overall this looks good.
> But I (still?) have some concerns about handling hm_revision.
> 
> ...
> 
>> diff --git a/drivers/net/ethernet/sun/sunhme.c b/drivers/net/ethernet/sun/sunhme.c
>> index bd1925f575c4..ec85aef35bf9 100644
>> --- a/drivers/net/ethernet/sun/sunhme.c
>> +++ b/drivers/net/ethernet/sun/sunhme.c
>> @@ -2430,6 +2430,58 @@ static void happy_meal_addr_init(struct happy_meal *hp,
>>   	}
>>   }
>>   
>> +static int happy_meal_common_probe(struct happy_meal *hp,
>> +				   struct device_node *dp)
>> +{
>> +	struct net_device *dev = hp->dev;
>> +	int err;
>> +
>> +#ifdef CONFIG_SPARC
>> +	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision);
> 
> Previously the logic, for SPARC for PCI went something like this:
> 
> 	/* in happy_meal_pci_probe() */
> 	hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
> 	if (hp->hm_revision == 0xff)
> 		hp->hm_revision = 0xc0 | (pdev->revision & 0x0f);
> 
> Now it goes something like this:
> 
> 	/* in happy_meal_pci_probe() */
> 	hp->hm_revision = 0xc0 | (pdev->revision & 0x0f);
> 	/* in happy_meal_common_probe() */
> 	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision);
> 
> Is this intentional?
> 
> Likewise, for sbus (which implies SPARC) the logic was something like:
> 
> 	/* in happy_meal_sbus_probe_one() */
> 	hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
> 	if (hp->hm_revision == 0xff)
> 		 hp->hm_revision = 0xa0;
> 
> And now goes something like this:
> 
> 	/* in happy_meal_pci_probe() */
> 	hp->hm_revision = 0xa0;
> 	/* in happy_meal_common_probe() */
> 	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision);

Yes, this is intentional. Logically, they are the same; we just set up the default
before calling of_getintprop_default instead of after.

>> +#endif
>> +
>> +	/* Now enable the feature flags we can. */
>> +	if (hp->hm_revision == 0x20 || hp->hm_revision == 0x21)
>> +		hp->happy_flags |= HFLAG_20_21;
>> +	else if (hp->hm_revision != 0xa0)
>> +		hp->happy_flags |= HFLAG_NOT_A0;
>> +
>> +	hp->happy_block = dmam_alloc_coherent(hp->dma_dev, PAGE_SIZE,
>> +					      &hp->hblock_dvma, GFP_KERNEL);
>> +	if (!hp->happy_block)
>> +		return -ENOMEM;
>> +
>> +	/* Force check of the link first time we are brought up. */
>> +	hp->linkcheck = 0;
>> +
>> +	/* Force timer state to 'asleep' with count of zero. */
>> +	hp->timer_state = asleep;
>> +	hp->timer_ticks = 0;
>> +
>> +	timer_setup(&hp->happy_timer, happy_meal_timer, 0);
>> +
>> +	dev->netdev_ops = &hme_netdev_ops;
>> +	dev->watchdog_timeo = 5 * HZ;
>> +	dev->ethtool_ops = &hme_ethtool_ops;
>> +
>> +	/* Happy Meal can do it all... */
>> +	dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM;
>> +	dev->features |= dev->hw_features | NETIF_F_RXCSUM;
>> +
>> +
> 
> nit: one blank line is enough.

Ah, oops.

--Sean

>> +	/* Grrr, Happy Meal comes up by default not advertising
>> +	 * full duplex 100baseT capabilities, fix this.
>> +	 */
>> +	spin_lock_irq(&hp->happy_lock);
>> +	happy_meal_set_initial_advertisement(hp);
>> +	spin_unlock_irq(&hp->happy_lock);
>> +
>> +	err = devm_register_netdev(hp->dma_dev, dev);
>> +	if (err)
>> +		dev_err(hp->dma_dev, "Cannot register net device, aborting.\n");
>> +	return err;
>> +}
>> +
> 
> ...
Simon Horman March 26, 2023, 7:57 a.m. UTC | #3
On Sat, Mar 25, 2023 at 12:06:41PM -0400, Sean Anderson wrote:
> On 3/25/23 05:10, Simon Horman wrote:
> > On Fri, Mar 24, 2023 at 01:51:36PM -0400, Sean Anderson wrote:
> > > Most of the second half of the PCI/SBUS probe functions are the same.
> > > Consolidate them into a common function.
> > > 
> > > Signed-off-by: Sean Anderson <seanga2@gmail.com>
> > 
> > Hi Sean,
> > 
> > overall this looks good.
> > But I (still?) have some concerns about handling hm_revision.
> > 
> > ...
> > 
> > > diff --git a/drivers/net/ethernet/sun/sunhme.c b/drivers/net/ethernet/sun/sunhme.c
> > > index bd1925f575c4..ec85aef35bf9 100644
> > > --- a/drivers/net/ethernet/sun/sunhme.c
> > > +++ b/drivers/net/ethernet/sun/sunhme.c
> > > @@ -2430,6 +2430,58 @@ static void happy_meal_addr_init(struct happy_meal *hp,
> > >   	}
> > >   }
> > > +static int happy_meal_common_probe(struct happy_meal *hp,
> > > +				   struct device_node *dp)
> > > +{
> > > +	struct net_device *dev = hp->dev;
> > > +	int err;
> > > +
> > > +#ifdef CONFIG_SPARC
> > > +	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision);
> > 
> > Previously the logic, for SPARC for PCI went something like this:
> > 
> > 	/* in happy_meal_pci_probe() */
> > 	hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
> > 	if (hp->hm_revision == 0xff)
> > 		hp->hm_revision = 0xc0 | (pdev->revision & 0x0f);
> > 
> > Now it goes something like this:
> > 
> > 	/* in happy_meal_pci_probe() */
> > 	hp->hm_revision = 0xc0 | (pdev->revision & 0x0f);
> > 	/* in happy_meal_common_probe() */
> > 	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision);
> > 
> > Is this intentional?
> > 
> > Likewise, for sbus (which implies SPARC) the logic was something like:
> > 
> > 	/* in happy_meal_sbus_probe_one() */
> > 	hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
> > 	if (hp->hm_revision == 0xff)
> > 		 hp->hm_revision = 0xa0;
> > 
> > And now goes something like this:
> > 
> > 	/* in happy_meal_pci_probe() */
> > 	hp->hm_revision = 0xa0;
> > 	/* in happy_meal_common_probe() */
> > 	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision);
> 
> Yes, this is intentional. Logically, they are the same; we just set up the default
> before calling of_getintprop_default instead of after.

Thanks, I see that now :)

And I have no further questions about this patch.

Reviewed-by: Simon Horman <simon.horman@corigine.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sun/sunhme.c b/drivers/net/ethernet/sun/sunhme.c
index bd1925f575c4..ec85aef35bf9 100644
--- a/drivers/net/ethernet/sun/sunhme.c
+++ b/drivers/net/ethernet/sun/sunhme.c
@@ -2430,6 +2430,58 @@  static void happy_meal_addr_init(struct happy_meal *hp,
 	}
 }
 
+static int happy_meal_common_probe(struct happy_meal *hp,
+				   struct device_node *dp)
+{
+	struct net_device *dev = hp->dev;
+	int err;
+
+#ifdef CONFIG_SPARC
+	hp->hm_revision = of_getintprop_default(dp, "hm-rev", hp->hm_revision);
+#endif
+
+	/* Now enable the feature flags we can. */
+	if (hp->hm_revision == 0x20 || hp->hm_revision == 0x21)
+		hp->happy_flags |= HFLAG_20_21;
+	else if (hp->hm_revision != 0xa0)
+		hp->happy_flags |= HFLAG_NOT_A0;
+
+	hp->happy_block = dmam_alloc_coherent(hp->dma_dev, PAGE_SIZE,
+					      &hp->hblock_dvma, GFP_KERNEL);
+	if (!hp->happy_block)
+		return -ENOMEM;
+
+	/* Force check of the link first time we are brought up. */
+	hp->linkcheck = 0;
+
+	/* Force timer state to 'asleep' with count of zero. */
+	hp->timer_state = asleep;
+	hp->timer_ticks = 0;
+
+	timer_setup(&hp->happy_timer, happy_meal_timer, 0);
+
+	dev->netdev_ops = &hme_netdev_ops;
+	dev->watchdog_timeo = 5 * HZ;
+	dev->ethtool_ops = &hme_ethtool_ops;
+
+	/* Happy Meal can do it all... */
+	dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM;
+	dev->features |= dev->hw_features | NETIF_F_RXCSUM;
+
+
+	/* Grrr, Happy Meal comes up by default not advertising
+	 * full duplex 100baseT capabilities, fix this.
+	 */
+	spin_lock_irq(&hp->happy_lock);
+	happy_meal_set_initial_advertisement(hp);
+	spin_unlock_irq(&hp->happy_lock);
+
+	err = devm_register_netdev(hp->dma_dev, dev);
+	if (err)
+		dev_err(hp->dma_dev, "Cannot register net device, aborting.\n");
+	return err;
+}
+
 #ifdef CONFIG_SBUS
 static int happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)
 {
@@ -2511,50 +2563,18 @@  static int happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)
 		goto err_out_clear_quattro;
 	}
 
-	hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
-	if (hp->hm_revision == 0xff)
-		hp->hm_revision = 0xa0;
-
-	/* Now enable the feature flags we can. */
-	if (hp->hm_revision == 0x20 || hp->hm_revision == 0x21)
-		hp->happy_flags = HFLAG_20_21;
-	else if (hp->hm_revision != 0xa0)
-		hp->happy_flags = HFLAG_NOT_A0;
+	hp->hm_revision = 0xa0;
 
 	if (qp != NULL)
 		hp->happy_flags |= HFLAG_QUATTRO;
 
+	hp->irq = op->archdata.irqs[0];
+
 	/* Get the supported DVMA burst sizes from our Happy SBUS. */
 	hp->happy_bursts = of_getintprop_default(sbus_dp,
 						 "burst-sizes", 0x00);
 
-	hp->happy_block = dmam_alloc_coherent(&op->dev, PAGE_SIZE,
-					      &hp->hblock_dvma, GFP_KERNEL);
-	if (!hp->happy_block) {
-		err = -ENOMEM;
-		goto err_out_clear_quattro;
-	}
-
-	/* Force check of the link first time we are brought up. */
-	hp->linkcheck = 0;
-
-	/* Force timer state to 'asleep' with count of zero. */
-	hp->timer_state = asleep;
-	hp->timer_ticks = 0;
-
-	timer_setup(&hp->happy_timer, happy_meal_timer, 0);
-
-	dev->netdev_ops = &hme_netdev_ops;
-	dev->watchdog_timeo = 5*HZ;
-	dev->ethtool_ops = &hme_ethtool_ops;
-
-	/* Happy Meal can do it all... */
-	dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM;
-	dev->features |= dev->hw_features | NETIF_F_RXCSUM;
-
-	hp->irq = op->archdata.irqs[0];
-
-#if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
+#ifdef CONFIG_PCI
 	/* Hook up SBUS register/descriptor accessors. */
 	hp->read_desc32 = sbus_hme_read_desc32;
 	hp->write_txd = sbus_hme_write_txd;
@@ -2563,18 +2583,9 @@  static int happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)
 	hp->write32 = sbus_hme_write32;
 #endif
 
-	/* Grrr, Happy Meal comes up by default not advertising
-	 * full duplex 100baseT capabilities, fix this.
-	 */
-	spin_lock_irq(&hp->happy_lock);
-	happy_meal_set_initial_advertisement(hp);
-	spin_unlock_irq(&hp->happy_lock);
-
-	err = devm_register_netdev(&op->dev, dev);
-	if (err) {
-		dev_err(&op->dev, "Cannot register net device, aborting.\n");
+	err = happy_meal_common_probe(hp, dp);
+	if (err)
 		goto err_out_clear_quattro;
-	}
 
 	platform_set_drvdata(op, hp);
 
@@ -2689,20 +2700,10 @@  static int happy_meal_pci_probe(struct pci_dev *pdev,
 	hp->bigmacregs = (hpreg_base + 0x6000UL);
 	hp->tcvregs    = (hpreg_base + 0x7000UL);
 
-#ifdef CONFIG_SPARC
-	hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
-	if (hp->hm_revision == 0xff)
+	if (IS_ENABLED(CONFIG_SPARC))
 		hp->hm_revision = 0xc0 | (pdev->revision & 0x0f);
-#else
-	/* works with this on non-sparc hosts */
-	hp->hm_revision = 0x20;
-#endif
-
-	/* Now enable the feature flags we can. */
-	if (hp->hm_revision == 0x20 || hp->hm_revision == 0x21)
-		hp->happy_flags = HFLAG_20_21;
-	else if (hp->hm_revision != 0xa0 && hp->hm_revision != 0xc0)
-		hp->happy_flags = HFLAG_NOT_A0;
+	else
+		hp->hm_revision = 0x20;
 
 	if (qp != NULL)
 		hp->happy_flags |= HFLAG_QUATTRO;
@@ -2714,30 +2715,9 @@  static int happy_meal_pci_probe(struct pci_dev *pdev,
 	/* Assume PCI happy meals can handle all burst sizes. */
 	hp->happy_bursts = DMA_BURSTBITS;
 #endif
-
-	hp->happy_block = dmam_alloc_coherent(&pdev->dev, PAGE_SIZE,
-					      &hp->hblock_dvma, GFP_KERNEL);
-	if (!hp->happy_block) {
-		err = -ENOMEM;
-		goto err_out_clear_quattro;
-	}
-
-	hp->linkcheck = 0;
-	hp->timer_state = asleep;
-	hp->timer_ticks = 0;
-
-	timer_setup(&hp->happy_timer, happy_meal_timer, 0);
-
 	hp->irq = pdev->irq;
-	dev->netdev_ops = &hme_netdev_ops;
-	dev->watchdog_timeo = 5*HZ;
-	dev->ethtool_ops = &hme_ethtool_ops;
 
-	/* Happy Meal can do it all... */
-	dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM;
-	dev->features |= dev->hw_features | NETIF_F_RXCSUM;
-
-#if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
+#ifdef CONFIG_SBUS
 	/* Hook up PCI register/descriptor accessors. */
 	hp->read_desc32 = pci_hme_read_desc32;
 	hp->write_txd = pci_hme_write_txd;
@@ -2746,18 +2726,9 @@  static int happy_meal_pci_probe(struct pci_dev *pdev,
 	hp->write32 = pci_hme_write32;
 #endif
 
-	/* Grrr, Happy Meal comes up by default not advertising
-	 * full duplex 100baseT capabilities, fix this.
-	 */
-	spin_lock_irq(&hp->happy_lock);
-	happy_meal_set_initial_advertisement(hp);
-	spin_unlock_irq(&hp->happy_lock);
-
-	err = devm_register_netdev(&pdev->dev, dev);
-	if (err) {
-		dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
+	err = happy_meal_common_probe(hp, dp);
+	if (err)
 		goto err_out_clear_quattro;
-	}
 
 	pci_set_drvdata(pdev, hp);