From patchwork Mon Sep 18 02:46:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chaoyong He X-Patchwork-Id: 131552 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2E34C425C9; Mon, 18 Sep 2023 04:49:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0E382427E6; Mon, 18 Sep 2023 04:47:49 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2130.outbound.protection.outlook.com [40.107.244.130]) by mails.dpdk.org (Postfix) with ESMTP id BD23941151 for ; Mon, 18 Sep 2023 04:47:44 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mCtrg/qMMOPV7PEoy6WlukvJ6cbocmYNgelxsLTX5w2Llgvs4QQLPcJkGaz8LHOVZhQ3O4UPp7sQBM40s+YAyb1P7Z5OUfWig+tgZhJWKzeV6p+CY38/ON8NY+MNOpCk0GxU3mkhBYK/jVZ3KiXemdVwiNMPDDidBOWBiv7+m4Zze57bn+EKABRQXr7sutlfkcLuBHMmQvrsRf8aad5/IKivIxeBjcRHI9lNorfNekBpR+7MKiHFutvgT4WJVEGdKwNRxXwlSp5ocoqWARZ2SpwUW7/v3Bm7mpzk8zs5mrQWWQ7vtv4/20cwuO9ZdrLaKiorSph6JKVlpXHfsvcOEw== 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=XwuB+/ZcSFenE1ezj9T79WAgZ8s+szB6iUQxlLJrhf4=; b=mPdniAJdGXDmBCRVu7mmZ5x0CyVJgQfy3XHJympWynz+A4glU7kvin/7ueiyo7EoYpxTpI70tiCoQoJw56jfwWvzpoIuYVvypdT8HEUzkxls9DNsay3abvZf0ZXtM3P6mYWU2SSGpZGy2+Ua42F1VGB5DhUA0YLuJogKZ7qyver6d7TOe+fEzwWdv4GrH/qto2IlKhwZZ2s2v/VC5MiUhUHQGoLXkBGSkNHWiTrJzt/7J31TE0FFbzbeZGR3qiVnSI7JM1hXupFfj5kOc50BFJ2YUnf3QiIBo/K+J9qBARSBL/ZMGp1pzFlF8nTNl5gGpnErzg8Mj7AFIPbuOcORxA== 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=XwuB+/ZcSFenE1ezj9T79WAgZ8s+szB6iUQxlLJrhf4=; b=l+4t2C34dYAI4kCnyesPT+f25xsFCyCQ3kvkU4kPVW9QuKfbMi9cXjOtTyE3IIrx2mRes3LQ8lk1IkGa1DsiBgdfYV/n7c4+dF92GL3bXccz8TmduvSKZdXUsgiGZCAGWqxRYNNiSqfmG1SUeOwpfQK1aL8FrasVOdikn+38+F4= 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 PH7PR13MB6435.namprd13.prod.outlook.com (2603:10b6:510:2ea::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 02:47:42 +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; Mon, 18 Sep 2023 02:47:42 +0000 From: Chaoyong He To: dev@dpdk.org Cc: Chaoyong He , =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH v4 18/26] net/nfp: refact the nsp module Date: Mon, 18 Sep 2023 10:46:04 +0800 Message-Id: <20230918024612.1600536-19-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230918024612.1600536-1-chaoyong.he@corigine.com> References: <20230915091551.1459606-1-chaoyong.he@corigine.com> <20230918024612.1600536-1-chaoyong.he@corigine.com> X-ClientProxiedBy: SE2P216CA0016.KORP216.PROD.OUTLOOK.COM (2603:1096:101:114::20) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH7PR13MB6435:EE_ X-MS-Office365-Filtering-Correlation-Id: 186be7fd-73e0-42e1-eddc-08dbb7f1a143 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Uy+bA9a6bXJajkcGmGiQtOAOZDDcVpa8P7K/DrR5ZWNIFTId5zr17EGN0xzBeIxfNANo3cp1ylzmC1VoT6Zl3HEyaYUF7WWgzEdY9LaqOOgZU/FCNt1w5yelCRII/T0a+6O3wpe7ga0xRe4gQ7tDJkYaMTowJDERp5GpKFZmbIwm39c+nP2/7p5qbunYUWcqUNlecSgQcJSqypwcPwdW7SQ+M7WKuzHSNkY71aH9iA/Oz44cSMf4mk1LT6SgJlKhMpghEaVO+rn+TJ+7dcd++77RgXpTsive3YuNNvCQT7jcWmK35pZ8jDQYTTOREh6ROa204xp2tN4sjQ+/+7jYcOmPx3jjZWvdjhFFw9ZGLTi2xhHwh+L6MY00N9Ekb4QMyJ+3o/ABuEhaithUlpquONHpzT4R+8gJCszdCoyziWoQc0mcYzc4W5DPv3eJyxNY9zSAgLMtDWEUBJByJzaS1sltwUB7PjfYatsh+OzFuL6anOGtF+nFQtlwwSQqzdboVmfWu4Z/cM9dK04Jwa8UzxTguzLrluv5Tw3lDNo31+r7fyJR1E/qrMiDeHiyx8stfo38tK4a/k6mAKjFRPmiKs7fhMdlsrAgrUowLcFaDWknBYVTIziQ/CgRFyNcKY+QmpWJ84n2PYa+kTpugRWIv+9JamrSFVj8WGEJauPYV5w= 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)(39830400003)(136003)(346002)(366004)(376002)(396003)(1800799009)(451199024)(186009)(54906003)(66476007)(66946007)(66574015)(41300700001)(6916009)(316002)(8676002)(4326008)(8936002)(52116002)(6506007)(6486002)(6512007)(478600001)(6666004)(83380400001)(26005)(1076003)(2616005)(107886003)(86362001)(2906002)(30864003)(44832011)(38100700002)(38350700002)(5660300002)(36756003)(66556008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hy2Y2jusumO89g8ss2H6H0ycaFjx?= =?utf-8?q?phvLX2eYixITyHMhwIX7NOib0G8jzt5hV7II+lDa7DZFDNnmrVIvpb6hwHsrnPSoF?= =?utf-8?q?N+VpB37/u7oJzYhw2pERIDktg/LPn1O07rI52VRZSJGGdP9/7/tmfKzUSSyJEj2Ld?= =?utf-8?q?q0gy9X20FptmPJN6nJneJwvOHQGfKpCdKJBopQ6jU0HqzVJoFEnJU98HR/oMQtUbD?= =?utf-8?q?+q0d0fADNKBca0gkrOwx3JpQQ0yCub23g5zZVukkJsf3G9Ut0HRuVXwmKIrRSD9dh?= =?utf-8?q?TmIbrTjg3IVLMuClV4JdLbo5HAij8+OhiVdgXrcm6Xn5b891K9vUYLuGCaecryCgm?= =?utf-8?q?H9hBBhJNyUaUCKmCCD8/sSxV6g4KKKec145RHoFnmEgFcRusCzi9yUVgGbN1IH0/Z?= =?utf-8?q?B0+0zhzpoaLlaus/5f4vcVmAFSz2K1Ewfkux0ITbg3o5Wv4/LTUq5u1dukSsE1F0x?= =?utf-8?q?Of5+PJQmmbkO5qZ957kZzEGp1P1exwg/jYLXN9qUXBZZ67dbelw8JlrctXqhjhIwI?= =?utf-8?q?3z9HJ7Medn5XM4avL1WzcnboUNwwincu1yC+eWcgOMDpewyfUvTm3rxDzc6STOx5/?= =?utf-8?q?gzJY2nGK3uvcX3+Xq+slpvoMAGrR8qBkG3ZIBgqmevOi4pNwt/GV7O383TSAb3Zx8?= =?utf-8?q?1FFNxXQ0BbwPk+55kHlnnc09lQe3V409Svlz4NcYlvVIcv3S1AiL9i0Wiqz+BqZNz?= =?utf-8?q?PUqyKNHw8bxtqtd5Jlz4hjPGAVCnp0a3tGHM/yS7DBokKfnT4j1F8jO4E/JbQP5x4?= =?utf-8?q?WW7/1b4RYwIW13Fn22te9JiUwqxKnArLeLw+RaaVqC1Ef57jEaaaWX0wIrU3l5MX2?= =?utf-8?q?koWIM/6He70zITgUE5DBk8ymnPjDK8IYAoCM2ZNtbbmzMGKs1J4kzmuSVTjFsK4Gk?= =?utf-8?q?Un8HAPbK6b+5cIsFKKhXq3t/Z4hYjZ1AhcWUW72dtRkqJIkx7f0RfDrdATbfvJ+IJ?= =?utf-8?q?PODSuN+pcRJDRclVOLjvcR3cyedpHcWyn0qjez13NLIXQQcHXc0oBhl2zFa6wtbdU?= =?utf-8?q?C7pLs2cycvKLDFJcbvJdaW4vba7HGW7qO2FHPNHTajo3eyMwiuvOJsN4spRrEQii7?= =?utf-8?q?+PJjxL59vFjgb6PJEQ9K3PcOWZGdruy7L1nxXBed1uLyk+GD5kOLGHuDQWhjeX0GZ?= =?utf-8?q?ePmLfjVjjO4hcpSqpb6GOdrucZY9DgzVc9S0QzPvggJNnmq014BlYkUAAMUdv5YK+?= =?utf-8?q?bmMc8ZMt+NBtueYb5/WWmyqdlVYl8dJK092FH1636OopWAsOWy9yATW1BRu7sw0RV?= =?utf-8?q?npmSb+cDYYnuUiQvvnOC9XspRV0e0A8BXeMXMCCyb6xbZzY8shU/RYidjkOurUs4p?= =?utf-8?q?isFhiX/0lcqL9KYFCYEZgkGm4iD/UAfkRRf5GX4CbBs6dZUjlB2vaqpik3070+f59?= =?utf-8?q?HArdOY54sR6xP5+vXouX5hvJdeuen4Nmak35www7xjMiIm1ZGeyZXR2p+od1UvWHv?= =?utf-8?q?h6eKXVPKAYrPv/Vs2Nywi3zhXPnpc0ljvwdd3oW58+dGzohZE67LBz5OD7yrFNo7d?= =?utf-8?q?nw2I7ZlMnuweau4csxN+ZseaEq0sp8dBBQ=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 186be7fd-73e0-42e1-eddc-08dbb7f1a143 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 02:47:42.6758 (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: 5Z85FttisK5bKRk/KtVyzmTcMszlksIFLmu6J3pIcAzA3qwhqohmuKWhl/LePsj7JDNzrv1rYTZfrvpBYx7Sc95LJWSEQtdfEB/j0J6wClA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB6435 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 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..e9b3fc3945 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; + 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 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; }