jclark / rpi-cm4-ptp-guide

Guide to using the hardware PTP support in the Raspberry Pi CM4
MIT License
89 stars 10 forks source link

ts2phc "interface eth0 does not have a PHC" error #4

Open jclark opened 2 years ago

jclark commented 2 years ago

When starting ts2phc using systemd on boot, it exits with the error "interface eth0 does not have a PHC".

Manually starting it later does not have this problem.

jclark commented 2 years ago

Using -c /dev/ptp0 rather -c eth0 also seems to avoid the problem.

jclark commented 2 years ago

linuxptp tests this by looking at phc_index in the ethtool_ts_info struct returned by SIOCETHTOOL with a ETHTOOL_GET_TS_INFO command.

When I do ethtool -T eth0 from systemd, it shows no hardware clock

Nov 12 10:47:46 wensleydale ethtool[419]: Time stamping parameters for eth0:
Nov 12 10:47:46 wensleydale ethtool[419]: Capabilities:
Nov 12 10:47:46 wensleydale ethtool[419]:         software-transmit
Nov 12 10:47:46 wensleydale ethtool[419]:         software-receive
Nov 12 10:47:46 wensleydale ethtool[419]:         software-system-clock
Nov 12 10:47:46 wensleydale ethtool[419]: PTP Hardware Clock: none
Nov 12 10:47:46 wensleydale ethtool[419]: Hardware Transmit Timestamp Modes: none
Nov 12 10:47:46 wensleydale ethtool[419]: Hardware Receive Filter Modes: none

Looks like this is happening before the link is up:

Nov 12 10:48:03 wensleydale kernel: [   10.494911] bcmgenet fd580000.ethernet eth0: Link is Up - 1Gbps/Full - flow control off
Nov 12 10:48:03 wensleydale kernel: [   10.494952] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

ls --full-time /dev/ptp0 shows /dev/ptp0 was created at 10:47:44.

But my unit file has

After=sys-subsystem-net-devices-%i.device
jclark commented 2 years ago

We can workaround this by adding a unit /etc/systemd/system/phc@.service

[Unit]
Description=Ensure PTP hardware clock (PHC) of %I is ready
Documentation=man:phc_ctl
After=sys-subsystem-net-devices-%i.device
Before=ptp4l@%i.service

[Service]
Type=oneshot
ExecStart=/usr/sbin/phc_ctl -Q %I
RemainAfterExit=yes
Restart=on-failure

[Install]
WantedBy=multi-user.target

Then we make ts2phc@.service depend on this:

Wants=phc@%i.service
After=phc@%i.service
jclark commented 2 years ago

This can also happen with clients and the timemaster service. ptp4l gives the following error:

interface 'eth0' does not support requested timestamping