* [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events
@ 2020-03-19 16:57 Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 01/10] net: ethernet: ti: cpts: use dev_yy() api for logs Grygorii Strashko
` (10 more replies)
0 siblings, 11 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:57 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
Hi Richard, All,
v2: no functional changes.
This is re-spin of patches to add CPSW IRQ and HW_TS_PUSH events support I've
sent long time ago [1]. In this series, I've tried to restructure and split changes,
and also add few additional optimizations comparing to initial RFC submission [1].
The HW_TS_PUSH events intended to serve for different timesync purposes on of
which is to add PPS generation function, which can be implemented as below:
+-----------------+
| Control |
| application |
+------->+ +----------+
| | | |
| | | |
| +-----------------+ |
| |
| |
| PTP_EXTTS_REQUEST |
| |
| |
+----------------------------------------------------------------+
| | Kernel
+-------+----------+ +-------v--------+
| \dev\ptpX | | /sys/class/pwm/|
| | | |
+-------^----------+ +-------+--------+
| |
| |
| +-------v-------------------+
+-------+----------+ | |
| CPTS driver | |pwm/pwm-omap-dmtimer.c |
| | +---------------------------+
+-------^----------+ |clocksource/timer_ti_dm.c |
| +-------+-------------------+
|HWx_TS_PUSH evt |
+----------------------------------------------------------------+
| | HW
+-------+----------+ +-------v--------+
| CPTS | | DMTimer |
| | | |
| HWx_TS_PUSH X<-----------------+ |
| + | |
+------------------+ +-------+--------+
|
X timer4
As per my knowledge there is at least one public implemented above PPS generation
schema from Tusori Tibor [2] based on initial HW_TS_PUSH enable submission[1].
And now there is work done by Lokesh Vutla <lokeshvutla@ti.com> published to
enable PWM enable/improve PWM adjustment from user space [3][4][5].
Main changes comparing to initial submission:
- both RX/TX timestamp processing deferred to ptp worker
- both CPTS IRQ and polling events processing supported to make it work for
Keystone 2 also
- switch to use new .gettimex64() interface
- no DT updates as number of HWx_TS_PUSH inputs is static per HW
Dependency:
ff7cf1822b93 kthread: mark timer used by delayed kthread works as IRQ safe
which was merged in -next, but has to be back-ported for testing with earlier
versions
Testing on am571x-idk/omap2plus_defconfig/+CONFIG_PREEMPT=y:
1) testing HW_TS_PUSH
- enable pwm in DT
pwm16: dmtimer-pwm {
compatible = "ti,omap-dmtimer-pwm";
ti,timers = <&timer16>;
#pwm-cells = <3>;
};
- configure and start pwm
echo 0 > /sys/class/pwm/pwmchip0/export
echo 1000000000 > /sys/class/pwm/pwmchip0/pwm0/period
echo 500000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
- test HWx_TS_PUSH using Kernel selftest testptp application
./tools/testing/selftests/ptp/testptp -d /dev/ptp0 -e 1000 -i 3
2) testing phc2sys
# ./linuxptp/phc2sys -s CLOCK_REALTIME -c eth0 -m -O 0 -u30
phc2sys[1616.791]: eth0 rms 408190379792180864 max 1580914543017209856 freq +864 +/- 4635 delay 645 +/- 29
phc2sys[1646.795]: eth0 rms 41 max 108 freq +0 +/- 36 delay 656 +/- 29
phc2sys[1676.800]: eth0 rms 43 max 83 freq +2 +/- 38 delay 650 +/- 0
phc2sys[1706.804]: eth0 rms 39 max 87 freq +4 +/- 34 delay 672 +/- 55
phc2sys[1736.808]: eth0 rms 35 max 66 freq +1 +/- 30 delay 667 +/- 49
phc2sys[1766.813]: eth0 rms 38 max 79 freq +2 +/- 33 delay 656 +/- 29
phc2sys[1796.817]: eth0 rms 45 max 98 freq +1 +/- 39 delay 656 +/- 29
phc2sys[1826.821]: eth0 rms 40 max 87 freq +5 +/- 35 delay 650 +/- 0
phc2sys[1856.826]: eth0 rms 29 max 76 freq -0 +/- 25 delay 656 +/- 29
phc2sys[1886.830]: eth0 rms 40 max 97 freq +4 +/- 35 delay 667 +/- 49
phc2sys[1916.834]: eth0 rms 42 max 94 freq +2 +/- 36 delay 661 +/- 41
phc2sys[1946.839]: eth0 rms 40 max 91 freq +2 +/- 35 delay 661 +/- 41
phc2sys[1976.843]: eth0 rms 46 max 88 freq -0 +/- 40 delay 667 +/- 49
phc2sys[2006.847]: eth0 rms 49 max 97 freq +2 +/- 43 delay 650 +/- 0
3) testing ptp4l
- 1G connection
# ./linuxptp/ptp4l -P -2 -H -i eth0 -l 6 -m -q -p /dev/ptp0 -f ptp.cfg -s
ptp4l[862.891]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[923.894]: rms 1019697354682 max 5768279314068 freq +26053 +/- 72 delay 488 +/- 1
ptp4l[987.896]: rms 13 max 26 freq +26005 +/- 29 delay 488 +/- 1
ptp4l[1051.899]: rms 14 max 50 freq +25895 +/- 21 delay 488 +/- 1
ptp4l[1115.901]: rms 11 max 27 freq +25878 +/- 17 delay 488 +/- 1
ptp4l[1179.904]: rms 10 max 27 freq +25857 +/- 12 delay 488 +/- 1
ptp4l[1243.906]: rms 14 max 37 freq +25851 +/- 15 delay 488 +/- 1
ptp4l[1307.909]: rms 12 max 33 freq +25835 +/- 15 delay 488 +/- 1
ptp4l[1371.911]: rms 11 max 27 freq +25832 +/- 14 delay 488 +/- 1
ptp4l[1435.914]: rms 11 max 26 freq +25823 +/- 11 delay 488 +/- 1
ptp4l[1499.916]: rms 10 max 29 freq +25829 +/- 11 delay 489 +/- 1
ptp4l[1563.919]: rms 11 max 27 freq +25827 +/- 12 delay 488 +/- 1
- 10M connection
# ./linuxptp/ptp4l -P -2 -H -i eth0 -l 6 -m -q -p /dev/ptp0 -f ptp.cfg -s
ptp4l[51.955]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[112.957]: rms 279468848453933920 max 1580914542977391360 freq +25390 +/- 3207 delay 8222 +/- 36
ptp4l[176.960]: rms 254 max 522 freq +25809 +/- 219 delay 8271 +/- 30
ptp4l[240.962]: rms 271 max 684 freq +25868 +/- 234 delay 8249 +/- 22
ptp4l[304.965]: rms 263 max 556 freq +25894 +/- 227 delay 8225 +/- 47
ptp4l[368.967]: rms 238 max 648 freq +25908 +/- 204 delay 8234 +/- 40
ptp4l[432.970]: rms 274 max 658 freq +25932 +/- 237 delay 8241 +/- 22
ptp4l[496.972]: rms 247 max 557 freq +25943 +/- 213 delay 8223 +/- 26
ptp4l[560.974]: rms 291 max 756 freq +25968 +/- 251 delay 8244 +/- 41
ptp4l[624.977]: rms 249 max 697 freq +25975 +/- 216 delay 8258 +/- 22
Changes in v2:
- fixed (formatting) comments from David Miller <davem@davemloft.net>
v1: https://patchwork.ozlabs.org/cover/1254708/
[1] https://lore.kernel.org/patchwork/cover/799251/
[2] https://usermanual.wiki/Document/SetupGuide.632280828.pdf
https://github.com/t-tibor/msc_thesis
[3] https://patchwork.kernel.org/cover/11421329/
[4] https://patchwork.kernel.org/cover/11433197/
[5] https://sourceforge.net/p/linuxptp/mailman/message/36943248/
Grygorii Strashko (10):
net: ethernet: ti: cpts: use dev_yy() api for logs
net: ethernet: ti: cpts: separate hw counter read from timecounter
net: ethernet: ti: cpts: move tc mult update in cpts_fifo_read()
net: ethernet: ti: cpts: switch to use new .gettimex64() interface
net: ethernet: ti: cpts: optimize packet to event matching
net: ethernet: ti: cpts: move tx timestamp processing to ptp worker
only
net: ethernet: ti: cpts: rework locking
net: ethernet: ti: cpts: move rx timestamp processing to ptp worker
only
net: ethernet: ti: cpts: add irq support
net: ethernet: ti: cpsw: enable cpts irq
drivers/net/ethernet/ti/cpsw.c | 35 +-
drivers/net/ethernet/ti/cpsw_new.c | 33 +-
drivers/net/ethernet/ti/cpsw_priv.c | 17 +-
drivers/net/ethernet/ti/cpsw_priv.h | 2 +
drivers/net/ethernet/ti/cpts.c | 508 +++++++++++++++++---------
drivers/net/ethernet/ti/cpts.h | 27 +-
drivers/net/ethernet/ti/netcp_ethss.c | 3 +-
7 files changed, 442 insertions(+), 183 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next v2 01/10] net: ethernet: ti: cpts: use dev_yy() api for logs
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
@ 2020-03-19 16:57 ` Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 02/10] net: ethernet: ti: cpts: separate hw counter read from timecounter Grygorii Strashko
` (9 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:57 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
Use dev_yy() API instead of pr_yy() for log outputs.
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
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;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net-next v2 02/10] net: ethernet: ti: cpts: separate hw counter read from timecounter
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 01/10] net: ethernet: ti: cpts: use dev_yy() api for logs Grygorii Strashko
@ 2020-03-19 16:57 ` Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 03/10] net: ethernet: ti: cpts: move tc mult update in cpts_fifo_read() Grygorii Strashko
` (8 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:57 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net-next v2 03/10] net: ethernet: ti: cpts: move tc mult update in cpts_fifo_read()
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 01/10] net: ethernet: ti: cpts: use dev_yy() api for logs Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 02/10] net: ethernet: ti: cpts: separate hw counter read from timecounter Grygorii Strashko
@ 2020-03-19 16:57 ` Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 04/10] net: ethernet: ti: cpts: switch to use new .gettimex64() interface Grygorii Strashko
` (7 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:57 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
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 <grygorii.strashko@ti.com>
---
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);
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net-next v2 04/10] net: ethernet: ti: cpts: switch to use new .gettimex64() interface
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
` (2 preceding siblings ...)
2020-03-19 16:57 ` [PATCH net-next v2 03/10] net: ethernet: ti: cpts: move tc mult update in cpts_fifo_read() Grygorii Strashko
@ 2020-03-19 16:57 ` Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 05/10] net: ethernet: ti: cpts: optimize packet to event matching Grygorii Strashko
` (6 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:57 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
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 <grygorii.strashko@ti.com>
---
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,
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net-next v2 05/10] net: ethernet: ti: cpts: optimize packet to event matching
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
` (3 preceding siblings ...)
2020-03-19 16:57 ` [PATCH net-next v2 04/10] net: ethernet: ti: cpts: switch to use new .gettimex64() interface Grygorii Strashko
@ 2020-03-19 16:57 ` Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 06/10] net: ethernet: ti: cpts: move tx timestamp processing to ptp worker only Grygorii Strashko
` (5 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:57 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
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 <grygorii.strashko@ti.com>
---
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));
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net-next v2 06/10] net: ethernet: ti: cpts: move tx timestamp processing to ptp worker only
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
` (4 preceding siblings ...)
2020-03-19 16:57 ` [PATCH net-next v2 05/10] net: ethernet: ti: cpts: optimize packet to event matching Grygorii Strashko
@ 2020-03-19 16:57 ` Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 07/10] net: ethernet: ti: cpts: rework locking Grygorii Strashko
` (4 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:57 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
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 over all defered TX timestamp processing and locking
overcomplicated. 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 <grygorii.strashko@ti.com>
---
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..10061e17d7b4 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;
+ LIST_HEAD(events_free);
+ unsigned long flags;
+ LIST_HEAD(events);
+
+ 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);
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net-next v2 07/10] net: ethernet: ti: cpts: rework locking
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
` (5 preceding siblings ...)
2020-03-19 16:57 ` [PATCH net-next v2 06/10] net: ethernet: ti: cpts: move tx timestamp processing to ptp worker only Grygorii Strashko
@ 2020-03-19 16:57 ` Grygorii Strashko
2020-03-19 16:58 ` [PATCH net-next v2 08/10] net: ethernet: ti: cpts: move rx timestamp processing to ptp worker only Grygorii Strashko
` (3 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:57 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
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 <grygorii.strashko@ti.com>
---
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 10061e17d7b4..3cfa0f78287b 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);
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net-next v2 08/10] net: ethernet: ti: cpts: move rx timestamp processing to ptp worker only
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
` (6 preceding siblings ...)
2020-03-19 16:57 ` [PATCH net-next v2 07/10] net: ethernet: ti: cpts: rework locking Grygorii Strashko
@ 2020-03-19 16:58 ` Grygorii Strashko
2020-03-19 22:41 ` kbuild test robot
2020-03-19 16:58 ` [PATCH net-next v2 09/10] net: ethernet: ti: cpts: add irq support Grygorii Strashko
` (2 subsequent siblings)
10 siblings, 1 reply; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:58 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
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 <grygorii.strashko@ti.com>
---
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 | 3 +-
4 files changed, 104 insertions(+), 58 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..993b4cfa4e86 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);
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net-next v2 09/10] net: ethernet: ti: cpts: add irq support
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
` (7 preceding siblings ...)
2020-03-19 16:58 ` [PATCH net-next v2 08/10] net: ethernet: ti: cpts: move rx timestamp processing to ptp worker only Grygorii Strashko
@ 2020-03-19 16:58 ` Grygorii Strashko
2020-03-19 16:58 ` [PATCH net-next v2 10/10] net: ethernet: ti: cpsw: enable cpts irq Grygorii Strashko
2020-03-20 11:07 ` [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
10 siblings, 0 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:58 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
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 <grygorii.strashko@ti.com>
---
drivers/net/ethernet/ti/cpsw_priv.c | 5 +-
drivers/net/ethernet/ti/cpts.c | 74 ++++++++++++++++++++++++++-
drivers/net/ethernet/ti/cpts.h | 18 ++++++-
drivers/net/ethernet/ti/netcp_ethss.c | 3 +-
4 files changed, 94 insertions(+), 6 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 fe70eb677b88..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,8 @@ 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;
int i, type = -1;
@@ -131,6 +138,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,10 +148,16 @@ 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:
+ 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");
@@ -154,9 +169,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 +192,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 +202,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 */
@@ -254,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;
}
@@ -733,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;
@@ -744,8 +809,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)
@@ -770,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 993b4cfa4e86..97826e03b5d1 100644
--- a/drivers/net/ethernet/ti/cpts.h
+++ b/drivers/net/ethernet/ti/cpts.h
@@ -119,6 +119,9 @@ 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;
+ u32 hw_ts_enable;
};
int cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb);
@@ -126,8 +129,9 @@ 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);
static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb)
{
@@ -139,6 +143,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;
@@ -151,7 +160,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;
}
@@ -174,6 +183,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
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);
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net-next v2 10/10] net: ethernet: ti: cpsw: enable cpts irq
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
` (8 preceding siblings ...)
2020-03-19 16:58 ` [PATCH net-next v2 09/10] net: ethernet: ti: cpts: add irq support Grygorii Strashko
@ 2020-03-19 16:58 ` Grygorii Strashko
2020-03-19 23:39 ` kbuild test robot
2020-03-20 11:07 ` [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
10 siblings, 1 reply; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-19 16:58 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel,
Grygorii Strashko
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 <grygorii.strashko@ti.com>
---
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 ce2155394830..ce8151e95443 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -1573,6 +1573,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.
*/
@@ -1707,6 +1713,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 8561f0e3b769..5d7c8ea4b5c7 100644
--- a/drivers/net/ethernet/ti/cpsw_new.c
+++ b/drivers/net/ethernet/ti/cpsw_new.c
@@ -1901,6 +1901,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);
@@ -1980,6 +1985,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);
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH net-next v2 08/10] net: ethernet: ti: cpts: move rx timestamp processing to ptp worker only
2020-03-19 16:58 ` [PATCH net-next v2 08/10] net: ethernet: ti: cpts: move rx timestamp processing to ptp worker only Grygorii Strashko
@ 2020-03-19 22:41 ` kbuild test robot
0 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2020-03-19 22:41 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 5778 bytes --]
Hi Grygorii,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
[also build test ERROR on net/master linus/master v5.6-rc6 next-20200319]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Grygorii-Strashko/net-ethernet-ti-cpts-add-irq-and-HW_TS_PUSH-events/20200320-041520
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 79e28519ac78dde6d38fe6ea22286af574f5c7db
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
drivers/net/ethernet/ti/cpsw.c: In function 'cpsw_rx_handler':
>> drivers/net/ethernet/ti/cpsw.c:444:7: error: void value not ignored as it ought to be
444 | ret = cpts_rx_timestamp(cpsw->cpts, skb);
| ^
vim +444 drivers/net/ethernet/ti/cpsw.c
343
344 static void cpsw_rx_handler(void *token, int len, int status)
345 {
346 struct page *new_page, *page = token;
347 void *pa = page_address(page);
348 struct cpsw_meta_xdp *xmeta = pa + CPSW_XMETA_OFFSET;
349 struct cpsw_common *cpsw = ndev_to_cpsw(xmeta->ndev);
350 int pkt_size = cpsw->rx_packet_max;
351 int ret = 0, port, ch = xmeta->ch;
352 int headroom = CPSW_HEADROOM;
353 struct net_device *ndev = xmeta->ndev;
354 struct cpsw_priv *priv;
355 struct page_pool *pool;
356 struct sk_buff *skb;
357 struct xdp_buff xdp;
358 dma_addr_t dma;
359
360 if (cpsw->data.dual_emac && status >= 0) {
361 port = CPDMA_RX_SOURCE_PORT(status);
362 if (port)
363 ndev = cpsw->slaves[--port].ndev;
364 }
365
366 priv = netdev_priv(ndev);
367 pool = cpsw->page_pool[ch];
368 if (unlikely(status < 0) || unlikely(!netif_running(ndev))) {
369 /* In dual emac mode check for all interfaces */
370 if (cpsw->data.dual_emac && cpsw->usage_count &&
371 (status >= 0)) {
372 /* The packet received is for the interface which
373 * is already down and the other interface is up
374 * and running, instead of freeing which results
375 * in reducing of the number of rx descriptor in
376 * DMA engine, requeue page back to cpdma.
377 */
378 new_page = page;
379 goto requeue;
380 }
381
382 /* the interface is going down, pages are purged */
383 page_pool_recycle_direct(pool, page);
384 return;
385 }
386
387 new_page = page_pool_dev_alloc_pages(pool);
388 if (unlikely(!new_page)) {
389 new_page = page;
390 ndev->stats.rx_dropped++;
391 goto requeue;
392 }
393
394 if (priv->xdp_prog) {
395 if (status & CPDMA_RX_VLAN_ENCAP) {
396 xdp.data = pa + CPSW_HEADROOM +
397 CPSW_RX_VLAN_ENCAP_HDR_SIZE;
398 xdp.data_end = xdp.data + len -
399 CPSW_RX_VLAN_ENCAP_HDR_SIZE;
400 } else {
401 xdp.data = pa + CPSW_HEADROOM;
402 xdp.data_end = xdp.data + len;
403 }
404
405 xdp_set_data_meta_invalid(&xdp);
406
407 xdp.data_hard_start = pa;
408 xdp.rxq = &priv->xdp_rxq[ch];
409
410 port = priv->emac_port + cpsw->data.dual_emac;
411 ret = cpsw_run_xdp(priv, ch, &xdp, page, port);
412 if (ret != CPSW_XDP_PASS)
413 goto requeue;
414
415 /* XDP prog might have changed packet data and boundaries */
416 len = xdp.data_end - xdp.data;
417 headroom = xdp.data - xdp.data_hard_start;
418
419 /* XDP prog can modify vlan tag, so can't use encap header */
420 status &= ~CPDMA_RX_VLAN_ENCAP;
421 }
422
423 /* pass skb to netstack if no XDP prog or returned XDP_PASS */
424 skb = build_skb(pa, cpsw_rxbuf_total_len(pkt_size));
425 if (!skb) {
426 ndev->stats.rx_dropped++;
427 page_pool_recycle_direct(pool, page);
428 goto requeue;
429 }
430
431 skb_reserve(skb, headroom);
432 skb_put(skb, len);
433 skb->dev = ndev;
434 if (status & CPDMA_RX_VLAN_ENCAP)
435 cpsw_rx_vlan_encap(skb);
436
437 /* unmap page as no netstack skb page recycling */
438 page_pool_release_page(pool, page);
439 ndev->stats.rx_bytes += len;
440 ndev->stats.rx_packets++;
441
442 ret = 0;
443 if (priv->rx_ts_enabled)
> 444 ret = cpts_rx_timestamp(cpsw->cpts, skb);
445
446 if (!ret) {
447 skb->protocol = eth_type_trans(skb, ndev);
448 netif_receive_skb(skb);
449 }
450
451 requeue:
452 xmeta = page_address(new_page) + CPSW_XMETA_OFFSET;
453 xmeta->ndev = ndev;
454 xmeta->ch = ch;
455
456 dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM;
457 ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma,
458 pkt_size, 0);
459 if (ret < 0) {
460 WARN_ON(ret == -ENOMEM);
461 page_pool_recycle_direct(pool, new_page);
462 }
463 }
464
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 49992 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net-next v2 10/10] net: ethernet: ti: cpsw: enable cpts irq
2020-03-19 16:58 ` [PATCH net-next v2 10/10] net: ethernet: ti: cpsw: enable cpts irq Grygorii Strashko
@ 2020-03-19 23:39 ` kbuild test robot
0 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2020-03-19 23:39 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 9933 bytes --]
Hi Grygorii,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
[also build test ERROR on net/master linus/master v5.6-rc6 next-20200319]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Grygorii-Strashko/net-ethernet-ti-cpts-add-irq-and-HW_TS_PUSH-events/20200320-041520
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 79e28519ac78dde6d38fe6ea22286af574f5c7db
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
drivers/net/ethernet/ti/cpsw.c: In function 'cpsw_rx_handler':
drivers/net/ethernet/ti/cpsw.c:444:7: error: void value not ignored as it ought to be
444 | ret = cpts_rx_timestamp(cpsw->cpts, skb);
| ^
drivers/net/ethernet/ti/cpsw.c: In function 'cpsw_probe':
>> drivers/net/ethernet/ti/cpsw.c:1727:2: error: implicit declaration of function 'cpts_set_irqpoll' [-Werror=implicit-function-declaration]
1727 | cpts_set_irqpoll(cpsw->cpts, false);
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/cpts_set_irqpoll +1727 drivers/net/ethernet/ti/cpsw.c
1514
1515 static int cpsw_probe(struct platform_device *pdev)
1516 {
1517 struct device *dev = &pdev->dev;
1518 struct clk *clk;
1519 struct cpsw_platform_data *data;
1520 struct net_device *ndev;
1521 struct cpsw_priv *priv;
1522 void __iomem *ss_regs;
1523 struct resource *ss_res;
1524 struct gpio_descs *mode;
1525 const struct soc_device_attribute *soc;
1526 struct cpsw_common *cpsw;
1527 int ret = 0, ch;
1528 int irq;
1529
1530 cpsw = devm_kzalloc(dev, sizeof(struct cpsw_common), GFP_KERNEL);
1531 if (!cpsw)
1532 return -ENOMEM;
1533
1534 platform_set_drvdata(pdev, cpsw);
1535 cpsw_slave_index = cpsw_slave_index_priv;
1536
1537 cpsw->dev = dev;
1538
1539 mode = devm_gpiod_get_array_optional(dev, "mode", GPIOD_OUT_LOW);
1540 if (IS_ERR(mode)) {
1541 ret = PTR_ERR(mode);
1542 dev_err(dev, "gpio request failed, ret %d\n", ret);
1543 return ret;
1544 }
1545
1546 clk = devm_clk_get(dev, "fck");
1547 if (IS_ERR(clk)) {
1548 ret = PTR_ERR(clk);
1549 dev_err(dev, "fck is not found %d\n", ret);
1550 return ret;
1551 }
1552 cpsw->bus_freq_mhz = clk_get_rate(clk) / 1000000;
1553
1554 ss_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1555 ss_regs = devm_ioremap_resource(dev, ss_res);
1556 if (IS_ERR(ss_regs))
1557 return PTR_ERR(ss_regs);
1558 cpsw->regs = ss_regs;
1559
1560 cpsw->wr_regs = devm_platform_ioremap_resource(pdev, 1);
1561 if (IS_ERR(cpsw->wr_regs))
1562 return PTR_ERR(cpsw->wr_regs);
1563
1564 /* RX IRQ */
1565 irq = platform_get_irq(pdev, 1);
1566 if (irq < 0)
1567 return irq;
1568 cpsw->irqs_table[0] = irq;
1569
1570 /* TX IRQ */
1571 irq = platform_get_irq(pdev, 2);
1572 if (irq < 0)
1573 return irq;
1574 cpsw->irqs_table[1] = irq;
1575
1576 /* get misc irq*/
1577 irq = platform_get_irq(pdev, 3);
1578 if (irq <= 0)
1579 return irq;
1580 cpsw->misc_irq = irq;
1581
1582 /*
1583 * This may be required here for child devices.
1584 */
1585 pm_runtime_enable(dev);
1586
1587 /* Need to enable clocks with runtime PM api to access module
1588 * registers
1589 */
1590 ret = pm_runtime_get_sync(dev);
1591 if (ret < 0) {
1592 pm_runtime_put_noidle(dev);
1593 goto clean_runtime_disable_ret;
1594 }
1595
1596 ret = cpsw_probe_dt(&cpsw->data, pdev);
1597 if (ret)
1598 goto clean_dt_ret;
1599
1600 soc = soc_device_match(cpsw_soc_devices);
1601 if (soc)
1602 cpsw->quirk_irq = 1;
1603
1604 data = &cpsw->data;
1605 cpsw->slaves = devm_kcalloc(dev,
1606 data->slaves, sizeof(struct cpsw_slave),
1607 GFP_KERNEL);
1608 if (!cpsw->slaves) {
1609 ret = -ENOMEM;
1610 goto clean_dt_ret;
1611 }
1612
1613 cpsw->rx_packet_max = max(rx_packet_max, CPSW_MAX_PACKET_SIZE);
1614 cpsw->descs_pool_size = descs_pool_size;
1615
1616 ret = cpsw_init_common(cpsw, ss_regs, ale_ageout,
1617 ss_res->start + CPSW2_BD_OFFSET,
1618 descs_pool_size);
1619 if (ret)
1620 goto clean_dt_ret;
1621
1622 ch = cpsw->quirk_irq ? 0 : 7;
1623 cpsw->txv[0].ch = cpdma_chan_create(cpsw->dma, ch, cpsw_tx_handler, 0);
1624 if (IS_ERR(cpsw->txv[0].ch)) {
1625 dev_err(dev, "error initializing tx dma channel\n");
1626 ret = PTR_ERR(cpsw->txv[0].ch);
1627 goto clean_cpts;
1628 }
1629
1630 cpsw->rxv[0].ch = cpdma_chan_create(cpsw->dma, 0, cpsw_rx_handler, 1);
1631 if (IS_ERR(cpsw->rxv[0].ch)) {
1632 dev_err(dev, "error initializing rx dma channel\n");
1633 ret = PTR_ERR(cpsw->rxv[0].ch);
1634 goto clean_cpts;
1635 }
1636 cpsw_split_res(cpsw);
1637
1638 /* setup netdev */
1639 ndev = devm_alloc_etherdev_mqs(dev, sizeof(struct cpsw_priv),
1640 CPSW_MAX_QUEUES, CPSW_MAX_QUEUES);
1641 if (!ndev) {
1642 dev_err(dev, "error allocating net_device\n");
1643 goto clean_cpts;
1644 }
1645
1646 priv = netdev_priv(ndev);
1647 priv->cpsw = cpsw;
1648 priv->ndev = ndev;
1649 priv->dev = dev;
1650 priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
1651 priv->emac_port = 0;
1652
1653 if (is_valid_ether_addr(data->slave_data[0].mac_addr)) {
1654 memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN);
1655 dev_info(dev, "Detected MACID = %pM\n", priv->mac_addr);
1656 } else {
1657 eth_random_addr(priv->mac_addr);
1658 dev_info(dev, "Random MACID = %pM\n", priv->mac_addr);
1659 }
1660
1661 memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN);
1662
1663 cpsw->slaves[0].ndev = ndev;
1664
1665 ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_RX;
1666
1667 ndev->netdev_ops = &cpsw_netdev_ops;
1668 ndev->ethtool_ops = &cpsw_ethtool_ops;
1669 netif_napi_add(ndev, &cpsw->napi_rx,
1670 cpsw->quirk_irq ? cpsw_rx_poll : cpsw_rx_mq_poll,
1671 CPSW_POLL_WEIGHT);
1672 netif_tx_napi_add(ndev, &cpsw->napi_tx,
1673 cpsw->quirk_irq ? cpsw_tx_poll : cpsw_tx_mq_poll,
1674 CPSW_POLL_WEIGHT);
1675
1676 /* register the network device */
1677 SET_NETDEV_DEV(ndev, dev);
1678 ndev->dev.of_node = cpsw->slaves[0].data->slave_node;
1679 ret = register_netdev(ndev);
1680 if (ret) {
1681 dev_err(dev, "error registering net device\n");
1682 ret = -ENODEV;
1683 goto clean_cpts;
1684 }
1685
1686 if (cpsw->data.dual_emac) {
1687 ret = cpsw_probe_dual_emac(priv);
1688 if (ret) {
1689 cpsw_err(priv, probe, "error probe slave 2 emac interface\n");
1690 goto clean_unregister_netdev_ret;
1691 }
1692 }
1693
1694 /* Grab RX and TX IRQs. Note that we also have RX_THRESHOLD and
1695 * MISC IRQs which are always kept disabled with this driver so
1696 * we will not request them.
1697 *
1698 * If anyone wants to implement support for those, make sure to
1699 * first request and append them to irqs_table array.
1700 */
1701 ret = devm_request_irq(dev, cpsw->irqs_table[0], cpsw_rx_interrupt,
1702 0, dev_name(dev), cpsw);
1703 if (ret < 0) {
1704 dev_err(dev, "error attaching irq (%d)\n", ret);
1705 goto clean_unregister_netdev_ret;
1706 }
1707
1708
1709 ret = devm_request_irq(dev, cpsw->irqs_table[1], cpsw_tx_interrupt,
1710 0, dev_name(&pdev->dev), cpsw);
1711 if (ret < 0) {
1712 dev_err(dev, "error attaching irq (%d)\n", ret);
1713 goto clean_unregister_netdev_ret;
1714 }
1715
1716 if (!cpsw->cpts)
1717 goto skip_cpts;
1718
1719 ret = devm_request_irq(&pdev->dev, cpsw->misc_irq, cpsw_misc_interrupt,
1720 0, dev_name(&pdev->dev), cpsw);
1721 if (ret < 0) {
1722 dev_err(dev, "error attaching misc irq (%d)\n", ret);
1723 goto clean_unregister_netdev_ret;
1724 }
1725
1726 /* Enable misc CPTS evnt_pend IRQ */
> 1727 cpts_set_irqpoll(cpsw->cpts, false);
1728 writel(0x10, &cpsw->wr_regs->misc_en);
1729
1730 skip_cpts:
1731 cpsw_notice(priv, probe,
1732 "initialized device (regs %pa, irq %d, pool size %d)\n",
1733 &ss_res->start, cpsw->irqs_table[0], descs_pool_size);
1734
1735 pm_runtime_put(&pdev->dev);
1736
1737 return 0;
1738
1739 clean_unregister_netdev_ret:
1740 unregister_netdev(ndev);
1741 clean_cpts:
1742 cpts_release(cpsw->cpts);
1743 cpdma_ctlr_destroy(cpsw->dma);
1744 clean_dt_ret:
1745 cpsw_remove_dt(pdev);
1746 pm_runtime_put_sync(&pdev->dev);
1747 clean_runtime_disable_ret:
1748 pm_runtime_disable(&pdev->dev);
1749 return ret;
1750 }
1751
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 49992 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
` (9 preceding siblings ...)
2020-03-19 16:58 ` [PATCH net-next v2 10/10] net: ethernet: ti: cpsw: enable cpts irq Grygorii Strashko
@ 2020-03-20 11:07 ` Grygorii Strashko
10 siblings, 0 replies; 14+ messages in thread
From: Grygorii Strashko @ 2020-03-20 11:07 UTC (permalink / raw)
To: David S . Miller, Richard Cochran, Lokesh Vutla, Tony Lindgren
Cc: Sekhar Nori, Murali Karicheri, netdev, linux-omap, linux-kernel
On 19/03/2020 18:57, Grygorii Strashko wrote:
> Hi Richard, All,
>
> v2: no functional changes.
>
> This is re-spin of patches to add CPSW IRQ and HW_TS_PUSH events support I've
> sent long time ago [1]. In this series, I've tried to restructure and split changes,
> and also add few additional optimizations comparing to initial RFC submission [1].
>
Pls, ignore this submission. Sent by mistake.
Sorry for this.
--
Best regards,
grygorii
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2020-03-20 11:08 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-19 16:57 [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 01/10] net: ethernet: ti: cpts: use dev_yy() api for logs Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 02/10] net: ethernet: ti: cpts: separate hw counter read from timecounter Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 03/10] net: ethernet: ti: cpts: move tc mult update in cpts_fifo_read() Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 04/10] net: ethernet: ti: cpts: switch to use new .gettimex64() interface Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 05/10] net: ethernet: ti: cpts: optimize packet to event matching Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 06/10] net: ethernet: ti: cpts: move tx timestamp processing to ptp worker only Grygorii Strashko
2020-03-19 16:57 ` [PATCH net-next v2 07/10] net: ethernet: ti: cpts: rework locking Grygorii Strashko
2020-03-19 16:58 ` [PATCH net-next v2 08/10] net: ethernet: ti: cpts: move rx timestamp processing to ptp worker only Grygorii Strashko
2020-03-19 22:41 ` kbuild test robot
2020-03-19 16:58 ` [PATCH net-next v2 09/10] net: ethernet: ti: cpts: add irq support Grygorii Strashko
2020-03-19 16:58 ` [PATCH net-next v2 10/10] net: ethernet: ti: cpsw: enable cpts irq Grygorii Strashko
2020-03-19 23:39 ` kbuild test robot
2020-03-20 11:07 ` [PATCH net-next v2 00/10] net: ethernet: ti: cpts: add irq and HW_TS_PUSH events Grygorii Strashko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.