From: Grygorii Strashko <grygorii.strashko@ti.com>
To: "David S . Miller" <davem@davemloft.net>,
Richard Cochran <richardcochran@gmail.com>,
Lokesh Vutla <lokeshvutla@ti.com>,
Tony Lindgren <tony@atomide.com>
Cc: Sekhar Nori <nsekhar@ti.com>,
Murali Karicheri <m-karicheri2@ti.com>,
netdev <netdev@vger.kernel.org>, <linux-omap@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Grygorii Strashko <grygorii.strashko@ti.com>
Subject: [PATCH net-next 02/11] net: ethernet: ti: cpts: separate hw counter read from timecounter
Date: Sat, 14 Mar 2020 00:49:05 +0200 [thread overview]
Message-ID: <20200313224914.5997-3-grygorii.strashko@ti.com> (raw)
In-Reply-To: <20200313224914.5997-1-grygorii.strashko@ti.com>
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 <grygorii.strashko@ti.com>
---
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);
--
2.17.1
next prev parent reply other threads:[~2020-03-13 22:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-13 22:49 [PATCH net-next 00/11] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
2020-03-13 22:49 ` [PATCH net-next 01/11] net: ethernet: ti: cpts: use dev_yy() api for logs Grygorii Strashko
2020-03-13 22:49 ` Grygorii Strashko [this message]
2020-03-13 22:49 ` [PATCH net-next 03/11] net: ethernet: ti: cpts: move tc mult update in cpts_fifo_read() Grygorii Strashko
2020-03-13 22:49 ` [PATCH net-next 04/11] net: ethernet: ti: cpts: switch to use new .gettimex64() interface Grygorii Strashko
2020-03-13 22:49 ` [PATCH net-next 05/11] net: ethernet: ti: cpts: optimize packet to event matching Grygorii Strashko
2020-03-13 22:49 ` [PATCH net-next 06/11] net: ethernet: ti: cpts: move tx timestamp processing to ptp worker only Grygorii Strashko
2020-03-14 3:50 ` David Miller
2020-03-13 22:49 ` [PATCH net-next 07/11] net: ethernet: ti: cpts: rework locking Grygorii Strashko
2020-03-13 22:49 ` [PATCH net-next 08/11] net: ethernet: ti: cpts: move rx timestamp processing to ptp worker only Grygorii Strashko
2020-03-13 22:49 ` [PATCH net-next 09/11] net: ethernet: ti: cpts: add irq support Grygorii Strashko
2020-03-14 3:50 ` David Miller
2020-03-13 22:49 ` [PATCH net-next 10/11] net: ethernet: ti: cpts: add support for HW_TS_PUSH events Grygorii Strashko
2020-03-13 22:49 ` [PATCH net-next 11/11] net: ethernet: ti: cpsw: enable cpts irq Grygorii Strashko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200313224914.5997-3-grygorii.strashko@ti.com \
--to=grygorii.strashko@ti.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=lokeshvutla@ti.com \
--cc=m-karicheri2@ti.com \
--cc=netdev@vger.kernel.org \
--cc=nsekhar@ti.com \
--cc=richardcochran@gmail.com \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).