All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 0/2] natsemi: Support Aculab E1/T1 cPCI carrier cards
@ 2007-02-14 10:02 Mark Brown
  2007-02-14 10:02 ` [patch 1/2] natsemi: Add support for using MII port with no PHY Mark Brown
  2007-02-14 10:02 ` [patch 2/2] natsemi: Support Aculab E1/T1 PMXc cPCI carrier cards Mark Brown
  0 siblings, 2 replies; 9+ messages in thread
From: Mark Brown @ 2007-02-14 10:02 UTC (permalink / raw)
  To: Tim Hockin, Jeff Garzik; +Cc: netdev, linux-kernel

These patches add support for the Aculab E1/T1 cPCI carrier card to the
natsemi driver.  The first patch provides support for using the MII port
with no PHY and the second adds the quirk required to configure the
card.

--
"You grabbed my hand and we fell into it, like a daydream - or a fever."

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

* [patch 1/2] natsemi: Add support for using MII port with no PHY
  2007-02-14 10:02 [patch 0/2] natsemi: Support Aculab E1/T1 cPCI carrier cards Mark Brown
@ 2007-02-14 10:02 ` Mark Brown
  2007-02-14 13:28   ` Ahmed S. Darwish
  2007-02-17 20:21   ` Jeff Garzik
  2007-02-14 10:02 ` [patch 2/2] natsemi: Support Aculab E1/T1 PMXc cPCI carrier cards Mark Brown
  1 sibling, 2 replies; 9+ messages in thread
From: Mark Brown @ 2007-02-14 10:02 UTC (permalink / raw)
  To: Tim Hockin, Jeff Garzik; +Cc: netdev, linux-kernel

