Supoort shared irq for virtqueues
cover Supoort shared irq for virtqueues
On some platforms, it has been observed that a device may fail to allocate enough MSI-X vectors, under such circumstances, the vqs have to share a irq/vector.
This series extends irq requester/handlers abilities to deal with:
(granted nvectors, and max_intr = total vq number + 1(config interrupt) )
1)nvectors = max_intr: each vq has its own vector/irq,
config interrupt is enabled, normal case
2)max_intr > nvectors >= 2: vqs share one irq/vector, config interrupt is enabled
3)nvectors = 1, vqs share one irq/vector, config interrupt is disabled. Otherwise it fails.
This series also made necessary changes to irq cleaners and related helpers.
Pleaase help reivew.
Thanks!
Zhu Lingshan
Zhu Lingshan (7):
vDPA/ifcvf: implement IO read/write helpers in the header file vDPA/ifcvf: introduce new helpers to set config vector and vq vectors vDPA/ifcvf: implement device MSIX vector allocation helper vDPA/ifcvf: implement shared irq handlers for vqs vDPA/ifcvf: irq request helpers for both shared and per_vq irq vDPA/ifcvf: implement config interrupt request helper vDPA/ifcvf: improve irq requester, to handle per_vq/shared/config irq
drivers/vdpa/ifcvf/ifcvf_base.c | 65 ++++-------- drivers/vdpa/ifcvf/ifcvf_base.h | 45 +++++++- drivers/vdpa/ifcvf/ifcvf_main.c | 179 +++++++++++++++++++++++++++----- 3 files changed, 215 insertions(+), 74 deletions(-)
Signature · 1 line
2.27.0
PATCH 1/7 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
PATCH 2/7 vDPA/ifcvf: introduce new helpers to set config vector and vq vectors
In reply to Zhu LingshanThis commit introduces new helpers to set config vector and vq vectors in virtio common config space.
--- drivers/vdpa/ifcvf/ifcvf_base.c | 30 ++++++++++++++++++++++++++++++ drivers/vdpa/ifcvf/ifcvf_base.h | 2 ++ 2 files changed, 32 insertions(+)
drivers/vdpa/ifcvf/ifcvf_base.c +30 -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) ==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) {
drivers/vdpa/ifcvf/ifcvf_base.h +2 -0
@@ -157,4 +157,6 @@ u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);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); +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_ */
Signature · 1 line
2.27.0
PATCH 3/7 vDPA/ifcvf: implement device MSIX vector allocation helper
In reply to Zhu LingshanThis commit implements a MSIX vector allocation helper
--- drivers/vdpa/ifcvf/ifcvf_main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/vdpa/ifcvf/ifcvf_main.c +24 -0
@@ -58,6 +58,30 @@ static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues)ifcvf_free_irq_vectors (pdev); } +static int ifcvf_alloc_vectors (struct ifcvf_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +u16 max_intr =0 ; +u16 ret =0 ; + +/* 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;
Signature · 1 line
2.27.0
PATCH 4/7 vDPA/ifcvf: implement shared irq handlers for vqs
In reply to Zhu LingshanIt has observed that a device may fail to alloc enough vectors on some platforms, e.g., requires 16 vectors, but only 2 or 4 vector slots allocated. The virt queues have to share a vector/irq under such circumstances.
This irq handlers has to kick every queue because it is not possible to tell which queue triggers the interrupt.
--- drivers/vdpa/ifcvf/ifcvf_main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/vdpa/ifcvf/ifcvf_main.c +15 -0
@@ -37,6 +37,21 @@ static irqreturn_t ifcvf_intr_handler(int irq, void *arg)return IRQ_HANDLED ; } +static irqreturn_t ifcvf_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); + } + +return IRQ_HANDLED ; +} +static void ifcvf_free_irq_vectors (void *data) {pci_free_irq_vectors (data);
Signature · 1 line
2.27.0
PATCH 5/7 vDPA/ifcvf: irq request helpers for both shared and per_vq irq
In reply to Zhu LingshanThis commit implements new irq request helpers:ifcvf_request_shared_vq_irq() for a shared irq, in this case, all virtqueues would share one irq/vector. This can help the device work on some platforms that can not provide enough MSIX vectors
ifcvf_request_per_vq_irq() for per vq irqs, in this case, every virtqueue has its own irq/vector
ifcvf_request_vq_irq() calls either of the above two, depends on the number of allocated vectors.
--- drivers/vdpa/ifcvf/ifcvf_base.c | 9 ----- drivers/vdpa/ifcvf/ifcvf_main.c | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 9 deletions(-)
drivers/vdpa/ifcvf/ifcvf_base.c +0 -9
@@ -349,15 +349,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_main.c +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH 6/7 vDPA/ifcvf: implement config interrupt request helper
In reply to Zhu LingshanThis commit implements new helper to request config interrupt by a given MSIX vector.
--- drivers/vdpa/ifcvf/ifcvf_base.c | 6 ------ drivers/vdpa/ifcvf/ifcvf_main.c | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-)
drivers/vdpa/ifcvf/ifcvf_base.c +0 -6
@@ -330,12 +330,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_main.c +26 -0
@@ -162,6 +162,32 @@ static int ifcvf_request_vq_irq(struct ifcvf_adapter *adapter, u8 vector_per_vq)return ret; } +static int ifcvf_request_config_irq (struct ifcvf_adapter *adapter,int config_vector) +{ +struct pci_dev *pdev = adapter->pdev; +struct ifcvf_hw *vf = &adapter->vf; +int ret; + +if (!config_vector) { +IFCVF_INFO (pdev,"No config interrupt because of no vectors\n" ); + vf->config_irq = -EINVAL ; +return 0 ; + } + +snprintf (vf->config_msix_name,256 ,"ifcvf[%s]-config\n" , +pci_name (pdev)); + 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" ); +return ret; + } +ifcvf_set_config_vector (vf, config_vector); + +return 0 ; +}static int ifcvf_request_irq (struct ifcvf_adapter *adapter) {
Signature · 1 line
2.27.0
PATCH 7/7 vDPA/ifcvf: improve irq requester, to handle per_vq/shared/config irq
In reply to Zhu LingshanThis commit expends irq requester abilities to handle per vq irq, shared irq and config irq.
On some platforms, the device can not get enough vectors for every virtqueue and config interrupt, the device needs to work under such circumstances.
Normally a device can get enough vectors, so every virtqueue and config interrupt can have its own vector/irq. If the total vector number is less than all virtqueues + 1(config interrupt), all virtqueues need to share a vector/irq and config interrupt is enabled. If the total vector number < 2, all vitequeues share a vector/irq, and config interrupt is disabled. Otherwise it will fail if allocation for vectors fails.
This commit also made necessary chages to the irq cleaner to free per vq irq/shared irq and config irq.
--- drivers/vdpa/ifcvf/ifcvf_base.h | 6 +-- drivers/vdpa/ifcvf/ifcvf_main.c | 78 +++++++++++++++------------------ 2 files changed, 38 insertions(+), 46 deletions(-)
drivers/vdpa/ifcvf/ifcvf_base.h +3 -3
@@ -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
@@ -102,11 +100,13 @@ struct ifcvf_hw {u8 notify_bar;/* Notificaiton bar address */ void __iomem *notify_base; +u8 vector_per_vq; +u16 padding;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 *net_cfg;struct vring_info vring[IFCVF_MAX_QUEUES ];
drivers/vdpa/ifcvf/ifcvf_main.c +35 -43
113 lines not on this page · raw message
Signature · 1 line
2.27.0