3 * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
25 #ifndef _RING_BUFFER_H_
26 #define _RING_BUFFER_H_
28 #include <linux/scatterlist.h>
30 struct hv_ring_buffer
{
31 /* Offset in bytes from the start of ring data below */
32 volatile u32 write_index
;
34 /* Offset in bytes from the start of ring data below */
35 volatile u32 read_index
;
37 volatile u32 interrupt_mask
;
39 /* Pad it to PAGE_SIZE so that data starts on page boundary */
43 * The interrupt_mask field is used only for channels but since our
44 * vmbus connection also uses this data structure and its data starts
45 * here, we commented out this field.
47 /* volatile u32 InterruptMask; */
50 * Ring data starts here + RingDataStartOffset
51 * !!! DO NOT place any fields below this !!!
54 } __attribute__((packed
));
56 struct hv_ring_buffer_info
{
57 struct hv_ring_buffer
*ring_buffer
;
58 u32 ring_size
; /* Include the shared header */
61 u32 ring_datasize
; /* < ring_size */
62 u32 ring_data_startoffset
;
65 struct hv_ring_buffer_debug_info
{
66 u32 current_interrupt_mask
;
67 u32 current_read_index
;
68 u32 current_write_index
;
69 u32 bytes_avail_toread
;
70 u32 bytes_avail_towrite
;
78 int ringbuffer_init(struct hv_ring_buffer_info
*ring_info
, void *buffer
,
81 void ringbuffer_cleanup(struct hv_ring_buffer_info
*ring_info
);
83 int ringbuffer_write(struct hv_ring_buffer_info
*ring_info
,
84 struct scatterlist
*sglist
,
87 int ringbuffer_peek(struct hv_ring_buffer_info
*ring_info
, void *buffer
,
90 int ringbuffer_read(struct hv_ring_buffer_info
*ring_info
,
95 u32
get_ringbuffer_interrupt_mask(struct hv_ring_buffer_info
*ring_info
);
97 void dump_ring_info(struct hv_ring_buffer_info
*ring_info
, char *prefix
);
99 void ringbuffer_get_debuginfo(struct hv_ring_buffer_info
*ring_info
,
100 struct hv_ring_buffer_debug_info
*debug_info
);
102 #endif /* _RING_BUFFER_H_ */