esiop.ss revision 1.9
1; $NetBSD: esiop.ss,v 1.9 2002/04/24 09:43:14 bouyer Exp $ 2 3; 4; Copyright (c) 2002 Manuel Bouyer. 5; 6; Redistribution and use in source and binary forms, with or without 7; modification, are permitted provided that the following conditions 8; are met: 9; 1. Redistributions of source code must retain the above copyright 10; notice, this list of conditions and the following disclaimer. 11; 2. Redistributions in binary form must reproduce the above copyright 12; notice, this list of conditions and the following disclaimer in the 13; documentation and/or other materials provided with the distribution. 14; 3. All advertising materials mentioning features or use of this software 15; must display the following acknowledgement: 16; This product includes software developed by Manuel Bouyer. 17; 4. Neither the name of the University nor the names of its contributors 18; may be used to endorse or promote products derived from this software 19; without specific prior written permission. 20; 21; THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24; ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31; SUCH DAMAGE. 32; 33 34ARCH 825 35 36; offsets in siop_common_xfer 37ABSOLUTE t_id = 40; 38ABSOLUTE t_msg_in = 48; 39ABSOLUTE t_ext_msg_in = 56; 40ABSOLUTE t_ext_msg_data = 64; 41ABSOLUTE t_msg_out = 72; 42ABSOLUTE t_cmd = 80; 43ABSOLUTE t_status = 88; 44ABSOLUTE t_data = 96; 45 46; offsets in the per-target lun table 47ABSOLUTE target_id = 0x0; 48ABSOLUTE target_luntbl = 0x8; 49 50;; interrupt codes 51; interrupts that needs a valid target/lun/tag 52ABSOLUTE int_done = 0xff00; 53ABSOLUTE int_msgin = 0xff01; 54ABSOLUTE int_extmsgin = 0xff02; 55ABSOLUTE int_extmsgdata = 0xff03; 56ABSOLUTE int_disc = 0xff04; 57; interrupts that don't have a valid I/T/Q 58ABSOLUTE int_resfail = 0xff80; 59ABSOLUTE int_err = 0xffff; 60 61; We use the various scratch[a-j] registers to keep internal status: 62 63; scratchA1: offset in data DSA (for save data pointer) 64; scratchB: save/restore DSA in data loop 65; scratchC: current target/lun/tag 66; scratchC0: flags 67ABSOLUTE f_c_target = 0x01 ; target valid 68ABSOLUTE f_c_lun = 0x02 ; lun valud 69ABSOLUTE f_c_tag = 0x04 ; tag valid 70ABSOLUTE f_c_data = 0x08 ; data I/O in progress 71ABSOLUTE f_c_data_mask = 0xf7 ; ~f_c_data 72ABSOLUTE f_c_sdp = 0x10 ; got save data pointer message 73; scratchC[1-3]: target/lun/tag 74 75; scratchD: current DSA in start cmd ring 76; scratchE0: index in start cmd ring 77ABSOLUTE ncmd_slots = 256 ; number of slots in CMD ring 78ABSOLUTE ncmd_slots_last = 0 ; == ncmd_slots in a 8bit counter 79; flags in a cmd slot 80ABSOLUTE f_cmd_free = 0x01 ; this slot is free 81ABSOLUTE f_cmd_ignore = 0x02 ; this slot is not free but don't start it 82; offsets in a cmd slot 83ABSOLUTE o_cmd_dsa = 0; also holds f_cmd_* 84; size of a cmd slot (for DSA increments) 85ABSOLUTE cmd_slot_size = 4; 86 87; SCRATCHE1: last status 88 89ENTRY reselect; 90ENTRY cmdr0; 91ENTRY cmdr1; 92ENTRY cmdr2; 93ENTRY cmdr3; 94ENTRY led_on1; 95ENTRY led_on2; 96ENTRY led_off; 97ENTRY status; 98ENTRY msgin; 99ENTRY msgin_ack; 100ENTRY get_extmsgdata; 101ENTRY send_msgout; 102ENTRY script_sched; 103ENTRY load_targtable; 104 105EXTERN tlq_offset; 106EXTERN abs_msgin2; 107 108PROC esiop_script: 109 110no_cmd: 111 MOVE ISTAT & 0x10 TO SFBR; pending done command ? 112 INTFLY 0, IF NOT 0x00; 113reselect: 114 MOVE 0x00 TO SCRATCHA1; 115 MOVE 0x00 TO SCRATCHC0; 116 MOVE 0xff TO SCRATCHE1; 117; a NOP by default; patched with MOVE GPREG | 0x01 to GPREG on compile-time 118; option "SIOP_SYMLED" 119led_off: 120 NOP; 121 WAIT RESELECT REL(reselect_fail); 122; a NOP by default; patched with MOVE GPREG & 0xfe to GPREG on compile-time 123; option "SIOP_SYMLED" 124led_on2: 125 NOP; 126 MOVE SSID & 0x0f to SFBR; 127 MOVE SFBR to SCRATCHC1; 128 MOVE SCRATCHC0 | f_c_target to SCRATCHC0; save target 129 CLEAR CARRY; 130 MOVE SCRATCHC1 SHL SFBR; 131 MOVE SFBR SHL DSA0; target * 4 in dsa 132 MOVE 0x0 to DSA1; 133 MOVE 0x0 to DSA2; 134 MOVE 0x0 to DSA3; 135; load DSA for the target table 136load_targtable: 137 MOVE DSA0 + 0x00 to DSA0; host will patch 0x0 with base of table 138 MOVE DSA1 + 0x00 to DSA1 with carry; 139 MOVE DSA2 + 0x00 to DSA2 with carry; 140 MOVE DSA3 + 0x00 to DSA3 with carry; now dsa -> basetable + target * 4 141 LOAD DSA0, 4, FROM 0; now load DSA for this target 142 SELECT FROM target_id, REL(nextisn); 143nextisn: 144 MOVE 1, abs_msgin2, WHEN MSG_IN; 145 MOVE SFBR & 0x07 to SCRATCHC2; 146 MOVE SCRATCHC0 | f_c_lun to SCRATCHC0; save LUN 147 CLEAR ACK and CARRY; 148 MOVE SCRATCHC2 SHL SFBR; 149 MOVE SFBR SHL SFBR; lun * 4 150 MOVE DSA0 + SFBR TO DSA0; 151 MOVE DSA1 + 0x0 TO DSA1 with carry; 152 MOVE DSA2 + 0x0 TO DSA2 with carry; 153 MOVE DSA3 + 0x0 TO DSA3 with carry; 154 LOAD DSA0, 4, from target_luntbl; load DSA for this LUN 155 JUMP REL(waitphase), WHEN NOT MSG_IN; 156 MOVE 1, abs_msgin2, WHEN MSG_IN; 157 CLEAR ACK; 158 INT int_msgin, IF NOT 0x20; not a simple tag message, let host handle it 159 MOVE 1, abs_msgin2, WHEN MSG_IN; get tag 160 CLEAR ACK; 161 MOVE SFBR to SCRATCHA2; 162 MOVE SFBR to SCRATCHC3; 163 MOVE SCRATCHC0 | f_c_tag to SCRATCHC0; save TAG 164 MOVE 0x0 to SCRATCHA3; 165 CLEAR CARRY; 166 MOVE SCRATCHA2 SHL SCRATCHA2; 167 MOVE SCRATCHA3 SHL SCRATCHA3; 168 MOVE SCRATCHA2 SHL SCRATCHA2; 169 MOVE SCRATCHA3 SHL SCRATCHA3; TAG * 4 to SCRATCHA(2,3) 170 MOVE SCRATCHA2 TO SFBR; 171 MOVE DSA0 + SFBR TO DSA0; 172 MOVE DSA1 + 0x00 TO DSA1 with CARRY; 173 MOVE DSA2 + 0x00 TO DSA2 with CARRY; 174 MOVE DSA3 + 0x00 TO DSA3 with CARRY; 175 MOVE SCRATCHA3 TO SFBR; 176 MOVE DSA1 + SFBR TO DSA1; 177 MOVE DSA2 + 0x00 TO DSA2 with CARRY; 178 MOVE DSA3 + 0x00 TO DSA3 with CARRY; SCRACHA(2,3) + DSA to DSA 179 LOAD DSA0, 4, from 0; load DSA for this tag 180 JUMP REL(waitphase); 181 182reselect_fail: 183 ; check that host asserted SIGP, this'll clear SIGP in ISTAT 184 MOVE CTEST2 & 0x40 TO SFBR; 185 INT int_resfail, IF 0x00; 186script_sched: 187; Load ring DSA 188 MOVE SCRATCHD0 to SFBR; 189 MOVE SFBR to DSA0; 190 MOVE SCRATCHD1 to SFBR; 191 MOVE SFBR to DSA1; 192 MOVE SCRATCHD2 to SFBR; 193 MOVE SFBR to DSA2; 194 MOVE SCRATCHD3 to SFBR; 195 MOVE SFBR to DSA3; 196 LOAD DSA0,4, from o_cmd_dsa; get DSA and flags for this slot 197 MOVE DSA0 to SFBR; to avoid another load later 198 MOVE SFBR to SCRATCHA0; to avoid another load later 199 MOVE DSA0 & f_cmd_free to SFBR; check flags 200 JUMP REL(no_cmd), IF NOT 0x0; 201 MOVE DSA0 & f_cmd_ignore to SFBR; 202 JUMP REL(ignore_cmd), IF NOT 0x0; 203; this slot is busy, attempt to exec command 204 SELECT ATN FROM t_id, REL(reselect); 205; select either succeeded or timed out. 206; if timed out the STO interrupt will be posted at the first SCSI bus access 207; waiting for a valid phase, so we have to do it now. If not a MSG_OUT phase, 208; this is an error anyway (we selected with ATN) 209 INT int_err, WHEN NOT MSG_OUT; 210 MOVE SCRATCHD0 to SFBR; restore scheduler DSA 211 MOVE SFBR to DSA0; 212 MOVE SCRATCHD1 to SFBR; 213 MOVE SFBR to DSA1; 214 MOVE SCRATCHD2 to SFBR; 215 MOVE SFBR to DSA2; 216 MOVE SCRATCHD3 to SFBR; 217 MOVE SFBR to DSA3; 218ignore_cmd: 219 MOVE SCRATCHE0 + 1 to SCRATCHE0; 220 MOVE SCRATCHD0 + cmd_slot_size to SCRATCHD0; 221 MOVE SCRATCHD1 + 0 to SCRATCHD1 WITH CARRY; 222 MOVE SCRATCHD2 + 0 to SCRATCHD2 WITH CARRY; 223 MOVE SCRATCHD3 + 0 to SCRATCHD3 WITH CARRY; 224 MOVE SCRATCHE0 TO SFBR; 225 JUMP REL(handle_cmd), IF NOT ncmd_slots_last; 226; reset pointers to beggining of area 227cmdr0: 228 MOVE 0xff to SCRATCHD0; correct value will be patched by driver 229cmdr1: 230 MOVE 0xff to SCRATCHD1; 231cmdr2: 232 MOVE 0xff to SCRATCHD2; 233cmdr3: 234 MOVE 0xff to SCRATCHD3; 235 MOVE 0x00 to SCRATCHE0; 236handle_cmd: 237 MOVE SCRATCHA0 | f_cmd_free to SCRATCHA0; mark slot as free 238 STORE noflush SCRATCHA0, 1, FROM o_cmd_dsa; 239 MOVE SCRATCHA0 & f_cmd_ignore to SFBR; 240 JUMP REL(script_sched), IF NOT 0x00; next command if ignore 241 242; a NOP by default; patched with MOVE GPREG & 0xfe to GPREG on compile-time 243; option "SIOP_SYMLED" 244led_on1: 245 NOP; 246 LOAD DSA0, 4, FROM o_cmd_dsa; reload DSA for this command 247 MOVE DSA0 & 0xfe to DSA0; clear f_cmd_free 248 MOVE 0x00 TO SCRATCHA1; 249 MOVE 0xff TO SCRATCHE1; 250 LOAD SCRATCHC0, 4, FROM tlq_offset; 251;we can now send our identify message 252send_msgout: ; entry point for msgout after a msgin or status phase 253 SET ATN; 254 CLEAR ACK; 255msgout: 256 MOVE FROM t_msg_out, WHEN MSG_OUT; 257 CLEAR ATN; 258 JUMP REL(waitphase); 259 260msgin_ack: 261 CLEAR ACK; 262waitphase: 263 JUMP REL(msgout), WHEN MSG_OUT; 264 JUMP REL(msgin), WHEN MSG_IN; 265 JUMP REL(dataout), WHEN DATA_OUT; 266 JUMP REL(datain), WHEN DATA_IN; 267 JUMP REL(cmdout), WHEN CMD; 268 JUMP REL(status), WHEN STATUS; 269 INT int_err; 270 271 272handle_sdp: 273 CLEAR ACK; 274 MOVE SCRATCHC0 | f_c_sdp TO SCRATCHC0; 275 ; should get a disconnect message now 276msgin: 277 CLEAR ATN 278 MOVE FROM t_msg_in, WHEN MSG_IN; 279handle_msgin: 280 JUMP REL(handle_cmpl), IF 0x00 ; command complete message 281 JUMP REL(handle_sdp), IF 0x02 ; save data pointer message 282 JUMP REL(handle_extin), IF 0x01 ; extended message 283 INT int_msgin, IF NOT 0x04; 284 CALL REL(disconnect) ; disconnect message 285; if we didn't get sdp, or if offset is 0, no need to interrupt 286 MOVE SCRATCHC0 & f_c_sdp TO SFBR; 287 JUMP REL(script_sched), if 0x00; 288 MOVE SCRATCHA1 TO SFBR; 289 JUMP REL(script_sched), if 0x00; 290; Ok, we need to save data pointers 291 INT int_disc; 292 293cmdout: 294 MOVE FROM t_cmd, WHEN CMD; 295 JUMP REL(waitphase); 296status: 297 MOVE FROM t_status, WHEN STATUS; 298 MOVE SFBR TO SCRATCHE1; 299 JUMP REL(waitphase); 300datain: 301 CALL REL(savedsa); 302 MOVE SCRATCHC0 | f_c_data TO SCRATCHC0; 303 datain_loop: 304 MOVE FROM t_data, WHEN DATA_IN; 305 MOVE SCRATCHA1 + 1 TO SCRATCHA1 ; adjust offset 306 MOVE DSA0 + 8 to DSA0; 307 MOVE DSA1 + 0 to DSA1 WITH CARRY; 308 MOVE DSA2 + 0 to DSA2 WITH CARRY; 309 MOVE DSA3 + 0 to DSA3 WITH CARRY; 310 JUMP REL(datain_loop), WHEN DATA_IN; 311 CALL REL(restoredsa); 312 MOVE SCRATCHC0 & f_c_data_mask TO SCRATCHC0; 313 JUMP REL(waitphase); 314 315dataout: 316 CALL REL(savedsa); 317 MOVE SCRATCHC0 | f_c_data TO SCRATCHC0; 318dataout_loop: 319 MOVE FROM t_data, WHEN DATA_OUT; 320 MOVE SCRATCHA1 + 1 TO SCRATCHA1 ; adjust offset 321 MOVE DSA0 + 8 to DSA0; 322 MOVE DSA1 + 0 to DSA1 WITH CARRY; 323 MOVE DSA2 + 0 to DSA2 WITH CARRY; 324 MOVE DSA3 + 0 to DSA3 WITH CARRY; 325 JUMP REL(dataout_loop), WHEN DATA_OUT; 326 CALL REL(restoredsa); 327 MOVE SCRATCHC0 & f_c_data_mask TO SCRATCHC0; 328 JUMP REL(waitphase); 329 330savedsa: 331 MOVE DSA0 to SFBR; 332 MOVE SFBR to SCRATCHB0; 333 MOVE DSA1 to SFBR; 334 MOVE SFBR to SCRATCHB1; 335 MOVE DSA2 to SFBR; 336 MOVE SFBR to SCRATCHB2; 337 MOVE DSA3 to SFBR; 338 MOVE SFBR to SCRATCHB3; 339 RETURN; 340 341restoredsa: 342 MOVE SCRATCHB0 TO SFBR; 343 MOVE SFBR TO DSA0; 344 MOVE SCRATCHB1 TO SFBR; 345 MOVE SFBR TO DSA1; 346 MOVE SCRATCHB2 TO SFBR; 347 MOVE SFBR TO DSA2; 348 MOVE SCRATCHB3 TO SFBR; 349 MOVE SFBR TO DSA3; 350 RETURN; 351 352disconnect: 353 MOVE SCNTL2 & 0x7f TO SCNTL2; 354 CLEAR ATN; 355 CLEAR ACK; 356 WAIT DISCONNECT; 357 RETURN; 358 359handle_cmpl: 360 CALL REL(disconnect); 361 MOVE SCRATCHE1 to SFBR; 362 INT int_done, IF NOT 0x00; if status is not "done", let host handle it 363 MOVE ISTAT | 0x10 TO ISTAT; else signal that cmd is done in ISTAT 364 JUMP REL(script_sched); and attempt next command 365 366handle_extin: 367 CLEAR ACK; 368 MOVE FROM t_ext_msg_in, WHEN MSG_IN; 369 INT int_extmsgin; /* let host fill in t_ext_msg_data */ 370get_extmsgdata: 371 CLEAR ACK; 372 MOVE FROM t_ext_msg_data, WHEN MSG_IN; 373 INT int_extmsgdata; 374 375PROC esiop_led_on: 376 MOVE GPREG & 0xfe TO GPREG; 377 378PROC esiop_led_off: 379 MOVE GPREG | 0x01 TO GPREG; 380