hv_netvsc: Fix the carrier state error when data path is off
authorHaiyang Zhang <haiyangz@microsoft.com>
Wed, 21 Jun 2017 23:40:47 +0000 (16:40 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 22 Jun 2017 17:30:37 +0000 (13:30 -0400)
When the VF NIC is opened, the synthetic NIC's carrier state is set to
off. This tells the host to transitions data path to the VF device. But
if startup script or user manipulates the admin state of the netvsc
device directly for example:
        # ifconfig eth0 down
# ifconfig eth0 up
Then the carrier state of the synthetic NIC would be on, even though the
data path was still over the VF NIC. This patch sets the carrier state
of synthetic NIC with consideration of the related VF state.

Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Reviewed-by: Stephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/hyperv/hyperv_net.h
drivers/net/hyperv/netvsc.c
drivers/net/hyperv/netvsc_drv.c

index ced947d257936f52e9b4a9af1e78534e51fa438a..d6c25580f8dd636dc43fe464adb339f597fdbcee 100644 (file)
@@ -717,6 +717,8 @@ struct net_device_context {
        u32 vf_alloc;
        /* Serial number of the VF to team with */
        u32 vf_serial;
+
+       bool datapath;  /* 0 - synthetic, 1 - VF nic */
 };
 
 /* Per channel data */
index 7c5ed8fe7a4fad77f0f34e40274adf45bc2cb568..0a9167dd72fb94e50692fa70ec9bc50fd99f733e 100644 (file)
@@ -57,6 +57,8 @@ void netvsc_switch_datapath(struct net_device *ndev, bool vf)
                               sizeof(struct nvsp_message),
                               (unsigned long)init_pkt,
                               VM_PKT_DATA_INBAND, 0);
+
+       net_device_ctx->datapath = vf;
 }
 
 static struct netvsc_device *alloc_net_device(void)
index 9a6c5864bc047ba94a0a59fdc03032a5385005d9..9913721504630f5dcee29536407bf7ecc7f16017 100644 (file)
@@ -68,7 +68,8 @@ static void netvsc_set_multicast_list(struct net_device *net)
 
 static int netvsc_open(struct net_device *net)
 {
-       struct netvsc_device *nvdev = net_device_to_netvsc_device(net);
+       struct net_device_context *ndev_ctx = netdev_priv(net);
+       struct netvsc_device *nvdev = ndev_ctx->nvdev;
        struct rndis_device *rdev;
        int ret = 0;
 
@@ -84,7 +85,7 @@ static int netvsc_open(struct net_device *net)
        netif_tx_wake_all_queues(net);
 
        rdev = nvdev->extension;
-       if (!rdev->link_state)
+       if (!rdev->link_state && !ndev_ctx->datapath)
                netif_carrier_on(net);
 
        return ret;
@@ -1284,7 +1285,8 @@ static void netvsc_link_change(struct work_struct *w)
        case RNDIS_STATUS_MEDIA_CONNECT:
                if (rdev->link_state) {
                        rdev->link_state = false;
-                       netif_carrier_on(net);
+                       if (!ndev_ctx->datapath)
+                               netif_carrier_on(net);
                        netif_tx_wake_all_queues(net);
                } else {
                        notify = true;