Skip to content

Commit 2ddae77

Browse files
Zhu Lingshanmstsirkin
authored andcommitted
vDPA/ifcvf: detect and use the onboard number of queues directly
To enable this multi-queue feature for ifcvf, this commit intends to detect and use the onboard number of queues directly than IFCVF_MAX_QUEUE_PAIRS = 1 (removed) Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> Link: https://lore.kernel.org/r/20210818095714.3220-2-lingshan.zhu@intel.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 6b5df34 commit 2ddae77

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

drivers/vdpa/ifcvf/ifcvf_base.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev)
158158
return -EIO;
159159
}
160160

161-
for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++) {
161+
hw->nr_vring = ifc_ioread16(&hw->common_cfg->num_queues);
162+
163+
for (i = 0; i < hw->nr_vring; i++) {
162164
ifc_iowrite16(i, &hw->common_cfg->queue_select);
163165
notify_off = ifc_ioread16(&hw->common_cfg->queue_notify_off);
164166
hw->vring[i].notify_addr = hw->notify_base +
@@ -304,7 +306,7 @@ u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid)
304306
u32 q_pair_id;
305307

306308
ifcvf_lm = (struct ifcvf_lm_cfg __iomem *)hw->lm_cfg;
307-
q_pair_id = qid / (IFCVF_MAX_QUEUE_PAIRS * 2);
309+
q_pair_id = qid / hw->nr_vring;
308310
avail_idx_addr = &ifcvf_lm->vring_lm_cfg[q_pair_id].idx_addr[qid % 2];
309311
last_avail_idx = ifc_ioread16(avail_idx_addr);
310312

@@ -318,7 +320,7 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num)
318320
u32 q_pair_id;
319321

320322
ifcvf_lm = (struct ifcvf_lm_cfg __iomem *)hw->lm_cfg;
321-
q_pair_id = qid / (IFCVF_MAX_QUEUE_PAIRS * 2);
323+
q_pair_id = qid / hw->nr_vring;
322324
avail_idx_addr = &ifcvf_lm->vring_lm_cfg[q_pair_id].idx_addr[qid % 2];
323325
hw->vring[qid].last_avail_idx = num;
324326
ifc_iowrite16(num, avail_idx_addr);

drivers/vdpa/ifcvf/ifcvf_base.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
(1ULL << VIRTIO_F_ACCESS_PLATFORM) | \
3232
(1ULL << VIRTIO_NET_F_MRG_RXBUF))
3333

34-
/* Only one queue pair for now. */
35-
#define IFCVF_MAX_QUEUE_PAIRS 1
34+
/* Max 8 data queue pairs(16 queues) and one control vq for now. */
35+
#define IFCVF_MAX_QUEUES 17
3636

3737
#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE
3838
#define IFCVF_QUEUE_MAX 32768
@@ -51,8 +51,6 @@
5151
#define ifcvf_private_to_vf(adapter) \
5252
(&((struct ifcvf_adapter *)adapter)->vf)
5353

54-
#define IFCVF_MAX_INTR (IFCVF_MAX_QUEUE_PAIRS * 2 + 1)
55-
5654
struct vring_info {
5755
u64 desc;
5856
u64 avail;
@@ -83,7 +81,7 @@ struct ifcvf_hw {
8381
u32 dev_type;
8482
struct virtio_pci_common_cfg __iomem *common_cfg;
8583
void __iomem *net_cfg;
86-
struct vring_info vring[IFCVF_MAX_QUEUE_PAIRS * 2];
84+
struct vring_info vring[IFCVF_MAX_QUEUES];
8785
void __iomem * const *base;
8886
char config_msix_name[256];
8987
struct vdpa_callback config_cb;
@@ -103,7 +101,7 @@ struct ifcvf_vring_lm_cfg {
103101

104102
struct ifcvf_lm_cfg {
105103
u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
106-
struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUE_PAIRS];
104+
struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUES];
107105
};
108106

109107
struct ifcvf_vdpa_mgmt_dev {

drivers/vdpa/ifcvf/ifcvf_main.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter)
6363
struct pci_dev *pdev = adapter->pdev;
6464
struct ifcvf_hw *vf = &adapter->vf;
6565
int vector, i, ret, irq;
66+
u16 max_intr;
6667

67-
ret = pci_alloc_irq_vectors(pdev, IFCVF_MAX_INTR,
68-
IFCVF_MAX_INTR, PCI_IRQ_MSIX);
68+
/* all queues and config interrupt */
69+
max_intr = vf->nr_vring + 1;
70+
71+
ret = pci_alloc_irq_vectors(pdev, max_intr,
72+
max_intr, PCI_IRQ_MSIX);
6973
if (ret < 0) {
7074
IFCVF_ERR(pdev, "Failed to alloc IRQ vectors\n");
7175
return ret;
@@ -83,7 +87,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter)
8387
return ret;
8488
}
8589

86-
for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++) {
90+
for (i = 0; i < vf->nr_vring; i++) {
8791
snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n",
8892
pci_name(pdev), i);
8993
vector = i + IFCVF_MSI_QUEUE_OFF;
@@ -112,7 +116,6 @@ static int ifcvf_start_datapath(void *private)
112116
u8 status;
113117
int ret;
114118

115-
vf->nr_vring = IFCVF_MAX_QUEUE_PAIRS * 2;
116119
ret = ifcvf_start_hw(vf);
117120
if (ret < 0) {
118121
status = ifcvf_get_status(vf);
@@ -128,7 +131,7 @@ static int ifcvf_stop_datapath(void *private)
128131
struct ifcvf_hw *vf = ifcvf_private_to_vf(private);
129132
int i;
130133

131-
for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++)
134+
for (i = 0; i < vf->nr_vring; i++)
132135
vf->vring[i].cb.callback = NULL;
133136

134137
ifcvf_stop_hw(vf);
@@ -141,7 +144,7 @@ static void ifcvf_reset_vring(struct ifcvf_adapter *adapter)
141144
struct ifcvf_hw *vf = ifcvf_private_to_vf(adapter);
142145
int i;
143146

144-
for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++) {
147+
for (i = 0; i < vf->nr_vring; i++) {
145148
vf->vring[i].last_avail_idx = 0;
146149
vf->vring[i].desc = 0;
147150
vf->vring[i].avail = 0;
@@ -227,7 +230,7 @@ static void ifcvf_vdpa_set_status(struct vdpa_device *vdpa_dev, u8 status)
227230
if ((status_old & VIRTIO_CONFIG_S_DRIVER_OK) &&
228231
!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
229232
ifcvf_stop_datapath(adapter);
230-
ifcvf_free_irq(adapter, IFCVF_MAX_QUEUE_PAIRS * 2);
233+
ifcvf_free_irq(adapter, vf->nr_vring);
231234
}
232235

233236
if (status == 0) {
@@ -526,13 +529,13 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
526529
goto err;
527530
}
528531

529-
for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++)
532+
for (i = 0; i < vf->nr_vring; i++)
530533
vf->vring[i].irq = -EINVAL;
531534

532535
vf->hw_features = ifcvf_get_hw_features(vf);
533536

534537
adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev;
535-
ret = _vdpa_register_device(&adapter->vdpa, IFCVF_MAX_QUEUE_PAIRS * 2);
538+
ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring);
536539
if (ret) {
537540
IFCVF_ERR(pdev, "Failed to register to vDPA bus");
538541
goto err;

0 commit comments

Comments
 (0)