Skip to contentSkip to conversation

vmxnet3: set carrier state properly on probe

PATCH Superseded Neil Horman 4 participants 12 messages Jan 25, 2013 – Jan 29, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmxnet3: set carrier state properly on probe

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Tested successfully by myself

CC "David S. Miller" <[email protected]>
CC "VMware, Inc." <[email protected]>
---
 drivers/net/vmxnet3/vmxnet3_drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_drv.c +3 -4
index b1c90f8..66c26a9 100644
@@ -150,8 +150,7 @@ vmxnet3_check_link(struct vmxnet3_adapter *adapter, bool affectTxQueue)
 	if (ret & 1) { /* Link is up. */
 		netdev_info(adapter->netdev, "NIC Link is Up %d Mbps\n",
 			    adapter->link_speed);
-		if (!netif_carrier_ok(adapter->netdev))
-			netif_carrier_on(adapter->netdev);
+		netif_carrier_on(adapter->netdev);
 
 		if (affectTxQueue) {
 			for (i = 0; i < adapter->num_tx_queues; i++)
@@ -160,8 +159,7 @@ vmxnet3_check_link(struct vmxnet3_adapter *adapter, bool affectTxQueue)
 		}
 	} else {
 		netdev_info(adapter->netdev, "NIC Link is Down\n");
-		if (netif_carrier_ok(adapter->netdev))
-			netif_carrier_off(adapter->netdev);
+		netif_carrier_off(adapter->netdev);
 
 		if (affectTxQueue) {
 			for (i = 0; i < adapter->num_tx_queues; i++)
@@ -3067,6 +3065,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
 		goto err_register;
 	}
 
+	netif_carrier_off(netdev);
 	vmxnet3_check_link(adapter, false);
 	return 0;
 
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 22 lines · Neil Horman

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Tested successfully by myself

CC "David S. Miller" <[email protected]>
CC "VMware, Inc." <[email protected]>
---
 drivers/net/vmxnet3/vmxnet3_drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_drv.c +0 -0
index b1c90f8..66c26a9 100644

[...]

drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_probe_device(struct pci_dev *pdev, · line 3071

Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1 -0
@@ -3067,6 +3065,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
 		goto err_register;
 	}
 
+	netif_carrier_off(netdev);
 	vmxnet3_check_link(adapter, false);
 	return 0;
 

You should do this before calling register_netdev(), otherwise the link state change can race with vmxnet3_open().

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#6 lore raw

PATCH v2 1/1 vmxnet3: set carrier state properly on probe

In reply to Neil Horman

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Tested successfully by myself

CC "David S. Miller" <[email protected]>
CC "VMware, Inc." <[email protected]>
CC Ben Hutchings <[email protected]>

---
Change notes:

v2) Moved netif_carrier_off above register_netdev to prevent race with dev_open as per Ben H.

---
 drivers/net/vmxnet3/vmxnet3_drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_drv.c +3 -4
