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 AB90545C11; Wed, 30 Oct 2024 09:19:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7CC5A4334E; Wed, 30 Oct 2024 09:19:47 +0100 (CET) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2112.outbound.protection.outlook.com [40.107.96.112]) by mails.dpdk.org (Postfix) with ESMTP id 964554025C for ; Wed, 30 Oct 2024 09:19:41 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PtFZ+fV0a5i/GQIL2KNeE5zMYgNfsi7+vYLVureDz71csX40T0g1zVrVXkBhoXcgdHab1WOhZHOWYyk7Qlottx7m9/SQqAkC4k0jqFx8CEYrFc4hN4J8IPiAquXQkVQkIKV90jLlLtfqCbn4cGrVkNNFsSSZ2AjtJ6rZzDBeXk4S4cVdgjd06HQGirMFZjQk1VUt9gCYy340qh6OEynsgivClKFRo5zG/59nUZxXHCbC2Mv/9nu6W33wplsV9/MA/9iroxqXL5ewAieacGJhTJ5pHOQfeOD3Z+fruy4TXXRXTLUNuX5tzzpZE7KMBbxK8jX4eXJuWV0tLWYBql6L7g== 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=K2FQBExzeZIJmgzEh8Z6VIxF6qUj08M7y5LI/JZvxHx2HmwsGZ5iIKBQakQ2pmMRAJbFxE9UOU+lMhCreHyyUfSA4wW5WU4gcuTL9YZ2L8cb15AWLeRgQAEsBXLaQST+Vw7hXZH5ezyts/Q/e4hEfpchbjb14wczQqDnwZ1RjOCIYBlwk+nQl5CVFWdEvax9u9+TG2iZZzmVVihAsuAgANaXkC1TV8aHPOUORl6pqZUQDxBzP7FjgrqNfgC2yiZy0mcCEmjwVUntlCkhl0ofIL9S5SooZvKbkKqj6E0vSmPOkTh89gwp3qApjLzNtcRhmTPoDpciHjndgD91k/i1rw== 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=cA3Y7ce8UnzgTZb5Hef7z2neFaVmXkCF32xu+iODsy8hqpRO4nW8weRAoDgPd5l59AufjeHJDE1D7NxaswHWiSTXdACYfr67YZZh7t3OuWinPTVYoJ5nyhKDEoTW2eVDc1f4PZqW8lt53A5entC+g+Q8KUGwWv4vVXf+WEyhe1o= 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 MN2PR13MB3973.namprd13.prod.outlook.com (2603:10b6:208:267::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 08:19:35 +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:19:35 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He , James Hershaw Subject: [PATCH 2/3] net/nfp: add support for EEPROM functions Date: Wed, 30 Oct 2024 16:19:09 +0800 Message-ID: <20241030081910.209308-3-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241030081910.209308-1-chaoyong.he@corigine.com> References: <20241030081910.209308-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2PR04CA0003.apcprd04.prod.outlook.com (2603:1096:4:197::23) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|MN2PR13MB3973:EE_ X-MS-Office365-Filtering-Correlation-Id: 034ab31c-5014-433f-b1cd-08dcf8bb96fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?MX/w7FeiLcf5pDFPmzXTUo+ls6yYdSegnkYfVzG2DW8HWYUUQRpzgjLgOok6?= =?us-ascii?Q?HtCBzQKOpEyveXU9uJZ4p8K39DV2HUx7AU0fVrvoot7quS0J8VGegLDR5Q+E?= =?us-ascii?Q?cycI50faWWNZbboT0iQApIFr4DXQF1mA9Ji7G9T3PBTqft2yvVtS6AAYfdSf?= =?us-ascii?Q?GB9k/7YPgvgRkdV8ShMLz5dD+vwYUGOHn+2r/e2SCwCIJYAejWK2VcPndwCC?= =?us-ascii?Q?1IOLF8FTatPgw9qeOXaQ6qa5DTlpz8UMXStyNmQr8OVz8pz5ogdmwLD5Lsge?= =?us-ascii?Q?UR0+TLwWE53qZpD3ybQce51qanF5/rbJv6dLRjsqlIgvhFMO6d+i30nlqtkR?= =?us-ascii?Q?hUeFAuBW0KJt5ss10a9Me4Yh3bZp92mJaXKbSx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/f8hbqyjhvn8omHD7ZJdAnUE9zJRpGCZq+eLWnAYtOsz?= =?us-ascii?Q?wND+unxU/XEBGOXL0NF7psS0pHtzVJJCDwCJxo+SraILxoZxB/Ka/XfrmEs3?= =?us-ascii?Q?8AEpoIk=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)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?BLZWzHOQnz6ljtt441qOzbTwCcD1/6m3lq0fdIvp0pZ/9m2IW9spVJYGxzY9?= =?us-ascii?Q?LLgLOypIX2YBNzmuk2VIWzDA5CQF2hrYVd4Z/Vj33CKvkbso9cuoI4YIRRF3?= =?us-ascii?Q?F+BkYaKzvzAfhvB0GIN1qaHoCUTNCjUF1dWmdC0swB3Ns2C1kdfraAHZJgcE?= =?us-ascii?Q?sDBd+1t56cZaB20IqRXAiJkoBPYTdg2GMEGY7CCahFUjJSbQkPd9VVjA1jcF?= =?us-ascii?Q?TArBKLcMprZVDd6dmFD/sxNs6WAQIvDKcrJwVaFFA+FcF+DSKRymn7JhKOnx?= =?us-ascii?Q?0gHmRH5V1LBgmT9/t8vliNr2T1YJ51j3PxeuDgCY2FOjNGlU+x2jDlHxZ5Dw?= =?us-ascii?Q?zx+kzefKEt2QZQZTSLvvpIWXPWeUkaxZaJPsjL4sndRQ0YS+ENadGnnG4GDe?= =?us-ascii?Q?YCgP5w5K+y/4dmZyQQKnLHJzj08cbVcbCeo1i1MugB06PKCBkvChjXo/hNCU?= =?us-ascii?Q?8m0zWoQ/yHAY2OFONlQrNPfWD1hv66sUprEEvOaH3HVfpo8yGboW0UEkVH1X?= =?us-ascii?Q?76k+5BiVakjn3JdTmyFqJTan1F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?zwpSGzXBqWdJFKUdUgV2Rtc7gQuB0NgRZjwh2YkstzXPtV/8FTAgZKcwsfDF?= =?us-ascii?Q?LQYPcTVqQShS+tgGD0d9+zqA4ydPqAQ7KztVFQ7c8sWabOmK+A6xTzv11JOS?= =?us-ascii?Q?0WpIczEjQxCnFGPCpSO8alliK7sT8XIOv5ddUTja106cTjXIHz8MIMrtdrca?= =?us-ascii?Q?Wg=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 034ab31c-5014-433f-b1cd-08dcf8bb96fb 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:19:35.7072 (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: BzyT7IfMVGPCnPo1kP5ki2j61hwVbetdmGxlcoCkyfRG8bwVF8TEuo3YHTU13utC7AB5zuJuT0JUPjUy9AWpecg29sUeJl7A7ypz07VlL3g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR13MB3973 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