Skip to contentSkip to conversation

Backport upstream NCSI fixes

PATCH In review Samuel Mendoza-Jonas 2 participants 9 messages Oct 23, 2017 – Oct 24, 2017

Subsystems (2)
lore
Share & tools
lore

Samuel Mendoza-Jonas

author maintainer
#0 lore raw

cover Backport upstream NCSI fixes

This backports a few useful NCSI fixes which are upstream, as well as replacing "net/ncsi: Don't assume last available channel exists" with the actual upstream version.

Gavin Shan (3):
net/ncsi: Disable HWA mode when no channels are found net/ncsi: Enforce failover on link monitor timeout net/ncsi: Fix length of GVI response packet

Samuel Mendoza-Jonas (4):
Revert "net/ncsi: Don't assume last available channel exists" net/ncsi: Don't limit vids based on hot_channel net/ncsi: Fix AEN HNCDSC packet length
net/ncsi: Stop monitor if channel times out or is inactive

 net/ncsi/internal.h    |  1 +
 net/ncsi/ncsi-aen.c    |  2 +-
 net/ncsi/ncsi-manage.c | 59 +++++++++++++++++++++++++++-----------------------
 net/ncsi/ncsi-rsp.c    |  2 +-
 4 files changed, 35 insertions(+), 29 deletions(-)
Signature · 1 line
2.14.2
author maintainer
#1 lore raw

PATCH 1/7 Revert "net/ncsi: Don't assume last available channel exists"

This reverts commit 7fd4e7d3b4fc52cdb965e2bbd9bbb3d57cb803fc.

---
 net/ncsi/ncsi-manage.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
net/ncsi/ncsi-manage.c +6 -15
index 75a97d48da8a..3cbd4328f142 100644
@@ -1407,10 +1407,7 @@ int ncsi_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
 	}
 
 	ndp = TO_NCSI_DEV_PRIV(nd);
-	if (!ndp) {
-		netdev_warn(dev, "ncsi: No ncsi_dev_priv?\n");
-		return 0;
-	}
+	ncf = ndp->hot_channel->filters[NCSI_FILTER_VLAN];
 
 	/* Add the VLAN id to our internal list */
 	list_for_each_entry_rcu(vlan, &ndp->vlan_vids, list) {
@@ -1422,17 +1419,11 @@ int ncsi_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
 		}
 	}
 