index b1c90f8..ffb97b2 100644
@@ -150,8 +150,7 @@ vmxnet3_check_link(struct vmxnet3_adapter *adapter, bool affectTxQueue)
 	if (ret & 1) { /* Link is up. */
 		netdev_info(adapter->netdev, "NIC Link is Up %d Mbps\n",
 			    adapter->link_speed);
-		if (!netif_carrier_ok(adapter->netdev))
-			netif_carrier_on(adapter->netdev);
+		netif_carrier_on(adapter->netdev);
 
 		if (affectTxQueue) {
 			for (i = 0; i < adapter->num_tx_queues; i++)
@@ -160,8 +159,7 @@ vmxnet3_check_link(struct vmxnet3_adapter *adapter, bool affectTxQueue)
 		}
 	} else {
 		netdev_info(adapter->netdev, "NIC Link is Down\n");
-		if (netif_carrier_ok(adapter->netdev))
-			netif_carrier_off(adapter->netdev);
+		netif_carrier_off(adapter->netdev);
 
 		if (affectTxQueue) {
 			for (i = 0; i < adapter->num_tx_queues; i++)
@@ -3060,6 +3058,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
 	netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
 	netif_set_real_num_rx_queues(adapter->netdev, adapter->num_rx_queues);
 
+	netif_carrier_off(netdev);
 	err = register_netdev(netdev);
 
 	if (err) {
Signature · 1 line
1.7.11.7
#2 lore raw
In reply to Ben Hutchings
Quoted 34 lines · Ben Hutchings
Quoted 24 lines · Neil Horman

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Tested successfully by myself

CC "David S. Miller" <[email protected]>
CC "VMware, Inc." <[email protected]>

---

 drivers/net/vmxnet3/vmxnet3_drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/vmxnet3/vmxnet3_drv.c index b1c90f8..66c26a9 100644

drivers/net/vmxnet3/vmxnet3_drv.c +0 -0

[...]

Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0 -0
@@ -3067,6 +3065,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
 
 		goto err_register;
 
 	}
 
Quoted 7 lines

drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_probe_device(struct pci_dev *pdev, · line 3070

Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1 -0
+	netif_carrier_off(netdev);
 
drivers/net/vmxnet3/vmxnet3_drv.c +0 -0
 	vmxnet3_check_link(adapter, false);
 	return 0;

You should do this before calling register_netdev(), otherwise the link state change can race with vmxnet3_open().

Hmm, is it safe to do before the network device is registered? The rest of the drivers (e1000, tg3, etc) seem to be doing netif_carrier_off() in open() rather than probe() and then do link checks.

Thanks,
Dmitry

#3 lore raw
Quoted 43 lines · Dmitry Torokhov
Quoted 34 lines · Ben Hutchings
Quoted 24 lines · Neil Horman

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Tested successfully by myself

CC "David S. Miller" <[email protected]>
CC "VMware, Inc." <[email protected]>

---

 drivers/net/vmxnet3/vmxnet3_drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/vmxnet3/vmxnet3_drv.c index b1c90f8..66c26a9 100644

drivers/net/vmxnet3/vmxnet3_drv.c +0 -0

[...]

Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0 -0
@@ -3067,6 +3065,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
 
 		goto err_register;
 
 	}
 
Quoted 7 lines

drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_probe_device(struct pci_dev *pdev, · line 3070

Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1 -0
+	netif_carrier_off(netdev);
 
drivers/net/vmxnet3/vmxnet3_drv.c +0 -0
 	vmxnet3_check_link(adapter, false);
 	return 0;

You should do this before calling register_netdev(), otherwise the link state change can race with vmxnet3_open().

Quoted 4 lines

Hmm, is it safe to do before the network device is registered? The rest of the drivers (e1000, tg3, etc) seem to be doing netif_carrier_off() in open() rather than probe() and then do link checks.

It appears to be safe to me, at least for the netif_carrier_off case, as theres a check to effecitvely just set the NOCARRIER bit if the device is in UNREGISTERED state.
Neil

Quoted 4 lines

Thanks,
Dmitry

#4 lore raw
Quoted 44 lines · Neil Horman
Quoted 43 lines · Dmitry Torokhov
Quoted 41 lines · Ben Hutchings
Quoted 24 lines · Neil Horman

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Tested successfully by myself

CC "David S. Miller" <[email protected]>
CC "VMware, Inc." <[email protected]>

---

 drivers/net/vmxnet3/vmxnet3_drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/vmxnet3/vmxnet3_drv.c index b1c90f8..66c26a9 100644

drivers/net/vmxnet3/vmxnet3_drv.c +0 -0

[...]

drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_probe_device(struct pci_dev *pdev, · line 3070

Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1 -0
@@ -3067,6 +3065,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
 
 		goto err_register;
 
 	}
 
+	netif_carrier_off(netdev);
 
drivers/net/vmxnet3/vmxnet3_drv.c +0 -0
 	vmxnet3_check_link(adapter, false);
 	return 0;

You should do this before calling register_netdev(), otherwise the link state change can race with vmxnet3_open().

Quoted 7 lines
Quoted 4 lines

Hmm, is it safe to do before the network device is registered? The rest of the drivers (e1000, tg3, etc) seem to be doing netif_carrier_off() in open() rather than probe() and then do link checks.

It appears to be safe to me, at least for the netif_carrier_off case, as theres a check to effecitvely just set the NOCARRIER bit if the device is in UNREGISTERED state.

Right, I made this work properly a little while ago (commit 8f4cccbbd92f). Previous best practice was to call netif_carrier_off() after registration, but userland could still see the wrong operstate because linkwatch updates it asynchronously.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#5 lore raw
Quoted 56 lines · Ben Hutchings
Quoted 55 lines · Neil Horman
Quoted 53 lines · Dmitry Torokhov
Quoted 40 lines · Ben Hutchings
Quoted 30 lines · Neil Horman

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an
interface is opened the __LINK_STATE_NOCARRIER bit is already cleared,
and so /sys/class/net/<ifname>/operstate remains in the unknown state.
Correct this by setting netif_carrier_off on probe, like other drivers
do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the
link_state_update function, as that check is atomically contained within
the netif_carrier_[on|off] functions anyway

Tested successfully by myself

CC "David S. Miller" <[email protected]>
CC "VMware, Inc." <[email protected]>

---

 drivers/net/vmxnet3/vmxnet3_drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/vmxnet3/vmxnet3_drv.c index b1c90f8..66c26a9 100644

drivers/net/vmxnet3/vmxnet3_drv.c +0 -0

[...]

Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0 -0
@@ -3067,6 +3065,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
 
 		goto err_register;
 
 	}
 
Quoted 8 lines

drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_probe_device(struct pci_dev *pdev, · line 3070

Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1 -0
+	netif_carrier_off(netdev);
 
drivers/net/vmxnet3/vmxnet3_drv.c +0 -0
 	vmxnet3_check_link(adapter, false);
 	return 0;

You should do this before calling register_netdev(), otherwise the link
state change can race with vmxnet3_open().

Hmm, is it safe to do before the network device is registered? The rest of the drivers (e1000, tg3, etc) seem to be doing netif_carrier_off() in open() rather than probe() and then do link checks.

Quoted 8 lines
Quoted 3 lines

It appears to be safe to me, at least for the netif_carrier_off case, as theres a check to effecitvely just set the NOCARRIER bit if the device is in UNREGISTERED state.

Right, I made this work properly a little while ago (commit 8f4cccbbd92f). Previous best practice was to call netif_carrier_off() after registration, but userland could still see the wrong operstate because linkwatch updates it asynchronously.

Ah, OK I see. Thank you for the explanation.

Thanks,
Dmitry

Acked-by on v2 1/1
#7 lore raw
In reply to Neil Horman
Quoted 9 lines · Neil Horman

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Quoted 5 lines

Tested successfully by myself

CC "David S. Miller" <[email protected]>
CC "VMware, Inc." <[email protected]>
Quoted 43 lines
CC Ben Hutchings <[email protected]>

---
Change notes:

v2) Moved netif_carrier_off above register_netdev to prevent race with dev_open as per Ben H.

---
 drivers/net/vmxnet3/vmxnet3_drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/vmxnet3/vmxnet3_drv.c index b1c90f8..ffb97b2 100644

drivers/net/vmxnet3/vmxnet3_drv.c +0 -0
@@ -150,8 +150,7 @@ vmxnet3_check_link(struct vmxnet3_adapter *adapter, bool

affectTxQueue) if (ret & 1) { /* Link is up. */

drivers/net/vmxnet3/vmxnet3_drv.c +3 -4
 		netdev_info(adapter->netdev, "NIC Link is Up %d Mbps\n",
 			    adapter->link_speed);
-		if (!netif_carrier_ok(adapter->netdev))
-			netif_carrier_on(adapter->netdev);
+		netif_carrier_on(adapter->netdev);
 
 		if (affectTxQueue) {
 			for (i = 0; i < adapter->num_tx_queues; i++)
@@ -160,8 +159,7 @@ vmxnet3_check_link(struct vmxnet3_adapter *adapter, bool
 affectTxQueue) }
 	} else {
 		netdev_info(adapter->netdev, "NIC Link is Down\n");
-		if (netif_carrier_ok(adapter->netdev))
-			netif_carrier_off(adapter->netdev);
+		netif_carrier_off(adapter->netdev);
 
 		if (affectTxQueue) {
 			for (i = 0; i < adapter->num_tx_queues; i++)
@@ -3060,6 +3058,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
 	netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
 	netif_set_real_num_rx_queues(adapter->netdev, adapter->num_rx_queues);
 
+	netif_carrier_off(netdev);
 	err = register_netdev(netdev);
 
 	if (err) {
maintainer
#8 lore raw
In reply to Neil Horman

From: Neil Horman <[email protected]>
Date: Tue, 29 Jan 2013 13:36:51 -0500

Quoted 5 lines

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Quoted 7 lines

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Tested successfully by myself

This doesn't apply to the current 'net' tree. Please respin.

#9 lore raw
Quoted 12 lines · David Miller

From: Neil Horman <[email protected]>
Date: Tue, 29 Jan 2013 13:36:51 -0500

Quoted 9 lines

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Quoted 5 lines
Quoted 3 lines

Tested successfully by myself

This doesn't apply to the current 'net' tree. Please respin.

I based it off net-next. I'll respin for net
Neil

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

PATCH v3 1/1 vmxnet3: set carrier state properly on probe

In reply to David Miller

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Tested successfully by myself

CC "David S. Miller" <[email protected]>
CC "VMware, Inc." <[email protected]>
CC Ben Hutchings <[email protected]>

---
Change notes:

v2) Moved netif_carrier_off above register_netdev to prevent race with dev_open as per Ben H.

v3) Respin for net tree

---
 drivers/net/vmxnet3/vmxnet3_drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_drv.c +3 -4
index dc8913c..12c6440 100644
@@ -154,8 +154,7 @@ vmxnet3_check_link(struct vmxnet3_adapter *adapter, bool affectTxQueue)
 	if (ret & 1) { /* Link is up. */
 		printk(KERN_INFO "%s: NIC Link is Up %d Mbps\n",
 		       adapter->netdev->name, adapter->link_speed);
-		if (!netif_carrier_ok(adapter->netdev))
-			netif_carrier_on(adapter->netdev);
+		netif_carrier_on(adapter->netdev);
 
 		if (affectTxQueue) {
 			for (i = 0; i < adapter->num_tx_queues; i++)
@@ -165,8 +164,7 @@ vmxnet3_check_link(struct vmxnet3_adapter *adapter, bool affectTxQueue)
 	} else {
 		printk(KERN_INFO "%s: NIC Link is Down\n",
 		       adapter->netdev->name);
-		if (netif_carrier_ok(adapter->netdev))
-			netif_carrier_off(adapter->netdev);
+		netif_carrier_off(adapter->netdev);
 
 		if (affectTxQueue) {
 			for (i = 0; i < adapter->num_tx_queues; i++)
@@ -3061,6 +3059,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
 	netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
 	netif_set_real_num_rx_queues(adapter->netdev, adapter->num_rx_queues);
 
+	netif_carrier_off(netdev);
 	err = register_netdev(netdev);
 
 	if (err) {
Signature · 1 line
1.7.11.7
maintainer Applied
#11 lore raw

From: Neil Horman <[email protected]>
Date: Tue, 29 Jan 2013 16:15:45 -0500

Quoted 5 lines

vmxnet3 fails to set netif_carrier_off on probe, meaning that when an interface is opened the __LINK_STATE_NOCARRIER bit is already cleared, and so /sys/class/net/<ifname>/operstate remains in the unknown state. Correct this by setting netif_carrier_off on probe, like other drivers do.

Quoted 7 lines

Also, while we're at it, lets remove the netif_carrier_ok checks from the link_state_update function, as that check is atomically contained within the netif_carrier_[on|off] functions anyway

Tested successfully by myself

Applied, thanks Neil.