[dpdk-dev] [PATCH] app/test lib/librte_pmd_af_packet: fix check for null & fix possible memory leak

2014-12-17 Thread Daniel Mrzyglod
app/test/test_sched.c:
-Fix several checking for NULL pointer
lib/librte_pmd_af_packet/rte_eth_af_packet.c:
-Not munmaped queue area
-Fix several checking for NULL pointer

Signed-off-by: Daniel Mrzyglod 
---
 app/test/test_sched.c|  2 ++
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 49 
 2 files changed, 31 insertions(+), 20 deletions(-)

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]);
}

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 d0fb3eb..d9f1373 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;
@@ -496,13 +501,13 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: I/F name too long (%s)\n",
name, pair->value);
-   goto error;
+   goto error_free_queues;
}
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
RTE_LOG(ERR, PMD,
"%s: ioctl failed (SIOCGIFINDEX)\n",
name);
-   goto error;
+   goto error_free_queues;
}
(*internals)->if_index = ifr.ifr_ifindex;

@@ -510,7 +515,7 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: ioctl failed (SIOCGIFHWADDR)\n",
name);
-   goto error;
+   goto error_free_queues;
}
memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);

@@ -544,7 +549,7 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: could not set PACKET_VERSION on AF_PACKET "
"socket for %s\n", name, pair->value);
-   goto error;
+   goto error_free_queues;
}

discard = 1;
@@ -554,7 +559,7 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: could not set PACKET_LOSS on "
"AF_PACKET socket for %s\n", name, pair->value);
-   goto error;
+   goto error_free_queues;
}

 #if defined(PACKET_QDISC_BYPASS)
@@ -566,7 +571,7 @@ rte_pmd_init_internals(const char *name,
"%s: could not set PACKET_QDISC_BYPASS "
"on AF_PACKET socket for %s\n", name,
pair->value);
-   goto error;
+   goto error_free_queues;
}
 #endif

@@ -575,7 +580,7 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: could not set PACKET_RX_RING on AF_PACKET "
"socket for %s\n", name, pair->value);
-   goto error;
+   goto error_free_queues;
}

rc = setsockopt(qsockfd, SOL_PACKET, PACKET_TX_RING, req, 
sizeof(*req));
@@ -583,7 +588,7 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: could not set PACKET_TX_RING on AF_PACKET "
"socket for %s\n", name, pair->value);
-   goto error;
+   goto error_free_queues;
}

rx_queue = &((*internals)->rx_queue[q]);
@@ -596,13 +601,15 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: call to mmap failed on AF_PACKET socket 
for %s\n",
  

[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] 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 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] 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(&spinlock_conf[port]) ;
ret = rte_eth_tx_burst(port, queueid, m_table, n);
+   rte_spinlock_unlock(&spinlock_conf[port]);
+   
if (unlikely(ret < n)) {
do {
rte_pktmbuf_free(m_table[ret]);
-- 
1.7.9.5



[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, &link_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_

[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, &port_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], 
&port_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] kni:fix build on Ubuntu 12.04.5 with current HWE

2014-09-30 Thread Daniel Mrzyglod
Recent Ubuntu 12.04.5 LTS is shipped with 3.13.0-36.63 as the only supported 
kernel.

Patch a09b359daca3d8af43dc22a57b34cf317f958236 describe the problem.

Signed-off-by: Daniel Mrzyglod 
---
 lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h 
b/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h
index 5a06383..65649ae 100644
--- a/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h
+++ b/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h
@@ -3861,7 +3861,8 @@ static inline struct sk_buff 
*__kc__vlan_hwaccel_put_tag(struct sk_buff *skb,

 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) )
 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,0)))
-#if (!(UBUNTU_RELEASE_CODE == UBUNTU_RELEASE_VERSION(14,4) && 
UBUNTU_KERNEL_CODE >= UBUNTU_KERNEL_VERSION(3,13,0,30,54)))
+#if (!((UBUNTU_RELEASE_CODE == UBUNTU_RELEASE_VERSION(14,4) \
+|| UBUNTU_RELEASE_CODE == UBUNTU_RELEASE_VERSION(12,4)) && UBUNTU_KERNEL_CODE 
>= UBUNTU_KERNEL_VERSION(3,13,0,30,54)))
 #ifdef NETIF_F_RXHASH
 #define PKT_HASH_TYPE_L3 0
 static inline void
-- 
1.7.9.5



[dpdk-dev] [PATCH] doc: fix openssl formating text in documentation

2017-01-10 Thread Daniel Mrzyglod
the code section was lacking indendation to be be corectly formatted.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/cryptodevs/openssl.rst | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/doc/guides/cryptodevs/openssl.rst 
b/doc/guides/cryptodevs/openssl.rst
index d2b5906..f1c39ba 100644
--- a/doc/guides/cryptodevs/openssl.rst
+++ b/doc/guides/cryptodevs/openssl.rst
@@ -98,15 +98,15 @@ To verify real traffic l2fwd-crypto example can be used 
with this command:
 
 .. code-block:: console
 
-sudo ./build/l2fwd-crypto -c 0x3 -n 4 --vdev "crypto_openssl"
---vdev "crypto_openssl"-- -p 0x3 --chain CIPHER_HASH
---cipher_op ENCRYPT --cipher_algo AES_CBC
---cipher_key 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f
---iv 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:ff
---auth_op GENERATE --auth_algo SHA1_HMAC
---auth_key 11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
-:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
-:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
+   sudo ./build/l2fwd-crypto -c 0x3 -n 4 --vdev "crypto_openssl"
+   --vdev "crypto_openssl"-- -p 0x3 --chain CIPHER_HASH
+   --cipher_op ENCRYPT --cipher_algo AES_CBC
+   --cipher_key 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f
+   --iv 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:ff
+   --auth_op GENERATE --auth_algo SHA1_HMAC
+   --auth_key 
11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
+   
:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
+   :11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
 
 Limitations
 ---
-- 
2.7.4



[dpdk-dev] [PATCH] doc: fix openssl formating text

2017-01-10 Thread Daniel Mrzyglod
The code section was lacking indentation to be be correctly formatted.

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/cryptodevs/openssl.rst | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/doc/guides/cryptodevs/openssl.rst 
b/doc/guides/cryptodevs/openssl.rst
index d2b5906..f1c39ba 100644
--- a/doc/guides/cryptodevs/openssl.rst
+++ b/doc/guides/cryptodevs/openssl.rst
@@ -98,15 +98,15 @@ To verify real traffic l2fwd-crypto example can be used 
with this command:
 
 .. code-block:: console
 
-sudo ./build/l2fwd-crypto -c 0x3 -n 4 --vdev "crypto_openssl"
---vdev "crypto_openssl"-- -p 0x3 --chain CIPHER_HASH
---cipher_op ENCRYPT --cipher_algo AES_CBC
---cipher_key 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f
---iv 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:ff
---auth_op GENERATE --auth_algo SHA1_HMAC
---auth_key 11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
-:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
-:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
+   sudo ./build/l2fwd-crypto -c 0x3 -n 4 --vdev "crypto_openssl"
+   --vdev "crypto_openssl"-- -p 0x3 --chain CIPHER_HASH
+   --cipher_op ENCRYPT --cipher_algo AES_CBC
+   --cipher_key 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f
+   --iv 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:ff
+   --auth_op GENERATE --auth_algo SHA1_HMAC
+   --auth_key 
11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
+   
:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
+   :11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
 
 Limitations
 ---
-- 
2.7.4



[dpdk-dev] [PATCH] app/test-crypto-perf: fix gcc compilation under FreeBSD

2017-02-01 Thread Daniel Mrzyglod
this fix error: implicit declaration of function 'getline'

Signed-off-by: Daniel Mrzyglod 
---
 app/test-crypto-perf/cperf_test_vector_parsing.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c 
b/app/test-crypto-perf/cperf_test_vector_parsing.c
index e0bcb20..c53ba67 100644
--- a/app/test-crypto-perf/cperf_test_vector_parsing.c
+++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
@@ -1,3 +1,6 @@
+#ifdef RTE_EXEC_ENV_BSDAPP
+   #define _WITH_GETLINE
+#endif
 #include 
 
 #include 
-- 
2.7.4



[dpdk-dev] [PATCH v2] app/test-crypto-perf: fix gcc compilation under FreeBSD

2017-02-02 Thread Daniel Mrzyglod
This patch fixes error: implicit declaration of function 'getline'

Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")

Signed-off-by: Daniel Mrzyglod 
---
v2:
* rewrite patch messege
* add fixline
---
 app/test-crypto-perf/cperf_test_vector_parsing.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c 
b/app/test-crypto-perf/cperf_test_vector_parsing.c
index e0bcb20..c53ba67 100644
--- a/app/test-crypto-perf/cperf_test_vector_parsing.c
+++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
@@ -1,3 +1,6 @@
+#ifdef RTE_EXEC_ENV_BSDAPP
+   #define _WITH_GETLINE
+#endif
 #include 
 
 #include 
-- 
2.7.4



[dpdk-dev] [PATCH v3] app/test-crypto-perf: fix compilation under FreeBSD

2017-02-07 Thread Daniel Mrzyglod
This patch fixes error: implicit declaration of function 'getline'

Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")

Signed-off-by: Daniel Mrzyglod 
---
v3:
* remove gcc from commit subject because it's common for all compillers

v2:
* rewrite patch messege
* add fixline
---
 app/test-crypto-perf/cperf_test_vector_parsing.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c 
b/app/test-crypto-perf/cperf_test_vector_parsing.c
index e0bcb20..c53ba67 100644
--- a/app/test-crypto-perf/cperf_test_vector_parsing.c
+++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
@@ -1,3 +1,6 @@
+#ifdef RTE_EXEC_ENV_BSDAPP
+   #define _WITH_GETLINE
+#endif
 #include 
 
 #include 
-- 
2.7.4



[dpdk-dev] [PATCH] test/bonding: fix namespace bonding mode4 unit tests

2017-07-05 Thread Daniel Mrzyglod
ring network driver is limited to 32 characters
the name of device was extened to net_ring_unit_test_mode4_slave_0 which is 33

Fixes: 5e41ab250dfa ("app/test: unit tests for bonding mode 4")

Signed-off-by: Daniel Mrzyglod 
---
 test/test/test_link_bonding_mode4.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/test/test/test_link_bonding_mode4.c 
