From patchwork Fri Aug 13 12:27:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12435527 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 X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E89AC4320A for ; Fri, 13 Aug 2021 12:27:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52ECE610A4 for ; Fri, 13 Aug 2021 12:27:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240474AbhHMM2P (ORCPT ); Fri, 13 Aug 2021 08:28:15 -0400 Received: from mga14.intel.com ([192.55.52.115]:5785 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229965AbhHMM2O (ORCPT ); Fri, 13 Aug 2021 08:28:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10074"; a="215280354" X-IronPort-AV: E=Sophos;i="5.84,318,1620716400"; d="scan'208";a="215280354" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2021 05:27:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,318,1620716400"; d="scan'208";a="639793620" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 13 Aug 2021 05:27:45 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6087DF9; Fri, 13 Aug 2021 15:27:45 +0300 (EEST) From: Andy Shevchenko To: Jonathan Lemon , Andy Shevchenko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Cochran Subject: [PATCH v1 net-next 1/3] ptp_ocp: Switch to use module_pci_driver() macro Date: Fri, 13 Aug 2021 15:27:35 +0300 Message-Id: <20210813122737.45860-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Eliminate some boilerplate code by using module_pci_driver() instead of init/exit, and, if needed, moving the salient bits from init into probe. Signed-off-by: Andy Shevchenko --- drivers/ptp/ptp_ocp.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 0d1034e3ed0f..874ea7930079 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -377,24 +376,7 @@ static struct pci_driver ptp_ocp_driver = { .probe = ptp_ocp_probe, .remove = ptp_ocp_remove, }; - -static int __init -ptp_ocp_init(void) -{ - int err; - - err = pci_register_driver(&ptp_ocp_driver); - return err; -} - -static void __exit -ptp_ocp_fini(void) -{ - pci_unregister_driver(&ptp_ocp_driver); -} - -module_init(ptp_ocp_init); -module_exit(ptp_ocp_fini); +module_pci_driver(ptp_ocp_driver); MODULE_DESCRIPTION("OpenCompute TimeCard driver"); MODULE_LICENSE("GPL v2"); From patchwork Fri Aug 13 12:27:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12435531 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 X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96AE3C4338F for ; Fri, 13 Aug 2021 12:27:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8198760E78 for ; Fri, 13 Aug 2021 12:27:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240523AbhHMM2S (ORCPT ); Fri, 13 Aug 2021 08:28:18 -0400 Received: from mga07.intel.com ([134.134.136.100]:22440 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229474AbhHMM2O (ORCPT ); Fri, 13 Aug 2021 08:28:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10074"; a="279292439" X-IronPort-AV: E=Sophos;i="5.84,318,1620716400"; d="scan'208";a="279292439" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2021 05:27:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,318,1620716400"; d="scan'208";a="528512741" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 13 Aug 2021 05:27:45 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6BF82B1; Fri, 13 Aug 2021 15:27:45 +0300 (EEST) From: Andy Shevchenko To: Jonathan Lemon , Andy Shevchenko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Cochran Subject: [PATCH v1 net-next 2/3] ptp_ocp: Convert to use managed functions pcim_* and devm_* Date: Fri, 13 Aug 2021 15:27:36 +0300 Message-Id: <20210813122737.45860-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210813122737.45860-1-andriy.shevchenko@linux.intel.com> References: <20210813122737.45860-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier. Signed-off-by: Andy Shevchenko --- drivers/ptp/ptp_ocp.c | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 874ea7930079..5d0c0c0734f2 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -301,30 +301,25 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct ptp_ocp *bp; int err; - bp = kzalloc(sizeof(*bp), GFP_KERNEL); + bp = devm_kzalloc(&pdev->dev, sizeof(*bp), GFP_KERNEL); if (!bp) return -ENOMEM; bp->pdev = pdev; pci_set_drvdata(pdev, bp); - err = pci_enable_device(pdev); + err = pcim_enable_device(pdev); if (err) { dev_err(&pdev->dev, "pci_enable_device\n"); - goto out_free; + return err; } - err = pci_request_regions(pdev, KBUILD_MODNAME); + err = pcim_iomap_regions(pdev, BIT(0), KBUILD_MODNAME); if (err) { - dev_err(&pdev->dev, "pci_request_region\n"); - goto out_disable; - } - - bp->base = pci_ioremap_bar(pdev, 0); - if (!bp->base) { dev_err(&pdev->dev, "io_remap bar0\n"); - err = -ENOMEM; - goto out_release_regions; + return err; } + + bp->base = pcim_iomap_table(pdev)[0]; bp->reg = bp->base + OCP_REGISTER_OFFSET; bp->tod = bp->base + TOD_REGISTER_OFFSET; bp->ptp_info = ptp_ocp_clock_info; @@ -332,29 +327,17 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) err = ptp_ocp_check_clock(bp); if (err) - goto out; + return err; bp->ptp = ptp_clock_register(&bp->ptp_info, &pdev->dev); if (IS_ERR(bp->ptp)) { dev_err(&pdev->dev, "ptp_clock_register\n"); - err = PTR_ERR(bp->ptp); - goto out; + return PTR_ERR(bp->ptp); } ptp_ocp_info(bp); return 0; - -out: - pci_iounmap(pdev, bp->base); -out_release_regions: - pci_release_regions(pdev); -out_disable: - pci_disable_device(pdev); -out_free: - kfree(bp); - - return err; } static void @@ -363,11 +346,6 @@ ptp_ocp_remove(struct pci_dev *pdev) struct ptp_ocp *bp = pci_get_drvdata(pdev); ptp_clock_unregister(bp->ptp); - pci_iounmap(pdev, bp->base); - pci_release_regions(pdev); - pci_disable_device(pdev); - pci_set_drvdata(pdev, NULL); - kfree(bp); } static struct pci_driver ptp_ocp_driver = { From patchwork Fri Aug 13 12:27:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12435529 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 X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CA6BC432BE for ; Fri, 13 Aug 2021 12:27:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C269610FE for ; Fri, 13 Aug 2021 12:27:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240494AbhHMM2Q (ORCPT ); Fri, 13 Aug 2021 08:28:16 -0400 Received: from mga05.intel.com ([192.55.52.43]:12541 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233514AbhHMM2O (ORCPT ); Fri, 13 Aug 2021 08:28:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10074"; a="301137663" X-IronPort-AV: E=Sophos;i="5.84,318,1620716400"; d="scan'208";a="301137663" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2021 05:27:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,318,1620716400"; d="scan'208";a="571790822" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 13 Aug 2021 05:27:45 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 7A25E238; Fri, 13 Aug 2021 15:27:45 +0300 (EEST) From: Andy Shevchenko To: Jonathan Lemon , Andy Shevchenko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Cochran Subject: [PATCH v1 net-next 3/3] ptp_ocp: use bits.h macros for all masks Date: Fri, 13 Aug 2021 15:27:37 +0300 Message-Id: <20210813122737.45860-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210813122737.45860-1-andriy.shevchenko@linux.intel.com> References: <20210813122737.45860-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Currently we are using BIT(), but GENMASK(). Make use of the latter one as well (far less error-prone, far more concise). Signed-off-by: Andy Shevchenko Reported-by: kernel test robot --- drivers/ptp/ptp_ocp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 5d0c0c0734f2..aad29b07c05b 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2020 Facebook */ +#include #include #include #include @@ -60,10 +61,10 @@ struct tod_reg { #define TOD_CTRL_DISABLE_FMT_A BIT(17) #define TOD_CTRL_DISABLE_FMT_B BIT(16) #define TOD_CTRL_ENABLE BIT(0) -#define TOD_CTRL_GNSS_MASK ((1U << 4) - 1) +#define TOD_CTRL_GNSS_MASK GENMASK(3, 0) #define TOD_CTRL_GNSS_SHIFT 24 -#define TOD_STATUS_UTC_MASK 0xff +#define TOD_STATUS_UTC_MASK GENMASK(7, 0) #define TOD_STATUS_UTC_VALID BIT(8) #define TOD_STATUS_LEAP_VALID BIT(16)