[dpdk-dev] [PATCH v2] lib/ether: prevent duplicate callback on list

2016-10-20 Thread E. Scott Daniels
This change prevents the attempt to add a structure which is
already on the callback list. If a struct with matching
parameters is found on the list, then no action is taken. If
a struct with matching parameters is found on the list, then
no action is taken.

Fixes: ac2f69c ("ethdev: fix crash if malloc of user callback fails")

Signed-off-by: E. Scott Daniels 
---

V2:
* Correct the component name; changed from net/ixgbe.
* Add Fixes tag.
* Acked-by: Wenzhuo Lu 

 lib/librte_ether/rte_ethdev.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 0d9d9c1..fde8112 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -2449,14 +2449,15 @@ rte_eth_dev_callback_register(uint8_t port_id,
}

/* create a new callback. */
-   if (user_cb == NULL)
+   if (user_cb == NULL) {
user_cb = rte_zmalloc("INTR_USER_CALLBACK",
sizeof(struct rte_eth_dev_callback), 0);
-   if (user_cb != NULL) {
-   user_cb->cb_fn = cb_fn;
-   user_cb->cb_arg = cb_arg;
-   user_cb->event = event;
-   TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
+   if (user_cb != NULL) {
+   user_cb->cb_fn = cb_fn;
+   user_cb->cb_arg = cb_arg;
+   user_cb->event = event;
+   TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
+   }
}

rte_spinlock_unlock(_eth_dev_cb_lock);
-- 
1.9.1



[dpdk-dev] [PATCH] net/ixgbe: prevent duplicate callback on list

2016-10-19 Thread E. Scott Daniels
This change prevents the attempt to add a structure which is
already on the callback list. If a struct with matching
parameters is found on the list, then no action is taken. If
a struct with matching parameters is found on the list, then
no action is taken.

Signed-off-by: E. Scott Daniels 
---
 lib/librte_ether/rte_ethdev.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 0d9d9c1..fde8112 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -2449,14 +2449,15 @@ rte_eth_dev_callback_register(uint8_t port_id,
}

/* create a new callback. */
-   if (user_cb == NULL)
+   if (user_cb == NULL) {
user_cb = rte_zmalloc("INTR_USER_CALLBACK",
sizeof(struct rte_eth_dev_callback), 0);
-   if (user_cb != NULL) {
-   user_cb->cb_fn = cb_fn;
-   user_cb->cb_arg = cb_arg;
-   user_cb->event = event;
-   TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
+   if (user_cb != NULL) {
+   user_cb->cb_fn = cb_fn;
+   user_cb->cb_arg = cb_arg;
+   user_cb->event = event;
+   TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
+   }
}

rte_spinlock_unlock(_eth_dev_cb_lock);
-- 
1.9.1



[dpdk-dev] [PATCH] net/ixgbe: prevent duplicate callback on list

2016-10-19 Thread E. Scott Daniels
If rte_eth_dev_callback_register() is invoked with parameters
which match a callback struct that is already on the list, an
attempt is made to add that same struct onto the tail of the
list. Adding a struct which is already on the list will have
undesired results.

This is an edge case, but I think it should be corrected;
patch prevents the attempt to add a struct which is already
on the list.

E. Scott Daniels (1):
  net/ixgbe: prevent duplicate callback on list

 lib/librte_ether/rte_ethdev.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

-- 
1.9.1



[dpdk-dev] [PATCH] net/ixgbe: fix vlan insert parameter type and its use

2016-10-18 Thread E. Scott Daniels
The final parameter to rte_pmd_ixgbe_set_vf_vlan_insert is uint8_t
and treated as a binary flag when it needs to be a uint16_t
and treated as a VLAN id.  The data sheet (sect 8.2.3.27.13) describes
the right most 16 bits as the VLAN id that is to be inserted; the
16.11  code is accepting only a 1 or 0 thus effectively only
allowing the VLAN id 1 to be inserted (0 disables the insertion
setting).

This patch changes the final parm name to represent the data that
is being accepted (vlan_id), changes the type to permit all valid
VLAN ids, and validates the parameter based on the range of 0 to
4095. Corresponding changes to prototype and documentation in the
.h file.

Fixes:  49e248223e9f71 ("net/ixgbe: add API for VF management")

Signed-off-by: E. Scott Daniels 
---
 drivers/net/ixgbe/ixgbe_ethdev.c  | 8 
 drivers/net/ixgbe/rte_pmd_ixgbe.h | 9 +
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 4ca5747..316af73 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -4727,7 +4727,7 @@ rte_pmd_ixgbe_set_vf_mac_anti_spoof(uint8_t port, 
uint16_t vf, uint8_t on)
 }

 int
-rte_pmd_ixgbe_set_vf_vlan_insert(uint8_t port, uint16_t vf, uint8_t on)
+rte_pmd_ixgbe_set_vf_vlan_insert(uint8_t port, uint16_t vf, uint16_t vlan_id)
 {
struct ixgbe_hw *hw;
uint32_t ctrl;
@@ -4742,13 +4742,13 @@ rte_pmd_ixgbe_set_vf_vlan_insert(uint8_t port, uint16_t 
vf, uint8_t on)
if (vf >= dev_info.max_vfs)
return -EINVAL;

-   if (on > 1)
+   if (vlan_id > 4095)
return -EINVAL;

hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
ctrl = IXGBE_READ_REG(hw, IXGBE_VMVIR(vf));
-   if (on) {
-   ctrl = on;
+   if (vlan_id) {
+   ctrl = vlan_id;
ctrl |= IXGBE_VMVIR_VLANA_DEFAULT;
} else {
ctrl = 0;
diff --git a/drivers/net/ixgbe/rte_pmd_ixgbe.h 
b/drivers/net/ixgbe/rte_pmd_ixgbe.h
index 2fdf530..c2fb826 100644
--- a/drivers/net/ixgbe/rte_pmd_ixgbe.h
+++ b/drivers/net/ixgbe/rte_pmd_ixgbe.h
@@ -99,16 +99,17 @@ int rte_pmd_ixgbe_set_vf_mac_anti_spoof(uint8_t port, 
uint16_t vf, uint8_t on);
  *The port identifier of the Ethernet device.
  * @param vf
  *ID specifying VF.
- * @param on
- *1 - Enable VF's vlan insert.
- *0 - Disable VF's vlan insert
+ * @param vlan_id
+ *0 - Disable VF's vlan insert.
+ *n - Enable; n is inserted as the vlan id.
  *
  * @return
  *   - (0) if successful.
  *   - (-ENODEV) if *port* invalid.
  *   - (-EINVAL) if bad parameter.
  */
-int rte_pmd_ixgbe_set_vf_vlan_insert(uint8_t port, uint16_t vf, uint8_t on);
+int rte_pmd_ixgbe_set_vf_vlan_insert(uint8_t port, uint16_t vf,
+   uint16_t vlan_id);

 /**
  * Enable/Disable tx loopback
-- 
1.9.1