From patchwork Fri Mar 15 17:56:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 1057150 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="pHBOX1WN"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44LYDX4Wnwz9s47 for ; Sat, 16 Mar 2019 04:56:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726853AbfCOR4n (ORCPT ); Fri, 15 Mar 2019 13:56:43 -0400 Received: from mail-eopbgr70050.outbound.protection.outlook.com ([40.107.7.50]:62178 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726773AbfCOR4m (ORCPT ); Fri, 15 Mar 2019 13:56:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=slwxbMlMKKj4H7iNiLOuAD8A66zMJ7ynM/NoOSM71gw=; b=pHBOX1WNudr7qYvGqO3494sbZIT7sMvLGLCUnLalP5md/SUKknFPtRr3LQWnL1ZEBaeVWJ91n3yuUwwb+NJkt8e7vwFybR6d8pjT0YCUMV6lna41HsUll9JIWrxinAbylofnHlDYwxy9xUlfzrgjApdy7wuBVazmQl870GjRLpE= Received: from HE1PR05MB3243.eurprd05.prod.outlook.com (10.170.243.17) by HE1PR05MB4730.eurprd05.prod.outlook.com (20.176.164.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Fri, 15 Mar 2019 17:56:10 +0000 Received: from HE1PR05MB3243.eurprd05.prod.outlook.com ([fe80::9d92:b76c:69a:95ce]) by HE1PR05MB3243.eurprd05.prod.outlook.com ([fe80::9d92:b76c:69a:95ce%3]) with mapi id 15.20.1709.011; Fri, 15 Mar 2019 17:56:10 +0000 From: Petr Machata To: "netdev@vger.kernel.org" CC: Petr Machata , Jiri Pirko , Ido Schimmel , "davem@davemloft.net" , Tariq Toukan , "jakub.kicinski@netronome.com" , "andrew@lunn.ch" , "stephen@networkplumber.org" Subject: [RFC PATCH net-next 3/3] mlxsw: spectrum: Add rtnl_link_ops Thread-Topic: [RFC PATCH net-next 3/3] mlxsw: spectrum: Add rtnl_link_ops Thread-Index: AQHU21hfjVXkTbjf2kOSwojgtzooAA== Date: Fri, 15 Mar 2019 17:56:10 +0000 Message-ID: <3d10297847b401cf4fba5342d3b191cebe256b64.1552672441.git.petrm@mellanox.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.4.11 x-clientproxiedby: LO2P265CA0183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::27) To HE1PR05MB3243.eurprd05.prod.outlook.com (2603:10a6:7:35::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 84287ae6-bbe8-4b9a-87b2-08d6a96f81d1 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:HE1PR05MB4730; x-ms-traffictypediagnostic: HE1PR05MB4730: x-microsoft-antispam-prvs: x-forefront-prvs: 09778E995A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(376002)(136003)(39860400002)(366004)(346002)(199004)(189003)(186003)(50226002)(14454004)(8936002)(2351001)(3846002)(2616005)(316002)(81156014)(1730700003)(26005)(6116002)(106356001)(102836004)(66066001)(6916009)(105586002)(81166006)(52116002)(6506007)(8676002)(6436002)(446003)(68736007)(11346002)(6486002)(486006)(476003)(5640700003)(305945005)(5660300002)(53936002)(6512007)(76176011)(25786009)(2906002)(386003)(118296001)(7736002)(86362001)(54906003)(256004)(71200400001)(71190400001)(36756003)(14444005)(478600001)(2501003)(99286004)(4326008)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR05MB4730; H:HE1PR05MB3243.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: erq6Ob7OFfPbYH5Af7ZABKaOJxnCVEx+x1bl7x3uHRMWMORmgXSOJJozHn2AP4Wm2Ex1/EzlCRnEyBYVR/SnGZRC2loHA/Z1S4nClpJDbDGdTWEwL9aKHkbphJKKK4XIjD8NwIbzUHjG1hR1WJmr2ZG3zvDuVWMjTAxHqffGVlzqjkt0FPCHGVyWjkWo2ZxHLyQ1DZoQNabqv8LPgULvq55wgFXBkwcP39F7EFYZ6jEw6tCTD7nMyt5BEVx4I0pHZrv9RpqczMZP477tU2J4Sxrd/1dWbn/RbGdpbg+q5+RqwKsIVRl59yX2hXGD4rhu/uLeNYZJP84OVf0bKmnJJlm33e4bvbZaajzeV2tfPloUOSWKR9pq1kisbCIpyzxkeVs+th6mPpTfL2KgEHSCVpRo813OjCyzo5jJTorM4ec= MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84287ae6-bbe8-4b9a-87b2-08d6a96f81d1 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2019 17:56:10.7693 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR05MB4730 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- 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) {