1 // Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
3 // This file is part of SCSI2SD.
5 // SCSI2SD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // SCSI2SD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
37 STATUS = __scsiphase_cd | __scsiphase_io,
38 COMMAND = __scsiphase_cd,
39 DATA_IN = __scsiphase_io,
41 MESSAGE_IN = __scsiphase_msg | __scsiphase_cd | __scsiphase_io,
42 MESSAGE_OUT = __scsiphase_msg | __scsiphase_cd
56 MSG_COMMAND_COMPLETE = 0,
58 MSG_LINKED_COMMAND_COMPLETE = 0x0A,
59 MSG_LINKED_COMMAND_COMPLETE_WITH_FLAG = 0x0B
69 // Maximum value for bytes-per-sector.
70 #define MAX_SECTOR_SIZE 8192
71 #define MIN_SECTOR_SIZE 64
73 // Shadow parameters, possibly not saved to flash yet.
74 // Set via Mode Select
77 uint16_t bytesPerSector;
84 const S2S_TargetCfg* cfg;
90 uint16_t unitAttention; // Set to the sense qualifier key to be returned.
92 // Only let the reserved initiator talk to us.
93 // A 3rd party may be sending the RESERVE/RELEASE commands
94 int reservedId; // 0 -> 7 if reserved. -1 if not reserved.
95 int reserverId; // 0 -> 7 if reserved. -1 if not reserved.
100 uint8_t data[MAX_SECTOR_SIZE * 2]; // Must be aligned for DMA
102 TargetState targets[S2S_MAX_TARGETS];
104 S2S_BoardCfg boardCfg;
107 // Set to true (1) if the ATN flag was set, and we need to
108 // enter the MESSAGE_OUT phase.
111 // Set to true (1) if the RST flag was set.
112 volatile int resetFlag;
114 // Set to true (1) if a parity error was observed.
119 int dataPtr; // Index into data, reset on [re]selection to savedDataPtr
120 int savedDataPtr; // Index into data, initially 0.
123 uint8_t cdb[12]; // command descriptor block
124 uint8_t cdbLen; // 6, 10, or 12 byte message.
125 int8_t lun; // Target lun, set by IDENTIFY message.
126 uint8_t discPriv; // Disconnect priviledge.
127 uint8_t compatMode; // SCSI_COMPAT_MODE
129 // Only let the reserved initiator talk to us.
130 // A 3rd party may be sending the RESERVE/RELEASE commands
131 int initiatorId; // 0 -> 7. Set during the selection phase.
133 // SCSI_STATUS value.
134 // Change to CHECK_CONDITION when setting a SENSE value
140 void (*postDataOutHook)(void);
146 uint8_t watchdogTick;
149 uint16_t lastSenseASC;
152 extern ScsiDevice scsiDev;
154 void process_Status(void);
155 void process_MessageIn(void);
159 void scsiDisconnect(void);
160 int scsiReconnect(void);
163 // Utility macros, consistent with the Linux Kernel code.
164 #define likely(x) __builtin_expect(!!(x), 1)
165 #define unlikely(x) __builtin_expect(!!(x), 0)
166 //#define likely(x) (x)
167 //#define unlikely(x) (x)