diff options
author | Stephen Hemminger <stephen@networkplumber.org> | 2018-09-14 15:54:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-09-17 10:59:41 -0400 |
commit | 00d7ddba1143623b31bc2c15d18216e2da031b14 (patch) | |
tree | e0815806a52bc6669417949d52257c22539bdf70 | |
parent | a15f2c08c70811f120d99288d81f70d7f3d104f1 (diff) |
hv_netvsc: pair VF based on serial number
Matching network device based on MAC address is problematic
since a non VF network device can be creted with a duplicate MAC
address causing confusion and problems. The VMBus API does provide
a serial number that is a better matching method.
Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/hyperv/netvsc.c | 3 | ||||
-rw-r--r-- | drivers/net/hyperv/netvsc_drv.c | 58 |
2 files changed, 36 insertions, 25 deletions
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 31c3d77b4733..fe01e141c8f8 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c | |||
@@ -1203,6 +1203,9 @@ static void netvsc_send_vf(struct net_device *ndev, | |||
1203 | 1203 | ||
1204 | net_device_ctx->vf_alloc = nvmsg->msg.v4_msg.vf_assoc.allocated; | 1204 | net_device_ctx->vf_alloc = nvmsg->msg.v4_msg.vf_assoc.allocated; |
1205 | net_device_ctx->vf_serial = nvmsg->msg.v4_msg.vf_assoc.serial; | 1205 | net_device_ctx->vf_serial = nvmsg->msg.v4_msg.vf_assoc.serial; |
1206 | netdev_info(ndev, "VF slot %u %s\n", | ||
1207 | net_device_ctx->vf_serial, | ||
1208 | net_device_ctx->vf_alloc ? "added" : "removed"); | ||
1206 | } | 1209 | } |
1207 | 1210 | ||
1208 | static void netvsc_receive_inband(struct net_device *ndev, | 1211 | static void netvsc_receive_inband(struct net_device *ndev, |
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 915fbd66a02b..3af6d8d15233 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c | |||
@@ -1894,20 +1894,6 @@ out_unlock: | |||
1894 | rtnl_unlock(); | 1894 | rtnl_unlock(); |
1895 | } | 1895 | } |
1896 | 1896 | ||
1897 | static struct net_device *get_netvsc_bymac(const u8 *mac) | ||
1898 | { | ||
1899 | struct net_device_context *ndev_ctx; | ||
1900 | |||
1901 | list_for_each_entry(ndev_ctx, &netvsc_dev_list, list) { | ||
1902 | struct net_device *dev = hv_get_drvdata(ndev_ctx->device_ctx); | ||
1903 | |||
1904 | if (ether_addr_equal(mac, dev->perm_addr)) | ||
1905 | return dev; | ||
1906 | } | ||
1907 | |||
1908 | return NULL; | ||
1909 | } | ||
1910 | |||
1911 | static struct net_device *get_netvsc_byref(struct net_device *vf_netdev) | 1897 | static struct net_device *get_netvsc_byref(struct net_device *vf_netdev) |
1912 | { | 1898 | { |
1913 | struct net_device_context *net_device_ctx; | 1899 | struct net_device_context *net_device_ctx; |
@@ -2036,26 +2022,48 @@ static void netvsc_vf_setup(struct work_struct *w) | |||
2036 | rtnl_unlock(); | 2022 | rtnl_unlock(); |
2037 | } | 2023 | } |
2038 | 2024 | ||
2025 | /* Find netvsc by VMBus serial number. | ||
2026 | * The PCI hyperv controller records the serial number as the slot. | ||
2027 | */ | ||
2028 | static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev) | ||
2029 | { | ||
2030 | struct device *parent = vf_netdev->dev.parent; | ||
2031 | struct net_device_context *ndev_ctx; | ||
2032 | struct pci_dev *pdev; | ||
2033 | |||
2034 | if (!parent || !dev_is_pci(parent)) | ||
2035 | return NULL; /* not a PCI device */ | ||
2036 | |||
2037 | pdev = to_pci_dev(parent); | ||
2038 | if (!pdev->slot) { | ||
2039 | netdev_notice(vf_netdev, "no PCI slot information\n"); | ||
2040 | return NULL; | ||
2041 | } | ||
2042 | |||
2043 | list_for_each_entry(ndev_ctx, &netvsc_dev_list, list) { | ||
2044 | if (!ndev_ctx->vf_alloc) | ||
2045 | continue; | ||
2046 | |||
2047 | if (ndev_ctx->vf_serial == pdev->slot->number) | ||
2048 | return hv_get_drvdata(ndev_ctx->device_ctx); | ||
2049 | } | ||
2050 | |||
2051 | netdev_notice(vf_netdev, | ||
2052 | "no netdev found for slot %u\n", pdev->slot->number); | ||
2053 | return NULL; | ||
2054 | } | ||
2055 | |||
2039 | static int netvsc_register_vf(struct net_device *vf_netdev) | 2056 | static int netvsc_register_vf(struct net_device *vf_netdev) |
2040 | { | 2057 | { |
2041 | struct net_device *ndev; | ||
2042 | struct net_device_context *net_device_ctx; | 2058 | struct net_device_context *net_device_ctx; |
2043 | struct device *pdev = vf_netdev->dev.parent; | ||
2044 | struct netvsc_device *netvsc_dev; | 2059 | struct netvsc_device *netvsc_dev; |
2060 | struct net_device *ndev; | ||
2045 | int ret; | 2061 | int ret; |
2046 | 2062 | ||
2047 | if (vf_netdev->addr_len != ETH_ALEN) | 2063 | if (vf_netdev->addr_len != ETH_ALEN) |
2048 | return NOTIFY_DONE; | 2064 | return NOTIFY_DONE; |
2049 | 2065 | ||
2050 | if (!pdev || !dev_is_pci(pdev) || dev_is_pf(pdev)) | 2066 | ndev = get_netvsc_byslot(vf_netdev); |
2051 | return NOTIFY_DONE; | ||
2052 | |||
2053 | /* | ||
2054 | * We will use the MAC address to locate the synthetic interface to | ||
2055 | * associate with the VF interface. If we don't find a matching | ||
2056 | * synthetic interface, move on. | ||
2057 | */ | ||
2058 | ndev = get_netvsc_bymac(vf_netdev->perm_addr); | ||
2059 | if (!ndev) | 2067 | if (!ndev) |
2060 | return NOTIFY_DONE; | 2068 | return NOTIFY_DONE; |
2061 | 2069 | ||