Apalis imx6 + libpcap

Hello community,

I try using libpcap on Yocto + Apalis iMX6 and i get problem.
My goal is to get hardware timestamp with good precision. FEC driver is well done and seems able to produce a good timestamp precision. this is my code sample to fix pcap options :

int res1= pcap_set_tstamp_type(handle, PCAP_TSTAMP_ADAPTER_UNSYNCED); 

int res2= pcap_set_tstamp_precision(handle, PCAP_TSTAMP_PRECISION_NANO);

But my problem is that when i use timestamp type PCAP_TSTAMP_ADAPTER_UNSYNCED are not good. Precision is not good.

Time stamping parameters for eth0 using ethtool:
Capabilities:
        hardware-transmit     (SOF_TIMESTAMPING_TX_HARDWARE)
        software-transmit     (SOF_TIMESTAMPING_TX_SOFTWARE)
        hardware-receive      (SOF_TIMESTAMPING_RX_HARDWARE)
        software-receive      (SOF_TIMESTAMPING_RX_SOFTWARE)
        software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
        hardware-raw-clock    (SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
        off                   (HWTSTAMP_TX_OFF)
        on                    (HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:
        none                  (HWTSTAMP_FILTER_NONE)
        all                   (HWTSTAMP_FILTER_ALL)

And to conclude, the same sample code is working well on Colibri iMX6!

BR

Fred

What exact versions of things (hardware and software) are you talking about? How does your environment look like (e.g. carrier board, network infrastructure etc.)?

Hello,

Apalis Evalboard rev. 1.1.
Apalis IMX6Q 1GB rev. 1.1A
Yocto krogoth + libpcap 1.7.4 (from yocto repo)

BR

Frederic

I don’t think we ever released any Krogoth based BSP.

Same problem with morty…

This option doesn’t work and i don’t know why :

int toto1 = pcap_set_tstamp_type(handle, PCAP_TSTAMP_ADAPTER_UNSYNCED);

To clarify : if i put this option, the timestamp is always the same…he’s never refreshed.

It is a very strange behavior : the same program using libpcap gives us differents results according to the board used (colibri or apalis).
It seems to be a driver/controller problem.
@marcel.tx : what do you think about that?

While the SoCs used on Colibri and Apalis iMX6 are both i.MX 6 chips, they are slightly different types inside the familiy (i.MX 6DL vs. i.MX 6Q) the Ethernet controller though is the same (FEC), and the same base device tree is used (imx6qdl.dtsi). It sounds like a clock is not enabled/not setup, but the clock configuration is shared in the above mentioned device tree.

Maybe sysfs clock information has some clue: /sys/kernel/debug/clk/clk_summary

Hello stefan.tx,

I just copy/paste the clk_summary in a next post. But i doesn’t see a clue concerning my problem.
Have you got an idea ?

@Marcel.tx : have you got an idea ? (i try using last Morty version and it doesn’t work too ! )

Hello all,

I just add an update :
I think it’s probably a driver problem, not a libpcap problem. Indeed, i use socket + SOF_TIMESTAMPING_RAW_HARDWARE and problem is the same.
On colibri: HW timestamp are OK…
On apalis : HW timestamp are never updated.

   clock                        enable_cnt  prepare_cnt  rate        accuracy
---------------------------------------------------------------------------------
  anaclk2                        0           0            0          0          
     lvds2_in                    0           0            0          0          
  anaclk1                        0           0            0          0          
     lvds1_in                    0           0            0          0          
  dummy                          2           3            0          0          
     lvds2_sel                   0           0            0          0          
        lvds2_gate               0           0            0          0          
     usbphy2_gate                1           1            0          0          
     usbphy1_gate                1           1            0          0          
  clk24m                         0           0            24000000   0          
  osc                            7           7            24000000   0          
     cko2_sel                    1           1            24000000   0          
        cko2_podf                1           1            24000000   0          
           cko2                  2           2            24000000   0          
              cko                1           1            24000000   0          
     periph_clk2_sel             0           0            24000000   0          
        periph_clk2              0           0            24000000   0          
     gpt_3m                      1           1            3000000    0          
     pll7_bypass_src             1           1            24000000   0          
        pll7                     1           1            480000000  0          
           pll7_bypass           1           1            480000000  0          
              pll7_usb_host      1           1            480000000  0          
                 usbphy2         1           1            480000000  0          
     pll6_bypass_src             1           1            24000000   0          
        pll6                     1           1            500000000  0          
           pll6_bypass           1           1            500000000  0          
              pll6_enet          3           3            500000000  0          
                 enet_ref        1           1            125000000  0          
                 pcie_ref        1           1            125000000  0          
                    pcie_ref_125m 1           1            125000000  0          
                 sata_ref        2           2            100000000  0          
                    lvds1_sel    1           1            100000000  0          
                       lvds1_gate 1           1            100000000  0          
                    sata_ref_100m 1           1            100000000  0          
     pll5_bypass_src             1           1            24000000   0          
        pll5                     1           1            1278084000 0          
           pll5_bypass           1           1            1278084000 0          
              pll5_video         1           1            1278084000 0          
                 pll5_post_div   1           1            319521000  0          
                    pll5_video_div 2           2            319521000  0          
                       ipu2_di1_pre_sel 0           0            319521000  0          
                          ipu2_di1_pre 0           0            106507000  0          
                             ipu2_di1_sel 0           0            106507000  0          
                                ipu2_di1 0           0            106507000  0          
                       ipu2_di0_pre_sel 1           1            319521000  0          
                          ipu2_di0_pre 1           1            159760500  0          
                             ipu2_di0_sel 1           1            159760500  0          
                                ipu2_di0 1           1            159760500  0          
                                   ipu2_pclk0_sel 1           1            159760500  0          
                                      ipu2_pclk0_div 1           1            159760500  0          
                                         ipu2_pclk_0 1           1            159760500  0          
                       ipu1_di1_pre_sel 0           0            319521000  0          
                          ipu1_di1_pre 0           0            106507000  0          
                             ipu1_di1_sel 0           0            106507000  0          
                                ipu1_di1 0           0            106507000  0          
                       ipu1_di0_pre_sel 1           1            319521000  0          
                          ipu1_di0_pre 1           1            106507000  0          
                             ipu1_di0_sel 1           1            106507000  0          
                                ipu1_di0 1           1            106507000  0          
                                   ipu1_pclk0_sel 1           1            106507000  0          
                                      ipu1_pclk0_div 1           1            106507000  0          
                                         ipu1_pclk_0 1           1            106507000  0          
                       ldb_di1_sel 0           0            319521000  0          
                          ldb_di1_div_7 0           0            45645857   0          
                             ldb_di1_div_sel 0           0            45645857   0          
                                ldb_di1 0           0            45645857   0          
                          ldb_di1_div_3_5 0           0            91291714   0          
                       ldb_di0_sel 0           0            319521000  0          
                          ldb_di0_div_7 0           0            45645857   0          
                             ldb_di0_div_sel 0           0            45645857   0          
                                ldb_di0 0           0            45645857   0          
                          ldb_di0_div_3_5 0           0            91291714   0          
     pll4_bypass_src             0           0            24000000   0          
        pll4                     0           0            147456000  0          
           pll4_bypass           0           0            147456000  0          
              pll4_audio         0           0            147456000  0          
                 pll4_post_div   0           0            36864000   0          
                    pll4_audio_div 0           0            36864000   0          
     pll3_bypass_src             1           1            24000000   0          
        pll3                     1           1            480000000  0          
           pll3_bypass           1           1            480000000  0          
              pll3_usb_otg       3           3            480000000  0          
                 gpu2d_core_sel  0           0            480000000  0          
                    gpu2d_core_podf 0           0            480000000  0          
                       gpu2d_core 0           0            480000000  0          
                 asrc_sel        0           0            480000000  0          
                    asrc_pred    0           0            240000000  0          
                       asrc_podf 0           0            30000000   0          
                          asrc   0           0            30000000   0          
                 esai_sel        0           0            480000000  0          
                    esai_pred    0           0            240000000  0          
                       esai_podf 0           0            30000000   0          
                          esai_extal 0           0            30000000   0          
                 periph2_clk2_sel 0           0            480000000  0          
                    periph2_clk2 0           0            480000000  0          
                 pll3_60m        0           0            60000000   0          
                    can_root     0           0            30000000   0          
                       can2_serial 0           0            30000000   0          
                       can1_serial 0           0            30000000   0          
                    ecspi_root   0           0            60000000   0          
                       ecspi5    0           0            60000000   0          
                       ecspi4    0           0            60000000   0          
                       ecspi3    0           0            60000000   0          
                       ecspi2    0           0            60000000   0          
                       ecspi1    0           0            60000000   0          
                 pll3_80m        1           1            80000000   0          
                    uart_serial_podf 1           1            80000000   0          
                       uart_serial 1           2            80000000   0          
                 pll3_120m       0           0            120000000  0          
                 pll3_pfd3_454m  0           0            454736842  0          
                    spdif_sel    0           0            454736842  0          
                       spdif_pred 0           0            227368421  0          
                          spdif_podf 0           0            28421052   0          
                             spdif 0           0            28421052   0          
                 pll3_pfd2_508m  0           0            508235294  0          
                    ssi3_sel     0           0            508235294  0          
                       ssi3_pred 0           0            127058823  0          
                          ssi3_podf 0           0            63529411   0          
                             ssi3 0           0            63529411   0          
                    ssi2_sel     0           0            508235294  0          
                       ssi2_pred 0           0            127058823  0          
                          ssi2_podf 0           0            63529411   0          
                             ssi2 0           0            63529411   0          
                    ssi1_sel     0           0            508235294  0          
                       ssi1_pred 0           0            127058823  0          
                          ssi1_podf 0           0            63529411   0          
                             ssi1 0           0            63529411   0          
                 pll3_pfd1_540m  2           2            540000000  0          
                    axi_alt_sel  1           1            540000000  0          
                       axi_sel   1           1            540000000  0          
                          axi    3           3            270000000  0          
                             openvg_axi 0           0            270000000  0          
                             mlb 0           0            270000000  0          
                             vpu_axi_sel 0           0            270000000  0          
                                vpu_axi_podf 0           0            270000000  0          
                                   vpu_axi 0           0            270000000  0          
                             vdo_axi_sel 0           0            270000000  0          
                                vdo_axi 0           0            270000000  0          
                                   vdoa 0           0            270000000  0          
                             emi_slow_sel 1           1            270000000  0          
                                emi_slow_podf 1           1            135000000  0          
                                   eim_slow 1           1            135000000  0          
                             pcie_axi_sel 1           1            270000000  0          
                                pcie_axi 1           1            270000000  0          
                             gpu3d_axi 0           0            270000000  0          
                             gpu2d_axi 0           0            270000000  0          
                    hdmi_isfr    1           1            540000000  0          
                    video_27m    0           0            27000000   0          
                 pll3_pfd0_720m  0           0            720000000  0          
                 usbphy1         0           0            480000000  0          
     pll2_bypass_src             1           1            24000000   0          
        pll2                     1           1            528000000  0          
           pll2_bypass           1           1            528000000  0          
              pll2_bus           2           2            528000000  0          
                 periph2_pre     0           0            528000000  0          
                    periph2      0           0            528000000  0          
                       mmdc_ch1_axi 0           0            528000000  0          
                 periph_pre      1           1            528000000  0          
                    periph       2           2            528000000  0          
                       mmdc_ch0_axi 3           3            528000000  0          
                          gpu3d_core_sel 0           0            528000000  0          
                             gpu3d_core_podf 0           0            528000000  0          
                                gpu3d_core 0           0            528000000  0          
                          ipu2_sel 1           1            528000000  0          
                             ipu2_podf 1           1            264000000  0          
                                ipu2 1           1            264000000  0          
                                   ipu2_pclk1_sel 0           0            264000000  0          
                                      ipu2_pclk1_div 0           0            0          0          
                                         ipu2_pclk_1 0           0            0          0          
                                dcic2 0           0            264000000  0          
                          ipu1_sel 1           1            528000000  0          
                             ipu1_podf 1           1            264000000  0          
                                ipu1 1           1            264000000  0          
                                   ipu1_pclk1_sel 0           0            264000000  0          
                                      ipu1_pclk1_div 0           0            0          0          
                                         ipu1_pclk_1 0           0            0          0          
                                dcic1 0           0            264000000  0          
                       ahb       8           8            132000000  0          
                          sdma   16          2            132000000  0          
                          sata   1           1            132000000  0          
                          rom    1           1            132000000  0          
                          ocram  2           2            132000000  0          
                          hdmi_iahb 1           1            132000000  0          
                          esai_mem 0           0            132000000  0          
                          esai_ipg 0           0            132000000  0          
                          caam_aclk 1           1            132000000  0          
                          caam_mem 1           1            132000000  0          
                          asrc_mem 0           0            132000000  0          
                          asrc_ipg 0           0            132000000  0          
                          cko1_sel 0           0            132000000  0          
                             cko1_podf 0           0            16500000   0          
                                cko1 0           0            16500000   0          
                          ipg    6           9            66000000   0          
                             usboh3 1           1            66000000   0          
                             uart_ipg 1           2            66000000   0          
                             ssi3_ipg 0           0            66000000   0          
                             ssi2_ipg 0           0            66000000   0          
                             ssi1_ipg 0           1            66000000   0          
                             spdif_gclk 0           1            66000000   0          
                             spba 0           0            66000000   0          
                             iim 0           1            66000000   0          
                             gpt_ipg 1           1            66000000   0          
                             enet 2           2            66000000   0          
                             can2_ipg 0           0            66000000   0          
                             can1_ipg 0           0            66000000   0          
                             caam_ipg 1           1            66000000   0          
                             ipg_per 1           1            66000000   0          
                                pwm4 1           1            66000000   0          
                                pwm3 0           0            66000000   0          
                                pwm2 0           0            66000000   0          
                                pwm1 0           0            66000000   0          
                                i2c3 0           0            66000000   0          
                                i2c2 0           0            66000000   0          
                                i2c1 0           0            66000000   0          
                                gpt_ipg_per 0           0            66000000   0          
                 pll2_pfd2_396m  2           2            396000000  0          
                    enfc_sel     0           0            396000000  0          
                       enfc_pred 0           0            79200000   0          
                          enfc_podf 0           0            19800000   0          
                             enfc 0           0            19800000   0          
                                gpmi_io 0           0            19800000   0          
                    emi_sel      0           0            396000000  0          
                       emi_podf  0           0            198000000  0          
                    usdhc4_sel   0           0            396000000  0          
                       usdhc4_podf 0           0            198000000  0          
                          usdhc4 0           0            198000000  0          
                             gpmi_bch 0           0            198000000  0          
                    usdhc3_sel   0           0            396000000  0          
                       usdhc3_podf 0           0            198000000  0          
                          usdhc3 0           0            198000000  0          
                             apbh_dma 0           0            198000000  0          
                             per1_bch 0           0            198000000  0          
                             gpmi_bch_apb 0           0            198000000  0          
                             gpmi_apb 0           0            198000000  0          
                    usdhc2_sel   0           0            396000000  0          
                       usdhc2_podf 0           0            198000000  0          
                          usdhc2 0           0            198000000  0          
                    usdhc1_sel   0           0            396000000  0          
                       usdhc1_podf 0           0            198000000  0          
                          usdhc1 0           0            198000000  0          
                    hsi_tx_sel   1           1            396000000  0          
                       hsi_tx_podf 1           1            198000000  0          
                          hsi_tx 1           1            198000000  0          
                    step         1           1            396000000  0          
                       pll1_sw   1           1            396000000  0          
                          arm    2           2            396000000  0          
                             twd 1           1            198000000  0          
                    pll2_198m    0           0            198000000  0          
                 pll2_pfd1_594m  0           0            594000000  0          
                    gpu3d_shader_sel 0           0            594000000  0          
                       gpu3d_shader 0           0            594000000  0          
                 pll2_pfd0_352m  0           0            352000000  0          
     pll1_bypass_src             0           0            24000000   0          
        pll1_bypass              0           0            24000000   0          
           pll1_sys              0           0            24000000   0          
        pll1                     0           0            792000000  0          
  ckih1                          0           0            0          0          
  ckil                           0           0            32768      0

Do you happen to have a little test program which allows us to reproduce here?

I can send you 2 samples : One using libpcap and one using socket.

Using libpcap :

#include <pcap.h>
#include <qdebug.h>

#include <QThread>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include "SerialPort.h"


int oldTimestamp = 0;
int IAT = 0;


void
got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
{
    IAT = header->ts.tv_usec-oldTimestamp;

    //debug QT
    qDebug() << "IAT1 " << IAT;

    oldTimestamp = header->ts.tv_usec;
}


void * InitPcap(void *)
{
    char *dev = NULL;               /* capture device name */
    char errbuf[PCAP_ERRBUF_SIZE];	/* error buffer */
    pcap_t *handle;                 /* packet capture handle */
    bpf_u_int32 mask;               /* subnet mask */
    bpf_u_int32 net;                /* ip */

    char filter_exp[] = "port 1234";/* filter expression [3] */
    //char filter_exp[] = "tcp";/* filter expression [3] */
    struct bpf_program fp;			/* compiled filter program (expression) */
    int num_packets = -1;			/* number of packets to capture */


    dev = pcap_lookupdev(errbuf);
    if (dev == NULL) {
        qDebug() << "pcap_lookupdev failed !";
        return NULL;
    }

    /* get network number and mask associated with capture device */
    if (pcap_lookupnet(dev, &net, &mask, errbuf) == -1) {
        qDebug() << "Couldn't get netmask for device";
        //return ;
    }

    /* open capture device */
    handle = pcap_create(dev, errbuf);
    if (handle == NULL) {
        qDebug() << "Couldn't open device !";
        //return ;
    }



    // /!\ ne marche pas avec Yocto + Apalis imx6
    int toto1 = pcap_set_tstamp_type(handle, PCAP_TSTAMP_ADAPTER_UNSYNCED);
    //int toto1 = pcap_set_tstamp_type(handle, PCAP_TSTAMP_HOST_HIPREC );
    qDebug() << "pcap_set_tstamp_type (0=success): " << toto1;

    int toto2 = pcap_set_tstamp_precision(handle, PCAP_TSTAMP_PRECISION_NANO);
    qDebug() << "pcap_set_tstamp_precision (0=success): " << toto2;

    int toto3 = pcap_activate(handle);
    qDebug() << "pcap_activate (0=success): " << toto3;


    QThread::msleep(5);


    /* make sure we're capturing on an Ethernet device [2] */
    if (pcap_datalink(handle) != DLT_EN10MB) {
        qDebug() << "Not an Ethernet adapter\n";
        //return ;
    }

    /* compile the filter expression */
    if (pcap_compile(handle, &fp, filter_exp, 0, net) == -1) {
        qDebug() << "Couldn't parse filter\n";
        //return ;
    }

    /* apply the compiled filter */
    if (pcap_setfilter(handle, &fp) == -1) {
        qDebug() << "Couldn't install filter\n";
        //return ;
    }

    /* now we can set our callback function */
    pcap_loop(handle, num_packets, got_packet, NULL);

    /* cleanup */
    pcap_freecode(&fp);
    pcap_close(handle);

}

Using socket :

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/net_tstamp.h>
#include <linux/errqueue.h>

struct sockaddr_in localSock;
struct ip_mreq group;
int sd;
int datalen;
char databuf[1024];


#define Adresse_IP_Multicast    "239.0.0.1"
#define Port_Local              1234

#ifndef SIOCSHWTSTAMP
    # define SIOCSHWTSTAMP 0x89b0
#endif


 static void bail(const char *error)
 {
         printf("%s: %s\n", error, strerror(errno));
         exit(1);
 }


 static void make_address(unsigned short port, struct sockaddr_in* host_address)
 {
   bzero(host_address, sizeof(struct sockaddr_in));

   host_address->sin_family = AF_INET;
   host_address->sin_port = htons(port);
   host_address->sin_addr.s_addr = INADDR_ANY;
 }

 /* Processing */
 static void print_time(struct timespec* ts)
 {
   if( ts != NULL ) {
       printf("SW0:%d ; SW1:%d ; HW:%d \n", ts[0].tv_nsec, ts[1].tv_nsec, ts[2].tv_nsec);

   } else
   {
     printf( "no timestamp\n" );
   }
 }


 /* Given a packet, extract the timestamp(s) */
 static void handle_time(struct msghdr* msg)
 {
   struct timespec* ts = NULL;
   struct cmsghdr* cmsg;

   for( cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg,cmsg) ) {
     if( cmsg->cmsg_level != SOL_SOCKET )
       continue;

     switch( cmsg->cmsg_type ) {
     case SO_TIMESTAMPNS:
       ts = (struct timespec*) CMSG_DATA(cmsg);
       break;
     case SO_TIMESTAMPING:
       ts = (struct timespec*) CMSG_DATA(cmsg);
       break;
     default:
       /* Ignore other cmsg options */
       break;
     }
   }

   print_time(ts);
 }

/* return = 0 --> OK        */
/* return=-1 --> error !    */
int IAT_Thread()
{

/* Create a datagram socket on which to receive. */
sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sd < 0)
    {
    //close(sd);
    return -1;
    }

/* Enable SO_REUSEADDR to allow multiple instances of this */
/* application to receive copies of the multicast datagrams. */
int reuse = 1;
if(setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0)
    {
    //close(sd);
    return -1;
    }

///* Standard kernel ioctl options */
    struct ifreq hwtstamp;
    struct hwtstamp_config hwconfig, hwconfig_requested;
memset(&hwtstamp, 0, sizeof(hwtstamp));
strncpy(hwtstamp.ifr_name, "eth0", sizeof(hwtstamp.ifr_name));
hwtstamp.ifr_data = (void *)&hwconfig;
memset(&hwconfig, 0, sizeof(hwconfig));
hwconfig.tx_type = HWTSTAMP_TX_OFF;
hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
hwconfig_requested = hwconfig;
 if (ioctl(sd, SIOCSHWTSTAMP, &hwtstamp) < 0) {
         if ((errno == EINVAL || errno == ENOTSUP) &&
             hwconfig_requested.tx_type == HWTSTAMP_TX_OFF &&
             hwconfig_requested.rx_filter == HWTSTAMP_FILTER_NONE)
                printf("SIOCSHWTSTAMP: disabling hardware time stamping not possible\n");
         else
                 bail("SIOCSHWTSTAMP");
}
printf("SIOCSHWTSTAMP: tx_type %d requested, got %d; rx_filter %d requested, got %d\n",
    hwconfig_requested.tx_type, hwconfig.tx_type,
   hwconfig_requested.rx_filter, hwconfig.rx_filter);


/* Bind to the proper port number with the IP address */
/* specified as INADDR_ANY. */
memset((char *) &localSock, 0, sizeof(localSock));
localSock.sin_family = AF_INET;
localSock.sin_port = htons(Port_Local);
localSock.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(sd, (struct sockaddr*)&localSock, sizeof(localSock)))
    {
    //close(sd);
    return -1;
    }


