Skip to content

Commit e98d2f9

Browse files
brudleysabhiram
authored andcommitted
Fix unaligned access exception in gptp, add SW hook (#22)
* Fix unaligned access exception * Latest gptp snapshot * Clean prop delay workaround for lowrisc_eth. * Remove prop_delay workaround. Timestamp issue fixed in lowrisc eth driver.
1 parent 32803fc commit e98d2f9

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

samples/net/gptp/prj.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ CONFIG_NET_CONFIG_SETTINGS=y
3838
# First ethernet interface will use these settings
3939
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
4040
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
41-
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
42-
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
41+
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.168.1.61"
42+
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.168.1.62"
4343

4444
# gPTP settings
4545
CONFIG_NET_GPTP=y
4646
CONFIG_NET_GPTP_STATISTICS=y
47-
CONFIG_NET_GPTP_GM_CAPABLE=y
47+
CONFIG_NET_GPTP_GM_CAPABLE=n
4848

4949
# How many traffic classes to enable
5050
CONFIG_NET_TC_TX_COUNT=6

subsys/net/l2/ethernet/gptp/gptp_data_set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ struct gptp_default_ds {
277277
bool gm_capable;
278278

279279
/** Number of ports of the time-aware system. */
280-
uint8_t nb_ports;
280+
uint32_t nb_ports;
281281

282282
/** Primary priority of the time-aware system. */
283283
uint8_t priority1;

subsys/net/l2/ethernet/gptp/gptp_md.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ LOG_MODULE_DECLARE(net_gptp, CONFIG_NET_GPTP_LOG_LEVEL);
1212
#include "gptp_data_set.h"
1313
#include "gptp_private.h"
1414

15+
#ifdef CONFIG_PTP_CLOCK_LOWRISC
16+
#include <posix/time.h>
17+
#endif
18+
1519
static void gptp_md_sync_prepare(struct net_pkt *pkt,
1620
struct gptp_md_sync_info *sync_send,
1721
int port_number)
@@ -101,6 +105,10 @@ static int gptp_set_md_sync_receive(int port,
101105
struct net_ptp_time *sync_ts;
102106
double prop_delay_rated;
103107
double delay_asymmetry_rated;
108+
#ifdef CONFIG_PTP_CLOCK_LOWRISC
109+
#define UPDATE_SECS 30
110+
static int count = UPDATE_SECS;
111+
#endif
104112

105113
state = &GPTP_PORT_STATE(port)->sync_rcv;
106114
if (!state->rcvd_sync_ptr || !state->rcvd_follow_up_ptr) {
@@ -129,6 +137,30 @@ static int gptp_set_md_sync_receive(int port,
129137
sync_rcv->upstream_tx_time *= NSEC_PER_SEC;
130138
sync_rcv->upstream_tx_time += sync_ts->nanosecond;
131139

140+
#ifdef CONFIG_PTP_CLOCK_LOWRISC
141+
if (++count >= UPDATE_SECS) {
142+
struct timespec tp;
143+
tp.tv_sec = sync_rcv->precise_orig_ts.second;
144+
tp.tv_nsec = sync_rcv->precise_orig_ts.nanosecond;
145+
clock_settime(CLOCK_REALTIME, &tp);
146+
147+
if (0) {
148+
struct tm tm, *tm_p = &tm;
149+
gmtime_r(&tp.tv_sec, tm_p);
150+
NET_WARN("seq %d sec:ns %d:%d %d-%02u-%02u " "%02u:%02u:%02u UTC",
151+
ntohs(fup_hdr->sequence_id),
152+
sync_rcv->precise_orig_ts._sec.low, sync_rcv->precise_orig_ts.nanosecond,
153+
tm_p->tm_year + 1900,
154+
tm_p->tm_mon + 1,
155+
tm_p->tm_mday,
156+
tm_p->tm_hour,
157+
tm_p->tm_min,
158+
tm_p->tm_sec);
159+
}
160+
count = 0;
161+
}
162+
#endif
163+
132164
prop_delay_rated = port_ds->neighbor_prop_delay;
133165
prop_delay_rated /= port_ds->neighbor_rate_ratio;
134166

@@ -402,6 +434,9 @@ static void gptp_md_pdelay_compute(int port)
402434
*/
403435
if ((port_ds->neighbor_prop_delay <=
404436
port_ds->neighbor_prop_delay_thresh)) {
437+
if (port_ds->as_capable == false) {
438+
NET_WARN("AS capable: true");
439+
}
405440
port_ds->as_capable = true;
406441
} else {
407442
port_ds->as_capable = false;

subsys/net/l2/ethernet/gptp/gptp_messages.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,9 @@ void gptp_handle_pdelay_req(int port, struct net_pkt *pkt)
643643
GPTP_STATS_INC(port, rx_pdelay_req_count);
644644

645645
if (ts_cb_registered == true) {
646+
#ifndef CONFIG_PTP_CLOCK_LOWRISC
646647
NET_WARN("Multiple pdelay requests");
648+
#endif
647649

648650
net_if_unregister_timestamp_cb(&pdelay_response_timestamp_cb);
649651
net_pkt_unref(pdelay_response_timestamp_cb.pkt);

subsys/net/l2/ethernet/gptp/gptp_mi.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ static void gptp_update_local_port_clock(void)
746746
struct net_ptp_time tm;
747747
int key;
748748

749+
NET_WARN("Setting CLOCK!\n");
750+
749751
state = &GPTP_STATE()->clk_slave_sync;
750752
global_ds = GPTP_GLOBAL_DS();
751753
port = state->pss_rcv_ptr->local_port_number;
@@ -865,6 +867,8 @@ static void gptp_mi_clk_slave_sync_state_machine(void)
865867
gptp_update_local_port_clock();
866868
#endif
867869
gptp_call_phase_dis_cb();
870+
} else {
871+
NET_WARN("slave_sync: would set clock but !state->rcvd_pss");
868872
}
869873

870874
break;
@@ -920,6 +924,7 @@ static inline void gptp_mi_setup_sync_send_time(void)
920924
struct gptp_global_ds *global_ds;
921925
uint64_t time_helper;
922926

927+
NET_WARN("Recogni should never be here");
923928
state = &GPTP_STATE()->clk_master_sync_send;
924929
global_ds = GPTP_GLOBAL_DS();
925930

@@ -1721,6 +1726,7 @@ static int compute_best_vector(void)
17211726
global_ds->gm_priority.port_number = best_vector->port_number;
17221727
}
17231728

1729+
NET_WARN("compute_best_vector: %d", best_port);
17241730
return best_port;
17251731
}
17261732

@@ -1864,6 +1870,8 @@ static void gptp_updt_roles_tree(void)
18641870
(gm_prio->root_system_id.grand_master_prio1 == 255U) ?
18651871
false : true;
18661872

1873+
NET_WARN("gptp_updt_roles_tree(): gm_present = %d, master_prio %d", global_ds->gm_present, gm_prio->root_system_id.grand_master_prio1);
1874+
18671875
/* Assign the port role for port 0. */
18681876
for (port = GPTP_PORT_START; port < GPTP_PORT_END; port++) {
18691877
if (global_ds->selected_role[port] == GPTP_PORT_SLAVE) {

0 commit comments

Comments
 (0)