netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MACB: Set PHY address in kernel parameters
@ 2010-03-31  7:51 Anders Darander
  2010-03-31  8:28 ` Patrick McHardy
  2010-03-31 10:03 ` Jiri Pirko
  0 siblings, 2 replies; 5+ messages in thread
From: Anders Darander @ 2010-03-31  7:51 UTC (permalink / raw)
  To: Haavard Skinnemoen
  Cc: David S. Miller, Jiri Pirko, Erik Waling, Patrick McHardy,
	Anders Darander, Grant Likely, netdev, linux-kernel

From: Anders Darander <ad@datarespons.se>

Add the possibility to set the phy address. This is needed if an integrated
switch is connected to the MAC, as it is often the case that the highest port
is the one connected to the MAC of the MCU.

E.g. in the case of the Micrel KSZ8873, port 3 is the one to connect to the
MCU, thus, the MAC needs to connect to phy address 0x03, instead of the first
phy found.

Signed-off-by: Anders Darander <ad@datarespons.se>
---
 drivers/net/macb.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index c8a18a6..9b4e301 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -53,6 +53,14 @@
 #define MACB_RX_INT_FLAGS	(MACB_BIT(RCOMP) | MACB_BIT(RXUBR)	\
 				 | MACB_BIT(ISR_ROVR))
 
