netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Machata <petrm@mellanox.com>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: Petr Machata <petrm@mellanox.com>, Jiri Pirko <jiri@mellanox.com>,
	Ido Schimmel <idosch@mellanox.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	Tariq Toukan <tariqt@mellanox.com>,
	"jakub.kicinski@netronome.com" <jakub.kicinski@netronome.com>,
	"andrew@lunn.ch" <andrew@lunn.ch>,
	"stephen@networkplumber.org" <stephen@networkplumber.org>
Subject: [RFC PATCH net-next 1/3] net: rtnetlink: Add link-down reason to RTNL messages
Date: Fri, 15 Mar 2019 17:56:07 +0000	[thread overview]
Message-ID: <3a247e91ebe81cdae4bae27ec1631c5015fb943f.1552672441.git.petrm@mellanox.com> (raw)
In-Reply-To: <cover.1552672441.git.petrm@mellanox.com>

In general, after a port is put administratively up, certain handshake
protocols have to finish successfully, otherwise the port is left in a
NO-CARRIER or DORMANT state. When that happens, it would be useful to
communicate the reasons to the administrator, so that the problem that
prevents the link from being established can be corrected.

Introduce two new link attributes: IFLA_LINK_DOWN_REASON_MAJOR and
_MINOR. Major reason code serve as broad categories intended to convey a
general idea of where the problem is. Minor codes are arbitrary numbers
specific for the driver that add detail to the major reasons. Add enum
rtnl_link_down_reason_major to define the well-known major reason codes.

The party with visibility into details of this process is the driver.
Therefore add two new RTNL hooks, link_down_reason_get_size and
fill_link_down_reason, to provide the necessary information.

Link-down reason is not included if the port is up or administratively
down, because those two state are easy to discover through existing
interfaces.

Signed-off-by: Petr Machata <petrm@mellanox.com>
---
 include/net/rtnetlink.h      |  3 +++
 include/uapi/linux/if_link.h | 16 ++++++++++++++++
 net/core/rtnetlink.c         | 22 ++++++++++++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index e2091bb2b3a8..cfd9e86ff0ca 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -110,6 +110,9 @@ struct rtnl_link_ops {
 	int			(*fill_linkxstats)(struct sk_buff *skb,
 						   const struct net_device *dev,
 						   int *prividx, int attr);
+	size_t			(*link_down_reason_get_size)(const struct net_device *dev);
+	int			(*fill_link_down_reason)(struct sk_buff *skb,
+							 const struct net_device *dev);
 };
 
 int __rtnl_link_register(struct rtnl_link_ops *ops);
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 5b225ff63b48..a47f42e79741 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -167,6 +167,8 @@ enum {
 	IFLA_NEW_IFINDEX,
 	IFLA_MIN_MTU,
 	IFLA_MAX_MTU,
+	IFLA_LINK_DOWN_REASON_MAJOR,  /* enum rtnl_link_down_reason_major */
+	IFLA_LINK_DOWN_REASON_MINOR,
 	__IFLA_MAX
 };
 
@@ -239,6 +241,20 @@ enum in6_addr_gen_mode {
 	IN6_ADDR_GEN_MODE_RANDOM,
 };
 
+enum rtnl_link_down_reason_major {
+	RTNL_LDR_OTHER,
+	RTNL_LDR_NO_CABLE,
+	RTNL_LDR_UNSUPPORTED_CABLE,
+	RTNL_LDR_AUTONEG_FAILURE,
+	RTNL_LDR_NO_LINK_PARTNER,
+	RTNL_LDR_LINK_TRAINING_FAILURE,
+	RTNL_LDR_LOGICAL_MISMATCH,
+	RTNL_LDR_REMOTE_FAULT,
+	RTNL_LDR_BAD_SIGNAL_INTEGRITY,
+	RTNL_LDR_CALIBRATION_FAILURE,
+	RTNL_LDR_POWER_BUDGET_EXCEEDED,
+};
+
 /* Bridge section */
 
 enum {
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index a51cab95ba64..206795f13850 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -979,6 +979,22 @@ static size_t rtnl_xdp_size(void)
 	return xdp_size;
 }
 
