From patchwork Tue Apr 19 14:54:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12818656 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 82B0AC433FE for ; Tue, 19 Apr 2022 14:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353696AbiDSO6V (ORCPT ); Tue, 19 Apr 2022 10:58:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353639AbiDSO57 (ORCPT ); Tue, 19 Apr 2022 10:57:59 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2084.outbound.protection.outlook.com [40.107.236.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C9AB22521 for ; Tue, 19 Apr 2022 07:55:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V4+g0/m2/Ecj+UQO2SGkfWePGbGiRzRf67+qd17WLS/XEOzytNf1JZtZ65t34LCQvf9faNKVWlK8xd1leoS/+zehf85cEKWRIav5Oa2X4lL2sRS9kIRurigLZEr4Nrwp7KgGmdPnPJteHvVv6xl0Q5KE84SVjipdVxwn+C6B5tU6hzOPv47bGJ1GbJl02+HG31mZFaW5cvfpagSdvpAzwPx6BROZCDikyCO7OdZ+u6x4hIQArjSOCXIcrf1at6z7P+UUDzeqvVi0fMHwBN862uSJSBDs5dTSge4DpkGsOgZx8wrUSXHDuFOYE0Ls/LBFR5gF9JOpl4S9klAP+UClGg== 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=YuQpOqFfZ1mE3+MiAjpqKm2iL417tDv5io2oJBWwC7s=; b=M4E8rmjmPX+u6MYDNemJJb92XqmR7l713cNUr3iLGErUQPOfIV8sT5XuBke10yRKa/LYBgxc+NvU4ForFDo0x6oSXyhlK+U7YdMcB9mStJzaWSMu+d/c4nLkcGFngeW1Hj1qofMXLC7TllV4Bel9pMRr82C2/XB8vR9AgCIXkrtD3mFj9Vc5heBlBm9hj22PJU5uBFGf1AfnYDffhkSNX/V+804YQkatUWYtrjKg0yn5tGk9WPJMBMom2UEMACyDyiV+5tCSImWqPsEjV7NnNfPgqQTv3aj3X06NeimjfXu0xxOCLvjn4U57CtmWZ9rdDh8cBHbsdkblHeRzaTGraw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YuQpOqFfZ1mE3+MiAjpqKm2iL417tDv5io2oJBWwC7s=; b=OwQXZMf8hP2WJYJnfsR1bVJDeD8Wq7is4UK7tfw9LzYoy5W4JJpIKGP4oUBC/8gUuv415xKJIEonSVpSA5xBimrVRkmIVCX3wm0udqAgBi/EHufadde8BAlTTI8QjK2eKLKYc+W6vGjcFzT4XTwxXXlhbmaiPH8qPNNEfeADTLfOD6xbUYdJ0AzwJweyhLxhEYbd833OVN+BOjsFScW3Km7crnUfyXg8Io2kY3YgC3pjtIP8rZhD8qdutMZ4vauC8mXZSUDSPWaDw27d1OVTzslkMP6zOF6Tats/Rr08hzqV/UuOsHB2N85s/s5bIg6iFIuWEfagn7pgPjQ/HRvJvw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) by MWHPR12MB1216.namprd12.prod.outlook.com (2603:10b6:300:10::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.25; Tue, 19 Apr 2022 14:55:14 +0000 Received: from MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d]) by MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d%2]) with mapi id 15.20.5186.013; Tue, 19 Apr 2022 14:55:14 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, petrm@nvidia.com, jiri@nvidia.com, vadimp@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 1/6] mlxsw: core_linecards: Introduce ops for linecards status change tracking Date: Tue, 19 Apr 2022 17:54:26 +0300 Message-Id: <20220419145431.2991382-2-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220419145431.2991382-1-idosch@nvidia.com> References: <20220419145431.2991382-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR07CA0215.eurprd07.prod.outlook.com (2603:10a6:802:58::18) To MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2e589d91-4613-4961-0350-08da22149c02 X-MS-TrafficTypeDiagnostic: MWHPR12MB1216:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fBlYGcM3qOQT1e0pe9KB8HFU6lZayDJHehSP0uAKPMTjOCK/PXth4VvGyA78p/a+BW8SeRih2FD+rhuGos+fjU3bJWshoufQryiYGy/rbe8kNPfNyj1IYkWcyacOoCvQnoNsB/aR94wLY44KtwRbTa+rxUl+ZQI1eRvP0NkNbCQNnDXVFvSqcR1rOYK7RF1yltn+nMmchBrU0puDk4iUZAAVlhlK/QP5HNltoEBztCiQ+4TeGpwrgZeMurNIdbb+gOjOxYBRUlo13dbfJjuGXMfVm7kpPDNAwJN3byMI+8Y61kK2OTp3OAWAqrAbk7OXpybehkUH3oZKb47/6scEEMvfJ7d4hvUKioB3kVu6KPu8y18VXEKfM/6GaTexL1f/EX+4iJsGj3yNutr3Q+smMoIswo5GWrTE0ff6zOvuJKK5sFl4IA0vZy/2xJrGtgO3XBKQSFg/fkp9Mt386gr3Hem+QN0qoG6QMOIaJXFW2VamNyYHWrz0aLpYwz41t1hifVMKtZvuT5tmPiU7UKZqaeMSA7Tw4xJ8SXQ6gcXK9FSKoCNT3kfmAUiEL66HTWnL2mp2DAMY2fgn1TJbchlSo32Szi+alXrpmwDpKAuCfvkGsG3s0m5A52zgovLO+gkRv8BPOKKzSUUZXDsfGnugBg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR12MB4347.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(508600001)(66946007)(66476007)(8936002)(6486002)(66556008)(6666004)(2906002)(6506007)(6512007)(316002)(86362001)(2616005)(5660300002)(36756003)(1076003)(8676002)(4326008)(38100700002)(83380400001)(6916009)(107886003)(26005)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5e2nO3+fKN0Y+x9vFibXpvspQUGBvwm+w3ip8JeHDx8J0Lru5HCuCdhuyJIhU0gPX+u+SsESUnHKbhxzmCOiu5fekpkojsYRbJOx+cXVjNvoijcC9Uh0iZkqg/hn2DINOct/JYXJbqoyFBbQxasI4GJsZccz+N+jCZNZwNzXN9xd2u4DDRkdaTsbNwGfTPQSWJdJxtNJgIzXLEKo588mc953HYvqr2NiV5MlUlw7smsE0qQtacwbxpdrGRGaBBJc70nA65Dpz2/G83NOrrhK7MxjhCyLM2hFCRueB4+fRXGx9XzvyXTdxchRRvHk++2UQECpCBy0Q2kAByuPl46eFQ5HFG6ej+dLv1Cm5zGUykYwKuNYgDTZQMTEnRVi4EnoeeyVPUTkEeabAmkCkNfH9oRL5/3FC8/7hBwCv1uHES8kA6G6zP2KOLHMIdmY/BqOYLZnd0twBKRlp+ZA6K+ankOi3g6fdWDCz8VNePbipHpWdQCcLmkcYa/x8BgsS/afI/3aqhG9aH42dfk9eBkSBz2aabNzevUU5F/LcwDZKdR6ClamfCML5Wj0WsTnYdV/FfkY8Eird2Ggb8ldjhrz5fvQzlJgXIRmOOnW9Nzjzf5J/WemwxoR1AkD93//v8Emj9cDQ0hDrnmxUweMEE4zqg0CnktCH7kCUIxJ+f8PES59DBUOtYlAc6cFtBuKostHozNi6PMYr11MsfuPpRcs6hLB0tugANQ2nB0t1ravIy6BM8R049TL4c6+4Uo8Q/BSEiEZVTJa419tjTf8cO5uTsgfi5hI2nq5cW2Lj2MMDsRq9VvLUPdtyYk3HoVcPZaE3u6tT1ogaZ5ve1y4O8ffsx2b6GI/8ETKsA1AGffFzBMPA6EjiyoCOR7ILhg2gnxF7V5mXuCv/Twm2u+D8u4524FH5z86ZDqe2TwQETwjy2dHAECEulUBdAoQR6Lo01ZLbVe+uvSAnm2aPhWTSH4Z8FGG0LuYWkfNnM8ptAYegClOjFOvs6fghWE1SIS+LqHruksv7MzpBLzR2LYC4W9OV0K0Apc1WT4FnbxTugffxpCuRvlQffjy6zxU9g6jLX5m8Qr3u57gr+ofCv9rHnZVC+I50zO9R16Pep8hDgjLkqQnsIwlNz2XwOEYJcBS0esJBv8iRl1E8uYHZ8zHnaDyjxf504eyNztrP15FWj/VcrycMETXL/h8WtQ/VRqBP7DEME/RIWezl1pAwJDlSC6tpXil9YYxi8obb6n3S3VIQtiGY2AKKqF6xLFmUHjLayyD/EqV5B1LtQnwYp8i5NFbgh70iVR9YcCuSFLbIDvuuOjn6OhQRmrTjWChQVABR3s57CEY+7INSjzI1BXmaDGHXVv8b7CHb1dV1/33wJJgh+M53T9Rd9iJ1/yHO35nMsAS5IdM+w1eGrsHGgDVrs/GWFTtGf5yyqXb4jSikwShbJgw6iAeQQBSemftNmj7XKkd2rOfZN4sRKmANrVvgg2MFGZayGzn9PfdEV0eJDmA8M+cpztyDbcETs84G75bjr8p5W2ufCyyK2O35h/huhQXW4bYWN5XWMHw0iSQOGU57+yehfPzKYpLnpWL0BntVHCSIBCW8Ua4AVXmmxbYqrHd667OZD3NROYDDIujvqJa+SI2QDPKsuSr+aD9e4iF5EZun54/D7uj3aURz/UtZwoQhRY0+BTRwIHUsLn2Su2xmbfLD13bgqhRu9pCEK4LYafXGoZHL1y7AbIO1qQJ99mQJQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e589d91-4613-4961-0350-08da22149c02 X-MS-Exchange-CrossTenant-AuthSource: MW3PR12MB4347.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 14:55:14.0133 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: loigrt4ptkydweL38SXB2w3lpk/z15T+dlGZcGqORdyaBdK10bNIoY/NkCojOghhk2wjn12Tzgwgc2XSnuNHWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1216 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Introduce an infrastructure allowing users to register a set of operations which are to be called whenever a line card gets active/inactive. Signed-off-by: Jiri Pirko Signed-off-by: Vadim Pasternak Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/core.h | 17 +++ .../ethernet/mellanox/mlxsw/core_linecards.c | 137 ++++++++++++++++++ 2 files changed, 154 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h index 850fff51b79f..c2a891287047 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core.h @@ -590,6 +590,8 @@ struct mlxsw_linecards { const struct mlxsw_bus_info *bus_info; u8 count; struct mlxsw_linecard_types_info *types_info; + struct list_head event_ops_list; + struct mutex event_ops_list_lock; /* Locks accesses to event ops list */ struct mlxsw_linecard linecards[]; }; @@ -603,4 +605,19 @@ int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core, const struct mlxsw_bus_info *bus_info); void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core); +typedef void mlxsw_linecards_event_op_t(struct mlxsw_core *mlxsw_core, + u8 slot_index, void *priv); + +struct mlxsw_linecards_event_ops { + mlxsw_linecards_event_op_t *got_active; + mlxsw_linecards_event_op_t *got_inactive; +}; + +int mlxsw_linecards_event_ops_register(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards_event_ops *ops, + void *priv); +void mlxsw_linecards_event_ops_unregister(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards_event_ops *ops, + void *priv); + #endif diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c index 1d50bfe67156..90e487cc2e2a 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c @@ -95,6 +95,137 @@ static void mlxsw_linecard_provision_fail(struct mlxsw_linecard *linecard) devlink_linecard_provision_fail(linecard->devlink_linecard); } +struct mlxsw_linecards_event_ops_item { + struct list_head list; + const struct mlxsw_linecards_event_ops *event_ops; + void *priv; +}; + +static void +mlxsw_linecard_event_op_call(struct mlxsw_linecard *linecard, + mlxsw_linecards_event_op_t *op, void *priv) +{ + struct mlxsw_core *mlxsw_core = linecard->linecards->mlxsw_core; + + if (!op) + return; + op(mlxsw_core, linecard->slot_index, priv); +} + +static void +mlxsw_linecard_active_ops_call(struct mlxsw_linecard *linecard) +{ + struct mlxsw_linecards *linecards = linecard->linecards; + struct mlxsw_linecards_event_ops_item *item; + + mutex_lock(&linecards->event_ops_list_lock); + list_for_each_entry(item, &linecards->event_ops_list, list) + mlxsw_linecard_event_op_call(linecard, + item->event_ops->got_active, + item->priv); + mutex_unlock(&linecards->event_ops_list_lock); +} + +static void +mlxsw_linecard_inactive_ops_call(struct mlxsw_linecard *linecard) +{ + struct mlxsw_linecards *linecards = linecard->linecards; + struct mlxsw_linecards_event_ops_item *item; + + mutex_lock(&linecards->event_ops_list_lock); + list_for_each_entry(item, &linecards->event_ops_list, list) + mlxsw_linecard_event_op_call(linecard, + item->event_ops->got_inactive, + item->priv); + mutex_unlock(&linecards->event_ops_list_lock); +} + +static void +mlxsw_linecards_event_ops_register_call(struct mlxsw_linecards *linecards, + const struct mlxsw_linecards_event_ops_item *item) +{ + struct mlxsw_linecard *linecard; + int i; + + for (i = 0; i < linecards->count; i++) { + linecard = mlxsw_linecard_get(linecards, i + 1); + mutex_lock(&linecard->lock); + if (linecard->active) + mlxsw_linecard_event_op_call(linecard, + item->event_ops->got_active, + item->priv); + mutex_unlock(&linecard->lock); + } +} + +static void +mlxsw_linecards_event_ops_unregister_call(struct mlxsw_linecards *linecards, + const struct mlxsw_linecards_event_ops_item *item) +{ + struct mlxsw_linecard *linecard; + int i; + + for (i = 0; i < linecards->count; i++) { + linecard = mlxsw_linecard_get(linecards, i + 1); + mutex_lock(&linecard->lock); + if (linecard->active) + mlxsw_linecard_event_op_call(linecard, + item->event_ops->got_inactive, + item->priv); + mutex_unlock(&linecard->lock); + } +} + +int mlxsw_linecards_event_ops_register(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards_event_ops *ops, + void *priv) +{ + struct mlxsw_linecards *linecards = mlxsw_core_linecards(mlxsw_core); + struct mlxsw_linecards_event_ops_item *item; + + if (!linecards) + return 0; + item = kzalloc(sizeof(*item), GFP_KERNEL); + if (!item) + return -ENOMEM; + item->event_ops = ops; + item->priv = priv; + + mutex_lock(&linecards->event_ops_list_lock); + list_add_tail(&item->list, &linecards->event_ops_list); + mutex_unlock(&linecards->event_ops_list_lock); + mlxsw_linecards_event_ops_register_call(linecards, item); + return 0; +} +EXPORT_SYMBOL(mlxsw_linecards_event_ops_register); + +void mlxsw_linecards_event_ops_unregister(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards_event_ops *ops, + void *priv) +{ + struct mlxsw_linecards *linecards = mlxsw_core_linecards(mlxsw_core); + struct mlxsw_linecards_event_ops_item *item, *tmp; + bool found = false; + + if (!linecards) + return; + mutex_lock(&linecards->event_ops_list_lock); + list_for_each_entry_safe(item, tmp, &linecards->event_ops_list, list) { + if (item->event_ops == ops && item->priv == priv) { + list_del(&item->list); + found = true; + break; + } + } + mutex_unlock(&linecards->event_ops_list_lock); + + if (!found) + return; + mlxsw_linecards_event_ops_unregister_call(linecards, item); + kfree(item); +} +EXPORT_SYMBOL(mlxsw_linecards_event_ops_unregister); + static int mlxsw_linecard_provision_set(struct mlxsw_linecard *linecard, u8 card_type, u16 hw_revision, u16 ini_version) @@ -163,12 +294,14 @@ static int mlxsw_linecard_ready_clear(struct mlxsw_linecard *linecard) static void mlxsw_linecard_active_set(struct mlxsw_linecard *linecard) { + mlxsw_linecard_active_ops_call(linecard); linecard->active = true; devlink_linecard_activate(linecard->devlink_linecard); } static void mlxsw_linecard_active_clear(struct mlxsw_linecard *linecard) { + mlxsw_linecard_inactive_ops_call(linecard); linecard->active = false; devlink_linecard_deactivate(linecard->devlink_linecard); } @@ -954,6 +1087,8 @@ int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core, linecards->count = slot_count; linecards->mlxsw_core = mlxsw_core; linecards->bus_info = bus_info; + INIT_LIST_HEAD(&linecards->event_ops_list); + mutex_init(&linecards->event_ops_list_lock); err = mlxsw_linecard_types_init(mlxsw_core, linecards); if (err) @@ -1001,5 +1136,7 @@ void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core) ARRAY_SIZE(mlxsw_linecard_listener), mlxsw_core); mlxsw_linecard_types_fini(linecards); + mutex_destroy(&linecards->event_ops_list_lock); + WARN_ON(!list_empty(&linecards->event_ops_list)); vfree(linecards); } From patchwork Tue Apr 19 14:54:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12818657 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 92F46C433EF for ; Tue, 19 Apr 2022 14:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349148AbiDSO6W (ORCPT ); Tue, 19 Apr 2022 10:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353674AbiDSO6G (ORCPT ); Tue, 19 Apr 2022 10:58:06 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2046.outbound.protection.outlook.com [40.107.223.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1CAE28985 for ; Tue, 19 Apr 2022 07:55:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nUtbFfEkOY6PiXkYLGT1iaKLOT1dSTH3TWCd4CStojhTnt4wIBxMTiMlMy5Siak13vJS87r+OEjc5Bhdu0zrRIl6PiqGM0dtlFkUtFxqgFVPyW8IOQeuTCO0Lnaj2Pdn3NxPhKaQ3ua2AtvPSDqNuZWrlfQhD174Uu4zqthmz/Es0pj/hgLvuNezUr48qxM4d6kCvwBRtBhLdR1uTZ6mV50QkfvwjPdKSYIPxc3OxlEduy7OEYHaj2Zkiq/lmed14JizA6D4EaIdKNlFn50DRp4h/jb/X86nQzax9f1gP70UwLnLaDm4C1WR7tAy1y+GRj4/3lGxo/Y7ftYYp+jgLA== 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=aK1jhz+plEhSunE7gzcEfLaHF6dJQu88NdaixHG+Ei4=; b=Qhb22Bdw4VdSFsyNNUCUljqqoiHHj3T4uGfZ9lZOd+Ng/2ltoC7Bg8RT+/KiKYf9+kyt+ZY3EWgTkizlD2aESVz3K5nshXFwSIMotk7ZjZdR7wl7AnXLOfu3vWh625W57PHjBrCeyLxWvt6W0QcnQrZbjykthhOMLECWdsMWfKL6AoLL3nYTJkszTLjgiTdnthBNNTp8oZZJi8Okwb4WLfnKZ+IV7qqgr48OCM7RcgtYKFFv1ldBv7q2LSvVJjP5+I0ijs/q8AYyRKFYMpZBPgiOaXB7stUgLD0iHciRL2BFAgu2giwVoCsv3T8VkaIUDJu35sBQVqvUD9rtvFH9bQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aK1jhz+plEhSunE7gzcEfLaHF6dJQu88NdaixHG+Ei4=; b=eNIZaV367SxkejWPIlHIycHw+NUbelmwQ0n6x/e91DDF65eWysi378QDD2KLw4YzBNFJjUMfE8J9RBGFNDQs4n05E2WitKh+ZJBwQ/+vWcF6XtfOVWz/rpUySGW4jvtpBC8nBIooGu1JeyoWjtTisTXqz/2uPgq5hxtr88N11RR/rIoMGZ4SRQ2BVMN/+SqrRxFNs1Vg6btz0e6F58dexVSYfJtv4tMOwCh6tKjVXuqSNnhOXHTTzX5VnIF7RlwlXE4dhZEyfm+0x3d3g4/iRugSt0pTHAj8u5YF4HCHQxF8mKEDHwPRhHf+4MkPZ1++BWwZUkJ40vAdacH099MbHg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) by BN6PR12MB1378.namprd12.prod.outlook.com (2603:10b6:404:1e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Tue, 19 Apr 2022 14:55:21 +0000 Received: from MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d]) by MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d%2]) with mapi id 15.20.5186.013; Tue, 19 Apr 2022 14:55:20 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, petrm@nvidia.com, jiri@nvidia.com, vadimp@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 2/6] mlxsw: core: Add bus argument to environment init API Date: Tue, 19 Apr 2022 17:54:27 +0300 Message-Id: <20220419145431.2991382-3-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220419145431.2991382-1-idosch@nvidia.com> References: <20220419145431.2991382-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0202CA0027.eurprd02.prod.outlook.com (2603:10a6:803:14::40) To MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 456dbfdf-27d8-4dbd-153c-08da2214a008 X-MS-TrafficTypeDiagnostic: BN6PR12MB1378:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7fkht7Y1300pZJbjc5z1qEtuijsxGU5SafLvM8wV5Nn1V1NLqbff28OJLxRi4RiSlf6l8XOYyQfAUFknsfUgGB2sT3wVsDYnOtTmfTnPJpnJFzkuPgIH2YBc3m9Utd+SwRz8+KJBff03Y2rT7JNH3bTrtlNP8sj9QvuawAHBeUmsr98nK2Mpju7EOu30LsznmvKpLqtDMSzzOQefonnXC2bvvIc7GsU8w9ao/wu8yOWXDa/GDnBNCXUJOG6R5yttHEmU88LTZx+wskp3M2dAqAaGpFlLELAIsZPpcfGlNqcxuDdEZdSb6GMhMZPrSEq7BgHT19d1UQrqbXFvkobX0Go1WHS79gevvEYsF4ivH+OPq9HOeO0VEltOSIsQsqphPudyFqfWHbQDYCnATbSnbqsD5iLUncrdCwFUfW1eq5Pci4JC2Wh9xNnD1GL0LHY0gD5TFv5iC/fIaOeH9KyD7WExqErFLJ2Vq6StVtarO0GMY46HBY7EUF5dOaPvPop6ghXHKHBvYRXXOGsK7yeIwwGuFvIaTB5HPK2hz3BKdTOAXgvq8gjYIhWgyntPVE1bYFY1kgCOojxoMw5Z46RvPLvCqE7j/CP449fCsInGrlVkIP2uhFQDqkvNH9881WJycJEHnpDOf9lcMfxTXDTz/Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR12MB4347.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(86362001)(38100700002)(6486002)(508600001)(8936002)(5660300002)(316002)(26005)(6512007)(8676002)(4326008)(66946007)(66556008)(83380400001)(186003)(66476007)(2906002)(6506007)(6916009)(2616005)(1076003)(107886003)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G67NqUmckoD9BPmTFrE/qvY0QeS6IfW4Is4TxWTOANyuWOE0v6250scCXVkVCbAZ37E4BBmjZ3IY0eoZ4eLN2obGfmeja3Idn5u9u3RGTzxFJnRlEDDcNTDEwKEW88O9tUyY3fXmrqu6rYn1OBtMsZoO8Fdqsb0y11jLB48iLcjISGynMjaF2TiN0Z9HHdyZ3f3K2MYc5A//moVVj+jzM+1F8QvBLPz6N1H1+wnfAKGPLDf4b3hytfle3NP9l7kaTcr32eMjt41fjjuO8HNDMzRik7ja5Ako/Wgs/lxKTypyX0za+j5Hq4Fc/ohAE8chHuu/EhL/Nw1yKUsz6y5C8ksDjr5NwCrF0RgclOfkHOHpHqVPQPbsEXP6hMfG2QQ48Ktg+zc8GyOdvvv+qCm4TFeKBg1dgh49RWS+dvAz9gT05IuKFSbhaxxpDF7OCdpijcl8MMlcI2XvT3QHhOIffLJcml3o+GeNfOd3kLmRjcpflWgRiwB9bh9iqs8vBSKrcp/L6h7vp9aJ5s2KA4vtmOT8uhtza1O539+DShzSfSCmzeZRatcDLd6n78tNz6VhujQBlIfug4EeSNEhhCTwPIjEjSjs/169iDwboAv+wduCxoiB08q6sWLDt9EeLbXwWncKNb2g7+VfXduTIYYwjhUDSu/51yyUJQ2cLb19IqJ0ganw53EbvpAG0WVLsoqRn8jS25pIwggJASVEwv7Cx8JrqKs3jO830ZurOsoIGKawA5RSgq99Qz98QHPUCKs8+RWRX34lxk7mpvQcNq/tZoZGeLJp9VOG/ywpLaktMqGfS3aqUWdTVkVHpw2t97YG/pyyujtKq2K89+cimCoOmPq9SoBOwaQ7L2o5qNLcn1XgFdLE0nWhA57YVbCJtWXzBi5VM4XM546QOuF8XNPblV8uCUi8NL70Zr++EE5xHEm3/Rt2HvaHE2jLGUXnTlhtvFMSMOGy+83V7rqoAS3R/YmOMhqGm+qL1vGhXBfT2Zibgelmg55N8OOxaIom6F9nfzTNI0cqQhB5psSjxFRzcXv1Wri8E1tNSa0pdDWGVrZXOyK6QNMQ2l6YIrjILPY8363GiThW8BHKF4xY3CpFC2IiXAoybTIu0hll0NULdrEqtAcOY0CNSzFf/z+DfPPjgWCbpyKeHBwtjDdrHnjFmJ3JnCxNUoj9zNfSoEG7egzq7hNdvwIyrH9H1MZ3HnfpvIdthwPD6n5jtFq1tFu0EFELvZ0NUHMT5bOp0YQnhLb5JOztBeCB+yER9u85I9F2B9aHUyBZBrKZb2w4rurrcMmnyKDlawVcafiZXff22p6cFm+YamjvCOVKDbExoxf+HeFrl3IikOR2NbSnH2mS7NVTWVVO1TUnQ8BRMtiDqfY/vD2dcIwZJBx0SdYM43HSJFAzNwScqlZV2sv7hjeo0u4Mx7nwEA9yDoVLq8ieY0oJsUhuBXChSadJkdMLSgxzkGaJerfFluG943Jrotu9K/4wvsoz/EtlrxPqnXoWOzcaN/D5P0eQWqx3Bnee+A9sYLGJ0eaWcB8kKy9XCUv5AwUwPFK2/uGbLiMWNtzPv/7HgiJu5EdSWTOqfm/AAT/8cAxrpqaL8tpntOnWv63CknKJJms5LzZ8AH7ECXcwcrVVTKgbWXyNjTPcccVaklKCb9JezoKLJ3SnZl/qMDo5Rv9l6gU4DCouYnXeSOG9ET46w1Un3YPm49RX/GwRbGYgVzSNoCTc1OGm5i8Jze+oFg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 456dbfdf-27d8-4dbd-153c-08da2214a008 X-MS-Exchange-CrossTenant-AuthSource: MW3PR12MB4347.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 14:55:20.7795 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Sm9xKPcUu3daGyPVA7X2f4aC63f5G5l/NKObIJ960ItWvINcEGjiSxdfrZu02cSvHvRUnENKmm/O1wqUfsfudg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1378 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vadim Pasternak Pass bus argument to mlxsw_env_init(). The purpose is to get access to device handle, which is to be provided to error message in case of line card activation failure. Signed-off-by: Vadim Pasternak Reviewed-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/core.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/core_env.c | 6 +++++- drivers/net/ethernet/mellanox/mlxsw/core_env.h | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index 0e92dd91eca4..fc52832241b3 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -2175,7 +2175,7 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, if (err) goto err_thermal_init; - err = mlxsw_env_init(mlxsw_core, &mlxsw_core->env); + err = mlxsw_env_init(mlxsw_core, mlxsw_bus_info, &mlxsw_core->env); if (err) goto err_env_init; diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.c b/drivers/net/ethernet/mellanox/mlxsw/core_env.c index b3b8a9015cd6..abb54177485c 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_env.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.c @@ -28,6 +28,7 @@ struct mlxsw_env_line_card { struct mlxsw_env { struct mlxsw_core *core; + const struct mlxsw_bus_info *bus_info; u8 max_module_count; /* Maximum number of modules per-slot. */ u8 num_of_slots; /* Including the main board. */ struct mutex line_cards_lock; /* Protects line cards. */ @@ -1194,7 +1195,9 @@ mlxsw_env_module_type_set(struct mlxsw_core *mlxsw_core, u8 slot_index) return 0; } -int mlxsw_env_init(struct mlxsw_core *mlxsw_core, struct mlxsw_env **p_env) +int mlxsw_env_init(struct mlxsw_core *mlxsw_core, + const struct mlxsw_bus_info *bus_info, + struct mlxsw_env **p_env) { u8 module_count, num_of_slots, max_module_count; char mgpir_pl[MLXSW_REG_MGPIR_LEN]; @@ -1221,6 +1224,7 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core, struct mlxsw_env **p_env) return -ENOMEM; env->core = mlxsw_core; + env->bus_info = bus_info; env->num_of_slots = num_of_slots + 1; env->max_module_count = max_module_count; err = mlxsw_env_line_cards_alloc(env); diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.h b/drivers/net/ethernet/mellanox/mlxsw/core_env.h index 6b494c64a4d7..a197e3ae069c 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_env.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.h @@ -60,7 +60,9 @@ int mlxsw_env_module_port_up(struct mlxsw_core *mlxsw_core, u8 slot_index, void mlxsw_env_module_port_down(struct mlxsw_core *mlxsw_core, u8 slot_index, u8 module); -int mlxsw_env_init(struct mlxsw_core *core, struct mlxsw_env **p_env); +int mlxsw_env_init(struct mlxsw_core *core, + const struct mlxsw_bus_info *bus_info, + struct mlxsw_env **p_env); void mlxsw_env_fini(struct mlxsw_env *env); #endif From patchwork Tue Apr 19 14:54:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12818659 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 88167C433F5 for ; Tue, 19 Apr 2022 14:56:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344346AbiDSO6q (ORCPT ); Tue, 19 Apr 2022 10:58:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345537AbiDSO6L (ORCPT ); Tue, 19 Apr 2022 10:58:11 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2049.outbound.protection.outlook.com [40.107.223.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A3332B18F for ; Tue, 19 Apr 2022 07:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LndxSzjgypgo3BLkz5SAvPxXKDB7+GBXjUhHM+Aa5neO479WK5DUL1rRunS0tSGPU0WJgbzt9Xs7QWQAtpud4bumwrOdNKXSoQVS9NQErynFSlKeF1wFqAFs4biwt15+kGFJxw6ayiUYbGDGC87h6hw5E5tqOPmJZOYTvlVxnkZ2KfAgoOl58Iy1sPxqd0kSIGhkuHVCUU8fnC/VwKffpUKVtRIpFEqPkEHzNdtG/ogfeD3zkScMkj1/ic4J4ZIoFmeo/RlRI5G6tj6NE35MDkYfxPWfkM1QrtMWQwNQAXfUBrppkIRoqV1IUrZ/Vri8Puyf9R3Y3R+VwieiOnrj3g== 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=RSeG+9ZUpsM8RNgrsINGSocUUTzfLVC2YVttiCyhcY0=; b=luvRVGLPq+JW8DdqLQKN4ywUMbzUAzo+/knStaD4GR8l0Nad+ql7WNuHBy38ulmrnMq1QXyGgpfEwXEe35l1mDZyeuuebTVdMxv/JQhFHsbyDIV0/xQH4EdNI8RLprPie4eT3wvF7nPfhogzWiFLko3/604mnxyH6/EF/iV54FhCG+hNlX3j0xBx55s2P7RipHc7Hk70WGvN1KJWBi/usTEixc9GDkDFHTPOn+oo1Xdl4oSAvW+hAt4BaXQ4mhDm7b1qFRQvybq/kBFetxhpQOQLViyQcIWmgfwUbMEPTUx7PgPMM6hROXeEYenMO40/fo4IyoWATU6wWJZost2eQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RSeG+9ZUpsM8RNgrsINGSocUUTzfLVC2YVttiCyhcY0=; b=qLr/4l1iOd6di+thcTGYh0WPClLraS8kYdnI0Fjba+2+a42m4GRDktJnuo87QFdRZr5cug115PYgaWBPO/eq3CJQUgkwY6iQSFCGhkpg3qWXzndiFOaBW5gDrLDw/lOXAj3bDxRKhHJIDodIb4NzYKe8oah4r1tOP6F0KV7sEHhhkY0KcKoEO79cXXt88HTIIjUsFtBKSURM+yg9P7C+MYxBCD5HdIYtrSTBWJO02riDhaWcqD6pYRXIq0mobUnw6aTo2ho1Uj7WURRC6z1RAwcc6JOo+v+J1xNHol/hpkJEIzj7K0JHmQ6fTtc3f3hsh/S/Ph4aYr3K5Yf+Yyf0WA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) by BN6PR12MB1378.namprd12.prod.outlook.com (2603:10b6:404:1e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Tue, 19 Apr 2022 14:55:26 +0000 Received: from MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d]) by MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d%2]) with mapi id 15.20.5186.013; Tue, 19 Apr 2022 14:55:26 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, petrm@nvidia.com, jiri@nvidia.com, vadimp@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 3/6] mlxsw: core_env: Split module power mode setting to a separate function Date: Tue, 19 Apr 2022 17:54:28 +0300 Message-Id: <20220419145431.2991382-4-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220419145431.2991382-1-idosch@nvidia.com> References: <20220419145431.2991382-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR08CA0222.eurprd08.prod.outlook.com (2603:10a6:802:15::31) To MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 050e8050-0c5b-4b98-0cc8-08da2214a363 X-MS-TrafficTypeDiagnostic: BN6PR12MB1378:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Er9+6RBECRJH9wDIEONsC90no4yTW+8Gze0MZ0WqQD39qsWPcFMQBaaTIVJN2FN7g9mITHVMcaWafoyMKNe8GGJ423x6qSqrGGLQ38wR8Qmovk0TkOcjWAHu7FSueS3WN99RHKAfZFnE/VABm8nHJCezrRjYR2whg8zkTmWiu7mjYlyJUw8kTgOQQcBSMAiIsSRkGvZWOGeF5mngJWOYuiogRC1d/L4e/uCyIcyasoh+R8FPZkXU6D0E6HPk4hpzz4zNoCNOzDMOIX797wHros2OczcQ3A63jaEZbFFmfK6KfotrZh6Em+nbeGM/Z8xO9kt1c2dGsff+TcQlAKvAVjzbNBXOj5l7uIuxvJ/EOEmCN6J8hvtbL9fjkBRqXsPOWlsK98xc3AYLiceuCE8dG1x6uS1x6NCokTCogWTB1UfrxbCW7hZStei37B3vZgsC7+617YbZnpCay7ILmJq5NPU81qCuKee5yCR8SbK1sPZ4rRD4MS1UDEtsVoG2jH7c8Tnm9YzmSjNl8+3VKCr3rNYmqeg97d9DXOWtxZJilVsyTgW0T83lUOor7PqHGavxkzZOQgjqgQUSZ2W4UtMwdELcfHCV6V75GAKuvBBorD58V8mxszzrWyj2q2imgh3JHDQP4WSF++k9ZCGxTEAeUw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR12MB4347.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(86362001)(38100700002)(6486002)(508600001)(8936002)(5660300002)(316002)(26005)(6512007)(8676002)(4326008)(66946007)(66556008)(83380400001)(186003)(66476007)(2906002)(6506007)(6916009)(2616005)(1076003)(107886003)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: coMbJexW9hGpzJPoiQ8Lo/LBP6oF2RsaPJurUNl7TADL3TLvMM4K8h4tbYvWQFg2j0Zi2gC3LxgE7E17FArqt0HO+Z3Vru1M8GI/WfnqV7MEhcv6/jI474vDZTwOgauVlj896+L5Ie8uQDCfV6E8Vwt1d5ZSGZXUWRhc62TW/sem8ZlJFXhTxYrUN0JzaV5Hq2xk2XXQNJ/iP/1RZmcbw95aMQQM9XayHMLyoj6nrmQiEIsWaM/FrpBB2B3ytQgCEp/rvD7BS/YxhH07wKheCP1ljMG0EeDAWGhqGlKEJahZVIEeM/h//em8uMlKFqMdseVkkXjK0wUa3AAcMR1fjY2n2AHfOYvM7d6aEOlmeK6Bs11BZVW7w2SkM+qOIl6n/lrJeCvVSV0+FclP81SLIASs7zV7RNIvAo3MBz7+Sd1V8ji/fXZ0rB6oZ4iS8F0acJucbwHHP9ZuRGzHH0HCP6CmnJStORTo+zq6+necLdPytyRs39pts9gIeGSDTEcngtCR5Mp4oUQq3SCzuKcVdYJv6XZGX+zegPAEiy6XhUGR2CDCjK8qVt9oAboYF8JFtwD3RrgQzLPOmbEFhveF2qRr3LzMTii6ad8iRk5Ew8hgP39R6tMZQEh+E2NQNy7/azV2TE7TtQ+/NCB/NAfVQkhNK3afrprlgvH2DDOieEe+vvtLYZIL/RPiJf6GNddULCcfljzvaVB0+8gc53vNWDhYl18reSE6LFwQebXOEtW65T5vjCdVCqJMBuuNp+IGQV7w3KUS3qFwkuDOOPrnnnQ9xYSNhw27XeY8peiT7l3QXWp3p83YRS/OHAcda3yJcyVk+vzNwLLSjdKBbcoZaX8De+OYJeygeJd+DN2K2LMSYtx1rfHPbYTNNqYRB+IDz6OhMMISAJcEWiULi21Z2MDnnEdQOhZrn828pPJA8T+JHNHgskJA4EoZg9YfQbbWGd6loyqCb+Ip+f36Sqz+cAQgvoEsFCvqNXqHYA1hc+sdqQBXki50pvjCCCMCiWiuQ0C85a9Qxt/7WIxNn3sBOe+zIH4OBFPhej2k7cbSgi+Wz6ItZv8GPOoIkXLEjtuX77NYfgnhQ9x/9y8PPk+2yNCRYT7ocoINwu8p93qZsayqcib/vPL3pdXXPF35cXRnqT+PYst9BzbFENwb0qQhrgJ/5fjKRnzP6bVUy84/zJFF8Xr0Vc9nRRVUalbs4qqceELCKMqFCNuUjLmCi5hsbEjxy+/Hw5NG6IdlMUTNto1n+1B3vRM6f/Ba6hSttoomX0n/siaz+tRkg3320MykFkepmwYicCd9AgyUBveynM27Vc40IHt6ih1DH/eouBZ6C3UUsqft8aNqhxw0Iza/9bapLwz8DwQHPZf89fds5Qx1UiVXp8ZQMQBtOiJ48ii/PWOcTi0J+OaWXEjCl7wbbl2h0DR2hFbS6N6SPBzOeVGti6sR+4vZZi+Q3XY2hroZr58tCcOwQpWLJzAK/WL5AG+PvkCeaEkM6hEOCj9UglIwY2sf8+dA4jzDXHGQd6c+5bv4pl5PGcpUcphaGM+fJUInlvkguhZJSmeUWPf9cfT1lBNPKVsJ8nnhx1jald/KGcMT2R1o1625BW0A972YWVJoT+BZyQUcxZXw4dRmsuc6ku6rP/A3JWAO7T7nhMuoZjGM/8K90QUF42bsH7hfYut7C4zu5aSmDolXi2UvRoFuZJmN6NUGAC6m1dNSkag9G2faTLljM6CX0ETaCa7m7g== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 050e8050-0c5b-4b98-0cc8-08da2214a363 X-MS-Exchange-CrossTenant-AuthSource: MW3PR12MB4347.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 14:55:26.3932 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nCxep65DIsCuXM1k0DPyeyRLtBN2Ras1MfmkaoHrccwozs1kXNfkTfIJOaySZfh6Vj38oYhPfDNShb5jCWAWiQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1378 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vadim Pasternak Move the code that applies the module power mode to the device to a separate function. This function will be invoked by the next patch to set the power mode on transceiver modules found on a line card when the line card becomes active. Signed-off-by: Vadim Pasternak Signed-off-by: Ido Schimmel --- .../net/ethernet/mellanox/mlxsw/core_env.c | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.c b/drivers/net/ethernet/mellanox/mlxsw/core_env.c index abb54177485c..a9b133d6c2fc 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_env.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.c @@ -648,25 +648,16 @@ static int __mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, return err; } -int -mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, u8 slot_index, - u8 module, - enum ethtool_module_power_mode_policy policy, - struct netlink_ext_ack *extack) +static int +mlxsw_env_set_module_power_mode_apply(struct mlxsw_core *mlxsw_core, + u8 slot_index, u8 module, + enum ethtool_module_power_mode_policy policy, + struct netlink_ext_ack *extack) { - struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env_module_info *module_info; bool low_power; int err = 0; - if (policy != ETHTOOL_MODULE_POWER_MODE_POLICY_HIGH && - policy != ETHTOOL_MODULE_POWER_MODE_POLICY_AUTO) { - NL_SET_ERR_MSG_MOD(extack, "Unsupported power mode policy"); - return -EOPNOTSUPP; - } - - mutex_lock(&mlxsw_env->line_cards_lock); - err = __mlxsw_env_validate_module_type(mlxsw_core, slot_index, module); if (err) { NL_SET_ERR_MSG_MOD(extack, @@ -691,7 +682,29 @@ mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, u8 slot_index, out_set_policy: module_info->power_mode_policy = policy; out: + return err; +} + +int +mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, u8 slot_index, + u8 module, + enum ethtool_module_power_mode_policy policy, + struct netlink_ext_ack *extack) +{ + struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); + int err; + + if (policy != ETHTOOL_MODULE_POWER_MODE_POLICY_HIGH && + policy != ETHTOOL_MODULE_POWER_MODE_POLICY_AUTO) { + NL_SET_ERR_MSG_MOD(extack, "Unsupported power mode policy"); + return -EOPNOTSUPP; + } + + mutex_lock(&mlxsw_env->line_cards_lock); + err = mlxsw_env_set_module_power_mode_apply(mlxsw_core, slot_index, + module, policy, extack); mutex_unlock(&mlxsw_env->line_cards_lock); + return err; } EXPORT_SYMBOL(mlxsw_env_set_module_power_mode); From patchwork Tue Apr 19 14:54:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12818658 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 9F073C433EF for ; Tue, 19 Apr 2022 14:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353665AbiDSO6c (ORCPT ); Tue, 19 Apr 2022 10:58:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347205AbiDSO6S (ORCPT ); Tue, 19 Apr 2022 10:58:18 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2052.outbound.protection.outlook.com [40.107.223.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 350342B18F for ; Tue, 19 Apr 2022 07:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b8RYfwP8koIwAL5EEPe4ZNqvSgTTSLSItakndfy7vf6jEXtoUfRPTepFZdG0RtHvvpjyqs4Q+AOVd0ocOBGj3TBV4peKIdEvOvUJ9DhewvfoLEhevUqKOeNzj45IHO2oNWeSGY2arUzNpxvW6UMGVoztBwoWLDS8XLK4Ah3LtlmvlIeDuhtD277fxk+NoTRDvSwQ1iEq8dyEAnLHYUva1+iQAUfyyAxAqYlKY/KYR05gVmtiN4Ep4TirrgOgtOSzbHJBybUecACvrlLVEBXvxx3T0PVpHeDh4QH7wlAc4gRsboUhlwYbzfAHyEaj2NlSFaeauSma9OUmdhrsoZ/KFg== 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=elySh5niHyzK/DzdfXwwe45OttsaQJ5GdIdOyrzQvco=; b=D0rM4arEdCVNdVhGkWallESI0mplzBrGBriBc4Ov1N2cua3NrTzarp1zHjzSoGIJd4jJUv2q8lHsLXgiLm+eD9KOd6vHet546onb/AK3dHN0xMwld5QwgZ+ZO0SagGYgbYxfCB8AM9//v8iW3xAWVt4UiPdrn24a9j5d+ueEbqRJtl8V4zWY4XnX9IQAymMYk7Lh60KYVel0L2fJzvK+VzNqDrt6q29OY2+StS1YDc7VGTg1s+Doq+v3Gttx1CmHRJFJFAQOoflt8rdoakHVO0bPDffe40hNQxAR4GH1PYNyEzyWhsnjhzU2jxxrUbz7YHd0aiAVq4Ix/gIz1sb3Tw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=elySh5niHyzK/DzdfXwwe45OttsaQJ5GdIdOyrzQvco=; b=d9jGOQXQz/P5tbp4ATBfwqa4052F9UR/If9aOn+zX0ggvDemHmHhaSHmgrgCR8R9dI0oJFfEWYZkgQeGS+sG47uoX8tZOpX8ajavYQiPQ7NFZpQGKfHdjIqi52ks+v/Gk0FB9/lIQ9Rumz9pgifGSpjO8AnA3kT1/JxaqAcSAZ8zh7ZSkaWc0409kUms8C9h7iLVxzNljhBzPp38gs9N4zSzmLf1BpKNTAjjFW0iS1GWYOmEYg79mVnq1vLkQhUWrVyq/W4e853mHRXPHDtwFEXewfajMVwTKaELSgi9nRXoCF94sOvvAVAVUQkR8wn2xkIeG5dq+EqwBfGMDbG4sA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) by BN6PR12MB1378.namprd12.prod.outlook.com (2603:10b6:404:1e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Tue, 19 Apr 2022 14:55:33 +0000 Received: from MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d]) by MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d%2]) with mapi id 15.20.5186.013; Tue, 19 Apr 2022 14:55:33 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, petrm@nvidia.com, jiri@nvidia.com, vadimp@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 4/6] mlxsw: core_env: Add interfaces for line card initialization and de-initialization Date: Tue, 19 Apr 2022 17:54:29 +0300 Message-Id: <20220419145431.2991382-5-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220419145431.2991382-1-idosch@nvidia.com> References: <20220419145431.2991382-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0502CA0021.eurprd05.prod.outlook.com (2603:10a6:803:1::34) To MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 226680c1-c8d4-4a44-2af8-08da2214a73d X-MS-TrafficTypeDiagnostic: BN6PR12MB1378:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PV/n2nRcniu5IcLPfftnGFpCX1o/SnTSI8BQKP+uSXUQfS97y6w97pJ61vkiiXri3IOdYbGa6A9pTGSIGKJsr4g7NjId1SR7cxM6oqiEyCquBSVWGallJMK3pL7hsk2Ln6uZCE9oLJUuUkZpwJRYZhQwggJ8iE179rsWY9RZSf5pYClQdRQ3drrK/Sr/HAgmztvqw1gDJxoHtalKKO0hF8+xdkRWhCynS6unfNFbp8CiEMYFrBLKV9lWOfHamd91vob3NThQedatfjwROyd9BZwgqVnUawauZUwR0NxfNv1VHLBBBA3STyfPelMqJJ+lQljsbddR76E1UA/ZZaqZ9LMPoSKCa62b/D1mvtU5UmbOIb5cGvSYYsaDtVsB+R4c6/DyxcjaiYMzvAwRGe+HjohjLMMxNHKvJNoqXjbjrCR13j30H+Gc10vWrQYlqN2WEuz/Zo6+qU7o40F02U3iqMZj3paGuXrPKExFh9R3NJmpIFv4EMMmFV5BGp7eTWTy0eoQnMOktnfLoeUIJd3yrG+5WdL0orRMsBw9u4EoeCaXNbdM8BacR4SaYKSyMJAoMd7UU0XGZedJisc+/AAKEiPl8SxKZK1LLeB63k6CggW4pzvFXCm6MM+pnrfqQx9IKXmi7bfdfVtX9aUbhuE4gA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR12MB4347.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(86362001)(30864003)(38100700002)(6486002)(508600001)(6666004)(8936002)(5660300002)(316002)(26005)(6512007)(8676002)(4326008)(66946007)(66556008)(83380400001)(186003)(66476007)(2906002)(6506007)(6916009)(2616005)(1076003)(107886003)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vUaZ23PYSP1kkM2yVBoxsyhah8KS1kPh14kLzoSZRWmsJxhy4FjazZZ64tKPfhRTF5ufmHRcP1O57Ukwej+Db6RUx1jGm6DJ6K3BJuVFjv6jbrjvNAPWp32hyMb+fAUQc5yr8F0kbxNdpVZWv0v7M9feMCuk8O5tSjgjQrtDCX4QnEo37Uog6EKoK3mtLTnaD8IORGIKq1xNZwXpzhqnC9o3if0rASu+Og7i8aEGdma9/5JTBcQfvr6JKMFPnXDIwWUE8M4LM36XcjpR6yTKjBUzTyJTSa8hCGmHWxVs/SysEbodz9fFy+QAUCTT5+weAIKazeGsTFMLnc8HuFQ19z3stjUGISBb3za+IXRyUBzkNHSe+r7L37Y1zutUKyOZSzxD9xwUcvAUSNDavogVUS/SALdYyJexKQ9PiT1LWXK/1EtF9ouxdFIS3Rq9LHvsZyXCehk9BBW41ce7CXAJ2GPThUXY1iJlo92czhjWP1jgwNLrkWqNrH+wdAhgQ7QpzXH1tMnL8m6FyESW5g77lihhkkcox+P8vAuKs64y1S6Wk1aoJ8JDheWlCoJ17c15hsdmcek9w3pQzalyGcGjVwr/8DB0kLFIGuZi56oOHJH7xHlCO2G9KDBXJzGgAC2dyfU0sgw719HvjlZBNFdV0/ROft4eH2YerpP4MVUx0PT7D9F2uwy+ZWvHnYkiQhwjzhVsBM9jbRcoa8HPfy56P/UEhqiZCXp7LkJzw/PbOEzvSwrB5liBnTkL/mFMB3NiXFVcP3x+SW9SpolLA8+2u+SIo6+Bxk3IBikffZiXA46+t06/ceJYdJA3yYAK4pabQbcs9XBcWvuT5WUBI3Ri+RAeYEELGYS2uceCgvKy5YB+fAnVpgPxzmFQjiJckM9mknjIukF1QN8tYpt7/7xh7WEf5dbWMmxiRnV+fZUxO7oeeZN4HKhflajKH1jc10J8wiOseoe5qMG74iN/0rHFZWlyB2d1P21pJ6S827cNfta5BdUmHzf8EJCZOg6Xz5xp3sy4chj/GjxDc6TKsn6Io35CfKcrzHwbTnhEbSgIbwHtkoi9KgayOIQ1igVNm/v+ctwb59hKTE2uMeA+YPWlk0M4Abb2EpjAGuiYa5Mf91D7d5VKuoYJ8ngfU1/dCDrGFc1mHgW59NEjKnxHSb7OLcyJDL0CBEjLmTRwCOIAwJ31PMb1WW4sWvccl8odLtYTs4FY3GPBJ5QVt5sP5C8vh8rSvpMHbIex5DAXtuD0MZ32JU0fsPAgxJJU7KBU+4kNmV32I2YHr5VG9XnqP920tEDJEbs9A2ZZpeuOzvQzlFijt7XzCFyZpflQNMlK2I6Os1vW44DTSx6zBpSch2diIfTMJSJVuI8OPxweEYDyStyr5Y7KyPFes6jH374z8J/a+kl2MfmivT/sa/5Dv0SuaI6lNkDch18ymn8Rl1YXkCnFiEdpO4mZ8YNFJ5TAyAbc1cxmI4VOiwby1K2r3gTlyuG1W7t//FYqAz3OL6sB9bur1e664qlB5YUke3HJntvIqxWwNulpgXx5dVDP4HYXiVeGATHvf//WHwKAj6iUbnfLTPx0Y48YenXJxbh1kCyHZ0p85MpKHDliTkzfVHC6hnasdkYW+bYvZL4y1qqyNlIOGGPTeJndA4JCnaGmL9e6Im5+40h53PPXiWFTs3rBxr71kp6Vs1CTYlYk/Z888vMaoz+t7lPhFJgzxR7PhA9CIoUVol7JRQOmgNrK5NYQYQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 226680c1-c8d4-4a44-2af8-08da2214a73d X-MS-Exchange-CrossTenant-AuthSource: MW3PR12MB4347.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 14:55:32.9496 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UuTuGDAwx6n4AREXGOF5/46TvtWs5yaEMYe/aogsr4t+5Who3TUm7TPEX4/2qpPeSgjCFyh1hp20wtNAVFxlRQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1378 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vadim Pasternak Netdevs for ports found on line cards are registered upon provisioning. However, user space is not allowed to access the transceiver modules found on a line card until the line card becomes active. Therefore, register event operations with the line card core to get notifications whenever a line card becomes active or inactive. When user space tries to dump the EEPROM of a transceiver module or reset it and the corresponding line card is inactive, emit an error message: ethtool -m enp1s0nl7p9 netlink error: mlxsw_core: Cannot read EEPROM of module on an inactive line card netlink error: Input/output error When user space tries to set the power mode policy of such a transceiver, cache the configuration and apply it when the line card becomes active. This is consistent with other port configuration (e.g., MTU setting) that user space is able to perform while the line card is provisioned, but inactive. Signed-off-by: Vadim Pasternak Signed-off-by: Ido Schimmel --- .../net/ethernet/mellanox/mlxsw/core_env.c | 166 +++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.c b/drivers/net/ethernet/mellanox/mlxsw/core_env.c index a9b133d6c2fc..34bec9cd572c 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_env.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.c @@ -23,6 +23,7 @@ struct mlxsw_env_module_info { struct mlxsw_env_line_card { u8 module_count; + bool active; struct mlxsw_env_module_info module_info[]; }; @@ -35,6 +36,24 @@ struct mlxsw_env { struct mlxsw_env_line_card *line_cards[]; }; +static bool __mlxsw_env_linecard_is_active(struct mlxsw_env *mlxsw_env, + u8 slot_index) +{ + return mlxsw_env->line_cards[slot_index]->active; +} + +static bool mlxsw_env_linecard_is_active(struct mlxsw_env *mlxsw_env, + u8 slot_index) +{ + bool active; + + mutex_lock(&mlxsw_env->line_cards_lock); + active = __mlxsw_env_linecard_is_active(mlxsw_env, slot_index); + mutex_unlock(&mlxsw_env->line_cards_lock); + + return active; +} + static struct mlxsw_env_module_info *mlxsw_env_module_info_get(struct mlxsw_core *mlxsw_core, u8 slot_index, u8 module) @@ -47,9 +66,13 @@ mlxsw_env_module_info *mlxsw_env_module_info_get(struct mlxsw_core *mlxsw_core, static int __mlxsw_env_validate_module_type(struct mlxsw_core *core, u8 slot_index, u8 module) { + struct mlxsw_env *mlxsw_env = mlxsw_core_env(core); struct mlxsw_env_module_info *module_info; int err; + if (!__mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) + return 0; + module_info = mlxsw_env_module_info_get(core, slot_index, module); switch (module_info->type) { case MLXSW_REG_PMTM_MODULE_TYPE_TWISTED_PAIR: @@ -269,12 +292,18 @@ int mlxsw_env_get_module_info(struct net_device *netdev, struct mlxsw_core *mlxsw_core, u8 slot_index, int module, struct ethtool_modinfo *modinfo) { + struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); u8 module_info[MLXSW_REG_MCIA_EEPROM_MODULE_INFO_SIZE]; u16 offset = MLXSW_REG_MCIA_EEPROM_MODULE_INFO_SIZE; u8 module_rev_id, module_id, diag_mon; unsigned int read_size; int err; + if (!mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) { + netdev_err(netdev, "Cannot read EEPROM of module on an inactive line card\n"); + return -EIO; + } + err = mlxsw_env_validate_module_type(mlxsw_core, slot_index, module); if (err) { netdev_err(netdev, @@ -359,6 +388,7 @@ int mlxsw_env_get_module_eeprom(struct net_device *netdev, int module, struct ethtool_eeprom *ee, u8 *data) { + struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); int offset = ee->offset; unsigned int read_size; bool qsfp, cmis; @@ -368,6 +398,11 @@ int mlxsw_env_get_module_eeprom(struct net_device *netdev, if (!ee->len) return -EINVAL; + if (!mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) { + netdev_err(netdev, "Cannot read EEPROM of module on an inactive line card\n"); + return -EIO; + } + memset(data, 0, ee->len); /* Validate module identifier value. */ err = mlxsw_env_validate_cable_ident(mlxsw_core, slot_index, module, @@ -428,10 +463,17 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, const struct ethtool_module_eeprom *page, struct netlink_ext_ack *extack) { + struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); u32 bytes_read = 0; u16 device_addr; int err; + if (!mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) { + NL_SET_ERR_MSG_MOD(extack, + "Cannot read EEPROM of module on an inactive line card"); + return -EIO; + } + err = mlxsw_env_validate_module_type(mlxsw_core, slot_index, module); if (err) { NL_SET_ERR_MSG_MOD(extack, "EEPROM is not equipped on port module type"); @@ -497,6 +539,11 @@ int mlxsw_env_reset_module(struct net_device *netdev, !(req & (ETH_RESET_PHY << ETH_RESET_SHARED_SHIFT))) return 0; + if (!mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) { + netdev_err(netdev, "Cannot reset module on an inactive line card\n"); + return -EIO; + } + mutex_lock(&mlxsw_env->line_cards_lock); err = __mlxsw_env_validate_module_type(mlxsw_core, slot_index, module); @@ -543,7 +590,7 @@ mlxsw_env_get_module_power_mode(struct mlxsw_core *mlxsw_core, u8 slot_index, struct mlxsw_env_module_info *module_info; char mcion_pl[MLXSW_REG_MCION_LEN]; u32 status_bits; - int err; + int err = 0; mutex_lock(&mlxsw_env->line_cards_lock); @@ -556,6 +603,10 @@ mlxsw_env_get_module_power_mode(struct mlxsw_core *mlxsw_core, u8 slot_index, module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index, module); params->policy = module_info->power_mode_policy; + /* Avoid accessing an inactive line card, as it will result in an error. */ + if (!__mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) + goto out; + mlxsw_reg_mcion_pack(mcion_pl, slot_index, module); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mcion), mcion_pl); if (err) { @@ -617,8 +668,16 @@ static int __mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, bool low_power, struct netlink_ext_ack *extack) { + struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); int err; + /* Avoid accessing an inactive line card, as it will result in an error. + * Cached configuration will be applied by mlxsw_env_got_active() when + * line card becomes active. + */ + if (!__mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) + return 0; + err = mlxsw_env_module_enable_set(mlxsw_core, slot_index, module, false); if (err) { NL_SET_ERR_MSG_MOD(extack, "Failed to disable module"); @@ -1208,6 +1267,98 @@ mlxsw_env_module_type_set(struct mlxsw_core *mlxsw_core, u8 slot_index) return 0; } +static void +mlxsw_env_linecard_modules_power_mode_apply(struct mlxsw_core *mlxsw_core, + struct mlxsw_env *env, + u8 slot_index) +{ + int i; + + for (i = 0; i < env->line_cards[slot_index]->module_count; i++) { + enum ethtool_module_power_mode_policy policy; + struct mlxsw_env_module_info *module_info; + struct netlink_ext_ack extack; + int err; + + module_info = &env->line_cards[slot_index]->module_info[i]; + policy = module_info->power_mode_policy; + err = mlxsw_env_set_module_power_mode_apply(mlxsw_core, + slot_index, i, + policy, &extack); + if (err) + dev_err(env->bus_info->dev, "%s\n", extack._msg); + } +} + +static void +mlxsw_env_got_active(struct mlxsw_core *mlxsw_core, u8 slot_index, void *priv) +{ + struct mlxsw_env *mlxsw_env = priv; + char mgpir_pl[MLXSW_REG_MGPIR_LEN]; + int err; + + mutex_lock(&mlxsw_env->line_cards_lock); + if (__mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) + goto out_unlock; + + mlxsw_reg_mgpir_pack(mgpir_pl, slot_index); + err = mlxsw_reg_query(mlxsw_env->core, MLXSW_REG(mgpir), mgpir_pl); + if (err) + goto out_unlock; + + mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL, + &mlxsw_env->line_cards[slot_index]->module_count, + NULL); + + err = mlxsw_env_module_event_enable(mlxsw_env, slot_index); + if (err) { + dev_err(mlxsw_env->bus_info->dev, "Failed to enable port module events for line card in slot %d\n", + slot_index); + goto err_mlxsw_env_module_event_enable; + } + err = mlxsw_env_module_type_set(mlxsw_env->core, slot_index); + if (err) { + dev_err(mlxsw_env->bus_info->dev, "Failed to set modules' type for line card in slot %d\n", + slot_index); + goto err_type_set; + } + + mlxsw_env->line_cards[slot_index]->active = true; + /* Apply power mode policy. */ + mlxsw_env_linecard_modules_power_mode_apply(mlxsw_core, mlxsw_env, + slot_index); + mutex_unlock(&mlxsw_env->line_cards_lock); + + return; + +err_type_set: + mlxsw_env_module_event_disable(mlxsw_env, slot_index); +err_mlxsw_env_module_event_enable: +out_unlock: + mutex_unlock(&mlxsw_env->line_cards_lock); +} + +static void +mlxsw_env_got_inactive(struct mlxsw_core *mlxsw_core, u8 slot_index, + void *priv) +{ + struct mlxsw_env *mlxsw_env = priv; + + mutex_lock(&mlxsw_env->line_cards_lock); + if (!__mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) + goto out_unlock; + mlxsw_env->line_cards[slot_index]->active = false; + mlxsw_env_module_event_disable(mlxsw_env, slot_index); + mlxsw_env->line_cards[slot_index]->module_count = 0; +out_unlock: + mutex_unlock(&mlxsw_env->line_cards_lock); +} + +static struct mlxsw_linecards_event_ops mlxsw_env_event_ops = { + .got_active = mlxsw_env_got_active, + .got_inactive = mlxsw_env_got_inactive, +}; + int mlxsw_env_init(struct mlxsw_core *mlxsw_core, const struct mlxsw_bus_info *bus_info, struct mlxsw_env **p_env) @@ -1247,6 +1398,11 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core, mutex_init(&env->line_cards_lock); *p_env = env; + err = mlxsw_linecards_event_ops_register(env->core, + &mlxsw_env_event_ops, env); + if (err) + goto err_linecards_event_ops_register; + err = mlxsw_env_temp_warn_event_register(mlxsw_core); if (err) goto err_temp_warn_event_register; @@ -1271,6 +1427,8 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core, if (err) goto err_type_set; + env->line_cards[0]->active = true; + return 0; err_type_set: @@ -1280,6 +1438,9 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core, err_module_plug_event_register: mlxsw_env_temp_warn_event_unregister(env); err_temp_warn_event_register: + mlxsw_linecards_event_ops_unregister(env->core, + &mlxsw_env_event_ops, env); +err_linecards_event_ops_register: mutex_destroy(&env->line_cards_lock); mlxsw_env_line_cards_free(env); err_mlxsw_env_line_cards_alloc: @@ -1289,11 +1450,14 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core, void mlxsw_env_fini(struct mlxsw_env *env) { + env->line_cards[0]->active = false; mlxsw_env_module_event_disable(env, 0); mlxsw_env_module_plug_event_unregister(env); /* Make sure there is no more event work scheduled. */ mlxsw_core_flush_owq(); mlxsw_env_temp_warn_event_unregister(env); + mlxsw_linecards_event_ops_unregister(env->core, + &mlxsw_env_event_ops, env); mutex_destroy(&env->line_cards_lock); mlxsw_env_line_cards_free(env); kfree(env); From patchwork Tue Apr 19 14:54:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12818660 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 9897CC433FE for ; Tue, 19 Apr 2022 14:56:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346700AbiDSO6t (ORCPT ); Tue, 19 Apr 2022 10:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353707AbiDSO6X (ORCPT ); Tue, 19 Apr 2022 10:58:23 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2073.outbound.protection.outlook.com [40.107.223.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7788B33EAD for ; Tue, 19 Apr 2022 07:55:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WkTDeYdFvWGwqLH/pkHG3juBWUfBk0uZONyrVSNpvwoiU1WGKu8AEfJB50ybdp7PzNT1Kxd0S0lNa/LDxNdVT5sMlNhjMHAI6b+NAeQzQzeb2PiAFgvDjMQWounDRpjGuNfAGxsz+xJJwPn7NuKy4Y6H3xv+kwmc6ANYBeNrgCUs4qPG2hvuiAGpP/Cd7fmDpep0BTtdaqvmIxiUFJk6cYmlxx8yCKbf3QswEtpKNUi4DYpCw+S24FsriwQcyvzTzLr7lZgusuECKPTCUll87yWba0jbChw7257ZFv2dzIRQiO6r37hL0ao4sipNBa2d3dWINSBrlyt4N4YXeuDbtw== 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=DlDtQIbRmcNPmYTkhXaDF6wuRujGCnttTp5ooD7tj24=; b=fTVMHLBhiI3Idpb/BGnv8L0xnHI4RONtSxSR4ONV2hPnCiaaVogoa4Qlliduwtvd/gActJEz1we4T97TA43iXU+mIOrLIP4WsTJG2MnZFf4GxnIacicJ9XbGzKMAPwk7mBTUqDDpPyJmKVmVmXlz0rTPjq1zzGbgQ3ZkxyW7VMDJdeqT0jdgba2HXDtxygy9TZKJnlkNs8lnki/Mrf2VG64w2nS8jSvapfx21hFu0Vu6Rvy+fCIz7OzkKHoO9Chj6ndgBnLdzsLJ8xPJXy0+3QrPtd2576bJ1uPlE8THHnme2r6gX+bSZYyPyYBczrSWvscTuQQII1TYSJH3XTMPNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DlDtQIbRmcNPmYTkhXaDF6wuRujGCnttTp5ooD7tj24=; b=GWMkjC3YGYqnwm3TMyqlbjYdnZT5kMjmYEXDcaQcU2/O4IpsoHH7sRiqW9HhyKxI54Jh+ove9BMz9H/gbU9OTX4yKYIPp53WUl0AhrkFO9yoG3UPbc7AkpJk3bnbGF3fcQWg9nxyMMGiMuof14tMVHeFgnyWXfQONrOt+Ifze8HkyD6uIDycyP351Gzx/NczryQQKG/tBH2QO3Ew3mKTQD0tQ7taDsd5ItFNDDQQVkZHu1kiNMYsYh0+hqmNG879BCIQ1N/pZSij4wgJvkuldg9QXo4ayJbtdwC1px1KUgxZcWRk2tUIQKW64bx/YSbF8LyQRP4kPmUlICqpcDf6GA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) by BN6PR12MB1378.namprd12.prod.outlook.com (2603:10b6:404:1e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Tue, 19 Apr 2022 14:55:38 +0000 Received: from MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d]) by MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d%2]) with mapi id 15.20.5186.013; Tue, 19 Apr 2022 14:55:38 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, petrm@nvidia.com, jiri@nvidia.com, vadimp@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 5/6] mlxsw: core_thermal: Add interfaces for line card initialization and de-initialization Date: Tue, 19 Apr 2022 17:54:30 +0300 Message-Id: <20220419145431.2991382-6-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220419145431.2991382-1-idosch@nvidia.com> References: <20220419145431.2991382-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0102CA0032.eurprd01.prod.exchangelabs.com (2603:10a6:802::45) To MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 024a3003-01c7-4a00-d504-08da2214aa96 X-MS-TrafficTypeDiagnostic: BN6PR12MB1378:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AgR2dd7cBpB3EsJeZyc86eEhb+vipQlKEgnwC0ovCUE/DXt4/tHpiUe2lTHnwOrYv0OaVB1NZwDmTggskraAQA8ET8pQBeLiWnEWeS198tGMVL+xpGKKyraRHr2WM0+gmNSK231lB2EH5mCReZgo6i9BOq4wKHm0zivnwDEFpvqX/5XGkHkfKOkqOfdwQ0JrMCNauZlniHUN0eD6eo45gwqMxIjQjmNfMFaX40tbsF5gXkhiQ/SJtk+nJ3Ub38pNMg6FCMxJ4IYGnajUU7LBn1xEEbkXOh+dOgDxIsFjOuSI7qj98xgzh190Tpulw6+yZXOJEaDU5JebzhiN9RsHeml7uo+qzm07vyAG6vf++B6WSP8GoyeQt9iueZn6d1BP3mi4uqPsyFLgQPoIK4A45yFd+jCO7T8tRCtJGXxNQQKrlPDVqq64/RYXKnUTuiOlPCFTKjnVuwo6+99oCCf6PLgTjct5qQdZ9KUtuYDEeWnK+k+h3b9i2glmzC04Hc/BbDAf2flr7yNK8O6QyGu1SJKmu6zDfQPo689Ku9QUyYa6C5LkNa66cEi4/S9ob0vsfKY6OuyFmBZ/5KAnY1l4gvAz/+ru/6vUpg1PaxaROBFMO23PwXPLqdwepEhfut6CcfL17l0zZB2k5fPEsG25+A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR12MB4347.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(86362001)(38100700002)(6486002)(508600001)(6666004)(8936002)(5660300002)(316002)(26005)(6512007)(8676002)(4326008)(66946007)(66556008)(186003)(66476007)(2906002)(6506007)(6916009)(2616005)(1076003)(107886003)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LDK392H95pPJ6h2rYzxG8UHf8FgtjQBEQ6tgDzzXUb1vHJESSH8YLa+1HcWNq3gjVlSJEVTh5OvQTX/VfhRXCDk/SPtUxEqWuSDemBlSx4JodHpNs+sVoRv+KZSKZTv3Js8wFVS428Yo8p9n4YIK2Dv1xAtRRLf0P7ZiT0f2FvGDd14xLbuwiBE/U2pJn0JkzmkeGSBD3BMu8FW+JX3QMSSusH64vrGl0XlPkhHnLABtNxD73EscnBA1L1AsLeqWyiLyoCMRtIlX7XZHh8GWrkjvINda2fxfTSZNdZZKJfK9sBsKR1P2SARbR031nzhIO66bNPXIQEagPonuTK+h8+s26c2WRUO4/E90kVgHjK2ouTBNExpylnAefE2U0PC0T6qoUyhU1aVd0fgNCrWqlwh9yA+RVoFEmfuSh581ZRP78LfiFk6tdWIbcvW3CSdIoEDFbKqVxgL9mSLC1kLSl1vtcPBJ5gE5nHpAKaq4ACpwqiOnXxGOYXBfTSc0uFokIGYWZBZr+RcYoBFpLBDGOtCADHlKofTc4HZ9T72cQ1fgJfLKGSBZAGtVEtUnN5K+sw4wv6YUbkTPBu9bkA4vUtU9OXQvcwHu540dcFjavn8G8fs9D4WYK/Y7rOheeE9QB0uGMoJHpAiTAo9UzZWSMoMlHqHkyRH4abGFx55hhCohmEgv4r1dq5XDKah6u3q91H8YJ2poYdkMLoJd3N9o+0cMmWAEuHOKtA+kImx6U+hwH+boBtkj+o8cP6fPCp4G4nXy+SW6a+WtFVvt9bINA8rscBvBkIuGU2MKnSmRKD/hgq2ijvQSZEO3Ube7+0LK9DhgNjeQJLtyQFzNjC/8GcfvMay5NFpr0HwpIcue3rGtxDMaDQ01zRMpWsA6BqF9rUK7OtFpJ6lRTcHfUjcj6Md0vel51YV/5KIE/BNfPuwxkYGaGHgYXhfSu7BJ1d2Qfu53bvYNP6WiJ+r9ucm32QlhEJn33xt4bwiaGMpn8aEuS3QRNBZfFHQby+IwUjjMB8kDIYyMUvY5XXa0hyaKRSAYpilLwpqeEagZ5ncqqiRvK2/tB4nT8D/YgO7qrZEZEnMnMrNj6rKK1aWxQSBOmBsbIdEV1BZcQ9DT28UNaGT4pSRD+k4CtPAOZK+/kPy2WXEgVavaQJVgdLyMVY/yhL+W5Yd2mfHD6T4p5O4Q/i90KcHI5SJ7hCpH6Kujz9BvUiMrQBlOviuiD12CshIj2XjWvuljy/CdrnEXz4g8LorZtIHsCtzEcuriztUszlf8E54PjXbFUZnu+/9J/FsEWSccQ4uXWHwqQy9I+peNsl8DIazntbRLA9JJBWgLxHaMRP+Tpbcli3xW5PmBt6eVTXKhC+4LjzOqCzOeQJrxUdJ9SloFyw9E7JSi3/fffNaVdmd4U8eVCzVYAvGqre9hHQeknpFS+bMXsaHM2cfoyk632Htvqoc2yDKRHvdFpWZypTGgvAop9Zcdt95POrrXyjixO5bbmSh+sxuK1wXkcd3Uall6B96TWOngTM5hQvkZAmFGfoHVWBjjb3H/V8upih3Sh3kpBkkZd7R5tQOkCxgGWK93X6/z5fEEpmBJdb53V/hZpZy2AqWFSNzHNVIoPAA+CSeam+765IL/8rt4vXAGZHkycDmZpIjkNIfjLV1Ka3PTMaZgjyBHmwbQ6UGk+r0rZ/tzm1lzSAwa7CHgaHv0V5yOUgsK1RLJ+TQ4mOyqMFT/gIpDvdWdGE9u4zkXeg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 024a3003-01c7-4a00-d504-08da2214aa96 X-MS-Exchange-CrossTenant-AuthSource: MW3PR12MB4347.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 14:55:38.4923 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rQPuG2lsFZ61s/c9SU/+RleVZMpksI/h5cUNq9jfObVv/Ojxb7oLFdmPBynNqhN/b2M86SKIVRq+/55/C39Dww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1378 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vadim Pasternak Add callback functions for line card thermal area initialization and de-initialization. Each line card is associated with the relevant thermal area, which may contain thermal zones for cages and gearboxes found on this line card. The line card thermal initialization / de-initialization APIs are to be called when line card is set to active / inactive state by got_active() / got_inactive() callbacks from line card state machine. For example thermal zone for module #9 located at line card #7 will have type: mlxsw-lc7-module9. And thermal zone for gearbox #2 located at line card #5 will have type: mlxsw-lc5-gearbox2. Signed-off-by: Vadim Pasternak Signed-off-by: Ido Schimmel --- .../ethernet/mellanox/mlxsw/core_thermal.c | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index e8ce26a1d483..3548fe1df7c8 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -90,6 +90,7 @@ struct mlxsw_thermal_area { struct mlxsw_thermal_module *tz_gearbox_arr; u8 tz_gearbox_num; u8 slot_index; + bool active; }; struct mlxsw_thermal { @@ -913,6 +914,64 @@ mlxsw_thermal_gearboxes_fini(struct mlxsw_thermal *thermal, kfree(area->tz_gearbox_arr); } +static void +mlxsw_thermal_got_active(struct mlxsw_core *mlxsw_core, u8 slot_index, + void *priv) +{ + struct mlxsw_thermal *thermal = priv; + struct mlxsw_thermal_area *linecard; + int err; + + linecard = &thermal->line_cards[slot_index]; + + if (linecard->active) + return; + + linecard->slot_index = slot_index; + err = mlxsw_thermal_modules_init(thermal->bus_info->dev, thermal->core, + thermal, linecard); + if (err) { + dev_err(thermal->bus_info->dev, "Failed to configure thermal objects for line card modules in slot %d\n", + slot_index); + return; + } + + err = mlxsw_thermal_gearboxes_init(thermal->bus_info->dev, + thermal->core, thermal, linecard); + if (err) { + dev_err(thermal->bus_info->dev, "Failed to configure thermal objects for line card gearboxes in slot %d\n", + slot_index); + goto err_thermal_linecard_gearboxes_init; + } + + linecard->active = true; + + return; + +err_thermal_linecard_gearboxes_init: + mlxsw_thermal_modules_fini(thermal, linecard); +} + +static void +mlxsw_thermal_got_inactive(struct mlxsw_core *mlxsw_core, u8 slot_index, + void *priv) +{ + struct mlxsw_thermal *thermal = priv; + struct mlxsw_thermal_area *linecard; + + linecard = &thermal->line_cards[slot_index]; + if (!linecard->active) + return; + linecard->active = false; + mlxsw_thermal_gearboxes_fini(thermal, linecard); + mlxsw_thermal_modules_fini(thermal, linecard); +} + +static struct mlxsw_linecards_event_ops mlxsw_thermal_event_ops = { + .got_active = mlxsw_thermal_got_active, + .got_inactive = mlxsw_thermal_got_inactive, +}; + int mlxsw_thermal_init(struct mlxsw_core *core, const struct mlxsw_bus_info *bus_info, struct mlxsw_thermal **p_thermal) @@ -1018,14 +1077,25 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_thermal_gearboxes_init; + err = mlxsw_linecards_event_ops_register(core, + &mlxsw_thermal_event_ops, + thermal); + if (err) + goto err_linecards_event_ops_register; + err = thermal_zone_device_enable(thermal->tzdev); if (err) goto err_thermal_zone_device_enable; + thermal->line_cards[0].active = true; *p_thermal = thermal; return 0; err_thermal_zone_device_enable: + mlxsw_linecards_event_ops_unregister(thermal->core, + &mlxsw_thermal_event_ops, + thermal); +err_linecards_event_ops_register: mlxsw_thermal_gearboxes_fini(thermal, &thermal->line_cards[0]); err_thermal_gearboxes_init: mlxsw_thermal_modules_fini(thermal, &thermal->line_cards[0]); @@ -1049,6 +1119,10 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal) { int i; + thermal->line_cards[0].active = false; + mlxsw_linecards_event_ops_unregister(thermal->core, + &mlxsw_thermal_event_ops, + thermal); mlxsw_thermal_gearboxes_fini(thermal, &thermal->line_cards[0]); mlxsw_thermal_modules_fini(thermal, &thermal->line_cards[0]); if (thermal->tzdev) { From patchwork Tue Apr 19 14:54:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12818661 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 B989FC433EF for ; Tue, 19 Apr 2022 14:56:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347213AbiDSO6u (ORCPT ); Tue, 19 Apr 2022 10:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353717AbiDSO63 (ORCPT ); Tue, 19 Apr 2022 10:58:29 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2087.outbound.protection.outlook.com [40.107.223.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E596828985 for ; Tue, 19 Apr 2022 07:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Nv/VbH7P9uule4oomVpDrv8+xKA24Xw2LXcWjUBBjD36QkRe9iuF3f1GEWl37Zj3WBsxdSs+ikognZQBdpeq5isM805KnOs+AwovGB5p0SpXdvqz/901VeUM/51y6zC1zlSQECP+G7q82VcGsJgHMWe2Tb2ud6XZkrpuyt4NBOs5C4em22z9zgfGCa6/Zq3SZvhc1ayEun2DCc8c2QcCDoyD7n31MTytFGRdfhDSnpN1lXtwOblgk4WeXyKVMoW1AkKEqPAuFIRW1bIPQofC//pAXZEnOAusEo01iVJBiakdaT3AjlJbt8EI98lFR+cohaWjiceR3y2OQZYCSoT2IA== 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=4JJXmPRgvsJh0n/ghYr4zzU3VnkBOtQIY9GOpbGVQCg=; b=mXeD9ubL930rxCf9uy7ZHK6l9iagEFx+1EgO/PoqFSBFSD3RWc3b7fC+ZxZ7sNacTyKbnU3+tQ6gvaXEm86YGBSDW7eZ+B0Rk+YbTYjEKzgWlBd11DDL/bzNtPuPowKyWbWIeeXM9vQ5fXUrFahoaC/cTC00NXr/BEQihCtBlVMaPUH/R7GETc74J4nq0Av9G4Bd1oe+c7T8bwIU7/JZvl4kHVE2CE2Mf4toPu6NhqD+LlaxfXYzZDzfcaHmaoyz2PIRSQDMkdFLSIaAAHqmroRIOWEztR7rjvxi9clrqD62lf73Qb0r1UVN1yqUGC0rYaCZEimMXLRvK4jMaHcHcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4JJXmPRgvsJh0n/ghYr4zzU3VnkBOtQIY9GOpbGVQCg=; b=hnf0RY6NKvOWKOkkmqXAdOAL+8mN5VbjQ2Xyu+tGNdk3kctl25AJbaSZ3XmHSlnZ81DFxlrgxM/zZul1Zc/zZJwaunHSqFl6MRbNrfzCcR2CDj8FEQBM+jj4TgS7J+eskg50mUKaYzM8i14pU6vAVq6OndqXGMV+42aOUCZvEq5k7JCQIqK4vPG5cD5LOfbYznmArP0EiX0OJi37l0WP73nWp5nsodi4843mZv47N+UGEVpREozQeQXS+5GyrApiDkO9mu+qE6S2Oky34o2uvVAB6EQ6whPX3Mu8L+VWjnieyPGctzE7Vg3wd3NaE5kMf03hTnhCWakV6tWLF2RVag== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) by BN6PR12MB1378.namprd12.prod.outlook.com (2603:10b6:404:1e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Tue, 19 Apr 2022 14:55:45 +0000 Received: from MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d]) by MW3PR12MB4347.namprd12.prod.outlook.com ([fe80::9196:55b8:5355:f64d%2]) with mapi id 15.20.5186.013; Tue, 19 Apr 2022 14:55:45 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, petrm@nvidia.com, jiri@nvidia.com, vadimp@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 6/6] mlxsw: core_hwmon: Add interfaces for line card initialization and de-initialization Date: Tue, 19 Apr 2022 17:54:31 +0300 Message-Id: <20220419145431.2991382-7-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220419145431.2991382-1-idosch@nvidia.com> References: <20220419145431.2991382-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR10CA0095.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:28::24) To MW3PR12MB4347.namprd12.prod.outlook.com (2603:10b6:303:2e::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b7c278fd-fab2-4827-4840-08da2214ae51 X-MS-TrafficTypeDiagnostic: BN6PR12MB1378:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: asTPGwtpE8fIGaA3onv2Fbgfy9p4a+rCGDyxgUYEy3AWDgH8JKiEjA3Jk47Foo3C4kDZXSWJTb8U5SsgGQ1kr2nQLPJF8bB4Ve1qO423fpZRgTj1m3WsRRT729F7ydahbAJ3LTkvFwvulovFmzQZhqk+H5pXEbXzB/dfQuTMblyHCWUt3nV+2Zua7rJnJ651PFOijM55x8uDyKNVR887RZ4wpGRVRG8kxvELALEYZWUkUj7AsG+nCwCxnuwhmVqVQA7vM2CgjTEGoTR7GSb3VodqA0etTTfY28WsxoQ5eXaWKuqsA6GWGRLVSxAgJLcsVMhtMPxwfGNZfWwTgwzQjn5T8JdKuFgXh/otj/98NBBjhJ5JPfPKIEuQs+ukaZOWL8mF8NMo8W4XI217ParH8Dnic2rMo048IyBhjSa4NwbsWktCRIOHzhx5o8bs4E98dDQ+GdANsB9h/273idG2oqwKn9X3Y0G8Ugu81dBybFhs30bGaYIsrurFM60QKAWLbjex/kO8uJARDagbIExwVI9ban+BhVjoZvEeNHR0IOD6uionRIzjd0MFjfwsrzwZNqirEiiwgZsdHQhKjIWZUJ1+NvrYNiZ0gH/cV0NHDNtHvEtg/Iu+vTE7THIZ9M31sGu7kp0nyhsLs2OxymJ1OA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR12MB4347.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(86362001)(38100700002)(6486002)(508600001)(6666004)(8936002)(5660300002)(316002)(26005)(6512007)(8676002)(4326008)(66946007)(66556008)(186003)(66476007)(2906002)(6506007)(6916009)(2616005)(1076003)(107886003)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lA+5wTcB5GFbgWUlK6Zj2JqpVNqYy8p5Ok6lhSH1hN9Uxcg1OdfR2aPDWnLnNx4/DIo3H2FgerMQIZDx8JypV8Nd4yo0FiAdD6WWb3TXudyNBawvvOJNdRdzip7a5Em6fvi1Loi09a4NlZRYvxhOSodjEzjJrj9Y1qgA9FQrYCo3BsBiS4AsE1i6uowbMbzvxJIzoH7dQ2JaS3Iap/jVFaPaS9PR085pBvONylt7zFsnmW5SfFmDkfUNjP6oqN4Llldeyk8ip479pJ5t62pgLnGRwo4CPSZxioNtj4NsDFdMFmPHIpJOLqPe2cVVoI7tuq6MWm6uOtbEfyuKzMFe39g+vY9WJ6kQGl0kMXF9AQ3pECONIcNGzvlSQ38+Cq+lw1qDz5k3cxP+0l5bj8jSDJs5K5c0ZngwsS3Gk92RydGPCY6flUoz315v1/krFXlKHjuJeC+fJSmWE7VbLqZKlys2fxSo7uz8m6uMb4dDb+VEUE27hhlBSkRkzU2KNdJu0cu/1RmXlOn9HNvtsmEg/H1S7vpGXrIrZKV+rzBgkJ+IyL/VkvPhcJyqpbZmxJPj4jLxfOYS0AKzMRy2eGkLb/4vnyGbxbRUfHCkx52ESXOjOeQeQqyJJZhkR+MivtVBvsYsGVhFnl60Q3q5nFm5lVjIUYL1gVVoKCCdVuzr90CGMnLeNMOmIMRg88dS1iFPJqw39Fsrlm4ez7qydzdFkB7E9QN5JUQeGLNf92F11z96A8uHX0H3NctTxtDNnLa+cUeEYQZq/BsYDqk8Ne73hNL0E4n61gFBZ/uN2DgyGzxKHjHaIPmZ4O1O+nAL6eHUvxw3df5uqO4pl9dH/T34BfvJxeOiBvkFTvbRwKSkCWkJzQ1uTY1Pcz2NOC6Wl78nDTQBcNfKwGW4MlOW0pmtdjcYjtLyrMzF+MKSnMg0qGx9EQCmt65sFFArltpsU60cKPZx5KvfQVB5zKGekmdOVUM9Vy+1Tvx4CEv3+XxNdlC2HZuxxXU4S6kRDm3RlpU91rXxVL9YEKURzgrtvz9gKmgzbCqPMC1kI43R8vTpvg3F+h8HcHSxqGCgZ0vytsW3JUSfnwwQL6bDPGFySXHJOtkg79XSqveHkhN+EC4e+knPZYTpslybCoKffeas0KsObXBTYcfemZ06shRDLAI3q12HRLOj5g4xYjq4sGTpQCIpbLbfScJnFqIMnGyNGsEyvV9s60V9kFT2FlwUXmGcZG8DLTDYvvsWAXi++pZgXjwulZkwL5Z98sSBPtYnpAmlPL7V46sTs3xiijRWa6MAldhUKO4i0IPZuDE6nFWrvqgb9Okas/pgzlU2XtRO39+MJE5WE8fuRfb32ib3/igdbB0ZQYMFM1+6fifpNg6ooIy1z580zzD8kVw6P3yGthYWaL4K1et3d8HlCT+wgxz+geZMhWaPUTX5sMuNzf8l0JC6eWobZBdfn+JxHxit5n5d/YUhol1PX0I1r+20fKbmo24/XqQfyliDQOZTSJYLbTogo38znlCzY0HamzzBBgwXPQgqpImg09RxPNWRB90Twfu+Ejb12PfeZlsU7j8TayzsveZpZdkqlETed9B9MTQG+vMQYWEedPgisqW0/ccfyCCTNcttzzYH+Dq2qaX3+AgnL835iz6/fe1Y+tTkekKrBRvUMU+7X/FB2OfBvCajG71Vo5a5N+mm0SGmoVKjtjySC7RHgYAzLvUvhfA8sSTDMGHK5oUYED7K3O7XHpkW/w== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7c278fd-fab2-4827-4840-08da2214ae51 X-MS-Exchange-CrossTenant-AuthSource: MW3PR12MB4347.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 14:55:44.8567 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LE+JTBrEAJ7+cOK8JCCTzCGAAmn+Ri6ZaIjGA+CizneVgz5jMT8kLPtrTvcA+xVAbokLacJzvLhWugiMIijyng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1378 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vadim Pasternak Add callback functions for line card 'hwmon' initialization and de-initialization. Each line card is associated with the relevant 'hwmon' device, which may contain thermal attributes for the cages and gearboxes found on this line card. The line card 'hwmon' initialization / de-initialization APIs are to be called when line card is set to active / inactive state by got_active() / got_inactive() callbacks from line card state machine. For example cage temperature for module #9 located at line card #7 will be exposed by utility 'sensors' like: linecard#07 front panel 009: +32.0C (crit = +70.0C, emerg = +80.0C) And temperature for gearbox #3 located at line card #5 will be exposed like: linecard#05 gearbox 003: +41.0C (highest = +41.0C) Signed-off-by: Vadim Pasternak Signed-off-by: Ido Schimmel --- .../net/ethernet/mellanox/mlxsw/core_hwmon.c | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c b/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c index fff6f248d6f7..70735068cf29 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c @@ -19,6 +19,7 @@ #define MLXSW_HWMON_ATTR_PER_SENSOR 3 #define MLXSW_HWMON_ATTR_PER_MODULE 7 #define MLXSW_HWMON_ATTR_PER_GEARBOX 4 +#define MLXSW_HWMON_DEV_NAME_LEN_MAX 16 #define MLXSW_HWMON_ATTR_COUNT (MLXSW_HWMON_SENSORS_MAX_COUNT * MLXSW_HWMON_ATTR_PER_SENSOR + \ MLXSW_HWMON_MODULES_MAX_COUNT * MLXSW_HWMON_ATTR_PER_MODULE + \ @@ -41,6 +42,7 @@ static int mlxsw_hwmon_get_attr_index(int index, int count) } struct mlxsw_hwmon_dev { + char name[MLXSW_HWMON_DEV_NAME_LEN_MAX]; struct mlxsw_hwmon *hwmon; struct device *hwmon_dev; struct attribute_group group; @@ -51,6 +53,7 @@ struct mlxsw_hwmon_dev { u8 sensor_count; u8 module_sensor_max; u8 slot_index; + bool active; }; struct mlxsw_hwmon { @@ -780,6 +783,75 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon_dev *mlxsw_hwmon_dev) return 0; } +static void +mlxsw_hwmon_got_active(struct mlxsw_core *mlxsw_core, u8 slot_index, + void *priv) +{ + struct mlxsw_hwmon *hwmon = priv; + struct mlxsw_hwmon_dev *linecard; + struct device *dev; + int err; + + dev = hwmon->bus_info->dev; + linecard = &hwmon->line_cards[slot_index]; + if (linecard->active) + return; + /* For the main board, module sensor indexes start from 1, sensor index + * 0 is used for the ASIC. Use the same numbering for line cards. + */ + linecard->sensor_count = 1; + linecard->slot_index = slot_index; + linecard->hwmon = hwmon; + err = mlxsw_hwmon_module_init(linecard); + if (err) { + dev_err(dev, "Failed to configure hwmon objects for line card modules in slot %d\n", + slot_index); + return; + } + + err = mlxsw_hwmon_gearbox_init(linecard); + if (err) { + dev_err(dev, "Failed to configure hwmon objects for line card gearboxes in slot %d\n", + slot_index); + return; + } + + linecard->groups[0] = &linecard->group; + linecard->group.attrs = linecard->attrs; + sprintf(linecard->name, "%s#%02u", "linecard", slot_index); + linecard->hwmon_dev = + hwmon_device_register_with_groups(dev, linecard->name, + linecard, linecard->groups); + if (IS_ERR(linecard->hwmon_dev)) { + dev_err(dev, "Failed to register hwmon objects for line card in slot %d\n", + slot_index); + return; + } + + linecard->active = true; +} + +static void +mlxsw_hwmon_got_inactive(struct mlxsw_core *mlxsw_core, u8 slot_index, + void *priv) +{ + struct mlxsw_hwmon *hwmon = priv; + struct mlxsw_hwmon_dev *linecard; + + linecard = &hwmon->line_cards[slot_index]; + if (!linecard->active) + return; + linecard->active = false; + hwmon_device_unregister(linecard->hwmon_dev); + /* Reset attributes counter */ + linecard->attrs_count = 0; +} + +static struct mlxsw_linecards_event_ops mlxsw_hwmon_event_ops = { + .got_active = mlxsw_hwmon_got_active, + .got_inactive = mlxsw_hwmon_got_inactive, +}; + int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core, const struct mlxsw_bus_info *mlxsw_bus_info, struct mlxsw_hwmon **p_hwmon) @@ -836,10 +908,19 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core, goto err_hwmon_register; } + err = mlxsw_linecards_event_ops_register(mlxsw_hwmon->core, + &mlxsw_hwmon_event_ops, + mlxsw_hwmon); + if (err) + goto err_linecards_event_ops_register; + mlxsw_hwmon->line_cards[0].hwmon_dev = hwmon_dev; + mlxsw_hwmon->line_cards[0].active = true; *p_hwmon = mlxsw_hwmon; return 0; +err_linecards_event_ops_register: + hwmon_device_unregister(mlxsw_hwmon->line_cards[0].hwmon_dev); err_hwmon_register: err_temp_gearbox_init: err_temp_module_init: @@ -851,6 +932,9 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core, void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon) { + mlxsw_hwmon->line_cards[0].active = false; + mlxsw_linecards_event_ops_unregister(mlxsw_hwmon->core, + &mlxsw_hwmon_event_ops, mlxsw_hwmon); hwmon_device_unregister(mlxsw_hwmon->line_cards[0].hwmon_dev); kfree(mlxsw_hwmon); }