Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2434055pxb; Tue, 13 Apr 2021 01:33:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbx5Q1oO0S61ovP5qWMTizz0SoHbyi96G60yhW4OTa/BTB02Z6tIEp1FH3vZckN71WpFA4 X-Received: by 2002:a17:902:e882:b029:e6:caba:fff6 with SMTP id w2-20020a170902e882b02900e6cabafff6mr30190399plg.73.1618302816141; Tue, 13 Apr 2021 01:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618302816; cv=none; d=google.com; s=arc-20160816; b=FVs2gcp0n5PmqxBcXoJFakfmqMxfSYtEykd8zbVmqZZHBl8g1QBgUg0QGPefd8mll0 u7paJCm755Oxe6a7pg+DKpfykR4dlrjQ3wENSAMqRkUI2yOUqhYiDscE31QhiXsw9g6I gP357FZMHdORm5G8JttOvHEL+llhccFj+tFHFCA1gWGUzQ8WlAhmI0Uvz8/9nmuIMNNY G7XK/Nlz3yQ1ApLKQclrb7zlFId4RjNzGVAhUpxLYz8qkdmtgbNjTnuh7Y9CAFcgvXb3 5sxr446R8g1Ip6HqZBCUPTIcOR5M4BJ0xMZ7RLAxFJMBCJrZgSwSzpntDeIfGC0USHAw 62VQ== 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 :ironport-sdr:ironport-sdr; bh=Mem0ifrxhy9fHj5cWjgJ/YinBzfveEZa/Bc/N3Fx0dY=; b=nTl7VK+w+87S56bWusfEhqF9WZRbmzwl2bJqRfXOUFzQ42VT70awgVG9/W15WqSJTt helZeYHEwYGMMxHH11Ds13y+dZSvMFOzOvFJZPWnUzPYdqcg4exvSkc4TvcTd3yPjL1P LDu2g8NKJoqEVUJifn1jWE7qklFffrgWFsPGP+U1JK5ml7H/3ZhsjcoA5ZLGGNfdXVkr CnkfD9dzFF57a1N12OyQFywm7d1MFRpMt5LS2A3EClx1r8HiPF8jpf0nfqAr3xiwFqky 2AZ+fM3gx+QLlUZB1VzA2zS0LjJeasE5TaJVgN0TT3Yj37Mk6iojZNEE3ZJf06oEKjxB qctQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y4si17371805pga.71.2021.04.13.01.33.23; Tue, 13 Apr 2021 01:33:36 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240878AbhDMFIK (ORCPT + 99 others); Tue, 13 Apr 2021 01:08:10 -0400 Received: from mga04.intel.com ([192.55.52.120]:52778 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231162AbhDMFIJ (ORCPT ); Tue, 13 Apr 2021 01:08:09 -0400 IronPort-SDR: 0LvSAp69fkk+As5PkAI/F08JJGyQ6i0HkGVW1PmbOaKj6G/lISDgkuM5LglynueKNQBhTMGtrb 1vSJQk4HwYFA== X-IronPort-AV: E=McAfee;i="6200,9189,9952"; a="192207938" X-IronPort-AV: E=Sophos;i="5.82,218,1613462400"; d="scan'208";a="192207938" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2021 22:07:49 -0700 IronPort-SDR: 9tT+16Lue95sfJbPlF2LFbVo9BriNYcjTt3//K5Rd/uajIgAYTMMvI1Lz3ZNUEKBNbjsFodvWt A/UOHBcnheDQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,218,1613462400"; d="scan'208";a="383181445" Received: from linux.intel.com ([10.54.29.200]) by orsmga006.jf.intel.com with ESMTP; 12 Apr 2021 22:07:49 -0700 Received: from linux.intel.com (unknown [10.88.229.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTPS id 84E81580782; Mon, 12 Apr 2021 22:07:46 -0700 (PDT) Date: Tue, 13 Apr 2021 13:07:43 +0800 From: Wong Vee Khee To: Richard Cochran 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: <20210413050743.GA10274@linux.intel.com> References: <20210411024028.14586-1-vee.khee.wong@linux.intel.com> <20210411151055.GA5719@hoboy.vegasvil.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210411151055.GA5719@hoboy.vegasvil.org> User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 11, 2021 at 08:10:55AM -0700, Richard Cochran wrote: > 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? > Nice catch. Fix in v4. > > 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. > The following check is introduced in intel_crosststamp() to avoid this: /* Both internal crosstimestamping and external triggered event * timestamping cannot be run concurrently. */ if (priv->plat->ext_snapshot_en) return -EBUSY; > > + 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. > As per Synopsys's design, all bits except Bits[27:25] gets cleared when this register is read. > > + 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. > Fix in v4. > Thanks, > Richard