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 9D6B241FC8; Wed, 30 Aug 2023 04:18:16 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D3A5140A6C; Wed, 30 Aug 2023 04:16:05 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2114.outbound.protection.outlook.com [40.107.93.114]) by mails.dpdk.org (Postfix) with ESMTP id 0108640648 for ; Wed, 30 Aug 2023 04:16:03 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QP4u41sqCM9stoorhFzgVQHbxw2++g7OlNxE45H1cMl0XYeO7ByompC/Ht63IrlHUHeubdGvko+Q0GZdDe7d3OhukQMoVOEJLswBPsdwRz48xfakM6tZ2986dLg7RaEc459Ixw3wfcOqCgFW0lm7U6+U2xUfYN4KHTwXkH0MtKfCfO2CQqQubcktMzIHwBQL5+cNTB8qQqdID6KxHAfR2C/IJh7KMaPcrX07rT1VS8NskJs+mgBYfrEazLsDDyilzu7XnnR8RAWg0Qi36X5VtVVucTWzxLPJJv2B+TQJ7unzjXMr1o5FtqSWc06TfzdBb7B5QBh6DU94pzKwO/vfkg== 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=dwbTUNDx+Fw0Bi1dx6A9Yef80m7zk+EhZGBn/xlqfbU=; b=dExZzOmoMRQFTOmya6CXQKLCFHxBe+rTDB9PkGBbcZ/tUBZdvHt0K4KcXDT2msNDLv1pkQhsz3ZGb1GoSYR97p5EYGSD3FlJT0GgG+IAScp8P+G6Eg9TyhLD8WkiOjpPgXc6H6ZheWOfIji10vgsYsQm+kIS05cJ/6KUpIZ84UunaJEvkZweDYaixx3nfmMPoNtfRCHIfR8B9W1zP77/ovyHC3QTz0YxCZfV/PjzGubyZaau/z3ITg80f86W3rKmhJyHOeE/zYJ9pL5XkCkh94cRhrLNww0trx57HFxJIsTXa8GU8ZAUcUG6EZGcTBFqMTivdVYBfXZ+9P0m1v82XA== 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=dwbTUNDx+Fw0Bi1dx6A9Yef80m7zk+EhZGBn/xlqfbU=; b=mFpfXMBEZ9bh9yHqLF3tYRoHa49Rg7efwFSvLoBQXyQXBScHyy+fqZgsMCWiNlpzbT2+TiOH0Whcq6eVKM1F7r4srhJMQw9NeQQKb2ApaFQV4auDkgXGE4anmULJrBcGLucARNwp1jCyfWf8EPAHi6hWWv2pYywfIo3n9/KLzSE= 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 DM6PR13MB3786.namprd13.prod.outlook.com (2603:10b6:5:229::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.18; Wed, 30 Aug 2023 02:16:00 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::c0f3:c2cc:b5bb:4192]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::c0f3:c2cc:b5bb:4192%4]) with mapi id 15.20.6699.034; Wed, 30 Aug 2023 02:16:00 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com, Chaoyong He Subject: [PATCH v2 19/27] net/nfp: refact the nsp module Date: Wed, 30 Aug 2023 10:14:49 +0800 Message-Id: <20230830021457.2064750-20-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230830021457.2064750-1-chaoyong.he@corigine.com> References: <20230824110956.1943559-1-chaoyong.he@corigine.com> <20230830021457.2064750-1-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: PH0PR07CA0113.namprd07.prod.outlook.com (2603:10b6:510:4::28) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|DM6PR13MB3786:EE_ X-MS-Office365-Filtering-Correlation-Id: 6123bd94-36e4-44aa-863d-08dba8ff0db8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5OBb407Na7NNfNwo3HKIMiYeeBTs6TUCaAaQCaS3xSat7SU74XJw29YLUHCZLmkD5OyQK/G7Juo2U16uXYNCNh6ApFpOf7jh9SVzRdTtL+1uoP/BYEHfnkqQ0Gz+tA3FkGC7Q1OQeMKu5m2woR0DE5eDMSPPenBqoxqPpAByw5NoKYytiT7l9BGhg0xjEo3kForngT7yhmdOHH2tJgdvsHBJseHUZxtMec/8N2Dse59VT2SDE7Gj6mv0xGpsSllbEleP5tSOJbRDJ0rlvGJRrBTBFU+vfNTpMrQg474kamuZoXUrb7HhVraEC4mipUxKz/X2ca+waItm11oXA1tw3ffBid13+u2iqDDD6L3sOy5Vnlegx1Vwc/1pgkMiVozZVuZKMvehQFqsOPKelca6JYAYkQA1MxpCDY78CDGFXLvEwF5AlrspzxArtc0jIa4ebYkHCvpJIhKhP8+11f1bVr59/hgucUJ7cJ4TsDEee79/GEab+0F26IJbjUVFuMuC6ogdS9uBR7b36lh0Jlh3rYO04QLLWQZVVCuhEqr+PHDXlHg3ijqAG8yPzFnrnelzRAUyC5Fg3yqYO435rst1X2OQIZlm2yNzeK2m8srGtOj/oChzJ6xT9Yo0fPuJoA44b9N7kE4njbhg1DLGLl4rU7w4tCJRLZdwLBOT2m0J0rQ= 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)(136003)(366004)(376002)(346002)(396003)(39830400003)(451199024)(186009)(1800799009)(6512007)(6916009)(316002)(38100700002)(41300700001)(38350700002)(2906002)(4326008)(66574015)(30864003)(83380400001)(2616005)(86362001)(44832011)(26005)(36756003)(1076003)(8676002)(5660300002)(107886003)(8936002)(6666004)(6506007)(6486002)(66556008)(66946007)(66476007)(52116002)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?T3RXcE1iYlRZR3l3d1NOK2VieFJIRytEM0VNRkJNUE8rcmVhOUx0dTdnOUJR?= =?utf-8?B?ZDk0RU9hMXpmTW1UMFlXVk4xOFA5TVBVNjR6K0EwNDJGTy83UmZaaUJ2dXY0?= =?utf-8?B?eHZjSnJHc0VyNXFoS2dncXQrOWtiSjFBMnRBc2V1NjFqMXhpS0lEbDZzN2FY?= =?utf-8?B?b3EzWWlJOTVETFM0RW4xNTJlRXN2VWtGU2JhY1VSLzVnZW5UVDd5RTlpa3pV?= =?utf-8?B?R09WWmxKZTdzMGt4eHMrR1V4L3g5NnFEb1VNUjZMMEc1V0lDMG5UNWhISUls?= =?utf-8?B?TnBZY0RiWjVjVktMV3hvai9sZW5YVXhJYVdQYXFBVTFMZndMUjI0WGRZUjNn?= =?utf-8?B?b2hXMEhBUnFQcGFzL09MRkxQL2NEc004RzA0YS9ZVDNsTDdLYU5ZUTF2V1hh?= =?utf-8?B?YUo4M012bkF4YVN3alcvRmU3YkN6MjBaTlc1a0FpUnlKc0UyTWNiZXlEREpI?= =?utf-8?B?ZWRrSnlRNUNxWm8raFppbjFnUm5rVmUzRWlyNjROMmpUcHJpRFpueDVlOGxa?= =?utf-8?B?OFZTWk10M1FjNThoeFA1ZjRXNFUxK2dsM1VwMStDajNHci96bS9KVFdTcEIy?= =?utf-8?B?RVpndFk0UVgxK0tZUjFXUXA4VDl2Qy84d2xsUkZUWVhXVHNSeWdZQzFJTlpK?= =?utf-8?B?OGZqNngvcDJDaVF2SUVUbkZtSmxXc2ZHNG1RK3JXYVBuWnovTnBLYXpPQU0x?= =?utf-8?B?eHM4ejBNVWV3KzIvTTFUWmxaZEhYVm5RTDhHbVZJK2VyUGRzS2FyRmdja1Bh?= =?utf-8?B?OXg4SUlEZURHSlpBVnNXY2RocFljbExYbXhrUzBJaHFudEllQnVPN01KVTla?= =?utf-8?B?V0Qybk9JbTQ3UXNtai9BWWdZdXExcGZEMDNiU2tkeHFUUnNBY0QyMHhBRlFC?= =?utf-8?B?eVlQRzhkeStwcklWalBvUlZPRlFkUUVXblNhU1NhaDVBYXRqTWtiZkMyRkQ1?= =?utf-8?B?QzQ5SmxhQ3NOM3d5RlRuam4rVnBRc3ZlcEdnVXFIajNjNm81T1JUWXpidUpO?= =?utf-8?B?NGF3eDhQd3Y2S01URmtBKzdkZ2M3RWZYVlNJZjlIYnJIU3ZMZXRoKzdxSUhW?= =?utf-8?B?cUNyQzhTMmNRUjBLbUI2ay85RlU4VWtXWE5RUjFCSFQ5TDFLUlpxWTlqWjZI?= =?utf-8?B?NkJ3VXRwdnV6R2JqU0IyN2xNSitmRHZpYU9YemtqZVd1bW5OZDh0TmlPVUtv?= =?utf-8?B?MDF1U0ljbEtBRUlaQlBMUXVUbnBOaWJ5OWJPdlFFc0ZIVWdQQWt1cHdVMC9k?= =?utf-8?B?YVovNWxiYWp1cVR1dFNFSXVBZnBMTExDQjNPdTZaYlY0NEtyVG1IbUtjTGE2?= =?utf-8?B?ejNYQ0Vrd1hhUFUzT0JNTC9rWktSYVBqVTdBQVg4SzRFVm53bTZ0RTEvaWRH?= =?utf-8?B?Q2JNWmZzcys0bERPUUxGTktKT211R2x2bjk3QWMxdUdET2M0TVNpV3N1YTdM?= =?utf-8?B?OVZCc2dlRDFoQllEeEpRMlIzcnZacVlvdXBOdVhXT0N4cVNJQTBWNFZkM2Q3?= =?utf-8?B?WTIwYTYwR3haY2kxODVxUk9KdmU1dTJwbDNXREVoSUZhL3NneFpnamppamhZ?= =?utf-8?B?bWk4Qk01MnpiNFFjcEVWZjdGZ3d4U3lFVlV4RHc4YzhObDBXbzVISEJTUTFD?= =?utf-8?B?WjdsNGlVV1dRcDVqSEpWdWF5WXhTKzdHZ291djJvRHFDY2FjQThMUGxGNGVu?= =?utf-8?B?R2Z6T1g2eVBGc0N2YWxPQUxWeFdnZFV6U1BPYTZRMG1hS3ZRL2FTK0hwSm9y?= =?utf-8?B?b2xJSkRCdVRtQW5LU2dUdzZTRUx1UzNtUHFYcGFSRWxPS05jNFdLZk9oRUhW?= =?utf-8?B?UVgvb2tHb0JrTFZLVVk1V25MaSt6RVc5UVVxUXJUbjhkRnRiNDZCVUlqa1lu?= =?utf-8?B?MFhsblhFNVQwSUlldXcwQWZHd1R6NUl2UHR3dTRydEtZUWdRd1AxaGlaUTVV?= =?utf-8?B?amJrUy9mNkhwcFJHd09VWjJLN1RHVGhMOFVIZnZNVTNjaDJrdkI0dzhTdmxO?= =?utf-8?B?WEhMeTdTSDUzdTV2d01heWZvZzZKNUtIdnlPbHVyYU55MmxUR2ZXbXBORXZG?= =?utf-8?B?ZkRFaC9jRkZjUXRKdE9SM3dka01RY1h5cmV0TkRFNXg4MC9WTk1JamtmYnpo?= =?utf-8?B?UkpzbjdlZHpNelRmcmFoQzU2cWxoT0NQTEtVNk0wVW1RVWEyNS9HU1lGek5H?= =?utf-8?B?M1E9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6123bd94-36e4-44aa-863d-08dba8ff0db8 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2023 02:16:00.8961 (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: bp+3+j89ci8x8vZOEsz03+nQabVSHurHJlJ38hn1vyIY6EdpB8DMV1oJUR7+YsSvt9Bnd9T3bJwOYai40aqJuqcRYYSn3CQPHPNDr7+SgrU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR13MB3786 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 Reviewed-by: Niklas Söderlund --- 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 2e43055fd5..9243191de3 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 8e65064b10..75d13cb84f 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 < %lu)", - 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; + uint64_t reg; + uint32_t size; + uint32_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 (%u < %u)", + 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 429f639fa2..86956f4330 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 355d907f4d..996fd4b44a 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 @@ -192,7 +176,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 @@ -221,7 +212,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; } } } @@ -232,6 +223,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) @@ -250,7 +244,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 = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) @@ -262,16 +255,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 @@ -291,11 +277,8 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) 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); @@ -436,7 +419,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; @@ -444,7 +427,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); @@ -456,7 +439,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); @@ -480,7 +463,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; @@ -509,7 +492,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); @@ -547,7 +530,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