ctl_tpc_local.c (312570) | ctl_tpc_local.c (313364) |
---|---|
1/*- 2 * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org> 3 * Copyright (c) 2004, 2005 Silicon Graphics International Corp. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org> 3 * Copyright (c) 2004, 2005 Silicon Graphics International Corp. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: stable/11/sys/cam/ctl/ctl_tpc_local.c 312570 2017-01-21 08:29:40Z mav $"); | 29__FBSDID("$FreeBSD: stable/11/sys/cam/ctl/ctl_tpc_local.c 313364 2017-02-07 01:42:13Z mav $"); |
30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/kernel.h> 34#include <sys/types.h> 35#include <sys/lock.h> 36#include <sys/module.h> 37#include <sys/mutex.h> --- 94 unchanged lines hidden (view full) --- 132 133static void 134tpcl_datamove(union ctl_io *io) 135{ 136 struct ctl_sg_entry *ext_sglist, *kern_sglist; 137 struct ctl_sg_entry ext_entry, kern_entry; 138 int ext_sg_entries, kern_sg_entries; 139 int ext_sg_start, ext_offset; | 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/kernel.h> 34#include <sys/types.h> 35#include <sys/lock.h> 36#include <sys/module.h> 37#include <sys/mutex.h> --- 94 unchanged lines hidden (view full) --- 132 133static void 134tpcl_datamove(union ctl_io *io) 135{ 136 struct ctl_sg_entry *ext_sglist, *kern_sglist; 137 struct ctl_sg_entry ext_entry, kern_entry; 138 int ext_sg_entries, kern_sg_entries; 139 int ext_sg_start, ext_offset; |
140 int len_to_copy, len_copied; | 140 int len_to_copy; |
141 int kern_watermark, ext_watermark; 142 struct ctl_scsiio *ctsio; 143 int i, j; 144 145 CTL_DEBUG_PRINT(("%s\n", __func__)); 146 147 ctsio = &io->scsiio; 148 --- 42 unchanged lines hidden (view full) --- 191 kern_sglist = &kern_entry; 192 kern_sglist->addr = ctsio->kern_data_ptr; 193 kern_sglist->len = ctsio->kern_data_len; 194 kern_sg_entries = 1; 195 } 196 197 kern_watermark = 0; 198 ext_watermark = ext_offset; | 141 int kern_watermark, ext_watermark; 142 struct ctl_scsiio *ctsio; 143 int i, j; 144 145 CTL_DEBUG_PRINT(("%s\n", __func__)); 146 147 ctsio = &io->scsiio; 148 --- 42 unchanged lines hidden (view full) --- 191 kern_sglist = &kern_entry; 192 kern_sglist->addr = ctsio->kern_data_ptr; 193 kern_sglist->len = ctsio->kern_data_len; 194 kern_sg_entries = 1; 195 } 196 197 kern_watermark = 0; 198 ext_watermark = ext_offset; |
199 len_copied = 0; | |
200 for (i = ext_sg_start, j = 0; 201 i < ext_sg_entries && j < kern_sg_entries;) { 202 uint8_t *ext_ptr, *kern_ptr; 203 204 len_to_copy = min(ext_sglist[i].len - ext_watermark, 205 kern_sglist[j].len - kern_watermark); 206 207 ext_ptr = (uint8_t *)ext_sglist[i].addr; --- 5 unchanged lines hidden (view full) --- 213 panic("need to implement bus address support"); 214#if 0 215 kern_ptr = bus_to_virt(kern_sglist[j].addr); 216#endif 217 } else 218 kern_ptr = (uint8_t *)kern_sglist[j].addr; 219 kern_ptr = kern_ptr + kern_watermark; 220 | 199 for (i = ext_sg_start, j = 0; 200 i < ext_sg_entries && j < kern_sg_entries;) { 201 uint8_t *ext_ptr, *kern_ptr; 202 203 len_to_copy = min(ext_sglist[i].len - ext_watermark, 204 kern_sglist[j].len - kern_watermark); 205 206 ext_ptr = (uint8_t *)ext_sglist[i].addr; --- 5 unchanged lines hidden (view full) --- 212 panic("need to implement bus address support"); 213#if 0 214 kern_ptr = bus_to_virt(kern_sglist[j].addr); 215#endif 216 } else 217 kern_ptr = (uint8_t *)kern_sglist[j].addr; 218 kern_ptr = kern_ptr + kern_watermark; 219 |
221 kern_watermark += len_to_copy; 222 ext_watermark += len_to_copy; 223 | |
224 if ((ctsio->io_hdr.flags & CTL_FLAG_DATA_MASK) == 225 CTL_FLAG_DATA_IN) { 226 CTL_DEBUG_PRINT(("%s: copying %d bytes to user\n", 227 __func__, len_to_copy)); 228 CTL_DEBUG_PRINT(("%s: from %p to %p\n", __func__, 229 kern_ptr, ext_ptr)); 230 memcpy(ext_ptr, kern_ptr, len_to_copy); 231 } else { 232 CTL_DEBUG_PRINT(("%s: copying %d bytes from user\n", 233 __func__, len_to_copy)); 234 CTL_DEBUG_PRINT(("%s: from %p to %p\n", __func__, 235 ext_ptr, kern_ptr)); 236 memcpy(kern_ptr, ext_ptr, len_to_copy); 237 } 238 | 220 if ((ctsio->io_hdr.flags & CTL_FLAG_DATA_MASK) == 221 CTL_FLAG_DATA_IN) { 222 CTL_DEBUG_PRINT(("%s: copying %d bytes to user\n", 223 __func__, len_to_copy)); 224 CTL_DEBUG_PRINT(("%s: from %p to %p\n", __func__, 225 kern_ptr, ext_ptr)); 226 memcpy(ext_ptr, kern_ptr, len_to_copy); 227 } else { 228 CTL_DEBUG_PRINT(("%s: copying %d bytes from user\n", 229 __func__, len_to_copy)); 230 CTL_DEBUG_PRINT(("%s: from %p to %p\n", __func__, 231 ext_ptr, kern_ptr)); 232 memcpy(kern_ptr, ext_ptr, len_to_copy); 233 } 234 |
239 len_copied += len_to_copy; | 235 ctsio->ext_data_filled += len_to_copy; 236 ctsio->kern_data_resid -= len_to_copy; |
240 | 237 |
238 ext_watermark += len_to_copy; |
|
241 if (ext_sglist[i].len == ext_watermark) { 242 i++; 243 ext_watermark = 0; 244 } 245 | 239 if (ext_sglist[i].len == ext_watermark) { 240 i++; 241 ext_watermark = 0; 242 } 243 |
244 kern_watermark += len_to_copy; |
|
246 if (kern_sglist[j].len == kern_watermark) { 247 j++; 248 kern_watermark = 0; 249 } 250 } 251 | 245 if (kern_sglist[j].len == kern_watermark) { 246 j++; 247 kern_watermark = 0; 248 } 249 } 250 |
252 ctsio->ext_data_filled += len_copied; 253 | |
254 CTL_DEBUG_PRINT(("%s: ext_sg_entries: %d, kern_sg_entries: %d\n", 255 __func__, ext_sg_entries, kern_sg_entries)); 256 CTL_DEBUG_PRINT(("%s: ext_data_len = %d, kern_data_len = %d\n", 257 __func__, ctsio->ext_data_len, ctsio->kern_data_len)); 258 | 251 CTL_DEBUG_PRINT(("%s: ext_sg_entries: %d, kern_sg_entries: %d\n", 252 __func__, ext_sg_entries, kern_sg_entries)); 253 CTL_DEBUG_PRINT(("%s: ext_data_len = %d, kern_data_len = %d\n", 254 __func__, ctsio->ext_data_len, ctsio->kern_data_len)); 255 |
259 /* XXX KDM set residual?? */ | |
260bailout: 261 io->scsiio.be_move_done(io); 262} 263 264static void 265tpcl_done(union ctl_io *io) 266{ 267 --- 68 unchanged lines hidden --- | 256bailout: 257 io->scsiio.be_move_done(io); 258} 259 260static void 261tpcl_done(union ctl_io *io) 262{ 263 --- 68 unchanged lines hidden --- |