[dpdk-dev] [PATCH 3/3] doc: add missing supported algos for AESNI MB PMD

2016-12-01 Thread Pablo de Lara
AESNI MB PMD supports SHA224-HMAC and SHA384-HMAC,
but the documentation was not updated with this.

Signed-off-by: Pablo de Lara 
---
 doc/guides/cryptodevs/aesni_mb.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/guides/cryptodevs/aesni_mb.rst 
b/doc/guides/cryptodevs/aesni_mb.rst
index cb429d7..8b18eba 100644
--- a/doc/guides/cryptodevs/aesni_mb.rst
+++ b/doc/guides/cryptodevs/aesni_mb.rst
@@ -55,7 +55,9 @@ Cipher algorithms:
 Hash algorithms:

 * RTE_CRYPTO_HASH_SHA1_HMAC
+* RTE_CRYPTO_HASH_SHA224_HMAC
 * RTE_CRYPTO_HASH_SHA256_HMAC
+* RTE_CRYPTO_HASH_SHA384_HMAC
 * RTE_CRYPTO_HASH_SHA512_HMAC

 Limitations
-- 
2.7.4



[dpdk-dev] [PATCH 2/3] crypto/aesni_mb: add single operation functionality

2016-12-01 Thread Pablo de Lara
Update driver to use new AESNI Multibuffer IPSec library single
operation functionality (cipher only and authentication only).
This patch also adds tests for this new feature.

Signed-off-by: Pablo de Lara 
---
 app/test/test_cryptodev.c   | 34 
 app/test/test_cryptodev_aes_test_vectors.h  | 36 ++---
 app/test/test_cryptodev_hash_test_vectors.h | 36 ++---
 doc/guides/cryptodevs/aesni_mb.rst  |  2 --
 doc/guides/rel_notes/release_17_02.rst  |  1 +
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c  | 49 +++--
 6 files changed, 116 insertions(+), 42 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index f1f3542..5895d99 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1466,6 +1466,38 @@ test_AES_CBC_HMAC_SHA512_decrypt_perform(struct 
rte_cryptodev_sym_session *sess,
 }

 static int
+test_AES_cipheronly_mb_all(void)
+{
+   struct crypto_testsuite_params *ts_params = _params;
+   int status;
+
+   status = test_blockcipher_all_tests(ts_params->mbuf_pool,
+   ts_params->op_mpool, ts_params->valid_devs[0],
+   RTE_CRYPTODEV_AESNI_MB_PMD,
+   BLKCIPHER_AES_CIPHERONLY_TYPE);
+
+   TEST_ASSERT_EQUAL(status, 0, "Test failed");
+
+   return TEST_SUCCESS;
+}
+
+static int
+test_authonly_mb_all(void)
+{
+   struct crypto_testsuite_params *ts_params = _params;
+   int status;
+
+   status = test_blockcipher_all_tests(ts_params->mbuf_pool,
+   ts_params->op_mpool, ts_params->valid_devs[0],
+   RTE_CRYPTODEV_AESNI_MB_PMD,
+   BLKCIPHER_AUTHONLY_TYPE);
+
+   TEST_ASSERT_EQUAL(status, 0, "Test failed");
+
+   return TEST_SUCCESS;
+}
+
+static int
 test_AES_chain_mb_all(void)
 {
struct crypto_testsuite_params *ts_params = _params;
@@ -6559,6 +6591,8 @@ static struct unit_test_suite 
cryptodev_aesni_mb_testsuite  = {
.teardown = testsuite_teardown,
.unit_test_cases = {
TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
+   TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
+   TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),

TEST_CASES_END() /**< NULL terminate unit test array */
}
diff --git a/app/test/test_cryptodev_aes_test_vectors.h 
b/app/test/test_cryptodev_aes_test_vectors.h
index efbe7da..898aae1 100644
--- a/app/test/test_cryptodev_aes_test_vectors.h
+++ b/app/test/test_cryptodev_aes_test_vectors.h
@@ -1025,84 +1025,96 @@ static const struct blockcipher_test_case 
aes_cipheronly_test_cases[] = {
.test_data = _test_data_4,
.op_mask = BLOCKCIPHER_TEST_OP_ENCRYPT,
.pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL |
-   BLOCKCIPHER_TEST_TARGET_PMD_QAT
+   BLOCKCIPHER_TEST_TARGET_PMD_QAT |
+   BLOCKCIPHER_TEST_TARGET_PMD_MB
},
{
.test_descr = "AES-128-CBC Decryption",
.test_data = _test_data_4,
.op_mask = BLOCKCIPHER_TEST_OP_DECRYPT,
.pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL |
-   BLOCKCIPHER_TEST_TARGET_PMD_QAT
+   BLOCKCIPHER_TEST_TARGET_PMD_QAT |
+   BLOCKCIPHER_TEST_TARGET_PMD_MB
},
{
.test_descr = "AES-192-CBC Encryption",
.test_data = _test_data_10,
.op_mask = BLOCKCIPHER_TEST_OP_ENCRYPT,
.pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL |
-   BLOCKCIPHER_TEST_TARGET_PMD_QAT
+   BLOCKCIPHER_TEST_TARGET_PMD_QAT |
+   BLOCKCIPHER_TEST_TARGET_PMD_MB
},
{
.test_descr = "AES-192-CBC Decryption",
.test_data = _test_data_10,
.op_mask = BLOCKCIPHER_TEST_OP_DECRYPT,
.pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL |
-   BLOCKCIPHER_TEST_TARGET_PMD_QAT
+   BLOCKCIPHER_TEST_TARGET_PMD_QAT |
+   BLOCKCIPHER_TEST_TARGET_PMD_MB
},
{
.test_descr = "AES-256-CBC Encryption",
.test_data = _test_data_11,
.op_mask = BLOCKCIPHER_TEST_OP_ENCRYPT,
.pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL |
-   BLOCKCIPHER_TEST_TARGET_PMD_QAT
+   BLOCKCIPHER_TEST_TARGET_PMD_QAT |
+   BLOCKCIPHER_TEST_TARGET_PMD_MB
},
{
.test_descr = "AES-256-CBC Decryption",
.test_data = _test_data_11,
.op_mask = BLOCKCIPHER_TEST_OP_DECRYPT,
.pmd_mask = BL

[dpdk-dev] [PATCH 1/3] doc: update AESNI MB PMD guide

2016-12-01 Thread Pablo de Lara
The Intel(R) Multi Buffer Crypto library used in the AESNI MB PMD
has been moved to a new repository, in github.
This patch updates the link where it can be downloaded.

Signed-off-by: Pablo de Lara 
---
 doc/guides/cryptodevs/aesni_mb.rst | 10 +++---
 doc/guides/rel_notes/release_17_02.rst |  7 +++
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/doc/guides/cryptodevs/aesni_mb.rst 
b/doc/guides/cryptodevs/aesni_mb.rst
index e812e95..b47cb6a 100644
--- a/doc/guides/cryptodevs/aesni_mb.rst
+++ b/doc/guides/cryptodevs/aesni_mb.rst
@@ -66,21 +66,17 @@ Limitations
 * Cipher only is not supported.
 * Only in-place is currently supported (destination address is the same as 
source address).
 * Only supports session-oriented API implementation (session-less APIs are not 
supported).
-*  Not performance tuned.

 Installation
 

 To build DPDK with the AESNI_MB_PMD the user is required to download the mult-
-buffer library from `here <https://downloadcenter.intel.com/download/22972>`_
-and compile it on their user system before building DPDK. When building the
-multi-buffer library it is necessary to have YASM package installed and also
-requires the overriding of YASM path when building, as a path is hard coded in
-the Makefile of the release package.
+buffer library from `here <https://github.com/01org/intel-ipsec-mb>`_
+and compile it on their user system before building DPDK.

 .. code-block:: console

-   make YASM=/usr/bin/yasm
+   make

 Initialization
 --
diff --git a/doc/guides/rel_notes/release_17_02.rst 
b/doc/guides/rel_notes/release_17_02.rst
index 87b..4f666df 100644
--- a/doc/guides/rel_notes/release_17_02.rst
+++ b/doc/guides/rel_notes/release_17_02.rst
@@ -44,6 +44,13 @@ New Features

   * Scatter-gather list (SGL) support.

+
+* **Updated the AESNI MB PMD.**
+
+  * The Intel(R) Multi Buffer Crypto for IPsec library used in
+AESNI MB PMD has been moved to a new repository, in github.
+
+
 Resolved Issues
 ---

-- 
2.7.4



[dpdk-dev] [PATCH 0/3] AESNI MB PMD updates

2016-12-01 Thread Pablo de Lara
The library used in AESNI MB PMD, Intel Multi Buffer Crypto for IPsec,
has been migrated to a new location, in github (see documentation patch
for the link).

The library has also been updated, so single crypto operations
are supported (cipher and authentication only). Therefore, the PMD
has been updated to support these operations.

This patchset depends on patchset "Add scatter-gather list capability to
Intel QuickAssist Technology driver" 
(http://dpdk.org/ml/archives/dev/2016-November/050947.html)

Pablo de Lara (3):
  doc: update AESNI MB PMD guide
  crypto/aesni_mb: add single operation functionality
  doc: add missing supported algos for AESNI MB PMD

 app/test/test_cryptodev.c   | 34 
 app/test/test_cryptodev_aes_test_vectors.h  | 36 ++---
 app/test/test_cryptodev_hash_test_vectors.h | 36 ++---
 doc/guides/cryptodevs/aesni_mb.rst  | 14 +++--
 doc/guides/rel_notes/release_17_02.rst  |  8 +
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c  | 49 +++--
 6 files changed, 128 insertions(+), 49 deletions(-)

-- 
2.7.4



[dpdk-dev] [PATCH] doc: add limitation for L3fwd-power app

2016-11-04 Thread Pablo de Lara
L3fwd-power app needs vector mode to be disabled in order to work
properly. The app used to work previously, because it was using
Rx scalar function, but now it uses vector function.

Vector mode needs to be disabled to make the app works,
which has been documented in release notes.

Signed-off-by: Pablo de Lara 
---
 doc/guides/rel_notes/release_16_11.rst | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/doc/guides/rel_notes/release_16_11.rst 
b/doc/guides/rel_notes/release_16_11.rst
index aa0c09a..cb4ec97 100644
--- a/doc/guides/rel_notes/release_16_11.rst
+++ b/doc/guides/rel_notes/release_16_11.rst
@@ -178,6 +178,17 @@ Known Issues

This section is a comment. Make sure to start the actual text at the margin.

+* **L3fwd-power app does not work properly when Rx vector is enabled.**
+
+  Using some drivers with vector enabled, makes L3fwd-power app not work
+  properly, since the queue monitoring works differently when using
+  scalar compared to vector, making the frequency scaling not to work 
correctly.
+  In addition, L3fwd-power requires the mbuf to have correct packet type,
+  but in some drivers, the vector mode must be disabled for this.
+
+  Therefore, in order to use L3fwd-power, vector mode should be disabled
+  from the config file.
+

 API Changes
 ---
-- 
2.7.4



[dpdk-dev] [PATCH] examples/l3fwd-power: fix inappropiate Rx queue count method

2016-11-04 Thread Pablo de Lara
Since commit b4f3c136a179 ("net/ixgbe: support checksum flags in SSE vector 
Rx"),
when HW IP Checksum is enabled, the RX vector function is available to use.
In case of L3fwd-power, since it is enabled, the RX vector function
was not used, but after this commit, it is. This has affected the way
to calculate how full an RX queue is, using rte_eth_rx_descriptor done
function, making the frequency to be at maximum, even when the frequency
is very low.

This commit reverts the way to know how full a queue is to the
previous way, using rte_eth_rx_queue_count(), making it work for both
vector and scalar RX functions.

Fixes: b451aa39db31 ("examples/l3fwd-power: use DD bit rather than RX queue 
count")

Signed-off-by: Pablo de Lara 
---
 examples/l3fwd-power/main.c | 30 +++---
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index b65d683..74369bb 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -370,7 +370,7 @@ static struct rte_timer power_timers[RTE_MAX_LCORE];

 static inline uint32_t power_idle_heuristic(uint32_t zero_rx_packet_count);
 static inline enum freq_scale_hint_t power_freq_scaleup_heuristic( \
-   unsigned lcore_id, uint8_t port_id, uint16_t queue_id);
+   unsigned lcore_id, uint32_t rx_queue_count);

 /* exit signal handler */
 static void
@@ -705,9 +705,7 @@ power_idle_heuristic(uint32_t zero_rx_packet_count)
 }

 static inline enum freq_scale_hint_t
-power_freq_scaleup_heuristic(unsigned lcore_id,
-uint8_t port_id,
-uint16_t queue_id)
+power_freq_scaleup_heuristic(unsigned lcore_id, uint32_t rx_queue_count)
 {
 /**
  * HW Rx queue size is 128 by default, Rx burst read at maximum 32 entries
@@ -720,15 +718,12 @@ power_freq_scaleup_heuristic(unsigned lcore_id,
 #define FREQ_UP_TREND2_ACC   100
 #define FREQ_UP_THRESHOLD1

-   if (likely(rte_eth_rx_descriptor_done(port_id, queue_id,
-   FREQ_GEAR3_RX_PACKET_THRESHOLD) > 0)) {
+   if (likely(rx_queue_count > FREQ_GEAR3_RX_PACKET_THRESHOLD)) {
stats[lcore_id].trend = 0;
return FREQ_HIGHEST;
-   } else if (likely(rte_eth_rx_descriptor_done(port_id, queue_id,
-   FREQ_GEAR2_RX_PACKET_THRESHOLD) > 0))
+   } else if (likely(rx_queue_count > FREQ_GEAR2_RX_PACKET_THRESHOLD))
stats[lcore_id].trend += FREQ_UP_TREND2_ACC;
-   else if (likely(rte_eth_rx_descriptor_done(port_id, queue_id,
-   FREQ_GEAR1_RX_PACKET_THRESHOLD) > 0))
+   else if (likely(rx_queue_count > FREQ_GEAR1_RX_PACKET_THRESHOLD))
stats[lcore_id].trend += FREQ_UP_TREND1_ACC;

if (likely(stats[lcore_id].trend > FREQ_UP_THRESHOLD)) {
@@ -833,6 +828,7 @@ main_loop(__attribute__((unused)) void *dummy)
enum freq_scale_hint_t lcore_scaleup_hint;
uint32_t lcore_rx_idle_count = 0;
uint32_t lcore_idle_hint = 0;
+   uint32_t rx_ring_length;
int intr_en = 0;

const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S 
* BURST_TX_DRAIN_US;
@@ -923,6 +919,18 @@ start_rx:
rx_queue->zero_rx_packet_count = 0;

/**
+* get available descriptor number via
+* MMIO read is costly, so only do it when
+* recent poll returns maximum number.
+*/
+   if (nb_rx >= MAX_PKT_BURST)
+   rx_ring_length =
+   rte_eth_rx_queue_count(portid,
+   queueid);
+   else
+   rx_ring_length = 0;
+
+   /**
 * do not scale up frequency immediately as
 * user to kernel space communication is costly
 * which might impact packet I/O for received
@@ -930,7 +938,7 @@ start_rx:
 */
rx_queue->freq_up_hint =
power_freq_scaleup_heuristic(lcore_id,
-   portid, queueid);
+   rx_ring_length);
}

/* Prefetch first packets */
-- 
2.5.5



[dpdk-dev] [PATCH] [RFC] Elastic Flow Distributor

2016-10-20 Thread Pablo de Lara
The following RFC shows the functionality and usage overview of
the new Elastic Flow Distributor (EFD) library.
Library code is included in the RFC (implemention in progress, API complete),
with a sample application to demonstrate the usage of the library,
based on the existing server/client sample app.

A PDF document has been uploaded with the following and more information
about the library, including color images (not ascii) to improve
readability, in the following link:

https://github.com/pablodelara/perfect_hash_flow_distributor/blob/master/EFD_description.pdf

Introduction


In Data Centers today clustering and scheduling of distributed workloads is a
very common task. Many workload requires a deterministic partitioning of a flat
key space among a cluster of machines. When a packet enters the cluster, the
ingress node will direct the packet to its handling node.  For example,
datacenters with disaggregated storage uses storage metadata table to forward
I/O requests to correct backend storage cluster, stateful packet inspection will
use match incoming flows to signatures in flow tables to send incoming packets
to their intended deep packet inspection (DPI) devices, and so on.

EFD is a distributor library that uses perfect hashing to determine a
target/value for a given incoming flow key. It has the following advantages:
first, because it uses perfect hashing it does not store the key itself and
hence lookup performance is not dependent on the key size. Second, the
target/value can be any arbitrary value hence the system designer and/or
operator can better optimize service rates and inter-cluster network traffic
locating.  Third, since the storage requirement is much smaller than a
hash-based flow table (i.e. better fit for CPU cache), EFD can scale to millions
of flow keys. Finally, with current optimized library implementation performance
is fully scalable with number of CPU cores.

Overview


The basic idea of EFD is when a given key is to be inserted, a family of hash
functions is searched until the correct hash function that maps the input key to
the correct value is found. However, rather than explicitly storing all keys and
their associated values, EFD stores only indices of hash functions that map keys
to values, and thereby consumes much less space than conventional  flow-based
tables. The lookup operation is very simple, similar to computational-based
scheme, given an input key the lookup operation is reduced to hashing that key
with the correct hash function.

Intuitively, finding a hash function that maps each of a large number (millions)
of input keys to the correct output value is effectively impossible, as a result
EFD, breaks the problem into smaller pieces (divide and conquer). EFD divides
the entire input key set into many small groups. Each group consists of
approximately 20-28 keys (a configurable parameter for the library), then, for
each small group, a brute force search to find a hash function that produces the
correct outputs for each key in the group.
It should be mentioned that since in the online lookup table for EFD doesn?t
store the key itself, the size of the EFD table is independent of the key size
and hence EFD lookup performance which is almost constant irrespective of the
length of the key which is a highly desirable feature especially for longer
keys.

API
===

The EFD library API is created with a very similar semantics of a hash-index or
a flow table, the application creates an EFD table for a given maximum number of
flows, a function is called to insert a flow key with a specific target value,
and another function is used to retrieve target values for a given individual
flow key or a bulk of keys.

EFD Table Create


The function rte_efd_create("flow table", num_flows, online_socket_bitmask,
offline_socket_bitmask) is used to create and return a pointer to an EFD table
that is sized to hold up to num_flows key. The online version of the EFD table
(the one that does not store the keys and is used for lookups) will be allocated
and created in the last level cache (LLC) of the socket defined by the
online_socket_bitmask, while the offline EFD table (the one that stores the keys
and is used for key inserts and for computing the perfect hashing) is allocated
and created in the LLC of the socket defined by offline_socket_bitmask. It
should be noted, that For highest performance the socket id should match that
where the thread is running, i.e. the online EFD lookup table should be created
on the same socket as where the lookup thread is running.

EFD Insert and Update
-

The EFD function to insert a key or update a key to a new value is
rte_efd_update(struct rte_efd_table *table, unsigned socket_id, const efd_key_t
*key, efd_value_t value). This function will update an existing key to a new
value (target) if the key has already been inserted before, or will insert the
 pair if this key has not been 

[dpdk-dev] [PATCH] doc: ZUC PMD cannot be built as a shared library

2016-10-13 Thread Pablo de Lara
ZUC PMD cannot be built as a shared library, due to
the fact that some assembly code in the underlying libsso
library is not relocatable.
This will be fixed in the future, but for the moment,
it is added as a limitation of the PMD.

Signed-off-by: Pablo de Lara 
---
 doc/guides/cryptodevs/zuc.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/doc/guides/cryptodevs/zuc.rst b/doc/guides/cryptodevs/zuc.rst
index 7267120..38d5068 100644
--- a/doc/guides/cryptodevs/zuc.rst
+++ b/doc/guides/cryptodevs/zuc.rst
@@ -53,6 +53,9 @@ Limitations
 * Chained mbufs are not supported.
 * ZUC (EIA3) supported only if hash offset field is byte-aligned.
 * ZUC (EEA3) supported only if cipher length, cipher offset fields are 
byte-aligned.
+* ZUC PMD cannot be built as a shared library, due to limitations in
+  in the underlying library.
+

 Installation
 
-- 
2.7.4



[dpdk-dev] [PATCH] doc: how to build KASUMI as shared library

2016-10-13 Thread Pablo de Lara
Libsso KASUMI library has to be built with specific
parameters to make the KASUMI PMD be built as
a shared library, so a note has been added in
its documentation.

Signed-off-by: Pablo de Lara 
---
 doc/guides/cryptodevs/kasumi.rst | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/doc/guides/cryptodevs/kasumi.rst b/doc/guides/cryptodevs/kasumi.rst
index c122f00..90d8e7b 100644
--- a/doc/guides/cryptodevs/kasumi.rst
+++ b/doc/guides/cryptodevs/kasumi.rst
@@ -68,7 +68,13 @@ and click on "Kasumi Bit Stream crypto library" link, to 
download the library.
 After downloading the library, the user needs to unpack and compile it
 on their system before building DPDK::

-   make kasumi
+   make
+
+**Note**: To build the PMD as a shared library, the libsso_kasumi
+library must be built as follows::
+
+  make KASUMI_CFLAGS=-DKASUMI_C
+

 Initialization
 --
-- 
2.7.4



[dpdk-dev] [PATCH] doc: fix libcrypto title

2016-10-13 Thread Pablo de Lara
Libcrypto documentation was missing the equal signs ("="),
in its title, so it was not present in the documentation
generated.

Fixes: d61f70b4c918 ("crypto/libcrypto: add driver for OpenSSL library")

Signed-off-by: Pablo de Lara 
---
 doc/guides/cryptodevs/libcrypto.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/guides/cryptodevs/libcrypto.rst 
b/doc/guides/cryptodevs/libcrypto.rst
index 22d81b7..5e9c76a 100644
--- a/doc/guides/cryptodevs/libcrypto.rst
+++ b/doc/guides/cryptodevs/libcrypto.rst
@@ -28,6 +28,7 @@
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 LibCrypto Crypto Poll Mode Driver
+=

 This code provides the initial implementation of the libcrypto poll mode
 driver. All cryptography operations are using Openssl library crypto API.
-- 
2.7.4



[dpdk-dev] [PATCH] hash: fix incorrect bucket size usage

2016-10-12 Thread Pablo de Lara
Multiwriter insert function was using a fixed value for
the bucket size, instead of using the
RTE_HASH_BUCKET_ENTRIES macro, which value was changed
recently (making it inconsistent in this case).

Fixes: be856325cba3 ("hash: add scalable multi-writer insertion with Intel TSX")

Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash_x86.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash_x86.h 
b/lib/librte_hash/rte_cuckoo_hash_x86.h
index 47aec6d..0c94244 100644
--- a/lib/librte_hash/rte_cuckoo_hash_x86.h
+++ b/lib/librte_hash/rte_cuckoo_hash_x86.h
@@ -167,7 +167,8 @@ rte_hash_cuckoo_make_space_mw_tm(const struct rte_hash *h,

/* Cuckoo bfs Search */
while (likely(tail != head && head <
-   queue + RTE_HASH_BFS_QUEUE_MAX_LEN - 
4)) {
+   queue + RTE_HASH_BFS_QUEUE_MAX_LEN -
+   RTE_HASH_BUCKET_ENTRIES)) {
curr_bkt = tail->bkt;
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
if (curr_bkt->key_idx[i] == EMPTY_SLOT) {
-- 
2.7.4



[dpdk-dev] [PATCH v2] hash: fix unlimited cuckoo path

2016-10-12 Thread Pablo de Lara
When trying to insert a new entry, if its target bucket is full,
the alternative location (bucket) of one of the entries is checked,
to try to find an empty slot, with make_space_bucket.
This function is called every time a new bucket is checked, recursively.
To avoid having a very long insert operation (and to avoid filling up
the stack), a limit in the number of pushes is introduced.

Fixes: 48a399119619 ("hash: replace with cuckoo hash implementation")

Signed-off-by: Pablo de Lara 
---

Changes in v2:
- Included Fixes line

 lib/librte_hash/rte_cuckoo_hash.c | 6 +-
 lib/librte_hash/rte_cuckoo_hash.h | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index 3324b17..51db006 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -419,6 +419,7 @@ rte_hash_reset(struct rte_hash *h)
 static inline int
 make_space_bucket(const struct rte_hash *h, struct rte_hash_bucket *bkt)
 {
+   static unsigned int nr_pushes;
unsigned i, j;
int ret;
uint32_t next_bucket_idx;
@@ -455,11 +456,13 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
break;

/* All entries have been pushed, so entry cannot be added */
-   if (i == RTE_HASH_BUCKET_ENTRIES)
+   if (i == RTE_HASH_BUCKET_ENTRIES || nr_pushes > RTE_HASH_MAX_PUSHES)
return -ENOSPC;

/* Set flag to indicate that this entry is going to be pushed */
bkt->flag[i] = 1;
+
+   nr_pushes++;
/* Need room in alternative bucket to insert the pushed entry */
ret = make_space_bucket(h, next_bkt[i]);
/*
@@ -469,6 +472,7 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
 * or return error
 */
bkt->flag[i] = 0;
+   nr_pushes = 0;
if (ret >= 0) {
next_bkt[i]->sig_alt[ret] = bkt->sig_current[i];
next_bkt[i]->sig_current[ret] = bkt->sig_alt[i];
diff --git a/lib/librte_hash/rte_cuckoo_hash.h 
b/lib/librte_hash/rte_cuckoo_hash.h
index c00aafa..1b8ffed 100644
--- a/lib/librte_hash/rte_cuckoo_hash.h
+++ b/lib/librte_hash/rte_cuckoo_hash.h
@@ -140,6 +140,8 @@ enum add_key_case {

 #define LCORE_CACHE_SIZE   64

+#define RTE_HASH_MAX_PUSHES 100
+
 #define RTE_HASH_BFS_QUEUE_MAX_LEN   1000

 #define RTE_XABORT_CUCKOO_PATH_INVALIDED 0x4
-- 
2.7.4



[dpdk-dev] [PATCH] hash: fix unlimited cuckoo path

2016-10-12 Thread Pablo de Lara
When trying to insert a new entry, if its target bucket is full,
the alternative location (bucket) of one of the entries is checked,
to try to find an empty slot, with make_space_bucket.
This function is called every time a new bucket is checked, recursively.
To avoid having a very long insert operation (and to avoid filling up
the stack), a limit in the number of pushes is introduced.

Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 6 +-
 lib/librte_hash/rte_cuckoo_hash.h | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index 3324b17..51db006 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -419,6 +419,7 @@ rte_hash_reset(struct rte_hash *h)
 static inline int
 make_space_bucket(const struct rte_hash *h, struct rte_hash_bucket *bkt)
 {
+   static unsigned int nr_pushes;
unsigned i, j;
int ret;
uint32_t next_bucket_idx;
@@ -455,11 +456,13 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
break;

/* All entries have been pushed, so entry cannot be added */
-   if (i == RTE_HASH_BUCKET_ENTRIES)
+   if (i == RTE_HASH_BUCKET_ENTRIES || nr_pushes > RTE_HASH_MAX_PUSHES)
return -ENOSPC;

/* Set flag to indicate that this entry is going to be pushed */
bkt->flag[i] = 1;
+
+   nr_pushes++;
/* Need room in alternative bucket to insert the pushed entry */
ret = make_space_bucket(h, next_bkt[i]);
/*
@@ -469,6 +472,7 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
 * or return error
 */
bkt->flag[i] = 0;
+   nr_pushes = 0;
if (ret >= 0) {
next_bkt[i]->sig_alt[ret] = bkt->sig_current[i];
next_bkt[i]->sig_current[ret] = bkt->sig_alt[i];
diff --git a/lib/librte_hash/rte_cuckoo_hash.h 
b/lib/librte_hash/rte_cuckoo_hash.h
index c00aafa..1b8ffed 100644
--- a/lib/librte_hash/rte_cuckoo_hash.h
+++ b/lib/librte_hash/rte_cuckoo_hash.h
@@ -140,6 +140,8 @@ enum add_key_case {

 #define LCORE_CACHE_SIZE   64

+#define RTE_HASH_MAX_PUSHES 100
+
 #define RTE_HASH_BFS_QUEUE_MAX_LEN   1000

 #define RTE_XABORT_CUCKOO_PATH_INVALIDED 0x4
-- 
2.7.4



[dpdk-dev] [PATCH] crypto/libcrypto: fix init function names

2016-10-11 Thread Pablo de Lara
All init/uninit function names in the virtual devices have been renamed,
so they finish with probe or remove, so to keep consistency,
same thing should be done in this PMD.

Fixes: d61f70b4c918 ("crypto/libcrypto: add driver for OpenSSL library")

Signed-off-by: Pablo de Lara 
---
 drivers/crypto/libcrypto/rte_libcrypto_pmd.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/libcrypto/rte_libcrypto_pmd.c 
b/drivers/crypto/libcrypto/rte_libcrypto_pmd.c
index 535fb57..b2c571d 100644
--- a/drivers/crypto/libcrypto/rte_libcrypto_pmd.c
+++ b/drivers/crypto/libcrypto/rte_libcrypto_pmd.c
@@ -42,7 +42,7 @@

 #include "rte_libcrypto_pmd_private.h"

-static int cryptodev_libcrypto_uninit(const char *name);
+static int cryptodev_libcrypto_remove(const char *name);

 
/**/

@@ -1008,13 +1008,13 @@ cryptodev_libcrypto_create(const char *name,
 init_error:
LIBCRYPTO_LOG_ERR("driver %s: cryptodev_libcrypto_create failed", name);

-   cryptodev_libcrypto_uninit(crypto_dev_name);
+   cryptodev_libcrypto_remove(crypto_dev_name);
return -EFAULT;
 }

 /** Initialise LIBCRYPTO crypto device */
 static int
-cryptodev_libcrypto_init(const char *name,
+cryptodev_libcrypto_probe(const char *name,
const char *input_args)
 {
struct rte_crypto_vdev_init_params init_params = {
@@ -1037,7 +1037,7 @@ cryptodev_libcrypto_init(const char *name,

 /** Uninitialise LIBCRYPTO crypto device */
 static int
-cryptodev_libcrypto_uninit(const char *name)
+cryptodev_libcrypto_remove(const char *name)
 {
if (name == NULL)
return -EINVAL;
@@ -1050,8 +1050,8 @@ cryptodev_libcrypto_uninit(const char *name)
 }

 static struct rte_vdev_driver cryptodev_libcrypto_pmd_drv = {
-   .probe = cryptodev_libcrypto_init,
-   .remove = cryptodev_libcrypto_uninit
+   .probe = cryptodev_libcrypto_probe,
+   .remove = cryptodev_libcrypto_remove
 };

 DRIVER_REGISTER_VDEV(CRYPTODEV_NAME_LIBCRYPTO_PMD, 
cryptodev_libcrypto_pmd_drv);
-- 
2.7.4



[dpdk-dev] [PATCH] crypto/zuc: fix init function names

2016-10-11 Thread Pablo de Lara
All init/uninit function names in the virtual devices have been renamed,
so they finish with probe or remove, so to keep consistency,
same thing should be done in this PMD.

Fixes: cf7685d68f00 ("crypto/zuc: add driver for ZUC library")

Signed-off-by: Pablo de Lara 
---
 drivers/crypto/zuc/rte_zuc_pmd.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/zuc/rte_zuc_pmd.c b/drivers/crypto/zuc/rte_zuc_pmd.c
index 457f3ca..403dca9 100644
--- a/drivers/crypto/zuc/rte_zuc_pmd.c
+++ b/drivers/crypto/zuc/rte_zuc_pmd.c
@@ -445,7 +445,7 @@ zuc_pmd_dequeue_burst(void *queue_pair,
return nb_dequeued;
 }

-static int cryptodev_zuc_uninit(const char *name);
+static int cryptodev_zuc_remove(const char *name);

 static int
 cryptodev_zuc_create(const char *name,
@@ -499,12 +499,12 @@ cryptodev_zuc_create(const char *name,
 init_error:
ZUC_LOG_ERR("driver %s: cryptodev_zuc_create failed", name);

-   cryptodev_zuc_uninit(crypto_dev_name);
+   cryptodev_zuc_remove(crypto_dev_name);
return -EFAULT;
 }

 static int
-cryptodev_zuc_init(const char *name,
+cryptodev_zuc_probe(const char *name,
const char *input_args)
 {
struct rte_crypto_vdev_init_params init_params = {
@@ -526,7 +526,7 @@ cryptodev_zuc_init(const char *name,
 }

 static int
-cryptodev_zuc_uninit(const char *name)
+cryptodev_zuc_remove(const char *name)
 {
if (name == NULL)
return -EINVAL;
@@ -539,8 +539,8 @@ cryptodev_zuc_uninit(const char *name)
 }

 static struct rte_vdev_driver cryptodev_zuc_pmd_drv = {
-   .probe = cryptodev_zuc_init,
-   .remove = cryptodev_zuc_uninit
+   .probe = cryptodev_zuc_probe,
+   .remove = cryptodev_zuc_remove
 };

 DRIVER_REGISTER_VDEV(CRYPTODEV_NAME_ZUC_PMD, cryptodev_zuc_pmd_drv);
-- 
2.7.4



[dpdk-dev] [PATCH] test: fix hash multiwriter test

2016-10-07 Thread Pablo de Lara
Hash multiwriter test consists of two subtests.
If the any of the subtests fails, the overall test should fail,
but the overall test only passed if the second subtest passed,
because the return of the first subtest was being overwritten.

Fixes: be856325cba3 ("hash: add scalable multi-writer insertion with Intel TSX")

Signed-off-by: Pablo de Lara 
---
 app/test/test_hash_multiwriter.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/app/test/test_hash_multiwriter.c b/app/test/test_hash_multiwriter.c
index 40af95d..4dcbd9d 100644
--- a/app/test/test_hash_multiwriter.c
+++ b/app/test/test_hash_multiwriter.c
@@ -247,8 +247,6 @@ err1:
 static int
 test_hash_multiwriter_main(void)
 {
-   int r = -1;
-
if (rte_lcore_count() == 1) {
printf("More than one lcore is required to do multiwriter 
test\n");
return 0;
@@ -268,14 +266,16 @@ test_hash_multiwriter_main(void)
printf("Test multi-writer with Hardware transactional 
memory\n");

use_htm = 1;
-   r = test_hash_multiwriter();
+   if (test_hash_multiwriter() < 0)
+   return -1;
}

printf("Test multi-writer without Hardware transactional memory\n");
use_htm = 0;
-   r = test_hash_multiwriter();
+   if (test_hash_multiwriter() < 0)
+   return -1;

-   return r;
+   return 0;
 }

 REGISTER_TEST_COMMAND(hash_multiwriter_autotest, test_hash_multiwriter_main);
-- 
2.7.4



[dpdk-dev] [PATCH] doc: fix typo in SNOW3G documentation

2016-10-06 Thread Pablo de Lara
Fixes: 1d0c90e6cf0b ("doc: update build instructions for libsso_snow3g")

Signed-off-by: Pablo de Lara 
---
 doc/guides/cryptodevs/snow3g.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/guides/cryptodevs/snow3g.rst b/doc/guides/cryptodevs/snow3g.rst
index f6eb538..75a08aa 100644
--- a/doc/guides/cryptodevs/snow3g.rst
+++ b/doc/guides/cryptodevs/snow3g.rst
@@ -58,7 +58,7 @@ Limitations
 Installation
 

-To build DPDK with the KASUMI_PMD the user is required to download
+To build DPDK with the SNOW3G_PMD the user is required to download
 the export controlled ``libsso_snow3g`` library, by requesting it from
 `<https://networkbuilders.intel.com/network-technologies/dpdk>`_.
 Once approval has been granted, the user needs to log in
-- 
2.7.4



[dpdk-dev] [PATCH v2] cryptodev: fix compilation error in SUSE 11 SP2

2016-10-05 Thread Pablo de Lara
This commit fixes following build error, which happens in SUSE 11 SP2,
with gcc 4.5.1:

In file included from lib/librte_cryptodev/rte_cryptodev.c:70:0:
lib/librte_cryptodev/rte_cryptodev.h:772:7:
error: flexible array member in otherwise empty struct

Fixes: 347a1e037fd3 ("lib: use C99 syntax for zero-size arrays")

Signed-off-by: Pablo de Lara 
---

Changes in v2:
- Fixed commit message

 lib/librte_cryptodev/rte_cryptodev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_cryptodev/rte_cryptodev.h 
b/lib/librte_cryptodev/rte_cryptodev.h
index d565f39..6ad5e91 100644
--- a/lib/librte_cryptodev/rte_cryptodev.h
+++ b/lib/librte_cryptodev/rte_cryptodev.h
@@ -773,7 +773,7 @@ struct rte_cryptodev_sym_session {
} __rte_aligned(8);
/**< Public symmetric session details */

-   char _private[];
+   __extension__ char _private[0];
/**< Private session material */
 };

-- 
2.7.4



[dpdk-dev] [PATCH v5 4/4] hash: modify lookup bulk pipeline

2016-10-05 Thread Pablo de Lara
From: Byron Marohn <byron.mar...@intel.com>

This patch replaces the pipelined rte_hash lookup mechanism with a
loop-and-jump model, which performs significantly better,
especially for smaller table sizes and smaller table occupancies.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
Signed-off-by: Pablo de Lara 
Acked-by: Bruce Richardson 
Acked-by: Sameh Gobriel 
---
 lib/librte_hash/rte_cuckoo_hash.c | 378 --
 lib/librte_hash/rte_cuckoo_hash.h |   3 +-
 2 files changed, 117 insertions(+), 264 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index d762f36..3324b17 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -914,44 +914,8 @@ rte_hash_get_key_with_position(const struct rte_hash *h, 
const int32_t position,
return 0;
 }

-/* Lookup bulk stage 0: Prefetch input key */
 static inline void
-lookup_stage0(unsigned *idx, uint64_t *lookup_mask,
-   const void * const *keys)
-{
-   *idx = __builtin_ctzl(*lookup_mask);
-   if (*lookup_mask == 0)
-   *idx = 0;
-
-   rte_prefetch0(keys[*idx]);
-   *lookup_mask &= ~(1llu << *idx);
-}
-
-/*
- * Lookup bulk stage 1: Calculate primary/secondary hashes
- * and prefetch primary/secondary buckets
- */
-static inline void
-lookup_stage1(unsigned idx, hash_sig_t *prim_hash, hash_sig_t *sec_hash,
-   const struct rte_hash_bucket **primary_bkt,
-   const struct rte_hash_bucket **secondary_bkt,
-   hash_sig_t *hash_vals, const void * const *keys,
-   const struct rte_hash *h)
-{
-   *prim_hash = rte_hash_hash(h, keys[idx]);
-   hash_vals[idx] = *prim_hash;
-   *sec_hash = rte_hash_secondary_hash(*prim_hash);
-
-   *primary_bkt = >buckets[*prim_hash & h->bucket_bitmask];
-   *secondary_bkt = >buckets[*sec_hash & h->bucket_bitmask];
-
-   rte_prefetch0(*primary_bkt);
-   rte_prefetch0(*secondary_bkt);
-}
-
-static inline void
-compare_signatures(unsigned int *prim_hash_matches,
-   unsigned int *sec_hash_matches,
+compare_signatures(uint32_t *prim_hash_matches, uint32_t *sec_hash_matches,
const struct rte_hash_bucket *prim_bkt,
const struct rte_hash_bucket *sec_bkt,
hash_sig_t prim_hash, hash_sig_t sec_hash,
@@ -962,11 +926,11 @@ compare_signatures(unsigned int *prim_hash_matches,
switch (sig_cmp_fn) {
 #ifdef RTE_MACHINE_CPUFLAG_AVX2
case RTE_HASH_COMPARE_AVX2:
-   *prim_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   *prim_hash_matches = 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
_mm256_load_si256(
(__m256i const *)prim_bkt->sig_current),
_mm256_set1_epi32(prim_hash)));
-   *sec_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   *sec_hash_matches = 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
_mm256_load_si256(
(__m256i const *)sec_bkt->sig_current),
_mm256_set1_epi32(sec_hash)));
@@ -975,7 +939,7 @@ compare_signatures(unsigned int *prim_hash_matches,
 #ifdef RTE_MACHINE_CPUFLAG_SSE2
case RTE_HASH_COMPARE_SSE:
/* Compare the first 4 signatures in the bucket */
-   *prim_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   *prim_hash_matches = _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
_mm_load_si128(
(__m128i const *)prim_bkt->sig_current),
_mm_set1_epi32(prim_hash)));
@@ -984,7 +948,7 @@ compare_signatures(unsigned int *prim_hash_matches,
(__m128i const 
*)_bkt->sig_current[4]),
_mm_set1_epi32(prim_hash << 4;
/* Compare the first 4 signatures in the bucket */
-   *sec_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   *sec_hash_matches = _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
_mm_load_si128(
(__m128i const *)sec_bkt->sig_current),
_mm_set1_epi32(sec_hash)));
@@ -1005,244 +969,134 @@ compare_signatures(unsigned int *prim_hash_matches,

 }

-/*
- * Lookup bulk stage 2:  Search for match hashes in primary/secondary locations
- * and prefetch first key slot
- */
+#define PREFETCH_OFFSET 4
 static inline void
-lookup_stage2(unsigned idx, hash_sig_t prim_hash, hash_sig_t sec_hash,
-   const struct rte_hash_bucket *prim_bkt,
-   const stru

[dpdk-dev] [PATCH v5 3/4] hash: add vectorized comparison

2016-10-05 Thread Pablo de Lara
From: Byron Marohn <byron.mar...@intel.com>

In lookup bulk function, the signatures of all entries
are compared against the signature of the key that is being looked up.
Now that all the signatures are together, they can be compared
with vector instructions (SSE, AVX2), achieving higher lookup performance.

Also, entries per bucket are increased to 8 when using processors
with AVX2, as 256 bits can be compared at once, which is the size of
8x32-bit signatures.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
Signed-off-by: Pablo de Lara 
Acked-by: Bruce Richardson 
Acked-by: Sameh Gobriel 
---
 lib/librte_hash/rte_cuckoo_hash.c | 76 +++
 lib/librte_hash/rte_cuckoo_hash.h | 12 ++-
 2 files changed, 81 insertions(+), 7 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index a7ee2b9..d762f36 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -284,6 +284,15 @@ rte_hash_create(const struct rte_hash_parameters *params)
h->free_slots = r;
h->hw_trans_mem_support = hw_trans_mem_support;

+#if defined(RTE_ARCH_X86)
+   if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
+   h->sig_cmp_fn = RTE_HASH_COMPARE_AVX2;
+   else if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE2))
+   h->sig_cmp_fn = RTE_HASH_COMPARE_SSE;
+   else
+#endif
+   h->sig_cmp_fn = RTE_HASH_COMPARE_SCALAR;
+
/* Turn on multi-writer only with explicit flat from user and TM
 * support.
 */
@@ -940,6 +949,62 @@ lookup_stage1(unsigned idx, hash_sig_t *prim_hash, 
hash_sig_t *sec_hash,
rte_prefetch0(*secondary_bkt);
 }

+static inline void
+compare_signatures(unsigned int *prim_hash_matches,
+   unsigned int *sec_hash_matches,
+   const struct rte_hash_bucket *prim_bkt,
+   const struct rte_hash_bucket *sec_bkt,
+   hash_sig_t prim_hash, hash_sig_t sec_hash,
+   enum rte_hash_sig_compare_function sig_cmp_fn)
+{
+   unsigned int i;
+
+   switch (sig_cmp_fn) {
+#ifdef RTE_MACHINE_CPUFLAG_AVX2
+   case RTE_HASH_COMPARE_AVX2:
+   *prim_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   _mm256_load_si256(
+   (__m256i const *)prim_bkt->sig_current),
+   _mm256_set1_epi32(prim_hash)));
+   *sec_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   _mm256_load_si256(
+   (__m256i const *)sec_bkt->sig_current),
+   _mm256_set1_epi32(sec_hash)));
+   break;
+#endif
+#ifdef RTE_MACHINE_CPUFLAG_SSE2
+   case RTE_HASH_COMPARE_SSE:
+   /* Compare the first 4 signatures in the bucket */
+   *prim_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const *)prim_bkt->sig_current),
+   _mm_set1_epi32(prim_hash)));
+   *prim_hash_matches |= (_mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const 
*)_bkt->sig_current[4]),
+   _mm_set1_epi32(prim_hash << 4;
+   /* Compare the first 4 signatures in the bucket */
+   *sec_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const *)sec_bkt->sig_current),
+   _mm_set1_epi32(sec_hash)));
+   *sec_hash_matches |= (_mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const 
*)_bkt->sig_current[4]),
+   _mm_set1_epi32(sec_hash << 4;
+   break;
+#endif
+   default:
+   for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
+   *prim_hash_matches |=
+   ((prim_hash == prim_bkt->sig_current[i]) << i);
+   *sec_hash_matches |=
+   ((sec_hash == sec_bkt->sig_current[i]) << i);
+   }
+   }
+
+}
+
 /*
  * Lookup bulk stage 2:  Search for match hashes in primary/secondary locations
  * and prefetch first key slot
@@ -952,15 +1017,14 @@ lookup_stage2(unsigned idx, hash_sig_t prim_hash, 
hash_sig_t sec_hash,
uint64_t *extra_hits_mask, const void *keys,
const struct rte_hash *h)
 {
-   unsigned prim_hash_matches, sec_hash_matches, key_idx, i;
-  

[dpdk-dev] [PATCH v5 2/4] hash: reorganize bucket structure

2016-10-05 Thread Pablo de Lara
From: Byron Marohn 

Move current signatures of all entries together in the bucket
and same with all alternative signatures, instead of having
current and alternative signatures together per entry in the bucket.
This will be benefitial in the next commits, where a vectorized
comparison will be performed, achieving better performance.

The alternative signatures have been moved away from
the current signatures, to make the key indices be consecutive
to the current signatures, as these two fields are used by lookup,
so they are in the same cache line.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
Acked-by: Bruce Richardson 
Acked-by: Sameh Gobriel 
---
 lib/librte_hash/rte_cuckoo_hash.c | 43 ++-
 lib/librte_hash/rte_cuckoo_hash.h | 17 --
 lib/librte_hash/rte_cuckoo_hash_x86.h | 20 
 3 files changed, 37 insertions(+), 43 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index 4de4422..a7ee2b9 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -421,7 +421,7 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
 */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
/* Search for space in alternative locations */
-   next_bucket_idx = bkt->signatures[i].alt & h->bucket_bitmask;
+   next_bucket_idx = bkt->sig_alt[i] & h->bucket_bitmask;
next_bkt[i] = >buckets[next_bucket_idx];
for (j = 0; j < RTE_HASH_BUCKET_ENTRIES; j++) {
if (next_bkt[i]->key_idx[j] == EMPTY_SLOT)
@@ -434,8 +434,8 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)

/* Alternative location has spare room (end of recursive function) */
if (i != RTE_HASH_BUCKET_ENTRIES) {
-   next_bkt[i]->signatures[j].alt = bkt->signatures[i].current;
-   next_bkt[i]->signatures[j].current = bkt->signatures[i].alt;
+   next_bkt[i]->sig_alt[j] = bkt->sig_current[i];
+   next_bkt[i]->sig_current[j] = bkt->sig_alt[i];
next_bkt[i]->key_idx[j] = bkt->key_idx[i];
return i;
}
@@ -461,8 +461,8 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
 */
bkt->flag[i] = 0;
if (ret >= 0) {
-   next_bkt[i]->signatures[ret].alt = bkt->signatures[i].current;
-   next_bkt[i]->signatures[ret].current = bkt->signatures[i].alt;
+   next_bkt[i]->sig_alt[ret] = bkt->sig_current[i];
+   next_bkt[i]->sig_current[ret] = bkt->sig_alt[i];
next_bkt[i]->key_idx[ret] = bkt->key_idx[i];
return i;
} else
@@ -544,8 +544,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,

/* Check if key is already inserted in primary location */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
-   if (prim_bkt->signatures[i].current == sig &&
-   prim_bkt->signatures[i].alt == alt_hash) {
+   if (prim_bkt->sig_current[i] == sig &&
+   prim_bkt->sig_alt[i] == alt_hash) {
k = (struct rte_hash_key *) ((char *)keys +
prim_bkt->key_idx[i] * 
h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -564,8 +564,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,

/* Check if key is already inserted in secondary location */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
-   if (sec_bkt->signatures[i].alt == sig &&
-   sec_bkt->signatures[i].current == alt_hash) {
+   if (sec_bkt->sig_alt[i] == sig &&
+   sec_bkt->sig_current[i] == alt_hash) {
k = (struct rte_hash_key *) ((char *)keys +
sec_bkt->key_idx[i] * 
h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -611,8 +611,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
/* Check if slot is available */
if (likely(prim_bkt->key_idx[i] == EMPTY_SLOT)) {
-   prim_bkt->signatures[i].current = sig;
-   prim_bkt->signatures[i].alt = alt_hash;
+   prim_bkt->sig_current[i] = sig;
+   prim_bkt->sig_alt[i] = alt_hash;
prim_bkt->key_idx[i] = new_idx;
break;
}
@@ -632,8 +632,8 @@ __rte_hash_add_key_with_hash(const struct 

[dpdk-dev] [PATCH v5 1/4] hash: reorder hash structure

2016-10-05 Thread Pablo de Lara
In order to optimize lookup performance, hash structure
is reordered, so all fields used for lookup will be
in the first cache line.

Signed-off-by: Pablo de Lara 
Acked-by: Bruce Richardson 
Acked-by: Sameh Gobriel 
---
 lib/librte_hash/rte_cuckoo_hash.h | 36 +---
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.h 
b/lib/librte_hash/rte_cuckoo_hash.h
index e290dab..27a47e5 100644
--- a/lib/librte_hash/rte_cuckoo_hash.h
+++ b/lib/librte_hash/rte_cuckoo_hash.h
@@ -185,30 +185,36 @@ struct rte_hash {
char name[RTE_HASH_NAMESIZE];   /**< Name of the hash. */
uint32_t entries;   /**< Total table entries. */
uint32_t num_buckets;   /**< Number of buckets in table. */
-   uint32_t key_len;   /**< Length of hash key. */
+
+   struct rte_ring *free_slots;
+   /**< Ring that stores all indexes of the free slots in the key table */
+   uint8_t hw_trans_mem_support;
+   /**< Hardware transactional memory support */
+   struct lcore_cache *local_free_slots;
+   /**< Local cache per lcore, storing some indexes of the free slots */
+   enum add_key_case add_key; /**< Multi-writer hash add behavior */
+
+   rte_spinlock_t *multiwriter_lock; /**< Multi-writer spinlock for w/o TM 
*/
+
+   /* Fields used in lookup */
+
+   uint32_t key_len __rte_cache_aligned;
+   /**< Length of hash key. */
rte_hash_function hash_func;/**< Function used to calculate hash. */
uint32_t hash_func_init_val;/**< Init value used by hash_func. */
rte_hash_cmp_eq_t rte_hash_custom_cmp_eq;
/**< Custom function used to compare keys. */
enum cmp_jump_table_case cmp_jump_table_idx;
/**< Indicates which compare function to use. */
-   uint32_t bucket_bitmask;/**< Bitmask for getting bucket index
-   from hash signature. */
+   uint32_t bucket_bitmask;
+   /**< Bitmask for getting bucket index from hash signature. */
uint32_t key_entry_size; /**< Size of each key entry. */

-   struct rte_ring *free_slots;/**< Ring that stores all indexes
-   of the free slots in the key 
table */
void *key_store;/**< Table storing all keys and data */
-   struct rte_hash_bucket *buckets;/**< Table with buckets storing 
all the
-   hash values and key 
indexes
-   to the key table*/
-   uint8_t hw_trans_mem_support;   /**< Hardware transactional
-   memory support */
-   struct lcore_cache *local_free_slots;
-   /**< Local cache per lcore, storing some indexes of the free slots */
-   enum add_key_case add_key; /**< Multi-writer hash add behavior */
-
-   rte_spinlock_t *multiwriter_lock; /**< Multi-writer spinlock for w/o TM 
*/
+   struct rte_hash_bucket *buckets;
+   /**< Table with buckets storing all the hash values and key indexes
+* to the key table.
+*/
 } __rte_cache_aligned;

 struct queue_node {
-- 
2.7.4



[dpdk-dev] [PATCH v5 0/4] Cuckoo hash enhancements

2016-10-05 Thread Pablo de Lara
This patchset improves lookup performance on the current hash library
by changing the existing lookup bulk pipeline, with an improved pipeline,
based on a loop-and-jump model, instead of the current 4-stage 2-entry pipeline.
Also, x86 vectorized intrinsics are used to improve performance when comparing 
signatures.

First patch reorganizes the order of the hash structure.
The structure takes more than one 64-byte cache line, but not all
the fields are used in the lookup operation (the most common operation).
Therefore, all these fields have been moved to the first part of the structure,
so they all fit in one cache line, improving slightly the performance in some
scenarios.

Second patch modifies the order of the bucket structure.
Currently, the buckets store all the signatures together (current and 
alternative).
In order to be able to perform a vectorized signature comparison,
all current signatures have to be together, so the order of the bucket has been 
changed,
having separated all the current signatures from the alternative signatures.

Third patch introduces x86 vectorized intrinsics.
When performing a lookup bulk operation, all current signatures in a bucket
are compared against the signature of the key being looked up.
Now that they all are together, a vectorized comparison can be performed,
which takes less instructions to be carried out.
In case of having a machine with AVX2, number of entries per bucket are
increased from 4 to 8, as AVX2 allows comparing two 256-bit values, with 
8x32-bit integers,
which are the 8 signatures on the bucket.

Fourth (and last) patch modifies the current pipeline of the lookup bulk 
function.
The new pipeline is based on a loop-and-jump model. The two key improvements 
are:

- Better prefetching: in this case, first 4 keys to be looked up are prefetched,
  and after that, the rest of the keys are prefetched at the time the 
calculation
  of the signatures are being performed. This gives more time for the CPU to
  prefetch the data requesting before actually need it, which result in less
  cache misses and therefore, higher throughput.

- Lower performance penalty when using fallback: the lookup bulk algorithm
  assumes that most times there will not be a collision in a bucket, but it 
might
  happen that two or more signatures are equal, which means that more than one
  key comparison might be necessary. In that case, only the key of the first 
hit is prefetched,
  like in the current implementation. The difference now is that if this 
comparison
  results in a miss, the information of the other keys to be compared has been 
stored,
  unlike the current implementation, which needs to perform an entire simple 
lookup again.

Changes in v5:
- Rebased against current HEAD
- Fix checkpatch warnings

Changes in v4:
- Reordered hash structure, so alt signature is at the start
  of the next cache line, and explain in the commit message
  why it has been moved
- Reordered hash structure, so name field is on top of the structure,
  leaving all the fields used in lookup in the next cache line
  (instead of the first cache line)

Changes in v3:
- Corrected the cover letter (wrong number of patches)

Changes in v2:
- Increased entries per bucket from 4 to 8 for all cases,
  so it is not architecture dependent any longer.
- Replaced compile-time signature comparison function election
  with run-time election, so best optimization available
  will be used from a single binary.
- Reordered the hash structure, so all the fields used by lookup
  are in the same cache line (first).


Byron Marohn (3):
  hash: reorganize bucket structure
  hash: add vectorized comparison
  hash: modify lookup bulk pipeline

Pablo de Lara (1):
  hash: reorder hash structure

 lib/librte_hash/rte_cuckoo_hash.c | 455 ++
 lib/librte_hash/rte_cuckoo_hash.h |  68 ++---
 lib/librte_hash/rte_cuckoo_hash_x86.h |  20 +-
 3 files changed, 235 insertions(+), 308 deletions(-)

-- 
2.7.4



[dpdk-dev] [PATCH] hash: fix incorrect free slot check

2016-10-04 Thread Pablo de Lara
In function rte_hash_cuckoo_insert_mw_tm, while looking for
an empty slot, only the first entry in the bucket was being checked,
as key_idx array was not being iterated.

Fixes: 5fc74c2e146d ("hash: check if slot is empty with key index")

Reported-by: Bruce Richardson 
Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash_x86.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash_x86.h 
b/lib/librte_hash/rte_cuckoo_hash_x86.h
index e16d69c..7ffa56f 100644
--- a/lib/librte_hash/rte_cuckoo_hash_x86.h
+++ b/lib/librte_hash/rte_cuckoo_hash_x86.h
@@ -53,7 +53,7 @@ rte_hash_cuckoo_insert_mw_tm(struct rte_hash_bucket *prim_bkt,
*/
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
/* Check if slot is available */
-   if (likely(prim_bkt->key_idx == EMPTY_SLOT)) {
+   if (likely(prim_bkt->key_idx[i] == EMPTY_SLOT)) 
{
prim_bkt->signatures[i].current = sig;
prim_bkt->signatures[i].alt = alt_hash;
prim_bkt->key_idx[i] = new_idx;
-- 
2.7.4



[dpdk-dev] [PATCH v2] kni: support RHEL 7.3

2016-09-16 Thread Pablo de Lara
Add support for RHEL 7.3, which uses kernel 3.10,
but backported features from newer kernels.

Signed-off-by: Pablo de Lara 
---
Changes in v2:
- Simplified conditional logic

 lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h 
b/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h
index bdd0806..e28d113 100644
--- a/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h
+++ b/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h
@@ -3891,7 +3891,7 @@ skb_set_hash(struct sk_buff *skb, __u32 hash, 
__always_unused int type)
 #if (( LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0) ) \
 || ( RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,2) ))
 #define HAVE_NDO_DFLT_BRIDGE_ADD_MASK
-#if (!( RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,2) ))
+#if ( RHEL_RELEASE_CODE != RHEL_RELEASE_VERSION(7,2) )
 #define HAVE_NDO_FDB_ADD_VID
 #endif /* !RHEL 7.2 */
 #endif /* >= 3.19.0 */
@@ -3901,12 +3901,13 @@ skb_set_hash(struct sk_buff *skb, __u32 hash, 
__always_unused int type)
 /* vlan_tx_xx functions got renamed to skb_vlan */
 #define vlan_tx_tag_get skb_vlan_tag_get
 #define vlan_tx_tag_present skb_vlan_tag_present
-#if (!( RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,2) ))
+#if ( RHEL_RELEASE_CODE != RHEL_RELEASE_VERSION(7,2) )
 #define HAVE_NDO_BRIDGE_SET_DEL_LINK_FLAGS
 #endif /* !RHEL 7.2 */
 #endif /* 4.0.0 */

-#if ( LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0) )
+#if (( LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0) ) \
+|| ( RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,3) ))
 /* ndo_bridge_getlink adds new nlflags parameter */
 #define HAVE_NDO_BRIDGE_GETLINK_NLFLAGS
 #endif /* >= 4.1.0 */
-- 
2.7.4



[dpdk-dev] [PATCH v3] tools: add crypto device details

2016-09-16 Thread Pablo de Lara
From: Eoin Breen <eoin.br...@intel.com>

Adding the support to bind/unbind crypto devices with
dpdk-devbind.py script, as now it is not restricted
to network devices anymore.

Signed-off-by: Eoin Breen 
Signed-off-by: Pablo de Lara 
---
Changes since v2:
* Removed network specific parameters from crypto parameters

Changes since v1:
* Resolved coding issues

 tools/dpdk-devbind.py | 90 ++-
 1 file changed, 82 insertions(+), 8 deletions(-)

diff --git a/tools/dpdk-devbind.py b/tools/dpdk-devbind.py
index b69ca2a..f4fda4b 100755
--- a/tools/dpdk-devbind.py
+++ b/tools/dpdk-devbind.py
@@ -40,6 +40,7 @@ from os.path import exists, abspath, dirname, basename

 # The PCI base class for NETWORK devices
 NETWORK_BASE_CLASS = "02"
+CRYPTO_BASE_CLASS = "0b"

 # global dict ethernet devices present. Dictionary indexed by PCI address.
 # Each device within this is itself a dictionary of device properties
@@ -299,6 +300,54 @@ def get_nic_details():
 devices[d]["Module_str"] = ",".join(modules)


+def get_crypto_details():
+'''This function populates the "devices" dictionary. The keys used are
+the pci addresses (domain:bus:slot.func). The values are themselves
+dictionaries - one for each NIC.'''
+global devices
+global dpdk_drivers
+
+# clear any old data
+# devices = {}
+# first loop through and read details for all devices
+# request machine readable format, with numeric IDs
+dev = {}
+dev_lines = check_output(["lspci", "-Dvmmn"]).splitlines()
+for dev_line in dev_lines:
+if (len(dev_line) == 0):
+if (dev["Class"][0:2] == CRYPTO_BASE_CLASS):
+# convert device and vendor ids to numbers, then add to global
+dev["Vendor"] = int(dev["Vendor"], 16)
+dev["Device"] = int(dev["Device"], 16)
+# use dict to make copy of dev
+devices[dev["Slot"]] = dict(dev)
+else:
+name, value = dev_line.decode().split("\t", 1)
+dev[name.rstrip(":")] = value
+
+# based on the basic info, get extended text details
+for d in devices.keys():
+# get additional info and add it to existing data
+devices[d] = devices[d].copy()
+devices[d].update(get_pci_device_details(d).items())
+
+# add igb_uio to list of supporting modules if needed
+if "Module_str" in devices[d]:
+for driver in dpdk_drivers:
+if driver not in devices[d]["Module_str"]:
+devices[d]["Module_str"] = \
+devices[d]["Module_str"] + ",%s" % driver
+else:
+devices[d]["Module_str"] = ",".join(dpdk_drivers)
+
+# make sure the driver and module strings do not have any duplicates
+if has_driver(d):
+modules = devices[d]["Module_str"].split(",")
+if devices[d]["Driver_str"] in modules:
+modules.remove(devices[d]["Driver_str"])
+devices[d]["Module_str"] = ",".join(modules)
+
+
 def dev_id_from_dev_name(dev_name):
 '''Take a device "name" - a string passed in by user to identify a NIC
 device, and determine the device id - i.e. the domain:bus:slot.func - for
@@ -480,15 +529,16 @@ def show_status():
 dpdk_drv = []
 no_drv = []

-# split our list of devices into the three categories above
+# split our list of network devices into the three categories above
 for d in devices.keys():
-if not has_driver(d):
-no_drv.append(devices[d])
-continue
-if devices[d]["Driver_str"] in dpdk_drivers:
-dpdk_drv.append(devices[d])
-else:
-kernel_drv.append(devices[d])
+if (NETWORK_BASE_CLASS in devices[d]["Class"]):
+if not has_driver(d):
+no_drv.append(devices[d])
+continue
+if devices[d]["Driver_str"] in dpdk_drivers:
+dpdk_drv.append(devices[d])
+else:
+kernel_drv.append(devices[d])

 # print each category separately, so we can clearly see what's used by DPDK
 display_devices("Network devices using DPDK-compatible driver", dpdk_drv,
@@ -498,6 +548,28 @@ def show_status():
 "unused=%(Module_str)s %(Active)s")
 display_devices("Other network devices", no_drv, "unused=%(Module_str)s")

+# split our list of crypto devices into the three categories above
+kernel_drv = []
+dpdk_drv = []
+no_drv = []
+
+for d in devices.keys():
+if (CRYPTO_BAS

[dpdk-dev] [PATCH v2] maintainers: claim responsability for crypto subtree

2016-09-16 Thread Pablo de Lara
>From 16.07, I will be the maintainer of the crypto subtree.

This will include:
- app/test/test_cryptodev*
- doc/guides/cryptodevs/
- drivers/crypto/
- examples/l2fwd-crypto/
- examples/ipsec-secgw/
- lib/librte_cryptodev/

Signed-off-by: Pablo de Lara 
---
Changes in v2:
- Included subtree path

 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index bc9aa02..fcb549d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -398,6 +398,8 @@ F: drivers/net/null/

 Crypto Drivers
 --
+M: Pablo de Lara 
+T: git://dpdk.org/next/dpdk-next-crypto

 Intel AES-NI GCM PMD
 M: Declan Doherty 
-- 
2.7.4



[dpdk-dev] [PATCH] kni: support RHEL 7.3

2016-09-14 Thread Pablo de Lara
Add support for RHEL 7.3, which uses kernel 3.10,
but backported features from newer kernels.

Signed-off-by: Pablo de Lara 
---
 lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h 
b/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h
index bdd0806..1e20a9e 100644
--- a/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h
+++ b/lib/librte_eal/linuxapp/kni/ethtool/igb/kcompat.h
@@ -3891,7 +3891,7 @@ skb_set_hash(struct sk_buff *skb, __u32 hash, 
__always_unused int type)
 #if (( LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0) ) \
 || ( RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,2) ))
 #define HAVE_NDO_DFLT_BRIDGE_ADD_MASK
-#if (!( RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,2) ))
+#if (!( RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7,2) ))
 #define HAVE_NDO_FDB_ADD_VID
 #endif /* !RHEL 7.2 */
 #endif /* >= 3.19.0 */
@@ -3901,12 +3901,13 @@ skb_set_hash(struct sk_buff *skb, __u32 hash, 
__always_unused int type)
 /* vlan_tx_xx functions got renamed to skb_vlan */
 #define vlan_tx_tag_get skb_vlan_tag_get
 #define vlan_tx_tag_present skb_vlan_tag_present
-#if (!( RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,2) ))
+#if (!( RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7,2) ))
 #define HAVE_NDO_BRIDGE_SET_DEL_LINK_FLAGS
 #endif /* !RHEL 7.2 */
 #endif /* 4.0.0 */

-#if ( LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0) )
+#if (( LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0) ) \
+|| ( RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,3) ))
 /* ndo_bridge_getlink adds new nlflags parameter */
 #define HAVE_NDO_BRIDGE_GETLINK_NLFLAGS
 #endif /* >= 4.1.0 */
-- 
2.7.4



[dpdk-dev] [PATCH v3 4/4] hash: modify lookup bulk pipeline

2016-09-06 Thread Pablo de Lara
From: Byron Marohn <byron.mar...@intel.com>

This patch replaces the pipelined rte_hash lookup mechanism with a
loop-and-jump model, which performs significantly better,
especially for smaller table sizes and smaller table occupancies.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 377 --
 lib/librte_hash/rte_cuckoo_hash.h |   3 +-
 2 files changed, 117 insertions(+), 263 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index eab28a1..47b5beb 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -913,43 +913,8 @@ rte_hash_get_key_with_position(const struct rte_hash *h, 
const int32_t position,
return 0;
 }

-/* Lookup bulk stage 0: Prefetch input key */
 static inline void
-lookup_stage0(unsigned *idx, uint64_t *lookup_mask,
-   const void * const *keys)
-{
-   *idx = __builtin_ctzl(*lookup_mask);
-   if (*lookup_mask == 0)
-   *idx = 0;
-
-   rte_prefetch0(keys[*idx]);
-   *lookup_mask &= ~(1llu << *idx);
-}
-
-/*
- * Lookup bulk stage 1: Calculate primary/secondary hashes
- * and prefetch primary/secondary buckets
- */
-static inline void
-lookup_stage1(unsigned idx, hash_sig_t *prim_hash, hash_sig_t *sec_hash,
-   const struct rte_hash_bucket **primary_bkt,
-   const struct rte_hash_bucket **secondary_bkt,
-   hash_sig_t *hash_vals, const void * const *keys,
-   const struct rte_hash *h)
-{
-   *prim_hash = rte_hash_hash(h, keys[idx]);
-   hash_vals[idx] = *prim_hash;
-   *sec_hash = rte_hash_secondary_hash(*prim_hash);
-
-   *primary_bkt = >buckets[*prim_hash & h->bucket_bitmask];
-   *secondary_bkt = >buckets[*sec_hash & h->bucket_bitmask];
-
-   rte_prefetch0(*primary_bkt);
-   rte_prefetch0(*secondary_bkt);
-}
-
-static inline void
-compare_signatures(unsigned *prim_hash_matches, unsigned *sec_hash_matches,
+compare_signatures(uint32_t *prim_hash_matches, uint32_t *sec_hash_matches,
const struct rte_hash_bucket *prim_bkt,
const struct rte_hash_bucket *sec_bkt,
hash_sig_t prim_hash, hash_sig_t sec_hash,
@@ -960,11 +925,11 @@ compare_signatures(unsigned *prim_hash_matches, unsigned 
*sec_hash_matches,
switch (sig_cmp_fn) {
 #ifdef RTE_MACHINE_CPUFLAG_AVX2
case RTE_HASH_COMPARE_AVX2:
-   *prim_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   *prim_hash_matches = 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
_mm256_load_si256(
(__m256i const *)prim_bkt->sig_current),
_mm256_set1_epi32(prim_hash)));
-   *sec_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   *sec_hash_matches = 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
_mm256_load_si256(
(__m256i const *)sec_bkt->sig_current),
_mm256_set1_epi32(sec_hash)));
@@ -973,7 +938,7 @@ compare_signatures(unsigned *prim_hash_matches, unsigned 
*sec_hash_matches,
 #ifdef RTE_MACHINE_CPUFLAG_SSE2
case RTE_HASH_COMPARE_SSE:
/* Compare the first 4 signatures in the bucket */
-   *prim_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   *prim_hash_matches = _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
_mm_load_si128(
(__m128i const *)prim_bkt->sig_current),
_mm_set1_epi32(prim_hash)));
@@ -982,7 +947,7 @@ compare_signatures(unsigned *prim_hash_matches, unsigned 
*sec_hash_matches,
(__m128i const 
*)_bkt->sig_current[4]),
_mm_set1_epi32(prim_hash << 4;
/* Compare the first 4 signatures in the bucket */
-   *sec_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   *sec_hash_matches = _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
_mm_load_si128(
(__m128i const *)sec_bkt->sig_current),
_mm_set1_epi32(sec_hash)));
@@ -1003,244 +968,134 @@ compare_signatures(unsigned *prim_hash_matches, 
unsigned *sec_hash_matches,

 }

-/*
- * Lookup bulk stage 2:  Search for match hashes in primary/secondary locations
- * and prefetch first key slot
- */
+#define PREFETCH_OFFSET 4
 static inline void
-lookup_stage2(unsigned idx, hash_sig_t prim_hash, hash_sig_t sec_hash,
-   const struct rte_hash_bucket *prim_b

[dpdk-dev] [PATCH v3 3/4] hash: add vectorized comparison

2016-09-06 Thread Pablo de Lara
From: Byron Marohn <byron.mar...@intel.com>

In lookup bulk function, the signatures of all entries
are compared against the signature of the key that is being looked up.
Now that all the signatures are together, they can be compared
with vector instructions (SSE, AVX2), achieving higher lookup performance.

Also, entries per bucket are increased to 8 when using processors
with AVX2, as 256 bits can be compared at once, which is the size of
8x32-bit signatures.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 73 ---
 lib/librte_hash/rte_cuckoo_hash.h | 12 ++-
 2 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index 9d507b6..eab28a1 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -283,6 +283,15 @@ rte_hash_create(const struct rte_hash_parameters *params)
h->free_slots = r;
h->hw_trans_mem_support = hw_trans_mem_support;

+#if defined(RTE_ARCH_X86)
+   if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
+   h->sig_cmp_fn = RTE_HASH_COMPARE_AVX2;
+   else if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE2))
+   h->sig_cmp_fn = RTE_HASH_COMPARE_SSE;
+   else
+#endif
+   h->sig_cmp_fn = RTE_HASH_COMPARE_SCALAR;
+
/* Turn on multi-writer only with explicit flat from user and TM
 * support.
 */
@@ -939,6 +948,61 @@ lookup_stage1(unsigned idx, hash_sig_t *prim_hash, 
hash_sig_t *sec_hash,
rte_prefetch0(*secondary_bkt);
 }

+static inline void
+compare_signatures(unsigned *prim_hash_matches, unsigned *sec_hash_matches,
+   const struct rte_hash_bucket *prim_bkt,
+   const struct rte_hash_bucket *sec_bkt,
+   hash_sig_t prim_hash, hash_sig_t sec_hash,
+   enum rte_hash_sig_compare_function sig_cmp_fn)
+{
+   unsigned i;
+
+   switch (sig_cmp_fn) {
+#ifdef RTE_MACHINE_CPUFLAG_AVX2
+   case RTE_HASH_COMPARE_AVX2:
+   *prim_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   _mm256_load_si256(
+   (__m256i const *)prim_bkt->sig_current),
+   _mm256_set1_epi32(prim_hash)));
+   *sec_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   _mm256_load_si256(
+   (__m256i const *)sec_bkt->sig_current),
+   _mm256_set1_epi32(sec_hash)));
+   break;
+#endif
+#ifdef RTE_MACHINE_CPUFLAG_SSE2
+   case RTE_HASH_COMPARE_SSE:
+   /* Compare the first 4 signatures in the bucket */
+   *prim_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const *)prim_bkt->sig_current),
+   _mm_set1_epi32(prim_hash)));
+   *prim_hash_matches |= (_mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const 
*)_bkt->sig_current[4]),
+   _mm_set1_epi32(prim_hash << 4;
+   /* Compare the first 4 signatures in the bucket */
+   *sec_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const *)sec_bkt->sig_current),
+   _mm_set1_epi32(sec_hash)));
+   *sec_hash_matches |= (_mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const 
*)_bkt->sig_current[4]),
+   _mm_set1_epi32(sec_hash << 4;
+   break;
+#endif
+   default:
+   for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
+   *prim_hash_matches |=
+   ((prim_hash == prim_bkt->sig_current[i]) << i);
+   *sec_hash_matches |=
+   ((sec_hash == sec_bkt->sig_current[i]) << i);
+   }
+   }
+
+}
+
 /*
  * Lookup bulk stage 2:  Search for match hashes in primary/secondary locations
  * and prefetch first key slot
@@ -951,15 +1015,14 @@ lookup_stage2(unsigned idx, hash_sig_t prim_hash, 
hash_sig_t sec_hash,
uint64_t *extra_hits_mask, const void *keys,
const struct rte_hash *h)
 {
-   unsigned prim_hash_matches, sec_hash_matches, key_idx, i;
+   unsigned prim_hash_matches, sec_hash_matches, key_

[dpdk-dev] [PATCH v3 2/4] hash: reorganize bucket structure

2016-09-06 Thread Pablo de Lara
From: Byron Marohn 

Move current signatures of all entries together in the bucket
and same with all alternative signatures, instead of having
current and alternative signatures together per entry in the bucket.
This will be benefitial in the next commits, where a vectorized
comparison will be performed, achieving better performance.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
---
 lib/librte_hash/rte_cuckoo_hash.c | 43 ++-
 lib/librte_hash/rte_cuckoo_hash.h | 17 --
 lib/librte_hash/rte_cuckoo_hash_x86.h | 20 
 3 files changed, 37 insertions(+), 43 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index dd0290f..9d507b6 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -420,7 +420,7 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
 */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
/* Search for space in alternative locations */
-   next_bucket_idx = bkt->signatures[i].alt & h->bucket_bitmask;
+   next_bucket_idx = bkt->sig_alt[i] & h->bucket_bitmask;
next_bkt[i] = >buckets[next_bucket_idx];
for (j = 0; j < RTE_HASH_BUCKET_ENTRIES; j++) {
if (next_bkt[i]->key_idx[j] == EMPTY_SLOT)
@@ -433,8 +433,8 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)

/* Alternative location has spare room (end of recursive function) */
if (i != RTE_HASH_BUCKET_ENTRIES) {
-   next_bkt[i]->signatures[j].alt = bkt->signatures[i].current;
-   next_bkt[i]->signatures[j].current = bkt->signatures[i].alt;
+   next_bkt[i]->sig_alt[j] = bkt->sig_current[i];
+   next_bkt[i]->sig_current[j] = bkt->sig_alt[i];
next_bkt[i]->key_idx[j] = bkt->key_idx[i];
return i;
}
@@ -460,8 +460,8 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
 */
bkt->flag[i] = 0;
if (ret >= 0) {
-   next_bkt[i]->signatures[ret].alt = bkt->signatures[i].current;
-   next_bkt[i]->signatures[ret].current = bkt->signatures[i].alt;
+   next_bkt[i]->sig_alt[ret] = bkt->sig_current[i];
+   next_bkt[i]->sig_current[ret] = bkt->sig_alt[i];
next_bkt[i]->key_idx[ret] = bkt->key_idx[i];
return i;
} else
@@ -543,8 +543,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,

/* Check if key is already inserted in primary location */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
-   if (prim_bkt->signatures[i].current == sig &&
-   prim_bkt->signatures[i].alt == alt_hash) {
+   if (prim_bkt->sig_current[i] == sig &&
+   prim_bkt->sig_alt[i] == alt_hash) {
k = (struct rte_hash_key *) ((char *)keys +
prim_bkt->key_idx[i] * 
h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -563,8 +563,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,

/* Check if key is already inserted in secondary location */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
-   if (sec_bkt->signatures[i].alt == sig &&
-   sec_bkt->signatures[i].current == alt_hash) {
+   if (sec_bkt->sig_alt[i] == sig &&
+   sec_bkt->sig_current[i] == alt_hash) {
k = (struct rte_hash_key *) ((char *)keys +
sec_bkt->key_idx[i] * 
h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -610,8 +610,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
/* Check if slot is available */
if (likely(prim_bkt->key_idx[i] == EMPTY_SLOT)) {
-   prim_bkt->signatures[i].current = sig;
-   prim_bkt->signatures[i].alt = alt_hash;
+   prim_bkt->sig_current[i] = sig;
+   prim_bkt->sig_alt[i] = alt_hash;
prim_bkt->key_idx[i] = new_idx;
break;
}
@@ -631,8 +631,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,
 */
ret = make_space_bucket(h, prim_bkt);
if (ret >= 0) {
-   prim_bkt->signatures[ret].current = sig;
-   prim_bkt->signatures[ret].alt = alt_hash;
+

[dpdk-dev] [PATCH v3 1/4] hash: reorder hash structure

2016-09-06 Thread Pablo de Lara
In order to optimize lookup performance, hash structure
is reordered, so all fields used for lookup will be
in the first cache line.

Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.h | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.h 
b/lib/librte_hash/rte_cuckoo_hash.h
index e290dab..701531a 100644
--- a/lib/librte_hash/rte_cuckoo_hash.h
+++ b/lib/librte_hash/rte_cuckoo_hash.h
@@ -182,9 +182,7 @@ struct rte_hash_bucket {

 /** A hash table structure. */
 struct rte_hash {
-   char name[RTE_HASH_NAMESIZE];   /**< Name of the hash. */
-   uint32_t entries;   /**< Total table entries. */
-   uint32_t num_buckets;   /**< Number of buckets in table. */
+   /* first cache line - fields used in lookup */
uint32_t key_len;   /**< Length of hash key. */
rte_hash_function hash_func;/**< Function used to calculate hash. */
uint32_t hash_func_init_val;/**< Init value used by hash_func. */
@@ -196,12 +194,13 @@ struct rte_hash {
from hash signature. */
uint32_t key_entry_size; /**< Size of each key entry. */

-   struct rte_ring *free_slots;/**< Ring that stores all indexes
-   of the free slots in the key 
table */
void *key_store;/**< Table storing all keys and data */
struct rte_hash_bucket *buckets;/**< Table with buckets storing 
all the
hash values and key 
indexes
to the key table*/
+
+   struct rte_ring *free_slots;/**< Ring that stores all indexes
+   of the free slots in the key 
table */
uint8_t hw_trans_mem_support;   /**< Hardware transactional
memory support */
struct lcore_cache *local_free_slots;
@@ -209,6 +208,9 @@ struct rte_hash {
enum add_key_case add_key; /**< Multi-writer hash add behavior */

rte_spinlock_t *multiwriter_lock; /**< Multi-writer spinlock for w/o TM 
*/
+   char name[RTE_HASH_NAMESIZE];   /**< Name of the hash. */
+   uint32_t entries;   /**< Total table entries. */
+   uint32_t num_buckets;   /**< Number of buckets in table. */
 } __rte_cache_aligned;

 struct queue_node {
-- 
2.7.4



[dpdk-dev] [PATCH v3 0/4] Cuckoo hash lookup enhancements

2016-09-06 Thread Pablo de Lara
This patchset improves lookup performance on the current hash library
by changing the existing lookup bulk pipeline, with an improved pipeline,
based on a loop-and-jump model, instead of the current 4-stage 2-entry pipeline.
Also, x86 vectorized intrinsics are used to improve performance when comparing 
signatures.

First patch reorganizes the order of the hash structure.
The structure takes more than one 64-byte cache line, but not all
the fields are used in the lookup operation (the most common operation).
Therefore, all these fields have been moved to the first part of the structure,
so they all fit in one cache line, improving slightly the performance in some
scenarios.

Second patch modifies the order of the bucket structure.
Currently, the buckets store all the signatures together (current and 
alternative).
In order to be able to perform a vectorized signature comparison,
all current signatures have to be together, so the order of the bucket has been 
changed,
having separated all the current signatures from the alternative signatures.

Third patch introduces x86 vectorized intrinsics.
When performing a lookup bulk operation, all current signatures in a bucket
are compared against the signature of the key being looked up.
Now that they all are together, a vectorized comparison can be performed,
which takes less instructions to be carried out.
In case of having a machine with AVX2, number of entries per bucket are
increased from 4 to 8, as AVX2 allows comparing two 256-bit values, with 
8x32-bit integers,
which are the 8 signatures on the bucket.

Fourth (and last) patch modifies the current pipeline of the lookup bulk 
function.
The new pipeline is based on a loop-and-jump model. The two key improvements 
are:

- Better prefetching: in this case, first 4 keys to be looked up are prefetched,
  and after that, the rest of the keys are prefetched at the time the 
calculation
  of the signatures are being performed. This gives more time for the CPU to
  prefetch the data requesting before actually need it, which result in less
  cache misses and therefore, higher throughput.

- Lower performance penalty when using fallback: the lookup bulk algorithm
  assumes that most times there will not be a collision in a bucket, but it 
might
  happen that two or more signatures are equal, which means that more than one
  key comparison might be necessary. In that case, only the key of the first 
hit is prefetched,
  like in the current implementation. The difference now is that if this 
comparison
  results in a miss, the information of the other keys to be compared has been 
stored,
  unlike the current implementation, which needs to perform an entire simple 
lookup again.

This patchset depends on the following patchset:
"Hash library fixes" (http://dpdk.org/ml/archives/dev/2016-August/045780.html)

Changes in v3:
- Corrected the cover letter (wrong number of patches)

Changes in v2:
- Increased entries per bucket from 4 to 8 for all cases,
  so it is not architecture dependent any longer.
- Replaced compile-time signature comparison function election
  with run-time election, so best optimization available
  will be used from a single binary.
- Reordered the hash structure, so all the fields used by lookup
  are in the same cache line (first).

Byron Marohn (3):
  hash: reorganize bucket structure
  hash: add vectorized comparison
  hash: modify lookup bulk pipeline

Pablo de Lara (1):
  hash: reorder hash structure

 lib/librte_hash/rte_cuckoo_hash.c | 455 ++
 lib/librte_hash/rte_cuckoo_hash.h |  44 ++--
 lib/librte_hash/rte_cuckoo_hash_x86.h |  20 +-
 3 files changed, 221 insertions(+), 298 deletions(-)

-- 
2.7.4



[dpdk-dev] [PATCH v3 0/4] Cuckoo hash lookup enhancements

2016-09-06 Thread Pablo de Lara
This patchset improves lookup performance on the current hash library
by changing the existing lookup bulk pipeline, with an improved pipeline,
based on a loop-and-jump model, instead of the current 4-stage 2-entry pipeline.
Also, x86 vectorized intrinsics are used to improve performance when comparing 
signatures.

First patch reorganizes the order of the hash structure.
The structure takes more than one 64-byte cache line, but not all
the fields are used in the lookup operation (the most common operation).
Therefore, all these fields have been moved to the first part of the structure,
so they all fit in one cache line, improving slightly the performance in some
scenarios.

Second patch modifies the order of the bucket structure.
Currently, the buckets store all the signatures together (current and 
alternative).
In order to be able to perform a vectorized signature comparison,
all current signatures have to be together, so the order of the bucket has been 
changed,
having separated all the current signatures from the alternative signatures.

Third patch introduces x86 vectorized intrinsics.
When performing a lookup bulk operation, all current signatures in a bucket
are compared against the signature of the key being looked up.
Now that they all are together, a vectorized comparison can be performed,
which takes less instructions to be carried out.
In case of having a machine with AVX2, number of entries per bucket are
increased from 4 to 8, as AVX2 allows comparing two 256-bit values, with 
8x32-bit integers,
which are the 8 signatures on the bucket.

Fourth (and last) patch modifies the current pipeline of the lookup bulk 
function.
The new pipeline is based on a loop-and-jump model. The two key improvements 
are:

- Better prefetching: in this case, first 4 keys to be looked up are prefetched,
  and after that, the rest of the keys are prefetched at the time the 
calculation
  of the signatures are being performed. This gives more time for the CPU to
  prefetch the data requesting before actually need it, which result in less
  cache misses and therefore, higher throughput.

- Lower performance penalty when using fallback: the lookup bulk algorithm
  assumes that most times there will not be a collision in a bucket, but it 
might
  happen that two or more signatures are equal, which means that more than one
  key comparison might be necessary. In that case, only the key of the first 
hit is prefetched,
  like in the current implementation. The difference now is that if this 
comparison
  results in a miss, the information of the other keys to be compared has been 
stored,
  unlike the current implementation, which needs to perform an entire simple 
lookup again.

This patchset depends on the following patchset:
"Hash library fixes" (http://dpdk.org/ml/archives/dev/2016-August/045780.html)

Changes in v3:
- Corrected the cover letter (wrong number of patches)

Changes in v2:
- Increased entries per bucket from 4 to 8 for all cases,
  so it is not architecture dependent any longer.
- Replaced compile-time signature comparison function election
  with run-time election, so best optimization available
  will be used from a single binary.
- Reordered the hash structure, so all the fields used by lookup
  are in the same cache line (first).

Byron Marohn (3):
  hash: reorganize bucket structure
  hash: add vectorized comparison
  hash: modify lookup bulk pipeline

Pablo de Lara (1):
  hash: reorder hash structure

 lib/librte_hash/rte_cuckoo_hash.c | 455 ++
 lib/librte_hash/rte_cuckoo_hash.h |  44 ++--
 lib/librte_hash/rte_cuckoo_hash_x86.h |  20 +-
 3 files changed, 221 insertions(+), 298 deletions(-)

-- 
2.7.4



[dpdk-dev] [PATCH v2 4/4] hash: modify lookup bulk pipeline

2016-09-03 Thread Pablo de Lara
From: Byron Marohn <byron.mar...@intel.com>

This patch replaces the pipelined rte_hash lookup mechanism with a
loop-and-jump model, which performs significantly better,
especially for smaller table sizes and smaller table occupancies.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 377 --
 lib/librte_hash/rte_cuckoo_hash.h |   3 +-
 2 files changed, 117 insertions(+), 263 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index eab28a1..47b5beb 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -913,43 +913,8 @@ rte_hash_get_key_with_position(const struct rte_hash *h, 
const int32_t position,
return 0;
 }

-/* Lookup bulk stage 0: Prefetch input key */
 static inline void
-lookup_stage0(unsigned *idx, uint64_t *lookup_mask,
-   const void * const *keys)
-{
-   *idx = __builtin_ctzl(*lookup_mask);
-   if (*lookup_mask == 0)
-   *idx = 0;
-
-   rte_prefetch0(keys[*idx]);
-   *lookup_mask &= ~(1llu << *idx);
-}
-
-/*
- * Lookup bulk stage 1: Calculate primary/secondary hashes
- * and prefetch primary/secondary buckets
- */
-static inline void
-lookup_stage1(unsigned idx, hash_sig_t *prim_hash, hash_sig_t *sec_hash,
-   const struct rte_hash_bucket **primary_bkt,
-   const struct rte_hash_bucket **secondary_bkt,
-   hash_sig_t *hash_vals, const void * const *keys,
-   const struct rte_hash *h)
-{
-   *prim_hash = rte_hash_hash(h, keys[idx]);
-   hash_vals[idx] = *prim_hash;
-   *sec_hash = rte_hash_secondary_hash(*prim_hash);
-
-   *primary_bkt = >buckets[*prim_hash & h->bucket_bitmask];
-   *secondary_bkt = >buckets[*sec_hash & h->bucket_bitmask];
-
-   rte_prefetch0(*primary_bkt);
-   rte_prefetch0(*secondary_bkt);
-}
-
-static inline void
-compare_signatures(unsigned *prim_hash_matches, unsigned *sec_hash_matches,
+compare_signatures(uint32_t *prim_hash_matches, uint32_t *sec_hash_matches,
const struct rte_hash_bucket *prim_bkt,
const struct rte_hash_bucket *sec_bkt,
hash_sig_t prim_hash, hash_sig_t sec_hash,
@@ -960,11 +925,11 @@ compare_signatures(unsigned *prim_hash_matches, unsigned 
*sec_hash_matches,
switch (sig_cmp_fn) {
 #ifdef RTE_MACHINE_CPUFLAG_AVX2
case RTE_HASH_COMPARE_AVX2:
-   *prim_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   *prim_hash_matches = 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
_mm256_load_si256(
(__m256i const *)prim_bkt->sig_current),
_mm256_set1_epi32(prim_hash)));
-   *sec_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   *sec_hash_matches = 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
_mm256_load_si256(
(__m256i const *)sec_bkt->sig_current),
_mm256_set1_epi32(sec_hash)));
@@ -973,7 +938,7 @@ compare_signatures(unsigned *prim_hash_matches, unsigned 
*sec_hash_matches,
 #ifdef RTE_MACHINE_CPUFLAG_SSE2
case RTE_HASH_COMPARE_SSE:
/* Compare the first 4 signatures in the bucket */
-   *prim_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   *prim_hash_matches = _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
_mm_load_si128(
(__m128i const *)prim_bkt->sig_current),
_mm_set1_epi32(prim_hash)));
@@ -982,7 +947,7 @@ compare_signatures(unsigned *prim_hash_matches, unsigned 
*sec_hash_matches,
(__m128i const 
*)_bkt->sig_current[4]),
_mm_set1_epi32(prim_hash << 4;
/* Compare the first 4 signatures in the bucket */
-   *sec_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   *sec_hash_matches = _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
_mm_load_si128(
(__m128i const *)sec_bkt->sig_current),
_mm_set1_epi32(sec_hash)));
@@ -1003,244 +968,134 @@ compare_signatures(unsigned *prim_hash_matches, 
unsigned *sec_hash_matches,

 }

-/*
- * Lookup bulk stage 2:  Search for match hashes in primary/secondary locations
- * and prefetch first key slot
- */
+#define PREFETCH_OFFSET 4
 static inline void
-lookup_stage2(unsigned idx, hash_sig_t prim_hash, hash_sig_t sec_hash,
-   const struct rte_hash_bucket *prim_b

[dpdk-dev] [PATCH v2 3/4] hash: add vectorized comparison

2016-09-03 Thread Pablo de Lara
From: Byron Marohn <byron.mar...@intel.com>

In lookup bulk function, the signatures of all entries
are compared against the signature of the key that is being looked up.
Now that all the signatures are together, they can be compared
with vector instructions (SSE, AVX2), achieving higher lookup performance.

Also, entries per bucket are increased to 8 when using processors
with AVX2, as 256 bits can be compared at once, which is the size of
8x32-bit signatures.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 73 ---
 lib/librte_hash/rte_cuckoo_hash.h | 12 ++-
 2 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index 9d507b6..eab28a1 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -283,6 +283,15 @@ rte_hash_create(const struct rte_hash_parameters *params)
h->free_slots = r;
h->hw_trans_mem_support = hw_trans_mem_support;

+#if defined(RTE_ARCH_X86)
+   if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
+   h->sig_cmp_fn = RTE_HASH_COMPARE_AVX2;
+   else if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE2))
+   h->sig_cmp_fn = RTE_HASH_COMPARE_SSE;
+   else
+#endif
+   h->sig_cmp_fn = RTE_HASH_COMPARE_SCALAR;
+
/* Turn on multi-writer only with explicit flat from user and TM
 * support.
 */
@@ -939,6 +948,61 @@ lookup_stage1(unsigned idx, hash_sig_t *prim_hash, 
hash_sig_t *sec_hash,
rte_prefetch0(*secondary_bkt);
 }

+static inline void
+compare_signatures(unsigned *prim_hash_matches, unsigned *sec_hash_matches,
+   const struct rte_hash_bucket *prim_bkt,
+   const struct rte_hash_bucket *sec_bkt,
+   hash_sig_t prim_hash, hash_sig_t sec_hash,
+   enum rte_hash_sig_compare_function sig_cmp_fn)
+{
+   unsigned i;
+
+   switch (sig_cmp_fn) {
+#ifdef RTE_MACHINE_CPUFLAG_AVX2
+   case RTE_HASH_COMPARE_AVX2:
+   *prim_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   _mm256_load_si256(
+   (__m256i const *)prim_bkt->sig_current),
+   _mm256_set1_epi32(prim_hash)));
+   *sec_hash_matches |= 
_mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   _mm256_load_si256(
+   (__m256i const *)sec_bkt->sig_current),
+   _mm256_set1_epi32(sec_hash)));
+   break;
+#endif
+#ifdef RTE_MACHINE_CPUFLAG_SSE2
+   case RTE_HASH_COMPARE_SSE:
+   /* Compare the first 4 signatures in the bucket */
+   *prim_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const *)prim_bkt->sig_current),
+   _mm_set1_epi32(prim_hash)));
+   *prim_hash_matches |= (_mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const 
*)_bkt->sig_current[4]),
+   _mm_set1_epi32(prim_hash << 4;
+   /* Compare the first 4 signatures in the bucket */
+   *sec_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const *)sec_bkt->sig_current),
+   _mm_set1_epi32(sec_hash)));
+   *sec_hash_matches |= (_mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128(
+   (__m128i const 
*)_bkt->sig_current[4]),
+   _mm_set1_epi32(sec_hash << 4;
+   break;
+#endif
+   default:
+   for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
+   *prim_hash_matches |=
+   ((prim_hash == prim_bkt->sig_current[i]) << i);
+   *sec_hash_matches |=
+   ((sec_hash == sec_bkt->sig_current[i]) << i);
+   }
+   }
+
+}
+
 /*
  * Lookup bulk stage 2:  Search for match hashes in primary/secondary locations
  * and prefetch first key slot
@@ -951,15 +1015,14 @@ lookup_stage2(unsigned idx, hash_sig_t prim_hash, 
hash_sig_t sec_hash,
uint64_t *extra_hits_mask, const void *keys,
const struct rte_hash *h)
 {
-   unsigned prim_hash_matches, sec_hash_matches, key_idx, i;
+   unsigned prim_hash_matches, sec_hash_matches, key_

[dpdk-dev] [PATCH v2 0/4] Cuckoo hash lookup enhancements

2016-09-03 Thread Pablo de Lara
This patchset improves lookup performance on the current hash library
by changing the existing lookup bulk pipeline, with an improved pipeline,
based on a loop-and-jump model, instead of the current 4-stage 2-entry pipeline.
Also, x86 vectorized intrinsics are used to improve performance when comparing 
signatures.

First patch modifies the order of the bucket structure.
Currently, the buckets store all the signatures together (current and 
alternative).
In order to be able to perform a vectorized signature comparison,
all current signatures have to be together, so the order of the bucket has been 
changed,
having separated all the current signatures from the alternative signatures.

Second patch introduces x86 vectorized intrinsics.
When performing a lookup bulk operation, all current signatures in a bucket
are compared against the signature of the key being looked up.
Now that they all are together, a vectorized comparison can be performed,
which takes less instructions to be carried out.
In case of having a machine with AVX2, number of entries per bucket are
increased from 4 to 8, as AVX2 allows comparing two 256-bit values, with 
8x32-bit integers,
which are the 8 signatures on the bucket.

Third (and last) patch modifies the current pipeline of the lookup bulk 
function.
The new pipeline is based on a loop-and-jump model. The two key improvements 
are:

- Better prefetching: in this case, first 4 keys to be looked up are prefetched,
  and after that, the rest of the keys are prefetched at the time the 
calculation
  of the signatures are being performed. This gives more time for the CPU to
  prefetch the data requesting before actually need it, which result in less
  cache misses and therefore, higher throughput.

- Lower performance penalty when using fallback: the lookup bulk algorithm
  assumes that most times there will not be a collision in a bucket, but it 
might
  happen that two or more signatures are equal, which means that more than one
  key comparison might be necessary. In that case, only the key of the first 
hit is prefetched,
  like in the current implementation. The difference now is that if this 
comparison
  results in a miss, the information of the other keys to be compared has been 
stored,
  unlike the current implementation, which needs to perform an entire simple 
lookup again.

This patchset depends on the following patchset:
"Hash library fixes" (http://dpdk.org/ml/archives/dev/2016-August/045780.html)

Changes in v2:
- Increased entries per bucket from 4 to 8 for all cases,
  so it is not architecture dependent any longer.
- Replaced compile-time signature comparison function election
  with run-time election, so best optimization available
  will be used from a single binary.
- Reordered the hash structure, so all the fields used by lookup
  are in the same cache line (first).


Byron Marohn (3):
  hash: reorganize bucket structure
  hash: add vectorized comparison
  hash: modify lookup bulk pipeline

Pablo de Lara (1):
  hash: reorder hash structure

 lib/librte_hash/rte_cuckoo_hash.c | 455 ++
 lib/librte_hash/rte_cuckoo_hash.h |  44 ++--
 lib/librte_hash/rte_cuckoo_hash_x86.h |  20 +-
 3 files changed, 221 insertions(+), 298 deletions(-)

-- 
2.7.4



[dpdk-dev] [PATCH] maintainers: claim responsability for crypto subtree

2016-08-30 Thread Pablo de Lara
>From 16.07, I will be the maintainer of the crypto subtree.

This will include:
- app/test/test_cryptodev*
- doc/guides/cryptodevs/
- drivers/crypto/
- examples/l2fwd-crypto/
- examples/ipsec-secgw/
- lib/librte_cryptodev/

Signed-off-by: Pablo de Lara 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index bc9aa02..ee5118e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -398,6 +398,7 @@ F: drivers/net/null/

 Crypto Drivers
 --
+T: Pablo de Lara 

 Intel AES-NI GCM PMD
 M: Declan Doherty 
-- 
2.7.4



[dpdk-dev] [PATCH 3/3] hash: modify lookup bulk pipeline

2016-08-26 Thread Pablo de Lara
From: Byron Marohn <byron.mar...@intel.com>

This patch replaces the pipelined rte_hash lookup mechanism with a
loop-and-jump model, which performs significantly better,
especially for smaller table sizes and smaller table occupancies.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 381 --
 lib/librte_hash/rte_cuckoo_hash.h |   3 +-
 2 files changed, 121 insertions(+), 263 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index 98713d3..41acdc7 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -904,61 +904,26 @@ rte_hash_get_key_with_position(const struct rte_hash *h, 
const int32_t position,
return 0;
 }

-/* Lookup bulk stage 0: Prefetch input key */
 static inline void
-lookup_stage0(unsigned *idx, uint64_t *lookup_mask,
-   const void * const *keys)
-{
-   *idx = __builtin_ctzl(*lookup_mask);
-   if (*lookup_mask == 0)
-   *idx = 0;
-
-   rte_prefetch0(keys[*idx]);
-   *lookup_mask &= ~(1llu << *idx);
-}
-
-/*
- * Lookup bulk stage 1: Calculate primary/secondary hashes
- * and prefetch primary/secondary buckets
- */
-static inline void
-lookup_stage1(unsigned idx, hash_sig_t *prim_hash, hash_sig_t *sec_hash,
-   const struct rte_hash_bucket **primary_bkt,
-   const struct rte_hash_bucket **secondary_bkt,
-   hash_sig_t *hash_vals, const void * const *keys,
-   const struct rte_hash *h)
-{
-   *prim_hash = rte_hash_hash(h, keys[idx]);
-   hash_vals[idx] = *prim_hash;
-   *sec_hash = rte_hash_secondary_hash(*prim_hash);
-
-   *primary_bkt = >buckets[*prim_hash & h->bucket_bitmask];
-   *secondary_bkt = >buckets[*sec_hash & h->bucket_bitmask];
-
-   rte_prefetch0(*primary_bkt);
-   rte_prefetch0(*secondary_bkt);
-}
-
-static inline void
-compare_signatures(unsigned *prim_hash_matches, unsigned *sec_hash_matches,
+compare_signatures(uint32_t *prim_hash_matches, uint32_t *sec_hash_matches,
const struct rte_hash_bucket *prim_bkt,
const struct rte_hash_bucket *sec_bkt,
hash_sig_t prim_hash, hash_sig_t sec_hash)
 {
 /* 8 entries per bucket */
 #if defined(__AVX2__)
-   *prim_hash_matches |= _mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   *prim_hash_matches = _mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
_mm256_load_si256((__m256i const 
*)prim_bkt->sig_current),
_mm256_set1_epi32(prim_hash)));
-   *sec_hash_matches |= _mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   *sec_hash_matches = _mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
_mm256_load_si256((__m256i const 
*)sec_bkt->sig_current),
_mm256_set1_epi32(sec_hash)));
 /* 4 entries per bucket */
 #elif defined(__SSE2__)
-   *prim_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   *prim_hash_matches = _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
_mm_load_si128((__m128i const *)prim_bkt->sig_current),
_mm_set1_epi32(prim_hash)));
-   *sec_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   *sec_hash_matches = _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
_mm_load_si128((__m128i const *)sec_bkt->sig_current),
_mm_set1_epi32(sec_hash)));
 #else
@@ -971,244 +936,138 @@ compare_signatures(unsigned *prim_hash_matches, 
unsigned *sec_hash_matches,
 #endif
 }

-/*
- * Lookup bulk stage 2:  Search for match hashes in primary/secondary locations
- * and prefetch first key slot
- */
+#define PREFETCH_OFFSET 4
 static inline void
-lookup_stage2(unsigned idx, hash_sig_t prim_hash, hash_sig_t sec_hash,
-   const struct rte_hash_bucket *prim_bkt,
-   const struct rte_hash_bucket *sec_bkt,
-   const struct rte_hash_key **key_slot, int32_t *positions,
-   uint64_t *extra_hits_mask, const void *keys,
-   const struct rte_hash *h)
+__rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
+   int32_t num_keys, int32_t *positions,
+   uint64_t *hit_mask, void *data[])
 {
-   unsigned prim_hash_matches, sec_hash_matches, key_idx;
-   unsigned total_hash_matches;
+   uint64_t hits = 0;
+   int32_t i;
+   uint32_t prim_hash[RTE_HASH_LOOKUP_BULK_MAX];
+   uint32_t sec_hash[RTE_HASH_LOOKUP_BULK_MAX];
+   const struct rte_hash_bucket *primary_bkt[RTE_HASH_LOOKUP_BULK_MAX];
+   const struct rte_hash_bucket *secondary_bkt[RTE_HASH_LOOKUP_BULK_MAX];
+   uint32_t prim_hitmask[RTE_HASH_LOOKUP_BULK_MAX] = {0};
+   uin

[dpdk-dev] [PATCH 2/3] hash: add vectorized comparison

2016-08-26 Thread Pablo de Lara
From: Byron Marohn <byron.mar...@intel.com>

In lookup bulk function, the signatures of all entries
are compared against the signature of the key that is being looked up.
Now that all the signatures are together, they can be compared
with vector instructions (SSE, AVX2), achieving higher lookup performance.

Also, entries per bucket are increased to 8 when using processors
with AVX2, as 256 bits can be compared at once, which is the size of
8x32-bit signatures.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 41 ++-
 lib/librte_hash/rte_cuckoo_hash.h |  4 
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index 9d507b6..98713d3 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -939,6 +939,38 @@ lookup_stage1(unsigned idx, hash_sig_t *prim_hash, 
hash_sig_t *sec_hash,
rte_prefetch0(*secondary_bkt);
 }

+static inline void
+compare_signatures(unsigned *prim_hash_matches, unsigned *sec_hash_matches,
+   const struct rte_hash_bucket *prim_bkt,
+   const struct rte_hash_bucket *sec_bkt,
+   hash_sig_t prim_hash, hash_sig_t sec_hash)
+{
+/* 8 entries per bucket */
+#if defined(__AVX2__)
+   *prim_hash_matches |= _mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   _mm256_load_si256((__m256i const 
*)prim_bkt->sig_current),
+   _mm256_set1_epi32(prim_hash)));
+   *sec_hash_matches |= _mm256_movemask_ps((__m256)_mm256_cmpeq_epi32(
+   _mm256_load_si256((__m256i const 
*)sec_bkt->sig_current),
+   _mm256_set1_epi32(sec_hash)));
+/* 4 entries per bucket */
+#elif defined(__SSE2__)
+   *prim_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128((__m128i const *)prim_bkt->sig_current),
+   _mm_set1_epi32(prim_hash)));
+   *sec_hash_matches |= _mm_movemask_ps((__m128)_mm_cmpeq_epi16(
+   _mm_load_si128((__m128i const *)sec_bkt->sig_current),
+   _mm_set1_epi32(sec_hash)));
+#else
+   unsigned i;
+
+   for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
+   *prim_hash_matches |= ((prim_hash == prim_bkt->sig_current[i]) 
<< i);
+   *sec_hash_matches |= ((sec_hash == sec_bkt->sig_current[i]) << 
i);
+   }
+#endif
+}
+
 /*
  * Lookup bulk stage 2:  Search for match hashes in primary/secondary locations
  * and prefetch first key slot
@@ -951,15 +983,14 @@ lookup_stage2(unsigned idx, hash_sig_t prim_hash, 
hash_sig_t sec_hash,
uint64_t *extra_hits_mask, const void *keys,
const struct rte_hash *h)
 {
-   unsigned prim_hash_matches, sec_hash_matches, key_idx, i;
+   unsigned prim_hash_matches, sec_hash_matches, key_idx;
unsigned total_hash_matches;

prim_hash_matches = 1 << RTE_HASH_BUCKET_ENTRIES;
sec_hash_matches = 1 << RTE_HASH_BUCKET_ENTRIES;
-   for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
-   prim_hash_matches |= ((prim_hash == prim_bkt->sig_current[i]) 
<< i);
-   sec_hash_matches |= ((sec_hash == sec_bkt->sig_current[i]) << 
i);
-   }
+
+   compare_signatures(_hash_matches, _hash_matches, prim_bkt,
+   sec_bkt, prim_hash, sec_hash);

key_idx = prim_bkt->key_idx[__builtin_ctzl(prim_hash_matches)];
if (key_idx == 0)
diff --git a/lib/librte_hash/rte_cuckoo_hash.h 
b/lib/librte_hash/rte_cuckoo_hash.h
index fe0654f..eb57d7e 100644
--- a/lib/librte_hash/rte_cuckoo_hash.h
+++ b/lib/librte_hash/rte_cuckoo_hash.h
@@ -130,7 +130,11 @@ enum add_key_case {
 };

 /** Number of items per bucket. */
+#if defined(__AVX2__)
+#define RTE_HASH_BUCKET_ENTRIES8
+#else
 #define RTE_HASH_BUCKET_ENTRIES4
+#endif

 #define NULL_SIGNATURE 0

-- 
2.7.4



[dpdk-dev] [PATCH 1/3] hash: reorganize bucket structure

2016-08-26 Thread Pablo de Lara
From: Byron Marohn 

Move current signatures of all entries together in the bucket
and same with all alternative signatures, instead of having
current and alternative signatures together per entry in the bucket.
This will be benefitial in the next commits, where a vectorized
comparison will be performed, achieving better performance.

Signed-off-by: Byron Marohn 
Signed-off-by: Saikrishna Edupuganti 
---
 lib/librte_hash/rte_cuckoo_hash.c | 43 ++-
 lib/librte_hash/rte_cuckoo_hash.h | 17 --
 lib/librte_hash/rte_cuckoo_hash_x86.h | 20 
 3 files changed, 37 insertions(+), 43 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index dd0290f..9d507b6 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -420,7 +420,7 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
 */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
/* Search for space in alternative locations */
-   next_bucket_idx = bkt->signatures[i].alt & h->bucket_bitmask;
+   next_bucket_idx = bkt->sig_alt[i] & h->bucket_bitmask;
next_bkt[i] = >buckets[next_bucket_idx];
for (j = 0; j < RTE_HASH_BUCKET_ENTRIES; j++) {
if (next_bkt[i]->key_idx[j] == EMPTY_SLOT)
@@ -433,8 +433,8 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)

/* Alternative location has spare room (end of recursive function) */
if (i != RTE_HASH_BUCKET_ENTRIES) {
-   next_bkt[i]->signatures[j].alt = bkt->signatures[i].current;
-   next_bkt[i]->signatures[j].current = bkt->signatures[i].alt;
+   next_bkt[i]->sig_alt[j] = bkt->sig_current[i];
+   next_bkt[i]->sig_current[j] = bkt->sig_alt[i];
next_bkt[i]->key_idx[j] = bkt->key_idx[i];
return i;
}
@@ -460,8 +460,8 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
 */
bkt->flag[i] = 0;
if (ret >= 0) {
-   next_bkt[i]->signatures[ret].alt = bkt->signatures[i].current;
-   next_bkt[i]->signatures[ret].current = bkt->signatures[i].alt;
+   next_bkt[i]->sig_alt[ret] = bkt->sig_current[i];
+   next_bkt[i]->sig_current[ret] = bkt->sig_alt[i];
next_bkt[i]->key_idx[ret] = bkt->key_idx[i];
return i;
} else
@@ -543,8 +543,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,

/* Check if key is already inserted in primary location */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
-   if (prim_bkt->signatures[i].current == sig &&
-   prim_bkt->signatures[i].alt == alt_hash) {
+   if (prim_bkt->sig_current[i] == sig &&
+   prim_bkt->sig_alt[i] == alt_hash) {
k = (struct rte_hash_key *) ((char *)keys +
prim_bkt->key_idx[i] * 
h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -563,8 +563,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,

/* Check if key is already inserted in secondary location */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
-   if (sec_bkt->signatures[i].alt == sig &&
-   sec_bkt->signatures[i].current == alt_hash) {
+   if (sec_bkt->sig_alt[i] == sig &&
+   sec_bkt->sig_current[i] == alt_hash) {
k = (struct rte_hash_key *) ((char *)keys +
sec_bkt->key_idx[i] * 
h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -610,8 +610,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
/* Check if slot is available */
if (likely(prim_bkt->key_idx[i] == EMPTY_SLOT)) {
-   prim_bkt->signatures[i].current = sig;
-   prim_bkt->signatures[i].alt = alt_hash;
+   prim_bkt->sig_current[i] = sig;
+   prim_bkt->sig_alt[i] = alt_hash;
prim_bkt->key_idx[i] = new_idx;
break;
}
@@ -631,8 +631,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,
 */
ret = make_space_bucket(h, prim_bkt);
if (ret >= 0) {
-   prim_bkt->signatures[ret].current = sig;
-   prim_bkt->signatures[ret].alt = alt_hash;
+

[dpdk-dev] [PATCH 3/3] hash: check if slot is empty with key index

2016-08-26 Thread Pablo de Lara
Instead of checking if the current and alternative signatures are 0,
it is faster to check if the key index associated to an entry
is 0, meaning that the slot is empty.

Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 16 
 lib/librte_hash/rte_cuckoo_hash.h |  2 ++
 lib/librte_hash/rte_cuckoo_hash_x86.h |  5 ++---
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index be1490a..dd0290f 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -423,7 +423,7 @@ make_space_bucket(const struct rte_hash *h, struct 
rte_hash_bucket *bkt)
next_bucket_idx = bkt->signatures[i].alt & h->bucket_bitmask;
next_bkt[i] = >buckets[next_bucket_idx];
for (j = 0; j < RTE_HASH_BUCKET_ENTRIES; j++) {
-   if (next_bkt[i]->signatures[j].sig == NULL_SIGNATURE)
+   if (next_bkt[i]->key_idx[j] == EMPTY_SLOT)
break;
}

@@ -609,7 +609,7 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, 
const void *key,
 #endif
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
/* Check if slot is available */
-   if (likely(prim_bkt->signatures[i].sig == 
NULL_SIGNATURE)) {
+   if (likely(prim_bkt->key_idx[i] == EMPTY_SLOT)) {
prim_bkt->signatures[i].current = sig;
prim_bkt->signatures[i].alt = alt_hash;
prim_bkt->key_idx[i] = new_idx;
@@ -707,7 +707,7 @@ __rte_hash_lookup_with_hash(const struct rte_hash *h, const 
void *key,
/* Check if key is in primary location */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
if (bkt->signatures[i].current == sig &&
-   bkt->signatures[i].sig != NULL_SIGNATURE) {
+   bkt->key_idx[i] != EMPTY_SLOT) {
k = (struct rte_hash_key *) ((char *)keys +
bkt->key_idx[i] * h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -823,7 +823,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, 
const void *key,
/* Check if key is in primary location */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
if (bkt->signatures[i].current == sig &&
-   bkt->signatures[i].sig != NULL_SIGNATURE) {
+   bkt->key_idx[i] != EMPTY_SLOT) {
k = (struct rte_hash_key *) ((char *)keys +
bkt->key_idx[i] * h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -834,7 +834,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, 
const void *key,
 * substracting the first dummy index
 */
ret = bkt->key_idx[i] - 1;
-   bkt->key_idx[i] = 0;
+   bkt->key_idx[i] = EMPTY_SLOT;
return ret;
}
}
@@ -848,7 +848,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, 
const void *key,
/* Check if key is in secondary location */
for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
if (bkt->signatures[i].current == alt_hash &&
-   bkt->signatures[i].sig != NULL_SIGNATURE) {
+   bkt->key_idx[i] != EMPTY_SLOT) {
k = (struct rte_hash_key *) ((char *)keys +
bkt->key_idx[i] * h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -859,7 +859,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, 
const void *key,
 * substracting the first dummy index
 */
ret = bkt->key_idx[i] - 1;
-   bkt->key_idx[i] = 0;
+   bkt->key_idx[i] = EMPTY_SLOT;
return ret;
}
}
@@ -1229,7 +1229,7 @@ rte_hash_iterate(const struct rte_hash *h, const void 
**key, void **data, uint32
idx = *next % RTE_HASH_BUCKET_ENTRIES;

/* If current position is empty, go to the next one */
-   while (h->buckets[bucket_idx].signatures[idx].sig == NULL_SIGNATURE) {
+   while (h->buckets[bucket_idx].key_idx[idx] == EMPTY_SLOT) {
(*ne

[dpdk-dev] [PATCH 2/3] hash: fix false zero signature key hit lookup

2016-08-26 Thread Pablo de Lara
This commit fixes a corner case scenario. When a key is deleted,
its signature in the hash table gets clear, which should prevent
a lookup of that same key, unless the signature of the key is all zeroes.

In that case, there will be a match, and key would be compared against
the key that is in the table (which does not get cleared,
as the performance penalty would be high), resulting in a wrong hit.

To prevent this from happening, the key index associated to that entry
should be set to zero when deleting it, so in case that same key
is looked up just after a deletion, it will point to the dummy key slot,
which guarantees a miss.

Fixes: 48a399119619 ("hash: replace with cuckoo hash implementation")

Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index 63fa036..be1490a 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -815,6 +815,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, 
const void *key,
unsigned i;
struct rte_hash_bucket *bkt;
struct rte_hash_key *k, *keys = h->key_store;
+   int32_t ret;

bucket_idx = sig & h->bucket_bitmask;
bkt = >buckets[bucket_idx];
@@ -832,7 +833,9 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, 
const void *key,
 * Return index where key is stored,
 * substracting the first dummy index
 */
-   return bkt->key_idx[i] - 1;
+   ret = bkt->key_idx[i] - 1;
+   bkt->key_idx[i] = 0;
+   return ret;
}
}
}
@@ -855,7 +858,9 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, 
const void *key,
 * Return index where key is stored,
 * substracting the first dummy index
 */
-   return bkt->key_idx[i] - 1;
+   ret = bkt->key_idx[i] - 1;
+   bkt->key_idx[i] = 0;
+   return ret;
}
}
}
-- 
2.7.4



[dpdk-dev] [PATCH 1/3] hash: fix ring size

2016-08-26 Thread Pablo de Lara
Ring stores the free slots available to be used in the key table.
The ring size was being increased by 1, because of the dummy slot,
used for key misses, but this is not actually stored in the ring,
so there is no need to increase it.

Fixes: 5915699153d7 ("hash: fix scaling by reducing contention")

Signed-off-by: Pablo de Lara 
---
 lib/librte_hash/rte_cuckoo_hash.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c 
b/lib/librte_hash/rte_cuckoo_hash.c
index 26e54f6..63fa036 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -159,7 +159,8 @@ rte_hash_create(const struct rte_hash_parameters *params)
num_key_slots = params->entries + 1;

snprintf(ring_name, sizeof(ring_name), "HT_%s", params->name);
-   r = rte_ring_create(ring_name, rte_align32pow2(num_key_slots),
+   /* Create ring (Dummy slot index is not enqueued) */
+   r = rte_ring_create(ring_name, rte_align32pow2(num_key_slots - 1),
params->socket_id, 0);
if (r == NULL) {
RTE_LOG(ERR, HASH, "memory allocation failed\n");
-- 
2.7.4



[dpdk-dev] [PATCH 0/3] Hash library fixes

2016-08-26 Thread Pablo de Lara
This patchset includes some minor fixes to the hash library,
plus a small improvement in checking for an empty slot
when performing different hash operations.

Pablo de Lara (3):
  hash: fix ring size
  hash: fix false zero signature key hit lookup
  hash: check if slot is empty with key index

 lib/librte_hash/rte_cuckoo_hash.c | 24 +++-
 lib/librte_hash/rte_cuckoo_hash.h |  2 ++
 lib/librte_hash/rte_cuckoo_hash_x86.h |  5 ++---
 3 files changed, 19 insertions(+), 12 deletions(-)

-- 
2.7.4



[dpdk-dev] [PATCH 3/3] app/test: add test cases for ZUC PMD

2016-08-26 Thread Pablo de Lara
Add cipher and authentication ZUC algorithm tests.

Signed-off-by: Pablo de Lara 
---
 app/test/test_cryptodev.c   | 241 ++
 app/test/test_cryptodev_zuc_hash_test_vectors.h | 397 
 app/test/test_cryptodev_zuc_test_vectors.h  | 582 
 3 files changed, 1220 insertions(+)
 create mode 100644 app/test/test_cryptodev_zuc_hash_test_vectors.h
 create mode 100644 app/test/test_cryptodev_zuc_test_vectors.h

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 703df91..ac83f24 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -48,6 +48,8 @@
 #include "test_cryptodev_kasumi_hash_test_vectors.h"
 #include "test_cryptodev_snow3g_test_vectors.h"
 #include "test_cryptodev_snow3g_hash_test_vectors.h"
+#include "test_cryptodev_zuc_test_vectors.h"
+#include "test_cryptodev_zuc_hash_test_vectors.h"
 #include "test_cryptodev_gcm_test_vectors.h"
 #include "test_cryptodev_hmac_test_vectors.h"

@@ -240,6 +242,20 @@ testsuite_setup(void)
}
}

+   /* Create 2 ZUC devices if required */
+   if (gbl_cryptodev_type == RTE_CRYPTODEV_ZUC_PMD) {
+   nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_ZUC_PMD);
+   if (nb_devs < 2) {
+   for (i = nb_devs; i < 2; i++) {
+   TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
+   RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
+   "Failed to create instance %u of"
+   " pmd : %s",
+   i, RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
+   }
+   }
+   }
+
/* Create 2 NULL devices if required */
if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
nb_devs = rte_cryptodev_count_devtype(
@@ -2831,6 +2847,132 @@ test_snow3g_encrypted_authentication(const struct 
snow3g_test_data *tdata)
 }

 static int
+test_zuc_encryption(const struct zuc_test_data *tdata)
+{
+   struct crypto_testsuite_params *ts_params = _params;
+   struct crypto_unittest_params *ut_params = _params;
+
+   int retval;
+   uint8_t *plaintext, *ciphertext;
+   unsigned plaintext_pad_len;
+   unsigned plaintext_len;
+
+   /* Create ZUC session */
+   retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
+   RTE_CRYPTO_CIPHER_OP_ENCRYPT,
+   RTE_CRYPTO_CIPHER_ZUC_EEA3,
+   tdata->key.data, tdata->key.len);
+   if (retval < 0)
+   return retval;
+
+   ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+   /* Clear mbuf payload */
+   memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+  rte_pktmbuf_tailroom(ut_params->ibuf));
+
+   plaintext_len = ceil_byte_length(tdata->plaintext.len);
+   /* Append data which is padded to a multiple */
+   /* of the algorithms block size */
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
+   plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
+   plaintext_pad_len);
+   memcpy(plaintext, tdata->plaintext.data, plaintext_len);
+
+   TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
+
+   /* Create ZUC operation */
+   retval = create_wireless_algo_cipher_operation(tdata->iv.data, 
tdata->iv.len,
+   tdata->plaintext.len,
+   tdata->validCipherOffsetLenInBits.len,
+   RTE_CRYPTO_CIPHER_ZUC_EEA3);
+   if (retval < 0)
+   return retval;
+
+   ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+   ut_params->op);
+   TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
+
+   ut_params->obuf = ut_params->op->sym->m_dst;
+   if (ut_params->obuf)
+   ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
+   + tdata->iv.len;
+   else
+   ciphertext = plaintext;
+
+   TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
+
+   /* Validate obuf */
+   TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
+   ciphertext,
+   tdata->ciphertext.data,
+   tdata->validCipherLenInBits.len,
+   "ZUC Ciphertext data not as expected");
+   return 0;
+}
+
+static int
+test_zuc_authentication(const struct zuc_hash_test_data *tdata)
+{
+   struct crypto_testsuite_params *ts_para

[dpdk-dev] [PATCH 2/3] app/test: rename some functions

2016-08-26 Thread Pablo de Lara
Before adding the new ZUC tests, since they will use
the existing common functions for SNOW3G and KASUMI,
these functions are renamed to *_wireless_algo_*,
instead of *_snow3g_kasumi_*, as they are common
functions for all the three wireless algorithms.

Signed-off-by: Pablo de Lara 
---
 app/test/test_cryptodev.c | 78 +++
 1 file changed, 39 insertions(+), 39 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index d7dec2b..703df91 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1095,7 +1095,7 @@ test_AES_qat_all(void)

 /* * Snow3G Tests * */
 static int
-create_snow3g_kasumi_hash_session(uint8_t dev_id,
+create_wireless_algo_hash_session(uint8_t dev_id,
const uint8_t *key, const uint8_t key_len,
const uint8_t aad_len, const uint8_t auth_len,
enum rte_crypto_auth_operation op,
@@ -1126,7 +1126,7 @@ create_snow3g_kasumi_hash_session(uint8_t dev_id,
 }

 static int
-create_snow3g_kasumi_cipher_session(uint8_t dev_id,
+create_wireless_algo_cipher_session(uint8_t dev_id,
enum rte_crypto_cipher_operation op,
enum rte_crypto_cipher_algorithm algo,
const uint8_t *key, const uint8_t key_len)
@@ -1157,7 +1157,7 @@ create_snow3g_kasumi_cipher_session(uint8_t dev_id,
 }

 static int
-create_snow3g_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
+create_wireless_algo_cipher_operation(const uint8_t *iv, const unsigned iv_len,
const unsigned cipher_len,
const unsigned cipher_offset,
enum rte_crypto_cipher_algorithm algo)
@@ -1202,7 +1202,7 @@ create_snow3g_kasumi_cipher_operation(const uint8_t *iv, 
const unsigned iv_len,
 }

 static int
-create_snow3g_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t 
iv_len,
+create_wireless_algo_cipher_operation_oop(const uint8_t *iv, const uint8_t 
iv_len,
const unsigned cipher_len,
const unsigned cipher_offset,
enum rte_crypto_cipher_algorithm algo)
@@ -1247,7 +1247,7 @@ create_snow3g_kasumi_cipher_operation_oop(const uint8_t 
*iv, const uint8_t iv_le
 }

 static int
-create_snow3g_kasumi_cipher_auth_session(uint8_t dev_id,
+create_wireless_algo_cipher_auth_session(uint8_t dev_id,
enum rte_crypto_cipher_operation cipher_op,
enum rte_crypto_auth_operation auth_op,
enum rte_crypto_auth_algorithm auth_algo,
@@ -1294,7 +1294,7 @@ create_snow3g_kasumi_cipher_auth_session(uint8_t dev_id,
 }

 static int
-create_snow3g_kasumi_auth_cipher_session(uint8_t dev_id,
+create_wireless_algo_auth_cipher_session(uint8_t dev_id,
enum rte_crypto_cipher_operation cipher_op,
enum rte_crypto_auth_operation auth_op,
enum rte_crypto_auth_algorithm auth_algo,
@@ -1338,7 +1338,7 @@ create_snow3g_kasumi_auth_cipher_session(uint8_t dev_id,
 }

 static int
-create_snow3g_kasumi_hash_operation(const uint8_t *auth_tag,
+create_wireless_algo_hash_operation(const uint8_t *auth_tag,
const unsigned auth_tag_len,
const uint8_t *aad, const unsigned aad_len,
unsigned data_pad_len,
@@ -1418,7 +1418,7 @@ create_snow3g_kasumi_hash_operation(const uint8_t 
*auth_tag,
 }

 static int
-create_snow3g_kasumi_cipher_hash_operation(const uint8_t *auth_tag,
+create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
const unsigned auth_tag_len,
const uint8_t *aad, const uint8_t aad_len,
unsigned data_pad_len,
@@ -1521,7 +1521,7 @@ create_snow3g_kasumi_cipher_hash_operation(const uint8_t 
*auth_tag,
 }

 static int
-create_snow3g_kasumi_auth_cipher_operation(const unsigned auth_tag_len,
+create_wireless_algo_auth_cipher_operation(const unsigned auth_tag_len,
const uint8_t *iv, const uint8_t iv_len,
const uint8_t *aad, const uint8_t aad_len,
unsigned data_pad_len,
@@ -1631,7 +1631,7 @@ test_snow3g_authentication(const struct 
snow3g_hash_test_data *tdata)
uint8_t *plaintext;

/* Create SNOW3G session */
-   retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
+   retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
tdata->key.data, tdata->key.len,
tdata->aad.len, tdata->digest.len,
RTE_CRYPTO_AUTH_OP_GENERATE,
@@ -1654,7 +1654,7 @@ test_snow3g_authentication(const struct 
snow3g_hash_test_data *tdata)
memcpy(plaintext, tdata->plaintext.data, plaintext_len);

/* Create SNOW3G operation */
-   retval = create_snow3g_kasumi_hash_operation(NULL, tdata->digest.len,
+   retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
  

[dpdk-dev] [PATCH 1/3] crypto/zuc: add driver for ZUC library

2016-08-26 Thread Pablo de Lara
Added new SW PMD which makes use of the libsso SW library,
which provides wireless algorithms ZUC EEA3 and EIA3
in software.

This PMD supports cipher-only, hash-only and chained operations
("cipher then hash" and "hash then cipher") of the following
algorithms:
- RTE_CRYPTO_SYM_CIPHER_ZUC_EEA3
- RTE_CRYPTO_SYM_AUTH_ZUC_EIA3

The ZUC hash and cipher algorithms, which are enabled
by this crypto PMD are implemented by Intel's libsso software
library.

Signed-off-by: Pablo de Lara 
---
 MAINTAINERS|   5 +
 config/common_base |   6 +
 doc/guides/rel_notes/release_16_11.rst |   5 +
 drivers/crypto/Makefile|   1 +
 drivers/crypto/zuc/Makefile|  69 
 drivers/crypto/zuc/rte_pmd_zuc_version.map |   3 +
 drivers/crypto/zuc/rte_zuc_pmd.c   | 548 +
 drivers/crypto/zuc/rte_zuc_pmd_ops.c   | 342 ++
 drivers/crypto/zuc/rte_zuc_pmd_private.h   | 108 ++
 lib/librte_cryptodev/rte_crypto_sym.h  |  20 +-
 lib/librte_cryptodev/rte_cryptodev.h   |   3 +
 mk/rte.app.mk  |   2 +
 scripts/test-build.sh  |   4 +
 13 files changed, 1108 insertions(+), 8 deletions(-)
 create mode 100644 drivers/crypto/zuc/Makefile
 create mode 100644 drivers/crypto/zuc/rte_pmd_zuc_version.map
 create mode 100644 drivers/crypto/zuc/rte_zuc_pmd.c
 create mode 100644 drivers/crypto/zuc/rte_zuc_pmd_ops.c
 create mode 100644 drivers/crypto/zuc/rte_zuc_pmd_private.h

diff --git a/MAINTAINERS b/MAINTAINERS
index bc9aa02..ce4b093 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -426,6 +426,11 @@ M: Pablo de Lara 
 F: drivers/crypto/kasumi/
 F: doc/guides/cryptodevs/kasumi.rst

+ZUC PMD
+M: Pablo de Lara 
+F: drivers/crypto/zuc/
+F: doc/guides/cryptodevs/zuc.rst
+
 Null Crypto PMD
 M: Declan Doherty 
 F: drivers/crypto/null/
diff --git a/config/common_base b/config/common_base
index 7830535..3a412ee 100644
--- a/config/common_base
+++ b/config/common_base
@@ -394,6 +394,12 @@ CONFIG_RTE_LIBRTE_PMD_KASUMI=n
 CONFIG_RTE_LIBRTE_PMD_KASUMI_DEBUG=n

 #
+# Compile PMD for ZUC device
+#
+CONFIG_RTE_LIBRTE_PMD_ZUC=n
+CONFIG_RTE_LIBRTE_PMD_ZUC_DEBUG=n
+
+#
 # Compile PMD for NULL Crypto device
 #
 CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO=y
diff --git a/doc/guides/rel_notes/release_16_11.rst 
b/doc/guides/rel_notes/release_16_11.rst
index 66916af..734aa10 100644
--- a/doc/guides/rel_notes/release_16_11.rst
+++ b/doc/guides/rel_notes/release_16_11.rst
@@ -36,6 +36,11 @@ New Features

  This section is a comment. Make sure to start the actual text at the 
margin.

+* **Added ZUC SW PMD.**
+
+  A new Crypto PMD has been added, which provides ZUC EA3 ciphering
+  and ZUC EIA3 hashing.
+

 Resolved Issues
 ---
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index dc4ef7f..17d74fc 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -36,6 +36,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_MB) += aesni_mb
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_QAT) += qat
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_SNOW3G) += snow3g
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_KASUMI) += kasumi
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_ZUC) += zuc
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO) += null

 include $(RTE_SDK)/mk/rte.subdir.mk
diff --git a/drivers/crypto/zuc/Makefile b/drivers/crypto/zuc/Makefile
new file mode 100644
index 000..b15eb0f
--- /dev/null
+++ b/drivers/crypto/zuc/Makefile
@@ -0,0 +1,69 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2016 Intel Corporation. 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 CONTR

[dpdk-dev] [PATCH 0/3] Add new ZUC SW PMD

2016-08-26 Thread Pablo de Lara
Added new SW PMD which makes use of the libsso SW library,
which provides wireless algorithms ZUC EEA3 and EIA3
in software.

This PMD supports cipher-only, hash-only and chained operations
("cipher then hash" and "hash then cipher") of the following
algorithms:
- RTE_CRYPTO_SYM_CIPHER_ZUC_EEA3
- RTE_CRYPTO_SYM_AUTH_ZUC_EIA3

The patchset also adds unit tests for this new PMD and
rename some common functions in the test application,
as they are used by all the wireless algorithms.

This patchset depends on the following patchset:
"add GMAC capability Intel QAT driver"
(http://dpdk.org/ml/archives/dev/2016-August/045617.html)

A v2 will be sent once the library is available.

Pablo de Lara (3):
  crypto/zuc: add driver for ZUC library
  app/test: rename some functions
  app/test: add test cases for ZUC PMD

 MAINTAINERS |   5 +
 app/test/test_cryptodev.c   | 319 +++--
 app/test/test_cryptodev_zuc_hash_test_vectors.h | 397 
 app/test/test_cryptodev_zuc_test_vectors.h  | 582 
 config/common_base  |   6 +
 doc/guides/rel_notes/release_16_11.rst  |   5 +
 drivers/crypto/Makefile |   1 +
 drivers/crypto/zuc/Makefile |  69 +++
 drivers/crypto/zuc/rte_pmd_zuc_version.map  |   3 +
 drivers/crypto/zuc/rte_zuc_pmd.c| 548 ++
 drivers/crypto/zuc/rte_zuc_pmd_ops.c| 342 ++
 drivers/crypto/zuc/rte_zuc_pmd_private.h| 108 +
 lib/librte_cryptodev/rte_crypto_sym.h   |  20 +-
 lib/librte_cryptodev/rte_cryptodev.h|   3 +
 mk/rte.app.mk   |   2 +
 scripts/test-build.sh   |   4 +
 16 files changed, 2367 insertions(+), 47 deletions(-)
 create mode 100644 app/test/test_cryptodev_zuc_hash_test_vectors.h
 create mode 100644 app/test/test_cryptodev_zuc_test_vectors.h
 create mode 100644 drivers/crypto/zuc/Makefile
 create mode 100644 drivers/crypto/zuc/rte_pmd_zuc_version.map
 create mode 100644 drivers/crypto/zuc/rte_zuc_pmd.c
 create mode 100644 drivers/crypto/zuc/rte_zuc_pmd_ops.c
 create mode 100644 drivers/crypto/zuc/rte_zuc_pmd_private.h

-- 
2.7.4



[dpdk-dev] [PATCH] drivers: make driver names consistent

2016-08-25 Thread Pablo de Lara
As discussed in the past release, driver names are modified
to be more consistent, and the future driver should follow
this new convention.

Driver names consist of:
"driver category"_"driver folder name"_"optional extra name".

For example:
- Crypto null driver   -> "crypto_null"
- Network IXGBE VF driver  -> "net_ixgbe_vf"

Signed-off-by: Pablo de Lara 
---
 app/pdump/main.c  |  4 ++--
 doc/guides/cryptodevs/aesni_gcm.rst   |  6 +++---
 doc/guides/cryptodevs/aesni_mb.rst|  6 +++---
 doc/guides/cryptodevs/kasumi.rst  |  6 +++---
 doc/guides/cryptodevs/null.rst|  6 +++---
 doc/guides/cryptodevs/snow3g.rst  |  6 +++---
 doc/guides/nics/pcap_ring.rst | 26 +-
 doc/guides/nics/vhost.rst |  2 +-
 doc/guides/xen/pkt_switch.rst | 10 +-
 drivers/net/af_packet/rte_eth_af_packet.c |  4 ++--
 drivers/net/bnx2x/bnx2x_ethdev.c  |  8 
 drivers/net/bnxt/bnxt_ethdev.c|  4 ++--
 drivers/net/bonding/rte_eth_bond_pmd.c|  4 ++--
 drivers/net/cxgbe/cxgbe_ethdev.c  |  4 ++--
 drivers/net/e1000/em_ethdev.c |  4 ++--
 drivers/net/e1000/igb_ethdev.c|  8 
 drivers/net/ena/ena_ethdev.c  |  4 ++--
 drivers/net/enic/enic_ethdev.c|  4 ++--
 drivers/net/fm10k/fm10k_ethdev.c  |  4 ++--
 drivers/net/i40e/i40e_ethdev.c|  4 ++--
 drivers/net/i40e/i40e_ethdev_vf.c |  4 ++--
 drivers/net/ixgbe/ixgbe_ethdev.c  |  8 
 drivers/net/mlx4/mlx4.c   |  4 ++--
 drivers/net/mlx5/mlx5.c   |  4 ++--
 drivers/net/mpipe/mpipe_tilegx.c  |  4 ++--
 drivers/net/nfp/nfp_net.c |  4 ++--
 drivers/net/null/rte_eth_null.c   |  4 ++--
 drivers/net/pcap/rte_eth_pcap.c   |  4 ++--
 drivers/net/qede/qede_ethdev.c|  8 
 drivers/net/ring/rte_eth_ring.c   |  4 ++--
 drivers/net/szedata2/rte_eth_szedata2.c   |  2 +-
 drivers/net/thunderx/nicvf_ethdev.c   |  4 ++--
 drivers/net/vhost/rte_eth_vhost.c |  4 ++--
 drivers/net/virtio/virtio_ethdev.c|  4 ++--
 drivers/net/virtio/virtio_user_ethdev.c   |  4 ++--
 drivers/net/vmxnet3/vmxnet3_ethdev.c  |  4 ++--
 drivers/net/xenvirt/rte_eth_xenvirt.c |  4 ++--
 lib/librte_cryptodev/rte_cryptodev.h  | 12 ++--
 38 files changed, 105 insertions(+), 105 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index b76cfd0..f3ef181 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -68,8 +68,8 @@
 #define CMD_LINE_OPT_SER_SOCK_PATH "server-socket-path"
 #define CMD_LINE_OPT_CLI_SOCK_PATH "client-socket-path"

-#define VDEV_PCAP "eth_pcap_%s_%d,tx_pcap=%s"
-#define VDEV_IFACE "eth_pcap_%s_%d,tx_iface=%s"
+#define VDEV_PCAP "net_pcap_%s_%d,tx_pcap=%s"
+#define VDEV_IFACE "net_pcap_%s_%d,tx_iface=%s"
 #define TX_STREAM_SIZE 64

 #define MP_NAME "pdump_pool_%d"
diff --git a/doc/guides/cryptodevs/aesni_gcm.rst 
b/doc/guides/cryptodevs/aesni_gcm.rst
index 7ff1c6b..04bf43c 100644
--- a/doc/guides/cryptodevs/aesni_gcm.rst
+++ b/doc/guides/cryptodevs/aesni_gcm.rst
@@ -64,9 +64,9 @@ In order to enable this virtual crypto PMD, user must:

 To use the PMD in an application, user must:

-* Call rte_eal_vdev_init("cryptodev_aesni_gcm_pmd") within the application.
+* Call rte_eal_vdev_init("crypto_aesni_gcm") within the application.

-* Use --vdev="cryptodev_aesni_gcm_pmd" in the EAL options, which will call 
rte_eal_vdev_init() internally.
+* Use --vdev="crypto_aesni_gcm" in the EAL options, which will call 
rte_eal_vdev_init() internally.

 The following parameters (all optional) can be provided in the previous two 
calls:

@@ -81,7 +81,7 @@ Example:

 .. code-block:: console

-./l2fwd-crypto -c 40 -n 4 
--vdev="cryptodev_aesni_gcm_pmd,socket_id=1,max_nb_sessions=128"
+./l2fwd-crypto -c 40 -n 4 
--vdev="crypto_aesni_gcm,socket_id=1,max_nb_sessions=128"

 Limitations
 ---
diff --git a/doc/guides/cryptodevs/aesni_mb.rst 
b/doc/guides/cryptodevs/aesni_mb.rst
index 60a8914..a827751 100644
--- a/doc/guides/cryptodevs/aesni_mb.rst
+++ b/doc/guides/cryptodevs/aesni_mb.rst
@@ -96,9 +96,9 @@ In order to enable this virtual crypto PMD, user must:

 To use the PMD in an application, user must:

-* Call rte_eal_vdev_init("cryptodev_aesni_mb_pmd") within the application.
+* Call rte_eal_vdev_init("crypto_aesni_mb") within the application.

-* Use --vdev="cryptodev_aesni_mb_pmd" in the EAL options, which will call 
rte_eal_vdev_init() internally.
+* Use --vdev="crypto_aesni_mb" in the EAL options, which will call 
rte_eal_vdev_init() internally.

 The following parameters (all optional) can be pr

[dpdk-dev] [PATCH] doc: fix old dpdk-nic-bind.py references

2016-07-29 Thread Pablo de Lara
dpdk-nic-bind.py script has been renamed to dpdk-devbind.py,
but some references to the old script have remained.
This commit completes the renaming.

Fixes: a5d7a3f77ddc ("unify tools naming")

Signed-off-by: Pablo de Lara 
---
 doc/guides/howto/flow_bifurcation.rst |  8 
 doc/guides/howto/lm_bond_virtio_sriov.rst |  8 
 doc/guides/howto/lm_virtio_vhost_user.rst | 16 
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/doc/guides/howto/flow_bifurcation.rst 
b/doc/guides/howto/flow_bifurcation.rst
index a1c6262..0d7226a 100644
--- a/doc/guides/howto/flow_bifurcation.rst
+++ b/doc/guides/howto/flow_bifurcation.rst
@@ -119,8 +119,8 @@ The typical procedure to achieve this is as follows:
.. code-block:: console

modprobe vfio-pci
-   dpdk_nic_bind.py -b vfio-pci 01:10.0
-   dpdk_nic_bind.py -b vfio-pci 01:10.1
+   dpdk-devbind.py -b vfio-pci 01:10.0
+   dpdk-devbind.py -b vfio-pci 01:10.1

 #. Run a DPDK application on the VFs:

@@ -279,8 +279,8 @@ The typical procedure to achieve this is as follows:
.. code-block:: console

modprobe vfio-pci
-   dpdk_nic_bind.py -b vfio-pci 01:10.0
-   dpdk_nic_bind.py -b vfio-pci 01:10.1
+   dpdk-devbind.py -b vfio-pci 01:10.0
+   dpdk-devbind.py -b vfio-pci 01:10.1

 #. run DPDK application on VFs:

diff --git a/doc/guides/howto/lm_bond_virtio_sriov.rst 
b/doc/guides/howto/lm_bond_virtio_sriov.rst
index 49666f1..9bc3450 100644
--- a/doc/guides/howto/lm_bond_virtio_sriov.rst
+++ b/doc/guides/howto/lm_bond_virtio_sriov.rst
@@ -613,17 +613,17 @@ Set up DPDK in the Virtual Machine
cat  /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages

ifconfig -a
-   /root/dpdk/tools/dpdk_nic_bind.py --status
+   /root/dpdk/tools/dpdk-devbind.py --status

rmmod virtio-pci ixgbevf

modprobe uio
insmod /root/dpdk/x86_64-default-linuxapp-gcc/kmod/igb_uio.ko

-   /root/dpdk/tools/dpdk_nic_bind.py -b igb_uio :00:03.0
-   /root/dpdk/tools/dpdk_nic_bind.py -b igb_uio :00:04.0
+   /root/dpdk/tools/dpdk-devbind.py -b igb_uio :00:03.0
+   /root/dpdk/tools/dpdk-devbind.py -b igb_uio :00:04.0

-   /root/dpdk/tools/dpdk_nic_bind.py --status
+   /root/dpdk/tools/dpdk-devbind.py --status

 run_testpmd_bonding_in_vm.sh
 
diff --git a/doc/guides/howto/lm_virtio_vhost_user.rst 
b/doc/guides/howto/lm_virtio_vhost_user.rst
index fad1f2a..4937781 100644
--- a/doc/guides/howto/lm_virtio_vhost_user.rst
+++ b/doc/guides/howto/lm_virtio_vhost_user.rst
@@ -91,14 +91,14 @@ For Fortville NIC.
 .. code-block:: console

cd /root/dpdk/tools
-   ./dpdk_nic_bind.py -b igb_uio :02:00.0
+   ./dpdk-devbind.py -b igb_uio :02:00.0

 For Niantic NIC.

 .. code-block:: console

cd /root/dpdk/tools
-   ./dpdk_nic_bind.py -b igb_uio :09:00.0
+   ./dpdk-devbind.py -b igb_uio :09:00.0

 On host_server_1: Terminal 3
 
@@ -172,14 +172,14 @@ For Fortville NIC.
 .. code-block:: console

cd /root/dpdk/tools
-   ./dpdk_nic_bind.py -b igb_uio :03:00.0
+   ./dpdk-devbind.py -b igb_uio :03:00.0

 For Niantic NIC.

 .. code-block:: console

cd /root/dpdk/tools
-   ./dpdk_nic_bind.py -b igb_uio :06:00.0
+   ./dpdk-devbind.py -b igb_uio :06:00.0

 On host_server_2: Terminal 3
 
@@ -444,17 +444,17 @@ setup_dpdk_virtio_in_vm.sh
cat  /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages

ifconfig -a
-   /root/dpdk/tools/dpdk_nic_bind.py --status
+   /root/dpdk/tools/dpdk-devbind.py --status

rmmod virtio-pci

modprobe uio
insmod /root/dpdk/x86_64-default-linuxapp-gcc/kmod/igb_uio.ko

-   /root/dpdk/tools/dpdk_nic_bind.py -b igb_uio :00:03.0
-   /root/dpdk/tools/dpdk_nic_bind.py -b igb_uio :00:04.0
+   /root/dpdk/tools/dpdk-devbind.py -b igb_uio :00:03.0
+   /root/dpdk/tools/dpdk-devbind.py -b igb_uio :00:04.0

-   /root/dpdk/tools/dpdk_nic_bind.py --status
+   /root/dpdk/tools/dpdk-devbind.py --status

 run_testpmd_in_vm.sh
 
-- 
2.7.4



[dpdk-dev] [PATCH v2 2/2] net/i40e: fix unsafe tailq element removal

2016-07-22 Thread Pablo de Lara
i40e driver was removing elements when iterating tailq lists
with TAILQ_FOREACH macro, which is not safe.
Instead, TAILQ_FOREACH_SAFE macro is used when removing/freeing
these elements.

Fixes: 4861cde46116 ("i40e: new poll mode driver")
Fixes: 440499cf5376 ("net/i40e: support floating VEB")

Signed-off-by: Pablo de Lara 
---
 drivers/net/i40e/i40e_ethdev.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 84c86aa..11a5804 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -31,7 +31,6 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */

-#include 
 #include 
 #include 
 #include 
@@ -51,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 

 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
@@ -4094,6 +4094,7 @@ i40e_vsi_release(struct i40e_vsi *vsi)
struct i40e_pf *pf;
struct i40e_hw *hw;
struct i40e_vsi_list *vsi_list;
+   void *temp;
int ret;
struct i40e_mac_filter *f;
uint16_t user_param = vsi->user_param;
@@ -4106,7 +4107,7 @@ i40e_vsi_release(struct i40e_vsi *vsi)

/* VSI has child to attach, release child first */
if (vsi->veb) {
-   TAILQ_FOREACH(vsi_list, >veb->head, list) {
+   TAILQ_FOREACH_SAFE(vsi_list, >veb->head, list, temp) {
if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
return -1;
TAILQ_REMOVE(>veb->head, vsi_list, list);
@@ -4115,7 +4116,7 @@ i40e_vsi_release(struct i40e_vsi *vsi)
}

if (vsi->floating_veb) {
-   TAILQ_FOREACH(vsi_list, >floating_veb->head, list) {
+   TAILQ_FOREACH_SAFE(vsi_list, >floating_veb->head, list, 
temp) {
if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
return -1;
TAILQ_REMOVE(>floating_veb->head, vsi_list, list);
@@ -4124,7 +4125,7 @@ i40e_vsi_release(struct i40e_vsi *vsi)

/* Remove all macvlan filters of the VSI */
i40e_vsi_remove_all_macvlan_filter(vsi);
-   TAILQ_FOREACH(f, >mac_list, next)
+   TAILQ_FOREACH_SAFE(f, >mac_list, next, temp)
rte_free(f);

if (vsi->type != I40E_VSI_MAIN &&
@@ -4682,6 +4683,7 @@ i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
 {
int i, num;
struct i40e_mac_filter *f;
+   void *temp;
struct i40e_mac_filter_info *mac_filter;
enum rte_mac_filter_type desired_filter;
int ret = I40E_SUCCESS;
@@ -4706,7 +4708,7 @@ i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
i = 0;

/* Remove all existing mac */
-   TAILQ_FOREACH(f, >mac_list, next) {
+   TAILQ_FOREACH_SAFE(f, >mac_list, next, temp) {
mac_filter[i] = f->mac_info;
ret = i40e_vsi_delete_mac(vsi, >mac_info.mac_addr);
if (ret) {
-- 
2.7.4



[dpdk-dev] [PATCH v2 1/2] eal: add tailq safe iterator macro

2016-07-22 Thread Pablo de Lara
Removing/freeing elements elements within a TAILQ_FOREACH loop is not safe.
FreeBSD defines TAILQ_FOREACH_SAFE macro, which permits
these operations safely.
This patch defines this macro for Linux systems, where it is not defined.

Signed-off-by: Pablo de Lara 
---
 lib/librte_eal/common/include/rte_tailq.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_tailq.h 
b/lib/librte_eal/common/include/rte_tailq.h
index 4a686e6..cc3c0f1 100644
--- a/lib/librte_eal/common/include/rte_tailq.h
+++ b/lib/librte_eal/common/include/rte_tailq.h
@@ -155,6 +155,14 @@ void __attribute__((constructor, used)) tailqinitfn_ 
##t(void) \
rte_panic("Cannot initialize tailq: %s\n", t.name); \
 }

+/* This macro permits both remove and free var within the loop safely.*/
+#ifndef TAILQ_FOREACH_SAFE
+#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
+   for ((var) = TAILQ_FIRST((head));   \
+   (var) && ((tvar) = TAILQ_NEXT((var), field), 1);\
+   (var) = (tvar))
+#endif
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.7.4



[dpdk-dev] [PATCH v2 0/2] Safe tailq element removal in i40e driver

2016-07-22 Thread Pablo de Lara
i40e driver was removing elements when iterating tailq lists 
with TAILQ_FOREACH macro, which is not safe.
Instead, TAILQ_FOREACH_SAFE macro is used when removing/freeing
these elements, which is defined in DPDK if it is not already
defined (in FreeBSD).

Changes in v2:
- Modified second commit title

Pablo de Lara (2):
  eal: add tailq safe iterator macro
  net/i40e: fix unsafe tailq element removal

 drivers/net/i40e/i40e_ethdev.c| 12 +++-
 lib/librte_eal/common/include/rte_tailq.h |  8 
 2 files changed, 15 insertions(+), 5 deletions(-)

-- 
2.7.4



[dpdk-dev] [PATCH 2/2] net/i40e: avoid unsafe tailq element removal

2016-07-22 Thread Pablo de Lara
i40e driver was removing elements when iterating tailq lists
with TAILQ_FOREACH macro, which is not safe.
Instead, TAILQ_FOREACH_SAFE macro is used when removing/freeing
these elements.

Fixes: 4861cde46116 ("i40e: new poll mode driver")
Fixes: 440499cf5376 ("net/i40e: support floating VEB")

Signed-off-by: Pablo de Lara 
---
 drivers/net/i40e/i40e_ethdev.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 84c86aa..11a5804 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -31,7 +31,6 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */

-#include 
 #include 
 #include 
 #include 
@@ -51,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 

 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
@@ -4094,6 +4094,7 @@ i40e_vsi_release(struct i40e_vsi *vsi)
struct i40e_pf *pf;
struct i40e_hw *hw;
struct i40e_vsi_list *vsi_list;
+   void *temp;
int ret;
struct i40e_mac_filter *f;
uint16_t user_param = vsi->user_param;
@@ -4106,7 +4107,7 @@ i40e_vsi_release(struct i40e_vsi *vsi)

/* VSI has child to attach, release child first */
if (vsi->veb) {
-   TAILQ_FOREACH(vsi_list, >veb->head, list) {
+   TAILQ_FOREACH_SAFE(vsi_list, >veb->head, list, temp) {
if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
return -1;
TAILQ_REMOVE(>veb->head, vsi_list, list);
@@ -4115,7 +4116,7 @@ i40e_vsi_release(struct i40e_vsi *vsi)
}

if (vsi->floating_veb) {
-   TAILQ_FOREACH(vsi_list, >floating_veb->head, list) {
+   TAILQ_FOREACH_SAFE(vsi_list, >floating_veb->head, list, 
temp) {
if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
return -1;
TAILQ_REMOVE(>floating_veb->head, vsi_list, list);
@@ -4124,7 +4125,7 @@ i40e_vsi_release(struct i40e_vsi *vsi)

/* Remove all macvlan filters of the VSI */
i40e_vsi_remove_all_macvlan_filter(vsi);
-   TAILQ_FOREACH(f, >mac_list, next)
+   TAILQ_FOREACH_SAFE(f, >mac_list, next, temp)
rte_free(f);

if (vsi->type != I40E_VSI_MAIN &&
@@ -4682,6 +4683,7 @@ i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
 {
int i, num;
struct i40e_mac_filter *f;
+   void *temp;
struct i40e_mac_filter_info *mac_filter;
enum rte_mac_filter_type desired_filter;
int ret = I40E_SUCCESS;
@@ -4706,7 +4708,7 @@ i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
i = 0;

/* Remove all existing mac */
-   TAILQ_FOREACH(f, >mac_list, next) {
+   TAILQ_FOREACH_SAFE(f, >mac_list, next, temp) {
mac_filter[i] = f->mac_info;
ret = i40e_vsi_delete_mac(vsi, >mac_info.mac_addr);
if (ret) {
-- 
2.7.4



[dpdk-dev] [PATCH 1/2] eal: add tailq safe iterator macro

2016-07-22 Thread Pablo de Lara
Removing/freeing elements elements within a TAILQ_FOREACH loop is not safe.
FreeBSD defines TAILQ_FOREACH_SAFE macro, which permits
these operations safely.
This patch defines this macro for Linux systems, where it is not defined.

Signed-off-by: Pablo de Lara 
---
 lib/librte_eal/common/include/rte_tailq.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_tailq.h 
b/lib/librte_eal/common/include/rte_tailq.h
index 4a686e6..cc3c0f1 100644
--- a/lib/librte_eal/common/include/rte_tailq.h
+++ b/lib/librte_eal/common/include/rte_tailq.h
@@ -155,6 +155,14 @@ void __attribute__((constructor, used)) tailqinitfn_ 
##t(void) \
rte_panic("Cannot initialize tailq: %s\n", t.name); \
 }

+/* This macro permits both remove and free var within the loop safely.*/
+#ifndef TAILQ_FOREACH_SAFE
+#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
+   for ((var) = TAILQ_FIRST((head));   \
+   (var) && ((tvar) = TAILQ_NEXT((var), field), 1);\
+   (var) = (tvar))
+#endif
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.7.4



[dpdk-dev] [PATCH 0/2] Safe tailq element removal in i40e driver

2016-07-22 Thread Pablo de Lara
i40e driver was removing elements when iterating tailq lists 
with TAILQ_FOREACH macro, which is not safe.
Instead, TAILQ_FOREACH_SAFE macro is used when removing/freeing
these elements, which is defined in DPDK if it is not already
defined (in FreeBSD).

Pablo de Lara (2):
  eal: add tailq safe iterator macro
  net/i40e: avoid unsafe tailq element removal

 drivers/net/i40e/i40e_ethdev.c| 12 +++-
 lib/librte_eal/common/include/rte_tailq.h | 11 +++
 2 files changed, 18 insertions(+), 5 deletions(-)

-- 
2.7.4



[dpdk-dev] [PATCH] doc: add cryptodev shared library version to release notes

2016-07-20 Thread Pablo de Lara
Signed-off-by: Pablo de Lara 
---
 doc/guides/rel_notes/release_16_07.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/guides/rel_notes/release_16_07.rst 
b/doc/guides/rel_notes/release_16_07.rst
index d3a144f..82ac5bb 100644
--- a/doc/guides/rel_notes/release_16_07.rst
+++ b/doc/guides/rel_notes/release_16_07.rst
@@ -321,6 +321,7 @@ The libraries prepended with a plus sign were incremented 
in this version.
  librte_acl.so.2
  librte_cfgfile.so.2
  librte_cmdline.so.2
+ librte_cryptodev.so.1
  librte_distributor.so.1
  librte_eal.so.2
  librte_hash.so.2
-- 
2.7.4



[dpdk-dev] [PATCH v3] crypto: fix memory leak

2016-07-18 Thread Pablo de Lara
When parsing the parameters for virtual device initialization,
rte_kvargs structure was being freed only if there was an error,
not when parsing was successful.

Coverity issue: 124568

Fixes: f3e764fa2fb7 ("cryptodev: uninline parameter parsing")

Signed-off-by: Pablo de Lara 
Acked-by: Reshma Pattan 
---

Changes in v3:
- Removed unnecessary NULL check

Changes in v2:
- Initialized ret variable to 0 (success)

 lib/librte_cryptodev/rte_cryptodev.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/librte_cryptodev/rte_cryptodev.c 
b/lib/librte_cryptodev/rte_cryptodev.c
index 20e5beb..fc4123b 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -148,8 +148,8 @@ int
 rte_cryptodev_parse_vdev_init_params(struct rte_crypto_vdev_init_params 
*params,
const char *input_args)
 {
-   struct rte_kvargs *kvlist;
-   int ret;
+   struct rte_kvargs *kvlist = NULL;
+   int ret = 0;

if (params == NULL)
return -EINVAL;
@@ -187,8 +187,6 @@ rte_cryptodev_parse_vdev_init_params(struct 
rte_crypto_vdev_init_params *params,
}
}

-   return 0;
-
 free_kvlist:
rte_kvargs_free(kvlist);
return ret;
-- 
2.7.4



[dpdk-dev] [PATCH v2] crypto: fix memory leak

2016-07-18 Thread Pablo de Lara
When parsing the parameters for virtual device initialization,
rte_kvargs structure was being freed only if there was an error,
not when parsing was successful.

Coverity issue: 124568

Fixes: f3e764fa2fb7 ("cryptodev: uninline parameter parsing")

Signed-off-by: Pablo de Lara 
---

Changes in v2:
- Initialize ret variable to 0 (success)

 lib/librte_cryptodev/rte_cryptodev.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/librte_cryptodev/rte_cryptodev.c 
b/lib/librte_cryptodev/rte_cryptodev.c
index 20e5beb..db809d8 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -148,8 +148,8 @@ int
 rte_cryptodev_parse_vdev_init_params(struct rte_crypto_vdev_init_params 
*params,
const char *input_args)
 {
-   struct rte_kvargs *kvlist;
-   int ret;
+   struct rte_kvargs *kvlist = NULL;
+   int ret = 0;

if (params == NULL)
return -EINVAL;
@@ -187,10 +187,9 @@ rte_cryptodev_parse_vdev_init_params(struct 
rte_crypto_vdev_init_params *params,
}
}

-   return 0;
-
 free_kvlist:
-   rte_kvargs_free(kvlist);
+   if (kvlist != NULL)
+   rte_kvargs_free(kvlist);
return ret;
 }

-- 
2.7.4



[dpdk-dev] [PATCH] crypto: fix memory leak

2016-07-18 Thread Pablo de Lara
When parsing the parameters for virtual device initialization,
rte_kvargs structure was being freed only if there was an error,
not when parsing was successful.

Coverity issue: 124568

Fixes: f3e764fa2fb7 ("cryptodev: uninline parameter parsing")

Signed-off-by: Pablo de Lara 
---
 lib/librte_cryptodev/rte_cryptodev.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/librte_cryptodev/rte_cryptodev.c 
b/lib/librte_cryptodev/rte_cryptodev.c
index 20e5beb..aaa9879 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -148,7 +148,7 @@ int
 rte_cryptodev_parse_vdev_init_params(struct rte_crypto_vdev_init_params 
*params,
const char *input_args)
 {
-   struct rte_kvargs *kvlist;
+   struct rte_kvargs *kvlist = NULL;
int ret;

if (params == NULL)
@@ -187,10 +187,11 @@ rte_cryptodev_parse_vdev_init_params(struct 
rte_crypto_vdev_init_params *params,
}
}

-   return 0;
+   ret = 0;

 free_kvlist:
-   rte_kvargs_free(kvlist);
+   if (kvlist != NULL)
+   rte_kvargs_free(kvlist);
return ret;
 }

-- 
2.7.4



[dpdk-dev] [PATCH] examples/performance-thread: add missing braces

2016-07-18 Thread Pablo de Lara
pthread_detach() function was returning 0 even when not calling
lthread_detach(), due to missing braces in conditional
(extra indentation was applied, giving a hint this is the correct fix).

Fixes: 433ba6228f9a ("examples/performance-thread: add pthread_shim app")

Signed-off-by: Pablo de Lara 
---
 examples/performance-thread/pthread_shim/pthread_shim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/performance-thread/pthread_shim/pthread_shim.c 
b/examples/performance-thread/pthread_shim/pthread_shim.c
index 93c3216..0d6100c 100644
--- a/examples/performance-thread/pthread_shim/pthread_shim.c
+++ b/examples/performance-thread/pthread_shim/pthread_shim.c
@@ -417,9 +417,10 @@ int pthread_detach(pthread_t tid)
if (override) {
struct lthread *lt = (struct lthread *)tid;

-   if (lt == lthread_current())
+   if (lt == lthread_current()) {
lthread_detach();
return 0;
+   }
NOT_IMPLEMENTED;
}
return _sys_pthread_funcs.f_pthread_detach(tid);
-- 
2.7.4



[dpdk-dev] [PATCH] doc: announce driver name changes

2016-07-09 Thread Pablo de Lara
Driver names for all the supported devices in DPDK do not have
a naming convention. Some are using a prefix, some are not
and some have long names. Driver names are used when creating
virtual devices, so it is useful to have consistency in the names.

Signed-off-by: Pablo de Lara 
---
 doc/guides/rel_notes/deprecation.rst | 5 +
 1 file changed, 5 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst 
b/doc/guides/rel_notes/deprecation.rst
index f502f86..37d65c8 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -41,3 +41,8 @@ Deprecation Notices
 * The mempool functions for single/multi producer/consumer are deprecated and
   will be removed in 16.11.
   It is replaced by rte_mempool_generic_get/put functions.
+
+* Driver names are quite inconsistent among each others and they will be
+  renamed to something more consistent (net_ prefix for net drivers and
+  crypto_ for crypto drivers) in 16.11. Some of these driver names are used
+  publicly, to create virtual devices, so a deprecation notice is necessary.
-- 
2.7.4



[dpdk-dev] [PATCH] app/test: fix hexdump length of cipher/plaintexts

2016-07-09 Thread Pablo de Lara
Plaintexts and ciphertexts are dumped when debugging is enabled,
using TEST_HEXDUMP. For Snow3G and KASUMI, their lengths are in bits,
but TEST_HEXDUMP uses bytes, so lenghts are passed in bytes now.

Fixes: 47df73a1a62f ("app/test: use hexdump if debug log is enabled")

Signed-off-by: Pablo de Lara 
---
 app/test/test_cryptodev.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 1e1f887..db43eb1 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -2295,7 +2295,7 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)
plaintext_pad_len);
memcpy(plaintext, tdata->plaintext.data, plaintext_len);

-   TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
+   TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);

/* Create SNOW3G operation */
retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, 
tdata->iv.len,
@@ -2316,7 +2316,7 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)
else
ciphertext = plaintext;

-   TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
+   TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);

/* Validate obuf */
TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
@@ -2368,7 +2368,7 @@ test_snow3g_encryption_oop(const struct snow3g_test_data 
*tdata)
rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
memcpy(plaintext, tdata->plaintext.data, plaintext_len);

-   TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
+   TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);

/* Create SNOW3G operation */
retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
@@ -2390,7 +2390,7 @@ test_snow3g_encryption_oop(const struct snow3g_test_data 
*tdata)
else
ciphertext = plaintext;

-   TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
+   TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);

/* Validate obuf */
TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
@@ -2549,7 +2549,7 @@ static int test_snow3g_decryption(const struct 
snow3g_test_data *tdata)
ciphertext_pad_len);
memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);

-   TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
+   TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);

/* Create SNOW3G operation */
retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, 
tdata->iv.len,
@@ -2569,7 +2569,7 @@ static int test_snow3g_decryption(const struct 
snow3g_test_data *tdata)
else
plaintext = ciphertext;

-   TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
+   TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);

/* Validate obuf */
TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
@@ -2622,7 +2622,7 @@ static int test_snow3g_decryption_oop(const struct 
snow3g_test_data *tdata)
rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);

-   TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
+   TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);

/* Create SNOW3G operation */
retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
@@ -2643,7 +2643,7 @@ static int test_snow3g_decryption_oop(const struct 
snow3g_test_data *tdata)
else
plaintext = ciphertext;

-   TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
+   TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);

/* Validate obuf */
TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
@@ -2689,7 +2689,7 @@ test_snow3g_authenticated_encryption(const struct 
snow3g_test_data *tdata)
plaintext_pad_len);
memcpy(plaintext, tdata->plaintext.data, plaintext_len);

-   TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
+   TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);

/* Create SNOW3G operation */
retval = create_snow3g_kasumi_cipher_hash_operation(tdata->digest.data,
@@ -2717,7 +2717,7 @@ test_snow3g_authenticated_encryption(const struct 
snow3g_test_data *tdata)
else
ciphertext = plaintext;

-   TEST_HEXDUMP(stdout, "ciphertext:", ciphert

[dpdk-dev] [PATCH 5/5] net/bonding: fix range of mode argument

2016-07-09 Thread Pablo de Lara
The range of the supported bonding modes is 0-6, instead of 0-4.

Fixes: cb6696d22023 ("drivers: update registration macro usage")

Signed-off-by: Pablo de Lara 
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c 
b/drivers/net/bonding/rte_eth_bond_pmd.c
index f617eea..b20a272 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -2519,7 +2519,7 @@ PMD_REGISTER_DRIVER(bond_drv, eth_bond);
 DRIVER_REGISTER_PARAM_STRING(eth_bond,
"slave= "
"primary= "
-   "mode=[0-4] "
+   "mode=[0-6] "
"xmit_policy=[l2 | l23 | l34] "
"socket_id= "
"mac= "
-- 
2.7.4



[dpdk-dev] [PATCH 4/5] drivers: add missing virtio and xenvirt arguments

2016-07-09 Thread Pablo de Lara
Virtio and Xenvirt are two virtual device drivers that admit
arguments, so DRIVER_REGISTER_PARAM_STRING should be used
in them.

Fixes: cb6696d22023 ("drivers: update registration macro usage")

Signed-off-by: Pablo de Lara 
---
 drivers/net/virtio/virtio_user_ethdev.c | 6 ++
 drivers/net/xenvirt/rte_eth_xenvirt.c   | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/net/virtio/virtio_user_ethdev.c 
b/drivers/net/virtio/virtio_user_ethdev.c
index 8eb166e..27b6d60 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -437,3 +437,9 @@ static struct rte_driver virtio_user_driver = {
 };

 PMD_REGISTER_DRIVER(virtio_user_driver, virtio_user);
+DRIVER_REGISTER_PARAM_STRING(virtio_user,
+   "path= "
+   "mac= "
+   "cq= "
+   "queue_size= "
+   "queues=");
diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c 
b/drivers/net/xenvirt/rte_eth_xenvirt.c
index b940e94..99f6cc8 100644
--- a/drivers/net/xenvirt/rte_eth_xenvirt.c
+++ b/drivers/net/xenvirt/rte_eth_xenvirt.c
@@ -766,3 +766,5 @@ static struct rte_driver pmd_xenvirt_drv = {
 };

 PMD_REGISTER_DRIVER(pmd_xenvirt_drv, eth_xenvirt);
+DRIVER_REGISTER_PARAM_STRING(eth_xenvirt,
+   "mac=");
-- 
2.7.4



[dpdk-dev] [PATCH 3/5] drivers: split driver arguments in multiple lines

2016-07-09 Thread Pablo de Lara
Driver arguments shown with DRIVER_REGISTER_PARAM_STRING
have been separated in multiple lines and indented to
ease their readability.

Signed-off-by: Pablo de Lara 
---
 drivers/crypto/aesni_gcm/aesni_gcm_pmd.c   |  6 --
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c |  6 --
 drivers/crypto/kasumi/rte_kasumi_pmd.c |  6 --
 drivers/crypto/null/null_crypto_pmd.c  |  6 --
 drivers/crypto/snow3g/rte_snow3g_pmd.c |  6 --
 drivers/net/af_packet/rte_eth_af_packet.c  |  8 ++--
 drivers/net/bonding/rte_eth_bond_pmd.c | 14 ++
 drivers/net/null/rte_eth_null.c|  4 +++-
 drivers/net/pcap/rte_eth_pcap.c|  8 ++--
 drivers/net/ring/rte_eth_ring.c|  3 ++-
 drivers/net/vhost/rte_eth_vhost.c  |  4 +++-
 11 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c 
b/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
index f9be44a..dc0b033 100644
--- a/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
+++ b/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
@@ -521,5 +521,7 @@ static struct rte_driver aesni_gcm_pmd_drv = {
 };

 PMD_REGISTER_DRIVER(aesni_gcm_pmd_drv, CRYPTODEV_NAME_AESNI_GCM_PMD);
-DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_AESNI_GCM_PMD, 
"max_nb_queue_pairs= "
-"max_nb_sessions= socket_id=");
+DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_AESNI_GCM_PMD,
+   "max_nb_queue_pairs= "
+   "max_nb_sessions= "
+   "socket_id=");
diff --git a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c 
b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
index 2140b92..b2d0c8c 100644
--- a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
+++ b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
@@ -721,5 +721,7 @@ static struct rte_driver cryptodev_aesni_mb_pmd_drv = {
 };

 PMD_REGISTER_DRIVER(cryptodev_aesni_mb_pmd_drv, CRYPTODEV_NAME_AESNI_MB_PMD);
-DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_AESNI_MB_PMD, 
"max_nb_queue_pairs= "
-"max_nb_sessions= socket_id=");
+DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_AESNI_MB_PMD,
+   "max_nb_queue_pairs= "
+   "max_nb_sessions= "
+   "socket_id=");
diff --git a/drivers/crypto/kasumi/rte_kasumi_pmd.c 
b/drivers/crypto/kasumi/rte_kasumi_pmd.c
index 400a248..1cdbc06 100644
--- a/drivers/crypto/kasumi/rte_kasumi_pmd.c
+++ b/drivers/crypto/kasumi/rte_kasumi_pmd.c
@@ -654,5 +654,7 @@ static struct rte_driver cryptodev_kasumi_pmd_drv = {
 };

 PMD_REGISTER_DRIVER(cryptodev_kasumi_pmd_drv, CRYPTODEV_NAME_KASUMI_PMD);
-DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_KASUMI_PMD, 
"max_nb_queue_pairs= "
-"max_nb_sessions= socket_id=");
+DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_KASUMI_PMD,
+   "max_nb_queue_pairs= "
+   "max_nb_sessions= "
+   "socket_id=");
diff --git a/drivers/crypto/null/null_crypto_pmd.c 
b/drivers/crypto/null/null_crypto_pmd.c
index e03d0eb..909b04f 100644
--- a/drivers/crypto/null/null_crypto_pmd.c
+++ b/drivers/crypto/null/null_crypto_pmd.c
@@ -275,5 +275,7 @@ static struct rte_driver cryptodev_null_pmd_drv = {
 };

 PMD_REGISTER_DRIVER(cryptodev_null_pmd_drv, CRYPTODEV_NAME_NULL_PMD);
-DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_NULL_PMD, 
"max_nb_queue_pairs= "
-"max_nb_sessions= socket_id=");
+DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_NULL_PMD,
+   "max_nb_queue_pairs= "
+   "max_nb_sessions= "
+   "socket_id=");
diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd.c 
b/drivers/crypto/snow3g/rte_snow3g_pmd.c
index a474a4d..87cd070 100644
--- a/drivers/crypto/snow3g/rte_snow3g_pmd.c
+++ b/drivers/crypto/snow3g/rte_snow3g_pmd.c
@@ -645,5 +645,7 @@ static struct rte_driver cryptodev_snow3g_pmd_drv = {
 };

 PMD_REGISTER_DRIVER(cryptodev_snow3g_pmd_drv, CRYPTODEV_NAME_SNOW3G_PMD);
-DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_SNOW3G_PMD, 
"max_nb_queue_pairs= "
-"max_nb_sessions= socket_id=");
+DRIVER_REGISTER_PARAM_STRING(CRYPTODEV_NAME_SNOW3G_PMD,
+   "max_nb_queue_pairs= "
+   "max_nb_sessions= "
+   "socket_id=");
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c 
b/drivers/net/af_packet/rte_eth_af_packet.c
index 238eed8..f795566 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -896,5 +896,9 @@ static struct rte_driver pmd_af_packet_drv = {
 };

 PMD_REGISTER_DRIVER(pmd_af_packet_drv, eth_af_packet);
-DRIVER_REGISTER_PARAM_STRING(eth_af_packet, "iface= "
-"qpairs= blocksz= framesz= framecnt=");
+DRIVER_REGISTER_PARAM_STRING(eth_af_packet,
+   "iface= "
+   "qpairs= "
+   "blocksz= "
+   "framesz= "
+   "framecnt=");
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c 
b/drivers/net/bonding/rte_eth_bond_pmd.c
index 0361be3..f617e

[dpdk-dev] [PATCH 2/5] drivers: remove static driver names

2016-07-09 Thread Pablo de Lara
Since now the PMD_REGISTER_DRIVER macro sets the driver names,
there is no need to have the rte_driver structure setting it
statically, as it will get overridden.

Signed-off-by: Pablo de Lara 
---
 drivers/net/af_packet/rte_eth_af_packet.c | 1 -
 drivers/net/bnxt/bnxt_ethdev.c| 1 -
 drivers/net/bonding/rte_eth_bond_pmd.c| 1 -
 drivers/net/cxgbe/cxgbe_ethdev.c  | 1 -
 drivers/net/ena/ena_ethdev.c  | 1 -
 drivers/net/mlx4/mlx4.c   | 1 -
 drivers/net/mlx5/mlx5.c   | 1 -
 drivers/net/mpipe/mpipe_tilegx.c  | 2 --
 drivers/net/null/rte_eth_null.c   | 1 -
 drivers/net/pcap/rte_eth_pcap.c   | 1 -
 drivers/net/ring/rte_eth_ring.c   | 1 -
 drivers/net/szedata2/rte_eth_szedata2.c   | 7 +++
 drivers/net/thunderx/nicvf_ethdev.c   | 1 -
 drivers/net/vhost/rte_eth_vhost.c | 1 -
 drivers/net/virtio/virtio_user_ethdev.c   | 1 -
 drivers/net/xenvirt/rte_eth_xenvirt.c | 1 -
 16 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c 
b/drivers/net/af_packet/rte_eth_af_packet.c
index 1d48e97..238eed8 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -890,7 +890,6 @@ rte_pmd_af_packet_devuninit(const char *name)
 }

 static struct rte_driver pmd_af_packet_drv = {
-   .name = "eth_af_packet",
.type = PMD_VDEV,
.init = rte_pmd_af_packet_devinit,
.uninit = rte_pmd_af_packet_devuninit,
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 9531abf..9a2123e 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -1041,7 +1041,6 @@ static int bnxt_rte_pmd_init(const char *name, const char 
*params __rte_unused)
 }

 static struct rte_driver bnxt_pmd_drv = {
-   .name = "eth_bnxt",
.type = PMD_PDEV,
.init = bnxt_rte_pmd_init,
 };
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c 
b/drivers/net/bonding/rte_eth_bond_pmd.c
index c373746..0361be3 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -2509,7 +2509,6 @@ bond_ethdev_configure(struct rte_eth_dev *dev)
 }

 static struct rte_driver bond_drv = {
-   .name = "eth_bond",
.type = PMD_VDEV,
.init = bond_init,
.uninit = bond_uninit,
diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c b/drivers/net/cxgbe/cxgbe_ethdev.c
index 69ff813..9208a61 100644
--- a/drivers/net/cxgbe/cxgbe_ethdev.c
+++ b/drivers/net/cxgbe/cxgbe_ethdev.c
@@ -1062,7 +1062,6 @@ static int rte_cxgbe_pmd_init(const char *name 
__rte_unused,
 }

 static struct rte_driver rte_cxgbe_driver = {
-   .name = "cxgbe_driver",
.type = PMD_PDEV,
.init = rte_cxgbe_pmd_init,
 };
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 702289b..11c7218 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -1445,7 +1445,6 @@ rte_ena_pmd_init(const char *name __rte_unused,
 };

 struct rte_driver ena_pmd_drv = {
-   .name = "ena_driver",
.type = PMD_PDEV,
.init = rte_ena_pmd_init,
 };
diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
index d9ffb13..8e1f7cb 100644
--- a/drivers/net/mlx4/mlx4.c
+++ b/drivers/net/mlx4/mlx4.c
@@ -5857,7 +5857,6 @@ rte_mlx4_pmd_init(const char *name, const char *args)

 static struct rte_driver rte_mlx4_driver = {
.type = PMD_PDEV,
-   .name = MLX4_DRIVER_NAME,
.init = rte_mlx4_pmd_init,
 };

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 8d32252..d96a9af 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -758,7 +758,6 @@ rte_mlx5_pmd_init(const char *name, const char *args)

 static struct rte_driver rte_mlx5_driver = {
.type = PMD_PDEV,
-   .name = MLX5_DRIVER_NAME,
.init = rte_mlx5_pmd_init,
 };

diff --git a/drivers/net/mpipe/mpipe_tilegx.c b/drivers/net/mpipe/mpipe_tilegx.c
index 64f4251..93f8730 100644
--- a/drivers/net/mpipe/mpipe_tilegx.c
+++ b/drivers/net/mpipe/mpipe_tilegx.c
@@ -1624,13 +1624,11 @@ rte_pmd_mpipe_devinit(const char *ifname,
 }

 static struct rte_driver pmd_mpipe_xgbe_drv = {
-   .name = "xgbe",
.type = PMD_VDEV,
.init = rte_pmd_mpipe_devinit,
 };

 static struct rte_driver pmd_mpipe_gbe_drv = {
-   .name = "gbe",
.type = PMD_VDEV,
.init = rte_pmd_mpipe_devinit,
 };
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index ae0ff77..367b884 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -687,7 +687,6 @@ rte_pmd_null_devuninit(const char *name)
 }

 static struct rte_driver pmd_null_drv = {
-   .name = "eth_null",
.type = PMD_VDEV,
.init = rte_pmd_null_devinit,
.uninit = rte_pmd_null_devuninit

[dpdk-dev] [PATCH 1/5] drivers: revert vdev driver names to original

2016-07-09 Thread Pablo de Lara
In order to avoid API breakage, the driver names of the virtual devices
have been renamed to their original name, before the modification
of the PMD_REGISTER_DRIVER macro, which sets now the driver names.

Fixes: cb6696d22023 ("drivers: update registration macro usage")

Signed-off-by: Pablo de Lara 
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 4 ++--
 drivers/net/mpipe/mpipe_tilegx.c   | 4 ++--
 drivers/net/pcap/rte_eth_pcap.c| 4 ++--
 drivers/net/xenvirt/rte_eth_xenvirt.c  | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c 
b/drivers/net/bonding/rte_eth_bond_pmd.c
index e2890be..c373746 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -2515,9 +2515,9 @@ static struct rte_driver bond_drv = {
.uninit = bond_uninit,
 };

-PMD_REGISTER_DRIVER(bond_drv, bonding);
+PMD_REGISTER_DRIVER(bond_drv, eth_bond);

-DRIVER_REGISTER_PARAM_STRING(bonding, "slave= primary= mode=[0-4] "
+DRIVER_REGISTER_PARAM_STRING(eth_bond, "slave= primary= mode=[0-4] "
 "xmit_policy=[l2 | l23 | l34] socket_id= mac= "
 "lsc_poll_period_ms= up_delay= down_delay=");

diff --git a/drivers/net/mpipe/mpipe_tilegx.c b/drivers/net/mpipe/mpipe_tilegx.c
index 4a2a905..64f4251 100644
--- a/drivers/net/mpipe/mpipe_tilegx.c
+++ b/drivers/net/mpipe/mpipe_tilegx.c
@@ -1635,8 +1635,8 @@ static struct rte_driver pmd_mpipe_gbe_drv = {
.init = rte_pmd_mpipe_devinit,
 };

-PMD_REGISTER_DRIVER(pmd_mpipe_xgbe_drv, mpipe_xgbe);
-PMD_REGISTER_DRIVER(pmd_mpipe_gbe_drv, mpipe_gbe);
+PMD_REGISTER_DRIVER(pmd_mpipe_xgbe_drv, xgbe);
+PMD_REGISTER_DRIVER(pmd_mpipe_gbe_drv, gbe);

 static void __attribute__((constructor, used))
 mpipe_init_contexts(void)
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index b341f93..7125823 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -1090,6 +1090,6 @@ static struct rte_driver pmd_pcap_drv = {
.uninit = rte_pmd_pcap_devuninit,
 };

-PMD_REGISTER_DRIVER(pmd_pcap_drv, pcap);
-DRIVER_REGISTER_PARAM_STRING(pcap, "rx_pcap= tx_pcap= "
+PMD_REGISTER_DRIVER(pmd_pcap_drv, eth_pcap);
+DRIVER_REGISTER_PARAM_STRING(eth_pcap, "rx_pcap= tx_pcap= "
 "rx_iface= tx_iface= iface=");
diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c 
b/drivers/net/xenvirt/rte_eth_xenvirt.c
index 47e3299..5122559 100644
--- a/drivers/net/xenvirt/rte_eth_xenvirt.c
+++ b/drivers/net/xenvirt/rte_eth_xenvirt.c
@@ -766,4 +766,4 @@ static struct rte_driver pmd_xenvirt_drv = {
.uninit = rte_pmd_xenvirt_devuninit,
 };

-PMD_REGISTER_DRIVER(pmd_xenvirt_drv, xenvirt);
+PMD_REGISTER_DRIVER(pmd_xenvirt_drv, eth_xenvirt);
-- 
2.7.4



[dpdk-dev] [PATCH 0/5] Driver register fixes

2016-07-09 Thread Pablo de Lara
This patchset makes some extra changes after the modification
of the PMD_REGISTER_DRIVER macro, including renaming back
some virtual device driver names (virtio could not be renamed)
and fixing/adding arguments of some drivers. 

Pablo de Lara (5):
  drivers: revert vdev driver names to original
  drivers: remove static driver names
  drivers: split driver arguments in multiple lines
  drivers: add missing virtio and xenvirt arguments
  net/bonding: fix range of mode argument

 drivers/crypto/aesni_gcm/aesni_gcm_pmd.c   |  6 --
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c |  6 --
 drivers/crypto/kasumi/rte_kasumi_pmd.c |  6 --
 drivers/crypto/null/null_crypto_pmd.c  |  6 --
 drivers/crypto/snow3g/rte_snow3g_pmd.c |  6 --
 drivers/net/af_packet/rte_eth_af_packet.c  |  9 ++---
 drivers/net/bnxt/bnxt_ethdev.c |  1 -
 drivers/net/bonding/rte_eth_bond_pmd.c | 19 ---
 drivers/net/cxgbe/cxgbe_ethdev.c   |  1 -
 drivers/net/ena/ena_ethdev.c   |  1 -
 drivers/net/mlx4/mlx4.c|  1 -
 drivers/net/mlx5/mlx5.c|  1 -
 drivers/net/mpipe/mpipe_tilegx.c   |  6 ++
 drivers/net/null/rte_eth_null.c|  5 +++--
 drivers/net/pcap/rte_eth_pcap.c| 11 +++
 drivers/net/ring/rte_eth_ring.c|  4 ++--
 drivers/net/szedata2/rte_eth_szedata2.c|  7 +++
 drivers/net/thunderx/nicvf_ethdev.c|  1 -
 drivers/net/vhost/rte_eth_vhost.c  |  5 +++--
 drivers/net/virtio/virtio_user_ethdev.c|  7 ++-
 drivers/net/xenvirt/rte_eth_xenvirt.c  |  5 +++--
 21 files changed, 67 insertions(+), 47 deletions(-)

-- 
2.7.4



[dpdk-dev] [PATCH v2] crypto: normalize cryptodev pmd names with macros

2016-07-08 Thread Pablo de Lara
Recently reported, the introduction of pmd information exports led to a
breakage of cryptodev unit tests because the test infrastructure relies on the
cryptodev names being available in macros.  This patch fixes the pmd naming to
use the macro names.  Note that the macro names were already pre-stringified,
which won't work as the PMD_REGISTER_DRIVER macro requires the name in both a
processing token and stringified form.  As such the names are defined now as
tokens, and converted where needed to stringified form on demand using RTE_STR.

Tested using the null and aesni_mb crypto pmds, as I don't have hardware for any
other device.  Also not build tested on snow3g or kasumi pmd because building
those requires external libraries that appear to not be open source licensed.

Signed-off-by: Neil Horman 
Signed-off-by: Pablo de Lara 
CC: Bruce Richardson 
CC: Thomas Monjalon 
CC: "De Lara Guarch, Pablo" 
CC: Stephen Hemminger 
CC: Panu Matilainen 
---

Changes in v2:
- Fixed compilation issue on snow3g/kasumi pmd
- Removed static name of qat pmd

 app/test/test_cryptodev.c  | 20 ++--
 app/test/test_cryptodev_perf.c | 18 +-
 drivers/crypto/aesni_gcm/aesni_gcm_pmd.c   |  7 +++
 drivers/crypto/aesni_gcm/aesni_gcm_pmd_private.h   |  6 +++---
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c |  7 +++
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd_private.h |  2 +-
 drivers/crypto/kasumi/rte_kasumi_pmd.c |  7 +++
 drivers/crypto/kasumi/rte_kasumi_pmd_private.h |  6 +++---
 drivers/crypto/null/null_crypto_pmd.c  |  7 +++
 drivers/crypto/null/null_crypto_pmd_private.h  |  6 +++---
 drivers/crypto/qat/rte_qat_cryptodev.c |  5 ++---
 drivers/crypto/snow3g/rte_snow3g_pmd.c |  7 +++
 drivers/crypto/snow3g/rte_snow3g_pmd_private.h |  6 +++---
 lib/librte_cryptodev/rte_cryptodev.h   | 12 ++--
 14 files changed, 55 insertions(+), 61 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index fbfe1d0..1e1f887 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -186,12 +186,12 @@ testsuite_setup(void)
if (nb_devs < 2) {
for (i = nb_devs; i < 2; i++) {
ret = rte_eal_vdev_init(
-   CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
+   RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 
NULL);

TEST_ASSERT(ret == 0,
"Failed to create instance %u of"
" pmd : %s",
-   i, CRYPTODEV_NAME_AESNI_MB_PMD);
+   i, 
RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
}
}
}
@@ -203,10 +203,10 @@ testsuite_setup(void)
if (nb_devs < 2) {
for (i = nb_devs; i < 2; i++) {
TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
-   CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
+   RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), 
NULL),
"Failed to create instance %u of"
" pmd : %s",
-   i, CRYPTODEV_NAME_AESNI_GCM_PMD);
+   i, 
RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
}
}
}
@@ -217,10 +217,10 @@ testsuite_setup(void)
if (nb_devs < 2) {
for (i = nb_devs; i < 2; i++) {
TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
-   CRYPTODEV_NAME_SNOW3G_PMD, NULL),
+   RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), 
NULL),
"Failed to create instance %u of"
" pmd : %s",
-   i, CRYPTODEV_NAME_SNOW3G_PMD);
+   i, RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
}
}
}
@@ -231,10 +231,10 @@ testsuite_setup(void)
if (nb_devs < 2) {
for (i = nb_devs; i < 2; i++) {
TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
-   CRYPTODEV_NAME_KASUMI_PMD, NULL),
+   RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), 
NULL),
"Failed to create instance %u of"
" pmd : %s",
-

[dpdk-dev] [PATCH] kasumi: fix AAD size of F9 function

2016-07-08 Thread Pablo de Lara
Additional authenticated data (AAD) in KASUMI F9 (UIA1) is 8 bytes
and not 9 bytes, since direction bit is obtained just after the
end of the message, and it is separated from the AAD.

Fixes: 2773c86d061a ("crypto/kasumi: add driver for KASUMI library")

Signed-off-by: Pablo de Lara 
---
 drivers/crypto/kasumi/rte_kasumi_pmd_ops.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/kasumi/rte_kasumi_pmd_ops.c 
b/drivers/crypto/kasumi/rte_kasumi_pmd_ops.c
index da5854e..b9285a4 100644
--- a/drivers/crypto/kasumi/rte_kasumi_pmd_ops.c
+++ b/drivers/crypto/kasumi/rte_kasumi_pmd_ops.c
@@ -57,8 +57,8 @@ static const struct rte_cryptodev_capabilities 
kasumi_pmd_capabilities[] = {
.increment = 0
},
.aad_size = {
-   .min = 9,
-   .max = 9,
+   .min = 8,
+   .max = 8,
.increment = 0
}
}, }
-- 
2.5.0



[dpdk-dev] [PATCH] cryptodev: move new cryptodev type to bottom of enum

2016-07-06 Thread Pablo de Lara
New cryptodev type for the new KASUMI PMD was added
in the cryptodev type enum, but not at the end of it,
causing an ABI breakage.

Fixes: 2773c86d061a ("crypto/kasumi: add driver for KASUMI library")

Signed-off-by: Pablo de Lara 
Reported-by: Ferruh Yigit 
---
 lib/librte_cryptodev/rte_cryptodev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_cryptodev/rte_cryptodev.h 
b/lib/librte_cryptodev/rte_cryptodev.h
index 7768f0a..508c1f7 100644
--- a/lib/librte_cryptodev/rte_cryptodev.h
+++ b/lib/librte_cryptodev/rte_cryptodev.h
@@ -67,9 +67,9 @@ enum rte_cryptodev_type {
RTE_CRYPTODEV_NULL_PMD = 1, /**< Null crypto PMD */
RTE_CRYPTODEV_AESNI_GCM_PMD,/**< AES-NI GCM PMD */
RTE_CRYPTODEV_AESNI_MB_PMD, /**< AES-NI multi buffer PMD */
-   RTE_CRYPTODEV_KASUMI_PMD,   /**< KASUMI PMD */
RTE_CRYPTODEV_QAT_SYM_PMD,  /**< QAT PMD Symmetric Crypto */
RTE_CRYPTODEV_SNOW3G_PMD,   /**< SNOW 3G PMD */
+   RTE_CRYPTODEV_KASUMI_PMD,   /**< KASUMI PMD */
 };

 extern const char **rte_cyptodev_names;
-- 
2.5.5



[dpdk-dev] [PATCH] examples/l2fwd-crypto: flush crypto dev buffers

2016-07-06 Thread Pablo de Lara
Crypto operations are enqueued in the crypto devices
when the crypto device buffers are full (MAX_PKT_BURST),
in order to be more efficient.

The problem is that operations might be stuck in those buffers,
if they never get full, and therefore, those operations
will never be performed.

Therefore, it is necessary to have a buffer flush mechanism,
similar to the one used for flush the TX buffers, so eventually,
all packets received are ciphered and sent out.

Fixes: 387259bd6c67 ("examples/l2fwd-crypto: add sample application")

Signed-off-by: Pablo de Lara 
---
 examples/l2fwd-crypto/main.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index 8dc616d..23b20b1 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -628,7 +628,7 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)

unsigned lcore_id = rte_lcore_id();
uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
-   unsigned i, j, portid, nb_rx;
+   unsigned i, j, portid, nb_rx, len;
struct lcore_queue_conf *qconf = _queue_conf[lcore_id];
const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
US_PER_S * BURST_TX_DRAIN_US;
@@ -727,10 +727,18 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)
cur_tsc = rte_rdtsc();

/*
-* TX burst queue drain
+* Crypto device/TX burst queue drain
 */
diff_tsc = cur_tsc - prev_tsc;
if (unlikely(diff_tsc > drain_tsc)) {
+   /* Enqueue all crypto ops remaining in buffers */
+   for (i = 0; i < qconf->nb_crypto_devs; i++) {
+   cparams = _cparams[i];
+   len = qconf->op_buf[cparams->dev_id].len;
+   l2fwd_crypto_send_burst(qconf, len, cparams);
+   qconf->op_buf[cparams->dev_id].len = 0;
+   }
+   /* Transmit all packets remaining in buffers */
for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
if (qconf->pkt_buf[portid].len == 0)
continue;
-- 
2.5.5



[dpdk-dev] [PATCH] doc: announce API change for virtual device initialization

2016-07-04 Thread Pablo de Lara
In order to create a virtual device, user needs to call
rte_eal_vdev_init generally, but this function returns 0
on success or negative number if error. Instead, something
more useful would be to return the port or device id of the
device created, so the user can call rte_eal_vdev_init
function and use the device straight away, using the id returned
by the function.

Signed-off-by: Pablo de Lara 
---
 doc/guides/rel_notes/deprecation.rst | 5 +
 1 file changed, 5 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst 
b/doc/guides/rel_notes/deprecation.rst
index f502f86..60cc7c7 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -41,3 +41,8 @@ Deprecation Notices
 * The mempool functions for single/multi producer/consumer are deprecated and
   will be removed in 16.11.
   It is replaced by rte_mempool_generic_get/put functions.
+
+* The rte_eal_vdev_init function will be changed in 16.11 to return
+  the port/device id of the device created, instead of 0, when it has been
+  initialized successfully, so user can use the returned value straight away
+  to call all the device functions that require that parameter.
-- 
2.5.0



[dpdk-dev] [PATCH] app/testpmd: limit number of forwarding cores

2016-06-28 Thread Pablo de Lara
Number of forwarding cores must be equal or less than
number of forwarding streams, otherwise two cores
would try to use a same queue on a port, which is not allowed.

Fixes: f2bb7ae1d204 ("app/testpmd: handle all Rx queues in RSS setup")

Signed-off-by: Pablo de Lara 
---
 app/test-pmd/config.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 9ccabf9..de60284 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1236,6 +1236,10 @@ rss_fwd_config_setup(void)
cur_fwd_config.nb_fwd_streams =
(streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);

+   if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
+   cur_fwd_config.nb_fwd_lcores =
+   (lcoreid_t)cur_fwd_config.nb_fwd_streams;
+
/* reinitialize forwarding streams */
init_fwd_streams();

-- 
2.5.5



[dpdk-dev] [PATCH] app/test: avoid freeing mbuf twice

2016-06-25 Thread Pablo de Lara
In cryptodev tests, when input and output buffers were the same,
the mbuf was being freed twice, causing refcnt_atomic to be negative.

Fixes: 202d375c60bc ("app/test: add cryptodev unit and performance tests")

Signed-off-by: Pablo de Lara 
---
 app/test/test_cryptodev.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 1a67ffb..67608ff 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -396,10 +396,13 @@ ut_teardown(void)

/*
 * free mbuf - both obuf and ibuf are usually the same,
-* but rte copes even if we call free twice
+* so check if they point at the same address is necessary,
+* to avoid freeing the mbuf twice.
 */
if (ut_params->obuf) {
rte_pktmbuf_free(ut_params->obuf);
+   if (ut_params->ibuf == ut_params->obuf)
+   ut_params->ibuf = 0;
ut_params->obuf = 0;
}
if (ut_params->ibuf) {
-- 
2.5.0



[dpdk-dev] [PATCH] kni: fix compilation with gcc 6.1

2016-06-23 Thread Pablo de Lara
Using gcc 6.1, in some cases, kni fails to compile
because of unused variables:

build/lib/librte_eal/linuxapp/kni/ixgbe_main.c:82:19:
error: ?ixgbe_copyright?
defined but not used [-Werror=unused-const-variable=]
static const char ixgbe_copyright[] =
   ^~~

build/lib/librte_eal/linuxapp/kni/ixgbe_main.c:62:19:
error: ?ixgbe_driver_string?
defined but not used [-Werror=unused-const-variable=]
static const char ixgbe_driver_string[] =

Fixes: 3fc5ca2f6352 ("kni: initial import")

Signed-off-by: Pablo de Lara 
---
 lib/librte_eal/linuxapp/kni/ethtool/ixgbe/ixgbe_main.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/lib/librte_eal/linuxapp/kni/ethtool/ixgbe/ixgbe_main.c 
b/lib/librte_eal/linuxapp/kni/ethtool/ixgbe/ixgbe_main.c
index 8c1d2fe..92fc9fc 100644
--- a/lib/librte_eal/linuxapp/kni/ethtool/ixgbe/ixgbe_main.c
+++ b/lib/librte_eal/linuxapp/kni/ethtool/ixgbe/ixgbe_main.c
@@ -59,8 +59,6 @@
 #undef CONFIG_DCA_MODULE

 char ixgbe_driver_name[] = "ixgbe";
-static const char ixgbe_driver_string[] =
- "Intel(R) 10 Gigabit PCI Express Network Driver";
 #define DRV_HW_PERF

 #ifndef CONFIG_IXGBE_NAPI
@@ -79,8 +77,6 @@ static const char ixgbe_driver_string[] =
 #define DRV_VERSION__stringify(MAJ) "." __stringify(MIN) "." \
__stringify(BUILD) DRIVERNAPI DRV_HW_PERF FPGA VMDQ_TAG
 const char ixgbe_driver_version[] = DRV_VERSION;
-static const char ixgbe_copyright[] =
-   "Copyright (c) 1999-2012 Intel Corporation.";

 /* ixgbe_pci_tbl - PCI Device ID Table
  *
-- 
2.5.5



[dpdk-dev] [PATCH v4 11/11] test: refactor snow3g/kasumi tests

2016-06-20 Thread Pablo de Lara
SNOW3G and KASUMI unit tests are very similar and
they were using duplicated code, so this commit
refactor and remove some of the duplicated functions.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c | 440 --
 1 file changed, 150 insertions(+), 290 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 7a8fda0..1a67ffb 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1091,10 +1091,11 @@ test_AES_qat_all(void)

 /* * Snow3G Tests * */
 static int
-create_snow3g_hash_session(uint8_t dev_id,
+create_snow3g_kasumi_hash_session(uint8_t dev_id,
const uint8_t *key, const uint8_t key_len,
const uint8_t aad_len, const uint8_t auth_len,
-   enum rte_crypto_auth_operation op)
+   enum rte_crypto_auth_operation op,
+   enum rte_crypto_auth_algorithm algo)
 {
uint8_t hash_key[key_len];

@@ -1109,7 +1110,7 @@ create_snow3g_hash_session(uint8_t dev_id,
ut_params->auth_xform.next = NULL;

ut_params->auth_xform.auth.op = op;
-   ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
+   ut_params->auth_xform.auth.algo = algo;
ut_params->auth_xform.auth.key.length = key_len;
ut_params->auth_xform.auth.key.data = hash_key;
ut_params->auth_xform.auth.digest_length = auth_len;
@@ -1121,36 +1122,9 @@ create_snow3g_hash_session(uint8_t dev_id,
 }

 static int
-create_kasumi_hash_session(uint8_t dev_id,
-   const uint8_t *key, const uint8_t key_len,
-   const uint8_t aad_len, const uint8_t auth_len,
-   enum rte_crypto_auth_operation op)
-{
-   uint8_t hash_key[key_len];
-
-   struct crypto_unittest_params *ut_params = _params;
-
-   memcpy(hash_key, key, key_len);
-   TEST_HEXDUMP(stdout, "key:", key, key_len);
-   /* Setup Authentication Parameters */
-   ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
-   ut_params->auth_xform.next = NULL;
-
-   ut_params->auth_xform.auth.op = op;
-   ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_KASUMI_F9;
-   ut_params->auth_xform.auth.key.length = key_len;
-   ut_params->auth_xform.auth.key.data = hash_key;
-   ut_params->auth_xform.auth.digest_length = auth_len;
-   ut_params->auth_xform.auth.add_auth_data_length = aad_len;
-   ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
-   _params->auth_xform);
-   TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
-   return 0;
-}
-
-static int
-create_kasumi_cipher_session(uint8_t dev_id,
+create_snow3g_kasumi_cipher_session(uint8_t dev_id,
enum rte_crypto_cipher_operation op,
+   enum rte_crypto_cipher_algorithm algo,
const uint8_t *key, const uint8_t key_len)
 {
uint8_t cipher_key[key_len];
@@ -1163,7 +1137,7 @@ create_kasumi_cipher_session(uint8_t dev_id,
ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
ut_params->cipher_xform.next = NULL;

-   ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_KASUMI_F8;
+   ut_params->cipher_xform.cipher.algo = algo;
ut_params->cipher_xform.cipher.op = op;
ut_params->cipher_xform.cipher.key.data = cipher_key;
ut_params->cipher_xform.cipher.key.length = key_len;
@@ -1179,9 +1153,10 @@ create_kasumi_cipher_session(uint8_t dev_id,
 }

 static int
-create_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
+create_snow3g_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
const unsigned cipher_len,
-   const unsigned cipher_offset)
+   const unsigned cipher_offset,
+   enum rte_crypto_cipher_algorithm algo)
 {
struct crypto_testsuite_params *ts_params = _params;
struct crypto_unittest_params *ut_params = _params;
@@ -1202,7 +1177,11 @@ create_kasumi_cipher_operation(const uint8_t *iv, const 
unsigned iv_len,
sym_op->m_src = ut_params->ibuf;

/* iv */
-   iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
+   if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
+   iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
+   else
+   iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
+
sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
, iv_pad_len);

@@ -1219,9 +1198,10 @@ create_kasumi_cipher_operation(const uint8_t *iv, const 
unsigned iv_len,
 }

 static int
-create_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
+create_snow3g_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t 
iv_len,
const unsigned cipher_len,
-   const

[dpdk-dev] [PATCH v4 10/11] test: add Snow3G UEA2 test with offset

2016-06-20 Thread Pablo de Lara
With the new libsso library, buffers can be encrypted/decrypted,
providing an offset in bits, so an extra unit test has been
added to cover this case.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c | 121 ++
 1 file changed, 121 insertions(+)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 546ae92..7a8fda0 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -2553,6 +2553,118 @@ test_snow3g_encryption_oop(const struct 
snow3g_test_data *tdata)
return 0;
 }

+/* Shift right a buffer by "offset" bits, "offset" < 8 */
+static void
+buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
+{
+   uint8_t curr_byte, prev_byte;
+   uint32_t length_in_bytes = ceil_byte_length(length + offset);
+   uint8_t lower_byte_mask = (1 << offset) - 1;
+   unsigned i;
+
+   prev_byte = buffer[0];
+   buffer[0] >>= offset;
+
+   for (i = 1; i < length_in_bytes; i++) {
+   curr_byte = buffer[i];
+   buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
+   (curr_byte >> offset);
+   prev_byte = curr_byte;
+   }
+}
+
+static int
+test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
+{
+   struct crypto_testsuite_params *ts_params = _params;
+   struct crypto_unittest_params *ut_params = _params;
+   uint8_t *plaintext, *ciphertext;
+   int retval;
+   uint32_t plaintext_len;
+   uint32_t plaintext_pad_len;
+   uint8_t extra_offset = 4;
+   uint8_t *expected_ciphertext_shifted;
+
+   /* Create SNOW3G session */
+   retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
+   RTE_CRYPTO_CIPHER_OP_ENCRYPT,
+   tdata->key.data, tdata->key.len);
+   if (retval < 0)
+   return retval;
+
+   ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+   ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+   TEST_ASSERT_NOT_NULL(ut_params->ibuf,
+   "Failed to allocate input buffer in mempool");
+   TEST_ASSERT_NOT_NULL(ut_params->obuf,
+   "Failed to allocate output buffer in mempool");
+
+   /* Clear mbuf payload */
+   memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+  rte_pktmbuf_tailroom(ut_params->ibuf));
+
+   plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
+   /*
+* Append data which is padded to a
+* multiple of the algorithms block size
+*/
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
+
+   plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
+   plaintext_pad_len);
+
+   rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
+
+   memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
+   buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
+
+#ifdef RTE_APP_TEST_DEBUG
+   rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
+#endif
+   /* Create SNOW3G operation */
+   retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
+   tdata->iv.len,
+   tdata->validCipherLenInBits.len,
+   tdata->validCipherOffsetLenInBits.len +
+   extra_offset);
+   if (retval < 0)
+   return retval;
+
+   ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+   ut_params->op);
+   TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
+
+   ut_params->obuf = ut_params->op->sym->m_dst;
+   if (ut_params->obuf)
+   ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
+   + tdata->iv.len;
+   else
+   ciphertext = plaintext;
+
+#ifdef RTE_APP_TEST_DEBUG
+   rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
+#endif
+
+   expected_ciphertext_shifted = rte_malloc(NULL,
+   ceil_byte_length(plaintext_len + extra_offset), 0);
+
+   TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
+   "failed to reserve memory for ciphertext shifted\n");
+
+   memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
+   ceil_byte_length(tdata->ciphertext.len));
+   buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
+

[dpdk-dev] [PATCH v4 09/11] test: add bit-level Snow3G UIA2 tests

2016-06-20 Thread Pablo de Lara
Snow3G PMD supports now buffers that are non byte multiple,
so tests to cover this case have been added.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c  |  50 ++
 app/test/test_cryptodev_snow3g_hash_test_vectors.h | 107 +
 2 files changed, 157 insertions(+)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 803f1f6..546ae92 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -2048,6 +2048,24 @@ test_snow3g_hash_generate_test_case_3(void)
 }

 static int
+test_snow3g_hash_generate_test_case_4(void)
+{
+   return test_snow3g_authentication(_hash_test_case_4);
+}
+
+static int
+test_snow3g_hash_generate_test_case_5(void)
+{
+   return test_snow3g_authentication(_hash_test_case_5);
+}
+
+static int
+test_snow3g_hash_generate_test_case_6(void)
+{
+   return test_snow3g_authentication(_hash_test_case_6);
+}
+
+static int
 test_snow3g_hash_verify_test_case_1(void)
 {
return test_snow3g_authentication_verify(_hash_test_case_1);
@@ -2067,6 +2085,24 @@ test_snow3g_hash_verify_test_case_3(void)
 }

 static int
+test_snow3g_hash_verify_test_case_4(void)
+{
+   return test_snow3g_authentication_verify(_hash_test_case_4);
+}
+
+static int
+test_snow3g_hash_verify_test_case_5(void)
+{
+   return test_snow3g_authentication_verify(_hash_test_case_5);
+}
+
+static int
+test_snow3g_hash_verify_test_case_6(void)
+{
+   return test_snow3g_authentication_verify(_hash_test_case_6);
+}
+
+static int
 test_kasumi_hash_generate_test_case_1(void)
 {
return test_kasumi_authentication(_hash_test_case_1);
@@ -4079,12 +4115,26 @@ static struct unit_test_suite 
cryptodev_sw_snow3g_testsuite  = {
test_snow3g_hash_generate_test_case_2),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_hash_generate_test_case_3),
+   /* Tests with buffers which length is not byte-aligned */
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_generate_test_case_4),
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_generate_test_case_5),
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_generate_test_case_6),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_hash_verify_test_case_1),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_hash_verify_test_case_2),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_hash_verify_test_case_3),
+   /* Tests with buffers which length is not byte-aligned */
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_verify_test_case_4),
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_verify_test_case_5),
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_verify_test_case_6),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_authenticated_encryption_test_case_1),
TEST_CASE_ST(ut_setup, ut_teardown,
diff --git a/app/test/test_cryptodev_snow3g_hash_test_vectors.h 
b/app/test/test_cryptodev_snow3g_hash_test_vectors.h
index fe4906b..a8a47db 100644
--- a/app/test/test_cryptodev_snow3g_hash_test_vectors.h
+++ b/app/test/test_cryptodev_snow3g_hash_test_vectors.h
@@ -438,4 +438,111 @@ struct snow3g_hash_test_data snow3g_hash_test_case_3 = {
}
 };

+struct snow3g_hash_test_data snow3g_hash_test_case_4 = {
+   .key = {
+   .data = {
+   0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00,
+   0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48
+   },
+   .len = 16
+   },
+   .aad = {
+   .data = {
+   0x38, 0xA6, 0xF0, 0x56, 0x05, 0xD2, 0xEC, 0x49,
+   0x38, 0xA6, 0xF0, 0x56, 0x05, 0xD2, 0xEC, 0x49,
+   },
+   .len = 16
+   },
+   .plaintext = {
+   .data = {
+   0x6B, 0x22, 0x77, 0x37, 0x29, 0x6F, 0x39, 0x3C,
+   0x80, 0x79, 0x35, 0x3E, 0xDC, 0x87, 0xE2, 0xE8,
+   0x05, 0xD2, 0xEC, 0x49, 0xA4, 0xF2, 0xD8, 0xE0
+   },
+   .len = 189
+   },
+   .validAuthLenInBits = {
+   .len = 189
+   },
+   .validAuthOffsetLenInBits = {
+   .len = 128
+   },
+   .digest = {
+   .data = {0x2B, 0xCE, 0x18, 0x20},
+   .len  = 4
+   }
+};
+
+struct snow3g_hash_test_data snow3g_hash_test_case_5 = {
+   .key = {
+   .data = {
+   0xD4, 0x2F, 0x68, 0x24, 0x28, 0x20, 0x1C, 0xAF,
+   0xCD, 0x9F

[dpdk-dev] [PATCH v4 07/11] test: fix buffer lengths for snow3G tests

2016-06-20 Thread Pablo de Lara
No padding was added in the input buffers for snow3G tests,
due to a wrong calculation of the length (should be multiple
of the block size). This fix takes into account the case
where the length is not byte multiple.

Fixes: 8bdf665fe6c0 ("app/test: add SNOW 3G")

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c | 139 ++
 1 file changed, 66 insertions(+), 73 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 3ff74cd..7dc5648 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1801,6 +1801,7 @@ test_snow3g_authentication(const struct 
snow3g_hash_test_data *tdata)

int retval;
unsigned plaintext_pad_len;
+   unsigned plaintext_len;
uint8_t *plaintext;

/* Create SNOW3G session */
@@ -1817,12 +1818,13 @@ test_snow3g_authentication(const struct 
snow3g_hash_test_data *tdata)
memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
rte_pktmbuf_tailroom(ut_params->ibuf));

+   plaintext_len = ceil_byte_length(tdata->plaintext.len);
/* Append data which is padded to a multiple of */
/* the algorithms block size */
-   plaintext_pad_len = tdata->plaintext.len >> 3;
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
plaintext_pad_len);
-   memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
+   memcpy(plaintext, tdata->plaintext.data, plaintext_len);

/* Create SNOW3G opertaion */
retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
@@ -1858,6 +1860,7 @@ test_snow3g_authentication_verify(const struct 
snow3g_hash_test_data *tdata)

int retval;
unsigned plaintext_pad_len;
+   unsigned plaintext_len;
uint8_t *plaintext;

/* Create SNOW3G session */
@@ -1873,12 +1876,13 @@ test_snow3g_authentication_verify(const struct 
snow3g_hash_test_data *tdata)
memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
rte_pktmbuf_tailroom(ut_params->ibuf));

-   /* Append data which is padded to a multiple */
-   /* of the algorithms block size */
-   plaintext_pad_len = tdata->plaintext.len >> 3;
+   plaintext_len = ceil_byte_length(tdata->plaintext.len);
+   /* Append data which is padded to a multiple of */
+   /* the algorithms block size */
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
-   plaintext_pad_len);
-   memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
+   plaintext_pad_len);
+   memcpy(plaintext, tdata->plaintext.data, plaintext_len);

/* Create SNOW3G operation */
retval = create_snow3g_hash_operation(tdata->digest.data,
@@ -2386,7 +2390,8 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)

int retval;
uint8_t *plaintext, *ciphertext;
-   uint8_t plaintext_pad_len;
+   unsigned plaintext_pad_len;
+   unsigned plaintext_len;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2401,16 +2406,13 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)
memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
   rte_pktmbuf_tailroom(ut_params->ibuf));

-   /*
-* Append data which is padded to a
-* multiple of the algorithms block size
-*/
-   /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
-   plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
-
-   plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
-   plaintext_pad_len);
-   memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
+   plaintext_len = ceil_byte_length(tdata->plaintext.len);
+   /* Append data which is padded to a multiple of */
+   /* the algorithms block size */
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
+   plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
+   plaintext_pad_len);
+   memcpy(plaintext, tdata->plaintext.data, plaintext_len);

TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);

@@ -2452,7 +2454,8 @@ test_snow3g_encryption_oop(const struct snow3g_test_data 
*tdata)
uint8_t *plaintext, *ciphertext;

int retval;
-   uint8_t plaintext_pad_len;
+   unsigned plaintext_pad_len;
+   unsigned plaintext_len;

/* Create SNOW3G session */
retval = crea

[dpdk-dev] [PATCH v4 06/11] test: use new bit-level memcmp macro

2016-06-20 Thread Pablo de Lara
Instead of modifying the content of the buffers, to compare them
at bit-level, use the new macro TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT,
which does not make any modifications in the buffers.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c | 68 +--
 1 file changed, 12 insertions(+), 56 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 3199d6e..3ff74cd 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -2387,8 +2387,6 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)
int retval;
uint8_t *plaintext, *ciphertext;
uint8_t plaintext_pad_len;
-   uint8_t lastByteValidBits = 8;
-   uint8_t lastByteMask = 0xFF;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2434,19 +2432,13 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)
else
ciphertext = plaintext;

-   lastByteValidBits = (tdata->validDataLenInBits.len % 8);
-   if (lastByteValidBits == 0)
-   lastByteValidBits = 8;
-   lastByteMask = lastByteMask << (8 - lastByteValidBits);
-   (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
-
TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);

/* Validate obuf */
-   TEST_ASSERT_BUFFERS_ARE_EQUAL(
+   TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
ciphertext,
tdata->ciphertext.data,
-   tdata->ciphertext.len >> 3,
+   tdata->validDataLenInBits.len,
"Snow3G Ciphertext data not as expected");
return 0;
 }
@@ -2461,8 +2453,6 @@ test_snow3g_encryption_oop(const struct snow3g_test_data 
*tdata)

int retval;
uint8_t plaintext_pad_len;
-   uint8_t lastByteValidBits = 8;
-   uint8_t lastByteMask = 0xFF;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2519,19 +2509,13 @@ test_snow3g_encryption_oop(const struct 
snow3g_test_data *tdata)
else
ciphertext = plaintext;

-   lastByteValidBits = (tdata->validDataLenInBits.len % 8);
-   if (lastByteValidBits == 0)
-   lastByteValidBits = 8;
-   lastByteMask = lastByteMask << (8 - lastByteValidBits);
-   (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
-
TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);

/* Validate obuf */
-   TEST_ASSERT_BUFFERS_ARE_EQUAL(
+   TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
ciphertext,
tdata->ciphertext.data,
-   tdata->ciphertext.len >> 3,
+   tdata->validDataLenInBits.len,
"Snow3G Ciphertext data not as expected");
return 0;
 }
@@ -2546,8 +2530,6 @@ static int test_snow3g_decryption(const struct 
snow3g_test_data *tdata)

uint8_t *plaintext, *ciphertext;
uint8_t ciphertext_pad_len;
-   uint8_t lastByteValidBits = 8;
-   uint8_t lastByteMask = 0xFF;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2590,18 +2572,13 @@ static int test_snow3g_decryption(const struct 
snow3g_test_data *tdata)
+ tdata->iv.len;
else
plaintext = ciphertext;
-   lastByteValidBits = (tdata->validDataLenInBits.len  % 8);
-   if (lastByteValidBits == 0)
-   lastByteValidBits = 8;
-   lastByteMask = lastByteMask << (8 - lastByteValidBits);
-   (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;

TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);

/* Validate obuf */
-   TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
+   TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
tdata->plaintext.data,
-   tdata->plaintext.len >> 3,
+   tdata->validDataLenInBits.len,
"Snow3G Plaintext data not as expected");
return 0;
 }
@@ -2615,8 +2592,6 @@ static int test_snow3g_decryption_oop(const struct 
snow3g_test_data *tdata)

uint8_t *plaintext, *ciphertext;
uint8_t ciphertext_pad_len;
-   uint8_t lastByteValidBits = 8;
-   uint8_t lastByteMask = 0xFF;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2673,18 +2648,13 @@ static int test_snow3g_decryption_oop(const struct 
snow3g_test_data *tdata)
+ tdata->iv.len;
else
   

[dpdk-dev] [PATCH v4 05/11] snow3g: add missing feature flags

2016-06-20 Thread Pablo de Lara
The underlying libsso library support SSE4.1 instruction set,
so feature flags of the crypto device must be updated
to reflect this.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 drivers/crypto/snow3g/rte_snow3g_pmd.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd.c 
b/drivers/crypto/snow3g/rte_snow3g_pmd.c
index b90d27d..6d59de7 100644
--- a/drivers/crypto/snow3g/rte_snow3g_pmd.c
+++ b/drivers/crypto/snow3g/rte_snow3g_pmd.c
@@ -555,6 +555,16 @@ cryptodev_snow3g_create(const char *name,
struct rte_cryptodev *dev;
char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
struct snow3g_private *internals;
+   uint64_t cpu_flags = 0;
+
+   /* Check CPU for supported vector instruction set */
+   if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_1))
+   cpu_flags |= RTE_CRYPTODEV_FF_CPU_SSE;
+   else {
+   SNOW3G_LOG_ERR("Vector instructions are not supported by CPU");
+   return -EFAULT;
+   }
+

/* Create a unique device name. */
if (create_unique_device_name(crypto_dev_name,
@@ -578,7 +588,8 @@ cryptodev_snow3g_create(const char *name,
dev->enqueue_burst = snow3g_pmd_enqueue_burst;

dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
-   RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING;
+   RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
+   cpu_flags;

internals = dev->data->dev_private;

-- 
2.5.0



[dpdk-dev] [PATCH v4 04/11] snow3g: support bit-level operations

2016-06-20 Thread Pablo de Lara
Underlying libsso_snow3g library now supports bit-level
operations, so PMD has been updated to allow them.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 doc/guides/cryptodevs/snow3g.rst   |   5 +-
 drivers/crypto/snow3g/rte_snow3g_pmd.c | 193 -
 2 files changed, 142 insertions(+), 56 deletions(-)

diff --git a/doc/guides/cryptodevs/snow3g.rst b/doc/guides/cryptodevs/snow3g.rst
index 418b9f0..670a62a 100644
--- a/doc/guides/cryptodevs/snow3g.rst
+++ b/doc/guides/cryptodevs/snow3g.rst
@@ -51,8 +51,9 @@ Limitations
 ---

 * Chained mbufs are not supported.
-* Snow3g(UEA2) supported only if cipher length, cipher offset fields are 
byte-aligned.
-* Snow3g(UIA2) supported only if hash length, hash offset fields are 
byte-aligned.
+* Snow3g(UIA2) supported only if hash offset field is byte-aligned.
+* In-place bit-level operations for Snow3g(UEA2) are not supported
+  (if length and/or offset of data to be ciphered is not byte-aligned).

 Installation
 
diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd.c 
b/drivers/crypto/snow3g/rte_snow3g_pmd.c
index 8bbee8a..b90d27d 100644
--- a/drivers/crypto/snow3g/rte_snow3g_pmd.c
+++ b/drivers/crypto/snow3g/rte_snow3g_pmd.c
@@ -206,14 +206,6 @@ process_snow3g_cipher_op(struct rte_crypto_op **ops,
break;
}

-   if (((ops[i]->sym->cipher.data.length % BYTE_LEN) != 0)
-   || ((ops[i]->sym->cipher.data.offset
-   % BYTE_LEN) != 0)) {
-   ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
-   SNOW3G_LOG_ERR("Data Length or offset");
-   break;
-   }
-
src[i] = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
(ops[i]->sym->cipher.data.offset >> 3);
dst[i] = ops[i]->sym->m_dst ?
@@ -233,6 +225,39 @@ process_snow3g_cipher_op(struct rte_crypto_op **ops,
return processed_ops;
 }

+/** Encrypt/decrypt mbuf (bit level function). */
+static uint8_t
+process_snow3g_cipher_op_bit(struct rte_crypto_op *op,
+   struct snow3g_session *session)
+{
+   uint8_t *src, *dst;
+   uint8_t *IV;
+   uint32_t length_in_bits, offset_in_bits;
+
+   /* Sanity checks. */
+   if (unlikely(op->sym->cipher.iv.length != SNOW3G_IV_LENGTH)) {
+   op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+   SNOW3G_LOG_ERR("iv");
+   return 0;
+   }
+
+   offset_in_bits = op->sym->cipher.data.offset;
+   src = rte_pktmbuf_mtod(op->sym->m_src, uint8_t *);
+   if (op->sym->m_dst == NULL) {
+   op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+   SNOW3G_LOG_ERR("bit-level in-place not supported\n");
+   return 0;
+   }
+   dst = rte_pktmbuf_mtod(op->sym->m_dst, uint8_t *);
+   IV = op->sym->cipher.iv.data;
+   length_in_bits = op->sym->cipher.data.length;
+
+   sso_snow3g_f8_1_buffer_bit(>pKeySched_cipher, IV,
+   src, dst, length_in_bits, offset_in_bits);
+
+   return 1;
+}
+
 /** Generate/verify hash from mbufs with same hash key. */
 static int
 process_snow3g_hash_op(struct rte_crypto_op **ops,
@@ -257,11 +282,10 @@ process_snow3g_hash_op(struct rte_crypto_op **ops,
break;
}

-   if (((ops[i]->sym->auth.data.length % BYTE_LEN) != 0)
-   || ((ops[i]->sym->auth.data.offset
-   % BYTE_LEN) != 0)) {
+   /* Data must be byte aligned */
+   if ((ops[i]->sym->auth.data.offset % BYTE_LEN) != 0) {
ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
-   SNOW3G_LOG_ERR("Data Length or offset");
+   SNOW3G_LOG_ERR("Offset");
break;
}

@@ -301,10 +325,11 @@ process_snow3g_hash_op(struct rte_crypto_op **ops,
 /** Process a batch of crypto ops which shares the same session. */
 static int
 process_ops(struct rte_crypto_op **ops, struct snow3g_session *session,
-   struct snow3g_qp *qp, uint8_t num_ops)
+   struct snow3g_qp *qp, uint8_t num_ops,
+   uint16_t *accumulated_enqueued_ops)
 {
unsigned i;
-   unsigned processed_ops;
+   unsigned enqueued_ops, processed_ops;

switch (session->op) {
case SNOW3G_OP_ONLY_CIPHER:
@@ -344,7 +369,63 @@ process_ops(struct rte_crypto_op **ops, struct 
snow3g_session *session,
}
}

-   return processed_ops;
+   enqueued_ops = rte_ring_enqueue_burst(qp->processed_ops,
+   (void **)ops, p

[dpdk-dev] [PATCH v4 03/11] snow3g: define IV/digest length macros

2016-06-20 Thread Pablo de Lara
In order to avoid using magic numbers, macros for
the IV and digest lengths for Snow3G have been added.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 drivers/crypto/snow3g/rte_snow3g_pmd.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd.c 
b/drivers/crypto/snow3g/rte_snow3g_pmd.c
index f3e0e66..8bbee8a 100644
--- a/drivers/crypto/snow3g/rte_snow3g_pmd.c
+++ b/drivers/crypto/snow3g/rte_snow3g_pmd.c
@@ -42,6 +42,8 @@

 #include "rte_snow3g_pmd_private.h"

+#define SNOW3G_IV_LENGTH 16
+#define SNOW3G_DIGEST_LENGTH 4
 #define SNOW3G_MAX_BURST 8
 #define BYTE_LEN 8

@@ -198,7 +200,7 @@ process_snow3g_cipher_op(struct rte_crypto_op **ops,

for (i = 0; i < num_ops; i++) {
/* Sanity checks. */
-   if (ops[i]->sym->cipher.iv.length != 16) {
+   if (unlikely(ops[i]->sym->cipher.iv.length != 
SNOW3G_IV_LENGTH)) {
ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
SNOW3G_LOG_ERR("iv");
break;
@@ -243,13 +245,13 @@ process_snow3g_hash_op(struct rte_crypto_op **ops,
uint32_t length_in_bits;

for (i = 0; i < num_ops; i++) {
-   if (ops[i]->sym->auth.aad.length != 16) {
+   if (unlikely(ops[i]->sym->auth.aad.length != SNOW3G_IV_LENGTH)) 
{
ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
SNOW3G_LOG_ERR("aad");
break;
}

-   if (ops[i]->sym->auth.digest.length != 4) {
+   if (unlikely(ops[i]->sym->auth.digest.length != 
SNOW3G_DIGEST_LENGTH)) {
ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
SNOW3G_LOG_ERR("digest");
break;
-- 
2.5.0



[dpdk-dev] [PATCH v4 02/11] doc: update build instructions for libsso_snow3g

2016-06-20 Thread Pablo de Lara
With the library update, the way to compile the library
has changed, so documentation reflects this change.
Also, the patch to fix the compilation issues present with gcc > 5.0
has been removed, as the issues have been fixed in the library.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 doc/guides/cryptodevs/snow3g.rst | 41 +---
 1 file changed, 9 insertions(+), 32 deletions(-)

diff --git a/doc/guides/cryptodevs/snow3g.rst b/doc/guides/cryptodevs/snow3g.rst
index 8564c9f..418b9f0 100644
--- a/doc/guides/cryptodevs/snow3g.rst
+++ b/doc/guides/cryptodevs/snow3g.rst
@@ -57,39 +57,16 @@ Limitations
 Installation
 

-To build DPDK with the SNOW3G_PMD the user is required to download
+To build DPDK with the KASUMI_PMD the user is required to download
 the export controlled ``libsso_snow3g`` library, by requesting it from
-`<https://networkbuilders.intel.com/network-technologies/dpdk>`_,
-and compiling it on their system before building DPDK::
-
-   make -f Makefile_snow3g
-
-**Note**: If using a gcc version higher than 5.0, and compilation fails, apply 
the following patch:
-
-.. code-block:: diff
-
-   /libsso/src/snow3g/sso_snow3g.c
-
-   static inline void ClockFSM_4(sso_snow3gKeyState4_t *pCtx, __m128i *data)
-   {
-   __m128i F, R;
-   -uint32_t K, L;
-   +uint32_t K;
-   +/* Declare unused if SNOW3G_WSM/SNB are defined */
-   +uint32_t L __attribute__ ((unused)) = 0;
-
-F = _mm_add_epi32(pCtx->LFSR_X[15], pCtx->FSM_X[0]);
-R = _mm_xor_si128(pCtx->LFSR_X[5], pCtx->FSM_X[2]);
-
-   /libsso/include/sso_snow3g_internal.h
-
-   -inline void ClockFSM_1(sso_snow3gKeyState1_t *pCtx, uint32_t *data);
-   -inline void ClockLFSR_1(sso_snow3gKeyState1_t *pCtx);
-   -inline void sso_snow3gStateInitialize_1(sso_snow3gKeyState1_t * pCtx, 
sso_snow3g_key_schedule_t *pKeySched, uint8_t *pIV);
-   +void ClockFSM_1(sso_snow3gKeyState1_t *pCtx, uint32_t *data);
-   +void ClockLFSR_1(sso_snow3gKeyState1_t *pCtx);
-   +void sso_snow3gStateInitialize_1(sso_snow3gKeyState1_t * pCtx, 
sso_snow3g_key_schedule_t *pKeySched, uint8_t *pIV);
+`<https://networkbuilders.intel.com/network-technologies/dpdk>`_.
+Once approval has been granted, the user needs to log in
+`<https://networkbuilders.intel.com/dpdklogin>`_
+and click on "Snow3G Bit Stream crypto library" link, to download the library.
+After downloading the library, the user needs to unpack and compile it
+on their system before building DPDK::

+   make snow3G

 Initialization
 --
@@ -97,7 +74,7 @@ Initialization
 In order to enable this virtual crypto PMD, user must:

 * Export the environmental variable LIBSSO_SNOW3G_PATH with the path where
-  the library was extracted.
+  the library was extracted (snow3g folder).

 * Build the LIBSSO_SNOW3G library (explained in Installation section).

-- 
2.5.0



[dpdk-dev] [PATCH v4 01/11] snow3g: rename libsso reference due to library update

2016-06-20 Thread Pablo de Lara
The underlying libsso library that SNOW3G PMD uses has been updated,
so now it is called libsso_snow3g. Also, the path to the library
has been renamed to reflect this changes (now called LIBSSO_SNOW3G_PATH).

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 doc/guides/cryptodevs/snow3g.rst |  6 +++---
 drivers/crypto/snow3g/Makefile   | 10 +-
 mk/rte.app.mk|  2 +-
 scripts/test-build.sh|  6 +++---
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/doc/guides/cryptodevs/snow3g.rst b/doc/guides/cryptodevs/snow3g.rst
index c1098b1..8564c9f 100644
--- a/doc/guides/cryptodevs/snow3g.rst
+++ b/doc/guides/cryptodevs/snow3g.rst
@@ -58,7 +58,7 @@ Installation
 

 To build DPDK with the SNOW3G_PMD the user is required to download
-the export controlled ``libsso`` library, by requesting it from
+the export controlled ``libsso_snow3g`` library, by requesting it from
 `<https://networkbuilders.intel.com/network-technologies/dpdk>`_,
 and compiling it on their system before building DPDK::

@@ -96,10 +96,10 @@ Initialization

 In order to enable this virtual crypto PMD, user must:

-* Export the environmental variable LIBSSO_PATH with the path where
+* Export the environmental variable LIBSSO_SNOW3G_PATH with the path where
   the library was extracted.

-* Build the LIBSSO library (explained in Installation section).
+* Build the LIBSSO_SNOW3G library (explained in Installation section).

 * Set CONFIG_RTE_LIBRTE_PMD_SNOW3G=y in config/common_base.

diff --git a/drivers/crypto/snow3g/Makefile b/drivers/crypto/snow3g/Makefile
index ee58270..b86e608 100644
--- a/drivers/crypto/snow3g/Makefile
+++ b/drivers/crypto/snow3g/Makefile
@@ -30,8 +30,8 @@

 include $(RTE_SDK)/mk/rte.vars.mk

-ifeq ($(LIBSSO_PATH),)
-$(error "Please define LIBSSO_PATH environment variable")
+ifeq ($(LIBSSO_SNOW3G_PATH),)
+$(error "Please define LIBSSO_SNOW3G_PATH environment variable")
 endif

 # library name
@@ -48,9 +48,9 @@ LIBABIVER := 1
 EXPORT_MAP := rte_pmd_snow3g_version.map

 # external library include paths
-CFLAGS += -I$(LIBSSO_PATH)
-CFLAGS += -I$(LIBSSO_PATH)/include
-CFLAGS += -I$(LIBSSO_PATH)/build
+CFLAGS += -I$(LIBSSO_SNOW3G_PATH)
+CFLAGS += -I$(LIBSSO_SNOW3G_PATH)/include
+CFLAGS += -I$(LIBSSO_SNOW3G_PATH)/build

 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_SNOW3G) += rte_snow3g_pmd.c
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index 21bed09..0844115 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -133,7 +133,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_GCM)  += 
-L$(AESNI_MULTI_BUFFER_LIB_PATH)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO) += -lrte_pmd_null_crypto
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_QAT)+= -lrte_pmd_qat -lcrypto
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SNOW3G) += -lrte_pmd_snow3g
-_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SNOW3G) += -L$(LIBSSO_PATH)/build -lsso
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SNOW3G) += -L$(LIBSSO_SNOW3G_PATH)/build 
-lsso_snow3g
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_KASUMI) += -lrte_pmd_kasumi
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_KASUMI) += -L$(LIBSSO_KASUMI_PATH)/build 
-lsso_kasumi
 endif # CONFIG_RTE_LIBRTE_CRYPTODEV
diff --git a/scripts/test-build.sh b/scripts/test-build.sh
index 0cfbdbc..31d5583 100755
--- a/scripts/test-build.sh
+++ b/scripts/test-build.sh
@@ -45,7 +45,7 @@ default_path=$PATH
 # - DPDK_DEP_ZLIB (y/[n])
 # - DPDK_MAKE_JOBS (int)
 # - DPDK_NOTIFY (notify-send)
-# - LIBSSO_PATH
+# - LIBSSO_SNOW3G_PATH
 # - LIBSSO_KASUMI_PATH
 . $(dirname $(readlink -e $0))/load-devel-config.sh

@@ -122,7 +122,7 @@ reset_env ()
unset DPDK_DEP_SZE
unset DPDK_DEP_ZLIB
unset AESNI_MULTI_BUFFER_LIB_PATH
-   unset LIBSSO_PATH
+   unset LIBSSO_SNOW3G_PATH
unset LIBSSO_KASUMI_PATH
unset PQOS_INSTALL_PATH
 }
@@ -168,7 +168,7 @@ config () #   
sed -ri   's,(PMD_AESNI_MB=)n,\1y,' $1/.config
test -z "$AESNI_MULTI_BUFFER_LIB_PATH" || \
sed -ri  's,(PMD_AESNI_GCM=)n,\1y,' $1/.config
-   test -z "$LIBSSO_PATH" || \
+   test -z "$LIBSSO_SNOW3G_PATH" || \
sed -ri 's,(PMD_SNOW3G=)n,\1y,' $1/.config
test -z "$LIBSSO_KASUMI_PATH" || \
sed -ri 's,(PMD_KASUMI=)n,\1y,' $1/.config
-- 
2.5.0



[dpdk-dev] [PATCH v4 00/11] Snow3G bit-level support

2016-06-20 Thread Pablo de Lara
The underlying library libsso for Snow3G PMD will be updated,
to support bit-level operations.

This patchset updates the PMD to allow the user to perform
crypto operation at bit-level. It also add some unit tests and
updates the documentation.

This patchset depends on the following patchset:
"Add new KASUMI SW PMD"
(http://dpdk.org/ml/archives/dev/2016-June/041906.html)

Changes in v2:
- Include macros for IV/digest lengths
- Refactored enqueue burst function to avoid duplication
- Added cpu flags in crypto feature flags
- Removed/refactored functions in unit tests

Changes in v3:
- Disabled SNOW3G/KASUMI PMD by default (enabled by mistake in v2)
- Fixed clang issue on v2

Changes in v4:
- Updated documentation, as the library has been released,
  with detailed instructions on how to get the libsso_snow3g library.

Pablo de Lara (11):
  snow3g: rename libsso reference due to library update
  doc: update build instructions for libsso_snow3g
  snow3g: define IV/digest length macros
  snow3g: support bit-level operations
  snow3g: add missing feature flags
  test: use new bit-level memcmp macro
  test: fix buffer lengths for snow3G tests
  test: add out-of-place crypto op tests for Snow3G PMD
  test: add bit-level Snow3G UIA2 tests
  test: add Snow3G UEA2 test with offset
  test: refactor snow3g/kasumi tests

 app/test/test_cryptodev.c  | 803 ++---
 app/test/test_cryptodev_snow3g_hash_test_vectors.h | 107 +++
 doc/guides/cryptodevs/snow3g.rst   |  52 +-
 drivers/crypto/snow3g/Makefile |  10 +-
 drivers/crypto/snow3g/rte_snow3g_pmd.c | 214 --
 mk/rte.app.mk  |   2 +-
 scripts/test-build.sh  |   6 +-
 7 files changed, 681 insertions(+), 513 deletions(-)

-- 
2.5.0



[dpdk-dev] [PATCH v3 3/3] test: add unit tests for KASUMI PMD

2016-06-20 Thread Pablo de Lara
Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c  | 995 +++--
 app/test/test_cryptodev.h  |   1 +
 app/test/test_cryptodev_kasumi_hash_test_vectors.h | 260 ++
 app/test/test_cryptodev_kasumi_test_vectors.h  | 308 +++
 4 files changed, 1475 insertions(+), 89 deletions(-)
 create mode 100644 app/test/test_cryptodev_kasumi_hash_test_vectors.h
 create mode 100644 app/test/test_cryptodev_kasumi_test_vectors.h

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 1acb324..3199d6e 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -44,6 +44,8 @@
 #include "test_cryptodev.h"

 #include "test_cryptodev_aes.h"
+#include "test_cryptodev_kasumi_test_vectors.h"
+#include "test_cryptodev_kasumi_hash_test_vectors.h"
 #include "test_cryptodev_snow3g_test_vectors.h"
 #include "test_cryptodev_snow3g_hash_test_vectors.h"
 #include "test_cryptodev_gcm_test_vectors.h"
@@ -112,6 +114,16 @@ setup_test_string(struct rte_mempool *mpool,
return m;
 }

+/* Get number of bytes in X bits (rounding up) */
+static uint32_t
+ceil_byte_length(uint32_t num_bits)
+{
+   if (num_bits % 8)
+   return ((num_bits >> 3) + 1);
+   else
+   return (num_bits >> 3);
+}
+
 static struct rte_crypto_op *
 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
 {
@@ -213,6 +225,20 @@ testsuite_setup(void)
}
}

+   /* Create 2 KASUMI devices if required */
+   if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
+   nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
+   if (nb_devs < 2) {
+   for (i = nb_devs; i < 2; i++) {
+   TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
+   CRYPTODEV_NAME_KASUMI_PMD, NULL),
+   "Failed to create instance %u of"
+   " pmd : %s",
+   i, CRYPTODEV_NAME_KASUMI_PMD);
+   }
+   }
+   }
+
/* Create 2 NULL devices if required */
if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
nb_devs = rte_cryptodev_count_devtype(
@@ -1093,6 +1119,146 @@ create_snow3g_hash_session(uint8_t dev_id,
TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
return 0;
 }
+
+static int
+create_kasumi_hash_session(uint8_t dev_id,
+   const uint8_t *key, const uint8_t key_len,
+   const uint8_t aad_len, const uint8_t auth_len,
+   enum rte_crypto_auth_operation op)
+{
+   uint8_t hash_key[key_len];
+
+   struct crypto_unittest_params *ut_params = _params;
+
+   memcpy(hash_key, key, key_len);
+   TEST_HEXDUMP(stdout, "key:", key, key_len);
+   /* Setup Authentication Parameters */
+   ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+   ut_params->auth_xform.next = NULL;
+
+   ut_params->auth_xform.auth.op = op;
+   ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_KASUMI_F9;
+   ut_params->auth_xform.auth.key.length = key_len;
+   ut_params->auth_xform.auth.key.data = hash_key;
+   ut_params->auth_xform.auth.digest_length = auth_len;
+   ut_params->auth_xform.auth.add_auth_data_length = aad_len;
+   ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
+   _params->auth_xform);
+   TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+   return 0;
+}
+
+static int
+create_kasumi_cipher_session(uint8_t dev_id,
+   enum rte_crypto_cipher_operation op,
+   const uint8_t *key, const uint8_t key_len)
+{
+   uint8_t cipher_key[key_len];
+
+   struct crypto_unittest_params *ut_params = _params;
+
+   memcpy(cipher_key, key, key_len);
+
+   /* Setup Cipher Parameters */
+   ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+   ut_params->cipher_xform.next = NULL;
+
+   ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_KASUMI_F8;
+   ut_params->cipher_xform.cipher.op = op;
+   ut_params->cipher_xform.cipher.key.data = cipher_key;
+   ut_params->cipher_xform.cipher.key.length = key_len;
+
+   TEST_HEXDUMP(stdout, "key:", key, key_len);
+
+   /* Create Crypto session */
+   ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
+   _params->
+   cipher_xform);
+   TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+   return 0;
+}
+
+static int

[dpdk-dev] [PATCH v3 2/3] test: add new buffer comparison macros

2016-06-20 Thread Pablo de Lara
In order to compare buffers with length and offset in bits,
new macros have been created, which use the previous compare function
to compare full bytes and then, compare first and last bytes of
each buffer separately.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test.h | 57 -
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/app/test/test.h b/app/test/test.h
index 8ddde23..81828be 100644
--- a/app/test/test.h
+++ b/app/test/test.h
@@ -65,7 +65,7 @@
}\
 } while (0)

-
+/* Compare two buffers (length in bytes) */
 #define TEST_ASSERT_BUFFERS_ARE_EQUAL(a, b, len,  msg, ...) do {   \
if (memcmp(a, b, len)) {\
printf("TestCase %s() line %d failed: "  \
@@ -75,6 +75,61 @@
}\
 } while (0)

+/* Compare two buffers with offset (length and offset in bytes) */
+#define TEST_ASSERT_BUFFERS_ARE_EQUAL_OFFSET(a, b, len, off, msg, ...) do { \
+   const uint8_t *_a_with_off = (const uint8_t *)a + off;  \
+   const uint8_t *_b_with_off = (const uint8_t *)b + off;  \
+   TEST_ASSERT_BUFFERS_ARE_EQUAL(_a_with_off, _b_with_off, len, msg);  \
+} while (0)
+
+/* Compare two buffers (length in bits) */
+#define TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(a, b, len, msg, ...) do {\
+   uint8_t _last_byte_a, _last_byte_b;   \
+   uint8_t _last_byte_mask, _last_byte_bits;  \
+   TEST_ASSERT_BUFFERS_ARE_EQUAL(a, b, (len >> 3), msg); \
+   if (len % 8) {  \
+   _last_byte_bits = len % 8;   \
+   _last_byte_mask = ~((1 << (8 - _last_byte_bits)) - 1); \
+   _last_byte_a = ((const uint8_t *)a)[len >> 3];\
+   _last_byte_b = ((const uint8_t *)b)[len >> 3];\
+   _last_byte_a &= _last_byte_mask; \
+   _last_byte_b &= _last_byte_mask;\
+   if (_last_byte_a != _last_byte_b) {  \
+   printf("TestCase %s() line %d failed: "  \
+   msg "\n", __func__, __LINE__, ##__VA_ARGS__);\
+   TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__);\
+   return TEST_FAILED;  \
+   }\
+   }\
+} while (0)
+
+/* Compare two buffers with offset (length and offset in bits) */
+#define TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(a, b, len, off, msg, ...) do 
{\
+   uint8_t _first_byte_a, _first_byte_b; \
+   uint8_t _first_byte_mask, _first_byte_bits;   \
+   uint32_t _len_without_first_byte = (off % 8) ?   \
+   len - (8 - (off % 8)) :   \
+   len;  \
+   uint32_t _off_in_bytes = (off % 8) ? (off >> 3) + 1 : (off >> 3); \
+   const uint8_t *_a_with_off = (const uint8_t *)a + _off_in_bytes;  \
+   const uint8_t *_b_with_off = (const uint8_t *)b + _off_in_bytes;  \
+   TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(_a_with_off, _b_with_off,   \
+   _len_without_first_byte, msg);\
+   if (off % 8) {\
+   _first_byte_bits = 8 - (off % 8); \
+   _first_byte_mask = (1 << _first_byte_bits) - 1;   \
+   _first_byte_a = *(_a_with_off - 1);   \
+   _first_byte_b = *(_b_with_off - 1);   \
+   _first_byte_a &= _first_byte_mask;\
+   _first_byte_b &= _first_byte_mask;\
+   if (_first_byte_a != _first_byte_b) { \
+   printf("TestCase %s() line %d failed: "   \
+   msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+   TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
+   return TEST_FAILED;   \
+   } \
+   } \
+}

[dpdk-dev] [PATCH v3 1/3] kasumi: add new KASUMI PMD

2016-06-20 Thread Pablo de Lara
Added new SW PMD which makes use of the libsso_kasumi SW library,
which provides wireless algorithms KASUMI F8 and F9
in software.

This PMD supports cipher-only, hash-only and chained operations
("cipher then hash" and "hash then cipher") of the following
algorithms:
- RTE_CRYPTO_SYM_CIPHER_KASUMI_F8
- RTE_CRYPTO_SYM_AUTH_KASUMI_F9

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 MAINTAINERS  |   5 +
 config/common_base   |   6 +
 config/defconfig_i686-native-linuxapp-gcc|   5 +
 config/defconfig_i686-native-linuxapp-icc|   5 +
 doc/guides/cryptodevs/index.rst  |   3 +-
 doc/guides/cryptodevs/kasumi.rst | 101 
 doc/guides/cryptodevs/overview.rst   |  79 +--
 doc/guides/rel_notes/release_16_07.rst   |   5 +
 drivers/crypto/Makefile  |   1 +
 drivers/crypto/kasumi/Makefile   |  64 +++
 drivers/crypto/kasumi/rte_kasumi_pmd.c   | 658 +++
 drivers/crypto/kasumi/rte_kasumi_pmd_ops.c   | 344 
 drivers/crypto/kasumi/rte_kasumi_pmd_private.h   | 106 
 drivers/crypto/kasumi/rte_pmd_kasumi_version.map |   3 +
 examples/l2fwd-crypto/main.c |  10 +-
 lib/librte_cryptodev/rte_crypto_sym.h|   6 +-
 lib/librte_cryptodev/rte_cryptodev.h |   3 +
 mk/rte.app.mk|   2 +
 scripts/test-build.sh|   4 +
 19 files changed, 1366 insertions(+), 44 deletions(-)
 create mode 100644 doc/guides/cryptodevs/kasumi.rst
 create mode 100644 drivers/crypto/kasumi/Makefile
 create mode 100644 drivers/crypto/kasumi/rte_kasumi_pmd.c
 create mode 100644 drivers/crypto/kasumi/rte_kasumi_pmd_ops.c
 create mode 100644 drivers/crypto/kasumi/rte_kasumi_pmd_private.h
 create mode 100644 drivers/crypto/kasumi/rte_pmd_kasumi_version.map

diff --git a/MAINTAINERS b/MAINTAINERS
index 3e6b70c..2e0270f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -396,6 +396,11 @@ M: Pablo de Lara 
 F: drivers/crypto/snow3g/
 F: doc/guides/cryptodevs/snow3g.rst

+KASUMI PMD
+M: Pablo de Lara 
+F: drivers/crypto/kasumi/
+F: doc/guides/cryptodevs/kasumi.rst
+
 Null Crypto PMD
 M: Declan Doherty 
 F: drivers/crypto/null/
diff --git a/config/common_base b/config/common_base
index b9ba405..fcf91c6 100644
--- a/config/common_base
+++ b/config/common_base
@@ -370,6 +370,12 @@ CONFIG_RTE_LIBRTE_PMD_SNOW3G=n
 CONFIG_RTE_LIBRTE_PMD_SNOW3G_DEBUG=n

 #
+# Compile PMD for KASUMI device
+#
+CONFIG_RTE_LIBRTE_PMD_KASUMI=n
+CONFIG_RTE_LIBRTE_PMD_KASUMI_DEBUG=n
+
+#
 # Compile PMD for NULL Crypto device
 #
 CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO=y
diff --git a/config/defconfig_i686-native-linuxapp-gcc 
b/config/defconfig_i686-native-linuxapp-gcc
index c32859f..ba07259 100644
--- a/config/defconfig_i686-native-linuxapp-gcc
+++ b/config/defconfig_i686-native-linuxapp-gcc
@@ -60,3 +60,8 @@ CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n
 # AES-NI GCM PMD is not supported on 32-bit
 #
 CONFIG_RTE_LIBRTE_PMD_AESNI_GCM=n
+
+#
+# KASUMI PMD is not supported on 32-bit
+#
+CONFIG_RTE_LIBRTE_PMD_KASUMI=n
diff --git a/config/defconfig_i686-native-linuxapp-icc 
b/config/defconfig_i686-native-linuxapp-icc
index cde9d96..850e536 100644
--- a/config/defconfig_i686-native-linuxapp-icc
+++ b/config/defconfig_i686-native-linuxapp-icc
@@ -60,3 +60,8 @@ CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n
 # AES-NI GCM PMD is not supported on 32-bit
 #
 CONFIG_RTE_LIBRTE_PMD_AESNI_GCM=n
+
+#
+# KASUMI PMD is not supported on 32-bit
+#
+CONFIG_RTE_LIBRTE_PMD_KASUMI=n
diff --git a/doc/guides/cryptodevs/index.rst b/doc/guides/cryptodevs/index.rst
index a3f11f3..9616de1 100644
--- a/doc/guides/cryptodevs/index.rst
+++ b/doc/guides/cryptodevs/index.rst
@@ -38,6 +38,7 @@ Crypto Device Drivers
 overview
 aesni_mb
 aesni_gcm
+kasumi
 null
 snow3g
-qat
\ No newline at end of file
+qat
diff --git a/doc/guides/cryptodevs/kasumi.rst b/doc/guides/cryptodevs/kasumi.rst
new file mode 100644
index 000..d6b3a97
--- /dev/null
+++ b/doc/guides/cryptodevs/kasumi.rst
@@ -0,0 +1,101 @@
+..  BSD LICENSE
+Copyright(c) 2016 Intel Corporation. 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 prio

[dpdk-dev] [PATCH v3 0/3] Add new KASUMI SW PMD

2016-06-20 Thread Pablo de Lara
Added new SW PMD which makes use of the libsso SW library,
which provides wireless algorithms KASUMI F8 and F9
in software.

This PMD supports cipher-only, hash-only and chained operations
("cipher then hash" and "hash then cipher") of the following
algorithms:
- RTE_CRYPTO_SYM_CIPHER_KASUMI_F8
- RTE_CRYPTO_SYM_AUTH_KASUMI_F9

The patchset also adds new macros to compare buffers at bit-level,
since the PMD supports bit-level hash/cipher operations,
and unit tests.

The patchset should be merged after the following patches/patchsets,
as they are making changes in some of the files of this patchset:
- rework crypto AES unit test
  ("http://dpdk.org/ml/archives/dev/2016-June/041572.html;)
- Refactor of debug information on cryptodev tests
  ("http://dpdk.org/ml/archives/dev/2016-June/041623.html;)
- doc: fix wrong supported feature table
  ("http://dpdk.org/dev/patchwork/patch/13413/;)

Changes in v2:
- Fixed key length
- Refactored enqueue burst function to avoid duplication
- Added CPU flags in crypto feature flags
- Added extra unit tets
- Added documentation
- Merged last patch in v1 into the first patch
- Added new driver in MAINTAINERS

Changes in v3:
- Updated documentation, as the library has been released,
  with detailed instructions on how to get the libsso_kasumi library.

Pablo de Lara (3):
  kasumi: add new KASUMI PMD
  test: add new buffer comparison macros
  test: add unit tests for KASUMI PMD

 MAINTAINERS|   5 +
 app/test/test.h|  57 +-
 app/test/test_cryptodev.c  | 995 +++--
 app/test/test_cryptodev.h  |   1 +
 app/test/test_cryptodev_kasumi_hash_test_vectors.h | 260 ++
 app/test/test_cryptodev_kasumi_test_vectors.h  | 308 +++
 config/common_base |   6 +
 config/defconfig_i686-native-linuxapp-gcc  |   5 +
 config/defconfig_i686-native-linuxapp-icc  |   5 +
 doc/guides/cryptodevs/index.rst|   3 +-
 doc/guides/cryptodevs/kasumi.rst   | 101 +++
 doc/guides/cryptodevs/overview.rst |  79 +-
 doc/guides/rel_notes/release_16_07.rst |   5 +
 drivers/crypto/Makefile|   1 +
 drivers/crypto/kasumi/Makefile |  64 ++
 drivers/crypto/kasumi/rte_kasumi_pmd.c | 658 ++
 drivers/crypto/kasumi/rte_kasumi_pmd_ops.c | 344 +++
 drivers/crypto/kasumi/rte_kasumi_pmd_private.h | 106 +++
 drivers/crypto/kasumi/rte_pmd_kasumi_version.map   |   3 +
 examples/l2fwd-crypto/main.c   |  10 +-
 lib/librte_cryptodev/rte_crypto_sym.h  |   6 +-
 lib/librte_cryptodev/rte_cryptodev.h   |   3 +
 mk/rte.app.mk  |   2 +
 scripts/test-build.sh  |   4 +
 24 files changed, 2897 insertions(+), 134 deletions(-)
 create mode 100644 app/test/test_cryptodev_kasumi_hash_test_vectors.h
 create mode 100644 app/test/test_cryptodev_kasumi_test_vectors.h
 create mode 100644 doc/guides/cryptodevs/kasumi.rst
 create mode 100644 drivers/crypto/kasumi/Makefile
 create mode 100644 drivers/crypto/kasumi/rte_kasumi_pmd.c
 create mode 100644 drivers/crypto/kasumi/rte_kasumi_pmd_ops.c
 create mode 100644 drivers/crypto/kasumi/rte_kasumi_pmd_private.h
 create mode 100644 drivers/crypto/kasumi/rte_pmd_kasumi_version.map

-- 
2.5.0



[dpdk-dev] [PATCH v3 11/11] test: refactor snow3g/kasumi tests

2016-06-20 Thread Pablo de Lara
SNOW3G and KASUMI unit tests are very similar and
they were using duplicated code, so this commit
refactor and remove some of the duplicated functions.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c | 440 --
 1 file changed, 150 insertions(+), 290 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 7a8fda0..1a67ffb 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1091,10 +1091,11 @@ test_AES_qat_all(void)

 /* * Snow3G Tests * */
 static int
-create_snow3g_hash_session(uint8_t dev_id,
+create_snow3g_kasumi_hash_session(uint8_t dev_id,
const uint8_t *key, const uint8_t key_len,
const uint8_t aad_len, const uint8_t auth_len,
-   enum rte_crypto_auth_operation op)
+   enum rte_crypto_auth_operation op,
+   enum rte_crypto_auth_algorithm algo)
 {
uint8_t hash_key[key_len];

@@ -1109,7 +1110,7 @@ create_snow3g_hash_session(uint8_t dev_id,
ut_params->auth_xform.next = NULL;

ut_params->auth_xform.auth.op = op;
-   ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
+   ut_params->auth_xform.auth.algo = algo;
ut_params->auth_xform.auth.key.length = key_len;
ut_params->auth_xform.auth.key.data = hash_key;
ut_params->auth_xform.auth.digest_length = auth_len;
@@ -1121,36 +1122,9 @@ create_snow3g_hash_session(uint8_t dev_id,
 }

 static int
-create_kasumi_hash_session(uint8_t dev_id,
-   const uint8_t *key, const uint8_t key_len,
-   const uint8_t aad_len, const uint8_t auth_len,
-   enum rte_crypto_auth_operation op)
-{
-   uint8_t hash_key[key_len];
-
-   struct crypto_unittest_params *ut_params = _params;
-
-   memcpy(hash_key, key, key_len);
-   TEST_HEXDUMP(stdout, "key:", key, key_len);
-   /* Setup Authentication Parameters */
-   ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
-   ut_params->auth_xform.next = NULL;
-
-   ut_params->auth_xform.auth.op = op;
-   ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_KASUMI_F9;
-   ut_params->auth_xform.auth.key.length = key_len;
-   ut_params->auth_xform.auth.key.data = hash_key;
-   ut_params->auth_xform.auth.digest_length = auth_len;
-   ut_params->auth_xform.auth.add_auth_data_length = aad_len;
-   ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
-   _params->auth_xform);
-   TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
-   return 0;
-}
-
-static int
-create_kasumi_cipher_session(uint8_t dev_id,
+create_snow3g_kasumi_cipher_session(uint8_t dev_id,
enum rte_crypto_cipher_operation op,
+   enum rte_crypto_cipher_algorithm algo,
const uint8_t *key, const uint8_t key_len)
 {
uint8_t cipher_key[key_len];
@@ -1163,7 +1137,7 @@ create_kasumi_cipher_session(uint8_t dev_id,
ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
ut_params->cipher_xform.next = NULL;

-   ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_KASUMI_F8;
+   ut_params->cipher_xform.cipher.algo = algo;
ut_params->cipher_xform.cipher.op = op;
ut_params->cipher_xform.cipher.key.data = cipher_key;
ut_params->cipher_xform.cipher.key.length = key_len;
@@ -1179,9 +1153,10 @@ create_kasumi_cipher_session(uint8_t dev_id,
 }

 static int
-create_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
+create_snow3g_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
const unsigned cipher_len,
-   const unsigned cipher_offset)
+   const unsigned cipher_offset,
+   enum rte_crypto_cipher_algorithm algo)
 {
struct crypto_testsuite_params *ts_params = _params;
struct crypto_unittest_params *ut_params = _params;
@@ -1202,7 +1177,11 @@ create_kasumi_cipher_operation(const uint8_t *iv, const 
unsigned iv_len,
sym_op->m_src = ut_params->ibuf;

/* iv */
-   iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
+   if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
+   iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
+   else
+   iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
+
sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
, iv_pad_len);

@@ -1219,9 +1198,10 @@ create_kasumi_cipher_operation(const uint8_t *iv, const 
unsigned iv_len,
 }

 static int
-create_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
+create_snow3g_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t 
iv_len,
const unsigned cipher_len,
-   const

[dpdk-dev] [PATCH v3 10/11] test: add Snow3G UEA2 test with offset

2016-06-20 Thread Pablo de Lara
With the new libsso library, buffers can be encrypted/decrypted,
providing an offset in bits, so an extra unit test has been
added to cover this case.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c | 121 ++
 1 file changed, 121 insertions(+)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 546ae92..7a8fda0 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -2553,6 +2553,118 @@ test_snow3g_encryption_oop(const struct 
snow3g_test_data *tdata)
return 0;
 }

+/* Shift right a buffer by "offset" bits, "offset" < 8 */
+static void
+buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
+{
+   uint8_t curr_byte, prev_byte;
+   uint32_t length_in_bytes = ceil_byte_length(length + offset);
+   uint8_t lower_byte_mask = (1 << offset) - 1;
+   unsigned i;
+
+   prev_byte = buffer[0];
+   buffer[0] >>= offset;
+
+   for (i = 1; i < length_in_bytes; i++) {
+   curr_byte = buffer[i];
+   buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
+   (curr_byte >> offset);
+   prev_byte = curr_byte;
+   }
+}
+
+static int
+test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
+{
+   struct crypto_testsuite_params *ts_params = _params;
+   struct crypto_unittest_params *ut_params = _params;
+   uint8_t *plaintext, *ciphertext;
+   int retval;
+   uint32_t plaintext_len;
+   uint32_t plaintext_pad_len;
+   uint8_t extra_offset = 4;
+   uint8_t *expected_ciphertext_shifted;
+
+   /* Create SNOW3G session */
+   retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
+   RTE_CRYPTO_CIPHER_OP_ENCRYPT,
+   tdata->key.data, tdata->key.len);
+   if (retval < 0)
+   return retval;
+
+   ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+   ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+   TEST_ASSERT_NOT_NULL(ut_params->ibuf,
+   "Failed to allocate input buffer in mempool");
+   TEST_ASSERT_NOT_NULL(ut_params->obuf,
+   "Failed to allocate output buffer in mempool");
+
+   /* Clear mbuf payload */
+   memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+  rte_pktmbuf_tailroom(ut_params->ibuf));
+
+   plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
+   /*
+* Append data which is padded to a
+* multiple of the algorithms block size
+*/
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
+
+   plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
+   plaintext_pad_len);
+
+   rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
+
+   memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
+   buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
+
+#ifdef RTE_APP_TEST_DEBUG
+   rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
+#endif
+   /* Create SNOW3G operation */
+   retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
+   tdata->iv.len,
+   tdata->validCipherLenInBits.len,
+   tdata->validCipherOffsetLenInBits.len +
+   extra_offset);
+   if (retval < 0)
+   return retval;
+
+   ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+   ut_params->op);
+   TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
+
+   ut_params->obuf = ut_params->op->sym->m_dst;
+   if (ut_params->obuf)
+   ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
+   + tdata->iv.len;
+   else
+   ciphertext = plaintext;
+
+#ifdef RTE_APP_TEST_DEBUG
+   rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
+#endif
+
+   expected_ciphertext_shifted = rte_malloc(NULL,
+   ceil_byte_length(plaintext_len + extra_offset), 0);
+
+   TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
+   "failed to reserve memory for ciphertext shifted\n");
+
+   memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
+   ceil_byte_length(tdata->ciphertext.len));
+   buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
+

[dpdk-dev] [PATCH v3 09/11] test: add bit-level Snow3G UIA2 tests

2016-06-20 Thread Pablo de Lara
Snow3G PMD supports now buffers that are non byte multiple,
so tests to cover this case have been added.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c  |  50 ++
 app/test/test_cryptodev_snow3g_hash_test_vectors.h | 107 +
 2 files changed, 157 insertions(+)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 803f1f6..546ae92 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -2048,6 +2048,24 @@ test_snow3g_hash_generate_test_case_3(void)
 }

 static int
+test_snow3g_hash_generate_test_case_4(void)
+{
+   return test_snow3g_authentication(_hash_test_case_4);
+}
+
+static int
+test_snow3g_hash_generate_test_case_5(void)
+{
+   return test_snow3g_authentication(_hash_test_case_5);
+}
+
+static int
+test_snow3g_hash_generate_test_case_6(void)
+{
+   return test_snow3g_authentication(_hash_test_case_6);
+}
+
+static int
 test_snow3g_hash_verify_test_case_1(void)
 {
return test_snow3g_authentication_verify(_hash_test_case_1);
@@ -2067,6 +2085,24 @@ test_snow3g_hash_verify_test_case_3(void)
 }

 static int
+test_snow3g_hash_verify_test_case_4(void)
+{
+   return test_snow3g_authentication_verify(_hash_test_case_4);
+}
+
+static int
+test_snow3g_hash_verify_test_case_5(void)
+{
+   return test_snow3g_authentication_verify(_hash_test_case_5);
+}
+
+static int
+test_snow3g_hash_verify_test_case_6(void)
+{
+   return test_snow3g_authentication_verify(_hash_test_case_6);
+}
+
+static int
 test_kasumi_hash_generate_test_case_1(void)
 {
return test_kasumi_authentication(_hash_test_case_1);
@@ -4079,12 +4115,26 @@ static struct unit_test_suite 
cryptodev_sw_snow3g_testsuite  = {
test_snow3g_hash_generate_test_case_2),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_hash_generate_test_case_3),
+   /* Tests with buffers which length is not byte-aligned */
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_generate_test_case_4),
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_generate_test_case_5),
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_generate_test_case_6),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_hash_verify_test_case_1),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_hash_verify_test_case_2),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_hash_verify_test_case_3),
+   /* Tests with buffers which length is not byte-aligned */
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_verify_test_case_4),
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_verify_test_case_5),
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_hash_verify_test_case_6),
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_authenticated_encryption_test_case_1),
TEST_CASE_ST(ut_setup, ut_teardown,
diff --git a/app/test/test_cryptodev_snow3g_hash_test_vectors.h 
b/app/test/test_cryptodev_snow3g_hash_test_vectors.h
index fe4906b..a8a47db 100644
--- a/app/test/test_cryptodev_snow3g_hash_test_vectors.h
+++ b/app/test/test_cryptodev_snow3g_hash_test_vectors.h
@@ -438,4 +438,111 @@ struct snow3g_hash_test_data snow3g_hash_test_case_3 = {
}
 };

+struct snow3g_hash_test_data snow3g_hash_test_case_4 = {
+   .key = {
+   .data = {
+   0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00,
+   0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48
+   },
+   .len = 16
+   },
+   .aad = {
+   .data = {
+   0x38, 0xA6, 0xF0, 0x56, 0x05, 0xD2, 0xEC, 0x49,
+   0x38, 0xA6, 0xF0, 0x56, 0x05, 0xD2, 0xEC, 0x49,
+   },
+   .len = 16
+   },
+   .plaintext = {
+   .data = {
+   0x6B, 0x22, 0x77, 0x37, 0x29, 0x6F, 0x39, 0x3C,
+   0x80, 0x79, 0x35, 0x3E, 0xDC, 0x87, 0xE2, 0xE8,
+   0x05, 0xD2, 0xEC, 0x49, 0xA4, 0xF2, 0xD8, 0xE0
+   },
+   .len = 189
+   },
+   .validAuthLenInBits = {
+   .len = 189
+   },
+   .validAuthOffsetLenInBits = {
+   .len = 128
+   },
+   .digest = {
+   .data = {0x2B, 0xCE, 0x18, 0x20},
+   .len  = 4
+   }
+};
+
+struct snow3g_hash_test_data snow3g_hash_test_case_5 = {
+   .key = {
+   .data = {
+   0xD4, 0x2F, 0x68, 0x24, 0x28, 0x20, 0x1C, 0xAF,
+   0xCD, 0x9F

[dpdk-dev] [PATCH v3 08/11] test: add out-of-place crypto op tests for Snow3G PMD

2016-06-20 Thread Pablo de Lara
Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 7dc5648..803f1f6 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -4057,6 +4057,11 @@ static struct unit_test_suite 
cryptodev_sw_snow3g_testsuite  = {
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_encryption_test_case_5),

+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_encryption_test_case_1_oop),
+   TEST_CASE_ST(ut_setup, ut_teardown,
+   test_snow3g_decryption_test_case_1_oop),
+
/** Snow3G decrypt only (UEA2) */
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_decryption_test_case_1),
-- 
2.5.0



[dpdk-dev] [PATCH v3 07/11] test: fix buffer lengths for snow3G tests

2016-06-20 Thread Pablo de Lara
No padding was added in the input buffers for snow3G tests,
due to a wrong calculation of the length (should be multiple
of the block size). This fix takes into account the case
where the length is not byte multiple.

Fixes: 8bdf665fe6c0 ("app/test: add SNOW 3G")

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c | 139 ++
 1 file changed, 66 insertions(+), 73 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 3ff74cd..7dc5648 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1801,6 +1801,7 @@ test_snow3g_authentication(const struct 
snow3g_hash_test_data *tdata)

int retval;
unsigned plaintext_pad_len;
+   unsigned plaintext_len;
uint8_t *plaintext;

/* Create SNOW3G session */
@@ -1817,12 +1818,13 @@ test_snow3g_authentication(const struct 
snow3g_hash_test_data *tdata)
memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
rte_pktmbuf_tailroom(ut_params->ibuf));

+   plaintext_len = ceil_byte_length(tdata->plaintext.len);
/* Append data which is padded to a multiple of */
/* the algorithms block size */
-   plaintext_pad_len = tdata->plaintext.len >> 3;
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
plaintext_pad_len);
-   memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
+   memcpy(plaintext, tdata->plaintext.data, plaintext_len);

/* Create SNOW3G opertaion */
retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
@@ -1858,6 +1860,7 @@ test_snow3g_authentication_verify(const struct 
snow3g_hash_test_data *tdata)

int retval;
unsigned plaintext_pad_len;
+   unsigned plaintext_len;
uint8_t *plaintext;

/* Create SNOW3G session */
@@ -1873,12 +1876,13 @@ test_snow3g_authentication_verify(const struct 
snow3g_hash_test_data *tdata)
memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
rte_pktmbuf_tailroom(ut_params->ibuf));

-   /* Append data which is padded to a multiple */
-   /* of the algorithms block size */
-   plaintext_pad_len = tdata->plaintext.len >> 3;
+   plaintext_len = ceil_byte_length(tdata->plaintext.len);
+   /* Append data which is padded to a multiple of */
+   /* the algorithms block size */
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
-   plaintext_pad_len);
-   memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
+   plaintext_pad_len);
+   memcpy(plaintext, tdata->plaintext.data, plaintext_len);

/* Create SNOW3G operation */
retval = create_snow3g_hash_operation(tdata->digest.data,
@@ -2386,7 +2390,8 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)

int retval;
uint8_t *plaintext, *ciphertext;
-   uint8_t plaintext_pad_len;
+   unsigned plaintext_pad_len;
+   unsigned plaintext_len;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2401,16 +2406,13 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)
memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
   rte_pktmbuf_tailroom(ut_params->ibuf));

-   /*
-* Append data which is padded to a
-* multiple of the algorithms block size
-*/
-   /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
-   plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
-
-   plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
-   plaintext_pad_len);
-   memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
+   plaintext_len = ceil_byte_length(tdata->plaintext.len);
+   /* Append data which is padded to a multiple of */
+   /* the algorithms block size */
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
+   plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
+   plaintext_pad_len);
+   memcpy(plaintext, tdata->plaintext.data, plaintext_len);

TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);

@@ -2452,7 +2454,8 @@ test_snow3g_encryption_oop(const struct snow3g_test_data 
*tdata)
uint8_t *plaintext, *ciphertext;

int retval;
-   uint8_t plaintext_pad_len;
+   unsigned plaintext_pad_len;
+   unsigned plaintext_len;

/* Create SNOW3G session */
retval = crea

[dpdk-dev] [PATCH v3 06/11] test: use new bit-level memcmp macro

2016-06-20 Thread Pablo de Lara
Instead of modifying the content of the buffers, to compare them
at bit-level, use the new macro TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT,
which does not make any modifications in the buffers.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 app/test/test_cryptodev.c | 68 +--
 1 file changed, 12 insertions(+), 56 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 3199d6e..3ff74cd 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -2387,8 +2387,6 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)
int retval;
uint8_t *plaintext, *ciphertext;
uint8_t plaintext_pad_len;
-   uint8_t lastByteValidBits = 8;
-   uint8_t lastByteMask = 0xFF;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2434,19 +2432,13 @@ test_snow3g_encryption(const struct snow3g_test_data 
*tdata)
else
ciphertext = plaintext;

-   lastByteValidBits = (tdata->validDataLenInBits.len % 8);
-   if (lastByteValidBits == 0)
-   lastByteValidBits = 8;
-   lastByteMask = lastByteMask << (8 - lastByteValidBits);
-   (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
-
TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);

/* Validate obuf */
-   TEST_ASSERT_BUFFERS_ARE_EQUAL(
+   TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
ciphertext,
tdata->ciphertext.data,
-   tdata->ciphertext.len >> 3,
+   tdata->validDataLenInBits.len,
"Snow3G Ciphertext data not as expected");
return 0;
 }
@@ -2461,8 +2453,6 @@ test_snow3g_encryption_oop(const struct snow3g_test_data 
*tdata)

int retval;
uint8_t plaintext_pad_len;
-   uint8_t lastByteValidBits = 8;
-   uint8_t lastByteMask = 0xFF;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2519,19 +2509,13 @@ test_snow3g_encryption_oop(const struct 
snow3g_test_data *tdata)
else
ciphertext = plaintext;

-   lastByteValidBits = (tdata->validDataLenInBits.len % 8);
-   if (lastByteValidBits == 0)
-   lastByteValidBits = 8;
-   lastByteMask = lastByteMask << (8 - lastByteValidBits);
-   (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
-
TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);

/* Validate obuf */
-   TEST_ASSERT_BUFFERS_ARE_EQUAL(
+   TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
ciphertext,
tdata->ciphertext.data,
-   tdata->ciphertext.len >> 3,
+   tdata->validDataLenInBits.len,
"Snow3G Ciphertext data not as expected");
return 0;
 }
@@ -2546,8 +2530,6 @@ static int test_snow3g_decryption(const struct 
snow3g_test_data *tdata)

uint8_t *plaintext, *ciphertext;
uint8_t ciphertext_pad_len;
-   uint8_t lastByteValidBits = 8;
-   uint8_t lastByteMask = 0xFF;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2590,18 +2572,13 @@ static int test_snow3g_decryption(const struct 
snow3g_test_data *tdata)
+ tdata->iv.len;
else
plaintext = ciphertext;
-   lastByteValidBits = (tdata->validDataLenInBits.len  % 8);
-   if (lastByteValidBits == 0)
-   lastByteValidBits = 8;
-   lastByteMask = lastByteMask << (8 - lastByteValidBits);
-   (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;

TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);

/* Validate obuf */
-   TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
+   TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
tdata->plaintext.data,
-   tdata->plaintext.len >> 3,
+   tdata->validDataLenInBits.len,
"Snow3G Plaintext data not as expected");
return 0;
 }
@@ -2615,8 +2592,6 @@ static int test_snow3g_decryption_oop(const struct 
snow3g_test_data *tdata)

uint8_t *plaintext, *ciphertext;
uint8_t ciphertext_pad_len;
-   uint8_t lastByteValidBits = 8;
-   uint8_t lastByteMask = 0xFF;

/* Create SNOW3G session */
retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2673,18 +2648,13 @@ static int test_snow3g_decryption_oop(const struct 
snow3g_test_data *tdata)
+ tdata->iv.len;
else
   

[dpdk-dev] [PATCH v3 05/11] snow3g: add missing feature flags

2016-06-20 Thread Pablo de Lara
The underlying libsso library supports SSE4.1 instruction set,
so feature flags of the crypto device must be updated
to reflect this.

Signed-off-by: Pablo de Lara 
Acked-by: Jain, Deepak K 
---
 drivers/crypto/snow3g/rte_snow3g_pmd.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd.c 
b/drivers/crypto/snow3g/rte_snow3g_pmd.c
index b90d27d..6d59de7 100644
--- a/drivers/crypto/snow3g/rte_snow3g_pmd.c
+++ b/drivers/crypto/snow3g/rte_snow3g_pmd.c
@@ -555,6 +555,16 @@ cryptodev_snow3g_create(const char *name,
struct rte_cryptodev *dev;
char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
struct snow3g_private *internals;
+   uint64_t cpu_flags = 0;
+
+   /* Check CPU for supported vector instruction set */
+   if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_1))
+   cpu_flags |= RTE_CRYPTODEV_FF_CPU_SSE;
+   else {
+   SNOW3G_LOG_ERR("Vector instructions are not supported by CPU");
+   return -EFAULT;
+   }
+

/* Create a unique device name. */
if (create_unique_device_name(crypto_dev_name,
@@ -578,7 +588,8 @@ cryptodev_snow3g_create(const char *name,
dev->enqueue_burst = snow3g_pmd_enqueue_burst;

dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
-   RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING;
+   RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
+   cpu_flags;

internals = dev->data->dev_private;

-- 
2.5.0



  1   2   3   4   5   6   >