From patchwork Fri Mar 13 22:49:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 211581 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 3A7D6C2BB1D for ; Fri, 13 Mar 2020 22:49:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 07A6B2074F for ; Fri, 13 Mar 2020 22:49:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="TuL6aplD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726643AbgCMWtg (ORCPT ); Fri, 13 Mar 2020 18:49:36 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:53582 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbgCMWtg (ORCPT ); Fri, 13 Mar 2020 18:49:36 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02DMnV0x030033; Fri, 13 Mar 2020 17:49:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584139771; bh=NC3leWhnM/4NIc8QyBQa2tN7YReyUOftwpbx33+WJHM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=TuL6aplDWwv+Y83xVkOpZwJl0IccEQhCGpIzS2thT+a95IHN9AhlexjyHExfIAvx2 J42cWNtfxsDPt2biJx/4g6Vk6YS+EyrnOkQrjr8b2q137FZajxed7wC8Dlk2VlpWBj lYzVC4L++KXqFvc6wbVrcUmHhgB/hYrtZ9LaiJTA= 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 02DMnVL7127550 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 13 Mar 2020 17:49:31 -0500 Received: from DLEE107.ent.ti.com (157.170.170.37) 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, 13 Mar 2020 17:49:30 -0500 Received: from localhost.localdomain (10.64.41.19) by DLEE107.ent.ti.com (157.170.170.37) 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, 13 Mar 2020 17:49:30 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by localhost.localdomain (8.15.2/8.15.2) with ESMTP id 02DMnTPG061620; Fri, 13 Mar 2020 17:49:30 -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 01/11] net: ethernet: ti: cpts: use dev_yy() api for logs Date: Sat, 14 Mar 2020 00:49:04 +0200 Message-ID: <20200313224914.5997-2-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313224914.5997-1-grygorii.strashko@ti.com> References: <20200313224914.5997-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@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 13 22:49:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 211580 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 B5B06C2BB1D for ; Fri, 13 Mar 2020 22:49:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A5222074D for ; Fri, 13 Mar 2020 22:49:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="tCcQwuam" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726777AbgCMWtu (ORCPT ); Fri, 13 Mar 2020 18:49:50 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:39860 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbgCMWtt (ORCPT ); Fri, 13 Mar 2020 18:49:49 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02DMnjKq029939; Fri, 13 Mar 2020 17:49:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584139785; bh=VDL4bQPEF3OLQcAhE+BrvsJYUbu3alZiaqyJxwQK41U=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=tCcQwuammv4QPSb0fDQVBovpAvYCjYjdxJ3DRixvZNASjsqHaM5yJmhdnzK+zcLPA EZ9F3fcnuMG/LwQhUf9Ie+61kqqmWrBow1HpsCKYuri3e2UdITTSt4VH5e76gP6BCy epYYpf+fAKNaPrH6q13HAzKfdBt2i3KXxWKWr1OE= 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 02DMnjBe048539; Fri, 13 Mar 2020 17:49:45 -0500 Received: from DFLE109.ent.ti.com (10.64.6.30) 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, 13 Mar 2020 17:49:45 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE109.ent.ti.com (10.64.6.30) 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, 13 Mar 2020 17:49:45 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02DMnhOa034818; Fri, 13 Mar 2020 17:49:44 -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 03/11] net: ethernet: ti: cpts: move tc mult update in cpts_fifo_read() Date: Sat, 14 Mar 2020 00:49:06 +0200 Message-ID: <20200313224914.5997-4-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313224914.5997-1-grygorii.strashko@ti.com> References: <20200313224914.5997-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Now CPTS driver .adjfreq() generates request to read CPTS current time (CPTS_EV_PUSH) with intention to process all pending event using previous frequency adjustment values before switching to the new ones. So CPTS_EV_PUSH works as a marker to switch to the new frequency adjustment values. Current code assumes that all job is done in .adjfreq(), but after enabling IRQ this will not be true any more. Hence save new frequency adjustment values (mult) and perform actual freq adjustment in cpts_fifo_read() immediately after CPTS_EV_PUSH is received. Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpts.c | 8 ++++++-- drivers/net/ethernet/ti/cpts.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index 6a1844cd23ff..e6a8ccae711c 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -165,6 +165,10 @@ static int cpts_fifo_read(struct cpts *cpts, int match) case CPTS_EV_PUSH: WRITE_ONCE(cpts->cur_timestamp, lo); timecounter_read(&cpts->tc); + if (cpts->mult_new) { + cpts->cc.mult = cpts->mult_new; + cpts->mult_new = 0; + } break; case CPTS_EV_TX: if (cpts_match_tx_ts(cpts, event)) { @@ -228,9 +232,9 @@ static int cpts_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) spin_lock_irqsave(&cpts->lock, flags); - cpts_update_cur_time(cpts, CPTS_EV_PUSH); + cpts->mult_new = neg_adj ? mult - diff : mult + diff; - cpts->cc.mult = neg_adj ? mult - diff : mult + diff; + cpts_update_cur_time(cpts, CPTS_EV_PUSH); spin_unlock_irqrestore(&cpts->lock, flags); diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h index 32ecd1ce4d3b..421630049ee7 100644 --- a/drivers/net/ethernet/ti/cpts.h +++ b/drivers/net/ethernet/ti/cpts.h @@ -116,6 +116,7 @@ struct cpts { unsigned long ov_check_period; struct sk_buff_head txq; u64 cur_timestamp; + u32 mult_new; }; void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb); From patchwork Fri Mar 13 22:49:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 211576 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 3C512C5ACBF for ; Fri, 13 Mar 2020 22:50:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0685D20752 for ; Fri, 13 Mar 2020 22:50:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="WUtIK0t9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727658AbgCMWuB (ORCPT ); Fri, 13 Mar 2020 18:50:01 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:56310 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727647AbgCMWuA (ORCPT ); Fri, 13 Mar 2020 18:50:00 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02DMnuvh078152; Fri, 13 Mar 2020 17:49:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584139796; bh=B5cAMHxAPuvvAk4PWvRvtFCRsiXSN+lqfOYamZvvxxg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=WUtIK0t9KRBJzlvhYFy8sTGork4xiBwygWAGx213SJb4s6PzGkQuzH6hd0HmgQyIH sPT9UoLzyNd71R302ZN5nbPJOpA+pPfmAcgsAUHYx461Ww8wfCi0z47m+S3aV4OO1/ nDby8e8PtITtG3dnj1o2D+dnd01VtGYKhbTFb/8s= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02DMnuWT031868 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 13 Mar 2020 17:49:56 -0500 Received: from DLEE101.ent.ti.com (157.170.170.31) 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; Fri, 13 Mar 2020 17:49:55 -0500 Received: from localhost.localdomain (10.64.41.19) by DLEE101.ent.ti.com (157.170.170.31) 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, 13 Mar 2020 17:49:55 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by localhost.localdomain (8.15.2/8.15.2) with ESMTP id 02DMnsuV061956; Fri, 13 Mar 2020 17:49:55 -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 06/11] net: ethernet: ti: cpts: move tx timestamp processing to ptp worker only Date: Sat, 14 Mar 2020 00:49:09 +0200 Message-ID: <20200313224914.5997-7-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313224914.5997-1-grygorii.strashko@ti.com> References: <20200313224914.5997-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Now the tx timestamp processing happens from different contexts - softirq and thread/PTP worker. Enabling IRQ will add one more hard_irq context. This makes overall deferred TX timestamp processing and locking over-complicated. Move tx timestamp processing to PTP worker always instead. napi_rx->cpts_tx_timestamp if ptp_packet then push to txq ptp_schedule_worker() do_aux_work->cpts_overflow_check cpts_process_events() Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpts.c | 165 +++++++++++++++++++-------------- 1 file changed, 94 insertions(+), 71 deletions(-) diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index f7ce482ad09c..e590d57a4313 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -21,6 +21,8 @@ #include "cpts.h" #define CPTS_SKB_TX_WORK_TIMEOUT 1 /* jiffies */ +#define CPTS_SKB_RX_TX_TMO 100 /*ms */ +#define CPTS_EVENT_RX_TX_TIMEOUT (100) /* ms */ struct cpts_skb_cb_data { u32 skb_mtype_seqid; @@ -92,46 +94,6 @@ static void cpts_purge_txq(struct cpts *cpts) dev_dbg(cpts->dev, "txq cleaned up %d\n", removed); } -static bool cpts_match_tx_ts(struct cpts *cpts, struct cpts_event *event) -{ - struct sk_buff *skb, *tmp; - 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)); - - /* 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; - struct cpts_skb_cb_data *skb_cb = - (struct cpts_skb_cb_data *)skb->cb; - - 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_seqid %08x\n", - mtype_seqid); - break; - } - - if (time_after(jiffies, skb_cb->tmo)) { - /* timeout any expired skbs over 1s */ - dev_dbg(cpts->dev, "expiring tx timestamp from txq\n"); - __skb_unlink(skb, &cpts->txq); - dev_consume_skb_any(skb); - } - } - - return found; -} - /* * Returns zero if matching event type was found. */ @@ -151,7 +113,6 @@ static int cpts_fifo_read(struct cpts *cpts, int match) } event = list_first_entry(&cpts->pool, struct cpts_event, list); - event->tmo = jiffies + 2; event->high = hi; event->low = lo; event->timestamp = timecounter_cyc2time(&cpts->tc, event->low); @@ -169,14 +130,10 @@ static int cpts_fifo_read(struct cpts *cpts, int match) } break; case CPTS_EV_TX: - if (cpts_match_tx_ts(cpts, event)) { - /* if the new event matches an existing skb, - * then don't queue it - */ - break; - } - /* fall through */ case CPTS_EV_RX: + event->tmo = jiffies + + msecs_to_jiffies(CPTS_EVENT_RX_TX_TIMEOUT); + list_del_init(&event->list); list_add_tail(&event->list, &cpts->events); break; @@ -297,6 +254,84 @@ static int cpts_ptp_enable(struct ptp_clock_info *ptp, return -EOPNOTSUPP; } +static bool cpts_match_tx_ts(struct cpts *cpts, struct cpts_event *event) +{ + struct sk_buff_head txq_list; + 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(&txq_list); + + spin_lock_irqsave(&cpts->txq.lock, flags); + skb_queue_splice_init(&cpts->txq, &txq_list); + spin_unlock_irqrestore(&cpts->txq.lock, flags); + + skb_queue_walk_safe(&txq_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) { + memset(&ssh, 0, sizeof(ssh)); + ssh.hwtstamp = ns_to_ktime(event->timestamp); + skb_tstamp_tx(skb, &ssh); + found = true; + __skb_unlink(skb, &txq_list); + dev_consume_skb_any(skb); + dev_dbg(cpts->dev, "match tx timestamp mtype_seqid %08x\n", + mtype_seqid); + break; + } + + if (time_after(jiffies, skb_cb->tmo)) { + /* timeout any expired skbs over 1s */ + dev_dbg(cpts->dev, "expiring tx timestamp from txq\n"); + __skb_unlink(skb, &txq_list); + dev_consume_skb_any(skb); + } + } + + spin_lock_irqsave(&cpts->txq.lock, flags); + skb_queue_splice(&txq_list, &cpts->txq); + spin_unlock_irqrestore(&cpts->txq.lock, flags); + + return found; +} + +static void cpts_process_events(struct cpts *cpts) +{ + struct list_head *this, *next; + struct cpts_event *event; + unsigned long flags; + LIST_HEAD(events); + LIST_HEAD(events_free); + + spin_lock_irqsave(&cpts->lock, flags); + list_splice_init(&cpts->events, &events); + spin_unlock_irqrestore(&cpts->lock, flags); + + 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)) { + list_del_init(&event->list); + list_add(&event->list, &events_free); + } + } + + spin_lock_irqsave(&cpts->lock, flags); + list_splice_tail(&events, &cpts->events); + list_splice_tail(&events_free, &cpts->pool); + spin_unlock_irqrestore(&cpts->lock, flags); +} + static long cpts_overflow_check(struct ptp_clock_info *ptp) { struct cpts *cpts = container_of(ptp, struct cpts, info); @@ -305,17 +340,20 @@ static long cpts_overflow_check(struct ptp_clock_info *ptp) u64 ns; spin_lock_irqsave(&cpts->lock, flags); - cpts_update_cur_time(cpts, -1, NULL); + spin_unlock_irqrestore(&cpts->lock, flags); ns = timecounter_read(&cpts->tc); + cpts_process_events(cpts); + + spin_lock_irqsave(&cpts->txq.lock, flags); if (!skb_queue_empty(&cpts->txq)) { cpts_purge_txq(cpts); if (!skb_queue_empty(&cpts->txq)) delay = CPTS_SKB_TX_WORK_TIMEOUT; } - spin_unlock_irqrestore(&cpts->lock, flags); + spin_unlock_irqrestore(&cpts->txq.lock, flags); dev_dbg(cpts->dev, "cpts overflow check at %lld\n", ns); return (long)delay; @@ -409,19 +447,6 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, break; } } - - if (ev_type == CPTS_EV_TX && !ns) { - struct cpts_skb_cb_data *skb_cb = - (struct cpts_skb_cb_data *)skb->cb; - /* Not found, add frame to queue for processing later. - * The periodic FIFO check will handle this. - */ - skb_get(skb); - /* get the timestamp for timeouts */ - skb_cb->tmo = jiffies + msecs_to_jiffies(100); - __skb_queue_tail(&cpts->txq, skb); - ptp_schedule_worker(cpts->clock, 0); - } spin_unlock_irqrestore(&cpts->lock, flags); return ns; @@ -455,9 +480,7 @@ EXPORT_SYMBOL_GPL(cpts_rx_timestamp); void cpts_tx_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; if (!(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) return; @@ -471,12 +494,12 @@ void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb) 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)); - ssh.hwtstamp = ns_to_ktime(ns); - skb_tstamp_tx(skb, &ssh); + /* Always defer TX TS processing to PTP worker */ + skb_get(skb); + /* get the timestamp for timeouts */ + skb_cb->tmo = jiffies + msecs_to_jiffies(CPTS_SKB_RX_TX_TMO); + skb_queue_tail(&cpts->txq, skb); + ptp_schedule_worker(cpts->clock, 0); } EXPORT_SYMBOL_GPL(cpts_tx_timestamp); From patchwork Fri Mar 13 22:49:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 211577 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 7EBD0C4CECE for ; Fri, 13 Mar 2020 22:50:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4ECF52074F for ; Fri, 13 Mar 2020 22:50:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="biJmG/fc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727689AbgCMWuI (ORCPT ); Fri, 13 Mar 2020 18:50:08 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:53648 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbgCMWuH (ORCPT ); Fri, 13 Mar 2020 18:50:07 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02DMo35e030170; Fri, 13 Mar 2020 17:50:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584139803; bh=HbCrkYxd2fgYWfBGFxDi0pw1/Bip+vB/5+UoxwDV48c=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=biJmG/fcDeNRog5nnlIJBFYOa4Y/dAChzRQY/xs3l/lc37fpW8ExhnqP/BwWN7SDf BTdU3lOEEVs7393Tn+TwUeU8FIClR11UQwqy/Zj3Y+d7gHXNgb5NBWQQoI0Wf2u5re axU7rF4lu3iNIBdBqnHjZt0rHfJywtLVl0AlCz1k= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02DMo2Tq032059 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 13 Mar 2020 17:50:03 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 13 Mar 2020 17:50:02 -0500 Received: from localhost.localdomain (10.64.41.19) 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, 13 Mar 2020 17:50:02 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by localhost.localdomain (8.15.2/8.15.2) with ESMTP id 02DMo1Sb062317; Fri, 13 Mar 2020 17:50:02 -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 07/11] net: ethernet: ti: cpts: rework locking Date: Sat, 14 Mar 2020 00:49:10 +0200 Message-ID: <20200313224914.5997-8-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313224914.5997-1-grygorii.strashko@ti.com> References: <20200313224914.5997-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Now spinlock is used to synchronize everything which is not required. Add mutex and use to sync access to PTP interface and PTP worker and use spinlock only to sync FIFO/events processing. Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpts.c | 53 +++++++++++++++++++--------------- drivers/net/ethernet/ti/cpts.h | 3 +- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index e590d57a4313..71f9bd410e4a 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -99,9 +99,12 @@ static void cpts_purge_txq(struct cpts *cpts) */ static int cpts_fifo_read(struct cpts *cpts, int match) { + struct cpts_event *event; + unsigned long flags; int i, type = -1; u32 hi, lo; - struct cpts_event *event; + + spin_lock_irqsave(&cpts->lock, flags); for (i = 0; i < CPTS_FIFO_DEPTH; i++) { if (cpts_fifo_pop(cpts, &hi, &lo)) @@ -109,7 +112,7 @@ static int cpts_fifo_read(struct cpts *cpts, int match) if (list_empty(&cpts->pool) && cpts_purge_events(cpts)) { dev_info(cpts->dev, "cpts: event pool empty\n"); - return -1; + break; } event = list_first_entry(&cpts->pool, struct cpts_event, list); @@ -148,6 +151,9 @@ static int cpts_fifo_read(struct cpts *cpts, int match) if (type == match) break; } + + spin_unlock_irqrestore(&cpts->lock, flags); + return type == match ? 0 : -1; } @@ -161,10 +167,15 @@ static u64 cpts_systim_read(const struct cyclecounter *cc) static void cpts_update_cur_time(struct cpts *cpts, int match, struct ptp_system_timestamp *sts) { + unsigned long flags; + + /* use spin_lock_irqsave() here as it has to run very fast */ + spin_lock_irqsave(&cpts->lock, flags); ptp_read_system_prets(sts); cpts_write32(cpts, TS_PUSH, ts_push); cpts_read32(cpts, ts_push); ptp_read_system_postts(sts); + spin_unlock_irqrestore(&cpts->lock, flags); if (cpts_fifo_read(cpts, match) && match != -1) dev_err(cpts->dev, "cpts: unable to obtain a time stamp\n"); @@ -174,11 +185,10 @@ static void cpts_update_cur_time(struct cpts *cpts, int match, static int cpts_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) { - u64 adj; - u32 diff, mult; - int neg_adj = 0; - unsigned long flags; struct cpts *cpts = container_of(ptp, struct cpts, info); + int neg_adj = 0; + u32 diff, mult; + u64 adj; if (ppb < 0) { neg_adj = 1; @@ -189,25 +199,23 @@ static int cpts_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) adj *= ppb; diff = div_u64(adj, 1000000000ULL); - spin_lock_irqsave(&cpts->lock, flags); + mutex_lock(&cpts->ptp_clk_mutex); cpts->mult_new = neg_adj ? mult - diff : mult + diff; cpts_update_cur_time(cpts, CPTS_EV_PUSH, NULL); - spin_unlock_irqrestore(&cpts->lock, flags); - + mutex_unlock(&cpts->ptp_clk_mutex); return 0; } static int cpts_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) { - unsigned long flags; struct cpts *cpts = container_of(ptp, struct cpts, info); - spin_lock_irqsave(&cpts->lock, flags); + mutex_lock(&cpts->ptp_clk_mutex); timecounter_adjtime(&cpts->tc, delta); - spin_unlock_irqrestore(&cpts->lock, flags); + mutex_unlock(&cpts->ptp_clk_mutex); return 0; } @@ -217,15 +225,14 @@ static int cpts_ptp_gettimeex(struct ptp_clock_info *ptp, struct ptp_system_timestamp *sts) { struct cpts *cpts = container_of(ptp, struct cpts, info); - unsigned long flags; u64 ns; - spin_lock_irqsave(&cpts->lock, flags); + mutex_lock(&cpts->ptp_clk_mutex); cpts_update_cur_time(cpts, CPTS_EV_PUSH, sts); ns = timecounter_read(&cpts->tc); - spin_unlock_irqrestore(&cpts->lock, flags); + mutex_unlock(&cpts->ptp_clk_mutex); *ts = ns_to_timespec64(ns); @@ -235,15 +242,14 @@ static int cpts_ptp_gettimeex(struct ptp_clock_info *ptp, static int cpts_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 *ts) { - u64 ns; - unsigned long flags; struct cpts *cpts = container_of(ptp, struct cpts, info); + u64 ns; ns = timespec64_to_ns(ts); - spin_lock_irqsave(&cpts->lock, flags); + mutex_lock(&cpts->ptp_clk_mutex); timecounter_init(&cpts->tc, &cpts->cc, ns); - spin_unlock_irqrestore(&cpts->lock, flags); + mutex_unlock(&cpts->ptp_clk_mutex); return 0; } @@ -339,10 +345,9 @@ static long cpts_overflow_check(struct ptp_clock_info *ptp) unsigned long flags; u64 ns; - spin_lock_irqsave(&cpts->lock, flags); - cpts_update_cur_time(cpts, -1, NULL); - spin_unlock_irqrestore(&cpts->lock, flags); + mutex_lock(&cpts->ptp_clk_mutex); + cpts_update_cur_time(cpts, -1, NULL); ns = timecounter_read(&cpts->tc); cpts_process_events(cpts); @@ -356,6 +361,7 @@ static long cpts_overflow_check(struct ptp_clock_info *ptp) spin_unlock_irqrestore(&cpts->txq.lock, flags); dev_dbg(cpts->dev, "cpts overflow check at %lld\n", ns); + mutex_unlock(&cpts->ptp_clk_mutex); return (long)delay; } @@ -425,8 +431,8 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, u32 mtype_seqid; u64 ns = 0; - spin_lock_irqsave(&cpts->lock, flags); 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)) { @@ -703,6 +709,7 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs, cpts->dev = dev; cpts->reg = (struct cpsw_cpts __iomem *)regs; spin_lock_init(&cpts->lock); + mutex_init(&cpts->ptp_clk_mutex); ret = cpts_of_parse(cpts, node); if (ret) diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h index 421630049ee7..f16e14d67f5f 100644 --- a/drivers/net/ethernet/ti/cpts.h +++ b/drivers/net/ethernet/ti/cpts.h @@ -104,7 +104,7 @@ struct cpts { int rx_enable; struct ptp_clock_info info; struct ptp_clock *clock; - spinlock_t lock; /* protects time registers */ + spinlock_t lock; /* protects fifo/events */ u32 cc_mult; /* for the nominal frequency */ struct cyclecounter cc; struct timecounter tc; @@ -117,6 +117,7 @@ struct cpts { struct sk_buff_head txq; 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); From patchwork Fri Mar 13 22:49:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 211578 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 631D9C2BB1D for ; Fri, 13 Mar 2020 22:50:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2EC162074F for ; Fri, 13 Mar 2020 22:50:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="KTlGXIIp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727710AbgCMWuN (ORCPT ); Fri, 13 Mar 2020 18:50:13 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:56344 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbgCMWuL (ORCPT ); Fri, 13 Mar 2020 18:50:11 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02DMo7vW078212; Fri, 13 Mar 2020 17:50:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584139807; bh=+RMAQxT0bLY51L11oK0fravKh9bd2gHmlnpRI9dLz44=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=KTlGXIIp1VfiLuYnIZ9mHFY4+aYEYVNk6o0fEKDgPu+kJucdf7vmFAdCopy8KAfxG D1KdB+ZUuULIGPnef8P9JkkmKLOgvVj2DWshDjuebTsC6ajQ5dI87tswmDezM6Jo1E 4xKtxMqyjgF8BNms6vRd7YQjgzSuJSXw7vr+Jk5w= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02DMo79o017791 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 13 Mar 2020 17:50:07 -0500 Received: from DLEE111.ent.ti.com (157.170.170.22) 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; Fri, 13 Mar 2020 17:50:07 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) 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.1847.3 via Frontend Transport; Fri, 13 Mar 2020 17:50:07 -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 02DMo645009820; Fri, 13 Mar 2020 17:50: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 09/11] net: ethernet: ti: cpts: add irq support Date: Sat, 14 Mar 2020 00:49:12 +0200 Message-ID: <20200313224914.5997-10-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313224914.5997-1-grygorii.strashko@ti.com> References: <20200313224914.5997-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Add CPTS IRQ support, but do not enable it. By default, the CPTS driver will continue working using polling mode which is required for CPTS to continue working on platforms other than CPSW, like Keystone 2. The CPTS IRQ support is required to enable support for HW_TS_PUSH events. The CPSW CPTS IRQ and HW_TS_PUSH events support will be enabled in follow up patches. Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpts.c | 22 +++++++++++++++++++++- drivers/net/ethernet/ti/cpts.h | 13 +++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index fcfd578b81ed..7156d343425d 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -103,6 +103,7 @@ static int cpts_fifo_read(struct cpts *cpts, int match) unsigned long flags; int i, type = -1; u32 hi, lo; + bool need_schedule = false; spin_lock_irqsave(&cpts->lock, flags); @@ -131,6 +132,8 @@ static int cpts_fifo_read(struct cpts *cpts, int match) cpts->cc.mult = cpts->mult_new; cpts->mult_new = 0; } + if (!cpts->irq_poll) + complete(&cpts->ts_push_complete); break; case CPTS_EV_TX: case CPTS_EV_RX: @@ -139,6 +142,7 @@ static int cpts_fifo_read(struct cpts *cpts, int match) list_del_init(&event->list); list_add_tail(&event->list, &cpts->events); + need_schedule = true; break; case CPTS_EV_ROLL: case CPTS_EV_HALF: @@ -154,9 +158,17 @@ static int cpts_fifo_read(struct cpts *cpts, int match) spin_unlock_irqrestore(&cpts->lock, flags); + if (!cpts->irq_poll && need_schedule) + ptp_schedule_worker(cpts->clock, 0); + return type == match ? 0 : -1; } +void cpts_misc_interrupt(struct cpts *cpts) +{ + cpts_fifo_read(cpts, -1); +} + static u64 cpts_systim_read(const struct cyclecounter *cc) { struct cpts *cpts = container_of(cc, struct cpts, cc); @@ -169,6 +181,8 @@ static void cpts_update_cur_time(struct cpts *cpts, int match, { unsigned long flags; + reinit_completion(&cpts->ts_push_complete); + /* use spin_lock_irqsave() here as it has to run very fast */ spin_lock_irqsave(&cpts->lock, flags); ptp_read_system_prets(sts); @@ -177,8 +191,12 @@ static void cpts_update_cur_time(struct cpts *cpts, int match, ptp_read_system_postts(sts); spin_unlock_irqrestore(&cpts->lock, flags); - if (cpts_fifo_read(cpts, match) && match != -1) + if (cpts->irq_poll && cpts_fifo_read(cpts, match) && match != -1) dev_err(cpts->dev, "cpts: unable to obtain a time stamp\n"); + + if (!cpts->irq_poll && + !wait_for_completion_timeout(&cpts->ts_push_complete, HZ)) + dev_err(cpts->dev, "cpts: obtain a time stamp timeout\n"); } /* PTP clock operations */ @@ -744,8 +762,10 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs, cpts->dev = dev; cpts->reg = (struct cpsw_cpts __iomem *)regs; + cpts->irq_poll = true; spin_lock_init(&cpts->lock); mutex_init(&cpts->ptp_clk_mutex); + init_completion(&cpts->ts_push_complete); ret = cpts_of_parse(cpts, node); if (ret) diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h index 993b4cfa4e86..d66cc023b44d 100644 --- a/drivers/net/ethernet/ti/cpts.h +++ b/drivers/net/ethernet/ti/cpts.h @@ -119,6 +119,8 @@ struct cpts { u64 cur_timestamp; u32 mult_new; struct mutex ptp_clk_mutex; /* sync PTP interface and worker */ + bool irq_poll; + struct completion ts_push_complete; }; int cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb); @@ -128,6 +130,7 @@ void cpts_unregister(struct cpts *cpts); struct cpts *cpts_create(struct device *dev, void __iomem *regs, struct device_node *node); void cpts_release(struct cpts *cpts); +void cpts_misc_interrupt(struct cpts *cpts); static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb) { @@ -139,6 +142,11 @@ static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb) return true; } +static inline void cpts_set_irqpoll(struct cpts *cpts, bool en) +{ + cpts->irq_poll = en; +} + #else struct cpts; @@ -174,6 +182,11 @@ static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb) { return false; } + +static inline void cpts_misc_interrupt(struct cpts *cpts) +{ +} + #endif From patchwork Fri Mar 13 22:49:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 211579 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 C7243C10DCE for ; Fri, 13 Mar 2020 22:50:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 95B082074F for ; Fri, 13 Mar 2020 22:50:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="oNVzsVR2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727723AbgCMWuW (ORCPT ); Fri, 13 Mar 2020 18:50:22 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:39910 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727717AbgCMWuW (ORCPT ); Fri, 13 Mar 2020 18:50:22 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02DMoHi0030059; Fri, 13 Mar 2020 17:50:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584139817; bh=nHfSppZELfgaerGJtOvbPZcBECIqXDeUoFzdmnJQKSA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=oNVzsVR2JbwZKCrq/lAS0Dvikna/wpvw411mBkWrDMkNu7ETYNbDTxwCta7kTB2TC 0FT5L3dY1KEVtLGsEedt2l+ifA5dFtUY/i6jgVUFbw6HdMNwWY90DOrM16p27TRLrd hVSkTEl44veHrz1dNXBpMJdPNgGJJ6uBpJodQNtk= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02DMoHtC032916 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 13 Mar 2020 17:50:17 -0500 Received: from DLEE104.ent.ti.com (157.170.170.34) 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; Fri, 13 Mar 2020 17:50:16 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE104.ent.ti.com (157.170.170.34) 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, 13 Mar 2020 17:50:16 -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 02DMoFgO010080; Fri, 13 Mar 2020 17:50: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 11/11] net: ethernet: ti: cpsw: enable cpts irq Date: Sat, 14 Mar 2020 00:49:14 +0200 Message-ID: <20200313224914.5997-12-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313224914.5997-1-grygorii.strashko@ti.com> References: <20200313224914.5997-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org The CPSW misc IRQ need be enabled for CPTS event_pend IRQs processing. This patch adds corresponding support to CPSW driver. Signed-off-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpsw.c | 21 +++++++++++++++++++++ drivers/net/ethernet/ti/cpsw_new.c | 20 ++++++++++++++++++++ drivers/net/ethernet/ti/cpsw_priv.c | 12 ++++++++++++ drivers/net/ethernet/ti/cpsw_priv.h | 2 ++ 4 files changed, 55 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index a27cb1b2190f..d93d0480b010 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -1572,6 +1572,12 @@ static int cpsw_probe(struct platform_device *pdev) return irq; cpsw->irqs_table[1] = irq; + /* get misc irq*/ + irq = platform_get_irq(pdev, 3); + if (irq <= 0) + return irq; + cpsw->misc_irq = irq; + /* * This may be required here for child devices. */ @@ -1706,6 +1712,21 @@ static int cpsw_probe(struct platform_device *pdev) goto clean_unregister_netdev_ret; } + if (!cpsw->cpts) + goto skip_cpts; + + ret = devm_request_irq(&pdev->dev, cpsw->misc_irq, cpsw_misc_interrupt, + 0, dev_name(&pdev->dev), cpsw); + if (ret < 0) { + dev_err(dev, "error attaching misc irq (%d)\n", ret); + goto clean_unregister_netdev_ret; + } + + /* Enable misc CPTS evnt_pend IRQ */ + cpts_set_irqpoll(cpsw->cpts, false); + writel(0x10, &cpsw->wr_regs->misc_en); + +skip_cpts: cpsw_notice(priv, probe, "initialized device (regs %pa, irq %d, pool size %d)\n", &ss_res->start, cpsw->irqs_table[0], descs_pool_size); diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c index 2ee685493147..04f6f8079bfa 100644 --- a/drivers/net/ethernet/ti/cpsw_new.c +++ b/drivers/net/ethernet/ti/cpsw_new.c @@ -1900,6 +1900,11 @@ static int cpsw_probe(struct platform_device *pdev) return irq; cpsw->irqs_table[1] = irq; + irq = platform_get_irq_byname(pdev, "misc"); + if (irq <= 0) + return irq; + cpsw->misc_irq = irq; + platform_set_drvdata(pdev, cpsw); /* This may be required here for child devices. */ pm_runtime_enable(dev); @@ -1979,6 +1984,21 @@ static int cpsw_probe(struct platform_device *pdev) goto clean_unregister_netdev; } + if (!cpsw->cpts) + goto skip_cpts; + + ret = devm_request_irq(dev, cpsw->misc_irq, cpsw_misc_interrupt, + 0, dev_name(&pdev->dev), cpsw); + if (ret < 0) { + dev_err(dev, "error attaching misc irq (%d)\n", ret); + goto clean_unregister_netdev; + } + + /* Enable misc CPTS evnt_pend IRQ */ + cpts_set_irqpoll(cpsw->cpts, false); + writel(0x10, &cpsw->wr_regs->misc_en); + +skip_cpts: ret = cpsw_register_notifiers(cpsw); if (ret) goto clean_unregister_netdev; diff --git a/drivers/net/ethernet/ti/cpsw_priv.c b/drivers/net/ethernet/ti/cpsw_priv.c index 099208927400..9d098c802c6d 100644 --- a/drivers/net/ethernet/ti/cpsw_priv.c +++ b/drivers/net/ethernet/ti/cpsw_priv.c @@ -114,6 +114,18 @@ irqreturn_t cpsw_rx_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } +irqreturn_t cpsw_misc_interrupt(int irq, void *dev_id) +{ + struct cpsw_common *cpsw = dev_id; + + writel(0, &cpsw->wr_regs->misc_en); + cpdma_ctlr_eoi(cpsw->dma, CPDMA_EOI_MISC); + cpts_misc_interrupt(cpsw->cpts); + writel(0x10, &cpsw->wr_regs->misc_en); + + return IRQ_HANDLED; +} + int cpsw_tx_mq_poll(struct napi_struct *napi_tx, int budget) { struct cpsw_common *cpsw = napi_to_cpsw(napi_tx); diff --git a/drivers/net/ethernet/ti/cpsw_priv.h b/drivers/net/ethernet/ti/cpsw_priv.h index b8d7b924ee3d..bf4e179b4ca4 100644 --- a/drivers/net/ethernet/ti/cpsw_priv.h +++ b/drivers/net/ethernet/ti/cpsw_priv.h @@ -350,6 +350,7 @@ struct cpsw_common { bool rx_irq_disabled; bool tx_irq_disabled; u32 irqs_table[IRQ_NUM]; + int misc_irq; struct cpts *cpts; struct devlink *devlink; int rx_ch_num, tx_ch_num; @@ -442,6 +443,7 @@ int cpsw_run_xdp(struct cpsw_priv *priv, int ch, struct xdp_buff *xdp, struct page *page, int port); irqreturn_t cpsw_tx_interrupt(int irq, void *dev_id); irqreturn_t cpsw_rx_interrupt(int irq, void *dev_id); +irqreturn_t cpsw_misc_interrupt(int irq, void *dev_id); int cpsw_tx_mq_poll(struct napi_struct *napi_tx, int budget); int cpsw_tx_poll(struct napi_struct *napi_tx, int budget); int cpsw_rx_mq_poll(struct napi_struct *napi_rx, int budget);