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 3/3] mlxsw: spectrum: Add rtnl_link_ops
Date: Fri, 15 Mar 2019 17:56:10 +0000	[thread overview]
Message-ID: <3d10297847b401cf4fba5342d3b191cebe256b64.1552672441.git.petrm@mellanox.com> (raw)
In-Reply-To: <cover.1552672441.git.petrm@mellanox.com>

In order to provide visibility into problems with bringing a link up,
add rtnl_link_ops. Add the mandatory kind field. Add two new functions,
mlxsw_sp_port_link_down_reason_get_size() to calculate the size
necessary for the link-down reason attributes, and
mlxsw_sp_port_fill_link_down_reason() to fetch and decode the link-down
reason from firmware, and dump to the RTNL message. Tie the functions
to, respectively, link_down_reason_get_size and fill_link_down_reason
hooks in rtnl_link_ops.

Signed-off-by: Petr Machata <petrm@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 108 +++++++++++++++++++++++++
 1 file changed, 108 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 9eb63300c1d3..b99b958da325 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -3207,6 +3207,113 @@ static const struct ethtool_ops mlxsw_sp_port_ethtool_ops = {
 	.get_module_eeprom	= mlxsw_sp_get_module_eeprom,
 };
 
+struct mlxsw_sp_ldr_opcode_mapping {
+	u16 status_opcode;
+	enum rtnl_link_down_reason_major major;
+};
+
+static const struct mlxsw_sp_ldr_opcode_mapping mlxsw_sp_ldr_opcode_map[] = {
+	{1024, RTNL_LDR_NO_CABLE},
+
+	{16, RTNL_LDR_UNSUPPORTED_CABLE},
+	{20, RTNL_LDR_UNSUPPORTED_CABLE},
+	{24, RTNL_LDR_UNSUPPORTED_CABLE},
+	{25, RTNL_LDR_UNSUPPORTED_CABLE},
+	{26, RTNL_LDR_UNSUPPORTED_CABLE},
+	{27, RTNL_LDR_UNSUPPORTED_CABLE},
+	{28, RTNL_LDR_UNSUPPORTED_CABLE},
+	{29, RTNL_LDR_UNSUPPORTED_CABLE},
+	{30, RTNL_LDR_UNSUPPORTED_CABLE},
+	{31, RTNL_LDR_UNSUPPORTED_CABLE},
+	{32, RTNL_LDR_UNSUPPORTED_CABLE},
+	{1025, RTNL_LDR_UNSUPPORTED_CABLE},
+	{1027, RTNL_LDR_UNSUPPORTED_CABLE},
+	{1029, RTNL_LDR_UNSUPPORTED_CABLE},
+
+	{2, RTNL_LDR_AUTONEG_FAILURE},
+	{3, RTNL_LDR_AUTONEG_FAILURE},
+	{4, RTNL_LDR_AUTONEG_FAILURE},
+	{38, RTNL_LDR_AUTONEG_FAILURE},
+	{39, RTNL_LDR_AUTONEG_FAILURE},
+
+	{36, RTNL_LDR_NO_LINK_PARTNER},
+
+	{5, RTNL_LDR_LINK_TRAINING_FAILURE},
+	{6, RTNL_LDR_LINK_TRAINING_FAILURE},
+	{7, RTNL_LDR_LINK_TRAINING_FAILURE},
+	{8, RTNL_LDR_LINK_TRAINING_FAILURE},
+
+	{9, RTNL_LDR_LOGICAL_MISMATCH},
+	{10, RTNL_LDR_LOGICAL_MISMATCH},
+	{11, RTNL_LDR_LOGICAL_MISMATCH},
+	{12, RTNL_LDR_LOGICAL_MISMATCH},
+	{13, RTNL_LDR_LOGICAL_MISMATCH},
+
+	{14, RTNL_LDR_REMOTE_FAULT},
+
+	{15, RTNL_LDR_BAD_SIGNAL_INTEGRITY},
+	{17, RTNL_LDR_BAD_SIGNAL_INTEGRITY},
+	{34, RTNL_LDR_BAD_SIGNAL_INTEGRITY},
+	{35, RTNL_LDR_BAD_SIGNAL_INTEGRITY},
+	{42, RTNL_LDR_BAD_SIGNAL_INTEGRITY},
+
+	{23, RTNL_LDR_CALIBRATION_FAILURE},
+
+	{1032, RTNL_LDR_POWER_BUDGET_EXCEEDED},
+};
+
+static size_t
+mlxsw_sp_port_link_down_reason_get_size(const struct net_device *dev)
+{
+	return nla_total_size(4) /* IFLA_LINK_DOWN_REASON_MAJOR */
+	     + nla_total_size(4) /* IFLA_LINK_DOWN_REASON_MINOR */
+	     + 0;
+}
+
+static int mlxsw_sp_port_fill_link_down_reason(struct sk_buff *skb,
+					       const struct net_device *dev)
+{
+	enum rtnl_link_down_reason_major major = RTNL_LDR_OTHER;
+	struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
+	char pddr_pl[MLXSW_REG_PDDR_LEN];
+	u16 status_opcode;
+	int i;
+	int err;
+
+	mlxsw_reg_pddr_pack(pddr_pl, mlxsw_sp_port->local_port,
+			    MLXSW_REG_PDDR_PAGESEL_TROUBLESHOOTING_INFO);
+	mlxsw_reg_pddr_trblsh_group_opcode_set(pddr_pl,
+				    MLXSW_REG_PDDR_TRBLSH_GROUP_MONITOR);
+
+	err = mlxsw_reg_query(mlxsw_sp_port->mlxsw_sp->core,
+			      MLXSW_REG(pddr), pddr_pl);
+	if (err)
+		return err;
+
+	status_opcode = mlxsw_reg_pddr_trblsh_status_opcode_get(pddr_pl);
+	if (!status_opcode)
+		return 0;
+
+	for (i = 0; i < ARRAY_SIZE(mlxsw_sp_ldr_opcode_map); ++i) {
+		if (mlxsw_sp_ldr_opcode_map[i].status_opcode == status_opcode) {
+			major = mlxsw_sp_ldr_opcode_map[i].major;
+			break;
+		}
+	}
+
+	if (nla_put_u32(skb, IFLA_LINK_DOWN_REASON_MAJOR, major) ||
+	    nla_put_u32(skb, IFLA_LINK_DOWN_REASON_MINOR, status_opcode))
+		return -EMSGSIZE;
+
+	return 0;
+}
+
+static const struct rtnl_link_ops mlxsw_sp_port_rtnl_link_ops = {
+	.kind			    = "mlxsw",
+	.link_down_reason_get_size  = mlxsw_sp_port_link_down_reason_get_size,
+	.fill_link_down_reason	    = mlxsw_sp_port_fill_link_down_reason,
+};
+
 static int
 mlxsw_sp_port_speed_by_width_set(struct mlxsw_sp_port *mlxsw_sp_port, u8 width)
 {
@@ -3436,6 +3543,7 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
 
 	dev->netdev_ops = &mlxsw_sp_port_netdev_ops;
 	dev->ethtool_ops = &mlxsw_sp_port_ethtool_ops;
+	dev->rtnl_link_ops = &mlxsw_sp_port_rtnl_link_ops;
 
 	err = mlxsw_sp_port_module_map(mlxsw_sp_port, module, width, lane);
 	if (err) {
-- 
2.4.11


  parent 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 ` [RFC PATCH net-next 1/3] net: rtnetlink: Add link-down reason to RTNL messages Petr Machata
2019-03-16  2:26   ` 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 ` Petr Machata [this message]
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=3d10297847b401cf4fba5342d3b191cebe256b64.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).