[OpenWrt-Devel,2/3,RFC] ar7240: report port link state changes to kernel log
diff mbox

Message ID 1418152881-7354-2-git-send-email-lynxis@fe80.eu
State Rejected
Headers show

Commit Message

Alexander Couzens Dec. 9, 2014, 7:21 p.m. UTC
Like other network device report link change to kernel log.
switch eth0 port 1: Link 100baseT Mbit duplex: full
---
 .../net/ethernet/atheros/ag71xx/ag71xx_ar7240.c    | 27 ++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

Patch
diff mbox

diff --git a/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_ar7240.c b/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_ar7240.c
index d4ccc02..a94837a 100644
--- a/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_ar7240.c
+++ b/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_ar7240.c
@@ -300,6 +300,7 @@  struct ar7240sw {
 	u8 vlan_tagged;
 	u16 pvid[AR7240_NUM_PORTS];
 	char buf[80];
+	u8 link;
 
 	rwlock_t stats_lock;
 	struct ar7240sw_port_stat port_stats[AR7240_NUM_PORTS];
@@ -1136,9 +1137,31 @@  static void link_function(struct work_struct *work) {
 			continue;
 
 		link = ar7240sw_phy_read(ag->mii_bus, i, MII_BMSR);
-		if (link & BMSR_LSTATUS) {
+		link &= BMSR_LSTATUS;
+		link = !!link;
+
+		if (link && !status)
 			status = 1;
-			break;
+
+		if ((!!(as->link & BIT(i))) != link) {
+			struct switch_port_link swlink;
+			int port = i + 1;
+			memset(&swlink, '0', sizeof(swlink));
+			/* link change */
+			if (link) {
+				as->link |= BIT(i);
+				as->swdev.ops->get_port_link(&as->swdev, port, &swlink);
+				pr_info("switch %s port %d: link %s Mbit duplex: %s\n",
+						as->swdev.netdev ? as->swdev.netdev->name : as->swdev.alias,
+						port,
+						swconfig_speed_str(swlink.speed),
+						swlink.duplex ? "full" : "half");
+			} else {
+				as->link &= ~BIT(i);
+				pr_info("switch %s port %d: link down\n",
+						as->swdev.netdev ? as->swdev.netdev->name : as->swdev.alias,
+						port);
+			}
 		}
 	}