From patchwork Fri Mar 20 19:42:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 222139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8129C4332B for ; Fri, 20 Mar 2020 19:43:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80DF820777 for ; Fri, 20 Mar 2020 19:43:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Kl5EHs9a" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727129AbgCTTnF (ORCPT ); Fri, 20 Mar 2020 15:43:05 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:35444 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726783AbgCTTnE (ORCPT ); Fri, 20 Mar 2020 15:43:04 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02KJgx1X086970; Fri, 20 Mar 2020 14:42:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584733379; bh=NC3leWhnM/4NIc8QyBQa2tN7YReyUOftwpbx33+WJHM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Kl5EHs9afy71sEPOJimxKkF/ju/ZOzGPsWIDDdkdgLoa45OHIsRpgWM6FJkJnjZXe di9w66jSsFVHQkH0rKURjEZCLMKtv7drysqsBfl+P/WqvBsZ7dMFONo5g41sxIMQ33 cKMGLlXAPz6RGetm1XNuhGWFOQqyWrDENrgK7J4c= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02KJgxgA113697 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 20 Mar 2020 14:42:59 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 20 Mar 2020 14:42:59 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Fri, 20 Mar 2020 14:42:59 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02KJgwLV044048; Fri, 20 Mar 2020 14:42:59 -0500 From: Grygorii Strashko To: "David S . Miller" , Richard Cochran , Lokesh Vutla , Tony Lindgren CC: Sekhar Nori , Murali Karicheri , netdev , , , Grygorii Strashko Subject: [PATCH net-next v3 01/11] net: ethernet: ti: cpts: use dev_yy() api for logs Date: Fri, 20 Mar 2020 21:42:34 +0200 Message-ID: <20200320194244.4703-2-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320194244.4703-1-grygorii.strashko@ti.com> References: <20200320194244.4703-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use dev_yy() API instead of pr_yy() for log outputs. Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpts.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index 729ce09dded9..f07b40504e5b 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -71,7 +71,7 @@ static int cpts_purge_events(struct cpts *cpts) } if (removed) - pr_debug("cpts: event pool cleaned up %d\n", removed); + dev_dbg(cpts->dev, "cpts: event pool cleaned up %d\n", removed); return removed ? 0 : -1; } @@ -150,7 +150,7 @@ static int cpts_fifo_read(struct cpts *cpts, int match) break; if (list_empty(&cpts->pool) && cpts_purge_events(cpts)) { - pr_err("cpts: event pool empty\n"); + dev_info(cpts->dev, "cpts: event pool empty\n"); return -1; } @@ -178,7 +178,7 @@ static int cpts_fifo_read(struct cpts *cpts, int match) case CPTS_EV_HW: break; default: - pr_err("cpts: unknown event type\n"); + dev_err(cpts->dev, "cpts: unknown event type\n"); break; } if (type == match) @@ -196,7 +196,7 @@ static u64 cpts_systim_read(const struct cyclecounter *cc) cpts_write32(cpts, TS_PUSH, ts_push); if (cpts_fifo_read(cpts, CPTS_EV_PUSH)) - pr_err("cpts: unable to obtain a time stamp\n"); + dev_err(cpts->dev, "cpts: unable to obtain a time stamp\n"); list_for_each_safe(this, next, &cpts->events) { event = list_entry(this, struct cpts_event, list); @@ -307,8 +307,8 @@ static long cpts_overflow_check(struct ptp_clock_info *ptp) } spin_unlock_irqrestore(&cpts->lock, flags); - pr_debug("cpts overflow check at %lld.%09ld\n", - (long long)ts.tv_sec, ts.tv_nsec); + dev_dbg(cpts->dev, "cpts overflow check at %lld.%09ld\n", + (long long)ts.tv_sec, ts.tv_nsec); return (long)delay; } From patchwork Fri Mar 20 19:42:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 222137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40127C4332E for ; Fri, 20 Mar 2020 19:43:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18F0D20782 for ; Fri, 20 Mar 2020 19:43:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="SiKyu5hY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727190AbgCTTnO (ORCPT ); Fri, 20 Mar 2020 15:43:14 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:44702 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726783AbgCTTnN (ORCPT ); Fri, 20 Mar 2020 15:43:13 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02KJh6PP018559; Fri, 20 Mar 2020 14:43:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584733387; bh=r65crBqSQyMLYoz3u50e2Ikb848eo23JjhikeJXrBxA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=SiKyu5hY3up2ajwl4kPZGoY2euC+DzuDeG/7Dx04H90bsO+45sy4gazOJPCc3pAM4 lIqatNvVe+LctZ/RYpWhx2+fSUyxvuNSpQnr3zm8Vukgqvn9Lgm//uZWZKAYJKJoNK KK8gtwagrpZDIj39dcl3DlKSHTGzrgGwMdRMzMR8= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02KJh6pQ114216 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 20 Mar 2020 14:43:06 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 20 Mar 2020 14:43:06 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Fri, 20 Mar 2020 14:43:06 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02KJh53U042903; Fri, 20 Mar 2020 14:43:06 -0500 From: Grygorii Strashko To: "David S . Miller" , Richard Cochran , Lokesh Vutla , Tony Lindgren CC: Sekhar Nori , Murali Karicheri , netdev , , , Grygorii Strashko Subject: [PATCH net-next v3 02/11] net: ethernet: ti: cpts: separate hw counter read from timecounter Date: Fri, 20 Mar 2020 21:42:35 +0200 Message-ID: <20200320194244.4703-3-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320194244.4703-1-grygorii.strashko@ti.com> References: <20200320194244.4703-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Separate hw counter read from timecounter code: - add CPTS context field to store current HW counter value - move HW timestamp request and FIFO read code out of timecounter code - convert cyc2time on event reception in cpts_fifo_read() - call timecounter_read() in cpts_fifo_read() to update tk->cycle_last Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpts.c | 53 +++++++++++++++++----------------- drivers/net/ethernet/ti/cpts.h | 2 ++ 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index f07b40504e5b..6a1844cd23ff 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -112,10 +112,8 @@ static bool cpts_match_tx_ts(struct cpts *cpts, struct cpts_event *event) (struct cpts_skb_cb_data *)skb->cb; if (cpts_match(skb, class, seqid, mtype)) { - u64 ns = timecounter_cyc2time(&cpts->tc, event->low); - memset(&ssh, 0, sizeof(ssh)); - ssh.hwtstamp = ns_to_ktime(ns); + ssh.hwtstamp = ns_to_ktime(event->timestamp); skb_tstamp_tx(skb, &ssh); found = true; __skb_unlink(skb, &cpts->txq); @@ -158,8 +156,16 @@ static int cpts_fifo_read(struct cpts *cpts, int match) event->tmo = jiffies + 2; event->high = hi; event->low = lo; + event->timestamp = timecounter_cyc2time(&cpts->tc, event->low); type = event_type(event); + + dev_dbg(cpts->dev, "CPTS_EV: %d high:%08X low:%08x\n", + type, event->high, event->low); switch (type) { + case CPTS_EV_PUSH: + WRITE_ONCE(cpts->cur_timestamp, lo); + timecounter_read(&cpts->tc); + break; case CPTS_EV_TX: if (cpts_match_tx_ts(cpts, event)) { /* if the new event matches an existing skb, @@ -168,7 +174,6 @@ static int cpts_fifo_read(struct cpts *cpts, int match) break; } /* fall through */ - case CPTS_EV_PUSH: case CPTS_EV_RX: list_del_init(&event->list); list_add_tail(&event->list, &cpts->events); @@ -189,26 +194,17 @@ static int cpts_fifo_read(struct cpts *cpts, int match) static u64 cpts_systim_read(const struct cyclecounter *cc) { - u64 val = 0; - struct cpts_event *event; - struct list_head *this, *next; struct cpts *cpts = container_of(cc, struct cpts, cc); - cpts_write32(cpts, TS_PUSH, ts_push); - if (cpts_fifo_read(cpts, CPTS_EV_PUSH)) - dev_err(cpts->dev, "cpts: unable to obtain a time stamp\n"); + return READ_ONCE(cpts->cur_timestamp); +} - list_for_each_safe(this, next, &cpts->events) { - event = list_entry(this, struct cpts_event, list); - if (event_type(event) == CPTS_EV_PUSH) { - list_del_init(&event->list); - list_add(&event->list, &cpts->pool); - val = event->low; - break; - } - } +static void cpts_update_cur_time(struct cpts *cpts, int match) +{ + cpts_write32(cpts, TS_PUSH, ts_push); - return val; + if (cpts_fifo_read(cpts, match) && match != -1) + dev_err(cpts->dev, "cpts: unable to obtain a time stamp\n"); } /* PTP clock operations */ @@ -232,7 +228,7 @@ static int cpts_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) spin_lock_irqsave(&cpts->lock, flags); - timecounter_read(&cpts->tc); + cpts_update_cur_time(cpts, CPTS_EV_PUSH); cpts->cc.mult = neg_adj ? mult - diff : mult + diff; @@ -260,6 +256,9 @@ static int cpts_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) struct cpts *cpts = container_of(ptp, struct cpts, info); spin_lock_irqsave(&cpts->lock, flags); + + cpts_update_cur_time(cpts, CPTS_EV_PUSH); + ns = timecounter_read(&cpts->tc); spin_unlock_irqrestore(&cpts->lock, flags); @@ -294,11 +293,14 @@ static long cpts_overflow_check(struct ptp_clock_info *ptp) { struct cpts *cpts = container_of(ptp, struct cpts, info); unsigned long delay = cpts->ov_check_period; - struct timespec64 ts; unsigned long flags; + u64 ns; spin_lock_irqsave(&cpts->lock, flags); - ts = ns_to_timespec64(timecounter_read(&cpts->tc)); + + cpts_update_cur_time(cpts, -1); + + ns = timecounter_read(&cpts->tc); if (!skb_queue_empty(&cpts->txq)) { cpts_purge_txq(cpts); @@ -307,8 +309,7 @@ static long cpts_overflow_check(struct ptp_clock_info *ptp) } spin_unlock_irqrestore(&cpts->lock, flags); - dev_dbg(cpts->dev, "cpts overflow check at %lld.%09ld\n", - (long long)ts.tv_sec, ts.tv_nsec); + dev_dbg(cpts->dev, "cpts overflow check at %lld\n", ns); return (long)delay; } @@ -390,7 +391,7 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type) seqid = (event->high >> SEQUENCE_ID_SHIFT) & SEQUENCE_ID_MASK; if (ev_type == event_type(event) && cpts_match(skb, class, seqid, mtype)) { - ns = timecounter_cyc2time(&cpts->tc, event->low); + ns = event->timestamp; list_del_init(&event->list); list_add(&event->list, &cpts->pool); break; diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h index bb997c11ee15..32ecd1ce4d3b 100644 --- a/drivers/net/ethernet/ti/cpts.h +++ b/drivers/net/ethernet/ti/cpts.h @@ -94,6 +94,7 @@ struct cpts_event { unsigned long tmo; u32 high; u32 low; + u64 timestamp; }; struct cpts { @@ -114,6 +115,7 @@ struct cpts { struct cpts_event pool_data[CPTS_MAX_EVENTS]; unsigned long ov_check_period; struct sk_buff_head txq; + u64 cur_timestamp; }; void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb); From patchwork Fri Mar 20 19:42:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 222136 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C30AEC4332B for ; Fri, 20 Mar 2020 19:43:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9A4D920782 for ; Fri, 20 Mar 2020 19:43:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="gS57sK/P" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727426AbgCTTnp (ORCPT ); Fri, 20 Mar 2020 15:43:45 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:39996 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727152AbgCTTnO (ORCPT ); Fri, 20 Mar 2020 15:43:14 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02KJhAaI027949; Fri, 20 Mar 2020 14:43:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584733390; bh=j9ewmM7hESI6g6wk0ydAH0XJIu7pbzNMSXUh1AYtGvM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=gS57sK/P3Kdhzv/95mOjc7FaOW2DuEYZDWHmZ9JOEf4merbotbb8fqQEzF4dAlJpM ETrFTvl7LXXp+GYd3D6ZbU4+Px2D8XlkAnS+3pb5NXHTGHy8q7ueKkVD54NKCl0mCM noW7B0vv82uSsH0nME4hQkpCLi/dzeH7QboOpQ4Y= Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02KJhAFU018688 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 20 Mar 2020 14:43:10 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 20 Mar 2020 14:43:10 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Fri, 20 Mar 2020 14:43:10 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02KJh9ua073749; Fri, 20 Mar 2020 14:43:09 -0500 From: Grygorii Strashko To: "David S . Miller" , Richard Cochran , Lokesh Vutla , Tony Lindgren CC: Sekhar Nori , Murali Karicheri , netdev , , , Grygorii Strashko Subject: [PATCH net-next v3 04/11] net: ethernet: ti: cpts: switch to use new .gettimex64() interface Date: Fri, 20 Mar 2020 21:42:37 +0200 Message-ID: <20200320194244.4703-5-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320194244.4703-1-grygorii.strashko@ti.com> References: <20200320194244.4703-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The CPTS HW latches and saves CPTS counter value in CPTS fifo immediately after writing to CPSW_CPTS_PUSH.TS_PUSH (bit 0), so the total time that the driver needs to read the CPTS timestamp is the time required CPSW_CPTS_PUSH write to actually reach HW. Hence switch CPTS driver to implement new .gettimex64() callback for more precise measurement of the offset between a PHC and the system clock which is measured as time between write(CPSW_CPTS_PUSH) read(CPSW_CPTS_PUSH) Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpts.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index e6a8ccae711c..7e4c1de0d207 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -203,9 +203,13 @@ static u64 cpts_systim_read(const struct cyclecounter *cc) return READ_ONCE(cpts->cur_timestamp); } -static void cpts_update_cur_time(struct cpts *cpts, int match) +static void cpts_update_cur_time(struct cpts *cpts, int match, + struct ptp_system_timestamp *sts) { + ptp_read_system_prets(sts); cpts_write32(cpts, TS_PUSH, ts_push); + cpts_read32(cpts, ts_push); + ptp_read_system_postts(sts); if (cpts_fifo_read(cpts, match) && match != -1) dev_err(cpts->dev, "cpts: unable to obtain a time stamp\n"); @@ -234,7 +238,7 @@ static int cpts_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) cpts->mult_new = neg_adj ? mult - diff : mult + diff; - cpts_update_cur_time(cpts, CPTS_EV_PUSH); + cpts_update_cur_time(cpts, CPTS_EV_PUSH, NULL); spin_unlock_irqrestore(&cpts->lock, flags); @@ -253,15 +257,17 @@ static int cpts_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) return 0; } -static int cpts_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) +static int cpts_ptp_gettimeex(struct ptp_clock_info *ptp, + struct timespec64 *ts, + struct ptp_system_timestamp *sts) { - u64 ns; - unsigned long flags; struct cpts *cpts = container_of(ptp, struct cpts, info); + unsigned long flags; + u64 ns; spin_lock_irqsave(&cpts->lock, flags); - cpts_update_cur_time(cpts, CPTS_EV_PUSH); + cpts_update_cur_time(cpts, CPTS_EV_PUSH, sts); ns = timecounter_read(&cpts->tc); spin_unlock_irqrestore(&cpts->lock, flags); @@ -302,7 +308,7 @@ static long cpts_overflow_check(struct ptp_clock_info *ptp) spin_lock_irqsave(&cpts->lock, flags); - cpts_update_cur_time(cpts, -1); + cpts_update_cur_time(cpts, -1, NULL); ns = timecounter_read(&cpts->tc); @@ -326,7 +332,7 @@ static const struct ptp_clock_info cpts_info = { .pps = 0, .adjfreq = cpts_ptp_adjfreq, .adjtime = cpts_ptp_adjtime, - .gettime64 = cpts_ptp_gettime, + .gettimex64 = cpts_ptp_gettimeex, .settime64 = cpts_ptp_settime, .enable = cpts_ptp_enable, .do_aux_work = cpts_overflow_check, From patchwork Fri Mar 20 19:42:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 222138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7D18C4332D for ; Fri, 20 Mar 2020 19:43:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8178920784 for ; Fri, 20 Mar 2020 19:43:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="aleudaF3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727301AbgCTTnW (ORCPT ); Fri, 20 Mar 2020 15:43:22 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:40012 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727257AbgCTTnW (ORCPT ); Fri, 20 Mar 2020 15:43:22 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02KJhHiw027971; Fri, 20 Mar 2020 14:43:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584733397; bh=OwrvzD0aVDA6B1hUvxViFQH5xN1/WUuimg+JwH5BZPA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=aleudaF3H54Wy7r4731RDOrlaDJqRuUAWA/+A6oVCouTvtPCKwPmYLI1RNcUCQcc2 HTuCZr5YZ0nPoqlZTklv6o3pxFn8R7dm/ln7WH6vxBy4hOszHSxvFZdLAZsPdaw+kL P2Qp/QT8AcE7QCNc8GpZ/eXBoV9ff6mnyddaBVAY= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02KJhH4X010497; Fri, 20 Mar 2020 14:43:17 -0500 Received: from DFLE100.ent.ti.com (10.64.6.21) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 20 Mar 2020 14:43:17 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Fri, 20 Mar 2020 14:43:17 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02KJhGVM043117; Fri, 20 Mar 2020 14:43:16 -0500 From: Grygorii Strashko To: "David S . Miller" , Richard Cochran , Lokesh Vutla , Tony Lindgren CC: Sekhar Nori , Murali Karicheri , netdev , , , Grygorii Strashko Subject: [PATCH net-next v3 05/11] net: ethernet: ti: cpts: optimize packet to event matching Date: Fri, 20 Mar 2020 21:42:38 +0200 Message-ID: <20200320194244.4703-6-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320194244.4703-1-grygorii.strashko@ti.com> References: <20200320194244.4703-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Now the CPTS driver performs packet (skb) parsing every time when it needs to match packet to CPTS event (including ptp_classify_raw() calls). This patch optimizes matching process by parsing packet only once upon arrival and stores PTP specific data in skb->cb using the same fromat as in CPTS HW event. As result, all future matching reduces to comparing two u32 values. Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpts.c | 91 ++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index 7e4c1de0d207..f7ce482ad09c 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -23,15 +23,13 @@ #define CPTS_SKB_TX_WORK_TIMEOUT 1 /* jiffies */ struct cpts_skb_cb_data { + u32 skb_mtype_seqid; unsigned long tmo; }; #define cpts_read32(c, r) readl_relaxed(&c->reg->r) #define cpts_write32(c, v, r) writel_relaxed(v, &c->reg->r) -static int cpts_match(struct sk_buff *skb, unsigned int ptp_class, - u16 ts_seqid, u8 ts_msgtype); - static int event_expired(struct cpts_event *event) { return time_after(jiffies, event->tmo); @@ -97,29 +95,29 @@ static void cpts_purge_txq(struct cpts *cpts) static bool cpts_match_tx_ts(struct cpts *cpts, struct cpts_event *event) { struct sk_buff *skb, *tmp; - u16 seqid; - u8 mtype; bool found = false; + u32 mtype_seqid; - mtype = (event->high >> MESSAGE_TYPE_SHIFT) & MESSAGE_TYPE_MASK; - seqid = (event->high >> SEQUENCE_ID_SHIFT) & SEQUENCE_ID_MASK; + mtype_seqid = event->high & + ((MESSAGE_TYPE_MASK << MESSAGE_TYPE_SHIFT) | + (SEQUENCE_ID_MASK << SEQUENCE_ID_SHIFT) | + (EVENT_TYPE_MASK << EVENT_TYPE_SHIFT)); /* no need to grab txq.lock as access is always done under cpts->lock */ skb_queue_walk_safe(&cpts->txq, skb, tmp) { struct skb_shared_hwtstamps ssh; - unsigned int class = ptp_classify_raw(skb); struct cpts_skb_cb_data *skb_cb = (struct cpts_skb_cb_data *)skb->cb; - if (cpts_match(skb, class, seqid, mtype)) { + if (mtype_seqid == skb_cb->skb_mtype_seqid) { memset(&ssh, 0, sizeof(ssh)); ssh.hwtstamp = ns_to_ktime(event->timestamp); skb_tstamp_tx(skb, &ssh); found = true; __skb_unlink(skb, &cpts->txq); dev_consume_skb_any(skb); - dev_dbg(cpts->dev, "match tx timestamp mtype %u seqid %04x\n", - mtype, seqid); + dev_dbg(cpts->dev, "match tx timestamp mtype_seqid %08x\n", + mtype_seqid); break; } @@ -338,12 +336,15 @@ static const struct ptp_clock_info cpts_info = { .do_aux_work = cpts_overflow_check, }; -static int cpts_match(struct sk_buff *skb, unsigned int ptp_class, - u16 ts_seqid, u8 ts_msgtype) +static int cpts_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid) { - u16 *seqid; - unsigned int offset = 0; + unsigned int ptp_class = ptp_classify_raw(skb); u8 *msgtype, *data = skb->data; + unsigned int offset = 0; + u16 *seqid; + + if (ptp_class == PTP_CLASS_NONE) + return 0; if (ptp_class & PTP_CLASS_VLAN) offset += VLAN_HLEN; @@ -371,22 +372,20 @@ static int cpts_match(struct sk_buff *skb, unsigned int ptp_class, msgtype = data + offset; seqid = (u16 *)(data + offset + OFF_PTP_SEQUENCE_ID); + *mtype_seqid = (*msgtype & MESSAGE_TYPE_MASK) << MESSAGE_TYPE_SHIFT; + *mtype_seqid |= (ntohs(*seqid) & SEQUENCE_ID_MASK) << SEQUENCE_ID_SHIFT; - return (ts_msgtype == (*msgtype & 0xf) && ts_seqid == ntohs(*seqid)); + return 1; } -static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type) +static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, + int ev_type, u32 skb_mtype_seqid) { - u64 ns = 0; - struct cpts_event *event; struct list_head *this, *next; - unsigned int class = ptp_classify_raw(skb); + struct cpts_event *event; unsigned long flags; - u16 seqid; - u8 mtype; - - if (class == PTP_CLASS_NONE) - return 0; + u32 mtype_seqid; + u64 ns = 0; spin_lock_irqsave(&cpts->lock, flags); cpts_fifo_read(cpts, -1); @@ -397,10 +396,13 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type) list_add(&event->list, &cpts->pool); continue; } - mtype = (event->high >> MESSAGE_TYPE_SHIFT) & MESSAGE_TYPE_MASK; - seqid = (event->high >> SEQUENCE_ID_SHIFT) & SEQUENCE_ID_MASK; - if (ev_type == event_type(event) && - cpts_match(skb, class, seqid, mtype)) { + + mtype_seqid = event->high & + ((MESSAGE_TYPE_MASK << MESSAGE_TYPE_SHIFT) | + (SEQUENCE_ID_MASK << SEQUENCE_ID_SHIFT) | + (EVENT_TYPE_MASK << EVENT_TYPE_SHIFT)); + + if (mtype_seqid == skb_mtype_seqid) { ns = event->timestamp; list_del_init(&event->list); list_add(&event->list, &cpts->pool); @@ -427,10 +429,21 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type) void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb) { - u64 ns; + struct cpts_skb_cb_data *skb_cb = (struct cpts_skb_cb_data *)skb->cb; struct skb_shared_hwtstamps *ssh; + int ret; + u64 ns; + + ret = cpts_skb_get_mtype_seqid(skb, &skb_cb->skb_mtype_seqid); + if (!ret) + return; + + skb_cb->skb_mtype_seqid |= (CPTS_EV_RX << EVENT_TYPE_SHIFT); - ns = cpts_find_ts(cpts, skb, CPTS_EV_RX); + dev_dbg(cpts->dev, "%s mtype seqid %08x\n", + __func__, skb_cb->skb_mtype_seqid); + + ns = cpts_find_ts(cpts, skb, CPTS_EV_RX, skb_cb->skb_mtype_seqid); if (!ns) return; ssh = skb_hwtstamps(skb); @@ -441,12 +454,24 @@ EXPORT_SYMBOL_GPL(cpts_rx_timestamp); void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb) { - u64 ns; + struct cpts_skb_cb_data *skb_cb = (struct cpts_skb_cb_data *)skb->cb; struct skb_shared_hwtstamps ssh; + int ret; + u64 ns; if (!(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) return; - ns = cpts_find_ts(cpts, skb, CPTS_EV_TX); + + ret = cpts_skb_get_mtype_seqid(skb, &skb_cb->skb_mtype_seqid); + if (!ret) + return; + + skb_cb->skb_mtype_seqid |= (CPTS_EV_TX << EVENT_TYPE_SHIFT); + + dev_dbg(cpts->dev, "%s mtype seqid %08x\n", + __func__, skb_cb->skb_mtype_seqid); + + ns = cpts_find_ts(cpts, skb, CPTS_EV_TX, skb_cb->skb_mtype_seqid); if (!ns) return; memset(&ssh, 0, sizeof(ssh)); From patchwork Fri Mar 20 19:42:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 222134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 934C8C4332D for ; Fri, 20 Mar 2020 19:44:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 576CE20781 for ; Fri, 20 Mar 2020 19:44:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="hY1Ljkdx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727406AbgCTTno (ORCPT ); Fri, 20 Mar 2020 15:43:44 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:35508 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbgCTTnn (ORCPT ); Fri, 20 Mar 2020 15:43:43 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02KJhdaR087093; Fri, 20 Mar 2020 14:43:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584733419; bh=jI2fN+Ky2ml2ahcXSc62hr/ZOdFJMFo2kttKunfy3vg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=hY1LjkdxPCF7930zuTeXjcjhOHiSSJQoHPFR1bFJsxI4Wv+a47QX8ufOtQWfjL+iT ssM75LQK4GsiiyDYzC/oETZR6NwMFvNv1TsV4K16IhcfV5DmFk/x6nHTyNa3r41x3b AuGukYUKJgEy/QQprCSQt+VLPw38eqzAOo0+lxpI= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02KJhdP9019057 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 20 Mar 2020 14:43:39 -0500 Received: from DFLE100.ent.ti.com (10.64.6.21) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 20 Mar 2020 14:43:39 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Fri, 20 Mar 2020 14:43:39 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02KJhc3h043381; Fri, 20 Mar 2020 14:43:39 -0500 From: Grygorii Strashko To: "David S . Miller" , Richard Cochran , Lokesh Vutla , Tony Lindgren CC: Sekhar Nori , Murali Karicheri , netdev , , , Grygorii Strashko Subject: [PATCH net-next v3 08/11] net: ethernet: ti: cpts: move rx timestamp processing to ptp worker only Date: Fri, 20 Mar 2020 21:42:41 +0200 Message-ID: <20200320194244.4703-9-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320194244.4703-1-grygorii.strashko@ti.com> References: <20200320194244.4703-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Once CPTS IRQ will be enabled the CPTS irq handler may compete with netif RX sofirq path and so RX timestamp might not be ready at the moment packet is processed. As result, packet has to be deferred and processed later. This patch moves RX timestamp processing tx timestamp processing to PTP worker always the same way as it's been done for TX timestamps. napi_rx->cpts_rx_timestamp if ptp_packet then push to rxq ptp_schedule_worker() do_aux_work->cpts_overflow_check cpts_process_events() Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpsw.c | 14 +-- drivers/net/ethernet/ti/cpsw_new.c | 13 ++- drivers/net/ethernet/ti/cpts.c | 132 ++++++++++++++++++----------- drivers/net/ethernet/ti/cpts.h | 6 +- 4 files changed, 106 insertions(+), 59 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index c2c5bf87da01..ce2155394830 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -433,17 +433,21 @@ static void cpsw_rx_handler(void *token, int len, int status) skb->dev = ndev; if (status & CPDMA_RX_VLAN_ENCAP) cpsw_rx_vlan_encap(skb); - if (priv->rx_ts_enabled) - cpts_rx_timestamp(cpsw->cpts, skb); - skb->protocol = eth_type_trans(skb, ndev); /* unmap page as no netstack skb page recycling */ page_pool_release_page(pool, page); - netif_receive_skb(skb); - ndev->stats.rx_bytes += len; ndev->stats.rx_packets++; + ret = 0; + if (priv->rx_ts_enabled) + ret = cpts_rx_timestamp(cpsw->cpts, skb); + + if (!ret) { + skb->protocol = eth_type_trans(skb, ndev); + netif_receive_skb(skb); + } + requeue: xmeta = page_address(new_page) + CPSW_XMETA_OFFSET; xmeta->ndev = ndev; diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c index 9209e613257d..8561f0e3b769 100644 --- a/drivers/net/ethernet/ti/cpsw_new.c +++ b/drivers/net/ethernet/ti/cpsw_new.c @@ -375,17 +375,22 @@ static void cpsw_rx_handler(void *token, int len, int status) skb->dev = ndev; if (status & CPDMA_RX_VLAN_ENCAP) cpsw_rx_vlan_encap(skb); - if (priv->rx_ts_enabled) - cpts_rx_timestamp(cpsw->cpts, skb); - skb->protocol = eth_type_trans(skb, ndev); /* unmap page as no netstack skb page recycling */ page_pool_release_page(pool, page); - netif_receive_skb(skb); ndev->stats.rx_bytes += len; ndev->stats.rx_packets++; + ret = 0; + if (priv->rx_ts_enabled) + ret = cpts_rx_timestamp(cpsw->cpts, skb); + + if (!ret) { + skb->protocol = eth_type_trans(skb, ndev); + netif_receive_skb(skb); + } + requeue: xmeta = page_address(new_page) + CPSW_XMETA_OFFSET; xmeta->ndev = ndev; diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index 3cfa0f78287b..fe70eb677b88 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -311,6 +311,66 @@ static bool cpts_match_tx_ts(struct cpts *cpts, struct cpts_event *event) return found; } +static bool cpts_match_rx_ts(struct cpts *cpts, struct cpts_event *event) +{ + struct sk_buff_head rxq_list; + struct sk_buff_head tempq; + struct sk_buff *skb, *tmp; + unsigned long flags; + bool found = false; + u32 mtype_seqid; + + mtype_seqid = event->high & + ((MESSAGE_TYPE_MASK << MESSAGE_TYPE_SHIFT) | + (SEQUENCE_ID_MASK << SEQUENCE_ID_SHIFT) | + (EVENT_TYPE_MASK << EVENT_TYPE_SHIFT)); + + __skb_queue_head_init(&rxq_list); + __skb_queue_head_init(&tempq); + + spin_lock_irqsave(&cpts->rxq.lock, flags); + skb_queue_splice_init(&cpts->rxq, &rxq_list); + spin_unlock_irqrestore(&cpts->rxq.lock, flags); + + skb_queue_walk_safe(&rxq_list, skb, tmp) { + struct skb_shared_hwtstamps *ssh; + struct cpts_skb_cb_data *skb_cb = + (struct cpts_skb_cb_data *)skb->cb; + + if (mtype_seqid == skb_cb->skb_mtype_seqid) { + __skb_unlink(skb, &rxq_list); + ssh = skb_hwtstamps(skb); + memset(ssh, 0, sizeof(*ssh)); + ssh->hwtstamp = ns_to_ktime(event->timestamp); + found = true; + dev_dbg(cpts->dev, "match rx timestamp mtype_seqid %08x\n", + mtype_seqid); + __skb_queue_tail(&tempq, skb); + break; + } + + if (time_after(jiffies, skb_cb->tmo)) { + /* timeout any expired skbs */ + dev_dbg(cpts->dev, "expiring rx timestamp\n"); + __skb_unlink(skb, &rxq_list); + __skb_queue_tail(&tempq, skb); + } + } + + spin_lock_irqsave(&cpts->rxq.lock, flags); + skb_queue_splice(&rxq_list, &cpts->rxq); + spin_unlock_irqrestore(&cpts->rxq.lock, flags); + + local_bh_disable(); + while ((skb = __skb_dequeue(&tempq))) { + skb->protocol = eth_type_trans(skb, skb->dev); + netif_receive_skb(skb); + } + local_bh_enable(); + + return found; +} + static void cpts_process_events(struct cpts *cpts) { struct list_head *this, *next; @@ -318,6 +378,7 @@ static void cpts_process_events(struct cpts *cpts) LIST_HEAD(events_free); unsigned long flags; LIST_HEAD(events); + int type; spin_lock_irqsave(&cpts->lock, flags); list_splice_init(&cpts->events, &events); @@ -325,8 +386,18 @@ static void cpts_process_events(struct cpts *cpts) list_for_each_safe(this, next, &events) { event = list_entry(this, struct cpts_event, list); - if (cpts_match_tx_ts(cpts, event) || - time_after(jiffies, event->tmo)) { + type = event_type(event); + + if (type == CPTS_EV_TX && + (cpts_match_tx_ts(cpts, event) || + time_after(jiffies, event->tmo))) { + list_del_init(&event->list); + list_add(&event->list, &events_free); + } + + if (type == CPTS_EV_RX && + (cpts_match_rx_ts(cpts, event) || + time_after(jiffies, event->tmo))) { list_del_init(&event->list); list_add(&event->list, &events_free); } @@ -422,64 +493,27 @@ static int cpts_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid) return 1; } -static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, - int ev_type, u32 skb_mtype_seqid) -{ - struct list_head *this, *next; - struct cpts_event *event; - unsigned long flags; - u32 mtype_seqid; - u64 ns = 0; - - cpts_fifo_read(cpts, -1); - spin_lock_irqsave(&cpts->lock, flags); - list_for_each_safe(this, next, &cpts->events) { - event = list_entry(this, struct cpts_event, list); - if (event_expired(event)) { - list_del_init(&event->list); - list_add(&event->list, &cpts->pool); - continue; - } - - mtype_seqid = event->high & - ((MESSAGE_TYPE_MASK << MESSAGE_TYPE_SHIFT) | - (SEQUENCE_ID_MASK << SEQUENCE_ID_SHIFT) | - (EVENT_TYPE_MASK << EVENT_TYPE_SHIFT)); - - 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 cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb) +int cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb) { struct cpts_skb_cb_data *skb_cb = (struct cpts_skb_cb_data *)skb->cb; - struct skb_shared_hwtstamps *ssh; int ret; - u64 ns; ret = cpts_skb_get_mtype_seqid(skb, &skb_cb->skb_mtype_seqid); if (!ret) - return; + return 0; skb_cb->skb_mtype_seqid |= (CPTS_EV_RX << EVENT_TYPE_SHIFT); dev_dbg(cpts->dev, "%s mtype seqid %08x\n", __func__, skb_cb->skb_mtype_seqid); - ns = cpts_find_ts(cpts, skb, 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); + /* Always defer RX TS processing to PTP worker */ + /* get the timestamp for timeouts */ + skb_cb->tmo = jiffies + msecs_to_jiffies(CPTS_SKB_RX_TX_TMO); + skb_queue_tail(&cpts->rxq, skb); + ptp_schedule_worker(cpts->clock, 0); + + return 1; } EXPORT_SYMBOL_GPL(cpts_rx_timestamp); @@ -514,6 +548,7 @@ int cpts_register(struct cpts *cpts) int err, i; skb_queue_head_init(&cpts->txq); + skb_queue_head_init(&cpts->rxq); INIT_LIST_HEAD(&cpts->events); INIT_LIST_HEAD(&cpts->pool); for (i = 0; i < CPTS_MAX_EVENTS; i++) @@ -556,6 +591,7 @@ void cpts_unregister(struct cpts *cpts) /* Drop all packet */ skb_queue_purge(&cpts->txq); + skb_queue_purge(&cpts->rxq); clk_disable(cpts->refclk); } diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h index f16e14d67f5f..d6069198e059 100644 --- a/drivers/net/ethernet/ti/cpts.h +++ b/drivers/net/ethernet/ti/cpts.h @@ -115,12 +115,13 @@ struct cpts { struct cpts_event pool_data[CPTS_MAX_EVENTS]; unsigned long ov_check_period; struct sk_buff_head txq; + struct sk_buff_head rxq; u64 cur_timestamp; u32 mult_new; struct mutex ptp_clk_mutex; /* sync PTP interface and worker */ }; -void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb); +int cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb); void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb); int cpts_register(struct cpts *cpts); void cpts_unregister(struct cpts *cpts); @@ -141,8 +142,9 @@ static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb) #else struct cpts; -static inline void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb) +static inline int cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb) { + return 0; } static inline void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb) { From patchwork Fri Mar 20 19:42:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 222135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9DDFC4332B for ; Fri, 20 Mar 2020 19:43:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B649820781 for ; Fri, 20 Mar 2020 19:43:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="yJhZTFK7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727471AbgCTTny (ORCPT ); Fri, 20 Mar 2020 15:43:54 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:44774 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727447AbgCTTnw (ORCPT ); Fri, 20 Mar 2020 15:43:52 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02KJhmBW018674; Fri, 20 Mar 2020 14:43:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584733428; bh=GPDfnTLXIFqL1TwhFk7bFb7bgEmGnFHMWKi6EbpWGnQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=yJhZTFK7bWrx6zwCM7papYKKLvnGKUq7n2u1ZgAywWMexQHlu0J1QekF8c4mTHJeQ OSBnPmfqkags1LWX8+R3GjarEyIzUxtax/bJitY2acKyWodHZb9HZ0LypyoaQhLSu6 DscgwggvHrnI4Sb8bLwDqIvRIDaeX81x14qpZHs4= Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02KJhmXf010759; Fri, 20 Mar 2020 14:43:48 -0500 Received: from DFLE108.ent.ti.com (10.64.6.29) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 20 Mar 2020 14:43:48 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Fri, 20 Mar 2020 14:43:48 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02KJhldn043440; Fri, 20 Mar 2020 14:43:47 -0500 From: Grygorii Strashko To: "David S . Miller" , Richard Cochran , Lokesh Vutla , Tony Lindgren CC: Sekhar Nori , Murali Karicheri , netdev , , , Grygorii Strashko Subject: [PATCH net-next v3 10/11] net: ethernet: ti: cpts: add support for HW_TS_PUSH events Date: Fri, 20 Mar 2020 21:42:43 +0200 Message-ID: <20200320194244.4703-11-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320194244.4703-1-grygorii.strashko@ti.com> References: <20200320194244.4703-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hence CPTS IRQ support is in place the W_TS_PUSH events can be added. PWM capable DmTimers can be used to generete input signals for CPTS on TI AM335x/AM437x/DRA7 SoCs to be timestamped: AM335x/AM437x: timer4 - timer7 DRA7/AM57xx: timer13 - timer16 Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpsw_priv.c | 5 ++- drivers/net/ethernet/ti/cpts.c | 52 ++++++++++++++++++++++++++- drivers/net/ethernet/ti/cpts.h | 5 +-- drivers/net/ethernet/ti/netcp_ethss.c | 3 +- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw_priv.c b/drivers/net/ethernet/ti/cpsw_priv.c index 97a058ca60ac..099208927400 100644 --- a/drivers/net/ethernet/ti/cpsw_priv.c +++ b/drivers/net/ethernet/ti/cpsw_priv.c @@ -28,6 +28,8 @@ #include "cpsw_sl.h" #include "davinci_cpdma.h" +#define CPTS_N_ETX_TS 4 + int (*cpsw_slave_index)(struct cpsw_common *cpsw, struct cpsw_priv *priv); void cpsw_intr_enable(struct cpsw_common *cpsw) @@ -522,7 +524,8 @@ int cpsw_init_common(struct cpsw_common *cpsw, void __iomem *ss_regs, if (!cpts_node) cpts_node = cpsw->dev->of_node; - cpsw->cpts = cpts_create(cpsw->dev, cpts_regs, cpts_node); + cpsw->cpts = cpts_create(cpsw->dev, cpts_regs, cpts_node, + CPTS_N_ETX_TS); if (IS_ERR(cpsw->cpts)) { ret = PTR_ERR(cpsw->cpts); cpdma_ctlr_destroy(cpsw->dma); diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index 187fd1398b7e..403e1dbed673 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -32,6 +32,11 @@ struct cpts_skb_cb_data { #define cpts_read32(c, r) readl_relaxed(&c->reg->r) #define cpts_write32(c, v, r) writel_relaxed(v, &c->reg->r) +static int cpts_event_port(struct cpts_event *event) +{ + return (event->high >> PORT_NUMBER_SHIFT) & PORT_NUMBER_MASK; +} + static int event_expired(struct cpts_event *event) { return time_after(jiffies, event->tmo); @@ -99,6 +104,7 @@ static void cpts_purge_txq(struct cpts *cpts) */ static int cpts_fifo_read(struct cpts *cpts, int match) { + struct ptp_clock_event pevent; bool need_schedule = false; struct cpts_event *event; unsigned long flags; @@ -146,7 +152,12 @@ static int cpts_fifo_read(struct cpts *cpts, int match) break; case CPTS_EV_ROLL: case CPTS_EV_HALF: + break; case CPTS_EV_HW: + pevent.timestamp = event->timestamp; + pevent.type = PTP_CLOCK_EXTTS; + pevent.index = cpts_event_port(event) - 1; + ptp_clock_event(cpts->clock, &pevent); break; default: dev_err(cpts->dev, "cpts: unknown event type\n"); @@ -272,9 +283,45 @@ static int cpts_ptp_settime(struct ptp_clock_info *ptp, return 0; } +static int cpts_extts_enable(struct cpts *cpts, u32 index, int on) +{ + u32 v; + + if (index >= cpts->info.n_ext_ts) + return -ENXIO; + + if (((cpts->hw_ts_enable & BIT(index)) >> index) == on) + return 0; + + mutex_lock(&cpts->ptp_clk_mutex); + + v = cpts_read32(cpts, control); + if (on) { + v |= BIT(8 + index); + cpts->hw_ts_enable |= BIT(index); + } else { + v &= ~BIT(8 + index); + cpts->hw_ts_enable &= ~BIT(index); + } + cpts_write32(cpts, v, control); + + mutex_unlock(&cpts->ptp_clk_mutex); + + return 0; +} + static int cpts_ptp_enable(struct ptp_clock_info *ptp, struct ptp_clock_request *rq, int on) { + struct cpts *cpts = container_of(ptp, struct cpts, info); + + switch (rq->type) { + case PTP_CLK_REQ_EXTTS: + return cpts_extts_enable(cpts, rq->extts.index, on); + default: + break; + } + return -EOPNOTSUPP; } @@ -751,7 +798,7 @@ static int cpts_of_parse(struct cpts *cpts, struct device_node *node) } struct cpts *cpts_create(struct device *dev, void __iomem *regs, - struct device_node *node) + struct device_node *node, u32 n_ext_ts) { struct cpts *cpts; int ret; @@ -790,6 +837,9 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs, cpts->cc.mask = CLOCKSOURCE_MASK(32); cpts->info = cpts_info; + if (n_ext_ts) + cpts->info.n_ext_ts = n_ext_ts; + cpts_calc_mult_shift(cpts); /* save cc.mult original value as it can be modified * by cpts_ptp_adjfreq(). diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h index e18cb5e436fe..acffe8a29b32 100644 --- a/drivers/net/ethernet/ti/cpts.h +++ b/drivers/net/ethernet/ti/cpts.h @@ -121,6 +121,7 @@ struct cpts { struct mutex ptp_clk_mutex; /* sync PTP interface and worker */ bool irq_poll; struct completion ts_push_complete; + u32 hw_ts_enable; }; int cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb); @@ -128,7 +129,7 @@ void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb); int cpts_register(struct cpts *cpts); void cpts_unregister(struct cpts *cpts); struct cpts *cpts_create(struct device *dev, void __iomem *regs, - struct device_node *node); + struct device_node *node, u32 n_ext_ts); void cpts_release(struct cpts *cpts); void cpts_misc_interrupt(struct cpts *cpts); @@ -160,7 +161,7 @@ static inline void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb) static inline struct cpts *cpts_create(struct device *dev, void __iomem *regs, - struct device_node *node) + struct device_node *node, u32 n_ext_ts) { return NULL; } diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c index fb36115e9c51..9d6e27fb710e 100644 --- a/drivers/net/ethernet/ti/netcp_ethss.c +++ b/drivers/net/ethernet/ti/netcp_ethss.c @@ -3716,7 +3716,8 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev, if (!cpts_node) cpts_node = of_node_get(node); - gbe_dev->cpts = cpts_create(gbe_dev->dev, gbe_dev->cpts_reg, cpts_node); + gbe_dev->cpts = cpts_create(gbe_dev->dev, gbe_dev->cpts_reg, + cpts_node, 0); of_node_put(cpts_node); if (IS_ENABLED(CONFIG_TI_CPTS) && IS_ERR(gbe_dev->cpts)) { ret = PTR_ERR(gbe_dev->cpts);