+/*
+ * Setup PHY probeing
+ */
+
+static int phy_addr = PHY_MAX_ADDR;
+module_param(phy_addr, ushort, 0);
+MODULE_PARAM_DESC(phy_addr, "PHY address connected to the MACB");
+
 static void __macb_set_hwaddr(struct macb *bp)
 {
 	u32 bottom;
@@ -193,7 +201,11 @@ static int macb_mii_probe(struct net_device *dev)
 	struct eth_platform_data *pdata;
 	int ret;
 
-	phydev = phy_find_first(bp->mii_bus);
+	if (phy_addr >= PHY_MAX_ADDRESS)
+		phydev = phy_find_first(bp->mii_bus);
+	else
+		phydev = bp->mii_bus->phy_map[phy_addr];
+
 	if (!phydev) {
 		printk (KERN_ERR "%s: no PHY found\n", dev->name);
 		return -1;
-- 
1.7.0.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] MACB: Set PHY address in kernel parameters
  2010-03-31  7:51 [PATCH] MACB: Set PHY address in kernel parameters Anders Darander
@ 2010-03-31  8:28 ` Patrick McHardy
  2010-03-31  8:50   ` Anders Darander
  2010-03-31 10:03 ` Jiri Pirko
  1 sibling, 1 reply; 5+ messages in thread
From: Patrick McHardy @ 2010-03-31  8:28 UTC (permalink / raw)
  To: Anders Darander
  Cc: Haavard Skinnemoen, David S. Miller, Jiri Pirko, Erik Waling,
	Anders Darander, Grant Likely, netdev, linux-kernel

Anders Darander wrote:
> From: Anders Darander <ad@datarespons.se>
> 
> Add the possibility to set the phy address. This is needed if an integrated
> switch is connected to the MAC, as it is often the case that the highest port
> is the one connected to the MAC of the MCU.
> 
> E.g. in the case of the Micrel KSZ8873, port 3 is the one to connect to the
> MCU, thus, the MAC needs to connect to phy address 0x03, instead of the first
> phy found.
> 
> Signed-off-by: Anders Darander <ad@datarespons.se>
> ---
>  drivers/net/macb.c |   14 +++++++++++++-
>  1 files changed, 13 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/net/macb.c b/drivers/net/macb.c
> index c8a18a6..9b4e301 100644
> --- a/drivers/net/macb.c
> +++ b/drivers/net/macb.c
> @@ -53,6 +53,14 @@
>  #define MACB_RX_INT_FLAGS	(MACB_BIT(RCOMP) | MACB_BIT(RXUBR)	\
>  				 | MACB_BIT(ISR_ROVR))
>  
> +/*
> + * Setup PHY probeing
> + */
> +
> +static int phy_addr = PHY_MAX_ADDR;
> +module_param(phy_addr, ushort, 0);
> +MODULE_PARAM_DESC(phy_addr, "PHY address connected to the MACB");
> +
>  static void __macb_set_hwaddr(struct macb *bp)
>  {
>  	u32 bottom;
> @@ -193,7 +201,11 @@ static int macb_mii_probe(struct net_device *dev)
>  	struct eth_platform_data *pdata;
>  	int ret;
>  
> -	phydev = phy_find_first(bp->mii_bus);
> +	if (phy_addr >= PHY_MAX_ADDRESS)
> +		phydev = phy_find_first(bp->mii_bus);
> +	else
> +		phydev = bp->mii_bus->phy_map[phy_addr];

This looks like you need to use an unsigned to avoid negative
indices.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MACB: Set PHY address in kernel parameters
  2010-03-31  8:28 ` Patrick McHardy
@ 2010-03-31  8:50   ` Anders Darander
  0 siblings, 0 replies; 5+ messages in thread
From: Anders Darander @ 2010-03-31  8:50 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netdev, linux-kernel

* Patrick McHardy <kaber@trash.net> [100331 10:29]:
> Anders Darander wrote:
> > +	if (phy_addr >= PHY_MAX_ADDRESS)
> > +		phydev = phy_find_first(bp->mii_bus);
> > +	else
> > +		phydev = bp->mii_bus->phy_map[phy_addr];

> This looks like you need to use an unsigned to avoid negative
> indices.

Thanks for spotting this. That made me find that I'd also been inconsistent with the variable and module parameter declarations.

A new version, V2, of the patch has been sent.

Best regards,
Anders Darander

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MACB: Set PHY address in kernel parameters
  2010-03-31  7:51 [PATCH] MACB: Set PHY address in kernel parameters Anders Darander
  2010-03-31  8:28 ` Patrick McHardy
@ 2010-03-31 10:03 ` Jiri Pirko
  2010-03-31 10:11   ` Anders Darander
  1 sibling, 1 reply; 5+ messages in thread
From: Jiri Pirko @ 2010-03-31 10:03 UTC (permalink / raw)
  To: Anders Darander
  Cc: Haavard Skinnemoen, David S. Miller, Erik Waling, Patrick McHardy,
	Anders Darander, Grant Likely, netdev, linux-kernel

Wed, Mar 31, 2010 at 09:51:42AM CEST, anders.darander@gmail.com wrote:
>From: Anders Darander <ad@datarespons.se>
>
>Add the possibility to set the phy address. This is needed if an integrated
>switch is connected to the MAC, as it is often the case that the highest port
>is the one connected to the MAC of the MCU.
>
>E.g. in the case of the Micrel KSZ8873, port 3 is the one to connect to the
>MCU, thus, the MAC needs to connect to phy address 0x03, instead of the first
>phy found.
>
>Signed-off-by: Anders Darander <ad@datarespons.se>
>---
> drivers/net/macb.c |   14 +++++++++++++-
> 1 files changed, 13 insertions(+), 1 deletions(-)
>
>diff --git a/drivers/net/macb.c b/drivers/net/macb.c
>index c8a18a6..9b4e301 100644
>--- a/drivers/net/macb.c
>+++ b/drivers/net/macb.c
>@@ -53,6 +53,14 @@
> #define MACB_RX_INT_FLAGS	(MACB_BIT(RCOMP) | MACB_BIT(RXUBR)	\
> 				 | MACB_BIT(ISR_ROVR))
> 
>+/*
>+ * Setup PHY probeing
>+ */
>+
>+static int phy_addr = PHY_MAX_ADDR;
>+module_param(phy_addr, ushort, 0);
>+MODULE_PARAM_DESC(phy_addr, "PHY address connected to the MACB");
>+
> static void __macb_set_hwaddr(struct macb *bp)
> {
> 	u32 bottom;
>@@ -193,7 +201,11 @@ static int macb_mii_probe(struct net_device *dev)
> 	struct eth_platform_data *pdata;
> 	int ret;
> 
>-	phydev = phy_find_first(bp->mii_bus);
>+	if (phy_addr >= PHY_MAX_ADDRESS)
>+		phydev = phy_find_first(bp->mii_bus);
>+	else
>+		phydev = bp->mii_bus->phy_map[phy_addr];
>+
> 	if (!phydev) {
> 		printk (KERN_ERR "%s: no PHY found\n", dev->name);
> 		return -1;
>-- 
>1.7.0.3
>

This is really ugly :( Should be done differently, more general. I've been
thinking about this for a while. Maybe the solution is to integrate the switch
into DSA subsystem. See net/dsa. Not sure though...

Jirka

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MACB: Set PHY address in kernel parameters
  2010-03-31 10:03 ` Jiri Pirko
@ 2010-03-31 10:11   ` Anders Darander
  0 siblings, 0 replies; 5+ messages in thread
From: Anders Darander @ 2010-03-31 10:11 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: Haavard Skinnemoen, David S. Miller, Erik Waling, Patrick McHardy,
	Grant Likely, netdev, linux-kernel

* Jiri Pirko <jpirko@redhat.com> [100331 12:03]:
> Wed, Mar 31, 2010 at 09:51:42AM CEST, anders.darander@gmail.com wrote:
> > 
> >-	phydev = phy_find_first(bp->mii_bus);
> >+	if (phy_addr >= PHY_MAX_ADDRESS)
> >+		phydev = phy_find_first(bp->mii_bus);
> >+	else
> >+		phydev = bp->mii_bus->phy_map[phy_addr];
> >+
> > 	if (!phydev) {
> > 		printk (KERN_ERR "%s: no PHY found\n", dev->name);
> > 		return -1;
> 
> This is really ugly :( Should be done differently, more general. I've been
> thinking about this for a while. Maybe the solution is to integrate the switch
> into DSA subsystem. See net/dsa. Not sure though...

A more general solution is always welcome...

However, although I've not tested it, I think that Marc Kleine-Budde
came up with the correct solution. That was using phy_mask, and set it
up in the *eth_data structure in the board setup code.

Thus, it seems that the needed functionality is readily available.
(Working in the embedded field, I've no problem with defining HW-related
things in the board setup code, as opposite of having it dynamically
defined).

Regards,
Anders


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-03-31 10:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-31  7:51 [PATCH] MACB: Set PHY address in kernel parameters Anders Darander
2010-03-31  8:28 ` Patrick McHardy
2010-03-31  8:50   ` Anders Darander
2010-03-31 10:03 ` Jiri Pirko
2010-03-31 10:11   ` Anders Darander

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).