-	if (!ndp->hot_channel) {
-		netdev_warn(dev,
-			    "ncsi: no available filter to check maximum\n");
-	} else {
-		ncf = ndp->hot_channel->filters[NCSI_FILTER_VLAN];
-		if (n_vids >= ncf->total) {
-			netdev_info(dev,
-				    "NCSI Channel supports up to %u VLAN tags but %u are already set\n",
-				    ncf->total, n_vids);
-			return -EINVAL;
-		}
+	if (n_vids >= ncf->total) {
+		netdev_info(dev,
+			    "NCSI Channel supports up to %u VLAN tags but %u are already set\n",
+			    ncf->total, n_vids);
+		return -EINVAL;
 	}
 
 	vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
Signature · 1 line
2.14.2
author maintainer
#2 lore raw

PATCH 2/7 net/ncsi: Don't limit vids based on hot_channel

In reply to Samuel Mendoza-Jonas

Currently we drop any new VLAN ids if there are more than the current (or last used) channel can support. Most importantly this is a problem if no channel has been selected yet, resulting in a segfault.

Secondly this does not necessarily reflect the capabilities of any other channels. Instead only drop a new VLAN id if we are already tracking the maximum allowed by the NCSI specification. Per-channel limits are already handled by ncsi_add_filter(), but add a message to set_one_vid() to make it obvious that the channel can not support any more VLAN ids.

(cherry picked from commit 6e9c0075409d4ec1bc63558ee5a93916a6d7d16f)
---
 net/ncsi/internal.h    |  1 +
 net/ncsi/ncsi-manage.c | 17 +++++++++--------
 2 files changed, 10 insertions(+), 8 deletions(-)
net/ncsi/internal.h +1 -0
index af3d636534ef..d30f7bd741d0 100644
@@ -286,6 +286,7 @@ struct ncsi_dev_priv {
 	struct work_struct  work;            /* For channel management     */
 	struct packet_type  ptype;           /* NCSI packet Rx handler     */
 	struct list_head    node;            /* Form NCSI device list      */
+#define NCSI_MAX_VLAN_VIDS	15
 	struct list_head    vlan_vids;       /* List of active VLAN IDs */
 };
 
net/ncsi/ncsi-manage.c +9 -8
index 3cbd4328f142..24bf3f100d48 100644
@@ -717,6 +717,10 @@ static int set_one_vid(struct ncsi_dev_priv *ndp, struct ncsi_channel *nc,
 	if (index < 0) {
 		netdev_err(ndp->ndev.dev,
 			   "Failed to add new VLAN tag, error %d\n", index);
+		if (index == -ENOSPC)
+			netdev_err(ndp->ndev.dev,
+				   "Channel %u already has all VLAN filters set\n",
+				   nc->id);
 		return -1;
 	}
 
@@ -1390,7 +1394,6 @@ static int ncsi_kick_channels(struct ncsi_dev_priv *ndp)
 
 int ncsi_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
 {
-	struct ncsi_channel_filter *ncf;
 	struct ncsi_dev_priv *ndp;
 	unsigned int n_vids = 0;
 	struct vlan_vid *vlan;
@@ -1407,7 +1410,6 @@ int ncsi_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
 	}
 
 	ndp = TO_NCSI_DEV_PRIV(nd);
-	ncf = ndp->hot_channel->filters[NCSI_FILTER_VLAN];
 
 	/* Add the VLAN id to our internal list */
 	list_for_each_entry_rcu(vlan, &ndp->vlan_vids, list) {
@@ -1418,12 +1420,11 @@ int ncsi_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
 			return 0;
 		}
 	}
-
-	if (n_vids >= ncf->total) {
-		netdev_info(dev,
-			    "NCSI Channel supports up to %u VLAN tags but %u are already set\n",
-			    ncf->total, n_vids);
-		return -EINVAL;
+	if (n_vids >= NCSI_MAX_VLAN_VIDS) {
+		netdev_warn(dev,
+			    "tried to add vlan id %u but NCSI max already registered (%u)\n",
+			    vid, NCSI_MAX_VLAN_VIDS);
+		return -ENOSPC;
 	}
 
 	vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
Signature · 1 line
2.14.2
author maintainer
#3 lore raw

PATCH 3/7 net/ncsi: Fix AEN HNCDSC packet length

In reply to Samuel Mendoza-Jonas

Correct the value of the HNCDSC AEN packet.

Fixes 7a82ecf4cfb85 "net/ncsi: NCSI AEN packet handler"
(cherry picked from commit 6850d0f8b2542112629061808ed950b35eb982e4)
---
 net/ncsi/ncsi-aen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ncsi/ncsi-aen.c +1 -1
index 6898e7229285..f135938bf781 100644
@@ -187,7 +187,7 @@ static struct ncsi_aen_handler {
 } ncsi_aen_handlers[] = {
 	{ NCSI_PKT_AEN_LSC,    12, ncsi_aen_handler_lsc    },
 	{ NCSI_PKT_AEN_CR,      4, ncsi_aen_handler_cr     },
-	{ NCSI_PKT_AEN_HNCDSC,  4, ncsi_aen_handler_hncdsc }
+	{ NCSI_PKT_AEN_HNCDSC,  8, ncsi_aen_handler_hncdsc }
 };
 
 int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb)
Signature · 1 line
2.14.2
author maintainer
#4 lore raw

PATCH 4/7 net/ncsi: Stop monitor if channel times out or is inactive

In reply to Samuel Mendoza-Jonas

ncsi_channel_monitor() misses stopping the channel monitor in several places that it should, causing a WARN_ON_ONCE() to trigger when the monitor is re-started later, eg:

[  459.040000] WARNING: CPU: 0 PID: 1093 at net/ncsi/ncsi-manage.c:269 ncsi_start_channel_monitor+0x7c/0x90
[  459.040000] CPU: 0 PID: 1093 Comm: kworker/0:3 Not tainted 4.10.17-gaca2fdd #140
[  459.040000] Hardware name: ASpeed SoC
[  459.040000] Workqueue: events ncsi_dev_work
[  459.040000] [<80010094>] (unwind_backtrace) from [<8000d950>] (show_stack+0x20/0x24)
[  459.040000] [<8000d950>] (show_stack) from [<801dbf70>] (dump_stack+0x20/0x28)
[  459.040000] [<801dbf70>] (dump_stack) from [<80018d7c>] (__warn+0xe0/0x108)
[  459.040000] [<80018d7c>] (__warn) from [<80018e70>] (warn_slowpath_null+0x30/0x38)
[  459.040000] [<80018e70>] (warn_slowpath_null) from [<803f6a08>] (ncsi_start_channel_monitor+0x7c/0x90)
[  459.040000] [<803f6a08>] (ncsi_start_channel_monitor) from [<803f7664>] (ncsi_configure_channel+0xdc/0x5fc)
[  459.040000] [<803f7664>] (ncsi_configure_channel) from [<803f8160>] (ncsi_dev_work+0xac/0x474)
[  459.040000] [<803f8160>] (ncsi_dev_work) from [<8002d244>] (process_one_work+0x1e0/0x450)
[  459.040000] [<8002d244>] (process_one_work) from [<8002d510>] (worker_thread+0x5c/0x570)
[  459.040000] [<8002d510>] (worker_thread) from [<80033614>] (kthread+0x124/0x164)
[  459.040000] [<80033614>] (kthread) from [<8000a5e8>] (ret_from_fork+0x14/0x2c)

This also updates the monitor instead of just returning if ncsi_xmit_cmd() fails to send the get-link-status command so that the monitor properly times out.

Fixes e6f44ed6d04d3 "net/ncsi: Package and channel management"
(cherry picked from commit 0795fb2021f07969949f523ea33c39785bfae9d6)
---
 net/ncsi/ncsi-manage.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
net/ncsi/ncsi-manage.c +9 -6
index 24bf3f100d48..5bef2cb5a825 100644
@@ -199,11 +199,15 @@ static void ncsi_channel_monitor(unsigned long data)
 	monitor_state = nc->monitor.state;
 	spin_unlock_irqrestore(&nc->lock, flags);
 
-	if (!enabled || chained)
+	if (!enabled || chained) {
+		ncsi_stop_channel_monitor(nc);
 		return;
+	}
 	if (state != NCSI_CHANNEL_INACTIVE &&
-	    state != NCSI_CHANNEL_ACTIVE)
+	    state != NCSI_CHANNEL_ACTIVE) {
+		ncsi_stop_channel_monitor(nc);
 		return;
+	}
 
 	switch (monitor_state) {
 	case NCSI_CHANNEL_MONITOR_START:
@@ -214,12 +218,9 @@ static void ncsi_channel_monitor(unsigned long data)
 		nca.type = NCSI_PKT_CMD_GLS;
 		nca.req_flags = 0;
 		ret = ncsi_xmit_cmd(&nca);
-		if (ret) {
+		if (ret)
 			netdev_err(ndp->ndev.dev, "Error %d sending GLS\n",
 				   ret);
-			return;
-		}
-
 		break;
 	case NCSI_CHANNEL_MONITOR_WAIT ... NCSI_CHANNEL_MONITOR_WAIT_MAX:
 		break;
@@ -230,6 +231,8 @@ static void ncsi_channel_monitor(unsigned long data)
 			ndp->flags |= NCSI_DEV_RESHUFFLE;
 		}
 