[-- Attachment #1: natsemi-ignore-phy.patch --]
[-- Type: text/plain, Size: 5586 bytes --]

This patch provides code paths which allow the natsemi driver to use the
external MII port on the chip but ignore any PHYs that may be attached to it.
The link state will be left as it was when the driver started and can be
configured via ethtool.  Any PHYs that are present can be accessed via the MII
ioctl()s.

This is useful for systems where the device is connected without a PHY
or where either information or actions outside the scope of the driver
are required in order to use the PHYs.

Signed-Off-By: Mark Brown <broonie@sirena.org.uk>

---

Previous versions of this patch exposed the new functionality as a module
option.  This has been removed.  Any hardware that needs this should be
identifiable by a quirk since it unlikely to behave correctly with an
unmodified driver.

Index: linux/drivers/net/natsemi.c
===================================================================
--- linux.orig/drivers/net/natsemi.c	2007-02-12 17:44:33.000000000 +0000
+++ linux/drivers/net/natsemi.c	2007-02-12 18:09:44.000000000 +0000
@@ -568,6 +568,8 @@
 	u32 intr_status;
 	/* Do not touch the nic registers */
 	int hands_off;
+	/* Don't pay attention to the reported link state. */
+	int ignore_phy;
 	/* external phy that is used: only valid if dev->if_port != PORT_TP */
 	int mii;
 	int phy_addr_external;
@@ -696,7 +698,10 @@
 	struct netdev_private *np = netdev_priv(dev);
 	u32 tmp;
 
-	netif_carrier_off(dev);
+	if (np->ignore_phy)
+		netif_carrier_on(dev);
+	else
+		netif_carrier_off(dev);
 
 	/* get the initial settings from hardware */
 	tmp            = mdio_read(dev, MII_BMCR);
@@ -806,8 +811,10 @@
 	np->hands_off = 0;
 	np->intr_status = 0;
 	np->eeprom_size = natsemi_pci_info[chip_idx].eeprom_size;
+	np->ignore_phy = 0;
 
 	/* Initial port:
+	 * - If configured to ignore the PHY set up for external.
 	 * - If the nic was configured to use an external phy and if find_mii
 	 *   finds a phy: use external port, first phy that replies.
 	 * - Otherwise: internal port.
@@ -815,7 +822,7 @@
 	 * The address would be used to access a phy over the mii bus, but
 	 * the internal phy is accessed through mapped registers.
 	 */
-	if (readl(ioaddr + ChipConfig) & CfgExtPhy)
+	if (np->ignore_phy || readl(ioaddr + ChipConfig) & CfgExtPhy)
 		dev->if_port = PORT_MII;
 	else
 		dev->if_port = PORT_TP;
@@ -825,7 +832,9 @@
 
 	if (dev->if_port != PORT_TP) {
 		np->phy_addr_external = find_mii(dev);
-		if (np->phy_addr_external == PHY_ADDR_NONE) {
+		/* If we're ignoring the PHY it doesn't matter if we can't
+		 * find one. */
+		if (!np->ignore_phy && np->phy_addr_external == PHY_ADDR_NONE) {
 			dev->if_port = PORT_TP;
 			np->phy_addr_external = PHY_ADDR_INTERNAL;
 		}
@@ -891,6 +900,8 @@
 		printk("%02x, IRQ %d", dev->dev_addr[i], irq);
 		if (dev->if_port == PORT_TP)
 			printk(", port TP.\n");
+		else if (np->ignore_phy)
+			printk(", port MII, ignoring PHY\n");
 		else
 			printk(", port MII, phy ad %d.\n", np->phy_addr_external);
 	}
@@ -1571,42 +1582,45 @@
 {
 	struct netdev_private *np = netdev_priv(dev);
 	void __iomem * ioaddr = ns_ioaddr(dev);
-	int duplex;
+	int duplex = np->duplex;
 	u16 bmsr;
 
-	/* The link status field is latched: it remains low after a temporary
-	 * link failure until it's read. We need the current link status,
-	 * thus read twice.
-	 */
-	mdio_read(dev, MII_BMSR);
-	bmsr = mdio_read(dev, MII_BMSR);
+	/* If we are ignoring the PHY then don't try reading it. */
+	if (!np->ignore_phy) {
+		/* The link status field is latched: it remains low
+		 * after a temporary link failure until it's read. We
+		 * need the current link status, thus read twice.
+		 */
+		mdio_read(dev, MII_BMSR);
+		bmsr = mdio_read(dev, MII_BMSR);
 
-	if (!(bmsr & BMSR_LSTATUS)) {
-		if (netif_carrier_ok(dev)) {
+		if (!(bmsr & BMSR_LSTATUS)) {
+			if (netif_carrier_ok(dev)) {
+				if (netif_msg_link(np))
+					printk(KERN_NOTICE "%s: link down.\n",
+					       dev->name);
+				netif_carrier_off(dev);
+				undo_cable_magic(dev);
+			}
+			return;
+		}
+		if (!netif_carrier_ok(dev)) {
 			if (netif_msg_link(np))
-				printk(KERN_NOTICE "%s: link down.\n",
-					dev->name);
-			netif_carrier_off(dev);
-			undo_cable_magic(dev);
+				printk(KERN_NOTICE "%s: link up.\n", dev->name);
+			netif_carrier_on(dev);
+			do_cable_magic(dev);
 		}
-		return;
-	}
-	if (!netif_carrier_ok(dev)) {
-		if (netif_msg_link(np))
-			printk(KERN_NOTICE "%s: link up.\n", dev->name);
-		netif_carrier_on(dev);
-		do_cable_magic(dev);
-	}
 
-	duplex = np->full_duplex;
-	if (!duplex) {
-		if (bmsr & BMSR_ANEGCOMPLETE) {
-			int tmp = mii_nway_result(
-				np->advertising & mdio_read(dev, MII_LPA));
-			if (tmp == LPA_100FULL || tmp == LPA_10FULL)
+		duplex = np->full_duplex;
+		if (!duplex) {
+			if (bmsr & BMSR_ANEGCOMPLETE) {
+				int tmp = mii_nway_result(
+					np->advertising & mdio_read(dev, MII_LPA));
+				if (tmp == LPA_100FULL || tmp == LPA_10FULL)
+					duplex = 1;
+			} else if (mdio_read(dev, MII_BMCR) & BMCR_FULLDPLX)
 				duplex = 1;
-		} else if (mdio_read(dev, MII_BMCR) & BMCR_FULLDPLX)
-			duplex = 1;
+		}
 	}
 
 	/* if duplex is set then bit 28 must be set, too */
@@ -2819,6 +2833,16 @@
 	}
 
 	/*
+	 * If we're ignoring the PHY then autoneg and the internal
+	 * transciever are really not going to work so don't let the
+	 * user select them.
+	 */
+	if (np->ignore_phy && (ecmd->autoneg == AUTONEG_ENABLE ||
+			       ecmd->port == PORT_TP)) {
+		return -EINVAL;
+	}
+
+	/*
 	 * maxtxpkt, maxrxpkt: ignored for now.
 	 *
 	 * transceiver:

--
"You grabbed my hand and we fell into it, like a daydream - or a fever."

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

* [patch 2/2] natsemi: Support Aculab E1/T1 PMXc cPCI carrier cards
  2007-02-14 10:02 [patch 0/2] natsemi: Support Aculab E1/T1 cPCI carrier cards Mark Brown
  2007-02-14 10:02 ` [patch 1/2] natsemi: Add support for using MII port with no PHY Mark Brown
@ 2007-02-14 10:02 ` Mark Brown
  2007-02-17 20:22   ` Jeff Garzik
  1 sibling, 1 reply; 9+ messages in thread
From: Mark Brown @ 2007-02-14 10:02 UTC (permalink / raw)
  To: Tim Hockin, Jeff Garzik; +Cc: netdev, linux-kernel

[-- Attachment #1: natsemi-aculab-cpci-carrier.patch --]
[-- Type: text/plain, Size: 1626 bytes --]

Aculab E1/T1 PMXc cPCI carrier card cards present a natsemi on the cPCI
bus with an oversized EEPROM using a direct MII<->MII connection with no
PHY.  This patch adds a new device table entry supporting these cards.

Signed-Off-By: Mark Brown <broonie@sirena.org.uk>

Index: linux/drivers/net/natsemi.c
===================================================================
--- linux.orig/drivers/net/natsemi.c	2007-02-12 18:09:44.000000000 +0000
+++ linux/drivers/net/natsemi.c	2007-02-12 18:09:59.000000000 +0000
@@ -244,6 +244,9 @@
 	MII_EN_SCRM	= 0x0004,	/* enable scrambler (tp) */
 };
 
+enum {
+	NATSEMI_FLAG_IGNORE_PHY		= 0x1,
+};
 
 /* array of board data directly indexed by pci_tbl[x].driver_data */
 static const struct {
@@ -251,10 +254,12 @@
 	unsigned long flags;
 	unsigned int eeprom_size;
 } natsemi_pci_info[] __devinitdata = {
+	{ "Aculab E1/T1 PMXc cPCI carrier card", NATSEMI_FLAG_IGNORE_PHY, 128 },
 	{ "NatSemi DP8381[56]", 0, 24 },
 };
 
 static const struct pci_device_id natsemi_pci_tbl[] __devinitdata = {
+	{ PCI_VENDOR_ID_NS, 0x0020, 0x12d9,     0x000c,     0, 0, 0 },
 	{ PCI_VENDOR_ID_NS, 0x0020, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
 	{ }	/* terminate list */
 };
@@ -811,7 +816,11 @@
 	np->hands_off = 0;
 	np->intr_status = 0;
 	np->eeprom_size = natsemi_pci_info[chip_idx].eeprom_size;
-	np->ignore_phy = 0;
+	if (natsemi_pci_info[chip_idx].flags & NATSEMI_FLAG_IGNORE_PHY) {
+		np->ignore_phy = 1;
+	} else {
+		np->ignore_phy = 0;
+	}
 
 	/* Initial port:
 	 * - If configured to ignore the PHY set up for external.

--
"You grabbed my hand and we fell into it, like a daydream - or a fever."

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

* Re: [patch 1/2] natsemi: Add support for using MII port with no PHY
  2007-02-14 10:02 ` [patch 1/2] natsemi: Add support for using MII port with no PHY Mark Brown
@ 2007-02-14 13:28   ` Ahmed S. Darwish
  2007-02-17 20:21   ` Jeff Garzik
  1 sibling, 0 replies; 9+ messages in thread
From: Ahmed S. Darwish @ 2007-02-14 13:28 UTC (permalink / raw)
  To: Mark Brown; +Cc: Tim Hockin, Jeff Garzik, netdev, linux-kernel

On Wed, Feb 14, 2007 at 10:02:04AM +0000, Mark Brown wrote:

> Signed-Off-By: Mark Brown <broonie@sirena.org.uk>
> 
[...]
> -		if (np->phy_addr_external == PHY_ADDR_NONE) {
> +		/* If we're ignoring the PHY it doesn't matter if we can't
> +		 * find one. */
> +		if (!np->ignore_phy && np->phy_addr_external == PHY_ADDR_NONE) {
[...]
> +	if (!np->ignore_phy) {
> +		/* The link status field is latched: it remains low
> +		 * after a temporary link failure until it's read. We
> +		 * need the current link status, thus read twice.
> +		 */
> +		mdio_read(dev, MII_BMSR);
> +		bmsr = mdio_read(dev, MII_BMSR);
[...]
>  	/*
> +	 * If we're ignoring the PHY then autoneg and the internal
> +	 * transciever are really not going to work so don't let the
> +	 * user select them.
> +	 */
> +	if (np->ignore_phy && (ecmd->autoneg == AUTONEG_ENABLE ||

A trivial comment actually, Is there a point to write multi-line comments 
in two different formats ?

Thanks,

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

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

* Re: [patch 1/2] natsemi: Add support for using MII port with no PHY
  2007-02-14 10:02 ` [patch 1/2] natsemi: Add support for using MII port with no PHY Mark Brown
  2007-02-14 13:28   ` Ahmed S. Darwish
@ 2007-02-17 20:21   ` Jeff Garzik
  1 sibling, 0 replies; 9+ messages in thread
From: Jeff Garzik @ 2007-02-17 20:21 UTC (permalink / raw)
  To: Mark Brown; +Cc: Tim Hockin, netdev, linux-kernel

Mark Brown wrote:
> This patch provides code paths which allow the natsemi driver to use the
> external MII port on the chip but ignore any PHYs that may be attached to it.
> The link state will be left as it was when the driver started and can be
> configured via ethtool.  Any PHYs that are present can be accessed via the MII
> ioctl()s.
> 
> This is useful for systems where the device is connected without a PHY
> or where either information or actions outside the scope of the driver
> are required in order to use the PHYs.
> 
> Signed-Off-By: Mark Brown <broonie@sirena.org.uk>
> 
> ---
> 
> Previous versions of this patch exposed the new functionality as a module
> option.  This has been removed.  Any hardware that needs this should be
> identifiable by a quirk since it unlikely to behave correctly with an
> unmodified driver.

I ACK this general concept.  Please update for the minor issues and resend.


> 
> Index: linux/drivers/net/natsemi.c
> ===================================================================
> --- linux.orig/drivers/net/natsemi.c	2007-02-12 17:44:33.000000000 +0000
> +++ linux/drivers/net/natsemi.c	2007-02-12 18:09:44.000000000 +0000
> @@ -568,6 +568,8 @@
>  	u32 intr_status;
>  	/* Do not touch the nic registers */
>  	int hands_off;
> +	/* Don't pay attention to the reported link state. */
> +	int ignore_phy;
>  	/* external phy that is used: only valid if dev->if_port != PORT_TP */
>  	int mii;
>  	int phy_addr_external;
> @@ -696,7 +698,10 @@
>  	struct netdev_private *np = netdev_priv(dev);
>  	u32 tmp;
>  
> -	netif_carrier_off(dev);
> +	if (np->ignore_phy)
> +		netif_carrier_on(dev);
> +	else
> +		netif_carrier_off(dev);
>  
>  	/* get the initial settings from hardware */
>  	tmp            = mdio_read(dev, MII_BMCR);
> @@ -806,8 +811,10 @@
>  	np->hands_off = 0;
>  	np->intr_status = 0;
>  	np->eeprom_size = natsemi_pci_info[chip_idx].eeprom_size;
> +	np->ignore_phy = 0;
>  
>  	/* Initial port:
> +	 * - If configured to ignore the PHY set up for external.
>  	 * - If the nic was configured to use an external phy and if find_mii
>  	 *   finds a phy: use external port, first phy that replies.
>  	 * - Otherwise: internal port.
> @@ -815,7 +822,7 @@
>  	 * The address would be used to access a phy over the mii bus, but
>  	 * the internal phy is accessed through mapped registers.
>  	 */
> -	if (readl(ioaddr + ChipConfig) & CfgExtPhy)
> +	if (np->ignore_phy || readl(ioaddr + ChipConfig) & CfgExtPhy)
>  		dev->if_port = PORT_MII;
>  	else
>  		dev->if_port = PORT_TP;
> @@ -825,7 +832,9 @@
>  
>  	if (dev->if_port != PORT_TP) {
>  		np->phy_addr_external = find_mii(dev);
> -		if (np->phy_addr_external == PHY_ADDR_NONE) {
> +		/* If we're ignoring the PHY it doesn't matter if we can't
> +		 * find one. */
> +		if (!np->ignore_phy && np->phy_addr_external == PHY_ADDR_NONE) {
>  			dev->if_port = PORT_TP;
>  			np->phy_addr_external = PHY_ADDR_INTERNAL;
>  		}
> @@ -891,6 +900,8 @@
>  		printk("%02x, IRQ %d", dev->dev_addr[i], irq);
>  		if (dev->if_port == PORT_TP)
>  			printk(", port TP.\n");
> +		else if (np->ignore_phy)
> +			printk(", port MII, ignoring PHY\n");
>  		else
>  			printk(", port MII, phy ad %d.\n", np->phy_addr_external);
>  	}
> @@ -1571,42 +1582,45 @@
>  {
>  	struct netdev_private *np = netdev_priv(dev);
>  	void __iomem * ioaddr = ns_ioaddr(dev);
> -	int duplex;
> +	int duplex = np->duplex;
>  	u16 bmsr;
>  
> -	/* The link status field is latched: it remains low after a temporary
> -	 * link failure until it's read. We need the current link status,
> -	 * thus read twice.
> -	 */
> -	mdio_read(dev, MII_BMSR);
> -	bmsr = mdio_read(dev, MII_BMSR);
> +	/* If we are ignoring the PHY then don't try reading it. */
> +	if (!np->ignore_phy) {

This change causes a lot of needless indentation changes.  I would 
prefer something like

	if (np->ignore_phy)
		return;

or

	if (np->ignore_phy)
		goto step_2;


> +		/* The link status field is latched: it remains low
> +		 * after a temporary link failure until it's read. We
> +		 * need the current link status, thus read twice.
> +		 */
> +		mdio_read(dev, MII_BMSR);
> +		bmsr = mdio_read(dev, MII_BMSR);
>  
> -	if (!(bmsr & BMSR_LSTATUS)) {
> -		if (netif_carrier_ok(dev)) {
> +		if (!(bmsr & BMSR_LSTATUS)) {
> +			if (netif_carrier_ok(dev)) {
> +				if (netif_msg_link(np))
> +					printk(KERN_NOTICE "%s: link down.\n",
> +					       dev->name);
> +				netif_carrier_off(dev);
> +				undo_cable_magic(dev);
> +			}
> +			return;
> +		}
> +		if (!netif_carrier_ok(dev)) {
>  			if (netif_msg_link(np))
> -				printk(KERN_NOTICE "%s: link down.\n",
> -					dev->name);
> -			netif_carrier_off(dev);
> -			undo_cable_magic(dev);
> +				printk(KERN_NOTICE "%s: link up.\n", dev->name);
> +			netif_carrier_on(dev);
> +			do_cable_magic(dev);
>  		}
> -		return;
> -	}
> -	if (!netif_carrier_ok(dev)) {
> -		if (netif_msg_link(np))
> -			printk(KERN_NOTICE "%s: link up.\n", dev->name);
> -		netif_carrier_on(dev);
> -		do_cable_magic(dev);
> -	}
>  
> -	duplex = np->full_duplex;
> -	if (!duplex) {
> -		if (bmsr & BMSR_ANEGCOMPLETE) {
> -			int tmp = mii_nway_result(
> -				np->advertising & mdio_read(dev, MII_LPA));
> -			if (tmp == LPA_100FULL || tmp == LPA_10FULL)
> +		duplex = np->full_duplex;
> +		if (!duplex) {
> +			if (bmsr & BMSR_ANEGCOMPLETE) {
> +				int tmp = mii_nway_result(
> +					np->advertising & mdio_read(dev, MII_LPA));
> +				if (tmp == LPA_100FULL || tmp == LPA_10FULL)
> +					duplex = 1;
> +			} else if (mdio_read(dev, MII_BMCR) & BMCR_FULLDPLX)
>  				duplex = 1;
> -		} else if (mdio_read(dev, MII_BMCR) & BMCR_FULLDPLX)
> -			duplex = 1;
> +		}
>  	}
>  
>  	/* if duplex is set then bit 28 must be set, too */
> @@ -2819,6 +2833,16 @@
>  	}
>  
>  	/*
> +	 * If we're ignoring the PHY then autoneg and the internal
> +	 * transciever are really not going to work so don't let the
> +	 * user select them.
> +	 */
> +	if (np->ignore_phy && (ecmd->autoneg == AUTONEG_ENABLE ||
> +			       ecmd->port == PORT_TP)) {
> +		return -EINVAL;
> +	}
> +
> +	/*

always kill the braces surrounding a single C statement


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

* Re: [patch 2/2] natsemi: Support Aculab E1/T1 PMXc cPCI carrier cards
  2007-02-14 10:02 ` [patch 2/2] natsemi: Support Aculab E1/T1 PMXc cPCI carrier cards Mark Brown
@ 2007-02-17 20:22   ` Jeff Garzik
  0 siblings, 0 replies; 9+ messages in thread
From: Jeff Garzik @ 2007-02-17 20:22 UTC (permalink / raw)
  To: Mark Brown; +Cc: Tim Hockin, netdev, linux-kernel

Mark Brown wrote:
> Aculab E1/T1 PMXc cPCI carrier card cards present a natsemi on the cPCI
> bus with an oversized EEPROM using a direct MII<->MII connection with no
> PHY.  This patch adds a new device table entry supporting these cards.
> 
> Signed-Off-By: Mark Brown <broonie@sirena.org.uk>

> @@ -811,7 +816,11 @@
>  	np->hands_off = 0;
>  	np->intr_status = 0;
>  	np->eeprom_size = natsemi_pci_info[chip_idx].eeprom_size;
> -	np->ignore_phy = 0;
> +	if (natsemi_pci_info[chip_idx].flags & NATSEMI_FLAG_IGNORE_PHY) {
> +		np->ignore_phy = 1;
> +	} else {
> +		np->ignore_phy = 0;
> +	}


I ACK the patch itself, but since you have to resend anyway, please kill 
the braces surrounding the above single-C-stmt lines.


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

* Re: [patch 1/2] natsemi: Add support for using MII port with no PHY
  2007-02-19 20:15 ` [patch 1/2] natsemi: Add support for using MII port with no PHY Mark Brown
@ 2007-02-20 16:18   ` Jeff Garzik
  0 siblings, 0 replies; 9+ messages in thread
From: Jeff Garzik @ 2007-02-20 16:18 UTC (permalink / raw)
  To: Mark Brown; +Cc: Tim Hockin, netdev, linux-kernel, akpm

Mark Brown wrote:
> This patch provides code paths which allow the natsemi driver to use the
> external MII port on the chip but ignore any PHYs that may be attached to it.
> The link state will be left as it was when the driver started and can be
> configured via ethtool.  Any PHYs that are present can be accessed via the MII
> ioctl()s.
> 
> This is useful for systems where the device is connected without a PHY
> or where either information or actions outside the scope of the driver
> are required in order to use the PHYs.
> 
> Signed-Off-By: Mark Brown <broonie@sirena.org.uk>
> 
> ---
> 
> This revision of the patch fixes some issues brought up during review.
> 
> Previous versions of this patch exposed the new functionality as a module
> option.  This has been removed.  Any hardware that needs this should be
> identifiable by a quirk since it unlikely to behave correctly with an
> unmodified driver.

applied 1-2



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

* [patch 1/2] natsemi: Add support for using MII port with no PHY
  2007-02-19 20:15 [patch 0/2] natsemi: Support Aculab E1/T1 cPCI carrier cards Mark Brown
@ 2007-02-19 20:15 ` Mark Brown
  2007-02-20 16:18   ` Jeff Garzik
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2007-02-19 20:15 UTC (permalink / raw)
  To: Tim Hockin, Jeff Garzik; +Cc: netdev, linux-kernel, akpm

[-- Attachment #1: natsemi-ignore-phy.patch --]
[-- Type: text/plain, Size: 4353 bytes --]

This patch provides code paths which allow the natsemi driver to use the
external MII port on the chip but ignore any PHYs that may be attached to it.
The link state will be left as it was when the driver started and can be
configured via ethtool.  Any PHYs that are present can be accessed via the MII
ioctl()s.

This is useful for systems where the device is connected without a PHY
or where either information or actions outside the scope of the driver
are required in order to use the PHYs.

Signed-Off-By: Mark Brown <broonie@sirena.org.uk>

---

This revision of the patch fixes some issues brought up during review.

Previous versions of this patch exposed the new functionality as a module
option.  This has been removed.  Any hardware that needs this should be
identifiable by a quirk since it unlikely to behave correctly with an
unmodified driver.

Index: linux/drivers/net/natsemi.c
===================================================================
--- linux.orig/drivers/net/natsemi.c	2007-02-19 10:10:40.000000000 +0000
+++ linux/drivers/net/natsemi.c	2007-02-19 10:20:45.000000000 +0000
@@ -568,6 +568,8 @@
 	u32 intr_status;
 	/* Do not touch the nic registers */
 	int hands_off;
+	/* Don't pay attention to the reported link state. */
+	int ignore_phy;
 	/* external phy that is used: only valid if dev->if_port != PORT_TP */
 	int mii;
 	int phy_addr_external;
@@ -696,7 +698,10 @@
 	struct netdev_private *np = netdev_priv(dev);
 	u32 tmp;
 
-	netif_carrier_off(dev);
+	if (np->ignore_phy)
+		netif_carrier_on(dev);
+	else
+		netif_carrier_off(dev);
 
 	/* get the initial settings from hardware */
 	tmp            = mdio_read(dev, MII_BMCR);
@@ -806,8 +811,10 @@
 	np->hands_off = 0;
 	np->intr_status = 0;
 	np->eeprom_size = natsemi_pci_info[chip_idx].eeprom_size;
+	np->ignore_phy = 0;
 
 	/* Initial port:
+	 * - If configured to ignore the PHY set up for external.
 	 * - If the nic was configured to use an external phy and if find_mii
 	 *   finds a phy: use external port, first phy that replies.
 	 * - Otherwise: internal port.
@@ -815,7 +822,7 @@
 	 * The address would be used to access a phy over the mii bus, but
 	 * the internal phy is accessed through mapped registers.
 	 */
-	if (readl(ioaddr + ChipConfig) & CfgExtPhy)
+	if (np->ignore_phy || readl(ioaddr + ChipConfig) & CfgExtPhy)
 		dev->if_port = PORT_MII;
 	else
 		dev->if_port = PORT_TP;
@@ -825,7 +832,9 @@
 
 	if (dev->if_port != PORT_TP) {
 		np->phy_addr_external = find_mii(dev);
-		if (np->phy_addr_external == PHY_ADDR_NONE) {
+		/* If we're ignoring the PHY it doesn't matter if we can't
+		 * find one. */
+		if (!np->ignore_phy && np->phy_addr_external == PHY_ADDR_NONE) {
 			dev->if_port = PORT_TP;
 			np->phy_addr_external = PHY_ADDR_INTERNAL;
 		}
@@ -891,6 +900,8 @@
 		printk("%02x, IRQ %d", dev->dev_addr[i], irq);
 		if (dev->if_port == PORT_TP)
 			printk(", port TP.\n");
+		else if (np->ignore_phy)
+			printk(", port MII, ignoring PHY\n");
 		else
 			printk(", port MII, phy ad %d.\n", np->phy_addr_external);
 	}
@@ -1571,9 +1582,13 @@
 {
 	struct netdev_private *np = netdev_priv(dev);
 	void __iomem * ioaddr = ns_ioaddr(dev);
-	int duplex;
+	int duplex = np->duplex;
 	u16 bmsr;
 
+	/* If we are ignoring the PHY then don't try reading it. */
+	if (np->ignore_phy)
+		goto propagate_state;
+
 	/* The link status field is latched: it remains low after a temporary
 	 * link failure until it's read. We need the current link status,
 	 * thus read twice.
@@ -1585,7 +1600,7 @@
 		if (netif_carrier_ok(dev)) {
 			if (netif_msg_link(np))
 				printk(KERN_NOTICE "%s: link down.\n",
-					dev->name);
+				       dev->name);
 			netif_carrier_off(dev);
 			undo_cable_magic(dev);
 		}
@@ -1609,6 +1624,7 @@
 			duplex = 1;
 	}
 
+propagate_state:
 	/* if duplex is set then bit 28 must be set, too */
 	if (duplex ^ !!(np->rx_config & RxAcceptTx)) {
 		if (netif_msg_link(np))
@@ -2819,6 +2835,15 @@
 	}
 
 	/*
+	 * If we're ignoring the PHY then autoneg and the internal
+	 * transciever are really not going to work so don't let the
+	 * user select them.
+	 */
+	if (np->ignore_phy && (ecmd->autoneg == AUTONEG_ENABLE ||
+			       ecmd->port == PORT_TP))
+		return -EINVAL;
+
+	/*
 	 * maxtxpkt, maxrxpkt: ignored for now.
 	 *
 	 * transceiver:

--
"You grabbed my hand and we fell into it, like a daydream - or a fever."

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

* Re: [patch 1/2] natsemi: Add support for using MII port with no PHY
@ 2007-02-14 13:50 Mark Brown
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2007-02-14 13:50 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: Tim Hockin, Jeff Garzik, netdev, linux-kernel

On Wed, Feb 14, 2007 at 03:28:34PM +0200, Ahmed S. Darwish wrote:

> A trivial comment actually, Is there a point to write multi-line comments 
> in two different formats ?

No goal in doing that, no - it wasn't a conscious decision.

-- 
"You grabbed my hand and we fell into it, like a daydream - or a fever."

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

end of thread, other threads:[~2007-02-20 16:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-14 10:02 [patch 0/2] natsemi: Support Aculab E1/T1 cPCI carrier cards Mark Brown
2007-02-14 10:02 ` [patch 1/2] natsemi: Add support for using MII port with no PHY Mark Brown
2007-02-14 13:28   ` Ahmed S. Darwish
2007-02-17 20:21   ` Jeff Garzik
2007-02-14 10:02 ` [patch 2/2] natsemi: Support Aculab E1/T1 PMXc cPCI carrier cards Mark Brown
2007-02-17 20:22   ` Jeff Garzik
2007-02-14 13:50 [patch 1/2] natsemi: Add support for using MII port with no PHY Mark Brown
2007-02-19 20:15 [patch 0/2] natsemi: Support Aculab E1/T1 cPCI carrier cards Mark Brown
2007-02-19 20:15 ` [patch 1/2] natsemi: Add support for using MII port with no PHY Mark Brown
2007-02-20 16:18   ` Jeff Garzik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.