[dpdk-dev] [PATCH v2] examples/exception_path: fix shift operation in lcore setup

2016-08-09 Thread Daniel Mrzyglod
The operaton may have an undefined behavior or yield to an unexpected result.
A bit shift operation has a shift amount which is too large or has a negative 
value.

As was mentioned in mailing list core list was limited to 64 so i changed 
bitmask
to core array

Coverity issue: 30688
Fixes: ea977ff1cb0b ("examples/exception_path: fix shift operation in lcore 
setup")

Signed-off-by: Daniel Mrzyglod 
---
 examples/exception_path/main.c | 74 ++
 1 file changed, 61 insertions(+), 13 deletions(-)

diff --git a/examples/exception_path/main.c b/examples/exception_path/main.c
index e5eedcc..1493338 100644
--- a/examples/exception_path/main.c
+++ b/examples/exception_path/main.c
@@ -128,11 +128,11 @@ static struct rte_mempool * pktmbuf_pool = NULL;
 /* Mask of enabled ports */
 static uint32_t ports_mask = 0;

-/* Mask of cores that read from NIC and write to tap */
-static uint64_t input_cores_mask = 0;
+/* Table of cores that read from NIC and write to tap */
+static uint8_t input_cores_table[RTE_MAX_LCORE];

-/* Mask of cores that read from tap and write to NIC */
-static uint64_t output_cores_mask = 0;
+/* Table of cores that read from tap and write to NIC */
+static uint8_t output_cores_table[RTE_MAX_LCORE];

 /* Array storing port_id that is associated with each lcore */
 static uint8_t port_ids[RTE_MAX_LCORE];
@@ -224,7 +224,7 @@ main_loop(__attribute__((unused)) void *arg)
char tap_name[IFNAMSIZ];
int tap_fd;

-   if ((1ULL << lcore_id) & input_cores_mask) {
+   if (input_cores_table[lcore_id]) {
/* Create new tap interface */
snprintf(tap_name, IFNAMSIZ, "tap_dpdk_%.2u", lcore_id);
tap_fd = tap_create(tap_name);
@@ -257,7 +257,7 @@ main_loop(__attribute__((unused)) void *arg)
}
}
}
-   else if ((1ULL << lcore_id) & output_cores_mask) {
+   else if (output_cores_table[lcore_id]) {
/* Create new tap interface */
snprintf(tap_name, IFNAMSIZ, "tap_dpdk_%.2u", lcore_id);
tap_fd = tap_create(tap_name);
@@ -341,7 +341,7 @@ setup_port_lcore_affinities(void)

/* Setup port_ids[] array, and check masks were ok */
RTE_LCORE_FOREACH(i) {
-   if (input_cores_mask & (1ULL << i)) {
+   if (input_cores_table[i]) {
/* Skip ports that are not enabled */
while ((ports_mask & (1 << rx_port)) == 0) {
rx_port++;
@@ -350,7 +350,7 @@ setup_port_lcore_affinities(void)
}

port_ids[i] = rx_port++;
-   } else if (output_cores_mask & (1ULL << (i & 0x3f))) {
+   } else if (output_cores_table[i]) {
/* Skip ports that are not enabled */
while ((ports_mask & (1 << tx_port)) == 0) {
tx_port++;
@@ -373,6 +373,54 @@ fail:
FATAL_ERROR("Invalid core/port masks specified on command line");
 }

+static int parse_hex2coretable(const char *coremask_string, uint8_t 
*core_table,
+   int core_table_size)
+{
+
+   char portmask[RTE_MAX_LCORE];
+
+   int coremask_string_len;
+   int i = 0, j = 0;
+   uint64_t num;
+   char tmp_char;
+   char *end = NULL;
+
+   coremask_string_len = strlen(coremask_string);
+   if ((coremask_string_len > (RTE_MAX_LCORE / 4) + 2)
+   || (core_table_size > RTE_MAX_LCORE) || 
(coremask_string == NULL)
+   || (core_table == NULL))
+   return -1;
+
+   memset(portmask, '\0', sizeof(portmask));
+   memset(core_table, '\0', sizeof(uint8_t) * core_table_size);
+   strncpy(portmask, coremask_string, coremask_string_len);
+
+   if (coremask_string[i] == '0') {
+   ++i;
+   if (coremask_string[i] == 'X' || coremask_string[i] == 'x')
+   ++i;
+   }
+
+   j = 0;
+   while (coremask_string_len - i > 0) {
+
+   tmp_char = portmask[coremask_string_len - 1];
+   end = NULL;
+   num = strtoull(_char, , 16);
+   if ((end == _char))
+   return -1;
+
+   for (int z = 0; z < 4; z++)
+   if (((num) & (1 << (z))) != 0)
+   core_table[z + j * 4] = 1;
+
+   coremask_string_len--;
+   j++;
+   }
+
+   return 0;
+}
+
 /* Parse the arguments given in the command line of the application */
 static void
 parse_args(int argc, char **argv)
@@ -382,15 +430,15 @@ parse_args(int argc, char **argv)

/* Disable printing messages within getopt() */
opterr = 0;
-
+   int reti = 0, reto =

[dpdk-dev] [PATCH] examples/exception_path: fix shift operation in lcore setup

2016-08-03 Thread Daniel Mrzyglod
The operaton may have an undefined behavior or yield to an unexpected result.
A bit shift operation has a shift amount which is too large or has a negative 
value.

Coverity issue: 30688
Fixes: ea977ff1cb0b ("examples/exception_path: fix shift operation in lcore 
setup")
The previous patch forget to fix values also for input_cores_mask

Signed-off-by: Daniel Mrzyglod 
---
 examples/exception_path/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/exception_path/main.c b/examples/exception_path/main.c
index e5eedcc..88e7708 100644
--- a/examples/exception_path/main.c
+++ b/examples/exception_path/main.c
@@ -341,7 +341,7 @@ setup_port_lcore_affinities(void)

/* Setup port_ids[] array, and check masks were ok */
RTE_LCORE_FOREACH(i) {
-   if (input_cores_mask & (1ULL << i)) {
+   if (input_cores_mask & (1ULL << (i & 0x3f))) {
/* Skip ports that are not enabled */
while ((ports_mask & (1 << rx_port)) == 0) {
rx_port++;
-- 
2.7.4



[dpdk-dev] [PATCH v4] eal/linuxapp: fix resource leak

2016-07-06 Thread Daniel Mrzyglod
Current code does not munmap 'hugepage' mapping (hugepage info file) on
function exit, leaking resources.

Coverity issue: 97920
Fixes: b6a468ad41d5 ("memory: add --socket-mem option")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c 
b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5578c25..b663244 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1136,7 +1136,7 @@ int
 rte_eal_hugepage_init(void)
 {
struct rte_mem_config *mcfg;
-   struct hugepage_file *hugepage, *tmp_hp = NULL;
+   struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];

uint64_t memory[RTE_MAX_NUMA_NODES];
@@ -1479,14 +1479,19 @@ rte_eal_hugepage_init(void)
"of memory.\n",
i, nr_hugefiles, RTE_STR(CONFIG_RTE_MAX_MEMSEG),
RTE_MAX_MEMSEG);
-   return -ENOMEM;
+   goto fail;
}

+   munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
+
return 0;

 fail:
huge_recover_sigbus();
free(tmp_hp);
+   if (hugepage != NULL)
+   munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
+
return -1;
 }

-- 
2.7.4



[dpdk-dev] [PATCH v3] eal/linuxapp: fix resource leak

2016-06-22 Thread Daniel Mrzyglod
This patch fix all cases to do proper handle all munmap if pointer
of hugepage is not NULL which prohibits resource leak.

Coverity issue: 97920
Fixes: b6a468ad41d5 ("memory: add --socket-mem option")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c 
b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 9251a5b..9b0d39a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1051,7 +1051,7 @@ int
 rte_eal_hugepage_init(void)
 {
struct rte_mem_config *mcfg;
-   struct hugepage_file *hugepage, *tmp_hp = NULL;
+   struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];

uint64_t memory[RTE_MAX_NUMA_NODES];
@@ -1367,13 +1367,15 @@ rte_eal_hugepage_init(void)
"of memory.\n",
i, nr_hugefiles, RTE_STR(CONFIG_RTE_MAX_MEMSEG),
RTE_MAX_MEMSEG);
-   return -ENOMEM;
+   goto fail;
}

return 0;

 fail:
free(tmp_hp);
+   if (hugepage != NULL)
+   munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
return -1;
 }

-- 
2.7.4



[dpdk-dev] [PATCH v2] examples/ip_pipeline: fix build error for gcc 4.8

2016-06-21 Thread Daniel Mrzyglod
This patch fixes a maybe-uninitialized warning when compiling DPDK with GCC 4.8

examples/ip_pipeline/pipeline/pipeline_common_fe.c: In function 
'app_pipeline_track_pktq_out_to_link':
examples/ip_pipeline/pipeline/pipeline_common_fe.c:66:31: error:
'reader' may be used uninitialized in this function 
[-Werror=maybe-uninitialized]

   struct app_pktq_out_params *pktq_out =

Fixes: 760064838ec0 ("examples/ip_pipeline: link routing output ports to 
devices")

Signed-off-by: Daniel Mrzyglod 
Acked-by: Cristian Dumitrescu 
---
 examples/ip_pipeline/app.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/examples/ip_pipeline/app.h b/examples/ip_pipeline/app.h
index 7611341..242dae8 100644
--- a/examples/ip_pipeline/app.h
+++ b/examples/ip_pipeline/app.h
@@ -667,11 +667,11 @@ app_swq_get_reader(struct app_params *app,
struct app_pktq_swq_params *swq,
uint32_t *pktq_in_id)
 {
-   struct app_pipeline_params *reader;
+   struct app_pipeline_params *reader = NULL;
uint32_t pos = swq - app->swq_params;
uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
RTE_DIM(app->pipeline_params));
-   uint32_t n_readers = 0, id, i;
+   uint32_t n_readers = 0, id = 0, i;

for (i = 0; i < n_pipelines; i++) {
struct app_pipeline_params *p = >pipeline_params[i];
@@ -727,11 +727,11 @@ app_tm_get_reader(struct app_params *app,
struct app_pktq_tm_params *tm,
uint32_t *pktq_in_id)
 {
-   struct app_pipeline_params *reader;
+   struct app_pipeline_params *reader = NULL;
uint32_t pos = tm - app->tm_params;
uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
RTE_DIM(app->pipeline_params));
-   uint32_t n_readers = 0, id, i;
+   uint32_t n_readers = 0, id = 0, i;

for (i = 0; i < n_pipelines; i++) {
struct app_pipeline_params *p = >pipeline_params[i];
-- 
2.5.5



[dpdk-dev] [PATCH] examples/ip_pipeline: fix build error for gcc 4.8

2016-06-09 Thread Daniel Mrzyglod
This patch fixes a maybe-uninitialized warning when compiling DPDK with GCC 4.8

examples/ip_pipeline/pipeline/pipeline_common_fe.c: In function 
'app_pipeline_track_pktq_out_to_link':
examples/ip_pipeline/pipeline/pipeline_common_fe.c:66:31: error:
'reader' may be used uninitialized in this function 
[-Werror=maybe-uninitialized]

   struct app_pktq_out_params *pktq_out =

Fixes: 760064838ec0 ("examples/ip_pipeline: link routing output ports to 
devices")

Signed-off-by: Daniel Mrzyglod 
---
 examples/ip_pipeline/app.h |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/examples/ip_pipeline/app.h b/examples/ip_pipeline/app.h
index 848244a..592c17c 100644
--- a/examples/ip_pipeline/app.h
+++ b/examples/ip_pipeline/app.h
@@ -667,7 +667,7 @@ app_swq_get_reader(struct app_params *app,
struct app_pktq_swq_params *swq,
uint32_t *pktq_in_id)
 {
-   struct app_pipeline_params *reader;
+   struct app_pipeline_params *reader = NULL;
uint32_t pos = swq - app->swq_params;
uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
RTE_DIM(app->pipeline_params));
@@ -727,7 +727,7 @@ app_tm_get_reader(struct app_params *app,
struct app_pktq_tm_params *tm,
uint32_t *pktq_in_id)
 {
-   struct app_pipeline_params *reader;
+   struct app_pipeline_params *reader = NULL;
uint32_t pos = tm - app->tm_params;
uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
RTE_DIM(app->pipeline_params));
-- 
1.7.9.5



[dpdk-dev] [PATCH] ixgbe: fix unused value

2016-06-02 Thread Daniel Mrzyglod
An assigned value that is never used may represent unnecessary computation,
an incorrect algorithm, or possibly the need for cleanup or refactoring.

In reassemble_packets: A value assigned to a variable is never used.

Fixes: cf4b4708a88a ("ixgbe: improve slow-path perf with vector scattered Rx")
Coverity ID 13335

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/ixgbe/ixgbe_rxtx_vec.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ixgbe/ixgbe_rxtx_vec.c 
b/drivers/net/ixgbe/ixgbe_rxtx_vec.c
index e97ea82..61c7aad 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx_vec.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx_vec.c
@@ -458,7 +458,6 @@ reassemble_packets(struct ixgbe_rx_queue *rxq, struct 
rte_mbuf **rx_bufs,
end->data_len);
secondlast->next = NULL;
rte_pktmbuf_free_seg(end);
-   end = secondlast;
}
pkts[pkt_idx++] = start;
start = end = NULL;
-- 
2.5.5



[dpdk-dev] [PATCH] i40e: fix unchecked return value

2016-05-24 Thread Daniel Mrzyglod
Calling i40e_switch_rx_queue without checking return value.
Fixed by add warning log information if return failed.

Fixes: 71d35259ff67 ("i40e: tear down flow director")
Coverity ID 13198

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/i40e/i40e_fdir.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
index 8aa41e5..ce6d916 100644
--- a/drivers/net/i40e/i40e_fdir.c
+++ b/drivers/net/i40e/i40e_fdir.c
@@ -288,12 +288,15 @@ i40e_fdir_teardown(struct i40e_pf *pf)
 {
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
struct i40e_vsi *vsi;
+   int err = I40E_SUCCESS;

vsi = pf->fdir.fdir_vsi;
if (!vsi)
return;
i40e_switch_tx_queue(hw, vsi->base_queue, FALSE);
-   i40e_switch_rx_queue(hw, vsi->base_queue, FALSE);
+   err = i40e_switch_rx_queue(hw, vsi->base_queue, FALSE);
+   if (err)
+   PMD_DRV_LOG(WARNING, "Failed to do FDIR RX switch off.");
i40e_dev_rx_queue_release(pf->fdir.rxq);
pf->fdir.rxq = NULL;
i40e_dev_tx_queue_release(pf->fdir.txq);
-- 
2.5.5



[dpdk-dev] [PATCH v2] eal/linuxapp: fix resource leak

2016-05-12 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 97920

munmap structure of hugepage

leaked_storage: Variable hugepage going out of scope leaks the storage
it points to.

The system resource will not be reclaimed and reused, reducing the future
availability of the resource.

In rte_eal_hugepage_init: Leak of memory or pointers to system resources

Fixes: b6a468ad41d5 ("memory: add --socket-mem option")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c 
b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5b9132c..9fd0d8d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1051,7 +1051,7 @@ int
 rte_eal_hugepage_init(void)
 {
struct rte_mem_config *mcfg;
-   struct hugepage_file *hugepage, *tmp_hp = NULL;
+   struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];

uint64_t memory[RTE_MAX_NUMA_NODES];
@@ -1367,13 +1367,15 @@ rte_eal_hugepage_init(void)
"of memory.\n",
i, nr_hugefiles, RTE_STR(CONFIG_RTE_MAX_MEMSEG),
RTE_MAX_MEMSEG);
-   return -ENOMEM;
+   goto fail;
}

return 0;

 fail:
free(tmp_hp);
+   if (hugepage != NULL)
+   munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
return -1;
 }

-- 
2.5.5



[dpdk-dev] [PATCH] eal/linuxapp: fix resource leak

2016-05-11 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 97920

munmap structure of hugepage

leaked_storage: Variable hugepage going out of scope leaks the storage
it points to.

The system resource will not be reclaimed and reused, reducing the future
availability of the resource.

In rte_eal_hugepage_init: Leak of memory or pointers to system resources

Fixes: b6a468ad41d5 ("memory: add --socket-mem option")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c 
b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5b9132c..cd40cc9 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1051,7 +1051,7 @@ int
 rte_eal_hugepage_init(void)
 {
struct rte_mem_config *mcfg;
-   struct hugepage_file *hugepage, *tmp_hp = NULL;
+   struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];

uint64_t memory[RTE_MAX_NUMA_NODES];
@@ -1374,6 +1374,8 @@ rte_eal_hugepage_init(void)

 fail:
free(tmp_hp);
+   if (hugepage != NULL)
+   munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
return -1;
 }

-- 
2.5.5



[dpdk-dev] [PATCH] vhost: fix buffer not null terminated

2016-05-10 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 124556

If the buffer is treated as a null terminated string in later operations,
a buffer overflow or over-read may occur.

In vhost_set_ifname: The string buffer may not have a null terminator if
the source string's length is equal to the buffer size

Fixes: 54292e9520e0 ("vhost: support ifname for vhost-user")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_vhost/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index d870ad9..f4695af 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -320,6 +320,7 @@ vhost_set_ifname(struct vhost_device_ctx ctx,
sizeof(dev->ifname) : if_len;

strncpy(dev->ifname, if_name, len);
+   dev->ifname[sizeof(dev->ifname) - 1] = '\0';
 }


-- 
2.5.5



[dpdk-dev] [PATCH v2] examples/vm_power_manager: buffer not null terminated

2016-05-10 Thread Daniel Mrzyglod
CID30691:
If the buffer is treated as a null terminated string in later operations,
a buffer overflow or over-read may occur.

In add_vm: The string buffer may not have a null terminator if the source
string's length is equal to the buffer size

Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host")

Signed-off-by: Daniel Mrzyglod 
---
 examples/vm_power_manager/channel_manager.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/examples/vm_power_manager/channel_manager.c 
b/examples/vm_power_manager/channel_manager.c
index 22c2ddd..e068ae2 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -667,6 +667,7 @@ add_vm(const char *vm_name)
return -1;
}
strncpy(new_domain->name, vm_name, sizeof(new_domain->name));
+   new_domain->name[sizeof(new_domain->name) - 1] = '\0';
new_domain->channel_mask = 0;
new_domain->num_channels = 0;

-- 
2.5.5



[dpdk-dev] [PATCH] sched: fix useless call

2016-05-10 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 13338

A function call that seems to have an intended effect has no actual effect
on the logic of the program.

In rte_sched_port_free: A function is called that is only useful for its
return value, and this value is ignored.

Fixes: de3cfa2c9823 ("sched: initial import")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_sched/rte_sched.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c
index 1609ea8..9b962a6 100644
--- a/lib/librte_sched/rte_sched.c
+++ b/lib/librte_sched/rte_sched.c
@@ -749,7 +749,6 @@ rte_sched_port_free(struct rte_sched_port *port)
rte_pktmbuf_free(mbufs[i]);
}

-   rte_bitmap_free(port->bmp);
rte_free(port);
 }

-- 
2.5.5



[dpdk-dev] [PATCH] examples/kni: unchecked return value

2016-05-09 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 30692

If the function returns an error value, the error value may be mistaken for
a normal value.

In kni_free_kni: Value returned from a function is not checked for errors
before being used

Fixes: b475eb0bc400 ("examples/kni: new parameters")

Signed-off-by: Daniel Mrzyglod 
---
 examples/kni/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/kni/main.c b/examples/kni/main.c
index a5297f2..dcecd09 100644
--- a/examples/kni/main.c
+++ b/examples/kni/main.c
@@ -831,7 +831,8 @@ kni_free_kni(uint8_t port_id)
return -1;

for (i = 0; i < p[port_id]->nb_kni; i++) {
-   rte_kni_release(p[port_id]->kni[i]);
+   if (rte_kni_release(p[port_id]->kni[i]))
+   printf("fail to release kni\n");
p[port_id]->kni[i] = NULL;
}
rte_eth_dev_stop(port_id);
-- 
2.5.5



[dpdk-dev] [PATCH] examples/ip_pipline: fix memory initialization in firewall bulk functions

2016-05-06 Thread Daniel Mrzyglod
bulk functions expect that all memory is set with zeros

Fixes: 67ebdbef0c31 ("examples/ip_pipeline: add bulk update of firewall rules")

Signed-off-by: Daniel Mrzyglod 
---
 examples/ip_pipeline/pipeline/pipeline_firewall_be.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/examples/ip_pipeline/pipeline/pipeline_firewall_be.c 
b/examples/ip_pipeline/pipeline/pipeline_firewall_be.c
index e7a8a4c..4edca66 100644
--- a/examples/ip_pipeline/pipeline/pipeline_firewall_be.c
+++ b/examples/ip_pipeline/pipeline/pipeline_firewall_be.c
@@ -732,7 +732,7 @@ pipeline_firewall_msg_req_add_bulk_handler(struct pipeline 
*p, void *msg)
n_keys = req->n_keys;

for (i = 0; i < n_keys; i++) {
-   entries[i] = rte_malloc(NULL,
+   entries[i] = rte_zmalloc(NULL,
sizeof(struct firewall_table_entry),
RTE_CACHE_LINE_SIZE);
if (entries[i] == NULL) {
@@ -740,7 +740,7 @@ pipeline_firewall_msg_req_add_bulk_handler(struct pipeline 
*p, void *msg)
return rsp;
}

-   params[i] = rte_malloc(NULL,
+   params[i] = rte_zmalloc(NULL,
sizeof(struct rte_table_acl_rule_add_params),
RTE_CACHE_LINE_SIZE);
if (params[i] == NULL) {
@@ -814,7 +814,7 @@ pipeline_firewall_msg_req_del_bulk_handler(struct pipeline 
*p, void *msg)
n_keys = req->n_keys;

for (i = 0; i < n_keys; i++) {
-   params[i] = rte_malloc(NULL,
+   params[i] = rte_zmalloc(NULL,
sizeof(struct rte_table_acl_rule_delete_params),
RTE_CACHE_LINE_SIZE);
if (params[i] == NULL) {
-- 
2.5.5



[dpdk-dev] [PATCH] eal/linux: fix undefined allocation of 0 bytes (CERT MEM04-C; CWE-131)

2016-04-27 Thread Daniel Mrzyglod
Fix issue reported by clang scan-build

there is a chance that nr_hugepages will be 0 if conditions for loop
for (i = 0; i < (int) internal_config.num_hugepage_sizes; i++)
will be unmeet.

Fixes: b6a468ad41d5 ("memory: add --socket-mem option")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c 
b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5b9132c..e94538e 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1114,6 +1114,8 @@ rte_eal_hugepage_init(void)
 * processing done on these pages, shared memory will be created
 * at a later stage.
 */
+   if (nr_hugepages == 0)
+   goto fail;
tmp_hp = malloc(nr_hugepages * sizeof(struct hugepage_file));
if (tmp_hp == NULL)
goto fail;
-- 
2.5.5



[dpdk-dev] [PATCH] lpm6: fix assigned value is garbage or undefined

2016-04-27 Thread Daniel Mrzyglod
Fix issue reported by clang scan-build

Value of pointer tbl_next was uninitialized. When function lookup_step()
take else branch it may provide garbage into tbl = tbl_next;

Fixes: 5c510e13a9cb ("lpm: add IPv6 support")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_lpm/rte_lpm6.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/librte_lpm/rte_lpm6.c b/lib/librte_lpm/rte_lpm6.c
index ba4353c..32fdba0 100644
--- a/lib/librte_lpm/rte_lpm6.c
+++ b/lib/librte_lpm/rte_lpm6.c
@@ -601,7 +601,7 @@ int
 rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip, uint8_t *next_hop)
 {
const struct rte_lpm6_tbl_entry *tbl;
-   const struct rte_lpm6_tbl_entry *tbl_next;
+   const struct rte_lpm6_tbl_entry *tbl_next = NULL;
int status;
uint8_t first_byte;
uint32_t tbl24_index;
@@ -636,7 +636,7 @@ rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
 {
unsigned i;
const struct rte_lpm6_tbl_entry *tbl;
-   const struct rte_lpm6_tbl_entry *tbl_next;
+   const struct rte_lpm6_tbl_entry *tbl_next = NULL;
uint32_t tbl24_index;
uint8_t first_byte, next_hop;
int status;
-- 
2.5.5



[dpdk-dev] [PATCH] app/test_acl: fix division by float zero

2016-04-22 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 13240

This could cause an immediate crash or incorrect computation.

In search_ip5tuples: An expression which may be zero is used
as a divisor in floating-point arithmetic.

divide_by_zero: In expression (long double)tm / pkt,
division by expression pkt which may be zero has undefined behavior.

Fixes: 26c057ab6c45 ("acl: new test-acl application")

Signed-off-by: Daniel Mrzyglod 
---
 app/test-acl/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/test-acl/main.c b/app/test-acl/main.c
index 0b0c093..d366981 100644
--- a/app/test-acl/main.c
+++ b/app/test-acl/main.c
@@ -901,7 +901,7 @@ search_ip5tuples(__attribute__((unused)) void *arg)
"%s  @lcore %u: %" PRIu32 " iterations, %" PRIu64 " pkts, %"
PRIu32 " categories, %" PRIu64 " cycles, %#Lf cycles/pkt\n",
__func__, lcore, i, pkt, config.run_categories,
-   tm, (long double)tm / pkt);
+   tm, (pkt == 0) ? 0 : (long double)tm / pkt);

return 0;
 }
-- 
2.5.5



[dpdk-dev] [PATCH v2] eal: fix unchecked return value from library

2016-04-22 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 13194

The function returns a value that indicates an error condition. If this
 is not checked, the error condition may not be handled correctly.

In pci_vfio_mp_sync_thread: Value returned from a library function is not
checked for errors before being used. This value may indicate an error 
condition.

Fixes: 2f4adfad0a69 ("vfio: add multiprocess support")

v2:
Changed ERR to WARNING because it has no real impact on the application
usability

Signed-off-by: Daniel Mrzyglod 
Acked-by: Anatoly Burakov 
---
 lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c 
b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
index d9188fd..26d966e 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
@@ -287,7 +287,10 @@ pci_vfio_mp_sync_thread(void __rte_unused * arg)
struct linger l;
l.l_onoff = 1;
l.l_linger = 60;
-   setsockopt(conn_sock, SOL_SOCKET, SO_LINGER, , sizeof(l));
+
+   if (setsockopt(conn_sock, SOL_SOCKET, SO_LINGER, , sizeof(l)) 
< 0)
+   RTE_LOG(WARNING, EAL, "Cannot set SO_LINGER option "
+   "on listen socket (%s)\n", 
strerror(errno));

ret = vfio_mp_sync_receive_request(conn_sock);

-- 
2.5.5



[dpdk-dev] [PATCH] eal: fix unchecked return value from library

2016-04-21 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 13194

The function returns a value that indicates an error condition. If this
 is not checked, the error condition may not be handled correctly.

In pci_vfio_mp_sync_thread: Value returned from a library function is not
checked for errors before being used. This value may indicate an error 
condition.

Fixes: 2f4adfad0a69 ("vfio: add multiprocess support")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c 
b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
index d9188fd..2b136fc 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
@@ -287,7 +287,10 @@ pci_vfio_mp_sync_thread(void __rte_unused * arg)
struct linger l;
l.l_onoff = 1;
l.l_linger = 60;
-   setsockopt(conn_sock, SOL_SOCKET, SO_LINGER, , sizeof(l));
+
+   if (setsockopt(conn_sock, SOL_SOCKET, SO_LINGER, , sizeof(l)) 
< 0)
+   RTE_LOG(ERR, EAL, "Cannot set SO_LINGER option "
+   "on listen socket (%s)\n", 
strerror(errno));

ret = vfio_mp_sync_receive_request(conn_sock);

-- 
2.5.5



[dpdk-dev] [PATCH] power: fix argument cannot be negative

2016-04-20 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 13269 & 13266:

Function strerror(errno) has built strings only for non-negative errno values.
for negative values of errno it describe error as "Unknown error -errno"
to be more descriptive i put string "channel not found" taken from header.

The negative argument will be interpreted as a very large unsigned value.

In send_msg: Negative value used as argument to a function expecting
a positive value (for example, size of buffer or allocation)

Fixes: 445c6528b55f ("power: common interface for guest and host")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_power/guest_channel.c| 3 ++-
 lib/librte_power/rte_power_kvm_vm.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/librte_power/guest_channel.c b/lib/librte_power/guest_channel.c
index d6b6d0a..c0d23d8 100644
--- a/lib/librte_power/guest_channel.c
+++ b/lib/librte_power/guest_channel.c
@@ -104,7 +104,8 @@ guest_channel_host_connect(const char *path, unsigned 
lcore_id)
ret = guest_channel_send_msg(, lcore_id);
if (ret != 0) {
RTE_LOG(ERR, GUEST_CHANNEL, "Error on channel '%s' 
communications "
-   "test: %s\n", fd_path, strerror(ret));
+   "test: %s\n", fd_path, ret > 0 ? strerror(ret) :
+   "channel not connected");
goto error;
}
RTE_LOG(INFO, GUEST_CHANNEL, "Channel '%s' is now connected\n", 
fd_path);
diff --git a/lib/librte_power/rte_power_kvm_vm.c 
b/lib/librte_power/rte_power_kvm_vm.c
index 7bb2774..5d53e6a 100644
--- a/lib/librte_power/rte_power_kvm_vm.c
+++ b/lib/librte_power/rte_power_kvm_vm.c
@@ -106,7 +106,8 @@ send_msg(unsigned lcore_id, uint32_t scale_direction)
ret = guest_channel_send_msg([lcore_id], lcore_id);
if (ret == 0)
return 1;
-   RTE_LOG(DEBUG, POWER, "Error sending message: %s\n", strerror(ret));
+   RTE_LOG(DEBUG, POWER, "Error sending message: %s\n", ret > 0 ? 
strerror(ret)
+   : "channel not connected");
return -1;
 }

-- 
2.5.5



[dpdk-dev] [PATCH v2] i40e: dereference before null check

2016-04-18 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 13302:
There may be a null pointer dereference, or else the comparison against
null is unnecessary.

In i40evf_config_vlan_pvid: All paths that lead to this null pointer
comparison already dereference the pointer earlier

Fixes: 2b12431b5369 ("i40e: add vlan stripping and insertion to VF")

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/i40e/i40e_ethdev_vf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/i40e/i40e_ethdev_vf.c 
b/drivers/net/i40e/i40e_ethdev_vf.c
index 2bce69b..2d75b96 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -538,7 +538,7 @@ i40evf_config_vlan_pvid(struct rte_eth_dev *dev,
struct vf_cmd_info args;
struct i40e_virtchnl_pvid_info tpid_info;

-   if (dev == NULL || info == NULL) {
+   if (info == NULL) {
PMD_DRV_LOG(ERR, "invalid parameters");
return I40E_ERR_PARAM;
}
-- 
2.5.5



[dpdk-dev] [PATCH] i40e: dereference before null check

2016-04-18 Thread Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 13302:
There may be a null pointer dereference, or else the comparison against
null is unnecessary.

In i40evf_config_vlan_pvid: All paths that lead to this null pointer
comparison already dereference the pointer earlier

Fixes: 2b12431b5369 ("i40e: add vlan stripping and insertion to VF")

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/i40e/i40e_ethdev_vf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/i40e/i40e_ethdev_vf.c 
b/drivers/net/i40e/i40e_ethdev_vf.c
index 2bce69b..0d69322 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -533,7 +533,7 @@ static int
 i40evf_config_vlan_pvid(struct rte_eth_dev *dev,
struct i40e_vsi_vlan_pvid_info *info)
 {
-   struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+   struct i40e_vf *vf = NULL;
int err;
struct vf_cmd_info args;
struct i40e_virtchnl_pvid_info tpid_info;
@@ -542,6 +542,7 @@ i40evf_config_vlan_pvid(struct rte_eth_dev *dev,
PMD_DRV_LOG(ERR, "invalid parameters");
return I40E_ERR_PARAM;
}
+   vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);

memset(_info, 0, sizeof(tpid_info));
tpid_info.vsi_id = vf->vsi_res->vsi_id;
-- 
2.5.5



[dpdk-dev] [PATCH] examples/exception_path: bad shift operation in setup_port_lcore_affinities

2016-04-15 Thread Daniel Mrzyglod
CID: #30688
The operaton may have an undefined behavior or yield to an unexpected result.

In setup_port_lcore_affinities: A bit shift operation has a shift amount which
is too large or has a negative value.

Fixes: af75078fece3 ("first public release")

Signed-off-by: Daniel Mrzyglod 
---
 examples/exception_path/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/exception_path/main.c b/examples/exception_path/main.c
index bec9804..c14a933 100644
--- a/examples/exception_path/main.c
+++ b/examples/exception_path/main.c
@@ -351,7 +351,7 @@ setup_port_lcore_affinities(void)

port_ids[i] = rx_port++;
}
-   else if (output_cores_mask & (1ULL << i)) {
+   else if (output_cores_mask & (1ULL << (i & 0x3f))) {
/* Skip ports that are not enabled */
while ((ports_mask & (1 << tx_port)) == 0) {
tx_port++;
-- 
2.5.5



[dpdk-dev] [PATCH] cmdline: fix unchecked return value

2016-04-14 Thread Daniel Mrzyglod
This patch is for checking if error values occurs.
fix for coverity errors #13209 & #13195

If the function returns an error value, the error value may be mistaken
for a normal value.

In rdline_char_in: Value returned from a function is not checked for errors
before being used

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_cmdline/cmdline_rdline.c | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/librte_cmdline/cmdline_rdline.c 
b/lib/librte_cmdline/cmdline_rdline.c
index 1ef2258..e75a556 100644
--- a/lib/librte_cmdline/cmdline_rdline.c
+++ b/lib/librte_cmdline/cmdline_rdline.c
@@ -377,7 +377,10 @@ rdline_char_in(struct rdline *rdl, char c)
case CMDLINE_KEY_CTRL_K:
cirbuf_get_buf_head(>right, rdl->kill_buf, 
RDLINE_BUF_SIZE);
rdl->kill_size = CIRBUF_GET_LEN(>right);
-   cirbuf_del_buf_head(>right, rdl->kill_size);
+
+   if (cirbuf_del_buf_head(>right, rdl->kill_size) < 
0)
+   return -EINVAL;
+
rdline_puts(rdl, vt100_clear_right);
break;

@@ -496,7 +499,10 @@ rdline_char_in(struct rdline *rdl, char c)
vt100_init(>vt100);
cirbuf_init(>left, rdl->left_buf, 0, 
RDLINE_BUF_SIZE);
cirbuf_init(>right, rdl->right_buf, 0, 
RDLINE_BUF_SIZE);
-   cirbuf_add_buf_tail(>left, buf, strnlen(buf, 
RDLINE_BUF_SIZE));
+
+   if (cirbuf_add_buf_tail(>left, buf, strnlen(buf, 
RDLINE_BUF_SIZE)) < 0)
+   return -EINVAL;
+
rdline_redisplay(rdl);
break;

@@ -513,7 +519,10 @@ rdline_char_in(struct rdline *rdl, char c)
vt100_init(>vt100);
cirbuf_init(>left, rdl->left_buf, 0, 
RDLINE_BUF_SIZE);
cirbuf_init(>right, rdl->right_buf, 0, 
RDLINE_BUF_SIZE);
-   cirbuf_add_buf_tail(>left, buf, strnlen(buf, 
RDLINE_BUF_SIZE));
+
+   if (cirbuf_add_buf_tail(>left, buf, strnlen(buf, 
RDLINE_BUF_SIZE)) <  0)
+   return -EINVAL;
+
rdline_redisplay(rdl);

break;
@@ -640,7 +649,9 @@ rdline_add_history(struct rdline * rdl, const char * buf)
rdline_remove_old_history_item(rdl);
}

-   cirbuf_add_buf_tail(>history, buf, len);
+   if (cirbuf_add_buf_tail(>history, buf, len) < 0)
+   return -EINVAL;
+
cirbuf_add_tail(>history, 0);

return 0;
-- 
2.5.5



[dpdk-dev] [PATCH] examples/vm_power_manager: buffer not null terminated

2016-04-12 Thread Daniel Mrzyglod
CID30691:
If the buffer is treated as a null terminated string in later operations,
a buffer overflow or over-read may occur.

In add_vm: The string buffer may not have a null terminator if the source
string's length is equal to the buffer size

Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host")

Signed-off-by: Daniel Mrzyglod 
---
 examples/vm_power_manager/channel_manager.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/vm_power_manager/channel_manager.c 
b/examples/vm_power_manager/channel_manager.c
index 22c2ddd..b9265ce 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -666,7 +666,8 @@ add_vm(const char *vm_name)
rte_free(new_domain);
return -1;
}
-   strncpy(new_domain->name, vm_name, sizeof(new_domain->name));
+   strncat(new_domain->name, vm_name, sizeof(new_domain->name) -
+   strlen(new_domain->name) - 1);
new_domain->channel_mask = 0;
new_domain->num_channels = 0;

-- 
2.5.5



[dpdk-dev] [PATCH] eal: fix resource leak

2016-04-11 Thread Daniel Mrzyglod
CID 13289 (#1-2 of 2): Resource leak (RESOURCE_LEAK):
The system resource will not be reclaimed and reused, reducing the future 
availability of the resource.
In pci_vfio_get_group_fd: Leak of memory or pointers to system resources

Fixes: ff0b67d1c868 ("vfio: DMA mapping")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c 
b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index fdfdeb4..10266f8 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -535,6 +535,7 @@ pci_vfio_get_group_fd(int iommu_group_no)
/* if the fd is valid, create a new group for it */
if (vfio_cfg.vfio_group_idx == VFIO_MAX_GROUPS) {
RTE_LOG(ERR, EAL, "Maximum number of VFIO groups 
reached!\n");
+   close(vfio_group_fd);
return -1;
}
vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = 
iommu_group_no;
-- 
2.5.5



[dpdk-dev] [PATCH v2] examples: fix build errors for icc

2016-04-04 Thread Daniel Mrzyglod
error: loops in this subroutine are not good vectorization candidates
 (try compiling with O3 and/or IPO).

this error occurs in icc 15.0.1

Solution to disable this diagnostic message
https://software.intel.com/en-us/forums/intel-c-compiler/topic/537688

Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application")
Fixes: 8cc72f2814dd ("examples/vmdq_dcb: support X710")

Signed-off-by: Daniel Mrzyglod 
---
 examples/ipsec-secgw/Makefile | 4 
 examples/vmdq_dcb/Makefile| 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/examples/ipsec-secgw/Makefile b/examples/ipsec-secgw/Makefile
index da39e49..f9b59c2 100644
--- a/examples/ipsec-secgw/Makefile
+++ b/examples/ipsec-secgw/Makefile
@@ -42,6 +42,10 @@ APP = ipsec-secgw

 CFLAGS += -O3 -gdwarf-2
 CFLAGS += $(WERROR_FLAGS)
+ifeq ($(CONFIG_RTE_TOOLCHAIN_ICC),y)
+CFLAGS_sa.o += -diag-disable=vec
+endif
+

 VPATH += $(SRCDIR)/librte_ipsec

diff --git a/examples/vmdq_dcb/Makefile b/examples/vmdq_dcb/Makefile
index 10a9a9a..8c51131 100644
--- a/examples/vmdq_dcb/Makefile
+++ b/examples/vmdq_dcb/Makefile
@@ -51,7 +51,9 @@ CFLAGS += $(WERROR_FLAGS)
 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
 CFLAGS_main.o += -Wno-return-type
 endif
-
+ifeq ($(CONFIG_RTE_TOOLCHAIN_ICC),y)
+CFLAGS_main.o += -diag-disable=vec
+endif
 EXTRA_CFLAGS += -O3 -g

 include $(RTE_SDK)/mk/rte.extapp.mk
-- 
2.5.5



[dpdk-dev] [PATCH 2/2] examples: fix build errors for icc

2016-04-04 Thread Daniel Mrzyglod
error: loops in this subroutine are not good vectorization candidates
 (try compiling with O3 and/or IPO).

Solution to disable this diagnostic message
https://software.intel.com/en-us/forums/intel-c-compiler/topic/537688

Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application")
Fixes: 8cc72f2814dd ("examples/vmdq_dcb: support X710")

Signed-off-by: Daniel Mrzyglod 
---
 examples/ipsec-secgw/Makefile | 4 
 examples/vmdq_dcb/Makefile| 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/examples/ipsec-secgw/Makefile b/examples/ipsec-secgw/Makefile
index da39e49..f9b59c2 100644
--- a/examples/ipsec-secgw/Makefile
+++ b/examples/ipsec-secgw/Makefile
@@ -42,6 +42,10 @@ APP = ipsec-secgw

 CFLAGS += -O3 -gdwarf-2
 CFLAGS += $(WERROR_FLAGS)
+ifeq ($(CONFIG_RTE_TOOLCHAIN_ICC),y)
+CFLAGS_sa.o += -diag-disable=vec
+endif
+

 VPATH += $(SRCDIR)/librte_ipsec

diff --git a/examples/vmdq_dcb/Makefile b/examples/vmdq_dcb/Makefile
index 10a9a9a..8c51131 100644
--- a/examples/vmdq_dcb/Makefile
+++ b/examples/vmdq_dcb/Makefile
@@ -51,7 +51,9 @@ CFLAGS += $(WERROR_FLAGS)
 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
 CFLAGS_main.o += -Wno-return-type
 endif
-
+ifeq ($(CONFIG_RTE_TOOLCHAIN_ICC),y)
+CFLAGS_main.o += -diag-disable=vec
+endif
 EXTRA_CFLAGS += -O3 -g

 include $(RTE_SDK)/mk/rte.extapp.mk
-- 
2.5.5



[dpdk-dev] [PATCH 0/2] fixes for icc build errors

2016-04-04 Thread Daniel Mrzyglod
This series of patches is to solve errors for Intel C Compiler 

Daniel Mrzyglod (2):
  examples/l2fwd-crypto: fix for icc
  examples: fix build errors for icc

 examples/ipsec-secgw/Makefile | 4 
 examples/l2fwd-crypto/main.c  | 4 ++--
 examples/vmdq_dcb/Makefile| 4 +++-
 3 files changed, 9 insertions(+), 3 deletions(-)

-- 
2.5.5



[dpdk-dev] [PATCH v2] examples/ipsec-secgw: fix missed headers for FreeBSD

2016-03-31 Thread Daniel Mrzyglod
In FreeBSD, sys/types.h and netinet/in.h need to be included before
netinet/ip.h

There were misssed typedef for u_char - 
There were missed network definitions - 

Failure #13: http://dpdk.org/ml/archives/test-report/2016-March/001896.html

Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application")

Signed-off-by: Daniel Mrzyglod 
---
 examples/ipsec-secgw/esp.c | 3 ++-
 examples/ipsec-secgw/ipsec-secgw.c | 2 ++
 examples/ipsec-secgw/ipsec.c   | 2 +-
 examples/ipsec-secgw/ipsec.h   | 2 --
 examples/ipsec-secgw/rt.c  | 1 +
 examples/ipsec-secgw/sa.c  | 2 ++
 examples/ipsec-secgw/sp.c  | 2 ++
 7 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/examples/ipsec-secgw/esp.c b/examples/ipsec-secgw/esp.c
index ca0fc56..1927380 100644
--- a/examples/ipsec-secgw/esp.c
+++ b/examples/ipsec-secgw/esp.c
@@ -33,9 +33,10 @@

 #include 
 #include 
-#include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 

diff --git a/examples/ipsec-secgw/ipsec-secgw.c 
b/examples/ipsec-secgw/ipsec-secgw.c
index d6c9a5d..1d6c81b 100644
--- a/examples/ipsec-secgw/ipsec-secgw.c
+++ b/examples/ipsec-secgw/ipsec-secgw.c
@@ -36,6 +36,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/examples/ipsec-secgw/ipsec.c b/examples/ipsec-secgw/ipsec.c
index d385100..baf30d4 100644
--- a/examples/ipsec-secgw/ipsec.c
+++ b/examples/ipsec-secgw/ipsec.c
@@ -30,7 +30,7 @@
  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
+#include 
 #include 
 #include 

diff --git a/examples/ipsec-secgw/ipsec.h b/examples/ipsec-secgw/ipsec.h
index 8eb4e76..a13fdef 100644
--- a/examples/ipsec-secgw/ipsec.h
+++ b/examples/ipsec-secgw/ipsec.h
@@ -35,8 +35,6 @@
 #define __IPSEC_H__

 #include 
-#include 
-#include 

 #include 
 #include 
diff --git a/examples/ipsec-secgw/rt.c b/examples/ipsec-secgw/rt.c
index c3bb4de..a6d0866 100644
--- a/examples/ipsec-secgw/rt.c
+++ b/examples/ipsec-secgw/rt.c
@@ -34,6 +34,7 @@
 /*
  * Routing Table (RT)
  */
+#include 
 #include 
 #include 

diff --git a/examples/ipsec-secgw/sa.c b/examples/ipsec-secgw/sa.c
index 91a5f6e..a5b8a63 100644
--- a/examples/ipsec-secgw/sa.c
+++ b/examples/ipsec-secgw/sa.c
@@ -34,6 +34,8 @@
 /*
  * Security Associations
  */
+#include 
+#include 
 #include 

 #include 
diff --git a/examples/ipsec-secgw/sp.c b/examples/ipsec-secgw/sp.c
index 7972f40..4f16730 100644
--- a/examples/ipsec-secgw/sp.c
+++ b/examples/ipsec-secgw/sp.c
@@ -34,6 +34,8 @@
 /*
  * Security Policies
  */
+#include 
+#include 
 #include 

 #include 
-- 
2.5.5



[dpdk-dev] [PATCH] examples/ipsec-secgw: Fix Missed Headers For FreeBSD

2016-03-31 Thread Daniel Mrzyglod
There were misssed typedef for u_char - 
There were missed network definitions - 

Failure #13: http://dpdk.org/ml/archives/test-report/2016-March/001896.html

Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application")

Signed-off-by: Daniel Mrzyglod 
---
 examples/ipsec-secgw/esp.c   | 4 +++-
 examples/ipsec-secgw/ipsec.c | 2 +-
 examples/ipsec-secgw/rt.c| 1 +
 examples/ipsec-secgw/sa.c| 2 ++
 examples/ipsec-secgw/sp.c| 2 ++
 5 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/examples/ipsec-secgw/esp.c b/examples/ipsec-secgw/esp.c
index ca0fc56..7b0e04c 100644
--- a/examples/ipsec-secgw/esp.c
+++ b/examples/ipsec-secgw/esp.c
@@ -33,8 +33,10 @@

 #include 
 #include 
-#include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/examples/ipsec-secgw/ipsec.c b/examples/ipsec-secgw/ipsec.c
index d385100..baf30d4 100644
--- a/examples/ipsec-secgw/ipsec.c
+++ b/examples/ipsec-secgw/ipsec.c
@@ -30,7 +30,7 @@
  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
+#include 
 #include 
 #include 

diff --git a/examples/ipsec-secgw/rt.c b/examples/ipsec-secgw/rt.c
index c3bb4de..a6d0866 100644
--- a/examples/ipsec-secgw/rt.c
+++ b/examples/ipsec-secgw/rt.c
@@ -34,6 +34,7 @@
 /*
  * Routing Table (RT)
  */
+#include 
 #include 
 #include 

diff --git a/examples/ipsec-secgw/sa.c b/examples/ipsec-secgw/sa.c
index 91a5f6e..a5b8a63 100644
--- a/examples/ipsec-secgw/sa.c
+++ b/examples/ipsec-secgw/sa.c
@@ -34,6 +34,8 @@
 /*
  * Security Associations
  */
+#include 
+#include 
 #include 

 #include 
diff --git a/examples/ipsec-secgw/sp.c b/examples/ipsec-secgw/sp.c
index 7972f40..4f16730 100644
--- a/examples/ipsec-secgw/sp.c
+++ b/examples/ipsec-secgw/sp.c
@@ -34,6 +34,8 @@
 /*
  * Security Policies
  */
+#include 
+#include 
 #include 

 #include 
-- 
2.5.5



[dpdk-dev] [PATCH 2/2] ena: Fix Compilation for freebsd

2016-03-29 Thread Daniel Mrzyglod
FreeBSD was not defined in ena_plat.h
ETIME is not defined in FreeBSD.

In file included from DPDK/drivers/net/ena/base/ena_com.h:37:0,
 from DPDK/drivers/net/ena/ena_ethdev.h:39,
 from DPDK/drivers/net/ena/ena_ethdev.c:41:
DPDK/drivers/net/ena/base/ena_plat.h:48:2: error: #error "Invalid platform"
 #error "Invalid platform"
  ^
compilation terminated due to -Wfatal-errors.

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/ena/base/ena_plat.h  | 2 ++
 drivers/net/ena/base/ena_plat_dpdk.h | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/drivers/net/ena/base/ena_plat.h b/drivers/net/ena/base/ena_plat.h
index 278175f..b5b6454 100644
--- a/drivers/net/ena/base/ena_plat.h
+++ b/drivers/net/ena/base/ena_plat.h
@@ -42,6 +42,8 @@
 #else
 #include "ena_plat_dpdk.h"
 #endif
+#elif defined(__FreeBSD__)
+#include "ena_plat_dpdk.h"
 #elif defined(_WIN32)
 #include "ena_plat_windows.h"
 #else
diff --git a/drivers/net/ena/base/ena_plat_dpdk.h 
b/drivers/net/ena/base/ena_plat_dpdk.h
index e245e34..aab2ac8 100644
--- a/drivers/net/ena/base/ena_plat_dpdk.h
+++ b/drivers/net/ena/base/ena_plat_dpdk.h
@@ -57,6 +57,9 @@ typedef uint16_t u16;
 typedef uint8_t u8;

 typedef uint64_t dma_addr_t;
+#ifndef ETIME
+#define ETIME ETIMEDOUT
+#endif

 #define ena_atomic32_t rte_atomic32_t
 #define ena_mem_handle_t void *
-- 
2.5.5



[dpdk-dev] [PATCH 1/2] ena: icc fix compilation errors

2016-03-29 Thread Daniel Mrzyglod
  ^

/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_com.c(2363): error 
#188: enumerated type mixed with another type
ena_com_get_hash_ctrl(ena_dev, 0, NULL);
   ^

compilation aborted for 
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_com.c (code 2)
/mnt/shared/dtmrzglx/hubabuba-ena/mk/internal/rte.compile-pre.mk:126: recipe 
for target 'ena_com.o' failed
make[6]: *** [ena_com.o] Error 2
  CC ena_eth_com.o
In file included from 
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.h(40),
 from 
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.c(34):
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_com.h(982): error 
#188: enumerated type mixed with another type
curr_moder_idx = *moder_tbl_idx;
   ^

In file included from 
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.h(40),
 from 
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.c(34):
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_com.h(994): error 
#188: enumerated type mixed with another type
new_moder_idx = curr_moder_idx + 1;
  ^

In file included from 
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.h(40),
 from 
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.c(34):
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_com.h(1000): error 
#188: enumerated type mixed with another type
new_moder_idx = curr_moder_idx - 1;
  ^

In file included from 
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.h(40),
 from 
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.c(34):
/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_com.h(1004): error 
#188: enumerated type mixed with another type
new_moder_idx = curr_moder_idx + 1;
  ^

/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.c(239): 
error #188: enumerated type mixed with another type
ena_rx_ctx->l3_proto = cdesc->status &
 ^

/mnt/shared/dtmrzglx/hubabuba-ena/drivers/net/ena/base/ena_eth_com.c(241): 
error #188: enumerated type mixed with another type
    ena_rx_ctx->l4_proto =
 ^

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/ena/base/ena_com.c | 18 +-
 drivers/net/ena/base/ena_com.h |  8 
 drivers/net/ena/base/ena_eth_com.c | 10 +-
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ena/base/ena_com.c b/drivers/net/ena/base/ena_com.c
index c7355eb..f886760 100644
--- a/drivers/net/ena/base/ena_com.c
+++ b/drivers/net/ena/base/ena_com.c
@@ -303,7 +303,7 @@ ena_com_submit_admin_cmd(struct ena_com_admin_queue 
*admin_queue,
 struct ena_admin_acq_entry *comp,
 size_t comp_size_in_bytes)
 {
-   unsigned long flags;
+   unsigned long flags = 0;
struct ena_comp_ctx *comp_ctx;

ENA_SPINLOCK_LOCK(admin_queue->q_lock, flags);
@@ -526,7 +526,7 @@ ena_com_wait_and_process_admin_cq_interrupts(
struct ena_comp_ctx *comp_ctx,
struct ena_com_admin_queue *admin_queue)
 {
-   unsigned long flags;
+   unsigned long flags = 0;
int ret = 0;

ENA_WAIT_EVENT_WAIT(comp_ctx->wait_event,
@@ -571,7 +571,7 @@ static u32 ena_com_reg_bar_read32(struct ena_com_dev 
*ena_dev, u16 offset)
volatile struct ena_admin_ena_mmio_req_read_less_resp *read_resp =
mmio_read->read_resp;
u32 mmio_read_reg, ret;
-   unsigned long flags;
+   unsigned long flags = 0;
int i;

ENA_MIGHT_SLEEP();
@@ -1248,7 +1248,7 @@ void ena_com_abort_admin_commands(struct ena_com_dev 
*ena_dev)
 void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev)
 {
struct ena_com_admin_queue *admin_queue = _dev->admin_queue;
-   unsigned long flags;
+   unsigned long flags = 0;

ENA_SPINLOCK_LOCK(admin_queue->q_lock, flags);
while (ATOMIC32_READ(_queue->outstanding_cmds) != 0) {
@@ -1293,7 +1293,7 @@ bool ena_com_get_admin_running_state(struct ena_com_dev 
*ena_dev)
 void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state)
 {
struct ena_com_admin_queue *admin_queue = _dev->admin_queue;
-   unsigned long flags;
+   unsigned long flags = 0;

ENA_SPINLOCK_LOCK(admin_queue->q_lock, flags);
ena_dev->admin_queue.running_state = state;
@@ -2190,7 +2190,7 @@ int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
if (u

[dpdk-dev] [PATCH 0/2] Fix multiple build errors for Amazon ENA driver

2016-03-29 Thread Daniel Mrzyglod
First patch cover multiple error for ICC.
a. mixed enum with other types
b. variable is used uninitialized

Patches for FreeBSD:
a. Target was not setup
b. ETIME is not avaliable in FreeBSD 

Daniel Mrzyglod (2):
  ena: icc fix compilation errors
  ena: Fix Compilation for freebsd

 drivers/net/ena/base/ena_com.c   | 18 +-
 drivers/net/ena/base/ena_com.h   |  8 
 drivers/net/ena/base/ena_eth_com.c   | 10 +-
 drivers/net/ena/base/ena_plat.h  |  2 ++
 drivers/net/ena/base/ena_plat_dpdk.h |  3 +++
 5 files changed, 23 insertions(+), 18 deletions(-)

-- 
2.5.5



[dpdk-dev] [PATCH v3] mk: fix eal shared library dependencies -lrt

2016-03-22 Thread Daniel Mrzyglod
For GLIBC < 2.17 it is necessery to add -lrt for linker
from glibc > 2.17 The `clock_*' suite of functions (declared in ) is now
available directly in the main C library. This affect Ubuntu 12.04 in i686
and other older Linux Distros).

v3: change LDFLAGS to LDLIBS
v2: Add missed example
v1: Initial revision


Fixes: 4758404a3084 ("mk: fix eal shared library dependencies")

Signed-off-by: Daniel Mrzyglod 
---
 app/test/Makefile| 1 +
 examples/ptpclient/Makefile  | 1 +
 lib/librte_eal/linuxapp/eal/Makefile | 1 +
 3 files changed, 3 insertions(+)

diff --git a/app/test/Makefile b/app/test/Makefile
index 00e4df2..707930f 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -114,6 +114,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_string.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_lib.c

 ifeq ($(CONFIG_RTE_LIBRTE_SCHED),y)
+LDLIBS += -lrt
 SRCS-y += test_red.c
 SRCS-y += test_sched.c
 endif
diff --git a/examples/ptpclient/Makefile b/examples/ptpclient/Makefile
index b77cf71..082c690 100644
--- a/examples/ptpclient/Makefile
+++ b/examples/ptpclient/Makefile
@@ -46,6 +46,7 @@ SRCS-y := ptpclient.c

 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrt

 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
diff --git a/lib/librte_eal/linuxapp/eal/Makefile 
b/lib/librte_eal/linuxapp/eal/Makefile
index 25b3a8e..1860739 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -52,6 +52,7 @@ CFLAGS += $(WERROR_FLAGS) -O3
 LDLIBS += -ldl
 LDLIBS += -lpthread
 LDLIBS += -lgcc_s
+LDLIBS += -lrt

 # specific to linuxapp exec-env
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) := eal.c
-- 
2.5.5



[dpdk-dev] [PATCH v2] mk: fix eal shared library dependencies -lrt

2016-03-22 Thread Daniel Mrzyglod
For GLIBC < 2.17 it is necessery to add -lrt for linker
from glibc > 2.17 The `clock_*' suite of functions (declared in ) is now
available directly in the main C library. This affect Ubuntu 12.04 in i686
and other older Linux Distros).

v3: change LDFLAGS to LDLIBS
v2: Add missed example
v1: Initial revision


Fixes: 4758404a3084 ("mk: fix eal shared library dependencies")

Signed-off-by: Daniel Mrzyglod 
---
 app/test/Makefile| 1 +
 examples/ptpclient/Makefile  | 1 +
 lib/librte_eal/linuxapp/eal/Makefile | 1 +
 3 files changed, 3 insertions(+)

diff --git a/app/test/Makefile b/app/test/Makefile
index 00e4df2..707930f 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -114,6 +114,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_string.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_lib.c

 ifeq ($(CONFIG_RTE_LIBRTE_SCHED),y)
+LDLIBS += -lrt
 SRCS-y += test_red.c
 SRCS-y += test_sched.c
 endif
diff --git a/examples/ptpclient/Makefile b/examples/ptpclient/Makefile
index b77cf71..082c690 100644
--- a/examples/ptpclient/Makefile
+++ b/examples/ptpclient/Makefile
@@ -46,6 +46,7 @@ SRCS-y := ptpclient.c

 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrt

 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
diff --git a/lib/librte_eal/linuxapp/eal/Makefile 
b/lib/librte_eal/linuxapp/eal/Makefile
index 25b3a8e..1860739 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -52,6 +52,7 @@ CFLAGS += $(WERROR_FLAGS) -O3
 LDLIBS += -ldl
 LDLIBS += -lpthread
 LDLIBS += -lgcc_s
+LDLIBS += -lrt

 # specific to linuxapp exec-env
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) := eal.c
-- 
2.5.5



[dpdk-dev] [PATCH v2] mk: fix eal shared library dependencies -lrt

2016-03-22 Thread Daniel Mrzyglod
For GLIBC < 2.17 it is necessery to add -lrt for linker
from glibc > 2.17 The `clock_*' suite of functions (declared in ) is now
available directly in the main C library. This affect Ubuntu 12.04 in i686
and other older Linux Distros).

Fixes: 4758404a3084 ("mk: fix eal shared library dependencies")

Signed-off-by: Daniel Mrzyglod 
---
 app/test/Makefile| 1 +
 examples/ptpclient/Makefile  | 1 +
 lib/librte_eal/linuxapp/eal/Makefile | 1 +
 3 files changed, 3 insertions(+)

diff --git a/app/test/Makefile b/app/test/Makefile
index 00e4df2..707930f 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -114,6 +114,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_string.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_lib.c

 ifeq ($(CONFIG_RTE_LIBRTE_SCHED),y)
+LDFLAGS += -lrt
 SRCS-y += test_red.c
 SRCS-y += test_sched.c
 endif
diff --git a/examples/ptpclient/Makefile b/examples/ptpclient/Makefile
index b77cf71..082c690 100644
--- a/examples/ptpclient/Makefile
+++ b/examples/ptpclient/Makefile
@@ -46,6 +46,7 @@ SRCS-y := ptpclient.c

 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
+LDFLAGS += -lrt

 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
diff --git a/lib/librte_eal/linuxapp/eal/Makefile 
b/lib/librte_eal/linuxapp/eal/Makefile
index 25b3a8e..1860739 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -52,6 +52,7 @@ CFLAGS += $(WERROR_FLAGS) -O3
 LDLIBS += -ldl
 LDLIBS += -lpthread
 LDLIBS += -lgcc_s
+LDLIBS += -lrt

 # specific to linuxapp exec-env
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) := eal.c
-- 
2.5.5



[dpdk-dev] [PATCH] mk: fix eal shared library dependencies -lrt

2016-03-22 Thread Daniel Mrzyglod
For GLIBC < 2.17 it is necessery to add -lrt for linker
from glibc > 2.17 The `clock_*' suite of functions (declared in ) is now
available directly in the main C library. This affect Ubuntu 12.04 in i686
and other older Linux Distros).

Fixes: 4758404a3084 ("mk: fix eal shared library dependencies")

Signed-off-by: Daniel Mrzyglod 
---
 app/test/Makefile| 1 +
 lib/librte_eal/linuxapp/eal/Makefile | 1 +
 2 files changed, 2 insertions(+)

diff --git a/app/test/Makefile b/app/test/Makefile
index 00e4df2..707930f 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -114,6 +114,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_string.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_lib.c

 ifeq ($(CONFIG_RTE_LIBRTE_SCHED),y)
+LDFLAGS += -lrt
 SRCS-y += test_red.c
 SRCS-y += test_sched.c
 endif
diff --git a/lib/librte_eal/linuxapp/eal/Makefile 
b/lib/librte_eal/linuxapp/eal/Makefile
index 25b3a8e..1860739 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -52,6 +52,7 @@ CFLAGS += $(WERROR_FLAGS) -O3
 LDLIBS += -ldl
 LDLIBS += -lpthread
 LDLIBS += -lgcc_s
+LDLIBS += -lrt

 # specific to linuxapp exec-env
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) := eal.c
-- 
2.5.5



[dpdk-dev] [PATCH] examples/bond: add header to support freebsd compilation

2015-11-25 Thread Daniel Mrzyglod
definition of 'AF_INET' enum was missing - is available in 

Signed-off-by: Daniel Mrzyglod 
---
 examples/bond/main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/examples/bond/main.c b/examples/bond/main.c
index 4622283..53bd044 100644
--- a/examples/bond/main.c
+++ b/examples/bond/main.c
@@ -33,6 +33,7 @@

 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.5.0



[dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing

2015-11-24 Thread Daniel Mrzyglod
This fix is for IPv6 checksum offload error on RHEL65.
Any optimalisation above -O0 provide error in IPv6 checksum
flag "-fstrict-aliasing" is default for optimalisation above -O0.

Fixes: 2b039d5f20a3 ("net: fix build with gcc 4.4.7 and strict aliasing")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_net/rte_ip.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index 71c519a..5b7554a 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -169,7 +169,8 @@ __rte_raw_cksum(const void *buf, size_t len, uint32_t sum)
 {
/* workaround gcc strict-aliasing warning */
uintptr_t ptr = (uintptr_t)buf;
-   const uint16_t *u16 = (const uint16_t *)ptr;
+   typedef uint16_t __attribute__((__may_alias__)) u16_p;
+   const u16_p *u16 = (const u16_p *)ptr;

while (len >= (sizeof(*u16) * 4)) {
sum += u16[0];
-- 
2.5.0



[dpdk-dev] [PATCH v2] net: fix build with gcc 4.4.7 and strict aliasing

2015-11-24 Thread Daniel Mrzyglod
This fix is for IPv6 checksum offload error on RHEL65.
Any optimalisation above -O0 provide error in IPv6 checksum
flag "-fstrict-aliasing" is default for optimalisation above -O0.
The solution is to add typedef with __attribute__((__may_alias__) for uint16_t.

Step 1 : start testpmd
./testpmd -c 0x6 -n 4  -- -i --portmask=0x3 --disable-hw-vlan --enable-rx-cksum 
--crc-strip --txqflags=0

Step 2 : settings and start
   set verbose 1
   set fwd csum
   start

Step 3 : send scapy with bad checksum IPv6/TCP packet
Ether(src="52:00:00:00:00:00", 
dst="90:e2:ba:4a:33:5d")/IPv6(src="::1")/TCP(chksum=0xf)/("X"*46)

Step 4 : Recieved packets:
RESULTS:
IPv6/TCP': ['0xd41'] or other unexpected.

EXPECTED RESULTS:
IPv6/TCP': ['0x9f5e']

Daniel Mrzyglod (1):
  net: fix build with gcc 4.4.7 and strict aliasing

 lib/librte_net/rte_ip.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.5.0



[dpdk-dev] [PATCH] net: fix build with gcc 4.4.7 and strict aliasing

2015-11-24 Thread Daniel Mrzyglod
This is fix for GCC 4.4.7.
flag "-fstrict-aliasing" is default for optimalisation above -O0.

Fixes: 2b039d5f20a3 ("net: fix build with gcc 4.4.7 and strict aliasing")

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_net/rte_ip.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index 71c519a..5b7554a 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -169,7 +169,8 @@ __rte_raw_cksum(const void *buf, size_t len, uint32_t sum)
 {
/* workaround gcc strict-aliasing warning */
uintptr_t ptr = (uintptr_t)buf;
-   const uint16_t *u16 = (const uint16_t *)ptr;
+   typedef uint16_t __attribute__((__may_alias__)) u16_p;
+   const u16_p *u16 = (const u16_p *)ptr;

while (len >= (sizeof(*u16) * 4)) {
sum += u16[0];
-- 
2.5.0



[dpdk-dev] [PATCH v5 7/7] doc: add a PTPCLIENT sample guide

2015-11-05 Thread Daniel Mrzyglod
It includes:
 - Add the ptpclient picture with svg format.
 - Add the ptpclient.rst file
 - Change the index.rst file for the above pictures index.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/sample_app_ug/img/ptpclient.svg | 520 +
 doc/guides/sample_app_ug/index.rst |   3 +
 doc/guides/sample_app_ug/ptpclient.rst | 306 +
 3 files changed, 829 insertions(+)
 create mode 100644 doc/guides/sample_app_ug/img/ptpclient.svg
 create mode 100644 doc/guides/sample_app_ug/ptpclient.rst

diff --git a/doc/guides/sample_app_ug/img/ptpclient.svg 
b/doc/guides/sample_app_ug/img/ptpclient.svg
new file mode 100644
index 000..55c134e
--- /dev/null
+++ b/doc/guides/sample_app_ug/img/ptpclient.svg
@@ -0,0 +1,520 @@
+
+
+
+http://purl.org/dc/elements/1.1/;
+   xmlns:cc="http://creativecommons.org/ns#;
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#;
+   xmlns:svg="http://www.w3.org/2000/svg;
+   xmlns="http://www.w3.org/2000/svg;
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd;
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape;
+   width="105mm"
+   height="148mm"
+   viewBox="0 0 372.04724 524.40945"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.91 r13725"
+   sodipodi:docname="drawing3.svg">
+  
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+
+
+
+
+
+
+  
+  
+  
+
+  
+image/svg+xml
+http://purl.org/dc/dcmitype/StillImage; />
+
+  
+
+  
+  
+
+
+
+
+T2
+FOLLOW UP:T1
+
+DELAY REQUEST
+T3
+T4
+T1
+
+DELAY RESPONSE:T4
+time
+
+master
+
+slave
+SYNC
+  
+
diff --git a/doc/guides/sample_app_ug/index.rst 
b/doc/guides/sample_app_ug/index.rst
index 9beedd9..8ae86c0 100644
--- a/doc/guides/sample_app_ug/index.rst
+++ b/doc/guides/sample_app_ug/index.rst
@@ -73,6 +73,7 @@ Sample Applications User Guide
 vm_power_management
 tep_termination
 proc_info
+ptpclient

 **Figures**

@@ -136,6 +137,8 @@ Sample Applications User Guide
 :numref:`figure_overlay_networking` :ref:`figure_overlay_networking`
 :numref:`figure_tep_termination_arch` :ref:`figure_tep_termination_arch`

+:numref:`figure_ptpclient_highlevel` :ref:`figure_ptpclient_highlevel`
+
 **Tables**

 :numref:`table_qos_metering_1` :ref:`table_qos_metering_1`
diff --git a/doc/guides/sample_app_ug/ptpclient.rst 
b/doc/guides/sample_app_ug/ptpclient.rst
new file mode 100644
index 000..6e425b7
--- /dev/null
+++ b/doc/guides/sample_app_ug/ptpclient.rst
@@ -0,0 +1,306 @@
+..  BSD LICENSE
+Copyright(c) 2015 Intel Corporation. All rights reserved.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the
+distribution.
+* Neither the name of Intel Corporation nor the names of its
+contributors may be used to endorse or promote products derived
+from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+PTP Client Sample Application
+=
+
+The PTP (Precision Time Protocol) client sample application is a simple
+example of using the DPDK IEEE1588 API to communicate with a PTP master clock
+to synchronize the time on the NIC and, optionally, on the Linux system.
+
+Note, PTP is a time

[dpdk-dev] [PATCH v5 6/7] example: PTP client slave minimal implementation

2015-11-05 Thread Daniel Mrzyglod
Add a sample application that acts as a PTP slave using the
DPDK ieee1588 functions.

Signed-off-by: Daniel Mrzyglod 
---
 MAINTAINERS  |   3 +
 doc/guides/rel_notes/release_2_2.rst |   5 +
 examples/Makefile|   1 +
 examples/ptpclient/Makefile  |  56 +++
 examples/ptpclient/ptpclient.c   | 779 +++
 5 files changed, 844 insertions(+)
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c

diff --git a/MAINTAINERS b/MAINTAINERS
index c8be5d2..0638665 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -520,3 +520,6 @@ F: examples/tep_termination/
 F: examples/vmdq/
 F: examples/vmdq_dcb/
 F: doc/guides/sample_app_ug/vmdq_dcb_forwarding.rst
+
+M: Daniel Mrzyglod 
+F: examples/ptpclient
diff --git a/doc/guides/rel_notes/release_2_2.rst 
b/doc/guides/rel_notes/release_2_2.rst
index 17b281c..1bfbdd2 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -94,6 +94,11 @@ New Features

 * **Added port hotplug support to xenvirt.**

+* **ptpclient: simple PTP slave client.**
+
+  Add a sample application that acts as a PTP slave using the
+  DPDK ieee1588 functions.
+

 Resolved Issues
 ---
diff --git a/examples/Makefile b/examples/Makefile
index b4eddbd..4672534 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -74,5 +74,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_XEN_DOM0) += vhost_xen
 DIRS-y += vmdq
 DIRS-y += vmdq_dcb
 DIRS-$(CONFIG_RTE_LIBRTE_POWER) += vm_power_manager
+DIRS-$(CONFIG_RTE_LIBRTE_IEEE1588) += ptpclient

 include $(RTE_SDK)/mk/rte.extsubdir.mk
diff --git a/examples/ptpclient/Makefile b/examples/ptpclient/Makefile
new file mode 100644
index 000..b77cf71
--- /dev/null
+++ b/examples/ptpclient/Makefile
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2015 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriddegitn by command line or environment
+RTE_TARGET ?= x86_64-native-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = ptpclient
+
+# all source are stored in SRCS-y
+SRCS-y := ptpclient.c
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c
new file mode 100644
index 000..2a9698b
--- /dev/null
+++ b/examples/ptpclient/ptpclient.c
@@ -0,0 +1,779 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distributio

[dpdk-dev] [PATCH v5 5/7] i40e: add additional ieee1588 support functions

2015-11-05 Thread Daniel Mrzyglod
From: Pablo de Lara <pablo.de.lara.gua...@intel.com>

Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Pablo de Lara 
Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/i40e/i40e_ethdev.c | 196 -
 drivers/net/i40e/i40e_ethdev.h |   5 ++
 2 files changed, 181 insertions(+), 20 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index ddf3d38..98d61f9 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -125,11 +125,13 @@
(1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
(1UL << RTE_ETH_FLOW_L2_PAYLOAD))

-#define I40E_PTP_40GB_INCVAL  0x01ULL
-#define I40E_PTP_10GB_INCVAL  0x03ULL
-#define I40E_PTP_1GB_INCVAL   0x20ULL
-#define I40E_PRTTSYN_TSYNENA  0x8000
-#define I40E_PRTTSYN_TSYNTYPE 0x0e00
+/* Additional timesync values. */
+#define I40E_PTP_40GB_INCVAL 0x01ULL
+#define I40E_PTP_10GB_INCVAL 0x03ULL
+#define I40E_PTP_1GB_INCVAL  0x20ULL
+#define I40E_PRTTSYN_TSYNENA 0x8000
+#define I40E_PRTTSYN_TSYNTYPE0x0e00
+#define I40E_CYCLECOUNTER_MASK   0x

 #define I40E_MAX_PERCENT100
 #define I40E_DEFAULT_DCB_APP_NUM1
@@ -400,11 +402,20 @@ static int i40e_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
   struct timespec *timestamp);
 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
+
+static int i40e_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);
+
+static int i40e_timesync_time_get(struct rte_eth_dev *dev,
+ struct timespec *timestamp);
+static int i40e_timesync_time_set(struct rte_eth_dev *dev,
+ struct timespec *timestamp);
+
 static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
 uint16_t queue_id);
 static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
  uint16_t queue_id);

+
 static const struct rte_pci_id pci_id_i40e_map[] = {
 #define RTE_PCI_DEV_ID_DECL_I40E(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
 #include "rte_pci_dev_ids.h"
@@ -469,6 +480,9 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
.timesync_read_rx_timestamp   = i40e_timesync_read_rx_timestamp,
.timesync_read_tx_timestamp   = i40e_timesync_read_tx_timestamp,
.get_dcb_info = i40e_dev_get_dcb_info,
+   .timesync_time_adjust = i40e_timesync_time_adjust,
+   .timesync_time_get= i40e_timesync_time_get,
+   .timesync_time_set= i40e_timesync_time_set,
 };

 /* store statistics names and its offset in stats structure */
@@ -7738,17 +7752,95 @@ i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t 
sw_id)
return 0;
 }

-static int
-i40e_timesync_enable(struct rte_eth_dev *dev)
+/*
+ * Adds the new cycles (in nanoseconds) to the previous time stored.
+ */
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta = (cycle_tstamp - tc->cycle_last);
+   uint64_t nsec = tc->nsec;
+
+   nsec += delta;
+
+   return nsec;
+}
+
+static uint64_t
+i40e_read_timesync_cyclecounter(struct rte_eth_dev *dev)
 {
struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-   struct rte_eth_link *link = >data->dev_link;
-   uint32_t tsync_ctl_l;
-   uint32_t tsync_ctl_h;
+   uint64_t systim_cycles = 0;
+
+   systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
+   systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
+   << 32;
+
+   return systim_cycles;
+}
+
+static uint64_t
+timecounter_read_ns_delta(struct rte_eth_dev *dev)
+{
+   uint64_t cycle_now, cycle_delta;
+   struct i40e_adapter *adapter =
+   (struct i40e_adapter *)dev->data->dev_private;
+
+   /* Read cycle counter. */
+   cycle_now = adapter->tc.cc->read(dev);
+
+   /* Calculate the delta since the last timecounter_read_delta(). */
+   cycle_delta = (cycle_now - adapter->tc.cycle_last);
+
+   /* Update time stamp of timecounter_read_delta() call. */
+   adapter->tc.cycle_last = cycle_now;
+
+   /* Delta already in nanoseconds. */
+   return cycle_delta;
+}
+
+static uint64_t
+timecounter_read(struct rte_eth_dev *dev)
+{
+   uint64_t nsec;
+   struct i40e_adapter *adapter =
+   (struct i40e_adapter *)dev->data->dev_private;
+
+   /* Increment time by nanoseconds since last call. */
+   nsec = timecounter_read_ns_d

[dpdk-dev] [PATCH v5 4/7] igb: add additional ieee1588 support functions

2015-11-05 Thread Daniel Mrzyglod
From: Pablo de Lara <pablo.de.lara.gua...@intel.com>

Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Pablo de Lara 
Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/e1000/e1000_ethdev.h |   3 +
 drivers/net/e1000/igb_ethdev.c   | 299 +--
 2 files changed, 292 insertions(+), 10 deletions(-)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index a667a1a..c2b64c7 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -33,6 +33,7 @@

 #ifndef _E1000_ETHDEV_H_
 #define _E1000_ETHDEV_H_
+#include 

 /* need update link, bit flag */
 #define E1000_FLAG_NEED_LINK_UPDATE (uint32_t)(1 << 0)
@@ -257,6 +258,8 @@ struct e1000_adapter {
struct e1000_vf_info*vfdata;
struct e1000_filter_info filter;
bool stopped;
+   struct cyclecounter cc;
+   struct timecounter tc;
 };

 #define E1000_DEV_PRIVATE(adapter) \
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index 2cb115c..dcc68b5 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -78,10 +78,11 @@
 #define IGB_8_BIT_MASK   UINT8_MAX

 /* Additional timesync values. */
-#define E1000_ETQF_FILTER_1588 3
-#define E1000_TIMINCA_INCVALUE 1600
-#define E1000_TIMINCA_INIT ((0x02 << E1000_TIMINCA_16NS_SHIFT) \
-   | E1000_TIMINCA_INCVALUE)
+#define E1000_CYCLECOUNTER_MASK  0x
+#define E1000_ETQF_FILTER_1588   3
+#define IGB_82576_TSYNC_SHIFT16
+#define E1000_INCPERIOD_82576(1 << E1000_TIMINCA_16NS_SHIFT)
+#define E1000_INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
 #define E1000_TSAUXC_DISABLE_SYSTIME 0x8000

 static int  eth_igb_configure(struct rte_eth_dev *dev);
@@ -236,6 +237,11 @@ static int igb_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
  uint32_t flags);
 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
  struct timespec *timestamp);
+static int igb_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);
+static int igb_timesync_time_get(struct rte_eth_dev *dev,
+struct timespec *timestamp);
+static int igb_timesync_time_set(struct rte_eth_dev *dev,
+struct timespec *timestamp);
 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
uint16_t queue_id);
 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
@@ -349,6 +355,9 @@ static const struct eth_dev_ops eth_igb_ops = {
.get_eeprom_length= eth_igb_get_eeprom_length,
.get_eeprom   = eth_igb_get_eeprom,
.set_eeprom   = eth_igb_set_eeprom,
+   .timesync_time_adjust  = igb_timesync_time_adjust,
+   .timesync_time_get = igb_timesync_time_get,
+   .timesync_time_set = igb_timesync_time_set,
 };

 /*
@@ -4182,20 +4191,248 @@ eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
return 0;
 }

+/*
+ * Register units might not be nanoseconds. This function converts
+ * these units into nanoseconds and adds to the previous time stored.
+ */
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta;
+   uint64_t nsec = tc->nsec, frac = tc->frac;
+
+   delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
+   /*
+* Cycle counts that are correctly converted as they
+* are between -1/2 max cycle count and +1/2 max cycle count.
+*/
+   if (delta > (tc->cc->mask / 2)) {
+   delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
+   nsec -= cyclecounter_cycles_to_ns_backwards(tc->cc, delta,
+   frac);
+   } else {
+   nsec += cyclecounter_cycles_to_ns(tc->cc, delta, tc->mask,
+ );
+   }
+
+   return nsec;
+}
+
+static uint64_t
+igb_read_timesync_cyclecounter(struct rte_eth_dev *dev)
+{
+   struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t systime_cycles = 0;
+
+   switch (hw->mac.type) {
+   case e1000_i210:
+   case e1000_i211:
+   /*
+* Need to read System Time Residue Register to be able
+* to read the other two registers.
+*/
+   E1000_READ_REG(hw, E1000_SYSTIMR);
+   /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
+   systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
+   systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYS

[dpdk-dev] [PATCH v5 3/7] ixgbe: add additional ieee1588 support functions

2015-11-05 Thread Daniel Mrzyglod
Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Daniel Mrzyglod 
Signed-off-by: Pablo de Lara 
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 272 +--
 drivers/net/ixgbe/ixgbe_ethdev.h |   3 +
 2 files changed, 264 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 0b0bbcf..1c4300e 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -126,10 +126,17 @@
 #define IXGBE_HKEY_MAX_INDEX 10

 /* Additional timesync values. */
-#define IXGBE_TIMINCA_16NS_SHIFT 24
-#define IXGBE_TIMINCA_INCVALUE   1600
-#define IXGBE_TIMINCA_INIT   ((0x02 << IXGBE_TIMINCA_16NS_SHIFT) \
- | IXGBE_TIMINCA_INCVALUE)
+#define NSEC_PER_SEC 10L
+#define IXGBE_INCVAL_10GB0x
+#define IXGBE_INCVAL_1GB 0x4000
+#define IXGBE_INCVAL_100 0x5000
+#define IXGBE_INCVAL_SHIFT_10GB  28
+#define IXGBE_INCVAL_SHIFT_1GB   24
+#define IXGBE_INCVAL_SHIFT_100   21
+#define IXGBE_INCVAL_SHIFT_82599 7
+#define IXGBE_INCPER_SHIFT_82599 24
+
+#define IXGBE_CYCLECOUNTER_MASK   0x

 static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev);
@@ -325,6 +332,11 @@ static int ixgbe_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
uint32_t flags);
 static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
struct timespec *timestamp);
+static int ixgbe_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);
+static int ixgbe_timesync_time_get(struct rte_eth_dev *dev,
+  struct timespec *timestamp);
+static int ixgbe_timesync_time_set(struct rte_eth_dev *dev,
+  struct timespec *timestamp);

 /*
  * Define VF Stats MACRO for Non "cleared on read" register
@@ -480,6 +492,9 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = {
.get_eeprom   = ixgbe_get_eeprom,
.set_eeprom   = ixgbe_set_eeprom,
.get_dcb_info = ixgbe_dev_get_dcb_info,
+   .timesync_time_adjust = ixgbe_timesync_time_adjust,
+   .timesync_time_get= ixgbe_timesync_time_get,
+   .timesync_time_set= ixgbe_timesync_time_set,
 };

 /*
@@ -5608,20 +5623,232 @@ ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
 ixgbe_dev_addr_list_itr, TRUE);
 }

+/*
+ * Register units might not be nanoseconds. This function converts
+ * these units into nanoseconds and adds to the previous time stored.
+ */
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta;
+   uint64_t nsec = tc->nsec, frac = tc->frac;
+
+   delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
+   /*
+* Cycle counts that are correctly converted as they
+* are between -1/2 max cycle count and +1/2 max cycle count.
+*/
+   if (delta > (tc->cc->mask / 2)) {
+   delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
+   nsec -= cyclecounter_cycles_to_ns_backwards(tc->cc,
+   delta, frac);
+   } else {
+   nsec += cyclecounter_cycles_to_ns(tc->cc, delta, tc->mask,
+ );
+   }
+
+   return nsec;
+}
+
+static uint64_t
+ixgbe_read_timesync_cyclecounter(struct rte_eth_dev *dev)
+{
+   struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t systime_cycles = 0;
+
+   switch (hw->mac.type) {
+   case ixgbe_mac_X550:
+   /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
+   systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
+   systime_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
+   * NSEC_PER_SEC;
+   break;
+   default:
+   systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
+   systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
+   << 32;
+   }
+
+   return systime_cycles;
+}
+
+/*
+ * Get nanoseconds since the last call of this function.
+ */
+static uint64_t
+timecounter_read_ns_delta(struct rte_eth_dev *dev)
+{
+   struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t cycle_now, cycle_delta;
+   uint64_t ns_offset;
+   struct ixgbe_adapter *adapter =
+   (struct ixgbe_adapter *)dev->data->dev_private;
+
+   /* Read cycle coun

[dpdk-dev] [PATCH v5 2/7] net: Add common PTP structures and functions

2015-11-05 Thread Daniel Mrzyglod
This patch add common functions and structures used for PTP processing.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_net/Makefile  |   2 +-
 lib/librte_net/rte_ptp.h | 105 +++
 2 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_net/rte_ptp.h

diff --git a/lib/librte_net/Makefile b/lib/librte_net/Makefile
index ad2e482..1d33618 100644
--- a/lib/librte_net/Makefile
+++ b/lib/librte_net/Makefile
@@ -34,7 +34,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3

 # install includes
-SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.h 
rte_sctp.h rte_icmp.h rte_arp.h
+SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.h 
rte_sctp.h rte_icmp.h rte_arp.h rte_ptp.h


 include $(RTE_SDK)/mk/rte.install.mk
diff --git a/lib/librte_net/rte_ptp.h b/lib/librte_net/rte_ptp.h
new file mode 100644
index 000..8a4c83c
--- /dev/null
+++ b/lib/librte_net/rte_ptp.h
@@ -0,0 +1,105 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define NSEC_PER_SEC 10L
+
+/*
+ * Structure for cyclecounter IEEE1588 functionality.
+ */
+struct cyclecounter {
+   uint64_t (*read)(struct rte_eth_dev *dev);
+   uint64_t mask;
+   uint32_t shift;
+};
+
+/*
+ * Structure to hold and calculate Unix epoch time.
+ */
+struct timecounter {
+   struct cyclecounter *cc;
+   uint64_t cycle_last;
+   uint64_t nsec;
+   uint64_t mask;
+   uint64_t frac;
+};
+
+
+/* Utility functions for PTP/IEEE1588 support. */
+
+static inline uint64_t
+timespec_to_ns(const struct timespec *ts)
+{
+   return ((uint64_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
+}
+
+static inline struct timespec
+ns_to_timespec(uint64_t nsec)
+{
+   struct timespec ts = {0, 0};
+
+   if (nsec == 0)
+   return ts;
+
+   ts.tv_sec = nsec / NSEC_PER_SEC;
+   ts.tv_nsec = nsec % NSEC_PER_SEC;
+
+   return ts;
+}
+
+/*
+ * Converts cycle counter cycles to nanoseconds.
+ */
+static inline uint64_t
+cyclecounter_cycles_to_ns(const struct cyclecounter *cc,
+ uint64_t cycles, uint64_t mask, uint64_t *frac)
+{
+   uint64_t ns;
+
+   /* Add fractional nanoseconds */
+   ns = cycles + *frac;
+   *frac = ns & mask;
+
+   /* Shift to get only nanoseconds. */
+   return ns >> cc->shift;
+}
+
+/*
+ * Like cyclecounter_cycles_to_ns(), but this is used when
+ * computing a time previous to the stored in the cycle counter.
+ */
+static inline uint64_t
+cyclecounter_cycles_to_ns_backwards(const struct cyclecounter *cc,
+  uint64_t cycles, uint64_t frac)
+{
+   return ((cycles - frac) >> cc->shift);
+}
-- 
2.5.0



[dpdk-dev] [PATCH v5 1/7] ethdev: add additional ieee1588 support functions

2015-11-05 Thread Daniel Mrzyglod
Add additional functions to support the existing IEEE1588
functionality.

* rte_eth_timesync_settime(), function to set the device clock time.
* rte_eth_timesync_gettime, function to get the device clock time.
* rte_eth_timesync_adjust, function to adjust the device clock time.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/rel_notes/release_2_2.rst   |  3 ++
 lib/librte_ether/rte_ethdev.c  | 36 +++
 lib/librte_ether/rte_ethdev.h  | 65 +-
 lib/librte_ether/rte_ether_version.map |  3 ++
 4 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/doc/guides/rel_notes/release_2_2.rst 
b/doc/guides/rel_notes/release_2_2.rst
index 59dda59..17b281c 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -222,6 +222,9 @@ API Changes

 * The devargs union field virtual is renamed to virt for C++ compatibility.

+* Add new functions in ethdev to support IEEE1588: 
rte_eth_timesync_time_adjust()
+  rte_eth_timesync_time_get(), rte_eth_timesync_time_set()
+

 ABI Changes
 ---
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index e0e1dca..20cf013 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3193,6 +3193,42 @@ rte_eth_timesync_read_tx_timestamp(uint8_t port_id, 
struct timespec *timestamp)
 }

 int
+rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_adjust, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_adjust)(dev, delta);
+}
+
+int
+rte_eth_timesync_time_get(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_get, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_get)(dev, timestamp);
+}
+
+int
+rte_eth_timesync_time_set(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_set, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_set)(dev, timestamp);
+}
+
+int
 rte_eth_dev_get_reg_length(uint8_t port_id)
 {
struct rte_eth_dev *dev;
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 48a540d..585d980 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1206,6 +1206,17 @@ typedef int (*eth_timesync_read_tx_timestamp_t)(struct 
rte_eth_dev *dev,
struct timespec *timestamp);
 /**< @internal Function used to read a TX IEEE1588/802.1AS timestamp. */

+typedef int (*eth_timesync_time_adjust)(struct rte_eth_dev *dev, int64_t);
+/**< @internal Function used to adjust device clock */
+
+typedef int (*eth_timesync_time_get)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock. */
+
+typedef int (*eth_timesync_time_set)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock */
+
 typedef int (*eth_get_reg_length_t)(struct rte_eth_dev *dev);
 /**< @internal Retrieve device register count  */

@@ -1400,6 +1411,12 @@ struct eth_dev_ops {

/** Get DCB information */
eth_get_dcb_info get_dcb_info;
+   /** Adjust the device clock */
+   eth_timesync_time_adjust timesync_time_adjust;
+   /** Get the device clock timespec */
+   eth_timesync_time_get timesync_time_get;
+   /** Set the device clock timespec */
+   eth_timesync_time_set timesync_time_set;
 };

 /**
@@ -3755,6 +3772,53 @@ extern int rte_eth_timesync_read_tx_timestamp(uint8_t 
port_id,
  struct timespec *timestamp);

 /**
+ * Adjust the timesync clock on an Ethernet device..
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param delta
+ *   The adjustment in nanoseconds
+ *
+ * @return
+ *   - 0: Success.
+ *   - -ENODEV: The port ID is invalid.
+ *   - -ENOTSUP: The function is not supported by the Ethernet driver.
+ */
+extern int rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta);
+
+/**
+ * Read the time from the timesync clock on an Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param time
+ *   Pointer to the timespec struct.
+ *
+ * @return
+ *   - 0: Success.
+ */
+extern int rte_eth_timesync_time_get(uint8_t port_id,
+ struct timespec *time);
+
+
+/**
+ * Set t

[dpdk-dev] [PATCH v5 0/7] add sample ptp slave application

2015-11-05 Thread Daniel Mrzyglod
Add a sample application that acts as a PTP slave using the DPDK IEEE1588
functions.

Also add some additional IEEE1588 support functions to enable getting,
setting and adjusting the device time.

V4->v5:
 - rebase to the current master

V3->V4:
Doc:
 - Update documentation for ptpclient
 - fix: put information about ptpaplication in correct place

V2->V3:
PMD:
 - move common structures and functions for PTP protocol to librte_net/rte_ptp.h

V1->V2:
PMDs:
 - add support for e1000
 - add support for ixgbe
 - add support for i40
ethdev:
 - change function names to more proper
Doc:
 - add documentation for ptpclient
sample:
 - add kernel adjustment option
 - add portmask option to provide portmask to aplication
Daniel Mrzyglod (5):
  ethdev: add additional ieee1588 support functions
  net: Add common PTP structures and functions
  ixgbe: add additional ieee1588 support functions
  example: PTP client slave minimal implementation
  doc: add a PTPCLIENT sample guide

Pablo de Lara (2):
  igb: add additional ieee1588 support functions
  i40e: add additional ieee1588 support functions

 MAINTAINERS|   3 +
 doc/guides/rel_notes/release_2_2.rst   |   8 +
 doc/guides/sample_app_ug/img/ptpclient.svg | 520 +++
 doc/guides/sample_app_ug/index.rst |   3 +
 doc/guides/sample_app_ug/ptpclient.rst | 306 +++
 drivers/net/e1000/e1000_ethdev.h   |   3 +
 drivers/net/e1000/igb_ethdev.c | 299 ++-
 drivers/net/i40e/i40e_ethdev.c | 196 +++-
 drivers/net/i40e/i40e_ethdev.h |   5 +
 drivers/net/ixgbe/ixgbe_ethdev.c   | 272 +-
 drivers/net/ixgbe/ixgbe_ethdev.h   |   3 +
 examples/Makefile  |   1 +
 examples/ptpclient/Makefile|  56 +++
 examples/ptpclient/ptpclient.c | 779 +
 lib/librte_ether/rte_ethdev.c  |  36 ++
 lib/librte_ether/rte_ethdev.h  |  65 ++-
 lib/librte_ether/rte_ether_version.map |   3 +
 lib/librte_net/Makefile|   2 +-
 lib/librte_net/rte_ptp.h   | 105 
 19 files changed, 2622 insertions(+), 43 deletions(-)
 create mode 100644 doc/guides/sample_app_ug/img/ptpclient.svg
 create mode 100644 doc/guides/sample_app_ug/ptpclient.rst
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c
 create mode 100644 lib/librte_net/rte_ptp.h

-- 
2.5.0



[dpdk-dev] [PATCH v4 7/7] doc: add a PTPCLIENT sample guide

2015-11-04 Thread Daniel Mrzyglod
It includes:
 - Add the ptpclient picture with svg format.
 - Add the ptpclient.rst file
 - Change the index.rst file for the above pictures index.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/sample_app_ug/img/ptpclient.svg | 520 +
 doc/guides/sample_app_ug/index.rst |   3 +
 doc/guides/sample_app_ug/ptpclient.rst | 306 +
 3 files changed, 829 insertions(+)
 create mode 100644 doc/guides/sample_app_ug/img/ptpclient.svg
 create mode 100644 doc/guides/sample_app_ug/ptpclient.rst

diff --git a/doc/guides/sample_app_ug/img/ptpclient.svg 
b/doc/guides/sample_app_ug/img/ptpclient.svg
new file mode 100644
index 000..55c134e
--- /dev/null
+++ b/doc/guides/sample_app_ug/img/ptpclient.svg
@@ -0,0 +1,520 @@
+
+
+
+http://purl.org/dc/elements/1.1/;
+   xmlns:cc="http://creativecommons.org/ns#;
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#;
+   xmlns:svg="http://www.w3.org/2000/svg;
+   xmlns="http://www.w3.org/2000/svg;
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd;
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape;
+   width="105mm"
+   height="148mm"
+   viewBox="0 0 372.04724 524.40945"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.91 r13725"
+   sodipodi:docname="drawing3.svg">
+  
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+
+
+
+
+
+
+  
+  
+  
+
+  
+image/svg+xml
+http://purl.org/dc/dcmitype/StillImage; />
+
+  
+
+  
+  
+
+
+
+
+T2
+FOLLOW UP:T1
+
+DELAY REQUEST
+T3
+T4
+T1
+
+DELAY RESPONSE:T4
+time
+
+master
+
+slave
+SYNC
+  
+
diff --git a/doc/guides/sample_app_ug/index.rst 
b/doc/guides/sample_app_ug/index.rst
index 9beedd9..8ae86c0 100644
--- a/doc/guides/sample_app_ug/index.rst
+++ b/doc/guides/sample_app_ug/index.rst
@@ -73,6 +73,7 @@ Sample Applications User Guide
 vm_power_management
 tep_termination
 proc_info
+ptpclient

 **Figures**

@@ -136,6 +137,8 @@ Sample Applications User Guide
 :numref:`figure_overlay_networking` :ref:`figure_overlay_networking`
 :numref:`figure_tep_termination_arch` :ref:`figure_tep_termination_arch`

+:numref:`figure_ptpclient_highlevel` :ref:`figure_ptpclient_highlevel`
+
 **Tables**

 :numref:`table_qos_metering_1` :ref:`table_qos_metering_1`
diff --git a/doc/guides/sample_app_ug/ptpclient.rst 
b/doc/guides/sample_app_ug/ptpclient.rst
new file mode 100644
index 000..6e425b7
--- /dev/null
+++ b/doc/guides/sample_app_ug/ptpclient.rst
@@ -0,0 +1,306 @@
+..  BSD LICENSE
+Copyright(c) 2015 Intel Corporation. All rights reserved.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the
+distribution.
+* Neither the name of Intel Corporation nor the names of its
+contributors may be used to endorse or promote products derived
+from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+PTP Client Sample Application
+=
+
+The PTP (Precision Time Protocol) client sample application is a simple
+example of using the DPDK IEEE1588 API to communicate with a PTP master clock
+to synchronize the time on the NIC and, optionally, on the Linux system.
+
+Note, PTP is a time

[dpdk-dev] [PATCH v4 6/7] example: PTP client slave minimal implementation

2015-11-04 Thread Daniel Mrzyglod
Add a sample application that acts as a PTP slave using the
DPDK ieee1588 functions.

Signed-off-by: Daniel Mrzyglod 
---
 MAINTAINERS  |   3 +
 doc/guides/rel_notes/release_2_2.rst |   5 +
 examples/Makefile|   1 +
 examples/ptpclient/Makefile  |  56 +++
 examples/ptpclient/ptpclient.c   | 779 +++
 5 files changed, 844 insertions(+)
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c

diff --git a/MAINTAINERS b/MAINTAINERS
index c8be5d2..0638665 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -520,3 +520,6 @@ F: examples/tep_termination/
 F: examples/vmdq/
 F: examples/vmdq_dcb/
 F: doc/guides/sample_app_ug/vmdq_dcb_forwarding.rst
+
+M: Daniel Mrzyglod 
+F: examples/ptpclient
diff --git a/doc/guides/rel_notes/release_2_2.rst 
b/doc/guides/rel_notes/release_2_2.rst
index e39d422..159450f 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -90,6 +90,11 @@ New Features

 * **Added port hotplug support to xenvirt.**

+* **ptpclient: simple PTP slave client.**
+
+  Add a sample application that acts as a PTP slave using the
+  DPDK ieee1588 functions.
+

 Resolved Issues
 ---
diff --git a/examples/Makefile b/examples/Makefile
index b4eddbd..4672534 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -74,5 +74,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_XEN_DOM0) += vhost_xen
 DIRS-y += vmdq
 DIRS-y += vmdq_dcb
 DIRS-$(CONFIG_RTE_LIBRTE_POWER) += vm_power_manager
+DIRS-$(CONFIG_RTE_LIBRTE_IEEE1588) += ptpclient

 include $(RTE_SDK)/mk/rte.extsubdir.mk
diff --git a/examples/ptpclient/Makefile b/examples/ptpclient/Makefile
new file mode 100644
index 000..b77cf71
--- /dev/null
+++ b/examples/ptpclient/Makefile
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2015 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriddegitn by command line or environment
+RTE_TARGET ?= x86_64-native-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = ptpclient
+
+# all source are stored in SRCS-y
+SRCS-y := ptpclient.c
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c
new file mode 100644
index 000..2a9698b
--- /dev/null
+++ b/examples/ptpclient/ptpclient.c
@@ -0,0 +1,779 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distributio

[dpdk-dev] [PATCH v4 5/7] i40e: add additional ieee1588 support functions

2015-11-04 Thread Daniel Mrzyglod
From: Pablo de Lara <pablo.de.lara.gua...@intel.com>

Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Pablo de Lara 
Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/i40e/i40e_ethdev.c | 192 -
 drivers/net/i40e/i40e_ethdev.h |   5 ++
 2 files changed, 177 insertions(+), 20 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 34acc8c..0c9f630 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -129,11 +129,13 @@
(1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
(1UL << RTE_ETH_FLOW_L2_PAYLOAD))

-#define I40E_PTP_40GB_INCVAL  0x01ULL
-#define I40E_PTP_10GB_INCVAL  0x03ULL
-#define I40E_PTP_1GB_INCVAL   0x20ULL
-#define I40E_PRTTSYN_TSYNENA  0x8000
-#define I40E_PRTTSYN_TSYNTYPE 0x0e00
+/* Additional timesync values. */
+#define I40E_PTP_40GB_INCVAL 0x01ULL
+#define I40E_PTP_10GB_INCVAL 0x03ULL
+#define I40E_PTP_1GB_INCVAL  0x20ULL
+#define I40E_PRTTSYN_TSYNENA 0x8000
+#define I40E_PRTTSYN_TSYNTYPE0x0e00
+#define I40E_CYCLECOUNTER_MASK   0x

 #define I40E_MAX_PERCENT100
 #define I40E_DEFAULT_DCB_APP_NUM1