+		ncsi_stop_channel_monitor(nc);
+
 		spin_lock_irqsave(&nc->lock, flags);
 		nc->state = NCSI_CHANNEL_INVISIBLE;
 		spin_unlock_irqrestore(&nc->lock, flags);
Signature · 1 line
2.14.2
author maintainer
#5 lore raw

PATCH 5/7 net/ncsi: Disable HWA mode when no channels are found

In reply to Samuel Mendoza-Jonas

From: Gavin Shan <[email protected]>

When there are no NCSI channels probed, HWA (Hardware Arbitration) mode is enabled. It's not correct because HWA depends on the fact:
NCSI channels exist and all of them support HWA mode. This disables HWA when no channels are probed.

(cherry picked from commit 100ef01f3ea4badbee6479290a41f74abd0e523f)
---
 net/ncsi/ncsi-manage.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
net/ncsi/ncsi-manage.c +10 -2
index 5bef2cb5a825..8a589e611225 100644
@@ -991,12 +991,15 @@ static bool ncsi_check_hwa(struct ncsi_dev_priv *ndp)
 	struct ncsi_package *np;
 	struct ncsi_channel *nc;
 	unsigned int cap;
+	bool has_channel = false;
 
 	/* The hardware arbitration is disabled if any one channel
 	 * doesn't support explicitly.
 	 */
 	NCSI_FOR_EACH_PACKAGE(ndp, np) {
 		NCSI_FOR_EACH_CHANNEL(np, nc) {
+			has_channel = true;
+
 			cap = nc->caps[NCSI_CAP_GENERIC].cap;
 			if (!(cap & NCSI_CAP_GENERIC_HWA) ||
 			    (cap & NCSI_CAP_GENERIC_HWA_MASK) !=
@@ -1007,8 +1010,13 @@ static bool ncsi_check_hwa(struct ncsi_dev_priv *ndp)
 		}
 	}
 
-	ndp->flags |= NCSI_DEV_HWA;
-	return true;
+	if (has_channel) {
+		ndp->flags |= NCSI_DEV_HWA;
+		return true;
+	}
+
+	ndp->flags &= ~NCSI_DEV_HWA;
+	return false;
 }
 
 static int ncsi_enable_hwa(struct ncsi_dev_priv *ndp)
Signature · 1 line
2.14.2
author maintainer
#6 lore raw

PATCH 6/7 net/ncsi: Enforce failover on link monitor timeout

In reply to Samuel Mendoza-Jonas

From: Gavin Shan <[email protected]>

The NCSI channel has been configured to provide service if its link monitor timer is enabled, regardless of its state (inactive or active). So the timeout event on the link monitor indicates the out-of-service on that channel, for which a failover is needed.

This sets NCSI_DEV_RESHUFFLE flag to enforce failover on link monitor timeout, regardless the channel's original state (inactive or active). Also, the link is put into "down" state to give the failing channel lowest priority when selecting for the active channel. The state of failing channel should be set to active in order for deinitialization and failover to be done.

(cherry picked from commit 52b4c8627f9f0d882e969967a207a27a80c9c753)
---
 net/ncsi/ncsi-manage.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/ncsi/ncsi-manage.c +5 -3
index 8a589e611225..8cae2f233272 100644
@@ -186,6 +186,7 @@ static void ncsi_channel_monitor(unsigned long data)
 	struct ncsi_channel *nc = (struct ncsi_channel *)data;
 	struct ncsi_package *np = nc->package;
 	struct ncsi_dev_priv *ndp = np->ndp;
+	struct ncsi_channel_mode *ncm;
 	struct ncsi_cmd_arg nca;
 	bool enabled, chained;
 	unsigned int monitor_state;
@@ -225,20 +226,21 @@ static void ncsi_channel_monitor(unsigned long data)
 	case NCSI_CHANNEL_MONITOR_WAIT ... NCSI_CHANNEL_MONITOR_WAIT_MAX:
 		break;
 	default:
-		if (!(ndp->flags & NCSI_DEV_HWA) &&
-		    state == NCSI_CHANNEL_ACTIVE) {
+		if (!(ndp->flags & NCSI_DEV_HWA)) {
 			ncsi_report_link(ndp, true);
 			ndp->flags |= NCSI_DEV_RESHUFFLE;
 		}
 
 		ncsi_stop_channel_monitor(nc);
 
+		ncm = &nc->modes[NCSI_MODE_LINK];
 		spin_lock_irqsave(&nc->lock, flags);
 		nc->state = NCSI_CHANNEL_INVISIBLE;
+		ncm->data[2] &= ~0x1;
 		spin_unlock_irqrestore(&nc->lock, flags);
 
 		spin_lock_irqsave(&ndp->lock, flags);
-		nc->state = NCSI_CHANNEL_INACTIVE;
+		nc->state = NCSI_CHANNEL_ACTIVE;
 		list_add_tail_rcu(&nc->link, &ndp->channel_queue);
 		spin_unlock_irqrestore(&ndp->lock, flags);
 		ncsi_process_next_channel(ndp);
Signature · 1 line
2.14.2
author maintainer
#7 lore raw

PATCH 7/7 net/ncsi: Fix length of GVI response packet

In reply to Samuel Mendoza-Jonas

From: Gavin Shan <[email protected]>

The length of GVI (GetVersionInfo) response packet should be 40 instead of 36. This issue was found from /sys/kernel/debug/ncsi/eth0/stats.

 # ethtool --ncsi eth0 swstats
     :
 RESPONSE     OK       TIMEOUT  ERROR
 =======================================
 GVI          0        0        2

With this applied, no error reported on GVI response packets:

 # ethtool --ncsi eth0 swstats
     :
 RESPONSE     OK       TIMEOUT  ERROR
 =======================================
 GVI          2        0        0
(cherry picked from commit 0a90e251988ceedc528c8db98f25b051cf190f44)
---
 net/ncsi/ncsi-rsp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ncsi/ncsi-rsp.c +1 -1
index 265b9a892d41..927dad4759d1 100644
@@ -959,7 +959,7 @@ static struct ncsi_rsp_handler {
 	{ NCSI_PKT_RSP_EGMF,    4, ncsi_rsp_handler_egmf    },
 	{ NCSI_PKT_RSP_DGMF,    4, ncsi_rsp_handler_dgmf    },
 	{ NCSI_PKT_RSP_SNFC,    4, ncsi_rsp_handler_snfc    },
-	{ NCSI_PKT_RSP_GVI,    36, ncsi_rsp_handler_gvi     },
+	{ NCSI_PKT_RSP_GVI,    40, ncsi_rsp_handler_gvi     },
 	{ NCSI_PKT_RSP_GC,     32, ncsi_rsp_handler_gc      },
 	{ NCSI_PKT_RSP_GP,     -1, ncsi_rsp_handler_gp      },
 	{ NCSI_PKT_RSP_GCPS,  172, ncsi_rsp_handler_gcps    },
Signature · 1 line
2.14.2
#8 lore raw
In reply to Samuel Mendoza-Jonas
Quoted 11 lines · Samuel Mendoza-Jonas

This backports a few useful NCSI fixes which are upstream, as well as replacing
"net/ncsi: Don't assume last available channel exists" with the actual upstream
version.

Gavin Shan (3):
  net/ncsi: Disable HWA mode when no channels are found net/ncsi: Enforce failover on link monitor timeout net/ncsi: Fix length of GVI response packet

Quoted 5 lines

Samuel Mendoza-Jonas (4):
  Revert "net/ncsi: Don't assume last available channel exists" net/ncsi: Don't limit vids based on hot_channel net/ncsi: Fix AEN HNCDSC packet length
  net/ncsi: Stop monitor if channel times out or is inactive

Series applied to dev-4.10.

Cheers,

Andrew

Quoted 8 lines

 net/ncsi/internal.h    |  1 +
 net/ncsi/ncsi-aen.c    |  2 +-
 net/ncsi/ncsi-manage.c | 59 +++++++++++++++++++++++++++-------------
----------
 net/ncsi/ncsi-rsp.c    |  2 +-

 4 files changed, 35 insertions(+), 29 deletions(-)