esiop.ss revision 1.2
1; $NetBSD: esiop.ss,v 1.2 2002/04/22 15:53:40 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 the University of 17; California, Berkeley and its contributors. 18; 4. Neither the name of the University nor the names of its contributors 19; may be used to endorse or promote products derived from this software 20; without specific prior written permission. 21; 22; THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25; ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32; SUCH DAMAGE. 33; 34 35ARCH 825 36 37; offsets in sym_xfer 38ABSOLUTE t_id = 24; 39ABSOLUTE t_msg_in = 32; 40ABSOLUTE t_ext_msg_in = 40; 41ABSOLUTE t_ext_msg_data = 48; 42ABSOLUTE t_msg_out = 56; 43ABSOLUTE t_cmd = 64; 44ABSOLUTE t_status = 72; 45ABSOLUTE t_data = 80; 46 47; offsets in the per-target lun table 48ABSOLUTE target_id = 0x0; 49ABSOLUTE target_luntbl = 0x8; 50 51;; interrupt codes 52; interrupts that needs a valid target/lun/tag 53ABSOLUTE int_done = 0xff00; 54ABSOLUTE int_msgin = 0xff01; 55ABSOLUTE int_extmsgin = 0xff02; 56ABSOLUTE int_extmsgdata = 0xff03; 57ABSOLUTE int_disc = 0xff04; 58; interrupts that don't have a valid I/T/Q 59ABSOLUTE int_resfail = 0xff80; 60ABSOLUTE int_err = 0xffff; 61 62; We use the various scratch[a-j] registers to keep internal status: 63 64; scratchA1: offset in data DSA (for save data pointer) 65; scratchB: save/restore DSA in data loop 66; scratchC: current target/lun/tag 67; scratchC0: flags 68ABSOLUTE f_c_target = 0x01 ; target valid 69ABSOLUTE f_c_lun = 0x02 ; lun valud 70ABSOLUTE f_c_tag = 0x04 ; tag valid 71ABSOLUTE f_c_data = 0x08 ; data I/O in progress 72ABSOLUTE f_c_data_mask = 0xf7 ; ~f_c_data 73ABSOLUTE f_c_sdp = 0x10 ; got save data pointer message 74; scratchC[1-3]: target/lun/tag 75 76; scratchD: current DSA in start cmd ring 77; scratchE0: index in start cmd ring 78ABSOLUTE ncmd_slots = 64 ; number of slots in CMD ring 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_* 84ABSOLUTE o_cmd_id = 4; 85 86; SCRATCHE1: last status 87 88ENTRY reselect; 89ENTRY ring_reset; 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 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; 138 MOVE DSA1 + 0x00 to DSA1 with carry; 139 MOVE DSA2 + 0x00 to DSA2 with carry; 140 MOVE DSA3 + 0x00 to DSA3 with carry; 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; target * 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 SCRATCHC3; 162 MOVE SCRATCHC0 | f_c_tag to SCRATCHC0; save TAG 163 MOVE 0x0 to SCRATCHA3; 164 CLEAR CARRY; 165 MOVE SCRATCHC3 SHL SFBR; 166 MOVE SCRATCHA3 SHL SCRATCHA3; 167 MOVE SFBR SHL SCRATCHA2; 168 MOVE SCRATCHA3 SHL SCRATCHA3; TAG * 4 to SCRACHA(2,3) 169 CLEAR CARRY; 170 MOVE SCRATCHA2 TO SFBR; 171 MOVE DSA0 + SFBR TO DSA0; 172 MOVE SCRATCHA3 TO SFBR; 173 MOVE DSA1 + SFBR TO DSA1 with CARRY; 174 MOVE DSA2 + 0x00 TO DSA2 with CARRY; 175 MOVE DSA3 + 0x00 TO DSA3 with CARRY; SCRACHA(2,3) + DSA to DSA 176 LOAD DSA0, 4, from 0; load DSA for this tag 177 JUMP REL(waitphase); 178 179reselect_fail: 180 ; check that host asserted SIGP, this'll clear SIGP in ISTAT 181 MOVE CTEST2 & 0x40 TO SFBR; 182 INT int_resfail, IF 0x00; 183script_sched: 184; Load ring DSA 185 MOVE SCRATCHD0 to SFBR; 186 MOVE SFBR to DSA0; 187 MOVE SCRATCHD1 to SFBR; 188 MOVE SFBR to DSA1; 189 MOVE SCRATCHD2 to SFBR; 190 MOVE SFBR to DSA2; 191 MOVE SCRATCHD3 to SFBR; 192 MOVE SFBR to DSA3; 193 LOAD SCRATCHA0,4, from o_cmd_dsa; /* get flags */ 194 MOVE SCRATCHA0 & f_cmd_free to SFBR; 195 JUMP REL(no_cmd), IF NOT 0x0; 196 MOVE SCRATCHA0 & f_cmd_ignore to SFBR; 197 JUMP REL(ignore_cmd), IF NOT 0x0; 198; this slot is busy, attempt to exec command 199 SELECT ATN FROM o_cmd_id, REL(reselect); 200; select either succeeded or timed out. In either case update ring pointer. 201; if timed out the STO interrupt will be posted at the first SCSI bus access 202; waiting for a valid phase. 203ignore_cmd: 204 MOVE SCRATCHE0 + 1 to SFBR; 205 MOVE SFBR to SCRATCHE0; 206 JUMP REL(ring_reset), IF ncmd_slots; 207 MOVE SCRATCHD0 + 8 to SCRATCHD0; sizeof (esiop_cmd_slot) 208 MOVE SCRATCHD1 + 0 to SCRATCHD1 WITH CARRY; 209 MOVE SCRATCHD2 + 0 to SCRATCHD2 WITH CARRY; 210 MOVE SCRATCHD3 + 0 to SCRATCHD3 WITH CARRY; 211 JUMP REL(handle_cmd); 212ring_reset: 213cmdr0: 214 MOVE 0xff to SCRATCHD0; correct value will be patched by driver 215cmdr1: 216 MOVE 0xff to SCRATCHD1; 217cmdr2: 218 MOVE 0xff to SCRATCHD2; 219cmdr3: 220 MOVE 0xff to SCRATCHD3; 221 MOVE 0x00 to SCRATCHE0; 222handle_cmd: 223 MOVE SCRATCHA0 | f_cmd_free to SCRATCHA0; 224 STORE noflush SCRATCHA0, 4, FROM o_cmd_dsa; 225 MOVE SCRATCHA0 & f_cmd_ignore to SFBR; 226 JUMP REL(script_sched), IF NOT 0x00; /* next command if ignore */ 227 228; a NOP by default; patched with MOVE GPREG & 0xfe to GPREG on compile-time 229; option "SIOP_SYMLED" 230led_on1: 231 NOP; 232 LOAD DSA0, 4, FROM o_cmd_dsa; /* load new DSA */ 233 MOVE DSA0 & 0xfe to DSA0; /* clear f_cmd_free */ 234 MOVE 0x00 TO SCRATCHA1; 235 MOVE 0xff TO SCRATCHE1; 236 LOAD SCRATCHC0, 4, FROM tlq_offset; 237msgin_ack: 238 CLEAR ACK; 239waitphase: 240 JUMP REL(msgout), WHEN MSG_OUT; 241 JUMP REL(msgin), WHEN MSG_IN; 242 JUMP REL(dataout), WHEN DATA_OUT; 243 JUMP REL(datain), WHEN DATA_IN; 244 JUMP REL(cmdout), WHEN CMD; 245 JUMP REL(status), WHEN STATUS; 246 INT int_err; 247 248; entry point for msgout after a msgin or status phase 249send_msgout: 250 SET ATN; 251 CLEAR ACK; 252msgout: 253 MOVE FROM t_msg_out, WHEN MSG_OUT; 254 CLEAR ATN; 255 JUMP REL(waitphase); 256 257handle_sdp: 258 CLEAR ACK; 259 MOVE SCRATCHC0 | f_c_sdp TO SCRATCHC0; 260 ; should get a disconnect message now 261msgin: 262 CLEAR ATN 263 MOVE FROM t_msg_in, WHEN MSG_IN; 264handle_msgin: 265 JUMP REL(handle_cmpl), IF 0x00 ; command complete message 266 JUMP REL(handle_sdp), IF 0x02 ; save data pointer message 267 JUMP REL(handle_extin), IF 0x01 ; extended message 268 INT int_msgin, IF NOT 0x04; 269 CALL REL(disconnect) ; disconnect message 270; if we didn't get sdp, or if offset is 0, no need to interrupt 271 MOVE SCRATCHC0 & f_c_sdp TO SFBR; 272 JUMP REL(script_sched), if 0x00; 273 MOVE SCRATCHA1 TO SFBR; 274 JUMP REL(script_sched), if 0x00; 275; Ok, we need to save data pointers 276 INT int_disc; 277 278cmdout: 279 MOVE FROM t_cmd, WHEN CMD; 280 JUMP REL(waitphase); 281status: 282 MOVE FROM t_status, WHEN STATUS; 283 MOVE SFBR TO SCRATCHE1; 284 JUMP REL(waitphase); 285datain: 286 CALL REL(savedsa); 287 MOVE SCRATCHC0 | f_c_data TO SCRATCHC0; 288 datain_loop: 289 MOVE FROM t_data, WHEN DATA_IN; 290 MOVE SCRATCHA1 + 1 TO SCRATCHA1 ; adjust offset 291 MOVE DSA0 + 8 to DSA0; 292 MOVE DSA1 + 0 to DSA1 WITH CARRY; 293 MOVE DSA2 + 0 to DSA2 WITH CARRY; 294 MOVE DSA3 + 0 to DSA3 WITH CARRY; 295 JUMP REL(datain_loop), WHEN DATA_IN; 296 CALL REL(restoredsa); 297 MOVE SCRATCHC0 & f_c_data_mask TO SCRATCHC0; 298 JUMP REL(waitphase); 299 300dataout: 301 CALL REL(savedsa); 302 MOVE SCRATCHC0 | f_c_data TO SCRATCHC0; 303dataout_loop: 304 MOVE FROM t_data, WHEN DATA_OUT; 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(dataout_loop), WHEN DATA_OUT; 311 CALL REL(restoredsa); 312 MOVE SCRATCHC0 & f_c_data_mask TO SCRATCHC0; 313 JUMP REL(waitphase); 314 315savedsa: 316 MOVE DSA0 to SFBR; 317 MOVE SFBR to SCRATCHB0; 318 MOVE DSA1 to SFBR; 319 MOVE SFBR to SCRATCHB1; 320 MOVE DSA2 to SFBR; 321 MOVE SFBR to SCRATCHB2; 322 MOVE DSA3 to SFBR; 323 MOVE SFBR to SCRATCHB3; 324 RETURN; 325 326restoredsa: 327 MOVE SCRATCHB0 TO SFBR; 328 MOVE SFBR TO DSA0; 329 MOVE SCRATCHB1 TO SFBR; 330 MOVE SFBR TO DSA1; 331 MOVE SCRATCHB2 TO SFBR; 332 MOVE SFBR TO DSA2; 333 MOVE SCRATCHB3 TO SFBR; 334 MOVE SFBR TO DSA3; 335 RETURN; 336 337disconnect: 338 MOVE SCNTL2 & 0x7f TO SCNTL2; 339 CLEAR ATN; 340 CLEAR ACK; 341 WAIT DISCONNECT; 342 RETURN; 343 344handle_cmpl: 345 CALL REL(disconnect); 346 MOVE SCRATCHE1 to SFBR; 347 INT int_done, IF NOT 0x00; if status is not "done", let host handle it 348 MOVE ISTAT | 0x10 TO ISTAT; else signal that cmd is done in ISTAT 349 JUMP REL(script_sched); and attempt next command 350 351handle_extin: 352 CLEAR ACK; 353 MOVE FROM t_ext_msg_in, WHEN MSG_IN; 354 INT int_extmsgin; /* let host fill in t_ext_msg_data */ 355get_extmsgdata: 356 CLEAR ACK; 357 MOVE FROM t_ext_msg_data, WHEN MSG_IN; 358 INT int_extmsgdata; 359