@@ -404,6 +406,11 @@ static int i40e_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
   struct timespec *timestamp);
 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
+static int i40e_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);
+static int i40e_timesync_time_get(struct rte_eth_dev *dev,
+ struct timespec *timestamp);
+static int i40e_timesync_time_set(struct rte_eth_dev *dev,
+ struct timespec *timestamp);


 static const struct rte_pci_id pci_id_i40e_map[] = {
@@ -468,6 +475,9 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
.timesync_read_rx_timestamp   = i40e_timesync_read_rx_timestamp,
.timesync_read_tx_timestamp   = i40e_timesync_read_tx_timestamp,
.get_dcb_info = i40e_dev_get_dcb_info,
+   .timesync_time_adjust = i40e_timesync_time_adjust,
+   .timesync_time_get= i40e_timesync_time_get,
+   .timesync_time_set= i40e_timesync_time_set,
 };

 /* store statistics names and its offset in stats structure */
@@ -7544,17 +7554,95 @@ i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t 
sw_id)
return 0;
 }

-static int
-i40e_timesync_enable(struct rte_eth_dev *dev)
+/*
+ * Adds the new cycles (in nanoseconds) to the previous time stored.
+ */
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta = (cycle_tstamp - tc->cycle_last);
+   uint64_t nsec = tc->nsec;
+
+   nsec += delta;
+
+   return nsec;
+}
+
+static uint64_t
+i40e_read_timesync_cyclecounter(struct rte_eth_dev *dev)
 {
struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-   struct rte_eth_link *link = >data->dev_link;
-   uint32_t tsync_ctl_l;
-   uint32_t tsync_ctl_h;
+   uint64_t systim_cycles = 0;
+
+   systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
+   systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
+   << 32;
+
+   return systim_cycles;
+}
+
+static uint64_t
+timecounter_read_ns_delta(struct rte_eth_dev *dev)
+{
+   uint64_t cycle_now, cycle_delta;
+   struct i40e_adapter *adapter =
+   (struct i40e_adapter *)dev->data->dev_private;
+
+   /* Read cycle counter. */
+   cycle_now = adapter->tc.cc->read(dev);
+
+   /* Calculate the delta since the last timecounter_read_delta(). */
+   cycle_delta = (cycle_now - adapter->tc.cycle_last);
+
+   /* Update time stamp of timecounter_read_delta() call. */
+   adapter->tc.cycle_last = cycle_now;
+
+   /* Delta already in nanoseconds. */
+   return cycle_delta;
+}
+
+static uint64_t
+timecounter_read(struct rte_eth_dev *dev)
+{
+   uint64_t nsec;
+   struct i40e_adapter *adapter =
+   (struct i40e_adapter *)dev->data->dev_private;
+
+   /* Increment time by nanoseconds since last call. */
+   nsec = timecounter_read_ns_delta(dev);
+   nsec += adapter->tc.nsec;
+   adapter->tc.nsec = nsec;
+
+   return nsec;
+}
+
+static void
+timecounter_init(struct rte_eth_dev *dev,
+ uint64_t start_time)
+{
+   struct i40e_adapter *adapter =
+   (struct i40e_adapter *)dev->data->dev_private;
+   adapter->tc.cc = >cc;
+   adapt

[dpdk-dev] [PATCH v4 4/7] igb: add additional ieee1588 support functions

2015-11-04 Thread Daniel Mrzyglod
From: Pablo de Lara <pablo.de.lara.gua...@intel.com>

Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Pablo de Lara 
Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/e1000/e1000_ethdev.h |   3 +
 drivers/net/e1000/igb_ethdev.c   | 299 +--
 2 files changed, 292 insertions(+), 10 deletions(-)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 3c6f613..247002a 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -33,6 +33,7 @@

 #ifndef _E1000_ETHDEV_H_
 #define _E1000_ETHDEV_H_
+#include 

 /* need update link, bit flag */
 #define E1000_FLAG_NEED_LINK_UPDATE (uint32_t)(1 << 0)
@@ -254,6 +255,8 @@ struct e1000_adapter {
struct e1000_vf_info*vfdata;
struct e1000_filter_info filter;
bool stopped;
+   struct cyclecounter cc;
+   struct timecounter tc;
 };

 #define E1000_DEV_PRIVATE(adapter) \
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index cd7f7c1..edb7456 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -78,10 +78,11 @@
 #define IGB_8_BIT_MASK   UINT8_MAX

 /* Additional timesync values. */
-#define E1000_ETQF_FILTER_1588 3
-#define E1000_TIMINCA_INCVALUE 1600
-#define E1000_TIMINCA_INIT ((0x02 << E1000_TIMINCA_16NS_SHIFT) \
-   | E1000_TIMINCA_INCVALUE)
+#define E1000_CYCLECOUNTER_MASK  0x
+#define E1000_ETQF_FILTER_1588   3
+#define IGB_82576_TSYNC_SHIFT16
+#define E1000_INCPERIOD_82576(1 << E1000_TIMINCA_16NS_SHIFT)
+#define E1000_INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
 #define E1000_TSAUXC_DISABLE_SYSTIME 0x8000

 static int  eth_igb_configure(struct rte_eth_dev *dev);
