[dpdk-dev] [PATCH v2] net/virtio: fix add pointer checking for rxvq

2018-05-24 Thread zhiyong . yang
For virtio-user server mode, one use case comes across segmentation fault.
step 1: Launch vhost side as client firstly.
step 2: launch virtio-user side as server.

The cause is: after registering virtio_interrupt_handler into
eal-intr-thread, two threads (main thread and eal-intr-thread) have
sync issues, so add rxvq pointer checking in function virtio_notify_peers
to decide if the code can continue.

Fixes: bd8f50a45d0f ("net/virtio-user: support server mode")
Cc: sta...@dpdk.org
Cc: maxime.coque...@redhat.com
Cc: tiwei@intel.com
Cc: lei.a@intel.com
Cc: ferruh.yi...@intel.com

Signed-off-by: Zhiyong Yang 
Reviewed-by: Maxime Coquelin 
---

Change in V2:
change title prefix from net/virtio-user to net/virtio.

 drivers/net/virtio/virtio_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index 5833dad73..df50a571a 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1245,6 +1245,9 @@ virtio_notify_peers(struct rte_eth_dev *dev)
return;
 
rxvq = dev->data->rx_queues[0];
+   if (!rxvq)
+   return;
+
rarp_mbuf = rte_net_make_rarp_packet(rxvq->mpool,
(struct ether_addr *)hw->mac_addr);
if (rarp_mbuf == NULL) {
-- 
2.14.3



[dpdk-dev] [PATCH] net/virtio-user: fix add pointer checking for rxvq

2018-05-23 Thread zhiyong . yang
For virtio-user server mode, One use case comes across segmentation fault.
step 1: Launch vhost side as client firstly.
step 2: launch virtio-user side as server.

The cause is: after registering virtio_interrupt_handler into
eal-intr-thread, two threads (main thread and eal-intr-thread) have
sync issues, so add rxvq pointer checking in function virtio_notify_peers
to decide if the code can continue.

Fixes: bd8f50a45d0f ("net/virtio-user: support server mode")
Cc: sta...@dpdk.org
Cc: maxime.coque...@redhat.com
Cc: tiwei@intel.com
Cc: lei.a@intel.com
Cc: ferruh.yi...@intel.com

Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index 5833dad73..df50a571a 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1245,6 +1245,9 @@ virtio_notify_peers(struct rte_eth_dev *dev)
return;
 
rxvq = dev->data->rx_queues[0];
+   if (!rxvq)
+   return;
+
rarp_mbuf = rte_net_make_rarp_packet(rxvq->mpool,
(struct ether_addr *)hw->mac_addr);
if (rarp_mbuf == NULL) {
-- 
2.14.3



[dpdk-dev] [PATCH] ethdev: fix eth_dev_last_created_port storage type

2018-05-17 Thread zhiyong . yang
eth_dev_last_created_port is used to store port id type and should
be extended to 16bits corresponding to ethdev port id range.

Cc: sta...@dpdk.org
Cc: ferruh.yi...@intel.com

Fixes: f8244c6399d9 ("ethdev: increase port id range")

Signed-off-by: Zhiyong Yang 
---
 lib/librte_ethdev/rte_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index b3ed82105..cd4bfd3c6 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -49,7 +49,7 @@ static int ethdev_logtype;
 
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
-static uint8_t eth_dev_last_created_port;
+static uint16_t eth_dev_last_created_port;
 
 /* spinlock for eth device callbacks */
 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
-- 
2.14.3



[dpdk-dev] [PATCH v2] app/testpmd: fix pmd_test_exit function for vdevs

2018-05-17 Thread zhiyong . yang
For vdev, just calling rte_eth_dev_close() isn't enough to free all
the resources allocated during device probe, e.g. for virtio-user,
virtio_user_pmd_remove(), i.e. the remove() method of a vdev driver,
needs to be called to unlink the socket file created during device
probe. So this patch calls the rte_eth_dev_detach() for vdev when
quitting testpmd.

Cc: maxime.coque...@redhat.com
Cc: ferruh.yi...@intel.com
Cc: tiwei@intel.com
Cc: lei.a@intel.com
Cc: bernard.iremon...@intel.com
Cc: sta...@dpdk.org

Fixes: af75078fece3 ("first public release")
Fixes: bd8f50a45d0f ("net/virtio-user: support server mode")

Signed-off-by: Zhiyong Yang 
---

changes in V2:
1. change the pache title and add a fixes line.

 app/test-pmd/testpmd.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 134401603..1d308f056 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2011,6 +2011,8 @@ detach_port(portid_t port_id)
 void
 pmd_test_exit(void)
 {
+   const struct rte_bus *bus;
+   struct rte_device *device;
portid_t pt_id;
int ret;
 
@@ -2020,10 +2022,14 @@ pmd_test_exit(void)
if (ports != NULL) {
no_link_check = 1;
RTE_ETH_FOREACH_DEV(pt_id) {
+   device = rte_eth_devices[pt_id].device;
+   bus = rte_bus_find_by_device(device);
printf("\nShutting down port %d...\n", pt_id);
fflush(stdout);
stop_port(pt_id);
close_port(pt_id);
+   if (bus && !strcmp(bus->name, "vdev"))
+   detach_port(pt_id);
}
}
 
-- 
2.14.3



[dpdk-dev] [PATCH] app/testpmd: add to call detach for vdev when quitting

2018-05-16 Thread zhiyong . yang
For vdev, just calling rte_eth_dev_close() isn't enough to free all
the resources allocated during device probe, e.g. for virtio-user,
virtio_user_pmd_remove(), i.e. the remove() method of a vdev driver,
needs to be called to unlink the socket file created during device
probe. So this patch calls the rte_eth_dev_detach() for vdev when
quitting testpmd.

Cc: maxime.coque...@redhat.com
Cc: ferruh.yi...@intel.com
Cc: tiwei@intel.com
Cc: lei.a@intel.com

Signed-off-by: Zhiyong Yang 
---
 app/test-pmd/testpmd.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 134401603..1d308f056 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2011,6 +2011,8 @@ detach_port(portid_t port_id)
 void
 pmd_test_exit(void)
 {
+   const struct rte_bus *bus;
+   struct rte_device *device;
portid_t pt_id;
int ret;
 
@@ -2020,10 +2022,14 @@ pmd_test_exit(void)
if (ports != NULL) {
no_link_check = 1;
RTE_ETH_FOREACH_DEV(pt_id) {
+   device = rte_eth_devices[pt_id].device;
+   bus = rte_bus_find_by_device(device);
printf("\nShutting down port %d...\n", pt_id);
fflush(stdout);
stop_port(pt_id);
close_port(pt_id);
+   if (bus && !strcmp(bus->name, "vdev"))
+   detach_port(pt_id);
}
}
 
-- 
2.14.3



[dpdk-dev] [PATCH] app/testpmd: fix print unused parameter name

2018-05-13 Thread zhiyong . yang
The second parameter "name" in the function rte_eth_dev_detach
has been already redefined as "char *name __rte_unused",
"port_id" is printed instead of "name" in testpmd.

Fixes: b65ecf199324 ("devargs: rename legacy API")
Cc: sta...@dpdk.org
Signed-off-by: Zhiyong Yang 
---
 app/test-pmd/testpmd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 664c43554..02a28199b 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -1985,7 +1985,7 @@ detach_port(portid_t port_id)
port_flow_flush(port_id);
 
if (rte_eth_dev_detach(port_id, name)) {
-   TESTPMD_LOG(ERR, "Failed to detach port '%s'\n", name);
+   TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
return;
}
 
@@ -1993,8 +1993,8 @@ detach_port(portid_t port_id)
 
update_fwd_ports(RTE_MAX_ETHPORTS);
 
-   printf("Port '%s' is detached. Now total ports is %d\n",
-   name, nb_ports);
+   printf("Port %u is detached. Now total ports is %d\n",
+   port_id, nb_ports);
printf("Done\n");
return;
 }
-- 
2.14.3



[dpdk-dev] [PATCH v4] net/virtio-user: fix multiple queues fail in server mode

2018-05-10 Thread zhiyong . yang
This patch fixes multiple queues failure when virtio-user works in
server mode.

This patch adds feature negotiation in the processing of virtio-user
connection and enables multiple-queue pairs.

Fixes: bd8f50a45d0f ("net/virtio-user: support server mode")
Cc: sta...@dpdk.org
Cc: tiwei@intel.com
Cc: ferruh.yi...@intel.com
Cc: maxime.coque...@redhat.com

Signed-off-by: Zhiyong Yang 
Reviewed-by: Tiwei Bie 
---

Changes in V4:
1. fix two typoes.

Changes in V3:
1. virtio_user_handle_mq is redefined as extern instead of static.
2. add to call virtio_user_handle_mq in virtio_user_server_reconnect. 

Changes in V2:
1. fix a comment typo.
2. add feature negotiation in the processing of reconnection.

 drivers/net/virtio/virtio_user/vhost_user.c  |  3 +++
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 18 ++--
 drivers/net/virtio/virtio_user/virtio_user_dev.h |  1 +
 drivers/net/virtio/virtio_user_ethdev.c  | 27 
 4 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index a6df97a00..93e4d9213 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -263,6 +263,9 @@ vhost_user_sock(struct virtio_user_dev *dev,
 
PMD_DRV_LOG(INFO, "%s", vhost_msg_strings[req]);
 
+   if (dev->is_server && vhostfd < 0)
+   return -1;
+
msg.request = req;
msg.flags = VHOST_USER_VERSION;
msg.size = 0;
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c 
b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 38b8bc90d..d50f98b36 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -435,7 +435,7 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev)
unlink(dev->path);
 }
 
-static uint8_t
+uint8_t
 virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs)
 {
uint16_t i;
@@ -447,11 +447,17 @@ virtio_user_handle_mq(struct virtio_user_dev *dev, 
uint16_t q_pairs)
return -1;
}
 
-   for (i = 0; i < q_pairs; ++i)
-   ret |= dev->ops->enable_qp(dev, i, 1);
-   for (i = q_pairs; i < dev->max_queue_pairs; ++i)
-   ret |= dev->ops->enable_qp(dev, i, 0);
-
+   /* Server mode can't enable queue pairs if vhostfd is invalid,
+* always return 0 in this case.
+*/
+   if (dev->vhostfd >= 0) {
+   for (i = 0; i < q_pairs; ++i)
+   ret |= dev->ops->enable_qp(dev, i, 1);
+   for (i = q_pairs; i < dev->max_queue_pairs; ++i)
+   ret |= dev->ops->enable_qp(dev, i, 0);
+   } else if (!dev->is_server) {
+   ret = ~0;
+   }
dev->queue_pairs = q_pairs;
 
return ret;
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h 
b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index ade727e46..784f4752e 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -48,4 +48,5 @@ int virtio_user_dev_init(struct virtio_user_dev *dev, char 
*path, int queues,
 int cq, int queue_size, const char *mac, char 
**ifname);
 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
+uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
 #endif
diff --git a/drivers/net/virtio/virtio_user_ethdev.c 
b/drivers/net/virtio/virtio_user_ethdev.c
index 4e7b3c34f..f35fa8d27 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -30,6 +30,7 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
int ret;
int flag;
int connectfd;
+   uint64_t features = dev->device_features;
struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
 
connectfd = accept(dev->listenfd, NULL, NULL);
@@ -37,6 +38,25 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
return -1;
 
dev->vhostfd = connectfd;
+   if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
+  &dev->device_features) < 0) {
+   PMD_INIT_LOG(ERR, "get_features failed: %s",
+strerror(errno));
+   return -1;
+   }
+
+   features &= ~dev->device_features;
+   /* For following bits, vhost-user doesn't really need to know */
+   features &= ~(1ull << VIRTIO_NET_F_MAC);
+   features &= ~(1ull << VIRTIO_NET_F_CTRL_VLAN);
+   features &= ~(1ull << VIRTIO_NET_F_CTRL_MAC_ADDR)

[dpdk-dev] [PATCH v3] net/virtio-user: fix multiple queues fail in server mode

2018-05-10 Thread zhiyong . yang
This patch fixes multiple queues failure when virtio-user works in
server mode.

This patch adds feature negotiation in the processing of virtio-user
connection and enables multiple-queue pairs.

Fixes: bd8f50a45d0f ("net/virtio-user: support server mode")
Cc: sta...@dpdk.org

Signed-off-by: Zhiyong Yang 
---

Changes in V3:
1. virtio_user_handle_mq is redefined as extern instead of static.
2. add to call virtio_user_handle_mq in virtio_user_server_reconnect. 

Changes in V2:
1. fix a comment typo.
2. add feature negotiation in the processing of reconnection.

 drivers/net/virtio/virtio_user/vhost_user.c  |  3 +++
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 18 ++--
 drivers/net/virtio/virtio_user/virtio_user_dev.h |  1 +
 drivers/net/virtio/virtio_user_ethdev.c  | 27 
 4 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index a6df97a00..93e4d9213 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -263,6 +263,9 @@ vhost_user_sock(struct virtio_user_dev *dev,
 
PMD_DRV_LOG(INFO, "%s", vhost_msg_strings[req]);
 
+   if (dev->is_server && vhostfd < 0)
+   return -1;
+
msg.request = req;
msg.flags = VHOST_USER_VERSION;
msg.size = 0;
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c 
b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 38b8bc90d..505f2ea5e 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -435,7 +435,7 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev)
unlink(dev->path);
 }
 
-static uint8_t
+uint8_t
 virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs)
 {
uint16_t i;
@@ -447,11 +447,17 @@ virtio_user_handle_mq(struct virtio_user_dev *dev, 
uint16_t q_pairs)
return -1;
}
 
-   for (i = 0; i < q_pairs; ++i)
-   ret |= dev->ops->enable_qp(dev, i, 1);
-   for (i = q_pairs; i < dev->max_queue_pairs; ++i)
-   ret |= dev->ops->enable_qp(dev, i, 0);
-
+   /* Server mode can't enable queue pairs if vhostfd is invalid,
+* always return 0 in this case.
+*/
+   if (dev->vhostfd >= 0)  {
+   for (i = 0; i < q_pairs; ++i)
+   ret |= dev->ops->enable_qp(dev, i, 1);
+   for (i = q_pairs; i < dev->max_queue_pairs; ++i)
+   ret |= dev->ops->enable_qp(dev, i, 0);
+   } else if (!dev->is_server) {
+   ret = ~0;
+   }
dev->queue_pairs = q_pairs;
 
return ret;
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h 
b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index ade727e46..784f4752e 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -48,4 +48,5 @@ int virtio_user_dev_init(struct virtio_user_dev *dev, char 
*path, int queues,
 int cq, int queue_size, const char *mac, char 
**ifname);
 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
+uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
 #endif
diff --git a/drivers/net/virtio/virtio_user_ethdev.c 
b/drivers/net/virtio/virtio_user_ethdev.c
index 4e7b3c34f..e53d8f996 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -30,6 +30,7 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
int ret;
int flag;
int connectfd;
+   uint64_t features = dev->device_features;
struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
 
connectfd = accept(dev->listenfd, NULL, NULL);
@@ -37,6 +38,25 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
return -1;
 
dev->vhostfd = connectfd;
+   if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
+  &dev->device_features) < 0) {
+   PMD_INIT_LOG(ERR, "get_features failed: %s",
+strerror(errno));
+   return -1;
+   }
+
+   features &= ~dev->device_features;
+   /* For following bits, vhost-user doesn't really need to know */
+   features &= ~(1ull << VIRTIO_NET_F_MAC);
+   features &= ~(1ull << VIRTIO_NET_F_CTRL_VLAN);
+   features &= ~(1ull << VIRTIO_NET_F_CTRL_MAC_ADDR);
+   features &= ~(1ull << VIRTIO_NET_F_STATUS);
+   if (features)
+   PMD_INIT_LOG(ERR, "WARNING: Some features 0x%" 

[dpdk-dev] [PATCH v2] net/virtio-user: fix multiple queues fail in server mode

2018-05-10 Thread zhiyong . yang
This patch fixes multiple queues failure when virtio-user works in
server mode.

This patch adds feature negotiation in the processing of virtio-user
reccnnection.

Fixes: bd8f50a45d0f ("net/virtio-user: support server mode")

Signed-off-by: Zhiyong Yang 
---

Changes in V2:
1. fix a comment typo.
2. add feature negotiation in the processing of reconnection.

 drivers/net/virtio/virtio_user/vhost_user.c  |  3 +++
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 14 ++
 drivers/net/virtio/virtio_user_ethdev.c  | 20 
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index a6df97a..93e4d92 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -263,6 +263,9 @@ struct hugepage_file_info {
 
PMD_DRV_LOG(INFO, "%s", vhost_msg_strings[req]);
 
+   if (dev->is_server && vhostfd < 0)
+   return -1;
+
msg.request = req;
msg.flags = VHOST_USER_VERSION;
msg.size = 0;
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c 
b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 38b8bc9..b7e1915 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -447,10 +447,16 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
return -1;
}
 
-   for (i = 0; i < q_pairs; ++i)
-   ret |= dev->ops->enable_qp(dev, i, 1);
-   for (i = q_pairs; i < dev->max_queue_pairs; ++i)
-   ret |= dev->ops->enable_qp(dev, i, 0);
+   /* Server mode can't enable queue pairs if vhostfd is invalid,
+* always return 0 in this case.
+*/
+   if (dev->vhostfd >= 0)  {
+   for (i = 0; i < q_pairs; ++i)
+   ret |= dev->ops->enable_qp(dev, i, 1);
+   for (i = q_pairs; i < dev->max_queue_pairs; ++i)
+   ret |= dev->ops->enable_qp(dev, i, 0);
+   } else if (!dev->is_server)
+   ret = ~0;
 
dev->queue_pairs = q_pairs;
 
diff --git a/drivers/net/virtio/virtio_user_ethdev.c 
b/drivers/net/virtio/virtio_user_ethdev.c
index 4e7b3c3..91a0c44 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -30,6 +30,7 @@
int ret;
int flag;
int connectfd;
+   uint64_t features = dev->device_features, status;
struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
 
connectfd = accept(dev->listenfd, NULL, NULL);
@@ -37,6 +38,25 @@
return -1;
 
dev->vhostfd = connectfd;
+   if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
+  &dev->device_features) < 0) {
+   PMD_INIT_LOG(ERR, "get_features failed: %s",
+strerror(errno));
+   return -1;
+   }
+
+   status = features & ~dev->device_features;
+   /* For following bits, vhost-user doesn't really need to know */
+   status &= ~(1ull << VIRTIO_NET_F_MAC);
+   status &= ~(1ull << VIRTIO_NET_F_CTRL_VLAN);
+   status &= ~(1ull << VIRTIO_NET_F_CTRL_MAC_ADDR);
+   status &= ~(1ull << VIRTIO_NET_F_STATUS);
+   if (status)
+   PMD_INIT_LOG(ERR, "WARNING: Some features (0x%lx) are not 
supported by vhost-user!",
+status);
+
+   dev->features &= dev->device_features;
+
flag = fcntl(connectfd, F_GETFD);
fcntl(connectfd, F_SETFL, flag | O_NONBLOCK);
 
-- 
1.8.3.1



[dpdk-dev] [PATCH] net/virtio-user: fix multiple queues fail in server mode

2018-05-09 Thread zhiyong . yang
This patch fixes multiple queues failure when virtio-user works in
server mode.

Fixes: bd8f50a45d0f ("net/virtio-user: support server mode")
Cc: sta...@dpdk.org
Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_user/vhost_user.c  | 3 +++
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 9 +
 2 files changed, 12 insertions(+)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index a6df97a00..a9e53d7b5 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -263,6 +263,9 @@ vhost_user_sock(struct virtio_user_dev *dev,
 
PMD_DRV_LOG(INFO, "%s", vhost_msg_strings[req]);
 
+   if (vhostfd < 0)
+   return -1;
+
msg.request = req;
msg.flags = VHOST_USER_VERSION;
msg.size = 0;
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c 
b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 38b8bc90d..e988dc3f4 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -126,6 +126,10 @@ virtio_user_start_device(struct virtio_user_dev *dev)
features &= ~(1ull << VIRTIO_NET_F_MAC);
/* Strip VIRTIO_NET_F_CTRL_VQ, as devices do not really need to know */
features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ);
+   /* Also disable features which depend on VIRTIO_NET_F_CTRL_VQ */
+   features &= ~(1ull << VIRTIO_NET_F_CTRL_RX);
+   features &= ~(1ull << VIRTIO_NET_F_CTRL_VLAN);
+   features &= ~(1ull << VIRTIO_NET_F_CTRL_MAC_ADDR);
features &= ~(1ull << VIRTIO_NET_F_STATUS);
ret = dev->ops->send_request(dev, VHOST_USER_SET_FEATURES, &features);
if (ret < 0)
@@ -488,6 +492,11 @@ virtio_user_handle_ctrl_msg(struct virtio_user_dev *dev, 
struct vring *vring,
queues = *(uint16_t *)(uintptr_t)vring->desc[idx_data].addr;
status = virtio_user_handle_mq(dev, queues);
}
+   /* Server mode can't enable queue pairs if vhostfd is not connected,
+* we suppose that status always returns 0 in this case.
+* /
+   if (dev->is_server && dev->vhostfd < 0)
+   status = 0;
 
/* Update status */
*(virtio_net_ctrl_ack *)(uintptr_t)vring->desc[idx_status].addr = 
status;
-- 
2.14.3



[dpdk-dev] [PATCH v7] net/virtio-user: add support for server mode

2018-04-06 Thread zhiyong . yang
In a container environment if the vhost-user backend restarts, there's
no way for it to reconnect to virtio-user. To address this, support for
server mode is added. In this mode the socket file is created by virtio-
user, which the backend then connects to. This means that if the backend
restarts, it can reconnect to virtio-user and continue communications.

With current implementation, LSC is enabled at virtio-user side to
support to accept the coming connection.

Server mode virtio-user only supports to work with vhost-user.

Release note is updated in this patch.

Signed-off-by: Zhiyong Yang 
---

Cc: maxime.coque...@redhat.com
Cc: jianfeng@intel.com
Cc: tiwei@intel.com
Cc: zhihong.w...@intel.com
Cc: dong1.w...@intel.com
Cc: tho...@monjalon.net

Changes in V7:
1. avoid misusing vhost-kernel in server mode virtio-user.
2. move the funciton definition is_vhost_user_by_type before 
virtio_user_start_device in order that it can be called.
3. add comments in the code to state feature negotiation limit.

Changes in V6:
1. fix report wrong link stauts in server mode.
2. fix some code style issues.

Changes in V5:
1. Support server mode virtio-user startup in non-blocking mode.
2. rebase on top of dpdk-next-virtio.

Changes in V4:
1. Don't create new pthread any more and use librte_eal interrupt thread
instead. 

Changes in V3:
1. use EAL epoll mechanism instead of vhost events. Cancel to export vhost
event APIs.
2. rebase the code on top of dpdk-next-virtio

Changes in V2:
1. split two patches 1/5 and 2/5 from v1 patchset to fix some existing issues
which is not strongly related to support for server mode
2. move fdset related functions to librte_eal from librte_vhost exposed as
new APIs.
3. release note is added in the patch 5/5.
4. squash data structure change patch into 4/5 according to Maxime's suggestion.

 doc/guides/rel_notes/release_18_05.rst   |   6 ++
 drivers/net/virtio/virtio_user/vhost_user.c  |  45 --
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 101 ---
 drivers/net/virtio/virtio_user/virtio_user_dev.h |   3 +
 drivers/net/virtio/virtio_user_ethdev.c  | 101 ---
 5 files changed, 209 insertions(+), 47 deletions(-)

diff --git a/doc/guides/rel_notes/release_18_05.rst 
b/doc/guides/rel_notes/release_18_05.rst
index 9cc77f893..f8897b2e9 100644
--- a/doc/guides/rel_notes/release_18_05.rst
+++ b/doc/guides/rel_notes/release_18_05.rst
@@ -58,6 +58,12 @@ New Features
   * Added support for NVGRE, VXLAN and GENEVE filters in flow API.
   * Added support for DROP action in flow API.
 
+* **Added support for virtio-user server mode.**
+  In a container environment if the vhost-user backend restarts, there's no way
+  for it to reconnect to virtio-user. To address this, support for server mode
+  is added. In this mode the socket file is created by virtio-user, which the
+  backend connects to. This means that if the backend restarts, it can 
reconnect
+  to virtio-user and continue communications.
 
 API Changes
 ---
diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 91c6449bb..a6df97a00 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -378,6 +378,30 @@ vhost_user_sock(struct virtio_user_dev *dev,
return 0;
 }
 
+#define MAX_VIRTIO_USER_BACKLOG 1
+static int
+virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)
+{
+   int ret;
+   int flag;
+   int fd = dev->listenfd;
+
+   ret = bind(fd, (struct sockaddr *)un, sizeof(*un));
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and try 
again\n",
+   dev->path, strerror(errno));
+   return -1;
+   }
+   ret = listen(fd, MAX_VIRTIO_USER_BACKLOG);
+   if (ret < 0)
+   return -1;
+
+   flag = fcntl(fd, F_GETFL);
+   fcntl(fd, F_SETFL, flag | O_NONBLOCK);
+
+   return 0;
+}
+
 /**
  * Set up environment to talk with a vhost user backend.
  *
@@ -405,13 +429,24 @@ vhost_user_setup(struct virtio_user_dev *dev)
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
-   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
-   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
-   close(fd);
-   return -1;
+
+   if (dev->is_server) {
+   dev->listenfd = fd;
+   if (virtio_user_start_server(dev, &un) < 0) {
+   PMD_DRV_LOG(ERR, "virtio-user startup fails in server 
mode");
+   close(fd);
+   return -1;
+   }
+   dev->vhostfd = -1;
+   } else {
+   

[dpdk-dev] [PATCH v6] net/virtio-user: add support for server mode

2018-04-05 Thread zhiyong . yang
In a container environment if the vhost-user backend restarts, there's
no way for it to reconnect to virtio-user. To address this, support for
server mode is added. In this mode the socket file is created by virtio-
user, which the backend then connects to. This means that if the backend
restarts, it can reconnect to virtio-user and continue communications.

With current implementation, LSC is enabled at virtio-user side to
support to accept the coming connection.

Release note is updated in this patch.

Signed-off-by: Zhiyong Yang 
---

Changes in V6:
1. fix report wrong link stauts in server mode.
2. fix some code style issues.

Changes in V5:
1. Support server mode virtio-user startup in non-blocking mode.
2. rebase on top of dpdk-next-virtio.

Changes in V4:
1. Don't create new pthread any more and use librte_eal interrupt thread.
2. virtio-user doesn't work in blocking mode any more for the first connection.
Client mode vhost-user startups firstly, then server mode virtio-user creates
socket file and startups. Keep consistency with usage of client mode
virtio-user. 

Changes in V3:
1. use EAL epoll mechanism instead of vhost events. Cancel to export vhost
event APIs.
2. rebase the code on top of dpdk-next-virtio

Changes in V2:
1. split two patches 1/5 and 2/5 from v1 patchset to fix some existing issues
which is not strongly related to support for server mode
2. move fdset related functions to librte_eal from librte_vhost exposed as
new APIs.
3. release note is added in the patch 5/5.
4. squash data structure change patch into 4/5 according to Maxime's suggestion.

 doc/guides/rel_notes/release_18_05.rst   |   6 ++
 drivers/net/virtio/virtio_user/vhost_user.c  |  45 --
 drivers/net/virtio/virtio_user/virtio_user_dev.c |  40 +++--
 drivers/net/virtio/virtio_user/virtio_user_dev.h |   3 +
 drivers/net/virtio/virtio_user_ethdev.c  | 101 ---
 5 files changed, 171 insertions(+), 24 deletions(-)

diff --git a/doc/guides/rel_notes/release_18_05.rst 
b/doc/guides/rel_notes/release_18_05.rst
index 9cc77f893..f8897b2e9 100644
--- a/doc/guides/rel_notes/release_18_05.rst
+++ b/doc/guides/rel_notes/release_18_05.rst
@@ -58,6 +58,12 @@ New Features
   * Added support for NVGRE, VXLAN and GENEVE filters in flow API.
   * Added support for DROP action in flow API.
 
+* **Added support for virtio-user server mode.**
+  In a container environment if the vhost-user backend restarts, there's no way
+  for it to reconnect to virtio-user. To address this, support for server mode
+  is added. In this mode the socket file is created by virtio-user, which the
+  backend connects to. This means that if the backend restarts, it can 
reconnect
+  to virtio-user and continue communications.
 
 API Changes
 ---
diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 91c6449bb..a6df97a00 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -378,6 +378,30 @@ vhost_user_sock(struct virtio_user_dev *dev,
return 0;
 }
 
+#define MAX_VIRTIO_USER_BACKLOG 1
+static int
+virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)
+{
+   int ret;
+   int flag;
+   int fd = dev->listenfd;
+
+   ret = bind(fd, (struct sockaddr *)un, sizeof(*un));
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and try 
again\n",
+   dev->path, strerror(errno));
+   return -1;
+   }
+   ret = listen(fd, MAX_VIRTIO_USER_BACKLOG);
+   if (ret < 0)
+   return -1;
+
+   flag = fcntl(fd, F_GETFL);
+   fcntl(fd, F_SETFL, flag | O_NONBLOCK);
+
+   return 0;
+}
+
 /**
  * Set up environment to talk with a vhost user backend.
  *
@@ -405,13 +429,24 @@ vhost_user_setup(struct virtio_user_dev *dev)
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
-   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
-   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
-   close(fd);
-   return -1;
+
+   if (dev->is_server) {
+   dev->listenfd = fd;
+   if (virtio_user_start_server(dev, &un) < 0) {
+   PMD_DRV_LOG(ERR, "virtio-user startup fails in server 
mode");
+   close(fd);
+   return -1;
+   }
+   dev->vhostfd = -1;
+   } else {
+   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
+   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
+   close(fd);
+   return -1;
+   }
+   

[dpdk-dev] [PATCH v5] net/virtio-user: add support for server mode

2018-04-04 Thread zhiyong . yang
In a container environment if the vhost-user backend restarts, there's
no way for it to reconnect to virtio-user. To address this, support for
server mode is added. In this mode the socket file is created by virtio-
user, which the backend then connects to. This means that if the backend
restarts, it can reconnect to virtio-user and continue communications.

With current implementation, LSC is enabled at virtio-user side to
support to accept the coming connection.

Release note is updated in this patch.

Signed-off-by: Zhiyong Yang 
---

Changes in V5:
1. Support server mode virtio-user startup in non-blocking mode.
2. rebase on top of dpdk-next-virtio.

Changes in V4:
1. Don't create new pthread any more and use librte_eal interrupt thread.
2. virtio-user doesn't work in blocking mode any more for the first connection.
Client mode vhost-user startups firstly, then server mode virtio-user creates
socket file and startups. Keep consistency with usage of client mode
virtio-user. 

Changes in V3:
1. use EAL epoll mechanism instead of vhost events. Cancel to export vhost
event APIs.
2. rebase the code on top of dpdk-next-virtio

Changes in V2:
1. split two patches 1/5 and 2/5 from v1 patchset to fix some existing issues
which is not strongly related to support for server mode
2. move fdset related functions to librte_eal from librte_vhost exposed as
new APIs.
3. release note is added in the patch 5/5.
4. squash data structure change patch into 4/5 according to Maxime's suggestion.

 doc/guides/rel_notes/release_18_05.rst   |  6 ++
 drivers/net/virtio/virtio_user/vhost_user.c  | 47 ++--
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 67 ++--
 drivers/net/virtio/virtio_user/virtio_user_dev.h |  3 +
 drivers/net/virtio/virtio_user_ethdev.c  | 98 +---
 5 files changed, 180 insertions(+), 41 deletions(-)

diff --git a/doc/guides/rel_notes/release_18_05.rst 
b/doc/guides/rel_notes/release_18_05.rst
index 9cc77f893..f8897b2e9 100644
--- a/doc/guides/rel_notes/release_18_05.rst
+++ b/doc/guides/rel_notes/release_18_05.rst
@@ -58,6 +58,12 @@ New Features
   * Added support for NVGRE, VXLAN and GENEVE filters in flow API.
   * Added support for DROP action in flow API.
 
+* **Added support for virtio-user server mode.**
+  In a container environment if the vhost-user backend restarts, there's no way
+  for it to reconnect to virtio-user. To address this, support for server mode
+  is added. In this mode the socket file is created by virtio-user, which the
+  backend connects to. This means that if the backend restarts, it can 
reconnect
+  to virtio-user and continue communications.
 
 API Changes
 ---
diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 91c6449bb..f08dfeda9 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -378,6 +378,34 @@ vhost_user_sock(struct virtio_user_dev *dev,
return 0;
 }
 
+#define MAX_VIRTIO_USER_BACKLOG 1
+static int
+virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)
+{
+   int ret;
+   int flag;
+   int fd = dev->listenfd;
+
+   ret = bind(fd, (struct sockaddr *)un, sizeof(*un));
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and try 
again\n",
+   dev->path, strerror(errno));
+   goto err;
+   }
+   ret = listen(fd, MAX_VIRTIO_USER_BACKLOG);
+   if (ret < 0)
+   goto err;
+
+   flag = fcntl(fd, F_GETFL);
+   fcntl(fd, F_SETFL, flag | O_NONBLOCK);
+   dev->vhostfd = -1;
+
+   return 0;
+err:
+   close(dev->listenfd);
+   return -1;
+}
+
 /**
  * Set up environment to talk with a vhost user backend.
  *
@@ -390,6 +418,7 @@ vhost_user_setup(struct virtio_user_dev *dev)
 {
int fd;
int flag;
+   int ret = 0;
struct sockaddr_un un;
 
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -405,14 +434,20 @@ vhost_user_setup(struct virtio_user_dev *dev)
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
-   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
-   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
-   close(fd);
-   return -1;
+
+   if (dev->is_server) {
+   dev->listenfd = fd;
+   ret = virtio_user_start_server(dev, &un);
+   } else {
+   dev->vhostfd = fd;
+   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
+   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
+   close(fd);
+   return -1;
+   }
 

[dpdk-dev] [PATCH v4 0/1] server mode virtio-user

2018-04-03 Thread zhiyong . yang
In a container environment if the vhost-user backend restarts, there's no way
for it to reconnect to virtio-user currently. To address this, support for
server mode is added. In this mode the socket file is created by virtio-user,
which the backend connects to. This means that if the backend restarts, it can
reconnect to virtio-user and continue communications.

The series add support for the feature and target for 18.05 release.

virtio-user adds support for server mode in this patch.

Client mode vhost-user startup firstly, server mode virtio-user startups
and creates the socket file to exchange vhost messages.

If the connection is broken, client mode vhost-user can support to
reconnect virtio-user.

Server mode virtio-user supports many times' vhost-user reconnections with
the same parameter configurations.
 
Virtio-user supports only one connection at the same time in server/client mode.

How to test?
The following scripts are as reference.

step1:
./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3e000 -n 4 --socket-mem 256,0 \
--vdev 'net_vhost0,iface=/tmp/sock0,client=1,queues=1' -- -i --rxq=1 --txq=1 \
--nb-cores=1 --no-numa

step2:
./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3 -n 4 -m 256,0 --no-pci \
--file-prefix=testpmd0 --vdev=net_virtio_user0,mac=00:11:22:33:44:10, \
path=/tmp/sock0,server=1,queues=1 -- -i --rxq=1 --txq=1 --no-numa

step3: at the virtio-user side, run "start"
step4: at the vhost-user side, run "start tx_first 4"

Then you can get the numbers by running "show port stats all" at both sides.

Vhost-user restarts (quit and startup again)and can reconnect virtio-user
successfully again and continue communications.

Changes in V4:
1. Don't create new pthread any more and use librte_eal interrupt thread.
2. virtio-user doesn't work in blocking mode any more for the first connection.
Client mode vhost-user startups firstly, then server mode creates socket file
and startups. Keep consistency with client mode virtio-user. 

Changes in V3:
1. use EAL epoll mechanism instead of vhost events. Cancel to export vhost
event APIs.
2. rebase the code on top of dpdk-next-virtio

Changes in V2:
1. split two patches 1/5 and 2/5 from v1 patchset to fix some existing issues
which is not strongly related to support for server mode
2. move fdset related functions to librte_eal from librte_vhost exposed as
new APIs.
3. release note is added in the patch 5/5.
4. squash data structure change patch into 4/5 according to Maxime's suggestion.


Zhiyong Yang (1):
  net/virtio-user: add support for server mode

 doc/guides/rel_notes/release_18_05.rst   |   6 ++
 drivers/net/virtio/virtio_user/vhost_user.c  |  64 --
 drivers/net/virtio/virtio_user/virtio_user_dev.c |  45 +++---
 drivers/net/virtio/virtio_user/virtio_user_dev.h |   4 +
 drivers/net/virtio/virtio_user_ethdev.c  | 103 +--
 5 files changed, 194 insertions(+), 28 deletions(-)

-- 
2.14.3



[dpdk-dev] [PATCH v4 1/1] net/virtio-user: add support for server mode

2018-04-03 Thread zhiyong . yang
virtio-user adds support for server mode in this patch.

Client mode vhost-user startup firstly, server mode virtio-user startups
and creates the socket file to exchange vhost messages.

If the connection is broken, client mode vhost-user can support to
reconnect virtio-user.

Server mode virtio-user supports many times' vhost-user reconnections with
the same parameter configurations.

Release note is updated in the patch.

Signed-off-by: Zhiyong Yang 
---
 doc/guides/rel_notes/release_18_05.rst   |   6 ++
 drivers/net/virtio/virtio_user/vhost_user.c  |  64 --
 drivers/net/virtio/virtio_user/virtio_user_dev.c |  45 +++---
 drivers/net/virtio/virtio_user/virtio_user_dev.h |   4 +
 drivers/net/virtio/virtio_user_ethdev.c  | 103 +--
 5 files changed, 194 insertions(+), 28 deletions(-)

diff --git a/doc/guides/rel_notes/release_18_05.rst 
b/doc/guides/rel_notes/release_18_05.rst
index 9cc77f893..f8897b2e9 100644
--- a/doc/guides/rel_notes/release_18_05.rst
+++ b/doc/guides/rel_notes/release_18_05.rst
@@ -58,6 +58,12 @@ New Features
   * Added support for NVGRE, VXLAN and GENEVE filters in flow API.
   * Added support for DROP action in flow API.
 
+* **Added support for virtio-user server mode.**
+  In a container environment if the vhost-user backend restarts, there's no way
+  for it to reconnect to virtio-user. To address this, support for server mode
+  is added. In this mode the socket file is created by virtio-user, which the
+  backend connects to. This means that if the backend restarts, it can 
reconnect
+  to virtio-user and continue communications.
 
 API Changes
 ---
diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 91c6449bb..1b3401d4f 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -378,6 +378,50 @@ vhost_user_sock(struct virtio_user_dev *dev,
return 0;
 }
 
+static void
+virtio_user_set_block(int fd, bool enabled)
+{
+   int f;
+
+   f = fcntl(fd, F_GETFL);
+   if (enabled)
+   fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
+   else
+   fcntl(fd, F_SETFL, f | O_NONBLOCK);
+}
+
+#define MAX_VIRTIO_USER_BACKLOG 128
+static int
+virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)
+{
+   int ret;
+   int fd = dev->listenfd;
+   int connectfd;
+
+   ret = bind(fd, (struct sockaddr *)un, sizeof(*un));
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and try 
again\n",
+   dev->path, strerror(errno));
+   goto err;
+   }
+   ret = listen(fd, MAX_VIRTIO_USER_BACKLOG);
+   if (ret < 0)
+   goto err;
+
+   connectfd = accept(fd, NULL, NULL);
+   if (connectfd >= 0)
+   dev->connected = true;
+   else
+   goto err;
+
+   dev->vhostfd = connectfd;
+   virtio_user_set_block(connectfd, true);
+   return 0;
+err:
+   close(dev->listenfd);
+   return -1;
+}
+
 /**
  * Set up environment to talk with a vhost user backend.
  *
@@ -390,6 +434,7 @@ vhost_user_setup(struct virtio_user_dev *dev)
 {
int fd;
int flag;
+   int ret = 0;
struct sockaddr_un un;
 
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -405,14 +450,21 @@ vhost_user_setup(struct virtio_user_dev *dev)
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
-   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
-   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
-   close(fd);
-   return -1;
+
+   if (dev->is_server) {
+   dev->listenfd = fd;
+   ret = virtio_user_start_server(dev, &un);
+   } else {
+   dev->vhostfd = fd;
+   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
+   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
+   close(fd);
+   return -1;
+   }
+   dev->connected = true;
}
 
-   dev->vhostfd = fd;
-   return 0;
+   return ret;
 }
 
 static int
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c 
b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index f90fee9e5..dd9fa9bdf 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -142,6 +142,9 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 {
uint32_t i;
 
+   if (!dev->connected)
+   return -1;
+
for (i = 0; i < dev->max_queue_pairs; ++i)
dev->ops->enable_qp(dev

[dpdk-dev] [PATCH] net/virtio-user: fix port_id type

2018-03-30 Thread zhiyong . yang
virtio-user port_id range should be increased from 8 bits to 16 bits.

Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_user/virtio_user_dev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h 
b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index 64467b4f9..5f8755771 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -31,7 +31,7 @@ struct virtio_user_dev {
   */
