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+cXVjN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rP15FWj/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); }