[dpdk-dev] [PATCH v5 4/9] null: virtual dynamic rss configuration

2015-10-14 Thread Tetsuya Mukawa
On 2015/09/30 23:05, Tomasz Kulasek wrote:
> This implementation allows to set and read RSS configuration for null
> device, and is used to validate right values propagation over the slaves,
> in test units for dynamic RSS configuration for bonding.
>
> v5 changes:
>  - replaced memcpy with rte_memcpy
>
> Signed-off-by: Tomasz Kulasek 
> ---
>  drivers/net/null/rte_eth_null.c |  116 
> +++
>  1 file changed, 116 insertions(+)
Acked-by: Tetsuya Mukawa 



[dpdk-dev] [PATCH v5 4/9] null: virtual dynamic rss configuration

2015-09-30 Thread Tomasz Kulasek
This implementation allows to set and read RSS configuration for null
device, and is used to validate right values propagation over the slaves,
in test units for dynamic RSS configuration for bonding.

v5 changes:
 - replaced memcpy with rte_memcpy

Signed-off-by: Tomasz Kulasek 
---
 drivers/net/null/rte_eth_null.c |  116 +++
 1 file changed, 116 insertions(+)

diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index bf81b1b..b01f647 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -37,6 +37,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 

 #define ETH_NULL_PACKET_SIZE_ARG   "size"
 #define ETH_NULL_PACKET_COPY_ARG   "copy"
@@ -73,6 +75,17 @@ struct pmd_internals {

struct null_queue rx_null_queues[RTE_MAX_QUEUES_PER_PORT];
struct null_queue tx_null_queues[RTE_MAX_QUEUES_PER_PORT];
+
+   /** Bit mask of RSS offloads, the bit offset also means flow type */
+   uint64_t flow_type_rss_offloads;
+
+   rte_spinlock_t rss_lock;
+
+   uint16_t reta_size;
+   struct rte_eth_rss_reta_entry64 reta_conf[ETH_RSS_RETA_SIZE_128 /
+   RTE_RETA_GROUP_SIZE];
+
+   uint8_t rss_key[40];/**< 40-byte hash key. */
 };


@@ -293,6 +306,8 @@ eth_dev_info(struct rte_eth_dev *dev,
dev_info->max_tx_queues = RTE_DIM(internals->tx_null_queues);
dev_info->min_rx_bufsize = 0;
dev_info->pci_dev = NULL;
+   dev_info->reta_size = internals->reta_size;
+   dev_info->flow_type_rss_offloads = internals->flow_type_rss_offloads;
 }

 static void
@@ -373,6 +388,91 @@ static int
 eth_link_update(struct rte_eth_dev *dev __rte_unused,
int wait_to_complete __rte_unused) { return 0; }

+static int
+eth_rss_reta_update(struct rte_eth_dev *dev,
+   struct rte_eth_rss_reta_entry64 *reta_conf, uint16_t reta_size)
+{
+   int i, j;
+   struct pmd_internals *internal = dev->data->dev_private;
+
+   if (reta_size != internal->reta_size)
+   return -EINVAL;
+
+   rte_spinlock_lock(>rss_lock);
+
+   /* Copy RETA table */
+   for (i = 0; i < (internal->reta_size / RTE_RETA_GROUP_SIZE); i++) {
+   internal->reta_conf[i].mask = reta_conf[i].mask;
+   for (j = 0; j < RTE_RETA_GROUP_SIZE; j++)
+   if ((reta_conf[i].mask >> j) & 0x01)
+   internal->reta_conf[i].reta[j] = 
reta_conf[i].reta[j];
+   }
+
+   rte_spinlock_unlock(>rss_lock);
+
+   return 0;
+}
+
+static int
+eth_rss_reta_query(struct rte_eth_dev *dev,
+   struct rte_eth_rss_reta_entry64 *reta_conf, uint16_t reta_size)
+{
+   int i, j;
+   struct pmd_internals *internal = dev->data->dev_private;
+
+   if (reta_size != internal->reta_size)
+   return -EINVAL;
+
+   rte_spinlock_lock(>rss_lock);
+
+   /* Copy RETA table */
+   for (i = 0; i < (internal->reta_size / RTE_RETA_GROUP_SIZE); i++) {
+   for (j = 0; j < RTE_RETA_GROUP_SIZE; j++)
+   if ((reta_conf[i].mask >> j) & 0x01)
+   reta_conf[i].reta[j] = 
internal->reta_conf[i].reta[j];
+   }
+
+   rte_spinlock_unlock(>rss_lock);
+
+   return 0;
+}
+
+static int
+eth_rss_hash_update(struct rte_eth_dev *dev, struct rte_eth_rss_conf *rss_conf)
+{
+   struct pmd_internals *internal = dev->data->dev_private;
+
+   rte_spinlock_lock(>rss_lock);
+
+   if ((rss_conf->rss_hf & internal->flow_type_rss_offloads) != 0)
+   dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf =
+   rss_conf->rss_hf & 
internal->flow_type_rss_offloads;
+
+   if (rss_conf->rss_key)
+   rte_memcpy(internal->rss_key, rss_conf->rss_key, 40);
+
+   rte_spinlock_unlock(>rss_lock);
+
+   return 0;
+}
+
+static int
+eth_rss_hash_conf_get(struct rte_eth_dev *dev,
+   struct rte_eth_rss_conf *rss_conf)
+{
+   struct pmd_internals *internal = dev->data->dev_private;
+
+   rte_spinlock_lock(>rss_lock);
+
+   rss_conf->rss_hf = dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
+   if (rss_conf->rss_key)
+   rte_memcpy(rss_conf->rss_key, internal->rss_key, 40);
+
+   rte_spinlock_unlock(>rss_lock);
+
+   return 0;
+}
+
 static const struct eth_dev_ops ops = {
.dev_start = eth_dev_start,
.dev_stop = eth_dev_stop,
@@ -385,6 +485,10 @@ static const struct eth_dev_ops ops = {
.link_update = eth_link_update,
.stats_get = eth_stats_get,
.stats_reset = eth_stats_reset,
+   .reta_update = eth_rss_reta_update,
+   .reta_query = eth_rss_reta_query,
+   .rss_hash_update = eth_rss_hash_update,
+   .rss_hash_conf_get = eth_rss_hash_conf_get
 };

 static int
@@ -400,6 +504,13 @@ eth_dev_null_create(const char *name,
struct pmd_internals