kernel: Remove some variables that are only set but never used.
[dragonfly.git] / sys / dev / disk / ncr / ncr.c
blob060d40a729993045c1e07193ee08b82f19aee042
1 /**************************************************************************
2 **
3 ** $FreeBSD: src/sys/pci/ncr.c,v 1.155.2.3 2001/03/05 13:09:10 obrien Exp $
4 **
5 ** Device driver for the NCR 53C8XX PCI-SCSI-Controller Family.
6 **
7 **-------------------------------------------------------------------------
8 **
9 ** Written for 386bsd and FreeBSD by
10 ** Wolfgang Stanglmeier <wolf@cologne.de>
11 ** Stefan Esser <se@mi.Uni-Koeln.de>
13 **-------------------------------------------------------------------------
15 ** Copyright (c) 1994 Wolfgang Stanglmeier. All rights reserved.
17 ** Redistribution and use in source and binary forms, with or without
18 ** modification, are permitted provided that the following conditions
19 ** are met:
20 ** 1. Redistributions of source code must retain the above copyright
21 ** notice, this list of conditions and the following disclaimer.
22 ** 2. Redistributions in binary form must reproduce the above copyright
23 ** notice, this list of conditions and the following disclaimer in the
24 ** documentation and/or other materials provided with the distribution.
25 ** 3. The name of the author may not be used to endorse or promote products
26 ** derived from this software without specific prior written permission.
28 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
32 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ***************************************************************************
42 #define NCR_DATE "pl30 98/1/1"
44 #define NCR_VERSION (2)
45 #define MAX_UNITS (16)
47 #define NCR_GETCC_WITHMSG
49 #if (defined(__DragonFly__) || defined (__FreeBSD__)) && defined(_KERNEL)
50 #include "opt_ncr.h"
51 #endif
53 /*==========================================================
55 ** Configuration and Debugging
57 ** May be overwritten in <arch/conf/xxxx>
59 **==========================================================
63 ** SCSI address of this device.
64 ** The boot routines should have set it.
65 ** If not, use this.
68 #ifndef SCSI_NCR_MYADDR
69 #define SCSI_NCR_MYADDR (7)
70 #endif /* SCSI_NCR_MYADDR */
73 ** The default synchronous period factor
74 ** (0=asynchronous)
75 ** If maximum synchronous frequency is defined, use it instead.
78 #ifndef SCSI_NCR_MAX_SYNC
80 #ifndef SCSI_NCR_DFLT_SYNC
81 #define SCSI_NCR_DFLT_SYNC (12)
82 #endif /* SCSI_NCR_DFLT_SYNC */
84 #else
86 #if SCSI_NCR_MAX_SYNC == 0
87 #define SCSI_NCR_DFLT_SYNC 0
88 #else
89 #define SCSI_NCR_DFLT_SYNC (250000 / SCSI_NCR_MAX_SYNC)
90 #endif
92 #endif
95 ** The minimal asynchronous pre-scaler period (ns)
96 ** Shall be 40.
99 #ifndef SCSI_NCR_MIN_ASYNC
100 #define SCSI_NCR_MIN_ASYNC (40)
101 #endif /* SCSI_NCR_MIN_ASYNC */
104 ** The maximal bus with (in log2 byte)
105 ** (0=8 bit, 1=16 bit)
108 #ifndef SCSI_NCR_MAX_WIDE
109 #define SCSI_NCR_MAX_WIDE (1)
110 #endif /* SCSI_NCR_MAX_WIDE */
112 /*==========================================================
114 ** Configuration and Debugging
116 **==========================================================
120 ** Number of targets supported by the driver.
121 ** n permits target numbers 0..n-1.
122 ** Default is 7, meaning targets #0..#6.
123 ** #7 .. is myself.
126 #define MAX_TARGET (16)
129 ** Number of logic units supported by the driver.
130 ** n enables logic unit numbers 0..n-1.
131 ** The common SCSI devices require only
132 ** one lun, so take 1 as the default.
135 #ifndef MAX_LUN
136 #define MAX_LUN (8)
137 #endif /* MAX_LUN */
140 ** The maximum number of jobs scheduled for starting.
141 ** There should be one slot per target, and one slot
142 ** for each tag of each target in use.
145 #define MAX_START (256)
148 ** The maximum number of segments a transfer is split into.
151 #define MAX_SCATTER (33)
154 ** The maximum transfer length (should be >= 64k).
155 ** MUST NOT be greater than (MAX_SCATTER-1) * PAGE_SIZE.
158 #define MAX_SIZE ((MAX_SCATTER-1) * (long) PAGE_SIZE)
161 ** other
164 #define NCR_SNOOP_TIMEOUT (1000000)
166 /*==========================================================
168 ** Include files
170 **==========================================================
173 #include <sys/param.h>
174 #include <sys/time.h>
176 #ifdef _KERNEL
177 #include <sys/systm.h>
178 #include <sys/malloc.h>
179 #include <sys/buf.h>
180 #include <sys/kernel.h>
181 #include <sys/sysctl.h>
182 #include <sys/bus.h>
183 #include <sys/thread2.h>
184 #include <machine/clock.h>
185 #include <machine/md_var.h>
186 #include <sys/rman.h>
187 #include <vm/vm.h>
188 #include <vm/pmap.h>
189 #include <vm/vm_extern.h>
190 #endif
192 #include <bus/pci/pcivar.h>
193 #include <bus/pci/pcireg.h>
194 #include "ncrreg.h"
196 #include <bus/cam/cam.h>
197 #include <bus/cam/cam_ccb.h>
198 #include <bus/cam/cam_sim.h>
199 #include <bus/cam/cam_xpt_sim.h>
200 #include <bus/cam/cam_debug.h>
202 #include <bus/cam/scsi/scsi_all.h>
203 #include <bus/cam/scsi/scsi_message.h>
205 /*==========================================================
207 ** Debugging tags
209 **==========================================================
212 #define DEBUG_ALLOC (0x0001)
213 #define DEBUG_PHASE (0x0002)
214 #define DEBUG_POLL (0x0004)
215 #define DEBUG_QUEUE (0x0008)
216 #define DEBUG_RESULT (0x0010)
217 #define DEBUG_SCATTER (0x0020)
218 #define DEBUG_SCRIPT (0x0040)
219 #define DEBUG_TINY (0x0080)
220 #define DEBUG_TIMING (0x0100)
221 #define DEBUG_NEGO (0x0200)
222 #define DEBUG_TAGS (0x0400)
223 #define DEBUG_FREEZE (0x0800)
224 #define DEBUG_RESTART (0x1000)
227 ** Enable/Disable debug messages.
228 ** Can be changed at runtime too.
230 #ifdef SCSI_NCR_DEBUG
231 #define DEBUG_FLAGS ncr_debug
232 #else /* SCSI_NCR_DEBUG */
233 #define SCSI_NCR_DEBUG 0
234 #define DEBUG_FLAGS 0
235 #endif /* SCSI_NCR_DEBUG */
239 /*==========================================================
241 ** assert ()
243 **==========================================================
245 ** modified copy from 386bsd:/usr/include/sys/assert.h
247 **----------------------------------------------------------
250 #ifdef DIAGNOSTIC
251 #define assert(expression) { \
252 if (!(expression)) { \
253 (void)kprintf("assertion \"%s\" failed: " \
254 "file \"%s\", line %d\n", \
255 #expression, __FILE__, __LINE__); \
256 Debugger(""); \
259 #else
260 #define assert(expression) { \
261 if (!(expression)) { \
262 (void)kprintf("assertion \"%s\" failed: " \
263 "file \"%s\", line %d\n", \
264 #expression, __FILE__, __LINE__); \
267 #endif
269 /*==========================================================
271 ** Access to the controller chip.
273 **==========================================================
276 #define INB(r) bus_space_read_1(np->bst, np->bsh, offsetof(struct ncr_reg, r))
277 #define INW(r) bus_space_read_2(np->bst, np->bsh, offsetof(struct ncr_reg, r))
278 #define INL(r) bus_space_read_4(np->bst, np->bsh, offsetof(struct ncr_reg, r))
280 #define OUTB(r, val) bus_space_write_1(np->bst, np->bsh, \
281 offsetof(struct ncr_reg, r), val)
282 #define OUTW(r, val) bus_space_write_2(np->bst, np->bsh, \
283 offsetof(struct ncr_reg, r), val)
284 #define OUTL(r, val) bus_space_write_4(np->bst, np->bsh, \
285 offsetof(struct ncr_reg, r), val)
286 #define OUTL_OFF(o, val) bus_space_write_4(np->bst, np->bsh, o, val)
288 #define INB_OFF(o) bus_space_read_1(np->bst, np->bsh, o)
289 #define INW_OFF(o) bus_space_read_2(np->bst, np->bsh, o)
290 #define INL_OFF(o) bus_space_read_4(np->bst, np->bsh, o)
292 #define READSCRIPT_OFF(base, off) \
293 (base ? *((volatile u_int32_t *)((volatile char *)base + (off))) : \
294 bus_space_read_4(np->bst2, np->bsh2, off))
296 #define WRITESCRIPT_OFF(base, off, val) \
297 do { \
298 if (base) \
299 *((volatile u_int32_t *) \
300 ((volatile char *)base + (off))) = (val); \
301 else \
302 bus_space_write_4(np->bst2, np->bsh2, off, val); \
303 } while (0)
305 #define READSCRIPT(r) \
306 READSCRIPT_OFF(np->script, offsetof(struct script, r))
308 #define WRITESCRIPT(r, val) \
309 WRITESCRIPT_OFF(np->script, offsetof(struct script, r), val)
312 ** Set bit field ON, OFF
315 #define OUTONB(r, m) OUTB(r, INB(r) | (m))
316 #define OUTOFFB(r, m) OUTB(r, INB(r) & ~(m))
317 #define OUTONW(r, m) OUTW(r, INW(r) | (m))
318 #define OUTOFFW(r, m) OUTW(r, INW(r) & ~(m))
319 #define OUTONL(r, m) OUTL(r, INL(r) | (m))
320 #define OUTOFFL(r, m) OUTL(r, INL(r) & ~(m))
322 /*==========================================================
324 ** Command control block states.
326 **==========================================================
329 #define HS_IDLE (0)
330 #define HS_BUSY (1)
331 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
332 #define HS_DISCONNECT (3) /* Disconnected by target */
334 #define HS_COMPLETE (4)
335 #define HS_SEL_TIMEOUT (5) /* Selection timeout */
336 #define HS_RESET (6) /* SCSI reset */
337 #define HS_ABORTED (7) /* Transfer aborted */
338 #define HS_TIMEOUT (8) /* Software timeout */
339 #define HS_FAIL (9) /* SCSI or PCI bus errors */
340 #define HS_UNEXPECTED (10) /* Unexpected disconnect */
341 #define HS_STALL (11) /* QUEUE FULL or BUSY */
343 #define HS_DONEMASK (0xfc)
345 /*==========================================================
347 ** Software Interrupt Codes
349 **==========================================================
352 #define SIR_SENSE_RESTART (1)
353 #define SIR_SENSE_FAILED (2)
354 #define SIR_STALL_RESTART (3)
355 #define SIR_STALL_QUEUE (4)
356 #define SIR_NEGO_SYNC (5)
357 #define SIR_NEGO_WIDE (6)
358 #define SIR_NEGO_FAILED (7)
359 #define SIR_NEGO_PROTO (8)
360 #define SIR_REJECT_RECEIVED (9)
361 #define SIR_REJECT_SENT (10)
362 #define SIR_IGN_RESIDUE (11)
363 #define SIR_MISSING_SAVE (12)
364 #define SIR_MAX (12)
366 /*==========================================================
368 ** Extended error codes.
369 ** xerr_status field of struct nccb.
371 **==========================================================
374 #define XE_OK (0)
375 #define XE_EXTRA_DATA (1) /* unexpected data phase */
376 #define XE_BAD_PHASE (2) /* illegal phase (4/5) */
378 /*==========================================================
380 ** Negotiation status.
381 ** nego_status field of struct nccb.
383 **==========================================================
386 #define NS_SYNC (1)
387 #define NS_WIDE (2)
389 /*==========================================================
391 ** XXX These are no longer used. Remove once the
392 ** script is updated.
393 ** "Special features" of targets.
394 ** quirks field of struct tcb.
395 ** actualquirks field of struct nccb.
397 **==========================================================
400 #define QUIRK_AUTOSAVE (0x01)
401 #define QUIRK_NOMSG (0x02)
402 #define QUIRK_NOSYNC (0x10)
403 #define QUIRK_NOWIDE16 (0x20)
404 #define QUIRK_NOTAGS (0x40)
405 #define QUIRK_UPDATE (0x80)
407 /*==========================================================
409 ** Misc.
411 **==========================================================
414 #define CCB_MAGIC (0xf2691ad2)
415 #define MAX_TAGS (32) /* hard limit */
417 /*==========================================================
419 ** OS dependencies.
421 **==========================================================
424 #define PRINT_ADDR(ccb) xpt_print_path((ccb)->ccb_h.path)
426 /*==========================================================
428 ** Declaration of structs.
430 **==========================================================
433 struct tcb;
434 struct lcb;
435 struct nccb;
436 struct ncb;
437 struct script;
439 typedef struct ncb * ncb_p;
440 typedef struct tcb * tcb_p;
441 typedef struct lcb * lcb_p;
442 typedef struct nccb * nccb_p;
444 struct link {
445 ncrcmd l_cmd;
446 ncrcmd l_paddr;
449 struct usrcmd {
450 u_long target;
451 u_long lun;
452 u_long data;
453 u_long cmd;
456 #define UC_SETSYNC 10
457 #define UC_SETTAGS 11
458 #define UC_SETDEBUG 12
459 #define UC_SETORDER 13
460 #define UC_SETWIDE 14
461 #define UC_SETFLAG 15
463 #define UF_TRACE (0x01)
465 /*---------------------------------------
467 ** Timestamps for profiling
469 **---------------------------------------
472 /* Type of the kernel variable `ticks'. XXX should be declared with the var. */
473 typedef int ticks_t;
475 struct tstamp {
476 ticks_t start;
477 ticks_t end;
478 ticks_t select;
479 ticks_t command;
480 ticks_t data;
481 ticks_t status;
482 ticks_t disconnect;
486 ** profiling data (per device)
489 struct profile {
490 u_long num_trans;
491 u_long num_bytes;
492 u_long num_disc;
493 u_long num_break;
494 u_long num_int;
495 u_long num_fly;
496 u_long ms_setup;
497 u_long ms_data;
498 u_long ms_disc;
499 u_long ms_post;
502 /*==========================================================
504 ** Declaration of structs: target control block
506 **==========================================================
509 #define NCR_TRANS_CUR 0x01 /* Modify current neogtiation status */
510 #define NCR_TRANS_ACTIVE 0x03 /* Assume this is the active target */
511 #define NCR_TRANS_GOAL 0x04 /* Modify negotiation goal */
512 #define NCR_TRANS_USER 0x08 /* Modify user negotiation settings */
514 struct ncr_transinfo {
515 u_int8_t width;
516 u_int8_t period;
517 u_int8_t offset;
520 struct ncr_target_tinfo {
521 /* Hardware version of our sync settings */
522 u_int8_t disc_tag;
523 #define NCR_CUR_DISCENB 0x01
524 #define NCR_CUR_TAGENB 0x02
525 #define NCR_USR_DISCENB 0x04
526 #define NCR_USR_TAGENB 0x08
527 u_int8_t sval;
528 struct ncr_transinfo current;
529 struct ncr_transinfo goal;
530 struct ncr_transinfo user;
531 /* Hardware version of our wide settings */
532 u_int8_t wval;
535 struct tcb {
537 ** during reselection the ncr jumps to this point
538 ** with SFBR set to the encoded target number
539 ** with bit 7 set.
540 ** if it's not this target, jump to the next.
542 ** JUMP IF (SFBR != #target#)
543 ** @(next tcb)
546 struct link jump_tcb;
549 ** load the actual values for the sxfer and the scntl3
550 ** register (sync/wide mode).
552 ** SCR_COPY (1);
553 ** @(sval field of this tcb)
554 ** @(sxfer register)
555 ** SCR_COPY (1);
556 ** @(wval field of this tcb)
557 ** @(scntl3 register)
560 ncrcmd getscr[6];
563 ** if next message is "identify"
564 ** then load the message to SFBR,
565 ** else load 0 to SFBR.
567 ** CALL
568 ** <RESEL_LUN>
571 struct link call_lun;
574 ** now look for the right lun.
576 ** JUMP
577 ** @(first nccb of this lun)
580 struct link jump_lcb;
583 ** pointer to interrupted getcc nccb
586 nccb_p hold_cp;
589 ** pointer to nccb used for negotiating.
590 ** Avoid to start a nego for all queued commands
591 ** when tagged command queuing is enabled.
594 nccb_p nego_cp;
597 ** statistical data
600 u_long transfers;
601 u_long bytes;
604 ** user settable limits for sync transfer
605 ** and tagged commands.
608 struct ncr_target_tinfo tinfo;
611 ** the lcb's of this tcb
614 lcb_p lp[MAX_LUN];
617 /*==========================================================
619 ** Declaration of structs: lun control block
621 **==========================================================
624 struct lcb {
626 ** during reselection the ncr jumps to this point
627 ** with SFBR set to the "Identify" message.
628 ** if it's not this lun, jump to the next.
630 ** JUMP IF (SFBR != #lun#)
631 ** @(next lcb of this target)
634 struct link jump_lcb;
637 ** if next message is "simple tag",
638 ** then load the tag to SFBR,
639 ** else load 0 to SFBR.
641 ** CALL
642 ** <RESEL_TAG>
645 struct link call_tag;
648 ** now look for the right nccb.
650 ** JUMP
651 ** @(first nccb of this lun)
654 struct link jump_nccb;
657 ** start of the nccb chain
660 nccb_p next_nccb;
663 ** Control of tagged queueing
666 u_char reqnccbs;
667 u_char reqlink;
668 u_char actlink;
669 u_char usetags;
670 u_char lasttag;
673 /*==========================================================
675 ** Declaration of structs: COMMAND control block
677 **==========================================================
679 ** This substructure is copied from the nccb to a
680 ** global address after selection (or reselection)
681 ** and copied back before disconnect.
683 ** These fields are accessible to the script processor.
685 **----------------------------------------------------------
688 struct head {
690 ** Execution of a nccb starts at this point.
691 ** It's a jump to the "SELECT" label
692 ** of the script.
694 ** After successful selection the script
695 ** processor overwrites it with a jump to
696 ** the IDLE label of the script.
699 struct link launch;
702 ** Saved data pointer.
703 ** Points to the position in the script
704 ** responsible for the actual transfer
705 ** of data.
706 ** It's written after reception of a
707 ** "SAVE_DATA_POINTER" message.
708 ** The goalpointer points after
709 ** the last transfer command.
712 u_int32_t savep;
713 u_int32_t lastp;
714 u_int32_t goalp;
717 ** The virtual address of the nccb
718 ** containing this header.
721 nccb_p cp;
724 ** space for some timestamps to gather
725 ** profiling data about devices and this driver.
728 struct tstamp stamp;
731 ** status fields.
734 u_char status[8];
738 ** The status bytes are used by the host and the script processor.
740 ** The first four byte are copied to the scratchb register
741 ** (declared as scr0..scr3 in ncr_reg.h) just after the select/reselect,
742 ** and copied back just after disconnecting.
743 ** Inside the script the XX_REG are used.
745 ** The last four bytes are used inside the script by "COPY" commands.
746 ** Because source and destination must have the same alignment
747 ** in a longword, the fields HAVE to be at the choosen offsets.
748 ** xerr_st (4) 0 (0x34) scratcha
749 ** sync_st (5) 1 (0x05) sxfer
750 ** wide_st (7) 3 (0x03) scntl3
754 ** First four bytes (script)
756 #define QU_REG scr0
757 #define HS_REG scr1
758 #define HS_PRT nc_scr1
759 #define SS_REG scr2
760 #define PS_REG scr3
763 ** First four bytes (host)
765 #define actualquirks phys.header.status[0]
766 #define host_status phys.header.status[1]
767 #define s_status phys.header.status[2]
768 #define parity_status phys.header.status[3]
771 ** Last four bytes (script)
773 #define xerr_st header.status[4] /* MUST be ==0 mod 4 */
774 #define sync_st header.status[5] /* MUST be ==1 mod 4 */
775 #define nego_st header.status[6]
776 #define wide_st header.status[7] /* MUST be ==3 mod 4 */
779 ** Last four bytes (host)
781 #define xerr_status phys.xerr_st
782 #define sync_status phys.sync_st
783 #define nego_status phys.nego_st
784 #define wide_status phys.wide_st
786 /*==========================================================
788 ** Declaration of structs: Data structure block
790 **==========================================================
792 ** During execution of a nccb by the script processor,
793 ** the DSA (data structure address) register points
794 ** to this substructure of the nccb.
795 ** This substructure contains the header with
796 ** the script-processor-changable data and
797 ** data blocks for the indirect move commands.
799 **----------------------------------------------------------
802 struct dsb {
805 ** Header.
806 ** Has to be the first entry,
807 ** because it's jumped to by the
808 ** script processor
811 struct head header;
814 ** Table data for Script
817 struct scr_tblsel select;
818 struct scr_tblmove smsg ;
819 struct scr_tblmove smsg2 ;
820 struct scr_tblmove cmd ;
821 struct scr_tblmove scmd ;
822 struct scr_tblmove sense ;
823 struct scr_tblmove data [MAX_SCATTER];
826 /*==========================================================
828 ** Declaration of structs: Command control block.
830 **==========================================================
832 ** During execution of a nccb by the script processor,
833 ** the DSA (data structure address) register points
834 ** to this substructure of the nccb.
835 ** This substructure contains the header with
836 ** the script-processor-changable data and then
837 ** data blocks for the indirect move commands.
839 **----------------------------------------------------------
843 struct nccb {
845 ** This filler ensures that the global header is
846 ** cache line size aligned.
848 ncrcmd filler[4];
851 ** during reselection the ncr jumps to this point.
852 ** If a "SIMPLE_TAG" message was received,
853 ** then SFBR is set to the tag.
854 ** else SFBR is set to 0
855 ** If looking for another tag, jump to the next nccb.
857 ** JUMP IF (SFBR != #TAG#)
858 ** @(next nccb of this lun)
861 struct link jump_nccb;
864 ** After execution of this call, the return address
865 ** (in the TEMP register) points to the following
866 ** data structure block.
867 ** So copy it to the DSA register, and start
868 ** processing of this data structure.
870 ** CALL
871 ** <RESEL_TMP>
874 struct link call_tmp;
877 ** This is the data structure which is
878 ** to be executed by the script processor.
881 struct dsb phys;
884 ** If a data transfer phase is terminated too early
885 ** (after reception of a message (i.e. DISCONNECT)),
886 ** we have to prepare a mini script to transfer
887 ** the rest of the data.
890 ncrcmd patch[8];
893 ** The general SCSI driver provides a
894 ** pointer to a control block.
897 union ccb *ccb;
900 ** We prepare a message to be sent after selection,
901 ** and a second one to be sent after getcc selection.
902 ** Contents are IDENTIFY and SIMPLE_TAG.
903 ** While negotiating sync or wide transfer,
904 ** a SDTM or WDTM message is appended.
907 u_char scsi_smsg [8];
908 u_char scsi_smsg2[8];
911 ** Lock this nccb.
912 ** Flag is used while looking for a free nccb.
915 u_long magic;
918 ** Physical address of this instance of nccb
921 u_long p_nccb;
924 ** Completion time out for this job.
925 ** It's set to time of start + allowed number of seconds.
928 time_t tlimit;
931 ** All nccbs of one hostadapter are chained.
934 nccb_p link_nccb;
937 ** All nccbs of one target/lun are chained.
940 nccb_p next_nccb;
943 ** Sense command
946 u_char sensecmd[6];
949 ** Tag for this transfer.
950 ** It's patched into jump_nccb.
951 ** If it's not zero, a SIMPLE_TAG
952 ** message is included in smsg.
955 u_char tag;
958 #define CCB_PHYS(cp,lbl) (cp->p_nccb + offsetof(struct nccb, lbl))
960 /*==========================================================
962 ** Declaration of structs: NCR device descriptor
964 **==========================================================
967 struct ncb {
969 ** The global header.
970 ** Accessible to both the host and the
971 ** script-processor.
972 ** We assume it is cache line size aligned.
974 struct head header;
976 int unit;
978 /*-----------------------------------------------
979 ** Scripts ..
980 **-----------------------------------------------
982 ** During reselection the ncr jumps to this point.
983 ** The SFBR register is loaded with the encoded target id.
985 ** Jump to the first target.
987 ** JUMP
988 ** @(next tcb)
990 struct link jump_tcb;
992 /*-----------------------------------------------
993 ** Configuration ..
994 **-----------------------------------------------
996 ** virtual and physical addresses
997 ** of the 53c810 chip.
999 int reg_rid;
1000 struct resource *reg_res;
1001 bus_space_tag_t bst;
1002 bus_space_handle_t bsh;
1004 int sram_rid;
1005 struct resource *sram_res;
1006 bus_space_tag_t bst2;
1007 bus_space_handle_t bsh2;
1009 struct resource *irq_res;
1010 void *irq_handle;
1013 ** Scripts instance virtual address.
1015 struct script *script;
1016 struct scripth *scripth;
1019 ** Scripts instance physical address.
1021 u_long p_script;
1022 u_long p_scripth;
1025 ** The SCSI address of the host adapter.
1027 u_char myaddr;
1030 ** timing parameters
1032 u_char minsync; /* Minimum sync period factor */
1033 u_char maxsync; /* Maximum sync period factor */
1034 u_char maxoffs; /* Max scsi offset */
1035 u_char clock_divn; /* Number of clock divisors */
1036 u_long clock_khz; /* SCSI clock frequency in KHz */
1037 u_long features; /* Chip features map */
1038 u_char multiplier; /* Clock multiplier (1,2,4) */
1040 u_char maxburst; /* log base 2 of dwords burst */
1043 ** BIOS supplied PCI bus options
1045 u_char rv_scntl3;
1046 u_char rv_dcntl;
1047 u_char rv_dmode;
1048 u_char rv_ctest3;
1049 u_char rv_ctest4;
1050 u_char rv_ctest5;
1051 u_char rv_gpcntl;
1052 u_char rv_stest2;
1054 /*-----------------------------------------------
1055 ** CAM SIM information for this instance
1056 **-----------------------------------------------
1059 struct cam_sim *sim;
1060 struct cam_path *path;
1062 /*-----------------------------------------------
1063 ** Job control
1064 **-----------------------------------------------
1066 ** Commands from user
1068 struct usrcmd user;
1071 ** Target data
1073 struct tcb target[MAX_TARGET];
1076 ** Start queue.
1078 u_int32_t squeue [MAX_START];
1079 u_short squeueput;
1082 ** Timeout handler
1084 time_t heartbeat;
1085 u_short ticks;
1086 u_short latetime;
1087 time_t lasttime;
1088 struct callout timeout_ch;
1090 /*-----------------------------------------------
1091 ** Debug and profiling
1092 **-----------------------------------------------
1094 ** register dump
1096 struct ncr_reg regdump;
1097 time_t regtime;
1100 ** Profiling data
1102 struct profile profile;
1103 u_long disc_phys;
1104 u_long disc_ref;
1107 ** Head of list of all nccbs for this controller.
1109 nccb_p link_nccb;
1112 ** message buffers.
1113 ** Should be longword aligned,
1114 ** because they're written with a
1115 ** COPY script command.
1117 u_char msgout[8];
1118 u_char msgin [8];
1119 u_int32_t lastmsg;
1122 ** Buffer for STATUS_IN phase.
1124 u_char scratch;
1127 ** controller chip dependent maximal transfer width.
1129 u_char maxwide;
1131 #ifdef NCR_IOMAPPED
1133 ** address of the ncr control registers in io space
1135 pci_port_t port;
1136 #endif
1139 #define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
1140 #define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
1142 /*==========================================================
1145 ** Script for NCR-Processor.
1147 ** Use ncr_script_fill() to create the variable parts.
1148 ** Use ncr_script_copy_and_bind() to make a copy and
1149 ** bind to physical addresses.
1152 **==========================================================
1154 ** We have to know the offsets of all labels before
1155 ** we reach them (for forward jumps).
1156 ** Therefore we declare a struct here.
1157 ** If you make changes inside the script,
1158 ** DONT FORGET TO CHANGE THE LENGTHS HERE!
1160 **----------------------------------------------------------
1164 ** Script fragments which are loaded into the on-board RAM
1165 ** of 825A, 875 and 895 chips.
1167 struct script {
1168 ncrcmd start [ 7];
1169 ncrcmd start0 [ 2];
1170 ncrcmd start1 [ 3];
1171 ncrcmd startpos [ 1];
1172 ncrcmd trysel [ 8];
1173 ncrcmd skip [ 8];
1174 ncrcmd skip2 [ 3];
1175 ncrcmd idle [ 2];
1176 ncrcmd select [ 18];
1177 ncrcmd prepare [ 4];
1178 ncrcmd loadpos [ 14];
1179 ncrcmd prepare2 [ 24];
1180 ncrcmd setmsg [ 5];
1181 ncrcmd clrack [ 2];
1182 ncrcmd dispatch [ 33];
1183 ncrcmd no_data [ 17];
1184 ncrcmd checkatn [ 10];
1185 ncrcmd command [ 15];
1186 ncrcmd status [ 27];
1187 ncrcmd msg_in [ 26];
1188 ncrcmd msg_bad [ 6];
1189 ncrcmd complete [ 13];
1190 ncrcmd cleanup [ 12];
1191 ncrcmd cleanup0 [ 9];
1192 ncrcmd signal [ 12];
1193 ncrcmd save_dp [ 5];
1194 ncrcmd restore_dp [ 5];
1195 ncrcmd disconnect [ 12];
1196 ncrcmd disconnect0 [ 5];
1197 ncrcmd disconnect1 [ 23];
1198 ncrcmd msg_out [ 9];
1199 ncrcmd msg_out_done [ 7];
1200 ncrcmd badgetcc [ 6];
1201 ncrcmd reselect [ 8];
1202 ncrcmd reselect1 [ 8];
1203 ncrcmd reselect2 [ 8];
1204 ncrcmd resel_tmp [ 5];
1205 ncrcmd resel_lun [ 18];
1206 ncrcmd resel_tag [ 24];
1207 ncrcmd data_in [MAX_SCATTER * 4 + 7];
1208 ncrcmd data_out [MAX_SCATTER * 4 + 7];
1212 ** Script fragments which stay in main memory for all chips.
1214 struct scripth {
1215 ncrcmd tryloop [MAX_START*5+2];
1216 ncrcmd msg_parity [ 6];
1217 ncrcmd msg_reject [ 8];
1218 ncrcmd msg_ign_residue [ 32];
1219 ncrcmd msg_extended [ 18];
1220 ncrcmd msg_ext_2 [ 18];
1221 ncrcmd msg_wdtr [ 27];
1222 ncrcmd msg_ext_3 [ 18];
1223 ncrcmd msg_sdtr [ 27];
1224 ncrcmd msg_out_abort [ 10];
1225 ncrcmd getcc [ 4];
1226 ncrcmd getcc1 [ 5];
1227 #ifdef NCR_GETCC_WITHMSG
1228 ncrcmd getcc2 [ 29];
1229 #else
1230 ncrcmd getcc2 [ 14];
1231 #endif
1232 ncrcmd getcc3 [ 6];
1233 ncrcmd aborttag [ 4];
1234 ncrcmd abort [ 22];
1235 ncrcmd snooptest [ 9];
1236 ncrcmd snoopend [ 2];
1239 /*==========================================================
1242 ** Function headers.
1245 **==========================================================
1248 #ifdef _KERNEL
1249 static nccb_p ncr_alloc_nccb (ncb_p np, u_long target, u_long lun);
1250 static void ncr_complete (ncb_p np, nccb_p cp);
1251 static int ncr_delta (int * from, int * to);
1252 static void ncr_exception (ncb_p np);
1253 static void ncr_free_nccb (ncb_p np, nccb_p cp);
1254 static void ncr_freeze_devq (ncb_p np, struct cam_path *path);
1255 static void ncr_selectclock (ncb_p np, u_char scntl3);
1256 static void ncr_getclock (ncb_p np, u_char multiplier);
1257 static nccb_p ncr_get_nccb (ncb_p np, u_long t,u_long l);
1258 #if 0
1259 static u_int32_t ncr_info (int unit);
1260 #endif
1261 static void ncr_init (ncb_p np, char * msg, u_long code);
1262 static void ncr_intr (void *vnp);
1263 static void ncr_int_ma (ncb_p np, u_char dstat);
1264 static void ncr_int_sir (ncb_p np);
1265 static void ncr_int_sto (ncb_p np);
1266 #if 0
1267 static void ncr_min_phys (struct buf *bp);
1268 #endif
1269 static void ncr_poll (struct cam_sim *sim);
1270 static void ncb_profile (ncb_p np, nccb_p cp);
1271 static void ncr_script_copy_and_bind
1272 (ncb_p np, ncrcmd *src, ncrcmd *dst, int len);
1273 static void ncr_script_fill (struct script * scr, struct scripth *scrh);
1274 static int ncr_scatter (struct dsb* phys, vm_offset_t vaddr,
1275 vm_size_t datalen);
1276 static void ncr_getsync (ncb_p np, u_char sfac, u_char *fakp,
1277 u_char *scntl3p);
1278 static void ncr_setsync (ncb_p np, nccb_p cp,u_char scntl3,u_char sxfer,
1279 u_char period);
1280 static void ncr_setwide (ncb_p np, nccb_p cp, u_char wide, u_char ack);
1281 static int ncr_show_msg (u_char * msg);
1282 static int ncr_snooptest (ncb_p np);
1283 static void ncr_action (struct cam_sim *sim, union ccb *ccb);
1284 static void ncr_timeout (void *arg);
1285 static void ncr_wakeup (ncb_p np, u_long code);
1287 static int ncr_probe (device_t dev);
1288 static int ncr_attach (device_t dev);
1290 #endif /* _KERNEL */
1292 /*==========================================================
1295 ** Global static data.
1298 **==========================================================
1303 * $FreeBSD: src/sys/pci/ncr.c,v 1.155.2.3 2001/03/05 13:09:10 obrien Exp $
1305 static const u_long ncr_version = NCR_VERSION * 11
1306 + (u_long) sizeof (struct ncb) * 7
1307 + (u_long) sizeof (struct nccb) * 5
1308 + (u_long) sizeof (struct lcb) * 3
1309 + (u_long) sizeof (struct tcb) * 2;
1311 #ifdef _KERNEL
1313 static int ncr_debug = SCSI_NCR_DEBUG;
1314 SYSCTL_INT(_debug, OID_AUTO, ncr_debug, CTLFLAG_RW, &ncr_debug, 0,
1315 "Driver debug flags");
1317 static int ncr_cache; /* to be aligned _NOT_ static */
1319 /*==========================================================
1322 ** Global static data: auto configure
1325 **==========================================================
1328 #define NCR_810_ID (0x00011000ul)
1329 #define NCR_815_ID (0x00041000ul)
1330 #define NCR_820_ID (0x00021000ul)
1331 #define NCR_825_ID (0x00031000ul)
1332 #define NCR_860_ID (0x00061000ul)
1333 #define NCR_875_ID (0x000f1000ul)
1334 #define NCR_875_ID2 (0x008f1000ul)
1335 #define NCR_885_ID (0x000d1000ul)
1336 #define NCR_895_ID (0x000c1000ul)
1337 #define NCR_896_ID (0x000b1000ul)
1338 #define NCR_895A_ID (0x00121000ul)
1339 #define NCR_1510D_ID (0x000a1000ul)
1342 static char *ncr_name (ncb_p np)
1344 static char name[10];
1345 ksnprintf(name, sizeof(name), "ncr%d", np->unit);
1346 return (name);
1349 /*==========================================================
1352 ** Scripts for NCR-Processor.
1354 ** Use ncr_script_bind for binding to physical addresses.
1357 **==========================================================
1359 ** NADDR generates a reference to a field of the controller data.
1360 ** PADDR generates a reference to another part of the script.
1361 ** RADDR generates a reference to a script processor register.
1362 ** FADDR generates a reference to a script processor register
1363 ** with offset.
1365 **----------------------------------------------------------
1368 #define RELOC_SOFTC 0x40000000
1369 #define RELOC_LABEL 0x50000000
1370 #define RELOC_REGISTER 0x60000000
1371 #define RELOC_KVAR 0x70000000
1372 #define RELOC_LABELH 0x80000000
1373 #define RELOC_MASK 0xf0000000
1375 #define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
1376 #define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
1377 #define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
1378 #define RADDR(label) (RELOC_REGISTER | REG(label))
1379 #define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
1380 #define KVAR(which) (RELOC_KVAR | (which))
1382 #define KVAR_SECOND (0)
1383 #define KVAR_TICKS (1)
1384 #define KVAR_NCR_CACHE (2)
1386 #define SCRIPT_KVAR_FIRST (0)
1387 #define SCRIPT_KVAR_LAST (3)
1390 * Kernel variables referenced in the scripts.
1391 * THESE MUST ALL BE ALIGNED TO A 4-BYTE BOUNDARY.
1393 static void *script_kvars[] =
1394 { &time_uptime, &ticks, &ncr_cache };
1396 static struct script script0 = {
1397 /*--------------------------< START >-----------------------*/ {
1399 ** Claim to be still alive ...
1401 SCR_COPY (sizeof (((struct ncb *)0)->heartbeat)),
1402 KVAR (KVAR_SECOND),
1403 NADDR (heartbeat),
1405 ** Make data structure address invalid.
1406 ** clear SIGP.
1408 SCR_LOAD_REG (dsa, 0xff),
1410 SCR_FROM_REG (ctest2),
1412 }/*-------------------------< START0 >----------------------*/,{
1414 ** Hook for interrupted GetConditionCode.
1415 ** Will be patched to ... IFTRUE by
1416 ** the interrupt handler.
1418 SCR_INT ^ IFFALSE (0),
1419 SIR_SENSE_RESTART,
1421 }/*-------------------------< START1 >----------------------*/,{
1423 ** Hook for stalled start queue.
1424 ** Will be patched to IFTRUE by the interrupt handler.
1426 SCR_INT ^ IFFALSE (0),
1427 SIR_STALL_RESTART,
1429 ** Then jump to a certain point in tryloop.
1430 ** Due to the lack of indirect addressing the code
1431 ** is self modifying here.
1433 SCR_JUMP,
1434 }/*-------------------------< STARTPOS >--------------------*/,{
1435 PADDRH(tryloop),
1437 }/*-------------------------< TRYSEL >----------------------*/,{
1439 ** Now:
1440 ** DSA: Address of a Data Structure
1441 ** or Address of the IDLE-Label.
1443 ** TEMP: Address of a script, which tries to
1444 ** start the NEXT entry.
1446 ** Save the TEMP register into the SCRATCHA register.
1447 ** Then copy the DSA to TEMP and RETURN.
1448 ** This is kind of an indirect jump.
1449 ** (The script processor has NO stack, so the
1450 ** CALL is actually a jump and link, and the
1451 ** RETURN is an indirect jump.)
1453 ** If the slot was empty, DSA contains the address
1454 ** of the IDLE part of this script. The processor
1455 ** jumps to IDLE and waits for a reselect.
1456 ** It will wake up and try the same slot again
1457 ** after the SIGP bit becomes set by the host.
1459 ** If the slot was not empty, DSA contains
1460 ** the address of the phys-part of a nccb.
1461 ** The processor jumps to this address.
1462 ** phys starts with head,
1463 ** head starts with launch,
1464 ** so actually the processor jumps to
1465 ** the lauch part.
1466 ** If the entry is scheduled for execution,
1467 ** then launch contains a jump to SELECT.
1468 ** If it's not scheduled, it contains a jump to IDLE.
1470 SCR_COPY (4),
1471 RADDR (temp),
1472 RADDR (scratcha),
1473 SCR_COPY (4),
1474 RADDR (dsa),
1475 RADDR (temp),
1476 SCR_RETURN,
1479 }/*-------------------------< SKIP >------------------------*/,{
1481 ** This entry has been canceled.
1482 ** Next time use the next slot.
1484 SCR_COPY (4),
1485 RADDR (scratcha),
1486 PADDR (startpos),
1488 ** patch the launch field.
1489 ** should look like an idle process.
1491 SCR_COPY_F (4),
1492 RADDR (dsa),
1493 PADDR (skip2),
1494 SCR_COPY (8),
1495 PADDR (idle),
1496 }/*-------------------------< SKIP2 >-----------------------*/,{
1498 SCR_JUMP,
1499 PADDR(start),
1500 }/*-------------------------< IDLE >------------------------*/,{
1502 ** Nothing to do?
1503 ** Wait for reselect.
1505 SCR_JUMP,
1506 PADDR(reselect),
1508 }/*-------------------------< SELECT >----------------------*/,{
1510 ** DSA contains the address of a scheduled
1511 ** data structure.
1513 ** SCRATCHA contains the address of the script,
1514 ** which starts the next entry.
1516 ** Set Initiator mode.
1518 ** (Target mode is left as an exercise for the reader)
1521 SCR_CLR (SCR_TRG),
1523 SCR_LOAD_REG (HS_REG, 0xff),
1527 ** And try to select this target.
1529 SCR_SEL_TBL_ATN ^ offsetof (struct dsb, select),
1530 PADDR (reselect),
1533 ** Now there are 4 possibilities:
1535 ** (1) The ncr looses arbitration.
1536 ** This is ok, because it will try again,
1537 ** when the bus becomes idle.
1538 ** (But beware of the timeout function!)
1540 ** (2) The ncr is reselected.
1541 ** Then the script processor takes the jump
1542 ** to the RESELECT label.
1544 ** (3) The ncr completes the selection.
1545 ** Then it will execute the next statement.
1547 ** (4) There is a selection timeout.
1548 ** Then the ncr should interrupt the host and stop.
1549 ** Unfortunately, it seems to continue execution
1550 ** of the script. But it will fail with an
1551 ** IID-interrupt on the next WHEN.
1554 SCR_JUMPR ^ IFTRUE (WHEN (SCR_MSG_IN)),
1558 ** Send the IDENTIFY and SIMPLE_TAG messages
1559 ** (and the MSG_EXT_SDTR message)
1561 SCR_MOVE_TBL ^ SCR_MSG_OUT,
1562 offsetof (struct dsb, smsg),
1563 #ifdef undef /* XXX better fail than try to deal with this ... */
1564 SCR_JUMPR ^ IFTRUE (WHEN (SCR_MSG_OUT)),
1565 -16,
1566 #endif
1567 SCR_CLR (SCR_ATN),
1569 SCR_COPY (1),
1570 RADDR (sfbr),
1571 NADDR (lastmsg),
1573 ** Selection complete.
1574 ** Next time use the next slot.
1576 SCR_COPY (4),
1577 RADDR (scratcha),
1578 PADDR (startpos),
1579 }/*-------------------------< PREPARE >----------------------*/,{
1581 ** The ncr doesn't have an indirect load
1582 ** or store command. So we have to
1583 ** copy part of the control block to a
1584 ** fixed place, where we can access it.
1586 ** We patch the address part of a
1587 ** COPY command with the DSA-register.
1589 SCR_COPY_F (4),
1590 RADDR (dsa),
1591 PADDR (loadpos),
1593 ** then we do the actual copy.
1595 SCR_COPY (sizeof (struct head)),
1597 ** continued after the next label ...
1600 }/*-------------------------< LOADPOS >---------------------*/,{
1602 NADDR (header),
1604 ** Mark this nccb as not scheduled.
1606 SCR_COPY (8),
1607 PADDR (idle),
1608 NADDR (header.launch),
1610 ** Set a time stamp for this selection
1612 SCR_COPY (sizeof (ticks)),
1613 KVAR (KVAR_TICKS),
1614 NADDR (header.stamp.select),
1616 ** load the savep (saved pointer) into
1617 ** the TEMP register (actual pointer)
1619 SCR_COPY (4),
1620 NADDR (header.savep),
1621 RADDR (temp),
1623 ** Initialize the status registers
1625 SCR_COPY (4),
1626 NADDR (header.status),
1627 RADDR (scr0),
1629 }/*-------------------------< PREPARE2 >---------------------*/,{
1631 ** Load the synchronous mode register
1633 SCR_COPY (1),
1634 NADDR (sync_st),
1635 RADDR (sxfer),
1637 ** Load the wide mode and timing register
1639 SCR_COPY (1),
1640 NADDR (wide_st),
1641 RADDR (scntl3),
1643 ** Initialize the msgout buffer with a NOOP message.
1645 SCR_LOAD_REG (scratcha, MSG_NOOP),
1647 SCR_COPY (1),
1648 RADDR (scratcha),
1649 NADDR (msgout),
1650 SCR_COPY (1),
1651 RADDR (scratcha),
1652 NADDR (msgin),
1654 ** Message in phase ?
1656 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
1657 PADDR (dispatch),
1659 ** Extended or reject message ?
1661 SCR_FROM_REG (sbdl),
1663 SCR_JUMP ^ IFTRUE (DATA (MSG_EXTENDED)),
1664 PADDR (msg_in),
1665 SCR_JUMP ^ IFTRUE (DATA (MSG_MESSAGE_REJECT)),
1666 PADDRH (msg_reject),
1668 ** normal processing
1670 SCR_JUMP,
1671 PADDR (dispatch),
1672 }/*-------------------------< SETMSG >----------------------*/,{
1673 SCR_COPY (1),
1674 RADDR (scratcha),
1675 NADDR (msgout),
1676 SCR_SET (SCR_ATN),
1678 }/*-------------------------< CLRACK >----------------------*/,{
1680 ** Terminate possible pending message phase.
1682 SCR_CLR (SCR_ACK),
1685 }/*-----------------------< DISPATCH >----------------------*/,{
1686 SCR_FROM_REG (HS_REG),
1688 SCR_INT ^ IFTRUE (DATA (HS_NEGOTIATE)),
1689 SIR_NEGO_FAILED,
1691 ** remove bogus output signals
1693 SCR_REG_REG (socl, SCR_AND, CACK|CATN),
1695 SCR_RETURN ^ IFTRUE (WHEN (SCR_DATA_OUT)),
1697 SCR_RETURN ^ IFTRUE (IF (SCR_DATA_IN)),
1699 SCR_JUMP ^ IFTRUE (IF (SCR_MSG_OUT)),
1700 PADDR (msg_out),
1701 SCR_JUMP ^ IFTRUE (IF (SCR_MSG_IN)),
1702 PADDR (msg_in),
1703 SCR_JUMP ^ IFTRUE (IF (SCR_COMMAND)),
1704 PADDR (command),
1705 SCR_JUMP ^ IFTRUE (IF (SCR_STATUS)),
1706 PADDR (status),
1708 ** Discard one illegal phase byte, if required.
1710 SCR_LOAD_REG (scratcha, XE_BAD_PHASE),
1712 SCR_COPY (1),
1713 RADDR (scratcha),
1714 NADDR (xerr_st),
1715 SCR_JUMPR ^ IFFALSE (IF (SCR_ILG_OUT)),
1717 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT,
1718 NADDR (scratch),
1719 SCR_JUMPR ^ IFFALSE (IF (SCR_ILG_IN)),
1721 SCR_MOVE_ABS (1) ^ SCR_ILG_IN,
1722 NADDR (scratch),
1723 SCR_JUMP,
1724 PADDR (dispatch),
1726 }/*-------------------------< NO_DATA >--------------------*/,{
1728 ** The target wants to tranfer too much data
1729 ** or in the wrong direction.
1730 ** Remember that in extended error.
1732 SCR_LOAD_REG (scratcha, XE_EXTRA_DATA),
1734 SCR_COPY (1),
1735 RADDR (scratcha),
1736 NADDR (xerr_st),
1738 ** Discard one data byte, if required.
1740 SCR_JUMPR ^ IFFALSE (WHEN (SCR_DATA_OUT)),
1742 SCR_MOVE_ABS (1) ^ SCR_DATA_OUT,
1743 NADDR (scratch),
1744 SCR_JUMPR ^ IFFALSE (IF (SCR_DATA_IN)),
1746 SCR_MOVE_ABS (1) ^ SCR_DATA_IN,
1747 NADDR (scratch),
1749 ** .. and repeat as required.
1751 SCR_CALL,
1752 PADDR (dispatch),
1753 SCR_JUMP,
1754 PADDR (no_data),
1755 }/*-------------------------< CHECKATN >--------------------*/,{
1757 ** If AAP (bit 1 of scntl0 register) is set
1758 ** and a parity error is detected,
1759 ** the script processor asserts ATN.
1761 ** The target should switch to a MSG_OUT phase
1762 ** to get the message.
1764 SCR_FROM_REG (socl),
1766 SCR_JUMP ^ IFFALSE (MASK (CATN, CATN)),
1767 PADDR (dispatch),
1769 ** count it
1771 SCR_REG_REG (PS_REG, SCR_ADD, 1),
1774 ** Prepare a MSG_INITIATOR_DET_ERR message
1775 ** (initiator detected error).
1776 ** The target should retry the transfer.
1778 SCR_LOAD_REG (scratcha, MSG_INITIATOR_DET_ERR),
1780 SCR_JUMP,
1781 PADDR (setmsg),
1783 }/*-------------------------< COMMAND >--------------------*/,{
1785 ** If this is not a GETCC transfer ...
1787 SCR_FROM_REG (SS_REG),
1789 /*<<<*/ SCR_JUMPR ^ IFTRUE (DATA (SCSI_STATUS_CHECK_COND)),
1792 ** ... set a timestamp ...
1794 SCR_COPY (sizeof (ticks)),
1795 KVAR (KVAR_TICKS),
1796 NADDR (header.stamp.command),
1798 ** ... and send the command
1800 SCR_MOVE_TBL ^ SCR_COMMAND,
1801 offsetof (struct dsb, cmd),
1802 SCR_JUMP,
1803 PADDR (dispatch),
1805 ** Send the GETCC command
1807 /*>>>*/ SCR_MOVE_TBL ^ SCR_COMMAND,
1808 offsetof (struct dsb, scmd),
1809 SCR_JUMP,
1810 PADDR (dispatch),
1812 }/*-------------------------< STATUS >--------------------*/,{
1814 ** set the timestamp.
1816 SCR_COPY (sizeof (ticks)),
1817 KVAR (KVAR_TICKS),
1818 NADDR (header.stamp.status),
1820 ** If this is a GETCC transfer,
1822 SCR_FROM_REG (SS_REG),
1824 /*<<<*/ SCR_JUMPR ^ IFFALSE (DATA (SCSI_STATUS_CHECK_COND)),
1827 ** get the status
1829 SCR_MOVE_ABS (1) ^ SCR_STATUS,
1830 NADDR (scratch),
1832 ** Save status to scsi_status.
1833 ** Mark as complete.
1834 ** And wait for disconnect.
1836 SCR_TO_REG (SS_REG),
1838 SCR_REG_REG (SS_REG, SCR_OR, SCSI_STATUS_SENSE),
1840 SCR_LOAD_REG (HS_REG, HS_COMPLETE),
1842 SCR_JUMP,
1843 PADDR (checkatn),
1845 ** If it was no GETCC transfer,
1846 ** save the status to scsi_status.
1848 /*>>>*/ SCR_MOVE_ABS (1) ^ SCR_STATUS,
1849 NADDR (scratch),
1850 SCR_TO_REG (SS_REG),
1853 ** if it was no check condition ...
1855 SCR_JUMP ^ IFTRUE (DATA (SCSI_STATUS_CHECK_COND)),
1856 PADDR (checkatn),
1858 ** ... mark as complete.
1860 SCR_LOAD_REG (HS_REG, HS_COMPLETE),
1862 SCR_JUMP,
1863 PADDR (checkatn),
1865 }/*-------------------------< MSG_IN >--------------------*/,{
1867 ** Get the first byte of the message
1868 ** and save it to SCRATCHA.
1870 ** The script processor doesn't negate the
1871 ** ACK signal after this transfer.
1873 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
1874 NADDR (msgin[0]),
1876 ** Check for message parity error.
1878 SCR_TO_REG (scratcha),
1880 SCR_FROM_REG (socl),
1882 SCR_JUMP ^ IFTRUE (MASK (CATN, CATN)),
1883 PADDRH (msg_parity),
1884 SCR_FROM_REG (scratcha),
1887 ** Parity was ok, handle this message.
1889 SCR_JUMP ^ IFTRUE (DATA (MSG_CMDCOMPLETE)),
1890 PADDR (complete),
1891 SCR_JUMP ^ IFTRUE (DATA (MSG_SAVEDATAPOINTER)),
1892 PADDR (save_dp),
1893 SCR_JUMP ^ IFTRUE (DATA (MSG_RESTOREPOINTERS)),
1894 PADDR (restore_dp),
1895 SCR_JUMP ^ IFTRUE (DATA (MSG_DISCONNECT)),
1896 PADDR (disconnect),
1897 SCR_JUMP ^ IFTRUE (DATA (MSG_EXTENDED)),
1898 PADDRH (msg_extended),
1899 SCR_JUMP ^ IFTRUE (DATA (MSG_NOOP)),
1900 PADDR (clrack),
1901 SCR_JUMP ^ IFTRUE (DATA (MSG_MESSAGE_REJECT)),
1902 PADDRH (msg_reject),
1903 SCR_JUMP ^ IFTRUE (DATA (MSG_IGN_WIDE_RESIDUE)),
1904 PADDRH (msg_ign_residue),
1906 ** Rest of the messages left as
1907 ** an exercise ...
1909 ** Unimplemented messages:
1910 ** fall through to MSG_BAD.
1912 }/*-------------------------< MSG_BAD >------------------*/,{
1914 ** unimplemented message - reject it.
1916 SCR_INT,
1917 SIR_REJECT_SENT,
1918 SCR_LOAD_REG (scratcha, MSG_MESSAGE_REJECT),
1920 SCR_JUMP,
1921 PADDR (setmsg),
1923 }/*-------------------------< COMPLETE >-----------------*/,{
1925 ** Complete message.
1927 ** If it's not the get condition code,
1928 ** copy TEMP register to LASTP in header.
1930 SCR_FROM_REG (SS_REG),
1932 /*<<<*/ SCR_JUMPR ^ IFTRUE (MASK (SCSI_STATUS_SENSE, SCSI_STATUS_SENSE)),
1934 SCR_COPY (4),
1935 RADDR (temp),
1936 NADDR (header.lastp),
1937 /*>>>*/ /*
1938 ** When we terminate the cycle by clearing ACK,
1939 ** the target may disconnect immediately.
1941 ** We don't want to be told of an
1942 ** "unexpected disconnect",
1943 ** so we disable this feature.
1945 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
1948 ** Terminate cycle ...
1950 SCR_CLR (SCR_ACK|SCR_ATN),
1953 ** ... and wait for the disconnect.
1955 SCR_WAIT_DISC,
1957 }/*-------------------------< CLEANUP >-------------------*/,{
1959 ** dsa: Pointer to nccb
1960 ** or xxxxxxFF (no nccb)
1962 ** HS_REG: Host-Status (<>0!)
1964 SCR_FROM_REG (dsa),
1966 SCR_JUMP ^ IFTRUE (DATA (0xff)),
1967 PADDR (signal),
1969 ** dsa is valid.
1970 ** save the status registers
1972 SCR_COPY (4),
1973 RADDR (scr0),
1974 NADDR (header.status),
1976 ** and copy back the header to the nccb.
1978 SCR_COPY_F (4),
1979 RADDR (dsa),
1980 PADDR (cleanup0),
1981 SCR_COPY (sizeof (struct head)),
1982 NADDR (header),
1983 }/*-------------------------< CLEANUP0 >--------------------*/,{
1987 ** If command resulted in "check condition"
1988 ** status and is not yet completed,
1989 ** try to get the condition code.
1991 SCR_FROM_REG (HS_REG),
1993 /*<<<*/ SCR_JUMPR ^ IFFALSE (MASK (0, HS_DONEMASK)),
1995 SCR_FROM_REG (SS_REG),
1997 SCR_JUMP ^ IFTRUE (DATA (SCSI_STATUS_CHECK_COND)),
1998 PADDRH(getcc2),
1999 }/*-------------------------< SIGNAL >----------------------*/,{
2001 ** if status = queue full,
2002 ** reinsert in startqueue and stall queue.
2004 /*>>>*/ SCR_FROM_REG (SS_REG),
2006 SCR_INT ^ IFTRUE (DATA (SCSI_STATUS_QUEUE_FULL)),
2007 SIR_STALL_QUEUE,
2009 ** And make the DSA register invalid.
2011 SCR_LOAD_REG (dsa, 0xff), /* invalid */
2014 ** if job completed ...
2016 SCR_FROM_REG (HS_REG),
2019 ** ... signal completion to the host
2021 SCR_INT_FLY ^ IFFALSE (MASK (0, HS_DONEMASK)),
2024 ** Auf zu neuen Schandtaten!
2026 SCR_JUMP,
2027 PADDR(start),
2029 }/*-------------------------< SAVE_DP >------------------*/,{
2031 ** SAVE_DP message:
2032 ** Copy TEMP register to SAVEP in header.
2034 SCR_COPY (4),
2035 RADDR (temp),
2036 NADDR (header.savep),
2037 SCR_JUMP,
2038 PADDR (clrack),
2039 }/*-------------------------< RESTORE_DP >---------------*/,{
2041 ** RESTORE_DP message:
2042 ** Copy SAVEP in header to TEMP register.
2044 SCR_COPY (4),
2045 NADDR (header.savep),
2046 RADDR (temp),
2047 SCR_JUMP,
2048 PADDR (clrack),
2050 }/*-------------------------< DISCONNECT >---------------*/,{
2052 ** If QUIRK_AUTOSAVE is set,
2053 ** do an "save pointer" operation.
2055 SCR_FROM_REG (QU_REG),
2057 /*<<<*/ SCR_JUMPR ^ IFFALSE (MASK (QUIRK_AUTOSAVE, QUIRK_AUTOSAVE)),
2060 ** like SAVE_DP message:
2061 ** Copy TEMP register to SAVEP in header.
2063 SCR_COPY (4),
2064 RADDR (temp),
2065 NADDR (header.savep),
2066 /*>>>*/ /*
2067 ** Check if temp==savep or temp==goalp:
2068 ** if not, log a missing save pointer message.
2069 ** In fact, it's a comparison mod 256.
2071 ** Hmmm, I hadn't thought that I would be urged to
2072 ** write this kind of ugly self modifying code.
2074 ** It's unbelievable, but the ncr53c8xx isn't able
2075 ** to subtract one register from another.
2077 SCR_FROM_REG (temp),
2080 ** You are not expected to understand this ..
2082 ** CAUTION: only little endian architectures supported! XXX
2084 SCR_COPY_F (1),
2085 NADDR (header.savep),
2086 PADDR (disconnect0),
2087 }/*-------------------------< DISCONNECT0 >--------------*/,{
2088 /*<<<*/ SCR_JUMPR ^ IFTRUE (DATA (1)),
2091 ** neither this
2093 SCR_COPY_F (1),
2094 NADDR (header.goalp),
2095 PADDR (disconnect1),
2096 }/*-------------------------< DISCONNECT1 >--------------*/,{
2097 SCR_INT ^ IFFALSE (DATA (1)),
2098 SIR_MISSING_SAVE,
2099 /*>>>*/
2102 ** DISCONNECTing ...
2104 ** disable the "unexpected disconnect" feature,
2105 ** and remove the ACK signal.
2107 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
2109 SCR_CLR (SCR_ACK|SCR_ATN),
2112 ** Wait for the disconnect.
2114 SCR_WAIT_DISC,
2117 ** Profiling:
2118 ** Set a time stamp,
2119 ** and count the disconnects.
2121 SCR_COPY (sizeof (ticks)),
2122 KVAR (KVAR_TICKS),
2123 NADDR (header.stamp.disconnect),
2124 SCR_COPY (4),
2125 NADDR (disc_phys),
2126 RADDR (temp),
2127 SCR_REG_REG (temp, SCR_ADD, 0x01),
2129 SCR_COPY (4),
2130 RADDR (temp),
2131 NADDR (disc_phys),
2133 ** Status is: DISCONNECTED.
2135 SCR_LOAD_REG (HS_REG, HS_DISCONNECT),
2137 SCR_JUMP,
2138 PADDR (cleanup),
2140 }/*-------------------------< MSG_OUT >-------------------*/,{
2142 ** The target requests a message.
2144 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
2145 NADDR (msgout),
2146 SCR_COPY (1),
2147 RADDR (sfbr),
2148 NADDR (lastmsg),
2150 ** If it was no ABORT message ...
2152 SCR_JUMP ^ IFTRUE (DATA (MSG_ABORT)),
2153 PADDRH (msg_out_abort),
2155 ** ... wait for the next phase
2156 ** if it's a message out, send it again, ...
2158 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_OUT)),
2159 PADDR (msg_out),
2160 }/*-------------------------< MSG_OUT_DONE >--------------*/,{
2162 ** ... else clear the message ...
2164 SCR_LOAD_REG (scratcha, MSG_NOOP),
2166 SCR_COPY (4),
2167 RADDR (scratcha),
2168 NADDR (msgout),
2170 ** ... and process the next phase
2172 SCR_JUMP,
2173 PADDR (dispatch),
2175 }/*------------------------< BADGETCC >---------------------*/,{
2177 ** If SIGP was set, clear it and try again.
2179 SCR_FROM_REG (ctest2),
2181 SCR_JUMP ^ IFTRUE (MASK (CSIGP,CSIGP)),
2182 PADDRH (getcc2),
2183 SCR_INT,
2184 SIR_SENSE_FAILED,
2185 }/*-------------------------< RESELECT >--------------------*/,{
2187 ** This NOP will be patched with LED OFF
2188 ** SCR_REG_REG (gpreg, SCR_OR, 0x01)
2190 SCR_NO_OP,
2194 ** make the DSA invalid.
2196 SCR_LOAD_REG (dsa, 0xff),
2198 SCR_CLR (SCR_TRG),
2201 ** Sleep waiting for a reselection.
2202 ** If SIGP is set, special treatment.
2204 ** Zu allem bereit ..
2206 SCR_WAIT_RESEL,
2207 PADDR(reselect2),
2208 }/*-------------------------< RESELECT1 >--------------------*/,{
2210 ** This NOP will be patched with LED ON
2211 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
2213 SCR_NO_OP,
2216 ** ... zu nichts zu gebrauchen ?
2218 ** load the target id into the SFBR
2219 ** and jump to the control block.
2221 ** Look at the declarations of
2222 ** - struct ncb
2223 ** - struct tcb
2224 ** - struct lcb
2225 ** - struct nccb
2226 ** to understand what's going on.
2228 SCR_REG_SFBR (ssid, SCR_AND, 0x8F),
2230 SCR_TO_REG (sdid),
2232 SCR_JUMP,
2233 NADDR (jump_tcb),
2234 }/*-------------------------< RESELECT2 >-------------------*/,{
2236 ** This NOP will be patched with LED ON
2237 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
2239 SCR_NO_OP,
2242 ** If it's not connected :(
2243 ** -> interrupted by SIGP bit.
2244 ** Jump to start.
2246 SCR_FROM_REG (ctest2),
2248 SCR_JUMP ^ IFTRUE (MASK (CSIGP,CSIGP)),
2249 PADDR (start),
2250 SCR_JUMP,
2251 PADDR (reselect),
2253 }/*-------------------------< RESEL_TMP >-------------------*/,{
2255 ** The return address in TEMP
2256 ** is in fact the data structure address,
2257 ** so copy it to the DSA register.
2259 SCR_COPY (4),
2260 RADDR (temp),
2261 RADDR (dsa),
2262 SCR_JUMP,
2263 PADDR (prepare),
2265 }/*-------------------------< RESEL_LUN >-------------------*/,{
2267 ** come back to this point
2268 ** to get an IDENTIFY message
2269 ** Wait for a msg_in phase.
2271 /*<<<*/ SCR_JUMPR ^ IFFALSE (WHEN (SCR_MSG_IN)),
2274 ** message phase
2275 ** It's not a sony, it's a trick:
2276 ** read the data without acknowledging it.
2278 SCR_FROM_REG (sbdl),
2280 /*<<<*/ SCR_JUMPR ^ IFFALSE (MASK (MSG_IDENTIFYFLAG, 0x98)),
2283 ** It WAS an Identify message.
2284 ** get it and ack it!
2286 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2287 NADDR (msgin),
2288 SCR_CLR (SCR_ACK),
2291 ** Mask out the lun.
2293 SCR_REG_REG (sfbr, SCR_AND, 0x07),
2295 SCR_RETURN,
2298 ** No message phase or no IDENTIFY message:
2299 ** return 0.
2301 /*>>>*/ SCR_LOAD_SFBR (0),
2303 SCR_RETURN,
2306 }/*-------------------------< RESEL_TAG >-------------------*/,{
2308 ** come back to this point
2309 ** to get a SIMPLE_TAG message
2310 ** Wait for a MSG_IN phase.
2312 /*<<<*/ SCR_JUMPR ^ IFFALSE (WHEN (SCR_MSG_IN)),
2315 ** message phase
2316 ** It's a trick - read the data
2317 ** without acknowledging it.
2319 SCR_FROM_REG (sbdl),
2321 /*<<<*/ SCR_JUMPR ^ IFFALSE (DATA (MSG_SIMPLE_Q_TAG)),
2324 ** It WAS a SIMPLE_TAG message.
2325 ** get it and ack it!
2327 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2328 NADDR (msgin),
2329 SCR_CLR (SCR_ACK),
2332 ** Wait for the second byte (the tag)
2334 /*<<<*/ SCR_JUMPR ^ IFFALSE (WHEN (SCR_MSG_IN)),
2337 ** Get it and ack it!
2339 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2340 NADDR (msgin),
2341 SCR_CLR (SCR_ACK|SCR_CARRY),
2343 SCR_RETURN,
2346 ** No message phase or no SIMPLE_TAG message
2347 ** or no second byte: return 0.
2349 /*>>>*/ SCR_LOAD_SFBR (0),
2351 SCR_SET (SCR_CARRY),
2353 SCR_RETURN,
2356 }/*-------------------------< DATA_IN >--------------------*/,{
2358 ** Because the size depends on the
2359 ** #define MAX_SCATTER parameter,
2360 ** it is filled in at runtime.
2362 ** SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_IN)),
2363 ** PADDR (no_data),
2364 ** SCR_COPY (sizeof (ticks)),
2365 ** KVAR (KVAR_TICKS),
2366 ** NADDR (header.stamp.data),
2367 ** SCR_MOVE_TBL ^ SCR_DATA_IN,
2368 ** offsetof (struct dsb, data[ 0]),
2370 ** ##===========< i=1; i<MAX_SCATTER >=========
2371 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2372 ** || PADDR (checkatn),
2373 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
2374 ** || offsetof (struct dsb, data[ i]),
2375 ** ##==========================================
2377 ** SCR_CALL,
2378 ** PADDR (checkatn),
2379 ** SCR_JUMP,
2380 ** PADDR (no_data),
2383 }/*-------------------------< DATA_OUT >-------------------*/,{
2385 ** Because the size depends on the
2386 ** #define MAX_SCATTER parameter,
2387 ** it is filled in at runtime.
2389 ** SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2390 ** PADDR (no_data),
2391 ** SCR_COPY (sizeof (ticks)),
2392 ** KVAR (KVAR_TICKS),
2393 ** NADDR (header.stamp.data),
2394 ** SCR_MOVE_TBL ^ SCR_DATA_OUT,
2395 ** offsetof (struct dsb, data[ 0]),
2397 ** ##===========< i=1; i<MAX_SCATTER >=========
2398 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2399 ** || PADDR (dispatch),
2400 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
2401 ** || offsetof (struct dsb, data[ i]),
2402 ** ##==========================================
2404 ** SCR_CALL,
2405 ** PADDR (dispatch),
2406 ** SCR_JUMP,
2407 ** PADDR (no_data),
2409 **---------------------------------------------------------
2411 (u_long)0
2413 }/*--------------------------------------------------------*/
2417 static struct scripth scripth0 = {
2418 /*-------------------------< TRYLOOP >---------------------*/{
2420 ** Load an entry of the start queue into dsa
2421 ** and try to start it by jumping to TRYSEL.
2423 ** Because the size depends on the
2424 ** #define MAX_START parameter, it is filled
2425 ** in at runtime.
2427 **-----------------------------------------------------------
2429 ** ##===========< I=0; i<MAX_START >===========
2430 ** || SCR_COPY (4),
2431 ** || NADDR (squeue[i]),
2432 ** || RADDR (dsa),
2433 ** || SCR_CALL,
2434 ** || PADDR (trysel),
2435 ** ##==========================================
2437 ** SCR_JUMP,
2438 ** PADDRH(tryloop),
2440 **-----------------------------------------------------------
2443 }/*-------------------------< MSG_PARITY >---------------*/,{
2445 ** count it
2447 SCR_REG_REG (PS_REG, SCR_ADD, 0x01),
2450 ** send a "message parity error" message.
2452 SCR_LOAD_REG (scratcha, MSG_PARITY_ERROR),
2454 SCR_JUMP,
2455 PADDR (setmsg),
2456 }/*-------------------------< MSG_MESSAGE_REJECT >---------------*/,{
2458 ** If a negotiation was in progress,
2459 ** negotiation failed.
2461 SCR_FROM_REG (HS_REG),
2463 SCR_INT ^ IFTRUE (DATA (HS_NEGOTIATE)),
2464 SIR_NEGO_FAILED,
2466 ** else make host log this message
2468 SCR_INT ^ IFFALSE (DATA (HS_NEGOTIATE)),
2469 SIR_REJECT_RECEIVED,
2470 SCR_JUMP,
2471 PADDR (clrack),
2473 }/*-------------------------< MSG_IGN_RESIDUE >----------*/,{
2475 ** Terminate cycle
2477 SCR_CLR (SCR_ACK),
2479 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2480 PADDR (dispatch),
2482 ** get residue size.
2484 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2485 NADDR (msgin[1]),
2487 ** Check for message parity error.
2489 SCR_TO_REG (scratcha),
2491 SCR_FROM_REG (socl),
2493 SCR_JUMP ^ IFTRUE (MASK (CATN, CATN)),
2494 PADDRH (msg_parity),
2495 SCR_FROM_REG (scratcha),
2498 ** Size is 0 .. ignore message.
2500 SCR_JUMP ^ IFTRUE (DATA (0)),
2501 PADDR (clrack),
2503 ** Size is not 1 .. have to interrupt.
2505 /*<<<*/ SCR_JUMPR ^ IFFALSE (DATA (1)),
2508 ** Check for residue byte in swide register
2510 SCR_FROM_REG (scntl2),
2512 /*<<<*/ SCR_JUMPR ^ IFFALSE (MASK (WSR, WSR)),
2515 ** There IS data in the swide register.
2516 ** Discard it.
2518 SCR_REG_REG (scntl2, SCR_OR, WSR),
2520 SCR_JUMP,
2521 PADDR (clrack),
2523 ** Load again the size to the sfbr register.
2525 /*>>>*/ SCR_FROM_REG (scratcha),
2527 /*>>>*/ SCR_INT,
2528 SIR_IGN_RESIDUE,
2529 SCR_JUMP,
2530 PADDR (clrack),
2532 }/*-------------------------< MSG_EXTENDED >-------------*/,{
2534 ** Terminate cycle
2536 SCR_CLR (SCR_ACK),
2538 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2539 PADDR (dispatch),
2541 ** get length.
2543 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2544 NADDR (msgin[1]),
2546 ** Check for message parity error.
2548 SCR_TO_REG (scratcha),
2550 SCR_FROM_REG (socl),
2552 SCR_JUMP ^ IFTRUE (MASK (CATN, CATN)),
2553 PADDRH (msg_parity),
2554 SCR_FROM_REG (scratcha),
2558 SCR_JUMP ^ IFTRUE (DATA (3)),
2559 PADDRH (msg_ext_3),
2560 SCR_JUMP ^ IFFALSE (DATA (2)),
2561 PADDR (msg_bad),
2562 }/*-------------------------< MSG_EXT_2 >----------------*/,{
2563 SCR_CLR (SCR_ACK),
2565 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2566 PADDR (dispatch),
2568 ** get extended message code.
2570 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2571 NADDR (msgin[2]),
2573 ** Check for message parity error.
2575 SCR_TO_REG (scratcha),
2577 SCR_FROM_REG (socl),
2579 SCR_JUMP ^ IFTRUE (MASK (CATN, CATN)),
2580 PADDRH (msg_parity),
2581 SCR_FROM_REG (scratcha),
2583 SCR_JUMP ^ IFTRUE (DATA (MSG_EXT_WDTR)),
2584 PADDRH (msg_wdtr),
2586 ** unknown extended message
2588 SCR_JUMP,
2589 PADDR (msg_bad)
2590 }/*-------------------------< MSG_WDTR >-----------------*/,{
2591 SCR_CLR (SCR_ACK),
2593 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2594 PADDR (dispatch),
2596 ** get data bus width
2598 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2599 NADDR (msgin[3]),
2600 SCR_FROM_REG (socl),
2602 SCR_JUMP ^ IFTRUE (MASK (CATN, CATN)),
2603 PADDRH (msg_parity),
2605 ** let the host do the real work.
2607 SCR_INT,
2608 SIR_NEGO_WIDE,
2610 ** let the target fetch our answer.
2612 SCR_SET (SCR_ATN),
2614 SCR_CLR (SCR_ACK),
2617 SCR_INT ^ IFFALSE (WHEN (SCR_MSG_OUT)),
2618 SIR_NEGO_PROTO,
2620 ** Send the MSG_EXT_WDTR
2622 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT,
2623 NADDR (msgout),
2624 SCR_CLR (SCR_ATN),
2626 SCR_COPY (1),
2627 RADDR (sfbr),
2628 NADDR (lastmsg),
2629 SCR_JUMP,
2630 PADDR (msg_out_done),
2632 }/*-------------------------< MSG_EXT_3 >----------------*/,{
2633 SCR_CLR (SCR_ACK),
2635 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2636 PADDR (dispatch),
2638 ** get extended message code.
2640 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2641 NADDR (msgin[2]),
2643 ** Check for message parity error.
2645 SCR_TO_REG (scratcha),
2647 SCR_FROM_REG (socl),
2649 SCR_JUMP ^ IFTRUE (MASK (CATN, CATN)),
2650 PADDRH (msg_parity),
2651 SCR_FROM_REG (scratcha),
2653 SCR_JUMP ^ IFTRUE (DATA (MSG_EXT_SDTR)),
2654 PADDRH (msg_sdtr),
2656 ** unknown extended message
2658 SCR_JUMP,
2659 PADDR (msg_bad)
2661 }/*-------------------------< MSG_SDTR >-----------------*/,{
2662 SCR_CLR (SCR_ACK),
2664 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2665 PADDR (dispatch),
2667 ** get period and offset
2669 SCR_MOVE_ABS (2) ^ SCR_MSG_IN,
2670 NADDR (msgin[3]),
2671 SCR_FROM_REG (socl),
2673 SCR_JUMP ^ IFTRUE (MASK (CATN, CATN)),
2674 PADDRH (msg_parity),
2676 ** let the host do the real work.
2678 SCR_INT,
2679 SIR_NEGO_SYNC,
2681 ** let the target fetch our answer.
2683 SCR_SET (SCR_ATN),
2685 SCR_CLR (SCR_ACK),
2688 SCR_INT ^ IFFALSE (WHEN (SCR_MSG_OUT)),
2689 SIR_NEGO_PROTO,
2691 ** Send the MSG_EXT_SDTR
2693 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT,
2694 NADDR (msgout),
2695 SCR_CLR (SCR_ATN),
2697 SCR_COPY (1),
2698 RADDR (sfbr),
2699 NADDR (lastmsg),
2700 SCR_JUMP,
2701 PADDR (msg_out_done),
2703 }/*-------------------------< MSG_OUT_ABORT >-------------*/,{
2705 ** After ABORT message,
2707 ** expect an immediate disconnect, ...
2709 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
2711 SCR_CLR (SCR_ACK|SCR_ATN),
2713 SCR_WAIT_DISC,
2716 ** ... and set the status to "ABORTED"
2718 SCR_LOAD_REG (HS_REG, HS_ABORTED),
2720 SCR_JUMP,
2721 PADDR (cleanup),
2723 }/*-------------------------< GETCC >-----------------------*/,{
2725 ** The ncr doesn't have an indirect load
2726 ** or store command. So we have to
2727 ** copy part of the control block to a
2728 ** fixed place, where we can modify it.
2730 ** We patch the address part of a COPY command
2731 ** with the address of the dsa register ...
2733 SCR_COPY_F (4),
2734 RADDR (dsa),
2735 PADDRH (getcc1),
2737 ** ... then we do the actual copy.
2739 SCR_COPY (sizeof (struct head)),
2740 }/*-------------------------< GETCC1 >----------------------*/,{
2742 NADDR (header),
2744 ** Initialize the status registers
2746 SCR_COPY (4),
2747 NADDR (header.status),
2748 RADDR (scr0),
2749 }/*-------------------------< GETCC2 >----------------------*/,{
2751 ** Get the condition code from a target.
2753 ** DSA points to a data structure.
2754 ** Set TEMP to the script location
2755 ** that receives the condition code.
2757 ** Because there is no script command
2758 ** to load a longword into a register,
2759 ** we use a CALL command.
2761 /*<<<*/ SCR_CALLR,
2764 ** Get the condition code.
2766 SCR_MOVE_TBL ^ SCR_DATA_IN,
2767 offsetof (struct dsb, sense),
2769 ** No data phase may follow!
2771 SCR_CALL,
2772 PADDR (checkatn),
2773 SCR_JUMP,
2774 PADDR (no_data),
2775 /*>>>*/
2778 ** The CALL jumps to this point.
2779 ** Prepare for a RESTORE_POINTER message.
2780 ** Save the TEMP register into the saved pointer.
2782 SCR_COPY (4),
2783 RADDR (temp),
2784 NADDR (header.savep),
2786 ** Load scratcha, because in case of a selection timeout,
2787 ** the host will expect a new value for startpos in
2788 ** the scratcha register.
2790 SCR_COPY (4),
2791 PADDR (startpos),
2792 RADDR (scratcha),
2793 #ifdef NCR_GETCC_WITHMSG
2795 ** If QUIRK_NOMSG is set, select without ATN.
2796 ** and don't send a message.
2798 SCR_FROM_REG (QU_REG),
2800 SCR_JUMP ^ IFTRUE (MASK (QUIRK_NOMSG, QUIRK_NOMSG)),
2801 PADDRH(getcc3),
2803 ** Then try to connect to the target.
2804 ** If we are reselected, special treatment
2805 ** of the current job is required before
2806 ** accepting the reselection.
2808 SCR_SEL_TBL_ATN ^ offsetof (struct dsb, select),
2809 PADDR(badgetcc),
2811 ** Send the IDENTIFY message.
2812 ** In case of short transfer, remove ATN.
2814 SCR_MOVE_TBL ^ SCR_MSG_OUT,
2815 offsetof (struct dsb, smsg2),
2816 SCR_CLR (SCR_ATN),
2819 ** save the first byte of the message.
2821 SCR_COPY (1),
2822 RADDR (sfbr),
2823 NADDR (lastmsg),
2824 SCR_JUMP,
2825 PADDR (prepare2),
2827 #endif
2828 }/*-------------------------< GETCC3 >----------------------*/,{
2830 ** Try to connect to the target.
2831 ** If we are reselected, special treatment
2832 ** of the current job is required before
2833 ** accepting the reselection.
2835 ** Silly target won't accept a message.
2836 ** Select without ATN.
2838 SCR_SEL_TBL ^ offsetof (struct dsb, select),
2839 PADDR(badgetcc),
2841 ** Force error if selection timeout
2843 SCR_JUMPR ^ IFTRUE (WHEN (SCR_MSG_IN)),
2846 ** don't negotiate.
2848 SCR_JUMP,
2849 PADDR (prepare2),
2850 }/*-------------------------< ABORTTAG >-------------------*/,{
2852 ** Abort a bad reselection.
2853 ** Set the message to ABORT vs. ABORT_TAG
2855 SCR_LOAD_REG (scratcha, MSG_ABORT_TAG),
2857 SCR_JUMPR ^ IFFALSE (CARRYSET),
2859 }/*-------------------------< ABORT >----------------------*/,{
2860 SCR_LOAD_REG (scratcha, MSG_ABORT),
2862 SCR_COPY (1),
2863 RADDR (scratcha),
2864 NADDR (msgout),
2865 SCR_SET (SCR_ATN),
2867 SCR_CLR (SCR_ACK),
2870 ** and send it.
2871 ** we expect an immediate disconnect
2873 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
2875 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
2876 NADDR (msgout),
2877 SCR_COPY (1),
2878 RADDR (sfbr),
2879 NADDR (lastmsg),
2880 SCR_CLR (SCR_ACK|SCR_ATN),
2882 SCR_WAIT_DISC,
2884 SCR_JUMP,
2885 PADDR (start),
2886 }/*-------------------------< SNOOPTEST >-------------------*/,{
2888 ** Read the variable.
2890 SCR_COPY (4),
2891 KVAR (KVAR_NCR_CACHE),
2892 RADDR (scratcha),
2894 ** Write the variable.
2896 SCR_COPY (4),
2897 RADDR (temp),
2898 KVAR (KVAR_NCR_CACHE),
2900 ** Read back the variable.
2902 SCR_COPY (4),
2903 KVAR (KVAR_NCR_CACHE),
2904 RADDR (temp),
2905 }/*-------------------------< SNOOPEND >-------------------*/,{
2907 ** And stop.
2909 SCR_INT,
2911 }/*--------------------------------------------------------*/
2915 /*==========================================================
2918 ** Fill in #define dependent parts of the script
2921 **==========================================================
2924 static void
2925 ncr_script_fill (struct script * scr, struct scripth * scrh)
2927 int i;
2928 ncrcmd *p;
2930 p = scrh->tryloop;
2931 for (i=0; i<MAX_START; i++) {
2932 *p++ =SCR_COPY (4);
2933 *p++ =NADDR (squeue[i]);
2934 *p++ =RADDR (dsa);
2935 *p++ =SCR_CALL;
2936 *p++ =PADDR (trysel);
2938 *p++ =SCR_JUMP;
2939 *p++ =PADDRH(tryloop);
2941 assert ((char *)p == (char *)&scrh->tryloop + sizeof (scrh->tryloop));
2943 p = scr->data_in;
2945 *p++ =SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_IN));
2946 *p++ =PADDR (no_data);
2947 *p++ =SCR_COPY (sizeof (ticks));
2948 *p++ =(ncrcmd) KVAR (KVAR_TICKS);
2949 *p++ =NADDR (header.stamp.data);
2950 *p++ =SCR_MOVE_TBL ^ SCR_DATA_IN;
2951 *p++ =offsetof (struct dsb, data[ 0]);
2953 for (i=1; i<MAX_SCATTER; i++) {
2954 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN));
2955 *p++ =PADDR (checkatn);
2956 *p++ =SCR_MOVE_TBL ^ SCR_DATA_IN;
2957 *p++ =offsetof (struct dsb, data[i]);
2960 *p++ =SCR_CALL;
2961 *p++ =PADDR (checkatn);
2962 *p++ =SCR_JUMP;
2963 *p++ =PADDR (no_data);
2965 assert ((char *)p == (char *)&scr->data_in + sizeof (scr->data_in));
2967 p = scr->data_out;
2969 *p++ =SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_OUT));
2970 *p++ =PADDR (no_data);
2971 *p++ =SCR_COPY (sizeof (ticks));
2972 *p++ =(ncrcmd) KVAR (KVAR_TICKS);
2973 *p++ =NADDR (header.stamp.data);
2974 *p++ =SCR_MOVE_TBL ^ SCR_DATA_OUT;
2975 *p++ =offsetof (struct dsb, data[ 0]);
2977 for (i=1; i<MAX_SCATTER; i++) {
2978 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT));
2979 *p++ =PADDR (dispatch);
2980 *p++ =SCR_MOVE_TBL ^ SCR_DATA_OUT;
2981 *p++ =offsetof (struct dsb, data[i]);
2984 *p++ =SCR_CALL;
2985 *p++ =PADDR (dispatch);
2986 *p++ =SCR_JUMP;
2987 *p++ =PADDR (no_data);
2989 assert ((char *)p == (char *)&scr->data_out + sizeof (scr->data_out));
2992 /*==========================================================
2995 ** Copy and rebind a script.
2998 **==========================================================
3001 static void ncr_script_copy_and_bind (ncb_p np, ncrcmd *src, ncrcmd *dst, int len)
3003 ncrcmd opcode, new, old, tmp1, tmp2;
3004 ncrcmd *start, *end;
3005 int relocs, offset;
3007 start = src;
3008 end = src + len/4;
3009 offset = 0;
3011 while (src < end) {
3013 opcode = *src++;
3014 WRITESCRIPT_OFF(dst, offset, opcode);
3015 offset += 4;
3018 ** If we forget to change the length
3019 ** in struct script, a field will be
3020 ** padded with 0. This is an illegal
3021 ** command.
3024 if (opcode == 0) {
3025 kprintf ("%s: ERROR0 IN SCRIPT at %d.\n",
3026 ncr_name(np), (int) (src-start-1));
3027 DELAY (1000000);
3030 if (DEBUG_FLAGS & DEBUG_SCRIPT)
3031 kprintf ("%p: <%x>\n",
3032 (src-1), (unsigned)opcode);
3035 ** We don't have to decode ALL commands
3037 switch (opcode >> 28) {
3039 case 0xc:
3041 ** COPY has TWO arguments.
3043 relocs = 2;
3044 tmp1 = src[0];
3045 if ((tmp1 & RELOC_MASK) == RELOC_KVAR)
3046 tmp1 = 0;
3047 tmp2 = src[1];
3048 if ((tmp2 & RELOC_MASK) == RELOC_KVAR)
3049 tmp2 = 0;
3050 if ((tmp1 ^ tmp2) & 3) {
3051 kprintf ("%s: ERROR1 IN SCRIPT at %d.\n",
3052 ncr_name(np), (int) (src-start-1));
3053 DELAY (1000000);
3056 ** If PREFETCH feature not enabled, remove
3057 ** the NO FLUSH bit if present.
3059 if ((opcode & SCR_NO_FLUSH) && !(np->features&FE_PFEN))
3060 WRITESCRIPT_OFF(dst, offset - 4,
3061 (opcode & ~SCR_NO_FLUSH));
3062 break;
3064 case 0x0:
3066 ** MOVE (absolute address)
3068 relocs = 1;
3069 break;
3071 case 0x8:
3073 ** JUMP / CALL
3074 ** dont't relocate if relative :-)
3076 if (opcode & 0x00800000)
3077 relocs = 0;
3078 else
3079 relocs = 1;
3080 break;
3082 case 0x4:
3083 case 0x5:
3084 case 0x6:
3085 case 0x7:
3086 relocs = 1;
3087 break;
3089 default:
3090 relocs = 0;
3091 break;
3094 if (relocs) {
3095 while (relocs--) {
3096 old = *src++;
3098 switch (old & RELOC_MASK) {
3099 case RELOC_REGISTER:
3100 new = (old & ~RELOC_MASK) + rman_get_start(np->reg_res);
3101 break;
3102 case RELOC_LABEL:
3103 new = (old & ~RELOC_MASK) + np->p_script;
3104 break;
3105 case RELOC_LABELH:
3106 new = (old & ~RELOC_MASK) + np->p_scripth;
3107 break;
3108 case RELOC_SOFTC:
3109 new = (old & ~RELOC_MASK) + vtophys(np);
3110 break;
3111 case RELOC_KVAR:
3112 if (((old & ~RELOC_MASK) <
3113 SCRIPT_KVAR_FIRST) ||
3114 ((old & ~RELOC_MASK) >
3115 SCRIPT_KVAR_LAST))
3116 panic("ncr KVAR out of range");
3117 new = vtophys(script_kvars[old &
3118 ~RELOC_MASK]);
3119 break;
3120 case 0:
3121 /* Don't relocate a 0 address. */
3122 if (old == 0) {
3123 new = old;
3124 break;
3126 /* fall through */
3127 default:
3128 panic("ncr_script_copy_and_bind: weird relocation %x @ %d", old, (int)(src - start));
3129 break;
3132 WRITESCRIPT_OFF(dst, offset, new);
3133 offset += 4;
3135 } else {
3136 WRITESCRIPT_OFF(dst, offset, *src++);
3137 offset += 4;
3143 /*==========================================================
3146 ** Auto configuration.
3149 **==========================================================
3152 #if 0
3153 /*----------------------------------------------------------
3155 ** Reduce the transfer length to the max value
3156 ** we can transfer safely.
3158 ** Reading a block greater then MAX_SIZE from the
3159 ** raw (character) device exercises a memory leak
3160 ** in the vm subsystem. This is common to ALL devices.
3161 ** We have submitted a description of this bug to
3162 ** <FreeBSD-bugs@freefall.cdrom.com>.
3163 ** It should be fixed in the current release.
3165 **----------------------------------------------------------
3168 void ncr_min_phys (struct buf *bp)
3170 if ((unsigned long)bp->b_bcount > MAX_SIZE) bp->b_bcount = MAX_SIZE;
3173 #endif
3175 #if 0
3176 /*----------------------------------------------------------
3178 ** Maximal number of outstanding requests per target.
3180 **----------------------------------------------------------
3183 u_int32_t ncr_info (int unit)
3185 return (1); /* may be changed later */
3188 #endif
3190 /*----------------------------------------------------------
3192 ** NCR chip devices table and chip look up function.
3193 ** Features bit are defined in ncrreg.h. Is it the
3194 ** right place?
3196 **----------------------------------------------------------
3198 typedef struct {
3199 unsigned long device_id;
3200 unsigned short minrevid;
3201 char *name;
3202 unsigned char maxburst;
3203 unsigned char maxoffs;
3204 unsigned char clock_divn;
3205 unsigned int features;
3206 } ncr_chip;
3208 static ncr_chip ncr_chip_table[] = {
3209 {NCR_810_ID, 0x00, "ncr 53c810 fast10 scsi", 4, 8, 4,
3210 FE_ERL}
3212 {NCR_810_ID, 0x10, "ncr 53c810a fast10 scsi", 4, 8, 4,
3213 FE_ERL|FE_LDSTR|FE_PFEN|FE_BOF}
3215 {NCR_815_ID, 0x00, "ncr 53c815 fast10 scsi", 4, 8, 4,
3216 FE_ERL|FE_BOF}
3218 {NCR_820_ID, 0x00, "ncr 53c820 fast10 wide scsi", 4, 8, 4,
3219 FE_WIDE|FE_ERL}
3221 {NCR_825_ID, 0x00, "ncr 53c825 fast10 wide scsi", 4, 8, 4,
3222 FE_WIDE|FE_ERL|FE_BOF}
3224 {NCR_825_ID, 0x10, "ncr 53c825a fast10 wide scsi", 7, 8, 4,
3225 FE_WIDE|FE_CACHE_SET|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM}
3227 {NCR_860_ID, 0x00, "ncr 53c860 fast20 scsi", 4, 8, 5,
3228 FE_ULTRA|FE_CLK80|FE_CACHE_SET|FE_LDSTR|FE_PFEN}
3230 {NCR_875_ID, 0x00, "ncr 53c875 fast20 wide scsi", 7, 16, 5,
3231 FE_WIDE|FE_ULTRA|FE_CLK80|FE_CACHE_SET|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM}
3233 {NCR_875_ID, 0x02, "ncr 53c875 fast20 wide scsi", 7, 16, 5,
3234 FE_WIDE|FE_ULTRA|FE_DBLR|FE_CACHE_SET|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM}
3236 {NCR_875_ID2, 0x00, "ncr 53c875j fast20 wide scsi", 7, 16, 5,
3237 FE_WIDE|FE_ULTRA|FE_DBLR|FE_CACHE_SET|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM}
3239 {NCR_885_ID, 0x00, "ncr 53c885 fast20 wide scsi", 7, 16, 5,
3240 FE_WIDE|FE_ULTRA|FE_DBLR|FE_CACHE_SET|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM}
3242 {NCR_895_ID, 0x00, "ncr 53c895 fast40 wide scsi", 7, 31, 7,
3243 FE_WIDE|FE_ULTRA2|FE_QUAD|FE_CACHE_SET|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM}
3245 {NCR_896_ID, 0x00, "ncr 53c896 fast40 wide scsi", 7, 31, 7,
3246 FE_WIDE|FE_ULTRA2|FE_QUAD|FE_CACHE_SET|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM}
3248 {NCR_895A_ID, 0x00, "ncr 53c895a fast40 wide scsi", 7, 31, 7,
3249 FE_WIDE|FE_ULTRA2|FE_QUAD|FE_CACHE_SET|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM}
3251 {NCR_1510D_ID, 0x00, "ncr 53c1510d fast40 wide scsi", 7, 31, 7,
3252 FE_WIDE|FE_ULTRA2|FE_QUAD|FE_CACHE_SET|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM}
3255 static int ncr_chip_lookup(u_long device_id, u_char revision_id)
3257 int i, found;
3259 found = -1;
3260 for (i = 0; i < NELEM(ncr_chip_table); i++) {
3261 if (device_id == ncr_chip_table[i].device_id &&
3262 ncr_chip_table[i].minrevid <= revision_id) {
3263 if (found < 0 ||
3264 ncr_chip_table[found].minrevid
3265 < ncr_chip_table[i].minrevid) {
3266 found = i;
3270 return found;
3273 /*----------------------------------------------------------
3275 ** Probe the hostadapter.
3277 **----------------------------------------------------------
3282 static int ncr_probe (device_t dev)
3284 int i;
3286 i = ncr_chip_lookup(pci_get_devid(dev), pci_get_revid(dev));
3287 if (i >= 0) {
3288 device_set_desc(dev, ncr_chip_table[i].name);
3289 return (-1000); /* Allows to use both ncr and sym */
3292 return (ENXIO);
3297 /*==========================================================
3299 ** NCR chip clock divisor table.
3300 ** Divisors are multiplied by 10,000,000 in order to make
3301 ** calculations more simple.
3303 **==========================================================
3306 #define _5M 5000000
3307 static u_long div_10M[] =
3308 {2*_5M, 3*_5M, 4*_5M, 6*_5M, 8*_5M, 12*_5M, 16*_5M};
3310 /*===============================================================
3312 ** NCR chips allow burst lengths of 2, 4, 8, 16, 32, 64, 128
3313 ** transfers. 32,64,128 are only supported by 875 and 895 chips.
3314 ** We use log base 2 (burst length) as internal code, with
3315 ** value 0 meaning "burst disabled".
3317 **===============================================================
3321 * Burst length from burst code.
3323 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
3326 * Burst code from io register bits.
3328 #define burst_code(dmode, ctest4, ctest5) \
3329 (ctest4) & 0x80? 0 : (((dmode) & 0xc0) >> 6) + ((ctest5) & 0x04) + 1
3332 * Set initial io register bits from burst code.
3334 static void
3335 ncr_init_burst(ncb_p np, u_char bc)
3337 np->rv_ctest4 &= ~0x80;
3338 np->rv_dmode &= ~(0x3 << 6);
3339 np->rv_ctest5 &= ~0x4;
3341 if (!bc) {
3342 np->rv_ctest4 |= 0x80;
3344 else {
3345 --bc;
3346 np->rv_dmode |= ((bc & 0x3) << 6);
3347 np->rv_ctest5 |= (bc & 0x4);
3351 /*==========================================================
3354 ** Auto configuration: attach and init a host adapter.
3357 **==========================================================
3361 static int
3362 ncr_attach (device_t dev)
3364 ncb_p np = (struct ncb*) device_get_softc(dev);
3365 u_char rev = 0;
3366 u_long period;
3367 int i, rid;
3368 u_int8_t usrsync;
3369 u_int8_t usrwide;
3370 struct cam_devq *devq;
3373 ** allocate and initialize structures.
3376 np->unit = device_get_unit(dev);
3379 ** Try to map the controller chip to
3380 ** virtual and physical memory.
3383 np->reg_rid = 0x14;
3384 np->reg_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &np->reg_rid,
3385 0, ~0, 1, RF_ACTIVE);
3386 if (!np->reg_res) {
3387 device_printf(dev, "could not map memory\n");
3388 return ENXIO;
3392 ** Make the controller's registers available.
3393 ** Now the INB INW INL OUTB OUTW OUTL macros
3394 ** can be used safely.
3397 np->bst = rman_get_bustag(np->reg_res);
3398 np->bsh = rman_get_bushandle(np->reg_res);
3401 #ifdef NCR_IOMAPPED
3403 ** Try to map the controller chip into iospace.
3406 if (!pci_map_port (config_id, 0x10, &np->port))
3407 return;
3408 #endif
3412 ** Save some controller register default values
3415 np->rv_scntl3 = INB(nc_scntl3) & 0x77;
3416 np->rv_dmode = INB(nc_dmode) & 0xce;
3417 np->rv_dcntl = INB(nc_dcntl) & 0xa9;
3418 np->rv_ctest3 = INB(nc_ctest3) & 0x01;
3419 np->rv_ctest4 = INB(nc_ctest4) & 0x88;
3420 np->rv_ctest5 = INB(nc_ctest5) & 0x24;
3421 np->rv_gpcntl = INB(nc_gpcntl);
3422 np->rv_stest2 = INB(nc_stest2) & 0x20;
3424 if (bootverbose >= 2) {
3425 kprintf ("\tBIOS values: SCNTL3:%02x DMODE:%02x DCNTL:%02x\n",
3426 np->rv_scntl3, np->rv_dmode, np->rv_dcntl);
3427 kprintf ("\t CTEST3:%02x CTEST4:%02x CTEST5:%02x\n",
3428 np->rv_ctest3, np->rv_ctest4, np->rv_ctest5);
3431 np->rv_dcntl |= NOCOM;
3434 ** Do chip dependent initialization.
3437 rev = pci_get_revid(dev);
3440 ** Get chip features from chips table.
3442 i = ncr_chip_lookup(pci_get_devid(dev), rev);
3444 if (i >= 0) {
3445 np->maxburst = ncr_chip_table[i].maxburst;
3446 np->maxoffs = ncr_chip_table[i].maxoffs;
3447 np->clock_divn = ncr_chip_table[i].clock_divn;
3448 np->features = ncr_chip_table[i].features;
3449 } else { /* Should'nt happen if probe() is ok */
3450 np->maxburst = 4;
3451 np->maxoffs = 8;
3452 np->clock_divn = 4;
3453 np->features = FE_ERL;
3456 np->maxwide = np->features & FE_WIDE ? 1 : 0;
3457 np->clock_khz = np->features & FE_CLK80 ? 80000 : 40000;
3458 if (np->features & FE_QUAD) np->multiplier = 4;
3459 else if (np->features & FE_DBLR) np->multiplier = 2;
3460 else np->multiplier = 1;
3463 ** Get the frequency of the chip's clock.
3464 ** Find the right value for scntl3.
3466 if (np->features & (FE_ULTRA|FE_ULTRA2))
3467 ncr_getclock(np, np->multiplier);
3469 #ifdef NCR_TEKRAM_EEPROM
3470 if (bootverbose) {
3471 kprintf ("%s: Tekram EEPROM read %s\n",
3472 ncr_name(np),
3473 read_tekram_eeprom (np, NULL) ?
3474 "succeeded" : "failed");
3476 #endif /* NCR_TEKRAM_EEPROM */
3479 * If scntl3 != 0, we assume BIOS is present.
3481 if (np->rv_scntl3)
3482 np->features |= FE_BIOS;
3485 * Divisor to be used for async (timer pre-scaler).
3487 i = np->clock_divn - 1;
3488 while (i >= 0) {
3489 --i;
3490 if (10ul * SCSI_NCR_MIN_ASYNC * np->clock_khz > div_10M[i]) {
3491 ++i;
3492 break;
3495 np->rv_scntl3 = i+1;
3498 * Minimum synchronous period factor supported by the chip.
3499 * Btw, 'period' is in tenths of nanoseconds.
3502 period = (4 * div_10M[0] + np->clock_khz - 1) / np->clock_khz;
3503 if (period <= 250) np->minsync = 10;
3504 else if (period <= 303) np->minsync = 11;
3505 else if (period <= 500) np->minsync = 12;
3506 else np->minsync = (period + 40 - 1) / 40;
3509 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
3512 if (np->minsync < 25 && !(np->features & (FE_ULTRA|FE_ULTRA2)))
3513 np->minsync = 25;
3514 else if (np->minsync < 12 && !(np->features & FE_ULTRA2))
3515 np->minsync = 12;
3518 * Maximum synchronous period factor supported by the chip.
3521 period = (11 * div_10M[np->clock_divn - 1]) / (4 * np->clock_khz);
3522 np->maxsync = period > 2540 ? 254 : period / 10;
3525 * Now, some features available with Symbios compatible boards.
3526 * LED support through GPIO0 and DIFF support.
3529 #ifdef SCSI_NCR_SYMBIOS_COMPAT
3530 if (!(np->rv_gpcntl & 0x01))
3531 np->features |= FE_LED0;
3532 #if 0 /* Not safe enough without NVRAM support or user settable option */
3533 if (!(INB(nc_gpreg) & 0x08))
3534 np->features |= FE_DIFF;
3535 #endif
3536 #endif /* SCSI_NCR_SYMBIOS_COMPAT */
3539 * Prepare initial IO registers settings.
3540 * Trust BIOS only if we believe we have one and if we want to.
3542 #ifdef SCSI_NCR_TRUST_BIOS
3543 if (!(np->features & FE_BIOS)) {
3544 #else
3545 if (1) {
3546 #endif
3547 np->rv_dmode = 0;
3548 np->rv_dcntl = NOCOM;
3549 np->rv_ctest3 = 0;
3550 np->rv_ctest4 = MPEE;
3551 np->rv_ctest5 = 0;
3552 np->rv_stest2 = 0;
3554 if (np->features & FE_ERL)
3555 np->rv_dmode |= ERL; /* Enable Read Line */
3556 if (np->features & FE_BOF)
3557 np->rv_dmode |= BOF; /* Burst Opcode Fetch */
3558 if (np->features & FE_ERMP)
3559 np->rv_dmode |= ERMP; /* Enable Read Multiple */
3560 if (np->features & FE_CLSE)
3561 np->rv_dcntl |= CLSE; /* Cache Line Size Enable */
3562 if (np->features & FE_WRIE)
3563 np->rv_ctest3 |= WRIE; /* Write and Invalidate */
3564 if (np->features & FE_PFEN)
3565 np->rv_dcntl |= PFEN; /* Prefetch Enable */
3566 if (np->features & FE_DFS)
3567 np->rv_ctest5 |= DFS; /* Dma Fifo Size */
3568 if (np->features & FE_DIFF)
3569 np->rv_stest2 |= 0x20; /* Differential mode */
3570 ncr_init_burst(np, np->maxburst); /* Max dwords burst length */
3571 } else {
3572 np->maxburst =
3573 burst_code(np->rv_dmode, np->rv_ctest4, np->rv_ctest5);
3577 ** Get on-chip SRAM address, if supported
3579 if ((np->features & FE_RAM) && sizeof(struct script) <= 4096) {
3580 np->sram_rid = 0x18;
3581 np->sram_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
3582 &np->sram_rid,
3583 0, ~0, 1, RF_ACTIVE);
3587 ** Allocate structure for script relocation.
3589 if (np->sram_res != NULL) {
3590 np->script = NULL;
3591 np->p_script = rman_get_start(np->sram_res);
3592 np->bst2 = rman_get_bustag(np->sram_res);
3593 np->bsh2 = rman_get_bushandle(np->sram_res);
3594 } else if (sizeof (struct script) > PAGE_SIZE) {
3595 np->script = (struct script*) kmem_alloc_contig
3596 (round_page(sizeof (struct script)),
3597 0, 0xffffffff, PAGE_SIZE);
3598 } else {
3599 np->script = (struct script *)
3600 kmalloc (sizeof (struct script), M_DEVBUF, M_WAITOK);
3603 /* XXX JGibbs - Use contigmalloc */
3604 if (sizeof (struct scripth) > PAGE_SIZE) {
3605 np->scripth = (struct scripth*) kmem_alloc_contig
3606 (round_page(sizeof (struct scripth)),
3607 0, 0xffffffff, PAGE_SIZE);
3608 } else
3610 np->scripth = (struct scripth *)
3611 kmalloc (sizeof (struct scripth), M_DEVBUF, M_WAITOK);
3614 #ifdef SCSI_NCR_PCI_CONFIG_FIXUP
3616 ** If cache line size is enabled, check PCI config space and
3617 ** try to fix it up if necessary.
3619 #ifdef PCIR_CACHELNSZ /* To be sure that new PCI stuff is present */
3621 u_char cachelnsz = pci_read_config(dev, PCIR_CACHELNSZ, 1);
3622 u_short command = pci_read_config(dev, PCIR_COMMAND, 2);
3624 if (!cachelnsz) {
3625 cachelnsz = 8;
3626 kprintf("%s: setting PCI cache line size register to %d.\n",
3627 ncr_name(np), (int)cachelnsz);
3628 pci_write_config(dev, PCIR_CACHELNSZ, cachelnsz, 1);
3631 if (!(command & (1<<4))) {
3632 command |= (1<<4);
3633 kprintf("%s: setting PCI command write and invalidate.\n",
3634 ncr_name(np));
3635 pci_write_config(dev, PCIR_COMMAND, command, 2);
3638 #endif /* PCIR_CACHELNSZ */
3640 #endif /* SCSI_NCR_PCI_CONFIG_FIXUP */
3642 /* Initialize per-target user settings */
3643 usrsync = 0;
3644 if (SCSI_NCR_DFLT_SYNC) {
3645 usrsync = SCSI_NCR_DFLT_SYNC;
3646 if (usrsync > np->maxsync)
3647 usrsync = np->maxsync;
3648 if (usrsync < np->minsync)
3649 usrsync = np->minsync;
3652 usrwide = (SCSI_NCR_MAX_WIDE);
3653 if (usrwide > np->maxwide) usrwide=np->maxwide;
3655 for (i=0;i<MAX_TARGET;i++) {
3656 tcb_p tp = &np->target[i];
3658 tp->tinfo.user.period = usrsync;
3659 tp->tinfo.user.offset = usrsync != 0 ? np->maxoffs : 0;
3660 tp->tinfo.user.width = usrwide;
3661 tp->tinfo.disc_tag = NCR_CUR_DISCENB
3662 | NCR_CUR_TAGENB
3663 | NCR_USR_DISCENB
3664 | NCR_USR_TAGENB;
3668 ** Bells and whistles ;-)
3670 if (bootverbose)
3671 kprintf("%s: minsync=%d, maxsync=%d, maxoffs=%d, %d dwords burst, %s dma fifo\n",
3672 ncr_name(np), np->minsync, np->maxsync, np->maxoffs,
3673 burst_length(np->maxburst),
3674 (np->rv_ctest5 & DFS) ? "large" : "normal");
3677 ** Print some complementary information that can be helpfull.
3679 if (bootverbose)
3680 kprintf("%s: %s, %s IRQ driver%s\n",
3681 ncr_name(np),
3682 np->rv_stest2 & 0x20 ? "differential" : "single-ended",
3683 np->rv_dcntl & IRQM ? "totem pole" : "open drain",
3684 np->sram_res ? ", using on-chip SRAM" : "");
3687 ** Patch scripts to physical addresses
3689 ncr_script_fill (&script0, &scripth0);
3691 if (np->script)
3692 np->p_script = vtophys(np->script);
3693 np->p_scripth = vtophys(np->scripth);
3695 ncr_script_copy_and_bind (np, (ncrcmd *) &script0,
3696 (ncrcmd *) np->script, sizeof(struct script));
3698 ncr_script_copy_and_bind (np, (ncrcmd *) &scripth0,
3699 (ncrcmd *) np->scripth, sizeof(struct scripth));
3702 ** Patch the script for LED support.
3705 if (np->features & FE_LED0) {
3706 WRITESCRIPT(reselect[0], SCR_REG_REG(gpreg, SCR_OR, 0x01));
3707 WRITESCRIPT(reselect1[0], SCR_REG_REG(gpreg, SCR_AND, 0xfe));
3708 WRITESCRIPT(reselect2[0], SCR_REG_REG(gpreg, SCR_AND, 0xfe));
3712 ** init data structure
3715 np->jump_tcb.l_cmd = SCR_JUMP;
3716 np->jump_tcb.l_paddr = NCB_SCRIPTH_PHYS (np, abort);
3719 ** Get SCSI addr of host adapter (set by bios?).
3722 np->myaddr = INB(nc_scid) & 0x07;
3723 if (!np->myaddr) np->myaddr = SCSI_NCR_MYADDR;
3725 #ifdef NCR_DUMP_REG
3727 ** Log the initial register contents
3730 int reg;
3731 for (reg=0; reg<256; reg+=4) {
3732 if (reg%16==0) kprintf ("reg[%2x]", reg);
3733 kprintf (" %08x", (int)pci_conf_read (config_id, reg));
3734 if (reg%16==12) kprintf ("\n");
3737 #endif /* NCR_DUMP_REG */
3740 ** Reset chip.
3743 OUTB (nc_istat, SRST);
3744 DELAY (1000);
3745 OUTB (nc_istat, 0 );
3749 ** Now check the cache handling of the pci chipset.
3752 if (ncr_snooptest (np)) {
3753 kprintf ("CACHE INCORRECTLY CONFIGURED.\n");
3754 return EINVAL;
3758 ** Install the interrupt handler.
3761 rid = 0;
3762 np->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
3763 RF_SHAREABLE | RF_ACTIVE);
3764 if (np->irq_res == NULL) {
3765 device_printf(dev,
3766 "interruptless mode: reduced performance.\n");
3767 } else {
3768 bus_setup_intr(dev, np->irq_res, 0,
3769 ncr_intr, np, &np->irq_handle, NULL);
3773 ** Create the device queue. We only allow MAX_START-1 concurrent
3774 ** transactions so we can be sure to have one element free in our
3775 ** start queue to reset to the idle loop.
3777 devq = cam_simq_alloc(MAX_START - 1);
3778 if (devq == NULL)
3779 return ENOMEM;
3782 ** Now tell the generic SCSI layer
3783 ** about our bus.
3785 np->sim = cam_sim_alloc(ncr_action, ncr_poll, "ncr", np, np->unit,
3786 &sim_mplock, 1, MAX_TAGS, devq);
3787 cam_simq_release(devq);
3788 if (np->sim == NULL)
3789 return ENOMEM;
3792 if (xpt_bus_register(np->sim, 0) != CAM_SUCCESS) {
3793 cam_sim_free(np->sim);
3794 return ENOMEM;
3797 if (xpt_create_path(&np->path, /*periph*/NULL,
3798 cam_sim_path(np->sim), CAM_TARGET_WILDCARD,
3799 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
3800 xpt_bus_deregister(cam_sim_path(np->sim));
3801 cam_sim_free(np->sim);
3802 return ENOMEM;
3806 ** start the timeout daemon
3808 callout_init(&np->timeout_ch);
3809 ncr_timeout (np);
3810 np->lasttime=0;
3812 return 0;
3815 /*==========================================================
3818 ** Process pending device interrupts.
3821 **==========================================================
3824 static void
3825 ncr_intr(void *vnp)
3827 ncb_p np = vnp;
3828 crit_enter();
3830 if (DEBUG_FLAGS & DEBUG_TINY) kprintf ("[");
3832 if (INB(nc_istat) & (INTF|SIP|DIP)) {
3834 ** Repeat until no outstanding ints
3836 do {
3837 ncr_exception (np);
3838 } while (INB(nc_istat) & (INTF|SIP|DIP));
3840 np->ticks = 100;
3843 if (DEBUG_FLAGS & DEBUG_TINY) kprintf ("]\n");
3845 crit_exit();
3848 /*==========================================================
3851 ** Start execution of a SCSI command.
3852 ** This is called from the generic SCSI driver.
3855 **==========================================================
3858 static void
3859 ncr_action (struct cam_sim *sim, union ccb *ccb)
3861 ncb_p np;
3863 np = (ncb_p) cam_sim_softc(sim);
3865 switch (ccb->ccb_h.func_code) {
3866 /* Common cases first */
3867 case XPT_SCSI_IO: /* Execute the requested I/O operation */
3869 nccb_p cp;
3870 lcb_p lp;
3871 tcb_p tp;
3872 struct ccb_scsiio *csio;
3873 u_int8_t *msgptr;
3874 u_int msglen;
3875 u_int msglen2;
3876 int segments;
3877 u_int8_t nego;
3878 u_int8_t idmsg;
3879 int qidx;
3881 tp = &np->target[ccb->ccb_h.target_id];
3882 csio = &ccb->csio;
3884 crit_enter();
3887 * Last time we need to check if this CCB needs to
3888 * be aborted.
3890 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) {
3891 xpt_done(ccb);
3892 crit_exit();
3893 return;
3895 ccb->ccb_h.status |= CAM_SIM_QUEUED;
3897 /*---------------------------------------------------
3899 ** Assign an nccb / bind ccb
3901 **----------------------------------------------------
3903 cp = ncr_get_nccb (np, ccb->ccb_h.target_id,
3904 ccb->ccb_h.target_lun);
3905 if (cp == NULL) {
3906 /* XXX JGibbs - Freeze SIMQ */
3907 ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
3908 xpt_done(ccb);
3909 crit_exit();
3910 return;
3913 cp->ccb = ccb;
3915 /*---------------------------------------------------
3917 ** timestamp
3919 **----------------------------------------------------
3922 ** XXX JGibbs - Isn't this expensive
3923 ** enough to be conditionalized??
3926 bzero (&cp->phys.header.stamp, sizeof (struct tstamp));
3927 cp->phys.header.stamp.start = ticks;
3929 nego = 0;
3930 if (tp->nego_cp == NULL) {
3932 if (tp->tinfo.current.width
3933 != tp->tinfo.goal.width) {
3934 tp->nego_cp = cp;
3935 nego = NS_WIDE;
3936 } else if ((tp->tinfo.current.period
3937 != tp->tinfo.goal.period)
3938 || (tp->tinfo.current.offset
3939 != tp->tinfo.goal.offset)) {
3940 tp->nego_cp = cp;
3941 nego = NS_SYNC;
3945 /*---------------------------------------------------
3947 ** choose a new tag ...
3949 **----------------------------------------------------
3951 lp = tp->lp[ccb->ccb_h.target_lun];
3953 if ((ccb->ccb_h.flags & CAM_TAG_ACTION_VALID) != 0
3954 && (ccb->csio.tag_action != CAM_TAG_ACTION_NONE)
3955 && (nego == 0)) {
3957 ** assign a tag to this nccb
3959 while (!cp->tag) {
3960 nccb_p cp2 = lp->next_nccb;
3961 lp->lasttag = lp->lasttag % 255 + 1;
3962 while (cp2 && cp2->tag != lp->lasttag)
3963 cp2 = cp2->next_nccb;
3964 if (cp2) continue;
3965 cp->tag=lp->lasttag;
3966 if (DEBUG_FLAGS & DEBUG_TAGS) {
3967 PRINT_ADDR(ccb);
3968 kprintf ("using tag #%d.\n", cp->tag);
3971 } else {
3972 cp->tag=0;
3975 /*----------------------------------------------------
3977 ** Build the identify / tag / sdtr message
3979 **----------------------------------------------------
3981 idmsg = MSG_IDENTIFYFLAG | ccb->ccb_h.target_lun;
3982 if (tp->tinfo.disc_tag & NCR_CUR_DISCENB)
3983 idmsg |= MSG_IDENTIFY_DISCFLAG;
3985 msgptr = cp->scsi_smsg;
3986 msglen = 0;
3987 msgptr[msglen++] = idmsg;
3989 if (cp->tag) {
3990 msgptr[msglen++] = ccb->csio.tag_action;
3991 msgptr[msglen++] = cp->tag;
3994 switch (nego) {
3995 case NS_SYNC:
3996 msgptr[msglen++] = MSG_EXTENDED;
3997 msgptr[msglen++] = MSG_EXT_SDTR_LEN;
3998 msgptr[msglen++] = MSG_EXT_SDTR;
3999 msgptr[msglen++] = tp->tinfo.goal.period;
4000 msgptr[msglen++] = tp->tinfo.goal.offset;
4001 if (DEBUG_FLAGS & DEBUG_NEGO) {
4002 PRINT_ADDR(ccb);
4003 kprintf ("sync msgout: ");
4004 ncr_show_msg (&cp->scsi_smsg [msglen-5]);
4005 kprintf (".\n");
4007 break;
4008 case NS_WIDE:
4009 msgptr[msglen++] = MSG_EXTENDED;
4010 msgptr[msglen++] = MSG_EXT_WDTR_LEN;
4011 msgptr[msglen++] = MSG_EXT_WDTR;
4012 msgptr[msglen++] = tp->tinfo.goal.width;
4013 if (DEBUG_FLAGS & DEBUG_NEGO) {
4014 PRINT_ADDR(ccb);
4015 kprintf ("wide msgout: ");
4016 ncr_show_msg (&cp->scsi_smsg [msglen-4]);
4017 kprintf (".\n");
4019 break;
4022 /*----------------------------------------------------
4024 ** Build the identify message for getcc.
4026 **----------------------------------------------------
4029 cp->scsi_smsg2 [0] = idmsg;
4030 msglen2 = 1;
4032 /*----------------------------------------------------
4034 ** Build the data descriptors
4036 **----------------------------------------------------
4039 /* XXX JGibbs - Handle other types of I/O */
4040 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
4041 segments = ncr_scatter(&cp->phys,
4042 (vm_offset_t)csio->data_ptr,
4043 (vm_size_t)csio->dxfer_len);
4045 if (segments < 0) {
4046 ccb->ccb_h.status = CAM_REQ_TOO_BIG;
4047 ncr_free_nccb(np, cp);
4048 crit_exit();
4049 xpt_done(ccb);
4050 return;
4052 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
4053 cp->phys.header.savep = NCB_SCRIPT_PHYS (np, data_in);
4054 cp->phys.header.goalp = cp->phys.header.savep +20 +segments*16;
4055 } else { /* CAM_DIR_OUT */
4056 cp->phys.header.savep = NCB_SCRIPT_PHYS (np, data_out);
4057 cp->phys.header.goalp = cp->phys.header.savep +20 +segments*16;
4059 } else {
4060 cp->phys.header.savep = NCB_SCRIPT_PHYS (np, no_data);
4061 cp->phys.header.goalp = cp->phys.header.savep;
4064 cp->phys.header.lastp = cp->phys.header.savep;
4067 /*----------------------------------------------------
4069 ** fill in nccb
4071 **----------------------------------------------------
4074 ** physical -> virtual backlink
4075 ** Generic SCSI command
4077 cp->phys.header.cp = cp;
4079 ** Startqueue
4081 cp->phys.header.launch.l_paddr = NCB_SCRIPT_PHYS (np, select);
4082 cp->phys.header.launch.l_cmd = SCR_JUMP;
4084 ** select
4086 cp->phys.select.sel_id = ccb->ccb_h.target_id;
4087 cp->phys.select.sel_scntl3 = tp->tinfo.wval;
4088 cp->phys.select.sel_sxfer = tp->tinfo.sval;
4090 ** message
4092 cp->phys.smsg.addr = CCB_PHYS (cp, scsi_smsg);
4093 cp->phys.smsg.size = msglen;
4095 cp->phys.smsg2.addr = CCB_PHYS (cp, scsi_smsg2);
4096 cp->phys.smsg2.size = msglen2;
4098 ** command
4100 /* XXX JGibbs - Support other command types */
4101 cp->phys.cmd.addr = vtophys (csio->cdb_io.cdb_bytes);
4102 cp->phys.cmd.size = csio->cdb_len;
4104 ** sense command
4106 cp->phys.scmd.addr = CCB_PHYS (cp, sensecmd);
4107 cp->phys.scmd.size = 6;
4109 ** patch requested size into sense command
4111 cp->sensecmd[0] = 0x03;
4112 cp->sensecmd[1] = ccb->ccb_h.target_lun << 5;
4113 cp->sensecmd[4] = sizeof(struct scsi_sense_data);
4114 cp->sensecmd[4] = csio->sense_len;
4116 ** sense data
4118 cp->phys.sense.addr = vtophys (&csio->sense_data);
4119 cp->phys.sense.size = csio->sense_len;
4121 ** status
4123 cp->actualquirks = QUIRK_NOMSG;
4124 cp->host_status = nego ? HS_NEGOTIATE : HS_BUSY;
4125 cp->s_status = SCSI_STATUS_ILLEGAL;
4126 cp->parity_status = 0;
4128 cp->xerr_status = XE_OK;
4129 cp->sync_status = tp->tinfo.sval;
4130 cp->nego_status = nego;
4131 cp->wide_status = tp->tinfo.wval;
4133 /*----------------------------------------------------
4135 ** Critical region: start this job.
4137 **----------------------------------------------------
4141 ** reselect pattern and activate this job.
4144 cp->jump_nccb.l_cmd = (SCR_JUMP ^ IFFALSE (DATA (cp->tag)));
4145 cp->tlimit = time_uptime
4146 + ccb->ccb_h.timeout / 1000 + 2;
4147 cp->magic = CCB_MAGIC;
4150 ** insert into start queue.
4153 qidx = np->squeueput + 1;
4154 if (qidx >= MAX_START)
4155 qidx = 0;
4156 np->squeue [qidx ] = NCB_SCRIPT_PHYS (np, idle);
4157 np->squeue [np->squeueput] = CCB_PHYS (cp, phys);
4158 np->squeueput = qidx;
4160 if(DEBUG_FLAGS & DEBUG_QUEUE)
4161 kprintf("%s: queuepos=%d tryoffset=%d.\n",
4162 ncr_name (np), np->squeueput,
4163 (unsigned)(READSCRIPT(startpos[0]) -
4164 (NCB_SCRIPTH_PHYS (np, tryloop))));
4167 ** Script processor may be waiting for reselect.
4168 ** Wake it up.
4170 OUTB (nc_istat, SIGP);
4173 ** and reenable interrupts
4175 crit_exit();
4176 break;
4178 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
4179 case XPT_EN_LUN: /* Enable LUN as a target */
4180 case XPT_TARGET_IO: /* Execute target I/O request */
4181 case XPT_ACCEPT_TARGET_IO: /* Accept Host Target Mode CDB */
4182 case XPT_CONT_TARGET_IO: /* Continue Host Target I/O Connection*/
4183 case XPT_ABORT: /* Abort the specified CCB */
4184 /* XXX Implement */
4185 ccb->ccb_h.status = CAM_REQ_INVALID;
4186 xpt_done(ccb);
4187 break;
4188 case XPT_SET_TRAN_SETTINGS:
4190 struct ccb_trans_settings *cts = &ccb->cts;
4191 tcb_p tp;
4192 u_int update_type;
4193 struct ccb_trans_settings_scsi *scsi =
4194 &cts->proto_specific.scsi;
4195 struct ccb_trans_settings_spi *spi =
4196 &cts->xport_specific.spi;
4198 update_type = 0;
4199 if (cts->type == CTS_TYPE_CURRENT_SETTINGS)
4200 update_type |= NCR_TRANS_GOAL;
4201 if (cts->type == CTS_TYPE_USER_SETTINGS)
4202 update_type |= NCR_TRANS_USER;
4204 crit_enter();
4205 tp = &np->target[ccb->ccb_h.target_id];
4206 /* Tag and disc enables */
4207 if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
4208 if (update_type & NCR_TRANS_GOAL) {
4209 if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0)
4210 tp->tinfo.disc_tag |= NCR_CUR_DISCENB;
4211 else
4212 tp->tinfo.disc_tag &= ~NCR_CUR_DISCENB;
4215 if (update_type & NCR_TRANS_USER) {
4216 if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0)
4217 tp->tinfo.disc_tag |= NCR_USR_DISCENB;
4218 else
4219 tp->tinfo.disc_tag &= ~NCR_USR_DISCENB;
4224 if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
4225 if (update_type & NCR_TRANS_GOAL) {
4226 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0)
4227 tp->tinfo.disc_tag |= NCR_CUR_TAGENB;
4228 else
4229 tp->tinfo.disc_tag &= ~NCR_CUR_TAGENB;
4232 if (update_type & NCR_TRANS_USER) {
4233 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0)
4234 tp->tinfo.disc_tag |= NCR_USR_TAGENB;
4235 else
4236 tp->tinfo.disc_tag &= ~NCR_USR_TAGENB;
4240 /* Filter bus width and sync negotiation settings */
4241 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) {
4242 if (spi->bus_width > np->maxwide)
4243 spi->bus_width = np->maxwide;
4246 if (((spi->valid & CTS_SPI_VALID_SYNC_RATE) != 0)
4247 || ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0)) {
4248 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) != 0) {
4249 if (spi->sync_period != 0
4250 && (spi->sync_period < np->minsync))
4251 spi->sync_period = np->minsync;
4253 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0) {
4254 if (spi->sync_offset == 0)
4255 spi->sync_period = 0;
4256 if (spi->sync_offset > np->maxoffs)
4257 spi->sync_offset = np->maxoffs;
4260 if ((update_type & NCR_TRANS_USER) != 0) {
4261 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) != 0)
4262 tp->tinfo.user.period = spi->sync_period;
4263 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0)
4264 tp->tinfo.user.offset = spi->sync_offset;
4265 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
4266 tp->tinfo.user.width = spi->bus_width;
4268 if ((update_type & NCR_TRANS_GOAL) != 0) {
4269 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) != 0)
4270 tp->tinfo.goal.period = spi->sync_period;
4272 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0)
4273 tp->tinfo.goal.offset = spi->sync_offset;
4275 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
4276 tp->tinfo.goal.width = spi->bus_width;
4278 crit_exit();
4279 ccb->ccb_h.status = CAM_REQ_CMP;
4280 xpt_done(ccb);
4281 break;
4283 case XPT_GET_TRAN_SETTINGS:
4284 /* Get default/user set transfer settings for the target */
4286 struct ccb_trans_settings *cts = &ccb->cts;
4287 struct ncr_transinfo *tinfo;
4288 tcb_p tp = &np->target[ccb->ccb_h.target_id];
4289 struct ccb_trans_settings_scsi *scsi =
4290 &cts->proto_specific.scsi;
4291 struct ccb_trans_settings_spi *spi =
4292 &cts->xport_specific.spi;
4294 cts->protocol = PROTO_SCSI;
4295 cts->protocol_version = SCSI_REV_2;
4296 cts->transport = XPORT_SPI;
4297 cts->transport_version = 2;
4299 crit_enter();
4300 if (cts->type == CTS_TYPE_CURRENT_SETTINGS) {
4301 tinfo = &tp->tinfo.current;
4302 if (tp->tinfo.disc_tag & NCR_CUR_DISCENB)
4303 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
4304 else
4305 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
4307 if (tp->tinfo.disc_tag & NCR_CUR_TAGENB)
4308 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
4309 else
4310 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
4311 } else {
4312 tinfo = &tp->tinfo.user;
4313 if (tp->tinfo.disc_tag & NCR_USR_DISCENB)
4314 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
4315 else
4316 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
4318 if (tp->tinfo.disc_tag & NCR_USR_TAGENB)
4319 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
4320 else
4321 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
4324 spi->sync_period = tinfo->period;
4325 spi->sync_offset = tinfo->offset;
4326 spi->bus_width = tinfo->width;
4328 crit_exit();
4329 spi->valid = CTS_SPI_VALID_SYNC_RATE
4330 | CTS_SPI_VALID_SYNC_OFFSET
4331 | CTS_SPI_VALID_BUS_WIDTH
4332 | CTS_SPI_VALID_DISC;
4333 scsi->valid = CTS_SCSI_VALID_TQ;
4335 ccb->ccb_h.status = CAM_REQ_CMP;
4336 xpt_done(ccb);
4337 break;
4339 case XPT_CALC_GEOMETRY:
4341 struct ccb_calc_geometry *ccg;
4342 u_int32_t size_mb;
4343 u_int32_t secs_per_cylinder;
4344 int extended;
4346 /* XXX JGibbs - I'm sure the NCR uses a different strategy,
4347 * but it should be able to deal with Adaptec
4348 * geometry too.
4350 extended = 1;
4351 ccg = &ccb->ccg;
4352 size_mb = ccg->volume_size
4353 / ((1024L * 1024L) / ccg->block_size);
4355 if (size_mb > 1024 && extended) {
4356 ccg->heads = 255;
4357 ccg->secs_per_track = 63;
4358 } else {
4359 ccg->heads = 64;
4360 ccg->secs_per_track = 32;
4362 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
4363 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
4364 ccb->ccb_h.status = CAM_REQ_CMP;
4365 xpt_done(ccb);
4366 break;
4368 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
4370 OUTB (nc_scntl1, CRST);
4371 ccb->ccb_h.status = CAM_REQ_CMP;
4372 DELAY(10000); /* Wait until our interrupt handler sees it */
4373 xpt_done(ccb);
4374 break;
4376 case XPT_TERM_IO: /* Terminate the I/O process */
4377 /* XXX Implement */
4378 ccb->ccb_h.status = CAM_REQ_INVALID;
4379 xpt_done(ccb);
4380 break;
4381 case XPT_PATH_INQ: /* Path routing inquiry */
4383 struct ccb_pathinq *cpi = &ccb->cpi;
4385 cpi->version_num = 1; /* XXX??? */
4386 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE;
4387 if ((np->features & FE_WIDE) != 0)
4388 cpi->hba_inquiry |= PI_WIDE_16;
4389 cpi->target_sprt = 0;
4390 cpi->hba_misc = 0;
4391 cpi->hba_eng_cnt = 0;
4392 cpi->max_target = (np->features & FE_WIDE) ? 15 : 7;
4393 cpi->max_lun = MAX_LUN - 1;
4394 cpi->initiator_id = np->myaddr;
4395 cpi->bus_id = cam_sim_bus(sim);
4396 cpi->base_transfer_speed = 3300;
4397 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
4398 strncpy(cpi->hba_vid, "Symbios", HBA_IDLEN);
4399 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
4400 cpi->unit_number = cam_sim_unit(sim);
4401 cpi->transport = XPORT_SPI;
4402 cpi->transport_version = 2;
4403 cpi->protocol = PROTO_SCSI;
4404 cpi->protocol_version = SCSI_REV_2;
4405 cpi->ccb_h.status = CAM_REQ_CMP;
4406 xpt_done(ccb);
4407 break;
4409 default:
4410 ccb->ccb_h.status = CAM_REQ_INVALID;
4411 xpt_done(ccb);
4412 break;
4416 /*==========================================================
4419 ** Complete execution of a SCSI command.
4420 ** Signal completion to the generic SCSI driver.
4423 **==========================================================
4426 static void
4427 ncr_complete (ncb_p np, nccb_p cp)
4429 union ccb *ccb;
4430 tcb_p tp;
4433 ** Sanity check
4436 if (!cp || (cp->magic!=CCB_MAGIC) || !cp->ccb) return;
4437 cp->magic = 1;
4438 cp->tlimit= 0;
4441 ** No Reselect anymore.
4443 cp->jump_nccb.l_cmd = (SCR_JUMP);
4446 ** No starting.
4448 cp->phys.header.launch.l_paddr= NCB_SCRIPT_PHYS (np, idle);
4451 ** timestamp
4453 ncb_profile (np, cp);
4455 if (DEBUG_FLAGS & DEBUG_TINY)
4456 kprintf ("CCB=%x STAT=%x/%x\n", (int)(intptr_t)cp & 0xfff,
4457 cp->host_status,cp->s_status);
4459 ccb = cp->ccb;
4460 cp->ccb = NULL;
4461 tp = &np->target[ccb->ccb_h.target_id];
4464 ** We do not queue more than 1 nccb per target
4465 ** with negotiation at any time. If this nccb was
4466 ** used for negotiation, clear this info in the tcb.
4469 if (cp == tp->nego_cp)
4470 tp->nego_cp = NULL;
4473 ** Check for parity errors.
4475 /* XXX JGibbs - What about reporting them??? */
4477 if (cp->parity_status) {
4478 PRINT_ADDR(ccb);
4479 kprintf ("%d parity error(s), fallback.\n", cp->parity_status);
4481 ** fallback to asynch transfer.
4483 tp->tinfo.goal.period = 0;
4484 tp->tinfo.goal.offset = 0;
4488 ** Check for extended errors.
4491 if (cp->xerr_status != XE_OK) {
4492 PRINT_ADDR(ccb);
4493 switch (cp->xerr_status) {
4494 case XE_EXTRA_DATA:
4495 kprintf ("extraneous data discarded.\n");
4496 break;
4497 case XE_BAD_PHASE:
4498 kprintf ("illegal scsi phase (4/5).\n");
4499 break;
4500 default:
4501 kprintf ("extended error %d.\n", cp->xerr_status);
4502 break;
4504 if (cp->host_status==HS_COMPLETE)
4505 cp->host_status = HS_FAIL;
4509 ** Check the status.
4511 if (cp->host_status == HS_COMPLETE) {
4513 if (cp->s_status == SCSI_STATUS_OK) {
4516 ** All went well.
4518 /* XXX JGibbs - Properly calculate residual */
4520 tp->bytes += ccb->csio.dxfer_len;
4521 tp->transfers ++;
4523 ccb->ccb_h.status = CAM_REQ_CMP;
4524 } else if ((cp->s_status & SCSI_STATUS_SENSE) != 0) {
4527 * XXX Could be TERMIO too. Should record
4528 * original status.
4530 ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
4531 cp->s_status &= ~SCSI_STATUS_SENSE;
4532 if (cp->s_status == SCSI_STATUS_OK) {
4533 ccb->ccb_h.status =
4534 CAM_AUTOSNS_VALID|CAM_SCSI_STATUS_ERROR;
4535 } else {
4536 ccb->ccb_h.status = CAM_AUTOSENSE_FAIL;
4538 } else {
4539 ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR;
4540 ccb->csio.scsi_status = cp->s_status;
4544 } else if (cp->host_status == HS_SEL_TIMEOUT) {
4547 ** Device failed selection
4549 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
4551 } else if (cp->host_status == HS_TIMEOUT) {
4554 ** No response
4556 ccb->ccb_h.status = CAM_CMD_TIMEOUT;
4557 } else if (cp->host_status == HS_STALL) {
4558 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4559 } else {
4562 ** Other protocol messes
4564 PRINT_ADDR(ccb);
4565 kprintf ("COMMAND FAILED (%x %x) @%p.\n",
4566 cp->host_status, cp->s_status, cp);
4568 ccb->ccb_h.status = CAM_CMD_TIMEOUT;
4571 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4572 xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
4573 ccb->ccb_h.status |= CAM_DEV_QFRZN;
4577 ** Free this nccb
4579 ncr_free_nccb (np, cp);
4582 ** signal completion to generic driver.
4584 xpt_done (ccb);
4587 /*==========================================================
4590 ** Signal all (or one) control block done.
4593 **==========================================================
4596 static void
4597 ncr_wakeup (ncb_p np, u_long code)
4600 ** Starting at the default nccb and following
4601 ** the links, complete all jobs with a
4602 ** host_status greater than "disconnect".
4604 ** If the "code" parameter is not zero,
4605 ** complete all jobs that are not IDLE.
4608 nccb_p cp = np->link_nccb;
4609 while (cp) {
4610 switch (cp->host_status) {
4612 case HS_IDLE:
4613 break;
4615 case HS_DISCONNECT:
4616 if(DEBUG_FLAGS & DEBUG_TINY) kprintf ("D");
4617 /* fall through */
4619 case HS_BUSY:
4620 case HS_NEGOTIATE:
4621 if (!code) break;
4622 cp->host_status = code;
4624 /* fall through */
4626 default:
4627 ncr_complete (np, cp);
4628 break;
4630 cp = cp -> link_nccb;
4634 static void
4635 ncr_freeze_devq (ncb_p np, struct cam_path *path)
4637 nccb_p cp;
4638 int i;
4639 int count;
4640 int firstskip;
4642 ** Starting at the first nccb and following
4643 ** the links, complete all jobs that match
4644 ** the passed in path and are in the start queue.
4647 cp = np->link_nccb;
4648 count = 0;
4649 firstskip = 0;
4650 while (cp) {
4651 switch (cp->host_status) {
4653 case HS_BUSY:
4654 case HS_NEGOTIATE:
4655 if ((cp->phys.header.launch.l_paddr
4656 == NCB_SCRIPT_PHYS (np, select))
4657 && (xpt_path_comp(path, cp->ccb->ccb_h.path) >= 0)) {
4659 /* Mark for removal from the start queue */
4660 for (i = 1; i < MAX_START; i++) {
4661 int idx;
4663 idx = np->squeueput - i;
4665 if (idx < 0)
4666 idx = MAX_START + idx;
4667 if (np->squeue[idx]
4668 == CCB_PHYS(cp, phys)) {
4669 np->squeue[idx] =
4670 NCB_SCRIPT_PHYS (np, skip);
4671 if (i > firstskip)
4672 firstskip = i;
4673 break;
4676 cp->host_status=HS_STALL;
4677 ncr_complete (np, cp);
4678 count++;
4680 break;
4681 default:
4682 break;
4684 cp = cp->link_nccb;
4687 if (count > 0) {
4688 int j;
4689 int bidx;
4691 /* Compress the start queue */
4692 j = 0;
4693 bidx = np->squeueput;
4694 i = np->squeueput - firstskip;
4695 if (i < 0)
4696 i = MAX_START + i;
4697 for (;;) {
4699 bidx = i - j;
4700 if (bidx < 0)
4701 bidx = MAX_START + bidx;
4703 if (np->squeue[i] == NCB_SCRIPT_PHYS (np, skip)) {
4704 j++;
4705 } else if (j != 0) {
4706 np->squeue[bidx] = np->squeue[i];
4707 if (np->squeue[bidx]
4708 == NCB_SCRIPT_PHYS(np, idle))
4709 break;
4711 i = (i + 1) % MAX_START;
4713 np->squeueput = bidx;
4717 /*==========================================================
4720 ** Start NCR chip.
4723 **==========================================================
4726 static void
4727 ncr_init(ncb_p np, char * msg, u_long code)
4729 int i;
4732 ** Reset chip.
4735 OUTB (nc_istat, SRST);
4736 DELAY (1000);
4737 OUTB (nc_istat, 0);
4740 ** Message.
4743 if (msg) kprintf ("%s: restart (%s).\n", ncr_name (np), msg);
4746 ** Clear Start Queue
4749 for (i=0;i<MAX_START;i++)
4750 np -> squeue [i] = NCB_SCRIPT_PHYS (np, idle);
4753 ** Start at first entry.
4756 np->squeueput = 0;
4757 WRITESCRIPT(startpos[0], NCB_SCRIPTH_PHYS (np, tryloop));
4758 WRITESCRIPT(start0 [0], SCR_INT ^ IFFALSE (0));
4761 ** Wakeup all pending jobs.
4764 ncr_wakeup (np, code);
4767 ** Init chip.
4770 OUTB (nc_istat, 0x00 ); /* Remove Reset, abort ... */
4771 OUTB (nc_scntl0, 0xca ); /* full arb., ena parity, par->ATN */
4772 OUTB (nc_scntl1, 0x00 ); /* odd parity, and remove CRST!! */
4773 ncr_selectclock(np, np->rv_scntl3); /* Select SCSI clock */
4774 OUTB (nc_scid , RRE|np->myaddr);/* host adapter SCSI address */
4775 OUTW (nc_respid, 1ul<<np->myaddr);/* id to respond to */
4776 OUTB (nc_istat , SIGP ); /* Signal Process */
4777 OUTB (nc_dmode , np->rv_dmode); /* XXX modify burstlen ??? */
4778 OUTB (nc_dcntl , np->rv_dcntl);
4779 OUTB (nc_ctest3, np->rv_ctest3);
4780 OUTB (nc_ctest5, np->rv_ctest5);
4781 OUTB (nc_ctest4, np->rv_ctest4);/* enable master parity checking */
4782 OUTB (nc_stest2, np->rv_stest2|EXT); /* Extended Sreq/Sack filtering */
4783 OUTB (nc_stest3, TE ); /* TolerANT enable */
4784 OUTB (nc_stime0, 0x0b ); /* HTH = disabled, STO = 0.1 sec. */
4786 if (bootverbose >= 2) {
4787 kprintf ("\tACTUAL values:SCNTL3:%02x DMODE:%02x DCNTL:%02x\n",
4788 np->rv_scntl3, np->rv_dmode, np->rv_dcntl);
4789 kprintf ("\t CTEST3:%02x CTEST4:%02x CTEST5:%02x\n",
4790 np->rv_ctest3, np->rv_ctest4, np->rv_ctest5);
4794 ** Enable GPIO0 pin for writing if LED support.
4797 if (np->features & FE_LED0) {
4798 OUTOFFB (nc_gpcntl, 0x01);
4802 ** Fill in target structure.
4804 for (i=0;i<MAX_TARGET;i++) {
4805 tcb_p tp = &np->target[i];
4807 tp->tinfo.sval = 0;
4808 tp->tinfo.wval = np->rv_scntl3;
4810 tp->tinfo.current.period = 0;
4811 tp->tinfo.current.offset = 0;
4812 tp->tinfo.current.width = MSG_EXT_WDTR_BUS_8_BIT;
4816 ** enable ints
4819 OUTW (nc_sien , STO|HTH|MA|SGE|UDC|RST);
4820 OUTB (nc_dien , MDPE|BF|ABRT|SSI|SIR|IID);
4823 ** Start script processor.
4826 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, start));
4829 * Notify the XPT of the event
4831 if (code == HS_RESET)
4832 xpt_async(AC_BUS_RESET, np->path, NULL);
4835 static void
4836 ncr_poll(struct cam_sim *sim)
4838 ncr_intr(cam_sim_softc(sim));
4842 /*==========================================================
4844 ** Get clock factor and sync divisor for a given
4845 ** synchronous factor period.
4846 ** Returns the clock factor (in sxfer) and scntl3
4847 ** synchronous divisor field.
4849 **==========================================================
4852 static void ncr_getsync(ncb_p np, u_char sfac, u_char *fakp, u_char *scntl3p)
4854 u_long clk = np->clock_khz; /* SCSI clock frequency in kHz */
4855 int div = np->clock_divn; /* Number of divisors supported */
4856 u_long fak; /* Sync factor in sxfer */
4857 u_long per; /* Period in tenths of ns */
4858 u_long kpc; /* (per * clk) */
4861 ** Compute the synchronous period in tenths of nano-seconds
4863 if (sfac <= 10) per = 250;
4864 else if (sfac == 11) per = 303;
4865 else if (sfac == 12) per = 500;
4866 else per = 40 * sfac;
4869 ** Look for the greatest clock divisor that allows an
4870 ** input speed faster than the period.
4872 kpc = per * clk;
4873 while (--div >= 0)
4874 if (kpc >= (div_10M[div] * 4)) break;
4877 ** Calculate the lowest clock factor that allows an output
4878 ** speed not faster than the period.
4880 fak = (kpc - 1) / div_10M[div] + 1;
4882 #if 0 /* You can #if 1 if you think this optimization is useful */
4884 per = (fak * div_10M[div]) / clk;
4887 ** Why not to try the immediate lower divisor and to choose
4888 ** the one that allows the fastest output speed ?
4889 ** We dont want input speed too much greater than output speed.
4891 if (div >= 1 && fak < 6) {
4892 u_long fak2, per2;
4893 fak2 = (kpc - 1) / div_10M[div-1] + 1;
4894 per2 = (fak2 * div_10M[div-1]) / clk;
4895 if (per2 < per && fak2 <= 6) {
4896 fak = fak2;
4897 per = per2;
4898 --div;
4901 #endif
4903 if (fak < 4) fak = 4; /* Should never happen, too bad ... */
4906 ** Compute and return sync parameters for the ncr
4908 *fakp = fak - 4;
4909 *scntl3p = ((div+1) << 4) + (sfac < 25 ? 0x80 : 0);
4912 /*==========================================================
4914 ** Switch sync mode for current job and its target
4916 **==========================================================
4919 static void
4920 ncr_setsync(ncb_p np, nccb_p cp, u_char scntl3, u_char sxfer, u_char period)
4922 union ccb *ccb;
4923 struct ccb_trans_settings neg;
4924 tcb_p tp;
4925 int div;
4926 u_int target = INB (nc_sdid) & 0x0f;
4927 u_int period_10ns;
4929 assert (cp);
4930 if (!cp) return;
4932 ccb = cp->ccb;
4933 assert (ccb);
4934 if (!ccb) return;
4935 assert (target == ccb->ccb_h.target_id);
4937 tp = &np->target[target];
4939 if (!scntl3 || !(sxfer & 0x1f))
4940 scntl3 = np->rv_scntl3;
4941 scntl3 = (scntl3 & 0xf0) | (tp->tinfo.wval & EWS)
4942 | (np->rv_scntl3 & 0x07);
4945 ** Deduce the value of controller sync period from scntl3.
4946 ** period is in tenths of nano-seconds.
4949 div = ((scntl3 >> 4) & 0x7);
4950 if ((sxfer & 0x1f) && div)
4951 period_10ns =
4952 (((sxfer>>5)+4)*div_10M[div-1])/np->clock_khz;
4953 else
4954 period_10ns = 0;
4956 tp->tinfo.goal.period = period;
4957 tp->tinfo.goal.offset = sxfer & 0x1f;
4958 tp->tinfo.current.period = period;
4959 tp->tinfo.current.offset = sxfer & 0x1f;
4962 ** Stop there if sync parameters are unchanged
4964 if (tp->tinfo.sval == sxfer && tp->tinfo.wval == scntl3) return;
4965 tp->tinfo.sval = sxfer;
4966 tp->tinfo.wval = scntl3;
4968 if (sxfer & 0x1f) {
4970 ** Disable extended Sreq/Sack filtering
4972 if (period_10ns <= 2000) OUTOFFB (nc_stest2, EXT);
4976 ** Tell the SCSI layer about the
4977 ** new transfer parameters.
4979 memset(&neg, 0, sizeof (neg));
4980 neg.protocol = PROTO_SCSI;
4981 neg.protocol_version = SCSI_REV_2;
4982 neg.transport = XPORT_SPI;
4983 neg.transport_version = 2;
4984 neg.xport_specific.spi.sync_period = period;
4985 neg.xport_specific.spi.sync_offset = sxfer & 0x1f;
4986 neg.xport_specific.spi.valid = CTS_SPI_VALID_SYNC_RATE
4987 | CTS_SPI_VALID_SYNC_OFFSET;
4988 xpt_setup_ccb(&neg.ccb_h, ccb->ccb_h.path,
4989 /*priority*/1);
4990 xpt_async(AC_TRANSFER_NEG, ccb->ccb_h.path, &neg);
4993 ** set actual value and sync_status
4995 OUTB (nc_sxfer, sxfer);
4996 np->sync_st = sxfer;
4997 OUTB (nc_scntl3, scntl3);
4998 np->wide_st = scntl3;
5001 ** patch ALL nccbs of this target.
5003 for (cp = np->link_nccb; cp; cp = cp->link_nccb) {
5004 if (!cp->ccb) continue;
5005 if (cp->ccb->ccb_h.target_id != target) continue;
5006 cp->sync_status = sxfer;
5007 cp->wide_status = scntl3;
5011 /*==========================================================
5013 ** Switch wide mode for current job and its target
5014 ** SCSI specs say: a SCSI device that accepts a WDTR
5015 ** message shall reset the synchronous agreement to
5016 ** asynchronous mode.
5018 **==========================================================
5021 static void ncr_setwide (ncb_p np, nccb_p cp, u_char wide, u_char ack)
5023 union ccb *ccb;
5024 struct ccb_trans_settings neg;
5025 u_int target = INB (nc_sdid) & 0x0f;
5026 tcb_p tp;
5027 u_char scntl3;
5028 u_char sxfer;
5030 assert (cp);
5031 if (!cp) return;
5033 ccb = cp->ccb;
5034 assert (ccb);
5035 if (!ccb) return;
5036 assert (target == ccb->ccb_h.target_id);
5038 tp = &np->target[target];
5039 tp->tinfo.current.width = wide;
5040 tp->tinfo.goal.width = wide;
5041 tp->tinfo.current.period = 0;
5042 tp->tinfo.current.offset = 0;
5044 scntl3 = (tp->tinfo.wval & (~EWS)) | (wide ? EWS : 0);
5046 sxfer = ack ? 0 : tp->tinfo.sval;
5049 ** Stop there if sync/wide parameters are unchanged
5051 if (tp->tinfo.sval == sxfer && tp->tinfo.wval == scntl3) return;
5052 tp->tinfo.sval = sxfer;
5053 tp->tinfo.wval = scntl3;
5055 /* Tell the SCSI layer about the new transfer params */
5056 memset(&neg, 0, sizeof (neg));
5057 neg.protocol = PROTO_SCSI;
5058 neg.protocol_version = SCSI_REV_2;
5059 neg.transport = XPORT_SPI;
5060 neg.transport_version = 2;
5061 neg.xport_specific.spi.bus_width = (scntl3 & EWS) ?
5062 MSG_EXT_WDTR_BUS_16_BIT : MSG_EXT_WDTR_BUS_8_BIT;
5063 neg.xport_specific.spi.sync_period = 0;
5064 neg.xport_specific.spi.sync_offset = 0;
5065 neg.xport_specific.spi.valid = CTS_SPI_VALID_SYNC_RATE
5066 | CTS_SPI_VALID_SYNC_OFFSET
5067 | CTS_SPI_VALID_BUS_WIDTH;
5068 xpt_setup_ccb(&neg.ccb_h, ccb->ccb_h.path, /*priority*/1);
5069 xpt_async(AC_TRANSFER_NEG, ccb->ccb_h.path, &neg);
5072 ** set actual value and sync_status
5074 OUTB (nc_sxfer, sxfer);
5075 np->sync_st = sxfer;
5076 OUTB (nc_scntl3, scntl3);
5077 np->wide_st = scntl3;
5080 ** patch ALL nccbs of this target.
5082 for (cp = np->link_nccb; cp; cp = cp->link_nccb) {
5083 if (!cp->ccb) continue;
5084 if (cp->ccb->ccb_h.target_id != target) continue;
5085 cp->sync_status = sxfer;
5086 cp->wide_status = scntl3;
5090 /*==========================================================
5093 ** ncr timeout handler.
5096 **==========================================================
5098 ** Misused to keep the driver running when
5099 ** interrupts are not configured correctly.
5101 **----------------------------------------------------------
5104 static void
5105 ncr_timeout (void *arg)
5107 ncb_p np = arg;
5108 time_t thistime = time_uptime;
5109 ticks_t step = np->ticks;
5110 long t;
5111 nccb_p cp;
5113 if (np->lasttime != thistime) {
5115 ** block ncr interrupts
5117 crit_enter();
5118 np->lasttime = thistime;
5120 /*----------------------------------------------------
5122 ** handle ncr chip timeouts
5124 ** Assumption:
5125 ** We have a chance to arbitrate for the
5126 ** SCSI bus at least every 10 seconds.
5128 **----------------------------------------------------
5131 t = thistime - np->heartbeat;
5133 if (t<2) np->latetime=0; else np->latetime++;
5135 if (np->latetime>2) {
5137 ** If there are no requests, the script
5138 ** processor will sleep on SEL_WAIT_RESEL.
5139 ** But we have to check whether it died.
5140 ** Let's try to wake it up.
5142 OUTB (nc_istat, SIGP);
5145 /*----------------------------------------------------
5147 ** handle nccb timeouts
5149 **----------------------------------------------------
5152 for (cp=np->link_nccb; cp; cp=cp->link_nccb) {
5154 ** look for timed out nccbs.
5156 if (!cp->host_status) continue;
5157 if (cp->tlimit > thistime) continue;
5160 ** Disable reselect.
5161 ** Remove it from startqueue.
5163 cp->jump_nccb.l_cmd = (SCR_JUMP);
5164 if (cp->phys.header.launch.l_paddr ==
5165 NCB_SCRIPT_PHYS (np, select)) {
5166 kprintf ("%s: timeout nccb=%p (skip)\n",
5167 ncr_name (np), cp);
5168 cp->phys.header.launch.l_paddr
5169 = NCB_SCRIPT_PHYS (np, skip);
5172 switch (cp->host_status) {
5174 case HS_BUSY:
5175 case HS_NEGOTIATE:
5176 /* fall through */
5177 case HS_DISCONNECT:
5178 cp->host_status=HS_TIMEOUT;
5180 cp->tag = 0;
5183 ** wakeup this nccb.
5185 ncr_complete (np, cp);
5187 crit_exit();
5190 callout_reset(&np->timeout_ch, step ? step : 1, ncr_timeout, np);
5192 if (INB(nc_istat) & (INTF|SIP|DIP)) {
5195 ** Process pending interrupts.
5198 crit_enter();
5199 if (DEBUG_FLAGS & DEBUG_TINY) kprintf ("{");
5200 ncr_exception (np);
5201 if (DEBUG_FLAGS & DEBUG_TINY) kprintf ("}");
5202 crit_exit();
5206 /*==========================================================
5208 ** log message for real hard errors
5210 ** "ncr0 targ 0?: ERROR (ds:si) (so-si-sd) (sxfer/scntl3) @ name (dsp:dbc)."
5211 ** " reg: r0 r1 r2 r3 r4 r5 r6 ..... rf."
5213 ** exception register:
5214 ** ds: dstat
5215 ** si: sist
5217 ** SCSI bus lines:
5218 ** so: control lines as driver by NCR.
5219 ** si: control lines as seen by NCR.
5220 ** sd: scsi data lines as seen by NCR.
5222 ** wide/fastmode:
5223 ** sxfer: (see the manual)
5224 ** scntl3: (see the manual)
5226 ** current script command:
5227 ** dsp: script adress (relative to start of script).
5228 ** dbc: first word of script command.
5230 ** First 16 register of the chip:
5231 ** r0..rf
5233 **==========================================================
5236 static void ncr_log_hard_error(ncb_p np, u_short sist, u_char dstat)
5238 u_int32_t dsp;
5239 int script_ofs;
5240 int script_size;
5241 char *script_name;
5242 u_char *script_base;
5243 int i;
5245 dsp = INL (nc_dsp);
5247 if (np->p_script < dsp &&
5248 dsp <= np->p_script + sizeof(struct script)) {
5249 script_ofs = dsp - np->p_script;
5250 script_size = sizeof(struct script);
5251 script_base = (u_char *) np->script;
5252 script_name = "script";
5254 else if (np->p_scripth < dsp &&
5255 dsp <= np->p_scripth + sizeof(struct scripth)) {
5256 script_ofs = dsp - np->p_scripth;
5257 script_size = sizeof(struct scripth);
5258 script_base = (u_char *) np->scripth;
5259 script_name = "scripth";
5260 } else {
5261 script_ofs = dsp;
5262 script_size = 0;
5263 script_base = NULL;
5264 script_name = "mem";
5267 kprintf ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x) @ (%s %x:%08x).\n",
5268 ncr_name (np), (unsigned)INB (nc_sdid)&0x0f, dstat, sist,
5269 (unsigned)INB (nc_socl), (unsigned)INB (nc_sbcl), (unsigned)INB (nc_sbdl),
5270 (unsigned)INB (nc_sxfer),(unsigned)INB (nc_scntl3), script_name, script_ofs,
5271 (unsigned)INL (nc_dbc));
5273 if (((script_ofs & 3) == 0) &&
5274 (unsigned)script_ofs < script_size) {
5275 kprintf ("%s: script cmd = %08x\n", ncr_name(np),
5276 (int)READSCRIPT_OFF(script_base, script_ofs));
5279 kprintf ("%s: regdump:", ncr_name(np));
5280 for (i=0; i<16;i++)
5281 kprintf (" %02x", (unsigned)INB_OFF(i));
5282 kprintf (".\n");
5285 /*==========================================================
5288 ** ncr chip exception handler.
5291 **==========================================================
5294 static void ncr_exception (ncb_p np)
5296 u_char istat, dstat;
5297 u_short sist;
5300 ** interrupt on the fly ?
5302 while ((istat = INB (nc_istat)) & INTF) {
5303 if (DEBUG_FLAGS & DEBUG_TINY) kprintf ("F ");
5304 OUTB (nc_istat, INTF);
5305 np->profile.num_fly++;
5306 ncr_wakeup (np, 0);
5308 if (!(istat & (SIP|DIP))) {
5309 return;
5313 ** Steinbach's Guideline for Systems Programming:
5314 ** Never test for an error condition you don't know how to handle.
5317 sist = (istat & SIP) ? INW (nc_sist) : 0;
5318 dstat = (istat & DIP) ? INB (nc_dstat) : 0;
5319 np->profile.num_int++;
5321 if (DEBUG_FLAGS & DEBUG_TINY)
5322 kprintf ("<%d|%x:%x|%x:%x>",
5323 INB(nc_scr0),
5324 dstat,sist,
5325 (unsigned)INL(nc_dsp),
5326 (unsigned)INL(nc_dbc));
5327 if ((dstat==DFE) && (sist==PAR)) return;
5329 /*==========================================================
5331 ** First the normal cases.
5333 **==========================================================
5335 /*-------------------------------------------
5336 ** SCSI reset
5337 **-------------------------------------------
5340 if (sist & RST) {
5341 ncr_init (np, bootverbose ? "scsi reset" : NULL, HS_RESET);
5342 return;
5345 /*-------------------------------------------
5346 ** selection timeout
5348 ** IID excluded from dstat mask!
5349 ** (chip bug)
5350 **-------------------------------------------
5353 if ((sist & STO) &&
5354 !(sist & (GEN|HTH|MA|SGE|UDC|RST|PAR)) &&
5355 !(dstat & (MDPE|BF|ABRT|SIR))) {
5356 ncr_int_sto (np);
5357 return;
5360 /*-------------------------------------------
5361 ** Phase mismatch.
5362 **-------------------------------------------
5365 if ((sist & MA) &&
5366 !(sist & (STO|GEN|HTH|SGE|UDC|RST|PAR)) &&
5367 !(dstat & (MDPE|BF|ABRT|SIR|IID))) {
5368 ncr_int_ma (np, dstat);
5369 return;
5372 /*----------------------------------------
5373 ** move command with length 0
5374 **----------------------------------------
5377 if ((dstat & IID) &&
5378 !(sist & (STO|GEN|HTH|MA|SGE|UDC|RST|PAR)) &&
5379 !(dstat & (MDPE|BF|ABRT|SIR)) &&
5380 ((INL(nc_dbc) & 0xf8000000) == SCR_MOVE_TBL)) {
5382 ** Target wants more data than available.
5383 ** The "no_data" script will do it.
5385 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, no_data));
5386 return;
5389 /*-------------------------------------------
5390 ** Programmed interrupt
5391 **-------------------------------------------
5394 if ((dstat & SIR) &&
5395 !(sist & (STO|GEN|HTH|MA|SGE|UDC|RST|PAR)) &&
5396 !(dstat & (MDPE|BF|ABRT|IID)) &&
5397 (INB(nc_dsps) <= SIR_MAX)) {
5398 ncr_int_sir (np);
5399 return;
5402 /*========================================
5403 ** log message for real hard errors
5404 **========================================
5407 ncr_log_hard_error(np, sist, dstat);
5409 /*========================================
5410 ** do the register dump
5411 **========================================
5414 if (time_uptime - np->regtime > 10) {
5415 int i;
5416 np->regtime = time_uptime;
5417 for (i=0; i<sizeof(np->regdump); i++)
5418 ((volatile char*)&np->regdump)[i] = INB_OFF(i);
5419 np->regdump.nc_dstat = dstat;
5420 np->regdump.nc_sist = sist;
5424 /*----------------------------------------
5425 ** clean up the dma fifo
5426 **----------------------------------------
5429 if ( (INB(nc_sstat0) & (ILF|ORF|OLF) ) ||
5430 (INB(nc_sstat1) & (FF3210) ) ||
5431 (INB(nc_sstat2) & (ILF1|ORF1|OLF1)) || /* wide .. */
5432 !(dstat & DFE)) {
5433 kprintf ("%s: have to clear fifos.\n", ncr_name (np));
5434 OUTB (nc_stest3, TE|CSF); /* clear scsi fifo */
5435 OUTB (nc_ctest3, np->rv_ctest3 | CLF);
5436 /* clear dma fifo */
5439 /*----------------------------------------
5440 ** handshake timeout
5441 **----------------------------------------
5444 if (sist & HTH) {
5445 kprintf ("%s: handshake timeout\n", ncr_name(np));
5446 OUTB (nc_scntl1, CRST);
5447 DELAY (1000);
5448 OUTB (nc_scntl1, 0x00);
5449 OUTB (nc_scr0, HS_FAIL);
5450 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, cleanup));
5451 return;
5454 /*----------------------------------------
5455 ** unexpected disconnect
5456 **----------------------------------------
5459 if ((sist & UDC) &&
5460 !(sist & (STO|GEN|HTH|MA|SGE|RST|PAR)) &&
5461 !(dstat & (MDPE|BF|ABRT|SIR|IID))) {
5462 OUTB (nc_scr0, HS_UNEXPECTED);
5463 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, cleanup));
5464 return;
5467 /*----------------------------------------
5468 ** cannot disconnect
5469 **----------------------------------------
5472 if ((dstat & IID) &&
5473 !(sist & (STO|GEN|HTH|MA|SGE|UDC|RST|PAR)) &&
5474 !(dstat & (MDPE|BF|ABRT|SIR)) &&
5475 ((INL(nc_dbc) & 0xf8000000) == SCR_WAIT_DISC)) {
5477 ** Unexpected data cycle while waiting for disconnect.
5479 if (INB(nc_sstat2) & LDSC) {
5481 ** It's an early reconnect.
5482 ** Let's continue ...
5484 OUTB (nc_dcntl, np->rv_dcntl | STD);
5486 ** info message
5488 kprintf ("%s: INFO: LDSC while IID.\n",
5489 ncr_name (np));
5490 return;
5492 kprintf ("%s: target %d doesn't release the bus.\n",
5493 ncr_name (np), INB (nc_sdid)&0x0f);
5495 ** return without restarting the NCR.
5496 ** timeout will do the real work.
5498 return;
5501 /*----------------------------------------
5502 ** single step
5503 **----------------------------------------
5506 if ((dstat & SSI) &&
5507 !(sist & (STO|GEN|HTH|MA|SGE|UDC|RST|PAR)) &&
5508 !(dstat & (MDPE|BF|ABRT|SIR|IID))) {
5509 OUTB (nc_dcntl, np->rv_dcntl | STD);
5510 return;
5514 ** @RECOVER@ HTH, SGE, ABRT.
5516 ** We should try to recover from these interrupts.
5517 ** They may occur if there are problems with synch transfers, or
5518 ** if targets are switched on or off while the driver is running.
5521 if (sist & SGE) {
5522 /* clear scsi offsets */
5523 OUTB (nc_ctest3, np->rv_ctest3 | CLF);
5527 ** Freeze controller to be able to read the messages.
5530 if (DEBUG_FLAGS & DEBUG_FREEZE) {
5531 int i;
5532 unsigned char val;
5533 for (i=0; i<0x60; i++) {
5534 switch (i%16) {
5536 case 0:
5537 kprintf ("%s: reg[%d0]: ",
5538 ncr_name(np),i/16);
5539 break;
5540 case 4:
5541 case 8:
5542 case 12:
5543 kprintf (" ");
5544 break;
5546 val = bus_space_read_1(np->bst, np->bsh, i);
5547 kprintf (" %x%x", val/16, val%16);
5548 if (i%16==15) kprintf (".\n");
5551 callout_stop(&np->timeout_ch);
5553 kprintf ("%s: halted!\n", ncr_name(np));
5555 ** don't restart controller ...
5557 OUTB (nc_istat, SRST);
5558 return;
5561 #ifdef NCR_FREEZE
5563 ** Freeze system to be able to read the messages.
5565 kprintf ("ncr: fatal error: system halted - press reset to reboot ...");
5566 crit_enter();
5567 for (;;);
5568 #endif
5571 ** sorry, have to kill ALL jobs ...
5574 ncr_init (np, "fatal error", HS_FAIL);
5577 /*==========================================================
5579 ** ncr chip exception handler for selection timeout
5581 **==========================================================
5583 ** There seems to be a bug in the 53c810.
5584 ** Although a STO-Interrupt is pending,
5585 ** it continues executing script commands.
5586 ** But it will fail and interrupt (IID) on
5587 ** the next instruction where it's looking
5588 ** for a valid phase.
5590 **----------------------------------------------------------
5593 static void ncr_int_sto (ncb_p np)
5595 u_long dsa, scratcha, diff;
5596 nccb_p cp;
5597 if (DEBUG_FLAGS & DEBUG_TINY) kprintf ("T");
5600 ** look for nccb and set the status.
5603 dsa = INL (nc_dsa);
5604 cp = np->link_nccb;
5605 while (cp && (CCB_PHYS (cp, phys) != dsa))
5606 cp = cp->link_nccb;
5608 if (cp) {
5609 cp-> host_status = HS_SEL_TIMEOUT;
5610 ncr_complete (np, cp);
5614 ** repair start queue
5617 scratcha = INL (nc_scratcha);
5618 diff = scratcha - NCB_SCRIPTH_PHYS (np, tryloop);
5620 /* assert ((diff <= MAX_START * 20) && !(diff % 20));*/
5622 if ((diff <= MAX_START * 20) && !(diff % 20)) {
5623 WRITESCRIPT(startpos[0], scratcha);
5624 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, start));
5625 return;
5627 ncr_init (np, "selection timeout", HS_FAIL);
5630 /*==========================================================
5633 ** ncr chip exception handler for phase errors.
5636 **==========================================================
5638 ** We have to construct a new transfer descriptor,
5639 ** to transfer the rest of the current block.
5641 **----------------------------------------------------------
5644 static void ncr_int_ma (ncb_p np, u_char dstat)
5646 u_int32_t dbc;
5647 u_int32_t rest;
5648 u_int32_t dsa;
5649 u_int32_t dsp;
5650 u_int32_t nxtdsp;
5651 volatile void *vdsp_base;
5652 size_t vdsp_off;
5653 u_int32_t oadr, olen;
5654 u_int32_t *tblp, *newcmd;
5655 u_char cmd, sbcl, ss0, ss2, ctest5;
5656 u_short delta;
5657 nccb_p cp;
5659 dsp = INL (nc_dsp);
5660 dsa = INL (nc_dsa);
5661 dbc = INL (nc_dbc);
5662 ss0 = INB (nc_sstat0);
5663 ss2 = INB (nc_sstat2);
5664 sbcl= INB (nc_sbcl);
5666 cmd = dbc >> 24;
5667 rest= dbc & 0xffffff;
5669 ctest5 = (np->rv_ctest5 & DFS) ? INB (nc_ctest5) : 0;
5670 if (ctest5 & DFS)
5671 delta=(((ctest5<<8) | (INB (nc_dfifo) & 0xff)) - rest) & 0x3ff;
5672 else
5673 delta=(INB (nc_dfifo) - rest) & 0x7f;
5677 ** The data in the dma fifo has not been transfered to
5678 ** the target -> add the amount to the rest
5679 ** and clear the data.
5680 ** Check the sstat2 register in case of wide transfer.
5683 if (!(dstat & DFE)) rest += delta;
5684 if (ss0 & OLF) rest++;
5685 if (ss0 & ORF) rest++;
5686 if (INB(nc_scntl3) & EWS) {
5687 if (ss2 & OLF1) rest++;
5688 if (ss2 & ORF1) rest++;
5690 OUTB (nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */
5691 OUTB (nc_stest3, TE|CSF); /* clear scsi fifo */
5694 ** locate matching cp
5696 cp = np->link_nccb;
5697 while (cp && (CCB_PHYS (cp, phys) != dsa))
5698 cp = cp->link_nccb;
5700 if (!cp) {
5701 kprintf ("%s: SCSI phase error fixup: CCB already dequeued (%p)\n",
5702 ncr_name (np), (void *) np->header.cp);
5703 return;
5705 if (cp != np->header.cp) {
5706 kprintf ("%s: SCSI phase error fixup: CCB address mismatch "
5707 "(%p != %p) np->nccb = %p\n",
5708 ncr_name (np), (void *)cp, (void *)np->header.cp,
5709 (void *)np->link_nccb);
5710 /* return;*/
5714 ** find the interrupted script command,
5715 ** and the address at which to continue.
5718 if (dsp == vtophys (&cp->patch[2])) {
5719 vdsp_base = cp;
5720 vdsp_off = offsetof(struct nccb, patch[0]);
5721 nxtdsp = READSCRIPT_OFF(vdsp_base, vdsp_off + 3*4);
5722 } else if (dsp == vtophys (&cp->patch[6])) {
5723 vdsp_base = cp;
5724 vdsp_off = offsetof(struct nccb, patch[4]);
5725 nxtdsp = READSCRIPT_OFF(vdsp_base, vdsp_off + 3*4);
5726 } else if (dsp > np->p_script &&
5727 dsp <= np->p_script + sizeof(struct script)) {
5728 vdsp_base = np->script;
5729 vdsp_off = dsp - np->p_script - 8;
5730 nxtdsp = dsp;
5731 } else {
5732 vdsp_base = np->scripth;
5733 vdsp_off = dsp - np->p_scripth - 8;
5734 nxtdsp = dsp;
5738 ** log the information
5740 if (DEBUG_FLAGS & (DEBUG_TINY|DEBUG_PHASE)) {
5741 kprintf ("P%x%x ",cmd&7, sbcl&7);
5742 kprintf ("RL=%d D=%d SS0=%x ",
5743 (unsigned) rest, (unsigned) delta, ss0);
5745 if (DEBUG_FLAGS & DEBUG_PHASE) {
5746 kprintf ("\nCP=%p CP2=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
5747 cp, np->header.cp,
5748 dsp,
5749 nxtdsp, (volatile char*)vdsp_base+vdsp_off, cmd);
5753 ** get old startaddress and old length.
5756 oadr = READSCRIPT_OFF(vdsp_base, vdsp_off + 1*4);
5758 if (cmd & 0x10) { /* Table indirect */
5759 tblp = (u_int32_t *) ((char*) &cp->phys + oadr);
5760 olen = tblp[0];
5761 oadr = tblp[1];
5762 } else {
5763 tblp = NULL;
5764 olen = READSCRIPT_OFF(vdsp_base, vdsp_off) & 0xffffff;
5767 if (DEBUG_FLAGS & DEBUG_PHASE) {
5768 kprintf ("OCMD=%x\nTBLP=%p OLEN=%lx OADR=%lx\n",
5769 (unsigned) (READSCRIPT_OFF(vdsp_base, vdsp_off) >> 24),
5770 (void *) tblp,
5771 (u_long) olen,
5772 (u_long) oadr);
5776 ** if old phase not dataphase, leave here.
5779 if (cmd != (READSCRIPT_OFF(vdsp_base, vdsp_off) >> 24)) {
5780 PRINT_ADDR(cp->ccb);
5781 kprintf ("internal error: cmd=%02x != %02x=(vdsp[0] >> 24)\n",
5782 (unsigned)cmd,
5783 (unsigned)READSCRIPT_OFF(vdsp_base, vdsp_off) >> 24);
5785 return;
5787 if (cmd & 0x06) {
5788 PRINT_ADDR(cp->ccb);
5789 kprintf ("phase change %x-%x %d@%08x resid=%d.\n",
5790 cmd&7, sbcl&7, (unsigned)olen,
5791 (unsigned)oadr, (unsigned)rest);
5793 OUTB (nc_dcntl, np->rv_dcntl | STD);
5794 return;
5798 ** choose the correct patch area.
5799 ** if savep points to one, choose the other.
5802 newcmd = cp->patch;
5803 if (cp->phys.header.savep == vtophys (newcmd)) newcmd+=4;
5806 ** fillin the commands
5809 newcmd[0] = ((cmd & 0x0f) << 24) | rest;
5810 newcmd[1] = oadr + olen - rest;
5811 newcmd[2] = SCR_JUMP;
5812 newcmd[3] = nxtdsp;
5814 if (DEBUG_FLAGS & DEBUG_PHASE) {
5815 PRINT_ADDR(cp->ccb);
5816 kprintf ("newcmd[%d] %x %x %x %x.\n",
5817 (int)(newcmd - cp->patch),
5818 (unsigned)newcmd[0],
5819 (unsigned)newcmd[1],
5820 (unsigned)newcmd[2],
5821 (unsigned)newcmd[3]);
5824 ** fake the return address (to the patch).
5825 ** and restart script processor at dispatcher.
5827 np->profile.num_break++;
5828 OUTL (nc_temp, vtophys (newcmd));
5829 if ((cmd & 7) == 0)
5830 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, dispatch));
5831 else
5832 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, checkatn));
5835 /*==========================================================
5838 ** ncr chip exception handler for programmed interrupts.
5841 **==========================================================
5844 static int ncr_show_msg (u_char * msg)
5846 u_char i;
5847 kprintf ("%x",*msg);
5848 if (*msg==MSG_EXTENDED) {
5849 for (i=1;i<8;i++) {
5850 if (i-1>msg[1]) break;
5851 kprintf ("-%x",msg[i]);
5853 return (i+1);
5854 } else if ((*msg & 0xf0) == 0x20) {
5855 kprintf ("-%x",msg[1]);
5856 return (2);
5858 return (1);
5861 static void ncr_int_sir (ncb_p np)
5863 u_char scntl3;
5864 u_char chg, ofs, per, fak, wide;
5865 u_char num = INB (nc_dsps);
5866 nccb_p cp=NULL;
5867 u_long dsa;
5868 u_int target = INB (nc_sdid) & 0x0f;
5869 tcb_p tp = &np->target[target];
5870 int i;
5871 if (DEBUG_FLAGS & DEBUG_TINY) kprintf ("I#%d", num);
5873 switch (num) {
5874 case SIR_SENSE_RESTART:
5875 case SIR_STALL_RESTART:
5876 break;
5878 default:
5880 ** lookup the nccb
5882 dsa = INL (nc_dsa);
5883 cp = np->link_nccb;
5884 while (cp && (CCB_PHYS (cp, phys) != dsa))
5885 cp = cp->link_nccb;
5887 assert (cp);
5888 if (!cp)
5889 goto out;
5890 assert (cp == np->header.cp);
5891 if (cp != np->header.cp)
5892 goto out;
5895 switch (num) {
5897 /*--------------------------------------------------------------------
5899 ** Processing of interrupted getcc selects
5901 **--------------------------------------------------------------------
5904 case SIR_SENSE_RESTART:
5905 /*------------------------------------------
5906 ** Script processor is idle.
5907 ** Look for interrupted "check cond"
5908 **------------------------------------------
5911 if (DEBUG_FLAGS & DEBUG_RESTART)
5912 kprintf ("%s: int#%d",ncr_name (np),num);
5913 cp = (nccb_p) 0;
5914 for (i=0; i<MAX_TARGET; i++) {
5915 if (DEBUG_FLAGS & DEBUG_RESTART) kprintf (" t%d", i);
5916 tp = &np->target[i];
5917 if (DEBUG_FLAGS & DEBUG_RESTART) kprintf ("+");
5918 cp = tp->hold_cp;
5919 if (!cp) continue;
5920 if (DEBUG_FLAGS & DEBUG_RESTART) kprintf ("+");
5921 if ((cp->host_status==HS_BUSY) &&
5922 (cp->s_status==SCSI_STATUS_CHECK_COND))
5923 break;
5924 if (DEBUG_FLAGS & DEBUG_RESTART) kprintf ("- (remove)");
5925 tp->hold_cp = cp = (nccb_p) 0;
5928 if (cp) {
5929 if (DEBUG_FLAGS & DEBUG_RESTART)
5930 kprintf ("+ restart job ..\n");
5931 OUTL (nc_dsa, CCB_PHYS (cp, phys));
5932 OUTL (nc_dsp, NCB_SCRIPTH_PHYS (np, getcc));
5933 return;
5937 ** no job, resume normal processing
5939 if (DEBUG_FLAGS & DEBUG_RESTART) kprintf (" -- remove trap\n");
5940 WRITESCRIPT(start0[0], SCR_INT ^ IFFALSE (0));
5941 break;
5943 case SIR_SENSE_FAILED:
5944 /*-------------------------------------------
5945 ** While trying to select for
5946 ** getting the condition code,
5947 ** a target reselected us.
5948 **-------------------------------------------
5950 if (DEBUG_FLAGS & DEBUG_RESTART) {
5951 PRINT_ADDR(cp->ccb);
5952 kprintf ("in getcc reselect by t%d.\n",
5953 INB(nc_ssid) & 0x0f);
5957 ** Mark this job
5959 cp->host_status = HS_BUSY;
5960 cp->s_status = SCSI_STATUS_CHECK_COND;
5961 np->target[cp->ccb->ccb_h.target_id].hold_cp = cp;
5964 ** And patch code to restart it.
5966 WRITESCRIPT(start0[0], SCR_INT);
5967 break;
5969 /*-----------------------------------------------------------------------------
5971 ** Was Sie schon immer ueber transfermode negotiation wissen wollten ...
5973 ** We try to negotiate sync and wide transfer only after
5974 ** a successfull inquire command. We look at byte 7 of the
5975 ** inquire data to determine the capabilities if the target.
5977 ** When we try to negotiate, we append the negotiation message
5978 ** to the identify and (maybe) simple tag message.
5979 ** The host status field is set to HS_NEGOTIATE to mark this
5980 ** situation.
5982 ** If the target doesn't answer this message immidiately
5983 ** (as required by the standard), the SIR_NEGO_FAIL interrupt
5984 ** will be raised eventually.
5985 ** The handler removes the HS_NEGOTIATE status, and sets the
5986 ** negotiated value to the default (async / nowide).
5988 ** If we receive a matching answer immediately, we check it
5989 ** for validity, and set the values.
5991 ** If we receive a Reject message immediately, we assume the
5992 ** negotiation has failed, and fall back to standard values.
5994 ** If we receive a negotiation message while not in HS_NEGOTIATE
5995 ** state, it's a target initiated negotiation. We prepare a
5996 ** (hopefully) valid answer, set our parameters, and send back
5997 ** this answer to the target.
5999 ** If the target doesn't fetch the answer (no message out phase),
6000 ** we assume the negotiation has failed, and fall back to default
6001 ** settings.
6003 ** When we set the values, we adjust them in all nccbs belonging
6004 ** to this target, in the controller's register, and in the "phys"
6005 ** field of the controller's struct ncb.
6007 ** Possible cases: hs sir msg_in value send goto
6008 ** We try try to negotiate:
6009 ** -> target doesnt't msgin NEG FAIL noop defa. - dispatch
6010 ** -> target rejected our msg NEG FAIL reject defa. - dispatch
6011 ** -> target answered (ok) NEG SYNC sdtr set - clrack
6012 ** -> target answered (!ok) NEG SYNC sdtr defa. REJ--->msg_bad
6013 ** -> target answered (ok) NEG WIDE wdtr set - clrack
6014 ** -> target answered (!ok) NEG WIDE wdtr defa. REJ--->msg_bad
6015 ** -> any other msgin NEG FAIL noop defa. - dispatch
6017 ** Target tries to negotiate:
6018 ** -> incoming message --- SYNC sdtr set SDTR -
6019 ** -> incoming message --- WIDE wdtr set WDTR -
6020 ** We sent our answer:
6021 ** -> target doesn't msgout --- PROTO ? defa. - dispatch
6023 **-----------------------------------------------------------------------------
6026 case SIR_NEGO_FAILED:
6027 /*-------------------------------------------------------
6029 ** Negotiation failed.
6030 ** Target doesn't send an answer message,
6031 ** or target rejected our message.
6033 ** Remove negotiation request.
6035 **-------------------------------------------------------
6037 OUTB (HS_PRT, HS_BUSY);
6039 /* fall through */
6041 case SIR_NEGO_PROTO:
6042 /*-------------------------------------------------------
6044 ** Negotiation failed.
6045 ** Target doesn't fetch the answer message.
6047 **-------------------------------------------------------
6050 if (DEBUG_FLAGS & DEBUG_NEGO) {
6051 PRINT_ADDR(cp->ccb);
6052 kprintf ("negotiation failed sir=%x status=%x.\n",
6053 num, cp->nego_status);
6057 ** any error in negotiation:
6058 ** fall back to default mode.
6060 switch (cp->nego_status) {
6062 case NS_SYNC:
6063 ncr_setsync (np, cp, 0, 0xe0, 0);
6064 break;
6066 case NS_WIDE:
6067 ncr_setwide (np, cp, 0, 0);
6068 break;
6071 np->msgin [0] = MSG_NOOP;
6072 np->msgout[0] = MSG_NOOP;
6073 cp->nego_status = 0;
6074 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, dispatch));
6075 break;
6077 case SIR_NEGO_SYNC:
6079 ** Synchronous request message received.
6082 if (DEBUG_FLAGS & DEBUG_NEGO) {
6083 PRINT_ADDR(cp->ccb);
6084 kprintf ("sync msgin: ");
6085 (void) ncr_show_msg (np->msgin);
6086 kprintf (".\n");
6090 ** get requested values.
6093 chg = 0;
6094 per = np->msgin[3];
6095 ofs = np->msgin[4];
6096 if (ofs==0) per=255;
6099 ** check values against driver limits.
6101 if (per < np->minsync)
6102 {chg = 1; per = np->minsync;}
6103 if (per < tp->tinfo.user.period)
6104 {chg = 1; per = tp->tinfo.user.period;}
6105 if (ofs > tp->tinfo.user.offset)
6106 {chg = 1; ofs = tp->tinfo.user.offset;}
6109 ** Check against controller limits.
6112 fak = 7;
6113 scntl3 = 0;
6114 if (ofs != 0) {
6115 ncr_getsync(np, per, &fak, &scntl3);
6116 if (fak > 7) {
6117 chg = 1;
6118 ofs = 0;
6121 if (ofs == 0) {
6122 fak = 7;
6123 per = 0;
6124 scntl3 = 0;
6127 if (DEBUG_FLAGS & DEBUG_NEGO) {
6128 PRINT_ADDR(cp->ccb);
6129 kprintf ("sync: per=%d scntl3=0x%x ofs=%d fak=%d chg=%d.\n",
6130 per, scntl3, ofs, fak, chg);
6133 if (INB (HS_PRT) == HS_NEGOTIATE) {
6134 OUTB (HS_PRT, HS_BUSY);
6135 switch (cp->nego_status) {
6137 case NS_SYNC:
6139 ** This was an answer message
6141 if (chg) {
6143 ** Answer wasn't acceptable.
6145 ncr_setsync (np, cp, 0, 0xe0, 0);
6146 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, msg_bad));
6147 } else {
6149 ** Answer is ok.
6151 ncr_setsync (np,cp,scntl3,(fak<<5)|ofs, per);
6152 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, clrack));
6154 return;
6156 case NS_WIDE:
6157 ncr_setwide (np, cp, 0, 0);
6158 break;
6163 ** It was a request. Set value and
6164 ** prepare an answer message
6167 ncr_setsync (np, cp, scntl3, (fak<<5)|ofs, per);
6169 np->msgout[0] = MSG_EXTENDED;
6170 np->msgout[1] = 3;
6171 np->msgout[2] = MSG_EXT_SDTR;
6172 np->msgout[3] = per;
6173 np->msgout[4] = ofs;
6175 cp->nego_status = NS_SYNC;
6177 if (DEBUG_FLAGS & DEBUG_NEGO) {
6178 PRINT_ADDR(cp->ccb);
6179 kprintf ("sync msgout: ");
6180 (void) ncr_show_msg (np->msgout);
6181 kprintf (".\n");
6184 if (!ofs) {
6185 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, msg_bad));
6186 return;
6188 np->msgin [0] = MSG_NOOP;
6190 break;
6192 case SIR_NEGO_WIDE:
6194 ** Wide request message received.
6196 if (DEBUG_FLAGS & DEBUG_NEGO) {
6197 PRINT_ADDR(cp->ccb);
6198 kprintf ("wide msgin: ");
6199 (void) ncr_show_msg (np->msgin);
6200 kprintf (".\n");
6204 ** get requested values.
6207 chg = 0;
6208 wide = np->msgin[3];
6211 ** check values against driver limits.
6214 if (wide > tp->tinfo.user.width)
6215 {chg = 1; wide = tp->tinfo.user.width;}
6217 if (DEBUG_FLAGS & DEBUG_NEGO) {
6218 PRINT_ADDR(cp->ccb);
6219 kprintf ("wide: wide=%d chg=%d.\n", wide, chg);
6222 if (INB (HS_PRT) == HS_NEGOTIATE) {
6223 OUTB (HS_PRT, HS_BUSY);
6224 switch (cp->nego_status) {
6226 case NS_WIDE:
6228 ** This was an answer message
6230 if (chg) {
6232 ** Answer wasn't acceptable.
6234 ncr_setwide (np, cp, 0, 1);
6235 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, msg_bad));
6236 } else {
6238 ** Answer is ok.
6240 ncr_setwide (np, cp, wide, 1);
6241 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, clrack));
6243 return;
6245 case NS_SYNC:
6246 ncr_setsync (np, cp, 0, 0xe0, 0);
6247 break;
6252 ** It was a request, set value and
6253 ** prepare an answer message
6256 ncr_setwide (np, cp, wide, 1);
6258 np->msgout[0] = MSG_EXTENDED;
6259 np->msgout[1] = 2;
6260 np->msgout[2] = MSG_EXT_WDTR;
6261 np->msgout[3] = wide;
6263 np->msgin [0] = MSG_NOOP;
6265 cp->nego_status = NS_WIDE;
6267 if (DEBUG_FLAGS & DEBUG_NEGO) {
6268 PRINT_ADDR(cp->ccb);
6269 kprintf ("wide msgout: ");
6270 (void) ncr_show_msg (np->msgout);
6271 kprintf (".\n");
6273 break;
6275 /*--------------------------------------------------------------------
6277 ** Processing of special messages
6279 **--------------------------------------------------------------------
6282 case SIR_REJECT_RECEIVED:
6283 /*-----------------------------------------------
6285 ** We received a MSG_MESSAGE_REJECT message.
6287 **-----------------------------------------------
6290 PRINT_ADDR(cp->ccb);
6291 kprintf ("MSG_MESSAGE_REJECT received (%x:%x).\n",
6292 (unsigned)np->lastmsg, np->msgout[0]);
6293 break;
6295 case SIR_REJECT_SENT:
6296 /*-----------------------------------------------
6298 ** We received an unknown message
6300 **-----------------------------------------------
6303 PRINT_ADDR(cp->ccb);
6304 kprintf ("MSG_MESSAGE_REJECT sent for ");
6305 (void) ncr_show_msg (np->msgin);
6306 kprintf (".\n");
6307 break;
6309 /*--------------------------------------------------------------------
6311 ** Processing of special messages
6313 **--------------------------------------------------------------------
6316 case SIR_IGN_RESIDUE:
6317 /*-----------------------------------------------
6319 ** We received an IGNORE RESIDUE message,
6320 ** which couldn't be handled by the script.
6322 **-----------------------------------------------
6325 PRINT_ADDR(cp->ccb);
6326 kprintf ("MSG_IGN_WIDE_RESIDUE received, but not yet implemented.\n");
6327 break;
6329 case SIR_MISSING_SAVE:
6330 /*-----------------------------------------------
6332 ** We received an DISCONNECT message,
6333 ** but the datapointer wasn't saved before.
6335 **-----------------------------------------------
6338 PRINT_ADDR(cp->ccb);
6339 kprintf ("MSG_DISCONNECT received, but datapointer not saved:\n"
6340 "\tdata=%x save=%x goal=%x.\n",
6341 (unsigned) INL (nc_temp),
6342 (unsigned) np->header.savep,
6343 (unsigned) np->header.goalp);
6344 break;
6346 /*--------------------------------------------------------------------
6348 ** Processing of a "SCSI_STATUS_QUEUE_FULL" status.
6350 ** XXX JGibbs - We should do the same thing for BUSY status.
6352 ** The current command has been rejected,
6353 ** because there are too many in the command queue.
6354 ** We have started too many commands for that target.
6356 **--------------------------------------------------------------------
6358 case SIR_STALL_QUEUE:
6359 cp->xerr_status = XE_OK;
6360 cp->host_status = HS_COMPLETE;
6361 cp->s_status = SCSI_STATUS_QUEUE_FULL;
6362 ncr_freeze_devq(np, cp->ccb->ccb_h.path);
6363 ncr_complete(np, cp);
6365 /* FALL THROUGH */
6367 case SIR_STALL_RESTART:
6368 /*-----------------------------------------------
6370 ** Enable selecting again,
6371 ** if NO disconnected jobs.
6373 **-----------------------------------------------
6376 ** Look for a disconnected job.
6378 cp = np->link_nccb;
6379 while (cp && cp->host_status != HS_DISCONNECT)
6380 cp = cp->link_nccb;
6383 ** if there is one, ...
6385 if (cp) {
6387 ** wait for reselection
6389 OUTL (nc_dsp, NCB_SCRIPT_PHYS (np, reselect));
6390 return;
6394 ** else remove the interrupt.
6397 kprintf ("%s: queue empty.\n", ncr_name (np));
6398 WRITESCRIPT(start1[0], SCR_INT ^ IFFALSE (0));
6399 break;
6402 out:
6403 OUTB (nc_dcntl, np->rv_dcntl | STD);
6406 /*==========================================================
6409 ** Acquire a control block
6412 **==========================================================
6415 static nccb_p ncr_get_nccb
6416 (ncb_p np, u_long target, u_long lun)
6418 lcb_p lp;
6419 nccb_p cp = NULL;
6421 /* Keep our timeout handler out */
6422 crit_enter();
6425 ** Lun structure available ?
6428 lp = np->target[target].lp[lun];
6429 if (lp) {
6430 cp = lp->next_nccb;
6433 ** Look for free CCB
6436 while (cp && cp->magic) {
6437 cp = cp->next_nccb;
6442 ** if nothing available, create one.
6445 if (cp == NULL)
6446 cp = ncr_alloc_nccb(np, target, lun);
6448 if (cp != NULL) {
6449 if (cp->magic) {
6450 kprintf("%s: Bogus free cp found\n", ncr_name(np));
6451 crit_exit();
6452 return (NULL);
6454 cp->magic = 1;
6456 crit_exit();
6457 return (cp);
6460 /*==========================================================
6463 ** Release one control block
6466 **==========================================================
6469 static void ncr_free_nccb (ncb_p np, nccb_p cp)
6472 ** sanity
6475 assert (cp != NULL);
6477 cp -> host_status = HS_IDLE;
6478 cp -> magic = 0;
6481 /*==========================================================
6484 ** Allocation of resources for Targets/Luns/Tags.
6487 **==========================================================
6490 static nccb_p
6491 ncr_alloc_nccb (ncb_p np, u_long target, u_long lun)
6493 tcb_p tp;
6494 lcb_p lp;
6495 nccb_p cp;
6497 assert (np != NULL);
6499 if (target>=MAX_TARGET) return(NULL);
6500 if (lun >=MAX_LUN ) return(NULL);
6502 tp=&np->target[target];
6504 if (!tp->jump_tcb.l_cmd) {
6507 ** initialize it.
6509 tp->jump_tcb.l_cmd = (SCR_JUMP^IFFALSE (DATA (0x80 + target)));
6510 tp->jump_tcb.l_paddr = np->jump_tcb.l_paddr;
6512 tp->getscr[0] =
6513 (np->features & FE_PFEN)? SCR_COPY(1) : SCR_COPY_F(1);
6514 tp->getscr[1] = vtophys (&tp->tinfo.sval);
6515 tp->getscr[2] = rman_get_start(np->reg_res) + offsetof (struct ncr_reg, nc_sxfer);
6516 tp->getscr[3] =
6517 (np->features & FE_PFEN)? SCR_COPY(1) : SCR_COPY_F(1);
6518 tp->getscr[4] = vtophys (&tp->tinfo.wval);
6519 tp->getscr[5] = rman_get_start(np->reg_res) + offsetof (struct ncr_reg, nc_scntl3);
6521 assert (((offsetof(struct ncr_reg, nc_sxfer) ^
6522 (offsetof(struct tcb ,tinfo)
6523 + offsetof(struct ncr_target_tinfo, sval))) & 3) == 0);
6524 assert (((offsetof(struct ncr_reg, nc_scntl3) ^
6525 (offsetof(struct tcb, tinfo)
6526 + offsetof(struct ncr_target_tinfo, wval))) &3) == 0);
6528 tp->call_lun.l_cmd = (SCR_CALL);
6529 tp->call_lun.l_paddr = NCB_SCRIPT_PHYS (np, resel_lun);
6531 tp->jump_lcb.l_cmd = (SCR_JUMP);
6532 tp->jump_lcb.l_paddr = NCB_SCRIPTH_PHYS (np, abort);
6533 np->jump_tcb.l_paddr = vtophys (&tp->jump_tcb);
6537 ** Logic unit control block
6539 lp = tp->lp[lun];
6540 if (!lp) {
6542 ** Allocate a lcb
6544 lp = kmalloc (sizeof (struct lcb), M_DEVBUF, M_WAITOK | M_ZERO);
6547 ** Initialize it
6549 lp->jump_lcb.l_cmd = (SCR_JUMP ^ IFFALSE (DATA (lun)));
6550 lp->jump_lcb.l_paddr = tp->jump_lcb.l_paddr;
6552 lp->call_tag.l_cmd = (SCR_CALL);
6553 lp->call_tag.l_paddr = NCB_SCRIPT_PHYS (np, resel_tag);
6555 lp->jump_nccb.l_cmd = (SCR_JUMP);
6556 lp->jump_nccb.l_paddr = NCB_SCRIPTH_PHYS (np, aborttag);
6558 lp->actlink = 1;
6561 ** Chain into LUN list
6563 tp->jump_lcb.l_paddr = vtophys (&lp->jump_lcb);
6564 tp->lp[lun] = lp;
6569 ** Allocate a nccb
6571 cp = kmalloc (sizeof (struct nccb), M_DEVBUF, M_WAITOK | M_ZERO);
6573 if (DEBUG_FLAGS & DEBUG_ALLOC) {
6574 kprintf ("new nccb @%p.\n", cp);
6578 ** Fill in physical addresses
6581 cp->p_nccb = vtophys (cp);
6584 ** Chain into reselect list
6586 cp->jump_nccb.l_cmd = SCR_JUMP;
6587 cp->jump_nccb.l_paddr = lp->jump_nccb.l_paddr;
6588 lp->jump_nccb.l_paddr = CCB_PHYS (cp, jump_nccb);
6589 cp->call_tmp.l_cmd = SCR_CALL;
6590 cp->call_tmp.l_paddr = NCB_SCRIPT_PHYS (np, resel_tmp);
6593 ** Chain into wakeup list
6595 cp->link_nccb = np->link_nccb;
6596 np->link_nccb = cp;
6599 ** Chain into CCB list
6601 cp->next_nccb = lp->next_nccb;
6602 lp->next_nccb = cp;
6604 return (cp);
6607 /*==========================================================
6610 ** Build Scatter Gather Block
6613 **==========================================================
6615 ** The transfer area may be scattered among
6616 ** several non adjacent physical pages.
6618 ** We may use MAX_SCATTER blocks.
6620 **----------------------------------------------------------
6623 static int ncr_scatter
6624 (struct dsb* phys, vm_offset_t vaddr, vm_size_t datalen)
6626 u_long paddr, pnext;
6628 u_short segment = 0;
6629 u_long segsize, segaddr;
6630 u_long size, csize = 0;
6631 u_long chunk = MAX_SIZE;
6632 int free;
6634 bzero (&phys->data, sizeof (phys->data));
6635 if (!datalen) return (0);
6637 paddr = vtophys (vaddr);
6640 ** insert extra break points at a distance of chunk.
6641 ** We try to reduce the number of interrupts caused
6642 ** by unexpected phase changes due to disconnects.
6643 ** A typical harddisk may disconnect before ANY block.
6644 ** If we wanted to avoid unexpected phase changes at all
6645 ** we had to use a break point every 512 bytes.
6646 ** Of course the number of scatter/gather blocks is
6647 ** limited.
6650 free = MAX_SCATTER - 1;
6652 if (vaddr & PAGE_MASK) free -= datalen / PAGE_SIZE;
6654 if (free>1)
6655 while ((chunk * free >= 2 * datalen) && (chunk>=1024))
6656 chunk /= 2;
6658 if(DEBUG_FLAGS & DEBUG_SCATTER)
6659 kprintf("ncr?:\tscattering virtual=%p size=%d chunk=%d.\n",
6660 (void *) vaddr, (unsigned) datalen, (unsigned) chunk);
6663 ** Build data descriptors.
6665 while (datalen && (segment < MAX_SCATTER)) {
6668 ** this segment is empty
6670 segsize = 0;
6671 segaddr = paddr;
6672 pnext = paddr;
6674 if (!csize) csize = chunk;
6676 while ((datalen) && (paddr == pnext) && (csize)) {
6679 ** continue this segment
6681 pnext = (paddr & (~PAGE_MASK)) + PAGE_SIZE;
6684 ** Compute max size
6687 size = pnext - paddr; /* page size */
6688 if (size > datalen) size = datalen; /* data size */
6689 if (size > csize ) size = csize ; /* chunksize */
6691 segsize += size;
6692 vaddr += size;
6693 csize -= size;
6694 datalen -= size;
6695 paddr = vtophys (vaddr);
6698 if(DEBUG_FLAGS & DEBUG_SCATTER)
6699 kprintf ("\tseg #%d addr=%x size=%d (rest=%d).\n",
6700 segment,
6701 (unsigned) segaddr,
6702 (unsigned) segsize,
6703 (unsigned) datalen);
6705 phys->data[segment].addr = segaddr;
6706 phys->data[segment].size = segsize;
6707 segment++;
6710 if (datalen) {
6711 kprintf("ncr?: scatter/gather failed (residue=%d).\n",
6712 (unsigned) datalen);
6713 return (-1);
6716 return (segment);
6719 /*==========================================================
6722 ** Test the pci bus snoop logic :-(
6724 ** Has to be called with interrupts disabled.
6727 **==========================================================
6730 #ifndef NCR_IOMAPPED
6731 static int ncr_regtest (struct ncb* np)
6733 volatile u_int32_t data;
6735 ** ncr registers may NOT be cached.
6736 ** write 0xffffffff to a read only register area,
6737 ** and try to read it back.
6739 data = 0xffffffff;
6740 OUTL_OFF(offsetof(struct ncr_reg, nc_dstat), data);
6741 data = INL_OFF(offsetof(struct ncr_reg, nc_dstat));
6742 #if 1
6743 if (data == 0xffffffff) {
6744 #else
6745 if ((data & 0xe2f0fffd) != 0x02000080) {
6746 #endif
6747 kprintf ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
6748 (unsigned) data);
6749 return (0x10);
6751 return (0);
6753 #endif
6755 static int ncr_snooptest (struct ncb* np)
6757 u_int32_t ncr_rd, ncr_wr, ncr_bk, host_rd, host_wr, pc;
6758 int i, err=0;
6759 #ifndef NCR_IOMAPPED
6760 err |= ncr_regtest (np);
6761 if (err) return (err);
6762 #endif
6764 ** init
6766 pc = NCB_SCRIPTH_PHYS (np, snooptest);
6767 host_wr = 1;
6768 ncr_wr = 2;
6770 ** Set memory and register.
6772 ncr_cache = host_wr;
6773 OUTL (nc_temp, ncr_wr);
6775 ** Start script (exchange values)
6777 OUTL (nc_dsp, pc);
6779 ** Wait 'til done (with timeout)
6781 for (i=0; i<NCR_SNOOP_TIMEOUT; i++)
6782 if (INB(nc_istat) & (INTF|SIP|DIP))
6783 break;
6785 ** Save termination position.
6787 pc = INL (nc_dsp);
6789 ** Read memory and register.
6791 host_rd = ncr_cache;
6792 ncr_rd = INL (nc_scratcha);
6793 ncr_bk = INL (nc_temp);
6795 ** Reset ncr chip
6797 OUTB (nc_istat, SRST);
6798 DELAY (1000);
6799 OUTB (nc_istat, 0 );
6801 ** check for timeout
6803 if (i>=NCR_SNOOP_TIMEOUT) {
6804 kprintf ("CACHE TEST FAILED: timeout.\n");
6805 return (0x20);
6808 ** Check termination position.
6810 if (pc != NCB_SCRIPTH_PHYS (np, snoopend)+8) {
6811 kprintf ("CACHE TEST FAILED: script execution failed.\n");
6812 kprintf ("start=%08lx, pc=%08lx, end=%08lx\n",
6813 (u_long) NCB_SCRIPTH_PHYS (np, snooptest), (u_long) pc,
6814 (u_long) NCB_SCRIPTH_PHYS (np, snoopend) +8);
6815 return (0x40);
6818 ** Show results.
6820 if (host_wr != ncr_rd) {
6821 kprintf ("CACHE TEST FAILED: host wrote %d, ncr read %d.\n",
6822 (int) host_wr, (int) ncr_rd);
6823 err |= 1;
6825 if (host_rd != ncr_wr) {
6826 kprintf ("CACHE TEST FAILED: ncr wrote %d, host read %d.\n",
6827 (int) ncr_wr, (int) host_rd);
6828 err |= 2;
6830 if (ncr_bk != ncr_wr) {
6831 kprintf ("CACHE TEST FAILED: ncr wrote %d, read back %d.\n",
6832 (int) ncr_wr, (int) ncr_bk);
6833 err |= 4;
6835 return (err);
6838 /*==========================================================
6841 ** Profiling the drivers and targets performance.
6844 **==========================================================
6848 ** Compute the difference in milliseconds.
6851 static int ncr_delta (int *from, int *to)
6853 if (!from) return (-1);
6854 if (!to) return (-2);
6855 return ((to - from) * 1000 / hz);
6858 #define PROFILE cp->phys.header.stamp
6859 static void ncb_profile (ncb_p np, nccb_p cp)
6861 int co, da, st, en, di, se, post,work,disc;
6862 u_long diff;
6864 PROFILE.end = ticks;
6866 st = ncr_delta (&PROFILE.start,&PROFILE.status);
6867 if (st<0) return; /* status not reached */
6869 da = ncr_delta (&PROFILE.start,&PROFILE.data);
6870 if (da<0) return; /* No data transfer phase */
6872 co = ncr_delta (&PROFILE.start,&PROFILE.command);
6873 if (co<0) return; /* command not executed */
6875 en = ncr_delta (&PROFILE.start,&PROFILE.end),
6876 di = ncr_delta (&PROFILE.start,&PROFILE.disconnect),
6877 se = ncr_delta (&PROFILE.start,&PROFILE.select);
6878 post = en - st;
6881 ** @PROFILE@ Disconnect time invalid if multiple disconnects
6884 if (di>=0) disc = se-di; else disc = 0;
6886 work = (st - co) - disc;
6888 diff = (np->disc_phys - np->disc_ref) & 0xff;
6889 np->disc_ref += diff;
6891 np->profile.num_trans += 1;
6892 if (cp->ccb)
6893 np->profile.num_bytes += cp->ccb->csio.dxfer_len;
6894 np->profile.num_disc += diff;
6895 np->profile.ms_setup += co;
6896 np->profile.ms_data += work;
6897 np->profile.ms_disc += disc;
6898 np->profile.ms_post += post;
6900 #undef PROFILE
6902 /*==========================================================
6904 ** Determine the ncr's clock frequency.
6905 ** This is essential for the negotiation
6906 ** of the synchronous transfer rate.
6908 **==========================================================
6910 ** Note: we have to return the correct value.
6911 ** THERE IS NO SAVE DEFAULT VALUE.
6913 ** Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
6914 ** 53C860 and 53C875 rev. 1 support fast20 transfers but
6915 ** do not have a clock doubler and so are provided with a
6916 ** 80 MHz clock. All other fast20 boards incorporate a doubler
6917 ** and so should be delivered with a 40 MHz clock.
6918 ** The future fast40 chips (895/895) use a 40 Mhz base clock
6919 ** and provide a clock quadrupler (160 Mhz). The code below
6920 ** tries to deal as cleverly as possible with all this stuff.
6922 **----------------------------------------------------------
6926 * Select NCR SCSI clock frequency
6928 static void ncr_selectclock(ncb_p np, u_char scntl3)
6930 if (np->multiplier < 2) {
6931 OUTB(nc_scntl3, scntl3);
6932 return;
6935 if (bootverbose >= 2)
6936 kprintf ("%s: enabling clock multiplier\n", ncr_name(np));
6938 OUTB(nc_stest1, DBLEN); /* Enable clock multiplier */
6939 if (np->multiplier > 2) { /* Poll bit 5 of stest4 for quadrupler */
6940 int i = 20;
6941 while (!(INB(nc_stest4) & LCKFRQ) && --i > 0)
6942 DELAY(20);
6943 if (!i)
6944 kprintf("%s: the chip cannot lock the frequency\n", ncr_name(np));
6945 } else /* Wait 20 micro-seconds for doubler */
6946 DELAY(20);
6947 OUTB(nc_stest3, HSC); /* Halt the scsi clock */
6948 OUTB(nc_scntl3, scntl3);
6949 OUTB(nc_stest1, (DBLEN|DBLSEL));/* Select clock multiplier */
6950 OUTB(nc_stest3, 0x00); /* Restart scsi clock */
6954 * calculate NCR SCSI clock frequency (in KHz)
6956 static unsigned
6957 ncrgetfreq (ncb_p np, int gen)
6959 int ms = 0;
6961 * Measure GEN timer delay in order
6962 * to calculate SCSI clock frequency
6964 * This code will never execute too
6965 * many loop iterations (if DELAY is
6966 * reasonably correct). It could get
6967 * too low a delay (too high a freq.)
6968 * if the CPU is slow executing the
6969 * loop for some reason (an NMI, for
6970 * example). For this reason we will
6971 * if multiple measurements are to be
6972 * performed trust the higher delay
6973 * (lower frequency returned).
6975 OUTB (nc_stest1, 0); /* make sure clock doubler is OFF */
6976 OUTW (nc_sien , 0); /* mask all scsi interrupts */
6977 (void) INW (nc_sist); /* clear pending scsi interrupt */
6978 OUTB (nc_dien , 0); /* mask all dma interrupts */
6979 (void) INW (nc_sist); /* another one, just to be sure :) */
6980 OUTB (nc_scntl3, 4); /* set pre-scaler to divide by 3 */
6981 OUTB (nc_stime1, 0); /* disable general purpose timer */
6982 OUTB (nc_stime1, gen); /* set to nominal delay of (1<<gen) * 125us */
6983 while (!(INW(nc_sist) & GEN) && ms++ < 1000)
6984 DELAY(1000); /* count ms */
6985 OUTB (nc_stime1, 0); /* disable general purpose timer */
6986 OUTB (nc_scntl3, 0);
6988 * Set prescaler to divide by whatever "0" means.
6989 * "0" ought to choose divide by 2, but appears
6990 * to set divide by 3.5 mode in my 53c810 ...
6992 OUTB (nc_scntl3, 0);
6994 if (bootverbose >= 2)
6995 kprintf ("\tDelay (GEN=%d): %u msec\n", gen, ms);
6997 * adjust for prescaler, and convert into KHz
6999 return ms ? ((1 << gen) * 4440) / ms : 0;
7002 static void ncr_getclock (ncb_p np, u_char multiplier)
7004 unsigned char scntl3;
7005 unsigned char stest1;
7006 scntl3 = INB(nc_scntl3);
7007 stest1 = INB(nc_stest1);
7009 np->multiplier = 1;
7011 if (multiplier > 1) {
7012 np->multiplier = multiplier;
7013 np->clock_khz = 40000 * multiplier;
7014 } else {
7015 if ((scntl3 & 7) == 0) {
7016 unsigned f1, f2;
7017 /* throw away first result */
7018 (void) ncrgetfreq (np, 11);
7019 f1 = ncrgetfreq (np, 11);
7020 f2 = ncrgetfreq (np, 11);
7022 if (bootverbose >= 2)
7023 kprintf ("\tNCR clock is %uKHz, %uKHz\n", f1, f2);
7024 if (f1 > f2) f1 = f2; /* trust lower result */
7025 if (f1 > 45000) {
7026 scntl3 = 5; /* >45Mhz: assume 80MHz */
7027 } else {
7028 scntl3 = 3; /* <45Mhz: assume 40MHz */
7031 else if ((scntl3 & 7) == 5)
7032 np->clock_khz = 80000; /* Probably a 875 rev. 1 ? */
7036 /*=========================================================================*/
7038 #ifdef NCR_TEKRAM_EEPROM
7040 struct tekram_eeprom_dev {
7041 u_char devmode;
7042 #define TKR_PARCHK 0x01
7043 #define TKR_TRYSYNC 0x02
7044 #define TKR_ENDISC 0x04
7045 #define TKR_STARTUNIT 0x08
7046 #define TKR_USETAGS 0x10
7047 #define TKR_TRYWIDE 0x20
7048 u_char syncparam; /* max. sync transfer rate (table ?) */
7049 u_char filler1;
7050 u_char filler2;
7054 struct tekram_eeprom {
7055 struct tekram_eeprom_dev
7056 dev[16];
7057 u_char adaptid;
7058 u_char adaptmode;
7059 #define TKR_ADPT_GT2DRV 0x01
7060 #define TKR_ADPT_GT1GB 0x02
7061 #define TKR_ADPT_RSTBUS 0x04
7062 #define TKR_ADPT_ACTNEG 0x08
7063 #define TKR_ADPT_NOSEEK 0x10
7064 #define TKR_ADPT_MORLUN 0x20
7065 u_char delay; /* unit ? ( table ??? ) */
7066 u_char tags; /* use 4 times as many ... */
7067 u_char filler[60];
7070 static void
7071 tekram_write_bit (ncb_p np, int bit)
7073 u_char val = 0x10 + ((bit & 1) << 1);
7075 DELAY(10);
7076 OUTB (nc_gpreg, val);
7077 DELAY(10);
7078 OUTB (nc_gpreg, val | 0x04);
7079 DELAY(10);
7080 OUTB (nc_gpreg, val);
7081 DELAY(10);
7084 static int
7085 tekram_read_bit (ncb_p np)
7087 OUTB (nc_gpreg, 0x10);
7088 DELAY(10);
7089 OUTB (nc_gpreg, 0x14);
7090 DELAY(10);
7091 return INB (nc_gpreg) & 1;
7094 static u_short
7095 read_tekram_eeprom_reg (ncb_p np, int reg)
7097 int bit;
7098 u_short result = 0;
7099 int cmd = 0x80 | reg;
7101 OUTB (nc_gpreg, 0x10);
7103 tekram_write_bit (np, 1);
7104 for (bit = 7; bit >= 0; bit--)
7106 tekram_write_bit (np, cmd >> bit);
7109 for (bit = 0; bit < 16; bit++)
7111 result <<= 1;
7112 result |= tekram_read_bit (np);
7115 OUTB (nc_gpreg, 0x00);
7116 return result;
7119 static int
7120 read_tekram_eeprom(ncb_p np, struct tekram_eeprom *buffer)
7122 u_short *p = (u_short *) buffer;
7123 u_short sum = 0;
7124 int i;
7126 if (INB (nc_gpcntl) != 0x09)
7128 return 0;
7130 for (i = 0; i < 64; i++)
7132 u_short val;
7133 if((i&0x0f) == 0) kprintf ("%02x:", i*2);
7134 val = read_tekram_eeprom_reg (np, i);
7135 if (p)
7136 *p++ = val;
7137 sum += val;
7138 if((i&0x01) == 0x00) kprintf (" ");
7139 kprintf ("%02x%02x", val & 0xff, (val >> 8) & 0xff);
7140 if((i&0x0f) == 0x0f) kprintf ("\n");
7142 kprintf ("Sum = %04x\n", sum);
7143 return sum == 0x1234;
7145 #endif /* NCR_TEKRAM_EEPROM */
7147 static device_method_t ncr_methods[] = {
7148 /* Device interface */
7149 DEVMETHOD(device_probe, ncr_probe),
7150 DEVMETHOD(device_attach, ncr_attach),
7152 DEVMETHOD_END
7155 static driver_t ncr_driver = {
7156 "ncr",
7157 ncr_methods,
7158 sizeof(struct ncb),
7161 static devclass_t ncr_devclass;
7163 DRIVER_MODULE(if_ncr, pci, ncr_driver, ncr_devclass, NULL, NULL);
7165 /*=========================================================================*/
7166 #endif /* _KERNEL */