b/test/test/test_link_bonding_mode4.c
index c6745e8..8b64bbf 100644
--- a/test/test/test_link_bonding_mode4.c
+++ b/test/test/test_link_bonding_mode4.c
@@ -73,11 +73,11 @@
 #define MAX_PKT_BURST   (32)
 #define DEF_PKT_BURST   (16)
 
-#define BONDED_DEV_NAME ("unit_test_mode4_bond_dev")
+#define BONDED_DEV_NAME ("ut_mode4_bond_dev")
 
-#define SLAVE_DEV_NAME_FMT  ("unit_test_mode4_slave_%d")
-#define SLAVE_RX_QUEUE_FMT  ("unit_test_mode4_slave_%d_rx")
-#define SLAVE_TX_QUEUE_FMT  ("unit_test_mode4_slave_%d_tx")
+#define SLAVE_DEV_NAME_FMT  ("ut_mode4_slave_%d")
+#define SLAVE_RX_QUEUE_FMT  ("ut_mode4_slave_%d_rx")
+#define SLAVE_TX_QUEUE_FMT  ("ut_mode4_slave_%d_tx")
 
 #define INVALID_SOCKET_ID   (-1)
 #define INVALID_PORT_ID (0xFF)
-- 
2.7.4



[dpdk-dev] [PATCH v2 0/3] Bonding add additional aggregators mode for 802.3AD

2017-07-19 Thread Daniel Mrzyglod
This patchseries add support for other aggregators in similar manner
that is provided in Linux kernel.

Modes added in patches:
stable - this is default mode from IEEE802.11AX/IEEE802.3AD documentation
bandwidth - takes aggregator with the biggest available speed
count - takes aggregators with the biggest number of slaves

V2:
-fix eal argument parsing
-add cmdline help in testpmd
-add unit test
-fix checkpatch warnings
-update device name in unit tests

Daniel Mrzyglod (3):
  drivers/bonding: add other agg selection modes
  testpmd: add cmndlines to support different aggregation modes
  test/bonding: add test case for agg selection in mode4

 app/test-pmd/cmdline.c|  94 ++-
 drivers/net/bonding/rte_eth_bond_8023ad.c | 193 --
 drivers/net/bonding/rte_eth_bond_8023ad.h |  32 
 drivers/net/bonding/rte_eth_bond_8023ad_private.h |   1 +
 drivers/net/bonding/rte_eth_bond_args.c   |  33 
 drivers/net/bonding/rte_eth_bond_pmd.c|  19 ++-
 drivers/net/bonding/rte_eth_bond_private.h|   5 +
 drivers/net/bonding/rte_eth_bond_version.map  |   5 +
 test/test/test_link_bonding_mode4.c   |  83 +-
 9 files changed, 446 insertions(+), 19 deletions(-)

-- 
2.13.3



[dpdk-dev] [PATCH v2 1/3] drivers/bonding: add other agg selection modes

2017-07-19 Thread Daniel Mrzyglod
This patch add support for setting additional aggregator modes for IEEE802.3AD
in similar manner that are supported in kernel mode.

This will add support for other manner:
stable - default mode taken from IEEE802.11AX this is default aggregator mode
bandwidth - takes aggregator with highest bandwidth
count - takes aggregator with biggest number of slaves

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 193 --
 drivers/net/bonding/rte_eth_bond_8023ad.h |  32 
 drivers/net/bonding/rte_eth_bond_8023ad_private.h |   1 +
 drivers/net/bonding/rte_eth_bond_args.c   |  33 
 drivers/net/bonding/rte_eth_bond_pmd.c|  19 ++-
 drivers/net/bonding/rte_eth_bond_private.h|   5 +
 drivers/net/bonding/rte_eth_bond_version.map  |   5 +
 7 files changed, 274 insertions(+), 14 deletions(-)

diff --git a/drivers/net/bonding/rte_eth_bond_8023ad.c 
b/drivers/net/bonding/rte_eth_bond_8023ad.c
index a2313b327..eb273988a 100644
--- a/drivers/net/bonding/rte_eth_bond_8023ad.c
+++ b/drivers/net/bonding/rte_eth_bond_8023ad.c
@@ -44,7 +44,6 @@
 #include "rte_eth_bond_private.h"
 
 static void bond_mode_8023ad_ext_periodic_cb(void *arg);
-
 #ifdef RTE_LIBRTE_BOND_DEBUG_8023AD
 #define MODE4_DEBUG(fmt, ...) RTE_LOG(DEBUG, PMD, "%6u [Port %u: %s] " fmt, \
bond_dbg_get_time_diff_ms(), slave_id, \
@@ -660,6 +659,25 @@ tx_machine(struct bond_dev_private *internals, uint8_t 
slave_id)
SM_FLAG_CLR(port, NTT);
 }
 
+static uint8_t
+max_index(uint64_t *a, int n)
+{
+   if (n <= 0)
+   return -1;
+
+   int i, max_i = 0;
+   uint64_t max = a[0];
+
+   for (i = 1; i < n; ++i) {
+   if (a[i] > max) {
+   max = a[i];
+   max_i = i;
+   }
+   }
+
+   return max_i;
+}
+
 /**
  * Function assigns port to aggregator.
  *
@@ -670,8 +688,13 @@ static void
 selection_logic(struct bond_dev_private *internals, uint8_t slave_id)
 {
struct port *agg, *port;
-   uint8_t slaves_count, new_agg_id, i;
+   uint8_t slaves_count, new_agg_id, i, j = 0;
uint8_t *slaves;
+   uint64_t agg_bandwidth[8] = {0};
+   uint64_t agg_count[8] = {0};
+   uint8_t default_slave = 0;
+   uint8_t mode_count_id, mode_band_id;
+   struct rte_eth_link link_info;
 
slaves = internals->active_slaves;
slaves_count = internals->active_slave_count;
@@ -684,6 +707,10 @@ selection_logic(struct bond_dev_private *internals, 
uint8_t slave_id)
if (agg->aggregator_port_id != slaves[i])
continue;
 
+   agg_count[agg->aggregator_port_id] += 1;
+   rte_eth_link_get_nowait(slaves[i], &link_info);
+   agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+
/* Actors system ID is not checked since all slave device have 
the same
 * ID (MAC address). */
if ((agg->actor.key == port->actor.key &&
@@ -694,15 +721,36 @@ selection_logic(struct bond_dev_private *internals, 
uint8_t slave_id)
(agg->actor.key &
rte_cpu_to_be_16(BOND_LINK_FULL_DUPLEX_KEY)) != 
0) {
 
-   break;
+   if (j == 0)
+   default_slave = i;
+   j++;
}
}
 
-   /* By default, port uses it self as agregator */
-   if (i == slaves_count)
-   new_agg_id = slave_id;
-   else
-   new_agg_id = slaves[i];
+   switch (internals->mode4.agg_selection) {
+   case AGG_COUNT:
+   mode_count_id = max_index(
+   (uint64_t *)agg_count, slaves_count);
+   new_agg_id = mode_count_id;
+   break;
+   case AGG_BANDWIDTH:
+   mode_band_id = max_index(
+   (uint64_t *)agg_bandwidth, slaves_count);
+   new_agg_id = mode_band_id;
+   break;
+   case AGG_STABLE:
+   if (default_slave == slaves_count)
+   new_agg_id = slave_id;
+   else
+   new_agg_id = slaves[default_slave];
+   break;
+   default:
+   if (default_slave == slaves_count)
+   new_agg_id = slave_id;
+   else
+   new_agg_id = slaves[default_slave];
+   break;
+   }
 
