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 E7AB442600; Tue, 19 Sep 2023 11:58:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E91D940E72; Tue, 19 Sep 2023 11:56:26 +0200 (CEST) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2122.outbound.protection.outlook.com [40.107.100.122]) by mails.dpdk.org (Postfix) with ESMTP id 24D2A40E72 for ; Tue, 19 Sep 2023 11:56:26 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LdGq+8IF3Er24qTtzRMKx3NVH00iUe8PgimlrdoxqnhQDijKXa6gzce9CQXO0JGtIqQTZeGCUrOU9bUIGLvU1bgSO+x5b4Ao+Ph5M78f6AYLJIfWdBKytMeDCmJmpbIJrCrNXuA/2C2rogjRiwKFQ8u74K9ffn0z3EdPYxLesEAo9Jrq7oDCWjOEPchgB8CiqgowaxKcksWsdtQ3m4IcQfy9YMuh8TZrDzEudjTRJa6C1tZu1TtoV50o6701OybaojKQGIG/nyaqnOeRPtzTqFDxcGDKHXEVjs6em/hreUiEnoQwtyFIUNnkzC3yz52z1kL10WqQf/DPQ6pNudJ3Ig== 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=8EB0CoZJPmhT+HqNDv1uaAX2qkZGvV4hv4xap0ytyf0=; b=g+W5kEWafzCHb2kNZPvvA9LfkjKql7e3zSJNua2+pjSsI47ijeAIGQ1XXvNIMmsZHmfeaUGU8obOfhwoq4ocqJa1DG1MZG8DwQ7E4TQh7D47JPbWN6b6N3z+wOy01bo1YIqfTvYTdDCvR95PJc8f+HJQlAqELa/UfxsieOxAUlGkX3RHnAoMUwkElqvIxfvSF/R4pqGjzouGBDhdgVAp6C6y7lyNDhGBr2qxg5+qgRrDPOCKItKjLaERARhe2nF52TUOVOj9UTH3IepErJASBzmTq2rjS4zl5JAng9zWxKKvFiGeyi1AaB9S7kZgIS5BnbFVdxmM6jGYHXCqaiw7uA== 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=8EB0CoZJPmhT+HqNDv1uaAX2qkZGvV4hv4xap0ytyf0=; b=EUiz1wPyZaczGi6FKdbMBAbnO6HKOnGMJ0bHxW2Ey+glLOCUGbkYU9rBnIg211EAfcOdVSTxSwe+URrln8ywBUgd5tVmQw2WxegYenXAc1Gul9QLmfmXN8XJll0ts5y39CFLxGGGan5Gy3MZTpHKz5QzvOJc5NT6SL5awVjOXME= 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 MW5PR13MB5877.namprd13.prod.outlook.com (2603:10b6:303:1c7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28; Tue, 19 Sep 2023 09:55:49 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7a1c:2887:348a:84bd]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7a1c:2887:348a:84bd%6]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 09:55:49 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He Subject: [PATCH v5 18/26] net/nfp: refact the nsp module Date: Tue, 19 Sep 2023 17:54:32 +0800 Message-Id: <20230919095440.45445-19-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230919095440.45445-1-chaoyong.he@corigine.com> References: <20230918024612.1600536-1-chaoyong.he@corigine.com> <20230919095440.45445-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BY5PR04CA0014.namprd04.prod.outlook.com (2603:10b6:a03:1d0::24) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|MW5PR13MB5877:EE_ X-MS-Office365-Filtering-Correlation-Id: 54c7ed92-e675-4ac5-916f-08dbb8f69a36 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m+dZQS1QDyLCsP23FpwMx2qKIvZJ+q1fuEEQcF6nVDc/oIYPeQ3F4zxyeH6kPXyzbWl2DJOIKEhz99atkKfU7Ij/hB94Gon/tLY8CyjGkVOg3Xj27xco/p6sq5t5LZ5ReQ/YvNpNBgKD/YKuYiTCGr2kdnxzM1g/+QrFM93a/SmjQld0e3hkb9hN9jq+OMU/IQmxbI4MjHOi5/+aM3UiQz/drysGmufQ6xANyGcdvAVKl5ojTJuicLacxM55fmKxIUXgOUB9kGM8zsC7vx2jENsHtfWXT1DJWI1tCJFPZYAvUaQb3sUB3p8sa7EcAjJdkQ4G9NKlpP8RcRErwm0/Bf2YrzZeUOPub0OX7U/R2e/i2k9QCmU0Bg/0hEraRDNFvv7lfWc7uKKrMxpY7KlbytV0+gVS+2cuvyubNf0fDFu+hhyTMJ1XNHE5BiX5k7YtRviNyXMw6u0C0cZFJbZJskp1lk884KlUt1AW0jsTN9RfMzwIsu4mCE11lDw5++6CaUTneOtrxEWRi4sjcokq4toaJFBwEX22iXQVlx6D64+WT/RRH2ddK6m0vPaUCzxFw5TqsjKn7J2y1fxGhpCo0U0aFWwjPjJWE9U6IsSzmhLSHrb8SDSIw8vNpquou9+0JYOvLtKxl70z48I9IPJ/Gw8wCbSMvoK6Jemt97oKMZY= 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:(13230031)(346002)(136003)(396003)(39840400004)(366004)(376002)(186009)(451199024)(1800799009)(6506007)(6486002)(6666004)(52116002)(86362001)(36756003)(38350700002)(38100700002)(2616005)(1076003)(107886003)(26005)(2906002)(30864003)(6512007)(478600001)(83380400001)(8676002)(5660300002)(4326008)(41300700001)(8936002)(44832011)(66946007)(66556008)(66476007)(6916009)(316002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?iukpynWM8z3zAgg6sATGQFUxxhFCOpzLSX8FyTwwgvihtqAt2g3G32jzV6N7?= =?us-ascii?Q?gvPBD9nE12ZaosE7n9UDsoLC44kr12QZHx9aTV5ospN5Q8H8cVIp8C5tXU9u?= =?us-ascii?Q?cGPaT3FSgTCkWq0KyqUxGDpzwg8OTKJg34YlsgQ2VKllZgQW5v2+WP70VYqf?= =?us-ascii?Q?pPZ1lkOZpvgAEr/NYnhTSIOXxyCGGERFR12Jz97g1h7tuav2Hi+66+5rDr3Y?= =?us-ascii?Q?YwRU9oZp4xrn3lfJzLjPdyi05c21/QUlPSxwejxqUTEm7iBm4g/v9hrqbSZC?= =?us-ascii?Q?THz1heqC+pkGfKDRcd2R0X64wsN6yznEFrKjhZCMo/gHO070N9xMFyK0+Yc3?= =?us-ascii?Q?HdaKcGems1ii4IJkw0vLkDTvWOKqX1TMlFo03zlEzVpiGnaiaAs9fJQOUp61?= =?us-ascii?Q?AXg1LEjXx/4Q6hAisXQmizSfafdQU1ewi6fxjHxXwUnn1YudSOKN2RYaiPVz?= =?us-ascii?Q?G1/PCtJNSsDMYoI0n7rDKKp9WPRU4WBV025lfckRZt63WLsKExaZlPc1LO38?= =?us-ascii?Q?ippjU5sv2eLa8yOtNWAgOsTt9QESYesrr8Byc8lE+/SmYwlCndR52AlULweQ?= =?us-ascii?Q?0I4LRtggXa2DqjNTxJfv5jBEAQ7SfpPvzZjvm5SeEoPylXRyHQQ/7wPfdUC5?= =?us-ascii?Q?WK08EC/QEMEZsPEQ+e8DRSYo5+Qz1l8gsu8yu1kZ7OXkNK3IDX0pozaFqLHs?= =?us-ascii?Q?dS9FZbqdKfam5PJLJId1smBjGMBObIZXCgn87LcxdIz1qeCBdiZ6cG8R82bq?= =?us-ascii?Q?Sfbnt9DBO2t9I1QxROuVMbzIrK8ihzlH2tEgGogGUOxDcWSqIChjEA1quNrH?= =?us-ascii?Q?FVYT/1k5ppdkhuTbkO6X04QChsEhP99eCYAT2LRuTyMuj6zEzepUnFAjMh65?= =?us-ascii?Q?LwlaD/0X8UdOu91nBPde2/vkmeUy9PbFzN01G+au40BBQAGEfTu+GwbxIGfw?= =?us-ascii?Q?607xsybMufYLQOW7QcNpF/gLTYF2mM+uizQRO0cVvetYov7I9fSfcHuteDWr?= =?us-ascii?Q?CQrCiXsw7/WQrIe7yy8yEwDJtDsFwAry4RnqNkizfZE3lG0yDZ/l5JSavK2l?= =?us-ascii?Q?AwARr2zzj5nzvOyH9zR+yVkHQ9xDBRyICHYxkTSAf5LNBywOquNI1JEuZQVj?= =?us-ascii?Q?DKoQXGCfERoW8oNQ1eipLIO9vTeWatr9/51gFZtN8s0hUA/ZZnYNkAjihAKG?= =?us-ascii?Q?75H7DS8aQuYX5SbM77FU3R56MKx3HbfskiPmnRSW+SDnuQFgp5xMgKRKbblM?= =?us-ascii?Q?d9OfDM86xJdtSEwzbH37rLtSJ4ArOA4lpr7xQCfgFn0hEneBYi6yV9oqOqEE?= =?us-ascii?Q?o9Cp7WQGKg3BkALeOQXYBQ2NifwSbTjtFmYCJhyrZhyG9zxoTC3E96NUrVRL?= =?us-ascii?Q?g8eHyT3nP0UInRrnGPpPc6tyJmNfhoPrN4PuoM545/JJkC0hkS77U/f+7MyC?= =?us-ascii?Q?L+tCkyE7JqUcGZU1lMSqDFaNKm9eDEo5RoIYZTB3xF8p7bfL5nw2VfK48Pm8?= =?us-ascii?Q?tYSmZtNxXLdLUfBLq0Qrw7PtHL8XTIQTVJ54oz0pPsHA8Ym9WcFehl8bn9iE?= =?us-ascii?Q?/dX4g/lnsuiYtLK8LrDt4ozllj8kXo2kKs5t74VkVY53D4WKQD4ZM3bjmcSs?= =?us-ascii?Q?CA=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54c7ed92-e675-4ac5-916f-08dbb8f69a36 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 09:55:49.4799 (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: 6wyIRFYQ8takktfi+sjM1KLpbhcpN+ePa1z2peVC+9DYBLkDz6QufAf0GzhRi54SOGL+jxVneB/UrJ6lIGtBjKHFHxDfbNMD0kteyjHAEI0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR13MB5877 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 Move the definition of data structure into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He --- drivers/net/nfp/nfp_ethdev.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 390 +++++++++++++++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 140 ++++----- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 - drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 79 ++--- 5 files changed, 398 insertions(+), 217 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index e3ff3d8087..efb47c5d56 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -661,7 +661,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev) static int nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) { - struct nfp_cpp *cpp = nsp->cpp; + struct nfp_cpp *cpp = nfp_nsp_cpp(nsp); void *fw_buf; char fw_name[125]; char serial[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 0f67148907..5b804f6174 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -3,20 +3,127 @@ * All rights reserved. */ -#define NFP_SUBSYS "nfp_nsp" - -#include -#include +#include "nfp_nsp.h" #include -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_nsp.h" #include "nfp_platform.h" #include "nfp_resource.h" -int +/* Offsets relative to the CSR base */ +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_DMA_BUF RTE_BIT64(1) +#define NSP_COMMAND_START RTE_BIT64(0) + +/* CPP address to retrieve the data from */ +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_DFLT_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_4KB GENMASK_ULL(15, 8) +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) + +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 + +#define NSP_CODE_MAJOR GENMASK_ULL(15, 12) +#define NSP_CODE_MINOR GENMASK_ULL(11, 0) + +#define NFP_FW_LOAD_RET_MAJOR GENMASK_ULL(15, 8) +#define NFP_FW_LOAD_RET_MINOR GENMASK_ULL(23, 16) + +enum nfp_nsp_cmd { + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_WRITE_FLASH = 11, /* Load and flash image from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_FW_STORED = 16, /* If no FW loaded, load flash app FW */ + SPCODE_HWINFO_LOOKUP = 17, /* Lookup HWinfo with overwrites etc. */ + SPCODE_HWINFO_SET = 18, /* Set HWinfo entry */ + SPCODE_FW_LOADED = 19, /* Is application firmware loaded */ + SPCODE_VERSIONS = 21, /* Report FW versions */ + SPCODE_READ_SFF_EEPROM = 22, /* Read module EEPROM */ + SPCODE_READ_MEDIA = 23, /* Get the supported/advertised media for a port */ +}; + +static const struct { + uint32_t code; + const char *msg; +} nsp_errors[] = { + { 6010, "could not map to phy for port" }, + { 6011, "not an allowed rate/lanes for port" }, + { 6012, "not an allowed rate/lanes for port" }, + { 6013, "high/low error, change other port first" }, + { 6014, "config not found in flash" }, +}; + +struct nfp_nsp { + struct nfp_cpp *cpp; + struct nfp_resource *res; + struct { + uint16_t major; + uint16_t minor; + } ver; + + /** Eth table config state */ + bool modified; + uint32_t idx; + void *entries; +}; + +/* NFP command argument structure */ +struct nfp_nsp_command_arg { + uint16_t code; /**< NFP SP Command Code */ + bool dma; /**< @buf points to a host buffer, not NSP buffer */ + bool error_quiet; /**< Don't print command error/warning */ + uint32_t timeout_sec; /**< Timeout value to wait for completion in seconds */ + uint32_t option; /**< NSP Command Argument */ + uint64_t buf; /**< NSP Buffer Address */ + /** Callback for interpreting option if error occurred */ + void (*error_cb)(struct nfp_nsp *state, uint32_t ret_val); +}; + +/* NFP command with buffer argument structure */ +struct nfp_nsp_command_buf_arg { + struct nfp_nsp_command_arg arg; /**< NFP command argument structure */ + const void *in_buf; /**< Buffer with data for input */ + void *out_buf; /**< Buffer for output data */ + uint32_t in_size; /**< Size of @in_buf */ + uint32_t out_size; /**< Size of @out_buf */ +}; + +struct nfp_cpp * +nfp_nsp_cpp(struct nfp_nsp *state) +{ + return state->cpp; +} + +bool nfp_nsp_config_modified(struct nfp_nsp *state) { return state->modified; @@ -24,7 +131,7 @@ nfp_nsp_config_modified(struct nfp_nsp *state) void nfp_nsp_config_set_modified(struct nfp_nsp *state, - int modified) + bool modified) { state->modified = modified; } @@ -66,7 +173,7 @@ nfp_nsp_print_extended_error(uint32_t ret_val) return; for (i = 0; i < RTE_DIM(nsp_errors); i++) - if (ret_val == (uint32_t)nsp_errors[i].code) + if (ret_val == nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -222,11 +329,8 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, - uint16_t code, - uint32_t option, - uint32_t buff_cpp, - uint64_t buff_addr) +nfp_nsp_command_real(struct nfp_nsp *state, + const struct nfp_nsp_command_arg *arg) { int err; uint64_t reg; @@ -250,22 +354,14 @@ nfp_nsp_command(struct nfp_nsp *state, return err; } - if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { - PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); - return -EINVAL; - } - - err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, arg->buf); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_OPTION, arg->option) | + FIELD_PREP(NSP_COMMAND_CODE, arg->code) | + FIELD_PREP(NSP_COMMAND_DMA_BUF, arg->dma) | FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; @@ -275,7 +371,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", - err, code); + err, arg->code); return err; } @@ -284,7 +380,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", - err, code); + err, arg->code); return err; } @@ -296,84 +392,85 @@ nfp_nsp_command(struct nfp_nsp *state, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { - PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); - nfp_nsp_print_extended_error(ret_val); + if (!arg->error_quiet) + PMD_DRV_LOG(WARNING, "Result (error) code set: %d (%d) command: %d", + -err, (int)ret_val, arg->code); + + if (arg->error_cb != 0) + arg->error_cb(state, ret_val); + else + nfp_nsp_print_extended_error(ret_val); + return -err; } return ret_val; } -#define SZ_1M 0x00100000 +static int +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code) +{ + const struct nfp_nsp_command_arg arg = { + .code = code, + }; + + return nfp_nsp_command_real(state, &arg); +} static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, - uint16_t code, uint32_t option, - const void *in_buf, - unsigned int in_size, - void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf_def(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) { int err; int ret; uint64_t reg; - size_t max_size; uint32_t cpp_id; uint64_t cpp_buf; struct nfp_cpp *cpp = nsp->cpp; - if (nsp->ver.minor < 13) { - PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); - return -EOPNOTSUPP; - } - - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, - ®); - if (err < 0) - return err; - - max_size = RTE_MAX(in_size, out_size); - if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %zu)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); - return -EINVAL; - } - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, ®); if (err < 0) return err; - cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; - cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); + cpp_id = FIELD_GET(NSP_DFLT_BUFFER_CPP, reg) << 8; + cpp_buf = FIELD_GET(NSP_DFLT_BUFFER_ADDRESS, reg); - if (in_buf != NULL && in_size > 0) { - err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); + if (arg->in_buf != NULL && arg->in_size > 0) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf, + arg->in_buf, arg->in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf != NULL && out_size > 0 && out_size > in_size) { - memset(out_buf, 0, out_size - in_size); - err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + if (arg->out_buf != NULL && arg->out_size > arg->in_size) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf + arg->in_size, + arg->out_buf, arg->out_size - arg->in_size); if (err < 0) return err; } - ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); + if (!FIELD_FIT(NSP_BUFFER_CPP, cpp_id >> 8) || + !FIELD_FIT(NSP_BUFFER_ADDRESS, cpp_buf)) { + PMD_DRV_LOG(ERR, "Buffer out of reach %#08x %#016lx", + cpp_id, cpp_buf); + return -EINVAL; + } + + arg->arg.buf = FIELD_PREP(NSP_BUFFER_CPP, cpp_id >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, cpp_buf); + ret = nfp_nsp_command_real(nsp, &arg->arg); if (ret < 0) { PMD_DRV_LOG(ERR, "NSP command failed"); return ret; } - if (out_buf != NULL && out_size > 0) { - err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); + if (arg->out_buf != NULL && arg->out_size > 0) { + err = nfp_cpp_read(cpp, cpp_id, cpp_buf, + arg->out_buf, arg->out_size); if (err < 0) return err; } @@ -381,6 +478,43 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, return ret; } +#define SZ_1M 0x00100000 +#define SZ_4K 0x00001000 + +static int +nfp_nsp_command_buf(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) +{ + int err; + size_t size; + uint64_t reg; + size_t max_size; + struct nfp_cpp *cpp = nsp->cpp; + + if (nsp->ver.minor < 13) { + PMD_DRV_LOG(ERR, "NSP: Code %#04x with buffer not supported ABI %hu.%hu)", + arg->arg.code, nsp->ver.major, nsp->ver.minor); + return -EOPNOTSUPP; + } + + err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); + if (err < 0) + return err; + + max_size = RTE_MAX(arg->in_size, arg->out_size); + size = FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M + + FIELD_GET(NSP_DFLT_BUFFER_SIZE_4KB, reg) * SZ_4K; + if (size < max_size) { + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command %#04x (%zu < %zu)", + arg->arg.code, size, max_size); + return -EINVAL; + } + + return nfp_nsp_command_buf_def(nsp, arg); +} + int nfp_nsp_wait(struct nfp_nsp *state) { @@ -392,7 +526,7 @@ nfp_nsp_wait(struct nfp_nsp *state) wait.tv_nsec = 25000000; /* 25ms */ for (;;) { - err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); + err = nfp_nsp_command(state, SPCODE_NOOP); if (err != -EAGAIN) break; @@ -413,13 +547,57 @@ nfp_nsp_wait(struct nfp_nsp *state) int nfp_nsp_device_soft_reset(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_SOFT_RESET, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_SOFT_RESET); } int nfp_nsp_mac_reinit(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_MAC_INIT, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_MAC_INIT); +} + +static void +nfp_nsp_load_fw_extended_msg(struct nfp_nsp *state, + uint32_t ret_val) +{ + uint32_t minor; + uint32_t major; + static const char * const major_msg[] = { + /* 0 */ "Firmware from driver loaded", + /* 1 */ "Firmware from flash loaded", + /* 2 */ "Firmware loading failure", + }; + static const char * const minor_msg[] = { + /* 0 */ "", + /* 1 */ "no named partition on flash", + /* 2 */ "error reading from flash", + /* 3 */ "can not deflate", + /* 4 */ "not a trusted file", + /* 5 */ "can not parse FW file", + /* 6 */ "MIP not found in FW file", + /* 7 */ "null firmware name in MIP", + /* 8 */ "FW version none", + /* 9 */ "FW build number none", + /* 10 */ "no FW selection policy HWInfo key found", + /* 11 */ "static FW selection policy", + /* 12 */ "FW version has precedence", + /* 13 */ "different FW application load requested", + /* 14 */ "development build", + }; + + major = FIELD_GET(NFP_FW_LOAD_RET_MAJOR, ret_val); + minor = FIELD_GET(NFP_FW_LOAD_RET_MINOR, ret_val); + + if (!nfp_nsp_has_stored_fw_load(state)) + return; + + if (major >= RTE_DIM(major_msg)) + PMD_DRV_LOG(INFO, "FW loading status: %x", ret_val); + else if (minor >= RTE_DIM(minor_msg)) + PMD_DRV_LOG(INFO, "%s, reason code: %d", major_msg[major], minor); + else + PMD_DRV_LOG(INFO, "%s%c %s", major_msg[major], + minor != 0 ? ',' : '.', minor_msg[minor]); } int @@ -427,8 +605,24 @@ nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + int ret; + struct nfp_nsp_command_buf_arg load_fw = { + { + .code = SPCODE_FW_LOAD, + .option = size, + .error_cb = nfp_nsp_load_fw_extended_msg, + }, + .in_buf = buf, + .in_size = size, + }; + + ret = nfp_nsp_command_buf(state, &load_fw); + if (ret < 0) + return ret; + + nfp_nsp_load_fw_extended_msg(state, ret); + + return 0; } int @@ -436,8 +630,16 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg eth_rescan = { + { + .code = SPCODE_ETH_RESCAN, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, ð_rescan); } int @@ -445,8 +647,16 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + struct nfp_nsp_command_buf_arg eth_ctrl = { + { + .code = SPCODE_ETH_CONTROL, + .option = size, + }, + .in_buf = buf, + .in_size = size, + }; + + return nfp_nsp_command_buf(state, ð_ctrl); } int @@ -454,8 +664,16 @@ nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg identify = { + { + .code = SPCODE_NSP_IDENTIFY, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &identify); } int @@ -464,6 +682,14 @@ nfp_nsp_read_sensors(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + struct nfp_nsp_command_buf_arg sensors = { + { + .code = SPCODE_NSP_SENSORS, + .option = sensor_mask, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &sensors); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 14986a9130..fe52dffeb7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -7,78 +7,8 @@ #define __NSP_NSP_H__ #include "nfp_cpp.h" -#include "nfp_nsp.h" - -/* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) - -/* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) - -#define NSP_DFLT_BUFFER 0x18 - -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) - -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 - -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) - -enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ -}; - -static const struct { - int code; - const char *msg; -} nsp_errors[] = { - { 6010, "could not map to phy for port" }, - { 6011, "not an allowed rate/lanes for port" }, - { 6012, "not an allowed rate/lanes for port" }, - { 6013, "high/low error, change other port first" }, - { 6014, "config not found in flash" }, -}; -struct nfp_nsp { - struct nfp_cpp *cpp; - struct nfp_resource *res; - struct { - uint16_t major; - uint16_t minor; - } ver; - - /* Eth table config state */ - int modified; - unsigned int idx; - void *entries; -}; +struct nfp_nsp; struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp); void nfp_nsp_close(struct nfp_nsp *state); @@ -92,18 +22,61 @@ int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, void *buf, size_t size); -static inline int +static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } +static inline bool +nfp_nsp_has_stored_fw_load(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 23; +} + +static inline bool +nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 24; +} + +static inline bool +nfp_nsp_has_hwinfo_set(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_fw_loaded(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_versions(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 27; +} + +static inline bool +nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 28; +} + +static inline bool +nfp_nsp_has_read_media(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 33; +} + enum nfp_eth_interface { NFP_INTERFACE_NONE = 0, NFP_INTERFACE_SFP = 1, NFP_INTERFACE_SFPP = 10, NFP_INTERFACE_SFP28 = 28, NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_RJ45 = 45, NFP_INTERFACE_CXP = 100, NFP_INTERFACE_QSFP28 = 112, }; @@ -151,6 +124,7 @@ struct nfp_eth_table { enum nfp_eth_media media; /**< Media type of the @interface */ enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_fec act_fec; /**< Active Forward Error Correction mode */ enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ struct rte_ether_addr mac_addr; /**< Interface MAC address */ @@ -159,17 +133,18 @@ struct nfp_eth_table { /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; /**< Enable port */ - int tx_enabled; /**< Enable TX */ - int rx_enabled; /**< Enable RX */ + bool enabled; /**< Enable port */ + bool tx_enabled; /**< Enable TX */ + bool rx_enabled; /**< Enable RX */ + bool supp_aneg; /**< Support auto negotiation */ - int override_changed; /**< Media reconfig pending */ + bool override_changed; /**< Media reconfig pending */ uint8_t port_type; /**< One of %PORT_* */ /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; /**< Split port */ + bool is_split; /**< Split port */ uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ } ports[]; /**< Table of ports */ @@ -177,8 +152,8 @@ struct nfp_eth_table { struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, bool enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, bool configured); int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); @@ -187,12 +162,13 @@ int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); -void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); +void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); -int nfp_nsp_config_modified(struct nfp_nsp *state); +struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state); +bool nfp_nsp_config_modified(struct nfp_nsp *state); uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int +static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported != 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index f656f200f4..46fa5467de 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -3,12 +3,8 @@ * All rights reserved. */ -#include -#include -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp_nffw.h" struct nsp_identify { uint8_t version[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index eb30d8e779..cc472907ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -3,10 +3,6 @@ * All rights reserved. */ -#include -#include -#include -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" #include "nfp_platform.h" @@ -21,6 +17,7 @@ #define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) #define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) #define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) +#define NSP_ETH_PORT_SUPP_ANEG RTE_BIT64(63) #define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) @@ -34,6 +31,7 @@ #define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) #define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) #define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) +#define NSP_ETH_STATE_ACT_FEC GENMASK_ULL(29, 28) #define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) #define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) @@ -54,26 +52,12 @@ #define PORT_NONE 0xef #define PORT_OTHER 0xff -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 - enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW + NSP_ETH_NUM_RAW, }; enum nfp_eth_rate { @@ -100,12 +84,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, RTE_ETH_SPEED_NUM_NONE, }, + { RATE_10M, RTE_ETH_SPEED_NUM_10M, }, + { RATE_100M, RTE_ETH_SPEED_NUM_100M, }, + { RATE_1G, RTE_ETH_SPEED_NUM_1G, }, + { RATE_10G, RTE_ETH_SPEED_NUM_10G, }, + { RATE_25G, RTE_ETH_SPEED_NUM_25G, }, }; static uint32_t @@ -193,7 +177,14 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; - dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->fec = FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->act_fec = dst->fec; + + if (nfp_nsp_get_abi_ver_minor(nsp) < 33) + return; + + dst->act_fec = FIELD_GET(NSP_ETH_STATE_ACT_FEC, state); + dst->supp_aneg = FIELD_GET(NSP_ETH_PORT_SUPP_ANEG, port); } static void @@ -222,7 +213,7 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) table->ports[i].label_port, table->ports[i].label_subport); - table->ports[i].is_split = 1; + table->ports[i].is_split = true; } } } @@ -233,6 +224,9 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) if (entry->interface == NFP_INTERFACE_NONE) { entry->port_type = PORT_NONE; return; + } else if (entry->interface == NFP_INTERFACE_RJ45) { + entry->port_type = PORT_TP; + return; } if (entry->media == NFP_MEDIA_FIBRE) @@ -251,7 +245,6 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) uint32_t table_sz; struct nfp_eth_table *table; union eth_table_entry *entries; - const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); if (entries == NULL) @@ -264,16 +257,9 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) goto err; } - /* - * The NFP3800 NIC support 8 ports, but only 2 ports are valid, - * the rest 6 ports mac are all 0, ensure we don't use these port - */ - for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) + for (i = 0; i < NSP_ETH_MAX_COUNT; i++) + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) cnt++; - } /* * Some versions of flash will give us 0 instead of port count. For @@ -294,11 +280,8 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) memset(table, 0, table_sz); table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) - nfp_eth_port_translate(nsp, &entries[i], i, - &table->ports[j++]); + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) + nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); } nfp_eth_calc_port_geometry(table); @@ -440,7 +423,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, - int enable) + bool enable) { uint64_t reg; struct nfp_nsp *nsp; @@ -448,7 +431,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) - return -1; + return -EIO; entries = nfp_nsp_config_entries(nsp); @@ -460,7 +443,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_ENABLED, enable); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -484,7 +467,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configured) + bool configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -513,7 +496,7 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -551,7 +534,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, entries[idx].control |= rte_cpu_to_le_64(ctrl_bit); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); return 0; } -- 2.39.1