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 7579845C11; Wed, 30 Oct 2024 09:28:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2DA0A43379; Wed, 30 Oct 2024 09:28:35 +0100 (CET) Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2099.outbound.protection.outlook.com [40.107.101.99]) by mails.dpdk.org (Postfix) with ESMTP id 6984B4336D for ; Wed, 30 Oct 2024 09:28:30 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NSfSGG9D7Y7MVnOhPkmHtN++dWHFTppHeE+l70Z11QQ46BPnXlpHUi1s8+NDBTIOjr/Fzjg/0810MRzRYdc/Cer5k5aEMAXOpL9m1WBaRfR9A6z58nzYHoE71GklQCnDIJr7xgYVLeP4VfBgJXTK9F/zOJY+dGefWC8V/QMmto0a3Gq/5LTOL4SFQAorAcwp3bVB8+ie43uNRXf3DzMVvvPZqXRxziaYS2kKQzuWp++S/3a+oFsf3MX/foJdmMFD6D2quTw5AJOn/GMTZ9NQ8+KexmHk0C9pr4oNES6M9+mEJ7JZNTX04QYk3R2InaI4+Lcib5GKF/2Y95q0nG0EDg== 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=h6Cx6m4ZepnZMjQuwtE1K/BQgYPWbbkG1ZGBeMC6BWw=; b=TGRQ28jJEQbU2bzw99zIxfBWgASEVrbW5fKYg5z8BEIUUcOVLxHf1D7pVq32G1JFAJ4fo03fa601t9zp5eDvGvRtocQ2qe9+V7i74i2vnpu6KwGIuCGoW8l9L9NI5KVzBsSI4O1+3nI+g33g9eJUz61ERJhoxW+Tpsm5YCOesP0XrOsTyjWKYcm4Qp3VjePwdcv1xomz+uNEi6u0u3CJpXcSBpeD4rrPxzVsE+sctWnVqUewbFFHqsq48Y3a8oVk+Oz3i86vs2pXqB1w8Fru8hx9R5yWsVJfefEGKr5Pi70h/r38iKOBCntz6tcnjgu/bpkvQwGrE43nRA9M+HXwUA== 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=h6Cx6m4ZepnZMjQuwtE1K/BQgYPWbbkG1ZGBeMC6BWw=; b=mZZ2gbWFNMPP6M/4g6W+ektTiUu6zeHYD8Irk2YQad9VA3cH6fQYhpXSNoz4R57hGRI5BGQB+v2cC0z0mMH7q7z2jv5b+lhlG4L669Oom7i6+Nu9tyuMaFUTL+E/BrkIfzTMjE40CYyK8XV/sXwPsMe/slb81Xoo8YXXJR2pig0= 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 LV8PR13MB6775.namprd13.prod.outlook.com (2603:10b6:408:233::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Wed, 30 Oct 2024 08:28:24 +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.8093.027; Wed, 30 Oct 2024 08:28:24 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He , James Hershaw Subject: [PATCH 3/4] net/nfp: add support for EEPROM functions Date: Wed, 30 Oct 2024 16:27:58 +0800 Message-ID: <20241030082759.209617-4-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241030082759.209617-1-chaoyong.he@corigine.com> References: <20241030081910.209308-1-chaoyong.he@corigine.com> <20241030082759.209617-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2PR02CA0120.apcprd02.prod.outlook.com (2603:1096:4:92::36) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|LV8PR13MB6775:EE_ X-MS-Office365-Filtering-Correlation-Id: 4704fcf5-8fd7-4164-d85c-08dcf8bcd1f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|52116014|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?etwbQrNhqn3BI8oETcE7s8hAfmY7FcxAAyE7Tb3wht181GBf+QbzvD9bNttf?= =?us-ascii?Q?yylsCReI2D47jimIe/8XM+eJN6eR/fJB55tEevFfgUo6vofuOENuuceyywK5?= =?us-ascii?Q?xY2Py6/cJcvcCyDavWixV1X9Gj2+hYQu8Lbm7bymWtRNtuFAfCdXRnnEStai?= =?us-ascii?Q?t+5ZvQV1wdyhnXjcfsdaj1Pi5tMH5jduTsJH3TCRLKgJuCnzs3N5uszM3aCC?= =?us-ascii?Q?uPUGeQRUbOPoVkBL3xUbBamRmDMLIpjA1Om8/zQ4pgZV8l/jumUoMAwQXnZw?= =?us-ascii?Q?jilPaeI/tc9Cfck8taC7Pg+izLA/A5BJFsco+sUwxqYkaMnjiMR4gPUCS2Mu?= =?us-ascii?Q?Y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RHcyY/8g7f?= =?us-ascii?Q?NvF3l30pz/1hO+SOlZTjOyZ4ge+JSECnW7S8jaXZLVEsQY+2UO8L+R6mFGHB?= =?us-ascii?Q?mUkiQC40r4omKA7AmjfI13k6WoSSuS57GqiSC0l7L7Izh/PeSkl4vWmKts8L?= =?us-ascii?Q?j/jJXCU=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)(366016)(52116014)(376014)(1800799024)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?QzH5wj2oLfEIWxNV3rqyVRqm/JeiIAnJgwLBghn8RcZNtpBwNT39Q1GTwDMl?= =?us-ascii?Q?bGd5xZoyFut7RCGGHvl34qZKDxkWw3HS5HuhVoh4TX7gTGinFKWnkgnhz3+q?= =?us-ascii?Q?c4pt6gmUsBYDicinS48FOpbvIBpNakDFJ7j7pztyuwwikYxrqs8Rg4s2t+kU?= =?us-ascii?Q?t8XucVrXfX0/iBDYGLDiLx2mkGwwKTaZZrjC2rg/u3GWEAwmkwTNZTme+QbN?= =?us-ascii?Q?ZLbE08VoQiuuF4msfudXULnpS3obfkvMYULiywiPKuILCxwSXb3fbE+ayu6F?= =?us-ascii?Q?9CdCbzv0NML70Ue/0oServv943z/1qtX3AwIToatNuGGENrUgCr1ZU90pXKT?= =?us-ascii?Q?evwPpXW8Nsadr4GzL6PHgZTZfFqCDlb2ryWgarkK75PSLUGT91VgkmghWsvI?= =?us-ascii?Q?N9I91lFmIq+lF/nWaVTz/1tX5NGSxr/tBQ+wCm5Y9dNa/w6ahp9lpquxdyXd?= =?us-ascii?Q?n7Gu0QtoLmnlxEryPFjOL8IrUHSG0L8Q0kcfzCfOWGahqFbxP6X+IdMp2Jlr?= =?us-ascii?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zawprk7IWXBJtl4UmcJqqt?= =?us-ascii?Q?BjVNZMtZ6DYFQ56kTpDxz38gLlWBB43Kp91V/Blv3OiuNY7Wxom0lIpDhK4r?= =?us-ascii?Q?HJyrSC9JJ6vTamMwAO9awpcRL3GbJOp5Z1828BpamjDbe0IoLTYuoDhUGjH5?= =?us-ascii?Q?vEJO/g49KMPXtjm8Egk/T8Y//7kSmE6zXKNNVw0MVjPBnKQmNVP9dcuu440s?= =?us-ascii?Q?4Q=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4704fcf5-8fd7-4164-d85c-08dcf8bcd1f3 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 08:28:24.2542 (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: QU7nFh1Us0I6D8HDhgc4L91q2C65UwMHlZndLXS0+c+moLaqaeM294KdpZaQuCD5NgqUoJmO54fwSwo//z93JmlwPZbWkzAraZkMk+VujEw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR13MB6775 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 --- .../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 + 6 files changed, 448 insertions(+) diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c index 8efef482b5..3d043e052a 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