Commit 63273cb4 authored by Long Li's avatar Long Li Committed by Martin K. Petersen

scsi: vmbus: Add function to report available ring buffer to write in total ring size percentage

Netvsc has a function to calculate how much ring buffer in percentage is
available to write. This function is also useful for storvsc and other
vmbus devices.

Define a similar function in vmbus to be used by other vmbus devices.
Signed-off-by: default avatarLong Li <longli@microsoft.com>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent b6240a4d
...@@ -227,6 +227,8 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, ...@@ -227,6 +227,8 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info,
ring_info->ring_buffer->feature_bits.value = 1; ring_info->ring_buffer->feature_bits.value = 1;
ring_info->ring_size = page_cnt << PAGE_SHIFT; ring_info->ring_size = page_cnt << PAGE_SHIFT;
ring_info->ring_size_div10_reciprocal =
reciprocal_value(ring_info->ring_size / 10);
ring_info->ring_datasize = ring_info->ring_size - ring_info->ring_datasize = ring_info->ring_size -
sizeof(struct hv_ring_buffer); sizeof(struct hv_ring_buffer);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/reciprocal_div.h>
#define MAX_PAGE_BUFFER_COUNT 32 #define MAX_PAGE_BUFFER_COUNT 32
#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */ #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
...@@ -120,6 +121,7 @@ struct hv_ring_buffer { ...@@ -120,6 +121,7 @@ struct hv_ring_buffer {
struct hv_ring_buffer_info { struct hv_ring_buffer_info {
struct hv_ring_buffer *ring_buffer; struct hv_ring_buffer *ring_buffer;
u32 ring_size; /* Include the shared header */ u32 ring_size; /* Include the shared header */
struct reciprocal_value ring_size_div10_reciprocal;
spinlock_t ring_lock; spinlock_t ring_lock;
u32 ring_datasize; /* < ring_size */ u32 ring_datasize; /* < ring_size */
...@@ -154,6 +156,16 @@ static inline u32 hv_get_bytes_to_write(const struct hv_ring_buffer_info *rbi) ...@@ -154,6 +156,16 @@ static inline u32 hv_get_bytes_to_write(const struct hv_ring_buffer_info *rbi)
return write; return write;
} }
static inline u32 hv_get_avail_to_write_percent(
const struct hv_ring_buffer_info *rbi)
{
u32 avail_write = hv_get_bytes_to_write(rbi);
return reciprocal_divide(
(avail_write << 3) + (avail_write << 1),
rbi->ring_size_div10_reciprocal);
}
/* /*
* VMBUS version is 32 bit entity broken up into * VMBUS version is 32 bit entity broken up into
* two 16 bit quantities: major_number. minor_number. * two 16 bit quantities: major_number. minor_number.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment