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 * 22 */ 23 24 25#ifndef _RING_BUFFER_H_ 26#define _RING_BUFFER_H_ 27 28#include <linux/scatterlist.h> 29 30struct hv_ring_buffer { 31 /* 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; 36 37 volatile u32 InterruptMask; 38 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 */ 47 /* volatile u32 InterruptMask; */ 48 49 /* 50 * Ring data starts here + RingDataStartOffset 51 * !!! DO NOT place any fields below this !!! 52 */ 53 u8 Buffer[0]; 54} __attribute__((packed)); 55 56struct hv_ring_buffer_info { 57 struct hv_ring_buffer *RingBuffer; 58 u32 RingSize; /* Include the shared header */ 59 spinlock_t ring_lock; 60 61 u32 RingDataSize; /* < ringSize */ 62 u32 RingDataStartOffset; 63}; 64 65struct hv_ring_buffer_debug_info { 66 u32 CurrentInterruptMask; 67 u32 CurrentReadIndex; 68 u32 CurrentWriteIndex; 69 u32 BytesAvailToRead; 70 u32 BytesAvailToWrite; 71}; 72 73 74 75/* Interface */ 76 77 78int RingBufferInit(struct hv_ring_buffer_info *RingInfo, void *Buffer, 79 u32 BufferLen); 80 81void RingBufferCleanup(struct hv_ring_buffer_info *RingInfo); 82 83int RingBufferWrite(struct hv_ring_buffer_info *RingInfo, 84 struct scatterlist *sglist, 85 u32 sgcount); 86 87int RingBufferPeek(struct hv_ring_buffer_info *RingInfo, void *Buffer, 88 u32 BufferLen); 89 90int RingBufferRead(struct hv_ring_buffer_info *RingInfo, 91 void *Buffer, 92 u32 BufferLen, 93 u32 Offset); 94 95u32 GetRingBufferInterruptMask(struct hv_ring_buffer_info *RingInfo); 96 97void DumpRingInfo(struct hv_ring_buffer_info *RingInfo, char *Prefix); 98 99void RingBufferGetDebugInfo(struct hv_ring_buffer_info *RingInfo, 100 struct hv_ring_buffer_debug_info *debug_info); 101 102#endif /* _RING_BUFFER_H_ */ 103