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.
103 // TODO reduce this buffer size and add a proper cache
104 uint8_t data[MAX_SECTOR_SIZE * 8]; // Must be aligned for DMA
106 TargetState targets[S2S_MAX_TARGETS];
108 S2S_BoardCfg boardCfg;
111 // Set to true (1) if the ATN flag was set, and we need to
112 // enter the MESSAGE_OUT phase.
115 // Set to true (1) if the RST flag was set.
116 volatile int resetFlag;
118 // Set to true (1) if a parity error was observed.
123 int dataPtr; // Index into data, reset on [re]selection to savedDataPtr
124 int savedDataPtr; // Index into data, initially 0.
127 uint8_t cdb[12]; // command descriptor block
128 uint8_t cdbLen; // 6, 10, or 12 byte message.
129 int8_t lun; // Target lun, set by IDENTIFY message.
130 uint8_t discPriv; // Disconnect priviledge.
131 uint8_t compatMode; // SCSI_COMPAT_MODE
133 // Only let the reserved initiator talk to us.
134 // A 3rd party may be sending the RESERVE/RELEASE commands
135 int initiatorId; // 0 -> 7. Set during the selection phase.
137 // SCSI_STATUS value.
138 // Change to CHECK_CONDITION when setting a SENSE value
144 void (*postDataOutHook)(void);
150 uint8_t watchdogTick;
153 uint16_t lastSenseASC;
155 int needSyncNegotiationAck;
158 extern ScsiDevice scsiDev;
160 void process_Status(void);
161 void process_MessageIn(void);
165 void scsiDisconnect(void);
166 int scsiReconnect(void);
169 // Utility macros, consistent with the Linux Kernel code.
170 #define likely(x) __builtin_expect(!!(x), 1)
171 #define unlikely(x) __builtin_expect(!!(x), 0)
172 //#define likely(x) (x)
173 //#define unlikely(x) (x)