From patchwork Thu Feb 15 11:09:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chintan Vankar X-Patchwork-Id: 201380 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp321466dyb; Thu, 15 Feb 2024 03:11:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXHIJtxKa1M0Rt0k5I0pE+z9BYNty+hi8paUtXmH+KNrSE0TcCVUvU83kVVMDB+57Epwv0iWrCVcYwG8lMkwuiolI/s3Q== X-Google-Smtp-Source: AGHT+IHcm6oSkULaw9v3mKGhXPMpDVDW4vlmb+NaBAuiHAjqai1DexY+rE+Ci0EbaHa9wPJ1fC5C X-Received: by 2002:ac8:5a87:0:b0:42d:a946:1db5 with SMTP id c7-20020ac85a87000000b0042da9461db5mr1552790qtc.58.1707995506189; Thu, 15 Feb 2024 03:11:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707995506; cv=pass; d=google.com; s=arc-20160816; b=X/PuJl+A+7h51JeStfGWqwtk1DpTdWWCKF1ikLgZ2RUArTZ5IWwVr2MrpcdupTrNPq BqcWfd/6rpwIoPd7CWSmXtWsj0Zn/o1dcCG783qOqLn4RkrcLyGZawUdSFMFNfVxhJz1 PB6/O0/x1VGHBVRAAVcuIPmu7E7D29cfK0edlFhuD82+Kiwkp5ptIWEzfO2B0LdzDlOv pJRCzWCcEh+Atpd/EQvQ4Db2DYwzJjFnupsqH5+z9beoCnL6uRrv+fIwXiEYbP5kJ2SF vG1OYBVSY1Jmwb/NWGBYUCgV3pVn3Llf2KSgJusBvc3IuTMH30/ho1ZSLHOnA2jf2VSi hHmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=HedDIvMLYfuWkKr9N3wYCvW8OcWi6ejb9YfzXb/Bzvg=; fh=58KR/JH9Go5Gb0ch3/RdrwyZxJ2DCDL1NmFyw11UykE=; b=JBiq5vPXvmZ/vcc4u+bSjt6daWbq2tkSOhyvRMtMbCQu1UGvwSdaAX1pBZFYd86j52 9e77fmVTqEIigk+QjCnl5tbnQ6znSOzGjYKoRCdtcAdUHGiq79G1ow7PUrOMv8wOtniZ /P9TDI+IGyOsAjnbvWsI+K6cdxaTiTGC2+ExNF00F1LwKDNNKTwiw1z9Q5UKmykCtnbA MrIt1cDAB0xok4XIo7NUUPYIC1vHLTo+lLa4/7ikJa9UasMnDAk5pxWibY2mHqQ8vtAS ue11Ksw6tnOjL27pveNyqbXC0jcJ6ZpRYvqy8HXRbfZNNt0MtOs9CbIZ/LI+s1IaBN5M f2+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=GrswMLsi; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-66747-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66747-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id wa4-20020a05620a4d0400b0078401633e31si1218731qkn.509.2024.02.15.03.11.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 03:11:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66747-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=GrswMLsi; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-66747-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66747-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E7D9A1C20AB4 for ; Thu, 15 Feb 2024 11:11:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38DA812C804; Thu, 15 Feb 2024 11:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="GrswMLsi" Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63885129A91; Thu, 15 Feb 2024 11:10:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707995411; cv=none; b=Aw4cQhBJlNtOR56sKy7d3H/lyiieE0K5sOxzvcYRzGOTxqa3qal2RzSbCJ6H0auLeFeu0/fTXIEXONKigCycJWsZfqn9dmfIGHOjP6OBZS1aiiBEFrJZJunJjjyRAlgrNnNMxQojzk0ghmx/5rlUFOm8YJhQ6M3qKmPCOsUQC1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707995411; c=relaxed/simple; bh=jvC+lMRGc6c7n5MUk7PAjVtPBj27Vmls03WU2plIzsI=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=mxQ279pujBT6t0NWYHUw1j5vOBGlmtteXG0+wYLObXJSbl+mEoOIwrE6ihDG7GADoZpinaVgW0xuYG62oD53dlPcxPzY2G4Zsw7qxByjLk7/E4zIx5CWvkiVbYhd/c+7kY9/krFgLzzUmmgbU4I5koaBfJL594Un0THamiPrZbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=GrswMLsi; arc=none smtp.client-ip=198.47.23.249 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 41FB9xXm081717; Thu, 15 Feb 2024 05:09:59 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1707995399; bh=HedDIvMLYfuWkKr9N3wYCvW8OcWi6ejb9YfzXb/Bzvg=; h=From:To:CC:Subject:Date; b=GrswMLsiwU/cAv2jsnm3AfqhIVIP17EMF1M72cPxVQVJtlm3Nj+e4QE8wJLZhZ9cw 7QJLXM7t/Te8T5ZAs5X4Co3f6vmMolSzG0bD50+a78CKThU3XlJ1ZOQ6UxmvMXgnfy yVBTliURsNRIgYqzRzvrEwkqpMRVc6+1lE1Vc6lg= Received: from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 41FB9xDx046597 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 15 Feb 2024 05:09:59 -0600 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Thu, 15 Feb 2024 05:09:58 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Thu, 15 Feb 2024 05:09:58 -0600 Received: from localhost (chintan-thinkstation-p360-tower.dhcp.ti.com [172.24.227.220]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 41FB9wix069245; Thu, 15 Feb 2024 05:09:58 -0600 From: Chintan Vankar To: Chintan Vankar , Dan Carpenter , Roger Quadros , Siddharth Vadapalli , Richard Cochran , Paolo Abeni , Jakub Kicinski , Eric Dumazet , "David S. Miller" CC: , Subject: [PATCH net-next 1/2] net: ethernet: ti: am65-cpts: Enable PTP RX HW timestamp using CPTS FIFO Date: Thu, 15 Feb 2024 16:39:52 +0530 Message-ID: <20240215110953.3225099-1-c-vankar@ti.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790963096205988246 X-GMAIL-MSGID: 1790963096205988246 CPTS module supports capturing timestamp for every packet it receives, add a new function named "am65_cpts_rx_find_ts()" to get the timestamp of received packets from CPTS FIFO. Add another function named "am65_cpts_rx_timestamp()" which internally calls "am65_cpts_rx_find_ts()" function and timestamps the received PTP packets. Signed-off-by: Chintan Vankar Reviewed-by: Jacob Keller --- drivers/net/ethernet/ti/am65-cpts.c | 84 +++++++++++++++++++++-------- drivers/net/ethernet/ti/am65-cpts.h | 11 ++-- 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c index c66618d91c28..92a3b40e60d6 100644 --- a/drivers/net/ethernet/ti/am65-cpts.c +++ b/drivers/net/ethernet/ti/am65-cpts.c @@ -859,29 +859,6 @@ static long am65_cpts_ts_work(struct ptp_clock_info *ptp) return delay; } -/** - * am65_cpts_rx_enable - enable rx timestamping - * @cpts: cpts handle - * @en: enable - * - * This functions enables rx packets timestamping. The CPTS can timestamp all - * rx packets. - */ -void am65_cpts_rx_enable(struct am65_cpts *cpts, bool en) -{ - u32 val; - - mutex_lock(&cpts->ptp_clk_lock); - val = am65_cpts_read32(cpts, control); - if (en) - val |= AM65_CPTS_CONTROL_TSTAMP_EN; - else - val &= ~AM65_CPTS_CONTROL_TSTAMP_EN; - am65_cpts_write32(cpts, val, control); - mutex_unlock(&cpts->ptp_clk_lock); -} -EXPORT_SYMBOL_GPL(am65_cpts_rx_enable); - static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid) { unsigned int ptp_class = ptp_classify_raw(skb); @@ -906,6 +883,67 @@ static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid) return 1; } +static u64 am65_cpts_find_rx_ts(struct am65_cpts *cpts, struct sk_buff *skb, + int ev_type, u32 skb_mtype_seqid) +{ + struct list_head *this, *next; + struct am65_cpts_event *event; + unsigned long flags; + u32 mtype_seqid; + u64 ns = 0; + + am65_cpts_fifo_read(cpts); + spin_lock_irqsave(&cpts->lock, flags); + list_for_each_safe(this, next, &cpts->events) { + event = list_entry(this, struct am65_cpts_event, list); + if (time_after(jiffies, event->tmo)) { + list_del_init(&event->list); + list_add(&event->list, &cpts->pool); + continue; + } + + mtype_seqid = event->event1 & + (AM65_CPTS_EVENT_1_MESSAGE_TYPE_MASK | + AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK | + AM65_CPTS_EVENT_1_EVENT_TYPE_MASK); + + if (mtype_seqid == skb_mtype_seqid) { + ns = event->timestamp; + list_del_init(&event->list); + list_add(&event->list, &cpts->pool); + break; + } + } + spin_unlock_irqrestore(&cpts->lock, flags); + + return ns; +} + +void am65_cpts_rx_timestamp(struct am65_cpts *cpts, struct sk_buff *skb) +{ + struct am65_cpts_skb_cb_data *skb_cb = (struct am65_cpts_skb_cb_data *)skb->cb; + struct skb_shared_hwtstamps *ssh; + int ret; + u64 ns; + + ret = am65_skb_get_mtype_seqid(skb, &skb_cb->skb_mtype_seqid); + if (!ret) + return; /* if not PTP class packet */ + + skb_cb->skb_mtype_seqid |= (AM65_CPTS_EV_RX << AM65_CPTS_EVENT_1_EVENT_TYPE_SHIFT); + + dev_dbg(cpts->dev, "%s mtype seqid %08x\n", __func__, skb_cb->skb_mtype_seqid); + + ns = am65_cpts_find_rx_ts(cpts, skb, AM65_CPTS_EV_RX, skb_cb->skb_mtype_seqid); + if (!ns) + return; + + ssh = skb_hwtstamps(skb); + memset(ssh, 0, sizeof(*ssh)); + ssh->hwtstamp = ns_to_ktime(ns); +} +EXPORT_SYMBOL_GPL(am65_cpts_rx_timestamp); + /** * am65_cpts_tx_timestamp - save tx packet for timestamping * @cpts: cpts handle diff --git a/drivers/net/ethernet/ti/am65-cpts.h b/drivers/net/ethernet/ti/am65-cpts.h index 6e14df0be113..6099d772799d 100644 --- a/drivers/net/ethernet/ti/am65-cpts.h +++ b/drivers/net/ethernet/ti/am65-cpts.h @@ -22,9 +22,9 @@ void am65_cpts_release(struct am65_cpts *cpts); struct am65_cpts *am65_cpts_create(struct device *dev, void __iomem *regs, struct device_node *node); int am65_cpts_phc_index(struct am65_cpts *cpts); +void am65_cpts_rx_timestamp(struct am65_cpts *cpts, struct sk_buff *skb); void am65_cpts_tx_timestamp(struct am65_cpts *cpts, struct sk_buff *skb); void am65_cpts_prep_tx_timestamp(struct am65_cpts *cpts, struct sk_buff *skb); -void am65_cpts_rx_enable(struct am65_cpts *cpts, bool en); u64 am65_cpts_ns_gettime(struct am65_cpts *cpts); int am65_cpts_estf_enable(struct am65_cpts *cpts, int idx, struct am65_cpts_estf_cfg *cfg); @@ -48,17 +48,18 @@ static inline int am65_cpts_phc_index(struct am65_cpts *cpts) return -1; } -static inline void am65_cpts_tx_timestamp(struct am65_cpts *cpts, +static inline void am65_cpts_rx_timestamp(struct am65_cpts *cpts, struct sk_buff *skb) { } -static inline void am65_cpts_prep_tx_timestamp(struct am65_cpts *cpts, - struct sk_buff *skb) +static inline void am65_cpts_tx_timestamp(struct am65_cpts *cpts, + struct sk_buff *skb) { } -static inline void am65_cpts_rx_enable(struct am65_cpts *cpts, bool en) +static inline void am65_cpts_prep_tx_timestamp(struct am65_cpts *cpts, + struct sk_buff *skb) { } From patchwork Thu Feb 15 11:09:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chintan Vankar X-Patchwork-Id: 201398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp327601dyb; Thu, 15 Feb 2024 03:24:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWsTsTSucTtgcbGfRYL1bi1O1rhKknUUINaxY7Tz980mCY740jHCgwajPS2l3DNIQdtAGupjhHLi/WInXEBUmIbsBsudw== X-Google-Smtp-Source: AGHT+IEI/rZk9v3MiQqgGslDw8LroyOQqnuHHp4dKbeHAQolnS3pbQ64G6S1PlqCBfGGjp6D9i4J X-Received: by 2002:a05:6871:79a:b0:21a:3627:efe1 with SMTP id o26-20020a056871079a00b0021a3627efe1mr1233798oap.25.1707996264887; Thu, 15 Feb 2024 03:24:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707996264; cv=pass; d=google.com; s=arc-20160816; b=zLHE8oLGbAHroejllbJZNyqONt12kFofB+W87QpR2MDLMbxdLrMALWcnSRiSPn1Od6 tTGytwzITOzwtdGKYrUUay0Rr9Zb8oBVxHJKUKxi80utgS/6QJ+uiq1iYt7pylV/ICZD EwGZGzqrz6RJZ8vyhCnKOy7ZP9rDuyXl/+W8G31B+Y5Gp/VF/2Ty8ndbVULlWfF2C11d A1EvvFKkxJkX5HDqdgf3icVTUmnnBr6DdAVnl4gkJByRPe5wSucOt4HFO6U+UcBE7+fT AyayrenSt38iq6fqYBpwdmGZZBuu9LL7KsPFqltjCjaqRmlsie2vRvwK2qCx+1jhMif3 dQFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=M407onLK2mqpOgnXCBUnGsRyi/aiFxEPhpsZL7d0pG8=; fh=58KR/JH9Go5Gb0ch3/RdrwyZxJ2DCDL1NmFyw11UykE=; b=Zi0WnxFmXNgs+WGDy56vPzpDmiLfts8IEUK55nPgu97cSG0obJj/BJxAtn/NbpGrjr LGybEWWfvAgHQVSu2EJJtu8urViIfeA0x2oZrL2MOEvmFfl4fguMLF4UZ/Y/yDFoAUqX +Noqa1buqc7kzhyPhO0OIxvqx5gbzYQ3IoMsBUh3pb6Lpx05j4mMHYx1JKMRWvxJJADw Z1W6wbwid1Bm/o5F+buSyqrAm4c6dTuPHLz+c6b8CSFwODx7gmIWMXqSma/HDDxVuo+R 97OhmuzXbIfcG5hljKqlbZMiQYELn8xk2DaI9amhdgk0wKDuxIBbAww5B6Xt7BZCrsof dkuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=MnWReYKz; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-66748-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66748-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l24-20020a63ba58000000b005dc893b82e5si970837pgu.817.2024.02.15.03.24.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 03:24:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66748-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=MnWReYKz; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-66748-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66748-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 87555292032 for ; Thu, 15 Feb 2024 11:11:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F22E412CDBD; Thu, 15 Feb 2024 11:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="MnWReYKz" Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63846129A75; Thu, 15 Feb 2024 11:10:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707995411; cv=none; b=RVNGj8YWdCFHWBLhP7g9vW44sypJKBgFRWCDnSmudvjOR/FCZQG6A/x2g2WTk4X04/jABjY+J6JwZN4iXd6rHUZHiXxnzjD32bFyPwGYmlnAY4JglF80q4LBzsOtdWMSgMHBxyp6TsvNGomrS7tg1rr8fZsB2hSK/f4qzuqLDnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707995411; c=relaxed/simple; bh=BJwDCaMI0aYz6VnWacdyLdYJC4bbqH19di3iUcevG24=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ShtipA0RnOzWf3xlACnCsVtYiHWQzkO4rVuwrtGMGP6nVSODKKEEt62ZQ6fcRcKJXjcVtX1i4f79xjIEh3qAIExenLHyioH5TUK3Cc7u2h8E6Jvtey/jyEWKMFy6jue8Xb04QrZeiZgr9qOuRqGWBS9F0thjoJf7Q9jQWLEAUoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=MnWReYKz; arc=none smtp.client-ip=198.47.23.249 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 41FBA0wY081722; Thu, 15 Feb 2024 05:10:00 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1707995400; bh=M407onLK2mqpOgnXCBUnGsRyi/aiFxEPhpsZL7d0pG8=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=MnWReYKzA+1q3mB0FCeKc5q6tTrpn6Fq1u0o/t7dZeNGeAaCDkZzFNSdJYYq6v7x7 muKAnYTy3Or9RrpiSW7P98ZoROZVOHdwVYnKhWQeKDIS7Dq1iziDliuB1CHzko7eSf X8WZsZfz30dlZhmo8x02T1UTGItUsQX0zJrupCNI= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 41FBA0qV001868 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 15 Feb 2024 05:10:00 -0600 Received: from DLEE111.ent.ti.com (157.170.170.22) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Thu, 15 Feb 2024 05:10:00 -0600 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Thu, 15 Feb 2024 05:10:00 -0600 Received: from localhost (chintan-thinkstation-p360-tower.dhcp.ti.com [172.24.227.220]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 41FB9x73111243; Thu, 15 Feb 2024 05:09:59 -0600 From: Chintan Vankar To: Chintan Vankar , Dan Carpenter , Roger Quadros , Siddharth Vadapalli , Richard Cochran , Paolo Abeni , Jakub Kicinski , Eric Dumazet , "David S. Miller" CC: , Subject: [PATCH net-next 2/2] net: ethernet: ti: am65-cpsw: Enable RX HW timestamp only for PTP packets Date: Thu, 15 Feb 2024 16:39:53 +0530 Message-ID: <20240215110953.3225099-2-c-vankar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240215110953.3225099-1-c-vankar@ti.com> References: <20240215110953.3225099-1-c-vankar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790963891266593640 X-GMAIL-MSGID: 1790963891266593640 The CPSW peripherals on J7AHP, J7VCL, J7AEP, J7ES, AM64 SoCs have an errata i2401 "CPSW: Host Timestamps Cause CPSW Port to Lock up". As a workaround, Disable timestamping on all RX packets and timestamp only PTP packets. Set Time Sync Receive bits in Time Sync control register so that packets can be determined as a valid Ethernet Receive Event for time synchronization. Update the RX filter configuration to indicate Hardware Timestamping support only for PTP packets. Replace "am65_cpsw_rx_ts()" function with "am65_cpts_rx_timestamp()" function which timestamps only PTP packets. Fixes: b1f66a5bee07 ("net: ethernet: ti: am65-cpsw-nuss: enable packet timestamping support") Signed-off-by: Chintan Vankar --- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 51 +++++++++++------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index 9d2f4ac783e4..ab843fb64b93 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c @@ -101,6 +101,12 @@ #define AM65_CPSW_PN_TS_CTL_TX_HOST_TS_EN BIT(11) #define AM65_CPSW_PN_TS_CTL_MSG_TYPE_EN_SHIFT 16 +#define AM65_CPSW_PN_TS_CTL_RX_ANX_F_EN BIT(0) +#define AM65_CPSW_PN_TS_CTL_RX_VLAN_LT1_EN BIT(1) +#define AM65_CPSW_PN_TS_CTL_RX_VLAN_LT2_EN BIT(2) +#define AM65_CPSW_PN_TS_CTL_RX_ANX_D_EN BIT(3) +#define AM65_CPSW_PN_TS_CTL_RX_ANX_E_EN BIT(9) + /* AM65_CPSW_PORTN_REG_TS_SEQ_LTYPE_REG register fields */ #define AM65_CPSW_PN_TS_SEQ_ID_OFFSET_SHIFT 16 @@ -124,6 +130,11 @@ AM65_CPSW_PN_TS_CTL_TX_ANX_E_EN | \ AM65_CPSW_PN_TS_CTL_TX_ANX_F_EN) +#define AM65_CPSW_TS_RX_ANX_ALL_EN \ + (AM65_CPSW_PN_TS_CTL_RX_ANX_D_EN | \ + AM65_CPSW_PN_TS_CTL_RX_ANX_E_EN | \ + AM65_CPSW_PN_TS_CTL_RX_ANX_F_EN) + #define AM65_CPSW_ALE_AGEOUT_DEFAULT 30 /* Number of TX/RX descriptors */ #define AM65_CPSW_MAX_TX_DESC 500 @@ -749,18 +760,6 @@ static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev) return ret; } -static void am65_cpsw_nuss_rx_ts(struct sk_buff *skb, u32 *psdata) -{ - struct skb_shared_hwtstamps *ssh; - u64 ns; - - ns = ((u64)psdata[1] << 32) | psdata[0]; - - ssh = skb_hwtstamps(skb); - memset(ssh, 0, sizeof(*ssh)); - ssh->hwtstamp = ns_to_ktime(ns); -} - /* RX psdata[2] word format - checksum information */ #define AM65_CPSW_RX_PSD_CSUM_ADD GENMASK(15, 0) #define AM65_CPSW_RX_PSD_CSUM_ERR BIT(16) @@ -841,9 +840,6 @@ static int am65_cpsw_nuss_rx_packets(struct am65_cpsw_common *common, skb->dev = ndev; psdata = cppi5_hdesc_get_psdata(desc_rx); - /* add RX timestamp */ - if (port->rx_ts_enabled) - am65_cpsw_nuss_rx_ts(skb, psdata); csum_info = psdata[2]; dev_dbg(dev, "%s rx csum_info:%#x\n", __func__, csum_info); @@ -856,6 +852,9 @@ static int am65_cpsw_nuss_rx_packets(struct am65_cpsw_common *common, ndev_priv = netdev_priv(ndev); am65_cpsw_nuss_set_offload_fwd_mark(skb, ndev_priv->offload_fwd_mark); skb_put(skb, pkt_len); + skb_reset_mac_header(skb); + if (port->rx_ts_enabled) + am65_cpts_rx_timestamp(common->cpts, skb); skb->protocol = eth_type_trans(skb, ndev); am65_cpsw_nuss_rx_csum(skb, csum_info); napi_gro_receive(&common->napi_rx, skb); @@ -1334,7 +1333,6 @@ static int am65_cpsw_nuss_ndo_slave_set_mac_address(struct net_device *ndev, static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr) { - struct am65_cpsw_common *common = am65_ndev_to_common(ndev); struct am65_cpsw_port *port = am65_ndev_to_port(ndev); u32 ts_ctrl, seq_id, ts_ctrl_ltype2, ts_vlan_ltype; struct hwtstamp_config cfg; @@ -1358,11 +1356,6 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev, case HWTSTAMP_FILTER_NONE: port->rx_ts_enabled = false; break; - case HWTSTAMP_FILTER_ALL: - case HWTSTAMP_FILTER_SOME: - case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: - case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: - case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: @@ -1372,10 +1365,13 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev, case HWTSTAMP_FILTER_PTP_V2_EVENT: case HWTSTAMP_FILTER_PTP_V2_SYNC: case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: - case HWTSTAMP_FILTER_NTP_ALL: port->rx_ts_enabled = true; - cfg.rx_filter = HWTSTAMP_FILTER_ALL; + cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; break; + case HWTSTAMP_FILTER_ALL: + case HWTSTAMP_FILTER_SOME: + case HWTSTAMP_FILTER_NTP_ALL: + return -EOPNOTSUPP; default: return -ERANGE; } @@ -1405,6 +1401,10 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev, ts_ctrl |= AM65_CPSW_TS_TX_ANX_ALL_EN | AM65_CPSW_PN_TS_CTL_TX_VLAN_LT1_EN; + if (port->rx_ts_enabled) + ts_ctrl |= AM65_CPSW_TS_RX_ANX_ALL_EN | + AM65_CPSW_PN_TS_CTL_RX_VLAN_LT1_EN; + writel(seq_id, port->port_base + AM65_CPSW_PORTN_REG_TS_SEQ_LTYPE_REG); writel(ts_vlan_ltype, port->port_base + AM65_CPSW_PORTN_REG_TS_VLAN_LTYPE_REG); @@ -1412,9 +1412,6 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev, AM65_CPSW_PORTN_REG_TS_CTL_LTYPE2); writel(ts_ctrl, port->port_base + AM65_CPSW_PORTN_REG_TS_CTL); - /* en/dis RX timestamp */ - am65_cpts_rx_enable(common->cpts, port->rx_ts_enabled); - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; } @@ -1431,7 +1428,7 @@ static int am65_cpsw_nuss_hwtstamp_get(struct net_device *ndev, cfg.tx_type = port->tx_ts_enabled ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; cfg.rx_filter = port->rx_ts_enabled ? - HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE; + HWTSTAMP_FILTER_PTP_V2_EVENT : HWTSTAMP_FILTER_NONE; return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; }