[dpdk-dev] [PATCH v2 5/6] DPDK-ENIC PMD interface

2014-11-21 Thread Sujith Sankar
Signed-off-by: Sujith Sankar 
---
 lib/librte_pmd_enic/enic_etherdev.c | 620 
 1 file changed, 620 insertions(+)
 create mode 100644 lib/librte_pmd_enic/enic_etherdev.c

diff --git a/lib/librte_pmd_enic/enic_etherdev.c 
b/lib/librte_pmd_enic/enic_etherdev.c
new file mode 100644
index 000..90003f5
--- /dev/null
+++ b/lib/librte_pmd_enic/enic_etherdev.c
@@ -0,0 +1,620 @@
+/*
+ * Copyright 2008-2014 Cisco Systems, Inc.  All rights reserved.
+ * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
+ *
+ * Copyright (c) 2014, Cisco Systems, Inc. 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 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 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ident "$Id$"
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "vnic_intr.h"
+#include "vnic_cq.h"
+#include "vnic_wq.h"
+#include "vnic_rq.h"
+#include "vnic_enet.h"
+#include "enic.h"
+
+#ifdef RTE_LIBRTE_ENIC_PMD_DEBUG_TRACE
+#define ENICPMD_FUNC_TRACE()\
+   do { \
+   dev_trace(enic, "Entering %s\n", __func__);   \
+   } while (0)
+#else
+#define ENICPMD_FUNC_TRACE()
+#endif
+
+
+/*
+ * The set of PCI devices this driver supports
+ */
+static struct rte_pci_id pci_id_enic_map[] = {
+#define RTE_PCI_DEV_ID_DECL_ENIC(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
+#ifndef PCI_VENDOR_ID_CISCO
+#define PCI_VENDOR_ID_CISCO0x1137
+#endif
+#include "rte_pci_dev_ids.h"
+RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET)
+RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_VF)
+{.vendor_id = 0, /* Sentinal */},
+};
+
+int enicpmd_fdir_remove_perfect_filter(struct rte_eth_dev *eth_dev,
+   struct rte_fdir_filter *fdir_filter,
+   uint16_t soft_id)
+{
+   struct enic *enic = pmd_priv(eth_dev);
+
+   ENICPMD_FUNC_TRACE();
+   return enic_fdir_del_fltr(enic, fdir_filter);
+}
+
+int enicpmd_fdir_add_perfect_filter(struct rte_eth_dev *eth_dev,
+   struct rte_fdir_filter *fdir_filter, uint16_t soft_id,
+   uint8_t queue, uint8_t drop)
+{
+   struct enic *enic = pmd_priv(eth_dev);
+
+   ENICPMD_FUNC_TRACE();
+   return enic_fdir_add_fltr(enic, fdir_filter, (uint16_t)queue, drop);
+}
+
+void enicpmd_fdir_info_get(struct rte_eth_dev *eth_dev,
+   struct rte_eth_fdir *fdir)
+{
+   struct enic *enic = pmd_priv(eth_dev);
+
+   ENICPMD_FUNC_TRACE();
+   *fdir = enic->fdir.stats;
+}
+
+void enicpmd_dev_tx_queue_release(void *txq)
+{
+   ENICPMD_FUNC_TRACE();
+   enic_free_wq(txq);
+}
+
+static int enicpmd_dev_setup_intr(struct enic *enic)
+{
+   int ret;
+   int index;
+
+   ENICPMD_FUNC_TRACE();
+
+   /* Are we done with the init of all the queues? */
+   for (index = 0; index < enic->cq_count; index++) {
+   if (!enic->cq[index].ctrl)
+   break;
+   }
+
+   if (enic->cq_count != index)
+   return 0;
+
+   ret = enic_alloc_intr_resources(enic);
+   if (ret) {
+   dev_err(enic, "alloc intr failed\n");
+   return ret;
+   }
+   enic_init_vnic_resources(enic);
+
+   ret = enic_setup_finish(enic);
+   if (ret)
+   dev_err(enic, "setup could not be finished\n");
+
+   return ret;
+}
+
+int enicpmd_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
+   uint16_t queue_idx,
+   uint16_t nb_desc,
+   unsigned int socket_id,
+   const struct rte_eth_txconf *tx_conf)
+{
+   int ret;
+   struct enic *enic = pmd_priv(eth_dev);
+
+   ENICPMD_FUNC_TRACE();
+   eth_dev->data->tx_queues[queue_idx] = (void *)&enic->wq[queue_idx];
+
+   

[dpdk-dev] [PATCH v2 5/6] DPDK-ENIC PMD interface

2014-11-21 Thread Sujith Sankar (ssujith)
Thanks for the comments, Neil.  I shall include those in v3.

Regards,
-Sujith

On 21/11/14 6:54 pm, "Neil Horman"  wrote:

>On Fri, Nov 21, 2014 at 10:03:02PM +0530, Sujith Sankar wrote:
>> Signed-off-by: Sujith Sankar 
>> ---
>>  lib/librte_pmd_enic/enic_etherdev.c | 620
>>
>>  1 file changed, 620 insertions(+)
>>  create mode 100644 lib/librte_pmd_enic/enic_etherdev.c
>> 
>> diff --git a/lib/librte_pmd_enic/enic_etherdev.c
>>b/lib/librte_pmd_enic/enic_etherdev.c
>> new file mode 100644
>> index 000..90003f5
>> --- /dev/null
>> +++ b/lib/librte_pmd_enic/enic_etherdev.c
>> @@ -0,0 +1,620 @@
>> +/*
>> + * Copyright 2008-2014 Cisco Systems, Inc.  All rights reserved.
>> + * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
>> + *
>> + * Copyright (c) 2014, Cisco Systems, Inc.
>> + * All rights reserved.
>> + *
>> + * Redistribution and use in source and binary forms, with or without
>> + * modification, are permitted provided that the following conditions
>> + * are met:
>> + *
>> + * 1. Redistributions of source code must retain the above copyright
>> + * notice, this list of conditions and the following disclaimer.
>> + *
>> + * 2. 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.
>> + *
>> + * 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 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
>> + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
>> + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
>> + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
>> + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
>> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
>> + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
>> + * POSSIBILITY OF SUCH DAMAGE.
>> + *
>> + */
>> +#ident "$Id$"
>> +
>> +#include 
>> +#include 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "vnic_intr.h"
>> +#include "vnic_cq.h"
>> +#include "vnic_wq.h"
>> +#include "vnic_rq.h"
>> +#include "vnic_enet.h"
>> +#include "enic.h"
>> +
>> +#ifdef RTE_LIBRTE_ENIC_PMD_DEBUG_TRACE
>> +#define ENICPMD_FUNC_TRACE()\
>> +do { \
>> +dev_trace(enic, "Entering %s\n", __func__);   \
>> +} while (0)
>You probably want to convert this to use:
>rte_log(RTE_LOG_DEBUG, RTE_LOGTYPE_PMD, ...)
>Currently you have dev_trace defined to printf, which won't work well on
>systems
>that have stdout/err closed.
>
>Also, you don't need the do{}while(0) construct here just don't add the
>semicolon after the rte_log call, and you'll get the same behavior
>
>converting to rte_log will also let you remove the DEBUG_TRACE ifdef as
>you can
>just enable PMD log types and DEBUG log levels via the log api
>
>> +#else
>> +#define ENICPMD_FUNC_TRACE()
>> +#endif
>> +
>> +
>> +/*
>> + * The set of PCI devices this driver supports
>> + */
>> +static struct rte_pci_id pci_id_enic_map[] = {
>> +#define RTE_PCI_DEV_ID_DECL_ENIC(vend, dev) {RTE_PCI_DEVICE(vend,
>>dev)},
>> +#ifndef PCI_VENDOR_ID_CISCO
>> +#define PCI_VENDOR_ID_CISCO 0x1137
>> +#endif
>> +#include "rte_pci_dev_ids.h"
>> +RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO,
>>PCI_DEVICE_ID_CISCO_VIC_ENET)
>> +RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO,
>>PCI_DEVICE_ID_CISCO_VIC_ENET_VF)
>> +{.vendor_id = 0, /* Sentinal */},
>> +};
>> +
>> +int enicpmd_fdir_remove_perfect_filter(struct rte_eth_dev *eth_dev,
>> +struct rte_fdir_filter *fdir_filter,
>> +uint16_t soft_id)
>> +{
>> +struct enic *enic = pmd_priv(eth_dev);
>> +
>> +ENICPMD_FUNC_TRACE();
>> +return enic_fdir_del_fltr(enic, fdir_filter);
>> +}
>> +
>> +int enicpmd_fdir_add_perfect_filter(struct rte_eth_dev *eth_dev,
>> +struct rte_fdir_filter *fdir_filter, uint16_t soft_id,
>> +uint8_t queue, uint8_t drop)
>> +{
>> +struct enic *enic = pmd_priv(eth_dev);
>> +
>> +ENICPMD_FUNC_TRACE();
>> +return enic_fdir_add_fltr(enic, fdir_filter, (uint16_t)queue, drop);
>> +}
>> +
>> +void enicpmd_fdir_info_get(struct rte_eth_dev *eth_dev,
>> +struct rte_eth_fdir *fdir)
>> +{
>> +struct enic *enic = pmd_priv(eth_dev);
>> +
>> +ENICPMD_FUNC_TRACE();
>> +*fdir = enic->fdir.stats;
>> +}
>> +
>The three functions above should be static, as their exported via the
>device
>structure below.  You don't want people able to call them directly.
>
>> +void enicpmd_dev_tx_queue_release(void *txq)
>> +{
>> +ENICPMD_FUNC_TRACE();
>> +enic_fr

[dpdk-dev] [PATCH v2 5/6] DPDK-ENIC PMD interface

2014-11-21 Thread Neil Horman
On Fri, Nov 21, 2014 at 10:03:02PM +0530, Sujith Sankar wrote:
> Signed-off-by: Sujith Sankar 
> ---
>  lib/librte_pmd_enic/enic_etherdev.c | 620 
> 
>  1 file changed, 620 insertions(+)
>  create mode 100644 lib/librte_pmd_enic/enic_etherdev.c
> 
> diff --git a/lib/librte_pmd_enic/enic_etherdev.c 
> b/lib/librte_pmd_enic/enic_etherdev.c
> new file mode 100644
> index 000..90003f5
> --- /dev/null
> +++ b/lib/librte_pmd_enic/enic_etherdev.c
> @@ -0,0 +1,620 @@
> +/*
> + * Copyright 2008-2014 Cisco Systems, Inc.  All rights reserved.
> + * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
> + *
> + * Copyright (c) 2014, Cisco Systems, Inc. 
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + * notice, this list of conditions and the following disclaimer.
> + *
> + * 2. 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.
> + *
> + * 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 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
> + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
> + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
> + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
> + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
> + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + *
> + */
> +#ident "$Id$"
> +
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "vnic_intr.h"
> +#include "vnic_cq.h"
> +#include "vnic_wq.h"
> +#include "vnic_rq.h"
> +#include "vnic_enet.h"
> +#include "enic.h"
> +
> +#ifdef RTE_LIBRTE_ENIC_PMD_DEBUG_TRACE
> +#define ENICPMD_FUNC_TRACE()\
> + do { \
> + dev_trace(enic, "Entering %s\n", __func__);   \
> + } while (0)
You probably want to convert this to use:
rte_log(RTE_LOG_DEBUG, RTE_LOGTYPE_PMD, ...)
Currently you have dev_trace defined to printf, which won't work well on systems
that have stdout/err closed.

Also, you don't need the do{}while(0) construct here just don't add the
semicolon after the rte_log call, and you'll get the same behavior

converting to rte_log will also let you remove the DEBUG_TRACE ifdef as you can
just enable PMD log types and DEBUG log levels via the log api

> +#else
> +#define ENICPMD_FUNC_TRACE()
> +#endif
> +
> +
> +/*
> + * The set of PCI devices this driver supports
> + */
> +static struct rte_pci_id pci_id_enic_map[] = {
> +#define RTE_PCI_DEV_ID_DECL_ENIC(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
> +#ifndef PCI_VENDOR_ID_CISCO
> +#define PCI_VENDOR_ID_CISCO  0x1137
> +#endif
> +#include "rte_pci_dev_ids.h"
> +RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET)
> +RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO, 
> PCI_DEVICE_ID_CISCO_VIC_ENET_VF)
> +{.vendor_id = 0, /* Sentinal */},
> +};
> +
> +int enicpmd_fdir_remove_perfect_filter(struct rte_eth_dev *eth_dev,
> + struct rte_fdir_filter *fdir_filter,
> + uint16_t soft_id)
> +{
> + struct enic *enic = pmd_priv(eth_dev);
> +
> + ENICPMD_FUNC_TRACE();
> + return enic_fdir_del_fltr(enic, fdir_filter);
> +}
> +
> +int enicpmd_fdir_add_perfect_filter(struct rte_eth_dev *eth_dev,
> + struct rte_fdir_filter *fdir_filter, uint16_t soft_id,
> + uint8_t queue, uint8_t drop)
> +{
> + struct enic *enic = pmd_priv(eth_dev);
> +
> + ENICPMD_FUNC_TRACE();
> + return enic_fdir_add_fltr(enic, fdir_filter, (uint16_t)queue, drop);
> +}
> +
> +void enicpmd_fdir_info_get(struct rte_eth_dev *eth_dev,
> + struct rte_eth_fdir *fdir)
> +{
> + struct enic *enic = pmd_priv(eth_dev);
> +
> + ENICPMD_FUNC_TRACE();
> + *fdir = enic->fdir.stats;
> +}
> +
The three functions above should be static, as their exported via the device
structure below.  You don't want people able to call them directly.

> +void enicpmd_dev_tx_queue_release(void *txq)
> +{
> + ENICPMD_FUNC_TRACE();
> + enic_free_wq(txq);
> +}
> +
> +static int enicpmd_dev_setup_intr(struct enic *enic)
> +{
> + int ret;
> + int index;
> +
> + ENICPMD_FUNC_TRACE();
> +
> + /* Are we done with the init of all the queues? */
> + for (index = 0; in