From patchwork Thu Aug 25 14:12:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12954756 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29829C28D13 for ; Thu, 25 Aug 2022 14:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242014AbiHYONr (ORCPT ); Thu, 25 Aug 2022 10:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241523AbiHYONZ (ORCPT ); Thu, 25 Aug 2022 10:13:25 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2124.outbound.protection.outlook.com [40.107.220.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C7FCB6D3A for ; Thu, 25 Aug 2022 07:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g1jRXfV3xmjAmcMnZQxzy9vycy9Mf9kauU0ULc8KpEiokcj0QcThqodD9z0hjGr13iuIP3ujdLBKLIY6T09zC9YzutWeSRy/lSsPimadXyAPdyAzSoXlIKioXj0LLIU0uvqxemIg2Yny4UAXc0vWp+aZC0FttrHgBdQqctEah4KOviGIiN90Jr8sg457qPnJxbkA14EXPglP6DWVNXxTRCE8bqn40rEgRaAmT4aiwWk8EcG3lmeSDcnPZ0du+OCF57x/KkbuNASAuaNaZ4MaEosPiA/3CO0xpA3xGO67DumsyanKHaJEVsh6w86Kb+1VhLxqEb/qOa8OcXr+SQ1yjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2CmaqTHBucCBPimMPzHw6oHDsEbtWOerT0u0N9eU1l4=; b=YbBR+IuKgBedC80ExH3nFA+aRlfaLO8CGzDLf8JjKqNWFNbqCrxDqSbmpiUcB6itWDymgicNYPtB/HlvJQORXvbfr4nezwgMEgF6KEeMvvlpw6tnfv3ZQcjGiEdqMN9UB6qZI2eQC9atMsg76Vew4ZuBtYGim6n2iM1AnQfDnUZ9tcE4dVwmeqqON03loNlRVHFnxembwdGJkXOEhEqDpK+g/NlmdL72jleXgrJ2AM8YMzacYV37LmkFFryd06JCrDF3bgR9yIvbnOLObxzD/jbwuXn8VCHIADd5UsX3M58+5kR4UmFZIeoujS+JyreRo3apiWKNrIDpQYcYkt7+Ug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2CmaqTHBucCBPimMPzHw6oHDsEbtWOerT0u0N9eU1l4=; b=EQvshdQqId4IxuHgDQdNoOO4+mHMomKt5mq61aw7AV/jAqqKEqiwoXpZHf3hqyXT3D7ha2BMKhg6iQH6HKwo0pHxIktkFIbTH8582OeDFcl4KOXMEQ9JO52IaGPoi86wzJHptwV+7m3t0I2cHy7pJoVNGSj1vYg35HdRc1n/Xzc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by SJ0PR13MB5401.namprd13.prod.outlook.com (2603:10b6:a03:424::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.14; Thu, 25 Aug 2022 14:12:41 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576%8]) with mapi id 15.20.5566.014; Thu, 25 Aug 2022 14:12:41 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, oss-drivers@corigine.com Subject: [PATCH net-next 1/3] nfp: propagate port speed from management firmware Date: Thu, 25 Aug 2022 16:12:21 +0200 Message-Id: <20220825141223.22346-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220825141223.22346-1-simon.horman@corigine.com> References: <20220825141223.22346-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR01CA0078.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::19) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a3e89e4f-3c95-4cc7-f6df-08da86a3df36 X-MS-TrafficTypeDiagnostic: SJ0PR13MB5401:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kwX5tAIVkJ54wXvMX0xx/OIZTkS+wejHrmpEM+KZE9CWAwFiFKqSMtQA043KiEiURbxcC2XYv8wi/5YWh1JXEB+PLgrdrcU0HDUikAqKkilYouqNiD+OjrHzAlZfEHy4TGldjThaLH9VbWzPkjzZf+LPfszIT1s/18gAvGfE8HS+AmEeL42RkV8Crw9vRXAr2wvFSx50sRjUxTFJaYO5VNCYW+YW9Qdjc2IkRupAWjoKoTqZ67W1rpj0O+mjscaXyeDDDie5KA3OpRcMmcD8GJ1WnyMNXlJXgN8uRQHSOYydukDUVVKqVsx2JMbVoFmHWGvrRKscsRRkep/PCMWDUt+4W96t7BiLxoKEJlOO2cfFEUaiFefnRyvE3BLnKMSK6UZgLF9Bpszuj6cLOE1KRvUtl6Sw3pRBbieMQXVYhJQUc4ZB5EKI2Ur9+nM21T1iOn4txasDMOG/vOoQ3EZwfqx2zNZu48GR5Mvyu4M2gWjLq2VWJB0X6Q4GtNLIw6xdy7ZpWvMmFzcC++G1yu7LPj60znGCiGo/NundtigabnD+LYg0nxhYxAjoFxx5Y7P/N2uCEJ4wFsYY2uSfgLdajLpXa7Kj2u4cHnFtmUupnMGUtOeA8JnEyJrm5TA7lZAMBErp26zLzk0RgTnf6rvmD2NRGw2nkksS93ShAZ5NwbJwRXVN+ls7wlsdTMKjsTofwo3KlTWcYym1XtlKbpBKRA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(376002)(396003)(366004)(136003)(346002)(39840400004)(86362001)(83380400001)(38100700002)(8936002)(4326008)(66946007)(6486002)(478600001)(8676002)(66476007)(66556008)(52116002)(110136005)(316002)(44832011)(6666004)(1076003)(2906002)(6512007)(36756003)(5660300002)(107886003)(186003)(41300700001)(6506007)(2616005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ERtrXMMpVbQEx21/q6tcmZw67a+A62hsMPMckYV44EGH9fBDy705DET3QvqCo30WfhF2mgjW7p273d22FbY1VrIy54riWVaCJZ5b89oGX0Bx2FTmGLYDEGyjIi2WJ+jqwvc+ZLYMDIZkNy1HUxpaxOR/9tMsYjY3YeFkXbb7o4JoUo6iBDwc4tinCrzFFASSFc6Q7ppF8DgEZtBrbKNApg8R3J2qcHOmk5mHTcD7PgsIVhsokRGbTqwRgNsUJnngv8iMyUqQGNOvUmaJk4fxfUjds2pgPjQdFqfRjaR0ifE6olmeMjhrX9cmFNnEUU47ecnAYBtQ3CugAC41vjkG8i3MqVdItuOKT+W9sV67u2lRaXWUijrZEcxvx+EAaKYXUPRvsK8VxTYpq3IAfM4SIre2adkiuMbDXHHp/dSIO+arLqnLFpk9nDGUE7TERYD4pYJW1aoONYl3gfWiY2nRxKFesdtHbAbbeDdKd6xrDvBbqUHlg4m+kAZ+i45cvpkHAUjfSleiz5/MvapfNNG0ie9lXf4yEMevH9XVaOg/SSnvBurViQRd4QICHvCKRQOnClnlX8fxEpsbzQBxPDd0WlOezzEfPd0yQanF5R3Lrm4feZ0XuhPL2PVzhQUrpFt0KekHPkNKWVXgfOefts5biLp2XondFjd2szUXbHZmf2VlbMPDBXrGK6omLYKrP9oj5EN2agHUy7JAXXVQEvDEYR7x8AkRaDBbkuyg+O5Ituy3zdErgZIvzshkhsvElxzagKhVEV/FV5SjKRxx4BwBDD9Yar8Iwb+UFgS4wrnnXzwJHjwA5jG9MwDfObDOOw1xAPPVMzEw44/3gRbXq+eQ9GNm/P0MtVr2l7o5DZ2Bg9zHWXfK2u/mC3pFI9UAyiUut3+tBkKp5CPQDvYCL9CnKIo9pMKQpdgGLNp1D/bKbTogCpVWGH69Ecl/ymwDtONoDPlFbCwCnZwgs2iiLFArvjXIWVgXtrUERgSN2tivKjyJgxSpAp1X8k8ea+cH6c6EnWwAN0Nj3Mv/7ChwoWyHd1+II9nnICJnrGFwg17xwiKj5iJnfU1Mr5q0xj1HcRzPkZbewhGZJxxR6UOSfQbfwXEJaIGqQx2cHj3P3yU7Zy5Amje7mu013GPmpsKFVyde3AWBbRk/kui7HvIfSC0OcRojTbZdnO2+ZMsH3Be/iLsUvUiD/BTcxjMnKATjtSmuOPucC/yfb6q/4Fe7SL9WtOhCu/3V5Lv+PpaGr03r1qJKNr0WnABbr0zndV3KFObS2zv/XELeuOY3P0oBRhGHRfwKoun52H7Ff0EQqJcOjpIjyvn8BcX89eTMVk2vIU0kCEsrA9HEgdqUDPirGCr04tGCFFNegQ0WOeYuC14fSjvWrTANlpbkoC/W0i8khkrWrjlzUyXC1owENNz6M1eqfGop8dh5uDuVLYjIJ5/oeHm3G1aZNFtJDWNtC/5VrD+aXkErQCIPw77NOHUx/0p5V1VQBoFjPdTHTi2pNN0UC4uKu4X9xdnDvMBn4pU5KU0W8gy5zvRO0FCman3sEg5Szo3faMSUnitWzeu6G/x0kxkUBweZZcQDCcFqIHT+VZ6cI1j8gJxQMGUXt+E9y4dtD8sUnX3f4rXNih/Tr851jnDPhaniYAXeeDOUk6AJM0IvwDrsdrQXukNj6DXmjBbeaQ== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3e89e4f-3c95-4cc7-f6df-08da86a3df36 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2022 14:12:41.0946 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JkCEsnumOu7dL9LrbRt2IzAGwiyd3e/BjOV6zAmmj2+ynkI81C9+SzCH3KVyrbwCXWAtMf41EXvyqdJ2epC23DmvmxplQtftPPXwOxdrFHg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR13MB5401 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Yinjun Zhang In future releases the NIC application firmware may be indifferent to port speeds - not built for specific port speeds - and consequently it will not be able to report VF port speeds to the driver without first learning them. With this change, the driver will pass the speed of physical ports from management firmware to application firmware, and the latter will copy the speed of port 0 to all the active VFs. So that the driver can get VF port speed as before. The port speed of a VF may be requested from userspace using: ethtool Signed-off-by: Yinjun Zhang Reviewed-by: Louis Peens Signed-off-by: Simon Horman --- drivers/net/ethernet/netronome/nfp/nfp_main.h | 3 + .../ethernet/netronome/nfp/nfp_net_common.c | 9 ++- .../net/ethernet/netronome/nfp/nfp_net_ctrl.h | 4 ++ .../ethernet/netronome/nfp/nfp_net_ethtool.c | 30 +++------- .../net/ethernet/netronome/nfp/nfp_net_main.c | 55 +++++++++++++++++++ drivers/net/ethernet/netronome/nfp/nfp_port.h | 2 + 6 files changed, 79 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_main.h b/drivers/net/ethernet/netronome/nfp/nfp_main.h index f56ca11de134..be3746cbc58b 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_main.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_main.h @@ -190,4 +190,7 @@ int nfp_shared_buf_pool_set(struct nfp_pf *pf, unsigned int sb, int nfp_devlink_params_register(struct nfp_pf *pf); void nfp_devlink_params_unregister(struct nfp_pf *pf); + +unsigned int nfp_net_lr2speed(unsigned int linkrate); +unsigned int nfp_net_speed2lr(unsigned int speed); #endif /* NFP_MAIN_H */ diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index cf4d6f1129fa..fda3e77f28d2 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -474,19 +474,22 @@ static void nfp_net_read_link_status(struct nfp_net *nn) { unsigned long flags; bool link_up; - u32 sts; + u16 sts; spin_lock_irqsave(&nn->link_status_lock, flags); - sts = nn_readl(nn, NFP_NET_CFG_STS); + sts = nn_readw(nn, NFP_NET_CFG_STS); link_up = !!(sts & NFP_NET_CFG_STS_LINK); if (nn->link_up == link_up) goto out; nn->link_up = link_up; - if (nn->port) + if (nn->port) { set_bit(NFP_PORT_CHANGED, &nn->port->flags); + if (nn->port->link_cb) + nn->port->link_cb(nn->port); + } if (nn->link_up) { netif_carrier_on(nn->dp.netdev); diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h index ac05ec34d69e..91708527a47c 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h @@ -193,6 +193,10 @@ #define NFP_NET_CFG_STS_LINK_RATE_40G 5 #define NFP_NET_CFG_STS_LINK_RATE_50G 6 #define NFP_NET_CFG_STS_LINK_RATE_100G 7 +/* NSP Link rate is a 16-bit word. It's determined by NSP and + * written to CFG BAR by NFP driver. + */ +#define NFP_NET_CFG_STS_NSP_LINK_RATE 0x0036 #define NFP_NET_CFG_CAP 0x0038 #define NFP_NET_CFG_MAX_TXRINGS 0x003c #define NFP_NET_CFG_MAX_RXRINGS 0x0040 diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c index eeb1455a4e5d..cd2e67185e8c 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c @@ -273,20 +273,11 @@ static int nfp_net_get_link_ksettings(struct net_device *netdev, struct ethtool_link_ksettings *cmd) { - static const u32 ls_to_ethtool[] = { - [NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED] = 0, - [NFP_NET_CFG_STS_LINK_RATE_UNKNOWN] = SPEED_UNKNOWN, - [NFP_NET_CFG_STS_LINK_RATE_1G] = SPEED_1000, - [NFP_NET_CFG_STS_LINK_RATE_10G] = SPEED_10000, - [NFP_NET_CFG_STS_LINK_RATE_25G] = SPEED_25000, - [NFP_NET_CFG_STS_LINK_RATE_40G] = SPEED_40000, - [NFP_NET_CFG_STS_LINK_RATE_50G] = SPEED_50000, - [NFP_NET_CFG_STS_LINK_RATE_100G] = SPEED_100000, - }; struct nfp_eth_table_port *eth_port; struct nfp_port *port; struct nfp_net *nn; - u32 sts, ls; + unsigned int speed; + u16 sts; /* Init to unknowns */ ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE); @@ -319,18 +310,15 @@ nfp_net_get_link_ksettings(struct net_device *netdev, return -EOPNOTSUPP; nn = netdev_priv(netdev); - sts = nn_readl(nn, NFP_NET_CFG_STS); - - ls = FIELD_GET(NFP_NET_CFG_STS_LINK_RATE, sts); - if (ls == NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED) + sts = nn_readw(nn, NFP_NET_CFG_STS); + speed = nfp_net_lr2speed(FIELD_GET(NFP_NET_CFG_STS_LINK_RATE, sts)); + if (!speed) return -EOPNOTSUPP; - if (ls == NFP_NET_CFG_STS_LINK_RATE_UNKNOWN || - ls >= ARRAY_SIZE(ls_to_ethtool)) - return 0; - - cmd->base.speed = ls_to_ethtool[ls]; - cmd->base.duplex = DUPLEX_FULL; + if (speed != SPEED_UNKNOWN) { + cmd->base.speed = speed; + cmd->base.duplex = DUPLEX_FULL; + } return 0; } diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c index ca4e05650fe6..dd668520851e 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c @@ -202,6 +202,9 @@ nfp_net_pf_alloc_vnics(struct nfp_pf *pf, void __iomem *ctrl_bar, goto err_free_prev; } + if (nn->port) + nn->port->link_cb = nfp_net_refresh_port_table; + ctrl_bar += NFP_PF_CSR_SLICE_SIZE; /* Kill the vNIC if app init marked it as invalid */ @@ -523,6 +526,57 @@ static int nfp_net_pci_map_mem(struct nfp_pf *pf) return err; } +static const unsigned int lr_to_speed[] = { + [NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED] = 0, + [NFP_NET_CFG_STS_LINK_RATE_UNKNOWN] = SPEED_UNKNOWN, + [NFP_NET_CFG_STS_LINK_RATE_1G] = SPEED_1000, + [NFP_NET_CFG_STS_LINK_RATE_10G] = SPEED_10000, + [NFP_NET_CFG_STS_LINK_RATE_25G] = SPEED_25000, + [NFP_NET_CFG_STS_LINK_RATE_40G] = SPEED_40000, + [NFP_NET_CFG_STS_LINK_RATE_50G] = SPEED_50000, + [NFP_NET_CFG_STS_LINK_RATE_100G] = SPEED_100000, +}; + +unsigned int nfp_net_lr2speed(unsigned int linkrate) +{ + if (linkrate < ARRAY_SIZE(lr_to_speed)) + return lr_to_speed[linkrate]; + + return SPEED_UNKNOWN; +} + +unsigned int nfp_net_speed2lr(unsigned int speed) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(lr_to_speed); i++) { + if (speed == lr_to_speed[i]) + return i; + } + + return NFP_NET_CFG_STS_LINK_RATE_UNKNOWN; +} + +static void nfp_net_notify_port_speed(struct nfp_port *port) +{ + struct net_device *netdev = port->netdev; + struct nfp_net *nn; + u16 sts; + + if (!nfp_netdev_is_nfp_net(netdev)) + return; + + nn = netdev_priv(netdev); + sts = nn_readw(nn, NFP_NET_CFG_STS); + + if (!(sts & NFP_NET_CFG_STS_LINK)) { + nn_writew(nn, NFP_NET_CFG_STS_NSP_LINK_RATE, NFP_NET_CFG_STS_LINK_RATE_UNKNOWN); + return; + } + + nn_writew(nn, NFP_NET_CFG_STS_NSP_LINK_RATE, nfp_net_speed2lr(port->eth_port->speed)); +} + static int nfp_net_eth_port_update(struct nfp_cpp *cpp, struct nfp_port *port, struct nfp_eth_table *eth_table) @@ -544,6 +598,7 @@ nfp_net_eth_port_update(struct nfp_cpp *cpp, struct nfp_port *port, } memcpy(port->eth_port, eth_port, sizeof(*eth_port)); + nfp_net_notify_port_speed(port); return 0; } diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.h b/drivers/net/ethernet/netronome/nfp/nfp_port.h index d1ebe6c72f7f..6793cdf9ff11 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_port.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_port.h @@ -46,6 +46,7 @@ enum nfp_port_flags { * @tc_offload_cnt: number of active TC offloads, how offloads are counted * is not defined, use as a boolean * @app: backpointer to the app structure + * @link_cb: callback when link status changed * @dl_port: devlink port structure * @eth_id: for %NFP_PORT_PHYS_PORT port ID in NFP enumeration scheme * @eth_forced: for %NFP_PORT_PHYS_PORT port is forced UP or DOWN, don't change @@ -66,6 +67,7 @@ struct nfp_port { unsigned long tc_offload_cnt; struct nfp_app *app; + void (*link_cb)(struct nfp_port *port); struct devlink_port dl_port; From patchwork Thu Aug 25 14:12:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12954757 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E7F6C64990 for ; Thu, 25 Aug 2022 14:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241864AbiHYOOA (ORCPT ); Thu, 25 Aug 2022 10:14:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241229AbiHYONg (ORCPT ); Thu, 25 Aug 2022 10:13:36 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2124.outbound.protection.outlook.com [40.107.220.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 428EC9E0DC for ; Thu, 25 Aug 2022 07:13:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fvy6B3kjcXdY5M+qScXNVBmXP+dJ4siUgTmorhZRnZn6Sclknuj8Grswemeg60B/1UGfgH/dU0gaqMxgOLDDlrowLlLrPYc8VR6MBarsbPGQJ1Z0p7KDRwey3/k9Tux01I/rI7iRSIO9lxDDTTQnQTfeqkyQd/rk0vEMesKz+zIlSxgGkQTxSxELK/UOvcg5/p2ScACLhytKM0VtybVckFZb7VyppwhZXRao/grKFbLRj9oYoXusA1bBZbRKfj1+Jae0P/PPvbEnFpiNY8VlmdJcZNHeBzhBauwv5+vQx6r/kTSEYymgPL+53hsX4t0zLNJLEfTx6P0i5ebHmEC4rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RuKu7PlIdgF+NWM62Xe6i+zMocafsAB4slMA52+BU+U=; b=CX1/YlsmCQQSt7671+4C2olELuT6xtBY/fscjoB0b/UJ92W5kTN3OjHh4tmx8Q6f8DTH+UPeSUZCUnxtx2mXOhdZftMyIk7DWrZEQAjj/fnyRHCZCsRqNz4iHaczpbyd0wlbvopprsd/urDSP6MjgT9Z9Qqd4trwOgHwaJsaUhNKKMPsjIDIEJ1LiV6jDO8T1c3XXFIZJ9YfdglIrp48tPNixa+8m/OFfT2j6Z0Yof9gqERO0aF5R6zvbNw8NVI1UKfP1dTsUieWm2oCOVAaJuOy/g8Uv7I+vxIOHI13hPERzxzHYNczqaiTSe6dK4mLzwv6cLtRF4NmqWQJORylpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RuKu7PlIdgF+NWM62Xe6i+zMocafsAB4slMA52+BU+U=; b=D49wKqcAbyFPUN2haMRq+vH1ACpPnOu8Y9qbGDlmrYwH++qbkVHapX3CRTOVcweO4NEz35wASZkOo1bZZd2W0zVTFjs6ljW2q7MWo1pNS3wQHvBQ6gLkZxc2SV6t8z0uzcmoZ2jOMo2kXt7guxt/DtOCgTLOGT9pEbLLrBHXsQw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by SJ0PR13MB5401.namprd13.prod.outlook.com (2603:10b6:a03:424::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.14; Thu, 25 Aug 2022 14:12:42 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576%8]) with mapi id 15.20.5566.014; Thu, 25 Aug 2022 14:12:42 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, oss-drivers@corigine.com Subject: [PATCH net-next 2/3] nfp: check if application firmware is indifferent to port speed Date: Thu, 25 Aug 2022 16:12:22 +0200 Message-Id: <20220825141223.22346-3-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220825141223.22346-1-simon.horman@corigine.com> References: <20220825141223.22346-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR01CA0078.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::19) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4fa373a6-86bb-4f9f-0d82-08da86a3e034 X-MS-TrafficTypeDiagnostic: SJ0PR13MB5401:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SuaEzUNiV9con8oSZfTPKwye/uNUEFjIVOOId8SgiTG6BYXaGeRJRXb8q4Mmmxg7Wnrw3xvYYGEicwYLTXkJqsJRzBvWZi4nYdSfJRLnNVouGW9Q3Ls61by8awyO9giQYC7VPf9Rt2+ysPmuThru44kwEX1ZGUZ1YzGfTeVRfjIfFOZM/5zucJYuhSuDNMO3LwFoLOAg5zEBs92K6C2FG7IR8/WEPHJ2WiRjaTLQWsvNjR8138XzN6h74zmns9ciFV8ZUXcFykHGMNUhIxIWaY87vnwfVZwzFtdLE+cP/CHB++u+0e6mHnP9Pe7iA2oeloSPk4JenfYUasxYG8uL24VcRcsJkJgZTB0h9JbwoahBQj+ao/iVKpZl8DoTNtq1nKiR8sZZ4mUz726J86YFjiiPNycZsxgjL/JGQ1gd5ge30uLraei/dXlK6xDzF1enNsZ597Xksx4GH9fAspvyG3ZBrVaeof9XFd0S/suLm/g/Wt8izu7QGVEEmt+MtznMecYFbHutL4byzJJQCluzU4YBQ2llhjOB+KQKN+mX+y7RiGltMR1tdRrP3GdUVpVHS4Ru1LhehxYMUOUK/bz0lctdOj+b0G+8dgQZCw6Xu23g81HF3C047bq7v/bI0KhXE6eEgP0vXe0qMYKQ+SO89EvZel6hFVSo29CainW4pjRhZTQwxdq/Wx2fS97zbo835Z2p6uBf9BrzZ3CB1X8kfQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(376002)(396003)(366004)(136003)(346002)(39840400004)(86362001)(83380400001)(38100700002)(8936002)(4326008)(66946007)(6486002)(478600001)(8676002)(66476007)(66556008)(52116002)(110136005)(316002)(44832011)(6666004)(1076003)(2906002)(6512007)(36756003)(5660300002)(107886003)(186003)(41300700001)(6506007)(2616005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: falCIFburidmQbxS03H7FB8YvvsHdGW9k3czzSml9Pk7hnaEO2l6tXrQ4SbdPZP1j8DENSKQb7juH/CBHHQ4dS3bdZcKrlYS47Ix17SNIQpbAJg01twPkjQVwS/NkSpWLHBrQbmFsjA3LqAbR8tcIoTRk0v/cNj2jaG9m0zwRjqzwzC/7cl6ZdA+knQ5jwH4E/VwcBbsYhVABU2r3ljB0LD9b5/9YWkKWoCOAA1eE2CQ+0rtAe1/HfYA1Jq4cVE+cbEG+QvrHSO5MBivASGQvLjg4xgLvxtvV0x8A9n7WSwlWLr+gppuJkAl2Y9m0GFv6cakWTZ3MXr4icZX+uHUf9wuyTsiVBLMSrz23AmaDmkZk/JJ5/np3l8c1/QPtXKsBBID2f2aBF/N3b29MM/ikaZMhELbP3Nn0BMjy3vm7HDL1MjPn7RiwF/yZzsugZJn66F1CaZM7bktZeoSgOwQkllGiteNHXRjT5o9SdpKqlcusOgKvn6K9u+Anl0o/jPMzsXcyG/0BjAgmC6C8THB9dMY8ef/UHFHU9KRCZk2tjGourmrg4dwzrcREBghcOPLP6o+koHvAwvo1Zsjj6pIuaeX3VMOfK5m4byra0VvNK/ntDhMykkZttNaVEq1NpzrVvbpc+FrHXwwbTVD1sFqjeiSCPlJGzaxEnt3gwK1E+f5Te/gM1vgPSlPaG80trqqzRkb5mAl0auIGlush+w2dSQag3sUrRKSpnpf/HUpuHSIj9UHdZWixVUosBXIeTheOGLR3VwANqK8I2mCTet3JQTA4k8Du2rI2XIHoLDFM3n8uWXPktOZJIlpp93cIxFrqBgWo458Iq9xPbAgmdfE/L9RDHog4rWF//bhBO6RxjVBRi8KMaU5+Ms+UGVFAczmoe5xMMZSUpxllSWvYoU4lWMWHCM/uc+ZO3S0jmiqqqoFrPnI83176uGWEspVrITBNLBIJHQvKWLxwQ6UG/nT+1svH5eYVBC2gDp4zQPGxflx+AW9BO6KMObFI4MHArY8Q2qGE0bh+KwHkEHV8bSgg0pT+SMGVYXOqfVhjllH4C4Yb7wXQHh04IKVDVFNcMvRaULnEHwwFciHON9WSD9kW7FzuiqsIscjBHGDdOyeN9VPvWIWRuEoUrQqCmqE273foqrpP47vE2p3UCkxEO4DRCJKGHlufFuqd9ofm1fuMByOvavrURJ0MzX/78fUFSjiGTbojZISXHQ/dYEV/PwTY0eyGAY9ueDVEKRS0Yi0mzI3hIE6QxzTgo+PHjNOXjbDE1i978WbDJzDb67hydFt8KAMsgqVTYJ2yXsvrGLPEmdZmt4nH7p1UB6Ecws/bLwch78IoxME9RtFgUv1ObqDkpLK1va/UbWxiyWOZP9bSNINlJEXd/tEeuzWhJDJ7mbMZnT/HPJQFc35rVP6gmT3aVQjy6uGixUvHjsSpckHXJ1SGiS06je1LQ+VyiXTrYMIvs/O7JDQtpbYn2jdNdHu+wkC8d2gzNqIUodpS61D8UC1i0v5YqwKV93zVoLRPQHdNFM0mMPF21CiZxcmQF5Oc7KBivyqdHJZ+honG19Yf6/q4Namz4If41vhGNiHRvHOiB/gEWXWcz4TBo45nkVLej6lztfYTYZBWJLsmyak5MDwSTSdKWWKxTLQyYGbMYbNKnAampBYLFOLVRzM+/MxPA== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4fa373a6-86bb-4f9f-0d82-08da86a3e034 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2022 14:12:42.6895 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Vr3hUBk4qVzKizEcLB1LfxxyQQ49Vn1kaJP/q/EhAos8I7wtap5TWWzMHKZG7DoFSWGn5hGKo5LF3TOZNNMHrQ10eSdytsW+GkX2XaC9//c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR13MB5401 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Yinjun Zhang A new tlv type is introduced to indicate if application firmware is indifferent to port speed, and inform management firmware of the result. And the result is always true for flower application firmware since it's indifferent to port speed from the start and will never change. Signed-off-by: Yinjun Zhang Reviewed-by: Louis Peens Signed-off-by: Simon Horman --- drivers/net/ethernet/netronome/nfp/nfp_main.h | 2 + .../net/ethernet/netronome/nfp/nfp_net_ctrl.c | 8 ++++ .../net/ethernet/netronome/nfp/nfp_net_ctrl.h | 7 +++ .../net/ethernet/netronome/nfp/nfp_net_main.c | 43 ++++++++++++++++++- 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_main.h b/drivers/net/ethernet/netronome/nfp/nfp_main.h index be3746cbc58b..6805af186f1b 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_main.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_main.h @@ -65,6 +65,7 @@ struct nfp_dumpspec { * @num_vfs: Number of SR-IOV VFs enabled * @fw_loaded: Is the firmware loaded? * @unload_fw_on_remove:Do we need to unload firmware on driver removal? + * @sp_indiff: Is the firmware indifferent to physical port speed? * @ctrl_vnic: Pointer to the control vNIC if available * @mip: MIP handle * @rtbl: RTsym table @@ -114,6 +115,7 @@ struct nfp_pf { bool fw_loaded; bool unload_fw_on_remove; + bool sp_indiff; struct nfp_net *ctrl_vnic; diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.c index c3a763134e79..d81bd8697047 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.c @@ -148,6 +148,14 @@ int nfp_net_tlv_caps_parse(struct device *dev, u8 __iomem *ctrl_mem, true)) return -EINVAL; break; + case NFP_NET_CFG_TLV_TYPE_SP_INDIFF: + if (length) { + dev_err(dev, "Unexpected len of SP_INDIFF TLV:%u\n", length); + return -EINVAL; + } + + caps->sp_indiff = true; + break; default: if (!FIELD_GET(NFP_NET_CFG_TLV_HEADER_REQUIRED, hdr)) break; diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h index 91708527a47c..1d53f721a1c8 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h @@ -492,6 +492,10 @@ * %NFP_NET_CFG_TLV_TYPE_CRYPTO_OPS_RX_SCAN: * Same as %NFP_NET_CFG_TLV_TYPE_CRYPTO_OPS, but crypto TLS does stream scan * RX sync, rather than kernel-assisted sync. + * + * %NFP_NET_CFG_TLV_TYPE_SP_INDIFF: + * Empty, indicate the firmware is indifferent to port speed. Then no need to + * reload driver and firmware when port speed is changed. */ #define NFP_NET_CFG_TLV_TYPE_UNKNOWN 0 #define NFP_NET_CFG_TLV_TYPE_RESERVED 1 @@ -505,6 +509,7 @@ #define NFP_NET_CFG_TLV_TYPE_CRYPTO_OPS 11 /* see crypto/fw.h */ #define NFP_NET_CFG_TLV_TYPE_VNIC_STATS 12 #define NFP_NET_CFG_TLV_TYPE_CRYPTO_OPS_RX_SCAN 13 +#define NFP_NET_CFG_TLV_TYPE_SP_INDIFF 14 struct device; @@ -519,6 +524,7 @@ struct device; * @vnic_stats_off: offset of vNIC stats area * @vnic_stats_cnt: number of vNIC stats * @tls_resync_ss: TLS resync will be performed via stream scan + * @sp_indiff: Firmware is indifferent to port speed */ struct nfp_net_tlv_caps { u32 me_freq_mhz; @@ -531,6 +537,7 @@ struct nfp_net_tlv_caps { unsigned int vnic_stats_off; unsigned int vnic_stats_cnt; unsigned int tls_resync_ss:1; + unsigned int sp_indiff:1; }; int nfp_net_tlv_caps_parse(struct device *dev, u8 __iomem *ctrl_mem, diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c index dd668520851e..e2d4c487e8de 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c @@ -206,6 +206,7 @@ nfp_net_pf_alloc_vnics(struct nfp_pf *pf, void __iomem *ctrl_bar, nn->port->link_cb = nfp_net_refresh_port_table; ctrl_bar += NFP_PF_CSR_SLICE_SIZE; + pf->sp_indiff |= nn->tlv_caps.sp_indiff; /* Kill the vNIC if app init marked it as invalid */ if (nn->port && nn->port->type == NFP_PORT_INVALID) @@ -307,6 +308,37 @@ static int nfp_net_pf_init_vnics(struct nfp_pf *pf) return err; } +static int nfp_net_pf_cfg_nsp(struct nfp_pf *pf, bool sp_indiff) +{ + struct nfp_nsp *nsp; + char hwinfo[32]; + int err; + + nsp = nfp_nsp_open(pf->cpp); + if (IS_ERR(nsp)) { + err = PTR_ERR(nsp); + return err; + } + + snprintf(hwinfo, sizeof(hwinfo), "sp_indiff=%d", sp_indiff); + err = nfp_nsp_hwinfo_set(nsp, hwinfo, sizeof(hwinfo)); + if (err) + nfp_warn(pf->cpp, "HWinfo(sp_indiff=%d) set failed: %d\n", sp_indiff, err); + + nfp_nsp_close(nsp); + return err; +} + +static int nfp_net_pf_init_nsp(struct nfp_pf *pf) +{ + return nfp_net_pf_cfg_nsp(pf, pf->sp_indiff); +} + +static void nfp_net_pf_clean_nsp(struct nfp_pf *pf) +{ + (void)nfp_net_pf_cfg_nsp(pf, false); +} + static int nfp_net_pf_app_init(struct nfp_pf *pf, u8 __iomem *qc_bar, unsigned int stride) { @@ -318,6 +350,8 @@ nfp_net_pf_app_init(struct nfp_pf *pf, u8 __iomem *qc_bar, unsigned int stride) if (IS_ERR(pf->app)) return PTR_ERR(pf->app); + pf->sp_indiff |= pf->app->type->id == NFP_APP_FLOWER_NIC; + devl_lock(devlink); err = nfp_app_init(pf->app); devl_unlock(devlink); @@ -780,10 +814,14 @@ int nfp_net_pci_probe(struct nfp_pf *pf) if (err) goto err_clean_ddir; - err = nfp_net_pf_alloc_irqs(pf); + err = nfp_net_pf_init_nsp(pf); if (err) goto err_free_vnics; + err = nfp_net_pf_alloc_irqs(pf); + if (err) + goto err_clean_nsp; + err = nfp_net_pf_app_start(pf); if (err) goto err_free_irqs; @@ -801,6 +839,8 @@ int nfp_net_pci_probe(struct nfp_pf *pf) nfp_net_pf_app_stop(pf); err_free_irqs: nfp_net_pf_free_irqs(pf); +err_clean_nsp: + nfp_net_pf_clean_nsp(pf); err_free_vnics: nfp_net_pf_free_vnics(pf); err_clean_ddir: @@ -831,6 +871,7 @@ void nfp_net_pci_remove(struct nfp_pf *pf) nfp_net_pf_free_vnic(pf, nn); } + nfp_net_pf_clean_nsp(pf); nfp_net_pf_app_stop(pf); /* stop app first, to avoid double free of ctrl vNIC's ddir */ nfp_net_debugfs_dir_clean(&pf->ddir); From patchwork Thu Aug 25 14:12:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12954758 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 753D2C64990 for ; Thu, 25 Aug 2022 14:14:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241764AbiHYOOT (ORCPT ); Thu, 25 Aug 2022 10:14:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241385AbiHYONz (ORCPT ); Thu, 25 Aug 2022 10:13:55 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2124.outbound.protection.outlook.com [40.107.220.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62E92B6D52 for ; Thu, 25 Aug 2022 07:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GxaZeJTScFF0XMF/lJIQle6pysDsOh/tT7DRU3hxobFqxnskSWZYrXiSMcJtWm2/ZbjRqTbVTOtI2AxztjdJvxEli/qihIMQpFiR5FVTRs3XzYsmVpP/yuDnEn+4k+eqE163dUFrg6b0Yj4peLnf9SJOflHf5JIK6+ez2t9vCddJqySfoEqt2h5RYJrhQUJjkqj3sBLul2O0SycXn4QOn/qkXIqQBd2vzeMpRPCKs+NiutW40UsxPR7zZQSlDOhojybrvVr1sfwU5NJLdX50cz/RP57kX53c9UynNw4MnuO5ye3m8KpYhDqEuhGoEyctavf7g86Fkvkea9vJK7SKJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VQWZ9NpAssNVObQ0AmIdAhovxyp2RhtpJDKuX7Eiowc=; b=kONnw2NtK1XydXAM+MPXQdgonVafjgCdCosk1eL4KHcftz6j78DC0uaHql1nSHgpzOwC8zdYztRmU8g+UNnfONP4i3qqgVbgm9g7U43DnKcS+vj8QYEMHreKNTZ4pWfyvL38a3fkkPSgPmDHo4wZ/MkrSvJAlXbfufMN3eep5MHaAA6AfYJdBRV7jEvYsmG6dPMS9gsQKUGo8GUQrLeL1edZjAH6UvVeFsvd9rDRhTP0e75sAt385yD/Ola2JWU9jy6vct7YQl5MA+3KfC8QVdiKEVB+A6TGO1kL2lboWibTFxeqiTV8jAkCDwUNVvc0wLCkbAOTTOcnkpTyFftL6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VQWZ9NpAssNVObQ0AmIdAhovxyp2RhtpJDKuX7Eiowc=; b=oMW8PGuGHqaVMtq8gNsTVoiANUGxueqbKV4stO7WuGzuqRUQ71MZORJZfEOKO4wfNtpWj3oqqdBqppvujwKEkKMPLtU5te59xZsqlzsaswEbRsig5LPxBWc5YSPU9DSS5LWIetr6/UuajACTyN5sOb3B5AyqBvY6r2SohwuPqok= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by SJ0PR13MB5401.namprd13.prod.outlook.com (2603:10b6:a03:424::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.14; Thu, 25 Aug 2022 14:12:44 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576%8]) with mapi id 15.20.5566.014; Thu, 25 Aug 2022 14:12:44 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, oss-drivers@corigine.com Subject: [PATCH net-next 3/3] nfp: add support for eeprom get and set command Date: Thu, 25 Aug 2022 16:12:23 +0200 Message-Id: <20220825141223.22346-4-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220825141223.22346-1-simon.horman@corigine.com> References: <20220825141223.22346-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR01CA0078.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::19) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b4d9a1d2-4785-4ca0-a39d-08da86a3e103 X-MS-TrafficTypeDiagnostic: SJ0PR13MB5401:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yd7JvlXwIZsukBwenHP79cj/UTZYvvlZb0y7PEzBQOGbN6ywSZgsFujxgBrCRHsQ7hWmqjojDJg6vuLdFO+ltP8+ULmJqAirHFugrc7rPHbiSsMnoJVWVv3W8jtZQ/SpUoq+fxDQC9GLxLUhz32i4hdMWoSoUYKLTg17RN8/DvyVj4Kqvo46BI71LmVOhohaWora3jz5eVLFuGOKrxZ4YHxHcvUsIJbENTwfI/9YQTNlHO9D//gt2bpO/nPj7yO4aSkr3VuTo8gwFQyDSJ7RU9N6s8a5YMWn++T7trQXkVpp/jUpnB1s5g1nxnjub7NKSR//eUqrq/JvCBeCvcMBCcJAUWmTdIEU7h433Qa2V03llJVYk84ntdhm5vNPc4h0lB0DkHVBimv6x+8nwTOctUfDpSWrWwNApo8amXMAUT2tQGpNXpF0sVL3sAq+RJqnZT34lMqtrbafd0gUn/vTlTYYdJDj1NipfjGX7qkxoSw5r199WdkhobFzf58qzL4k2GjawSCPOw0g/uB3U2oqMw03o8hECu8bdydMOoFp7rQBTFNWCZVzGEAwz99lHIXVTOktTdSBT9R6GGY6kFPGwQ6nR1AJyKu7zwphs3csnzZ20blz4dRuTurbosyb1RR8yKW+/PNwhggcNOExymg3rTelbr0yswRDzegl+L6Pu8KXogAuXcLbwd0Br+VftQnARcAPerRLz5ApyA1LJ3Oryg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(376002)(396003)(366004)(136003)(346002)(39840400004)(86362001)(83380400001)(38100700002)(8936002)(4326008)(66946007)(6486002)(478600001)(8676002)(66476007)(66556008)(52116002)(110136005)(316002)(44832011)(6666004)(1076003)(2906002)(6512007)(36756003)(5660300002)(107886003)(186003)(41300700001)(6506007)(2616005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ueTNilP62f8BybZd5AFMvqQvu2OAg6zc4T4o18OyJBzhIMaIsGksXGNo1hDgZvJZx7ApHyzBE4K5YHiwypecCBKCNaA+2jdRpEaaAGvwj+grPQoOotQMbBKU7nQvxbdDKl8it09EhjmAWRuKnLoK9+dlJWrRKXFC+ioR2pWbx18vRT3JUuZS3/Nk9RgSFdnBcGe/XGaZNwCHWvvTpVO96ABPiA1KclBB0I5Q1w8d9piP72VuUm7M3e7Q+5JCqDRbKuCp+bhqU+O0suJ6PMZ8Zy4ojyJ508pRN37sraG5o13E0/7oadYQKrdT3cFo5tgrEuhyFEnwoBKBINzNEXxtxJqgJwtgxR8arxd5syiuLXdNfQrjJQaqTi+cCOSa8jIMlTyauPraYNuFSuDMZMH2qXh92anQAnlgIidf4JQqmoiSjJnOhWTtD2WgRdzPD4+pZ1nJcnHHrH6b3g7Xd02SwtdVyc/OqlrGlitgBNUJSw4V4dnUg0fvAFCLxl19RY+HqZhk97vrHUdkD1IdZ4ZyzbZMjQe1EoG3vyjqWOAwUS37exQ7ZZZfjtFEJF1Bf/kTn1WO1b+Aze1dUPJwcAj/mGt7OXeJQ2gN0CJ0Yh9TaJ0i+/KyaKCk+VP3sksv0Kr2m4tQVT7++0wjDg5xBSGPVceVP0PsorOcYpx87weQh3c2EqE+BVN4dF5UeQOC0aLg/GAb7zo6lnTFeVZARXGvRHAQC+5yu4SIUmpkXThnYj34ukh9xnB7kUxeOI//IRt+rrm7CFZqY1ezC6CcwIWFd98ZHMHi8EPbQPDBC9MIKmlGkhkWzrk8OqrHOPAJo93m9ZRjbcHSp/3wNZR6fYmUTeLRiKlkkcOQ+jurL1FbruO1ERYJj7ppp+1XXFSBPovnwR/2B+vzA6mkPdZZnwGXVI2AnB6UvPApcmykjKMqsMX1T6Gbtg16owg0V6hdr1DVU336DcQpWMS3e3Fbm5oViZNK3FFyA3x36pfC5xm/ephXgBScu7trarxIVhLAHY0Ye1gTDzqBqrJmy+8Sna6sM+UXlVzgtdCl5MYq0Uomub5A/db5IF9PcoVQRYJBS6h0gPto/u/PMoUb2T+s+2BpKRIdfBTJwySyNo8c4H9eEHuOuwpomD7f854qTIv8ic+9lQw73RNNOvrgzqCdo/n5D22UXeD++XJLs5A7AvVkFJ0vMel0SxB2s/4vvv7v/MzzP6uPs2wO1tg/dCLrraIpkIRUXT35aslD4BiYfiojv4jMr4QASseDkaZc9BS/O7ejrLniSVSBYsezpsr1ESfu78CzpylkGsgkV2qrzuhMSJ2xgtJSs/JHG7NAuwkTuGCv0q3i/3Nat4wJJmTZ/bT6Wv+MJIrwMnYS5Sg23XSayqGqdSG78zTIdQ6HS6xvwg/CuUQi7GLY52fMcrVXlnQF+xgpQBavUdqjmIPnWE0SGn5cU36xZ2tuVdiriYgZ7TcPIIYyj/JMGInn0ivmilYr9Nc5B2gAd8l1EUPv8QIMei4NHr6+1PI16dnmv3N6Y01HsNiAVNneBTYyQJXFnxQquZiCarz+Yv9VQNDZRDaRr7AhDQ6NIFgvoXd/1G80qhQbKlfF71ddGfpWij2rx1Q8CZoKZ0cDX+4Yd7rTLJWdZO0szwwo4CUzTD3aHvSfVaSf4tUpsQ4qLU9LMjwZ6JRNkg== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4d9a1d2-4785-4ca0-a39d-08da86a3e103 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2022 14:12:44.0655 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zcfDRLDB2YBRoTVxgJciGYLIbo16XX3id6FP99AQSij4oM/ThN+BFAfksLj7GDh87iFUKLI5/I6nQa47adPFCFx7aV6OWTT+wJUWe1W6zlo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR13MB5401 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Baowen Zheng Add support for eeprom get and set operation with ethtool command. with this change, we can support commands as: #ethtool -e enp101s0np0 offset 0 length 6 Offset Values ------ ------ 0x0000: 00 15 4d 16 66 33 #ethtool -E enp101s0np0 magic 0x400019ee offset 5 length 1 value 0x88 We make this change to persist MAC change during driver reload and system reboot. Signed-off-by: Baowen Zheng Signed-off-by: Simon Horman --- .../ethernet/netronome/nfp/nfp_net_ethtool.c | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c index cd2e67185e8c..ac31c79ccd3a 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c @@ -1664,6 +1664,160 @@ static int nfp_net_set_phys_id(struct net_device *netdev, return err; } +#define NFP_EEPROM_LEN ETH_ALEN + +static int +nfp_net_get_eeprom_len(struct net_device *netdev) +{ + struct nfp_eth_table_port *eth_port; + struct nfp_port *port; + + port = nfp_port_from_netdev(netdev); + eth_port = __nfp_port_get_eth_port(port); + if (!eth_port) + return 0; + + return NFP_EEPROM_LEN; +} + +static int +nfp_net_get_nsp_hwindex(struct net_device *netdev, + struct nfp_nsp **nspptr, + u32 *index) +{ + struct nfp_eth_table_port *eth_port; + struct nfp_port *port; + struct nfp_nsp *nsp; + int err; + + port = nfp_port_from_netdev(netdev); + eth_port = __nfp_port_get_eth_port(port); + if (!eth_port) + return -EOPNOTSUPP; + + nsp = nfp_nsp_open(port->app->cpp); + if (IS_ERR(nsp)) { + err = PTR_ERR(nsp); + netdev_err(netdev, "Failed to access the NSP: %d\n", err); + return err; + } + + if (!nfp_nsp_has_hwinfo_lookup(nsp)) { + netdev_err(netdev, "NSP doesn't support PF MAC generation\n"); + nfp_nsp_close(nsp); + return -EOPNOTSUPP; + } + + *nspptr = nsp; + *index = eth_port->eth_index; + + return 0; +} + +static int +nfp_net_get_port_mac_by_hwinfo(struct net_device *netdev, + u8 *mac_addr) +{ + char hwinfo[32] = {}; + struct nfp_nsp *nsp; + u32 index; + int err; + + err = nfp_net_get_nsp_hwindex(netdev, &nsp, &index); + if (err) + return err; + + snprintf(hwinfo, sizeof(hwinfo), "eth%u.mac", index); + err = nfp_nsp_hwinfo_lookup(nsp, hwinfo, sizeof(hwinfo)); + nfp_nsp_close(nsp); + if (err) { + netdev_err(netdev, "Reading persistent MAC address failed: %d\n", + err); + return -EOPNOTSUPP; + } + + if (sscanf(hwinfo, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", + &mac_addr[0], &mac_addr[1], &mac_addr[2], + &mac_addr[3], &mac_addr[4], &mac_addr[5]) != 6) { + netdev_err(netdev, "Can't parse persistent MAC address (%s)\n", + hwinfo); + return -EOPNOTSUPP; + } + + return 0; +} + +static int +nfp_net_set_port_mac_by_hwinfo(struct net_device *netdev, + u8 *mac_addr) +{ + char hwinfo[32] = {}; + struct nfp_nsp *nsp; + u32 index; + int err; + + err = nfp_net_get_nsp_hwindex(netdev, &nsp, &index); + if (err) + return err; + + snprintf(hwinfo, sizeof(hwinfo), + "eth%u.mac=%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", + index, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], + mac_addr[4], mac_addr[5]); + + err = nfp_nsp_hwinfo_set(nsp, hwinfo, sizeof(hwinfo)); + nfp_nsp_close(nsp); + if (err) { + netdev_err(netdev, "HWinfo set failed: %d, hwinfo: %s\n", + err, hwinfo); + return -EOPNOTSUPP; + } + + return 0; +} + +static int +nfp_net_get_eeprom(struct net_device *netdev, + struct ethtool_eeprom *eeprom, u8 *bytes) +{ + struct nfp_net *nn = netdev_priv(netdev); + u8 buf[NFP_EEPROM_LEN] = {}; + + if (eeprom->len == 0) + return -EINVAL; + + if (nfp_net_get_port_mac_by_hwinfo(netdev, buf)) + return -EOPNOTSUPP; + + eeprom->magic = nn->pdev->vendor | (nn->pdev->device << 16); + memcpy(bytes, buf + eeprom->offset, eeprom->len); + + return 0; +} + +static int +nfp_net_set_eeprom(struct net_device *netdev, + struct ethtool_eeprom *eeprom, u8 *bytes) +{ + struct nfp_net *nn = netdev_priv(netdev); + u8 buf[NFP_EEPROM_LEN] = {}; + + if (eeprom->len == 0) + return -EINVAL; + + if (eeprom->magic != (nn->pdev->vendor | nn->pdev->device << 16)) + return -EINVAL; + + if (nfp_net_get_port_mac_by_hwinfo(netdev, buf)) + return -EOPNOTSUPP; + + memcpy(buf + eeprom->offset, bytes, eeprom->len); + if (nfp_net_set_port_mac_by_hwinfo(netdev, buf)) + return -EOPNOTSUPP; + + return 0; +} + static const struct ethtool_ops nfp_net_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_MAX_FRAMES | @@ -1687,6 +1841,9 @@ static const struct ethtool_ops nfp_net_ethtool_ops = { .set_dump = nfp_app_set_dump, .get_dump_flag = nfp_app_get_dump_flag, .get_dump_data = nfp_app_get_dump_data, + .get_eeprom_len = nfp_net_get_eeprom_len, + .get_eeprom = nfp_net_get_eeprom, + .set_eeprom = nfp_net_set_eeprom, .get_module_info = nfp_port_get_module_info, .get_module_eeprom = nfp_port_get_module_eeprom, .get_coalesce = nfp_net_get_coalesce,