Skip to content

Commit 98f4c65

Browse files
committed
hv: move ringbuffer bus attributes to dev_groups
This moves the ringbuffer bus attributes to the dev_groups structure, deletes the now unneeded struct hv_device_info, and removes some now unused functions, and variables as everything is now moved to the dev_groups structure, dev_attrs is no longer needed. Tested-by: "K. Y. Srinivasan" <kys@microsoft.com> Cc: Haiyang Zhang <haiyangz@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1fdde16 commit 98f4c65

File tree

1 file changed

+146
-84
lines changed

1 file changed

+146
-84
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 146 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ static struct tasklet_struct msg_dpc;
4646
static struct completion probe_event;
4747
static int irq;
4848

49-
struct hv_device_info {
50-
struct hv_ring_buffer_debug_info inbound;
51-
struct hv_ring_buffer_debug_info outbound;
52-
};
53-
5449
static int vmbus_exists(void)
5550
{
5651
if (hv_acpi_dev == NULL)
@@ -59,17 +54,6 @@ static int vmbus_exists(void)
5954
return 0;
6055
}
6156

62-
63-
static void get_channel_info(struct hv_device *device,
64-
struct hv_device_info *info)
65-
{
66-
if (!device->channel)
67-
return;
68-
69-
hv_ringbuffer_get_debuginfo(&device->channel->inbound, &info->inbound);
70-
hv_ringbuffer_get_debuginfo(&device->channel->outbound, &info->outbound);
71-
}
72-
7357
#define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)->guid) * 2)
7458
static void print_alias_name(struct hv_device *hv_dev, char *alias_name)
7559
{
@@ -78,56 +62,6 @@ static void print_alias_name(struct hv_device *hv_dev, char *alias_name)
7862
sprintf(&alias_name[i], "%02x", hv_dev->dev_type.b[i/2]);
7963
}
8064

