blob: 6202157e145dc791b1412149c0dc94eb0066a2e8 [file] [log] [blame]
Hank Janssen3e7ee492009-07-13 16:02:34 -07001/*
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 *
22 */
23
24
25#ifndef _RING_BUFFER_H_
26#define _RING_BUFFER_H_
27
Nicolas Palixb219b3f2009-07-30 17:37:23 +020028#include <linux/scatterlist.h>
Hank Janssen3e7ee492009-07-13 16:02:34 -070029
Hank Janssen3e7ee492009-07-13 16:02:34 -070030typedef struct _RING_BUFFER {
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070031 /* Offset in bytes from the start of ring data below */
32 volatile u32 WriteIndex;
33
34 /* Offset in bytes from the start of ring data below */
35 volatile u32 ReadIndex;
Hank Janssen3e7ee492009-07-13 16:02:34 -070036
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070037 volatile u32 InterruptMask;
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070038
39 /* Pad it to PAGE_SIZE so that data starts on page boundary */
40 u8 Reserved[4084];
41
42 /* NOTE:
43 * The InterruptMask 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.
46 */
Bill Pemberton454f18a2009-07-27 16:47:24 -040047 /* volatile u32 InterruptMask; */
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070048
49 /*
50 * Ring data starts here + RingDataStartOffset
51 * !!! DO NOT place any fields below this !!!
52 */
53 u8 Buffer[0];
Greg Kroah-Hartmanb211a952009-07-15 11:07:45 -070054} __attribute__((packed)) RING_BUFFER;
Hank Janssen3e7ee492009-07-13 16:02:34 -070055
56typedef struct _RING_BUFFER_INFO {
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070057 RING_BUFFER *RingBuffer;
58 u32 RingSize; /* Include the shared header */
Greg Kroah-Hartmana98f96e2009-07-15 14:55:14 -070059 spinlock_t ring_lock;
Hank Janssen3e7ee492009-07-13 16:02:34 -070060
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070061 u32 RingDataSize; /* < ringSize */
62 u32 RingDataStartOffset;
Hank Janssen3e7ee492009-07-13 16:02:34 -070063
64} RING_BUFFER_INFO;
65
Hank Janssen3e7ee492009-07-13 16:02:34 -070066typedef struct _RING_BUFFER_DEBUG_INFO {
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070067 u32 CurrentInterruptMask;
68 u32 CurrentReadIndex;
69 u32 CurrentWriteIndex;
70 u32 BytesAvailToRead;
71 u32 BytesAvailToWrite;
72} RING_BUFFER_DEBUG_INFO;
Hank Janssen3e7ee492009-07-13 16:02:34 -070073
74
Bill Pemberton454f18a2009-07-27 16:47:24 -040075
76/* Interface */
77
Hank Janssen3e7ee492009-07-13 16:02:34 -070078
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070079int RingBufferInit(RING_BUFFER_INFO *RingInfo, void *Buffer, u32 BufferLen);
Hank Janssen3e7ee492009-07-13 16:02:34 -070080
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070081void RingBufferCleanup(RING_BUFFER_INFO *RingInfo);
Hank Janssen3e7ee492009-07-13 16:02:34 -070082
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070083int RingBufferWrite(RING_BUFFER_INFO *RingInfo,
84 struct scatterlist *sglist,
85 u32 sgcount);
Hank Janssen3e7ee492009-07-13 16:02:34 -070086
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070087int RingBufferPeek(RING_BUFFER_INFO *RingInfo, void *Buffer, u32 BufferLen);
Hank Janssen3e7ee492009-07-13 16:02:34 -070088
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070089int RingBufferRead(RING_BUFFER_INFO *RingInfo,
90 void *Buffer,
91 u32 BufferLen,
92 u32 Offset);
Hank Janssen3e7ee492009-07-13 16:02:34 -070093
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070094u32 GetRingBufferInterruptMask(RING_BUFFER_INFO *RingInfo);
Hank Janssen3e7ee492009-07-13 16:02:34 -070095
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070096void DumpRingInfo(RING_BUFFER_INFO *RingInfo, char *Prefix);
Hank Janssen3e7ee492009-07-13 16:02:34 -070097
Greg Kroah-Hartman3523a802009-08-17 17:22:08 -070098void RingBufferGetDebugInfo(RING_BUFFER_INFO *RingInfo,
99 RING_BUFFER_DEBUG_INFO *DebugInfo);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700100
Bill Pemberton454f18a2009-07-27 16:47:24 -0400101#endif /* _RING_BUFFER_H_ */