+static bool rtnl_should_fill_link_down_reason(const struct net_device *dev)
+{
+	return (dev->flags & IFF_UP) && !netif_oper_up(dev) &&
+		dev->rtnl_link_ops &&
+		dev->rtnl_link_ops->link_down_reason_get_size &&
+		dev->rtnl_link_ops->fill_link_down_reason;
+}
+
+static size_t rtnl_link_down_reason_get_size(const struct net_device *dev)
+{
+	if (!rtnl_should_fill_link_down_reason(dev))
+		return 0;
+
+	return dev->rtnl_link_ops->link_down_reason_get_size(dev);
+}
+
 static noinline size_t if_nlmsg_size(const struct net_device *dev,
 				     u32 ext_filter_mask)
 {
@@ -1026,6 +1042,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + nla_total_size(4)  /* IFLA_CARRIER_DOWN_COUNT */
 	       + nla_total_size(4)  /* IFLA_MIN_MTU */
 	       + nla_total_size(4)  /* IFLA_MAX_MTU */
+	       + rtnl_link_down_reason_get_size(dev)
 	       + 0;
 }
 
@@ -1683,6 +1700,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
 	    nla_put_s32(skb, IFLA_NEW_IFINDEX, new_ifindex) < 0)
 		goto nla_put_failure;
 
+	if (rtnl_should_fill_link_down_reason(dev) &&
+	    dev->rtnl_link_ops->fill_link_down_reason(skb, dev))
+		goto nla_put_failure;
 
 	rcu_read_lock();
 	if (rtnl_fill_link_af(skb, dev, ext_filter_mask))
@@ -1742,6 +1762,8 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
 	[IFLA_CARRIER_DOWN_COUNT] = { .type = NLA_U32 },
 	[IFLA_MIN_MTU]		= { .type = NLA_U32 },
 	[IFLA_MAX_MTU]		= { .type = NLA_U32 },
+	[IFLA_LINK_DOWN_REASON_MAJOR] = { .type = NLA_U32 },
+	[IFLA_LINK_DOWN_REASON_MINOR] = { .type = NLA_U32 },
 };
 
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
-- 
2.4.11


  reply	other threads:[~2019-03-15 17:56 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-15 17:56 [RFC PATCH net-next 0/3] RTNL: Add link-down reason reporting Petr Machata
2019-03-15 17:56 ` Petr Machata [this message]
2019-03-16  2:26   ` [RFC PATCH net-next 1/3] net: rtnetlink: Add link-down reason to RTNL messages Jakub Kicinski
2019-03-17  0:24     ` Michal Kubecek
2019-03-18 12:34     ` Petr Machata
2019-03-18 12:43       ` Michal Kubecek
2019-03-18 13:12       ` Andrew Lunn
2019-03-16  2:26   ` Andrew Lunn
2019-03-18 13:15     ` Petr Machata
2019-03-18 13:33       ` Andrew Lunn
2019-03-18 13:47         ` Petr Machata
2019-03-18 14:02       ` Andrew Lunn
2019-03-18 15:52         ` Stephen Hemminger
2019-03-19 10:18           ` Petr Machata
2019-03-19 11:56             ` Michal Kubecek
2019-03-19 15:42             ` Stephen Hemminger
2019-03-19 15:57               ` Petr Machata
2019-03-17 22:38   ` Roopa Prabhu
2019-03-18  0:03     ` Andrew Lunn
2019-03-28 17:59       ` Petr Machata
2019-03-28 19:51         ` Andrew Lunn
2019-04-23 13:41           ` Jiri Pirko
2019-03-18 12:15     ` Petr Machata
2019-03-15 17:56 ` [RFC PATCH net-next 2/3] mlxsw: reg: Add Port Diagnostics Database Register Petr Machata
2019-03-15 17:56 ` [RFC PATCH net-next 3/3] mlxsw: spectrum: Add rtnl_link_ops Petr Machata
2019-03-16  2:06 ` [RFC PATCH net-next 0/3] RTNL: Add link-down reason reporting Andrew Lunn
2019-03-18 12:11   ` Petr Machata

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3a247e91ebe81cdae4bae27ec1631c5015fb943f.1552672441.git.petrm@mellanox.com \
    --to=petrm@mellanox.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=idosch@mellanox.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=jiri@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    --cc=tariqt@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).