Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1192963pxy; Fri, 23 Apr 2021 02:29:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAO1RbjNjtVj6OzPmOwhdGxp/Sc0oqEoj60cpHYKXuvm8TaT7zh7n0u9O7lCGYMLS4REHS X-Received: by 2002:a17:90b:1e01:: with SMTP id pg1mr4769111pjb.156.1619170179956; Fri, 23 Apr 2021 02:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619170179; cv=none; d=google.com; s=arc-20160816; b=tJwpm64UVgBUGnxVQ8OoHjYkCdHB6ZBq+xTUijjzZ+8y5KyIS73132wpLaKpqQGLyG Tk1bimd7jUAfQeR3xEeZOFYQjox79xRDsNrvlSQC3B7CX/wtwH/0Kcnpg+oQ5rrinl+0 UAHH6wmPKEeH0zS+3exL7jl0mk+eYKGoIDjehIL12ITOce0SyCqJnVQoxZKvk6jWOLKH Omq01uVt5Ng+90jN+beaDkVtxyl0ZoNbDenzWDRI2QgMYO2ckSp5w/HXg8twkeFfSc/q jJ81hjXLowkU3JpAXhmMGl6Sny04Ip90ntU7Lr0750BtEib6tk3kl0Euf9FU4MK2GL2m WAoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=7lI8MpzrnoUYHnrMbVDKW1q9yfiqUwJd7+92w9/86FI=; b=of5z8+Nf0jzScf2xS5/GtzjQJTB494TD6j5JqRBP1eNQVORDITepe79m9HFMInms57 +AOMtUy4CPa38aGpZU7icgMqDa9bcWfknduVXPCS3ohk/sfWDGdLEHrIZyyKw+RksPYI bvOQxJg323jdyeiveWW7LE/A/diwE39DBetdPXcZ0jv78z/0Xx/cF5jYLFotLxX8jA/0 0ebfaCft3MDLoCllHoynH6LOt4zsTxrIQcU5xafxAZYdHtuUoBbxlPxhFHJJBlASsJBa fyYYY4MkYHprBIF3CFlczAd+94maHPiF8vP21y5usS2DigIs7BDp5Z3BQQJC7/SJSNaf Ymmw== 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=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t4si6346658plr.14.2021.04.23.02.29.26; Fri, 23 Apr 2021 02:29:39 -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=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241778AbhDWJ2Z (ORCPT + 99 others); Fri, 23 Apr 2021 05:28:25 -0400 Received: from inva021.nxp.com ([92.121.34.21]:51160 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241759AbhDWJ2Z (ORCPT ); Fri, 23 Apr 2021 05:28:25 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 39816201F9F; Fri, 23 Apr 2021 11:27:48 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id DBDFA200E40; Fri, 23 Apr 2021 11:27:44 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 655B1402B7; Fri, 23 Apr 2021 11:27:40 +0200 (CEST) From: Yangbo Lu To: netdev@vger.kernel.org Cc: Yangbo Lu , Richard Cochran , Vladimir Oltean , "David S . Miller" , Jakub Kicinski , Claudiu Manoil , linux-kernel@vger.kernel.org Subject: [net-next, v2] enetc: fix locking for one-step timestamping packet transfer Date: Fri, 23 Apr 2021 17:33:55 +0800 Message-Id: <20210423093355.8665-1-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The previous patch to support PTP Sync packet one-step timestamping described one-step timestamping packet handling logic as below in commit message: - Trasmit packet immediately if no other one in transfer, or queue to skb queue if there is already one in transfer. The test_and_set_bit_lock() is used here to lock and check state. - Start a work when complete transfer on hardware, to release the bit lock and to send one skb in skb queue if has. There was not problem of the description, but there was a mistake in implementation. The locking/test_and_set_bit_lock() should be put in enetc_start_xmit() which may be called by worker, rather than in enetc_xmit(). Otherwise, the worker calling enetc_start_xmit() after bit lock released is not able to lock again for transfer. Fixes: 7294380c5211 ("enetc: support PTP Sync packet one-step timestamping") Signed-off-by: Yangbo Lu Reviewed-by: Claudiu Manoil --- Changes for v2: - None. Just resent. --- drivers/net/ethernet/freescale/enetc/enetc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 4f23829e7317..3ca93adb9662 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -321,6 +321,15 @@ static netdev_tx_t enetc_start_xmit(struct sk_buff *skb, struct enetc_bdr *tx_ring; int count; + /* Queue one-step Sync packet if already locked */ + if (skb->cb[0] & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) { + if (test_and_set_bit_lock(ENETC_TX_ONESTEP_TSTAMP_IN_PROGRESS, + &priv->flags)) { + skb_queue_tail(&priv->tx_skbs, skb); + return NETDEV_TX_OK; + } + } + tx_ring = priv->tx_ring[skb->queue_mapping]; if (unlikely(skb_shinfo(skb)->nr_frags > ENETC_MAX_SKB_FRAGS)) @@ -372,15 +381,6 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev) skb->cb[0] = ENETC_F_TX_TSTAMP; } - /* Queue one-step Sync packet if already locked */ - if (skb->cb[0] & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) { - if (test_and_set_bit_lock(ENETC_TX_ONESTEP_TSTAMP_IN_PROGRESS, - &priv->flags)) { - skb_queue_tail(&priv->tx_skbs, skb); - return NETDEV_TX_OK; - } - } - return enetc_start_xmit(skb, ndev); } base-commit: cad4162a90aeff737a16c0286987f51e927f003a -- 2.25.1