@@ -236,6 +237,11 @@ static int igb_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
  uint32_t flags);
 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
  struct timespec *timestamp);
+static int igb_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);
+static int igb_timesync_time_get(struct rte_eth_dev *dev,
+struct timespec *timestamp);
+static int igb_timesync_time_set(struct rte_eth_dev *dev,
+struct timespec *timestamp);
 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
uint16_t queue_id);
 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
@@ -349,6 +355,9 @@ static const struct eth_dev_ops eth_igb_ops = {
.get_eeprom_length= eth_igb_get_eeprom_length,
.get_eeprom   = eth_igb_get_eeprom,
.set_eeprom   = eth_igb_set_eeprom,
+   .timesync_time_adjust  = igb_timesync_time_adjust,
+   .timesync_time_get = igb_timesync_time_get,
+   .timesync_time_set = igb_timesync_time_set,
 };

 /*
@@ -4165,20 +4174,248 @@ eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
return 0;
 }

+/*
+ * Register units might not be nanoseconds. This function converts
+ * these units into nanoseconds and adds to the previous time stored.
+ */
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta;
+   uint64_t nsec = tc->nsec, frac = tc->frac;
+
+   delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
+   /*
+* Cycle counts that are correctly converted as they
+* are between -1/2 max cycle count and +1/2 max cycle count.
+*/
+   if (delta > (tc->cc->mask / 2)) {
+   delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
+   nsec -= cyclecounter_cycles_to_ns_backwards(tc->cc, delta,
+   frac);
+   } else {
+   nsec += cyclecounter_cycles_to_ns(tc->cc, delta, tc->mask,
+ );
+   }
+
+   return nsec;
+}
+
+static uint64_t
+igb_read_timesync_cyclecounter(struct rte_eth_dev *dev)
+{
+   struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t systime_cycles = 0;
+
+   switch (hw->mac.type) {
+   case e1000_i210:
+   case e1000_i211:
+   /*
+* Need to read System Time Residue Register to be able
+* to read the other two registers.
+*/
+   E1000_READ_REG(hw, E1000_SYSTIMR);
+   /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
+   systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
+   systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYS

[dpdk-dev] [PATCH v4 3/7] ixgbe: add additional ieee1588 support functions

2015-11-04 Thread Daniel Mrzyglod
Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Daniel Mrzyglod 
Signed-off-by: Pablo de Lara 
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 272 +--
 drivers/net/ixgbe/ixgbe_ethdev.h |   3 +
 2 files changed, 264 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 25966ef..e575f28 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -126,10 +126,17 @@
 #define IXGBE_HKEY_MAX_INDEX 10

 /* Additional timesync values. */
-#define IXGBE_TIMINCA_16NS_SHIFT 24
-#define IXGBE_TIMINCA_INCVALUE   1600
-#define IXGBE_TIMINCA_INIT   ((0x02 << IXGBE_TIMINCA_16NS_SHIFT) \
- | IXGBE_TIMINCA_INCVALUE)
+#define NSEC_PER_SEC 10L
+#define IXGBE_INCVAL_10GB0x
+#define IXGBE_INCVAL_1GB 0x4000
+#define IXGBE_INCVAL_100 0x5000
+#define IXGBE_INCVAL_SHIFT_10GB  28
+#define IXGBE_INCVAL_SHIFT_1GB   24
+#define IXGBE_INCVAL_SHIFT_100   21
+#define IXGBE_INCVAL_SHIFT_82599 7
+#define IXGBE_INCPER_SHIFT_82599 24
+
+#define IXGBE_CYCLECOUNTER_MASK   0x

 static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev);