uint64_tdevice_features; /* supported features by device */
uint8_t status;
-   uint8_t port_id;
+   uint16_tport_id;
uint8_t mac_addr[ETHER_ADDR_LEN];
charpath[PATH_MAX];
struct vringvrings[VIRTIO_MAX_VIRTQUEUES];
-- 
2.14.3



[dpdk-dev] [PATCH v3 2/4] net/virtio: add checking for cvq

2018-03-20 Thread zhiyong . yang
Add checking for cvq to judge if virtio_ack_link_announce should be called.
The existing code doesn't cause issue, and add the checking just to look
more reasonable.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index f377d8aa3..b567d3cf8 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1337,7 +1337,8 @@ virtio_interrupt_handler(void *param)
 
if (isr & VIRTIO_NET_S_ANNOUNCE) {
virtio_notify_peers(dev);
-   virtio_ack_link_announce(dev);
+   if (hw->cvq)
+   virtio_ack_link_announce(dev);
}
 }
 
-- 
2.14.3



[dpdk-dev] [PATCH v3 3/4] net/virtio-user: add support for server mode

2018-03-20 Thread zhiyong . yang
virtio-user adds support for server mode in this patch.

Virtio-user with server mode creates socket file and then starts to wait
for the first connection from vhost user with client mode in blocking mode.

Server mode virtio-user supports many times' vhost reconnections with
the same configurations.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_user/vhost_user.c  | 96 ++--
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 47 
 drivers/net/virtio/virtio_user/virtio_user_dev.h | 11 +++
 drivers/net/virtio/virtio_user_ethdev.c  | 83 +++-
 4 files changed, 215 insertions(+), 22 deletions(-)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 91c6449bb..90f4fed31 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -378,6 +378,65 @@ vhost_user_sock(struct virtio_user_dev *dev,
return 0;
 }
 
+static void
+virtio_user_set_block(int fd, bool enabled)
+{
+   int f;
+
+   f = fcntl(fd, F_GETFL);
+   if (enabled)
+   fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
+   else
+   fcntl(fd, F_SETFL, f | O_NONBLOCK);
+}
+
+#define MAX_VIRTIO_USER_BACKLOG 128
+static int
+virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)
+{
+   int ret;
+   int fd = dev->listenfd;
+   int connectfd;
+
+   ret = bind(fd, (struct sockaddr *)un, sizeof(*un));
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and try 
again\n",
+   dev->path, strerror(errno));
+   goto err;
+   }
+   ret = listen(fd, MAX_VIRTIO_USER_BACKLOG);
+   if (ret < 0)
+   goto err;
+
+   virtio_user_set_block(fd, true);
+   PMD_DRV_LOG(NOTICE, "virtio user server mode is waiting for connection 
from vhost user.");
+   while (1) {
+   connectfd = accept(fd, NULL, NULL);
+   if (connectfd >= 0) {
+   dev->connected = true;
+   break;
+   }
+   }
+
+   dev->vhostfd = connectfd;
+   virtio_user_set_block(connectfd, true);
+
+   return 0;
+err:
+   close(dev->epoll_fd);
+   close(dev->listenfd);
+   return -1;
+}
+
+static __attribute__((noreturn)) void *
+event_dispatch(void *arg)
+{
+   struct virtio_user_dev *dev = arg;
+
+   while (1)
+   rte_epoll_wait(dev->epoll_fd, &dev->rte_epoll_ev, 128, -1);
+}
+
 /**
  * Set up environment to talk with a vhost user backend.
  *
@@ -390,6 +449,7 @@ vhost_user_setup(struct virtio_user_dev *dev)
 {
int fd;
int flag;
+   int ret;
struct sockaddr_un un;
 
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -405,13 +465,39 @@ vhost_user_setup(struct virtio_user_dev *dev)
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
-   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
-   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
-   close(fd);
-   return -1;
+
+   if (dev->is_server) {
+   static pthread_t fdset_tid;
+
+   dev->listenfd = fd;
+   dev->epoll_fd = rte_intr_tls_epfd();
+   if (dev->epoll_fd < 0) {
+   PMD_DRV_LOG(ERR, "Can't create epoll file descriptor");
+   return -1;
+   }
+   virtio_user_set_block(dev->epoll_fd, true);
+   if (fdset_tid == 0) {
+   ret = pthread_create(&fdset_tid, NULL, event_dispatch,
+dev);
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "failed to create fdset 
handling thread");
+   close(fd);
+   close(dev->epoll_fd);
+   return -1;
+   }
+   }
+   return virtio_user_start_server(dev, &un);
+
+   } else {
+   dev->vhostfd = fd;
+   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
+   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
+   close(fd);
+   return -1;
+   }
+   dev->connected = true;
}
 
-   dev->vhostfd = fd;
return 0;
 }
 
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c 
b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index f90fee9e5..1430b7cbd 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+

[dpdk-dev] [PATCH v3 4/4] net/vhost: add NULL pointer checking

2018-03-20 Thread zhiyong . yang
When vhost user PMD works in client mode to connect/reconnect virtio-user
with server mode, new thread sometimes may run to new_device before
queue_setup has been done, So have to wait until memory allocation is
done.

Release note is updated in the patch.

Signed-off-by: Zhiyong Yang 
---
 doc/guides/rel_notes/release_18_05.rst | 7 +++
 drivers/net/vhost/rte_eth_vhost.c  | 9 +
 2 files changed, 16 insertions(+)

diff --git a/doc/guides/rel_notes/release_18_05.rst 
b/doc/guides/rel_notes/release_18_05.rst
index 3923dc253..7b301f021 100644
--- a/doc/guides/rel_notes/release_18_05.rst
+++ b/doc/guides/rel_notes/release_18_05.rst
@@ -41,6 +41,13 @@ New Features
  Also, make sure to start the actual text at the margin.
  =
 
+* **Added support for virtio-user server mode.**
+
+  In a container environment if the vhost-user backend restarts, there's no way
+  for it to reconnect to virtio-user. To address this, support for server mode
+  is added. In this mode the socket file is created by virtio-user, which the
+  backend then connects to. This means that if the backend restarts, it can
+  reconnect to virtio-user and continue communications.
 
 API Changes
 ---
diff --git a/drivers/net/vhost/rte_eth_vhost.c 
b/drivers/net/vhost/rte_eth_vhost.c
index 3aae01c39..2490bad0b 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -580,6 +580,15 @@ new_device(int vid)
eth_dev->data->numa_node = newnode;
 #endif
 
+   /* The thread may run here before eth_dev->data->rx_queues or
+* eth_dev->data->tx_queues have gotten valid memory, so have to
+* wait until memory allocation is done.
+*/
+   while (!eth_dev->data->rx_queues ||
+  !eth_dev->data->tx_queues) {
+   usleep(1);
+   }
+
for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
vq = eth_dev->data->rx_queues[i];
if (vq == NULL)
-- 
2.14.3



[dpdk-dev] [PATCH v3 1/4] net/virtio: fix add pointer checking

2018-03-20 Thread zhiyong . yang
It is necessary to add pointer checking because in some case the
code will cause crash. For example, the code goes here before
memory allocation of rxvq is finished.

Fixes: 7365504f77e3("net/virtio: support guest announce")
Cc: sta...@dpdk.org
Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_ethdev.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index 884f74ad0..f377d8aa3 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1273,9 +1273,13 @@ static void
 virtio_notify_peers(struct rte_eth_dev *dev)
 {
struct virtio_hw *hw = dev->data->dev_private;
-   struct virtnet_rx *rxvq = dev->data->rx_queues[0];
+   struct virtnet_rx *rxvq;
struct rte_mbuf *rarp_mbuf;
 
+   if (!dev->data->rx_queues)
+   return;
+
+   rxvq = dev->data->rx_queues[0];
rarp_mbuf = rte_net_make_rarp_packet(rxvq->mpool,
(struct ether_addr *)hw->mac_addr);
if (rarp_mbuf == NULL) {
-- 
2.14.3



[dpdk-dev] [PATCH v3 0/4] add support for virtio-user server mode

2018-03-20 Thread zhiyong . yang
In a container environment if the vhost-user backend restarts, there's no way
for it to reconnect to virtio-user currently. To address this, support for
server mode is added. In this mode the socket file is created by virtio-user,
which the backend then connects to. This means that if the backend restarts,
it can reconnect to virtio-user and continue communications.

The series add support for the feature and target for 18.05 release.

Virtio-user with server mode creates socket file and then starts to wait for the
first connection from vhost user with client mode in blocking mode.

Virtio-user with server mode supports many times' vhost reconnections with the
same configurations. 

Virtio-user supports only one connection at the same time in server/client mode.

How to test?
The following scripts are as reference.

./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3 -n 4 -m 256,0 --no-pci \
--file-prefix=testpmd0 --vdev=net_virtio_user0,mac=00:11:22:33:44:10, \
path=/tmp/sock0,server=1,queues=1 -- -i --rxq=1 --txq=1 --no-numa

./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3e000 -n 4 --socket-mem 256,0 \
--vdev 'net_vhost0,iface=/tmp/sock0,client=1,queues=1' -- -i --rxq=1 --txq=1 \
--nb-cores=1 --no-numa

step1 : at the virtio-user side, run "start"
step2: at the vhost-user side run "start tx_first 4"

Then you can get the numbers by running "show port stats all" at both sides.

Changes in V3:
1. use EAL epoll mechanism instead of vhost events. Cancel to export vhost
event APIs.
2. rebase the code on top of dpdk-next-virtio

Changes in V2:
1. split two patches 1/5 and 2/5 from v1 patchset to fix some existing issues
which is not strongly related to support for server mode according to Maxime's
comments.
2. move fdset related functions to librte_eal from librte_vhost exposed as
new APIs according to Thomas' comments.
3. release note is added in the patch 5/5.
4. squash data structure change patch into 4/5 according to Maxime's suggestion.

Zhiyong Yang (4):
  net/virtio: fix add pointer checking
  net/virtio: add checking for cvq
  net/virtio-user: add support for server mode
  net/vhost: add NULL pointer checking

 doc/guides/rel_notes/release_18_05.rst   |  7 ++
 drivers/net/vhost/rte_eth_vhost.c|  9 +++
 drivers/net/virtio/virtio_ethdev.c   |  9 ++-
 drivers/net/virtio/virtio_user/vhost_user.c  | 96 ++--
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 47 
 drivers/net/virtio/virtio_user/virtio_user_dev.h | 11 +++
 drivers/net/virtio/virtio_user_ethdev.c  | 83 +++-
 7 files changed, 238 insertions(+), 24 deletions(-)

-- 
2.14.3



[dpdk-dev] [PATCH v2 5/5] net/vhost: add memory checking

2018-03-15 Thread zhiyong . yang
When vhost user PMD works in client mode to connect/reconnect virtio-user
with server mode, new thread sometimes may run to new_device before
queue_setup has been done, So have to wait until memory allocation is
done.

Release note is updated in the patch.

Signed-off-by: Zhiyong Yang 
---
 doc/guides/rel_notes/release_18_05.rst | 7 +++
 drivers/net/vhost/rte_eth_vhost.c  | 9 +
 2 files changed, 16 insertions(+)

diff --git a/doc/guides/rel_notes/release_18_05.rst 
b/doc/guides/rel_notes/release_18_05.rst
index 3923dc253..7b301f021 100644
--- a/doc/guides/rel_notes/release_18_05.rst
+++ b/doc/guides/rel_notes/release_18_05.rst
@@ -41,6 +41,13 @@ New Features
  Also, make sure to start the actual text at the margin.
  =
 
+* **Added support for virtio-user server mode.**
+
+  In a container environment if the vhost-user backend restarts, there's no way
+  for it to reconnect to virtio-user. To address this, support for server mode
+  is added. In this mode the socket file is created by virtio-user, which the
+  backend then connects to. This means that if the backend restarts, it can
+  reconnect to virtio-user and continue communications.
 
 API Changes
 ---
diff --git a/drivers/net/vhost/rte_eth_vhost.c 
b/drivers/net/vhost/rte_eth_vhost.c
index 3aae01c39..2490bad0b 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -580,6 +580,15 @@ new_device(int vid)
eth_dev->data->numa_node = newnode;
 #endif
 
+   /* The thread may run here before eth_dev->data->rx_queues or
+* eth_dev->data->tx_queues have gotten valid memory, so have to
+* wait until memory allocation is done.
+*/
+   while (!eth_dev->data->rx_queues ||
+  !eth_dev->data->tx_queues) {
+   usleep(1);
+   }
+
for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
vq = eth_dev->data->rx_queues[i];
if (vq == NULL)
-- 
2.14.3



[dpdk-dev] [PATCH v2 4/5] net/virtio-user: add support for server mode

2018-03-15 Thread zhiyong . yang
virtio-user adds support for server mode in this patch.

Virtio-user with server mode creates socket file and then starts to wait
for the first connection from vhost user with client mode in blocking mode.

Server mode virtio-user supports many times' vhost reconnections with
same configurations.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_user/vhost_user.c  | 77 --
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 44 +
 drivers/net/virtio/virtio_user/virtio_user_dev.h |  8 +++
 drivers/net/virtio/virtio_user_ethdev.c  | 82 ++--
 4 files changed, 188 insertions(+), 23 deletions(-)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 91c6449bb..cd30f713a 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -378,6 +378,55 @@ vhost_user_sock(struct virtio_user_dev *dev,
return 0;
 }
 
+static void
+virtio_user_set_block(int fd, bool enabled)
+{
+   int f;
+
+   f = fcntl(fd, F_GETFL);
+   if (enabled)
+   fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
+   else
+   fcntl(fd, F_SETFL, f | O_NONBLOCK);
+}
+
+#define MAX_VIRTIO_USER_BACKLOG 128
+static int
+virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)
+{
+   int ret;
+   int fd = dev->listenfd;
+   int connectfd;
+
+   ret = bind(fd, (struct sockaddr *)un, sizeof(*un));
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and try 
again\n",
+   dev->path, strerror(errno));
+   goto err;
+   }
+   ret = listen(fd, MAX_VIRTIO_USER_BACKLOG);
+   if (ret < 0)
+   goto err;
+
+   virtio_user_set_block(fd, true);
+   PMD_DRV_LOG(NOTICE, "virtio user server mode is waiting for connection 
from vhost user.");
+   while (1) {
+   connectfd = accept(fd, NULL, NULL);
+   if (connectfd >= 0) {
+   dev->connected = true;
+   break;
+   }
+   }
+
+   dev->vhostfd = connectfd;
+   virtio_user_set_block(connectfd, true);
+
+   return 0;
+err:
+   close(fd);
+   return -1;
+}
+
 /**
  * Set up environment to talk with a vhost user backend.
  *
@@ -390,6 +439,7 @@ vhost_user_setup(struct virtio_user_dev *dev)
 {
int fd;
int flag;
+   int ret;
struct sockaddr_un un;
 
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -405,13 +455,30 @@ vhost_user_setup(struct virtio_user_dev *dev)
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
-   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
-   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
-   close(fd);
-   return -1;
+
+   if (dev->is_server) {
+   static pthread_t fdset_tid;
+
+   dev->listenfd = fd;
+   if (fdset_tid == 0) {
+   ret = pthread_create(&fdset_tid, NULL,
+rte_fdset_event_dispatch,
+&dev->fdset);
+   if (ret < 0)
+   PMD_DRV_LOG(ERR, "failed to create fdset 
handling thread");
+   }
+   return virtio_user_start_server(dev, &un);
+
+   } else {
+   dev->vhostfd = fd;
+   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
+   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
+   close(fd);
+   return -1;
+   }
+   dev->connected = true;
}
 
-   dev->vhostfd = fd;
return 0;
 }
 
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c 
b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index f90fee9e5..23312344f 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -142,6 +142,9 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 {
uint32_t i;
 
+   if (!dev->connected)
+   return -1;
+
for (i = 0; i < dev->max_queue_pairs; ++i)
dev->ops->enable_qp(dev, i, 0);
 
@@ -267,21 +270,27 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
dev->vhostfds = NULL;
dev->tapfds = NULL;
 
-   if (is_vhost_user_by_type(dev->path)) {
-   dev->ops = &ops_user;
+   if (dev->is_server) {
+   dev->ops = &ops_user;/* server mode only supports vhost user */
} else {

[dpdk-dev] [PATCH v2 3/5] eal: expose fdset related APIs

2018-03-15 Thread zhiyong . yang
The patch moves fdset related functions from lib vhost to lib eal and
expose them as new APIs in order that they can be reused.
Just move the code to the new place "eal_interrupts.c" and add prefix
"rte_ " to functions name, and don't change any functionality.

Librte_vhost changes new function names accordingly when invoking.
Remove the files fd_man.h and fd_man.c and remove fd_mac.c from Makefile
from librte_vhost.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_eal/common/include/rte_eal_interrupts.h |  56 +
 lib/librte_eal/linuxapp/eal/eal_interrupts.c   | 257 +++
 lib/librte_eal/rte_eal_version.map |  10 +
 lib/librte_vhost/Makefile  |   2 +-
 lib/librte_vhost/fd_man.c  | 274 -
 lib/librte_vhost/fd_man.h  |  40 ---
 lib/librte_vhost/socket.c  |  22 +-
 7 files changed, 336 insertions(+), 325 deletions(-)
 delete mode 100644 lib/librte_vhost/fd_man.c
 delete mode 100644 lib/librte_vhost/fd_man.h

diff --git a/lib/librte_eal/common/include/rte_eal_interrupts.h 
b/lib/librte_eal/common/include/rte_eal_interrupts.h
index 3f792a97f..1886d0dd0 100644
--- a/lib/librte_eal/common/include/rte_eal_interrupts.h
+++ b/lib/librte_eal/common/include/rte_eal_interrupts.h
@@ -17,6 +17,9 @@
 #ifndef _RTE_EAL_INTERRUPTS_H_
 #define _RTE_EAL_INTERRUPTS_H_
 
+#include 
+#include "rte_compat.h"
+
 #define RTE_MAX_RXTX_INTR_VEC_ID 32
 #define RTE_INTR_VEC_ZERO_OFFSET  0
 #define RTE_INTR_VEC_RXTX_OFFSET  1
@@ -82,6 +85,24 @@ struct rte_intr_handle {
 };
 
 #define RTE_EPOLL_PER_THREAD-1  /**< to hint using per thread epfd */
+#define RTE_MAX_FDS 1024
+
+typedef void (*fd_cb)(int fd, void *dat, int *remove);
+
+struct rte_fdentry {
+   int fd; /* -1 indicates this entry is empty */
+   fd_cb rcb;  /* callback when this fd is readable. */
+   fd_cb wcb;  /* callback when this fd is writeable.*/
+   void *dat;  /* fd context */
+   int busy;   /* whether this entry is being used in cb. */
+};
+
+struct rte_fdset {
+   struct pollfd rwfds[RTE_MAX_FDS];
+   struct rte_fdentry fd[RTE_MAX_FDS];
+   pthread_mutex_t fd_mutex;
+   int num;/* current fd number of this fdset */
+};
 
 /**
  * It waits for events on the epoll instance.
@@ -218,4 +239,39 @@ rte_intr_allow_others(struct rte_intr_handle *intr_handle);
 int
 rte_intr_cap_multiple(struct rte_intr_handle *intr_handle);
 
+/**
+ * Initialize struct rte_fdset.
+ *
+ * @param intr_handle
+ *   Pointer to struct rte_fdset.
+ */
+void __rte_experimental
+rte_fdset_init(struct rte_fdset *pfdset);
+
+/**
+ * Register the fd in the fdset with read/write handler and context.
+ *
+ * @param intr_handle
+ *   Pointer to struct rte_fdset.
+ */
+int __rte_experimental
+rte_fdset_add(struct rte_fdset *pfdset, int fd,
+   fd_cb rcb, fd_cb wcb, void *dat);
+
+/**
+ * Unregister the fd in the fdset.
+ *
+ * @param intr_handle
+ *   Pointer to struct rte_fdset.
+ */
+void * __rte_experimental
+rte_fdset_del(struct rte_fdset *pfdset, int fd);
+
+/**
+ * This functions runs in infinite blocking loop until there is no fd in
+ * pfdset. It calls corresponding r/w handler if there is event on the fd.
+ */
+void * __rte_experimental
+rte_fdset_event_dispatch(void *arg);
+
 #endif /* _RTE_EAL_INTERRUPTS_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c 
b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
index f86f22f7b..95a382525 100644
--- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c
+++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
@@ -1230,3 +1230,260 @@ rte_intr_cap_multiple(struct rte_intr_handle 
*intr_handle)
 
return 0;
 }
