1 /******************************************************************************
2 ** High Performance device driver for the Symbios 53C896 controller.
4 ** Copyright (C) 1998 Gerard Roudier <groudier@club-internet.fr>
6 ** This driver also supports all the Symbios 53C8XX controller family,
7 ** except 53C810 revisions < 16, 53C825 revisions < 16 and all
8 ** revisions of 53C815 controllers.
10 ** This driver is based on the Linux port of the FreeBSD ncr driver.
12 ** Copyright (C) 1994 Wolfgang Stanglmeier
14 **-----------------------------------------------------------------------------
16 ** This program is free software; you can redistribute it and/or modify
17 ** it under the terms of the GNU General Public License as published by
18 ** the Free Software Foundation; either version 2 of the License, or
19 ** (at your option) any later version.
21 ** This program is distributed in the hope that it will be useful,
22 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ** GNU General Public License for more details.
26 ** You should have received a copy of the GNU General Public License
27 ** along with this program; if not, write to the Free Software
28 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 **-----------------------------------------------------------------------------
32 ** The Linux port of the FreeBSD ncr driver has been achieved in
35 ** Gerard Roudier <groudier@club-internet.fr>
37 ** Being given that this driver originates from the FreeBSD version, and
38 ** in order to keep synergy on both, any suggested enhancements and corrections
39 ** received on Linux are automatically a potential candidate for the FreeBSD
42 ** The original driver has been written for 386bsd and FreeBSD by
43 ** Wolfgang Stanglmeier <wolf@cologne.de>
44 ** Stefan Esser <se@mi.Uni-Koeln.de>
46 **-----------------------------------------------------------------------------
48 ** Major contributions:
49 ** --------------------
51 ** NVRAM detection and reading.
52 ** Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
54 *******************************************************************************
58 ** April 2 1999, sym53c8xx version 1.3c
60 ** Supported SCSI features:
61 ** Synchronous data transfers
63 ** Disconnection/Reselection
64 ** Tagged command queuing
65 ** SCSI Parity checking
67 ** Supported NCR chips:
68 ** 53C810A (8 bits, Fast 10, no rom BIOS)
69 ** 53C825A (Wide, Fast 10, on-board rom BIOS)
70 ** 53C860 (8 bits, Fast 20, no rom BIOS)
71 ** 53C875 (Wide, Fast 20, on-board rom BIOS)
72 ** 53C876 (Wide, Fast 20 Dual, on-board rom BIOS)
73 ** 53C895 (Wide, Fast 40, on-board rom BIOS)
74 ** 53C896 (Wide, Fast 40 Dual, on-board rom BIOS)
83 ** Name and version of the driver
85 #define SCSI_NCR_DRIVER_NAME "sym53c8xx - version 1.3c"
87 /* #define DEBUG_896R1 */
88 #define SCSI_NCR_OPTIMIZE_896
89 /* #define SCSI_NCR_OPTIMIZE_896_1 */
91 #define SCSI_NCR_DEBUG_FLAGS (0)
93 #define NAME53C "sym53c"
94 #define NAME53C8XX "sym53c8xx"
96 /*==========================================================
100 **==========================================================
103 #define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))
106 #include <linux/module.h>
111 #include <asm/system.h>
112 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93)
113 #include <linux/spinlock.h>
115 #include <linux/delay.h>
116 #include <linux/signal.h>
117 #include <linux/sched.h>
118 #include <linux/errno.h>
119 #include <linux/pci.h>
120 #include <linux/string.h>
121 #include <linux/malloc.h>
122 #include <linux/mm.h>
123 #include <linux/ioport.h>
124 #include <linux/time.h>
125 #include <linux/timer.h>
126 #include <linux/stat.h>
128 #include <linux/version.h>
129 #include <linux/blk.h>
131 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,35)
132 #include <linux/init.h>
142 #if LINUX_VERSION_CODE <= LinuxVersionCode(2,1,92)
143 #include <linux/bios32.h>
148 #include "constants.h"
151 #include <linux/types.h>
154 ** Define BITS_PER_LONG for earlier linux versions.
156 #ifndef BITS_PER_LONG
157 #if (~0UL) == 0xffffffffUL
158 #define BITS_PER_LONG 32
160 #define BITS_PER_LONG 64
165 ** Define the BSD style u_int32 and u_int64 type.
166 ** Are in fact u_int32_t and u_int64_t :-)
171 #include "sym53c8xx.h"
173 /*==========================================================
175 ** A la VMS/CAM-3 queue management.
176 ** Implemented from linux list management.
178 **==========================================================
181 typedef struct xpt_quehead
{
182 struct xpt_quehead
*flink
; /* Forward pointer */
183 struct xpt_quehead
*blink
; /* Backward pointer */
186 #define xpt_que_init(ptr) do { \
187 (ptr)->flink = (ptr); (ptr)->blink = (ptr); \
190 static inline void __xpt_que_add(struct xpt_quehead
* new,
191 struct xpt_quehead
* blink
,
192 struct xpt_quehead
* flink
)
200 static inline void __xpt_que_del(struct xpt_quehead
* blink
,
201 struct xpt_quehead
* flink
)
203 flink
->blink
= blink
;
204 blink
->flink
= flink
;
207 static inline int xpt_que_empty(struct xpt_quehead
*head
)
209 return head
->flink
== head
;
212 static inline void xpt_que_splice(struct xpt_quehead
*list
,
213 struct xpt_quehead
*head
)
215 struct xpt_quehead
*first
= list
->flink
;
218 struct xpt_quehead
*last
= list
->blink
;
219 struct xpt_quehead
*at
= head
->flink
;
229 #define xpt_que_entry(ptr, type, member) \
230 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
233 #define xpt_insque(new, pos) __xpt_que_add(new, pos, (pos)->flink)
235 #define xpt_remque(el) __xpt_que_del((el)->blink, (el)->flink)
237 #define xpt_insque_head(new, head) __xpt_que_add(new, head, (head)->flink)
239 static inline struct xpt_quehead
*xpt_remque_head(struct xpt_quehead
*head
)
241 struct xpt_quehead
*elem
= head
->flink
;
244 __xpt_que_del(head
, elem
->flink
);
250 #define xpt_insque_tail(new, head) __xpt_que_add(new, (head)->blink, head)
252 static inline struct xpt_quehead
*xpt_remque_tail(struct xpt_quehead
*head
)
254 struct xpt_quehead
*elem
= head
->blink
;
257 __xpt_que_del(elem
->blink
, head
);
263 /*==========================================================
265 ** On x86 architecture, write buffers management does
266 ** not reorder writes to memory. So, using compiler
267 ** optimization barriers is enough to guarantee some
268 ** ordering when the CPU is writing data accessed by
270 ** On Alpha architecture, explicit memory barriers have
272 ** Other architectures are defaulted to mb() macro if
273 ** defined, otherwise use compiler barrier.
275 **==========================================================
278 #if defined(__i386__)
279 #define MEMORY_BARRIER() barrier()
280 #elif defined(__alpha__)
281 #define MEMORY_BARRIER() mb()
284 # define MEMORY_BARRIER() mb()
286 # define MEMORY_BARRIER() barrier()
290 /*==========================================================
292 ** Configuration and Debugging
294 **==========================================================
298 ** SCSI address of this device.
299 ** The boot routines should have set it.
303 #ifndef SCSI_NCR_MYADDR
304 #define SCSI_NCR_MYADDR (7)
308 ** The maximum number of tags per logic unit.
309 ** Used only for devices that support tags.
312 #ifndef SCSI_NCR_MAX_TAGS
313 #define SCSI_NCR_MAX_TAGS (8)
317 ** TAGS are actually limited to 64 tags/lun.
318 ** We need to deal with power of 2, for alignment constraints.
320 #if SCSI_NCR_MAX_TAGS > 64
321 #undef SCSI_NCR_MAX_TAGS
322 #define SCSI_NCR_MAX_TAGS (64)
328 ** Choose appropriate type for tag bitmap.
330 #if SCSI_NCR_MAX_TAGS > 32
331 typedef u_int64 tagmap_t
;
333 typedef u_int32 tagmap_t
;
337 ** Number of targets supported by the driver.
338 ** n permits target numbers 0..n-1.
339 ** Default is 16, meaning targets #0..#15.
343 #ifdef SCSI_NCR_MAX_TARGET
344 #define MAX_TARGET (SCSI_NCR_MAX_TARGET)
346 #define MAX_TARGET (16)
350 ** Number of logic units supported by the driver.
351 ** n enables logic unit numbers 0..n-1.
352 ** The common SCSI devices require only
353 ** one lun, so take 1 as the default.
356 #ifdef SCSI_NCR_MAX_LUN
357 #define MAX_LUN SCSI_NCR_MAX_LUN
363 ** Asynchronous pre-scaler (ns). Shall be 40 for
364 ** the SCSI timings to be compliant.
367 #ifndef SCSI_NCR_MIN_ASYNC
368 #define SCSI_NCR_MIN_ASYNC (40)
372 ** The maximum number of jobs scheduled for starting.
373 ** We allocate 4 entries more than the value we announce
374 ** to the SCSI upper layer. Guess why ! :-)
377 #ifdef SCSI_NCR_CAN_QUEUE
378 #define MAX_START (SCSI_NCR_CAN_QUEUE + 4)
380 #define MAX_START (MAX_TARGET + 7 * SCSI_NCR_MAX_TAGS)
384 ** The maximum number of segments a transfer is split into.
385 ** We support up to 127 segments for both read and write.
386 ** Since we try to avoid phase mismatches by testing the PHASE
387 ** before each MOV, the both DATA_IN and DATA_OUT scripts do
388 ** not fit in the 4K on-chip RAM. For this reason, the data
389 ** scripts are broken into 2 sub-scripts.
390 ** 80 (MAX_SCATTERL) segments are moved from a sub-script
391 ** in on-chip RAM. This makes data transfers shorter than
392 ** 80k (assuming 1k fs) as fast as possible.
393 ** The 896 allows to handle phase mismatches from SCRIPTS.
394 ** So, for this chip, we use a simple array of MOV's.
395 ** Perhaps, using a simple array of MOV's and going with
396 ** the phase mismatch interrupt is also the best solution
397 ** for the 895 in Ultra2-mode, since the PHASE test + MOV
398 ** latency may be enough to fill the SCSI offset for very
399 ** fast disks like the Cheatah Wide LVD and so, may waste
400 ** SCSI BUS bandwitch.
403 #define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)
405 #ifdef SCSI_NCR_OPTIMIZE_896
406 #define SCR_SG_SIZE (2)
407 #define MAX_SCATTERL MAX_SCATTER
408 #define MAX_SCATTERH 0
410 #if (MAX_SCATTER > 80)
411 #define SCR_SG_SIZE (4)
412 #define MAX_SCATTERL 80
413 #define MAX_SCATTERH (MAX_SCATTER - MAX_SCATTERL)
415 #define MAX_SCATTERL MAX_SCATTER
416 #define MAX_SCATTERH 0
418 #endif /* SCSI_NCR_OPTIMIZE_896 */
421 ** Io mapped or memory mapped.
424 #if defined(SCSI_NCR_IOMAPPED)
432 #define NCR_SNOOP_TIMEOUT (1000000)
434 /*==========================================================
436 ** Miscallaneous BSDish defines.
438 **==========================================================
441 #define u_char unsigned char
442 #define u_short unsigned short
443 #define u_int unsigned int
444 #define u_long unsigned long
447 #define bcopy(s, d, n) memcpy((d), (s), (n))
451 #define bzero(d, n) memset((d), 0, (n))
455 #define offsetof(t, m) ((size_t) (&((t *)0)->m))
458 /*==========================================================
462 **==========================================================
465 #define DEBUG_ALLOC (0x0001)
466 #define DEBUG_PHASE (0x0002)
467 #define DEBUG_POLL (0x0004)
468 #define DEBUG_QUEUE (0x0008)
469 #define DEBUG_RESULT (0x0010)
470 #define DEBUG_SCATTER (0x0020)
471 #define DEBUG_SCRIPT (0x0040)
472 #define DEBUG_TINY (0x0080)
473 #define DEBUG_TIMING (0x0100)
474 #define DEBUG_NEGO (0x0200)
475 #define DEBUG_TAGS (0x0400)
476 #define DEBUG_FREEZE (0x0800)
477 #define DEBUG_RESTART (0x1000)
480 ** Enable/Disable debug messages.
481 ** Can be changed at runtime too.
484 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
485 static int ncr_debug
= SCSI_NCR_DEBUG_FLAGS
;
486 #define DEBUG_FLAGS ncr_debug
488 #define DEBUG_FLAGS SCSI_NCR_DEBUG_FLAGS
494 ** Assuming that SMP systems are generally high end systems and may
495 ** use several SCSI adapters, we are using one lock per controller
496 ** instead of some global one. For the moment (linux-2.1.95), driver's
497 ** entry points are called with the 'io_request_lock' lock held, so:
498 ** - We are uselessly loosing a couple of micro-seconds to lock the
499 ** controller data structure.
500 ** - But the driver is not broken by design for SMP and so can be
501 ** more resistant to bugs or bad changes in the IO sub-system code.
502 ** - A small advantage could be that the interrupt code is grained as
503 ** wished (e.g.: threaded by controller).
506 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93)
508 spinlock_t sym53c8xx_lock
;
509 #define NCR_LOCK_DRIVER(flags) spin_lock_irqsave(&sym53c8xx_lock, flags)
510 #define NCR_UNLOCK_DRIVER(flags) spin_unlock_irqrestore(&sym53c8xx_lock,flags)
512 #define NCR_INIT_LOCK_NCB(np) spin_lock_init(&np->smp_lock);
513 #define NCR_LOCK_NCB(np, flags) spin_lock_irqsave(&np->smp_lock, flags)
514 #define NCR_UNLOCK_NCB(np, flags) spin_unlock_irqrestore(&np->smp_lock, flags)
516 # if LINUX_VERSION_CODE < LinuxVersionCode(2,3,99)
518 # define NCR_LOCK_SCSI_DONE(np, flags) \
519 spin_lock_irqsave(&io_request_lock, flags)
520 # define NCR_UNLOCK_SCSI_DONE(np, flags) \
521 spin_unlock_irqrestore(&io_request_lock, flags)
525 # define NCR_LOCK_SCSI_DONE(np, flags) do {;} while (0)
526 # define NCR_UNLOCK_SCSI_DONE(np, flags) do {;} while (0)
532 #define NCR_LOCK_DRIVER(flags) do { save_flags(flags); cli(); } while (0)
533 #define NCR_UNLOCK_DRIVER(flags) do { restore_flags(flags); } while (0)
535 #define NCR_INIT_LOCK_NCB(np) do { } while (0)
536 #define NCR_LOCK_NCB(np, flags) do { save_flags(flags); cli(); } while (0)
537 #define NCR_UNLOCK_NCB(np, flags) do { restore_flags(flags); } while (0)
539 #define NCR_LOCK_SCSI_DONE(np, flags) do {;} while (0)
540 #define NCR_UNLOCK_SCSI_DONE(np, flags) do {;} while (0)
545 ** Address translation
547 ** The driver has to provide bus memory addresses to
548 ** the script processor. Because some architectures use
549 ** different physical addressing scheme from the PCI BUS,
550 ** we use virt_to_bus() instead of virt_to_phys().
553 #define vtobus(p) virt_to_bus(p)
558 ** Since linux-2.1, we must use ioremap() to map the io memory space.
559 ** iounmap() to unmap it. That allows portability.
560 ** Linux 1.3.X and 2.0.X allow to remap physical pages addresses greater
561 ** than the highest physical memory address to kernel virtual pages with
562 ** vremap() / vfree(). That was not portable but worked with i386
566 #if LINUX_VERSION_CODE < LinuxVersionCode(2,1,0)
567 #define ioremap vremap
568 #define iounmap vfree
572 #define pcivtobus(p) ((p) & pci_dvma_mask)
573 #else /* __sparc__ */
574 #define pcivtobus(p) (p)
577 #if !defined(NCR_IOMAPPED) || defined(__i386__)
578 static u_long __init
remap_pci_mem(u_long base
, u_long size
)
580 u_long page_base
= ((u_long
) base
) & PAGE_MASK
;
581 u_long page_offs
= ((u_long
) base
) - page_base
;
582 u_long page_remapped
= (u_long
) ioremap(page_base
, page_offs
+size
);
584 return page_remapped
? (page_remapped
+ page_offs
) : 0UL;
587 static void __init
unmap_pci_mem(u_long vaddr
, u_long size
)
590 iounmap((void *) (vaddr
& PAGE_MASK
));
592 #endif /* !NCR_IOMAPPED || __i386__ */
595 ** Insert a delay in micro-seconds and milli-seconds.
596 ** -------------------------------------------------
597 ** Under Linux, udelay() is restricted to delay < 1 milli-second.
598 ** In fact, it generally works for up to 1 second delay.
599 ** Since 2.1.105, the mdelay() function is provided for delays
601 ** Under 2.0 kernels, udelay() is an inline function that is very
602 ** inaccurate on Pentium processors.
605 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,105)
606 #define UDELAY udelay
607 #define MDELAY mdelay
609 static void UDELAY(long us
) { udelay(us
); }
610 static void MDELAY(long ms
) { while (ms
--) UDELAY(1000); }
614 ** Simple power of two buddy-like allocator
615 ** ----------------------------------------
616 ** This simple code is not intended to be fast, but to provide
617 ** power of 2 aligned memory allocations.
618 ** Since the SCRIPTS processor only supplies 8 bit arithmetic,
619 ** this allocator allows simple and fast address calculations
620 ** from the SCRIPTS code. In addition, cache line alignment
621 ** is guaranteed for power of 2 cache line size.
624 #define MEMO_SHIFT 4 /* 16 bytes minimum memory chunk */
625 #define MEMO_PAGE_ORDER 0 /* 1 PAGE maximum (for now (ever?) */
626 typedef unsigned long addr
; /* Enough bits to bit-hack addresses */
628 #define MEMO_FREE_UNUSED /* Free unused pages immediately */
631 struct m_link
*next
; /* Simple links are enough */
634 #ifndef GFP_DMA_32BIT
635 #define GFP_DMA_32BIT 0 /* Will this flag ever exist */
638 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,0)
639 #define get_pages(order) __get_free_pages(GFP_ATOMIC | GFP_DMA_32BIT, order)
641 #define get_pages(order) __get_free_pages(GFP_ATOMIC | GFP_DMA_32BIT, order, 0)
645 ** Lists of available memory chunks.
646 ** Starts with 16 bytes chunks until 1 PAGE chunks.
648 static struct m_link h
[PAGE_SHIFT
-MEMO_SHIFT
+MEMO_PAGE_ORDER
+1];
651 ** Allocate a memory area aligned on the lowest power of 2
652 ** greater than the requested size.
654 static void *__m_alloc(int size
)
657 int s
= (1 << MEMO_SHIFT
);
661 if (size
> (PAGE_SIZE
<< MEMO_PAGE_ORDER
))
671 if (s
== (PAGE_SIZE
<< MEMO_PAGE_ORDER
)) {
672 h
[j
].next
= (struct m_link
*)get_pages(MEMO_PAGE_ORDER
);
680 a
= (addr
) h
[j
].next
;
682 h
[j
].next
= h
[j
].next
->next
;
686 h
[j
].next
= (struct m_link
*) (a
+s
);
691 printk("m_alloc(%d) = %p\n", size
, (void *) a
);
697 ** Free a memory area allocated using m_alloc().
699 ** Free pages that become unused if MEMO_FREE_UNUSED is defined.
701 static void __m_free(void *ptr
, int size
)
704 int s
= (1 << MEMO_SHIFT
);
709 printk("m_free(%p, %d)\n", ptr
, size
);
712 if (size
> (PAGE_SIZE
<< MEMO_PAGE_ORDER
))
723 #ifdef MEMO_FREE_UNUSED
724 if (s
== (PAGE_SIZE
<< MEMO_PAGE_ORDER
)) {
725 free_pages(a
, MEMO_PAGE_ORDER
);
731 while (q
->next
&& q
->next
!= (struct m_link
*) b
) {
735 ((struct m_link
*) a
)->next
= h
[i
].next
;
736 h
[i
].next
= (struct m_link
*) a
;
739 q
->next
= q
->next
->next
;
749 ** The memory pool is shared by all instances.
750 ** We use a global SMP LOCK to be SMP safe.
753 static void *m_calloc(int size
, char *name
, int uflags
)
758 NCR_LOCK_DRIVER(flags
);
760 NCR_UNLOCK_DRIVER(flags
);
762 if (DEBUG_FLAGS
& DEBUG_ALLOC
)
763 printk ("new %s[%d] @%p.\n", name
, size
, p
);
767 else if (uflags
& MEMO_WARN
)
768 printk (NAME53C8XX
": failed to allocate %s[%d]\n", name
, size
);
773 static void m_free(void *ptr
, int size
, char *name
)
777 if (DEBUG_FLAGS
& DEBUG_ALLOC
)
778 printk ("freeing %s[%d] @%p.\n", name
, size
, ptr
);
780 NCR_LOCK_DRIVER(flags
);
782 NCR_UNLOCK_DRIVER(flags
);
786 ** Transfer direction
788 ** Low-level scsi drivers under Linux do not receive the expected
789 ** data transfer direction from upper scsi drivers.
790 ** The driver will only check actual data direction for common
791 ** scsi opcodes. Other ones may cause problem, since they may
792 ** depend on device type or be vendor specific.
793 ** I would prefer to never trust the device for data direction,
794 ** but that is not possible.
796 ** The original driver requires the expected direction to be known.
797 ** The Linux version of the driver has been enhanced in order to
798 ** be able to transfer data in the direction choosen by the target.
805 ** Head of list of NCR boards
807 ** For kernel version < 1.3.70, host is retrieved by its irq level.
808 ** For later kernels, the internal host control block address
809 ** (struct ncb) is used as device id parameter of the irq stuff.
812 static struct Scsi_Host
*first_host
= NULL
;
816 ** /proc directory entry and proc_info function
819 static struct proc_dir_entry proc_scsi_sym53c8xx
= {
820 PROC_SCSI_SYM53C8XX
, 9, NAME53C8XX
,
821 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
823 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
824 static int sym53c8xx_proc_info(char *buffer
, char **start
, off_t offset
,
825 int length
, int hostno
, int func
);
831 ** This structure is initialized from linux config options.
832 ** It can be overridden at boot-up by the boot command line.
834 #define SCSI_NCR_MAX_EXCLUDES 8
835 struct ncr_driver_setup
{
836 u_char master_parity
;
838 u_char disconnection
;
839 u_char special_features
;
841 u_char force_sync_nego
;
842 u_char reverse_probe
;
847 u_short default_sync
;
858 u_int excludes
[SCSI_NCR_MAX_EXCLUDES
];
862 static struct ncr_driver_setup
863 driver_setup
= SCSI_NCR_DRIVER_SETUP
;
865 #ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
866 static struct ncr_driver_setup
867 driver_safe_setup __initdata
= SCSI_NCR_DRIVER_SAFE_SETUP
;
869 char *sym53c8xx
= 0; /* command line passed by insmod */
870 # if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,30)
871 MODULE_PARM(sym53c8xx
, "s");
877 ** Other Linux definitions
879 #define SetScsiResult(cmd, h_sts, s_sts) \
880 cmd->result = (((h_sts) << 16) + ((s_sts) & 0x7f))
882 static void sym53c8xx_select_queue_depths(
883 struct Scsi_Host
*host
, struct scsi_device
*devlist
);
884 static void sym53c8xx_intr(int irq
, void *dev_id
, struct pt_regs
* regs
);
885 static void sym53c8xx_timeout(unsigned long np
);
887 #define initverbose (driver_setup.verbose)
888 #define bootverbose (np->verbose)
890 #ifdef SCSI_NCR_NVRAM_SUPPORT
892 ** Symbios NvRAM data format
894 #define SYMBIOS_NVRAM_SIZE 368
895 #define SYMBIOS_NVRAM_ADDRESS 0x100
897 struct Symbios_nvram
{
899 u_short type
; /* 0x0000 */
900 u_short byte_count
; /* excluding header/trailer */
903 /* Controller set up 20 bytes */
904 u_char v_major
; /* 0x00 */
905 u_char v_minor
; /* 0x30 */
908 #define SYMBIOS_SCAM_ENABLE (1)
909 #define SYMBIOS_PARITY_ENABLE (1<<1)
910 #define SYMBIOS_VERBOSE_MSGS (1<<2)
911 #define SYMBIOS_CHS_MAPPING (1<<3)
912 #define SYMBIOS_NO_NVRAM (1<<3) /* ??? */
914 #define SYMBIOS_SCAN_HI_LO (1)
916 #define SYMBIOS_TERM_CANT_PROGRAM (0)
917 #define SYMBIOS_TERM_ENABLED (1)
918 #define SYMBIOS_TERM_DISABLED (2)
920 #define SYMBIOS_RMVBL_NO_SUPPORT (0)
921 #define SYMBIOS_RMVBL_BOOT_DEVICE (1)
922 #define SYMBIOS_RMVBL_MEDIA_INSTALLED (2)
924 u_char num_hba
; /* 0x04 */
925 u_char num_devices
; /* 0x10 */
926 u_char max_scam_devices
; /* 0x04 */
927 u_char num_valid_scam_devives
; /* 0x00 */
930 /* Boot order 14 bytes * 4 */
932 u_short type
; /* 4:8xx / 0:nok */
933 u_short device_id
; /* PCI device id */
934 u_short vendor_id
; /* PCI vendor id */
935 u_char bus_nr
; /* PCI bus number */
936 u_char device_fn
; /* PCI device/function number << 3*/
939 #define SYMBIOS_INIT_SCAN_AT_BOOT (1)
940 u_short io_port
; /* PCI io_port address */
943 /* Targets 8 bytes * 16 */
944 struct Symbios_target
{
946 #define SYMBIOS_DISCONNECT_ENABLE (1)
947 #define SYMBIOS_SCAN_AT_BOOT_TIME (1<<1)
948 #define SYMBIOS_SCAN_LUNS (1<<2)
949 #define SYMBIOS_QUEUE_TAGS_ENABLED (1<<3)
951 u_char bus_width
; /* 0x08/0x10 */
953 u_short sync_period
; /* 4*period factor */
956 /* Scam table 8 bytes * 4 */
957 struct Symbios_scam
{
960 #define SYMBIOS_SCAM_DEFAULT_METHOD (0)
961 #define SYMBIOS_SCAM_DONT_ASSIGN (1)
962 #define SYMBIOS_SCAM_SET_SPECIFIC_ID (2)
963 #define SYMBIOS_SCAM_USE_ORDER_GIVEN (3)
965 #define SYMBIOS_SCAM_UNKNOWN (0)
966 #define SYMBIOS_SCAM_DEVICE_NOT_FOUND (1)
967 #define SYMBIOS_SCAM_ID_NOT_SET (2)
968 #define SYMBIOS_SCAM_ID_VALID (3)
973 u_char spare_devices
[15*8];
974 u_char trailer
[6]; /* 0xfe 0xfe 0x00 0x00 0x00 0x00 */
976 typedef struct Symbios_nvram Symbios_nvram
;
977 typedef struct Symbios_host Symbios_host
;
978 typedef struct Symbios_target Symbios_target
;
979 typedef struct Symbios_scam Symbios_scam
;
982 ** Tekram NvRAM data format.
984 #define TEKRAM_NVRAM_SIZE 64
985 #define TEKRAM_NVRAM_ADDRESS 0
987 struct Tekram_nvram
{
988 struct Tekram_target
{
990 #define TEKRAM_PARITY_CHECK (1)
991 #define TEKRAM_SYNC_NEGO (1<<1)
992 #define TEKRAM_DISCONNECT_ENABLE (1<<2)
993 #define TEKRAM_START_CMD (1<<3)
994 #define TEKRAM_TAGGED_COMMANDS (1<<4)
995 #define TEKRAM_WIDE_NEGO (1<<5)
1001 #define TEKRAM_MORE_THAN_2_DRIVES (1)
1002 #define TEKRAM_DRIVES_SUP_1GB (1<<1)
1003 #define TEKRAM_RESET_ON_POWER_ON (1<<2)
1004 #define TEKRAM_ACTIVE_NEGATION (1<<3)
1005 #define TEKRAM_IMMEDIATE_SEEK (1<<4)
1006 #define TEKRAM_SCAN_LUNS (1<<5)
1007 #define TEKRAM_REMOVABLE_FLAGS (3<<6) /* 0: disable; 1: boot device; 2:all */
1008 u_char boot_delay_index
;
1009 u_char max_tags_index
;
1011 #define TEKRAM_F2_F6_ENABLED (1)
1014 typedef struct Tekram_nvram Tekram_nvram
;
1015 typedef struct Tekram_target Tekram_target
;
1017 static u_char Tekram_sync
[12] __initdata
= {25,31,37,43,50,62,75,125,12,15,18,21};
1019 #endif /* SCSI_NCR_NVRAM_SUPPORT */
1022 ** Structures used by sym53c8xx_detect/sym53c8xx_pci_init to
1023 ** transmit device configuration to the ncr_attach() function.
1032 /* port and reg fields to use INB, OUTB macros */
1034 volatile struct ncr_reg
*reg
;
1039 #define SCSI_NCR_SYMBIOS_NVRAM (1)
1040 #define SCSI_NCR_TEKRAM_NVRAM (2)
1041 #ifdef SCSI_NCR_NVRAM_SUPPORT
1043 Symbios_nvram Symbios
;
1044 Tekram_nvram Tekram
;
1050 ** Structure used by sym53c8xx_detect/sym53c8xx_pci_init
1051 ** to save data on each detected board for ncr_attach().
1058 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
1064 /*==========================================================
1068 **==========================================================
1070 ** modified copy from 386bsd:/usr/include/sys/assert.h
1072 **----------------------------------------------------------
1075 #define assert(expression) { \
1076 if (!(expression)) { \
1078 "assertion \"%s\" failed: file \"%s\", line %d\n", \
1080 __FILE__, __LINE__); \
1084 /*==========================================================
1086 ** Big/Little endian support.
1088 **==========================================================
1092 ** If the NCR uses big endian addressing mode over the
1093 ** PCI, actual io register addresses for byte and word
1094 ** accesses must be changed according to lane routing.
1095 ** Btw, ncr_offb() and ncr_offw() macros only apply to
1096 ** constants and so donnot generate bloated code.
1099 #if defined(SCSI_NCR_BIG_ENDIAN)
1101 #define ncr_offb(o) (((o)&~3)+((~((o)&3))&3))
1102 #define ncr_offw(o) (((o)&~3)+((~((o)&3))&2))
1106 #define ncr_offb(o) (o)
1107 #define ncr_offw(o) (o)
1112 ** If the CPU and the NCR use same endian-ness adressing,
1113 ** no byte reordering is needed for script patching.
1114 ** Macro cpu_to_scr() is to be used for script patching.
1115 ** Macro scr_to_cpu() is to be used for getting a DWORD
1119 #if defined(__BIG_ENDIAN) && !defined(SCSI_NCR_BIG_ENDIAN)
1121 #define cpu_to_scr(dw) cpu_to_le32(dw)
1122 #define scr_to_cpu(dw) le32_to_cpu(dw)
1124 #elif defined(__LITTLE_ENDIAN) && defined(SCSI_NCR_BIG_ENDIAN)
1126 #define cpu_to_scr(dw) cpu_to_be32(dw)
1127 #define scr_to_cpu(dw) be32_to_cpu(dw)
1131 #define cpu_to_scr(dw) (dw)
1132 #define scr_to_cpu(dw) (dw)
1136 /*==========================================================
1138 ** Access to the controller chip.
1140 ** If NCR_IOMAPPED is defined, the driver will use
1141 ** normal IOs instead of the MEMORY MAPPED IO method
1142 ** recommended by PCI specifications.
1143 ** If all PCI bridges, host brigdes and architectures
1144 ** would have been correctly designed for PCI, this
1145 ** option would be useless.
1147 **==========================================================
1151 ** If the CPU and the NCR use same endian-ness adressing,
1152 ** no byte reordering is needed for accessing chip io
1153 ** registers. Functions suffixed by '_raw' are assumed
1154 ** to access the chip over the PCI without doing byte
1155 ** reordering. Functions suffixed by '_l2b' are
1156 ** assumed to perform little-endian to big-endian byte
1157 ** reordering, those suffixed by '_b2l' blah, blah,
1161 #if defined(NCR_IOMAPPED)
1164 ** IO mapped only input / ouput
1167 #define INB_OFF(o) inb (np->base_io + ncr_offb(o))
1168 #define OUTB_OFF(o, val) outb ((val), np->base_io + ncr_offb(o))
1170 #if defined(__BIG_ENDIAN) && !defined(SCSI_NCR_BIG_ENDIAN)
1172 #define INW_OFF(o) inw_l2b (np->base_io + ncr_offw(o))
1173 #define INL_OFF(o) inl_l2b (np->base_io + (o))
1175 #define OUTW_OFF(o, val) outw_b2l ((val), np->base_io + ncr_offw(o))
1176 #define OUTL_OFF(o, val) outl_b2l ((val), np->base_io + (o))
1178 #elif defined(__LITTLE_ENDIAN) && defined(SCSI_NCR_BIG_ENDIAN)
1180 #define INW_OFF(o) inw_b2l (np->base_io + ncr_offw(o))
1181 #define INL_OFF(o) inl_b2l (np->base_io + (o))
1183 #define OUTW_OFF(o, val) outw_l2b ((val), np->base_io + ncr_offw(o))
1184 #define OUTL_OFF(o, val) outl_l2b ((val), np->base_io + (o))
1188 #define INW_OFF(o) inw_raw (np->base_io + ncr_offw(o))
1189 #define INL_OFF(o) inl_raw (np->base_io + (o))
1191 #define OUTW_OFF(o, val) outw_raw ((val), np->base_io + ncr_offw(o))
1192 #define OUTL_OFF(o, val) outl_raw ((val), np->base_io + (o))
1194 #endif /* ENDIANs */
1196 #else /* defined NCR_IOMAPPED */
1199 ** MEMORY mapped IO input / output
1202 #define INB_OFF(o) readb((char *)np->reg + ncr_offb(o))
1203 #define OUTB_OFF(o, val) writeb((val), (char *)np->reg + ncr_offb(o))
1205 #if defined(__BIG_ENDIAN) && !defined(SCSI_NCR_BIG_ENDIAN)
1207 #define INW_OFF(o) readw_l2b((char *)np->reg + ncr_offw(o))
1208 #define INL_OFF(o) readl_l2b((char *)np->reg + (o))
1210 #define OUTW_OFF(o, val) writew_b2l((val), (char *)np->reg + ncr_offw(o))
1211 #define OUTL_OFF(o, val) writel_b2l((val), (char *)np->reg + (o))
1213 #elif defined(__LITTLE_ENDIAN) && defined(SCSI_NCR_BIG_ENDIAN)
1215 #define INW_OFF(o) readw_b2l((char *)np->reg + ncr_offw(o))
1216 #define INL_OFF(o) readl_b2l((char *)np->reg + (o))
1218 #define OUTW_OFF(o, val) writew_l2b((val), (char *)np->reg + ncr_offw(o))
1219 #define OUTL_OFF(o, val) writel_l2b((val), (char *)np->reg + (o))
1223 #define INW_OFF(o) readw_raw((char *)np->reg + ncr_offw(o))
1224 #define INL_OFF(o) readl_raw((char *)np->reg + (o))
1226 #define OUTW_OFF(o, val) writew_raw((val), (char *)np->reg + ncr_offw(o))
1227 #define OUTL_OFF(o, val) writel_raw((val), (char *)np->reg + (o))
1231 #endif /* defined NCR_IOMAPPED */
1233 #define INB(r) INB_OFF (offsetof(struct ncr_reg,r))
1234 #define INW(r) INW_OFF (offsetof(struct ncr_reg,r))
1235 #define INL(r) INL_OFF (offsetof(struct ncr_reg,r))
1237 #define OUTB(r, val) OUTB_OFF (offsetof(struct ncr_reg,r), (val))
1238 #define OUTW(r, val) OUTW_OFF (offsetof(struct ncr_reg,r), (val))
1239 #define OUTL(r, val) OUTL_OFF (offsetof(struct ncr_reg,r), (val))
1242 ** Set bit field ON, OFF
1245 #define OUTONB(r, m) OUTB(r, INB(r) | (m))
1246 #define OUTOFFB(r, m) OUTB(r, INB(r) & ~(m))
1247 #define OUTONW(r, m) OUTW(r, INW(r) | (m))
1248 #define OUTOFFW(r, m) OUTW(r, INW(r) & ~(m))
1249 #define OUTONL(r, m) OUTL(r, INL(r) | (m))
1250 #define OUTOFFL(r, m) OUTL(r, INL(r) & ~(m))
1253 /*==========================================================
1255 ** Command control block states.
1257 **==========================================================
1262 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
1263 #define HS_DISCONNECT (3) /* Disconnected by target */
1265 #define HS_DONEMASK (0x80)
1266 #define HS_COMPLETE (4|HS_DONEMASK)
1267 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
1268 #define HS_RESET (6|HS_DONEMASK) /* SCSI reset */
1269 #define HS_ABORTED (7|HS_DONEMASK) /* Transfer aborted */
1270 #define HS_TIMEOUT (8|HS_DONEMASK) /* Software timeout */
1271 #define HS_FAIL (9|HS_DONEMASK) /* SCSI or PCI bus errors */
1272 #define HS_UNEXPECTED (10|HS_DONEMASK)/* Unexpected disconnect */
1274 #define DSA_INVALID 0xffffffff
1276 /*==========================================================
1278 ** Software Interrupt Codes
1280 **==========================================================
1283 #define SIR_BAD_STATUS (1)
1284 #define SIR_SEL_ATN_NO_MSG_OUT (2)
1285 #define SIR_NEGO_SYNC (3)
1286 #define SIR_NEGO_WIDE (4)
1287 #define SIR_NEGO_FAILED (5)
1288 #define SIR_NEGO_PROTO (6)
1289 #define SIR_REJECT_RECEIVED (7)
1290 #define SIR_REJECT_TO_SEND (8)
1291 #define SIR_IGN_RESIDUE (9)
1292 #define SIR_MISSING_SAVE (10)
1293 #define SIR_RESEL_NO_MSG_IN (11)
1294 #define SIR_RESEL_NO_IDENTIFY (12)
1295 #define SIR_RESEL_BAD_LUN (13)
1296 #define SIR_UNUSED_14 (14)
1297 #define SIR_RESEL_BAD_I_T_L (15)
1298 #define SIR_RESEL_BAD_I_T_L_Q (16)
1299 #define SIR_UNUSED_17 (17)
1300 #define SIR_RESEL_ABORTED (18)
1301 #define SIR_MSG_OUT_DONE (19)
1302 #define SIR_MAX (19)
1304 /*==========================================================
1306 ** Extended error codes.
1307 ** xerr_status field of struct ccb.
1309 **==========================================================
1313 #define XE_EXTRA_DATA (1) /* unexpected data phase */
1314 #define XE_BAD_PHASE (2) /* illegal phase (4/5) */
1316 /*==========================================================
1318 ** Negotiation status.
1319 ** nego_status field of struct ccb.
1321 **==========================================================
1327 /*==========================================================
1329 ** "Special features" of targets.
1330 ** quirks field of struct tcb.
1331 ** actualquirks field of struct ccb.
1333 **==========================================================
1336 #define QUIRK_AUTOSAVE (0x01)
1337 #define QUIRK_NOMSG (0x02)
1338 #define QUIRK_NOSYNC (0x10)
1339 #define QUIRK_NOWIDE16 (0x20)
1341 /*==========================================================
1343 ** Capability bits in Inquire response byte 7.
1345 **==========================================================
1348 #define INQ7_QUEUE (0x02)
1349 #define INQ7_SYNC (0x10)
1350 #define INQ7_WIDE16 (0x20)
1352 /*==========================================================
1354 ** A CCB hashed table is used to retrieve CCB address
1357 **==========================================================
1360 #define CCB_HASH_SHIFT 8
1361 #define CCB_HASH_SIZE (1UL << CCB_HASH_SHIFT)
1362 #define CCB_HASH_MASK (CCB_HASH_SIZE-1)
1363 #define CCB_HASH_CODE(dsa) (((dsa) >> 11) & CCB_HASH_MASK)
1365 /*==========================================================
1367 ** Declaration of structs.
1369 **==========================================================
1378 typedef struct ncb
* ncb_p
;
1379 typedef struct tcb
* tcb_p
;
1380 typedef struct lcb
* lcb_p
;
1381 typedef struct ccb
* ccb_p
;
1395 #define UC_SETSYNC 10
1396 #define UC_SETTAGS 11
1397 #define UC_SETDEBUG 12
1398 #define UC_SETORDER 13
1399 #define UC_SETWIDE 14
1400 #define UC_SETFLAG 15
1401 #define UC_CLEARPROF 16
1402 #define UC_SETVERBOSE 17
1404 #define UF_TRACE (0x01)
1405 #define UF_NODISC (0x02)
1406 #define UF_NOSCAN (0x04)
1408 #ifdef SCSI_NCR_PROFILE_SUPPORT
1410 ** profiling data (per host)
1431 /*========================================================================
1433 ** Declaration of structs: target control block
1435 **========================================================================
1438 /*----------------------------------------------------------------
1440 ** An array of bus addresses is used on reselection by
1442 **----------------------------------------------------------------
1444 u_int32
*luntbl
; /* lcbs bus address table */
1445 u_int32 b_luntbl
; /* bus address of this table */
1446 lcb_p lp
[MAX_LUN
]; /* The lcb's of this tcb */
1448 /*----------------------------------------------------------------
1449 ** Target capabilities.
1450 **----------------------------------------------------------------
1452 u_char inq_done
; /* Target capabilities received */
1453 u_char inq_byte7
; /* Contains these capabilities */
1455 /*----------------------------------------------------------------
1456 ** Pointer to the ccb used for negotiation.
1457 ** Prevent from starting a negotiation for all queued commands
1458 ** when tagged command queuing is enabled.
1459 **----------------------------------------------------------------
1463 /*----------------------------------------------------------------
1465 **----------------------------------------------------------------
1470 /*----------------------------------------------------------------
1471 ** negotiation of wide and synch transfer and device quirks.
1472 ** sval and wval are read from SCRIPTS and so have alignment
1474 **----------------------------------------------------------------
1476 /*0*/ u_char minsync
;
1478 /*2*/ u_short period
;
1479 /*0*/ u_char maxoffs
;
1480 /*1*/ u_char quirks
;
1481 /*2*/ u_char widedone
;
1484 /*----------------------------------------------------------------
1485 ** User settable limits and options.
1486 ** These limits are read from the NVRAM if present.
1487 **----------------------------------------------------------------
1495 /*========================================================================
1497 ** Declaration of structs: lun control block
1499 **========================================================================
1502 /*----------------------------------------------------------------
1503 ** On reselection, SCRIPTS use this value as a JUMP address
1504 ** after the IDENTIFY has been successfully received.
1505 ** This field is set to 'resel_tag' if TCQ is enabled and
1506 ** to 'resel_notag' if TCQ is disabled.
1507 ** (Must be at zero due to bad lun handling on reselection)
1508 **----------------------------------------------------------------
1510 /*0*/ u_int32 resel_task
;
1512 /*----------------------------------------------------------------
1513 ** Task table used by the script processor to retrieve the
1514 ** task corresponding to a reselected nexus. The TAG is used
1515 ** as offset to determine the corresponding entry.
1516 ** Each entry contains the associated CCB bus address.
1517 **----------------------------------------------------------------
1519 u_int32 tasktbl_0
; /* Used if TCQ not enabled */
1523 /*----------------------------------------------------------------
1524 ** CCB queue management.
1525 **----------------------------------------------------------------
1527 XPT_QUEHEAD busy_ccbq
; /* Queue of busy CCBs */
1528 XPT_QUEHEAD wait_ccbq
; /* Queue of waiting for IO CCBs */
1529 u_char busyccbs
; /* CCBs busy for this lun */
1530 u_char queuedccbs
; /* CCBs queued to the controller*/
1531 u_char queuedepth
; /* Queue depth for this lun */
1532 u_char scdev_depth
; /* SCSI device queue depth */
1533 u_char maxnxs
; /* Max possible nexuses */
1535 /*----------------------------------------------------------------
1536 ** Control of tagged command queuing.
1537 ** Tags allocation is performed using a circular buffer.
1538 ** This avoids using a loop for tag allocation.
1539 **----------------------------------------------------------------
1541 u_char ia_tag
; /* Tag allocation index */
1542 u_char if_tag
; /* Tag release index */
1543 u_char cb_tags
[SCSI_NCR_MAX_TAGS
]; /* Circular tags buffer */
1544 u_char usetags
; /* Command queuing is active */
1545 u_char maxtags
; /* Max NR of tags asked by user */
1546 u_char numtags
; /* Current number of tags */
1547 u_char inq_byte7
; /* Store unit CmdQ capabitility */
1549 /*----------------------------------------------------------------
1550 ** QUEUE FULL and ORDERED tag control.
1551 **----------------------------------------------------------------
1553 u_short num_good
; /* Nr of GOOD since QUEUE FULL */
1554 tagmap_t tags_umap
; /* Used tags bitmap */
1555 tagmap_t tags_smap
; /* Tags in use at 'tag_stime' */
1556 u_long tags_stime
; /* Last time we set smap=umap */
1559 /*========================================================================
1561 ** Declaration of structs: actions for a task.
1563 **========================================================================
1565 ** It is part of the CCB and is called by the scripts processor to
1566 ** start or restart the data structure (nexus).
1568 **------------------------------------------------------------------------
1575 /*========================================================================
1577 ** Declaration of structs: Phase mismatch context.
1579 **========================================================================
1581 ** It is part of the CCB and is used as parameters for the DATA
1582 ** pointer. We need two contexts to handle correctly the SAVED
1585 **------------------------------------------------------------------------
1588 struct scr_tblmove sg
; /* Updated interrupted SG block */
1589 u_int32 ret
; /* SCRIPT return address */
1592 /*========================================================================
1594 ** Declaration of structs: global HEADER.
1596 **========================================================================
1598 ** In earlier driver versions, this substructure was copied from the
1599 ** ccb to a global address after selection (or reselection) and copied
1600 ** back before disconnect. Since we are now using LOAD/STORE DSA
1601 ** RELATIVE instructions, the script is able to access directly these
1602 ** fields, and so, this header is no more copied.
1604 **------------------------------------------------------------------------
1608 /*----------------------------------------------------------------
1609 ** Start and restart SCRIPTS addresses (must be at 0).
1610 **----------------------------------------------------------------
1614 /*----------------------------------------------------------------
1615 ** Saved data pointer.
1616 ** Points to the position in the script responsible for the
1617 ** actual transfer of data.
1618 ** It's written after reception of a SAVE_DATA_POINTER message.
1619 ** The goalpointer points after the last transfer command.
1620 **----------------------------------------------------------------
1626 /*----------------------------------------------------------------
1627 ** Alternate data pointer.
1628 ** They are copied back to savep/lastp/goalp by the SCRIPTS
1629 ** when the direction is unknown and the device claims data out.
1630 **----------------------------------------------------------------
1635 /*----------------------------------------------------------------
1637 **----------------------------------------------------------------
1639 u_char scr_st
[4]; /* script status */
1640 u_char status
[4]; /* host status */
1644 ** The status bytes are used by the host and the script processor.
1646 ** The last four bytes (status[4]) are copied to the scratchb register
1647 ** (declared as scr0..scr3 in ncr_reg.h) just after the select/reselect,
1648 ** and copied back just after disconnecting.
1649 ** Inside the script the XX_REG are used.
1651 ** The first four bytes (scr_st[4]) are used inside the script by
1652 ** "LOAD/STORE" commands.
1653 ** Because source and destination must have the same alignment
1654 ** in a DWORD, the fields HAVE to be at the choosen offsets.
1655 ** xerr_st 0 (0x34) scratcha
1656 ** sync_st 1 (0x05) sxfer
1657 ** wide_st 3 (0x03) scntl3
1661 ** Last four bytes (script)
1665 #define HS_PRT nc_scr1
1667 #define SS_PRT nc_scr2
1669 #define HF_PRT nc_scr3
1672 ** Last four bytes (host)
1674 #define actualquirks phys.header.status[0]
1675 #define host_status phys.header.status[1]
1676 #define scsi_status phys.header.status[2]
1677 #define host_flags phys.header.status[3]
1682 #define HF_IN_PM0 1u
1683 #define HF_IN_PM1 (1u<<1)
1684 #define HF_ACT_PM (1u<<2)
1685 #define HF_DP_SAVED (1u<<3)
1686 #define HF_PAR_ERR (1u<<4)
1687 #define HF_DATA_ST (1u<<5)
1688 #define HF_PM_TO_C (1u<<6)
1691 ** First four bytes (script)
1693 #define xerr_st header.scr_st[0]
1694 #define sync_st header.scr_st[1]
1695 #define nego_st header.scr_st[2]
1696 #define wide_st header.scr_st[3]
1699 ** First four bytes (host)
1701 #define xerr_status phys.xerr_st
1702 #define nego_status phys.nego_st
1704 /*==========================================================
1706 ** Declaration of structs: Data structure block
1708 **==========================================================
1710 ** During execution of a ccb by the script processor,
1711 ** the DSA (data structure address) register points
1712 ** to this substructure of the ccb.
1713 ** This substructure contains the header with
1714 ** the script-processor-changable data and
1715 ** data blocks for the indirect move commands.
1717 **----------------------------------------------------------
1729 ** Table data for Script
1732 struct scr_tblsel select
;
1733 struct scr_tblmove smsg
;
1734 struct scr_tblmove cmd
;
1735 struct scr_tblmove sense
;
1736 struct scr_tblmove data
[MAX_SCATTER
];
1739 ** Phase mismatch contexts.
1740 ** We need two to handle correctly the
1741 ** SAVED DATA POINTER.
1747 #ifdef SCSI_NCR_PROFILE_SUPPORT
1749 ** Disconnection counter
1756 /*========================================================================
1758 ** Declaration of structs: Command control block.
1760 **========================================================================
1763 /*----------------------------------------------------------------
1764 ** This is the data structure which is pointed by the DSA
1765 ** register when it is executed by the script processor.
1766 ** It must be the first entry.
1767 **----------------------------------------------------------------
1771 /*----------------------------------------------------------------
1772 ** The general SCSI driver provides a
1773 ** pointer to a control block.
1774 **----------------------------------------------------------------
1776 Scsi_Cmnd
*cmd
; /* SCSI command */
1777 u_long tlimit
; /* Deadline for this job */
1778 int data_len
; /* Total data length */
1780 /*----------------------------------------------------------------
1782 ** We prepare a message to be sent after selection.
1783 ** We may use a second one if the command is rescheduled
1784 ** due to CHECK_CONDITION or QUEUE FULL status.
1785 ** Contents are IDENTIFY and SIMPLE_TAG.
1786 ** While negotiating sync or wide transfer,
1787 ** a SDTR or WDTR message is appended.
1788 **----------------------------------------------------------------
1790 u_char scsi_smsg
[8];
1791 u_char scsi_smsg2
[8];
1793 /*----------------------------------------------------------------
1795 **----------------------------------------------------------------
1797 u_long p_ccb
; /* BUS address of this CCB */
1798 u_char sensecmd
[6]; /* Sense command */
1799 u_char tag
; /* Tag for this transfer */
1800 /* 255 means no tag */
1805 ccb_p link_ccb
; /* Host adapter CCB chain */
1806 ccb_p link_ccbh
; /* Host adapter CCB hash chain */
1807 XPT_QUEHEAD link_ccbq
; /* Link to unit CCB queue */
1808 u_int32 startp
; /* Initial data pointer */
1811 #define CCB_PHYS(cp,lbl) (cp->p_ccb + offsetof(struct ccb, lbl))
1814 /*========================================================================
1816 ** Declaration of structs: NCR device descriptor
1818 **========================================================================
1821 /*----------------------------------------------------------------
1822 ** Idle task and invalid task actions and their bus
1824 **----------------------------------------------------------------
1826 struct action idletask
;
1827 struct action notask
;
1828 struct action bad_i_t_l
;
1829 struct action bad_i_t_l_q
;
1833 u_long p_bad_i_t_l_q
;
1835 /*----------------------------------------------------------------
1836 ** Dummy lun table to protect us against target returning bad
1837 ** lun number on reselection.
1838 **----------------------------------------------------------------
1840 u_int32
*badluntbl
; /* Table physical address */
1841 u_int32 resel_badlun
; /* SCRIPT handler BUS address */
1843 /*----------------------------------------------------------------
1844 ** Bit 32-63 of the on-chip RAM bus address in LE format.
1845 ** The START_RAM64 script loads the MMRS and MMWS from this
1847 **----------------------------------------------------------------
1849 u_int32 scr_ram_seg
;
1851 /*----------------------------------------------------------------
1852 ** CCBs management queues.
1853 **----------------------------------------------------------------
1855 Scsi_Cmnd
*waiting_list
; /* Commands waiting for a CCB */
1856 /* when lcb is not allocated. */
1857 Scsi_Cmnd
*done_list
; /* Commands waiting for done() */
1858 /* callback to be invoked. */
1859 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93)
1860 spinlock_t smp_lock
; /* Lock for SMP threading */
1863 /*----------------------------------------------------------------
1864 ** Chip and controller indentification.
1865 **----------------------------------------------------------------
1867 int unit
; /* Unit number */
1868 char chip_name
[8]; /* Chip name */
1869 char inst_name
[16]; /* ncb instance name */
1871 /*----------------------------------------------------------------
1872 ** Initial value of some IO register bits.
1873 ** These values are assumed to have been set by BIOS, and may
1874 ** be used for probing adapter implementation differences.
1875 **----------------------------------------------------------------
1877 u_char sv_scntl0
, sv_scntl3
, sv_dmode
, sv_dcntl
, sv_ctest3
, sv_ctest4
,
1878 sv_ctest5
, sv_gpcntl
, sv_stest2
, sv_stest4
;
1880 /*----------------------------------------------------------------
1881 ** Actual initial value of IO register bits used by the
1882 ** driver. They are loaded at initialisation according to
1883 ** features that are to be enabled.
1884 **----------------------------------------------------------------
1886 u_char rv_scntl0
, rv_scntl3
, rv_dmode
, rv_dcntl
, rv_ctest3
, rv_ctest4
,
1887 rv_ctest5
, rv_stest2
, rv_ccntl0
, rv_ccntl1
;
1889 /*----------------------------------------------------------------
1891 ** Target control block bus address array used by the SCRIPT
1893 **----------------------------------------------------------------
1895 struct tcb target
[MAX_TARGET
];
1898 /*----------------------------------------------------------------
1899 ** Virtual and physical bus addresses of the chip.
1900 **----------------------------------------------------------------
1902 u_long base_va
; /* MMIO base virtual address */
1903 u_long base_ba
; /* MMIO base bus address */
1904 u_long base_io
; /* IO space base address */
1905 u_long base_ws
; /* (MM)IO window size */
1906 u_long base2_ba
; /* On-chip RAM bus address. */
1907 u_int irq
; /* IRQ number */
1908 volatile /* Pointer to volatile for */
1909 struct ncr_reg
*reg
; /* memory mapped IO. */
1911 /*----------------------------------------------------------------
1912 ** SCRIPTS virtual and physical bus addresses.
1913 ** 'script' is loaded in the on-chip RAM if present.
1914 ** 'scripth' stays in main memory for all chips except the
1915 ** 53C896 that provides 8K on-chip RAM.
1916 **----------------------------------------------------------------
1918 struct script
*script0
; /* Copies of script and scripth */
1919 struct scripth
*scripth0
; /* relocated for this ncb. */
1920 u_long p_script
; /* Actual script and scripth */
1921 u_long p_scripth
; /* bus addresses. */
1924 /*----------------------------------------------------------------
1925 ** General controller parameters and configuration.
1926 **----------------------------------------------------------------
1928 u_short device_id
; /* PCI device id */
1929 u_char revision_id
; /* PCI device revision id */
1930 u_int features
; /* Chip features map */
1931 u_char myaddr
; /* SCSI id of the adapter */
1932 u_char maxburst
; /* log base 2 of dwords burst */
1933 u_char maxwide
; /* Maximum transfer width */
1934 u_char minsync
; /* Minimum sync period factor */
1935 u_char maxsync
; /* Maximum sync period factor */
1936 u_char maxoffs
; /* Max scsi offset */
1937 u_char multiplier
; /* Clock multiplier (1,2,4) */
1938 u_char clock_divn
; /* Number of clock divisors */
1939 u_long clock_khz
; /* SCSI clock frequency in KHz */
1941 /*----------------------------------------------------------------
1942 ** Start queue management.
1943 ** It is filled up by the host processor and accessed by the
1944 ** SCRIPTS processor in order to start SCSI commands.
1945 **----------------------------------------------------------------
1947 u_int32
*squeue
; /* Start queue */
1948 u_short squeueput
; /* Next free slot of the queue */
1949 u_short actccbs
; /* Number of allocated CCBs */
1950 u_short queuedepth
; /* Start queue depth */
1952 /*----------------------------------------------------------------
1953 ** Command completion queue.
1954 ** It is the same size as the start queue to avoid overflow.
1955 **----------------------------------------------------------------
1957 u_short dqueueget
; /* Next position to scan */
1958 u_int32
*dqueue
; /* Completion (done) queue */
1960 /*----------------------------------------------------------------
1962 **----------------------------------------------------------------
1964 struct timer_list timer
; /* Timer handler link header */
1966 u_long settle_time
; /* Resetting the SCSI BUS */
1968 /*----------------------------------------------------------------
1969 ** Debugging and profiling.
1970 **----------------------------------------------------------------
1972 struct ncr_reg regdump
; /* Register dump */
1973 u_long regtime
; /* Time it has been done */
1974 #ifdef SCSI_NCR_PROFILE_SUPPORT
1975 struct profile profile
; /* Profiling data */
1978 /*----------------------------------------------------------------
1979 ** Miscellaneous buffers accessed by the scripts-processor.
1980 ** They shall be DWORD aligned, because they may be read or
1981 ** written with a script command.
1982 **----------------------------------------------------------------
1984 u_char msgout
[8]; /* Buffer for MESSAGE OUT */
1985 u_char msgin
[8]; /* Buffer for MESSAGE IN */
1986 u_int32 lastmsg
; /* Last SCSI message sent */
1987 u_char scratch
; /* Scratch for SCSI receive */
1989 /*----------------------------------------------------------------
1990 ** Miscellaneous configuration and status parameters.
1991 **----------------------------------------------------------------
1993 u_char scsi_mode
; /* Current SCSI BUS mode */
1994 u_char order
; /* Tag order to use */
1995 u_char verbose
; /* Verbosity for this controller*/
1996 u_int32 ncr_cache
; /* Used for cache test at init. */
1998 /*----------------------------------------------------------------
1999 ** CCB lists and queue.
2000 **----------------------------------------------------------------
2002 ccb_p ccbh
[CCB_HASH_SIZE
]; /* CCB hashed by DSA value */
2003 struct ccb
*ccbc
; /* CCB chain */
2004 XPT_QUEHEAD free_ccbq
; /* Queue of available CCBs */
2006 /*----------------------------------------------------------------
2007 ** We need the LCB in order to handle disconnections and
2008 ** to count active CCBs for task management. So, we use
2009 ** a unique CCB for LUNs we donnot have the LCB yet.
2010 ** This queue normally should have at most 1 element.
2011 **----------------------------------------------------------------
2013 XPT_QUEHEAD b0_ccbq
;
2015 /*----------------------------------------------------------------
2016 ** We use a different scatter function for 896 rev 1.
2017 **----------------------------------------------------------------
2019 int (*scatter
) (ccb_p
, Scsi_Cmnd
*);
2021 /*----------------------------------------------------------------
2022 ** Fields that should be removed or changed.
2023 **----------------------------------------------------------------
2025 struct usrcmd user
; /* Command from user */
2026 u_char release_stage
; /* Synchronisation stage on release */
2029 #define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
2030 #define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
2031 #define NCB_SCRIPTH0_PHYS(np,lbl) (np->p_scripth0+offsetof (struct scripth,lbl))
2033 /*==========================================================
2036 ** Script for NCR-Processor.
2038 ** Use ncr_script_fill() to create the variable parts.
2039 ** Use ncr_script_copy_and_bind() to make a copy and
2040 ** bind to physical addresses.
2043 **==========================================================
2045 ** We have to know the offsets of all labels before
2046 ** we reach them (for forward jumps).
2047 ** Therefore we declare a struct here.
2048 ** If you make changes inside the script,
2049 ** DONT FORGET TO CHANGE THE LENGTHS HERE!
2051 **----------------------------------------------------------
2055 ** Script fragments which are loaded into the on-chip RAM
2056 ** of 825A, 875, 876, 895 and 896 chips.
2060 ncrcmd getjob_begin
[ 4];
2061 ncrcmd getjob_end
[ 4];
2063 ncrcmd wf_sel_done
[ 2];
2064 ncrcmd send_ident
[ 2];
2065 ncrcmd select2
[ 6];
2066 ncrcmd command
[ 2];
2067 ncrcmd dispatch
[ 26];
2068 ncrcmd sel_no_cmd
[ 10];
2071 ncrcmd databreak
[ 2];
2072 #ifdef SCSI_NCR_PROFILE_SUPPORT
2073 ncrcmd dataphase
[ 4];
2075 ncrcmd dataphase
[ 2];
2079 ncrcmd msg_in2
[ 16];
2080 ncrcmd msg_bad
[ 6];
2081 ncrcmd complete
[ 8];
2082 ncrcmd complete2
[ 6];
2084 ncrcmd done_end
[ 2];
2085 ncrcmd save_dp
[ 8];
2086 ncrcmd restore_dp
[ 4];
2087 #ifdef SCSI_NCR_PROFILE_SUPPORT
2088 ncrcmd disconnect
[ 32];
2090 ncrcmd disconnect
[ 20];
2093 ncrcmd ungetjob
[ 4];
2094 ncrcmd reselect
[ 4];
2095 ncrcmd reselected
[ 44];
2096 ncrcmd resel_tag
[ 6];
2097 ncrcmd resel_go
[ 6];
2098 ncrcmd resel_notag
[ 4];
2099 ncrcmd resel_dsa
[ 8];
2100 ncrcmd data_in
[MAX_SCATTERL
* SCR_SG_SIZE
];
2101 ncrcmd data_in2
[ 4];
2102 ncrcmd data_out
[MAX_SCATTERL
* SCR_SG_SIZE
];
2103 ncrcmd data_out2
[ 4];
2104 ncrcmd pm0_data
[ 16];
2105 ncrcmd pm1_data
[ 16];
2108 ncrcmd saved_dsa
[ 1];
2109 ncrcmd done_pos
[ 1];
2110 ncrcmd startpos
[ 1];
2111 ncrcmd targtbl
[ 1];
2115 ** Script fragments which stay in main memory for all chips
2116 ** except for the 896 that support 8K on-chip RAM.
2119 ncrcmd start64
[ 2];
2120 ncrcmd select_no_atn
[ 4];
2121 ncrcmd wf_sel_done_no_atn
[ 4];
2123 ncrcmd msg_reject
[ 8];
2124 ncrcmd msg_ign_residue
[ 24];
2125 ncrcmd msg_extended
[ 10];
2126 ncrcmd msg_ext_2
[ 10];
2127 ncrcmd msg_wdtr
[ 14];
2128 ncrcmd send_wdtr
[ 4];
2129 ncrcmd msg_ext_3
[ 10];
2130 ncrcmd msg_sdtr
[ 14];
2131 ncrcmd send_sdtr
[ 4];
2132 ncrcmd nego_bad_phase
[ 4];
2133 ncrcmd msg_out_abort
[ 12];
2134 ncrcmd msg_out
[ 6];
2135 ncrcmd msg_out_done
[ 4];
2136 ncrcmd no_data
[ 16];
2137 #if MAX_SCATTERH != 0
2138 ncrcmd hdata_in
[MAX_SCATTERH
* SCR_SG_SIZE
];
2139 ncrcmd hdata_in2
[ 2];
2140 ncrcmd hdata_out
[MAX_SCATTERH
* SCR_SG_SIZE
];
2141 ncrcmd hdata_out2
[ 2];
2143 ncrcmd abort_resel
[ 16];
2144 ncrcmd resend_ident
[ 4];
2145 ncrcmd ident_break
[ 4];
2146 ncrcmd ident_break_atn
[ 4];
2147 ncrcmd sdata_in
[ 6];
2148 ncrcmd data_io
[ 2];
2149 ncrcmd data_io_com
[ 8];
2150 ncrcmd data_io_out
[ 10];
2151 ncrcmd bad_identify
[ 12];
2152 ncrcmd bad_i_t_l
[ 4];
2153 ncrcmd bad_i_t_l_q
[ 4];
2154 ncrcmd bad_status
[ 10];
2155 ncrcmd tweak_pmj
[ 12];
2156 ncrcmd pm_handle
[ 20];
2157 ncrcmd pm_handle1
[ 4];
2158 ncrcmd pm_save
[ 4];
2159 ncrcmd pm0_save
[ 10];
2160 ncrcmd pm1_save
[ 10];
2163 ncrcmd pm0_data_addr
[ 1];
2164 ncrcmd pm1_data_addr
[ 1];
2165 /* End of data area */
2167 ncrcmd start_ram
[ 1];
2168 ncrcmd script0_ba
[ 4];
2170 ncrcmd start_ram64
[ 3];
2171 ncrcmd script0_ba64
[ 3];
2172 ncrcmd scripth0_ba64
[ 6];
2173 ncrcmd ram_seg64
[ 1];
2175 ncrcmd snooptest
[ 6];
2176 ncrcmd snoopend
[ 2];
2179 /*==========================================================
2182 ** Function headers.
2185 **==========================================================
2188 static ccb_p
ncr_alloc_ccb (ncb_p np
);
2189 static void ncr_complete (ncb_p np
, ccb_p cp
);
2190 static void ncr_exception (ncb_p np
);
2191 static void ncr_free_ccb (ncb_p np
, ccb_p cp
);
2192 static ccb_p
ncr_ccb_from_dsa(ncb_p np
, u_long dsa
);
2193 static void ncr_init_tcb (ncb_p np
, u_char tn
);
2194 static lcb_p
ncr_alloc_lcb (ncb_p np
, u_char tn
, u_char ln
);
2195 static lcb_p
ncr_setup_lcb (ncb_p np
, u_char tn
, u_char ln
,
2197 static void ncr_getclock (ncb_p np
, int mult
);
2198 static void ncr_selectclock (ncb_p np
, u_char scntl3
);
2199 static ccb_p
ncr_get_ccb (ncb_p np
, u_char tn
, u_char ln
);
2200 static void ncr_init (ncb_p np
, int reset
, char * msg
, u_long code
);
2201 static void ncr_int_sbmc (ncb_p np
);
2202 static void ncr_int_par (ncb_p np
, u_short sist
);
2203 static void ncr_int_ma (ncb_p np
);
2204 static void ncr_int_sir (ncb_p np
);
2205 static void ncr_int_sto (ncb_p np
);
2206 static void ncr_int_udc (ncb_p np
);
2207 static u_long
ncr_lookup (char* id
);
2208 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
);
2209 #ifdef SCSI_NCR_PROFILE_SUPPORT
2210 static void ncb_profile (ncb_p np
, ccb_p cp
);
2212 static void ncr_script_copy_and_bind
2213 (ncb_p np
, ncrcmd
*src
, ncrcmd
*dst
, int len
);
2214 static void ncr_script_fill (struct script
* scr
, struct scripth
* scripth
);
2215 static int ncr_scatter_896R1 (ccb_p cp
, Scsi_Cmnd
*cmd
);
2216 static int ncr_scatter (ccb_p cp
, Scsi_Cmnd
*cmd
);
2217 static void ncr_getsync (ncb_p np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
);
2218 static void ncr_setsync (ncb_p np
, ccb_p cp
, u_char scntl3
, u_char sxfer
);
2219 static void ncr_setup_tags (ncb_p np
, u_char tn
, u_char ln
);
2220 static void ncr_setwide (ncb_p np
, ccb_p cp
, u_char wide
, u_char ack
);
2221 static int ncr_show_msg (u_char
* msg
);
2222 static int ncr_snooptest (ncb_p np
);
2223 static void ncr_timeout (ncb_p np
);
2224 static void ncr_wakeup (ncb_p np
, u_long code
);
2225 static int ncr_wakeup_done (ncb_p np
);
2226 static void ncr_start_next_ccb (ncb_p np
, lcb_p lp
, int maxn
);
2227 static void ncr_put_start_queue(ncb_p np
, ccb_p cp
);
2228 static void ncr_soft_reset (ncb_p np
);
2229 static void ncr_start_reset (ncb_p np
);
2230 static int ncr_reset_scsi_bus (ncb_p np
, int enab_int
, int settle_delay
);
2232 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
2233 static void ncr_usercmd (ncb_p np
);
2236 static int ncr_attach (Scsi_Host_Template
*tpnt
, int unit
, ncr_device
*device
);
2237 static void ncr_free_resources(ncb_p np
);
2239 static void insert_into_waiting_list(ncb_p np
, Scsi_Cmnd
*cmd
);
2240 static Scsi_Cmnd
*retrieve_from_waiting_list(int to_remove
, ncb_p np
, Scsi_Cmnd
*cmd
);
2241 static void process_waiting_list(ncb_p np
, int sts
);
2243 #define remove_from_waiting_list(np, cmd) \
2244 retrieve_from_waiting_list(1, (np), (cmd))
2245 #define requeue_waiting_list(np) process_waiting_list((np), DID_OK)
2246 #define reset_waiting_list(np) process_waiting_list((np), DID_RESET)
2248 #ifdef SCSI_NCR_NVRAM_SUPPORT
2249 static void ncr_get_nvram (ncr_device
*devp
, ncr_nvram
*nvp
);
2250 static int ncr_get_Symbios_nvram (ncr_slot
*np
, Symbios_nvram
*nvram
);
2251 static int ncr_get_Tekram_nvram (ncr_slot
*np
, Tekram_nvram
*nvram
);
2254 /*==========================================================
2257 ** Global static data.
2260 **==========================================================
2263 static inline char *ncr_name (ncb_p np
)
2265 return np
->inst_name
;
2269 /*==========================================================
2272 ** Scripts for NCR-Processor.
2274 ** Use ncr_script_bind for binding to physical addresses.
2277 **==========================================================
2279 ** NADDR generates a reference to a field of the controller data.
2280 ** PADDR generates a reference to another part of the script.
2281 ** RADDR generates a reference to a script processor register.
2282 ** FADDR generates a reference to a script processor register
2285 **----------------------------------------------------------
2288 #define RELOC_SOFTC 0x40000000
2289 #define RELOC_LABEL 0x50000000
2290 #define RELOC_REGISTER 0x60000000
2292 #define RELOC_KVAR 0x70000000
2294 #define RELOC_LABELH 0x80000000
2295 #define RELOC_MASK 0xf0000000
2297 #define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
2298 #define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
2299 #define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
2300 #define RADDR(label) (RELOC_REGISTER | REG(label))
2301 #define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
2302 #define KVAR(which) (RELOC_KVAR | (which))
2304 #define SCR_DATA_ZERO 0xf00ff00f
2307 #define SCRIPT_KVAR_JIFFIES (0)
2308 #define SCRIPT_KVAR_FIRST SCRIPT_KVAR_JIFFIES
2309 #define SCRIPT_KVAR_LAST SCRIPT_KVAR_JIFFIES
2311 * Kernel variables referenced in the scripts.
2312 * THESE MUST ALL BE ALIGNED TO A 4-BYTE BOUNDARY.
2314 static void *script_kvars
[] __initdata
=
2315 { (void *)&jiffies
};
2318 static struct script script0 __initdata
= {
2319 /*--------------------------< START >-----------------------*/ {
2321 ** This NOP will be patched with LED ON
2322 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
2329 SCR_FROM_REG (ctest2
),
2332 ** Start the next job.
2334 ** @DSA = start point for this job.
2335 ** SCRATCHA = address of this job in the start queue.
2337 ** We will restore startpos with SCRATCHA if we fails the
2338 ** arbitration or if it is the idle job.
2340 ** The below GETJOB_BEGIN to GETJOB_END section of SCRIPTS
2341 ** is a critical path. If it is partially executed, it then
2342 ** may happen that the job address is not yet in the DSA
2343 ** and the the next queue position points to the next JOB.
2345 SCR_LOAD_ABS (scratcha
, 4),
2347 SCR_LOAD_ABS (dsa
, 4),
2349 SCR_LOAD_REL (temp
, 4),
2351 }/*-------------------------< GETJOB_BEGIN >------------------*/,{
2352 SCR_STORE_ABS (temp
, 4),
2354 SCR_LOAD_REL (dsa
, 4),
2356 }/*-------------------------< GETJOB_END >--------------------*/,{
2357 SCR_LOAD_REL (temp
, 4),
2362 }/*-------------------------< SELECT >----------------------*/,{
2364 ** DSA contains the address of a scheduled
2367 ** SCRATCHA contains the address of the start queue
2368 ** entry which points to the next job.
2370 ** Set Initiator mode.
2372 ** (Target mode is left as an exercise for the reader)
2378 ** And try to select this target.
2380 SCR_SEL_TBL_ATN
^ offsetof (struct dsb
, select
),
2383 ** Now there are 4 possibilities:
2385 ** (1) The ncr looses arbitration.
2386 ** This is ok, because it will try again,
2387 ** when the bus becomes idle.
2388 ** (But beware of the timeout function!)
2390 ** (2) The ncr is reselected.
2391 ** Then the script processor takes the jump
2392 ** to the RESELECT label.
2394 ** (3) The ncr wins arbitration.
2395 ** Then it will execute SCRIPTS instruction until
2396 ** the next instruction that checks SCSI phase.
2397 ** Then will stop and wait for selection to be
2398 ** complete or selection time-out to occur.
2400 ** After having won arbitration, the ncr SCRIPTS
2401 ** processor is able to execute instructions while
2402 ** the SCSI core is performing SCSI selection. But
2403 ** some script instruction that is not waiting for
2404 ** a valid phase (or selection timeout) to occur
2405 ** breaks the selection procedure, by probably
2406 ** affecting timing requirements.
2407 ** So we have to wait immediately for the next phase
2408 ** or the selection to complete or time-out.
2410 }/*-------------------------< WF_SEL_DONE >----------------------*/,{
2411 SCR_INT
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2412 SIR_SEL_ATN_NO_MSG_OUT
,
2413 }/*-------------------------< SEND_IDENT >----------------------*/,{
2415 ** Selection complete.
2416 ** Send the IDENTIFY and SIMPLE_TAG messages
2417 ** (and the M_X_SYNC_REQ / M_X_WIDE_REQ message)
2419 SCR_MOVE_TBL
^ SCR_MSG_OUT
,
2420 offsetof (struct dsb
, smsg
),
2421 }/*-------------------------< SELECT2 >----------------------*/,{
2423 ** load the savep (saved pointer) into
2424 ** the actual data pointer.
2426 SCR_LOAD_REL (temp
, 4),
2427 offsetof (struct ccb
, phys
.header
.savep
),
2429 ** Initialize the status registers
2431 SCR_LOAD_REL (scr0
, 4),
2432 offsetof (struct ccb
, phys
.header
.status
),
2434 ** Anticipate the COMMAND phase.
2435 ** This is the PHASE we expect at this point.
2437 SCR_JUMP
^ IFFALSE (WHEN (SCR_COMMAND
)),
2440 }/*-------------------------< COMMAND >--------------------*/,{
2442 ** ... and send the command
2444 SCR_MOVE_TBL
^ SCR_COMMAND
,
2445 offsetof (struct dsb
, cmd
),
2447 }/*-----------------------< DISPATCH >----------------------*/,{
2449 ** MSG_IN is the only phase that shall be
2450 ** entered at least once for each (re)selection.
2451 ** So we test it first.
2453 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)),
2455 SCR_JUMP
^ IFTRUE (IF (SCR_DATA_OUT
)),
2457 SCR_JUMP
^ IFTRUE (IF (SCR_DATA_IN
)),
2459 SCR_JUMP
^ IFTRUE (IF (SCR_STATUS
)),
2461 SCR_JUMP
^ IFTRUE (IF (SCR_COMMAND
)),
2463 SCR_JUMP
^ IFTRUE (IF (SCR_MSG_OUT
)),
2466 ** Discard one illegal phase byte, if required.
2468 SCR_LOAD_REG (scratcha
, XE_BAD_PHASE
),
2470 SCR_STORE_REL (scratcha
, 1),
2471 offsetof (struct ccb
, xerr_status
),
2472 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_OUT
)),
2474 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT
,
2476 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_IN
)),
2478 SCR_MOVE_ABS (1) ^ SCR_ILG_IN
,
2483 }/*---------------------< SEL_NO_CMD >----------------------*/,{
2485 ** The target does not switch to command
2486 ** phase after IDENTIFY has been sent.
2488 ** If it stays in MSG OUT phase send it
2489 ** the IDENTIFY again.
2491 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
2492 PADDRH (resend_ident
),
2494 ** If target does not switch to MSG IN phase
2495 ** and we sent a negotiation, assert the
2496 ** failure immediately.
2498 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)),
2500 SCR_FROM_REG (HS_REG
),
2502 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
2505 ** Jump to dispatcher.
2510 }/*-------------------------< INIT >------------------------*/,{
2512 ** Wait for the SCSI RESET signal to be
2513 ** inactive before restarting operations,
2514 ** since the chip may hang on SEL_ATN
2515 ** if SCSI RESET is active.
2517 SCR_FROM_REG (sstat0
),
2519 SCR_JUMPR
^ IFTRUE (MASK (IRST
, IRST
)),
2523 }/*-------------------------< CLRACK >----------------------*/,{
2525 ** Terminate possible pending message phase.
2532 }/*-------------------------< DATABREAK >-------------------*/,{
2534 ** Jump to dispatcher.
2539 }/*-------------------------< DATAPHASE >------------------*/,{
2540 #ifdef SCSI_NCR_PROFILE_SUPPORT
2541 SCR_REG_REG (HF_REG
, SCR_OR
, HF_DATA_ST
),
2547 }/*-------------------------< STATUS >--------------------*/,{
2551 SCR_MOVE_ABS (1) ^ SCR_STATUS
,
2554 ** save status to scsi_status.
2555 ** mark as complete.
2557 SCR_TO_REG (SS_REG
),
2559 SCR_LOAD_REG (HS_REG
, HS_COMPLETE
),
2563 }/*-------------------------< MSG_IN >--------------------*/,{
2565 ** Get the first byte of the message.
2567 ** The script processor doesn't negate the
2568 ** ACK signal after this transfer.
2570 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2572 }/*-------------------------< MSG_IN2 >--------------------*/,{
2574 ** Handle this message.
2576 SCR_JUMP
^ IFTRUE (DATA (M_COMPLETE
)),
2578 SCR_JUMP
^ IFTRUE (DATA (M_DISCONNECT
)),
2580 SCR_JUMP
^ IFTRUE (DATA (M_SAVE_DP
)),
2582 SCR_JUMP
^ IFTRUE (DATA (M_RESTORE_DP
)),
2584 SCR_JUMP
^ IFTRUE (DATA (M_EXTENDED
)),
2585 PADDRH (msg_extended
),
2586 SCR_JUMP
^ IFTRUE (DATA (M_NOOP
)),
2588 SCR_JUMP
^ IFTRUE (DATA (M_REJECT
)),
2589 PADDRH (msg_reject
),
2590 SCR_JUMP
^ IFTRUE (DATA (M_IGN_RESIDUE
)),
2591 PADDRH (msg_ign_residue
),
2593 ** Rest of the messages left as
2596 ** Unimplemented messages:
2597 ** fall through to MSG_BAD.
2599 }/*-------------------------< MSG_BAD >------------------*/,{
2601 ** unimplemented message - reject it.
2610 }/*-------------------------< COMPLETE >-----------------*/,{
2612 ** Complete message.
2614 ** Copy the data pointer to LASTP in header.
2616 SCR_STORE_REL (temp
, 4),
2617 offsetof (struct ccb
, phys
.header
.lastp
),
2619 ** When we terminate the cycle by clearing ACK,
2620 ** the target may disconnect immediately.
2622 ** We don't want to be told of an
2623 ** "unexpected disconnect",
2624 ** so we disable this feature.
2626 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2629 ** Terminate cycle ...
2631 SCR_CLR (SCR_ACK
|SCR_ATN
),
2634 ** ... and wait for the disconnect.
2638 }/*-------------------------< COMPLETE2 >-----------------*/,{
2640 ** Save host status to header.
2642 SCR_STORE_REL (scr0
, 4),
2643 offsetof (struct ccb
, phys
.header
.status
),
2646 ** If command resulted in not GOOD status,
2647 ** call the C code if needed.
2649 SCR_FROM_REG (SS_REG
),
2651 SCR_CALL
^ IFFALSE (DATA (S_GOOD
)),
2652 PADDRH (bad_status
),
2654 }/*------------------------< DONE >-----------------*/,{
2656 ** Copy the DSA to the DONE QUEUE and
2657 ** signal completion to the host.
2658 ** If we are interrupted between DONE
2659 ** and DONE_END, we must reset, otherwise
2660 ** the completed CCB will be lost.
2662 SCR_STORE_ABS (dsa
, 4),
2664 SCR_LOAD_ABS (dsa
, 4),
2666 SCR_LOAD_ABS (scratcha
, 4),
2668 SCR_STORE_REL (scratcha
, 4),
2671 ** The instruction below reads the DONE QUEUE next
2672 ** free position from memory.
2673 ** In addition it ensures that all PCI posted writes
2674 ** are flushed and so the DSA value of the done
2675 ** CCB is visible by the CPU before INTFLY is raised.
2677 SCR_LOAD_REL (temp
, 4),
2681 SCR_STORE_ABS (temp
, 4),
2683 }/*------------------------< DONE_END >-----------------*/,{
2687 }/*-------------------------< SAVE_DP >------------------*/,{
2689 ** Clear ACK immediately.
2690 ** No need to delay it.
2695 ** Keep track we received a SAVE DP, so
2696 ** we will switch to the other PM context
2697 ** on the next PM since the DP may point
2698 ** to the current PM context.
2700 SCR_REG_REG (HF_REG
, SCR_OR
, HF_DP_SAVED
),
2704 ** Copy the data pointer to SAVEP in header.
2706 SCR_STORE_REL (temp
, 4),
2707 offsetof (struct ccb
, phys
.header
.savep
),
2710 }/*-------------------------< RESTORE_DP >---------------*/,{
2712 ** RESTORE_DP message:
2713 ** Copy SAVEP in header to actual data pointer.
2715 SCR_LOAD_REL (temp
, 4),
2716 offsetof (struct ccb
, phys
.header
.savep
),
2720 }/*-------------------------< DISCONNECT >---------------*/,{
2722 ** DISCONNECTing ...
2724 ** disable the "unexpected disconnect" feature,
2725 ** and remove the ACK signal.
2727 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2729 SCR_CLR (SCR_ACK
|SCR_ATN
),
2732 ** Wait for the disconnect.
2736 #ifdef SCSI_NCR_PROFILE_SUPPORT
2738 ** Count the disconnects.
2739 ** Disconnect without DATA PHASE having been
2740 ** entered are counted in bits 8..15.
2742 SCR_LOAD_REL (scratcha
, 4),
2743 offsetof (struct ccb
, phys
.num_disc
),
2744 SCR_FROM_REG (HF_REG
),
2746 SCR_JUMPR
^ IFTRUE (MASK (HF_DATA_ST
, HF_DATA_ST
)),
2748 SCR_REG_REG (scratcha1
, SCR_ADD
, 0x01),
2750 SCR_REG_REG (scratcha
, SCR_ADD
, 0x01),
2752 SCR_STORE_REL (scratcha
, 4),
2753 offsetof (struct ccb
, phys
.num_disc
),
2756 ** Status is: DISCONNECTED.
2758 SCR_LOAD_REG (HS_REG
, HS_DISCONNECT
),
2761 ** Save host status to header.
2763 SCR_STORE_REL (scr0
, 4),
2764 offsetof (struct ccb
, phys
.header
.status
),
2766 ** If QUIRK_AUTOSAVE is set,
2767 ** do an "save pointer" operation.
2769 SCR_FROM_REG (QU_REG
),
2771 SCR_JUMP
^ IFFALSE (MASK (QUIRK_AUTOSAVE
, QUIRK_AUTOSAVE
)),
2774 ** like SAVE_DP message:
2775 ** Remember we saved the data pointer.
2776 ** Copy data pointer to SAVEP in header.
2778 SCR_REG_REG (HF_REG
, SCR_OR
, HF_DP_SAVED
),
2780 SCR_STORE_REL (temp
, 4),
2781 offsetof (struct ccb
, phys
.header
.savep
),
2785 }/*-------------------------< IDLE >------------------------*/,{
2788 ** Wait for reselect.
2789 ** This NOP will be patched with LED OFF
2790 ** SCR_REG_REG (gpreg, SCR_OR, 0x01)
2794 }/*-------------------------< UNGETJOB >-----------------*/,{
2796 ** We are not able to restart the SCRIPTS if we are
2797 ** interrupted and these instruction haven't been
2798 ** all executed. BTW, this is very unlikely to
2799 ** happen, but we check that from the C code.
2801 SCR_LOAD_REG (dsa
, 0xff),
2803 SCR_STORE_ABS (scratcha
, 4),
2805 }/*-------------------------< RESELECT >--------------------*/,{
2807 ** make the host status invalid.
2812 ** Sleep waiting for a reselection.
2813 ** If SIGP is set, special treatment.
2815 ** Zu allem bereit ..
2819 }/*-------------------------< RESELECTED >------------------*/,{
2821 ** This NOP will be patched with LED ON
2822 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
2827 ** load the target id into the sdid
2829 SCR_REG_SFBR (ssid
, SCR_AND
, 0x8F),
2834 ** load the target control block address
2836 SCR_LOAD_ABS (dsa
, 4),
2838 SCR_SFBR_REG (dsa
, SCR_SHL
, 0),
2840 SCR_REG_REG (dsa
, SCR_SHL
, 0),
2842 SCR_REG_REG (dsa
, SCR_AND
, 0x3c),
2844 SCR_LOAD_REL (dsa
, 4),
2847 ** Load the synchronous transfer registers.
2849 SCR_LOAD_REL (scntl3
, 1),
2850 offsetof(struct tcb
, wval
),
2851 SCR_LOAD_REL (sxfer
, 1),
2852 offsetof(struct tcb
, sval
),
2854 ** If MESSAGE IN phase as expected,
2855 ** read the data directly from the BUS DATA lines.
2856 ** This helps to support very old SCSI devices that
2857 ** may reselect without sending an IDENTIFY.
2859 SCR_INT
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2860 SIR_RESEL_NO_MSG_IN
,
2861 SCR_FROM_REG (sbdl
),
2864 ** If message phase but not an IDENTIFY,
2865 ** get some help from the C code.
2866 ** Old SCSI device may behave so.
2868 SCR_INT
^ IFFALSE (MASK (0x80, 0x80)),
2869 SIR_RESEL_NO_IDENTIFY
,
2871 ** It is an IDENTIFY message,
2872 ** Load the LUN control block address.
2873 ** Avoid nasty address calculation if LUN #0.
2875 SCR_LOAD_REL (dsa
, 4),
2876 offsetof(struct tcb
, b_luntbl
),
2877 SCR_JUMPR
^ IFTRUE (MASK (0x0, 0x3f)),
2879 SCR_SFBR_REG (dsa
, SCR_SHL
, 0),
2881 SCR_REG_REG (dsa
, SCR_SHL
, 0),
2883 SCR_REG_REG (dsa
, SCR_AND
, 0xfc),
2885 SCR_LOAD_REL (dsa
, 4),
2888 ** Load the reselect task action for this LUN.
2889 ** Load the tasks DSA array for this LUN.
2892 SCR_LOAD_REL (temp
, 4),
2893 offsetof(struct lcb
, resel_task
),
2894 SCR_LOAD_REL (dsa
, 4),
2895 offsetof(struct lcb
, b_tasktbl
),
2899 }/*-------------------------< RESEL_TAG >-------------------*/,{
2901 ** Read IDENTIFY + SIMPLE + TAG using a single MOVE.
2902 ** Agressive optimization, is'nt it?
2903 ** No need to test the SIMPLE TAG message, since the
2904 ** driver only supports conformant devices for tags. ;-)
2906 SCR_MOVE_ABS (3) ^ SCR_MSG_IN
,
2909 ** Read the TAG from the SIDL.
2910 ** Still an aggressive optimization. ;-)
2911 ** Compute the CCB indirect jump address which
2912 ** is (#TAG*2 & 0xfc) due to tag numbering using
2913 ** 1,3,5..MAXTAGS*2+1 actual values.
2915 SCR_REG_SFBR (sidl
, SCR_SHL
, 0),
2918 ** Retrieve the DSA of this task.
2919 ** JUMP indirectly to the restart point of the CCB.
2921 SCR_SFBR_REG (dsa
, SCR_AND
, 0xfc),
2923 }/*-------------------------< RESEL_GO >-------------------*/,{
2924 SCR_LOAD_REL (dsa
, 4),
2926 SCR_LOAD_REL (temp
, 4),
2927 offsetof(struct ccb
, phys
.header
.go
.restart
),
2930 }/*-------------------------< RESEL_NOTAG >-------------------*/,{
2933 ** Read an throw away the IDENTIFY.
2935 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2938 ** JUMP indirectly to the restart point of the CCB.
2943 }/*-------------------------< RESEL_DSA >-------------------*/,{
2945 ** Ack the IDENTIFY or TAG previously received.
2950 ** load the savep (saved pointer) into
2951 ** the actual data pointer.
2953 SCR_LOAD_REL (temp
, 4),
2954 offsetof (struct ccb
, phys
.header
.savep
),
2956 ** Initialize the status registers
2958 SCR_LOAD_REL (scr0
, 4),
2959 offsetof (struct ccb
, phys
.header
.status
),
2961 ** Jump to dispatcher.
2966 }/*-------------------------< DATA_IN >--------------------*/,{
2968 ** Because the size depends on the
2969 ** #define MAX_SCATTERL parameter,
2970 ** it is filled in at runtime.
2972 ** ##===========< i=0; i<MAX_SCATTERL >=========
2973 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2974 ** || PADDR (databreak),
2975 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
2976 ** || offsetof (struct dsb, data[ i]),
2977 ** ##==========================================
2979 **---------------------------------------------------------
2982 }/*-------------------------< DATA_IN2 >-------------------*/,{
2987 }/*-------------------------< DATA_OUT >--------------------*/,{
2989 ** Because the size depends on the
2990 ** #define MAX_SCATTERL parameter,
2991 ** it is filled in at runtime.
2993 ** ##===========< i=0; i<MAX_SCATTERL >=========
2994 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2995 ** || PADDR (databreak),
2996 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
2997 ** || offsetof (struct dsb, data[ i]),
2998 ** ##==========================================
3000 **---------------------------------------------------------
3003 }/*-------------------------< DATA_OUT2 >-------------------*/,{
3009 }/*-------------------------< PM0_DATA >--------------------*/,{
3011 ** Keep track we are executing the PM0 DATA
3014 SCR_REG_REG (HF_REG
, SCR_OR
, HF_IN_PM0
),
3017 ** MOVE the data according to the actual
3020 SCR_JUMPR
^ IFFALSE (WHEN (SCR_DATA_IN
)),
3022 SCR_MOVE_TBL
^ SCR_DATA_IN
,
3023 offsetof (struct ccb
, phys
.pm0
.sg
),
3026 SCR_MOVE_TBL
^ SCR_DATA_OUT
,
3027 offsetof (struct ccb
, phys
.pm0
.sg
),
3029 ** Clear the flag that told we were in
3030 ** the PM0 DATA mini-script.
3032 SCR_REG_REG (HF_REG
, SCR_AND
, (~HF_IN_PM0
)),
3035 ** Return to the previous DATA script which
3036 ** is guaranteed by design (if no bug) to be
3037 ** the main DATA script for this transfer.
3039 SCR_LOAD_REL (temp
, 4),
3040 offsetof (struct ccb
, phys
.pm0
.ret
),
3043 }/*-------------------------< PM1_DATA >--------------------*/,{
3045 ** Keep track we are executing the PM1 DATA
3048 SCR_REG_REG (HF_REG
, SCR_OR
, HF_IN_PM1
),
3051 ** MOVE the data according to the actual
3054 SCR_JUMPR
^ IFFALSE (WHEN (SCR_DATA_IN
)),
3056 SCR_MOVE_TBL
^ SCR_DATA_IN
,
3057 offsetof (struct ccb
, phys
.pm1
.sg
),
3060 SCR_MOVE_TBL
^ SCR_DATA_OUT
,
3061 offsetof (struct ccb
, phys
.pm1
.sg
),
3063 ** Clear the flag that told we were in
3064 ** the PM1 DATA mini-script.
3066 SCR_REG_REG (HF_REG
, SCR_AND
, (~HF_IN_PM1
)),
3069 ** Return to the previous DATA script which
3070 ** is guaranteed by design (if no bug) to be
3071 ** the main DATA script for this transfer.
3073 SCR_LOAD_REL (temp
, 4),
3074 offsetof (struct ccb
, phys
.pm1
.ret
),
3078 }/*-------------------------< SAVED_DSA >-------------------*/,{
3080 }/*-------------------------< DONE_POS >--------------------*/,{
3082 }/*-------------------------< STARTPOS >--------------------*/,{
3084 }/*-------------------------< TARGTBL >---------------------*/,{
3086 }/*--------------------------------------------------------*/
3089 static struct scripth scripth0 __initdata
= {
3090 /*------------------------< START64 >-----------------------*/{
3092 ** SCRIPT entry point for the 896.
3093 ** For now, there is no specific stuff for that
3094 ** chip at this point, but this may come.
3098 }/*------------------------< SELECT_NO_ATN >-----------------*/,{
3100 ** Set Initiator mode.
3101 ** And try to select this target without ATN.
3106 SCR_SEL_TBL
^ offsetof (struct dsb
, select
),
3108 }/*------------------------< WF_SEL_DONE_NO_ATN >-----------------*/,{
3110 ** Wait immediately for the next phase or
3111 ** the selection to complete or time-out.
3113 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3118 }/*-------------------------< CANCEL >------------------------*/,{
3120 ** Load the host status.
3122 SCR_LOAD_REG (HS_REG
, HS_ABORTED
),
3127 }/*-------------------------< MSG_REJECT >---------------*/,{
3129 ** If a negotiation was in progress,
3130 ** negotiation failed.
3131 ** Otherwise just make host log this message
3133 SCR_FROM_REG (HS_REG
),
3135 SCR_INT
^ IFFALSE (DATA (HS_NEGOTIATE
)),
3136 SIR_REJECT_RECEIVED
,
3137 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
3142 }/*-------------------------< MSG_IGN_RESIDUE >----------*/,{
3148 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3151 ** get residue size.
3153 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3156 ** Size is 0 .. ignore message.
3158 SCR_JUMP
^ IFTRUE (DATA (0)),
3161 ** Size is not 1 .. have to interrupt.
3163 SCR_JUMPR
^ IFFALSE (DATA (1)),
3166 ** Check for residue byte in swide register
3168 SCR_FROM_REG (scntl2
),
3170 SCR_JUMPR
^ IFFALSE (MASK (WSR
, WSR
)),
3173 ** There IS data in the swide register.
3176 SCR_REG_REG (scntl2
, SCR_OR
, WSR
),
3181 ** Load again the size to the sfbr register.
3183 SCR_FROM_REG (scratcha
),
3190 }/*-------------------------< MSG_EXTENDED >-------------*/,{
3196 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3201 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3205 SCR_JUMP
^ IFTRUE (DATA (3)),
3207 SCR_JUMP
^ IFFALSE (DATA (2)),
3209 }/*-------------------------< MSG_EXT_2 >----------------*/,{
3212 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3215 ** get extended message code.
3217 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3219 SCR_JUMP
^ IFTRUE (DATA (M_X_WIDE_REQ
)),
3222 ** unknown extended message
3226 }/*-------------------------< MSG_WDTR >-----------------*/,{
3229 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3232 ** get data bus width
3234 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3237 ** let the host do the real work.
3242 ** let the target fetch our answer.
3248 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3249 PADDRH (nego_bad_phase
),
3251 }/*-------------------------< SEND_WDTR >----------------*/,{
3253 ** Send the M_X_WIDE_REQ
3255 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT
,
3258 PADDRH (msg_out_done
),
3260 }/*-------------------------< MSG_EXT_3 >----------------*/,{
3263 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3266 ** get extended message code.
3268 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3270 SCR_JUMP
^ IFTRUE (DATA (M_X_SYNC_REQ
)),
3273 ** unknown extended message
3278 }/*-------------------------< MSG_SDTR >-----------------*/,{
3281 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3284 ** get period and offset
3286 SCR_MOVE_ABS (2) ^ SCR_MSG_IN
,
3289 ** let the host do the real work.
3294 ** let the target fetch our answer.
3300 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3301 PADDRH (nego_bad_phase
),
3303 }/*-------------------------< SEND_SDTR >-------------*/,{
3305 ** Send the M_X_SYNC_REQ
3307 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT
,
3310 PADDRH (msg_out_done
),
3312 }/*-------------------------< NEGO_BAD_PHASE >------------*/,{
3318 }/*-------------------------< MSG_OUT_ABORT >-------------*/,{
3320 ** After ABORT message,
3322 ** expect an immediate disconnect, ...
3324 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
3326 SCR_CLR (SCR_ACK
|SCR_ATN
),
3333 ** ... and set the status to "ABORTED"
3335 SCR_LOAD_REG (HS_REG
, HS_ABORTED
),
3340 }/*-------------------------< MSG_OUT >-------------------*/,{
3342 ** The target requests a message.
3344 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
3347 ** If it was no ABORT message ...
3349 SCR_JUMP
^ IFTRUE (DATA (M_ABORT
)),
3350 PADDRH (msg_out_abort
),
3352 ** ... wait for the next phase
3353 ** if it's a message out, send it again, ...
3355 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
3357 }/*-------------------------< MSG_OUT_DONE >--------------*/,{
3359 ** ... else clear the message ...
3364 ** ... and process the next phase
3369 }/*-------------------------< NO_DATA >--------------------*/,{
3371 ** The target wants to tranfer too much data
3372 ** or in the wrong direction.
3373 ** Remember that in extended error.
3375 SCR_LOAD_REG (scratcha
, XE_EXTRA_DATA
),
3377 SCR_STORE_REL (scratcha
, 1),
3378 offsetof (struct ccb
, xerr_status
),
3380 ** Discard one data byte, if required.
3382 SCR_JUMPR
^ IFFALSE (WHEN (SCR_DATA_OUT
)),
3384 SCR_MOVE_ABS (1) ^ SCR_DATA_OUT
,
3386 SCR_JUMPR
^ IFFALSE (IF (SCR_DATA_IN
)),
3388 SCR_MOVE_ABS (1) ^ SCR_DATA_IN
,
3391 ** .. and repeat as required.
3398 #if MAX_SCATTERH != 0
3400 }/*-------------------------< HDATA_IN >-------------------*/,{
3402 ** Because the size depends on the
3403 ** #define MAX_SCATTERH parameter,
3404 ** it is filled in at runtime.
3406 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
3407 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
3408 ** || PADDR (databreak),
3409 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
3410 ** || offsetof (struct dsb, data[ i]),
3411 ** ##===================================================
3413 **---------------------------------------------------------
3416 }/*-------------------------< HDATA_IN2 >------------------*/,{
3420 }/*-------------------------< HDATA_OUT >-------------------*/,{
3422 ** Because the size depends on the
3423 ** #define MAX_SCATTERH parameter,
3424 ** it is filled in at runtime.
3426 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
3427 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
3428 ** || PADDR (databreak),
3429 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
3430 ** || offsetof (struct dsb, data[ i]),
3431 ** ##===================================================
3433 **---------------------------------------------------------
3436 }/*-------------------------< HDATA_OUT2 >------------------*/,{
3440 #endif /* MAX_SCATTERH */
3442 }/*-------------------------< ABORT_RESEL >----------------*/,{
3448 ** send the abort/abortag/reset message
3449 ** we expect an immediate disconnect
3451 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
3453 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
3455 SCR_CLR (SCR_ACK
|SCR_ATN
),
3463 }/*-------------------------< RESEND_IDENT >-------------------*/,{
3465 ** The target stays in MSG OUT phase after having acked
3466 ** Identify [+ Tag [+ Extended message ]]. Targets shall
3467 ** behave this way on parity error.
3468 ** We must send it again all the messages.
3470 SCR_SET (SCR_ATN
), /* Shall be asserted 2 deskew delays before the */
3471 0, /* 1rst ACK = 90 ns. Hope the NCR is'nt too fast */
3474 }/*-------------------------< IDENT_BREAK >-------------------*/,{
3479 }/*-------------------------< IDENT_BREAK_ATN >----------------*/,{
3484 }/*-------------------------< SDATA_IN >-------------------*/,{
3485 SCR_MOVE_TBL
^ SCR_DATA_IN
,
3486 offsetof (struct dsb
, sense
),
3492 }/*-------------------------< DATA_IO >--------------------*/,{
3494 ** We jump here if the data direction was unknown at the
3495 ** time we had to queue the command to the scripts processor.
3496 ** Pointers had been set as follow in this situation:
3497 ** savep --> DATA_IO
3498 ** lastp --> start pointer when DATA_IN
3499 ** goalp --> goal pointer when DATA_IN
3500 ** wlastp --> start pointer when DATA_OUT
3501 ** wgoalp --> goal pointer when DATA_OUT
3502 ** This script sets savep/lastp/goalp according to the
3503 ** direction chosen by the target.
3505 SCR_JUMP
^ IFTRUE (WHEN (SCR_DATA_OUT
)),
3506 PADDRH(data_io_out
),
3507 }/*-------------------------< DATA_IO_COM >-----------------*/,{
3509 ** Direction is DATA IN.
3510 ** Warning: we jump here, even when phase is DATA OUT.
3512 SCR_LOAD_REL (scratcha
, 4),
3513 offsetof (struct ccb
, phys
.header
.lastp
),
3514 SCR_STORE_REL (scratcha
, 4),
3515 offsetof (struct ccb
, phys
.header
.savep
),
3518 ** Jump to the SCRIPTS according to actual direction.
3520 SCR_LOAD_REL (temp
, 4),
3521 offsetof (struct ccb
, phys
.header
.savep
),
3524 }/*-------------------------< DATA_IO_OUT >-----------------*/,{
3526 ** Direction is DATA OUT.
3528 SCR_LOAD_REL (scratcha
, 4),
3529 offsetof (struct ccb
, phys
.header
.wlastp
),
3530 SCR_STORE_REL (scratcha
, 4),
3531 offsetof (struct ccb
, phys
.header
.lastp
),
3532 SCR_LOAD_REL (scratcha
, 4),
3533 offsetof (struct ccb
, phys
.header
.wgoalp
),
3534 SCR_STORE_REL (scratcha
, 4),
3535 offsetof (struct ccb
, phys
.header
.goalp
),
3537 PADDRH(data_io_com
),
3539 }/*-------------------------< BAD_IDENTIFY >---------------*/,{
3541 ** If message phase but not an IDENTIFY,
3542 ** get some help from the C code.
3543 ** Old SCSI device may behave so.
3545 SCR_JUMPR
^ IFTRUE (MASK (0x80, 0x80)),
3548 SIR_RESEL_NO_IDENTIFY
,
3550 PADDRH (abort_resel
),
3552 ** Message is an IDENTIFY, but lun is unknown.
3553 ** Read the message, since we got it directly
3554 ** from the SCSI BUS data lines.
3555 ** Signal problem to C code for logging the event.
3556 ** Send a M_ABORT to clear all pending tasks.
3560 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3563 PADDRH (abort_resel
),
3564 }/*-------------------------< BAD_I_T_L >------------------*/,{
3566 ** We donnot have a task for that I_T_L.
3567 ** Signal problem to C code for logging the event.
3568 ** Send a M_ABORT message.
3571 SIR_RESEL_BAD_I_T_L
,
3573 PADDRH (abort_resel
),
3574 }/*-------------------------< BAD_I_T_L_Q >----------------*/,{
3576 ** We donnot have a task that matches the tag.
3577 ** Signal problem to C code for logging the event.
3578 ** Send a M_ABORTTAG message.
3581 SIR_RESEL_BAD_I_T_L_Q
,
3583 PADDRH (abort_resel
),
3584 }/*-------------------------< BAD_STATUS >-----------------*/,{
3586 ** If command resulted in either QUEUE FULL,
3587 ** CHECK CONDITION or COMMAND TERMINATED,
3590 SCR_LOAD_ABS (scratcha
, 4),
3592 SCR_INT
^ IFTRUE (DATA (S_QUEUE_FULL
)),
3594 SCR_INT
^ IFTRUE (DATA (S_CHECK_COND
)),
3596 SCR_INT
^ IFTRUE (DATA (S_TERMINATED
)),
3601 }/*-------------------------< TWEAK_PMJ >------------------*/,{
3603 ** Disable PM handling from SCRIPTS for the data phase
3604 ** and so force PM to be handled from C code if HF_PM_TO_C
3607 SCR_FROM_REG(HF_REG
),
3609 SCR_JUMPR
^ IFTRUE (MASK (HF_PM_TO_C
, HF_PM_TO_C
)),
3611 SCR_REG_REG (ccntl0
, SCR_OR
, ENPMJ
),
3615 SCR_REG_REG (ccntl0
, SCR_AND
, (~ENPMJ
)),
3620 }/*-------------------------< PM_HANDLE >------------------*/,{
3622 ** Phase mismatch handling.
3624 ** Since we have to deal with 2 SCSI data pointers
3625 ** (current and saved), we need at least 2 contexts.
3626 ** Each context (pm0 and pm1) has a saved area, a
3627 ** SAVE mini-script and a DATA phase mini-script.
3630 ** Get the PM handling flags.
3632 SCR_FROM_REG (HF_REG
),
3635 ** If no flags (1rst PM for example), avoid
3636 ** all the below heavy flags testing.
3637 ** This makes the normal case a bit faster.
3639 SCR_JUMP
^ IFTRUE (MASK (0, (HF_IN_PM0
| HF_IN_PM1
| HF_DP_SAVED
))),
3640 PADDRH (pm_handle1
),
3642 ** If we received a SAVE DP, switch to the
3643 ** other PM context since the savep may point
3644 ** to the current PM context.
3646 SCR_JUMPR
^ IFFALSE (MASK (HF_DP_SAVED
, HF_DP_SAVED
)),
3648 SCR_REG_REG (sfbr
, SCR_XOR
, HF_ACT_PM
),
3651 ** If we have been interrupt in a PM DATA mini-script,
3652 ** we take the return address from the corresponding
3654 ** This ensure the return address always points to the
3655 ** main DATA script for this transfer.
3657 SCR_JUMP
^ IFTRUE (MASK (0, (HF_IN_PM0
| HF_IN_PM1
))),
3658 PADDRH (pm_handle1
),
3659 SCR_JUMPR
^ IFFALSE (MASK (HF_IN_PM0
, HF_IN_PM0
)),
3661 SCR_LOAD_REL (ia
, 4),
3662 offsetof(struct ccb
, phys
.pm0
.ret
),
3665 SCR_LOAD_REL (ia
, 4),
3666 offsetof(struct ccb
, phys
.pm1
.ret
),
3669 }/*-------------------------< PM_HANDLE1 >-----------------*/,{
3672 ** Update the return address so that it
3673 ** will point after the interrupted MOVE.
3675 SCR_REG_REG (ia
, SCR_ADD
, 8),
3677 SCR_REG_REG (ia1
, SCR_ADDC
, 0),
3679 }/*-------------------------< PM_SAVE >--------------------*/,{
3681 ** Clear all the flags that told us if we were
3682 ** interrupted in a PM DATA mini-script and/or
3683 ** we received a SAVE DP.
3685 SCR_SFBR_REG (HF_REG
, SCR_AND
, (~(HF_IN_PM0
|HF_IN_PM1
|HF_DP_SAVED
))),
3688 ** Choose the current PM context.
3690 SCR_JUMP
^ IFTRUE (MASK (HF_ACT_PM
, HF_ACT_PM
)),
3692 }/*-------------------------< PM0_SAVE >-------------------*/,{
3694 ** Save the remaining byte count, the updated
3695 ** address and the return address.
3697 SCR_STORE_REL (rbc
, 4),
3698 offsetof(struct ccb
, phys
.pm0
.sg
.size
),
3699 SCR_STORE_REL (ua
, 4),
3700 offsetof(struct ccb
, phys
.pm0
.sg
.addr
),
3701 SCR_STORE_REL (ia
, 4),
3702 offsetof(struct ccb
, phys
.pm0
.ret
),
3704 ** Set the current pointer at the PM0 DATA mini-script.
3706 SCR_LOAD_ABS (temp
, 4),
3707 PADDRH (pm0_data_addr
),
3710 }/*-------------------------< PM1_SAVE >-------------------*/,{
3712 ** Save the remaining byte count, the updated
3713 ** address and the return address.
3715 SCR_STORE_REL (rbc
, 4),
3716 offsetof(struct ccb
, phys
.pm1
.sg
.size
),
3717 SCR_STORE_REL (ua
, 4),
3718 offsetof(struct ccb
, phys
.pm1
.sg
.addr
),
3719 SCR_STORE_REL (ia
, 4),
3720 offsetof(struct ccb
, phys
.pm1
.ret
),
3722 ** Set the current pointer at the PM1 DATA mini-script.
3724 SCR_LOAD_ABS (temp
, 4),
3725 PADDRH (pm1_data_addr
),
3728 }/*-------------------------< PM0_DATA_ADDR >---------------*/,{
3730 }/*-------------------------< PM1_DATA_ADDR >---------------*/,{
3732 }/*-------------------------< START_RAM >-------------------*/,{
3734 ** Load the script into on-chip RAM,
3735 ** and jump to start point.
3737 SCR_COPY (sizeof (struct script
)),
3738 }/*-------------------------< SCRIPT0_BA >--------------------*/,{
3744 }/*-------------------------< START_RAM64 >--------------------*/,{
3746 ** Load the RAM and start for 64 bit PCI (896).
3747 ** Both scripts (script and scripth) are loaded into
3748 ** the RAM which is 8K (4K for 825A/875/895).
3749 ** We also need to load some 32-63 bit segments
3750 ** address of the SCRIPTS processor.
3751 ** LOAD/STORE ABSOLUTE always refers to on-chip RAM
3752 ** in our implementation. The main memory is
3753 ** accessed using LOAD/STORE DSA RELATIVE.
3755 SCR_LOAD_REL (mmws
, 4),
3756 offsetof (struct ncb
, scr_ram_seg
),
3757 SCR_COPY (sizeof(struct script
)),
3758 }/*-------------------------< SCRIPT0_BA64 >--------------------*/,{
3761 SCR_COPY (sizeof(struct scripth
)),
3762 }/*-------------------------< SCRIPTH0_BA64 >--------------------*/,{
3765 SCR_LOAD_REL (mmrs
, 4),
3766 offsetof (struct ncb
, scr_ram_seg
),
3769 }/*-------------------------< RAM_SEG64 >--------------------*/,{
3771 }/*-------------------------< SNOOPTEST >-------------------*/,{
3773 ** Read the variable.
3775 SCR_LOAD_REL (scratcha
, 4),
3776 offsetof(struct ncb
, ncr_cache
),
3777 SCR_STORE_REL (temp
, 4),
3778 offsetof(struct ncb
, ncr_cache
),
3779 SCR_LOAD_REL (temp
, 4),
3780 offsetof(struct ncb
, ncr_cache
),
3781 }/*-------------------------< SNOOPEND >-------------------*/,{
3787 }/*--------------------------------------------------------*/
3790 /*==========================================================
3793 ** Fill in #define dependent parts of the script
3796 **==========================================================
3799 void __init
ncr_script_fill (struct script
* scr
, struct scripth
* scrh
)
3804 #if MAX_SCATTERH != 0
3806 for (i
=0; i
<MAX_SCATTERH
; i
++) {
3807 #if SCR_SG_SIZE == 4
3808 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
3809 *p
++ =PADDR (databreak
);
3811 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
3812 *p
++ =offsetof (struct dsb
, data
[i
]);
3814 assert ((u_long
)p
== (u_long
)&scrh
->hdata_in
+ sizeof (scrh
->hdata_in
));
3818 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
3819 #if SCR_SG_SIZE == 4
3820 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
3821 *p
++ =PADDR (databreak
);
3823 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
3824 *p
++ =offsetof (struct dsb
, data
[i
]);
3826 assert ((u_long
)p
== (u_long
)&scr
->data_in
+ sizeof (scr
->data_in
));
3828 #if MAX_SCATTERH != 0
3829 p
= scrh
->hdata_out
;
3830 for (i
=0; i
<MAX_SCATTERH
; i
++) {
3831 #if SCR_SG_SIZE == 4
3832 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
3833 *p
++ =PADDR (databreak
);
3835 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
3836 *p
++ =offsetof (struct dsb
, data
[i
]);
3838 assert ((u_long
)p
==(u_long
)&scrh
->hdata_out
+ sizeof (scrh
->hdata_out
));
3842 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
3843 #if SCR_SG_SIZE == 4
3844 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
3845 *p
++ =PADDR (databreak
);
3847 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
3848 *p
++ =offsetof (struct dsb
, data
[i
]);
3851 assert ((u_long
)p
== (u_long
)&scr
->data_out
+ sizeof (scr
->data_out
));
3854 /*==========================================================
3857 ** Copy and rebind a script.
3860 **==========================================================
3863 static void __init
ncr_script_copy_and_bind (ncb_p np
,ncrcmd
*src
,ncrcmd
*dst
,int len
)
3865 ncrcmd opcode
, new, old
, tmp1
, tmp2
;
3866 ncrcmd
*start
, *end
;
3876 *dst
++ = cpu_to_scr(opcode
);
3879 ** If we forget to change the length
3880 ** in struct script, a field will be
3881 ** padded with 0. This is an illegal
3886 printk (KERN_INFO
"%s: ERROR0 IN SCRIPT at %d.\n",
3887 ncr_name(np
), (int) (src
-start
-1));
3893 ** We use the bogus value 0xf00ff00f ;-)
3894 ** to reserve data area in SCRIPTS.
3896 if (opcode
== SCR_DATA_ZERO
) {
3901 if (DEBUG_FLAGS
& DEBUG_SCRIPT
)
3902 printk (KERN_INFO
"%p: <%x>\n",
3903 (src
-1), (unsigned)opcode
);
3906 ** We don't have to decode ALL commands
3908 switch (opcode
>> 28) {
3912 ** LOAD / STORE DSA relative, don't relocate.
3918 ** LOAD / STORE absolute.
3924 ** COPY has TWO arguments.
3930 if ((tmp1
& RELOC_MASK
) == RELOC_KVAR
)
3932 if ((tmp2
& RELOC_MASK
) == RELOC_KVAR
)
3935 if ((tmp1
^ tmp2
) & 3) {
3936 printk (KERN_ERR
"%s: ERROR1 IN SCRIPT at %d.\n",
3937 ncr_name(np
), (int) (src
-start
-1));
3941 ** If PREFETCH feature not enabled, remove
3942 ** the NO FLUSH bit if present.
3944 if ((opcode
& SCR_NO_FLUSH
) &&
3945 !(np
->features
& FE_PFEN
)) {
3946 dst
[-1] = cpu_to_scr(opcode
& ~SCR_NO_FLUSH
);
3953 ** MOVE (absolute address)
3961 ** dont't relocate if relative :-)
3963 if (opcode
& 0x00800000)
3965 else if ((opcode
& 0xf8400000) == 0x80400000)/*JUMP64*/
3984 *dst
++ = cpu_to_scr(*src
++);
3990 switch (old
& RELOC_MASK
) {
3991 case RELOC_REGISTER
:
3992 new = (old
& ~RELOC_MASK
) + pcivtobus(np
->base_ba
);
3995 new = (old
& ~RELOC_MASK
) + np
->p_script
;
3998 new = (old
& ~RELOC_MASK
) + np
->p_scripth
;
4001 new = (old
& ~RELOC_MASK
) + vtobus(np
);
4005 if (((old
& ~RELOC_MASK
) < SCRIPT_KVAR_FIRST
) ||
4006 ((old
& ~RELOC_MASK
) > SCRIPT_KVAR_LAST
))
4007 panic("ncr KVAR out of range");
4008 new = vtobus(script_kvars
[old
& ~RELOC_MASK
]);
4012 /* Don't relocate a 0 address. */
4019 panic("ncr_script_copy_and_bind: "
4020 "weird relocation %x\n", old
);
4024 *dst
++ = cpu_to_scr(new);
4029 /*==========================================================
4032 ** Auto configuration: attach and init a host adapter.
4035 **==========================================================
4039 ** Linux host data structure.
4047 ** Print something which allows to retrieve the controler type, unit,
4048 ** target, lun concerned by a kernel message.
4051 static void PRINT_TARGET(ncb_p np
, int target
)
4053 printk(KERN_INFO
"%s-<%d,*>: ", ncr_name(np
), target
);
4056 static void PRINT_LUN(ncb_p np
, int target
, int lun
)
4058 printk(KERN_INFO
"%s-<%d,%d>: ", ncr_name(np
), target
, lun
);
4061 static void PRINT_ADDR(Scsi_Cmnd
*cmd
)
4063 struct host_data
*host_data
= (struct host_data
*) cmd
->host
->hostdata
;
4064 PRINT_LUN(host_data
->ncb
, cmd
->target
, cmd
->lun
);
4067 /*==========================================================
4069 ** NCR chip clock divisor table.
4070 ** Divisors are multiplied by 10,000,000 in order to make
4071 ** calculations more simple.
4073 **==========================================================
4077 static u_long div_10M
[] =
4078 {2*_5M
, 3*_5M
, 4*_5M
, 6*_5M
, 8*_5M
, 12*_5M
, 16*_5M
};
4081 /*===============================================================
4083 ** Prepare io register values used by ncr_init() according
4084 ** to selected and supported features.
4086 ** NCR chips allow burst lengths of 2, 4, 8, 16, 32, 64, 128
4087 ** transfers. 32,64,128 are only supported by 825A, 875, 895
4089 ** We use log base 2 (burst length) as internal code, with
4090 ** value 0 meaning "burst disabled".
4092 **===============================================================
4096 * Burst length from burst code.
4098 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
4101 * Burst code from io register bits.
4103 #define burst_code(dmode, ctest4, ctest5) \
4104 (ctest4) & 0x80? 0 : (((dmode) & 0xc0) >> 6) + ((ctest5) & 0x04) + 1
4107 * Set initial io register bits from burst code.
4109 static inline void ncr_init_burst(ncb_p np
, u_char bc
)
4111 np
->rv_ctest4
&= ~0x80;
4112 np
->rv_dmode
&= ~(0x3 << 6);
4113 np
->rv_ctest5
&= ~0x4;
4116 np
->rv_ctest4
|= 0x80;
4120 np
->rv_dmode
|= ((bc
& 0x3) << 6);
4121 np
->rv_ctest5
|= (bc
& 0x4);
4125 #ifdef SCSI_NCR_NVRAM_SUPPORT
4128 ** Get target set-up from Symbios format NVRAM.
4132 ncr_Symbios_setup_target(ncb_p np
, int target
, Symbios_nvram
*nvram
)
4134 tcb_p tp
= &np
->target
[target
];
4135 Symbios_target
*tn
= &nvram
->target
[target
];
4137 tp
->usrsync
= tn
->sync_period
? (tn
->sync_period
+ 3) / 4 : 255;
4138 tp
->usrwide
= tn
->bus_width
== 0x10 ? 1 : 0;
4140 (tn
->flags
& SYMBIOS_QUEUE_TAGS_ENABLED
)? SCSI_NCR_MAX_TAGS
: 0;
4142 if (!(tn
->flags
& SYMBIOS_DISCONNECT_ENABLE
))
4143 tp
->usrflag
|= UF_NODISC
;
4144 if (!(tn
->flags
& SYMBIOS_SCAN_AT_BOOT_TIME
))
4145 tp
->usrflag
|= UF_NOSCAN
;
4149 ** Get target set-up from Tekram format NVRAM.
4153 ncr_Tekram_setup_target(ncb_p np
, int target
, Tekram_nvram
*nvram
)
4155 tcb_p tp
= &np
->target
[target
];
4156 struct Tekram_target
*tn
= &nvram
->target
[target
];
4159 if (tn
->flags
& TEKRAM_SYNC_NEGO
) {
4160 i
= tn
->sync_index
& 0xf;
4161 tp
->usrsync
= i
< 12 ? Tekram_sync
[i
] : 255;
4164 tp
->usrwide
= (tn
->flags
& TEKRAM_WIDE_NEGO
) ? 1 : 0;
4166 if (tn
->flags
& TEKRAM_TAGGED_COMMANDS
) {
4167 tp
->usrtags
= 2 << nvram
->max_tags_index
;
4170 if (!(tn
->flags
& TEKRAM_DISCONNECT_ENABLE
))
4171 tp
->usrflag
= UF_NODISC
;
4173 /* If any device does not support parity, we will not use this option */
4174 if (!(tn
->flags
& TEKRAM_PARITY_CHECK
))
4175 np
->rv_scntl0
&= ~0x0a; /* SCSI parity checking disabled */
4177 #endif /* SCSI_NCR_NVRAM_SUPPORT */
4179 static int __init
ncr_prepare_setting(ncb_p np
, ncr_nvram
*nvram
)
4186 ** Save assumed BIOS setting
4189 np
->sv_scntl0
= INB(nc_scntl0
) & 0x0a;
4190 np
->sv_scntl3
= INB(nc_scntl3
) & 0x07;
4191 np
->sv_dmode
= INB(nc_dmode
) & 0xce;
4192 np
->sv_dcntl
= INB(nc_dcntl
) & 0xa8;
4193 np
->sv_ctest3
= INB(nc_ctest3
) & 0x01;
4194 np
->sv_ctest4
= INB(nc_ctest4
) & 0x80;
4195 np
->sv_ctest5
= INB(nc_ctest5
) & 0x24;
4196 np
->sv_gpcntl
= INB(nc_gpcntl
);
4197 np
->sv_stest2
= INB(nc_stest2
) & 0x20;
4198 np
->sv_stest4
= INB(nc_stest4
);
4204 np
->maxwide
= (np
->features
& FE_WIDE
)? 1 : 0;
4207 ** Get the frequency of the chip's clock.
4208 ** Find the right value for scntl3.
4211 if (np
->features
& FE_QUAD
)
4213 else if (np
->features
& FE_DBLR
)
4218 np
->clock_khz
= (np
->features
& FE_CLK80
)? 80000 : 40000;
4219 np
->clock_khz
*= np
->multiplier
;
4221 if (np
->clock_khz
!= 40000)
4222 ncr_getclock(np
, np
->multiplier
);
4225 * Divisor to be used for async (timer pre-scaler).
4227 i
= np
->clock_divn
- 1;
4229 if (10ul * SCSI_NCR_MIN_ASYNC
* np
->clock_khz
> div_10M
[i
]) {
4234 np
->rv_scntl3
= i
+1;
4237 * Minimum synchronous period factor supported by the chip.
4238 * Btw, 'period' is in tenths of nanoseconds.
4241 period
= (4 * div_10M
[0] + np
->clock_khz
- 1) / np
->clock_khz
;
4242 if (period
<= 250) np
->minsync
= 10;
4243 else if (period
<= 303) np
->minsync
= 11;
4244 else if (period
<= 500) np
->minsync
= 12;
4245 else np
->minsync
= (period
+ 40 - 1) / 40;
4248 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
4251 if (np
->minsync
< 25 && !(np
->features
& (FE_ULTRA
|FE_ULTRA2
)))
4253 else if (np
->minsync
< 12 && !(np
->features
& FE_ULTRA2
))
4257 * Maximum synchronous period factor supported by the chip.
4260 period
= (11 * div_10M
[np
->clock_divn
- 1]) / (4 * np
->clock_khz
);
4261 np
->maxsync
= period
> 2540 ? 254 : period
/ 10;
4264 ** 64 bit (53C896) ?
4266 if (np
->features
& FE_64BIT
)
4267 #if BITS_PER_LONG > 32
4268 np
->rv_ccntl1
|= (XTIMOD
| EXTIBMV
);
4270 np
->rv_ccntl1
|= (DDAC
);
4274 ** Phase mismatch handled by SCRIPTS (53C896) ?
4276 if (np
->features
& FE_NOPM
)
4277 np
->rv_ccntl0
|= (ENPMJ
);
4280 ** Prepare initial value of other IO registers
4282 #if defined SCSI_NCR_TRUST_BIOS_SETTING
4283 np
->rv_scntl0
= np
->sv_scntl0
;
4284 np
->rv_dmode
= np
->sv_dmode
;
4285 np
->rv_dcntl
= np
->sv_dcntl
;
4286 np
->rv_ctest3
= np
->sv_ctest3
;
4287 np
->rv_ctest4
= np
->sv_ctest4
;
4288 np
->rv_ctest5
= np
->sv_ctest5
;
4289 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest4
, np
->sv_ctest5
);
4293 ** Select burst length (dwords)
4295 burst_max
= driver_setup
.burst_max
;
4296 if (burst_max
== 255)
4297 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest4
, np
->sv_ctest5
);
4300 if (burst_max
> np
->maxburst
)
4301 burst_max
= np
->maxburst
;
4304 ** DEL 352 - 53C810 Rev x11 - Part Number 609-0392140 - ITEM 2.
4305 ** This chip and the 860 Rev 1 may wrongly use PCI cache line
4306 ** based transactions on LOAD/STORE instructions. So we have
4307 ** to prevent these chips from using such PCI transactions in
4308 ** this driver. The generic sym53c8xx driver that does not use
4309 ** LOAD/STORE instructions does not need this work-around.
4311 if ((np
->device_id
== PCI_DEVICE_ID_NCR_53C810
&&
4312 np
->revision_id
>= 0x10 && np
->revision_id
<= 0x11) ||
4313 (np
->device_id
== PCI_DEVICE_ID_NCR_53C860
&&
4314 np
->revision_id
<= 0x1))
4315 np
->features
&= ~(FE_WRIE
|FE_ERL
|FE_ERMP
);
4318 ** Select all supported special features.
4319 ** If we are using on-board RAM for scripts, prefetch (PFEN)
4320 ** does not help, but burst op fetch (BOF) does.
4321 ** Disabling PFEN makes sure BOF will be used.
4323 if (np
->features
& FE_ERL
)
4324 np
->rv_dmode
|= ERL
; /* Enable Read Line */
4325 if (np
->features
& FE_BOF
)
4326 np
->rv_dmode
|= BOF
; /* Burst Opcode Fetch */
4327 if (np
->features
& FE_ERMP
)
4328 np
->rv_dmode
|= ERMP
; /* Enable Read Multiple */
4329 #ifdef SCSI_NCR_OPTIMIZE_896
4330 if ((np
->features
& FE_PFEN
) && !np
->base2_ba
)
4332 if (np
->features
& FE_PFEN
)
4334 np
->rv_dcntl
|= PFEN
; /* Prefetch Enable */
4335 if (np
->features
& FE_CLSE
)
4336 np
->rv_dcntl
|= CLSE
; /* Cache Line Size Enable */
4337 if (np
->features
& FE_WRIE
)
4338 np
->rv_ctest3
|= WRIE
; /* Write and Invalidate */
4339 if (np
->features
& FE_DFS
)
4340 np
->rv_ctest5
|= DFS
; /* Dma Fifo Size */
4343 ** Select some other
4345 if (driver_setup
.master_parity
)
4346 np
->rv_ctest4
|= MPEE
; /* Master parity checking */
4347 if (driver_setup
.scsi_parity
)
4348 np
->rv_scntl0
|= 0x0a; /* full arb., ena parity, par->ATN */
4350 #ifdef SCSI_NCR_NVRAM_SUPPORT
4352 ** Get parity checking, host ID and verbose mode from NVRAM
4355 switch(nvram
->type
) {
4356 case SCSI_NCR_TEKRAM_NVRAM
:
4357 np
->myaddr
= nvram
->data
.Tekram
.host_id
& 0x0f;
4359 case SCSI_NCR_SYMBIOS_NVRAM
:
4360 if (!(nvram
->data
.Symbios
.flags
& SYMBIOS_PARITY_ENABLE
))
4361 np
->rv_scntl0
&= ~0x0a;
4362 np
->myaddr
= nvram
->data
.Symbios
.host_id
& 0x0f;
4363 if (nvram
->data
.Symbios
.flags
& SYMBIOS_VERBOSE_MSGS
)
4370 ** Get SCSI addr of host adapter (set by bios?).
4372 if (np
->myaddr
== 255) {
4373 np
->myaddr
= INB(nc_scid
) & 0x07;
4375 np
->myaddr
= SCSI_NCR_MYADDR
;
4378 #endif /* SCSI_NCR_TRUST_BIOS_SETTING */
4381 * Prepare initial io register bits for burst length
4383 ncr_init_burst(np
, burst_max
);
4386 ** Set differential mode and LED support.
4387 ** Ignore these features for boards known to use a
4388 ** specific GPIO wiring (Tekram only for now) and
4389 ** for the 896 that drives the LED directly.
4390 ** Probe initial setting of GPREG and GPCNTL for
4393 if (!nvram
|| nvram
->type
!= SCSI_NCR_TEKRAM_NVRAM
) {
4394 switch(driver_setup
.diff_support
) {
4396 if (INB(nc_gpreg
) & 0x08)
4399 np
->rv_stest2
|= 0x20;
4402 np
->rv_stest2
|= (np
->sv_stest2
& 0x20);
4408 if ((driver_setup
.led_pin
||
4409 (nvram
&& nvram
->type
== SCSI_NCR_SYMBIOS_NVRAM
)) &&
4410 !(np
->features
& FE_LEDC
) && !(np
->sv_gpcntl
& 0x01))
4411 np
->features
|= FE_LED0
;
4416 switch(driver_setup
.irqm
& 3) {
4418 np
->rv_dcntl
|= IRQM
;
4421 np
->rv_dcntl
|= (np
->sv_dcntl
& IRQM
);
4428 ** Configure targets according to driver setup.
4429 ** If NVRAM present get targets setup from NVRAM.
4430 ** Allow to override sync, wide and NOSCAN from
4431 ** boot command line.
4433 for (i
= 0 ; i
< MAX_TARGET
; i
++) {
4434 tcb_p tp
= &np
->target
[i
];
4437 #ifdef SCSI_NCR_NVRAM_SUPPORT
4439 switch(nvram
->type
) {
4440 case SCSI_NCR_TEKRAM_NVRAM
:
4441 ncr_Tekram_setup_target(np
, i
, &nvram
->data
.Tekram
);
4443 case SCSI_NCR_SYMBIOS_NVRAM
:
4444 ncr_Symbios_setup_target(np
, i
, &nvram
->data
.Symbios
);
4447 if (driver_setup
.use_nvram
& 0x2)
4448 tp
->usrsync
= driver_setup
.default_sync
;
4449 if (driver_setup
.use_nvram
& 0x4)
4450 tp
->usrwide
= driver_setup
.max_wide
;
4451 if (driver_setup
.use_nvram
& 0x8)
4452 tp
->usrflag
&= ~UF_NOSCAN
;
4458 tp
->usrsync
= driver_setup
.default_sync
;
4459 tp
->usrwide
= driver_setup
.max_wide
;
4460 tp
->usrtags
= SCSI_NCR_MAX_TAGS
;
4461 if (!driver_setup
.disconnection
)
4462 np
->target
[i
].usrflag
= UF_NODISC
;
4467 ** Announce all that stuff to user.
4470 i
= nvram
? nvram
->type
: 0;
4471 printk(KERN_INFO
"%s: %sID %d, Fast-%d%s%s\n", ncr_name(np
),
4472 i
== SCSI_NCR_SYMBIOS_NVRAM
? "Symbios format NVRAM, " :
4473 (i
== SCSI_NCR_TEKRAM_NVRAM
? "Tekram format NVRAM, " : ""),
4475 np
->minsync
< 12 ? 40 : (np
->minsync
< 25 ? 20 : 10),
4476 (np
->rv_scntl0
& 0xa) ? ", Parity Checking" : ", NO Parity",
4477 (np
->rv_stest2
& 0x20) ? ", Differential" : "");
4479 if (bootverbose
> 1) {
4480 printk (KERN_INFO
"%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
4481 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
4482 ncr_name(np
), np
->sv_scntl3
, np
->sv_dmode
, np
->sv_dcntl
,
4483 np
->sv_ctest3
, np
->sv_ctest4
, np
->sv_ctest5
);
4485 printk (KERN_INFO
"%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
4486 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
4487 ncr_name(np
), np
->rv_scntl3
, np
->rv_dmode
, np
->rv_dcntl
,
4488 np
->rv_ctest3
, np
->rv_ctest4
, np
->rv_ctest5
);
4491 if (bootverbose
&& np
->base2_ba
)
4492 printk (KERN_INFO
"%s: on-chip RAM at 0x%lx\n",
4493 ncr_name(np
), np
->base2_ba
);
4499 #ifdef SCSI_NCR_DEBUG_NVRAM
4501 void __init
ncr_display_Symbios_nvram(ncb_p np
, Symbios_nvram
*nvram
)
4505 /* display Symbios nvram host data */
4506 printk(KERN_DEBUG
"%s: HOST ID=%d%s%s%s%s%s\n",
4507 ncr_name(np
), nvram
->host_id
& 0x0f,
4508 (nvram
->flags
& SYMBIOS_SCAM_ENABLE
) ? " SCAM" :"",
4509 (nvram
->flags
& SYMBIOS_PARITY_ENABLE
) ? " PARITY" :"",
4510 (nvram
->flags
& SYMBIOS_VERBOSE_MSGS
) ? " VERBOSE" :"",
4511 (nvram
->flags
& SYMBIOS_CHS_MAPPING
) ? " CHS_ALT" :"",
4512 (nvram
->flags1
& SYMBIOS_SCAN_HI_LO
) ? " HI_LO" :"");
4514 /* display Symbios nvram drive data */
4515 for (i
= 0 ; i
< 15 ; i
++) {
4516 struct Symbios_target
*tn
= &nvram
->target
[i
];
4517 printk(KERN_DEBUG
"%s-%d:%s%s%s%s WIDTH=%d SYNC=%d TMO=%d\n",
4519 (tn
->flags
& SYMBIOS_DISCONNECT_ENABLE
) ? " DISC" : "",
4520 (tn
->flags
& SYMBIOS_SCAN_AT_BOOT_TIME
) ? " SCAN_BOOT" : "",
4521 (tn
->flags
& SYMBIOS_SCAN_LUNS
) ? " SCAN_LUNS" : "",
4522 (tn
->flags
& SYMBIOS_QUEUE_TAGS_ENABLED
)? " TCQ" : "",
4524 tn
->sync_period
/ 4,
4529 static u_char Tekram_boot_delay
[7] __initdata
= {3, 5, 10, 20, 30, 60, 120};
4531 void __init
ncr_display_Tekram_nvram(ncb_p np
, Tekram_nvram
*nvram
)
4533 int i
, tags
, boot_delay
;
4536 /* display Tekram nvram host data */
4537 tags
= 2 << nvram
->max_tags_index
;
4539 if (nvram
->boot_delay_index
< 6)
4540 boot_delay
= Tekram_boot_delay
[nvram
->boot_delay_index
];
4541 switch((nvram
->flags
& TEKRAM_REMOVABLE_FLAGS
) >> 6) {
4543 case 0: rem
= ""; break;
4544 case 1: rem
= " REMOVABLE=boot device"; break;
4545 case 2: rem
= " REMOVABLE=all"; break;
4549 "%s: HOST ID=%d%s%s%s%s%s%s%s%s%s BOOT DELAY=%d tags=%d\n",
4550 ncr_name(np
), nvram
->host_id
& 0x0f,
4551 (nvram
->flags1
& SYMBIOS_SCAM_ENABLE
) ? " SCAM" :"",
4552 (nvram
->flags
& TEKRAM_MORE_THAN_2_DRIVES
) ? " >2DRIVES" :"",
4553 (nvram
->flags
& TEKRAM_DRIVES_SUP_1GB
) ? " >1GB" :"",
4554 (nvram
->flags
& TEKRAM_RESET_ON_POWER_ON
) ? " RESET" :"",
4555 (nvram
->flags
& TEKRAM_ACTIVE_NEGATION
) ? " ACT_NEG" :"",
4556 (nvram
->flags
& TEKRAM_IMMEDIATE_SEEK
) ? " IMM_SEEK" :"",
4557 (nvram
->flags
& TEKRAM_SCAN_LUNS
) ? " SCAN_LUNS" :"",
4558 (nvram
->flags1
& TEKRAM_F2_F6_ENABLED
) ? " F2_F6" :"",
4559 rem
, boot_delay
, tags
);
4561 /* display Tekram nvram drive data */
4562 for (i
= 0; i
<= 15; i
++) {
4564 struct Tekram_target
*tn
= &nvram
->target
[i
];
4565 j
= tn
->sync_index
& 0xf;
4566 sync
= j
< 12 ? Tekram_sync
[j
] : 255;
4567 printk(KERN_DEBUG
"%s-%d:%s%s%s%s%s%s PERIOD=%d\n",
4569 (tn
->flags
& TEKRAM_PARITY_CHECK
) ? " PARITY" : "",
4570 (tn
->flags
& TEKRAM_SYNC_NEGO
) ? " SYNC" : "",
4571 (tn
->flags
& TEKRAM_DISCONNECT_ENABLE
) ? " DISC" : "",
4572 (tn
->flags
& TEKRAM_START_CMD
) ? " START" : "",
4573 (tn
->flags
& TEKRAM_TAGGED_COMMANDS
) ? " TCQ" : "",
4574 (tn
->flags
& TEKRAM_WIDE_NEGO
) ? " WIDE" : "",
4578 #endif /* SCSI_NCR_DEBUG_NVRAM */
4581 ** Host attach and initialisations.
4583 ** Allocate host data and ncb structure.
4584 ** Request IO region and remap MMIO region.
4585 ** Do chip initialization.
4586 ** If all is OK, install interrupt handling and
4587 ** start the timer daemon.
4590 static int __init
ncr_attach (Scsi_Host_Template
*tpnt
, int unit
, ncr_device
*device
)
4592 struct host_data
*host_data
;
4594 struct Scsi_Host
*instance
= 0;
4596 ncr_nvram
*nvram
= device
->nvram
;
4600 printk(KERN_INFO
"ncr53c%s-%d: rev=0x%02x, base=0x%lx, io_port=0x%lx, irq=0x%x\n",
4601 device
->chip
.name
, unit
, device
->chip
.revision_id
, device
->slot
.base
,
4602 device
->slot
.io_port
, device
->slot
.irq
);
4604 printk(KERN_INFO NAME53C
"%s-%d: rev=0x%02x, base=0x%lx, io_port=0x%lx, irq=%d\n",
4605 device
->chip
.name
, unit
, device
->chip
.revision_id
, device
->slot
.base
,
4606 device
->slot
.io_port
, device
->slot
.irq
);
4610 ** Allocate host_data structure
4612 if (!(instance
= scsi_register(tpnt
, sizeof(*host_data
))))
4614 host_data
= (struct host_data
*) instance
->hostdata
;
4617 ** Allocate the host control block.
4619 np
= m_calloc(sizeof(struct ncb
), "NCB", MEMO_WARN
);
4622 NCR_INIT_LOCK_NCB(np
);
4623 host_data
->ncb
= np
;
4626 ** Store input informations in the host data structure.
4628 strncpy(np
->chip_name
, device
->chip
.name
, sizeof(np
->chip_name
) - 1);
4630 np
->verbose
= driver_setup
.verbose
;
4631 sprintf(np
->inst_name
, NAME53C
"%s-%d", np
->chip_name
, np
->unit
);
4632 np
->device_id
= device
->chip
.device_id
;
4633 np
->revision_id
= device
->chip
.revision_id
;
4634 np
->features
= device
->chip
.features
;
4635 np
->clock_divn
= device
->chip
.nr_divisor
;
4636 np
->maxoffs
= device
->chip
.offset_max
;
4637 np
->maxburst
= device
->chip
.burst_max
;
4638 np
->myaddr
= device
->host_id
;
4641 ** Allocate the start queue.
4643 np
->squeue
= (ncrcmd
*)
4644 m_calloc(sizeof(ncrcmd
)*(MAX_START
*2), "SQUEUE", MEMO_WARN
);
4649 ** Allocate the done queue.
4651 np
->dqueue
= (ncrcmd
*)
4652 m_calloc(sizeof(ncrcmd
)*(MAX_START
*2), "DQUEUE", MEMO_WARN
);
4657 ** Allocate the target bus address array.
4659 np
->targtbl
= (u_int32
*) m_calloc(256, "TARGTBL", MEMO_WARN
);
4664 ** Allocate SCRIPTS areas
4666 np
->script0
= (struct script
*)
4667 m_calloc(sizeof(struct script
), "SCRIPT", MEMO_WARN
);
4670 np
->scripth0
= (struct scripth
*)
4671 m_calloc(sizeof(struct scripth
), "SCRIPTH", MEMO_WARN
);
4676 ** Initialyze the CCB free queue and,
4677 ** allocate some CCB. We need at least ONE.
4679 xpt_que_init(&np
->free_ccbq
);
4680 xpt_que_init(&np
->b0_ccbq
);
4681 if (!ncr_alloc_ccb(np
))
4685 ** Initialize timer structure
4688 init_timer(&np
->timer
);
4689 np
->timer
.data
= (unsigned long) np
;
4690 np
->timer
.function
= sym53c8xx_timeout
;
4693 ** Try to map the controller chip to
4694 ** virtual and physical memory.
4697 np
->base_ba
= device
->slot
.base
;
4698 np
->base_ws
= (np
->features
& FE_IO256
)? 256 : 128;
4699 np
->base2_ba
= (np
->features
& FE_RAM
)? device
->slot
.base_2
: 0;
4701 #ifndef NCR_IOMAPPED
4702 np
->base_va
= remap_pci_mem(np
->base_ba
, np
->base_ws
);
4704 printk(KERN_ERR
"%s: can't map PCI MMIO region\n",ncr_name(np
));
4707 else if (bootverbose
> 1)
4708 printk(KERN_INFO
"%s: using memory mapped IO\n", ncr_name(np
));
4711 ** Make the controller's registers available.
4712 ** Now the INB INW INL OUTB OUTW OUTL macros
4713 ** can be used safely.
4716 np
->reg
= (struct ncr_reg
*) np
->base_va
;
4718 #endif /* !defined NCR_IOMAPPED */
4721 ** Try to map the controller chip into iospace.
4724 if (device
->slot
.io_port
) {
4725 request_region(device
->slot
.io_port
, np
->base_ws
, NAME53C8XX
);
4726 np
->base_io
= device
->slot
.io_port
;
4729 #ifdef SCSI_NCR_NVRAM_SUPPORT
4731 switch(nvram
->type
) {
4732 case SCSI_NCR_SYMBIOS_NVRAM
:
4733 #ifdef SCSI_NCR_DEBUG_NVRAM
4734 ncr_display_Symbios_nvram(np
, &nvram
->data
.Symbios
);
4737 case SCSI_NCR_TEKRAM_NVRAM
:
4738 #ifdef SCSI_NCR_DEBUG_NVRAM
4739 ncr_display_Tekram_nvram(np
, &nvram
->data
.Tekram
);
4744 #ifdef SCSI_NCR_DEBUG_NVRAM
4745 printk(KERN_DEBUG
"%s: NVRAM: None or invalid data.\n", ncr_name(np
));
4752 ** Do chip dependent initialization.
4754 if (np
->base2_ba
&& sizeof(struct script
) > 4096) {
4755 printk(KERN_ERR
"%s: script too large.\n", ncr_name(np
));
4758 (void) ncr_prepare_setting(np
, nvram
);
4761 ** Patch script to physical addresses
4763 ncr_script_fill (&script0
, &scripth0
);
4765 np
->p_script
= vtobus(np
->script0
);
4766 np
->p_scripth
= vtobus(np
->scripth0
);
4767 np
->p_scripth0
= np
->p_scripth
;
4770 np
->p_script
= pcivtobus(np
->base2_ba
);
4771 if (np
->features
& FE_RAM8K
) {
4772 np
->p_scripth
= np
->p_script
+ 4096;
4773 #if BITS_PER_LONG > 32
4774 np
->scr_ram_seg
= cpu_to_scr(np
->base2_ba
>> 32);
4779 ncr_script_copy_and_bind (np
, (ncrcmd
*) &script0
, (ncrcmd
*) np
->script0
, sizeof(struct script
));
4780 ncr_script_copy_and_bind (np
, (ncrcmd
*) &scripth0
, (ncrcmd
*) np
->scripth0
, sizeof(struct scripth
));
4783 ** Patch some variables in SCRIPTS
4785 np
->scripth0
->pm0_data_addr
[0] =
4786 cpu_to_scr(NCB_SCRIPT_PHYS(np
, pm0_data
));
4787 np
->scripth0
->pm1_data_addr
[0] =
4788 cpu_to_scr(NCB_SCRIPT_PHYS(np
, pm1_data
));
4790 np
->scripth0
->script0_ba
[0] = cpu_to_scr(vtobus(np
->script0
));
4791 np
->scripth0
->script0_ba64
[0] = cpu_to_scr(vtobus(np
->script0
));
4792 np
->scripth0
->scripth0_ba64
[0] = cpu_to_scr(vtobus(np
->scripth0
));
4793 np
->scripth0
->ram_seg64
[0] = np
->scr_ram_seg
;
4796 ** Prepare the idle and invalid task actions.
4798 np
->idletask
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
4799 np
->idletask
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l
));
4800 np
->p_idletask
= vtobus(&np
->idletask
);
4802 np
->notask
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
4803 np
->notask
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l
));
4804 np
->p_notask
= vtobus(&np
->notask
);
4806 np
->bad_i_t_l
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
4807 np
->bad_i_t_l
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l
));
4808 np
->p_bad_i_t_l
= vtobus(&np
->bad_i_t_l
);
4810 np
->bad_i_t_l_q
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
4811 np
->bad_i_t_l_q
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
,bad_i_t_l_q
));
4812 np
->p_bad_i_t_l_q
= vtobus(&np
->bad_i_t_l_q
);
4815 ** Allocate and prepare the bad lun table.
4817 np
->badluntbl
= m_calloc(256, "BADLUNTBL", MEMO_WARN
);
4821 assert (offsetof(struct lcb
, resel_task
) == 0);
4822 np
->resel_badlun
= cpu_to_scr(NCB_SCRIPTH_PHYS(np
, bad_identify
));
4824 for (i
= 0 ; i
< 64 ; i
++)
4825 np
->badluntbl
[i
] = cpu_to_scr(vtobus(&np
->resel_badlun
));
4828 ** Prepare the target bus address array.
4830 np
->script0
->targtbl
[0] = cpu_to_scr(vtobus(np
->targtbl
));
4831 for (i
= 0 ; i
< MAX_TARGET
; i
++) {
4832 np
->targtbl
[i
] = cpu_to_scr(vtobus(&np
->target
[i
]));
4833 np
->target
[i
].b_luntbl
= cpu_to_scr(vtobus(np
->badluntbl
));
4837 ** Patch the script for LED support.
4840 if (np
->features
& FE_LED0
) {
4841 np
->script0
->idle
[0] =
4842 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_OR
, 0x01));
4843 np
->script0
->reselected
[0] =
4844 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
4845 np
->script0
->start
[0] =
4846 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
4850 ** DEL 472 - 53C896 Rev 1 - Part Number 609-0393055 - ITEM 5.
4852 if (np
->device_id
== PCI_DEVICE_ID_NCR_53C896
&&
4853 np
->revision_id
<= 0x1 && (np
->features
& FE_NOPM
)) {
4854 np
->scatter
= ncr_scatter_896R1
;
4855 #ifndef SCSI_NCR_PROFILE_SUPPORT
4860 np
->script0
->dataphase
[XXX
] = cpu_to_scr(SCR_JUMP
);
4861 np
->script0
->dataphase
[XXX
+1] =
4862 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, tweak_pmj
));
4867 np
->scatter
= ncr_scatter_896R1
;
4869 np
->scatter
= ncr_scatter
;
4874 ** We should use ncr_soft_reset(), but we donnot want to do
4875 ** so, since we may not be safe if ABRT interrupt occurs due
4876 ** to the BIOS or previous O/S having enable this interrupt.
4878 OUTB (nc_istat
, SRST
);
4883 ** Now check the cache handling of the pci chipset.
4886 if (ncr_snooptest (np
)) {
4887 printk (KERN_ERR
"CACHE INCORRECTLY CONFIGURED.\n");
4892 ** Install the interrupt handler.
4894 if (request_irq(device
->slot
.irq
, sym53c8xx_intr
,
4895 ((driver_setup
.irqm
& 0x10) ? 0 : SA_SHIRQ
) |
4896 #if LINUX_VERSION_CODE < LinuxVersionCode(2,2,0)
4897 ((driver_setup
.irqm
& 0x20) ? 0 : SA_INTERRUPT
),
4902 printk(KERN_ERR
"%s: request irq %d failure\n",
4903 ncr_name(np
), device
->slot
.irq
);
4906 np
->irq
= device
->slot
.irq
;
4909 ** After SCSI devices have been opened, we cannot
4910 ** reset the bus safely, so we do it here.
4911 ** Interrupt handler does the real work.
4912 ** Process the reset exception,
4913 ** if interrupts are not enabled yet.
4914 ** Then enable disconnects.
4916 NCR_LOCK_NCB(np
, flags
);
4917 if (ncr_reset_scsi_bus(np
, 0, driver_setup
.settle_delay
) != 0) {
4918 printk(KERN_ERR
"%s: FATAL ERROR: CHECK SCSI BUS - CABLES, TERMINATION, DEVICE POWER etc.!\n", ncr_name(np
));
4920 NCR_UNLOCK_NCB(np
, flags
);
4926 ** The middle-level SCSI driver does not
4927 ** wait for devices to settle.
4928 ** Wait synchronously if more than 2 seconds.
4930 if (driver_setup
.settle_delay
> 2) {
4931 printk(KERN_INFO
"%s: waiting %d seconds for scsi devices to settle...\n",
4932 ncr_name(np
), driver_setup
.settle_delay
);
4933 MDELAY (1000 * driver_setup
.settle_delay
);
4937 ** start the timeout daemon
4943 ** use SIMPLE TAG messages by default
4945 #ifdef SCSI_NCR_ALWAYS_SIMPLE_TAG
4946 np
->order
= M_SIMPLE_TAG
;
4953 first_host
= instance
;
4956 ** Fill Linux host instance structure
4957 ** and return success.
4959 instance
->max_channel
= 0;
4960 instance
->max_id
= np
->maxwide
? 16 : 8;
4961 instance
->max_lun
= SCSI_NCR_MAX_LUN
;
4962 #ifndef NCR_IOMAPPED
4963 instance
->base
= (char *) np
->reg
;
4965 instance
->irq
= np
->irq
;
4966 instance
->unique_id
= np
->base_io
;
4967 instance
->io_port
= np
->base_io
;
4968 instance
->n_io_port
= np
->base_ws
;
4969 instance
->dma_channel
= 0;
4970 instance
->select_queue_depths
= sym53c8xx_select_queue_depths
;
4972 NCR_UNLOCK_NCB(np
, flags
);
4975 ** Now let the generic SCSI driver
4976 ** look for the SCSI devices on the bus ..
4981 if (!instance
) return -1;
4982 printk(KERN_INFO
"%s: giving up ...\n", ncr_name(np
));
4984 ncr_free_resources(np
);
4985 scsi_unregister(instance
);
4992 ** Free controller resources.
4994 static void ncr_free_resources(ncb_p np
)
5002 free_irq(np
->irq
, np
);
5004 release_region(np
->base_io
, np
->base_ws
);
5005 #ifndef NCR_IOMAPPED
5007 unmap_pci_mem(np
->base_va
, np
->base_ws
);
5010 m_free(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
5012 m_free(np
->script0
, sizeof(struct script
), "SCRIPT");
5014 m_free(np
->squeue
, sizeof(ncrcmd
)*(MAX_START
*2), "SQUEUE");
5016 m_free(np
->dqueue
, sizeof(ncrcmd
)*(MAX_START
*2),"DQUEUE");
5018 while ((cp
= np
->ccbc
) != NULL
) {
5019 np
->ccbc
= cp
->link_ccb
;
5020 m_free(cp
, sizeof(*cp
), "CCB");
5024 m_free(np
->badluntbl
, 256,"BADLUNTBL");
5026 for (target
= 0; target
< MAX_TARGET
; target
++) {
5027 tp
= &np
->target
[target
];
5028 for (lun
= 0 ; lun
< MAX_LUN
; lun
++) {
5032 if (lp
->tasktbl
!= &lp
->tasktbl_0
)
5033 m_free(lp
->tasktbl
, 256, "TASKTBL");
5034 m_free(lp
, sizeof(*lp
), "LCB");
5038 m_free(np
, sizeof(*np
), "NCB");
5042 /*==========================================================
5045 ** Done SCSI commands list management.
5047 ** We donnot enter the scsi_done() callback immediately
5048 ** after a command has been seen as completed but we
5049 ** insert it into a list which is flushed outside any kind
5050 ** of driver critical section.
5051 ** This allows to do minimal stuff under interrupt and
5052 ** inside critical sections and to also avoid locking up
5053 ** on recursive calls to driver entry points under SMP.
5054 ** In fact, the only kernel point which is entered by the
5055 ** driver with a driver lock set is get_free_pages(GFP_ATOMIC...)
5056 ** that shall not reenter the driver under any circumstance.
5058 **==========================================================
5060 static inline void ncr_queue_done_cmd(ncb_p np
, Scsi_Cmnd
*cmd
)
5062 cmd
->host_scribble
= (char *) np
->done_list
;
5063 np
->done_list
= cmd
;
5066 static inline void ncr_flush_done_cmds(Scsi_Cmnd
*lcmd
)
5072 lcmd
= (Scsi_Cmnd
*) cmd
->host_scribble
;
5073 cmd
->scsi_done(cmd
);
5078 /*==========================================================
5081 ** Start execution of a SCSI command.
5082 ** This is called from the generic SCSI driver.
5085 **==========================================================
5087 static int ncr_queue_command (ncb_p np
, Scsi_Cmnd
*cmd
)
5089 /* Scsi_Device *device = cmd->device; */
5090 tcb_p tp
= &np
->target
[cmd
->target
];
5091 lcb_p lp
= tp
->lp
[cmd
->lun
];
5095 u_char nego
, idmsg
, *msgptr
;
5098 u_int32 lastp
, goalp
;
5100 /*---------------------------------------------
5102 ** Some shortcuts ...
5104 **---------------------------------------------
5106 if ((cmd
->target
== np
->myaddr
) ||
5107 (cmd
->target
>= MAX_TARGET
) ||
5108 (cmd
->lun
>= MAX_LUN
)) {
5109 return(DID_BAD_TARGET
);
5112 /*---------------------------------------------
5114 ** Complete the 1st TEST UNIT READY command
5115 ** with error condition if the device is
5116 ** flagged NOSCAN, in order to speed up
5119 **---------------------------------------------
5121 if (cmd
->cmnd
[0] == 0 && (tp
->usrflag
& UF_NOSCAN
)) {
5122 tp
->usrflag
&= ~UF_NOSCAN
;
5123 return DID_BAD_TARGET
;
5126 if (DEBUG_FLAGS
& DEBUG_TINY
) {
5128 printk ("CMD=%x ", cmd
->cmnd
[0]);
5131 /*---------------------------------------------------
5133 ** Assign a ccb / bind cmd.
5134 ** If resetting, shorten settle_time if necessary
5135 ** in order to avoid spurious timeouts.
5136 ** If resetting or no free ccb,
5137 ** insert cmd into the waiting list.
5139 **----------------------------------------------------
5141 if (np
->settle_time
&& cmd
->timeout_per_command
>= HZ
&&
5142 np
->settle_time
> jiffies
+ cmd
->timeout_per_command
- HZ
) {
5143 np
->settle_time
= jiffies
+ cmd
->timeout_per_command
- HZ
;
5146 if (np
->settle_time
|| !(cp
=ncr_get_ccb (np
, cmd
->target
, cmd
->lun
))) {
5147 insert_into_waiting_list(np
, cmd
);
5152 /*---------------------------------------------------
5154 ** Enable tagged queue if asked by scsi ioctl
5156 **----------------------------------------------------
5158 #if 0 /* This stuff was only usefull for linux-1.2.13 */
5159 if (lp
&& !lp
->numtags
&& cmd
->device
&& cmd
->device
->tagged_queue
) {
5160 lp
->numtags
= tp
->usrtags
;
5161 ncr_setup_tags (np
, cp
->target
, cp
->lun
);
5165 #ifdef SCSI_NCR_PROFILE_SUPPORT
5166 cp
->phys
.num_disc
= 0;
5169 /*---------------------------------------------------
5171 ** negotiation required?
5173 **---------------------------------------------------
5178 if ((!tp
->widedone
|| !tp
->period
) && !tp
->nego_cp
&& tp
->inq_done
&& lp
) {
5181 ** negotiate wide transfers ?
5184 if (!tp
->widedone
) {
5185 if (tp
->inq_byte7
& INQ7_WIDE16
) {
5192 ** negotiate synchronous transfers?
5195 if (!nego
&& !tp
->period
) {
5196 if (tp
->inq_byte7
& INQ7_SYNC
) {
5200 PRINT_TARGET(np
, cp
->target
);
5201 printk ("target did not report SYNC.\n");
5206 ** remember nego is pending for the target.
5207 ** Avoid to start a nego for all queued commands
5208 ** when tagged command queuing is enabled.
5215 /*----------------------------------------------------
5217 ** Build the identify / tag / sdtr message
5219 **----------------------------------------------------
5222 idmsg
= M_IDENTIFY
| cp
->lun
;
5224 if (cp
->tag
!= NO_TAG
|| (lp
&& !(tp
->usrflag
& UF_NODISC
)))
5227 msgptr
= cp
->scsi_smsg
;
5229 msgptr
[msglen
++] = idmsg
;
5231 if (cp
->tag
!= NO_TAG
) {
5232 char order
= np
->order
;
5235 ** Force ordered tag if necessary to avoid timeouts
5236 ** and to preserve interactivity.
5238 if (lp
&& lp
->tags_stime
+ (3*HZ
) <= jiffies
) {
5239 if (lp
->tags_smap
) {
5240 order
= M_ORDERED_TAG
;
5241 if ((DEBUG_FLAGS
& DEBUG_TAGS
)||bootverbose
>2){
5243 printk("ordered tag forced.\n");
5246 lp
->tags_stime
= jiffies
;
5247 lp
->tags_smap
= lp
->tags_umap
;
5252 ** Ordered write ops, unordered read ops.
5254 switch (cmd
->cmnd
[0]) {
5255 case 0x08: /* READ_SMALL (6) */
5256 case 0x28: /* READ_BIG (10) */
5257 case 0xa8: /* READ_HUGE (12) */
5258 order
= M_SIMPLE_TAG
;
5261 order
= M_ORDERED_TAG
;
5264 msgptr
[msglen
++] = order
;
5266 ** Actual tags are numbered 1,3,5,..2*MAXTAGS+1,
5267 ** since we may have to deal with devices that have
5268 ** problems with #TAG 0 or too great #TAG numbers.
5270 msgptr
[msglen
++] = (cp
->tag
<< 1) + 1;
5275 msgptr
[msglen
++] = M_EXTENDED
;
5276 msgptr
[msglen
++] = 3;
5277 msgptr
[msglen
++] = M_X_SYNC_REQ
;
5278 msgptr
[msglen
++] = tp
->maxoffs
? tp
->minsync
: 0;
5279 msgptr
[msglen
++] = tp
->maxoffs
;
5280 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
5281 PRINT_ADDR(cp
->cmd
);
5282 printk ("sync msgout: ");
5283 ncr_show_msg (&cp
->scsi_smsg
[msglen
-5]);
5288 msgptr
[msglen
++] = M_EXTENDED
;
5289 msgptr
[msglen
++] = 2;
5290 msgptr
[msglen
++] = M_X_WIDE_REQ
;
5291 msgptr
[msglen
++] = tp
->usrwide
;
5292 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
5293 PRINT_ADDR(cp
->cmd
);
5294 printk ("wide msgout: ");
5295 ncr_show_msg (&cp
->scsi_smsg
[msglen
-4]);
5303 /*----------------------------------------------------
5305 ** Build the data descriptors
5307 **----------------------------------------------------
5310 segments
= np
->scatter (cp
, cp
->cmd
);
5313 ncr_free_ccb(np
, cp
);
5317 /*----------------------------------------------------
5319 ** Determine xfer direction.
5321 **----------------------------------------------------
5326 switch((int) cmd
->cmnd
[0]) {
5327 case 0x08: /* READ(6) 08 */
5328 case 0x28: /* READ(10) 28 */
5329 case 0xA8: /* READ(12) A8 */
5330 direction
= XFER_IN
;
5332 case 0x0A: /* WRITE(6) 0A */
5333 case 0x2A: /* WRITE(10) 2A */
5334 case 0xAA: /* WRITE(12) AA */
5335 direction
= XFER_OUT
;
5338 direction
= (XFER_IN
|XFER_OUT
);
5343 /*----------------------------------------------------
5345 ** Set the DATA POINTER.
5347 **----------------------------------------------------
5351 ** Default to no data transfer.
5353 lastp
= goalp
= NCB_SCRIPTH_PHYS (np
, no_data
);
5356 ** Compute data out pointers, if needed.
5358 if (direction
& XFER_OUT
) {
5359 goalp
= NCB_SCRIPT_PHYS (np
, data_out2
) + 8;
5360 #if MAX_SCATTERH != 0
5361 if (segments
<= MAX_SCATTERL
)
5362 lastp
= goalp
- 8 - (segments
* (SCR_SG_SIZE
*4));
5364 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_out2
);
5365 lastp
-= (segments
- MAX_SCATTERL
) * (SCR_SG_SIZE
*4);
5368 lastp
= goalp
- 8 - (segments
* (SCR_SG_SIZE
*4));
5371 ** If actual data direction is unknown, save pointers
5372 ** in header. The SCRIPTS will swap them to current
5373 ** if target decision will be data out.
5375 if (direction
& XFER_IN
) {
5376 cp
->phys
.header
.wgoalp
= cpu_to_scr(goalp
);
5377 cp
->phys
.header
.wlastp
= cpu_to_scr(lastp
);
5382 ** Compute data in pointers, if needed.
5384 if (direction
& XFER_IN
) {
5385 goalp
= NCB_SCRIPT_PHYS (np
, data_in2
) + 8;
5386 #if MAX_SCATTERH != 0
5387 if (segments
<= MAX_SCATTERL
)
5388 lastp
= goalp
- 8 - (segments
* (SCR_SG_SIZE
*4));
5390 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_in2
);
5391 lastp
-= (segments
- MAX_SCATTERL
) * (SCR_SG_SIZE
*4);
5394 lastp
= goalp
- 8 - (segments
* (SCR_SG_SIZE
*4));
5399 ** Set all pointers values needed by SCRIPTS.
5400 ** If direction is unknown, start at data_io.
5402 cp
->phys
.header
.lastp
= cpu_to_scr(lastp
);
5403 cp
->phys
.header
.goalp
= cpu_to_scr(goalp
);
5405 if ((direction
& (XFER_IN
|XFER_OUT
)) == (XFER_IN
|XFER_OUT
))
5406 cp
->phys
.header
.savep
=
5407 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, data_io
));
5409 cp
->phys
.header
.savep
= cpu_to_scr(lastp
);
5412 ** Save the initial data pointer in order to be able
5413 ** to redo the command.
5415 cp
->startp
= cp
->phys
.header
.savep
;
5417 /*----------------------------------------------------
5421 **----------------------------------------------------
5424 ** physical -> virtual backlink
5425 ** Generic SCSI command
5431 cp
->phys
.header
.go
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
,select
));
5432 cp
->phys
.header
.go
.restart
= cpu_to_scr(NCB_SCRIPT_PHYS (np
,resel_dsa
));
5436 cp
->phys
.select
.sel_id
= cp
->target
;
5437 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
5438 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
5442 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg
));
5443 cp
->phys
.smsg
.size
= cpu_to_scr(msglen
);
5448 cp
->phys
.cmd
.addr
= cpu_to_scr(vtobus (&cmd
->cmnd
[0]));
5449 cp
->phys
.cmd
.size
= cpu_to_scr(cmd
->cmd_len
);
5454 cp
->actualquirks
= tp
->quirks
;
5455 cp
->host_status
= nego
? HS_NEGOTIATE
: HS_BUSY
;
5456 cp
->scsi_status
= S_ILLEGAL
;
5458 cp
->xerr_status
= XE_OK
;
5459 cp
->nego_status
= nego
;
5461 /*----------------------------------------------------
5463 ** Critical region: start this job.
5465 **----------------------------------------------------
5469 ** activate this job.
5472 /* Compute a time limit greater than the middle-level driver one */
5473 if (cmd
->timeout_per_command
> 0)
5474 cp
->tlimit
= jiffies
+ cmd
->timeout_per_command
+ HZ
;
5476 cp
->tlimit
= jiffies
+ 86400 * HZ
;/* No timeout=24 hours */
5479 ** insert next CCBs into start queue.
5480 ** 2 max at a time is enough to flush the CCB wait queue.
5484 ncr_start_next_ccb(np
, lp
, 2);
5486 ncr_put_start_queue(np
, cp
);
5489 ** Command is successfully queued.
5496 /*==========================================================
5499 ** Insert a CCB into the start queue and wake up the
5500 ** SCRIPTS processor.
5503 **==========================================================
5506 static void ncr_start_next_ccb(ncb_p np
, lcb_p lp
, int maxn
)
5511 while (maxn
-- && lp
->queuedccbs
< lp
->queuedepth
) {
5512 qp
= xpt_remque_head(&lp
->wait_ccbq
);
5516 cp
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
5517 xpt_insque_tail(qp
, &lp
->busy_ccbq
);
5518 lp
->tasktbl
[cp
->tag
== NO_TAG
? 0 : cp
->tag
] =
5519 cpu_to_scr(cp
->p_ccb
);
5520 ncr_put_start_queue(np
, cp
);
5524 static void ncr_put_start_queue(ncb_p np
, ccb_p cp
)
5529 ** insert into start queue.
5531 qidx
= np
->squeueput
+ 2;
5532 if (qidx
>= MAX_START
*2) qidx
= 0;
5534 np
->squeue
[qidx
] = cpu_to_scr(np
->p_idletask
);
5536 np
->squeue
[np
->squeueput
] = cpu_to_scr(cp
->p_ccb
);
5538 np
->squeueput
= qidx
;
5541 if (DEBUG_FLAGS
& DEBUG_QUEUE
)
5542 printk ("%s: queuepos=%d.\n", ncr_name (np
), np
->squeueput
);
5545 ** Script processor may be waiting for reselect.
5549 OUTB (nc_istat
, SIGP
);
5553 /*==========================================================
5555 ** Soft reset the chip.
5557 ** Some 896 and 876 chip revisions may hang-up if we set
5558 ** the SRST (soft reset) bit at the wrong time when SCRIPTS
5560 ** So, we need to abort the current operation prior to
5561 ** soft resetting the chip.
5563 **==========================================================
5566 static void ncr_soft_reset(ncb_p np
)
5571 OUTB (nc_istat
, CABRT
);
5572 for (i
= 1000000 ; i
; --i
) {
5573 istat
= INB (nc_istat
);
5585 printk("%s: unable to abort current chip operation.\n",
5587 OUTB (nc_istat
, SRST
);
5592 /*==========================================================
5595 ** Start reset process.
5596 ** If reset in progress do nothing.
5597 ** The interrupt handler will reinitialize the chip.
5598 ** The timeout handler will wait for settle_time before
5599 ** clearing it and so resuming command processing.
5602 **==========================================================
5604 static void ncr_start_reset(ncb_p np
)
5606 if (!np
->settle_time
) {
5607 (void) ncr_reset_scsi_bus(np
, 1, driver_setup
.settle_delay
);
5611 static int ncr_reset_scsi_bus(ncb_p np
, int enab_int
, int settle_delay
)
5616 np
->settle_time
= jiffies
+ settle_delay
* HZ
;
5618 if (bootverbose
> 1)
5619 printk("%s: resetting, "
5620 "command processing suspended for %d seconds\n",
5621 ncr_name(np
), settle_delay
);
5623 ncr_soft_reset(np
); /* Soft reset the chip */
5624 UDELAY (2000); /* The 895/6 need time for the bus mode to settle */
5626 OUTW (nc_sien
, RST
);
5628 ** Enable Tolerant, reset IRQD if present and
5629 ** properly set IRQ mode, prior to resetting the bus.
5631 OUTB (nc_stest3
, TE
);
5632 OUTB (nc_dcntl
, (np
->rv_dcntl
& IRQM
));
5633 OUTB (nc_scntl1
, CRST
);
5636 if (!driver_setup
.bus_check
)
5639 ** Check for no terminators or SCSI bus shorts to ground.
5640 ** Read SCSI data bus, data parity bits and control signals.
5641 ** We are expecting RESET to be TRUE and other signals to be
5644 term
= INB(nc_sstat0
); /* rst, sdp0 */
5645 term
= ((term
& 2) << 7) + ((term
& 1) << 16);
5646 term
|= ((INB(nc_sstat2
) & 0x01) << 25) | /* sdp1 */
5647 (INW(nc_sbdl
) << 9) | /* d15-0 */
5648 INB(nc_sbcl
); /* req, ack, bsy, sel, atn, msg, cd, io */
5650 if (!(np
->features
& FE_WIDE
))
5653 if (term
!= (2<<7)) {
5654 printk("%s: suspicious SCSI data while resetting the BUS.\n",
5656 printk("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
5657 "0x%lx, expecting 0x%lx\n",
5659 (np
->features
& FE_WIDE
) ? "dp1,d15-8," : "",
5660 (u_long
)term
, (u_long
)(2<<7));
5661 if (driver_setup
.bus_check
== 1)
5665 OUTB (nc_scntl1
, 0);
5669 /*==========================================================
5672 ** Reset the SCSI BUS.
5673 ** This is called from the generic SCSI driver.
5676 **==========================================================
5678 static int ncr_reset_bus (ncb_p np
, Scsi_Cmnd
*cmd
, int sync_reset
)
5680 /* Scsi_Device *device = cmd->device; */
5685 * Return immediately if reset is in progress.
5687 if (np
->settle_time
) {
5688 return SCSI_RESET_PUNT
;
5691 * Start the reset process.
5692 * The script processor is then assumed to be stopped.
5693 * Commands will now be queued in the waiting list until a settle
5694 * delay of 2 seconds will be completed.
5696 ncr_start_reset(np
);
5698 * First, look in the wakeup list
5700 for (found
=0, cp
=np
->ccbc
; cp
; cp
=cp
->link_ccb
) {
5702 ** look for the ccb of this command.
5704 if (cp
->host_status
== HS_IDLE
) continue;
5705 if (cp
->cmd
== cmd
) {
5711 * Then, look in the waiting list
5713 if (!found
&& retrieve_from_waiting_list(0, np
, cmd
))
5716 * Wake-up all awaiting commands with DID_RESET.
5718 reset_waiting_list(np
);
5720 * Wake-up all pending commands with HS_RESET -> DID_RESET.
5722 ncr_wakeup(np
, HS_RESET
);
5724 * If the involved command was not in a driver queue, and the
5725 * scsi driver told us reset is synchronous, and the command is not
5726 * currently in the waiting list, complete it with DID_RESET status,
5727 * in order to keep it alive.
5729 if (!found
&& sync_reset
&& !retrieve_from_waiting_list(0, np
, cmd
)) {
5730 SetScsiResult(cmd
, DID_RESET
, 0);
5731 ncr_queue_done_cmd(np
, cmd
);
5734 return SCSI_RESET_SUCCESS
;
5737 /*==========================================================
5740 ** Abort an SCSI command.
5741 ** This is called from the generic SCSI driver.
5744 **==========================================================
5746 static int ncr_abort_command (ncb_p np
, Scsi_Cmnd
*cmd
)
5748 /* Scsi_Device *device = cmd->device; */
5754 * First, look for the scsi command in the waiting list
5756 if (remove_from_waiting_list(np
, cmd
)) {
5757 SetScsiResult(cmd
, DID_ABORT
, 0);
5758 ncr_queue_done_cmd(np
, cmd
);
5759 return SCSI_ABORT_SUCCESS
;
5763 * Then, look in the wakeup list
5765 for (found
=0, cp
=np
->ccbc
; cp
; cp
=cp
->link_ccb
) {
5767 ** look for the ccb of this command.
5769 if (cp
->host_status
== HS_IDLE
) continue;
5770 if (cp
->cmd
== cmd
) {
5777 return SCSI_ABORT_NOT_RUNNING
;
5780 if (np
->settle_time
) {
5781 return SCSI_ABORT_SNOOZE
;
5785 ** If the CCB is active, patch schedule jumps for the
5786 ** script to abort the command.
5790 switch(cp
->host_status
) {
5793 printk ("%s: abort ccb=%p (cancel)\n", ncr_name (np
), cp
);
5794 cp
->phys
.header
.go
.start
=
5795 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, cancel
));
5796 retv
= SCSI_ABORT_PENDING
;
5799 cp
->phys
.header
.go
.restart
=
5800 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l_q
));
5801 retv
= SCSI_ABORT_PENDING
;
5804 retv
= SCSI_ABORT_NOT_RUNNING
;
5810 ** If there are no requests, the script
5811 ** processor will sleep on SEL_WAIT_RESEL.
5812 ** Let's wake it up, since it may have to work.
5814 OUTB (nc_istat
, SIGP
);
5819 /*==========================================================
5821 ** Linux release module stuff.
5823 ** Called before unloading the module
5825 ** We have to free resources and halt the NCR chip
5827 **==========================================================
5831 static int ncr_detach(ncb_p np
)
5835 printk("%s: detaching ...\n", ncr_name(np
));
5838 ** Stop the ncr_timeout process
5839 ** Set release_stage to 1 and wait that ncr_timeout() set it to 2.
5841 np
->release_stage
= 1;
5842 for (i
= 50 ; i
&& np
->release_stage
!= 2 ; i
--) MDELAY (100);
5843 if (np
->release_stage
!= 2)
5844 printk("%s: the timer seems to be already stopped\n",
5846 else np
->release_stage
= 2;
5850 ** We should use ncr_soft_reset(), but we donnot want to do
5851 ** so, since we may not be safe if interrupts occur.
5854 printk("%s: resetting chip\n", ncr_name(np
));
5855 OUTB (nc_istat
, SRST
);
5857 OUTB (nc_istat
, 0 );
5860 ** Restore bios setting for automatic clock detection.
5862 OUTB(nc_dmode
, np
->sv_dmode
);
5863 OUTB(nc_dcntl
, np
->sv_dcntl
);
5864 OUTB(nc_ctest3
, np
->sv_ctest3
);
5865 OUTB(nc_ctest4
, np
->sv_ctest4
);
5866 OUTB(nc_ctest5
, np
->sv_ctest5
);
5867 OUTB(nc_gpcntl
, np
->sv_gpcntl
);
5868 OUTB(nc_stest2
, np
->sv_stest2
);
5870 ncr_selectclock(np
, np
->sv_scntl3
);
5872 ** Free host resources
5874 ncr_free_resources(np
);
5880 /*==========================================================
5883 ** Complete execution of a SCSI command.
5884 ** Signal completion to the generic SCSI driver.
5887 **==========================================================
5890 void ncr_complete (ncb_p np
, ccb_p cp
)
5899 if (!cp
|| !cp
->cmd
)
5903 ** Gather profiling data
5905 #ifdef SCSI_NCR_PROFILE_SUPPORT
5906 ncb_profile (np
, cp
);
5909 if (DEBUG_FLAGS
& DEBUG_TINY
)
5910 printk ("CCB=%lx STAT=%x/%x\n", (unsigned long)cp
,
5911 cp
->host_status
,cp
->scsi_status
);
5914 ** Get command, target and lun pointers.
5919 tp
= &np
->target
[cp
->target
];
5920 lp
= tp
->lp
[cp
->lun
];
5923 ** We donnot queue more than 1 ccb per target
5924 ** with negotiation at any time. If this ccb was
5925 ** used for negotiation, clear this info in the tcb.
5928 if (cp
== tp
->nego_cp
)
5932 ** If auto-sense performed, change scsi status.
5934 if (cp
->auto_sense
) {
5935 cp
->scsi_status
= cp
->auto_sense
;
5939 ** Check for parity errors.
5942 if (cp
->host_flags
& HF_PAR_ERR
) {
5944 printk ("unrecovered SCSI parity error.\n");
5945 if (cp
->host_status
==HS_COMPLETE
)
5946 cp
->host_status
= HS_FAIL
;
5950 ** Check for extended errors.
5953 if (cp
->xerr_status
!= XE_OK
) {
5955 switch (cp
->xerr_status
) {
5957 printk ("extraneous data discarded.\n");
5960 printk ("illegal scsi phase (4/5).\n");
5963 printk ("extended error %d.\n", cp
->xerr_status
);
5966 if (cp
->host_status
==HS_COMPLETE
)
5967 cp
->host_status
= HS_FAIL
;
5971 ** Print out any error for debugging purpose.
5973 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
5974 if (cp
->host_status
!=HS_COMPLETE
|| cp
->scsi_status
!=S_GOOD
) {
5976 printk ("ERROR: cmd=%x host_status=%x scsi_status=%x\n",
5977 cmd
->cmnd
[0], cp
->host_status
, cp
->scsi_status
);
5982 ** Check the status.
5984 if ( (cp
->host_status
== HS_COMPLETE
)
5985 && (cp
->scsi_status
== S_GOOD
||
5986 cp
->scsi_status
== S_COND_MET
)) {
5988 ** All went well (GOOD status).
5989 ** CONDITION MET status is returned on
5990 ** `Pre-Fetch' or `Search data' success.
5992 SetScsiResult(cmd
, DID_OK
, cp
->scsi_status
);
5996 ** Could dig out the correct value for resid,
5997 ** but it would be quite complicated.
5999 /* if (cp->phys.header.lastp != cp->phys.header.goalp) */
6002 ** Allocate the lcb if not yet.
6005 ncr_alloc_lcb (np
, cp
->target
, cp
->lun
);
6008 ** On standard INQUIRY response (EVPD and CmDt
6009 ** not set), setup logical unit according to
6010 ** announced capabilities (we need the 1rst 7 bytes).
6012 if (cmd
->cmnd
[0] == 0x12 && !(cmd
->cmnd
[1] & 0x3) &&
6013 cmd
->cmnd
[4] >= 7 && !cmd
->use_sg
) {
6014 ncr_setup_lcb (np
, cp
->target
, cp
->lun
,
6015 (char *) cmd
->request_buffer
);
6018 tp
->bytes
+= cp
->data_len
;
6022 ** If tags was reduced due to queue full,
6023 ** increase tags if 1000 good status received.
6025 if (lp
&& lp
->usetags
&& lp
->numtags
< lp
->maxtags
) {
6027 if (lp
->num_good
>= 1000) {
6030 ncr_setup_tags (np
, cp
->target
, cp
->lun
);
6033 } else if ((cp
->host_status
== HS_COMPLETE
)
6034 && (cp
->scsi_status
== S_CHECK_COND
)) {
6036 ** Check condition code
6038 SetScsiResult(cmd
, DID_OK
, S_CHECK_COND
);
6040 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
6041 u_char
* p
= (u_char
*) & cmd
->sense_buffer
;
6044 printk ("sense data:");
6045 for (i
=0; i
<14; i
++) printk (" %x", *p
++);
6049 } else if ((cp
->host_status
== HS_COMPLETE
)
6050 && (cp
->scsi_status
== S_BUSY
||
6051 cp
->scsi_status
== S_QUEUE_FULL
)) {
6056 SetScsiResult(cmd
, DID_OK
, cp
->scsi_status
);
6058 } else if ((cp
->host_status
== HS_SEL_TIMEOUT
)
6059 || (cp
->host_status
== HS_TIMEOUT
)) {
6064 SetScsiResult(cmd
, DID_TIME_OUT
, cp
->scsi_status
);
6066 } else if (cp
->host_status
== HS_RESET
) {
6071 SetScsiResult(cmd
, DID_RESET
, cp
->scsi_status
);
6073 } else if (cp
->host_status
== HS_ABORTED
) {
6078 SetScsiResult(cmd
, DID_ABORT
, cp
->scsi_status
);
6083 ** Other protocol messes
6086 printk ("COMMAND FAILED (%x %x) @%p.\n",
6087 cp
->host_status
, cp
->scsi_status
, cp
);
6089 SetScsiResult(cmd
, DID_ERROR
, cp
->scsi_status
);
6096 if (tp
->usrflag
& UF_TRACE
) {
6101 p
= (u_char
*) &cmd
->cmnd
[0];
6102 for (i
=0; i
<cmd
->cmd_len
; i
++) printk (" %x", *p
++);
6104 if (cp
->host_status
==HS_COMPLETE
) {
6105 switch (cp
->scsi_status
) {
6111 p
= (u_char
*) &cmd
->sense_buffer
;
6112 for (i
=0; i
<14; i
++)
6113 printk (" %x", *p
++);
6116 printk (" STAT: %x\n", cp
->scsi_status
);
6119 } else printk (" HOSTERROR: %x", cp
->host_status
);
6126 ncr_free_ccb (np
, cp
);
6129 ** requeue awaiting scsi commands for this lun.
6131 if (lp
&& lp
->queuedccbs
< lp
->queuedepth
&&
6132 !xpt_que_empty(&lp
->wait_ccbq
))
6133 ncr_start_next_ccb(np
, lp
, 2);
6136 ** requeue awaiting scsi commands for this controller.
6138 if (np
->waiting_list
)
6139 requeue_waiting_list(np
);
6142 ** signal completion to generic driver.
6144 ncr_queue_done_cmd(np
, cmd
);
6147 /*==========================================================
6150 ** Signal all (or one) control block done.
6153 **==========================================================
6157 ** The NCR has completed CCBs.
6158 ** Look at the DONE QUEUE.
6160 int ncr_wakeup_done (ncb_p np
)
6169 dsa
= scr_to_cpu(np
->dqueue
[i
]);
6173 if ((i
= i
+2) >= MAX_START
*2)
6176 cp
= ncr_ccb_from_dsa(np
, dsa
);
6178 ncr_complete (np
, cp
);
6182 printk (KERN_ERR
"%s: bad DSA (%lx) in done queue.\n",
6191 ** Complete all active CCBs.
6193 void ncr_wakeup (ncb_p np
, u_long code
)
6195 ccb_p cp
= np
->ccbc
;
6198 if (cp
->host_status
!= HS_IDLE
) {
6199 cp
->host_status
= code
;
6200 ncr_complete (np
, cp
);
6206 /*==========================================================
6212 **==========================================================
6215 void ncr_init (ncb_p np
, int reset
, char * msg
, u_long code
)
6221 ** Reset chip if asked, otherwise just clear fifos.
6227 OUTB (nc_stest3
, TE
|CSF
);
6228 OUTONB (nc_ctest3
, CLF
);
6235 if (msg
) printk (KERN_INFO
"%s: restart (%s).\n", ncr_name (np
), msg
);
6238 ** Clear Start Queue
6240 phys
= vtobus(np
->squeue
);
6241 np
->queuedepth
= MAX_START
- 1; /* 1 entry needed as end marker */
6242 for (i
= 0; i
< MAX_START
*2; i
+= 2) {
6243 np
->squeue
[i
] = cpu_to_scr(np
->p_idletask
);
6244 np
->squeue
[i
+1] = cpu_to_scr(phys
+ (i
+2)*4);
6246 np
->squeue
[MAX_START
*2-1] = cpu_to_scr(phys
);
6250 ** Start at first entry.
6253 np
->script0
->startpos
[0] = cpu_to_scr(phys
);
6258 phys
= vtobus(np
->dqueue
);
6259 for (i
= 0; i
< MAX_START
*2; i
+= 2) {
6261 np
->dqueue
[i
+1] = cpu_to_scr(phys
+ (i
+2)*4);
6263 np
->dqueue
[MAX_START
*2-1] = cpu_to_scr(phys
);
6266 ** Start at first entry.
6268 np
->script0
->done_pos
[0] = cpu_to_scr(phys
);
6272 ** Wakeup all pending jobs.
6274 ncr_wakeup (np
, code
);
6280 OUTB (nc_istat
, 0x00 ); /* Remove Reset, abort */
6281 UDELAY (2000); /* The 895 needs time for the bus mode to settle */
6283 OUTB (nc_scntl0
, np
->rv_scntl0
| 0xc0);
6284 /* full arb., ena parity, par->ATN */
6285 OUTB (nc_scntl1
, 0x00); /* odd parity, and remove CRST!! */
6287 ncr_selectclock(np
, np
->rv_scntl3
); /* Select SCSI clock */
6289 OUTB (nc_scid
, RRE
|np
->myaddr
); /* Adapter SCSI address */
6290 OUTW (nc_respid
, 1ul<<np
->myaddr
); /* Id to respond to */
6291 OUTB (nc_istat
, SIGP
); /* Signal Process */
6292 OUTB (nc_dmode
, np
->rv_dmode
); /* Burst length, dma mode */
6293 OUTB (nc_ctest5
, np
->rv_ctest5
); /* Large fifo + large burst */
6295 OUTB (nc_dcntl
, NOCOM
|np
->rv_dcntl
); /* Protect SFBR */
6296 OUTB (nc_ctest3
, np
->rv_ctest3
); /* Write and invalidate */
6297 OUTB (nc_ctest4
, np
->rv_ctest4
); /* Master parity checking */
6299 OUTB (nc_stest2
, EXT
|np
->rv_stest2
); /* Extended Sreq/Sack filtering */
6300 OUTB (nc_stest3
, TE
); /* TolerANT enable */
6301 OUTB (nc_stime0
, 0x0c); /* HTH disabled STO 0.25 sec */
6304 ** DEL 441 - 53C876 Rev 5 - Part Number 609-0392787/2788 - ITEM 2.
6305 ** Disable overlapped arbitration.
6306 ** The 896 Rev 1 needs also this work-around to be applied.
6308 if (np
->device_id
== PCI_DEVICE_ID_NCR_53C875
&&
6309 np
->revision_id
>= 0x10 && np
->revision_id
<= 0x15)
6310 OUTB (nc_ctest0
, (1<<5));
6311 else if (np
->device_id
== PCI_DEVICE_ID_NCR_53C896
&&
6312 np
->revision_id
<= 0x1)
6313 np
->rv_ccntl0
|= DPR
;
6316 ** If 64 bit (53C896) enable 40 bit address table
6317 ** indirect addressing for MOVE.
6320 if (np
->features
& FE_64BIT
) {
6321 OUTB (nc_ccntl1
, np
->rv_ccntl1
);
6325 ** If phase mismatch handled by scripts (53C896),
6326 ** set PM jump addresses.
6329 if (np
->features
& FE_NOPM
) {
6330 printk(KERN_INFO
"%s: handling phase mismatch from SCRIPTS.\n",
6332 OUTB (nc_ccntl0
, np
->rv_ccntl0
);
6333 OUTL (nc_pmjad1
, NCB_SCRIPTH_PHYS (np
, pm_handle
));
6334 OUTL (nc_pmjad2
, NCB_SCRIPTH_PHYS (np
, pm_handle
));
6338 ** Enable GPIO0 pin for writing if LED support from SCRIPTS.
6339 ** Also set GPIO5 and clear GPIO6 if hardware LED control.
6342 if (np
->features
& FE_LED0
)
6343 OUTB(nc_gpcntl
, INB(nc_gpcntl
) & ~0x01);
6344 else if (np
->features
& FE_LEDC
)
6345 OUTB(nc_gpcntl
, (INB(nc_gpcntl
) & ~0x41) | 0x20);
6352 OUTW (nc_sien
, STO
|HTH
|MA
|SGE
|UDC
|RST
|PAR
);
6353 OUTB (nc_dien
, MDPE
|BF
|SSI
|SIR
|IID
);
6356 ** For 895/6 enable SBMC interrupt and save current SCSI bus mode.
6358 if (np
->features
& FE_ULTRA2
) {
6359 OUTONW (nc_sien
, SBMC
);
6360 np
->scsi_mode
= INB (nc_stest4
) & SMODE
;
6364 ** Fill in target structure.
6365 ** Reinitialize usrsync.
6366 ** Reinitialize usrwide.
6367 ** Prepare sync negotiation according to actual SCSI bus mode.
6370 for (i
=0;i
<MAX_TARGET
;i
++) {
6371 tcb_p tp
= &np
->target
[i
];
6374 tp
->wval
= np
->rv_scntl3
;
6376 if (tp
->usrsync
!= 255) {
6377 if (tp
->usrsync
<= np
->maxsync
) {
6378 if (tp
->usrsync
< np
->minsync
) {
6379 tp
->usrsync
= np
->minsync
;
6386 if (tp
->usrwide
> np
->maxwide
)
6387 tp
->usrwide
= np
->maxwide
;
6389 ncr_negotiate (np
, tp
);
6393 ** Start script processor.
6398 printk ("%s: Downloading SCSI SCRIPTS.\n",
6400 if (np
->features
& FE_RAM8K
)
6401 phys
= NCB_SCRIPTH0_PHYS (np
, start_ram64
);
6403 phys
= NCB_SCRIPTH_PHYS (np
, start_ram
);
6406 phys
= NCB_SCRIPT_PHYS (np
, init
);
6408 OUTL (nc_dsa
, vtobus(np
));
6409 OUTL (nc_dsp
, phys
);
6412 /*==========================================================
6414 ** Prepare the negotiation values for wide and
6415 ** synchronous transfers.
6417 **==========================================================
6420 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
)
6423 ** minsync unit is 4ns !
6426 u_long minsync
= tp
->usrsync
;
6429 ** SCSI bus mode limit
6432 if (np
->scsi_mode
&& np
->scsi_mode
== SMODE_SE
) {
6433 if (minsync
< 12) minsync
= 12;
6440 if (minsync
< np
->minsync
)
6441 minsync
= np
->minsync
;
6447 if (minsync
> np
->maxsync
)
6450 tp
->minsync
= minsync
;
6451 tp
->maxoffs
= (minsync
<255 ? np
->maxoffs
: 0);
6454 ** period=0: has to negotiate sync transfer
6460 ** widedone=0: has to negotiate wide transfer
6465 /*==========================================================
6467 ** Get clock factor and sync divisor for a given
6468 ** synchronous factor period.
6469 ** Returns the clock factor (in sxfer) and scntl3
6470 ** synchronous divisor field.
6472 **==========================================================
6475 static void ncr_getsync(ncb_p np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
)
6477 u_long clk
= np
->clock_khz
; /* SCSI clock frequency in kHz */
6478 int div
= np
->clock_divn
; /* Number of divisors supported */
6479 u_long fak
; /* Sync factor in sxfer */
6480 u_long per
; /* Period in tenths of ns */
6481 u_long kpc
; /* (per * clk) */
6484 ** Compute the synchronous period in tenths of nano-seconds
6486 if (sfac
<= 10) per
= 250;
6487 else if (sfac
== 11) per
= 303;
6488 else if (sfac
== 12) per
= 500;
6489 else per
= 40 * sfac
;
6492 ** Look for the greatest clock divisor that allows an
6493 ** input speed faster than the period.
6497 if (kpc
>= (div_10M
[div
] << 2)) break;
6500 ** Calculate the lowest clock factor that allows an output
6501 ** speed not faster than the period.
6503 fak
= (kpc
- 1) / div_10M
[div
] + 1;
6505 #if 0 /* This optimization does not seem very usefull */
6507 per
= (fak
* div_10M
[div
]) / clk
;
6510 ** Why not to try the immediate lower divisor and to choose
6511 ** the one that allows the fastest output speed ?
6512 ** We dont want input speed too much greater than output speed.
6514 if (div
>= 1 && fak
< 8) {
6516 fak2
= (kpc
- 1) / div_10M
[div
-1] + 1;
6517 per2
= (fak2
* div_10M
[div
-1]) / clk
;
6518 if (per2
< per
&& fak2
<= 8) {
6526 if (fak
< 4) fak
= 4; /* Should never happen, too bad ... */
6529 ** Compute and return sync parameters for the ncr
6532 *scntl3p
= ((div
+1) << 4) + (sfac
< 25 ? 0x80 : 0);
6536 /*==========================================================
6538 ** Set actual values, sync status and patch all ccbs of
6539 ** a target according to new sync/wide agreement.
6541 **==========================================================
6544 static void ncr_set_sync_wide_status (ncb_p np
, u_char target
)
6547 tcb_p tp
= &np
->target
[target
];
6550 ** set actual value and sync_status
6552 OUTB (nc_sxfer
, tp
->sval
);
6553 OUTB (nc_scntl3
, tp
->wval
);
6556 ** patch ALL ccbs of this target.
6558 for (cp
= np
->ccbc
; cp
; cp
= cp
->link_ccb
) {
6559 if (cp
->host_status
== HS_IDLE
)
6561 if (cp
->target
!= target
)
6563 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
6564 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
6568 /*==========================================================
6570 ** Switch sync mode for current job and it's target
6572 **==========================================================
6575 static void ncr_setsync (ncb_p np
, ccb_p cp
, u_char scntl3
, u_char sxfer
)
6578 u_char target
= INB (nc_sdid
) & 0x0f;
6584 assert (target
== (cp
->target
& 0xf));
6586 tp
= &np
->target
[target
];
6588 if (!scntl3
|| !(sxfer
& 0x1f))
6589 scntl3
= np
->rv_scntl3
;
6590 scntl3
= (scntl3
& 0xf0) | (tp
->wval
& EWS
) | (np
->rv_scntl3
& 0x07);
6593 ** Deduce the value of controller sync period from scntl3.
6594 ** period is in tenths of nano-seconds.
6597 idiv
= ((scntl3
>> 4) & 0x7);
6598 if ((sxfer
& 0x1f) && idiv
)
6599 tp
->period
= (((sxfer
>>5)+4)*div_10M
[idiv
-1])/np
->clock_khz
;
6601 tp
->period
= 0xffff;
6604 ** Stop there if sync parameters are unchanged
6606 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
) return;
6611 ** Bells and whistles ;-)
6613 PRINT_TARGET(np
, target
);
6614 if (sxfer
& 0x01f) {
6615 unsigned f10
= 100000 << (tp
->widedone
? tp
->widedone
-1 : 0);
6616 unsigned mb10
= (f10
+ tp
->period
/2) / tp
->period
;
6620 ** Disable extended Sreq/Sack filtering
6622 if (tp
->period
<= 2000) OUTOFFB (nc_stest2
, EXT
);
6625 ** Bells and whistles ;-)
6627 if (tp
->period
< 500) scsi
= "FAST-40";
6628 else if (tp
->period
< 1000) scsi
= "FAST-20";
6629 else if (tp
->period
< 2000) scsi
= "FAST-10";
6630 else scsi
= "FAST-5";
6632 printk ("%s %sSCSI %d.%d MB/s (%d ns, offset %d)\n", scsi
,
6633 tp
->widedone
> 1 ? "WIDE " : "",
6634 mb10
/ 10, mb10
% 10, tp
->period
/ 10, sxfer
& 0x1f);
6636 printk ("%sasynchronous.\n", tp
->widedone
> 1 ? "wide " : "");
6639 ** set actual value and sync_status
6640 ** patch ALL ccbs of this target.
6642 ncr_set_sync_wide_status(np
, target
);
6645 /*==========================================================
6647 ** Switch wide mode for current job and it's target
6648 ** SCSI specs say: a SCSI device that accepts a WDTR
6649 ** message shall reset the synchronous agreement to
6650 ** asynchronous mode.
6652 **==========================================================
6655 static void ncr_setwide (ncb_p np
, ccb_p cp
, u_char wide
, u_char ack
)
6657 u_short target
= INB (nc_sdid
) & 0x0f;
6665 assert (target
== (cp
->target
& 0xf));
6667 tp
= &np
->target
[target
];
6668 tp
->widedone
= wide
+1;
6669 scntl3
= (tp
->wval
& (~EWS
)) | (wide
? EWS
: 0);
6671 sxfer
= ack
? 0 : tp
->sval
;
6674 ** Stop there if sync/wide parameters are unchanged
6676 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
) return;
6681 ** Bells and whistles ;-)
6683 if (bootverbose
>= 2) {
6684 PRINT_TARGET(np
, target
);
6686 printk ("WIDE SCSI (16 bit) enabled.\n");
6688 printk ("WIDE SCSI disabled.\n");
6692 ** set actual value and sync_status
6693 ** patch ALL ccbs of this target.
6695 ncr_set_sync_wide_status(np
, target
);
6698 /*==========================================================
6700 ** Switch tagged mode for a target.
6702 **==========================================================
6705 static void ncr_setup_tags (ncb_p np
, u_char tn
, u_char ln
)
6707 tcb_p tp
= &np
->target
[tn
];
6708 lcb_p lp
= tp
->lp
[ln
];
6709 u_char reqtags
, maxdepth
;
6718 ** If SCSI device queue depth is not yet set, leave here.
6720 if (!lp
->scdev_depth
)
6724 ** Donnot allow more tags than the SCSI driver can queue
6726 ** Donnot allow more tags than we can handle.
6728 maxdepth
= lp
->scdev_depth
;
6729 if (maxdepth
> lp
->maxnxs
) maxdepth
= lp
->maxnxs
;
6730 if (lp
->maxtags
> maxdepth
) lp
->maxtags
= maxdepth
;
6731 if (lp
->numtags
> maxdepth
) lp
->numtags
= maxdepth
;
6734 ** only devices conformant to ANSI Version >= 2
6735 ** only devices capable of tagged commands
6736 ** only if enabled by user ..
6738 if ((lp
->inq_byte7
& INQ7_QUEUE
) && lp
->numtags
> 1) {
6739 reqtags
= lp
->numtags
;
6745 ** Update max number of tags
6747 lp
->numtags
= reqtags
;
6748 if (lp
->numtags
> lp
->maxtags
)
6749 lp
->maxtags
= lp
->numtags
;
6752 ** If we want to switch tag mode, we must wait
6753 ** for no CCB to be active.
6755 if (reqtags
> 1 && lp
->usetags
) { /* Stay in tagged mode */
6756 if (lp
->queuedepth
== reqtags
) /* Already announced */
6758 lp
->queuedepth
= reqtags
;
6760 else if (reqtags
<= 1 && !lp
->usetags
) { /* Stay in untagged mode */
6761 lp
->queuedepth
= reqtags
;
6764 else { /* Want to switch tag mode */
6765 if (lp
->busyccbs
) /* If not yet safe, return */
6767 lp
->queuedepth
= reqtags
;
6768 lp
->usetags
= reqtags
> 1 ? 1 : 0;
6772 ** Patch the lun mini-script, according to tag mode.
6774 lp
->resel_task
= lp
->usetags
?
6775 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_tag
)) :
6776 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_notag
));
6779 ** Announce change to user.
6782 PRINT_LUN(np
, tn
, ln
);
6784 printk("tagged command queue depth set to %d\n", reqtags
);
6786 printk("tagged command queueing disabled\n");
6790 /*----------------------------------------------------
6792 ** handle user commands
6794 **----------------------------------------------------
6797 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
6799 static void ncr_usercmd (ncb_p np
)
6804 switch (np
->user
.cmd
) {
6809 for (t
=0; t
<MAX_TARGET
; t
++) {
6810 if (!((np
->user
.target
>>t
)&1)) continue;
6811 tp
= &np
->target
[t
];
6812 tp
->usrsync
= np
->user
.data
;
6813 ncr_negotiate (np
, tp
);
6818 for (t
=0; t
<MAX_TARGET
; t
++) {
6820 if (!((np
->user
.target
>>t
)&1)) continue;
6821 np
->target
[t
].usrtags
= np
->user
.data
;
6822 for (ln
= 0; ln
< MAX_LUN
; ln
++) {
6823 lcb_p lp
= np
->target
[t
].lp
[ln
];
6826 lp
->maxtags
= lp
->numtags
= np
->user
.data
;
6827 ncr_setup_tags (np
, t
, ln
);
6833 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
6834 ncr_debug
= np
->user
.data
;
6839 np
->order
= np
->user
.data
;
6843 np
->verbose
= np
->user
.data
;
6847 for (t
=0; t
<MAX_TARGET
; t
++) {
6849 if (!((np
->user
.target
>>t
)&1)) continue;
6850 tp
= &np
->target
[t
];
6851 size
= np
->user
.data
;
6852 if (size
> np
->maxwide
) size
=np
->maxwide
;
6854 ncr_negotiate (np
, tp
);
6859 for (t
=0; t
<MAX_TARGET
; t
++) {
6860 if (!((np
->user
.target
>>t
)&1)) continue;
6861 tp
= &np
->target
[t
];
6862 tp
->usrflag
= np
->user
.data
;
6866 #ifdef SCSI_NCR_PROFILE_SUPPORT
6868 bzero(&np
->profile
, sizeof(np
->profile
));
6876 /*==========================================================
6879 ** ncr timeout handler.
6882 **==========================================================
6884 ** Misused to keep the driver running when
6885 ** interrupts are not configured correctly.
6887 **----------------------------------------------------------
6890 static void ncr_timeout (ncb_p np
)
6892 u_long thistime
= jiffies
;
6895 ** If release process in progress, let's go
6896 ** Set the release stage from 1 to 2 to synchronize
6897 ** with the release process.
6900 if (np
->release_stage
) {
6901 if (np
->release_stage
== 1) np
->release_stage
= 2;
6905 np
->timer
.expires
= jiffies
+ SCSI_NCR_TIMER_INTERVAL
;
6906 add_timer(&np
->timer
);
6909 ** If we are resetting the ncr, wait for settle_time before
6910 ** clearing it. Then command processing will be resumed.
6912 if (np
->settle_time
) {
6913 if (np
->settle_time
<= thistime
) {
6914 if (bootverbose
> 1)
6915 printk("%s: command processing resumed\n", ncr_name(np
));
6916 np
->settle_time
= 0;
6917 requeue_waiting_list(np
);
6923 ** Nothing to do for now, but that may come.
6925 if (np
->lasttime
+ 4*HZ
< thistime
) {
6926 np
->lasttime
= thistime
;
6929 #ifdef SCSI_NCR_BROKEN_INTR
6930 if (INB(nc_istat
) & (INTF
|SIP
|DIP
)) {
6933 ** Process pending interrupts.
6935 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("{");
6937 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("}");
6939 #endif /* SCSI_NCR_BROKEN_INTR */
6942 /*==========================================================
6944 ** log message for real hard errors
6946 ** "ncr0 targ 0?: ERROR (ds:si) (so-si-sd) (sxfer/scntl3) @ name (dsp:dbc)."
6947 ** " reg: r0 r1 r2 r3 r4 r5 r6 ..... rf."
6949 ** exception register:
6954 ** so: control lines as driver by NCR.
6955 ** si: control lines as seen by NCR.
6956 ** sd: scsi data lines as seen by NCR.
6959 ** sxfer: (see the manual)
6960 ** scntl3: (see the manual)
6962 ** current script command:
6963 ** dsp: script adress (relative to start of script).
6964 ** dbc: first word of script command.
6966 ** First 16 register of the chip:
6969 **==========================================================
6972 static void ncr_log_hard_error(ncb_p np
, u_short sist
, u_char dstat
)
6978 u_char
*script_base
;
6983 if (dsp
> np
->p_script
&& dsp
<= np
->p_script
+ sizeof(struct script
)) {
6984 script_ofs
= dsp
- np
->p_script
;
6985 script_size
= sizeof(struct script
);
6986 script_base
= (u_char
*) np
->script0
;
6987 script_name
= "script";
6989 else if (np
->p_scripth
< dsp
&&
6990 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
6991 script_ofs
= dsp
- np
->p_scripth
;
6992 script_size
= sizeof(struct scripth
);
6993 script_base
= (u_char
*) np
->scripth0
;
6994 script_name
= "scripth";
6999 script_name
= "mem";
7002 printk ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x) @ (%s %x:%08x).\n",
7003 ncr_name (np
), (unsigned)INB (nc_sdid
)&0x0f, dstat
, sist
,
7004 (unsigned)INB (nc_socl
), (unsigned)INB (nc_sbcl
), (unsigned)INB (nc_sbdl
),
7005 (unsigned)INB (nc_sxfer
),(unsigned)INB (nc_scntl3
), script_name
, script_ofs
,
7006 (unsigned)INL (nc_dbc
));
7008 if (((script_ofs
& 3) == 0) &&
7009 (unsigned)script_ofs
< script_size
) {
7010 printk ("%s: script cmd = %08x\n", ncr_name(np
),
7011 scr_to_cpu((int) *(ncrcmd
*)(script_base
+ script_ofs
)));
7014 printk ("%s: regdump:", ncr_name(np
));
7016 printk (" %02x", (unsigned)INB_OFF(i
));
7020 /*============================================================
7022 ** ncr chip exception handler.
7024 **============================================================
7026 ** In normal situations, interrupt conditions occur one at
7027 ** a time. But when something bad happens on the SCSI BUS,
7028 ** the chip may raise several interrupt flags before
7029 ** stopping and interrupting the CPU. The additionnal
7030 ** interrupt flags are stacked in some extra registers
7031 ** after the SIP and/or DIP flag has been raised in the
7032 ** ISTAT. After the CPU has read the interrupt condition
7033 ** flag from SIST or DSTAT, the chip unstacks the other
7034 ** interrupt flags and sets the corresponding bits in
7035 ** SIST or DSTAT. Since the chip starts stacking once the
7036 ** SIP or DIP flag is set, there is a small window of time
7037 ** where the stacking does not occur.
7039 ** Typically, multiple interrupt conditions may happen in
7040 ** the following situations:
7042 ** - SCSI parity error + Phase mismatch (PAR|MA)
7043 ** When an parity error is detected in input phase
7044 ** and the device switches to msg-in phase inside a
7046 ** - SCSI parity error + Unexpected disconnect (PAR|UDC)
7047 ** When a stupid device does not want to handle the
7048 ** recovery of an SCSI parity error.
7049 ** - Some combinations of STO, PAR, UDC, ...
7050 ** When using non compliant SCSI stuff, when user is
7051 ** doing non compliant hot tampering on the BUS, when
7052 ** something really bad happens to a device, etc ...
7054 ** The heuristic suggested by SYMBIOS to handle
7055 ** multiple interrupts is to try unstacking all
7056 ** interrupts conditions and to handle them on some
7057 ** priority based on error severity.
7058 ** This will work when the unstacking has been
7059 ** successful, but we cannot be 100 % sure of that,
7060 ** since the CPU may have been faster to unstack than
7061 ** the chip is able to stack. Hmmm ... But it seems that
7062 ** such a situation is very unlikely to happen.
7064 ** If this happen, for example STO catched by the CPU
7065 ** then UDC happenning before the CPU have restarted
7066 ** the SCRIPTS, the driver may wrongly complete the
7067 ** same command on UDC, since the SCRIPTS didn't restart
7068 ** and the DSA still points to the same command.
7069 ** We avoid this situation by setting the DSA to an
7070 ** invalid value when the CCB is completed and before
7071 ** restarting the SCRIPTS.
7073 ** Another issue is that we need some section of our
7074 ** recovery procedures to be somehow uninterruptible and
7075 ** that the SCRIPTS processor does not provides such a
7076 ** feature. For this reason, we handle recovery preferently
7077 ** from the C code and check against some SCRIPTS
7078 ** critical sections from the C code.
7080 ** Hopefully, the interrupt handling of the driver is now
7081 ** able to resist to weird BUS error conditions, but donnot
7082 ** ask me for any guarantee that it will never fail. :-)
7083 ** Use at your own decision and risk.
7085 **============================================================
7088 void ncr_exception (ncb_p np
)
7090 u_char istat
, istatc
;
7095 #ifdef SCSI_NCR_OPTIMIZE_896_1
7097 ** This optimization when used with a 896 that handles
7098 ** phase mismatch from the SCRIPTS allows to only do
7099 ** PCI memory writes transactions from the CPU and so to
7100 ** take advantage of PCI posted writes.
7101 ** Who wants his 500 MHz CPU to wait several micro-seconds
7102 ** for the PCI BUS to be granted when this can be avoided?
7103 ** I don't, even for my slow 233 MHz PII. :-)
7105 ** We assume we have been called for command completion.
7106 ** If no completion found, go with normal handling.
7107 ** Ordering is ensured by the SCRIPTS performing a read
7108 ** from main memory prior to raising INTFLY.
7109 ** We have to raise SIGP since the chip may be currently
7110 ** going to a wait reselect instruction. IMO, SIGP should
7111 ** not be clearable in ISTAT since it can be polled and
7112 ** cleared by reading CTEST2. This tiny chip misdesign is a
7115 ** The MA interrupt and interrupt sharing may also have
7116 ** adverse effects on this optimization, so we only want
7117 ** to use it if it is enabled by user.
7118 ** (BTW, this optimization seems to even have some goodness
7119 ** with my 895 that unfortunately suffers of the MA int.).
7121 if (driver_setup
.optimize
& 1) {
7122 OUTB(nc_istat
, (INTF
| SIGP
));
7123 if (ncr_wakeup_done (np
)) {
7124 #ifdef SCSI_NCR_PROFILE_SUPPORT
7125 ++np
->profile
.num_fly
;
7130 #endif /* SCSI_NCR_OPTIMIZE_896_1 */
7133 ** interrupt on the fly ?
7135 istat
= INB (nc_istat
);
7137 OUTB (nc_istat
, (istat
& SIGP
) | INTF
);
7138 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("F ");
7139 (void)ncr_wakeup_done (np
);
7140 #ifdef SCSI_NCR_PROFILE_SUPPORT
7141 ++np
->profile
.num_fly
;
7145 if (!(istat
& (SIP
|DIP
)))
7148 #ifdef SCSI_NCR_PROFILE_SUPPORT
7149 ++np
->profile
.num_int
;
7152 #if 0 /* We should never get this one */
7154 OUTB (nc_istat
, CABRT
);
7158 ** Steinbach's Guideline for Systems Programming:
7159 ** Never test for an error condition you don't know how to handle.
7162 /*========================================================
7163 ** PAR and MA interrupts may occur at the same time,
7164 ** and we need to know of both in order to handle
7165 ** this situation properly. We try to unstack SCSI
7166 ** interrupts for that reason. BTW, I dislike a LOT
7167 ** such a loop inside the interrupt routine.
7168 ** Even if DMA interrupt stacking is very unlikely to
7169 ** happen, we also try unstacking these ones, since
7170 ** this has no performance impact.
7171 **=========================================================
7178 sist
|= INW (nc_sist
);
7180 dstat
|= INB (nc_dstat
);
7181 istatc
= INB (nc_istat
);
7183 } while (istatc
& (SIP
|DIP
));
7185 if (DEBUG_FLAGS
& DEBUG_TINY
)
7186 printk ("<%d|%x:%x|%x:%x>",
7189 (unsigned)INL(nc_dsp
),
7190 (unsigned)INL(nc_dbc
));
7192 /*========================================================
7193 ** First, interrupts we want to service cleanly.
7195 ** Phase mismatch (MA) is the most frequent interrupt
7196 ** for chip earlier than the 896 and so we have to service
7197 ** it as quickly as possible.
7198 ** A SCSI parity error (PAR) may be combined with a phase
7199 ** mismatch condition (MA).
7200 ** Programmed interrupts (SIR) are used to call the C code
7202 ** The single step interrupt (SSI) is not used in this
7204 **=========================================================
7207 if (!(sist
& (STO
|GEN
|HTH
|SGE
|UDC
|SBMC
|RST
)) &&
7208 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
7209 if (sist
& PAR
) ncr_int_par (np
, sist
);
7210 else if (sist
& MA
) ncr_int_ma (np
);
7211 else if (dstat
& SIR
) ncr_int_sir (np
);
7212 else if (dstat
& SSI
) OUTONB (nc_dcntl
, (STD
|NOCOM
));
7213 else goto unknown_int
;
7217 /*========================================================
7218 ** Now, interrupts that donnot happen in normal
7219 ** situations and that we may need to recover from.
7221 ** On SCSI RESET (RST), we reset everything.
7222 ** On SCSI BUS MODE CHANGE (SBMC), we complete all
7223 ** active CCBs with RESET status, prepare all devices
7224 ** for negotiating again and restart the SCRIPTS.
7225 ** On STO and UDC, we complete the CCB with the corres-
7226 ** ponding status and restart the SCRIPTS.
7227 **=========================================================
7231 ncr_init (np
, 1, bootverbose
? "scsi reset" : NULL
, HS_RESET
);
7235 OUTB (nc_ctest3
, np
->rv_ctest3
| CLF
); /* clear dma fifo */
7236 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
7238 if (!(sist
& (GEN
|HTH
|SGE
)) &&
7239 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
7240 if (sist
& SBMC
) ncr_int_sbmc (np
);
7241 else if (sist
& STO
) ncr_int_sto (np
);
7242 else if (sist
& UDC
) ncr_int_udc (np
);
7243 else goto unknown_int
;
7247 /*=========================================================
7248 ** Now, interrupts we are not able to recover cleanly.
7250 ** Do the register dump.
7251 ** Log message for hard errors.
7252 ** Reset everything.
7253 **=========================================================
7255 if (jiffies
- np
->regtime
> 10*HZ
) {
7256 np
->regtime
= jiffies
;
7257 for (i
= 0; i
<sizeof(np
->regdump
); i
++)
7258 ((char*)&np
->regdump
)[i
] = INB_OFF(i
);
7259 np
->regdump
.nc_dstat
= dstat
;
7260 np
->regdump
.nc_sist
= sist
;
7263 ncr_log_hard_error(np
, sist
, dstat
);
7265 if ((sist
& (GEN
|HTH
|SGE
)) ||
7266 (dstat
& (MDPE
|BF
|ABRT
|IID
))) {
7267 ncr_start_reset(np
);
7272 /*=========================================================
7273 ** We just miss the cause of the interrupt. :(
7274 ** Print a message. The timeout will do the real work.
7275 **=========================================================
7277 printk( "%s: unknown interrupt(s) ignored, "
7278 "ISTAT=0x%x DSTAT=0x%x SIST=0x%x\n",
7279 ncr_name(np
), istat
, dstat
, sist
);
7283 /*==========================================================
7285 ** generic recovery from scsi interrupt
7287 **==========================================================
7289 ** The doc says that when the chip gets an SCSI interrupt,
7290 ** it tries to stop in an orderly fashion, by completing
7291 ** an instruction fetch that had started or by flushing
7292 ** the DMA fifo for a write to memory that was executing.
7293 ** Such a fashion is not enough to know if the instruction
7294 ** that was just before the current DSP value has been
7297 ** There are 3 small SCRIPTS sections that deal with the
7298 ** start queue and the done queue that may break any
7299 ** assomption from the C code if we are interrupted
7300 ** inside, so we reset if it happens. Btw, since these
7301 ** SCRIPTS sections are executed while the SCRIPTS hasn't
7302 ** started SCSI operations, it is very unlikely to happen.
7304 ** All the driver data structures are supposed to be
7305 ** allocated from the same 4 GB memory window, so there
7306 ** is a 1 to 1 relationship between DSA and driver data
7307 ** structures. Since we are careful :) to invalidate the
7308 ** DSA when we complete a command or when the SCRIPTS
7309 ** pushes a DSA into a queue, we can trust it when it
7312 **----------------------------------------------------------
7314 static void ncr_recover_scsi_int (ncb_p np
, u_char hsts
)
7316 u_int32 dsp
= INL (nc_dsp
);
7317 u_int32 dsa
= INL (nc_dsa
);
7318 u_char scntl1
= INB (nc_scntl1
);
7319 ccb_p cp
= ncr_ccb_from_dsa(np
, dsa
);
7322 ** If we are connected to the SCSI BUS, we only
7323 ** can reset the BUS.
7329 ** If we haven't been interrupted inside the SCRIPTS
7330 ** critical pathes, we can safely restart the SCRIPTS
7331 ** and trust the DSA value if it matches a CCB.
7333 if ((!(dsp
> NCB_SCRIPT_PHYS (np
, getjob_begin
) &&
7334 dsp
< NCB_SCRIPT_PHYS (np
, getjob_end
) + 1)) &&
7335 (!(dsp
> NCB_SCRIPT_PHYS (np
, ungetjob
) &&
7336 dsp
< NCB_SCRIPT_PHYS (np
, reselect
) + 1)) &&
7337 (!(dsp
> NCB_SCRIPT_PHYS (np
, done
) &&
7338 dsp
< NCB_SCRIPT_PHYS (np
, done_end
) + 1))) {
7340 cp
->host_status
= hsts
;
7341 ncr_complete (np
, cp
);
7343 OUTL (nc_dsa
, DSA_INVALID
);
7344 OUTB (nc_ctest3
, np
->rv_ctest3
| CLF
); /* clear dma fifo */
7345 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
7346 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, start
));
7354 ncr_start_reset(np
);
7357 /*==========================================================
7359 ** ncr chip exception handler for selection timeout
7361 **==========================================================
7363 ** There seems to be a bug in the 53c810.
7364 ** Although a STO-Interrupt is pending,
7365 ** it continues executing script commands.
7366 ** But it will fail and interrupt (IID) on
7367 ** the next instruction where it's looking
7368 ** for a valid phase.
7370 **----------------------------------------------------------
7373 void ncr_int_sto (ncb_p np
)
7375 u_int32 dsp
= INL (nc_dsp
);
7377 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("T");
7379 if (dsp
== NCB_SCRIPT_PHYS (np
, wf_sel_done
) + 8 ||
7380 dsp
== NCB_SCRIPTH_PHYS (np
, wf_sel_done_no_atn
) + 8 ||
7381 !(driver_setup
.recovery
& 1))
7382 ncr_recover_scsi_int(np
, HS_SEL_TIMEOUT
);
7384 ncr_start_reset(np
);
7387 /*==========================================================
7389 ** ncr chip exception handler for unexpected disconnect
7391 **==========================================================
7393 **----------------------------------------------------------
7395 void ncr_int_udc (ncb_p np
)
7397 printk ("%s: unexpected disconnect\n", ncr_name(np
));
7398 ncr_recover_scsi_int(np
, HS_UNEXPECTED
);
7401 /*==========================================================
7403 ** ncr chip exception handler for SCSI bus mode change
7405 **==========================================================
7407 ** spi2-r12 11.2.3 says a transceiver mode change must
7408 ** generate a reset event and a device that detects a reset
7409 ** event shall initiate a hard reset. It says also that a
7410 ** device that detects a mode change shall set data transfer
7411 ** mode to eight bit asynchronous, etc...
7412 ** So, just resetting should be enough.
7415 **----------------------------------------------------------
7418 static void ncr_int_sbmc (ncb_p np
)
7420 u_char scsi_mode
= INB (nc_stest4
) & SMODE
;
7422 printk("%s: SCSI bus mode change from %x to %x.\n",
7423 ncr_name(np
), np
->scsi_mode
, scsi_mode
);
7425 np
->scsi_mode
= scsi_mode
;
7429 ** Suspend command processing for 1 second and
7430 ** reinitialize all except the chip.
7432 np
->settle_time
= jiffies
+ HZ
;
7433 ncr_init (np
, 0, bootverbose
? "scsi mode change" : NULL
, HS_RESET
);
7436 /*==========================================================
7438 ** ncr chip exception handler for SCSI parity error.
7440 **==========================================================
7442 ** When the chip detects a SCSI parity error and is
7443 ** currently executing a (CH)MOV instruction, it does
7444 ** not interrupt immediately, but tries to finish the
7445 ** transfer of the current scatter entry before
7446 ** interrupting. The following situations may occur:
7448 ** - The complete scatter entry has been transferred
7449 ** without the device having changed phase.
7450 ** The chip will then interrupt with the DSP pointing
7451 ** to the instruction that follows the MOV.
7453 ** - A phase mismatch occurs before the MOV finished
7454 ** and phase errors are to be handled by the C code.
7455 ** The chip will then interrupt with both PAR and MA
7458 ** - A phase mismatch occurs before the MOV finished
7459 ** and phase errors are to be handled by SCRIPTS (896).
7460 ** The chip will load the DSP with the phase mismatch
7461 ** JUMP address and interrupt the host processor.
7463 **----------------------------------------------------------
7466 static void ncr_int_par (ncb_p np
, u_short sist
)
7468 u_char hsts
= INB (HS_PRT
);
7469 u_int32 dsp
= INL (nc_dsp
);
7470 u_int32 dbc
= INL (nc_dbc
);
7471 u_int32 dsa
= INL (nc_dsa
);
7472 u_char sbcl
= INB (nc_sbcl
);
7473 u_char cmd
= dbc
>> 24;
7474 int phase
= cmd
& 7;
7476 printk("%s: SCSI parity error detected: SCR1=%d DBC=%x SBCL=%x\n",
7477 ncr_name(np
), hsts
, dbc
, sbcl
);
7480 ** Check that the chip is connected to the SCSI BUS.
7482 if (!(INB (nc_scntl1
) & ISCON
)) {
7483 if (!(driver_setup
.recovery
& 1)) {
7484 ncr_recover_scsi_int(np
, HS_FAIL
);
7491 ** If the nexus is not clearly identified, reset the bus.
7492 ** We will try to do better later.
7494 if (!ncr_ccb_from_dsa(np
, dsa
))
7498 ** Check instruction was a MOV, direction was INPUT and
7501 if ((cmd
& 0xc0) || !(phase
& 1) || !(sbcl
& 0x8))
7505 ** Keep track of the parity error.
7507 OUTONB (HF_PRT
, HF_PAR_ERR
);
7510 ** Prepare the message to send to the device.
7512 np
->msgout
[0] = (phase
== 7) ? M_PARITY
: M_ID_ERROR
;
7515 ** If the old phase was DATA IN phase, we have to deal with
7516 ** the 3 situations described above.
7517 ** For other input phases (MSG IN and STATUS), the device
7518 ** must resend the whole thing that failed parity checking
7519 ** or signal error. So, jumping to dispatcher should be OK.
7522 /* Phase mismatch handled by SCRIPTS */
7523 if (dsp
== NCB_SCRIPTH_PHYS (np
, pm_handle
))
7525 /* Phase mismatch handled by the C code */
7528 /* No phase mismatch occurred */
7530 OUTL (nc_temp
, dsp
);
7531 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, databreak
));
7535 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, clrack
));
7539 ncr_start_reset(np
);
7543 /*==========================================================
7546 ** ncr chip exception handler for phase errors.
7549 **==========================================================
7551 ** We have to construct a new transfer descriptor,
7552 ** to transfer the rest of the current block.
7554 **----------------------------------------------------------
7557 static void ncr_int_ma (ncb_p np
)
7570 u_char hflags
, hflags0
;
7574 #ifdef SCSI_NCR_PROFILE_SUPPORT
7575 ++np
->profile
.num_break
;
7583 rest
= dbc
& 0xffffff;
7587 ** locate matching cp.
7589 cp
= ncr_ccb_from_dsa(np
, dsa
);
7592 ** Donnot take into account dma fifo and various buffers in
7593 ** DATA IN phase since the chip flushes everything before
7594 ** raising the MA interrupt for interrupted INPUT phases.
7596 if ((cmd
& 7) != 1) {
7601 ** Read DFIFO, CTEST[4-6] using 1 PCI bus ownership.
7603 dfifo
= INL(nc_dfifo
);
7606 ** Calculate remaining bytes in DMA fifo.
7607 ** (CTEST5 = dfifo >> 16)
7609 if (dfifo
& (DFS
<< 16))
7610 delta
= ((((dfifo
>> 8) & 0x300) |
7611 (dfifo
& 0xff)) - rest
) & 0x3ff;
7613 delta
= ((dfifo
& 0xff) - rest
) & 0x7f;
7616 ** The data in the dma fifo has not been transfered to
7617 ** the target -> add the amount to the rest
7618 ** and clear the data.
7619 ** Check the sstat2 register in case of wide transfer.
7622 ss0
= INB (nc_sstat0
);
7623 if (ss0
& OLF
) rest
++;
7624 if (ss0
& ORF
) rest
++;
7625 if (cp
&& (cp
->phys
.select
.sel_scntl3
& EWS
)) {
7626 ss2
= INB (nc_sstat2
);
7627 if (ss2
& OLF1
) rest
++;
7628 if (ss2
& ORF1
) rest
++;
7634 OUTB (nc_ctest3
, np
->rv_ctest3
| CLF
); /* dma fifo */
7635 OUTB (nc_stest3
, TE
|CSF
); /* scsi fifo */
7639 ** log the information
7642 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
7643 printk ("P%x%x RL=%d D=%d ", cmd
&7, INB(nc_sbcl
)&7,
7644 (unsigned) rest
, (unsigned) delta
);
7647 ** try to find the interrupted script command,
7648 ** and the address at which to continue.
7652 if (dsp
> np
->p_script
&&
7653 dsp
<= np
->p_script
+ sizeof(struct script
)) {
7654 vdsp
= (u_int32
*)((char*)np
->script0
+ (dsp
-np
->p_script
-8));
7657 else if (dsp
> np
->p_scripth
&&
7658 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
7659 vdsp
= (u_int32
*)((char*)np
->scripth0
+ (dsp
-np
->p_scripth
-8));
7664 ** log the information
7666 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
7667 printk ("\nCP=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
7668 cp
, (unsigned)dsp
, (unsigned)nxtdsp
, vdsp
, cmd
);
7672 printk ("%s: interrupted SCRIPT address not found.\n",
7678 printk ("%s: SCSI phase error fixup: CCB already dequeued.\n",
7684 ** get old startaddress and old length.
7687 oadr
= scr_to_cpu(vdsp
[1]);
7689 if (cmd
& 0x10) { /* Table indirect */
7690 tblp
= (u_int32
*) ((char*) &cp
->phys
+ oadr
);
7691 olen
= scr_to_cpu(tblp
[0]);
7692 oadr
= scr_to_cpu(tblp
[1]);
7694 tblp
= (u_int32
*) 0;
7695 olen
= scr_to_cpu(vdsp
[0]) & 0xffffff;
7698 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
7699 printk ("OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
7700 (unsigned) (scr_to_cpu(vdsp
[0]) >> 24),
7707 ** check cmd against assumed interrupted script command.
7710 if (cmd
!= (scr_to_cpu(vdsp
[0]) >> 24)) {
7711 PRINT_ADDR(cp
->cmd
);
7712 printk ("internal error: cmd=%02x != %02x=(vdsp[0] >> 24)\n",
7713 (unsigned)cmd
, (unsigned)scr_to_cpu(vdsp
[0]) >> 24);
7719 ** if old phase not dataphase, leave here.
7723 PRINT_ADDR(cp
->cmd
);
7724 printk ("phase change %x-%x %d@%08x resid=%d.\n",
7725 cmd
&7, INB(nc_sbcl
)&7, (unsigned)olen
,
7726 (unsigned)oadr
, (unsigned)rest
);
7727 goto unexpected_phase
;
7731 ** Choose the correct PM save area.
7733 ** Look at the PM_SAVE SCRIPT if you want to understand
7734 ** this stuff. The equivalent code is implemented in
7735 ** SCRIPTS for the 896 that is able to handle PM from
7736 ** the SCRIPTS processor.
7739 hflags0
= INB (HF_PRT
);
7742 if (hflags
& (HF_IN_PM0
| HF_IN_PM1
| HF_DP_SAVED
)) {
7743 if (hflags
& HF_IN_PM0
)
7744 nxtdsp
= scr_to_cpu(cp
->phys
.pm0
.ret
);
7745 else if (hflags
& HF_IN_PM1
)
7746 nxtdsp
= scr_to_cpu(cp
->phys
.pm1
.ret
);
7748 if (hflags
& HF_DP_SAVED
)
7749 hflags
^= HF_ACT_PM
;
7752 if (!(hflags
& HF_ACT_PM
)) {
7754 newcmd
= NCB_SCRIPT_PHYS(np
, pm0_data
);
7758 newcmd
= NCB_SCRIPT_PHYS(np
, pm1_data
);
7761 hflags
&= ~(HF_IN_PM0
| HF_IN_PM1
| HF_DP_SAVED
);
7762 if (hflags
!= hflags0
)
7763 OUTB (HF_PRT
, hflags
);
7766 ** fillin the phase mismatch context
7769 pm
->sg
.addr
= cpu_to_scr(oadr
+ olen
- rest
);
7770 pm
->sg
.size
= cpu_to_scr(rest
);
7771 pm
->ret
= cpu_to_scr(nxtdsp
);
7773 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
7774 PRINT_ADDR(cp
->cmd
);
7775 printk ("PM %x %x %x / %x %x %x.\n",
7776 hflags0
, hflags
, newcmd
,
7777 (unsigned)scr_to_cpu(pm
->sg
.addr
),
7778 (unsigned)scr_to_cpu(pm
->sg
.size
),
7779 (unsigned)scr_to_cpu(pm
->ret
));
7783 ** fake the return address (to the patch).
7784 ** and restart script processor at dispatcher.
7787 OUTL (nc_temp
, newcmd
);
7788 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, databreak
));
7792 ** Unexpected phase changes that occurs when the current phase
7793 ** is not a DATA IN or DATA OUT phase are due to error conditions.
7794 ** Such event may only happen when the SCRIPTS is using a
7795 ** multibyte SCSI MOVE.
7797 ** Phase change Some possible cause
7799 ** COMMAND --> MSG IN SCSI parity error detected by target.
7800 ** COMMAND --> STATUS Bad command or refused by target.
7801 ** MSG OUT --> MSG IN Message rejected by target.
7802 ** MSG OUT --> COMMAND Bogus target that discards extended
7803 ** negotiation messages.
7805 ** The code below does not care of the new phase and so
7806 ** trusts the target. Why to annoy it ?
7807 ** If the interrupted phase is COMMAND phase, we restart at
7809 ** If a target does not get all the messages after selection,
7810 ** the code assumes blindly that the target discards extended
7811 ** messages and clears the negotiation status.
7812 ** If the target does not want all our response to negotiation,
7813 ** we force a SIR_NEGO_PROTO interrupt (it is a hack that avoids
7814 ** bloat for such a should_not_happen situation).
7815 ** In all other situation, we reset the BUS.
7816 ** Are these assumptions reasonnable ? (Wait and see ...)
7823 case 2: /* COMMAND phase */
7824 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
7827 case 3: /* STATUS phase */
7828 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
7831 case 6: /* MSG OUT phase */
7833 ** If the device may want to use untagged when we want
7834 ** tagged, we prepare an IDENTIFY without disc. granted,
7835 ** since we will not be able to handle reselect.
7836 ** Otherwise, we just don't care.
7838 if (dsp
== NCB_SCRIPT_PHYS (np
, send_ident
)) {
7839 if (cp
->tag
!= NO_TAG
&& olen
- rest
<= 3) {
7840 cp
->host_status
= HS_BUSY
;
7841 np
->msgout
[0] = M_IDENTIFY
| cp
->lun
;
7842 nxtdsp
= NCB_SCRIPTH_PHYS (np
, ident_break_atn
);
7845 nxtdsp
= NCB_SCRIPTH_PHYS (np
, ident_break
);
7847 else if (dsp
== NCB_SCRIPTH_PHYS (np
, send_wdtr
) ||
7848 dsp
== NCB_SCRIPTH_PHYS (np
, send_sdtr
)) {
7849 nxtdsp
= NCB_SCRIPTH_PHYS (np
, nego_bad_phase
);
7853 case 7: /* MSG IN phase */
7854 nxtdsp
= NCB_SCRIPT_PHYS (np
, clrack
);
7860 OUTL (nc_dsp
, nxtdsp
);
7865 ncr_start_reset(np
);
7868 /*==========================================================
7870 ** ncr chip handler for QUEUE FULL and CHECK CONDITION
7872 **==========================================================
7874 ** On QUEUE FULL status, we set the actual tagged command
7875 ** queue depth to the number of disconnected CCBs that is
7876 ** hopefully a good value to avoid further QUEUE FULL.
7878 ** On CHECK CONDITION or COMMAND TERMINATED, we use the
7879 ** CCB of the failed command for performing a REQUEST
7880 ** SENSE SCSI command.
7882 ** We do not want to change the order commands will be
7883 ** actually queued to the device after we received a
7884 ** QUEUE FULL status. We also want to properly deal with
7885 ** contingent allegiance condition. For these reasons,
7886 ** we remove from the start queue all commands for this
7887 ** LUN that haven't been yet queued to the device and
7888 ** put them back in the correponding LUN queue, then
7889 ** requeue the CCB that failed in front of the LUN queue.
7890 ** I just hope this not to be performed too often. :)
7892 **----------------------------------------------------------
7895 static void ncr_sir_to_redo(ncb_p np
, int num
, ccb_p cp
)
7897 Scsi_Cmnd
*cmd
= cp
->cmd
;
7898 tcb_p tp
= &np
->target
[cp
->target
];
7899 lcb_p lp
= tp
->lp
[cp
->lun
];
7903 u_char s_status
= INB (SS_PRT
);
7906 ** Remove all CCBs queued to the chip for that LUN and put
7907 ** them back in the LUN CCB wait queue.
7910 int i
= np
->squeueput
;
7911 int j
= (INL (nc_scratcha
) - vtobus(np
->squeue
)) / 4;
7912 int k
= np
->squeueput
;
7914 busyccbs
= lp
->queuedccbs
;
7921 cp2
= ncr_ccb_from_dsa(np
, scr_to_cpu(np
->squeue
[i
]));
7924 if (cp2
->target
!= cp
->target
|| cp2
->lun
!= cp
->lun
)
7926 xpt_remque(&cp2
->link_ccbq
);
7927 xpt_insque_head(&cp2
->link_ccbq
, &lp
->wait_ccbq
);
7930 np
->squeue
[i
] = DSA_INVALID
;
7935 ** Requeue the interrupted CCB in front of
7936 ** the LUN CCB wait queue.
7938 xpt_remque(&cp
->link_ccbq
);
7939 xpt_insque_head(&cp
->link_ccbq
, &lp
->wait_ccbq
);
7944 ** Repair the startqueue if necessary.
7946 if (k
!= np
->squeueput
) {
7950 if (j
>= MAX_START
*2)
7952 if (np
->squeue
[j
] == DSA_INVALID
)
7954 np
->squeue
[k
] = np
->squeue
[j
];
7955 if (j
== np
->squeueput
)
7958 if (k
>= MAX_START
*2)
7966 ** Now we can restart the SCRIPTS processor safely.
7969 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, start
));
7972 default: /* Just for safety, should never happen */
7974 if (!lp
|| !lp
->queuedccbs
) {
7975 ncr_complete(np
, cp
);
7978 if (bootverbose
>= 1) {
7980 printk ("QUEUE FULL! %d busy, %d disconnected CCBs\n",
7981 busyccbs
, lp
->queuedccbs
);
7984 ** Decrease number of tags to the number of
7985 ** disconnected commands.
7987 if (lp
->queuedccbs
< lp
->numtags
) {
7988 lp
->numtags
= lp
->queuedccbs
;
7990 ncr_setup_tags (np
, cp
->target
, cp
->lun
);
7993 ** Repair the offending CCB.
7995 cp
->phys
.header
.savep
= cp
->startp
;
7996 cp
->host_status
= HS_BUSY
;
7997 cp
->scsi_status
= S_ILLEGAL
;
7998 cp
->host_flags
&= HF_PM_TO_C
;
8005 ** If we were requesting sense, give up.
8007 if (cp
->auto_sense
) {
8008 ncr_complete(np
, cp
);
8013 ** Device returned CHECK CONDITION status.
8014 ** Prepare all needed data strutures for getting
8021 cp
->scsi_smsg2
[0] = M_IDENTIFY
| cp
->lun
;
8022 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg2
));
8023 cp
->phys
.smsg
.size
= cpu_to_scr(1);
8028 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, sensecmd
));
8029 cp
->phys
.cmd
.size
= cpu_to_scr(6);
8032 ** patch requested size into sense command
8034 cp
->sensecmd
[0] = 0x03;
8035 cp
->sensecmd
[1] = cp
->lun
<< 5;
8036 cp
->sensecmd
[4] = sizeof(cmd
->sense_buffer
);
8041 cp
->phys
.sense
.addr
=
8042 cpu_to_scr(vtobus (&cmd
->sense_buffer
[0]));
8043 cp
->phys
.sense
.size
=
8044 cpu_to_scr(sizeof(cmd
->sense_buffer
));
8047 ** requeue the command.
8049 startp
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, sdata_in
));
8051 cp
->phys
.header
.savep
= startp
;
8052 cp
->phys
.header
.goalp
= startp
+ 24;
8053 cp
->phys
.header
.lastp
= startp
;
8054 cp
->phys
.header
.wgoalp
= startp
+ 24;
8055 cp
->phys
.header
.wlastp
= startp
;
8057 cp
->host_status
= HS_BUSY
;
8058 cp
->scsi_status
= S_ILLEGAL
;
8060 cp
->auto_sense
= s_status
;
8062 cp
->phys
.header
.go
.start
=
8063 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
8066 ** Select without ATN for quirky devices.
8068 if (tp
->quirks
& QUIRK_NOMSG
)
8069 cp
->phys
.header
.go
.start
=
8070 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, select_no_atn
));
8073 ** If lp not yet allocated, requeue the command.
8076 ncr_put_start_queue(np
, cp
);
8081 ** requeue awaiting scsi commands for this lun.
8084 ncr_start_next_ccb(np
, lp
, 1);
8090 /*==========================================================
8093 ** ncr chip exception handler for programmed interrupts.
8096 **==========================================================
8099 static int ncr_show_msg (u_char
* msg
)
8103 if (*msg
==M_EXTENDED
) {
8105 if (i
-1>msg
[1]) break;
8106 printk ("-%x",msg
[i
]);
8109 } else if ((*msg
& 0xf0) == 0x20) {
8110 printk ("-%x",msg
[1]);
8117 void ncr_int_sir (ncb_p np
)
8120 u_char chg
, ofs
, per
, fak
, wide
;
8121 u_char num
= INB (nc_dsps
);
8123 u_long dsa
= INL (nc_dsa
);
8124 u_char target
= INB (nc_sdid
) & 0x0f;
8125 tcb_p tp
= &np
->target
[target
];
8127 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("I#%d", num
);
8130 case SIR_SEL_ATN_NO_MSG_OUT
:
8132 ** The device didn't go to MSG OUT phase after having
8133 ** been selected with ATN. We donnot want to handle
8136 printk ("%s:%d: No MSG OUT phase after selection with ATN.\n",
8137 ncr_name (np
), target
);
8139 case SIR_RESEL_NO_MSG_IN
:
8140 case SIR_RESEL_NO_IDENTIFY
:
8142 ** If devices reselecting without sending an IDENTIFY
8143 ** message still exist, this should help.
8144 ** We just assume lun=0, 1 CCB, no tag.
8147 OUTL (nc_dsa
, scr_to_cpu(tp
->lp
[0]->tasktbl
[0]));
8148 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, resel_go
));
8151 case SIR_RESEL_BAD_LUN
:
8152 np
->msgout
[0] = M_RESET
;
8154 case SIR_RESEL_BAD_I_T_L
:
8155 np
->msgout
[0] = M_ABORT
;
8157 case SIR_RESEL_BAD_I_T_L_Q
:
8158 np
->msgout
[0] = M_ABORT_TAG
;
8160 case SIR_RESEL_ABORTED
:
8161 np
->lastmsg
= np
->msgout
[0];
8162 np
->msgout
[0] = M_NOOP
;
8163 printk ("%s:%d: message %d sent on bad reselection.\n",
8164 ncr_name (np
), target
, np
->lastmsg
);
8166 case SIR_MSG_OUT_DONE
:
8167 np
->lastmsg
= np
->msgout
[0];
8168 np
->msgout
[0] = M_NOOP
;
8169 /* Should we really care of that */
8170 if (np
->lastmsg
== M_PARITY
|| np
->lastmsg
== M_ID_ERROR
)
8171 OUTOFFB (HF_PRT
, HF_PAR_ERR
);
8173 case SIR_BAD_STATUS
:
8174 cp
= ncr_ccb_from_dsa(np
, dsa
);
8177 ncr_sir_to_redo(np
, num
, cp
);
8183 cp
= ncr_ccb_from_dsa(np
, dsa
);
8189 /*-----------------------------------------------------------------------------
8191 ** Was Sie schon immer ueber transfermode negotiation wissen wollten ...
8193 ** We try to negotiate sync and wide transfer only after
8194 ** a successfull inquire command. We look at byte 7 of the
8195 ** inquire data to determine the capabilities of the target.
8197 ** When we try to negotiate, we append the negotiation message
8198 ** to the identify and (maybe) simple tag message.
8199 ** The host status field is set to HS_NEGOTIATE to mark this
8202 ** If the target doesn't answer this message immidiately
8203 ** (as required by the standard), the SIR_NEGO_FAIL interrupt
8204 ** will be raised eventually.
8205 ** The handler removes the HS_NEGOTIATE status, and sets the
8206 ** negotiated value to the default (async / nowide).
8208 ** If we receive a matching answer immediately, we check it
8209 ** for validity, and set the values.
8211 ** If we receive a Reject message immediately, we assume the
8212 ** negotiation has failed, and fall back to standard values.
8214 ** If we receive a negotiation message while not in HS_NEGOTIATE
8215 ** state, it's a target initiated negotiation. We prepare a
8216 ** (hopefully) valid answer, set our parameters, and send back
8217 ** this answer to the target.
8219 ** If the target doesn't fetch the answer (no message out phase),
8220 ** we assume the negotiation has failed, and fall back to default
8223 ** When we set the values, we adjust them in all ccbs belonging
8224 ** to this target, in the controller's register, and in the "phys"
8225 ** field of the controller's struct ncb.
8227 ** Possible cases: hs sir msg_in value send goto
8228 ** We try to negotiate:
8229 ** -> target doesnt't msgin NEG FAIL noop defa. - dispatch
8230 ** -> target rejected our msg NEG FAIL reject defa. - dispatch
8231 ** -> target answered (ok) NEG SYNC sdtr set - clrack
8232 ** -> target answered (!ok) NEG SYNC sdtr defa. REJ--->msg_bad
8233 ** -> target answered (ok) NEG WIDE wdtr set - clrack
8234 ** -> target answered (!ok) NEG WIDE wdtr defa. REJ--->msg_bad
8235 ** -> any other msgin NEG FAIL noop defa. - dispatch
8237 ** Target tries to negotiate:
8238 ** -> incoming message --- SYNC sdtr set SDTR -
8239 ** -> incoming message --- WIDE wdtr set WDTR -
8240 ** We sent our answer:
8241 ** -> target doesn't msgout --- PROTO ? defa. - dispatch
8243 **-----------------------------------------------------------------------------
8246 case SIR_NEGO_FAILED
:
8247 /*-------------------------------------------------------
8249 ** Negotiation failed.
8250 ** Target doesn't send an answer message,
8251 ** or target rejected our message.
8253 ** Remove negotiation request.
8255 **-------------------------------------------------------
8257 OUTB (HS_PRT
, HS_BUSY
);
8261 case SIR_NEGO_PROTO
:
8262 /*-------------------------------------------------------
8264 ** Negotiation failed.
8265 ** Target doesn't fetch the answer message.
8267 **-------------------------------------------------------
8270 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
8271 PRINT_ADDR(cp
->cmd
);
8272 printk ("negotiation failed sir=%x status=%x.\n",
8273 num
, cp
->nego_status
);
8277 ** any error in negotiation:
8278 ** fall back to default mode.
8280 switch (cp
->nego_status
) {
8283 ncr_setsync (np
, cp
, 0, 0xe0);
8287 ncr_setwide (np
, cp
, 0, 0);
8291 np
->msgin
[0] = M_NOOP
;
8292 np
->msgout
[0] = M_NOOP
;
8293 cp
->nego_status
= 0;
8298 ** Synchronous request message received.
8301 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
8302 PRINT_ADDR(cp
->cmd
);
8303 printk ("sync msgin: ");
8304 (void) ncr_show_msg (np
->msgin
);
8309 ** get requested values.
8315 if (ofs
==0) per
=255;
8318 ** if target sends SDTR message,
8319 ** it CAN transfer synch.
8323 tp
->inq_byte7
|= INQ7_SYNC
;
8326 ** check values against driver limits.
8329 if (per
< np
->minsync
)
8330 {chg
= 1; per
= np
->minsync
;}
8331 if (per
< tp
->minsync
)
8332 {chg
= 1; per
= tp
->minsync
;}
8333 if (ofs
> tp
->maxoffs
)
8334 {chg
= 1; ofs
= tp
->maxoffs
;}
8337 ** Check against controller limits.
8342 ncr_getsync(np
, per
, &fak
, &scntl3
);
8355 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
8356 PRINT_ADDR(cp
->cmd
);
8357 printk ("sync: per=%d scntl3=0x%x ofs=%d fak=%d chg=%d.\n",
8358 per
, scntl3
, ofs
, fak
, chg
);
8361 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
8362 OUTB (HS_PRT
, HS_BUSY
);
8363 switch (cp
->nego_status
) {
8367 ** This was an answer message
8371 ** Answer wasn't acceptable.
8373 ncr_setsync (np
, cp
, 0, 0xe0);
8374 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, msg_bad
));
8379 ncr_setsync (np
, cp
, scntl3
, (fak
<<5)|ofs
);
8380 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, clrack
));
8385 ncr_setwide (np
, cp
, 0, 0);
8391 ** It was a request. Set value and
8392 ** prepare an answer message
8395 ncr_setsync (np
, cp
, scntl3
, (fak
<<5)|ofs
);
8397 np
->msgout
[0] = M_EXTENDED
;
8399 np
->msgout
[2] = M_X_SYNC_REQ
;
8400 np
->msgout
[3] = per
;
8401 np
->msgout
[4] = ofs
;
8403 cp
->nego_status
= NS_SYNC
;
8405 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
8406 PRINT_ADDR(cp
->cmd
);
8407 printk ("sync msgout: ");
8408 (void) ncr_show_msg (np
->msgout
);
8413 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, msg_bad
));
8416 np
->msgin
[0] = M_NOOP
;
8422 ** Wide request message received.
8424 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
8425 PRINT_ADDR(cp
->cmd
);
8426 printk ("wide msgin: ");
8427 (void) ncr_show_msg (np
->msgin
);
8432 ** get requested values.
8436 wide
= np
->msgin
[3];
8439 ** if target sends WDTR message,
8440 ** it CAN transfer wide.
8444 tp
->inq_byte7
|= INQ7_WIDE16
;
8447 ** check values against driver limits.
8450 if (wide
> tp
->usrwide
)
8451 {chg
= 1; wide
= tp
->usrwide
;}
8453 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
8454 PRINT_ADDR(cp
->cmd
);
8455 printk ("wide: wide=%d chg=%d.\n", wide
, chg
);
8458 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
8459 OUTB (HS_PRT
, HS_BUSY
);
8460 switch (cp
->nego_status
) {
8464 ** This was an answer message
8468 ** Answer wasn't acceptable.
8470 ncr_setwide (np
, cp
, 0, 1);
8471 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, msg_bad
));
8476 ncr_setwide (np
, cp
, wide
, 1);
8477 OUTL (nc_dsp
, NCB_SCRIPT_PHYS (np
, clrack
));
8482 ncr_setsync (np
, cp
, 0, 0xe0);
8488 ** It was a request, set value and
8489 ** prepare an answer message
8492 ncr_setwide (np
, cp
, wide
, 1);
8494 np
->msgout
[0] = M_EXTENDED
;
8496 np
->msgout
[2] = M_X_WIDE_REQ
;
8497 np
->msgout
[3] = wide
;
8499 np
->msgin
[0] = M_NOOP
;
8501 cp
->nego_status
= NS_WIDE
;
8503 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
8504 PRINT_ADDR(cp
->cmd
);
8505 printk ("wide msgout: ");
8506 (void) ncr_show_msg (np
->msgin
);
8511 /*--------------------------------------------------------------------
8513 ** Processing of special messages
8515 **--------------------------------------------------------------------
8518 case SIR_REJECT_RECEIVED
:
8519 /*-----------------------------------------------
8521 ** We received a M_REJECT message.
8523 **-----------------------------------------------
8526 PRINT_ADDR(cp
->cmd
);
8527 printk ("M_REJECT received (%x:%x).\n",
8528 (unsigned)scr_to_cpu(np
->lastmsg
), np
->msgout
[0]);
8531 case SIR_REJECT_TO_SEND
:
8532 /*-----------------------------------------------
8534 ** We received an unknown message
8536 **-----------------------------------------------
8539 PRINT_ADDR(cp
->cmd
);
8540 printk ("M_REJECT to send for ");
8541 (void) ncr_show_msg (np
->msgin
);
8543 np
->msgout
[0] = M_REJECT
;
8546 /*--------------------------------------------------------------------
8548 ** Processing of special messages
8550 **--------------------------------------------------------------------
8553 case SIR_IGN_RESIDUE
:
8554 /*-----------------------------------------------
8556 ** We received an IGNORE RESIDUE message,
8557 ** which couldn't be handled by the script.
8559 **-----------------------------------------------
8562 PRINT_ADDR(cp
->cmd
);
8563 printk ("M_IGN_RESIDUE received, but not yet implemented.\n");
8566 case SIR_MISSING_SAVE
:
8567 /*-----------------------------------------------
8569 ** We received an DISCONNECT message,
8570 ** but the datapointer wasn't saved before.
8572 **-----------------------------------------------
8575 PRINT_ADDR(cp
->cmd
);
8576 printk ("M_DISCONNECT received, but datapointer not saved: "
8577 "data=%x save=%x goal=%x.\n",
8578 (unsigned) INL (nc_temp
),
8579 (unsigned) scr_to_cpu(np
->header
.savep
),
8580 (unsigned) scr_to_cpu(np
->header
.goalp
));
8586 OUTONB (nc_dcntl
, (STD
|NOCOM
));
8590 /*==========================================================
8593 ** Aquire a control block
8596 **==========================================================
8599 static ccb_p
ncr_get_ccb (ncb_p np
, u_char tn
, u_char ln
)
8601 tcb_p tp
= &np
->target
[tn
];
8602 lcb_p lp
= tp
->lp
[ln
];
8603 u_char tag
= NO_TAG
;
8605 ccb_p cp
= (ccb_p
) 0;
8608 ** Allocate a new CCB if needed.
8610 if (xpt_que_empty(&np
->free_ccbq
))
8611 (void) ncr_alloc_ccb(np
);
8614 ** Look for a free CCB
8616 qp
= xpt_remque_head(&np
->free_ccbq
);
8619 cp
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
8622 ** If the LCB is not yet available and we already
8623 ** have queued a CCB for a LUN without LCB,
8624 ** give up. Otherwise all is fine. :-)
8627 if (xpt_que_empty(&np
->b0_ccbq
))
8628 xpt_insque_head(&cp
->link_ccbq
, &np
->b0_ccbq
);
8633 ** Tune tag mode if asked by user.
8635 if (lp
->queuedepth
!= lp
->numtags
) {
8636 ncr_setup_tags(np
, tn
, ln
);
8640 ** Get a tag for this nexus if required.
8641 ** Keep from using more tags than we can handle.
8644 if (lp
->busyccbs
< lp
->maxnxs
) {
8645 tag
= lp
->cb_tags
[lp
->ia_tag
];
8647 if (lp
->ia_tag
== SCSI_NCR_MAX_TAGS
)
8649 lp
->tags_umap
|= (((tagmap_t
) 1) << tag
);
8656 ** Put the CCB in the LUN wait queue and
8657 ** count it as busy.
8659 xpt_insque_tail(&cp
->link_ccbq
, &lp
->wait_ccbq
);
8664 ** Remember all informations needed to free this CCB.
8670 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
8671 PRINT_LUN(np
, tn
, ln
);
8672 printk ("ccb @%p using tag %d.\n", cp
, tag
);
8678 xpt_insque_head(&cp
->link_ccbq
, &np
->free_ccbq
);
8682 /*==========================================================
8685 ** Release one control block
8688 **==========================================================
8691 static void ncr_free_ccb (ncb_p np
, ccb_p cp
)
8693 tcb_p tp
= &np
->target
[cp
->target
];
8694 lcb_p lp
= tp
->lp
[cp
->lun
];
8696 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
8697 PRINT_LUN(np
, cp
->target
, cp
->lun
);
8698 printk ("ccb @%p freeing tag %d.\n", cp
, cp
->tag
);
8702 ** If lun control block available, make available
8703 ** the task slot and the tag if any.
8704 ** Decrement counters.
8707 if (cp
->tag
!= NO_TAG
) {
8708 lp
->cb_tags
[lp
->if_tag
++] = cp
->tag
;
8709 if (lp
->if_tag
== SCSI_NCR_MAX_TAGS
)
8711 lp
->tags_umap
&= ~(((tagmap_t
) 1) << cp
->tag
);
8712 lp
->tags_smap
&= lp
->tags_umap
;
8713 lp
->tasktbl
[cp
->tag
] = cpu_to_scr(np
->p_bad_i_t_l_q
);
8715 lp
->tasktbl
[0] = cpu_to_scr(np
->p_bad_i_t_l
);
8724 ** Make this CCB available.
8726 xpt_remque(&cp
->link_ccbq
);
8727 xpt_insque_head(&cp
->link_ccbq
, &np
->free_ccbq
);
8728 cp
-> host_status
= HS_IDLE
;
8732 /*------------------------------------------------------------------------
8733 ** Allocate a CCB and initialize its fixed part.
8734 **------------------------------------------------------------------------
8735 **------------------------------------------------------------------------
8737 static ccb_p
ncr_alloc_ccb(ncb_p np
)
8743 ** Allocate memory for this CCB.
8745 cp
= m_calloc(sizeof(struct ccb
), "CCB", MEMO_WARN
);
8750 ** Count it and initialyze it.
8755 ** Remember virtual and bus address of this ccb.
8757 cp
->p_ccb
= vtobus(cp
);
8760 ** Insert this ccb into the hashed list.
8762 hcode
= CCB_HASH_CODE(cp
->p_ccb
);
8763 cp
->link_ccbh
= np
->ccbh
[hcode
];
8764 np
->ccbh
[hcode
] = cp
;
8767 ** Initialyze the start and restart actions.
8769 cp
->phys
.header
.go
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
8770 cp
->phys
.header
.go
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS(np
,bad_i_t_l
));
8773 ** Chain into wakeup list and free ccb queue.
8775 cp
->link_ccb
= np
->ccbc
;
8778 xpt_insque_head(&cp
->link_ccbq
, &np
->free_ccbq
);
8783 /*------------------------------------------------------------------------
8784 ** Look up a CCB from a DSA value.
8785 **------------------------------------------------------------------------
8786 **------------------------------------------------------------------------
8788 static ccb_p
ncr_ccb_from_dsa(ncb_p np
, u_long dsa
)
8793 hcode
= CCB_HASH_CODE(dsa
);
8794 cp
= np
->ccbh
[hcode
];
8796 if (cp
->p_ccb
== dsa
)
8804 /*==========================================================
8807 ** Allocation of resources for Targets/Luns/Tags.
8810 **==========================================================
8814 /*------------------------------------------------------------------------
8815 ** Target control block initialisation.
8816 **------------------------------------------------------------------------
8817 ** This data structure is fully initialized after a SCSI command
8818 ** has been successfully completed for this target.
8819 **------------------------------------------------------------------------
8821 static void ncr_init_tcb (ncb_p np
, u_char tn
)
8823 tcb_p tp
= &np
->target
[tn
];
8831 ** Allocate the lcb bus address array.
8833 tp
->luntbl
= m_calloc(256, "LUNTBL", MEMO_WARN
);
8838 ** Compute the bus address of this table.
8840 tp
->b_luntbl
= cpu_to_scr(vtobus(tp
->luntbl
));
8843 ** Check some alignments required by the chip.
8845 assert (( (offsetof(struct ncr_reg
, nc_sxfer
) ^
8846 offsetof(struct tcb
, sval
)) &3) == 0);
8847 assert (( (offsetof(struct ncr_reg
, nc_scntl3
) ^
8848 offsetof(struct tcb
, wval
)) &3) == 0);
8851 /*------------------------------------------------------------------------
8852 ** Lun control block allocation and initialization.
8853 **------------------------------------------------------------------------
8854 ** This data structure is allocated and initialized after a SCSI
8855 ** command has been successfully completed for this target/lun.
8856 **------------------------------------------------------------------------
8858 static lcb_p
ncr_alloc_lcb (ncb_p np
, u_char tn
, u_char ln
)
8860 tcb_p tp
= &np
->target
[tn
];
8861 lcb_p lp
= tp
->lp
[ln
];
8864 ** Already done, return.
8870 ** Initialize the target control block if not yet.
8872 ncr_init_tcb(np
, tn
);
8877 ** Allocate the lcb.
8879 lp
= m_calloc(sizeof(struct lcb
), "LCB", MEMO_WARN
);
8885 ** Make it available to the chip.
8887 tp
->luntbl
[ln
] = cpu_to_scr(vtobus(lp
));
8890 ** Initialize the CCB queue headers.
8892 xpt_que_init(&lp
->busy_ccbq
);
8893 xpt_que_init(&lp
->wait_ccbq
);
8896 ** Set max CCBs to 1 and use the default task array
8900 lp
->tasktbl
= &lp
->tasktbl_0
;
8901 lp
->b_tasktbl
= cpu_to_scr(vtobus(lp
->tasktbl
));
8902 lp
->tasktbl
[0] = cpu_to_scr(np
->p_notask
);
8903 lp
->resel_task
= cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_notag
));
8906 ** Initialize command queuing control.
8916 /*------------------------------------------------------------------------
8917 ** Lun control block setup on INQUIRY data received.
8918 **------------------------------------------------------------------------
8919 ** We only support WIDE, SYNC for targets and CMDQ for logical units.
8920 ** This setup is done on each INQUIRY since we are expecting user
8921 ** will play with CHANGE DEFINITION commands. :-)
8922 **------------------------------------------------------------------------
8924 static lcb_p
ncr_setup_lcb (ncb_p np
, u_char tn
, u_char ln
, u_char
*inq_data
)
8926 tcb_p tp
= &np
->target
[tn
];
8927 lcb_p lp
= tp
->lp
[ln
];
8932 ** If no lcb, try to allocate it.
8934 if (!lp
&& !(lp
= ncr_alloc_lcb(np
, tn
, ln
)))
8938 ** Get device quirks from a speciality table.
8940 tp
->quirks
= ncr_lookup (inq_data
);
8941 if (tp
->quirks
&& bootverbose
) {
8942 PRINT_LUN(np
, tn
, ln
);
8943 printk ("quirks=%x.\n", tp
->quirks
);
8947 ** Evaluate trustable target/unit capabilities.
8948 ** We only believe device version >= SCSI-2 that
8949 ** use appropriate response data format (2).
8950 ** But it seems that some CCS devices also
8951 ** support SYNC and I donnot want to frustrate
8955 if ((inq_data
[2] & 0x7) >= 2 && (inq_data
[3] & 0xf) == 2)
8956 inq_byte7
= inq_data
[7];
8957 else if ((inq_data
[2] & 0x7) == 1 && (inq_data
[3] & 0xf) == 1)
8958 inq_byte7
= INQ7_SYNC
;
8961 ** Throw away announced LUN capabilities if we are told
8962 ** that there is no real device supported by the logical unit.
8964 if ((inq_data
[0] & 0xe0) > 0x20 || (inq_data
[0] & 0x1f) == 0x1f)
8965 inq_byte7
&= (INQ7_SYNC
| INQ7_WIDE16
);
8968 ** If user is wanting SYNC, force this feature.
8970 if (driver_setup
.force_sync_nego
)
8971 inq_byte7
|= INQ7_SYNC
;
8974 ** Prepare negotiation if SIP capabilities have changed.
8977 if ((inq_byte7
^ tp
->inq_byte7
) & (INQ7_SYNC
| INQ7_WIDE16
)) {
8978 tp
->inq_byte7
= inq_byte7
;
8979 ncr_negotiate(np
, tp
);
8983 ** If unit supports tagged commands, allocate and
8984 ** initialyze the task table if not yet.
8986 if ((inq_byte7
& INQ7_QUEUE
) && lp
->tasktbl
== &lp
->tasktbl_0
) {
8987 lp
->tasktbl
= m_calloc(256, "TASKTBL", MEMO_WARN
);
8989 lp
->tasktbl
= &lp
->tasktbl_0
;
8992 lp
->b_tasktbl
= cpu_to_scr(vtobus(lp
->tasktbl
));
8993 for (i
= 0 ; i
< 64 ; i
++)
8994 lp
->tasktbl
[i
] = cpu_to_scr(np
->p_notask
);
8995 for (i
= 0 ; i
< SCSI_NCR_MAX_TAGS
; i
++)
8997 lp
->maxnxs
= SCSI_NCR_MAX_TAGS
;
8998 lp
->tags_stime
= jiffies
;
9002 ** Adjust tagged queueing status if needed.
9004 if ((inq_byte7
^ lp
->inq_byte7
) & INQ7_QUEUE
) {
9005 lp
->inq_byte7
= inq_byte7
;
9006 lp
->numtags
= lp
->maxtags
;
9007 ncr_setup_tags (np
, tn
, ln
);
9014 /*==========================================================
9017 ** Build Scatter Gather Block
9020 **==========================================================
9022 ** The transfer area may be scattered among
9023 ** several non adjacent physical pages.
9025 ** We may use MAX_SCATTER blocks.
9027 **----------------------------------------------------------
9031 ** We try to reduce the number of interrupts caused
9032 ** by unexpected phase changes due to disconnects.
9033 ** A typical harddisk may disconnect before ANY block.
9034 ** If we wanted to avoid unexpected phase changes at all
9035 ** we had to use a break point every 512 bytes.
9036 ** Of course the number of scatter/gather blocks is
9038 ** Under Linux, the scatter/gatter blocks are provided by
9039 ** the generic driver. We just have to copy addresses and
9040 ** sizes to the data segment array.
9044 ** For 64 bit systems, we use the 8 upper bits of the size field
9045 ** to provide bus address bits 32-39 to the SCRIPTS processor.
9046 ** This allows the 896 to access up to 1 tera-bytes of memory.
9047 ** For 32 bit chips on 64 bit systems, we must be provided with
9048 ** memory addresses that fit into the first 32 bit bus address
9049 ** range and so, this does not matter and we expect an error from
9050 ** the chip if this ever happen.
9052 ** We use a separate function for the case Linux does not provide
9053 ** a scatter list in order to allow better code optimization
9054 ** for the case we have a scatter list (BTW, for now this just wastes
9055 ** about 40 bytes of code for x86, but my guess is that the scatter
9056 ** code will get more complex later).
9059 #if BITS_PER_LONG > 32
9060 #define SCATTER_ONE(data, badd, len) \
9061 (data)->addr = cpu_to_scr(badd); \
9062 (data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len);
9064 #define SCATTER_ONE(data, badd, len) \
9065 (data)->addr = cpu_to_scr(badd); \
9066 (data)->size = cpu_to_scr(len);
9069 #define CROSS_16MB(p, n) (((((u_long) p) + n - 1) ^ ((u_long) p)) & ~0xffffff)
9071 static int ncr_scatter_no_sglist(ccb_p cp
, Scsi_Cmnd
*cmd
)
9073 struct scr_tblmove
*data
= &cp
->phys
.data
[MAX_SCATTER
-1];
9076 cp
->data_len
= cmd
->request_bufflen
;
9078 if (cmd
->request_bufflen
) {
9079 u_long baddr
= vtobus(cmd
->request_buffer
);
9080 SCATTER_ONE(data
, baddr
, cmd
->request_bufflen
);
9081 if (CROSS_16MB(baddr
, cmd
->request_bufflen
)) {
9082 cp
->host_flags
|= HF_PM_TO_C
;
9084 printk("He! we are crossing a 16 MB boundary (0x%lx, 0x%x)\n",
9085 baddr
, cmd
->request_bufflen
);
9097 ** DEL 472 - 53C896 Rev 1 - Part Number 609-0393055 - ITEM 5.
9099 ** We disable data phase mismatch handling from SCRIPTS for data
9100 ** transfers that contains scatter/gather entries that cross
9101 ** a 16 MB boundary.
9102 ** We use a different scatter function for 896 rev. 1 that needs
9103 ** such a work-around. Doing so, we do not affect performance for
9105 ** This problem should not be triggered for disk IOs under Linux,
9106 ** since such IOs are performed using pages and buffers that are
9107 ** nicely power-of-two sized and aligned. But, since this may change
9108 ** at any time, a work-around was required.
9110 static int ncr_scatter_896R1(ccb_p cp
, Scsi_Cmnd
*cmd
)
9113 int use_sg
= (int) cmd
->use_sg
;
9118 segn
= ncr_scatter_no_sglist(cp
, cmd
);
9119 else if (use_sg
> MAX_SCATTER
)
9122 struct scatterlist
*scatter
= (struct scatterlist
*)cmd
->buffer
;
9123 struct scr_tblmove
*data
= &cp
->phys
.data
[MAX_SCATTER
- use_sg
];
9125 for (segn
= 0; segn
< use_sg
; segn
++) {
9126 u_long baddr
= vtobus(scatter
[segn
].address
);
9127 SCATTER_ONE(&data
[segn
],
9129 scatter
[segn
].length
);
9130 if (CROSS_16MB(baddr
, scatter
[segn
].length
)) {
9131 cp
->host_flags
|= HF_PM_TO_C
;
9133 printk("He! we are crossing a 16 MB boundary (0x%lx, 0x%x)\n",
9134 baddr
, scatter
[segn
].length
);
9137 cp
->data_len
+= scatter
[segn
].length
;
9144 static int ncr_scatter(ccb_p cp
, Scsi_Cmnd
*cmd
)
9147 int use_sg
= (int) cmd
->use_sg
;
9152 segment
= ncr_scatter_no_sglist(cp
, cmd
);
9153 else if (use_sg
> MAX_SCATTER
)
9156 struct scatterlist
*scatter
= (struct scatterlist
*)cmd
->buffer
;
9157 struct scr_tblmove
*data
= &cp
->phys
.data
[MAX_SCATTER
- use_sg
];
9159 for (segment
= 0; segment
< use_sg
; segment
++) {
9160 u_long baddr
= vtobus(scatter
[segment
].address
);
9161 SCATTER_ONE(&data
[segment
],
9163 scatter
[segment
].length
);
9164 cp
->data_len
+= scatter
[segment
].length
;
9171 /*==========================================================
9174 ** Test the pci bus snoop logic :-(
9176 ** Has to be called with interrupts disabled.
9179 **==========================================================
9182 #ifndef NCR_IOMAPPED
9183 static int __init
ncr_regtest (struct ncb
* np
)
9185 register volatile u_int32 data
;
9187 ** ncr registers may NOT be cached.
9188 ** write 0xffffffff to a read only register area,
9189 ** and try to read it back.
9192 OUTL_OFF(offsetof(struct ncr_reg
, nc_dstat
), data
);
9193 data
= INL_OFF(offsetof(struct ncr_reg
, nc_dstat
));
9195 if (data
== 0xffffffff) {
9197 if ((data
& 0xe2f0fffd) != 0x02000080) {
9199 printk ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
9207 static int __init
ncr_snooptest (struct ncb
* np
)
9209 u_int32 ncr_rd
, ncr_wr
, ncr_bk
, host_rd
, host_wr
, pc
;
9211 #ifndef NCR_IOMAPPED
9213 err
|= ncr_regtest (np
);
9214 if (err
) return (err
);
9220 pc
= NCB_SCRIPTH0_PHYS (np
, snooptest
);
9224 ** Set memory and register.
9226 np
->ncr_cache
= cpu_to_scr(host_wr
);
9227 OUTL (nc_temp
, ncr_wr
);
9229 ** Start script (exchange values)
9231 OUTL (nc_dsa
, vtobus(np
));
9234 ** Wait 'til done (with timeout)
9236 for (i
=0; i
<NCR_SNOOP_TIMEOUT
; i
++)
9237 if (INB(nc_istat
) & (INTF
|SIP
|DIP
))
9240 ** Save termination position.
9244 ** Read memory and register.
9246 host_rd
= scr_to_cpu(np
->ncr_cache
);
9247 ncr_rd
= INL (nc_scratcha
);
9248 ncr_bk
= INL (nc_temp
);
9251 ** check for timeout
9253 if (i
>=NCR_SNOOP_TIMEOUT
) {
9254 printk ("CACHE TEST FAILED: timeout.\n");
9258 ** Check termination position.
9260 if (pc
!= NCB_SCRIPTH0_PHYS (np
, snoopend
)+8) {
9261 printk ("CACHE TEST FAILED: script execution failed.\n");
9262 printk ("start=%08lx, pc=%08lx, end=%08lx\n",
9263 (u_long
) NCB_SCRIPTH0_PHYS (np
, snooptest
), (u_long
) pc
,
9264 (u_long
) NCB_SCRIPTH0_PHYS (np
, snoopend
) +8);
9270 if (host_wr
!= ncr_rd
) {
9271 printk ("CACHE TEST FAILED: host wrote %d, ncr read %d.\n",
9272 (int) host_wr
, (int) ncr_rd
);
9275 if (host_rd
!= ncr_wr
) {
9276 printk ("CACHE TEST FAILED: ncr wrote %d, host read %d.\n",
9277 (int) ncr_wr
, (int) host_rd
);
9280 if (ncr_bk
!= ncr_wr
) {
9281 printk ("CACHE TEST FAILED: ncr wrote %d, read back %d.\n",
9282 (int) ncr_wr
, (int) ncr_bk
);
9288 /*==========================================================
9291 ** Profiling the drivers and targets performance.
9294 **==========================================================
9297 #ifdef SCSI_NCR_PROFILE_SUPPORT
9299 static void ncb_profile (ncb_p np
, ccb_p cp
)
9301 int num_disc
= (cp
->phys
.num_disc
& 0xff);
9302 int num_disc0
= (cp
->phys
.num_disc
>> 8);
9304 ++np
->profile
.num_trans
;
9305 np
->profile
.num_disc
+= num_disc
;
9306 np
->profile
.num_disc0
+= num_disc0
;
9307 np
->profile
.num_kbytes
+= (cp
->data_len
>> 10);
9309 if (num_disc
> num_disc0
) {
9310 if (cp
->data_len
<= 1024)
9311 np
->profile
.num_br1k
+= (num_disc
- num_disc0
);
9312 else if (cp
->data_len
<= 2048)
9313 np
->profile
.num_br2k
+= (num_disc
- num_disc0
);
9314 else if (cp
->data_len
<= 4096)
9315 np
->profile
.num_br4k
+= (num_disc
- num_disc0
);
9316 else if (cp
->data_len
<= 8192)
9317 np
->profile
.num_br8k
+= (num_disc
- num_disc0
);
9319 np
->profile
.num_brnk
+= (num_disc
- num_disc0
);
9324 #endif /* SCSI_NCR_PROFILE_SUPPORT */
9326 /*==========================================================
9331 ** @GENSCSI@ should be integrated to scsiconf.c
9334 **==========================================================
9337 struct table_entry
{
9338 char * manufacturer
;
9344 static struct table_entry device_tab
[] =
9347 {"", "", "", QUIRK_NOMSG
},
9349 {"SONY", "SDT-5000", "3.17", QUIRK_NOMSG
},
9350 {"WangDAT", "Model 2600", "01.7", QUIRK_NOMSG
},
9351 {"WangDAT", "Model 3200", "02.2", QUIRK_NOMSG
},
9352 {"WangDAT", "Model 1300", "02.4", QUIRK_NOMSG
},
9353 {"", "", "", 0} /* catch all: must be last entry. */
9356 static u_long
ncr_lookup(char * id
)
9358 struct table_entry
* p
= device_tab
;
9364 r
= p
->manufacturer
;
9365 while ((c
=*r
++)) if (c
!=*d
++) break;
9370 while ((c
=*r
++)) if (c
!=*d
++) break;
9375 while ((c
=*r
++)) if (c
!=*d
++) break;
9382 /*==========================================================
9384 ** Determine the ncr's clock frequency.
9385 ** This is essential for the negotiation
9386 ** of the synchronous transfer rate.
9388 **==========================================================
9390 ** Note: we have to return the correct value.
9391 ** THERE IS NO SAFE DEFAULT VALUE.
9393 ** Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
9394 ** 53C860 and 53C875 rev. 1 support fast20 transfers but
9395 ** do not have a clock doubler and so are provided with a
9396 ** 80 MHz clock. All other fast20 boards incorporate a doubler
9397 ** and so should be delivered with a 40 MHz clock.
9398 ** The recent fast40 chips (895/896) use a 40 Mhz base clock
9399 ** and provide a clock quadrupler (160 Mhz). The code below
9400 ** tries to deal as cleverly as possible with all this stuff.
9402 **----------------------------------------------------------
9406 * Select NCR SCSI clock frequency
9408 static void ncr_selectclock(ncb_p np
, u_char scntl3
)
9410 if (np
->multiplier
< 2) {
9411 OUTB(nc_scntl3
, scntl3
);
9415 if (bootverbose
>= 2)
9416 printk ("%s: enabling clock multiplier\n", ncr_name(np
));
9418 OUTB(nc_stest1
, DBLEN
); /* Enable clock multiplier */
9419 if (np
->multiplier
> 2) { /* Poll bit 5 of stest4 for quadrupler */
9421 while (!(INB(nc_stest4
) & LCKFRQ
) && --i
> 0)
9424 printk("%s: the chip cannot lock the frequency\n", ncr_name(np
));
9425 } else /* Wait 20 micro-seconds for doubler */
9427 OUTB(nc_stest3
, HSC
); /* Halt the scsi clock */
9428 OUTB(nc_scntl3
, scntl3
);
9429 OUTB(nc_stest1
, (DBLEN
|DBLSEL
));/* Select clock multiplier */
9430 OUTB(nc_stest3
, 0x00); /* Restart scsi clock */
9435 * calculate NCR SCSI clock frequency (in KHz)
9437 static unsigned __init
ncrgetfreq (ncb_p np
, int gen
)
9442 * Measure GEN timer delay in order
9443 * to calculate SCSI clock frequency
9445 * This code will never execute too
9446 * many loop iterations (if DELAY is
9447 * reasonably correct). It could get
9448 * too low a delay (too high a freq.)
9449 * if the CPU is slow executing the
9450 * loop for some reason (an NMI, for
9451 * example). For this reason we will
9452 * if multiple measurements are to be
9453 * performed trust the higher delay
9454 * (lower frequency returned).
9456 OUTB (nc_stest1
, 0); /* make sure clock doubler is OFF */
9457 OUTW (nc_sien
, 0); /* mask all scsi interrupts */
9458 (void) INW (nc_sist
); /* clear pending scsi interrupt */
9459 OUTB (nc_dien
, 0); /* mask all dma interrupts */
9460 (void) INW (nc_sist
); /* another one, just to be sure :) */
9461 OUTB (nc_scntl3
, 4); /* set pre-scaler to divide by 3 */
9462 OUTB (nc_stime1
, 0); /* disable general purpose timer */
9463 OUTB (nc_stime1
, gen
); /* set to nominal delay of 1<<gen * 125us */
9464 while (!(INW(nc_sist
) & GEN
) && ms
++ < 100000)
9465 UDELAY (1000); /* count ms */
9466 OUTB (nc_stime1
, 0); /* disable general purpose timer */
9468 * set prescaler to divide by whatever 0 means
9469 * 0 ought to choose divide by 2, but appears
9470 * to set divide by 3.5 mode in my 53c810 ...
9472 OUTB (nc_scntl3
, 0);
9474 if (bootverbose
>= 2)
9475 printk ("%s: Delay (GEN=%d): %u msec\n", ncr_name(np
), gen
, ms
);
9477 * adjust for prescaler, and convert into KHz
9479 return ms
? ((1 << gen
) * 4340) / ms
: 0;
9483 * Get/probe NCR SCSI clock frequency
9485 static void __init
ncr_getclock (ncb_p np
, int mult
)
9487 unsigned char scntl3
= INB(nc_scntl3
);
9488 unsigned char stest1
= INB(nc_stest1
);
9495 ** True with 875/895/896 with clock multiplier selected
9497 if (mult
> 1 && (stest1
& (DBLEN
+DBLSEL
)) == DBLEN
+DBLSEL
) {
9498 if (bootverbose
>= 2)
9499 printk ("%s: clock multiplier found\n", ncr_name(np
));
9500 np
->multiplier
= mult
;
9504 ** If multiplier not found or scntl3 not 7,5,3,
9505 ** reset chip and get frequency from general purpose timer.
9506 ** Otherwise trust scntl3 BIOS setting.
9508 if (np
->multiplier
!= mult
|| (scntl3
& 7) < 3 || !(scntl3
& 1)) {
9511 (void) ncrgetfreq (np
, 11); /* throw away first result */
9512 f1
= ncrgetfreq (np
, 11);
9513 f2
= ncrgetfreq (np
, 11);
9516 printk ("%s: NCR clock is %uKHz, %uKHz\n", ncr_name(np
), f1
, f2
);
9518 if (f1
> f2
) f1
= f2
; /* trust lower result */
9520 if (f1
< 45000) f1
= 40000;
9521 else if (f1
< 55000) f1
= 50000;
9524 if (f1
< 80000 && mult
> 1) {
9525 if (bootverbose
>= 2)
9526 printk ("%s: clock multiplier assumed\n", ncr_name(np
));
9527 np
->multiplier
= mult
;
9530 if ((scntl3
& 7) == 3) f1
= 40000;
9531 else if ((scntl3
& 7) == 5) f1
= 80000;
9534 f1
/= np
->multiplier
;
9538 ** Compute controller synchronous parameters.
9540 f1
*= np
->multiplier
;
9544 /*===================== LINUX ENTRY POINTS SECTION ==========================*/
9547 #define uchar unsigned char
9551 #define ushort unsigned short
9555 #define ulong unsigned long
9558 /* ---------------------------------------------------------------------
9560 ** Driver setup from the boot command line
9562 ** ---------------------------------------------------------------------
9572 #define OPT_MASTER_PARITY 2
9573 #define OPT_SCSI_PARITY 3
9574 #define OPT_DISCONNECTION 4
9575 #define OPT_SPECIAL_FEATURES 5
9576 #define OPT_ULTRA_SCSI 6
9577 #define OPT_FORCE_SYNC_NEGO 7
9578 #define OPT_REVERSE_PROBE 8
9579 #define OPT_DEFAULT_SYNC 9
9580 #define OPT_VERBOSE 10
9581 #define OPT_DEBUG 11
9582 #define OPT_BURST_MAX 12
9583 #define OPT_LED_PIN 13
9584 #define OPT_MAX_WIDE 14
9585 #define OPT_SETTLE_DELAY 15
9586 #define OPT_DIFF_SUPPORT 16
9588 #define OPT_PCI_FIX_UP 18
9589 #define OPT_BUS_CHECK 19
9590 #define OPT_OPTIMIZE 20
9591 #define OPT_RECOVERY 21
9592 #define OPT_SAFE_SETUP 22
9593 #define OPT_USE_NVRAM 23
9594 #define OPT_EXCLUDE 24
9596 static char setup_token
[] __initdata
=
9617 static int __init
get_setup_token(char *p
)
9619 char *cur
= setup_token
;
9623 while (cur
!= NULL
&& (pc
= strchr(cur
, ':')) != NULL
) {
9626 if (!strncmp(p
, cur
, pc
- cur
))
9634 void __init
sym53c8xx_setup(char *str
, int *ints
)
9636 #ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
9642 while (cur
!= NULL
&& (pc
= strchr(cur
, ':')) != NULL
) {
9654 val
= (int) simple_strtoul(pv
, &pe
, 0);
9656 switch (get_setup_token(cur
)) {
9658 driver_setup
.default_tags
= val
;
9659 if (pe
&& *pe
== '/') {
9661 while (*pe
&& *pe
!= ARG_SEP
&&
9662 i
< sizeof(driver_setup
.tag_ctrl
)-1) {
9663 driver_setup
.tag_ctrl
[i
++] = *pe
++;
9665 driver_setup
.tag_ctrl
[i
] = '\0';
9668 case OPT_MASTER_PARITY
:
9669 driver_setup
.master_parity
= val
;
9671 case OPT_SCSI_PARITY
:
9672 driver_setup
.scsi_parity
= val
;
9674 case OPT_DISCONNECTION
:
9675 driver_setup
.disconnection
= val
;
9677 case OPT_SPECIAL_FEATURES
:
9678 driver_setup
.special_features
= val
;
9680 case OPT_ULTRA_SCSI
:
9681 driver_setup
.ultra_scsi
= val
;
9683 case OPT_FORCE_SYNC_NEGO
:
9684 driver_setup
.force_sync_nego
= val
;
9686 case OPT_REVERSE_PROBE
:
9687 driver_setup
.reverse_probe
= val
;
9689 case OPT_DEFAULT_SYNC
:
9690 driver_setup
.default_sync
= val
;
9693 driver_setup
.verbose
= val
;
9696 driver_setup
.debug
= val
;
9699 driver_setup
.burst_max
= val
;
9702 driver_setup
.led_pin
= val
;
9705 driver_setup
.max_wide
= val
? 1:0;
9707 case OPT_SETTLE_DELAY
:
9708 driver_setup
.settle_delay
= val
;
9710 case OPT_DIFF_SUPPORT
:
9711 driver_setup
.diff_support
= val
;
9714 driver_setup
.irqm
= val
;
9716 case OPT_PCI_FIX_UP
:
9717 driver_setup
.pci_fix_up
= val
;
9720 driver_setup
.bus_check
= val
;
9723 driver_setup
.optimize
= val
;
9726 driver_setup
.recovery
= val
;
9729 driver_setup
.use_nvram
= val
;
9731 case OPT_SAFE_SETUP
:
9732 memcpy(&driver_setup
, &driver_safe_setup
,
9733 sizeof(driver_setup
));
9736 if (xi
< SCSI_NCR_MAX_EXCLUDES
)
9737 driver_setup
.excludes
[xi
++] = val
;
9740 printk("sym53c8xx_setup: unexpected boot option '%.*s' ignored\n", (int)(pc
-cur
+1), cur
);
9744 if ((cur
= strchr(cur
, ARG_SEP
)) != NULL
)
9747 #endif /* SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT */
9750 static int sym53c8xx_pci_init(Scsi_Host_Template
*tpnt
,
9751 uchar bus
, uchar device_fn
, ncr_device
*device
);
9754 ** Linux entry point for SYM53C8XX devices detection routine.
9756 ** Called by the middle-level scsi drivers at initialization time,
9757 ** or at module installation.
9759 ** Read the PCI configuration and try to attach each
9760 ** detected NCR board.
9762 ** If NVRAM is present, try to attach boards according to
9763 ** the used defined boot order.
9765 ** Returns the number of boards successfully attached.
9768 static void __init
ncr_print_driver_setup(void)
9770 #define YesNo(y) y ? 'y' : 'n'
9771 printk (NAME53C8XX
": setup=disc:%c,specf:%d,ultra:%d,tags:%d,sync:%d,"
9772 "burst:%d,wide:%c,diff:%d,revprob:%c,buschk:0x%x\n",
9773 YesNo(driver_setup
.disconnection
),
9774 driver_setup
.special_features
,
9775 driver_setup
.ultra_scsi
,
9776 driver_setup
.default_tags
,
9777 driver_setup
.default_sync
,
9778 driver_setup
.burst_max
,
9779 YesNo(driver_setup
.max_wide
),
9780 driver_setup
.diff_support
,
9781 YesNo(driver_setup
.reverse_probe
),
9782 driver_setup
.bus_check
);
9784 printk (NAME53C8XX
": setup=mpar:%c,spar:%c,fsn=%c,verb:%d,debug:0x%x,"
9785 "led:%c,settle:%d,irqm:0x%x,nvram:0x%x,pcifix:0x%x\n",
9786 YesNo(driver_setup
.master_parity
),
9787 YesNo(driver_setup
.scsi_parity
),
9788 YesNo(driver_setup
.force_sync_nego
),
9789 driver_setup
.verbose
,
9791 YesNo(driver_setup
.led_pin
),
9792 driver_setup
.settle_delay
,
9794 driver_setup
.use_nvram
,
9795 driver_setup
.pci_fix_up
);
9799 /*===================================================================
9800 ** SYM53C8XX devices description table and chip ids list.
9801 **===================================================================
9804 static ncr_chip ncr_chip_table
[] __initdata
= SCSI_NCR_CHIP_TABLE
;
9805 static ushort ncr_chip_ids
[] __initdata
= SCSI_NCR_CHIP_IDS
;
9807 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
9808 /*===================================================================
9809 ** Detect all NCR PQS/PDS boards and keep track of their bus nr.
9811 ** The NCR PQS or PDS card is constructed as a DEC bridge
9812 ** behind which sit a proprietary NCR memory controller and
9813 ** four or two 53c875s as separate devices. In its usual mode
9814 ** of operation, the 875s are slaved to the memory controller
9815 ** for all transfers. We can tell if an 875 is part of a
9816 ** PQS/PDS or not since if it is, it will be on the same bus
9817 ** as the memory controller. To operate with the Linux
9818 ** driver, the memory controller is disabled and the 875s
9819 ** freed to function independently. The only wrinkle is that
9820 ** the preset SCSI ID (which may be zero) must be read in from
9821 ** a special configuration space register of the 875
9822 **===================================================================
9824 #define SCSI_NCR_MAX_PQS_BUS 16
9825 static int pqs_bus
[SCSI_NCR_MAX_PQS_BUS
] __initdata
= { 0 };
9827 static void __init
ncr_detect_pqs_pds(void)
9831 for(index
=0; index
< SCSI_NCR_MAX_PQS_BUS
; index
++) {
9832 u_char tmp
, bus
, device_fn
;
9834 if (pcibios_find_device(0x101a, 0x0009, index
, &bus
,
9835 &device_fn
) != PCIBIOS_SUCCESSFUL
) {
9836 pqs_bus
[index
] = -1;
9839 printk(KERN_INFO NAME53C8XX
": NCR PQS/PDS memory controller detected on bus %d\n", bus
);
9840 pcibios_read_config_byte(bus
, device_fn
, 0x44, &tmp
);
9841 /* bit 1: allow individual 875 configuration */
9843 pcibios_write_config_byte(bus
, device_fn
, 0x44, tmp
);
9844 pcibios_read_config_byte(bus
, device_fn
, 0x45, &tmp
);
9845 /* bit 2: drive individual 875 interrupts to the bus */
9847 pcibios_write_config_byte(bus
, device_fn
, 0x45, tmp
);
9849 pqs_bus
[index
] = bus
;
9852 #endif /* SCSI_NCR_PQS_PDS_SUPPORT */
9854 /*===================================================================
9855 ** Detect all 53c8xx hosts and then attach them.
9857 ** If we are using NVRAM, once all hosts are detected, we need to
9858 ** check any NVRAM for boot order in case detect and boot order
9859 ** differ and attach them using the order in the NVRAM.
9861 ** If no NVRAM is found or data appears invalid attach boards in
9862 ** the the order they are detected.
9863 **===================================================================
9865 int __init
sym53c8xx_detect(Scsi_Host_Template
*tpnt
)
9867 int i
, j
, chips
, hosts
, count
;
9868 u_char bus
, device_fn
;
9870 int attach_count
= 0;
9871 ncr_device
*devtbl
, *devp
;
9872 #ifdef SCSI_NCR_NVRAM_SUPPORT
9873 ncr_nvram nvram0
, nvram
, *nvp
;
9879 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,92)
9882 if (!pcibios_present())
9887 ** Initialize driver general stuff.
9889 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
9890 tpnt
->proc_dir
= &proc_scsi_sym53c8xx
;
9891 tpnt
->proc_info
= sym53c8xx_proc_info
;
9894 #if defined(SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT) && defined(MODULE)
9896 sym53c8xx_setup(sym53c8xx
, (int *) 0);
9898 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
9899 ncr_debug
= driver_setup
.debug
;
9902 if (initverbose
>= 2)
9903 ncr_print_driver_setup();
9906 ** Allocate the device table since we donnot want to
9907 ** overflow the kernel stack.
9908 ** 1 x 4K PAGE is enough for more than 40 devices for i386.
9910 devtbl
= m_calloc(PAGE_SIZE
, "devtbl", MEMO_WARN
);
9915 ** Detect all NCR PQS/PDS memory controllers.
9917 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
9918 ncr_detect_pqs_pds();
9922 ** Detect all 53c8xx hosts.
9923 ** Save the first Symbios NVRAM content if any
9924 ** for the boot order.
9926 chips
= sizeof(ncr_chip_ids
) / sizeof(ncr_chip_ids
[0]);
9927 hosts
= PAGE_SIZE
/ sizeof(*devtbl
);
9928 #ifdef SCSI_NCR_NVRAM_SUPPORT
9929 nvp
= (driver_setup
.use_nvram
& 0x1) ? &nvram0
: 0;
9940 i
= driver_setup
.reverse_probe
? chips
- 1 - j
: j
;
9941 if (pcibios_find_device(PCI_VENDOR_ID_NCR
, ncr_chip_ids
[i
],
9942 index
, &bus
, &device_fn
)) {
9948 devp
= &devtbl
[count
];
9949 devp
->host_id
= 255;
9950 devp
->attach_done
= 0;
9951 if (sym53c8xx_pci_init(tpnt
, bus
, device_fn
, devp
)) {
9955 #ifdef SCSI_NCR_NVRAM_SUPPORT
9957 ncr_get_nvram(devp
, nvp
);
9959 case SCSI_NCR_SYMBIOS_NVRAM
:
9961 * Switch to the other nvram buffer, so that
9962 * nvram0 will contain the first Symbios
9963 * format NVRAM content with boot order.
9966 msg
= "with Symbios NVRAM";
9968 case SCSI_NCR_TEKRAM_NVRAM
:
9969 msg
= "with Tekram NVRAM";
9974 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
9976 msg
= "(NCR PQS/PDS)";
9978 printk(KERN_INFO NAME53C8XX
": 53c%s detected %s\n",
9979 devp
->chip
.name
, msg
);
9983 ** If we have found a SYMBIOS NVRAM, use first the NVRAM boot
9984 ** sequence as device boot order.
9985 ** check devices in the boot record against devices detected.
9986 ** attach devices if we find a match. boot table records that
9987 ** do not match any detected devices will be ignored.
9988 ** devices that do not match any boot table will not be attached
9989 ** here but will attempt to be attached during the device table
9992 #ifdef SCSI_NCR_NVRAM_SUPPORT
9993 if (!nvp
|| nvram0
.type
!= SCSI_NCR_SYMBIOS_NVRAM
)
9995 for (i
= 0; i
< 4; i
++) {
9996 Symbios_host
*h
= &nvram0
.data
.Symbios
.host
[i
];
9997 for (j
= 0 ; j
< count
; j
++) {
9999 if (h
->device_fn
!= devp
->slot
.device_fn
||
10000 h
->bus_nr
!= devp
->slot
.bus
||
10001 h
->device_id
!= devp
->chip
.device_id
)
10003 if (devp
->attach_done
)
10005 if (h
->flags
& SYMBIOS_INIT_SCAN_AT_BOOT
) {
10006 ncr_get_nvram(devp
, nvp
);
10007 if (!ncr_attach (tpnt
, attach_count
, devp
))
10010 else if (!(driver_setup
.use_nvram
& 0x80))
10011 printk(KERN_INFO NAME53C8XX
10012 ": 53c%s state OFF thus not attached\n",
10017 devp
->attach_done
= 1;
10025 ** Rescan device list to make sure all boards attached.
10026 ** Devices without boot records will not be attached yet
10027 ** so try to attach them here.
10029 for (i
= 0; i
< count
; i
++) {
10031 if (!devp
->attach_done
) {
10032 #ifdef SCSI_NCR_NVRAM_SUPPORT
10033 ncr_get_nvram(devp
, nvp
);
10035 if (!ncr_attach (tpnt
, attach_count
, devp
))
10040 m_free(devtbl
, PAGE_SIZE
, "devtbl");
10042 return attach_count
;
10045 /*===================================================================
10046 ** Generically read a base address from the PCI configuration space.
10047 ** Return the offset immediately after the base address that has
10048 ** been read. Btw, we blindly assume that the high 32 bits of 64 bit
10049 ** base addresses are set to zero on 32 bit architectures.
10050 **===================================================================
10052 #if LINUX_VERSION_CODE <= LinuxVersionCode(2,1,92)
10054 pci_read_base_address(u_char bus
, u_char device_fn
, int offset
, u_long
*base
)
10058 pcibios_read_config_dword(bus
, device_fn
, offset
, &tmp
);
10060 offset
+= sizeof(u_int32
);
10061 if ((tmp
& 0x7) == 0x4) {
10062 #if BITS_PER_LONG > 32
10063 pcibios_read_config_dword(bus
, device_fn
, offset
, &tmp
);
10064 *base
|= (((u_long
)tmp
) << 32);
10066 offset
+= sizeof(u_int32
);
10070 #else /* LINUX_VERSION_CODE > LinuxVersionCode(2,1,92) */
10072 pci_get_base_address(struct pci_dev
*pdev
, int index
, u_long
*base
)
10074 /* FIXME! This is just unbelieably horrible backwards compatibility code */
10075 struct resource
*res
= pdev
->resource
+ index
;
10077 *base
= res
->start
| (res
->flags
& 0xf);
10078 if ((res
->flags
& 0x7) == 0x4) {
10085 /*===================================================================
10086 ** Read and check the PCI configuration for any detected NCR
10087 ** boards and save data for attaching after all boards have
10089 **===================================================================
10091 static int __init
sym53c8xx_pci_init(Scsi_Host_Template
*tpnt
,
10092 uchar bus
, uchar device_fn
, ncr_device
*device
)
10094 u_short vendor_id
, device_id
, command
;
10095 u_char cache_line_size
, latency_timer
;
10096 u_char suggested_cache_line_size
= 0;
10098 #if LINUX_VERSION_CODE > LinuxVersionCode(2,1,92)
10099 struct pci_dev
*pdev
;
10104 u_long base
, base_2
, io_port
;
10108 printk(KERN_INFO NAME53C8XX
": at PCI bus %d, device %d, function %d\n",
10109 bus
, (int) (device_fn
& 0xf8) >> 3, (int) device_fn
& 7);
10111 ** Read info from the PCI config space.
10112 ** pcibios_read_config_xxx() functions are assumed to be used for
10113 ** successfully detected PCI devices.
10115 #if LINUX_VERSION_CODE > LinuxVersionCode(2,1,92)
10116 pdev
= pci_find_slot(bus
, device_fn
);
10117 vendor_id
= pdev
->vendor
;
10118 device_id
= pdev
->device
;
10121 i
= pci_get_base_address(pdev
, i
, &io_port
);
10122 i
= pci_get_base_address(pdev
, i
, &base
);
10123 (void) pci_get_base_address(pdev
, i
, &base_2
);
10125 pcibios_read_config_word(bus
, device_fn
, PCI_VENDOR_ID
, &vendor_id
);
10126 pcibios_read_config_word(bus
, device_fn
, PCI_DEVICE_ID
, &device_id
);
10127 pcibios_read_config_byte(bus
, device_fn
, PCI_INTERRUPT_LINE
, &irq
);
10128 i
= PCI_BASE_ADDRESS_0
;
10129 i
= pci_read_base_address(bus
, device_fn
, i
, &io_port
);
10130 i
= pci_read_base_address(bus
, device_fn
, i
, &base
);
10131 (void) pci_read_base_address(bus
, device_fn
, i
, &base_2
);
10133 pcibios_read_config_word(bus
, device_fn
, PCI_COMMAND
, &command
);
10134 pcibios_read_config_byte(bus
, device_fn
, PCI_CLASS_REVISION
, &revision
);
10135 pcibios_read_config_byte(bus
, device_fn
, PCI_CACHE_LINE_SIZE
,
10137 pcibios_read_config_byte(bus
, device_fn
, PCI_LATENCY_TIMER
,
10140 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
10142 ** Match the BUS number for PQS/PDS devices.
10143 ** Read the SCSI ID from a special register mapped
10144 ** into the configuration space of the individual
10145 ** 875s. This register is set up by the PQS bios
10147 for(i
= 0; i
< SCSI_NCR_MAX_PQS_BUS
&& pqs_bus
[i
] != -1; i
++) {
10149 if (pqs_bus
[i
] == bus
) {
10150 pcibios_read_config_byte(bus
, device_fn
, 0x84, &tmp
);
10151 device
->pqs_pds
= 1;
10152 device
->host_id
= tmp
;
10156 #endif /* SCSI_NCR_PQS_PDS_SUPPORT */
10159 ** If user excludes this chip, donnot initialize it.
10161 for (i
= 0 ; i
< SCSI_NCR_MAX_EXCLUDES
; i
++) {
10162 if (driver_setup
.excludes
[i
] ==
10163 (io_port
& PCI_BASE_ADDRESS_IO_MASK
))
10167 ** Check if the chip is supported
10170 for (i
= 0; i
< sizeof(ncr_chip_table
)/sizeof(ncr_chip_table
[0]); i
++) {
10171 if (device_id
!= ncr_chip_table
[i
].device_id
)
10173 if (revision
> ncr_chip_table
[i
].revision_id
)
10175 if (!(ncr_chip_table
[i
].features
& FE_LDSTR
))
10177 chip
= &device
->chip
;
10178 memcpy(chip
, &ncr_chip_table
[i
], sizeof(*chip
));
10179 chip
->revision_id
= revision
;
10183 #if defined(__i386__)
10185 ** Ignore Symbios chips controlled by SISL RAID controller.
10186 ** This controller sets value 0x52414944 at RAM end - 16.
10188 if (chip
&& (base_2
& PCI_BASE_ADDRESS_MEM_MASK
)) {
10189 unsigned int ram_size
, ram_val
;
10192 if (chip
->features
& FE_RAM8K
)
10197 ram_ptr
= remap_pci_mem(base_2
& PCI_BASE_ADDRESS_MEM_MASK
,
10200 ram_val
= readl_raw(ram_ptr
+ ram_size
- 16);
10201 unmap_pci_mem(ram_ptr
, ram_size
);
10202 if (ram_val
== 0x52414944) {
10203 printk(NAME53C8XX
": not initializing, "
10204 "driven by SISL RAID controller.\n");
10212 printk(NAME53C8XX
": not initializing, device not supported\n");
10218 ** Fix-up for power/pc.
10219 ** Should not be performed by the driver.
10221 if ((command
& (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
))
10222 != (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
)) {
10223 printk(NAME53C8XX
": setting%s%s...\n",
10224 (command
& PCI_COMMAND_IO
) ? "" : " PCI_COMMAND_IO",
10225 (command
& PCI_COMMAND_MEMORY
) ? "" : " PCI_COMMAND_MEMORY");
10226 command
|= (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
);
10227 pcibios_write_config_word(bus
, device_fn
, PCI_COMMAND
, command
);
10230 #if LINUX_VERSION_CODE < LinuxVersionCode(2,2,0)
10232 if (io_port
>= 0x10000000) {
10233 printk(NAME53C8XX
": reallocating io_port (Wacky IBM)");
10234 io_port
= (io_port
& 0x00FFFFFF) | 0x01000000;
10235 pcibios_write_config_dword(bus
, device_fn
,
10236 PCI_BASE_ADDRESS_0
, io_port
);
10238 if (base
>= 0x10000000) {
10239 printk(NAME53C8XX
": reallocating base (Wacky IBM)");
10240 base
= (base
& 0x00FFFFFF) | 0x01000000;
10241 pcibios_write_config_dword(bus
, device_fn
,
10242 PCI_BASE_ADDRESS_1
, base
);
10244 if (base_2
>= 0x10000000) {
10245 printk(NAME53C8XX
": reallocating base2 (Wacky IBM)");
10246 base_2
= (base_2
& 0x00FFFFFF) | 0x01000000;
10247 pcibios_write_config_dword(bus
, device_fn
,
10248 PCI_BASE_ADDRESS_2
, base_2
);
10252 #endif /* __powerpc__ */
10256 ** Fix-ups for sparc.
10258 ** I wrote: Should not be performed by the driver,
10259 ** Guy wrote: but how can OBP know each and every PCI card,
10260 ** if they don't use Fcode?
10261 ** I replied: no need to know each and every PCI card, just
10262 ** be skilled enough to understand the PCI specs.
10266 ** PCI configuration is based on configuration registers being
10267 ** coherent with hardware and software resource identifications.
10268 ** This is fairly simple, but seems still too complex for Sparc.
10270 if (!cache_line_size
)
10271 suggested_cache_line_size
= 16;
10273 #endif /* __sparc__ */
10275 #if defined(__i386__) && !defined(MODULE)
10276 if (!cache_line_size
) {
10277 #if LINUX_VERSION_CODE < LinuxVersionCode(2,1,75)
10281 switch(boot_cpu_data
.x86
) {
10283 case 4: suggested_cache_line_size
= 4; break;
10285 case 5: suggested_cache_line_size
= 8; break;
10288 #endif /* __i386__ */
10291 ** Check availability of IO space, memory space.
10292 ** Enable master capability if not yet.
10294 #ifdef NCR_IOMAPPED
10295 if (!(command
& PCI_COMMAND_IO
) || !(io_port
& 1)) {
10296 printk(NAME53C8XX
": I/O base address (0x%lx) disabled.\n",
10301 if (!(command
& PCI_COMMAND_MEMORY
)) {
10302 printk(NAME53C8XX
": PCI_COMMAND_MEMORY not set.\n");
10306 io_port
&= PCI_BASE_ADDRESS_IO_MASK
;
10307 base
&= PCI_BASE_ADDRESS_MEM_MASK
;
10308 base_2
&= PCI_BASE_ADDRESS_MEM_MASK
;
10310 #ifdef NCR_IOMAPPED
10311 if (io_port
&& check_region (io_port
, 128)) {
10312 printk(NAME53C8XX
": IO region 0x%lx[0..127] is in use\n",
10320 printk(NAME53C8XX
": MMIO base address disabled.\n");
10326 ** Set MASTER capable and PARITY bit, if not yet.
10328 if ((command
& (PCI_COMMAND_MASTER
| PCI_COMMAND_PARITY
))
10329 != (PCI_COMMAND_MASTER
| PCI_COMMAND_PARITY
)) {
10330 printk(NAME53C8XX
": setting%s%s...(fix-up)\n",
10331 (command
& PCI_COMMAND_MASTER
) ? "" : " PCI_COMMAND_MASTER",
10332 (command
& PCI_COMMAND_PARITY
) ? "" : " PCI_COMMAND_PARITY");
10333 command
|= (PCI_COMMAND_MASTER
| PCI_COMMAND_PARITY
);
10334 pcibios_write_config_word(bus
, device_fn
, PCI_COMMAND
, command
);
10338 ** Fix some features according to driver setup.
10340 if (!(driver_setup
.special_features
& 1))
10341 chip
->features
&= ~FE_SPECIAL_SET
;
10343 if (driver_setup
.special_features
& 2)
10344 chip
->features
&= ~FE_WRIE
;
10345 if (driver_setup
.special_features
& 4)
10346 chip
->features
&= ~FE_NOPM
;
10348 if (driver_setup
.ultra_scsi
< 2 && (chip
->features
& FE_ULTRA2
)) {
10349 chip
->features
|= FE_ULTRA
;
10350 chip
->features
&= ~FE_ULTRA2
;
10352 if (driver_setup
.ultra_scsi
< 1)
10353 chip
->features
&= ~FE_ULTRA
;
10354 if (!driver_setup
.max_wide
)
10355 chip
->features
&= ~FE_WIDE
;
10357 #ifdef SCSI_NCR_PCI_FIX_UP_SUPPORT
10359 ** Try to fix up PCI config according to wished features.
10361 if ((driver_setup
.pci_fix_up
& 1) && (chip
->features
& FE_CLSE
) &&
10362 !cache_line_size
&& suggested_cache_line_size
) {
10363 cache_line_size
= suggested_cache_line_size
;
10364 pcibios_write_config_byte(bus
, device_fn
,
10365 PCI_CACHE_LINE_SIZE
, cache_line_size
);
10366 printk(NAME53C8XX
": PCI_CACHE_LINE_SIZE set to %d (fix-up).\n",
10370 if ((driver_setup
.pci_fix_up
& 2) && cache_line_size
&&
10371 (chip
->features
& FE_WRIE
) && !(command
& PCI_COMMAND_INVALIDATE
)) {
10372 printk(NAME53C8XX
": setting PCI_COMMAND_INVALIDATE (fix-up)\n");
10373 command
|= PCI_COMMAND_INVALIDATE
;
10374 pcibios_write_config_word(bus
, device_fn
, PCI_COMMAND
, command
);
10378 ** Tune PCI LATENCY TIMER according to burst max length transfer.
10379 ** (latency timer >= burst length + 6, we add 10 to be quite sure)
10382 if ((driver_setup
.pci_fix_up
& 4) && chip
->burst_max
) {
10383 uchar lt
= (1 << chip
->burst_max
) + 6 + 10;
10384 if (latency_timer
< lt
) {
10385 latency_timer
= lt
;
10387 ": setting PCI_LATENCY_TIMER to %d (fix-up).\n",
10389 pcibios_write_config_byte(bus
, device_fn
,
10390 PCI_LATENCY_TIMER
, latency_timer
);
10394 #endif /* SCSI_NCR_PCI_FIX_UP_SUPPORT */
10397 ** Initialise ncr_device structure with items required by ncr_attach.
10399 device
->slot
.bus
= bus
;
10400 device
->slot
.device_fn
= device_fn
;
10401 device
->slot
.base
= base
;
10402 device
->slot
.base_2
= base_2
;
10403 device
->slot
.io_port
= io_port
;
10404 device
->slot
.irq
= irq
;
10405 device
->attach_done
= 0;
10411 /*===================================================================
10412 ** Detect and try to read SYMBIOS and TEKRAM NVRAM.
10414 ** Data can be used to order booting of boards.
10416 ** Data is saved in ncr_device structure if NVRAM found. This
10417 ** is then used to find drive boot order for ncr_attach().
10419 ** NVRAM data is passed to Scsi_Host_Template later during
10420 ** ncr_attach() for any device set up.
10421 *===================================================================
10423 #ifdef SCSI_NCR_NVRAM_SUPPORT
10424 static void __init
ncr_get_nvram(ncr_device
*devp
, ncr_nvram
*nvp
)
10430 ** Get access to chip IO registers
10432 #ifdef NCR_IOMAPPED
10433 request_region(devp
->slot
.io_port
, 128, NAME53C8XX
);
10434 devp
->slot
.base_io
= devp
->slot
.io_port
;
10436 devp
->slot
.reg
= (struct ncr_reg
*) remap_pci_mem(devp
->slot
.base
, 128);
10437 if (!devp
->slot
.reg
)
10442 ** Try to read SYMBIOS nvram.
10443 ** Try to read TEKRAM nvram if Symbios nvram not found.
10445 if (!ncr_get_Symbios_nvram(&devp
->slot
, &nvp
->data
.Symbios
))
10446 nvp
->type
= SCSI_NCR_SYMBIOS_NVRAM
;
10447 else if (!ncr_get_Tekram_nvram(&devp
->slot
, &nvp
->data
.Tekram
))
10448 nvp
->type
= SCSI_NCR_TEKRAM_NVRAM
;
10455 ** Release access to chip IO registers
10457 #ifdef NCR_IOMAPPED
10458 release_region(devp
->slot
.base_io
, 128);
10460 unmap_pci_mem((u_long
) devp
->slot
.reg
, 128ul);
10464 #endif /* SCSI_NCR_NVRAM_SUPPORT */
10467 ** Linux select queue depths function
10470 #define DEF_DEPTH (driver_setup.default_tags)
10471 #define ALL_TARGETS -2
10472 #define NO_TARGET -1
10473 #define ALL_LUNS -2
10476 static int device_queue_depth(ncb_p np
, int target
, int lun
)
10479 char *p
= driver_setup
.tag_ctrl
;
10485 while ((c
= *p
++) != 0) {
10486 v
= simple_strtoul(p
, &ep
, 0);
10495 t
= (target
== v
) ? v
: NO_TARGET
;
10500 u
= (lun
== v
) ? v
: NO_LUN
;
10503 if (h
== np
->unit
&&
10504 (t
== ALL_TARGETS
|| t
== target
) &&
10505 (u
== ALL_LUNS
|| u
== lun
))
10520 static void sym53c8xx_select_queue_depths(struct Scsi_Host
*host
, struct scsi_device
*devlist
)
10522 struct scsi_device
*device
;
10524 for (device
= devlist
; device
; device
= device
->next
) {
10530 if (device
->host
!= host
)
10533 np
= ((struct host_data
*) host
->hostdata
)->ncb
;
10534 tp
= &np
->target
[device
->id
];
10535 lp
= tp
->lp
[device
->lun
];
10538 ** Select queue depth from driver setup.
10539 ** Donnot use more than configured by user.
10541 ** Donnot use more than our maximum.
10543 numtags
= device_queue_depth(np
, device
->id
, device
->lun
);
10544 if (numtags
> tp
->usrtags
)
10545 numtags
= tp
->usrtags
;
10546 if (!device
->tagged_supported
)
10548 device
->queue_depth
= numtags
;
10549 if (device
->queue_depth
< 2)
10550 device
->queue_depth
= 2;
10551 if (device
->queue_depth
> SCSI_NCR_MAX_TAGS
)
10552 device
->queue_depth
= SCSI_NCR_MAX_TAGS
;
10555 ** Since the queue depth is not tunable under Linux,
10556 ** we need to know this value in order not to
10557 ** announce stupid things to user.
10560 lp
->numtags
= lp
->maxtags
= numtags
;
10561 lp
->scdev_depth
= device
->queue_depth
;
10563 ncr_setup_tags (np
, device
->id
, device
->lun
);
10565 #ifdef DEBUG_SYM53C8XX
10566 printk("sym53c8xx_select_queue_depth: host=%d, id=%d, lun=%d, depth=%d\n",
10567 np
->unit
, device
->id
, device
->lun
, device
->queue_depth
);
10573 ** Linux entry point for info() function
10575 const char *sym53c8xx_info (struct Scsi_Host
*host
)
10577 return SCSI_NCR_DRIVER_NAME
;
10581 ** Linux entry point of queuecommand() function
10584 int sym53c8xx_queue_command (Scsi_Cmnd
*cmd
, void (* done
)(Scsi_Cmnd
*))
10586 ncb_p np
= ((struct host_data
*) cmd
->host
->hostdata
)->ncb
;
10587 unsigned long flags
;
10590 #ifdef DEBUG_SYM53C8XX
10591 printk("sym53c8xx_queue_command\n");
10594 cmd
->scsi_done
= done
;
10595 cmd
->host_scribble
= NULL
;
10596 cmd
->SCp
.ptr
= NULL
;
10597 cmd
->SCp
.buffer
= NULL
;
10599 NCR_LOCK_NCB(np
, flags
);
10601 if ((sts
= ncr_queue_command(np
, cmd
)) != DID_OK
) {
10602 SetScsiResult(cmd
, sts
, 0);
10603 #ifdef DEBUG_SYM53C8XX
10604 printk("sym53c8xx : command not queued - result=%d\n", sts
);
10607 #ifdef DEBUG_SYM53C8XX
10609 printk("sym53c8xx : command successfully queued\n");
10612 NCR_UNLOCK_NCB(np
, flags
);
10621 ** Linux entry point of the interrupt handler.
10622 ** Since linux versions > 1.3.70, we trust the kernel for
10623 ** passing the internal host descriptor as 'dev_id'.
10624 ** Otherwise, we scan the host list and call the interrupt
10625 ** routine for each host that uses this IRQ.
10628 static void sym53c8xx_intr(int irq
, void *dev_id
, struct pt_regs
* regs
)
10630 unsigned long flags
;
10631 ncb_p np
= (ncb_p
) dev_id
;
10632 Scsi_Cmnd
*done_list
;
10634 #ifdef DEBUG_SYM53C8XX
10635 printk("sym53c8xx : interrupt received\n");
10638 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("[");
10640 NCR_LOCK_NCB(np
, flags
);
10642 done_list
= np
->done_list
;
10644 NCR_UNLOCK_NCB(np
, flags
);
10646 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("]\n");
10649 NCR_LOCK_SCSI_DONE(np
, flags
);
10650 ncr_flush_done_cmds(done_list
);
10651 NCR_UNLOCK_SCSI_DONE(np
, flags
);
10656 ** Linux entry point of the timer handler
10659 static void sym53c8xx_timeout(unsigned long npref
)
10661 ncb_p np
= (ncb_p
) npref
;
10662 unsigned long flags
;
10663 Scsi_Cmnd
*done_list
;
10665 NCR_LOCK_NCB(np
, flags
);
10666 ncr_timeout((ncb_p
) np
);
10667 done_list
= np
->done_list
;
10669 NCR_UNLOCK_NCB(np
, flags
);
10672 NCR_LOCK_SCSI_DONE(np
, flags
);
10673 ncr_flush_done_cmds(done_list
);
10674 NCR_UNLOCK_SCSI_DONE(np
, flags
);
10679 ** Linux entry point of reset() function
10682 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
10683 int sym53c8xx_reset(Scsi_Cmnd
*cmd
, unsigned int reset_flags
)
10685 int sym53c8xx_reset(Scsi_Cmnd
*cmd
)
10688 ncb_p np
= ((struct host_data
*) cmd
->host
->hostdata
)->ncb
;
10690 unsigned long flags
;
10691 Scsi_Cmnd
*done_list
;
10693 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
10694 printk("sym53c8xx_reset: pid=%lu reset_flags=%x serial_number=%ld serial_number_at_timeout=%ld\n",
10695 cmd
->pid
, reset_flags
, cmd
->serial_number
, cmd
->serial_number_at_timeout
);
10697 printk("sym53c8xx_reset: command pid %lu\n", cmd
->pid
);
10700 NCR_LOCK_NCB(np
, flags
);
10703 * We have to just ignore reset requests in some situations.
10705 #if defined SCSI_RESET_NOT_RUNNING
10706 if (cmd
->serial_number
!= cmd
->serial_number_at_timeout
) {
10707 sts
= SCSI_RESET_NOT_RUNNING
;
10712 * If the mid-level driver told us reset is synchronous, it seems
10713 * that we must call the done() callback for the involved command,
10714 * even if this command was not queued to the low-level driver,
10715 * before returning SCSI_RESET_SUCCESS.
10718 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
10719 sts
= ncr_reset_bus(np
, cmd
,
10720 (reset_flags
& (SCSI_RESET_SYNCHRONOUS
| SCSI_RESET_ASYNCHRONOUS
)) == SCSI_RESET_SYNCHRONOUS
);
10722 sts
= ncr_reset_bus(np
, cmd
, 0);
10726 * Since we always reset the controller, when we return success,
10727 * we add this information to the return code.
10729 #if defined SCSI_RESET_HOST_RESET
10730 if (sts
== SCSI_RESET_SUCCESS
)
10731 sts
|= SCSI_RESET_HOST_RESET
;
10735 done_list
= np
->done_list
;
10737 NCR_UNLOCK_NCB(np
, flags
);
10739 ncr_flush_done_cmds(done_list
);
10745 ** Linux entry point of abort() function
10748 int sym53c8xx_abort(Scsi_Cmnd
*cmd
)
10750 ncb_p np
= ((struct host_data
*) cmd
->host
->hostdata
)->ncb
;
10752 unsigned long flags
;
10753 Scsi_Cmnd
*done_list
;
10755 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
10756 printk("sym53c8xx_abort: pid=%lu serial_number=%ld serial_number_at_timeout=%ld\n",
10757 cmd
->pid
, cmd
->serial_number
, cmd
->serial_number_at_timeout
);
10759 printk("sym53c8xx_abort: command pid %lu\n", cmd
->pid
);
10762 NCR_LOCK_NCB(np
, flags
);
10764 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
10766 * We have to just ignore abort requests in some situations.
10768 if (cmd
->serial_number
!= cmd
->serial_number_at_timeout
) {
10769 sts
= SCSI_ABORT_NOT_RUNNING
;
10774 sts
= ncr_abort_command(np
, cmd
);
10776 done_list
= np
->done_list
;
10778 NCR_UNLOCK_NCB(np
, flags
);
10780 ncr_flush_done_cmds(done_list
);
10787 int sym53c8xx_release(struct Scsi_Host
*host
)
10789 #ifdef DEBUG_SYM53C8XX
10790 printk("sym53c8xx : release\n");
10792 ncr_detach(((struct host_data
*) host
->hostdata
)->ncb
);
10800 ** Scsi command waiting list management.
10802 ** It may happen that we cannot insert a scsi command into the start queue,
10803 ** in the following circumstances.
10804 ** Too few preallocated ccb(s),
10805 ** maxtags < cmd_per_lun of the Linux host control block,
10807 ** Such scsi commands are inserted into a waiting list.
10808 ** When a scsi command complete, we try to requeue the commands of the
10812 #define next_wcmd host_scribble
10814 static void insert_into_waiting_list(ncb_p np
, Scsi_Cmnd
*cmd
)
10818 #ifdef DEBUG_WAITING_LIST
10819 printk("%s: cmd %lx inserted into waiting list\n", ncr_name(np
), (u_long
) cmd
);
10821 cmd
->next_wcmd
= 0;
10822 if (!(wcmd
= np
->waiting_list
)) np
->waiting_list
= cmd
;
10824 while ((wcmd
->next_wcmd
) != 0)
10825 wcmd
= (Scsi_Cmnd
*) wcmd
->next_wcmd
;
10826 wcmd
->next_wcmd
= (char *) cmd
;
10830 static Scsi_Cmnd
*retrieve_from_waiting_list(int to_remove
, ncb_p np
, Scsi_Cmnd
*cmd
)
10832 Scsi_Cmnd
**pcmd
= &np
->waiting_list
;
10835 if (cmd
== *pcmd
) {
10837 *pcmd
= (Scsi_Cmnd
*) cmd
->next_wcmd
;
10838 cmd
->next_wcmd
= 0;
10840 #ifdef DEBUG_WAITING_LIST
10841 printk("%s: cmd %lx retrieved from waiting list\n", ncr_name(np
), (u_long
) cmd
);
10845 pcmd
= (Scsi_Cmnd
**) &(*pcmd
)->next_wcmd
;
10850 static void process_waiting_list(ncb_p np
, int sts
)
10852 Scsi_Cmnd
*waiting_list
, *wcmd
;
10854 waiting_list
= np
->waiting_list
;
10855 np
->waiting_list
= 0;
10857 #ifdef DEBUG_WAITING_LIST
10858 if (waiting_list
) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np
), (u_long
) waiting_list
, sts
);
10860 while ((wcmd
= waiting_list
) != 0) {
10861 waiting_list
= (Scsi_Cmnd
*) wcmd
->next_wcmd
;
10862 wcmd
->next_wcmd
= 0;
10863 if (sts
== DID_OK
) {
10864 #ifdef DEBUG_WAITING_LIST
10865 printk("%s: cmd %lx trying to requeue\n", ncr_name(np
), (u_long
) wcmd
);
10867 sts
= ncr_queue_command(np
, wcmd
);
10869 if (sts
!= DID_OK
) {
10870 #ifdef DEBUG_WAITING_LIST
10871 printk("%s: cmd %lx done forced sts=%d\n", ncr_name(np
), (u_long
) wcmd
, sts
);
10873 SetScsiResult(wcmd
, sts
, 0);
10874 ncr_queue_done_cmd(np
, wcmd
);
10881 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
10883 /*=========================================================================
10884 ** Proc file system stuff
10886 ** A read operation returns profile information.
10887 ** A write operation is a control command.
10888 ** The string is parsed in the driver code and the command is passed
10889 ** to the ncr_usercmd() function.
10890 **=========================================================================
10893 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
10895 #define is_digit(c) ((c) >= '0' && (c) <= '9')
10896 #define digit_to_bin(c) ((c) - '0')
10897 #define is_space(c) ((c) == ' ' || (c) == '\t')
10899 static int skip_spaces(char *ptr
, int len
)
10903 for (cnt
= len
; cnt
> 0 && (c
= *ptr
++) && is_space(c
); cnt
--);
10905 return (len
- cnt
);
10908 static int get_int_arg(char *ptr
, int len
, u_long
*pv
)
10913 for (v
= 0, cnt
= len
; cnt
> 0 && (c
= *ptr
++) && is_digit(c
); cnt
--) {
10914 v
= (v
* 10) + digit_to_bin(c
);
10920 return (len
- cnt
);
10923 static int is_keyword(char *ptr
, int len
, char *verb
)
10925 int verb_len
= strlen(verb
);
10927 if (len
>= strlen(verb
) && !memcmp(verb
, ptr
, verb_len
))
10934 #define SKIP_SPACES(min_spaces) \
10935 if ((arg_len = skip_spaces(ptr, len)) < (min_spaces)) \
10937 ptr += arg_len; len -= arg_len;
10939 #define GET_INT_ARG(v) \
10940 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
10942 ptr += arg_len; len -= arg_len;
10946 ** Parse a control command
10949 static int ncr_user_command(ncb_p np
, char *buffer
, int length
)
10951 char *ptr
= buffer
;
10953 struct usrcmd
*uc
= &np
->user
;
10957 bzero(uc
, sizeof(*uc
));
10959 if (len
> 0 && ptr
[len
-1] == '\n')
10962 if ((arg_len
= is_keyword(ptr
, len
, "setsync")) != 0)
10963 uc
->cmd
= UC_SETSYNC
;
10964 else if ((arg_len
= is_keyword(ptr
, len
, "settags")) != 0)
10965 uc
->cmd
= UC_SETTAGS
;
10966 else if ((arg_len
= is_keyword(ptr
, len
, "setorder")) != 0)
10967 uc
->cmd
= UC_SETORDER
;
10968 else if ((arg_len
= is_keyword(ptr
, len
, "setverbose")) != 0)
10969 uc
->cmd
= UC_SETVERBOSE
;
10970 else if ((arg_len
= is_keyword(ptr
, len
, "setwide")) != 0)
10971 uc
->cmd
= UC_SETWIDE
;
10972 else if ((arg_len
= is_keyword(ptr
, len
, "setdebug")) != 0)
10973 uc
->cmd
= UC_SETDEBUG
;
10974 else if ((arg_len
= is_keyword(ptr
, len
, "setflag")) != 0)
10975 uc
->cmd
= UC_SETFLAG
;
10976 else if ((arg_len
= is_keyword(ptr
, len
, "clearprof")) != 0)
10977 uc
->cmd
= UC_CLEARPROF
;
10981 #ifdef DEBUG_PROC_INFO
10982 printk("ncr_user_command: arg_len=%d, cmd=%ld\n", arg_len
, uc
->cmd
);
10987 ptr
+= arg_len
; len
-= arg_len
;
10995 if ((arg_len
= is_keyword(ptr
, len
, "all")) != 0) {
10996 ptr
+= arg_len
; len
-= arg_len
;
10999 GET_INT_ARG(target
);
11000 uc
->target
= (1<<target
);
11001 #ifdef DEBUG_PROC_INFO
11002 printk("ncr_user_command: target=%ld\n", target
);
11009 case UC_SETVERBOSE
:
11014 GET_INT_ARG(uc
->data
);
11015 #ifdef DEBUG_PROC_INFO
11016 printk("ncr_user_command: data=%ld\n", uc
->data
);
11021 if ((arg_len
= is_keyword(ptr
, len
, "simple")))
11022 uc
->data
= M_SIMPLE_TAG
;
11023 else if ((arg_len
= is_keyword(ptr
, len
, "ordered")))
11024 uc
->data
= M_ORDERED_TAG
;
11025 else if ((arg_len
= is_keyword(ptr
, len
, "default")))
11033 if ((arg_len
= is_keyword(ptr
, len
, "alloc")))
11034 uc
->data
|= DEBUG_ALLOC
;
11035 else if ((arg_len
= is_keyword(ptr
, len
, "phase")))
11036 uc
->data
|= DEBUG_PHASE
;
11037 else if ((arg_len
= is_keyword(ptr
, len
, "poll")))
11038 uc
->data
|= DEBUG_POLL
;
11039 else if ((arg_len
= is_keyword(ptr
, len
, "queue")))
11040 uc
->data
|= DEBUG_QUEUE
;
11041 else if ((arg_len
= is_keyword(ptr
, len
, "result")))
11042 uc
->data
|= DEBUG_RESULT
;
11043 else if ((arg_len
= is_keyword(ptr
, len
, "scatter")))
11044 uc
->data
|= DEBUG_SCATTER
;
11045 else if ((arg_len
= is_keyword(ptr
, len
, "script")))
11046 uc
->data
|= DEBUG_SCRIPT
;
11047 else if ((arg_len
= is_keyword(ptr
, len
, "tiny")))
11048 uc
->data
|= DEBUG_TINY
;
11049 else if ((arg_len
= is_keyword(ptr
, len
, "timing")))
11050 uc
->data
|= DEBUG_TIMING
;
11051 else if ((arg_len
= is_keyword(ptr
, len
, "nego")))
11052 uc
->data
|= DEBUG_NEGO
;
11053 else if ((arg_len
= is_keyword(ptr
, len
, "tags")))
11054 uc
->data
|= DEBUG_TAGS
;
11055 else if ((arg_len
= is_keyword(ptr
, len
, "freeze")))
11056 uc
->data
|= DEBUG_FREEZE
;
11057 else if ((arg_len
= is_keyword(ptr
, len
, "restart")))
11058 uc
->data
|= DEBUG_RESTART
;
11061 ptr
+= arg_len
; len
-= arg_len
;
11063 #ifdef DEBUG_PROC_INFO
11064 printk("ncr_user_command: data=%ld\n", uc
->data
);
11070 if ((arg_len
= is_keyword(ptr
, len
, "trace")))
11071 uc
->data
|= UF_TRACE
;
11072 else if ((arg_len
= is_keyword(ptr
, len
, "no_disc")))
11073 uc
->data
|= UF_NODISC
;
11076 ptr
+= arg_len
; len
-= arg_len
;
11088 NCR_LOCK_NCB(np
, flags
);
11090 NCR_UNLOCK_NCB(np
, flags
);
11095 #endif /* SCSI_NCR_USER_COMMAND_SUPPORT */
11097 #ifdef SCSI_NCR_USER_INFO_SUPPORT
11107 static void copy_mem_info(struct info_str
*info
, char *data
, int len
)
11109 if (info
->pos
+ len
> info
->length
)
11110 len
= info
->length
- info
->pos
;
11112 if (info
->pos
+ len
< info
->offset
) {
11116 if (info
->pos
< info
->offset
) {
11117 data
+= (info
->offset
- info
->pos
);
11118 len
-= (info
->offset
- info
->pos
);
11122 memcpy(info
->buffer
+ info
->pos
, data
, len
);
11127 static int copy_info(struct info_str
*info
, char *fmt
, ...)
11133 va_start(args
, fmt
);
11134 len
= vsprintf(buf
, fmt
, args
);
11137 copy_mem_info(info
, buf
, len
);
11142 ** Copy formatted profile information into the input buffer.
11145 #define to_ms(t) ((t) * 1000 / HZ)
11147 static int ncr_host_info(ncb_p np
, char *ptr
, off_t offset
, int len
)
11149 struct info_str info
;
11153 info
.offset
= offset
;
11156 copy_info(&info
, "General information:\n");
11157 copy_info(&info
, " Chip " NAME53C
"%s, ", np
->chip_name
);
11158 copy_info(&info
, "device id 0x%x, ", np
->device_id
);
11159 copy_info(&info
, "revision id 0x%x\n", np
->revision_id
);
11161 copy_info(&info
, " IO port address 0x%lx, ", (u_long
) np
->base_io
);
11162 copy_info(&info
, "IRQ number %d\n", (int) np
->irq
);
11164 #ifndef NCR_IOMAPPED
11166 copy_info(&info
, " Using memory mapped IO at virtual address 0x%lx\n",
11169 copy_info(&info
, " Synchronous period factor %d, ", (int) np
->minsync
);
11170 copy_info(&info
, "max commands per lun %d\n", SCSI_NCR_MAX_TAGS
);
11172 if (driver_setup
.debug
|| driver_setup
.verbose
> 1) {
11173 copy_info(&info
, " Debug flags 0x%x, ", driver_setup
.debug
);
11174 copy_info(&info
, "verbosity level %d\n", driver_setup
.verbose
);
11177 #ifdef SCSI_NCR_PROFILE_SUPPORT
11178 copy_info(&info
, "Profiling information:\n");
11179 copy_info(&info
, " %-12s = %lu\n", "num_fly", np
->profile
.num_fly
);
11180 copy_info(&info
, " %-12s = %lu\n", "num_trans",np
->profile
.num_trans
);
11181 copy_info(&info
, " %-12s = %lu\n", "num_disc", np
->profile
.num_disc
);
11182 copy_info(&info
, " %-12s = %lu\n", "num_disc0",np
->profile
.num_disc0
);
11183 copy_info(&info
, " %-12s = %lu\n", "num_break",np
->profile
.num_break
);
11185 copy_info(&info
, " %-12s = %lu\n", "num_br1k",np
->profile
.num_br1k
);
11186 copy_info(&info
, " %-12s = %lu\n", "num_br2k",np
->profile
.num_br2k
);
11187 copy_info(&info
, " %-12s = %lu\n", "num_br4k",np
->profile
.num_br4k
);
11188 copy_info(&info
, " %-12s = %lu\n", "num_br8k",np
->profile
.num_br8k
);
11189 copy_info(&info
, " %-12s = %lu\n", "num_brnk",np
->profile
.num_brnk
);
11191 copy_info(&info
, " %-12s = %lu\n", "num_int", np
->profile
.num_int
);
11192 copy_info(&info
, " %-12s = %lu\n","num_kbytes",np
->profile
.num_kbytes
);
11195 return info
.pos
> info
.offset
? info
.pos
- info
.offset
: 0;
11198 #endif /* SCSI_NCR_USER_INFO_SUPPORT */
11201 ** Entry point of the scsi proc fs of the driver.
11202 ** - func = 0 means read (returns profile data)
11203 ** - func = 1 means write (parse user control command)
11206 static int sym53c8xx_proc_info(char *buffer
, char **start
, off_t offset
,
11207 int length
, int hostno
, int func
)
11209 struct Scsi_Host
*host
;
11210 struct host_data
*host_data
;
11214 #ifdef DEBUG_PROC_INFO
11215 printk("sym53c8xx_proc_info: hostno=%d, func=%d\n", hostno
, func
);
11218 for (host
= first_host
; host
; host
= host
->next
) {
11219 if (host
->hostt
!= first_host
->hostt
)
11221 if (host
->host_no
== hostno
) {
11222 host_data
= (struct host_data
*) host
->hostdata
;
11223 ncb
= host_data
->ncb
;
11232 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
11233 retv
= ncr_user_command(ncb
, buffer
, length
);
11241 #ifdef SCSI_NCR_USER_INFO_SUPPORT
11242 retv
= ncr_host_info(ncb
, buffer
, offset
, length
);
11252 /*=========================================================================
11253 ** End of proc file system stuff
11254 **=========================================================================
11259 #ifdef SCSI_NCR_NVRAM_SUPPORT
11261 /* ---------------------------------------------------------------------
11263 ** Try reading Symbios format nvram
11265 ** ---------------------------------------------------------------------
11267 ** GPOI0 - data in/data out
11270 ** return 0 if NVRAM data OK, 1 if NVRAM data not OK
11271 ** ---------------------------------------------------------------------
11279 static u_short
nvram_read_data(ncr_slot
*np
, u_char
*data
, int len
, u_char
*gpreg
, u_char
*gpcntl
);
11280 static void nvram_start(ncr_slot
*np
, u_char
*gpreg
);
11281 static void nvram_write_byte(ncr_slot
*np
, u_char
*ack_data
, u_char write_data
, u_char
*gpreg
, u_char
*gpcntl
);
11282 static void nvram_read_byte(ncr_slot
*np
, u_char
*read_data
, u_char ack_data
, u_char
*gpreg
, u_char
*gpcntl
);
11283 static void nvram_readAck(ncr_slot
*np
, u_char
*read_bit
, u_char
*gpreg
, u_char
*gpcntl
);
11284 static void nvram_writeAck(ncr_slot
*np
, u_char write_bit
, u_char
*gpreg
, u_char
*gpcntl
);
11285 static void nvram_doBit(ncr_slot
*np
, u_char
*read_bit
, u_char write_bit
, u_char
*gpreg
);
11286 static void nvram_stop(ncr_slot
*np
, u_char
*gpreg
);
11287 static void nvram_setBit(ncr_slot
*np
, u_char write_bit
, u_char
*gpreg
, int bit_mode
);
11289 static int __init
ncr_get_Symbios_nvram (ncr_slot
*np
, Symbios_nvram
*nvram
)
11291 static u_char Symbios_trailer
[6] = {0xfe, 0xfe, 0, 0, 0, 0};
11292 u_char gpcntl
, gpreg
;
11293 u_char old_gpcntl
, old_gpreg
;
11298 /* save current state of GPCNTL and GPREG */
11299 old_gpreg
= INB (nc_gpreg
);
11300 old_gpcntl
= INB (nc_gpcntl
);
11301 gpcntl
= old_gpcntl
& 0xfc;
11303 /* set up GPREG & GPCNTL to set GPIO0 and GPIO1 in to known state */
11304 OUTB (nc_gpreg
, old_gpreg
);
11305 OUTB (nc_gpcntl
, gpcntl
);
11307 /* this is to set NVRAM into a known state with GPIO0/1 both low */
11309 nvram_setBit(np
, 0, &gpreg
, CLR_CLK
);
11310 nvram_setBit(np
, 0, &gpreg
, CLR_BIT
);
11312 /* now set NVRAM inactive with GPIO0/1 both high */
11313 nvram_stop(np
, &gpreg
);
11315 /* activate NVRAM */
11316 nvram_start(np
, &gpreg
);
11318 /* write device code and random address MSB */
11319 nvram_write_byte(np
, &ack_data
,
11320 0xa0 | ((SYMBIOS_NVRAM_ADDRESS
>> 7) & 0x0e), &gpreg
, &gpcntl
);
11321 if (ack_data
& 0x01)
11324 /* write random address LSB */
11325 nvram_write_byte(np
, &ack_data
,
11326 (SYMBIOS_NVRAM_ADDRESS
& 0x7f) << 1, &gpreg
, &gpcntl
);
11327 if (ack_data
& 0x01)
11330 /* regenerate START state to set up for reading */
11331 nvram_start(np
, &gpreg
);
11333 /* rewrite device code and address MSB with read bit set (lsb = 0x01) */
11334 nvram_write_byte(np
, &ack_data
,
11335 0xa1 | ((SYMBIOS_NVRAM_ADDRESS
>> 7) & 0x0e), &gpreg
, &gpcntl
);
11336 if (ack_data
& 0x01)
11339 /* now set up GPIO0 for inputting data */
11341 OUTB (nc_gpcntl
, gpcntl
);
11343 /* input all active data - only part of total NVRAM */
11344 csum
= nvram_read_data(np
,
11345 (u_char
*) nvram
, sizeof(*nvram
), &gpreg
, &gpcntl
);
11347 /* finally put NVRAM back in inactive mode */
11349 OUTB (nc_gpcntl
, gpcntl
);
11350 nvram_stop(np
, &gpreg
);
11352 #ifdef SCSI_NCR_DEBUG_NVRAM
11353 printk("sym53c8xx: NvRAM marker=%x trailer=%x %x %x %x %x %x byte_count=%d/%d checksum=%x/%x\n",
11354 nvram
->start_marker
,
11355 nvram
->trailer
[0], nvram
->trailer
[1], nvram
->trailer
[2],
11356 nvram
->trailer
[3], nvram
->trailer
[4], nvram
->trailer
[5],
11357 nvram
->byte_count
, sizeof(*nvram
) - 12,
11358 nvram
->checksum
, csum
);
11361 /* check valid NVRAM signature, verify byte count and checksum */
11362 if (nvram
->type
== 0 &&
11363 !memcmp(nvram
->trailer
, Symbios_trailer
, 6) &&
11364 nvram
->byte_count
== sizeof(*nvram
) - 12 &&
11365 csum
== nvram
->checksum
)
11368 /* return GPIO0/1 to original states after having accessed NVRAM */
11369 OUTB (nc_gpcntl
, old_gpcntl
);
11370 OUTB (nc_gpreg
, old_gpreg
);
11376 * Read Symbios NvRAM data and compute checksum.
11378 static u_short __init
nvram_read_data(ncr_slot
*np
, u_char
*data
, int len
, u_char
*gpreg
, u_char
*gpcntl
)
11383 for (x
= 0; x
< len
; x
++)
11384 nvram_read_byte(np
, &data
[x
], (x
== (len
- 1)), gpreg
, gpcntl
);
11386 for (x
= 6, csum
= 0; x
< len
- 6; x
++)
11393 * Send START condition to NVRAM to wake it up.
11395 static void __init
nvram_start(ncr_slot
*np
, u_char
*gpreg
)
11397 nvram_setBit(np
, 1, gpreg
, SET_BIT
);
11398 nvram_setBit(np
, 0, gpreg
, SET_CLK
);
11399 nvram_setBit(np
, 0, gpreg
, CLR_BIT
);
11400 nvram_setBit(np
, 0, gpreg
, CLR_CLK
);
11404 * WRITE a byte to the NVRAM and then get an ACK to see it was accepted OK,
11405 * GPIO0 must already be set as an output
11407 static void __init
nvram_write_byte(ncr_slot
*np
, u_char
*ack_data
, u_char write_data
, u_char
*gpreg
, u_char
*gpcntl
)
11411 for (x
= 0; x
< 8; x
++)
11412 nvram_doBit(np
, 0, (write_data
>> (7 - x
)) & 0x01, gpreg
);
11414 nvram_readAck(np
, ack_data
, gpreg
, gpcntl
);
11418 * READ a byte from the NVRAM and then send an ACK to say we have got it,
11419 * GPIO0 must already be set as an input
11421 static void __init
nvram_read_byte(ncr_slot
*np
, u_char
*read_data
, u_char ack_data
, u_char
*gpreg
, u_char
*gpcntl
)
11427 for (x
= 0; x
< 8; x
++) {
11428 nvram_doBit(np
, &read_bit
, 1, gpreg
);
11429 *read_data
|= ((read_bit
& 0x01) << (7 - x
));
11432 nvram_writeAck(np
, ack_data
, gpreg
, gpcntl
);
11436 * Output an ACK to the NVRAM after reading,
11437 * change GPIO0 to output and when done back to an input
11439 static void __init
nvram_writeAck(ncr_slot
*np
, u_char write_bit
, u_char
*gpreg
, u_char
*gpcntl
)
11441 OUTB (nc_gpcntl
, *gpcntl
& 0xfe);
11442 nvram_doBit(np
, 0, write_bit
, gpreg
);
11443 OUTB (nc_gpcntl
, *gpcntl
);
11447 * Input an ACK from NVRAM after writing,
11448 * change GPIO0 to input and when done back to an output
11450 static void __init
nvram_readAck(ncr_slot
*np
, u_char
*read_bit
, u_char
*gpreg
, u_char
*gpcntl
)
11452 OUTB (nc_gpcntl
, *gpcntl
| 0x01);
11453 nvram_doBit(np
, read_bit
, 1, gpreg
);
11454 OUTB (nc_gpcntl
, *gpcntl
);
11458 * Read or write a bit to the NVRAM,
11459 * read if GPIO0 input else write if GPIO0 output
11461 static void __init
nvram_doBit(ncr_slot
*np
, u_char
*read_bit
, u_char write_bit
, u_char
*gpreg
)
11463 nvram_setBit(np
, write_bit
, gpreg
, SET_BIT
);
11464 nvram_setBit(np
, 0, gpreg
, SET_CLK
);
11466 *read_bit
= INB (nc_gpreg
);
11467 nvram_setBit(np
, 0, gpreg
, CLR_CLK
);
11468 nvram_setBit(np
, 0, gpreg
, CLR_BIT
);
11472 * Send STOP condition to NVRAM - puts NVRAM to sleep... ZZzzzz!!
11474 static void __init
nvram_stop(ncr_slot
*np
, u_char
*gpreg
)
11476 nvram_setBit(np
, 0, gpreg
, SET_CLK
);
11477 nvram_setBit(np
, 1, gpreg
, SET_BIT
);
11481 * Set/clear data/clock bit in GPIO0
11483 static void __init
nvram_setBit(ncr_slot
*np
, u_char write_bit
, u_char
*gpreg
, int bit_mode
)
11488 *gpreg
|= write_bit
;
11501 OUTB (nc_gpreg
, *gpreg
);
11511 /* ---------------------------------------------------------------------
11513 ** Try reading Tekram format nvram
11515 ** ---------------------------------------------------------------------
11518 ** GPIO1 - data out
11520 ** GPIO4 - chip select
11522 ** return 0 if NVRAM data OK, 1 if NVRAM data not OK
11523 ** ---------------------------------------------------------------------
11526 static u_short
Tnvram_read_data(ncr_slot
*np
, u_short
*data
, int len
, u_char
*gpreg
);
11527 static void Tnvram_Send_Command(ncr_slot
*np
, u_short write_data
, u_char
*read_bit
, u_char
*gpreg
);
11528 static void Tnvram_Read_Word(ncr_slot
*np
, u_short
*nvram_data
, u_char
*gpreg
);
11529 static void Tnvram_Read_Bit(ncr_slot
*np
, u_char
*read_bit
, u_char
*gpreg
);
11530 static void Tnvram_Write_Bit(ncr_slot
*np
, u_char write_bit
, u_char
*gpreg
);
11531 static void Tnvram_Stop(ncr_slot
*np
, u_char
*gpreg
);
11532 static void Tnvram_Clk(ncr_slot
*np
, u_char
*gpreg
);
11534 static int __init
ncr_get_Tekram_nvram (ncr_slot
*np
, Tekram_nvram
*nvram
)
11536 u_char gpcntl
, gpreg
;
11537 u_char old_gpcntl
, old_gpreg
;
11540 /* save current state of GPCNTL and GPREG */
11541 old_gpreg
= INB (nc_gpreg
);
11542 old_gpcntl
= INB (nc_gpcntl
);
11544 /* set up GPREG & GPCNTL to set GPIO0/1/2/4 in to known state, 0 in,
11546 gpreg
= old_gpreg
& 0xe9;
11547 OUTB (nc_gpreg
, gpreg
);
11548 gpcntl
= (old_gpcntl
& 0xe9) | 0x09;
11549 OUTB (nc_gpcntl
, gpcntl
);
11551 /* input all of NVRAM, 64 words */
11552 csum
= Tnvram_read_data(np
, (u_short
*) nvram
,
11553 sizeof(*nvram
) / sizeof(short), &gpreg
);
11555 /* return GPIO0/1/2/4 to original states after having accessed NVRAM */
11556 OUTB (nc_gpcntl
, old_gpcntl
);
11557 OUTB (nc_gpreg
, old_gpreg
);
11559 /* check data valid */
11560 if (csum
!= 0x1234)
11567 * Read Tekram NvRAM data and compute checksum.
11569 static u_short __init
Tnvram_read_data(ncr_slot
*np
, u_short
*data
, int len
, u_char
*gpreg
)
11575 for (x
= 0, csum
= 0; x
< len
; x
++) {
11577 /* output read command and address */
11578 Tnvram_Send_Command(np
, 0x180 | x
, &read_bit
, gpreg
);
11579 if (read_bit
& 0x01)
11580 return 0; /* Force bad checksum */
11582 Tnvram_Read_Word(np
, &data
[x
], gpreg
);
11585 Tnvram_Stop(np
, gpreg
);
11592 * Send read command and address to NVRAM
11594 static void __init
Tnvram_Send_Command(ncr_slot
*np
, u_short write_data
, u_char
*read_bit
, u_char
*gpreg
)
11598 /* send 9 bits, start bit (1), command (2), address (6) */
11599 for (x
= 0; x
< 9; x
++)
11600 Tnvram_Write_Bit(np
, (u_char
) (write_data
>> (8 - x
)), gpreg
);
11602 *read_bit
= INB (nc_gpreg
);
11606 * READ a byte from the NVRAM
11608 static void __init
Tnvram_Read_Word(ncr_slot
*np
, u_short
*nvram_data
, u_char
*gpreg
)
11614 for (x
= 0; x
< 16; x
++) {
11615 Tnvram_Read_Bit(np
, &read_bit
, gpreg
);
11617 if (read_bit
& 0x01)
11618 *nvram_data
|= (0x01 << (15 - x
));
11620 *nvram_data
&= ~(0x01 << (15 - x
));
11625 * Read bit from NVRAM
11627 static void __init
Tnvram_Read_Bit(ncr_slot
*np
, u_char
*read_bit
, u_char
*gpreg
)
11630 Tnvram_Clk(np
, gpreg
);
11631 *read_bit
= INB (nc_gpreg
);
11635 * Write bit to GPIO0
11637 static void __init
Tnvram_Write_Bit(ncr_slot
*np
, u_char write_bit
, u_char
*gpreg
)
11639 if (write_bit
& 0x01)
11646 OUTB (nc_gpreg
, *gpreg
);
11649 Tnvram_Clk(np
, gpreg
);
11653 * Send STOP condition to NVRAM - puts NVRAM to sleep... ZZZzzz!!
11655 static void __init
Tnvram_Stop(ncr_slot
*np
, u_char
*gpreg
)
11658 OUTB (nc_gpreg
, *gpreg
);
11661 Tnvram_Clk(np
, gpreg
);
11665 * Pulse clock bit in GPIO0
11667 static void __init
Tnvram_Clk(ncr_slot
*np
, u_char
*gpreg
)
11669 OUTB (nc_gpreg
, *gpreg
| 0x04);
11671 OUTB (nc_gpreg
, *gpreg
);
11674 #endif /* SCSI_NCR_NVRAM_SUPPORT */
11681 Scsi_Host_Template driver_template
= SYM53C8XX
;
11682 #include "scsi_module.c"