/* Join the multicast group 239.0.0.1 on the local interface eth0   */
/* interface. Note that this IP_ADD_MEMBERSHIP option must be       */
/* called for each local interface over which the multicast         */
/* datagrams are to be received. */
group.imr_multiaddr.s_addr = inet_addr(Adresse_IP_Multicast);
///* Fetch the IP address to listen to based on interface name. */
group.imr_interface.s_addr = htonl(INADDR_ANY);

if(setsockopt(sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&group, sizeof(group)) < 0)
    {
    //close(sd);
    return -1;
    }


///* Enable timestamping in ns with HW */
int sotimestamp = SOF_TIMESTAMPING_RX_HARDWARE | SOF_TIMESTAMPING_RX_SOFTWARE
        | SOF_TIMESTAMPING_RAW_HARDWARE | SOF_TIMESTAMPING_SYS_HARDWARE | SOF_TIMESTAMPING_SOFTWARE;
int rc = setsockopt(sd, SOL_SOCKET, SO_TIMESTAMPING, &sotimestamp, sizeof(sotimestamp));
if (0 > rc)
{
    //close(sd);
    return -1;
}

int pkt_num = 0;

while(1)
{
    struct msghdr msg;
    struct iovec iov;
    struct sockaddr_in host_address;
    char buffer[2048];
    char control[1024];
    int got;

    /* recvmsg header structure */
    make_address(0, &host_address);
    iov.iov_base = buffer;
    iov.iov_len = 2048;
    msg.msg_iov = &iov;
    msg.msg_iovlen = 1;
    msg.msg_name = &host_address;
    msg.msg_namelen = sizeof(struct sockaddr_in);
    msg.msg_control = control;
    msg.msg_controllen = 1024;


    got = recvmsg(sd, &msg, 0);

    if( !got && errno == EAGAIN )
        continue;

    printf("Packet %d - %d bytes\t", pkt_num, got);
    pkt_num++;
    handle_time(&msg);


}

}



/* Esssai IAT */
void * IAT_withoutlibpcap(void *)
{
    int ret = IAT_Thread();
}

Thanks for the examples. I modified your PCAP example slightly so it does not require Qt and prints a list of supported timestamps (main.c, and the binary built in armhf pcaptest). I used libpcap and netcat from our package feeds, and used netcat with port 1234 to generate the traffic. I ran it on our latest 2.7.3 release on a Colibri iMX6S V1.0A and Apalis iMX6Q V1.1B, here are the results:

root@apalis-imx6:~# ./pcaptest 
Suported timestamp 0: host 
Suported timestamp 4: adapter_unsynced
pcap_set_tstamp_type (0=success): 0 
pcap_set_tstamp_precision (0=success): 0
apcap_activate (0=success): 0
Start PCAP loop... 
Packet, tv_sec 1504112811, tv_usec 413027246
Packet, tv_sec 1504112625, tv_usec 164986785
Packet, tv_sec 1504112811, tv_usec 638785129
Packet, tv_sec 1504112625, tv_usec 164986785
Packet, tv_sec 1504112811, tv_usec 856447400
Packet, tv_sec 1504112625, tv_usec 164986785
Packet, tv_sec 1504112812, tv_usec 42067526 
Packet, tv_sec 1504112625, tv_usec 164986785
Packet, tv_sec 1504112812, tv_usec 214668478
Packet, tv_sec 1504112625, tv_usec 164986785
Packet, tv_sec 1504112812, tv_usec 362829608
Packet, tv_sec 1504112625, tv_usec 164986785
Packet, tv_sec 1504112812, tv_usec 548785369
Packet, tv_sec 1504112625, tv_usec 164986785
Packet, tv_sec 1504112812, tv_usec 713316707
Packet, tv_sec 1504112625, tv_usec 164986785




