From patchwork Wed Jan 26 04:40:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 12724580 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 F2672C28CF5 for ; Wed, 26 Jan 2022 04:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232419AbiAZEki (ORCPT ); Tue, 25 Jan 2022 23:40:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232141AbiAZEkg (ORCPT ); Tue, 25 Jan 2022 23:40:36 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAE9AC06161C for ; Tue, 25 Jan 2022 20:40:35 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id o64so22197061pjo.2 for ; Tue, 25 Jan 2022 20:40:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1Rv8q/Tn35fSrhYqgIYlz+o0VC1ITQsNAgoiqK3u5bs=; b=fXy6M3lmahrpjHVAwvJOSd5MQyahtLQoIN0wj3m1dwYfSNU7sxOUthoYZIezLQ3HfU aE0/M+7O69WM9XmWXRcfftAO0reS4ypTFRF6mIRJncbShEf15gNgiG/5vV3f+5qDJrNM +EGhC8zRAOFn3+Bc6bP3s9Hg1G3QG9sw1xSbs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1Rv8q/Tn35fSrhYqgIYlz+o0VC1ITQsNAgoiqK3u5bs=; b=0YdHpok5HJa9EE09gaJQblk7kA4+ikLbKcOuavJkw4lrMW2ee91Hw6Ty3b7CVcMRpX sC9wLCJaMn89jme4NHbelIi/IO0V+nvAGlDAb0jKDlrjM2ytWJXAzvmXbV4+IkHdn0Mm FpMNinvjytOymwtYFAtPsHCjZUgj5fcv7/tZleMG25XoaaQe/2r75B7viOheYp4mBFKE H+DxHUzSy9W3uqrHbGT58BM4s33iaeXO3+mW6VT3zRF6x3z8R4G0E9Wij/t1Jkplos5s DIVjDJndgNNxvHIV8CW/19WWZXvqFjJXBp+egacgsWtIMZJCooHUn9V3OWbONgWAWLSq 6Q4w== X-Gm-Message-State: AOAM532lkZlUTlAdZ0n3fRwwm3Jwd7D1op/i93FV96yUgHvkn4RLdiHU WPtGGdnn5o6Dk3dg9exSXXwJ6Q== X-Google-Smtp-Source: ABdhPJydHQJAlSwdtEFznTI7Yeer1hHCUCE7K0Kx6tUvemEM3nZlXO6i1kPprwa+Y3qs/z2S2XA6iQ== X-Received: by 2002:a17:902:ea10:b0:14a:f84a:bfa0 with SMTP id s16-20020a170902ea1000b0014af84abfa0mr21559269plg.163.1643172034981; Tue, 25 Jan 2022 20:40:34 -0800 (PST) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id s12sm559957pfk.65.2022.01.25.20.40.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Jan 2022 20:40:34 -0800 (PST) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, kuba@kernel.org, gospo@broadcom.com, pavan.chebbi@broadcom.com, Richard Cochran Subject: [PATCH net-next 2/5] bnxt_en: PTP: Refactor PTP initialization functions Date: Tue, 25 Jan 2022 23:40:10 -0500 Message-Id: <1643172013-31729-3-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1643172013-31729-1-git-send-email-michael.chan@broadcom.com> References: <1643172013-31729-1-git-send-email-michael.chan@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Pavan Chebbi Making the ptp free and timecounter initialization code into separate functions so that later patches can use them. Cc: Richard Cochran Signed-off-by: Pavan Chebbi Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c index 48520967746f..921aa7f75c9a 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c @@ -714,6 +714,34 @@ static bool bnxt_pps_config_ok(struct bnxt *bp) return !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) == !ptp->ptp_info.pin_config; } +static void bnxt_ptp_timecounter_init(struct bnxt *bp, bool init_tc) +{ + struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; + + if (!ptp->ptp_clock) { + memset(&ptp->cc, 0, sizeof(ptp->cc)); + ptp->cc.read = bnxt_cc_read; + ptp->cc.mask = CYCLECOUNTER_MASK(48); + ptp->cc.shift = 0; + ptp->cc.mult = 1; + ptp->next_overflow_check = jiffies + BNXT_PHC_OVERFLOW_PERIOD; + } + if (init_tc) + timecounter_init(&ptp->tc, &ptp->cc, ktime_to_ns(ktime_get_real())); +} + +static void bnxt_ptp_free(struct bnxt *bp) +{ + struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; + + if (ptp->ptp_clock) { + ptp_clock_unregister(ptp->ptp_clock); + ptp->ptp_clock = NULL; + kfree(ptp->ptp_info.pin_config); + ptp->ptp_info.pin_config = NULL; + } +} + int bnxt_ptp_init(struct bnxt *bp) { struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; @@ -729,23 +757,12 @@ int bnxt_ptp_init(struct bnxt *bp) if (ptp->ptp_clock && bnxt_pps_config_ok(bp)) return 0; - if (ptp->ptp_clock) { - ptp_clock_unregister(ptp->ptp_clock); - ptp->ptp_clock = NULL; - kfree(ptp->ptp_info.pin_config); - ptp->ptp_info.pin_config = NULL; - } + bnxt_ptp_free(bp); + atomic_set(&ptp->tx_avail, BNXT_MAX_TX_TS); spin_lock_init(&ptp->ptp_lock); - memset(&ptp->cc, 0, sizeof(ptp->cc)); - ptp->cc.read = bnxt_cc_read; - ptp->cc.mask = CYCLECOUNTER_MASK(48); - ptp->cc.shift = 0; - ptp->cc.mult = 1; - - ptp->next_overflow_check = jiffies + BNXT_PHC_OVERFLOW_PERIOD; - timecounter_init(&ptp->tc, &ptp->cc, ktime_to_ns(ktime_get_real())); + bnxt_ptp_timecounter_init(bp, true); ptp->ptp_info = bnxt_ptp_caps; if ((bp->fw_cap & BNXT_FW_CAP_PTP_PPS)) {