From patchwork Wed Dec 7 00:44:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066434 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DC1EC4708D for ; Wed, 7 Dec 2022 00:45:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbiLGApM (ORCPT ); Tue, 6 Dec 2022 19:45:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbiLGApJ (ORCPT ); Tue, 6 Dec 2022 19:45:09 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2084.outbound.protection.outlook.com [40.107.220.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0AAA2FFF9 for ; Tue, 6 Dec 2022 16:45:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U5wVF/paTgtHrx0aJZtXawhxLH7emL7B/5/prsIG4VhMRk6wJLHs4VLGbvG9JBVJMygtCl+jsddGMlnMpPumpQfRsPRCdFMYfX2jqC1NLjUBpOZDXBTif8GJnCxk1fYHYECmXBRqPilv5XSLKsk7AuUH0svUk7XhgiOHY7Nb7GEqBjZN+faRAkFj6Ep2PgIulLMxjYXU4j63vHUFVOfrdxDUs5rpA61z39XadelWCQLoNUyVCJjB3Sy8F5+4ChcyYC7uxJhMoqq2P5a99eRtTYTLkQR23fFaajrjOAnudDoXdecfmQbpSmCpPdal2W3BzXOJa+KlRM9316TvZSZmRA== 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=lh+npd9Pwun9Ftndp+6Pd+p4gTMLjS1fxR1wvUpQ2ag=; b=VQ7zpyjPH5zQfghRvPTNOAnIvBsKLQXQSULyEgaGO2MjOrZserkDuk8XKyCl9zEqifJ0rhFH3rMq0gr2IdR/RLMfJw2PNbnrLaTev54kw3cD5lQsKBt9x4cTGZXpGP1zx3qoyyaiNc/jG9YjjF2P2vTE3OBN1fGGrj67gqoiqkqUy16GOxzPDGzKRPwv2ErQChILsDFS2ljKSsGBFwwJNY6jckNZlPv94h+IgfLwOWkotAK7C5VJS7BSqOnTifDXjck5dCXL4m/+f/S8qrT0cdHMDT0uTaQP9haZLW3lPbeFI/3fQRopPvA3clrM1D6KLbKi1hQcO7PaQ4rLiVHylg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lh+npd9Pwun9Ftndp+6Pd+p4gTMLjS1fxR1wvUpQ2ag=; b=J9lMfB2BA1UNARmtK0OBgrjFOcD2hUI/BwOGLmjYonVwcSu+ECIkr8iHv23UrsCagpH9ut375ukbLXfRYImsLS46UpMXHGQmRDXGD77TZKW9OEL60Kg1i22S+xEnhL+eZc+H5KJRTZMgcsI/GSK2gOkFwoIjIlRy5xo46sB1NP0= Received: from BN9PR03CA0924.namprd03.prod.outlook.com (2603:10b6:408:107::29) by DS0PR12MB7704.namprd12.prod.outlook.com (2603:10b6:8:130::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.13; Wed, 7 Dec 2022 00:45:06 +0000 Received: from BN8NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:408:107:cafe::d2) by BN9PR03CA0924.outlook.office365.com (2603:10b6:408:107::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT010.mail.protection.outlook.com (10.13.177.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:06 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:05 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 01/16] devlink: add fw bank select parameter Date: Tue, 6 Dec 2022 16:44:28 -0800 Message-ID: <20221207004443.33779-2-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT010:EE_|DS0PR12MB7704:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ca0da00-4622-4c18-2ec6-08dad7ec48df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iTq56CW2/XqkUkuyIREfLkEkd/2PXQqArZX7xD27ZuLsbwe6Zy1c81kGTrLiPTw2LPK/WeufsaPN9HWTSIOuT4UeiyK9r5gRNbhq8mqRfykj83BxDR41O+9Nun4cRBZ7MT07N3MgTteW6ZQgEOG8aO9vQW+27GA2H7/jBrR6wwnPSblK+qkTFhF1qkkMypdXgwptx+8BTQch014XzekeMvW/akBActaTOClT01Rs+i3CMu3VjioKjRTfQ82Le1toFRqd5bldq1nRUGBVjCv7fo6UHh7SUcyjkKpkOU/oUU4PcCkuGGNvCFVQVWDfCjUPLf3DcncL8kdGq1468fYutGXlIW6DHU1oezmnwmLr36hHzoUV7oi+TL9n2c2Ev2ZEpKrA/uhVA3FPu4VMKlBMtjsaiz8JmUJpnK7//9+Xs30FXqbgelQ8bK0K8eFzEPFpxraHTtTchwJtVHTdoCcVYmTM8fUFJPk3/MnhptP3dCBdzwrnCrf/nLLNy7uex+syKxZWL6fPcqeqzXXZEOq5Mb+xCoJ0waxrdbOU07U0C320JmrTd4ziH9trD/n5rpv/oGo4So6obwl20hZsC8FhIVHgw/wbawvH9HWpGxk5GSquHKfhf3Pfc/Gdckqa3cz+7oHbk/yN32yMqEUyFQG3eJKU8r99KukKxYdXffuu2lvGF8OQBU4FqefBYTckLW6SW1zVj9QNBZDSCRRWqT9al1Zw93gHyZ0Wwgsi+5vVLm+VD0lxNwwUXblfUmF4aKae8wGYXLVVsNm/hWzVNZFUQw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(396003)(346002)(136003)(376002)(451199015)(46966006)(40470700004)(36840700001)(81166007)(40480700001)(1076003)(36756003)(86362001)(40460700003)(45080400002)(478600001)(966005)(356005)(44832011)(316002)(70206006)(4326008)(8936002)(5660300002)(26005)(54906003)(70586007)(2906002)(110136005)(15650500001)(6666004)(41300700001)(16526019)(8676002)(82310400005)(36860700001)(82740400003)(336012)(83380400001)(186003)(2616005)(47076005)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:06.0717 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ca0da00-4622-4c18-2ec6-08dad7ec48df X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7704 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a new device generic parameter to select the bank of firmware to be used on future boot and/or resets in those devices that have multiple firmware memory banks. This can be used along with the FW_LOAD_POLICY parameter, depending on the capabilities of the particular device. Examples: $ devlink dev param set pci/0000:07:00.0 name fw_bank value 1 cmode permanent $ devlink dev param show pci/0000:07:00.0 name fw_bank pci/0000:07:00.0: name fw_bank type generic values: cmode permanent value 1 Link: https://lore.kernel.org/netdev/CO1PR11MB508942BE965E63893DE9B86AD6129@CO1PR11MB5089.namprd11.prod.outlook.com/ Signed-off-by: Shannon Nelson --- Documentation/networking/devlink/devlink-params.rst | 4 ++++ include/net/devlink.h | 4 ++++ net/core/devlink.c | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/Documentation/networking/devlink/devlink-params.rst b/Documentation/networking/devlink/devlink-params.rst index 4e01dc32bc08..7cf1cd68ff08 100644 --- a/Documentation/networking/devlink/devlink-params.rst +++ b/Documentation/networking/devlink/devlink-params.rst @@ -137,3 +137,7 @@ own name. * - ``event_eq_size`` - u32 - Control the size of asynchronous control events EQ. + * - ``fw_bank`` + - u8 + - Select the bank of firmware to be used on future boot and/or resets in + devices that have multiple firmware memory banks. diff --git a/include/net/devlink.h b/include/net/devlink.h index 5f6eca5e4a40..3fa26a26fa44 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -510,6 +510,7 @@ enum devlink_param_generic_id { DEVLINK_PARAM_GENERIC_ID_ENABLE_IWARP, DEVLINK_PARAM_GENERIC_ID_IO_EQ_SIZE, DEVLINK_PARAM_GENERIC_ID_EVENT_EQ_SIZE, + DEVLINK_PARAM_GENERIC_ID_FW_BANK, /* add new param generic ids above here*/ __DEVLINK_PARAM_GENERIC_ID_MAX, @@ -568,6 +569,9 @@ enum devlink_param_generic_id { #define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_NAME "event_eq_size" #define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32 +#define DEVLINK_PARAM_GENERIC_FW_BANK_NAME "fw_bank" +#define DEVLINK_PARAM_GENERIC_FW_BANK_TYPE DEVLINK_PARAM_TYPE_U8 + #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \ { \ .id = DEVLINK_PARAM_GENERIC_ID_##_id, \ diff --git a/net/core/devlink.c b/net/core/devlink.c index 907df7124157..25a075f0aadd 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5221,6 +5221,11 @@ static const struct devlink_param devlink_param_generic[] = { .name = DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_NAME, .type = DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_TYPE, }, + { + .id = DEVLINK_PARAM_GENERIC_ID_FW_BANK, + .name = DEVLINK_PARAM_GENERIC_FW_BANK_NAME, + .type = DEVLINK_PARAM_GENERIC_FW_BANK_TYPE, + }, }; static int devlink_param_generic_verify(const struct devlink_param *param) From patchwork Wed Dec 7 00:44:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066435 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 758DAC352A1 for ; Wed, 7 Dec 2022 00:45:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229788AbiLGApN (ORCPT ); Tue, 6 Dec 2022 19:45:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229719AbiLGApJ (ORCPT ); Tue, 6 Dec 2022 19:45:09 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 756013121F for ; Tue, 6 Dec 2022 16:45:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bkN38YmDyvUxaT014BEYDhWCjprWxk4xTUJy5qi+d3vVcfknIPiokl6D40T3stWAI8j+dSoa8AhJiojeX2d/vdRPmswkpIUEpR8ct4z1HrCw0yv97n0aHTaIjp+bY5bA33vtxst0BJdGDQtx7QOVs7loriaRLoKAfyxCrC2LHGKDU6SbbDz6q5zJtaYCEOQkRysAS+M5zWBrNu8o3syWSHYJ4Cve1/1xU4TZAUERjGK83hkliIxpEyGqtHIwr+vpCcCKsqbZ9EEXyvl/eTrd71+z3D/wx3Ex/+mKqG0VRP6BN+Bx3C+w8KftQ/4OaozIi4UBPWHKUkr/UwjswS554g== 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=dftM4Y00xPfFgSg6fF26978p5ywCI5zmwxdH7xDeQ0o=; b=HtgHHbydH9yE6FMWqNC711LKbVnNe30DA53/Qr8A9ocpv9/X5jk3hvDVtrG1sbX7JtercrH3HGhcJFSc/YQSapp9C986Hc4XQ3SfbYVI8oyk/Yjz0ueSI8U1NVAja/af7tDLQDMnluxiykNyWkfV2QjX2exuNhatFWmDFt0qV17OzMwC/kxbXmK657pVdkSkrpwWIRpwZREkL9nPNCz/PhuFC8r//5IXsqg+8WkeVE/zZ1JqwrWDgt6NphhtLdPrbjC3c4oxpQ2eesr1fSJa4PJY05R1bwBMCiV2SsE3DSo7sp4j6CPhqmPQ2D1L9UO0eFu7bIfMAjfwpJcPzK0+GA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dftM4Y00xPfFgSg6fF26978p5ywCI5zmwxdH7xDeQ0o=; b=Vtg57dRAgqrYo5MF34WTDs/diIfHqWmYBAhCMoqAoAxR82xIEgTx2yzZWW75/KQWc3W4PpdY25ZWbiPiME+sZD0mw/zaTIG73gK5DUpCVk4em2poEbEcS4MGz1+z+WCnd/O1lnK0ZbjYwz/BSOZcr/+Q0iNF2+3kUQlQ0IiPzwo= Received: from BN9PR03CA0903.namprd03.prod.outlook.com (2603:10b6:408:107::8) by SN7PR12MB7275.namprd12.prod.outlook.com (2603:10b6:806:2ae::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:06 +0000 Received: from BN8NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:408:107:cafe::e1) by BN9PR03CA0903.outlook.office365.com (2603:10b6:408:107::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT010.mail.protection.outlook.com (10.13.177.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:06 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:05 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 02/16] devlink: add enable_migration parameter Date: Tue, 6 Dec 2022 16:44:29 -0800 Message-ID: <20221207004443.33779-3-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT010:EE_|SN7PR12MB7275:EE_ X-MS-Office365-Filtering-Correlation-Id: 635b38a1-29ed-49d1-503b-08dad7ec4943 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: liJxnPbt3htfJDmqsFnuh2AFFUy3Hi89UjomNUK5o1xxdhljFoaYO9JxoHEAbG8RvsKsLjplsj1i1ZrnBv+Pkvy7LclAzrEjHg+YFLvqDGs6cVuTHCqROdVi0fZq3aTpmjHeq0vdl41auqKaC8Chss9jfYO1Oxyrj6Z9Cj43GGDfmWIdhR7DC2h4BjGnjCNRTTFUzc4+96++tytbWdGEUD031kUqSIAHqY4PXH+xUv3cMXKCwl56b+o0pIeFmaSB/ra+FNw0HFkT5dfC5fmi/mFZXf5sr714T5OmKwdtZVooMc6gfuB/9jDo9L9C5KSuoUGteEqySFnNdA0P1UbjHNjvQYT098VaGXC9LeEh8AmI5rjxb76Subf2iKxCGYHnBGCyw0EBOwQOxjZkZUeiu+k7TGe455wM+P1saoMU7/c3wXVfph6dO2gsiZ0PfvQ6ALm4g6MnA4zl4l+BP7fZAgLu9pL/8sVVbqmAEFn5Dd1q2o/wTu5nE/AnBX50UQJtE6lG37eII8x5YmElqgH2WXAy/o7UYXoNV97l6wFh5h5o4p/fptqJp2XUQyxavx5crjoB159BO/jMqnj/OpjDPkeoS8jQgqfzg0LSe0CCsIvW3dkyDser4N9jc0XNqxYJT40uLITuBpM5BMSkUrnvrTC8e1RnkmgprNGaYzOtA1kqYS3Gm8V+dpnE7OeBclXHEe1KR4JnIXwDhQqwpfyfRoaErNfaeHQwBAbVcR+Wjqc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(346002)(376002)(136003)(39860400002)(451199015)(40470700004)(46966006)(36840700001)(8676002)(6666004)(4326008)(70206006)(70586007)(36756003)(40480700001)(83380400001)(41300700001)(478600001)(36860700001)(44832011)(86362001)(8936002)(5660300002)(40460700003)(82740400003)(2906002)(81166007)(82310400005)(356005)(336012)(16526019)(54906003)(2616005)(316002)(110136005)(1076003)(26005)(186003)(47076005)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:06.7435 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 635b38a1-29ed-49d1-503b-08dad7ec4943 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7275 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a new device generic parameter to enable/disable support for live migration in the devlink device. This is intended primarily for a core device that supports other ports/VFs/SFs. Those dependent ports may need their own migratable parameter for individual enable/disable control. Examples: $ devlink dev param set pci/0000:07:00.0 name enable_migration value true cmode runtime $ devlink dev param show pci/0000:07:00.0 name enable_migration pci/0000:07:00.0: name enable_migration type generic values: cmode runtime value true Signed-off-by: Shannon Nelson --- Documentation/networking/devlink/devlink-params.rst | 3 +++ include/net/devlink.h | 4 ++++ net/core/devlink.c | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/Documentation/networking/devlink/devlink-params.rst b/Documentation/networking/devlink/devlink-params.rst index 7cf1cd68ff08..602c8d487afd 100644 --- a/Documentation/networking/devlink/devlink-params.rst +++ b/Documentation/networking/devlink/devlink-params.rst @@ -141,3 +141,6 @@ own name. - u8 - Select the bank of firmware to be used on future boot and/or resets in devices that have multiple firmware memory banks. + * - ``enable_migration`` + - Boolean + - Enable/disable support for live migration in the devlink device. diff --git a/include/net/devlink.h b/include/net/devlink.h index 3fa26a26fa44..79842b174915 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -511,6 +511,7 @@ enum devlink_param_generic_id { DEVLINK_PARAM_GENERIC_ID_IO_EQ_SIZE, DEVLINK_PARAM_GENERIC_ID_EVENT_EQ_SIZE, DEVLINK_PARAM_GENERIC_ID_FW_BANK, + DEVLINK_PARAM_GENERIC_ID_ENABLE_MIGRATION, /* add new param generic ids above here*/ __DEVLINK_PARAM_GENERIC_ID_MAX, @@ -572,6 +573,9 @@ enum devlink_param_generic_id { #define DEVLINK_PARAM_GENERIC_FW_BANK_NAME "fw_bank" #define DEVLINK_PARAM_GENERIC_FW_BANK_TYPE DEVLINK_PARAM_TYPE_U8 +#define DEVLINK_PARAM_GENERIC_ENABLE_MIGRATION_NAME "enable_migration" +#define DEVLINK_PARAM_GENERIC_ENABLE_MIGRATION_TYPE DEVLINK_PARAM_TYPE_BOOL + #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \ { \ .id = DEVLINK_PARAM_GENERIC_ID_##_id, \ diff --git a/net/core/devlink.c b/net/core/devlink.c index 25a075f0aadd..b51c1d0da29f 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5226,6 +5226,11 @@ static const struct devlink_param devlink_param_generic[] = { .name = DEVLINK_PARAM_GENERIC_FW_BANK_NAME, .type = DEVLINK_PARAM_GENERIC_FW_BANK_TYPE, }, + { + .id = DEVLINK_PARAM_GENERIC_ID_ENABLE_MIGRATION, + .name = DEVLINK_PARAM_GENERIC_ENABLE_MIGRATION_NAME, + .type = DEVLINK_PARAM_GENERIC_ENABLE_MIGRATION_TYPE, + }, }; static int devlink_param_generic_verify(const struct devlink_param *param) From patchwork Wed Dec 7 00:44:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066437 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5430C352A1 for ; Wed, 7 Dec 2022 00:45:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229840AbiLGAp0 (ORCPT ); Tue, 6 Dec 2022 19:45:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbiLGApN (ORCPT ); Tue, 6 Dec 2022 19:45:13 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2076.outbound.protection.outlook.com [40.107.223.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CAB313CE0 for ; Tue, 6 Dec 2022 16:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c/r92gIjc6XhwvFP0sUqdeTepfmUefUudxTa+Udrdb6mlHgxNvwYzcUv/X1ld8KJF3ebUVihFYOYPP9TxJy+l/CsoxtG6xb4wUNCVbp7Ci4NR0wgnG95xHdtFxqmC/xdLmfQpMJWo53pPt+A1TiQ785hjx0mxeWupUAE1ma06Wbl45jJN0ovprs3d5CmrCxBlNbPOJU0wEG0RpVAlswfBnthiPL9uR4mx3s7O9u2SCaRfYkHitoT7CBj67koWK3RQE+f46UkIINRu8DcUzfjVCO/3OAJ2eJ0hW31o/6thrKRdy9uM+W4nyGdk8lu6F1q1OldYo+JmbdIhNVyTLsBTg== 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=2HFsBKgL+moTsaoytukYXmZEhXSic0YAPXrc/Ue8T9Q=; b=W2i7PUu6FiYhfI2cuSKg1H2BmohoFGilaWz3vzAwr4l4yVaO9qgnkZQoxR+9dHStuOKIt+VeAj30AFplBrDo43XSwNc0dGMmvneWVgELJ7yOUcPCrMKhbBDMSpeaSOl5Zq0xxrc4Aktoany3b0yJKfbdMUzJbjljtLiMV2hN950SX4aoG3DCCzdjX3V43wbU/meMoU67YpfePgXfj1jhUZ4DRYeZtm/69p5FiWV+Ub6viE8ZFuzpdJJpwk1FZnpTss4IDI9PnGKDSpaFigr5wbxr+CP7E/oJQB+LpAKekDRYb3pu43RTorWRuGLxDT2XkmBtPep0i8ga3um4O/orPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2HFsBKgL+moTsaoytukYXmZEhXSic0YAPXrc/Ue8T9Q=; b=i5faY03ff3znapU4uT3e7tvp/+kFOLO1OWNh6cBlif02IfT7DYxt8c7KAaSKqTPfzoAX5Ah0WVM1eBPw8U7Gc+OMhQr01OP3F9H2JFkoL4cmXFY2T67VOrU+x2Xgm/xmFj98gB72wE8OpAmnYth52Eyca/zuSJQMicBCrTtWIzE= Received: from BN9PR03CA0989.namprd03.prod.outlook.com (2603:10b6:408:109::34) by CY8PR12MB7514.namprd12.prod.outlook.com (2603:10b6:930:92::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:07 +0000 Received: from BN8NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:408:109:cafe::4f) by BN9PR03CA0989.outlook.office365.com (2603:10b6:408:109::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT056.mail.protection.outlook.com (10.13.177.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:07 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:06 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 03/16] pds_core: initial framework for pds_core driver Date: Tue, 6 Dec 2022 16:44:30 -0800 Message-ID: <20221207004443.33779-4-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT056:EE_|CY8PR12MB7514:EE_ X-MS-Office365-Filtering-Correlation-Id: 11928d71-3300-43c7-686e-08dad7ec49bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4Fi93amFq7OtNtCiwFk+cGg2Pr6IKNmBzR/j8QsLn8dPr9Mas1yQPc1SfskTRoDq8BxrS8YHK/q4t69mBSc/rlrfGBPp9Gl0tUxqqs1iewbK4SDQyt6ux+x2KExwh7ffTBcMdzlDIbeHh1EVAWYkBa1E+ZWyfI628o2aIrbv5mE4mN2usP97ipdukgTsTP+L+tnKGRR7tfzsBLavDsQ9xa3DTJWlcQNSoG86ct4zBbJxKgWrm73T6caQNwUmoXxll1gJBYIuiovMC3GmaVPBzINHlwbhfdKd+YJorRNUrwG5glaLwI+T5Ss3wU+R5+yNGuzZuuQSlXZRmNSvE54hPyQMZ+YVNCVoLZF4p5meeCBzZogvXmqUYYflgCm/qXW0khw8Sy4q4weKXXDoG16DSYBUR4UOA2Lhw7Ko61amyJyufCtrovoSbpfDoZmuuBp8F6JJ7Ml3ZQSa1DgRf2H+6+79iA2pmO47C63jwbpXsk9atvKTL9Am1RsdLSEVArG4/mIZzxlOgnh3dTV4N6Am1TKKz74KrmpfDiejFKdWR9ssPdUDjIHWuFTqhm7rhcLvxqJ2gNznThnHZLqTy1bBid70WzpQgfrJQnbfuhQ0x7fIFT5CpIPwO9V9VOdfkxxk6di1pddYEDX8Ed0JWknV3/lrNp8yysyVB5AD0mImy3KFtz2KPnJ7/W3SeB0NE4c+ryrdL4ZcHpEuBuA192MnU41niBW5J/85FvNzb+vAtWg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(346002)(396003)(136003)(376002)(451199015)(36840700001)(46966006)(40470700004)(82740400003)(110136005)(36756003)(54906003)(36860700001)(81166007)(356005)(70586007)(316002)(478600001)(82310400005)(41300700001)(70206006)(4326008)(6666004)(8676002)(30864003)(44832011)(47076005)(426003)(8936002)(40480700001)(5660300002)(2616005)(16526019)(336012)(86362001)(26005)(186003)(40460700003)(1076003)(2906002)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:07.5371 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 11928d71-3300-43c7-686e-08dad7ec49bc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7514 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This is the initial PCI driver framework for the new pds_core device driver and its family of client drivers. This does the very basics of registering for the new PCI device 1dd8:100c, setting up debugfs entries, and registering with devlink. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/pds_core/Makefile | 9 + drivers/net/ethernet/pensando/pds_core/core.h | 68 ++ .../net/ethernet/pensando/pds_core/debugfs.c | 47 ++ .../net/ethernet/pensando/pds_core/devlink.c | 46 ++ drivers/net/ethernet/pensando/pds_core/main.c | 263 ++++++++ include/linux/pds/pds_common.h | 13 + include/linux/pds/pds_core_if.h | 581 ++++++++++++++++++ 7 files changed, 1027 insertions(+) create mode 100644 drivers/net/ethernet/pensando/pds_core/Makefile create mode 100644 drivers/net/ethernet/pensando/pds_core/core.h create mode 100644 drivers/net/ethernet/pensando/pds_core/debugfs.c create mode 100644 drivers/net/ethernet/pensando/pds_core/devlink.c create mode 100644 drivers/net/ethernet/pensando/pds_core/main.c create mode 100644 include/linux/pds/pds_common.h create mode 100644 include/linux/pds/pds_core_if.h diff --git a/drivers/net/ethernet/pensando/pds_core/Makefile b/drivers/net/ethernet/pensando/pds_core/Makefile new file mode 100644 index 000000000000..72bbc5fa68ad --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2022 Pensando Systems, Inc + +obj-$(CONFIG_PDS_CORE) := pds_core.o + +pds_core-y := main.o \ + devlink.o + +pds_core-$(CONFIG_DEBUG_FS) += debugfs.o diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h new file mode 100644 index 000000000000..022adc4aea01 --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2022 Pensando Systems, Inc */ + +#ifndef _PDSC_H_ +#define _PDSC_H_ + +#include +#include + +#include +#include + +#define PDSC_DRV_DESCRIPTION "Pensando Core PF Driver" + +struct pdsc_dev_bar { + void __iomem *vaddr; + phys_addr_t bus_addr; + unsigned long len; + int res_index; +}; + +/* No state flags set means we are in a steady running state */ +enum pdsc_state_flags { + PDSC_S_FW_DEAD, /* fw stopped, waiting for startup or recovery */ + PDSC_S_INITING_DRIVER, /* initial startup from probe */ + PDSC_S_STOPPING_DRIVER, /* driver remove */ + + /* leave this as last */ + PDSC_S_STATE_SIZE +}; + +struct pdsc { + struct pci_dev *pdev; + struct dentry *dentry; + struct device *dev; + struct pdsc_dev_bar bars[PDS_CORE_BARS_MAX]; + int hw_index; + int id; + + unsigned long state; + + struct pds_core_dev_info_regs __iomem *info_regs; + struct pds_core_dev_cmd_regs __iomem *cmd_regs; + struct pds_core_intr __iomem *intr_ctrl; + u64 __iomem *intr_status; + u64 __iomem *db_pages; + dma_addr_t phy_db_pages; + u64 __iomem *kern_dbpage; +}; + +struct pdsc *pdsc_dl_alloc(struct device *dev); +void pdsc_dl_free(struct pdsc *pdsc); +int pdsc_dl_register(struct pdsc *pdsc); +void pdsc_dl_unregister(struct pdsc *pdsc); + +#ifdef CONFIG_DEBUG_FS +void pdsc_debugfs_create(void); +void pdsc_debugfs_destroy(void); +void pdsc_debugfs_add_dev(struct pdsc *pdsc); +void pdsc_debugfs_del_dev(struct pdsc *pdsc); +#else +static inline void pdsc_debugfs_create(void) { } +static inline void pdsc_debugfs_destroy(void) { } +static inline void pdsc_debugfs_add_dev(struct pdsc *pdsc) { } +static inline void pdsc_debugfs_del_dev(struct pdsc *pdsc) { } +#endif + +#endif /* _PDSC_H_ */ diff --git a/drivers/net/ethernet/pensando/pds_core/debugfs.c b/drivers/net/ethernet/pensando/pds_core/debugfs.c new file mode 100644 index 000000000000..3f876dcc5431 --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/debugfs.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2022 Pensando Systems, Inc */ + +#ifdef CONFIG_DEBUG_FS + +#include +#include +#include +#include + +#include "core.h" + +static struct dentry *pdsc_dir; + +void pdsc_debugfs_create(void) +{ + pdsc_dir = debugfs_create_dir(PDS_CORE_DRV_NAME, NULL); +} + +void pdsc_debugfs_destroy(void) +{ + debugfs_remove_recursive(pdsc_dir); +} + +static int core_state_show(struct seq_file *seq, void *v) +{ + struct pdsc *pdsc = seq->private; + + seq_printf(seq, "%#lx\n", pdsc->state); + return 0; +} +DEFINE_SHOW_ATTRIBUTE(core_state); + +void pdsc_debugfs_add_dev(struct pdsc *pdsc) +{ + pdsc->dentry = debugfs_create_dir(pci_name(pdsc->pdev), pdsc_dir); + + debugfs_create_file("state", 0400, pdsc->dentry, + pdsc, &core_state_fops); +} + +void pdsc_debugfs_del_dev(struct pdsc *pdsc) +{ + debugfs_remove_recursive(pdsc->dentry); + pdsc->dentry = NULL; +} +#endif /* CONFIG_DEBUG_FS */ diff --git a/drivers/net/ethernet/pensando/pds_core/devlink.c b/drivers/net/ethernet/pensando/pds_core/devlink.c new file mode 100644 index 000000000000..016566aec1dc --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/devlink.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2022 Pensando Systems, Inc */ + +#include +#include +#include +#include + +#include "core.h" + +static const struct devlink_ops pdsc_dl_ops = { +}; + +struct pdsc *pdsc_dl_alloc(struct device *dev) +{ + struct devlink *dl; + + dl = devlink_alloc(&pdsc_dl_ops, sizeof(struct pdsc), dev); + if (!dl) + return NULL; + + return devlink_priv(dl); +} + +void pdsc_dl_free(struct pdsc *pdsc) +{ + struct devlink *dl = priv_to_devlink(pdsc); + + devlink_free(dl); +} + +int pdsc_dl_register(struct pdsc *pdsc) +{ + struct devlink *dl = priv_to_devlink(pdsc); + + devlink_register(dl); + + return 0; +} + +void pdsc_dl_unregister(struct pdsc *pdsc) +{ + struct devlink *dl = priv_to_devlink(pdsc); + + devlink_unregister(dl); +} diff --git a/drivers/net/ethernet/pensando/pds_core/main.c b/drivers/net/ethernet/pensando/pds_core/main.c new file mode 100644 index 000000000000..4bdbcc1c17a7 --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/main.c @@ -0,0 +1,263 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2022 Pensando Systems, Inc */ + +/* main PCI driver and mgmt logic */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include + +#include "core.h" + +MODULE_DESCRIPTION(PDSC_DRV_DESCRIPTION); +MODULE_AUTHOR("Pensando Systems, Inc"); +MODULE_LICENSE("GPL"); + +/* Supported devices */ +static const struct pci_device_id pdsc_id_table[] = { + { PCI_VDEVICE(PENSANDO, PCI_DEVICE_ID_PENSANDO_CORE_PF) }, + { 0, } /* end of table */ +}; +MODULE_DEVICE_TABLE(pci, pdsc_id_table); + +static void pdsc_unmap_bars(struct pdsc *pdsc) +{ + struct pdsc_dev_bar *bars = pdsc->bars; + unsigned int i; + + for (i = 0; i < PDS_CORE_BARS_MAX; i++) { + if (bars[i].vaddr) { + pcim_iounmap(pdsc->pdev, bars[i].vaddr); + bars[i].vaddr = NULL; + } + + bars[i].len = 0; + bars[i].bus_addr = 0; + bars[i].res_index = 0; + } +} + +static int pdsc_map_bars(struct pdsc *pdsc) +{ + struct pdsc_dev_bar *bar = pdsc->bars; + struct pci_dev *pdev = pdsc->pdev; + struct device *dev = pdsc->dev; + struct pdsc_dev_bar *bars; + unsigned int i, j; + int num_bars = 0; + int err; + u32 sig; + + bars = pdsc->bars; + num_bars = 0; + + /* Since the PCI interface in the hardware is configurable, + * we need to poke into all the bars to find the set we're + * expecting. The will be in the right order. + */ + for (i = 0, j = 0; i < PDS_CORE_BARS_MAX; i++) { + if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM)) + continue; + + bars[j].len = pci_resource_len(pdev, i); + bars[j].bus_addr = pci_resource_start(pdev, i); + bars[j].res_index = i; + + /* only map the whole bar 0 */ + if (j > 0) { + bars[j].vaddr = NULL; + } else { + bars[j].vaddr = pcim_iomap(pdev, i, bars[j].len); + if (!bars[j].vaddr) { + dev_err(dev, + "Cannot memory-map BAR %d, aborting\n", + i); + return -ENODEV; + } + } + + j++; + } + num_bars = j; + + /* BAR0: dev_cmd and interrupts */ + if (num_bars < 1) { + dev_err(dev, "No bars found\n"); + err = -EFAULT; + goto err_out; + } + + if (bar->len < PDS_CORE_BAR0_SIZE) { + dev_err(dev, "Resource bar size %lu too small\n", + bar->len); + err = -EFAULT; + goto err_out; + } + + pdsc->info_regs = bar->vaddr + PDS_CORE_BAR0_DEV_INFO_REGS_OFFSET; + pdsc->cmd_regs = bar->vaddr + PDS_CORE_BAR0_DEV_CMD_REGS_OFFSET; + pdsc->intr_status = bar->vaddr + PDS_CORE_BAR0_INTR_STATUS_OFFSET; + pdsc->intr_ctrl = bar->vaddr + PDS_CORE_BAR0_INTR_CTRL_OFFSET; + + sig = ioread32(&pdsc->info_regs->signature); + if (sig != PDS_CORE_DEV_INFO_SIGNATURE) { + dev_err(dev, "Incompatible firmware signature %x", sig); + err = -EFAULT; + goto err_out; + } + + /* BAR1: doorbells */ + bar++; + if (num_bars < 2) { + dev_err(dev, "Doorbell bar missing\n"); + err = -EFAULT; + goto err_out; + } + + pdsc->db_pages = bar->vaddr; + pdsc->phy_db_pages = bar->bus_addr; + + return 0; + +err_out: + pdsc_unmap_bars(pdsc); + pdsc->info_regs = NULL; + pdsc->cmd_regs = NULL; + pdsc->intr_status = NULL; + pdsc->intr_ctrl = NULL; + return err; +} + +static DEFINE_IDA(pdsc_pf_ida); + +static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) +{ + struct device *dev = &pdev->dev; + struct pdsc *pdsc; + int err; + + pdsc = pdsc_dl_alloc(dev); + if (!pdsc) + return -ENOMEM; + + pdsc->pdev = pdev; + pdsc->dev = &pdev->dev; + set_bit(PDSC_S_FW_DEAD, &pdsc->state); + set_bit(PDSC_S_INITING_DRIVER, &pdsc->state); + pci_set_drvdata(pdev, pdsc); + pdsc_debugfs_add_dev(pdsc); + + err = ida_alloc(&pdsc_pf_ida, GFP_KERNEL); + if (err < 0) { + dev_err(pdsc->dev, "%s: id alloc failed: %pe\n", __func__, ERR_PTR(err)); + goto err_out_free_devlink; + } + pdsc->id = err; + + /* Query system for DMA addressing limitation for the device. */ + err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(PDS_CORE_ADDR_LEN)); + if (err) { + dev_err(dev, "Unable to obtain 64-bit DMA for consistent allocations, aborting: %pe\n", + ERR_PTR(err)); + goto err_out_free_ida; + } + + pci_enable_pcie_error_reporting(pdev); + + /* Use devres management */ + err = pcim_enable_device(pdev); + if (err) { + dev_err(dev, "Cannot enable PCI device: %pe\n", ERR_PTR(err)); + goto err_out_free_ida; + } + + err = pci_request_regions(pdev, PDS_CORE_DRV_NAME); + if (err) { + dev_err(dev, "Cannot request PCI regions: %pe\n", ERR_PTR(err)); + goto err_out_pci_disable_device; + } + + pcie_print_link_status(pdev); + pci_set_master(pdev); + + err = pdsc_map_bars(pdsc); + if (err) + goto err_out_pci_disable_device; + + /* publish devlink device */ + err = pdsc_dl_register(pdsc); + if (err) { + dev_err(dev, "Cannot register devlink: %pe\n", ERR_PTR(err)); + goto err_out; + } + + clear_bit(PDSC_S_INITING_DRIVER, &pdsc->state); + return 0; + +err_out: + pci_clear_master(pdev); + pdsc_unmap_bars(pdsc); + pci_release_regions(pdev); +err_out_pci_disable_device: + pci_disable_pcie_error_reporting(pdev); + pci_disable_device(pdev); +err_out_free_ida: + ida_free(&pdsc_pf_ida, pdsc->id); +err_out_free_devlink: + pdsc_debugfs_del_dev(pdsc); + pdsc_dl_free(pdsc); + + return err; +} + +static void pdsc_remove(struct pci_dev *pdev) +{ + struct pdsc *pdsc = pci_get_drvdata(pdev); + + /* Undo the devlink registration now to be sure there + * are no requests while we're stopping. + */ + pdsc_dl_unregister(pdsc); + + /* Device teardown */ + ida_free(&pdsc_pf_ida, pdsc->id); + + /* PCI teardown */ + pci_clear_master(pdev); + pdsc_unmap_bars(pdsc); + pci_release_regions(pdev); + pci_disable_pcie_error_reporting(pdev); + pci_disable_device(pdev); + + /* Devlink and pdsc struct teardown */ + pdsc_dl_free(pdsc); +} + +static struct pci_driver pdsc_driver = { + .name = PDS_CORE_DRV_NAME, + .id_table = pdsc_id_table, + .probe = pdsc_probe, + .remove = pdsc_remove, +}; + +static int __init pdsc_init_module(void) +{ + pdsc_debugfs_create(); + return pci_register_driver(&pdsc_driver); +} + +static void __exit pdsc_cleanup_module(void) +{ + pci_unregister_driver(&pdsc_driver); + pdsc_debugfs_destroy(); + + pr_info("removed\n"); +} + +module_init(pdsc_init_module); +module_exit(pdsc_cleanup_module); diff --git a/include/linux/pds/pds_common.h b/include/linux/pds/pds_common.h new file mode 100644 index 000000000000..7de3c1b8526b --- /dev/null +++ b/include/linux/pds/pds_common.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) OR BSD-2-Clause */ +/* Copyright (c) 2022 Pensando Systems, Inc. All rights reserved. */ + +#ifndef _PDS_COMMON_H_ +#define _PDS_COMMON_H_ + +#define PDS_CORE_DRV_NAME "pds_core" + +/* the device's internal addressing uses up to 52 bits */ +#define PDS_CORE_ADDR_LEN 52 +#define PDS_CORE_ADDR_MASK (BIT_ULL(PDS_ADDR_LEN) - 1) + +#endif /* _PDS_COMMON_H_ */ diff --git a/include/linux/pds/pds_core_if.h b/include/linux/pds/pds_core_if.h new file mode 100644 index 000000000000..b1183f8a27ec --- /dev/null +++ b/include/linux/pds/pds_core_if.h @@ -0,0 +1,581 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) OR BSD-2-Clause */ +/* Copyright (c) 2022 Pensando Systems, Inc. All rights reserved. */ + +#ifndef _PDS_CORE_IF_H_ +#define _PDS_CORE_IF_H_ + +#include "pds_common.h" + +#define PCI_VENDOR_ID_PENSANDO 0x1dd8 +#define PCI_DEVICE_ID_PENSANDO_CORE_PF 0x100c + +#define PDS_CORE_BARS_MAX 4 +#define PDS_CORE_PCI_BAR_DBELL 1 + +/* Bar0 */ +#define PDS_CORE_DEV_INFO_SIGNATURE 0x44455649 /* 'DEVI' */ +#define PDS_CORE_BAR0_SIZE 0x8000 +#define PDS_CORE_BAR0_DEV_INFO_REGS_OFFSET 0x0000 +#define PDS_CORE_BAR0_DEV_CMD_REGS_OFFSET 0x0800 +#define PDS_CORE_BAR0_DEV_CMD_DATA_REGS_OFFSET 0x0c00 +#define PDS_CORE_BAR0_INTR_STATUS_OFFSET 0x1000 +#define PDS_CORE_BAR0_INTR_CTRL_OFFSET 0x2000 +#define PDS_CORE_DEV_CMD_DONE 0x00000001 + +#define PDS_CORE_DEVCMD_TIMEOUT 5 + +#define PDS_CORE_CLIENT_ID 0 +#define PDS_CORE_ASIC_TYPE_CAPRI 0 + +/* + * enum pds_core_cmd_opcode - Device commands + */ +enum pds_core_cmd_opcode { + + /* Core init */ + PDS_CORE_CMD_NOP = 0, + PDS_CORE_CMD_IDENTIFY = 1, + PDS_CORE_CMD_RESET = 2, + PDS_CORE_CMD_INIT = 3, + + PDS_CORE_CMD_FW_DOWNLOAD = 4, + PDS_CORE_CMD_FW_CONTROL = 5, + + /* SR/IOV commands */ + PDS_CORE_CMD_VF_GETATTR = 60, + PDS_CORE_CMD_VF_SETATTR = 61, + PDS_CORE_CMD_VF_CTRL = 62, + + /* Add commands before this line */ + PDS_CORE_CMD_MAX, + PDS_CORE_CMD_COUNT +}; + +/** + * struct pds_core_drv_identity - Driver identity information + * @drv_type: Driver type (enum pds_core_driver_type) + * @os_dist: OS distribution, numeric format + * @os_dist_str: OS distribution, string format + * @kernel_ver: Kernel version, numeric format + * @kernel_ver_str: Kernel version, string format + * @driver_ver_str: Driver version, string format + */ +struct pds_core_drv_identity { + __le32 drv_type; + __le32 os_dist; + char os_dist_str[128]; + __le32 kernel_ver; + char kernel_ver_str[32]; + char driver_ver_str[32]; +}; + +#define PDS_DEV_TYPE_MAX 16 +/** + * struct pds_core_dev_identity - Device identity information + * @version: Version of device identify + * @type: Identify type (0 for now) + * @state: Device state + * @rsvd: Word boundary padding + * @nlifs: Number of LIFs provisioned + * @nintrs: Number of interrupts provisioned + * @ndbpgs_per_lif: Number of doorbell pages per LIF + * @intr_coal_mult: Interrupt coalescing multiplication factor + * Scale user-supplied interrupt coalescing + * value in usecs to device units using: + * device units = usecs * mult / div + * @intr_coal_div: Interrupt coalescing division factor + * Scale user-supplied interrupt coalescing + * value in usecs to device units using: + * device units = usecs * mult / div + * @vif_types: How many of each VIF device type is supported + */ +struct pds_core_dev_identity { + u8 version; + u8 type; + u8 state; + u8 rsvd; + __le32 nlifs; + __le32 nintrs; + __le32 ndbpgs_per_lif; + __le32 intr_coal_mult; + __le32 intr_coal_div; + __le16 vif_types[PDS_DEV_TYPE_MAX]; +}; + +#define PDS_CORE_IDENTITY_VERSION_1 1 + +/** + * struct pds_core_dev_identify_cmd - Driver/device identify command + * @opcode: Opcode PDS_CORE_CMD_IDENTIFY + * @ver: Highest version of identify supported by driver + * + * Expects to find driver identification info (struct pds_core_drv_identity) + * in cmd_regs->data. Driver should keep the devcmd interface locked + * while preparing the driver info. + */ +struct pds_core_dev_identify_cmd { + u8 opcode; + u8 ver; +}; + +/** + * struct pds_core_dev_identify_comp - Device identify command completion + * @status: Status of the command (enum pds_core_status_code) + * @ver: Version of identify returned by device + * + * Device identification info (struct pds_core_dev_identity) can be found + * in cmd_regs->data. Driver should keep the devcmd interface locked + * while reading the results. + */ +struct pds_core_dev_identify_comp { + u8 status; + u8 ver; +}; + +/** + * struct pds_core_dev_reset_cmd - Device reset command + * @opcode: Opcode PDS_CORE_CMD_RESET + * + * Resets and clears all LIFs, VDevs, and VIFs on the device. + */ +struct pds_core_dev_reset_cmd { + u8 opcode; +}; + +/** + * struct pds_core_dev_reset_comp - Reset command completion + * @status: Status of the command (enum pds_core_status_code) + */ +struct pds_core_dev_reset_comp { + u8 status; +}; + +/* + * struct pds_core_dev_init_data - Pointers and info needed for the Core + * initialization PDS_CORE_CMD_INIT command. The in and out structs are + * overlays on the pds_core_dev_cmd_regs.data space for passing data down + * to the firmware on init, and then returning initialization results. + */ +struct pds_core_dev_init_data_in { + __le64 adminq_q_base; + __le64 adminq_cq_base; + __le64 notifyq_cq_base; + __le32 flags; + __le16 intr_index; + u8 adminq_ring_size; + u8 notifyq_ring_size; +}; + +struct pds_core_dev_init_data_out { + __le32 core_hw_index; + __le32 adminq_hw_index; + __le32 notifyq_hw_index; + u8 adminq_hw_type; + u8 notifyq_hw_type; +}; + +/** + * struct pds_core_dev_init_cmd - Core device initialize + * @opcode: opcode PDS_CORE_CMD_INIT + * + * Initializes the core device and sets up the AdminQ and NotifyQ. + * Expects to find initialization data (struct pds_core_dev_init_data_in) + * in cmd_regs->data. Driver should keep the devcmd interface locked + * while preparing the driver info. + */ +struct pds_core_dev_init_cmd { + u8 opcode; +}; + +/** + * struct pds_core_dev_init_comp - Core init completion + * @status: Status of the command (enum pds_core_status_code) + * + * Initialization result data (struct pds_core_dev_init_data_in) + * is found in cmd_regs->data. + */ +struct pds_core_dev_init_comp { + u8 status; +}; + +/** + * struct pds_core_fw_download_cmd - Firmware download command + * @opcode: opcode + * @rsvd: Word boundary padding + * @addr: DMA address of the firmware buffer + * @offset: offset of the firmware buffer within the full image + * @length: number of valid bytes in the firmware buffer + */ +struct pds_core_fw_download_cmd { + u8 opcode; + u8 rsvd[3]; + __le32 offset; + __le64 addr; + __le32 length; +}; + +/** + * struct pds_core_fw_download_comp - Firmware download completion + * @status: Status of the command (enum pds_core_status_code) + */ +struct pds_core_fw_download_comp { + u8 status; +}; + +/** + * enum pds_core_fw_control_oper - FW control operations + * @PDS_CORE_FW_INSTALL_ASYNC: Install firmware asynchronously + * @PDS_CORE_FW_INSTALL_STATUS: Firmware installation status + * @PDS_CORE_FW_ACTIVATE_ASYNC: Activate firmware asynchronously + * @PDS_CORE_FW_ACTIVATE_STATUS: Firmware activate status + * @PDS_CORE_FW_UPDATE_CLEANUP: Cleanup any firmware update leftovers + * @PDS_CORE_FW_GET_BOOT: Return current active firmware slot + * @PDS_CORE_FW_SET_BOOT: Set active firmware slot for next boot + * @PDS_CORE_FW_GET_LIST: Return list of installed firmware images + */ +enum pds_core_fw_control_oper { + PDS_CORE_FW_INSTALL_ASYNC = 0, + PDS_CORE_FW_INSTALL_STATUS = 1, + PDS_CORE_FW_ACTIVATE_ASYNC = 2, + PDS_CORE_FW_ACTIVATE_STATUS = 3, + PDS_CORE_FW_UPDATE_CLEANUP = 4, + PDS_CORE_FW_GET_BOOT = 5, + PDS_CORE_FW_SET_BOOT = 6, + PDS_CORE_FW_GET_LIST = 7, +}; + +enum pds_core_fw_slot { + PDS_CORE_FW_SLOT_INVALID = 0, + PDS_CORE_FW_SLOT_A = 1, + PDS_CORE_FW_SLOT_B = 2, + PDS_CORE_FW_SLOT_GOLD = 3, +}; + +/** + * struct pds_core_fw_control_cmd - Firmware control command + * @opcode: opcode + * @rsvd: Word boundary padding + * @oper: firmware control operation (enum pds_core_fw_control_oper) + * @slot: slot to operate on (enum pds_core_fw_slot) + */ +struct pds_core_fw_control_cmd { + u8 opcode; + u8 rsvd[3]; + u8 oper; + u8 slot; +}; + +/** + * struct pds_core_fw_control_comp - Firmware control copletion + * @status: Status of the command (enum pds_core_status_code) + * @rsvd: Word alignment space + * @slot: Slot number (enum pds_core_fw_slot) + * @rsvd1: Struct padding + * @color: Color bit + */ +struct pds_core_fw_control_comp { + u8 status; + u8 rsvd[3]; + u8 slot; + u8 rsvd1[10]; + u8 color; +}; + +struct pds_core_fw_name_info { +#define PDS_CORE_FWSLOT_BUFLEN 8 +#define PDS_CORE_FWVERS_BUFLEN 32 + char slotname[PDS_CORE_FWSLOT_BUFLEN]; + char fw_version[PDS_CORE_FWVERS_BUFLEN]; +}; + +struct pds_core_fw_list_info { +#define PDS_CORE_FWVERS_LIST_LEN 16 + u8 num_fw_slots; + struct pds_core_fw_name_info fw_names[PDS_CORE_FWVERS_LIST_LEN]; +} __packed; + +enum pds_core_vf_attr { + PDS_CORE_VF_ATTR_SPOOFCHK = 1, + PDS_CORE_VF_ATTR_TRUST = 2, + PDS_CORE_VF_ATTR_MAC = 3, + PDS_CORE_VF_ATTR_LINKSTATE = 4, + PDS_CORE_VF_ATTR_VLAN = 5, + PDS_CORE_VF_ATTR_RATE = 6, + PDS_CORE_VF_ATTR_STATSADDR = 7, +}; + +/** + * enum pds_core_vf_link_status - Virtual Function link status + * @PDS_CORE_VF_LINK_STATUS_AUTO: Use link state of the uplink + * @PDS_CORE_VF_LINK_STATUS_UP: Link always up + * @PDS_CORE_VF_LINK_STATUS_DOWN: Link always down + */ +enum pds_core_vf_link_status { + PDS_CORE_VF_LINK_STATUS_AUTO = 0, + PDS_CORE_VF_LINK_STATUS_UP = 1, + PDS_CORE_VF_LINK_STATUS_DOWN = 2, +}; + +/** + * struct pds_core_vf_setattr_cmd - Set VF attributes on the NIC + * @opcode: Opcode + * @attr: Attribute type (enum pds_core_vf_attr) + * @vf_index: VF index + * @macaddr: mac address + * @vlanid: vlan ID + * @maxrate: max Tx rate in Mbps + * @spoofchk: enable address spoof checking + * @trust: enable VF trust + * @linkstate: set link up or down + * @stats: stats addr struct + * @stats.pa: set DMA address for VF stats + * @stats.len: length of VF stats space + * @pad: force union to specific size + */ +struct pds_core_vf_setattr_cmd { + u8 opcode; + u8 attr; + __le16 vf_index; + union { + u8 macaddr[6]; + __le16 vlanid; + __le32 maxrate; + u8 spoofchk; + u8 trust; + u8 linkstate; + struct { + __le64 pa; + __le32 len; + } stats; + u8 pad[60]; + } __packed; +}; + +struct pds_core_vf_setattr_comp { + u8 status; + u8 attr; + __le16 vf_index; + __le16 comp_index; + u8 rsvd[9]; + u8 color; +}; + +/** + * struct pds_core_vf_getattr_cmd - Get VF attributes from the NIC + * @opcode: Opcode + * @attr: Attribute type (enum pds_core_vf_attr) + * @vf_index: VF index + */ +struct pds_core_vf_getattr_cmd { + u8 opcode; + u8 attr; + __le16 vf_index; +}; + +struct pds_core_vf_getattr_comp { + u8 status; + u8 attr; + __le16 vf_index; + union { + u8 macaddr[6]; + __le16 vlanid; + __le32 maxrate; + u8 spoofchk; + u8 trust; + u8 linkstate; + __le64 stats_pa; + u8 pad[11]; + } __packed; + u8 color; +}; + +enum pds_core_vf_ctrl_opcode { + PDS_CORE_VF_CTRL_START_ALL = 0, + PDS_CORE_VF_CTRL_START = 1, +}; + +/** + * struct pds_core_vf_ctrl_cmd - VF control command + * @opcode: Opcode for the command + * @ctrl_opcode: VF control operation type + * @vf_index: VF Index. It is unused if op START_ALL is used. + */ +struct pds_core_vf_ctrl_cmd { + u8 opcode; + u8 ctrl_opcode; + __le16 vf_index; +}; + +/** + * struct pds_core_vf_ctrl_comp - VF_CTRL command completion. + * @status: Status of the command (enum pds_core_status_code) + */ +struct pds_core_vf_ctrl_comp { + u8 status; +}; + +/* + * union pds_core_dev_cmd - Overlay of core device command structures + */ +union pds_core_dev_cmd { + u8 opcode; + u32 words[16]; + + struct pds_core_dev_identify_cmd identify; + struct pds_core_dev_init_cmd init; + struct pds_core_dev_reset_cmd reset; + struct pds_core_fw_download_cmd fw_download; + struct pds_core_fw_control_cmd fw_control; + + struct pds_core_vf_setattr_cmd vf_setattr; + struct pds_core_vf_getattr_cmd vf_getattr; + struct pds_core_vf_ctrl_cmd vf_ctrl; +}; + +/* + * union pds_core_dev_comp - Overlay of core device completion structures + */ +union pds_core_dev_comp { + u8 status; + u8 bytes[16]; + + struct pds_core_dev_identify_comp identify; + struct pds_core_dev_reset_comp reset; + struct pds_core_dev_init_comp init; + struct pds_core_fw_download_comp fw_download; + struct pds_core_fw_control_comp fw_control; + + struct pds_core_vf_setattr_comp vf_setattr; + struct pds_core_vf_getattr_comp vf_getattr; + struct pds_core_vf_ctrl_comp vf_ctrl; +}; + +/** + * struct pds_core_dev_hwstamp_regs - Hardware current timestamp registers + * @tick_low: Low 32 bits of hardware timestamp + * @tick_high: High 32 bits of hardware timestamp + */ +struct pds_core_dev_hwstamp_regs { + u32 tick_low; + u32 tick_high; +}; + +/** + * struct pds_core_dev_info_regs - Device info register format (read-only) + * @signature: Signature value of 0x44455649 ('DEVI') + * @version: Current version of info + * @asic_type: Asic type + * @asic_rev: Asic revision + * @fw_status: Firmware status + * bit 0 - 1 = fw running + * bit 4-7 - 4 bit generation number, changes on fw restart + * @fw_heartbeat: Firmware heartbeat counter + * @serial_num: Serial number + * @fw_version: Firmware version + * @oprom_regs: oprom_regs to store oprom debug enable/disable and bmp + * @rsvd_pad1024: Struct padding + * @hwstamp: Hardware current timestamp registers + * @rsvd_pad2048: Struct padding + */ +struct pds_core_dev_info_regs { +#define PDS_CORE_DEVINFO_FWVERS_BUFLEN 32 +#define PDS_CORE_DEVINFO_SERIAL_BUFLEN 32 + u32 signature; + u8 version; + u8 asic_type; + u8 asic_rev; +#define PDS_CORE_FW_STS_F_RUNNING 0x01 +#define PDS_CORE_FW_STS_F_GENERATION 0xF0 + u8 fw_status; + __le32 fw_heartbeat; + char fw_version[PDS_CORE_DEVINFO_FWVERS_BUFLEN]; + char serial_num[PDS_CORE_DEVINFO_SERIAL_BUFLEN]; + u8 oprom_regs[32]; /* reserved */ + u8 rsvd_pad1024[916]; + struct pds_core_dev_hwstamp_regs hwstamp; /* on 1k boundary */ + u8 rsvd_pad2048[1016]; +} __packed; + +/** + * struct pds_core_dev_cmd_regs - Device command register format (read-write) + * @doorbell: Device Cmd Doorbell, write-only + * Write a 1 to signal device to process cmd + * @done: Command completed indicator, poll for completion + * bit 0 == 1 when command is complete + * @cmd: Opcode-specific command bytes + * @comp: Opcode-specific response bytes + * @rsvd: Struct padding + * @data: Opcode-specific side-data + */ +struct pds_core_dev_cmd_regs { + u32 doorbell; + u32 done; + union pds_core_dev_cmd cmd; + union pds_core_dev_comp comp; + u8 rsvd[48]; + u32 data[478]; +} __packed; + +/** + * struct pds_core_dev_regs - Device register format for bar 0 page 0 + * @info: Device info registers + * @devcmd: Device command registers + */ +struct pds_core_dev_regs { + struct pds_core_dev_info_regs info; + struct pds_core_dev_cmd_regs devcmd; +} __packed; + +/* + * struct pds_core_vf_stats - VF statistics structure + */ +struct pds_core_vf_stats { + /* RX */ + __le64 rx_ucast_bytes; + __le64 rx_ucast_packets; + __le64 rx_mcast_bytes; + __le64 rx_mcast_packets; + __le64 rx_bcast_bytes; + __le64 rx_bcast_packets; + __le64 rsvd0; + __le64 rsvd1; + /* RX drops */ + __le64 rx_ucast_drop_bytes; + __le64 rx_ucast_drop_packets; + __le64 rx_mcast_drop_bytes; + __le64 rx_mcast_drop_packets; + __le64 rx_bcast_drop_bytes; + __le64 rx_bcast_drop_packets; + __le64 rx_dma_error; + __le64 rsvd2; + /* TX */ + __le64 tx_ucast_bytes; + __le64 tx_ucast_packets; + __le64 tx_mcast_bytes; + __le64 tx_mcast_packets; + __le64 tx_bcast_bytes; + __le64 tx_bcast_packets; + __le64 rsvd3; + __le64 rsvd4; + /* TX drops */ + __le64 tx_ucast_drop_bytes; + __le64 tx_ucast_drop_packets; + __le64 tx_mcast_drop_bytes; + __le64 tx_mcast_drop_packets; + __le64 tx_bcast_drop_bytes; + __le64 tx_bcast_drop_packets; + __le64 tx_dma_error; + __le64 rsvd5; +}; + +#ifndef __CHECKER__ +static_assert(sizeof(struct pds_core_drv_identity) <= 1912); +static_assert(sizeof(struct pds_core_dev_identity) <= 1912); +static_assert(sizeof(union pds_core_dev_cmd) == 64); +static_assert(sizeof(union pds_core_dev_comp) == 16); +static_assert(sizeof(struct pds_core_dev_info_regs) == 2048); +static_assert(sizeof(struct pds_core_dev_cmd_regs) == 2048); +static_assert(sizeof(struct pds_core_dev_regs) == 4096); +#endif /* __CHECKER__ */ + +#endif /* _PDS_CORE_REGS_H_ */ From patchwork Wed Dec 7 00:44:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066438 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7730DC4708D for ; Wed, 7 Dec 2022 00:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbiLGAp1 (ORCPT ); Tue, 6 Dec 2022 19:45:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbiLGApN (ORCPT ); Tue, 6 Dec 2022 19:45:13 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2042.outbound.protection.outlook.com [40.107.220.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9A8D2AE3E for ; Tue, 6 Dec 2022 16:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=klACIoC9Qfn1DjX7wH6yXw/3Tq/9VxFw594ELixLiWXn8hSuU6ymP7OoL9jgt5NszDXn9Hdzu+iXbRv8lM7F8rMUvbNSDOsNxCQzxM8R2DlRpcibJShqyNpq/qKJxARD7Mi9Y5SjAP8CJanr/Y0uF5oeuMbP10L0EorvMaRls539uhaCNdnj6pbFeNxeEjOoAutPGVYu+B8RLsr4UliS8TBnHpPhm+EVpO2QN68lg8OpuyMPUDQoMUlUgXZ/1cks+qKkg0eh1uf2KQ//pocC5j4kWAFOXhsczjNdJNqLwzaR9rxOiufOuKakcFvtsTwf9hl7ZMyAhRF3rJeVKCLzTg== 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=H3GikLoi5QhjYyBpPiQGInfW5aoc0DDhPA2UjFnZaQE=; b=MdjY2j/NyAxDoN3KIQwqOGuFoyQDweyNOtO9U1/nNbgHLiFuV7kTJaIZeH+zLfuMJZfRRadhKAQJf+Kg5X7No+//M73IMvMLEDgDgY9LAoSdCNWhlQzL/0ixPdqW2oXCdUUiZ1j17Erqihdsp4jaEnQ+1a/B2Do1Ak9X5E/EV/KZcQzhgq02dkwNAudAUOzH9MpNaHx8sb0aG1OarkAdVXPAkHhH7YQq1qFgVHni3Jd6ZVij+26brtmWR+3P1MtbUEl+zQl6S4hqFyQya1zg+IUsEapkNGdFXAeSniKqumtwrZSy9A6DX8axrFmQwAVDX6S6n+2gtO1zyVPkDXLR3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H3GikLoi5QhjYyBpPiQGInfW5aoc0DDhPA2UjFnZaQE=; b=f3nxct5mmR+wafjWFBOmTkx2t9JFrO2GffFAc2JmC6D1FI9dr6g4GNeCuxttu/hfzhfi0u/PSZDyYd2Tu/N908QGsdmnz7++HOOCJgrJl+IzW0Z5/kk7kDxWV3SBHFLlv3Eruc2ZPVmLVeY1WCU+Rztc5SHjRLT6ILJbDS+5S8s= Received: from BN0PR03CA0018.namprd03.prod.outlook.com (2603:10b6:408:e6::23) by DM4PR12MB6352.namprd12.prod.outlook.com (2603:10b6:8:a0::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.23; Wed, 7 Dec 2022 00:45:08 +0000 Received: from BN8NAM11FT105.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e6:cafe::1b) by BN0PR03CA0018.outlook.office365.com (2603:10b6:408:e6::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT105.mail.protection.outlook.com (10.13.176.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:08 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:07 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 04/16] pds_core: add devcmd device interfaces Date: Tue, 6 Dec 2022 16:44:31 -0800 Message-ID: <20221207004443.33779-5-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT105:EE_|DM4PR12MB6352:EE_ X-MS-Office365-Filtering-Correlation-Id: bf117fd8-1b6f-44e4-2dea-08dad7ec4a1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OHfahXsNA+jMaog5omOpS8/idoRB9dPUr5KeZ69DgHFztvMTSEqOkTy5BI0OfS7nrnxMXF2ziAwf70JzZiXH2r923FWiSPQskU7nNayo7l3PTIyCdxKa+PPyYIMvuieKmAa2qntQzIOF2zUUVaCtIRQZFo0NSeREkuvjQE8I6X9e1S/cmWc6Gy74iupP4U4YkJhOkgZRvOh9jgMDRWa3Nj6gUciSTijibamFZabdCNZraP+s7p0DHWleARvazO8zjKOUlEBjoGb+xALWS6h3QulWOfWS6bE5DCO/IxSb1SATspMHqj+hTSeWnjKMw8ybHOv4bbRMIE9BPuEAHoUn3gK8kR+G1eSWOFBQpuVNGn/QCOBEzO9Yo48/X7tBmMz/VrI2U6RwS6FOmsSLE1GJaQj95a4R+cW4k4xhUbPkjl2ufcYcY0ZWi6SWKXFQPsor0/Js9m6IyNZiQ+NqI8YclZFIRlLz32rEj1KGQ+0UzxsHIME8SOKg+3w9pTGOoCuUpjAfDSLSWaLVgJkw2GccZVGehByCN+YG2q2jrRZaCUSiCd5/IZzDFYzP8dWD7d0+4D704+q8FTfrDNlbkrprdEqH+9mRx7gnxxPT04z9pnQXHaNIXpZuG4JH3RSgb+GUd/cQ+0ozb9SuTDwljTbcCc+YA2GRN9tJiN/FSJZ4/tocigszmSACTsbDdv6pfkOlzYOtULTyuhjZ3BgeZq7ap8oGfedwTHv4Z0Q1HSIS4N0= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(39860400002)(136003)(346002)(451199015)(40470700004)(46966006)(36840700001)(6666004)(82740400003)(81166007)(478600001)(82310400005)(356005)(8936002)(316002)(36860700001)(26005)(110136005)(36756003)(54906003)(86362001)(5660300002)(40460700003)(40480700001)(8676002)(70586007)(1076003)(70206006)(41300700001)(2616005)(83380400001)(44832011)(426003)(186003)(30864003)(47076005)(336012)(4326008)(16526019)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:08.1623 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf117fd8-1b6f-44e4-2dea-08dad7ec4a1e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT105.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6352 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The devcmd interface is the basic connection to the device through the PCI BAR for low level identification and command services. This does the early device initialization and finds the identity data, and adds devcmd routines to be used by later driver bits. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/pds_core/Makefile | 4 +- drivers/net/ethernet/pensando/pds_core/core.c | 43 +++ drivers/net/ethernet/pensando/pds_core/core.h | 55 +++ .../net/ethernet/pensando/pds_core/debugfs.c | 67 ++++ drivers/net/ethernet/pensando/pds_core/dev.c | 355 ++++++++++++++++++ drivers/net/ethernet/pensando/pds_core/main.c | 30 ++ include/linux/pds/pds_common.h | 67 ++++ include/linux/pds/pds_intr.h | 160 ++++++++ 8 files changed, 780 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/pensando/pds_core/core.c create mode 100644 drivers/net/ethernet/pensando/pds_core/dev.c create mode 100644 include/linux/pds/pds_intr.h diff --git a/drivers/net/ethernet/pensando/pds_core/Makefile b/drivers/net/ethernet/pensando/pds_core/Makefile index 72bbc5fa68ad..446054206b6a 100644 --- a/drivers/net/ethernet/pensando/pds_core/Makefile +++ b/drivers/net/ethernet/pensando/pds_core/Makefile @@ -4,6 +4,8 @@ obj-$(CONFIG_PDS_CORE) := pds_core.o pds_core-y := main.o \ - devlink.o + devlink.o \ + dev.o \ + core.o pds_core-$(CONFIG_DEBUG_FS) += debugfs.o diff --git a/drivers/net/ethernet/pensando/pds_core/core.c b/drivers/net/ethernet/pensando/pds_core/core.c new file mode 100644 index 000000000000..d846e8b93575 --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/core.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2022 Pensando Systems, Inc */ + +#include +#include +#include +#include +#include +#include + +#include "core.h" + +int pdsc_setup(struct pdsc *pdsc, bool init) +{ + int err = 0; + + if (init) + err = pdsc_dev_init(pdsc); + else + err = pdsc_dev_reinit(pdsc); + if (err) + return err; + + clear_bit(PDSC_S_FW_DEAD, &pdsc->state); + return 0; +} + +void pdsc_teardown(struct pdsc *pdsc, bool removing) +{ + pdsc_devcmd_reset(pdsc); + + if (removing && pdsc->intr_info) { + devm_kfree(pdsc->dev, pdsc->intr_info); + pdsc->intr_info = NULL; + } + + if (pdsc->kern_dbpage) { + iounmap(pdsc->kern_dbpage); + pdsc->kern_dbpage = NULL; + } + + set_bit(PDSC_S_FW_DEAD, &pdsc->state); +} diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h index 022adc4aea01..d0d2c395ba25 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.h +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -9,8 +9,13 @@ #include #include +#include #define PDSC_DRV_DESCRIPTION "Pensando Core PF Driver" +#define PDSC_TEARDOWN_RECOVERY false +#define PDSC_TEARDOWN_REMOVING true +#define PDSC_SETUP_RECOVERY false +#define PDSC_SETUP_INIT true struct pdsc_dev_bar { void __iomem *vaddr; @@ -19,6 +24,22 @@ struct pdsc_dev_bar { int res_index; }; +struct pdsc_devinfo { + u8 asic_type; + u8 asic_rev; + char fw_version[PDS_CORE_DEVINFO_FWVERS_BUFLEN + 1]; + char serial_num[PDS_CORE_DEVINFO_SERIAL_BUFLEN + 1]; +}; + +#define PDSC_INTR_NAME_MAX_SZ 32 + +struct pdsc_intr_info { + char name[PDSC_INTR_NAME_MAX_SZ]; + unsigned int index; + unsigned int vector; + void *data; +}; + /* No state flags set means we are in a steady running state */ enum pdsc_state_flags { PDSC_S_FW_DEAD, /* fw stopped, waiting for startup or recovery */ @@ -34,11 +55,24 @@ struct pdsc { struct dentry *dentry; struct device *dev; struct pdsc_dev_bar bars[PDS_CORE_BARS_MAX]; + int num_vfs; int hw_index; int id; unsigned long state; + u8 fw_status; + u8 fw_generation; + unsigned long last_fw_time; + u32 last_hb; + struct pdsc_devinfo dev_info; + struct pds_core_dev_identity dev_ident; + unsigned int nintrs; + struct pdsc_intr_info *intr_info; /* array of nintrs elements */ + + unsigned int devcmd_timeout; + struct mutex devcmd_lock; /* lock for dev_cmd operations */ + struct mutex config_lock; /* lock for configuration operations */ struct pds_core_dev_info_regs __iomem *info_regs; struct pds_core_dev_cmd_regs __iomem *cmd_regs; struct pds_core_intr __iomem *intr_ctrl; @@ -48,6 +82,8 @@ struct pdsc { u64 __iomem *kern_dbpage; }; +void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num); + struct pdsc *pdsc_dl_alloc(struct device *dev); void pdsc_dl_free(struct pdsc *pdsc); int pdsc_dl_register(struct pdsc *pdsc); @@ -58,11 +94,30 @@ void pdsc_debugfs_create(void); void pdsc_debugfs_destroy(void); void pdsc_debugfs_add_dev(struct pdsc *pdsc); void pdsc_debugfs_del_dev(struct pdsc *pdsc); +void pdsc_debugfs_add_ident(struct pdsc *pdsc); +void pdsc_debugfs_add_irqs(struct pdsc *pdsc); #else static inline void pdsc_debugfs_create(void) { } static inline void pdsc_debugfs_destroy(void) { } static inline void pdsc_debugfs_add_dev(struct pdsc *pdsc) { } static inline void pdsc_debugfs_del_dev(struct pdsc *pdsc) { } +static inline void pdsc_debugfs_add_ident(struct pdsc *pdsc) { } +static inline void pdsc_debugfs_add_irqs(struct pdsc *pdsc) { } #endif +int pdsc_err_to_errno(enum pds_core_status_code code); +bool pdsc_is_fw_running(struct pdsc *pdsc); +bool pdsc_is_fw_good(struct pdsc *pdsc); +int pdsc_devcmd(struct pdsc *pdsc, union pds_core_dev_cmd *cmd, + union pds_core_dev_comp *comp, int max_seconds); +int pdsc_devcmd_locked(struct pdsc *pdsc, union pds_core_dev_cmd *cmd, + union pds_core_dev_comp *comp, int max_seconds); +int pdsc_devcmd_init(struct pdsc *pdsc); +int pdsc_devcmd_reset(struct pdsc *pdsc); +int pdsc_dev_reinit(struct pdsc *pdsc); +int pdsc_dev_init(struct pdsc *pdsc); + +int pdsc_setup(struct pdsc *pdsc, bool init); +void pdsc_teardown(struct pdsc *pdsc, bool removing); + #endif /* _PDSC_H_ */ diff --git a/drivers/net/ethernet/pensando/pds_core/debugfs.c b/drivers/net/ethernet/pensando/pds_core/debugfs.c index 3f876dcc5431..698fd6d09387 100644 --- a/drivers/net/ethernet/pensando/pds_core/debugfs.c +++ b/drivers/net/ethernet/pensando/pds_core/debugfs.c @@ -44,4 +44,71 @@ void pdsc_debugfs_del_dev(struct pdsc *pdsc) debugfs_remove_recursive(pdsc->dentry); pdsc->dentry = NULL; } + +static int identity_show(struct seq_file *seq, void *v) +{ + struct pdsc *pdsc = seq->private; + struct pds_core_dev_identity *ident; + int vt; + + ident = &pdsc->dev_ident; + + seq_printf(seq, "asic_type: 0x%x\n", pdsc->dev_info.asic_type); + seq_printf(seq, "asic_rev: 0x%x\n", pdsc->dev_info.asic_rev); + seq_printf(seq, "serial_num: %s\n", pdsc->dev_info.serial_num); + seq_printf(seq, "fw_version: %s\n", pdsc->dev_info.fw_version); + seq_printf(seq, "fw_status: 0x%x\n", + ioread8(&pdsc->info_regs->fw_status)); + seq_printf(seq, "fw_heartbeat: 0x%x\n", + ioread32(&pdsc->info_regs->fw_heartbeat)); + + seq_printf(seq, "nlifs: %d\n", le32_to_cpu(ident->nlifs)); + seq_printf(seq, "nintrs: %d\n", le32_to_cpu(ident->nintrs)); + seq_printf(seq, "ndbpgs_per_lif: %d\n", le32_to_cpu(ident->ndbpgs_per_lif)); + seq_printf(seq, "intr_coal_mult: %d\n", le32_to_cpu(ident->intr_coal_mult)); + seq_printf(seq, "intr_coal_div: %d\n", le32_to_cpu(ident->intr_coal_div)); + + seq_puts(seq, "vif_types: "); + for (vt = 0; vt < PDS_DEV_TYPE_MAX; vt++) + seq_printf(seq, "%d ", le16_to_cpu(pdsc->dev_ident.vif_types[vt])); + seq_puts(seq, "\n"); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(identity); + +void pdsc_debugfs_add_ident(struct pdsc *pdsc) +{ + debugfs_create_file("identity", 0400, pdsc->dentry, pdsc, &identity_fops); +} + +static int irqs_show(struct seq_file *seq, void *v) +{ + struct pdsc *pdsc = seq->private; + struct pdsc_intr_info *intr_info; + int i; + + seq_printf(seq, "index vector name (nintrs %d)\n", pdsc->nintrs); + + if (!pdsc->intr_info) + return 0; + + for (i = 0; i < pdsc->nintrs; i++) { + intr_info = &pdsc->intr_info[i]; + if (!intr_info->vector) + continue; + + seq_printf(seq, "% 3d % 3d %s\n", + i, intr_info->vector, intr_info->name); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(irqs); + +void pdsc_debugfs_add_irqs(struct pdsc *pdsc) +{ + debugfs_create_file("irqs", 0400, pdsc->dentry, pdsc, &irqs_fops); +} + #endif /* CONFIG_DEBUG_FS */ diff --git a/drivers/net/ethernet/pensando/pds_core/dev.c b/drivers/net/ethernet/pensando/pds_core/dev.c new file mode 100644 index 000000000000..1f1193706407 --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/dev.c @@ -0,0 +1,355 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2022 Pensando Systems, Inc */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core.h" + +int pdsc_err_to_errno(enum pds_core_status_code code) +{ + switch (code) { + case PDS_RC_SUCCESS: + return 0; + case PDS_RC_EVERSION: + case PDS_RC_EQTYPE: + case PDS_RC_EQID: + case PDS_RC_EINVAL: + case PDS_RC_ENOSUPP: + return -EINVAL; + case PDS_RC_EPERM: + return -EPERM; + case PDS_RC_ENOENT: + return -ENOENT; + case PDS_RC_EAGAIN: + return -EAGAIN; + case PDS_RC_ENOMEM: + return -ENOMEM; + case PDS_RC_EFAULT: + return -EFAULT; + case PDS_RC_EBUSY: + return -EBUSY; + case PDS_RC_EEXIST: + return -EEXIST; + case PDS_RC_EVFID: + return -ENODEV; + case PDS_RC_ECLIENT: + return -ECHILD; + case PDS_RC_ENOSPC: + return -ENOSPC; + case PDS_RC_ERANGE: + return -ERANGE; + case PDS_RC_BAD_ADDR: + return -EFAULT; + case PDS_RC_EOPCODE: + case PDS_RC_EINTR: + case PDS_RC_DEV_CMD: + case PDS_RC_ERROR: + case PDS_RC_ERDMA: + case PDS_RC_EIO: + default: + return -EIO; + } +} + +bool pdsc_is_fw_running(struct pdsc *pdsc) +{ + pdsc->fw_status = ioread8(&pdsc->info_regs->fw_status); + pdsc->last_fw_time = jiffies; + pdsc->last_hb = ioread32(&pdsc->info_regs->fw_heartbeat); + + /* Firmware is useful only if the running bit is set and + * fw_status != 0xff (bad PCI read) + */ + return (pdsc->fw_status != 0xff) && + (pdsc->fw_status & PDS_CORE_FW_STS_F_RUNNING); +} + +bool pdsc_is_fw_good(struct pdsc *pdsc) +{ + return pdsc_is_fw_running(pdsc) && + (pdsc->fw_status & PDS_CORE_FW_STS_F_GENERATION) == pdsc->fw_generation; +} + +static u8 pdsc_devcmd_status(struct pdsc *pdsc) +{ + return ioread8(&pdsc->cmd_regs->comp.status); +} + +static bool pdsc_devcmd_done(struct pdsc *pdsc) +{ + return ioread32(&pdsc->cmd_regs->done) & PDS_CORE_DEV_CMD_DONE; +} + +static void pdsc_devcmd_dbell(struct pdsc *pdsc) +{ + iowrite32(0, &pdsc->cmd_regs->done); + iowrite32(1, &pdsc->cmd_regs->doorbell); +} + +static void pdsc_devcmd_clean(struct pdsc *pdsc) +{ + iowrite32(0, &pdsc->cmd_regs->doorbell); + memset_io(&pdsc->cmd_regs->cmd, 0, sizeof(pdsc->cmd_regs->cmd)); +} + +static const char *pdsc_devcmd_str(int opcode) +{ + switch (opcode) { + case PDS_CORE_CMD_NOP: + return "PDS_CORE_CMD_NOP"; + case PDS_CORE_CMD_IDENTIFY: + return "PDS_CORE_CMD_IDENTIFY"; + case PDS_CORE_CMD_RESET: + return "PDS_CORE_CMD_RESET"; + case PDS_CORE_CMD_INIT: + return "PDS_CORE_CMD_INIT"; + case PDS_CORE_CMD_FW_DOWNLOAD: + return "PDS_CORE_CMD_FW_DOWNLOAD"; + case PDS_CORE_CMD_FW_CONTROL: + return "PDS_CORE_CMD_FW_CONTROL"; + default: + return "PDS_CORE_CMD_UNKNOWN"; + } +} + +static int pdsc_devcmd_wait(struct pdsc *pdsc, int max_seconds) +{ + struct device *dev = pdsc->dev; + unsigned long start_time; + unsigned long max_wait; + unsigned long duration; + int timeout = 0; + int status = 0; + int done = 0; + int err = 0; + int opcode; + + opcode = ioread8(&pdsc->cmd_regs->cmd.opcode); + + start_time = jiffies; + max_wait = start_time + (max_seconds * HZ); + + while (!done && !timeout) { + done = pdsc_devcmd_done(pdsc); + if (done) + break; + + timeout = time_after(jiffies, max_wait); + if (timeout) + break; + + usleep_range(100, 200); + } + duration = jiffies - start_time; + + if (done && duration > HZ) + dev_dbg(dev, "DEVCMD %d %s after %ld secs\n", + opcode, pdsc_devcmd_str(opcode), duration / HZ); + + if (!done || timeout) { + dev_err(dev, "DEVCMD %d %s timeout, done %d timeout %d max_seconds=%d\n", + opcode, pdsc_devcmd_str(opcode), done, timeout, + max_seconds); + err = -ETIMEDOUT; + pdsc_devcmd_clean(pdsc); + } + + status = pdsc_devcmd_status(pdsc); + err = pdsc_err_to_errno(status); + if (status != PDS_RC_SUCCESS && status != PDS_RC_EAGAIN) + dev_err(dev, "DEVCMD %d %s failed, status=%d err %d %pe\n", + opcode, pdsc_devcmd_str(opcode), status, err, + ERR_PTR(err)); + + return err; +} + +int pdsc_devcmd_locked(struct pdsc *pdsc, union pds_core_dev_cmd *cmd, + union pds_core_dev_comp *comp, int max_seconds) +{ + int err; + + memcpy_toio(&pdsc->cmd_regs->cmd, cmd, sizeof(*cmd)); + pdsc_devcmd_dbell(pdsc); + err = pdsc_devcmd_wait(pdsc, max_seconds); + memcpy_fromio(comp, &pdsc->cmd_regs->comp, sizeof(*comp)); + + return err; +} + +int pdsc_devcmd(struct pdsc *pdsc, union pds_core_dev_cmd *cmd, + union pds_core_dev_comp *comp, int max_seconds) +{ + int err; + + mutex_lock(&pdsc->devcmd_lock); + err = pdsc_devcmd_locked(pdsc, cmd, comp, max_seconds); + mutex_unlock(&pdsc->devcmd_lock); + + return err; +} + +int pdsc_devcmd_init(struct pdsc *pdsc) +{ + union pds_core_dev_comp comp = { 0 }; + union pds_core_dev_cmd cmd = { + .opcode = PDS_CORE_CMD_INIT, + }; + + return pdsc_devcmd(pdsc, &cmd, &comp, pdsc->devcmd_timeout); +} + +int pdsc_devcmd_reset(struct pdsc *pdsc) +{ + union pds_core_dev_comp comp = { 0 }; + union pds_core_dev_cmd cmd = { + .reset.opcode = PDS_CORE_CMD_RESET, + }; + + return pdsc_devcmd(pdsc, &cmd, &comp, pdsc->devcmd_timeout); +} + +static int pdsc_devcmd_identify_locked(struct pdsc *pdsc) +{ + union pds_core_dev_comp comp = { 0 }; + union pds_core_dev_cmd cmd = { + .identify.opcode = PDS_CORE_CMD_IDENTIFY, + .identify.ver = PDS_CORE_IDENTITY_VERSION_1, + }; + + return pdsc_devcmd_locked(pdsc, &cmd, &comp, pdsc->devcmd_timeout); +} + +static void pdsc_init_devinfo(struct pdsc *pdsc) +{ + pdsc->dev_info.asic_type = ioread8(&pdsc->info_regs->asic_type); + pdsc->dev_info.asic_rev = ioread8(&pdsc->info_regs->asic_rev); + + memcpy_fromio(pdsc->dev_info.fw_version, + pdsc->info_regs->fw_version, + PDS_CORE_DEVINFO_FWVERS_BUFLEN); + + memcpy_fromio(pdsc->dev_info.serial_num, + pdsc->info_regs->serial_num, + PDS_CORE_DEVINFO_SERIAL_BUFLEN); + + pdsc->dev_info.fw_version[PDS_CORE_DEVINFO_FWVERS_BUFLEN] = 0; + pdsc->dev_info.serial_num[PDS_CORE_DEVINFO_SERIAL_BUFLEN] = 0; + + dev_dbg(pdsc->dev, "fw_version %s\n", pdsc->dev_info.fw_version); +} + +static int pdsc_identify(struct pdsc *pdsc) +{ + struct pds_core_drv_identity drv = { 0 }; + size_t sz; + int err; + + drv.drv_type = cpu_to_le32(PDS_DRIVER_LINUX); + drv.kernel_ver = cpu_to_le32(LINUX_VERSION_CODE); + snprintf(drv.kernel_ver_str, sizeof(drv.kernel_ver_str), + "%s %s", utsname()->release, utsname()->version); + snprintf(drv.driver_ver_str, sizeof(drv.driver_ver_str), + "%s %s", PDS_CORE_DRV_NAME, utsname()->release); + + /* Next let's get some info about the device + * We use the devcmd_lock at this level in order to + * get safe access to the cmd_regs->data before anyone + * else can mess it up + */ + mutex_lock(&pdsc->devcmd_lock); + + sz = min_t(size_t, sizeof(drv), sizeof(pdsc->cmd_regs->data)); + memcpy_toio(&pdsc->cmd_regs->data, &drv, sz); + + err = pdsc_devcmd_identify_locked(pdsc); + if (!err) { + sz = min_t(size_t, sizeof(pdsc->dev_ident), sizeof(pdsc->cmd_regs->data)); + memcpy_fromio(&pdsc->dev_ident, &pdsc->cmd_regs->data, sz); + } + mutex_unlock(&pdsc->devcmd_lock); + + if (err) { + dev_err(pdsc->dev, "Cannot identify device: %pe\n", ERR_PTR(err)); + return err; + } + + if (isprint(pdsc->dev_info.fw_version[0]) && + isascii(pdsc->dev_info.fw_version[0])) + dev_info(pdsc->dev, "FW: %.*s\n", + (int)(sizeof(pdsc->dev_info.fw_version) - 1), + pdsc->dev_info.fw_version); + else + dev_info(pdsc->dev, "FW: (invalid string) 0x%02x 0x%02x 0x%02x 0x%02x ...\n", + (u8)pdsc->dev_info.fw_version[0], + (u8)pdsc->dev_info.fw_version[1], + (u8)pdsc->dev_info.fw_version[2], + (u8)pdsc->dev_info.fw_version[3]); + + return 0; +} + +int pdsc_dev_reinit(struct pdsc *pdsc) +{ + pdsc_init_devinfo(pdsc); + + return pdsc_identify(pdsc); +} + +int pdsc_dev_init(struct pdsc *pdsc) +{ + unsigned int nintrs; + int err; + + /* Initial init and reset of device */ + pdsc_init_devinfo(pdsc); + pdsc->devcmd_timeout = PDS_CORE_DEVCMD_TIMEOUT; + + err = pdsc_devcmd_reset(pdsc); + if (err) + return err; + + err = pdsc_identify(pdsc); + if (err) + return err; + + pdsc_debugfs_add_ident(pdsc); + + /* Now we can reserve interrupts */ + nintrs = le32_to_cpu(pdsc->dev_ident.nintrs); + nintrs = min_t(unsigned int, num_online_cpus(), nintrs); + + /* Get intr_info struct array for tracking */ + pdsc->intr_info = devm_kcalloc(pdsc->dev, nintrs, + sizeof(*pdsc->intr_info), GFP_KERNEL); + if (!pdsc->intr_info) { + err = -ENOSPC; + goto err_out; + } + + err = pci_alloc_irq_vectors(pdsc->pdev, nintrs, nintrs, PCI_IRQ_MSIX); + if (err != nintrs) { + dev_err(pdsc->dev, "Can't get %d intrs from OS: %pe\n", + nintrs, ERR_PTR(err)); + err = -ENOSPC; + goto err_out; + } + pdsc->nintrs = nintrs; + pdsc_debugfs_add_irqs(pdsc); + + return 0; + +err_out: + if (pdsc->intr_info) { + devm_kfree(pdsc->dev, pdsc->intr_info); + pdsc->intr_info = NULL; + } + return err; +} diff --git a/drivers/net/ethernet/pensando/pds_core/main.c b/drivers/net/ethernet/pensando/pds_core/main.c index 4bdbcc1c17a7..770b3f895bbb 100644 --- a/drivers/net/ethernet/pensando/pds_core/main.c +++ b/drivers/net/ethernet/pensando/pds_core/main.c @@ -189,6 +189,15 @@ static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (err) goto err_out_pci_disable_device; + /* PDS device setup */ + mutex_init(&pdsc->devcmd_lock); + mutex_init(&pdsc->config_lock); + + mutex_lock(&pdsc->config_lock); + err = pdsc_setup(pdsc, PDSC_SETUP_INIT); + if (err) + goto err_out_unmap_bars; + /* publish devlink device */ err = pdsc_dl_register(pdsc); if (err) { @@ -196,10 +205,21 @@ static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_out; } + mutex_unlock(&pdsc->config_lock); + + pdsc->fw_generation = PDS_CORE_FW_STS_F_GENERATION & + ioread8(&pdsc->info_regs->fw_status); + clear_bit(PDSC_S_INITING_DRIVER, &pdsc->state); return 0; err_out: + pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING); +err_out_unmap_bars: + mutex_unlock(&pdsc->config_lock); + mutex_destroy(&pdsc->config_lock); + mutex_destroy(&pdsc->devcmd_lock); + pci_free_irq_vectors(pdev); pci_clear_master(pdev); pdsc_unmap_bars(pdsc); pci_release_regions(pdev); @@ -224,10 +244,20 @@ static void pdsc_remove(struct pci_dev *pdev) */ pdsc_dl_unregister(pdsc); + /* Now we can lock it up and tear it down */ + mutex_lock(&pdsc->config_lock); + set_bit(PDSC_S_STOPPING_DRIVER, &pdsc->state); + /* Device teardown */ + pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING); + pdsc_debugfs_del_dev(pdsc); + mutex_unlock(&pdsc->config_lock); + mutex_destroy(&pdsc->config_lock); + mutex_destroy(&pdsc->devcmd_lock); ida_free(&pdsc_pf_ida, pdsc->id); /* PCI teardown */ + pci_free_irq_vectors(pdev); pci_clear_master(pdev); pdsc_unmap_bars(pdsc); pci_release_regions(pdev); diff --git a/include/linux/pds/pds_common.h b/include/linux/pds/pds_common.h index 7de3c1b8526b..e7fe84379a2f 100644 --- a/include/linux/pds/pds_common.h +++ b/include/linux/pds/pds_common.h @@ -10,4 +10,71 @@ #define PDS_CORE_ADDR_LEN 52 #define PDS_CORE_ADDR_MASK (BIT_ULL(PDS_ADDR_LEN) - 1) +/* + * enum pds_core_status_code - Device command return codes + */ +enum pds_core_status_code { + PDS_RC_SUCCESS = 0, /* Success */ + PDS_RC_EVERSION = 1, /* Incorrect version for request */ + PDS_RC_EOPCODE = 2, /* Invalid cmd opcode */ + PDS_RC_EIO = 3, /* I/O error */ + PDS_RC_EPERM = 4, /* Permission denied */ + PDS_RC_EQID = 5, /* Bad qid */ + PDS_RC_EQTYPE = 6, /* Bad qtype */ + PDS_RC_ENOENT = 7, /* No such element */ + PDS_RC_EINTR = 8, /* operation interrupted */ + PDS_RC_EAGAIN = 9, /* Try again */ + PDS_RC_ENOMEM = 10, /* Out of memory */ + PDS_RC_EFAULT = 11, /* Bad address */ + PDS_RC_EBUSY = 12, /* Device or resource busy */ + PDS_RC_EEXIST = 13, /* object already exists */ + PDS_RC_EINVAL = 14, /* Invalid argument */ + PDS_RC_ENOSPC = 15, /* No space left or alloc failure */ + PDS_RC_ERANGE = 16, /* Parameter out of range */ + PDS_RC_BAD_ADDR = 17, /* Descriptor contains a bad ptr */ + PDS_RC_DEV_CMD = 18, /* Device cmd attempted on AdminQ */ + PDS_RC_ENOSUPP = 19, /* Operation not supported */ + PDS_RC_ERROR = 29, /* Generic error */ + PDS_RC_ERDMA = 30, /* Generic RDMA error */ + PDS_RC_EVFID = 31, /* VF ID does not exist */ + PDS_RC_BAD_FW = 32, /* FW file is invalid or corrupted */ + PDS_RC_ECLIENT = 33, /* No such client id */ +}; + +enum pds_core_driver_type { + PDS_DRIVER_LINUX = 1, + PDS_DRIVER_WIN = 2, + PDS_DRIVER_DPDK = 3, + PDS_DRIVER_FREEBSD = 4, + PDS_DRIVER_IPXE = 5, + PDS_DRIVER_ESXI = 6, +}; + +/* PDSC interface uses identity version 1 and PDSC uses 2 */ +#define PDSC_IDENTITY_VERSION_1 1 +#define PDSC_IDENTITY_VERSION_2 2 + +#define PDS_CORE_IFNAMSIZ 16 + +/** + * enum pds_core_logical_qtype - Logical Queue Types + * @PDS_CORE_QTYPE_ADMINQ: Administrative Queue + * @PDS_CORE_QTYPE_NOTIFYQ: Notify Queue + * @PDS_CORE_QTYPE_RXQ: Receive Queue + * @PDS_CORE_QTYPE_TXQ: Transmit Queue + * @PDS_CORE_QTYPE_EQ: Event Queue + * @PDS_CORE_QTYPE_MAX: Max queue type supported + */ +enum pds_core_logical_qtype { + PDS_CORE_QTYPE_ADMINQ = 0, + PDS_CORE_QTYPE_NOTIFYQ = 1, + PDS_CORE_QTYPE_RXQ = 2, + PDS_CORE_QTYPE_TXQ = 3, + PDS_CORE_QTYPE_EQ = 4, + + PDS_CORE_QTYPE_MAX = 16 /* don't change - used in struct size */ +}; + +typedef void (*pds_core_cb)(void *cb_arg); + #endif /* _PDS_COMMON_H_ */ diff --git a/include/linux/pds/pds_intr.h b/include/linux/pds/pds_intr.h new file mode 100644 index 000000000000..bcdafd492e65 --- /dev/null +++ b/include/linux/pds/pds_intr.h @@ -0,0 +1,160 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) OR BSD-2-Clause */ +/* Copyright (c) 2022 Pensando Systems, Inc. All rights reserved. */ + +#ifndef _PDS_INTR_H_ +#define _PDS_INTR_H_ + +/* + * Interrupt control register + * @coal_init: Coalescing timer initial value, in + * device units. Use @identity->intr_coal_mult + * and @identity->intr_coal_div to convert from + * usecs to device units: + * + * coal_init = coal_usecs * coal_mutl / coal_div + * + * When an interrupt is sent the interrupt + * coalescing timer current value + * (@coalescing_curr) is initialized with this + * value and begins counting down. No more + * interrupts are sent until the coalescing + * timer reaches 0. When @coalescing_init=0 + * interrupt coalescing is effectively disabled + * and every interrupt assert results in an + * interrupt. Reset value: 0 + * @mask: Interrupt mask. When @mask=1 the interrupt + * resource will not send an interrupt. When + * @mask=0 the interrupt resource will send an + * interrupt if an interrupt event is pending + * or on the next interrupt assertion event. + * Reset value: 1 + * @credits: Interrupt credits. This register indicates + * how many interrupt events the hardware has + * sent. When written by software this + * register atomically decrements @int_credits + * by the value written. When @int_credits + * becomes 0 then the "pending interrupt" bit + * in the Interrupt Status register is cleared + * by the hardware and any pending but unsent + * interrupts are cleared. + * !!!IMPORTANT!!! This is a signed register. + * @flags: Interrupt control flags + * @unmask -- When this bit is written with a 1 + * the interrupt resource will set mask=0. + * @coal_timer_reset -- When this + * bit is written with a 1 the + * @coalescing_curr will be reloaded with + * @coalescing_init to reset the coalescing + * timer. + * @mask_on_assert: Automatically mask on assertion. When + * @mask_on_assert=1 the interrupt resource + * will set @mask=1 whenever an interrupt is + * sent. When using interrupts in Legacy + * Interrupt mode the driver must select + * @mask_on_assert=0 for proper interrupt + * operation. + * @coalescing_curr: Coalescing timer current value, in + * microseconds. When this value reaches 0 + * the interrupt resource is again eligible to + * send an interrupt. If an interrupt event + * is already pending when @coalescing_curr + * reaches 0 the pending interrupt will be + * sent, otherwise an interrupt will be sent + * on the next interrupt assertion event. + */ +struct pds_core_intr { + u32 coal_init; + u32 mask; + u16 credits; + u16 flags; +#define PDS_CORE_INTR_F_UNMASK 0x0001 +#define PDS_CORE_INTR_F_TIMER_RESET 0x0002 + u32 mask_on_assert; + u32 coalescing_curr; + u32 rsvd6[3]; +}; +#ifndef __CHECKER__ +static_assert(sizeof(struct pds_core_intr) == 32); +#endif /* __CHECKER__ */ + +#define PDS_CORE_INTR_CTRL_REGS_MAX 2048 +#define PDS_CORE_INTR_CTRL_COAL_MAX 0x3F +#define PDS_CORE_INTR_INDEX_NOT_ASSIGNED -1 + +struct pds_core_intr_status { + u32 status[2]; +}; + +/** + * enum pds_core_intr_mask_vals - valid values for mask and mask_assert. + * @PDS_CORE_INTR_MASK_CLEAR: unmask interrupt. + * @PDS_CORE_INTR_MASK_SET: mask interrupt. + */ +enum pds_core_intr_mask_vals { + PDS_CORE_INTR_MASK_CLEAR = 0, + PDS_CORE_INTR_MASK_SET = 1, +}; + +/** + * enum pds_core_intr_credits_bits - Bitwise composition of credits values. + * @PDS_CORE_INTR_CRED_COUNT: bit mask of credit count, no shift needed. + * @PDS_CORE_INTR_CRED_COUNT_SIGNED: bit mask of credit count, including sign bit. + * @PDS_CORE_INTR_CRED_UNMASK: unmask the interrupt. + * @PDS_CORE_INTR_CRED_RESET_COALESCE: reset the coalesce timer. + * @PDS_CORE_INTR_CRED_REARM: unmask the and reset the timer. + */ +enum pds_core_intr_credits_bits { + PDS_CORE_INTR_CRED_COUNT = 0x7fffu, + PDS_CORE_INTR_CRED_COUNT_SIGNED = 0xffffu, + PDS_CORE_INTR_CRED_UNMASK = 0x10000u, + PDS_CORE_INTR_CRED_RESET_COALESCE = 0x20000u, + PDS_CORE_INTR_CRED_REARM = (PDS_CORE_INTR_CRED_UNMASK | + PDS_CORE_INTR_CRED_RESET_COALESCE), +}; + +static inline void pds_core_intr_coal_init(struct pds_core_intr __iomem *intr_ctrl, + u32 coal) +{ + iowrite32(coal, &intr_ctrl->coal_init); +} + +static inline void pds_core_intr_mask(struct pds_core_intr __iomem *intr_ctrl, + u32 mask) +{ + iowrite32(mask, &intr_ctrl->mask); +} + +static inline void pds_core_intr_credits(struct pds_core_intr __iomem *intr_ctrl, + u32 cred, u32 flags) +{ + if (WARN_ON_ONCE(cred > PDS_CORE_INTR_CRED_COUNT)) { + cred = ioread32(&intr_ctrl->credits); + cred &= PDS_CORE_INTR_CRED_COUNT_SIGNED; + } + + iowrite32(cred | flags, &intr_ctrl->credits); +} + +static inline void pds_core_intr_clean_flags(struct pds_core_intr __iomem *intr_ctrl, + u32 flags) +{ + u32 cred; + + cred = ioread32(&intr_ctrl->credits); + cred &= PDS_CORE_INTR_CRED_COUNT_SIGNED; + cred |= flags; + iowrite32(cred, &intr_ctrl->credits); +} + +static inline void pds_core_intr_clean(struct pds_core_intr __iomem *intr_ctrl) +{ + pds_core_intr_clean_flags(intr_ctrl, PDS_CORE_INTR_CRED_RESET_COALESCE); +} + +static inline void pds_core_intr_mask_assert(struct pds_core_intr __iomem *intr_ctrl, + u32 mask) +{ + iowrite32(mask, &intr_ctrl->mask_on_assert); +} + +#endif /* _PDS_INTR_H_ */ From patchwork Wed Dec 7 00:44:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066436 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAA11C3A5A7 for ; Wed, 7 Dec 2022 00:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229796AbiLGApZ (ORCPT ); Tue, 6 Dec 2022 19:45:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbiLGApM (ORCPT ); Tue, 6 Dec 2022 19:45:12 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2072.outbound.protection.outlook.com [40.107.244.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEEC22FFF9 for ; Tue, 6 Dec 2022 16:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LGJX7jyi8Ie7Hh4LTqsXA9g+aARLV3/eO0DzLN5CQx8e1z46+QoJcRbufZ0/0U0bjNHvjgeM/zgSez8C7uRE6q1eURScRn9b5vBqk34iW58x9S3i2GXAJ7KjSd0VasyyP0KHMGDuK/cycDc6cilqwE8AxU2KDMaFHCaB+z0CccILDOTDaHFqfrF5h8cTfRBJBeo7ew5uLv/LMoi26/eLjG6PbZKuqkkomhOL1Ucsv6ijRUIAjHjggut0WB6lpHOxzMBRu1dQZt2uVwM96hn9mhTTcDij0FH6vSMFs1/4VadWUXrDii6zkyklXvBYqJqd2XTI7ZblU9pWsbo5o2SBkw== 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=4yqtZcnHBZBxfBfsGDJIYSsLt13lHqZVixgPtQG2nEw=; b=A889ChKx/cZUniMKFvQlN0qkCh49tEncnIF/Lh99Kq4DGBYjVIYtmqwRikpLHKAB8RefLZL0miUPuHw5Gu4pVpIcckntGa0mop6un3Q+2kgKPU+yNjS5QFJ7hrGHXUiF+tSKSjtmSR+x/PKNfnQkE3O8oBMy8E2YgipxiGsPL94z3heHcIlj5Pu/m9cO7hTOhKMwbXO1mlHIeBLVTeI05PFRNb8OD8IARn7KMD4sKTP9TjbXS1AsMoszOFJjDnSRIdOM+ntuOb97KtcsCnujquXEReAjA+kBcvl0qJEoMZa+LDI5YominBdwnfUIGJoStAB3aQy6BIBIzz1PMwzZcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4yqtZcnHBZBxfBfsGDJIYSsLt13lHqZVixgPtQG2nEw=; b=dZD63r8x9EcWcHih6IzEGe/tHSPj4ZnWNSOTe3wO1l6Q9Dg7dsOrzyKgYy3I8+5XHqyxvO0+c/vZ57E/eajdthmmshdcep66ls/xljMrw5otppzLFpEQnzardYumRoxoBQSqVPsKsNoRovihSXY0hztMWTeDtohioIdlregtNPU= Received: from BN0PR03CA0004.namprd03.prod.outlook.com (2603:10b6:408:e6::9) by IA0PR12MB7580.namprd12.prod.outlook.com (2603:10b6:208:43b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:08 +0000 Received: from BN8NAM11FT105.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e6:cafe::44) by BN0PR03CA0004.outlook.office365.com (2603:10b6:408:e6::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT105.mail.protection.outlook.com (10.13.176.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:08 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:07 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 05/16] pds_core: health timer and workqueue Date: Tue, 6 Dec 2022 16:44:32 -0800 Message-ID: <20221207004443.33779-6-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT105:EE_|IA0PR12MB7580:EE_ X-MS-Office365-Filtering-Correlation-Id: c70042a3-7f9c-4e1a-3c05-08dad7ec4a6f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tjSdnGJM4BhHnj/4mgw+Rv7wfvWUeRl2aRZJCna2ZIBlnn9whJr/aH35zutailG3CtyYIPriJEfTGkQxadvGaeoG7Fb/8pAFHztbbXIUD2uFkhLvH9oYEtAl4+sETe1+3bYIRhjCwAhwUbp34cb5DjdBL5N3SdbPTOkZXNi+LVQVIt7dHJVmmaL7D0jG0YP02AuLS4fTGIC4Ffof1Hp7Po5Ff8RHp1/Ip81/4x3/IaDNbDacSXz/xD/LP1HWezvn7RznTazMA0Y+/Xb/QqSaruupmTwN6lmwoiqWeXpeV1aJMcBLwUSDIPSXsRADT8fLMJHqRJmrICF7Hi60csuzAzgz5ItcGpEBLWTcJOrgxlnQg7Ti9uG4qRoWC1ZddPnxXyx6u7v9KwmJyVFXoBqWEkcsm7b84fh6M4thdQEfNE9TKcDsR8MHmTHRe0/tolDEHZ5fse6S2MaxpObPMUVk3fOaNdL2skUlXe/JbVVFjFz6n/+NaF4r9WyeZg2Gx9I1QG/qYc8b4j/sGX6wTGqOCuoBn1MgqGnMr1DiWt9SETyh4ILKCh9PpkppDtk5UHRYMCGxE4wSJG7sCcK6iK3Yn++xEu3uTb/AgYoQza/o4u2whT+BIqnDcYpjCeacL0Pz2IFzGz6bcgytNjP2C1s2kj5pA9BKWEOtBPPeXCQ7JNAHEP1gBWm6GxPPpjVvrg80irJx3AZrpoGw14lwXI591ZoK5TGvz+CqkE/ZHP8+6KY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(39860400002)(136003)(346002)(451199015)(36840700001)(40470700004)(46966006)(40480700001)(81166007)(36756003)(356005)(82740400003)(86362001)(40460700003)(316002)(110136005)(6666004)(54906003)(478600001)(44832011)(2906002)(5660300002)(8936002)(70586007)(41300700001)(36860700001)(4326008)(8676002)(70206006)(83380400001)(47076005)(2616005)(426003)(82310400005)(26005)(1076003)(336012)(16526019)(186003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:08.6935 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c70042a3-7f9c-4e1a-3c05-08dad7ec4a6f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT105.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7580 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add in the periodic health check and the related workqueue, as well as the handlers for when a FW reset is seen. Signed-off-by: Shannon Nelson --- drivers/net/ethernet/pensando/pds_core/core.c | 60 +++++++++++++++++++ drivers/net/ethernet/pensando/pds_core/core.h | 9 +++ drivers/net/ethernet/pensando/pds_core/dev.c | 3 + drivers/net/ethernet/pensando/pds_core/main.c | 50 ++++++++++++++++ 4 files changed, 122 insertions(+) diff --git a/drivers/net/ethernet/pensando/pds_core/core.c b/drivers/net/ethernet/pensando/pds_core/core.c index d846e8b93575..49cab9e58da6 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.c +++ b/drivers/net/ethernet/pensando/pds_core/core.c @@ -41,3 +41,63 @@ void pdsc_teardown(struct pdsc *pdsc, bool removing) set_bit(PDSC_S_FW_DEAD, &pdsc->state); } + +static void pdsc_fw_down(struct pdsc *pdsc) +{ + mutex_lock(&pdsc->config_lock); + + if (test_and_set_bit(PDSC_S_FW_DEAD, &pdsc->state)) { + dev_err(pdsc->dev, "%s: already happening\n", __func__); + mutex_unlock(&pdsc->config_lock); + return; + } + + pdsc_teardown(pdsc, PDSC_TEARDOWN_RECOVERY); + + mutex_unlock(&pdsc->config_lock); +} + +static void pdsc_fw_up(struct pdsc *pdsc) +{ + int err; + + mutex_lock(&pdsc->config_lock); + + if (!test_bit(PDSC_S_FW_DEAD, &pdsc->state)) { + dev_err(pdsc->dev, "%s: fw not dead\n", __func__); + mutex_unlock(&pdsc->config_lock); + return; + } + + err = pdsc_setup(pdsc, PDSC_SETUP_RECOVERY); + if (err) + goto err_out; + + mutex_unlock(&pdsc->config_lock); + + return; + +err_out: + pdsc_teardown(pdsc, PDSC_TEARDOWN_RECOVERY); + mutex_unlock(&pdsc->config_lock); +} + +void pdsc_health_thread(struct work_struct *work) +{ + struct pdsc *pdsc = container_of(work, struct pdsc, health_work); + bool healthy; + + healthy = pdsc_is_fw_good(pdsc); + dev_dbg(pdsc->dev, "%s: health %d fw_status %#02x fw_heartbeat %d\n", + __func__, healthy, pdsc->fw_status, pdsc->last_hb); + + if (test_bit(PDSC_S_FW_DEAD, &pdsc->state)) { + if (healthy) + pdsc_fw_up(pdsc); + } else { + if (!healthy) + pdsc_fw_down(pdsc); + } + + pdsc->fw_generation = pdsc->fw_status & PDS_CORE_FW_STS_F_GENERATION; +} diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h index d0d2c395ba25..f09b6ad503ef 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.h +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -12,6 +12,8 @@ #include #define PDSC_DRV_DESCRIPTION "Pensando Core PF Driver" + +#define PDSC_WATCHDOG_SECS 5 #define PDSC_TEARDOWN_RECOVERY false #define PDSC_TEARDOWN_REMOVING true #define PDSC_SETUP_RECOVERY false @@ -64,12 +66,17 @@ struct pdsc { u8 fw_generation; unsigned long last_fw_time; u32 last_hb; + struct timer_list wdtimer; + unsigned int wdtimer_period; + struct work_struct health_work; struct pdsc_devinfo dev_info; struct pds_core_dev_identity dev_ident; unsigned int nintrs; struct pdsc_intr_info *intr_info; /* array of nintrs elements */ + struct workqueue_struct *wq; + unsigned int devcmd_timeout; struct mutex devcmd_lock; /* lock for dev_cmd operations */ struct mutex config_lock; /* lock for configuration operations */ @@ -82,6 +89,7 @@ struct pdsc { u64 __iomem *kern_dbpage; }; +void pdsc_queue_health_check(struct pdsc *pdsc); void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num); struct pdsc *pdsc_dl_alloc(struct device *dev); @@ -119,5 +127,6 @@ int pdsc_dev_init(struct pdsc *pdsc); int pdsc_setup(struct pdsc *pdsc, bool init); void pdsc_teardown(struct pdsc *pdsc, bool removing); +void pdsc_health_thread(struct work_struct *work); #endif /* _PDSC_H_ */ diff --git a/drivers/net/ethernet/pensando/pds_core/dev.c b/drivers/net/ethernet/pensando/pds_core/dev.c index 1f1193706407..93433201cfa2 100644 --- a/drivers/net/ethernet/pensando/pds_core/dev.c +++ b/drivers/net/ethernet/pensando/pds_core/dev.c @@ -181,6 +181,9 @@ int pdsc_devcmd_locked(struct pdsc *pdsc, union pds_core_dev_cmd *cmd, err = pdsc_devcmd_wait(pdsc, max_seconds); memcpy_fromio(comp, &pdsc->cmd_regs->comp, sizeof(*comp)); + if (err == -ENXIO || err == -ETIMEDOUT) + pdsc_queue_health_check(pdsc); + return err; } diff --git a/drivers/net/ethernet/pensando/pds_core/main.c b/drivers/net/ethernet/pensando/pds_core/main.c index 770b3f895bbb..23f209d3375c 100644 --- a/drivers/net/ethernet/pensando/pds_core/main.c +++ b/drivers/net/ethernet/pensando/pds_core/main.c @@ -25,6 +25,31 @@ static const struct pci_device_id pdsc_id_table[] = { }; MODULE_DEVICE_TABLE(pci, pdsc_id_table); +void pdsc_queue_health_check(struct pdsc *pdsc) +{ + unsigned long mask; + + /* Don't do a check when in a transition state */ + mask = BIT_ULL(PDSC_S_INITING_DRIVER) | + BIT_ULL(PDSC_S_STOPPING_DRIVER); + if (pdsc->state & mask) + return; + + /* Queue a new health check if one isn't already queued */ + queue_work(pdsc->wq, &pdsc->health_work); +} + +static void pdsc_wdtimer_cb(struct timer_list *t) +{ + struct pdsc *pdsc = from_timer(pdsc, t, wdtimer); + + dev_dbg(pdsc->dev, "%s: jiffies %ld\n", __func__, jiffies); + mod_timer(&pdsc->wdtimer, + round_jiffies(jiffies + pdsc->wdtimer_period)); + + pdsc_queue_health_check(pdsc); +} + static void pdsc_unmap_bars(struct pdsc *pdsc) { struct pdsc_dev_bar *bars = pdsc->bars; @@ -135,9 +160,12 @@ static int pdsc_map_bars(struct pdsc *pdsc) static DEFINE_IDA(pdsc_pf_ida); +#define PDSC_WQ_NAME_LEN 24 + static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct device *dev = &pdev->dev; + char wq_name[PDSC_WQ_NAME_LEN]; struct pdsc *pdsc; int err; @@ -189,6 +217,13 @@ static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (err) goto err_out_pci_disable_device; + /* General workqueue and timer, but don't start timer yet */ + snprintf(wq_name, sizeof(wq_name), "%s.%d", PDS_CORE_DRV_NAME, pdsc->id); + pdsc->wq = create_singlethread_workqueue(wq_name); + INIT_WORK(&pdsc->health_work, pdsc_health_thread); + timer_setup(&pdsc->wdtimer, pdsc_wdtimer_cb, 0); + pdsc->wdtimer_period = PDSC_WATCHDOG_SECS * HZ; + /* PDS device setup */ mutex_init(&pdsc->devcmd_lock); mutex_init(&pdsc->config_lock); @@ -209,6 +244,8 @@ static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pdsc->fw_generation = PDS_CORE_FW_STS_F_GENERATION & ioread8(&pdsc->info_regs->fw_status); + /* Lastly, start the health check timer */ + mod_timer(&pdsc->wdtimer, round_jiffies(jiffies + pdsc->wdtimer_period)); clear_bit(PDSC_S_INITING_DRIVER, &pdsc->state); return 0; @@ -216,6 +253,12 @@ static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_out: pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING); err_out_unmap_bars: + del_timer_sync(&pdsc->wdtimer); + if (pdsc->wq) { + flush_workqueue(pdsc->wq); + destroy_workqueue(pdsc->wq); + pdsc->wq = NULL; + } mutex_unlock(&pdsc->config_lock); mutex_destroy(&pdsc->config_lock); mutex_destroy(&pdsc->devcmd_lock); @@ -248,6 +291,13 @@ static void pdsc_remove(struct pci_dev *pdev) mutex_lock(&pdsc->config_lock); set_bit(PDSC_S_STOPPING_DRIVER, &pdsc->state); + del_timer_sync(&pdsc->wdtimer); + if (pdsc->wq) { + flush_workqueue(pdsc->wq); + destroy_workqueue(pdsc->wq); + pdsc->wq = NULL; + } + /* Device teardown */ pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING); pdsc_debugfs_del_dev(pdsc); From patchwork Wed Dec 7 00:44:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066445 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77E71C3A5A7 for ; Wed, 7 Dec 2022 00:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbiLGApl (ORCPT ); Tue, 6 Dec 2022 19:45:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbiLGApZ (ORCPT ); Tue, 6 Dec 2022 19:45:25 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2089.outbound.protection.outlook.com [40.107.220.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 384FD326DF for ; Tue, 6 Dec 2022 16:45:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cmH4AMKPb4d2+ch405dje/s73TB7n+QhbTN6M1Bp64ijS5mti8JWXlZ9ezyMK7wqyiCWJnQJG7hYGtjV/TMYLLnLWGQ6v4hpoawbfMuXNbaTNzOIaOhePVd1PyeesrCZL/HKXwVAA04fvJgNoljz1/M7hU3rsbykXHavbEno9XV4/ATW3Rz3HzA1FvZlugqANSqLiGDqSMCxv8lhPlcMhCjdC49GbGwTehmSSm8SnRJLyjNU4oD5G9tNOHgLi1wWVTQRJ6wQR/p/OLccr+eE9pQRxKAi41rsLBYz7inBwY/pb5yCTRVD/k6PTySSNOfSFWzRSOVb/LXlnA9y0n90kA== 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=L0J+qgrGudaG1upHCD35XuASuTg5/cavX4MrwhC/DG8=; b=IR2RcgDK4UHd4vyk82++D1vwFijZNHhANuik89fOxHhNLBWcGSNdCJrfHet7O6W1BEYXNaCpS60Qp/meJoBKQE5CK+7NbnVJHrRPWcgg+T9DreZF55fx+7hFzAi3sWFwUk9jf/OwFk3GNdvzp3TNtQnPZxwUe4KCa1Ac64jccIOmX1tuBy6v9ocVdBMFm9pB3XysHqrgg7EuEcCoGKB1MSqwKAG4gU9DXQ9tzQ4NBQcBJNIgrASPeaBCtBKObbfu1jPL+8gcClj4T2WFbXeiTmNOPGTZLZYlHLIWVfstj/KG2QFqj92J/dzE2ASYi1urjYhh69ibu0BnyGCey6nZEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L0J+qgrGudaG1upHCD35XuASuTg5/cavX4MrwhC/DG8=; b=TWBPCukIDGivHjKNr/YSO1ifAP75RyoU44vestKj1G1KTRLLMgv8ug7lULtDInOGBjbHBFICO0eH6ThYx6GrtTcm7C6hpSGCru9v3oGrqcGT/3tWq9ceHaD7IUlyslyp/Mi+/wOTrebSbCxsFfAkPo1uS52LkD5vPCILQGMEZsQ= Received: from BN9PR03CA0491.namprd03.prod.outlook.com (2603:10b6:408:130::16) by DS0PR12MB7772.namprd12.prod.outlook.com (2603:10b6:8:138::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:09 +0000 Received: from BN8NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:408:130:cafe::c2) by BN9PR03CA0491.outlook.office365.com (2603:10b6:408:130::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT027.mail.protection.outlook.com (10.13.177.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.15 via Frontend Transport; Wed, 7 Dec 2022 00:45:09 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:08 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 06/16] pds_core: set up device and adminq Date: Tue, 6 Dec 2022 16:44:33 -0800 Message-ID: <20221207004443.33779-7-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT027:EE_|DS0PR12MB7772:EE_ X-MS-Office365-Filtering-Correlation-Id: e2c0a504-8c75-4dc0-c5b4-08dad7ec4add X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: deYnWitPYQdYpTh0aLEBuwwx293cn5Eqnp01w0LUVroActqexgxvmxy2ZpZHu6eRv3ITjP6DC75IgsnNW2MG9wohl0gt1EUgvPK0/TcFgtk4hQlhuQ5bb4TkllINAQoOkO+1BE0Hb5FnubcKnZ7WkfUiHJ48HxhMdeo9QULBd2rHvt1+4o0TxgJlgCUf2A7TaYPs5lblwCpQQSZzFX578qHKU2DEXW3qYDszk2wapokPk9JgzeBochr1jpPV53XHAWuDpdfaAdIYrYLXDXJKsaos8Bbz2PU1ewSz4upyH+a/uN+v8/TNxGehy/9EshzNpTO96uCkrVd5OZZhMG/pS7EqANwbCLlt2eC3ui0nSHx/MWln3FliP8ZjZR7blrPVh/nrxtqKDVKLXK1PYCudjlfRHnxo1nh2x41xqzMfzNA2f6uqfglIK17vWsepw6Z4IeWZXkUaUfOW4gWTVEZDBZoa81yAuSqMpU7cQ1R/KzpS6q2cuypmg2aYoGrPDZJIBBqGUN2/OZ6CPyTuRgzn3uExnd1khMvIUNmDeJY+5HimdFh8UPXiwfXe2k9SCszuSI4Zvj+39C4UI55x5UeSEI80SP617cvk1X1IHtrQ72zNXFFJLoTbyAalvPm42kIBtrN8JHHSiVv5bUawUwcrs97Frx/ySthRj1G7RJGqfqT0iN9sNPT3xMzKjbelYgRSZyU00zrB7YrWrtL2Ug5f7pl9aCjiNQ3efWT3FjLe14I= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(346002)(396003)(136003)(376002)(451199015)(46966006)(36840700001)(40470700004)(36756003)(36860700001)(16526019)(70206006)(82740400003)(186003)(4326008)(8676002)(70586007)(336012)(426003)(1076003)(2616005)(26005)(40460700003)(6666004)(110136005)(83380400001)(478600001)(54906003)(86362001)(316002)(47076005)(82310400005)(2906002)(40480700001)(356005)(41300700001)(81166007)(8936002)(44832011)(30864003)(5660300002)(36900700001)(579004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:09.4179 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2c0a504-8c75-4dc0-c5b4-08dad7ec4add X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7772 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Set up the basic adminq and notifyq services. These are used mostly by the client drivers for feature configuration. Signed-off-by: Shannon Nelson --- drivers/net/ethernet/pensando/pds_core/core.c | 444 +++++++++++- drivers/net/ethernet/pensando/pds_core/core.h | 149 ++++ .../net/ethernet/pensando/pds_core/debugfs.c | 125 ++++ .../net/ethernet/pensando/pds_core/devlink.c | 55 ++ drivers/net/ethernet/pensando/pds_core/main.c | 14 + include/linux/pds/pds_adminq.h | 641 ++++++++++++++++++ 6 files changed, 1425 insertions(+), 3 deletions(-) create mode 100644 include/linux/pds/pds_adminq.h diff --git a/drivers/net/ethernet/pensando/pds_core/core.c b/drivers/net/ethernet/pensando/pds_core/core.c index 49cab9e58da6..507f718bc8ab 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.c +++ b/drivers/net/ethernet/pensando/pds_core/core.c @@ -10,8 +10,368 @@ #include "core.h" +#include + +void pdsc_work_thread(struct work_struct *work) +{ + /* stub */ +} + +irqreturn_t pdsc_adminq_isr(int irq, void *data) +{ + /* stub */ + return IRQ_HANDLED; +} + +void pdsc_intr_free(struct pdsc *pdsc, int index) +{ + struct pdsc_intr_info *intr_info; + + if (index >= pdsc->nintrs || index < 0) { + WARN(true, "bad intr index %d\n", index); + return; + } + + intr_info = &pdsc->intr_info[index]; + if (!intr_info->vector) + return; + dev_dbg(pdsc->dev, "%s: idx %d vec %d name %s\n", + __func__, index, intr_info->vector, intr_info->name); + + pds_core_intr_mask(&pdsc->intr_ctrl[index], PDS_CORE_INTR_MASK_SET); + pds_core_intr_clean(&pdsc->intr_ctrl[index]); + + devm_free_irq(pdsc->dev, intr_info->vector, intr_info->data); + + memset(intr_info, 0, sizeof(*intr_info)); +} + +int pdsc_intr_alloc(struct pdsc *pdsc, char *name, + irq_handler_t handler, void *data) +{ + struct pdsc_intr_info *intr_info; + unsigned int index; + int err; + + /* Find the first available interrupt */ + for (index = 0; index < pdsc->nintrs; index++) + if (!pdsc->intr_info[index].vector) + break; + if (index >= pdsc->nintrs) { + dev_warn(pdsc->dev, "%s: no intr, index=%d nintrs=%d\n", + __func__, index, pdsc->nintrs); + return -ENOSPC; + } + + pds_core_intr_clean_flags(&pdsc->intr_ctrl[index], + PDS_CORE_INTR_CRED_RESET_COALESCE); + + intr_info = &pdsc->intr_info[index]; + + intr_info->index = index; + intr_info->data = data; + strscpy(intr_info->name, name, sizeof(intr_info->name)); + + /* Get the OS vector number for the interrupt */ + err = pci_irq_vector(pdsc->pdev, index); + if (err < 0) { + dev_err(pdsc->dev, "failed to get intr vector index %d: %pe\n", + index, ERR_PTR(err)); + goto err_out_free_intr; + } + intr_info->vector = err; + + /* Init the device's intr mask */ + pds_core_intr_clean(&pdsc->intr_ctrl[index]); + pds_core_intr_mask_assert(&pdsc->intr_ctrl[index], 1); + pds_core_intr_mask(&pdsc->intr_ctrl[index], PDS_CORE_INTR_MASK_SET); + + /* Register the isr with a name */ + err = devm_request_irq(pdsc->dev, intr_info->vector, + handler, 0, intr_info->name, data); + if (err) { + dev_err(pdsc->dev, "failed to get intr irq vector %d: %pe\n", + intr_info->vector, ERR_PTR(err)); + goto err_out_free_intr; + } + + return index; + +err_out_free_intr: + pdsc_intr_free(pdsc, index); + return err; +} + +static void pdsc_qcq_intr_free(struct pdsc *pdsc, struct pdsc_qcq *qcq) +{ + if (!(qcq->flags & PDS_CORE_QCQ_F_INTR) || + qcq->intx == PDS_CORE_INTR_INDEX_NOT_ASSIGNED) + return; + + pdsc_intr_free(pdsc, qcq->intx); + qcq->intx = PDS_CORE_INTR_INDEX_NOT_ASSIGNED; +} + +static int pdsc_qcq_intr_alloc(struct pdsc *pdsc, struct pdsc_qcq *qcq) +{ + char name[PDSC_INTR_NAME_MAX_SZ]; + int index; + + if (!(qcq->flags & PDS_CORE_QCQ_F_INTR)) { + qcq->intx = PDS_CORE_INTR_INDEX_NOT_ASSIGNED; + return 0; + } + + snprintf(name, sizeof(name), + "%s-%d-%s", PDS_CORE_DRV_NAME, pdsc->pdev->bus->number, qcq->q.name); + index = pdsc_intr_alloc(pdsc, name, pdsc_adminq_isr, qcq); + if (index < 0) + return index; + qcq->intx = index; + + return 0; +} + +void pdsc_qcq_free(struct pdsc *pdsc, struct pdsc_qcq *qcq) +{ + struct device *dev = pdsc->dev; + + if (!(qcq && qcq->pdsc)) + return; + + pdsc_debugfs_del_qcq(qcq); + + pdsc_qcq_intr_free(pdsc, qcq); + + if (qcq->q_base) { + dmam_free_coherent(dev, qcq->q_size, + qcq->q_base, qcq->q_base_pa); + qcq->q_base = NULL; + qcq->q_base_pa = 0; + } + + if (qcq->cq_base) { + dmam_free_coherent(dev, qcq->cq_size, qcq->cq_base, qcq->cq_base_pa); + qcq->cq_base = NULL; + qcq->cq_base_pa = 0; + } + + if (qcq->cq.info) { + vfree(qcq->cq.info); + qcq->cq.info = NULL; + } + if (qcq->q.info) { + vfree(qcq->q.info); + qcq->q.info = NULL; + } + + qcq->pdsc = NULL; + memset(&qcq->q, 0, sizeof(qcq->q)); + memset(&qcq->cq, 0, sizeof(qcq->cq)); +} + +static void pdsc_q_map(struct pdsc_queue *q, void *base, dma_addr_t base_pa) +{ + struct pdsc_q_info *cur; + unsigned int i; + + q->base = base; + q->base_pa = base_pa; + + for (i = 0, cur = q->info; i < q->num_descs; i++, cur++) + cur->desc = base + (i * q->desc_size); +} + +static void pdsc_cq_map(struct pdsc_cq *cq, void *base, dma_addr_t base_pa) +{ + struct pdsc_cq_info *cur; + unsigned int i; + + cq->base = base; + cq->base_pa = base_pa; + + for (i = 0, cur = cq->info; i < cq->num_descs; i++, cur++) + cur->comp = base + (i * cq->desc_size); +} + +int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index, + const char *name, unsigned int flags, unsigned int num_descs, + unsigned int desc_size, unsigned int cq_desc_size, + unsigned int pid, struct pdsc_qcq *qcq) +{ + struct device *dev = pdsc->dev; + dma_addr_t cq_base_pa = 0; + dma_addr_t q_base_pa = 0; + void *q_base, *cq_base; + int err; + + qcq->q.info = vzalloc(num_descs * sizeof(*qcq->q.info)); + if (!qcq->q.info) { + dev_err(dev, "Cannot allocate %s queue info\n", name); + err = -ENOMEM; + goto err_out; + } + + qcq->pdsc = pdsc; + qcq->flags = flags; + INIT_WORK(&qcq->work, pdsc_work_thread); + + qcq->q.type = type; + qcq->q.index = index; + qcq->q.num_descs = num_descs; + qcq->q.desc_size = desc_size; + qcq->q.tail_idx = 0; + qcq->q.head_idx = 0; + qcq->q.pid = pid; + snprintf(qcq->q.name, sizeof(qcq->q.name), "%s%u", name, index); + + err = pdsc_qcq_intr_alloc(pdsc, qcq); + if (err) + goto err_out_free_q_info; + + qcq->cq.info = vzalloc(num_descs * sizeof(*qcq->cq.info)); + if (!qcq->cq.info) { + dev_err(dev, "Cannot allocate %s completion queue info\n", name); + err = -ENOMEM; + goto err_out_free_irq; + } + + qcq->cq.bound_intr = &pdsc->intr_info[qcq->intx]; + qcq->cq.num_descs = num_descs; + qcq->cq.desc_size = cq_desc_size; + qcq->cq.tail_idx = 0; + qcq->cq.done_color = 1; + + if (flags & PDS_CORE_QCQ_F_NOTIFYQ) { + /* q & cq need to be contiguous in case of notifyq */ + qcq->q_size = PAGE_SIZE + ALIGN(num_descs * desc_size, PAGE_SIZE) + + ALIGN(num_descs * cq_desc_size, PAGE_SIZE); + qcq->q_base = dmam_alloc_coherent(dev, qcq->q_size + qcq->cq_size, + &qcq->q_base_pa, + GFP_KERNEL); + if (!qcq->q_base) { + dev_err(dev, "Cannot allocate %s qcq DMA memory\n", name); + err = -ENOMEM; + goto err_out_free_cq_info; + } + q_base = PTR_ALIGN(qcq->q_base, PAGE_SIZE); + q_base_pa = ALIGN(qcq->q_base_pa, PAGE_SIZE); + pdsc_q_map(&qcq->q, q_base, q_base_pa); + + cq_base = PTR_ALIGN(q_base + + ALIGN(num_descs * desc_size, PAGE_SIZE), PAGE_SIZE); + cq_base_pa = ALIGN(qcq->q_base_pa + + ALIGN(num_descs * desc_size, PAGE_SIZE), PAGE_SIZE); + + } else { + /* q DMA descriptors */ + qcq->q_size = PAGE_SIZE + (num_descs * desc_size); + qcq->q_base = dmam_alloc_coherent(dev, qcq->q_size, + &qcq->q_base_pa, + GFP_KERNEL); + if (!qcq->q_base) { + dev_err(dev, "Cannot allocate %s queue DMA memory\n", name); + err = -ENOMEM; + goto err_out_free_cq_info; + } + q_base = PTR_ALIGN(qcq->q_base, PAGE_SIZE); + q_base_pa = ALIGN(qcq->q_base_pa, PAGE_SIZE); + pdsc_q_map(&qcq->q, q_base, q_base_pa); + + /* cq DMA descriptors */ + qcq->cq_size = PAGE_SIZE + (num_descs * cq_desc_size); + qcq->cq_base = dmam_alloc_coherent(dev, qcq->cq_size, + &qcq->cq_base_pa, + GFP_KERNEL); + if (!qcq->cq_base) { + dev_err(dev, "Cannot allocate %s cq DMA memory\n", name); + err = -ENOMEM; + goto err_out_free_q; + } + cq_base = PTR_ALIGN(qcq->cq_base, PAGE_SIZE); + cq_base_pa = ALIGN(qcq->cq_base_pa, PAGE_SIZE); + } + + pdsc_cq_map(&qcq->cq, cq_base, cq_base_pa); + qcq->cq.bound_q = &qcq->q; + + pdsc_debugfs_add_qcq(pdsc, qcq); + + return 0; + +err_out_free_q: + dmam_free_coherent(dev, qcq->q_size, qcq->q_base, qcq->q_base_pa); +err_out_free_cq_info: + vfree(qcq->cq.info); +err_out_free_irq: + pdsc_qcq_intr_free(pdsc, qcq); +err_out_free_q_info: + vfree(qcq->q.info); + memset(qcq, 0, sizeof(*qcq)); +err_out: + dev_err(dev, "qcq alloc of %s%d failed %d\n", name, index, err); + return err; +} + +static int pdsc_core_init(struct pdsc *pdsc) +{ + union pds_core_dev_comp comp = { 0 }; + union pds_core_dev_cmd cmd = { + .init.opcode = PDS_CORE_CMD_INIT, + }; + struct pds_core_dev_init_data_out cido; + struct pds_core_dev_init_data_in cidi; + u32 dbid_count; + u32 dbpage_num; + size_t sz; + int err; + + cidi.adminq_q_base = cpu_to_le64(pdsc->adminqcq.q_base_pa); + cidi.adminq_cq_base = cpu_to_le64(pdsc->adminqcq.cq_base_pa); + cidi.notifyq_cq_base = cpu_to_le64(pdsc->notifyqcq.cq.base_pa); + cidi.flags = cpu_to_le32(PDS_CORE_QINIT_F_IRQ | PDS_CORE_QINIT_F_ENA); + cidi.intr_index = cpu_to_le16(pdsc->adminqcq.intx); + cidi.adminq_ring_size = ilog2(pdsc->adminqcq.q.num_descs); + cidi.notifyq_ring_size = ilog2(pdsc->notifyqcq.q.num_descs); + + mutex_lock(&pdsc->devcmd_lock); + + sz = min_t(size_t, sizeof(cidi), sizeof(pdsc->cmd_regs->data)); + memcpy_toio(&pdsc->cmd_regs->data, &cidi, sz); + + err = pdsc_devcmd_locked(pdsc, &cmd, &comp, pdsc->devcmd_timeout); + + sz = min_t(size_t, sizeof(cido), sizeof(pdsc->cmd_regs->data)); + memcpy_fromio(&cido, &pdsc->cmd_regs->data, sz); + + mutex_unlock(&pdsc->devcmd_lock); + + pdsc->hw_index = le32_to_cpu(cido.core_hw_index); + + dbid_count = le32_to_cpu(pdsc->dev_ident.ndbpgs_per_lif); + dbpage_num = pdsc->hw_index * dbid_count; + pdsc->kern_dbpage = pdsc_map_dbpage(pdsc, dbpage_num); + if (!pdsc->kern_dbpage) { + dev_err(pdsc->dev, "Cannot map dbpage, aborting\n"); + return -ENOMEM; + } + + pdsc->adminqcq.q.hw_type = cido.adminq_hw_type; + pdsc->adminqcq.q.hw_index = le32_to_cpu(cido.adminq_hw_index); + pdsc->adminqcq.q.dbval = PDS_CORE_DBELL_QID(pdsc->adminqcq.q.hw_index); + + pdsc->notifyqcq.q.hw_type = cido.notifyq_hw_type; + pdsc->notifyqcq.q.hw_index = le32_to_cpu(cido.notifyq_hw_index); + pdsc->notifyqcq.q.dbval = PDS_CORE_DBELL_QID(pdsc->notifyqcq.q.hw_index); + + pdsc->last_eid = 0; + + return err; +} + int pdsc_setup(struct pdsc *pdsc, bool init) { + int numdescs; int err = 0; if (init) @@ -21,17 +381,60 @@ int pdsc_setup(struct pdsc *pdsc, bool init) if (err) return err; + /* Scale the descriptor ring length based on number of CPUs and VFs */ + numdescs = max_t(int, PDSC_ADMINQ_MIN_LENGTH, num_online_cpus()); + numdescs += 2 * pci_sriov_get_totalvfs(pdsc->pdev); + numdescs = roundup_pow_of_two(numdescs); + err = pdsc_qcq_alloc(pdsc, PDS_CORE_QTYPE_ADMINQ, 0, "adminq", + PDS_CORE_QCQ_F_CORE | PDS_CORE_QCQ_F_INTR, + numdescs, + sizeof(union pds_core_adminq_cmd), + sizeof(union pds_core_adminq_comp), + 0, &pdsc->adminqcq); + if (err) + goto err_out_teardown; + + err = pdsc_qcq_alloc(pdsc, PDS_CORE_QTYPE_NOTIFYQ, 0, "notifyq", + PDS_CORE_QCQ_F_NOTIFYQ, + PDSC_NOTIFYQ_LENGTH, + sizeof(struct pds_core_notifyq_cmd), + sizeof(union pds_core_notifyq_comp), + 0, &pdsc->notifyqcq); + if (err) + goto err_out_teardown; + + /* NotifyQ rides on the AdminQ interrupt */ + pdsc->notifyqcq.intx = pdsc->adminqcq.intx; + + /* Set up the Core with the AdminQ and NotifyQ info */ + err = pdsc_core_init(pdsc); + if (err) + goto err_out_teardown; + clear_bit(PDSC_S_FW_DEAD, &pdsc->state); return 0; + +err_out_teardown: + pdsc_teardown(pdsc, init); + return err; } void pdsc_teardown(struct pdsc *pdsc, bool removing) { + int i; + pdsc_devcmd_reset(pdsc); + pdsc_qcq_free(pdsc, &pdsc->notifyqcq); + pdsc_qcq_free(pdsc, &pdsc->adminqcq); - if (removing && pdsc->intr_info) { - devm_kfree(pdsc->dev, pdsc->intr_info); - pdsc->intr_info = NULL; + if (pdsc->intr_info) { + for (i = 0; i < pdsc->nintrs; i++) + pdsc_intr_free(pdsc, i); + + if (removing) { + devm_kfree(pdsc->dev, pdsc->intr_info); + pdsc->intr_info = NULL; + } } if (pdsc->kern_dbpage) { @@ -42,6 +445,36 @@ void pdsc_teardown(struct pdsc *pdsc, bool removing) set_bit(PDSC_S_FW_DEAD, &pdsc->state); } +int pdsc_start(struct pdsc *pdsc) +{ + pds_core_intr_mask(&pdsc->intr_ctrl[pdsc->adminqcq.intx], + PDS_CORE_INTR_MASK_CLEAR); + + return 0; +} + +static void pdsc_mask_interrupts(struct pdsc *pdsc) +{ + int i; + + if (!pdsc->intr_info) + return; + + /* Mask interrupts that are in use */ + for (i = 0; i < pdsc->nintrs; i++) + if (pdsc->intr_info[i].vector) + pds_core_intr_mask(&pdsc->intr_ctrl[i], + PDS_CORE_INTR_MASK_SET); +} + +void pdsc_stop(struct pdsc *pdsc) +{ + if (pdsc->wq) + flush_workqueue(pdsc->wq); + + pdsc_mask_interrupts(pdsc); +} + static void pdsc_fw_down(struct pdsc *pdsc) { mutex_lock(&pdsc->config_lock); @@ -52,6 +485,7 @@ static void pdsc_fw_down(struct pdsc *pdsc) return; } + pdsc_mask_interrupts(pdsc); pdsc_teardown(pdsc, PDSC_TEARDOWN_RECOVERY); mutex_unlock(&pdsc->config_lock); @@ -73,6 +507,10 @@ static void pdsc_fw_up(struct pdsc *pdsc) if (err) goto err_out; + err = pdsc_start(pdsc); + if (err) + goto err_out; + mutex_unlock(&pdsc->config_lock); return; diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h index f09b6ad503ef..3d1023f0eeb2 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.h +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -9,11 +9,15 @@ #include #include +#include #include #define PDSC_DRV_DESCRIPTION "Pensando Core PF Driver" #define PDSC_WATCHDOG_SECS 5 +#define PDSC_QUEUE_NAME_MAX_SZ 32 +#define PDSC_ADMINQ_MIN_LENGTH 16 /* must be a power of two */ +#define PDSC_NOTIFYQ_LENGTH 64 /* must be a power of two */ #define PDSC_TEARDOWN_RECOVERY false #define PDSC_TEARDOWN_REMOVING true #define PDSC_SETUP_RECOVERY false @@ -33,6 +37,28 @@ struct pdsc_devinfo { char serial_num[PDS_CORE_DEVINFO_SERIAL_BUFLEN + 1]; }; +struct pdsc_queue { + struct pdsc_q_info *info; + u64 dbval; + u16 head_idx; + u16 tail_idx; + u8 hw_type; + unsigned int index; + unsigned int num_descs; + u64 dbell_count; + u64 features; + unsigned int type; + unsigned int hw_index; + union { + void *base; + struct pds_core_admin_cmd *adminq; + }; + dma_addr_t base_pa; /* must be page aligned */ + unsigned int desc_size; + unsigned int pid; + char name[PDSC_QUEUE_NAME_MAX_SZ]; +}; + #define PDSC_INTR_NAME_MAX_SZ 32 struct pdsc_intr_info { @@ -42,6 +68,61 @@ struct pdsc_intr_info { void *data; }; +struct pdsc_cq_info { + void *comp; +}; + +struct pdsc_buf_info { + struct page *page; + dma_addr_t dma_addr; + u32 page_offset; + u32 len; +}; + +struct pdsc_q_info { + union { + void *desc; + struct pdsc_admin_cmd *adminq_desc; + }; + unsigned int bytes; + unsigned int nbufs; + struct pdsc_buf_info bufs[PDS_CORE_MAX_FRAGS]; + struct pdsc_wait_context *wc; + void *dest; +}; + +struct pdsc_cq { + struct pdsc_cq_info *info; + struct pdsc_queue *bound_q; + struct pdsc_intr_info *bound_intr; + u16 tail_idx; + bool done_color; + unsigned int num_descs; + unsigned int desc_size; + void *base; + dma_addr_t base_pa; /* must be page aligned */ +} ____cacheline_aligned_in_smp; + +struct pdsc_qcq { + struct pdsc *pdsc; + void *q_base; + dma_addr_t q_base_pa; /* might not be page aligned */ + void *cq_base; + dma_addr_t cq_base_pa; /* might not be page aligned */ + u32 q_size; + u32 cq_size; + bool armed; + unsigned int flags; + + struct work_struct work; + struct pdsc_queue q; + struct pdsc_cq cq; + int intx; + + u32 accum_work; + struct dentry *dentry; +}; + /* No state flags set means we are in a steady running state */ enum pdsc_state_flags { PDSC_S_FW_DEAD, /* fw stopped, waiting for startup or recovery */ @@ -80,6 +161,7 @@ struct pdsc { unsigned int devcmd_timeout; struct mutex devcmd_lock; /* lock for dev_cmd operations */ struct mutex config_lock; /* lock for configuration operations */ + spinlock_t adminq_lock; /* lock for adminq operations */ struct pds_core_dev_info_regs __iomem *info_regs; struct pds_core_dev_cmd_regs __iomem *cmd_regs; struct pds_core_intr __iomem *intr_ctrl; @@ -87,8 +169,57 @@ struct pdsc { u64 __iomem *db_pages; dma_addr_t phy_db_pages; u64 __iomem *kern_dbpage; + + struct pdsc_qcq adminqcq; + struct pdsc_qcq notifyqcq; + u64 last_eid; +}; + +/** enum pds_core_dbell_bits - bitwise composition of dbell values. + * + * @PDS_CORE_DBELL_QID_MASK: unshifted mask of valid queue id bits. + * @PDS_CORE_DBELL_QID_SHIFT: queue id shift amount in dbell value. + * @PDS_CORE_DBELL_QID: macro to build QID component of dbell value. + * + * @PDS_CORE_DBELL_RING_MASK: unshifted mask of valid ring bits. + * @PDS_CORE_DBELL_RING_SHIFT: ring shift amount in dbell value. + * @PDS_CORE_DBELL_RING: macro to build ring component of dbell value. + * + * @PDS_CORE_DBELL_RING_0: ring zero dbell component value. + * @PDS_CORE_DBELL_RING_1: ring one dbell component value. + * @PDS_CORE_DBELL_RING_2: ring two dbell component value. + * @PDS_CORE_DBELL_RING_3: ring three dbell component value. + * + * @PDS_CORE_DBELL_INDEX_MASK: bit mask of valid index bits, no shift needed. + */ +enum pds_core_dbell_bits { + PDS_CORE_DBELL_QID_MASK = 0xffffff, + PDS_CORE_DBELL_QID_SHIFT = 24, + +#define PDS_CORE_DBELL_QID(n) \ + (((u64)(n) & PDS_CORE_DBELL_QID_MASK) << PDS_CORE_DBELL_QID_SHIFT) + + PDS_CORE_DBELL_RING_MASK = 0x7, + PDS_CORE_DBELL_RING_SHIFT = 16, + +#define PDS_CORE_DBELL_RING(n) \ + (((u64)(n) & PDS_CORE_DBELL_RING_MASK) << PDS_CORE_DBELL_RING_SHIFT) + + PDS_CORE_DBELL_RING_0 = 0, + PDS_CORE_DBELL_RING_1 = PDS_CORE_DBELL_RING(1), + PDS_CORE_DBELL_RING_2 = PDS_CORE_DBELL_RING(2), + PDS_CORE_DBELL_RING_3 = PDS_CORE_DBELL_RING(3), + + PDS_CORE_DBELL_INDEX_MASK = 0xffff, }; +static inline void pds_core_dbell_ring(u64 __iomem *db_page, + enum pds_core_logical_qtype qtype, + u64 val) +{ + writeq(val, &db_page[qtype]); +} + void pdsc_queue_health_check(struct pdsc *pdsc); void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num); @@ -104,6 +235,8 @@ void pdsc_debugfs_add_dev(struct pdsc *pdsc); void pdsc_debugfs_del_dev(struct pdsc *pdsc); void pdsc_debugfs_add_ident(struct pdsc *pdsc); void pdsc_debugfs_add_irqs(struct pdsc *pdsc); +void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq); +void pdsc_debugfs_del_qcq(struct pdsc_qcq *qcq); #else static inline void pdsc_debugfs_create(void) { } static inline void pdsc_debugfs_destroy(void) { } @@ -111,6 +244,8 @@ static inline void pdsc_debugfs_add_dev(struct pdsc *pdsc) { } static inline void pdsc_debugfs_del_dev(struct pdsc *pdsc) { } static inline void pdsc_debugfs_add_ident(struct pdsc *pdsc) { } static inline void pdsc_debugfs_add_irqs(struct pdsc *pdsc) { } +static inline void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq) { } +static inline void pdsc_debugfs_del_qcq(struct pdsc_qcq *qcq) { } #endif int pdsc_err_to_errno(enum pds_core_status_code code); @@ -125,8 +260,22 @@ int pdsc_devcmd_reset(struct pdsc *pdsc); int pdsc_dev_reinit(struct pdsc *pdsc); int pdsc_dev_init(struct pdsc *pdsc); +int pdsc_intr_alloc(struct pdsc *pdsc, char *name, + irq_handler_t handler, void *data); +void pdsc_intr_free(struct pdsc *pdsc, int index); +void pdsc_qcq_free(struct pdsc *pdsc, struct pdsc_qcq *qcq); +int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index, + const char *name, unsigned int flags, unsigned int num_descs, + unsigned int desc_size, unsigned int cq_desc_size, + unsigned int pid, struct pdsc_qcq *qcq); int pdsc_setup(struct pdsc *pdsc, bool init); void pdsc_teardown(struct pdsc *pdsc, bool removing); +int pdsc_start(struct pdsc *pdsc); +void pdsc_stop(struct pdsc *pdsc); void pdsc_health_thread(struct work_struct *work); +void pdsc_process_adminq(struct pdsc_qcq *qcq); +void pdsc_work_thread(struct work_struct *work); +irqreturn_t pdsc_adminq_isr(int irq, void *data); + #endif /* _PDSC_H_ */ diff --git a/drivers/net/ethernet/pensando/pds_core/debugfs.c b/drivers/net/ethernet/pensando/pds_core/debugfs.c index 698fd6d09387..294bb97ca639 100644 --- a/drivers/net/ethernet/pensando/pds_core/debugfs.c +++ b/drivers/net/ethernet/pensando/pds_core/debugfs.c @@ -111,4 +111,129 @@ void pdsc_debugfs_add_irqs(struct pdsc *pdsc) debugfs_create_file("irqs", 0400, pdsc->dentry, pdsc, &irqs_fops); } +static int q_tail_show(struct seq_file *seq, void *v) +{ + struct pdsc_queue *q = seq->private; + + seq_printf(seq, "%d\n", q->tail_idx); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(q_tail); + +static int q_head_show(struct seq_file *seq, void *v) +{ + struct pdsc_queue *q = seq->private; + + seq_printf(seq, "%d\n", q->head_idx); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(q_head); + +static int cq_tail_show(struct seq_file *seq, void *v) +{ + struct pdsc_cq *cq = seq->private; + + seq_printf(seq, "%d\n", cq->tail_idx); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(cq_tail); + +static const struct debugfs_reg32 intr_ctrl_regs[] = { + { .name = "coal_init", .offset = 0, }, + { .name = "mask", .offset = 4, }, + { .name = "credits", .offset = 8, }, + { .name = "mask_on_assert", .offset = 12, }, + { .name = "coal_timer", .offset = 16, }, +}; + +void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq) +{ + struct dentry *qcq_dentry, *q_dentry, *cq_dentry; + struct dentry *intr_dentry; + struct debugfs_regset32 *intr_ctrl_regset; + struct pdsc_intr_info *intr = &pdsc->intr_info[qcq->intx]; + struct debugfs_blob_wrapper *desc_blob; + struct device *dev = pdsc->dev; + struct pdsc_queue *q = &qcq->q; + struct pdsc_cq *cq = &qcq->cq; + + qcq_dentry = debugfs_create_dir(q->name, pdsc->dentry); + if (IS_ERR_OR_NULL(qcq_dentry)) + return; + qcq->dentry = qcq_dentry; + + debugfs_create_x64("q_base_pa", 0400, qcq_dentry, &qcq->q_base_pa); + debugfs_create_x32("q_size", 0400, qcq_dentry, &qcq->q_size); + debugfs_create_x64("cq_base_pa", 0400, qcq_dentry, &qcq->cq_base_pa); + debugfs_create_x32("cq_size", 0400, qcq_dentry, &qcq->cq_size); + debugfs_create_x32("accum_work", 0400, qcq_dentry, &qcq->accum_work); + + q_dentry = debugfs_create_dir("q", qcq->dentry); + if (IS_ERR_OR_NULL(q_dentry)) + return; + + debugfs_create_u32("index", 0400, q_dentry, &q->index); + debugfs_create_u32("num_descs", 0400, q_dentry, &q->num_descs); + debugfs_create_u32("desc_size", 0400, q_dentry, &q->desc_size); + debugfs_create_u32("pid", 0400, q_dentry, &q->pid); + + debugfs_create_file("tail", 0400, q_dentry, q, &q_tail_fops); + debugfs_create_file("head", 0400, q_dentry, q, &q_head_fops); + + desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL); + if (!desc_blob) + return; + desc_blob->data = q->base; + desc_blob->size = (unsigned long)q->num_descs * q->desc_size; + debugfs_create_blob("desc_blob", 0400, q_dentry, desc_blob); + + cq_dentry = debugfs_create_dir("cq", qcq->dentry); + if (IS_ERR_OR_NULL(cq_dentry)) + return; + + debugfs_create_x64("base_pa", 0400, cq_dentry, &cq->base_pa); + debugfs_create_u32("num_descs", 0400, cq_dentry, &cq->num_descs); + debugfs_create_u32("desc_size", 0400, cq_dentry, &cq->desc_size); + debugfs_create_bool("done_color", 0400, cq_dentry, &cq->done_color); + + debugfs_create_file("tail", 0400, cq_dentry, cq, &cq_tail_fops); + + desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL); + if (!desc_blob) + return; + desc_blob->data = cq->base; + desc_blob->size = (unsigned long)cq->num_descs * cq->desc_size; + debugfs_create_blob("desc_blob", 0400, cq_dentry, desc_blob); + + if (qcq->flags & PDS_CORE_QCQ_F_INTR) { + intr_dentry = debugfs_create_dir("intr", qcq->dentry); + if (IS_ERR_OR_NULL(intr_dentry)) + return; + + debugfs_create_u32("index", 0400, intr_dentry, + &intr->index); + debugfs_create_u32("vector", 0400, intr_dentry, + &intr->vector); + + intr_ctrl_regset = devm_kzalloc(dev, sizeof(*intr_ctrl_regset), + GFP_KERNEL); + if (!intr_ctrl_regset) + return; + intr_ctrl_regset->regs = intr_ctrl_regs; + intr_ctrl_regset->nregs = ARRAY_SIZE(intr_ctrl_regs); + intr_ctrl_regset->base = &pdsc->intr_ctrl[intr->index]; + + debugfs_create_regset32("intr_ctrl", 0400, intr_dentry, + intr_ctrl_regset); + } +}; + +void pdsc_debugfs_del_qcq(struct pdsc_qcq *qcq) +{ + debugfs_remove_recursive(qcq->dentry); + qcq->dentry = NULL; +} #endif /* CONFIG_DEBUG_FS */ diff --git a/drivers/net/ethernet/pensando/pds_core/devlink.c b/drivers/net/ethernet/pensando/pds_core/devlink.c index 016566aec1dc..78fe657f6532 100644 --- a/drivers/net/ethernet/pensando/pds_core/devlink.c +++ b/drivers/net/ethernet/pensando/pds_core/devlink.c @@ -8,7 +8,62 @@ #include "core.h" +static int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req, + struct netlink_ext_ack *extack) +{ + union pds_core_dev_cmd cmd = { + .fw_control.opcode = PDS_CORE_CMD_FW_CONTROL, + .fw_control.oper = PDS_CORE_FW_GET_LIST, + }; + struct pds_core_fw_list_info *fw_list; + struct pdsc *pdsc = devlink_priv(dl); + union pds_core_dev_comp comp; + char *fwprefix = "fw."; + char buf[16]; + int listlen; + int err; + int i; + + fw_list = (struct pds_core_fw_list_info *)pdsc->cmd_regs->data; + + mutex_lock(&pdsc->devcmd_lock); + err = pdsc_devcmd_locked(pdsc, &cmd, &comp, pdsc->devcmd_timeout * 2); + listlen = fw_list->num_fw_slots; + for (i = 0; !err && i < listlen; i++) { + snprintf(buf, sizeof(buf), "%d] %s%s", + i, fwprefix, fw_list->fw_names[i].slotname); + err = devlink_info_version_stored_put(req, buf, + fw_list->fw_names[i].fw_version); + } + mutex_unlock(&pdsc->devcmd_lock); + if (err && err != -EIO) + return err; + + err = devlink_info_version_running_put(req, + DEVLINK_INFO_VERSION_GENERIC_FW, + pdsc->dev_info.fw_version); + if (err) + return err; + + snprintf(buf, sizeof(buf), "0x%x", pdsc->dev_info.asic_type); + err = devlink_info_version_fixed_put(req, + DEVLINK_INFO_VERSION_GENERIC_ASIC_ID, + buf); + if (err) + return err; + + snprintf(buf, sizeof(buf), "0x%x", pdsc->dev_info.asic_rev); + err = devlink_info_version_fixed_put(req, + DEVLINK_INFO_VERSION_GENERIC_ASIC_REV, + buf); + if (err) + return err; + + return devlink_info_serial_number_put(req, pdsc->dev_info.serial_num); +} + static const struct devlink_ops pdsc_dl_ops = { + .info_get = pdsc_dl_info_get, }; struct pdsc *pdsc_dl_alloc(struct device *dev) diff --git a/drivers/net/ethernet/pensando/pds_core/main.c b/drivers/net/ethernet/pensando/pds_core/main.c index 23f209d3375c..856704f8827a 100644 --- a/drivers/net/ethernet/pensando/pds_core/main.c +++ b/drivers/net/ethernet/pensando/pds_core/main.c @@ -158,6 +158,13 @@ static int pdsc_map_bars(struct pdsc *pdsc) return err; } +void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num) +{ + return pci_iomap_range(pdsc->pdev, + pdsc->bars[PDS_CORE_PCI_BAR_DBELL].res_index, + (u64)page_num << PAGE_SHIFT, PAGE_SIZE); +} + static DEFINE_IDA(pdsc_pf_ida); #define PDSC_WQ_NAME_LEN 24 @@ -227,11 +234,15 @@ static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) /* PDS device setup */ mutex_init(&pdsc->devcmd_lock); mutex_init(&pdsc->config_lock); + spin_lock_init(&pdsc->adminq_lock); mutex_lock(&pdsc->config_lock); err = pdsc_setup(pdsc, PDSC_SETUP_INIT); if (err) goto err_out_unmap_bars; + err = pdsc_start(pdsc); + if (err) + goto err_out_teardown; /* publish devlink device */ err = pdsc_dl_register(pdsc); @@ -251,6 +262,8 @@ static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return 0; err_out: + pdsc_stop(pdsc); +err_out_teardown: pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING); err_out_unmap_bars: del_timer_sync(&pdsc->wdtimer); @@ -299,6 +312,7 @@ static void pdsc_remove(struct pci_dev *pdev) } /* Device teardown */ + pdsc_stop(pdsc); pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING); pdsc_debugfs_del_dev(pdsc); mutex_unlock(&pdsc->config_lock); diff --git a/include/linux/pds/pds_adminq.h b/include/linux/pds/pds_adminq.h new file mode 100644 index 000000000000..b06d28d0f906 --- /dev/null +++ b/include/linux/pds/pds_adminq.h @@ -0,0 +1,641 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2022 Pensando Systems, Inc */ + +#ifndef _PDS_CORE_ADMINQ_H_ +#define _PDS_CORE_ADMINQ_H_ + +enum pds_core_adminq_flags { + PDS_AQ_FLAG_FASTPOLL = BIT(1), /* poll for completion at 1ms intervals */ +}; + +/* + * enum pds_core_adminq_opcode - AdminQ command opcodes + * These commands are only processed on AdminQ, not available in devcmd + */ +enum pds_core_adminq_opcode { + PDS_AQ_CMD_NOP = 0, + + /* Client control */ + PDS_AQ_CMD_CLIENT_REG = 6, + PDS_AQ_CMD_CLIENT_UNREG = 7, + PDS_AQ_CMD_CLIENT_CMD = 8, + + /* LIF commands */ + PDS_AQ_CMD_LIF_IDENTIFY = 20, + PDS_AQ_CMD_LIF_INIT = 21, + PDS_AQ_CMD_LIF_RESET = 22, + PDS_AQ_CMD_LIF_GETATTR = 23, + PDS_AQ_CMD_LIF_SETATTR = 24, + PDS_AQ_CMD_LIF_SETPHC = 25, + + PDS_AQ_CMD_RX_MODE_SET = 30, + PDS_AQ_CMD_RX_FILTER_ADD = 31, + PDS_AQ_CMD_RX_FILTER_DEL = 32, + + /* Queue commands */ + PDS_AQ_CMD_Q_IDENTIFY = 39, + PDS_AQ_CMD_Q_INIT = 40, + PDS_AQ_CMD_Q_CONTROL = 41, + + /* RDMA commands */ + PDS_AQ_CMD_RDMA_RESET_LIF = 50, + PDS_AQ_CMD_RDMA_CREATE_EQ = 51, + PDS_AQ_CMD_RDMA_CREATE_CQ = 52, + PDS_AQ_CMD_RDMA_CREATE_ADMINQ = 53, + + /* SR/IOV commands */ + PDS_AQ_CMD_VF_GETATTR = 60, + PDS_AQ_CMD_VF_SETATTR = 61, +}; + +/* + * enum pds_core_notifyq_opcode - NotifyQ event codes + */ +enum pds_core_notifyq_opcode { + PDS_EVENT_LINK_CHANGE = 1, + PDS_EVENT_RESET = 2, + PDS_EVENT_XCVR = 5, + PDS_EVENT_CLIENT = 6, +}; + +#define PDS_COMP_COLOR_MASK 0x80 + +/** + * struct pds_core_notifyq_event - Generic event reporting structure + * @eid: event number + * @ecode: event code + * + * This is the generic event report struct from which the other + * actual events will be formed. + */ +struct pds_core_notifyq_event { + __le64 eid; + __le16 ecode; +}; + +/** + * struct pds_core_link_change_event - Link change event notification + * @eid: event number + * @ecode: event code = PDS_EVENT_LINK_CHANGE + * @link_status: link up/down, with error bits (enum pds_core_port_status) + * @link_speed: speed of the network link + * + * Sent when the network link state changes between UP and DOWN + */ +struct pds_core_link_change_event { + __le64 eid; + __le16 ecode; + __le16 link_status; + __le32 link_speed; /* units of 1Mbps: e.g. 10000 = 10Gbps */ +}; + +/** + * struct pds_core_reset_event - Reset event notification + * @eid: event number + * @ecode: event code = PDS_EVENT_RESET + * @reset_code: reset type + * @state: 0=pending, 1=complete, 2=error + * + * Sent when the NIC or some subsystem is going to be or + * has been reset. + */ +struct pds_core_reset_event { + __le64 eid; + __le16 ecode; + u8 reset_code; + u8 state; +}; + +/** + * struct pds_core_client_event - Client event notification + * @eid: event number + * @ecode: event code = PDS_EVENT_CLIENT + * @client_id: client to sent event to + * @client_event: wrapped event struct for the client + * + * Sent when an event needs to be passed on to a client + */ +struct pds_core_client_event { + __le64 eid; + __le16 ecode; + __le16 client_id; + u8 client_event[54]; +}; + +/** + * struct pds_core_notifyq_cmd - Placeholder for building qcq + * @data: anonymous field for building the qcq + */ +struct pds_core_notifyq_cmd { + __le32 data; /* Not used but needed for qcq structure */ +}; + +/* + * union pds_core_notifyq_comp - Overlay of notifyq event structures + */ +union pds_core_notifyq_comp { + struct { + __le64 eid; + __le16 ecode; + }; + struct pds_core_notifyq_event event; + struct pds_core_link_change_event link_change; + struct pds_core_reset_event reset; + u8 data[64]; +}; + +/** + * struct pds_core_client_reg_cmd - Register a new client with DSC + * @opcode: opcode PDS_AQ_CMD_CLIENT_REG + * @rsvd: word boundary padding + * @devname: text name of client device + * @vif_type: what type of device (enum pds_core_vif_types) + * + * Tell the DSC of the new client, and receive a client_id from DSC. + */ +struct pds_core_client_reg_cmd { + u8 opcode; + u8 rsvd[3]; + char devname[32]; + u8 vif_type; +}; + +/** + * struct pds_core_client_reg_comp - Client registration completion + * @status: Status of the command (enum pdc_core_status_code) + * @rsvd: Word boundary padding + * @comp_index: Index in the descriptor ring for which this is the completion + * @client_id: New id assigned by DSC + * @rsvd1: Word boundary padding + * @color: Color bit + */ + +struct pds_core_client_reg_comp { + u8 status; + u8 rsvd; + __le16 comp_index; + __le16 client_id; + u8 rsvd1[9]; + u8 color; +}; + +/** + * struct pds_core_client_unreg_cmd - Unregister a client from DSC + * @opcode: opcode PDS_AQ_CMD_CLIENT_UNREG + * @rsvd: word boundary padding + * @client_id: id of client being removed + * + * Tell the DSC this client is going away and remove its context + * This uses the generic completion. + */ +struct pds_core_client_unreg_cmd { + u8 opcode; + u8 rsvd; + __le16 client_id; +}; + +/** + * struct pds_core_client_request_cmd - Pass along a wrapped client AdminQ cmd + * @opcode: opcode PDS_AQ_CMD_CLIENT_CMD + * @rsvd: word boundary padding + * @client_id: id of client being removed + * @client_cmd: the wrapped clinet command + * + * Proxy post an adminq command for the client. + * This uses the generic completion. + */ +struct pds_core_client_request_cmd { + u8 opcode; + u8 rsvd; + __le16 client_id; + u8 client_cmd[60]; +}; + +#define PDS_CORE_MAX_FRAGS 16 + +#define PDS_CORE_QCQ_F_INITED BIT(0) +#define PDS_CORE_QCQ_F_SG BIT(1) +#define PDS_CORE_QCQ_F_INTR BIT(2) +#define PDS_CORE_QCQ_F_TX_STATS BIT(3) +#define PDS_CORE_QCQ_F_RX_STATS BIT(4) +#define PDS_CORE_QCQ_F_NOTIFYQ BIT(5) +#define PDS_CORE_QCQ_F_CMB_RINGS BIT(6) +#define PDS_CORE_QCQ_F_CORE BIT(7) + +enum pds_core_lif_type { + PDS_CORE_LIF_TYPE_DEFAULT = 0, +}; + +/** + * union pds_core_lif_config - LIF configuration + * @state: LIF state (enum pds_core_lif_state) + * @rsvd: Word boundary padding + * @name: LIF name + * @rsvd2: Word boundary padding + * @features: LIF features active (enum pds_core_hw_features) + * @queue_count: Queue counts per queue-type + * @words: Full union buffer size + */ +union pds_core_lif_config { + struct { + u8 state; + u8 rsvd[3]; + char name[PDS_CORE_IFNAMSIZ]; + u8 rsvd2[12]; + __le64 features; + __le32 queue_count[PDS_CORE_QTYPE_MAX]; + } __packed; + __le32 words[64]; +}; + +/** + * struct pds_core_lif_status - LIF status register + * @eid: most recent NotifyQ event id + * @rsvd: full struct size + */ +struct pds_core_lif_status { + __le64 eid; + u8 rsvd[56]; +}; + +/** + * struct pds_core_lif_info - LIF info structure + * @config: LIF configuration structure + * @status: LIF status structure + */ +struct pds_core_lif_info { + union pds_core_lif_config config; + struct pds_core_lif_status status; +}; + +/** + * struct pds_core_lif_identity - LIF identity information (type-specific) + * @features: LIF features (see enum pds_core_hw_features) + * @version: Identify structure version + * @hw_index: LIF hardware index + * @rsvd: Word boundary padding + * @max_nb_sessions: Maximum number of sessions supported + * @rsvd2: buffer padding + * @config: LIF config struct with features, q counts + */ +struct pds_core_lif_identity { + __le64 features; + u8 version; + u8 hw_index; + u8 rsvd[2]; + __le32 max_nb_sessions; + u8 rsvd2[120]; + union pds_core_lif_config config; +}; + +/** + * struct pds_core_lif_identify_cmd - Get LIF identity info command + * @opcode: Opcode PDS_AQ_CMD_LIF_IDENTIFY + * @type: LIF type (enum pds_core_lif_type) + * @client_id: Client identifier + * @ver: Version of identify returned by device + * @rsvd: Word boundary padding + * @ident_pa: DMA address to receive identity info (struct pds_core_lif_identity) + * + * Firmware will copy LIF identity data (struct pds_core_lif_identity) + * into the buffer address given. + */ +struct pds_core_lif_identify_cmd { + u8 opcode; + u8 type; + __le16 client_id; + u8 ver; + u8 rsvd[3]; + __le64 ident_pa; +}; + +/** + * struct pds_core_lif_identify_comp - LIF identify command completion + * @status: Status of the command (enum pds_core_status_code) + * @ver: Version of identify returned by device + * @bytes: Bytes copied into the buffer + * @rsvd: Word boundary padding + * @color: Color bit + */ +struct pds_core_lif_identify_comp { + u8 status; + u8 ver; + __le16 bytes; + u8 rsvd[11]; + u8 color; +}; + +/** + * struct pds_core_lif_init_cmd - LIF init command + * @opcode: Opcode PDS_AQ_CMD_LIF_INIT + * @type: LIF type (enum pds_core_lif_type) + * @client_id: Client identifier + * @rsvd: Word boundary padding + * @info_pa: Destination address for LIF info (struct pds_core_lif_info) + */ +struct pds_core_lif_init_cmd { + u8 opcode; + u8 type; + __le16 client_id; + __le32 rsvd; + __le64 info_pa; +}; + +/** + * struct pds_core_lif_init_comp - LIF init command completion + * @status: Status of the command (enum pds_core_status_code) + * @rsvd: Word boundary padding + * @hw_index: Hardware index of the initialized LIF + * @rsvd1: Word boundary padding + * @color: Color bit + */ +struct pds_core_lif_init_comp { + u8 status; + u8 rsvd; + __le16 hw_index; + u8 rsvd1[11]; + u8 color; +}; + +/** + * struct pds_core_lif_reset_cmd - LIF reset command + * Will reset only the specified LIF. + * @opcode: Opcode PDS_AQ_CMD_LIF_RESET + * @rsvd: Word boundary padding + * @client_id: Client identifier + */ +struct pds_core_lif_reset_cmd { + u8 opcode; + u8 rsvd; + __le16 client_id; +}; + +/** + * enum pds_core_lif_attr - List of LIF attributes + * @PDS_CORE_LIF_ATTR_STATE: LIF state attribute + * @PDS_CORE_LIF_ATTR_NAME: LIF name attribute + * @PDS_CORE_LIF_ATTR_FEATURES: LIF features attribute + * @PDS_CORE_LIF_ATTR_STATS_CTRL: LIF statistics control attribute + */ +enum pds_core_lif_attr { + PDS_CORE_LIF_ATTR_STATE = 0, + PDS_CORE_LIF_ATTR_NAME = 1, + PDS_CORE_LIF_ATTR_FEATURES = 4, + PDS_CORE_LIF_ATTR_STATS_CTRL = 6, +}; + +/** + * struct pds_core_lif_setattr_cmd - Set LIF attributes on the NIC + * @opcode: Opcode PDS_AQ_CMD_LIF_SETATTR + * @attr: Attribute type (enum pds_core_lif_attr) + * @client_id: Client identifier + * @state: LIF state (enum pds_core_lif_state) + * @name: The name string, 0 terminated + * @features: Features (enum pds_core_hw_features) + * @stats_ctl: Stats control commands (enum pds_core_stats_ctl_cmd) + * @rsvd: Command Buffer padding + */ +struct pds_core_lif_setattr_cmd { + u8 opcode; + u8 attr; + __le16 client_id; + union { + u8 state; + char name[PDS_CORE_IFNAMSIZ]; + __le64 features; + u8 stats_ctl; + u8 rsvd[60]; + } __packed; +}; + +/** + * struct pds_core_lif_setattr_comp - LIF set attr command completion + * @status: Status of the command (enum pds_core_status_code) + * @rsvd: Word boundary padding + * @comp_index: Index in the descriptor ring for which this is the completion + * @features: Features (enum pds_core_hw_features) + * @rsvd2: Word boundary padding + * @color: Color bit + */ +struct pds_core_lif_setattr_comp { + u8 status; + u8 rsvd; + __le16 comp_index; + union { + __le64 features; + u8 rsvd2[11]; + } __packed; + u8 color; +}; + +/** + * struct pds_core_lif_getattr_cmd - Get LIF attributes from the NIC + * @opcode: Opcode PDS_AQ_CMD_LIF_GETATTR + * @attr: Attribute type (enum pds_core_lif_attr) + * @client_id: Client identifier + */ +struct pds_core_lif_getattr_cmd { + u8 opcode; + u8 attr; + __le16 client_id; +}; + +/** + * struct pds_core_lif_getattr_comp - LIF get attr command completion + * @status: Status of the command (enum pds_core_status_code) + * @rsvd: Word boundary padding + * @comp_index: Index in the descriptor ring for which this is the completion + * @state: LIF state (enum pds_core_lif_state) + * @name: LIF name string, 0 terminated + * @features: Features (enum pds_core_hw_features) + * @rsvd2: Word boundary padding + * @color: Color bit + */ +struct pds_core_lif_getattr_comp { + u8 status; + u8 rsvd; + __le16 comp_index; + union { + u8 state; + __le64 features; + u8 rsvd2[11]; + } __packed; + u8 color; +}; + +/** + * union pds_core_q_identity - Queue identity information + * @version: Queue type version that can be used with FW + * @supported: Bitfield of queue versions, first bit = ver 0 + * @rsvd: Word boundary padding + * @features: Queue features + * @desc_sz: Descriptor size + * @comp_sz: Completion descriptor size + * @rsvd2: Word boundary padding + */ +struct pds_core_q_identity { + u8 version; + u8 supported; + u8 rsvd[6]; +#define PDS_CORE_QIDENT_F_CQ 0x01 /* queue has completion ring */ + __le64 features; + __le16 desc_sz; + __le16 comp_sz; + u8 rsvd2[6]; +}; + +/** + * struct pds_core_q_identify_cmd - queue identify command + * @opcode: Opcode PDS_AQ_CMD_Q_IDENTIFY + * @type: Logical queue type (enum pds_core_logical_qtype) + * @client_id: Client identifier + * @ver: Highest queue type version that the driver supports + * @rsvd: Word boundary padding + * @ident_pa: DMA address to receive the data (struct pds_core_q_identity) + */ +struct pds_core_q_identify_cmd { + u8 opcode; + u8 type; + __le16 client_id; + u8 ver; + u8 rsvd[3]; + __le64 ident_pa; +}; + +/** + * struct pds_core_q_identify_comp - queue identify command completion + * @status: Status of the command (enum pds_core_status_code) + * @rsvd: Word boundary padding + * @comp_index: Index in the descriptor ring for which this is the completion + * @ver: Queue type version that can be used with FW + * @rsvd1: Word boundary padding + * @color: Color bit + */ +struct pds_core_q_identify_comp { + u8 status; + u8 rsvd; + __le16 comp_index; + u8 ver; + u8 rsvd1[10]; + u8 color; +}; + +/** + * struct pds_core_q_init_cmd - Queue init command + * @opcode: Opcode PDS_AQ_CMD_Q_INIT + * @type: Logical queue type + * @client_id: Client identifier + * @ver: Queue type version + * @rsvd: Word boundary padding + * @index: (LIF, qtype) relative admin queue index + * @intr_index: Interrupt control register index, or Event queue index + * @pid: Process ID + * @flags: + * IRQ: Interrupt requested on completion + * ENA: Enable the queue. If ENA=0 the queue is initialized + * but remains disabled, to be later enabled with the + * Queue Enable command. If ENA=1, then queue is + * initialized and then enabled. + * @cos: Class of service for this queue + * @ring_size: Queue ring size, encoded as a log2(size), in + * number of descriptors. The actual ring size is + * (1 << ring_size). For example, to select a ring size + * of 64 descriptors write ring_size = 6. The minimum + * ring_size value is 2 for a ring of 4 descriptors. + * The maximum ring_size value is 12 for a ring of 4k + * descriptors. Values of ring_size <2 and >12 are + * reserved. + * @ring_base: Queue ring base address + * @cq_ring_base: Completion queue ring base address + */ +struct pds_core_q_init_cmd { + u8 opcode; + u8 type; + __le16 client_id; + u8 ver; + u8 rsvd[3]; + __le32 index; + __le16 pid; + __le16 intr_index; + __le16 flags; +#define PDS_CORE_QINIT_F_IRQ 0x01 /* Request interrupt on completion */ +#define PDS_CORE_QINIT_F_ENA 0x02 /* Enable the queue */ + u8 cos; +#define PDS_CORE_QSIZE_MIN_LG2 2 +#define PDS_CORE_QSIZE_MAX_LG2 12 + u8 ring_size; + __le64 ring_base; + __le64 cq_ring_base; +} __packed; + +/** + * struct pds_core_q_init_comp - Queue init command completion + * @status: Status of the command (enum pds_core_status_code) + * @rsvd: Word boundary padding + * @comp_index: Index in the descriptor ring for which this is the completion + * @hw_index: Hardware Queue ID + * @hw_type: Hardware Queue type + * @rsvd2: Word boundary padding + * @color: Color + */ +struct pds_core_q_init_comp { + u8 status; + u8 rsvd; + __le16 comp_index; + __le32 hw_index; + u8 hw_type; + u8 rsvd2[6]; + u8 color; +}; + +union pds_core_adminq_cmd { + u8 opcode; + u8 bytes[64]; + + struct pds_core_client_reg_cmd client_reg; + struct pds_core_client_unreg_cmd client_unreg; + struct pds_core_client_request_cmd client_request; + + struct pds_core_lif_identify_cmd lif_ident; + struct pds_core_lif_init_cmd lif_init; + struct pds_core_lif_reset_cmd lif_reset; + struct pds_core_lif_setattr_cmd lif_setattr; + struct pds_core_lif_getattr_cmd lif_getattr; + + struct pds_core_q_identify_cmd q_ident; + struct pds_core_q_init_cmd q_init; +}; + +union pds_core_adminq_comp { + struct { + u8 status; + u8 rsvd; + __le16 comp_index; + u8 rsvd2[11]; + u8 color; + }; + u32 words[4]; + + struct pds_core_client_reg_comp client_reg; + + struct pds_core_lif_identify_comp lif_ident; + struct pds_core_lif_init_comp lif_init; + struct pds_core_lif_setattr_comp lif_setattr; + struct pds_core_lif_getattr_comp lif_getattr; + + struct pds_core_q_identify_comp q_ident; + struct pds_core_q_init_comp q_init; +}; + +#ifndef __CHECKER__ +static_assert(sizeof(union pds_core_adminq_cmd) == 64); +static_assert(sizeof(union pds_core_adminq_comp) == 16); +static_assert(sizeof(union pds_core_notifyq_comp) == 64); +#endif /* __CHECKER__ */ + +static inline u8 pdsc_color_match(u8 color, u8 done_color) +{ + return (!!(color & PDS_COMP_COLOR_MASK)) == done_color; +} + +#endif /* _PDS_CORE_ADMINQ_H_ */ From patchwork Wed Dec 7 00:44:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066441 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A8C3C352A1 for ; Wed, 7 Dec 2022 00:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbiLGApd (ORCPT ); Tue, 6 Dec 2022 19:45:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbiLGApY (ORCPT ); Tue, 6 Dec 2022 19:45:24 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20608.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::608]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA1723207C for ; Tue, 6 Dec 2022 16:45:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KfNB1oyKQweOkz4Mh7i94EQC2LMZzcl4t+eG+7a3LiSkBIiIm6URQav3AVy7qlslNNJBF3areaGCaBfZJeW6Z3Qw1g/lc0dsi7gjmYkP7mxaP3AgiBMqktndP62Ez/u/Z8+AC6tbfkR+32QrbwN/cyKeYUuVBZ4y3QUbOKLn6JAK8mODE6cVCRlGmOTxnN6G3vMYjs7d9zD8tz7BiWXNxgKJmBIBKhwz9fC6G8K4VAnXssF92Zze/nEQ+BUPNOhX1c3IEI1YUlJ/0Ui7jO24RldxsnmMfi3CUW0McLTqw5JQfG/C4Y3vG7InVmBYhLMXQ/k/ELhx3PU23MYNztbdHg== 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=sKTZ1F37KVZpCQ1jvkSXGve4fl4em3gXNcA+z/oE0CU=; b=gcleSncCtMRMsRZ4lzLYlaVhY376dN2l0rTPFgBTEAgxs9s6T96D3D/s3qdi4A9RcoIm0U1r+d6YU/FFRhfbBS7jm/zvgSaZDG0AyWqKS+i5UftGzkTe6ly7aUA5L8PtE67uKz93KCcWNcV5JFYP5wK3kGgBlW4O9H0IVCUVHJIqAvqvev87mqquR29+q+CEl8DYVFq0pt/3muHxckGfZUg8KwMJUpeiHLfgh6tXLTpIOykInok3OpnNCdzep40IfbzndBD1Yg1JgvaAEqqtdhJVBVpAU5H8NN8x4npwQC759DsMt4rYYFSTPRx7LPDiggjk7TjinT4T7K/BHGXipQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sKTZ1F37KVZpCQ1jvkSXGve4fl4em3gXNcA+z/oE0CU=; b=FUVs9Bs3+zHgVk7JP5XcX+iuZaPsE1JEdXvwvyKXasDtKjIwbKRVRysm4XowhMlx2yoeWld/zXeEaHT2nXqZW+TX7PufXqsBwLnTs+l7ZKYj8njIR5NZHl8vnbw0HRtRiovyrRPAvgSetA9d6eoK1S561W4ucp3oHxbyB2cAGAk= Received: from BN9PR03CA0263.namprd03.prod.outlook.com (2603:10b6:408:ff::28) by PH8PR12MB6771.namprd12.prod.outlook.com (2603:10b6:510:1c6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:10 +0000 Received: from BN8NAM11FT112.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::2) by BN9PR03CA0263.outlook.office365.com (2603:10b6:408:ff::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT112.mail.protection.outlook.com (10.13.176.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:10 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:09 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 07/16] pds_core: Add adminq processing and commands Date: Tue, 6 Dec 2022 16:44:34 -0800 Message-ID: <20221207004443.33779-8-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT112:EE_|PH8PR12MB6771:EE_ X-MS-Office365-Filtering-Correlation-Id: 941db0f2-6dbd-4821-a29f-08dad7ec4b4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fxJ+DdGioJpDFU6caweEI/FrtTfqcFQvH3Q2mcFyUo5maeokzfTtJFZB2zzF5j8/RTFHCb4PdtYpn9A5c6MsmQNaG5+IrMLOFCLUOxjh/2rwHBJU1D692htwvsQt+Ei5GGpQgvbo0xRYXxshOXzY89tZ+hnBT22VVRMuq5yaaZ5Qc9MQ5Zr7VIk06gAuDzUlNtItedPj/m4iB4sFuIPjS7vYZIQA+9H9Aev4p+Dv9p4qvZNZ2Z8n6qwFKeWQpqlhZMm2HOFCjF7KwFiJ5E+pZvCgZvZHqOrvR1rhT9fP/PHDcZ/I3eCyodRPkb72EFmaJ8ZbrEBeRKJO0XQd9x40HxMt4fOv11sGIGtUa8AV38k7bwLaoNqJZjSXrZBrK/49rpQ1cbtLtaQeQLTYPlcOTdsC5l8t4ZpryuMDSKbSDRs22+OXvdhkyN2xlxJ1Nrcwbi/jwcc0iloKif5DsgG2GjvQ1rCsK7EUHE0tccwtemFLqIQ7IJRJI6ent6fyUI1p2k1D6Sg5lkQf7lH2MGkNTIeoiSU492iNNwK/FYGuk49/EcQ8btxVOE/xIjftmnNL3yjVFlWVDO2Z1UVLTtWCX0usfVuKSj1FG8DBWEIfs81FILZgJ6dlsK4GK50N6+qemiy2DMXCBXRNQXxbr66seheeYznKnC+074XuGI1K4AI+B9eeB9lx8xOrw17qgP/MpEmqcDdoEITal0zPT8vV0haXwQH+/3pWu0GM19lAR2c= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(39860400002)(396003)(451199015)(36840700001)(40470700004)(46966006)(36756003)(316002)(41300700001)(81166007)(40460700003)(86362001)(8936002)(4326008)(2906002)(5660300002)(82740400003)(30864003)(44832011)(36860700001)(83380400001)(356005)(70206006)(478600001)(70586007)(2616005)(54906003)(110136005)(40480700001)(82310400005)(8676002)(6666004)(47076005)(426003)(1076003)(16526019)(186003)(336012)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:10.1576 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 941db0f2-6dbd-4821-a29f-08dad7ec4b4e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT112.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6771 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add the service routines for submitting and processing the adminq messages and for handling notifyq events. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/pds_core/Makefile | 1 + .../net/ethernet/pensando/pds_core/adminq.c | 282 ++++++++++++++++++ drivers/net/ethernet/pensando/pds_core/core.c | 11 - drivers/net/ethernet/pensando/pds_core/core.h | 6 + include/linux/pds/pds_adminq.h | 2 + 5 files changed, 291 insertions(+), 11 deletions(-) create mode 100644 drivers/net/ethernet/pensando/pds_core/adminq.c diff --git a/drivers/net/ethernet/pensando/pds_core/Makefile b/drivers/net/ethernet/pensando/pds_core/Makefile index 446054206b6a..c7a722f7d9b8 100644 --- a/drivers/net/ethernet/pensando/pds_core/Makefile +++ b/drivers/net/ethernet/pensando/pds_core/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_PDS_CORE) := pds_core.o pds_core-y := main.o \ devlink.o \ dev.o \ + adminq.o \ core.o pds_core-$(CONFIG_DEBUG_FS) += debugfs.o diff --git a/drivers/net/ethernet/pensando/pds_core/adminq.c b/drivers/net/ethernet/pensando/pds_core/adminq.c new file mode 100644 index 000000000000..ba9e84a7ca92 --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/adminq.c @@ -0,0 +1,282 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2022 Pensando Systems, Inc */ + +#include +#include +#include +#include + +#include "core.h" + +#include + +struct pdsc_wait_context { + struct pdsc_qcq *qcq; + struct completion wait_completion; +}; + +static int pdsc_process_notifyq(struct pdsc_qcq *qcq) +{ + union pds_core_notifyq_comp *comp; + struct pdsc *pdsc = qcq->pdsc; + struct pdsc_cq *cq = &qcq->cq; + struct pdsc_cq_info *cq_info; + int nq_work = 0; + u64 eid; + + cq_info = &cq->info[cq->tail_idx]; + comp = cq_info->comp; + eid = le64_to_cpu(comp->event.eid); + while (eid > pdsc->last_eid) { + u16 ecode = le16_to_cpu(comp->event.ecode); + + switch (ecode) { + case PDS_EVENT_LINK_CHANGE: + dev_info(pdsc->dev, "NotifyQ LINK_CHANGE ecode %d eid %lld\n", + ecode, eid); + break; + + case PDS_EVENT_RESET: + dev_info(pdsc->dev, "NotifyQ RESET ecode %d eid %lld\n", + ecode, eid); + break; + + case PDS_EVENT_XCVR: + dev_info(pdsc->dev, "NotifyQ XCVR ecode %d eid %lld\n", + ecode, eid); + break; + + default: + dev_info(pdsc->dev, "NotifyQ ecode %d eid %lld\n", + ecode, eid); + break; + } + + pdsc->last_eid = eid; + cq->tail_idx = (cq->tail_idx + 1) & (cq->num_descs - 1); + cq_info = &cq->info[cq->tail_idx]; + comp = cq_info->comp; + eid = le64_to_cpu(comp->event.eid); + + nq_work++; + } + + qcq->accum_work += nq_work; + + return nq_work; +} + +void pdsc_process_adminq(struct pdsc_qcq *qcq) +{ + union pds_core_adminq_comp *comp; + struct pdsc_queue *q = &qcq->q; + struct pdsc *pdsc = qcq->pdsc; + struct pdsc_cq *cq = &qcq->cq; + struct pdsc_q_info *q_info; + unsigned long irqflags; + int nq_work = 0; + int aq_work = 0; + int credits; + u32 index; + + /* Check for NotifyQ event */ + nq_work = pdsc_process_notifyq(&pdsc->notifyqcq); + + /* Check for empty queue, which can happen if the interrupt was + * for a NotifyQ event and there are no new AdminQ completions. + */ + if (q->tail_idx == q->head_idx) + goto credits; + + /* Find the first completion to clean, + * run the callback in the related q_info, + * and continue while we still match done color + */ + spin_lock_irqsave(&pdsc->adminq_lock, irqflags); + comp = cq->info[cq->tail_idx].comp; + while (pdsc_color_match(comp->color, cq->done_color)) { + q_info = &q->info[q->tail_idx]; + index = q->tail_idx; + q->tail_idx = (q->tail_idx + 1) & (q->num_descs - 1); + + /* Copy out the completion data */ + memcpy(q_info->dest, comp, sizeof(*comp)); + + complete_all(&q_info->wc->wait_completion); + + if (cq->tail_idx == cq->num_descs - 1) + cq->done_color = !cq->done_color; + cq->tail_idx = (cq->tail_idx + 1) & (cq->num_descs - 1); + comp = cq->info[cq->tail_idx].comp; + + aq_work++; + } + spin_unlock_irqrestore(&pdsc->adminq_lock, irqflags); + + qcq->accum_work += aq_work; + +credits: + /* Return the interrupt credits, one for each completion */ + credits = nq_work + aq_work; + if (credits) + pds_core_intr_credits(&pdsc->intr_ctrl[qcq->intx], + credits, + PDS_CORE_INTR_CRED_REARM); +} + +void pdsc_work_thread(struct work_struct *work) +{ + struct pdsc_qcq *qcq = container_of(work, struct pdsc_qcq, work); + + pdsc_process_adminq(qcq); +} + +irqreturn_t pdsc_adminq_isr(int irq, void *data) +{ + struct pdsc_qcq *qcq = data; + struct pdsc *pdsc = qcq->pdsc; + + /* Don't process AdminQ when shutting down */ + if (pdsc->state & BIT_ULL(PDSC_S_STOPPING_DRIVER)) { + pr_err("%s: called while PDSC_S_STOPPING_DRIVER\n", __func__); + return IRQ_HANDLED; + } + + queue_work(pdsc->wq, &qcq->work); + pds_core_intr_mask(&pdsc->intr_ctrl[irq], PDS_CORE_INTR_MASK_CLEAR); + + return IRQ_HANDLED; +} + +static int __pdsc_adminq_post(struct pdsc *pdsc, + struct pdsc_qcq *qcq, + union pds_core_adminq_cmd *cmd, + union pds_core_adminq_comp *comp, + struct pdsc_wait_context *wc) +{ + struct pdsc_queue *q = &qcq->q; + struct pdsc_q_info *q_info; + unsigned long irqflags; + unsigned int avail; + int ret = 0; + int index; + + spin_lock_irqsave(&pdsc->adminq_lock, irqflags); + + /* Check for space in the queue */ + avail = q->tail_idx; + if (q->head_idx >= avail) + avail += q->num_descs - q->head_idx - 1; + else + avail -= q->head_idx + 1; + if (!avail) { + ret = -ENOSPC; + goto err_out; + } + + /* Check that the FW is running */ + if (!pdsc_is_fw_running(pdsc)) { + u8 fw_status = ioread8(&pdsc->info_regs->fw_status); + + dev_info(pdsc->dev, "%s: post failed - fw not running %#02x:\n", + __func__, fw_status); + ret = -ENXIO; + + goto err_out; + } + + /* Post the request */ + index = q->head_idx; + q_info = &q->info[index]; + q_info->wc = wc; + q_info->dest = comp; + memcpy(q_info->desc, cmd, sizeof(*cmd)); + + dev_dbg(pdsc->dev, "head_idx %d tail_idx %d\n", q->head_idx, q->tail_idx); + dev_dbg(pdsc->dev, "post admin queue command:\n"); + dynamic_hex_dump("cmd ", DUMP_PREFIX_OFFSET, 16, 1, + cmd, sizeof(*cmd), true); + + q->head_idx = (q->head_idx + 1) & (q->num_descs - 1); + + pds_core_dbell_ring(pdsc->kern_dbpage, q->hw_type, q->dbval | q->head_idx); + ret = index; + +err_out: + spin_unlock_irqrestore(&pdsc->adminq_lock, irqflags); + return ret; +} + +int pdsc_adminq_post(struct pdsc *pdsc, + struct pdsc_qcq *qcq, + union pds_core_adminq_cmd *cmd, + union pds_core_adminq_comp *comp, + bool fast_poll) +{ + struct pdsc_wait_context wc = { + .wait_completion = COMPLETION_INITIALIZER_ONSTACK(wc.wait_completion), + .qcq = qcq, + }; + unsigned long poll_interval = 1; + unsigned long time_limit; + unsigned long time_start; + unsigned long time_done; + unsigned long remaining; + int err = 0; + int index; + + index = __pdsc_adminq_post(pdsc, qcq, cmd, comp, &wc); + if (index < 0) { + err = index; + goto out; + } + + time_start = jiffies; + time_limit = time_start + HZ * pdsc->devcmd_timeout; + do { + /* Timeslice the actual wait to catch IO errors etc early */ + remaining = wait_for_completion_timeout(&wc.wait_completion, + msecs_to_jiffies(poll_interval)); + if (remaining) + break; + + if (!pdsc_is_fw_running(pdsc)) { + u8 fw_status = ioread8(&pdsc->info_regs->fw_status); + + dev_dbg(pdsc->dev, "%s: post wait failed - fw not running %#02x:\n", + __func__, fw_status); + err = -ENXIO; + break; + } + + /* When fast_poll is not requested, prevent aggressive polling + * on failures due to timeouts by doing exponential back off. + */ + if (!fast_poll && poll_interval < PDSC_ADMINQ_MAX_POLL_INTERVAL) + poll_interval <<= 1; + } while (time_before(jiffies, time_limit)); + time_done = jiffies; + dev_dbg(pdsc->dev, "%s: elapsed %d msecs\n", + __func__, jiffies_to_msecs(time_done - time_start)); + + /* Check the results */ + if (time_after_eq(time_done, time_limit)) + err = -ETIMEDOUT; + + dev_dbg(pdsc->dev, "read admin queue completion idx %d:\n", index); + dynamic_hex_dump("comp ", DUMP_PREFIX_OFFSET, 16, 1, + comp, sizeof(*comp), true); + + if (remaining && comp->status) + err = pdsc_err_to_errno(comp->status); + +out: + if (err) { + dev_dbg(pdsc->dev, "%s: opcode %d status %d err %pe\n", + __func__, cmd->opcode, comp->status, ERR_PTR(err)); + if (err == -ENXIO || err == -ETIMEDOUT) + pdsc_queue_health_check(pdsc); + } + + return err; +} diff --git a/drivers/net/ethernet/pensando/pds_core/core.c b/drivers/net/ethernet/pensando/pds_core/core.c index 507f718bc8ab..e2017cee8284 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.c +++ b/drivers/net/ethernet/pensando/pds_core/core.c @@ -12,17 +12,6 @@ #include -void pdsc_work_thread(struct work_struct *work) -{ - /* stub */ -} - -irqreturn_t pdsc_adminq_isr(int irq, void *data) -{ - /* stub */ - return IRQ_HANDLED; -} - void pdsc_intr_free(struct pdsc *pdsc, int index) { struct pdsc_intr_info *intr_info; diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h index 3d1023f0eeb2..bdb3a29d789e 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.h +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -260,6 +260,12 @@ int pdsc_devcmd_reset(struct pdsc *pdsc); int pdsc_dev_reinit(struct pdsc *pdsc); int pdsc_dev_init(struct pdsc *pdsc); +int pdsc_adminq_post(struct pdsc *pdsc, + struct pdsc_qcq *qcq, + union pds_core_adminq_cmd *cmd, + union pds_core_adminq_comp *comp, + bool fast_poll); + int pdsc_intr_alloc(struct pdsc *pdsc, char *name, irq_handler_t handler, void *data); void pdsc_intr_free(struct pdsc *pdsc, int index); diff --git a/include/linux/pds/pds_adminq.h b/include/linux/pds/pds_adminq.h index b06d28d0f906..19070099eb35 100644 --- a/include/linux/pds/pds_adminq.h +++ b/include/linux/pds/pds_adminq.h @@ -4,6 +4,8 @@ #ifndef _PDS_CORE_ADMINQ_H_ #define _PDS_CORE_ADMINQ_H_ +#define PDSC_ADMINQ_MAX_POLL_INTERVAL 256 + enum pds_core_adminq_flags { PDS_AQ_FLAG_FASTPOLL = BIT(1), /* poll for completion at 1ms intervals */ }; From patchwork Wed Dec 7 00:44:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066439 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D6C7C63706 for ; Wed, 7 Dec 2022 00:45:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229811AbiLGAp3 (ORCPT ); Tue, 6 Dec 2022 19:45:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229719AbiLGApN (ORCPT ); Tue, 6 Dec 2022 19:45:13 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2052.outbound.protection.outlook.com [40.107.243.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B8A32051 for ; Tue, 6 Dec 2022 16:45:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TaVs4f2rl8SaBH33yBxEGYdV4bLtUwS5SAqHwMsz8RUnnboQJ774LjPZRXVmFjV3nKytz7X7z+rM1ZtW+v03kPYfaQQJGJRpMUNfYj267BbvAeAcOe4J0DMb0KrYSucab4y5wOle9GEAWHskClow7J5EGh1g1MrsEhj4KnDdjSIVPhaC8dXdIxz5Pmm7SwH81fYZOwckHyKC6Q87Qv+tgzmvBc6brSvf+7XNlt0soveCGY/2xkt64R09Ua1Udu2J5WnRzTOwjmHTvfZxeUo3Fao0HPogAvvYhiHo1TpNJGniOjR5x9KIEqT2lSBSMgqFvbZYwiFX0kTVQBMbs4SJcw== 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=HWbWQ++unlN+XhCdTD+fXVkmSciqcCrecxDLmHgrzWw=; b=NCP3BvJWtfJ6gIyL18bx1FcV5eRbgbHmkbRekiMYh4UyjamY0Ci1nMTAkdKeowPrICS3EA/uOI/qHK5mBfWIixjCEzVGB0Ugm1HYHtf2UDZ4FkmBhDxY60ASgObx5zkPI11nWoXICS6/g3IBMp/hxT+8xrW/1djmzzM1Z0Szz/CuRJylRgyO1EOcYHDBWjzSJzKX076PBG+BQUtozOyL8lu5fQ0yuCAExioJmZ9nwSIs2C/qchj+5VnPCyt7mW+suyO+Jt8z9HmQOEtpSsIgHfuQS0AuUTi4DTa8ETxxTX8JUwHAxZtHmt0K8VwPB8MgNh7K6uM5+YG8FXbGvkebhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HWbWQ++unlN+XhCdTD+fXVkmSciqcCrecxDLmHgrzWw=; b=ffweg+q8Ik1kt2jliQK9aKy7AUf8qcc8VaC6Ztkx347IXbkGJAnCZATZnWd2c/T7xwJY3UUZoK6Idd8ymd8QiuM2OkBk1WokXKhthbDXepX4kwY1OOMZWmWG4UA0WBKx9nE0pdXkwK5vmM1mlj+fuV4sLkCcaFzWDmnYKQXNpko= Received: from BN9PR03CA0262.namprd03.prod.outlook.com (2603:10b6:408:ff::27) by IA1PR12MB6555.namprd12.prod.outlook.com (2603:10b6:208:3a1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:10 +0000 Received: from BN8NAM11FT112.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::ae) by BN9PR03CA0262.outlook.office365.com (2603:10b6:408:ff::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT112.mail.protection.outlook.com (10.13.176.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:10 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:09 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 08/16] pds_core: add fw bank select Date: Tue, 6 Dec 2022 16:44:35 -0800 Message-ID: <20221207004443.33779-9-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT112:EE_|IA1PR12MB6555:EE_ X-MS-Office365-Filtering-Correlation-Id: 989ae6a3-23de-494a-ea32-08dad7ec4bb9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5UlFMs6z6I+LkPQO8Jo5idI+4vR49io6+BklOO4bqRxu1pOQxIbTBjqqD6kvWUegaidwgmm5FPDsQZZeBIP2rLChESknl5tTpei3WBJi9YygXI/qmW8Akl4cYEdSv/X5Jgy17fk6tEi8qng0E1/Y4JXw0/qgyDmEEdFfY6nTnuzwx2sBZf1Q5tiaZMK13CKczppdDYynZT+jXxA1eafm99//FcRE3vVkNDXKK6cb0nN8uM1v7Al2X64ric9K8sG6sRfd0C/vWIhy+uLq5gKYJ/2XdeyDlJ2t2rc7LUgJfs6DqYzvlIxu1WZ67dt3DVrM3W6LrZELDCr75vD9hxbPiyY67cFY8BFT/YkLt6VlwHqNj2tM9WKdqq9RjL5BYU2CjkXEzsCjR/fxi5ZrmSt8lY66VdGdLMF/jin2qDXcW57RbMhsE1jIVGVXhhulgBHZDCqEvIE1F+t1nItuKi7mjhkZE4ClQav0CAw1aLQT9Zg8D91dPfO3/ZTEOMyHUuqEyHIJVj0uQFv+BPfQtCg8dNgnK0FTZDWRd7Eq6S6thdB/O/5eCntHDGQzws3KSkIKWWmVu3aephRno8KGr3J9cGsG9IyfVPpVN3HrC7kcSDCx3QzfkxTXpvTmY+6yw6mTGwcsj8hucUFEDKtZosilu+WbkfJJoSTdaKdvk6JBpw5boDHRbAzW6sfoGhrUgbKQf9xREzd9YkpGXoJz+YDq/mI0UagbL2j5UTA99Kl2T4o= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(39860400002)(396003)(376002)(136003)(451199015)(46966006)(36840700001)(40470700004)(15650500001)(2906002)(8936002)(44832011)(83380400001)(8676002)(86362001)(36756003)(70206006)(4326008)(16526019)(81166007)(356005)(426003)(41300700001)(186003)(47076005)(82310400005)(2616005)(82740400003)(1076003)(5660300002)(336012)(110136005)(26005)(316002)(54906003)(36860700001)(6666004)(70586007)(478600001)(40460700003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:10.8763 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 989ae6a3-23de-494a-ea32-08dad7ec4bb9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT112.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6555 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for the fw_bank parameter to select the next bootup firmware. This can be selected at any time, and is also selected automatically when a new firmware is flashed into the device. There are three banks available in this device: 1 and 2 are the primaries for normal operations, while bank 3 has 'gold' firmware that can be selected and used as recovery fw in the case that both 1 and 2 become corrupt. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/pds_core/devlink.c | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/net/ethernet/pensando/pds_core/devlink.c b/drivers/net/ethernet/pensando/pds_core/devlink.c index 78fe657f6532..cd132573cbe0 100644 --- a/drivers/net/ethernet/pensando/pds_core/devlink.c +++ b/drivers/net/ethernet/pensando/pds_core/devlink.c @@ -8,6 +8,69 @@ #include "core.h" +static int pdsc_dl_fw_bank_get(struct devlink *dl, u32 id, + struct devlink_param_gset_ctx *ctx) +{ + struct pdsc *pdsc = devlink_priv(dl); + union pds_core_dev_cmd cmd = { + .fw_control.opcode = PDS_CORE_CMD_FW_CONTROL, + .fw_control.oper = PDS_CORE_FW_GET_BOOT, + }; + union pds_core_dev_comp comp; + int err; + + err = pdsc_devcmd(pdsc, &cmd, &comp, pdsc->devcmd_timeout); + if (err) + return err; + + ctx->val.vu8 = comp.fw_control.slot; + + return 0; +} + +static int pdsc_dl_fw_bank_set(struct devlink *dl, u32 id, + struct devlink_param_gset_ctx *ctx) +{ + struct pdsc *pdsc = devlink_priv(dl); + union pds_core_dev_cmd cmd = { + .fw_control.opcode = PDS_CORE_CMD_FW_CONTROL, + .fw_control.oper = PDS_CORE_FW_SET_BOOT, + }; + union pds_core_dev_comp comp; + int timeout; + + cmd.fw_control.slot = ctx->val.vu8; + + /* This is known to be a longer running command, so be sure + * to use a larger timeout on the command than usual + */ +#define PDSC_SET_BOOT_TIMEOUT 10 + timeout = max_t(int, PDSC_SET_BOOT_TIMEOUT, pdsc->devcmd_timeout); + return pdsc_devcmd(pdsc, &cmd, &comp, timeout); +} + +static int pdsc_dl_fw_bank_validate(struct devlink *dl, u32 id, + union devlink_param_value val, + struct netlink_ext_ack *extack) +{ + switch (val.vu8) { + case PDS_CORE_FW_SLOT_A: + case PDS_CORE_FW_SLOT_B: + case PDS_CORE_FW_SLOT_GOLD: + return 0; + default: + return -EINVAL; + } +} + +static const struct devlink_param pdsc_dl_params[] = { + DEVLINK_PARAM_GENERIC(FW_BANK, + BIT(DEVLINK_PARAM_CMODE_PERMANENT), + pdsc_dl_fw_bank_get, + pdsc_dl_fw_bank_set, + pdsc_dl_fw_bank_validate), +}; + static int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req, struct netlink_ext_ack *extack) { @@ -87,6 +150,12 @@ void pdsc_dl_free(struct pdsc *pdsc) int pdsc_dl_register(struct pdsc *pdsc) { struct devlink *dl = priv_to_devlink(pdsc); + int err; + + err = devlink_params_register(dl, pdsc_dl_params, + ARRAY_SIZE(pdsc_dl_params)); + if (err) + return err; devlink_register(dl); @@ -98,4 +167,6 @@ void pdsc_dl_unregister(struct pdsc *pdsc) struct devlink *dl = priv_to_devlink(pdsc); devlink_unregister(dl); + devlink_params_unregister(dl, pdsc_dl_params, + ARRAY_SIZE(pdsc_dl_params)); } From patchwork Wed Dec 7 00:44:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066442 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A84AAC3A5A7 for ; Wed, 7 Dec 2022 00:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229867AbiLGApf (ORCPT ); Tue, 6 Dec 2022 19:45:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbiLGApY (ORCPT ); Tue, 6 Dec 2022 19:45:24 -0500 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2063.outbound.protection.outlook.com [40.107.212.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 237EE31ED1 for ; Tue, 6 Dec 2022 16:45:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EhSSr5I+nGyZSQsoEe+Ef8AdmE9SbycTk8ad8U9et1y1tp1Fxx3z62UA5Z+dSD+msSkMKZAzyxNiS8nFc1xbTGStsHIRmm59etV4WXnOYWuJYoVZwJiYgwpTRtA6kJmaUgLng3ZrLBNoMcsS4x91QFn8p9Qt81L4/Al7UKM9NxWk76viIk2eDG2AwGZhPcHKdEVOQaMA8CnlS3Adr8Q+3q7yL18X0bo2WV+qI8Wc18ECq2daRoon8p6ctMK+c7KCzJD63OPhxN4eB1WawI/plHPGOYy24fSVlEmHNSIHTG117wVmnet87b5trDkffwPkFdnR+4MaysKcQfV56SqNkg== 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=eO4gra8+cc5vxp7LPiAitn0q1HhCMNhd+uKZAB+v3Gs=; b=fJKORpzHrc5EB+XzwmLUeRkY0cm8PiC8v5gPcMPEbyzl9zCatw3vSiIpEjtdLlAIYG64fz1UY9IINCBkftnu89hAdDNUVhmCncWVFzeHqXLL1VY7dW9TNKRT6J7OGrPguH33mhhdJwWxEJbduu0vIPUmmzV+c1fBQxVEpWBcJ3mnplzboPVoRHG8vEfmNwxOYTICd8lDM/RbNWaUkpU8ll3iy1fR0Kb4qNl0VLS+o/UCFq5sfFoo9fksjmUH48VqBAIDcOOqtby0vbMggFM6yix6r4d9UrlLihEFsEVBZ3RZ+MbiQc8qRx2/8k2FXsXzqBuvW96yGdAATRQqZSFOfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eO4gra8+cc5vxp7LPiAitn0q1HhCMNhd+uKZAB+v3Gs=; b=RPVos3nzndN1MyWhT/j+336wRZDkhzFCU7PV1L1R8bs+YE5o0x52qt1mTiziBWvTbILCMezg4q0pnlR1sH7VaM8FyJ/i/0SwB374bSC5Hk4il0JzsVlitEG9FPFqK0BDO1CHyXyW0tBfNcRF9YyeKz3GlNurDWh5CSLhiV9IlCM= Received: from BN8PR16CA0029.namprd16.prod.outlook.com (2603:10b6:408:4c::42) by CH0PR12MB5025.namprd12.prod.outlook.com (2603:10b6:610:d5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:11 +0000 Received: from BN8NAM11FT095.eop-nam11.prod.protection.outlook.com (2603:10b6:408:4c:cafe::b9) by BN8PR16CA0029.outlook.office365.com (2603:10b6:408:4c::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 00:45:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT095.mail.protection.outlook.com (10.13.176.206) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:11 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:10 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 09/16] pds_core: add FW update feature to devlink Date: Tue, 6 Dec 2022 16:44:36 -0800 Message-ID: <20221207004443.33779-10-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT095:EE_|CH0PR12MB5025:EE_ X-MS-Office365-Filtering-Correlation-Id: 585c1676-da8d-434d-b762-08dad7ec4c0a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cBk1MeeJBWX3NBUBDEDz+E/RghHHTc8afuitGSyZImXlaUP4nQ6v/eLHHvxWBeW8YRUScy2L24lNuhSJsKC/iN0UL3V0JoQvi3CAYSBr2V5SzO8u1qW2QoKZlwQBjFjy7YOisFjA92XUyfuEODHHiVpYFfy2Ls0IiMalCscs9bfh+rySgIybex6u/78o1D+O+QEETbJ1WDobxaS+cHtNvpsUbcn2hVK74aIOzcYC1Bvye1uSUDAJ/VRttzI4ONbpnr5nvNbNciMJ7liVwCA/CK4lQWT38JznGj4HnhscdB2Lxap9Focu4AhcjvR+mfMHWhemE7JMOQZL0laWq3gWWZmHLAWXVDeYPOkR6+RAE95lsLMZvbNZKcNzfe8QUlcGc8yJZpLvYAv4lgWF7uKHKlbIAKoCo83d8mEzavBZxNA5+fGFO2KLgM9HtBJgmfFIOVeWgXLGQdVB/6CHVkl4853igna6CEjg+56u+A+8P0Zd+6vXXtScW41J7/cv1eOfKPOQMEoKN7fO0cLhOw/fKBs/eQL95FdTfb+Yxxsl3JH90XR1igfyykyk53Aaz0ys5n+yMbJ8g603RV7R7j8t2fesmmbtIOUK1F2jJStIwpa2hP7kR4vx1SaxzA30emiC8I/dfr/3hFCH36+Afk/RlJtEB27pUBRmYMmgs+vxrXXTxpyS3rkZD2vWhk1VuHIxoZMSa8yX8HHzCHG0okL8YOLhbxU41TUMzWdIo0vkdbI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(136003)(346002)(376002)(396003)(451199015)(36840700001)(40470700004)(46966006)(2616005)(186003)(26005)(16526019)(1076003)(336012)(316002)(36860700001)(83380400001)(110136005)(6666004)(81166007)(15650500001)(4326008)(8676002)(40460700003)(41300700001)(356005)(2906002)(478600001)(82740400003)(44832011)(70206006)(47076005)(70586007)(426003)(36756003)(82310400005)(54906003)(8936002)(5660300002)(86362001)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:11.3902 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 585c1676-da8d-434d-b762-08dad7ec4c0a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT095.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5025 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add in the support for doing firmware updates. Of the two main banks available, 1, and 2, this updates the one not in use and then selects it for the next boot. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/pds_core/Makefile | 3 +- drivers/net/ethernet/pensando/pds_core/core.h | 3 + .../net/ethernet/pensando/pds_core/devlink.c | 10 + drivers/net/ethernet/pensando/pds_core/fw.c | 192 ++++++++++++++++++ 4 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/pensando/pds_core/fw.c diff --git a/drivers/net/ethernet/pensando/pds_core/Makefile b/drivers/net/ethernet/pensando/pds_core/Makefile index c7a722f7d9b8..06bd3da8c38b 100644 --- a/drivers/net/ethernet/pensando/pds_core/Makefile +++ b/drivers/net/ethernet/pensando/pds_core/Makefile @@ -7,6 +7,7 @@ pds_core-y := main.o \ devlink.o \ dev.o \ adminq.o \ - core.o + core.o \ + fw.o pds_core-$(CONFIG_DEBUG_FS) += debugfs.o diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h index bdb3a29d789e..8549dd4303e5 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.h +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -284,4 +284,7 @@ void pdsc_process_adminq(struct pdsc_qcq *qcq); void pdsc_work_thread(struct work_struct *work); irqreturn_t pdsc_adminq_isr(int irq, void *data); +int pdsc_firmware_update(struct pdsc *pdsc, const struct firmware *fw, + struct netlink_ext_ack *extack); + #endif /* _PDSC_H_ */ diff --git a/drivers/net/ethernet/pensando/pds_core/devlink.c b/drivers/net/ethernet/pensando/pds_core/devlink.c index cd132573cbe0..0ba4bbbe5f7f 100644 --- a/drivers/net/ethernet/pensando/pds_core/devlink.c +++ b/drivers/net/ethernet/pensando/pds_core/devlink.c @@ -71,6 +71,15 @@ static const struct devlink_param pdsc_dl_params[] = { pdsc_dl_fw_bank_validate), }; +static int pdsc_dl_flash_update(struct devlink *dl, + struct devlink_flash_update_params *params, + struct netlink_ext_ack *extack) +{ + struct pdsc *pdsc = devlink_priv(dl); + + return pdsc_firmware_update(pdsc, params->fw, extack); +} + static int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req, struct netlink_ext_ack *extack) { @@ -127,6 +136,7 @@ static int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req, static const struct devlink_ops pdsc_dl_ops = { .info_get = pdsc_dl_info_get, + .flash_update = pdsc_dl_flash_update, }; struct pdsc *pdsc_dl_alloc(struct device *dev) diff --git a/drivers/net/ethernet/pensando/pds_core/fw.c b/drivers/net/ethernet/pensando/pds_core/fw.c new file mode 100644 index 000000000000..3c64deef5549 --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/fw.c @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2022 Pensando Systems, Inc */ + +#include +#include +#include +#include + +#include "core.h" + +/* The worst case wait for the install activity is about 25 minutes when + * installing a new CPLD, which is very seldom. Normal is about 30-35 + * seconds. Since the driver can't tell if a CPLD update will happen we + * set the timeout for the ugly case. + */ +#define PDSC_FW_INSTALL_TIMEOUT (25 * 60) +#define PDSC_FW_SELECT_TIMEOUT 30 + +/* Number of periodic log updates during fw file download */ +#define PDSC_FW_INTERVAL_FRACTION 32 + +static int pdsc_devcmd_firmware_download(struct pdsc *pdsc, u64 addr, + u32 offset, u32 length) +{ + union pds_core_dev_cmd cmd = { + .fw_download.opcode = PDS_CORE_CMD_FW_DOWNLOAD, + .fw_download.offset = cpu_to_le32(offset), + .fw_download.addr = cpu_to_le64(addr), + .fw_download.length = cpu_to_le32(length), + }; + union pds_core_dev_comp comp; + + return pdsc_devcmd_locked(pdsc, &cmd, &comp, pdsc->devcmd_timeout); +} + +static int pdsc_devcmd_firmware_install(struct pdsc *pdsc) +{ + union pds_core_dev_cmd cmd = { + .fw_control.opcode = PDS_CORE_CMD_FW_CONTROL, + .fw_control.oper = PDS_CORE_FW_INSTALL_ASYNC + }; + union pds_core_dev_comp comp; + int err; + + err = pdsc_devcmd(pdsc, &cmd, &comp, pdsc->devcmd_timeout); + if (err < 0) + return err; + + return comp.fw_control.slot; +} + +static int pdsc_devcmd_firmware_activate(struct pdsc *pdsc, + enum pds_core_fw_slot slot) +{ + union pds_core_dev_cmd cmd = { + .fw_control.opcode = PDS_CORE_CMD_FW_CONTROL, + .fw_control.oper = PDS_CORE_FW_ACTIVATE_ASYNC, + .fw_control.slot = slot + }; + union pds_core_dev_comp comp; + + return pdsc_devcmd(pdsc, &cmd, &comp, pdsc->devcmd_timeout); +} + +static int pdsc_fw_status_long_wait(struct pdsc *pdsc, + const char *label, + unsigned long timeout, + u8 fw_cmd, + struct netlink_ext_ack *extack) +{ + union pds_core_dev_cmd cmd = { + .fw_control.opcode = PDS_CORE_CMD_FW_CONTROL, + .fw_control.oper = fw_cmd, + }; + union pds_core_dev_comp comp; + unsigned long start_time; + unsigned long end_time; + int err; + + /* Ping on the status of the long running async install + * command. We get EAGAIN while the command is still + * running, else we get the final command status. + */ + start_time = jiffies; + end_time = start_time + (timeout * HZ); + do { + err = pdsc_devcmd(pdsc, &cmd, &comp, pdsc->devcmd_timeout); + msleep(20); + } while (time_before(jiffies, end_time) && + (err == -EAGAIN || err == -ETIMEDOUT)); + + if (err == -EAGAIN || err == -ETIMEDOUT) { + NL_SET_ERR_MSG_MOD(extack, "Firmware wait timed out"); + dev_err(pdsc->dev, "DEV_CMD firmware wait %s timed out\n", label); + } else if (err) { + NL_SET_ERR_MSG_MOD(extack, "Firmware wait failed"); + } + + return err; +} + +int pdsc_firmware_update(struct pdsc *pdsc, const struct firmware *fw, + struct netlink_ext_ack *extack) +{ + u32 buf_sz, copy_sz, offset; + struct devlink *dl; + int next_interval; + u64 data_addr; + int err = 0; + u8 fw_slot; + + dev_info(pdsc->dev, "Installing firmware\n"); + + dl = priv_to_devlink(pdsc); + devlink_flash_update_status_notify(dl, "Preparing to flash", NULL, 0, 0); + + buf_sz = sizeof(pdsc->cmd_regs->data); + + dev_dbg(pdsc->dev, + "downloading firmware - size %d part_sz %d nparts %lu\n", + (int)fw->size, buf_sz, DIV_ROUND_UP(fw->size, buf_sz)); + + offset = 0; + next_interval = 0; + data_addr = offsetof(struct pds_core_dev_cmd_regs, data); + while (offset < fw->size) { + if (offset >= next_interval) { + devlink_flash_update_status_notify(dl, "Downloading", NULL, + offset, fw->size); + next_interval = offset + (fw->size / PDSC_FW_INTERVAL_FRACTION); + } + + copy_sz = min_t(unsigned int, buf_sz, fw->size - offset); + mutex_lock(&pdsc->devcmd_lock); + memcpy_toio(&pdsc->cmd_regs->data, fw->data + offset, copy_sz); + err = pdsc_devcmd_firmware_download(pdsc, data_addr, offset, copy_sz); + mutex_unlock(&pdsc->devcmd_lock); + if (err) { + dev_err(pdsc->dev, + "download failed offset 0x%x addr 0x%llx len 0x%x: %pe\n", + offset, data_addr, copy_sz, ERR_PTR(err)); + NL_SET_ERR_MSG_MOD(extack, "Segment download failed"); + goto err_out; + } + offset += copy_sz; + } + devlink_flash_update_status_notify(dl, "Downloading", NULL, + fw->size, fw->size); + + devlink_flash_update_timeout_notify(dl, "Installing", NULL, + PDSC_FW_INSTALL_TIMEOUT); + + fw_slot = pdsc_devcmd_firmware_install(pdsc); + if (fw_slot < 0) { + err = fw_slot; + dev_err(pdsc->dev, "install failed: %pe\n", ERR_PTR(err)); + NL_SET_ERR_MSG_MOD(extack, "Failed to start firmware install"); + goto err_out; + } + + err = pdsc_fw_status_long_wait(pdsc, "Installing", + PDSC_FW_INSTALL_TIMEOUT, + PDS_CORE_FW_INSTALL_STATUS, + extack); + if (err) + goto err_out; + + devlink_flash_update_timeout_notify(dl, "Selecting", NULL, + PDSC_FW_SELECT_TIMEOUT); + + err = pdsc_devcmd_firmware_activate(pdsc, fw_slot); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Failed to start firmware select"); + goto err_out; + } + + err = pdsc_fw_status_long_wait(pdsc, "Selecting", + PDSC_FW_SELECT_TIMEOUT, + PDS_CORE_FW_ACTIVATE_STATUS, + extack); + if (err) + goto err_out; + + dev_info(pdsc->dev, "Firmware update completed, slot %d\n", fw_slot); + +err_out: + if (err) + devlink_flash_update_status_notify(dl, "Flash failed", NULL, 0, 0); + else + devlink_flash_update_status_notify(dl, "Flash done", NULL, 0, 0); + return err; +} From patchwork Wed Dec 7 00:44:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066440 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 871BDC3A5A7 for ; Wed, 7 Dec 2022 00:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229821AbiLGApb (ORCPT ); Tue, 6 Dec 2022 19:45:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbiLGApY (ORCPT ); Tue, 6 Dec 2022 19:45:24 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2077.outbound.protection.outlook.com [40.107.93.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED58A326D6 for ; Tue, 6 Dec 2022 16:45:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d/I+sf2hM54h5TNP5P1oTtA1yxGcNxvFt6FP0w8sjOyiBvdQ2Qs79pv1leNanADQH448uqpB4/s64JQQ2semhB5bdGu44R7Bmy+JMRhBL4QZM3/MOL6Wp3oifwMZguxTBcy7JUkQDGMKS7rId3fB4kmBAY+YcKoZFC9awk75GSnPE5tkPS9O/GmqVzWsHoIl0v/7zCrK0wc4JNyaJkPcHz0C2pYmkLuU/es6VUXtaIaHzpFdpK/wDHu1ecKlBUFHymPTOmQE/Y2TAghx/frNxV8O28JX0i1TKTiuahBdsQuFcGX0DiXRQTLTpP48KKW3ep9NBNTiAFKbQpz3Nfc/Lg== 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=OUgtY629be5+PVLzJY7azWMQwa79YT4+ODgHApdksR8=; b=LhJPqJyJ3Lh2EUdERJuUz3nO2IqZYiZz0iqbYaTsEMxThWoVM/fug+lfDrSBSuXQpk3UkWxF6XmJznm53ENVDmRjITn0ouqG9DauVTuwutxnklMHaJhuyaPY/hTIlQtJL/vHyKUpEWscVuh3Z4n5UmmY8o33tlreEU3xtof8MnCn9Ehk8cMN0ugCXnvw/Tq79+I/3sVrDEknXjkK+A5peCvZev5WcfeAQdspzqhWhAwUQWW2f+uBvAyBVynQ6mCLvOqhvKmcKLGmy+sgmE54duFcdedV1IDeGrRFIlXpM6dELe7BmxB7U4B0wYLsFXgGI36zFv6NhamQlXaUHhPoOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OUgtY629be5+PVLzJY7azWMQwa79YT4+ODgHApdksR8=; b=PkJ5Z4eIw6JXNn5+ZuALboB0jGar32k6EaJiMSZB174DoZB3A5bFiOhguMkwJ/oUinfKW1pQqPtYJfmgpSvZP+8AsblRfkyeTjMi21kHjtbG2gu6W308cqnMnWGQwO7pZoDY8PCO6FY9h/AyQ4zybsf9nI6Km36JZLOHXb2HwTk= Received: from BN8PR16CA0009.namprd16.prod.outlook.com (2603:10b6:408:4c::22) by DS0PR12MB6608.namprd12.prod.outlook.com (2603:10b6:8:d0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:12 +0000 Received: from BN8NAM11FT095.eop-nam11.prod.protection.outlook.com (2603:10b6:408:4c:cafe::ad) by BN8PR16CA0009.outlook.office365.com (2603:10b6:408:4c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 00:45:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT095.mail.protection.outlook.com (10.13.176.206) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:11 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:11 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 10/16] pds_core: set up the VIF definitions and defaults Date: Tue, 6 Dec 2022 16:44:37 -0800 Message-ID: <20221207004443.33779-11-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT095:EE_|DS0PR12MB6608:EE_ X-MS-Office365-Filtering-Correlation-Id: 0ea0d6a5-9daa-42ea-012c-08dad7ec4c57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sn/rrDWOT5GkIQyqdb8CoCUQTtWex/+haIB6dXKFlxnh3lPg7SVbQnFqQDUW4ey9FiOCt06j+ahZMsRg9HWJGT/hBN7zOiAlERhYJTscb+vmOYVVHDw7ouhnQ/jkiaoBnxpdzLOhB8ELrjqhysq1KF9u11FwtUrxYmHJSD1HbHhEISKUFek6kQOWa95uxdlIsVUM3lwawCmwjyFlXX0n2JJCqsKjUEVh+iMeRHDAt5ldHi2QtVoAw7+ATO7y+A81zhGifdi2y7Tl2srrtatCpwe9FveXsjratUH9Pd6lLsHViWDtXUIGkxCsH5A/ROJtN7YUM26HyYaWJQUeM5xFo4GadO5hVTgFAohBpLg1kUzaEnMZKoB1KEPVk6MHqZjfNJsDU3JtywMMxq0F5mFekyVITxUpBVcsLTulK5hrnwXNfar7kQhjgcNu7h0yk5Ybhd76pyCQDrrQwG2zBaUZgiBNYe2UtMPe7W0rzEIXEv1eNJb4AChjNhtnePqBSqO9+CN5T2HQMwT2N1vuy3KzDzkFO7VgWsHcvFsIurGSppcNhYNtlMXNljDxN8xx5cXrkh266ItcrrI9pioLGkWCCyh5y2+2Fs4g6GZJTfmzZ+4iGdJdcr2niq5poWJzv4NkT5XYe/HisHE0uftCqdYF9adQvtA0XWxgevLp/MePON7NKLRapWKUUbowZANcxHnEaUJcwo6JTvG0mbtZJ9Iof9qSMWW0BL8uCZnjOyVTCxpuwbM5N/QoRhkfhXafCfyWMCUv7B6ZK7dCLONIvyt5tQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(376002)(346002)(136003)(396003)(451199015)(46966006)(40470700004)(36840700001)(2906002)(83380400001)(426003)(110136005)(54906003)(26005)(41300700001)(186003)(86362001)(16526019)(316002)(1076003)(2616005)(40460700003)(82310400005)(36756003)(44832011)(8936002)(5660300002)(47076005)(36860700001)(336012)(70206006)(70586007)(82740400003)(4326008)(40480700001)(356005)(478600001)(8676002)(81166007)(6666004)(36900700001)(309714004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:11.8901 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0ea0d6a5-9daa-42ea-012c-08dad7ec4c57 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT095.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6608 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The Virtual Interfaces (VIFs) supported by the DSC's configuration (VFio Live Migration, vDPA, etc) are reported in the dev_ident struct. Signed-off-by: Shannon Nelson --- drivers/net/ethernet/pensando/pds_core/core.c | 54 +++++++++++++++++++ drivers/net/ethernet/pensando/pds_core/core.h | 13 +++++ .../net/ethernet/pensando/pds_core/debugfs.c | 23 ++++++++ include/linux/pds/pds_common.h | 19 +++++++ 4 files changed, 109 insertions(+) diff --git a/drivers/net/ethernet/pensando/pds_core/core.c b/drivers/net/ethernet/pensando/pds_core/core.c index e2017cee8284..e6810f43df26 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.c +++ b/drivers/net/ethernet/pensando/pds_core/core.c @@ -358,6 +358,47 @@ static int pdsc_core_init(struct pdsc *pdsc) return err; } +static struct pdsc_viftype pdsc_viftype_defaults[] = { + [PDS_DEV_TYPE_VDPA] = { .name = PDS_DEV_TYPE_VDPA_STR, + .vif_id = PDS_DEV_TYPE_VDPA, + .dl_id = DEVLINK_PARAM_GENERIC_ID_ENABLE_VNET }, + [PDS_DEV_TYPE_LM] = { .name = PDS_DEV_TYPE_LM_STR, + .vif_id = PDS_DEV_TYPE_LM, + .dl_id = DEVLINK_PARAM_GENERIC_ID_ENABLE_MIGRATION}, + [PDS_DEV_TYPE_MAX] = { 0 } +}; + +static int pdsc_viftypes_init(struct pdsc *pdsc) +{ + enum pds_core_vif_types vt; + + pdsc->viftype_status = devm_kzalloc(pdsc->dev, + sizeof(pdsc_viftype_defaults), + GFP_KERNEL); + if (!pdsc->viftype_status) + return -ENOMEM; + + for (vt = 0; vt < PDS_DEV_TYPE_MAX; vt++) { + bool vt_support; + + if (!pdsc_viftype_defaults[vt].name) + continue; + + /* Grab the defaults */ + pdsc->viftype_status[vt] = pdsc_viftype_defaults[vt]; + + /* See what the Core device has for support */ + vt_support = !!le16_to_cpu(pdsc->dev_ident.vif_types[vt]); + dev_dbg(pdsc->dev, "VIF %s is %ssupported\n", + pdsc->viftype_status[vt].name, + vt_support ? "" : "not "); + + pdsc->viftype_status[vt].supported = vt_support; + } + + return 0; +} + int pdsc_setup(struct pdsc *pdsc, bool init) { int numdescs; @@ -400,6 +441,14 @@ int pdsc_setup(struct pdsc *pdsc, bool init) if (err) goto err_out_teardown; + /* Set up the VIFs */ + err = pdsc_viftypes_init(pdsc); + if (err) + goto err_out_teardown; + + if (init) + pdsc_debugfs_add_viftype(pdsc); + clear_bit(PDSC_S_FW_DEAD, &pdsc->state); return 0; @@ -416,6 +465,11 @@ void pdsc_teardown(struct pdsc *pdsc, bool removing) pdsc_qcq_free(pdsc, &pdsc->notifyqcq); pdsc_qcq_free(pdsc, &pdsc->adminqcq); + if (pdsc->viftype_status) { + devm_kfree(pdsc->dev, pdsc->viftype_status); + pdsc->viftype_status = NULL; + } + if (pdsc->intr_info) { for (i = 0; i < pdsc->nintrs; i++) pdsc_intr_free(pdsc, i); diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h index 8549dd4303e5..bdcfd5f0da60 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.h +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -123,6 +123,15 @@ struct pdsc_qcq { struct dentry *dentry; }; +struct pdsc_viftype { + char *name; + bool supported; + bool enabled; + int dl_id; + int vif_id; + struct pds_auxiliary_dev *padev; +}; + /* No state flags set means we are in a steady running state */ enum pdsc_state_flags { PDSC_S_FW_DEAD, /* fw stopped, waiting for startup or recovery */ @@ -173,6 +182,7 @@ struct pdsc { struct pdsc_qcq adminqcq; struct pdsc_qcq notifyqcq; u64 last_eid; + struct pdsc_viftype *viftype_status; }; /** enum pds_core_dbell_bits - bitwise composition of dbell values. @@ -227,6 +237,7 @@ struct pdsc *pdsc_dl_alloc(struct device *dev); void pdsc_dl_free(struct pdsc *pdsc); int pdsc_dl_register(struct pdsc *pdsc); void pdsc_dl_unregister(struct pdsc *pdsc); +int pdsc_dl_vif_add(struct pdsc *pdsc, enum pds_core_vif_types vt, const char *name); #ifdef CONFIG_DEBUG_FS void pdsc_debugfs_create(void); @@ -234,6 +245,7 @@ void pdsc_debugfs_destroy(void); void pdsc_debugfs_add_dev(struct pdsc *pdsc); void pdsc_debugfs_del_dev(struct pdsc *pdsc); void pdsc_debugfs_add_ident(struct pdsc *pdsc); +void pdsc_debugfs_add_viftype(struct pdsc *pdsc); void pdsc_debugfs_add_irqs(struct pdsc *pdsc); void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq); void pdsc_debugfs_del_qcq(struct pdsc_qcq *qcq); @@ -243,6 +255,7 @@ static inline void pdsc_debugfs_destroy(void) { } static inline void pdsc_debugfs_add_dev(struct pdsc *pdsc) { } static inline void pdsc_debugfs_del_dev(struct pdsc *pdsc) { } static inline void pdsc_debugfs_add_ident(struct pdsc *pdsc) { } +static inline void pdsc_debugfs_add_viftype(struct pdsc *pdsc) { } static inline void pdsc_debugfs_add_irqs(struct pdsc *pdsc) { } static inline void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq) { } static inline void pdsc_debugfs_del_qcq(struct pdsc_qcq *qcq) { } diff --git a/drivers/net/ethernet/pensando/pds_core/debugfs.c b/drivers/net/ethernet/pensando/pds_core/debugfs.c index 294bb97ca639..5b8d53912691 100644 --- a/drivers/net/ethernet/pensando/pds_core/debugfs.c +++ b/drivers/net/ethernet/pensando/pds_core/debugfs.c @@ -82,6 +82,29 @@ void pdsc_debugfs_add_ident(struct pdsc *pdsc) debugfs_create_file("identity", 0400, pdsc->dentry, pdsc, &identity_fops); } +static int viftype_show(struct seq_file *seq, void *v) +{ + struct pdsc *pdsc = seq->private; + int vt; + + for (vt = 0; vt < PDS_DEV_TYPE_MAX; vt++) { + if (!pdsc->viftype_status[vt].name) + continue; + + seq_printf(seq, "%s\t%d supported %d enabled\n", + pdsc->viftype_status[vt].name, + pdsc->viftype_status[vt].supported, + pdsc->viftype_status[vt].enabled); + } + return 0; +} +DEFINE_SHOW_ATTRIBUTE(viftype); + +void pdsc_debugfs_add_viftype(struct pdsc *pdsc) +{ + debugfs_create_file("viftypes", 0400, pdsc->dentry, pdsc, &viftype_fops); +} + static int irqs_show(struct seq_file *seq, void *v) { struct pdsc *pdsc = seq->private; diff --git a/include/linux/pds/pds_common.h b/include/linux/pds/pds_common.h index e7fe84379a2f..2fa4ec440ef5 100644 --- a/include/linux/pds/pds_common.h +++ b/include/linux/pds/pds_common.h @@ -50,6 +50,25 @@ enum pds_core_driver_type { PDS_DRIVER_ESXI = 6, }; +enum pds_core_vif_types { + PDS_DEV_TYPE_CORE = 0, + PDS_DEV_TYPE_VDPA = 1, + PDS_DEV_TYPE_VFIO = 2, + PDS_DEV_TYPE_ETH = 3, + PDS_DEV_TYPE_RDMA = 4, + PDS_DEV_TYPE_LM = 5, + + /* new ones added before this line */ + PDS_DEV_TYPE_MAX = 16 /* don't change - used in struct size */ +}; + +#define PDS_DEV_TYPE_CORE_STR "Core" +#define PDS_DEV_TYPE_VDPA_STR "vDPA" +#define PDS_DEV_TYPE_VFIO_STR "VFio" +#define PDS_DEV_TYPE_ETH_STR "Eth" +#define PDS_DEV_TYPE_RDMA_STR "RDMA" +#define PDS_DEV_TYPE_LM_STR "LM" + /* PDSC interface uses identity version 1 and PDSC uses 2 */ #define PDSC_IDENTITY_VERSION_1 1 #define PDSC_IDENTITY_VERSION_2 2 From patchwork Wed Dec 7 00:44:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066443 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B61B7C352A1 for ; Wed, 7 Dec 2022 00:45:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbiLGApg (ORCPT ); Tue, 6 Dec 2022 19:45:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229807AbiLGApZ (ORCPT ); Tue, 6 Dec 2022 19:45:25 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8193B326F2 for ; Tue, 6 Dec 2022 16:45:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H/YCclBZ4iDzeRYS4Eb6Xm4pPt30gqAex3l28lrR0bx9yuobMKT825VE7fAHvwANOag5TqfD/fw2DbZsEcsUyU17qMLLODKvDaOss3avsl1sLpkEpJ+jLtyAVYAjWmiiFa61HAURviDpwzoyW4au9boHYF4d6g+qlTsPD2I0ZmtOeVNwpVJAvBTJGJVlUn8p2HZpQXd19FQknuDihUMKmdvEhm5KpfaHeBzpGvLMn+1hqZzloCEawub4UTgywq1zWT8oZmCm7kQpQxy7Xih0DnDbMJe8KyBH+3m3bhWxeVUnScKx10CcHqVL4EfSigHGzggBWh52VTIK/6/Fi+Z1Gg== 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=vUcPBe1tIy/npRLAgIcH87sIjalZf58mWjLHliYRVmc=; b=W9En56u2m/N0ZSTWDNgAkos81VuwoPELWHVKHTz3UiDgQd9T9dRGlP1e3FAPqV0gq6+e3d5axDvXZS2blOG2znoXfje7YI0OcUQQLWEZxYJnqgwHWFUh4Goo41eI1MmgzRMofY5DCCeOLX0a5KV6LqPA3Ke+okvRccRAWXIqc/GRhzewDcfU0U65E4ar9PmkY1/UEyBxgAMpVvagQaat2IhTrKqskwmivQa6XFdoI1biFlt8NXt3KvYMhg8DQICLbM+l7LbpZgUOgxxUPC8Q8u2XNikgbB7+W3Ss+RHJ2HevWG5aZElG7+6tOC5gUJ9ifmw/76EoKjNS1gqhVr9bCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vUcPBe1tIy/npRLAgIcH87sIjalZf58mWjLHliYRVmc=; b=qEbRMUU6qO7MsqUAO7bdcfZmNDelm97n1u62TL0dL4fn57ooZJRWKD0Xq1PQad+0kOCefksLhVtu3xwKgV2xD3pNQO9QtS9huuasNbr0+J3wngABpNzKkyBXyL4e+/ajOCzJxLnX9ORhMbpcbwnSIZkBnfHJKPX0aqk9qf/2TjQ= Received: from BN9PR03CA0256.namprd03.prod.outlook.com (2603:10b6:408:ff::21) by DM4PR12MB5392.namprd12.prod.outlook.com (2603:10b6:5:39f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:12 +0000 Received: from BN8NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::5a) by BN9PR03CA0256.outlook.office365.com (2603:10b6:408:ff::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT003.mail.protection.outlook.com (10.13.177.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:12 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:11 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 11/16] pds_core: initial VF configuration Date: Tue, 6 Dec 2022 16:44:38 -0800 Message-ID: <20221207004443.33779-12-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT003:EE_|DM4PR12MB5392:EE_ X-MS-Office365-Filtering-Correlation-Id: c1ad0ee6-a727-4215-bd85-08dad7ec4cd2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nycDxTZ9d7BisdQm5fG2nE0b9OYWMSULyOwIk/x2Fb64W1f208GSpEI3id173nQiuDzz2g3BjXfmTSy7k4MEpA5oKzrpREKbiYP5Tl0+aIPWY1Xhbv2qq8zdsDDX3WWntBa+v0NB6TPct0P7Qi0oU16u4qd30V0wAjvnAKdxyNCHwoQLGHswEYh14q9zjYYhUxLyyuchW/OUErhSxrqsaw5Yk9Baelb+4Y8TYse06cDg/gL3Rbf1aHyUKsf/DkjXowt9iIDTK0PMsj4htCMiwwORddJV1PS3rK2+trQDdKdsD7S9DrmipDMWzQoIW4eQwtNHcPKB5924BanWvbXJSLo3n+5TF3PENEpPT9tBkSxPLSIZuMakJFMbKJ/NA2f7iQpCDJzbI+rTsx8NcFJPWdL1c34XkSmAC49IRVKjiRJ+Ynwp0Vy0NzDTjyS/zcRhLFNLz9hjlhCy7gl045sHUaXGkdi9F7RldbXcZEHmzAi/7HtSybMjccCKY/CFSyio95u9fPmY6p4R4m+5BbDrrF12YTjLEppgFXDalESeMlEiGten616so7bCVC0bfAKlxBO3yizruH6GJVjO/HHzzpcFwHfnQ1rjZ5dKWlyS9w9lsBud54S/jdsSqHyEzJUOhourODDLmQCYOOftU5VlL5x3IZIZ/yagPMFqu8rcMCZQnchA+27XYo7y8HoNfOS+6OK5qEpCzn+UQXnEA+647FuGXi4mAdwloO2Mo0ESi3Q= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(39860400002)(136003)(346002)(451199015)(36840700001)(40470700004)(46966006)(40480700001)(81166007)(36756003)(356005)(82740400003)(86362001)(40460700003)(316002)(110136005)(6666004)(54906003)(478600001)(44832011)(2906002)(5660300002)(8936002)(70586007)(41300700001)(36860700001)(4326008)(8676002)(70206006)(83380400001)(47076005)(2616005)(426003)(82310400005)(26005)(1076003)(336012)(16526019)(186003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:12.7010 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1ad0ee6-a727-4215-bd85-08dad7ec4cd2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5392 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Set up the VF control and management Signed-off-by: Shannon Nelson --- drivers/net/ethernet/pensando/pds_core/core.h | 10 +++++- drivers/net/ethernet/pensando/pds_core/main.c | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h index bdcfd5f0da60..83a7f7ebcc4b 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.h +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -30,6 +30,13 @@ struct pdsc_dev_bar { int res_index; }; +struct pdsc_vf { + u16 index; + __le16 vif_types[PDS_DEV_TYPE_MAX]; + + struct pds_auxiliary_dev *padev; +}; + struct pdsc_devinfo { u8 asic_type; u8 asic_rev; @@ -147,6 +154,7 @@ struct pdsc { struct dentry *dentry; struct device *dev; struct pdsc_dev_bar bars[PDS_CORE_BARS_MAX]; + struct pdsc_vf *vfs; int num_vfs; int hw_index; int id; @@ -166,6 +174,7 @@ struct pdsc { struct pdsc_intr_info *intr_info; /* array of nintrs elements */ struct workqueue_struct *wq; + struct rw_semaphore vf_op_lock; /* lock for VF operations */ unsigned int devcmd_timeout; struct mutex devcmd_lock; /* lock for dev_cmd operations */ @@ -299,5 +308,4 @@ irqreturn_t pdsc_adminq_isr(int irq, void *data); int pdsc_firmware_update(struct pdsc *pdsc, const struct firmware *fw, struct netlink_ext_ack *extack); - #endif /* _PDSC_H_ */ diff --git a/drivers/net/ethernet/pensando/pds_core/main.c b/drivers/net/ethernet/pensando/pds_core/main.c index 856704f8827a..1ff63a4339d8 100644 --- a/drivers/net/ethernet/pensando/pds_core/main.c +++ b/drivers/net/ethernet/pensando/pds_core/main.c @@ -165,6 +165,37 @@ void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num) (u64)page_num << PAGE_SHIFT, PAGE_SIZE); } +static int pdsc_sriov_configure(struct pci_dev *pdev, int num_vfs) +{ + struct pdsc *pdsc = pci_get_drvdata(pdev); + struct device *dev = pdsc->dev; + int ret = 0; + + if (num_vfs > 0) { + pdsc->vfs = kcalloc(num_vfs, sizeof(struct pdsc_vf), GFP_KERNEL); + if (!pdsc->vfs) + return -ENOMEM; + pdsc->num_vfs = num_vfs; + + ret = pci_enable_sriov(pdev, num_vfs); + if (ret) { + dev_err(dev, "Cannot enable SRIOV: %pe\n", ERR_PTR(ret)); + goto no_vfs; + } + + return num_vfs; + } + +no_vfs: + pci_disable_sriov(pdev); + + kfree(pdsc->vfs); + pdsc->vfs = NULL; + pdsc->num_vfs = 0; + + return ret; +} + static DEFINE_IDA(pdsc_pf_ida); #define PDSC_WQ_NAME_LEN 24 @@ -237,6 +268,7 @@ static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) spin_lock_init(&pdsc->adminq_lock); mutex_lock(&pdsc->config_lock); + init_rwsem(&pdsc->vf_op_lock); err = pdsc_setup(pdsc, PDSC_SETUP_INIT); if (err) goto err_out_unmap_bars; @@ -300,6 +332,8 @@ static void pdsc_remove(struct pci_dev *pdev) */ pdsc_dl_unregister(pdsc); + pdsc_sriov_configure(pdev, 0); + /* Now we can lock it up and tear it down */ mutex_lock(&pdsc->config_lock); set_bit(PDSC_S_STOPPING_DRIVER, &pdsc->state); @@ -337,6 +371,7 @@ static struct pci_driver pdsc_driver = { .id_table = pdsc_id_table, .probe = pdsc_probe, .remove = pdsc_remove, + .sriov_configure = pdsc_sriov_configure, }; static int __init pdsc_init_module(void) From patchwork Wed Dec 7 00:44:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066446 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A291C352A1 for ; Wed, 7 Dec 2022 00:45:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229799AbiLGApz (ORCPT ); Tue, 6 Dec 2022 19:45:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbiLGAp0 (ORCPT ); Tue, 6 Dec 2022 19:45:26 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2043.outbound.protection.outlook.com [40.107.93.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C00E4D5E9 for ; Tue, 6 Dec 2022 16:45:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YG2i5Fl/2BL2emhHRm+X27Lq+ZDDiheN6Oy4cU5LR1z8pZpwc8BKTGSvLQi/ethhZZc9ogGftbycMS9nI2iW9OxRYrzo0yvF7Q/4RzNrxrFF070NCenFnugZ60q1nfmC4t2ISqwrBPfw0FxWr5vKY+kAHde2f50uL9YUQffEJd7KPow74sRZZp6geisToz2ZKTaSqB9bLcGLbGk0WWv32gAl/FJg1S1qkrqgeXjW9F5SgMR/iJz66rNqOgGi7D+/4jlPrmbIU6TZW0Sp8oPn8e4/5rhmOgrA6rb3ib9LwhGqrUQ0iLPKgXCtQdsH0xymshTSpn+KZCkPaz0Bvu7U5g== 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=FJ0jN4lv/NuWpsMgTPdamEJkZW+f8y6P/ofrQL0aEwI=; b=Ucg9UPauscGADQrY5ARud8vP7KamijEdxWGGUjhvjChLGHAEAbMiD3uthCahoTsIu13H5sgdBN/1NkpiLSVXozIKYeCJb1Z+IMcVT80QeWFHq41affBXb3smANCyNWocYUPIlql1m7qDBKxazS6SL97IQsjR20PWiRles+YYrQ0/7TyflOcMDtdA06fwzIA0wdH71iW3w1iMRZY/fVvKy7xfrpgbBKnzPfuZemAtYqI5Hwu3UGmzvr9UmBfs7+lsmTiYk0YLMuK5jc+u1+UciSzTaAtnGuGSjlihPX57WMc6vd3lEwEKcbEDG+WDJmLrNU4Sp4ieRm31K6t0PfS+rw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FJ0jN4lv/NuWpsMgTPdamEJkZW+f8y6P/ofrQL0aEwI=; b=2C4dtTBDPn4uGQ/XtkgXtyaRIes4Hc6Larg3t2KF8il8JzBhhYd3o1DhTnrsVNHf/+I8W2tskaaEHttA6SwO6pk209TeaPkv2x4TK4ZPomY02aORuhnfK7zJU55s5IBmLzWYPnTk9BON8uLpdQ1g427DG7Cs372iVGLkzZfkFxg= Received: from BN9PR03CA0132.namprd03.prod.outlook.com (2603:10b6:408:fe::17) by DM6PR12MB4332.namprd12.prod.outlook.com (2603:10b6:5:21e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:15 +0000 Received: from BN8NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::84) by BN9PR03CA0132.outlook.office365.com (2603:10b6:408:fe::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT073.mail.protection.outlook.com (10.13.177.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:13 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:12 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 12/16] pds_core: add auxiliary_bus devices Date: Tue, 6 Dec 2022 16:44:39 -0800 Message-ID: <20221207004443.33779-13-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT073:EE_|DM6PR12MB4332:EE_ X-MS-Office365-Filtering-Correlation-Id: e216ae8d-2e0f-4f3c-d890-08dad7ec4d39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wbzugpMAsVu+wWfekI/ml45o1Aqd3GK4OAf/c7k6ViTqy5dVGzXjaZ7FWJtTW12RyRUonasy41MfFhco3o3piJCq9JUsvsr8wQnmiSYbKpVyIY6aaNIws7oXQ1OjT1uJGdhcKaBbEow9YQoHoWAhVG5hFXigjhN6NXS8NVpiiMpkXyHTBfCR1e19/ptpoxFiMEffD26aqePUhhDqwGlotNEKhx8YNZZhn//mLeCkagBZSHw6eZJ2OdWig4rrXZ0gQ7tPUPzp8v0kPaSBmEABUoKdumOHcX1PSt2wRszJz5sA/Uo2jurykZm+xaM7gRn7VBqZMGRnBx+nGrIgReZ8wNMZsOP5DQ6F/n9GKS5FHecO1l6NIca4GW/er75/I/sf7HKn0fmfeaYw533k1HJcccI3mvdkkJALwog76eNY/KIIuXVPDstaAi7oNLWO/QI+nOvb0G64JuOWmQ5+s3i4rKN4hx6n5UHCJ8sr96fM7Qus4o3XZW0NCs+ssuhuFKX2zg3I0G6lL6duxP2SA0VWVL6AA0ME6uiBk7CjggotIt7lVAz046cF2WAgoN9qBkphNEO3p3AmGUW6J/U6Vu9RtT1zdX65aN1sVLUj0ySpTd2DpKfKpws9tHL83Z82Re7ipVHEkQIYjr1u19lrYPUrevUytYsfjkHYV8f1GsaJeyXLukBnp4pkP9YobN7tyCNA6BCT5IlfvQ4xV5voH9ionJotX4+enqBfKV8gStHbCyL07OHektEs6OebzoD5npW+5CKDzWNTJ2oILdOyLyr1BA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(136003)(376002)(396003)(346002)(451199015)(40470700004)(36840700001)(46966006)(2616005)(1076003)(26005)(110136005)(186003)(336012)(16526019)(36860700001)(316002)(83380400001)(6666004)(4326008)(40460700003)(8676002)(82310400005)(41300700001)(356005)(44832011)(2906002)(478600001)(82740400003)(70206006)(70586007)(426003)(47076005)(81166007)(36756003)(54906003)(8936002)(5660300002)(40480700001)(86362001)(36900700001)(309714004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:13.3768 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e216ae8d-2e0f-4f3c-d890-08dad7ec4d39 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4332 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org An auxiliary_bus device is created for each VF, and the device name is made up of the PF driver name, VIF name, and PCI BDF of the VF. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/pds_core/Makefile | 1 + .../net/ethernet/pensando/pds_core/auxbus.c | 123 ++++++++++++++++++ drivers/net/ethernet/pensando/pds_core/core.h | 3 + drivers/net/ethernet/pensando/pds_core/main.c | 19 +++ include/linux/pds/pds_auxbus.h | 37 ++++++ 5 files changed, 183 insertions(+) create mode 100644 drivers/net/ethernet/pensando/pds_core/auxbus.c create mode 100644 include/linux/pds/pds_auxbus.h diff --git a/drivers/net/ethernet/pensando/pds_core/Makefile b/drivers/net/ethernet/pensando/pds_core/Makefile index 06bd3da8c38b..c8b9208d2c0d 100644 --- a/drivers/net/ethernet/pensando/pds_core/Makefile +++ b/drivers/net/ethernet/pensando/pds_core/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_PDS_CORE) := pds_core.o pds_core-y := main.o \ devlink.o \ + auxbus.o \ dev.o \ adminq.o \ core.o \ diff --git a/drivers/net/ethernet/pensando/pds_core/auxbus.c b/drivers/net/ethernet/pensando/pds_core/auxbus.c new file mode 100644 index 000000000000..331944a4d1a0 --- /dev/null +++ b/drivers/net/ethernet/pensando/pds_core/auxbus.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2022 Pensando Systems, Inc */ + +#include +#include +#include +#include + +#include "core.h" + +#include +#include + +static void pdsc_auxbus_dev_release(struct device *dev) +{ + struct pds_auxiliary_dev *padev = + container_of(dev, struct pds_auxiliary_dev, aux_dev.dev); + + devm_kfree(dev->parent, padev); +} + +static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *pdsc, + char *name, u32 id, + struct pci_dev *client_dev) +{ + struct auxiliary_device *aux_dev; + struct pds_auxiliary_dev *padev; + int err; + + padev = devm_kzalloc(pdsc->dev, sizeof(*padev), GFP_KERNEL); + if (!padev) + return NULL; + + padev->pcidev = client_dev; + + aux_dev = &padev->aux_dev; + aux_dev->name = name; + aux_dev->id = id; + padev->id = id; + aux_dev->dev.parent = pdsc->dev; + aux_dev->dev.release = pdsc_auxbus_dev_release; + + err = auxiliary_device_init(aux_dev); + if (err < 0) { + dev_warn(pdsc->dev, "auxiliary_device_init of %s id %d failed: %pe\n", + name, id, ERR_PTR(err)); + goto err_out; + } + + err = auxiliary_device_add(aux_dev); + if (err) { + auxiliary_device_uninit(aux_dev); + dev_warn(pdsc->dev, "auxiliary_device_add of %s id %d failed: %pe\n", + name, id, ERR_PTR(err)); + goto err_out; + } + + dev_dbg(pdsc->dev, "%s: name %s id %d pdsc %p\n", + __func__, padev->aux_dev.name, id, pdsc); + + return padev; + +err_out: + devm_kfree(pdsc->dev, padev); + return NULL; +} + +int pdsc_auxbus_dev_add_vf(struct pdsc *pdsc, int vf_id) +{ + struct pds_auxiliary_dev *padev; + enum pds_core_vif_types vt; + int err = 0; + + if (!pdsc->vfs) + return -ENOTTY; + + if (vf_id >= pdsc->num_vfs) + return -ERANGE; + + if (pdsc->vfs[vf_id].padev) { + dev_info(pdsc->dev, "%s: vfid %d already running\n", __func__, vf_id); + return -ENODEV; + } + + for (vt = 0; vt < PDS_DEV_TYPE_MAX; vt++) { + u16 vt_support; + u32 id; + + /* Verify that the type supported and enabled */ + vt_support = !!le16_to_cpu(pdsc->dev_ident.vif_types[vt]); + if (!(vt_support && + pdsc->viftype_status[vt].supported && + pdsc->viftype_status[vt].enabled)) + continue; + + id = PCI_DEVID(pdsc->pdev->bus->number, + pci_iov_virtfn_devfn(pdsc->pdev, vf_id)); + padev = pdsc_auxbus_dev_register(pdsc, pdsc->viftype_status[vt].name, id, + pdsc->pdev); + pdsc->vfs[vf_id].padev = padev; + + /* We only support a single type per VF, so jump out here */ + break; + } + + return err; +} + +int pdsc_auxbus_dev_del_vf(struct pdsc *pdsc, int vf_id) +{ + struct pds_auxiliary_dev *padev; + + dev_info(pdsc->dev, "%s: vfid %d\n", __func__, vf_id); + + padev = pdsc->vfs[vf_id].padev; + pdsc->vfs[vf_id].padev = NULL; + if (padev) { + auxiliary_device_delete(&padev->aux_dev); + auxiliary_device_uninit(&padev->aux_dev); + } + + return 0; +} diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h index 83a7f7ebcc4b..dbf1fe5135ad 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.h +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -302,6 +302,9 @@ int pdsc_start(struct pdsc *pdsc); void pdsc_stop(struct pdsc *pdsc); void pdsc_health_thread(struct work_struct *work); +int pdsc_auxbus_dev_add_vf(struct pdsc *pdsc, int vf_id); +int pdsc_auxbus_dev_del_vf(struct pdsc *pdsc, int vf_id); + void pdsc_process_adminq(struct pdsc_qcq *qcq); void pdsc_work_thread(struct work_struct *work); irqreturn_t pdsc_adminq_isr(int irq, void *data); diff --git a/drivers/net/ethernet/pensando/pds_core/main.c b/drivers/net/ethernet/pensando/pds_core/main.c index 1ff63a4339d8..b3418e32da63 100644 --- a/drivers/net/ethernet/pensando/pds_core/main.c +++ b/drivers/net/ethernet/pensando/pds_core/main.c @@ -169,7 +169,10 @@ static int pdsc_sriov_configure(struct pci_dev *pdev, int num_vfs) { struct pdsc *pdsc = pci_get_drvdata(pdev); struct device *dev = pdsc->dev; + enum pds_core_vif_types vt; + bool enabled = false; int ret = 0; + int i; if (num_vfs > 0) { pdsc->vfs = kcalloc(num_vfs, sizeof(struct pdsc_vf), GFP_KERNEL); @@ -183,9 +186,21 @@ static int pdsc_sriov_configure(struct pci_dev *pdev, int num_vfs) goto no_vfs; } + /* If any VF types are enabled, start the VF aux devices */ + for (vt = 0; vt < PDS_DEV_TYPE_MAX && !enabled; vt++) + enabled = pdsc->viftype_status[vt].supported && + pdsc->viftype_status[vt].enabled; + if (enabled) + for (i = 0; i < num_vfs; i++) + pdsc_auxbus_dev_add_vf(pdsc, i); + return num_vfs; } + i = pci_num_vf(pdev); + while (i--) + pdsc_auxbus_dev_del_vf(pdsc, i); + no_vfs: pci_disable_sriov(pdev); @@ -332,6 +347,10 @@ static void pdsc_remove(struct pci_dev *pdev) */ pdsc_dl_unregister(pdsc); + /* Remove the VFs and their aux_bus connections before other + * cleanup so that the clients can use the AdminQ to cleanly + * shut themselves down. + */ pdsc_sriov_configure(pdev, 0); /* Now we can lock it up and tear it down */ diff --git a/include/linux/pds/pds_auxbus.h b/include/linux/pds/pds_auxbus.h new file mode 100644 index 000000000000..7ad66d726b01 --- /dev/null +++ b/include/linux/pds/pds_auxbus.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2022 Pensando Systems, Inc */ + + +#ifndef _PDSC_AUXBUS_H_ +#define _PDSC_AUXBUS_H_ + +#include + +struct pds_auxiliary_dev; + +struct pds_auxiliary_drv { + + /* .event_handler() - callback for receiving events + * padev: ptr to the client device info + * event: ptr to event data + * The client can provide an event handler callback that can + * receive DSC events. The Core driver may generate its + * own events which can notify the client of changes in the + * DSC status, such as a RESET event generated when the Core + * has lost contact with the FW - in this case the event.eid + * field will be 0. + */ + void (*event_handler)(struct pds_auxiliary_dev *padev, + union pds_core_notifyq_comp *event); +}; + +struct pds_auxiliary_dev { + struct auxiliary_device aux_dev; + struct pci_dev *pcidev; + u32 id; + u16 client_id; + void (*event_handler)(struct pds_auxiliary_dev *padev, + union pds_core_notifyq_comp *event); + void *priv; +}; +#endif /* _PDSC_AUXBUS_H_ */ From patchwork Wed Dec 7 00:44:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066444 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87B28C352A1 for ; Wed, 7 Dec 2022 00:45:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229511AbiLGApi (ORCPT ); Tue, 6 Dec 2022 19:45:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbiLGApZ (ORCPT ); Tue, 6 Dec 2022 19:45:25 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2047.outbound.protection.outlook.com [40.107.237.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FE56490B1 for ; Tue, 6 Dec 2022 16:45:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OpAkaZSAa0gvxxlmNGeQ1DmbYRfKOJGq60rzSmTwwdGqLUhxyyIUxJW3fz1qvInaOClZNwKLurpJfRgO/oylE2qU0nrtfvA56PMY4I8yCo9YenQJk/PrWJEDi4UFau4i7Sh969q9+q6vQ+bL/DXlBXdXCHT8Xfpvg4/NIRJUBSRoUIX5K/e8PUIdRz45Tb9kaadmLBLaKPHV/1HLbpQuzT+4iGHS3TzFHySQNn2ZAsDL3hIBrGgSmVRv/exA7poIm6qvt9rg5NnHBcTAt0PcK5bK+Li/zSo8Q/PnoMBbGW+SQz559HrxRUSrtSrH3gWZgUAbW3ZR0Pg6Mpr0pfeCsg== 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=SCRL4m4dDeLGllexvaltPaOpxyrqzaWYvk1JaSDAksg=; b=L9qTyM1w1JcqfyxWqbeXRUjaraR29NGVEZzwRNHi3C9rLcGP+HlHigT3tRALlMTvtm4lFl5HY6RgLZuLftwA4o9DEq54ecCrumD5jIziGn7RdjjU6lVZ7FDpyka07U6WKysT6AnOFCWoRDCOPfaKO/5Ec6WsQ2amCeZhp6jnpP/4g81kpOzWXGNn1z7ytXbQgT4ApxBcbJb+HXlA+k+GfvJFQg9VF3cmNrM07yVSq87XhxOIuDeUJQd+xwTGsGBcidkfiOb6xlDHpR5pZL0JL9TxFO9hoZxEBMNLJEEgDZdVSCYaJSGg25606bUGWKIPblKvKPH9t4uUOUrJ8aCvow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SCRL4m4dDeLGllexvaltPaOpxyrqzaWYvk1JaSDAksg=; b=l0JoCal7pTojZCTg0L9fk6jlQMibmEh/SkSV0WiOKarYJ2YD+W/I1NZEB85h5Itgsq4EVpdcEcfGT5Kp/GG6dABHxngT42WiOe6w6Y2fxbiDR8BTiljbKlsOdWaRBL4STBBU5mqJj33ZVxhyapb1b4MG9rQ+NL0X0axOsGsqrFE= Received: from BN9PR03CA0142.namprd03.prod.outlook.com (2603:10b6:408:fe::27) by BN9PR12MB5100.namprd12.prod.outlook.com (2603:10b6:408:119::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:15 +0000 Received: from BN8NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::df) by BN9PR03CA0142.outlook.office365.com (2603:10b6:408:fe::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT073.mail.protection.outlook.com (10.13.177.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:15 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:13 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 13/16] pds_core: devlink params for enabling VIF support Date: Tue, 6 Dec 2022 16:44:40 -0800 Message-ID: <20221207004443.33779-14-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT073:EE_|BN9PR12MB5100:EE_ X-MS-Office365-Filtering-Correlation-Id: 10dc3e47-e8cb-4fdf-38b8-08dad7ec4e85 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n35XT5TNIeOTjlfr+4Bo83mTwHNdE5/GppSirichD+ZF6Vdv7LZP9VSzGcE2g1YFZ1YyIyOwFyaWxlRDLDxqKGovuTEmUt8Z6YBaJ1Nxof5ElIlKzFZNgiEjQhai5j92yUmAH/t1ue2qvBQ6MOEiHhn3R0FyAgNy5HXr0icpoDEcLMVPxALYlBXq22XW1dZr/JkgCofzkpDsnV6dtcTjijVu3mRdMX3WS99lwiZ9525GmNoKD1XWLfKLsSbCvXezUQxnHBr6DMcemcwgqJpyph6ulsQyrdVEiKjIQf5ECBnjvNxNjueJaMbxsX3Bi2bgLXd5VOYPx7/n7aCJ1GK9ZEwQU0QpQbnMRHDUCqWG1gR7O3YhbVKRHmBDDHTfQKVqAwnVj83N94kXCAqRggrHziKBIpdl/mBDsZPmYT0AZktS5Lp+HzHJY3jaS8ViQBAAXk9EcSoOB489rV/ImLs6Y+GJHTHB9jOWXaOnlV/Y5ZGhJs++fxH3glVj3v+Epa7ZDruj57/RXv2WQfluqp71Z/Hc2YVg0ZFOAxoTwE44b8sqSf4mBRIK//e9oE2sDUX7qtzd7n6ZGYkO0JBodRMeegOOaICI6cioU/3WKZPMoG7NHp0wLhgRYqavmk/Cto981UxR3PsGvgJd8QBkQ+YxUpSoWrjQbDHO2VDittTU6AYksKs4HZxXYUMy+sEo8WqoNZ52Uw3uj6MYLOLnY5lUe+sDaW/U3b0wCavq/JShKxY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(136003)(396003)(376002)(346002)(39860400002)(451199015)(40470700004)(36840700001)(46966006)(83380400001)(36860700001)(86362001)(356005)(5660300002)(81166007)(44832011)(4326008)(8936002)(2906002)(82740400003)(40460700003)(41300700001)(70206006)(82310400005)(8676002)(40480700001)(26005)(6666004)(426003)(336012)(47076005)(1076003)(186003)(16526019)(110136005)(316002)(2616005)(54906003)(70586007)(478600001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:15.5485 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 10dc3e47-e8cb-4fdf-38b8-08dad7ec4e85 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5100 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add the devlink parameter switches so the user can enable the features supported by the VFs. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/pds_core/devlink.c | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/drivers/net/ethernet/pensando/pds_core/devlink.c b/drivers/net/ethernet/pensando/pds_core/devlink.c index 0ba4bbbe5f7f..f3df806f7e6b 100644 --- a/drivers/net/ethernet/pensando/pds_core/devlink.c +++ b/drivers/net/ethernet/pensando/pds_core/devlink.c @@ -8,6 +8,75 @@ #include "core.h" +static struct pdsc_viftype *pdsc_dl_find_viftype_by_id(struct pdsc *pdsc, + enum devlink_param_type dl_id) +{ + int vt; + + for (vt = 0; vt < PDS_DEV_TYPE_MAX; vt++) { + if (pdsc->viftype_status[vt].dl_id == dl_id) + return &pdsc->viftype_status[vt]; + } + + return NULL; +} + +static int pdsc_dl_enable_get(struct devlink *dl, u32 id, + struct devlink_param_gset_ctx *ctx) +{ + struct pdsc *pdsc = devlink_priv(dl); + struct pdsc_viftype *vt_entry; + + vt_entry = pdsc_dl_find_viftype_by_id(pdsc, id); + if (!vt_entry) + return -ENOENT; + + ctx->val.vbool = vt_entry->enabled; + + return 0; +} + +static int pdsc_dl_enable_set(struct devlink *dl, u32 id, + struct devlink_param_gset_ctx *ctx) +{ + struct pdsc *pdsc = devlink_priv(dl); + struct pdsc_viftype *vt_entry; + int err = 0; + int vf; + + vt_entry = pdsc_dl_find_viftype_by_id(pdsc, id); + if (!vt_entry || !vt_entry->supported) + return -EOPNOTSUPP; + + if (vt_entry->enabled == ctx->val.vbool) + return 0; + + vt_entry->enabled = ctx->val.vbool; + for (vf = 0; vf < pdsc->num_vfs; vf++) { + err = ctx->val.vbool ? pdsc_auxbus_dev_add_vf(pdsc, vf) : + pdsc_auxbus_dev_del_vf(pdsc, vf); + } + + return err; +} + +static int pdsc_dl_enable_validate(struct devlink *dl, u32 id, + union devlink_param_value val, + struct netlink_ext_ack *extack) +{ + struct pdsc *pdsc = devlink_priv(dl); + struct pdsc_viftype *vt_entry; + + vt_entry = pdsc_dl_find_viftype_by_id(pdsc, id); + if (!vt_entry || !vt_entry->supported) + return -EOPNOTSUPP; + + if (!pdsc->viftype_status[vt_entry->vif_id].supported) + return -ENODEV; + + return 0; +} + static int pdsc_dl_fw_bank_get(struct devlink *dl, u32 id, struct devlink_param_gset_ctx *ctx) { @@ -69,8 +138,35 @@ static const struct devlink_param pdsc_dl_params[] = { pdsc_dl_fw_bank_get, pdsc_dl_fw_bank_set, pdsc_dl_fw_bank_validate), + DEVLINK_PARAM_GENERIC(ENABLE_VNET, + BIT(DEVLINK_PARAM_CMODE_RUNTIME), + pdsc_dl_enable_get, + pdsc_dl_enable_set, + pdsc_dl_enable_validate), + DEVLINK_PARAM_GENERIC(ENABLE_MIGRATION, + BIT(DEVLINK_PARAM_CMODE_RUNTIME), + pdsc_dl_enable_get, + pdsc_dl_enable_set, + pdsc_dl_enable_validate), }; +static void pdsc_dl_set_params_init_values(struct devlink *dl) +{ + struct pdsc *pdsc = devlink_priv(dl); + union devlink_param_value value; + int vt; + + for (vt = 0; vt < PDS_DEV_TYPE_MAX; vt++) { + if (!pdsc->viftype_status[vt].dl_id) + continue; + + value.vbool = pdsc->viftype_status[vt].enabled; + devlink_param_driverinit_value_set(dl, + pdsc->viftype_status[vt].dl_id, + value); + } +} + static int pdsc_dl_flash_update(struct devlink *dl, struct devlink_flash_update_params *params, struct netlink_ext_ack *extack) @@ -166,6 +262,7 @@ int pdsc_dl_register(struct pdsc *pdsc) ARRAY_SIZE(pdsc_dl_params)); if (err) return err; + pdsc_dl_set_params_init_values(dl); devlink_register(dl); From patchwork Wed Dec 7 00:44:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066449 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B8C9C3A5A7 for ; Wed, 7 Dec 2022 00:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229475AbiLGAqZ (ORCPT ); Tue, 6 Dec 2022 19:46:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229809AbiLGAp1 (ORCPT ); Tue, 6 Dec 2022 19:45:27 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2069.outbound.protection.outlook.com [40.107.243.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7999D4EC01 for ; Tue, 6 Dec 2022 16:45:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pr/jUWEtSaU8HMzzacsp9Ma2b+Jy1JJlQaxczL0zR1cffOw7/SHfuMD0ITHB3wPLKhtRMez8q/48n1lihE2nbS94s0/83mv5H3Xv0rTgvGoEIWQpr7YOlWsGdrgMlSDXD/y8yHxfIiYJ7RwC5tqnVaRupJa4+QEImUIhXGz6uP139uKwOAhv2+pglnHeK5r7SEhfFvee4RjzKpdqsoIHXHuZeGmqRADjDtKY1smHFKX49dTE9oQnfo5mCYmcyuFzoE8TsV2ZRYOUqbko5t8pv/gl03na+qaRTlt8kuw/duPGjNfrAKinnhbkXqr2Nmq7luI5EamM1NwsNpPj8Jozhw== 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=FkrLBOaHfUn8fFpGADArRA0+DoOAA8xiSN0FgzMn/fs=; b=XBaPpD63rsglTlt2u992H6xEQ3R4NjZ96wA8R6Pr7zr9NIKtzMhSplgTZnOwE+khmnzzhgD45RujISF/rcw5/C6E0E+qP/X3YtYOhiycl/P7gAh0xwjDlpNff24D6TlxZrezmC3ad1cxJ/8SlwP1WIagzEdBCGdNJvWEmc2myn7B7XGW21brFK5e0OdiuBpg3WnBOyT8HHUuZVGDHO/G9rDEv7H2iabUrUf8kgd/c+nUEFqqs703YB9NnaC1rWUDdFKdhVbkE6qCAUYljW/Pn99rsebbziLHm9JRtTKa+6MpOK6LeNQsBv16kvW4AenPlD6qjK+1l5SfA+F/HBxtdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FkrLBOaHfUn8fFpGADArRA0+DoOAA8xiSN0FgzMn/fs=; b=h5ZrHT6OSXyROPVfWKkg+jM9VWyKeqnwlL72rnLUYGmY+PsvCr1Fp3veMr+o5dlD/7AvZU/+I80zblGiuiilDY5axg+SU8N3OmNuUGlLufR0pRCB1fujjSvuk4GVNZnMW7b32CP+1uxLpQLByAtrF32kOxk6Lj7LO5BbZKIO9mQ= Received: from BN9PR03CA0132.namprd03.prod.outlook.com (2603:10b6:408:fe::17) by SN7PR12MB6957.namprd12.prod.outlook.com (2603:10b6:806:263::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.13; Wed, 7 Dec 2022 00:45:16 +0000 Received: from BN8NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::c4) by BN9PR03CA0132.outlook.office365.com (2603:10b6:408:fe::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT073.mail.protection.outlook.com (10.13.177.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:15 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:13 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 14/16] pds_core: add the aux client API Date: Tue, 6 Dec 2022 16:44:41 -0800 Message-ID: <20221207004443.33779-15-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT073:EE_|SN7PR12MB6957:EE_ X-MS-Office365-Filtering-Correlation-Id: 88a809f7-b350-4af8-491e-08dad7ec4eb7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 44UW5iN5mz+BIR0bKAxsLhwQJAthXoXQh/WLTTAw1CIxG/Ar7eThS68xeQFtie+ksxJfCiRbZ+fJj/C9uPjHTpURUr+9MyQJ7Y/rrwgCZE5rqOJfICDK/FX0ve6liFtBCW32mSvArSRBsK37kTj+VUe6yn4m8J1aSWAg7L/WNi738islQii91i+aQaILSNtu4eE/bJKNRaa9ABiHddISuuRRPMb6DlTuQa6RG93+icVoe0PJJ8RfgG33UA0zi3tTnDvwTYkjDf7mhnUeB98+P6zU/bVLHD3GCzflySoX9CUB0NAtfwq1Hzrgvsudmy5NCZzmvuGW4cfnlF+sN7/EKLeBA6q/gY+Et0rLEwkyLLswg+B3srWzNwvECx43PzPFKiH6kZx4yRf3UdoUgcGf3BAi8eMC4WcwiGDlffau+WXCuaWmL9ZBMpaCcl4T2OmBmsYSYuIStWax5D6cIuorLAYuDC33J9c3wva6RcwD/Blkm5NJJNxRZBEPNTCfDLbAZUbEJOe6KIH4mw0Ie2QTGkgUnIF9C59YDrq8utdp1UMUN31uDVKH6e9WqoyuPFVvPN4M7fomWqP/3H36wpJOwu3MQxmydhOrxy0l5ELHfd1jKgEymjjUi+nQm9j5YfTWb8TT69crxtnv2Mx6/LaMK4K0vHR+TYYymPkzkziE2rmtDg3xCxolrCKkW2wene4p2Sdx4jIsh18fwYff42v+kH2RzBL3+lbdWwJXOpVZx6o= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(39860400002)(136003)(396003)(346002)(451199015)(36840700001)(40470700004)(46966006)(36860700001)(2906002)(83380400001)(36756003)(336012)(40480700001)(16526019)(186003)(1076003)(41300700001)(70586007)(70206006)(86362001)(40460700003)(26005)(82740400003)(356005)(81166007)(110136005)(82310400005)(426003)(8676002)(2616005)(316002)(4326008)(44832011)(8936002)(6666004)(54906003)(5660300002)(478600001)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:15.8766 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88a809f7-b350-4af8-491e-08dad7ec4eb7 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6957 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add the client API operations for registering, unregistering, and running adminq commands. We expect to add additional operations for other clients, including requesting additional private adminqs and IRQs, but don't have the need yet, Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/pds_core/auxbus.c | 144 +++++++++++++++++- include/linux/pds/pds_auxbus.h | 51 +++++++ 2 files changed, 193 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/pensando/pds_core/auxbus.c b/drivers/net/ethernet/pensando/pds_core/auxbus.c index 331944a4d1a0..e82f4e2ef458 100644 --- a/drivers/net/ethernet/pensando/pds_core/auxbus.c +++ b/drivers/net/ethernet/pensando/pds_core/auxbus.c @@ -11,6 +11,144 @@ #include #include +/** + * pds_client_register - Register the client with the device + * @padev: ptr to the client device info + * @padrv: ptr to the client driver info + * + * Register the client with the core and with the DSC. The core + * will fill in the client padev->client_id for use in calls + * to the DSC AdminQ + */ +static int pds_client_register(struct pds_auxiliary_dev *padev, + struct pds_auxiliary_drv *padrv) +{ + union pds_core_adminq_comp comp = { 0 }; + union pds_core_adminq_cmd cmd = { 0 }; + struct device *dev; + struct pdsc *pdsc; + int err; + u16 ci; + + pdsc = (struct pdsc *)dev_get_drvdata(padev->aux_dev.dev.parent); + dev = pdsc->dev; + + if (pdsc->state) + return -ENXIO; + + cmd.client_reg.opcode = PDS_AQ_CMD_CLIENT_REG; + strscpy(cmd.client_reg.devname, dev_name(&padev->aux_dev.dev), + sizeof(cmd.client_reg.devname)); + + err = pdsc_adminq_post(pdsc, &pdsc->adminqcq, &cmd, &comp, false); + if (err) { + dev_info(dev, "register dev_name %s with DSC failed, status %d: %pe\n", + dev_name(&padev->aux_dev.dev), comp.status, ERR_PTR(err)); + return err; + } + + ci = le16_to_cpu(comp.client_reg.client_id); + if (!ci) { + dev_err(dev, "%s: device returned null client_id\n", __func__); + return -EIO; + } + + padev->client_id = ci; + padev->event_handler = padrv->event_handler; + + return 0; +} + +/** + * pds_client_unregister - Disconnect the client from the device + * @padev: ptr to the client device info + * + * Disconnect the client from the core and with the DSC. + */ +static int pds_client_unregister(struct pds_auxiliary_dev *padev) +{ + union pds_core_adminq_comp comp = { 0 }; + union pds_core_adminq_cmd cmd = { 0 }; + struct device *dev; + struct pdsc *pdsc; + int err; + + pdsc = (struct pdsc *)dev_get_drvdata(padev->aux_dev.dev.parent); + dev = pdsc->dev; + + if (pdsc->state) + return -ENXIO; + + cmd.client_unreg.opcode = PDS_AQ_CMD_CLIENT_UNREG; + cmd.client_unreg.client_id = cpu_to_le16(padev->client_id); + + err = pdsc_adminq_post(pdsc, &pdsc->adminqcq, &cmd, &comp, false); + if (err) + dev_info(dev, "unregister dev_name %s failed, status %d: %pe\n", + dev_name(&padev->aux_dev.dev), comp.status, ERR_PTR(err)); + + padev->client_id = 0; + + return err; +} + +/** + * pds_client_adminq_cmd - Process an adminq request for the client + * @padev: ptr to the client device + * @req: ptr to buffer with request + * @req_len: length of actual struct used for request + * @resp: ptr to buffer where answer is to be copied + * @flags: optional flags from pds_core_adminq_flags + * + * Return: 0 on success, or + * negative for error + * + * Client sends pointers to request and response buffers + * Core copies request data into pds_core_client_request_cmd + * Core sets other fields as needed + * Core posts to AdminQ + * Core copies completion data into response buffer + */ +static int pds_client_adminq_cmd(struct pds_auxiliary_dev *padev, + union pds_core_adminq_cmd *req, + size_t req_len, + union pds_core_adminq_comp *resp, + u64 flags) +{ + union pds_core_adminq_cmd cmd = { 0 }; + struct device *dev; + struct pdsc *pdsc; + size_t cp_len; + int err; + + pdsc = (struct pdsc *)dev_get_drvdata(padev->aux_dev.dev.parent); + dev = pdsc->dev; + + dev_dbg(dev, "%s: %s opcode %d\n", + __func__, dev_name(&padev->aux_dev.dev), req->opcode); + + if (pdsc->state) + return -ENXIO; + + /* Wrap the client's request */ + cmd.client_request.opcode = PDS_AQ_CMD_CLIENT_CMD; + cmd.client_request.client_id = cpu_to_le16(padev->client_id); + cp_len = min_t(size_t, req_len, sizeof(cmd.client_request.client_cmd)); + memcpy(cmd.client_request.client_cmd, req, cp_len); + + err = pdsc_adminq_post(pdsc, &pdsc->adminqcq, &cmd, resp, !!(flags & PDS_AQ_FLAG_FASTPOLL)); + if (err && err != -EAGAIN) + dev_info(dev, "client admin cmd failed: %pe\n", ERR_PTR(err)); + + return err; +} + +static struct pds_core_ops pds_core_ops = { + .register_client = pds_client_register, + .unregister_client = pds_client_unregister, + .adminq_cmd = pds_client_adminq_cmd, +}; + static void pdsc_auxbus_dev_release(struct device *dev) { struct pds_auxiliary_dev *padev = @@ -21,7 +159,8 @@ static void pdsc_auxbus_dev_release(struct device *dev) static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *pdsc, char *name, u32 id, - struct pci_dev *client_dev) + struct pci_dev *client_dev, + struct pds_core_ops *ops) { struct auxiliary_device *aux_dev; struct pds_auxiliary_dev *padev; @@ -31,6 +170,7 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *pdsc, if (!padev) return NULL; + padev->ops = ops; padev->pcidev = client_dev; aux_dev = &padev->aux_dev; @@ -96,7 +236,7 @@ int pdsc_auxbus_dev_add_vf(struct pdsc *pdsc, int vf_id) id = PCI_DEVID(pdsc->pdev->bus->number, pci_iov_virtfn_devfn(pdsc->pdev, vf_id)); padev = pdsc_auxbus_dev_register(pdsc, pdsc->viftype_status[vt].name, id, - pdsc->pdev); + pdsc->pdev, &pds_core_ops); pdsc->vfs[vf_id].padev = padev; /* We only support a single type per VF, so jump out here */ diff --git a/include/linux/pds/pds_auxbus.h b/include/linux/pds/pds_auxbus.h index 7ad66d726b01..ac121b44c71a 100644 --- a/include/linux/pds/pds_auxbus.h +++ b/include/linux/pds/pds_auxbus.h @@ -27,6 +27,7 @@ struct pds_auxiliary_drv { struct pds_auxiliary_dev { struct auxiliary_device aux_dev; + struct pds_core_ops *ops; struct pci_dev *pcidev; u32 id; u16 client_id; @@ -34,4 +35,54 @@ struct pds_auxiliary_dev { union pds_core_notifyq_comp *event); void *priv; }; + +struct pds_fw_state { + unsigned long last_fw_time; + u32 fw_heartbeat; + u8 fw_status; +}; + +/* + * ptrs to functions to be used by the client for core services + */ +struct pds_core_ops { + + /* .register() - register the client with the device + * padev: ptr to the client device info + * padrv: ptr to the client driver info + * Register the client with the core and with the DSC. The core + * will fill in the client padrv->client_id for use in calls + * to the DSC AdminQ + */ + int (*register_client)(struct pds_auxiliary_dev *padev, + struct pds_auxiliary_drv *padrv); + + /* .unregister() - disconnect the client from the device + * padev: ptr to the client device info + * Disconnect the client from the core and with the DSC. + */ + int (*unregister_client)(struct pds_auxiliary_dev *padev); + + /* .adminq_cmd() - process an adminq request for the client + * padev: ptr to the client device + * req: ptr to buffer with request + * req_len: length of actual struct used for request + * resp: ptr to buffer where answer is to be copied + * flags: optional flags defined by enum pds_core_adminq_flags + * and used for more flexible adminq behvior + * + * returns 0 on success, or + * negative for error + * Client sends pointers to request and response buffers + * Core copies request data into pds_core_client_request_cmd + * Core sets other fields as needed + * Core posts to AdminQ + * Core copies completion data into response buffer + */ + int (*adminq_cmd)(struct pds_auxiliary_dev *padev, + union pds_core_adminq_cmd *req, + size_t req_len, + union pds_core_adminq_comp *resp, + u64 flags); +}; #endif /* _PDSC_AUXBUS_H_ */ From patchwork Wed Dec 7 00:44:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066448 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6710C63706 for ; Wed, 7 Dec 2022 00:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbiLGAp5 (ORCPT ); Tue, 6 Dec 2022 19:45:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbiLGAp0 (ORCPT ); Tue, 6 Dec 2022 19:45:26 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2087.outbound.protection.outlook.com [40.107.237.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B477D4E680 for ; Tue, 6 Dec 2022 16:45:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LtlrhCCkdPdSKayTTpg/YPIe8dZ6uTgaNP84h4z5WjniYlhNOvcfkmc/+fcfiDwXXKRhEhlRyQ0J0yefyTIo9XxMEwM0HFuovUdBInyj6S4ZO48o9tCAbzu1hHsVT9zvw3yMlWJ9mIGC4KV6LMbeO7hfR2mrUF0wA/XNPRcWY79B/QAsjYXN1cjMdFOZv3KZfVIq2hqo/aUT9eN3VeaNLheO2AExrQJxoLO9BBKk1+cA+vI3PF8nIn8vMjSOw4qlEZl3Ehk2BwHGBG/i/yglOguZYHIESMRtUzmSLfh3DdSNRshJRvXe3ksSULeubmyemYHxCYp0sZaWp0mvWzaMiQ== 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=GdZrI+mSjKE4Yzd0HOOXSpqCjdE+E9tyCmN7tuBUkBU=; b=FFBVz6x1RuuAB1VjEEOe//KbIoa6sW+JNbMRQG1koe00LL76/A9qu3J+ZCYdDs0LFFo204U3oWNBnNfIayh1gAnlDbR+YmswTK2+L9bnozAmupxNL32HklsgfpEyvM8MhbthkHsd40Rjs12OT+0O6N+jR4y2oxsq5uiIFw4SGzk62YFgHrb9o+l0p1CR7EpUXpIFtjzGEOg69ZXctZeWvKn2cpaem7niVffl5vdu9+ZwSeIijy/EKlEcCcB2s5gp6LMLMQ8Zsh5sOLw63qCmYF9UkCc1waMdm3U8JPyP9iLt4BdjPs+bsRl0jKk4xlxfQdPFZp5aGQNkgVpV/kKyXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GdZrI+mSjKE4Yzd0HOOXSpqCjdE+E9tyCmN7tuBUkBU=; b=yyYWCgDV8xIgRw9fcmc+WvMGthu0XlDB+7iRVb+wPOnsTfFcWlSuHyMGMk9HtanEhtGudjt9XvpnSmebn4YpuwUiIa+2zb1nFPONEmmZMJpFjF1YsTfSfRlskE10ga8AlEthF0Jh243D1KlVdD+1W4lf3c0OP3gD7NlYzS9eSyk= Received: from BN9PR03CA0148.namprd03.prod.outlook.com (2603:10b6:408:fe::33) by IA1PR12MB6114.namprd12.prod.outlook.com (2603:10b6:208:3ea::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:16 +0000 Received: from BN8NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::3) by BN9PR03CA0148.outlook.office365.com (2603:10b6:408:fe::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT073.mail.protection.outlook.com (10.13.177.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:16 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:14 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 15/16] pds_core: publish events to the clients Date: Tue, 6 Dec 2022 16:44:42 -0800 Message-ID: <20221207004443.33779-16-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT073:EE_|IA1PR12MB6114:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a90b8ec-2657-440b-19fb-08dad7ec4f2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uEgkr9Uc8CvhwiQleJ2OJBQb7nNbFg8oOuqn99xR0hze7NoWQulzEQfjakrRRxJ3hZI+DXY3L0ZzXN/MIo9Q6OE85qYthjzzL9KMGSmeaegjFOEBmdbrdAhkUCo9VZi2gtBEAGvDfVX2748xSM9qsBcvnsOnvGN+qIkdwuSWf3ejnnoAwuISxROQFkmb+39v1L6h96p1vT1vlTfW84+AoeE1PhvvPnj+UovdgH6NGD9OutDbN9/nG0owVtWAGrMIXs9/yuwK6FLD9H2yV27iOobyfZ5/k6KwgobR/t2Y+Gglf5HDMkqhv6aPp41O91Od293YsAQ+zcQ67rCBm/s3PhurVGd4RzVxGOU53GcomWvso4mxaSOYd5eK5+DLggc0TNRRfmOXgaE8S394aOIYaw7Xl/QEJ04eOgDhCX1L6ybb8YH4eUc45bpRaLxC7iaRULHU0FC2LI7M2uWBg+4YO1g0C8RZ6Kwv9FBxukiI4RoGGw4hvook0dAPeLmtqYtWcYf2JahYX3fCXIp+mTW8wqSCQNOxDmyiKAWWNb40mAVJ+Jj8M5GTvThW7ZZREDwNuv4WC1CTaIj+OcCxwsU9Ei2jndPdUz93uuQXjFUbelBa46dbHReqEzL94yeK/7nw+HCg/U1WcoiQHQWUWwXQ4PxVrS9uWkecxxm91Gtjp/2YwoM+9ripJgJ0OeNbZ/dbspd6Ags4vPNYrPaH5valRilRHkeb1xZKdyAzLtE07ao= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(39860400002)(136003)(346002)(451199015)(36840700001)(40470700004)(46966006)(40480700001)(81166007)(36756003)(356005)(82740400003)(86362001)(40460700003)(316002)(110136005)(6666004)(54906003)(478600001)(44832011)(2906002)(5660300002)(8936002)(70586007)(41300700001)(36860700001)(4326008)(8676002)(70206006)(83380400001)(47076005)(2616005)(426003)(82310400005)(26005)(1076003)(336012)(16526019)(186003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:16.6421 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7a90b8ec-2657-440b-19fb-08dad7ec4f2c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6114 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When the Core device gets an event from the device, or notices the device FW to be up or down, it needs to send those events on to the clients that have an event handler. Add the code to pass along the events to either the specific client or to all the clients. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/pds_core/adminq.c | 17 ++++++++ .../net/ethernet/pensando/pds_core/auxbus.c | 40 +++++++++++++++++++ drivers/net/ethernet/pensando/pds_core/core.c | 15 +++++++ drivers/net/ethernet/pensando/pds_core/core.h | 3 ++ 4 files changed, 75 insertions(+) diff --git a/drivers/net/ethernet/pensando/pds_core/adminq.c b/drivers/net/ethernet/pensando/pds_core/adminq.c index ba9e84a7ca92..4d2d69ce81f4 100644 --- a/drivers/net/ethernet/pensando/pds_core/adminq.c +++ b/drivers/net/ethernet/pensando/pds_core/adminq.c @@ -34,11 +34,13 @@ static int pdsc_process_notifyq(struct pdsc_qcq *qcq) case PDS_EVENT_LINK_CHANGE: dev_info(pdsc->dev, "NotifyQ LINK_CHANGE ecode %d eid %lld\n", ecode, eid); + pdsc_auxbus_publish(pdsc, PDSC_ALL_CLIENT_IDS, comp); break; case PDS_EVENT_RESET: dev_info(pdsc->dev, "NotifyQ RESET ecode %d eid %lld\n", ecode, eid); + pdsc_auxbus_publish(pdsc, PDSC_ALL_CLIENT_IDS, comp); break; case PDS_EVENT_XCVR: @@ -46,6 +48,21 @@ static int pdsc_process_notifyq(struct pdsc_qcq *qcq) ecode, eid); break; + case PDS_EVENT_CLIENT: + { + struct pds_core_client_event *ce; + union pds_core_notifyq_comp *cc; + u16 client_id; + + ce = (struct pds_core_client_event *)comp; + cc = (union pds_core_notifyq_comp *)&ce->client_event; + client_id = le16_to_cpu(ce->client_id); + dev_info(pdsc->dev, "NotifyQ CLIENT %d ecode %d eid %lld cc->ecode %d\n", + client_id, ecode, eid, le16_to_cpu(cc->ecode)); + pdsc_auxbus_publish(pdsc, client_id, cc); + break; + } + default: dev_info(pdsc->dev, "NotifyQ ecode %d eid %lld\n", ecode, eid); diff --git a/drivers/net/ethernet/pensando/pds_core/auxbus.c b/drivers/net/ethernet/pensando/pds_core/auxbus.c index e82f4e2ef458..55507a690a79 100644 --- a/drivers/net/ethernet/pensando/pds_core/auxbus.c +++ b/drivers/net/ethernet/pensando/pds_core/auxbus.c @@ -205,6 +205,46 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *pdsc, return NULL; } +static int pdsc_core_match(struct device *dev, const void *data) +{ + struct pds_auxiliary_dev *curr_padev; + struct pdsc *curr_pdsc; + const struct pdsc *pdsc; + + /* Match the core device searching for its clients */ + curr_padev = container_of(dev, struct pds_auxiliary_dev, aux_dev.dev); + curr_pdsc = (struct pdsc *)dev_get_drvdata(curr_padev->aux_dev.dev.parent); + pdsc = data; + + if (curr_pdsc == pdsc) + return 1; + + return 0; +} + +int pdsc_auxbus_publish(struct pdsc *pdsc, u16 client_id, + union pds_core_notifyq_comp *event) +{ + struct pds_auxiliary_dev *padev; + struct auxiliary_device *aux_dev; + + /* Search aux bus for this core's devices */ + aux_dev = auxiliary_find_device(NULL, pdsc, pdsc_core_match); + while (aux_dev) { + padev = container_of(aux_dev, struct pds_auxiliary_dev, aux_dev); + if ((padev->client_id == client_id || + client_id == PDSC_ALL_CLIENT_IDS) && + padev->event_handler) + padev->event_handler(padev, event); + put_device(&aux_dev->dev); + + aux_dev = auxiliary_find_device(&aux_dev->dev, + pdsc, pdsc_core_match); + } + + return 0; +} + int pdsc_auxbus_dev_add_vf(struct pdsc *pdsc, int vf_id) { struct pds_auxiliary_dev *padev; diff --git a/drivers/net/ethernet/pensando/pds_core/core.c b/drivers/net/ethernet/pensando/pds_core/core.c index e6810f43df26..ac9fe716fb52 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.c +++ b/drivers/net/ethernet/pensando/pds_core/core.c @@ -520,6 +520,11 @@ void pdsc_stop(struct pdsc *pdsc) static void pdsc_fw_down(struct pdsc *pdsc) { + union pds_core_notifyq_comp reset_event = { + .reset.ecode = cpu_to_le16(PDS_EVENT_RESET), + .reset.state = 0, + }; + mutex_lock(&pdsc->config_lock); if (test_and_set_bit(PDSC_S_FW_DEAD, &pdsc->state)) { @@ -528,6 +533,9 @@ static void pdsc_fw_down(struct pdsc *pdsc) return; } + /* Notify clients of fw_down */ + pdsc_auxbus_publish(pdsc, PDSC_ALL_CLIENT_IDS, &reset_event); + pdsc_mask_interrupts(pdsc); pdsc_teardown(pdsc, PDSC_TEARDOWN_RECOVERY); @@ -536,6 +544,10 @@ static void pdsc_fw_down(struct pdsc *pdsc) static void pdsc_fw_up(struct pdsc *pdsc) { + union pds_core_notifyq_comp reset_event = { + .reset.ecode = cpu_to_le16(PDS_EVENT_RESET), + .reset.state = 1, + }; int err; mutex_lock(&pdsc->config_lock); @@ -556,6 +568,9 @@ static void pdsc_fw_up(struct pdsc *pdsc) mutex_unlock(&pdsc->config_lock); + /* Notify clients of fw_up */ + pdsc_auxbus_publish(pdsc, PDSC_ALL_CLIENT_IDS, &reset_event); + return; err_out: diff --git a/drivers/net/ethernet/pensando/pds_core/core.h b/drivers/net/ethernet/pensando/pds_core/core.h index dbf1fe5135ad..ace1a1b1ec8f 100644 --- a/drivers/net/ethernet/pensando/pds_core/core.h +++ b/drivers/net/ethernet/pensando/pds_core/core.h @@ -302,6 +302,9 @@ int pdsc_start(struct pdsc *pdsc); void pdsc_stop(struct pdsc *pdsc); void pdsc_health_thread(struct work_struct *work); +#define PDSC_ALL_CLIENT_IDS 0xffff +int pdsc_auxbus_publish(struct pdsc *pdsc, u16 client_id, + union pds_core_notifyq_comp *event); int pdsc_auxbus_dev_add_vf(struct pdsc *pdsc, int vf_id); int pdsc_auxbus_dev_del_vf(struct pdsc *pdsc, int vf_id); From patchwork Wed Dec 7 00:44:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nelson, Shannon" X-Patchwork-Id: 13066447 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3FC4C3A5A7 for ; Wed, 7 Dec 2022 00:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229834AbiLGAp4 (ORCPT ); Tue, 6 Dec 2022 19:45:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229843AbiLGAp0 (ORCPT ); Tue, 6 Dec 2022 19:45:26 -0500 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2050.outbound.protection.outlook.com [40.107.102.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A67C4E6B7 for ; Tue, 6 Dec 2022 16:45:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bIdCUQ+zPIhsCUcsJMrZdaZPMpuTJLCuD2LjRttDtXwwXKZ8FBYpWOiGmJ0HY/zWSriFyFiQwKm38QzrIYsp3X6a3WQIzK8N8H2pdboG1JN16hHTq2OJwKJZvb6pP9esw0pHqVKzHTwqQb97tsPi2TUp1VpDYXvZ2wOxSh8gkGg4NXcwBA7z/9LMAe0zBr8rhZV4xxOzjrDPK+lSsRrhUOaY7UI0iObMAwkFPeVbbdDGI0Ow7eHXWmLG1Edqy5AHXkMmxq4dbVdRFJ+QD/Hvs7ieQ8yXod2h86WATEM5wX5EYaPzbsAUa/OPCD6MGrE4KnMxtiZCyczDt3rSo7KMoQ== 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=mHoSRqEdWpWxyycEQB0jkDSIyCq6qX88t+2U92PHpNE=; b=ZZ8O9H8RrSF/tOYUJqBWm4zP7Yv/c2uDNbl3zdgrEpwueMQIs9QLPmuMj7RvQBBDPLYHugcomJP2wa0h/5bJQBI7ULBzDMlsZfvuvIKkgm6tZgeD0vsSWcGUj8hoqfb7qbcF53XOvZKzRk2jWgV6/ucW6vG+PaZ3UN691PrRQ1gHRnkwL+ylNMHQSHkDPIccbgeq4Ajjy4Yx+XlAWQFxB2ZGOCGqPSJKPnvfNFbcpb9Zsf3+fnfptvsTaayG/9wQCC9K6r/KKlkJeKyBKs9iO/FRYZMt7nZl6Wn2fWkyLeTCNTzKnz3pBtTSc8c21zeHv8Qhu3gVr0LGa21afP8rAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mHoSRqEdWpWxyycEQB0jkDSIyCq6qX88t+2U92PHpNE=; b=VzqwPwy5o9VBA8moHocVITapDSGeHjN7EDi0WLbONSIiijqE3gMOBrBku6+FkZfbU1mOd6t0MZ8lttA2IBUmPRcuIQ+kaVryqSn22GasokZvmCRd9FEGNTyYS1W8cUh6RpK0I16PXB1uEKXEbvPI2FRud6AuCw4xJugk7w8IrRI= Received: from BN9PR03CA0144.namprd03.prod.outlook.com (2603:10b6:408:fe::29) by SJ0PR12MB5454.namprd12.prod.outlook.com (2603:10b6:a03:304::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 00:45:17 +0000 Received: from BN8NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::58) by BN9PR03CA0144.outlook.office365.com (2603:10b6:408:fe::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT073.mail.protection.outlook.com (10.13.177.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 00:45:16 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 18:45:15 -0600 From: Shannon Nelson To: , , CC: , Shannon Nelson Subject: [PATCH v2 net-next 16/16] pds_core: Kconfig and pds_core.rst Date: Tue, 6 Dec 2022 16:44:43 -0800 Message-ID: <20221207004443.33779-17-shannon.nelson@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207004443.33779-1-shannon.nelson@amd.com> References: <20221207004443.33779-1-shannon.nelson@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT073:EE_|SJ0PR12MB5454:EE_ X-MS-Office365-Filtering-Correlation-Id: 08dbada8-3e72-442d-2a52-08dad7ec4f5e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gtaSi6B2AmK4L6eP1VY/og0eXsgyp3a8yAZb22s/fRF5WEwbA+btfKpeOMkB1NonTuwgaVpDjDz2coQIrWjITXQdSES9zf6f2JpsBqONmlPEfYUV7F3AlK8bNYs7GHru50RD88xHmFO22cdO9rwwm+wBf6RzKuN/4mAKin/98W3kyIFX2M1Z4CR0DGX3jVNvAn4VlmVi+04oRwpwnjzKHsQGbUTp/eKlSnPu/54Zo2rOHqronfhpPR3spAmyxgPHRRxpLJDBglAH6tUqRVWvAI55b5Y9N1YqH4zTZymwbqIshLxlSdlNDiaZXqztxrmLCZClKi0fYmPEQPEa6vsQ+46NKpq/QfsQAc6gtyen+UrlFf6/k5Z1QVUCiOs/gcsd6N0vQczT3DkgfSpzSwHF3fjUCrVmnrRCHyW3TrjvhBkrs8lsO+NSicPWNCFDfeW3yMfP6GYP9cGODlnzCqwHFuffSowJ9IgaccdmMGP/L0k1RgEofrMHNlkd+ySzlDhYKJImBCdO1Liof6XjOwUvkSh6eu6eKf1HpV35dG4CFFPXN3k3KWO6M0j83CZoaE6YYpJI+ZA9eN1nYBhkYGDzkbwe8glWrdHTjG8o32qzn7n5i1VY7uchlwze68VtMkKy/1jMfF9ZiGTWaP/VdKI5SxIKGwKTkrILomKcs8iJ+8G/tczyZPdfIutN3M8iTSQPHeMRVjJVe/vJE8nufBM29DwwM/M9fdj1kU+Gyhp8N1jE98xGsUOvI11Aeq0MzFp7/DWOT03K88sBsNIAk2S7jw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(376002)(346002)(136003)(451199015)(46966006)(36840700001)(40470700004)(36860700001)(83380400001)(86362001)(81166007)(356005)(82740400003)(5660300002)(2906002)(40460700003)(4326008)(41300700001)(8936002)(44832011)(8676002)(82310400005)(6666004)(43170500006)(40480700001)(26005)(47076005)(186003)(426003)(1076003)(336012)(16526019)(54906003)(316002)(110136005)(2616005)(70206006)(70586007)(478600001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 00:45:16.9702 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 08dbada8-3e72-442d-2a52-08dad7ec4f5e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5454 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Documentation and Kconfig hook for building the driver. Signed-off-by: Shannon Nelson --- .../ethernet/pensando/pds_core.rst | 159 ++++++++++++++++++ MAINTAINERS | 3 +- drivers/net/ethernet/pensando/Kconfig | 12 ++ 3 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 Documentation/networking/device_drivers/ethernet/pensando/pds_core.rst diff --git a/Documentation/networking/device_drivers/ethernet/pensando/pds_core.rst b/Documentation/networking/device_drivers/ethernet/pensando/pds_core.rst new file mode 100644 index 000000000000..95424e8ba1fb --- /dev/null +++ b/Documentation/networking/device_drivers/ethernet/pensando/pds_core.rst @@ -0,0 +1,159 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +======================================================== +Linux Driver for the Pensando(R) DSC adapter family +======================================================== + +Pensando Linux Core driver +Copyright(c) 2022 Pensando Systems, Inc + +Identifying the Adapter +======================= + +To find if one or more Pensando PCI Core devices are installed on the +host, check for the PCI devices:: + + # lspci -d 1dd8:100c + 39:00.0 Processing accelerators: Pensando Systems Device 100c + 3a:00.0 Processing accelerators: Pensando Systems Device 100c + +If such devices are listed as above, then the pds_core.ko driver should find +and configure them for use. There should be log entries in the kernel +messages such as these:: + + $ dmesg | grep pds_core + pds_core 0000:b5:00.0: 126.016 Gb/s available PCIe bandwidth (8.0 GT/s PCIe x16 link) + pds_core 0000:b5:00.0: FW: 1.51.0-73 + pds_core 0000:b6:00.0: 126.016 Gb/s available PCIe bandwidth (8.0 GT/s PCIe x16 link) + pds_core 0000:b5:00.0: FW: 1.51.0-73 + +Driver and firmware version information can be gathered with devlink:: + + $ devlink dev info pci/0000:b5:00.0 + pci/0000:b5:00.0: + driver pds_core + serial_number FLM18420073 + versions: + fixed: + asic.id 0x0 + asic.rev 0x0 + running: + fw 1.51.0-73 + stored: + fw.goldfw 1.15.9-C-22 + fw.mainfwa 1.51.0-73 + fw.mainfwb 1.51.0-57 + + +Info versions +============= + +The ``pds_core`` driver reports the following versions + +.. list-table:: devlink info versions implemented + :widths: 5 5 90 + + * - Name + - Type + - Description + * - ``fw`` + - running + - Version of firmware running on the device + * - ``fw.goldfw`` + - stored + - Version of firmware stored in the goldfw slot + * - ``fw.mainfwa`` + - stored + - Version of firmware stored in the mainfwa slot + * - ``fw.mainfwb`` + - stored + - Version of firmware stored in the mainfwb slot + * - ``asic.id`` + - fixed + - The ASIC type for this device + * - ``asic.rev`` + - fixed + - The revision of the ASIC for this device + + +Parameters +========== + +The ``pds_core`` driver implements the following generic +parameters for controlling the functionality to be made available +as auxiliary_bus devices. + +.. list-table:: Generic parameters implemented + :widths: 5 5 8 82 + + * - Name + - Mode + - Type + - Description + * - ``enable_vnet`` + - runtime + - Boolean + - Enables vDPA functionality through an auxiliary_bus device + + +The ``pds_core`` driver also implements the following driver-specific +parameters for similar uses, as well as for selecting the next boot firmware: + +.. list-table:: Driver-specific parameters implemented + :widths: 5 5 8 82 + + * - Name + - Mode + - Type + - Description + * - ``enable_migration`` + - runtime + - Boolean + - Enables Live Migration functionality through an auxiliary_bus device + * - ``fw_bank`` + - runtime + - String + - Selects the Firmware slot to use for the next DSC boot + + +Firmware Management +=================== + +The ``fw_bank`` parameter can inspect and select the firmware image to be +used in the next DSC boot up. Banks 1 and 2 are used for normal operations, +while bank 3 should only be selected for recovery purposes if both the other +banks have bad or corrupted firmware. + +The ``flash`` command can update a the DSC firmware. The downloaded firmware +will be saved into either of firmware bank 1 or bank 2, whichever is not +currrently in use, and that bank will be then selected for the next boot. +The ``fw_bank`` parameter will be updated to reflect this. + +Enabling the driver +=================== + +The driver is enabled via the standard kernel configuration system, +using the make command:: + + make oldconfig/menuconfig/etc. + +The driver is located in the menu structure at: + + -> Device Drivers + -> Network device support (NETDEVICES [=y]) + -> Ethernet driver support + -> Pensando devices + -> Pensando Ethernet PDS_CORE Support + +Support +======= + +For general Linux networking support, please use the netdev mailing +list, which is monitored by Pensando personnel:: + + netdev@vger.kernel.org + +For more specific support needs, please use the Pensando driver support +email:: + + drivers@pensando.io diff --git a/MAINTAINERS b/MAINTAINERS index 955c1be1efb2..f77fd6fbdedd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16156,8 +16156,9 @@ M: Brett Creeley M: drivers@pensando.io L: netdev@vger.kernel.org S: Supported -F: Documentation/networking/device_drivers/ethernet/pensando/ionic.rst +F: Documentation/networking/device_drivers/ethernet/pensando/ F: drivers/net/ethernet/pensando/ +F: include/linux/pds/ PER-CPU MEMORY ALLOCATOR M: Dennis Zhou diff --git a/drivers/net/ethernet/pensando/Kconfig b/drivers/net/ethernet/pensando/Kconfig index 3f7519e435b8..d9e8973d54f6 100644 --- a/drivers/net/ethernet/pensando/Kconfig +++ b/drivers/net/ethernet/pensando/Kconfig @@ -17,6 +17,18 @@ config NET_VENDOR_PENSANDO if NET_VENDOR_PENSANDO +config PDS_CORE + tristate "Pensando Data Systems Core Device Support" + depends on 64BIT && PCI + help + This enables the support for the Pensando Core device family of + adapters. More specific information on this driver can be + found in + . + + To compile this driver as a module, choose M here. The module + will be called pds_core. + config IONIC tristate "Pensando Ethernet IONIC Support" depends on 64BIT && PCI