1 // Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
\r
2 // Copyright (C) 2014 Doug Brown <doug@downtowndougbrown.com>
\r
4 // This file is part of SCSI2SD.
\r
6 // SCSI2SD is free software: you can redistribute it and/or modify
\r
7 // it under the terms of the GNU General Public License as published by
\r
8 // the Free Software Foundation, either version 3 of the License, or
\r
9 // (at your option) any later version.
\r
11 // SCSI2SD is distributed in the hope that it will be useful,
\r
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 // GNU General Public License for more details.
\r
16 // You should have received a copy of the GNU General Public License
\r
17 // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
\r
18 #pragma GCC push_options
\r
19 #pragma GCC optimize("-flto")
\r
23 #include "scsiPhy.h"
\r
34 BlockDevice blockDev;
\r
37 static int doSdInit()
\r
40 if (blockDev.state & DISK_PRESENT)
\r
46 blockDev.state = blockDev.state | DISK_INITIALISED;
\r
52 // Callback once all data has been read in the data out phase.
\r
53 static void doFormatUnitComplete(void)
\r
55 // TODO start writing the initialisation pattern to the SD
\r
57 scsiDev.phase = STATUS;
\r
60 static void doFormatUnitSkipData(int bytes)
\r
62 // We may not have enough memory to store the initialisation pattern and
\r
63 // defect list data. Since we're not making use of it yet anyway, just
\r
64 // discard the bytes.
\r
65 scsiEnterPhase(DATA_OUT);
\r
67 for (i = 0; i < bytes; ++i)
\r
73 // Callback from the data out phase.
\r
74 static void doFormatUnitPatternHeader(void)
\r
77 ((((uint16_t)scsiDev.data[2])) << 8) +
\r
81 ((((uint16_t)scsiDev.data[4 + 2])) << 8) +
\r
82 scsiDev.data[4 + 3];
\r
84 doFormatUnitSkipData(defectLength + patternLength);
\r
85 doFormatUnitComplete();
\r
88 // Callback from the data out phase.
\r
89 static void doFormatUnitHeader(void)
\r
91 int IP = (scsiDev.data[1] & 0x08) ? 1 : 0;
\r
92 int DSP = (scsiDev.data[1] & 0x04) ? 1 : 0;
\r
94 if (! DSP) // disable save parameters
\r
96 // Save the "MODE SELECT savable parameters"
\r
98 scsiDev.target->targetId,
\r
99 scsiDev.target->liveCfg.bytesPerSector);
\r
104 // We need to read the initialisation pattern header first.
\r
105 scsiDev.dataLen += 4;
\r
106 scsiDev.phase = DATA_OUT;
\r
107 scsiDev.postDataOutHook = doFormatUnitPatternHeader;
\r
111 // Read the defect list data
\r
113 ((((uint16_t)scsiDev.data[2])) << 8) +
\r
115 doFormatUnitSkipData(defectLength);
\r
116 doFormatUnitComplete();
\r
120 static void doReadCapacity()
\r
122 uint32_t lba = (((uint32) scsiDev.cdb[2]) << 24) +
\r
123 (((uint32) scsiDev.cdb[3]) << 16) +
\r
124 (((uint32) scsiDev.cdb[4]) << 8) +
\r
126 int pmi = scsiDev.cdb[8] & 1;
\r
128 uint32_t capacity = getScsiCapacity(
\r
129 scsiDev.target->cfg->sdSectorStart,
\r
130 scsiDev.target->liveCfg.bytesPerSector,
\r
131 scsiDev.target->cfg->scsiSectors);
\r
136 // We don't do anything with the "partial medium indicator", and
\r
137 // assume that delays are constant across each block. But the spec
\r
138 // says we must return this error if pmi is specified incorrectly.
\r
139 scsiDev.status = CHECK_CONDITION;
\r
140 scsiDev.target->sense.code = ILLEGAL_REQUEST;
\r
141 scsiDev.target->sense.asc = INVALID_FIELD_IN_CDB;
\r
142 scsiDev.phase = STATUS;
\r
144 else if (capacity > 0)
\r
146 uint32_t highestBlock = capacity - 1;
\r
148 scsiDev.data[0] = highestBlock >> 24;
\r
149 scsiDev.data[1] = highestBlock >> 16;
\r
150 scsiDev.data[2] = highestBlock >> 8;
\r
151 scsiDev.data[3] = highestBlock;
\r
153 uint32_t bytesPerSector = scsiDev.target->liveCfg.bytesPerSector;
\r
154 scsiDev.data[4] = bytesPerSector >> 24;
\r
155 scsiDev.data[5] = bytesPerSector >> 16;
\r
156 scsiDev.data[6] = bytesPerSector >> 8;
\r
157 scsiDev.data[7] = bytesPerSector;
\r
158 scsiDev.dataLen = 8;
\r
159 scsiDev.phase = DATA_IN;
\r
163 scsiDev.status = CHECK_CONDITION;
\r
164 scsiDev.target->sense.code = NOT_READY;
\r
165 scsiDev.target->sense.asc = MEDIUM_NOT_PRESENT;
\r
166 scsiDev.phase = STATUS;
\r
170 static void doWrite(uint32 lba, uint32 blocks)
\r
172 if (unlikely(blockDev.state & DISK_WP) ||
\r
173 unlikely(scsiDev.target->cfg->deviceType == CONFIG_OPTICAL))
\r
176 scsiDev.status = CHECK_CONDITION;
\r
177 scsiDev.target->sense.code = ILLEGAL_REQUEST;
\r
178 scsiDev.target->sense.asc = WRITE_PROTECTED;
\r
179 scsiDev.phase = STATUS;
\r
181 else if (unlikely(((uint64) lba) + blocks >
\r
183 scsiDev.target->cfg->sdSectorStart,
\r
184 scsiDev.target->liveCfg.bytesPerSector,
\r
185 scsiDev.target->cfg->scsiSectors
\r
189 scsiDev.status = CHECK_CONDITION;
\r
190 scsiDev.target->sense.code = ILLEGAL_REQUEST;
\r
191 scsiDev.target->sense.asc = LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
\r
192 scsiDev.phase = STATUS;
\r
196 transfer.dir = TRANSFER_WRITE;
\r
197 transfer.lba = lba;
\r
198 transfer.blocks = blocks;
\r
199 transfer.currentBlock = 0;
\r
200 scsiDev.phase = DATA_OUT;
\r
201 scsiDev.dataLen = scsiDev.target->liveCfg.bytesPerSector;
\r
202 scsiDev.dataPtr = scsiDev.target->liveCfg.bytesPerSector;
\r
204 // No need for single-block writes atm. Overhead of the
\r
205 // multi-block write is minimal.
\r
206 transfer.multiBlock = 1;
\r
208 sdWriteMultiSectorPrep();
\r
213 static void doRead(uint32 lba, uint32 blocks)
\r
215 uint32_t capacity = getScsiCapacity(
\r
216 scsiDev.target->cfg->sdSectorStart,
\r
217 scsiDev.target->liveCfg.bytesPerSector,
\r
218 scsiDev.target->cfg->scsiSectors);
\r
219 if (unlikely(((uint64) lba) + blocks > capacity))
\r
221 scsiDev.status = CHECK_CONDITION;
\r
222 scsiDev.target->sense.code = ILLEGAL_REQUEST;
\r
223 scsiDev.target->sense.asc = LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
\r
224 scsiDev.phase = STATUS;
\r
228 transfer.dir = TRANSFER_READ;
\r
229 transfer.lba = lba;
\r
230 transfer.blocks = blocks;
\r
231 transfer.currentBlock = 0;
\r
232 scsiDev.phase = DATA_IN;
\r
233 scsiDev.dataLen = 0; // No data yet
\r
235 if ((blocks == 1) ||
\r
236 unlikely(((uint64) lba) + blocks == capacity)
\r
239 // We get errors on reading the last sector using a multi-sector
\r
241 transfer.multiBlock = 0;
\r
245 transfer.multiBlock = 1;
\r
246 sdReadMultiSectorPrep();
\r
251 static void doSeek(uint32 lba)
\r
255 scsiDev.target->cfg->sdSectorStart,
\r
256 scsiDev.target->liveCfg.bytesPerSector,
\r
257 scsiDev.target->cfg->scsiSectors)
\r
260 scsiDev.status = CHECK_CONDITION;
\r
261 scsiDev.target->sense.code = ILLEGAL_REQUEST;
\r
262 scsiDev.target->sense.asc = LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
\r
263 scsiDev.phase = STATUS;
\r
267 static int doTestUnitReady()
\r
270 if (likely(blockDev.state == (DISK_STARTED | DISK_PRESENT | DISK_INITIALISED)))
\r
274 else if (unlikely(!(blockDev.state & DISK_STARTED)))
\r
277 scsiDev.status = CHECK_CONDITION;
\r
278 scsiDev.target->sense.code = NOT_READY;
\r
279 scsiDev.target->sense.asc = LOGICAL_UNIT_NOT_READY_INITIALIZING_COMMAND_REQUIRED;
\r
280 scsiDev.phase = STATUS;
\r
282 else if (unlikely(!(blockDev.state & DISK_PRESENT)))
\r
285 scsiDev.status = CHECK_CONDITION;
\r
286 scsiDev.target->sense.code = NOT_READY;
\r
287 scsiDev.target->sense.asc = MEDIUM_NOT_PRESENT;
\r
288 scsiDev.phase = STATUS;
\r
290 else if (unlikely(!(blockDev.state & DISK_INITIALISED)))
\r
293 scsiDev.status = CHECK_CONDITION;
\r
294 scsiDev.target->sense.code = NOT_READY;
\r
295 scsiDev.target->sense.asc = LOGICAL_UNIT_NOT_READY_CAUSE_NOT_REPORTABLE;
\r
296 scsiDev.phase = STATUS;
\r
301 // Handle direct-access scsi device commands
\r
302 int scsiDiskCommand()
\r
304 int commandHandled = 1;
\r
306 uint8 command = scsiDev.cdb[0];
\r
307 if (unlikely(command == 0x1B))
\r
310 // Enable or disable media access operations.
\r
311 // Ignore load/eject requests. We can't do that.
\r
312 //int immed = scsiDev.cdb[1] & 1;
\r
313 int start = scsiDev.cdb[4] & 1;
\r
317 blockDev.state = blockDev.state | DISK_STARTED;
\r
318 if (!(blockDev.state & DISK_INITIALISED))
\r
325 blockDev.state &= ~DISK_STARTED;
\r
328 else if (unlikely(command == 0x00))
\r
333 else if (unlikely(!doTestUnitReady()))
\r
335 // Status and sense codes already set by doTestUnitReady
\r
337 else if (likely(command == 0x08))
\r
341 (((uint32) scsiDev.cdb[1] & 0x1F) << 16) +
\r
342 (((uint32) scsiDev.cdb[2]) << 8) +
\r
344 uint32 blocks = scsiDev.cdb[4];
\r
345 if (unlikely(blocks == 0)) blocks = 256;
\r
346 doRead(lba, blocks);
\r
348 else if (likely(command == 0x28))
\r
351 // Ignore all cache control bits - we don't support a memory cache.
\r
354 (((uint32) scsiDev.cdb[2]) << 24) +
\r
355 (((uint32) scsiDev.cdb[3]) << 16) +
\r
356 (((uint32) scsiDev.cdb[4]) << 8) +
\r
359 (((uint32) scsiDev.cdb[7]) << 8) +
\r
362 doRead(lba, blocks);
\r
364 else if (likely(command == 0x0A))
\r
368 (((uint32) scsiDev.cdb[1] & 0x1F) << 16) +
\r
369 (((uint32) scsiDev.cdb[2]) << 8) +
\r
371 uint32 blocks = scsiDev.cdb[4];
\r
372 if (unlikely(blocks == 0)) blocks = 256;
\r
373 doWrite(lba, blocks);
\r
375 else if (likely(command == 0x2A) || // WRITE(10)
\r
376 unlikely(command == 0x2E)) // WRITE AND VERIFY
\r
378 // Ignore all cache control bits - we don't support a memory cache.
\r
379 // Don't bother verifying either. The SD card likely stores ECC
\r
380 // along with each flash row.
\r
383 (((uint32) scsiDev.cdb[2]) << 24) +
\r
384 (((uint32) scsiDev.cdb[3]) << 16) +
\r
385 (((uint32) scsiDev.cdb[4]) << 8) +
\r
388 (((uint32) scsiDev.cdb[7]) << 8) +
\r
391 doWrite(lba, blocks);
\r
394 else if (unlikely(command == 0x04))
\r
397 // We don't really do any formatting, but we need to read the correct
\r
398 // number of bytes in the DATA_OUT phase to make the SCSI host happy.
\r
400 int fmtData = (scsiDev.cdb[1] & 0x10) ? 1 : 0;
\r
403 // We need to read the parameter list, but we don't know how
\r
404 // big it is yet. Start with the header.
\r
405 scsiDev.dataLen = 4;
\r
406 scsiDev.phase = DATA_OUT;
\r
407 scsiDev.postDataOutHook = doFormatUnitHeader;
\r
411 // No data to read, we're already finished!
\r
414 else if (unlikely(command == 0x25))
\r
419 else if (unlikely(command == 0x0B))
\r
423 (((uint32) scsiDev.cdb[1] & 0x1F) << 16) +
\r
424 (((uint32) scsiDev.cdb[2]) << 8) +
\r
430 else if (unlikely(command == 0x2B))
\r
434 (((uint32) scsiDev.cdb[2]) << 24) +
\r
435 (((uint32) scsiDev.cdb[3]) << 16) +
\r
436 (((uint32) scsiDev.cdb[4]) << 8) +
\r
441 else if (unlikely(command == 0x36))
\r
443 // LOCK UNLOCK CACHE
\r
444 // We don't have a cache to lock data into. do nothing.
\r
446 else if (unlikely(command == 0x34))
\r
449 // We don't have a cache to pre-fetch into. do nothing.
\r
451 else if (unlikely(command == 0x1E))
\r
453 // PREVENT ALLOW MEDIUM REMOVAL
\r
454 // Not much we can do to prevent the user removing the SD card.
\r
457 else if (unlikely(command == 0x01))
\r
460 // Set the lun to a vendor-specific state. Ignore.
\r
462 else if (unlikely(command == 0x35))
\r
464 // SYNCHRONIZE CACHE
\r
465 // We don't have a cache. do nothing.
\r
467 else if (unlikely(command == 0x2F))
\r
470 // TODO: When they supply data to verify, we should read the data and
\r
471 // verify it. If they don't supply any data, just say success.
\r
472 if ((scsiDev.cdb[1] & 0x02) == 0)
\r
474 // They are asking us to do a medium verification with no data
\r
475 // comparison. Assume success, do nothing.
\r
479 // TODO. This means they are supplying data to verify against.
\r
480 // Technically we should probably grab the data and compare it.
\r
481 scsiDev.status = CHECK_CONDITION;
\r
482 scsiDev.target->sense.code = ILLEGAL_REQUEST;
\r
483 scsiDev.target->sense.asc = INVALID_FIELD_IN_CDB;
\r
484 scsiDev.phase = STATUS;
\r
489 commandHandled = 0;
\r
492 return commandHandled;
\r
495 void scsiDiskPoll()
\r
497 if (scsiDev.phase == DATA_IN &&
\r
498 transfer.currentBlock != transfer.blocks)
\r
500 scsiEnterPhase(DATA_IN);
\r
502 int totalSDSectors =
\r
504 SDSectorsPerSCSISector(scsiDev.target->liveCfg.bytesPerSector);
\r
507 scsiDev.target->cfg->sdSectorStart,
\r
508 scsiDev.target->liveCfg.bytesPerSector,
\r
511 const int sdPerScsi =
\r
512 SDSectorsPerSCSISector(scsiDev.target->liveCfg.bytesPerSector);
\r
513 int buffers = sizeof(scsiDev.data) / SD_SECTOR_SIZE;
\r
516 int scsiActive = 0;
\r
518 while ((i < totalSDSectors) &&
\r
519 likely(scsiDev.phase == DATA_IN) &&
\r
520 likely(!scsiDev.resetFlag))
\r
522 // Wait for the next DMA interrupt. It's beneficial to halt the
\r
523 // processor to give the DMA controller more memory bandwidth to
\r
525 // We're optimistically assuming a race condition won't occur
\r
526 // between these checks and the interrupt handers. The 1ms
\r
527 // systick timer interrupt saves us on the event of a race.
\r
528 int scsiBusy = scsiDMABusy();
\r
529 int sdBusy = sdDMABusy();
\r
530 if (scsiBusy && sdBusy) __WFI();
\r
532 if (sdActive && !sdBusy && sdReadSectorDMAPoll())
\r
537 else if (!sdActive &&
\r
538 (prep - i < buffers) &&
\r
539 (prep < totalSDSectors))
\r
541 // Start an SD transfer if we have space.
\r
542 if (transfer.multiBlock)
\r
544 sdReadMultiSectorDMA(&scsiDev.data[SD_SECTOR_SIZE * (prep % buffers)]);
\r
548 sdReadSingleSectorDMA(sdLBA + prep, &scsiDev.data[SD_SECTOR_SIZE * (prep % buffers)]);
\r
553 if (scsiActive && !scsiBusy && scsiWriteDMAPoll())
\r
558 else if (!scsiActive && ((prep - i) > 0))
\r
560 int dmaBytes = SD_SECTOR_SIZE;
\r
561 if ((i % sdPerScsi) == (sdPerScsi - 1))
\r
563 dmaBytes = scsiDev.target->liveCfg.bytesPerSector % SD_SECTOR_SIZE;
\r
564 if (dmaBytes == 0) dmaBytes = SD_SECTOR_SIZE;
\r
566 scsiWriteDMA(&scsiDev.data[SD_SECTOR_SIZE * (i % buffers)], dmaBytes);
\r
570 if (scsiDev.phase == DATA_IN)
\r
572 scsiDev.phase = STATUS;
\r
576 else if (scsiDev.phase == DATA_OUT &&
\r
577 transfer.currentBlock != transfer.blocks)
\r
579 scsiEnterPhase(DATA_OUT);
\r
581 const int sdPerScsi =
\r
582 SDSectorsPerSCSISector(scsiDev.target->liveCfg.bytesPerSector);
\r
583 int totalSDSectors = transfer.blocks * sdPerScsi;
\r
584 int buffers = sizeof(scsiDev.data) / SD_SECTOR_SIZE;
\r
587 int scsiDisconnected = 0;
\r
588 int scsiComplete = 0;
\r
589 uint32_t lastActivityTime = getTime_ms();
\r
590 int scsiActive = 0;
\r
593 while ((i < totalSDSectors) &&
\r
594 (likely(scsiDev.phase == DATA_OUT) || // scsiDisconnect keeps our phase.
\r
596 likely(!scsiDev.resetFlag))
\r
598 // Wait for the next DMA interrupt. It's beneficial to halt the
\r
599 // processor to give the DMA controller more memory bandwidth to
\r
601 // We're optimistically assuming a race condition won't occur
\r
602 // between these checks and the interrupt handers. The 1ms
\r
603 // systick timer interrupt saves us on the event of a race.
\r
604 int scsiBusy = scsiDMABusy();
\r
605 int sdBusy = sdDMABusy();
\r
606 if (scsiBusy && sdBusy) __WFI();
\r
608 if (sdActive && !sdBusy && sdWriteSectorDMAPoll(i == (totalSDSectors - 1)))
\r
613 else if (!sdActive && ((prep - i) > 0))
\r
615 // Start an SD transfer if we have space.
\r
616 sdWriteMultiSectorDMA(&scsiDev.data[SD_SECTOR_SIZE * (i % buffers)]);
\r
620 uint32_t now = getTime_ms();
\r
622 if (scsiActive && !scsiBusy && scsiReadDMAPoll())
\r
626 lastActivityTime = now;
\r
628 else if (!scsiActive &&
\r
629 ((prep - i) < buffers) &&
\r
630 (prep < totalSDSectors) &&
\r
631 likely(!scsiDisconnected))
\r
633 int dmaBytes = SD_SECTOR_SIZE;
\r
634 if ((prep % sdPerScsi) == (sdPerScsi - 1))
\r
636 dmaBytes = scsiDev.target->liveCfg.bytesPerSector % SD_SECTOR_SIZE;
\r
637 if (dmaBytes == 0) dmaBytes = SD_SECTOR_SIZE;
\r
639 scsiReadDMA(&scsiDev.data[SD_SECTOR_SIZE * (prep % buffers)], dmaBytes);
\r
643 (scsiActive == 0) &&
\r
644 likely(!scsiDisconnected) &&
\r
645 unlikely(scsiDev.discPriv) &&
\r
646 unlikely(diffTime_ms(lastActivityTime, now) >= 20) &&
\r
647 likely(scsiDev.phase == DATA_OUT))
\r
649 // We're transferring over the SCSI bus faster than the SD card
\r
650 // can write. There is no more buffer space once we've finished
\r
651 // this SCSI transfer.
\r
652 // The NCR 53C700 interface chips have a 250ms "byte-to-byte"
\r
653 // timeout buffer. SD card writes are supposed to complete
\r
654 // within 200ms, but sometimes they don't.
\r
655 // The NCR 53C700 series is used on HP 9000 workstations.
\r
657 scsiDisconnected = 1;
\r
658 lastActivityTime = getTime_ms();
\r
660 else if (unlikely(scsiDisconnected) &&
\r
662 (prep == i) || // Buffers empty.
\r
663 // Send some messages every 100ms so we don't timeout.
\r
664 // At a minimum, a reselection involves an IDENTIFY message.
\r
665 unlikely(diffTime_ms(lastActivityTime, now) >= 100)
\r
668 int reconnected = scsiReconnect();
\r
671 scsiDisconnected = 0;
\r
672 lastActivityTime = getTime_ms(); // Don't disconnect immediately.
\r
674 else if (diffTime_ms(lastActivityTime, getTime_ms()) >= 10000)
\r
676 // Give up after 10 seconds of trying to reconnect.
\r
677 scsiDev.resetFlag = 1;
\r
681 likely(!scsiComplete) &&
\r
683 (prep == totalSDSectors) && // All scsi data read and buffered
\r
684 likely(!scsiDev.discPriv) && // Prefer disconnect where possible.
\r
685 unlikely(diffTime_ms(lastActivityTime, now) >= 150) &&
\r
687 likely(scsiDev.phase == DATA_OUT) &&
\r
688 !(scsiDev.cdb[scsiDev.cdbLen - 1] & 0x01) // Not linked command
\r
691 // We're transferring over the SCSI bus faster than the SD card
\r
692 // can write. All data is buffered, and we're just waiting for
\r
693 // the SD card to complete. The host won't let us disconnect.
\r
694 // Some drivers set a 250ms timeout on transfers to complete.
\r
695 // SD card writes are supposed to complete
\r
696 // within 200ms, but sometimes they don'to.
\r
697 // Just pretend we're finished.
\r
701 process_MessageIn(); // Will go to BUS_FREE state
\r
703 // Try and prevent anyone else using the SCSI bus while we're not ready.
\r
704 SCSI_SetPin(SCSI_Out_BSY);
\r
710 SCSI_ClearPin(SCSI_Out_BSY);
\r
713 !scsiDev.resetFlag &&
\r
714 unlikely(scsiDisconnected) &&
\r
715 (elapsedTime_ms(lastActivityTime) <= 10000))
\r
717 scsiDisconnected = !scsiReconnect();
\r
719 if (scsiDisconnected)
\r
721 // Failed to reconnect
\r
722 scsiDev.resetFlag = 1;
\r
725 if (scsiDev.phase == DATA_OUT)
\r
727 if (scsiDev.parityError &&
\r
728 (scsiDev.target->cfg->flags & CONFIG_ENABLE_PARITY) &&
\r
729 (scsiDev.compatMode >= COMPAT_SCSI2))
\r
731 scsiDev.target->sense.code = ABORTED_COMMAND;
\r
732 scsiDev.target->sense.asc = SCSI_PARITY_ERROR;
\r
733 scsiDev.status = CHECK_CONDITION;;
\r
735 scsiDev.phase = STATUS;
\r
741 void scsiDiskReset()
\r
743 scsiDev.dataPtr = 0;
\r
744 scsiDev.savedDataPtr = 0;
\r
745 scsiDev.dataLen = 0;
\r
746 // transfer.lba = 0; // Needed in Request Sense to determine failure
\r
747 transfer.blocks = 0;
\r
748 transfer.currentBlock = 0;
\r
750 // Cancel long running commands!
\r
751 if (unlikely(transfer.inProgress == 1))
\r
753 if (transfer.dir == TRANSFER_WRITE)
\r
762 transfer.inProgress = 0;
\r
763 transfer.multiBlock = 0;
\r
766 void scsiDiskInit()
\r
768 transfer.inProgress = 0;
\r
771 // Don't require the host to send us a START STOP UNIT command
\r
772 blockDev.state = DISK_STARTED;
\r
773 // WP pin not available for micro-sd
\r
774 // TODO read card WP register
\r
778 blockDev.state = blockDev.state | DISK_WP;
\r
783 #pragma GCC pop_options
\r