[SLOF] [PATCH v2 13/19] virtio: make all virtio apis 1.0 aware

Nikunj A Dadhania nikunj at linux.vnet.ibm.com
Fri Jan 22 16:26:40 AEDT 2016


Alexey Kardashevskiy <aik at ozlabs.ru> writes:

> On 01/20/2016 11:10 PM, Nikunj A Dadhania wrote:
>> Convert the following routines:
>>      virtio_get_qsize
>>      virtio_vring_desc
>>      virtio_get_vring_avail
>>      virtio_get_vring_used
>>      virtio_set_status: also use it in device reset.
>>      virtio_queue_notify
>>      virtio_set_qaddr
>>      virtio_{get,read}_config
>>      virtio_fill_desc
>>
>> Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
>> ---
>>   lib/libvirtio/virtio.c | 127 +++++++++++++++++++++++++++++++++++++++++--------
>>   lib/libvirtio/virtio.h |   2 +-
>>   2 files changed, 108 insertions(+), 21 deletions(-)
>>
>> diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c
>> index 1331efd..c2dd7dc 100644
>> --- a/lib/libvirtio/virtio.c
>> +++ b/lib/libvirtio/virtio.c
>> @@ -94,11 +94,20 @@ unsigned long virtio_vring_size(unsigned int qsize)
>>    * @param   queue virtio queue number
>>    * @return  number of elements
>>    */
>> -int virtio_get_qsize(struct virtio_device *dev, int queue)
>> +unsigned int virtio_get_qsize(struct virtio_device *dev, int queue)
>>   {
>> -	int size = 0;
>> +	unsigned int size = 0;
>>
>> -	if (dev->type == VIRTIO_TYPE_PCI) {
>> +	if (dev->type != VIRTIO_TYPE_PCI)
>> +		return 0;
>> +	if (dev->is_modern) {
>> +		void *addr = dev->common.addr + offset_of(struct virtio_dev_common, q_select);
>> +		ci_write_16(addr, cpu_to_le16(queue));
>> +		eieio();
>> +		/* read qsize */
>
> addr = dev->common.addr + offset_of(struct virtio_dev_common, q_size);

I understand, the code was just for optimization, rather than to
re-compute.

>
>
>> +		size = le16_to_cpu(ci_read_16(addr + 2));
>
>
> size = le16_to_cpu(ci_read_16(addr));
>
> as the legacy code uses VIRTIOHDR_QUEUE_SELECT and VIRTIOHDR_QUEUE_SIZE, 
> not magic constant, like you have it done in virtio_get_vring_desc() and 
> other places.

Sure.

>> @@ -193,7 +232,20 @@ void virtio_reset_device(struct virtio_device *dev)
>>    */
>>   void virtio_queue_notify(struct virtio_device *dev, int queue)
>>   {
>> -	if (dev->type == VIRTIO_TYPE_PCI) {
>> +	if (dev->type != VIRTIO_TYPE_PCI)
>> +		return;
>> +	if (dev->is_modern) {
>> +		void *q_sel = dev->common.addr + offset_of(struct virtio_dev_common, q_select);
>> +		void *q_ntfy = dev->common.addr + offset_of(struct virtio_dev_common, q_notify_off);
>> +		void *addr;
>> +		uint16_t q_notify_off = 0;
>
> Redundant "= 0".

Will remove.

Regards
Nikunj



More information about the SLOF mailing list