From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1CD3F45C2A; Mon, 4 Nov 2024 02:35:42 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BF8C240697; Mon, 4 Nov 2024 02:35:34 +0100 (CET) Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2132.outbound.protection.outlook.com [40.107.101.132]) by mails.dpdk.org (Postfix) with ESMTP id C34B24014F for ; Mon, 4 Nov 2024 02:35:23 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=C8RJ/V9HHRRE1dPcvFcpzFeBA7w2FnWtdmpErbM0P7+buyhYKkPCJX97SXUJyoP4NKaYwAsICFPyqVakrWdnStOOE6vf2+nqXiU8z7BbVVOVXVSjMoAwPdB7lGFB18IJ5PsmMXDQf4QLDDWpY6VY98rj4Xj2L9gJS2jWziJ+Iy1E3OQvNxtyh1KgaaK6xklHfVUbr6k9XmcMuksrqHrJ7OtHQsisBQV2Gry79wNpxL5iyVOUvlnD85cQt92o9dg/2RuoI51gZRHEiz7O7Rp9BYqUaGmpPszXs0t71coZ5TC6zwskPjosV4qNCMlpATlyNb1MZ8ggurJ4o1p4RRs3wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=PXxVeOWzW3zuMNijZK4o102ZJ03UKd8tQ92q8ZXAuWo=; b=ZvfNYfmn6sFPOKsfOiW95YtcG7jFOrvCzFWb2n4CfASAdxgcQf3eBp7bK5s0081Grskb3gaucN3uGVdQytYzkjJLm0VSartZ63SFGH+y3D/BQic3/Ju0/jR1dv+fLdtWVhhOvFoF4RM2y56EC7HqPNLwaLuD+GXvte0Gsu8hgMS9+XJBeCOmjPOeyhaTe9FKTUz5uWCoNkEvVBEeDpR1M7ifAi2stymdo7wOp3Vt/bB+HfCSgH203QrREupjmTWZHPTAVjaIYpkftmROH/m9Q7+17/LivcsGE1gywbbSyOB4D4s6EKgLg6AnfBc+5bTtsjVBfjSEGQSBHr1JGkKQ6w== 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=PXxVeOWzW3zuMNijZK4o102ZJ03UKd8tQ92q8ZXAuWo=; b=YA82NKYi9c6GaVJXovDM546FYBPEMhYqEvznoFCF2Bx8jg8M+8afW+GOrpVhCDrFVdE9r/FIlgHq83wquKv9z18W8S1B/8Fhx7yV8dBDM1NCKmzVPvbCHwyX0XvgWX2i/KMWXfx67Ub71p9SjpDBsP91FpmZMWNhxxlKWPNUBbo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by SN7PR13MB6158.namprd13.prod.outlook.com (2603:10b6:806:323::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 01:35:21 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::b900:5f05:766f:833]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::b900:5f05:766f:833%5]) with mapi id 15.20.8114.028; Mon, 4 Nov 2024 01:35:21 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He , James Hershaw Subject: [PATCH v4 3/4] net/nfp: add support for EEPROM functions Date: Mon, 4 Nov 2024 09:34:41 +0800 Message-ID: <20241104013442.308780-4-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241104013442.308780-1-chaoyong.he@corigine.com> References: <20241101025713.290462-1-chaoyong.he@corigine.com> <20241104013442.308780-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2PR06CA0009.apcprd06.prod.outlook.com (2603:1096:4:186::17) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|SN7PR13MB6158:EE_ X-MS-Office365-Filtering-Correlation-Id: 70e40b8a-8ae7-4af6-6b46-08dcfc70f250 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?fqtUxFOkqXwCw2x6SN+dM9iT9LcPXo6DQp4RQiRjjQxaOHdkCz37wLKvPmMM?= =?us-ascii?Q?+MR+d6yzDMvkAzVU+qw453u8IabdTSNdUFOW4HcaPkAO35t502lqtBY8U5zc?= =?us-ascii?Q?weoWywlIqrHVgOHADIQU6hKlSz2a0FUun4TB254eXKrL8wXD0Ig7LMlB3DCs?= =?us-ascii?Q?0uZcGISGFIlERVMSbMozh5cypb8NmXeWRzs7Rm9ll6LidD0UC58C0Zlza5+k?= =?us-ascii?Q?9SDkFft/NccE+vz9ZzYda/umlaqyg+cSDGIcUcRrNkOO2dhKJPLADe3IStcc?= =?us-ascii?Q?HYCQRTyoc/RlyaMePwGDhZnNzkOTDpwG2SRylericALJt6/ldlgidaCVtuDl?= =?us-ascii?Q?fUJzuMnLRL4qFcImsFpC3sbMtT0tpfevLixLohZktgjj7sDC1WzUINkiYNj+?= =?us-ascii?Q?6fJ62BpfB5LfdLwGGNr5CiFFURpYAt/nkOEB4JQc1kwlH7Zrt5swIsM9JH/Z?= =?us-ascii?Q?TBoLb1JuiniKUNHb25QbT5s4jjTlCDtTemP1MiE8pH5fG+86N3dtpGqdZYqS?= =?us-ascii?Q?n7KLPip+prX2L2/QJBx35asstTLNBBMbBBHAAjLhMK8pwGNIzDAemsh5c4jA?= =?us-ascii?Q?KGAqnZBpZAKYDm1oxCQogfuBaQrzE9eN4WX/19RuORl4h+4kySFZq5olxK8R?= =?us-ascii?Q?Lxt6xmqUEWBJZodTWF7jNqqThNC9k0EF6K15pYtcOIrFCGiQQwZRH+oOY0AY?= =?us-ascii?Q?T0Vli8nuXXHUiBAhS1TJqqiCeY10ru8dAwoXbV+rQv7phJzDIbraHmi0iN7A?= =?us-ascii?Q?jX3w/FG4e3h+Optu1OVur40ExE0vUMYznyouQKDD5mOF7Q+2nan9wAEqn27V?= =?us-ascii?Q?Ds027QPpoYpwteZs4JS4h2DubbCDJv4PVlbLis9JXH/LSv1ZN0sfdkFcmPJf?= =?us-ascii?Q?cQ8XzvcewHqRZaUMt1A4sAVg8QCJ87mFPgWIqlFIcnkU8afm7BJWzA1O88S6?= =?us-ascii?Q?9otTiiuPws8RAVBHZkD/BGDMlaU5xhTfSS6F0KTb7DUgtaVpz0acbY/9pN7q?= =?us-ascii?Q?dCZpoTSo6A53rn87AUILCaes0pOkEulR5OiuiI4z9BvJzUEjHq89eOi74Ia2?= =?us-ascii?Q?5jCcZIy2j5z7bw2Sd6y40sMOA9XAlIkpTLwmamOa9rxgNnP+MBOTErMDekHA?= =?us-ascii?Q?fcWe8hQTlNHMK2ggALqF61u/vT9TXswLRkig846OJ6axsOmKy1RssKDkit+q?= =?us-ascii?Q?9UsmUiCz2SVGh0dk5tYY6HLrEx3XmURoDo/fIbdyMzho/ai65ysj96PL47wi?= =?us-ascii?Q?fytnaVafkUKDE4y3ghAmjWl6/DZ5rcEE6cLlAYuWStccExohy4edbca6mTcz?= =?us-ascii?Q?EBOgKwo9dYajXq5/btp1VYGfbGYQvsI7j4j55KiGi8bwexPbBo3/oDuQufPg?= =?us-ascii?Q?BsfIoD0=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?TY19hdAtbkqPHb5Ms+q1rM33FE5toUVPIDFeWztqxTxzl7bVLm24QEVpFJDq?= =?us-ascii?Q?EDyyfof5sNOKrcOt55F4Bht7qvOuAub7QXVsk6xYWk/F8Hdmydt1xMaNNAde?= =?us-ascii?Q?r2BY0MSLo0InY09QjZBHVPMuEHRE3ZCQzWFQ+LoxV+EisLUOEFJbWz9+nnF9?= =?us-ascii?Q?s/NqdwP+Hlf1AbpomwUpfiEde9BwEOzbtwVR/sVO7QWqHGWbyBjwGDMrQ9fG?= =?us-ascii?Q?n3zRP9CWK+lB9hL5VGP7qLSb3Vm94kCp0w8NTL6Awn1KYTIwvE43yKw5OH9O?= =?us-ascii?Q?Im4HRXQilR67yJTjmHxaiUdF/RG44J02MZcfNR0R5OxhtAE+jghGv4wK5x+J?= =?us-ascii?Q?Ppb+TZ0Ha4Lyg1upb5kOjqAvCUf1hc+O4AHVHCBzTv3JQHdUIQvObsE+yRfr?= =?us-ascii?Q?fp/UAWNfVkh6hA32wPojVQ8Z9mYohCb2JsT+u5mCzGmZJo2pm2vDQE3HfYZn?= =?us-ascii?Q?1khsPfykp31aGhFuesqmcMAHHCcXNC+4IHe+//txZXtmywixWdETcOg2zmCL?= =?us-ascii?Q?liEFm9pHXZeAaKcPMcpT2bHmaYcjaf83wMV3fCzcGTBdWwTY7/heepl+sWeQ?= =?us-ascii?Q?apNdW9lXAA8nQSgsWO8LlDSwYjQoUvClbO3ab02ioDP+Q+ixT5gLuaOK9w40?= =?us-ascii?Q?oXhs6JYVgXh8mBsipUr6MjPixLiJnRYhXzNhD506mWH42ZeizuKivbOpVSQw?= =?us-ascii?Q?T63KtM0aVtZE/6GnS9L1j+LNPtrfofrD+mdEIWCD3yaoXQM4Dy0a0iGi3/90?= =?us-ascii?Q?swEWk9erx1LvdUD1kSatyDw62QzAvWvFQrC+wv2h8j8F7ButxDOTNMOYQfBU?= =?us-ascii?Q?aH+pdjLa0mI1BHV9nV6MEGaCPjKeGarXrczsrQ1NkVXRWD7xoRzq4IgiePrk?= =?us-ascii?Q?aJKDjXW2GocjFGfN87LBMGlGIlDqrBbaraziDymx9zznf1zLLZXgeTY/e4Y6?= =?us-ascii?Q?AD83ewVn7vLrM4MqaqlnNScm9VegntRV5PjX8zyoKhx+Kj++lUs5l0Snx60p?= =?us-ascii?Q?tWe3saPfHUlaMdSRyD9TbYJrvHWRSDlzDqsS1B8oW8TOTlXfN0ztkwLVVUmz?= =?us-ascii?Q?RYlacs8banQgHHKepWaDY/zBhqEr38UyDVsgTOSuxshKEdXIquRZzvUodjc4?= =?us-ascii?Q?Fzjp87TLg8RzxRsi1yEvysw/SCJQI5KvSOi03SPvgeDfTaSECTiCrcwO5bCV?= =?us-ascii?Q?I9Lhb0XTL5y7xcflL/6pzfRXqLLQgSE8h66Nsk07EfrntPSD3tDGXIDl4PXz?= =?us-ascii?Q?+aDo6EvuZ+y/YFHFwXaRGT0CGmc5BdRncpHlGrKgmFfwbaRFMD2GJhFrSeLY?= =?us-ascii?Q?2AgUgDXlUOaD429st5YKwQclxq77E0HoponG6ZbiwJe/dmvyz4FnbxpI49yF?= =?us-ascii?Q?iwjtbvLCGHr4gfqOOb8G0tjTztar7ISdunsv7AKDUg0aMdEMzEuklf7PjVls?= =?us-ascii?Q?eEjbC3jx+YVL2vtyERHAA1T2jdVBfY+9KRIpAKG1uOfZApOBhNjUMEh2bYcB?= =?us-ascii?Q?HJC0CFhMuKM1HOOIRosP2Gq0XwJ+KQ2UPKFmhKQQF7eqoQz2dB9+qcwNv1Wy?= =?us-ascii?Q?WZ83go3us9smvbo6rpv4qOxCNhtOW1tCiAvCGDoznfLekDxsw82X0chuQOQJ?= =?us-ascii?Q?8g=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 70e40b8a-8ae7-4af6-6b46-08dcfc70f250 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 01:35:21.3622 (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: O7cCMCE1dJAHN+stJb2Axihm61cwfciiu++uVJaSeNytzJjwmz5sUMigRaD9GxrcvjRnYROm8O3cacBbH3AXYg7GOBMa+8kaC10y3+sRpyY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR13MB6158 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add support for the following EEPROM function callbacks: .get_eeprom_len Get the maximum size of the device EEPROM data. .get_eeprom Get the device EEPROM data at a certain offset and length. .set_eeprom Set the device EEPROM data at a certain offset and length. Note that for an nfp NIC, the "device EEPROM" is simply a field in the hwinfo that is used to store a 6B mac address associated with a physical port. .get_module_info Get information regarding the type and size of the plugin module EEPROM for a specific port. .get_module_eeprom Get the data stored in the plugin module EEPROM for a specific port. Signed-off-by: James Hershaw Signed-off-by: Chaoyong He --- doc/guides/nics/features/nfp.ini | 2 + .../net/nfp/flower/nfp_flower_representor.c | 76 ++++++ drivers/net/nfp/nfp_ethdev.c | 5 + drivers/net/nfp/nfp_net_common.c | 256 ++++++++++++++++++ drivers/net/nfp/nfp_net_common.h | 6 + drivers/net/nfp/nfpcore/nfp_nsp.c | 96 +++++++ drivers/net/nfp/nfpcore/nfp_nsp.h | 9 + 7 files changed, 450 insertions(+) diff --git a/doc/guides/nics/features/nfp.ini b/doc/guides/nics/features/nfp.ini index c3c282b288..5303b3abf5 100644 --- a/doc/guides/nics/features/nfp.ini +++ b/doc/guides/nics/features/nfp.ini @@ -25,6 +25,8 @@ L4 checksum offload = Y Packet type parsing = Y Basic stats = Y Stats per queue = Y +EEPROM dump = Y +Module EEPROM dump = Y Linux = Y Multiprocess aware = Y x86-64 = Y diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c index 5a45c44867..04536ce15f 100644 --- a/drivers/net/nfp/flower/nfp_flower_representor.c +++ b/drivers/net/nfp/flower/nfp_flower_representor.c @@ -24,6 +24,70 @@ struct nfp_repr_init { struct nfp_net_hw_priv *hw_priv; }; +static int +nfp_repr_get_eeprom_len(struct rte_eth_dev *dev) +{ + struct nfp_flower_representor *repr; + + repr = dev->data->dev_private; + if (!nfp_flower_repr_is_phy(repr)) + return -EOPNOTSUPP; + + return nfp_net_get_eeprom_len(dev); +} + +static int +nfp_repr_get_eeprom(struct rte_eth_dev *dev, + struct rte_dev_eeprom_info *eeprom) +{ + struct nfp_flower_representor *repr; + + repr = dev->data->dev_private; + if (!nfp_flower_repr_is_phy(repr)) + return -EOPNOTSUPP; + + return nfp_net_get_eeprom(dev, eeprom); +} + +static int +nfp_repr_set_eeprom(struct rte_eth_dev *dev, + struct rte_dev_eeprom_info *eeprom) +{ + struct nfp_flower_representor *repr; + + repr = dev->data->dev_private; + if (!nfp_flower_repr_is_phy(repr)) + return -EOPNOTSUPP; + + return nfp_net_set_eeprom(dev, eeprom); +} + +static int +nfp_repr_get_module_info(struct rte_eth_dev *dev, + struct rte_eth_dev_module_info *info) +{ + struct nfp_flower_representor *repr; + + repr = dev->data->dev_private; + if (!nfp_flower_repr_is_phy(repr)) + return -EOPNOTSUPP; + + return nfp_net_get_module_info(dev, info); +} + +static int +nfp_repr_get_module_eeprom(struct rte_eth_dev *dev, + struct rte_dev_eeprom_info *info) +{ + struct nfp_flower_representor *repr; + + repr = dev->data->dev_private; + if (!nfp_flower_repr_is_phy(repr)) + return -EOPNOTSUPP; + + return nfp_net_get_module_eeprom(dev, info); +} + static int nfp_flower_repr_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete) @@ -553,6 +617,12 @@ static const struct eth_dev_ops nfp_flower_multiple_pf_repr_dev_ops = { .xstats_get_names = nfp_net_xstats_get_names, .xstats_get_by_id = nfp_net_xstats_get_by_id, .xstats_get_names_by_id = nfp_net_xstats_get_names_by_id, + + .get_eeprom_length = nfp_repr_get_eeprom_len, + .get_eeprom = nfp_repr_get_eeprom, + .set_eeprom = nfp_repr_set_eeprom, + .get_module_info = nfp_repr_get_module_info, + .get_module_eeprom = nfp_repr_get_module_eeprom, }; static const struct eth_dev_ops nfp_flower_repr_dev_ops = { @@ -585,6 +655,12 @@ static const struct eth_dev_ops nfp_flower_repr_dev_ops = { .xstats_get_names = nfp_net_xstats_get_names, .xstats_get_by_id = nfp_net_xstats_get_by_id, .xstats_get_names_by_id = nfp_net_xstats_get_names_by_id, + + .get_eeprom_length = nfp_repr_get_eeprom_len, + .get_eeprom = nfp_repr_get_eeprom, + .set_eeprom = nfp_repr_set_eeprom, + .get_module_info = nfp_repr_get_module_info, + .get_module_eeprom = nfp_repr_get_module_eeprom, }; static uint32_t diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 77b95d2c5e..2ee76d309c 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -978,6 +978,11 @@ static const struct eth_dev_ops nfp_net_eth_dev_ops = { .fec_get_capability = nfp_net_fec_get_capability, .fec_get = nfp_net_fec_get, .fec_set = nfp_net_fec_set, + .get_eeprom_length = nfp_net_get_eeprom_len, + .get_eeprom = nfp_net_get_eeprom, + .set_eeprom = nfp_net_set_eeprom, + .get_module_info = nfp_net_get_module_info, + .get_module_eeprom = nfp_net_get_module_eeprom, }; static inline void diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c index 4ad6c532ee..a45837353a 100644 --- a/drivers/net/nfp/nfp_net_common.c +++ b/drivers/net/nfp/nfp_net_common.c @@ -2925,3 +2925,259 @@ nfp_net_recv_pkt_meta_check_register(struct nfp_net_hw_priv *hw_priv) return true; } + +static int +nfp_net_get_nfp_index(struct rte_eth_dev *dev) +{ + int nfp_idx; + + if (rte_eth_dev_is_repr(dev)) { + struct nfp_flower_representor *repr; + repr = dev->data->dev_private; + nfp_idx = repr->nfp_idx; + } else { + struct nfp_net_hw *net_hw; + net_hw = dev->data->dev_private; + nfp_idx = net_hw->nfp_idx; + } + + return nfp_idx; +} + +int +nfp_net_get_eeprom_len(__rte_unused struct rte_eth_dev *dev) +{ + return RTE_ETHER_ADDR_LEN; +} + +static int +nfp_net_get_port_mac_hwinfo(struct nfp_net_hw_priv *hw_priv, + uint32_t index, + struct rte_ether_addr *mac_addr) +{ + int ret; + char hwinfo[32]; + struct nfp_nsp *nsp; + + snprintf(hwinfo, sizeof(hwinfo), "eth%u.mac", index); + + nsp = nfp_nsp_open(hw_priv->pf_dev->cpp); + if (nsp == NULL) + return -EOPNOTSUPP; + + ret = nfp_nsp_hwinfo_lookup(nsp, hwinfo, sizeof(hwinfo)); + nfp_nsp_close(nsp); + + if (ret != 0) { + PMD_DRV_LOG(ERR, "Read persistent MAC address failed for eth_index %u.", index); + return ret; + } + + ret = rte_ether_unformat_addr(hwinfo, mac_addr); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Can not parse persistent MAC address."); + return -EOPNOTSUPP; + } + + return 0; +} + +static int +nfp_net_set_port_mac_hwinfo(struct nfp_net_hw_priv *hw_priv, + uint32_t index, + struct rte_ether_addr *mac_addr) +{ + int ret; + char hwinfo_mac[32]; + struct nfp_nsp *nsp; + char buf[RTE_ETHER_ADDR_FMT_SIZE]; + + rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, mac_addr); + snprintf(hwinfo_mac, sizeof(hwinfo_mac), "eth%u.mac=%s", index, buf); + + nsp = nfp_nsp_open(hw_priv->pf_dev->cpp); + if (nsp == NULL) + return -EOPNOTSUPP; + + ret = nfp_nsp_hwinfo_set(nsp, hwinfo_mac, sizeof(hwinfo_mac)); + nfp_nsp_close(nsp); + + if (ret != 0) { + PMD_DRV_LOG(ERR, "HWinfo set failed: %d.", ret); + return ret; + } + + return 0; +} + +int +nfp_net_get_eeprom(struct rte_eth_dev *dev, + struct rte_dev_eeprom_info *eeprom) +{ + int ret; + uint32_t nfp_idx; + struct nfp_net_hw *net_hw; + struct rte_ether_addr mac_addr; + struct nfp_net_hw_priv *hw_priv; + + if (eeprom->length == 0) + return -EINVAL; + + hw_priv = dev->process_private; + nfp_idx = nfp_net_get_nfp_index(dev); + + ret = nfp_net_get_port_mac_hwinfo(hw_priv, nfp_idx, &mac_addr); + if (ret != 0) + return -EOPNOTSUPP; + + net_hw = nfp_net_get_hw(dev); + eeprom->magic = net_hw->vendor_id | (net_hw->device_id << 16); + memcpy(eeprom->data, mac_addr.addr_bytes + eeprom->offset, eeprom->length); + + return 0; +} + +int +nfp_net_set_eeprom(struct rte_eth_dev *dev, + struct rte_dev_eeprom_info *eeprom) +{ + int ret; + uint32_t nfp_idx; + struct nfp_net_hw *net_hw; + struct rte_ether_addr mac_addr; + struct nfp_net_hw_priv *hw_priv; + + if (eeprom->length == 0) + return -EINVAL; + + net_hw = nfp_net_get_hw(dev); + if (eeprom->magic != (uint32_t)(net_hw->vendor_id | (net_hw->device_id << 16))) + return -EINVAL; + + hw_priv = dev->process_private; + nfp_idx = nfp_net_get_nfp_index(dev); + ret = nfp_net_get_port_mac_hwinfo(hw_priv, nfp_idx, &mac_addr); + if (ret != 0) + return -EOPNOTSUPP; + + memcpy(mac_addr.addr_bytes + eeprom->offset, eeprom->data, eeprom->length); + ret = nfp_net_set_port_mac_hwinfo(hw_priv, nfp_idx, &mac_addr); + if (ret != 0) + return -EOPNOTSUPP; + + return 0; +} + +int +nfp_net_get_module_info(struct rte_eth_dev *dev, + struct rte_eth_dev_module_info *info) +{ + int ret = 0; + uint8_t data; + uint32_t idx; + uint32_t read_len; + struct nfp_nsp *nsp; + struct nfp_net_hw_priv *hw_priv; + struct nfp_eth_table_port *eth_port; + + hw_priv = dev->process_private; + nsp = nfp_nsp_open(hw_priv->pf_dev->cpp); + if (nsp == NULL) { + PMD_DRV_LOG(ERR, "Unable to open NSP."); + return -EIO; + } + + if (!nfp_nsp_has_read_module_eeprom(nsp)) { + PMD_DRV_LOG(ERR, "Read module eeprom not supported. Please update flash."); + ret = -EOPNOTSUPP; + goto exit_close_nsp; + } + + idx = nfp_net_get_idx(dev); + eth_port = &hw_priv->pf_dev->nfp_eth_table->ports[idx]; + switch (eth_port->interface) { + case NFP_INTERFACE_SFP: + /* FALLTHROUGH */ + case NFP_INTERFACE_SFP28: + /* Read which revision the transceiver compiles with */ + ret = nfp_nsp_read_module_eeprom(nsp, eth_port->eth_index, + SFP_SFF8472_COMPLIANCE, &data, 1, &read_len); + if (ret != 0) + goto exit_close_nsp; + + if (data == 0) { + info->type = RTE_ETH_MODULE_SFF_8079; + info->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN; + } else { + info->type = RTE_ETH_MODULE_SFF_8472; + info->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN; + } + break; + case NFP_INTERFACE_QSFP: + /* Read which revision the transceiver compiles with */ + ret = nfp_nsp_read_module_eeprom(nsp, eth_port->eth_index, + SFP_SFF_REV_COMPLIANCE, &data, 1, &read_len); + if (ret != 0) + goto exit_close_nsp; + + if (data == 0) { + info->type = RTE_ETH_MODULE_SFF_8436; + info->eeprom_len = RTE_ETH_MODULE_SFF_8436_MAX_LEN; + } else { + info->type = RTE_ETH_MODULE_SFF_8636; + info->eeprom_len = RTE_ETH_MODULE_SFF_8636_MAX_LEN; + } + break; + case NFP_INTERFACE_QSFP28: + info->type = RTE_ETH_MODULE_SFF_8636; + info->eeprom_len = RTE_ETH_MODULE_SFF_8636_MAX_LEN; + break; + default: + PMD_DRV_LOG(ERR, "Unsupported module %#x detected.", + eth_port->interface); + ret = -EINVAL; + } + +exit_close_nsp: + nfp_nsp_close(nsp); + return ret; +} + +int +nfp_net_get_module_eeprom(struct rte_eth_dev *dev, + struct rte_dev_eeprom_info *info) +{ + int ret = 0; + uint32_t idx; + struct nfp_nsp *nsp; + struct nfp_net_hw_priv *hw_priv; + struct nfp_eth_table_port *eth_port; + + hw_priv = dev->process_private; + nsp = nfp_nsp_open(hw_priv->pf_dev->cpp); + if (nsp == NULL) { + PMD_DRV_LOG(ERR, "Unable to open NSP."); + return -EIO; + } + + if (!nfp_nsp_has_read_module_eeprom(nsp)) { + PMD_DRV_LOG(ERR, "Read module eeprom not supported. Please update flash."); + ret = -EOPNOTSUPP; + goto exit_close_nsp; + } + + idx = nfp_net_get_idx(dev); + eth_port = &hw_priv->pf_dev->nfp_eth_table->ports[idx]; + ret = nfp_nsp_read_module_eeprom(nsp, eth_port->eth_index, info->offset, + info->data, info->length, &info->length); + if (ret != 0) { + if (info->length) + PMD_DRV_LOG(ERR, "Incomplete read from module EEPROM: %d.", ret); + else + PMD_DRV_LOG(ERR, "Read from module EEPROM failed: %d.", ret); + } + +exit_close_nsp: + nfp_nsp_close(nsp); + return ret; +} diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h index a9581827f9..5ad698cad2 100644 --- a/drivers/net/nfp/nfp_net_common.h +++ b/drivers/net/nfp/nfp_net_common.h @@ -394,6 +394,12 @@ void nfp_net_notify_port_speed(struct nfp_net_hw *hw, struct rte_eth_link *link); bool nfp_net_recv_pkt_meta_check_register(struct nfp_net_hw_priv *hw_priv); +int nfp_net_get_eeprom_len(struct rte_eth_dev *dev); +int nfp_net_get_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *eeprom); +int nfp_net_set_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *eeprom); +int nfp_net_get_module_info(struct rte_eth_dev *dev, struct rte_eth_dev_module_info *info); +int nfp_net_get_module_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *info); + #define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\ ((struct nfp_app_fw_nic *)app_fw_priv) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 3afbcffa42..9837b3354b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -808,6 +808,102 @@ nfp_nsp_hwinfo_lookup_real(struct nfp_nsp *state, return nfp_nsp_command_buf(state, &hwinfo_lookup); } +static int +nfp_nsp_read_module_eeprom_real(struct nfp_nsp *state, + void *buf, + uint32_t size) +{ + struct nfp_nsp_command_buf_arg module_eeprom = { + { + .code = SPCODE_READ_SFF_EEPROM, + .option = size, + }, + .in_buf = buf, + .in_size = size, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &module_eeprom); +} + +int +nfp_nsp_read_module_eeprom(struct nfp_nsp *state, + int eth_index, + uint32_t offset, + void *data, + uint32_t len, + uint32_t *read_len) +{ + int ret; + int bufsz; + struct eeprom_buf { + uint8_t metalen; + rte_le16_t length; + rte_le16_t offset; + rte_le16_t readlen; + uint8_t eth_index; + uint8_t data[]; + } __rte_packed * buf; + + /* Buffer must be large enough and rounded to the next block size. */ + bufsz = sizeof(*(buf)) + sizeof((buf)->data[0]) * + (RTE_ALIGN_CEIL(len, NSP_SFF_EEPROM_BLOCK_LEN)); + buf = calloc(1, bufsz); + if (buf == NULL) + return -ENOMEM; + + buf->metalen = offsetof(struct eeprom_buf, data) / NSP_SFF_EEPROM_BLOCK_LEN; + buf->length = rte_cpu_to_le_16(len); + buf->offset = rte_cpu_to_le_16(offset); + buf->eth_index = eth_index; + + ret = nfp_nsp_read_module_eeprom_real(state, buf, bufsz); + if (ret != 0) + goto free_exit; + + if (rte_le_to_cpu_16(buf->readlen) < len) { + ret = -EIO; + goto free_exit; + } + + if (len != 0) + memcpy(data, buf->data, len); + + *read_len = len; + +free_exit: + free(buf); + return ret; +} + +int +nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, + void *buf, + uint32_t size) +{ + int ret; + uint32_t size_tmp; + + if (!nfp_nsp_has_hwinfo_lookup(state)) { + PMD_DRV_LOG(ERR, "NSP HWinfo lookup not supported. Please update flash."); + return -EOPNOTSUPP; + } + + size_tmp = RTE_MIN(size, NFP_HWINFO_LOOKUP_SIZE); + + ret = nfp_nsp_hwinfo_lookup_real(state, buf, size, false); + if (ret != 0) + return ret; + + if (strnlen(buf, size_tmp) == size_tmp) { + PMD_DRV_LOG(ERR, "NSP HWinfo value not NULL terminated."); + return -EINVAL; + } + + return 0; +} + int nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state, void *buf, diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index cfb5066fc9..0ae10dabfb 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -8,6 +8,11 @@ #include "nfp_cpp.h" +/* EEPROM byte offsets */ +#define SFP_SFF8472_COMPLIANCE 0x5e +#define SFP_SFF_REV_COMPLIANCE 1 +#define NSP_SFF_EEPROM_BLOCK_LEN 8 + /* Defines the valid values of the 'abi_drv_reset' hwinfo key */ #define NFP_NSP_DRV_RESET_DISK 0 #define NFP_NSP_DRV_RESET_ALWAYS 1 @@ -238,8 +243,12 @@ int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val); bool nfp_nsp_fw_loaded(struct nfp_nsp *state); int nfp_nsp_load_stored_fw(struct nfp_nsp *state); +int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, uint32_t size); int nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state, void *buf, size_t size, const char *default_val); +int nfp_nsp_read_module_eeprom(struct nfp_nsp *state, int eth_index, + uint32_t offset, void *data, + uint32_t len, uint32_t *read_len); /* The buf used to receive bitmap of link modes */ struct nfp_eth_media_buf { -- 2.43.5