app/testpmd: add Rx HW timestamp
[dpdk.git] / app / test-pmd / config.c
index 90e4f19..7ff0bb2 100644 (file)
 #include <inttypes.h>
 
 #include <sys/queue.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #include <rte_common.h>
 #include <rte_byteorder.h>
@@ -603,6 +607,14 @@ port_offload_cap_display(portid_t port_id)
                        printf("off\n");
        }
 
+       if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
+               printf("HW timestamp:                  ");
+               if (dev->data->dev_conf.rxmode.hw_timestamp)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
        if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
                printf("Double VLANs insert:           ");
                if (ports[port_id].tx_ol_flags &
@@ -2510,6 +2522,30 @@ show_gro(portid_t port_id)
                printf("Port %u doesn't enable GRO.\n", port_id);
 }
 
+void
+setup_gso(const char *mode, portid_t port_id)
+{
+       if (!rte_eth_dev_is_valid_port(port_id)) {
+               printf("invalid port id %u\n", port_id);
+               return;
+       }
+       if (strcmp(mode, "on") == 0) {
+               if (test_done == 0) {
+                       printf("before enabling GSO,"
+                                       " please stop forwarding first\n");
+                       return;
+               }
+               gso_ports[port_id].enable = 1;
+       } else if (strcmp(mode, "off") == 0) {
+               if (test_done == 0) {
+                       printf("before disabling GSO,"
+                                       " please stop forwarding first\n");
+                       return;
+               }
+               gso_ports[port_id].enable = 0;
+       }
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
@@ -3351,46 +3387,43 @@ port_dcb_info_display(uint8_t port_id)
 uint8_t *
 open_ddp_package_file(const char *file_path, uint32_t *size)
 {
-       FILE *fh = fopen(file_path, "rb");
-       uint32_t pkg_size;
+       int fd = open(file_path, O_RDONLY);
+       off_t pkg_size;
        uint8_t *buf = NULL;
        int ret = 0;
+       struct stat st_buf;
 
        if (size)
                *size = 0;
 
-       if (fh == NULL) {
+       if (fd == -1) {
                printf("%s: Failed to open %s\n", __func__, file_path);
                return buf;
        }
 
-       ret = fseek(fh, 0, SEEK_END);
-       if (ret < 0) {
-               fclose(fh);
+       if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
+               close(fd);
                printf("%s: File operations failed\n", __func__);
                return buf;
        }
 
-       pkg_size = ftell(fh);
+       pkg_size = st_buf.st_size;
+       if (pkg_size < 0) {
+               close(fd);
+               printf("%s: File operations failed\n", __func__);
+               return buf;
+       }
 
        buf = (uint8_t *)malloc(pkg_size);
        if (!buf) {
-               fclose(fh);
+               close(fd);
                printf("%s: Failed to malloc memory\n", __func__);
                return buf;
        }
 
-       ret = fseek(fh, 0, SEEK_SET);
+       ret = read(fd, buf, pkg_size);
        if (ret < 0) {
-               fclose(fh);
-               printf("%s: File seek operation failed\n", __func__);
-               close_ddp_package_file(buf);
-               return NULL;
-       }
-
-       ret = fread(buf, 1, pkg_size, fh);
-       if (ret < 0) {
-               fclose(fh);
+               close(fd);
                printf("%s: File read operation failed\n", __func__);
                close_ddp_package_file(buf);
                return NULL;
@@ -3399,7 +3432,7 @@ open_ddp_package_file(const char *file_path, uint32_t *size)
        if (size)
                *size = pkg_size;
 
-       fclose(fh);
+       close(fd);
 
        return buf;
 }