53 |
|
const int SENSE_LENGTH = 256; |
54 |
|
static UBYTE *sense_buffer = NULL; // Buffer for autosense data |
55 |
|
|
56 |
+ |
static bool direct_transfers_supported = false; // Direct data transfers (bypassing the buffer) are supported |
57 |
+ |
|
58 |
|
|
59 |
|
/* |
60 |
|
* Initialization |
71 |
|
break; |
72 |
|
case 2: |
73 |
|
buffer_memf = MEMF_ANY | MEMF_PUBLIC; |
74 |
+ |
direct_transfers_supported = true; |
75 |
|
break; |
76 |
|
default: |
77 |
|
buffer_memf = MEMF_CHIP | MEMF_PUBLIC; |
215 |
|
|
216 |
|
bool scsi_send_cmd(size_t data_length, bool reading, int sg_size, uint8 **sg_ptr, uint32 *sg_len, uint16 *stat, uint32 timeout) |
217 |
|
{ |
218 |
< |
// Check if buffer is large enough, allocate new buffer if needed |
219 |
< |
if (!try_buffer(data_length)) { |
220 |
< |
char str[256]; |
221 |
< |
sprintf(str, GetString(STR_SCSI_BUFFER_ERR), data_length); |
222 |
< |
ErrorAlert(str); |
223 |
< |
return false; |
224 |
< |
} |
218 |
> |
// Bypass the buffer if there's only one S/G table entry |
219 |
> |
bool do_direct_transfer = (sg_size == 1 && ((uint32)sg_ptr[0] & 1) == 0 && direct_transfers_supported); |
220 |
> |
|
221 |
> |
if (!do_direct_transfer) { |
222 |
> |
|
223 |
> |
// Check if buffer is large enough, allocate new buffer if needed |
224 |
> |
if (!try_buffer(data_length)) { |
225 |
> |
char str[256]; |
226 |
> |
sprintf(str, GetString(STR_SCSI_BUFFER_ERR), data_length); |
227 |
> |
ErrorAlert(str); |
228 |
> |
return false; |
229 |
> |
} |
230 |
|
|
231 |
< |
// Process S/G table when writing |
232 |
< |
if (!reading) { |
233 |
< |
D(bug(" writing to buffer\n")); |
234 |
< |
uint8 *buffer_ptr = buffer; |
235 |
< |
for (int i=0; i<sg_size; i++) { |
236 |
< |
uint32 len = sg_len[i]; |
237 |
< |
D(bug(" %d bytes from %08lx\n", len, sg_ptr[i])); |
238 |
< |
memcpy(buffer_ptr, sg_ptr[i], len); |
239 |
< |
buffer_ptr += len; |
231 |
> |
// Process S/G table when writing |
232 |
> |
if (!reading) { |
233 |
> |
D(bug(" writing to buffer\n")); |
234 |
> |
uint8 *buffer_ptr = buffer; |
235 |
> |
for (int i=0; i<sg_size; i++) { |
236 |
> |
uint32 len = sg_len[i]; |
237 |
> |
D(bug(" %d bytes from %08lx\n", len, sg_ptr[i])); |
238 |
> |
memcpy(buffer_ptr, sg_ptr[i], len); |
239 |
> |
buffer_ptr += len; |
240 |
> |
} |
241 |
|
} |
242 |
|
} |
243 |
|
|
249 |
|
D(bug(" autosense\n")); |
250 |
|
memcpy(buffer, sense_buffer, scsi.scsi_SenseActual); |
251 |
|
scsi.scsi_Status = 0; |
252 |
+ |
do_direct_transfer = false; |
253 |
|
|
254 |
|
} else { |
255 |
|
|
256 |
|
// No, send regular command |
257 |
|
D(bug(" sending command, length %ld\n", data_length)); |
258 |
< |
scsi.scsi_Data = (UWORD *)buffer; |
259 |
< |
scsi.scsi_Length = data_length; |
258 |
> |
if (do_direct_transfer) { |
259 |
> |
scsi.scsi_Data = (UWORD *)sg_ptr[0]; |
260 |
> |
scsi.scsi_Length = sg_len[0]; |
261 |
> |
} else { |
262 |
> |
scsi.scsi_Data = (UWORD *)buffer; |
263 |
> |
scsi.scsi_Length = data_length; |
264 |
> |
} |
265 |
|
scsi.scsi_Actual = 0; |
266 |
|
scsi.scsi_Flags = (reading ? SCSIF_READ : SCSIF_WRITE) | SCSIF_AUTOSENSE; |
267 |
|
scsi.scsi_SenseActual = 0; |
271 |
|
*stat = scsi.scsi_Status; |
272 |
|
} |
273 |
|
|
274 |
< |
// Process S/G table when reading |
275 |
< |
if (reading && res == 0) { |
276 |
< |
D(bug(" reading from buffer\n")); |
277 |
< |
uint8 *buffer_ptr = buffer; |
278 |
< |
for (int i=0; i<sg_size; i++) { |
279 |
< |
uint32 len = sg_len[i]; |
280 |
< |
D(bug(" %d bytes to %08lx\n", len, sg_ptr[i])); |
281 |
< |
memcpy(sg_ptr[i], buffer_ptr, len); |
282 |
< |
buffer_ptr += len; |
274 |
> |
if (!do_direct_transfer) { |
275 |
> |
|
276 |
> |
// Process S/G table when reading |
277 |
> |
if (reading && res == 0) { |
278 |
> |
D(bug(" reading from buffer\n")); |
279 |
> |
uint8 *buffer_ptr = buffer; |
280 |
> |
for (int i=0; i<sg_size; i++) { |
281 |
> |
uint32 len = sg_len[i]; |
282 |
> |
D(bug(" %d bytes to %08lx\n", len, sg_ptr[i])); |
283 |
> |
memcpy(sg_ptr[i], buffer_ptr, len); |
284 |
> |
buffer_ptr += len; |
285 |
> |
} |
286 |
|
} |
287 |
|
} |
288 |
|
return res == 0; |