hyperv: Fix the carrier status setting
Subsystems (3)
Haiyang Zhang
maintainerPATCH v2 1/1 hyperv: Fix the carrier status setting
Without this patch, the "cat /sys/class/net/ethN/operstate" shows "unknown", and "ethtool ethN" shows "Link detected: yes", when VM boots up with or without vNIC connected.
This patch fixed the problem.
--- drivers/net/hyperv/netvsc_drv.c | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-)
drivers/net/hyperv/netvsc_drv.c +15 -9
@@ -88,8 +88,12 @@ static int netvsc_open(struct net_device *net) {struct net_device_context *net_device_ctx =netdev_priv (net);struct hv_device *device_obj = net_device_ctx->device_ctx; +struct netvsc_device *nvdev; +struct rndis_device *rdev;int ret =0 ; +netif_carrier_off (net); +/* Open up the device */ ret =rndis_filter_open (device_obj);if (ret !=0 ) {
@@ -99,6 +103,11 @@ static int netvsc_open(struct net_device *net)netif_start_queue (net); + nvdev =hv_get_drvdata (device_obj); + rdev = nvdev->extension; +if (!rdev->link_state) +netif_carrier_on (net); +return ret; }
@@ -229,15 +238,17 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,struct net_device *net;struct net_device_context *ndev_ctx;struct netvsc_device *net_device; +struct rndis_device *rdev; net_device =hv_get_drvdata (device_obj); + rdev = net_device->extension; + + rdev->link_state = status !=1 ; + net = net_device->ndev; -if (!net) { -netdev_err (net,"got link status but net device " -"not initialized yet\n" ); +if (!net || net->reg_state !=NETREG_REGISTERED )return ; - }if (status ==1 ) {netif_carrier_on (net);
@@ -414,9 +425,6 @@ static int netvsc_probe(struct hv_device *dev,if (!net)return -ENOMEM ; -/* Set initial state */ -netif_carrier_off (net); - net_device_ctx =netdev_priv (net); net_device_ctx->device_ctx = dev;hv_set_drvdata (dev, net);
@@ -443,8 +451,6 @@ static int netvsc_probe(struct hv_device *dev, }memcpy (net->dev_addr, device_info.mac_adr,ETH_ALEN ); -netif_carrier_on (net); - ret =register_netdev (net);if (ret !=0 ) {pr_err ("Unable to register netdev.\n" );
Signature · 1 line
1.7.4.1
Quoted 30 lines · Haiyang Zhang
Without this patch, the "cat
/sys/class/net/ethN/operstate" shows "unknown", and "ethtool ethN" shows "Link detected: yes", when VM boots up with or without vNIC connected.This patch fixed the problem.
Signed-off-by Haiyang Zhang <[email protected]>Reviewed-by K. Y. Srinivasan <[email protected]>--- drivers/net/hyperv/netvsc_drv.c | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-)drivers/net/hyperv/netvsc_drv.c +4
-0@@ -88,8 +88,12 @@ static int netvsc_open(struct net_device *net) {struct net_device_context *net_device_ctx =netdev_priv (net);struct hv_device *device_obj = net_device_ctx->device_ctx; +struct netvsc_device *nvdev; +struct rndis_device *rdev;int ret =0 ; +netif_carrier_off (net); +/* Open up the device */ ret =rndis_filter_open (device_obj);if (ret !=0 ) {
drivers/net/hyperv/netvsc_drv.c static int netvsc_open(struct net_device *net) · line 108
Quoted 6 lines
drivers/net/hyperv/netvsc_drv.c +3
-0@@ -99,6 +103,11 @@ static int netvsc_open(struct net_device *net)netif_start_queue (net); + nvdev =hv_get_drvdata (device_obj); + rdev = nvdev->extension; +if (!rdev->link_state)
What if the link status interrupt comes here at this time?
Quoted 46 lines
drivers/net/hyperv/netvsc_drv.c +8
-9+netif_carrier_on (net); +return ret; }@@ -229,15 +238,17 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,struct net_device *net;struct net_device_context *ndev_ctx;struct netvsc_device *net_device; +struct rndis_device *rdev; net_device =hv_get_drvdata (device_obj); + rdev = net_device->extension; + + rdev->link_state = status !=1 ; + net = net_device->ndev; -if (!net) { -netdev_err (net,"got link status but net device " -"not initialized yet\n" ); +if (!net || net->reg_state !=NETREG_REGISTERED )return ; - }if (status ==1 ) {netif_carrier_on (net);@@ -414,9 +425,6 @@ static int netvsc_probe(struct hv_device *dev,if (!net)return -ENOMEM ; -/* Set initial state */ -netif_carrier_off (net); - net_device_ctx =netdev_priv (net); net_device_ctx->device_ctx = dev;hv_set_drvdata (dev, net);@@ -443,8 +451,6 @@ static int netvsc_probe(struct hv_device *dev, }memcpy (net->dev_addr, device_info.mac_adr,ETH_ALEN ); -netif_carrier_on (net); - ret =register_netdev (net);if (ret !=0 ) {pr_err ("Unable to register netdev.\n" );
Haiyang Zhang
maintainerQuoted 41 lines
-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, February 11, 2014 4:51 AM
To: Haiyang Zhang; [email protected]; [email protected]
Cc: KY Srinivasan; [email protected]; [email protected]; driverdev- [email protected]
Subject: Re: [PATCH net,v2] hyperv: Fix the carrier status settingQuoted 30 lines · Haiyang Zhang
Without this patch, the "cat
/sys/class/net/ethN/operstate" shows "unknown", and "ethtool ethN" shows "Link detected: yes", when VM boots up with or without vNIC connected.This patch fixed the problem.
Signed-off-by Haiyang Zhang <[email protected]>Reviewed-by K. Y. Srinivasan <[email protected]>--- drivers/net/hyperv/netvsc_drv.c | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-)(quoted diff) +0
-0
b/drivers/net/hyperv/netvsc_drv.cindex 7756118..18916f7 100644drivers/net/hyperv/netvsc_drv.c +4
-0@@ -88,8 +88,12 @@ static int netvsc_open(struct net_device *net) {struct net_device_context *net_device_ctx =netdev_priv (net);struct hv_device *device_obj = net_device_ctx->device_ctx; +struct netvsc_device *nvdev; +struct rndis_device *rdev;int ret =0 ; +netif_carrier_off (net); +/* Open up the device */ ret =rndis_filter_open (device_obj);if (ret !=0 ) {@@ -99,6 +103,11 @@ static int netvsc_open(struct net_device *net)
Quoted 7 lines
drivers/net/hyperv/netvsc_drv.c static int netvsc_open(struct net_device *net) · line 108
Quoted 5 lines
drivers/net/hyperv/netvsc_drv.c +3
-0netif_start_queue (net); + nvdev =hv_get_drvdata (device_obj); + rdev = nvdev->extension; +if (!rdev->link_state)What if the link status interrupt comes here at this time?
Thank you for pointing this out. I have submitted an updated patch.
- Haiyang