summaryrefslogtreecommitdiff
path: root/drivers/staging/hv/RingBuffer.h
blob: 16586148bef98b822445d3b212009f43132e7887 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 *
 * Copyright (c) 2009, Microsoft Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307 USA.
 *
 * Authors:
 *   Haiyang Zhang <haiyangz@microsoft.com>
 *   Hank Janssen  <hjanssen@microsoft.com>
 *
 */


#ifndef _RING_BUFFER_H_
#define _RING_BUFFER_H_

#include <linux/scatterlist.h>

#include "include/osd.h"

typedef struct _RING_BUFFER {
    volatile u32	WriteIndex;     /* Offset in bytes from the start of ring data below */
    volatile u32	ReadIndex;      /* Offset in bytes from the start of ring data below */

	volatile u32 InterruptMask;
	u8	Reserved[4084];			/* Pad it to PAGE_SIZE so that data starts on page boundary */
	/* NOTE: The InterruptMask field is used only for channels but since our vmbus connection */
	/* also uses this data structure and its data starts here, we commented out this field. */
	/* volatile u32 InterruptMask; */
	/* Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!! */
    u8		Buffer[0];
} __attribute__((packed)) RING_BUFFER;

typedef struct _RING_BUFFER_INFO {
    RING_BUFFER*	RingBuffer;
    u32			RingSize;			/* Include the shared header */
	spinlock_t ring_lock;

    u32			RingDataSize;		/* < ringSize */
	u32			RingDataStartOffset;

} RING_BUFFER_INFO;


typedef struct _RING_BUFFER_DEBUG_INFO {
	u32		CurrentInterruptMask;
	u32		CurrentReadIndex;
	u32		CurrentWriteIndex;
	u32		BytesAvailToRead;
	u32		BytesAvailToWrite;
}RING_BUFFER_DEBUG_INFO;



/* Interface */


static int
RingBufferInit(
	RING_BUFFER_INFO	*RingInfo,
	void *				Buffer,
	u32				BufferLen
	);

static void
RingBufferCleanup(
	RING_BUFFER_INFO	*RingInfo
	);

static int
RingBufferWrite(
	RING_BUFFER_INFO *RingInfo,
	struct scatterlist *sglist,
	u32 sgcount
	);

static int
RingBufferPeek(
	RING_BUFFER_INFO	*RingInfo,
	void *				Buffer,
	u32				BufferLen
	);

static int
RingBufferRead(
	RING_BUFFER_INFO	*RingInfo,
	void *				Buffer,
	u32				BufferLen,
	u32				Offset
	);

static u32
GetRingBufferInterruptMask(
	RING_BUFFER_INFO *RingInfo
	);

static void
DumpRingInfo(
	RING_BUFFER_INFO* RingInfo,
	char *Prefix
	);

static void
RingBufferGetDebugInfo(
	RING_BUFFER_INFO		*RingInfo,
	RING_BUFFER_DEBUG_INFO	*DebugInfo
	);

#endif /* _RING_BUFFER_H_ */