Re: [patch 1/4] natsemi: Add support for using MII port with no PHY

2006-03-16 Thread Andrew Morton
Mark Brown [EMAIL PROTECTED] wrote:

  +if (np-ignore_phy  (ecmd-autoneg == AUTONEG_ENABLE ||
  +   ecmd-port == PORT_INTERNAL)) {

What's PORT_INTERNAL?  ethtool doesn't appear to define that.

drivers/net/natsemi.c: In function `netdev_set_ecmd':
drivers/net/natsemi.c:2989: `PORT_INTERNAL' undeclared (first use in this 
function)
drivers/net/natsemi.c:2989: (Each undeclared identifier is reported only once
drivers/net/natsemi.c:2989: for each function it appears in.)

-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch 1/4] natsemi: Add support for using MII port with no PHY

2006-03-16 Thread Mark Brown
On Thu, Mar 16, 2006 at 01:09:02AM -0800, Andrew Morton wrote:
 Mark Brown [EMAIL PROTECTED] wrote:

   +  if (np-ignore_phy  (ecmd-autoneg == AUTONEG_ENABLE ||
   + ecmd-port == PORT_INTERNAL)) {

 What's PORT_INTERNAL?  ethtool doesn't appear to define that.

It should be PORT_TP, sorry:

This patch provides a module option which configures 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 [EMAIL PROTECTED]

Index: natsemi-queue/drivers/net/natsemi.c
===
--- natsemi-queue.orig/drivers/net/natsemi.c2006-02-25 13:38:34.0 
+
+++ natsemi-queue/drivers/net/natsemi.c 2006-02-25 13:50:51.0 +
@@ -259,7 +259,7 @@ MODULE_PARM_DESC(debug, DP8381x default
 MODULE_PARM_DESC(rx_copybreak, 
DP8381x copy breakpoint for copy-only-tiny-frames);
 MODULE_PARM_DESC(options, 
-   DP8381x: Bits 0-3: media type, bit 17: full duplex);
+   DP8381x: Bits 0-3: media type, bit 17: full duplex, bit 18: ignore 
PHY);
 MODULE_PARM_DESC(full_duplex, DP8381x full duplex setting(s) (1));
 
 /*
@@ -690,6 +690,8 @@ struct netdev_private {
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;
@@ -891,7 +893,19 @@ static int __devinit natsemi_probe1 (str
np-hands_off = 0;
np-intr_status = 0;
 
+   option = find_cnt  MAX_UNITS ? options[find_cnt] : 0;
+   if (dev-mem_start)
+   option = dev-mem_start;
+
+   /* Ignore the PHY status? */
+   if (option  0x400) {
+   np-ignore_phy = 1;
+   } else {
+   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.
@@ -899,7 +913,7 @@ static int __devinit natsemi_probe1 (str
 * 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;
@@ -909,7 +923,9 @@ static int __devinit natsemi_probe1 (str
 
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;
}
@@ -917,10 +933,6 @@ static int __devinit natsemi_probe1 (str
np-phy_addr_external = PHY_ADDR_INTERNAL;
}
 
-   option = find_cnt  MAX_UNITS ? options[find_cnt] : 0;
-   if (dev-mem_start)
-   option = dev-mem_start;
-
/* The lower four bits are the media type. */
if (option) {
if (option  0x200)
@@ -954,7 +966,10 @@ static int __devinit natsemi_probe1 (str
if (mtu)
dev-mtu = mtu;
 
-   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);
@@ -1002,6 +1017,8 @@ static int __devinit natsemi_probe1 (str
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);
}
@@ -1682,42 +1699,44 @@ static void check_link(struct net_device
 {
struct netdev_private *np = netdev_priv(dev);
void __iomem * ioaddr = ns_ioaddr(dev);
-   int duplex;
+   int duplex = np-full_duplex;
u16 bmsr;
-   
-   /* The link status field is 

Re: [patch 1/4] natsemi: Add support for using MII port with no PHY

2006-03-13 Thread Mark Brown
On Sun, Mar 12, 2006 at 01:41:13PM -0800, [EMAIL PROTECTED] wrote:

 Not that my opinion should hold much weight, having been absent from the
 driver for some time, but yuck.  Is there no better way to do this thatn
 sprinkling poo all over it?

The changes are mostly isolated into check_link(), the fact that half
the function gets placed inside a conditional but diff sees it as a
bunch of smaller changes makes the changes look a lot more invasive than
they actually are.  I guess that could be helped by splitting the PHY
access code out of check_link() into check_phy_status() or something but
I'm not sure how much that really helps.

-- 
You grabbed my hand and we fell into it, like a daydream - or a fever.
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch 1/4] natsemi: Add support for using MII port with no PHY

2006-03-13 Thread thockin
On Mon, Mar 13, 2006 at 06:23:31PM +, Mark Brown wrote:
 On Sun, Mar 12, 2006 at 01:41:13PM -0800, [EMAIL PROTECTED] wrote:
 
  Not that my opinion should hold much weight, having been absent from the
  driver for some time, but yuck.  Is there no better way to do this thatn
  sprinkling poo all over it?
 
 The changes are mostly isolated into check_link(), the fact that half
 the function gets placed inside a conditional but diff sees it as a
 bunch of smaller changes makes the changes look a lot more invasive than
 they actually are.  I guess that could be helped by splitting the PHY
 access code out of check_link() into check_phy_status() or something but
 I'm not sure how much that really helps.

It's not terribly offensive it just seems like a hack. :)  I'm not sure I
really understand the reasoning, so I can't offer anythign better or more
general purpose.
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 1/4] natsemi: Add support for using MII port with no PHY

2006-03-12 Thread Mark Brown
This patch provides a module option which configures 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 [EMAIL PROTECTED]

Index: natsemi-queue/drivers/net/natsemi.c
===
--- natsemi-queue.orig/drivers/net/natsemi.c2006-02-25 13:38:34.0 
+
+++ natsemi-queue/drivers/net/natsemi.c 2006-02-25 13:50:51.0 +
@@ -259,7 +259,7 @@ MODULE_PARM_DESC(debug, DP8381x default
 MODULE_PARM_DESC(rx_copybreak, 
DP8381x copy breakpoint for copy-only-tiny-frames);
 MODULE_PARM_DESC(options, 
-   DP8381x: Bits 0-3: media type, bit 17: full duplex);
+   DP8381x: Bits 0-3: media type, bit 17: full duplex, bit 18: ignore 
PHY);
 MODULE_PARM_DESC(full_duplex, DP8381x full duplex setting(s) (1));
 
 /*
@@ -690,6 +690,8 @@ struct netdev_private {
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;
@@ -891,7 +893,19 @@ static int __devinit natsemi_probe1 (str
np-hands_off = 0;
np-intr_status = 0;
 
+   option = find_cnt  MAX_UNITS ? options[find_cnt] : 0;
+   if (dev-mem_start)
+   option = dev-mem_start;
+
+   /* Ignore the PHY status? */
+   if (option  0x400) {
+   np-ignore_phy = 1;
+   } else {
+   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.
@@ -899,7 +913,7 @@ static int __devinit natsemi_probe1 (str
 * 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;
@@ -909,7 +923,9 @@ static int __devinit natsemi_probe1 (str
 
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;
}
@@ -917,10 +933,6 @@ static int __devinit natsemi_probe1 (str
np-phy_addr_external = PHY_ADDR_INTERNAL;
}
 
-   option = find_cnt  MAX_UNITS ? options[find_cnt] : 0;
-   if (dev-mem_start)
-   option = dev-mem_start;
-
/* The lower four bits are the media type. */
if (option) {
if (option  0x200)
@@ -954,7 +966,10 @@ static int __devinit natsemi_probe1 (str
if (mtu)
dev-mtu = mtu;
 
-   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);
@@ -1002,6 +1017,8 @@ static int __devinit natsemi_probe1 (str
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);
}
@@ -1682,42 +1699,44 @@ static void check_link(struct net_device
 {
struct netdev_private *np = netdev_priv(dev);
void __iomem * ioaddr = ns_ioaddr(dev);
-   int duplex;
+   int duplex = np-full_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 (!(bmsr  BMSR_LSTATUS)) {
-   if (netif_carrier_ok(dev)) {
+