vDPA/ifcvf: implement shared IRQ feature
Subsystems (5)
v4 cover vDPA/ifcvf: implement shared IRQ feature
It has been observed that on some platforms/devices, there may not be enough MSI vectors for virtqueues and the config change. Under such circumstances, the interrupt sources of a device have to share vectors/IRQs.
This series implemented a shared IRQ feature for ifcvf.
Please help review.
For the test report, plase kindly refer to last version cover letter:
https://www.spinics.net/lists/netdev/msg795808.html
Changes from V3:
fix code indenting issues reported by LKP:
Changes from V2:
(1) Fix misuse of nvectors(in ifcvf_alloc_vectors return value)(Michael)
(2) Fix misuse of irq = get_vq_irq() in setup irqbypass(Michael)
(3) Coding style improvements(Michael)
(4) Better naming of device shared irq/shared vq irq
Changes from V1:
(1) Enable config interrupt when only one vector is allocated(Michael)
(2) Clean vectors/IRQs if failed to request config interrupt since config interrupt is a must(Michael)
(3) Keep local vdpa_ops, disable irq_bypass by setting IRQ = -EINVAL for shared IRQ case(Michael)
(4) Improvements on error messages(Michael)
(5) Squash functions implementation patches to the callers(Michael)
Zhu Lingshan (4):
vDPA/ifcvf: implement IO read/write helpers in the header file vDPA/ifcvf: implement device MSIX vector allocator
vhost_vdpa: don't setup irq offloading when irq_num < 0 vDPA/ifcvf: implement shared IRQ feature
drivers/vdpa/ifcvf/ifcvf_base.c | 67 +++----- drivers/vdpa/ifcvf/ifcvf_base.h | 60 +++++++- drivers/vdpa/ifcvf/ifcvf_main.c | 262 ++++++++++++++++++++++++++++---- drivers/vhost/vdpa.c | 4 + 4 files changed, 314 insertions(+), 79 deletions(-)
Signature · 1 line
2.27.0
PATCH v4 1/4 vDPA/ifcvf: implement IO read/write helpers in the header file
re-implement IO read/write helpers in the header file, so that they can be utilized among modules.
--- drivers/vdpa/ifcvf/ifcvf_base.c | 36 -------------------------------- drivers/vdpa/ifcvf/ifcvf_base.h | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 36 deletions(-)
drivers/vdpa/ifcvf/ifcvf_base.c +0 -36
@@ -10,42 +10,6 @@#include "ifcvf_base.h" -static inline u8 ifc_ioread8 (u8 __iomem *addr) -{ -return ioread8 (addr); -} -static inline u16 ifc_ioread16 (__le16 __iomem *addr) -{ -return ioread16 (addr); -} - -static inline u32 ifc_ioread32 (__le32 __iomem *addr) -{ -return ioread32 (addr); -} - -static inline void ifc_iowrite8 (u8 value,u8 __iomem *addr) -{ -iowrite8 (value, addr); -} - -static inline void ifc_iowrite16 (u16 value,__le16 __iomem *addr) -{ -iowrite16 (value, addr); -} - -static inline void ifc_iowrite32 (u32 value,__le32 __iomem *addr) -{ -iowrite32 (value, addr); -} - -static void ifc_iowrite64_twopart (u64 val, -__le32 __iomem *lo,__le32 __iomem *hi) -{ -ifc_iowrite32 ((u32 )val, lo); -ifc_iowrite32 (val >>32 , hi); -} -struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw) { return container_of(hw, struct ifcvf_adapter, vf);
drivers/vdpa/ifcvf/ifcvf_base.h +37 -0
@@ -42,6 +42,43 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +static inline u8 ifc_ioread8 (u8 __iomem *addr) +{ +return ioread8 (addr); +} + +static inline u16 ifc_ioread16 (__le16 __iomem *addr) +{ +return ioread16 (addr); +} + +static inline u32 ifc_ioread32 (__le32 __iomem *addr) +{ +return ioread32 (addr); +} + +static inline void ifc_iowrite8 (u8 value,u8 __iomem *addr) +{ +iowrite8 (value, addr); +} + +static inline void ifc_iowrite16 (u16 value,__le16 __iomem *addr) +{ +iowrite16 (value, addr); +} + +static inline void ifc_iowrite32 (u32 value,__le32 __iomem *addr) +{ +iowrite32 (value, addr); +} + +static inline void ifc_iowrite64_twopart (u64 val, +__le32 __iomem *lo,__le32 __iomem *hi) +{ +ifc_iowrite32 ((u32 )val, lo); +ifc_iowrite32 (val >>32 , hi); +} +struct vring_info {u64 desc;u64 avail;
Signature · 1 line
2.27.0
Re: [PATCH V4 1/4] vDPA/ifcvf: implement IO read/write helpers in the header file
Quoted 4 lines · Zhu Lingshan
re-implement IO read/write helpers in the header file, so that they can be utilized among modules.
Signed-off-by Zhu Lingshan <[email protected]>
I wonder if we can simply use include/linux/virtio_pci_modern.h.
The accessors vp_ioreadX/writeX() there were decoupled from the virtio_pci_modern_device structure.
Thanks
Quoted 100 lines
--- drivers/vdpa/ifcvf/ifcvf_base.c | 36 -------------------------------- drivers/vdpa/ifcvf/ifcvf_base.h | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 36 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +0
-36@@ -10,42 +10,6 @@#include "ifcvf_base.h" -static inline u8 ifc_ioread8 (u8 __iomem *addr) -{ -return ioread8 (addr); -} -static inline u16 ifc_ioread16 (__le16 __iomem *addr) -{ -return ioread16 (addr); -} - -static inline u32 ifc_ioread32 (__le32 __iomem *addr) -{ -return ioread32 (addr); -} - -static inline void ifc_iowrite8 (u8 value,u8 __iomem *addr) -{ -iowrite8 (value, addr); -} - -static inline void ifc_iowrite16 (u16 value,__le16 __iomem *addr) -{ -iowrite16 (value, addr); -} - -static inline void ifc_iowrite32 (u32 value,__le32 __iomem *addr) -{ -iowrite32 (value, addr); -} - -static void ifc_iowrite64_twopart (u64 val, -__le32 __iomem *lo,__le32 __iomem *hi) -{ -ifc_iowrite32 ((u32 )val, lo); -ifc_iowrite32 (val >>32 , hi); -} -struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw) { return container_of(hw, struct ifcvf_adapter, vf);drivers/vdpa/ifcvf/ifcvf_base.h +37
-0@@ -42,6 +42,43 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +static inline u8 ifc_ioread8 (u8 __iomem *addr) +{ +return ioread8 (addr); +} + +static inline u16 ifc_ioread16 (__le16 __iomem *addr) +{ +return ioread16 (addr); +} + +static inline u32 ifc_ioread32 (__le32 __iomem *addr) +{ +return ioread32 (addr); +} + +static inline void ifc_iowrite8 (u8 value,u8 __iomem *addr) +{ +iowrite8 (value, addr); +} + +static inline void ifc_iowrite16 (u16 value,__le16 __iomem *addr) +{ +iowrite16 (value, addr); +} + +static inline void ifc_iowrite32 (u32 value,__le32 __iomem *addr) +{ +iowrite32 (value, addr); +} + +static inline void ifc_iowrite64_twopart (u64 val, +__le32 __iomem *lo,__le32 __iomem *hi) +{ +ifc_iowrite32 ((u32 )val, lo); +ifc_iowrite32 (val >>32 , hi); +} +struct vring_info {u64 desc;u64 avail;
Re: [PATCH V4 1/4] vDPA/ifcvf: implement IO read/write helpers in the header file
Quoted 5 lines · Jason Wang
Quoted 3 lines · Zhu Lingshan
re-implement IO read/write helpers in the header file, so that they can be utilized among modules.
Quoted 8 lines
Quoted 1 line
Signed-off-by Zhu Lingshan <[email protected]>I wonder if we can simply use
include/linux/virtio_pci_modern.h.The accessors vp_ioreadX/writeX() there were decoupled from the
virtio_pci_modern_devicestructure.Thanks
sure, can do.
Thanks
Quoted 100 lines
Quoted 99 lines
---
drivers/vdpa/ifcvf/ifcvf_base.c| 36 --------------------------------drivers/vdpa/ifcvf/ifcvf_base.h| 37 +++++++++++++++++++++++++++++++++2 files changed, 37 insertions(+), 36 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +0
-35@@ -10,42 +10,6 @@ #include "ifcvf_base.h" -static inline u8 ifc_ioread8(u8 __iomem *addr) -{ - return ioread8(addr); -} -static inline u16 ifc_ioread16 (__le16 __iomem *addr) -{ - return ioread16(addr); -} - -static inline u32 ifc_ioread32 (__le32 __iomem *addr) -{ - return ioread32(addr); -} - -static inline void ifc_iowrite8 (u8 value,u8 __iomem *addr) -{ - iowrite8(value, addr); -} - -static inline void ifc_iowrite16 (u16 value,__le16 __iomem *addr) -{ - iowrite16(value, addr); -} - -static inline void ifc_iowrite32 (u32 value,__le32 __iomem *addr) -{ - iowrite32(value, addr); -} - -static void ifc_iowrite64_twopart (u64 val, - __le32 __iomem *lo, __le32 __iomem *hi) -{ - ifc_iowrite32((u32)val, lo); - ifc_iowrite32(val >> 32, hi); -} - struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) { return container_of(hw, struct ifcvf_adapter, vf);drivers/vdpa/ifcvf/ifcvf_base.h +36
-0@@ -42,6 +42,43 @@ #define ifcvf_private_to_vf(adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +static inline u8 ifc_ioread8(u8 __iomem *addr) +{ + return ioread8(addr); +} + +static inline u16 ifc_ioread16 (__le16 __iomem *addr) +{ + return ioread16(addr); +} + +static inline u32 ifc_ioread32 (__le32 __iomem *addr) +{ + return ioread32(addr); +} + +static inline void ifc_iowrite8 (u8 value,u8 __iomem *addr) +{ + iowrite8(value, addr); +} + +static inline void ifc_iowrite16 (u16 value,__le16 __iomem *addr) +{ + iowrite16(value, addr); +} + +static inline void ifc_iowrite32 (u32 value,__le32 __iomem *addr) +{ + iowrite32(value, addr); +} + +static inline void ifc_iowrite64_twopart (u64 val, + __le32 __iomem *lo, __le32 __iomem *hi) +{ + ifc_iowrite32((u32)val, lo); + ifc_iowrite32(val >> 32, hi); +} + struct vring_info { u64 desc; u64 avail;
PATCH v4 2/4 vDPA/ifcvf: implement device MSIX vector allocator
In reply to Zhu LingshanThis commit implements a MSIX vector allocation helper for vqs and config interrupts.
--- drivers/vdpa/ifcvf/ifcvf_main.c | 35 +++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
drivers/vdpa/ifcvf/ifcvf_main.c +33 -2
@@ -58,14 +58,45 @@ static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues)ifcvf_free_irq_vectors (pdev); } +/* ifcvf MSIX vectors allocator, this helper tries to allocate +* vectors for all virtqueues and the config interrupt. +* It returns the number of allocated vectors, negative +* return value when fails. +*/ +static int ifcvf_alloc_vectors (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int max_intr, ret; + +/* all queues and config interrupt */ + max_intr = vf->nr_vring +1 ; + ret =pci_alloc_irq_vectors (pdev,1 , max_intr,PCI_IRQ_MSIX |PCI_IRQ_AFFINITY ); + +if (ret <0 ) { +IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" ); +return ret; + } + +if (ret < max_intr) +IFCVF_INFO (pdev, +"Requested %u vectors, however only %u allocated, lower performance\n" , + max_intr, ret); + +return ret; +} +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, i, ret, irq; +int vector, nvectors, i, ret, irq;u16 max_intr; -/* all queues and config interrupt */ + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + max_intr = vf->nr_vring +1 ; ret = pci_alloc_irq_vectors(pdev, max_intr,
Signature · 1 line
2.27.0
Re: [PATCH V4 2/4] vDPA/ifcvf: implement device MSIX vector allocator
Quoted 46 lines · Zhu Lingshan
This commit implements a MSIX vector allocation helper for vqs and config interrupts.
Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_main.c | 35 +++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)drivers/vdpa/ifcvf/ifcvf_main.c +28
-0@@ -58,14 +58,45 @@ static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues)ifcvf_free_irq_vectors (pdev); } +/* ifcvf MSIX vectors allocator, this helper tries to allocate +* vectors for all virtqueues and the config interrupt. +* It returns the number of allocated vectors, negative +* return value when fails. +*/ +static int ifcvf_alloc_vectors (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int max_intr, ret; + +/* all queues and config interrupt */ + max_intr = vf->nr_vring +1 ; + ret =pci_alloc_irq_vectors (pdev,1 , max_intr,PCI_IRQ_MSIX |PCI_IRQ_AFFINITY ); + +if (ret <0 ) { +IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" ); +return ret; + } + +if (ret < max_intr) +IFCVF_INFO (pdev, +"Requested %u vectors, however only %u allocated, lower performance\n" , + max_intr, ret); + +return ret; +} +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) {
drivers/vdpa/ifcvf/ifcvf_main.c static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) · line 98
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +4
-2struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, i, ret, irq; +int vector, nvectors, i, ret, irq;u16 max_intr; -/* all queues and config interrupt */ + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors;
Why not simply checking by using nvectors <= 0? If ifcvf_alloc_vectors can return 0 this breaks the ifcvf_request_irq() caller's assumption.
drivers/vdpa/ifcvf/ifcvf_main.c static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) · line 102
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0+ max_intr = vf->nr_vring +1 ; ret = pci_alloc_irq_vectors(pdev, max_intr,
So irq is allocated twice here?
Thanks
Re: [PATCH V4 2/4] vDPA/ifcvf: implement device MSIX vector allocator
Quoted 54 lines · Jason Wang
Quoted 52 lines · Zhu Lingshan
This commit implements a MSIX vector allocation helper for vqs and config interrupts.
Signed-off-by Zhu Lingshan <[email protected]>---
drivers/vdpa/ifcvf/ifcvf_main.c| 35 +++++++++++++++++++++++++++++++--1 file changed, 33 insertions(+), 2 deletions(-)drivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -58,14 +58,45 @@ static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) ifcvf_free_irq_vectors(pdev); }+/* ifcvf MSIX vectors allocator, this helper tries to allocate
+ * vectors for all virtqueues and the config interrupt.
+ * It returns the number of allocated vectors, negative
+ * return value when fails.
+ */drivers/vdpa/ifcvf/ifcvf_main.c +9
-0+static int ifcvf_alloc_vectors (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + int max_intr, ret; + + /* all queues and config interrupt */ + max_intr = vf->nr_vring + 1; + ret = pci_alloc_irq_vectors(pdev, 1, max_intr, PCI_IRQ_MSIX |
PCI_IRQ_AFFINITY);drivers/vdpa/ifcvf/ifcvf_main.c +9
-0+ + if (ret < 0) { + IFCVF_ERR(pdev, "Failed to alloc IRQ vectors\n"); + return ret; + } + + if (ret < max_intr) + IFCVF_INFO(pdev, + "Requested %u vectors, however only %u allocated,lower performance\n",
+max_intr, ret);drivers/vdpa/ifcvf/ifcvf_main.c +4
-0+ + return ret; +} +static int
ifcvf_request_irq(struct ifcvf_adapter *adapter){
structpci_dev*pdev =adapter->pdev;
structifcvf_hw*vf =&adapter->vf;
- int vector, i, ret, irq;
+ int vector, nvectors, i, ret, irq;
Quoted 8 lines
Quoted 5 lines
u16
max_intr;
- /* all queues and config interrupt */
+ nvectors =ifcvf_alloc_vectors(adapter);
+ if (!(nvectors > 0))
+ return nvectors;Why not simply checking by using nvectors <= 0? If
ifcvf_alloc_vectorscan return 0 this breaks theifcvf_request_irq()caller's assumption.
It can return zero if no vectors allocated, then ifcvf_request_irq fails. For sure I can use <=0
Thanks!
Quoted 8 lines
Quoted 5 lines
+
max_intr=vf->nr_vring+ 1;
ret = pci_alloc_irq_vectors(pdev,max_intr,So irq is allocated twice here?
Oh, it is a rebasing problem, I should move the deleting line here from the next patch.
Thanks
Quoted 4 lines
Thanks
PATCH v4 3/4 vhost_vdpa: don't setup irq offloading when irq_num < 0
In reply to Zhu LingshanWhen irq number is negative(e.g., -EINVAL), the virtqueue may be disabled or the virtqueues are sharing a device irq. In such case, we should not setup irq offloading for a virtqueue.
--- drivers/vhost/vdpa.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/vhost/vdpa.c +4 -0
@@ -96,6 +96,10 @@ static void vhost_vdpa_setup_vq_irq(struct vhost_vdpa *v, u16 qid)if (!ops->get_vq_irq)return ; + irq = ops->get_vq_irq (vdpa, qid); +if (irq <0 ) +return ; + irq = ops->get_vq_irq (vdpa, qid);irq_bypass_unregister_producer (&vq->call_ctx.producer);if (!vq->call_ctx.ctx || irq <0 )
Signature · 1 line
2.27.0
Re: [PATCH V4 3/4] vhost_vdpa: don't setup irq offloading when irq_num < 0
Quoted 14 lines · Zhu Lingshan
When irq number is
negative(e.g., -EINVAL), the virtqueue may be disabled or the virtqueues are sharing a device irq. In such case, we should not setup irq offloading for a virtqueue.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vhost/vdpa.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/vhost/vdpa.c +0
-0
drivers/vhost/vdpa.c static void vhost_vdpa_setup_vq_irq(struct vhost_vdpa *v, u16 qid) · line 103
Quoted 8 lines
drivers/vhost/vdpa.c +4
-0@@ -96,6 +96,10 @@ static void vhost_vdpa_setup_vq_irq(struct vhost_vdpa *v, u16 qid)if (!ops->get_vq_irq)return ; + irq = ops->get_vq_irq (vdpa, qid); +if (irq <0 ) +return ; + irq = ops->get_vq_irq (vdpa, qid);
So the get_vq_irq() will be called twice?
drivers/vhost/vdpa.c static void vhost_vdpa_setup_vq_irq(struct vhost_vdpa *v, u16 qid) · line 105
Quoted 2 lines
drivers/vhost/vdpa.c +0
-0irq_bypass_unregister_producer (&vq->call_ctx.producer);if (!vq->call_ctx.ctx || irq <0 )
We're already checked irq against 0 here.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V4 3/4] vhost_vdpa: don't setup irq offloading when irq_num < 0
Quoted 11 lines · Jason Wang
Quoted 9 lines · Zhu Lingshan
When irq number is
negative(e.g., -EINVAL), the virtqueue may be disabled or the virtqueues are sharing a device irq. In such case, we should not setup irq offloading for a virtqueue.Signed-off-by Zhu Lingshan <[email protected]>---
drivers/vhost/vdpa.c| 4 ++++1 file changed, 4 insertions(+)
Quoted 16 lines
drivers/vhost/vdpa.c static void vhost_vdpa_setup_vq_irq(struct · line 103
Quoted 13 lines
drivers/vhost/vdpa.c +3
-0@@ -96,6 +96,10 @@ static void vhost_vdpa_setup_vq_irq(struct vhost_vdpa *v, u16 qid) if (!ops->get_vq_irq) return; + irq = ops->get_vq_irq(vdpa, qid); + if (irq < 0) + return; + irq = ops->get_vq_irq(vdpa, qid);So the
get_vq_irq()will be called twice?
yes, the latter one should be removed
Quoted 7 lines
Quoted 4 lines
drivers/vhost/vdpa.c +0
-0irq_bypass_unregister_producer (&vq->call_ctx.producer);if (!vq->call_ctx.ctx || irq < 0)
We're already checked irq against 0 here.
sure, will remove this
Thanks!
Quoted 5 lines
Thanks
PATCH v4 4/4 vDPA/ifcvf: implement shared IRQ feature
In reply to Zhu LingshanOn some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt sources(virtqueues, config changes) must share an IRQ/vector, to avoid initialization failures, keep the device functional.
This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.
Otherwise, it needs to fail.
This commit introduces some helper functions:ifcvf_set_vq_vector() and ifcvf_set_config_vector() sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.
This commit adds some fields in struct ifcvf_hw and re-placed the existed fields to be aligned with the cacheline.
--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)
drivers/vdpa/ifcvf/ifcvf_base.c +32 -15
@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector) +{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select); +ifc_iowrite16 (vector, &cfg->queue_msix_vector); +if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + } + +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector) +{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + } + +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {
@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; }
@@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)
@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable); }
drivers/vdpa/ifcvf/ifcvf_base.h +16 -7
@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40
@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 +/* all vqs share a vector, and config interrupt has a separate vector */ +#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3 +static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);
@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {
@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */
drivers/vdpa/ifcvf/ifcvf_main.c +208 -35
309 lines not on this page · raw message
Signature · 1 line
2.27.0
Quoted 43 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +1
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector)
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 28
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select); +ifc_iowrite16 (vector, &cfg->queue_msix_vector); +if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + }
Let's leave this check for the caller, E.g can caller try to assign NO_VECTOR during uni-nit?
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + }
Similar question as above.
Quoted 59 lines
drivers/vdpa/ifcvf/ifcvf_base.c +6
-15+ +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; }@@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable); }drivers/vdpa/ifcvf/ifcvf_base.h +0
-2@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_base.h +6
-0@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 +/* all vqs share a vector, and config interrupt has a separate vector */ +#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3
I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;
Any reason for moving nv_vring, config_size, and other stuffs?
Quoted 40 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */ drivers/vdpa/ifcvf/ifcvf_main.c +0
-0
drivers/vdpa/ifcvf/ifcvf_main.c line 20
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0@@ -17,6 +17,7 @@#define DRIVER_AUTHOR "Intel Corporation"#define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */
This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, void *arg) · line 31
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0static irqreturn_t ifcvf_config_changed (int irq,void *arg) {struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg)return IRQ_HANDLED ; } +/* handles vqs interrupt */
So did this.
Quoted 20 lines
drivers/vdpa/ifcvf/ifcvf_main.c +13
-0static irqreturn_t ifcvf_intr_handler (int irq,void *arg) {struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +struct vring_info *vring; +int i; + +for (i =0 ; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; +if (vring->cb.callback) + vf->vring->cb.callback (vring->cb.private); + } +
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 64
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+return IRQ_HANDLED ; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +u8 isr; + + isr =ifc_ioread8 (vf->isr);
We need to exactly what vp_interrupt do here. Checking against vf->isr first and return IRQ_NONE if it is not set.
Always return IRQ_HANDLED will break the device who shares an irq with IFCVF.
Quoted 94 lines
drivers/vdpa/ifcvf/ifcvf_main.c +57
-12+if (isr &VIRTIO_PCI_ISR_CONFIG ) +ifcvf_config_changed (irq, arg); + +return ifcvf_vq_shared_intr_handler (irq, arg); +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data); } -static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +static void ifcvf_free_vq_irq (struct ifcvf_adapter *adapter,int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf;int i; +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) { +for (i =0 ; i < queues; i++) { +devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL ; + } + }else { +devm_free_irq (&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL ; + } +} -for (i =0 ; i < queues; i++) { -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL ; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; + +/* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status != MSIX_VECTOR_DEV_SHARED +*/ +if (vf->msix_vector_status !=MSIX_VECTOR_DEV_SHARED ) { +devm_free_irq (&pdev->dev, vf->config_irq, vf); + vf->config_irq = -EINVAL ; } +} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ +struct pci_dev *pdev = adapter->pdev; -devm_free_irq (&pdev->dev, vf->config_irq, vf); +ifcvf_free_vq_irq (adapter, queues); +ifcvf_free_config_irq (adapter);ifcvf_free_irq_vectors (pdev); }@@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter)return ret; } -static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +static int ifcvf_request_per_vq_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, nvectors, i, ret, irq; -u16 max_intr; +int i, vector, ret, irq; - nvectors =ifcvf_alloc_vectors (adapter); -if (!(nvectors >0 )) -return nvectors; +for (i =0 ; i < vf->nr_vring; i++) { +snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" ,pci_name (pdev), i); + vector = i; + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_intr_handler,0 , + vf->vring[i].msix_name, + &vf->vring[i]); +if (ret) { +IFCVF_ERR (pdev,"Failed to request irq for vq %d\n" , i); +ifcvf_free_vq_irq (adapter, i); + }else { + vf->vring[i].irq = irq; +ifcvf_set_vq_vector (vf, i, vector); + } + } - max_intr = vf->nr_vring +1 ; + vf->vqs_shared_irq = -EINVAL ; + +return 0 ;
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 180
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */
I think we can remove this comment since the code is straightforward.
Quoted 113 lines
drivers/vdpa/ifcvf/ifcvf_main.c +81
-18+snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-vqs-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_vq_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); + +return ret; + } + + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + +return 0 ; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared device interrupt name */ +snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-dev-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_dev_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); - ret =pci_alloc_irq_vectors (pdev, max_intr, - max_intr,PCI_IRQ_MSIX ); -if (ret <0 ) { -IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" );return ret; } + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + + vf->config_irq = irq; +ifcvf_set_config_vector (vf, vector); + +return 0 ; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) + ret =ifcvf_request_per_vq_irq (adapter); +else + ret =ifcvf_request_shared_vq_irq (adapter); + +return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int config_vector, ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_DEV_SHARED ) +return 0 ; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) +/* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vector for config interrupt */ + config_vector = vf->nr_vring; + +if (vf->msix_vector_status ==MSIX_VECTOR_SHARED_VQ_AND_CONFIG ) +/* vector 0 for vqs and 1 for config interrupt */ + config_vector =1 ; +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" ,pci_name (pdev)); - vector =0 ; - vf->config_irq =pci_irq_vector (pdev, vector); + vf->config_irq =pci_irq_vector (pdev, config_vector); ret =devm_request_irq (&pdev->dev, vf->config_irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);if (ret) {IFCVF_ERR (pdev,"Failed to request config irq\n" ); +ifcvf_free_vq_irq (adapter, vf->nr_vring);return ret; } -for (i =0 ; i < vf->nr_vring; i++) { -snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" , -pci_name (pdev), i); - vector = i +IFCVF_MSI_QUEUE_OFF ; - irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, - ifcvf_intr_handler,0 , - vf->vring[i].msix_name, - &vf->vring[i]); -if (ret) { -IFCVF_ERR (pdev, -"Failed to request irq for vq %d\n" , i);
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-3-ifcvf_free_irq (adapter, i); +ifcvf_set_config_vector (vf, config_vector); -return ret; - } +return 0 ; +} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{
As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Thanks
Quoted 44 lines
drivers/vdpa/ifcvf/ifcvf_main.c +29
-2+struct ifcvf_hw *vf = &adapter->vf; +int nvectors, ret, max_intr; - vf->vring[i].irq = irq; + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + + vf->msix_vector_status =MSIX_VECTOR_PER_VQ_AND_CONFIG ; + max_intr = vf->nr_vring +1 ; +if (nvectors < max_intr) + vf->msix_vector_status =MSIX_VECTOR_SHARED_VQ_AND_CONFIG ; + +if (nvectors ==1 ) { + vf->msix_vector_status =MSIX_VECTOR_DEV_SHARED ; + ret =ifcvf_request_dev_shared_irq (adapter); + +return ret; } + ret =ifcvf_request_vq_irq (adapter); +if (ret) +return ret; + + ret =ifcvf_request_config_irq (adapter); + +if (ret) +return ret; +return 0 ; }@@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct vdpa_device *vdpa_dev, {struct ifcvf_hw *vf =vdpa_to_vf (vdpa_dev); -return vf->vring[qid].irq; +if (vf->vqs_shared_irq <0 ) +return vf->vring[qid].irq; +else +return -EINVAL ; } static struct vdpa_notification_area ifcvf_get_vq_notification(struct vdpa_device *vdpa_dev,
Quoted 51 lines · Jason Wang
Quoted 49 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>---
drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +6
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector) +{ + struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; + struct ifcvf_adapter *ifcvf = vf_to_adapter(hw); + + ifc_iowrite16(qid, &cfg->queue_select); + ifc_iowrite16(vector, &cfg->queue_msix_vector);
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 28
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.c +4
-0+ if (ifc_ioread16(&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { + IFCVF_ERR(ifcvf->pdev, "No msix vector for queue %u\n", qid); + return -EINVAL; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?
ifcvf driver sets NO_VECTOR when call hw_disable(). I am not sure whether I get it,
Yes we can let the caller check a vq vector, however this may cause more than three levels brackets, may looks ugly.
Quoted 81 lines
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ + return 0; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ + struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; + struct ifcvf_adapter *ifcvf = vf_to_adapter(hw); + + cfg = hw->common_cfg; + ifc_iowrite16(vector, &cfg->msix_config); + if (ifc_ioread16(&cfg->msix_config) == VIRTIO_MSI_NO_VECTOR) { + IFCVF_ERR(ifcvf->pdev, "No msix vector for device config\n"); + return -EINVAL; + }Similar question as above.
Quoted 59 lines
drivers/vdpa/ifcvf/ifcvf_base.c +4
-0+ + return 0; +} + static void __iomem *get_cap_addr(struct ifcvf_hw *hw,struct
virtio_pci_cap*cap)
{drivers/vdpa/ifcvf/ifcvf_base.c +1
-0@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL; + return 0; }@@ -321,12 +353,6 @@ static int
ifcvf_hw_enable(struct ifcvf_hw *hw)ifcvf =vf_to_adapter(hw);
cfg =hw->common_cfg;
-ifc_iowrite16(IFCVF_MSI_CONFIG_OFF, &cfg->msix_config); -
- if (ifc_ioread16(&cfg->msix_config)==VIRTIO_MSI_NO_VECTOR) { -IFCVF_ERR(ifcvf->pdev, "No msix vector for device config\n"); - return-EINVAL;
- }
for (i = 0; i <hw->nr_vring; i++) {
if (!hw->vring[i].ready)drivers/vdpa/ifcvf/ifcvf_base.c +0
-9@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifc_iowrite64_twopart(hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi); ifc_iowrite16(hw->vring[i].size, &cfg->queue_size); - ifc_iowrite16(i + IFCVF_MSI_QUEUE_OFF, &cfg->queue_msix_vector); - - if (ifc_ioread16(&cfg->queue_msix_vector) == - VIRTIO_MSI_NO_VECTOR) { - IFCVF_ERR(ifcvf->pdev, - "No msix vector for queue %u\n", i); - return -EINVAL; - } - ifcvf_set_vq_state(hw, i, hw->vring[i].last_avail_idx); ifc_iowrite16(1, &cfg->queue_enable);}
drivers/vdpa/ifcvf/ifcvf_base.h +0
-2@@ -27,8 +27,6 @@ #define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE #define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1 #define IFCVF_PCI_MAX_RESOURCE 6 #define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@ #define ifcvf_private_to_vf(adapter) \ (&((struct ifcvf_adapter *)adapter)->vf)+/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 5 lines
+/* all vqs share a vector, and config interrupt has a separate vector */
drivers/vdpa/ifcvf/ifcvf_base.h +3
-0+#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
IMHO we still need 2 and 3, because MSIX_VECTOR_SHARED_VQ_AND_CONFIG means there are at least 2 vectors, the vqs share one vector, config change has its own vector.MSIX_VECTOR_DEV_SHARED means three are only one vector, all vqs and config changes need to share this vector.
Quoted 15 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 12 lines
+
static inline u8ifc_ioread8(u8 __iomem *addr)
{
return ioread8(addr);drivers/vdpa/ifcvf/ifcvf_base.h +0
-1@@ -97,25 +102,27 @@ struct ifcvf_hw { u8 __iomem *isr; /* Live migration */ u8 __iomem *lm_cfg; - u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?
for cacheline alignment.
Quoted 41 lines
Quoted 41 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; + u8 msix_vector_status; + /* virtio-net or virtio-blk device config size */ + u32 config_size; /* Notificaiton bar address */ void __iomem *notify_base; phys_addr_t notify_base_pa; u32 notify_off_multiplier; + u32 dev_type; u64 req_features; u64 hw_features; - u32 dev_type; struct virtio_pci_common_cfg __iomem *common_cfg; void __iomem *dev_cfg; struct vring_info vring[IFCVF_MAX_QUEUES]; void __iomem * const *base; char config_msix_name[256]; struct vdpa_callback config_cb; - unsigned int config_irq; - /* virtio-net or virtio-blk device config size */ - u32 config_size; + int config_irq; + int vqs_shared_irq; + u16 nr_vring; }; struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num); struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw); int ifcvf_probed_virtio_net(struct ifcvf_hw *hw); u32 ifcvf_get_config_size(struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */
drivers/vdpa/ifcvf/ifcvf_main.c +0
-1--- a/drivers/vdpa/ifcvf/ifcvf_main.c
Quoted 8 lines
Quoted 5 lines
+++
b/drivers/vdpa/ifcvf/ifcvf_main.cdrivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -17,6 +17,7 @@ #define DRIVER_AUTHOR "Intel Corporation" #define IFCVF_DRIVER_NAME "ifcvf"+/* handles config interrupt */
This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
OK, do you mean the comments? I can remove these comments.
Quoted 49 lines
Quoted 10 lines
static
irqreturn_tifcvf_config_changed(int irq, void *arg){
structifcvf_hw*vf = arg;drivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg) return IRQ_HANDLED; }+/* handles vqs interrupt */
So did this.
Quoted 20 lines
static
irqreturn_tifcvf_intr_handler(int irq, void *arg){
structvring_info*vring = arg;drivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg) return IRQ_HANDLED; }+/* handls vqs shared interrupt */
drivers/vdpa/ifcvf/ifcvf_main.c +12
-0+static irqreturn_t ifcvf_vq_shared_intr_handler (int irq,void *arg) +{ + struct ifcvf_hw *vf = arg; + struct vring_info *vring; + int i; + + for (i = 0; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; + if (vring->cb.callback) + vf->vring->cb.callback (vring->cb.private); + } +drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 64
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+ return IRQ_HANDLED; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg) +{ + struct ifcvf_hw *vf = arg; + u8 isr; + + isr = ifc_ioread8(vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.
Quoted 1 line
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.
as we discussed in another thread(spec inconsistency about ISR), ISR may only works for INTx for now, but VFs don't have INTx, and a VF may not share its vectors with other devices, so I guess it can work and may be our best try for now.
Quoted 97 lines
Quoted 97 lines
+ if (isr &
VIRTIO_PCI_ISR_CONFIG)
+ifcvf_config_changed(irq, arg);drivers/vdpa/ifcvf/ifcvf_main.c +4
-0+ + return ifcvf_vq_shared_intr_handler(irq, arg); +} +static void
ifcvf_free_irq_vectors(void *data)
{
pci_free_irq_vectors(data);
}
-static voidifcvf_free_irq(struct ifcvf_adapter *adapter, int queues)+static voidifcvf_free_vq_irq(struct ifcvf_adapter *adapter, int queues)
{
structpci_dev*pdev =adapter->pdev;
structifcvf_hw*vf =&adapter->vf;
int i;
+ if (vf->msix_vector_status==MSIX_VECTOR_PER_VQ_AND_CONFIG) { + for (i = 0; i < queues; i++) {
+devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq =-EINVAL;
+ }
+ } else {
+devm_free_irq(&pdev->dev, vf->vqs_shared_irq, vf); +vf->vqs_shared_irq=-EINVAL;
+ }
+}
- for (i = 0; i < queues; i++) {
-devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq =-EINVAL;drivers/vdpa/ifcvf/ifcvf_main.c +8
-0+static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + + /* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status !=
MSIX_VECTOR_DEV_SHARED
+ */
+ if (vf->msix_vector_status!=MSIX_VECTOR_DEV_SHARED) { +devm_free_irq(&pdev->dev, vf->config_irq, vf); +vf->config_irq=-EINVAL;
}drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ + struct pci_dev *pdev = adapter->pdev;-
devm_free_irq(&pdev->dev, vf->config_irq, vf);
+ifcvf_free_vq_irq(adapter, queues);
+ifcvf_free_config_irq(adapter);
ifcvf_free_irq_vectors(pdev);
}
@@ -86,58 +142,172 @@ static intifcvf_alloc_vectors(struct ifcvf_adapter *adapter)return ret;
}
-static intifcvf_request_irq(struct ifcvf_adapter *adapter)
+static intifcvf_request_per_vq_irq(struct ifcvf_adapter *adapter)
{
structpci_dev*pdev =adapter->pdev;
structifcvf_hw*vf =&adapter->vf;
- int vector, nvectors, i, ret, irq;
- u16max_intr;
+ int i, vector, ret, irq;
- nvectors =ifcvf_alloc_vectors(adapter);
- if (!(nvectors > 0))
- return nvectors;
+ for (i = 0; i <vf->nr_vring; i++) {
+snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n", pci_name(pdev), i);
+ vector = i;
+ irq =pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ifcvf_intr_handler, 0,
+ vf->vring[i].msix_name,
+ &vf->vring[i]);
+ if (ret) {
+IFCVF_ERR(pdev, "Failed to request irq for vq %d\n", i);
+ifcvf_free_vq_irq(adapter, i);
+ } else {
+ vf->vring[i].irq = irq;
+ifcvf_set_vq_vector(vf, i, vector);
+ }
+ }
-max_intr=vf->nr_vring+ 1;
+vf->vqs_shared_irq=-EINVAL;drivers/vdpa/ifcvf/ifcvf_main.c +8
-0+ + return 0; +} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf;
Quoted 8 lines
Quoted 5 lines
+ int i, vector, ret, irq;
+
+ vector = 0;
+ /* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */I think we can remove this comment since the code is straightforward.
sure
Quoted 120 lines
Quoted 120 lines
+
snprintf(vf->vring[0].msix_name, 256, "ifcvf[%s]-vqs-shared-irq\n", pci_name(pdev));
+ irq =pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ifcvf_vq_shared_intr_handler, 0,
+ vf->vring[0].msix_name, vf);
+ if (ret) {
+IFCVF_ERR(pdev, "Failed to request shared irq for vf\n");drivers/vdpa/ifcvf/ifcvf_main.c +22
-0+ + return ret; + } + + vf->vqs_shared_irq = irq; + for (i = 0; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL; + ifcvf_set_vq_vector(vf, i, vector); + } + + return 0; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + int i, vector, ret, irq; + + vector = 0; + /* reuse msix_name[256] space of vring0 to store shared deviceinterrupt name */
+snprintf(vf->vring[0].msix_name, 256, "ifcvf[%s]-dev-shared-irq\n", pci_name(pdev));
+ irq =pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ifcvf_dev_shared_intr_handler, 0,
+ vf->vring[0].msix_name, vf);
+ if (ret) {
+IFCVF_ERR(pdev, "Failed to request shared irq for vf\n"); - ret = pci_alloc_irq_vectors(pdev,max_intr,
-max_intr,PCI_IRQ_MSIX);
- if (ret < 0) {
-IFCVF_ERR(pdev, "Failed to alloc IRQ vectors\n"); return ret;
}
+vf->vqs_shared_irq= irq;
+ for (i = 0; i <vf->nr_vring; i++) {
+ vf->vring[i].irq =-EINVAL;
+ifcvf_set_vq_vector(vf, i, vector);
+ }drivers/vdpa/ifcvf/ifcvf_main.c +32
-0+ + vf->config_irq = irq; + ifcvf_set_config_vector(vf, vector); + + return 0; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ + struct ifcvf_hw *vf = &adapter->vf; + int ret; + + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) + ret = ifcvf_request_per_vq_irq(adapter); + else + ret = ifcvf_request_shared_vq_irq(adapter); + + return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + int config_vector, ret; + + if (vf->msix_vector_status == MSIX_VECTOR_DEV_SHARED) + return 0; + + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) + /* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vectorfor config interrupt */
+config_vector=vf->nr_vring;drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+ + if (vf->msix_vector_status == MSIX_VECTOR_SHARED_VQ_AND_CONFIG) + /* vector 0 for vqs and 1 for config interrupt */ + config_vector = 1; +
snprintf(vf->config_msix_name, 256, "ifcvf[%s]-config\n", pci_name(pdev));
- vector = 0;
-vf->config_irq=pci_irq_vector(pdev, vector);
+vf->config_irq=pci_irq_vector(pdev, config_vector); ret =devm_request_irq(&pdev->dev, vf->config_irq, ifcvf_config_changed, 0, vf->config_msix_name, vf);
if (ret) {
IFCVF_ERR(pdev, "Failed to request config irq\n"); +ifcvf_free_vq_irq(adapter, vf->nr_vring); return ret;
}
- for (i = 0; i <vf->nr_vring; i++) {
-snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n", - pci_name(pdev), i);
- vector = i +IFCVF_MSI_QUEUE_OFF;
- irq =pci_irq_vector(pdev, vector);
- ret = devm_request_irq(&pdev->dev, irq,
-ifcvf_intr_handler, 0,
- vf->vring[i].msix_name,
- &vf->vring[i]);
- if (ret) {
- IFCVF_ERR(pdev,
- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq(adapter, i);
+ifcvf_set_config_vector(vf, config_vector);
- return ret;
- }
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 5 lines
+ return 0;
drivers/vdpa/ifcvf/ifcvf_main.c +4
-0+} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Do you mean if we don't get enough vectors, just use only one vector for the vqs and config changes? I guess this only works if ISR work for MSIX as we expects, or we may waste some time in the device config space.
Thanks,
Zhu Lingshan
Quoted 40 lines
Thanks
Quoted 36 lines
+ struct
ifcvf_hw*vf =&adapter->vf;
+ int nvectors, ret,max_intr;
- vf->vring[i].irq = irq;
+ nvectors =ifcvf_alloc_vectors(adapter);
+ if (!(nvectors > 0))
+ return nvectors;drivers/vdpa/ifcvf/ifcvf_main.c +11
-0+ + vf->msix_vector_status = MSIX_VECTOR_PER_VQ_AND_CONFIG; + max_intr = vf->nr_vring + 1; + if (nvectors < max_intr) + vf->msix_vector_status = MSIX_VECTOR_SHARED_VQ_AND_CONFIG; + + if (nvectors == 1) { + vf->msix_vector_status = MSIX_VECTOR_DEV_SHARED; + ret = ifcvf_request_dev_shared_irq(adapter); + + return ret;}
+ ret =ifcvf_request_vq_irq(adapter);
+ if (ret)
+ return ret;drivers/vdpa/ifcvf/ifcvf_main.c +6
-0+ + ret = ifcvf_request_config_irq(adapter); + + if (ret) + return ret; +return 0;
}
@@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(structvdpa_device*vdpa_dev, {
structifcvf_hw*vf =vdpa_to_vf(vdpa_dev);
- return vf->vring[qid].irq;
+ if (vf->vqs_shared_irq< 0)
+ return vf->vring[qid].irq;
+ else
Quoted 8 lines
Quoted 3 lines
+ return
-EINVAL;
}
static structvdpa_notification_areaifcvf_get_vq_notification(structvdpa_device*vdpa_dev,_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 179 lines · Zhu Lingshan
Quoted 53 lines · Jason Wang
Quoted 51 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>---
drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +7
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector) +{ + struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; + struct ifcvf_adapter *ifcvf = vf_to_adapter(hw); + + ifc_iowrite16(qid, &cfg->queue_select); + ifc_iowrite16(vector, &cfg->queue_msix_vector); + if (ifc_ioread16(&cfg->queue_msix_vector) ==Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 28
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_base.c +3
-0VIRTIO_MSI_NO_VECTOR) { + IFCVF_ERR(ifcvf->pdev, "No msix vector for queue %u\n", qid); + return -EINVAL; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?ifcvf driver sets
NO_VECTORwhen callhw_disable(). I am not sure whether I get it,
Yes we can let the caller check a vq vector, however this may cause more than three levels brackets, may looks ugly.Quoted 83 lines
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ + return 0; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ + struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; + struct ifcvf_adapter *ifcvf = vf_to_adapter(hw); + + cfg = hw->common_cfg; + ifc_iowrite16(vector, &cfg->msix_config); + if (ifc_ioread16(&cfg->msix_config) == VIRTIO_MSI_NO_VECTOR) { + IFCVF_ERR(ifcvf->pdev, "No msix vector for device config\n"); + return -EINVAL; + }Similar question as above.
Quoted 61 lines
drivers/vdpa/ifcvf/ifcvf_base.c +4
-0+ + return 0; +} + static void __iomem *get_cap_addr(struct ifcvf_hw *hw,struct
virtio_pci_cap*cap)
{drivers/vdpa/ifcvf/ifcvf_base.c +1
-0@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL; + return 0; }@@ -321,12 +353,6 @@ static int
ifcvf_hw_enable(struct ifcvf_hw *hw)ifcvf =vf_to_adapter(hw);
cfg =hw->common_cfg;
-ifc_iowrite16(IFCVF_MSI_CONFIG_OFF, &cfg->msix_config); -
- if (ifc_ioread16(&cfg->msix_config)==VIRTIO_MSI_NO_VECTOR) { -IFCVF_ERR(ifcvf->pdev, "No msix vector for device config\n"); - return-EINVAL;
- }
for (i = 0; i <hw->nr_vring; i++) {
if (!hw->vring[i].ready)drivers/vdpa/ifcvf/ifcvf_base.c +0
-9@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifc_iowrite64_twopart(hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi); ifc_iowrite16(hw->vring[i].size, &cfg->queue_size); - ifc_iowrite16(i + IFCVF_MSI_QUEUE_OFF, &cfg->queue_msix_vector); - - if (ifc_ioread16(&cfg->queue_msix_vector) == - VIRTIO_MSI_NO_VECTOR) { - IFCVF_ERR(ifcvf->pdev, - "No msix vector for queue %u\n", i); - return -EINVAL; - } - ifcvf_set_vq_state(hw, i, hw->vring[i].last_avail_idx); ifc_iowrite16(1, &cfg->queue_enable);}
drivers/vdpa/ifcvf/ifcvf_base.h +0
-2@@ -27,8 +27,6 @@ #define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE #define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1 #define IFCVF_PCI_MAX_RESOURCE 6 #define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@ #define ifcvf_private_to_vf(adapter) \ (&((struct ifcvf_adapter *)adapter)->vf)+/* all vqs and config interrupt has its own vector */
drivers/vdpa/ifcvf/ifcvf_base.h +2
-0+#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 +/* all vqs share a vector, and config interrupt has a separate Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 4 lines
vector */
drivers/vdpa/ifcvf/ifcvf_base.h +3
-0+#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
IMHO we still need 2 and 3, because
MSIX_VECTOR_SHARED_VQ_AND_CONFIGmeans there are at least 2 vectors,
the vqs share one vector, config change has its own vector.MSIX_VECTOR_DEV_SHAREDmeans three are only one vector, all vqs and config changes need to share this vector.Quoted 15 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 12 lines
+
static inline u8ifc_ioread8(u8 __iomem *addr)
{
return ioread8(addr);drivers/vdpa/ifcvf/ifcvf_base.h +0
-1@@ -97,25 +102,27 @@ struct ifcvf_hw { u8 __iomem *isr; /* Live migration */ u8 __iomem *lm_cfg; - u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?
Quoted 1 line
for cacheline alignment.
maybe a separate patch then.
Quoted 402 lines
Quoted 43 lines
Quoted 43 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; + u8 msix_vector_status; + /* virtio-net or virtio-blk device config size */ + u32 config_size; /* Notificaiton bar address */ void __iomem *notify_base; phys_addr_t notify_base_pa; u32 notify_off_multiplier; + u32 dev_type; u64 req_features; u64 hw_features; - u32 dev_type; struct virtio_pci_common_cfg __iomem *common_cfg; void __iomem *dev_cfg; struct vring_info vring[IFCVF_MAX_QUEUES]; void __iomem * const *base; char config_msix_name[256]; struct vdpa_callback config_cb; - unsigned int config_irq; - /* virtio-net or virtio-blk device config size */ - u32 config_size; + int config_irq; + int vqs_shared_irq; + u16 nr_vring; }; struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num); struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw); int ifcvf_probed_virtio_net(struct ifcvf_hw *hw); u32 ifcvf_get_config_size(struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */
drivers/vdpa/ifcvf/ifcvf_main.c +0
-0Quoted 8 lines
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -17,6 +17,7 @@ #define DRIVER_AUTHOR "Intel Corporation" #define IFCVF_DRIVER_NAME "ifcvf"+/* handles config interrupt */
This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
OK, do you mean the comments? I can remove these comments.
Quoted 50 lines
Quoted 10 lines
static
irqreturn_tifcvf_config_changed(int irq, void *arg){
structifcvf_hw*vf = arg;drivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg) return IRQ_HANDLED; }+/* handles vqs interrupt */
So did this.
Quoted 20 lines
static
irqreturn_tifcvf_intr_handler(int irq, void *arg){
structvring_info*vring = arg;drivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg) return IRQ_HANDLED; }+/* handls vqs shared interrupt */
drivers/vdpa/ifcvf/ifcvf_main.c +12
-0+static irqreturn_t ifcvf_vq_shared_intr_handler (int irq,void *arg) +{ + struct ifcvf_hw *vf = arg; + struct vring_info *vring; + int i; + + for (i = 0; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; + if (vring->cb.callback) + vf->vring->cb.callback (vring->cb.private); + } +drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 64
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+ return IRQ_HANDLED; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg) +{ + struct ifcvf_hw *vf = arg; + u8 isr; + + isr = ifc_ioread8(vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.as we discussed in another thread(spec inconsistency about ISR), ISR may only works for INTx for now,
but VFs don't have INTx, and a VF may not share its vectors with other devices, so I guess it can work
and may be our best try for now.Quoted 98 lines
Quoted 98 lines
+ if (isr &
VIRTIO_PCI_ISR_CONFIG)
+ifcvf_config_changed(irq, arg);drivers/vdpa/ifcvf/ifcvf_main.c +4
-0+ + return ifcvf_vq_shared_intr_handler(irq, arg); +} +static void
ifcvf_free_irq_vectors(void *data)
{
pci_free_irq_vectors(data);
}
-static voidifcvf_free_irq(struct ifcvf_adapter *adapter, int queues)+static voidifcvf_free_vq_irq(struct ifcvf_adapter *adapter, int queues)
{
structpci_dev*pdev =adapter->pdev;
structifcvf_hw*vf =&adapter->vf;
int i;
+ if (vf->msix_vector_status==MSIX_VECTOR_PER_VQ_AND_CONFIG) { + for (i = 0; i < queues; i++) {
+devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq =-EINVAL;
+ }
+ } else {
+devm_free_irq(&pdev->dev, vf->vqs_shared_irq, vf); +vf->vqs_shared_irq=-EINVAL;
+ }
+}
- for (i = 0; i < queues; i++) {
-devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq =-EINVAL;drivers/vdpa/ifcvf/ifcvf_main.c +8
-0+static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + + /* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status !=
MSIX_VECTOR_DEV_SHARED
+ */
+ if (vf->msix_vector_status!=MSIX_VECTOR_DEV_SHARED) { +devm_free_irq(&pdev->dev, vf->config_irq, vf); +vf->config_irq=-EINVAL;
}drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ + struct pci_dev *pdev = adapter->pdev;-
devm_free_irq(&pdev->dev, vf->config_irq, vf);
+ifcvf_free_vq_irq(adapter, queues);
+ifcvf_free_config_irq(adapter);ifcvf_free_irq_vectors(pdev);
}
@@ -86,58 +142,172 @@ static intifcvf_alloc_vectors(struct ifcvf_adapter *adapter)
return ret;
}
-static intifcvf_request_irq(struct ifcvf_adapter *adapter)+static intifcvf_request_per_vq_irq(struct ifcvf_adapter *adapter){
structpci_dev*pdev =adapter->pdev;
structifcvf_hw*vf =&adapter->vf;
- int vector, nvectors, i, ret, irq;
- u16max_intr;
+ int i, vector, ret, irq;
- nvectors =ifcvf_alloc_vectors(adapter);
- if (!(nvectors > 0))
- return nvectors;
+ for (i = 0; i <vf->nr_vring; i++) {
+snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n", pci_name(pdev), i);
+ vector = i;
+ irq =pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ifcvf_intr_handler, 0,
+ vf->vring[i].msix_name,
+ &vf->vring[i]);
+ if (ret) {
+IFCVF_ERR(pdev, "Failed to request irq for vq %d\n", i); +ifcvf_free_vq_irq(adapter, i);
+ } else {
+ vf->vring[i].irq = irq;
+ifcvf_set_vq_vector(vf, i, vector);
+ }
+ }
-max_intr=vf->nr_vring+ 1;
+vf->vqs_shared_irq=-EINVAL;drivers/vdpa/ifcvf/ifcvf_main.c +8
-0+ + return 0; +} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf;Quoted 8 lines
Quoted 5 lines
+ int i, vector, ret, irq;
+
+ vector = 0;
+ /* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */I think we can remove this comment since the code is straightforward.
sure
Quoted 121 lines
Quoted 121 lines
+
snprintf(vf->vring[0].msix_name, 256, "ifcvf[%s]-vqs-shared-irq\n", pci_name(pdev));
+ irq =pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ifcvf_vq_shared_intr_handler, 0,
+ vf->vring[0].msix_name, vf);
+ if (ret) {
+IFCVF_ERR(pdev, "Failed to request shared irq for vf\n");drivers/vdpa/ifcvf/ifcvf_main.c +22
-0+ + return ret; + } + + vf->vqs_shared_irq = irq; + for (i = 0; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL; + ifcvf_set_vq_vector(vf, i, vector); + } + + return 0; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + int i, vector, ret, irq; + + vector = 0; + /* reuse msix_name[256] space of vring0 to store shared deviceinterrupt name */
+snprintf(vf->vring[0].msix_name, 256, "ifcvf[%s]-dev-shared-irq\n", pci_name(pdev));
+ irq =pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ifcvf_dev_shared_intr_handler, 0,
+ vf->vring[0].msix_name, vf);
+ if (ret) {
+IFCVF_ERR(pdev, "Failed to request shared irq for vf\n"); - ret = pci_alloc_irq_vectors(pdev,max_intr,
-max_intr,PCI_IRQ_MSIX);
- if (ret < 0) {
-IFCVF_ERR(pdev, "Failed to alloc IRQ vectors\n"); return ret;
}
+vf->vqs_shared_irq= irq;
+ for (i = 0; i <vf->nr_vring; i++) {
+ vf->vring[i].irq =-EINVAL;
+ifcvf_set_vq_vector(vf, i, vector);
+ }drivers/vdpa/ifcvf/ifcvf_main.c +32
-0+ + vf->config_irq = irq; + ifcvf_set_config_vector(vf, vector); + + return 0; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ + struct ifcvf_hw *vf = &adapter->vf; + int ret; + + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) + ret = ifcvf_request_per_vq_irq(adapter); + else + ret = ifcvf_request_shared_vq_irq(adapter); + + return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + int config_vector, ret; + + if (vf->msix_vector_status == MSIX_VECTOR_DEV_SHARED) + return 0; + + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) + /* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vectorfor config interrupt */
+config_vector=vf->nr_vring;drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+ + if (vf->msix_vector_status == MSIX_VECTOR_SHARED_VQ_AND_CONFIG) + /* vector 0 for vqs and 1 for config interrupt */ + config_vector = 1; +
snprintf(vf->config_msix_name, 256, "ifcvf[%s]-config\n", pci_name(pdev));
- vector = 0;
-vf->config_irq=pci_irq_vector(pdev, vector);
+vf->config_irq=pci_irq_vector(pdev, config_vector); ret =devm_request_irq(&pdev->dev, vf->config_irq, ifcvf_config_changed, 0, vf->config_msix_name, vf);
if (ret) {
IFCVF_ERR(pdev, "Failed to request config irq\n"); +ifcvf_free_vq_irq(adapter, vf->nr_vring); return ret;
}
- for (i = 0; i <vf->nr_vring; i++) {
-snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n", - pci_name(pdev), i);
- vector = i +IFCVF_MSI_QUEUE_OFF;
- irq =pci_irq_vector(pdev, vector);
- ret = devm_request_irq(&pdev->dev, irq,
-ifcvf_intr_handler, 0,
- vf->vring[i].msix_name,
- &vf->vring[i]);
- if (ret) {
- IFCVF_ERR(pdev,
- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq(adapter, i);
+ifcvf_set_config_vector(vf, config_vector);
- return ret;
- }
+ return 0;Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_main.c +4
-0+} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Do you mean if we don't get enough vectors, just use only one vector for the vqs and config changes? I guess this
only works if ISR work for MSIX as we expects, or we may waste some time in the device config space.Thanks,
Zhu LingshanQuoted 50 lines
Thanks
Quoted 33 lines
+ struct
ifcvf_hw*vf =&adapter->vf;
+ int nvectors, ret,max_intr;
- vf->vring[i].irq = irq;
+ nvectors =ifcvf_alloc_vectors(adapter);
+ if (!(nvectors > 0))
+ return nvectors;drivers/vdpa/ifcvf/ifcvf_main.c +11
-0+ + vf->msix_vector_status = MSIX_VECTOR_PER_VQ_AND_CONFIG; + max_intr = vf->nr_vring + 1; + if (nvectors < max_intr) + vf->msix_vector_status = MSIX_VECTOR_SHARED_VQ_AND_CONFIG; + + if (nvectors == 1) { + vf->msix_vector_status = MSIX_VECTOR_DEV_SHARED; + ret = ifcvf_request_dev_shared_irq(adapter); + + return ret;}
+ ret =ifcvf_request_vq_irq(adapter);
+ if (ret)
+ return ret;drivers/vdpa/ifcvf/ifcvf_main.c +6
-0+ + ret = ifcvf_request_config_irq(adapter); + + if (ret) + return ret; +return 0;
}
@@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(structvdpa_device*vdpa_dev,
{
structifcvf_hw*vf =vdpa_to_vf(vdpa_dev);Quoted 8 lines
- return vf->vring[qid].irq;
+ if (vf->vqs_shared_irq< 0)
+ return vf->vring[qid].irq;
+ else
+ return-EINVAL;
}
static structvdpa_notification_areaifcvf_get_vq_notification(structvdpa_device*vdpa_dev,_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 172 lines · Michael S. Tsirkin
Quoted 171 lines · Zhu Lingshan
Quoted 51 lines · Jason Wang
Quoted 50 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +6
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector) +{ + struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; + struct ifcvf_adapter *ifcvf = vf_to_adapter(hw); + + ifc_iowrite16(qid, &cfg->queue_select); + ifc_iowrite16(vector, &cfg->queue_msix_vector);Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 28
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.c +4
-0+ if (ifc_ioread16(&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { + IFCVF_ERR(ifcvf->pdev, "No msix vector for queue %u\n", qid); + return -EINVAL; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?ifcvf driver sets
NO_VECTORwhen callhw_disable(). I am not sure whether I get it,
Yes we can let the caller check a vq vector, however this may cause more than three levels brackets, may looks ugly.Quoted 80 lines
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ + return 0; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ + struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; + struct ifcvf_adapter *ifcvf = vf_to_adapter(hw); + + cfg = hw->common_cfg; + ifc_iowrite16(vector, &cfg->msix_config); + if (ifc_ioread16(&cfg->msix_config) == VIRTIO_MSI_NO_VECTOR) { + IFCVF_ERR(ifcvf->pdev, "No msix vector for device config\n"); + return -EINVAL; + }Similar question as above.
Quoted 60 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-15+ + return 0; +} + static void __iomem *get_cap_addr(struct ifcvf_hw *hw, struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL; + return 0; } @@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf = vf_to_adapter(hw); cfg = hw->common_cfg; - ifc_iowrite16(IFCVF_MSI_CONFIG_OFF, &cfg->msix_config); - - if (ifc_ioread16(&cfg->msix_config) == VIRTIO_MSI_NO_VECTOR) { - IFCVF_ERR(ifcvf->pdev, "No msix vector for device config\n"); - return -EINVAL; - } for (i = 0; i < hw->nr_vring; i++) { if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifc_iowrite64_twopart(hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi); ifc_iowrite16(hw->vring[i].size, &cfg->queue_size); - ifc_iowrite16(i + IFCVF_MSI_QUEUE_OFF, &cfg->queue_msix_vector); - - if (ifc_ioread16(&cfg->queue_msix_vector) == - VIRTIO_MSI_NO_VECTOR) { - IFCVF_ERR(ifcvf->pdev, - "No msix vector for queue %u\n", i); - return -EINVAL; - } - ifcvf_set_vq_state(hw, i, hw->vring[i].last_avail_idx); ifc_iowrite16(1, &cfg->queue_enable);}
drivers/vdpa/ifcvf/ifcvf_base.h +1
-2@@ -27,8 +27,6 @@ #define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE #define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1 #define IFCVF_PCI_MAX_RESOURCE 6 #define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@ #define ifcvf_private_to_vf(adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-0+/* all vqs share a vector, and config interrupt has a separate vector */
drivers/vdpa/ifcvf/ifcvf_base.h +3
-0+#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
IMHO we still need 2 and 3, because
MSIX_VECTOR_SHARED_VQ_AND_CONFIGmeans there are at least 2 vectors,
the vqs share one vector, config change has its own vector.MSIX_VECTOR_DEV_SHAREDmeans three are only one vector, all vqs and config changes need to share this vector.Quoted 13 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 11 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+ static inline u8 ifc_ioread8(u8 __iomem *addr) { return ioread8(addr);@@ -97,25 +102,27 @@ struct ifcvf_hw { u8 __iomem *isr; /* Live migration */ u8 __iomem *lm_cfg; - u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?
Quoted 2 lines
Quoted 1 line
for cacheline alignment.
maybe a separate patch then.
Sure
Thanks!
Quoted 392 lines
Quoted 392 lines
Quoted 42 lines
Quoted 42 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; + u8 msix_vector_status; + /* virtio-net or virtio-blk device config size */ + u32 config_size; /* Notificaiton bar address */ void __iomem *notify_base; phys_addr_t notify_base_pa; u32 notify_off_multiplier; + u32 dev_type; u64 req_features; u64 hw_features; - u32 dev_type; struct virtio_pci_common_cfg __iomem *common_cfg; void __iomem *dev_cfg; struct vring_info vring[IFCVF_MAX_QUEUES]; void __iomem * const *base; char config_msix_name[256]; struct vdpa_callback config_cb; - unsigned int config_irq; - /* virtio-net or virtio-blk device config size */ - u32 config_size; + int config_irq; + int vqs_shared_irq; + u16 nr_vring; }; struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num); struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw); int ifcvf_probed_virtio_net(struct ifcvf_hw *hw); u32 ifcvf_get_config_size(struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */
drivers/vdpa/ifcvf/ifcvf_main.c +0
-1--- a/drivers/vdpa/ifcvf/ifcvf_main.cQuoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c line 19
Quoted 5 lines
+++
b/drivers/vdpa/ifcvf/ifcvf_main.cdrivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -17,6 +17,7 @@ #define DRIVER_AUTHOR "Intel Corporation" #define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
OK, do you mean the comments? I can remove these comments.
Quoted 47 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, · line 31
Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_main.c +0
-0static irqreturn_t ifcvf_config_changed(int irq, void *arg) { struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg) return IRQ_HANDLED; } +/* handles vqs interrupt */So did this.
Quoted 20 lines
drivers/vdpa/ifcvf/ifcvf_main.c +12
-0static irqreturn_t ifcvf_intr_handler(int irq, void *arg) { struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg) return IRQ_HANDLED; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler(int irq, void *arg) +{ + struct ifcvf_hw *vf = arg; + struct vring_info *vring; + int i; + + for (i = 0; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; + if (vring->cb.callback) + vf->vring->cb.callback (vring->cb.private); + } +drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, · line 64
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+ return IRQ_HANDLED; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg) +{ + struct ifcvf_hw *vf = arg; + u8 isr; + + isr = ifc_ioread8(vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.as we discussed in another thread(spec inconsistency about ISR), ISR may only works for INTx for now,
but VFs don't have INTx, and a VF may not share its vectors with other devices, so I guess it can work
and may be our best try for now.Quoted 96 lines
Quoted 96 lines
drivers/vdpa/ifcvf/ifcvf_main.c +24
-2+ if (isr & VIRTIO_PCI_ISR_CONFIG) + ifcvf_config_changed(irq, arg); + + return ifcvf_vq_shared_intr_handler(irq, arg); +} + static void ifcvf_free_irq_vectors(void *data) { pci_free_irq_vectors(data); } -static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) +static void ifcvf_free_vq_irq(struct ifcvf_adapter *adapter, int queues) { struct pci_dev *pdev = adapter->pdev; struct ifcvf_hw *vf = &adapter->vf; int i; + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) { + for (i = 0; i < queues; i++) { + devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL; + } + } else { + devm_free_irq(&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL; + } +} - for (i = 0; i < queues; i++) { - devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + + /* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status !=
MSIX_VECTOR_DEV_SHARED
+ */
+ if (vf->msix_vector_status!=MSIX_VECTOR_DEV_SHARED) { +devm_free_irq(&pdev->dev, vf->config_irq, vf); +vf->config_irq=-EINVAL;
}drivers/vdpa/ifcvf/ifcvf_main.c +7
-0+} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ + struct pci_dev *pdev = adapter->pdev; - devm_free_irq(&pdev->dev, vf->config_irq, vf); + ifcvf_free_vq_irq(adapter, queues); + ifcvf_free_config_irq(adapter); ifcvf_free_irq_vectors(pdev); } @@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct
ifcvf_adapter*adapter)
return ret;
}
-static intifcvf_request_irq(struct ifcvf_adapter *adapter)
+static intifcvf_request_per_vq_irq(struct ifcvf_adapter *adapter)
{
structpci_dev*pdev =adapter->pdev;
structifcvf_hw*vf =&adapter->vf;
- int vector, nvectors, i, ret, irq;
- u16max_intr;
+ int i, vector, ret, irq;
- nvectors =ifcvf_alloc_vectors(adapter);
- if (!(nvectors > 0))
- return nvectors;
+ for (i = 0; i <vf->nr_vring; i++) {
+snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n", pci_name(pdev), i);
+ vector = i;
+ irq =pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ifcvf_intr_handler, 0,
+ vf->vring[i].msix_name,
+ &vf->vring[i]);
+ if (ret) {
+IFCVF_ERR(pdev, "Failed to request irq for vq %d\n", i); +ifcvf_free_vq_irq(adapter, i);
+ } else {
+ vf->vring[i].irq = irq;
+ifcvf_set_vq_vector(vf, i, vector);
+ }
+ }
-max_intr=vf->nr_vring+ 1;
+vf->vqs_shared_irq=-EINVAL;drivers/vdpa/ifcvf/ifcvf_main.c +7
-0+ + return 0; +} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev;Quoted 8 lines
Quoted 6 lines
+ struct
ifcvf_hw*vf =&adapter->vf;
+ int i, vector, ret, irq;
+
+ vector = 0;
+ /* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */I think we can remove this comment since the code is straightforward.
sure
Quoted 119 lines
Quoted 119 lines
+
snprintf(vf->vring[0].msix_name, 256, "ifcvf[%s]-vqs-shared-irq\n", pci_name(pdev));
+ irq =pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ifcvf_vq_shared_intr_handler, 0,
+ vf->vring[0].msix_name, vf);
+ if (ret) {
+IFCVF_ERR(pdev, "Failed to request shared irq for vf\n");drivers/vdpa/ifcvf/ifcvf_main.c +22
-0+ + return ret; + } + + vf->vqs_shared_irq = irq; + for (i = 0; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL; + ifcvf_set_vq_vector(vf, i, vector); + } + + return 0; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + int i, vector, ret, irq; + + vector = 0; + /* reuse msix_name[256] space of vring0 to store shared deviceinterrupt name */
+snprintf(vf->vring[0].msix_name, 256, "ifcvf[%s]-dev-shared-irq\n", pci_name(pdev));
+ irq =pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ifcvf_dev_shared_intr_handler, 0,
+ vf->vring[0].msix_name, vf);
+ if (ret) {
+IFCVF_ERR(pdev, "Failed to request shared irq for vf\n");
- ret = pci_alloc_irq_vectors(pdev,max_intr,
-max_intr,PCI_IRQ_MSIX);
- if (ret < 0) {
-IFCVF_ERR(pdev, "Failed to alloc IRQ vectors\n");
return ret;
}
+vf->vqs_shared_irq= irq;
+ for (i = 0; i <vf->nr_vring; i++) {
+ vf->vring[i].irq =-EINVAL;
+ifcvf_set_vq_vector(vf, i, vector);
+ }drivers/vdpa/ifcvf/ifcvf_main.c +32
-0+ + vf->config_irq = irq; + ifcvf_set_config_vector(vf, vector); + + return 0; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ + struct ifcvf_hw *vf = &adapter->vf; + int ret; + + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) + ret = ifcvf_request_per_vq_irq(adapter); + else + ret = ifcvf_request_shared_vq_irq(adapter); + + return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; + int config_vector, ret; + + if (vf->msix_vector_status == MSIX_VECTOR_DEV_SHARED) + return 0; + + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) + /* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vectorfor config interrupt */
+config_vector=vf->nr_vring;drivers/vdpa/ifcvf/ifcvf_main.c +8
-15+ + if (vf->msix_vector_status == MSIX_VECTOR_SHARED_VQ_AND_CONFIG) + /* vector 0 for vqs and 1 for config interrupt */ + config_vector = 1; + snprintf(vf->config_msix_name, 256, "ifcvf[%s]-config\n", pci_name(pdev)); - vector = 0; - vf->config_irq = pci_irq_vector(pdev, vector); + vf->config_irq = pci_irq_vector(pdev, config_vector); ret = devm_request_irq(&pdev->dev, vf->config_irq, ifcvf_config_changed, 0, vf->config_msix_name, vf); if (ret) { IFCVF_ERR(pdev, "Failed to request config irq\n"); + ifcvf_free_vq_irq(adapter, vf->nr_vring); return ret; } - for (i = 0; i < vf->nr_vring; i++) { - snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n", - pci_name(pdev), i); - vector = i + IFCVF_MSI_QUEUE_OFF; - irq = pci_irq_vector(pdev, vector); - ret = devm_request_irq(&pdev->dev, irq, - ifcvf_intr_handler, 0, - vf->vring[i].msix_name, - &vf->vring[i]); - if (ret) { - IFCVF_ERR(pdev, - "Failed to request irq for vq %d\n", i); - ifcvf_free_irq(adapter, i); + ifcvf_set_config_vector(vf, config_vector); - return ret; - }Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 5 lines
+ return 0;
drivers/vdpa/ifcvf/ifcvf_main.c +4
-0+} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Do you mean if we don't get enough vectors, just use only one vector for the vqs and config changes? I guess this
only works if ISR work for MSIX as we expects, or we may waste some time in the device config space.Thanks,
Zhu LingshanQuoted 48 lines
Thanks
Quoted 33 lines
+ struct
ifcvf_hw*vf =&adapter->vf;
+ int nvectors, ret,max_intr;
- vf->vring[i].irq = irq;
+ nvectors =ifcvf_alloc_vectors(adapter);
+ if (!(nvectors > 0))
+ return nvectors;drivers/vdpa/ifcvf/ifcvf_main.c +19
-0+ + vf->msix_vector_status = MSIX_VECTOR_PER_VQ_AND_CONFIG; + max_intr = vf->nr_vring + 1; + if (nvectors < max_intr) + vf->msix_vector_status = MSIX_VECTOR_SHARED_VQ_AND_CONFIG; + + if (nvectors == 1) { + vf->msix_vector_status = MSIX_VECTOR_DEV_SHARED; + ret = ifcvf_request_dev_shared_irq(adapter); + + return ret; } + ret = ifcvf_request_vq_irq(adapter); + if (ret) + return ret; + + ret = ifcvf_request_config_irq(adapter); + + if (ret) + return ret; + return 0; } @@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct
vdpa_device*vdpa_dev,
{
structifcvf_hw*vf =vdpa_to_vf(vdpa_dev);Quoted 8 lines
- return vf->vring[qid].irq;
+ if (vf->vqs_shared_irq< 0)
+ return vf->vring[qid].irq;
+ else
+ return-EINVAL;
}
static structvdpa_notification_area
ifcvf_get_vq_notification(structvdpa_device*vdpa_dev,_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 66 lines · Lingshan
Quoted 62 lines · Michael S. Tsirkin
Quoted 61 lines · Zhu Lingshan
Quoted 59 lines · Jason Wang
Quoted 45 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +1
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector) +{drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct · line 29
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +9
-0+struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select); +ifc_iowrite16 (vector, &cfg->queue_msix_vector); +if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
ifcvf driver sets
NO_VECTORwhen callhw_disable(). I am not sure whether I get it,
I meant you invent the ifcvf_set_vq_vector() you'd better use that in hw_disable() as well.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Yes we can let the caller check a vq vector, however this may cause more than three levels brackets, may looks ugly.
I don't understand here, this is how virito_pci did:
/*
* vp_modern_queue_vector - set the MSIX vector for a specific virtqueue
* @mdev: the modern virtio-pci device
* @index: queue index
* @vector: the config vector
*
* Returns the config vector read from the device
*/
u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,
u16 index, u16 vector)
{
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
vp_iowrite16(index, &cfg->queue_select);
vp_iowrite16(vector, &cfg->queue_msix_vector);
/* Flush the write out to device */
return vp_ioread16(&cfg->queue_msix_vector);
}EXPORT_SYMBOL_GPL(vp_modern_queue_vector);
Quoted 88 lines
Quoted 88 lines
Quoted 88 lines
Quoted 88 lines
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + }Similar question as above.
Quoted 62 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-15+ +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; } @@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable);}drivers/vdpa/ifcvf/ifcvf_base.h +2
-2@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 +/* all vqs share a vector, and config interrupt has a separate vector */
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_base.h +3
-0+#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
IMHO we still need 2 and 3, because
MSIX_VECTOR_SHARED_VQ_AND_CONFIGmeans there are at least 2 vectors,
the vqs share one vector, config change has its own vector.
I want to know the value of having a dedicated vector for config?
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
MSIX_VECTOR_DEV_SHAREDmeans three are only one vector, all vqs and config changes need to share this vector.Quoted 13 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 11 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?
Quoted 56 lines
Quoted 2 lines
Quoted 1 line
for cacheline alignment.
maybe a separate patch then.
Sure
Thanks!
Quoted 51 lines
Quoted 51 lines
Quoted 42 lines
Quoted 42 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */drivers/vdpa/ifcvf/ifcvf_main.c +0
-1--- a/drivers/vdpa/ifcvf/ifcvf_main.cQuoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c line 19
Quoted 5 lines
+++
b/drivers/vdpa/ifcvf/ifcvf_main.cdrivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -17,6 +17,7 @@#define DRIVER_AUTHOR "Intel Corporation"#define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
OK, do you mean the comments? I can remove these comments.
Yes.
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, · line 31
Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_main.c +0
-0static irqreturn_t ifcvf_config_changed (int irq,void *arg) {struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg)return IRQ_HANDLED ; } +/* handles vqs interrupt */So did this.
Quoted 20 lines
drivers/vdpa/ifcvf/ifcvf_main.c +12
-0static irqreturn_t ifcvf_intr_handler (int irq,void *arg) {struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler(int irq, void *arg) +{ +struct ifcvf_hw *vf = arg; +struct vring_info *vring; +int i; + +for (i =0 ; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; +if (vring->cb.callback) + vf->vring->cb.callback (vring->cb.private); + } +drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, · line 64
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+return IRQ_HANDLED ; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +u8 isr; + + isr =ifc_ioread8 (vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.as we discussed in another thread(spec inconsistency about ISR), ISR may only works for INTx for now,
but VFs don't have INTx, and a VF may not share its vectors with other devices, so I guess it can work
and may be our best try for now.
Right, I thought you're using shared irq but actually not.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 66
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_main.c +2
-0+if (isr &VIRTIO_PCI_ISR_CONFIG ) +ifcvf_config_changed (irq, arg);
I wonder how ISR works in IFCVF, if ISR doesn't work for MSI, we need to remove the check of isr otherwise we will break config interrupt?
Quoted 229 lines
Quoted 229 lines
Quoted 229 lines
Quoted 93 lines
Quoted 93 lines
drivers/vdpa/ifcvf/ifcvf_main.c +22
-2+ +return ifcvf_vq_shared_intr_handler (irq, arg); +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data); } -static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) +static void ifcvf_free_vq_irq(struct ifcvf_adapter *adapter, int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf;int i; + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) { +for (i =0 ; i < queues; i++) { +devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL ; + } + } else { +devm_free_irq (&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL ; + } +} - for (i = 0; i < queues; i++) { -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL ; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; + +/* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status !=
MSIX_VECTOR_DEV_SHAREDdrivers/vdpa/ifcvf/ifcvf_main.c +11
-0+*/ +if (vf->msix_vector_status !=MSIX_VECTOR_DEV_SHARED ) { +devm_free_irq (&pdev->dev, vf->config_irq, vf); + vf->config_irq = -EINVAL ; } +} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ +struct pci_dev *pdev = adapter->pdev; -devm_free_irq (&pdev->dev, vf->config_irq, vf); +ifcvf_free_vq_irq (adapter, queues); +ifcvf_free_config_irq (adapter);ifcvf_free_irq_vectors (pdev); } @@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct
ifcvf_adapter*adapter)return ret;}
-static intifcvf_request_irq(struct ifcvf_adapter *adapter)drivers/vdpa/ifcvf/ifcvf_main.c +4
-4+static int ifcvf_request_per_vq_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, nvectors, i, ret, irq; -u16 max_intr; +int i, vector, ret, irq; - nvectors =ifcvf_alloc_vectors (adapter); -if (!(nvectors >0 )) -return nvectors; +for (i =0 ; i < vf->nr_vring; i++) { + snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n",
pci_name(pdev), i);drivers/vdpa/ifcvf/ifcvf_main.c +22
-0+ vector = i; + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_intr_handler,0 , + vf->vring[i].msix_name, + &vf->vring[i]); +if (ret) { +IFCVF_ERR (pdev,"Failed to request irq for vq %d\n" , i); +ifcvf_free_vq_irq (adapter, i); + }else { + vf->vring[i].irq = irq; +ifcvf_set_vq_vector (vf, i, vector); + } + } - max_intr = vf->nr_vring +1 ; + vf->vqs_shared_irq = -EINVAL ; + +return 0 ; +} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev;Quoted 8 lines
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */
I think we can remove this comment since the code is straightforward.
sure
Quoted 127 lines
Quoted 114 lines
+ snprintf(vf->vring[0].msix_name, 256,
"ifcvf[%s]-vqs-shared-irq\n",pci_name(pdev));drivers/vdpa/ifcvf/ifcvf_main.c +28
-0+ irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_vq_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); + +return ret; + } + + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + +return 0 ; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared device interrupt name */
+ snprintf(vf->vring[0].msix_name, 256,
"ifcvf[%s]-dev-shared-irq\n",pci_name(pdev));drivers/vdpa/ifcvf/ifcvf_main.c +42
-3+ irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_dev_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); - ret =pci_alloc_irq_vectors (pdev, max_intr, - max_intr,PCI_IRQ_MSIX ); -if (ret <0 ) { -IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" ); return ret; } + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + + vf->config_irq = irq; +ifcvf_set_config_vector (vf, vector); + +return 0 ; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) + ret =ifcvf_request_per_vq_irq (adapter); +else + ret =ifcvf_request_shared_vq_irq (adapter); + +return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int config_vector, ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_DEV_SHARED ) +return 0 ; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) +/* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vector for config interrupt */
drivers/vdpa/ifcvf/ifcvf_main.c +8
-12+ config_vector = vf->nr_vring; + +if (vf->msix_vector_status ==MSIX_VECTOR_SHARED_VQ_AND_CONFIG ) +/* vector 0 for vqs and 1 for config interrupt */ + config_vector =1 ; +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" ,pci_name (pdev)); - vector =0 ; - vf->config_irq =pci_irq_vector (pdev, vector); + vf->config_irq =pci_irq_vector (pdev, config_vector); ret =devm_request_irq (&pdev->dev, vf->config_irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);if (ret) {IFCVF_ERR (pdev,"Failed to request config irq\n" ); +ifcvf_free_vq_irq (adapter, vf->nr_vring);return ret; } - for (i = 0; i < vf->nr_vring; i++) { -snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" , -pci_name (pdev), i); - vector = i +IFCVF_MSI_QUEUE_OFF ; - irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, - ifcvf_intr_handler,0 , - vf->vring[i].msix_name, - &vf->vring[i]); -if (ret) { - IFCVF_ERR(pdev,drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-3- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq (adapter, i); +ifcvf_set_config_vector (vf, config_vector); - return ret; - } +return 0 ; +} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Do you mean if we don't get enough vectors, just use only one vector for the vqs and config changes? I guess this
only works if ISR work for MSIX as we expects, or we may waste some time in the device config space.
Ok, I think I got you here. It's better to document this in the change log.
Thanks
Quoted 52 lines
Quoted 51 lines
Quoted 51 lines
Thanks,
Zhu LingshanQuoted 48 lines
Thanks
Quoted 40 lines
drivers/vdpa/ifcvf/ifcvf_main.c +24
-0+struct ifcvf_hw *vf = &adapter->vf; +int nvectors, ret, max_intr; - vf->vring[i].irq = irq; + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + + vf->msix_vector_status =MSIX_VECTOR_PER_VQ_AND_CONFIG ; + max_intr = vf->nr_vring +1 ; +if (nvectors < max_intr) + vf->msix_vector_status =MSIX_VECTOR_SHARED_VQ_AND_CONFIG ; + +if (nvectors ==1 ) { + vf->msix_vector_status =MSIX_VECTOR_DEV_SHARED ; + ret =ifcvf_request_dev_shared_irq (adapter); + +return ret; } + ret =ifcvf_request_vq_irq (adapter); +if (ret) +return ret; + + ret =ifcvf_request_config_irq (adapter); + +if (ret) +return ret; +return 0 ; } @@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct
vdpa_device*vdpa_dev,{ struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);- return vf->vring[qid].irq;
drivers/vdpa/ifcvf/ifcvf_main.c +4
-0+if (vf->vqs_shared_irq <0 ) +return vf->vring[qid].irq; +else +return -EINVAL ; } static struct vdpa_notification_areaQuoted 1 line
ifcvf_get_vq_notification(struct
vdpa_device*vdpa_dev,_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 64 lines · Jason Wang
Quoted 63 lines · Lingshan
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Zhu Lingshan
Quoted 58 lines · Jason Wang
Quoted 45 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +1
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector) +{drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct · line 29
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +9
-0+struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select); +ifc_iowrite16 (vector, &cfg->queue_msix_vector); +if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
ifcvf driver sets
NO_VECTORwhen callhw_disable(). I am not sure whether I get it,I meant you invent the
ifcvf_set_vq_vector()you'd better use that inhw_disable()as well.
OK
Quoted 23 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Yes we can let the caller check a vq vector, however this may cause more than three levels brackets, may looks ugly.
I don't understand here, this is how
virito_pcidid:/*
*vp_modern_queue_vector- set the MSIX vector for a specific virtqueue
* @mdev: the modern virtio-pci device
* @index: queue index
* @vector: the config vector
*
* Returns the config vector read from the device
*/
u16 vp_modern_queue_vector(structvirtio_pci_modern_device*mdev,u16 index, u16 vector) { struct virtio_pci_common_cfg __iomem *cfg = mdev->common; vp_iowrite16(index, &cfg->queue_select); vp_iowrite16(vector, &cfg->queue_msix_vector); /* Flush the write out to device */ return vp_ioread16(&cfg->queue_msix_vector); }
Quoted 1 line
EXPORT_SYMBOL_GPL(vp_modern_queue_vector);
I mean if we leave the checks for the caller, it may look like:
+ for (i = 0; i < vf->nr_vring; i++) {
+ snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n", pci_name(pdev), i); + vector = i;
+ irq = pci_irq_vector(pdev, vector);
+ ret = devm_request_irq(&pdev->dev, irq,
+ ifcvf_intr_handler, 0,
+ vf->vring[i].msix_name,
+ &vf->vring[i]);
+ if (ret) {
+ IFCVF_ERR(pdev, "Failed to request irq for vq %d\n", i); + ifcvf_free_vq_irq(adapter, i);
+ } else {
+ vf->vring[i].irq = irq;
+ ifcvf_set_vq_vector(vf, i, vector);
if (xxxxx) {
xxxxxxxxxxx;
}
+ }
+ }
Too many brackets.
Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + }Similar question as above.
Quoted 62 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-15+ +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; } @@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable);}drivers/vdpa/ifcvf/ifcvf_base.h +2
-2@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 +/* all vqs share a vector, and config interrupt has a separate vector */
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_base.h +3
-0+#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
IMHO we still need 2 and 3, because
MSIX_VECTOR_SHARED_VQ_AND_CONFIGmeans there are at least 2 vectors,
the vqs share one vector, config change has its own vector.I want to know the value of having a dedicated vector for config?
I think a dedicated vector for config changes can help us avoid operations on config space when vq interrupt triggered.
Quoted 411 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
MSIX_VECTOR_DEV_SHAREDmeans three are only one vector, all vqs and config changes need to share this vector.Quoted 11 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?Quoted 53 lines
Quoted 2 lines
Quoted 1 line
for cacheline alignment.
maybe a separate patch then.
Sure
Thanks!
Quoted 48 lines
Quoted 48 lines
Quoted 39 lines
Quoted 39 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */drivers/vdpa/ifcvf/ifcvf_main.c +0
-0Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c line 19
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -17,6 +17,7 @@#define DRIVER_AUTHOR "Intel Corporation"#define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
OK, do you mean the comments? I can remove these comments.
Yes.
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, · line 31
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c +0
-0static irqreturn_t ifcvf_config_changed (int irq,void *arg) {struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg)return IRQ_HANDLED ; } +/* handles vqs interrupt */So did this.
Quoted 20 lines
drivers/vdpa/ifcvf/ifcvf_main.c +12
-0static irqreturn_t ifcvf_intr_handler (int irq,void *arg) {struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler(int irq, void *arg) +{ +struct ifcvf_hw *vf = arg; +struct vring_info *vring; +int i; + +for (i =0 ; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; +if (vring->cb.callback) + vf->vring->cb.callback (vring->cb.private); + } +drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, · line 64
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+return IRQ_HANDLED ; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +u8 isr; + + isr =ifc_ioread8 (vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.as we discussed in another thread(spec inconsistency about ISR), ISR may only works for INTx for now,
but VFs don't have INTx, and a VF may not share its vectors with other devices, so I guess it can work
and may be our best try for now.Right, I thought you're using shared irq but actually not.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 66
Quoted 2 lines
drivers/vdpa/ifcvf/ifcvf_main.c +2
-0+if (isr &VIRTIO_PCI_ISR_CONFIG ) +ifcvf_config_changed (irq, arg);I wonder how ISR works in IFCVF, if ISR doesn't work for MSI, we need to remove the check of isr otherwise we will break config interrupt?
Quoted 226 lines
Quoted 226 lines
Quoted 226 lines
Quoted 92 lines
Quoted 92 lines
drivers/vdpa/ifcvf/ifcvf_main.c +22
-2+ +return ifcvf_vq_shared_intr_handler (irq, arg); +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data); } -static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) +static void ifcvf_free_vq_irq(struct ifcvf_adapter *adapter, int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf;int i; + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) { +for (i =0 ; i < queues; i++) { +devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL ; + } + } else { +devm_free_irq (&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL ; + } +} - for (i = 0; i < queues; i++) { -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL ; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; + +/* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status !=
MSIX_VECTOR_DEV_SHAREDdrivers/vdpa/ifcvf/ifcvf_main.c +11
-0+*/ +if (vf->msix_vector_status !=MSIX_VECTOR_DEV_SHARED ) { +devm_free_irq (&pdev->dev, vf->config_irq, vf); + vf->config_irq = -EINVAL ; } +} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ +struct pci_dev *pdev = adapter->pdev; -devm_free_irq (&pdev->dev, vf->config_irq, vf); +ifcvf_free_vq_irq (adapter, queues); +ifcvf_free_config_irq (adapter);ifcvf_free_irq_vectors (pdev); } @@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct
ifcvf_adapter*adapter)return ret; } -static int ifcvf_request_irq(struct ifcvf_adapter *adapter)drivers/vdpa/ifcvf/ifcvf_main.c +4
-4+static int ifcvf_request_per_vq_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, nvectors, i, ret, irq; -u16 max_intr; +int i, vector, ret, irq; - nvectors =ifcvf_alloc_vectors (adapter); -if (!(nvectors >0 )) -return nvectors; +for (i =0 ; i < vf->nr_vring; i++) { + snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n",
pci_name(pdev), i);drivers/vdpa/ifcvf/ifcvf_main.c +21
-0+ vector = i; + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_intr_handler,0 , + vf->vring[i].msix_name, + &vf->vring[i]); +if (ret) { +IFCVF_ERR (pdev,"Failed to request irq for vq %d\n" , i); +ifcvf_free_vq_irq (adapter, i); + }else { + vf->vring[i].irq = irq; +ifcvf_set_vq_vector (vf, i, vector); + } + } - max_intr = vf->nr_vring +1 ; + vf->vqs_shared_irq = -EINVAL ; + +return 0 ; +} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{Quoted 8 lines
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-0+struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */
I think we can remove this comment since the code is straightforward.
sure
Quoted 125 lines
Quoted 113 lines
+ snprintf(vf->vring[0].msix_name, 256,
"ifcvf[%s]-vqs-shared-irq\n",pci_name(pdev));drivers/vdpa/ifcvf/ifcvf_main.c +28
-0+ irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_vq_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); + +return ret; + } + + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + +return 0 ; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared device interrupt name */
+ snprintf(vf->vring[0].msix_name, 256,
"ifcvf[%s]-dev-shared-irq\n",pci_name(pdev));drivers/vdpa/ifcvf/ifcvf_main.c +42
-3+ irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_dev_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); - ret =pci_alloc_irq_vectors (pdev, max_intr, - max_intr,PCI_IRQ_MSIX ); -if (ret <0 ) { -IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" ); return ret; } + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + + vf->config_irq = irq; +ifcvf_set_config_vector (vf, vector); + +return 0 ; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) + ret =ifcvf_request_per_vq_irq (adapter); +else + ret =ifcvf_request_shared_vq_irq (adapter); + +return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int config_vector, ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_DEV_SHARED ) +return 0 ; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) +/* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vector for config interrupt */
drivers/vdpa/ifcvf/ifcvf_main.c +8
-12+ config_vector = vf->nr_vring; + +if (vf->msix_vector_status ==MSIX_VECTOR_SHARED_VQ_AND_CONFIG ) +/* vector 0 for vqs and 1 for config interrupt */ + config_vector =1 ; +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" ,pci_name (pdev)); - vector =0 ; - vf->config_irq =pci_irq_vector (pdev, vector); + vf->config_irq =pci_irq_vector (pdev, config_vector); ret =devm_request_irq (&pdev->dev, vf->config_irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);if (ret) {IFCVF_ERR (pdev,"Failed to request config irq\n" ); +ifcvf_free_vq_irq (adapter, vf->nr_vring);return ret; } - for (i = 0; i < vf->nr_vring; i++) { -snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" , -pci_name (pdev), i); - vector = i +IFCVF_MSI_QUEUE_OFF ; - irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, - ifcvf_intr_handler,0 , - vf->vring[i].msix_name, - &vf->vring[i]); -if (ret) { - IFCVF_ERR(pdev,drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-3- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq (adapter, i); +ifcvf_set_config_vector (vf, config_vector); - return ret; - } +return 0 ; +} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Do you mean if we don't get enough vectors, just use only one vector for the vqs and config changes? I guess this
only works if ISR work for MSIX as we expects, or we may waste some time in the device config space.Ok, I think I got you here. It's better to document this in the change log.
Thanks
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Thanks,
Zhu LingshanQuoted 48 lines
Thanks
Quoted 40 lines
drivers/vdpa/ifcvf/ifcvf_main.c +24
-0+struct ifcvf_hw *vf = &adapter->vf; +int nvectors, ret, max_intr; - vf->vring[i].irq = irq; + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + + vf->msix_vector_status =MSIX_VECTOR_PER_VQ_AND_CONFIG ; + max_intr = vf->nr_vring +1 ; +if (nvectors < max_intr) + vf->msix_vector_status =MSIX_VECTOR_SHARED_VQ_AND_CONFIG ; + +if (nvectors ==1 ) { + vf->msix_vector_status =MSIX_VECTOR_DEV_SHARED ; + ret =ifcvf_request_dev_shared_irq (adapter); + +return ret; } + ret =ifcvf_request_vq_irq (adapter); +if (ret) +return ret; + + ret =ifcvf_request_config_irq (adapter); + +if (ret) +return ret; +return 0 ; } @@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct
vdpa_device*vdpa_dev,{ struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); - return vf->vring[qid].irq;drivers/vdpa/ifcvf/ifcvf_main.c +4
-0+if (vf->vqs_shared_irq <0 ) +return vf->vring[qid].irq; +else +return -EINVAL ; } static struct vdpa_notification_areaQuoted 1 line
ifcvf_get_vq_notification(struct
vdpa_device*vdpa_dev,_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 110 lines · Lingshan
Quoted 64 lines · Jason Wang
Quoted 63 lines · Lingshan
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Zhu Lingshan
Quoted 58 lines · Jason Wang
Quoted 45 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +1
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector) +{drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct · line 29
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +9
-0+struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select); +ifc_iowrite16 (vector, &cfg->queue_msix_vector); +if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
ifcvf driver sets
NO_VECTORwhen callhw_disable(). I am not sure whether I get it,I meant you invent the
ifcvf_set_vq_vector()you'd better use that inhw_disable()as well.OK
Quoted 23 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Yes we can let the caller check a vq vector, however this may cause more than three levels brackets, may looks ugly.
I don't understand here, this is how
virito_pcidid:/*
*vp_modern_queue_vector- set the MSIX vector for a specific virtqueue
* @mdev: the modern virtio-pci device
* @index: queue index
* @vector: the config vector
*
* Returns the config vector read from the device
*/
u16 vp_modern_queue_vector(structvirtio_pci_modern_device*mdev,u16 index, u16 vector) { struct virtio_pci_common_cfg __iomem *cfg = mdev->common; vp_iowrite16(index, &cfg->queue_select); vp_iowrite16(vector, &cfg->queue_msix_vector); /* Flush the write out to device */ return vp_ioread16(&cfg->queue_msix_vector); }Quoted 1 line
EXPORT_SYMBOL_GPL(vp_modern_queue_vector);I mean if we leave the checks for the caller, it may look like:
(quoted diff) +2
-0+ for (i = 0; i < vf->nr_vring; i++) { + snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n",
pci_name(pdev), i);(quoted diff) +8
-0+ vector = i; + irq = pci_irq_vector(pdev, vector); + ret = devm_request_irq(&pdev->dev, irq, + ifcvf_intr_handler, 0, + vf->vring[i].msix_name, + &vf->vring[i]); + if (ret) { + IFCVF_ERR(pdev, "Failed to request irq for vq%d\n", i);
Review
Quoted 9 lines
(quoted diff) +6
-0+ ifcvf_free_vq_irq(adapter, i); + } else { + vf->vring[i].irq = irq; + ifcvf_set_vq_vector(vf, i, vector); if (xxxxx) { xxxxxxxxxxx; } + } + }
If the brackets are the only concern, you can factor out the per vq logic into a dedicated function.
Thanks
Quoted 506 lines
Too many brackets.
Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct · line 44
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + }Similar question as above.
Quoted 62 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-15+ +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; } @@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable);}drivers/vdpa/ifcvf/ifcvf_base.h +2
-2@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 +/* all vqs share a vector, and config interrupt has a separate vector */
drivers/vdpa/ifcvf/ifcvf_base.h
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_base.h +3
-0+#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
IMHO we still need 2 and 3, because
MSIX_VECTOR_SHARED_VQ_AND_CONFIGmeans there are at least 2 vectors,
the vqs share one vector, config change has its own vector.I want to know the value of having a dedicated vector for config?
I think a dedicated vector for config changes can help us avoid operations on config space when vq interrupt triggered.
Quoted 411 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
MSIX_VECTOR_DEV_SHAREDmeans three are only one vector, all vqs and config changes need to share this vector.Quoted 11 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?Quoted 53 lines
Quoted 2 lines
Quoted 1 line
for cacheline alignment.
maybe a separate patch then.
Sure
Thanks!
Quoted 48 lines
Quoted 48 lines
Quoted 39 lines
Quoted 39 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */drivers/vdpa/ifcvf/ifcvf_main.c +0
-0Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c line 19
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_main.c +0
-0@@ -17,6 +17,7 @@#define DRIVER_AUTHOR "Intel Corporation"#define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
OK, do you mean the comments? I can remove these comments.
Yes.
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, · line 31
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c +0
-0static irqreturn_t ifcvf_config_changed (int irq,void *arg) {struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg)return IRQ_HANDLED ; } +/* handles vqs interrupt */So did this.
Quoted 20 lines
drivers/vdpa/ifcvf/ifcvf_main.c +12
-0static irqreturn_t ifcvf_intr_handler (int irq,void *arg) {struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler(int irq, void *arg) +{ +struct ifcvf_hw *vf = arg; +struct vring_info *vring; +int i; + +for (i =0 ; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; +if (vring->cb.callback) + vf->vring->cb.callback (vring->cb.private); + } +drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, · line 64
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+return IRQ_HANDLED ; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +u8 isr; + + isr =ifc_ioread8 (vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.as we discussed in another thread(spec inconsistency about ISR), ISR may only works for INTx for now,
but VFs don't have INTx, and a VF may not share its vectors with other devices, so I guess it can work
and may be our best try for now.Right, I thought you're using shared irq but actually not.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, · line 66
Quoted 2 lines
drivers/vdpa/ifcvf/ifcvf_main.c +2
-0+if (isr &VIRTIO_PCI_ISR_CONFIG ) +ifcvf_config_changed (irq, arg);I wonder how ISR works in IFCVF, if ISR doesn't work for MSI, we need to remove the check of isr otherwise we will break config interrupt?
Quoted 226 lines
Quoted 226 lines
Quoted 226 lines
Quoted 92 lines
Quoted 92 lines
drivers/vdpa/ifcvf/ifcvf_main.c +22
-2+ +return ifcvf_vq_shared_intr_handler (irq, arg); +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data); } -static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) +static void ifcvf_free_vq_irq(struct ifcvf_adapter *adapter, int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf;int i; + if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) { +for (i =0 ; i < queues; i++) { +devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL ; + } + } else { +devm_free_irq (&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL ; + } +} - for (i = 0; i < queues; i++) { -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL ; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; + +/* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status !=
MSIX_VECTOR_DEV_SHAREDdrivers/vdpa/ifcvf/ifcvf_main.c +11
-0+*/ +if (vf->msix_vector_status !=MSIX_VECTOR_DEV_SHARED ) { +devm_free_irq (&pdev->dev, vf->config_irq, vf); + vf->config_irq = -EINVAL ; } +} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ +struct pci_dev *pdev = adapter->pdev; -devm_free_irq (&pdev->dev, vf->config_irq, vf); +ifcvf_free_vq_irq (adapter, queues); +ifcvf_free_config_irq (adapter);ifcvf_free_irq_vectors (pdev); } @@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct
ifcvf_adapter*adapter)return ret; } -static int ifcvf_request_irq(struct ifcvf_adapter *adapter)drivers/vdpa/ifcvf/ifcvf_main.c +4
-4+static int ifcvf_request_per_vq_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, nvectors, i, ret, irq; -u16 max_intr; +int i, vector, ret, irq; - nvectors =ifcvf_alloc_vectors (adapter); -if (!(nvectors >0 )) -return nvectors; +for (i =0 ; i < vf->nr_vring; i++) { + snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n",
pci_name(pdev), i);drivers/vdpa/ifcvf/ifcvf_main.c +21
-0+ vector = i; + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_intr_handler,0 , + vf->vring[i].msix_name, + &vf->vring[i]); +if (ret) { +IFCVF_ERR (pdev,"Failed to request irq for vq %d\n" , i); +ifcvf_free_vq_irq (adapter, i); + }else { + vf->vring[i].irq = irq; +ifcvf_set_vq_vector (vf, i, vector); + } + } - max_intr = vf->nr_vring +1 ; + vf->vqs_shared_irq = -EINVAL ; + +return 0 ; +} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{Quoted 8 lines
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-0+struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */
I think we can remove this comment since the code is straightforward.
sure
Quoted 125 lines
Quoted 113 lines
+ snprintf(vf->vring[0].msix_name, 256,
"ifcvf[%s]-vqs-shared-irq\n",pci_name(pdev));drivers/vdpa/ifcvf/ifcvf_main.c +28
-0+ irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_vq_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); + +return ret; + } + + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + +return 0 ; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared device interrupt name */
+ snprintf(vf->vring[0].msix_name, 256,
"ifcvf[%s]-dev-shared-irq\n",pci_name(pdev));drivers/vdpa/ifcvf/ifcvf_main.c +42
-3+ irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_dev_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); - ret =pci_alloc_irq_vectors (pdev, max_intr, - max_intr,PCI_IRQ_MSIX ); -if (ret <0 ) { -IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" ); return ret; } + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + + vf->config_irq = irq; +ifcvf_set_config_vector (vf, vector); + +return 0 ; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) + ret =ifcvf_request_per_vq_irq (adapter); +else + ret =ifcvf_request_shared_vq_irq (adapter); + +return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int config_vector, ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_DEV_SHARED ) +return 0 ; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) +/* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vector for config interrupt */
drivers/vdpa/ifcvf/ifcvf_main.c +8
-12+ config_vector = vf->nr_vring; + +if (vf->msix_vector_status ==MSIX_VECTOR_SHARED_VQ_AND_CONFIG ) +/* vector 0 for vqs and 1 for config interrupt */ + config_vector =1 ; +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" ,pci_name (pdev)); - vector =0 ; - vf->config_irq =pci_irq_vector (pdev, vector); + vf->config_irq =pci_irq_vector (pdev, config_vector); ret =devm_request_irq (&pdev->dev, vf->config_irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);if (ret) {IFCVF_ERR (pdev,"Failed to request config irq\n" ); +ifcvf_free_vq_irq (adapter, vf->nr_vring);return ret; } - for (i = 0; i < vf->nr_vring; i++) { -snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" , -pci_name (pdev), i); - vector = i +IFCVF_MSI_QUEUE_OFF ; - irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, - ifcvf_intr_handler,0 , - vf->vring[i].msix_name, - &vf->vring[i]); -if (ret) { - IFCVF_ERR(pdev,drivers/vdpa/ifcvf/ifcvf_main.c
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-3- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq (adapter, i); +ifcvf_set_config_vector (vf, config_vector); - return ret; - } +return 0 ; +} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Do you mean if we don't get enough vectors, just use only one vector for the vqs and config changes? I guess this
only works if ISR work for MSIX as we expects, or we may waste some time in the device config space.Ok, I think I got you here. It's better to document this in the change log.
Thanks
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Thanks,
Zhu LingshanQuoted 48 lines
Thanks
Quoted 40 lines
drivers/vdpa/ifcvf/ifcvf_main.c +24
-0+struct ifcvf_hw *vf = &adapter->vf; +int nvectors, ret, max_intr; - vf->vring[i].irq = irq; + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + + vf->msix_vector_status =MSIX_VECTOR_PER_VQ_AND_CONFIG ; + max_intr = vf->nr_vring +1 ; +if (nvectors < max_intr) + vf->msix_vector_status =MSIX_VECTOR_SHARED_VQ_AND_CONFIG ; + +if (nvectors ==1 ) { + vf->msix_vector_status =MSIX_VECTOR_DEV_SHARED ; + ret =ifcvf_request_dev_shared_irq (adapter); + +return ret; } + ret =ifcvf_request_vq_irq (adapter); +if (ret) +return ret; + + ret =ifcvf_request_config_irq (adapter); + +if (ret) +return ret; +return 0 ; } @@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct
vdpa_device*vdpa_dev,{ struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); - return vf->vring[qid].irq;drivers/vdpa/ifcvf/ifcvf_main.c +4
-0+if (vf->vqs_shared_irq <0 ) +return vf->vring[qid].irq; +else +return -EINVAL ; } static struct vdpa_notification_areaQuoted 1 line
ifcvf_get_vq_notification(struct
vdpa_device*vdpa_dev,_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 50 lines · Jason Wang
Quoted 48 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +7
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector) +{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select); +ifc_iowrite16 (vector, &cfg->queue_msix_vector);
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 28
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_base.c +4
-0+if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?
Hmm I'm not sure I agree. Caller will have to write queue select again, and that's an extra IO, which is a waste.
And having function checking itself just seems better contained.
Quoted 78 lines
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + }Similar question as above.
Quoted 57 lines
drivers/vdpa/ifcvf/ifcvf_base.c +6
-15+ +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; }@@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable); }drivers/vdpa/ifcvf/ifcvf_base.h +2
-2@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_base.h +4
-0+/* all vqs share a vector, and config interrupt has a separate vector */ +#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
Yes but if we do not have a dedicated vector then we need an extra device IO (in fact, a read) on each interrupt.
Quoted 91 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?Quoted 39 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */ drivers/vdpa/ifcvf/ifcvf_main.c +0
-0drivers/vdpa/ifcvf/ifcvf_main.c line 19
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0@@ -17,6 +17,7 @@#define DRIVER_AUTHOR "Intel Corporation"#define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */ This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, void *arg) · line 30
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0static irqreturn_t ifcvf_config_changed (int irq,void *arg) {struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg)return IRQ_HANDLED ; } +/* handles vqs interrupt */ So did this.
Quoted 16 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0static irqreturn_t ifcvf_intr_handler (int irq,void *arg) {struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +struct vring_info *vring; +int i; + +for (i =0 ; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; +if (vring->cb.callback)
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 59
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c +8
-0+ vf->vring->cb.callback (vring->cb.private); + } + +return IRQ_HANDLED ; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg)
shared is not a good name given IRQ_SHARED is not set. maybe "common"? "reused"?
Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 64
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+{ +struct ifcvf_hw *vf = arg; +u8 isr; + + isr =ifc_ioread8 (vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.
no, vf->isr is not set for VQ interrupts. If need to actually poke at the VQ to know.
Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.
It's a MSI, not INT#. So interrupt is not shared as such - it's only sharing vector between config and vq.
Quoted 226 lines
Quoted 87 lines
drivers/vdpa/ifcvf/ifcvf_main.c +57
-12+if (isr &VIRTIO_PCI_ISR_CONFIG ) +ifcvf_config_changed (irq, arg); + +return ifcvf_vq_shared_intr_handler (irq, arg); +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data); } -static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +static void ifcvf_free_vq_irq (struct ifcvf_adapter *adapter,int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf;int i; +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) { +for (i =0 ; i < queues; i++) { +devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL ; + } + }else { +devm_free_irq (&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL ; + } +} -for (i =0 ; i < queues; i++) { -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL ; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; + +/* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status != MSIX_VECTOR_DEV_SHARED +*/ +if (vf->msix_vector_status !=MSIX_VECTOR_DEV_SHARED ) { +devm_free_irq (&pdev->dev, vf->config_irq, vf); + vf->config_irq = -EINVAL ; } +} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ +struct pci_dev *pdev = adapter->pdev; -devm_free_irq (&pdev->dev, vf->config_irq, vf); +ifcvf_free_vq_irq (adapter, queues); +ifcvf_free_config_irq (adapter);ifcvf_free_irq_vectors (pdev); }@@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter)return ret; } -static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +static int ifcvf_request_per_vq_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, nvectors, i, ret, irq; -u16 max_intr; +int i, vector, ret, irq; - nvectors =ifcvf_alloc_vectors (adapter); -if (!(nvectors >0 )) -return nvectors; +for (i =0 ; i < vf->nr_vring; i++) { +snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" ,pci_name (pdev), i); + vector = i; + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_intr_handler,0 , + vf->vring[i].msix_name, + &vf->vring[i]); +if (ret) { +IFCVF_ERR (pdev,"Failed to request irq for vq %d\n" , i); +ifcvf_free_vq_irq (adapter, i); + }else { + vf->vring[i].irq = irq; +ifcvf_set_vq_vector (vf, i, vector); + } + } - max_intr = vf->nr_vring +1 ; + vf->vqs_shared_irq = -EINVAL ; + +return 0 ;drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 177
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */ I think we can remove this comment since the code is straightforward.
Quoted 109 lines
drivers/vdpa/ifcvf/ifcvf_main.c +81
-17+snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-vqs-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_vq_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); + +return ret; + } + + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + +return 0 ; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared device interrupt name */ +snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-dev-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_dev_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); - ret =pci_alloc_irq_vectors (pdev, max_intr, - max_intr,PCI_IRQ_MSIX ); -if (ret <0 ) { -IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" );return ret; } + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + + vf->config_irq = irq; +ifcvf_set_config_vector (vf, vector); + +return 0 ; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) + ret =ifcvf_request_per_vq_irq (adapter); +else + ret =ifcvf_request_shared_vq_irq (adapter); + +return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int config_vector, ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_DEV_SHARED ) +return 0 ; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) +/* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vector for config interrupt */ + config_vector = vf->nr_vring; + +if (vf->msix_vector_status ==MSIX_VECTOR_SHARED_VQ_AND_CONFIG ) +/* vector 0 for vqs and 1 for config interrupt */ + config_vector =1 ; +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" ,pci_name (pdev)); - vector =0 ; - vf->config_irq =pci_irq_vector (pdev, vector); + vf->config_irq =pci_irq_vector (pdev, config_vector); ret =devm_request_irq (&pdev->dev, vf->config_irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);if (ret) {IFCVF_ERR (pdev,"Failed to request config irq\n" ); +ifcvf_free_vq_irq (adapter, vf->nr_vring);return ret; } -for (i =0 ; i < vf->nr_vring; i++) { -snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" , -pci_name (pdev), i); - vector = i +IFCVF_MSI_QUEUE_OFF ; - irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, - ifcvf_intr_handler,0 , - vf->vring[i].msix_name, - &vf->vring[i]); -if (ret) { - IFCVF_ERR(pdev,drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-4- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq (adapter, i); +ifcvf_set_config_vector (vf, config_vector); -return ret; - } +return 0 ; +} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Quoted 2 lines
Thanks
Well it is claimed there are platforms where we are short on vectors. 3 versus 2 seems a 50% saving. You disagree?
Quoted 31 lines
Quoted 31 lines
drivers/vdpa/ifcvf/ifcvf_main.c +25
-1+struct ifcvf_hw *vf = &adapter->vf; +int nvectors, ret, max_intr; - vf->vring[i].irq = irq; + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + + vf->msix_vector_status =MSIX_VECTOR_PER_VQ_AND_CONFIG ; + max_intr = vf->nr_vring +1 ; +if (nvectors < max_intr) + vf->msix_vector_status =MSIX_VECTOR_SHARED_VQ_AND_CONFIG ; + +if (nvectors ==1 ) { + vf->msix_vector_status =MSIX_VECTOR_DEV_SHARED ; + ret =ifcvf_request_dev_shared_irq (adapter); + +return ret; } + ret =ifcvf_request_vq_irq (adapter); +if (ret) +return ret; + + ret =ifcvf_request_config_irq (adapter); + +if (ret) +return ret; +return 0 ; }@@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct vdpa_device *vdpa_dev, {
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_vdpa_get_vq_irq(struct vdpa_device *vdpa_dev, · line 620
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c +4
-1struct ifcvf_hw *vf =vdpa_to_vf (vdpa_dev); -return vf->vring[qid].irq; +if (vf->vqs_shared_irq <0 ) +return vf->vring[qid].irq; +else +return -EINVAL ; } static struct vdpa_notification_area ifcvf_get_vq_notification(struct vdpa_device *vdpa_dev,
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 238 lines · Michael S. Tsirkin
Quoted 48 lines · Jason Wang
Quoted 47 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +6
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector) +{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select);Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 28
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ifc_iowrite16 (vector, &cfg->queue_msix_vector); +if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?Hmm I'm not sure I agree. Caller will have to write queue select again, and that's an extra IO, which is a waste.
And having function checking itself just seems better contained.Quoted 75 lines
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + }Similar question as above.
Quoted 56 lines
drivers/vdpa/ifcvf/ifcvf_base.c +6
-15+ +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; }@@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable); }drivers/vdpa/ifcvf/ifcvf_base.h +1
-2@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.h +5
-0+#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 +/* all vqs share a vector, and config interrupt has a separate vector */ +#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
Yes but if we do not have a dedicated vector then we need an extra device IO (in fact, a read) on each interrupt.
Quoted 89 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?Quoted 39 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */ drivers/vdpa/ifcvf/ifcvf_main.c +0
-0drivers/vdpa/ifcvf/ifcvf_main.c line 19
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0@@ -17,6 +17,7 @@#define DRIVER_AUTHOR "Intel Corporation"#define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */ This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, void *arg) · line 30
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0static irqreturn_t ifcvf_config_changed (int irq,void *arg) {struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg)return IRQ_HANDLED ; } +/* handles vqs interrupt */ So did this.
Quoted 18 lines
drivers/vdpa/ifcvf/ifcvf_main.c +12
-0static irqreturn_t ifcvf_intr_handler (int irq,void *arg) {struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +struct vring_info *vring; +int i; + +for (i =0 ; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; +if (vring->cb.callback) + vf->vring->cb.callback (vring->cb.private); + }
Quoted 8 lines
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 59
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-0+ +return IRQ_HANDLED ; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg)shared is not a good name given
IRQ_SHAREDis not set. maybe "common"? "reused"?
Sure, I can do better naming
Thanks
Quoted 286 lines
Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 64
Quoted 6 lines
drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+{ +struct ifcvf_hw *vf = arg; +u8 isr; + + isr =ifc_ioread8 (vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.no,
vf->isris not set for VQ interrupts. If need to actually poke at the VQ to know.Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.It's a MSI, not INT#. So interrupt is not shared as such - it's only sharing vector between config and vq.
Quoted 223 lines
Quoted 86 lines
drivers/vdpa/ifcvf/ifcvf_main.c +57
-12+if (isr &VIRTIO_PCI_ISR_CONFIG ) +ifcvf_config_changed (irq, arg); + +return ifcvf_vq_shared_intr_handler (irq, arg); +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data); } -static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +static void ifcvf_free_vq_irq (struct ifcvf_adapter *adapter,int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf;int i; +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) { +for (i =0 ; i < queues; i++) { +devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL ; + } + }else { +devm_free_irq (&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL ; + } +} -for (i =0 ; i < queues; i++) { -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL ; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; + +/* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status != MSIX_VECTOR_DEV_SHARED +*/ +if (vf->msix_vector_status !=MSIX_VECTOR_DEV_SHARED ) { +devm_free_irq (&pdev->dev, vf->config_irq, vf); + vf->config_irq = -EINVAL ; } +} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ +struct pci_dev *pdev = adapter->pdev; -devm_free_irq (&pdev->dev, vf->config_irq, vf); +ifcvf_free_vq_irq (adapter, queues); +ifcvf_free_config_irq (adapter);ifcvf_free_irq_vectors (pdev); }@@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter)return ret; } -static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +static int ifcvf_request_per_vq_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, nvectors, i, ret, irq; -u16 max_intr; +int i, vector, ret, irq; - nvectors =ifcvf_alloc_vectors (adapter); -if (!(nvectors >0 )) -return nvectors; +for (i =0 ; i < vf->nr_vring; i++) { +snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" ,pci_name (pdev), i); + vector = i; + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_intr_handler,0 , + vf->vring[i].msix_name, + &vf->vring[i]); +if (ret) { +IFCVF_ERR (pdev,"Failed to request irq for vq %d\n" , i); +ifcvf_free_vq_irq (adapter, i); + }else { + vf->vring[i].irq = irq; +ifcvf_set_vq_vector (vf, i, vector); + } + } - max_intr = vf->nr_vring +1 ; + vf->vqs_shared_irq = -EINVAL ; + +return 0 ;drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 177
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */ I think we can remove this comment since the code is straightforward.
Quoted 109 lines
drivers/vdpa/ifcvf/ifcvf_main.c +81
-17+snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-vqs-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_vq_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); + +return ret; + } + + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + +return 0 ; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared device interrupt name */ +snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-dev-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_dev_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); - ret =pci_alloc_irq_vectors (pdev, max_intr, - max_intr,PCI_IRQ_MSIX ); -if (ret <0 ) { -IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" );return ret; } + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + + vf->config_irq = irq; +ifcvf_set_config_vector (vf, vector); + +return 0 ; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) + ret =ifcvf_request_per_vq_irq (adapter); +else + ret =ifcvf_request_shared_vq_irq (adapter); + +return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int config_vector, ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_DEV_SHARED ) +return 0 ; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) +/* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vector for config interrupt */ + config_vector = vf->nr_vring; + +if (vf->msix_vector_status ==MSIX_VECTOR_SHARED_VQ_AND_CONFIG ) +/* vector 0 for vqs and 1 for config interrupt */ + config_vector =1 ; +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" ,pci_name (pdev)); - vector =0 ; - vf->config_irq =pci_irq_vector (pdev, vector); + vf->config_irq =pci_irq_vector (pdev, config_vector); ret =devm_request_irq (&pdev->dev, vf->config_irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);if (ret) {IFCVF_ERR (pdev,"Failed to request config irq\n" ); +ifcvf_free_vq_irq (adapter, vf->nr_vring);return ret; } -for (i =0 ; i < vf->nr_vring; i++) { -snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" , -pci_name (pdev), i); - vector = i +IFCVF_MSI_QUEUE_OFF ; - irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, - ifcvf_intr_handler,0 , - vf->vring[i].msix_name, - &vf->vring[i]); -if (ret) { - IFCVF_ERR(pdev,drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-4- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq (adapter, i); +ifcvf_set_config_vector (vf, config_vector); -return ret; - } +return 0 ; +} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Quoted 2 lines
Thanks
Well it is claimed there are platforms where we are short on vectors. 3 versus 2 seems a 50% saving. You disagree?
Quoted 39 lines
Quoted 39 lines
drivers/vdpa/ifcvf/ifcvf_main.c +29
-2+struct ifcvf_hw *vf = &adapter->vf; +int nvectors, ret, max_intr; - vf->vring[i].irq = irq; + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + + vf->msix_vector_status =MSIX_VECTOR_PER_VQ_AND_CONFIG ; + max_intr = vf->nr_vring +1 ; +if (nvectors < max_intr) + vf->msix_vector_status =MSIX_VECTOR_SHARED_VQ_AND_CONFIG ; + +if (nvectors ==1 ) { + vf->msix_vector_status =MSIX_VECTOR_DEV_SHARED ; + ret =ifcvf_request_dev_shared_irq (adapter); + +return ret; } + ret =ifcvf_request_vq_irq (adapter); +if (ret) +return ret; + + ret =ifcvf_request_config_irq (adapter); + +if (ret) +return ret; +return 0 ; }@@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct vdpa_device *vdpa_dev, {struct ifcvf_hw *vf =vdpa_to_vf (vdpa_dev); -return vf->vring[qid].irq; +if (vf->vqs_shared_irq <0 ) +return vf->vring[qid].irq; +else +return -EINVAL ; } static struct vdpa_notification_area ifcvf_get_vq_notification(struct vdpa_device *vdpa_dev,
Quoted 62 lines · Michael S. Tsirkin
Quoted 50 lines · Jason Wang
Quoted 48 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +7
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector) +{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select); +ifc_iowrite16 (vector, &cfg->queue_msix_vector);Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 28
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_base.c +4
-0+if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?
Quoted 3 lines
Hmm I'm not sure I agree. Caller will have to write queue select again, and that's an extra IO, which is a waste.
And having function checking itself just seems better contained.
It's as simple as just return what we read here like virtio_pci did:
u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,
u16 index, u16 vector)
{
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
vp_iowrite16(index, &cfg->queue_select);
vp_iowrite16(vector, &cfg->queue_msix_vector);
/* Flush the write out to device */
return vp_ioread16(&cfg->queue_msix_vector);
}EXPORT_SYMBOL_GPL(vp_modern_queue_vector);
Then the caller can decide to check it with NO_VECTOR if needed. Current code will break the callers that want to set NO_VECTOR.
Quoted 89 lines
Quoted 79 lines
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + }Similar question as above.
Quoted 57 lines
drivers/vdpa/ifcvf/ifcvf_base.c +6
-15+ +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; }@@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable); }drivers/vdpa/ifcvf/ifcvf_base.h +2
-2@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_base.h +4
-0+/* all vqs share a vector, and config interrupt has a separate vector */ +#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
Quoted 2 lines
Yes but if we do not have a dedicated vector then we need an extra device IO (in fact, a read) on each interrupt.
Ok, right.
Quoted 114 lines
Quoted 92 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 11 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?Quoted 39 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */ drivers/vdpa/ifcvf/ifcvf_main.c +0
-0drivers/vdpa/ifcvf/ifcvf_main.c line 19
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0@@ -17,6 +17,7 @@#define DRIVER_AUTHOR "Intel Corporation"#define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */ This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, void *arg) · line 30
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0static irqreturn_t ifcvf_config_changed (int irq,void *arg) {struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg)return IRQ_HANDLED ; } +/* handles vqs interrupt */ So did this.
Quoted 16 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0static irqreturn_t ifcvf_intr_handler (int irq,void *arg) {struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +struct vring_info *vring; +int i; + +for (i =0 ; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; +if (vring->cb.callback)Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 59
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c +8
-0+ vf->vring->cb.callback (vring->cb.private); + } + +return IRQ_HANDLED ; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg)shared is not a good name given
IRQ_SHAREDis not set. maybe "common"? "reused"?Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 64
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+{ +struct ifcvf_hw *vf = arg; +u8 isr; + + isr =ifc_ioread8 (vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.
Quoted 1 line
no,
vf->isris not set for VQ interrupts.
I actually wonder what's the actual behaviour of IFCVF.
Quoted 9 lines
If need to actually poke
at the VQ to know.Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.It's a MSI, not INT#. So interrupt is not shared as such - it's only sharing vector between config and vq.
Right, I thought it was a shared one as virito_pci did.
Quoted 228 lines
Quoted 228 lines
Quoted 89 lines
drivers/vdpa/ifcvf/ifcvf_main.c +57
-12+if (isr &VIRTIO_PCI_ISR_CONFIG ) +ifcvf_config_changed (irq, arg); + +return ifcvf_vq_shared_intr_handler (irq, arg); +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data); } -static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +static void ifcvf_free_vq_irq (struct ifcvf_adapter *adapter,int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf;int i; +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) { +for (i =0 ; i < queues; i++) { +devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL ; + } + }else { +devm_free_irq (&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL ; + } +} -for (i =0 ; i < queues; i++) { -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL ; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; + +/* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status != MSIX_VECTOR_DEV_SHARED +*/ +if (vf->msix_vector_status !=MSIX_VECTOR_DEV_SHARED ) { +devm_free_irq (&pdev->dev, vf->config_irq, vf); + vf->config_irq = -EINVAL ; } +} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ +struct pci_dev *pdev = adapter->pdev; -devm_free_irq (&pdev->dev, vf->config_irq, vf); +ifcvf_free_vq_irq (adapter, queues); +ifcvf_free_config_irq (adapter);ifcvf_free_irq_vectors (pdev); }@@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter)return ret; } -static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +static int ifcvf_request_per_vq_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, nvectors, i, ret, irq; -u16 max_intr; +int i, vector, ret, irq; - nvectors =ifcvf_alloc_vectors (adapter); -if (!(nvectors >0 )) -return nvectors; +for (i =0 ; i < vf->nr_vring; i++) { +snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" ,pci_name (pdev), i); + vector = i; + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_intr_handler,0 , + vf->vring[i].msix_name, + &vf->vring[i]); +if (ret) { +IFCVF_ERR (pdev,"Failed to request irq for vq %d\n" , i); +ifcvf_free_vq_irq (adapter, i); + }else { + vf->vring[i].irq = irq; +ifcvf_set_vq_vector (vf, i, vector); + } + } - max_intr = vf->nr_vring +1 ; + vf->vqs_shared_irq = -EINVAL ; + +return 0 ;drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 177
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */ I think we can remove this comment since the code is straightforward.
Quoted 109 lines
drivers/vdpa/ifcvf/ifcvf_main.c +81
-17+snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-vqs-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_vq_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); + +return ret; + } + + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + +return 0 ; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared device interrupt name */ +snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-dev-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_dev_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); - ret =pci_alloc_irq_vectors (pdev, max_intr, - max_intr,PCI_IRQ_MSIX ); -if (ret <0 ) { -IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" );return ret; } + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + + vf->config_irq = irq; +ifcvf_set_config_vector (vf, vector); + +return 0 ; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) + ret =ifcvf_request_per_vq_irq (adapter); +else + ret =ifcvf_request_shared_vq_irq (adapter); + +return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int config_vector, ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_DEV_SHARED ) +return 0 ; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) +/* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vector for config interrupt */ + config_vector = vf->nr_vring; + +if (vf->msix_vector_status ==MSIX_VECTOR_SHARED_VQ_AND_CONFIG ) +/* vector 0 for vqs and 1 for config interrupt */ + config_vector =1 ; +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" ,pci_name (pdev)); - vector =0 ; - vf->config_irq =pci_irq_vector (pdev, vector); + vf->config_irq =pci_irq_vector (pdev, config_vector); ret =devm_request_irq (&pdev->dev, vf->config_irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);if (ret) {IFCVF_ERR (pdev,"Failed to request config irq\n" ); +ifcvf_free_vq_irq (adapter, vf->nr_vring);return ret; } -for (i =0 ; i < vf->nr_vring; i++) { -snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" , -pci_name (pdev), i); - vector = i +IFCVF_MSI_QUEUE_OFF ; - irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, - ifcvf_intr_handler,0 , - vf->vring[i].msix_name, - &vf->vring[i]); -if (ret) { - IFCVF_ERR(pdev,drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-4- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq (adapter, i); +ifcvf_set_config_vector (vf, config_vector); -return ret; - } +return 0 ; +} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Quoted 5 lines
Quoted 2 lines
Thanks
Well it is claimed there are platforms where we are short on vectors. 3 versus 2 seems a 50% saving. You disagree?
I think we can 2 vectors (a dedicated for config).
Thanks
Quoted 41 lines
Quoted 40 lines
Quoted 40 lines
drivers/vdpa/ifcvf/ifcvf_main.c +29
-2+struct ifcvf_hw *vf = &adapter->vf; +int nvectors, ret, max_intr; - vf->vring[i].irq = irq; + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + + vf->msix_vector_status =MSIX_VECTOR_PER_VQ_AND_CONFIG ; + max_intr = vf->nr_vring +1 ; +if (nvectors < max_intr) + vf->msix_vector_status =MSIX_VECTOR_SHARED_VQ_AND_CONFIG ; + +if (nvectors ==1 ) { + vf->msix_vector_status =MSIX_VECTOR_DEV_SHARED ; + ret =ifcvf_request_dev_shared_irq (adapter); + +return ret; } + ret =ifcvf_request_vq_irq (adapter); +if (ret) +return ret; + + ret =ifcvf_request_config_irq (adapter); + +if (ret) +return ret; +return 0 ; }@@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct vdpa_device *vdpa_dev, {struct ifcvf_hw *vf =vdpa_to_vf (vdpa_dev); -return vf->vring[qid].irq; +if (vf->vqs_shared_irq <0 ) +return vf->vring[qid].irq; +else +return -EINVAL ; } static struct vdpa_notification_area ifcvf_get_vq_notification(struct vdpa_device *vdpa_dev,
Quoted 74 lines · Jason Wang
Quoted 58 lines · Michael S. Tsirkin
Quoted 48 lines · Jason Wang
Quoted 47 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +6
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector) +{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select);Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 28
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ifc_iowrite16 (vector, &cfg->queue_msix_vector); +if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?Quoted 3 lines
Hmm I'm not sure I agree. Caller will have to write queue select again, and that's an extra IO, which is a waste.
And having function checking itself just seems better contained.It's as simple as just return what we read here like
virtio_pcidid:u16 vp_modern_queue_vector(struct
virtio_pci_modern_device*mdev,u16 index, u16 vector) { struct virtio_pci_common_cfg __iomem *cfg = mdev->common; vp_iowrite16(index, &cfg->queue_select); vp_iowrite16(vector, &cfg->queue_msix_vector); /* Flush the write out to device */ return vp_ioread16(&cfg->queue_msix_vector); }
Quoted 4 lines
EXPORT_SYMBOL_GPL(vp_modern_queue_vector);Then the caller can decide to check it with
NO_VECTORif needed. Current code will break the callers that want to setNO_VECTOR.
OK, we can let the caller check the return value, then re-use set_xxx_vector in hw_disable()
Thanks
Quoted 478 lines
Quoted 84 lines
Quoted 75 lines
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + }Similar question as above.
Quoted 56 lines
drivers/vdpa/ifcvf/ifcvf_base.c +6
-15+ +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; }@@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable); }drivers/vdpa/ifcvf/ifcvf_base.h +1
-2@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_base.h +5
-0+#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 +/* all vqs share a vector, and config interrupt has a separate vector */ +#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
Quoted 2 lines
Yes but if we do not have a dedicated vector then we need an extra device IO (in fact, a read) on each interrupt.
Ok, right.
Quoted 106 lines
Quoted 87 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?Quoted 39 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */ drivers/vdpa/ifcvf/ifcvf_main.c +0
-0drivers/vdpa/ifcvf/ifcvf_main.c line 19
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0@@ -17,6 +17,7 @@#define DRIVER_AUTHOR "Intel Corporation"#define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */ This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, void *arg) · line 30
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0static irqreturn_t ifcvf_config_changed (int irq,void *arg) {struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg)return IRQ_HANDLED ; } +/* handles vqs interrupt */ So did this.
Quoted 16 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0static irqreturn_t ifcvf_intr_handler (int irq,void *arg) {struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +struct vring_info *vring; +int i; + +for (i =0 ; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; +if (vring->cb.callback)Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 59
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c +8
-0+ vf->vring->cb.callback (vring->cb.private); + } + +return IRQ_HANDLED ; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg)shared is not a good name given
IRQ_SHAREDis not set. maybe "common"? "reused"?Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 64
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+{ +struct ifcvf_hw *vf = arg; +u8 isr; + + isr =ifc_ioread8 (vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.Quoted 1 line
no,
vf->isris not set for VQ interrupts.I actually wonder what's the actual behaviour of IFCVF.
Quoted 8 lines
If need to actually poke
at the VQ to know.Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.It's a MSI, not INT#. So interrupt is not shared as such - it's only sharing vector between config and vq.
Right, I thought it was a shared one as
virito_pcidid.Quoted 224 lines
Quoted 224 lines
Quoted 87 lines
drivers/vdpa/ifcvf/ifcvf_main.c +57
-12+if (isr &VIRTIO_PCI_ISR_CONFIG ) +ifcvf_config_changed (irq, arg); + +return ifcvf_vq_shared_intr_handler (irq, arg); +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data); } -static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +static void ifcvf_free_vq_irq (struct ifcvf_adapter *adapter,int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf;int i; +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) { +for (i =0 ; i < queues; i++) { +devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL ; + } + }else { +devm_free_irq (&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL ; + } +} -for (i =0 ; i < queues; i++) { -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL ; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; + +/* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status != MSIX_VECTOR_DEV_SHARED +*/ +if (vf->msix_vector_status !=MSIX_VECTOR_DEV_SHARED ) { +devm_free_irq (&pdev->dev, vf->config_irq, vf); + vf->config_irq = -EINVAL ; } +} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ +struct pci_dev *pdev = adapter->pdev; -devm_free_irq (&pdev->dev, vf->config_irq, vf); +ifcvf_free_vq_irq (adapter, queues); +ifcvf_free_config_irq (adapter);ifcvf_free_irq_vectors (pdev); }@@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter)return ret; } -static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +static int ifcvf_request_per_vq_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, nvectors, i, ret, irq; -u16 max_intr; +int i, vector, ret, irq; - nvectors =ifcvf_alloc_vectors (adapter); -if (!(nvectors >0 )) -return nvectors; +for (i =0 ; i < vf->nr_vring; i++) { +snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" ,pci_name (pdev), i); + vector = i; + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_intr_handler,0 , + vf->vring[i].msix_name, + &vf->vring[i]); +if (ret) { +IFCVF_ERR (pdev,"Failed to request irq for vq %d\n" , i); +ifcvf_free_vq_irq (adapter, i); + }else { + vf->vring[i].irq = irq; +ifcvf_set_vq_vector (vf, i, vector); + } + } - max_intr = vf->nr_vring +1 ; + vf->vqs_shared_irq = -EINVAL ; + +return 0 ;drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 177
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */ I think we can remove this comment since the code is straightforward.
Quoted 109 lines
drivers/vdpa/ifcvf/ifcvf_main.c +81
-17+snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-vqs-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_vq_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); + +return ret; + } + + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + +return 0 ; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared device interrupt name */ +snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-dev-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_dev_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); - ret =pci_alloc_irq_vectors (pdev, max_intr, - max_intr,PCI_IRQ_MSIX ); -if (ret <0 ) { -IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" );return ret; } + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + + vf->config_irq = irq; +ifcvf_set_config_vector (vf, vector); + +return 0 ; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) + ret =ifcvf_request_per_vq_irq (adapter); +else + ret =ifcvf_request_shared_vq_irq (adapter); + +return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int config_vector, ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_DEV_SHARED ) +return 0 ; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) +/* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vector for config interrupt */ + config_vector = vf->nr_vring; + +if (vf->msix_vector_status ==MSIX_VECTOR_SHARED_VQ_AND_CONFIG ) +/* vector 0 for vqs and 1 for config interrupt */ + config_vector =1 ; +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" ,pci_name (pdev)); - vector =0 ; - vf->config_irq =pci_irq_vector (pdev, vector); + vf->config_irq =pci_irq_vector (pdev, config_vector); ret =devm_request_irq (&pdev->dev, vf->config_irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);if (ret) {IFCVF_ERR (pdev,"Failed to request config irq\n" ); +ifcvf_free_vq_irq (adapter, vf->nr_vring);return ret; } -for (i =0 ; i < vf->nr_vring; i++) { -snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" , -pci_name (pdev), i); - vector = i +IFCVF_MSI_QUEUE_OFF ; - irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, - ifcvf_intr_handler,0 , - vf->vring[i].msix_name, - &vf->vring[i]); -if (ret) { - IFCVF_ERR(pdev,drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-4- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq (adapter, i); +ifcvf_set_config_vector (vf, config_vector); -return ret; - } +return 0 ; +} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Quoted 4 lines
Quoted 2 lines
Thanks
Well it is claimed there are platforms where we are short on vectors. 3 versus 2 seems a 50% saving. You disagree?
I think we can 2 vectors (a dedicated for config).
Thanks
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
drivers/vdpa/ifcvf/ifcvf_main.c +29
-2+struct ifcvf_hw *vf = &adapter->vf; +int nvectors, ret, max_intr; - vf->vring[i].irq = irq; + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + + vf->msix_vector_status =MSIX_VECTOR_PER_VQ_AND_CONFIG ; + max_intr = vf->nr_vring +1 ; +if (nvectors < max_intr) + vf->msix_vector_status =MSIX_VECTOR_SHARED_VQ_AND_CONFIG ; + +if (nvectors ==1 ) { + vf->msix_vector_status =MSIX_VECTOR_DEV_SHARED ; + ret =ifcvf_request_dev_shared_irq (adapter); + +return ret; } + ret =ifcvf_request_vq_irq (adapter); +if (ret) +return ret; + + ret =ifcvf_request_config_irq (adapter); + +if (ret) +return ret; +return 0 ; }@@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct vdpa_device *vdpa_dev, {struct ifcvf_hw *vf =vdpa_to_vf (vdpa_dev); -return vf->vring[qid].irq; +if (vf->vqs_shared_irq <0 ) +return vf->vring[qid].irq; +else +return -EINVAL ; } static struct vdpa_notification_area ifcvf_get_vq_notification(struct vdpa_device *vdpa_dev,
Michael S. Tsirkin
maintainerQuoted 79 lines · Jason Wang
Quoted 62 lines · Michael S. Tsirkin
Quoted 50 lines · Jason Wang
Quoted 48 lines · Zhu Lingshan
On some platforms/devices, there may not be enough MSI vector slots allocated for virtqueues and config changes. In such a case, the interrupt
sources(virtqueues, config changes)must share an IRQ/vector, to avoid initialization failures, keep the device functional.This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1 (config changes), every virtqueue and the config interrupt has a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but greater than 1. In this case, all virtqueues share a vector/IRQ, the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and the config interrupt share a vector/IRQ. The worst and most unlikely case.Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector()andifcvf_set_config_vector()sets virtqueue vector and config vector in the device config space, so that the device can send interrupt DMA.This commit adds some fields in struct
ifcvf_hwand re-placed the existed fields to be aligned with the cacheline.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_base.c | 47 ++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 23 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 243 +++++++++++++++++++++++++++----- 3 files changed, 256 insertions(+), 57 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +7
-0@@ -15,6 +15,36 @@ struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) return container_of(hw, struct ifcvf_adapter, vf); } +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector) +{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + +ifc_iowrite16 (qid, &cfg->queue_select); +ifc_iowrite16 (vector, &cfg->queue_msix_vector);Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 28
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_base.c +4
-0+if (ifc_ioread16 (&cfg->queue_msix_vector) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for queue %u\n" , qid); +return -EINVAL ; + }Let's leave this check for the caller, E.g can caller try to assign
NO_VECTORduring uni-nit?Quoted 3 lines
Hmm I'm not sure I agree. Caller will have to write queue select again, and that's an extra IO, which is a waste.
And having function checking itself just seems better contained.It's as simple as just return what we read here like
virtio_pcidid:u16 vp_modern_queue_vector(struct
virtio_pci_modern_device*mdev,u16 index, u16 vector) { struct virtio_pci_common_cfg __iomem *cfg = mdev->common; vp_iowrite16(index, &cfg->queue_select); vp_iowrite16(vector, &cfg->queue_msix_vector); /* Flush the write out to device */ return vp_ioread16(&cfg->queue_msix_vector); }
Quoted 1 line
EXPORT_SYMBOL_GPL(vp_modern_queue_vector);
That would be ok.
Quoted 506 lines
Then the caller can decide to check it with
NO_VECTORif needed. Current code will break the callers that want to setNO_VECTOR.Quoted 89 lines
Quoted 79 lines
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_base.c +5
-0+ +return 0 ; +} + +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector)drivers/vdpa/ifcvf/ifcvf_base.c struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) · line 43
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_base.c +10
-0+{ +struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; +struct ifcvf_adapter *ifcvf =vf_to_adapter (hw); + + cfg = hw->common_cfg; +ifc_iowrite16 (vector, &cfg->msix_config); +if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { +IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); +return -EINVAL ; + }Similar question as above.
Quoted 57 lines
drivers/vdpa/ifcvf/ifcvf_base.c +6
-15+ +return 0 ; +} +static void __iomem *get_cap_addr (struct ifcvf_hw *hw,struct virtio_pci_cap *cap) {@@ -140,6 +170,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) hw->common_cfg, hw->notify_base, hw->isr, hw->dev_cfg, hw->notify_off_multiplier); + hw->vqs_shared_irq = -EINVAL ; +return 0 ; }@@ -321,12 +353,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw) ifcvf =vf_to_adapter (hw); cfg = hw->common_cfg; -ifc_iowrite16 (IFCVF_MSI_CONFIG_OFF , &cfg->msix_config); - -if (ifc_ioread16 (&cfg->msix_config) ==VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev,"No msix vector for device config\n" ); -return -EINVAL ; - }for (i =0 ; i < hw->nr_vring; i++) {if (!hw->vring[i].ready)@@ -340,15 +366,6 @@ static int ifcvf_hw_enable(struct ifcvf_hw *hw)ifc_iowrite64_twopart (hw->vring[i].used, &cfg->queue_used_lo, &cfg->queue_used_hi);ifc_iowrite16 (hw->vring[i].size, &cfg->queue_size); -ifc_iowrite16 (i +IFCVF_MSI_QUEUE_OFF , &cfg->queue_msix_vector); - -if (ifc_ioread16 (&cfg->queue_msix_vector) == -VIRTIO_MSI_NO_VECTOR ) { -IFCVF_ERR (ifcvf->pdev, -"No msix vector for queue %u\n" , i); -return -EINVAL ; - } -ifcvf_set_vq_state (hw, i, hw->vring[i].last_avail_idx);ifc_iowrite16 (1 , &cfg->queue_enable); }drivers/vdpa/ifcvf/ifcvf_base.h +2
-2@@ -27,8 +27,6 @@#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE#define IFCVF_QUEUE_MAX 32768 -#define IFCVF_MSI_CONFIG_OFF 0 -#define IFCVF_MSI_QUEUE_OFF 1#define IFCVF_PCI_MAX_RESOURCE 6#define IFCVF_LM_CFG_SIZE 0x40@@ -42,6 +40,13 @@#define ifcvf_private_to_vf (adapter) \ (&((struct ifcvf_adapter *)adapter)->vf) +/* all vqs and config interrupt has its own vector */ +#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_base.h line 48
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_base.h +4
-0+/* all vqs share a vector, and config interrupt has a separate vector */ +#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 +/* all vqs and config interrupt share a vector */ +#define MSIX_VECTOR_DEV_SHARED 3I think there's no much value to differ 2 from 3 consider config interrupt should be rare.
Quoted 2 lines
Yes but if we do not have a dedicated vector then we need an extra device IO (in fact, a read) on each interrupt.
Ok, right.
Quoted 114 lines
Quoted 92 lines
drivers/vdpa/ifcvf/ifcvf_base.h struct ifcvf_hw { · line 100
Quoted 11 lines
drivers/vdpa/ifcvf/ifcvf_base.h +1
-1+static inline u8 ifc_ioread8 (u8 __iomem *addr) {return ioread8 (addr);@@ -97,25 +102,27 @@ struct ifcvf_hw {u8 __iomem *isr;/* Live migration */ u8 __iomem *lm_cfg; -u16 nr_vring;Any reason for moving
nv_vring,config_size, and other stuffs?Quoted 39 lines
drivers/vdpa/ifcvf/ifcvf_base.h +9
-4/* Notification bar number */ u8 notify_bar; +u8 msix_vector_status; +/* virtio-net or virtio-blk device config size */ +u32 config_size;/* Notificaiton bar address */ void __iomem *notify_base;phys_addr_t notify_base_pa;u32 notify_off_multiplier; +u32 dev_type;u64 req_features;u64 hw_features; -u32 dev_type;struct virtio_pci_common_cfg __iomem *common_cfg;void __iomem *dev_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];void __iomem *const *base;char config_msix_name[256 ];struct vdpa_callback config_cb; -unsigned int config_irq; -/* virtio-net or virtio-blk device config size */ -u32 config_size; +int config_irq; +int vqs_shared_irq; +u16 nr_vring; };struct ifcvf_adapter {@@ -160,4 +167,6 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);struct ifcvf_adapter *vf_to_adapter (struct ifcvf_hw *hw);int ifcvf_probed_virtio_net (struct ifcvf_hw *hw);u32 ifcvf_get_config_size (struct ifcvf_hw *hw); +int ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector); +int ifcvf_set_config_vector (struct ifcvf_hw *hw,int vector);#endif /* _IFCVF_H_ */ drivers/vdpa/ifcvf/ifcvf_main.c +0
-0drivers/vdpa/ifcvf/ifcvf_main.c line 19
Quoted 3 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0@@ -17,6 +17,7 @@#define DRIVER_AUTHOR "Intel Corporation"#define IFCVF_DRIVER_NAME "ifcvf" +/* handles config interrupt */ This seems unrelated to the shared IRQ logic and it looks useless since it's easily to deduce it from the function name below.
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_config_changed(int irq, void *arg) · line 30
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0static irqreturn_t ifcvf_config_changed (int irq,void *arg) {struct ifcvf_hw *vf = arg;@@ -27,6 +28,7 @@ static irqreturn_t ifcvf_config_changed(int irq, void *arg)return IRQ_HANDLED ; } +/* handles vqs interrupt */ So did this.
Quoted 16 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0static irqreturn_t ifcvf_intr_handler (int irq,void *arg) {struct vring_info *vring = arg;@@ -37,24 +39,78 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +/* handls vqs shared interrupt */ +static irqreturn_t ifcvf_vq_shared_intr_handler (int irq,void *arg) +{ +struct ifcvf_hw *vf = arg; +struct vring_info *vring; +int i; + +for (i =0 ; i < vf->nr_vring; i++) { + vring = &vf->vring[i]; +if (vring->cb.callback)Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 59
Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c +8
-0+ vf->vring->cb.callback (vring->cb.private); + } + +return IRQ_HANDLED ; +} + +/* handles a shared interrupt for vqs and config */ +static irqreturn_t ifcvf_dev_shared_intr_handler (int irq,void *arg)shared is not a good name given
IRQ_SHAREDis not set. maybe "common"? "reused"?Quoted 9 lines
drivers/vdpa/ifcvf/ifcvf_main.c static irqreturn_t ifcvf_intr_handler(int irq, void *arg) · line 64
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_main.c +5
-0+{ +struct ifcvf_hw *vf = arg; +u8 isr; + + isr =ifc_ioread8 (vf->isr);We need to exactly what
vp_interruptdo here. Checking againstvf->isrfirst and returnIRQ_NONEif it is not set.Quoted 1 line
no,
vf->isris not set for VQ interrupts.I actually wonder what's the actual behaviour of IFCVF.
Quoted 9 lines
If need to actually poke
at the VQ to know.Quoted 2 lines
Always return
IRQ_HANDLEDwill break the device who shares an irq with IFCVF.It's a MSI, not INT#. So interrupt is not shared as such - it's only sharing vector between config and vq.
Right, I thought it was a shared one as
virito_pcidid.Quoted 228 lines
Quoted 228 lines
Quoted 89 lines
drivers/vdpa/ifcvf/ifcvf_main.c +57
-12+if (isr &VIRTIO_PCI_ISR_CONFIG ) +ifcvf_config_changed (irq, arg); + +return ifcvf_vq_shared_intr_handler (irq, arg); +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data); } -static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +static void ifcvf_free_vq_irq (struct ifcvf_adapter *adapter,int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf;int i; +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) { +for (i =0 ; i < queues; i++) { +devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vf->vring[i].irq = -EINVAL ; + } + }else { +devm_free_irq (&pdev->dev, vf->vqs_shared_irq, vf); + vf->vqs_shared_irq = -EINVAL ; + } +} -for (i =0 ; i < queues; i++) { -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); - vf->vring[i].irq = -EINVAL ; +static void ifcvf_free_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; + +/* If the irq is shared by all vqs and the config interrupt, +* it is already freed in ifcvf_free_vq_irq, so here only +* need to free config irq when msix_vector_status != MSIX_VECTOR_DEV_SHARED +*/ +if (vf->msix_vector_status !=MSIX_VECTOR_DEV_SHARED ) { +devm_free_irq (&pdev->dev, vf->config_irq, vf); + vf->config_irq = -EINVAL ; } +} + +static void ifcvf_free_irq (struct ifcvf_adapter *adapter,int queues) +{ +struct pci_dev *pdev = adapter->pdev; -devm_free_irq (&pdev->dev, vf->config_irq, vf); +ifcvf_free_vq_irq (adapter, queues); +ifcvf_free_config_irq (adapter);ifcvf_free_irq_vectors (pdev); }@@ -86,58 +142,172 @@ static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter)return ret; } -static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +static int ifcvf_request_per_vq_irq (struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; -int vector, nvectors, i, ret, irq; -u16 max_intr; +int i, vector, ret, irq; - nvectors =ifcvf_alloc_vectors (adapter); -if (!(nvectors >0 )) -return nvectors; +for (i =0 ; i < vf->nr_vring; i++) { +snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" ,pci_name (pdev), i); + vector = i; + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_intr_handler,0 , + vf->vring[i].msix_name, + &vf->vring[i]); +if (ret) { +IFCVF_ERR (pdev,"Failed to request irq for vq %d\n" , i); +ifcvf_free_vq_irq (adapter, i); + }else { + vf->vring[i].irq = irq; +ifcvf_set_vq_vector (vf, i, vector); + } + } - max_intr = vf->nr_vring +1 ; + vf->vqs_shared_irq = -EINVAL ; + +return 0 ;drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 177
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +10
-0+} + +static int ifcvf_request_shared_vq_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared vqs interrupt name */ I think we can remove this comment since the code is straightforward.
Quoted 109 lines
drivers/vdpa/ifcvf/ifcvf_main.c +81
-17+snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-vqs-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_vq_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); + +return ret; + } + + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + +return 0 ; + +} + +static int ifcvf_request_dev_shared_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int i, vector, ret, irq; + + vector =0 ; +/* reuse msix_name[256] space of vring0 to store shared device interrupt name */ +snprintf (vf->vring[0 ].msix_name,256 ,"ifcvf[%s]-dev-shared-irq\n" ,pci_name (pdev)); + irq =pci_irq_vector (pdev, vector); + ret =devm_request_irq (&pdev->dev, irq, + ifcvf_dev_shared_intr_handler,0 , + vf->vring[0 ].msix_name, vf); +if (ret) { +IFCVF_ERR (pdev,"Failed to request shared irq for vf\n" ); - ret =pci_alloc_irq_vectors (pdev, max_intr, - max_intr,PCI_IRQ_MSIX ); -if (ret <0 ) { -IFCVF_ERR (pdev,"Failed to alloc IRQ vectors\n" );return ret; } + vf->vqs_shared_irq = irq; +for (i =0 ; i < vf->nr_vring; i++) { + vf->vring[i].irq = -EINVAL ; +ifcvf_set_vq_vector (vf, i, vector); + } + + vf->config_irq = irq; +ifcvf_set_config_vector (vf, vector); + +return 0 ; + +} + +static int ifcvf_request_vq_irq (struct ifcvf_adapter *adapter) +{ +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) + ret =ifcvf_request_per_vq_irq (adapter); +else + ret =ifcvf_request_shared_vq_irq (adapter); + +return ret; +} + +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int config_vector, ret; + +if (vf->msix_vector_status ==MSIX_VECTOR_DEV_SHARED ) +return 0 ; + +if (vf->msix_vector_status ==MSIX_VECTOR_PER_VQ_AND_CONFIG ) +/* vector 0 ~ vf->nr_vring for vqs, num vf->nr_vring vector for config interrupt */ + config_vector = vf->nr_vring; + +if (vf->msix_vector_status ==MSIX_VECTOR_SHARED_VQ_AND_CONFIG ) +/* vector 0 for vqs and 1 for config interrupt */ + config_vector =1 ; +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" ,pci_name (pdev)); - vector =0 ; - vf->config_irq =pci_irq_vector (pdev, vector); + vf->config_irq =pci_irq_vector (pdev, config_vector); ret =devm_request_irq (&pdev->dev, vf->config_irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);if (ret) {IFCVF_ERR (pdev,"Failed to request config irq\n" ); +ifcvf_free_vq_irq (adapter, vf->nr_vring);return ret; } -for (i =0 ; i < vf->nr_vring; i++) { -snprintf (vf->vring[i].msix_name,256 ,"ifcvf[%s]-%d\n" , -pci_name (pdev), i); - vector = i +IFCVF_MSI_QUEUE_OFF ; - irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, - ifcvf_intr_handler,0 , - vf->vring[i].msix_name, - &vf->vring[i]); -if (ret) { - IFCVF_ERR(pdev,drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) · line 282
Quoted 10 lines
drivers/vdpa/ifcvf/ifcvf_main.c +6
-4- "Failed to request irq for vq %d\n", i); -ifcvf_free_irq (adapter, i); +ifcvf_set_config_vector (vf, config_vector); -return ret; - } +return 0 ; +} + +static int ifcvf_request_irq (struct ifcvf_adapter *adapter) +{As replied above, I think having two modes should be sufficient and the code could be greatly simplified.
Quoted 5 lines
Quoted 2 lines
Thanks
Well it is claimed there are platforms where we are short on vectors. 3 versus 2 seems a 50% saving. You disagree?
I think we can 2 vectors (a dedicated for config).
Thanks
Quoted 41 lines
Quoted 40 lines
Quoted 40 lines
drivers/vdpa/ifcvf/ifcvf_main.c +29
-2+struct ifcvf_hw *vf = &adapter->vf; +int nvectors, ret, max_intr; - vf->vring[i].irq = irq; + nvectors =ifcvf_alloc_vectors (adapter); +if (!(nvectors >0 )) +return nvectors; + + vf->msix_vector_status =MSIX_VECTOR_PER_VQ_AND_CONFIG ; + max_intr = vf->nr_vring +1 ; +if (nvectors < max_intr) + vf->msix_vector_status =MSIX_VECTOR_SHARED_VQ_AND_CONFIG ; + +if (nvectors ==1 ) { + vf->msix_vector_status =MSIX_VECTOR_DEV_SHARED ; + ret =ifcvf_request_dev_shared_irq (adapter); + +return ret; } + ret =ifcvf_request_vq_irq (adapter); +if (ret) +return ret; + + ret =ifcvf_request_config_irq (adapter); + +if (ret) +return ret; +return 0 ; }@@ -441,7 +611,10 @@ static int ifcvf_vdpa_get_vq_irq(struct vdpa_device *vdpa_dev, {struct ifcvf_hw *vf =vdpa_to_vf (vdpa_dev); -return vf->vring[qid].irq; +if (vf->vqs_shared_irq <0 ) +return vf->vring[qid].irq; +else +return -EINVAL ; } static struct vdpa_notification_area ifcvf_get_vq_notification(struct vdpa_device *vdpa_dev,