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 C18CC45C22; Fri, 1 Nov 2024 03:57:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8B193434D0; Fri, 1 Nov 2024 03:57:41 +0100 (CET) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2137.outbound.protection.outlook.com [40.107.220.137]) by mails.dpdk.org (Postfix) with ESMTP id C25C743497 for ; Fri, 1 Nov 2024 03:57:38 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CerZKl6qaDIEJY1Drc+33jOonmI+xYDaVh/0riLRuap5AjwwOYIxMwlW4rNa2jSdA5wFOh+AUEEhBnHimZ1Y9fqqcNJpc9Ib0y15TJKfnS2/Um4TUu1cyOGVdvBayyDMNwiCLEBFwMwiGNfau/S4ZgZndYtpF8bF90oOBBsc/DCAe4Im9wn+c5nc3oTggVlPGYRu7aumX/hKzBUweeDcSh5otGBLylEX9K9kijpV4xPcqa0SCSZNWq2uL4kv+vS/jgOuZ62n/+hJMq0hEL8hJO/H/jaWSO5re29WBYfUJlDaXy6/TY1/qJ7/MtE5UFy5G7pJgIlpSvb/LNsNFIgR+w== 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=1HpEFAs3go4z49Z/xKNivnjBe1VhiKryiPaY2RmNRjU=; b=HTOfJp7YBfLk31WljWJ0k5QjuFmdv76bBq24SvYDmd5xEvccukHLqkHHfCQ9CPESQvnwpLFttMemISwz7KolwjZE4kGmycwLDE3ZnietVveFk/+YAsRwVizJYx2hA5vUrnIiRlYuVCqGdIAgBKtzZLiXCcnDMlcUS62OQCemOMC7TuC68N8dTtojlvsC3bIQuUxKuO/trkNXMoLcPCs7nFvGIQek7IkIGzEnTsr/4EZ2cOzTRbg2BnWqoewdKqzRvmNny5X7EfIzKcPitjPgwiK5ZFo15MV8CcPt2boxczbVLwlfX2c6aYegrgagAqgJTAjiRTIQJqhQHYzZem6PCg== 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=1HpEFAs3go4z49Z/xKNivnjBe1VhiKryiPaY2RmNRjU=; b=FzhMu5jnskPAO3fxcXG+eJ+tluYXmrGJJI2HMkiy4OtYpvFhL1XdeLlGopLQBrqsq2pNYBhKjAmYUxKdQVPOKl4f8w13Wce3FpNtwcL0eeXCSrAzfi72ifcWEIQXhrZcuGkoKePX7x2h5Bz/K45rmarZJEsT7M5Bk4Yl4vunNm0= 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 PH0PR13MB4891.namprd13.prod.outlook.com (2603:10b6:510:96::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Fri, 1 Nov 2024 02:57:36 +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; Fri, 1 Nov 2024 02:57:36 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He , James Hershaw Subject: [PATCH v3 3/4] net/nfp: add support for EEPROM functions Date: Fri, 1 Nov 2024 10:57:12 +0800 Message-ID: <20241101025713.290462-4-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241101025713.290462-1-chaoyong.he@corigine.com> References: <20241030082759.209617-1-chaoyong.he@corigine.com> <20241101025713.290462-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TP0P295CA0031.TWNP295.PROD.OUTLOOK.COM (2603:1096:910:4::12) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH0PR13MB4891:EE_ X-MS-Office365-Filtering-Correlation-Id: 095e1f36-6383-425d-7fb4-08dcfa20f0a1 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?biyDcipj4oKPWUDfmclPdc4rRJfK3eO88DshZWkkyN+8SujZCzKv4tVcPwkf?= =?us-ascii?Q?crW3MFCdtETHt4Zz+T8WuSQ8cR+S0umKtCiK1pOsSHacgUewKrXWBWSEsNP4?= =?us-ascii?Q?Kf6GVsrYBnnaGFwPbUatq5Ul1q/bKR+WiLluNF97W2TxtT2InDKlBLJEdK/C?= =?us-ascii?Q?XUzgtGXQBu6HaHFNVdpMcRrUaypjVf/UTAyGNbZEcIFkf+b4U6GiwD/yg7g5?= =?us-ascii?Q?uSwPB/NLT192bcsB6W+76MAxammMShz/60Gxb4jgmpXH+MA7TMV1WAY3DmuH?= =?us-ascii?Q?LZYqSvyPFqZ5h+4XOlvN+m/7+ig+HLTkXkF/7CPYi5iOX25o7jWjvnaKsCO/?= =?us-ascii?Q?9aW5IciqnAbWNaDMKr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ascii?Q?a6ODZIU9Cno2ifIMNBH+J5qxWRmI9HJ3/dQKC5onxehzwCN9pbTXJB6huxTh?= =?us-ascii?Q?bagtvoTIFfGyCxhT7V3i1S4QTr0LsTPjmqjUpbgQy1X1QEHsUtM7LkaNxTt8?= =?us-ascii?Q?AR8VkUg=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?7UIuey9TadYFxjyhO6y2/K0dwZgiZi4Z4AjlMesQV1pk77z8mOfM7hvGubjj?= =?us-ascii?Q?LvajYD/pbF6ZCQQ/HmivxfbZKo+HO0akNXjXwtwcgQTW2sWkLoIE9QRWbmpo?= =?us-ascii?Q?3J7vj58EimTt5qTs8PoobkWDtVMURdsv7gC0TP8vPXoakrtf7tNmclGe5CZS?= =?us-ascii?Q?xtpYXKMfwN2rkrKa1uXoaBDOOT/hc5KcODPoLXuLGNCBmI+BCWJugKw2Xact?= =?us-ascii?Q?0usZ3ULEAkD0fQA3GBP4sah5775xoYjOgdenp4HYQARNfb26edZBk/r9101n?= =?us-ascii?Q?lFTrw/Bv1Zb0QN03y7AIqrRuTCo+Gb6/lfZaMhB1rukJME97M8bqc5KiT/79?= =?us-ascii?Q?FOTnlRn38MCaMHIyCW3+MUR0xgY9Qu39hsgmz3O6Sf5iRwJL6EuHjXPferLb?= =?us-ascii?Q?JTEsWKcmVih/t5aYU+yT0+GDhJNvInlpBAHytdFMGkdl0A57gb/kK8UDYXUP?= =?us-ascii?Q?r4Kfs8AM/6V9gOedDdKBSicGCqYJ5qgZ1E6g+rX0R+lO2F9ZwsQusx7ruFpl?= =?us-ascii?Q?9C8bropUHpF41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X01pmRMdI9CfHC?= =?us-ascii?Q?XvdTPYW79zh5iAsaRHOiAxXxwAkTh9SbP5LfZJpKllLOBKw+6q1eQFIt6FQS?= =?us-ascii?Q?kEAQrDjkXi8RwpiU+g86nw46tWPlqgCMUQjsKJj81SpPehOJq/Dx5UYjDFxw?= =?us-ascii?Q?65vBi/e5LXAGQTSCRmn5KC26syhuCTbCLdRaL0suYN9YPjKoDuFYkU1AO0db?= =?us-ascii?Q?Yg=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 095e1f36-6383-425d-7fb4-08dcfa20f0a1 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 02:57:36.5147 (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: Rl546KqjKzOBCuuxmOPbmoErTsniYsTz7QsjNDLnh+KmeRoxBUtMeMndOmTxCnwtmVSh7Rvl+Jvf3sRKWYwnkCJrt8xwpxfoeMLdx00SXKY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB4891 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 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