if (new_agg_id != port->aggregator_port_id) {
port->aggregator_port_id = new_agg_id;
@@ -909,7 +957,7 @@ bond_mode_8023ad_activate_slave(struct rte_eth_dev 
*bond_dev, uint8_t slave_id)
 
/* default states */
port->actor_state = STATE_AGGREGATION | STATE_LACP_ACTIVE | 
STATE_DEFAUL

[dpdk-dev] [PATCH v2 2/3] testpmd: add cmndlines to support different aggregation modes

2017-07-19 Thread Daniel Mrzyglod
This patch add support for different aggregator modes in similar manner
that is provided in linux kernel.

testpmd> set bonding agg_mode  
testpmd> show bonding config 

Signed-off-by: Daniel Mrzyglod 
---
 app/test-pmd/cmdline.c | 94 +-
 1 file changed, 93 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 7decb96c8..7e08674b9 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -579,6 +579,9 @@ static void cmd_help_long_parsed(void *parsed_result,
"set bonding mac_addr (port_id) (address)\n"
"   Set the MAC address of a bonded device.\n\n"
 
+   "set bonding mode IEEE802.3AD aggregator policy 
(port_id) (agg_name)"
+   "   Set Aggregation mode for IEEE802.3AD (mode 4)"
+
"set bonding xmit_balance_policy (port_id) 
(l2|l23|l34)\n"
"   Set the transmit balance policy for bonded 
device running in balance mode.\n\n"
 
@@ -4589,7 +4592,7 @@ static void cmd_show_bonding_config_parsed(void 
*parsed_result,
__attribute__((unused)) void *data)
 {
struct cmd_show_bonding_config_result *res = parsed_result;
-   int bonding_mode;
+   int bonding_mode, agg_mode;
uint8_t slaves[RTE_MAX_ETHPORTS];
int num_slaves, num_active_slaves;
int primary_id;
@@ -4630,6 +4633,23 @@ static void cmd_show_bonding_config_parsed(void 
*parsed_result,
}
}
 
+   if (bonding_mode == BONDING_MODE_8023AD) {
+   agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
+   printf("\tIEEE802.3AD Aggregator Mode: ");
+   switch (agg_mode) {
+   case AGG_BANDWIDTH:
+   printf("bandwidth");
+   break;
+   case AGG_STABLE:
+   printf("stable");
+   break;
+   case AGG_COUNT:
+   printf("count");
+   break;
+   }
+   printf("\n");
+   }
+
num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
 
if (num_slaves < 0) {
@@ -5062,6 +5082,77 @@ cmdline_parse_inst_t cmd_set_bond_mon_period = {
}
 };
 
+
+
+struct cmd_set_bonding_agg_mode_policy_result {
+   cmdline_fixed_string_t set;
+   cmdline_fixed_string_t bonding;
+   cmdline_fixed_string_t agg_mode;
+   uint8_t port_num;
+   cmdline_fixed_string_t policy;
+};
+
+
+static void
+cmd_set_bonding_agg_mode(void *parsed_result,
+   __attribute__((unused)) struct cmdline *cl,
+   __attribute__((unused)) void *data)
+{
+   struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
+   uint8_t policy = AGG_BANDWIDTH;
+
+   if (res->port_num >= nb_ports) {
+   printf("Port id %d must be less than %d\n",
+   res->port_num, nb_ports);
+   return;
+   }
+
+   if (!strcmp(res->policy, "bandwidth"))
+   policy = AGG_BANDWIDTH;
+   else if (!strcmp(res->policy, "stable"))
+   policy = AGG_STABLE;
+   else if (!strcmp(res->policy, "count"))
+   policy = AGG_COUNT;
+
+   rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
+}
+
+
+cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
+   TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
+   set, "set");
+cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
+   TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
+   bonding, "bonding");
+
+cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
+   TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
+   agg_mode, "agg_mode");
+
+cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
+   TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
+   port_num, UINT8);
+
+cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
+   TOKEN_STRING_INITIALIZER(
+   struct cmd_set_bonding_balance_xmit_policy_result,
+   policy, "stable#bandwidth#count");
+
+cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
+   .f = cmd_set_bonding_agg_mode,
+   .data = (void *) 0,
+   .help_str = "set bonding mode IEEE802.3AD aggregator policy  
",
+   .tokens = {
+   (void *)&cmd_set_bonding_agg_mode_se

[dpdk-dev] [PATCH v2 3/3] test/bonding: add test case for agg selection in mode4

2017-07-19 Thread Daniel Mrzyglod
Signed-off-by: Daniel Mrzyglod 
---
 test/test/test_link_bonding_mode4.c | 83 +++--
 1 file changed, 79 insertions(+), 4 deletions(-)

diff --git a/test/test/test_link_bonding_mode4.c 
b/test/test/test_link_bonding_mode4.c
index 8b64bbf71..8e9e23db5 100644
--- a/test/test/test_link_bonding_mode4.c
+++ b/test/test/test_link_bonding_mode4.c
@@ -73,11 +73,11 @@
 #define MAX_PKT_BURST   (32)
 #define DEF_PKT_BURST   (16)
 
-#define BONDED_DEV_NAME ("ut_mode4_bond_dev")
+#define BONDED_DEV_NAME ("net_bonding_m4_bond_dev")
 
-#define SLAVE_DEV_NAME_FMT  ("ut_mode4_slave_%d")
-#define SLAVE_RX_QUEUE_FMT  ("ut_mode4_slave_%d_rx")
-#define SLAVE_TX_QUEUE_FMT  ("ut_mode4_slave_%d_tx")
+#define SLAVE_DEV_NAME_FMT  ("net_virt_%d")
+#define SLAVE_RX_QUEUE_FMT  ("net_virt_%d_rx")
+#define SLAVE_TX_QUEUE_FMT  ("net_virt_%d_tx")
 
 #define INVALID_SOCKET_ID   (-1)
 #define INVALID_PORT_ID (0xFF)
@@ -682,6 +682,74 @@ test_mode4_lacp(void)
 
return TEST_SUCCESS;
 }
+static int
+test_mode4_agg_mode_selection(void)
+{
+   int retval;
+   /* Test and verify for Stable mode */
+   retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
+   TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
+
+
+   retval = rte_eth_bond_8023ad_agg_selection_set(
+   test_params.bonded_port_id, AGG_STABLE);
+   TEST_ASSERT_SUCCESS(retval, "Failed to initialize bond aggregation 
mode");
+   retval = bond_handshake();
+   TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
+
+
+   retval = rte_eth_bond_8023ad_agg_selection_get(
+   test_params.bonded_port_id);
+   TEST_ASSERT_EQUAL(retval, AGG_STABLE,
+   "Wrong agg mode received from bonding device");
+
+   retval = remove_slaves_and_stop_bonded_device();
+   TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
+
+
+   /* test and verify for Bandwidth mode */
+   retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
+   TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
+
+
+   retval = rte_eth_bond_8023ad_agg_selection_set(
+   test_params.bonded_port_id,
+   AGG_BANDWIDTH);
+   TEST_ASSERT_SUCCESS(retval,
+   "Failed to initialize bond aggregation mode");
+   retval = bond_handshake();
+   TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
+
+   retval = rte_eth_bond_8023ad_agg_selection_get(
+   test_params.bonded_port_id);
+   TEST_ASSERT_EQUAL(retval, AGG_BANDWIDTH,
+   "Wrong agg mode received from bonding device");
+
+   retval = remove_slaves_and_stop_bonded_device();
+   TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
+
+   /* test and verify selection for count mode */
+   retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
+   TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
+
+
+   retval = rte_eth_bond_8023ad_agg_selection_set(
+   test_params.bonded_port_id, AGG_COUNT);
+   TEST_ASSERT_SUCCESS(retval,
+   "Failed to initialize bond aggregation mode");
+   retval = bond_handshake();
+   TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
+
+   retval = rte_eth_bond_8023ad_agg_selection_get(
+   test_params.bonded_port_id);
+   TEST_ASSERT_EQUAL(retval, AGG_COUNT,
+   "Wrong agg mode received from bonding device");
+
+   retval = remove_slaves_and_stop_bonded_device();
+   TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
+
+   return TEST_SUCCESS;
+}
 
 static int
 generate_packets(struct ether_addr *src_mac,
@@ -1535,6 +1603,11 @@ test_mode4_executor(int (*test_func)(void))
 }
 
 static int
+test_mode4_agg_mode_selection_wrapper(void){
+   return test_mode4_executor(&test_mode4_agg_mode_selection);
+}
+
+static int
 test_mode4_lacp_wrapper(void)
 {
return test_mode4_executor(&test_mode4_lacp);
@@ -1581,6 +1654,8 @@ static struct unit_test_suite 
link_bonding_mode4_test_suite  = {
.setup = test_setup,
.teardown = testsuite_teardown,
.unit_test_cases = {
+   TEST_CASE_NAMED("test_mode4_agg_mode_selection",
+   test_mode4_agg_mode_selection_wrapper),
TEST_CASE_NAMED("test_mode4_lacp", test_mode4_lacp_wrapper),
TEST_CASE_NAMED("test_mode4_rx", test_mode4_rx_wrapper),
TEST_CASE_NAMED("test_mode4_tx_burst", 
test_mode4_tx_burst_wrapper),
-- 
2.13.3



[dpdk-dev] [PATCH] doc: fix testpmd literal block representation

2017-07-20 Thread Daniel Mrzyglod
There were mising :: so file was parsed in wrong way

Fixes: c735b831b0c1 ("app/testpmd: add cmd for dedicated LACP Rx/Tx queues")

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst 
b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index cafcd1d11..e5a38cf1d 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -1804,7 +1804,7 @@ set bonding lacp dedicated_queue
 
 
 Enable dedicated tx/rx queues on bonding devices slaves to handle LACP control 
plane traffic
-when in mode 4 (link-aggregration-802.3ad)
+when in mode 4 (link-aggregration-802.3ad)::
 
testpmd> set bonding lacp dedicated_queues (port_id) (enable|disable)
 
-- 
2.13.3



[dpdk-dev] [PATCH] app/testpmd: fix argument cannot be negative

2017-07-25 Thread Daniel Mrzyglod
Coverity issue: 143454
Fixes: a92a5a2cbbff ("app/testpmd: add command for loading DDP")

Signed-off-by: Daniel Mrzyglod 
---
 app/test-pmd/config.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index ee6644d10..b77fb96e1 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -3292,7 +3292,7 @@ uint8_t *
 open_ddp_package_file(const char *file_path, uint32_t *size)
 {
FILE *fh = fopen(file_path, "rb");
-   uint32_t pkg_size;
+   off_t pkg_size;
uint8_t *buf = NULL;
int ret = 0;
 
@@ -3312,6 +3312,12 @@ open_ddp_package_file(const char *file_path, uint32_t 
*size)
}
 
pkg_size = ftell(fh);
+   if (pkg_size == -1) {
+   fclose(fh);
+   printf("%s: The stream specified is not a seekable stream\n"
+   , __func__);
+   return buf;
+   }
 
buf = (uint8_t *)malloc(pkg_size);
if (!buf) {
-- 
2.13.3



[dpdk-dev] [PATCH] test/bonding: fix namespace of the rss tests

2017-07-26 Thread Daniel Mrzyglod
drivers are looking by name of the device so change namespace to proper one

Fixes: 43b630244e7e ("app/test: add dynamic bonding RSS configuration")

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

diff --git a/test/test/test_link_bonding_rssconf.c 
b/test/test/test_link_bonding_rssconf.c
index dcbc9d1e2..f8cf1cabf 100644
--- a/test/test/test_link_bonding_rssconf.c
+++ b/test/test/test_link_bonding_rssconf.c
@@ -60,7 +60,7 @@
 #define RXTX_RING_SIZE 1024
 #define RXTX_QUEUE_COUNT   4
 
-#define BONDED_DEV_NAME ("rssconf_bond_dev")
+#define BONDED_DEV_NAME ("net_bonding_rss")
 
 #define SLAVE_DEV_NAME_FMT  ("net_null%d")
 #define SLAVE_RXTX_QUEUE_FMT  ("rssconf_slave%d_q%d")
-- 
2.13.3



[dpdk-dev] [PATCH] doc: add testpmd bonding mode 4 aggregators mode

2017-07-26 Thread Daniel Mrzyglod
Add testpmd commands for setting aggregators mode in mode 4 (IEEE802.3AD).

Signed-off-by: Daniel Mrzyglod 
---
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 8 
 1 file changed, 8 insertions(+)

diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst 
b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index e5a38cf1d..2ed62f5bc 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -1809,6 +1809,14 @@ when in mode 4 (link-aggregration-802.3ad)::
testpmd> set bonding lacp dedicated_queues (port_id) (enable|disable)
 
 
+set bonding agg_mode
+
+
+Enable one of the specific aggregators mode when in mode 4 
(link-aggregration-802.3ad)::
+
+   testpmd> set bonding agg_mode (port_id) (bandwidth|count|stable)
+
+
 show bonding config
 ~~~
 
-- 
2.13.3



[dpdk-dev] [PATCH] app/crypto-perf: fix for segfault when bad optype is used with gcm alghorithms

2017-02-16 Thread Daniel Mrzyglod
When somebody use bad --optype with aead alghorithms
segmentation fault could happen.

Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")

Signed-off-by: Daniel Mrzyglod 
---
How to reproduce:
 AESNI_GCM:
./build/app/dpdk-test-crypto-perf -c 0xc0 --vdev crypto_aesni_gcm_pmd
-w :5e:00.0 -w :3d:01.0 -- --ptest throughput
--devtype crypto_aesni_gcm --optype cipher-then-auth  --cipher-algo aes-gcm
--cipher-op encrypt --cipher-key-sz 16 --cipher-iv-sz 12 --auth-algo aes-gcm
--auth-op generate --auth-key-sz 16 --auth-aad-sz 4 --auth-digest-sz 8
--total-ops 1000 --burst-sz 32 --buffer-sz 1024

---
 app/test-crypto-perf/cperf_options_parsing.c | 9 +
 app/test-crypto-perf/main.c  | 6 --
 doc/guides/tools/cryptoperf.rst  | 2 ++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/app/test-crypto-perf/cperf_options_parsing.c 
b/app/test-crypto-perf/cperf_options_parsing.c
index c1d5ffc..215a07b 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -829,6 +829,15 @@ cperf_options_check(struct cperf_options *options)
}
}

+   if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_GCM ||
+   options->auth_algo == RTE_CRYPTO_AUTH_AES_GCM ||
+   options->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC ) {
+   if (options->op_type != CPERF_AEAD) {
+   RTE_LOG(ERR, USER1, "Use --optype aead\n");
+   return -EINVAL;
+   }
+   }
+
return 0;
 }

diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index c1eaaff..fb3f72e 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -118,7 +118,8 @@ cperf_verify_devices_capabilities(struct cperf_options 
*opts,

if (opts->op_type == CPERF_AUTH_ONLY ||
opts->op_type == CPERF_CIPHER_THEN_AUTH ||
-   opts->op_type == CPERF_AUTH_THEN_CIPHER)  {
+   opts->op_type == CPERF_AUTH_THEN_CIPHER ||
+   opts->op_type == CPERF_AEAD)  {

cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
cap_idx.algo.auth = opts->auth_algo;
@@ -139,7 +140,8 @@ cperf_verify_devices_capabilities(struct cperf_options 
*opts,

if (opts->op_type == CPERF_CIPHER_ONLY ||
opts->op_type == CPERF_CIPHER_THEN_AUTH ||
-   opts->op_type == CPERF_AUTH_THEN_CIPHER) {
+   opts->op_type == CPERF_AUTH_THEN_CIPHER ||
+   opts->op_type == CPERF_AEAD) {

cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
cap_idx.algo.cipher = opts->cipher_algo;
diff --git a/doc/guides/tools/cryptoperf.rst b/doc/guides/tools/cryptoperf.rst
index 1fc40c4..9cb3338 100644
--- a/doc/guides/tools/cryptoperf.rst
+++ b/doc/guides/tools/cryptoperf.rst
@@ -180,6 +180,8 @@ The following are the appication command-line options:
auth-then-cipher
aead

+For GCM alghorithms you should use aead flag.
+
 * ``--sessionless``

 Enable session-less crypto operations mode.
--
2.7.4



[dpdk-dev] [PATCH v2] app/crypto-perf: fix for segfault when bad optype is used with gcm alghorithms

2017-02-16 Thread Daniel Mrzyglod
When somebody use bad --optype with aead alghorithms
segmentation fault could happen.

Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")

Signed-off-by: Daniel Mrzyglod 
---
Changes for v2:
  - fix checkpatch error related with whitespace
  - fix spelling error

How to reproduce:
 AESNI_GCM:
./build/app/dpdk-test-crypto-perf -c 0xc0 --vdev crypto_aesni_gcm_pmd
-w :5e:00.0 -w :3d:01.0 -- --ptest throughput
--devtype crypto_aesni_gcm --optype cipher-then-auth  --cipher-algo aes-gcm
--cipher-op encrypt --cipher-key-sz 16 --cipher-iv-sz 12 --auth-algo aes-gcm
--auth-op generate --auth-key-sz 16 --auth-aad-sz 4 --auth-digest-sz 8
--total-ops 1000 --burst-sz 32 --buffer-sz 1024

---
 app/test-crypto-perf/cperf_options_parsing.c | 9 +
 app/test-crypto-perf/main.c  | 6 --
 doc/guides/tools/cryptoperf.rst  | 2 ++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/app/test-crypto-perf/cperf_options_parsing.c 
b/app/test-crypto-perf/cperf_options_parsing.c
index c1d5ffc..215a07b 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -829,6 +829,15 @@ cperf_options_check(struct cperf_options *options)
}
}

+   if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_GCM ||
+   options->auth_algo == RTE_CRYPTO_AUTH_AES_GCM ||
+   options->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
+   if (options->op_type != CPERF_AEAD) {
+   RTE_LOG(ERR, USER1, "Use --optype aead\n");
+   return -EINVAL;
+   }
+   }
+
return 0;
 }

diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index c1eaaff..fb3f72e 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -118,7 +118,8 @@ cperf_verify_devices_capabilities(struct cperf_options 
*opts,

if (opts->op_type == CPERF_AUTH_ONLY ||
opts->op_type == CPERF_CIPHER_THEN_AUTH ||
-   opts->op_type == CPERF_AUTH_THEN_CIPHER)  {
+   opts->op_type == CPERF_AUTH_THEN_CIPHER ||
+   opts->op_type == CPERF_AEAD)  {

cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
cap_idx.algo.auth = opts->auth_algo;
@@ -139,7 +140,8 @@ cperf_verify_devices_capabilities(struct cperf_options 
*opts,

if (opts->op_type == CPERF_CIPHER_ONLY ||
opts->op_type == CPERF_CIPHER_THEN_AUTH ||
-   opts->op_type == CPERF_AUTH_THEN_CIPHER) {
+   opts->op_type == CPERF_AUTH_THEN_CIPHER ||
+   opts->op_type == CPERF_AEAD) {

cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
cap_idx.algo.cipher = opts->cipher_algo;
diff --git a/doc/guides/tools/cryptoperf.rst b/doc/guides/tools/cryptoperf.rst
index 1fc40c4..9cb3338 100644
--- a/doc/guides/tools/cryptoperf.rst
+++ b/doc/guides/tools/cryptoperf.rst
@@ -180,6 +180,8 @@ The following are the appication command-line options:
auth-then-cipher
aead

+For GCM algorithms you should use aead flag.
+
 * ``--sessionless``

 Enable session-less crypto operations mode.
--
2.7.4



[dpdk-dev] [PATCH v3] app/crypto-perf: fix avoid wrong optype for AEAD algorithms

2017-03-08 Thread Daniel Mrzyglod
When somebody use bad --optype with aead alghorithms
segmentation fault could happen.

Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")

Signed-off-by: Daniel Mrzyglod 
---
Changes for v3:
  - fix headline of this patch
  - add ccm alghorithm

Changes for v2:
  - fix checkpatch error related with whitespace
  - fix spelling error

How to reproduce:
 AESNI_GCM:
./build/app/dpdk-test-crypto-perf -c 0xc0 --vdev crypto_aesni_gcm_pmd
-w :5e:00.0 -w :3d:01.0 -- --ptest throughput
--devtype crypto_aesni_gcm --optype cipher-then-auth  --cipher-algo aes-gcm
--cipher-op encrypt --cipher-key-sz 16 --cipher-iv-sz 12 --auth-algo aes-gcm
--auth-op generate --auth-key-sz 16 --auth-aad-sz 4 --auth-digest-sz 8
--total-ops 1000 --burst-sz 32 --buffer-sz 1024

---
 app/test-crypto-perf/cperf_options_parsing.c | 11 +++
 app/test-crypto-perf/main.c  |  6 --
 doc/guides/tools/cryptoperf.rst  |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/app/test-crypto-perf/cperf_options_parsing.c 
b/app/test-crypto-perf/cperf_options_parsing.c
index c1d5ffc..c87ba67 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -829,6 +829,17 @@ cperf_options_check(struct cperf_options *options)
}
}
 
+   if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_GCM ||
+   options->cipher_algo == RTE_CRYPTO_CIPHER_AES_CCM ||
+   options->auth_algo == RTE_CRYPTO_AUTH_AES_GCM ||
+   options->auth_algo == RTE_CRYPTO_AUTH_AES_CCM ||
+   options->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
+   if (options->op_type != CPERF_AEAD) {
+   RTE_LOG(ERR, USER1, "Use --optype aead\n");
+   return -EINVAL;
+   }
+   }
+
return 0;
 }
 
diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index c1eaaff..fb3f72e 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -118,7 +118,8 @@ cperf_verify_devices_capabilities(struct cperf_options 
*opts,
 
if (opts->op_type == CPERF_AUTH_ONLY ||
opts->op_type == CPERF_CIPHER_THEN_AUTH ||
-   opts->op_type == CPERF_AUTH_THEN_CIPHER)  {
+   opts->op_type == CPERF_AUTH_THEN_CIPHER ||
+   opts->op_type == CPERF_AEAD)  {
 
cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
cap_idx.algo.auth = opts->auth_algo;
@@ -139,7 +140,8 @@ cperf_verify_devices_capabilities(struct cperf_options 
*opts,
 
if (opts->op_type == CPERF_CIPHER_ONLY ||
opts->op_type == CPERF_CIPHER_THEN_AUTH ||
-   opts->op_type == CPERF_AUTH_THEN_CIPHER) {
+   opts->op_type == CPERF_AUTH_THEN_CIPHER ||
+   opts->op_type == CPERF_AEAD) {
 
cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
cap_idx.algo.cipher = opts->cipher_algo;
diff --git a/doc/guides/tools/cryptoperf.rst b/doc/guides/tools/cryptoperf.rst
index 1117ebf..478d256 100644
--- a/doc/guides/tools/cryptoperf.rst
+++ b/doc/guides/tools/cryptoperf.rst
@@ -181,6 +181,8 @@ The following are the appication command-line options:
auth-then-cipher
aead
 
+For GCM/CCM algorithms you should use aead flag.
+
 * ``--sessionless``
 
 Enable session-less crypto operations mode.
-- 
2.7.4



[dpdk-dev] [PATCH 0/2] Bonding add additional aggregators mode for 802.3AD

2017-05-26 Thread Daniel Mrzyglod
This patchseries add support for other aggregators in similar manner
that is provided in Linux kernel.

Modes added in patches:
stable - this is default mode from IEEE802.11AX/IEEE802.3AD documentation
bandwidth - takes aggregator with the biggest available speed
count - takes aggregators with the biggest number of slaves

Daniel Mrzyglod (2):
  drivers/bonding: add other agg selection modes for mode4
  app/testpmd: add support for different aggregation mode in IEEE802.3ad
bonding

 app/test-pmd/cmdline.c|  90 +-
 drivers/net/bonding/rte_eth_bond_8023ad.c | 191 --
 drivers/net/bonding/rte_eth_bond_8023ad.h |  32 
 drivers/net/bonding/rte_eth_bond_8023ad_private.h |   1 +
 drivers/net/bonding/rte_eth_bond_args.c   |  33 
 drivers/net/bonding/rte_eth_bond_pmd.c|  17 +-
 drivers/net/bonding/rte_eth_bond_private.h|   5 +
 drivers/net/bonding/rte_eth_bond_version.map  |  11 ++
 8 files changed, 364 insertions(+), 16 deletions(-)

-- 
2.9.4



[dpdk-dev] [PATCH 1/2] drivers/bonding: add other agg selection modes for mode4

2017-05-26 Thread Daniel Mrzyglod
This patch add support for setting additional aggregator modes for IEEE802.3AD
in similar manner that are supported in kernel mode.

This will add support for other manner:
stable - default mode taken from IEEE802.11AX this is default aggregator mode
bandwidth - takes aggregator with highest bandwidth
count - takes aggregator with biggest number of slaves

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 191 --
 drivers/net/bonding/rte_eth_bond_8023ad.h |  32 
 drivers/net/bonding/rte_eth_bond_8023ad_private.h |   1 +
 drivers/net/bonding/rte_eth_bond_args.c   |  33 
 drivers/net/bonding/rte_eth_bond_pmd.c|  17 +-
 drivers/net/bonding/rte_eth_bond_private.h|   5 +
 drivers/net/bonding/rte_eth_bond_version.map  |  11 ++
 7 files changed, 275 insertions(+), 15 deletions(-)

diff --git a/drivers/net/bonding/rte_eth_bond_8023ad.c 
b/drivers/net/bonding/rte_eth_bond_8023ad.c
index 7b863d6..5698982 100644
--- a/drivers/net/bonding/rte_eth_bond_8023ad.c
+++ b/drivers/net/bonding/rte_eth_bond_8023ad.c
@@ -44,7 +44,6 @@
 #include "rte_eth_bond_private.h"
 
 static void bond_mode_8023ad_ext_periodic_cb(void *arg);
-
 #ifdef RTE_LIBRTE_BOND_DEBUG_8023AD
 #define MODE4_DEBUG(fmt, ...) RTE_LOG(DEBUG, PMD, "%6u [Port %u: %s] " fmt, \
bond_dbg_get_time_diff_ms(), slave_id, \
@@ -647,6 +646,25 @@ tx_machine(struct bond_dev_private *internals, uint8_t 
slave_id)
SM_FLAG_CLR(port, NTT);
 }
 
+static uint8_t
+max_index(uint64_t *a, int n)
+{
+   if (n <= 0)
+   return -1;
+
+   int i, max_i = 0;
+   uint64_t max = a[0];
+
+   for (i = 1; i < n; ++i) {
+   if (a[i] > max) {
+   max = a[i];
+   max_i = i;
+   }
+   }
+
+   return max_i;
+}
+
 /**
  * Function assigns port to aggregator.
  *
@@ -657,8 +675,13 @@ static void
 selection_logic(struct bond_dev_private *internals, uint8_t slave_id)
 {
struct port *agg, *port;
-   uint8_t slaves_count, new_agg_id, i;
+   uint8_t slaves_count, new_agg_id, i, j = 0;
uint8_t *slaves;
+   uint64_t agg_bandwidth[8] = {0};
+   uint64_t agg_count[8] = {0};
+   uint8_t default_slave = 0;
+   uint8_t mode_count_id, mode_band_id;
+   struct rte_eth_link link_info;
 
slaves = internals->active_slaves;
slaves_count = internals->active_slave_count;
@@ -671,6 +694,10 @@ selection_logic(struct bond_dev_private *internals, 
uint8_t slave_id)
if (agg->aggregator_port_id != slaves[i])
continue;
 
+   agg_count[agg->aggregator_port_id] += 1;
+   rte_eth_link_get_nowait(slaves[i], &link_info);
+   agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+
/* Actors system ID is not checked since all slave device have 
the same
 * ID (MAC address). */
if ((agg->actor.key == port->actor.key &&
@@ -681,15 +708,34 @@ selection_logic(struct bond_dev_private *internals, 
uint8_t slave_id)
(agg->actor.key &
rte_cpu_to_be_16(BOND_LINK_FULL_DUPLEX_KEY)) != 
0) {
 
-   break;
+   if (j == 0)
+   default_slave = i;
+   j++;
}
}
 
-   /* By default, port uses it self as agregator */
-   if (i == slaves_count)
-   new_agg_id = slave_id;
-   else
-   new_agg_id = slaves[i];
+   switch (internals->mode4.agg_selection) {
+   case AGG_COUNT:
+   mode_count_id = max_index((uint64_t *)agg_count, slaves_count);
+   new_agg_id = mode_count_id;
+   break;
+   case AGG_BANDWIDTH:
+   mode_band_id = max_index((uint64_t *)agg_bandwidth, 
slaves_count);
+   new_agg_id = mode_band_id;
+   break;
+   case AGG_STABLE:
+   if (default_slave == slaves_count)
+   new_agg_id = slave_id;
+   else
+   new_agg_id = slaves[default_slave];
+   break;
+   default:
+   if (default_slave == slaves_count)
+   new_agg_id = slave_id;
+   else
+   new_agg_id = slaves[default_slave];
+   break;
+   }
 
if (new_agg_id != port->aggregator_port_id) {
port->aggregator_port_id = new_agg_id;
@@ -872,7 +918,7 @@ bond_mode_8023ad_activate_slave(struct rte_eth_dev 
*bond_dev, uint8_t slave_id)
 
/* default states */
port->actor_state = STATE_AGGREGATION | STATE_LACP_ACTIVE | 
STATE_DEFAULTED;
-   port->partner_state = STATE_LACP_ACTIVE;
+   port->partner

[dpdk-dev] [PATCH 2/2] app/testpmd: add support for different aggregation mode in IEEE802.3ad bonding

2017-05-26 Thread Daniel Mrzyglod
This patch add support for different aggregator modes in similar manner
that is provided in linux kernel.

testpmd> set bonding agg_mode  
testpmd> show bonding config 

Signed-off-by: Daniel Mrzyglod 
---
 app/test-pmd/cmdline.c | 90 +-
 1 file changed, 89 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 0afac68..11a3000 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -87,6 +87,7 @@
 #include 
 #ifdef RTE_LIBRTE_PMD_BOND
 #include 
+#include 
 #endif
 #ifdef RTE_LIBRTE_IXGBE_PMD
 #include 
@@ -4359,7 +4360,7 @@ static void cmd_show_bonding_config_parsed(void 
*parsed_result,
__attribute__((unused)) void *data)
 {
struct cmd_show_bonding_config_result *res = parsed_result;
-   int bonding_mode;
+   int bonding_mode, agg_mode;
uint8_t slaves[RTE_MAX_ETHPORTS];
int num_slaves, num_active_slaves;
int primary_id;
@@ -4400,6 +4401,23 @@ static void cmd_show_bonding_config_parsed(void 
*parsed_result,
}
}
 
+   if (bonding_mode == BONDING_MODE_8023AD) {
+   agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
+   printf("\t802.11AD Aggregator Mode: ");
+   switch (agg_mode) {
+   case AGG_BANDWIDTH:
+   printf("bandwidth");
+   break;
+   case AGG_STABLE:
+   printf("stable");
+   break;
+   case AGG_COUNT:
+   printf("count");
+   break;
+   }
+   printf("\n");
+   }
+
num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
 
if (num_slaves < 0) {
@@ -4832,6 +4850,75 @@ cmdline_parse_inst_t cmd_set_bond_mon_period = {
}
 };
 
+
+
+struct cmd_set_bonding_agg_mode_policy_result {
+   cmdline_fixed_string_t set;
+   cmdline_fixed_string_t bonding;
+   cmdline_fixed_string_t agg_mode;
+   uint8_t port_num;
+   cmdline_fixed_string_t policy;
+};
+
+
+static void
+cmd_set_bonding_agg_mode(void *parsed_result,
+   __attribute__((unused)) struct cmdline *cl,
+   __attribute__((unused)) void *data)
+{
+   struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
+   uint8_t policy = AGG_BANDWIDTH;
+
+   if (res->port_num >= nb_ports) {
+   printf("Port id %d must be less than %d\n", res->port_num, 
nb_ports);
+   return;
+   }
+
+   if (!strcmp(res->policy, "bandwidth"))
+   policy = AGG_BANDWIDTH;
+   else if (!strcmp(res->policy, "stable"))
+   policy = AGG_STABLE;
+   else if (!strcmp(res->policy, "count"))
+   policy = AGG_COUNT;
+
+   rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
+}
+
+
+cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
+   TOKEN_STRING_INITIALIZER(struct 
cmd_set_bonding_agg_mode_policy_result,
+   set, "set");
+cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
+   TOKEN_STRING_INITIALIZER(struct 
cmd_set_bonding_agg_mode_policy_result,
+   bonding, "bonding");
+
+cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
+   TOKEN_STRING_INITIALIZER(struct 
cmd_set_bonding_agg_mode_policy_result,
+   agg_mode, "agg_mode");
+
+cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
+   TOKEN_NUM_INITIALIZER(struct 
cmd_set_bonding_agg_mode_policy_result,
+   port_num, UINT8);
+
+cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
+TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
+   policy, "stable#bandwidth#count");
+
+cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
+   .f = cmd_set_bonding_agg_mode,
+   .data = (void *) 0,
+   .help_str = "set bonding mode802.11 aggregator policy  
",
+   .tokens = {
+   (void *)&cmd_set_bonding_agg_mode_set,
+   (void *)&cmd_set_bonding_agg_mode_bonding,
+   (void *)&cmd_set_bonding_agg_mode_agg_mode,
+   (void *)&cmd_set_bonding_agg_mode_portnum,
+   (void *)&cmd_set_bonding_agg_mode_policy_string,
+   NULL
+   }
+};
+
+
 #endif /* RTE_LIBRTE_PMD_BOND */
 
 /* *** SET FORWARDING MODE *** */
@@ -13613,6 +13700,7 @@ cmdline_parse_ctx_t main_ctx[] = {
(cmdline_p

[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 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(&port_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],
&subport, &pipe, &traffic_class, &queue);

-   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 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(&port_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],
&subport, &pipe, &traffic_class, &queue);

-   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, &subport_stats, &tc_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, &queue_stats, &qlen);
-   //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 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(&port_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_E

[dpdk-dev] [PATCH] net/i40e: fix return code not checked

2017-08-10 Thread Daniel Mrzyglod
Calling i40e_vsi_delete_mac without checking return
value (as is done elsewhere 5 out of 6 times)

Coverity issue: 140735
Fixes: 43c89d5a4fde ("net/i40e: set VF MAC from PF")

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

diff --git a/drivers/net/i40e/rte_pmd_i40e.c b/drivers/net/i40e/rte_pmd_i40e.c
index f12b7f4a1..950a0d6a2 100644
--- a/drivers/net/i40e/rte_pmd_i40e.c
+++ b/drivers/net/i40e/rte_pmd_i40e.c
@@ -591,7 +591,9 @@ rte_pmd_i40e_set_vf_mac_addr(uint8_t port, uint16_t vf_id,
 
/* Remove all existing mac */
TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
-   i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
+   if (i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr)
+   != I40E_SUCCESS)
+   PMD_DRV_LOG(WARNING, "Delete MAC failed");
 
return 0;
 }
-- 
2.13.3



[dpdk-dev] [PATCH] app/testpmd: wrong usage of fseek & ftell to determine filesize

2017-08-18 Thread Daniel Mrzyglod
This issue was about passing unsigned argument where should be signed number.
In reality this is about wrong usage of fseek and ftell to determine
filesize.
This patch is compliant to suggestions from FIO19-C:
"Do not use fseek() and ftell() to compute the size of a regular file"

Coverity issue: 143454
Fixes: a92a5a2cbbff ("app/testpmd: add command for loading DDP")

Signed-off-by: Daniel Mrzyglod 
---
 app/test-pmd/config.c | 39 ---
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 3ae3e1cd8..32b0c1566 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -40,6 +40,10 @@
 #include 
 
 #include 
+#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -3295,46 +3299,43 @@ port_dcb_info_display(uint8_t port_id)
 uint8_t *
 open_ddp_package_file(const char *file_path, uint32_t *size)
 {
-   FILE *fh = fopen(file_path, "rb");
-   uint32_t pkg_size;
+   int fd = open(file_path, O_RDONLY);
+   off_t pkg_size;
uint8_t *buf = NULL;
int ret = 0;
+   struct stat st_buf;
 
if (size)
*size = 0;
 
-   if (fh == NULL) {
+   if (fd == -1) {
printf("%s: Failed to open %s\n", __func__, file_path);
return buf;
}
 
-   ret = fseek(fh, 0, SEEK_END);
-   if (ret < 0) {
-   fclose(fh);
+   if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
+   close(fd);
printf("%s: File operations failed\n", __func__);
return buf;
}
 
-   pkg_size = ftell(fh);
+   pkg_size = st_buf.st_size;
+   if (pkg_size < 0) {
+   close(fd);
+   printf("%s: File operations failed\n", __func__);
+   return buf;
+   }
 
buf = (uint8_t *)malloc(pkg_size);
if (!buf) {
-   fclose(fh);
+   close(fd);
printf("%s: Failed to malloc memory\n", __func__);
return buf;
}
 
-   ret = fseek(fh, 0, SEEK_SET);
+   ret = read(fd, buf, pkg_size);
if (ret < 0) {
-   fclose(fh);
-   printf("%s: File seek operation failed\n", __func__);
-   close_ddp_package_file(buf);
-   return NULL;
-   }
-
-   ret = fread(buf, 1, pkg_size, fh);
-   if (ret < 0) {
-   fclose(fh);
+   close(fd);
printf("%s: File read operation failed\n", __func__);
close_ddp_package_file(buf);
return NULL;
@@ -3343,7 +3344,7 @@ open_ddp_package_file(const char *file_path, uint32_t 
*size)
if (size)
*size = pkg_size;
 
-   fclose(fh);
+   close(fd);
 
return buf;
 }
-- 
2.13.4



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

2017-09-19 Thread Daniel Mrzyglod
Memory allocated in strdup is not free.

Coverity issue: 143257
Fixes: d8a2bc71dfc2 ("log: remove app path from syslog id")
Cc: tho...@monjalon.net

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

diff --git a/lib/librte_eal/linuxapp/eal/eal.c 
b/lib/librte_eal/linuxapp/eal/eal.c
index 48f12f4..1bdbc3f 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -781,6 +781,7 @@ rte_eal_init(int argc, char **argv)
if (rte_eal_cpu_init() < 0) {
rte_eal_init_alert("Cannot detect lcores.");
rte_errno = ENOTSUP;
+   free(logid);
return -1;
}
 
@@ -789,6 +790,7 @@ rte_eal_init(int argc, char **argv)
rte_eal_init_alert("Invalid 'command line' arguments.");
rte_errno = EINVAL;
rte_atomic32_clear(&run_once);
+   free(logid);
return -1;
}
 
@@ -799,6 +801,7 @@ rte_eal_init(int argc, char **argv)
rte_eal_init_alert("Cannot get hugepage information.");
rte_errno = EACCES;
rte_atomic32_clear(&run_once);
+   free(logid);
return -1;
}
 
@@ -826,6 +829,7 @@ rte_eal_init(int argc, char **argv)
rte_eal_init_alert("Cannot init logging.");
rte_errno = ENOMEM;
rte_atomic32_clear(&run_once);
+   free(logid);
return -1;
}
 
@@ -834,6 +838,7 @@ rte_eal_init(int argc, char **argv)
rte_eal_init_alert("Cannot init VFIO\n");
rte_errno = EAGAIN;
rte_atomic32_clear(&run_once);
+   free(logid);
return -1;
}
 #endif
@@ -841,6 +846,7 @@ rte_eal_init(int argc, char **argv)
if (rte_eal_memory_init() < 0) {
rte_eal_init_alert("Cannot init memory\n");
rte_errno = ENOMEM;
+   free(logid);
return -1;
}
 
@@ -850,24 +856,28 @@ rte_eal_init(int argc, char **argv)
if (rte_eal_memzone_init() < 0) {
rte_eal_init_alert("Cannot init memzone\n");
rte_errno = ENODEV;
+   free(logid);
return -1;
}
 
if (rte_eal_tailqs_init() < 0) {
rte_eal_init_alert("Cannot init tail queues for objects\n");
rte_errno = EFAULT;
+   free(logid);
return -1;
}
 
if (rte_eal_alarm_init() < 0) {
rte_eal_init_alert("Cannot init interrupt-handling thread\n");
/* rte_eal_alarm_init sets rte_errno on failure. */
+   free(logid);
return -1;
}
 
if (rte_eal_timer_init() < 0) {
rte_eal_init_alert("Cannot init HPET or TSC timers\n");
rte_errno = ENOTSUP;
+   free(logid);
return -1;
}
 
@@ -886,17 +896,20 @@ rte_eal_init(int argc, char **argv)
 
if (rte_eal_intr_init() < 0) {
rte_eal_init_alert("Cannot init interrupt-handling thread\n");
+   free(logid);
return -1;
}
 
if (eal_option_device_parse()) {
rte_errno = ENODEV;
+   free(logid);
return -1;
}
 
if (rte_bus_scan()) {
rte_eal_init_alert("Cannot scan the buses for devices\n");
rte_errno = ENODEV;
+   free(logid);
return -1;
}
 
@@ -941,6 +954,7 @@ rte_eal_init(int argc, char **argv)
if (ret) {
rte_eal_init_alert("rte_service_init() failed\n");
rte_errno = ENOEXEC;
+   free(logid);
return -1;
}
 
@@ -948,6 +962,7 @@ rte_eal_init(int argc, char **argv)
if (rte_bus_probe()) {
rte_eal_init_alert("Cannot probe devices\n");
rte_errno = ENOTSUP;
+   free(logid);
return -1;
}
 
@@ -957,6 +972,7 @@ rte_eal_init(int argc, char **argv)
ret = rte_service_start_with_defaults();
if (ret < 0 && ret != -ENOTSUP) {
rte_errno = ENOEXEC;
+   free(logid);
return -1;
}
 
-- 
2.7.4



[dpdk-dev] [PATCH] net/virtio: fix of untrusted scalar value

2017-09-20 Thread Daniel Mrzyglod
The unscrutinized value may be incorrectly assumed to be within a certain
range by later operations.

In vhost_user_read: An unscrutinized value from an untrusted source used
in a trusted context - the value of sz_payload may be harmfull and we need
limit them to the max value of payload.

Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")
Cc: jianfeng@intel.com

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/virtio/virtio_user/vhost_user.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 4ad7b21..b490336 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -130,6 +130,10 @@ vhost_user_read(int fd, struct vhost_user_msg *msg)
}
 
sz_payload = msg->size;
+
+   if (sz_payload > sizeof(msg->payload))
+   goto fail;
+
if (sz_payload) {
ret = recv(fd, (void *)((char *)msg + sz_hdr), sz_payload, 0);
if (ret < sz_payload) {
-- 
2.7.4



[dpdk-dev] [PATCH v2] net/virtio: fix of untrusted scalar value

2017-09-20 Thread Daniel Mrzyglod
The unscrutinized value may be incorrectly assumed to be within a certain
range by later operations.

In vhost_user_read: An unscrutinized value from an untrusted source used
in a trusted context - the value of sz_payload may be harmfull and we need
limit them to the max value of payload.

Coverity issue: 139601

Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")
Cc: jianfeng@intel.com
Cc: stable@sta...@dpdk.org

Signed-off-by: Daniel Mrzyglod 
---
v2:
* Add Cc for stable in gitlog massage
* Add Coverity line
* v1 was acked by Acked-by: Jianfeng Tan 

 drivers/net/virtio/virtio_user/vhost_user.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 4ad7b21..b490336 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -130,6 +130,10 @@ vhost_user_read(int fd, struct vhost_user_msg *msg)
}
 
sz_payload = msg->size;
+
+   if (sz_payload > sizeof(msg->payload))
+   goto fail;
+
if (sz_payload) {
ret = recv(fd, (void *)((char *)msg + sz_hdr), sz_payload, 0);
if (ret < sz_payload) {
-- 
2.7.4



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

2017-09-22 Thread Daniel Mrzyglod
Memory allocated in strdup is not free.

Coverity issue: 143257
Fixes: d8a2bc71dfc2 ("log: remove app path from syslog id")
Cc: tho...@monjalon.net

Signed-off-by: Daniel Mrzyglod 
---
v2:
* Fix due to compilation errors

 lib/librte_eal/linuxapp/eal/eal.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal.c 
b/lib/librte_eal/linuxapp/eal/eal.c
index 48f12f4..a7df566 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -751,7 +751,7 @@ rte_eal_init(int argc, char **argv)
int i, fctret, ret;
pthread_t thread_id;
static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
-   const char *logid;
+   char *logid;
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
@@ -781,6 +781,7 @@ rte_eal_init(int argc, char **argv)
if (rte_eal_cpu_init() < 0) {
rte_eal_init_alert("Cannot detect lcores.");
rte_errno = ENOTSUP;
+   free(logid);
return -1;
}
 
@@ -789,6 +790,7 @@ rte_eal_init(int argc, char **argv)
rte_eal_init_alert("Invalid 'command line' arguments.");
rte_errno = EINVAL;
rte_atomic32_clear(&run_once);
+   free(logid);
return -1;
}
 
@@ -799,6 +801,7 @@ rte_eal_init(int argc, char **argv)
rte_eal_init_alert("Cannot get hugepage information.");
rte_errno = EACCES;
rte_atomic32_clear(&run_once);
+   free(logid);
return -1;
}
 
@@ -826,6 +829,7 @@ rte_eal_init(int argc, char **argv)
rte_eal_init_alert("Cannot init logging.");
rte_errno = ENOMEM;
rte_atomic32_clear(&run_once);
+   free(logid);
return -1;
}
 
@@ -834,6 +838,7 @@ rte_eal_init(int argc, char **argv)
rte_eal_init_alert("Cannot init VFIO\n");
rte_errno = EAGAIN;
rte_atomic32_clear(&run_once);
+   free(logid);
return -1;
}
 #endif
@@ -841,6 +846,7 @@ rte_eal_init(int argc, char **argv)
if (rte_eal_memory_init() < 0) {
rte_eal_init_alert("Cannot init memory\n");
rte_errno = ENOMEM;
+   free(logid);
return -1;
}
 
@@ -850,24 +856,28 @@ rte_eal_init(int argc, char **argv)
if (rte_eal_memzone_init() < 0) {
rte_eal_init_alert("Cannot init memzone\n");
rte_errno = ENODEV;
+   free(logid);
return -1;
}
 
if (rte_eal_tailqs_init() < 0) {
rte_eal_init_alert("Cannot init tail queues for objects\n");
rte_errno = EFAULT;
+   free(logid);
return -1;
}
 
if (rte_eal_alarm_init() < 0) {
rte_eal_init_alert("Cannot init interrupt-handling thread\n");
/* rte_eal_alarm_init sets rte_errno on failure. */
+   free(logid);
return -1;
}
 
if (rte_eal_timer_init() < 0) {
rte_eal_init_alert("Cannot init HPET or TSC timers\n");
rte_errno = ENOTSUP;
+   free(logid);
return -1;
}
 
@@ -886,17 +896,20 @@ rte_eal_init(int argc, char **argv)
 
if (rte_eal_intr_init() < 0) {
rte_eal_init_alert("Cannot init interrupt-handling thread\n");
+   free(logid);
return -1;
}
 
if (eal_option_device_parse()) {
rte_errno = ENODEV;
+   free(logid);
return -1;
}
 
if (rte_bus_scan()) {
rte_eal_init_alert("Cannot scan the buses for devices\n");
rte_errno = ENODEV;
+   free(logid);
return -1;
}
 
@@ -941,6 +954,7 @@ rte_eal_init(int argc, char **argv)
if (ret) {
rte_eal_init_alert("rte_service_init() failed\n");
rte_errno = ENOEXEC;
+   free(logid);
return -1;
}
 
@@ -948,6 +962,7 @@ rte_eal_init(int argc, char **argv)
if (rte_bus_probe()) {
rte_eal_init_alert("Cannot probe devices\n");
rte_errno = ENOTSUP;
+   free(logid);
return -1;
}
 
@@ -957,6 +972,7 @@ rte_eal_init(int argc, char **argv)
ret = rte_service_start_with_defaults();
if (ret < 0 && ret != -ENOTSUP) {
rte_errno = ENOEXEC;
+   free(logid);
return -1;
}
 
-- 
2.7.4



[dpdk-dev] [PATCH v3] net/virtio: fix of untrusted scalar value

2017-09-22 Thread Daniel Mrzyglod
The unscrutinized value may be incorrectly assumed to be within a certain
range by later operations.

In vhost_user_read: An unscrutinized value from an untrusted source used
in a trusted context - the value of sz_payload may be harmfull and we need
limit them to the max value of payload.

Coverity issue: 139601

Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")
Cc: jianfeng@intel.com
Cc: sta...@dpdk.org

Signed-off-by: Daniel Mrzyglod 
---
v3:
* there were wrong v2 email adress for stable dpdk mailinglist
* fix compilation errors

v2:
* Add Cc for stable in gitlog massage
* Add Coverity line
* v1 was acked by Acked-by: Jianfeng Tan 


 drivers/net/virtio/virtio_user/vhost_user.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 4ad7b21..97bd832 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -130,6 +130,10 @@ vhost_user_read(int fd, struct vhost_user_msg *msg)
}
 
sz_payload = msg->size;
+
+   if ((size_t)sz_payload > sizeof(msg->payload))
+   goto fail;
+
if (sz_payload) {
ret = recv(fd, (void *)((char *)msg + sz_hdr), sz_payload, 0);
if (ret < sz_payload) {
-- 
2.7.4



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

2017-10-11 Thread Daniel Mrzyglod
Memory allocated in strdup is not free.

Coverity issue: 143257
Fixes: d8a2bc71dfc2 ("log: remove app path from syslog id")
Cc: tho...@monjalon.net
Cc: sta...@dpdk.org

Signed-off-by: Daniel Mrzyglod 
---
v3: 
* remove strdup because it's basically striped argv[0]
v2:
* Fix due to compilation errors
 
 lib/librte_eal/linuxapp/eal/eal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal.c 
b/lib/librte_eal/linuxapp/eal/eal.c
index 1f07347..739b61a 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -763,7 +763,7 @@ rte_eal_init(int argc, char **argv)
}
 
logid = strrchr(argv[0], '/');
-   logid = strdup(logid ? logid + 1: argv[0]);
+   logid = logid ? logid + 1 : argv[0];
 
thread_id = pthread_self();
 
-- 
2.7.4



[dpdk-dev] [PATCH] net/bonding: fix setting default aggregator mode to stable

2017-10-20 Thread Daniel Mrzyglod
This patch change default aggregator  mode to stable
when using rte_eth_bond_create()

Fixes: 6d72657ce379 ("net/bonding: add other aggregator modes")

Signed-off-by: Daniel Mrzyglod 
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c 
b/drivers/net/bonding/rte_eth_bond_pmd.c
index 3fbc1b123..df20349d7 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -2841,6 +2841,7 @@ bond_probe(struct rte_vdev_device *dev)
struct rte_kvargs *kvlist;
uint8_t bonding_mode, socket_id/*, agg_mode*/;
int  arg_count, port_id;
+   uint8_t agg_mode;
 
if (!dev)
return -EINVAL;
@@ -2898,6 +2899,25 @@ bond_probe(struct rte_vdev_device *dev)
internals = rte_eth_devices[port_id].data->dev_private;
internals->kvlist = kvlist;
 
+
+   if (rte_kvargs_count(kvlist, PMD_BOND_AGG_MODE_KVARG) == 1) {
+   if (rte_kvargs_process(kvlist,
+   PMD_BOND_AGG_MODE_KVARG,
+   &bond_ethdev_parse_slave_agg_mode_kvarg,
+   &agg_mode) != 0) {
+   RTE_LOG(ERR, EAL,
+   "Failed to parse agg selection mode for 
bonded device %s\n",
+   name);
+   goto parse_error;
+   }
+
+   if (internals->mode == BONDING_MODE_8023AD)
+   rte_eth_bond_8023ad_agg_selection_set(port_id,
+   agg_mode);
+   } else {
+   rte_eth_bond_8023ad_agg_selection_set(port_id, AGG_STABLE);
+   }
+
RTE_LOG(INFO, EAL, "Create bonded device %s on port %d in mode %u on "
"socket %u.\n", name, port_id, bonding_mode, socket_id);
return 0;
@@ -3064,7 +3084,6 @@ bond_ethdev_configure(struct rte_eth_dev *dev)
name);
}
if (internals->mode == BONDING_MODE_8023AD)
-   if (agg_mode != 0)
rte_eth_bond_8023ad_agg_selection_set(port_id,
agg_mode);
}
-- 
2.13.6



[dpdk-dev] [PATCH v2] test/pmd_perf: fix for segmentation fault

2017-10-27 Thread Daniel Mrzyglod
Error can be reproduce if we run pmd_perf_autotest with more then
one device in such way:
RTE>>set_rxtx_sc poll_before_xmit
RTE>>pmd_perf_autotest

if first burst was value less than MAX_PKT_BURST in the end we overwrite
pkts_burst table for rx which was supposed for another interface.

Fixes: 002ade70e933 ("app/test: measure cycles per packet in Rx/Tx")
Cc: cunming.li...@intel.com
Cc: sta...@dpdk.org

Signed-off-by: Daniel Mrzyglod 
---
 test/test/test_pmd_perf.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/test/test/test_pmd_perf.c b/test/test/test_pmd_perf.c
index a3e29ed..255f260 100644
--- a/test/test/test_pmd_perf.c
+++ b/test/test/test_pmd_perf.c
@@ -572,6 +572,7 @@ poll_burst(void *args)
unsigned i, portid, nb_rx = 0;
uint64_t total;
uint64_t timeout = MAX_IDLE;
+   int num[RTE_MAX_ETHPORTS];
 
lcore_id = rte_lcore_id();
conf = &lcore_conf[lcore_id];
@@ -591,6 +592,7 @@ poll_burst(void *args)
for (i = 0; i < conf->nb_ports; i++) {
portid = conf->portlist[i];
next[portid] = i * pkt_per_port;
+   num[portid] = pkt_per_port;
}
 
while (!rte_atomic64_read(&start))
@@ -601,8 +603,8 @@ poll_burst(void *args)
for (i = 0; i < conf->nb_ports; i++) {
portid = conf->portlist[i];
nb_rx = rte_eth_rx_burst(portid, 0,
-&pkts_burst[next[portid]],
-MAX_PKT_BURST);
+   &pkts_burst[next[portid]],
+   RTE_MIN(MAX_PKT_BURST, num[portid]));
if (unlikely(nb_rx == 0)) {
timeout--;
if (unlikely(timeout == 0))
@@ -610,6 +612,7 @@ poll_burst(void *args)
continue;
}
next[portid] += nb_rx;
+   num[portid] -= nb_rx;
total -= nb_rx;
}
}
@@ -618,7 +621,6 @@ poll_burst(void *args)
 
printf("%"PRIu64" packets lost, IDLE %"PRIu64" times\n",
   total, MAX_IDLE - timeout);
-
/* clean up */
total = pkt_per_port * conf->nb_ports - total;
for (i = 0; i < total; i++)
@@ -644,7 +646,7 @@ exec_burst(uint32_t flags, int lcore)
conf = &lcore_conf[lcore];
 
pkt_per_port = MAX_TRAFFIC_BURST;
-   num = pkt_per_port;
+   num = pkt_per_port * conf->nb_ports;
 
rte_atomic64_init(&start);
 
@@ -661,11 +663,12 @@ exec_burst(uint32_t flags, int lcore)
nb_tx = RTE_MIN(MAX_PKT_BURST, num);
for (i = 0; i < conf->nb_ports; i++) {
portid = conf->portlist[i];
-   rte_eth_tx_burst(portid, 0,
+   nb_tx = rte_eth_tx_burst(portid, 0,
 &tx_burst[idx], nb_tx);
idx += nb_tx;
+   num -= nb_tx;
}
-   num -= nb_tx;
+
}
 
sleep(5);
-- 
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 = &app->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 = &app->pipeline_params[i];
-- 
2.5.5



[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] 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 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] 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] 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.

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..9c85e9f 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -96,7 +96,10 @@ rte_cfgfile_load(const char *filename, int flags)
int lineno = 0;
struct rte_cfgfile *cfg = NULL;

+   memset(buffer, '\0', sizeof(buffer));
+
FILE *f = fopen(filename, "r");
+
if (f == NULL)
return NULL;

-- 
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] 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 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 v3 1/2] This patch add support of mode 5 to link bonding pmd

2014-11-26 Thread Daniel Mrzyglod
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

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.

Signed-off-by: Daniel Mrzyglod 
---
 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 +-
 4 files changed, 171 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..29b9a89 100644
--- a/lib/librte_pmd_bond/rte_eth_bond.h
+++ b/lib/librte_pmd_bond/rte_eth_bond.h
@@ -77,6 +77,17 @@ 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)
+ * 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.*/
+
 /* 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, &link_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_count;
+   uint64_t tx_byt

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

2014-11-26 Thread Daniel Mrzyglod
This patch add unit tests for mode 5 - tlb - to the others 
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, &port_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], 
&port_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_par

[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 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, &link_status);
+   uint64_t link_bwg = link_status.link_speed * 100ULL / 8;
+   if (link_bwg == 0)
+   return;
+   link_bwg = (link_bwg * (update_idx+1) * REORDER_PERIO

[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, &port_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], 
&port_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_par

[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, &port_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], 
&port_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_par

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

2014-10-08 Thread Daniel Mrzyglod
From: 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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/setup.sh b/tools/setup.sh
index 369e09e..6a9d23c 100755
--- a/tools/setup.sh
+++ b/tools/setup.sh
@@ -169,7 +169,7 @@ 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
+   if ls /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko* &> 
/dev/null; 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 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 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 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 = &rte_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 = &rte_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 = &rte_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 dr

[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, 
&frac);
+   }
+
+   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 

[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 OF M

[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 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 = &rte_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 = &rte_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 = &rte_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

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

2015-10-30 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 | 313 +--
 drivers/net/ixgbe/ixgbe_ethdev.h |  22 +++
 2 files changed, 324 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 4373661..2c39501 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
@@ -465,6 +477,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_time_adjust  = ixgbe_timesync_time_adjust,
+   .timesync_time_get = ixgbe_timesync_time_get,
+   .timesync_time_set = ixgbe_timesync_time_set,
 };

 /*
@@ -5267,20 +5282,273 @@ 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(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 uint64_t
+cyclecounter_cycles_to_ns_backwards(const struct cyclecounter *cc,
+  uint64_t cycles, uint64_t frac)
+{
+   return ((cycles - frac) >> cc->shift);
+}
+
+/*
+ * 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, 
&frac);
+   }
+
+   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

[dpdk-dev] [PATCH v2 3/6] igb: add additional ieee1588 support functions

2015-10-30 Thread Daniel Mrzyglod
From: Pablo de Lara 

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 |  22 +++
 drivers/net/e1000/igb_ethdev.c   | 338 +--
 2 files changed, 350 insertions(+), 10 deletions(-)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 4e69e44..c8772b7 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -220,6 +220,26 @@ struct e1000_filter_info {
 };

 /*
+ * 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;
+};
+
+/*
  * Structure to store private data for each driver instance (for each port).
  */
 struct e1000_adapter {
@@ -230,6 +250,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 3ab082e..fea11f8 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -78,10 +78,12 @@
 #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 NSEC_PER_SEC 10L
+#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);
@@ -230,6 +232,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,
@@ -327,6 +334,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,
 };

 /*
@@ -3883,20 +3893,286 @@ eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
return 0;
 }

+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(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 uint64_t
+cyclecounter_cycles_to_ns_backwards(const struct cyclecounter *cc,
+   uint64_t cycles, uint64_t frac)
+{
+   return ((cycles - frac) >> cc->shift);
+}
+
+/*
+ * Register units might not be nanoseconds. This function converts
+ * these units into nanoseconds and adds to the previous time stored.
+ */
+static uint64_t
+timecounter_cycl

[dpdk-dev] [PATCH v2 4/6] i40e: add additional ieee1588 support functions

2015-10-30 Thread Daniel Mrzyglod
From: Pablo de Lara 

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 | 214 +
 drivers/net/i40e/i40e_ethdev.h |  18 
 2 files changed, 212 insertions(+), 20 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 2dd9fdc..985ab24 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -107,11 +107,14 @@
(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 NSEC_PER_SEC 10L
+#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

 static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
@@ -232,6 +235,11 @@ static int i40e_timesync_read_rx_timestamp(struct 
rte_eth_dev *dev,
   uint32_t flags);
 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
   struct timespec *timestamp);
+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[] = {
 #define RTE_PCI_DEV_ID_DECL_I40E(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
@@ -289,6 +297,9 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
.timesync_disable = i40e_timesync_disable,
.timesync_read_rx_timestamp   = i40e_timesync_read_rx_timestamp,
.timesync_read_tx_timestamp   = i40e_timesync_read_tx_timestamp,
+   .timesync_time_adjust = i40e_timesync_time_adjust,
+   .timesync_time_get= i40e_timesync_time_get,
+   .timesync_time_set= i40e_timesync_time_set,
 };

 static struct eth_driver rte_i40e_pmd = {
@@ -6175,17 +6186,116 @@ 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)
+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(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;
+}
+
+/*
+ * 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 = &dev->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;
+
+  

[dpdk-dev] [PATCH v2 5/6] example: PTP client slave minimal implementation

2015-10-30 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  |  57 +++
 examples/ptpclient/ptpclient.c   | 788 +++
 5 files changed, 854 insertions(+)
 create mode 100644 examples/ptpclient/Makefile
 create mode 100644 examples/ptpclient/ptpclient.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 080a8e8..3e446d5 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
diff --git a/doc/guides/rel_notes/release_2_2.rst 
b/doc/guides/rel_notes/release_2_2.rst
index b83ef7f..840d8ea 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -92,6 +92,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..1a8efb3
--- /dev/null
+++ b/examples/ptpclient/Makefile
@@ -0,0 +1,57 @@
+#   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
+
+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..453c20b
--- /dev/null
+++ b/examples/ptpclient/ptpclient.c
@@ -0,0 +1,788 @@
+/*-
+ *   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

[dpdk-dev] [PATCH v2 6/6] doc: add a PTPCLIENT sample guide

2015-10-30 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, opt

[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] 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] 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 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 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 = &rte_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 = &rte_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 = &rte_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 

[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 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,
+ &frac);
+   }
+
+   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 

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

2015-11-03 Thread Daniel Mrzyglod
From: Pablo de Lara 

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,
+ &frac);
+   }
+
+   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_SYSTIMH)
+ 

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

2015-11-03 Thread Daniel Mrzyglod
From: Pablo de Lara 

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 = &dev->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 = &adapter->cc;
+   adapter->tc.cycle_l

[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 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, opt

[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 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 = &rte_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 = &rte_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 = &rte_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);

[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 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,
+ &frac);
+   }
+
+   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 

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

2015-11-04 Thread Daniel Mrzyglod
From: Pablo de Lara 

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,
+ &frac);
+   }
+
+   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_SYSTIMH)
+ 

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

2015-11-04 Thread Daniel Mrzyglod
From: Pablo de Lara 

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 = &dev->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 = &adapter->cc;
+   adapter->tc.cycle_l

[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
+ *   distribution.
+

[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, opt

[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 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 = &rte_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 = &rte_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 = &rte_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);

[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 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,
+ &frac);
+   }
+
+   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 

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

2015-11-05 Thread Daniel Mrzyglod
From: Pablo de Lara 

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,
+ &frac);
+   }
+
+   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_SYSTIMH)
+ 

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

2015-11-05 Thread Daniel Mrzyglod
From: Pablo de Lara 

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 = &dev->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 +

[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
+ *   distribution.
+

[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, opt

  1   2   >