Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1190363pxb; Sun, 11 Apr 2021 10:25:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRDCQepvLuzLZIAbgtqTbe2clooCwtUdNQku+l1FfHQ4xSaJzI6v5SDXxt7iAhQCqPfpIO X-Received: by 2002:a63:d146:: with SMTP id c6mr23604858pgj.131.1618161919017; Sun, 11 Apr 2021 10:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618161919; cv=none; d=google.com; s=arc-20160816; b=iQ1rMfrYoV7LeUKpKxWs+Jg7m4kmpCkDTTCkMUDeEerfW3y8bE4PxNMPqkNq1f1qtd D7yvjuixFbEgcZNCuWNDYimBDHaJGZBeRzsiS0Av+KBGnvi8qftID8F03vc+Nc4Fihgq XLE8okP7ckbYsHuBLLzrkzqlJVEbRDqj2NpBzQvocFgrPHGN+8D3icH8wuZ4KFuoQz8a EpoYNAx+jlWFaN8Gboemw+Sl/48b84PvGrrvf146MLYtIG4J4WDoo+2nJA5wrwD85xZb p943FAzWNWmbVylS2VX8oO/+qmNOXGwfMIJwf7a+RkBwr4R41EnN3o/oNgyi3ZvPUR2O /BPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=0zyJmgYFpxkhTs/vyxtcrJtWhM0pW8558w941/ZF9cA=; b=xdQEnnZ3vZ/cGcRsu0KNHhBWxBcC25TfIl0tDnpa404g8drw9y+ghu1OBoYtTdaA9n NrOekL69kA6UR1mWXCd0ykkmMtw9I6anmUUhTm1ut244f6vpulljpH5kLcdpHyH1weXA YbCBnXMKjoBTmUxKyVirvD3mnvMTXQoOj4ybRTJx8f4Fa3sFORaoHNa2mle/sHZoWPim Cok28P0+BMQ44/fZ0O9bYwEdUAC2+wCxPTcFXV6ruJHuSWouwoaAV+9Rys0A1uA09qOm iydlo61MH88v24Lv26tEDk4yAdwWV3RSj90/5AEkb3+2zHrrUnOdz2SnS4bWA+B2mRji QNLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="dNM/qJPc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si10644327plg.355.2021.04.11.10.25.06; Sun, 11 Apr 2021 10:25:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="dNM/qJPc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235789AbhDKPLP (ORCPT + 99 others); Sun, 11 Apr 2021 11:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235503AbhDKPLO (ORCPT ); Sun, 11 Apr 2021 11:11:14 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98DE6C061574; Sun, 11 Apr 2021 08:10:58 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id lr1-20020a17090b4b81b02900ea0a3f38c1so8174312pjb.0; Sun, 11 Apr 2021 08:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=0zyJmgYFpxkhTs/vyxtcrJtWhM0pW8558w941/ZF9cA=; b=dNM/qJPcIvjk2GYrFX+iD68pia86U0nkEur8Znqf0zzxhPwx/6/yF3WVQJV+akOxXa 6nhsJtBR0s1/Zu2MPgihMZm2c9Jy1dDFL62QlsF3+vZxlna0kSEHlNg9uxgKMfDhnGTV vabdloE7g/PGvZ7aTGfFD2mqP8RA2hcvUdYDHX8eMNp9yLYcrWlIz1mzFQ2+K1qS0VTk FZbcFFqrQF7x4iplkPjXGIyrdaR8alrZIxBPiMdYMWzwGs19tkscKha3htk5Tx6sDT+C 3lhi5XRgSbZHcWwX2Q+dU9fW0q5t58naYiSYzle8a4eC0gNwEXarUSPgwqMvwpLeo3qq nzzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=0zyJmgYFpxkhTs/vyxtcrJtWhM0pW8558w941/ZF9cA=; b=huJ1SEWSQ0Nc0drCnG7r0lPoK/8m5cXtr497m9SSbqaGFag5XCY+Fwny9LpHBzHqBG E6Th8XJupWuuBjlAmLw1wmQBGA9ZUaDDPsQHupEvl+szGfFmWPgWK/AGNLHm9mj3kiNL QHgRPj1PPbRtyIALuIsCTxkSkmM7Z6c2Q3MoTD7xnOa/YOY/Sjya0DL+O3sTajK5zp4z 3sCXjz25C3EyaBINeFPZxpAnusYn8c1r+4gpjO7K9XlUECaXSCGkBxeE/Kh534j+v+3x pgchn5ZE0RRiihJfui2Aa+MND0X79ZaUusb95lNCG5Kd0ZpDkvW2hpx8H+1Yhkiv99br LFew== X-Gm-Message-State: AOAM533ohCdb6eeTuQnExZ81nEHMm8NWqIC6g1nA2nTXHMWs6GgqLSoW Q715qcPln5nG9Ie+jeWo7uA= X-Received: by 2002:a17:90b:88c:: with SMTP id bj12mr22694484pjb.177.1618153857985; Sun, 11 Apr 2021 08:10:57 -0700 (PDT) Received: from hoboy.vegasvil.org ([2601:645:c000:35:e2d5:5eff:fea5:802f]) by smtp.gmail.com with ESMTPSA id r6sm8355586pgp.64.2021.04.11.08.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Apr 2021 08:10:57 -0700 (PDT) Date: Sun, 11 Apr 2021 08:10:55 -0700 From: Richard Cochran To: Wong Vee Khee Cc: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S . Miller" , Jakub Kicinski , Maxime Coquelin , Voon Weifeng , Ong Boon Leong , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v3 1/1] net: stmmac: Add support for external trigger timestamping Message-ID: <20210411151055.GA5719@hoboy.vegasvil.org> References: <20210411024028.14586-1-vee.khee.wong@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210411024028.14586-1-vee.khee.wong@linux.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 11, 2021 at 10:40:28AM +0800, Wong Vee Khee wrote: > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c > index 60566598d644..60e17fd24aba 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c > @@ -296,6 +296,13 @@ static int intel_crosststamp(ktime_t *device, > > intel_priv = priv->plat->bsp_priv; > > + /* Both internal crosstimestamping and external triggered event > + * timestamping cannot be run concurrently. > + */ > + if (priv->plat->ext_snapshot_en) > + return -EBUSY; > + > + mutex_lock(&priv->aux_ts_lock); Lock, then ... > /* Enable Internal snapshot trigger */ > acr_value = readl(ptpaddr + PTP_ACR); > acr_value &= ~PTP_ACR_MASK; > @@ -321,6 +328,7 @@ static int intel_crosststamp(ktime_t *device, > acr_value = readl(ptpaddr + PTP_ACR); > acr_value |= PTP_ACR_ATSFC; > writel(acr_value, ptpaddr + PTP_ACR); > + mutex_unlock(&priv->aux_ts_lock); unlock, then ... > /* Trigger Internal snapshot signal > * Create a rising edge by just toggle the GPO1 to low > @@ -355,6 +363,8 @@ static int intel_crosststamp(ktime_t *device, > *system = convert_art_to_tsc(art_time); > } > > + /* Release the mutex */ > + mutex_unlock(&priv->aux_ts_lock); unlock again? Huh? > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h > index c49debb62b05..abadcd8cdc41 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h > @@ -239,6 +239,9 @@ struct stmmac_priv { > int use_riwt; > int irq_wake; > spinlock_t ptp_lock; > + /* Mutex lock for Auxiliary Snapshots */ > + struct mutex aux_ts_lock; In the comment, please be specific about which data are protected. For example: /* Protects auxiliary snapshot registers from concurrent access. */ > @@ -163,6 +166,43 @@ static void get_ptptime(void __iomem *ptpaddr, u64 *ptp_time) > *ptp_time = ns; > } > > +static void timestamp_interrupt(struct stmmac_priv *priv) > +{ > + struct ptp_clock_event event; > + unsigned long flags; > + u32 num_snapshot; > + u32 ts_status; > + u32 tsync_int; Please group same types together (u32) in a one-line list. > + u64 ptp_time; > + int i; > + > + tsync_int = readl(priv->ioaddr + GMAC_INT_STATUS) & GMAC_INT_TSIE; > + > + if (!tsync_int) > + return; > + > + /* Read timestamp status to clear interrupt from either external > + * timestamp or start/end of PPS. > + */ > + ts_status = readl(priv->ioaddr + GMAC_TIMESTAMP_STATUS); Reading this register has a side effect of clearing status? If so, doesn't it need protection against concurrent access? The function, intel_crosststamp() also reads this bit. > + if (!priv->plat->ext_snapshot_en) > + return; Doesn't this test come too late? Setting ts_status just cleared the bit used by the other code path. > + num_snapshot = (ts_status & GMAC_TIMESTAMP_ATSNS_MASK) >> > + GMAC_TIMESTAMP_ATSNS_SHIFT; > + > + for (i = 0; i < num_snapshot; i++) { > + spin_lock_irqsave(&priv->ptp_lock, flags); > + get_ptptime(priv->ptpaddr, &ptp_time); > + spin_unlock_irqrestore(&priv->ptp_lock, flags); > + event.type = PTP_CLOCK_EXTTS; > + event.index = 0; > + event.timestamp = ptp_time; > + ptp_clock_event(priv->ptp_clock, &event); > + } > +} > + > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c > index b164ae22e35f..d668c33a0746 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c > @@ -135,9 +135,13 @@ static int stmmac_enable(struct ptp_clock_info *ptp, > { > struct stmmac_priv *priv = > container_of(ptp, struct stmmac_priv, ptp_clock_ops); > + void __iomem *ptpaddr = priv->ptpaddr; > + void __iomem *ioaddr = priv->hw->pcsr; > struct stmmac_pps_cfg *cfg; > int ret = -EOPNOTSUPP; > unsigned long flags; > + u32 intr_value; > + u32 acr_value; Please group same types together. Thanks, Richard