blob: c5ecf41a00e698754ca81275b5486b7400d717bf [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
Greg Kroah-Hartman09d50ff2009-07-13 17:09:34 -070028#include "include/osd.h"
Hank Janssen3e7ee492009-07-13 16:02:34 -070029
30typedef struct _SG_BUFFER_LIST {
Greg Kroah-Hartman8282c402009-07-14 15:06:28 -070031 void * Data;
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070032 u32 Length;
Hank Janssen3e7ee492009-07-13 16:02:34 -070033} SG_BUFFER_LIST;
34
35typedef struct _RING_BUFFER {
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070036 volatile u32 WriteIndex; // Offset in bytes from the start of ring data below
37 volatile u32 ReadIndex; // Offset in bytes from the start of ring data below
Hank Janssen3e7ee492009-07-13 16:02:34 -070038
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070039 volatile u32 InterruptMask;
Greg Kroah-Hartman5654e932009-07-14 15:08:20 -070040 u8 Reserved[4084]; // Pad it to PAGE_SIZE so that data starts on page boundary
Hank Janssen3e7ee492009-07-13 16:02:34 -070041 // NOTE: The InterruptMask field is used only for channels but since our vmbus connection
42 // also uses this data structure and its data starts here, we commented out this field.
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070043 // volatile u32 InterruptMask;
Hank Janssen3e7ee492009-07-13 16:02:34 -070044 // Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
Greg Kroah-Hartman5654e932009-07-14 15:08:20 -070045 u8 Buffer[0];
Hank Janssen3e7ee492009-07-13 16:02:34 -070046} STRUCT_PACKED RING_BUFFER;
47
48typedef struct _RING_BUFFER_INFO {
49 RING_BUFFER* RingBuffer;
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070050 u32 RingSize; // Include the shared header
Hank Janssen3e7ee492009-07-13 16:02:34 -070051 HANDLE RingLock;
52
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070053 u32 RingDataSize; // < ringSize
54 u32 RingDataStartOffset;
Hank Janssen3e7ee492009-07-13 16:02:34 -070055
56} RING_BUFFER_INFO;
57
58
59typedef struct _RING_BUFFER_DEBUG_INFO {
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070060 u32 CurrentInterruptMask;
61 u32 CurrentReadIndex;
62 u32 CurrentWriteIndex;
63 u32 BytesAvailToRead;
64 u32 BytesAvailToWrite;
Hank Janssen3e7ee492009-07-13 16:02:34 -070065}RING_BUFFER_DEBUG_INFO;
66
67
68//
69// Interface
70//
71
Greg Kroah-Hartman2be13012009-07-14 15:05:36 -070072static int
Hank Janssen3e7ee492009-07-13 16:02:34 -070073RingBufferInit(
74 RING_BUFFER_INFO *RingInfo,
Greg Kroah-Hartman8282c402009-07-14 15:06:28 -070075 void * Buffer,
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070076 u32 BufferLen
Hank Janssen3e7ee492009-07-13 16:02:34 -070077 );
78
Greg Kroah-Hartman2be13012009-07-14 15:05:36 -070079static void
Hank Janssen3e7ee492009-07-13 16:02:34 -070080RingBufferCleanup(
81 RING_BUFFER_INFO *RingInfo
82 );
83
Greg Kroah-Hartman2be13012009-07-14 15:05:36 -070084static int
Hank Janssen3e7ee492009-07-13 16:02:34 -070085RingBufferWrite(
86 RING_BUFFER_INFO *RingInfo,
87 SG_BUFFER_LIST SgBuffers[],
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070088 u32 SgBufferCount
Hank Janssen3e7ee492009-07-13 16:02:34 -070089 );
90
Greg Kroah-Hartman2be13012009-07-14 15:05:36 -070091static int
Hank Janssen3e7ee492009-07-13 16:02:34 -070092RingBufferPeek(
93 RING_BUFFER_INFO *RingInfo,
Greg Kroah-Hartman8282c402009-07-14 15:06:28 -070094 void * Buffer,
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070095 u32 BufferLen
Hank Janssen3e7ee492009-07-13 16:02:34 -070096 );
97
Greg Kroah-Hartman2be13012009-07-14 15:05:36 -070098static int
Hank Janssen3e7ee492009-07-13 16:02:34 -070099RingBufferRead(
100 RING_BUFFER_INFO *RingInfo,
Greg Kroah-Hartman8282c402009-07-14 15:06:28 -0700101 void * Buffer,
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -0700102 u32 BufferLen,
103 u32 Offset
Hank Janssen3e7ee492009-07-13 16:02:34 -0700104 );
105
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -0700106static u32
Hank Janssen3e7ee492009-07-13 16:02:34 -0700107GetRingBufferInterruptMask(
108 RING_BUFFER_INFO *RingInfo
109 );
110
Greg Kroah-Hartman2be13012009-07-14 15:05:36 -0700111static void
Hank Janssen3e7ee492009-07-13 16:02:34 -0700112DumpRingInfo(
113 RING_BUFFER_INFO* RingInfo,
114 char *Prefix
115 );
116
Greg Kroah-Hartman2be13012009-07-14 15:05:36 -0700117static void
Hank Janssen3e7ee492009-07-13 16:02:34 -0700118RingBufferGetDebugInfo(
119 RING_BUFFER_INFO *RingInfo,
120 RING_BUFFER_DEBUG_INFO *DebugInfo
121 );
122
123#endif // _RING_BUFFER_H_