Skip to content

Commit ae904d9

Browse files
Zhu Lingshanmstsirkin
authored andcommitted
vDPA/ifcvf: detect and report max allowed vq size
Rather than a hardcode, this commit detects and reports the max value of allowed size of the virtqueues Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> Message-Id: <20230612151420.1019504-3-lingshan.zhu@intel.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 7712832 commit ae904d9

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

drivers/vdpa/ifcvf/ifcvf_base.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,37 @@ static int ifcvf_read_config_range(struct pci_dev *dev,
6969
return 0;
7070
}
7171

72+
static u16 ifcvf_get_vq_size(struct ifcvf_hw *hw, u16 qid)
73+
{
74+
u16 queue_size;
75+
76+
vp_iowrite16(qid, &hw->common_cfg->queue_select);
77+
queue_size = vp_ioread16(&hw->common_cfg->queue_size);
78+
79+
return queue_size;
80+
}
81+
82+
/* This function returns the max allowed safe size for
83+
* all virtqueues. It is the minimal size that can be
84+
* suppprted by all virtqueues.
85+
*/
86+
u16 ifcvf_get_max_vq_size(struct ifcvf_hw *hw)
87+
{
88+
u16 queue_size, max_size, qid;
89+
90+
max_size = ifcvf_get_vq_size(hw, 0);
91+
for (qid = 1; qid < hw->nr_vring; qid++) {
92+
queue_size = ifcvf_get_vq_size(hw, qid);
93+
/* 0 means the queue is unavailable */
94+
if (!queue_size)
95+
continue;
96+
97+
max_size = min(queue_size, max_size);
98+
}
99+
100+
return max_size;
101+
}
102+
72103
int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev)
73104
{
74105
struct virtio_pci_cap cap;

drivers/vdpa/ifcvf/ifcvf_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#define IFCVF_MAX_QUEUES 17
2929

3030
#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE
31-
#define IFCVF_QUEUE_MAX 32768
3231
#define IFCVF_PCI_MAX_RESOURCE 6
3332

3433
#define IFCVF_LM_CFG_SIZE 0x40
@@ -138,4 +137,5 @@ bool ifcvf_get_vq_ready(struct ifcvf_hw *hw, u16 qid);
138137
void ifcvf_set_vq_ready(struct ifcvf_hw *hw, u16 qid, bool ready);
139138
void ifcvf_set_driver_features(struct ifcvf_hw *hw, u64 features);
140139
u64 ifcvf_get_driver_features(struct ifcvf_hw *hw);
140+
u16 ifcvf_get_max_vq_size(struct ifcvf_hw *hw);
141141
#endif /* _IFCVF_H_ */

drivers/vdpa/ifcvf/ifcvf_main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ static int ifcvf_vdpa_reset(struct vdpa_device *vdpa_dev)
451451

452452
static u16 ifcvf_vdpa_get_vq_num_max(struct vdpa_device *vdpa_dev)
453453
{
454-
return IFCVF_QUEUE_MAX;
454+
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
455+
456+
return ifcvf_get_max_vq_size(vf);
455457
}
456458

457459
static int ifcvf_vdpa_get_vq_state(struct vdpa_device *vdpa_dev, u16 qid,

0 commit comments

Comments
 (0)