]> Pileus Git - ~andy/linux/blob - drivers/staging/hv/ring_buffer.h
5c172889d11627e95fe8ca4442868dadebd117b0
[~andy/linux] / drivers / staging / hv / ring_buffer.h
1 /*
2  *
3  * Copyright (c) 2009, Microsoft Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * Authors:
19  *   Haiyang Zhang <haiyangz@microsoft.com>
20  *   Hank Janssen  <hjanssen@microsoft.com>
21  *   K. Y. Srinivasan <kys@microsoft.com>
22  *
23  */
24
25
26 #ifndef _RING_BUFFER_H_
27 #define _RING_BUFFER_H_
28
29 #include <linux/scatterlist.h>
30
31 struct hv_ring_buffer {
32         /* Offset in bytes from the start of ring data below */
33         volatile u32 write_index;
34
35         /* Offset in bytes from the start of ring data below */
36         volatile u32 read_index;
37
38         volatile u32 interrupt_mask;
39
40         /* Pad it to PAGE_SIZE so that data starts on page boundary */
41         u8      reserved[4084];
42
43         /* NOTE:
44          * The interrupt_mask field is used only for channels but since our
45          * vmbus connection also uses this data structure and its data starts
46          * here, we commented out this field.
47          */
48         /* volatile u32 InterruptMask; */
49
50         /*
51          * Ring data starts here + RingDataStartOffset
52          * !!! DO NOT place any fields below this !!!
53          */
54         u8 buffer[0];
55 } __packed;
56
57 struct hv_ring_buffer_info {
58         struct hv_ring_buffer *ring_buffer;
59         u32 ring_size;                  /* Include the shared header */
60         spinlock_t ring_lock;
61
62         u32 ring_datasize;              /* < ring_size */
63         u32 ring_data_startoffset;
64 };
65
66 struct hv_ring_buffer_debug_info {
67         u32 current_interrupt_mask;
68         u32 current_read_index;
69         u32 current_write_index;
70         u32 bytes_avail_toread;
71         u32 bytes_avail_towrite;
72 };
73
74
75
76 /* Interface */
77
78
79 int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, void *buffer,
80                    u32 buflen);
81
82 void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info);
83
84 int hv_ringbuffer_write(struct hv_ring_buffer_info *ring_info,
85                     struct scatterlist *sglist,
86                     u32 sgcount);
87
88 int ringbuffer_peek(struct hv_ring_buffer_info *ring_info, void *buffer,
89                    u32 buflen);
90
91 int ringbuffer_read(struct hv_ring_buffer_info *ring_info,
92                    void *buffer,
93                    u32 buflen,
94                    u32 offset);
95
96 u32 get_ringbuffer_interrupt_mask(struct hv_ring_buffer_info *ring_info);
97
98 void dump_ring_info(struct hv_ring_buffer_info *ring_info, char *prefix);
99
100 void ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info,
101                             struct hv_ring_buffer_debug_info *debug_info);
102
103 #endif /* _RING_BUFFER_H_ */