@@ -329,6 +336,11 @@ static int ixgbe_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
uint32_t flags);
 static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
struct timespec *timestamp);
+static int ixgbe_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);
+static int ixgbe_timesync_time_get(struct rte_eth_dev *dev,
+  struct timespec *timestamp);
+static int ixgbe_timesync_time_set(struct rte_eth_dev *dev,
+  struct timespec *timestamp);

 /*
  * Define VF Stats MACRO for Non "cleared on read" register
@@ -484,6 +496,9 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = {
.get_eeprom   = ixgbe_get_eeprom,
.set_eeprom   = ixgbe_set_eeprom,
.get_dcb_info = ixgbe_dev_get_dcb_info,
+   .timesync_time_adjust = ixgbe_timesync_time_adjust,
+   .timesync_time_get= ixgbe_timesync_time_get,
+   .timesync_time_set= ixgbe_timesync_time_set,
 };

 /*
@@ -5654,20 +5669,232 @@ ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
 ixgbe_dev_addr_list_itr, TRUE);
 }

+/*
+ * Register units might not be nanoseconds. This function converts
+ * these units into nanoseconds and adds to the previous time stored.
+ */
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta;
+   uint64_t nsec = tc->nsec, frac = tc->frac;
+
+   delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
+   /*
+* Cycle counts that are correctly converted as they
+* are between -1/2 max cycle count and +1/2 max cycle count.
+*/
+   if (delta > (tc->cc->mask / 2)) {
+   delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
+   nsec -= cyclecounter_cycles_to_ns_backwards(tc->cc,
+   delta, frac);
+   } else {
+   nsec += cyclecounter_cycles_to_ns(tc->cc, delta, tc->mask,
+ );
+   }
+
+   return nsec;
+}
+
+static uint64_t
+ixgbe_read_timesync_cyclecounter(struct rte_eth_dev *dev)
+{
+   struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t systime_cycles = 0;
+
+   switch (hw->mac.type) {
+   case ixgbe_mac_X550:
+   /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
+   systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
+   systime_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
+   * NSEC_PER_SEC;
+   break;
+   default:
+   systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
+   systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
+   << 32;
+   }
+
+   return systime_cycles;
+}
+
+/*
+ * Get nanoseconds since the last call of this function.
+ */
+static uint64_t
+timecounter_read_ns_delta(struct rte_eth_dev *dev)
+{
+   struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t cycle_now, cycle_delta;
+   uint64_t ns_offset;
+   struct ixgbe_adapter *adapter =
+   (struct ixgbe_adapter *)dev->data->dev_private;
+
+   /* Read cycle coun

[dpdk-dev] [PATCH v4 2/7] net: Add common PTP structures and functions

2015-11-04 Thread Daniel Mrzyglod
This patch add common functions and structures used for PTP processing.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_net/Makefile  |   2 +-
 lib/librte_net/rte_ptp.h | 105 +++
 2 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_net/rte_ptp.h

diff --git a/lib/librte_net/Makefile b/lib/librte_net/Makefile
index ad2e482..1d33618 100644
--- a/lib/librte_net/Makefile
+++ b/lib/librte_net/Makefile
@@ -34,7 +34,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3

 # install includes
-SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.h 
rte_sctp.h rte_icmp.h rte_arp.h
+SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.h 
rte_sctp.h rte_icmp.h rte_arp.h rte_ptp.h


 include $(RTE_SDK)/mk/rte.install.mk
diff --git a/lib/librte_net/rte_ptp.h b/lib/librte_net/rte_ptp.h
new file mode 100644
index 000..8a4c83c
--- /dev/null
+++ b/lib/librte_net/rte_ptp.h
@@ -0,0 +1,105 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define NSEC_PER_SEC 10L
+
+/*
+ * Structure for cyclecounter IEEE1588 functionality.
+ */
+struct cyclecounter {
+   uint64_t (*read)(struct rte_eth_dev *dev);
+   uint64_t mask;
+   uint32_t shift;
+};
+
+/*
+ * Structure to hold and calculate Unix epoch time.
+ */
+struct timecounter {
+   struct cyclecounter *cc;
+   uint64_t cycle_last;
+   uint64_t nsec;
+   uint64_t mask;
+   uint64_t frac;
+};
+
+
+/* Utility functions for PTP/IEEE1588 support. */
+
+static inline uint64_t
+timespec_to_ns(const struct timespec *ts)
+{
+   return ((uint64_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
+}
+
+static inline struct timespec
+ns_to_timespec(uint64_t nsec)
+{
+   struct timespec ts = {0, 0};
+
+   if (nsec == 0)
+   return ts;
+
+   ts.tv_sec = nsec / NSEC_PER_SEC;
+   ts.tv_nsec = nsec % NSEC_PER_SEC;
+
+   return ts;
+}
+
+/*
+ * Converts cycle counter cycles to nanoseconds.
+ */
+static inline uint64_t
+cyclecounter_cycles_to_ns(const struct cyclecounter *cc,
+ uint64_t cycles, uint64_t mask, uint64_t *frac)
+{
+   uint64_t ns;
+
+   /* Add fractional nanoseconds */
+   ns = cycles + *frac;
+   *frac = ns & mask;
+
+   /* Shift to get only nanoseconds. */
+   return ns >> cc->shift;
+}
+
+/*
+ * Like cyclecounter_cycles_to_ns(), but this is used when
+ * computing a time previous to the stored in the cycle counter.
+ */
+static inline uint64_t
+cyclecounter_cycles_to_ns_backwards(const struct cyclecounter *cc,
+  uint64_t cycles, uint64_t frac)
+{
+   return ((cycles - frac) >> cc->shift);
+}
-- 
2.5.0



[dpdk-dev] [PATCH v4 1/7] ethdev: add additional ieee1588 support functions

2015-11-04 Thread Daniel Mrzyglod
Add additional functions to support the existing IEEE1588
functionality.

* rte_eth_timesync_settime(), function to set the device clock time.
* rte_eth_timesync_gettime, function to get the device clock time.
* rte_eth_timesync_adjust, function to adjust the device clock time.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/rel_notes/release_2_2.rst   |  3 ++
 lib/librte_ether/rte_ethdev.c  | 36 +++
 lib/librte_ether/rte_ethdev.h  | 65 +-
 lib/librte_ether/rte_ether_version.map |  3 ++
 4 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/doc/guides/rel_notes/release_2_2.rst 
b/doc/guides/rel_notes/release_2_2.rst
index ca8471b..e39d422 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -205,6 +205,9 @@ API Changes

 * The devargs union field virtual is renamed to virt for C++ compatibility.

+* Add new functions in ethdev to support IEEE1588: 
rte_eth_timesync_time_adjust()
+  rte_eth_timesync_time_get(), rte_eth_timesync_time_set()
+

 ABI Changes
 ---
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index fcc9e0f..759a731 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3165,6 +3165,42 @@ rte_eth_timesync_read_tx_timestamp(uint8_t port_id, 
struct timespec *timestamp)
 }

 int
+rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_adjust, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_adjust)(dev, delta);
+}
+
+int
+rte_eth_timesync_time_get(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_get, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_get)(dev, timestamp);
+}
+
+int
+rte_eth_timesync_time_set(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_set, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_set)(dev, timestamp);
+}
+
+int
 rte_eth_dev_get_reg_length(uint8_t port_id)
 {
struct rte_eth_dev *dev;
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 4f7b64b..f9d282b 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1200,6 +1200,17 @@ typedef int (*eth_timesync_read_tx_timestamp_t)(struct 
rte_eth_dev *dev,
struct timespec *timestamp);
 /**< @internal Function used to read a TX IEEE1588/802.1AS timestamp. */

+typedef int (*eth_timesync_time_adjust)(struct rte_eth_dev *dev, int64_t);
+/**< @internal Function used to adjust device clock */
+
+typedef int (*eth_timesync_time_get)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock. */
+
+typedef int (*eth_timesync_time_set)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock */
+
 typedef int (*eth_get_reg_length_t)(struct rte_eth_dev *dev);
 /**< @internal Retrieve device register count  */

@@ -1394,6 +1405,12 @@ struct eth_dev_ops {

/** Get DCB information */
eth_get_dcb_info get_dcb_info;
+   /** Adjust the device clock */
+   eth_timesync_time_adjust timesync_time_adjust;
+   /** Get the device clock timespec */
+   eth_timesync_time_get timesync_time_get;
+   /** Set the device clock timespec */
+   eth_timesync_time_set timesync_time_set;
 };

 /**
@@ -3745,6 +3762,53 @@ extern int rte_eth_timesync_read_tx_timestamp(uint8_t 
port_id,
  struct timespec *timestamp);

 /**
+ * Adjust the timesync clock on an Ethernet device..
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param delta
+ *   The adjustment in nanoseconds
+ *
+ * @return
+ *   - 0: Success.
+ *   - -ENODEV: The port ID is invalid.
+ *   - -ENOTSUP: The function is not supported by the Ethernet driver.
+ */
+extern int rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta);
+
+/**
+ * Read the time from the timesync clock on an Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param time
+ *   Pointer to the timespec struct.
+ *
+ * @return
+ *   - 0: Success.
+ */
+extern int rte_eth_timesync_time_get(uint8_t port_id,
+ struct timespec *time);
+
+
+/**
+ * Set t

[dpdk-dev] [PATCH v4 0/7] add sample ptp slave application

2015-11-04 Thread Daniel Mrzyglod
Add a sample application that acts as a PTP slave using the DPDK IEEE1588
functions.

Also add some additional IEEE1588 support functions to enable getting,
setting and adjusting the device time.

V3->V4:
Doc:
 - Update documentation for ptpclient
 - fix: put information about ptpaplication in correct place

V2->V3:
PMD:
 - move common structures and functions for PTP protocol to librte_net/rte_ptp.h

V1->V2:
PMDs:
 - add support for e1000
 - add support for ixgbe
 - add support for i40
ethdev:
 - change function names to more proper
Doc:
 - add documentation for ptpclient
sample:
 - add kernel adjustment option
 - add portmask option to provide portmask to aplication

Daniel Mrzyglod (5):
  ethdev: add additional ieee1588 support functions
  net: Add common PTP structures and functions
  ixgbe: add additional ieee1588 support functions
  example: PTP client slave minimal implementation
  doc: add a PTPCLIENT sample guide

Pablo de Lara (2):
  igb: add additional ieee1588 support functions
  i40e: add additional ieee1588 support functions

 MAINTAINERS|   3 +
 doc/guides/rel_notes/release_2_2.rst   |   8 +
 doc/guides/sample_app_ug/img/ptpclient.svg | 520 +++
 doc/guides/sample_app_ug/index.rst |   3 +
 doc/guides/sample_app_ug/ptpclient.rst | 306 +++
 drivers/net/e1000/e1000_ethdev.h   |   3 +
 drivers/net/e1000/igb_ethdev.c | 299 ++-
 drivers/net/i40e/i40e_ethdev.c | 192 ++-
 drivers/net/i40e/i40e_ethdev.h |   5 +
 drivers/net/ixgbe/ixgbe_ethdev.c   | 272 +-
 drivers/net/ixgbe/ixgbe_ethdev.h   |   3 +
 examples/Makefile  |   1 +
 examples/ptpclient/Makefile|  56 +++
 examples/ptpclient/ptpclient.c | 779 +
 lib/librte_ether/rte_ethdev.c  |  36 ++
 lib/librte_ether/rte_ethdev.h  |  65 ++-
 lib/librte_ether/rte_ether_version.map |   3 +
 lib/librte_net/Makefile|   2 +-
 lib/librte_net/rte_ptp.h   | 105 
 19 files changed, 2618 insertions(+), 43 deletions(-)
 create mode 100644 doc/guides/sample_app_ug/img/ptpclient.svg
 create mode 100644 doc/guides/sample_app_ug/ptpclient.rst
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c
 create mode 100644 lib/librte_net/rte_ptp.h

-- 
2.5.0



[dpdk-dev] [PATCH v3 7/7] doc: add a PTPCLIENT sample guide

2015-11-03 Thread Daniel Mrzyglod
It includes:
 - Add the ptpclient picture with svg format.
 - Add the ptpclient.rst file
 - Change the index.rst file for the above pictures index.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/sample_app_ug/img/ptpclient.svg | 520 +
 doc/guides/sample_app_ug/index.rst |   3 +
 doc/guides/sample_app_ug/ptpclient.rst | 324 ++
 3 files changed, 847 insertions(+)
 create mode 100644 doc/guides/sample_app_ug/img/ptpclient.svg
 create mode 100644 doc/guides/sample_app_ug/ptpclient.rst

diff --git a/doc/guides/sample_app_ug/img/ptpclient.svg 
b/doc/guides/sample_app_ug/img/ptpclient.svg
new file mode 100644
index 000..55c134e
--- /dev/null
+++ b/doc/guides/sample_app_ug/img/ptpclient.svg
@@ -0,0 +1,520 @@
+
+
+
+http://purl.org/dc/elements/1.1/;
+   xmlns:cc="http://creativecommons.org/ns#;
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#;
+   xmlns:svg="http://www.w3.org/2000/svg;
+   xmlns="http://www.w3.org/2000/svg;
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd;
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape;
+   width="105mm"
+   height="148mm"
+   viewBox="0 0 372.04724 524.40945"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.91 r13725"
+   sodipodi:docname="drawing3.svg">
+  
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+
+
+
+
+
+
+  
+  
+  
+
+  
+image/svg+xml
+http://purl.org/dc/dcmitype/StillImage; />
+
+  
+
+  
+  
+
+
+
+
+T2
+FOLLOW UP:T1
+
+DELAY REQUEST
+T3
+T4
+T1
+
+DELAY RESPONSE:T4
+time
+
+master
+
+slave
+SYNC
+  
+
diff --git a/doc/guides/sample_app_ug/index.rst 
b/doc/guides/sample_app_ug/index.rst
index 9beedd9..8ae86c0 100644
--- a/doc/guides/sample_app_ug/index.rst
+++ b/doc/guides/sample_app_ug/index.rst
@@ -73,6 +73,7 @@ Sample Applications User Guide
 vm_power_management
 tep_termination
 proc_info
+ptpclient

 **Figures**

@@ -136,6 +137,8 @@ Sample Applications User Guide
 :numref:`figure_overlay_networking` :ref:`figure_overlay_networking`
 :numref:`figure_tep_termination_arch` :ref:`figure_tep_termination_arch`

+:numref:`figure_ptpclient_highlevel` :ref:`figure_ptpclient_highlevel`
+
 **Tables**

 :numref:`table_qos_metering_1` :ref:`table_qos_metering_1`
diff --git a/doc/guides/sample_app_ug/ptpclient.rst 
b/doc/guides/sample_app_ug/ptpclient.rst
new file mode 100644
index 000..31aa505
--- /dev/null
+++ b/doc/guides/sample_app_ug/ptpclient.rst
@@ -0,0 +1,324 @@
+..  BSD LICENSE
+Copyright(c) 2015 Intel Corporation. All rights reserved.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the
+distribution.
+* Neither the name of Intel Corporation nor the names of its
+contributors may be used to endorse or promote products derived
+from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+PTP Client Sample Application
+=
+
+The PTP (Precision Time Protocol) client sample application is a simple
+example of using the DPDK IEEE1588 API to communicate with a PTP master clock
+to synchronize the time on the NIC and, optionally, on the Linux system.
+
+Note, PTP is a time

[dpdk-dev] [PATCH v3 6/7] example: PTP client slave minimal implementation

2015-11-03 Thread Daniel Mrzyglod
Add a sample application that acts as a PTP slave using the
DPDK ieee1588 functions.

Signed-off-by: Daniel Mrzyglod 
---
 MAINTAINERS  |   3 +
 doc/guides/rel_notes/release_2_2.rst |   5 +
 examples/Makefile|   1 +
 examples/ptpclient/Makefile  |  56 +++
 examples/ptpclient/ptpclient.c   | 779 +++
 5 files changed, 844 insertions(+)
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c

diff --git a/MAINTAINERS b/MAINTAINERS
index c8be5d2..0638665 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -520,3 +520,6 @@ F: examples/tep_termination/
 F: examples/vmdq/
 F: examples/vmdq_dcb/
 F: doc/guides/sample_app_ug/vmdq_dcb_forwarding.rst
+
+M: Daniel Mrzyglod 
+F: examples/ptpclient
diff --git a/doc/guides/rel_notes/release_2_2.rst 
b/doc/guides/rel_notes/release_2_2.rst
index 09fd642..c32338c 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -141,6 +141,11 @@ Libraries
 Examples
 

+* **ptpclient: simple PTP slave client.**
+
+  Add a sample application that acts as a PTP slave using the
+  DPDK ieee1588 functions.
+

 Other
 ~
diff --git a/examples/Makefile b/examples/Makefile
index b4eddbd..4672534 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -74,5 +74,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_XEN_DOM0) += vhost_xen
 DIRS-y += vmdq
 DIRS-y += vmdq_dcb
 DIRS-$(CONFIG_RTE_LIBRTE_POWER) += vm_power_manager
+DIRS-$(CONFIG_RTE_LIBRTE_IEEE1588) += ptpclient

 include $(RTE_SDK)/mk/rte.extsubdir.mk
diff --git a/examples/ptpclient/Makefile b/examples/ptpclient/Makefile
new file mode 100644
index 000..00dc68e
--- /dev/null
+++ b/examples/ptpclient/Makefile
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2015 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriddegitn by command line or environment
+RTE_TARGET ?= x86_64-native-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = ptpclient
+
+# all source are stored in SRCS-y
+SRCS-y := ptpclient.c
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c
new file mode 100644
index 000..8cfa8d0
--- /dev/null
+++ b/examples/ptpclient/ptpclient.c
@@ -0,0 +1,779 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation 

[dpdk-dev] [PATCH v3 5/7] i40e: add additional ieee1588 support functions

2015-11-03 Thread Daniel Mrzyglod
From: Pablo de Lara <pablo.de.lara.gua...@intel.com>

Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Pablo de Lara 
Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/i40e/i40e_ethdev.c | 192 -
 drivers/net/i40e/i40e_ethdev.h |   5 ++
 2 files changed, 177 insertions(+), 20 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 5a9f11d..f1c36a8 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -129,11 +129,13 @@
(1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
(1UL << RTE_ETH_FLOW_L2_PAYLOAD))

-#define I40E_PTP_40GB_INCVAL  0x01ULL
-#define I40E_PTP_10GB_INCVAL  0x03ULL
-#define I40E_PTP_1GB_INCVAL   0x20ULL
-#define I40E_PRTTSYN_TSYNENA  0x8000
-#define I40E_PRTTSYN_TSYNTYPE 0x0e00
+/* Additional timesync values. */
+#define I40E_PTP_40GB_INCVAL 0x01ULL
+#define I40E_PTP_10GB_INCVAL 0x03ULL
+#define I40E_PTP_1GB_INCVAL  0x20ULL
+#define I40E_PRTTSYN_TSYNENA 0x8000
+#define I40E_PRTTSYN_TSYNTYPE0x0e00
+#define I40E_CYCLECOUNTER_MASK   0x

 #define I40E_MAX_PERCENT100
 #define I40E_DEFAULT_DCB_APP_NUM1
