Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2193904iof; Tue, 7 Jun 2022 22:48:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVFCpHcZT3goYly4CgNH1TQHkg9B9qvX5xMZrI7fsmghKeM94H5OckdEkwpZ66iYcM06m1 X-Received: by 2002:a17:902:d4cc:b0:167:735a:e796 with SMTP id o12-20020a170902d4cc00b00167735ae796mr16349339plg.5.1654667289192; Tue, 07 Jun 2022 22:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667289; cv=none; d=google.com; s=arc-20160816; b=ZhzYjS1a9SgaOw9hGxNuVfGADYySlzJfHm0oh2t6CpYWqA4SaIJ0VksY/nl7dPn4rN GQs6c34jz26u0DpkBIBfWswF5ab9ygt3796pLsI+qi6+dsrPeM099Ftmez6tnsKloDpe ht97UUj44E31pWlt+YxwuPVwLJ/4rMF3vJ30ywqlj0TNfxjY2w/eg3YvoW1YbkDEY2dl QbljJU8qRz83oTe8MkJySjgCC8lujLWfUpwO/jRQrHG7Tl+38AQoR9IkQhp0BZCuXyL4 Tqav7CwSIB8Cs5LjomPaKAyh9myG3zFaM5xb9rsAyMCAAvCQhBkNEHU/rzqnTnjtBRPt YTmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oUGtofExTHHO/ZCwH4ZBiyseODjLsFSP7vqRySOIY9s=; b=fK6PJ5JV8/5K0Xsh0Ap6gZgdulwW+Z08pdpo0oPdWPAFDWalmGceprQd//32GLTB/3 r0jqSIq6M01e8cqe459JHY6GK9AhuhwriMAdTk9pK2x1+9T67FXYTbNwuiGm3fTHEjjW zHS+a0T5N9sNoaJS4dMUmcVoBhTp5T2YgKlL7fpCy9Lf2IGMZrDwAHMAYv04SvHcePpN +KmutCzoy0ID+/KD6kO23hatRZoh8x/3uJvfJcQ4LZR5n+Y5erxehOwZz5Mf65XUGwvh DcK085tFiNdreCekqkuA6555xOCFh2OFk0JepvHRX/AnYPO2ceqQSEoZGW48sCTg5Hz2 BMNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CJuBpY2J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h2-20020a170902f54200b00164db3d3af7si29192504plf.284.2022.06.07.22.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:48:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CJuBpY2J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DF214154B3C; Tue, 7 Jun 2022 22:13:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389934AbiFHAgY (ORCPT + 99 others); Tue, 7 Jun 2022 20:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383052AbiFGVwM (ORCPT ); Tue, 7 Jun 2022 17:52:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B149811178; Tue, 7 Jun 2022 12:10:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4D1BBB823B2; Tue, 7 Jun 2022 19:10:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4747C385A5; Tue, 7 Jun 2022 19:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629020; bh=ZTwSZD87fdAeVEUj2frEjr7IJiDfgHVX8UWIVufBZcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CJuBpY2Jog3Q3qyJWktTE1CbR9icjmqpNpXWeIGBPNeUmkaIxko16U33f+CJmbsGQ +u7gi1hPvJs7JqZJ9cRTYZbQBCopsgGlQOmzAB9PsJvf5Fp9wwnJOWJghXvzIOduP+ R/NsfjDJNrkfb6LJaeW+PR3vmKzFPY/8Rr+AjBWI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harini Katakam , Radhey Shyam Pandey , Claudiu Beznea , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.18 503/879] net: macb: Fix PTP one step sync support Date: Tue, 7 Jun 2022 19:00:21 +0200 Message-Id: <20220607165017.474449409@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Harini Katakam [ Upstream commit 5cebb40bc9554aafcc492431181f43c6231b0459 ] PTP one step sync packets cannot have CSUM padding and insertion in SW since time stamp is inserted on the fly by HW. In addition, ptp4l version 3.0 and above report an error when skb timestamps are reported for packets that not processed for TX TS after transmission. Add a helper to identify PTP one step sync and fix the above two errors. Add a common mask for PTP header flag field "twoStepflag". Also reset ptp OSS bit when one step is not selected. Fixes: ab91f0a9b5f4 ("net: macb: Add hardware PTP support") Fixes: 653e92a9175e ("net: macb: add support for padding and fcs computation") Signed-off-by: Harini Katakam Reviewed-by: Radhey Shyam Pandey Reviewed-by: Claudiu Beznea Link: https://lore.kernel.org/r/20220518170756.7752-1-harini.katakam@xilinx.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/cadence/macb_main.c | 40 +++++++++++++++++++++--- drivers/net/ethernet/cadence/macb_ptp.c | 4 ++- include/linux/ptp_classify.h | 3 ++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index ed7c2c2c4401..e9e5c3f6027c 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "macb.h" @@ -1124,6 +1125,36 @@ static void macb_tx_error_task(struct work_struct *work) spin_unlock_irqrestore(&bp->lock, flags); } +static bool ptp_one_step_sync(struct sk_buff *skb) +{ + struct ptp_header *hdr; + unsigned int ptp_class; + u8 msgtype; + + /* No need to parse packet if PTP TS is not involved */ + if (likely(!(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))) + goto not_oss; + + /* Identify and return whether PTP one step sync is being processed */ + ptp_class = ptp_classify_raw(skb); + if (ptp_class == PTP_CLASS_NONE) + goto not_oss; + + hdr = ptp_parse_header(skb, ptp_class); + if (!hdr) + goto not_oss; + + if (hdr->flag_field[0] & PTP_FLAG_TWOSTEP) + goto not_oss; + + msgtype = ptp_get_msgtype(hdr, ptp_class); + if (msgtype == PTP_MSGTYPE_SYNC) + return true; + +not_oss: + return false; +} + static void macb_tx_interrupt(struct macb_queue *queue) { unsigned int tail; @@ -1168,8 +1199,8 @@ static void macb_tx_interrupt(struct macb_queue *queue) /* First, update TX stats if needed */ if (skb) { - if (unlikely(skb_shinfo(skb)->tx_flags & - SKBTX_HW_TSTAMP) && + if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && + !ptp_one_step_sync(skb) && gem_ptp_do_txstamp(queue, skb, desc) == 0) { /* skb now belongs to timestamp buffer * and will be removed later @@ -1999,7 +2030,8 @@ static unsigned int macb_tx_map(struct macb *bp, ctrl |= MACB_BF(TX_LSO, lso_ctrl); ctrl |= MACB_BF(TX_TCP_SEQ_SRC, seq_ctrl); if ((bp->dev->features & NETIF_F_HW_CSUM) && - skb->ip_summed != CHECKSUM_PARTIAL && !lso_ctrl) + skb->ip_summed != CHECKSUM_PARTIAL && !lso_ctrl && + !ptp_one_step_sync(skb)) ctrl |= MACB_BIT(TX_NOCRC); } else /* Only set MSS/MFS on payload descriptors @@ -2097,7 +2129,7 @@ static int macb_pad_and_fcs(struct sk_buff **skb, struct net_device *ndev) if (!(ndev->features & NETIF_F_HW_CSUM) || !((*skb)->ip_summed != CHECKSUM_PARTIAL) || - skb_shinfo(*skb)->gso_size) /* Not available for GSO */ + skb_shinfo(*skb)->gso_size || ptp_one_step_sync(*skb)) return 0; if (padlen <= 0) { diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c index fb6b27f46b15..9559c16078f9 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -470,8 +470,10 @@ int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd) case HWTSTAMP_TX_ONESTEP_SYNC: if (gem_ptp_set_one_step_sync(bp, 1) != 0) return -ERANGE; - fallthrough; + tx_bd_control = TSTAMP_ALL_FRAMES; + break; case HWTSTAMP_TX_ON: + gem_ptp_set_one_step_sync(bp, 0); tx_bd_control = TSTAMP_ALL_FRAMES; break; default: diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h index fefa7790dc46..2b6ea36ad162 100644 --- a/include/linux/ptp_classify.h +++ b/include/linux/ptp_classify.h @@ -43,6 +43,9 @@ #define OFF_PTP_SOURCE_UUID 22 /* PTPv1 only */ #define OFF_PTP_SEQUENCE_ID 30 +/* PTP header flag fields */ +#define PTP_FLAG_TWOSTEP BIT(1) + /* Below defines should actually be removed at some point in time. */ #define IP6_HLEN 40 #define UDP_HLEN 8 -- 2.35.1