@@ -41,11 +41,12 @@ SOF_TIMESTAMPING_SOFTWARE: return system time stamp generated in
4141SOF_TIMESTAMPING_TX/RX determine how time stamps are generated.
4242SOF_TIMESTAMPING_RAW/SYS determine how they are reported in the
4343following control message:
44- struct scm_timestamping {
45- struct timespec systime;
46- struct timespec hwtimetrans;
47- struct timespec hwtimeraw;
48- };
44+
45+ struct scm_timestamping {
46+ struct timespec systime;
47+ struct timespec hwtimetrans;
48+ struct timespec hwtimeraw;
49+ };
4950
5051recvmsg() can be used to get this control message for regular incoming
5152packets. For send time stamps the outgoing packet is looped back to
@@ -87,12 +88,13 @@ by the network device and will be empty without that support.
8788SIOCSHWTSTAMP:
8889
8990Hardware time stamping must also be initialized for each device driver
90- that is expected to do hardware time stamping. The parameter is:
91+ that is expected to do hardware time stamping. The parameter is defined in
92+ /include/linux/net_tstamp.h as:
9193
9294struct hwtstamp_config {
93- int flags; /* no flags defined right now, must be zero */
94- int tx_type; /* HWTSTAMP_TX_* */
95- int rx_filter; /* HWTSTAMP_FILTER_* */
95+ int flags; /* no flags defined right now, must be zero */
96+ int tx_type; /* HWTSTAMP_TX_* */
97+ int rx_filter; /* HWTSTAMP_FILTER_* */
9698};
9799
98100Desired behavior is passed into the kernel and to a specific device by
@@ -139,42 +141,56 @@ enum {
139141 /* time stamp any incoming packet */
140142 HWTSTAMP_FILTER_ALL,
141143
142- /* return value: time stamp all packets requested plus some others */
143- HWTSTAMP_FILTER_SOME,
144+ /* return value: time stamp all packets requested plus some others */
145+ HWTSTAMP_FILTER_SOME,
144146
145147 /* PTP v1, UDP, any kind of event packet */
146148 HWTSTAMP_FILTER_PTP_V1_L4_EVENT,
147149
148- ...
150+ /* for the complete list of values, please check
151+ * the include file /include/linux/net_tstamp.h
152+ */
149153};
150154
151155
152156DEVICE IMPLEMENTATION
153157
154158A driver which supports hardware time stamping must support the
155- SIOCSHWTSTAMP ioctl. Time stamps for received packets must be stored
156- in the skb with skb_hwtstamp_set().
159+ SIOCSHWTSTAMP ioctl and update the supplied struct hwtstamp_config with
160+ the actual values as described in the section on SIOCSHWTSTAMP.
161+
162+ Time stamps for received packets must be stored in the skb. To get a pointer
163+ to the shared time stamp structure of the skb call skb_hwtstamps(). Then
164+ set the time stamps in the structure:
165+
166+ struct skb_shared_hwtstamps {
167+ /* hardware time stamp transformed into duration
168+ * since arbitrary point in time
169+ */
170+ ktime_t hwtstamp;
171+ ktime_t syststamp; /* hwtstamp transformed to system time base */
172+ };
157173
158174Time stamps for outgoing packets are to be generated as follows:
159- - In hard_start_xmit(), check if skb_hwtstamp_check_tx_hardware()
160- returns non-zero. If yes, then the driver is expected
161- to do hardware time stamping.
175+ - In hard_start_xmit(), check if skb_tx(skb)->hardware is set no-zero.
176+ If yes, then the driver is expected to do hardware time stamping.
162177- If this is possible for the skb and requested, then declare
163- that the driver is doing the time stamping by calling
164- skb_hwtstamp_tx_in_progress(). A driver not supporting
165- hardware time stamping doesn't do that. A driver must never
166- touch sk_buff::tstamp! It is used to store how time stamping
167- for an outgoing packets is to be done.
178+ that the driver is doing the time stamping by setting the field
179+ skb_tx(skb)->in_progress non-zero. You might want to keep a pointer
180+ to the associated skb for the next step and not free the skb. A driver
181+ not supporting hardware time stamping doesn't do that. A driver must
182+ never touch sk_buff::tstamp! It is used to store software generated
183+ time stamps by the network subsystem.
168184- As soon as the driver has sent the packet and/or obtained a
169185 hardware time stamp for it, it passes the time stamp back by
170186 calling skb_hwtstamp_tx() with the original skb, the raw
171- hardware time stamp and a handle to the device (necessary
172- to convert the hardware time stamp to system time). If obtaining
173- the hardware time stamp somehow fails, then the driver should
174- not fall back to software time stamping. The rationale is that
175- this would occur at a later time in the processing pipeline
176- than other software time stamping and therefore could lead
177- to unexpected deltas between time stamps.
178- - If the driver did not call skb_hwtstamp_tx_in_progress() , then
187+ hardware time stamp. skb_hwtstamp_tx() clones the original skb and
188+ adds the timestamps, therefore the original skb has to be freed now.
189+ If obtaining the hardware time stamp somehow fails, then the driver
190+ should not fall back to software time stamping. The rationale is that
191+ this would occur at a later time in the processing pipeline than other
192+ software time stamping and therefore could lead to unexpected deltas
193+ between time stamps.
194+ - If the driver did not call set skb_tx(skb)->in_progress , then
179195 dev_hard_start_xmit() checks whether software time stamping
180196 is wanted as fallback and potentially generates the time stamp.
0 commit comments