@@ -268,6 +270,11 @@ static int i40e_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
   struct timespec *timestamp);
 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
+static int i40e_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);
+static int i40e_timesync_time_get(struct rte_eth_dev *dev,
+ struct timespec *timestamp);
+static int i40e_timesync_time_set(struct rte_eth_dev *dev,
+ struct timespec *timestamp);


 static const struct rte_pci_id pci_id_i40e_map[] = {
@@ -332,6 +339,9 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
.timesync_read_rx_timestamp   = i40e_timesync_read_rx_timestamp,
.timesync_read_tx_timestamp   = i40e_timesync_read_tx_timestamp,
.get_dcb_info = i40e_dev_get_dcb_info,
+   .timesync_time_adjust = i40e_timesync_time_adjust,
+   .timesync_time_get= i40e_timesync_time_get,
+   .timesync_time_set= i40e_timesync_time_set,
 };

 /* store statistics names and its offset in stats structure */
@@ -6742,17 +6752,95 @@ i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t 
sw_id)
return 0;
 }

-static int
-i40e_timesync_enable(struct rte_eth_dev *dev)
+/*
+ * Adds the new cycles (in nanoseconds) to the previous time stored.
+ */
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta = (cycle_tstamp - tc->cycle_last);
+   uint64_t nsec = tc->nsec;
+
+   nsec += delta;
+
+   return nsec;
+}
+
+static uint64_t
+i40e_read_timesync_cyclecounter(struct rte_eth_dev *dev)
 {
struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-   struct rte_eth_link *link = >data->dev_link;
-   uint32_t tsync_ctl_l;
-   uint32_t tsync_ctl_h;
+   uint64_t systim_cycles = 0;
+
+   systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
+   systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
+   << 32;
+
+   return systim_cycles;
+}
+
+static uint64_t
+timecounter_read_ns_delta(struct rte_eth_dev *dev)
+{
+   uint64_t cycle_now, cycle_delta;
+   struct i40e_adapter *adapter =
+   (struct i40e_adapter *)dev->data->dev_private;
+
+   /* Read cycle counter. */
+   cycle_now = adapter->tc.cc->read(dev);
+
+   /* Calculate the delta since the last timecounter_read_delta(). */
+   cycle_delta = (cycle_now - adapter->tc.cycle_last);
+
+   /* Update time stamp of timecounter_read_delta() call. */
+   adapter->tc.cycle_last = cycle_now;
+
+   /* Delta already in nanoseconds. */
+   return cycle_delta;
+}
+
+static uint64_t
+timecounter_read(struct rte_eth_dev *dev)
+{
+   uint64_t nsec;
+   struct i40e_adapter *adapter =
+   (struct i40e_adapter *)dev->data->dev_private;
+
+   /* Increment time by nanoseconds since last call. */
+   nsec = timecounter_read_ns_delta(dev);
+   nsec += adapter->tc.nsec;
+   adapter->tc.nsec = nsec;
+
+   return nsec;
+}
+
+static void
+timecounter_init(struct rte_eth_dev *dev,
+ uint64_t start_time)
+{
+   struct i40e_adapter *adapter =
+   (struct i40e_adapter *)dev->data->dev_private;
+   adapter->tc.cc = >cc;
+   adapt

[dpdk-dev] [PATCH v3 4/7] igb: add additional ieee1588 support functions

2015-11-03 Thread Daniel Mrzyglod
From: Pablo de Lara <pablo.de.lara.gua...@intel.com>

Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Pablo de Lara 
Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/e1000/e1000_ethdev.h |   3 +
 drivers/net/e1000/igb_ethdev.c   | 299 +--
 2 files changed, 292 insertions(+), 10 deletions(-)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 3c6f613..247002a 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -33,6 +33,7 @@

 #ifndef _E1000_ETHDEV_H_
 #define _E1000_ETHDEV_H_
+#include 

 /* need update link, bit flag */
 #define E1000_FLAG_NEED_LINK_UPDATE (uint32_t)(1 << 0)
@@ -254,6 +255,8 @@ struct e1000_adapter {
struct e1000_vf_info*vfdata;
struct e1000_filter_info filter;
bool stopped;
+   struct cyclecounter cc;
+   struct timecounter tc;
 };

 #define E1000_DEV_PRIVATE(adapter) \
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index 97ca3c0..d4c0bcb 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -78,10 +78,11 @@
 #define IGB_8_BIT_MASK   UINT8_MAX

 /* Additional timesync values. */
-#define E1000_ETQF_FILTER_1588 3
-#define E1000_TIMINCA_INCVALUE 1600
-#define E1000_TIMINCA_INIT ((0x02 << E1000_TIMINCA_16NS_SHIFT) \
-   | E1000_TIMINCA_INCVALUE)
+#define E1000_CYCLECOUNTER_MASK  0x
+#define E1000_ETQF_FILTER_1588   3
+#define IGB_82576_TSYNC_SHIFT16
+#define E1000_INCPERIOD_82576(1 << E1000_TIMINCA_16NS_SHIFT)
+#define E1000_INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
 #define E1000_TSAUXC_DISABLE_SYSTIME 0x8000

 static int  eth_igb_configure(struct rte_eth_dev *dev);
@@ -236,6 +237,11 @@ static int igb_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
  uint32_t flags);
 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
  struct timespec *timestamp);
+static int igb_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);
+static int igb_timesync_time_get(struct rte_eth_dev *dev,
+struct timespec *timestamp);
+static int igb_timesync_time_set(struct rte_eth_dev *dev,
+struct timespec *timestamp);
 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
uint16_t queue_id);
 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
@@ -349,6 +355,9 @@ static const struct eth_dev_ops eth_igb_ops = {
.get_eeprom_length= eth_igb_get_eeprom_length,
.get_eeprom   = eth_igb_get_eeprom,
.set_eeprom   = eth_igb_set_eeprom,
+   .timesync_time_adjust  = igb_timesync_time_adjust,
+   .timesync_time_get = igb_timesync_time_get,
+   .timesync_time_set = igb_timesync_time_set,
 };

 /*
@@ -4160,20 +4169,248 @@ eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
return 0;
 }

+/*
+ * Register units might not be nanoseconds. This function converts
+ * these units into nanoseconds and adds to the previous time stored.
+ */
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta;
+   uint64_t nsec = tc->nsec, frac = tc->frac;
+
+   delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
+   /*
+* Cycle counts that are correctly converted as they
+* are between -1/2 max cycle count and +1/2 max cycle count.
+*/
+   if (delta > (tc->cc->mask / 2)) {
+   delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
+   nsec -= cyclecounter_cycles_to_ns_backwards(tc->cc, delta,
+   frac);
+   } else {
+   nsec += cyclecounter_cycles_to_ns(tc->cc, delta, tc->mask,
+ );
+   }
+
+   return nsec;
+}
+
+static uint64_t
+igb_read_timesync_cyclecounter(struct rte_eth_dev *dev)
+{
+   struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t systime_cycles = 0;
+
+   switch (hw->mac.type) {
+   case e1000_i210:
+   case e1000_i211:
+   /*
+* Need to read System Time Residue Register to be able
+* to read the other two registers.
+*/
+   E1000_READ_REG(hw, E1000_SYSTIMR);
+   /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
+   systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
+   systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYS

[dpdk-dev] [PATCH v3 3/7] ixgbe: add additional ieee1588 support functions

2015-11-03 Thread Daniel Mrzyglod
Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Daniel Mrzyglod 
Signed-off-by: Pablo de Lara 
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 272 +--
 drivers/net/ixgbe/ixgbe_ethdev.h |   3 +
 2 files changed, 264 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 52c2fdb..595d75c 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -126,10 +126,17 @@
 #define IXGBE_HKEY_MAX_INDEX 10

 /* Additional timesync values. */
-#define IXGBE_TIMINCA_16NS_SHIFT 24
-#define IXGBE_TIMINCA_INCVALUE   1600
-#define IXGBE_TIMINCA_INIT   ((0x02 << IXGBE_TIMINCA_16NS_SHIFT) \
- | IXGBE_TIMINCA_INCVALUE)
+#define NSEC_PER_SEC 10L
+#define IXGBE_INCVAL_10GB0x
+#define IXGBE_INCVAL_1GB 0x4000
+#define IXGBE_INCVAL_100 0x5000
+#define IXGBE_INCVAL_SHIFT_10GB  28
+#define IXGBE_INCVAL_SHIFT_1GB   24
+#define IXGBE_INCVAL_SHIFT_100   21
+#define IXGBE_INCVAL_SHIFT_82599 7
+#define IXGBE_INCPER_SHIFT_82599 24
+
+#define IXGBE_CYCLECOUNTER_MASK   0x

 static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev);
@@ -329,6 +336,11 @@ static int ixgbe_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
uint32_t flags);
 static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
struct timespec *timestamp);
+static int ixgbe_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);
+static int ixgbe_timesync_time_get(struct rte_eth_dev *dev,
+  struct timespec *timestamp);
+static int ixgbe_timesync_time_set(struct rte_eth_dev *dev,
+  struct timespec *timestamp);

 /*
  * Define VF Stats MACRO for Non "cleared on read" register
@@ -484,6 +496,9 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = {
.get_eeprom   = ixgbe_get_eeprom,
.set_eeprom   = ixgbe_set_eeprom,
.get_dcb_info = ixgbe_dev_get_dcb_info,
+   .timesync_time_adjust = ixgbe_timesync_time_adjust,
+   .timesync_time_get= ixgbe_timesync_time_get,
+   .timesync_time_set= ixgbe_timesync_time_set,
 };

 /*
@@ -5650,20 +5665,232 @@ ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
 ixgbe_dev_addr_list_itr, TRUE);
 }

+/*
+ * Register units might not be nanoseconds. This function converts
+ * these units into nanoseconds and adds to the previous time stored.
+ */
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta;
+   uint64_t nsec = tc->nsec, frac = tc->frac;
+
+   delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
+   /*
+* Cycle counts that are correctly converted as they
+* are between -1/2 max cycle count and +1/2 max cycle count.
+*/
+   if (delta > (tc->cc->mask / 2)) {
+   delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
+   nsec -= cyclecounter_cycles_to_ns_backwards(tc->cc,
+   delta, frac);
+   } else {
+   nsec += cyclecounter_cycles_to_ns(tc->cc, delta, tc->mask,
+ );
+   }
+
+   return nsec;
+}
+
+static uint64_t
+ixgbe_read_timesync_cyclecounter(struct rte_eth_dev *dev)
+{
+   struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t systime_cycles = 0;
+
+   switch (hw->mac.type) {
+   case ixgbe_mac_X550:
+   /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
+   systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
+   systime_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
+   * NSEC_PER_SEC;
+   break;
+   default:
+   systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
+   systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
+   << 32;
+   }
+
+   return systime_cycles;
+}
+
+/*
+ * Get nanoseconds since the last call of this function.
+ */
+static uint64_t
+timecounter_read_ns_delta(struct rte_eth_dev *dev)
+{
+   struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t cycle_now, cycle_delta;
+   uint64_t ns_offset;
+   struct ixgbe_adapter *adapter =
+   (struct ixgbe_adapter *)dev->data->dev_private;
+
+   /* Read cycle coun

[dpdk-dev] [PATCH v3 2/7] net: Add common PTP structures and functions

2015-11-03 Thread Daniel Mrzyglod
This patch add common functions and structures used for PTP processing.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_net/Makefile  |   2 +-
 lib/librte_net/rte_ptp.h | 105 +++
 2 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_net/rte_ptp.h

diff --git a/lib/librte_net/Makefile b/lib/librte_net/Makefile
index ad2e482..1d33618 100644
--- a/lib/librte_net/Makefile
+++ b/lib/librte_net/Makefile
@@ -34,7 +34,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3

 # install includes
-SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.h 
rte_sctp.h rte_icmp.h rte_arp.h
+SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.h 
rte_sctp.h rte_icmp.h rte_arp.h rte_ptp.h


 include $(RTE_SDK)/mk/rte.install.mk
diff --git a/lib/librte_net/rte_ptp.h b/lib/librte_net/rte_ptp.h
new file mode 100644
index 000..8a4c83c
--- /dev/null
+++ b/lib/librte_net/rte_ptp.h
@@ -0,0 +1,105 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define NSEC_PER_SEC 10L
+
+/*
+ * Structure for cyclecounter IEEE1588 functionality.
+ */
+struct cyclecounter {
+   uint64_t (*read)(struct rte_eth_dev *dev);
+   uint64_t mask;
+   uint32_t shift;
+};
+
+/*
+ * Structure to hold and calculate Unix epoch time.
+ */
+struct timecounter {
+   struct cyclecounter *cc;
+   uint64_t cycle_last;
+   uint64_t nsec;
+   uint64_t mask;
+   uint64_t frac;
+};
+
+
+/* Utility functions for PTP/IEEE1588 support. */
+
+static inline uint64_t
+timespec_to_ns(const struct timespec *ts)
+{
+   return ((uint64_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
+}
+
+static inline struct timespec
+ns_to_timespec(uint64_t nsec)
+{
+   struct timespec ts = {0, 0};
+
+   if (nsec == 0)
+   return ts;
+
+   ts.tv_sec = nsec / NSEC_PER_SEC;
+   ts.tv_nsec = nsec % NSEC_PER_SEC;
+
+   return ts;
+}
+
+/*
+ * Converts cycle counter cycles to nanoseconds.
+ */
+static inline uint64_t
+cyclecounter_cycles_to_ns(const struct cyclecounter *cc,
+ uint64_t cycles, uint64_t mask, uint64_t *frac)
+{
+   uint64_t ns;
+
+   /* Add fractional nanoseconds */
+   ns = cycles + *frac;
+   *frac = ns & mask;
+
+   /* Shift to get only nanoseconds. */
+   return ns >> cc->shift;
+}
+
+/*
+ * Like cyclecounter_cycles_to_ns(), but this is used when
+ * computing a time previous to the stored in the cycle counter.
+ */
+static inline uint64_t
+cyclecounter_cycles_to_ns_backwards(const struct cyclecounter *cc,
+  uint64_t cycles, uint64_t frac)
+{
+   return ((cycles - frac) >> cc->shift);
+}
-- 
2.1.0



[dpdk-dev] [PATCH v3 1/7] ethdev: add additional ieee1588 support functions

2015-11-03 Thread Daniel Mrzyglod
Add additional functions to support the existing IEEE1588
functionality.

* rte_eth_timesync_settime(), function to set the device clock time.
* rte_eth_timesync_gettime, function to get the device clock time.
* rte_eth_timesync_adjust, function to adjust the device clock time.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/rel_notes/release_2_2.rst   |  3 ++
 lib/librte_ether/rte_ethdev.c  | 36 +++
 lib/librte_ether/rte_ethdev.h  | 64 ++
 lib/librte_ether/rte_ether_version.map |  3 ++
 4 files changed, 106 insertions(+)

diff --git a/doc/guides/rel_notes/release_2_2.rst 
b/doc/guides/rel_notes/release_2_2.rst
index 16fcc89..09fd642 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -176,6 +176,9 @@ API Changes

 * The devargs union field virtual is renamed to virt for C++ compatibility.

+* Add new functions in ethdev to support IEEE1588: 
rte_eth_timesync_time_adjust()
+  rte_eth_timesync_time_get(), rte_eth_timesync_time_set()
+

 ABI Changes
 ---
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 58aaeb2..a1e7eac 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3171,6 +3171,42 @@ rte_eth_timesync_read_tx_timestamp(uint8_t port_id, 
struct timespec *timestamp)
 }

 int
+rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_adjust, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_adjust)(dev, delta);
+}
+
+int
+rte_eth_timesync_time_get(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_get, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_get)(dev, timestamp);
+}
+
+int
+rte_eth_timesync_time_set(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_set, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_set)(dev, timestamp);
+}
+
+int
 rte_eth_dev_get_reg_length(uint8_t port_id)
 {
struct rte_eth_dev *dev;
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 7cf4af8..75cc742 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1200,6 +1200,17 @@ typedef int (*eth_timesync_read_tx_timestamp_t)(struct 
rte_eth_dev *dev,
struct timespec *timestamp);
 /**< @internal Function used to read a TX IEEE1588/802.1AS timestamp. */

+typedef int (*eth_timesync_time_adjust)(struct rte_eth_dev *dev, int64_t);
+/**< @internal Function used to adjust device clock */
+
+typedef int (*eth_timesync_time_get)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock. */
+
+typedef int (*eth_timesync_time_set)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock */
+
 typedef int (*eth_get_reg_length_t)(struct rte_eth_dev *dev);
 /**< @internal Retrieve device register count  */

@@ -1394,6 +1405,12 @@ struct eth_dev_ops {

/** Get DCB information */
eth_get_dcb_info get_dcb_info;
+   /** Adjust the device clock */
+   eth_timesync_time_adjust timesync_time_adjust;
+   /** Get the device clock timespec */
+   eth_timesync_time_get timesync_time_get;
+   /** Set the device clock timespec */
+   eth_timesync_time_set timesync_time_set;
 };

 /**
@@ -3735,6 +3752,53 @@ extern int rte_eth_timesync_read_rx_timestamp(uint8_t 
port_id,
 extern int rte_eth_timesync_read_tx_timestamp(uint8_t port_id,
  struct timespec *timestamp);

+/**
+ * Adjust the timesync clock on an Ethernet device..
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param delta
+ *   The adjustment in nanoseconds
+ *
+ * @return
+ *   - 0: Success.
+ *   - -ENODEV: The port ID is invalid.
+ *   - -ENOTSUP: The function is not supported by the Ethernet driver.
+ */
+extern int rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta);
+
+/**
+ * Read the time from the timesync clock on an Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param time
+ *   Pointer to the timespec struct.
+ *
+ * @return
+ *   - 0: Success.
+ */
+extern int rte_eth_timesync_time_get(uint8_t port_id,
+   

[dpdk-dev] [PATCH v3 0/7] add sample ptp slave application

2015-11-03 Thread Daniel Mrzyglod
Add a sample application that acts as a PTP slave using the DPDK IEEE1588
functions.

Also add some additional IEEE1588 support functions to enable getting,
setting and adjusting the device time.

V2->V3:
PMD:
 - move common structures and functions for PTP protocol to librte_net/rte_ptp.h

V1->V2:
PMDs:
 - add support for e1000
 - add support for ixgbe
 - add support for i40
ethdev:
 - change function names to more proper.
Doc:
 - add documentation for ptpclient
sample:
 - add kernel adjustment option
 - add portmask option to provide portmask to aplication


Daniel Mrzyglod (5):
  ethdev: add additional ieee1588 support functions
  net: Add common PTP structures and functions
  ixgbe: add additional ieee1588 support functions
  example: PTP client slave minimal implementation
  doc: add a PTPCLIENT sample guide

Pablo de Lara (2):
  igb: add additional ieee1588 support functions
  i40e: add additional ieee1588 support functions

 MAINTAINERS|   3 +
 doc/guides/rel_notes/release_2_2.rst   |   8 +
 doc/guides/sample_app_ug/img/ptpclient.svg | 520 +++
 doc/guides/sample_app_ug/index.rst |   3 +
 doc/guides/sample_app_ug/ptpclient.rst | 324 
 drivers/net/e1000/e1000_ethdev.h   |   3 +
 drivers/net/e1000/igb_ethdev.c | 299 ++-
 drivers/net/i40e/i40e_ethdev.c | 192 ++-
 drivers/net/i40e/i40e_ethdev.h |   5 +
 drivers/net/ixgbe/ixgbe_ethdev.c   | 272 +-
 drivers/net/ixgbe/ixgbe_ethdev.h   |   3 +
 examples/Makefile  |   1 +
 examples/ptpclient/Makefile|  56 +++
 examples/ptpclient/ptpclient.c | 779 +
 lib/librte_ether/rte_ethdev.c  |  36 ++
 lib/librte_ether/rte_ethdev.h  |  64 +++
 lib/librte_ether/rte_ether_version.map |   3 +
 lib/librte_net/Makefile|   2 +-
 lib/librte_net/rte_ptp.h   | 105 
 19 files changed, 2636 insertions(+), 42 deletions(-)
 create mode 100644 doc/guides/sample_app_ug/img/ptpclient.svg
 create mode 100644 doc/guides/sample_app_ug/ptpclient.rst
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c
 create mode 100644 lib/librte_net/rte_ptp.h

-- 
2.1.0



[dpdk-dev] [PATCH v2 1/6] ethdev: add additional ieee1588 support functions

2015-10-30 Thread Daniel Mrzyglod
Add additional functions to support the existing IEEE1588
functionality.

* rte_eth_timesync_settime(), function to set the device clock time.
* rte_eth_timesync_gettime, function to get the device clock time.
* rte_eth_timesync_adjust, function to adjust the device clock time.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/rel_notes/release_2_2.rst   |  3 ++
 lib/librte_ether/rte_ethdev.c  | 36 +++
 lib/librte_ether/rte_ethdev.h  | 64 ++
 lib/librte_ether/rte_ether_version.map |  9 +
 4 files changed, 112 insertions(+)

diff --git a/doc/guides/rel_notes/release_2_2.rst 
b/doc/guides/rel_notes/release_2_2.rst
index 89e4d58..b83ef7f 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -123,6 +123,9 @@ API Changes

 * The devargs union field virtual is renamed to virt for C++ compatibility.

+* Add new functions in ethdev to support IEEE1588: 
rte_eth_timesync_time_adjust()
+  rte_eth_timesync_time_get(), rte_eth_timesync_time_set()
+

 ABI Changes
 ---
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index f593f6e..d7d2714 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3284,6 +3284,42 @@ rte_eth_timesync_read_tx_timestamp(uint8_t port_id, 
struct timespec *timestamp)
 }

 int
+rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_adjust, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_adjust)(dev, delta);
+}
+
+int
+rte_eth_timesync_time_get(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_get, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_get)(dev, timestamp);
+}
+
+int
+rte_eth_timesync_time_set(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_set, -ENOTSUP);
+   return (*dev->dev_ops->timesync_time_set)(dev, timestamp);
+}
+
+int
 rte_eth_dev_get_reg_length(uint8_t port_id)
 {
struct rte_eth_dev *dev;
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 8a8c82b..c639064 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1129,6 +1129,17 @@ typedef int (*eth_timesync_read_tx_timestamp_t)(struct 
rte_eth_dev *dev,
struct timespec *timestamp);
 /**< @internal Function used to read a TX IEEE1588/802.1AS timestamp. */

+typedef int (*eth_timesync_time_adjust)(struct rte_eth_dev *dev, int64_t);
+/**< @internal Function used to adjust device clock */
+
+typedef int (*eth_timesync_time_get)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock. */
+
+typedef int (*eth_timesync_time_set)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock */
+
 typedef int (*eth_get_reg_length_t)(struct rte_eth_dev *dev);
 /**< @internal Retrieve device register count  */

@@ -1312,6 +1323,12 @@ struct eth_dev_ops {
eth_timesync_read_rx_timestamp_t timesync_read_rx_timestamp;
/** Read the IEEE1588/802.1AS TX timestamp. */
eth_timesync_read_tx_timestamp_t timesync_read_tx_timestamp;
+   /** Adjust the device clock */
+   eth_timesync_time_adjust timesync_time_adjust;
+   /** Get the device clock timespec */
+   eth_timesync_time_get timesync_time_get;
+   /** Set the device clock timespec */
+   eth_timesync_time_set timesync_time_set;
 };

 /**
@@ -3598,6 +3615,53 @@ extern int rte_eth_timesync_read_rx_timestamp(uint8_t 
port_id,
 extern int rte_eth_timesync_read_tx_timestamp(uint8_t port_id,
  struct timespec *timestamp);

+/**
+ * Adjust the timesync clock on an Ethernet device..
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param delta
+ *   The adjustment in nanoseconds
+ *
+ * @return
+ *   - 0: Success.
+ *   - -ENODEV: The port ID is invalid.
+ *   - -ENOTSUP: The function is not supported by the Ethernet driver.
+ */
+extern int rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta);
+
+/**
+ * Read the time from the timesync clock on an Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param time
+ *   Pointer to the 

[dpdk-dev] [PATCH v2 0/6] add sample ptp slave application

2015-10-30 Thread Daniel Mrzyglod
Add a sample application that acts as a PTP slave using the DPDK IEEE1588
functions.

Also add some additional IEEE1588 support functions to enable getting,
setting and adjusting the device time.

V1->V2:
PMDs:
 - add support for e1000
 - add support for ixgbe
 - add support for i40
ethdev:
 - change function names to more proper.
Doc:
 - add documentation for ptpclient
sample:
 - add kernel adjustment option
 - add portmask option to provide portmask to aplication


Daniel Mrzyglod (4):
  ethdev: add additional ieee1588 support functions
  ixgbe: add additional ieee1588 support functions
  example: PTP client slave minimal implementation
  doc: add a PTPCLIENT sample guide

Pablo de Lara (2):
  igb: add additional ieee1588 support functions
  i40e: add additional ieee1588 support functions

 MAINTAINERS|   3 +
 doc/guides/rel_notes/release_2_2.rst   |   8 +
 doc/guides/sample_app_ug/img/ptpclient.svg | 520 +++
 doc/guides/sample_app_ug/index.rst |   3 +
 doc/guides/sample_app_ug/ptpclient.rst | 324 
 drivers/net/e1000/e1000_ethdev.h   |  22 +
 drivers/net/e1000/igb_ethdev.c | 338 -
 drivers/net/i40e/i40e_ethdev.c | 214 +++-
 drivers/net/i40e/i40e_ethdev.h |  18 +
 drivers/net/ixgbe/ixgbe_ethdev.c   | 313 +++-
 drivers/net/ixgbe/ixgbe_ethdev.h   |  22 +
 examples/Makefile  |   1 +
 examples/ptpclient/Makefile|  57 +++
 examples/ptpclient/ptpclient.c | 788 +
 lib/librte_ether/rte_ethdev.c  |  36 ++
 lib/librte_ether/rte_ethdev.h  |  64 +++
 lib/librte_ether/rte_ether_version.map |   9 +
 17 files changed, 2699 insertions(+), 41 deletions(-)
 create mode 100644 doc/guides/sample_app_ug/img/ptpclient.svg
 create mode 100644 doc/guides/sample_app_ug/ptpclient.rst
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c

-- 
2.1.0



[dpdk-dev] [PATCH 3/3] example: PTP client slave minimal implementation

2015-10-02 Thread Daniel Mrzyglod
Add a sample application that acts as a PTP slave using the
DPDK ieee1588 functions.

Signed-off-by: Daniel Mrzyglod 
---
 MAINTAINERS|   3 +
 examples/Makefile  |   1 +
 examples/ptpclient/Makefile|  59 +
 examples/ptpclient/ptpclient.c | 525 +
 4 files changed, 588 insertions(+)
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 080a8e8..a80ce96 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -514,3 +514,6 @@ F: examples/tep_termination/
 F: examples/vmdq/
 F: examples/vmdq_dcb/
 F: doc/guides/sample_app_ug/vmdq_dcb_forwarding.rst
+
+M: Daniel Mrzyglod 
+F: examples/ptpclient
\ No newline at end of file
diff --git a/examples/Makefile b/examples/Makefile
index b4eddbd..4672534 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -74,5 +74,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_XEN_DOM0) += vhost_xen
 DIRS-y += vmdq
 DIRS-y += vmdq_dcb
 DIRS-$(CONFIG_RTE_LIBRTE_POWER) += vm_power_manager
+DIRS-$(CONFIG_RTE_LIBRTE_IEEE1588) += ptpclient

 include $(RTE_SDK)/mk/rte.extsubdir.mk
diff --git a/examples/ptpclient/Makefile b/examples/ptpclient/Makefile
new file mode 100644
index 000..503339f
--- /dev/null
+++ b/examples/ptpclient/Makefile
@@ -0,0 +1,59 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriddegitn by command line or environment
+RTE_TARGET ?= x86_64-native-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = ptpclient
+
+# all source are stored in SRCS-y
+SRCS-y := ptpclient.c
+#SRCS-$(CONFIG_RTE_LIBRTE_IEEE1588) := ptpclient.c
+
+
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+EXTRA_CFLAGS += -O3
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c
new file mode 100644
index 000..1fe8e6d
--- /dev/null
+++ b/examples/ptpclient/ptpclient.c
@@ -0,0 +1,525 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES 

[dpdk-dev] [PATCH 2/3] ixgbe: add additional ieee1588 support functions

2015-10-02 Thread Daniel Mrzyglod
Add additional functions to support the existing IEEE1588
functionality and to enable getting, setting and adjusting
the device time.

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 250 +--
 drivers/net/ixgbe/ixgbe_ethdev.h |  24 
 2 files changed, 263 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index ec2918c..d0c575f 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -126,10 +126,12 @@
 #define IXGBE_HKEY_MAX_INDEX 10

 /* Additional timesync values. */
-#define IXGBE_TIMINCA_16NS_SHIFT 24
-#define IXGBE_TIMINCA_INCVALUE   1600
-#define IXGBE_TIMINCA_INIT   ((0x02 << IXGBE_TIMINCA_16NS_SHIFT) \
- | IXGBE_TIMINCA_INCVALUE)
+#define NSEC_PER_SEC 10L
+#define IXGBE_INCVAL_10GB0x
+#define IXGBE_INCVAL_SHIFT_10GB  28
+#define IXGBE_INCVAL_SHIFT_82599 7
+#define IXGBE_INCPER_SHIFT_82599 24
+#define IXGBE_CYCLECOUTER_MASK   0x

 static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev);
@@ -325,6 +327,11 @@ static int ixgbe_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
uint32_t flags);
 static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
struct timespec *timestamp);
+static int ixgbe_timesync_adjust(struct rte_eth_dev *dev, int64_t delta);
+static int ixgbe_timesync_gettime(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+static int ixgbe_timesync_settime(struct rte_eth_dev *dev,
+   struct timespec *timestamp);

 /*
  * Define VF Stats MACRO for Non "cleared on read" register
@@ -465,6 +472,9 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = {
.get_eeprom_length= ixgbe_get_eeprom_length,
.get_eeprom   = ixgbe_get_eeprom,
.set_eeprom   = ixgbe_set_eeprom,
+   .timesync_adjust = ixgbe_timesync_adjust,
+   .timesync_gettime = ixgbe_timesync_gettime,
+   .timesync_settime = ixgbe_timesync_settime,
 };

 /*
@@ -5241,20 +5251,223 @@ ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
 ixgbe_dev_addr_list_itr, TRUE);
 }

+static inline uint64_t
+timespec_to_ns(const struct timespec *ts)
+{
+   return ((uint64_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
+}
+
+static struct timespec
+ns_to_timespec(int64_t nsec)
+{
+struct timespec ts = {0, 0};
+int32_t rem;
+
+if (nsec == 0)
+return ts;
+rem = nsec % NSEC_PER_SEC;
+ts.tv_sec = nsec / NSEC_PER_SEC;
+
+if (unlikely(rem < 0)) {
+ts.tv_sec--;
+rem += NSEC_PER_SEC;
+}
+
+ts.tv_nsec = rem;
+
+return ts;
+}
+
+static inline uint64_t
+cyclecounter_cycles_to_ns(const struct cyclecounter *cc,
+ uint64_t cycles, uint64_t mask, uint64_t 
*frac)
+{
+   uint64_t ns = cycles;
+
+   ns = (ns * cc->mult) + *frac;
+   *frac = ns & mask;
+   return ns >> cc->shift;
+}
+
+static uint64_t
+cyclecounter_cycles_to_ns_backwards(const struct cyclecounter *cc,
+  uint64_t cycles, uint64_t mask __rte_unused, 
uint64_t frac)
+{
+   uint64_t ns = (uint64_t) cycles;
+
+   ns = ((ns * cc->mult) - frac) >> cc->shift;
+
+   return ns;
+}
+
+static uint64_t
+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)
+{
+   uint64_t delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
+   uint64_t nsec = tc->nsec, frac = tc->frac;
+
+
+   /* Cycle counts that are corectly converted as they
+* are between -1/2 max cycle count and +1/2max cycle count
+* */
+   if (delta > tc->cc->mask / 2) {
+   delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
+   nsec -= cyclecounter_cycles_to_ns_backwards(tc->cc, delta, 
tc->mask, frac);
+   } else {
+   nsec += cyclecounter_cycles_to_ns(tc->cc, delta, tc->mask, 
);
+   }
+
+   return nsec;
+}
+
+static uint64_t
+ixgbe_read_timesync_cyclecounter(struct rte_eth_dev *dev)
+{
+   struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   uint64_t systim_cycles = 0;
+
+   systim_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
+   systim_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH) << 32;
+
+   return systim_cycles;
+}
+
+static uint64_t
+timecounter_read_ns_delta(struct rte_eth_dev *dev)
+{
+   uint64_t cycle_now, cycle_delta;
+   uint64_t ns_offset;
+   struct ixgbe_adapter *ada

[dpdk-dev] [PATCH 1/3] ethdev: add additional ieee1588 support functions

2015-10-02 Thread Daniel Mrzyglod
Add additional functions to support the existing IEEE1588
functionality.

* rte_eth_timesync_settime(), function to set the device clock time.
* rte_eth_timesync_gettime, function to get the device clock time.
* rte_eth_timesync_adjust, function to adjust the device clock time.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_ether/rte_ethdev.c  | 36 +++
 lib/librte_ether/rte_ethdev.h  | 64 ++
 lib/librte_ether/rte_ether_version.map |  9 +
 3 files changed, 109 insertions(+)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index f593f6e..6f26f3a 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3272,6 +3272,42 @@ rte_eth_timesync_read_rx_timestamp(uint8_t port_id, 
struct timespec *timestamp,
 }

 int
+rte_eth_timesync_adjust(uint8_t port_id, int64_t delta)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust, -ENOTSUP);
+   return (*dev->dev_ops->timesync_adjust)(dev, delta);
+}
+
+int
+rte_eth_timesync_gettime(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_gettime, -ENOTSUP);
+   return (*dev->dev_ops->timesync_gettime)(dev, timestamp);
+}
+
+int
+rte_eth_timesync_settime(uint8_t port_id, struct timespec *timestamp)
+{
+   struct rte_eth_dev *dev;
+
+   VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+   dev = _eth_devices[port_id];
+
+   FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_settime, -ENOTSUP);
+   return (*dev->dev_ops->timesync_settime)(dev, timestamp);
+}
+
+int
 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
 {
struct rte_eth_dev *dev;
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 8a8c82b..6fdaacd 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1129,6 +1129,17 @@ typedef int (*eth_timesync_read_tx_timestamp_t)(struct 
rte_eth_dev *dev,
struct timespec *timestamp);
 /**< @internal Function used to read a TX IEEE1588/802.1AS timestamp. */

+typedef int (*eth_timesync_adjust)(struct rte_eth_dev *dev, int64_t);
+/**< @internal Function used to adjust device clock */
+
+typedef int (*eth_timesync_gettime)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock. */
+
+typedef int (*eth_timesync_settime)(struct rte_eth_dev *dev,
+   struct timespec *timestamp);
+/**< @internal Function used to get time from device clock */
+
 typedef int (*eth_get_reg_length_t)(struct rte_eth_dev *dev);
 /**< @internal Retrieve device register count  */

@@ -1312,6 +1323,12 @@ struct eth_dev_ops {
eth_timesync_read_rx_timestamp_t timesync_read_rx_timestamp;
/** Read the IEEE1588/802.1AS TX timestamp. */
eth_timesync_read_tx_timestamp_t timesync_read_tx_timestamp;
+   /** Adjust the device clock */
+   eth_timesync_adjust timesync_adjust;
+   /** Get the device clock timespec */
+   eth_timesync_gettime timesync_gettime;
+   /** Set the device clock timespec */
+   eth_timesync_settime timesync_settime;
 };

 /**
@@ -3598,6 +3615,53 @@ extern int rte_eth_timesync_read_rx_timestamp(uint8_t 
port_id,
 extern int rte_eth_timesync_read_tx_timestamp(uint8_t port_id,
  struct timespec *timestamp);

+/**
+ * Adjust the timesync clock on an Ethernet device..
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param delta
+ *   The adjustment in nanoseconds
+ *
+ * @return
+ *   - 0: Success.
+ *   - -ENODEV: The port ID is invalid.
+ *   - -ENOTSUP: The function is not supported by the Ethernet driver.
+ */
+extern int rte_eth_timesync_adjust(uint8_t port_id, int64_t delta);
+
+/**
+ * Read the time from the timesync clock on an Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param time
+ *   Pointer to the timespec struct.
+ *
+ * @return
+ *   - 0: Success.
+ */
+extern int rte_eth_timesync_gettime(uint8_t port_id,
+ struct timespec *time);
+
+
+/**
+ * Set the time of the timesync clock on an Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param time
+ *   Pointer to the timespec struct.
+ *
+ * @return
+ *   - 0: Success.
+ *   - -EINVAL: No timestamp is available.
+ *   - -ENODEV: The port ID is invalid.
+ *   - -ENOTSUP: The function is not supported by the Ethernet driver.
+ */
+

[dpdk-dev] [PATCH 0/3] add sample ptp slave application

2015-10-02 Thread Daniel Mrzyglod
Add a sample application that acts as a PTP slave using the DPDK IEEE1588
functions.

Also add some additional IEEE1588 support functions to enable getting,
setting and adjusting the device time.

Some V1 limitations of the app:

* The mater clock sequence id and clock id are not verified fully.
* Only one master clock is supported/assumed.

To be added:

* Support for igb and i40e.
* Multiple checks on clock source.
* Some additional protocol values may be required to be parsed for more
  complex PTP environments.
* Add frequency adjustment as well as absolute time adjustment.
* Make the implementation NIC speed independent.
* Check for linkup/down.




Daniel Mrzyglod (3):
  ethdev: add additional ieee1588 support functions
  ixgbe: add additional ieee1588 support functions
  example: PTP client slave minimal implementation

 MAINTAINERS|   3 +
 drivers/net/ixgbe/ixgbe_ethdev.c   | 250 +++-
 drivers/net/ixgbe/ixgbe_ethdev.h   |  24 ++
 examples/Makefile  |   1 +
 examples/ptpclient/Makefile|  59 
 examples/ptpclient/ptpclient.c | 525 +
 lib/librte_ether/rte_ethdev.c  |  36 +++
 lib/librte_ether/rte_ethdev.h  |  64 
 lib/librte_ether/rte_ether_version.map |   9 +
 9 files changed, 960 insertions(+), 11 deletions(-)
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c

-- 
2.1.0



[dpdk-dev] [PATCH v3] cfgfile: fix unitialised buffer

2015-06-29 Thread Daniel Mrzyglod
Nature of the problem was not initialised buffer[256], there were probability
that operation system will provide previously used memory and on special 
condition
there were probability that string operations will work on random data that
could provide unexpected program behaviour.

Changes in v3:
-Simplify the initialization of buffer.
Changes in v2:
-Found the real nature of problem. Only buffer was not initilized.
Changes in v1:
-Add additional separate IO buffer and initialize both buffers.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_cfgfile/rte_cfgfile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index b81c273..a677dad 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -92,7 +92,7 @@ rte_cfgfile_load(const char *filename, int flags)
int allocated_entries = 0;
int curr_section = -1;
int curr_entry = -1;
-   char buffer[256];
+   char buffer[256] = {0};
int lineno = 0;
struct rte_cfgfile *cfg = NULL;

-- 
2.1.0



[dpdk-dev] [PATCH] cfgfile: fix unitialised buffer and improve reading from nfs filesystem.

2015-06-26 Thread Daniel Mrzyglod
Nature of the problem was not initialised buffer[256] on special condition
there were probability that program will work on unitialised data that
could provide unexpected program behaviour.

Adding additional transparent I/O buffer for I/O operations
improve reading on heavyloaded enviroments with NFS.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_cfgfile/rte_cfgfile.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index b81c273..88fcb46 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -93,10 +93,14 @@ rte_cfgfile_load(const char *filename, int flags)
int curr_section = -1;
int curr_entry = -1;
char buffer[256];
+   char f_streambuff[BUFSIZ];
int lineno = 0;
struct rte_cfgfile *cfg = NULL;
+   memset(buffer, '\0', 256*sizeof(char));
+   memset(f_streambuff, '\0', BUFSIZ);

FILE *f = fopen(filename, "r");
+   setbuf(f, f_streambuff);
if (f == NULL)
return NULL;

-- 
2.1.0



[dpdk-dev] [PATCH] cfgfile: Fix for Reading Files on nfs filesystem.

2015-06-24 Thread Daniel Mrzyglod
The problem occure when we have config files on NFS filesystem.
Solution with minimal change to library is to add buffer for I/O operations.
Without buffering there is  3-10% of faulty Reading from NFS.

The problem seems to be only NFS filesystem.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_cfgfile/rte_cfgfile.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index b81c273..6105e0c 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -93,10 +93,13 @@ rte_cfgfile_load(const char *filename, int flags)
int curr_section = -1;
int curr_entry = -1;
char buffer[256];
+   char f_streambuff[BUFSIZ];
int lineno = 0;
struct rte_cfgfile *cfg = NULL;
+   memset(f_streambuff,'\0',BUFSIZ);

FILE *f = fopen(filename, "r");
+   setbuf( f, f_streambuff);
if (f == NULL)
return NULL;

-- 
2.1.0



[dpdk-dev] [PATCH] lib: fix RTE_MBUF_METADATA macros

2015-06-05 Thread Daniel Mrzyglod
Fix RTE_MBUF_METADATA macros to allow for unaligned accesses to
meta-data fields.
Forcing aligned accesses is not really required, so this is removing an
unneeded constraint.
This issue was met during testing of the new version of the ip_pipeline
application. There is no performance impact.
This change has no ABI impact, as the previous code that uses aligned
accesses continues to run without any issues.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_pipeline/rte_pipeline.c  |  8 
 lib/librte_port/rte_port.h  | 26 +-
 lib/librte_table/rte_table_array.c  |  4 +---
 lib/librte_table/rte_table_hash_ext.c   | 13 -
 lib/librte_table/rte_table_hash_key16.c | 24 
 lib/librte_table/rte_table_hash_key32.c | 24 
 lib/librte_table/rte_table_hash_key8.c  | 24 
 lib/librte_table/rte_table_hash_lru.c   | 13 -
 lib/librte_table/rte_table_lpm.c|  4 
 lib/librte_table/rte_table_lpm_ipv6.c   |  4 
 10 files changed, 14 insertions(+), 130 deletions(-)

diff --git a/lib/librte_pipeline/rte_pipeline.c 
b/lib/librte_pipeline/rte_pipeline.c
index 36d92c9..b777cf1 100644
--- a/lib/librte_pipeline/rte_pipeline.c
+++ b/lib/librte_pipeline/rte_pipeline.c
@@ -175,14 +175,6 @@ rte_pipeline_check_params(struct rte_pipeline_params 
*params)
return -EINVAL;
}

-   /* offset_port_id */
-   if (params->offset_port_id & 0x3) {
-   RTE_LOG(ERR, PIPELINE,
-   "%s: Incorrect value for parameter offset_port_id\n",
-   __func__);
-   return -EINVAL;
-   }
-
return 0;
 }