81-
/*
82-
* vmbus_show_device_attr - Show the device attribute in sysfs.
83-
*
84-
* This is invoked when user does a
85-
* "cat /sys/bus/vmbus/devices/<busdevice>/<attr name>"
86-
*/
87-
static ssize_t vmbus_show_device_attr(struct device *dev,
88-
struct device_attribute *dev_attr,
89-
char *buf)
90-
{
91-
struct hv_device *hv_dev = device_to_hv_device(dev);
92-
struct hv_device_info *device_info;
93-
int ret = 0;
94-
95-
device_info = kzalloc(sizeof(struct hv_device_info), GFP_KERNEL);
96-
if (!device_info)
97-
return ret;
98-
99-
get_channel_info(hv_dev, device_info);
100-
101-
if (!strcmp(dev_attr->attr.name, "out_intr_mask")) {
102-
ret = sprintf(buf, "%d\n", device_info->outbound.current_interrupt_mask);
103-
} else if (!strcmp(dev_attr->attr.name, "out_read_index")) {
104-
ret = sprintf(buf, "%d\n", device_info->outbound.current_read_index);
105-
} else if (!strcmp(dev_attr->attr.name, "out_write_index")) {
106-
ret = sprintf(buf, "%d\n", device_info->outbound.current_write_index);
107-
} else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) {
108-
ret = sprintf(buf, "%d\n",
109-
device_info->outbound.bytes_avail_toread);
110-
} else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) {
111-
ret = sprintf(buf, "%d\n",
112-
device_info->outbound.bytes_avail_towrite);
113-
} else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) {
114-
ret = sprintf(buf, "%d\n", device_info->inbound.current_interrupt_mask);
115-
} else if (!strcmp(dev_attr->attr.name, "in_read_index")) {
116-
ret = sprintf(buf, "%d\n", device_info->inbound.current_read_index);
117-
} else if (!strcmp(dev_attr->attr.name, "in_write_index")) {
118-
ret = sprintf(buf, "%d\n", device_info->inbound.current_write_index);
119-
} else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) {
120-
ret = sprintf(buf, "%d\n",
121-
device_info->inbound.bytes_avail_toread);
122-
} else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) {
123-
ret = sprintf(buf, "%d\n",
124-
device_info->inbound.bytes_avail_towrite);
125-
}
126-
127-
kfree(device_info);
128-
return ret;
129-
}
130-
13165
static u8 channel_monitor_group(struct vmbus_channel *channel)
13266
{
13367
return (u8)channel->offermsg.monitorid / 32;
@@ -313,6 +247,142 @@ static ssize_t client_monitor_conn_id_show(struct device *dev,
313247
}
314248
static DEVICE_ATTR_RO(client_monitor_conn_id);
315249

250+
static ssize_t out_intr_mask_show(struct device *dev,
251+
struct device_attribute *dev_attr, char *buf)
252+
{
253+
struct hv_device *hv_dev = device_to_hv_device(dev);
254+
struct hv_ring_buffer_debug_info outbound;
255+
256+
if (!hv_dev->channel)
257+
return -ENODEV;
258+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
259+
return sprintf(buf, "%d\n", outbound.current_interrupt_mask);
260+
}
261+
static DEVICE_ATTR_RO(out_intr_mask);
262+
263+
static ssize_t out_read_index_show(struct device *dev,
264+
struct device_attribute *dev_attr, char *buf)
265+
{
266+
struct hv_device *hv_dev = device_to_hv_device(dev);
267+
struct hv_ring_buffer_debug_info outbound;
268+
269+
if (!hv_dev->channel)
270+
return -ENODEV;
271+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
272+
return sprintf(buf, "%d\n", outbound.current_read_index);
273+
}
274+
static DEVICE_ATTR_RO(out_read_index);
275+
276+
static ssize_t out_write_index_show(struct device *dev,
277+
struct device_attribute *dev_attr,
278+
char *buf)
279+
{
280+
struct hv_device *hv_dev = device_to_hv_device(dev);
281+
struct hv_ring_buffer_debug_info outbound;
282+
283+
if (!hv_dev->channel)
284+
return -ENODEV;
285+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
286+
return sprintf(buf, "%d\n", outbound.current_write_index);
287+
}
288+
static DEVICE_ATTR_RO(out_write_index);
289+
290+
static ssize_t out_read_bytes_avail_show(struct device *dev,
291+
struct device_attribute *dev_attr,
292+
char *buf)
293+
{
294+
struct hv_device *hv_dev = device_to_hv_device(dev);
295+
struct hv_ring_buffer_debug_info outbound;
296+
297+
if (!hv_dev->channel)
298+
return -ENODEV;
299+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
300+
return sprintf(buf, "%d\n", outbound.bytes_avail_toread);
301+
}
302+
static DEVICE_ATTR_RO(out_read_bytes_avail);
303+
304+
static ssize_t out_write_bytes_avail_show(struct device *dev,
305+
struct device_attribute *dev_attr,
306+
char *buf)
307+
{
308+
struct hv_device *hv_dev = device_to_hv_device(dev);
309+
struct hv_ring_buffer_debug_info outbound;
310+
311+
if (!hv_dev->channel)
312+
return -ENODEV;
313+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
314+
return sprintf(buf, "%d\n", outbound.bytes_avail_towrite);
315+
}
316+
static DEVICE_ATTR_RO(out_write_bytes_avail);
317+
318+
static ssize_t in_intr_mask_show(struct device *dev,
319+
struct device_attribute *dev_attr, char *buf)
320+
{
321+
struct hv_device *hv_dev = device_to_hv_device(dev);
322+
struct hv_ring_buffer_debug_info inbound;
323+
324+
if (!hv_dev->channel)
325+
return -ENODEV;
326+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
327+
return sprintf(buf, "%d\n", inbound.current_interrupt_mask);
328+
}
329+
static DEVICE_ATTR_RO(in_intr_mask);
330+
331+
static ssize_t in_read_index_show(struct device *dev,
332+
struct device_attribute *dev_attr, char *buf)
333+
{
334+
struct hv_device *hv_dev = device_to_hv_device(dev);
335+
struct hv_ring_buffer_debug_info inbound;
336+
337+
if (!hv_dev->channel)
338+
return -ENODEV;
339+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
340+
return sprintf(buf, "%d\n", inbound.current_read_index);
341+
}
342+
static DEVICE_ATTR_RO(in_read_index);
343+
344+
static ssize_t in_write_index_show(struct device *dev,
345+
struct device_attribute *dev_attr, char *buf)
346+
{
347+
struct hv_device *hv_dev = device_to_hv_device(dev);
348+
struct hv_ring_buffer_debug_info inbound;
349+
350+
if (!hv_dev->channel)
351+
return -ENODEV;
352+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
353+
return sprintf(buf, "%d\n", inbound.current_write_index);
354+
}
355+
static DEVICE_ATTR_RO(in_write_index);
356+
357+
static ssize_t in_read_bytes_avail_show(struct device *dev,
358+
struct device_attribute *dev_attr,
359+
char *buf)
360+
{
361+
struct hv_device *hv_dev = device_to_hv_device(dev);
362+
struct hv_ring_buffer_debug_info inbound;
363+
364+
if (!hv_dev->channel)
365+
return -ENODEV;
366+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
367+
return sprintf(buf, "%d\n", inbound.bytes_avail_toread);
368+
}
369+
static DEVICE_ATTR_RO(in_read_bytes_avail);
370+
371+
static ssize_t in_write_bytes_avail_show(struct device *dev,
372+
struct device_attribute *dev_attr,
373+
char *buf)
374+
{
375+
struct hv_device *hv_dev = device_to_hv_device(dev);
376+
struct hv_ring_buffer_debug_info inbound;
377+
378+
if (!hv_dev->channel)
379+
return -ENODEV;
380+
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
381+
return sprintf(buf, "%d\n", inbound.bytes_avail_towrite);
382+
}
383+
static DEVICE_ATTR_RO(in_write_bytes_avail);
384+
385+
/* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
316386
static struct attribute *vmbus_attrs[] = {
317387
&dev_attr_id.attr,
318388
&dev_attr_state.attr,
@@ -326,27 +396,20 @@ static struct attribute *vmbus_attrs[] = {
326396
&dev_attr_client_monitor_latency.attr,
327397
&dev_attr_server_monitor_conn_id.attr,
328398
&dev_attr_client_monitor_conn_id.attr,
399+
&dev_attr_out_intr_mask.attr,
400+
&dev_attr_out_read_index.attr,
401+
&dev_attr_out_write_index.attr,
402+
&dev_attr_out_read_bytes_avail.attr,
403+
&dev_attr_out_write_bytes_avail.attr,
404+
&dev_attr_in_intr_mask.attr,
405+
&dev_attr_in_read_index.attr,
406+
&dev_attr_in_write_index.attr,
407+
&dev_attr_in_read_bytes_avail.attr,
408+
&dev_attr_in_write_bytes_avail.attr,
329409
NULL,
330410
};
331411
ATTRIBUTE_GROUPS(vmbus);
332412

333-
/* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
334-
static struct device_attribute vmbus_device_attrs[] = {
335-
__ATTR(out_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
336-
__ATTR(out_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
337-
__ATTR(out_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
338-
__ATTR(out_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
339-
__ATTR(out_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
340-
341-
__ATTR(in_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
342-
__ATTR(in_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
343-
__ATTR(in_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
344-
__ATTR(in_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
345-
__ATTR(in_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
346-
__ATTR_NULL
347-
};
348-
349-
350413
/*
351414
* vmbus_uevent - add uevent for our device
352415
*
@@ -494,7 +557,6 @@ static struct bus_type hv_bus = {
494557
.remove = vmbus_remove,
495558
.probe = vmbus_probe,
496559
.uevent = vmbus_uevent,
497-
.dev_attrs = vmbus_device_attrs,
498560
.dev_groups = vmbus_groups,
499561
};
500562

0 commit comments

Comments
 (0)