root@colibri-imx6:~# ./pcaptest
Suported timestamp 0: host 
Suported timestamp 4: adapter_unsynced
pcap_set_tstamp_type (0=success): 0 
pcap_set_tstamp_precision (0=success): 0
pcap_activate (0=success): 0 
Start PCAP loop... 
Packet, tv_sec 1504112871, tv_usec 651917429
Packet, tv_sec 1504112871, tv_usec 653217569
Packet, tv_sec 1504112871, tv_usec 652379077
Packet, tv_sec 1504112872, tv_usec 92473173 
Packet, tv_sec 1504112872, tv_usec 93624369 
Packet, tv_sec 1504112872, tv_usec 270659591
Packet, tv_sec 1504112872, tv_usec 271879729
Packet, tv_sec 1504112872, tv_usec 457121672
Packet, tv_sec 1504112872, tv_usec 458346209
Packet, tv_sec 1504112872, tv_usec 602865076
Packet, tv_sec 1504112872, tv_usec 604080289
Packet, tv_sec 1504112872, tv_usec 742996709
Packet, tv_sec 1504112872, tv_usec 744346609 

I set tstamp type to adapter_unsynced, and it shows that the clocks are frozen at the same values (presumably one for incoming and one for outgoing packets). I will create a ticket and do further investigation.

The Ethernet on Apalis iMX6 uses RGMII (which allows gigabit Ethernet) hence the wiring is somewhat different. Now in RGMII mode there is only one SoC pad which can be used as IEEE 1588 Timestamp clock source (GPIO16). That SoC pad is by default used as SPDIF1_IN (MXM3 pin 217). See also Chapter 5.3 Ethernet in the Apalis iMX6 Datasheet.

If you don’t use that pin, you can leave it unconnected and use pinmux options to “route through” the 125MHz reference clock used by the Ethernet block:

--- a/arch/arm/boot/dts/imx6qdl-apalis.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-apalis.dtsi
@@ -688,6 +688,7 @@
                                MX6QDL_PAD_RGMII_RD2__RGMII_RD2       0x1b0b0
                                MX6QDL_PAD_RGMII_RD3__RGMII_RD3       0x1b0b0
                                MX6QDL_PAD_RGMII_RX_CTL__RGMII_RX_CTL 0x1b0b0
+                               MX6QDL_PAD_GPIO_16__ENET_REF_CLK      ((1<<30) | 0x1b0b0)
                        >;
                };
                pinctrl_enet_ctrl: enet_ctrlgrp {
@@ -871,7 +872,6 @@
        spdif {
                pinctrl_spdif: spdifgrp {
                        fsl,pins = <
-                               MX6QDL_PAD_GPIO_16__SPDIF_IN  0x1b0b0
                                MX6QDL_PAD_GPIO_17__SPDIF_OUT 0x1b0b0
                        >;
                };

Tested on a Apalis Evaluation board, removed the jumper at SPDIF_IN to disconnect the pad: With the modified device tree I get valid timestamps.

Hello,

I’s perfectly working now.
Many thanks for the help.

great job !