diff --git a/lib/librte_port/rte_port.h b/lib/librte_port/rte_port.h
index d84e5a1..c3a0cca 100644
--- a/lib/librte_port/rte_port.h
+++ b/lib/librte_port/rte_port.h
@@ -54,23 +54,23 @@ extern "C" {
  * Macros to allow accessing metadata stored in the mbuf headroom
  * just beyond the end of the mbuf data structure returned by a port
  */
-#define RTE_MBUF_METADATA_UINT8(mbuf, offset)  \
-   (((uint8_t *)&(mbuf)[1])[offset])
-#define RTE_MBUF_METADATA_UINT16(mbuf, offset) \
-   (((uint16_t *)&(mbuf)[1])[offset/sizeof(uint16_t)])
-#define RTE_MBUF_METADATA_UINT32(mbuf, offset) \
-   (((uint32_t *)&(mbuf)[1])[offset/sizeof(uint32_t)])
-#define RTE_MBUF_METADATA_UINT64(mbuf, offset) \
-   (((uint64_t *)&(mbuf)[1])[offset/sizeof(uint64_t)])
-
 #define RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)  \
-   (_MBUF_METADATA_UINT8(mbuf, offset))
+   (&((uint8_t *) &(mbuf)[1])[offset])
 #define RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset) \
-   (_MBUF_METADATA_UINT16(mbuf, offset))
+   ((uint16_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
 #define RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset) \
-   (_MBUF_METADATA_UINT32(mbuf, offset))
+   ((uint32_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
 #define RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset) \
-   (_MBUF_METADATA_UINT64(mbuf, offset))
+   ((uint64_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
+
+#define RTE_MBUF_METADATA_UINT8(mbuf, offset)  \
+   (* RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
+#define RTE_MBUF_METADATA_UINT16(mbuf, offset) \
+   (* RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset))
+#define RTE_MBUF_METADATA_UINT32(mbuf, offset) \
+   (* RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset))
+#define RTE_MBUF_METADATA_UINT64(mbuf, offset) \
+   (* RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset))
 /**@}*/

 /*
diff --git a/lib/librte_table/rte_table_array.c 
b/lib/librte_table/rte_table_array.c
index c031070..b00ca67 100644
--- a/lib/librte_table/rte_table_array.c
+++ b/lib/librte_table/rte_table_array.c
@@ -66,10 +66,8 @@ rte_table_array_create(void *params, int socket_id, uint32_t 
entry_size)
/* Check input parameters */
if ((p == NULL) ||
(p->n_entries == 0) ||
-   (!rte_is_power_of_2(p->n_entries)) ||
-   ((p->offset & 0x3) != 0)) {
+   (!rte_is_power_of_2(p->n_entries)))
return NULL;
-   }

/* Memory allocation */
total_cl_size = (sizeof(struct rte_table_array) +
diff --git a/lib/librte_table/rte_table_hash_ext.c 
b/lib/librte_table/rte_table_hash_ext.c
index 66e416b..73beeaf 100644
--- a/lib/librte_table/rte_table_hash_ext.c
+++ b/lib/librte_table/rte_table_hash_ext.c
@@ -149,19 +149,6 @@ check_params_create(struct rte_table_hash_ext_params 
*params)
return -EINVAL;
}

-   /* signature offset */
-   if ((params->signature_offset & 0x3) != 0) {
-   RTE_LOG(ERR, TABLE, "%s: signature_offset invalid value\n",
-   __func__);
-   

[dpdk-dev] [PATCH] cmdline: fix type format from unsigned to size_t for buffer size

2015-02-20 Thread Daniel Mrzyglod
Function match_inst is used to take buffor using sizeof() which is size_t type.
This modification also involved changing '%u' to '%zu' in printf function.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_cmdline/cmdline_parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/librte_cmdline/cmdline_parse.c 
b/lib/librte_cmdline/cmdline_parse.c
index dfc885c..0821791 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -138,7 +138,7 @@ nb_common_chars(const char * s1, const char * s2)
  */
 static int
 match_inst(cmdline_parse_inst_t *inst, const char *buf,
-  unsigned int nb_match_token, void *resbuf, unsigned resbuf_size)
+  unsigned int nb_match_token, void *resbuf, size_t resbuf_size)
 {
unsigned int token_num=0;
cmdline_parse_token_hdr_t * token_p;
@@ -169,7 +169,7 @@ match_inst(cmdline_parse_inst_t *inst, const char *buf,

if (token_hdr.offset > resbuf_size) {
printf("Parse error(%s:%d): Token offset(%u) "
-   "exceeds maximum size(%u)\n",
+   "exceeds maximum size(%zu)\n",
__FILE__, __LINE__,
token_hdr.offset, resbuf_size);
return -ENOBUFS;
-- 
2.1.0



[dpdk-dev] [PATCH v2] doc: Add requirements for x32 ABI

2015-02-16 Thread Daniel Mrzyglod
This patch add requirements about compiler and distribution support.

v2:
spelling fixes

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/linux_gsg/sys_reqs.rst | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/doc/guides/linux_gsg/sys_reqs.rst 
b/doc/guides/linux_gsg/sys_reqs.rst
index 8e2307b..ef4196e 100644
--- a/doc/guides/linux_gsg/sys_reqs.rst
+++ b/doc/guides/linux_gsg/sys_reqs.rst
@@ -62,7 +62,7 @@ Compilation of the DPDK
 *   coreutils:  cmp, sed, grep, arch

 *   gcc: versions 4.5.x or later is recommended for i686/x86_64. versions 
4.8.x or later is recommanded
-for ppc_64. On some distributions, some specific compiler flags and linker 
flags are enabled by
+for ppc_64 and x86_x32 ABI. On some distributions, some specific compiler 
flags and linker flags are enabled by
 default and affect performance (- fstack-protector, for example). Please 
refer to the documentation
 of your distribution and to gcc -dumpspecs.

@@ -78,7 +78,14 @@ Compilation of the DPDK

 glibc.ppc64, libgcc.ppc64, libstdc++.ppc64 and glibc-devel.ppc64 for IBM 
ppc_64;

-*   Python, version 2.6 or 2.7, to use various helper scripts included in the 
DPDK package
+.. note::
+
+x86_x32 ABI is currently supported with distribution packages only on 
Ubuntu
+higher than 13.10 or recent debian distribution. The only supported  
compiler is gcc 4.8+.
+
+.. note::
+
+Python, version 2.6 or 2.7, to use various helper scripts included in the 
DPDK package


 **Optional Tools:**
-- 
2.1.0



[dpdk-dev] [PATCH] doc: Add requirements for x32 ABI

2015-02-13 Thread Daniel Mrzyglod
This patch add requirements about compiler and distribution support.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/linux_gsg/sys_reqs.rst | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/doc/guides/linux_gsg/sys_reqs.rst 
b/doc/guides/linux_gsg/sys_reqs.rst
index 8e2307b..ef4196e 100644
--- a/doc/guides/linux_gsg/sys_reqs.rst
+++ b/doc/guides/linux_gsg/sys_reqs.rst
@@ -62,7 +62,7 @@ Compilation of the DPDK
 *   coreutils:  cmp, sed, grep, arch

 *   gcc: versions 4.5.x or later is recommended for i686/x86_64. versions 
4.8.x or later is recommanded
-for ppc_64. On some distributions, some specific compiler flags and linker 
flags are enabled by
+for ppc_64 and x86_x32 ABI. On some distributions, some specific compiler 
flags and linker flags are enabled by
 default and affect performance (- fstack-protector, for example). Please 
refer to the documentation
 of your distribution and to gcc -dumpspecs.

@@ -78,7 +78,14 @@ Compilation of the DPDK

 glibc.ppc64, libgcc.ppc64, libstdc++.ppc64 and glibc-devel.ppc64 for IBM 
ppc_64;

-*   Python, version 2.6 or 2.7, to use various helper scripts included in the 
DPDK package
+.. note::
+
+x86_x32 ABI is currently supported with distribution packages only on 
Ubuntu
+higher then 13.10 or recent debian distribution. The only supported  
compiler is gcc 4.8+.
+
+.. note::
+
+Python, version 2.6 or 2.7, to use various helper scripts included in the 
DPDK package


 **Optional Tools:**
-- 
2.1.0



[dpdk-dev] [PATCH v4] test: fix missing NULL pointer checks

2015-01-30 Thread Daniel Mrzyglod
In test_sched, we are missing NULL pointer checks after create_mempool()
and rte_pktmbuf_alloc(). Add in these checks using TEST_ASSERT_NOT_NULL
macros.

VERIFY macro was removed and replaced by standard test ASSERTS from
"test.h" header.
This provides additional information to track when the failure occured.

v4 changes:
-If test fails add cleanup routines
-Change Magic Numbers to dedicated Macro RTE_DIM

v3 changes:
- remove VERIFY macro
- fix spelling error.
- change unproper comment

v2 changes:
- Replace all VERIFY macros instances by proper TEST_ASSERT* macros.
- fix description

v1 changes:
- first iteration of patch using VERIFY macro.

Signed-off-by: Daniel Mrzyglod 
---
 app/test/test_sched.c | 120 ++
 1 file changed, 83 insertions(+), 37 deletions(-)

diff --git a/app/test/test_sched.c b/app/test/test_sched.c
index c957d80..6a97e2c 100644
--- a/app/test/test_sched.c
+++ b/app/test/test_sched.c
@@ -44,14 +44,7 @@
 #include 
 #include 
 #include 
-
-
-#define VERIFY(exp,fmt,args...)\
-   if (!(exp)) {   \
-   printf(fmt, ##args);
\
-   return -1;  
\
-   }
-
+#include 

 #define SUBPORT0
 #define PIPE   1
@@ -92,6 +85,10 @@ static struct rte_sched_port_params port_param = {
.n_pipe_profiles = 1,
 };

+static struct rte_sched_port *port = NULL;
+static struct rte_mbuf *in_mbufs[10];
+static struct rte_mempool *mp = NULL;
+
 #define NB_MBUF  32
 #define MAX_PACKET_SZ2048
 #define MBUF_SZ (MAX_PACKET_SZ + sizeof(struct rte_mbuf) + 
RTE_PKTMBUF_HEADROOM)
@@ -128,7 +125,6 @@ prepare_pkt(struct rte_mbuf *mbuf)
struct ether_hdr *eth_hdr;
struct vlan_hdr *vlan1, *vlan2;
struct ipv4_hdr *ip_hdr;
-
/* Simulate a classifier */
eth_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
vlan1 = (struct vlan_hdr *)(_hdr->ether_type );
@@ -150,64 +146,71 @@ prepare_pkt(struct rte_mbuf *mbuf)
 }


+static void
+clean_environment(void)
+{
+   uint32_t i;
+
+   port = NULL;
+   for (i = 0; i < RTE_DIM(in_mbufs); i++) {
+   if (in_mbufs[i] != NULL) {
+   rte_pktmbuf_free(in_mbufs[i]);
+   in_mbufs[i] = NULL;
+   }
+   }
+}
+
 /**
  * test main entrance for library sched
  */
 static int
 test_sched(void)
 {
-   struct rte_mempool *mp = NULL;
-   struct rte_sched_port *port = NULL;
uint32_t pipe;
-   struct rte_mbuf *in_mbufs[10];
+   uint32_t i;
struct rte_mbuf *out_mbufs[10];
-   int i;
-
int err;

-   mp = create_mempool();
-
port_param.socket = 0;
port_param.rate = (uint64_t) 1 * 1000 * 1000 / 8;

port = rte_sched_port_config(_param);
-   VERIFY(port != NULL, "Error config sched port\n");
-
+   TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");

err = rte_sched_subport_config(port, SUBPORT, subport_param);
-   VERIFY(err == 0, "Error config sched, err=%d\n", err);
+   TEST_ASSERT_SUCCESS(err, "Error config sched, err=%d\n", err);

for (pipe = 0; pipe < port_param.n_pipes_per_subport; pipe ++) {
err = rte_sched_pipe_config(port, SUBPORT, pipe, 0);
-   VERIFY(err == 0, "Error config sched pipe %u, err=%d\n", pipe, 
err);
+   TEST_ASSERT_SUCCESS(err, "Error config sched pipe %u, 
err=%d\n", pipe, err);
}

-   for (i = 0; i < 10; i++) {
+   for (i = 0; i < RTE_DIM(in_mbufs); i++) {
in_mbufs[i] = rte_pktmbuf_alloc(mp);
+   TEST_ASSERT_NOT_NULL(in_mbufs[i], "Packet allocation failed\n");
prepare_pkt(in_mbufs[i]);
}

+   err = rte_sched_port_enqueue(port, in_mbufs, RTE_DIM(in_mbufs));
+   TEST_ASSERT_EQUAL(err, RTE_DIM(in_mbufs), "Wrong enqueue, err=%d\n", 
err);

-   err = rte_sched_port_enqueue(port, in_mbufs, 10);
-   VERIFY(err == 10, "Wrong enqueue, err=%d\n", err);
-
-   err = rte_sched_port_dequeue(port, out_mbufs, 10);
-   VERIFY(err == 10, "Wrong dequeue, err=%d\n", err);
+   err = rte_sched_port_dequeue(port, out_mbufs, RTE_DIM(out_mbufs));
+   TEST_ASSERT_EQUAL(err, RTE_DIM(out_mbufs), "Wrong dequeue, err=%d\n", 
err);

-   for (i = 0; i < 10; i++) {
+   for (i = 0; i < RTE_DIM(out_mbufs); i++) {
enum rte_meter_color color;
uint32_t subport, traffic_class, queue;

color = rte_sched_port_pkt_read_color(out_mbufs[i]);
-   VERIFY(color == e_RTE_METER_YELLOW, "Wrong color\n");
+   TEST_ASSERT_EQUAL(c

[dpdk-dev] [PATCH v3] test: fix missing NULL pointer checks

2015-01-27 Thread Daniel Mrzyglod
In test_sched, we are missing NULL pointer checks after create_mempool()
and rte_pktmbuf_alloc(). Add in these checks using TEST_ASSERT_NOT_NULL macros.

VERIFY macro was removed and replaced by standard test ASSERTS from "test.h" 
header.
This provides additional information to track when the failure occured.

v3 changes:
- remove VERIFY macro
- fix spelling error.
- change unproper comment

v2 changes:
- Replace all VERIFY macros instances by proper TEST_ASSERT* macros.
- fix description

v1 changes:
- first iteration of patch using VERIFY macro.

Signed-off-by: Daniel Mrzyglod 
---
 app/test/test_sched.c | 39 ++-
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/app/test/test_sched.c b/app/test/test_sched.c
index c957d80..60c62de 100644
--- a/app/test/test_sched.c
+++ b/app/test/test_sched.c
@@ -46,13 +46,6 @@
 #include 


-#define VERIFY(exp,fmt,args...)\
-   if (!(exp)) {   \
-   printf(fmt, ##args);
\
-   return -1;  
\
-   }
-
-
 #define SUBPORT0
 #define PIPE   1
 #define TC 2
@@ -166,48 +159,49 @@ test_sched(void)
int err;

mp = create_mempool();
+   TEST_ASSERT_NOT_NULL(mp, "Error creating mempool\n");

port_param.socket = 0;
port_param.rate = (uint64_t) 1 * 1000 * 1000 / 8;

port = rte_sched_port_config(_param);
-   VERIFY(port != NULL, "Error config sched port\n");
-
+   TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");

err = rte_sched_subport_config(port, SUBPORT, subport_param);
-   VERIFY(err == 0, "Error config sched, err=%d\n", err);
+   TEST_ASSERT_SUCCESS(err, "Error config sched, err=%d\n", err);

for (pipe = 0; pipe < port_param.n_pipes_per_subport; pipe ++) {
err = rte_sched_pipe_config(port, SUBPORT, pipe, 0);
-   VERIFY(err == 0, "Error config sched pipe %u, err=%d\n", pipe, 
err);
+   TEST_ASSERT_SUCCESS(err, "Error config sched pipe %u, 
err=%d\n", pipe, err);
}

for (i = 0; i < 10; i++) {
in_mbufs[i] = rte_pktmbuf_alloc(mp);
+   TEST_ASSERT_NOT_NULL(in_mbufs[i], "Packet allocation failed\n");
prepare_pkt(in_mbufs[i]);
}


err = rte_sched_port_enqueue(port, in_mbufs, 10);
-   VERIFY(err == 10, "Wrong enqueue, err=%d\n", err);
+   TEST_ASSERT_EQUAL(err, 10, "Wrong enqueue, err=%d\n", err);

err = rte_sched_port_dequeue(port, out_mbufs, 10);
-   VERIFY(err == 10, "Wrong dequeue, err=%d\n", err);
+   TEST_ASSERT_EQUAL(err, 10, "Wrong dequeue, err=%d\n", err);

for (i = 0; i < 10; i++) {
enum rte_meter_color color;
uint32_t subport, traffic_class, queue;

color = rte_sched_port_pkt_read_color(out_mbufs[i]);
-   VERIFY(color == e_RTE_METER_YELLOW, "Wrong color\n");
+   TEST_ASSERT_EQUAL(color, e_RTE_METER_YELLOW, "Wrong color\n");

rte_sched_port_pkt_read_tree_path(out_mbufs[i],
, , _class, );

-   VERIFY(subport == SUBPORT, "Wrong subport\n");
-   VERIFY(pipe == PIPE, "Wrong pipe\n");
-   VERIFY(traffic_class == TC, "Wrong traffic_class\n");
-   VERIFY(queue == QUEUE, "Wrong queue\n");
+   TEST_ASSERT_EQUAL(subport, SUBPORT, "Wrong subport\n");
+   TEST_ASSERT_EQUAL(pipe, PIPE, "Wrong pipe\n");
+   TEST_ASSERT_EQUAL(traffic_class, TC, "Wrong traffic_class\n");
+   TEST_ASSERT_EQUAL(queue, QUEUE, "Wrong queue\n");

}

@@ -215,12 +209,15 @@ test_sched(void)
struct rte_sched_subport_stats subport_stats;
uint32_t tc_ov;
rte_sched_subport_read_stats(port, SUBPORT, _stats, _ov);
-   //VERIFY(subport_stats.n_pkts_tc[TC-1] == 10, "Wrong subport stats\n");
-
+#if 0
+   TEST_ASSERT_EQUAL(subport_stats.n_pkts_tc[TC-1], 10, "Wrong subport 
stats\n");
+#endif
struct rte_sched_queue_stats queue_stats;
uint16_t qlen;
rte_sched_queue_read_stats(port, QUEUE, _stats, );
-   //VERIFY(queue_stats.n_pkts == 10, "Wrong queue stats\n");
+#if 0
+   TEST_ASSERT_EQUAL(queue_stats.n_pkts, 10, "Wrong queue stats\n");
+#endif

rte_sched_port_free(port);

-- 
2.1.0



[dpdk-dev] [PATCH v2] test: fix missing NULL pointer checks

2015-01-27 Thread Daniel Mrzyglod
In test_sched, we are missing NULL pointer checks after calls to create the
mempool and to allocate an mbuf. Add in these checks using TEST_ASSERT_NOT_NULL 
macros.

Signed-off-by: Daniel Mrzyglod 
---
 app/test/test_sched.c | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/app/test/test_sched.c b/app/test/test_sched.c
index c957d80..83dccd2 100644
--- a/app/test/test_sched.c
+++ b/app/test/test_sched.c
@@ -166,48 +166,49 @@ test_sched(void)
int err;

mp = create_mempool();
+   TEST_ASSERT_NOT_NULL(mp, "Error create mempool\n");

port_param.socket = 0;
port_param.rate = (uint64_t) 1 * 1000 * 1000 / 8;

port = rte_sched_port_config(_param);
-   VERIFY(port != NULL, "Error config sched port\n");
-
+   TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");

err = rte_sched_subport_config(port, SUBPORT, subport_param);
-   VERIFY(err == 0, "Error config sched, err=%d\n", err);
+   TEST_ASSERT_SUCCESS(err, "Error config sched, err=%d\n", err);

for (pipe = 0; pipe < port_param.n_pipes_per_subport; pipe ++) {
err = rte_sched_pipe_config(port, SUBPORT, pipe, 0);
-   VERIFY(err == 0, "Error config sched pipe %u, err=%d\n", pipe, 
err);
+   TEST_ASSERT_SUCCESS(err, "Error config sched pipe %u, 
err=%d\n", pipe, err);
}

for (i = 0; i < 10; i++) {
in_mbufs[i] = rte_pktmbuf_alloc(mp);
+   TEST_ASSERT_NOT_NULL(in_mbufs[i], "Packet allocation failed\n");
prepare_pkt(in_mbufs[i]);
}


err = rte_sched_port_enqueue(port, in_mbufs, 10);
-   VERIFY(err == 10, "Wrong enqueue, err=%d\n", err);
+   TEST_ASSERT_EQUAL(err, 10, "Wrong enqueue, err=%d\n", err);

err = rte_sched_port_dequeue(port, out_mbufs, 10);
-   VERIFY(err == 10, "Wrong dequeue, err=%d\n", err);
+   TEST_ASSERT_EQUAL(err, 10, "Wrong dequeue, err=%d\n", err);

for (i = 0; i < 10; i++) {
enum rte_meter_color color;
uint32_t subport, traffic_class, queue;

color = rte_sched_port_pkt_read_color(out_mbufs[i]);
-   VERIFY(color == e_RTE_METER_YELLOW, "Wrong color\n");
+   TEST_ASSERT_EQUAL(color, e_RTE_METER_YELLOW, "Wrong color\n");

rte_sched_port_pkt_read_tree_path(out_mbufs[i],
, , _class, );

-   VERIFY(subport == SUBPORT, "Wrong subport\n");
-   VERIFY(pipe == PIPE, "Wrong pipe\n");
-   VERIFY(traffic_class == TC, "Wrong traffic_class\n");
-   VERIFY(queue == QUEUE, "Wrong queue\n");
+   TEST_ASSERT_EQUAL(subport, SUBPORT, "Wrong subport\n");
+   TEST_ASSERT_EQUAL(pipe, PIPE, "Wrong pipe\n");
+   TEST_ASSERT_EQUAL(traffic_class, TC, "Wrong traffic_class\n");
+   TEST_ASSERT_EQUAL(queue, QUEUE, "Wrong queue\n");

}

-- 
2.1.0



[dpdk-dev] [PATCH] mk: add support for ICC 15 compiler

2015-01-22 Thread Daniel Mrzyglod
This patch add Support for ICC 15.

ICC 15 changed inline-max-size and inline-max-total-size default values,
so for ICC 15 flags -no-inline-max-size -no-inline-max-total-size must be added.

additionally disable compile error for:
13368 - loop was not vectorized with "vector always assert"
15527 - loop was not vectorized: function call to fprintf cannot be vectorize

Signed-off-by: Daniel Mrzyglod 
---
 mk/toolchain/icc/rte.vars.mk | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/mk/toolchain/icc/rte.vars.mk b/mk/toolchain/icc/rte.vars.mk
index 5503fb0..e39d710 100644
--- a/mk/toolchain/icc/rte.vars.mk
+++ b/mk/toolchain/icc/rte.vars.mk
@@ -66,11 +66,18 @@ TOOLCHAIN_ASFLAGS =
 # Turn off some ICC warnings -
 #   Remark #271   : trailing comma is nonstandard
 #   Warning #1478 : function "" (declared at line N of "")
+#   error #13368: loop was not vectorized with "vector always assert"
+#   error #15527: loop was not vectorized: function call to fprintf cannot be 
vectorize
 #   was declared "deprecated"
 WERROR_FLAGS := -Wall -Werror-all -w2 -diag-disable 271 -diag-warning 1478
+WERROR_FLAGS += -diag-disable 13368 -diag-disable 15527

 # process cpu flags
 include $(RTE_SDK)/mk/toolchain/$(RTE_TOOLCHAIN)/rte.toolchain-compat.mk
+# disable max-inline params boundaries for ICC 15 compiler
+ifeq ($(shell test $(ICC_MAJOR_VERSION) -eq 15 && echo 1), 1)
+   TOOLCHAIN_CFLAGS += -no-inline-max-size -no-inline-max-total-size
+endif

 export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
 export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
-- 
2.1.0



[dpdk-dev] [PATCH] af_packet: fix possible memory leak

2014-12-19 Thread Daniel Mrzyglod
In rte_pmd_init_internals, we are mapping memory but not released
if error occure it could produce memoryleak.
Add unmmap function to release memory.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c 
b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
index 236749b..93e6b6b 100644
--- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
+++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
@@ -481,6 +481,11 @@ rte_pmd_init_internals(const char *name,
if (*internals == NULL)
goto error;

+   for (q = 0; q < nb_queues; q++) {
+   (*internals)->rx_queue[q].map = MAP_FAILED;
+   (*internals)->tx_queue[q].map = MAP_FAILED;
+   }
+
req = &((*internals)->req);

req->tp_block_size = blocksize;
@@ -682,6 +687,8 @@ error:
rte_free(pci_dev);
if (*internals) {
for (q = 0; q < nb_queues; q++) {
+   munmap((*internals)->rx_queue[q].map,
+   2 * req->tp_block_size 
* req->tp_block_nr);
if ((*internals)->rx_queue[q].rd)
rte_free((*internals)->rx_queue[q].rd);
if ((*internals)->tx_queue[q].rd)
-- 
2.1.0



[dpdk-dev] [PATCH] af_packet: fix memory allocation check

2014-12-18 Thread Daniel Mrzyglod
In rte_eth_af_packet.c we are we are missing NULL pointer
checks after calls to alocate memory for queues. Add checking NULL
pointer and error handling.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c 
b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
index ad7242c..236749b 100644
--- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
+++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
@@ -603,6 +603,8 @@ rte_pmd_init_internals(const char *name,
rdsize = req->tp_frame_nr * sizeof(*(rx_queue->rd));

rx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node);
+   if (rx_queue->rd == NULL)
+   goto error;
for (i = 0; i < req->tp_frame_nr; ++i) {
rx_queue->rd[i].iov_base = rx_queue->map + (i * 
framesize);
rx_queue->rd[i].iov_len = req->tp_frame_size;
@@ -615,6 +617,8 @@ rte_pmd_init_internals(const char *name,
tx_queue->map = rx_queue->map + req->tp_block_size * 
req->tp_block_nr;

tx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node);
+   if (tx_queue->rd == NULL)
+   goto error;
for (i = 0; i < req->tp_frame_nr; ++i) {
tx_queue->rd[i].iov_base = tx_queue->map + (i * 
framesize);
tx_queue->rd[i].iov_len = req->tp_frame_size;
-- 
2.1.0



[dpdk-dev] [PATCH] af_packet: fix memory allocation check

2014-12-18 Thread Daniel Mrzyglod
In rte_eth_af_packet.c we are we are missing NULL pointer
checks after calls to alocate memory for queues. Add checking NULL
pointer and error handling.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c 
b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
index ad7242c..236749b 100644
--- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
+++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
@@ -603,6 +603,8 @@ rte_pmd_init_internals(const char *name,
rdsize = req->tp_frame_nr * sizeof(*(rx_queue->rd));

rx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node);
+   if (rx_queue->rd == NULL)
+   goto error;
for (i = 0; i < req->tp_frame_nr; ++i) {
rx_queue->rd[i].iov_base = rx_queue->map + (i * 
framesize);
rx_queue->rd[i].iov_len = req->tp_frame_size;
@@ -615,6 +617,8 @@ rte_pmd_init_internals(const char *name,
tx_queue->map = rx_queue->map + req->tp_block_size * 
req->tp_block_nr;

tx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node);
+   if (tx_queue->rd == NULL)
+   goto error;
for (i = 0; i < req->tp_frame_nr; ++i) {
tx_queue->rd[i].iov_base = tx_queue->map + (i * 
framesize);
tx_queue->rd[i].iov_len = req->tp_frame_size;
-- 
2.1.0



[dpdk-dev] [PATCH] test: fix missing NULL pointer checks

2014-12-18 Thread Daniel Mrzyglod
In test_sched, we are missing NULL pointer checks after calls to create the 
mempool and to allocate an mbuf. Add in these checks using VERIFY macros.

Signed-off-by: Daniel Mrzyglod 
---
 app/test/test_sched.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/app/test/test_sched.c b/app/test/test_sched.c
index c957d80..9b6e037 100644
--- a/app/test/test_sched.c
+++ b/app/test/test_sched.c
@@ -166,6 +166,7 @@ test_sched(void)
int err;

mp = create_mempool();
+   VERIFY(mp != NULL,"Error create mempool\n");

port_param.socket = 0;
port_param.rate = (uint64_t) 1 * 1000 * 1000 / 8;
@@ -184,6 +185,7 @@ test_sched(void)

for (i = 0; i < 10; i++) {
in_mbufs[i] = rte_pktmbuf_alloc(mp);
+   VERIFY(in_mbufs[i] != NULL, "Bad packet allocation");
prepare_pkt(in_mbufs[i]);
}

-- 
2.1.0



[dpdk-dev] [PATCH v4 2/2] Unit tests for Mode 5 of Bonding Transmit Load balancig.

2014-11-27 Thread Daniel Mrzyglod
This Patch add unit tests for mode 5 - tlb - to the oders
link bonding unit tests.

Signed-off-by: Daniel Mrzyglod 
---
 app/test/test_link_bonding.c | 499 ++-
 app/test/virtual_pmd.c   |   6 +-
 2 files changed, 502 insertions(+), 3 deletions(-)

diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c
index 93449af..f62c490 100644
--- a/app/test/test_link_bonding.c
+++ b/app/test/test_link_bonding.c
@@ -41,7 +41,7 @@
 #include 
 #include 
 #include 
-
+#include 
 #include 
 #include 
 #include 
@@ -3856,6 +3856,498 @@ testsuite_teardown(void)
return remove_slaves_and_stop_bonded_device();
 }

+static int
+test_tlb_tx_burst(void)
+{
+   int i, burst_size, nb_tx;
+   uint64_t nb_tx2 = 0;
+   struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
+   struct rte_eth_stats port_stats[32];
+   uint64_t sum_ports_opackets = 0, all_bond_opackets = 0, all_bond_obytes 
= 0;
+   uint16_t pktlen;
+   uint64_t floor_obytes = 0, ceiling_obytes = 0;
+
+   TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves
+   (BONDING_MODE_ADAPTIVE_TRANSMIT_LOAD_BALANCING, 1, 3, 
1),
+   "Failed to initialise bonded device");
+
+   burst_size = 20 * test_params->bonded_slave_count;
+
+   TEST_ASSERT(burst_size < MAX_PKT_BURST,
+   "Burst size specified is greater than supported.\n");
+
+
+   /* Generate 40 test bursts in 2s of packets to transmit  */
+   for (i = 0; i < 40; i++) {
+   /*test two types of mac src own(bonding) and others */
+   if (i % 2 == 0) {
+   initialize_eth_header(test_params->pkt_eth_hdr,
+   (struct ether_addr *)src_mac,
+   (struct ether_addr *)dst_mac_0, 0, 0);
+   } else {
+   initialize_eth_header(test_params->pkt_eth_hdr,
+   (struct ether_addr 
*)test_params->default_slave_mac,
+   (struct ether_addr *)dst_mac_0, 0, 0);
+   }
+   pktlen = initialize_udp_header(test_params->pkt_udp_hdr, 
src_port,
+   dst_port_0, 16);
+   pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, 
src_addr,
+   dst_addr_0, pktlen);
+   generate_packet_burst(test_params->mbuf_pool, pkt_burst,
+   test_params->pkt_eth_hdr, 0, 
test_params->pkt_ipv4_hdr,
+   1, test_params->pkt_udp_hdr, burst_size, 60, 1);
+   /* Send burst on bonded port */
+   nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, 
pkt_burst,
+   burst_size);
+   nb_tx2 += nb_tx;
+
+   TEST_ASSERT_EQUAL(nb_tx, burst_size,
+   "number of packet not equal burst size");
+
+   rte_delay_us(5);
+   }
+
+
+   /* Verify bonded port tx stats */
+   rte_eth_stats_get(test_params->bonded_port_id, _stats[0]);
+
+   all_bond_opackets = port_stats[0].opackets;
+   all_bond_obytes = port_stats[0].obytes;
+
+   TEST_ASSERT_EQUAL(port_stats[0].opackets, (uint64_t)nb_tx2,
+   "Bonded Port (%d) opackets value (%u) not as expected 
(%d)\n",
+   test_params->bonded_port_id, (unsigned 
int)port_stats[0].opackets,
+   burst_size);
+
+
+   /* Verify slave ports tx stats */
+   for (i = 0; i < test_params->bonded_slave_count; i++) {
+   rte_eth_stats_get(test_params->slave_port_ids[i], 
_stats[i]);
+   sum_ports_opackets += port_stats[i].opackets;
+   }
+
+   TEST_ASSERT_EQUAL(sum_ports_opackets, (uint64_t)all_bond_opackets,
+   "Total packets sent by slaves is not equal to packets 
sent by bond interface");
+   /* distribution of packets on each slave within +/- 10% of the expected 
value. */
+   for (i = 0; i < test_params->bonded_slave_count; i++) {
+
+   floor_obytes = 
(all_bond_obytes*90)/(test_params->bonded_slave_count*100);
+   ceiling_obytes = 
(all_bond_obytes*110)/(test_params->bonded_slave_count*100);
+   TEST_ASSERT(port_stats[i].obytes >= floor_obytes &&
+   port_stats[i].obytes <= ceiling_obytes,
+   "Distribution is not even");
+   }
+   /* Put all slaves down and try and transmit */
+   for (i = 0; i < test_params->bonded_slave_count; i++) {
+   virtual_ethdev_simulate_link_status_interrupt(
+   test_params->slave_port_ids[i], 0);
+   }
+
+

[dpdk-dev] [PATCH v4 0/2] ADD mode 5(tlb) to link bonding pmd

2014-11-27 Thread Daniel Mrzyglod
ADD mode 5(tlb) to link bonding pmd

v4 change:
Change description of mode 5 in header.
Add description to cover letter.

v3 change:
Rebase patch version to HEAD of orgin/master.
Unit tests moved to the separate patch v3 2/2.

v2 change:
Add Unit Tests
Modification that updates obytes structure in virtualpmd driver.
change internals->slaves[i].last_obytes to have proper values.
Update codebase to Declan's patches.

v1 change:
Add support for mode 5 (Transmit load balancing) into pmd driver


Daniel Mrzyglod (2):
  This patch add support of mode 5 to link bonding pmd
  Unit tests for Mode 5 of Bonding Transmit Load balancig.

 app/test/test_link_bonding.c   | 499 -
 app/test/virtual_pmd.c |   6 +-
 lib/librte_pmd_bond/rte_eth_bond.h |   6 +
 lib/librte_pmd_bond/rte_eth_bond_args.c|   1 +
 lib/librte_pmd_bond/rte_eth_bond_pmd.c | 160 -
 lib/librte_pmd_bond/rte_eth_bond_private.h |   2 +-
 6 files changed, 668 insertions(+), 6 deletions(-)

-- 
2.1.0



[dpdk-dev] [PATCH v4 2/2] Unit tests for Mode 5 of Bonding Transmit Load balancig.

2014-11-27 Thread Daniel Mrzyglod
This Patch add unit tests for mode 5 - tlb - to the oders
link bonding unit tests.

Signed-off-by: Daniel Mrzyglod 
---
 app/test/test_link_bonding.c | 499 ++-
 app/test/virtual_pmd.c   |   6 +-
 2 files changed, 502 insertions(+), 3 deletions(-)

diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c
index 93449af..f62c490 100644
--- a/app/test/test_link_bonding.c
+++ b/app/test/test_link_bonding.c
@@ -41,7 +41,7 @@
 #include 
 #include 
 #include 
-
+#include 
 #include 
 #include 
 #include 
@@ -3856,6 +3856,498 @@ testsuite_teardown(void)
return remove_slaves_and_stop_bonded_device();
 }

+static int
+test_tlb_tx_burst(void)
+{
+   int i, burst_size, nb_tx;
+   uint64_t nb_tx2 = 0;
+   struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
+   struct rte_eth_stats port_stats[32];
+   uint64_t sum_ports_opackets = 0, all_bond_opackets = 0, all_bond_obytes 
= 0;
+   uint16_t pktlen;
+   uint64_t floor_obytes = 0, ceiling_obytes = 0;
+
+   TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves
+   (BONDING_MODE_ADAPTIVE_TRANSMIT_LOAD_BALANCING, 1, 3, 
1),
+   "Failed to initialise bonded device");
+
+   burst_size = 20 * test_params->bonded_slave_count;
+
+   TEST_ASSERT(burst_size < MAX_PKT_BURST,
+   "Burst size specified is greater than supported.\n");
+
+
+   /* Generate 40 test bursts in 2s of packets to transmit  */
+   for (i = 0; i < 40; i++) {
+   /*test two types of mac src own(bonding) and others */
+   if (i % 2 == 0) {
+   initialize_eth_header(test_params->pkt_eth_hdr,
+   (struct ether_addr *)src_mac,
+   (struct ether_addr *)dst_mac_0, 0, 0);
+   } else {
+   initialize_eth_header(test_params->pkt_eth_hdr,
+   (struct ether_addr 
*)test_params->default_slave_mac,
+   (struct ether_addr *)dst_mac_0, 0, 0);
+   }
+   pktlen = initialize_udp_header(test_params->pkt_udp_hdr, 
src_port,
+   dst_port_0, 16);
+   pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, 
src_addr,
+   dst_addr_0, pktlen);
+   generate_packet_burst(test_params->mbuf_pool, pkt_burst,
+   test_params->pkt_eth_hdr, 0, 
test_params->pkt_ipv4_hdr,
+   1, test_params->pkt_udp_hdr, burst_size, 60, 1);
+   /* Send burst on bonded port */
+   nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, 
pkt_burst,
+   burst_size);
+   nb_tx2 += nb_tx;
+
+   TEST_ASSERT_EQUAL(nb_tx, burst_size,
+   "number of packet not equal burst size");
+
+   rte_delay_us(5);
+   }
+
+
+   /* Verify bonded port tx stats */
+   rte_eth_stats_get(test_params->bonded_port_id, _stats[0]);
+
+   all_bond_opackets = port_stats[0].opackets;
+   all_bond_obytes = port_stats[0].obytes;
+
+   TEST_ASSERT_EQUAL(port_stats[0].opackets, (uint64_t)nb_tx2,
+   "Bonded Port (%d) opackets value (%u) not as expected 
(%d)\n",
+   test_params->bonded_port_id, (unsigned 
int)port_stats[0].opackets,
+   burst_size);
+
+
+   /* Verify slave ports tx stats */
+   for (i = 0; i < test_params->bonded_slave_count; i++) {
+   rte_eth_stats_get(test_params->slave_port_ids[i], 
_stats[i]);
+   sum_ports_opackets += port_stats[i].opackets;
+   }
+
+   TEST_ASSERT_EQUAL(sum_ports_opackets, (uint64_t)all_bond_opackets,
+   "Total packets sent by slaves is not equal to packets 
sent by bond interface");
+   /* distribution of packets on each slave within +/- 10% of the expected 
value. */
+   for (i = 0; i < test_params->bonded_slave_count; i++) {
+
+   floor_obytes = 
(all_bond_obytes*90)/(test_params->bonded_slave_count*100);
+   ceiling_obytes = 
(all_bond_obytes*110)/(test_params->bonded_slave_count*100);
+   TEST_ASSERT(port_stats[i].obytes >= floor_obytes &&
+   port_stats[i].obytes <= ceiling_obytes,
+   "Distribution is not even");
+   }
+   /* Put all slaves down and try and transmit */
+   for (i = 0; i < test_params->bonded_slave_count; i++) {
+   virtual_ethdev_simulate_link_status_interrupt(
+   test_params->slave_port_ids[i], 0);
+   }
+
+

[dpdk-dev] [PATCH v4 1/2] This patch add support of mode 5 to link bonding pmd

2014-11-27 Thread Daniel Mrzyglod
Add support for mode 5 (Transmit load balancing) into pmd driver

This patch add support for Adaptive transmit load balancing (mode 5) to the
librte_pmd_bond library. This mode provides an adaptive transmit load 
balancing. It dynamically changes the transmitting slave, according to the 
computed load. 

Further details are described here:
https://www.kernel.org/doc/Documentation/networking/bonding.txt
In implementation callback is used for sorting slave order - providing 
statistics for burst function about slave bandwith usage  and sort 
interfaces due to usage.

Difference in this implementation vs Linux implementation:
- We Are trying send all pkts ? If one interface hasn?t send packets we are 
trying to send rest of packets by other slaves sorted previously by callback 
function.

Some implementation details:
- Every 100ms is taken obytes statistics from every slave.
- Every 10 ms the slaves in  table are sorted and updated by callback - 
bandwidth and successfully transmitted bytes from previous iteration which 
happens every 100 ms
- There is callback function which updates this statistics for transparency and
for rather intensive computation involved in this mode.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_pmd_bond/rte_eth_bond.h |   6 ++
 lib/librte_pmd_bond/rte_eth_bond_args.c|   1 +
 lib/librte_pmd_bond/rte_eth_bond_pmd.c | 160 -
 lib/librte_pmd_bond/rte_eth_bond_private.h |   2 +-
 4 files changed, 166 insertions(+), 3 deletions(-)

diff --git a/lib/librte_pmd_bond/rte_eth_bond.h 
b/lib/librte_pmd_bond/rte_eth_bond.h
index 085500b..3831f56 100644
--- a/lib/librte_pmd_bond/rte_eth_bond.h
+++ b/lib/librte_pmd_bond/rte_eth_bond.h
@@ -77,6 +77,12 @@ extern "C" {
  * In this mode all transmitted packets will be transmitted on all available
  * active slaves of the bonded. */
 #endif
+#define BONDING_MODE_ADAPTIVE_TRANSMIT_LOAD_BALANCING  (5)
+/**< Adaptive TLB (Mode 5)
+ * This mode provides an adaptive transmit load balancing. It dynamically
+ * changes the transmitting slave, according to the computed load. Statistics
+ * are collected in 100ms intervals and scheduled every 10ms */
+
 /* Balance Mode Transmit Policies */
 #define BALANCE_XMIT_POLICY_LAYER2 (0)
 /**< Layer 2 (Ethernet MAC) */
diff --git a/lib/librte_pmd_bond/rte_eth_bond_args.c 
b/lib/librte_pmd_bond/rte_eth_bond_args.c
index d8ce681..2675cf6 100644
--- a/lib/librte_pmd_bond/rte_eth_bond_args.c
+++ b/lib/librte_pmd_bond/rte_eth_bond_args.c
@@ -173,6 +173,7 @@ bond_ethdev_parse_slave_mode_kvarg(const char *key 
__rte_unused,
 #ifdef RTE_MBUF_REFCNT
case BONDING_MODE_BROADCAST:
 #endif
+   case BONDING_MODE_ADAPTIVE_TRANSMIT_LOAD_BALANCING:
return 0;
default:
RTE_BOND_LOG(ERR, "Invalid slave mode value (%s) specified", 
value);
diff --git a/lib/librte_pmd_bond/rte_eth_bond_pmd.c 
b/lib/librte_pmd_bond/rte_eth_bond_pmd.c
index cf2fbab..7a5dae6 100644
--- a/lib/librte_pmd_bond/rte_eth_bond_pmd.c
+++ b/lib/librte_pmd_bond/rte_eth_bond_pmd.c
@@ -30,7 +30,7 @@
  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
+#include 
 #include 
 #include 
 #include 
@@ -41,10 +41,15 @@
 #include 
 #include 
 #include 
+#include 

 #include "rte_eth_bond.h"
 #include "rte_eth_bond_private.h"

+#define REORDER_PERIOD_MS 10
+/* Table for statistics in mode 5 TLB */
+static uint64_t tlb_last_obytets[RTE_MAX_ETHPORTS];
+
 static uint16_t
 bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
@@ -288,6 +293,144 @@ xmit_slave_hash(const struct rte_mbuf *buf, uint8_t 
slave_count, uint8_t policy)
return hash % slave_count;
 }

+struct bwg_slave {
+   uint64_t bwg_left_int;
+   uint64_t bwg_left_remainder;
+   uint8_t slave;
+};
+
+static int
+bandwidth_cmp(const void *a, const void *b)
+{
+   const struct bwg_slave *bwg_a = a;
+   const struct bwg_slave *bwg_b = b;
+   int64_t diff = (int64_t)bwg_b->bwg_left_int - 
(int64_t)bwg_a->bwg_left_int;
+   int64_t diff2 = (int64_t)bwg_b->bwg_left_remainder -
+   (int64_t)bwg_a->bwg_left_remainder;
+   if (diff > 0)
+   return 1;
+   else if (diff < 0)
+   return -1;
+   else if (diff2 > 0)
+   return 1;
+   else if (diff2 < 0)
+   return -1;
+   else
+   return 0;
+}
+
+static void
+bandwidth_left(int port_id, uint64_t load, uint8_t update_idx,
+   struct bwg_slave *bwg_slave)
+{
+   struct rte_eth_link link_status;
+
+   rte_eth_link_get(port_id, _status);
+   uint64_t link_bwg = link_status.link_speed * 100ULL / 8;
+   if (link_bwg == 0)
+   return;
+   link_bwg = (link_bwg * (update_idx+1) * REORDER_PERIOD_MS

[dpdk-dev] [PATCH v4 0/2] ADD mode 5(tlb) to link bonding pmd

2014-11-27 Thread Daniel Mrzyglod
ADD mode 5(tlb) to link bonding pmd

v4 change:
Change description of mode 5 in header.
Add description to cover letter.

v3 change:
Rebase patch version to HEAD of orgin/master.
Unit tests moved to the separate patch v3 2/2.

v2 change:
Add Unit Tests
Modification that updates obytes structure in virtualpmd driver.
change internals->slaves[i].last_obytes to have proper values.
Update codebase to Declan's patches.

v1 change:
Add support for mode 5 (Transmit load balancing) into pmd driver


Daniel Mrzyglod (2):
  This patch add support of mode 5 to link bonding pmd
  Unit tests for Mode 5 of Bonding Transmit Load balancig.

 app/test/test_link_bonding.c   | 499 -
 app/test/virtual_pmd.c |   6 +-
 lib/librte_pmd_bond/rte_eth_bond.h |   6 +
 lib/librte_pmd_bond/rte_eth_bond_args.c|   1 +
 lib/librte_pmd_bond/rte_eth_bond_pmd.c | 160 -
 lib/librte_pmd_bond/rte_eth_bond_private.h |   2 +-
 6 files changed, 668 insertions(+), 6 deletions(-)

-- 
2.1.0



[dpdk-dev] [PATCH v3 0/2] ADD mode 5(tlb) to link bonding pmd

2014-11-26 Thread Daniel Mrzyglod
This mode provides an adaptive transmit load balancing.
It dynamically changes the transmitting slave, according to the computed load.
Statistics are collected in 100ms intervals and scheduled every 10ms.

Daniel Mrzyglod (2):
  This patch add support of mode 5 to link bonding pmd
  Unit tests for Mode 5 of Bonding Transmit Load balancing.

 app/test/test_link_bonding.c   | 499 -
 app/test/virtual_pmd.c |   6 +-
 lib/librte_pmd_bond/rte_eth_bond.h |  11 +
 lib/librte_pmd_bond/rte_eth_bond_args.c|   1 +
 lib/librte_pmd_bond/rte_eth_bond_pmd.c | 160 -
 lib/librte_pmd_bond/rte_eth_bond_private.h |   2 +-
 6 files changed, 673 insertions(+), 6 deletions(-)

-- 
2.1.0



[dpdk-dev] [PATCH] x32 ABI support, first iteration

2014-11-13 Thread Daniel Mrzyglod
Signed-off-by: Konstantin Ananyev 
Signed-off-by: Daniel Mrzyglod 
---
 config/defconfig_x86_x32-native-linuxapp-gcc | 46 
 mk/arch/x86_x32/rte.vars.mk  | 63 
 2 files changed, 109 insertions(+)
 create mode 100644 config/defconfig_x86_x32-native-linuxapp-gcc
 create mode 100644 mk/arch/x86_x32/rte.vars.mk

diff --git a/config/defconfig_x86_x32-native-linuxapp-gcc 
b/config/defconfig_x86_x32-native-linuxapp-gcc
new file mode 100644
index 000..fb0afc4
--- /dev/null
+++ b/config/defconfig_x86_x32-native-linuxapp-gcc
@@ -0,0 +1,46 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#include "common_linuxapp"
+
+CONFIG_RTE_MACHINE="native"
+
+CONFIG_RTE_ARCH="x86_x32"
+CONFIG_RTE_ARCH_X86_X32=y
+
+CONFIG_RTE_TOOLCHAIN="gcc"
+CONFIG_RTE_TOOLCHAIN_GCC=y
+
+#
+# KNI is not supported on 32-bit
+#
+CONFIG_RTE_LIBRTE_KNI=n
diff --git a/mk/arch/x86_x32/rte.vars.mk b/mk/arch/x86_x32/rte.vars.mk
new file mode 100644
index 000..9507af7
--- /dev/null
+++ b/mk/arch/x86_x32/rte.vars.mk
@@ -0,0 +1,63 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#
+# arch:
+#
+#   - define ARCH variable (overriden by cmdline or by previous
+# optional define in machine .mk)
+#   - define CROSS variable (overriden by cmdline or previous define
+# in machine .mk)
+#   - define CPU_CFLAGS variable (overriden by cmdline or previous
+# define in machine .mk)
+#   - define CPU_LDFLAGS variable (overriden by cmdline or previous
+# define in machine .mk)
+#   - define CPU_ASFLAGS variable (overriden by cmdline or previous
+# define in machine .mk)
+#   - may override any pr

[dpdk-dev] [PATCH v3] Modify tools/setup.sh to be compatible with fedora 21

2014-10-10 Thread Daniel Mrzyglod
script was expecting /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko but in 
fedora 21
there are Compressed kernel modules - xz (LZMA)

V3 patch: Remove sudo
V2 patch: Use modinfo instead ls
V1 patch: use ls instead checking if specific file exist

Signed-off-by: Daniel Mrzyglod 
---
 tools/setup.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/setup.sh b/tools/setup.sh
index 369e09e..14e319c 100755
--- a/tools/setup.sh
+++ b/tools/setup.sh
@@ -169,7 +169,8 @@ load_igb_uio_module()

/sbin/lsmod | grep -s uio > /dev/null
if [ $? -ne 0 ] ; then
-   if [ -f /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko ] ; 
then
+   modinfo uio > /dev/null
+   if [ $? -eq 0 ]; then
echo "Loading uio module"
sudo /sbin/modprobe uio
fi
-- 
2.1.0



[dpdk-dev] [PATCH v2] Modify tools/setup.sh to be compatible with fedora 21

2014-10-09 Thread Daniel Mrzyglod
script was expecting /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko but in 
fedora 21
there are Compressed kernel modules - xz (LZMA)

Signed-off-by: Daniel Mrzyglod 
---
 tools/setup.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/setup.sh b/tools/setup.sh
index 369e09e..14e319c 100755
--- a/tools/setup.sh
+++ b/tools/setup.sh
@@ -169,7 +169,8 @@ load_igb_uio_module()

/sbin/lsmod | grep -s uio > /dev/null
if [ $? -ne 0 ] ; then
-   if [ -f /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko ] ; 
then
+   sudo modinfo uio > /dev/null
+   if [ $? -eq 0 ]; then
echo "Loading uio module"
sudo /sbin/modprobe uio
fi
-- 
2.1.0



[dpdk-dev] [PATCH v2] ADD mode 5(tlb) to link bonding pmd

2014-09-26 Thread Daniel Mrzyglod

Signed-off-by: Daniel Mrzyglod 
---
 app/test/test_link_bonding.c   |  501 +++-
 app/test/virtual_pmd.c |6 +-
 app/test/virtual_pmd.h |7 +
 lib/librte_pmd_bond/rte_eth_bond.h |   23 ++
 lib/librte_pmd_bond/rte_eth_bond_args.c|1 +
 lib/librte_pmd_bond/rte_eth_bond_pmd.c |  161 -
 lib/librte_pmd_bond/rte_eth_bond_private.h |3 +-
 7 files changed, 696 insertions(+), 6 deletions(-)

diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c
index c4fcaf7..77f791f 100644
--- a/app/test/test_link_bonding.c
+++ b/app/test/test_link_bonding.c
@@ -41,7 +41,7 @@
 #include 
 #include 
 #include 
-
+#include 
 #include 
 #include 
 #include 
@@ -3845,6 +3845,500 @@ testsuite_teardown(void)
return remove_slaves_and_stop_bonded_device();
 }

+#define NINETY_PERCENT_NUMERAL 90
+#define ONE_HUNDRED_PERCENT_DENOMINATOR 100
+#define ONE_HUNDRED_PERCENT_AND_TEN_NUMERAL 110
+static int
+test_tlb_tx_burst(void)
+{
+   int i, burst_size, nb_tx;
+   uint64_t nb_tx2 = 0;
+   struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
+   struct rte_eth_stats port_stats[32];
+   uint64_t sum_ports_opackets = 0, all_bond_opackets = 0, all_bond_obytes 
= 0;
+   uint16_t pktlen;
+
+   TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves
+   (BONDING_MODE_ADAPTIVE_TRANSMIT_LOAD_BALANCING, 1, 3, 
1),
+   "Failed to initialise bonded device");
+
+   burst_size = 20 * test_params->bonded_slave_count;
+
+   TEST_ASSERT(burst_size < MAX_PKT_BURST,
+   "Burst size specified is greater than supported.\n");
+
+
+   /* Generate 40 test bursts in 2s of packets to transmit  */
+   for (i = 0; i < 40; i++) {
+   /*test two types of mac src own(bonding) and others */
+   if (i % 2 == 0) {
+   initialize_eth_header(test_params->pkt_eth_hdr,
+   (struct ether_addr *)src_mac, (struct 
ether_addr *)dst_mac_0, 0, 0);
+   } else {
+   initialize_eth_header(test_params->pkt_eth_hdr,
+   (struct ether_addr 
*)test_params->default_slave_mac,
+   (struct ether_addr *)dst_mac_0, 0, 0);
+   }
+   pktlen = initialize_udp_header(test_params->pkt_udp_hdr, 
src_port,
+   dst_port_0, 16);
+   pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, 
src_addr,
+   dst_addr_0, pktlen);
+   generate_packet_burst(test_params->mbuf_pool, pkt_burst,
+   test_params->pkt_eth_hdr, 0, 
test_params->pkt_ipv4_hdr,
+   1, test_params->pkt_udp_hdr, burst_size, 60, 1);
+   /* Send burst on bonded port */
+   nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, 
pkt_burst,
+   burst_size);
+   nb_tx2 += nb_tx;
+
+   TEST_ASSERT_EQUAL(nb_tx, burst_size,
+   "number of packet not equal burst size");
+
+   rte_delay_us(5);
+   }
+
+
+   /* Verify bonded port tx stats */
+   rte_eth_stats_get(test_params->bonded_port_id, _stats[0]);
+
+   all_bond_opackets = port_stats[0].opackets;
+   all_bond_obytes = port_stats[0].obytes;
+
+   TEST_ASSERT_EQUAL(port_stats[0].opackets, (uint64_t)nb_tx2,
+   "Bonded Port (%d) opackets value (%u) not as expected 
(%d)\n",
+   test_params->bonded_port_id, (unsigned 
int)port_stats[0].opackets,
+   burst_size);
+
+
+   /* Verify slave ports tx stats */
+   for (i = 0; i < test_params->bonded_slave_count; i++) {
+   rte_eth_stats_get(test_params->slave_port_ids[i], 
_stats[i]);
+   sum_ports_opackets += port_stats[i].opackets;
+   }
+
+   TEST_ASSERT_EQUAL(sum_ports_opackets, (uint64_t)all_bond_opackets,
+   "Total packets sent by slaves is not equalto packets 
sent by bond interface");
+
+   for (i = 0; i < test_params->bonded_slave_count; i++) {
+   printf("port stats:%"PRIu64"\n", port_stats[i].opackets);
+   /* distribution of packets on each slave within +/- 10% of the 
expected value. */
+   TEST_ASSERT(port_stats[i].obytes >= 
((all_bond_obytes*NINETY_PERCENT_NUMERAL)/
+   
(test_params->bonded_slave_count*ONE_HUNDRED_PERCENT_DENOMINATOR)) &&
+   port_stats[i].obytes <= 
((all_bond_obytes*ONE_HUNDRED_PERCENT_AND_TEN_NUMERAL) /
+  

[dpdk-dev] [PATCH] ADD mode 5(tlb) to link bonding pmd

2014-09-17 Thread Daniel Mrzyglod
This patch set adds support of mode 5 to link bonding pmd

This patchset depend on  Declan Doherty patch set:
http://dpdk.org/ml/archives/dev/2014-September/005069.html

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_pmd_bond/rte_eth_bond.h |   23 
 lib/librte_pmd_bond/rte_eth_bond_args.c|1 +
 lib/librte_pmd_bond/rte_eth_bond_pmd.c |  163 +++-
 lib/librte_pmd_bond/rte_eth_bond_private.h |5 +-
 4 files changed, 189 insertions(+), 3 deletions(-)

diff --git a/lib/librte_pmd_bond/rte_eth_bond.h 
b/lib/librte_pmd_bond/rte_eth_bond.h
index bd59780..1bd76ce 100644
--- a/lib/librte_pmd_bond/rte_eth_bond.h
+++ b/lib/librte_pmd_bond/rte_eth_bond.h
@@ -75,6 +75,29 @@ extern "C" {
 /**< Broadcast (Mode 3).
  * In this mode all transmitted packets will be transmitted on all available
  * active slaves of the bonded. */
+#define BONDING_MODE_ADAPTIVE_TRANSMIT_LOAD_BALANCING  (5)
+/**< Broadcast (Mode 5)
+ * Adaptive transmit load balancing: channel bonding that
+ * does not require any special switch support.  The
+ * outgoing traffic is distributed according to the
+ * current load (computed relative to the speed) on each
+ * slave.  Incoming traffic is received by the current
+ * slave.  If the receiving slave fails, another slave
+ * takes over the MAC address of the failed receiving
+ * slave.*/
+#define BONDING_MODE_ADAPTIVE_LOAD_BALANCING   (6)
+/**
+ * Adaptive load balancing: includes balance-tlb plus
+ * receive load balancing (rlb) for IPV4 traffic, and
+ * does not require any special switch support.  The
+ * receive load balancing is achieved by ARP negotiation.
+ * The bonding driver intercepts the ARP Replies sent by
+ * the local system on their way out and overwrites the
+ * source hardware address with the unique hardware
+ * address of one of the slaves in the bond such that
+ * different peers use different hardware addresses for
+ * the server. */
+

 /* Balance Mode Transmit Policies */
 #define BALANCE_XMIT_POLICY_LAYER2 (0)
diff --git a/lib/librte_pmd_bond/rte_eth_bond_args.c 
b/lib/librte_pmd_bond/rte_eth_bond_args.c
index 11d9816..bb1cfae 100644
--- a/lib/librte_pmd_bond/rte_eth_bond_args.c
+++ b/lib/librte_pmd_bond/rte_eth_bond_args.c
@@ -170,6 +170,7 @@ bond_ethdev_parse_slave_mode_kvarg(const char *key 
__rte_unused,
case BONDING_MODE_ACTIVE_BACKUP:
case BONDING_MODE_BALANCE:
case BONDING_MODE_BROADCAST:
+   case BONDING_MODE_ADAPTIVE_TRANSMIT_LOAD_BALANCING:
return 0;
default:
return -1;
diff --git a/lib/librte_pmd_bond/rte_eth_bond_pmd.c 
b/lib/librte_pmd_bond/rte_eth_bond_pmd.c
index 38cc1ae..9c4c174 100644
--- a/lib/librte_pmd_bond/rte_eth_bond_pmd.c
+++ b/lib/librte_pmd_bond/rte_eth_bond_pmd.c
@@ -30,7 +30,7 @@
  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
+#include 
 #include 
 #include 
 #include 
@@ -40,10 +40,14 @@
 #include 
 #include 
 #include 
+#include 
+#include 

 #include "rte_eth_bond.h"
 #include "rte_eth_bond_private.h"

+#define REORDER_PERIOD_MS 10
+
 static uint16_t
 bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
@@ -286,6 +290,141 @@ xmit_slave_hash(const struct rte_mbuf *buf, uint8_t 
slave_count, uint8_t policy)
return hash % slave_count;
 }

+struct bwg_slave {
+   uint64_t bwg_left_int;
+   uint64_t bwg_left_remainder;
+   uint8_t slave;
+};
+
+static int
+bandwidth_cmp(const void *a, const void *b)
+{
+   const struct bwg_slave *bwg_a = a;
+   const struct bwg_slave *bwg_b = b;
+   int64_t diff = (int64_t)bwg_b->bwg_left_int - 
(int64_t)bwg_a->bwg_left_int;
+   int64_t diff2 = (int64_t)bwg_b->bwg_left_remainder -
+   (int64_t)bwg_a->bwg_left_remainder;
+   if (diff > 0)
+   return 1;
+   else if (diff < 0)
+   return -1;
+   else if (diff2 > 0)
+   return 1;
+   else if (diff2 < 0)
+   return -1;
+   else
+   return 0;
+}
+
+static void
+bandwidth_left(int port_id, uint64_t load, uint8_t update_idx, struct 
bwg_slave *bwg_slave)
+{
+   struct rte_eth_link link_status;
+
+   rte_eth_link_get(port_id, _status);
+   uint64_t link_bwg = link_status.link_speed * 100ULL / 8;
+   if (link_bwg == 0)
+   return;
+   link_bwg = (link_bwg * (update_idx+1) * REORDER_PERIOD_MS);
+   bwg_slave->bwg_left_int = ((link_bwg - 1000*load)) / link_bwg;
+   bwg_slave->bwg_left_remainder = ((link_bwg - 1000*load)) % link_bwg;
+}
+
+static void
+bond_ethdev_update_tlb_slave_cb(void *arg)
+{
+   struct bond_dev_private *internals = arg;
+   struct rte_eth_stats slave_stats;
+   struct bwg_slave bwg_array[RTE_MAX_ETHPORTS];
+   uint8_t slave_

[dpdk-dev] [PATCH] Added Spinlock to l3fwd-vf example to prevent race conditioning

2014-07-08 Thread Daniel Mrzyglod

Signed-off-by: Daniel Mrzyglod 
---
 examples/l3fwd-vf/main.c |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/l3fwd-vf/main.c b/examples/l3fwd-vf/main.c
index 2ca5c21..57852d0 100644
--- a/examples/l3fwd-vf/main.c
+++ b/examples/l3fwd-vf/main.c
@@ -54,6 +54,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -328,7 +329,7 @@ struct lcore_conf {
 } __rte_cache_aligned;

 static struct lcore_conf lcore_conf[RTE_MAX_LCORE];
-
+static rte_spinlock_t 
spinlock_conf[RTE_MAX_ETHPORTS]={RTE_SPINLOCK_INITIALIZER};
 /* Send burst of packets on an output interface */
 static inline int
 send_burst(struct lcore_conf *qconf, uint16_t n, uint8_t port)
@@ -340,7 +341,10 @@ send_burst(struct lcore_conf *qconf, uint16_t n, uint8_t 
port)
queueid = qconf->tx_queue_id;
m_table = (struct rte_mbuf **)qconf->tx_mbufs[port].m_table;

+   rte_spinlock_lock(_conf[port]) ;
ret = rte_eth_tx_burst(port, queueid, m_table, n);
+   rte_spinlock_unlock(_conf[port]);
+   
if (unlikely(ret < n)) {
do {
rte_pktmbuf_free(m_table[ret]);
-- 
1.7.9.5



  1   2   >