From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/1] net/eth: fix link handling
Date: Wed, 26 Sep 2012 15:59:36 +0200 [thread overview]
Message-ID: <1348667976-25910-1-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20120924093122.GD26553@game.jcrosoft.org>
The current code handle just the send where we are supposed to the same on rx
The current code use activate for both open and link up.
Now we handle both seperatly and update the link at first rx or tx not at
open.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
drivers/net/phy/phy.c | 34 ++++++++++++++++-------
include/linux/phy.h | 3 +++
include/net.h | 4 +++
net/eth.c | 72 ++++++++++++++++++++++++++++++++++++-------------
4 files changed, 85 insertions(+), 28 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e1a24fa..56cc25b 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -29,6 +29,29 @@
static int genphy_config_init(struct phy_device *phydev);
+int phy_update_status(struct phy_device *dev)
+{
+ struct phy_driver *drv = to_phy_driver(dev->dev.driver);
+ struct eth_device *edev = dev->attached_dev;
+ int ret;
+
+ ret = drv->read_status(dev);
+ if (ret)
+ return ret;
+
+ if (dev->link == edev->carrier)
+ return 0;
+
+ dev->adjust_link(edev);
+ edev->carrier = dev->link;
+
+ if (dev->link)
+ printf("%dMbps %s duplex link detected\n", dev->speed,
+ dev->duplex ? "full" : "half");
+
+ return 0;
+}
+
struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id)
{
struct phy_device *dev;
@@ -172,16 +195,7 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
drv->config_aneg(dev);
- ret = drv->read_status(dev);
- if (ret < 0)
- return ret;
-
- if (dev->link)
- printf("%dMbps %s duplex link detected\n", dev->speed,
- dev->duplex ? "full" : "half");
-
- if (adjust_link)
- adjust_link(edev);
+ dev->adjust_link = adjust_link;
return 0;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 8fe6b86..76f9edb 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -164,6 +164,7 @@ struct phy_device {
void *priv;
struct eth_device *attached_dev;
+ void (*adjust_link)(struct eth_device *dev);
struct cdev cdev;
};
@@ -253,6 +254,8 @@ int phy_device_connect(struct eth_device *dev, struct mii_bus *bus, int addr,
void (*adjust_link) (struct eth_device *edev),
u32 flags, phy_interface_t interface);
+int phy_update_status(struct phy_device *phydev);
+
/* Generic PHY support and helper functions */
int genphy_restart_aneg(struct phy_device *phydev);
int genphy_config_aneg(struct phy_device *phydev);
diff --git a/include/net.h b/include/net.h
index 39fad12..a3474a5 100644
--- a/include/net.h
+++ b/include/net.h
@@ -32,6 +32,10 @@ struct device_d;
struct eth_device {
int active;
+ #define CARRIER_ON 0
+ #define CARRIER_OFF 1
+ #define CARRIER_UNKNOW -1
+ int carrier;
int (*init) (struct eth_device*);
diff --git a/net/eth.c b/net/eth.c
index beedd22..2e01cc1 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -28,6 +28,7 @@
#include <malloc.h>
static struct eth_device *eth_current;
+static uint64_t last_link_check;
static LIST_HEAD(netdev_list);
@@ -124,24 +125,61 @@ int eth_complete(struct string_list *sl, char *instr)
}
#endif
-int eth_send(void *packet, int length)
+static int eth_carrier_check(void)
{
int ret;
- if (!eth_current)
- return -ENODEV;
+ if (!eth_current->phydev) {
+ eth_current->carrier = CARRIER_ON;
+ return 0;
+ }
- if (!eth_current->active) {
- ret = eth_current->open(eth_current);
+ if (eth_current->carrier == CARRIER_UNKNOW ||
+ is_timeout(last_link_check, 10 * SECOND)) {
+ ret = phy_update_status(eth_current->phydev);
if (ret)
return ret;
-
- if (eth_current->phydev)
- eth_current->active = eth_current->phydev->link;
- else
- eth_current->active = 1;
+ last_link_check = get_time_ns();
}
+ if (!eth_current->carrier)
+ return -ENETDOWN;
+
+ return 0;
+}
+
+int eth_open(void)
+{
+ int ret;
+
+ if (!eth_current)
+ return -ENODEV;
+
+ if (eth_current->active)
+ return 0;
+
+ ret = eth_current->open(eth_current);
+ if (ret)
+ return ret;
+
+ eth_current->active = 1;
+ eth_current->carrier = CARRIER_UNKNOW;
+
+ return 0;
+}
+
+int eth_send(void *packet, int length)
+{
+ int ret;
+
+ ret = eth_open();
+ if (ret)
+ return ret;
+
+ ret = eth_carrier_check();
+ if (ret)
+ return ret;
+
led_trigger_network(LED_TRIGGER_NET_TX);
return eth_current->send(eth_current, packet, length);
@@ -151,15 +189,13 @@ int eth_rx(void)
{
int ret;
- if (!eth_current)
- return -ENODEV;
+ ret = eth_open();
+ if (ret)
+ return ret;
- if (!eth_current->active) {
- ret = eth_current->open(eth_current);
- if (ret)
- return ret;
- eth_current->active = 1;
- }
+ ret = eth_carrier_check();
+ if (ret)
+ return ret;
return eth_current->recv(eth_current);
}
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-09-26 14:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-24 9:31 [PATCH 0/1 v7] net: introduce phylib Jean-Christophe PLAGNIOL-VILLARD
2012-09-24 9:36 ` [PATCH 1/1] " Jean-Christophe PLAGNIOL-VILLARD
2012-09-24 19:20 ` [PATCH 0/1 v7] " Sascha Hauer
2012-09-24 20:14 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-25 17:26 ` Jan Lübbe
2012-09-25 18:19 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 11:02 ` Sascha Hauer
2012-09-26 11:20 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 11:31 ` Sascha Hauer
2012-09-26 11:36 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 11:37 ` [PATCH 1/2] calao: at91 qil/tny/usb auto detect the phy addr Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 11:37 ` [PATCH 2/2] net/eth: fix missing check on eth active Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 11:53 ` [PATCH 3/3] net/eth: fix link handling Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 12:43 ` Sascha Hauer
2012-09-26 12:50 ` Jan Lübbe
2012-09-26 13:03 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 13:08 ` Sascha Hauer
2012-09-26 13:43 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 13:05 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 13:59 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-09-26 15:17 ` [PATCH 1/1] " Sascha Hauer
2012-09-26 15:51 ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-02 14:44 ` [PATCH 0/1 v7] net: introduce phylib Renaud Barbier
2012-10-02 16:04 ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-02 16:58 ` Sascha Hauer
2012-10-02 18:32 ` Jean-Christophe PLAGNIOL-VILLARD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1348667976-25910-1-git-send-email-plagnioj@jcrosoft.com \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox