[dpdk-dev] [RFC PATCH 2/4] Add the new common device header and C file.

2015-04-12 Thread Neil Horman
On Fri, Apr 10, 2015 at 07:25:32PM +, Wiles, Keith wrote:
> 
> 
> On 4/9/15, 6:53 AM, "Neil Horman"  wrote:
> 
> >On Wed, Apr 08, 2015 at 03:58:38PM -0500, Keith Wiles wrote:
> >> Move a number of device specific define, structures and functions
> >> into a generic device base set of files for all device not just
> >>Ethernet.
> >> 
> >> Signed-off-by: Keith Wiles 
> >> ---
> >>  lib/librte_eal/common/eal_common_device.c | 185 +++
> >>  lib/librte_eal/common/include/rte_common_device.h | 617
> >>++
> >>  2 files changed, 802 insertions(+)
> >>  create mode 100644 lib/librte_eal/common/eal_common_device.c
> >>  create mode 100644 lib/librte_eal/common/include/rte_common_device.h
> >> 
> >> diff --git a/lib/librte_eal/common/eal_common_device.c
> >>b/lib/librte_eal/common/eal_common_device.c
> >> new file mode 100644
> >> index 000..a9ef925
> >> --- /dev/null
> >> +++ b/lib/librte_eal/common/eal_common_device.c
> >> @@ -0,0 +1,185 @@
> >> +/*-
> >> + *   BSD LICENSE
> >> + *
> >> + *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> >> + *   Copyright(c) 2014 6WIND S.A.
> >> + *   All rights reserved.
> >> + *
> >> + *   Redistribution and use in source and binary forms, with or without
> >> + *   modification, are permitted provided that the following conditions
> >> + *   are met:
> >> + *
> >> + * * Redistributions of source code must retain the above copyright
> >> + *   notice, this list of conditions and the following disclaimer.
> >> + * * Redistributions in binary form must reproduce the above
> >>copyright
> >> + *   notice, this list of conditions and the following disclaimer
> >>in
> >> + *   the documentation and/or other materials provided with the
> >> + *   distribution.
> >> + * * Neither the name of Intel Corporation nor the names of its
> >> + *   contributors may be used to endorse or promote products
> >>derived
> >> + *   from this software without specific prior written permission.
> >> + *
> >> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> >>CONTRIBUTORS
> >> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> >> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
> >>FOR
> >> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
> >>COPYRIGHT
> >> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
> >>INCIDENTAL,
> >> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> >> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> >>USE,
> >> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
> >>ANY
> >> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
> >>TORT
> >> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
> >>USE
> >> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
> >>DAMAGE.
> >> + */
> >> +
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +
> >> +#include "rte_common_device.h"
> >> +
> >> +void *
> >> +rte_dev_add_callback(struct rte_dev_rxtx_callback ** cbp,
> >> +  void * fn, void *user_param)
> >> +{
> >> +  struct rte_dev_rxtx_callback *cb;
> >> +
> >> +  cb = rte_zmalloc(NULL, sizeof(*cb), 0);
> >> +
> >> +  if (cb == NULL) {
> >> +  rte_errno = ENOMEM;
> >> +  return NULL;
> >> +  }
> >> +
> >> +  cb->fn.vp = fn;
> >> +  cb->param = user_param;
> >> +  cb->next = *cbp;
> >> +  *cbp = cb;
> >> +  return cb;
> >> +}
> >> +
> >> +int
> >> +rte_dev_remove_callback(struct rte_dev_rxtx_callback ** cbp,
> >> +  struct rte_dev_rxtx_callback *user_cb)
> >> +{
> >> +  struct rte_dev_rxtx_callback *cb = *cbp;
> >> +  struct rte_dev_rxtx_callback *prev_cb;
> >> +
> >> +  /* Reset head pointer and remove user cb if first in the list. */
> >> +  if (cb == user_cb) {
> >> +  *cbp = user_cb->next;
> >> +  return 0;
> >> +  }
> >> +
> >> +  /* Remove the user cb from the callback list. */
> >> +  do {
> >> +  prev_cb = cb;
> >> +  cb = cb->next;
> >> +
> >> +  if (cb == user_cb) {
> >> +  prev_cb->next = user_cb->next;
> >> +  return 0;
> >> +  }
> >> +  } while (cb != NULL);
> >> +
> >> +  /* Callback wasn't found. */
> >> +  return (-EINVAL);
> >> +}
> >> +
> >> +int
> >> +rte_dev_callback_register(struct rte_dev_cb_list * cb_list,
> >> +  rte_spinlock_t * lock,
> >> +  enum rte_dev_event_type event,
> >> +  rte_dev_cb_fn cb_fn, void *cb_arg)
> >> +{
> >> +  struct rte_dev_callback *cb;
> >> +
> >> +  rte_spinlock_lock(lock);
> >> +
> >> +  TAILQ_FOREACH(cb, cb_list, next) {
> >> +  if (cb->cb_fn == cb_fn &&
> >> +  cb->cb_arg == cb_arg &&
> >> +  cb->event == event) {
> >> + 

[dpdk-dev] [RFC PATCH 2/4] Add the new common device header and C file.

2015-04-10 Thread Wiles, Keith


On 4/9/15, 6:53 AM, "Neil Horman"  wrote:

>On Wed, Apr 08, 2015 at 03:58:38PM -0500, Keith Wiles wrote:
>> Move a number of device specific define, structures and functions
>> into a generic device base set of files for all device not just
>>Ethernet.
>> 
>> Signed-off-by: Keith Wiles 
>> ---
>>  lib/librte_eal/common/eal_common_device.c | 185 +++
>>  lib/librte_eal/common/include/rte_common_device.h | 617
>>++
>>  2 files changed, 802 insertions(+)
>>  create mode 100644 lib/librte_eal/common/eal_common_device.c
>>  create mode 100644 lib/librte_eal/common/include/rte_common_device.h
>> 
>> diff --git a/lib/librte_eal/common/eal_common_device.c
>>b/lib/librte_eal/common/eal_common_device.c
>> new file mode 100644
>> index 000..a9ef925
>> --- /dev/null
>> +++ b/lib/librte_eal/common/eal_common_device.c
>> @@ -0,0 +1,185 @@
>> +/*-
>> + *   BSD LICENSE
>> + *
>> + *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
>> + *   Copyright(c) 2014 6WIND S.A.
>> + *   All rights reserved.
>> + *
>> + *   Redistribution and use in source and binary forms, with or without
>> + *   modification, are permitted provided that the following conditions
>> + *   are met:
>> + *
>> + * * Redistributions of source code must retain the above copyright
>> + *   notice, this list of conditions and the following disclaimer.
>> + * * Redistributions in binary form must reproduce the above
>>copyright
>> + *   notice, this list of conditions and the following disclaimer
>>in
>> + *   the documentation and/or other materials provided with the
>> + *   distribution.
>> + * * Neither the name of Intel Corporation nor the names of its
>> + *   contributors may be used to endorse or promote products
>>derived
>> + *   from this software without specific prior written permission.
>> + *
>> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
>>CONTRIBUTORS
>> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
>> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
>>FOR
>> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
>>COPYRIGHT
>> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
>>INCIDENTAL,
>> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
>> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
>>USE,
>> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
>>ANY
>> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
>>TORT
>> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
>>USE
>> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
>>DAMAGE.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "rte_common_device.h"
>> +
>> +void *
>> +rte_dev_add_callback(struct rte_dev_rxtx_callback ** cbp,
>> +void * fn, void *user_param)
>> +{
>> +struct rte_dev_rxtx_callback *cb;
>> +
>> +cb = rte_zmalloc(NULL, sizeof(*cb), 0);
>> +
>> +if (cb == NULL) {
>> +rte_errno = ENOMEM;
>> +return NULL;
>> +}
>> +
>> +cb->fn.vp = fn;
>> +cb->param = user_param;
>> +cb->next = *cbp;
>> +*cbp = cb;
>> +return cb;
>> +}
>> +
>> +int
>> +rte_dev_remove_callback(struct rte_dev_rxtx_callback ** cbp,
>> +struct rte_dev_rxtx_callback *user_cb)
>> +{
>> +struct rte_dev_rxtx_callback *cb = *cbp;
>> +struct rte_dev_rxtx_callback *prev_cb;
>> +
>> +/* Reset head pointer and remove user cb if first in the list. */
>> +if (cb == user_cb) {
>> +*cbp = user_cb->next;
>> +return 0;
>> +}
>> +
>> +/* Remove the user cb from the callback list. */
>> +do {
>> +prev_cb = cb;
>> +cb = cb->next;
>> +
>> +if (cb == user_cb) {
>> +prev_cb->next = user_cb->next;
>> +return 0;
>> +}
>> +} while (cb != NULL);
>> +
>> +/* Callback wasn't found. */
>> +return (-EINVAL);
>> +}
>> +
>> +int
>> +rte_dev_callback_register(struct rte_dev_cb_list * cb_list,
>> +rte_spinlock_t * lock,
>> +enum rte_dev_event_type event,
>> +rte_dev_cb_fn cb_fn, void *cb_arg)
>> +{
>> +struct rte_dev_callback *cb;
>> +
>> +rte_spinlock_lock(lock);
>> +
>> +TAILQ_FOREACH(cb, cb_list, next) {
>> +if (cb->cb_fn == cb_fn &&
>> +cb->cb_arg == cb_arg &&
>> +cb->event == event) {
>> +break;
>> +}
>> +}
>> +
>> +/* create a new callback. */
>> +if (cb == NULL && (cb = rte_zmalloc("INTR_USER_CALLBACK",
>> +sizeof(struct rte_dev_callback), 0)) != NULL) {
>> +cb->cb_fn = cb_fn;
>> +cb-

[dpdk-dev] [RFC PATCH 2/4] Add the new common device header and C file.

2015-04-09 Thread Neil Horman
On Wed, Apr 08, 2015 at 03:58:38PM -0500, Keith Wiles wrote:
> Move a number of device specific define, structures and functions
> into a generic device base set of files for all device not just Ethernet.
> 
> Signed-off-by: Keith Wiles 
> ---
>  lib/librte_eal/common/eal_common_device.c | 185 +++
>  lib/librte_eal/common/include/rte_common_device.h | 617 
> ++
>  2 files changed, 802 insertions(+)
>  create mode 100644 lib/librte_eal/common/eal_common_device.c
>  create mode 100644 lib/librte_eal/common/include/rte_common_device.h
> 
> diff --git a/lib/librte_eal/common/eal_common_device.c 
> b/lib/librte_eal/common/eal_common_device.c
> new file mode 100644
> index 000..a9ef925
> --- /dev/null
> +++ b/lib/librte_eal/common/eal_common_device.c
> @@ -0,0 +1,185 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2014 6WIND S.A.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + * * Redistributions of source code must retain the above copyright
> + *   notice, this list of conditions and the following disclaimer.
> + * * Redistributions in binary form must reproduce the above copyright
> + *   notice, this list of conditions and the following disclaimer in
> + *   the documentation and/or other materials provided with the
> + *   distribution.
> + * * Neither the name of Intel Corporation nor the names of its
> + *   contributors may be used to endorse or promote products derived
> + *   from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "rte_common_device.h"
> +
> +void *
> +rte_dev_add_callback(struct rte_dev_rxtx_callback ** cbp,
> + void * fn, void *user_param)
> +{
> + struct rte_dev_rxtx_callback *cb;
> +
> + cb = rte_zmalloc(NULL, sizeof(*cb), 0);
> +
> + if (cb == NULL) {
> + rte_errno = ENOMEM;
> + return NULL;
> + }
> +
> + cb->fn.vp = fn;
> + cb->param = user_param;
> + cb->next = *cbp;
> + *cbp = cb;
> + return cb;
> +}
> +
> +int
> +rte_dev_remove_callback(struct rte_dev_rxtx_callback ** cbp,
> + struct rte_dev_rxtx_callback *user_cb)
> +{
> + struct rte_dev_rxtx_callback *cb = *cbp;
> + struct rte_dev_rxtx_callback *prev_cb;
> +
> + /* Reset head pointer and remove user cb if first in the list. */
> + if (cb == user_cb) {
> + *cbp = user_cb->next;
> + return 0;
> + }
> +
> + /* Remove the user cb from the callback list. */
> + do {
> + prev_cb = cb;
> + cb = cb->next;
> +
> + if (cb == user_cb) {
> + prev_cb->next = user_cb->next;
> + return 0;
> + }
> + } while (cb != NULL);
> +
> + /* Callback wasn't found. */
> + return (-EINVAL);
> +}
> +
> +int
> +rte_dev_callback_register(struct rte_dev_cb_list * cb_list,
> + rte_spinlock_t * lock,
> + enum rte_dev_event_type event,
> + rte_dev_cb_fn cb_fn, void *cb_arg)
> +{
> + struct rte_dev_callback *cb;
> +
> + rte_spinlock_lock(lock);
> +
> + TAILQ_FOREACH(cb, cb_list, next) {
> + if (cb->cb_fn == cb_fn &&
> + cb->cb_arg == cb_arg &&
> + cb->event == event) {
> + break;
> + }
> + }
> +
> + /* create a new callback. */
> + if (cb == NULL && (cb = rte_zmalloc("INTR_USER_CALLBACK",
> + sizeof(struct rte_dev_callback), 0)) != NULL) {
> + cb->cb_fn = cb_fn;
> + cb->cb_arg = cb_arg;
> + cb->event = event;
> + TAILQ_INSERT_TAIL(cb_list, cb, next);
> + }
> +
> + rte_spinlock_unlock(lock);
> +

[dpdk-dev] [RFC PATCH 2/4] Add the new common device header and C file.

2015-04-08 Thread Keith Wiles
Move a number of device specific define, structures and functions
into a generic device base set of files for all device not just Ethernet.

Signed-off-by: Keith Wiles 
---
 lib/librte_eal/common/eal_common_device.c | 185 +++
 lib/librte_eal/common/include/rte_common_device.h | 617 ++
 2 files changed, 802 insertions(+)
 create mode 100644 lib/librte_eal/common/eal_common_device.c
 create mode 100644 lib/librte_eal/common/include/rte_common_device.h

diff --git a/lib/librte_eal/common/eal_common_device.c 
b/lib/librte_eal/common/eal_common_device.c
new file mode 100644
index 000..a9ef925
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_device.c
@@ -0,0 +1,185 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2014 6WIND S.A.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "rte_common_device.h"
+
+void *
+rte_dev_add_callback(struct rte_dev_rxtx_callback ** cbp,
+   void * fn, void *user_param)
+{
+   struct rte_dev_rxtx_callback *cb;
+
+   cb = rte_zmalloc(NULL, sizeof(*cb), 0);
+
+   if (cb == NULL) {
+   rte_errno = ENOMEM;
+   return NULL;
+   }
+
+   cb->fn.vp = fn;
+   cb->param = user_param;
+   cb->next = *cbp;
+   *cbp = cb;
+   return cb;
+}
+
+int
+rte_dev_remove_callback(struct rte_dev_rxtx_callback ** cbp,
+   struct rte_dev_rxtx_callback *user_cb)
+{
+   struct rte_dev_rxtx_callback *cb = *cbp;
+   struct rte_dev_rxtx_callback *prev_cb;
+
+   /* Reset head pointer and remove user cb if first in the list. */
+   if (cb == user_cb) {
+   *cbp = user_cb->next;
+   return 0;
+   }
+
+   /* Remove the user cb from the callback list. */
+   do {
+   prev_cb = cb;
+   cb = cb->next;
+
+   if (cb == user_cb) {
+   prev_cb->next = user_cb->next;
+   return 0;
+   }
+   } while (cb != NULL);
+
+   /* Callback wasn't found. */
+   return (-EINVAL);
+}
+
+int
+rte_dev_callback_register(struct rte_dev_cb_list * cb_list,
+   rte_spinlock_t * lock,
+   enum rte_dev_event_type event,
+   rte_dev_cb_fn cb_fn, void *cb_arg)
+{
+   struct rte_dev_callback *cb;
+
+   rte_spinlock_lock(lock);
+
+   TAILQ_FOREACH(cb, cb_list, next) {
+   if (cb->cb_fn == cb_fn &&
+   cb->cb_arg == cb_arg &&
+   cb->event == event) {
+   break;
+   }
+   }
+
+   /* create a new callback. */
+   if (cb == NULL && (cb = rte_zmalloc("INTR_USER_CALLBACK",
+   sizeof(struct rte_dev_callback), 0)) != NULL) {
+   cb->cb_fn = cb_fn;
+   cb->cb_arg = cb_arg;
+   cb->event = event;
+   TAILQ_INSERT_TAIL(cb_list, cb, next);
+   }
+
+   rte_spinlock_unlock(lock);
+   return ((cb == NULL) ? -ENOMEM : 0);
+}
+
+int
+rte_dev_callback_unregister(struct rte_dev_cb_list * cb_list,
+   rte_spinlock_t * lock,
+   enum rte_dev_event_type event,
+   rte_dev_cb_fn cb_fn, void *cb