Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/mm.h> |
Greg Kroah-Hartman | 4983b39 | 2009-08-19 16:14:47 -0700 | [diff] [blame] | 26 | #include "osd.h" |
Greg Kroah-Hartman | 645954c | 2009-08-28 16:22:59 -0700 | [diff] [blame] | 27 | #include "logging.h" |
Greg Kroah-Hartman | 8f078ca | 2010-05-05 22:22:35 -0700 | [diff] [blame] | 28 | #include "ring_buffer.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 29 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 30 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 31 | /* #defines */ |
| 32 | |
| 33 | |
| 34 | /* Amount of space to write to */ |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 35 | #define BYTES_AVAIL_TO_WRITE(r, w, z) ((w) >= (r)) ? ((z) - ((w) - (r))) : ((r) - (w)) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 36 | |
| 37 | |
| 38 | /*++ |
| 39 | |
| 40 | Name: |
| 41 | GetRingBufferAvailBytes() |
| 42 | |
| 43 | Description: |
| 44 | Get number of bytes available to read and to write to |
| 45 | for the specified ring buffer |
| 46 | |
| 47 | --*/ |
| 48 | static inline void |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 49 | GetRingBufferAvailBytes(struct hv_ring_buffer_info *rbi, u32 *read, u32 *write) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 50 | { |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 51 | u32 read_loc, write_loc; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 52 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 53 | /* Capture the read/write indices before they changed */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 54 | read_loc = rbi->RingBuffer->ReadIndex; |
| 55 | write_loc = rbi->RingBuffer->WriteIndex; |
| 56 | |
| 57 | *write = BYTES_AVAIL_TO_WRITE(read_loc, write_loc, rbi->RingDataSize); |
| 58 | *read = rbi->RingDataSize - *write; |
| 59 | } |
| 60 | |
| 61 | /*++ |
| 62 | |
| 63 | Name: |
| 64 | GetNextWriteLocation() |
| 65 | |
| 66 | Description: |
| 67 | Get the next write location for the specified ring buffer |
| 68 | |
| 69 | --*/ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 70 | static inline u32 |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 71 | GetNextWriteLocation(struct hv_ring_buffer_info *RingInfo) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 72 | { |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 73 | u32 next = RingInfo->RingBuffer->WriteIndex; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 74 | |
Bill Pemberton | 1bbdd7a | 2010-05-05 15:27:48 -0400 | [diff] [blame] | 75 | /* ASSERT(next < RingInfo->RingDataSize); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 76 | |
| 77 | return next; |
| 78 | } |
| 79 | |
| 80 | /*++ |
| 81 | |
| 82 | Name: |
| 83 | SetNextWriteLocation() |
| 84 | |
| 85 | Description: |
| 86 | Set the next write location for the specified ring buffer |
| 87 | |
| 88 | --*/ |
| 89 | static inline void |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 90 | SetNextWriteLocation(struct hv_ring_buffer_info *RingInfo, |
| 91 | u32 NextWriteLocation) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 92 | { |
| 93 | RingInfo->RingBuffer->WriteIndex = NextWriteLocation; |
| 94 | } |
| 95 | |
| 96 | /*++ |
| 97 | |
| 98 | Name: |
| 99 | GetNextReadLocation() |
| 100 | |
| 101 | Description: |
| 102 | Get the next read location for the specified ring buffer |
| 103 | |
| 104 | --*/ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 105 | static inline u32 |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 106 | GetNextReadLocation(struct hv_ring_buffer_info *RingInfo) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 107 | { |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 108 | u32 next = RingInfo->RingBuffer->ReadIndex; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 109 | |
Bill Pemberton | 1bbdd7a | 2010-05-05 15:27:48 -0400 | [diff] [blame] | 110 | /* ASSERT(next < RingInfo->RingDataSize); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 111 | |
| 112 | return next; |
| 113 | } |
| 114 | |
| 115 | /*++ |
| 116 | |
| 117 | Name: |
| 118 | GetNextReadLocationWithOffset() |
| 119 | |
| 120 | Description: |
| 121 | Get the next read location + offset for the specified ring buffer. |
| 122 | This allows the caller to skip |
| 123 | |
| 124 | --*/ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 125 | static inline u32 |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 126 | GetNextReadLocationWithOffset(struct hv_ring_buffer_info *RingInfo, u32 Offset) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 127 | { |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 128 | u32 next = RingInfo->RingBuffer->ReadIndex; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 129 | |
Bill Pemberton | 1bbdd7a | 2010-05-05 15:27:48 -0400 | [diff] [blame] | 130 | /* ASSERT(next < RingInfo->RingDataSize); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 131 | next += Offset; |
| 132 | next %= RingInfo->RingDataSize; |
| 133 | |
| 134 | return next; |
| 135 | } |
| 136 | |
| 137 | /*++ |
| 138 | |
| 139 | Name: |
| 140 | SetNextReadLocation() |
| 141 | |
| 142 | Description: |
| 143 | Set the next read location for the specified ring buffer |
| 144 | |
| 145 | --*/ |
| 146 | static inline void |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 147 | SetNextReadLocation(struct hv_ring_buffer_info *RingInfo, u32 NextReadLocation) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 148 | { |
| 149 | RingInfo->RingBuffer->ReadIndex = NextReadLocation; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /*++ |
| 154 | |
| 155 | Name: |
| 156 | GetRingBuffer() |
| 157 | |
| 158 | Description: |
| 159 | Get the start of the ring buffer |
| 160 | |
| 161 | --*/ |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 162 | static inline void * |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 163 | GetRingBuffer(struct hv_ring_buffer_info *RingInfo) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 164 | { |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 165 | return (void *)RingInfo->RingBuffer->Buffer; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | |
| 169 | /*++ |
| 170 | |
| 171 | Name: |
| 172 | GetRingBufferSize() |
| 173 | |
| 174 | Description: |
| 175 | Get the size of the ring buffer |
| 176 | |
| 177 | --*/ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 178 | static inline u32 |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 179 | GetRingBufferSize(struct hv_ring_buffer_info *RingInfo) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 180 | { |
| 181 | return RingInfo->RingDataSize; |
| 182 | } |
| 183 | |
| 184 | /*++ |
| 185 | |
| 186 | Name: |
| 187 | GetRingBufferIndices() |
| 188 | |
| 189 | Description: |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 190 | Get the read and write indices as u64 of the specified ring buffer |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 191 | |
| 192 | --*/ |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 193 | static inline u64 |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 194 | GetRingBufferIndices(struct hv_ring_buffer_info *RingInfo) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 195 | { |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 196 | return ((u64)RingInfo->RingBuffer->WriteIndex << 32) |
| 197 | || RingInfo->RingBuffer->ReadIndex; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | |
| 201 | /*++ |
| 202 | |
| 203 | Name: |
| 204 | DumpRingInfo() |
| 205 | |
| 206 | Description: |
| 207 | Dump out to console the ring buffer info |
| 208 | |
| 209 | --*/ |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 210 | void DumpRingInfo(struct hv_ring_buffer_info *RingInfo, char *Prefix) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 211 | { |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 212 | u32 bytesAvailToWrite; |
| 213 | u32 bytesAvailToRead; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 214 | |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 215 | GetRingBufferAvailBytes(RingInfo, |
| 216 | &bytesAvailToRead, |
| 217 | &bytesAvailToWrite); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 218 | |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 219 | DPRINT(VMBUS, |
| 220 | DEBUG_RING_LVL, |
| 221 | "%s <<ringinfo %p buffer %p avail write %u " |
| 222 | "avail read %u read idx %u write idx %u>>", |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 223 | Prefix, |
| 224 | RingInfo, |
| 225 | RingInfo->RingBuffer->Buffer, |
| 226 | bytesAvailToWrite, |
| 227 | bytesAvailToRead, |
| 228 | RingInfo->RingBuffer->ReadIndex, |
| 229 | RingInfo->RingBuffer->WriteIndex); |
| 230 | } |
| 231 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 232 | |
| 233 | /* Internal routines */ |
| 234 | |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 235 | static u32 |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 236 | CopyToRingBuffer( |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 237 | struct hv_ring_buffer_info *RingInfo, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 238 | u32 StartWriteOffset, |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 239 | void *Src, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 240 | u32 SrcLen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 241 | |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 242 | static u32 |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 243 | CopyFromRingBuffer( |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 244 | struct hv_ring_buffer_info *RingInfo, |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 245 | void *Dest, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 246 | u32 DestLen, |
| 247 | u32 StartReadOffset); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 248 | |
| 249 | |
| 250 | |
| 251 | /*++ |
| 252 | |
| 253 | Name: |
| 254 | RingBufferGetDebugInfo() |
| 255 | |
| 256 | Description: |
| 257 | Get various debug metrics for the specified ring buffer |
| 258 | |
| 259 | --*/ |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 260 | void RingBufferGetDebugInfo(struct hv_ring_buffer_info *RingInfo, |
Greg Kroah-Hartman | 80682b7 | 2010-07-27 11:37:32 -0700 | [diff] [blame] | 261 | struct hv_ring_buffer_debug_info *debug_info) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 262 | { |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 263 | u32 bytesAvailToWrite; |
| 264 | u32 bytesAvailToRead; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 265 | |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 266 | if (RingInfo->RingBuffer) { |
| 267 | GetRingBufferAvailBytes(RingInfo, |
| 268 | &bytesAvailToRead, |
| 269 | &bytesAvailToWrite); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 270 | |
Greg Kroah-Hartman | 80682b7 | 2010-07-27 11:37:32 -0700 | [diff] [blame] | 271 | debug_info->BytesAvailToRead = bytesAvailToRead; |
| 272 | debug_info->BytesAvailToWrite = bytesAvailToWrite; |
| 273 | debug_info->CurrentReadIndex = RingInfo->RingBuffer->ReadIndex; |
| 274 | debug_info->CurrentWriteIndex = RingInfo->RingBuffer->WriteIndex; |
| 275 | debug_info->CurrentInterruptMask = RingInfo->RingBuffer->InterruptMask; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | |
| 280 | /*++ |
| 281 | |
| 282 | Name: |
| 283 | GetRingBufferInterruptMask() |
| 284 | |
| 285 | Description: |
| 286 | Get the interrupt mask for the specified ring buffer |
| 287 | |
| 288 | --*/ |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 289 | u32 GetRingBufferInterruptMask(struct hv_ring_buffer_info *rbi) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 290 | { |
| 291 | return rbi->RingBuffer->InterruptMask; |
| 292 | } |
| 293 | |
| 294 | /*++ |
| 295 | |
| 296 | Name: |
| 297 | RingBufferInit() |
| 298 | |
| 299 | Description: |
| 300 | Initialize the ring buffer |
| 301 | |
| 302 | --*/ |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 303 | int RingBufferInit(struct hv_ring_buffer_info *RingInfo, void *Buffer, u32 BufferLen) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 304 | { |
Greg Kroah-Hartman | 4a1b3ac | 2010-07-27 11:47:08 -0700 | [diff] [blame^] | 305 | if (sizeof(struct hv_ring_buffer) != PAGE_SIZE) |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 306 | return -EINVAL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 307 | |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 308 | memset(RingInfo, 0, sizeof(struct hv_ring_buffer_info)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 309 | |
Greg Kroah-Hartman | 4a1b3ac | 2010-07-27 11:47:08 -0700 | [diff] [blame^] | 310 | RingInfo->RingBuffer = (struct hv_ring_buffer *)Buffer; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 311 | RingInfo->RingBuffer->ReadIndex = RingInfo->RingBuffer->WriteIndex = 0; |
| 312 | |
| 313 | RingInfo->RingSize = BufferLen; |
Greg Kroah-Hartman | 4a1b3ac | 2010-07-27 11:47:08 -0700 | [diff] [blame^] | 314 | RingInfo->RingDataSize = BufferLen - sizeof(struct hv_ring_buffer); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 315 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 316 | spin_lock_init(&RingInfo->ring_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | /*++ |
| 322 | |
| 323 | Name: |
| 324 | RingBufferCleanup() |
| 325 | |
| 326 | Description: |
| 327 | Cleanup the ring buffer |
| 328 | |
| 329 | --*/ |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 330 | void RingBufferCleanup(struct hv_ring_buffer_info *RingInfo) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 331 | { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /*++ |
| 335 | |
| 336 | Name: |
| 337 | RingBufferWrite() |
| 338 | |
| 339 | Description: |
| 340 | Write to the ring buffer |
| 341 | |
| 342 | --*/ |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 343 | int RingBufferWrite(struct hv_ring_buffer_info *OutRingInfo, |
Greg Kroah-Hartman | 3523a80 | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 344 | struct scatterlist *sglist, u32 sgcount) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 345 | { |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 346 | int i = 0; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 347 | u32 byteAvailToWrite; |
| 348 | u32 byteAvailToRead; |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 349 | u32 totalBytesToWrite = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 350 | |
Nicolas Palix | b219b3f | 2009-07-30 17:37:23 +0200 | [diff] [blame] | 351 | struct scatterlist *sg; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 352 | volatile u32 nextWriteLocation; |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 353 | u64 prevIndices = 0; |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 354 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 355 | |
Nicolas Palix | b219b3f | 2009-07-30 17:37:23 +0200 | [diff] [blame] | 356 | for_each_sg(sglist, sg, sgcount, i) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 357 | { |
Nicolas Palix | b219b3f | 2009-07-30 17:37:23 +0200 | [diff] [blame] | 358 | totalBytesToWrite += sg->length; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 361 | totalBytesToWrite += sizeof(u64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 362 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 363 | spin_lock_irqsave(&OutRingInfo->ring_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 364 | |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 365 | GetRingBufferAvailBytes(OutRingInfo, |
| 366 | &byteAvailToRead, |
| 367 | &byteAvailToWrite); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 368 | |
| 369 | DPRINT_DBG(VMBUS, "Writing %u bytes...", totalBytesToWrite); |
| 370 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 371 | /* DumpRingInfo(OutRingInfo, "BEFORE "); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 372 | |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 373 | /* If there is only room for the packet, assume it is full. */ |
| 374 | /* Otherwise, the next time around, we think the ring buffer */ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 375 | /* is empty since the read index == write index */ |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 376 | if (byteAvailToWrite <= totalBytesToWrite) { |
| 377 | DPRINT_DBG(VMBUS, |
| 378 | "No more space left on outbound ring buffer " |
| 379 | "(needed %u, avail %u)", |
| 380 | totalBytesToWrite, |
| 381 | byteAvailToWrite); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 382 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 383 | spin_unlock_irqrestore(&OutRingInfo->ring_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 384 | return -1; |
| 385 | } |
| 386 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 387 | /* Write to the ring buffer */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 388 | nextWriteLocation = GetNextWriteLocation(OutRingInfo); |
| 389 | |
Nicolas Palix | b219b3f | 2009-07-30 17:37:23 +0200 | [diff] [blame] | 390 | for_each_sg(sglist, sg, sgcount, i) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 391 | { |
Nicolas Palix | b219b3f | 2009-07-30 17:37:23 +0200 | [diff] [blame] | 392 | nextWriteLocation = CopyToRingBuffer(OutRingInfo, |
| 393 | nextWriteLocation, |
| 394 | sg_virt(sg), |
| 395 | sg->length); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 398 | /* Set previous packet start */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 399 | prevIndices = GetRingBufferIndices(OutRingInfo); |
| 400 | |
| 401 | nextWriteLocation = CopyToRingBuffer(OutRingInfo, |
Nicolas Palix | b219b3f | 2009-07-30 17:37:23 +0200 | [diff] [blame] | 402 | nextWriteLocation, |
| 403 | &prevIndices, |
| 404 | sizeof(u64)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 405 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 406 | /* Make sure we flush all writes before updating the writeIndex */ |
Greg Kroah-Hartman | 28b6ca9 | 2009-07-16 12:34:20 -0700 | [diff] [blame] | 407 | mb(); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 408 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 409 | /* Now, update the write location */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 410 | SetNextWriteLocation(OutRingInfo, nextWriteLocation); |
| 411 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 412 | /* DumpRingInfo(OutRingInfo, "AFTER "); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 413 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 414 | spin_unlock_irqrestore(&OutRingInfo->ring_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | |
| 419 | /*++ |
| 420 | |
| 421 | Name: |
| 422 | RingBufferPeek() |
| 423 | |
| 424 | Description: |
| 425 | Read without advancing the read index |
| 426 | |
| 427 | --*/ |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 428 | int RingBufferPeek(struct hv_ring_buffer_info *InRingInfo, void *Buffer, u32 BufferLen) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 429 | { |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 430 | u32 bytesAvailToWrite; |
| 431 | u32 bytesAvailToRead; |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 432 | u32 nextReadLocation = 0; |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 433 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 434 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 435 | spin_lock_irqsave(&InRingInfo->ring_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 436 | |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 437 | GetRingBufferAvailBytes(InRingInfo, |
| 438 | &bytesAvailToRead, |
| 439 | &bytesAvailToWrite); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 440 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 441 | /* Make sure there is something to read */ |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 442 | if (bytesAvailToRead < BufferLen) { |
| 443 | /* DPRINT_DBG(VMBUS, |
| 444 | "got callback but not enough to read " |
| 445 | "<avail to read %d read size %d>!!", |
| 446 | bytesAvailToRead, |
| 447 | BufferLen); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 448 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 449 | spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 450 | |
| 451 | return -1; |
| 452 | } |
| 453 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 454 | /* Convert to byte offset */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 455 | nextReadLocation = GetNextReadLocation(InRingInfo); |
| 456 | |
| 457 | nextReadLocation = CopyFromRingBuffer(InRingInfo, |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 458 | Buffer, |
| 459 | BufferLen, |
| 460 | nextReadLocation); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 461 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 462 | spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | |
| 468 | /*++ |
| 469 | |
| 470 | Name: |
| 471 | RingBufferRead() |
| 472 | |
| 473 | Description: |
| 474 | Read and advance the read index |
| 475 | |
| 476 | --*/ |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 477 | int RingBufferRead(struct hv_ring_buffer_info *InRingInfo, void *Buffer, |
Greg Kroah-Hartman | 3523a80 | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 478 | u32 BufferLen, u32 Offset) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 479 | { |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 480 | u32 bytesAvailToWrite; |
| 481 | u32 bytesAvailToRead; |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 482 | u32 nextReadLocation = 0; |
| 483 | u64 prevIndices = 0; |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 484 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 485 | |
Bill Pemberton | a16e148 | 2010-05-05 15:27:50 -0400 | [diff] [blame] | 486 | if (BufferLen <= 0) |
| 487 | return -EINVAL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 488 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 489 | spin_lock_irqsave(&InRingInfo->ring_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 490 | |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 491 | GetRingBufferAvailBytes(InRingInfo, |
| 492 | &bytesAvailToRead, |
| 493 | &bytesAvailToWrite); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 494 | |
| 495 | DPRINT_DBG(VMBUS, "Reading %u bytes...", BufferLen); |
| 496 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 497 | /* DumpRingInfo(InRingInfo, "BEFORE "); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 498 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 499 | /* Make sure there is something to read */ |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 500 | if (bytesAvailToRead < BufferLen) { |
| 501 | DPRINT_DBG(VMBUS, |
| 502 | "got callback but not enough to read " |
| 503 | "<avail to read %d read size %d>!!", |
| 504 | bytesAvailToRead, |
| 505 | BufferLen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 506 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 507 | spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 508 | |
| 509 | return -1; |
| 510 | } |
| 511 | |
| 512 | nextReadLocation = GetNextReadLocationWithOffset(InRingInfo, Offset); |
| 513 | |
| 514 | nextReadLocation = CopyFromRingBuffer(InRingInfo, |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 515 | Buffer, |
| 516 | BufferLen, |
| 517 | nextReadLocation); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 518 | |
| 519 | nextReadLocation = CopyFromRingBuffer(InRingInfo, |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 520 | &prevIndices, |
| 521 | sizeof(u64), |
| 522 | nextReadLocation); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 523 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 524 | /* Make sure all reads are done before we update the read index since */ |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 525 | /* the writer may start writing to the read area once the read index */ |
| 526 | /*is updated */ |
Greg Kroah-Hartman | 28b6ca9 | 2009-07-16 12:34:20 -0700 | [diff] [blame] | 527 | mb(); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 528 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 529 | /* Update the read index */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 530 | SetNextReadLocation(InRingInfo, nextReadLocation); |
| 531 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 532 | /* DumpRingInfo(InRingInfo, "AFTER "); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 533 | |
Greg Kroah-Hartman | a98f96e | 2009-07-15 14:55:14 -0700 | [diff] [blame] | 534 | spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 535 | |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | |
| 540 | /*++ |
| 541 | |
| 542 | Name: |
| 543 | CopyToRingBuffer() |
| 544 | |
| 545 | Description: |
| 546 | Helper routine to copy from source to ring buffer. |
| 547 | Assume there is enough room. Handles wrap-around in dest case only!! |
| 548 | |
| 549 | --*/ |
Greg Kroah-Hartman | bd1de70 | 2009-07-29 09:04:51 -0700 | [diff] [blame] | 550 | static u32 |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 551 | CopyToRingBuffer( |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 552 | struct hv_ring_buffer_info *RingInfo, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 553 | u32 StartWriteOffset, |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 554 | void *Src, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 555 | u32 SrcLen) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 556 | { |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 557 | void *ringBuffer = GetRingBuffer(RingInfo); |
| 558 | u32 ringBufferSize = GetRingBufferSize(RingInfo); |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 559 | u32 fragLen; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 560 | |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 561 | /* wrap-around detected! */ |
| 562 | if (SrcLen > ringBufferSize - StartWriteOffset) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 563 | DPRINT_DBG(VMBUS, "wrap-around detected!"); |
| 564 | |
| 565 | fragLen = ringBufferSize - StartWriteOffset; |
| 566 | memcpy(ringBuffer + StartWriteOffset, Src, fragLen); |
| 567 | memcpy(ringBuffer, Src + fragLen, SrcLen - fragLen); |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 568 | } else |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 569 | memcpy(ringBuffer + StartWriteOffset, Src, SrcLen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 570 | |
| 571 | StartWriteOffset += SrcLen; |
| 572 | StartWriteOffset %= ringBufferSize; |
| 573 | |
| 574 | return StartWriteOffset; |
| 575 | } |
| 576 | |
| 577 | |
| 578 | /*++ |
| 579 | |
| 580 | Name: |
| 581 | CopyFromRingBuffer() |
| 582 | |
| 583 | Description: |
| 584 | Helper routine to copy to source from ring buffer. |
| 585 | Assume there is enough room. Handles wrap-around in src case only!! |
| 586 | |
| 587 | --*/ |
Greg Kroah-Hartman | bd1de70 | 2009-07-29 09:04:51 -0700 | [diff] [blame] | 588 | static u32 |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 589 | CopyFromRingBuffer( |
Greg Kroah-Hartman | 8a0e1c5 | 2010-07-27 11:43:11 -0700 | [diff] [blame] | 590 | struct hv_ring_buffer_info *RingInfo, |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 591 | void *Dest, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 592 | u32 DestLen, |
| 593 | u32 StartReadOffset) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 594 | { |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 595 | void *ringBuffer = GetRingBuffer(RingInfo); |
| 596 | u32 ringBufferSize = GetRingBufferSize(RingInfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 597 | |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 598 | u32 fragLen; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 599 | |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 600 | /* wrap-around detected at the src */ |
| 601 | if (DestLen > ringBufferSize - StartReadOffset) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 602 | DPRINT_DBG(VMBUS, "src wrap-around detected!"); |
| 603 | |
| 604 | fragLen = ringBufferSize - StartReadOffset; |
| 605 | |
| 606 | memcpy(Dest, ringBuffer + StartReadOffset, fragLen); |
| 607 | memcpy(Dest + fragLen, ringBuffer, DestLen - fragLen); |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 608 | } else |
| 609 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 610 | memcpy(Dest, ringBuffer + StartReadOffset, DestLen); |
C. Bartlett | 4408f53 | 2010-02-03 15:34:27 +0000 | [diff] [blame] | 611 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 612 | |
| 613 | StartReadOffset += DestLen; |
| 614 | StartReadOffset %= ringBufferSize; |
| 615 | |
| 616 | return StartReadOffset; |
| 617 | } |
| 618 | |
| 619 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 620 | /* eof */ |