+
+#define FDPOLLERR (POLLERR | POLLHUP | POLLNVAL)
+
+static int
+get_last_valid_idx(struct rte_fdset *pfdset, int last_valid_idx)
+{
+   int i;
+
+   for (i = last_valid_idx; i >= 0 && pfdset->fd[i].fd == -1; i--)
+   ;
+
+   return i;
+}
+
+static void
+fdset_move(struct rte_fdset *pfdset, int dst, int src)
+{
+   pfdset->fd[dst]= pfdset->fd[src];
+   pfdset->rwfds[dst] = pfdset->rwfds[src];
+}
+
+static void
+fdset_shrink_nolock(struct rte_fdset *pfdset)
+{
+   int i;
+   int last_valid_idx = get_last_valid_idx(pfdset, pfdset->num - 1);
+
+   for (i = 0; i < last_valid_idx; i++) {
+   if (pfdset->fd[i].fd != -1)
+   continue;
+
+   fdset_move(pfdset, i, last_valid_idx);
+   last_valid_idx = get_last_valid_idx(pfdset, last_valid_idx - 1);
+   }
+   pfdset->num = last_valid_idx + 1;
+}
+
+/*
+ * Find deleted fd entries and remove them
+ */
+static void
+fdset_shrink(struct rte_fdset *pfdset)
+{
+   pthread_mutex_lock(&pfdset->fd_mutex);
+   fdset_shrink_nolock(pfdset);
+   pthread_mutex_unlock(&pfds

[dpdk-dev] [PATCH v2 1/5] net/virtio: fix add pointer checking

2018-03-15 Thread zhiyong . yang
It is necessary to add pointer checking because in some case the
code will cause crash.
For example,
The code goes here before memory allocation of rxvq is done.

Fixes: 7365504f77e3("net/virtio: support guest announce")
Cc: sta...@dpdk.org
Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_ethdev.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index 884f74ad0..b38582c8d 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1273,9 +1273,14 @@ static void
 virtio_notify_peers(struct rte_eth_dev *dev)
 {
struct virtio_hw *hw = dev->data->dev_private;
-   struct virtnet_rx *rxvq = dev->data->rx_queues[0];
+   struct virtnet_rx *rxvq;
struct rte_mbuf *rarp_mbuf;
 
+   if (!dev->data->rx_queues)
+   return;
+
+   rxvq = dev->data->rx_queues[0];
+
rarp_mbuf = rte_net_make_rarp_packet(rxvq->mpool,
(struct ether_addr *)hw->mac_addr);
if (rarp_mbuf == NULL) {
-- 
2.14.3



[dpdk-dev] [PATCH v2 2/5] net/virtio: add checking for cvq

2018-03-15 Thread zhiyong . yang
Add checking for cvq to judge if virtio_ack_link_announce is called.
The original code doesn't cause issue, and add the checking just to look
more reasonable.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index b38582c8d..74943a5a9 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1338,7 +1338,8 @@ virtio_interrupt_handler(void *param)
 
if (isr & VIRTIO_NET_S_ANNOUNCE) {
virtio_notify_peers(dev);
-   virtio_ack_link_announce(dev);
+   if (hw->cvq)
+   virtio_ack_link_announce(dev);
}
 }
 
-- 
2.14.3



[dpdk-dev] [PATCH v2 0/5] add support for virtio-user server mode

2018-03-15 Thread zhiyong . yang
In a container environment if the vhost-user backend restarts, there's no way
for it to reconnect to virtio-user currently. To address this, support for
server mode is added. In this mode the socket file is created by virtio-user,
which the backend then connects to. This means that if the backend restarts,
it can reconnect to virtio-user and continue communications.

The series add support for the feature and target for 18.05 release.

Virtio-user with server mode creates socket file and then starts to wait for the
first connection from vhost user with client mode in blocking mode.

Virtio-user with server mode supports many times' vhost reconnections with same 
configurations. 

Virtio-user supports only one connection at the same time in server/client mode.

How to test?
The following scripts are as reference.

./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3 -n 4 -m 256,0 --no-pci \
--file-prefix=testpmd0 --vdev=net_virtio_user0,mac=00:11:22:33:44:10, \
path=/tmp/sock0,server=1,queues=1 -- -i --rxq=1 --txq=1 --no-numa

./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3e000 -n 4 --socket-mem 256,0 \
--vdev 'net_vhost0,iface=/tmp/sock0,client=1,queues=1' -- -i --rxq=1 --txq=1 \
--nb-cores=1 --no-numa

step1 : at the virio-user side, run "start"
step2: at the vhost-user side run "start tx_first 4"

Changes in V2:
1. split two patch 1/5 and 2/5 from v1 patchset to fix some existing issues 
which is not
strongly related to support for server mode according to Maxime's comments.
2. move fdset related functions to librte_eal from librte_vhost exposed as
new APIs according to Thomas' comments.
3. release note is added in the patch 5/5.
4. squash data structure change patch into 4/5 according to Maxime's suggestion.

Zhiyong Yang (5):
  net/virtio: fix add pointer checking
  net/virtio: add checking for cvq
  eal: expose fdset related APIs
  net/virtio-user: add support for server mode
  net/vhost: add memory checking

 doc/guides/rel_notes/release_18_05.rst |   7 +
 drivers/net/vhost/rte_eth_vhost.c  |   9 +
 drivers/net/virtio/virtio_ethdev.c |  10 +-
 drivers/net/virtio/virtio_user/vhost_user.c|  77 +-
 drivers/net/virtio/virtio_user/virtio_user_dev.c   |  44 ++--
 drivers/net/virtio/virtio_user/virtio_user_dev.h   |   8 +
 drivers/net/virtio/virtio_user_ethdev.c|  82 +-
 lib/librte_eal/common/include/rte_eal_interrupts.h |  56 +
 lib/librte_eal/linuxapp/eal/eal_interrupts.c   | 257 +++
 lib/librte_eal/rte_eal_version.map |  10 +
 lib/librte_vhost/Makefile  |   2 +-
 lib/librte_vhost/fd_man.c  | 274 -
 lib/librte_vhost/fd_man.h  |  40 ---
 lib/librte_vhost/socket.c  |  22 +-
 14 files changed, 548 insertions(+), 350 deletions(-)
 delete mode 100644 lib/librte_vhost/fd_man.c
 delete mode 100644 lib/librte_vhost/fd_man.h

-- 
2.14.3



[dpdk-dev] [PATCH 5/5] net/sfc: remove void pointer cast

2018-02-26 Thread Zhiyong Yang
Cc: arybche...@solarflare.com 
Signed-off-by: Zhiyong Yang 
---
 drivers/net/sfc/sfc_flow.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/sfc/sfc_flow.c b/drivers/net/sfc/sfc_flow.c
index 93cdf8f4c..eb555c324 100644
--- a/drivers/net/sfc/sfc_flow.c
+++ b/drivers/net/sfc/sfc_flow.c
@@ -115,13 +115,13 @@ sfc_flow_parse_init(const struct rte_flow_item *item,
return -rte_errno;
}
 
-   mask = (const uint8_t *)def_mask;
+   mask = def_mask;
} else {
-   mask = (const uint8_t *)item->mask;
+   mask = item->mask;
}
 
-   spec = (const uint8_t *)item->spec;
-   last = (const uint8_t *)item->last;
+   spec = item->spec;
+   last = item->last;
 
if (spec == NULL)
goto exit;
-- 
2.13.3



[dpdk-dev] [PATCH 4/5] net/bnxt: remove void pointer cast

2018-02-26 Thread Zhiyong Yang
Cc: ajit.khapa...@broadcom.com
Cc: somnath.ko...@broadcom.com
Signed-off-by: Zhiyong Yang 
---
 drivers/net/bnxt/bnxt_filter.c | 44 --
 1 file changed, 17 insertions(+), 27 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_filter.c b/drivers/net/bnxt/bnxt_filter.c
index 032e8eed0..bbaae1a07 100644
--- a/drivers/net/bnxt/bnxt_filter.c
+++ b/drivers/net/bnxt/bnxt_filter.c
@@ -354,8 +354,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp,
}
switch (item->type) {
case RTE_FLOW_ITEM_TYPE_ETH:
-   eth_spec = (const struct rte_flow_item_eth *)item->spec;
-   eth_mask = (const struct rte_flow_item_eth *)item->mask;
+   eth_spec = item->spec;
+   eth_mask = item->mask;
 
/* Source MAC address mask cannot be partially set.
 * Should be All 0's or all 1's.
@@ -410,10 +410,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp,
 
break;
case RTE_FLOW_ITEM_TYPE_VLAN:
-   vlan_spec =
-   (const struct rte_flow_item_vlan *)item->spec;
-   vlan_mask =
-   (const struct rte_flow_item_vlan *)item->mask;
+   vlan_spec = item->spec;
+   vlan_mask = item->mask;
if (vlan_mask->tci & 0x && !vlan_mask->tpid) {
/* Only the VLAN ID can be matched. */
filter->l2_ovlan =
@@ -431,10 +429,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp,
break;
case RTE_FLOW_ITEM_TYPE_IPV4:
/* If mask is not involved, we could use EM filters. */
-   ipv4_spec =
-   (const struct rte_flow_item_ipv4 *)item->spec;
-   ipv4_mask =
-   (const struct rte_flow_item_ipv4 *)item->mask;
+   ipv4_spec = item->spec;
+   ipv4_mask = item->mask;
/* Only IP DST and SRC fields are maskable. */
if (ipv4_mask->hdr.version_ihl ||
ipv4_mask->hdr.type_of_service ||
@@ -483,10 +479,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp,
}
break;
case RTE_FLOW_ITEM_TYPE_IPV6:
-   ipv6_spec =
-   (const struct rte_flow_item_ipv6 *)item->spec;
-   ipv6_mask =
-   (const struct rte_flow_item_ipv6 *)item->mask;
+   ipv6_spec = item->spec;
+   ipv6_mask = item->mask;
 
/* Only IP DST and SRC fields are maskable. */
if (ipv6_mask->hdr.vtc_flow ||
@@ -527,8 +521,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp,
EM_FLOW_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
break;
case RTE_FLOW_ITEM_TYPE_TCP:
-   tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
-   tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
+   tcp_spec = item->spec;
+   tcp_mask = item->mask;
 
/* Check TCP mask. Only DST & SRC ports are maskable */
if (tcp_mask->hdr.sent_seq ||
@@ -564,8 +558,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp,
}
break;
case RTE_FLOW_ITEM_TYPE_UDP:
-   udp_spec = (const struct rte_flow_item_udp *)item->spec;
-   udp_mask = (const struct rte_flow_item_udp *)item->mask;
+   udp_spec = item->spec;
+   udp_mask = item->mask;
 
if (udp_mask->hdr.dgram_len ||
udp_mask->hdr.dgram_cksum) {
@@ -597,10 +591,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp,
}
break;
case RTE_FLOW_ITEM_TYPE_VXLAN:
-   vxlan_spec =
-   (const struct rte_flow_item_vxlan *)item->spec;
-   vxlan_mask =
-   (const struct rte_flow_item_vxlan *)item->mask;
+   vxlan_spec = item->spec;
+   vxlan_mask = item->mask;
/* Check if VXLAN item is used to describe protocol.
 * If yes, both spec and mask should be NULL.
  

[dpdk-dev] [PATCH 3/5] net/e1000: remove void pointer cast

2018-02-26 Thread Zhiyong Yang
Cc: wenzhuo...@intel.com
Signed-off-by: Zhiyong Yang 
---
 drivers/net/e1000/igb_flow.c | 27 +--
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
index a14275968..c0f5b5190 100644
--- a/drivers/net/e1000/igb_flow.c
+++ b/drivers/net/e1000/igb_flow.c
@@ -175,7 +175,7 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
return -rte_errno;
}
 
-   ipv4_mask = (const struct rte_flow_item_ipv4 *)item->mask;
+   ipv4_mask = item->mask;
/**
 * Only support src & dst addresses, protocol,
 * others should be masked.
@@ -198,7 +198,7 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
filter->src_ip_mask = ipv4_mask->hdr.src_addr;
filter->proto_mask  = ipv4_mask->hdr.next_proto_id;
 
-   ipv4_spec = (const struct rte_flow_item_ipv4 *)item->spec;
+   ipv4_spec = item->spec;
filter->dst_ip = ipv4_spec->hdr.dst_addr;
filter->src_ip = ipv4_spec->hdr.src_addr;
filter->proto  = ipv4_spec->hdr.next_proto_id;
@@ -228,7 +228,7 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
/* get the TCP/UDP/SCTP info */
if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
if (item->spec && item->mask) {
-   tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
+   tcp_mask = item->mask;
 
/**
 * Only support src & dst ports, tcp flags,
@@ -263,14 +263,14 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
return -rte_errno;
}
 
-   tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
+   tcp_spec = item->spec;
filter->dst_port  = tcp_spec->hdr.dst_port;
filter->src_port  = tcp_spec->hdr.src_port;
filter->tcp_flags = tcp_spec->hdr.tcp_flags;
}
} else if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
if (item->spec && item->mask) {
-   udp_mask = (const struct rte_flow_item_udp *)item->mask;
+   udp_mask = item->mask;
 
/**
 * Only support src & dst ports,
@@ -289,14 +289,13 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
filter->dst_port_mask = udp_mask->hdr.dst_port;
filter->src_port_mask = udp_mask->hdr.src_port;
 
-   udp_spec = (const struct rte_flow_item_udp *)item->spec;
+   udp_spec = item->spec;
filter->dst_port = udp_spec->hdr.dst_port;
filter->src_port = udp_spec->hdr.src_port;
}
} else {
if (item->spec && item->mask) {
-   sctp_mask = (const struct rte_flow_item_sctp *)
-   item->mask;
+   sctp_mask = item->mask;
 
/**
 * Only support src & dst ports,
@@ -533,8 +532,8 @@ cons_parse_ethertype_filter(const struct rte_flow_attr 
*attr,
return -rte_errno;
}
 
-   eth_spec = (const struct rte_flow_item_eth *)item->spec;
-   eth_mask = (const struct rte_flow_item_eth *)item->mask;
+   eth_spec = item->spec;
+   eth_mask = item->mask;
 
/* Mask bits of source MAC address must be full of 0.
 * Mask bits of destination MAC address must be full
@@ -848,8 +847,8 @@ cons_parse_syn_filter(const struct rte_flow_attr *attr,
return -rte_errno;
}
 
-   tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
-   tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
+   tcp_spec = item->spec;
+   tcp_mask = item->mask;
if (!(tcp_spec->hdr.tcp_flags & TCP_SYN_FLAG) ||
tcp_mask->hdr.src_port ||
tcp_mask->hdr.dst_port ||
@@ -1065,8 +1064,8 @@ cons_parse_flex_filter(const struct rte_flow_attr *attr,
return -rte_errno;
}
 
-   raw_spec = (const struct rte_flow_item_raw *)item->spec;
-   raw_mask = (const struct rte_flow_item_raw *)item->mask;
+   raw_spec = item->spec;
+   raw_mask = item->mask;
 
if (!raw_mask->length ||
!raw_mask->relative) {
-- 
2.13.3



[dpdk-dev] [PATCH 2/5] net/ixgbe: remove void pointer cast

2018-02-26 Thread Zhiyong Yang
Cc: wenzhuo...@intel.com
Cc: konstantin.anan...@intel.com
Signed-off-by: Zhiyong Yang 
---
 drivers/net/ixgbe/ixgbe_flow.c | 106 ++---
 1 file changed, 46 insertions(+), 60 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_flow.c b/drivers/net/ixgbe/ixgbe_flow.c
index dcbfb38b3..abdeac28b 100644
--- a/drivers/net/ixgbe/ixgbe_flow.c
+++ b/drivers/net/ixgbe/ixgbe_flow.c
@@ -264,8 +264,8 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
}
/* Skip Ethernet */
if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
-   eth_spec = (const struct rte_flow_item_eth *)item->spec;
-   eth_mask = (const struct rte_flow_item_eth *)item->mask;
+   eth_spec = item->spec;
+   eth_mask = item->mask;
/*Not supported last point for range*/
if (item->last) {
rte_flow_error_set(error,
@@ -298,8 +298,8 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
}
 
if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
-   vlan_spec = (const struct rte_flow_item_vlan *)item->spec;
-   vlan_mask = (const struct rte_flow_item_vlan *)item->mask;
+   vlan_spec = item->spec;
+   vlan_mask = item->mask;
/*Not supported last point for range*/
if (item->last) {
rte_flow_error_set(error,
@@ -346,7 +346,7 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
return -rte_errno;
}
 
-   ipv4_mask = (const struct rte_flow_item_ipv4 *)item->mask;
+   ipv4_mask = item->mask;
/**
 * Only support src & dst addresses, protocol,
 * others should be masked.
@@ -368,7 +368,7 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
filter->src_ip_mask = ipv4_mask->hdr.src_addr;
filter->proto_mask  = ipv4_mask->hdr.next_proto_id;
 
-   ipv4_spec = (const struct rte_flow_item_ipv4 *)item->spec;
+   ipv4_spec = item->spec;
filter->dst_ip = ipv4_spec->hdr.dst_addr;
filter->src_ip = ipv4_spec->hdr.src_addr;
filter->proto  = ipv4_spec->hdr.next_proto_id;
@@ -413,7 +413,7 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
}
 
if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
-   tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
+   tcp_mask = item->mask;
 
/**
 * Only support src & dst ports, tcp flags,
@@ -447,12 +447,12 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
return -rte_errno;
}
 
-   tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
+   tcp_spec = item->spec;
filter->dst_port  = tcp_spec->hdr.dst_port;
filter->src_port  = tcp_spec->hdr.src_port;
filter->tcp_flags = tcp_spec->hdr.tcp_flags;
} else if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
-   udp_mask = (const struct rte_flow_item_udp *)item->mask;
+   udp_mask = item->mask;
 
/**
 * Only support src & dst ports,
@@ -471,11 +471,11 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
filter->dst_port_mask = udp_mask->hdr.dst_port;
filter->src_port_mask = udp_mask->hdr.src_port;
 
-   udp_spec = (const struct rte_flow_item_udp *)item->spec;
+   udp_spec = item->spec;
filter->dst_port = udp_spec->hdr.dst_port;
filter->src_port = udp_spec->hdr.src_port;
} else if (item->type == RTE_FLOW_ITEM_TYPE_SCTP) {
-   sctp_mask = (const struct rte_flow_item_sctp *)item->mask;
+   sctp_mask = item->mask;
 
/**
 * Only support src & dst ports,
@@ -494,7 +494,7 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
filter->dst_port_mask = sctp_mask->hdr.dst_port;
filter->src_port_mask = sctp_mask->hdr.src_port;
 
-   sctp_spec = (const struct rte_flow_item_sctp *)item->spec;
+   sctp_spec = item->spec;
filter->dst_port = sctp_spec->hdr.dst_port;
filter->src_port = sctp_spec->hdr.src_port;
} else {
@@ -699,8 +699,8 @@ cons_parse_ethertype_filter(const struct rte_flow_attr 
*attr,
return -rte_errno;
}
 
-   eth_spec = (const struct rte_flow_item_eth *)item->spec;
-   eth_mask = (const struct rte_flow_item_eth *)item->

[dpdk-dev] [PATCH 1/5] flow_classify: remove void pointer cast

2018-02-26 Thread Zhiyong Yang
Cc: bernard.iremon...@intel.com
Signed-off-by: Zhiyong Yang 
---
 lib/librte_flow_classify/rte_flow_classify.c   |  4 +---
 lib/librte_flow_classify/rte_flow_classify_parse.c | 24 +++---
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/lib/librte_flow_classify/rte_flow_classify.c 
b/lib/librte_flow_classify/rte_flow_classify.c
index 7edb2f15f..591d98e25 100644
--- a/lib/librte_flow_classify/rte_flow_classify.c
+++ b/lib/librte_flow_classify/rte_flow_classify.c
@@ -635,9 +635,7 @@ action_apply(struct rte_flow_classifier *cls,
}
if (count) {
ret = 0;
-   ntuple_stats =
-   (struct rte_flow_classify_ipv4_5tuple_stats *)
-   stats->stats;
+   ntuple_stats = stats->stats;
ntuple_stats->counter1 = count;
ntuple_stats->ipv4_5tuple = rule->rules.u.ipv4_5tuple;
}
diff --git a/lib/librte_flow_classify/rte_flow_classify_parse.c 
b/lib/librte_flow_classify/rte_flow_classify_parse.c
index 10eaf0435..f65ceaf7c 100644
--- a/lib/librte_flow_classify/rte_flow_classify_parse.c
+++ b/lib/librte_flow_classify/rte_flow_classify_parse.c
@@ -279,7 +279,7 @@ classify_parse_ntuple_filter(const struct rte_flow_attr 
*attr,
 
}
 
-   ipv4_mask = (const struct rte_flow_item_ipv4 *)item->mask;
+   ipv4_mask = item->mask;
/**
 * Only support src & dst addresses, protocol,
 * others should be masked.
@@ -301,7 +301,7 @@ classify_parse_ntuple_filter(const struct rte_flow_attr 
*attr,
filter->src_ip_mask = ipv4_mask->hdr.src_addr;
filter->proto_mask  = ipv4_mask->hdr.next_proto_id;
 
-   ipv4_spec = (const struct rte_flow_item_ipv4 *)item->spec;
+   ipv4_spec = item->spec;
filter->dst_ip = ipv4_spec->hdr.dst_addr;
filter->src_ip = ipv4_spec->hdr.src_addr;
filter->proto  = ipv4_spec->hdr.next_proto_id;
@@ -339,7 +339,7 @@ classify_parse_ntuple_filter(const struct rte_flow_attr 
*attr,
}
 
if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
-   tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
+   tcp_mask = item->mask;
 
/**
 * Only support src & dst ports, tcp flags,
@@ -373,12 +373,12 @@ classify_parse_ntuple_filter(const struct rte_flow_attr 
*attr,
return -EINVAL;
}
 
-   tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
+   tcp_spec = item->spec;
filter->dst_port  = tcp_spec->hdr.dst_port;
filter->src_port  = tcp_spec->hdr.src_port;
filter->tcp_flags = tcp_spec->hdr.tcp_flags;
} else if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
-   udp_mask = (const struct rte_flow_item_udp *)item->mask;
+   udp_mask = item->mask;
 
/**
 * Only support src & dst ports,
@@ -397,11 +397,11 @@ classify_parse_ntuple_filter(const struct rte_flow_attr 
*attr,
filter->dst_port_mask = udp_mask->hdr.dst_port;
filter->src_port_mask = udp_mask->hdr.src_port;
 
-   udp_spec = (const struct rte_flow_item_udp *)item->spec;
+   udp_spec = item->spec;
filter->dst_port = udp_spec->hdr.dst_port;
filter->src_port = udp_spec->hdr.src_port;
} else {
-   sctp_mask = (const struct rte_flow_item_sctp *)item->mask;
+   sctp_mask = item->mask;
 
/**
 * Only support src & dst ports,
@@ -420,7 +420,7 @@ classify_parse_ntuple_filter(const struct rte_flow_attr 
*attr,
filter->dst_port_mask = sctp_mask->hdr.dst_port;
filter->src_port_mask = sctp_mask->hdr.src_port;
 
-   sctp_spec = (const struct rte_flow_item_sctp *)item->spec;
+   sctp_spec = item->spec;
filter->dst_port = sctp_spec->hdr.dst_port;
filter->src_port = sctp_spec->hdr.src_port;
}
@@ -480,12 +480,12 @@ classify_parse_ntuple_filter(const struct rte_flow_attr 
*attr,
switch (act->type) {
case RTE_FLOW_ACTION_TYPE_COUNT:
action.action_mask |= 1LLU << RTE_FLOW_ACTION_TYPE_COUNT;
-   count = (const struct rte_flow_action_count *)act->conf;
+   count = act->conf;
memcpy(&action.act.counter, count, sizeof(action.act.counter));
break;
case RTE_FLOW_ACTION_TYPE_MARK:
action.action_mask |= 1LLU << RTE_FLOW_ACTION_TYPE_MARK;
-   mark_spec = (const struct rte

[dpdk-dev] [PATCH 0/5] remove void pointer explicit cast

2018-02-26 Thread Zhiyong Yang
The patch series cleanup void pointer explicit cast related to
struct rte_flow_item fields in librte_flow_classify and make
code more readable.

Zhiyong Yang (5):
  flow_classify: remove void pointer cast
  net/ixgbe: remove void pointer cast
  net/e1000: remove void pointer cast
  net/bnxt: remove void pointer cast
  net/sfc: remove void pointer cast

 drivers/net/bnxt/bnxt_filter.c |  44 -
 drivers/net/e1000/igb_flow.c   |  27 +++---
 drivers/net/ixgbe/ixgbe_flow.c | 106 +
 drivers/net/sfc/sfc_flow.c |   8 +-
 lib/librte_flow_classify/rte_flow_classify.c   |   4 +-
 lib/librte_flow_classify/rte_flow_classify_parse.c |  24 ++---
 6 files changed, 93 insertions(+), 120 deletions(-)

-- 
2.13.3



[dpdk-dev] [PATCH 4/4] net/vhost: add memory checking to support client mode

2018-02-14 Thread Zhiyong Yang
When vhost user PMD works in client mode to connect/reconnect virtio
user in server mode, new thread sometimes may run to new_device before
queue_setup has been done, So have to wait until memory allocation
is done.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/vhost/rte_eth_vhost.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/net/vhost/rte_eth_vhost.c 
b/drivers/net/vhost/rte_eth_vhost.c
index 3aae01c39..cd67bc7c5 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -580,6 +580,15 @@ new_device(int vid)
eth_dev->data->numa_node = newnode;
 #endif
 
+   /* The thread may run here before eth_dev->data->rx_queues or
+* eth_dev->data->tx_queues have gotten valid memory, so have to
+* wait until memory allocation is done.
+*/
+   while (!eth_dev->data->rx_queues ||
+  !eth_dev->data->tx_queues) {
+   ;
+   }
+
for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
vq = eth_dev->data->rx_queues[i];
if (vq == NULL)
-- 
2.13.3



[dpdk-dev] [PATCH 3/4] net/virtio-user: support server mode

2018-02-14 Thread Zhiyong Yang
virtio user adds to support for server mode.

Virtio user with server mode creates socket file and then starts to wait
for first connection from vhost user with client mode in blocking mode.

Server mode virtio user supports many times' vhost reconnections with
same configurations.

Support only one connection at the same time in server mode.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_ethdev.c   |  9 ++-
 drivers/net/virtio/virtio_user/vhost_user.c  | 77 --
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 44 +
 drivers/net/virtio/virtio_user_ethdev.c  | 81 ++--
 4 files changed, 186 insertions(+), 25 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index 884f74ad0..44d037d6b 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1273,9 +1273,13 @@ static void
 virtio_notify_peers(struct rte_eth_dev *dev)
 {
struct virtio_hw *hw = dev->data->dev_private;
-   struct virtnet_rx *rxvq = dev->data->rx_queues[0];
+   struct virtnet_rx *rxvq = NULL;
struct rte_mbuf *rarp_mbuf;
 
+   if (!dev->data->rx_queues)
+   return;
+
+   rxvq = dev->data->rx_queues[0];
rarp_mbuf = rte_net_make_rarp_packet(rxvq->mpool,
(struct ether_addr *)hw->mac_addr);
if (rarp_mbuf == NULL) {
@@ -1333,7 +1337,8 @@ virtio_interrupt_handler(void *param)
 
if (isr & VIRTIO_NET_S_ANNOUNCE) {
virtio_notify_peers(dev);
-   virtio_ack_link_announce(dev);
+   if (hw->cvq)
+   virtio_ack_link_announce(dev);
}
 }
 
diff --git a/drivers/net/virtio/virtio_user/vhost_user.c 
b/drivers/net/virtio/virtio_user/vhost_user.c
index 91c6449bb..fd806e106 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -378,6 +378,55 @@ vhost_user_sock(struct virtio_user_dev *dev,
return 0;
 }
 
+static void
+virtio_user_set_block(int fd, bool enabled)
+{
+   int f;
+
+   f = fcntl(fd, F_GETFL);
+   if (enabled)
+   fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
+   else
+   fcntl(fd, F_SETFL, f | O_NONBLOCK);
+}
+
+#define MAX_VIRTIO_USER_BACKLOG 128
+static int
+virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)
+{
+   int ret;
+   int fd = dev->listenfd;
+   int connectfd;
+
+   ret = bind(fd, (struct sockaddr *)un, sizeof(*un));
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and try 
again\n",
+   dev->path, strerror(errno));
+   goto err;
+   }
+   ret = listen(fd, MAX_VIRTIO_USER_BACKLOG);
+   if (ret < 0)
+   goto err;
+
+   virtio_user_set_block(fd, true);
+   PMD_DRV_LOG(NOTICE, "virtio user server mode is waiting for connection 
from vhost user.");
+   while (1) {
+   connectfd = accept(fd, NULL, NULL);
+   if (connectfd >= 0) {
+   dev->connected = true;
+   break;
+   }
+   }
+
+   dev->vhostfd = connectfd;
+   virtio_user_set_block(connectfd, true);
+
+   return 0;
+err:
+   close(fd);
+   return -1;
+}
+
 /**
  * Set up environment to talk with a vhost user backend.
  *
@@ -390,6 +439,7 @@ vhost_user_setup(struct virtio_user_dev *dev)
 {
int fd;
int flag;
+   int ret;
struct sockaddr_un un;
 
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -405,13 +455,30 @@ vhost_user_setup(struct virtio_user_dev *dev)
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
-   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
-   PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
-   close(fd);
-   return -1;
+
+   if (dev->is_server) {
+   static pthread_t fdset_tid;
+
+   dev->listenfd = fd;
+   if (fdset_tid == 0) {
+   ret = pthread_create(&fdset_tid, NULL,
+fdset_event_dispatch,
+&dev->fdset);
+   if (ret < 0)
+   PMD_DRV_LOG(ERR, "failed to create fdset 
handling thread");
+   }
+   return virtio_user_start_server(dev, &un);
+
+   } else {
+   dev->vhostfd = fd;
+   if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
+   PMD_DRV_LOG(ERR, "connect error, %s", strerro

[dpdk-dev] [PATCH 2/4] net/virtio-user: add data members to support server mode

2018-02-14 Thread Zhiyong Yang
Add data members so as to support server mode.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_user/virtio_user_dev.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h 
b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index 64467b4f9..e640a3438 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -6,13 +6,21 @@
 #define _VIRTIO_USER_DEV_H
 
 #include 
+#include 
 #include "../virtio_pci.h"
 #include "../virtio_ring.h"
 #include "vhost.h"
+#include "fd_man.h"
 
 struct virtio_user_dev {
/* for vhost_user backend */
int vhostfd;
+   int listenfd;   /* listening fd  */
+   boolconnected;  /* connection status */
+
+   /* support for server/clinet mode */
+   boolis_server;
+   struct fdsetfdset;
 
/* for vhost_kernel backend */
char*ifname;
-- 
2.13.3



[dpdk-dev] [PATCH 1/4] vhost: move fdset functions from fd_man.c to fd_man.h

2018-02-14 Thread Zhiyong Yang
The patch moves fdset related funcitons from fd_man.c to fd_man.h in
order to reuse these funcitons from the perspective of PMDs.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_vhost/Makefile |   3 +-
 lib/librte_vhost/fd_man.c | 274 --
 lib/librte_vhost/fd_man.h | 258 +--
 3 files changed, 253 insertions(+), 282 deletions(-)
 delete mode 100644 lib/librte_vhost/fd_man.c

diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile
index 5d6c6abae..e201df79c 100644
--- a/lib/librte_vhost/Makefile
+++ b/lib/librte_vhost/Makefile
@@ -21,10 +21,11 @@ endif
 LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev -lrte_net
 
 # all source are stored in SRCS-y
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \
+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := iotlb.c socket.c vhost.c \
vhost_user.c virtio_net.c
 
 # install includes
 SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h
+SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += fd_man.h
 
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
deleted file mode 100644
index 181711c2a..0
--- a/lib/librte_vhost/fd_man.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2010-2014 Intel Corporation
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-
-#include "fd_man.h"
-
-#define FDPOLLERR (POLLERR | POLLHUP | POLLNVAL)
-
-static int
-get_last_valid_idx(struct fdset *pfdset, int last_valid_idx)
-{
-   int i;
-
-   for (i = last_valid_idx; i >= 0 && pfdset->fd[i].fd == -1; i--)
-   ;
-
-   return i;
-}
-
-static void
-fdset_move(struct fdset *pfdset, int dst, int src)
-{
-   pfdset->fd[dst]= pfdset->fd[src];
-   pfdset->rwfds[dst] = pfdset->rwfds[src];
-}
-
-static void
-fdset_shrink_nolock(struct fdset *pfdset)
-{
-   int i;
-   int last_valid_idx = get_last_valid_idx(pfdset, pfdset->num - 1);
-
-   for (i = 0; i < last_valid_idx; i++) {
-   if (pfdset->fd[i].fd != -1)
-   continue;
-
-   fdset_move(pfdset, i, last_valid_idx);
-   last_valid_idx = get_last_valid_idx(pfdset, last_valid_idx - 1);
-   }
-   pfdset->num = last_valid_idx + 1;
-}
-
-/*
- * Find deleted fd entries and remove them
- */
-static void
-fdset_shrink(struct fdset *pfdset)
-{
-   pthread_mutex_lock(&pfdset->fd_mutex);
-   fdset_shrink_nolock(pfdset);
-   pthread_mutex_unlock(&pfdset->fd_mutex);
-}
-
-/**
- * Returns the index in the fdset for a given fd.
- * @return
- *   index for the fd, or -1 if fd isn't in the fdset.
- */
-static int
-fdset_find_fd(struct fdset *pfdset, int fd)
-{
-   int i;
-
-   for (i = 0; i < pfdset->num && pfdset->fd[i].fd != fd; i++)
-   ;
-
-   return i == pfdset->num ? -1 : i;
-}
-
-static void
-fdset_add_fd(struct fdset *pfdset, int idx, int fd,
-   fd_cb rcb, fd_cb wcb, void *dat)
-{
-   struct fdentry *pfdentry = &pfdset->fd[idx];
-   struct pollfd *pfd = &pfdset->rwfds[idx];
-
-   pfdentry->fd  = fd;
-   pfdentry->rcb = rcb;
-   pfdentry->wcb = wcb;
-   pfdentry->dat = dat;
-
-   pfd->fd = fd;
-   pfd->events  = rcb ? POLLIN : 0;
-   pfd->events |= wcb ? POLLOUT : 0;
-   pfd->revents = 0;
-}
-
-void
-fdset_init(struct fdset *pfdset)
-{
-   int i;
-
-   if (pfdset == NULL)
-   return;
-
-   for (i = 0; i < MAX_FDS; i++) {
-   pfdset->fd[i].fd = -1;
-   pfdset->fd[i].dat = NULL;
-   }
-   pfdset->num = 0;
-}
-
-/**
- * Register the fd in the fdset with read/write handler and context.
- */
-int
-fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat)
-{
-   int i;
-
-   if (pfdset == NULL || fd == -1)
-   return -1;
-
-   pthread_mutex_lock(&pfdset->fd_mutex);
-   i = pfdset->num < MAX_FDS ? pfdset->num++ : -1;
-   if (i == -1) {
-   fdset_shrink_nolock(pfdset);
-   i = pfdset->num < MAX_FDS ? pfdset->num++ : -1;
-   if (i == -1) {
-   pthread_mutex_unlock(&pfdset->fd_mutex);
-   return -2;
-   }
-   }
-
-   fdset_add_fd(pfdset, i, fd, rcb, wcb, dat);
-   pthread_mutex_unlock(&pfdset->fd_mutex);
-
-   return 0;
-}
-
-/**
- *  Unregister the fd from the fdset.
- *  Returns context of a given fd or NULL.
- */
-void *
-fdset_del(struct fdset *pfdset, int fd)
-{
-   int i;
-   void *dat = NULL;
-
-   if (pfdset == NULL || fd == -1)
-   return NUL

[dpdk-dev] [PATCH 0/4] add to support for virtio-user server mode

2018-02-14 Thread Zhiyong Yang
When vhost user/ovs-dpdk restart, virtio user is expected to keep alive
so that vhost user can reconnect it successfully and continue to exchange
packets.

The series support the feature and target for 18.05 release.

Virtio user with server mode creates socket file and then starts to wait
for first connection from vhost user with client mode in blocking mode.

Virtio user with server mode supports many times' vhost reconnections with
same configurations. 

Virtio user supports only one connection at the same time in server/client
mode.

How to test?
for example:

./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3 -n 4 -m 256,0 --no-pci \
--file-prefix=testpmd0 --vdev=net_virtio_user0,mac=00:11:22:33:44:10, \
path=/tmp/sock0,server=1,queues=1 -- -i --rxq=1 --txq=1 --no-numa

./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3e000 -n 4 --socket-mem 256,0 \
--vdev 'net_vhost0,iface=/tmp/sock0,client=0,queues=1' -- -i --rxq=1 --txq=1 \
--nb-cores=1 --no-numa

Zhiyong Yang (4):
  vhost: move fdset functions from fd_man.c to fd_man.h
  net/virtio-user: add data members to support server mode
  net/virtio-user: support server mode
  net/vhost: add memory checking to support client mode

 drivers/net/vhost/rte_eth_vhost.c|   9 +
 drivers/net/virtio/virtio_ethdev.c   |   9 +-
 drivers/net/virtio/virtio_user/vhost_user.c  |  77 ++-
 drivers/net/virtio/virtio_user/virtio_user_dev.c |  44 ++--
 drivers/net/virtio/virtio_user/virtio_user_dev.h |   8 +
 drivers/net/virtio/virtio_user_ethdev.c  |  81 ++-
 lib/librte_vhost/Makefile|   3 +-
 lib/librte_vhost/fd_man.c| 274 ---
 lib/librte_vhost/fd_man.h| 258 -
 9 files changed, 456 insertions(+), 307 deletions(-)
 delete mode 100644 lib/librte_vhost/fd_man.c

-- 
2.13.3



[dpdk-dev] [PATCH] vhost: unlink existing file for server mode

2018-02-02 Thread Zhiyong Yang
Vhost-user startup will fail based on server mode, if the specified
socket file has already existed. The patch introduces function
unlink() to remove the possible existing file.

Cc: y...@fridaylinux.org
Cc: maxime.coque...@redhat.com

Signed-off-by: Zhiyong Yang 
---
 lib/librte_vhost/socket.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index 6e3857e7a..324a24f4e 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -315,6 +315,7 @@ vhost_user_start_server(struct vhost_user_socket *vsocket)
int fd = vsocket->socket_fd;
const char *path = vsocket->path;
 
+   unlink(path);
ret = bind(fd, (struct sockaddr *)&vsocket->un, sizeof(vsocket->un));
if (ret < 0) {
RTE_LOG(ERR, VHOST_CONFIG,
-- 
2.13.3



[dpdk-dev] [PATCH] net/tap: fix ICC compilation fails

2018-01-31 Thread Zhiyong Yang
The following error is reported when compiling 18.02-rc2 usng ICC,
"transfer of control bypasses initialization of".
The patch fixes the issue.

Fixes: 1911c5edc6cd ("net/tap: fix eBPF RSS map key handling")
Cc: sta...@dpdk.org
Cc: pascal.ma...@6wind.com
Cc: ferruh.yi...@intel.com
Cc: tho...@monjalon.net
Cc: ophi...@mellanox.com

Signed-off-by: Zhiyong Yang 
---
 drivers/net/tap/tap_flow.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c
index 212992e49..65657f0a0 100644
--- a/drivers/net/tap/tap_flow.c
+++ b/drivers/net/tap/tap_flow.c
@@ -1930,6 +1930,7 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 
*key_idx)
static __u32 num_used_keys;
static __u32 rss_keys[MAX_RSS_KEYS] = {KEY_STAT_UNSPEC};
static __u32 rss_keys_initialized;
+   __u32 key;
 
switch (cmd) {
case KEY_CMD_GET:
@@ -1975,7 +1976,7 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 
*key_idx)
 * map index as an out-of-range value and the release operation
 * will be silently ignored.
 */
-   __u32 key = *key_idx - KEY_IDX_OFFSET;
+   key = *key_idx - KEY_IDX_OFFSET;
if (key >= RTE_DIM(rss_keys))
break;
 
-- 
2.13.3



[dpdk-dev] [PATCH] net/i40e: remove unnecessary void pointer cast

2018-01-24 Thread Zhiyong Yang
void pointer can be assigned to any type pointer without type cast.
The patch can make code more simple.

Cc: beilei.x...@intel.com
Cc: qi.z.zh...@intel.com
Cc: helin.zh...@intel.com

Signed-off-by: Zhiyong Yang 
---
 drivers/net/i40e/i40e_flow.c | 118 +--
 1 file changed, 47 insertions(+), 71 deletions(-)

diff --git a/drivers/net/i40e/i40e_flow.c b/drivers/net/i40e/i40e_flow.c
index a74fa08ab..bc6eceb95 100644
--- a/drivers/net/i40e/i40e_flow.c
+++ b/drivers/net/i40e/i40e_flow.c
@@ -1989,8 +1989,8 @@ i40e_flow_parse_ethertype_pattern(struct rte_eth_dev *dev,
item_type = item->type;
switch (item_type) {
case RTE_FLOW_ITEM_TYPE_ETH:
-   eth_spec = (const struct rte_flow_item_eth *)item->spec;
-   eth_mask = (const struct rte_flow_item_eth *)item->mask;
+   eth_spec = item->spec;
+   eth_mask = item->mask;
/* Get the MAC info. */
if (!eth_spec || !eth_mask) {
rte_flow_error_set(error, EINVAL,
@@ -2075,7 +2075,7 @@ i40e_flow_parse_ethertype_action(struct rte_eth_dev *dev,
}
 
if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
-   act_q = (const struct rte_flow_action_queue *)act->conf;
+   act_q = act->conf;
filter->queue = act_q->index;
if (filter->queue >= pf->dev_data->nb_rx_queues) {
rte_flow_error_set(error, EINVAL,
@@ -2477,8 +2477,8 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
item_type = item->type;
switch (item_type) {
case RTE_FLOW_ITEM_TYPE_ETH:
-   eth_spec = (const struct rte_flow_item_eth *)item->spec;
-   eth_mask = (const struct rte_flow_item_eth *)item->mask;
+   eth_spec = item->spec;
+   eth_mask = item->mask;
 
if (eth_spec && eth_mask) {
if (!is_zero_ether_addr(ð_mask->src) ||
@@ -2515,10 +2515,8 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
 
break;
case RTE_FLOW_ITEM_TYPE_VLAN:
-   vlan_spec =
-   (const struct rte_flow_item_vlan *)item->spec;
-   vlan_mask =
-   (const struct rte_flow_item_vlan *)item->mask;
+   vlan_spec = item->spec;
+   vlan_mask = item->mask;
if (vlan_spec && vlan_mask) {
if (vlan_mask->tci ==
rte_cpu_to_be_16(I40E_TCI_MASK)) {
@@ -2534,10 +2532,8 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
break;
case RTE_FLOW_ITEM_TYPE_IPV4:
l3 = RTE_FLOW_ITEM_TYPE_IPV4;
-   ipv4_spec =
-   (const struct rte_flow_item_ipv4 *)item->spec;
-   ipv4_mask =
-   (const struct rte_flow_item_ipv4 *)item->mask;
+   ipv4_spec = item->spec;
+   ipv4_mask = item->mask;
pctype = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
layer_idx = I40E_FLXPLD_L3_IDX;
 
@@ -2602,10 +2598,8 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
break;
case RTE_FLOW_ITEM_TYPE_IPV6:
l3 = RTE_FLOW_ITEM_TYPE_IPV6;
-   ipv6_spec =
-   (const struct rte_flow_item_ipv6 *)item->spec;
-   ipv6_mask =
-   (const struct rte_flow_item_ipv6 *)item->mask;
+   ipv6_spec = item->spec;
+   ipv6_mask = item->mask;
pctype = I40E_FILTER_PCTYPE_NONF_IPV6_OTHER;
layer_idx = I40E_FLXPLD_L3_IDX;
 
@@ -2673,8 +2667,8 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
outer_ip = false;
break;
case RTE_FLOW_ITEM_TYPE_TCP:
-   tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
-   tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
+   tcp_spec = item->spec;
+   tcp_mask = item->mask;
 
if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
pctype =
@@ -2721,8 +2715,8 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
 
break;
case RTE_FLOW_ITEM_TYPE_UDP:
- 

[dpdk-dev] [PATCH] event/opdl: fix ICC fails at compile time

2018-01-24 Thread Zhiyong Yang
ICC reports the issue at compile time as follows.
error #592: variable "i" is used before its value is set
RTE_SET_USED(i);

The patch is to fix it. GCC and CLANG has been tested as well.

Fixes: d548ef513cd7 ("event/opdl: add unit tests")
Cc: liang.j...@intel.com
Cc: peter.mccar...@intel.com
Cc: ferruh.yi...@intel.com

Signed-off-by: Zhiyong Yang 
---
 drivers/event/opdl/opdl_test.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/event/opdl/opdl_test.c b/drivers/event/opdl/opdl_test.c
index 13d4f6b45..39c6cf8cf 100644
--- a/drivers/event/opdl/opdl_test.c
+++ b/drivers/event/opdl/opdl_test.c
@@ -562,7 +562,6 @@ single_link_w_stats(struct test *t)
uint32_t deq_pkts;
struct rte_mbuf *mbufs[3];
RTE_SET_USED(mbufs);
-   RTE_SET_USED(i);
 
/* Create instance with 3 ports */
if (init(t, 2, tx_port + 1) < 0 ||
@@ -702,10 +701,8 @@ single_link(struct test *t)
/* const uint8_t w3_port = 3; */
const uint8_t tx_port = 2;
int err;
-   int i;
struct rte_mbuf *mbufs[3];
RTE_SET_USED(mbufs);
-   RTE_SET_USED(i);
 
/* Create instance with 5 ports */
if (init(t, 2, tx_port+1) < 0 ||
-- 
2.13.3



[dpdk-dev] [PATCH] examples/flow_filtering: fix incorrect port id size

2018-01-23 Thread Zhiyong Yang
Ethdev port id has been extended 16bits from 8bits in DPDK 17.11 release,
the patch fixes mismatch use.

Fixes: 4a3ef59a10c8 ("examples/flow_filtering: add simple demo of flow API")
Cc: sta...@dpdk.org
Cc: or...@mellanox.com
Cc: ferruh.yi...@intel.com
Cc: tho...@monjalon.net

Signed-off-by: Zhiyong Yang 
---
 examples/flow_filtering/flow_blocks.c | 4 ++--
 examples/flow_filtering/main.c| 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/examples/flow_filtering/flow_blocks.c 
b/examples/flow_filtering/flow_blocks.c
index f92df1024..61b045af3 100644
--- a/examples/flow_filtering/flow_blocks.c
+++ b/examples/flow_filtering/flow_blocks.c
@@ -33,7 +33,7 @@
 #define MAX_PATTERN_NUM4
 
 struct rte_flow *
-generate_ipv4_flow(uint8_t port_id, uint16_t rx_q,
+generate_ipv4_flow(uint16_t port_id, uint16_t rx_q,
uint32_t src_ip, uint32_t src_mask,
uint32_t dest_ip, uint32_t dest_mask,
struct rte_flow_error *error);
@@ -62,7 +62,7 @@ generate_ipv4_flow(uint8_t port_id, uint16_t rx_q,
  *   A flow if the rule could be created else return NULL.
  */
 struct rte_flow *
-generate_ipv4_flow(uint8_t port_id, uint16_t rx_q,
+generate_ipv4_flow(uint16_t port_id, uint16_t rx_q,
uint32_t src_ip, uint32_t src_mask,
uint32_t dest_ip, uint32_t dest_mask,
struct rte_flow_error *error)
diff --git a/examples/flow_filtering/main.c b/examples/flow_filtering/main.c
index 58e26859f..cc955cd90 100644
--- a/examples/flow_filtering/main.c
+++ b/examples/flow_filtering/main.c
@@ -58,7 +58,7 @@
 
 static volatile bool force_quit;
 
-static uint8_t port_id;
+static uint16_t port_id;
 static uint16_t nr_queues = 5;
 static uint8_t selected_queue = 1;
 struct rte_mempool *mbuf_pool;
-- 
2.13.3



[dpdk-dev] [PATCH] lib: fix wrong cast

2018-01-23 Thread Zhiyong Yang
The wrong casts don't cause actual error, but they should conform to C
standard.

Fixes: c261d1431bd8 ("security: introduce security API and framework")
Fixes: b3bbd9e5f265 ("cryptodev: support device independent sessions")
Cc: sta...@dpdk.org
Cc: declan.dohe...@intel.com
Cc: akhil.go...@nxp.com

Signed-off-by: Zhiyong Yang 
---
 lib/librte_cryptodev/rte_cryptodev.c | 2 +-
 lib/librte_security/rte_security.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/librte_cryptodev/rte_cryptodev.c 
b/lib/librte_cryptodev/rte_cryptodev.c
index 7726d15f4..8745b6b02 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -1094,7 +1094,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
struct rte_cryptodev_sym_session *sess;
 
/* Allocate a session structure from the session pool */
-   if (rte_mempool_get(mp, (void *)&sess)) {
+   if (rte_mempool_get(mp, (void **)&sess)) {
CDEV_LOG_ERR("couldn't get object from session mempool");
return NULL;
}
diff --git a/lib/librte_security/rte_security.c 
b/lib/librte_security/rte_security.c
index 6461dba05..d98f46dea 100644
--- a/lib/librte_security/rte_security.c
+++ b/lib/librte_security/rte_security.c
@@ -49,7 +49,7 @@ rte_security_session_create(struct rte_security_ctx *instance,
 
RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_create, NULL);
 
-   if (rte_mempool_get(mp, (void *)&sess))
+   if (rte_mempool_get(mp, (void **)&sess))
return NULL;
 
if (instance->ops->session_create(instance->device, conf, sess, mp)) {
-- 
2.13.3



[dpdk-dev] [PATCH] mbuf: remove void pointer cast

2018-01-19 Thread Zhiyong Yang
It is unnecessary to cast from void * to struct rte_mbuf *,
the change can make code clearer.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_mbuf/rte_mbuf.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index a594e4772..2fd4f5ef9 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -896,11 +896,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int 
is_header);
 static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 {
struct rte_mbuf *m;
-   void *mb = NULL;
 
-   if (rte_mempool_get(mp, &mb) < 0)
+   if (rte_mempool_get(mp, (void **)&m) < 0)
return NULL;
-   m = (struct rte_mbuf *)mb;
MBUF_RAW_ALLOC_CHECK(m);
return m;
 }
-- 
2.13.3



[dpdk-dev] [PATCH] lib/librte_mbuf: remove void * pointer cast

2018-01-19 Thread Zhiyong Yang
It is unnecessary to cast from void * to struct rte_mbuf *,
the change can make code more simple.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_mbuf/rte_mbuf.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index a594e4772..2fd4f5ef9 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -896,11 +896,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int 
is_header);
 static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 {
struct rte_mbuf *m;
-   void *mb = NULL;
 
-   if (rte_mempool_get(mp, &mb) < 0)
+   if (rte_mempool_get(mp, (void **)&m) < 0)
return NULL;
-   m = (struct rte_mbuf *)mb;
MBUF_RAW_ALLOC_CHECK(m);
return m;
 }
-- 
2.13.3



[dpdk-dev] [PATCH v3] doc: fix link bonding PMD typo in prog guide

2018-01-18 Thread Zhiyong Yang
fix one typo and a grammatical mistake.

Fixes: b0152b1b40fe ("doc: update bonding")
Cc: sta...@dpdk.org

Signed-off-by: Zhiyong Yang 
Acked-by: Marko Kovacevic 
---

Changes in V3:
use "similar capabilities" instead of "the similar capabilities"

Changes in V2:
Fix the title and fixline format issue in commit log.

 doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst 
b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
index 1ef231df9..e13a54fc5 100644
--- a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
+++ b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
@@ -33,7 +33,7 @@ Link Bonding Poll Mode Driver Library
 
 In addition to Poll Mode Drivers (PMDs) for physical and virtual hardware,
 DPDK also includes a pure-software library that
-allows physical PMD's to be bonded together to create a single logical PMD.
+allows physical PMDs to be bonded together to create a single logical PMD.
 
 .. figure:: img/bond-overview.*
 
@@ -41,12 +41,12 @@ allows physical PMD's to be bonded together to create a 
single logical PMD.
 
 
 The Link Bonding PMD library(librte_pmd_bond) supports bonding of groups of
-``rte_eth_dev`` ports of the same speed and duplex to provide
-similar the capabilities to that found in Linux bonding driver to allow the
-aggregation of multiple (slave) NICs into a single logical interface between a
-server and a switch. The new bonded PMD will then process these interfaces
-based on the mode of operation specified to provide support for features such
-as redundant links, fault tolerance and/or load balancing.
+``rte_eth_dev`` ports of the same speed and duplex to provide similar
+capabilities to that found in Linux bonding driver to allow the aggregation
+of multiple (slave) NICs into a single logical interface between a server
+and a switch. The new bonded PMD will then process these interfaces based on
+the mode of operation specified to provide support for features such as
+redundant links, fault tolerance and/or load balancing.
 
 The librte_pmd_bond library exports a C API which provides an API for the
 creation of bonded devices as well as the configuration and management of the
-- 
2.13.3



[dpdk-dev] [PATCH 5/5] lib/librte_pipeline: remove unnecessary void * pointer cast using rte_zmalloc_socket

2018-01-15 Thread Zhiyong Yang
void * pointer can be assigned to any data type pointer. Unnecessary cast
can be removed in order to keep code clearer.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_pipeline/rte_pipeline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_pipeline/rte_pipeline.c 
b/lib/librte_pipeline/rte_pipeline.c
index 1b331f4df..0cb8b804e 100644
--- a/lib/librte_pipeline/rte_pipeline.c
+++ b/lib/librte_pipeline/rte_pipeline.c
@@ -347,7 +347,7 @@ rte_pipeline_table_create(struct rte_pipeline *p,
/* Allocate space for the default table entry */
entry_size = sizeof(struct rte_pipeline_table_entry) +
params->action_data_size;
-   default_entry = (struct rte_pipeline_table_entry *) rte_zmalloc_socket(
+   default_entry = rte_zmalloc_socket(
"PIPELINE", entry_size, RTE_CACHE_LINE_SIZE, p->socket_id);
if (default_entry == NULL) {
RTE_LOG(ERR, PIPELINE,
-- 
2.13.3



[dpdk-dev] [PATCH 4/5] lib/librte_member: remove unnecessary void * pointer cast

2018-01-15 Thread Zhiyong Yang
void * pointer can be assigned to any data type pointer. Unnecessary cast
can be removed in order to keep code clearer.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_member/rte_member.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/librte_member/rte_member.c b/lib/librte_member/rte_member.c
index 0c4c14470..1366b3d39 100644
--- a/lib/librte_member/rte_member.c
+++ b/lib/librte_member/rte_member.c
@@ -107,7 +107,7 @@ rte_member_create(const struct rte_member_parameters 
*params)
rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
 
TAILQ_FOREACH(te, member_list, next) {
-   setsum = (struct rte_member_setsum *) te->data;
+   setsum = te->data;
if (strncmp(params->name, setsum->name,
RTE_MEMBER_NAMESIZE) == 0)
break;
@@ -125,7 +125,7 @@ rte_member_create(const struct rte_member_parameters 
*params)
}
 
/* Create a new setsum structure */
-   setsum = (struct rte_member_setsum *) rte_zmalloc_socket(params->name,
+   setsum = rte_zmalloc_socket(params->name,
sizeof(struct rte_member_setsum), RTE_CACHE_LINE_SIZE,
params->socket_id);
if (setsum == NULL) {
-- 
2.13.3



[dpdk-dev] [PATCH 3/5] lib/librte_hash: remove unnecessary void * pointer cast using rte_zmalloc_socket

2018-01-15 Thread Zhiyong Yang
void * pointer can be assigned to any data type pointer. Unnecessary cast
can be removed in order to keep code clearer.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_hash/rte_fbk_hash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_hash/rte_fbk_hash.c b/lib/librte_hash/rte_fbk_hash.c
index a8d0d485d..4aff40e67 100644
--- a/lib/librte_hash/rte_fbk_hash.c
+++ b/lib/librte_hash/rte_fbk_hash.c
@@ -123,7 +123,7 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params 
*params)
}
 
/* Allocate memory for table. */
-   ht = (struct rte_fbk_hash_table *)rte_zmalloc_socket(hash_name, 
mem_size,
+   ht = rte_zmalloc_socket(hash_name, mem_size,
0, params->socket_id);
if (ht == NULL) {
RTE_LOG(ERR, HASH, "Failed to allocate fbk hash table\n");
-- 
2.13.3



[dpdk-dev] [PATCH 2/5] lib/librte_efd: remove unnecessary void * pointer cast using rte_zmalloc_socket

2018-01-15 Thread Zhiyong Yang
void * pointer can be assigned to any data type pointer. Unnecessary cast
can be removed in order to keep code clearer.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_efd/rte_efd.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/librte_efd/rte_efd.c b/lib/librte_efd/rte_efd.c
index e15ff04c9..a780e2fe8 100644
--- a/lib/librte_efd/rte_efd.c
+++ b/lib/librte_efd/rte_efd.c
@@ -558,7 +558,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, 
uint32_t key_len,
}
 
/* Create a new EFD table management structure */
-   table = (struct rte_efd_table *) rte_zmalloc_socket(NULL,
+   table = rte_zmalloc_socket(NULL,
sizeof(struct rte_efd_table),
RTE_CACHE_LINE_SIZE,
offline_cpu_socket);
@@ -580,7 +580,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, 
uint32_t key_len,
table->key_len = key_len;
 
/* key_array */
-   key_array = (uint8_t *) rte_zmalloc_socket(NULL,
+   key_array = rte_zmalloc_socket(NULL,
table->max_num_rules * table->key_len,
RTE_CACHE_LINE_SIZE,
offline_cpu_socket);
@@ -616,7 +616,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, 
uint32_t key_len,
 * as a continuous block
 */
table->chunks[socket_id] =
-   (struct efd_online_chunk *) rte_zmalloc_socket(
+   rte_zmalloc_socket(
NULL,
online_table_size,
RTE_CACHE_LINE_SIZE,
@@ -666,7 +666,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, 
uint32_t key_len,
 */
offline_table_size = num_chunks * sizeof(struct 
efd_offline_chunk_rules);
table->offline_chunks =
-   (struct efd_offline_chunk_rules *) 
rte_zmalloc_socket(NULL,
+   rte_zmalloc_socket(NULL,
offline_table_size,
RTE_CACHE_LINE_SIZE,
offline_cpu_socket);
-- 
2.13.3



[dpdk-dev] [PATCH 0/5] remove unnecessary void * pointer cast

2018-01-15 Thread Zhiyong Yang
void * pointer can be assigned to any data type pointer. Unnecessary cast
can be removed in order to keep code clearer.

Zhiyong Yang (5):
  lib/librte_lpm: remove unnecessary void * pointer cast
  lib/librte_efd: remove unnecessary void * pointer cast using
rte_zmalloc_socket
  lib/librte_hash: remove unnecessary void * pointer cast using
rte_zmalloc_socket
  lib/librte_member: remove unnecessary void * pointer cast
  lib/librte_pipeline: remove unnecessary void * pointer cast using
rte_zmalloc_socket

 lib/librte_efd/rte_efd.c   |  8 
 lib/librte_hash/rte_fbk_hash.c |  2 +-
 lib/librte_lpm/rte_lpm.c   | 24 
 lib/librte_lpm/rte_lpm6.c  |  4 ++--
 lib/librte_member/rte_member.c |  4 ++--
 lib/librte_pipeline/rte_pipeline.c |  2 +-
 6 files changed, 22 insertions(+), 22 deletions(-)

-- 
2.13.3



[dpdk-dev] [PATCH 1/5] lib/librte_lpm: remove unnecessary void * pointer cast

2018-01-15 Thread Zhiyong Yang
void * pointer can be assigned to any data type pointer. Unnecessary cast
can be removed in order to keep code clearer.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_lpm/rte_lpm.c  | 24 
 lib/librte_lpm/rte_lpm6.c |  4 ++--
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
index 5ba595e22..d464dbda9 100644
--- a/lib/librte_lpm/rte_lpm.c
+++ b/lib/librte_lpm/rte_lpm.c
@@ -99,7 +99,7 @@ rte_lpm_find_existing_v20(const char *name)
 
rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
TAILQ_FOREACH(te, lpm_list, next) {
-   l = (struct rte_lpm_v20 *) te->data;
+   l = te->data;
if (strncmp(name, l->name, RTE_LPM_NAMESIZE) == 0)
break;
}
@@ -125,7 +125,7 @@ rte_lpm_find_existing_v1604(const char *name)
 
rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
TAILQ_FOREACH(te, lpm_list, next) {
-   l = (struct rte_lpm *) te->data;
+   l = te->data;
if (strncmp(name, l->name, RTE_LPM_NAMESIZE) == 0)
break;
}
@@ -174,11 +174,11 @@ rte_lpm_create_v20(const char *name, int socket_id, int 
max_rules,
 
/* guarantee there's no existing */
TAILQ_FOREACH(te, lpm_list, next) {
-   lpm = (struct rte_lpm_v20 *) te->data;
+   lpm = te->data;
if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0)
break;
}
-   lpm = NULL;
+
if (te != NULL) {
rte_errno = EEXIST;
goto exit;
@@ -193,7 +193,7 @@ rte_lpm_create_v20(const char *name, int socket_id, int 
max_rules,
}
 
/* Allocate memory to store the LPM data structures. */
-   lpm = (struct rte_lpm_v20 *)rte_zmalloc_socket(mem_name, mem_size,
+   lpm = rte_zmalloc_socket(mem_name, mem_size,
RTE_CACHE_LINE_SIZE, socket_id);
if (lpm == NULL) {
RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
@@ -206,7 +206,7 @@ rte_lpm_create_v20(const char *name, int socket_id, int 
max_rules,
lpm->max_rules = max_rules;
snprintf(lpm->name, sizeof(lpm->name), "%s", name);
 
-   te->data = (void *) lpm;
+   te->data = lpm;
 
TAILQ_INSERT_TAIL(lpm_list, te, next);
 
@@ -250,11 +250,11 @@ rte_lpm_create_v1604(const char *name, int socket_id,
 
/* guarantee there's no existing */
TAILQ_FOREACH(te, lpm_list, next) {
-   lpm = (struct rte_lpm *) te->data;
+   lpm = te->data;
if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0)
break;
}
-   lpm = NULL;
+
if (te != NULL) {
rte_errno = EEXIST;
goto exit;
@@ -269,7 +269,7 @@ rte_lpm_create_v1604(const char *name, int socket_id,
}
 
/* Allocate memory to store the LPM data structures. */
-   lpm = (struct rte_lpm *)rte_zmalloc_socket(mem_name, mem_size,
+   lpm = rte_zmalloc_socket(mem_name, mem_size,
RTE_CACHE_LINE_SIZE, socket_id);
if (lpm == NULL) {
RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
@@ -278,7 +278,7 @@ rte_lpm_create_v1604(const char *name, int socket_id,
goto exit;
}
 
-   lpm->rules_tbl = (struct rte_lpm_rule *)rte_zmalloc_socket(NULL,
+   lpm->rules_tbl = rte_zmalloc_socket(NULL,
(size_t)rules_size, RTE_CACHE_LINE_SIZE, socket_id);
 
if (lpm->rules_tbl == NULL) {
@@ -290,7 +290,7 @@ rte_lpm_create_v1604(const char *name, int socket_id,
goto exit;
}
 
-   lpm->tbl8 = (struct rte_lpm_tbl_entry *)rte_zmalloc_socket(NULL,
+   lpm->tbl8 = rte_zmalloc_socket(NULL,
(size_t)tbl8s_size, RTE_CACHE_LINE_SIZE, socket_id);
 
if (lpm->tbl8 == NULL) {
@@ -308,7 +308,7 @@ rte_lpm_create_v1604(const char *name, int socket_id,
lpm->number_tbl8s = config->number_tbl8s;
snprintf(lpm->name, sizeof(lpm->name), "%s", name);
 
-   te->data = (void *) lpm;
+   te->data = lpm;
 
TAILQ_INSERT_TAIL(lpm_list, te, next);
 
diff --git a/lib/librte_lpm/rte_lpm6.c b/lib/librte_lpm/rte_lpm6.c
index 45d648571..149677eb1 100644
--- a/lib/librte_lpm/rte_lpm6.c
+++ b/lib/librte_lpm/rte_lpm6.c
@@ -166,7 +166,7 @@ rte_lpm6_create(const char *name, int socket_id,
}
 
/* Allocate memory to store the LPM data structures. */
-   lpm = (struct rte_lpm6 *)rte_zmalloc_socket(mem_name, (size_t)mem_size,
+   lpm = rte_zmalloc_socket(mem_name, (size_t)mem_size,
RTE_CACHE_LINE_SIZE, socket_id);
 
if (lpm == NULL) {
@@ -176,7 +176,7 @@ rte_lpm6_create(const c

[dpdk-dev] [PATCH v2] doc: fix link bonding PMD typo in prog guide

2018-01-12 Thread Zhiyong Yang
fix one typo and a grammatical mistake.

Fixes: b0152b1b40fe ("doc: update bonding")
Cc: sta...@dpdk.org

Signed-off-by: Zhiyong Yang 
Acked-by: Marko Kovacevic 
---

Changes in V2:
1. Fix the title and fixline format issue in commit log.

 doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst 
b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
index 1ef231df9..6bb299f99 100644
--- a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
+++ b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
@@ -33,7 +33,7 @@ Link Bonding Poll Mode Driver Library
 
 In addition to Poll Mode Drivers (PMDs) for physical and virtual hardware,
 DPDK also includes a pure-software library that
-allows physical PMD's to be bonded together to create a single logical PMD.
+allows physical PMDs to be bonded together to create a single logical PMD.
 
 .. figure:: img/bond-overview.*
 
@@ -42,7 +42,7 @@ allows physical PMD's to be bonded together to create a 
single logical PMD.
 
 The Link Bonding PMD library(librte_pmd_bond) supports bonding of groups of
 ``rte_eth_dev`` ports of the same speed and duplex to provide
-similar the capabilities to that found in Linux bonding driver to allow the
+the similar capabilities to that found in Linux bonding driver to allow the
 aggregation of multiple (slave) NICs into a single logical interface between a
 server and a switch. The new bonded PMD will then process these interfaces
 based on the mode of operation specified to provide support for features such
-- 
2.13.3



[dpdk-dev] [PATCH] lib/librte_vhost: mov enum definition from PMD to lib

2018-01-12 Thread Zhiyong Yang
The enum definition is placed in librte_vhost in order to avoid many
duplication definitions in PMD and example code everywhere.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/vhost/rte_eth_vhost.c | 2 --
 examples/tep_termination/main.h   | 2 --
 examples/vhost/main.h | 2 --
 lib/librte_vhost/rte_vhost.h  | 2 ++
 4 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c 
b/drivers/net/vhost/rte_eth_vhost.c
index 2536ee4a2..1cd68433f 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -46,8 +46,6 @@
 
 #include "rte_eth_vhost.h"
 
-enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
-
 #define ETH_VHOST_IFACE_ARG"iface"
 #define ETH_VHOST_QUEUES_ARG   "queues"
 #define ETH_VHOST_CLIENT_ARG   "client"
diff --git a/examples/tep_termination/main.h b/examples/tep_termination/main.h
index 966c63a51..c0aad3613 100644
--- a/examples/tep_termination/main.h
+++ b/examples/tep_termination/main.h
@@ -25,8 +25,6 @@
 /* Max number of devices. Limited by the application. */
 #define MAX_DEVICES 64
 
-enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
-
 /* Per-device statistics struct */
 struct device_statistics {
uint64_t tx_total;
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index 764c33afe..ea89b080d 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -14,8 +14,6 @@
 #define RTE_LOGTYPE_VHOST_DATA   RTE_LOGTYPE_USER2
 #define RTE_LOGTYPE_VHOST_PORT   RTE_LOGTYPE_USER3
 
-enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
-
 #define MAX_PKT_BURST 32   /* Max burst size for RX/TX */
 
 struct device_statistics {
diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index d33206997..7d7ed1e62 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -29,6 +29,8 @@ extern "C" {
 #define RTE_VHOST_USER_DEQUEUE_ZERO_COPY   (1ULL << 2)
 #define RTE_VHOST_USER_IOMMU_SUPPORT   (1ULL << 3)
 
+enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
+
 /**
  * Information relating to memory regions including offsets to
  * addresses in QEMUs memory file.
-- 
2.13.3



[dpdk-dev] [PATCH v2] examples/vhost: fix remove dev_info.max_rx_queues checking to solve startup failure

2018-01-09 Thread Zhiyong Yang
For vhost sample, the operation if (dev_info.max_rx_queues >
MAX_QUEUES) in the function port_init causes startup failure
when using X710(i40e driver). X710 requires that MAX_QUEUES
should be defined no less than 320, however it is defined as
128 currently.

Such checking is overkill and Removal don't affect any
functionality (have already validated ixgbe and i40e).

The removal can avoid similar issue when introduing new physical
NIC.

Fixes: 8bd6c395a568("examples/vhost: increase maximum queue number")
Cc: sta...@dpdk.org

Signed-off-by: Zhiyong Yang 
---

Changes in V2:
1. Remove the checking instead of redefine macro "MAX_QUEUES"

 examples/vhost/main.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 10a7f5d32..1f532fe3b 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -279,12 +279,6 @@ port_init(uint16_t port)
/* The max pool number from dev_info will be used to validate the pool 
number specified in cmd line */
rte_eth_dev_info_get (port, &dev_info);
 
-   if (dev_info.max_rx_queues > MAX_QUEUES) {
-   rte_exit(EXIT_FAILURE,
-   "please define MAX_QUEUES no less than %u in %s\n",
-   dev_info.max_rx_queues, __FILE__);
-   }
-
rxconf = &dev_info.default_rxconf;
txconf = &dev_info.default_txconf;
rxconf->rx_drop_en = 1;
-- 
2.13.3



[dpdk-dev] [PATCH v3] bus/pci: fix wrong intr_handle.type with uio_pci_generic

2018-01-09 Thread Zhiyong Yang
For virtio legacy device, testpmd startup fails when using uio_pci_generic.

The issue is caused by invoking the function pci_ioport_map. The correct
value of intr_handle.type is already set before calling it, we should avoid
overwriting the default value "RTE_INTR_HANDLE_UNKNOWN" in this function.
Besides, the removal has no harm to other cases because it is set to 0 by a
memset on the whole struct during allocation in the function pci_scan_one.

Such assignments are removed in the meanwhile in pci_uio_map_resource(),
pci_vfio_map_resource_primary() and pci_vfio_map_resource_secondary() in
order to keep consistencies and avoid future questions.

Fixes: 756ce64b1ecd ("eal: introduce PCI ioport API")
Cc: sta...@dpdk.org
Signed-off-by: Zhiyong Yang 
---

Changes in V3:
1. Such assignments are removed in order to keep consistencies and avoid
future questions.

Changes in V2:
1. Reword the commit log.
2. Remove the assignment operation which causes the issue.

 drivers/bus/pci/linux/pci.c  | 1 -
 drivers/bus/pci/linux/pci_vfio.c | 2 --
 drivers/bus/pci/pci_common_uio.c | 1 -
 3 files changed, 4 deletions(-)

diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 25f907e04..3e97aa48e 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -694,7 +694,6 @@ pci_ioport_map(struct rte_pci_device *dev, int bar 
__rte_unused,
if (!found)
return -1;
 
-   dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
p->base = start;
RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%x\n", start);
 
diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index be986cbdb..aeeaa9ed8 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -430,7 +430,6 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
struct pci_map *maps;
 
dev->intr_handle.fd = -1;
-   dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 
/* store PCI address string */
snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
@@ -547,7 +546,6 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)
struct pci_map *maps;
 
dev->intr_handle.fd = -1;
-   dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 
/* store PCI address string */
snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c
index dd84ec8bf..54bc20b59 100644
--- a/drivers/bus/pci/pci_common_uio.c
+++ b/drivers/bus/pci/pci_common_uio.c
@@ -90,7 +90,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
dev->intr_handle.fd = -1;
dev->intr_handle.uio_cfg_fd = -1;
-   dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 
/* secondary processes - use already recorded details */
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-- 
2.13.3



[dpdk-dev] [PATCH] examples/vhost: fix extend MAX_QUEUES to resolve startup failure

2018-01-03 Thread Zhiyong Yang
When binding X710 NIC (i40e driver) to DPDK, vhost sample startups
failure.
The sample requires that MAX_QUEUES should be defined no less than 320.
So, the patch redefines MAX_QUEUES 320 to fix the issue.

Cc: sta...@dpdk.org
Signed-off-by: Zhiyong Yang 
---
 examples/vhost/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 89a61f0e5..487cc530e 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -57,7 +57,7 @@
 #include "main.h"
 
 #ifndef MAX_QUEUES
-#define MAX_QUEUES 128
+#define MAX_QUEUES 320
 #endif
 
 /* the maximum number of external ports supported */
-- 
2.13.3



[dpdk-dev] [PATCH v2] bus/pci: fix wrong intr_handle.type with uio_pci_generic

2017-12-28 Thread Zhiyong Yang
For virtio legacy device, testpmd startup fails when using
uio_pci_generic. The issue is caused by invoking the function
pci_ioport_map. The right intr_handle.type is already set before
calling it, we should avoid overwriting the default value "RTE_
INTR_HANDLE_UNKNOWN" in it. Besides, the removal has no harm to
other cases since it already is set to this value (0) at init.

Fixes: 756ce64b1ecd ("eal: introduce PCI ioport API")
Cc: sta...@dpdk.org
Signed-off-by: Zhiyong Yang 
---

Changes in V2:
1. reword the commit log.
2. remove the assignment operation which causes the issue.

 drivers/bus/pci/linux/pci.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 5da6728fb..ec31216bc 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -723,7 +723,6 @@ pci_ioport_map(struct rte_pci_device *dev, int bar 
__rte_unused,
if (!found)
return -1;
 
-   dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
p->base = start;
RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%x\n", start);
 
-- 
2.13.3



[dpdk-dev] [PATCH] doc: fix link bonding pmd typo in prog guide

2017-12-28 Thread Zhiyong Yang
fix one typo and a grammatical mistake.

Fixes: b0152b1b40fe("doc: update bonding")
Signed-off-by: Zhiyong Yang 
---
 doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst 
b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
index 1ef231df9..244424269 100644
--- a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
+++ b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
@@ -33,7 +33,7 @@ Link Bonding Poll Mode Driver Library
 
 In addition to Poll Mode Drivers (PMDs) for physical and virtual hardware,
 DPDK also includes a pure-software library that
-allows physical PMD's to be bonded together to create a single logical PMD.
+allows physical PMDs to be bonded together to create a single logical PMD.
 
 .. figure:: img/bond-overview.*
 
@@ -42,7 +42,7 @@ allows physical PMD's to be bonded together to create a 
single logical PMD.
 
 The Link Bonding PMD library(librte_pmd_bond) supports bonding of groups of
 ``rte_eth_dev`` ports of the same speed and duplex to provide
-similar the capabilities to that found in Linux bonding driver to allow the
+the capabilities similar to that found in Linux bonding driver to allow the
 aggregation of multiple (slave) NICs into a single logical interface between a
 server and a switch. The new bonded PMD will then process these interfaces
 based on the mode of operation specified to provide support for features such
-- 
2.13.3



[dpdk-dev] [PATCH] bus/pci: fix wrong intr_handle.type with uio_pci_generic

2017-12-27 Thread Zhiyong Yang
In the function rte_pci_ioport_map, if uio_pci_generic is used on X86
platform, pci_ioport_map() is invoked, the operation
ev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN; is execused directly,
it causes the wrong assignment for uio_pci_generic, the patch fixes it.

Fixes: 756ce64b1ecd ("eal: introduce PCI ioport API")
Cc: sta...@dpdk.org
Signed-off-by: Zhiyong Yang 
---
 drivers/bus/pci/linux/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 5da6728fb..8ff7dbfd7 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -723,7 +723,9 @@ pci_ioport_map(struct rte_pci_device *dev, int bar 
__rte_unused,
if (!found)
return -1;
 
-   dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+   if (dev->kdrv == RTE_KDRV_NONE)
+   dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
p->base = start;
RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%x\n", start);
 
-- 
2.13.3



[dpdk-dev] [PATCH] net/virtio: fix wrong use_msix value for legacy device

2017-12-27 Thread Zhiyong Yang
If virtio fails to detect modern device, use_misx should be reset
to VIRTIO_MSIX_NONE, otherwise this wrong value will be used after
legacy device detection succeeds to be done.

Fixes: fe19d49cb525 ("net/virtio: fix Rx interrupt with VFIO")
Cc: sta...@dpdk.org
Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_pci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index 9574498fb..5582238fd 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -695,6 +695,7 @@ vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw)
return 0;
}
 
+   hw->use_msix = VIRTIO_MSIX_NONE;
PMD_INIT_LOG(INFO, "trying with legacy virtio pci.");
if (rte_pci_ioport_map(dev, 0, VTPCI_IO(hw)) < 0) {
if (dev->kdrv == RTE_KDRV_UNKNOWN &&
-- 
2.13.3



[dpdk-dev] [PATCH] net/virtio: remove unnecessary macro definitions

2017-12-26 Thread Zhiyong Yang
DPDK has already the definition of Ethernet numeric link speeds in Mbps in
the file Rte_ethdev.h, it is unnecessary to rededine virtio specific link
speeds macros again.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_ethdev.c | 2 +-
 drivers/net/virtio/virtio_ethdev.h | 5 -
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index e0328f61d..db89cc32d 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1965,7 +1965,7 @@ virtio_dev_link_update(struct rte_eth_dev *dev, 
__rte_unused int wait_to_complet
virtio_dev_atomic_read_link_status(dev, &link);
old = link;
link.link_duplex = ETH_LINK_FULL_DUPLEX;
-   link.link_speed  = SPEED_10G;
+   link.link_speed  = ETH_SPEED_NUM_10G;
 
if (hw->started == 0) {
link.link_status = ETH_LINK_DOWN;
diff --git a/drivers/net/virtio/virtio_ethdev.h 
b/drivers/net/virtio/virtio_ethdev.h
index 2039bc547..6387a44f9 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -38,11 +38,6 @@
 
 #include "virtio_pci.h"
 
-#define SPEED_10   10
-#define SPEED_100  100
-#define SPEED_1000 1000
-#define SPEED_10G  1
-
 #ifndef PAGE_SIZE
 #define PAGE_SIZE 4096
 #endif
-- 
2.13.3



[dpdk-dev] [PATCH] lib/librte_vhost: remove redundant logic judgement

2017-12-25 Thread Zhiyong Yang
At the beginning of vring_translate, the code
if(!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) already judges
if IOMMU_PLATFORM is supported. The function vhost_iova_to_vva always
repeats the logic, __vhost_iova_to_vva can be used directly to avoid it
here.

Signed-off-by: Zhiyong Yang 
---
 lib/librte_vhost/vhost.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 4f8b73a09..bb615fd2a 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -157,7 +157,7 @@ vring_translate(struct virtio_net *dev, struct 
vhost_virtqueue *vq)
goto out;
 
size = sizeof(struct vring_desc) * vq->size;
-   vq->desc = (struct vring_desc *)(uintptr_t)vhost_iova_to_vva(dev, vq,
+   vq->desc = (struct vring_desc *)(uintptr_t)__vhost_iova_to_vva(dev, vq,
vq->ring_addrs.desc_user_addr,
size, VHOST_ACCESS_RW);
if (!vq->desc)
@@ -165,7 +165,8 @@ vring_translate(struct virtio_net *dev, struct 
vhost_virtqueue *vq)
 
size = sizeof(struct vring_avail);
size += sizeof(uint16_t) * vq->size;
-   vq->avail = (struct vring_avail *)(uintptr_t)vhost_iova_to_vva(dev, vq,
+   vq->avail = (struct vring_avail *)(uintptr_t)__vhost_iova_to_vva(dev,
+   vq,
vq->ring_addrs.avail_user_addr,
size, VHOST_ACCESS_RW);
if (!vq->avail)
@@ -173,7 +174,7 @@ vring_translate(struct virtio_net *dev, struct 
vhost_virtqueue *vq)
 
size = sizeof(struct vring_used);
size += sizeof(struct vring_used_elem) * vq->size;
-   vq->used = (struct vring_used *)(uintptr_t)vhost_iova_to_vva(dev, vq,
+   vq->used = (struct vring_used *)(uintptr_t)__vhost_iova_to_vva(dev, vq,
vq->ring_addrs.used_user_addr,
size, VHOST_ACCESS_RW);
if (!vq->used)
-- 
2.13.3



[dpdk-dev] [PATCH 08/11] net/vhostpci: add RX function

2017-11-30 Thread Zhiyong Yang
Add the functions to support receiving packets.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/vhostpci/vhostpci_ethdev.c | 311 +
 1 file changed, 311 insertions(+)

diff --git a/drivers/net/vhostpci/vhostpci_ethdev.c 
b/drivers/net/vhostpci/vhostpci_ethdev.c
index 0582f73b7..06e3f5c50 100644
--- a/drivers/net/vhostpci/vhostpci_ethdev.c
+++ b/drivers/net/vhostpci/vhostpci_ethdev.c
@@ -49,6 +49,10 @@
 #include "vhostpci_logs.h"
 #include "vhostpci_ethdev.h"
 
+#define MAX_BATCH_LEN 256
+#define VHOSTPCI_MAX_PKT_BURST 32
+#define VHOSTPCI_BUF_VECTOR_MAX 256
+
 static void
 vhostpci_dev_info_get(struct rte_eth_dev *dev,
struct rte_eth_dev_info *dev_info);
@@ -92,6 +96,10 @@ vhostpci_dev_tx_queue_setup(struct rte_eth_dev *dev, 
uint16_t tx_queue_id,
 static int
 vhostpci_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features);
 
+static uint16_t
+vhostpci_dequeue_burst(struct vhostpci_net *dev, uint16_t queue_id,
+   struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);
+
 static int
 vhostpci_dev_start(struct rte_eth_dev *dev);
 
@@ -313,6 +321,308 @@ vhostpci_dev_tx_queue_setup(struct rte_eth_dev *dev, 
uint16_t tx_queue_id,
return 0;
 }
 
+static __rte_always_inline void
+update_used_ring(struct vhostpci_virtqueue *vq,
+uint32_t used_idx, uint32_t desc_idx)
+{
+   vq->used->ring[used_idx].id  = desc_idx;
+   vq->used->ring[used_idx].len = 0;
+}
+
+static __rte_always_inline int
+copy_desc_to_mbuf(struct vhostpci_net *dev, struct vhostpci_virtqueue *vq,
+ struct vring_desc *descs, uint16_t max_desc,
+ struct rte_mbuf *m, uint16_t desc_idx,
+ struct rte_mempool *mbuf_pool)
+{
+   struct vring_desc *desc;
+   uint64_t desc_addr;
+   uint32_t desc_avail, desc_offset;
+   uint32_t mbuf_avail, mbuf_offset;
+   uint32_t cpy_len;
+   struct rte_mbuf *cur = m, *prev = m;
+   /* A counter to avoid desc dead loop chain */
+   uint32_t nr_desc = 1;
+   struct batch_copy_elem *batch_copy = vq->batch_copy_elems;
+   uint16_t copy_nb = vq->batch_copy_nb_elems;
+   int error = 0;
+
+   desc = &descs[desc_idx];
+   if (unlikely(desc->len < dev->vhost_hlen)) {
+   error = -1;
+   goto out;
+   }
+
+   desc_addr = remote_gpa_to_vva(dev, desc->addr);
+
+   if (unlikely(!desc_addr)) {
+   error = -1;
+   goto out;
+   }
+
+   /**
+* A virtio driver normally uses at least 2 desc buffers
+* for Tx: the first for storing the header, and others
+* for storing the data.
+*/
+   if (likely((desc->len == dev->vhost_hlen) &&
+  (desc->flags & VRING_DESC_F_NEXT) != 0)) {
+   desc = &descs[desc->next];
+   if (unlikely(desc->flags & VRING_DESC_F_INDIRECT)) {
+   error = -1;
+   goto out;
+   }
+
+   desc_addr = remote_gpa_to_vva(dev, desc->addr);
+   if (unlikely(!desc_addr)) {
+   error = -1;
+   goto out;
+   }
+
+   desc_offset = 0;
+   desc_avail  = desc->len;
+   nr_desc+= 1;
+   } else {
+   desc_avail  = desc->len - dev->vhost_hlen;
+   desc_offset = dev->vhost_hlen;
+   }
+
+   rte_prefetch0((void *)(uintptr_t)(desc_addr + desc_offset));
+
+   mbuf_offset = 0;
+   mbuf_avail  = m->buf_len - RTE_PKTMBUF_HEADROOM;
+   while (1) {
+   cpy_len = RTE_MIN(desc_avail, mbuf_avail);
+   if (likely(cpy_len > MAX_BATCH_LEN ||
+  copy_nb >= vq->size ||
+  (cur == m))) {
+   rte_memcpy(rte_pktmbuf_mtod_offset(cur, void *,
+   mbuf_offset), (void *)((uintptr_t)(desc_addr +
+   desc_offset)), cpy_len);
+   } else {
+   batch_copy[copy_nb].dst =
+   rte_pktmbuf_mtod_offset(cur, void *,
+   mbuf_offset);
+   batch_copy[copy_nb].src =
+   (void *)((uintptr_t)(desc_addr +
+desc_offset));
+   batch_copy[copy_nb].len = cpy_len;
+   copy_nb++;
+   }
+
+   mbuf_avail  -= cpy_len;
+   mbuf_offset += cpy_len;
+   desc_avail  -= cpy_len;
+   desc_offset += cpy_len;
+
+   /* This desc reaches to its end, get the next one */
+   if (desc_avail == 0) {
+   if ((desc->fl

[dpdk-dev] [PATCH 09/11] net/vhostpci: add TX function

2017-11-30 Thread Zhiyong Yang
add the functions to support transmitting packets.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/vhostpci/vhostpci_ethdev.c | 352 +
 1 file changed, 352 insertions(+)

diff --git a/drivers/net/vhostpci/vhostpci_ethdev.c 
b/drivers/net/vhostpci/vhostpci_ethdev.c
index 06e3f5c50..f233d85a8 100644
--- a/drivers/net/vhostpci/vhostpci_ethdev.c
+++ b/drivers/net/vhostpci/vhostpci_ethdev.c
@@ -53,6 +53,12 @@
 #define VHOSTPCI_MAX_PKT_BURST 32
 #define VHOSTPCI_BUF_VECTOR_MAX 256
 
+/* avoid write operation when necessary, to lessen cache issues */
+#define ASSIGN_UNLESS_EQUAL(var, val) do { \
+   if ((var) != (val)) \
+   (var) = (val);  \
+} while (0)
+
 static void
 vhostpci_dev_info_get(struct rte_eth_dev *dev,
struct rte_eth_dev_info *dev_info);
@@ -100,6 +106,10 @@ static uint16_t
 vhostpci_dequeue_burst(struct vhostpci_net *dev, uint16_t queue_id,
struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);
 
+static uint16_t
+vhostpci_dequeue_burst(struct vhostpci_net *dev, uint16_t queue_id,
+   struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);
+
 static int
 vhostpci_dev_start(struct rte_eth_dev *dev);
 
@@ -321,6 +331,346 @@ vhostpci_dev_tx_queue_setup(struct rte_eth_dev *dev, 
uint16_t tx_queue_id,
return 0;
 }
 
+
+static inline void
+do_data_copy_enqueue(struct vhostpci_virtqueue *vq)
+{
+   struct batch_copy_elem *elem = vq->batch_copy_elems;
+   uint16_t count = vq->batch_copy_nb_elems;
+   int i;
+
+   for (i = 0; i < count; i++)
+   rte_memcpy(elem[i].dst, elem[i].src, elem[i].len);
+}
+
+static __rte_always_inline int
+copy_mbuf_to_desc_mergeable(struct vhostpci_net *dev,
+   struct vhostpci_virtqueue *vq, struct rte_mbuf *m,
+   struct buf_vector *buf_vec, uint16_t num_buffers)
+{
+   uint32_t vec_idx = 0;
+   uint64_t desc_addr;
+   uint32_t mbuf_offset, mbuf_avail;
+   uint32_t desc_offset, desc_avail;
+   uint32_t cpy_len;
+   uint64_t hdr_addr;
+   struct batch_copy_elem *batch_copy = vq->batch_copy_elems;
+   uint16_t copy_nb = vq->batch_copy_nb_elems;
+   int error = 0;
+
+   if (unlikely(m == NULL)) {
+   error = -1;
+   goto out;
+   }
+
+   desc_addr = remote_gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
+
+   if (buf_vec[vec_idx].buf_len < dev->vhost_hlen || !desc_addr) {
+   error = -1;
+   goto out;
+   }
+
+   hdr_addr = desc_addr;
+   rte_prefetch0((void *)(uintptr_t)hdr_addr);
+
+   desc_avail  = buf_vec[vec_idx].buf_len - dev->vhost_hlen;
+   desc_offset = dev->vhost_hlen;
+
+   mbuf_avail  = rte_pktmbuf_data_len(m);
+   mbuf_offset = 0;
+   while (mbuf_avail != 0 || m->next != NULL) {
+   /* done with current desc buf, get the next one */
+   if (desc_avail == 0) {
+   vec_idx++;
+   desc_addr = remote_gpa_to_vva(dev,
+   buf_vec[vec_idx].buf_addr);
+
+   if (unlikely(!desc_addr)) {
+   error = -1;
+   goto out;
+   }
+
+   /* Prefetch buffer address. */
+   rte_prefetch0((void *)(uintptr_t)desc_addr);
+   desc_offset = 0;
+   desc_avail  = buf_vec[vec_idx].buf_len;
+   }
+
+   /* done with current mbuf, get the next one */
+   if (mbuf_avail == 0) {
+   m = m->next;
+   mbuf_offset = 0;
+   mbuf_avail  = rte_pktmbuf_data_len(m);
+   }
+
+   if (hdr_addr) {
+   struct virtio_net_hdr_mrg_rxbuf *hdr;
+
+   hdr = (struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)
+   hdr_addr;
+   ASSIGN_UNLESS_EQUAL(hdr->num_buffers, num_buffers);
+   hdr_addr = 0;
+   }
+
+   cpy_len = RTE_MIN(desc_avail, mbuf_avail);
+
+   if (likely(cpy_len > MAX_BATCH_LEN || copy_nb >= vq->size)) {
+   rte_memcpy((void *)((uintptr_t)(desc_addr +
+   desc_offset)),
+   rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
+   cpy_len);
+
+   } else {
+   batch_copy[copy_nb].dst =
+   (void *)((uintptr_t)(desc_addr + desc_offset));
+   batch_copy[copy_nb].src =
+   rte_pktmbuf_mtod_offset(m, void *, mbuf_offset);
+   batch_copy[copy_nb].l

[dpdk-dev] [PATCH 11/11] net/vhostpci: update release note

2017-11-30 Thread Zhiyong Yang
update release note doc.
update MAINTAINERS file.

Signed-off-by: Zhiyong Yang 
---
 MAINTAINERS| 6 ++
 doc/guides/rel_notes/release_18_02.rst | 6 ++
 2 files changed, 12 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f0baeb423..7db0cfa35 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -525,6 +525,12 @@ T: git://dpdk.org/next/dpdk-next-virtio
 F: drivers/net/vhost/
 F: doc/guides/nics/features/vhost.ini
 
+Vhostpci PMD
+M: Zhiyong Yang 
+F: drivers/net/vhostpci/
+F: doc/guides/nics/vhostpci.rst
+F: doc/guides/nics/features/vhostpci.ini
+
 Virtio PMD
 M: Yuanhan Liu 
 M: Maxime Coquelin 
diff --git a/doc/guides/rel_notes/release_18_02.rst 
b/doc/guides/rel_notes/release_18_02.rst
index 24b67bb8b..b9f251db4 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -41,6 +41,11 @@ New Features
  Also, make sure to start the actual text at the margin.
  =
 
+* **Added vhostpci PMD.**
+
+  Added a new ``vhostpci PMD`` to drive ``vhostpci device``, which is a new
+  virtio pci device. Vhostpci PMD works in pair with virtio-net PMD to achieve
+  point-to-point communication between VMs.
 
 API Changes
 ---
@@ -154,6 +159,7 @@ The libraries prepended with a plus sign were incremented 
in this version.
  librte_pmd_ring.so.2
  librte_pmd_softnic.so.1
  librte_pmd_vhost.so.2
+ librte_pmd_vhostpci.so.1
  librte_port.so.3
  librte_power.so.1
  librte_reorder.so.1
-- 
2.13.3



[dpdk-dev] [PATCH 07/11] net/vhostpci: get remote memory region and vring info

2017-11-30 Thread Zhiyong Yang
Linking up status is triggered to indicate that remote memory regions
and vring info have been ready, Vhostpci PMD can get them.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/vhostpci/vhostpci_ethdev.c | 81 ++
 1 file changed, 81 insertions(+)

diff --git a/drivers/net/vhostpci/vhostpci_ethdev.c 
b/drivers/net/vhostpci/vhostpci_ethdev.c
index 76353930a..0582f73b7 100644
--- a/drivers/net/vhostpci/vhostpci_ethdev.c
+++ b/drivers/net/vhostpci/vhostpci_ethdev.c
@@ -73,6 +73,9 @@ static int
 vhostpci_dev_atomic_write_link_status(struct rte_eth_dev *dev,
struct rte_eth_link *link);
 
+static inline uint64_t
+remote_gpa_to_vva(struct vhostpci_net *vpnet, uint64_t remote_gpa);
+
 static int
 vhostpci_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
   uint16_t nb_rx_desc __rte_unused,
@@ -105,6 +108,9 @@ vhostpci_dev_close(struct rte_eth_dev *dev);
 static void
 vhostpci_dev_stop(struct rte_eth_dev *dev);
 
+static int
+vhostpci_get_remote_mem(struct rte_eth_dev *dev);
+
 static const struct eth_dev_ops vhostpci_eth_dev_ops = {
.dev_start   = vhostpci_dev_start,
.dev_stop= vhostpci_dev_stop,
@@ -335,6 +341,71 @@ vhostpci_dev_atomic_write_link_status(struct rte_eth_dev 
*dev,
return 0;
 }
 
+static inline uint64_t
+remote_gpa_to_vva(struct vhostpci_net *vpnet, uint64_t remote_gpa)
+{
+   uint64_t mem_base = vpnet->mem_base;
+   uint32_t i, nregions = vpnet->mem.nregions;
+   struct vhostpci_mem_region *regions = vpnet->mem.regions;
+
+   for (i = 0; i < nregions; i++) {
+   if (remote_gpa > regions[i].start &&
+   remote_gpa < regions[i].end)
+
+   return (remote_gpa - regions[i].start
+   + regions[i].offset + mem_base);
+   }
+
+   return 0;
+}
+
+static int
+vhostpci_get_remote_mem(struct rte_eth_dev *dev)
+{
+   struct vpnet_metadata *metadata;
+   struct rte_mem_resource *mem_resource;
+   struct rte_pci_device *pci_device = RTE_ETH_DEV_TO_PCI(dev);
+   struct vhostpci_mem_region *regions;
+   struct vpnet_remote_vq *vq;
+   struct vhostpci_net *vpnet;
+   struct vhostpci_virtqueue *virtqueue[VHOSTPCI_MAX_QUEUE_PAIRS * 2];
+   struct vhostpci_hw *hw = dev->data->dev_private;
+   uint64_t offset = 0;
+   uint32_t i;
+
+   vpnet = hw->vpnet;
+   mem_resource = pci_device->mem_resource;
+   metadata = mem_resource[REMOTE_MEM_BAR_ID].addr;
+
+   vpnet->mem_base = (uint64_t)metadata + METADATA_SIZE;
+   vpnet->mem.nregions = metadata->nregions;
+   vpnet->nr_vring = metadata->nvqs;
+   regions = vpnet->mem.regions;
+
+   for (i = 0; i < metadata->nregions; i++) {
+   regions[i].guest_phys_addr = metadata->mem[i].gpa;
+   regions[i].size = metadata->mem[i].size;
+   regions[i].start = metadata->mem[i].gpa;
+   regions[i].end = metadata->mem[i].gpa + metadata->mem[i].size;
+   regions[i].offset = offset;
+   offset += regions[i].size;
+   }
+
+   vq = metadata->vq;
+   for (i = 0; i < vpnet->nr_vring; i++) {
+   virtqueue[i] = vpnet->virtqueue[i];
+   virtqueue[i]->desc  = (struct vring_desc 
*)remote_gpa_to_vva(vpnet, vq[i].desc_gpa);
+   virtqueue[i]->avail = (struct vring_avail 
*)remote_gpa_to_vva(vpnet, vq[i].avail_gpa);
+   virtqueue[i]->used  = (struct vring_used 
*)remote_gpa_to_vva(vpnet, vq[i].used_gpa);
+   virtqueue[i]->last_avail_idx = vq[i].last_avail_idx;
+   virtqueue[i]->enabled = vq[i].vring_enabled;
+   virtqueue[i]->last_used_idx = 0;
+   virtqueue[i]->size  = VHOSTPCI_NUM_DESCRIPTORS;
+   }
+
+   return 0;
+}
+
 static int
 vhostpci_dev_link_update(struct rte_eth_dev *dev,
int wait_to_complete __rte_unused)
@@ -362,9 +433,19 @@ vhostpci_dev_link_update(struct rte_eth_dev *dev,
 dev->data->port_id);
 
} else {
+   int ret;
+
link.link_status = ETH_LINK_UP;
PMD_INIT_LOG(DEBUG, "Port %d is up",
 dev->data->port_id);
+
+   /* get the remote guest memory region and vring info */
+   vhostpci_get_remote_mem(dev);
+
+   ret = vhostpci_init_device(dev,
+   VHOSTPCI_PMD_DEFAULT_GUEST_FEATURES);
+   if (ret < 0)
+   return ret;
}
}
 
-- 
2.13.3



[dpdk-dev] [PATCH 10/11] net/vhostpci: support RX/TX packets statistics

2017-11-30 Thread Zhiyong Yang
Add the functions to support for TX/RX pkts statistics.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/vhostpci/vhostpci_ethdev.c | 73 ++
 1 file changed, 73 insertions(+)

diff --git a/drivers/net/vhostpci/vhostpci_ethdev.c 
b/drivers/net/vhostpci/vhostpci_ethdev.c
index f233d85a8..3dd09e2ea 100644
--- a/drivers/net/vhostpci/vhostpci_ethdev.c
+++ b/drivers/net/vhostpci/vhostpci_ethdev.c
@@ -129,11 +129,19 @@ vhostpci_dev_stop(struct rte_eth_dev *dev);
 static int
 vhostpci_get_remote_mem(struct rte_eth_dev *dev);
 
+static void
+vhostpci_dev_stats_reset(struct rte_eth_dev *dev);
+
+static int
+vhostpci_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
+
 static const struct eth_dev_ops vhostpci_eth_dev_ops = {
.dev_start   = vhostpci_dev_start,
.dev_stop= vhostpci_dev_stop,
.dev_close   = vhostpci_dev_close,
.dev_infos_get   = vhostpci_dev_info_get,
+   .stats_get   = vhostpci_dev_stats_get,
+   .stats_reset = vhostpci_dev_stats_reset,
.dev_configure   = vhostpci_dev_configure,
.link_update = vhostpci_dev_link_update,
.rx_queue_setup  = vhostpci_dev_rx_queue_setup,
@@ -284,6 +292,71 @@ vhostpci_dev_configure(struct rte_eth_dev *dev 
__rte_unused)
 }
 
 static int
+vhostpci_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
+{
+   int i;
+   unsigned long rx_total = 0, tx_total = 0, tx_missed_total = 0;
+   unsigned long rx_total_bytes = 0, tx_total_bytes = 0;
+   struct vhostpci_queue *vq;
+
+   for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
+   i < dev->data->nb_rx_queues; i++) {
+   if (dev->data->rx_queues[i] == NULL)
+   continue;
+   vq = dev->data->rx_queues[i];
+   stats->q_ipackets[i] = vq->stats.pkts;
+   rx_total += stats->q_ipackets[i];
+
+   stats->q_ibytes[i] = vq->stats.bytes;
+   rx_total_bytes += stats->q_ibytes[i];
+   }
+
+   for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
+   i < dev->data->nb_tx_queues; i++) {
+   if (dev->data->tx_queues[i] == NULL)
+   continue;
+   vq = dev->data->tx_queues[i];
+   stats->q_opackets[i] = vq->stats.pkts;
+   tx_missed_total += vq->stats.missed_pkts;
+   tx_total += stats->q_opackets[i];
+
+   stats->q_obytes[i] = vq->stats.bytes;
+   tx_total_bytes += stats->q_obytes[i];
+   }
+
+   stats->ipackets = rx_total;
+   stats->opackets = tx_total;
+   stats->oerrors = tx_missed_total;
+   stats->ibytes = rx_total_bytes;
+   stats->obytes = tx_total_bytes;
+
+   return 0;
+}
+
+static void
+vhostpci_dev_stats_reset(struct rte_eth_dev *dev)
+{
+   struct vhostpci_queue *vq;
+   int i;
+
+   for (i = 0; i < dev->data->nb_rx_queues; i++) {
+   if (dev->data->rx_queues[i] == NULL)
+   continue;
+   vq = dev->data->rx_queues[i];
+   vq->stats.pkts = 0;
+   vq->stats.bytes = 0;
+   }
+   for (i = 0; i < dev->data->nb_tx_queues; i++) {
+   if (dev->data->tx_queues[i] == NULL)
+   continue;
+   vq = dev->data->tx_queues[i];
+   vq->stats.pkts = 0;
+   vq->stats.bytes = 0;
+   vq->stats.missed_pkts = 0;
+   }
+}
+
+static int
 vhostpci_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
uint16_t nb_rx_desc __rte_unused,
unsigned int socket_id,
-- 
2.13.3



[dpdk-dev] [PATCH 04/11] net/vhostpci: add basic framework

2017-11-30 Thread Zhiyong Yang
This commit introduces the vhostpci framework in DPDK. Including:

1. Register vhostpci PMD.
2. Implement the pci device probe and remove functions.
3. vhostpci_net PMD allocates memory and initializes.
4. start, stop, close and info_gets functions.

Signed-off-by: Zhiyong Yang 
---
 config/common_linuxapp |   1 +
 drivers/net/vhostpci/Makefile  |   2 +
 drivers/net/vhostpci/vhostpci_ethdev.c | 539 +
 drivers/net/vhostpci/vhostpci_pci.c| 334 
 mk/rte.app.mk  |   1 +
 5 files changed, 877 insertions(+)
 create mode 100644 drivers/net/vhostpci/vhostpci_ethdev.c
 create mode 100644 drivers/net/vhostpci/vhostpci_pci.c

diff --git a/config/common_linuxapp b/config/common_linuxapp
index 74c7d64ec..d5e2132a3 100644
--- a/config/common_linuxapp
+++ b/config/common_linuxapp
@@ -49,4 +49,5 @@ CONFIG_RTE_LIBRTE_PMD_TAP=y
 CONFIG_RTE_LIBRTE_AVP_PMD=y
 CONFIG_RTE_LIBRTE_NFP_PMD=y
 CONFIG_RTE_LIBRTE_POWER=y
+CONFIG_RTE_LIBRTE_VHOSTPCI_PMD=y
 CONFIG_RTE_VIRTIO_USER=y
diff --git a/drivers/net/vhostpci/Makefile b/drivers/net/vhostpci/Makefile
index 3467e7cbe..3089e54d8 100644
--- a/drivers/net/vhostpci/Makefile
+++ b/drivers/net/vhostpci/Makefile
@@ -48,5 +48,7 @@ LIBABIVER := 1
 #
 # all source are stored in SRCS-y
 #
+SRCS-$(CONFIG_RTE_LIBRTE_VHOSTPCI_PMD) += vhostpci_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_VHOSTPCI_PMD) += vhostpci_ethdev.c
 
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/drivers/net/vhostpci/vhostpci_ethdev.c 
b/drivers/net/vhostpci/vhostpci_ethdev.c
new file mode 100644
index 0..873ff7482
--- /dev/null
+++ b/drivers/net/vhostpci/vhostpci_ethdev.c
@@ -0,0 +1,539 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   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 
+#include 
+#include 
+
+#include "vhostpci_logs.h"
+#include "vhostpci_ethdev.h"
+
+static void
+vhostpci_dev_info_get(struct rte_eth_dev *dev,
+   struct rte_eth_dev_info *dev_info);
+
+static void
+vhostpci_get_hwaddr(struct vhostpci_hw *hw);
+
+static int
+vhostpci_dev_configure(struct rte_eth_dev *dev);
+
+static int
+eth_vhostpci_dev_init(struct rte_eth_dev *eth_dev);
+
+static int
+vhostpci_dev_atomic_write_link_status(struct rte_eth_dev *dev,
+   struct rte_eth_link *link);
+
+static int
+vhostpci_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features);
+
+static int
+vhostpci_dev_start(struct rte_eth_dev *dev);
+
+static void
+update_queuing_status(struct rte_eth_dev *dev);
+
+static void
+vhostpci_dev_close(struct rte_eth_dev *dev);
+
+static void
+vhostpci_dev_stop(struct rte_eth_dev *dev);
+
+static const struct eth_dev_ops vhostpci_eth_dev_ops = {
+   .dev_start   = vhostpci_dev_start,
+   .dev_stop= vhostpci_dev_stop,
+   .dev_close   = vhostpci_dev_close,
+   .dev_infos_get   = vhostpci_dev_info_get,
+   .dev_configure   = vhostpci_dev_configure,
+};
+
+static inline bool
+is_valid_virt_queue_idx(uint32_t idx, int is_tx, uint32_t nr_vring)
+{
+   return (is_tx ^ (idx & 1)) == 0 && idx < nr_vring;
+}
+
+static int
+vhostpci_negotiate_features(

[dpdk-dev] [PATCH 06/11] net/vhostpci: add support for link status change

2017-11-30 Thread Zhiyong Yang
Signed-off-by: Zhiyong Yang 
---
 drivers/net/vhostpci/vhostpci_ethdev.c | 102 +
 1 file changed, 102 insertions(+)

diff --git a/drivers/net/vhostpci/vhostpci_ethdev.c 
b/drivers/net/vhostpci/vhostpci_ethdev.c
index 068c19b2b..76353930a 100644
--- a/drivers/net/vhostpci/vhostpci_ethdev.c
+++ b/drivers/net/vhostpci/vhostpci_ethdev.c
@@ -54,6 +54,9 @@ vhostpci_dev_info_get(struct rte_eth_dev *dev,
struct rte_eth_dev_info *dev_info);
 
 static void
+vhostpci_interrupt_handler(void *param);
+
+static void
 vhostpci_get_hwaddr(struct vhostpci_hw *hw);
 
 static int
@@ -63,6 +66,10 @@ static int
 eth_vhostpci_dev_init(struct rte_eth_dev *eth_dev);
 
 static int
+vhostpci_dev_atomic_read_link_status(struct rte_eth_dev *dev,
+   struct rte_eth_link *link);
+
+static int
 vhostpci_dev_atomic_write_link_status(struct rte_eth_dev *dev,
struct rte_eth_link *link);
 
@@ -85,6 +92,10 @@ vhostpci_init_device(struct rte_eth_dev *eth_dev, uint64_t 
req_features);
 static int
 vhostpci_dev_start(struct rte_eth_dev *dev);
 
+static int
+vhostpci_dev_link_update(struct rte_eth_dev *dev,
+__rte_unused int wait_to_complete);
+
 static void
 update_queuing_status(struct rte_eth_dev *dev);
 
@@ -100,6 +111,7 @@ static const struct eth_dev_ops vhostpci_eth_dev_ops = {
.dev_close   = vhostpci_dev_close,
.dev_infos_get   = vhostpci_dev_info_get,
.dev_configure   = vhostpci_dev_configure,
+   .link_update = vhostpci_dev_link_update,
.rx_queue_setup  = vhostpci_dev_rx_queue_setup,
.tx_queue_setup  = vhostpci_dev_tx_queue_setup,
 };
@@ -296,6 +308,20 @@ vhostpci_dev_tx_queue_setup(struct rte_eth_dev *dev, 
uint16_t tx_queue_id,
 }
 
 static int
+vhostpci_dev_atomic_read_link_status(struct rte_eth_dev *dev,
+   struct rte_eth_link *link)
+{
+   struct rte_eth_link *dst = link;
+   struct rte_eth_link *src = &(dev->data->dev_link);
+
+   if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
+   *(uint64_t *)src) == 0)
+   return -1;
+
+   return 0;
+}
+
+static int
 vhostpci_dev_atomic_write_link_status(struct rte_eth_dev *dev,
struct rte_eth_link *link)
 {
@@ -309,6 +335,70 @@ vhostpci_dev_atomic_write_link_status(struct rte_eth_dev 
*dev,
return 0;
 }
 
+static int
+vhostpci_dev_link_update(struct rte_eth_dev *dev,
+   int wait_to_complete __rte_unused)
+{
+   struct rte_eth_link link, old;
+   uint16_t status;
+   struct vhostpci_hw *hw = dev->data->dev_private;
+
+   memset(&link, 0, sizeof(link));
+   vhostpci_dev_atomic_read_link_status(dev, &link);
+   old = link;
+   link.link_duplex = ETH_LINK_FULL_DUPLEX;
+   link.link_speed  = ETH_SPEED_NUM_10G;
+
+   if (hw->started == 0) {
+   link.link_status = ETH_LINK_DOWN;
+   } else {
+   PMD_INIT_LOG(DEBUG, "Get link status from hw");
+   vhpci_read_dev_config(hw,
+   offsetof(struct vpnet_pci_config, status),
+   &status, sizeof(status));
+   if ((status & VHOSTPCI_NET_S_LINK_UP) == 0) {
+   link.link_status = ETH_LINK_DOWN;
+   PMD_INIT_LOG(DEBUG, "Port %d is down",
+dev->data->port_id);
+
+   } else {
+   link.link_status = ETH_LINK_UP;
+   PMD_INIT_LOG(DEBUG, "Port %d is up",
+dev->data->port_id);
+   }
+   }
+
+   vhostpci_dev_atomic_write_link_status(dev, &link);
+
+   return (old.link_status == link.link_status) ? -1 : 0;
+}
+
+/**
+ * Process vhostpci Config changed interrupt and call the callback
+ * if link state changed.
+ */
+static void
+vhostpci_interrupt_handler(void *param)
+{
+   struct rte_eth_dev *dev = param;
+   struct vhostpci_hw *hw = dev->data->dev_private;
+   uint8_t isr;
+
+   /* Read interrupt status which clears interrupt */
+   isr = vhpci_isr(hw);
+   PMD_DRV_LOG(INFO, "interrupt status = %x", isr);
+
+   if (rte_intr_enable(dev->intr_handle) < 0)
+   PMD_DRV_LOG(ERR, "interrupt enable failed");
+
+   if (isr & VIRTIO_PCI_ISR_CONFIG) {
+   if (vhostpci_dev_link_update(dev, 0) == 0)
+   _rte_eth_dev_callback_process(dev,
+   RTE_ETH_EVENT_INTR_LSC, NULL, NULL);
+   }
+
+}
+
 /* reset device and renegotiate features if needed */
 static int
 vhostpci_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
@@ -538,6 +628,13 @@ eth_vhostpci_dev_init(struct rte_eth_dev *eth_dev)
if (ret < 0)
  

[dpdk-dev] [PATCH 05/11] net/vhostpci: add queue setup

2017-11-30 Thread Zhiyong Yang
add the functions for setup the RX/TX queue.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/vhostpci/vhostpci_ethdev.c | 63 ++
 1 file changed, 63 insertions(+)

diff --git a/drivers/net/vhostpci/vhostpci_ethdev.c 
b/drivers/net/vhostpci/vhostpci_ethdev.c
index 873ff7482..068c19b2b 100644
--- a/drivers/net/vhostpci/vhostpci_ethdev.c
+++ b/drivers/net/vhostpci/vhostpci_ethdev.c
@@ -67,6 +67,19 @@ vhostpci_dev_atomic_write_link_status(struct rte_eth_dev 
*dev,
struct rte_eth_link *link);
 
 static int
+vhostpci_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
+  uint16_t nb_rx_desc __rte_unused,
+  unsigned int socket_id,
+  const struct rte_eth_rxconf *rx_conf __rte_unused,
+  struct rte_mempool *mb_pool);
+
+static int
+vhostpci_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
+  uint16_t nb_tx_desc __rte_unused,
+  unsigned int socket_id,
+  const struct rte_eth_txconf *tx_conf __rte_unused);
+
+static int
 vhostpci_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features);
 
 static int
@@ -87,6 +100,8 @@ static const struct eth_dev_ops vhostpci_eth_dev_ops = {
.dev_close   = vhostpci_dev_close,
.dev_infos_get   = vhostpci_dev_info_get,
.dev_configure   = vhostpci_dev_configure,
+   .rx_queue_setup  = vhostpci_dev_rx_queue_setup,
+   .tx_queue_setup  = vhostpci_dev_tx_queue_setup,
 };
 
 static inline bool
@@ -233,6 +248,54 @@ vhostpci_dev_configure(struct rte_eth_dev *dev 
__rte_unused)
 }
 
 static int
+vhostpci_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
+   uint16_t nb_rx_desc __rte_unused,
+   unsigned int socket_id,
+   const struct rte_eth_rxconf *rx_conf __rte_unused,
+   struct rte_mempool *mb_pool)
+{
+   struct vhostpci_queue *vq;
+   struct vhostpci_hw *hw = dev->data->dev_private;
+
+   vq = rte_zmalloc_socket(NULL, sizeof(struct vhostpci_queue),
+   RTE_CACHE_LINE_SIZE, socket_id);
+   if (vq == NULL) {
+   RTE_LOG(ERR, PMD, "Failed to allocate memory for rx queue\n");
+   return -ENOMEM;
+   }
+
+   vq->mb_pool = mb_pool;
+   vq->virtqueue_id = rx_queue_id * VTNET_QNUM + VTNET_TXQ;
+   vq->vpnet = hw->vpnet;
+   dev->data->rx_queues[rx_queue_id] = vq;
+
+   return 0;
+}
+
+static int
+vhostpci_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
+   uint16_t nb_tx_desc __rte_unused,
+   unsigned int socket_id,
+   const struct rte_eth_txconf *tx_conf __rte_unused)
+{
+   struct vhostpci_queue *vq;
+   struct vhostpci_hw *hw = dev->data->dev_private;
+
+   vq = rte_zmalloc_socket(NULL, sizeof(struct vhostpci_queue),
+   RTE_CACHE_LINE_SIZE, socket_id);
+   if (vq == NULL) {
+   RTE_LOG(ERR, PMD, "Failed to allocate memory for tx queue\n");
+   return -ENOMEM;
+   }
+
+   vq->virtqueue_id = tx_queue_id * VTNET_QNUM  + VTNET_RXQ;
+   vq->vpnet = hw->vpnet;
+   dev->data->tx_queues[tx_queue_id] = vq;
+
+   return 0;
+}
+
+static int
 vhostpci_dev_atomic_write_link_status(struct rte_eth_dev *dev,
struct rte_eth_link *link)
 {
-- 
2.13.3



[dpdk-dev] [PATCH 03/11] net/vhostpci: add debugging log macros

2017-11-30 Thread Zhiyong Yang
add a header file with debugging log macros for vhostpci PMD.

Signed-off-by: Zhiyong Yang 
---
 config/common_base   |  4 +++
 drivers/net/vhostpci/vhostpci_logs.h | 69 
 2 files changed, 73 insertions(+)
 create mode 100644 drivers/net/vhostpci/vhostpci_logs.h

diff --git a/config/common_base b/config/common_base
index ea8313591..f382fc6ce 100644
--- a/config/common_base
+++ b/config/common_base
@@ -284,6 +284,10 @@ CONFIG_RTE_LIBRTE_MRVL_PMD=n
 # Compile burst-oriented vhostpci PMD driver
 #
 CONFIG_RTE_LIBRTE_VHOSTPCI_PMD=n
+CONFIG_RTE_LIBRTE_VHOSTPCI_DEBUG_INIT=n
+CONFIG_RTE_LIBRTE_VHOSTPCI_DEBUG_RX=n
+CONFIG_RTE_LIBRTE_VHOSTPCI_DEBUG_TX=n
+CONFIG_RTE_LIBRTE_VHOSTPCI_DEBUG_DRIVER=n
 
 #
 # Compile burst-oriented Broadcom BNXT PMD driver
diff --git a/drivers/net/vhostpci/vhostpci_logs.h 
b/drivers/net/vhostpci/vhostpci_logs.h
new file mode 100644
index 0..16c49d29d
--- /dev/null
+++ b/drivers/net/vhostpci/vhostpci_logs.h
@@ -0,0 +1,69 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   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.
+ */
+
+#ifndef _VHOSTPCI_LOGS_H_
+#define _VHOSTPCI_LOGS_H_
+
+#include 
+
+#ifdef RTE_LIBRTE_VHOSTPCI_DEBUG_INIT
+#define PMD_INIT_LOG(level, fmt, args...) \
+   RTE_LOG(level, PMD, "%s(): " fmt "\n", __func__, ## args)
+#define PMD_INIT_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>")
+#else
+#define PMD_INIT_LOG(level, fmt, args...) do { } while (0)
+#define PMD_INIT_FUNC_TRACE() do { } while (0)
+#endif
+
+#ifdef RTE_LIBRTE_VHOSTPCI_DEBUG_RX
+#define PMD_RX_LOG(level, fmt, args...) \
+   RTE_LOG(level, PMD, "%s() rx: " fmt "\n", __func__, ## args)
+#else
+#define PMD_RX_LOG(level, fmt, args...) do { } while (0)
+#endif
+
+#ifdef RTE_LIBRTE_VHOSTPCI_DEBUG_TX
+#define PMD_TX_LOG(level, fmt, args...) \
+   RTE_LOG(level, PMD, "%s() tx: " fmt "\n", __func__, ## args)
+#else
+#define PMD_TX_LOG(level, fmt, args...) do { } while (0)
+#endif
+
+#ifdef RTE_LIBRTE_VHOSTPCI_DEBUG_DRIVER
+#define PMD_DRV_LOG(level, fmt, args...) \
+   RTE_LOG(level, PMD, "%s(): " fmt "\n", __func__, ## args)
+#else
+#define PMD_DRV_LOG(level, fmt, args...) do { } while (0)
+#endif
+
+#endif /* _VIRTIO_LOGS_H_ */
-- 
2.13.3



[dpdk-dev] [PATCH 01/11] drivers/net: add vhostpci PMD base files

2017-11-30 Thread Zhiyong Yang
Add Makefile and map files for vhostpci PMD.
Update common_base and drivers/net/Makefile files.

Signed-off-by: Zhiyong Yang 
---
 config/common_base|  5 +++
 drivers/net/Makefile  |  1 +
 drivers/net/vhostpci/Makefile | 52 +++
 drivers/net/vhostpci/rte_pmd_vhostpci_version.map |  3 ++
 4 files changed, 61 insertions(+)
 create mode 100644 drivers/net/vhostpci/Makefile
 create mode 100644 drivers/net/vhostpci/rte_pmd_vhostpci_version.map

diff --git a/config/common_base b/config/common_base
index e74febef4..ea8313591 100644
--- a/config/common_base
+++ b/config/common_base
@@ -281,6 +281,11 @@ CONFIG_RTE_LIBRTE_NFP_DEBUG=n
 CONFIG_RTE_LIBRTE_MRVL_PMD=n
 
 #
+# Compile burst-oriented vhostpci PMD driver
+#
+CONFIG_RTE_LIBRTE_VHOSTPCI_PMD=n
+
+#
 # Compile burst-oriented Broadcom BNXT PMD driver
 #
 CONFIG_RTE_LIBRTE_BNXT_PMD=y
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index ef09b4e16..96da4b59f 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -66,6 +66,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_SFC_EFX_PMD) += sfc
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_SZEDATA2) += szedata2
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap
 DIRS-$(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD) += thunderx
+DIRS-$(CONFIG_RTE_LIBRTE_VHOSTPCI_PMD) += vhostpci
 DIRS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio
 DIRS-$(CONFIG_RTE_LIBRTE_VMXNET3_PMD) += vmxnet3
 
diff --git a/drivers/net/vhostpci/Makefile b/drivers/net/vhostpci/Makefile
new file mode 100644
index 0..3467e7cbe
--- /dev/null
+++ b/drivers/net/vhostpci/Makefile
@@ -0,0 +1,52 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2017 Intel Corporation. All rights reserved.
+#   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 $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_vhostpci.a
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_bus_pci
+
+EXPORT_MAP := rte_pmd_vhostpci_version.map
+
+LIBABIVER := 1
+
+#
+# all source are stored in SRCS-y
+#
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/drivers/net/vhostpci/rte_pmd_vhostpci_version.map 
b/drivers/net/vhostpci/rte_pmd_vhostpci_version.map
new file mode 100644
index 0..58b94270d
--- /dev/null
+++ b/drivers/net/vhostpci/rte_pmd_vhostpci_version.map
@@ -0,0 +1,3 @@
+DPDK_18.02 {
+   local: *;
+};
-- 
2.13.3



[dpdk-dev] [PATCH 02/11] net/vhostpci: public header files

2017-11-30 Thread Zhiyong Yang
add public/exported files for vhostpci PMD.  The structures and
constants that define the method of operation of the device can be
visible by both the PMD and the DPDK application.

Signed-off-by: Zhiyong Yang 
---
 drivers/net/vhostpci/vhostpci_ethdev.h | 176 
 drivers/net/vhostpci/vhostpci_net.h|  74 ++
 drivers/net/vhostpci/vhostpci_pci.h| 240 +
 3 files changed, 490 insertions(+)
 create mode 100644 drivers/net/vhostpci/vhostpci_ethdev.h
 create mode 100644 drivers/net/vhostpci/vhostpci_net.h
 create mode 100644 drivers/net/vhostpci/vhostpci_pci.h

diff --git a/drivers/net/vhostpci/vhostpci_ethdev.h 
b/drivers/net/vhostpci/vhostpci_ethdev.h
new file mode 100644
index 0..3ff67dbc6
--- /dev/null
+++ b/drivers/net/vhostpci/vhostpci_ethdev.h
@@ -0,0 +1,176 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   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.
+ */
+
+#ifndef _VHOSTPCI_ETHDEV_H_
+#define _VHOSTPCI_ETHDEV_H_
+
+#include 
+
+#include "vhostpci_pci.h"
+#include "vhostpci_net.h"
+
+#define VHOSTPCI_MAX_RX_QUEUES 128U
+#define VHOSTPCI_MAX_TX_QUEUES 128U
+#define VHOSTPCI_MAX_MAC_ADDRS 1
+#define VHOSTPCI_MIN_RX_BUFSIZE 64
+#define VHOSTPCI_MAX_RX_PKTLEN  9728U
+#define VHOSTPCI_NUM_DESCRIPTORS 256U
+#define VHOSTPCI_MAX_QUEUE_PAIRS 0x1
+
+/* Features supported by vhostpci PMD by default. */
+#define VHOSTPCI_PMD_DEFAULT_GUEST_FEATURES\
+   (1ULL << VIRTIO_NET_F_MRG_RXBUF   | \
+1ULL << VIRTIO_F_VERSION_1)
+
+/**
+ * This is the first element of the scatter-gather list.  If you don't
+ * specify GSO or CSUM features, you can simply ignore the header.
+ */
+struct virtio_net_hdr {
+#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1/**< Use csum_start,csum_offset*/
+#define VIRTIO_NET_HDR_F_DATA_VALID 2/**< Checksum is valid */
+   uint8_t flags;
+#define VIRTIO_NET_HDR_GSO_NONE 0/**< Not a GSO frame */
+#define VIRTIO_NET_HDR_GSO_TCPV41/**< GSO frame, IPv4 TCP (TSO) */
+#define VIRTIO_NET_HDR_GSO_UDP  3/**< GSO frame, IPv4 UDP (UFO) */
+#define VIRTIO_NET_HDR_GSO_TCPV64/**< GSO frame, IPv6 TCP */
+#define VIRTIO_NET_HDR_GSO_ECN  0x80 /**< TCP has ECN set */
+   uint8_t gso_type;
+   uint16_t hdr_len; /**< Ethernet + IP + tcp/udp hdrs */
+   uint16_t gso_size;/**< Bytes to append to hdr_len per frame */
+   uint16_t csum_start;  /**< Position to start checksumming from */
+   uint16_t csum_offset; /**< Offset after that to place checksum */
+};
+
+/**
+ * This is the version of the header to use when the MRG_RXBUF
+ * feature has been negotiated.
+ */
+struct virtio_net_hdr_mrg_rxbuf {
+   struct virtio_net_hdr hdr;
+   uint16_t num_buffers; /**< Number of merged rx buffers */
+};
+
+enum {VTNET_RXQ = 0, VTNET_TXQ, VTNET_QNUM};
+
+struct vhostpci_stats {
+   uint64_t pkts;
+   uint64_t bytes;
+   uint64_t missed_pkts;
+};
+
+struct vhostpci_queue {
+   rte_atomic32_t allow_queuing;
+   rte_atomic32_t while_queuing;
+   struct rte_mempool *mb_pool;
+   uint16_t port_id;
+   uint16_t virtqueue_id;
+   struct vhostpci_stats stats;
+   void *vpnet;
+};
+
+/**
+ * Information relating to memory regions including offsets to
+ * 

[dpdk-dev] [PATCH 00/11] net/vhostpci: A new vhostpci PMD supporting VM2VM scenario

2017-11-30 Thread Zhiyong Yang
Vhostpci PMD is a new type driver working in guest OS which has ability to
drive the vhostpci modern pci device, which is a new virtio device.

The following linking is about vhostpci design:

An initial device design is presented at KVM Forum'16:
http://www.linux-kvm.org/images/5/55/02x07A-Wei_Wang-Design_of-Vhost-pci.pdf
The latest device design and implementation will be posted to the QEMU 
community soon.

Vhostpci PMD works in pair with virtio-net PMD to achieve point-to-point 
communication
between VMs. DPDK already has virtio/vhost user PMD pair to implement RX/TX 
packets
between guest/host scenario. However, for VM2VM use cases, Virtio PMD needs to
transmit pkts from VM1 to host OS firstly by vhost user port, then transmit 
pkts to
the 2nd VM by virtio PMD port again. Virtio/Vhostpci PMD pair can implement 
shared
memory to receive/trasmit packets directly between two VMs. Currently, the 
entire memory
of the virtio-net side VM is shared to the vhost-pci side VM, and mapped via 
device BAR2,
and the first 4KB area of BAR2 is reserved to store the metadata.

The vhostpci/virtio PMD working processing is the following:

1.VM1 startup with vhostpci device, bind the device to DPDK in the guest1,
launch the DPDK testpmd, then waiting for the remote memory info (the VM2
shares memory, memory regions and vring info).

2.VM2 startup with virtio-net device, bind the virito-net to DPDK in the VM2,
run testpmd using virtio PMD.

3.vhostpci device negotiate virtio message with virtio-net device via socket
as vhost user/virtio-net do that.

4.Vhostpci device gets VM2's memory region and vring info and write the metadata
to VM2's shared memory. 

5.When the metadata is ready to be read by the Vhostpci PMD, the PMD 
will receive a config interrupt with LINK_UP set in the status config.

6.Vhostpci PMD and Virtio PMD can transmit/receive the packets.

How to test?

1. launch VM1 with vhostpci device. 
qemu/x86_64-softmmu/qemu-system-x86_64 -cpu host -M pc -enable-kvm \
-smp 16,threads=1,sockets=1 -m 8G -mem-prealloc -realtime mlock=on \
-object memory-backend-file,id=mem,size=8G,mem-path=/dev/hugepages, \
share=on -numa node,memdev=mem -drive 
if=virtio,file=/root/vhost-pci/guest1.img,format=raw \
-kernel /opt/guest_kernel -append 'root=/dev/vda1 ro default_hugepagesz=1G 
hugepagesz=1G \
hugepages=2 console=ttyS0,115200,8n1 3' -netdev 
tap,id=net1,br=br0,script=/etc/qemu-ifup \
-chardev socket,id=slave1,server,wait=off, path=/opt/vhost-pci-slave1 -device 
vhost-pci-net-pci, \
chardev=slave1 \
-nographic

2. bind vhostpci device to dpdk using igb_uio. 
startup dpdk 
./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3 -n 4 -- -i

3. launch VM2 with virtio-net device.

qemu/x86_64-softmmu/qemu-system-x86_64 -cpu host -M pc -enable-kvm \
-smp 4,threads=1,sockets=1 -m 8G -mem-prealloc -realtime mlock=on \
-object memory-backend-file,id=mem,size=8G,mem-path=/dev/hugepages,share=on \
-numa node,memdev=mem -drive 
if=virtio,file=/root/vhost-pci/guest2.img,format=raw \
-net none -no-hpet -kernel /opt/guest_kernel \
-append 'root=/dev/vda1 ro default_hugepagesz=1G hugepagesz=1G hugepages=2 
console=ttyS0,115200,8n1 3' \
-chardev socket,id=sock2,path=/opt/vhost-pci-slave1 \
-netdev type=vhost-user,id=net2,chardev=sock2,vhostforce \
-device virtio-net-pci,mac=52:54:00:00:00:02,netdev=net2 \
-nographic

4.bind virtio-net to dpdk using igb_uio
run dpdk

./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3 -n 4 --socket-mem 512,0 \
-- -i --rxq=1 --txq=1 --nb-cores=1

5. vhostpci PMD run "start"

6. virtio PMD side run "start tx_first"

loopback testing can work.

note: 
1. only support igb_uio for now.
2. vhostpci device is a modern pci device. vhostpci PMD only supports mergable
mode. Virtio device side must be mergable mode.
3. vhostpci PMD supports one queue pair for now.

Zhiyong Yang (11):
  drivers/net: add vhostpci PMD base files
  net/vhostpci: public header files
  net/vhostpci: add debugging log macros
  net/vhostpci: add basic framework
  net/vhostpci: add queue setup
  net/vhostpci: add support for link status change
  net/vhostpci: get remote memory region and vring info
  net/vhostpci: add RX function
  net/vhostpci: add TX function
  net/vhostpci: support RX/TX packets statistics
  net/vhostpci: update release note

 MAINTAINERS   |6 +
 config/common_base|9 +
 config/common_linuxapp|1 +
 doc/guides/rel_notes/release_18_02.rst|6 +
 drivers/net/Makefile  |1 +
 drivers/net/vhostpci/Makefile |   54 +
 drivers/net/vhostpci/rte_pmd_vhostpci_version.map |3 +
 drivers/net/vhostpci/vhostpci_ethdev.c| 1521 +
 drivers/net/vhostpci/vhostpci_ethdev.h|  176 +++
 drivers/net/vhostpci/vhostpci_logs.h  |   69 +
 drivers/net/vhostpci/vhostpci_net.h 

[dpdk-dev] [PATCH v6] net/virtio: fix rxq intr config fails using vfio-pci

2017-11-09 Thread Zhiyong Yang
When running l3fwd-power to test virtio rxq interrupt using vfio
pci noiommu mode, startup fails. In the function virtio_read_caps,
the code if (flags & PCI_MSIX_ENABLE) intends to double check
if vfio msix is enabled or not. However, it is not enable at that
time. So use_msix is assigned to "0", not "1", which causes the
failure of configuring rxq intr in l3fwd-power.
This patch adds the function "vtpci_msix_detect" to detect the status
of msix when interrupt changes happen.
In the meanwhile, virtio_intr_enable/disable are introduced to wrap
rte_intr_enable/disable to enhance the ability to detect msix.
use_msix can indicate three different msix status by:
VIRTIO_MSIX_NONE (0)
VIRTIO_MSIX_DISABLED (1)
VIRTIO_MSIX_ENABLED (2)

CC: sta...@dpdk.org
CC: jianfeng@intel.com
CC: y...@fridaylinux.org
CC: maxime.coque...@redhat.com

Fixes: cb482cb3a305 ("net/virtio: fix MAC address read")
Signed-off-by: Zhiyong Yang 
Acked-by: Jianfeng Tan 
Acked-by: Maxime Coquelin 
---

Changes in v6:
Change enum type name "VIRTIO_MSIX_STATUS" to "virtio_msix_status".

Changes in v5:
1. Introduce new enum data type "VIRTIO_MSIX_STATUS" instead of macros.
2. Remove the unnecessary comments.

Changes in v4:
Enhance the commit log description.

Changes in v3:
Simply the code according to jianfeng's comments.

Changes in v2:
Add the capability to detect msix if virtio intr changes.

 drivers/net/virtio/virtio_ethdev.c | 46 --
 drivers/net/virtio/virtio_pci.c| 43 +--
 drivers/net/virtio/virtio_pci.h|  8 +++
 3 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index d2576d5e0..87ac2bee6 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -97,6 +97,9 @@ static void virtio_mac_addr_remove(struct rte_eth_dev *dev, 
uint32_t index);
 static void virtio_mac_addr_set(struct rte_eth_dev *dev,
struct ether_addr *mac_addr);
 
+static int virtio_intr_enable(struct rte_eth_dev *dev);
+static int virtio_intr_disable(struct rte_eth_dev *dev);
+
 static int virtio_dev_queue_stats_mapping_set(
struct rte_eth_dev *eth_dev,
uint16_t queue_id,
@@ -618,7 +621,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
virtio_queues_unbind_intr(dev);
 
if (intr_conf->lsc || intr_conf->rxq) {
-   rte_intr_disable(dev->intr_handle);
+   virtio_intr_disable(dev);
rte_intr_efd_disable(dev->intr_handle);
rte_free(dev->intr_handle->intr_vec);
dev->intr_handle->intr_vec = NULL;
@@ -1160,6 +1163,34 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t 
vlan_id, int on)
 }
 
 static int
+virtio_intr_enable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+
+   if (rte_intr_enable(dev->intr_handle) < 0)
+   return -1;
+
+   if (!hw->virtio_user_dev)
+   hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+   return 0;
+}
+
+static int
+virtio_intr_disable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+
+   if (rte_intr_disable(dev->intr_handle) < 0)
+   return -1;
+
+   if (!hw->virtio_user_dev)
+   hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+   return 0;
+}
+
+static int
 virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 {
uint64_t host_features;
@@ -1228,7 +1259,7 @@ virtio_interrupt_handler(void *param)
isr = vtpci_isr(hw);
PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
 
-   if (rte_intr_enable(dev->intr_handle) < 0)
+   if (virtio_intr_enable(dev) < 0)
PMD_DRV_LOG(ERR, "interrupt enable failed");
 
if (isr & VIRTIO_PCI_ISR_CONFIG) {
@@ -1348,7 +1379,7 @@ virtio_configure_intr(struct rte_eth_dev *dev)
 * to change the config size from 20 to 24, or VIRTIO_MSI_QUEUE_VECTOR
 * (22) will be ignored.
 */
-   if (rte_intr_enable(dev->intr_handle) < 0) {
+   if (virtio_intr_enable(dev) < 0) {
PMD_DRV_LOG(ERR, "interrupt enable failed");
return -1;
}
@@ -1388,7 +1419,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t 
req_features)
}
 
/* If host does not support both status and MSI-X then disable LSC */
-   if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) && hw->use_msix)
+   if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) &&
+   hw->use_msix != VIRTIO_MSIX_NONE)
eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
   

[dpdk-dev] [PATCH v5] net/virtio: fix rxq intr config fails using vfio-pci

2017-11-09 Thread Zhiyong Yang
When running l3fwd-power to test virtio rxq interrupt using vfio
pci noiommu mode, startup fails. In the function virtio_read_caps,
the code if (flags & PCI_MSIX_ENABLE) intends to double check
if vfio msix is enabled or not. However, it is not enable at that
time. So use_msix is assigned to "0", not "1", which causes the
failure of configuring rxq intr in l3fwd-power.
This patch adds the function "vtpci_msix_detect" to detect the status
of msix when interrupt changes happen.
In the meanwhile, virtio_intr_enable/disable are introduced to wrap
rte_intr_enable/disable to enhance the ability to detect msix.
use_msix can indicate three different msix status by:
VIRTIO_MSIX_NONE (0)
VIRTIO_MSIX_DISABLED (1)
VIRTIO_MSIX_ENABLED (2)

CC: sta...@dpdk.org
CC: jianfeng@intel.com
CC: y...@fridaylinux.org
CC: maxime.coque...@redhat.com

Fixes: cb482cb3a305 ("net/virtio: fix MAC address read")
Signed-off-by: Zhiyong Yang 
Acked-by: Jianfeng Tan 
Acked-by: Maxime Coquelin 
---

Changes in v5:
1. Introduce new enum data type "VIRTIO_MSIX_STATUS" instead of macros.
2. Remove the unnecessary comments.

Changes in v4:
Enhance the commit log description.

Changes in v3:
Simply the code according to jianfeng's comments.

Changes in v2:
Add the capability to detect msix if virtio intr changes.

 drivers/net/virtio/virtio_ethdev.c | 46 --
 drivers/net/virtio/virtio_pci.c| 43 +--
 drivers/net/virtio/virtio_pci.h|  8 +++
 3 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index d2576d5e0..87ac2bee6 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -97,6 +97,9 @@ static void virtio_mac_addr_remove(struct rte_eth_dev *dev, 
uint32_t index);
 static void virtio_mac_addr_set(struct rte_eth_dev *dev,
struct ether_addr *mac_addr);
 
+static int virtio_intr_enable(struct rte_eth_dev *dev);
+static int virtio_intr_disable(struct rte_eth_dev *dev);
+
 static int virtio_dev_queue_stats_mapping_set(
struct rte_eth_dev *eth_dev,
uint16_t queue_id,
@@ -618,7 +621,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
virtio_queues_unbind_intr(dev);
 
if (intr_conf->lsc || intr_conf->rxq) {
-   rte_intr_disable(dev->intr_handle);
+   virtio_intr_disable(dev);
rte_intr_efd_disable(dev->intr_handle);
rte_free(dev->intr_handle->intr_vec);
dev->intr_handle->intr_vec = NULL;
@@ -1160,6 +1163,34 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t 
vlan_id, int on)
 }
 
 static int
+virtio_intr_enable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+
+   if (rte_intr_enable(dev->intr_handle) < 0)
+   return -1;
+
+   if (!hw->virtio_user_dev)
+   hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+   return 0;
+}
+
+static int
+virtio_intr_disable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+
+   if (rte_intr_disable(dev->intr_handle) < 0)
+   return -1;
+
+   if (!hw->virtio_user_dev)
+   hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+   return 0;
+}
+
+static int
 virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 {
uint64_t host_features;
@@ -1228,7 +1259,7 @@ virtio_interrupt_handler(void *param)
isr = vtpci_isr(hw);
PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
 
-   if (rte_intr_enable(dev->intr_handle) < 0)
+   if (virtio_intr_enable(dev) < 0)
PMD_DRV_LOG(ERR, "interrupt enable failed");
 
if (isr & VIRTIO_PCI_ISR_CONFIG) {
@@ -1348,7 +1379,7 @@ virtio_configure_intr(struct rte_eth_dev *dev)
 * to change the config size from 20 to 24, or VIRTIO_MSI_QUEUE_VECTOR
 * (22) will be ignored.
 */
-   if (rte_intr_enable(dev->intr_handle) < 0) {
+   if (virtio_intr_enable(dev) < 0) {
PMD_DRV_LOG(ERR, "interrupt enable failed");
return -1;
}
@@ -1388,7 +1419,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t 
req_features)
}
 
/* If host does not support both status and MSI-X then disable LSC */
-   if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) && hw->use_msix)
+   if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) &&
+   hw->use_msix != VIRTIO_MSIX_NONE)
eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
else
eth_dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
@@ -1801,9 +18

[dpdk-dev] [PATCH v4] net/virtio: fix rxq intr config fails using vfio-pci

2017-11-08 Thread Zhiyong Yang
When running l3fwd-power to test virtio rxq interrupt using vfio
pci noiommu mode, startup fails. In the function virtio_read_caps,
the code if (flags & PCI_MSIX_ENABLE) intends to double check
if vfio msix is enabled or not. However, it is not enable at that
time. So use_msix is assigned to "0", not "1", which causes the
failure of configuring rxq intr in l3fwd-power.
This patch adds the function "vtpci_msix_detect" to detect the status
of msix when interrupt changes happen.
In the meanwhile, virtio_intr_enable/disable are introduced to wrap
rte_intr_enable/disable to enhance the ability to detect msix.
use_msix can indicate three different msix status by:
VIRTIO_MSIX_NONE (0)
VIRTIO_MSIX_DISABLED (1)
VIRTIO_MSIX_ENABLED (2)

CC: sta...@dpdk.org
CC: jianfeng@intel.com
CC: y...@fridaylinux.org
CC: maxime.coque...@redhat.com

Fixes: cb482cb3a305 ("net/virtio: fix MAC address read")
Signed-off-by: Zhiyong Yang 
---

Changes in v4:
Enhance the commit log description.

Changes in v3:
Simply the code according to jianfeng's comments.

Changes in v2:
Add the capability to detect msix if virtio intr changes.

 drivers/net/virtio/virtio_ethdev.c | 46 ++--
 drivers/net/virtio/virtio_pci.c| 48 --
 drivers/net/virtio/virtio_pci.h|  6 +
 3 files changed, 91 insertions(+), 9 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index d2576d5e0..87ac2bee6 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -97,6 +97,9 @@ static void virtio_mac_addr_remove(struct rte_eth_dev *dev, 
uint32_t index);
 static void virtio_mac_addr_set(struct rte_eth_dev *dev,
struct ether_addr *mac_addr);
 
+static int virtio_intr_enable(struct rte_eth_dev *dev);
+static int virtio_intr_disable(struct rte_eth_dev *dev);
+
 static int virtio_dev_queue_stats_mapping_set(
struct rte_eth_dev *eth_dev,
uint16_t queue_id,
@@ -618,7 +621,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
virtio_queues_unbind_intr(dev);
 
if (intr_conf->lsc || intr_conf->rxq) {
-   rte_intr_disable(dev->intr_handle);
+   virtio_intr_disable(dev);
rte_intr_efd_disable(dev->intr_handle);
rte_free(dev->intr_handle->intr_vec);
dev->intr_handle->intr_vec = NULL;
@@ -1160,6 +1163,34 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t 
vlan_id, int on)
 }
 
 static int
+virtio_intr_enable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+
+   if (rte_intr_enable(dev->intr_handle) < 0)
+   return -1;
+
+   if (!hw->virtio_user_dev)
+   hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+   return 0;
+}
+
+static int
+virtio_intr_disable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+
+   if (rte_intr_disable(dev->intr_handle) < 0)
+   return -1;
+
+   if (!hw->virtio_user_dev)
+   hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+   return 0;
+}
+
+static int
 virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 {
uint64_t host_features;
@@ -1228,7 +1259,7 @@ virtio_interrupt_handler(void *param)
isr = vtpci_isr(hw);
PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
 
-   if (rte_intr_enable(dev->intr_handle) < 0)
+   if (virtio_intr_enable(dev) < 0)
PMD_DRV_LOG(ERR, "interrupt enable failed");
 
if (isr & VIRTIO_PCI_ISR_CONFIG) {
@@ -1348,7 +1379,7 @@ virtio_configure_intr(struct rte_eth_dev *dev)
 * to change the config size from 20 to 24, or VIRTIO_MSI_QUEUE_VECTOR
 * (22) will be ignored.
 */
-   if (rte_intr_enable(dev->intr_handle) < 0) {
+   if (virtio_intr_enable(dev) < 0) {
PMD_DRV_LOG(ERR, "interrupt enable failed");
return -1;
}
@@ -1388,7 +1419,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t 
req_features)
}
 
/* If host does not support both status and MSI-X then disable LSC */
-   if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) && hw->use_msix)
+   if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) &&
+   hw->use_msix != VIRTIO_MSIX_NONE)
eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
else
eth_dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
@@ -1801,9 +1833,9 @@ virtio_dev_start(struct rte_eth_dev *dev)
 */
if (dev->data->dev_conf.intr_conf.lsc ||
dev->data->dev_conf.intr_conf.rxq) {
-   rte_intr_disable(dev

[dpdk-dev] [PATCH v3] net/virtio: fix rxq intr config fails using vfio-pci

2017-11-08 Thread Zhiyong Yang
When running l3fwd-power to test virtio rxq interrupt using vfio
pci noiommu mode, startup fails. In the function virtio_read_caps,
the code if (flags & PCI_MSIX_ENABLE) intends to double check
if vfio msix is enabled or not. However, it is not enable at that
time. So use_msix is assigned to "0", not "1", which causes the
failure of configuring rxq intr in l3fwd-power.
This patch adds the function "vtpci_msix_detect" to detect the status
of msix when interrupt changes happen.
In the meanwhile, virtio_intr_enable/disable are introduced to wrap
rte_intr_enable/disable to enhance the ability to detect msix. Only
supporting and enabling msix can assign "VIRTIO_MSIX_ENABLED(2)" to
use_msix.

Fixes: cb482cb3a305 ("net/virtio: fix MAC address read")
Signed-off-by: Zhiyong Yang 
---

Changes in v3:
Simply the code according to jianfeng's comments.

Changes in v2:
Add the capability to detect msix if virtio intr changes.

 drivers/net/virtio/virtio_ethdev.c | 46 ++--
 drivers/net/virtio/virtio_pci.c| 48 --
 drivers/net/virtio/virtio_pci.h|  6 +
 3 files changed, 91 insertions(+), 9 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index d2576d5e0..87ac2bee6 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -97,6 +97,9 @@ static void virtio_mac_addr_remove(struct rte_eth_dev *dev, 
uint32_t index);
 static void virtio_mac_addr_set(struct rte_eth_dev *dev,
struct ether_addr *mac_addr);
 
+static int virtio_intr_enable(struct rte_eth_dev *dev);
+static int virtio_intr_disable(struct rte_eth_dev *dev);
+
 static int virtio_dev_queue_stats_mapping_set(
struct rte_eth_dev *eth_dev,
uint16_t queue_id,
@@ -618,7 +621,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
virtio_queues_unbind_intr(dev);
 
if (intr_conf->lsc || intr_conf->rxq) {
-   rte_intr_disable(dev->intr_handle);
+   virtio_intr_disable(dev);
rte_intr_efd_disable(dev->intr_handle);
rte_free(dev->intr_handle->intr_vec);
dev->intr_handle->intr_vec = NULL;
@@ -1160,6 +1163,34 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t 
vlan_id, int on)
 }
 
 static int
+virtio_intr_enable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+
+   if (rte_intr_enable(dev->intr_handle) < 0)
+   return -1;
+
+   if (!hw->virtio_user_dev)
+   hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+   return 0;
+}
+
+static int
+virtio_intr_disable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+
+   if (rte_intr_disable(dev->intr_handle) < 0)
+   return -1;
+
+   if (!hw->virtio_user_dev)
+   hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+   return 0;
+}
+
+static int
 virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 {
uint64_t host_features;
@@ -1228,7 +1259,7 @@ virtio_interrupt_handler(void *param)
isr = vtpci_isr(hw);
PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
 
-   if (rte_intr_enable(dev->intr_handle) < 0)
+   if (virtio_intr_enable(dev) < 0)
PMD_DRV_LOG(ERR, "interrupt enable failed");
 
if (isr & VIRTIO_PCI_ISR_CONFIG) {
@@ -1348,7 +1379,7 @@ virtio_configure_intr(struct rte_eth_dev *dev)
 * to change the config size from 20 to 24, or VIRTIO_MSI_QUEUE_VECTOR
 * (22) will be ignored.
 */
-   if (rte_intr_enable(dev->intr_handle) < 0) {
+   if (virtio_intr_enable(dev) < 0) {
PMD_DRV_LOG(ERR, "interrupt enable failed");
return -1;
}
@@ -1388,7 +1419,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t 
req_features)
}
 
/* If host does not support both status and MSI-X then disable LSC */
-   if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) && hw->use_msix)
+   if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) &&
+   hw->use_msix != VIRTIO_MSIX_NONE)
eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
else
eth_dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
@@ -1801,9 +1833,9 @@ virtio_dev_start(struct rte_eth_dev *dev)
 */
if (dev->data->dev_conf.intr_conf.lsc ||
dev->data->dev_conf.intr_conf.rxq) {
-   rte_intr_disable(dev->intr_handle);
+   virtio_intr_disable(dev);
 
-   if (rte_intr_enable(dev->intr_handle) < 0) {
+   if (virtio_intr_enable(dev) < 0) {
   

[dpdk-dev] [PATCH v2] net/virtio: fix rxq intr config fails using vfio-pci

2017-11-08 Thread Zhiyong Yang
When running l3fwd-power to test virtio rxq interrupt using vfio
pci noiommu mode, startup fails. In the function virtio_read_caps,
the code if (flags & PCI_MSIX_ENABLE) intends to double check
if vfio msix is enabled or not. However, it is not enable at that
stage. So use_msix is assigned to "0", not "1", which causes the
failure of configuring rxq intr in l3fwd-power.
This patch adds the function vtpci_msix_detect to detect the status
of msix when interrupt changes happen.
In the meanwhile, virtio_intr_enable/disable are introduced to wrap
rte_intr_enable/disable to enhance the ability to detect msix. Only
support and enable msix can assign "1" to use_msix.

Fixes: cb482cb3a305 ("net/virtio: fix MAC address read")
Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_ethdev.c | 64 +-
 drivers/net/virtio/virtio_pci.c| 42 +
 drivers/net/virtio/virtio_pci.h|  5 +++
 3 files changed, 104 insertions(+), 7 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index d2576d5e0..525cfa06c 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -97,6 +97,9 @@ static void virtio_mac_addr_remove(struct rte_eth_dev *dev, 
uint32_t index);
 static void virtio_mac_addr_set(struct rte_eth_dev *dev,
struct ether_addr *mac_addr);
 
+static int virtio_intr_enable(struct rte_eth_dev *dev);
+static int virtio_intr_disable(struct rte_eth_dev *dev);
+
 static int virtio_dev_queue_stats_mapping_set(
struct rte_eth_dev *eth_dev,
uint16_t queue_id,
@@ -618,7 +621,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
virtio_queues_unbind_intr(dev);
 
if (intr_conf->lsc || intr_conf->rxq) {
-   rte_intr_disable(dev->intr_handle);
+   virtio_intr_disable(dev);
rte_intr_efd_disable(dev->intr_handle);
rte_free(dev->intr_handle->intr_vec);
dev->intr_handle->intr_vec = NULL;
@@ -1160,6 +1163,44 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t 
vlan_id, int on)
 }
 
 static int
+virtio_intr_enable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+   int msix_detect;
+
+   if (rte_intr_enable(dev->intr_handle) < 0)
+   return -1;
+
+   msix_detect = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+   if (msix_detect < 0)
+   return -1;
+   else if (msix_detect == SUPPORT_MSIX_STATUS_ENABLED)
+   hw->use_msix = 1;
+   else
+   hw->use_msix = 0;
+   return 0;
+}
+
+static int
+virtio_intr_disable(struct rte_eth_dev *dev)
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+   int msix_detect;
+
+   if (rte_intr_disable(dev->intr_handle) < 0)
+   return -1;
+
+   msix_detect = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+   if (msix_detect < 0)
+   return -1;
+   else if (msix_detect == SUPPORT_MSIX_STATUS_ENABLED)
+   hw->use_msix = 1;
+   else
+   hw->use_msix = 0;
+   return 0;
+}
+
+static int
 virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 {
uint64_t host_features;
@@ -1228,7 +1269,7 @@ virtio_interrupt_handler(void *param)
isr = vtpci_isr(hw);
PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
 
-   if (rte_intr_enable(dev->intr_handle) < 0)
+   if (virtio_intr_enable(dev) < 0)
PMD_DRV_LOG(ERR, "interrupt enable failed");
 
if (isr & VIRTIO_PCI_ISR_CONFIG) {
@@ -1348,7 +1389,7 @@ virtio_configure_intr(struct rte_eth_dev *dev)
 * to change the config size from 20 to 24, or VIRTIO_MSI_QUEUE_VECTOR
 * (22) will be ignored.
 */
-   if (rte_intr_enable(dev->intr_handle) < 0) {
+   if (virtio_intr_enable(dev) < 0) {
PMD_DRV_LOG(ERR, "interrupt enable failed");
return -1;
}
@@ -1370,7 +1411,15 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t 
req_features)
struct virtio_net_config local_config;
struct rte_pci_device *pci_dev = NULL;
int ret;
+   int msix_detect;
 
+   msix_detect = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(eth_dev));
+   if (msix_detect < 0)
+   return -1;
+   else if (msix_detect == SUPPORT_MSIX_STATUS_ENABLED)
+   hw->use_msix = 1;
+   else
+   hw->use_msix = 0;
/* Reset the device although not necessary at startup */
vtpci_reset(hw);
 
@@ -1388,7 +1437,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t 
req_features)
}
 
/* If host does not support both status and MSI-X then 

[dpdk-dev] [PATCH] net/virtio: fix use_msix get the wrong value

2017-10-31 Thread Zhiyong Yang
When running l3fwd-power to test virtio rxq interrupt using vfio
pci noiommu mode, startup fails. In the function virtio_read_caps,
the code if (flags & PCI_MSIX_ENABLE) intends to double check
if vfio msix is enabled or not. However, it is indeed not valid.
Come back to l3fwd-power, use_msix is not assigned to the right
value "1". The patch fixes the issue.

Fixes: cb482cb3a305 ("net/virtio: fix MAC address read")
Signed-off-by: Zhiyong Yang 
---
 drivers/net/virtio/virtio_pci.c | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index 55b717c03..be5b07a58 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -580,8 +580,6 @@ get_cfg_addr(struct rte_pci_device *dev, struct 
virtio_pci_cap *cap)
return base + offset;
 }
 
-#define PCI_MSIX_ENABLE 0x8000
-
 static int
 virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
 {
@@ -609,14 +607,7 @@ virtio_read_caps(struct rte_pci_device *dev, struct 
virtio_hw *hw)
}
 
if (cap.cap_vndr == PCI_CAP_ID_MSIX) {
-   /* Transitional devices would also have this capability,
-* that's why we also check if msix is enabled.
-* 1st byte is cap ID; 2nd byte is the position of next
-* cap; next two bytes are the flags.
-*/
-   uint16_t flags = ((uint16_t *)&cap)[1];
-
-   if (flags & PCI_MSIX_ENABLE)
+   if (dev->intr_handle.type == RTE_INTR_HANDLE_VFIO_MSIX)
hw->use_msix = 1;
}
 
-- 
2.13.3



[dpdk-dev] [PATCH v3] net/virtio: fix wrong TX pkt length stats

2017-10-23 Thread Zhiyong Yang
In the function virtqueue_enqueue_xmit(), when can_push is true,
vtnet_hdr_size is added to pkt_len by calling rte_pktmbuf_prepend.
which is wrong for pkt stats, virtio header length should be subtracted
before calling stats function.

Fixes: 58169a9c8153 ("net/virtio: support Tx checksum offload")

Cc: sta...@dpdk.org
Cc: y...@fridaylinux.org
Cc: maxime.coque...@redhat.com
Signed-off-by: Zhiyong Yang 
Reviewed-by: Maxime Coquelin 
---

Changes in V3:
Move code inside "if (can_push)" clause and simplify comments.

Changes in V2:
Put code in the function virtqueue_enqueue_xmit() according to
yuanhan's comments.

 drivers/net/virtio/virtio_rxtx.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index 2cf82fef4..ac4055d45 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -299,6 +299,10 @@ virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct 
rte_mbuf *cookie,
/* prepend cannot fail, checked by caller */
hdr = (struct virtio_net_hdr *)
rte_pktmbuf_prepend(cookie, head_size);
+   /* rte_pktmbuf_prepend() counts the hdr size to the pkt length,
+* which is wrong. Below subtract restores correct pkt size.
+*/
+   cookie->pkt_len -= head_size;
/* if offload disabled, it is not zeroed below, do it now */
if (offload == 0) {
ASSIGN_UNLESS_EQUAL(hdr->csum_start, 0);
-- 
2.13.3



[dpdk-dev] [PATCH v2] net/virtio: fix wrong TX pkt length stats

2017-10-22 Thread Zhiyong Yang
In the function virtqueue_enqueue_xmit(), when can_push is true,
vtnet_hdr_size is added to pkt_len by calling rte_pktmbuf_prepend.
So, virtio header length should be subtracted before calling stats
function.

Fixes: 58169a9c8153 ("net/virtio: support Tx checksum offload")

Cc: sta...@dpdk.org
Cc: y...@fridaylinux.org
Cc: maxime.coque...@redhat.com
Signed-off-by: Zhiyong Yang 
Reviewed-by: Maxime Coquelin 
---

Changes in V2:
Put code in the function virtqueue_enqueue_xmit() according to
yuanhan's comments.

 drivers/net/virtio/virtio_rxtx.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index 2cf82fef4..f28751e07 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -396,6 +396,13 @@ virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct 
rte_mbuf *cookie,
vq->vq_desc_tail_idx = idx;
vq->vq_free_cnt = (uint16_t)(vq->vq_free_cnt - needed);
vq_update_avail_ring(vq, head_idx);
+
+   /* when can_push is true, vtnet_hdr_size is added to pkt_len
+* of mbuf. It should be subtracted in order to make stats function
+* work in the right way.
+*/
+   if (can_push)
+   cookie->pkt_len -= head_size;
 }
 
 void
-- 
2.13.3



[dpdk-dev] [PATCH v2] examples/l2fwd-crypto: fix port id type

2017-10-18 Thread Zhiyong Yang
Fix port id issues and keep variables related to port ids in
consistent data type definition "uint16_t".

Remove unnecessary cast in the meanwhile.

Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
Acked-by: Pablo de Lara 
---
 examples/l2fwd-crypto/main.c | 42 ++
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index 7dfcba421..fa995e7dd 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -114,7 +114,7 @@ static uint64_t l2fwd_enabled_port_mask;
 static uint64_t l2fwd_enabled_crypto_mask;
 
 /* list of enabled ports */
-static uint32_t l2fwd_dst_ports[RTE_MAX_ETHPORTS];
+static uint16_t l2fwd_dst_ports[RTE_MAX_ETHPORTS];
 
 
 struct pkt_buffer {
@@ -226,7 +226,7 @@ struct l2fwd_crypto_params {
 /** lcore configuration */
 struct lcore_queue_conf {
unsigned nb_rx_ports;
-   unsigned rx_port_list[MAX_RX_QUEUE_PER_LCORE];
+   uint16_t rx_port_list[MAX_RX_QUEUE_PER_LCORE];
 
unsigned nb_crypto_devs;
unsigned cryptodev_list[MAX_RX_QUEUE_PER_LCORE];
@@ -292,7 +292,7 @@ print_stats(void)
uint64_t total_packets_dropped, total_packets_tx, total_packets_rx;
uint64_t total_packets_enqueued, total_packets_dequeued,
total_packets_errors;
-   unsigned portid;
+   uint16_t portid;
uint64_t cdevid;
 
total_packets_dropped = 0;
@@ -621,7 +621,7 @@ l2fwd_send_packet(struct rte_mbuf *m, uint16_t port)
 }
 
 static void
-l2fwd_mac_updating(struct rte_mbuf *m, unsigned int dest_portid)
+l2fwd_mac_updating(struct rte_mbuf *m, uint16_t dest_portid)
 {
struct ether_hdr *eth;
void *tmp;
@@ -637,17 +637,17 @@ l2fwd_mac_updating(struct rte_mbuf *m, unsigned int 
dest_portid)
 }
 
 static void
-l2fwd_simple_forward(struct rte_mbuf *m, unsigned int portid,
+l2fwd_simple_forward(struct rte_mbuf *m, uint16_t portid,
struct l2fwd_crypto_options *options)
 {
-   unsigned int dst_port;
+   uint16_t dst_port;
 
dst_port = l2fwd_dst_ports[portid];
 
if (options->mac_updating)
l2fwd_mac_updating(m, dst_port);
 
-   l2fwd_send_packet(m, (uint8_t) dst_port);
+   l2fwd_send_packet(m, dst_port);
 }
 
 /** Generate random key */
@@ -719,7 +719,8 @@ 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, len;
+   unsigned int i, j, nb_rx, len;
+   uint16_t portid;
struct lcore_queue_conf *qconf = &lcore_queue_conf[lcore_id];
const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
US_PER_S * BURST_TX_DRAIN_US;
@@ -884,7 +885,7 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)
continue;
l2fwd_send_burst(&lcore_queue_conf[lcore_id],
 qconf->pkt_buf[portid].len,
-(uint8_t) portid);
+portid);
qconf->pkt_buf[portid].len = 0;
}
 
@@ -918,7 +919,7 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)
 
cparams = &port_cparams[i];
 
-   nb_rx = rte_eth_rx_burst((uint8_t) portid, 0,
+   nb_rx = rte_eth_rx_burst(portid, 0,
 pkts_burst, MAX_PKT_BURST);
 
port_statistics[portid].rx += nb_rx;
@@ -2342,7 +2343,7 @@ initialize_cryptodevs(struct l2fwd_crypto_options 
*options, unsigned nb_ports,
 static int
 initialize_ports(struct l2fwd_crypto_options *options)
 {
-   uint8_t last_portid, portid;
+   uint16_t last_portid, portid;
unsigned enabled_portcount = 0;
unsigned nb_ports = rte_eth_dev_count();
 
@@ -2363,12 +2364,12 @@ initialize_ports(struct l2fwd_crypto_options *options)
continue;
 
/* init port */
-   printf("Initializing port %u... ", (unsigned) portid);
+   printf("Initializing port %u... ", portid);
fflush(stdout);
retval = rte_eth_dev_configure(portid, 1, 1, &port_conf);
if (retval < 0) {
printf("Cannot configure device: err=%d, port=%u\n",
- retval, (unsigned) portid);
+ retval, portid);
return -1;
}
 
@@ -2376,7 +2377,7 @@ initialize_ports(struct l2fwd_crypto_options *options)
  &nb_txd);
   

[dpdk-dev] [PATCH] examples/l2fwd-crypto: fix port id type

2017-10-18 Thread Zhiyong Yang
Fix port id issue and remove unnecessary cast.

Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 examples/l2fwd-crypto/main.c | 30 --
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index 7dfcba421..3408938aa 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -647,7 +647,7 @@ l2fwd_simple_forward(struct rte_mbuf *m, unsigned int 
portid,
if (options->mac_updating)
l2fwd_mac_updating(m, dst_port);
 
-   l2fwd_send_packet(m, (uint8_t) dst_port);
+   l2fwd_send_packet(m, dst_port);
 }
 
 /** Generate random key */
@@ -719,7 +719,8 @@ 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, len;
+   unsigned int i, j, nb_rx, len;
+   uint16_t portid;
struct lcore_queue_conf *qconf = &lcore_queue_conf[lcore_id];
const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
US_PER_S * BURST_TX_DRAIN_US;
@@ -884,7 +885,7 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)
continue;
l2fwd_send_burst(&lcore_queue_conf[lcore_id],
 qconf->pkt_buf[portid].len,
-(uint8_t) portid);
+portid);
qconf->pkt_buf[portid].len = 0;
}
 
@@ -918,7 +919,7 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)
 
cparams = &port_cparams[i];
 
-   nb_rx = rte_eth_rx_burst((uint8_t) portid, 0,
+   nb_rx = rte_eth_rx_burst(portid, 0,
 pkts_burst, MAX_PKT_BURST);
 
port_statistics[portid].rx += nb_rx;
@@ -2342,7 +2343,7 @@ initialize_cryptodevs(struct l2fwd_crypto_options 
*options, unsigned nb_ports,
 static int
 initialize_ports(struct l2fwd_crypto_options *options)
 {
-   uint8_t last_portid, portid;
+   uint16_t last_portid, portid;
unsigned enabled_portcount = 0;
unsigned nb_ports = rte_eth_dev_count();
 
@@ -2363,12 +2364,12 @@ initialize_ports(struct l2fwd_crypto_options *options)
continue;
 
/* init port */
-   printf("Initializing port %u... ", (unsigned) portid);
+   printf("Initializing port %u... ", portid);
fflush(stdout);
retval = rte_eth_dev_configure(portid, 1, 1, &port_conf);
if (retval < 0) {
printf("Cannot configure device: err=%d, port=%u\n",
- retval, (unsigned) portid);
+ retval, portid);
return -1;
}
 
@@ -2376,7 +2377,7 @@ initialize_ports(struct l2fwd_crypto_options *options)
  &nb_txd);
if (retval < 0) {
printf("Cannot adjust number of descriptors: err=%d, 
port=%u\n",
-   retval, (unsigned) portid);
+   retval, portid);
return -1;
}
 
@@ -2387,7 +2388,7 @@ initialize_ports(struct l2fwd_crypto_options *options)
 NULL, l2fwd_pktmbuf_pool);
if (retval < 0) {
printf("rte_eth_rx_queue_setup:err=%d, port=%u\n",
-   retval, (unsigned) portid);
+   retval, portid);
return -1;
}
 
@@ -2398,7 +2399,7 @@ initialize_ports(struct l2fwd_crypto_options *options)
NULL);
if (retval < 0) {
printf("rte_eth_tx_queue_setup:err=%d, port=%u\n",
-   retval, (unsigned) portid);
+   retval, portid);
 
return -1;
}
@@ -2407,7 +2408,7 @@ initialize_ports(struct l2fwd_crypto_options *options)
retval = rte_eth_dev_start(portid);
if (retval < 0) {
printf("rte_eth_dev_start:err=%d, port=%u\n",
-   retval, (unsigned) portid);
+   retval, portid);
return -1;
}
 
@@ -2416,7 +2417,7 @@ initialize_ports(struct l2fwd_crypto_options *options)
   

[dpdk-dev] [PATCH v3] doc: add virtio lsc note

2017-10-15 Thread Zhiyong Yang
Virtio PMD already has supported link status change(lsc), but VM which
must be created by qemu 2.7.0 and above can support it when vhost
user disconnects, since the capability to detect vhost user disconnection
is introduced in qemu 2.7.0. The patch updates doc to let user know that.

Signed-off-by: Zhiyong Yang 
Reviewed-by: John McNamara 
---
 doc/guides/nics/virtio.rst | 7 +++
 1 file changed, 7 insertions(+)

Changes in v3:
Add a blank line and indent, and text is minor changed according to John's
comments.

Changes in v2:
reword the doc and commit log.

diff --git a/doc/guides/nics/virtio.rst b/doc/guides/nics/virtio.rst
index 4d6a83768..af82f86e4 100644
--- a/doc/guides/nics/virtio.rst
+++ b/doc/guides/nics/virtio.rst
@@ -291,6 +291,13 @@ interrupt, Rx interrupts, and Tx interrupts. Config 
interrupt is used for
 notification of device configuration changes, especially link status (lsc).
 Interrupt mode is translated into Rx interrupts in the context of DPDK.
 
+.. Note::
+
+   Virtio PMD already has support for receiving lsc from qemu when the link
+   status changes, especially when vhost user disconnects. However, it fails
+   to do that if the VM is created by qemu 2.6.2 or below, since the
+   capability to detect vhost user disconnection is introduced in qemu 2.7.0.
+
 Prerequisites for Rx interrupts
 ~~~
 
-- 
2.13.3



[dpdk-dev] [PATCH] app/testpmd: remove useless funciton declarations

2017-10-15 Thread Zhiyong Yang
The four function declarations have no funciton implementation,
remove them.

Signed-off-by: Zhiyong Yang 
---
 app/test-pmd/testpmd.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 265b75f9f..15ebf8c92 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -698,10 +698,6 @@ void port_rss_hash_conf_show(portid_t port_id, char 
rss_info[],
 int show_rss_key);
 void port_rss_hash_key_update(portid_t port_id, char rss_type[],
  uint8_t *hash_key, uint hash_key_len);
-void get_syn_filter(portid_t port_id);
-void get_ethertype_filter(portid_t port_id, uint16_t index);
-void get_2tuple_filter(portid_t port_id, uint16_t index);
-void get_5tuple_filter(portid_t port_id, uint16_t index);
 int rx_queue_id_is_invalid(queueid_t rxq_id);
 int tx_queue_id_is_invalid(queueid_t txq_id);
 void setup_gro(const char *onoff, portid_t port_id);
-- 
2.13.3



[dpdk-dev] [PATCH 7/8] examples: fix port id type

2017-10-13 Thread Zhiyong Yang
Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 examples/distributor/main.c|  2 +-
 examples/ethtool/lib/rte_ethtool.c | 42 +--
 examples/ethtool/lib/rte_ethtool.h | 42 +--
 examples/exception_path/main.c |  2 +-
 examples/ipsec-secgw/ipsec-secgw.c | 47 --
 examples/kni/main.c| 16 
 examples/l2fwd-crypto/main.c   | 18 -
 examples/l2fwd-jobstats/main.c | 26 ++--
 examples/l3fwd-acl/main.c  | 23 ++-
 examples/l3fwd-power/main.c| 12 +++---
 examples/l3fwd/l3fwd_em.c  | 17 
 examples/l3fwd/l3fwd_em_sequential.h   |  4 +-
 examples/link_status_interrupt/main.c  | 15 ---
 .../client_server_mp/mp_client/client.c|  6 +--
 examples/multi_process/symmetric_mp/main.c | 21 +-
 examples/performance-thread/l3fwd-thread/main.c|  6 +--
 examples/ptpclient/ptpclient.c |  8 ++--
 examples/qos_meter/main.c  |  4 +-
 examples/qos_sched/cmdline.c   | 30 +++---
 examples/quota_watermark/qw/init.c |  4 +-
 examples/quota_watermark/qw/init.h |  4 +-
 examples/quota_watermark/qw/main.c |  4 +-
 examples/quota_watermark/qw/main.h |  2 +-
 examples/rxtx_callbacks/main.c |  2 +-
 examples/server_node_efd/node/node.c   | 21 +-
 examples/server_node_efd/server/init.c | 18 +
 examples/tep_termination/main.c|  6 +--
 examples/tep_termination/vxlan_setup.c |  6 +--
 examples/tep_termination/vxlan_setup.h | 10 ++---
 examples/vmdq/main.c   |  6 +--
 examples/vmdq_dcb/main.c   |  6 +--
 31 files changed, 219 insertions(+), 211 deletions(-)

diff --git a/examples/distributor/main.c b/examples/distributor/main.c
index 108efc8a6..61e6e6b9e 100644
--- a/examples/distributor/main.c
+++ b/examples/distributor/main.c
@@ -212,7 +212,7 @@ lcore_rx(struct lcore_params *p)
 {
const uint16_t nb_ports = rte_eth_dev_count();
const int socket_id = rte_socket_id();
-   uint8_t port;
+   uint16_t port;
struct rte_mbuf *bufs[BURST_SIZE*2];
 
for (port = 0; port < nb_ports; port++) {
diff --git a/examples/ethtool/lib/rte_ethtool.c 
b/examples/ethtool/lib/rte_ethtool.c
index 252382cb5..6e30ed8db 100644
--- a/examples/ethtool/lib/rte_ethtool.c
+++ b/examples/ethtool/lib/rte_ethtool.c
@@ -47,7 +47,7 @@
 
 
 int
-rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo)
+rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo)
 {
struct rte_eth_dev_info dev_info;
struct rte_dev_reg_info reg_info;
@@ -106,7 +106,7 @@ rte_ethtool_get_drvinfo(uint8_t port_id, struct 
ethtool_drvinfo *drvinfo)
 }
 
 int
-rte_ethtool_get_regs_len(uint8_t port_id)
+rte_ethtool_get_regs_len(uint16_t port_id)
 {
struct rte_dev_reg_info reg_info;
int ret;
@@ -121,7 +121,7 @@ rte_ethtool_get_regs_len(uint8_t port_id)
 }
 
 int
-rte_ethtool_get_regs(uint8_t port_id, struct ethtool_regs *regs, void *data)
+rte_ethtool_get_regs(uint16_t port_id, struct ethtool_regs *regs, void *data)
 {
struct rte_dev_reg_info reg_info;
int status;
@@ -141,7 +141,7 @@ rte_ethtool_get_regs(uint8_t port_id, struct ethtool_regs 
*regs, void *data)
 }
 
 int
-rte_ethtool_get_link(uint8_t port_id)
+rte_ethtool_get_link(uint16_t port_id)
 {
struct rte_eth_link link;
 
@@ -151,13 +151,13 @@ rte_ethtool_get_link(uint8_t port_id)
 }
 
 int
-rte_ethtool_get_eeprom_len(uint8_t port_id)
+rte_ethtool_get_eeprom_len(uint16_t port_id)
 {
return rte_eth_dev_get_eeprom_length(port_id);
 }
 
 int
-rte_ethtool_get_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom,
+rte_ethtool_get_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
void *words)
 {
struct rte_dev_eeprom_info eeprom_info;
@@ -180,7 +180,7 @@ rte_ethtool_get_eeprom(uint8_t port_id, struct 
ethtool_eeprom *eeprom,
 }
 
 int
-rte_ethtool_set_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom,
+rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
void *words)
 {
struct rte_dev_eeprom_info eeprom_info;
@@ -203,7 +203,7 @@ rte_ethtool_set_eeprom(uint8_t port_id, struct 
ethtool_eeprom *eeprom,
 }
 
 int
-rte_ethtool_get_pauseparam(uint8_t port_id,
+rte_ethtool_get_pauseparam(uint16_t port_id,
struct ethtool_pauseparam *pause_param)
 {
struct rte_eth_fc_conf fc_conf;
@@ -238,7 +238,7 @@ rte_ethtool_get_pauseparam(uint8_t port_

[dpdk-dev] [PATCH 8/8] doc: update port id type

2017-10-13 Thread Zhiyong Yang
Since port id has changed from uint8_t to uint16_t in dpdk code,
So update the change in related doc.

Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 doc/guides/prog_guide/poll_mode_drv.rst  |  2 +-
 doc/guides/prog_guide/rte_flow.rst   | 12 ++--
 doc/guides/sample_app_ug/ipv4_multicast.rst  |  2 +-
 doc/guides/sample_app_ug/kernel_nic_interface.rst|  8 
 doc/guides/sample_app_ug/l2_forward_job_stats.rst|  4 ++--
 doc/guides/sample_app_ug/l2_forward_real_virtual.rst |  2 +-
 doc/guides/sample_app_ug/l3_forward.rst  | 10 +-
 doc/guides/sample_app_ug/l3_forward_power_man.rst|  4 ++--
 doc/guides/sample_app_ug/link_status_intr.rst|  4 ++--
 doc/guides/sample_app_ug/ptpclient.rst   |  2 +-
 doc/guides/sample_app_ug/rxtx_callbacks.rst  |  6 +++---
 doc/guides/sample_app_ug/skeleton.rst|  6 +++---
 12 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/doc/guides/prog_guide/poll_mode_drv.rst 
b/doc/guides/prog_guide/poll_mode_drv.rst
index 423170997..6a0c9f992 100644
--- a/doc/guides/prog_guide/poll_mode_drv.rst
+++ b/doc/guides/prog_guide/poll_mode_drv.rst
@@ -562,7 +562,7 @@ NIC Reset API
 
 .. code-block:: c
 
-int rte_eth_dev_reset(uint8_t port_id);
+int rte_eth_dev_reset(uint16_t port_id);
 
 Sometimes a port has to be reset passively. For example when a PF is
 reset, all its VFs should also be reset by the application to make them
diff --git a/doc/guides/prog_guide/rte_flow.rst 
b/doc/guides/prog_guide/rte_flow.rst
index 31138819b..13e3dbe0d 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -1418,7 +1418,7 @@ supported and can be created.
 .. code-block:: c
 
int
-   rte_flow_validate(uint8_t port_id,
+   rte_flow_validate(uint16_t port_id,
  const struct rte_flow_attr *attr,
  const struct rte_flow_item pattern[],
  const struct rte_flow_action actions[],
@@ -1473,7 +1473,7 @@ actually created and a handle returned.
 .. code-block:: c
 
struct rte_flow *
-   rte_flow_create(uint8_t port_id,
+   rte_flow_create(uint16_t port_id,
const struct rte_flow_attr *attr,
const struct rte_flow_item pattern[],
const struct rte_flow_action *actions[],
@@ -1505,7 +1505,7 @@ performing this step before releasing resources.
 .. code-block:: c
 
int
-   rte_flow_destroy(uint8_t port_id,
+   rte_flow_destroy(uint16_t port_id,
 struct rte_flow *flow,
 struct rte_flow_error *error);
 
@@ -1536,7 +1536,7 @@ port. They are released as with successive calls to 
``rte_flow_destroy()``.
 .. code-block:: c
 
int
-   rte_flow_flush(uint8_t port_id,
+   rte_flow_flush(uint16_t port_id,
   struct rte_flow_error *error);
 
 In the unlikely event of failure, handles are still considered destroyed and
@@ -1564,7 +1564,7 @@ definition.
 .. code-block:: c
 
int
-   rte_flow_query(uint8_t port_id,
+   rte_flow_query(uint16_t port_id,
   struct rte_flow *flow,
   enum rte_flow_action_type action,
   void *data,
@@ -1637,7 +1637,7 @@ port and may return errors such as ``ENOTSUP`` ("not 
supported"):
 .. code-block:: c
 
int
-   rte_flow_isolate(uint8_t port_id, int set, struct rte_flow_error *error);
+   rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
 
 Arguments:
 
diff --git a/doc/guides/sample_app_ug/ipv4_multicast.rst 
b/doc/guides/sample_app_ug/ipv4_multicast.rst
index 49712a0fe..60bca859e 100644
--- a/doc/guides/sample_app_ug/ipv4_multicast.rst
+++ b/doc/guides/sample_app_ug/ipv4_multicast.rst
@@ -268,7 +268,7 @@ The actual packet transmission is done in the 
mcast_send_pkt() function:
 
 .. code-block:: c
 
-static inline void mcast_send_pkt(struct rte_mbuf *pkt, struct ether_addr 
*dest_addr, struct lcore_queue_conf *qconf, uint8_t port)
+static inline void mcast_send_pkt(struct rte_mbuf *pkt, struct ether_addr 
*dest_addr, struct lcore_queue_conf *qconf, uint16_t port)
 {
 struct ether_hdr *ethdr;
 uint16_t len;
diff --git a/doc/guides/sample_app_ug/kernel_nic_interface.rst 
b/doc/guides/sample_app_ug/kernel_nic_interface.rst
index 619a7b527..e050e8bf7 100644
--- a/doc/guides/sample_app_ug/kernel_nic_interface.rst
+++ b/doc/guides/sample_app_ug/kernel_nic_interface.rst
@@ -246,7 +246,7 @@ The code for allocating the kernel NIC interfaces for a 
specific port is as foll
 .. code-block:: c
 
 static int
-kni_alloc(uint8_t port_id)
+kni_alloc(uint16_t port_id)
 {
 uint8_t i;
 struct rte_kni *kni;
@@ -335,7 +335,7 @@ The code is as follows:
 int i, j, nb_token;
 char *str_fld[_NUM_FLD];
 unsigned long int_fld[_NUM_FLD];
-   

[dpdk-dev] [PATCH 6/8] test: fix port id type

2017-10-13 Thread Zhiyong Yang
Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 test/test-pipeline/init.c | 8 
 test/test/test_link_bonding.c | 2 +-
 test/test/test_link_bonding_mode4.c   | 4 ++--
 test/test/test_link_bonding_rssconf.c | 7 ---
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/test/test-pipeline/init.c b/test/test-pipeline/init.c
index 1457c7890..b1f8e93ea 100644
--- a/test/test-pipeline/init.c
+++ b/test/test-pipeline/init.c
@@ -194,9 +194,9 @@ app_ports_check_link(void)
 
for (i = 0; i < app.n_ports; i++) {
struct rte_eth_link link;
-   uint8_t port;
+   uint16_t port;
 
-   port = (uint8_t) app.ports[i];
+   port = app.ports[i];
memset(&link, 0, sizeof(link));
rte_eth_link_get_nowait(port, &link);
RTE_LOG(INFO, USER1, "Port %u (%u Gbps) %s\n",
@@ -219,10 +219,10 @@ app_init_ports(void)
 
/* Init NIC ports, then start the ports */
for (i = 0; i < app.n_ports; i++) {
-   uint8_t port;
+   uint16_t port;
int ret;
 
-   port = (uint8_t) app.ports[i];
+   port = app.ports[i];
RTE_LOG(INFO, USER1, "Initializing NIC port %u ...\n", port);
 
/* Init port */
diff --git a/test/test/test_link_bonding.c b/test/test/test_link_bonding.c
index e41ab60d2..c6e3a725b 100644
--- a/test/test/test_link_bonding.c
+++ b/test/test/test_link_bonding.c
@@ -226,7 +226,7 @@ static void free_virtualpmd_tx_queue(void);
 
 
 static int
-configure_ethdev(uint8_t port_id, uint8_t start, uint8_t en_isr)
+configure_ethdev(uint16_t port_id, uint8_t start, uint8_t en_isr)
 {
int q_id;
 
diff --git a/test/test/test_link_bonding_mode4.c 
b/test/test/test_link_bonding_mode4.c
index 5deea6e16..a7a3f8e25 100644
--- a/test/test/test_link_bonding_mode4.c
+++ b/test/test/test_link_bonding_mode4.c
@@ -102,7 +102,7 @@ static const struct ether_addr slow_protocol_mac_addr = {
 struct slave_conf {
struct rte_ring *rx_queue;
struct rte_ring *tx_queue;
-   uint8_t port_id;
+   uint16_t port_id;
uint8_t bonded : 1;
 
uint8_t lacp_parnter_state;
@@ -235,7 +235,7 @@ free_pkts(struct rte_mbuf **pkts, uint16_t count)
 }
 
 static int
-configure_ethdev(uint8_t port_id, uint8_t start)
+configure_ethdev(uint16_t port_id, uint8_t start)
 {
TEST_ASSERT(rte_eth_dev_configure(port_id, 1, 1, &default_pmd_conf) == 
0,
"Failed to configure device %u", port_id);
diff --git a/test/test/test_link_bonding_rssconf.c 
b/test/test/test_link_bonding_rssconf.c
index f8cf1cabf..7dccc6e12 100644
--- a/test/test/test_link_bonding_rssconf.c
+++ b/test/test/test_link_bonding_rssconf.c
@@ -75,7 +75,7 @@
 #define INVALID_BONDING_MODE(-1)
 
 struct slave_conf {
-   uint8_t port_id;
+   uint16_t port_id;
struct rte_eth_dev_info dev_info;
 
struct rte_eth_rss_conf rss_conf;
@@ -159,7 +159,8 @@ static struct rte_eth_conf rss_pmd_conf = {
RTE_DIM(test_params.slave_ports))
 
 static int
-configure_ethdev(uint8_t port_id, struct rte_eth_conf *eth_conf, uint8_t start)
+configure_ethdev(uint16_t port_id, struct rte_eth_conf *eth_conf,
+uint8_t start)
 {
int rxq, txq;
 
@@ -243,7 +244,7 @@ bond_slaves(void)
  * Set all RETA values in port_id to value
  */
 static int
-reta_set(uint8_t port_id, uint8_t value, int reta_size)
+reta_set(uint16_t port_id, uint8_t value, int reta_size)
 {
struct rte_eth_rss_reta_entry64 reta_conf[512/RTE_RETA_GROUP_SIZE];
int i, j;
-- 
2.13.3



[dpdk-dev] [PATCH 5/8] app: fix port id type

2017-10-13 Thread Zhiyong Yang
Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 app/pdump/main.c   |  2 +-
 app/test-pmd/cmdline.c | 52 ++
 2 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 3d8e50273..66272f59a 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -131,7 +131,7 @@ struct pdump_stats {
 
 struct pdump_tuples {
/* cli params */
-   uint8_t port;
+   uint16_t port;
char *device_id;
uint16_t queue;
char rx_dev[TX_STREAM_SIZE];
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index bb19d726f..bb01e989a 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -1942,7 +1942,7 @@ cmdline_parse_inst_t cmd_config_rss_hash_key = {
 /* *** configure port rxq/txq start/stop *** */
 struct cmd_config_rxtx_queue {
cmdline_fixed_string_t port;
-   uint8_t portid;
+   portid_t portid;
cmdline_fixed_string_t rxtxq;
uint16_t qid;
cmdline_fixed_string_t opname;
@@ -2010,7 +2010,7 @@ cmd_config_rxtx_queue_parsed(void *parsed_result,
 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
-   TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
+   TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, 
"rxq#txq");
 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
@@ -5237,7 +5237,7 @@ struct cmd_set_bond_mac_addr_result {
cmdline_fixed_string_t set;
cmdline_fixed_string_t bonding;
cmdline_fixed_string_t mac_addr;
-   uint8_t port_num;
+   uint16_t port_num;
struct ether_addr address;
 };
 
@@ -5267,7 +5267,8 @@ cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, 
mac_addr,
"mac_addr");
 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
-   TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, 
port_num, UINT8);
+   TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
+   port_num, UINT16);
 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
TOKEN_ETHERADDR_INITIALIZER(struct 
cmd_set_bond_mac_addr_result, address);
 
@@ -5291,7 +5292,7 @@ struct cmd_set_bond_mon_period_result {
cmdline_fixed_string_t set;
cmdline_fixed_string_t bonding;
cmdline_fixed_string_t mon_period;
-   uint8_t port_num;
+   uint16_t port_num;
uint32_t period_ms;
 };
 
@@ -5325,7 +5326,7 @@ cmdline_parse_token_string_t 
cmd_set_bond_mon_period_mon_period =
mon_period, "mon_period");
 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
-   port_num, UINT8);
+   port_num, UINT16);
 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
period_ms, UINT32);
@@ -5350,7 +5351,7 @@ struct cmd_set_bonding_agg_mode_policy_result {
cmdline_fixed_string_t set;
cmdline_fixed_string_t bonding;
cmdline_fixed_string_t agg_mode;
-   uint8_t port_num;
+   uint16_t port_num;
cmdline_fixed_string_t policy;
 };
 
@@ -5393,7 +5394,7 @@ cmdline_parse_token_string_t 
cmd_set_bonding_agg_mode_agg_mode =
 
 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
-   port_num, UINT8);
+   port_num, UINT16);
 
 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
TOKEN_STRING_INITIALIZER(
@@ -5607,7 +5608,7 @@ struct cmd_set_promisc_mode_result {
cmdline_fixed_string_t set;
cmdline_fixed_string_t promisc;
cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
-   uint8_t port_num;/* valid if "allports" argument == 0 */
+   uint16_t port_num;   /* valid if "allports" argument == 0 */
cmdline_fixed_string_t mode;
 };
 
@@ -5687,7 +5688,7 @@ struct cmd_set_allmulti_mode_result {
cmdline_fixed_string_t set;
cmdline_fixed_string_t allmulti;
cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
-   uint8_t port_num;/* valid if "allp

[dpdk-dev] [PATCH 4/8] net/mrvl: fix port id type

2017-10-13 Thread Zhiyong Yang
port id should be defined as uint16_t.

Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 drivers/net/mrvl/mrvl_qos.c | 2 +-
 drivers/net/mrvl/mrvl_qos.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mrvl/mrvl_qos.c b/drivers/net/mrvl/mrvl_qos.c
index 796509b1b..c7b96ef1d 100644
--- a/drivers/net/mrvl/mrvl_qos.c
+++ b/drivers/net/mrvl/mrvl_qos.c
@@ -486,7 +486,7 @@ setup_tc(struct pp2_ppio_tc_params *param, uint8_t inqs,
  * @returns 0 in case of success, negative value otherwise.
  */
 int
-mrvl_configure_rxqs(struct mrvl_priv *priv, uint8_t portid,
+mrvl_configure_rxqs(struct mrvl_priv *priv, uint16_t portid,
uint16_t max_queues)
 {
size_t i, tc;
diff --git a/drivers/net/mrvl/mrvl_qos.h b/drivers/net/mrvl/mrvl_qos.h
index 0fcc85ca7..90c08e98d 100644
--- a/drivers/net/mrvl/mrvl_qos.h
+++ b/drivers/net/mrvl/mrvl_qos.h
@@ -94,7 +94,7 @@ mrvl_get_qoscfg(const char *key __rte_unused, const char 
*path,
  * @returns 0 in case of success, negative value otherwise.
  */
 int
-mrvl_configure_rxqs(struct mrvl_priv *priv, uint8_t portid,
+mrvl_configure_rxqs(struct mrvl_priv *priv, uint16_t portid,
uint16_t max_queues);
 
 /**
-- 
2.13.3



[dpdk-dev] [PATCH 3/8] net/fm10k: fix port id type

2017-10-13 Thread Zhiyong Yang
The variable "port" should be defined as uint16_t, fix it here.

Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 drivers/net/fm10k/fm10k_rxtx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/fm10k/fm10k_rxtx.c b/drivers/net/fm10k/fm10k_rxtx.c
index c9bb04a0e..4e84926f8 100644
--- a/drivers/net/fm10k/fm10k_rxtx.c
+++ b/drivers/net/fm10k/fm10k_rxtx.c
@@ -198,7 +198,7 @@ fm10k_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
q->alloc_thresh);
 
if (unlikely(ret != 0)) {
-   uint8_t port = q->port_id;
+   uint16_t port = q->port_id;
PMD_RX_LOG(ERR, "Failed to alloc mbuf");
/*
 * Need to restore next_dd if we cannot allocate new
@@ -356,7 +356,7 @@ fm10k_recv_scattered_pkts(void *rx_queue, struct rte_mbuf 
**rx_pkts,
q->alloc_thresh);
 
if (unlikely(ret != 0)) {
-   uint8_t port = q->port_id;
+   uint16_t port = q->port_id;
PMD_RX_LOG(ERR, "Failed to alloc mbuf");
/*
 * Need to restore next_dd if we cannot allocate new
-- 
2.13.3



[dpdk-dev] [PATCH 2/8] net/i40e: fix port id type

2017-10-13 Thread Zhiyong Yang
Some functions applied were still developed on top of uint8_t port_id,
however port_id has been increased range to uint16_t. The patch fixes
the issue.

Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 drivers/net/i40e/i40e_ethdev.c  | 2 +-
 drivers/net/i40e/rte_pmd_i40e.c | 8 
 drivers/net/i40e/rte_pmd_i40e.h | 8 
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 71327d1b9..f40c463aa 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -11065,7 +11065,7 @@ i40e_update_customized_ptype(struct rte_eth_dev *dev, 
uint8_t *pkg,
   struct rte_pmd_i40e_proto_info *proto)
 {
struct rte_pmd_i40e_ptype_mapping *ptype_mapping;
-   uint8_t port_id = dev->data->port_id;
+   uint16_t port_id = dev->data->port_id;
uint32_t ptype_num;
struct rte_pmd_i40e_ptype_info *ptype;
uint32_t buff_size;
diff --git a/drivers/net/i40e/rte_pmd_i40e.c b/drivers/net/i40e/rte_pmd_i40e.c
index 3155cf8d9..b113eb4c3 100644
--- a/drivers/net/i40e/rte_pmd_i40e.c
+++ b/drivers/net/i40e/rte_pmd_i40e.c
@@ -2295,7 +2295,7 @@ int rte_pmd_i40e_ptype_mapping_replace(uint16_t port,
 }
 
 int
-rte_pmd_i40e_add_vf_mac_addr(uint8_t port, uint16_t vf_id,
+rte_pmd_i40e_add_vf_mac_addr(uint16_t port, uint16_t vf_id,
 struct ether_addr *mac_addr)
 {
struct rte_eth_dev *dev;
@@ -2338,7 +2338,7 @@ rte_pmd_i40e_add_vf_mac_addr(uint8_t port, uint16_t vf_id,
return 0;
 }
 
-int rte_pmd_i40e_flow_type_mapping_reset(uint8_t port)
+int rte_pmd_i40e_flow_type_mapping_reset(uint16_t port)
 {
struct rte_eth_dev *dev;
 
@@ -2355,7 +2355,7 @@ int rte_pmd_i40e_flow_type_mapping_reset(uint8_t port)
 }
 
 int rte_pmd_i40e_flow_type_mapping_get(
-   uint8_t port,
+   uint16_t port,
struct rte_pmd_i40e_flow_type_mapping *mapping_items)
 {
struct rte_eth_dev *dev;
@@ -2381,7 +2381,7 @@ int rte_pmd_i40e_flow_type_mapping_get(
 
 int
 rte_pmd_i40e_flow_type_mapping_update(
-   uint8_t port,
+   uint16_t port,
struct rte_pmd_i40e_flow_type_mapping *mapping_items,
uint16_t count,
uint8_t exclusive)
diff --git a/drivers/net/i40e/rte_pmd_i40e.h b/drivers/net/i40e/rte_pmd_i40e.h
index f18251be7..467b415b9 100644
--- a/drivers/net/i40e/rte_pmd_i40e.h
+++ b/drivers/net/i40e/rte_pmd_i40e.h
@@ -759,7 +759,7 @@ int rte_pmd_i40e_ptype_mapping_replace(uint16_t port,
  *   - (-ENODEV) if *port* invalid.
  *   - (-EINVAL) if *vf* or *mac_addr* is invalid.
  */
-int rte_pmd_i40e_add_vf_mac_addr(uint8_t port, uint16_t vf_id,
+int rte_pmd_i40e_add_vf_mac_addr(uint16_t port, uint16_t vf_id,
 struct ether_addr *mac_addr);
 
 #define RTE_PMD_I40E_PCTYPE_MAX64
@@ -788,7 +788,7 @@ struct rte_pmd_i40e_flow_type_mapping {
  * set other PCTYPEs maps to PCTYPE_INVALID.
  */
 int rte_pmd_i40e_flow_type_mapping_update(
-   uint8_t port,
+   uint16_t port,
struct rte_pmd_i40e_flow_type_mapping *mapping_items,
uint16_t count,
uint8_t exclusive);
@@ -805,7 +805,7 @@ int rte_pmd_i40e_flow_type_mapping_update(
  *RTE_PMD_I40E_FLOW_TYPE_MAX items
  */
 int rte_pmd_i40e_flow_type_mapping_get(
-   uint8_t port,
+   uint16_t port,
struct rte_pmd_i40e_flow_type_mapping *mapping_items);
 
 /**
@@ -815,7 +815,7 @@ int rte_pmd_i40e_flow_type_mapping_get(
  * @param port
  *pointer to port identifier of the device
  */
-int rte_pmd_i40e_flow_type_mapping_reset(uint8_t port);
+int rte_pmd_i40e_flow_type_mapping_reset(uint16_t port);
 
 /**
  * On the PF, find VF index based on VF MAC address
-- 
2.13.3



[dpdk-dev] [PATCH 1/8] net/bonding: fix port id type

2017-10-13 Thread Zhiyong Yang
Fixes: f8244c6399d9 ("ethdev: increase port id range")
Signed-off-by: Zhiyong Yang 
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c 
b/drivers/net/bonding/rte_eth_bond_pmd.c
index 8cbcf6d72..3fbc1b123 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -538,7 +538,7 @@ ipv4_addr_to_dot(uint32_t be_ipv4_addr, char *buf, uint8_t 
buf_size)
 #define MAX_CLIENTS_NUMBER 128
 uint8_t active_clients;
 struct client_stats_t {
-   uint8_t port;
+   uint16_t port;
uint32_t ipv4_addr;
uint32_t ipv4_rx_packets;
uint32_t ipv4_tx_packets;
@@ -546,7 +546,7 @@ struct client_stats_t {
 struct client_stats_t client_stats[MAX_CLIENTS_NUMBER];
 
 static void
-update_client_stats(uint32_t addr, uint8_t port, uint32_t *TXorRXindicator)
+update_client_stats(uint32_t addr, uint16_t port, uint32_t *TXorRXindicator)
 {
int i = 0;
 
@@ -604,7 +604,7 @@ update_client_stats(uint32_t addr, uint8_t port, uint32_t 
*TXorRXindicator)
 
 static void
 mode6_debug(const char __attribute__((unused)) *info, struct ether_hdr *eth_h,
-   uint8_t port, uint32_t __attribute__((unused)) *burstnumber)
+   uint16_t port, uint32_t __attribute__((unused)) *burstnumber)
 {
struct ipv4_hdr *ipv4_h;
 #ifdef RTE_LIBRTE_BOND_DEBUG_ALB
@@ -2059,7 +2059,7 @@ bond_ethdev_close(struct rte_eth_dev *dev)
 
RTE_LOG(INFO, EAL, "Closing bonded device %s\n", dev->device->name);
while (internals->slave_count != skipped) {
-   uint8_t port_id = internals->slaves[skipped].port_id;
+   uint16_t port_id = internals->slaves[skipped].port_id;
 
rte_eth_dev_stop(port_id);
 
-- 
2.13.3



[dpdk-dev] [PATCH 0/8] fix port id type

2017-10-13 Thread Zhiyong Yang
Fix port id type and update related docs.

Zhiyong Yang (8):
  net/bonding: fix port id type
  net/i40e: fix port id type
  net/fm10k: fix port id type
  net/mrvl: fix port id type
  app: fix port id type
  test: fix port id type
  examples: fix port id type
  doc: update port id type

 app/pdump/main.c   |  2 +-
 app/test-pmd/cmdline.c | 52 +++---
 doc/guides/prog_guide/poll_mode_drv.rst|  2 +-
 doc/guides/prog_guide/rte_flow.rst | 12 ++---
 doc/guides/sample_app_ug/ipv4_multicast.rst|  2 +-
 doc/guides/sample_app_ug/kernel_nic_interface.rst  |  8 ++--
 doc/guides/sample_app_ug/l2_forward_job_stats.rst  |  4 +-
 .../sample_app_ug/l2_forward_real_virtual.rst  |  2 +-
 doc/guides/sample_app_ug/l3_forward.rst| 10 ++---
 doc/guides/sample_app_ug/l3_forward_power_man.rst  |  4 +-
 doc/guides/sample_app_ug/link_status_intr.rst  |  4 +-
 doc/guides/sample_app_ug/ptpclient.rst |  2 +-
 doc/guides/sample_app_ug/rxtx_callbacks.rst|  6 +--
 doc/guides/sample_app_ug/skeleton.rst  |  6 +--
 drivers/net/bonding/rte_eth_bond_pmd.c |  8 ++--
 drivers/net/fm10k/fm10k_rxtx.c |  4 +-
 drivers/net/i40e/i40e_ethdev.c |  2 +-
 drivers/net/i40e/rte_pmd_i40e.c|  8 ++--
 drivers/net/i40e/rte_pmd_i40e.h|  8 ++--
 drivers/net/mrvl/mrvl_qos.c|  2 +-
 drivers/net/mrvl/mrvl_qos.h|  2 +-
 examples/distributor/main.c|  2 +-
 examples/ethtool/lib/rte_ethtool.c | 42 -
 examples/ethtool/lib/rte_ethtool.h | 42 -
 examples/exception_path/main.c |  2 +-
 examples/ipsec-secgw/ipsec-secgw.c | 47 ++-
 examples/kni/main.c| 16 +++
 examples/l2fwd-crypto/main.c   | 18 
 examples/l2fwd-jobstats/main.c | 26 +--
 examples/l3fwd-acl/main.c  | 23 +-
 examples/l3fwd-power/main.c| 12 ++---
 examples/l3fwd/l3fwd_em.c  | 17 +++
 examples/l3fwd/l3fwd_em_sequential.h   |  4 +-
 examples/link_status_interrupt/main.c  | 15 +++
 .../client_server_mp/mp_client/client.c|  6 +--
 examples/multi_process/symmetric_mp/main.c | 21 -
 examples/performance-thread/l3fwd-thread/main.c|  6 +--
 examples/ptpclient/ptpclient.c |  8 ++--
 examples/qos_meter/main.c  |  4 +-
 examples/qos_sched/cmdline.c   | 30 ++---
 examples/quota_watermark/qw/init.c |  4 +-
 examples/quota_watermark/qw/init.h |  4 +-
 examples/quota_watermark/qw/main.c |  4 +-
 examples/quota_watermark/qw/main.h |  2 +-
 examples/rxtx_callbacks/main.c |  2 +-
 examples/server_node_efd/node/node.c   | 21 -
 examples/server_node_efd/server/init.c | 18 
 examples/tep_termination/main.c|  6 +--
 examples/tep_termination/vxlan_setup.c |  6 +--
 examples/tep_termination/vxlan_setup.h | 10 ++---
 examples/vmdq/main.c   |  6 +--
 examples/vmdq_dcb/main.c   |  6 +--
 test/test-pipeline/init.c  |  8 ++--
 test/test/test_link_bonding.c  |  2 +-
 test/test/test_link_bonding_mode4.c|  4 +-
 test/test/test_link_bonding_rssconf.c  |  7 +--
 56 files changed, 306 insertions(+), 295 deletions(-)

-- 
2.13.3



[dpdk-dev] [PATCH 6/6] app/testpmd: fix port id type

2017-10-12 Thread Zhiyong Yang
Fixes: f8244c6399d9 ("ethdev: increase port id range")

Signed-off-by: Zhiyong Yang 
---
 app/test-pmd/cmdline.c | 427 +
 app/test-pmd/config.c  |  14 +-
 app/test-pmd/testpmd.c |  13 +-
 app/test-pmd/testpmd.h |  16 +-
 4 files changed, 236 insertions(+), 234 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 120460452..bb19d726f 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -1141,7 +1141,7 @@ cmdline_parse_inst_t cmd_operate_attach_port = {
 struct cmd_operate_detach_port_result {
cmdline_fixed_string_t port;
cmdline_fixed_string_t keyword;
-   uint8_t port_id;
+   portid_t port_id;
 };
 
 static void cmd_operate_detach_port_parsed(void *parsed_result,
@@ -1164,7 +1164,7 @@ cmdline_parse_token_string_t 
cmd_operate_detach_port_keyword =
keyword, "detach");
 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
-   port_id, UINT8);
+   port_id, UINT16);
 
 cmdline_parse_inst_t cmd_operate_detach_port = {
.f = cmd_operate_detach_port_parsed,
@@ -1543,7 +1543,7 @@ struct cmd_config_mtu_result {
cmdline_fixed_string_t port;
cmdline_fixed_string_t keyword;
cmdline_fixed_string_t mtu;
-   uint8_t port_id;
+   portid_t port_id;
uint16_t value;
 };
 
@@ -1571,7 +1571,7 @@ cmdline_parse_token_string_t cmd_config_mtu_mtu =
TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
 "mtu");
 cmdline_parse_token_num_t cmd_config_mtu_port_id =
-   TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
+   TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
 cmdline_parse_token_num_t cmd_config_mtu_value =
TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
 
@@ -1825,7 +1825,7 @@ cmdline_parse_inst_t cmd_config_rss = {
 struct cmd_config_rss_hash_key {
cmdline_fixed_string_t port;
cmdline_fixed_string_t config;
-   uint8_t port_id;
+   portid_t port_id;
cmdline_fixed_string_t rss_hash_key;
cmdline_fixed_string_t rss_type;
cmdline_fixed_string_t key;
@@ -1907,7 +1907,7 @@ cmdline_parse_token_string_t 
cmd_config_rss_hash_key_config =
TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
 "config");
 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
-   TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
+   TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
 rss_hash_key, "rss-hash-key");
@@ -2037,7 +2037,7 @@ cmdline_parse_inst_t cmd_config_rxtx_queue = {
 struct cmd_config_rss_reta {
cmdline_fixed_string_t port;
cmdline_fixed_string_t keyword;
-   uint8_t port_id;
+   portid_t port_id;
cmdline_fixed_string_t name;
cmdline_fixed_string_t list_name;
cmdline_fixed_string_t list_of_items;
@@ -2146,7 +2146,7 @@ cmdline_parse_token_string_t cmd_config_rss_reta_port =
 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
-   TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
+   TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
 cmdline_parse_token_string_t cmd_config_rss_reta_name =
TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
@@ -2173,7 +2173,7 @@ cmdline_parse_inst_t cmd_config_rss_reta = {
 struct cmd_showport_reta {
cmdline_fixed_string_t show;
cmdline_fixed_string_t port;
-   uint8_t port_id;
+   portid_t port_id;
cmdline_fixed_string_t rss;
cmdline_fixed_string_t reta;
uint16_t size;
@@ -2254,7 +2254,7 @@ cmdline_parse_token_string_t cmd_showport_reta_show =
 cmdline_parse_token_string_t cmd_showport_reta_port =
TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
 cmdline_parse_token_num_t cmd_showport_reta_port_id =
-   TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
+   TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
 cmdline_parse_token_string_t cmd_showport_reta_rss =
TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
 cmdline_parse_token_string_t cmd_showport_reta_reta =
@@ -2285,7 +2285,7 @@ cmdline_parse_inst_t

[dpdk-dev] [PATCH 4/6] app/pdump: fix port id type

2017-10-12 Thread Zhiyong Yang
Increase port id range to 16 bits and remove the unnecessary cast.

Fixes: f8244c6399d9 ("ethdev: increase port id range")

Signed-off-by: Zhiyong Yang 
---
 app/pdump/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 090a50cfc..3d8e50273 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -579,7 +579,7 @@ signal_handler(int sig_num)
 }
 
 static inline int
-configure_vdev(uint8_t port_id)
+configure_vdev(uint16_t port_id)
 {
struct ether_addr addr;
const uint16_t rxRings = 0, txRings = 1;
@@ -609,7 +609,7 @@ configure_vdev(uint8_t port_id)
rte_eth_macaddr_get(port_id, &addr);
printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8
" %02"PRIx8" %02"PRIx8" %02"PRIx8"\n",
-   (unsigned)port_id,
+   port_id,
addr.addr_bytes[0], addr.addr_bytes[1],
addr.addr_bytes[2], addr.addr_bytes[3],
addr.addr_bytes[4], addr.addr_bytes[5]);
-- 
2.13.3



[dpdk-dev] [PATCH 5/6] app/proc_info: fix port id type

2017-10-12 Thread Zhiyong Yang
Fixes: f8244c6399d9 ("ethdev: increase port id range")

Signed-off-by: Zhiyong Yang 
---
 app/proc_info/main.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/app/proc_info/main.c b/app/proc_info/main.c
index 12566e27d..64fbbd0f8 100644
--- a/app/proc_info/main.c
+++ b/app/proc_info/main.c
@@ -310,7 +310,7 @@ meminfo_display(void)
 }
 
 static void
-nic_stats_display(uint8_t port_id)
+nic_stats_display(uint16_t port_id)
 {
struct rte_eth_stats stats;
uint8_t i;
@@ -349,7 +349,7 @@ nic_stats_display(uint8_t port_id)
 }
 
 static void
-nic_stats_clear(uint8_t port_id)
+nic_stats_clear(uint16_t port_id)
 {
printf("\n Clearing NIC stats for port %d\n", port_id);
rte_eth_stats_reset(port_id);
@@ -411,7 +411,7 @@ static void collectd_resolve_cnt_type(char *cnt_type, 
size_t cnt_type_len,
 }
 
 static void
-nic_xstats_by_name_display(uint8_t port_id, char *name)
+nic_xstats_by_name_display(uint16_t port_id, char *name)
 {
uint64_t id;
 
@@ -426,7 +426,7 @@ nic_xstats_by_name_display(uint8_t port_id, char *name)
 }
 
 static void
-nic_xstats_by_ids_display(uint8_t port_id, uint64_t *ids, int len)
+nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len)
 {
struct rte_eth_xstat_name *xstats_names;
uint64_t *values;
@@ -473,7 +473,7 @@ nic_xstats_by_ids_display(uint8_t port_id, uint64_t *ids, 
int len)
 }
 
 static void
-nic_xstats_display(uint8_t port_id)
+nic_xstats_display(uint16_t port_id)
 {
struct rte_eth_xstat_name *xstats_names;
uint64_t *values;
@@ -541,7 +541,7 @@ nic_xstats_display(uint8_t port_id)
 }
 
 static void
-nic_xstats_clear(uint8_t port_id)
+nic_xstats_clear(uint16_t port_id)
 {
printf("\n Clearing NIC xstats for port %d\n", port_id);
rte_eth_xstats_reset(port_id);
@@ -618,7 +618,7 @@ main(int argc, char **argv)
char n_flag[] = "-n4";
char mp_flag[] = "--proc-type=secondary";
char *argp[argc + 3];
-   uint8_t nb_ports;
+   uint16_t nb_ports;
 
/* preparse app arguments */
ret = proc_info_preparse_args(argc, argv);
-- 
2.13.3



  1   2   3   >