virtio PCI Port Hotplug
PATCH v6 1/6 virtio: add support for PCI Port Hotplug
In reply to Bernard IremongerThis patch depends on the Port Hotplug Framework. It implements the eth_dev_uninit_t() function for virtio pmd.
--- drivers/net/virtio/virtio_ethdev.c | 72 ++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 7 deletions(-)
drivers/net/virtio/virtio_ethdev.c +65 -7
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -51,6 +51,7 @@#include <rte_pci.h> #include <rte_ether.h> #include <rte_common.h> +#include <rte_errno.h> #include <rte_memory.h> #include <rte_eal.h>
@@ -63,6 +64,7 @@static int eth_virtio_dev_init (struct rte_eth_dev *eth_dev); +static int eth_virtio_dev_uninit (struct rte_eth_dev *eth_dev);static int virtio_dev_configure (struct rte_eth_dev *dev);static int virtio_dev_start (struct rte_eth_dev *dev);static void virtio_dev_stop (struct rte_eth_dev *dev);
@@ -324,8 +326,12 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, mz =rte_memzone_reserve_aligned (vq_name, vq->vq_ring_size, socket_id,0 ,VIRTIO_PCI_VRING_ALIGN );if (mz ==NULL ) { -rte_free (vq); -return -ENOMEM ; +if (rte_errno ==EEXIST ) + mz =rte_memzone_lookup (vq_name); +if (mz ==NULL ) { +rte_free (vq); +return -ENOMEM ; + } }/*
@@ -358,8 +364,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, vq_size * hw->vtnet_hdr_size, socket_id, 0, RTE_CACHE_LINE_SIZE);if (vq->virtio_net_hdr_mz ==NULL ) { -rte_free (vq); -return -ENOMEM ; +if (rte_errno ==EEXIST ) + vq->virtio_net_hdr_mz = +rte_memzone_lookup (vq_name); +if (vq->virtio_net_hdr_mz ==NULL ) { +rte_free (vq); +return -ENOMEM ; + } } vq->virtio_net_hdr_mem = vq->virtio_net_hdr_mz->phys_addr;
@@ -372,8 +383,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, vq->virtio_net_hdr_mz =rte_memzone_reserve_aligned (vq_name,PAGE_SIZE , socket_id,0 ,RTE_CACHE_LINE_SIZE );if (vq->virtio_net_hdr_mz ==NULL ) { -rte_free (vq); -return -ENOMEM ; +if (rte_errno ==EEXIST ) + vq->virtio_net_hdr_mz = +rte_memzone_lookup (vq_name); +if (vq->virtio_net_hdr_mz ==NULL ) { +rte_free (vq); +return -ENOMEM ; + } } vq->virtio_net_hdr_mem = vq->virtio_net_hdr_mz->phys_addr;
@@ -1250,12 +1266,52 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)return 0 ; } +static int +eth_virtio_dev_uninit (struct rte_eth_dev *eth_dev) +{ +struct rte_pci_device *pci_dev; +struct virtio_hw *hw = eth_dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) +return -EPERM ; + +if (hw->started ==1 ) { +virtio_dev_stop (eth_dev); +virtio_dev_close (eth_dev); + } + pci_dev = eth_dev->pci_dev; + + eth_dev->dev_ops =NULL ; + eth_dev->tx_pkt_burst =NULL ; + eth_dev->rx_pkt_burst =NULL ; + +rte_free (hw->cvq); + hw->cvq =NULL ; + +rte_free (eth_dev->data->mac_addrs); + eth_dev->data->mac_addrs =NULL ; + +/* reset interrupt callback */ +if (pci_dev->driver->drv_flags &RTE_PCI_DRV_INTR_LSC ) +rte_intr_callback_unregister (&pci_dev->intr_handle, + virtio_interrupt_handler, + eth_dev); + +PMD_INIT_LOG (DEBUG ,"dev_uninit completed" ); + +return 0 ; +} +static struct eth_driver rte_virtio_pmd = { .pci_drv = { .name ="rte_virtio_pmd" , .id_table = pci_id_virtio_map, + .drv_flags =RTE_PCI_DRV_DETACHABLE , }, .eth_dev_init = eth_virtio_dev_init, + .eth_dev_uninit = eth_virtio_dev_uninit, .dev_private_size =sizeof (struct virtio_hw ), };
@@ -1398,6 +1454,8 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev) "Before freeing rxq[%d] used and unused buf", i);VIRTQUEUE_DUMP ((struct virtqueue *)dev->data->rx_queues[i]); +PMD_INIT_LOG (DEBUG ,"rx_queues[%d]=%p" , + i, dev->data->rx_queues[i]);while ((buf = (struct rte_mbuf *)virtqueue_detatch_unused ( dev->data->rx_queues[i])) !=NULL ) {rte_pktmbuf_free (buf);
Signature · 1 line
1.9.1
PATCH v6 2/6 virtio: check vq parameter in virtqueue_detatch_unused() function
In reply to Bernard IremongerIf vq is NULL, there is a segmentation fault.
--- drivers/net/virtio/virtqueue.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/virtio/virtqueue.c +8 -6
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -60,11 +60,13 @@ virtqueue_detatch_unused(struct virtqueue *vq)struct rte_mbuf *cookie;int idx; -for (idx =0 ; idx < vq->vq_nentries; idx++) { -if ((cookie = vq->vq_descx[idx].cookie) !=NULL ) { - vq->vq_descx[idx].cookie =NULL ; -return cookie; +if (vq !=NULL ) +for (idx =0 ; idx < vq->vq_nentries; idx++) { + cookie = vq->vq_descx[idx].cookie; +if (cookie !=NULL ) { + vq->vq_descx[idx].cookie =NULL ; +return cookie; + } } - }return NULL ; }
Signature · 1 line
1.9.1
PATCH v6 3/6 virtio: add proper queue release
In reply to Bernard IremongerAdd functions virtio_dev_queue_release(), virtio_dev_rx_queue_release() and virtio_dev_tx_queue_release().
--- drivers/net/virtio/virtio_ethdev.c | 32 ++++++++++++++------------------ drivers/net/virtio/virtio_ethdev.h | 8 +++++++- drivers/net/virtio/virtio_rxtx.c | 12 ++++++++++++ 3 files changed, 33 insertions(+), 19 deletions(-)
drivers/net/virtio/virtio_ethdev.c +14 -18
@@ -80,9 +80,6 @@ static int virtio_dev_link_update(struct rte_eth_dev *dev,static void virtio_set_hwaddr (struct virtio_hw *hw);static void virtio_get_hwaddr (struct virtio_hw *hw); -static void virtio_dev_rx_queue_release(__rte_unused void *rxq); -static void virtio_dev_tx_queue_release(__rte_unused void *txq); -static void virtio_dev_stats_get (struct rte_eth_dev *dev,struct rte_eth_stats *stats);static void virtio_dev_stats_reset (struct rte_eth_dev *dev);static void virtio_dev_free_mbufs (struct rte_eth_dev *dev);
@@ -240,6 +237,20 @@ virtio_set_multiple_queues(struct rte_eth_dev *dev, uint16_t nb_queues)return 0 ; } +void +virtio_dev_queue_release (struct virtqueue *vq) { +struct virtio_hw *hw = vq->hw; + +if (vq) { +/* Select and deactivate the queue */ +VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vq->queue_id); +VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN ,0 ); + +rte_free (vq); + vq =NULL ; + } +} + int virtio_dev_queue_setup(struct rte_eth_dev *dev, int queue_type, uint16_t queue_idx,
@@ -553,10 +564,8 @@ static const struct eth_dev_ops virtio_eth_dev_ops = { .stats_reset = virtio_dev_stats_reset, .link_update = virtio_dev_link_update, .rx_queue_setup = virtio_dev_rx_queue_setup, -/* meaningfull only to multiple queue */ .rx_queue_release = virtio_dev_rx_queue_release, .tx_queue_setup = virtio_dev_tx_queue_setup, -/* meaningfull only to multiple queue */ .tx_queue_release = virtio_dev_tx_queue_release,/* collect stats per queue */ .queue_stats_mapping_set = virtio_dev_queue_stats_mapping_set,
@@ -1335,19 +1344,6 @@ rte_virtio_pmd_init(const char *name __rte_unused, }/* -* Only 1 queue is supported, no queue release related operation -*/ -static void -virtio_dev_rx_queue_release(__rte_unused void *rxq) -{ -} - -static void -virtio_dev_tx_queue_release(__rte_unused void *txq) -{ -} - -/* * Configure virtio device * It returns 0 on success. */
drivers/net/virtio/virtio_ethdev.h +7 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -84,15 +84,21 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,unsigned int socket_id, struct virtqueue **pvq); +void virtio_dev_queue_release (struct virtqueue *vq); +int virtio_dev_rx_queue_setup (struct rte_eth_dev *dev,uint16_t rx_queue_id,uint16_t nb_rx_desc,unsigned int socket_id,const struct rte_eth_rxconf *rx_conf,struct rte_mempool *mb_pool); +void virtio_dev_rx_queue_release (void *rxq); +int virtio_dev_tx_queue_setup (struct rte_eth_dev *dev,uint16_t tx_queue_id,uint16_t nb_tx_desc,unsigned int socket_id,const struct rte_eth_txconf *tx_conf); +void virtio_dev_tx_queue_release (void *txq); +uint16_t virtio_recv_pkts (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts);
drivers/net/virtio/virtio_rxtx.c +12 -0
@@ -401,6 +401,12 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,return 0 ; } +void +virtio_dev_rx_queue_release (void *rxq) +{ +virtio_dev_queue_release (rxq); +} +/* * struct rte_eth_dev *dev: Used to update dev * uint16_t nb_desc: Defaults to values read from config space
@@ -455,6 +461,12 @@ virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,return 0 ; } +void +virtio_dev_tx_queue_release (void *txq) +{ +virtio_dev_queue_release (txq); +} +static void virtio_discard_rxbuf (struct virtqueue *vq,struct rte_mbuf *m) {
Signature · 1 line
1.9.1
PATCH v6 4/6 virtio: free queue memory in virtio_dev_close()
In reply to Bernard IremongerAdd function virtio_free_queues() and call from virtio_dev_close() Use virtio_dev_rx_queue_release() and virtio_dev_tx_queue_release()
--- drivers/net/virtio/virtio_ethdev.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/net/virtio/virtio_ethdev.c +17 -0
@@ -439,6 +439,22 @@ virtio_dev_cq_queue_setup(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx, }static void +virtio_free_queues (struct rte_eth_dev *dev) +{ +unsigned int i; + +for (i =0 ; i < dev->data->nb_rx_queues; i++) +virtio_dev_rx_queue_release (dev->data->rx_queues[i]); + + dev->data->nb_rx_queues =0 ; + +for (i =0 ; i < dev->data->nb_tx_queues; i++) +virtio_dev_tx_queue_release (dev->data->tx_queues[i]); + + dev->data->nb_tx_queues =0 ; +} + +static void virtio_dev_close (struct rte_eth_dev *dev) {struct virtio_hw *hw = dev->data->dev_private;
@@ -452,6 +468,7 @@ virtio_dev_close(struct rte_eth_dev *dev)vtpci_reset (hw); hw->started =0 ;virtio_dev_free_mbufs (dev); +virtio_free_queues (dev); } static void
Signature · 1 line
1.9.1
PATCH v6 5/6 virtio: use queue_release in dev_uninit
In reply to Bernard Iremonger--- drivers/net/virtio/virtio_ethdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -2
@@ -1313,8 +1313,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) eth_dev->tx_pkt_burst =NULL ; eth_dev->rx_pkt_burst =NULL ; -rte_free (hw->cvq); - hw->cvq =NULL ; +virtio_dev_queue_release (hw->cvq);rte_free (eth_dev->data->mac_addrs); eth_dev->data->mac_addrs =NULL ;
Signature · 1 line
1.9.1
v6 cover virtio PCI Port Hotplug
Changes in V6:
Rebase.
Use queue_release function in dev_uninit function (patch 5) Set vq to NULL in queue release function.
Move previous patch 5 to patch 6.
Changes in V5:
Rebase.
Add proper queue release patch (patch 3). Reorder patches, moved previous patch 3 to patch 4, moved previous patch 4 to patch 5.
Changes in V4:
Rebase to latest code.
Move freeing of queue memory from uninit() function to close() function. Change to testpmd to facilate testing on VM.
Changes in V3:
Rebase to latest code.
Free queue memory in uninit() function.
Changes in V2:
Rebase to use new drivers directory.
Bernard Iremonger (6):
virtio: add support for PCI Port Hotplug
virtio: check vq parameter in virtqueue_detatch_unused() function
virtio: add proper queue release
virtio: free queue memory in virtio_dev_close()
virtio: use queue_release in dev_uninit
test-pmd: remove call to rte_eth_promiscuous_disable() from
detach_port()
app/test-pmd/testpmd.c | 4 +- drivers/net/virtio/virtio_ethdev.c | 120 +++++++++++++++++++++++++++++-------- drivers/net/virtio/virtio_ethdev.h | 8 ++- drivers/net/virtio/virtio_rxtx.c | 12 ++++ drivers/net/virtio/virtqueue.c | 14 +++-- 5 files changed, 123 insertions(+), 35 deletions(-)
Signature · 1 line
1.9.1
PATCH v6 6/6 test-pmd: remove call to rte_eth_promiscuous_disable() from detach_port()
At this point the stop() and close() functions have already been called. The rte_eth_promiscuous_disable() function does not return on the VM.
--- app/test-pmd/testpmd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
app/test-pmd/testpmd.c +1 -3
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -1542,8 +1542,6 @@ detach_port(uint8_t port_id)return ; } -rte_eth_promiscuous_disable (port_id); -if (rte_eth_dev_detach (port_id, name))return ;
Signature · 1 line
1.9.1
Quoted 34 lines · On Wed, 15 Jul 2015 14:50:59 +0100 Bernard Iremonger…
Changes in V6:
Rebase.
Usequeue_releasefunction indev_uninitfunction (patch 5) Set vq to NULL in queue release function.
Move previous patch 5 to patch 6.Changes in V5:
Rebase.
Add proper queue release patch (patch 3). Reorder patches, moved previous patch 3 to patch 4, moved previous patch 4 to patch 5.Changes in V4:
Rebase to latest code.
Move freeing of queue memory fromuninit()function toclose()function. Change to testpmd to facilate testing on VM.Changes in V3:
Rebase to latest code.
Free queue memory inuninit()function.Changes in V2:
Rebase to use new drivers directory.Bernard Iremonger (6):
virtio: add support for PCI Port Hotplug
virtio: check vq parameter invirtqueue_detatch_unused()function
virtio: add proper queue release
virtio: free queue memory invirtio_dev_close()
virtio: usequeue_releaseindev_uninit
test-pmd: remove call torte_eth_promiscuous_disable()from
detach_port()
Quoted 7 lines
app/test-pmd/testpmd.c | 4 +- drivers/net/virtio/virtio_ethdev.c | 120 +++++++++++++++++++++++++++++-------- drivers/net/virtio/virtio_ethdev.h | 8 ++- drivers/net/virtio/virtio_rxtx.c | 12 ++++ drivers/net/virtio/virtqueue.c | 14 +++-- 5 files changed, 123 insertions(+), 35 deletions(-)
Looks good thanks.
Re: [PATCH v6 6/6] test-pmd: remove call to rte_eth_promiscuous_disable() from detach_port()
In reply to Bernard IremongerBernard
Apply the patchset and run vhost-sample, both vhost-user and vhost-cuse, no impact. Thx.
Thanks
Qian
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bernard Iremonger
Sent: Wednesday, July 15, 2015 9:51 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v6 6/6] test-pmd: remove call to rte_eth_promiscuous_disable() from detach_port()
At this point the stop() and close() functions have already been called. The rte_eth_promiscuous_disable() function does not return on the VM.
--- app/test-pmd/testpmd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
app/test-pmd/testpmd.c +1 -3
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -1542,8 +1542,6 @@ detach_port(uint8_t port_id)return ; } -rte_eth_promiscuous_disable (port_id); -if (rte_eth_dev_detach (port_id, name))return ;
--
1.9.1
Thomas Monjalon
AppliedQuoted 9 lines
Quoted 8 lines
Bernard Iremonger (6):
virtio: add support for PCI Port Hotplug
virtio: check vq parameter invirtqueue_detatch_unused()function
virtio: add proper queue release
virtio: free queue memory invirtio_dev_close()
virtio: usequeue_releaseindev_uninit
test-pmd: remove call torte_eth_promiscuous_disable()from
detach_port()
Quoted 3 lines
Looks good thanks.
Applied, thanks