1 // Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
2 // Copyright (C) 2014 Doug Brown <doug@downtowndougbrown.com>
4 // This file is part of SCSI2SD.
6 // SCSI2SD is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SCSI2SD is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
19 #include "stm32f2xx.h"
37 if (blockDev
.state
& DISK_PRESENT
)
39 blockDev
.state
= blockDev
.state
| DISK_INITIALISED
;
44 // Callback once all data has been read in the data out phase.
45 static void doFormatUnitComplete(void)
47 // TODO start writing the initialisation pattern to the SD
49 scsiDev
.phase
= STATUS
;
52 static void doFormatUnitSkipData(int bytes
)
54 // We may not have enough memory to store the initialisation pattern and
55 // defect list data. Since we're not making use of it yet anyway, just
57 scsiEnterPhase(DATA_OUT
);
59 for (i
= 0; i
< bytes
; ++i
)
65 // Callback from the data out phase.
66 static void doFormatUnitPatternHeader(void)
69 ((((uint16_t)scsiDev
.data
[2])) << 8) +
73 ((((uint16_t)scsiDev
.data
[4 + 2])) << 8) +
76 doFormatUnitSkipData(defectLength
+ patternLength
);
77 doFormatUnitComplete();
80 // Callback from the data out phase.
81 static void doFormatUnitHeader(void)
83 int IP
= (scsiDev
.data
[1] & 0x08) ? 1 : 0;
84 int DSP
= (scsiDev
.data
[1] & 0x04) ? 1 : 0;
86 if (! DSP
) // disable save parameters
88 // Save the "MODE SELECT savable parameters"
90 scsiDev
.target
->targetId
,
91 scsiDev
.target
->liveCfg
.bytesPerSector
);
96 // We need to read the initialisation pattern header first.
98 scsiDev
.phase
= DATA_OUT
;
99 scsiDev
.postDataOutHook
= doFormatUnitPatternHeader
;
103 // Read the defect list data
105 ((((uint16_t)scsiDev
.data
[2])) << 8) +
107 doFormatUnitSkipData(defectLength
);
108 doFormatUnitComplete();
112 static void doReadCapacity()
114 uint32_t lba
= (((uint32_t) scsiDev
.cdb
[2]) << 24) +
115 (((uint32_t) scsiDev
.cdb
[3]) << 16) +
116 (((uint32_t) scsiDev
.cdb
[4]) << 8) +
118 int pmi
= scsiDev
.cdb
[8] & 1;
120 uint32_t capacity
= getScsiCapacity(
121 scsiDev
.target
->cfg
->sdSectorStart
,
122 scsiDev
.target
->liveCfg
.bytesPerSector
,
123 scsiDev
.target
->cfg
->scsiSectors
);
128 // We don't do anything with the "partial medium indicator", and
129 // assume that delays are constant across each block. But the spec
130 // says we must return this error if pmi is specified incorrectly.
131 scsiDev
.status
= CHECK_CONDITION
;
132 scsiDev
.target
->sense
.code
= ILLEGAL_REQUEST
;
133 scsiDev
.target
->sense
.asc
= INVALID_FIELD_IN_CDB
;
134 scsiDev
.phase
= STATUS
;
136 else if (capacity
> 0)
138 uint32_t highestBlock
= capacity
- 1;
140 scsiDev
.data
[0] = highestBlock
>> 24;
141 scsiDev
.data
[1] = highestBlock
>> 16;
142 scsiDev
.data
[2] = highestBlock
>> 8;
143 scsiDev
.data
[3] = highestBlock
;
145 uint32_t bytesPerSector
= scsiDev
.target
->liveCfg
.bytesPerSector
;
146 scsiDev
.data
[4] = bytesPerSector
>> 24;
147 scsiDev
.data
[5] = bytesPerSector
>> 16;
148 scsiDev
.data
[6] = bytesPerSector
>> 8;
149 scsiDev
.data
[7] = bytesPerSector
;
151 scsiDev
.phase
= DATA_IN
;
155 scsiDev
.status
= CHECK_CONDITION
;
156 scsiDev
.target
->sense
.code
= NOT_READY
;
157 scsiDev
.target
->sense
.asc
= MEDIUM_NOT_PRESENT
;
158 scsiDev
.phase
= STATUS
;
162 static void doWrite(uint32_t lba
, uint32_t blocks
)
164 if (unlikely(scsiDev
.target
->cfg
->deviceType
== S2S_CFG_FLOPPY_14MB
)) {
165 // Floppies are supposed to be slow. Some systems can't handle a floppy
166 // without an access time
170 uint32_t bytesPerSector
= scsiDev
.target
->liveCfg
.bytesPerSector
;
172 if (unlikely(blockDev
.state
& DISK_WP
) ||
173 unlikely(scsiDev
.target
->cfg
->deviceType
== S2S_CFG_OPTICAL
))
176 scsiDev
.status
= CHECK_CONDITION
;
177 scsiDev
.target
->sense
.code
= ILLEGAL_REQUEST
;
178 scsiDev
.target
->sense
.asc
= WRITE_PROTECTED
;
179 scsiDev
.phase
= STATUS
;
181 else if (unlikely(((uint64_t) lba
) + blocks
>
183 scsiDev
.target
->cfg
->sdSectorStart
,
185 scsiDev
.target
->cfg
->scsiSectors
189 scsiDev
.status
= CHECK_CONDITION
;
190 scsiDev
.target
->sense
.code
= ILLEGAL_REQUEST
;
191 scsiDev
.target
->sense
.asc
= LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE
;
192 scsiDev
.phase
= STATUS
;
197 transfer
.blocks
= blocks
;
198 transfer
.currentBlock
= 0;
199 scsiDev
.phase
= DATA_OUT
;
200 scsiDev
.dataLen
= bytesPerSector
;
201 scsiDev
.dataPtr
= bytesPerSector
;
203 // No need for single-block writes atm. Overhead of the
204 // multi-block write is minimal.
205 transfer
.multiBlock
= 1;
208 // TODO uint32_t sdLBA =
209 // TODO SCSISector2SD(
210 // TODO scsiDev.target->cfg->sdSectorStart,
211 // TODO bytesPerSector,
213 // TODO uint32_t sdBlocks = blocks * SDSectorsPerSCSISector(bytesPerSector);
214 // TODO sdWriteMultiSectorPrep(sdLBA, sdBlocks);
219 static void doRead(uint32_t lba
, uint32_t blocks
)
221 if (unlikely(scsiDev
.target
->cfg
->deviceType
== S2S_CFG_FLOPPY_14MB
)) {
222 // Floppies are supposed to be slow. Some systems can't handle a floppy
223 // without an access time
227 uint32_t capacity
= getScsiCapacity(
228 scsiDev
.target
->cfg
->sdSectorStart
,
229 scsiDev
.target
->liveCfg
.bytesPerSector
,
230 scsiDev
.target
->cfg
->scsiSectors
);
231 if (unlikely(((uint64_t) lba
) + blocks
> capacity
))
233 scsiDev
.status
= CHECK_CONDITION
;
234 scsiDev
.target
->sense
.code
= ILLEGAL_REQUEST
;
235 scsiDev
.target
->sense
.asc
= LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE
;
236 scsiDev
.phase
= STATUS
;
241 transfer
.blocks
= blocks
;
242 transfer
.currentBlock
= 0;
243 scsiDev
.phase
= DATA_IN
;
244 scsiDev
.dataLen
= 0; // No data yet
246 uint32_t bytesPerSector
= scsiDev
.target
->liveCfg
.bytesPerSector
;
247 uint32_t sdSectorPerSCSISector
= SDSectorsPerSCSISector(bytesPerSector
);
249 blocks
* sdSectorPerSCSISector
;
253 !(scsiDev
.boardCfg
.flags
& S2S_CFG_ENABLE_CACHE
)
255 unlikely(((uint64_t) lba
) + blocks
== capacity
)
258 // We get errors on reading the last sector using a multi-sector
260 transfer
.multiBlock
= 0;
264 transfer
.multiBlock
= 1;
268 // scsiDev.target->cfg->sdSectorStart,
272 // TODO sdReadMultiSectorPrep(sdLBA, sdSectors);
277 static void doSeek(uint32_t lba
)
281 scsiDev
.target
->cfg
->sdSectorStart
,
282 scsiDev
.target
->liveCfg
.bytesPerSector
,
283 scsiDev
.target
->cfg
->scsiSectors
)
286 scsiDev
.status
= CHECK_CONDITION
;
287 scsiDev
.target
->sense
.code
= ILLEGAL_REQUEST
;
288 scsiDev
.target
->sense
.asc
= LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE
;
289 scsiDev
.phase
= STATUS
;
293 static int doTestUnitReady()
296 if (likely(blockDev
.state
== (DISK_STARTED
| DISK_PRESENT
| DISK_INITIALISED
)))
300 else if (unlikely(!(blockDev
.state
& DISK_STARTED
)))
303 scsiDev
.status
= CHECK_CONDITION
;
304 scsiDev
.target
->sense
.code
= NOT_READY
;
305 scsiDev
.target
->sense
.asc
= LOGICAL_UNIT_NOT_READY_INITIALIZING_COMMAND_REQUIRED
;
306 scsiDev
.phase
= STATUS
;
308 else if (unlikely(!(blockDev
.state
& DISK_PRESENT
)))
311 scsiDev
.status
= CHECK_CONDITION
;
312 scsiDev
.target
->sense
.code
= NOT_READY
;
313 scsiDev
.target
->sense
.asc
= MEDIUM_NOT_PRESENT
;
314 scsiDev
.phase
= STATUS
;
316 else if (unlikely(!(blockDev
.state
& DISK_INITIALISED
)))
319 scsiDev
.status
= CHECK_CONDITION
;
320 scsiDev
.target
->sense
.code
= NOT_READY
;
321 scsiDev
.target
->sense
.asc
= LOGICAL_UNIT_NOT_READY_CAUSE_NOT_REPORTABLE
;
322 scsiDev
.phase
= STATUS
;
327 // Handle direct-access scsi device commands
328 int scsiDiskCommand()
330 int commandHandled
= 1;
332 uint8_t command
= scsiDev
.cdb
[0];
333 if (unlikely(command
== 0x1B))
336 // Enable or disable media access operations.
337 // Ignore load/eject requests. We can't do that.
338 //int immed = scsiDev.cdb[1] & 1;
339 int start
= scsiDev
.cdb
[4] & 1;
343 blockDev
.state
= blockDev
.state
| DISK_STARTED
;
344 if (!(blockDev
.state
& DISK_INITIALISED
))
351 blockDev
.state
&= ~DISK_STARTED
;
354 else if (unlikely(command
== 0x00))
359 else if (unlikely(!doTestUnitReady()))
361 // Status and sense codes already set by doTestUnitReady
363 else if (likely(command
== 0x08))
367 (((uint32_t) scsiDev
.cdb
[1] & 0x1F) << 16) +
368 (((uint32_t) scsiDev
.cdb
[2]) << 8) +
370 uint32_t blocks
= scsiDev
.cdb
[4];
371 if (unlikely(blocks
== 0)) blocks
= 256;
374 else if (likely(command
== 0x28))
377 // Ignore all cache control bits - we don't support a memory cache.
380 (((uint32_t) scsiDev
.cdb
[2]) << 24) +
381 (((uint32_t) scsiDev
.cdb
[3]) << 16) +
382 (((uint32_t) scsiDev
.cdb
[4]) << 8) +
385 (((uint32_t) scsiDev
.cdb
[7]) << 8) +
390 else if (likely(command
== 0x0A))
394 (((uint32_t) scsiDev
.cdb
[1] & 0x1F) << 16) +
395 (((uint32_t) scsiDev
.cdb
[2]) << 8) +
397 uint32_t blocks
= scsiDev
.cdb
[4];
398 if (unlikely(blocks
== 0)) blocks
= 256;
399 doWrite(lba
, blocks
);
401 else if (likely(command
== 0x2A) || // WRITE(10)
402 unlikely(command
== 0x2E)) // WRITE AND VERIFY
404 // Ignore all cache control bits - we don't support a memory cache.
405 // Don't bother verifying either. The SD card likely stores ECC
406 // along with each flash row.
409 (((uint32_t) scsiDev
.cdb
[2]) << 24) +
410 (((uint32_t) scsiDev
.cdb
[3]) << 16) +
411 (((uint32_t) scsiDev
.cdb
[4]) << 8) +
414 (((uint32_t) scsiDev
.cdb
[7]) << 8) +
417 doWrite(lba
, blocks
);
419 else if (unlikely(command
== 0x04))
422 // We don't really do any formatting, but we need to read the correct
423 // number of bytes in the DATA_OUT phase to make the SCSI host happy.
425 int fmtData
= (scsiDev
.cdb
[1] & 0x10) ? 1 : 0;
428 // We need to read the parameter list, but we don't know how
429 // big it is yet. Start with the header.
431 scsiDev
.phase
= DATA_OUT
;
432 scsiDev
.postDataOutHook
= doFormatUnitHeader
;
436 // No data to read, we're already finished!
439 else if (unlikely(command
== 0x25))
444 else if (unlikely(command
== 0x0B))
448 (((uint32_t) scsiDev
.cdb
[1] & 0x1F) << 16) +
449 (((uint32_t) scsiDev
.cdb
[2]) << 8) +
455 else if (unlikely(command
== 0x2B))
459 (((uint32_t) scsiDev
.cdb
[2]) << 24) +
460 (((uint32_t) scsiDev
.cdb
[3]) << 16) +
461 (((uint32_t) scsiDev
.cdb
[4]) << 8) +
466 else if (unlikely(command
== 0x36))
469 // We don't have a cache to lock data into. do nothing.
471 else if (unlikely(command
== 0x34))
474 // We don't have a cache to pre-fetch into. do nothing.
476 else if (unlikely(command
== 0x1E))
478 // PREVENT ALLOW MEDIUM REMOVAL
479 // Not much we can do to prevent the user removing the SD card.
482 else if (unlikely(command
== 0x01))
485 // Set the lun to a vendor-specific state. Ignore.
487 else if (unlikely(command
== 0x35))
490 // We don't have a cache. do nothing.
492 else if (unlikely(command
== 0x2F))
495 // TODO: When they supply data to verify, we should read the data and
496 // verify it. If they don't supply any data, just say success.
497 if ((scsiDev
.cdb
[1] & 0x02) == 0)
499 // They are asking us to do a medium verification with no data
500 // comparison. Assume success, do nothing.
504 // TODO. This means they are supplying data to verify against.
505 // Technically we should probably grab the data and compare it.
506 scsiDev
.status
= CHECK_CONDITION
;
507 scsiDev
.target
->sense
.code
= ILLEGAL_REQUEST
;
508 scsiDev
.target
->sense
.asc
= INVALID_FIELD_IN_CDB
;
509 scsiDev
.phase
= STATUS
;
512 else if (unlikely(command
== 0x37))
515 scsiDev
.status
= CHECK_CONDITION
;
516 scsiDev
.target
->sense
.code
= NO_SENSE
;
517 scsiDev
.target
->sense
.asc
= DEFECT_LIST_NOT_FOUND
;
518 scsiDev
.phase
= STATUS
;
526 return commandHandled
;
531 uint32_t bytesPerSector
= scsiDev
.target
->liveCfg
.bytesPerSector
;
533 if (scsiDev
.phase
== DATA_IN
&&
534 transfer
.currentBlock
!= transfer
.blocks
)
536 scsiEnterPhase(DATA_IN
);
539 transfer
.blocks
* SDSectorsPerSCSISector(bytesPerSector
);
542 scsiDev
.target
->cfg
->sdSectorStart
,
546 const int sdPerScsi
= SDSectorsPerSCSISector(bytesPerSector
);
547 const int buffers
= sizeof(scsiDev
.data
) / SD_SECTOR_SIZE
;
550 int scsiActive
__attribute__((unused
)) = 0; // unused if DMA disabled
552 while ((i
< totalSDSectors
) &&
553 likely(scsiDev
.phase
== DATA_IN
) &&
554 likely(!scsiDev
.resetFlag
))
556 int completedDmaSectors
;
557 if (sdActive
&& (completedDmaSectors
= sdReadDMAPoll(sdActive
)))
559 prep
+= completedDmaSectors
;
560 sdActive
-= completedDmaSectors
;
561 } else if (sdActive
> 1) {
562 if (scsiDev
.data
[SD_SECTOR_SIZE
* (prep
% buffers
) + 511] != 0x33) {
569 (prep
- i
< buffers
) &&
570 (prep
< totalSDSectors
))
572 // Start an SD transfer if we have space.
573 uint32_t startBuffer
= prep
% buffers
;
574 uint32_t sectors
= totalSDSectors
- prep
;
576 uint32_t freeBuffers
= buffers
- (prep
- i
);
578 uint32_t contiguousBuffers
= buffers
- startBuffer
;
579 freeBuffers
= freeBuffers
< contiguousBuffers
580 ? freeBuffers
: contiguousBuffers
;
581 sectors
= sectors
< freeBuffers
? sectors
: freeBuffers
;
583 if (sectors
> 128) sectors
= 128; // 65536 DMA limit !!
585 for (int dodgy
= 0; dodgy
< sectors
; dodgy
++)
587 scsiDev
.data
[SD_SECTOR_SIZE
* (startBuffer
+ dodgy
) + 511] = 0x33;
590 sdReadDMA(sdLBA
+ prep
, sectors
, &scsiDev
.data
[SD_SECTOR_SIZE
* startBuffer
]);
596 if (scsiActive
&& scsiPhyComplete() && scsiWriteDMAPoll())
602 if (!scsiActive
&& ((prep
- i
) > 0))
604 int dmaBytes
= SD_SECTOR_SIZE
;
605 if ((i
% sdPerScsi
) == (sdPerScsi
- 1))
607 dmaBytes
= bytesPerSector
% SD_SECTOR_SIZE
;
608 if (dmaBytes
== 0) dmaBytes
= SD_SECTOR_SIZE
;
610 scsiWriteDMA(&scsiDev
.data
[SD_SECTOR_SIZE
* (i
% buffers
)], dmaBytes
);
616 int dmaBytes
= SD_SECTOR_SIZE
;
617 if ((i
% sdPerScsi
) == (sdPerScsi
- 1))
619 dmaBytes
= bytesPerSector
% SD_SECTOR_SIZE
;
620 if (dmaBytes
== 0) dmaBytes
= SD_SECTOR_SIZE
;
622 for (int k
= 0; k
< dmaBytes
; ++k
)
624 scsiPhyTx(scsiDev
.data
[SD_SECTOR_SIZE
* (i
% buffers
) + k
]);
627 while (!scsiPhyComplete() && !scsiDev
.resetFlag
) {}
633 // We've finished transferring the data to the FPGA, now wait until it's
634 // written to he SCSI bus.
635 while (!scsiPhyComplete() &&
636 likely(scsiDev
.phase
== DATA_IN
) &&
637 likely(!scsiDev
.resetFlag
))
642 if (scsiDev
.phase
== DATA_IN
)
644 scsiDev
.phase
= STATUS
;
648 else if (scsiDev
.phase
== DATA_OUT
&&
649 transfer
.currentBlock
!= transfer
.blocks
)
651 scsiEnterPhase(DATA_OUT
);
653 const int sdPerScsi
= SDSectorsPerSCSISector(bytesPerSector
);
654 int totalSDSectors
= transfer
.blocks
* sdPerScsi
;
657 scsiDev
.target
->cfg
->sdSectorStart
,
660 // int buffers = sizeof(scsiDev.data) / SD_SECTOR_SIZE;
663 // int scsiDisconnected = 0;
664 int scsiComplete
= 0;
665 // uint32_t lastActivityTime = s2s_getTime_ms();
666 // int scsiActive = 0;
669 while ((i
< totalSDSectors
) &&
670 (likely(scsiDev
.phase
== DATA_OUT
) || // scsiDisconnect keeps our phase.
672 likely(!scsiDev
.resetFlag
))
674 // Well, until we have some proper non-blocking SD code, we must
675 // do this in a half-duplex fashion. We need to write as much as
676 // possible in each SD card transaction.
677 uint32_t maxSectors
= sizeof(scsiDev
.data
) / SD_SECTOR_SIZE
;
678 uint32_t rem
= totalSDSectors
- i
;
680 rem
< maxSectors
? rem
: maxSectors
;
681 scsiRead(&scsiDev
.data
[0], sectors
* SD_SECTOR_SIZE
);
682 sdTmpWrite(&scsiDev
.data
[0], i
+ sdLBA
, sectors
);
685 // Wait for the next DMA interrupt. It's beneficial to halt the
686 // processor to give the DMA controller more memory bandwidth to
690 while (scsiBusy
&& sdBusy
)
692 uint8_t intr
= CyEnterCriticalSection();
693 scsiBusy
= scsiDMABusy();
694 sdBusy
= sdDMABusy();
695 if (scsiBusy
&& sdBusy
)
699 CyExitCriticalSection(intr
);
702 if (sdActive
&& !sdBusy
&& sdWriteSectorDMAPoll())
707 if (!sdActive
&& ((prep
- i
) > 0))
709 // Start an SD transfer if we have space.
710 sdWriteMultiSectorDMA(&scsiDev
.data
[SD_SECTOR_SIZE
* (i
% buffers
)]);
714 uint32_t now
= getTime_ms();
716 if (scsiActive
&& !scsiBusy
&& scsiReadDMAPoll())
720 lastActivityTime
= now
;
723 ((prep
- i
) < buffers
) &&
724 (prep
< totalSDSectors
) &&
725 likely(!scsiDisconnected
))
727 int dmaBytes
= SD_SECTOR_SIZE
;
728 if ((prep
% sdPerScsi
) == (sdPerScsi
- 1))
730 dmaBytes
= bytesPerSector
% SD_SECTOR_SIZE
;
731 if (dmaBytes
== 0) dmaBytes
= SD_SECTOR_SIZE
;
733 scsiReadDMA(&scsiDev
.data
[SD_SECTOR_SIZE
* (prep
% buffers
)], dmaBytes
);
737 (scsiDev
.boardCfg
.flags
& CONFIG_ENABLE_DISCONNECT
) &&
739 likely(!scsiDisconnected
) &&
740 unlikely(scsiDev
.discPriv
) &&
741 unlikely(diffTime_ms(lastActivityTime
, now
) >= 20) &&
742 likely(scsiDev
.phase
== DATA_OUT
))
744 // We're transferring over the SCSI bus faster than the SD card
745 // can write. There is no more buffer space once we've finished
746 // this SCSI transfer.
747 // The NCR 53C700 interface chips have a 250ms "byte-to-byte"
748 // timeout buffer. SD card writes are supposed to complete
749 // within 200ms, but sometimes they don't.
750 // The NCR 53C700 series is used on HP 9000 workstations.
752 scsiDisconnected
= 1;
753 lastActivityTime
= getTime_ms();
755 else if (unlikely(scsiDisconnected
) &&
757 (prep
== i
) || // Buffers empty.
758 // Send some messages every 100ms so we don't timeout.
759 // At a minimum, a reselection involves an IDENTIFY message.
760 unlikely(diffTime_ms(lastActivityTime
, now
) >= 100)
763 int reconnected
= scsiReconnect();
766 scsiDisconnected
= 0;
767 lastActivityTime
= getTime_ms(); // Don't disconnect immediately.
769 else if (diffTime_ms(lastActivityTime
, getTime_ms()) >= 10000)
771 // Give up after 10 seconds of trying to reconnect.
772 scsiDev
.resetFlag
= 1;
776 likely(!scsiComplete
) &&
778 (prep
== totalSDSectors
) && // All scsi data read and buffered
779 likely(!scsiDev
.discPriv
) && // Prefer disconnect where possible.
780 unlikely(diffTime_ms(lastActivityTime
, now
) >= 150) &&
782 likely(scsiDev
.phase
== DATA_OUT
) &&
783 !(scsiDev
.cdb
[scsiDev
.cdbLen
- 1] & 0x01) // Not linked command
786 // We're transferring over the SCSI bus faster than the SD card
787 // can write. All data is buffered, and we're just waiting for
788 // the SD card to complete. The host won't let us disconnect.
789 // Some drivers set a 250ms timeout on transfers to complete.
790 // SD card writes are supposed to complete
791 // within 200ms, but sometimes they don'to.
792 // Just pretend we're finished.
796 process_MessageIn(); // Will go to BUS_FREE state
798 // Try and prevent anyone else using the SCSI bus while we're not ready.
799 SCSI_SetPin(SCSI_Out_BSY
);
807 SCSI_ClearPin(SCSI_Out_BSY
);
810 !scsiDev
.resetFlag
&&
811 unlikely(scsiDisconnected
) &&
812 (s2s_elapsedTime_ms(lastActivityTime
) <= 10000))
814 scsiDisconnected
= !scsiReconnect();
816 if (scsiDisconnected
)
818 // Failed to reconnect
819 scsiDev
.resetFlag
= 1;
823 if (scsiDev
.phase
== DATA_OUT
)
825 if (scsiDev
.parityError
&&
826 (scsiDev
.boardCfg
.flags
& S2S_CFG_ENABLE_PARITY
) &&
827 (scsiDev
.compatMode
>= COMPAT_SCSI2
))
829 scsiDev
.target
->sense
.code
= ABORTED_COMMAND
;
830 scsiDev
.target
->sense
.asc
= SCSI_PARITY_ERROR
;
831 scsiDev
.status
= CHECK_CONDITION
;;
833 scsiDev
.phase
= STATUS
;
842 scsiDev
.savedDataPtr
= 0;
844 // transfer.lba = 0; // Needed in Request Sense to determine failure
846 transfer
.currentBlock
= 0;
848 // Cancel long running commands!
851 ((scsiDev
.boardCfg
.flags
& S2S_CFG_ENABLE_CACHE
) == 0) ||
852 (transfer
.multiBlock
== 0)
856 sdCompleteTransfer();
859 transfer
.multiBlock
= 0;
866 // Don't require the host to send us a START STOP UNIT command
867 blockDev
.state
= DISK_STARTED
;