1 /******************************************************************************
2 ** High Performance device driver for the Symbios 53C896 controller.
4 ** Copyright (C) 1998-2001 Gerard Roudier <groudier@free.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@free.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 ** Supported SCSI features:
59 ** Synchronous data transfers
61 ** Disconnection/Reselection
62 ** Tagged command queuing
63 ** SCSI Parity checking
65 ** Supported NCR/SYMBIOS chips:
66 ** 53C810A (8 bits, Fast 10, no rom BIOS)
67 ** 53C825A (Wide, Fast 10, on-board rom BIOS)
68 ** 53C860 (8 bits, Fast 20, no rom BIOS)
69 ** 53C875 (Wide, Fast 20, on-board rom BIOS)
70 ** 53C876 (Wide, Fast 20 Dual, on-board rom BIOS)
71 ** 53C895 (Wide, Fast 40, on-board rom BIOS)
72 ** 53C895A (Wide, Fast 40, on-board rom BIOS)
73 ** 53C896 (Wide, Fast 40 Dual, on-board rom BIOS)
74 ** 53C897 (Wide, Fast 40 Dual, on-board rom BIOS)
75 ** 53C1510D (Wide, Fast 40 Dual, on-board rom BIOS)
76 ** 53C1010 (Wide, Fast 80 Dual, on-board rom BIOS)
77 ** 53C1010_66(Wide, Fast 80 Dual, on-board rom BIOS, 33/66MHz PCI)
86 ** Name and version of the driver
88 #define SCSI_NCR_DRIVER_NAME "sym53c8xx-1.7.3c-20010512"
90 #define SCSI_NCR_DEBUG_FLAGS (0)
92 #define NAME53C "sym53c"
93 #define NAME53C8XX "sym53c8xx"
95 /*==========================================================
99 **==========================================================
102 #include <linux/version.h>
104 #include <linux/module.h>
108 #include <asm/system.h>
109 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
110 #include <linux/spinlock.h>
111 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
112 #include <asm/spinlock.h>
114 #include <linux/delay.h>
115 #include <linux/interrupt.h>
116 #include <linux/signal.h>
117 #include <linux/errno.h>
118 #include <linux/pci.h>
119 #include <linux/string.h>
120 #include <linux/mm.h>
121 #include <linux/ioport.h>
122 #include <linux/time.h>
123 #include <linux/timer.h>
124 #include <linux/stat.h>
126 #include <linux/blk.h>
128 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,35)
129 #include <linux/init.h>
139 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,92)
140 #include <linux/bios32.h>
146 #include <linux/types.h>
149 ** Define BITS_PER_LONG for earlier linux versions.
151 #ifndef BITS_PER_LONG
152 #if (~0UL) == 0xffffffffUL
153 #define BITS_PER_LONG 32
155 #define BITS_PER_LONG 64
160 ** Define the BSD style u_int32 and u_int64 type.
161 ** Are in fact u_int32_t and u_int64_t :-)
166 #include "sym53c8xx.h"
169 ** Donnot compile integrity checking code for Linux-2.3.0
170 ** and above since SCSI data structures are not ready yet.
172 /* #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
174 #define SCSI_NCR_INTEGRITY_CHECKING
177 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
178 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
181 ** Hmmm... What complex some PCI-HOST bridges actually are,
182 ** despite the fact that the PCI specifications are looking
183 ** so smart and simple! ;-)
185 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,47)
186 #define SCSI_NCR_DYNAMIC_DMA_MAPPING
189 /*==========================================================
191 ** A la VMS/CAM-3 queue management.
192 ** Implemented from linux list management.
194 **==========================================================
197 typedef struct xpt_quehead
{
198 struct xpt_quehead
*flink
; /* Forward pointer */
199 struct xpt_quehead
*blink
; /* Backward pointer */
202 #define xpt_que_init(ptr) do { \
203 (ptr)->flink = (ptr); (ptr)->blink = (ptr); \
206 static inline void __xpt_que_add(struct xpt_quehead
* new,
207 struct xpt_quehead
* blink
,
208 struct xpt_quehead
* flink
)
216 static inline void __xpt_que_del(struct xpt_quehead
* blink
,
217 struct xpt_quehead
* flink
)
219 flink
->blink
= blink
;
220 blink
->flink
= flink
;
223 static inline int xpt_que_empty(struct xpt_quehead
*head
)
225 return head
->flink
== head
;
228 static inline void xpt_que_splice(struct xpt_quehead
*list
,
229 struct xpt_quehead
*head
)
231 struct xpt_quehead
*first
= list
->flink
;
234 struct xpt_quehead
*last
= list
->blink
;
235 struct xpt_quehead
*at
= head
->flink
;
245 #define xpt_que_entry(ptr, type, member) \
246 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
249 #define xpt_insque(new, pos) __xpt_que_add(new, pos, (pos)->flink)
251 #define xpt_remque(el) __xpt_que_del((el)->blink, (el)->flink)
253 #define xpt_insque_head(new, head) __xpt_que_add(new, head, (head)->flink)
255 static inline struct xpt_quehead
*xpt_remque_head(struct xpt_quehead
*head
)
257 struct xpt_quehead
*elem
= head
->flink
;
260 __xpt_que_del(head
, elem
->flink
);
266 #define xpt_insque_tail(new, head) __xpt_que_add(new, (head)->blink, head)
268 static inline struct xpt_quehead
*xpt_remque_tail(struct xpt_quehead
*head
)
270 struct xpt_quehead
*elem
= head
->blink
;
273 __xpt_que_del(elem
->blink
, head
);
279 /*==========================================================
281 ** Configuration and Debugging
283 **==========================================================
287 ** SCSI address of this device.
288 ** The boot routines should have set it.
292 #ifndef SCSI_NCR_MYADDR
293 #define SCSI_NCR_MYADDR (7)
297 ** The maximum number of tags per logic unit.
298 ** Used only for devices that support tags.
301 #ifndef SCSI_NCR_MAX_TAGS
302 #define SCSI_NCR_MAX_TAGS (8)
306 ** TAGS are actually unlimited (256 tags/lun).
307 ** But Linux only supports 255. :)
309 #if SCSI_NCR_MAX_TAGS > 255
312 #define MAX_TAGS SCSI_NCR_MAX_TAGS
316 ** Since the ncr chips only have a 8 bit ALU, we try to be clever
317 ** about offset calculation in the TASK TABLE per LUN that is an
318 ** array of DWORDS = 4 bytes.
320 #if MAX_TAGS > (512/4)
321 #define MAX_TASKS (1024/4)
322 #elif MAX_TAGS > (256/4)
323 #define MAX_TASKS (512/4)
325 #define MAX_TASKS (256/4)
329 ** This one means 'NO TAG for this job'
334 ** Number of targets supported by the driver.
335 ** n permits target numbers 0..n-1.
336 ** Default is 16, meaning targets #0..#15.
340 #ifdef SCSI_NCR_MAX_TARGET
341 #define MAX_TARGET (SCSI_NCR_MAX_TARGET)
343 #define MAX_TARGET (16)
347 ** Number of logic units supported by the driver.
348 ** n enables logic unit numbers 0..n-1.
349 ** The common SCSI devices require only
350 ** one lun, so take 1 as the default.
353 #ifdef SCSI_NCR_MAX_LUN
360 ** Asynchronous pre-scaler (ns). Shall be 40 for
361 ** the SCSI timings to be compliant.
364 #ifndef SCSI_NCR_MIN_ASYNC
365 #define SCSI_NCR_MIN_ASYNC (40)
369 ** The maximum number of jobs scheduled for starting.
370 ** We allocate 4 entries more than the value we announce
371 ** to the SCSI upper layer. Guess why ! :-)
374 #ifdef SCSI_NCR_CAN_QUEUE
375 #define MAX_START (SCSI_NCR_CAN_QUEUE + 4)
377 #define MAX_START (MAX_TARGET + 7 * MAX_TAGS)
381 ** We donnot want to allocate more than 1 PAGE for the
382 ** the start queue and the done queue. We hard-code entry
383 ** size to 8 in order to let cpp do the checking.
384 ** Allows 512-4=508 pending IOs for i386 but Linux seems for
385 ** now not able to provide the driver with this amount of IOs.
387 #if MAX_START > PAGE_SIZE/8
389 #define MAX_START (PAGE_SIZE/8)
393 ** The maximum number of segments a transfer is split into.
394 ** We support up to 127 segments for both read and write.
397 #define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)
398 #define SCR_SG_SIZE (2)
404 #define NCR_SNOOP_TIMEOUT (1000000)
406 /*==========================================================
408 ** Miscallaneous BSDish defines.
410 **==========================================================
413 #define u_char unsigned char
414 #define u_short unsigned short
415 #define u_int unsigned int
416 #define u_long unsigned long
419 #define bcopy(s, d, n) memcpy((d), (s), (n))
423 #define bzero(d, n) memset((d), 0, (n))
427 #define offsetof(t, m) ((size_t) (&((t *)0)->m))
431 ** Simple Wrapper to kernel PCI bus interface.
433 ** This wrapper allows to get rid of old kernel PCI interface
434 ** and still allows to preserve linux-2.0 compatibilty.
435 ** In fact, it is mostly an incomplete emulation of the new
436 ** PCI code for pre-2.2 kernels. When kernel-2.0 support
437 ** will be dropped, we will just have to remove most of this
441 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
443 typedef struct pci_dev
*pcidev_t
;
444 #define PCIDEV_NULL (0)
445 #define PciBusNumber(d) (d)->bus->number
446 #define PciDeviceFn(d) (d)->devfn
447 #define PciVendorId(d) (d)->vendor
448 #define PciDeviceId(d) (d)->device
449 #define PciIrqLine(d) (d)->irq
452 pci_get_base_cookie(struct pci_dev
*pdev
, int index
)
456 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,12)
457 base
= pdev
->resource
[index
].start
;
459 base
= pdev
->base_address
[index
];
460 #if BITS_PER_LONG > 32
461 if ((base
& 0x7) == 0x4)
462 *base
|= (((u_long
)pdev
->base_address
[++index
]) << 32);
465 return (base
& ~0x7ul
);
469 pci_get_base_address(struct pci_dev
*pdev
, int index
, u_long
*base
)
472 #define PCI_BAR_OFFSET(index) (PCI_BASE_ADDRESS_0 + (index<<2))
474 pci_read_config_dword(pdev
, PCI_BAR_OFFSET(index
), &tmp
);
477 if ((tmp
& 0x7) == 0x4) {
478 #if BITS_PER_LONG > 32
479 pci_read_config_dword(pdev
, PCI_BAR_OFFSET(index
), &tmp
);
480 *base
|= (((u_long
)tmp
) << 32);
485 #undef PCI_BAR_OFFSET
488 #else /* Incomplete emulation of current PCI code for pre-2.2 kernels */
490 typedef unsigned int pcidev_t
;
491 #define PCIDEV_NULL (~0u)
492 #define PciBusNumber(d) ((d)>>8)
493 #define PciDeviceFn(d) ((d)&0xff)
494 #define __PciDev(busn, devfn) (((busn)<<8)+(devfn))
496 #define pci_present pcibios_present
498 #define pci_read_config_byte(d, w, v) \
499 pcibios_read_config_byte(PciBusNumber(d), PciDeviceFn(d), w, v)
500 #define pci_read_config_word(d, w, v) \
501 pcibios_read_config_word(PciBusNumber(d), PciDeviceFn(d), w, v)
502 #define pci_read_config_dword(d, w, v) \
503 pcibios_read_config_dword(PciBusNumber(d), PciDeviceFn(d), w, v)
505 #define pci_write_config_byte(d, w, v) \
506 pcibios_write_config_byte(PciBusNumber(d), PciDeviceFn(d), w, v)
507 #define pci_write_config_word(d, w, v) \
508 pcibios_write_config_word(PciBusNumber(d), PciDeviceFn(d), w, v)
509 #define pci_write_config_dword(d, w, v) \
510 pcibios_write_config_dword(PciBusNumber(d), PciDeviceFn(d), w, v)
512 static pcidev_t __init
513 pci_find_device(unsigned int vendor
, unsigned int device
, pcidev_t prev
)
515 static unsigned short pci_index
;
517 unsigned char bus_number
, device_fn
;
519 if (prev
== PCIDEV_NULL
)
523 retv
= pcibios_find_device (vendor
, device
, pci_index
,
524 &bus_number
, &device_fn
);
525 return retv
? PCIDEV_NULL
: __PciDev(bus_number
, device_fn
);
528 static u_short __init
PciVendorId(pcidev_t dev
)
531 pci_read_config_word(dev
, PCI_VENDOR_ID
, &vendor_id
);
535 static u_short __init
PciDeviceId(pcidev_t dev
)
538 pci_read_config_word(dev
, PCI_DEVICE_ID
, &device_id
);
542 static u_int __init
PciIrqLine(pcidev_t dev
)
545 pci_read_config_byte(dev
, PCI_INTERRUPT_LINE
, &irq
);
550 pci_get_base_address(pcidev_t dev
, int offset
, u_long
*base
)
554 pci_read_config_dword(dev
, PCI_BASE_ADDRESS_0
+ offset
, &tmp
);
556 offset
+= sizeof(u_int32
);
557 if ((tmp
& 0x7) == 0x4) {
558 #if BITS_PER_LONG > 32
559 pci_read_config_dword(dev
, PCI_BASE_ADDRESS_0
+ offset
, &tmp
);
560 *base
|= (((u_long
)tmp
) << 32);
562 offset
+= sizeof(u_int32
);
567 pci_get_base_cookie(struct pci_dev
*pdev
, int offset
)
571 (void) pci_get_base_address(dev
, offset
, &base
);
576 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) */
578 /* Does not make sense in earlier kernels */
579 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
580 #define pci_enable_device(pdev) (0)
582 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,4)
583 #define scsi_set_pci_device(inst, pdev) (0)
586 /*==========================================================
590 **==========================================================
593 #define DEBUG_ALLOC (0x0001)
594 #define DEBUG_PHASE (0x0002)
595 #define DEBUG_QUEUE (0x0008)
596 #define DEBUG_RESULT (0x0010)
597 #define DEBUG_POINTER (0x0020)
598 #define DEBUG_SCRIPT (0x0040)
599 #define DEBUG_TINY (0x0080)
600 #define DEBUG_TIMING (0x0100)
601 #define DEBUG_NEGO (0x0200)
602 #define DEBUG_TAGS (0x0400)
603 #define DEBUG_IC (0x0800)
606 ** Enable/Disable debug messages.
607 ** Can be changed at runtime too.
610 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
611 static int ncr_debug
= SCSI_NCR_DEBUG_FLAGS
;
612 #define DEBUG_FLAGS ncr_debug
614 #define DEBUG_FLAGS SCSI_NCR_DEBUG_FLAGS
620 ** Assuming that SMP systems are generally high end systems and may
621 ** use several SCSI adapters, we are using one lock per controller
622 ** instead of some global one. For the moment (linux-2.1.95), driver's
623 ** entry points are called with the 'io_request_lock' lock held, so:
624 ** - We are uselessly loosing a couple of micro-seconds to lock the
625 ** controller data structure.
626 ** - But the driver is not broken by design for SMP and so can be
627 ** more resistant to bugs or bad changes in the IO sub-system code.
628 ** - A small advantage could be that the interrupt code is grained as
629 ** wished (e.g.: threaded by controller).
632 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
634 spinlock_t sym53c8xx_lock
= SPIN_LOCK_UNLOCKED
;
635 #define NCR_LOCK_DRIVER(flags) spin_lock_irqsave(&sym53c8xx_lock, flags)
636 #define NCR_UNLOCK_DRIVER(flags) spin_unlock_irqrestore(&sym53c8xx_lock,flags)
638 #define NCR_INIT_LOCK_NCB(np) spin_lock_init(&np->smp_lock);
639 #define NCR_LOCK_NCB(np, flags) spin_lock_irqsave(&np->smp_lock, flags)
640 #define NCR_UNLOCK_NCB(np, flags) spin_unlock_irqrestore(&np->smp_lock, flags)
642 #define NCR_LOCK_SCSI_DONE(host, flags) \
643 spin_lock_irqsave(((host)->host_lock), flags)
644 #define NCR_UNLOCK_SCSI_DONE(host, flags) \
645 spin_unlock_irqrestore(((host)->host_lock), flags)
649 #define NCR_LOCK_DRIVER(flags) do { save_flags(flags); cli(); } while (0)
650 #define NCR_UNLOCK_DRIVER(flags) do { restore_flags(flags); } while (0)
652 #define NCR_INIT_LOCK_NCB(np) do { } while (0)
653 #define NCR_LOCK_NCB(np, flags) do { save_flags(flags); cli(); } while (0)
654 #define NCR_UNLOCK_NCB(np, flags) do { restore_flags(flags); } while (0)
656 #define NCR_LOCK_SCSI_DONE(host, flags) do {;} while (0)
657 #define NCR_UNLOCK_SCSI_DONE(host, flags) do {;} while (0)
664 ** Since linux-2.1, we must use ioremap() to map the io memory space.
665 ** iounmap() to unmap it. That allows portability.
666 ** Linux 1.3.X and 2.0.X allow to remap physical pages addresses greater
667 ** than the highest physical memory address to kernel virtual pages with
668 ** vremap() / vfree(). That was not portable but worked with i386
672 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
673 #define ioremap vremap
674 #define iounmap vfree
678 # include <asm/irq.h>
679 # define memcpy_to_pci(a, b, c) memcpy_toio((a), (b), (c))
680 #elif defined(__alpha__)
681 # define memcpy_to_pci(a, b, c) memcpy_toio((a), (b), (c))
683 # define memcpy_to_pci(a, b, c) memcpy_toio((a), (b), (c))
686 #ifndef SCSI_NCR_PCI_MEM_NOT_SUPPORTED
687 static u_long __init
remap_pci_mem(u_long base
, u_long size
)
689 u_long page_base
= ((u_long
) base
) & PAGE_MASK
;
690 u_long page_offs
= ((u_long
) base
) - page_base
;
691 u_long page_remapped
= (u_long
) ioremap(page_base
, page_offs
+size
);
693 return page_remapped
? (page_remapped
+ page_offs
) : 0UL;
696 static void __init
unmap_pci_mem(u_long vaddr
, u_long size
)
699 iounmap((void *) (vaddr
& PAGE_MASK
));
702 #endif /* not def SCSI_NCR_PCI_MEM_NOT_SUPPORTED */
705 ** Insert a delay in micro-seconds and milli-seconds.
706 ** -------------------------------------------------
707 ** Under Linux, udelay() is restricted to delay < 1 milli-second.
708 ** In fact, it generally works for up to 1 second delay.
709 ** Since 2.1.105, the mdelay() function is provided for delays
711 ** Under 2.0 kernels, udelay() is an inline function that is very
712 ** inaccurate on Pentium processors.
715 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,105)
716 #define UDELAY udelay
717 #define MDELAY mdelay
719 static void UDELAY(long us
) { udelay(us
); }
720 static void MDELAY(long ms
) { while (ms
--) UDELAY(1000); }
724 ** Simple power of two buddy-like allocator
725 ** ----------------------------------------
726 ** This simple code is not intended to be fast, but to provide
727 ** power of 2 aligned memory allocations.
728 ** Since the SCRIPTS processor only supplies 8 bit arithmetic,
729 ** this allocator allows simple and fast address calculations
730 ** from the SCRIPTS code. In addition, cache line alignment
731 ** is guaranteed for power of 2 cache line size.
732 ** Enhanced in linux-2.3.44 to provide a memory pool per pcidev
733 ** to support dynamic dma mapping. (I would have preferred a
734 ** real bus astraction, btw).
737 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
738 #define __GetFreePages(flags, order) __get_free_pages(flags, order)
740 #define __GetFreePages(flags, order) __get_free_pages(flags, order, 0)
743 #define MEMO_SHIFT 4 /* 16 bytes minimum memory chunk */
744 #if PAGE_SIZE >= 8192
745 #define MEMO_PAGE_ORDER 0 /* 1 PAGE maximum */
747 #define MEMO_PAGE_ORDER 1 /* 2 PAGES maximum */
749 #define MEMO_FREE_UNUSED /* Free unused pages immediately */
751 #define MEMO_GFP_FLAGS GFP_ATOMIC
752 #define MEMO_CLUSTER_SHIFT (PAGE_SHIFT+MEMO_PAGE_ORDER)
753 #define MEMO_CLUSTER_SIZE (1UL << MEMO_CLUSTER_SHIFT)
754 #define MEMO_CLUSTER_MASK (MEMO_CLUSTER_SIZE-1)
756 typedef u_long m_addr_t
; /* Enough bits to bit-hack addresses */
757 typedef pcidev_t m_bush_t
; /* Something that addresses DMAable */
759 typedef struct m_link
{ /* Link between free memory chunks */
763 #ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
764 typedef struct m_vtob
{ /* Virtual to Bus address translation */
769 #define VTOB_HASH_SHIFT 5
770 #define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT)
771 #define VTOB_HASH_MASK (VTOB_HASH_SIZE-1)
772 #define VTOB_HASH_CODE(m) \
773 ((((m_addr_t) (m)) >> MEMO_CLUSTER_SHIFT) & VTOB_HASH_MASK)
776 typedef struct m_pool
{ /* Memory pool of a given kind */
777 #ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
779 m_addr_t (*getp
)(struct m_pool
*);
780 void (*freep
)(struct m_pool
*, m_addr_t
);
781 #define M_GETP() mp->getp(mp)
782 #define M_FREEP(p) mp->freep(mp, p)
783 #define GetPages() __GetFreePages(MEMO_GFP_FLAGS, MEMO_PAGE_ORDER)
784 #define FreePages(p) free_pages(p, MEMO_PAGE_ORDER)
786 m_vtob_s
*(vtob
[VTOB_HASH_SIZE
]);
789 #define M_GETP() __GetFreePages(MEMO_GFP_FLAGS, MEMO_PAGE_ORDER)
790 #define M_FREEP(p) free_pages(p, MEMO_PAGE_ORDER)
791 #endif /* SCSI_NCR_DYNAMIC_DMA_MAPPING */
792 struct m_link h
[PAGE_SHIFT
-MEMO_SHIFT
+MEMO_PAGE_ORDER
+1];
795 static void *___m_alloc(m_pool_s
*mp
, int size
)
798 int s
= (1 << MEMO_SHIFT
);
803 if (size
> (PAGE_SIZE
<< MEMO_PAGE_ORDER
))
813 if (s
== (PAGE_SIZE
<< MEMO_PAGE_ORDER
)) {
814 h
[j
].next
= (m_link_s
*) M_GETP();
822 a
= (m_addr_t
) h
[j
].next
;
824 h
[j
].next
= h
[j
].next
->next
;
828 h
[j
].next
= (m_link_s
*) (a
+s
);
833 printk("___m_alloc(%d) = %p\n", size
, (void *) a
);
838 static void ___m_free(m_pool_s
*mp
, void *ptr
, int size
)
841 int s
= (1 << MEMO_SHIFT
);
847 printk("___m_free(%p, %d)\n", ptr
, size
);
850 if (size
> (PAGE_SIZE
<< MEMO_PAGE_ORDER
))
861 #ifdef MEMO_FREE_UNUSED
862 if (s
== (PAGE_SIZE
<< MEMO_PAGE_ORDER
)) {
869 while (q
->next
&& q
->next
!= (m_link_s
*) b
) {
873 ((m_link_s
*) a
)->next
= h
[i
].next
;
874 h
[i
].next
= (m_link_s
*) a
;
877 q
->next
= q
->next
->next
;
884 static void *__m_calloc2(m_pool_s
*mp
, int size
, char *name
, int uflags
)
888 p
= ___m_alloc(mp
, size
);
890 if (DEBUG_FLAGS
& DEBUG_ALLOC
)
891 printk ("new %-10s[%4d] @%p.\n", name
, size
, p
);
895 else if (uflags
& MEMO_WARN
)
896 printk (NAME53C8XX
": failed to allocate %s[%d]\n", name
, size
);
901 #define __m_calloc(mp, s, n) __m_calloc2(mp, s, n, MEMO_WARN)
903 static void __m_free(m_pool_s
*mp
, void *ptr
, int size
, char *name
)
905 if (DEBUG_FLAGS
& DEBUG_ALLOC
)
906 printk ("freeing %-10s[%4d] @%p.\n", name
, size
, ptr
);
908 ___m_free(mp
, ptr
, size
);
913 * With pci bus iommu support, we use a default pool of unmapped memory
914 * for memory we donnot need to DMA from/to and one pool per pcidev for
915 * memory accessed by the PCI chip. `mp0' is the default not DMAable pool.
918 #ifndef SCSI_NCR_DYNAMIC_DMA_MAPPING
924 static m_addr_t
___mp0_getp(m_pool_s
*mp
)
926 m_addr_t m
= GetPages();
932 static void ___mp0_freep(m_pool_s
*mp
, m_addr_t m
)
938 static m_pool_s mp0
= {0, ___mp0_getp
, ___mp0_freep
};
940 #endif /* SCSI_NCR_DYNAMIC_DMA_MAPPING */
942 static void *m_calloc(int size
, char *name
)
946 NCR_LOCK_DRIVER(flags
);
947 m
= __m_calloc(&mp0
, size
, name
);
948 NCR_UNLOCK_DRIVER(flags
);
952 static void m_free(void *ptr
, int size
, char *name
)
955 NCR_LOCK_DRIVER(flags
);
956 __m_free(&mp0
, ptr
, size
, name
);
957 NCR_UNLOCK_DRIVER(flags
);
964 #ifndef SCSI_NCR_DYNAMIC_DMA_MAPPING
966 /* Without pci bus iommu support, all the memory is assumed DMAable */
968 #define __m_calloc_dma(b, s, n) m_calloc(s, n)
969 #define __m_free_dma(b, p, s, n) m_free(p, s, n)
970 #define __vtobus(b, p) virt_to_bus(p)
975 * With pci bus iommu support, we maintain one pool per pcidev and a
976 * hashed reverse table for virtual to bus physical address translations.
978 static m_addr_t
___dma_getp(m_pool_s
*mp
)
983 vbp
= __m_calloc(&mp0
, sizeof(*vbp
), "VTOB");
986 vp
= (m_addr_t
) pci_alloc_consistent(mp
->bush
,
987 PAGE_SIZE
<<MEMO_PAGE_ORDER
,
990 int hc
= VTOB_HASH_CODE(vp
);
993 vbp
->next
= mp
->vtob
[hc
];
999 __m_free(&mp0
, vbp
, sizeof(*vbp
), "VTOB");
1004 static void ___dma_freep(m_pool_s
*mp
, m_addr_t m
)
1006 m_vtob_s
**vbpp
, *vbp
;
1007 int hc
= VTOB_HASH_CODE(m
);
1009 vbpp
= &mp
->vtob
[hc
];
1010 while (*vbpp
&& (*vbpp
)->vaddr
!= m
)
1011 vbpp
= &(*vbpp
)->next
;
1014 *vbpp
= (*vbpp
)->next
;
1015 pci_free_consistent(mp
->bush
, PAGE_SIZE
<<MEMO_PAGE_ORDER
,
1016 (void *)vbp
->vaddr
, (dma_addr_t
)vbp
->baddr
);
1017 __m_free(&mp0
, vbp
, sizeof(*vbp
), "VTOB");
1022 static inline m_pool_s
*___get_dma_pool(m_bush_t bush
)
1025 for (mp
= mp0
.next
; mp
&& mp
->bush
!= bush
; mp
= mp
->next
);
1029 static m_pool_s
*___cre_dma_pool(m_bush_t bush
)
1032 mp
= __m_calloc(&mp0
, sizeof(*mp
), "MPOOL");
1034 bzero(mp
, sizeof(*mp
));
1036 mp
->getp
= ___dma_getp
;
1037 mp
->freep
= ___dma_freep
;
1038 mp
->next
= mp0
.next
;
1044 static void ___del_dma_pool(m_pool_s
*p
)
1046 struct m_pool
**pp
= &mp0
.next
;
1048 while (*pp
&& *pp
!= p
)
1052 __m_free(&mp0
, p
, sizeof(*p
), "MPOOL");
1056 static void *__m_calloc_dma(m_bush_t bush
, int size
, char *name
)
1062 NCR_LOCK_DRIVER(flags
);
1063 mp
= ___get_dma_pool(bush
);
1065 mp
= ___cre_dma_pool(bush
);
1067 m
= __m_calloc(mp
, size
, name
);
1068 if (mp
&& !mp
->nump
)
1069 ___del_dma_pool(mp
);
1070 NCR_UNLOCK_DRIVER(flags
);
1075 static void __m_free_dma(m_bush_t bush
, void *m
, int size
, char *name
)
1080 NCR_LOCK_DRIVER(flags
);
1081 mp
= ___get_dma_pool(bush
);
1083 __m_free(mp
, m
, size
, name
);
1084 if (mp
&& !mp
->nump
)
1085 ___del_dma_pool(mp
);
1086 NCR_UNLOCK_DRIVER(flags
);
1089 static m_addr_t
__vtobus(m_bush_t bush
, void *m
)
1093 int hc
= VTOB_HASH_CODE(m
);
1095 m_addr_t a
= ((m_addr_t
) m
) & ~MEMO_CLUSTER_MASK
;
1097 NCR_LOCK_DRIVER(flags
);
1098 mp
= ___get_dma_pool(bush
);
1101 while (vp
&& (m_addr_t
) vp
->vaddr
!= a
)
1104 NCR_UNLOCK_DRIVER(flags
);
1105 return vp
? vp
->baddr
+ (((m_addr_t
) m
) - a
) : 0;
1108 #endif /* SCSI_NCR_DYNAMIC_DMA_MAPPING */
1110 #define _m_calloc_dma(np, s, n) __m_calloc_dma(np->pdev, s, n)
1111 #define _m_free_dma(np, p, s, n) __m_free_dma(np->pdev, p, s, n)
1112 #define m_calloc_dma(s, n) _m_calloc_dma(np, s, n)
1113 #define m_free_dma(p, s, n) _m_free_dma(np, p, s, n)
1114 #define _vtobus(np, p) __vtobus(np->pdev, p)
1115 #define vtobus(p) _vtobus(np, p)
1118 * Deal with DMA mapping/unmapping.
1121 #ifndef SCSI_NCR_DYNAMIC_DMA_MAPPING
1123 /* Linux versions prior to pci bus iommu kernel interface */
1125 #define __unmap_scsi_data(pdev, cmd) do {; } while (0)
1126 #define __map_scsi_single_data(pdev, cmd) (__vtobus(pdev,(cmd)->request_buffer))
1127 #define __map_scsi_sg_data(pdev, cmd) ((cmd)->use_sg)
1128 #define __sync_scsi_data(pdev, cmd) do {; } while (0)
1130 #define scsi_sg_dma_address(sc) vtobus((sc)->address)
1131 #define scsi_sg_dma_len(sc) ((sc)->length)
1135 /* Linux version with pci bus iommu kernel interface */
1137 /* To keep track of the dma mapping (sg/single) that has been set */
1138 #define __data_mapped(cmd) (cmd)->SCp.phase
1139 #define __data_mapping(cmd) (cmd)->SCp.dma_handle
1141 static void __unmap_scsi_data(pcidev_t pdev
, Scsi_Cmnd
*cmd
)
1143 int dma_dir
= scsi_to_pci_dma_dir(cmd
->sc_data_direction
);
1145 switch(__data_mapped(cmd
)) {
1147 pci_unmap_sg(pdev
, cmd
->buffer
, cmd
->use_sg
, dma_dir
);
1150 pci_unmap_page(pdev
, __data_mapping(cmd
),
1151 cmd
->request_bufflen
, dma_dir
);
1154 __data_mapped(cmd
) = 0;
1157 static dma_addr_t
__map_scsi_single_data(pcidev_t pdev
, Scsi_Cmnd
*cmd
)
1160 int dma_dir
= scsi_to_pci_dma_dir(cmd
->sc_data_direction
);
1162 if (cmd
->request_bufflen
== 0)
1165 mapping
= pci_map_page(pdev
,
1166 virt_to_page(cmd
->request_buffer
),
1167 ((unsigned long)cmd
->request_buffer
&
1169 cmd
->request_bufflen
, dma_dir
);
1170 __data_mapped(cmd
) = 1;
1171 __data_mapping(cmd
) = mapping
;
1176 static int __map_scsi_sg_data(pcidev_t pdev
, Scsi_Cmnd
*cmd
)
1179 int dma_dir
= scsi_to_pci_dma_dir(cmd
->sc_data_direction
);
1181 if (cmd
->use_sg
== 0)
1184 use_sg
= pci_map_sg(pdev
, cmd
->buffer
, cmd
->use_sg
, dma_dir
);
1185 __data_mapped(cmd
) = 2;
1186 __data_mapping(cmd
) = use_sg
;
1191 static void __sync_scsi_data(pcidev_t pdev
, Scsi_Cmnd
*cmd
)
1193 int dma_dir
= scsi_to_pci_dma_dir(cmd
->sc_data_direction
);
1195 switch(__data_mapped(cmd
)) {
1197 pci_dma_sync_sg(pdev
, cmd
->buffer
, cmd
->use_sg
, dma_dir
);
1200 pci_dma_sync_single(pdev
, __data_mapping(cmd
),
1201 cmd
->request_bufflen
, dma_dir
);
1206 #define scsi_sg_dma_address(sc) sg_dma_address(sc)
1207 #define scsi_sg_dma_len(sc) sg_dma_len(sc)
1209 #endif /* SCSI_NCR_DYNAMIC_DMA_MAPPING */
1211 #define unmap_scsi_data(np, cmd) __unmap_scsi_data(np->pdev, cmd)
1212 #define map_scsi_single_data(np, cmd) __map_scsi_single_data(np->pdev, cmd)
1213 #define map_scsi_sg_data(np, cmd) __map_scsi_sg_data(np->pdev, cmd)
1214 #define sync_scsi_data(np, cmd) __sync_scsi_data(np->pdev, cmd)
1218 * Print out some buffer.
1220 static void ncr_print_hex(u_char
*p
, int n
)
1223 printk (" %x", *p
++);
1226 static void ncr_printl_hex(char *label
, u_char
*p
, int n
)
1228 printk("%s", label
);
1229 ncr_print_hex(p
, n
);
1234 ** Transfer direction
1236 ** Until some linux kernel version near 2.3.40, low-level scsi
1237 ** drivers were not told about data transfer direction.
1238 ** We check the existence of this feature that has been expected
1239 ** for a _long_ time by all SCSI driver developers by just
1240 ** testing against the definition of SCSI_DATA_UNKNOWN. Indeed
1241 ** this is a hack, but testing against a kernel version would
1242 ** have been a shame. ;-)
1244 #ifdef SCSI_DATA_UNKNOWN
1246 #define scsi_data_direction(cmd) (cmd->sc_data_direction)
1250 #define SCSI_DATA_UNKNOWN 0
1251 #define SCSI_DATA_WRITE 1
1252 #define SCSI_DATA_READ 2
1253 #define SCSI_DATA_NONE 3
1255 static __inline__
int scsi_data_direction(Scsi_Cmnd
*cmd
)
1259 switch((int) cmd
->cmnd
[0]) {
1260 case 0x08: /* READ(6) 08 */
1261 case 0x28: /* READ(10) 28 */
1262 case 0xA8: /* READ(12) A8 */
1263 direction
= SCSI_DATA_READ
;
1265 case 0x0A: /* WRITE(6) 0A */
1266 case 0x2A: /* WRITE(10) 2A */
1267 case 0xAA: /* WRITE(12) AA */
1268 direction
= SCSI_DATA_WRITE
;
1271 direction
= SCSI_DATA_UNKNOWN
;
1278 #endif /* SCSI_DATA_UNKNOWN */
1282 ** /proc directory entry and proc_info function
1284 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,27)
1285 static struct proc_dir_entry proc_scsi_sym53c8xx
= {
1286 PROC_SCSI_SYM53C8XX
, 9, NAME53C8XX
,
1287 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
1290 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
1291 static int sym53c8xx_proc_info(char *buffer
, char **start
, off_t offset
,
1292 int length
, int hostno
, int func
);
1298 ** This structure is initialized from linux config options.
1299 ** It can be overridden at boot-up by the boot command line.
1301 static struct ncr_driver_setup
1302 driver_setup
= SCSI_NCR_DRIVER_SETUP
;
1304 #ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
1305 static struct ncr_driver_setup
1306 driver_safe_setup __initdata
= SCSI_NCR_DRIVER_SAFE_SETUP
;
1308 char *sym53c8xx
= 0; /* command line passed by insmod */
1309 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,30)
1310 MODULE_PARM(sym53c8xx
, "s");
1316 ** Other Linux definitions
1318 #define SetScsiResult(cmd, h_sts, s_sts) \
1319 cmd->result = (((h_sts) << 16) + ((s_sts) & 0x7f))
1321 /* We may have to remind our amnesiac SCSI layer of the reason of the abort */
1323 #define SetScsiAbortResult(cmd) \
1326 (cmd)->abort_reason == DID_TIME_OUT ? DID_TIME_OUT : DID_ABORT, \
1329 #define SetScsiAbortResult(cmd) SetScsiResult(cmd, DID_ABORT, 0xff)
1332 static void sym53c8xx_intr(int irq
, void *dev_id
, struct pt_regs
* regs
);
1333 static void sym53c8xx_timeout(unsigned long np
);
1335 #define initverbose (driver_setup.verbose)
1336 #define bootverbose (np->verbose)
1338 #ifdef SCSI_NCR_NVRAM_SUPPORT
1339 static u_char Tekram_sync
[16] __initdata
=
1340 {25,31,37,43, 50,62,75,125, 12,15,18,21, 6,7,9,10};
1341 #endif /* SCSI_NCR_NVRAM_SUPPORT */
1344 ** Structures used by sym53c8xx_detect/sym53c8xx_pci_init to
1345 ** transmit device configuration to the ncr_attach() function.
1356 /* port and reg fields to use INB, OUTB macros */
1358 volatile struct ncr_reg
*reg
;
1363 #define SCSI_NCR_SYMBIOS_NVRAM (1)
1364 #define SCSI_NCR_TEKRAM_NVRAM (2)
1365 #ifdef SCSI_NCR_NVRAM_SUPPORT
1367 Symbios_nvram Symbios
;
1368 Tekram_nvram Tekram
;
1374 ** Structure used by sym53c8xx_detect/sym53c8xx_pci_init
1375 ** to save data on each detected board for ncr_attach().
1383 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
1389 /*==========================================================
1393 **==========================================================
1395 ** modified copy from 386bsd:/usr/include/sys/assert.h
1397 **----------------------------------------------------------
1400 #define assert(expression) { \
1401 if (!(expression)) { \
1403 "assertion \"%s\" failed: file \"%s\", line %d\n", \
1405 __FILE__, __LINE__); \
1409 /*==========================================================
1411 ** Command control block states.
1413 **==========================================================
1418 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
1419 #define HS_DISCONNECT (3) /* Disconnected by target */
1421 #define HS_DONEMASK (0x80)
1422 #define HS_COMPLETE (4|HS_DONEMASK)
1423 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
1424 #define HS_RESET (6|HS_DONEMASK) /* SCSI reset */
1425 #define HS_ABORTED (7|HS_DONEMASK) /* Transfer aborted */
1426 #define HS_TIMEOUT (8|HS_DONEMASK) /* Software timeout */
1427 #define HS_FAIL (9|HS_DONEMASK) /* SCSI or PCI bus errors */
1428 #define HS_UNEXPECTED (10|HS_DONEMASK)/* Unexpected disconnect */
1430 #define DSA_INVALID 0xffffffff
1432 /*==========================================================
1434 ** Software Interrupt Codes
1436 **==========================================================
1439 #define SIR_BAD_STATUS (1)
1440 #define SIR_SEL_ATN_NO_MSG_OUT (2)
1441 #define SIR_MSG_RECEIVED (3)
1442 #define SIR_MSG_WEIRD (4)
1443 #define SIR_NEGO_FAILED (5)
1444 #define SIR_NEGO_PROTO (6)
1445 #define SIR_SCRIPT_STOPPED (7)
1446 #define SIR_REJECT_TO_SEND (8)
1447 #define SIR_SWIDE_OVERRUN (9)
1448 #define SIR_SODL_UNDERRUN (10)
1449 #define SIR_RESEL_NO_MSG_IN (11)
1450 #define SIR_RESEL_NO_IDENTIFY (12)
1451 #define SIR_RESEL_BAD_LUN (13)
1452 #define SIR_TARGET_SELECTED (14)
1453 #define SIR_RESEL_BAD_I_T_L (15)
1454 #define SIR_RESEL_BAD_I_T_L_Q (16)
1455 #define SIR_ABORT_SENT (17)
1456 #define SIR_RESEL_ABORTED (18)
1457 #define SIR_MSG_OUT_DONE (19)
1458 #define SIR_AUTO_SENSE_DONE (20)
1459 #define SIR_DUMMY_INTERRUPT (21)
1460 #define SIR_DATA_OVERRUN (22)
1461 #define SIR_BAD_PHASE (23)
1462 #define SIR_MAX (23)
1464 /*==========================================================
1466 ** Extended error bits.
1467 ** xerr_status field of struct ccb.
1469 **==========================================================
1472 #define XE_EXTRA_DATA (1) /* unexpected data phase */
1473 #define XE_BAD_PHASE (2) /* illegal phase (4/5) */
1474 #define XE_PARITY_ERR (4) /* unrecovered SCSI parity error */
1475 #define XE_SODL_UNRUN (1<<3)
1476 #define XE_SWIDE_OVRUN (1<<4)
1478 /*==========================================================
1480 ** Negotiation status.
1481 ** nego_status field of struct ccb.
1483 **==========================================================
1486 #define NS_NOCHANGE (0)
1491 /*==========================================================
1493 ** "Special features" of targets.
1494 ** quirks field of struct tcb.
1495 ** actualquirks field of struct ccb.
1497 **==========================================================
1500 #define QUIRK_AUTOSAVE (0x01)
1502 /*==========================================================
1504 ** Capability bits in Inquire response byte 7.
1506 **==========================================================
1509 #define INQ7_QUEUE (0x02)
1510 #define INQ7_SYNC (0x10)
1511 #define INQ7_WIDE16 (0x20)
1513 /*==========================================================
1515 ** A CCB hashed table is used to retrieve CCB address
1518 **==========================================================
1521 #define CCB_HASH_SHIFT 8
1522 #define CCB_HASH_SIZE (1UL << CCB_HASH_SHIFT)
1523 #define CCB_HASH_MASK (CCB_HASH_SIZE-1)
1524 #define CCB_HASH_CODE(dsa) (((dsa) >> 11) & CCB_HASH_MASK)
1526 /*==========================================================
1528 ** Declaration of structs.
1530 **==========================================================
1539 typedef struct ncb
* ncb_p
;
1540 typedef struct tcb
* tcb_p
;
1541 typedef struct lcb
* lcb_p
;
1542 typedef struct ccb
* ccb_p
;
1556 #define UC_SETSYNC 10
1557 #define UC_SETTAGS 11
1558 #define UC_SETDEBUG 12
1559 #define UC_SETORDER 13
1560 #define UC_SETWIDE 14
1561 #define UC_SETFLAG 15
1562 #define UC_SETVERBOSE 17
1563 #define UC_RESETDEV 18
1564 #define UC_CLEARDEV 19
1566 #define UF_TRACE (0x01)
1567 #define UF_NODISC (0x02)
1568 #define UF_NOSCAN (0x04)
1570 /*========================================================================
1572 ** Declaration of structs: target control block
1574 **========================================================================
1577 /*----------------------------------------------------------------
1579 ** An array of bus addresses is used on reselection by
1581 **----------------------------------------------------------------
1583 u_int32
*luntbl
; /* lcbs bus address table */
1584 u_int32 b_luntbl
; /* bus address of this table */
1585 u_int32 b_lun0
; /* bus address of lun0 */
1586 lcb_p l0p
; /* lcb of LUN #0 (normal case) */
1588 lcb_p
*lmp
; /* Other lcb's [1..MAX_LUN] */
1590 /*----------------------------------------------------------------
1591 ** Target capabilities.
1592 **----------------------------------------------------------------
1594 u_char inq_done
; /* Target capabilities received */
1595 u_char inq_byte7
; /* Contains these capabilities */
1597 /*----------------------------------------------------------------
1599 **----------------------------------------------------------------
1601 u_char to_reset
; /* This target is to be reset */
1603 /*----------------------------------------------------------------
1604 ** Pointer to the ccb used for negotiation.
1605 ** Prevent from starting a negotiation for all queued commands
1606 ** when tagged command queuing is enabled.
1607 **----------------------------------------------------------------
1611 /*----------------------------------------------------------------
1612 ** negotiation of wide and synch transfer and device quirks.
1613 ** sval, wval and uval are read from SCRIPTS and so have alignment
1615 **----------------------------------------------------------------
1619 /*2*/ u_char filler2
;
1627 #ifdef SCSI_NCR_INTEGRITY_CHECKING
1629 u_char ic_max_width
;
1632 u_char ic_maximums_set
;
1633 u_char ppr_negotiation
;
1635 /*----------------------------------------------------------------
1636 ** User settable limits and options.
1637 ** These limits are read from the NVRAM if present.
1638 **----------------------------------------------------------------
1646 /*========================================================================
1648 ** Declaration of structs: lun control block
1650 **========================================================================
1653 /*----------------------------------------------------------------
1654 ** On reselection, SCRIPTS use this value as a JUMP address
1655 ** after the IDENTIFY has been successfully received.
1656 ** This field is set to 'resel_tag' if TCQ is enabled and
1657 ** to 'resel_notag' if TCQ is disabled.
1658 ** (Must be at zero due to bad lun handling on reselection)
1659 **----------------------------------------------------------------
1661 /*0*/ u_int32 resel_task
;
1663 /*----------------------------------------------------------------
1664 ** Task table used by the script processor to retrieve the
1665 ** task corresponding to a reselected nexus. The TAG is used
1666 ** as offset to determine the corresponding entry.
1667 ** Each entry contains the associated CCB bus address.
1668 **----------------------------------------------------------------
1670 u_int32 tasktbl_0
; /* Used if TCQ not enabled */
1674 /*----------------------------------------------------------------
1675 ** CCB queue management.
1676 **----------------------------------------------------------------
1678 XPT_QUEHEAD busy_ccbq
; /* Queue of busy CCBs */
1679 XPT_QUEHEAD wait_ccbq
; /* Queue of waiting for IO CCBs */
1680 u_short busyccbs
; /* CCBs busy for this lun */
1681 u_short queuedccbs
; /* CCBs queued to the controller*/
1682 u_short queuedepth
; /* Queue depth for this lun */
1683 u_short scdev_depth
; /* SCSI device queue depth */
1684 u_short maxnxs
; /* Max possible nexuses */
1686 /*----------------------------------------------------------------
1687 ** Control of tagged command queuing.
1688 ** Tags allocation is performed using a circular buffer.
1689 ** This avoids using a loop for tag allocation.
1690 **----------------------------------------------------------------
1692 u_short ia_tag
; /* Tag allocation index */
1693 u_short if_tag
; /* Tag release index */
1694 u_char
*cb_tags
; /* Circular tags buffer */
1695 u_char inq_byte7
; /* Store unit CmdQ capability */
1696 u_char usetags
; /* Command queuing is active */
1697 u_char to_clear
; /* User wants to clear all tasks*/
1698 u_short maxtags
; /* Max NR of tags asked by user */
1699 u_short numtags
; /* Current number of tags */
1701 /*----------------------------------------------------------------
1702 ** QUEUE FULL and ORDERED tag control.
1703 **----------------------------------------------------------------
1705 u_short num_good
; /* Nr of GOOD since QUEUE FULL */
1706 u_short tags_sum
[2]; /* Tags sum counters */
1707 u_char tags_si
; /* Current index to tags sum */
1708 u_long tags_stime
; /* Last time we switch tags_sum */
1711 /*========================================================================
1713 ** Declaration of structs: actions for a task.
1715 **========================================================================
1717 ** It is part of the CCB and is called by the scripts processor to
1718 ** start or restart the data structure (nexus).
1720 **------------------------------------------------------------------------
1727 /*========================================================================
1729 ** Declaration of structs: Phase mismatch context.
1731 **========================================================================
1733 ** It is part of the CCB and is used as parameters for the DATA
1734 ** pointer. We need two contexts to handle correctly the SAVED
1737 **------------------------------------------------------------------------
1740 struct scr_tblmove sg
; /* Updated interrupted SG block */
1741 u_int32 ret
; /* SCRIPT return address */
1744 /*========================================================================
1746 ** Declaration of structs: global HEADER.
1748 **========================================================================
1750 ** In earlier driver versions, this substructure was copied from the
1751 ** ccb to a global address after selection (or reselection) and copied
1752 ** back before disconnect. Since we are now using LOAD/STORE DSA
1753 ** RELATIVE instructions, the script is able to access directly these
1754 ** fields, and so, this header is no more copied.
1756 **------------------------------------------------------------------------
1760 /*----------------------------------------------------------------
1761 ** Start and restart SCRIPTS addresses (must be at 0).
1762 **----------------------------------------------------------------
1766 /*----------------------------------------------------------------
1767 ** Saved data pointer.
1768 ** Points to the position in the script responsible for the
1769 ** actual transfer of data.
1770 ** It's written after reception of a SAVE_DATA_POINTER message.
1771 ** The goalpointer points after the last transfer command.
1772 **----------------------------------------------------------------
1778 /*----------------------------------------------------------------
1779 ** Alternate data pointer.
1780 ** They are copied back to savep/lastp/goalp by the SCRIPTS
1781 ** when the direction is unknown and the device claims data out.
1782 **----------------------------------------------------------------
1787 /*----------------------------------------------------------------
1789 **----------------------------------------------------------------
1791 u_char status
[4]; /* host status */
1795 ** LUN control block lookup.
1796 ** We use a direct pointer for LUN #0, and a table of pointers
1797 ** which is only allocated for devices that support LUN(s) > 0.
1800 #define ncr_lp(np, tp, lun) (!lun) ? (tp)->l0p : 0
1802 #define ncr_lp(np, tp, lun) \
1803 (!lun) ? (tp)->l0p : (tp)->lmp ? (tp)->lmp[(lun)] : 0
1807 ** The status bytes are used by the host and the script processor.
1809 ** The four bytes (status[4]) are copied to the scratchb register
1810 ** (declared as scr0..scr3 in ncr_reg.h) just after the select/reselect,
1811 ** and copied back just after disconnecting.
1812 ** Inside the script the XX_REG are used.
1816 ** Last four bytes (script)
1820 #define HS_PRT nc_scr1
1822 #define SS_PRT nc_scr2
1824 #define HF_PRT nc_scr3
1827 ** Last four bytes (host)
1829 #define actualquirks phys.header.status[0]
1830 #define host_status phys.header.status[1]
1831 #define scsi_status phys.header.status[2]
1832 #define host_flags phys.header.status[3]
1837 #define HF_IN_PM0 1u
1838 #define HF_IN_PM1 (1u<<1)
1839 #define HF_ACT_PM (1u<<2)
1840 #define HF_DP_SAVED (1u<<3)
1841 #define HF_AUTO_SENSE (1u<<4)
1842 #define HF_DATA_IN (1u<<5)
1843 #define HF_PM_TO_C (1u<<6)
1844 #define HF_EXT_ERR (1u<<7)
1846 #ifdef SCSI_NCR_IARB_SUPPORT
1847 #define HF_HINT_IARB (1u<<7)
1851 ** This one is stolen from QU_REG.:)
1853 #define HF_DATA_ST (1u<<7)
1855 /*==========================================================
1857 ** Declaration of structs: Data structure block
1859 **==========================================================
1861 ** During execution of a ccb by the script processor,
1862 ** the DSA (data structure address) register points
1863 ** to this substructure of the ccb.
1864 ** This substructure contains the header with
1865 ** the script-processor-changable data and
1866 ** data blocks for the indirect move commands.
1868 **----------------------------------------------------------
1880 ** Table data for Script
1883 struct scr_tblsel select
;
1884 struct scr_tblmove smsg
;
1885 struct scr_tblmove smsg_ext
;
1886 struct scr_tblmove cmd
;
1887 struct scr_tblmove sense
;
1888 struct scr_tblmove wresid
;
1889 struct scr_tblmove data
[MAX_SCATTER
];
1892 ** Phase mismatch contexts.
1893 ** We need two to handle correctly the
1894 ** SAVED DATA POINTER.
1902 /*========================================================================
1904 ** Declaration of structs: Command control block.
1906 **========================================================================
1909 /*----------------------------------------------------------------
1910 ** This is the data structure which is pointed by the DSA
1911 ** register when it is executed by the script processor.
1912 ** It must be the first entry.
1913 **----------------------------------------------------------------
1917 /*----------------------------------------------------------------
1918 ** The general SCSI driver provides a
1919 ** pointer to a control block.
1920 **----------------------------------------------------------------
1922 Scsi_Cmnd
*cmd
; /* SCSI command */
1923 u_char cdb_buf
[16]; /* Copy of CDB */
1924 u_char sense_buf
[64];
1925 int data_len
; /* Total data length */
1926 int segments
; /* Number of SG segments */
1928 /*----------------------------------------------------------------
1930 ** We prepare a message to be sent after selection.
1931 ** We may use a second one if the command is rescheduled
1932 ** due to CHECK_CONDITION or QUEUE FULL status.
1933 ** Contents are IDENTIFY and SIMPLE_TAG.
1934 ** While negotiating sync or wide transfer,
1935 ** a SDTR or WDTR message is appended.
1936 **----------------------------------------------------------------
1938 u_char scsi_smsg
[12];
1939 u_char scsi_smsg2
[12];
1941 /*----------------------------------------------------------------
1942 ** Miscellaneous status'.
1943 **----------------------------------------------------------------
1945 u_char nego_status
; /* Negotiation status */
1946 u_char xerr_status
; /* Extended error flags */
1947 u_int32 extra_bytes
; /* Extraneous bytes transferred */
1949 /*----------------------------------------------------------------
1950 ** Saved info for auto-sense
1951 **----------------------------------------------------------------
1953 u_char sv_scsi_status
;
1954 u_char sv_xerr_status
;
1956 /*----------------------------------------------------------------
1958 **----------------------------------------------------------------
1960 u_long p_ccb
; /* BUS address of this CCB */
1961 u_char sensecmd
[6]; /* Sense command */
1962 u_char to_abort
; /* This CCB is to be aborted */
1963 u_short tag
; /* Tag for this transfer */
1964 /* NO_TAG means no tag */
1965 u_char tags_si
; /* Lun tags sum index (0,1) */
1970 ccb_p link_ccb
; /* Host adapter CCB chain */
1971 ccb_p link_ccbh
; /* Host adapter CCB hash chain */
1972 XPT_QUEHEAD link_ccbq
; /* Link to unit CCB queue */
1973 u_int32 startp
; /* Initial data pointer */
1974 u_int32 lastp0
; /* Initial 'lastp' */
1975 int ext_sg
; /* Extreme data pointer, used */
1976 int ext_ofs
; /* to calculate the residual. */
1980 #define CCB_PHYS(cp,lbl) (cp->p_ccb + offsetof(struct ccb, lbl))
1983 /*========================================================================
1985 ** Declaration of structs: NCR device descriptor
1987 **========================================================================
1990 /*----------------------------------------------------------------
1991 ** Idle task and invalid task actions and their bus
1993 **----------------------------------------------------------------
1995 struct action idletask
;
1996 struct action notask
;
1997 struct action bad_i_t_l
;
1998 struct action bad_i_t_l_q
;
2002 u_long p_bad_i_t_l_q
;
2004 /*----------------------------------------------------------------
2005 ** Dummy lun table to protect us against target returning bad
2006 ** lun number on reselection.
2007 **----------------------------------------------------------------
2009 u_int32
*badluntbl
; /* Table physical address */
2010 u_int32 resel_badlun
; /* SCRIPT handler BUS address */
2012 /*----------------------------------------------------------------
2013 ** Bit 32-63 of the on-chip RAM bus address in LE format.
2014 ** The START_RAM64 script loads the MMRS and MMWS from this
2016 **----------------------------------------------------------------
2018 u_int32 scr_ram_seg
;
2020 /*----------------------------------------------------------------
2021 ** CCBs management queues.
2022 **----------------------------------------------------------------
2024 Scsi_Cmnd
*waiting_list
; /* Commands waiting for a CCB */
2025 /* when lcb is not allocated. */
2026 Scsi_Cmnd
*done_list
; /* Commands waiting for done() */
2027 /* callback to be invoked. */
2028 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
2029 spinlock_t smp_lock
; /* Lock for SMP threading */
2032 /*----------------------------------------------------------------
2033 ** Chip and controller indentification.
2034 **----------------------------------------------------------------
2036 int unit
; /* Unit number */
2037 char chip_name
[8]; /* Chip name */
2038 char inst_name
[16]; /* ncb instance name */
2040 /*----------------------------------------------------------------
2041 ** Initial value of some IO register bits.
2042 ** These values are assumed to have been set by BIOS, and may
2043 ** be used for probing adapter implementation differences.
2044 **----------------------------------------------------------------
2046 u_char sv_scntl0
, sv_scntl3
, sv_dmode
, sv_dcntl
, sv_ctest3
, sv_ctest4
,
2047 sv_ctest5
, sv_gpcntl
, sv_stest2
, sv_stest4
, sv_stest1
, sv_scntl4
;
2049 /*----------------------------------------------------------------
2050 ** Actual initial value of IO register bits used by the
2051 ** driver. They are loaded at initialisation according to
2052 ** features that are to be enabled.
2053 **----------------------------------------------------------------
2055 u_char rv_scntl0
, rv_scntl3
, rv_dmode
, rv_dcntl
, rv_ctest3
, rv_ctest4
,
2056 rv_ctest5
, rv_stest2
, rv_ccntl0
, rv_ccntl1
, rv_scntl4
;
2058 /*----------------------------------------------------------------
2060 ** Target control block bus address array used by the SCRIPT
2062 **----------------------------------------------------------------
2064 struct tcb target
[MAX_TARGET
];
2067 /*----------------------------------------------------------------
2068 ** Virtual and physical bus addresses of the chip.
2069 **----------------------------------------------------------------
2071 #ifndef SCSI_NCR_PCI_MEM_NOT_SUPPORTED
2072 u_long base_va
; /* MMIO base virtual address */
2073 u_long base2_va
; /* On-chip RAM virtual address */
2075 u_long base_ba
; /* MMIO base bus address */
2076 u_long base_io
; /* IO space base address */
2077 u_long base_ws
; /* (MM)IO window size */
2078 u_long base2_ba
; /* On-chip RAM bus address */
2079 u_long base2_ws
; /* On-chip RAM window size */
2080 u_int irq
; /* IRQ number */
2081 volatile /* Pointer to volatile for */
2082 struct ncr_reg
*reg
; /* memory mapped IO. */
2084 /*----------------------------------------------------------------
2085 ** SCRIPTS virtual and physical bus addresses.
2086 ** 'script' is loaded in the on-chip RAM if present.
2087 ** 'scripth' stays in main memory for all chips except the
2088 ** 53C895A and 53C896 that provide 8K on-chip RAM.
2089 **----------------------------------------------------------------
2091 struct script
*script0
; /* Copies of script and scripth */
2092 struct scripth
*scripth0
; /* relocated for this ncb. */
2093 u_long p_script
; /* Actual script and scripth */
2094 u_long p_scripth
; /* bus addresses. */
2097 /*----------------------------------------------------------------
2098 ** General controller parameters and configuration.
2099 **----------------------------------------------------------------
2102 u_short device_id
; /* PCI device id */
2103 u_char revision_id
; /* PCI device revision id */
2104 u_char bus
; /* PCI BUS number */
2105 u_char device_fn
; /* PCI BUS device and function */
2106 u_char myaddr
; /* SCSI id of the adapter */
2107 u_char maxburst
; /* log base 2 of dwords burst */
2108 u_char maxwide
; /* Maximum transfer width */
2109 u_char minsync
; /* Minimum sync period factor */
2110 u_char maxsync
; /* Maximum sync period factor */
2111 u_char maxoffs
; /* Max scsi offset */
2112 u_char maxoffs_st
; /* Max scsi offset in ST mode */
2113 u_char multiplier
; /* Clock multiplier (1,2,4) */
2114 u_char clock_divn
; /* Number of clock divisors */
2115 u_long clock_khz
; /* SCSI clock frequency in KHz */
2116 u_int features
; /* Chip features map */
2118 /*----------------------------------------------------------------
2119 ** Range for the PCI clock frequency measurement result
2120 ** that ensures the algorithm used by the driver can be
2121 ** trusted for the SCSI clock frequency measurement.
2122 ** (Assuming a PCI clock frequency of 33 MHz).
2123 **----------------------------------------------------------------
2128 /*----------------------------------------------------------------
2129 ** Start queue management.
2130 ** It is filled up by the host processor and accessed by the
2131 ** SCRIPTS processor in order to start SCSI commands.
2132 **----------------------------------------------------------------
2134 u_long p_squeue
; /* Start queue BUS address */
2135 u_int32
*squeue
; /* Start queue virtual address */
2136 u_short squeueput
; /* Next free slot of the queue */
2137 u_short actccbs
; /* Number of allocated CCBs */
2138 u_short queuedepth
; /* Start queue depth */
2140 /*----------------------------------------------------------------
2141 ** Command completion queue.
2142 ** It is the same size as the start queue to avoid overflow.
2143 **----------------------------------------------------------------
2145 u_short dqueueget
; /* Next position to scan */
2146 u_int32
*dqueue
; /* Completion (done) queue */
2148 /*----------------------------------------------------------------
2150 **----------------------------------------------------------------
2152 struct timer_list timer
; /* Timer handler link header */
2154 u_long settle_time
; /* Resetting the SCSI BUS */
2156 /*----------------------------------------------------------------
2157 ** Debugging and profiling.
2158 **----------------------------------------------------------------
2160 struct ncr_reg regdump
; /* Register dump */
2161 u_long regtime
; /* Time it has been done */
2163 /*----------------------------------------------------------------
2164 ** Miscellaneous buffers accessed by the scripts-processor.
2165 ** They shall be DWORD aligned, because they may be read or
2166 ** written with a script command.
2167 **----------------------------------------------------------------
2169 u_char msgout
[12]; /* Buffer for MESSAGE OUT */
2170 u_char msgin
[12]; /* Buffer for MESSAGE IN */
2171 u_int32 lastmsg
; /* Last SCSI message sent */
2172 u_char scratch
; /* Scratch for SCSI receive */
2174 /*----------------------------------------------------------------
2175 ** Miscellaneous configuration and status parameters.
2176 **----------------------------------------------------------------
2178 u_char scsi_mode
; /* Current SCSI BUS mode */
2179 u_char order
; /* Tag order to use */
2180 u_char verbose
; /* Verbosity for this controller*/
2181 u_int32 ncr_cache
; /* Used for cache test at init. */
2182 u_long p_ncb
; /* BUS address of this NCB */
2184 /*----------------------------------------------------------------
2185 ** CCB lists and queue.
2186 **----------------------------------------------------------------
2188 ccb_p ccbh
[CCB_HASH_SIZE
]; /* CCB hashed by DSA value */
2189 struct ccb
*ccbc
; /* CCB chain */
2190 XPT_QUEHEAD free_ccbq
; /* Queue of available CCBs */
2192 /*----------------------------------------------------------------
2193 ** IMMEDIATE ARBITRATION (IARB) control.
2194 ** We keep track in 'last_cp' of the last CCB that has been
2195 ** queued to the SCRIPTS processor and clear 'last_cp' when
2196 ** this CCB completes. If last_cp is not zero at the moment
2197 ** we queue a new CCB, we set a flag in 'last_cp' that is
2198 ** used by the SCRIPTS as a hint for setting IARB.
2199 ** We donnot set more than 'iarb_max' consecutive hints for
2200 ** IARB in order to leave devices a chance to reselect.
2201 ** By the way, any non zero value of 'iarb_max' is unfair. :)
2202 **----------------------------------------------------------------
2204 #ifdef SCSI_NCR_IARB_SUPPORT
2205 struct ccb
*last_cp
; /* Last queud CCB used for IARB */
2206 u_short iarb_max
; /* Max. # consecutive IARB hints*/
2207 u_short iarb_count
; /* Actual # of these hints */
2210 /*----------------------------------------------------------------
2211 ** We need the LCB in order to handle disconnections and
2212 ** to count active CCBs for task management. So, we use
2213 ** a unique CCB for LUNs we donnot have the LCB yet.
2214 ** This queue normally should have at most 1 element.
2215 **----------------------------------------------------------------
2217 XPT_QUEHEAD b0_ccbq
;
2219 /*----------------------------------------------------------------
2220 ** We use a different scatter function for 896 rev 1.
2221 **----------------------------------------------------------------
2223 int (*scatter
) (ncb_p
, ccb_p
, Scsi_Cmnd
*);
2225 /*----------------------------------------------------------------
2226 ** Command abort handling.
2227 ** We need to synchronize tightly with the SCRIPTS
2228 ** processor in order to handle things correctly.
2229 **----------------------------------------------------------------
2231 u_char abrt_msg
[4]; /* Message to send buffer */
2232 struct scr_tblmove abrt_tbl
; /* Table for the MOV of it */
2233 struct scr_tblsel abrt_sel
; /* Sync params for selection */
2234 u_char istat_sem
; /* Tells the chip to stop (SEM) */
2236 /*----------------------------------------------------------------
2237 ** Fields that should be removed or changed.
2238 **----------------------------------------------------------------
2240 struct usrcmd user
; /* Command from user */
2241 volatile u_char release_stage
; /* Synchronisation stage on release */
2243 /*----------------------------------------------------------------
2244 ** Fields that are used (primarily) for integrity check
2245 **----------------------------------------------------------------
2247 unsigned char check_integrity
; /* Enable midlayer integ. check on
2249 #ifdef SCSI_NCR_INTEGRITY_CHECKING
2250 unsigned char check_integ_par
; /* Set if par or Init. Det. error
2251 * used only during integ check */
2255 #define NCB_PHYS(np, lbl) (np->p_ncb + offsetof(struct ncb, lbl))
2256 #define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
2257 #define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
2258 #define NCB_SCRIPTH0_PHYS(np,lbl) (np->p_scripth0+offsetof (struct scripth,lbl))
2260 /*==========================================================
2263 ** Script for NCR-Processor.
2265 ** Use ncr_script_fill() to create the variable parts.
2266 ** Use ncr_script_copy_and_bind() to make a copy and
2267 ** bind to physical addresses.
2270 **==========================================================
2272 ** We have to know the offsets of all labels before
2273 ** we reach them (for forward jumps).
2274 ** Therefore we declare a struct here.
2275 ** If you make changes inside the script,
2276 ** DONT FORGET TO CHANGE THE LENGTHS HERE!
2278 **----------------------------------------------------------
2282 ** Script fragments which are loaded into the on-chip RAM
2283 ** of 825A, 875, 876, 895, 895A and 896 chips.
2287 ncrcmd getjob_begin
[ 4];
2288 ncrcmd getjob_end
[ 4];
2290 ncrcmd wf_sel_done
[ 2];
2291 ncrcmd send_ident
[ 2];
2292 #ifdef SCSI_NCR_IARB_SUPPORT
2293 ncrcmd select2
[ 8];
2295 ncrcmd select2
[ 2];
2297 ncrcmd command
[ 2];
2298 ncrcmd dispatch
[ 28];
2299 ncrcmd sel_no_cmd
[ 10];
2302 ncrcmd disp_status
[ 4];
2303 ncrcmd datai_done
[ 26];
2304 ncrcmd datao_done
[ 12];
2305 ncrcmd ign_i_w_r_msg
[ 4];
2306 ncrcmd datai_phase
[ 2];
2307 ncrcmd datao_phase
[ 4];
2309 ncrcmd msg_in2
[ 10];
2310 #ifdef SCSI_NCR_IARB_SUPPORT
2311 ncrcmd status
[ 14];
2313 ncrcmd status
[ 10];
2315 ncrcmd complete
[ 8];
2316 #ifdef SCSI_NCR_PCIQ_MAY_REORDER_WRITES
2317 ncrcmd complete2
[ 12];
2319 ncrcmd complete2
[ 10];
2321 #ifdef SCSI_NCR_PCIQ_SYNC_ON_INTR
2326 ncrcmd done_end
[ 2];
2327 ncrcmd save_dp
[ 8];
2328 ncrcmd restore_dp
[ 4];
2329 ncrcmd disconnect
[ 20];
2330 #ifdef SCSI_NCR_IARB_SUPPORT
2335 #ifdef SCSI_NCR_IARB_SUPPORT
2336 ncrcmd ungetjob
[ 6];
2338 ncrcmd ungetjob
[ 4];
2340 ncrcmd reselect
[ 4];
2341 ncrcmd reselected
[ 20];
2342 ncrcmd resel_scntl4
[ 30];
2343 #if MAX_TASKS*4 > 512
2344 ncrcmd resel_tag
[ 18];
2345 #elif MAX_TASKS*4 > 256
2346 ncrcmd resel_tag
[ 12];
2348 ncrcmd resel_tag
[ 8];
2350 ncrcmd resel_go
[ 6];
2351 ncrcmd resel_notag
[ 2];
2352 ncrcmd resel_dsa
[ 8];
2353 ncrcmd data_in
[MAX_SCATTER
* SCR_SG_SIZE
];
2354 ncrcmd data_in2
[ 4];
2355 ncrcmd data_out
[MAX_SCATTER
* SCR_SG_SIZE
];
2356 ncrcmd data_out2
[ 4];
2357 ncrcmd pm0_data
[ 12];
2358 ncrcmd pm0_data_out
[ 6];
2359 ncrcmd pm0_data_end
[ 6];
2360 ncrcmd pm1_data
[ 12];
2361 ncrcmd pm1_data_out
[ 6];
2362 ncrcmd pm1_data_end
[ 6];
2366 ** Script fragments which stay in main memory for all chips
2367 ** except for the 895A and 896 that support 8K on-chip RAM.
2370 ncrcmd start64
[ 2];
2371 ncrcmd no_data
[ 2];
2372 ncrcmd sel_for_abort
[ 18];
2373 ncrcmd sel_for_abort_1
[ 2];
2374 ncrcmd select_no_atn
[ 8];
2375 ncrcmd wf_sel_done_no_atn
[ 4];
2377 ncrcmd msg_in_etc
[ 14];
2378 ncrcmd msg_received
[ 4];
2379 ncrcmd msg_weird_seen
[ 4];
2380 ncrcmd msg_extended
[ 20];
2381 ncrcmd msg_bad
[ 6];
2382 ncrcmd msg_weird
[ 4];
2383 ncrcmd msg_weird1
[ 8];
2385 ncrcmd wdtr_resp
[ 6];
2386 ncrcmd send_wdtr
[ 4];
2387 ncrcmd sdtr_resp
[ 6];
2388 ncrcmd send_sdtr
[ 4];
2389 ncrcmd ppr_resp
[ 6];
2390 ncrcmd send_ppr
[ 4];
2391 ncrcmd nego_bad_phase
[ 4];
2392 ncrcmd msg_out
[ 4];
2393 ncrcmd msg_out_done
[ 4];
2394 ncrcmd data_ovrun
[ 2];
2395 ncrcmd data_ovrun1
[ 22];
2396 ncrcmd data_ovrun2
[ 8];
2397 ncrcmd abort_resel
[ 16];
2398 ncrcmd resend_ident
[ 4];
2399 ncrcmd ident_break
[ 4];
2400 ncrcmd ident_break_atn
[ 4];
2401 ncrcmd sdata_in
[ 6];
2402 ncrcmd data_io
[ 2];
2403 ncrcmd data_io_com
[ 8];
2404 ncrcmd data_io_out
[ 12];
2405 ncrcmd resel_bad_lun
[ 4];
2406 ncrcmd bad_i_t_l
[ 4];
2407 ncrcmd bad_i_t_l_q
[ 4];
2408 ncrcmd bad_status
[ 6];
2409 ncrcmd tweak_pmj
[ 12];
2410 ncrcmd pm_handle
[ 20];
2411 ncrcmd pm_handle1
[ 4];
2412 ncrcmd pm_save
[ 4];
2413 ncrcmd pm0_save
[ 14];
2414 ncrcmd pm1_save
[ 14];
2417 #ifdef SYM_DEBUG_PM_WITH_WSR
2418 ncrcmd pm_wsr_handle
[ 44];
2420 ncrcmd pm_wsr_handle
[ 42];
2422 ncrcmd wsr_ma_helper
[ 4];
2426 ncrcmd scratch
[ 1];
2427 ncrcmd scratch1
[ 1];
2428 ncrcmd pm0_data_addr
[ 1];
2429 ncrcmd pm1_data_addr
[ 1];
2430 ncrcmd saved_dsa
[ 1];
2431 ncrcmd saved_drs
[ 1];
2432 ncrcmd done_pos
[ 1];
2433 ncrcmd startpos
[ 1];
2434 ncrcmd targtbl
[ 1];
2435 /* End of data area */
2437 #ifdef SCSI_NCR_PCI_MEM_NOT_SUPPORTED
2438 ncrcmd start_ram
[ 1];
2439 ncrcmd script0_ba
[ 4];
2440 ncrcmd start_ram64
[ 3];
2441 ncrcmd script0_ba64
[ 3];
2442 ncrcmd scripth0_ba64
[ 6];
2443 ncrcmd ram_seg64
[ 1];
2445 ncrcmd snooptest
[ 6];
2446 ncrcmd snoopend
[ 2];
2449 /*==========================================================
2452 ** Function headers.
2455 **==========================================================
2458 static ccb_p
ncr_alloc_ccb (ncb_p np
);
2459 static void ncr_complete (ncb_p np
, ccb_p cp
);
2460 static void ncr_exception (ncb_p np
);
2461 static void ncr_free_ccb (ncb_p np
, ccb_p cp
);
2462 static ccb_p
ncr_ccb_from_dsa(ncb_p np
, u_long dsa
);
2463 static void ncr_init_tcb (ncb_p np
, u_char tn
);
2464 static lcb_p
ncr_alloc_lcb (ncb_p np
, u_char tn
, u_char ln
);
2465 static lcb_p
ncr_setup_lcb (ncb_p np
, u_char tn
, u_char ln
,
2467 static void ncr_getclock (ncb_p np
, int mult
);
2468 static u_int
ncr_getpciclock (ncb_p np
);
2469 static void ncr_selectclock (ncb_p np
, u_char scntl3
);
2470 static ccb_p
ncr_get_ccb (ncb_p np
, u_char tn
, u_char ln
);
2471 static void ncr_init (ncb_p np
, int reset
, char * msg
, u_long code
);
2472 static void ncr_int_sbmc (ncb_p np
);
2473 static void ncr_int_par (ncb_p np
, u_short sist
);
2474 static void ncr_int_ma (ncb_p np
);
2475 static void ncr_int_sir (ncb_p np
);
2476 static void ncr_int_sto (ncb_p np
);
2477 static void ncr_int_udc (ncb_p np
);
2478 static void ncr_negotiate (ncb_p np
, tcb_p tp
);
2479 static int ncr_prepare_nego(ncb_p np
, ccb_p cp
, u_char
*msgptr
);
2480 #ifdef SCSI_NCR_INTEGRITY_CHECKING
2481 static int ncr_ic_nego(ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
, u_char
*msgptr
);
2483 static void ncr_script_copy_and_bind
2484 (ncb_p np
, ncrcmd
*src
, ncrcmd
*dst
, int len
);
2485 static void ncr_script_fill (struct script
* scr
, struct scripth
* scripth
);
2486 static int ncr_scatter_896R1 (ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
);
2487 static int ncr_scatter (ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
);
2488 static void ncr_getsync (ncb_p np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
);
2489 static void ncr_get_xfer_info(ncb_p np
, tcb_p tp
, u_char
*factor
, u_char
*offset
, u_char
*width
);
2490 static void ncr_setsync (ncb_p np
, ccb_p cp
, u_char scntl3
, u_char sxfer
, u_char scntl4
);
2491 static void ncr_set_sync_wide_status (ncb_p np
, u_char target
);
2492 static void ncr_setup_tags (ncb_p np
, u_char tn
, u_char ln
);
2493 static void ncr_setwide (ncb_p np
, ccb_p cp
, u_char wide
, u_char ack
);
2494 static void ncr_setsyncwide (ncb_p np
, ccb_p cp
, u_char scntl3
, u_char sxfer
, u_char scntl4
, u_char wide
);
2495 static int ncr_show_msg (u_char
* msg
);
2496 static void ncr_print_msg (ccb_p cp
, char *label
, u_char
* msg
);
2497 static int ncr_snooptest (ncb_p np
);
2498 static void ncr_timeout (ncb_p np
);
2499 static void ncr_wakeup (ncb_p np
, u_long code
);
2500 static int ncr_wakeup_done (ncb_p np
);
2501 static void ncr_start_next_ccb (ncb_p np
, lcb_p lp
, int maxn
);
2502 static void ncr_put_start_queue(ncb_p np
, ccb_p cp
);
2503 static void ncr_chip_reset (ncb_p np
);
2504 static void ncr_soft_reset (ncb_p np
);
2505 static void ncr_start_reset (ncb_p np
);
2506 static int ncr_reset_scsi_bus (ncb_p np
, int enab_int
, int settle_delay
);
2507 static int ncr_compute_residual (ncb_p np
, ccb_p cp
);
2509 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
2510 static void ncr_usercmd (ncb_p np
);
2513 static int ncr_attach (Scsi_Host_Template
*tpnt
, int unit
, ncr_device
*device
);
2514 static void ncr_free_resources(ncb_p np
);
2516 static void insert_into_waiting_list(ncb_p np
, Scsi_Cmnd
*cmd
);
2517 static Scsi_Cmnd
*retrieve_from_waiting_list(int to_remove
, ncb_p np
, Scsi_Cmnd
*cmd
);
2518 static void process_waiting_list(ncb_p np
, int sts
);
2520 #define remove_from_waiting_list(np, cmd) \
2521 retrieve_from_waiting_list(1, (np), (cmd))
2522 #define requeue_waiting_list(np) process_waiting_list((np), DID_OK)
2523 #define reset_waiting_list(np) process_waiting_list((np), DID_RESET)
2525 #ifdef SCSI_NCR_NVRAM_SUPPORT
2526 static void ncr_get_nvram (ncr_device
*devp
, ncr_nvram
*nvp
);
2527 static int sym_read_Tekram_nvram (ncr_slot
*np
, u_short device_id
,
2528 Tekram_nvram
*nvram
);
2529 static int sym_read_Symbios_nvram (ncr_slot
*np
, Symbios_nvram
*nvram
);
2532 /*==========================================================
2535 ** Global static data.
2538 **==========================================================
2541 static inline char *ncr_name (ncb_p np
)
2543 return np
->inst_name
;
2547 /*==========================================================
2550 ** Scripts for NCR-Processor.
2552 ** Use ncr_script_bind for binding to physical addresses.
2555 **==========================================================
2557 ** NADDR generates a reference to a field of the controller data.
2558 ** PADDR generates a reference to another part of the script.
2559 ** RADDR generates a reference to a script processor register.
2560 ** FADDR generates a reference to a script processor register
2563 **----------------------------------------------------------
2566 #define RELOC_SOFTC 0x40000000
2567 #define RELOC_LABEL 0x50000000
2568 #define RELOC_REGISTER 0x60000000
2570 #define RELOC_KVAR 0x70000000
2572 #define RELOC_LABELH 0x80000000
2573 #define RELOC_MASK 0xf0000000
2575 #define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
2576 #define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
2577 #define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
2578 #define RADDR(label) (RELOC_REGISTER | REG(label))
2579 #define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
2580 #define KVAR(which) (RELOC_KVAR | (which))
2582 #define SCR_DATA_ZERO 0xf00ff00f
2585 #define SCRIPT_KVAR_JIFFIES (0)
2586 #define SCRIPT_KVAR_FIRST SCRIPT_KVAR_JIFFIES
2587 #define SCRIPT_KVAR_LAST SCRIPT_KVAR_JIFFIES
2589 * Kernel variables referenced in the scripts.
2590 * THESE MUST ALL BE ALIGNED TO A 4-BYTE BOUNDARY.
2592 static void *script_kvars
[] __initdata
=
2593 { (void *)&jiffies
};
2596 static struct script script0 __initdata
= {
2597 /*--------------------------< START >-----------------------*/ {
2599 ** This NOP will be patched with LED ON
2600 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
2607 SCR_FROM_REG (ctest2
),
2611 ** Stop here if the C code wants to perform
2612 ** some error recovery procedure manually.
2613 ** (Indicate this by setting SEM in ISTAT)
2615 SCR_FROM_REG (istat
),
2618 ** Report to the C code the next position in
2619 ** the start queue the SCRIPTS will schedule.
2620 ** The C code must not change SCRATCHA.
2622 SCR_LOAD_ABS (scratcha
, 4),
2624 SCR_INT
^ IFTRUE (MASK (SEM
, SEM
)),
2628 ** Start the next job.
2630 ** @DSA = start point for this job.
2631 ** SCRATCHA = address of this job in the start queue.
2633 ** We will restore startpos with SCRATCHA if we fails the
2634 ** arbitration or if it is the idle job.
2636 ** The below GETJOB_BEGIN to GETJOB_END section of SCRIPTS
2637 ** is a critical path. If it is partially executed, it then
2638 ** may happen that the job address is not yet in the DSA
2639 ** and the next queue position points to the next JOB.
2641 SCR_LOAD_ABS (dsa
, 4),
2643 SCR_LOAD_REL (temp
, 4),
2645 }/*-------------------------< GETJOB_BEGIN >------------------*/,{
2646 SCR_STORE_ABS (temp
, 4),
2648 SCR_LOAD_REL (dsa
, 4),
2650 }/*-------------------------< GETJOB_END >--------------------*/,{
2651 SCR_LOAD_REL (temp
, 4),
2656 }/*-------------------------< SELECT >----------------------*/,{
2658 ** DSA contains the address of a scheduled
2661 ** SCRATCHA contains the address of the start queue
2662 ** entry which points to the next job.
2664 ** Set Initiator mode.
2666 ** (Target mode is left as an exercise for the reader)
2672 ** And try to select this target.
2674 SCR_SEL_TBL_ATN
^ offsetof (struct dsb
, select
),
2677 ** Now there are 4 possibilities:
2679 ** (1) The ncr loses arbitration.
2680 ** This is ok, because it will try again,
2681 ** when the bus becomes idle.
2682 ** (But beware of the timeout function!)
2684 ** (2) The ncr is reselected.
2685 ** Then the script processor takes the jump
2686 ** to the RESELECT label.
2688 ** (3) The ncr wins arbitration.
2689 ** Then it will execute SCRIPTS instruction until
2690 ** the next instruction that checks SCSI phase.
2691 ** Then will stop and wait for selection to be
2692 ** complete or selection time-out to occur.
2694 ** After having won arbitration, the ncr SCRIPTS
2695 ** processor is able to execute instructions while
2696 ** the SCSI core is performing SCSI selection. But
2697 ** some script instruction that is not waiting for
2698 ** a valid phase (or selection timeout) to occur
2699 ** breaks the selection procedure, by probably
2700 ** affecting timing requirements.
2701 ** So we have to wait immediately for the next phase
2702 ** or the selection to complete or time-out.
2706 ** load the savep (saved pointer) into
2707 ** the actual data pointer.
2709 SCR_LOAD_REL (temp
, 4),
2710 offsetof (struct ccb
, phys
.header
.savep
),
2712 ** Initialize the status registers
2714 SCR_LOAD_REL (scr0
, 4),
2715 offsetof (struct ccb
, phys
.header
.status
),
2717 }/*-------------------------< WF_SEL_DONE >----------------------*/,{
2718 SCR_INT
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2719 SIR_SEL_ATN_NO_MSG_OUT
,
2720 }/*-------------------------< SEND_IDENT >----------------------*/,{
2722 ** Selection complete.
2723 ** Send the IDENTIFY and SIMPLE_TAG messages
2724 ** (and the M_X_SYNC_REQ / M_X_WIDE_REQ message)
2726 SCR_MOVE_TBL
^ SCR_MSG_OUT
,
2727 offsetof (struct dsb
, smsg
),
2728 }/*-------------------------< SELECT2 >----------------------*/,{
2729 #ifdef SCSI_NCR_IARB_SUPPORT
2731 ** Set IMMEDIATE ARBITRATION if we have been given
2732 ** a hint to do so. (Some job to do after this one).
2734 SCR_FROM_REG (HF_REG
),
2736 SCR_JUMPR
^ IFFALSE (MASK (HF_HINT_IARB
, HF_HINT_IARB
)),
2738 SCR_REG_REG (scntl1
, SCR_OR
, IARB
),
2742 ** Anticipate the COMMAND phase.
2743 ** This is the PHASE we expect at this point.
2745 SCR_JUMP
^ IFFALSE (WHEN (SCR_COMMAND
)),
2748 }/*-------------------------< COMMAND >--------------------*/,{
2750 ** ... and send the command
2752 SCR_MOVE_TBL
^ SCR_COMMAND
,
2753 offsetof (struct dsb
, cmd
),
2755 }/*-----------------------< DISPATCH >----------------------*/,{
2757 ** MSG_IN is the only phase that shall be
2758 ** entered at least once for each (re)selection.
2759 ** So we test it first.
2761 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)),
2763 SCR_JUMP
^ IFTRUE (IF (SCR_DATA_OUT
)),
2764 PADDR (datao_phase
),
2765 SCR_JUMP
^ IFTRUE (IF (SCR_DATA_IN
)),
2766 PADDR (datai_phase
),
2767 SCR_JUMP
^ IFTRUE (IF (SCR_STATUS
)),
2769 SCR_JUMP
^ IFTRUE (IF (SCR_COMMAND
)),
2771 SCR_JUMP
^ IFTRUE (IF (SCR_MSG_OUT
)),
2774 * Discard as many illegal phases as
2775 * required and tell the C code about.
2777 SCR_JUMPR
^ IFFALSE (WHEN (SCR_ILG_OUT
)),
2779 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT
,
2781 SCR_JUMPR
^ IFTRUE (WHEN (SCR_ILG_OUT
)),
2783 SCR_JUMPR
^ IFFALSE (WHEN (SCR_ILG_IN
)),
2785 SCR_MOVE_ABS (1) ^ SCR_ILG_IN
,
2787 SCR_JUMPR
^ IFTRUE (WHEN (SCR_ILG_IN
)),
2793 }/*---------------------< SEL_NO_CMD >----------------------*/,{
2795 ** The target does not switch to command
2796 ** phase after IDENTIFY has been sent.
2798 ** If it stays in MSG OUT phase send it
2799 ** the IDENTIFY again.
2801 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
2802 PADDRH (resend_ident
),
2804 ** If target does not switch to MSG IN phase
2805 ** and we sent a negotiation, assert the
2806 ** failure immediately.
2808 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)),
2810 SCR_FROM_REG (HS_REG
),
2812 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
2815 ** Jump to dispatcher.
2820 }/*-------------------------< INIT >------------------------*/,{
2822 ** Wait for the SCSI RESET signal to be
2823 ** inactive before restarting operations,
2824 ** since the chip may hang on SEL_ATN
2825 ** if SCSI RESET is active.
2827 SCR_FROM_REG (sstat0
),
2829 SCR_JUMPR
^ IFTRUE (MASK (IRST
, IRST
)),
2833 }/*-------------------------< CLRACK >----------------------*/,{
2835 ** Terminate possible pending message phase.
2842 }/*-------------------------< DISP_STATUS >----------------------*/,{
2844 ** Anticipate STATUS phase.
2846 ** Does spare 3 SCRIPTS instructions when we have
2847 ** completed the INPUT of the data.
2849 SCR_JUMP
^ IFTRUE (WHEN (SCR_STATUS
)),
2854 }/*-------------------------< DATAI_DONE >-------------------*/,{
2856 * If the device wants us to send more data,
2857 * we must count the extra bytes.
2859 SCR_JUMP
^ IFTRUE (WHEN (SCR_DATA_IN
)),
2860 PADDRH (data_ovrun
),
2862 ** If the SWIDE is not full, jump to dispatcher.
2863 ** We anticipate a STATUS phase.
2864 ** If we get later an IGNORE WIDE RESIDUE, we
2865 ** will alias it as a MODIFY DP (-1).
2867 SCR_FROM_REG (scntl2
),
2869 SCR_JUMP
^ IFFALSE (MASK (WSR
, WSR
)),
2870 PADDR (disp_status
),
2872 ** The SWIDE is full.
2873 ** Clear this condition.
2875 SCR_REG_REG (scntl2
, SCR_OR
, WSR
),
2878 * We are expecting an IGNORE RESIDUE message
2879 * from the device, otherwise we are in data
2880 * overrun condition. Check against MSG_IN phase.
2882 SCR_INT
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2884 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2885 PADDR (disp_status
),
2887 * We are in MSG_IN phase,
2888 * Read the first byte of the message.
2889 * If it is not an IGNORE RESIDUE message,
2890 * signal overrun and jump to message
2893 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2895 SCR_INT
^ IFFALSE (DATA (M_IGN_RESIDUE
)),
2897 SCR_JUMP
^ IFFALSE (DATA (M_IGN_RESIDUE
)),
2901 * We got the message we expected.
2902 * Read the 2nd byte, and jump to dispatcher.
2906 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2911 PADDR (disp_status
),
2913 }/*-------------------------< DATAO_DONE >-------------------*/,{
2915 * If the device wants us to send more data,
2916 * we must count the extra bytes.
2918 SCR_JUMP
^ IFTRUE (WHEN (SCR_DATA_OUT
)),
2919 PADDRH (data_ovrun
),
2921 ** If the SODL is not full jump to dispatcher.
2922 ** We anticipate a MSG IN phase or a STATUS phase.
2924 SCR_FROM_REG (scntl2
),
2926 SCR_JUMP
^ IFFALSE (MASK (WSS
, WSS
)),
2927 PADDR (disp_status
),
2929 ** The SODL is full, clear this condition.
2931 SCR_REG_REG (scntl2
, SCR_OR
, WSS
),
2934 ** And signal a DATA UNDERRUN condition
2942 }/*-------------------------< IGN_I_W_R_MSG >--------------*/,{
2944 ** We jump here from the phase mismatch interrupt,
2945 ** When we have a SWIDE and the device has presented
2946 ** a IGNORE WIDE RESIDUE message on the BUS.
2947 ** We just have to throw away this message and then
2948 ** to jump to dispatcher.
2950 SCR_MOVE_ABS (2) ^ SCR_MSG_IN
,
2953 ** Clear ACK and jump to dispatcher.
2958 }/*-------------------------< DATAI_PHASE >------------------*/,{
2961 }/*-------------------------< DATAO_PHASE >------------------*/,{
2963 ** Patch for 53c1010_66 only - to allow A0 part
2964 ** to operate properly in a 33MHz PCI bus.
2966 ** SCR_REG_REG(scntl4, SCR_OR, 0x0c),
2973 }/*-------------------------< MSG_IN >--------------------*/,{
2975 ** Get the first byte of the message.
2977 ** The script processor doesn't negate the
2978 ** ACK signal after this transfer.
2980 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2982 }/*-------------------------< MSG_IN2 >--------------------*/,{
2984 ** Check first against 1 byte messages
2985 ** that we handle from SCRIPTS.
2987 SCR_JUMP
^ IFTRUE (DATA (M_COMPLETE
)),
2989 SCR_JUMP
^ IFTRUE (DATA (M_DISCONNECT
)),
2991 SCR_JUMP
^ IFTRUE (DATA (M_SAVE_DP
)),
2993 SCR_JUMP
^ IFTRUE (DATA (M_RESTORE_DP
)),
2996 ** We handle all other messages from the
2997 ** C code, so no need to waste on-chip RAM
3001 PADDRH (msg_in_etc
),
3003 }/*-------------------------< STATUS >--------------------*/,{
3007 SCR_MOVE_ABS (1) ^ SCR_STATUS
,
3009 #ifdef SCSI_NCR_IARB_SUPPORT
3011 ** If STATUS is not GOOD, clear IMMEDIATE ARBITRATION,
3012 ** since we may have to tamper the start queue from
3015 SCR_JUMPR
^ IFTRUE (DATA (S_GOOD
)),
3017 SCR_REG_REG (scntl1
, SCR_AND
, ~IARB
),
3021 ** save status to scsi_status.
3022 ** mark as complete.
3024 SCR_TO_REG (SS_REG
),
3026 SCR_LOAD_REG (HS_REG
, HS_COMPLETE
),
3029 ** Anticipate the MESSAGE PHASE for
3030 ** the TASK COMPLETE message.
3032 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)),
3037 }/*-------------------------< COMPLETE >-----------------*/,{
3039 ** Complete message.
3041 ** Copy the data pointer to LASTP in header.
3043 SCR_STORE_REL (temp
, 4),
3044 offsetof (struct ccb
, phys
.header
.lastp
),
3046 ** When we terminate the cycle by clearing ACK,
3047 ** the target may disconnect immediately.
3049 ** We don't want to be told of an
3050 ** "unexpected disconnect",
3051 ** so we disable this feature.
3053 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
3056 ** Terminate cycle ...
3058 SCR_CLR (SCR_ACK
|SCR_ATN
),
3061 ** ... and wait for the disconnect.
3065 }/*-------------------------< COMPLETE2 >-----------------*/,{
3067 ** Save host status to header.
3069 SCR_STORE_REL (scr0
, 4),
3070 offsetof (struct ccb
, phys
.header
.status
),
3072 #ifdef SCSI_NCR_PCIQ_MAY_REORDER_WRITES
3074 ** Some bridges may reorder DMA writes to memory.
3075 ** We donnot want the CPU to deal with completions
3076 ** without all the posted write having been flushed
3077 ** to memory. This DUMMY READ should flush posted
3078 ** buffers prior to the CPU having to deal with
3081 SCR_LOAD_REL (scr0
, 4), /* DUMMY READ */
3082 offsetof (struct ccb
, phys
.header
.status
),
3085 ** If command resulted in not GOOD status,
3086 ** call the C code if needed.
3088 SCR_FROM_REG (SS_REG
),
3090 SCR_CALL
^ IFFALSE (DATA (S_GOOD
)),
3091 PADDRH (bad_status
),
3094 ** If we performed an auto-sense, call
3095 ** the C code to synchronyze task aborts
3096 ** with UNIT ATTENTION conditions.
3098 SCR_FROM_REG (HF_REG
),
3100 SCR_INT
^ IFTRUE (MASK (HF_AUTO_SENSE
, HF_AUTO_SENSE
)),
3101 SIR_AUTO_SENSE_DONE
,
3103 }/*------------------------< DONE >-----------------*/,{
3104 #ifdef SCSI_NCR_PCIQ_SYNC_ON_INTR
3106 ** It seems that some bridges flush everything
3107 ** when the INTR line is raised. For these ones,
3108 ** we can just ensure that the INTR line will be
3109 ** raised before each completion. So, if it happens
3110 ** that we have been faster that the CPU, we just
3111 ** have to synchronize with it. A dummy programmed
3112 ** interrupt will do the trick.
3113 ** Note that we overlap at most 1 IO with the CPU
3114 ** in this situation and that the IRQ line must not
3117 SCR_FROM_REG (istat
),
3119 SCR_INT
^ IFTRUE (MASK (INTF
, INTF
)),
3120 SIR_DUMMY_INTERRUPT
,
3123 ** Copy the DSA to the DONE QUEUE and
3124 ** signal completion to the host.
3125 ** If we are interrupted between DONE
3126 ** and DONE_END, we must reset, otherwise
3127 ** the completed CCB will be lost.
3129 SCR_STORE_ABS (dsa
, 4),
3131 SCR_LOAD_ABS (dsa
, 4),
3133 SCR_LOAD_ABS (scratcha
, 4),
3135 SCR_STORE_REL (scratcha
, 4),
3138 ** The instruction below reads the DONE QUEUE next
3139 ** free position from memory.
3140 ** In addition it ensures that all PCI posted writes
3141 ** are flushed and so the DSA value of the done
3142 ** CCB is visible by the CPU before INTFLY is raised.
3144 SCR_LOAD_REL (temp
, 4),
3148 SCR_STORE_ABS (temp
, 4),
3150 }/*------------------------< DONE_END >-----------------*/,{
3154 }/*-------------------------< SAVE_DP >------------------*/,{
3156 ** Clear ACK immediately.
3157 ** No need to delay it.
3162 ** Keep track we received a SAVE DP, so
3163 ** we will switch to the other PM context
3164 ** on the next PM since the DP may point
3165 ** to the current PM context.
3167 SCR_REG_REG (HF_REG
, SCR_OR
, HF_DP_SAVED
),
3171 ** Copy the data pointer to SAVEP in header.
3173 SCR_STORE_REL (temp
, 4),
3174 offsetof (struct ccb
, phys
.header
.savep
),
3177 }/*-------------------------< RESTORE_DP >---------------*/,{
3179 ** RESTORE_DP message:
3180 ** Copy SAVEP in header to actual data pointer.
3182 SCR_LOAD_REL (temp
, 4),
3183 offsetof (struct ccb
, phys
.header
.savep
),
3187 }/*-------------------------< DISCONNECT >---------------*/,{
3189 ** DISCONNECTing ...
3191 ** disable the "unexpected disconnect" feature,
3192 ** and remove the ACK signal.
3194 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
3196 SCR_CLR (SCR_ACK
|SCR_ATN
),
3199 ** Wait for the disconnect.
3204 ** Status is: DISCONNECTED.
3206 SCR_LOAD_REG (HS_REG
, HS_DISCONNECT
),
3209 ** Save host status to header.
3211 SCR_STORE_REL (scr0
, 4),
3212 offsetof (struct ccb
, phys
.header
.status
),
3214 ** If QUIRK_AUTOSAVE is set,
3215 ** do an "save pointer" operation.
3217 SCR_FROM_REG (QU_REG
),
3219 SCR_JUMP
^ IFFALSE (MASK (QUIRK_AUTOSAVE
, QUIRK_AUTOSAVE
)),
3222 ** like SAVE_DP message:
3223 ** Remember we saved the data pointer.
3224 ** Copy data pointer to SAVEP in header.
3226 SCR_REG_REG (HF_REG
, SCR_OR
, HF_DP_SAVED
),
3228 SCR_STORE_REL (temp
, 4),
3229 offsetof (struct ccb
, phys
.header
.savep
),
3233 }/*-------------------------< IDLE >------------------------*/,{
3236 ** Wait for reselect.
3237 ** This NOP will be patched with LED OFF
3238 ** SCR_REG_REG (gpreg, SCR_OR, 0x01)
3242 #ifdef SCSI_NCR_IARB_SUPPORT
3246 }/*-------------------------< UNGETJOB >-----------------*/,{
3247 #ifdef SCSI_NCR_IARB_SUPPORT
3249 ** Set IMMEDIATE ARBITRATION, for the next time.
3250 ** This will give us better chance to win arbitration
3251 ** for the job we just wanted to do.
3253 SCR_REG_REG (scntl1
, SCR_OR
, IARB
),
3257 ** We are not able to restart the SCRIPTS if we are
3258 ** interrupted and these instruction haven't been
3259 ** all executed. BTW, this is very unlikely to
3260 ** happen, but we check that from the C code.
3262 SCR_LOAD_REG (dsa
, 0xff),
3264 SCR_STORE_ABS (scratcha
, 4),
3266 }/*-------------------------< RESELECT >--------------------*/,{
3268 ** make the host status invalid.
3273 ** Sleep waiting for a reselection.
3274 ** If SIGP is set, special treatment.
3276 ** Zu allem bereit ..
3280 }/*-------------------------< RESELECTED >------------------*/,{
3282 ** This NOP will be patched with LED ON
3283 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
3288 ** load the target id into the sdid
3290 SCR_REG_SFBR (ssid
, SCR_AND
, 0x8F),
3295 ** load the target control block address
3297 SCR_LOAD_ABS (dsa
, 4),
3299 SCR_SFBR_REG (dsa
, SCR_SHL
, 0),
3301 SCR_REG_REG (dsa
, SCR_SHL
, 0),
3303 SCR_REG_REG (dsa
, SCR_AND
, 0x3c),
3305 SCR_LOAD_REL (dsa
, 4),
3308 ** Load the synchronous transfer registers.
3310 SCR_LOAD_REL (scntl3
, 1),
3311 offsetof(struct tcb
, wval
),
3312 SCR_LOAD_REL (sxfer
, 1),
3313 offsetof(struct tcb
, sval
),
3314 }/*-------------------------< RESEL_SCNTL4 >------------------*/,{
3316 ** Write with uval value. Patch if device
3317 ** does not support Ultra3.
3319 ** SCR_LOAD_REL (scntl4, 1),
3320 ** offsetof(struct tcb, uval),
3326 * We expect MESSAGE IN phase.
3327 * If not, get help from the C code.
3329 SCR_INT
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3330 SIR_RESEL_NO_MSG_IN
,
3331 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3335 * If IDENTIFY LUN #0, use a faster path
3336 * to find the LCB structure.
3338 SCR_JUMPR
^ IFTRUE (MASK (0x80, 0xbf)),
3341 * If message isn't an IDENTIFY,
3342 * tell the C code about.
3344 SCR_INT
^ IFFALSE (MASK (0x80, 0x80)),
3345 SIR_RESEL_NO_IDENTIFY
,
3347 * It is an IDENTIFY message,
3348 * Load the LUN control block address.
3350 SCR_LOAD_REL (dsa
, 4),
3351 offsetof(struct tcb
, b_luntbl
),
3352 SCR_SFBR_REG (dsa
, SCR_SHL
, 0),
3354 SCR_REG_REG (dsa
, SCR_SHL
, 0),
3356 SCR_REG_REG (dsa
, SCR_AND
, 0xfc),
3358 SCR_LOAD_REL (dsa
, 4),
3363 ** LUN 0 special case (but usual one :))
3365 SCR_LOAD_REL (dsa
, 4),
3366 offsetof(struct tcb
, b_lun0
),
3369 ** Load the reselect task action for this LUN.
3370 ** Load the tasks DSA array for this LUN.
3373 SCR_LOAD_REL (temp
, 4),
3374 offsetof(struct lcb
, resel_task
),
3375 SCR_LOAD_REL (dsa
, 4),
3376 offsetof(struct lcb
, b_tasktbl
),
3379 }/*-------------------------< RESEL_TAG >-------------------*/,{
3381 ** ACK the IDENTIFY or TAG previously received
3387 ** Read IDENTIFY + SIMPLE + TAG using a single MOVE.
3388 ** Agressive optimization, is'nt it?
3389 ** No need to test the SIMPLE TAG message, since the
3390 ** driver only supports conformant devices for tags. ;-)
3392 SCR_MOVE_ABS (2) ^ SCR_MSG_IN
,
3395 ** Read the TAG from the SIDL.
3396 ** Still an aggressive optimization. ;-)
3397 ** Compute the CCB indirect jump address which
3398 ** is (#TAG*2 & 0xfc) due to tag numbering using
3399 ** 1,3,5..MAXTAGS*2+1 actual values.
3401 SCR_REG_SFBR (sidl
, SCR_SHL
, 0),
3403 #if MAX_TASKS*4 > 512
3404 SCR_JUMPR
^ IFFALSE (CARRYSET
),
3406 SCR_REG_REG (dsa1
, SCR_OR
, 2),
3408 SCR_REG_REG (sfbr
, SCR_SHL
, 0),
3410 SCR_JUMPR
^ IFFALSE (CARRYSET
),
3412 SCR_REG_REG (dsa1
, SCR_OR
, 1),
3414 #elif MAX_TASKS*4 > 256
3415 SCR_JUMPR
^ IFFALSE (CARRYSET
),
3417 SCR_REG_REG (dsa1
, SCR_OR
, 1),
3421 ** Retrieve the DSA of this task.
3422 ** JUMP indirectly to the restart point of the CCB.
3424 SCR_SFBR_REG (dsa
, SCR_AND
, 0xfc),
3426 }/*-------------------------< RESEL_GO >-------------------*/,{
3427 SCR_LOAD_REL (dsa
, 4),
3429 SCR_LOAD_REL (temp
, 4),
3430 offsetof(struct ccb
, phys
.header
.go
.restart
),
3433 /* In normal situations we branch to RESEL_DSA */
3434 }/*-------------------------< RESEL_NOTAG >-------------------*/,{
3436 ** JUMP indirectly to the restart point of the CCB.
3441 }/*-------------------------< RESEL_DSA >-------------------*/,{
3443 ** Ack the IDENTIFY or TAG previously received.
3448 ** load the savep (saved pointer) into
3449 ** the actual data pointer.
3451 SCR_LOAD_REL (temp
, 4),
3452 offsetof (struct ccb
, phys
.header
.savep
),
3454 ** Initialize the status registers
3456 SCR_LOAD_REL (scr0
, 4),
3457 offsetof (struct ccb
, phys
.header
.status
),
3459 ** Jump to dispatcher.
3464 }/*-------------------------< DATA_IN >--------------------*/,{
3466 ** Because the size depends on the
3467 ** #define MAX_SCATTER parameter,
3468 ** it is filled in at runtime.
3470 ** ##===========< i=0; i<MAX_SCATTER >=========
3471 ** || SCR_CHMOV_TBL ^ SCR_DATA_IN,
3472 ** || offsetof (struct dsb, data[ i]),
3473 ** ##==========================================
3475 **---------------------------------------------------------
3478 }/*-------------------------< DATA_IN2 >-------------------*/,{
3482 PADDRH (data_ovrun
),
3483 }/*-------------------------< DATA_OUT >--------------------*/,{
3485 ** Because the size depends on the
3486 ** #define MAX_SCATTER parameter,
3487 ** it is filled in at runtime.
3489 ** ##===========< i=0; i<MAX_SCATTER >=========
3490 ** || SCR_CHMOV_TBL ^ SCR_DATA_OUT,
3491 ** || offsetof (struct dsb, data[ i]),
3492 ** ##==========================================
3494 **---------------------------------------------------------
3497 }/*-------------------------< DATA_OUT2 >-------------------*/,{
3501 PADDRH (data_ovrun
),
3503 }/*-------------------------< PM0_DATA >--------------------*/,{
3505 ** Read our host flags to SFBR, so we will be able
3506 ** to check against the data direction we expect.
3508 SCR_FROM_REG (HF_REG
),
3511 ** Check against actual DATA PHASE.
3513 SCR_JUMP
^ IFFALSE (WHEN (SCR_DATA_IN
)),
3514 PADDR (pm0_data_out
),
3516 ** Actual phase is DATA IN.
3517 ** Check against expected direction.
3519 SCR_JUMP
^ IFFALSE (MASK (HF_DATA_IN
, HF_DATA_IN
)),
3520 PADDRH (data_ovrun
),
3522 ** Keep track we are moving data from the
3523 ** PM0 DATA mini-script.
3525 SCR_REG_REG (HF_REG
, SCR_OR
, HF_IN_PM0
),
3528 ** Move the data to memory.
3530 SCR_CHMOV_TBL
^ SCR_DATA_IN
,
3531 offsetof (struct ccb
, phys
.pm0
.sg
),
3533 PADDR (pm0_data_end
),
3534 }/*-------------------------< PM0_DATA_OUT >----------------*/,{
3536 ** Actual phase is DATA OUT.
3537 ** Check against expected direction.
3539 SCR_JUMP
^ IFTRUE (MASK (HF_DATA_IN
, HF_DATA_IN
)),
3540 PADDRH (data_ovrun
),
3542 ** Keep track we are moving data from the
3543 ** PM0 DATA mini-script.
3545 SCR_REG_REG (HF_REG
, SCR_OR
, HF_IN_PM0
),
3548 ** Move the data from memory.
3550 SCR_CHMOV_TBL
^ SCR_DATA_OUT
,
3551 offsetof (struct ccb
, phys
.pm0
.sg
),
3552 }/*-------------------------< PM0_DATA_END >----------------*/,{
3554 ** Clear the flag that told we were moving
3555 ** data from the PM0 DATA mini-script.
3557 SCR_REG_REG (HF_REG
, SCR_AND
, (~HF_IN_PM0
)),
3560 ** Return to the previous DATA script which
3561 ** is guaranteed by design (if no bug) to be
3562 ** the main DATA script for this transfer.
3564 SCR_LOAD_REL (temp
, 4),
3565 offsetof (struct ccb
, phys
.pm0
.ret
),
3568 }/*-------------------------< PM1_DATA >--------------------*/,{
3570 ** Read our host flags to SFBR, so we will be able
3571 ** to check against the data direction we expect.
3573 SCR_FROM_REG (HF_REG
),
3576 ** Check against actual DATA PHASE.
3578 SCR_JUMP
^ IFFALSE (WHEN (SCR_DATA_IN
)),
3579 PADDR (pm1_data_out
),
3581 ** Actual phase is DATA IN.
3582 ** Check against expected direction.
3584 SCR_JUMP
^ IFFALSE (MASK (HF_DATA_IN
, HF_DATA_IN
)),
3585 PADDRH (data_ovrun
),
3587 ** Keep track we are moving data from the
3588 ** PM1 DATA mini-script.
3590 SCR_REG_REG (HF_REG
, SCR_OR
, HF_IN_PM1
),
3593 ** Move the data to memory.
3595 SCR_CHMOV_TBL
^ SCR_DATA_IN
,
3596 offsetof (struct ccb
, phys
.pm1
.sg
),
3598 PADDR (pm1_data_end
),
3599 }/*-------------------------< PM1_DATA_OUT >----------------*/,{
3601 ** Actual phase is DATA OUT.
3602 ** Check against expected direction.
3604 SCR_JUMP
^ IFTRUE (MASK (HF_DATA_IN
, HF_DATA_IN
)),
3605 PADDRH (data_ovrun
),
3607 ** Keep track we are moving data from the
3608 ** PM1 DATA mini-script.
3610 SCR_REG_REG (HF_REG
, SCR_OR
, HF_IN_PM1
),
3613 ** Move the data from memory.
3615 SCR_CHMOV_TBL
^ SCR_DATA_OUT
,
3616 offsetof (struct ccb
, phys
.pm1
.sg
),
3617 }/*-------------------------< PM1_DATA_END >----------------*/,{
3619 ** Clear the flag that told we were moving
3620 ** data from the PM1 DATA mini-script.
3622 SCR_REG_REG (HF_REG
, SCR_AND
, (~HF_IN_PM1
)),
3625 ** Return to the previous DATA script which
3626 ** is guaranteed by design (if no bug) to be
3627 ** the main DATA script for this transfer.
3629 SCR_LOAD_REL (temp
, 4),
3630 offsetof (struct ccb
, phys
.pm1
.ret
),
3633 }/*---------------------------------------------------------*/
3637 static struct scripth scripth0 __initdata
= {
3638 /*------------------------< START64 >-----------------------*/{
3640 ** SCRIPT entry point for the 895A and the 896.
3641 ** For now, there is no specific stuff for that
3642 ** chip at this point, but this may come.
3646 }/*-------------------------< NO_DATA >-------------------*/,{
3648 PADDRH (data_ovrun
),
3649 }/*-----------------------< SEL_FOR_ABORT >------------------*/,{
3651 ** We are jumped here by the C code, if we have
3652 ** some target to reset or some disconnected
3653 ** job to abort. Since error recovery is a serious
3654 ** busyness, we will really reset the SCSI BUS, if
3655 ** case of a SCSI interrupt occurring in this path.
3659 ** Set initiator mode.
3664 ** And try to select this target.
3666 SCR_SEL_TBL_ATN
^ offsetof (struct ncb
, abrt_sel
),
3670 ** Wait for the selection to complete or
3671 ** the selection to time out.
3673 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3679 SIR_TARGET_SELECTED
,
3681 ** The C code should let us continue here.
3682 ** Send the 'kiss of death' message.
3683 ** We expect an immediate disconnect once
3684 ** the target has eaten the message.
3686 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
3688 SCR_MOVE_TBL
^ SCR_MSG_OUT
,
3689 offsetof (struct ncb
, abrt_tbl
),
3690 SCR_CLR (SCR_ACK
|SCR_ATN
),
3695 ** Tell the C code that we are done.
3699 }/*-----------------------< SEL_FOR_ABORT_1 >--------------*/,{
3701 ** Jump at scheduler.
3706 }/*------------------------< SELECT_NO_ATN >-----------------*/,{
3708 ** Set Initiator mode.
3709 ** And try to select this target without ATN.
3714 SCR_SEL_TBL
^ offsetof (struct dsb
, select
),
3717 ** load the savep (saved pointer) into
3718 ** the actual data pointer.
3720 SCR_LOAD_REL (temp
, 4),
3721 offsetof (struct ccb
, phys
.header
.savep
),
3723 ** Initialize the status registers
3725 SCR_LOAD_REL (scr0
, 4),
3726 offsetof (struct ccb
, phys
.header
.status
),
3728 }/*------------------------< WF_SEL_DONE_NO_ATN >-----------------*/,{
3730 ** Wait immediately for the next phase or
3731 ** the selection to complete or time-out.
3733 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3738 }/*-------------------------< MSG_IN_ETC >--------------------*/,{
3740 ** If it is an EXTENDED (variable size message)
3743 SCR_JUMP
^ IFTRUE (DATA (M_EXTENDED
)),
3744 PADDRH (msg_extended
),
3746 ** Let the C code handle any other
3749 SCR_JUMP
^ IFTRUE (MASK (0x00, 0xf0)),
3750 PADDRH (msg_received
),
3751 SCR_JUMP
^ IFTRUE (MASK (0x10, 0xf0)),
3752 PADDRH (msg_received
),
3754 ** We donnot handle 2 bytes messages from SCRIPTS.
3755 ** So, let the C code deal with these ones too.
3757 SCR_JUMP
^ IFFALSE (MASK (0x20, 0xf0)),
3758 PADDRH (msg_weird_seen
),
3761 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3764 PADDRH (msg_received
),
3766 }/*-------------------------< MSG_RECEIVED >--------------------*/,{
3767 SCR_LOAD_REL (scratcha
, 4), /* DUMMY READ */
3772 }/*-------------------------< MSG_WEIRD_SEEN >------------------*/,{
3773 SCR_LOAD_REL (scratcha
, 4), /* DUMMY READ */
3778 }/*-------------------------< MSG_EXTENDED >--------------------*/,{
3780 ** Clear ACK and get the next byte
3781 ** assumed to be the message length.
3785 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3788 ** Try to catch some unlikely situations as 0 length
3789 ** or too large the length.
3791 SCR_JUMP
^ IFTRUE (DATA (0)),
3792 PADDRH (msg_weird_seen
),
3793 SCR_TO_REG (scratcha
),
3795 SCR_REG_REG (sfbr
, SCR_ADD
, (256-8)),
3797 SCR_JUMP
^ IFTRUE (CARRYSET
),
3798 PADDRH (msg_weird_seen
),
3800 ** We donnot handle extended messages from SCRIPTS.
3801 ** Read the amount of data correponding to the
3802 ** message length and call the C code.
3804 SCR_STORE_REL (scratcha
, 1),
3805 offsetof (struct dsb
, smsg_ext
.size
),
3808 SCR_MOVE_TBL
^ SCR_MSG_IN
,
3809 offsetof (struct dsb
, smsg_ext
),
3811 PADDRH (msg_received
),
3813 }/*-------------------------< MSG_BAD >------------------*/,{
3815 ** unimplemented message - reject it.
3824 }/*-------------------------< MSG_WEIRD >--------------------*/,{
3826 ** weird message received
3827 ** ignore all MSG IN phases and reject it.
3833 }/*-------------------------< MSG_WEIRD1 >--------------------*/,{
3836 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3838 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3841 PADDRH (msg_weird1
),
3842 }/*-------------------------< WDTR_RESP >----------------*/,{
3844 ** let the target fetch our answer.
3850 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3851 PADDRH (nego_bad_phase
),
3853 }/*-------------------------< SEND_WDTR >----------------*/,{
3855 ** Send the M_X_WIDE_REQ
3857 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT
,
3860 PADDRH (msg_out_done
),
3862 }/*-------------------------< SDTR_RESP >-------------*/,{
3864 ** let the target fetch our answer.
3870 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3871 PADDRH (nego_bad_phase
),
3873 }/*-------------------------< SEND_SDTR >-------------*/,{
3875 ** Send the M_X_SYNC_REQ
3877 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT
,
3880 PADDRH (msg_out_done
),
3882 }/*-------------------------< PPR_RESP >-------------*/,{
3884 ** let the target fetch our answer.
3890 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3891 PADDRH (nego_bad_phase
),
3893 }/*-------------------------< SEND_PPR >-------------*/,{
3895 ** Send the M_X_PPR_REQ
3897 SCR_MOVE_ABS (8) ^ SCR_MSG_OUT
,
3900 PADDRH (msg_out_done
),
3902 }/*-------------------------< NEGO_BAD_PHASE >------------*/,{
3908 }/*-------------------------< MSG_OUT >-------------------*/,{
3910 ** The target requests a message.
3912 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
3915 ** ... wait for the next phase
3916 ** if it's a message out, send it again, ...
3918 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
3920 }/*-------------------------< MSG_OUT_DONE >--------------*/,{
3922 ** ... else clear the message ...
3927 ** ... and process the next phase
3932 }/*-------------------------< DATA_OVRUN >-----------------------*/,{
3934 * Use scratcha to count the extra bytes.
3936 SCR_LOAD_ABS (scratcha
, 4),
3938 }/*-------------------------< DATA_OVRUN1 >----------------------*/,{
3940 * The target may want to transfer too much data.
3942 * If phase is DATA OUT write 1 byte and count it.
3944 SCR_JUMPR
^ IFFALSE (WHEN (SCR_DATA_OUT
)),
3946 SCR_CHMOV_ABS (1) ^ SCR_DATA_OUT
,
3949 PADDRH (data_ovrun2
),
3951 * If WSR is set, clear this condition, and
3954 SCR_FROM_REG (scntl2
),
3956 SCR_JUMPR
^ IFFALSE (MASK (WSR
, WSR
)),
3958 SCR_REG_REG (scntl2
, SCR_OR
, WSR
),
3961 PADDRH (data_ovrun2
),
3963 * Finally check against DATA IN phase.
3964 * Signal data overrun to the C code
3965 * and jump to dispatcher if not so.
3966 * Read 1 byte otherwise and count it.
3968 SCR_JUMPR
^ IFTRUE (WHEN (SCR_DATA_IN
)),
3974 SCR_CHMOV_ABS (1) ^ SCR_DATA_IN
,
3976 }/*-------------------------< DATA_OVRUN2 >----------------------*/,{
3979 * This will allow to return a negative
3982 SCR_REG_REG (scratcha
, SCR_ADD
, 0x01),
3984 SCR_REG_REG (scratcha1
, SCR_ADDC
, 0),
3986 SCR_REG_REG (scratcha2
, SCR_ADDC
, 0),
3989 * .. and repeat as required.
3992 PADDRH (data_ovrun1
),
3994 }/*-------------------------< ABORT_RESEL >----------------*/,{
4000 ** send the abort/abortag/reset message
4001 ** we expect an immediate disconnect
4003 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
4005 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
4007 SCR_CLR (SCR_ACK
|SCR_ATN
),
4015 }/*-------------------------< RESEND_IDENT >-------------------*/,{
4017 ** The target stays in MSG OUT phase after having acked
4018 ** Identify [+ Tag [+ Extended message ]]. Targets shall
4019 ** behave this way on parity error.
4020 ** We must send it again all the messages.
4022 SCR_SET (SCR_ATN
), /* Shall be asserted 2 deskew delays before the */
4023 0, /* 1rst ACK = 90 ns. Hope the NCR is'nt too fast */
4026 }/*-------------------------< IDENT_BREAK >-------------------*/,{
4031 }/*-------------------------< IDENT_BREAK_ATN >----------------*/,{
4036 }/*-------------------------< SDATA_IN >-------------------*/,{
4037 SCR_CHMOV_TBL
^ SCR_DATA_IN
,
4038 offsetof (struct dsb
, sense
),
4042 PADDRH (data_ovrun
),
4043 }/*-------------------------< DATA_IO >--------------------*/,{
4045 ** We jump here if the data direction was unknown at the
4046 ** time we had to queue the command to the scripts processor.
4047 ** Pointers had been set as follow in this situation:
4048 ** savep --> DATA_IO
4049 ** lastp --> start pointer when DATA_IN
4050 ** goalp --> goal pointer when DATA_IN
4051 ** wlastp --> start pointer when DATA_OUT
4052 ** wgoalp --> goal pointer when DATA_OUT
4053 ** This script sets savep/lastp/goalp according to the
4054 ** direction chosen by the target.
4056 SCR_JUMP
^ IFTRUE (WHEN (SCR_DATA_OUT
)),
4057 PADDRH(data_io_out
),
4058 }/*-------------------------< DATA_IO_COM >-----------------*/,{
4060 ** Direction is DATA IN.
4061 ** Warning: we jump here, even when phase is DATA OUT.
4063 SCR_LOAD_REL (scratcha
, 4),
4064 offsetof (struct ccb
, phys
.header
.lastp
),
4065 SCR_STORE_REL (scratcha
, 4),
4066 offsetof (struct ccb
, phys
.header
.savep
),
4069 ** Jump to the SCRIPTS according to actual direction.
4071 SCR_LOAD_REL (temp
, 4),
4072 offsetof (struct ccb
, phys
.header
.savep
),
4075 }/*-------------------------< DATA_IO_OUT >-----------------*/,{
4077 ** Direction is DATA OUT.
4079 SCR_REG_REG (HF_REG
, SCR_AND
, (~HF_DATA_IN
)),
4081 SCR_LOAD_REL (scratcha
, 4),
4082 offsetof (struct ccb
, phys
.header
.wlastp
),
4083 SCR_STORE_REL (scratcha
, 4),
4084 offsetof (struct ccb
, phys
.header
.lastp
),
4085 SCR_LOAD_REL (scratcha
, 4),
4086 offsetof (struct ccb
, phys
.header
.wgoalp
),
4087 SCR_STORE_REL (scratcha
, 4),
4088 offsetof (struct ccb
, phys
.header
.goalp
),
4090 PADDRH(data_io_com
),
4092 }/*-------------------------< RESEL_BAD_LUN >---------------*/,{
4094 ** Message is an IDENTIFY, but lun is unknown.
4095 ** Signal problem to C code for logging the event.
4096 ** Send a M_ABORT to clear all pending tasks.
4101 PADDRH (abort_resel
),
4102 }/*-------------------------< BAD_I_T_L >------------------*/,{
4104 ** We donnot have a task for that I_T_L.
4105 ** Signal problem to C code for logging the event.
4106 ** Send a M_ABORT message.
4109 SIR_RESEL_BAD_I_T_L
,
4111 PADDRH (abort_resel
),
4112 }/*-------------------------< BAD_I_T_L_Q >----------------*/,{
4114 ** We donnot have a task that matches the tag.
4115 ** Signal problem to C code for logging the event.
4116 ** Send a M_ABORTTAG message.
4119 SIR_RESEL_BAD_I_T_L_Q
,
4121 PADDRH (abort_resel
),
4122 }/*-------------------------< BAD_STATUS >-----------------*/,{
4124 ** Anything different from INTERMEDIATE
4125 ** CONDITION MET should be a bad SCSI status,
4126 ** given that GOOD status has already been tested.
4129 SCR_LOAD_ABS (scratcha
, 4),
4131 SCR_INT
^ IFFALSE (DATA (S_COND_MET
)),
4136 }/*-------------------------< TWEAK_PMJ >------------------*/,{
4138 ** Disable PM handling from SCRIPTS for the data phase
4139 ** and so force PM to be handled from C code if HF_PM_TO_C
4142 SCR_FROM_REG(HF_REG
),
4144 SCR_JUMPR
^ IFTRUE (MASK (HF_PM_TO_C
, HF_PM_TO_C
)),
4146 SCR_REG_REG (ccntl0
, SCR_OR
, ENPMJ
),
4150 SCR_REG_REG (ccntl0
, SCR_AND
, (~ENPMJ
)),
4155 }/*-------------------------< PM_HANDLE >------------------*/,{
4157 ** Phase mismatch handling.
4159 ** Since we have to deal with 2 SCSI data pointers
4160 ** (current and saved), we need at least 2 contexts.
4161 ** Each context (pm0 and pm1) has a saved area, a
4162 ** SAVE mini-script and a DATA phase mini-script.
4165 ** Get the PM handling flags.
4167 SCR_FROM_REG (HF_REG
),
4170 ** If no flags (1rst PM for example), avoid
4171 ** all the below heavy flags testing.
4172 ** This makes the normal case a bit faster.
4174 SCR_JUMP
^ IFTRUE (MASK (0, (HF_IN_PM0
| HF_IN_PM1
| HF_DP_SAVED
))),
4175 PADDRH (pm_handle1
),
4177 ** If we received a SAVE DP, switch to the
4178 ** other PM context since the savep may point
4179 ** to the current PM context.
4181 SCR_JUMPR
^ IFFALSE (MASK (HF_DP_SAVED
, HF_DP_SAVED
)),
4183 SCR_REG_REG (sfbr
, SCR_XOR
, HF_ACT_PM
),
4186 ** If we have been interrupt in a PM DATA mini-script,
4187 ** we take the return address from the corresponding
4189 ** This ensure the return address always points to the
4190 ** main DATA script for this transfer.
4192 SCR_JUMP
^ IFTRUE (MASK (0, (HF_IN_PM0
| HF_IN_PM1
))),
4193 PADDRH (pm_handle1
),
4194 SCR_JUMPR
^ IFFALSE (MASK (HF_IN_PM0
, HF_IN_PM0
)),
4196 SCR_LOAD_REL (ia
, 4),
4197 offsetof(struct ccb
, phys
.pm0
.ret
),
4200 SCR_LOAD_REL (ia
, 4),
4201 offsetof(struct ccb
, phys
.pm1
.ret
),
4204 }/*-------------------------< PM_HANDLE1 >-----------------*/,{
4207 ** Update the return address so that it
4208 ** will point after the interrupted MOVE.
4210 SCR_REG_REG (ia
, SCR_ADD
, 8),
4212 SCR_REG_REG (ia1
, SCR_ADDC
, 0),
4214 }/*-------------------------< PM_SAVE >--------------------*/,{
4216 ** Clear all the flags that told us if we were
4217 ** interrupted in a PM DATA mini-script and/or
4218 ** we received a SAVE DP.
4220 SCR_SFBR_REG (HF_REG
, SCR_AND
, (~(HF_IN_PM0
|HF_IN_PM1
|HF_DP_SAVED
))),
4223 ** Choose the current PM context.
4225 SCR_JUMP
^ IFTRUE (MASK (HF_ACT_PM
, HF_ACT_PM
)),
4227 }/*-------------------------< PM0_SAVE >-------------------*/,{
4228 SCR_STORE_REL (ia
, 4),
4229 offsetof(struct ccb
, phys
.pm0
.ret
),
4231 ** If WSR bit is set, either UA and RBC may
4232 ** have to be changed whatever the device wants
4233 ** to ignore this residue ot not.
4235 SCR_FROM_REG (scntl2
),
4237 SCR_CALL
^ IFTRUE (MASK (WSR
, WSR
)),
4238 PADDRH (pm_wsr_handle
),
4240 ** Save the remaining byte count, the updated
4241 ** address and the return address.
4243 SCR_STORE_REL (rbc
, 4),
4244 offsetof(struct ccb
, phys
.pm0
.sg
.size
),
4245 SCR_STORE_REL (ua
, 4),
4246 offsetof(struct ccb
, phys
.pm0
.sg
.addr
),
4248 ** Set the current pointer at the PM0 DATA mini-script.
4250 SCR_LOAD_ABS (temp
, 4),
4251 PADDRH (pm0_data_addr
),
4254 }/*-------------------------< PM1_SAVE >-------------------*/,{
4255 SCR_STORE_REL (ia
, 4),
4256 offsetof(struct ccb
, phys
.pm1
.ret
),
4258 ** If WSR bit is set, either UA and RBC may
4259 ** have been changed whatever the device wants
4260 ** to ignore this residue or not.
4262 SCR_FROM_REG (scntl2
),
4264 SCR_CALL
^ IFTRUE (MASK (WSR
, WSR
)),
4265 PADDRH (pm_wsr_handle
),
4267 ** Save the remaining byte count, the updated
4268 ** address and the return address.
4270 SCR_STORE_REL (rbc
, 4),
4271 offsetof(struct ccb
, phys
.pm1
.sg
.size
),
4272 SCR_STORE_REL (ua
, 4),
4273 offsetof(struct ccb
, phys
.pm1
.sg
.addr
),
4275 ** Set the current pointer at the PM1 DATA mini-script.
4277 SCR_LOAD_ABS (temp
, 4),
4278 PADDRH (pm1_data_addr
),
4281 }/*--------------------------< PM_WSR_HANDLE >-----------------------*/,{
4283 * Phase mismatch handling from SCRIPT with WSR set.
4284 * Such a condition can occur if the chip wants to
4285 * execute a CHMOV(size > 1) when the WSR bit is
4286 * set and the target changes PHASE.
4288 #ifdef SYM_DEBUG_PM_WITH_WSR
4290 * Some debugging may still be needed.:)
4296 * We must move the residual byte to memory.
4298 * UA contains bit 0..31 of the address to
4299 * move the residual byte.
4300 * Move it to the table indirect.
4302 SCR_STORE_REL (ua
, 4),
4303 offsetof (struct ccb
, phys
.wresid
.addr
),
4305 * Increment UA (move address to next position).
4307 SCR_REG_REG (ua
, SCR_ADD
, 1),
4309 SCR_REG_REG (ua1
, SCR_ADDC
, 0),
4311 SCR_REG_REG (ua2
, SCR_ADDC
, 0),
4313 SCR_REG_REG (ua3
, SCR_ADDC
, 0),
4316 * Compute SCRATCHA as:
4317 * - size to transfer = 1 byte.
4318 * - bit 24..31 = high address bit [32...39].
4320 SCR_LOAD_ABS (scratcha
, 4),
4322 SCR_REG_REG (scratcha
, SCR_OR
, 1),
4324 SCR_FROM_REG (rbc3
),
4326 SCR_TO_REG (scratcha3
),
4329 * Move this value to the table indirect.
4331 SCR_STORE_REL (scratcha
, 4),
4332 offsetof (struct ccb
, phys
.wresid
.size
),
4334 * Wait for a valid phase.
4335 * While testing with bogus QUANTUM drives, the C1010
4336 * sometimes raised a spurious phase mismatch with
4337 * WSR and the CHMOV(1) triggered another PM.
4338 * Waiting explicitely for the PHASE seemed to avoid
4339 * the nested phase mismatch. Btw, this didn't happen
4340 * using my IBM drives.
4342 SCR_JUMPR
^ IFFALSE (WHEN (SCR_DATA_IN
)),
4345 * Perform the move of the residual byte.
4347 SCR_CHMOV_TBL
^ SCR_DATA_IN
,
4348 offsetof (struct ccb
, phys
.wresid
),
4350 * We can now handle the phase mismatch with UA fixed.
4351 * RBC[0..23]=0 is a special case that does not require
4352 * a PM context. The C code also checks against this.
4356 SCR_RETURN
^ IFFALSE (DATA (0)),
4358 SCR_FROM_REG (rbc1
),
4360 SCR_RETURN
^ IFFALSE (DATA (0)),
4362 SCR_FROM_REG (rbc2
),
4364 SCR_RETURN
^ IFFALSE (DATA (0)),
4368 * Not only we donnot need a PM context, but this would
4369 * lead to a bogus CHMOV(0). This condition means that
4370 * the residual was the last byte to move from this CHMOV.
4371 * So, we just have to move the current data script pointer
4372 * (i.e. TEMP) to the SCRIPTS address following the
4373 * interrupted CHMOV and jump to dispatcher.
4375 SCR_STORE_ABS (ia
, 4),
4377 SCR_LOAD_ABS (temp
, 4),
4381 }/*--------------------------< WSR_MA_HELPER >-----------------------*/,{
4383 * Helper for the C code when WSR bit is set.
4384 * Perform the move of the residual byte.
4386 SCR_CHMOV_TBL
^ SCR_DATA_IN
,
4387 offsetof (struct ccb
, phys
.wresid
),
4390 }/*-------------------------< ZERO >------------------------*/,{
4392 }/*-------------------------< SCRATCH >---------------------*/,{
4394 }/*-------------------------< SCRATCH1 >--------------------*/,{
4396 }/*-------------------------< PM0_DATA_ADDR >---------------*/,{
4398 }/*-------------------------< PM1_DATA_ADDR >---------------*/,{
4400 }/*-------------------------< SAVED_DSA >-------------------*/,{
4402 }/*-------------------------< SAVED_DRS >-------------------*/,{
4404 }/*-------------------------< DONE_POS >--------------------*/,{
4406 }/*-------------------------< STARTPOS >--------------------*/,{
4408 }/*-------------------------< TARGTBL >---------------------*/,{
4413 ** We may use MEMORY MOVE instructions to load the on chip-RAM,
4414 ** if it happens that mapping PCI memory is not possible.
4415 ** But writing the RAM from the CPU is the preferred method,
4416 ** since PCI 2.2 seems to disallow PCI self-mastering.
4419 #ifdef SCSI_NCR_PCI_MEM_NOT_SUPPORTED
4421 }/*-------------------------< START_RAM >-------------------*/,{
4423 ** Load the script into on-chip RAM,
4424 ** and jump to start point.
4426 SCR_COPY (sizeof (struct script
)),
4427 }/*-------------------------< SCRIPT0_BA >--------------------*/,{
4433 }/*-------------------------< START_RAM64 >--------------------*/,{
4435 ** Load the RAM and start for 64 bit PCI (895A,896).
4436 ** Both scripts (script and scripth) are loaded into
4437 ** the RAM which is 8K (4K for 825A/875/895).
4438 ** We also need to load some 32-63 bit segments
4439 ** address of the SCRIPTS processor.
4440 ** LOAD/STORE ABSOLUTE always refers to on-chip RAM
4441 ** in our implementation. The main memory is
4442 ** accessed using LOAD/STORE DSA RELATIVE.
4444 SCR_LOAD_REL (mmws
, 4),
4445 offsetof (struct ncb
, scr_ram_seg
),
4446 SCR_COPY (sizeof(struct script
)),
4447 }/*-------------------------< SCRIPT0_BA64 >--------------------*/,{
4450 SCR_COPY (sizeof(struct scripth
)),
4451 }/*-------------------------< SCRIPTH0_BA64 >--------------------*/,{
4454 SCR_LOAD_REL (mmrs
, 4),
4455 offsetof (struct ncb
, scr_ram_seg
),
4458 }/*-------------------------< RAM_SEG64 >--------------------*/,{
4461 #endif /* SCSI_NCR_PCI_MEM_NOT_SUPPORTED */
4463 }/*-------------------------< SNOOPTEST >-------------------*/,{
4465 ** Read the variable.
4467 SCR_LOAD_REL (scratcha
, 4),
4468 offsetof(struct ncb
, ncr_cache
),
4469 SCR_STORE_REL (temp
, 4),
4470 offsetof(struct ncb
, ncr_cache
),
4471 SCR_LOAD_REL (temp
, 4),
4472 offsetof(struct ncb
, ncr_cache
),
4473 }/*-------------------------< SNOOPEND >-------------------*/,{
4479 }/*--------------------------------------------------------*/
4482 /*==========================================================
4485 ** Fill in #define dependent parts of the script
4488 **==========================================================
4491 void __init
ncr_script_fill (struct script
* scr
, struct scripth
* scrh
)
4497 for (i
=0; i
<MAX_SCATTER
; i
++) {
4498 *p
++ =SCR_CHMOV_TBL
^ SCR_DATA_IN
;
4499 *p
++ =offsetof (struct dsb
, data
[i
]);
4502 assert ((u_long
)p
== (u_long
)&scr
->data_in
+ sizeof (scr
->data_in
));
4506 for (i
=0; i
<MAX_SCATTER
; i
++) {
4507 *p
++ =SCR_CHMOV_TBL
^ SCR_DATA_OUT
;
4508 *p
++ =offsetof (struct dsb
, data
[i
]);
4511 assert ((u_long
)p
== (u_long
)&scr
->data_out
+ sizeof (scr
->data_out
));
4514 /*==========================================================
4517 ** Copy and rebind a script.
4520 **==========================================================
4524 ncr_script_copy_and_bind (ncb_p np
,ncrcmd
*src
,ncrcmd
*dst
,int len
)
4526 ncrcmd opcode
, new, old
, tmp1
, tmp2
;
4527 ncrcmd
*start
, *end
;
4537 *dst
++ = cpu_to_scr(opcode
);
4540 ** If we forget to change the length
4541 ** in struct script, a field will be
4542 ** padded with 0. This is an illegal
4547 printk (KERN_INFO
"%s: ERROR0 IN SCRIPT at %d.\n",
4548 ncr_name(np
), (int) (src
-start
-1));
4554 ** We use the bogus value 0xf00ff00f ;-)
4555 ** to reserve data area in SCRIPTS.
4557 if (opcode
== SCR_DATA_ZERO
) {
4562 if (DEBUG_FLAGS
& DEBUG_SCRIPT
)
4563 printk (KERN_INFO
"%p: <%x>\n",
4564 (src
-1), (unsigned)opcode
);
4567 ** We don't have to decode ALL commands
4569 switch (opcode
>> 28) {
4573 ** LOAD / STORE DSA relative, don't relocate.
4579 ** LOAD / STORE absolute.
4585 ** COPY has TWO arguments.
4591 if ((tmp1
& RELOC_MASK
) == RELOC_KVAR
)
4593 if ((tmp2
& RELOC_MASK
) == RELOC_KVAR
)
4596 if ((tmp1
^ tmp2
) & 3) {
4597 printk (KERN_ERR
"%s: ERROR1 IN SCRIPT at %d.\n",
4598 ncr_name(np
), (int) (src
-start
-1));
4602 ** If PREFETCH feature not enabled, remove
4603 ** the NO FLUSH bit if present.
4605 if ((opcode
& SCR_NO_FLUSH
) &&
4606 !(np
->features
& FE_PFEN
)) {
4607 dst
[-1] = cpu_to_scr(opcode
& ~SCR_NO_FLUSH
);
4614 ** MOVE/CHMOV (absolute address)
4616 if (!(np
->features
& FE_WIDE
))
4617 dst
[-1] = cpu_to_scr(opcode
| OPC_MOVE
);
4623 ** MOVE/CHMOV (table indirect)
4625 if (!(np
->features
& FE_WIDE
))
4626 dst
[-1] = cpu_to_scr(opcode
| OPC_MOVE
);
4633 ** don't relocate if relative :-)
4635 if (opcode
& 0x00800000)
4637 else if ((opcode
& 0xf8400000) == 0x80400000)/*JUMP64*/
4656 *dst
++ = cpu_to_scr(*src
++);
4662 switch (old
& RELOC_MASK
) {
4663 case RELOC_REGISTER
:
4664 new = (old
& ~RELOC_MASK
) + np
->base_ba
;
4667 new = (old
& ~RELOC_MASK
) + np
->p_script
;
4670 new = (old
& ~RELOC_MASK
) + np
->p_scripth
;
4673 new = (old
& ~RELOC_MASK
) + np
->p_ncb
;
4678 if (((old
& ~RELOC_MASK
) < SCRIPT_KVAR_FIRST
) ||
4679 ((old
& ~RELOC_MASK
) > SCRIPT_KVAR_LAST
))
4680 panic("ncr KVAR out of range");
4681 new = vtobus(script_kvars
[old
& ~RELOC_MASK
]);
4685 /* Don't relocate a 0 address. */
4692 new = 0; /* For 'cc' not to complain */
4693 panic("ncr_script_copy_and_bind: "
4694 "weird relocation %x\n", old
);
4698 *dst
++ = cpu_to_scr(new);
4703 /*==========================================================
4706 ** Auto configuration: attach and init a host adapter.
4709 **==========================================================
4713 ** Linux host data structure.
4721 ** Print something which allows to retrieve the controler type, unit,
4722 ** target, lun concerned by a kernel message.
4725 static void PRINT_TARGET(ncb_p np
, int target
)
4727 printk(KERN_INFO
"%s-<%d,*>: ", ncr_name(np
), target
);
4730 static void PRINT_LUN(ncb_p np
, int target
, int lun
)
4732 printk(KERN_INFO
"%s-<%d,%d>: ", ncr_name(np
), target
, lun
);
4735 static void PRINT_ADDR(Scsi_Cmnd
*cmd
)
4737 struct host_data
*host_data
= (struct host_data
*) cmd
->device
->host
->hostdata
;
4738 PRINT_LUN(host_data
->ncb
, cmd
->device
->id
, cmd
->device
->lun
);
4741 /*==========================================================
4743 ** NCR chip clock divisor table.
4744 ** Divisors are multiplied by 10,000,000 in order to make
4745 ** calculations more simple.
4747 **==========================================================
4751 static u_long div_10M
[] =
4752 {2*_5M
, 3*_5M
, 4*_5M
, 6*_5M
, 8*_5M
, 12*_5M
, 16*_5M
};
4755 /*===============================================================
4757 ** Prepare io register values used by ncr_init() according
4758 ** to selected and supported features.
4760 ** NCR/SYMBIOS chips allow burst lengths of 2, 4, 8, 16, 32, 64,
4761 ** 128 transfers. All chips support at least 16 transfers bursts.
4762 ** The 825A, 875 and 895 chips support bursts of up to 128
4763 ** transfers and the 895A and 896 support bursts of up to 64
4764 ** transfers. All other chips support up to 16 transfers bursts.
4766 ** For PCI 32 bit data transfers each transfer is a DWORD (4 bytes).
4767 ** It is a QUADWORD (8 bytes) for PCI 64 bit data transfers.
4768 ** Only the 896 is able to perform 64 bit data transfers.
4770 ** We use log base 2 (burst length) as internal code, with
4771 ** value 0 meaning "burst disabled".
4773 **===============================================================
4777 * Burst length from burst code.
4779 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
4782 * Burst code from io register bits.
4784 #define burst_code(dmode, ctest4, ctest5) \
4785 (ctest4) & 0x80? 0 : (((dmode) & 0xc0) >> 6) + ((ctest5) & 0x04) + 1
4788 * Set initial io register bits from burst code.
4790 static inline void ncr_init_burst(ncb_p np
, u_char bc
)
4792 np
->rv_ctest4
&= ~0x80;
4793 np
->rv_dmode
&= ~(0x3 << 6);
4794 np
->rv_ctest5
&= ~0x4;
4797 np
->rv_ctest4
|= 0x80;
4801 np
->rv_dmode
|= ((bc
& 0x3) << 6);
4802 np
->rv_ctest5
|= (bc
& 0x4);
4806 #ifdef SCSI_NCR_NVRAM_SUPPORT
4809 ** Get target set-up from Symbios format NVRAM.
4813 ncr_Symbios_setup_target(ncb_p np
, int target
, Symbios_nvram
*nvram
)
4815 tcb_p tp
= &np
->target
[target
];
4816 Symbios_target
*tn
= &nvram
->target
[target
];
4818 tp
->usrsync
= tn
->sync_period
? (tn
->sync_period
+ 3) / 4 : 255;
4819 tp
->usrwide
= tn
->bus_width
== 0x10 ? 1 : 0;
4821 (tn
->flags
& SYMBIOS_QUEUE_TAGS_ENABLED
)? MAX_TAGS
: 0;
4823 if (!(tn
->flags
& SYMBIOS_DISCONNECT_ENABLE
))
4824 tp
->usrflag
|= UF_NODISC
;
4825 if (!(tn
->flags
& SYMBIOS_SCAN_AT_BOOT_TIME
))
4826 tp
->usrflag
|= UF_NOSCAN
;
4830 ** Get target set-up from Tekram format NVRAM.
4834 ncr_Tekram_setup_target(ncb_p np
, int target
, Tekram_nvram
*nvram
)
4836 tcb_p tp
= &np
->target
[target
];
4837 struct Tekram_target
*tn
= &nvram
->target
[target
];
4840 if (tn
->flags
& TEKRAM_SYNC_NEGO
) {
4841 i
= tn
->sync_index
& 0xf;
4842 tp
->usrsync
= Tekram_sync
[i
];
4845 tp
->usrwide
= (tn
->flags
& TEKRAM_WIDE_NEGO
) ? 1 : 0;
4847 if (tn
->flags
& TEKRAM_TAGGED_COMMANDS
) {
4848 tp
->usrtags
= 2 << nvram
->max_tags_index
;
4851 if (!(tn
->flags
& TEKRAM_DISCONNECT_ENABLE
))
4852 tp
->usrflag
= UF_NODISC
;
4854 /* If any device does not support parity, we will not use this option */
4855 if (!(tn
->flags
& TEKRAM_PARITY_CHECK
))
4856 np
->rv_scntl0
&= ~0x0a; /* SCSI parity checking disabled */
4858 #endif /* SCSI_NCR_NVRAM_SUPPORT */
4861 ** Save initial settings of some IO registers.
4862 ** Assumed to have been set by BIOS.
4864 static void __init
ncr_save_initial_setting(ncb_p np
)
4866 np
->sv_scntl0
= INB(nc_scntl0
) & 0x0a;
4867 np
->sv_dmode
= INB(nc_dmode
) & 0xce;
4868 np
->sv_dcntl
= INB(nc_dcntl
) & 0xa8;
4869 np
->sv_ctest3
= INB(nc_ctest3
) & 0x01;
4870 np
->sv_ctest4
= INB(nc_ctest4
) & 0x80;
4871 np
->sv_gpcntl
= INB(nc_gpcntl
);
4872 np
->sv_stest2
= INB(nc_stest2
) & 0x20;
4873 np
->sv_stest4
= INB(nc_stest4
);
4874 np
->sv_stest1
= INB(nc_stest1
);
4876 np
->sv_scntl3
= INB(nc_scntl3
) & 0x07;
4878 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
4879 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
) ){
4881 ** C1010 always uses large fifo, bit 5 rsvd
4882 ** scntl4 used ONLY with C1010
4884 np
->sv_ctest5
= INB(nc_ctest5
) & 0x04 ;
4885 np
->sv_scntl4
= INB(nc_scntl4
);
4888 np
->sv_ctest5
= INB(nc_ctest5
) & 0x24 ;
4894 ** Prepare io register values used by ncr_init()
4895 ** according to selected and supported features.
4897 static int __init
ncr_prepare_setting(ncb_p np
, ncr_nvram
*nvram
)
4903 #ifdef CONFIG_PARISC
4904 char scsi_mode
= -1;
4905 struct hardware_path hwpath
;
4912 np
->maxwide
= (np
->features
& FE_WIDE
)? 1 : 0;
4915 * Guess the frequency of the chip's clock.
4917 if (np
->features
& (FE_ULTRA3
| FE_ULTRA2
))
4918 np
->clock_khz
= 160000;
4919 else if (np
->features
& FE_ULTRA
)
4920 np
->clock_khz
= 80000;
4922 np
->clock_khz
= 40000;
4925 * Get the clock multiplier factor.
4927 if (np
->features
& FE_QUAD
)
4929 else if (np
->features
& FE_DBLR
)
4935 * Measure SCSI clock frequency for chips
4936 * it may vary from assumed one.
4938 if (np
->features
& FE_VARCLK
)
4939 ncr_getclock(np
, np
->multiplier
);
4942 * Divisor to be used for async (timer pre-scaler).
4944 * Note: For C1010 the async divisor is 2(8) if he
4945 * quadrupler is disabled (enabled).
4948 if ( (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
4949 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)) {
4955 i
= np
->clock_divn
- 1;
4957 if (10ul * SCSI_NCR_MIN_ASYNC
* np
->clock_khz
4963 np
->rv_scntl3
= i
+1;
4968 * Save the ultra3 register for the C1010/C1010_66
4971 np
->rv_scntl4
= np
->sv_scntl4
;
4974 * Minimum synchronous period factor supported by the chip.
4975 * Btw, 'period' is in tenths of nanoseconds.
4978 period
= (4 * div_10M
[0] + np
->clock_khz
- 1) / np
->clock_khz
;
4980 #ifdef CONFIG_PARISC
4981 /* Host firmware (PDC) keeps a table for crippling SCSI capabilities.
4982 * Many newer machines export one channel of 53c896 chip
4983 * as SE, 50-pin HD. Also used for Multi-initiator SCSI clusters
4984 * to set the SCSI Initiator ID.
4986 get_pci_node_path(np
->pdev
, &hwpath
);
4987 if (pdc_get_initiator(&hwpath
, &np
->myaddr
, &period
, &np
->maxwide
, &scsi_mode
))
4990 np
->features
|= FE_WIDE
;
4991 if (scsi_mode
>= 0) {
4992 /* C3000 PDC reports period/mode */
4993 driver_setup
.diff_support
= 0;
4995 case 0: np
->scsi_mode
= SMODE_SE
; break;
4996 case 1: np
->scsi_mode
= SMODE_HVD
; break;
4997 case 2: np
->scsi_mode
= SMODE_LVD
; break;
5004 if (period
<= 250) np
->minsync
= 10;
5005 else if (period
<= 303) np
->minsync
= 11;
5006 else if (period
<= 500) np
->minsync
= 12;
5007 else np
->minsync
= (period
+ 40 - 1) / 40;
5010 * Fix up. If sync. factor is 10 (160000Khz clock) and chip
5011 * supports ultra3, then min. sync. period 12.5ns and the factor is 9
5012 * Also keep track of the maximum offset in ST mode which may differ
5013 * from the maximum offset in DT mode. For now hardcoded to 31.
5016 if (np
->features
& FE_ULTRA3
) {
5017 if (np
->minsync
== 10)
5019 np
->maxoffs_st
= 31;
5022 np
->maxoffs_st
= np
->maxoffs
;
5025 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
5027 * Transfer period minimums: SCSI-1 200 (50); Fast 100 (25)
5028 * Ultra 50 (12); Ultra2 (6); Ultra3 (3)
5031 if (np
->minsync
< 25 && !(np
->features
& (FE_ULTRA
|FE_ULTRA2
|FE_ULTRA3
)))
5033 else if (np
->minsync
< 12 && (np
->features
& FE_ULTRA
))
5035 else if (np
->minsync
< 10 && (np
->features
& FE_ULTRA2
))
5037 else if (np
->minsync
< 9 && (np
->features
& FE_ULTRA3
))
5041 * Maximum synchronous period factor supported by the chip.
5044 period
= (11 * div_10M
[np
->clock_divn
- 1]) / (4 * np
->clock_khz
);
5045 np
->maxsync
= period
> 2540 ? 254 : period
/ 10;
5048 ** 64 bit (53C895A or 53C896) ?
5050 if (np
->features
& FE_DAC
) {
5051 if (np
->features
& FE_DAC_IN_USE
)
5052 np
->rv_ccntl1
|= (XTIMOD
| EXTIBMV
);
5054 np
->rv_ccntl1
|= (DDAC
);
5058 ** Phase mismatch handled by SCRIPTS (53C895A, 53C896 or C1010) ?
5060 if (np
->features
& FE_NOPM
)
5061 np
->rv_ccntl0
|= (ENPMJ
);
5064 ** Prepare initial value of other IO registers
5066 #if defined SCSI_NCR_TRUST_BIOS_SETTING
5067 np
->rv_scntl0
= np
->sv_scntl0
;
5068 np
->rv_dmode
= np
->sv_dmode
;
5069 np
->rv_dcntl
= np
->sv_dcntl
;
5070 np
->rv_ctest3
= np
->sv_ctest3
;
5071 np
->rv_ctest4
= np
->sv_ctest4
;
5072 np
->rv_ctest5
= np
->sv_ctest5
;
5073 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest4
, np
->sv_ctest5
);
5077 ** Select burst length (dwords)
5079 burst_max
= driver_setup
.burst_max
;
5080 if (burst_max
== 255)
5081 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest4
, np
->sv_ctest5
);
5084 if (burst_max
> np
->maxburst
)
5085 burst_max
= np
->maxburst
;
5088 ** DEL 352 - 53C810 Rev x11 - Part Number 609-0392140 - ITEM 2.
5089 ** This chip and the 860 Rev 1 may wrongly use PCI cache line
5090 ** based transactions on LOAD/STORE instructions. So we have
5091 ** to prevent these chips from using such PCI transactions in
5092 ** this driver. The generic sym53c8xx driver that does not use
5093 ** LOAD/STORE instructions does not need this work-around.
5095 if ((np
->device_id
== PCI_DEVICE_ID_NCR_53C810
&&
5096 np
->revision_id
>= 0x10 && np
->revision_id
<= 0x11) ||
5097 (np
->device_id
== PCI_DEVICE_ID_NCR_53C860
&&
5098 np
->revision_id
<= 0x1))
5099 np
->features
&= ~(FE_WRIE
|FE_ERL
|FE_ERMP
);
5102 ** DEL ? - 53C1010 Rev 1 - Part Number 609-0393638
5103 ** 64-bit Slave Cycles must be disabled.
5105 if ( ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) && (np
->revision_id
< 0x02) )
5106 || (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
) )
5107 np
->rv_ccntl1
|= 0x10;
5110 ** Select all supported special features.
5111 ** If we are using on-board RAM for scripts, prefetch (PFEN)
5112 ** does not help, but burst op fetch (BOF) does.
5113 ** Disabling PFEN makes sure BOF will be used.
5115 if (np
->features
& FE_ERL
)
5116 np
->rv_dmode
|= ERL
; /* Enable Read Line */
5117 if (np
->features
& FE_BOF
)
5118 np
->rv_dmode
|= BOF
; /* Burst Opcode Fetch */
5119 if (np
->features
& FE_ERMP
)
5120 np
->rv_dmode
|= ERMP
; /* Enable Read Multiple */
5122 if ((np
->features
& FE_PFEN
) && !np
->base2_ba
)
5124 if (np
->features
& FE_PFEN
)
5126 np
->rv_dcntl
|= PFEN
; /* Prefetch Enable */
5127 if (np
->features
& FE_CLSE
)
5128 np
->rv_dcntl
|= CLSE
; /* Cache Line Size Enable */
5129 if (np
->features
& FE_WRIE
)
5130 np
->rv_ctest3
|= WRIE
; /* Write and Invalidate */
5133 if ( (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
5134 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
) &&
5135 (np
->features
& FE_DFS
))
5136 np
->rv_ctest5
|= DFS
; /* Dma Fifo Size */
5137 /* C1010/C1010_66 always large fifo */
5140 ** Select some other
5142 if (driver_setup
.master_parity
)
5143 np
->rv_ctest4
|= MPEE
; /* Master parity checking */
5144 if (driver_setup
.scsi_parity
)
5145 np
->rv_scntl0
|= 0x0a; /* full arb., ena parity, par->ATN */
5147 #ifdef SCSI_NCR_NVRAM_SUPPORT
5149 ** Get parity checking, host ID and verbose mode from NVRAM
5152 switch(nvram
->type
) {
5153 case SCSI_NCR_TEKRAM_NVRAM
:
5154 np
->myaddr
= nvram
->data
.Tekram
.host_id
& 0x0f;
5156 case SCSI_NCR_SYMBIOS_NVRAM
:
5157 if (!(nvram
->data
.Symbios
.flags
& SYMBIOS_PARITY_ENABLE
))
5158 np
->rv_scntl0
&= ~0x0a;
5159 np
->myaddr
= nvram
->data
.Symbios
.host_id
& 0x0f;
5160 if (nvram
->data
.Symbios
.flags
& SYMBIOS_VERBOSE_MSGS
)
5167 ** Get SCSI addr of host adapter (set by bios?).
5169 if (np
->myaddr
== 255) {
5170 np
->myaddr
= INB(nc_scid
) & 0x07;
5172 np
->myaddr
= SCSI_NCR_MYADDR
;
5175 #endif /* SCSI_NCR_TRUST_BIOS_SETTING */
5178 * Prepare initial io register bits for burst length
5180 ncr_init_burst(np
, burst_max
);
5183 ** Set SCSI BUS mode.
5185 ** - ULTRA2 chips (895/895A/896)
5186 ** and ULTRA 3 chips (1010) report the current
5187 ** BUS mode through the STEST4 IO register.
5188 ** - For previous generation chips (825/825A/875),
5189 ** user has to tell us how to check against HVD,
5190 ** since a 100% safe algorithm is not possible.
5192 np
->scsi_mode
= SMODE_SE
;
5193 if (np
->features
& (FE_ULTRA2
| FE_ULTRA3
))
5194 np
->scsi_mode
= (np
->sv_stest4
& SMODE
);
5195 else if (np
->features
& FE_DIFF
) {
5196 switch(driver_setup
.diff_support
) {
5197 case 4: /* Trust previous settings if present, then GPIO3 */
5198 if (np
->sv_scntl3
) {
5199 if (np
->sv_stest2
& 0x20)
5200 np
->scsi_mode
= SMODE_HVD
;
5203 case 3: /* SYMBIOS controllers report HVD through GPIO3 */
5204 if (nvram
&& nvram
->type
!= SCSI_NCR_SYMBIOS_NVRAM
)
5206 if (INB(nc_gpreg
) & 0x08)
5208 case 2: /* Set HVD unconditionally */
5209 np
->scsi_mode
= SMODE_HVD
;
5210 case 1: /* Trust previous settings for HVD */
5211 if (np
->sv_stest2
& 0x20)
5212 np
->scsi_mode
= SMODE_HVD
;
5214 default:/* Don't care about HVD */
5218 if (np
->scsi_mode
== SMODE_HVD
)
5219 np
->rv_stest2
|= 0x20;
5222 ** Set LED support from SCRIPTS.
5223 ** Ignore this feature for boards known to use a
5224 ** specific GPIO wiring and for the 895A or 896
5225 ** that drive the LED directly.
5226 ** Also probe initial setting of GPIO0 as output.
5228 if ((driver_setup
.led_pin
||
5229 (nvram
&& nvram
->type
== SCSI_NCR_SYMBIOS_NVRAM
)) &&
5230 !(np
->features
& FE_LEDC
) && !(np
->sv_gpcntl
& 0x01))
5231 np
->features
|= FE_LED0
;
5236 switch(driver_setup
.irqm
& 3) {
5238 np
->rv_dcntl
|= IRQM
;
5241 np
->rv_dcntl
|= (np
->sv_dcntl
& IRQM
);
5248 ** Configure targets according to driver setup.
5249 ** If NVRAM present get targets setup from NVRAM.
5250 ** Allow to override sync, wide and NOSCAN from
5251 ** boot command line.
5253 for (i
= 0 ; i
< MAX_TARGET
; i
++) {
5254 tcb_p tp
= &np
->target
[i
];
5257 #ifdef SCSI_NCR_NVRAM_SUPPORT
5259 switch(nvram
->type
) {
5260 case SCSI_NCR_TEKRAM_NVRAM
:
5261 ncr_Tekram_setup_target(np
, i
, &nvram
->data
.Tekram
);
5263 case SCSI_NCR_SYMBIOS_NVRAM
:
5264 ncr_Symbios_setup_target(np
, i
, &nvram
->data
.Symbios
);
5267 if (driver_setup
.use_nvram
& 0x2)
5268 tp
->usrsync
= driver_setup
.default_sync
;
5269 if (driver_setup
.use_nvram
& 0x4)
5270 tp
->usrwide
= driver_setup
.max_wide
;
5271 if (driver_setup
.use_nvram
& 0x8)
5272 tp
->usrflag
&= ~UF_NOSCAN
;
5278 tp
->usrsync
= driver_setup
.default_sync
;
5279 tp
->usrwide
= driver_setup
.max_wide
;
5280 tp
->usrtags
= MAX_TAGS
;
5281 if (!driver_setup
.disconnection
)
5282 np
->target
[i
].usrflag
= UF_NODISC
;
5287 ** Announce all that stuff to user.
5290 i
= nvram
? nvram
->type
: 0;
5291 printk(KERN_INFO
"%s: %sID %d, Fast-%d%s%s\n", ncr_name(np
),
5292 i
== SCSI_NCR_SYMBIOS_NVRAM
? "Symbios format NVRAM, " :
5293 (i
== SCSI_NCR_TEKRAM_NVRAM
? "Tekram format NVRAM, " : ""),
5295 np
->minsync
< 10 ? 80 :
5296 (np
->minsync
< 12 ? 40 : (np
->minsync
< 25 ? 20 : 10) ),
5297 (np
->rv_scntl0
& 0xa) ? ", Parity Checking" : ", NO Parity",
5298 (np
->rv_stest2
& 0x20) ? ", Differential" : "");
5300 if (bootverbose
> 1) {
5301 printk (KERN_INFO
"%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
5302 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
5303 ncr_name(np
), np
->sv_scntl3
, np
->sv_dmode
, np
->sv_dcntl
,
5304 np
->sv_ctest3
, np
->sv_ctest4
, np
->sv_ctest5
);
5306 printk (KERN_INFO
"%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
5307 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
5308 ncr_name(np
), np
->rv_scntl3
, np
->rv_dmode
, np
->rv_dcntl
,
5309 np
->rv_ctest3
, np
->rv_ctest4
, np
->rv_ctest5
);
5312 if (bootverbose
&& np
->base2_ba
)
5313 printk (KERN_INFO
"%s: on-chip RAM at 0x%lx\n",
5314 ncr_name(np
), np
->base2_ba
);
5320 #ifdef SCSI_NCR_DEBUG_NVRAM
5322 void __init
ncr_display_Symbios_nvram(ncb_p np
, Symbios_nvram
*nvram
)
5326 /* display Symbios nvram host data */
5327 printk(KERN_DEBUG
"%s: HOST ID=%d%s%s%s%s%s\n",
5328 ncr_name(np
), nvram
->host_id
& 0x0f,
5329 (nvram
->flags
& SYMBIOS_SCAM_ENABLE
) ? " SCAM" :"",
5330 (nvram
->flags
& SYMBIOS_PARITY_ENABLE
) ? " PARITY" :"",
5331 (nvram
->flags
& SYMBIOS_VERBOSE_MSGS
) ? " VERBOSE" :"",
5332 (nvram
->flags
& SYMBIOS_CHS_MAPPING
) ? " CHS_ALT" :"",
5333 (nvram
->flags1
& SYMBIOS_SCAN_HI_LO
) ? " HI_LO" :"");
5335 /* display Symbios nvram drive data */
5336 for (i
= 0 ; i
< 15 ; i
++) {
5337 struct Symbios_target
*tn
= &nvram
->target
[i
];
5338 printk(KERN_DEBUG
"%s-%d:%s%s%s%s WIDTH=%d SYNC=%d TMO=%d\n",
5340 (tn
->flags
& SYMBIOS_DISCONNECT_ENABLE
) ? " DISC" : "",
5341 (tn
->flags
& SYMBIOS_SCAN_AT_BOOT_TIME
) ? " SCAN_BOOT" : "",
5342 (tn
->flags
& SYMBIOS_SCAN_LUNS
) ? " SCAN_LUNS" : "",
5343 (tn
->flags
& SYMBIOS_QUEUE_TAGS_ENABLED
)? " TCQ" : "",
5345 tn
->sync_period
/ 4,
5350 static u_char Tekram_boot_delay
[7] __initdata
= {3, 5, 10, 20, 30, 60, 120};
5352 void __init
ncr_display_Tekram_nvram(ncb_p np
, Tekram_nvram
*nvram
)
5354 int i
, tags
, boot_delay
;
5357 /* display Tekram nvram host data */
5358 tags
= 2 << nvram
->max_tags_index
;
5360 if (nvram
->boot_delay_index
< 6)
5361 boot_delay
= Tekram_boot_delay
[nvram
->boot_delay_index
];
5362 switch((nvram
->flags
& TEKRAM_REMOVABLE_FLAGS
) >> 6) {
5364 case 0: rem
= ""; break;
5365 case 1: rem
= " REMOVABLE=boot device"; break;
5366 case 2: rem
= " REMOVABLE=all"; break;
5370 "%s: HOST ID=%d%s%s%s%s%s%s%s%s%s BOOT DELAY=%d tags=%d\n",
5371 ncr_name(np
), nvram
->host_id
& 0x0f,
5372 (nvram
->flags1
& SYMBIOS_SCAM_ENABLE
) ? " SCAM" :"",
5373 (nvram
->flags
& TEKRAM_MORE_THAN_2_DRIVES
) ? " >2DRIVES" :"",
5374 (nvram
->flags
& TEKRAM_DRIVES_SUP_1GB
) ? " >1GB" :"",
5375 (nvram
->flags
& TEKRAM_RESET_ON_POWER_ON
) ? " RESET" :"",
5376 (nvram
->flags
& TEKRAM_ACTIVE_NEGATION
) ? " ACT_NEG" :"",
5377 (nvram
->flags
& TEKRAM_IMMEDIATE_SEEK
) ? " IMM_SEEK" :"",
5378 (nvram
->flags
& TEKRAM_SCAN_LUNS
) ? " SCAN_LUNS" :"",
5379 (nvram
->flags1
& TEKRAM_F2_F6_ENABLED
) ? " F2_F6" :"",
5380 rem
, boot_delay
, tags
);
5382 /* display Tekram nvram drive data */
5383 for (i
= 0; i
<= 15; i
++) {
5385 struct Tekram_target
*tn
= &nvram
->target
[i
];
5386 j
= tn
->sync_index
& 0xf;
5387 sync
= Tekram_sync
[j
];
5388 printk(KERN_DEBUG
"%s-%d:%s%s%s%s%s%s PERIOD=%d\n",
5390 (tn
->flags
& TEKRAM_PARITY_CHECK
) ? " PARITY" : "",
5391 (tn
->flags
& TEKRAM_SYNC_NEGO
) ? " SYNC" : "",
5392 (tn
->flags
& TEKRAM_DISCONNECT_ENABLE
) ? " DISC" : "",
5393 (tn
->flags
& TEKRAM_START_CMD
) ? " START" : "",
5394 (tn
->flags
& TEKRAM_TAGGED_COMMANDS
) ? " TCQ" : "",
5395 (tn
->flags
& TEKRAM_WIDE_NEGO
) ? " WIDE" : "",
5399 #endif /* SCSI_NCR_DEBUG_NVRAM */
5402 ** Host attach and initialisations.
5404 ** Allocate host data and ncb structure.
5405 ** Request IO region and remap MMIO region.
5406 ** Do chip initialization.
5407 ** If all is OK, install interrupt handling and
5408 ** start the timer daemon.
5412 ncr_attach (Scsi_Host_Template
*tpnt
, int unit
, ncr_device
*device
)
5414 struct host_data
*host_data
;
5416 struct Scsi_Host
*instance
= 0;
5418 ncr_nvram
*nvram
= device
->nvram
;
5421 printk(KERN_INFO NAME53C
"%s-%d: rev 0x%x on pci bus %d device %d function %d "
5427 device
->chip
.name
, unit
, device
->chip
.revision_id
,
5428 device
->slot
.bus
, (device
->slot
.device_fn
& 0xf8) >> 3,
5429 device
->slot
.device_fn
& 7,
5431 __irq_itoa(device
->slot
.irq
));
5437 ** Allocate host_data structure
5439 if (!(instance
= scsi_register(tpnt
, sizeof(*host_data
))))
5441 host_data
= (struct host_data
*) instance
->hostdata
;
5444 ** Allocate the host control block.
5446 np
= __m_calloc_dma(device
->pdev
, sizeof(struct ncb
), "NCB");
5449 NCR_INIT_LOCK_NCB(np
);
5450 np
->pdev
= device
->pdev
;
5451 np
->p_ncb
= vtobus(np
);
5452 host_data
->ncb
= np
;
5455 ** Store input informations in the host data structure.
5457 strncpy(np
->chip_name
, device
->chip
.name
, sizeof(np
->chip_name
) - 1);
5459 np
->verbose
= driver_setup
.verbose
;
5460 sprintf(np
->inst_name
, NAME53C
"%s-%d", np
->chip_name
, np
->unit
);
5461 np
->device_id
= device
->chip
.device_id
;
5462 np
->revision_id
= device
->chip
.revision_id
;
5463 np
->bus
= device
->slot
.bus
;
5464 np
->device_fn
= device
->slot
.device_fn
;
5465 np
->features
= device
->chip
.features
;
5466 np
->clock_divn
= device
->chip
.nr_divisor
;
5467 np
->maxoffs
= device
->chip
.offset_max
;
5468 np
->maxburst
= device
->chip
.burst_max
;
5469 np
->myaddr
= device
->host_id
;
5472 ** Allocate the start queue.
5474 np
->squeue
= (ncrcmd
*)
5475 m_calloc_dma(sizeof(ncrcmd
)*(MAX_START
*2), "SQUEUE");
5478 np
->p_squeue
= vtobus(np
->squeue
);
5481 ** Allocate the done queue.
5483 np
->dqueue
= (ncrcmd
*)
5484 m_calloc_dma(sizeof(ncrcmd
)*(MAX_START
*2), "DQUEUE");
5489 ** Allocate the target bus address array.
5491 np
->targtbl
= (u_int32
*) m_calloc_dma(256, "TARGTBL");
5496 ** Allocate SCRIPTS areas
5498 np
->script0
= (struct script
*)
5499 m_calloc_dma(sizeof(struct script
), "SCRIPT");
5502 np
->scripth0
= (struct scripth
*)
5503 m_calloc_dma(sizeof(struct scripth
), "SCRIPTH");
5508 ** Initialyze the CCB free queue and,
5509 ** allocate some CCB. We need at least ONE.
5511 xpt_que_init(&np
->free_ccbq
);
5512 xpt_que_init(&np
->b0_ccbq
);
5513 if (!ncr_alloc_ccb(np
))
5517 ** Initialize timer structure
5520 init_timer(&np
->timer
);
5521 np
->timer
.data
= (unsigned long) np
;
5522 np
->timer
.function
= sym53c8xx_timeout
;
5525 ** Try to map the controller chip to
5526 ** virtual and physical memory.
5529 np
->base_ba
= device
->slot
.base
;
5530 np
->base_ws
= (np
->features
& FE_IO256
)? 256 : 128;
5531 np
->base2_ba
= (np
->features
& FE_RAM
)? device
->slot
.base_2
: 0;
5533 #ifndef SCSI_NCR_IOMAPPED
5534 np
->base_va
= remap_pci_mem(device
->slot
.base_c
, np
->base_ws
);
5536 printk(KERN_ERR
"%s: can't map PCI MMIO region\n",ncr_name(np
));
5539 else if (bootverbose
> 1)
5540 printk(KERN_INFO
"%s: using memory mapped IO\n", ncr_name(np
));
5543 ** Make the controller's registers available.
5544 ** Now the INB INW INL OUTB OUTW OUTL macros
5545 ** can be used safely.
5548 np
->reg
= (struct ncr_reg
*) np
->base_va
;
5550 #endif /* !defined SCSI_NCR_IOMAPPED */
5553 ** If on-chip RAM is used, make sure SCRIPTS isn't too large.
5555 if (np
->base2_ba
&& sizeof(struct script
) > 4096) {
5556 printk(KERN_ERR
"%s: script too large.\n", ncr_name(np
));
5561 ** Try to map the controller chip into iospace.
5564 if (device
->slot
.io_port
) {
5565 request_region(device
->slot
.io_port
, np
->base_ws
, NAME53C8XX
);
5566 np
->base_io
= device
->slot
.io_port
;
5569 #ifdef SCSI_NCR_NVRAM_SUPPORT
5571 switch(nvram
->type
) {
5572 case SCSI_NCR_SYMBIOS_NVRAM
:
5573 #ifdef SCSI_NCR_DEBUG_NVRAM
5574 ncr_display_Symbios_nvram(np
, &nvram
->data
.Symbios
);
5577 case SCSI_NCR_TEKRAM_NVRAM
:
5578 #ifdef SCSI_NCR_DEBUG_NVRAM
5579 ncr_display_Tekram_nvram(np
, &nvram
->data
.Tekram
);
5584 #ifdef SCSI_NCR_DEBUG_NVRAM
5585 printk(KERN_DEBUG
"%s: NVRAM: None or invalid data.\n", ncr_name(np
));
5592 ** Save setting of some IO registers, so we will
5593 ** be able to probe specific implementations.
5595 ncr_save_initial_setting (np
);
5598 ** Reset the chip now, since it has been reported
5599 ** that SCSI clock calibration may not work properly
5600 ** if the chip is currently active.
5602 ncr_chip_reset (np
);
5605 ** Do chip dependent initialization.
5607 (void) ncr_prepare_setting(np
, nvram
);
5610 ** Check the PCI clock frequency if needed.
5612 ** Must be done after ncr_prepare_setting since it destroys
5613 ** STEST1 that is used to probe for the clock multiplier.
5615 ** The range is currently [22688 - 45375 Khz], given
5616 ** the values used by ncr_getclock().
5617 ** This calibration of the frequecy measurement
5618 ** algorithm against the PCI clock frequency is only
5619 ** performed if the driver has had to measure the SCSI
5620 ** clock due to other heuristics not having been enough
5621 ** to deduce the SCSI clock frequency.
5623 ** When the chip has been initialized correctly by the
5624 ** SCSI BIOS, the driver deduces the presence of the
5625 ** clock multiplier and the value of the SCSI clock from
5626 ** initial values of IO registers, and therefore no
5627 ** clock measurement is performed.
5628 ** Normally the driver should never have to measure any
5629 ** clock, unless the controller may use a 80 MHz clock
5630 ** or has a clock multiplier and any of the following
5631 ** condition is met:
5633 ** - No SCSI BIOS is present.
5634 ** - SCSI BIOS did'nt enable the multiplier for some reason.
5635 ** - User has disabled the controller from the SCSI BIOS.
5636 ** - User booted the O/S from another O/S that did'nt enable
5637 ** the multiplier for some reason.
5639 ** As a result, the driver may only have to measure some
5640 ** frequency in very unusual situations.
5642 ** For this reality test against the PCI clock to really
5643 ** protect against flaws in the udelay() calibration or
5644 ** driver problem that affect the clock measurement
5645 ** algorithm, the actual PCI clock frequency must be 33 MHz.
5647 i
= np
->pciclock_max
? ncr_getpciclock(np
) : 0;
5648 if (i
&& (i
< np
->pciclock_min
|| i
> np
->pciclock_max
)) {
5649 printk(KERN_ERR
"%s: PCI clock (%u KHz) is out of range "
5650 "[%u KHz - %u KHz].\n",
5651 ncr_name(np
), i
, np
->pciclock_min
, np
->pciclock_max
);
5656 ** Patch script to physical addresses
5658 ncr_script_fill (&script0
, &scripth0
);
5660 np
->p_script
= vtobus(np
->script0
);
5661 np
->p_scripth
= vtobus(np
->scripth0
);
5662 np
->p_scripth0
= np
->p_scripth
;
5665 np
->p_script
= np
->base2_ba
;
5666 if (np
->features
& FE_RAM8K
) {
5667 np
->base2_ws
= 8192;
5668 np
->p_scripth
= np
->p_script
+ 4096;
5669 #if BITS_PER_LONG > 32
5670 np
->scr_ram_seg
= cpu_to_scr(np
->base2_ba
>> 32);
5674 np
->base2_ws
= 4096;
5675 #ifndef SCSI_NCR_PCI_MEM_NOT_SUPPORTED
5677 remap_pci_mem(device
->slot
.base_2_c
, np
->base2_ws
);
5678 if (!np
->base2_va
) {
5679 printk(KERN_ERR
"%s: can't map PCI MEMORY region\n",
5686 ncr_script_copy_and_bind (np
, (ncrcmd
*) &script0
, (ncrcmd
*) np
->script0
, sizeof(struct script
));
5687 ncr_script_copy_and_bind (np
, (ncrcmd
*) &scripth0
, (ncrcmd
*) np
->scripth0
, sizeof(struct scripth
));
5690 ** Patch some variables in SCRIPTS
5692 np
->scripth0
->pm0_data_addr
[0] =
5693 cpu_to_scr(NCB_SCRIPT_PHYS(np
, pm0_data
));
5694 np
->scripth0
->pm1_data_addr
[0] =
5695 cpu_to_scr(NCB_SCRIPT_PHYS(np
, pm1_data
));
5698 ** Patch if not Ultra 3 - Do not write to scntl4
5700 if (np
->features
& FE_ULTRA3
) {
5701 np
->script0
->resel_scntl4
[0] = cpu_to_scr(SCR_LOAD_REL (scntl4
, 1));
5702 np
->script0
->resel_scntl4
[1] = cpu_to_scr(offsetof(struct tcb
, uval
));
5706 #ifdef SCSI_NCR_PCI_MEM_NOT_SUPPORTED
5707 np
->scripth0
->script0_ba
[0] = cpu_to_scr(vtobus(np
->script0
));
5708 np
->scripth0
->script0_ba64
[0] = cpu_to_scr(vtobus(np
->script0
));
5709 np
->scripth0
->scripth0_ba64
[0] = cpu_to_scr(vtobus(np
->scripth0
));
5710 np
->scripth0
->ram_seg64
[0] = np
->scr_ram_seg
;
5713 ** Prepare the idle and invalid task actions.
5715 np
->idletask
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
5716 np
->idletask
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l
));
5717 np
->p_idletask
= NCB_PHYS(np
, idletask
);
5719 np
->notask
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
5720 np
->notask
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l
));
5721 np
->p_notask
= NCB_PHYS(np
, notask
);
5723 np
->bad_i_t_l
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
5724 np
->bad_i_t_l
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l
));
5725 np
->p_bad_i_t_l
= NCB_PHYS(np
, bad_i_t_l
);
5727 np
->bad_i_t_l_q
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
5728 np
->bad_i_t_l_q
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
,bad_i_t_l_q
));
5729 np
->p_bad_i_t_l_q
= NCB_PHYS(np
, bad_i_t_l_q
);
5732 ** Allocate and prepare the bad lun table.
5734 np
->badluntbl
= m_calloc_dma(256, "BADLUNTBL");
5738 assert (offsetof(struct lcb
, resel_task
) == 0);
5739 np
->resel_badlun
= cpu_to_scr(NCB_SCRIPTH_PHYS(np
, resel_bad_lun
));
5741 for (i
= 0 ; i
< 64 ; i
++)
5742 np
->badluntbl
[i
] = cpu_to_scr(NCB_PHYS(np
, resel_badlun
));
5745 ** Prepare the target bus address array.
5747 np
->scripth0
->targtbl
[0] = cpu_to_scr(vtobus(np
->targtbl
));
5748 for (i
= 0 ; i
< MAX_TARGET
; i
++) {
5749 np
->targtbl
[i
] = cpu_to_scr(NCB_PHYS(np
, target
[i
]));
5750 np
->target
[i
].b_luntbl
= cpu_to_scr(vtobus(np
->badluntbl
));
5751 np
->target
[i
].b_lun0
= cpu_to_scr(NCB_PHYS(np
, resel_badlun
));
5755 ** Patch the script for LED support.
5758 if (np
->features
& FE_LED0
) {
5759 np
->script0
->idle
[0] =
5760 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_OR
, 0x01));
5761 np
->script0
->reselected
[0] =
5762 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
5763 np
->script0
->start
[0] =
5764 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
5768 ** Patch the script to provide an extra clock cycle on
5769 ** data out phase - 53C1010_66MHz part only.
5770 ** (Fixed in rev. 1 of the chip)
5772 if (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
&&
5773 np
->revision_id
< 1){
5774 np
->script0
->datao_phase
[0] =
5775 cpu_to_scr(SCR_REG_REG(scntl4
, SCR_OR
, 0x0c));
5778 #ifdef SCSI_NCR_IARB_SUPPORT
5780 ** If user does not want to use IMMEDIATE ARBITRATION
5781 ** when we are reselected while attempting to arbitrate,
5782 ** patch the SCRIPTS accordingly with a SCRIPT NO_OP.
5784 if (!(driver_setup
.iarb
& 1))
5785 np
->script0
->ungetjob
[0] = cpu_to_scr(SCR_NO_OP
);
5787 ** If user wants IARB to be set when we win arbitration
5788 ** and have other jobs, compute the max number of consecutive
5789 ** settings of IARB hint before we leave devices a chance to
5790 ** arbitrate for reselection.
5792 np
->iarb_max
= (driver_setup
.iarb
>> 4);
5796 ** DEL 472 - 53C896 Rev 1 - Part Number 609-0393055 - ITEM 5.
5798 if (np
->device_id
== PCI_DEVICE_ID_NCR_53C896
&&
5799 np
->revision_id
<= 0x1 && (np
->features
& FE_NOPM
)) {
5800 np
->scatter
= ncr_scatter_896R1
;
5801 np
->script0
->datai_phase
[0] = cpu_to_scr(SCR_JUMP
);
5802 np
->script0
->datai_phase
[1] =
5803 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, tweak_pmj
));
5804 np
->script0
->datao_phase
[0] = cpu_to_scr(SCR_JUMP
);
5805 np
->script0
->datao_phase
[1] =
5806 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, tweak_pmj
));
5810 np
->scatter
= ncr_scatter_896R1
;
5812 np
->scatter
= ncr_scatter
;
5817 ** We should use ncr_soft_reset(), but we donnot want to do
5818 ** so, since we may not be safe if ABRT interrupt occurs due
5819 ** to the BIOS or previous O/S having enable this interrupt.
5821 ** For C1010 need to set ABRT bit prior to SRST if SCRIPTs
5822 ** are running. Not true in this case.
5827 ** Now check the cache handling of the pci chipset.
5830 if (ncr_snooptest (np
)) {
5831 printk (KERN_ERR
"CACHE INCORRECTLY CONFIGURED.\n");
5836 ** Install the interrupt handler.
5837 ** If we synchonize the C code with SCRIPTS on interrupt,
5838 ** we donnot want to share the INTR line at all.
5840 if (request_irq(device
->slot
.irq
, sym53c8xx_intr
,
5841 #ifdef SCSI_NCR_PCIQ_SYNC_ON_INTR
5842 ((driver_setup
.irqm
& 0x20) ? 0 : SA_INTERRUPT
),
5844 ((driver_setup
.irqm
& 0x10) ? 0 : SA_SHIRQ
) |
5845 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,0)
5846 ((driver_setup
.irqm
& 0x20) ? 0 : SA_INTERRUPT
),
5852 printk(KERN_ERR
"%s: request irq %d failure\n",
5853 ncr_name(np
), device
->slot
.irq
);
5856 np
->irq
= device
->slot
.irq
;
5859 ** After SCSI devices have been opened, we cannot
5860 ** reset the bus safely, so we do it here.
5861 ** Interrupt handler does the real work.
5862 ** Process the reset exception,
5863 ** if interrupts are not enabled yet.
5864 ** Then enable disconnects.
5866 NCR_LOCK_NCB(np
, flags
);
5867 if (ncr_reset_scsi_bus(np
, 0, driver_setup
.settle_delay
) != 0) {
5868 printk(KERN_ERR
"%s: FATAL ERROR: CHECK SCSI BUS - CABLES, TERMINATION, DEVICE POWER etc.!\n", ncr_name(np
));
5870 NCR_UNLOCK_NCB(np
, flags
);
5876 ** The middle-level SCSI driver does not
5877 ** wait for devices to settle.
5878 ** Wait synchronously if more than 2 seconds.
5880 if (driver_setup
.settle_delay
> 2) {
5881 printk(KERN_INFO
"%s: waiting %d seconds for scsi devices to settle...\n",
5882 ncr_name(np
), driver_setup
.settle_delay
);
5883 MDELAY (1000 * driver_setup
.settle_delay
);
5887 ** start the timeout daemon
5893 ** use SIMPLE TAG messages by default
5895 #ifdef SCSI_NCR_ALWAYS_SIMPLE_TAG
5896 np
->order
= M_SIMPLE_TAG
;
5901 ** Fill Linux host instance structure
5902 ** and return success.
5904 instance
->max_channel
= 0;
5905 instance
->this_id
= np
->myaddr
;
5906 instance
->max_id
= np
->maxwide
? 16 : 8;
5907 instance
->max_lun
= MAX_LUN
;
5908 #ifndef SCSI_NCR_IOMAPPED
5909 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,29)
5910 instance
->base
= (unsigned long) np
->reg
;
5912 instance
->base
= (char *) np
->reg
;
5915 instance
->irq
= np
->irq
;
5916 instance
->unique_id
= np
->base_io
;
5917 instance
->io_port
= np
->base_io
;
5918 instance
->n_io_port
= np
->base_ws
;
5919 instance
->dma_channel
= 0;
5920 instance
->cmd_per_lun
= MAX_TAGS
;
5921 instance
->can_queue
= (MAX_START
-4);
5922 scsi_set_device(instance
, &device
->pdev
->dev
);
5924 np
->check_integrity
= 0;
5926 #ifdef SCSI_NCR_INTEGRITY_CHECKING
5927 instance
->check_integrity
= 0;
5929 #ifdef SCSI_NCR_ENABLE_INTEGRITY_CHECK
5930 if ( !(driver_setup
.bus_check
& 0x04) ) {
5931 np
->check_integrity
= 1;
5932 instance
->check_integrity
= 1;
5937 NCR_UNLOCK_NCB(np
, flags
);
5940 ** Now let the generic SCSI driver
5941 ** look for the SCSI devices on the bus ..
5946 if (!instance
) return -1;
5947 printk(KERN_INFO
"%s: giving up ...\n", ncr_name(np
));
5949 ncr_free_resources(np
);
5950 scsi_unregister(instance
);
5957 ** Free controller resources.
5959 static void ncr_free_resources(ncb_p np
)
5967 free_irq(np
->irq
, np
);
5969 release_region(np
->base_io
, np
->base_ws
);
5970 #ifndef SCSI_NCR_PCI_MEM_NOT_SUPPORTED
5972 unmap_pci_mem(np
->base_va
, np
->base_ws
);
5974 unmap_pci_mem(np
->base2_va
, np
->base2_ws
);
5977 m_free_dma(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
5979 m_free_dma(np
->script0
, sizeof(struct script
), "SCRIPT");
5981 m_free_dma(np
->squeue
, sizeof(ncrcmd
)*(MAX_START
*2), "SQUEUE");
5983 m_free_dma(np
->dqueue
, sizeof(ncrcmd
)*(MAX_START
*2),"DQUEUE");
5985 while ((cp
= np
->ccbc
) != NULL
) {
5986 np
->ccbc
= cp
->link_ccb
;
5987 m_free_dma(cp
, sizeof(*cp
), "CCB");
5991 m_free_dma(np
->badluntbl
, 256,"BADLUNTBL");
5993 for (target
= 0; target
< MAX_TARGET
; target
++) {
5994 tp
= &np
->target
[target
];
5995 for (lun
= 0 ; lun
< MAX_LUN
; lun
++) {
5996 lp
= ncr_lp(np
, tp
, lun
);
5999 if (lp
->tasktbl
!= &lp
->tasktbl_0
)
6000 m_free_dma(lp
->tasktbl
, MAX_TASKS
*4, "TASKTBL");
6002 m_free(lp
->cb_tags
, MAX_TAGS
, "CB_TAGS");
6003 m_free_dma(lp
, sizeof(*lp
), "LCB");
6007 m_free(tp
->lmp
, MAX_LUN
* sizeof(lcb_p
), "LMP");
6009 m_free_dma(tp
->luntbl
, 256, "LUNTBL");
6014 m_free_dma(np
->targtbl
, 256, "TARGTBL");
6016 m_free_dma(np
, sizeof(*np
), "NCB");
6020 /*==========================================================
6023 ** Done SCSI commands list management.
6025 ** We donnot enter the scsi_done() callback immediately
6026 ** after a command has been seen as completed but we
6027 ** insert it into a list which is flushed outside any kind
6028 ** of driver critical section.
6029 ** This allows to do minimal stuff under interrupt and
6030 ** inside critical sections and to also avoid locking up
6031 ** on recursive calls to driver entry points under SMP.
6032 ** In fact, the only kernel point which is entered by the
6033 ** driver with a driver lock set is get_free_pages(GFP_ATOMIC...)
6034 ** that shall not reenter the driver under any circumstance.
6036 **==========================================================
6038 static inline void ncr_queue_done_cmd(ncb_p np
, Scsi_Cmnd
*cmd
)
6040 unmap_scsi_data(np
, cmd
);
6041 cmd
->host_scribble
= (char *) np
->done_list
;
6042 np
->done_list
= cmd
;
6045 static inline void ncr_flush_done_cmds(Scsi_Cmnd
*lcmd
)
6051 lcmd
= (Scsi_Cmnd
*) cmd
->host_scribble
;
6052 cmd
->scsi_done(cmd
);
6056 /*==========================================================
6059 ** Prepare the next negotiation message for integrity check,
6062 ** Fill in the part of message buffer that contains the
6063 ** negotiation and the nego_status field of the CCB.
6064 ** Returns the size of the message in bytes.
6066 ** If tp->ppr_negotiation is 1 and a M_REJECT occurs, then
6067 ** we disable ppr_negotiation. If the first ppr_negotiation is
6068 ** successful, set this flag to 2.
6070 **==========================================================
6072 #ifdef SCSI_NCR_INTEGRITY_CHECKING
6073 static int ncr_ic_nego(ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
, u_char
*msgptr
)
6075 tcb_p tp
= &np
->target
[cp
->target
];
6078 u_char new_width
, new_offset
, new_period
;
6081 if (tp
->ppr_negotiation
== 1) /* PPR message successful */
6082 tp
->ppr_negotiation
= 2;
6086 if (!tp
->ic_maximums_set
) {
6087 tp
->ic_maximums_set
= 1;
6090 * Check against target, host and user limits
6092 if ( (tp
->inq_byte7
& INQ7_WIDE16
) &&
6093 np
->maxwide
&& tp
->usrwide
)
6094 tp
->ic_max_width
= 1;
6096 tp
->ic_max_width
= 0;
6099 if ((tp
->inq_byte7
& INQ7_SYNC
) && tp
->maxoffs
)
6100 tp
->ic_min_sync
= (tp
->minsync
< np
->minsync
) ?
6101 np
->minsync
: tp
->minsync
;
6103 tp
->ic_min_sync
= 255;
6109 * Enable PPR negotiation - only if Ultra3 support
6114 if (tp
->ic_max_width
&& (tp
->ic_min_sync
!= 255 ))
6115 tp
->ppr_negotiation
= 1;
6117 tp
->ppr_negotiation
= 0;
6118 if (np
->features
& FE_ULTRA3
) {
6119 if (tp
->ic_max_width
&& (tp
->ic_min_sync
== 0x09))
6120 tp
->ppr_negotiation
= 1;
6123 if (!tp
->ppr_negotiation
)
6124 cmd
->ic_nego
&= ~NS_PPR
;
6127 if (DEBUG_FLAGS
& DEBUG_IC
) {
6128 printk("%s: cmd->ic_nego %d, 1st byte 0x%2X\n",
6129 ncr_name(np
), cmd
->ic_nego
, cmd
->cmnd
[0]);
6132 /* Previous command recorded a parity or an initiator
6133 * detected error condition. Force bus to narrow for this
6134 * target. Clear flag. Negotation on request sense.
6135 * Note: kernel forces 2 bus resets :o( but clears itself out.
6136 * Minor bug? in scsi_obsolete.c (ugly)
6138 if (np
->check_integ_par
) {
6139 printk("%s: Parity Error. Target set to narrow.\n",
6141 tp
->ic_max_width
= 0;
6142 tp
->widedone
= tp
->period
= 0;
6146 * If ic_nego == NS_PPR, we are in the initial test for
6147 * PPR messaging support. If driver flag is clear, then
6148 * either we don't support PPR nego (narrow or async device)
6149 * or this is the second TUR and we have had a M. REJECT
6150 * or unexpected disconnect on the first PPR negotiation.
6151 * Do not negotiate, reset nego flags (in case a reset has
6152 * occurred), clear ic_nego and return.
6153 * General case: Kernel will clear flag on a fallback.
6154 * Do only SDTR or WDTR in the future.
6156 if (!tp
->ppr_negotiation
&& (cmd
->ic_nego
== NS_PPR
)) {
6157 tp
->ppr_negotiation
= 0;
6158 cmd
->ic_nego
&= ~NS_PPR
;
6159 tp
->widedone
= tp
->period
= 1;
6162 else if (( tp
->ppr_negotiation
&& !(cmd
->ic_nego
& NS_PPR
)) ||
6163 (!tp
->ppr_negotiation
&& (cmd
->ic_nego
& NS_PPR
)) ) {
6164 tp
->ppr_negotiation
= 0;
6165 cmd
->ic_nego
&= ~NS_PPR
;
6169 * Always check the PPR nego. flag bit if ppr_negotiation
6170 * is set. If the ic_nego PPR bit is clear,
6171 * there must have been a fallback. Do only
6172 * WDTR / SDTR in the future.
6174 if ((tp
->ppr_negotiation
) && (!(cmd
->ic_nego
& NS_PPR
)))
6175 tp
->ppr_negotiation
= 0;
6177 /* In case of a bus reset, ncr_negotiate will reset
6178 * the flags tp->widedone and tp->period to 0, forcing
6179 * a new negotiation. Do WDTR then SDTR. If PPR, do both.
6180 * Do NOT increase the period. It is possible for the Scsi_Cmnd
6181 * flags to be set to increase the period when a bus reset
6182 * occurs - we don't want to change anything.
6187 if (tp
->ppr_negotiation
&& (!tp
->widedone
) && (!tp
->period
) ) {
6188 cmd
->ic_nego
= NS_PPR
;
6189 tp
->widedone
= tp
->period
= 1;
6192 else if (!tp
->widedone
) {
6193 cmd
->ic_nego
= NS_WIDE
;
6197 else if (!tp
->period
) {
6198 cmd
->ic_nego
= NS_SYNC
;
6203 new_width
= cmd
->ic_nego_width
& tp
->ic_max_width
;
6205 switch (cmd
->ic_nego_sync
) {
6206 case 2: /* increase the period */
6208 if (tp
->ic_min_sync
<= 0x09)
6209 tp
->ic_min_sync
= 0x0A;
6210 else if (tp
->ic_min_sync
<= 0x0A)
6211 tp
->ic_min_sync
= 0x0C;
6212 else if (tp
->ic_min_sync
<= 0x0C)
6213 tp
->ic_min_sync
= 0x19;
6214 else if (tp
->ic_min_sync
<= 0x19)
6215 tp
->ic_min_sync
*= 2;
6217 tp
->ic_min_sync
= 255;
6218 cmd
->ic_nego_sync
= 0;
6222 new_period
= tp
->maxoffs
?tp
->ic_min_sync
:0;
6223 new_offset
= tp
->maxoffs
;
6226 case 1: /* nego. to maximum */
6227 new_period
= tp
->maxoffs
?tp
->ic_min_sync
:0;
6228 new_offset
= tp
->maxoffs
;
6231 case 0: /* nego to async */
6240 if (tp
->ppr_negotiation
) {
6241 u_char options_byte
= 0;
6244 ** Must make sure data is consistent.
6245 ** If period is 9 and sync, must be wide and DT bit set.
6246 ** else period must be larger. If the width is 0,
6247 ** reset bus to wide but increase the period to 0x0A.
6248 ** Note: The strange else clause is due to the integrity check.
6249 ** If fails at 0x09, wide, the I.C. code will redo at the same
6250 ** speed but a narrow bus. The driver must take care of slowing
6251 ** the bus speed down.
6253 ** The maximum offset in ST mode is 31, in DT mode 62 (1010/1010_66 only)
6255 if ( (new_period
==0x09) && new_offset
) {
6257 options_byte
= 0x02;
6259 tp
->ic_min_sync
= 0x0A;
6261 cmd
->ic_nego_width
= 1;
6265 if (!options_byte
&& new_offset
> np
->maxoffs_st
)
6266 new_offset
= np
->maxoffs_st
;
6270 msgptr
[msglen
++] = M_EXTENDED
;
6271 msgptr
[msglen
++] = 6;
6272 msgptr
[msglen
++] = M_X_PPR_REQ
;
6273 msgptr
[msglen
++] = new_period
;
6274 msgptr
[msglen
++] = 0;
6275 msgptr
[msglen
++] = new_offset
;
6276 msgptr
[msglen
++] = new_width
;
6277 msgptr
[msglen
++] = options_byte
;
6281 switch (cmd
->ic_nego
& ~NS_PPR
) {
6284 ** WDTR negotiation on if device supports
6285 ** wide or if wide device forced narrow
6286 ** due to a parity error.
6289 cmd
->ic_nego_width
&= tp
->ic_max_width
;
6291 if (tp
->ic_max_width
| np
->check_integ_par
) {
6293 msgptr
[msglen
++] = M_EXTENDED
;
6294 msgptr
[msglen
++] = 2;
6295 msgptr
[msglen
++] = M_X_WIDE_REQ
;
6296 msgptr
[msglen
++] = new_width
;
6302 ** negotiate synchronous transfers
6303 ** Target must support sync transfers.
6304 ** Min. period = 0x0A, maximum offset of 31=0x1f.
6307 if (tp
->inq_byte7
& INQ7_SYNC
) {
6309 if (new_offset
&& (new_period
< 0x0A)) {
6310 tp
->ic_min_sync
= 0x0A;
6313 if (new_offset
> np
->maxoffs_st
)
6314 new_offset
= np
->maxoffs_st
;
6316 msgptr
[msglen
++] = M_EXTENDED
;
6317 msgptr
[msglen
++] = 3;
6318 msgptr
[msglen
++] = M_X_SYNC_REQ
;
6319 msgptr
[msglen
++] = new_period
;
6320 msgptr
[msglen
++] = new_offset
;
6323 cmd
->ic_nego_sync
= 0;
6333 cp
->nego_status
= nego
;
6334 np
->check_integ_par
= 0;
6338 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6339 ncr_print_msg(cp
, nego
== NS_WIDE
?
6340 "wide/narrow msgout":
6341 (nego
== NS_SYNC
? "sync/async msgout" : "ppr msgout"),
6348 #endif /* SCSI_NCR_INTEGRITY_CHECKING */
6350 /*==========================================================
6353 ** Prepare the next negotiation message if needed.
6355 ** Fill in the part of message buffer that contains the
6356 ** negotiation and the nego_status field of the CCB.
6357 ** Returns the size of the message in bytes.
6360 **==========================================================
6364 static int ncr_prepare_nego(ncb_p np
, ccb_p cp
, u_char
*msgptr
)
6366 tcb_p tp
= &np
->target
[cp
->target
];
6369 u_char width
, offset
, factor
, last_byte
;
6371 if (!np
->check_integrity
) {
6372 /* If integrity checking disabled, enable PPR messaging
6373 * if device supports wide, sync and ultra 3
6375 if (tp
->ppr_negotiation
== 1) /* PPR message successful */
6376 tp
->ppr_negotiation
= 2;
6378 if ((tp
->inq_done
) && (!tp
->ic_maximums_set
)) {
6379 tp
->ic_maximums_set
= 1;
6382 * Issue PPR only if board is capable
6383 * and set-up for Ultra3 transfers.
6385 tp
->ppr_negotiation
= 0;
6386 if ( (np
->features
& FE_ULTRA3
) &&
6387 (tp
->usrwide
) && (tp
->maxoffs
) &&
6388 (tp
->minsync
== 0x09) )
6389 tp
->ppr_negotiation
= 1;
6395 * Get the current width, offset and period
6397 ncr_get_xfer_info( np
, tp
, &factor
,
6401 ** negotiate wide transfers ?
6404 if (!tp
->widedone
) {
6405 if (tp
->inq_byte7
& INQ7_WIDE16
) {
6406 if (tp
->ppr_negotiation
)
6411 width
= tp
->usrwide
;
6412 #ifdef SCSI_NCR_INTEGRITY_CHECKING
6414 width
&= tp
->ic_max_width
;
6422 ** negotiate synchronous transfers?
6425 if ((nego
!= NS_WIDE
) && !tp
->period
) {
6426 if (tp
->inq_byte7
& INQ7_SYNC
) {
6427 if (tp
->ppr_negotiation
)
6432 /* Check for async flag */
6433 if (tp
->maxoffs
== 0) {
6438 offset
= tp
->maxoffs
;
6439 factor
= tp
->minsync
;
6440 #ifdef SCSI_NCR_INTEGRITY_CHECKING
6441 if ((tp
->ic_done
) &&
6442 (factor
< tp
->ic_min_sync
))
6443 factor
= tp
->ic_min_sync
;
6451 PRINT_TARGET(np
, cp
->target
);
6452 printk ("target did not report SYNC.\n");
6460 ** Must make sure data is consistent.
6461 ** If period is 9 and sync, must be wide and DT bit set
6462 ** else period must be larger.
6463 ** Maximum offset is 31=0x1f is ST mode, 62 if DT mode
6466 if ( (factor
==9) && offset
) {
6473 if (!last_byte
&& offset
> np
->maxoffs_st
)
6474 offset
= np
->maxoffs_st
;
6476 msgptr
[msglen
++] = M_EXTENDED
;
6477 msgptr
[msglen
++] = 6;
6478 msgptr
[msglen
++] = M_X_PPR_REQ
;
6479 msgptr
[msglen
++] = factor
;
6480 msgptr
[msglen
++] = 0;
6481 msgptr
[msglen
++] = offset
;
6482 msgptr
[msglen
++] = width
;
6483 msgptr
[msglen
++] = last_byte
;
6487 ** Never negotiate faster than Ultra 2 (25ns periods)
6489 if (offset
&& (factor
< 0x0A)) {
6493 if (offset
> np
->maxoffs_st
)
6494 offset
= np
->maxoffs_st
;
6496 msgptr
[msglen
++] = M_EXTENDED
;
6497 msgptr
[msglen
++] = 3;
6498 msgptr
[msglen
++] = M_X_SYNC_REQ
;
6499 msgptr
[msglen
++] = factor
;
6500 msgptr
[msglen
++] = offset
;
6503 msgptr
[msglen
++] = M_EXTENDED
;
6504 msgptr
[msglen
++] = 2;
6505 msgptr
[msglen
++] = M_X_WIDE_REQ
;
6506 msgptr
[msglen
++] = width
;
6510 cp
->nego_status
= nego
;
6514 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6515 ncr_print_msg(cp
, nego
== NS_WIDE
?
6517 (nego
== NS_SYNC
? "sync msgout" : "ppr msgout"),
6525 /*==========================================================
6528 ** Start execution of a SCSI command.
6529 ** This is called from the generic SCSI driver.
6532 **==========================================================
6534 static int ncr_queue_command (ncb_p np
, Scsi_Cmnd
*cmd
)
6536 /* Scsi_Device *device = cmd->device; */
6537 tcb_p tp
= &np
->target
[cmd
->device
->id
];
6538 lcb_p lp
= ncr_lp(np
, tp
, cmd
->device
->lun
);
6541 u_char idmsg
, *msgptr
;
6544 u_int32 lastp
, goalp
;
6546 /*---------------------------------------------
6548 ** Some shortcuts ...
6550 **---------------------------------------------
6552 if ((cmd
->device
->id
== np
->myaddr
) ||
6553 (cmd
->device
->id
>= MAX_TARGET
) ||
6554 (cmd
->device
->lun
>= MAX_LUN
)) {
6555 return(DID_BAD_TARGET
);
6558 /*---------------------------------------------
6560 ** Complete the 1st TEST UNIT READY command
6561 ** with error condition if the device is
6562 ** flagged NOSCAN, in order to speed up
6565 **---------------------------------------------
6567 if ((cmd
->cmnd
[0] == 0 || cmd
->cmnd
[0] == 0x12) &&
6568 (tp
->usrflag
& UF_NOSCAN
)) {
6569 tp
->usrflag
&= ~UF_NOSCAN
;
6570 return DID_BAD_TARGET
;
6573 if (DEBUG_FLAGS
& DEBUG_TINY
) {
6575 printk ("CMD=%x ", cmd
->cmnd
[0]);
6578 /*---------------------------------------------------
6580 ** Assign a ccb / bind cmd.
6581 ** If resetting, shorten settle_time if necessary
6582 ** in order to avoid spurious timeouts.
6583 ** If resetting or no free ccb,
6584 ** insert cmd into the waiting list.
6586 **----------------------------------------------------
6588 if (np
->settle_time
&& cmd
->timeout_per_command
>= HZ
) {
6589 u_long tlimit
= ktime_get(cmd
->timeout_per_command
- HZ
);
6590 if (ktime_dif(np
->settle_time
, tlimit
) > 0)
6591 np
->settle_time
= tlimit
;
6594 if (np
->settle_time
|| !(cp
=ncr_get_ccb (np
, cmd
->device
->id
, cmd
->device
->lun
))) {
6595 insert_into_waiting_list(np
, cmd
);
6600 /*---------------------------------------------------
6602 ** Enable tagged queue if asked by scsi ioctl
6604 **----------------------------------------------------
6606 #if 0 /* This stuff was only useful for linux-1.2.13 */
6607 if (lp
&& !lp
->numtags
&& cmd
->device
&& cmd
->device
->tagged_queue
) {
6608 lp
->numtags
= tp
->usrtags
;
6609 ncr_setup_tags (np
, cp
->target
, cp
->lun
);
6613 /*----------------------------------------------------
6615 ** Build the identify / tag / sdtr message
6617 **----------------------------------------------------
6620 idmsg
= M_IDENTIFY
| cp
->lun
;
6622 if (cp
->tag
!= NO_TAG
|| (lp
&& !(tp
->usrflag
& UF_NODISC
)))
6625 msgptr
= cp
->scsi_smsg
;
6627 msgptr
[msglen
++] = idmsg
;
6629 if (cp
->tag
!= NO_TAG
) {
6630 char order
= np
->order
;
6633 ** Force ordered tag if necessary to avoid timeouts
6634 ** and to preserve interactivity.
6636 if (lp
&& ktime_exp(lp
->tags_stime
)) {
6637 lp
->tags_si
= !(lp
->tags_si
);
6638 if (lp
->tags_sum
[lp
->tags_si
]) {
6639 order
= M_ORDERED_TAG
;
6640 if ((DEBUG_FLAGS
& DEBUG_TAGS
)||bootverbose
>0){
6642 printk("ordered tag forced.\n");
6645 lp
->tags_stime
= ktime_get(3*HZ
);
6650 ** Ordered write ops, unordered read ops.
6652 switch (cmd
->cmnd
[0]) {
6653 case 0x08: /* READ_SMALL (6) */
6654 case 0x28: /* READ_BIG (10) */
6655 case 0xa8: /* READ_HUGE (12) */
6656 order
= M_SIMPLE_TAG
;
6659 order
= M_ORDERED_TAG
;
6662 msgptr
[msglen
++] = order
;
6664 ** For less than 128 tags, actual tags are numbered
6665 ** 1,3,5,..2*MAXTAGS+1,since we may have to deal
6666 ** with devices that have problems with #TAG 0 or too
6667 ** great #TAG numbers. For more tags (up to 256),
6668 ** we use directly our tag number.
6670 #if MAX_TASKS > (512/4)
6671 msgptr
[msglen
++] = cp
->tag
;
6673 msgptr
[msglen
++] = (cp
->tag
<< 1) + 1;
6679 /*----------------------------------------------------
6681 ** Build the data descriptors
6683 **----------------------------------------------------
6686 direction
= scsi_data_direction(cmd
);
6687 if (direction
!= SCSI_DATA_NONE
) {
6688 cp
->segments
= np
->scatter (np
, cp
, cp
->cmd
);
6689 if (cp
->segments
< 0) {
6690 ncr_free_ccb(np
, cp
);
6699 /*---------------------------------------------------
6701 ** negotiation required?
6703 ** (nego_status is filled by ncr_prepare_nego())
6705 **---------------------------------------------------
6708 cp
->nego_status
= 0;
6710 #ifdef SCSI_NCR_INTEGRITY_CHECKING
6711 if ((np
->check_integrity
&& tp
->ic_done
) || !np
->check_integrity
) {
6712 if ((!tp
->widedone
|| !tp
->period
) && !tp
->nego_cp
&& lp
) {
6713 msglen
+= ncr_prepare_nego (np
, cp
, msgptr
+ msglen
);
6716 else if (np
->check_integrity
&& (cmd
->ic_in_progress
)) {
6717 msglen
+= ncr_ic_nego (np
, cp
, cmd
, msgptr
+ msglen
);
6719 else if (np
->check_integrity
&& cmd
->ic_complete
) {
6720 u_long current_period
;
6721 u_char current_offset
, current_width
, current_factor
;
6723 ncr_get_xfer_info (np
, tp
, ¤t_factor
,
6724 ¤t_offset
, ¤t_width
);
6726 tp
->ic_max_width
= current_width
;
6727 tp
->ic_min_sync
= current_factor
;
6729 if (current_factor
== 9) current_period
= 125;
6730 else if (current_factor
== 10) current_period
= 250;
6731 else if (current_factor
== 11) current_period
= 303;
6732 else if (current_factor
== 12) current_period
= 500;
6733 else current_period
= current_factor
* 40;
6736 * Negotiation for this target is complete. Update flags.
6738 tp
->period
= current_period
;
6742 printk("%s: Integrity Check Complete: \n", ncr_name(np
));
6744 printk("%s: %s %s SCSI", ncr_name(np
),
6745 current_offset
?"SYNC":"ASYNC",
6746 tp
->ic_max_width
?"WIDE":"NARROW");
6747 if (current_offset
) {
6748 u_long mbs
= 10000 * (tp
->ic_max_width
+ 1);
6750 printk(" %d.%d MB/s",
6751 (int) (mbs
/ current_period
), (int) (mbs
% current_period
));
6753 printk(" (%d ns, %d offset)\n",
6754 (int) current_period
/10, current_offset
);
6757 printk(" %d MB/s. \n ", (tp
->ic_max_width
+1)*5);
6760 if ((!tp
->widedone
|| !tp
->period
) && !tp
->nego_cp
&& lp
) {
6761 msglen
+= ncr_prepare_nego (np
, cp
, msgptr
+ msglen
);
6763 #endif /* SCSI_NCR_INTEGRITY_CHECKING */
6766 /*----------------------------------------------------
6768 ** Determine xfer direction.
6770 **----------------------------------------------------
6773 direction
= SCSI_DATA_NONE
;
6776 ** If data direction is UNKNOWN, speculate DATA_READ
6777 ** but prepare alternate pointers for WRITE in case
6778 ** of our speculation will be just wrong.
6779 ** SCRIPTS will swap values if needed.
6782 case SCSI_DATA_UNKNOWN
:
6783 case SCSI_DATA_WRITE
:
6784 goalp
= NCB_SCRIPT_PHYS (np
, data_out2
) + 8;
6785 lastp
= goalp
- 8 - (cp
->segments
* (SCR_SG_SIZE
*4));
6786 if (direction
!= SCSI_DATA_UNKNOWN
)
6788 cp
->phys
.header
.wgoalp
= cpu_to_scr(goalp
);
6789 cp
->phys
.header
.wlastp
= cpu_to_scr(lastp
);
6791 case SCSI_DATA_READ
:
6792 cp
->host_flags
|= HF_DATA_IN
;
6793 goalp
= NCB_SCRIPT_PHYS (np
, data_in2
) + 8;
6794 lastp
= goalp
- 8 - (cp
->segments
* (SCR_SG_SIZE
*4));
6797 case SCSI_DATA_NONE
:
6798 lastp
= goalp
= NCB_SCRIPTH_PHYS (np
, no_data
);
6803 ** Set all pointers values needed by SCRIPTS.
6804 ** If direction is unknown, start at data_io.
6806 cp
->phys
.header
.lastp
= cpu_to_scr(lastp
);
6807 cp
->phys
.header
.goalp
= cpu_to_scr(goalp
);
6809 if (direction
== SCSI_DATA_UNKNOWN
)
6810 cp
->phys
.header
.savep
=
6811 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, data_io
));
6813 cp
->phys
.header
.savep
= cpu_to_scr(lastp
);
6816 ** Save the initial data pointer in order to be able
6817 ** to redo the command.
6818 ** We also have to save the initial lastp, since it
6819 ** will be changed to DATA_IO if we don't know the data
6820 ** direction and the device completes the command with
6821 ** QUEUE FULL status (without entering the data phase).
6823 cp
->startp
= cp
->phys
.header
.savep
;
6824 cp
->lastp0
= cp
->phys
.header
.lastp
;
6826 /*----------------------------------------------------
6830 **----------------------------------------------------
6833 ** physical -> virtual backlink
6834 ** Generic SCSI command
6840 cp
->phys
.header
.go
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
,select
));
6841 cp
->phys
.header
.go
.restart
= cpu_to_scr(NCB_SCRIPT_PHYS (np
,resel_dsa
));
6845 cp
->phys
.select
.sel_id
= cp
->target
;
6846 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
6847 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
6848 cp
->phys
.select
.sel_scntl4
= tp
->uval
;
6852 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg
));
6853 cp
->phys
.smsg
.size
= cpu_to_scr(msglen
);
6858 memcpy(cp
->cdb_buf
, cmd
->cmnd
, MIN(cmd
->cmd_len
, sizeof(cp
->cdb_buf
)));
6859 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, cdb_buf
[0]));
6860 cp
->phys
.cmd
.size
= cpu_to_scr(cmd
->cmd_len
);
6865 cp
->actualquirks
= tp
->quirks
;
6866 cp
->host_status
= cp
->nego_status
? HS_NEGOTIATE
: HS_BUSY
;
6867 cp
->scsi_status
= S_ILLEGAL
;
6868 cp
->xerr_status
= 0;
6869 cp
->extra_bytes
= 0;
6872 ** extreme data pointer.
6873 ** shall be positive, so -1 is lower than lowest.:)
6878 /*----------------------------------------------------
6880 ** Critical region: start this job.
6882 **----------------------------------------------------
6886 ** activate this job.
6890 ** insert next CCBs into start queue.
6891 ** 2 max at a time is enough to flush the CCB wait queue.
6894 ncr_start_next_ccb(np
, lp
, 2);
6896 ncr_put_start_queue(np
, cp
);
6899 ** Command is successfully queued.
6906 /*==========================================================
6909 ** Insert a CCB into the start queue and wake up the
6910 ** SCRIPTS processor.
6913 **==========================================================
6916 static void ncr_start_next_ccb(ncb_p np
, lcb_p lp
, int maxn
)
6921 while (maxn
-- && lp
->queuedccbs
< lp
->queuedepth
) {
6922 qp
= xpt_remque_head(&lp
->wait_ccbq
);
6926 cp
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
6927 xpt_insque_tail(qp
, &lp
->busy_ccbq
);
6928 lp
->tasktbl
[cp
->tag
== NO_TAG
? 0 : cp
->tag
] =
6929 cpu_to_scr(cp
->p_ccb
);
6930 ncr_put_start_queue(np
, cp
);
6934 static void ncr_put_start_queue(ncb_p np
, ccb_p cp
)
6938 #ifdef SCSI_NCR_IARB_SUPPORT
6940 ** If the previously queued CCB is not yet done,
6941 ** set the IARB hint. The SCRIPTS will go with IARB
6942 ** for this job when starting the previous one.
6943 ** We leave devices a chance to win arbitration by
6944 ** not using more than 'iarb_max' consecutive
6945 ** immediate arbitrations.
6947 if (np
->last_cp
&& np
->iarb_count
< np
->iarb_max
) {
6948 np
->last_cp
->host_flags
|= HF_HINT_IARB
;
6957 ** insert into start queue.
6959 qidx
= np
->squeueput
+ 2;
6960 if (qidx
>= MAX_START
*2) qidx
= 0;
6962 np
->squeue
[qidx
] = cpu_to_scr(np
->p_idletask
);
6964 np
->squeue
[np
->squeueput
] = cpu_to_scr(cp
->p_ccb
);
6966 np
->squeueput
= qidx
;
6969 if (DEBUG_FLAGS
& DEBUG_QUEUE
)
6970 printk ("%s: queuepos=%d.\n", ncr_name (np
), np
->squeueput
);
6973 ** Script processor may be waiting for reselect.
6977 OUTB (nc_istat
, SIGP
|np
->istat_sem
);
6981 /*==========================================================
6983 ** Soft reset the chip.
6985 ** Some 896 and 876 chip revisions may hang-up if we set
6986 ** the SRST (soft reset) bit at the wrong time when SCRIPTS
6988 ** So, we need to abort the current operation prior to
6989 ** soft resetting the chip.
6991 **==========================================================
6994 static void ncr_chip_reset (ncb_p np
)
6996 OUTB (nc_istat
, SRST
);
7001 static void ncr_soft_reset(ncb_p np
)
7006 if (!(np
->features
& FE_ISTAT1
) || !(INB (nc_istat1
) & SRUN
))
7009 OUTB (nc_istat
, CABRT
);
7010 for (i
= 100000 ; i
; --i
) {
7011 istat
= INB (nc_istat
);
7015 else if (istat
& DIP
) {
7016 if (INB (nc_dstat
) & ABRT
)
7023 printk("%s: unable to abort current chip operation, "
7024 "ISTAT=0x%02x.\n", ncr_name(np
), istat
);
7029 /*==========================================================
7032 ** Start reset process.
7033 ** The interrupt handler will reinitialize the chip.
7034 ** The timeout handler will wait for settle_time before
7035 ** clearing it and so resuming command processing.
7038 **==========================================================
7040 static void ncr_start_reset(ncb_p np
)
7042 (void) ncr_reset_scsi_bus(np
, 1, driver_setup
.settle_delay
);
7045 static int ncr_reset_scsi_bus(ncb_p np
, int enab_int
, int settle_delay
)
7050 np
->settle_time
= ktime_get(settle_delay
* HZ
);
7052 if (bootverbose
> 1)
7053 printk("%s: resetting, "
7054 "command processing suspended for %d seconds\n",
7055 ncr_name(np
), settle_delay
);
7057 ncr_soft_reset(np
); /* Soft reset the chip */
7058 UDELAY (2000); /* The 895/6 need time for the bus mode to settle */
7060 OUTW (nc_sien
, RST
);
7062 ** Enable Tolerant, reset IRQD if present and
7063 ** properly set IRQ mode, prior to resetting the bus.
7065 OUTB (nc_stest3
, TE
);
7066 OUTB (nc_dcntl
, (np
->rv_dcntl
& IRQM
));
7067 OUTB (nc_scntl1
, CRST
);
7070 if (!driver_setup
.bus_check
)
7073 ** Check for no terminators or SCSI bus shorts to ground.
7074 ** Read SCSI data bus, data parity bits and control signals.
7075 ** We are expecting RESET to be TRUE and other signals to be
7078 term
= INB(nc_sstat0
);
7079 term
= ((term
& 2) << 7) + ((term
& 1) << 17); /* rst sdp0 */
7080 term
|= ((INB(nc_sstat2
) & 0x01) << 26) | /* sdp1 */
7081 ((INW(nc_sbdl
) & 0xff) << 9) | /* d7-0 */
7082 ((INW(nc_sbdl
) & 0xff00) << 10) | /* d15-8 */
7083 INB(nc_sbcl
); /* req ack bsy sel atn msg cd io */
7085 if (!(np
->features
& FE_WIDE
))
7088 if (term
!= (2<<7)) {
7089 printk("%s: suspicious SCSI data while resetting the BUS.\n",
7091 printk("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
7092 "0x%lx, expecting 0x%lx\n",
7094 (np
->features
& FE_WIDE
) ? "dp1,d15-8," : "",
7095 (u_long
)term
, (u_long
)(2<<7));
7096 if (driver_setup
.bus_check
== 1)
7100 OUTB (nc_scntl1
, 0);
7104 /*==========================================================
7107 ** Reset the SCSI BUS.
7108 ** This is called from the generic SCSI driver.
7111 **==========================================================
7113 static int ncr_reset_bus (ncb_p np
, Scsi_Cmnd
*cmd
, int sync_reset
)
7115 /* Scsi_Device *device = cmd->device; */
7120 * Return immediately if reset is in progress.
7122 if (np
->settle_time
) {
7123 return SCSI_RESET_PUNT
;
7126 * Start the reset process.
7127 * The script processor is then assumed to be stopped.
7128 * Commands will now be queued in the waiting list until a settle
7129 * delay of 2 seconds will be completed.
7131 ncr_start_reset(np
);
7133 * First, look in the wakeup list
7135 for (found
=0, cp
=np
->ccbc
; cp
; cp
=cp
->link_ccb
) {
7137 ** look for the ccb of this command.
7139 if (cp
->host_status
== HS_IDLE
) continue;
7140 if (cp
->cmd
== cmd
) {
7146 * Then, look in the waiting list
7148 if (!found
&& retrieve_from_waiting_list(0, np
, cmd
))
7151 * Wake-up all awaiting commands with DID_RESET.
7153 reset_waiting_list(np
);
7155 * Wake-up all pending commands with HS_RESET -> DID_RESET.
7157 ncr_wakeup(np
, HS_RESET
);
7159 * If the involved command was not in a driver queue, and the
7160 * scsi driver told us reset is synchronous, and the command is not
7161 * currently in the waiting list, complete it with DID_RESET status,
7162 * in order to keep it alive.
7164 if (!found
&& sync_reset
&& !retrieve_from_waiting_list(0, np
, cmd
)) {
7165 SetScsiResult(cmd
, DID_RESET
, 0);
7166 ncr_queue_done_cmd(np
, cmd
);
7169 return SCSI_RESET_SUCCESS
;
7172 /*==========================================================
7175 ** Abort an SCSI command.
7176 ** This is called from the generic SCSI driver.
7179 **==========================================================
7181 static int ncr_abort_command (ncb_p np
, Scsi_Cmnd
*cmd
)
7183 /* Scsi_Device *device = cmd->device; */
7187 * First, look for the scsi command in the waiting list
7189 if (remove_from_waiting_list(np
, cmd
)) {
7190 SetScsiAbortResult(cmd
);
7191 ncr_queue_done_cmd(np
, cmd
);
7192 return SCSI_ABORT_SUCCESS
;
7196 * Then, look in the wakeup list
7198 for (cp
=np
->ccbc
; cp
; cp
=cp
->link_ccb
) {
7200 ** look for the ccb of this command.
7202 if (cp
->host_status
== HS_IDLE
) continue;
7208 return SCSI_ABORT_NOT_RUNNING
;
7212 ** Keep track we have to abort this job.
7217 ** Tell the SCRIPTS processor to stop
7218 ** and synchronize with us.
7220 np
->istat_sem
= SEM
;
7223 ** If there are no requests, the script
7224 ** processor will sleep on SEL_WAIT_RESEL.
7225 ** Let's wake it up, since it may have to work.
7227 OUTB (nc_istat
, SIGP
|SEM
);
7230 ** Tell user we are working for him.
7232 return SCSI_ABORT_PENDING
;
7235 /*==========================================================
7237 ** Linux release module stuff.
7239 ** Called before unloading the module
7241 ** We have to free resources and halt the NCR chip
7243 **==========================================================
7246 static int ncr_detach(ncb_p np
)
7250 printk("%s: detaching ...\n", ncr_name(np
));
7253 ** Stop the ncr_timeout process
7254 ** Set release_stage to 1 and wait that ncr_timeout() set it to 2.
7256 np
->release_stage
= 1;
7257 for (i
= 50 ; i
&& np
->release_stage
!= 2 ; i
--) MDELAY (100);
7258 if (np
->release_stage
!= 2)
7259 printk("%s: the timer seems to be already stopped\n",
7261 else np
->release_stage
= 2;
7265 ** We should use ncr_soft_reset(), but we donnot want to do
7266 ** so, since we may not be safe if interrupts occur.
7269 printk("%s: resetting chip\n", ncr_name(np
));
7273 ** Restore bios setting for automatic clock detection.
7275 OUTB(nc_dmode
, np
->sv_dmode
);
7276 OUTB(nc_dcntl
, np
->sv_dcntl
);
7277 OUTB(nc_ctest3
, np
->sv_ctest3
);
7278 OUTB(nc_ctest4
, np
->sv_ctest4
);
7279 OUTB(nc_ctest5
, np
->sv_ctest5
);
7280 OUTB(nc_gpcntl
, np
->sv_gpcntl
);
7281 OUTB(nc_stest2
, np
->sv_stest2
);
7283 ncr_selectclock(np
, np
->sv_scntl3
);
7285 ** Free host resources
7287 ncr_free_resources(np
);
7292 /*==========================================================
7295 ** Complete execution of a SCSI command.
7296 ** Signal completion to the generic SCSI driver.
7299 **==========================================================
7302 void ncr_complete (ncb_p np
, ccb_p cp
)
7311 if (!cp
|| !cp
->cmd
)
7315 ** Print some debugging info.
7318 if (DEBUG_FLAGS
& DEBUG_TINY
)
7319 printk ("CCB=%lx STAT=%x/%x\n", (unsigned long)cp
,
7320 cp
->host_status
,cp
->scsi_status
);
7323 ** Get command, target and lun pointers.
7328 tp
= &np
->target
[cp
->target
];
7329 lp
= ncr_lp(np
, tp
, cp
->lun
);
7332 ** We donnot queue more than 1 ccb per target
7333 ** with negotiation at any time. If this ccb was
7334 ** used for negotiation, clear this info in the tcb.
7337 if (cp
== tp
->nego_cp
)
7340 #ifdef SCSI_NCR_IARB_SUPPORT
7342 ** We just complete the last queued CCB.
7343 ** Clear this info that is no more relevant.
7345 if (cp
== np
->last_cp
)
7350 ** If auto-sense performed, change scsi status,
7351 ** Otherwise, compute the residual.
7353 if (cp
->host_flags
& HF_AUTO_SENSE
) {
7354 cp
->scsi_status
= cp
->sv_scsi_status
;
7355 cp
->xerr_status
= cp
->sv_xerr_status
;
7359 if (cp
->xerr_status
||
7360 cp
->phys
.header
.lastp
!= cp
->phys
.header
.goalp
)
7361 cp
->resid
= ncr_compute_residual(np
, cp
);
7365 ** Check for extended errors.
7368 if (cp
->xerr_status
) {
7369 if (cp
->xerr_status
& XE_PARITY_ERR
) {
7371 printk ("unrecovered SCSI parity error.\n");
7373 if (cp
->xerr_status
& XE_EXTRA_DATA
) {
7375 printk ("extraneous data discarded.\n");
7377 if (cp
->xerr_status
& XE_BAD_PHASE
) {
7379 printk ("illegal scsi phase (4/5).\n");
7381 if (cp
->xerr_status
& XE_SODL_UNRUN
) {
7383 printk ("ODD transfer in DATA OUT phase.\n");
7385 if (cp
->xerr_status
& XE_SWIDE_OVRUN
){
7387 printk ("ODD transfer in DATA IN phase.\n");
7390 if (cp
->host_status
==HS_COMPLETE
)
7391 cp
->host_status
= HS_FAIL
;
7395 ** Print out any error for debugging purpose.
7397 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
7398 if (cp
->host_status
!=HS_COMPLETE
|| cp
->scsi_status
!=S_GOOD
||
7401 printk ("ERROR: cmd=%x host_status=%x scsi_status=%x "
7402 "data_len=%d residual=%d\n",
7403 cmd
->cmnd
[0], cp
->host_status
, cp
->scsi_status
,
7404 cp
->data_len
, cp
->resid
);
7408 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,99)
7410 ** Move residual byte count to user structure.
7412 cmd
->resid
= cp
->resid
;
7415 ** Check the status.
7417 if ( (cp
->host_status
== HS_COMPLETE
)
7418 && (cp
->scsi_status
== S_GOOD
||
7419 cp
->scsi_status
== S_COND_MET
)) {
7421 ** All went well (GOOD status).
7422 ** CONDITION MET status is returned on
7423 ** `Pre-Fetch' or `Search data' success.
7425 SetScsiResult(cmd
, DID_OK
, cp
->scsi_status
);
7428 ** Allocate the lcb if not yet.
7431 ncr_alloc_lcb (np
, cp
->target
, cp
->lun
);
7434 ** On standard INQUIRY response (EVPD and CmDt
7435 ** not set), setup logical unit according to
7436 ** announced capabilities (we need the 1rst 8 bytes).
7438 if (cmd
->cmnd
[0] == 0x12 && !(cmd
->cmnd
[1] & 0x3) &&
7439 cmd
->request_bufflen
- cp
->resid
> 7 && !cmd
->use_sg
) {
7440 sync_scsi_data(np
, cmd
); /* SYNC the data */
7441 ncr_setup_lcb (np
, cp
->target
, cp
->lun
,
7442 (char *) cmd
->request_buffer
);
7446 ** If tags was reduced due to queue full,
7447 ** increase tags if 1000 good status received.
7449 if (lp
&& lp
->usetags
&& lp
->numtags
< lp
->maxtags
) {
7451 if (lp
->num_good
>= 1000) {
7454 ncr_setup_tags (np
, cp
->target
, cp
->lun
);
7457 } else if ((cp
->host_status
== HS_COMPLETE
)
7458 && (cp
->scsi_status
== S_CHECK_COND
)) {
7460 ** Check condition code
7462 SetScsiResult(cmd
, DID_OK
, S_CHECK_COND
);
7464 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
7466 ncr_printl_hex("sense data:", cmd
->sense_buffer
, 14);
7468 } else if ((cp
->host_status
== HS_COMPLETE
)
7469 && (cp
->scsi_status
== S_CONFLICT
)) {
7471 ** Reservation Conflict condition code
7473 SetScsiResult(cmd
, DID_OK
, S_CONFLICT
);
7475 } else if ((cp
->host_status
== HS_COMPLETE
)
7476 && (cp
->scsi_status
== S_BUSY
||
7477 cp
->scsi_status
== S_QUEUE_FULL
)) {
7482 SetScsiResult(cmd
, DID_OK
, cp
->scsi_status
);
7484 } else if ((cp
->host_status
== HS_SEL_TIMEOUT
)
7485 || (cp
->host_status
== HS_TIMEOUT
)) {
7490 SetScsiResult(cmd
, DID_TIME_OUT
, cp
->scsi_status
);
7492 } else if (cp
->host_status
== HS_RESET
) {
7497 SetScsiResult(cmd
, DID_RESET
, cp
->scsi_status
);
7499 } else if (cp
->host_status
== HS_ABORTED
) {
7504 SetScsiAbortResult(cmd
);
7510 ** Other protocol messes
7513 printk ("COMMAND FAILED (%x %x) @%p.\n",
7514 cp
->host_status
, cp
->scsi_status
, cp
);
7516 did_status
= DID_ERROR
;
7517 if (cp
->xerr_status
& XE_PARITY_ERR
)
7518 did_status
= DID_PARITY
;
7520 SetScsiResult(cmd
, did_status
, cp
->scsi_status
);
7527 if (tp
->usrflag
& UF_TRACE
) {
7530 ncr_print_hex(cmd
->cmnd
, cmd
->cmd_len
);
7532 if (cp
->host_status
==HS_COMPLETE
) {
7533 switch (cp
->scsi_status
) {
7539 ncr_print_hex(cmd
->sense_buffer
, 14);
7542 printk (" STAT: %x\n", cp
->scsi_status
);
7545 } else printk (" HOSTERROR: %x", cp
->host_status
);
7552 ncr_free_ccb (np
, cp
);
7555 ** requeue awaiting scsi commands for this lun.
7557 if (lp
&& lp
->queuedccbs
< lp
->queuedepth
&&
7558 !xpt_que_empty(&lp
->wait_ccbq
))
7559 ncr_start_next_ccb(np
, lp
, 2);
7562 ** requeue awaiting scsi commands for this controller.
7564 if (np
->waiting_list
)
7565 requeue_waiting_list(np
);
7568 ** signal completion to generic driver.
7570 ncr_queue_done_cmd(np
, cmd
);
7573 /*==========================================================
7576 ** Signal all (or one) control block done.
7579 **==========================================================
7583 ** The NCR has completed CCBs.
7584 ** Look at the DONE QUEUE.
7586 ** On architectures that may reorder LOAD/STORE operations,
7587 ** a memory barrier may be needed after the reading of the
7588 ** so-called `flag' and prior to dealing with the data.
7590 int ncr_wakeup_done (ncb_p np
)
7599 dsa
= scr_to_cpu(np
->dqueue
[i
]);
7603 if ((i
= i
+2) >= MAX_START
*2)
7606 cp
= ncr_ccb_from_dsa(np
, dsa
);
7609 ncr_complete (np
, cp
);
7613 printk (KERN_ERR
"%s: bad DSA (%lx) in done queue.\n",
7622 ** Complete all active CCBs.
7624 void ncr_wakeup (ncb_p np
, u_long code
)
7626 ccb_p cp
= np
->ccbc
;
7629 if (cp
->host_status
!= HS_IDLE
) {
7630 cp
->host_status
= code
;
7631 ncr_complete (np
, cp
);
7637 /*==========================================================
7643 **==========================================================
7646 void ncr_init (ncb_p np
, int reset
, char * msg
, u_long code
)
7652 ** Reset chip if asked, otherwise just clear fifos.
7658 OUTB (nc_stest3
, TE
|CSF
);
7659 OUTONB (nc_ctest3
, CLF
);
7666 if (msg
) printk (KERN_INFO
"%s: restart (%s).\n", ncr_name (np
), msg
);
7669 ** Clear Start Queue
7671 phys
= np
->p_squeue
;
7672 np
->queuedepth
= MAX_START
- 1; /* 1 entry needed as end marker */
7673 for (i
= 0; i
< MAX_START
*2; i
+= 2) {
7674 np
->squeue
[i
] = cpu_to_scr(np
->p_idletask
);
7675 np
->squeue
[i
+1] = cpu_to_scr(phys
+ (i
+2)*4);
7677 np
->squeue
[MAX_START
*2-1] = cpu_to_scr(phys
);
7681 ** Start at first entry.
7684 np
->scripth0
->startpos
[0] = cpu_to_scr(phys
);
7689 phys
= vtobus(np
->dqueue
);
7690 for (i
= 0; i
< MAX_START
*2; i
+= 2) {
7692 np
->dqueue
[i
+1] = cpu_to_scr(phys
+ (i
+2)*4);
7694 np
->dqueue
[MAX_START
*2-1] = cpu_to_scr(phys
);
7697 ** Start at first entry.
7699 np
->scripth0
->done_pos
[0] = cpu_to_scr(phys
);
7703 ** Wakeup all pending jobs.
7705 ncr_wakeup (np
, code
);
7711 OUTB (nc_istat
, 0x00 ); /* Remove Reset, abort */
7712 UDELAY (2000); /* The 895 needs time for the bus mode to settle */
7714 OUTB (nc_scntl0
, np
->rv_scntl0
| 0xc0);
7715 /* full arb., ena parity, par->ATN */
7716 OUTB (nc_scntl1
, 0x00); /* odd parity, and remove CRST!! */
7718 ncr_selectclock(np
, np
->rv_scntl3
); /* Select SCSI clock */
7720 OUTB (nc_scid
, RRE
|np
->myaddr
); /* Adapter SCSI address */
7721 OUTW (nc_respid
, 1ul<<np
->myaddr
); /* Id to respond to */
7722 OUTB (nc_istat
, SIGP
); /* Signal Process */
7723 OUTB (nc_dmode
, np
->rv_dmode
); /* Burst length, dma mode */
7724 OUTB (nc_ctest5
, np
->rv_ctest5
); /* Large fifo + large burst */
7726 OUTB (nc_dcntl
, NOCOM
|np
->rv_dcntl
); /* Protect SFBR */
7727 OUTB (nc_ctest3
, np
->rv_ctest3
); /* Write and invalidate */
7728 OUTB (nc_ctest4
, np
->rv_ctest4
); /* Master parity checking */
7730 if ((np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
7731 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
)){
7732 OUTB (nc_stest2
, EXT
|np
->rv_stest2
);
7733 /* Extended Sreq/Sack filtering, not supported in C1010/C1010_66 */
7735 OUTB (nc_stest3
, TE
); /* TolerANT enable */
7736 OUTB (nc_stime0
, 0x0c); /* HTH disabled STO 0.25 sec */
7739 ** DEL 441 - 53C876 Rev 5 - Part Number 609-0392787/2788 - ITEM 2.
7740 ** Disable overlapped arbitration for all dual-function
7741 ** devices, regardless revision id.
7742 ** We may consider it is a post-chip-design feature. ;-)
7744 ** Errata applies to all 896 and 1010 parts.
7746 if (np
->device_id
== PCI_DEVICE_ID_NCR_53C875
)
7747 OUTB (nc_ctest0
, (1<<5));
7748 else if (np
->device_id
== PCI_DEVICE_ID_NCR_53C896
||
7749 np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
||
7750 np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)
7751 np
->rv_ccntl0
|= DPR
;
7754 ** C1010_66MHz rev 0 part requies AIPCNTL1 bit 3 to be set.
7756 if (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)
7757 OUTB(nc_aipcntl1
, (1<<3));
7760 ** Write CCNTL0/CCNTL1 for chips capable of 64 bit addressing
7761 ** and/or hardware phase mismatch, since only such chips
7762 ** seem to support those IO registers.
7764 if (np
->features
& (FE_DAC
| FE_NOPM
)) {
7765 OUTB (nc_ccntl0
, np
->rv_ccntl0
);
7766 OUTB (nc_ccntl1
, np
->rv_ccntl1
);
7770 ** If phase mismatch handled by scripts (53C895A or 53C896
7771 ** or 53C1010 or 53C1010_66), set PM jump addresses.
7774 if (np
->features
& FE_NOPM
) {
7775 printk(KERN_INFO
"%s: handling phase mismatch from SCRIPTS.\n",
7777 OUTL (nc_pmjad1
, NCB_SCRIPTH_PHYS (np
, pm_handle
));
7778 OUTL (nc_pmjad2
, NCB_SCRIPTH_PHYS (np
, pm_handle
));
7782 ** Enable GPIO0 pin for writing if LED support from SCRIPTS.
7783 ** Also set GPIO5 and clear GPIO6 if hardware LED control.
7786 if (np
->features
& FE_LED0
)
7787 OUTB(nc_gpcntl
, INB(nc_gpcntl
) & ~0x01);
7788 else if (np
->features
& FE_LEDC
)
7789 OUTB(nc_gpcntl
, (INB(nc_gpcntl
) & ~0x41) | 0x20);
7796 OUTW (nc_sien
, STO
|HTH
|MA
|SGE
|UDC
|RST
|PAR
);
7797 OUTB (nc_dien
, MDPE
|BF
|SSI
|SIR
|IID
);
7800 ** For 895/895A/896/c1010
7801 ** Enable SBMC interrupt and save current SCSI bus mode.
7803 if ( (np
->features
& FE_ULTRA2
) || (np
->features
& FE_ULTRA3
) ) {
7804 OUTONW (nc_sien
, SBMC
);
7805 np
->scsi_mode
= INB (nc_stest4
) & SMODE
;
7809 ** Fill in target structure.
7810 ** Reinitialize usrsync.
7811 ** Reinitialize usrwide.
7812 ** Prepare sync negotiation according to actual SCSI bus mode.
7815 for (i
=0;i
<MAX_TARGET
;i
++) {
7816 tcb_p tp
= &np
->target
[i
];
7821 tp
->wval
= np
->rv_scntl3
;
7822 tp
->uval
= np
->rv_scntl4
;
7824 if (tp
->usrsync
!= 255) {
7825 if (tp
->usrsync
<= np
->maxsync
) {
7826 if (tp
->usrsync
< np
->minsync
) {
7827 tp
->usrsync
= np
->minsync
;
7834 if (tp
->usrwide
> np
->maxwide
)
7835 tp
->usrwide
= np
->maxwide
;
7837 ncr_negotiate (np
, tp
);
7841 ** Download SCSI SCRIPTS to on-chip RAM if present,
7842 ** and start script processor.
7843 ** We do the download preferently from the CPU.
7844 ** For platforms that may not support PCI memory mapping,
7845 ** we use a simple SCRIPTS that performs MEMORY MOVEs.
7849 printk ("%s: Downloading SCSI SCRIPTS.\n",
7851 #ifdef SCSI_NCR_PCI_MEM_NOT_SUPPORTED
7852 if (np
->base2_ws
== 8192)
7853 phys
= NCB_SCRIPTH0_PHYS (np
, start_ram64
);
7855 phys
= NCB_SCRIPTH_PHYS (np
, start_ram
);
7857 if (np
->base2_ws
== 8192) {
7858 memcpy_to_pci(np
->base2_va
+ 4096,
7859 np
->scripth0
, sizeof(struct scripth
));
7860 OUTL (nc_mmws
, np
->scr_ram_seg
);
7861 OUTL (nc_mmrs
, np
->scr_ram_seg
);
7862 OUTL (nc_sfs
, np
->scr_ram_seg
);
7863 phys
= NCB_SCRIPTH_PHYS (np
, start64
);
7866 phys
= NCB_SCRIPT_PHYS (np
, init
);
7867 memcpy_to_pci(np
->base2_va
, np
->script0
, sizeof(struct script
));
7868 #endif /* SCSI_NCR_PCI_MEM_NOT_SUPPORTED */
7871 phys
= NCB_SCRIPT_PHYS (np
, init
);
7875 OUTL (nc_dsa
, np
->p_ncb
);
7879 /*==========================================================
7881 ** Prepare the negotiation values for wide and
7882 ** synchronous transfers.
7884 **==========================================================
7887 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
)
7890 ** minsync unit is 4ns !
7893 u_long minsync
= tp
->usrsync
;
7896 ** SCSI bus mode limit
7899 if (np
->scsi_mode
&& np
->scsi_mode
== SMODE_SE
) {
7900 if (minsync
< 12) minsync
= 12;
7907 if (minsync
< np
->minsync
)
7908 minsync
= np
->minsync
;
7914 if (minsync
> np
->maxsync
)
7917 tp
->minsync
= minsync
;
7918 tp
->maxoffs
= (minsync
<255 ? np
->maxoffs
: 0);
7921 ** period=0: has to negotiate sync transfer
7927 ** widedone=0: has to negotiate wide transfer
7932 /*==========================================================
7934 ** Get clock factor and sync divisor for a given
7935 ** synchronous factor period.
7936 ** Returns the clock factor (in sxfer) and scntl3
7937 ** synchronous divisor field.
7939 **==========================================================
7942 static void ncr_getsync(ncb_p np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
)
7944 u_long clk
= np
->clock_khz
; /* SCSI clock frequency in kHz */
7945 int div
= np
->clock_divn
; /* Number of divisors supported */
7946 u_long fak
; /* Sync factor in sxfer */
7947 u_long per
; /* Period in tenths of ns */
7948 u_long kpc
; /* (per * clk) */
7951 ** Compute the synchronous period in tenths of nano-seconds
7954 ** Note, if sfac == 9, DT is being used. Double the period of 125
7957 if (sfac
<= 10) per
= 250;
7958 else if (sfac
== 11) per
= 303;
7959 else if (sfac
== 12) per
= 500;
7960 else per
= 40 * sfac
;
7963 ** Look for the greatest clock divisor that allows an
7964 ** input speed faster than the period.
7968 if (kpc
>= (div_10M
[div
] << 2)) break;
7971 ** Calculate the lowest clock factor that allows an output
7972 ** speed not faster than the period.
7974 fak
= (kpc
- 1) / div_10M
[div
] + 1;
7976 #if 0 /* This optimization does not seem very useful */
7978 per
= (fak
* div_10M
[div
]) / clk
;
7981 ** Why not to try the immediate lower divisor and to choose
7982 ** the one that allows the fastest output speed ?
7983 ** We don't want input speed too much greater than output speed.
7985 if (div
>= 1 && fak
< 8) {
7987 fak2
= (kpc
- 1) / div_10M
[div
-1] + 1;
7988 per2
= (fak2
* div_10M
[div
-1]) / clk
;
7989 if (per2
< per
&& fak2
<= 8) {
7997 if (fak
< 4) fak
= 4; /* Should never happen, too bad ... */
8000 ** Compute and return sync parameters for the ncr
8005 ** If sfac < 25, and 8xx parts, desire that the chip operate at
8006 ** least at Ultra speeds. Must set bit 7 of scntl3.
8007 ** For C1010, do not set this bit. If operating at Ultra3 speeds,
8008 ** set the U3EN bit instead.
8010 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8011 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)) {
8012 *scntl3p
= (div
+1) << 4;
8016 *scntl3p
= ((div
+1) << 4) + (sfac
< 25 ? 0x80 : 0);
8021 /*==========================================================
8023 ** Utility routine to return the current bus width
8024 ** synchronous period and offset.
8025 ** Utilizes target sval, wval and uval
8027 **==========================================================
8029 static void ncr_get_xfer_info(ncb_p np
, tcb_p tp
, u_char
*factor
,
8030 u_char
*offset
, u_char
*width
)
8036 *width
= (tp
->wval
& EWS
) ? 1 : 0;
8038 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8039 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
))
8040 *offset
= (tp
->sval
& 0x3f);
8042 *offset
= (tp
->sval
& 0x1f);
8045 * Midlayer signal to the driver that all of the scsi commands
8046 * for the integrity check have completed. Save the negotiated
8047 * parameters (extracted from sval, wval and uval).
8048 * See ncr_setsync for alg. details.
8051 idiv
= (tp
->wval
>>4) & 0x07;
8053 if ( *offset
&& idiv
) {
8054 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8055 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)){
8056 if (tp
->uval
& 0x80)
8057 period
= (2*div_10M
[idiv
-1])/np
->clock_khz
;
8059 period
= (4*div_10M
[idiv
-1])/np
->clock_khz
;
8062 period
= (((tp
->sval
>>5)+4)*div_10M
[idiv
-1])/np
->clock_khz
;
8067 if (period
<= 125) *factor
= 9;
8068 else if (period
<= 250) *factor
= 10;
8069 else if (period
<= 303) *factor
= 11;
8070 else if (period
<= 500) *factor
= 12;
8071 else *factor
= (period
+ 40 - 1) / 40;
8076 /*==========================================================
8078 ** Set actual values, sync status and patch all ccbs of
8079 ** a target according to new sync/wide agreement.
8081 **==========================================================
8084 static void ncr_set_sync_wide_status (ncb_p np
, u_char target
)
8086 ccb_p cp
= np
->ccbc
;
8087 tcb_p tp
= &np
->target
[target
];
8090 ** set actual value and sync_status
8092 ** TEMP register contains current scripts address
8093 ** which is data type/direction/dependent.
8095 OUTB (nc_sxfer
, tp
->sval
);
8096 OUTB (nc_scntl3
, tp
->wval
);
8097 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8098 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
))
8099 OUTB (nc_scntl4
, tp
->uval
);
8102 ** patch ALL ccbs of this target.
8104 for (cp
= np
->ccbc
; cp
; cp
= cp
->link_ccb
) {
8105 if (cp
->host_status
== HS_IDLE
)
8107 if (cp
->target
!= target
)
8109 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
8110 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
8111 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8112 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
))
8113 cp
->phys
.select
.sel_scntl4
= tp
->uval
;
8117 /*==========================================================
8119 ** Switch sync mode for current job and it's target
8121 **==========================================================
8124 static void ncr_setsync (ncb_p np
, ccb_p cp
, u_char scntl3
, u_char sxfer
,
8128 u_char target
= INB (nc_sdid
) & 0x0f;
8135 assert (target
== (cp
->target
& 0xf));
8137 tp
= &np
->target
[target
];
8139 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8140 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)) {
8141 offset
= sxfer
& 0x3f; /* bits 5-0 */
8142 scntl3
= (scntl3
& 0xf0) | (tp
->wval
& EWS
);
8143 scntl4
= (scntl4
& 0x80);
8146 offset
= sxfer
& 0x1f; /* bits 4-0 */
8147 if (!scntl3
|| !offset
)
8148 scntl3
= np
->rv_scntl3
;
8150 scntl3
= (scntl3
& 0xf0) | (tp
->wval
& EWS
) |
8151 (np
->rv_scntl3
& 0x07);
8156 ** Deduce the value of controller sync period from scntl3.
8157 ** period is in tenths of nano-seconds.
8160 idiv
= ((scntl3
>> 4) & 0x7);
8161 if ( offset
&& idiv
) {
8162 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8163 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)) {
8164 /* Note: If extra data hold clocks are used,
8165 * the formulas below must be modified.
8166 * When scntl4 == 0, ST mode.
8169 tp
->period
= (2*div_10M
[idiv
-1])/np
->clock_khz
;
8171 tp
->period
= (4*div_10M
[idiv
-1])/np
->clock_khz
;
8174 tp
->period
= (((sxfer
>>5)+4)*div_10M
[idiv
-1])/np
->clock_khz
;
8177 tp
->period
= 0xffff;
8181 ** Stop there if sync parameters are unchanged
8183 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
&& tp
->uval
== scntl4
) return;
8189 ** Bells and whistles ;-)
8190 ** Donnot announce negotiations due to auto-sense,
8191 ** unless user really want us to be verbose. :)
8193 if ( bootverbose
< 2 && (cp
->host_flags
& HF_AUTO_SENSE
))
8195 PRINT_TARGET(np
, target
);
8197 unsigned f10
= 100000 << (tp
->widedone
? tp
->widedone
-1 : 0);
8198 unsigned mb10
= (f10
+ tp
->period
/2) / tp
->period
;
8202 ** Disable extended Sreq/Sack filtering
8204 if ((tp
->period
<= 2000) &&
8205 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
8206 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
))
8207 OUTOFFB (nc_stest2
, EXT
);
8210 ** Bells and whistles ;-)
8212 if (tp
->period
< 250) scsi
= "FAST-80";
8213 else if (tp
->period
< 500) scsi
= "FAST-40";
8214 else if (tp
->period
< 1000) scsi
= "FAST-20";
8215 else if (tp
->period
< 2000) scsi
= "FAST-10";
8216 else scsi
= "FAST-5";
8218 printk ("%s %sSCSI %d.%d MB/s (%d.%d ns, offset %d)\n", scsi
,
8219 tp
->widedone
> 1 ? "WIDE " : "",
8220 mb10
/ 10, mb10
% 10, tp
->period
/ 10, tp
->period
% 10,
8223 printk ("%sasynchronous.\n", tp
->widedone
> 1 ? "wide " : "");
8226 ** set actual value and sync_status
8227 ** patch ALL ccbs of this target.
8229 ncr_set_sync_wide_status(np
, target
);
8233 /*==========================================================
8235 ** Switch wide mode for current job and it's target
8236 ** SCSI specs say: a SCSI device that accepts a WDTR
8237 ** message shall reset the synchronous agreement to
8238 ** asynchronous mode.
8240 **==========================================================
8243 static void ncr_setwide (ncb_p np
, ccb_p cp
, u_char wide
, u_char ack
)
8245 u_short target
= INB (nc_sdid
) & 0x0f;
8253 assert (target
== (cp
->target
& 0xf));
8255 tp
= &np
->target
[target
];
8256 tp
->widedone
= wide
+1;
8257 scntl3
= (tp
->wval
& (~EWS
)) | (wide
? EWS
: 0);
8259 sxfer
= ack
? 0 : tp
->sval
;
8262 ** Stop there if sync/wide parameters are unchanged
8264 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
) return;
8269 ** Bells and whistles ;-)
8271 if (bootverbose
>= 2) {
8272 PRINT_TARGET(np
, target
);
8274 printk ("WIDE SCSI (16 bit) enabled.\n");
8276 printk ("WIDE SCSI disabled.\n");
8280 ** set actual value and sync_status
8281 ** patch ALL ccbs of this target.
8283 ncr_set_sync_wide_status(np
, target
);
8287 /*==========================================================
8289 ** Switch sync/wide mode for current job and it's target
8290 ** PPR negotiations only
8292 **==========================================================
8295 static void ncr_setsyncwide (ncb_p np
, ccb_p cp
, u_char scntl3
, u_char sxfer
,
8296 u_char scntl4
, u_char wide
)
8299 u_char target
= INB (nc_sdid
) & 0x0f;
8306 assert (target
== (cp
->target
& 0xf));
8308 tp
= &np
->target
[target
];
8309 tp
->widedone
= wide
+1;
8311 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8312 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)) {
8313 offset
= sxfer
& 0x3f; /* bits 5-0 */
8314 scntl3
= (scntl3
& 0xf0) | (wide
? EWS
: 0);
8315 scntl4
= (scntl4
& 0x80);
8318 offset
= sxfer
& 0x1f; /* bits 4-0 */
8319 if (!scntl3
|| !offset
)
8320 scntl3
= np
->rv_scntl3
;
8322 scntl3
= (scntl3
& 0xf0) | (wide
? EWS
: 0) |
8323 (np
->rv_scntl3
& 0x07);
8328 ** Deduce the value of controller sync period from scntl3.
8329 ** period is in tenths of nano-seconds.
8332 idiv
= ((scntl3
>> 4) & 0x7);
8333 if ( offset
&& idiv
) {
8334 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8335 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)) {
8336 /* Note: If extra data hold clocks are used,
8337 * the formulas below must be modified.
8338 * When scntl4 == 0, ST mode.
8341 tp
->period
= (2*div_10M
[idiv
-1])/np
->clock_khz
;
8343 tp
->period
= (4*div_10M
[idiv
-1])/np
->clock_khz
;
8346 tp
->period
= (((sxfer
>>5)+4)*div_10M
[idiv
-1])/np
->clock_khz
;
8349 tp
->period
= 0xffff;
8353 ** Stop there if sync parameters are unchanged
8355 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
&& tp
->uval
== scntl4
) return;
8361 ** Bells and whistles ;-)
8362 ** Donnot announce negotiations due to auto-sense,
8363 ** unless user really want us to be verbose. :)
8365 if ( bootverbose
< 2 && (cp
->host_flags
& HF_AUTO_SENSE
))
8367 PRINT_TARGET(np
, target
);
8369 unsigned f10
= 100000 << (tp
->widedone
? tp
->widedone
-1 : 0);
8370 unsigned mb10
= (f10
+ tp
->period
/2) / tp
->period
;
8374 ** Disable extended Sreq/Sack filtering
8376 if ((tp
->period
<= 2000) &&
8377 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
8378 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
))
8379 OUTOFFB (nc_stest2
, EXT
);
8382 ** Bells and whistles ;-)
8384 if (tp
->period
< 250) scsi
= "FAST-80";
8385 else if (tp
->period
< 500) scsi
= "FAST-40";
8386 else if (tp
->period
< 1000) scsi
= "FAST-20";
8387 else if (tp
->period
< 2000) scsi
= "FAST-10";
8388 else scsi
= "FAST-5";
8390 printk ("%s %sSCSI %d.%d MB/s (%d.%d ns, offset %d)\n", scsi
,
8391 tp
->widedone
> 1 ? "WIDE " : "",
8392 mb10
/ 10, mb10
% 10, tp
->period
/ 10, tp
->period
% 10,
8395 printk ("%sasynchronous.\n", tp
->widedone
> 1 ? "wide " : "");
8398 ** set actual value and sync_status
8399 ** patch ALL ccbs of this target.
8401 ncr_set_sync_wide_status(np
, target
);
8407 /*==========================================================
8409 ** Switch tagged mode for a target.
8411 **==========================================================
8414 static void ncr_setup_tags (ncb_p np
, u_char tn
, u_char ln
)
8416 tcb_p tp
= &np
->target
[tn
];
8417 lcb_p lp
= ncr_lp(np
, tp
, ln
);
8418 u_short reqtags
, maxdepth
;
8427 ** If SCSI device queue depth is not yet set, leave here.
8429 if (!lp
->scdev_depth
)
8433 ** Donnot allow more tags than the SCSI driver can queue
8435 ** Donnot allow more tags than we can handle.
8437 maxdepth
= lp
->scdev_depth
;
8438 if (maxdepth
> lp
->maxnxs
) maxdepth
= lp
->maxnxs
;
8439 if (lp
->maxtags
> maxdepth
) lp
->maxtags
= maxdepth
;
8440 if (lp
->numtags
> maxdepth
) lp
->numtags
= maxdepth
;
8443 ** only devices conformant to ANSI Version >= 2
8444 ** only devices capable of tagged commands
8445 ** only if enabled by user ..
8447 if ((lp
->inq_byte7
& INQ7_QUEUE
) && lp
->numtags
> 1) {
8448 reqtags
= lp
->numtags
;
8454 ** Update max number of tags
8456 lp
->numtags
= reqtags
;
8457 if (lp
->numtags
> lp
->maxtags
)
8458 lp
->maxtags
= lp
->numtags
;
8461 ** If we want to switch tag mode, we must wait
8462 ** for no CCB to be active.
8464 if (reqtags
> 1 && lp
->usetags
) { /* Stay in tagged mode */
8465 if (lp
->queuedepth
== reqtags
) /* Already announced */
8467 lp
->queuedepth
= reqtags
;
8469 else if (reqtags
<= 1 && !lp
->usetags
) { /* Stay in untagged mode */
8470 lp
->queuedepth
= reqtags
;
8473 else { /* Want to switch tag mode */
8474 if (lp
->busyccbs
) /* If not yet safe, return */
8476 lp
->queuedepth
= reqtags
;
8477 lp
->usetags
= reqtags
> 1 ? 1 : 0;
8481 ** Patch the lun mini-script, according to tag mode.
8483 lp
->resel_task
= lp
->usetags
?
8484 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_tag
)) :
8485 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_notag
));
8488 ** Announce change to user.
8491 PRINT_LUN(np
, tn
, ln
);
8493 printk("tagged command queue depth set to %d\n", reqtags
);
8495 printk("tagged command queueing disabled\n");
8499 /*----------------------------------------------------
8501 ** handle user commands
8503 **----------------------------------------------------
8506 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
8508 static void ncr_usercmd (ncb_p np
)
8515 switch (np
->user
.cmd
) {
8519 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
8520 ncr_debug
= np
->user
.data
;
8525 np
->order
= np
->user
.data
;
8529 np
->verbose
= np
->user
.data
;
8534 ** We assume that other commands apply to targets.
8535 ** This should always be the case and avoid the below
8536 ** 4 lines to be repeated 5 times.
8538 for (t
= 0; t
< MAX_TARGET
; t
++) {
8539 if (!((np
->user
.target
>> t
) & 1))
8541 tp
= &np
->target
[t
];
8543 switch (np
->user
.cmd
) {
8546 tp
->usrsync
= np
->user
.data
;
8547 ncr_negotiate (np
, tp
);
8551 size
= np
->user
.data
;
8552 if (size
> np
->maxwide
)
8555 ncr_negotiate (np
, tp
);
8559 tp
->usrtags
= np
->user
.data
;
8560 for (ln
= 0; ln
< MAX_LUN
; ln
++) {
8562 lp
= ncr_lp(np
, tp
, ln
);
8565 lp
->numtags
= np
->user
.data
;
8566 lp
->maxtags
= lp
->numtags
;
8567 ncr_setup_tags (np
, t
, ln
);
8573 np
->istat_sem
= SEM
;
8574 OUTB (nc_istat
, SIGP
|SEM
);
8578 for (ln
= 0; ln
< MAX_LUN
; ln
++) {
8580 lp
= ncr_lp(np
, tp
, ln
);
8584 np
->istat_sem
= SEM
;
8585 OUTB (nc_istat
, SIGP
|SEM
);
8589 tp
->usrflag
= np
->user
.data
;
8599 /*==========================================================
8602 ** ncr timeout handler.
8605 **==========================================================
8607 ** Misused to keep the driver running when
8608 ** interrupts are not configured correctly.
8610 **----------------------------------------------------------
8613 static void ncr_timeout (ncb_p np
)
8615 u_long thistime
= ktime_get(0);
8618 ** If release process in progress, let's go
8619 ** Set the release stage from 1 to 2 to synchronize
8620 ** with the release process.
8623 if (np
->release_stage
) {
8624 if (np
->release_stage
== 1) np
->release_stage
= 2;
8628 #ifdef SCSI_NCR_PCIQ_BROKEN_INTR
8629 np
->timer
.expires
= ktime_get((HZ
+9)/10);
8631 np
->timer
.expires
= ktime_get(SCSI_NCR_TIMER_INTERVAL
);
8633 add_timer(&np
->timer
);
8636 ** If we are resetting the ncr, wait for settle_time before
8637 ** clearing it. Then command processing will be resumed.
8639 if (np
->settle_time
) {
8640 if (np
->settle_time
<= thistime
) {
8641 if (bootverbose
> 1)
8642 printk("%s: command processing resumed\n", ncr_name(np
));
8643 np
->settle_time
= 0;
8644 requeue_waiting_list(np
);
8650 ** Nothing to do for now, but that may come.
8652 if (np
->lasttime
+ 4*HZ
< thistime
) {
8653 np
->lasttime
= thistime
;
8656 #ifdef SCSI_NCR_PCIQ_MAY_MISS_COMPLETIONS
8658 ** Some way-broken PCI bridges may lead to
8659 ** completions being lost when the clearing
8660 ** of the INTFLY flag by the CPU occurs
8661 ** concurrently with the chip raising this flag.
8662 ** If this ever happen, lost completions will
8665 ncr_wakeup_done(np
);
8668 #ifdef SCSI_NCR_PCIQ_BROKEN_INTR
8669 if (INB(nc_istat
) & (INTF
|SIP
|DIP
)) {
8672 ** Process pending interrupts.
8674 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("{");
8676 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("}");
8678 #endif /* SCSI_NCR_PCIQ_BROKEN_INTR */
8681 /*==========================================================
8683 ** log message for real hard errors
8685 ** "ncr0 targ 0?: ERROR (ds:si) (so-si-sd) (sxfer/scntl3) @ name (dsp:dbc)."
8686 ** " reg: r0 r1 r2 r3 r4 r5 r6 ..... rf."
8688 ** exception register:
8693 ** so: control lines as driver by NCR.
8694 ** si: control lines as seen by NCR.
8695 ** sd: scsi data lines as seen by NCR.
8698 ** sxfer: (see the manual)
8699 ** scntl3: (see the manual)
8701 ** current script command:
8702 ** dsp: script address (relative to start of script).
8703 ** dbc: first word of script command.
8705 ** First 24 register of the chip:
8708 **==========================================================
8711 static void ncr_log_hard_error(ncb_p np
, u_short sist
, u_char dstat
)
8717 u_char
*script_base
;
8722 if (dsp
> np
->p_script
&& dsp
<= np
->p_script
+ sizeof(struct script
)) {
8723 script_ofs
= dsp
- np
->p_script
;
8724 script_size
= sizeof(struct script
);
8725 script_base
= (u_char
*) np
->script0
;
8726 script_name
= "script";
8728 else if (np
->p_scripth
< dsp
&&
8729 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
8730 script_ofs
= dsp
- np
->p_scripth
;
8731 script_size
= sizeof(struct scripth
);
8732 script_base
= (u_char
*) np
->scripth0
;
8733 script_name
= "scripth";
8738 script_name
= "mem";
8741 printk ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x) @ (%s %x:%08x).\n",
8742 ncr_name (np
), (unsigned)INB (nc_sdid
)&0x0f, dstat
, sist
,
8743 (unsigned)INB (nc_socl
), (unsigned)INB (nc_sbcl
), (unsigned)INB (nc_sbdl
),
8744 (unsigned)INB (nc_sxfer
),(unsigned)INB (nc_scntl3
), script_name
, script_ofs
,
8745 (unsigned)INL (nc_dbc
));
8747 if (((script_ofs
& 3) == 0) &&
8748 (unsigned)script_ofs
< script_size
) {
8749 printk ("%s: script cmd = %08x\n", ncr_name(np
),
8750 scr_to_cpu((int) *(ncrcmd
*)(script_base
+ script_ofs
)));
8753 printk ("%s: regdump:", ncr_name(np
));
8755 printk (" %02x", (unsigned)INB_OFF(i
));
8759 /*============================================================
8761 ** ncr chip exception handler.
8763 **============================================================
8765 ** In normal situations, interrupt conditions occur one at
8766 ** a time. But when something bad happens on the SCSI BUS,
8767 ** the chip may raise several interrupt flags before
8768 ** stopping and interrupting the CPU. The additionnal
8769 ** interrupt flags are stacked in some extra registers
8770 ** after the SIP and/or DIP flag has been raised in the
8771 ** ISTAT. After the CPU has read the interrupt condition
8772 ** flag from SIST or DSTAT, the chip unstacks the other
8773 ** interrupt flags and sets the corresponding bits in
8774 ** SIST or DSTAT. Since the chip starts stacking once the
8775 ** SIP or DIP flag is set, there is a small window of time
8776 ** where the stacking does not occur.
8778 ** Typically, multiple interrupt conditions may happen in
8779 ** the following situations:
8781 ** - SCSI parity error + Phase mismatch (PAR|MA)
8782 ** When an parity error is detected in input phase
8783 ** and the device switches to msg-in phase inside a
8785 ** - SCSI parity error + Unexpected disconnect (PAR|UDC)
8786 ** When a stupid device does not want to handle the
8787 ** recovery of an SCSI parity error.
8788 ** - Some combinations of STO, PAR, UDC, ...
8789 ** When using non compliant SCSI stuff, when user is
8790 ** doing non compliant hot tampering on the BUS, when
8791 ** something really bad happens to a device, etc ...
8793 ** The heuristic suggested by SYMBIOS to handle
8794 ** multiple interrupts is to try unstacking all
8795 ** interrupts conditions and to handle them on some
8796 ** priority based on error severity.
8797 ** This will work when the unstacking has been
8798 ** successful, but we cannot be 100 % sure of that,
8799 ** since the CPU may have been faster to unstack than
8800 ** the chip is able to stack. Hmmm ... But it seems that
8801 ** such a situation is very unlikely to happen.
8803 ** If this happen, for example STO catched by the CPU
8804 ** then UDC happenning before the CPU have restarted
8805 ** the SCRIPTS, the driver may wrongly complete the
8806 ** same command on UDC, since the SCRIPTS didn't restart
8807 ** and the DSA still points to the same command.
8808 ** We avoid this situation by setting the DSA to an
8809 ** invalid value when the CCB is completed and before
8810 ** restarting the SCRIPTS.
8812 ** Another issue is that we need some section of our
8813 ** recovery procedures to be somehow uninterruptible and
8814 ** that the SCRIPTS processor does not provides such a
8815 ** feature. For this reason, we handle recovery preferently
8816 ** from the C code and check against some SCRIPTS
8817 ** critical sections from the C code.
8819 ** Hopefully, the interrupt handling of the driver is now
8820 ** able to resist to weird BUS error conditions, but donnot
8821 ** ask me for any guarantee that it will never fail. :-)
8822 ** Use at your own decision and risk.
8824 **============================================================
8827 void ncr_exception (ncb_p np
)
8829 u_char istat
, istatc
;
8835 ** interrupt on the fly ?
8837 ** A `dummy read' is needed to ensure that the
8838 ** clear of the INTF flag reaches the device
8839 ** before the scanning of the DONE queue.
8841 istat
= INB (nc_istat
);
8843 OUTB (nc_istat
, (istat
& SIGP
) | INTF
| np
->istat_sem
);
8844 istat
= INB (nc_istat
); /* DUMMY READ */
8845 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("F ");
8846 (void)ncr_wakeup_done (np
);
8849 if (!(istat
& (SIP
|DIP
)))
8852 #if 0 /* We should never get this one */
8854 OUTB (nc_istat
, CABRT
);
8858 ** Steinbach's Guideline for Systems Programming:
8859 ** Never test for an error condition you don't know how to handle.
8862 /*========================================================
8863 ** PAR and MA interrupts may occur at the same time,
8864 ** and we need to know of both in order to handle
8865 ** this situation properly. We try to unstack SCSI
8866 ** interrupts for that reason. BTW, I dislike a LOT
8867 ** such a loop inside the interrupt routine.
8868 ** Even if DMA interrupt stacking is very unlikely to
8869 ** happen, we also try unstacking these ones, since
8870 ** this has no performance impact.
8871 **=========================================================
8878 sist
|= INW (nc_sist
);
8880 dstat
|= INB (nc_dstat
);
8881 istatc
= INB (nc_istat
);
8883 } while (istatc
& (SIP
|DIP
));
8885 if (DEBUG_FLAGS
& DEBUG_TINY
)
8886 printk ("<%d|%x:%x|%x:%x>",
8889 (unsigned)INL(nc_dsp
),
8890 (unsigned)INL(nc_dbc
));
8893 ** On paper, a memory barrier may be needed here.
8894 ** And since we are paranoid ... :)
8898 /*========================================================
8899 ** First, interrupts we want to service cleanly.
8901 ** Phase mismatch (MA) is the most frequent interrupt
8902 ** for chip earlier than the 896 and so we have to service
8903 ** it as quickly as possible.
8904 ** A SCSI parity error (PAR) may be combined with a phase
8905 ** mismatch condition (MA).
8906 ** Programmed interrupts (SIR) are used to call the C code
8908 ** The single step interrupt (SSI) is not used in this
8910 **=========================================================
8913 if (!(sist
& (STO
|GEN
|HTH
|SGE
|UDC
|SBMC
|RST
)) &&
8914 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
8915 if (sist
& PAR
) ncr_int_par (np
, sist
);
8916 else if (sist
& MA
) ncr_int_ma (np
);
8917 else if (dstat
& SIR
) ncr_int_sir (np
);
8918 else if (dstat
& SSI
) OUTONB_STD ();
8919 else goto unknown_int
;
8923 /*========================================================
8924 ** Now, interrupts that donnot happen in normal
8925 ** situations and that we may need to recover from.
8927 ** On SCSI RESET (RST), we reset everything.
8928 ** On SCSI BUS MODE CHANGE (SBMC), we complete all
8929 ** active CCBs with RESET status, prepare all devices
8930 ** for negotiating again and restart the SCRIPTS.
8931 ** On STO and UDC, we complete the CCB with the corres-
8932 ** ponding status and restart the SCRIPTS.
8933 **=========================================================
8937 ncr_init (np
, 1, bootverbose
? "scsi reset" : NULL
, HS_RESET
);
8941 OUTB (nc_ctest3
, np
->rv_ctest3
| CLF
); /* clear dma fifo */
8942 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
8944 if (!(sist
& (GEN
|HTH
|SGE
)) &&
8945 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
8946 if (sist
& SBMC
) ncr_int_sbmc (np
);
8947 else if (sist
& STO
) ncr_int_sto (np
);
8948 else if (sist
& UDC
) ncr_int_udc (np
);
8949 else goto unknown_int
;
8953 /*=========================================================
8954 ** Now, interrupts we are not able to recover cleanly.
8956 ** Do the register dump.
8957 ** Log message for hard errors.
8958 ** Reset everything.
8959 **=========================================================
8961 if (ktime_exp(np
->regtime
)) {
8962 np
->regtime
= ktime_get(10*HZ
);
8963 for (i
= 0; i
<sizeof(np
->regdump
); i
++)
8964 ((char*)&np
->regdump
)[i
] = INB_OFF(i
);
8965 np
->regdump
.nc_dstat
= dstat
;
8966 np
->regdump
.nc_sist
= sist
;
8969 ncr_log_hard_error(np
, sist
, dstat
);
8971 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
8972 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)) {
8973 u_char ctest4_o
, ctest4_m
;
8977 * Get shadow register data
8980 ctest4_o
= INB(nc_ctest4
);
8982 OUTB(nc_ctest4
, ctest4_o
| 0x10);
8984 ctest4_m
= INB(nc_ctest4
);
8985 shadow
= INW_OFF(0x42);
8987 OUTB(nc_ctest4
, ctest4_o
);
8989 printk("%s: ctest4/sist original 0x%x/0x%X mod: 0x%X/0x%x\n",
8990 ncr_name(np
), ctest4_o
, sist
, ctest4_m
, shadow
);
8993 if ((sist
& (GEN
|HTH
|SGE
)) ||
8994 (dstat
& (MDPE
|BF
|ABRT
|IID
))) {
8995 ncr_start_reset(np
);
9000 /*=========================================================
9001 ** We just miss the cause of the interrupt. :(
9002 ** Print a message. The timeout will do the real work.
9003 **=========================================================
9005 printk( "%s: unknown interrupt(s) ignored, "
9006 "ISTAT=0x%x DSTAT=0x%x SIST=0x%x\n",
9007 ncr_name(np
), istat
, dstat
, sist
);
9011 /*==========================================================
9013 ** generic recovery from scsi interrupt
9015 **==========================================================
9017 ** The doc says that when the chip gets an SCSI interrupt,
9018 ** it tries to stop in an orderly fashion, by completing
9019 ** an instruction fetch that had started or by flushing
9020 ** the DMA fifo for a write to memory that was executing.
9021 ** Such a fashion is not enough to know if the instruction
9022 ** that was just before the current DSP value has been
9025 ** There are 3 small SCRIPTS sections that deal with the
9026 ** start queue and the done queue that may break any
9027 ** assomption from the C code if we are interrupted
9028 ** inside, so we reset if it happens. Btw, since these
9029 ** SCRIPTS sections are executed while the SCRIPTS hasn't
9030 ** started SCSI operations, it is very unlikely to happen.
9032 ** All the driver data structures are supposed to be
9033 ** allocated from the same 4 GB memory window, so there
9034 ** is a 1 to 1 relationship between DSA and driver data
9035 ** structures. Since we are careful :) to invalidate the
9036 ** DSA when we complete a command or when the SCRIPTS
9037 ** pushes a DSA into a queue, we can trust it when it
9040 **----------------------------------------------------------
9042 static void ncr_recover_scsi_int (ncb_p np
, u_char hsts
)
9044 u_int32 dsp
= INL (nc_dsp
);
9045 u_int32 dsa
= INL (nc_dsa
);
9046 ccb_p cp
= ncr_ccb_from_dsa(np
, dsa
);
9049 ** If we haven't been interrupted inside the SCRIPTS
9050 ** critical pathes, we can safely restart the SCRIPTS
9051 ** and trust the DSA value if it matches a CCB.
9053 if ((!(dsp
> NCB_SCRIPT_PHYS (np
, getjob_begin
) &&
9054 dsp
< NCB_SCRIPT_PHYS (np
, getjob_end
) + 1)) &&
9055 (!(dsp
> NCB_SCRIPT_PHYS (np
, ungetjob
) &&
9056 dsp
< NCB_SCRIPT_PHYS (np
, reselect
) + 1)) &&
9057 (!(dsp
> NCB_SCRIPTH_PHYS (np
, sel_for_abort
) &&
9058 dsp
< NCB_SCRIPTH_PHYS (np
, sel_for_abort_1
) + 1)) &&
9059 (!(dsp
> NCB_SCRIPT_PHYS (np
, done
) &&
9060 dsp
< NCB_SCRIPT_PHYS (np
, done_end
) + 1))) {
9062 cp
->host_status
= hsts
;
9063 ncr_complete (np
, cp
);
9065 OUTL (nc_dsa
, DSA_INVALID
);
9066 OUTB (nc_ctest3
, np
->rv_ctest3
| CLF
); /* clear dma fifo */
9067 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
9068 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
9076 ncr_start_reset(np
);
9079 /*==========================================================
9081 ** ncr chip exception handler for selection timeout
9083 **==========================================================
9085 ** There seems to be a bug in the 53c810.
9086 ** Although a STO-Interrupt is pending,
9087 ** it continues executing script commands.
9088 ** But it will fail and interrupt (IID) on
9089 ** the next instruction where it's looking
9090 ** for a valid phase.
9092 **----------------------------------------------------------
9095 void ncr_int_sto (ncb_p np
)
9097 u_int32 dsp
= INL (nc_dsp
);
9099 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("T");
9101 if (dsp
== NCB_SCRIPT_PHYS (np
, wf_sel_done
) + 8 ||
9102 !(driver_setup
.recovery
& 1))
9103 ncr_recover_scsi_int(np
, HS_SEL_TIMEOUT
);
9105 ncr_start_reset(np
);
9108 /*==========================================================
9110 ** ncr chip exception handler for unexpected disconnect
9112 **==========================================================
9114 **----------------------------------------------------------
9116 void ncr_int_udc (ncb_p np
)
9118 u_int32 dsa
= INL (nc_dsa
);
9119 ccb_p cp
= ncr_ccb_from_dsa(np
, dsa
);
9122 * Fix Up. Some disks respond to a PPR negotiation with
9123 * a bus free instead of a message reject.
9124 * Disable ppr negotiation if this is first time
9125 * tried ppr negotiation.
9128 tcb_p tp
= &np
->target
[cp
->target
];
9129 if (tp
->ppr_negotiation
== 1)
9130 tp
->ppr_negotiation
= 0;
9133 printk ("%s: unexpected disconnect\n", ncr_name(np
));
9134 ncr_recover_scsi_int(np
, HS_UNEXPECTED
);
9137 /*==========================================================
9139 ** ncr chip exception handler for SCSI bus mode change
9141 **==========================================================
9143 ** spi2-r12 11.2.3 says a transceiver mode change must
9144 ** generate a reset event and a device that detects a reset
9145 ** event shall initiate a hard reset. It says also that a
9146 ** device that detects a mode change shall set data transfer
9147 ** mode to eight bit asynchronous, etc...
9148 ** So, just resetting should be enough.
9151 **----------------------------------------------------------
9154 static void ncr_int_sbmc (ncb_p np
)
9156 u_char scsi_mode
= INB (nc_stest4
) & SMODE
;
9158 printk("%s: SCSI bus mode change from %x to %x.\n",
9159 ncr_name(np
), np
->scsi_mode
, scsi_mode
);
9161 np
->scsi_mode
= scsi_mode
;
9165 ** Suspend command processing for 1 second and
9166 ** reinitialize all except the chip.
9168 np
->settle_time
= ktime_get(1*HZ
);
9169 ncr_init (np
, 0, bootverbose
? "scsi mode change" : NULL
, HS_RESET
);
9172 /*==========================================================
9174 ** ncr chip exception handler for SCSI parity error.
9176 **==========================================================
9178 ** When the chip detects a SCSI parity error and is
9179 ** currently executing a (CH)MOV instruction, it does
9180 ** not interrupt immediately, but tries to finish the
9181 ** transfer of the current scatter entry before
9182 ** interrupting. The following situations may occur:
9184 ** - The complete scatter entry has been transferred
9185 ** without the device having changed phase.
9186 ** The chip will then interrupt with the DSP pointing
9187 ** to the instruction that follows the MOV.
9189 ** - A phase mismatch occurs before the MOV finished
9190 ** and phase errors are to be handled by the C code.
9191 ** The chip will then interrupt with both PAR and MA
9194 ** - A phase mismatch occurs before the MOV finished and
9195 ** phase errors are to be handled by SCRIPTS (895A or 896).
9196 ** The chip will load the DSP with the phase mismatch
9197 ** JUMP address and interrupt the host processor.
9199 **----------------------------------------------------------
9202 static void ncr_int_par (ncb_p np
, u_short sist
)
9204 u_char hsts
= INB (HS_PRT
);
9205 u_int32 dsp
= INL (nc_dsp
);
9206 u_int32 dbc
= INL (nc_dbc
);
9207 u_int32 dsa
= INL (nc_dsa
);
9208 u_char sbcl
= INB (nc_sbcl
);
9209 u_char cmd
= dbc
>> 24;
9210 int phase
= cmd
& 7;
9211 ccb_p cp
= ncr_ccb_from_dsa(np
, dsa
);
9213 printk("%s: SCSI parity error detected: SCR1=%d DBC=%x SBCL=%x\n",
9214 ncr_name(np
), hsts
, dbc
, sbcl
);
9217 ** Check that the chip is connected to the SCSI BUS.
9219 if (!(INB (nc_scntl1
) & ISCON
)) {
9220 if (!(driver_setup
.recovery
& 1)) {
9221 ncr_recover_scsi_int(np
, HS_FAIL
);
9228 ** If the nexus is not clearly identified, reset the bus.
9229 ** We will try to do better later.
9235 ** Check instruction was a MOV, direction was INPUT and
9238 if ((cmd
& 0xc0) || !(phase
& 1) || !(sbcl
& 0x8))
9242 ** Keep track of the parity error.
9244 OUTONB (HF_PRT
, HF_EXT_ERR
);
9245 cp
->xerr_status
|= XE_PARITY_ERR
;
9248 ** Prepare the message to send to the device.
9250 np
->msgout
[0] = (phase
== 7) ? M_PARITY
: M_ID_ERROR
;
9252 #ifdef SCSI_NCR_INTEGRITY_CHECKING
9254 ** Save error message. For integrity check use only.
9256 if (np
->check_integrity
)
9257 np
->check_integ_par
= np
->msgout
[0];
9261 ** If the old phase was DATA IN or DT DATA IN phase,
9262 ** we have to deal with the 3 situations described above.
9263 ** For other input phases (MSG IN and STATUS), the device
9264 ** must resend the whole thing that failed parity checking
9265 ** or signal error. So, jumping to dispatcher should be OK.
9267 if ((phase
== 1) || (phase
== 5)) {
9268 /* Phase mismatch handled by SCRIPTS */
9269 if (dsp
== NCB_SCRIPTH_PHYS (np
, pm_handle
))
9271 /* Phase mismatch handled by the C code */
9274 /* No phase mismatch occurred */
9276 OUTL (nc_temp
, dsp
);
9277 OUTL_DSP (NCB_SCRIPT_PHYS (np
, dispatch
));
9281 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
9285 ncr_start_reset(np
);
9289 /*==========================================================
9292 ** ncr chip exception handler for phase errors.
9295 **==========================================================
9297 ** We have to construct a new transfer descriptor,
9298 ** to transfer the rest of the current block.
9300 **----------------------------------------------------------
9303 static void ncr_int_ma (ncb_p np
)
9316 u_char hflags
, hflags0
;
9325 rest
= dbc
& 0xffffff;
9329 ** locate matching cp.
9331 cp
= ncr_ccb_from_dsa(np
, dsa
);
9333 if (DEBUG_FLAGS
& DEBUG_PHASE
)
9334 printk("CCB = %2x %2x %2x %2x %2x %2x\n",
9335 cp
->cmd
->cmnd
[0], cp
->cmd
->cmnd
[1], cp
->cmd
->cmnd
[2],
9336 cp
->cmd
->cmnd
[3], cp
->cmd
->cmnd
[4], cp
->cmd
->cmnd
[5]);
9339 ** Donnot take into account dma fifo and various buffers in
9340 ** INPUT phase since the chip flushes everything before
9341 ** raising the MA interrupt for interrupted INPUT phases.
9342 ** For DATA IN phase, we will check for the SWIDE later.
9344 if ((cmd
& 7) != 1 && (cmd
& 7) != 5) {
9349 ** If C1010, DFBC contains number of bytes in DMA fifo.
9350 ** else read DFIFO, CTEST[4-6] using 1 PCI bus ownership.
9352 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
9353 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
))
9354 delta
= INL(nc_dfbc
) & 0xffff;
9356 dfifo
= INL(nc_dfifo
);
9359 ** Calculate remaining bytes in DMA fifo.
9360 ** C1010 - always large fifo, value in dfbc
9361 ** Otherwise, (CTEST5 = dfifo >> 16)
9363 if (dfifo
& (DFS
<< 16))
9364 delta
= ((((dfifo
>> 8) & 0x300) |
9365 (dfifo
& 0xff)) - rest
) & 0x3ff;
9367 delta
= ((dfifo
& 0xff) - rest
) & 0x7f;
9370 ** The data in the dma fifo has not been
9371 ** transferred to the target -> add the amount
9372 ** to the rest and clear the data.
9373 ** Check the sstat2 register in case of wide
9380 ss0
= INB (nc_sstat0
);
9381 if (ss0
& OLF
) rest
++;
9382 if ((np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
9383 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
) && (ss0
& ORF
))
9385 if (cp
&& (cp
->phys
.select
.sel_scntl3
& EWS
)) {
9386 ss2
= INB (nc_sstat2
);
9387 if (ss2
& OLF1
) rest
++;
9388 if ((np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
9389 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
) && (ss2
& ORF
))
9396 OUTB (nc_ctest3
, np
->rv_ctest3
| CLF
); /* dma fifo */
9397 OUTB (nc_stest3
, TE
|CSF
); /* scsi fifo */
9401 ** log the information
9404 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
9405 printk ("P%x%x RL=%d D=%d ", cmd
&7, INB(nc_sbcl
)&7,
9406 (unsigned) rest
, (unsigned) delta
);
9409 ** try to find the interrupted script command,
9410 ** and the address at which to continue.
9414 if (dsp
> np
->p_script
&&
9415 dsp
<= np
->p_script
+ sizeof(struct script
)) {
9416 vdsp
= (u_int32
*)((char*)np
->script0
+ (dsp
-np
->p_script
-8));
9419 else if (dsp
> np
->p_scripth
&&
9420 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
9421 vdsp
= (u_int32
*)((char*)np
->scripth0
+ (dsp
-np
->p_scripth
-8));
9426 ** log the information
9428 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
9429 printk ("\nCP=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
9430 cp
, (unsigned)dsp
, (unsigned)nxtdsp
, vdsp
, cmd
);
9434 printk ("%s: interrupted SCRIPT address not found.\n",
9440 printk ("%s: SCSI phase error fixup: CCB already dequeued.\n",
9446 ** get old startaddress and old length.
9449 oadr
= scr_to_cpu(vdsp
[1]);
9451 if (cmd
& 0x10) { /* Table indirect */
9452 tblp
= (u_int32
*) ((char*) &cp
->phys
+ oadr
);
9453 olen
= scr_to_cpu(tblp
[0]);
9454 oadr
= scr_to_cpu(tblp
[1]);
9456 tblp
= (u_int32
*) 0;
9457 olen
= scr_to_cpu(vdsp
[0]) & 0xffffff;
9460 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
9461 printk ("OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
9462 (unsigned) (scr_to_cpu(vdsp
[0]) >> 24),
9469 ** check cmd against assumed interrupted script command.
9470 ** If dt data phase, the MOVE instruction hasn't bit 4 of
9474 if (((cmd
& 2) ? cmd
: (cmd
& ~4)) != (scr_to_cpu(vdsp
[0]) >> 24)) {
9475 PRINT_ADDR(cp
->cmd
);
9476 printk ("internal error: cmd=%02x != %02x=(vdsp[0] >> 24)\n",
9477 (unsigned)cmd
, (unsigned)scr_to_cpu(vdsp
[0]) >> 24);
9483 ** if old phase not dataphase, leave here.
9484 ** C/D line is low if data.
9488 PRINT_ADDR(cp
->cmd
);
9489 printk ("phase change %x-%x %d@%08x resid=%d.\n",
9490 cmd
&7, INB(nc_sbcl
)&7, (unsigned)olen
,
9491 (unsigned)oadr
, (unsigned)rest
);
9492 goto unexpected_phase
;
9496 ** Choose the correct PM save area.
9498 ** Look at the PM_SAVE SCRIPT if you want to understand
9499 ** this stuff. The equivalent code is implemented in
9500 ** SCRIPTS for the 895A and 896 that are able to handle
9501 ** PM from the SCRIPTS processor.
9504 hflags0
= INB (HF_PRT
);
9507 if (hflags
& (HF_IN_PM0
| HF_IN_PM1
| HF_DP_SAVED
)) {
9508 if (hflags
& HF_IN_PM0
)
9509 nxtdsp
= scr_to_cpu(cp
->phys
.pm0
.ret
);
9510 else if (hflags
& HF_IN_PM1
)
9511 nxtdsp
= scr_to_cpu(cp
->phys
.pm1
.ret
);
9513 if (hflags
& HF_DP_SAVED
)
9514 hflags
^= HF_ACT_PM
;
9517 if (!(hflags
& HF_ACT_PM
)) {
9519 newcmd
= NCB_SCRIPT_PHYS(np
, pm0_data
);
9523 newcmd
= NCB_SCRIPT_PHYS(np
, pm1_data
);
9526 hflags
&= ~(HF_IN_PM0
| HF_IN_PM1
| HF_DP_SAVED
);
9527 if (hflags
!= hflags0
)
9528 OUTB (HF_PRT
, hflags
);
9531 ** fillin the phase mismatch context
9534 pm
->sg
.addr
= cpu_to_scr(oadr
+ olen
- rest
);
9535 pm
->sg
.size
= cpu_to_scr(rest
);
9536 pm
->ret
= cpu_to_scr(nxtdsp
);
9539 ** If we have a SWIDE,
9540 ** - prepare the address to write the SWIDE from SCRIPTS,
9541 ** - compute the SCRIPTS address to restart from,
9542 ** - move current data pointer context by one byte.
9544 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
9545 if ( ((cmd
& 7) == 1 || (cmd
& 7) == 5)
9546 && cp
&& (cp
->phys
.select
.sel_scntl3
& EWS
) &&
9547 (INB (nc_scntl2
) & WSR
)) {
9550 #ifdef SYM_DEBUG_PM_WITH_WSR
9552 printk ("MA interrupt with WSR set - "
9553 "pm->sg.addr=%x - pm->sg.size=%d\n",
9554 pm
->sg
.addr
, pm
->sg
.size
);
9557 * Set up the table indirect for the MOVE
9558 * of the residual byte and adjust the data
9561 tmp
= scr_to_cpu(pm
->sg
.addr
);
9562 cp
->phys
.wresid
.addr
= cpu_to_scr(tmp
);
9563 pm
->sg
.addr
= cpu_to_scr(tmp
+ 1);
9564 tmp
= scr_to_cpu(pm
->sg
.size
);
9565 cp
->phys
.wresid
.size
= cpu_to_scr((tmp
&0xff000000) | 1);
9566 pm
->sg
.size
= cpu_to_scr(tmp
- 1);
9569 * If only the residual byte is to be moved,
9570 * no PM context is needed.
9572 if ((tmp
&0xffffff) == 1)
9576 * Prepare the address of SCRIPTS that will
9577 * move the residual byte to memory.
9579 nxtdsp
= NCB_SCRIPTH_PHYS (np
, wsr_ma_helper
);
9582 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
9583 PRINT_ADDR(cp
->cmd
);
9584 printk ("PM %x %x %x / %x %x %x.\n",
9585 hflags0
, hflags
, newcmd
,
9586 (unsigned)scr_to_cpu(pm
->sg
.addr
),
9587 (unsigned)scr_to_cpu(pm
->sg
.size
),
9588 (unsigned)scr_to_cpu(pm
->ret
));
9592 ** Restart the SCRIPTS processor.
9595 OUTL (nc_temp
, newcmd
);
9600 ** Unexpected phase changes that occurs when the current phase
9601 ** is not a DATA IN or DATA OUT phase are due to error conditions.
9602 ** Such event may only happen when the SCRIPTS is using a
9603 ** multibyte SCSI MOVE.
9605 ** Phase change Some possible cause
9607 ** COMMAND --> MSG IN SCSI parity error detected by target.
9608 ** COMMAND --> STATUS Bad command or refused by target.
9609 ** MSG OUT --> MSG IN Message rejected by target.
9610 ** MSG OUT --> COMMAND Bogus target that discards extended
9611 ** negotiation messages.
9613 ** The code below does not care of the new phase and so
9614 ** trusts the target. Why to annoy it ?
9615 ** If the interrupted phase is COMMAND phase, we restart at
9617 ** If a target does not get all the messages after selection,
9618 ** the code assumes blindly that the target discards extended
9619 ** messages and clears the negotiation status.
9620 ** If the target does not want all our response to negotiation,
9621 ** we force a SIR_NEGO_PROTO interrupt (it is a hack that avoids
9622 ** bloat for such a should_not_happen situation).
9623 ** In all other situation, we reset the BUS.
9624 ** Are these assumptions reasonnable ? (Wait and see ...)
9631 case 2: /* COMMAND phase */
9632 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
9635 case 3: /* STATUS phase */
9636 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
9639 case 6: /* MSG OUT phase */
9641 ** If the device may want to use untagged when we want
9642 ** tagged, we prepare an IDENTIFY without disc. granted,
9643 ** since we will not be able to handle reselect.
9644 ** Otherwise, we just don't care.
9646 if (dsp
== NCB_SCRIPT_PHYS (np
, send_ident
)) {
9647 if (cp
->tag
!= NO_TAG
&& olen
- rest
<= 3) {
9648 cp
->host_status
= HS_BUSY
;
9649 np
->msgout
[0] = M_IDENTIFY
| cp
->lun
;
9650 nxtdsp
= NCB_SCRIPTH_PHYS (np
, ident_break_atn
);
9653 nxtdsp
= NCB_SCRIPTH_PHYS (np
, ident_break
);
9655 else if (dsp
== NCB_SCRIPTH_PHYS (np
, send_wdtr
) ||
9656 dsp
== NCB_SCRIPTH_PHYS (np
, send_sdtr
) ||
9657 dsp
== NCB_SCRIPTH_PHYS (np
, send_ppr
)) {
9658 nxtdsp
= NCB_SCRIPTH_PHYS (np
, nego_bad_phase
);
9662 case 7: /* MSG IN phase */
9663 nxtdsp
= NCB_SCRIPT_PHYS (np
, clrack
);
9674 ncr_start_reset(np
);
9677 /*==========================================================
9679 ** ncr chip handler for QUEUE FULL and CHECK CONDITION
9681 **==========================================================
9683 ** On QUEUE FULL status, we set the actual tagged command
9684 ** queue depth to the number of disconnected CCBs that is
9685 ** hopefully a good value to avoid further QUEUE FULL.
9687 ** On CHECK CONDITION or COMMAND TERMINATED, we use the
9688 ** CCB of the failed command for performing a REQUEST
9689 ** SENSE SCSI command.
9691 ** We do not want to change the order commands will be
9692 ** actually queued to the device after we received a
9693 ** QUEUE FULL status. We also want to properly deal with
9694 ** contingent allegiance condition. For these reasons,
9695 ** we remove from the start queue all commands for this
9696 ** LUN that haven't been yet queued to the device and
9697 ** put them back in the correponding LUN queue, then
9698 ** requeue the CCB that failed in front of the LUN queue.
9699 ** I just hope this not to be performed too often. :)
9701 ** If we are using IMMEDIATE ARBITRATION, we clear the
9702 ** IARB hint for every commands we encounter in order not
9703 ** to be stuck with a won arbitration and no job to queue
9705 **----------------------------------------------------------
9708 static void ncr_sir_to_redo(ncb_p np
, int num
, ccb_p cp
)
9710 Scsi_Cmnd
*cmd
= cp
->cmd
;
9711 tcb_p tp
= &np
->target
[cp
->target
];
9712 lcb_p lp
= ncr_lp(np
, tp
, cp
->lun
);
9716 u_char s_status
= INB (SS_PRT
);
9722 ** If the LCB is not yet available, then only
9723 ** 1 IO is accepted, so we should have it.
9728 ** Remove all CCBs queued to the chip for that LUN and put
9729 ** them back in the LUN CCB wait queue.
9731 busyccbs
= lp
->queuedccbs
;
9732 i
= (INL (nc_scratcha
) - np
->p_squeue
) / 4;
9734 while (i
!= np
->squeueput
) {
9735 cp2
= ncr_ccb_from_dsa(np
, scr_to_cpu(np
->squeue
[i
]));
9737 #ifdef SCSI_NCR_IARB_SUPPORT
9738 /* IARB hints may not be relevant any more. Forget them. */
9739 cp2
->host_flags
&= ~HF_HINT_IARB
;
9741 if (cp2
&& cp2
->target
== cp
->target
&& cp2
->lun
== cp
->lun
) {
9742 xpt_remque(&cp2
->link_ccbq
);
9743 xpt_insque_head(&cp2
->link_ccbq
, &lp
->wait_ccbq
);
9749 np
->squeue
[j
] = np
->squeue
[i
];
9750 if ((j
+= 2) >= MAX_START
*2) j
= 0;
9752 if ((i
+= 2) >= MAX_START
*2) i
= 0;
9754 if (i
!= j
) /* Copy back the idle task if needed */
9755 np
->squeue
[j
] = np
->squeue
[i
];
9756 np
->squeueput
= j
; /* Update our current start queue pointer */
9759 ** Requeue the interrupted CCB in front of the
9760 ** LUN CCB wait queue to preserve ordering.
9762 xpt_remque(&cp
->link_ccbq
);
9763 xpt_insque_head(&cp
->link_ccbq
, &lp
->wait_ccbq
);
9769 #ifdef SCSI_NCR_IARB_SUPPORT
9770 /* IARB hint may not be relevant any more. Forget it. */
9771 cp
->host_flags
&= ~HF_HINT_IARB
;
9777 ** Now we can restart the SCRIPTS processor safely.
9779 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
9784 ncr_complete(np
, cp
);
9787 if (!lp
|| !lp
->queuedccbs
) {
9788 ncr_complete(np
, cp
);
9791 if (bootverbose
>= 1) {
9793 printk ("QUEUE FULL! %d busy, %d disconnected CCBs\n",
9794 busyccbs
, lp
->queuedccbs
);
9797 ** Decrease number of tags to the number of
9798 ** disconnected commands.
9800 if (lp
->queuedccbs
< lp
->numtags
) {
9801 lp
->numtags
= lp
->queuedccbs
;
9803 ncr_setup_tags (np
, cp
->target
, cp
->lun
);
9806 ** Repair the offending CCB.
9808 cp
->phys
.header
.savep
= cp
->startp
;
9809 cp
->phys
.header
.lastp
= cp
->lastp0
;
9810 cp
->host_status
= HS_BUSY
;
9811 cp
->scsi_status
= S_ILLEGAL
;
9812 cp
->xerr_status
= 0;
9813 cp
->extra_bytes
= 0;
9814 cp
->host_flags
&= (HF_PM_TO_C
|HF_DATA_IN
);
9821 ** If we were requesting sense, give up.
9823 if (cp
->host_flags
& HF_AUTO_SENSE
) {
9824 ncr_complete(np
, cp
);
9829 ** Save SCSI status and extended error.
9830 ** Compute the data residual now.
9832 cp
->sv_scsi_status
= cp
->scsi_status
;
9833 cp
->sv_xerr_status
= cp
->xerr_status
;
9834 cp
->resid
= ncr_compute_residual(np
, cp
);
9837 ** Device returned CHECK CONDITION status.
9838 ** Prepare all needed data strutures for getting
9845 cp
->scsi_smsg2
[0] = M_IDENTIFY
| cp
->lun
;
9849 ** If we are currently using anything different from
9850 ** async. 8 bit data transfers with that target,
9851 ** start a negotiation, since the device may want
9852 ** to report us a UNIT ATTENTION condition due to
9853 ** a cause we currently ignore, and we donnot want
9854 ** to be stuck with WIDE and/or SYNC data transfer.
9856 ** cp->nego_status is filled by ncr_prepare_nego().
9858 ** Do NOT negotiate if performing integrity check
9859 ** or if integrity check has completed, all check
9860 ** conditions will have been cleared.
9863 #ifdef SCSI_NCR_INTEGRITY_CHECKING
9864 if (DEBUG_FLAGS
& DEBUG_IC
) {
9865 printk("%s: ncr_sir_to_redo: ic_done %2X, in_progress %2X\n",
9866 ncr_name(np
), tp
->ic_done
, cp
->cmd
->ic_in_progress
);
9870 ** If parity error during integrity check,
9871 ** set the target width to narrow. Otherwise,
9872 ** do not negotiate on a request sense.
9874 if ( np
->check_integ_par
&& np
->check_integrity
9875 && cp
->cmd
->ic_in_progress
) {
9876 cp
->nego_status
= 0;
9878 ncr_ic_nego (np
, cp
, cmd
,&cp
->scsi_smsg2
[msglen
]);
9881 if (!np
->check_integrity
||
9882 (np
->check_integrity
&&
9883 (!cp
->cmd
->ic_in_progress
&& !tp
->ic_done
)) ) {
9884 ncr_negotiate(np
, tp
);
9885 cp
->nego_status
= 0;
9888 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
9889 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
))
9890 sync_offset
= tp
->sval
& 0x3f;
9892 sync_offset
= tp
->sval
& 0x1f;
9894 if ((tp
->wval
& EWS
) || sync_offset
)
9896 ncr_prepare_nego (np
, cp
, &cp
->scsi_smsg2
[msglen
]);
9901 ncr_negotiate(np
, tp
);
9902 cp
->nego_status
= 0;
9903 if ((tp
->wval
& EWS
) || (tp
->sval
& 0x1f))
9905 ncr_prepare_nego (np
, cp
, &cp
->scsi_smsg2
[msglen
]);
9906 #endif /* SCSI_NCR_INTEGRITY_CHECKING */
9909 ** Message table indirect structure.
9911 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg2
));
9912 cp
->phys
.smsg
.size
= cpu_to_scr(msglen
);
9917 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, sensecmd
));
9918 cp
->phys
.cmd
.size
= cpu_to_scr(6);
9921 ** patch requested size into sense command
9923 cp
->sensecmd
[0] = 0x03;
9924 cp
->sensecmd
[1] = cp
->lun
<< 5;
9925 cp
->sensecmd
[4] = sizeof(cp
->sense_buf
);
9930 bzero(cp
->sense_buf
, sizeof(cp
->sense_buf
));
9931 cp
->phys
.sense
.addr
= cpu_to_scr(CCB_PHYS(cp
,sense_buf
[0]));
9932 cp
->phys
.sense
.size
= cpu_to_scr(sizeof(cp
->sense_buf
));
9935 ** requeue the command.
9937 startp
= NCB_SCRIPTH_PHYS (np
, sdata_in
);
9939 cp
->phys
.header
.savep
= cpu_to_scr(startp
);
9940 cp
->phys
.header
.goalp
= cpu_to_scr(startp
+ 16);
9941 cp
->phys
.header
.lastp
= cpu_to_scr(startp
);
9942 cp
->phys
.header
.wgoalp
= cpu_to_scr(startp
+ 16);
9943 cp
->phys
.header
.wlastp
= cpu_to_scr(startp
);
9945 cp
->host_status
= cp
->nego_status
? HS_NEGOTIATE
: HS_BUSY
;
9946 cp
->scsi_status
= S_ILLEGAL
;
9947 cp
->host_flags
= (HF_AUTO_SENSE
|HF_DATA_IN
);
9949 cp
->phys
.header
.go
.start
=
9950 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
9953 ** If lp not yet allocated, requeue the command.
9956 ncr_put_start_queue(np
, cp
);
9961 ** requeue awaiting scsi commands for this lun.
9964 ncr_start_next_ccb(np
, lp
, 1);
9969 /*----------------------------------------------------------
9971 ** After a device has accepted some management message
9972 ** as BUS DEVICE RESET, ABORT TASK, etc ..., or when
9973 ** a device signals a UNIT ATTENTION condition, some
9974 ** tasks are thrown away by the device. We are required
9975 ** to reflect that on our tasks list since the device
9976 ** will never complete these tasks.
9978 ** This function completes all disconnected CCBs for a
9979 ** given target that matches the following criteria:
9980 ** - lun=-1 means any logical UNIT otherwise a given one.
9981 ** - task=-1 means any task, otherwise a given one.
9982 **----------------------------------------------------------
9984 static int ncr_clear_tasks(ncb_p np
, u_char hsts
,
9985 int target
, int lun
, int task
)
9990 for (cp
= np
->ccbc
; cp
; cp
= cp
->link_ccb
) {
9991 if (cp
->host_status
!= HS_DISCONNECT
)
9993 if (cp
->target
!= target
)
9995 if (lun
!= -1 && cp
->lun
!= lun
)
9997 if (task
!= -1 && cp
->tag
!= NO_TAG
&& cp
->scsi_smsg
[2] != task
)
9999 cp
->host_status
= hsts
;
10000 cp
->scsi_status
= S_ILLEGAL
;
10001 ncr_complete(np
, cp
);
10007 /*==========================================================
10009 ** ncr chip handler for TASKS recovery.
10011 **==========================================================
10013 ** We cannot safely abort a command, while the SCRIPTS
10014 ** processor is running, since we just would be in race
10017 ** As long as we have tasks to abort, we keep the SEM
10018 ** bit set in the ISTAT. When this bit is set, the
10019 ** SCRIPTS processor interrupts (SIR_SCRIPT_STOPPED)
10020 ** each time it enters the scheduler.
10022 ** If we have to reset a target, clear tasks of a unit,
10023 ** or to perform the abort of a disconnected job, we
10024 ** restart the SCRIPTS for selecting the target. Once
10025 ** selected, the SCRIPTS interrupts (SIR_TARGET_SELECTED).
10026 ** If it loses arbitration, the SCRIPTS will interrupt again
10027 ** the next time it will enter its scheduler, and so on ...
10029 ** On SIR_TARGET_SELECTED, we scan for the more
10030 ** appropriate thing to do:
10032 ** - If nothing, we just sent a M_ABORT message to the
10033 ** target to get rid of the useless SCSI bus ownership.
10034 ** According to the specs, no tasks shall be affected.
10035 ** - If the target is to be reset, we send it a M_RESET
10037 ** - If a logical UNIT is to be cleared , we send the
10038 ** IDENTIFY(lun) + M_ABORT.
10039 ** - If an untagged task is to be aborted, we send the
10040 ** IDENTIFY(lun) + M_ABORT.
10041 ** - If a tagged task is to be aborted, we send the
10042 ** IDENTIFY(lun) + task attributes + M_ABORT_TAG.
10044 ** Once our 'kiss of death' :) message has been accepted
10045 ** by the target, the SCRIPTS interrupts again
10046 ** (SIR_ABORT_SENT). On this interrupt, we complete
10047 ** all the CCBs that should have been aborted by the
10048 ** target according to our message.
10050 **----------------------------------------------------------
10052 static void ncr_sir_task_recovery(ncb_p np
, int num
)
10056 int target
=-1, lun
=-1, task
;
10062 ** The SCRIPTS processor stopped before starting
10063 ** the next command in order to allow us to perform
10064 ** some task recovery.
10066 case SIR_SCRIPT_STOPPED
:
10069 ** Do we have any target to reset or unit to clear ?
10071 for (i
= 0 ; i
< MAX_TARGET
; i
++) {
10072 tp
= &np
->target
[i
];
10073 if (tp
->to_reset
|| (tp
->l0p
&& tp
->l0p
->to_clear
)) {
10079 for (k
= 1 ; k
< MAX_LUN
; k
++) {
10080 if (tp
->lmp
[k
] && tp
->lmp
[k
]->to_clear
) {
10090 ** If not, look at the CCB list for any
10091 ** disconnected CCB to be aborted.
10093 if (target
== -1) {
10094 for (cp
= np
->ccbc
; cp
; cp
= cp
->link_ccb
) {
10095 if (cp
->host_status
!= HS_DISCONNECT
)
10097 if (cp
->to_abort
) {
10098 target
= cp
->target
;
10105 ** If some target is to be selected,
10106 ** prepare and start the selection.
10108 if (target
!= -1) {
10109 tp
= &np
->target
[target
];
10110 np
->abrt_sel
.sel_id
= target
;
10111 np
->abrt_sel
.sel_scntl3
= tp
->wval
;
10112 np
->abrt_sel
.sel_sxfer
= tp
->sval
;
10113 np
->abrt_sel
.sel_scntl4
= tp
->uval
;
10114 OUTL(nc_dsa
, np
->p_ncb
);
10115 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, sel_for_abort
));
10120 ** Nothing is to be selected, so we donnot need
10121 ** to synchronize with the SCRIPTS anymore.
10122 ** Remove the SEM flag from the ISTAT.
10125 OUTB (nc_istat
, SIGP
);
10128 ** Now look at CCBs to abort that haven't started yet.
10129 ** Remove all those CCBs from the start queue and
10130 ** complete them with appropriate status.
10131 ** Btw, the SCRIPTS processor is still stopped, so
10132 ** we are not in race.
10134 for (cp
= np
->ccbc
; cp
; cp
= cp
->link_ccb
) {
10135 if (cp
->host_status
!= HS_BUSY
&&
10136 cp
->host_status
!= HS_NEGOTIATE
)
10140 #ifdef SCSI_NCR_IARB_SUPPORT
10142 ** If we are using IMMEDIATE ARBITRATION, we donnot
10143 ** want to cancel the last queued CCB, since the
10144 ** SCRIPTS may have anticipated the selection.
10146 if (cp
== np
->last_cp
) {
10152 ** Compute index of next position in the start
10153 ** queue the SCRIPTS will schedule.
10155 i
= (INL (nc_scratcha
) - np
->p_squeue
) / 4;
10158 ** Remove the job from the start queue.
10162 if (i
== np
->squeueput
)
10164 if (k
== -1) { /* Not found yet */
10165 if (cp
== ncr_ccb_from_dsa(np
,
10166 scr_to_cpu(np
->squeue
[i
])))
10171 ** Once found, we have to move
10172 ** back all jobs by 1 position.
10174 np
->squeue
[k
] = np
->squeue
[i
];
10176 if (k
>= MAX_START
*2)
10181 if (i
>= MAX_START
*2)
10185 ** If job removed, repair the start queue.
10188 np
->squeue
[k
] = np
->squeue
[i
]; /* Idle task */
10189 np
->squeueput
= k
; /* Start queue pointer */
10191 cp
->host_status
= HS_ABORTED
;
10192 cp
->scsi_status
= S_ILLEGAL
;
10193 ncr_complete(np
, cp
);
10197 ** The SCRIPTS processor has selected a target
10198 ** we may have some manual recovery to perform for.
10200 case SIR_TARGET_SELECTED
:
10201 target
= (INB (nc_sdid
) & 0xf);
10202 tp
= &np
->target
[target
];
10204 np
->abrt_tbl
.addr
= cpu_to_scr(vtobus(np
->abrt_msg
));
10207 ** If the target is to be reset, prepare a
10208 ** M_RESET message and clear the to_reset flag
10209 ** since we donnot expect this operation to fail.
10211 if (tp
->to_reset
) {
10212 np
->abrt_msg
[0] = M_RESET
;
10213 np
->abrt_tbl
.size
= 1;
10219 ** Otherwise, look for some logical unit to be cleared.
10221 if (tp
->l0p
&& tp
->l0p
->to_clear
)
10223 else if (tp
->lmp
) {
10224 for (k
= 1 ; k
< MAX_LUN
; k
++) {
10225 if (tp
->lmp
[k
] && tp
->lmp
[k
]->to_clear
) {
10233 ** If a logical unit is to be cleared, prepare
10234 ** an IDENTIFY(lun) + ABORT MESSAGE.
10237 lcb_p lp
= ncr_lp(np
, tp
, lun
);
10238 lp
->to_clear
= 0; /* We donnot expect to fail here */
10239 np
->abrt_msg
[0] = M_IDENTIFY
| lun
;
10240 np
->abrt_msg
[1] = M_ABORT
;
10241 np
->abrt_tbl
.size
= 2;
10246 ** Otherwise, look for some disconnected job to
10247 ** abort for this target.
10249 for (cp
= np
->ccbc
; cp
; cp
= cp
->link_ccb
) {
10250 if (cp
->host_status
!= HS_DISCONNECT
)
10252 if (cp
->target
!= target
)
10259 ** If we have none, probably since the device has
10260 ** completed the command before we won abitration,
10261 ** send a M_ABORT message without IDENTIFY.
10262 ** According to the specs, the device must just
10263 ** disconnect the BUS and not abort any task.
10266 np
->abrt_msg
[0] = M_ABORT
;
10267 np
->abrt_tbl
.size
= 1;
10272 ** We have some task to abort.
10273 ** Set the IDENTIFY(lun)
10275 np
->abrt_msg
[0] = M_IDENTIFY
| cp
->lun
;
10278 ** If we want to abort an untagged command, we
10279 ** will send a IDENTIFY + M_ABORT.
10280 ** Otherwise (tagged command), we will send
10281 ** a IDENTITFY + task attributes + ABORT TAG.
10283 if (cp
->tag
== NO_TAG
) {
10284 np
->abrt_msg
[1] = M_ABORT
;
10285 np
->abrt_tbl
.size
= 2;
10288 np
->abrt_msg
[1] = cp
->scsi_smsg
[1];
10289 np
->abrt_msg
[2] = cp
->scsi_smsg
[2];
10290 np
->abrt_msg
[3] = M_ABORT_TAG
;
10291 np
->abrt_tbl
.size
= 4;
10293 cp
->to_abort
= 0; /* We donnot expect to fail here */
10297 ** The target has accepted our message and switched
10298 ** to BUS FREE phase as we expected.
10300 case SIR_ABORT_SENT
:
10301 target
= (INB (nc_sdid
) & 0xf);
10302 tp
= &np
->target
[target
];
10305 ** If we didn't abort anything, leave here.
10307 if (np
->abrt_msg
[0] == M_ABORT
)
10311 ** If we sent a M_RESET, then a hardware reset has
10312 ** been performed by the target.
10313 ** - Reset everything to async 8 bit
10314 ** - Tell ourself to negotiate next time :-)
10315 ** - Prepare to clear all disconnected CCBs for
10316 ** this target from our task list (lun=task=-1)
10320 if (np
->abrt_msg
[0] == M_RESET
) {
10322 tp
->wval
= np
->rv_scntl3
;
10323 tp
->uval
= np
->rv_scntl4
;
10324 ncr_set_sync_wide_status(np
, target
);
10325 ncr_negotiate(np
, tp
);
10329 ** Otherwise, check for the LUN and TASK(s)
10330 ** concerned by the cancelation.
10331 ** If it is not ABORT_TAG then it is CLEAR_QUEUE
10332 ** or an ABORT message :-)
10335 lun
= np
->abrt_msg
[0] & 0x3f;
10336 if (np
->abrt_msg
[1] == M_ABORT_TAG
)
10337 task
= np
->abrt_msg
[2];
10341 ** Complete all the CCBs the device should have
10342 ** aborted due to our 'kiss of death' message.
10344 (void) ncr_clear_tasks(np
, HS_ABORTED
, target
, lun
, task
);
10348 ** We have performed a auto-sense that succeeded.
10349 ** If the device reports a UNIT ATTENTION condition
10350 ** due to a RESET condition, we must complete all
10351 ** disconnect CCBs for this unit since the device
10352 ** shall have thrown them away.
10353 ** Since I haven't time to guess what the specs are
10354 ** expecting for other UNIT ATTENTION conditions, I
10355 ** decided to only care about RESET conditions. :)
10357 case SIR_AUTO_SENSE_DONE
:
10358 cp
= ncr_ccb_from_dsa(np
, INL (nc_dsa
));
10361 memcpy(cp
->cmd
->sense_buffer
, cp
->sense_buf
,
10362 sizeof(cp
->cmd
->sense_buffer
));
10363 p
= &cp
->cmd
->sense_buffer
[0];
10365 if (p
[0] != 0x70 || p
[2] != 0x6 || p
[12] != 0x29)
10368 (void) ncr_clear_tasks(np
, HS_RESET
, cp
->target
, cp
->lun
, -1);
10374 ** Print to the log the message we intend to send.
10376 if (num
== SIR_TARGET_SELECTED
) {
10377 PRINT_TARGET(np
, target
);
10378 ncr_printl_hex("control msgout:", np
->abrt_msg
,
10379 np
->abrt_tbl
.size
);
10380 np
->abrt_tbl
.size
= cpu_to_scr(np
->abrt_tbl
.size
);
10384 ** Let the SCRIPTS processor continue.
10390 /*==========================================================
10392 ** Gérard's alchemy:) that deals with with the data
10393 ** pointer for both MDP and the residual calculation.
10395 **==========================================================
10397 ** I didn't want to bloat the code by more than 200
10398 ** lignes for the handling of both MDP and the residual.
10399 ** This has been achieved by using a data pointer
10400 ** representation consisting in an index in the data
10401 ** array (dp_sg) and a negative offset (dp_ofs) that
10402 ** have the following meaning:
10404 ** - dp_sg = MAX_SCATTER
10405 ** we are at the end of the data script.
10406 ** - dp_sg < MAX_SCATTER
10407 ** dp_sg points to the next entry of the scatter array
10408 ** we want to transfer.
10410 ** dp_ofs represents the residual of bytes of the
10411 ** previous entry scatter entry we will send first.
10413 ** no residual to send first.
10415 ** The function ncr_evaluate_dp() accepts an arbitray
10416 ** offset (basically from the MDP message) and returns
10417 ** the corresponding values of dp_sg and dp_ofs.
10419 **----------------------------------------------------------
10422 static int ncr_evaluate_dp(ncb_p np
, ccb_p cp
, u_int32 scr
, int *ofs
)
10425 int dp_ofs
, dp_sg
, dp_sgmin
;
10430 ** Compute the resulted data pointer in term of a script
10431 ** address within some DATA script and a signed byte offset.
10435 if (dp_scr
== NCB_SCRIPT_PHYS (np
, pm0_data
))
10436 pm
= &cp
->phys
.pm0
;
10437 else if (dp_scr
== NCB_SCRIPT_PHYS (np
, pm1_data
))
10438 pm
= &cp
->phys
.pm1
;
10443 dp_scr
= scr_to_cpu(pm
->ret
);
10444 dp_ofs
-= scr_to_cpu(pm
->sg
.size
);
10448 ** Deduce the index of the sg entry.
10449 ** Keep track of the index of the first valid entry.
10450 ** If result is dp_sg = MAX_SCATTER, then we are at the
10451 ** end of the data and vice-versa.
10453 tmp
= scr_to_cpu(cp
->phys
.header
.goalp
);
10454 dp_sg
= MAX_SCATTER
;
10456 dp_sg
-= (tmp
- 8 - (int)dp_scr
) / (SCR_SG_SIZE
*4);
10457 dp_sgmin
= MAX_SCATTER
- cp
->segments
;
10460 ** Move to the sg entry the data pointer belongs to.
10462 ** If we are inside the data area, we expect result to be:
10465 ** dp_ofs = 0 and dp_sg is the index of the sg entry
10466 ** the data pointer belongs to (or the end of the data)
10468 ** dp_ofs < 0 and dp_sg is the index of the sg entry
10469 ** the data pointer belongs to + 1.
10473 while (dp_sg
> dp_sgmin
) {
10475 tmp
= scr_to_cpu(cp
->phys
.data
[dp_sg
].size
);
10476 n
= dp_ofs
+ (tmp
& 0xffffff);
10484 else if (dp_ofs
> 0) {
10485 while (dp_sg
< MAX_SCATTER
) {
10486 tmp
= scr_to_cpu(cp
->phys
.data
[dp_sg
].size
);
10487 dp_ofs
-= (tmp
& 0xffffff);
10495 ** Make sure the data pointer is inside the data area.
10496 ** If not, return some error.
10498 if (dp_sg
< dp_sgmin
|| (dp_sg
== dp_sgmin
&& dp_ofs
< 0))
10500 else if (dp_sg
> MAX_SCATTER
|| (dp_sg
== MAX_SCATTER
&& dp_ofs
> 0))
10504 ** Save the extreme pointer if needed.
10506 if (dp_sg
> cp
->ext_sg
||
10507 (dp_sg
== cp
->ext_sg
&& dp_ofs
> cp
->ext_ofs
)) {
10508 cp
->ext_sg
= dp_sg
;
10509 cp
->ext_ofs
= dp_ofs
;
10522 /*==========================================================
10524 ** ncr chip handler for MODIFY DATA POINTER MESSAGE
10526 **==========================================================
10528 ** We also call this function on IGNORE WIDE RESIDUE
10529 ** messages that do not match a SWIDE full condition.
10530 ** Btw, we assume in that situation that such a message
10531 ** is equivalent to a MODIFY DATA POINTER (offset=-1).
10533 **----------------------------------------------------------
10536 static void ncr_modify_dp(ncb_p np
, tcb_p tp
, ccb_p cp
, int ofs
)
10539 u_int32 dp_scr
= INL (nc_temp
);
10547 ** Not supported for auto_sense;
10549 if (cp
->host_flags
& HF_AUTO_SENSE
)
10553 ** Apply our alchemy:) (see comments in ncr_evaluate_dp()),
10554 ** to the resulted data pointer.
10556 dp_sg
= ncr_evaluate_dp(np
, cp
, dp_scr
, &dp_ofs
);
10561 ** And our alchemy:) allows to easily calculate the data
10562 ** script address we want to return for the next data phase.
10564 dp_ret
= cpu_to_scr(cp
->phys
.header
.goalp
);
10565 dp_ret
= dp_ret
- 8 - (MAX_SCATTER
- dp_sg
) * (SCR_SG_SIZE
*4);
10568 ** If offset / scatter entry is zero we donnot need
10569 ** a context for the new current data pointer.
10577 ** Get a context for the new current data pointer.
10579 hflags
= INB (HF_PRT
);
10581 if (hflags
& HF_DP_SAVED
)
10582 hflags
^= HF_ACT_PM
;
10584 if (!(hflags
& HF_ACT_PM
)) {
10585 pm
= &cp
->phys
.pm0
;
10586 dp_scr
= NCB_SCRIPT_PHYS (np
, pm0_data
);
10589 pm
= &cp
->phys
.pm1
;
10590 dp_scr
= NCB_SCRIPT_PHYS (np
, pm1_data
);
10593 hflags
&= ~(HF_DP_SAVED
);
10595 OUTB (HF_PRT
, hflags
);
10598 ** Set up the new current data pointer.
10599 ** ofs < 0 there, and for the next data phase, we
10600 ** want to transfer part of the data of the sg entry
10601 ** corresponding to index dp_sg-1 prior to returning
10602 ** to the main data script.
10604 pm
->ret
= cpu_to_scr(dp_ret
);
10605 tmp
= scr_to_cpu(cp
->phys
.data
[dp_sg
-1].addr
);
10606 tmp
+= scr_to_cpu(cp
->phys
.data
[dp_sg
-1].size
) + dp_ofs
;
10607 pm
->sg
.addr
= cpu_to_scr(tmp
);
10608 pm
->sg
.size
= cpu_to_scr(-dp_ofs
);
10611 OUTL (nc_temp
, dp_scr
);
10612 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
10616 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, msg_bad
));
10620 /*==========================================================
10622 ** ncr chip calculation of the data residual.
10624 **==========================================================
10626 ** As I used to say, the requirement of data residual
10627 ** in SCSI is broken, useless and cannot be achieved
10628 ** without huge complexity.
10629 ** But most OSes and even the official CAM require it.
10630 ** When stupidity happens to be so widely spread inside
10631 ** a community, it gets hard to convince.
10633 ** Anyway, I don't care, since I am not going to use
10634 ** any software that considers this data residual as
10635 ** a relevant information. :)
10637 **----------------------------------------------------------
10640 static int ncr_compute_residual(ncb_p np
, ccb_p cp
)
10642 int dp_sg
, dp_sgmin
, tmp
;
10647 * Check for some data lost or just thrown away.
10648 * We are not required to be quite accurate in this
10649 * situation. Btw, if we are odd for output and the
10650 * device claims some more data, it may well happen
10651 * than our residual be zero. :-)
10653 if (cp
->xerr_status
& (XE_EXTRA_DATA
|XE_SODL_UNRUN
|XE_SWIDE_OVRUN
)) {
10654 if (cp
->xerr_status
& XE_EXTRA_DATA
)
10655 resid
-= cp
->extra_bytes
;
10656 if (cp
->xerr_status
& XE_SODL_UNRUN
)
10658 if (cp
->xerr_status
& XE_SWIDE_OVRUN
)
10664 ** If SCRIPTS reaches its goal point, then
10665 ** there is no additionnal residual.
10667 if (cp
->phys
.header
.lastp
== cp
->phys
.header
.goalp
)
10671 ** If the last data pointer is data_io (direction
10672 ** unknown), then no data transfer should have
10675 if (cp
->phys
.header
.lastp
== NCB_SCRIPTH_PHYS (np
, data_io
))
10676 return cp
->data_len
;
10679 ** If no data transfer occurs, or if the data
10680 ** pointer is weird, return full residual.
10682 if (cp
->startp
== cp
->phys
.header
.lastp
||
10683 ncr_evaluate_dp(np
, cp
, scr_to_cpu(cp
->phys
.header
.lastp
),
10685 return cp
->data_len
;
10689 ** We are now full comfortable in the computation
10690 ** of the data residual (2's complement).
10692 dp_sgmin
= MAX_SCATTER
- cp
->segments
;
10693 resid
= -cp
->ext_ofs
;
10694 for (dp_sg
= cp
->ext_sg
; dp_sg
< MAX_SCATTER
; ++dp_sg
) {
10695 tmp
= scr_to_cpu(cp
->phys
.data
[dp_sg
].size
);
10696 resid
+= (tmp
& 0xffffff);
10700 ** Hopefully, the result is not too wrong.
10705 /*==========================================================
10707 ** Print out the containt of a SCSI message.
10709 **==========================================================
10712 static int ncr_show_msg (u_char
* msg
)
10715 printk ("%x",*msg
);
10716 if (*msg
==M_EXTENDED
) {
10717 for (i
=1;i
<8;i
++) {
10718 if (i
-1>msg
[1]) break;
10719 printk ("-%x",msg
[i
]);
10722 } else if ((*msg
& 0xf0) == 0x20) {
10723 printk ("-%x",msg
[1]);
10729 static void ncr_print_msg (ccb_p cp
, char *label
, u_char
*msg
)
10732 PRINT_ADDR(cp
->cmd
);
10734 printk ("%s: ", label
);
10736 (void) ncr_show_msg (msg
);
10740 /*===================================================================
10742 ** Negotiation for WIDE and SYNCHRONOUS DATA TRANSFER.
10744 **===================================================================
10746 ** Was Sie schon immer ueber transfermode negotiation wissen wollten ...
10748 ** We try to negotiate sync and wide transfer only after
10749 ** a successful inquire command. We look at byte 7 of the
10750 ** inquire data to determine the capabilities of the target.
10752 ** When we try to negotiate, we append the negotiation message
10753 ** to the identify and (maybe) simple tag message.
10754 ** The host status field is set to HS_NEGOTIATE to mark this
10757 ** If the target doesn't answer this message immediately
10758 ** (as required by the standard), the SIR_NEGO_FAILED interrupt
10759 ** will be raised eventually.
10760 ** The handler removes the HS_NEGOTIATE status, and sets the
10761 ** negotiated value to the default (async / nowide).
10763 ** If we receive a matching answer immediately, we check it
10764 ** for validity, and set the values.
10766 ** If we receive a Reject message immediately, we assume the
10767 ** negotiation has failed, and fall back to standard values.
10769 ** If we receive a negotiation message while not in HS_NEGOTIATE
10770 ** state, it's a target initiated negotiation. We prepare a
10771 ** (hopefully) valid answer, set our parameters, and send back
10772 ** this answer to the target.
10774 ** If the target doesn't fetch the answer (no message out phase),
10775 ** we assume the negotiation has failed, and fall back to default
10776 ** settings (SIR_NEGO_PROTO interrupt).
10778 ** When we set the values, we adjust them in all ccbs belonging
10779 ** to this target, in the controller's register, and in the "phys"
10780 ** field of the controller's struct ncb.
10782 **---------------------------------------------------------------------
10785 /*==========================================================
10787 ** ncr chip handler for SYNCHRONOUS DATA TRANSFER
10788 ** REQUEST (SDTR) message.
10790 **==========================================================
10792 ** Read comments above.
10794 **----------------------------------------------------------
10796 static void ncr_sync_nego(ncb_p np
, tcb_p tp
, ccb_p cp
)
10798 u_char scntl3
, scntl4
;
10799 u_char chg
, ofs
, per
, fak
;
10802 ** Synchronous request message received.
10805 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
10806 ncr_print_msg(cp
, "sync msg in", np
->msgin
);
10810 ** get requested values.
10814 per
= np
->msgin
[3];
10815 ofs
= np
->msgin
[4];
10816 if (ofs
==0) per
=255;
10819 ** if target sends SDTR message,
10820 ** it CAN transfer synch.
10824 tp
->inq_byte7
|= INQ7_SYNC
;
10827 ** check values against driver limits.
10830 if (per
< np
->minsync
)
10831 {chg
= 1; per
= np
->minsync
;}
10832 if (per
< tp
->minsync
)
10833 {chg
= 1; per
= tp
->minsync
;}
10834 if (ofs
> np
->maxoffs_st
)
10835 {chg
= 1; ofs
= np
->maxoffs_st
;}
10836 if (ofs
> tp
->maxoffs
)
10837 {chg
= 1; ofs
= tp
->maxoffs
;}
10840 ** Check against controller limits.
10846 ncr_getsync(np
, per
, &fak
, &scntl3
);
10860 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
10861 PRINT_ADDR(cp
->cmd
);
10862 printk ("sync: per=%d scntl3=0x%x scntl4=0x%x ofs=%d fak=%d chg=%d.\n",
10863 per
, scntl3
, scntl4
, ofs
, fak
, chg
);
10866 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
10867 OUTB (HS_PRT
, HS_BUSY
);
10868 switch (cp
->nego_status
) {
10871 ** This was an answer message
10875 ** Answer wasn't acceptable.
10877 ncr_setsync (np
, cp
, 0, 0xe0, 0);
10878 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, msg_bad
));
10883 if ((np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
10884 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
))
10885 ncr_setsync (np
, cp
, scntl3
, (fak
<<5)|ofs
,0);
10887 ncr_setsync (np
, cp
, scntl3
, ofs
, scntl4
);
10889 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
10894 ncr_setwide (np
, cp
, 0, 0);
10900 ** It was a request. Set value and
10901 ** prepare an answer message
10904 if ((np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
10905 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
))
10906 ncr_setsync (np
, cp
, scntl3
, (fak
<<5)|ofs
,0);
10908 ncr_setsync (np
, cp
, scntl3
, ofs
, scntl4
);
10910 np
->msgout
[0] = M_EXTENDED
;
10912 np
->msgout
[2] = M_X_SYNC_REQ
;
10913 np
->msgout
[3] = per
;
10914 np
->msgout
[4] = ofs
;
10916 cp
->nego_status
= NS_SYNC
;
10918 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
10919 ncr_print_msg(cp
, "sync msgout", np
->msgout
);
10922 np
->msgin
[0] = M_NOOP
;
10925 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, msg_bad
));
10927 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, sdtr_resp
));
10930 /*==========================================================
10932 ** ncr chip handler for WIDE DATA TRANSFER REQUEST
10935 **==========================================================
10937 ** Read comments above.
10939 **----------------------------------------------------------
10941 static void ncr_wide_nego(ncb_p np
, tcb_p tp
, ccb_p cp
)
10946 ** Wide request message received.
10948 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
10949 ncr_print_msg(cp
, "wide msgin", np
->msgin
);
10953 ** get requested values.
10957 wide
= np
->msgin
[3];
10960 ** if target sends WDTR message,
10961 ** it CAN transfer wide.
10965 tp
->inq_byte7
|= INQ7_WIDE16
;
10968 ** check values against driver limits.
10971 if (wide
> tp
->usrwide
)
10972 {chg
= 1; wide
= tp
->usrwide
;}
10974 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
10975 PRINT_ADDR(cp
->cmd
);
10976 printk ("wide: wide=%d chg=%d.\n", wide
, chg
);
10979 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
10980 OUTB (HS_PRT
, HS_BUSY
);
10981 switch (cp
->nego_status
) {
10984 ** This was an answer message
10988 ** Answer wasn't acceptable.
10990 ncr_setwide (np
, cp
, 0, 1);
10991 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, msg_bad
));
10996 ncr_setwide (np
, cp
, wide
, 1);
10997 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
11002 ncr_setsync (np
, cp
, 0, 0xe0, 0);
11008 ** It was a request, set value and
11009 ** prepare an answer message
11012 ncr_setwide (np
, cp
, wide
, 1);
11014 np
->msgout
[0] = M_EXTENDED
;
11016 np
->msgout
[2] = M_X_WIDE_REQ
;
11017 np
->msgout
[3] = wide
;
11019 np
->msgin
[0] = M_NOOP
;
11021 cp
->nego_status
= NS_WIDE
;
11023 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
11024 ncr_print_msg(cp
, "wide msgout", np
->msgout
);
11027 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, wdtr_resp
));
11029 /*==========================================================
11031 ** ncr chip handler for PARALLEL PROTOCOL REQUEST
11034 **==========================================================
11036 ** Read comments above.
11038 **----------------------------------------------------------
11040 static void ncr_ppr_nego(ncb_p np
, tcb_p tp
, ccb_p cp
)
11042 u_char scntl3
, scntl4
;
11043 u_char chg
, ofs
, per
, fak
, wth
, dt
;
11046 ** PPR message received.
11049 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
11050 ncr_print_msg(cp
, "ppr msg in", np
->msgin
);
11054 ** get requested values.
11058 per
= np
->msgin
[3];
11059 ofs
= np
->msgin
[5];
11060 wth
= np
->msgin
[6];
11062 if (ofs
==0) per
=255;
11065 ** if target sends sync (wide),
11066 ** it CAN transfer synch (wide).
11070 tp
->inq_byte7
|= INQ7_SYNC
;
11073 tp
->inq_byte7
|= INQ7_WIDE16
;
11076 ** check values against driver limits.
11079 if (wth
> tp
->usrwide
)
11080 {chg
= 1; wth
= tp
->usrwide
;}
11081 if (per
< np
->minsync
)
11082 {chg
= 1; per
= np
->minsync
;}
11083 if (per
< tp
->minsync
)
11084 {chg
= 1; per
= tp
->minsync
;}
11085 if (ofs
> tp
->maxoffs
)
11086 {chg
= 1; ofs
= tp
->maxoffs
;}
11089 ** Check against controller limits.
11095 scntl4
= dt
? 0x80 : 0;
11096 ncr_getsync(np
, per
, &fak
, &scntl3
);
11111 ** If target responds with Ultra 3 speed
11112 ** but narrow or not DT, reject.
11113 ** If target responds with DT request
11114 ** but not Ultra3 speeds, reject message,
11115 ** reset min sync for target to 0x0A and
11116 ** set flags to re-negotiate.
11119 if ((per
== 0x09) && ofs
&& (!wth
|| !dt
))
11121 else if (( (per
> 0x09) && dt
) )
11124 /* Not acceptable since beyond controller limit */
11125 if (!dt
&& ofs
> np
->maxoffs_st
)
11126 {chg
= 2; ofs
= np
->maxoffs_st
;}
11128 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
11129 PRINT_ADDR(cp
->cmd
);
11130 printk ("ppr: wth=%d per=%d scntl3=0x%x scntl4=0x%x ofs=%d fak=%d chg=%d.\n",
11131 wth
, per
, scntl3
, scntl4
, ofs
, fak
, chg
);
11134 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
11135 OUTB (HS_PRT
, HS_BUSY
);
11136 switch (cp
->nego_status
) {
11139 ** This was an answer message
11143 ** Answer wasn't acceptable.
11146 /* Send message reject and reset flags for
11147 ** host to re-negotiate with min period 0x0A.
11149 tp
->minsync
= 0x0A;
11153 ncr_setsyncwide (np
, cp
, 0, 0xe0, 0, 0);
11154 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, msg_bad
));
11160 if ((np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
11161 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
))
11162 ncr_setsyncwide (np
, cp
, scntl3
, (fak
<<5)|ofs
,0, wth
);
11164 ncr_setsyncwide (np
, cp
, scntl3
, ofs
, scntl4
, wth
);
11166 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
11172 ncr_setsync (np
, cp
, 0, 0xe0, 0);
11176 ncr_setwide (np
, cp
, 0, 0);
11182 ** It was a request. Set value and
11183 ** prepare an answer message
11185 ** If narrow or not DT and requesting Ultra3
11186 ** slow the bus down and force ST. If not
11187 ** requesting Ultra3, force ST.
11188 ** Max offset is 31=0x1f if ST mode.
11191 if ((per
== 0x09) && ofs
&& (!wth
|| !dt
)) {
11195 else if ( (per
> 0x09) && dt
) {
11198 if (!dt
&& ofs
> np
->maxoffs_st
)
11199 ofs
= np
->maxoffs_st
;
11201 if ((np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
11202 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
))
11203 ncr_setsyncwide (np
, cp
, scntl3
, (fak
<<5)|ofs
,0, wth
);
11205 ncr_setsyncwide (np
, cp
, scntl3
, ofs
, scntl4
, wth
);
11207 np
->msgout
[0] = M_EXTENDED
;
11209 np
->msgout
[2] = M_X_PPR_REQ
;
11210 np
->msgout
[3] = per
;
11212 np
->msgout
[5] = ofs
;
11213 np
->msgout
[6] = wth
;
11214 np
->msgout
[7] = dt
;
11216 cp
->nego_status
= NS_PPR
;
11218 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
11219 ncr_print_msg(cp
, "ppr msgout", np
->msgout
);
11222 np
->msgin
[0] = M_NOOP
;
11225 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, msg_bad
));
11227 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, ppr_resp
));
11233 ** Reset SYNC or WIDE to default settings.
11234 ** Called when a negotiation does not succeed either
11235 ** on rejection or on protocol error.
11237 static void ncr_nego_default(ncb_p np
, tcb_p tp
, ccb_p cp
)
11240 ** any error in negotiation:
11241 ** fall back to default mode.
11243 switch (cp
->nego_status
) {
11246 ncr_setsync (np
, cp
, 0, 0xe0, 0);
11250 ncr_setwide (np
, cp
, 0, 0);
11255 * ppr_negotiation is set to 1 on the first ppr nego command.
11256 * If ppr is successful, it is reset to 2.
11257 * If unsuccessful it is reset to 0.
11259 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
11260 tcb_p tp
=&np
->target
[cp
->target
];
11261 u_char factor
, offset
, width
;
11263 ncr_get_xfer_info ( np
, tp
, &factor
, &offset
, &width
);
11265 printk("Current factor %d offset %d width %d\n",
11266 factor
, offset
, width
);
11268 if (tp
->ppr_negotiation
== 2)
11269 ncr_setsyncwide (np
, cp
, 0, 0xe0, 0, 0);
11270 else if (tp
->ppr_negotiation
== 1) {
11272 /* First ppr command has received a M REJECT.
11273 * Do not change the existing wide/sync parameter
11274 * values (asyn/narrow if this as the first nego;
11275 * may be different if target initiates nego.).
11277 tp
->ppr_negotiation
= 0;
11281 tp
->ppr_negotiation
= 0;
11282 ncr_setwide (np
, cp
, 0, 0);
11286 np
->msgin
[0] = M_NOOP
;
11287 np
->msgout
[0] = M_NOOP
;
11288 cp
->nego_status
= 0;
11291 /*==========================================================
11293 ** ncr chip handler for MESSAGE REJECT received for
11294 ** a WIDE or SYNCHRONOUS negotiation.
11296 ** clear the PPR negotiation flag, all future nego.
11297 ** will be SDTR and WDTR
11299 **==========================================================
11301 ** Read comments above.
11303 **----------------------------------------------------------
11305 static void ncr_nego_rejected(ncb_p np
, tcb_p tp
, ccb_p cp
)
11307 ncr_nego_default(np
, tp
, cp
);
11308 OUTB (HS_PRT
, HS_BUSY
);
11312 /*==========================================================
11315 ** ncr chip exception handler for programmed interrupts.
11318 **==========================================================
11321 void ncr_int_sir (ncb_p np
)
11323 u_char num
= INB (nc_dsps
);
11324 u_long dsa
= INL (nc_dsa
);
11325 ccb_p cp
= ncr_ccb_from_dsa(np
, dsa
);
11326 u_char target
= INB (nc_sdid
) & 0x0f;
11327 tcb_p tp
= &np
->target
[target
];
11330 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("I#%d", num
);
11334 ** See comments in the SCRIPTS code.
11336 #ifdef SCSI_NCR_PCIQ_SYNC_ON_INTR
11337 case SIR_DUMMY_INTERRUPT
:
11342 ** The C code is currently trying to recover from something.
11343 ** Typically, user want to abort some command.
11345 case SIR_SCRIPT_STOPPED
:
11346 case SIR_TARGET_SELECTED
:
11347 case SIR_ABORT_SENT
:
11348 case SIR_AUTO_SENSE_DONE
:
11349 ncr_sir_task_recovery(np
, num
);
11352 ** The device didn't go to MSG OUT phase after having
11353 ** been selected with ATN. We donnot want to handle
11356 case SIR_SEL_ATN_NO_MSG_OUT
:
11357 printk ("%s:%d: No MSG OUT phase after selection with ATN.\n",
11358 ncr_name (np
), target
);
11361 ** The device didn't switch to MSG IN phase after
11362 ** having reseleted the initiator.
11364 case SIR_RESEL_NO_MSG_IN
:
11366 ** After reselection, the device sent a message that wasn't
11369 case SIR_RESEL_NO_IDENTIFY
:
11371 ** If devices reselecting without sending an IDENTIFY
11372 ** message still exist, this should help.
11373 ** We just assume lun=0, 1 CCB, no tag.
11376 OUTL (nc_dsa
, scr_to_cpu(tp
->l0p
->tasktbl
[0]));
11377 OUTL_DSP (NCB_SCRIPT_PHYS (np
, resel_go
));
11381 ** The device reselected a LUN we donnot know of.
11383 case SIR_RESEL_BAD_LUN
:
11384 np
->msgout
[0] = M_RESET
;
11387 ** The device reselected for an untagged nexus and we
11390 case SIR_RESEL_BAD_I_T_L
:
11391 np
->msgout
[0] = M_ABORT
;
11394 ** The device reselected for a tagged nexus that we donnot
11397 case SIR_RESEL_BAD_I_T_L_Q
:
11398 np
->msgout
[0] = M_ABORT_TAG
;
11401 ** The SCRIPTS let us know that the device has grabbed
11402 ** our message and will abort the job.
11404 case SIR_RESEL_ABORTED
:
11405 np
->lastmsg
= np
->msgout
[0];
11406 np
->msgout
[0] = M_NOOP
;
11407 printk ("%s:%d: message %x sent on bad reselection.\n",
11408 ncr_name (np
), target
, np
->lastmsg
);
11411 ** The SCRIPTS let us know that a message has been
11412 ** successfully sent to the device.
11414 case SIR_MSG_OUT_DONE
:
11415 np
->lastmsg
= np
->msgout
[0];
11416 np
->msgout
[0] = M_NOOP
;
11417 /* Should we really care of that */
11418 if (np
->lastmsg
== M_PARITY
|| np
->lastmsg
== M_ID_ERROR
) {
11420 cp
->xerr_status
&= ~XE_PARITY_ERR
;
11421 if (!cp
->xerr_status
)
11422 OUTOFFB (HF_PRT
, HF_EXT_ERR
);
11427 ** The device didn't send a GOOD SCSI status.
11428 ** We may have some work to do prior to allow
11429 ** the SCRIPTS processor to continue.
11431 case SIR_BAD_STATUS
:
11434 ncr_sir_to_redo(np
, num
, cp
);
11437 ** We are asked by the SCRIPTS to prepare a
11440 case SIR_REJECT_TO_SEND
:
11441 ncr_print_msg(cp
, "M_REJECT to send for ", np
->msgin
);
11442 np
->msgout
[0] = M_REJECT
;
11445 ** We have been ODD at the end of a DATA IN
11446 ** transfer and the device didn't send a
11447 ** IGNORE WIDE RESIDUE message.
11448 ** It is a data overrun condition.
11450 case SIR_SWIDE_OVERRUN
:
11452 OUTONB (HF_PRT
, HF_EXT_ERR
);
11453 cp
->xerr_status
|= XE_SWIDE_OVRUN
;
11457 ** We have been ODD at the end of a DATA OUT
11459 ** It is a data underrun condition.
11461 case SIR_SODL_UNDERRUN
:
11463 OUTONB (HF_PRT
, HF_EXT_ERR
);
11464 cp
->xerr_status
|= XE_SODL_UNRUN
;
11468 ** The device wants us to tranfer more data than
11469 ** expected or in the wrong direction.
11470 ** The number of extra bytes is in scratcha.
11471 ** It is a data overrun condition.
11473 case SIR_DATA_OVERRUN
:
11475 OUTONB (HF_PRT
, HF_EXT_ERR
);
11476 cp
->xerr_status
|= XE_EXTRA_DATA
;
11477 cp
->extra_bytes
+= INL (nc_scratcha
);
11481 ** The device switched to an illegal phase (4/5).
11483 case SIR_BAD_PHASE
:
11485 OUTONB (HF_PRT
, HF_EXT_ERR
);
11486 cp
->xerr_status
|= XE_BAD_PHASE
;
11490 ** We received a message.
11492 case SIR_MSG_RECEIVED
:
11495 switch (np
->msgin
[0]) {
11497 ** We received an extended message.
11498 ** We handle MODIFY DATA POINTER, SDTR, WDTR
11499 ** and reject all other extended messages.
11502 switch (np
->msgin
[2]) {
11503 case M_X_MODIFY_DP
:
11504 if (DEBUG_FLAGS
& DEBUG_POINTER
)
11505 ncr_print_msg(cp
,"modify DP",np
->msgin
);
11506 tmp
= (np
->msgin
[3]<<24) + (np
->msgin
[4]<<16) +
11507 (np
->msgin
[5]<<8) + (np
->msgin
[6]);
11508 ncr_modify_dp(np
, tp
, cp
, tmp
);
11511 ncr_sync_nego(np
, tp
, cp
);
11514 ncr_wide_nego(np
, tp
, cp
);
11517 ncr_ppr_nego(np
, tp
, cp
);
11524 ** We received a 1/2 byte message not handled from SCRIPTS.
11525 ** We are only expecting MESSAGE REJECT and IGNORE WIDE
11526 ** RESIDUE messages that haven't been anticipated by
11527 ** SCRIPTS on SWIDE full condition. Unanticipated IGNORE
11528 ** WIDE RESIDUE messages are aliased as MODIFY DP (-1).
11530 case M_IGN_RESIDUE
:
11531 if (DEBUG_FLAGS
& DEBUG_POINTER
)
11532 ncr_print_msg(cp
,"ign wide residue", np
->msgin
);
11533 ncr_modify_dp(np
, tp
, cp
, -1);
11536 if (INB (HS_PRT
) == HS_NEGOTIATE
)
11537 ncr_nego_rejected(np
, tp
, cp
);
11539 PRINT_ADDR(cp
->cmd
);
11540 printk ("M_REJECT received (%x:%x).\n",
11541 scr_to_cpu(np
->lastmsg
), np
->msgout
[0]);
11550 ** We received an unknown message.
11551 ** Ignore all MSG IN phases and reject it.
11553 case SIR_MSG_WEIRD
:
11554 ncr_print_msg(cp
, "WEIRD message received", np
->msgin
);
11555 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, msg_weird
));
11558 ** Negotiation failed.
11559 ** Target does not send us the reply.
11560 ** Remove the HS_NEGOTIATE status.
11562 case SIR_NEGO_FAILED
:
11563 OUTB (HS_PRT
, HS_BUSY
);
11565 ** Negotiation failed.
11566 ** Target does not want answer message.
11568 case SIR_NEGO_PROTO
:
11569 ncr_nego_default(np
, tp
, cp
);
11577 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, msg_bad
));
11580 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
11587 /*==========================================================
11590 ** Acquire a control block
11593 **==========================================================
11596 static ccb_p
ncr_get_ccb (ncb_p np
, u_char tn
, u_char ln
)
11598 tcb_p tp
= &np
->target
[tn
];
11599 lcb_p lp
= ncr_lp(np
, tp
, ln
);
11600 u_short tag
= NO_TAG
;
11602 ccb_p cp
= (ccb_p
) 0;
11605 ** Allocate a new CCB if needed.
11607 if (xpt_que_empty(&np
->free_ccbq
))
11608 (void) ncr_alloc_ccb(np
);
11611 ** Look for a free CCB
11613 qp
= xpt_remque_head(&np
->free_ccbq
);
11616 cp
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
11619 ** If the LCB is not yet available and we already
11620 ** have queued a CCB for a LUN without LCB,
11621 ** give up. Otherwise all is fine. :-)
11624 if (xpt_que_empty(&np
->b0_ccbq
))
11625 xpt_insque_head(&cp
->link_ccbq
, &np
->b0_ccbq
);
11630 ** Tune tag mode if asked by user.
11632 if (lp
->queuedepth
!= lp
->numtags
) {
11633 ncr_setup_tags(np
, tn
, ln
);
11637 ** Get a tag for this nexus if required.
11638 ** Keep from using more tags than we can handle.
11641 if (lp
->busyccbs
< lp
->maxnxs
) {
11642 tag
= lp
->cb_tags
[lp
->ia_tag
];
11644 if (lp
->ia_tag
== MAX_TAGS
)
11646 cp
->tags_si
= lp
->tags_si
;
11647 ++lp
->tags_sum
[cp
->tags_si
];
11654 ** Put the CCB in the LUN wait queue and
11655 ** count it as busy.
11657 xpt_insque_tail(&cp
->link_ccbq
, &lp
->wait_ccbq
);
11662 ** Remember all informations needed to free this CCB.
11669 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
11670 PRINT_LUN(np
, tn
, ln
);
11671 printk ("ccb @%p using tag %d.\n", cp
, tag
);
11677 xpt_insque_head(&cp
->link_ccbq
, &np
->free_ccbq
);
11681 /*==========================================================
11684 ** Release one control block
11687 **==========================================================
11690 static void ncr_free_ccb (ncb_p np
, ccb_p cp
)
11692 tcb_p tp
= &np
->target
[cp
->target
];
11693 lcb_p lp
= ncr_lp(np
, tp
, cp
->lun
);
11695 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
11696 PRINT_LUN(np
, cp
->target
, cp
->lun
);
11697 printk ("ccb @%p freeing tag %d.\n", cp
, cp
->tag
);
11701 ** If lun control block available, make available
11702 ** the task slot and the tag if any.
11703 ** Decrement counters.
11706 if (cp
->tag
!= NO_TAG
) {
11707 lp
->cb_tags
[lp
->if_tag
++] = cp
->tag
;
11708 if (lp
->if_tag
== MAX_TAGS
)
11710 --lp
->tags_sum
[cp
->tags_si
];
11711 lp
->tasktbl
[cp
->tag
] = cpu_to_scr(np
->p_bad_i_t_l_q
);
11713 lp
->tasktbl
[0] = cpu_to_scr(np
->p_bad_i_t_l
);
11722 ** Make this CCB available.
11724 xpt_remque(&cp
->link_ccbq
);
11725 xpt_insque_head(&cp
->link_ccbq
, &np
->free_ccbq
);
11726 cp
-> host_status
= HS_IDLE
;
11730 /*------------------------------------------------------------------------
11731 ** Allocate a CCB and initialize its fixed part.
11732 **------------------------------------------------------------------------
11733 **------------------------------------------------------------------------
11735 static ccb_p
ncr_alloc_ccb(ncb_p np
)
11741 ** Allocate memory for this CCB.
11743 cp
= m_calloc_dma(sizeof(struct ccb
), "CCB");
11748 ** Count it and initialyze it.
11753 ** Remember virtual and bus address of this ccb.
11755 cp
->p_ccb
= vtobus(cp
);
11758 ** Insert this ccb into the hashed list.
11760 hcode
= CCB_HASH_CODE(cp
->p_ccb
);
11761 cp
->link_ccbh
= np
->ccbh
[hcode
];
11762 np
->ccbh
[hcode
] = cp
;
11765 ** Initialyze the start and restart actions.
11767 cp
->phys
.header
.go
.start
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
11768 cp
->phys
.header
.go
.restart
= cpu_to_scr(NCB_SCRIPTH_PHYS(np
,bad_i_t_l
));
11771 ** Initilialyze some other fields.
11773 cp
->phys
.smsg_ext
.addr
= cpu_to_scr(NCB_PHYS(np
, msgin
[2]));
11776 ** Chain into wakeup list and free ccb queue.
11778 cp
->link_ccb
= np
->ccbc
;
11781 xpt_insque_head(&cp
->link_ccbq
, &np
->free_ccbq
);
11786 /*------------------------------------------------------------------------
11787 ** Look up a CCB from a DSA value.
11788 **------------------------------------------------------------------------
11789 **------------------------------------------------------------------------
11791 static ccb_p
ncr_ccb_from_dsa(ncb_p np
, u_long dsa
)
11796 hcode
= CCB_HASH_CODE(dsa
);
11797 cp
= np
->ccbh
[hcode
];
11799 if (cp
->p_ccb
== dsa
)
11801 cp
= cp
->link_ccbh
;
11807 /*==========================================================
11810 ** Allocation of resources for Targets/Luns/Tags.
11813 **==========================================================
11817 /*------------------------------------------------------------------------
11818 ** Target control block initialisation.
11819 **------------------------------------------------------------------------
11820 ** This data structure is fully initialized after a SCSI command
11821 ** has been successfully completed for this target.
11822 **------------------------------------------------------------------------
11824 static void ncr_init_tcb (ncb_p np
, u_char tn
)
11827 ** Check some alignments required by the chip.
11829 assert (( (offsetof(struct ncr_reg
, nc_sxfer
) ^
11830 offsetof(struct tcb
, sval
)) &3) == 0);
11831 assert (( (offsetof(struct ncr_reg
, nc_scntl3
) ^
11832 offsetof(struct tcb
, wval
)) &3) == 0);
11833 if ((np
->device_id
== PCI_DEVICE_ID_LSI_53C1010
) ||
11834 (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)){
11835 assert (( (offsetof(struct ncr_reg
, nc_scntl4
) ^
11836 offsetof(struct tcb
, uval
)) &3) == 0);
11840 /*------------------------------------------------------------------------
11841 ** Lun control block allocation and initialization.
11842 **------------------------------------------------------------------------
11843 ** This data structure is allocated and initialized after a SCSI
11844 ** command has been successfully completed for this target/lun.
11845 **------------------------------------------------------------------------
11847 static lcb_p
ncr_alloc_lcb (ncb_p np
, u_char tn
, u_char ln
)
11849 tcb_p tp
= &np
->target
[tn
];
11850 lcb_p lp
= ncr_lp(np
, tp
, ln
);
11853 ** Already done, return.
11859 ** Initialize the target control block if not yet.
11861 ncr_init_tcb(np
, tn
);
11864 ** Allocate the lcb bus address array.
11865 ** Compute the bus address of this table.
11867 if (ln
&& !tp
->luntbl
) {
11870 tp
->luntbl
= m_calloc_dma(256, "LUNTBL");
11873 for (i
= 0 ; i
< 64 ; i
++)
11874 tp
->luntbl
[i
] = cpu_to_scr(NCB_PHYS(np
, resel_badlun
));
11875 tp
->b_luntbl
= cpu_to_scr(vtobus(tp
->luntbl
));
11879 ** Allocate the table of pointers for LUN(s) > 0, if needed.
11881 if (ln
&& !tp
->lmp
) {
11882 tp
->lmp
= m_calloc(MAX_LUN
* sizeof(lcb_p
), "LMP");
11888 ** Allocate the lcb.
11889 ** Make it available to the chip.
11891 lp
= m_calloc_dma(sizeof(struct lcb
), "LCB");
11896 tp
->luntbl
[ln
] = cpu_to_scr(vtobus(lp
));
11900 tp
->b_lun0
= cpu_to_scr(vtobus(lp
));
11904 ** Initialize the CCB queue headers.
11906 xpt_que_init(&lp
->busy_ccbq
);
11907 xpt_que_init(&lp
->wait_ccbq
);
11910 ** Set max CCBs to 1 and use the default task array
11914 lp
->tasktbl
= &lp
->tasktbl_0
;
11915 lp
->b_tasktbl
= cpu_to_scr(vtobus(lp
->tasktbl
));
11916 lp
->tasktbl
[0] = cpu_to_scr(np
->p_notask
);
11917 lp
->resel_task
= cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_notag
));
11920 ** Initialize command queuing control.
11923 lp
->queuedccbs
= 1;
11924 lp
->queuedepth
= 1;
11930 /*------------------------------------------------------------------------
11931 ** Lun control block setup on INQUIRY data received.
11932 **------------------------------------------------------------------------
11933 ** We only support WIDE, SYNC for targets and CMDQ for logical units.
11934 ** This setup is done on each INQUIRY since we are expecting user
11935 ** will play with CHANGE DEFINITION commands. :-)
11936 **------------------------------------------------------------------------
11938 static lcb_p
ncr_setup_lcb (ncb_p np
, u_char tn
, u_char ln
, u_char
*inq_data
)
11940 tcb_p tp
= &np
->target
[tn
];
11941 lcb_p lp
= ncr_lp(np
, tp
, ln
);
11946 ** If no lcb, try to allocate it.
11948 if (!lp
&& !(lp
= ncr_alloc_lcb(np
, tn
, ln
)))
11951 #if 0 /* No more used. Left here as provision */
11953 ** Get device quirks.
11956 if (tp
->quirks
&& bootverbose
) {
11957 PRINT_LUN(np
, tn
, ln
);
11958 printk ("quirks=%x.\n", tp
->quirks
);
11963 ** Evaluate trustable target/unit capabilities.
11964 ** We only believe device version >= SCSI-2 that
11965 ** use appropriate response data format (2).
11966 ** But it seems that some CCS devices also
11967 ** support SYNC and I donnot want to frustrate
11971 if ((inq_data
[2] & 0x7) >= 2 && (inq_data
[3] & 0xf) == 2)
11972 inq_byte7
= inq_data
[7];
11973 else if ((inq_data
[2] & 0x7) == 1 && (inq_data
[3] & 0xf) == 1)
11974 inq_byte7
= INQ7_SYNC
;
11977 ** Throw away announced LUN capabilities if we are told
11978 ** that there is no real device supported by the logical unit.
11980 if ((inq_data
[0] & 0xe0) > 0x20 || (inq_data
[0] & 0x1f) == 0x1f)
11981 inq_byte7
&= (INQ7_SYNC
| INQ7_WIDE16
);
11984 ** If user is wanting SYNC, force this feature.
11986 if (driver_setup
.force_sync_nego
)
11987 inq_byte7
|= INQ7_SYNC
;
11990 ** Prepare negotiation if SIP capabilities have changed.
11993 if ((inq_byte7
^ tp
->inq_byte7
) & (INQ7_SYNC
| INQ7_WIDE16
)) {
11994 tp
->inq_byte7
= inq_byte7
;
11995 ncr_negotiate(np
, tp
);
11999 ** If unit supports tagged commands, allocate and
12000 ** initialyze the task table if not yet.
12002 if ((inq_byte7
& INQ7_QUEUE
) && lp
->tasktbl
== &lp
->tasktbl_0
) {
12003 lp
->tasktbl
= m_calloc_dma(MAX_TASKS
*4, "TASKTBL");
12004 if (!lp
->tasktbl
) {
12005 lp
->tasktbl
= &lp
->tasktbl_0
;
12008 lp
->b_tasktbl
= cpu_to_scr(vtobus(lp
->tasktbl
));
12009 for (i
= 0 ; i
< MAX_TASKS
; i
++)
12010 lp
->tasktbl
[i
] = cpu_to_scr(np
->p_notask
);
12012 lp
->cb_tags
= m_calloc(MAX_TAGS
, "CB_TAGS");
12015 for (i
= 0 ; i
< MAX_TAGS
; i
++)
12016 lp
->cb_tags
[i
] = i
;
12018 lp
->maxnxs
= MAX_TAGS
;
12019 lp
->tags_stime
= ktime_get(3*HZ
);
12023 ** Adjust tagged queueing status if needed.
12025 if ((inq_byte7
^ lp
->inq_byte7
) & INQ7_QUEUE
) {
12026 lp
->inq_byte7
= inq_byte7
;
12027 lp
->numtags
= lp
->maxtags
;
12028 ncr_setup_tags (np
, tn
, ln
);
12035 /*==========================================================
12038 ** Build Scatter Gather Block
12041 **==========================================================
12043 ** The transfer area may be scattered among
12044 ** several non adjacent physical pages.
12046 ** We may use MAX_SCATTER blocks.
12048 **----------------------------------------------------------
12052 ** We try to reduce the number of interrupts caused
12053 ** by unexpected phase changes due to disconnects.
12054 ** A typical harddisk may disconnect before ANY block.
12055 ** If we wanted to avoid unexpected phase changes at all
12056 ** we had to use a break point every 512 bytes.
12057 ** Of course the number of scatter/gather blocks is
12059 ** Under Linux, the scatter/gatter blocks are provided by
12060 ** the generic driver. We just have to copy addresses and
12061 ** sizes to the data segment array.
12065 ** For 64 bit systems, we use the 8 upper bits of the size field
12066 ** to provide bus address bits 32-39 to the SCRIPTS processor.
12067 ** This allows the 895A and 896 to address up to 1 TB of memory.
12068 ** For 32 bit chips on 64 bit systems, we must be provided with
12069 ** memory addresses that fit into the first 32 bit bus address
12070 ** range and so, this does not matter and we expect an error from
12071 ** the chip if this ever happen.
12073 ** We use a separate function for the case Linux does not provide
12074 ** a scatter list in order to allow better code optimization
12075 ** for the case we have a scatter list (BTW, for now this just wastes
12076 ** about 40 bytes of code for x86, but my guess is that the scatter
12077 ** code will get more complex later).
12080 #define SCATTER_ONE(data, badd, len) \
12081 (data)->addr = cpu_to_scr(badd); \
12082 (data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len);
12084 #define CROSS_16MB(p, n) (((((u_long) p) + n - 1) ^ ((u_long) p)) & ~0xffffff)
12086 static int ncr_scatter_no_sglist(ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
)
12088 struct scr_tblmove
*data
= &cp
->phys
.data
[MAX_SCATTER
-1];
12091 cp
->data_len
= cmd
->request_bufflen
;
12093 if (cmd
->request_bufflen
) {
12094 dma_addr_t baddr
= map_scsi_single_data(np
, cmd
);
12096 SCATTER_ONE(data
, baddr
, cmd
->request_bufflen
);
12097 if (CROSS_16MB(baddr
, cmd
->request_bufflen
)) {
12098 cp
->host_flags
|= HF_PM_TO_C
;
12100 printk("He! we are crossing a 16 MB boundary (0x%lx, 0x%x)\n",
12101 baddr
, cmd
->request_bufflen
);
12113 ** DEL 472 - 53C896 Rev 1 - Part Number 609-0393055 - ITEM 5.
12115 ** We disable data phase mismatch handling from SCRIPTS for data
12116 ** transfers that contains scatter/gather entries that cross
12117 ** a 16 MB boundary.
12118 ** We use a different scatter function for 896 rev. 1 that needs
12119 ** such a work-around. Doing so, we do not affect performance for
12121 ** This problem should not be triggered for disk IOs under Linux,
12122 ** since such IOs are performed using pages and buffers that are
12123 ** nicely power-of-two sized and aligned. But, since this may change
12124 ** at any time, a work-around was required.
12126 static int ncr_scatter_896R1(ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
)
12129 int use_sg
= (int) cmd
->use_sg
;
12134 segn
= ncr_scatter_no_sglist(np
, cp
, cmd
);
12136 struct scatterlist
*scatter
= (struct scatterlist
*)cmd
->buffer
;
12137 struct scr_tblmove
*data
;
12139 use_sg
= map_scsi_sg_data(np
, cmd
);
12140 if (use_sg
> MAX_SCATTER
) {
12141 unmap_scsi_data(np
, cmd
);
12145 data
= &cp
->phys
.data
[MAX_SCATTER
- use_sg
];
12147 for (segn
= 0; segn
< use_sg
; segn
++) {
12148 dma_addr_t baddr
= scsi_sg_dma_address(&scatter
[segn
]);
12149 unsigned int len
= scsi_sg_dma_len(&scatter
[segn
]);
12151 SCATTER_ONE(&data
[segn
],
12154 if (CROSS_16MB(baddr
, scatter
[segn
].length
)) {
12155 cp
->host_flags
|= HF_PM_TO_C
;
12157 printk("He! we are crossing a 16 MB boundary (0x%lx, 0x%x)\n",
12158 baddr
, scatter
[segn
].length
);
12161 cp
->data_len
+= len
;
12168 static int ncr_scatter(ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
)
12171 int use_sg
= (int) cmd
->use_sg
;
12176 segment
= ncr_scatter_no_sglist(np
, cp
, cmd
);
12178 struct scatterlist
*scatter
= (struct scatterlist
*)cmd
->buffer
;
12179 struct scr_tblmove
*data
;
12181 use_sg
= map_scsi_sg_data(np
, cmd
);
12182 if (use_sg
> MAX_SCATTER
) {
12183 unmap_scsi_data(np
, cmd
);
12186 data
= &cp
->phys
.data
[MAX_SCATTER
- use_sg
];
12188 for (segment
= 0; segment
< use_sg
; segment
++) {
12189 dma_addr_t baddr
= scsi_sg_dma_address(&scatter
[segment
]);
12190 unsigned int len
= scsi_sg_dma_len(&scatter
[segment
]);
12192 SCATTER_ONE(&data
[segment
],
12195 cp
->data_len
+= len
;
12202 /*==========================================================
12205 ** Test the pci bus snoop logic :-(
12207 ** Has to be called with interrupts disabled.
12210 **==========================================================
12213 #ifndef SCSI_NCR_IOMAPPED
12214 static int __init
ncr_regtest (struct ncb
* np
)
12216 register volatile u_int32 data
;
12218 ** ncr registers may NOT be cached.
12219 ** write 0xffffffff to a read only register area,
12220 ** and try to read it back.
12223 OUTL_OFF(offsetof(struct ncr_reg
, nc_dstat
), data
);
12224 data
= INL_OFF(offsetof(struct ncr_reg
, nc_dstat
));
12226 if (data
== 0xffffffff) {
12228 if ((data
& 0xe2f0fffd) != 0x02000080) {
12230 printk ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
12238 static int __init
ncr_snooptest (struct ncb
* np
)
12240 u_int32 ncr_rd
, ncr_wr
, ncr_bk
, host_rd
, host_wr
, pc
;
12243 #ifndef SCSI_NCR_IOMAPPED
12245 err
|= ncr_regtest (np
);
12246 if (err
) return (err
);
12251 ** Enable Master Parity Checking as we intend
12252 ** to enable it for normal operations.
12254 OUTB (nc_ctest4
, (np
->rv_ctest4
& MPEE
));
12258 pc
= NCB_SCRIPTH0_PHYS (np
, snooptest
);
12262 ** Set memory and register.
12264 np
->ncr_cache
= cpu_to_scr(host_wr
);
12265 OUTL (nc_temp
, ncr_wr
);
12267 ** Start script (exchange values)
12269 OUTL (nc_dsa
, np
->p_ncb
);
12272 ** Wait 'til done (with timeout)
12274 for (i
=0; i
<NCR_SNOOP_TIMEOUT
; i
++)
12275 if (INB(nc_istat
) & (INTF
|SIP
|DIP
))
12277 if (i
>=NCR_SNOOP_TIMEOUT
) {
12278 printk ("CACHE TEST FAILED: timeout.\n");
12282 ** Check for fatal DMA errors.
12284 dstat
= INB (nc_dstat
);
12285 #if 1 /* Band aiding for broken hardwares that fail PCI parity */
12286 if ((dstat
& MDPE
) && (np
->rv_ctest4
& MPEE
)) {
12287 printk ("%s: PCI DATA PARITY ERROR DETECTED - "
12288 "DISABLING MASTER DATA PARITY CHECKING.\n",
12290 np
->rv_ctest4
&= ~MPEE
;
12294 if (dstat
& (MDPE
|BF
|IID
)) {
12295 printk ("CACHE TEST FAILED: DMA error (dstat=0x%02x).", dstat
);
12299 ** Save termination position.
12303 ** Read memory and register.
12305 host_rd
= scr_to_cpu(np
->ncr_cache
);
12306 ncr_rd
= INL (nc_scratcha
);
12307 ncr_bk
= INL (nc_temp
);
12309 ** Check termination position.
12311 if (pc
!= NCB_SCRIPTH0_PHYS (np
, snoopend
)+8) {
12312 printk ("CACHE TEST FAILED: script execution failed.\n");
12313 printk ("start=%08lx, pc=%08lx, end=%08lx\n",
12314 (u_long
) NCB_SCRIPTH0_PHYS (np
, snooptest
), (u_long
) pc
,
12315 (u_long
) NCB_SCRIPTH0_PHYS (np
, snoopend
) +8);
12321 if (host_wr
!= ncr_rd
) {
12322 printk ("CACHE TEST FAILED: host wrote %d, ncr read %d.\n",
12323 (int) host_wr
, (int) ncr_rd
);
12326 if (host_rd
!= ncr_wr
) {
12327 printk ("CACHE TEST FAILED: ncr wrote %d, host read %d.\n",
12328 (int) ncr_wr
, (int) host_rd
);
12331 if (ncr_bk
!= ncr_wr
) {
12332 printk ("CACHE TEST FAILED: ncr wrote %d, read back %d.\n",
12333 (int) ncr_wr
, (int) ncr_bk
);
12339 /*==========================================================
12341 ** Determine the ncr's clock frequency.
12342 ** This is essential for the negotiation
12343 ** of the synchronous transfer rate.
12345 **==========================================================
12347 ** Note: we have to return the correct value.
12348 ** THERE IS NO SAFE DEFAULT VALUE.
12350 ** Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
12351 ** 53C860 and 53C875 rev. 1 support fast20 transfers but
12352 ** do not have a clock doubler and so are provided with a
12353 ** 80 MHz clock. All other fast20 boards incorporate a doubler
12354 ** and so should be delivered with a 40 MHz clock.
12355 ** The recent fast40 chips (895/896/895A) and the
12356 ** fast80 chip (C1010) use a 40 Mhz base clock
12357 ** and provide a clock quadrupler (160 Mhz). The code below
12358 ** tries to deal as cleverly as possible with all this stuff.
12360 **----------------------------------------------------------
12364 * Select NCR SCSI clock frequency
12366 static void ncr_selectclock(ncb_p np
, u_char scntl3
)
12368 if (np
->multiplier
< 2) {
12369 OUTB(nc_scntl3
, scntl3
);
12373 if (bootverbose
>= 2)
12374 printk ("%s: enabling clock multiplier\n", ncr_name(np
));
12376 OUTB(nc_stest1
, DBLEN
); /* Enable clock multiplier */
12378 if ( (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010
) &&
12379 (np
->device_id
!= PCI_DEVICE_ID_LSI_53C1010_66
) &&
12380 (np
->multiplier
> 2)) {
12381 int i
= 20; /* Poll bit 5 of stest4 for quadrupler */
12382 while (!(INB(nc_stest4
) & LCKFRQ
) && --i
> 0)
12385 printk("%s: the chip cannot lock the frequency\n",
12388 } else /* Wait 120 micro-seconds for multiplier*/
12391 OUTB(nc_stest3
, HSC
); /* Halt the scsi clock */
12392 OUTB(nc_scntl3
, scntl3
);
12393 OUTB(nc_stest1
, (DBLEN
|DBLSEL
));/* Select clock multiplier */
12394 OUTB(nc_stest3
, 0x00); /* Restart scsi clock */
12399 * calculate NCR SCSI clock frequency (in KHz)
12401 static unsigned __init
ncrgetfreq (ncb_p np
, int gen
)
12403 unsigned int ms
= 0;
12408 * Measure GEN timer delay in order
12409 * to calculate SCSI clock frequency
12411 * This code will never execute too
12412 * many loop iterations (if DELAY is
12413 * reasonably correct). It could get
12414 * too low a delay (too high a freq.)
12415 * if the CPU is slow executing the
12416 * loop for some reason (an NMI, for
12417 * example). For this reason we will
12418 * if multiple measurements are to be
12419 * performed trust the higher delay
12420 * (lower frequency returned).
12422 OUTW (nc_sien
, 0x0);/* mask all scsi interrupts */
12423 /* enable general purpose timer */
12424 (void) INW (nc_sist
); /* clear pending scsi interrupt */
12425 OUTB (nc_dien
, 0); /* mask all dma interrupts */
12426 (void) INW (nc_sist
); /* another one, just to be sure :) */
12427 OUTB (nc_scntl3
, 4); /* set pre-scaler to divide by 3 */
12428 OUTB (nc_stime1
, 0); /* disable general purpose timer */
12429 OUTB (nc_stime1
, gen
); /* set to nominal delay of 1<<gen * 125us */
12430 /* Temporary fix for udelay issue with Alpha
12432 while (!(INW(nc_sist
) & GEN
) && ms
++ < 100000) {
12434 for (count
= 0; count
< 10; count
++)
12437 OUTB (nc_stime1
, 0); /* disable general purpose timer */
12439 * set prescaler to divide by whatever 0 means
12440 * 0 ought to choose divide by 2, but appears
12441 * to set divide by 3.5 mode in my 53c810 ...
12443 OUTB (nc_scntl3
, 0);
12446 * adjust for prescaler, and convert into KHz
12447 * scale values derived empirically.
12449 f
= ms
? ((1 << gen
) * 4340) / ms
: 0;
12451 if (bootverbose
>= 2)
12452 printk ("%s: Delay (GEN=%d): %u msec, %u KHz\n",
12453 ncr_name(np
), gen
, ms
, f
);
12458 static unsigned __init
ncr_getfreq (ncb_p np
)
12463 (void) ncrgetfreq (np
, gen
); /* throw away first result */
12464 f1
= ncrgetfreq (np
, gen
);
12465 f2
= ncrgetfreq (np
, gen
);
12466 if (f1
> f2
) f1
= f2
; /* trust lower result */
12471 * Get/probe NCR SCSI clock frequency
12473 static void __init
ncr_getclock (ncb_p np
, int mult
)
12475 unsigned char scntl3
= np
->sv_scntl3
;
12476 unsigned char stest1
= np
->sv_stest1
;
12479 np
->multiplier
= 1;
12483 ** True with 875/895/896/895A with clock multiplier selected
12485 if (mult
> 1 && (stest1
& (DBLEN
+DBLSEL
)) == DBLEN
+DBLSEL
) {
12486 if (bootverbose
>= 2)
12487 printk ("%s: clock multiplier found\n", ncr_name(np
));
12488 np
->multiplier
= mult
;
12492 ** If multiplier not found or scntl3 not 7,5,3,
12493 ** reset chip and get frequency from general purpose timer.
12494 ** Otherwise trust scntl3 BIOS setting.
12496 if (np
->multiplier
!= mult
|| (scntl3
& 7) < 3 || !(scntl3
& 1)) {
12497 OUTB (nc_stest1
, 0); /* make sure doubler is OFF */
12498 f1
= ncr_getfreq (np
);
12501 printk ("%s: NCR clock is %uKHz\n", ncr_name(np
), f1
);
12503 if (f1
< 55000) f1
= 40000;
12507 ** Suggest to also check the PCI clock frequency
12508 ** to make sure our frequency calculation algorithm
12509 ** is not too biased.
12511 if (np
->features
& FE_66MHZ
) {
12512 np
->pciclock_min
= (66000*55+80-1)/80;
12513 np
->pciclock_max
= (66000*55)/40;
12516 np
->pciclock_min
= (33000*55+80-1)/80;
12517 np
->pciclock_max
= (33000*55)/40;
12520 if (f1
== 40000 && mult
> 1) {
12521 if (bootverbose
>= 2)
12522 printk ("%s: clock multiplier assumed\n", ncr_name(np
));
12523 np
->multiplier
= mult
;
12526 if ((scntl3
& 7) == 3) f1
= 40000;
12527 else if ((scntl3
& 7) == 5) f1
= 80000;
12530 f1
/= np
->multiplier
;
12534 ** Compute controller synchronous parameters.
12536 f1
*= np
->multiplier
;
12537 np
->clock_khz
= f1
;
12541 * Get/probe PCI clock frequency
12543 static u_int __init
ncr_getpciclock (ncb_p np
)
12547 OUTB (nc_stest1
, SCLK
); /* Use the PCI clock as SCSI clock */
12548 f
= ncr_getfreq (np
);
12549 OUTB (nc_stest1
, 0);
12554 /*===================== LINUX ENTRY POINTS SECTION ==========================*/
12557 #define uchar unsigned char
12561 #define ushort unsigned short
12565 #define ulong unsigned long
12568 /* ---------------------------------------------------------------------
12570 ** Driver setup from the boot command line
12572 ** ---------------------------------------------------------------------
12576 #define ARG_SEP ' '
12578 #define ARG_SEP ','
12582 #define OPT_MASTER_PARITY 2
12583 #define OPT_SCSI_PARITY 3
12584 #define OPT_DISCONNECTION 4
12585 #define OPT_SPECIAL_FEATURES 5
12586 #define OPT_RESERVED_1 6
12587 #define OPT_FORCE_SYNC_NEGO 7
12588 #define OPT_REVERSE_PROBE 8
12589 #define OPT_DEFAULT_SYNC 9
12590 #define OPT_VERBOSE 10
12591 #define OPT_DEBUG 11
12592 #define OPT_BURST_MAX 12
12593 #define OPT_LED_PIN 13
12594 #define OPT_MAX_WIDE 14
12595 #define OPT_SETTLE_DELAY 15
12596 #define OPT_DIFF_SUPPORT 16
12597 #define OPT_IRQM 17
12598 #define OPT_PCI_FIX_UP 18
12599 #define OPT_BUS_CHECK 19
12600 #define OPT_OPTIMIZE 20
12601 #define OPT_RECOVERY 21
12602 #define OPT_SAFE_SETUP 22
12603 #define OPT_USE_NVRAM 23
12604 #define OPT_EXCLUDE 24
12605 #define OPT_HOST_ID 25
12607 #ifdef SCSI_NCR_IARB_SUPPORT
12608 #define OPT_IARB 26
12611 static char setup_token
[] __initdata
=
12625 #ifdef SCSI_NCR_IARB_SUPPORT
12628 ; /* DONNOT REMOVE THIS ';' */
12631 #define ARG_SEP ' '
12633 #define ARG_SEP ','
12636 static int __init
get_setup_token(char *p
)
12638 char *cur
= setup_token
;
12642 while (cur
!= NULL
&& (pc
= strchr(cur
, ':')) != NULL
) {
12645 if (!strncmp(p
, cur
, pc
- cur
))
12653 int __init
sym53c8xx_setup(char *str
)
12655 #ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
12662 while (cur
!= NULL
&& (pc
= strchr(cur
, ':')) != NULL
) {
12674 val
= (int) simple_strtoul(pv
, &pe
, 0);
12676 switch (get_setup_token(cur
)) {
12678 driver_setup
.default_tags
= val
;
12679 if (pe
&& *pe
== '/') {
12681 while (*pe
&& *pe
!= ARG_SEP
&&
12682 i
< sizeof(driver_setup
.tag_ctrl
)-1) {
12683 driver_setup
.tag_ctrl
[i
++] = *pe
++;
12685 driver_setup
.tag_ctrl
[i
] = '\0';
12688 case OPT_MASTER_PARITY
:
12689 driver_setup
.master_parity
= val
;
12691 case OPT_SCSI_PARITY
:
12692 driver_setup
.scsi_parity
= val
;
12694 case OPT_DISCONNECTION
:
12695 driver_setup
.disconnection
= val
;
12697 case OPT_SPECIAL_FEATURES
:
12698 driver_setup
.special_features
= val
;
12700 case OPT_FORCE_SYNC_NEGO
:
12701 driver_setup
.force_sync_nego
= val
;
12703 case OPT_REVERSE_PROBE
:
12704 driver_setup
.reverse_probe
= val
;
12706 case OPT_DEFAULT_SYNC
:
12707 driver_setup
.default_sync
= val
;
12710 driver_setup
.verbose
= val
;
12713 driver_setup
.debug
= val
;
12715 case OPT_BURST_MAX
:
12716 driver_setup
.burst_max
= val
;
12719 driver_setup
.led_pin
= val
;
12722 driver_setup
.max_wide
= val
? 1:0;
12724 case OPT_SETTLE_DELAY
:
12725 driver_setup
.settle_delay
= val
;
12727 case OPT_DIFF_SUPPORT
:
12728 driver_setup
.diff_support
= val
;
12731 driver_setup
.irqm
= val
;
12733 case OPT_PCI_FIX_UP
:
12734 driver_setup
.pci_fix_up
= val
;
12736 case OPT_BUS_CHECK
:
12737 driver_setup
.bus_check
= val
;
12740 driver_setup
.optimize
= val
;
12743 driver_setup
.recovery
= val
;
12745 case OPT_USE_NVRAM
:
12746 driver_setup
.use_nvram
= val
;
12748 case OPT_SAFE_SETUP
:
12749 memcpy(&driver_setup
, &driver_safe_setup
,
12750 sizeof(driver_setup
));
12753 if (xi
< SCSI_NCR_MAX_EXCLUDES
)
12754 driver_setup
.excludes
[xi
++] = val
;
12757 driver_setup
.host_id
= val
;
12759 #ifdef SCSI_NCR_IARB_SUPPORT
12761 driver_setup
.iarb
= val
;
12765 printk("sym53c8xx_setup: unexpected boot option '%.*s' ignored\n", (int)(pc
-cur
+1), cur
);
12769 if ((cur
= strchr(cur
, ARG_SEP
)) != NULL
)
12772 #endif /* SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT */
12776 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13)
12778 __setup("sym53c8xx=", sym53c8xx_setup
);
12783 sym53c8xx_pci_init(Scsi_Host_Template
*tpnt
, pcidev_t pdev
, ncr_device
*device
);
12786 ** Linux entry point for SYM53C8XX devices detection routine.
12788 ** Called by the middle-level scsi drivers at initialization time,
12789 ** or at module installation.
12791 ** Read the PCI configuration and try to attach each
12792 ** detected NCR board.
12794 ** If NVRAM is present, try to attach boards according to
12795 ** the used defined boot order.
12797 ** Returns the number of boards successfully attached.
12800 static void __init
ncr_print_driver_setup(void)
12802 #define YesNo(y) y ? 'y' : 'n'
12803 printk (NAME53C8XX
": setup=disc:%c,specf:%d,tags:%d,sync:%d,"
12804 "burst:%d,wide:%c,diff:%d,revprob:%c,buschk:0x%x\n",
12805 YesNo(driver_setup
.disconnection
),
12806 driver_setup
.special_features
,
12807 driver_setup
.default_tags
,
12808 driver_setup
.default_sync
,
12809 driver_setup
.burst_max
,
12810 YesNo(driver_setup
.max_wide
),
12811 driver_setup
.diff_support
,
12812 YesNo(driver_setup
.reverse_probe
),
12813 driver_setup
.bus_check
);
12815 printk (NAME53C8XX
": setup=mpar:%c,spar:%c,fsn=%c,verb:%d,debug:0x%x,"
12816 "led:%c,settle:%d,irqm:0x%x,nvram:0x%x,pcifix:0x%x\n",
12817 YesNo(driver_setup
.master_parity
),
12818 YesNo(driver_setup
.scsi_parity
),
12819 YesNo(driver_setup
.force_sync_nego
),
12820 driver_setup
.verbose
,
12821 driver_setup
.debug
,
12822 YesNo(driver_setup
.led_pin
),
12823 driver_setup
.settle_delay
,
12825 driver_setup
.use_nvram
,
12826 driver_setup
.pci_fix_up
);
12830 /*===================================================================
12831 ** SYM53C8XX devices description table and chip ids list.
12832 **===================================================================
12835 static ncr_chip ncr_chip_table
[] __initdata
= SCSI_NCR_CHIP_TABLE
;
12836 static ushort ncr_chip_ids
[] __initdata
= SCSI_NCR_CHIP_IDS
;
12838 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
12839 /*===================================================================
12840 ** Detect all NCR PQS/PDS boards and keep track of their bus nr.
12842 ** The NCR PQS or PDS card is constructed as a DEC bridge
12843 ** behind which sit a proprietary NCR memory controller and
12844 ** four or two 53c875s as separate devices. In its usual mode
12845 ** of operation, the 875s are slaved to the memory controller
12846 ** for all transfers. We can tell if an 875 is part of a
12847 ** PQS/PDS or not since if it is, it will be on the same bus
12848 ** as the memory controller. To operate with the Linux
12849 ** driver, the memory controller is disabled and the 875s
12850 ** freed to function independently. The only wrinkle is that
12851 ** the preset SCSI ID (which may be zero) must be read in from
12852 ** a special configuration space register of the 875
12853 **===================================================================
12855 #define SCSI_NCR_MAX_PQS_BUS 16
12856 static int pqs_bus
[SCSI_NCR_MAX_PQS_BUS
] __initdata
= { 0 };
12858 static void __init
ncr_detect_pqs_pds(void)
12861 pcidev_t dev
= PCIDEV_NULL
;
12863 for(index
=0; index
< SCSI_NCR_MAX_PQS_BUS
; index
++) {
12866 dev
= pci_find_device(0x101a, 0x0009, dev
);
12867 if (dev
== PCIDEV_NULL
) {
12868 pqs_bus
[index
] = -1;
12871 printk(KERN_INFO NAME53C8XX
": NCR PQS/PDS memory controller detected on bus %d\n", PciBusNumber(dev
));
12872 pci_read_config_byte(dev
, 0x44, &tmp
);
12873 /* bit 1: allow individual 875 configuration */
12875 pci_write_config_byte(dev
, 0x44, tmp
);
12876 pci_read_config_byte(dev
, 0x45, &tmp
);
12877 /* bit 2: drive individual 875 interrupts to the bus */
12879 pci_write_config_byte(dev
, 0x45, tmp
);
12881 pqs_bus
[index
] = PciBusNumber(dev
);
12884 #endif /* SCSI_NCR_PQS_PDS_SUPPORT */
12886 /*===================================================================
12887 ** Detect all 53c8xx hosts and then attach them.
12889 ** If we are using NVRAM, once all hosts are detected, we need to
12890 ** check any NVRAM for boot order in case detect and boot order
12891 ** differ and attach them using the order in the NVRAM.
12893 ** If no NVRAM is found or data appears invalid attach boards in
12894 ** the order they are detected.
12895 **===================================================================
12897 int __init
sym53c8xx_detect(Scsi_Host_Template
*tpnt
)
12900 int i
, j
, chips
, hosts
, count
;
12901 int attach_count
= 0;
12902 ncr_device
*devtbl
, *devp
;
12903 #ifdef SCSI_NCR_NVRAM_SUPPORT
12904 ncr_nvram nvram0
, nvram
, *nvp
;
12908 ** PCI is required.
12910 if (!pci_present())
12914 ** Initialize driver general stuff.
12916 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
12917 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,27)
12918 tpnt
->proc_dir
= &proc_scsi_sym53c8xx
;
12920 tpnt
->proc_name
= NAME53C8XX
;
12922 tpnt
->proc_info
= sym53c8xx_proc_info
;
12925 #if defined(SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT) && defined(MODULE)
12927 sym53c8xx_setup(sym53c8xx
);
12929 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
12930 ncr_debug
= driver_setup
.debug
;
12933 if (initverbose
>= 2)
12934 ncr_print_driver_setup();
12937 ** Allocate the device table since we donnot want to
12938 ** overflow the kernel stack.
12939 ** 1 x 4K PAGE is enough for more than 40 devices for i386.
12941 devtbl
= m_calloc(PAGE_SIZE
, "devtbl");
12946 ** Detect all NCR PQS/PDS memory controllers.
12948 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
12949 ncr_detect_pqs_pds();
12953 ** Detect all 53c8xx hosts.
12954 ** Save the first Symbios NVRAM content if any
12955 ** for the boot order.
12957 chips
= sizeof(ncr_chip_ids
) / sizeof(ncr_chip_ids
[0]);
12958 hosts
= PAGE_SIZE
/ sizeof(*devtbl
);
12959 #ifdef SCSI_NCR_NVRAM_SUPPORT
12960 nvp
= (driver_setup
.use_nvram
& 0x1) ? &nvram0
: 0;
12964 pcidev
= PCIDEV_NULL
;
12967 if (count
>= hosts
)
12971 i
= driver_setup
.reverse_probe
? chips
- 1 - j
: j
;
12972 pcidev
= pci_find_device(PCI_VENDOR_ID_NCR
, ncr_chip_ids
[i
],
12974 if (pcidev
== PCIDEV_NULL
) {
12978 if (pci_enable_device(pcidev
)) /* @!*!$&*!%-*#;! */
12980 /* Some HW as the HP LH4 may report twice PCI devices */
12981 for (i
= 0; i
< count
; i
++) {
12982 if (devtbl
[i
].slot
.bus
== PciBusNumber(pcidev
) &&
12983 devtbl
[i
].slot
.device_fn
== PciDeviceFn(pcidev
))
12986 if (i
!= count
) /* Ignore this device if we already have it */
12988 pci_set_master(pcidev
);
12989 devp
= &devtbl
[count
];
12990 devp
->host_id
= driver_setup
.host_id
;
12991 devp
->attach_done
= 0;
12992 if (sym53c8xx_pci_init(tpnt
, pcidev
, devp
)) {
12996 #ifdef SCSI_NCR_NVRAM_SUPPORT
12998 ncr_get_nvram(devp
, nvp
);
12999 switch(nvp
->type
) {
13000 case SCSI_NCR_SYMBIOS_NVRAM
:
13002 * Switch to the other nvram buffer, so that
13003 * nvram0 will contain the first Symbios
13004 * format NVRAM content with boot order.
13007 msg
= "with Symbios NVRAM";
13009 case SCSI_NCR_TEKRAM_NVRAM
:
13010 msg
= "with Tekram NVRAM";
13015 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
13017 msg
= "(NCR PQS/PDS)";
13019 printk(KERN_INFO NAME53C8XX
": 53c%s detected %s\n",
13020 devp
->chip
.name
, msg
);
13024 ** If we have found a SYMBIOS NVRAM, use first the NVRAM boot
13025 ** sequence as device boot order.
13026 ** check devices in the boot record against devices detected.
13027 ** attach devices if we find a match. boot table records that
13028 ** do not match any detected devices will be ignored.
13029 ** devices that do not match any boot table will not be attached
13030 ** here but will attempt to be attached during the device table
13033 #ifdef SCSI_NCR_NVRAM_SUPPORT
13034 if (!nvp
|| nvram0
.type
!= SCSI_NCR_SYMBIOS_NVRAM
)
13036 for (i
= 0; i
< 4; i
++) {
13037 Symbios_host
*h
= &nvram0
.data
.Symbios
.host
[i
];
13038 for (j
= 0 ; j
< count
; j
++) {
13040 if (h
->device_fn
!= devp
->slot
.device_fn
||
13041 h
->bus_nr
!= devp
->slot
.bus
||
13042 h
->device_id
!= devp
->chip
.device_id
)
13044 if (devp
->attach_done
)
13046 if (h
->flags
& SYMBIOS_INIT_SCAN_AT_BOOT
) {
13047 ncr_get_nvram(devp
, nvp
);
13048 if (!ncr_attach (tpnt
, attach_count
, devp
))
13051 else if (!(driver_setup
.use_nvram
& 0x80))
13052 printk(KERN_INFO NAME53C8XX
13053 ": 53c%s state OFF thus not attached\n",
13058 devp
->attach_done
= 1;
13066 ** Rescan device list to make sure all boards attached.
13067 ** Devices without boot records will not be attached yet
13068 ** so try to attach them here.
13070 for (i
= 0; i
< count
; i
++) {
13072 if (!devp
->attach_done
) {
13073 #ifdef SCSI_NCR_NVRAM_SUPPORT
13074 ncr_get_nvram(devp
, nvp
);
13076 if (!ncr_attach (tpnt
, attach_count
, devp
))
13081 m_free(devtbl
, PAGE_SIZE
, "devtbl");
13083 return attach_count
;
13086 /*===================================================================
13087 ** Read and check the PCI configuration for any detected NCR
13088 ** boards and save data for attaching after all boards have
13090 **===================================================================
13093 sym53c8xx_pci_init(Scsi_Host_Template
*tpnt
, pcidev_t pdev
, ncr_device
*device
)
13095 u_short vendor_id
, device_id
, command
, status_reg
;
13096 u_char cache_line_size
, latency_timer
;
13097 u_char suggested_cache_line_size
= 0;
13098 u_char pci_fix_up
= driver_setup
.pci_fix_up
;
13101 u_long base
, base_c
, base_2
, base_2_c
, io_port
;
13105 printk(KERN_INFO NAME53C8XX
": at PCI bus %d, device %d, function %d\n",
13106 PciBusNumber(pdev
),
13107 (int) (PciDeviceFn(pdev
) & 0xf8) >> 3,
13108 (int) (PciDeviceFn(pdev
) & 7));
13111 ** Read info from the PCI config space.
13112 ** pci_read_config_xxx() functions are assumed to be used for
13113 ** successfully detected PCI devices.
13115 vendor_id
= PciVendorId(pdev
);
13116 device_id
= PciDeviceId(pdev
);
13117 irq
= PciIrqLine(pdev
);
13119 i
= pci_get_base_address(pdev
, 0, &io_port
);
13120 io_port
= pci_get_base_cookie(pdev
, 0);
13122 base_c
= pci_get_base_cookie(pdev
, i
);
13123 i
= pci_get_base_address(pdev
, i
, &base
);
13125 base_2_c
= pci_get_base_cookie(pdev
, i
);
13126 (void) pci_get_base_address(pdev
, i
, &base_2
);
13128 pci_read_config_word(pdev
, PCI_COMMAND
, &command
);
13129 pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &revision
);
13130 pci_read_config_byte(pdev
, PCI_CACHE_LINE_SIZE
, &cache_line_size
);
13131 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &latency_timer
);
13132 pci_read_config_word(pdev
, PCI_STATUS
, &status_reg
);
13134 #ifdef SCSI_NCR_PQS_PDS_SUPPORT
13136 ** Match the BUS number for PQS/PDS devices.
13137 ** Read the SCSI ID from a special register mapped
13138 ** into the configuration space of the individual
13139 ** 875s. This register is set up by the PQS bios
13141 for(i
= 0; i
< SCSI_NCR_MAX_PQS_BUS
&& pqs_bus
[i
] != -1; i
++) {
13143 if (pqs_bus
[i
] == PciBusNumber(pdev
)) {
13144 pci_read_config_byte(pdev
, 0x84, &tmp
);
13145 device
->pqs_pds
= 1;
13146 device
->host_id
= tmp
;
13150 #endif /* SCSI_NCR_PQS_PDS_SUPPORT */
13153 ** If user excludes this chip, donnot initialize it.
13155 for (i
= 0 ; i
< SCSI_NCR_MAX_EXCLUDES
; i
++) {
13156 if (driver_setup
.excludes
[i
] ==
13157 (io_port
& PCI_BASE_ADDRESS_IO_MASK
))
13161 ** Check if the chip is supported
13164 for (i
= 0; i
< sizeof(ncr_chip_table
)/sizeof(ncr_chip_table
[0]); i
++) {
13165 if (device_id
!= ncr_chip_table
[i
].device_id
)
13167 if (revision
> ncr_chip_table
[i
].revision_id
)
13169 if (!(ncr_chip_table
[i
].features
& FE_LDSTR
))
13171 chip
= &device
->chip
;
13172 memcpy(chip
, &ncr_chip_table
[i
], sizeof(*chip
));
13173 chip
->revision_id
= revision
;
13177 #ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
13178 /* Configure DMA attributes. For DAC capable boards, we can encode
13179 ** 32+8 bits for SCSI DMA data addresses with the extra bits used
13180 ** in the size field. We use normal 32-bit PCI addresses for
13183 if (chip
&& (chip
->features
& FE_DAC
)) {
13184 if (pci_set_dma_mask(pdev
, (u64
) 0xffffffffff))
13185 chip
->features
&= ~FE_DAC_IN_USE
;
13187 chip
->features
|= FE_DAC_IN_USE
;
13190 if (chip
&& !(chip
->features
& FE_DAC_IN_USE
)) {
13191 if (pci_set_dma_mask(pdev
, (u64
) 0xffffffff)) {
13192 printk(KERN_WARNING NAME53C8XX
13193 "32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
13200 ** Ignore Symbios chips controlled by SISL RAID controller.
13201 ** This controller sets value 0x52414944 at RAM end - 16.
13203 #if defined(__i386__) && !defined(SCSI_NCR_PCI_MEM_NOT_SUPPORTED)
13204 if (chip
&& (base_2_c
& PCI_BASE_ADDRESS_MEM_MASK
)) {
13205 unsigned int ram_size
, ram_val
;
13208 if (chip
->features
& FE_RAM8K
)
13213 ram_ptr
= remap_pci_mem(base_2_c
& PCI_BASE_ADDRESS_MEM_MASK
,
13216 ram_val
= readl_raw(ram_ptr
+ ram_size
- 16);
13217 unmap_pci_mem(ram_ptr
, ram_size
);
13218 if (ram_val
== 0x52414944) {
13219 printk(NAME53C8XX
": not initializing, "
13220 "driven by SISL RAID controller.\n");
13225 #endif /* i386 and PCI MEMORY accessible */
13228 printk(NAME53C8XX
": not initializing, device not supported\n");
13232 #if defined(__powerpc__) || defined(__hppa__)
13234 ** Fix-up for power/pc and hppa.
13235 ** Should not be performed by the driver.
13237 if ((command
& (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
))
13238 != (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
)) {
13239 printk(NAME53C8XX
": setting%s%s...\n",
13240 (command
& PCI_COMMAND_IO
) ? "" : " PCI_COMMAND_IO",
13241 (command
& PCI_COMMAND_MEMORY
) ? "" : " PCI_COMMAND_MEMORY");
13242 command
|= (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
);
13243 pci_write_config_word(pdev
, PCI_COMMAND
, command
);
13246 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,0)
13248 if (io_port
>= 0x10000000) {
13249 printk(NAME53C8XX
": reallocating io_port (Wacky IBM)");
13250 io_port
= (io_port
& 0x00FFFFFF) | 0x01000000;
13251 pci_write_config_dword(pdev
,
13252 PCI_BASE_ADDRESS_0
, io_port
);
13254 if (base
>= 0x10000000) {
13255 printk(NAME53C8XX
": reallocating base (Wacky IBM)");
13256 base
= (base
& 0x00FFFFFF) | 0x01000000;
13257 pci_write_config_dword(pdev
,
13258 PCI_BASE_ADDRESS_1
, base
);
13260 if (base_2
>= 0x10000000) {
13261 printk(NAME53C8XX
": reallocating base2 (Wacky IBM)");
13262 base_2
= (base_2
& 0x00FFFFFF) | 0x01000000;
13263 pci_write_config_dword(pdev
,
13264 PCI_BASE_ADDRESS_2
, base_2
);
13268 #endif /* __powerpc__ */
13270 #if defined(__i386__) && !defined(MODULE)
13271 if (!cache_line_size
) {
13272 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,75)
13276 switch(boot_cpu_data
.x86
) {
13278 case 4: suggested_cache_line_size
= 4; break;
13280 case 5: suggested_cache_line_size
= 8; break;
13283 #endif /* __i386__ */
13286 ** Check availability of IO space, memory space.
13287 ** Enable master capability if not yet.
13289 ** We shouldn't have to care about the IO region when
13290 ** we are using MMIO. But calling check_region() from
13291 ** both the ncr53c8xx and the sym53c8xx drivers prevents
13292 ** from attaching devices from the both drivers.
13293 ** If you have a better idea, let me know.
13295 /* #ifdef SCSI_NCR_IOMAPPED */
13297 if (!(command
& PCI_COMMAND_IO
)) {
13298 printk(NAME53C8XX
": I/O base address (0x%lx) disabled.\n",
13303 if (!(command
& PCI_COMMAND_MEMORY
)) {
13304 printk(NAME53C8XX
": PCI_COMMAND_MEMORY not set.\n");
13308 io_port
&= PCI_BASE_ADDRESS_IO_MASK
;
13309 base
&= PCI_BASE_ADDRESS_MEM_MASK
;
13310 base_2
&= PCI_BASE_ADDRESS_MEM_MASK
;
13312 /* #ifdef SCSI_NCR_IOMAPPED */
13314 if (io_port
&& check_region (io_port
, 128)) {
13315 printk(NAME53C8XX
": IO region 0x%lx[0..127] is in use\n",
13322 #ifndef SCSI_NCR_IOMAPPED
13324 printk(NAME53C8XX
": MMIO base address disabled.\n");
13330 ** Set MASTER capable and PARITY bit, if not yet.
13332 if ((command
& (PCI_COMMAND_MASTER
| PCI_COMMAND_PARITY
))
13333 != (PCI_COMMAND_MASTER
| PCI_COMMAND_PARITY
)) {
13334 printk(NAME53C8XX
": setting%s%s...(fix-up)\n",
13335 (command
& PCI_COMMAND_MASTER
) ? "" : " PCI_COMMAND_MASTER",
13336 (command
& PCI_COMMAND_PARITY
) ? "" : " PCI_COMMAND_PARITY");
13337 command
|= (PCI_COMMAND_MASTER
| PCI_COMMAND_PARITY
);
13338 pci_write_config_word(pdev
, PCI_COMMAND
, command
);
13342 ** Fix some features according to driver setup.
13344 if (!(driver_setup
.special_features
& 1))
13345 chip
->features
&= ~FE_SPECIAL_SET
;
13347 if (driver_setup
.special_features
& 2)
13348 chip
->features
&= ~FE_WRIE
;
13349 if (driver_setup
.special_features
& 4)
13350 chip
->features
&= ~FE_NOPM
;
13354 ** Work around for errant bit in 895A. The 66Mhz
13355 ** capable bit is set erroneously. Clear this bit.
13356 ** (Item 1 DEL 533)
13358 ** Make sure Config space and Features agree.
13360 ** Recall: writes are not normal to status register -
13361 ** write a 1 to clear and a 0 to leave unchanged.
13362 ** Can only reset bits.
13364 if (chip
->features
& FE_66MHZ
) {
13365 if (!(status_reg
& PCI_STATUS_66MHZ
))
13366 chip
->features
&= ~FE_66MHZ
;
13369 if (status_reg
& PCI_STATUS_66MHZ
) {
13370 status_reg
= PCI_STATUS_66MHZ
;
13371 pci_write_config_word(pdev
, PCI_STATUS
, status_reg
);
13372 pci_read_config_word(pdev
, PCI_STATUS
, &status_reg
);
13377 ** Some features are required to be enabled in order to
13378 ** work around some chip problems. :) ;)
13379 ** (ITEM 12 of a DEL about the 896 I haven't yet).
13380 ** We must ensure the chip will use WRITE AND INVALIDATE.
13381 ** The revision number limit is for now arbitrary.
13383 if (device_id
== PCI_DEVICE_ID_NCR_53C896
&& revision
<= 0x10) {
13384 chip
->features
|= (FE_WRIE
| FE_CLSE
);
13385 pci_fix_up
|= 3; /* Force appropriate PCI fix-up */
13388 #ifdef SCSI_NCR_PCI_FIX_UP_SUPPORT
13390 ** Try to fix up PCI config according to wished features.
13392 if ((pci_fix_up
& 1) && (chip
->features
& FE_CLSE
) &&
13393 !cache_line_size
&& suggested_cache_line_size
) {
13394 cache_line_size
= suggested_cache_line_size
;
13395 pci_write_config_byte(pdev
,
13396 PCI_CACHE_LINE_SIZE
, cache_line_size
);
13397 printk(NAME53C8XX
": PCI_CACHE_LINE_SIZE set to %d (fix-up).\n",
13401 if ((pci_fix_up
& 2) && cache_line_size
&&
13402 (chip
->features
& FE_WRIE
) && !(command
& PCI_COMMAND_INVALIDATE
)) {
13403 printk(NAME53C8XX
": setting PCI_COMMAND_INVALIDATE (fix-up)\n");
13404 command
|= PCI_COMMAND_INVALIDATE
;
13405 pci_write_config_word(pdev
, PCI_COMMAND
, command
);
13409 ** Tune PCI LATENCY TIMER according to burst max length transfer.
13410 ** (latency timer >= burst length + 6, we add 10 to be quite sure)
13413 if (chip
->burst_max
&& (latency_timer
== 0 || (pci_fix_up
& 4))) {
13414 uchar lt
= (1 << chip
->burst_max
) + 6 + 10;
13415 if (latency_timer
< lt
) {
13417 ": changing PCI_LATENCY_TIMER from %d to %d.\n",
13418 (int) latency_timer
, (int) lt
);
13419 latency_timer
= lt
;
13420 pci_write_config_byte(pdev
,
13421 PCI_LATENCY_TIMER
, latency_timer
);
13425 #endif /* SCSI_NCR_PCI_FIX_UP_SUPPORT */
13428 ** Initialise ncr_device structure with items required by ncr_attach.
13430 device
->pdev
= pdev
;
13431 device
->slot
.bus
= PciBusNumber(pdev
);
13432 device
->slot
.device_fn
= PciDeviceFn(pdev
);
13433 device
->slot
.base
= base
;
13434 device
->slot
.base_2
= base_2
;
13435 device
->slot
.base_c
= base_c
;
13436 device
->slot
.base_2_c
= base_2_c
;
13437 device
->slot
.io_port
= io_port
;
13438 device
->slot
.irq
= irq
;
13439 device
->attach_done
= 0;
13445 /*===================================================================
13446 ** Detect and try to read SYMBIOS and TEKRAM NVRAM.
13448 ** Data can be used to order booting of boards.
13450 ** Data is saved in ncr_device structure if NVRAM found. This
13451 ** is then used to find drive boot order for ncr_attach().
13453 ** NVRAM data is passed to Scsi_Host_Template later during
13454 ** ncr_attach() for any device set up.
13455 *===================================================================
13457 #ifdef SCSI_NCR_NVRAM_SUPPORT
13458 static void __init
ncr_get_nvram(ncr_device
*devp
, ncr_nvram
*nvp
)
13464 ** Get access to chip IO registers
13466 #ifdef SCSI_NCR_IOMAPPED
13467 request_region(devp
->slot
.io_port
, 128, NAME53C8XX
);
13468 devp
->slot
.base_io
= devp
->slot
.io_port
;
13471 (struct ncr_reg
*) remap_pci_mem(devp
->slot
.base_c
, 128);
13472 if (!devp
->slot
.reg
)
13477 ** Try to read SYMBIOS nvram.
13478 ** Try to read TEKRAM nvram if Symbios nvram not found.
13480 if (!sym_read_Symbios_nvram(&devp
->slot
, &nvp
->data
.Symbios
))
13481 nvp
->type
= SCSI_NCR_SYMBIOS_NVRAM
;
13482 else if (!sym_read_Tekram_nvram(&devp
->slot
, devp
->chip
.device_id
,
13483 &nvp
->data
.Tekram
))
13484 nvp
->type
= SCSI_NCR_TEKRAM_NVRAM
;
13491 ** Release access to chip IO registers
13493 #ifdef SCSI_NCR_IOMAPPED
13494 release_region(devp
->slot
.base_io
, 128);
13496 unmap_pci_mem((u_long
) devp
->slot
.reg
, 128ul);
13500 #endif /* SCSI_NCR_NVRAM_SUPPORT */
13503 ** Linux select queue depths function
13506 #define DEF_DEPTH (driver_setup.default_tags)
13507 #define ALL_TARGETS -2
13508 #define NO_TARGET -1
13509 #define ALL_LUNS -2
13512 static int device_queue_depth(ncb_p np
, int target
, int lun
)
13515 char *p
= driver_setup
.tag_ctrl
;
13521 while ((c
= *p
++) != 0) {
13522 v
= simple_strtoul(p
, &ep
, 0);
13531 t
= (target
== v
) ? v
: NO_TARGET
;
13536 u
= (lun
== v
) ? v
: NO_LUN
;
13539 if (h
== np
->unit
&&
13540 (t
== ALL_TARGETS
|| t
== target
) &&
13541 (u
== ALL_LUNS
|| u
== lun
))
13556 int sym53c8xx_slave_configure(Scsi_Device
*device
)
13558 struct Scsi_Host
*host
= device
->host
;
13562 int numtags
, depth_to_use
;
13564 np
= ((struct host_data
*) host
->hostdata
)->ncb
;
13565 tp
= &np
->target
[device
->id
];
13566 lp
= ncr_lp(np
, tp
, device
->lun
);
13569 ** Select queue depth from driver setup.
13570 ** Donnot use more than configured by user.
13572 ** Donnot use more than our maximum.
13574 numtags
= device_queue_depth(np
, device
->id
, device
->lun
);
13575 if (numtags
> tp
->usrtags
)
13576 numtags
= tp
->usrtags
;
13577 if (!device
->tagged_supported
)
13579 depth_to_use
= numtags
;
13580 if (depth_to_use
< 2)
13582 if (depth_to_use
> MAX_TAGS
)
13583 depth_to_use
= MAX_TAGS
;
13585 scsi_adjust_queue_depth(device
,
13586 (device
->tagged_supported
?
13587 MSG_SIMPLE_TAG
: 0),
13591 ** Since the queue depth is not tunable under Linux,
13592 ** we need to know this value in order not to
13593 ** announce stupid things to user.
13596 lp
->numtags
= lp
->maxtags
= numtags
;
13597 lp
->scdev_depth
= depth_to_use
;
13599 ncr_setup_tags (np
, device
->id
, device
->lun
);
13601 #ifdef DEBUG_SYM53C8XX
13602 printk("sym53c8xx_select_queue_depth: host=%d, id=%d, lun=%d, depth=%d\n",
13603 np
->unit
, device
->id
, device
->lun
, depth_to_use
);
13610 ** Linux entry point for info() function
13612 const char *sym53c8xx_info (struct Scsi_Host
*host
)
13614 return SCSI_NCR_DRIVER_NAME
;
13618 ** Linux entry point of queuecommand() function
13621 int sym53c8xx_queue_command (Scsi_Cmnd
*cmd
, void (* done
)(Scsi_Cmnd
*))
13623 ncb_p np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
13624 unsigned long flags
;
13627 #ifdef DEBUG_SYM53C8XX
13628 printk("sym53c8xx_queue_command\n");
13631 cmd
->scsi_done
= done
;
13632 cmd
->host_scribble
= NULL
;
13633 cmd
->SCp
.ptr
= NULL
;
13634 cmd
->SCp
.buffer
= NULL
;
13635 #ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
13636 __data_mapped(cmd
) = 0;
13637 __data_mapping(cmd
) = 0;
13640 NCR_LOCK_NCB(np
, flags
);
13642 if ((sts
= ncr_queue_command(np
, cmd
)) != DID_OK
) {
13643 SetScsiResult(cmd
, sts
, 0);
13644 #ifdef DEBUG_SYM53C8XX
13645 printk("sym53c8xx : command not queued - result=%d\n", sts
);
13648 #ifdef DEBUG_SYM53C8XX
13650 printk("sym53c8xx : command successfully queued\n");
13653 NCR_UNLOCK_NCB(np
, flags
);
13655 if (sts
!= DID_OK
) {
13656 unmap_scsi_data(np
, cmd
);
13664 ** Linux entry point of the interrupt handler.
13665 ** Since linux versions > 1.3.70, we trust the kernel for
13666 ** passing the internal host descriptor as 'dev_id'.
13667 ** Otherwise, we scan the host list and call the interrupt
13668 ** routine for each host that uses this IRQ.
13671 static void sym53c8xx_intr(int irq
, void *dev_id
, struct pt_regs
* regs
)
13673 unsigned long flags
;
13674 ncb_p np
= (ncb_p
) dev_id
;
13675 Scsi_Cmnd
*done_list
;
13677 #ifdef DEBUG_SYM53C8XX
13678 printk("sym53c8xx : interrupt received\n");
13681 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("[");
13683 NCR_LOCK_NCB(np
, flags
);
13685 done_list
= np
->done_list
;
13687 NCR_UNLOCK_NCB(np
, flags
);
13689 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("]\n");
13692 NCR_LOCK_SCSI_DONE(done_list
->device
->host
, flags
);
13693 ncr_flush_done_cmds(done_list
);
13694 NCR_UNLOCK_SCSI_DONE(done_list
->device
->host
, flags
);
13699 ** Linux entry point of the timer handler
13702 static void sym53c8xx_timeout(unsigned long npref
)
13704 ncb_p np
= (ncb_p
) npref
;
13705 unsigned long flags
;
13706 Scsi_Cmnd
*done_list
;
13708 NCR_LOCK_NCB(np
, flags
);
13709 ncr_timeout((ncb_p
) np
);
13710 done_list
= np
->done_list
;
13712 NCR_UNLOCK_NCB(np
, flags
);
13715 NCR_LOCK_SCSI_DONE(done_list
->device
->host
, flags
);
13716 ncr_flush_done_cmds(done_list
);
13717 NCR_UNLOCK_SCSI_DONE(done_list
->device
->host
, flags
);
13722 ** Linux entry point of reset() function
13725 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
13726 int sym53c8xx_reset(Scsi_Cmnd
*cmd
, unsigned int reset_flags
)
13728 int sym53c8xx_reset(Scsi_Cmnd
*cmd
)
13731 ncb_p np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
13733 unsigned long flags
;
13734 Scsi_Cmnd
*done_list
;
13736 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
13737 printk("sym53c8xx_reset: pid=%lu reset_flags=%x serial_number=%ld serial_number_at_timeout=%ld\n",
13738 cmd
->pid
, reset_flags
, cmd
->serial_number
, cmd
->serial_number_at_timeout
);
13740 printk("sym53c8xx_reset: command pid %lu\n", cmd
->pid
);
13743 NCR_LOCK_NCB(np
, flags
);
13746 * We have to just ignore reset requests in some situations.
13748 #if defined SCSI_RESET_NOT_RUNNING
13749 if (cmd
->serial_number
!= cmd
->serial_number_at_timeout
) {
13750 sts
= SCSI_RESET_NOT_RUNNING
;
13755 * If the mid-level driver told us reset is synchronous, it seems
13756 * that we must call the done() callback for the involved command,
13757 * even if this command was not queued to the low-level driver,
13758 * before returning SCSI_RESET_SUCCESS.
13761 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
13762 sts
= ncr_reset_bus(np
, cmd
,
13763 (reset_flags
& (SCSI_RESET_SYNCHRONOUS
| SCSI_RESET_ASYNCHRONOUS
)) == SCSI_RESET_SYNCHRONOUS
);
13765 sts
= ncr_reset_bus(np
, cmd
, 0);
13769 * Since we always reset the controller, when we return success,
13770 * we add this information to the return code.
13772 #if defined SCSI_RESET_HOST_RESET
13773 if (sts
== SCSI_RESET_SUCCESS
)
13774 sts
|= SCSI_RESET_HOST_RESET
;
13778 done_list
= np
->done_list
;
13780 NCR_UNLOCK_NCB(np
, flags
);
13782 ncr_flush_done_cmds(done_list
);
13788 ** Linux entry point of abort() function
13791 int sym53c8xx_abort(Scsi_Cmnd
*cmd
)
13793 ncb_p np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
13795 unsigned long flags
;
13796 Scsi_Cmnd
*done_list
;
13798 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
13799 printk("sym53c8xx_abort: pid=%lu serial_number=%ld serial_number_at_timeout=%ld\n",
13800 cmd
->pid
, cmd
->serial_number
, cmd
->serial_number_at_timeout
);
13802 printk("sym53c8xx_abort: command pid %lu\n", cmd
->pid
);
13805 NCR_LOCK_NCB(np
, flags
);
13807 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
13809 * We have to just ignore abort requests in some situations.
13811 if (cmd
->serial_number
!= cmd
->serial_number_at_timeout
) {
13812 sts
= SCSI_ABORT_NOT_RUNNING
;
13817 sts
= ncr_abort_command(np
, cmd
);
13819 done_list
= np
->done_list
;
13821 NCR_UNLOCK_NCB(np
, flags
);
13823 ncr_flush_done_cmds(done_list
);
13829 int sym53c8xx_release(struct Scsi_Host
*host
)
13831 #ifdef DEBUG_SYM53C8XX
13832 printk("sym53c8xx : release\n");
13834 ncr_detach(((struct host_data
*) host
->hostdata
)->ncb
);
13841 ** Scsi command waiting list management.
13843 ** It may happen that we cannot insert a scsi command into the start queue,
13844 ** in the following circumstances.
13845 ** Too few preallocated ccb(s),
13846 ** maxtags < cmd_per_lun of the Linux host control block,
13848 ** Such scsi commands are inserted into a waiting list.
13849 ** When a scsi command complete, we try to requeue the commands of the
13853 #define next_wcmd host_scribble
13855 static void insert_into_waiting_list(ncb_p np
, Scsi_Cmnd
*cmd
)
13859 #ifdef DEBUG_WAITING_LIST
13860 printk("%s: cmd %lx inserted into waiting list\n", ncr_name(np
), (u_long
) cmd
);
13862 cmd
->next_wcmd
= 0;
13863 if (!(wcmd
= np
->waiting_list
)) np
->waiting_list
= cmd
;
13865 while ((wcmd
->next_wcmd
) != 0)
13866 wcmd
= (Scsi_Cmnd
*) wcmd
->next_wcmd
;
13867 wcmd
->next_wcmd
= (char *) cmd
;
13871 static Scsi_Cmnd
*retrieve_from_waiting_list(int to_remove
, ncb_p np
, Scsi_Cmnd
*cmd
)
13873 Scsi_Cmnd
**pcmd
= &np
->waiting_list
;
13876 if (cmd
== *pcmd
) {
13878 *pcmd
= (Scsi_Cmnd
*) cmd
->next_wcmd
;
13879 cmd
->next_wcmd
= 0;
13881 #ifdef DEBUG_WAITING_LIST
13882 printk("%s: cmd %lx retrieved from waiting list\n", ncr_name(np
), (u_long
) cmd
);
13886 pcmd
= (Scsi_Cmnd
**) &(*pcmd
)->next_wcmd
;
13891 static void process_waiting_list(ncb_p np
, int sts
)
13893 Scsi_Cmnd
*waiting_list
, *wcmd
;
13895 waiting_list
= np
->waiting_list
;
13896 np
->waiting_list
= 0;
13898 #ifdef DEBUG_WAITING_LIST
13899 if (waiting_list
) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np
), (u_long
) waiting_list
, sts
);
13901 while ((wcmd
= waiting_list
) != 0) {
13902 waiting_list
= (Scsi_Cmnd
*) wcmd
->next_wcmd
;
13903 wcmd
->next_wcmd
= 0;
13904 if (sts
== DID_OK
) {
13905 #ifdef DEBUG_WAITING_LIST
13906 printk("%s: cmd %lx trying to requeue\n", ncr_name(np
), (u_long
) wcmd
);
13908 sts
= ncr_queue_command(np
, wcmd
);
13910 if (sts
!= DID_OK
) {
13911 #ifdef DEBUG_WAITING_LIST
13912 printk("%s: cmd %lx done forced sts=%d\n", ncr_name(np
), (u_long
) wcmd
, sts
);
13914 SetScsiResult(wcmd
, sts
, 0);
13915 ncr_queue_done_cmd(np
, wcmd
);
13922 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
13924 /*=========================================================================
13925 ** Proc file system stuff
13927 ** A read operation returns adapter information.
13928 ** A write operation is a control command.
13929 ** The string is parsed in the driver code and the command is passed
13930 ** to the ncr_usercmd() function.
13931 **=========================================================================
13934 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
13936 #define is_digit(c) ((c) >= '0' && (c) <= '9')
13937 #define digit_to_bin(c) ((c) - '0')
13938 #define is_space(c) ((c) == ' ' || (c) == '\t')
13940 static int skip_spaces(char *ptr
, int len
)
13944 for (cnt
= len
; cnt
> 0 && (c
= *ptr
++) && is_space(c
); cnt
--);
13946 return (len
- cnt
);
13949 static int get_int_arg(char *ptr
, int len
, u_long
*pv
)
13954 for (v
= 0, cnt
= len
; cnt
> 0 && (c
= *ptr
++) && is_digit(c
); cnt
--) {
13955 v
= (v
* 10) + digit_to_bin(c
);
13961 return (len
- cnt
);
13964 static int is_keyword(char *ptr
, int len
, char *verb
)
13966 int verb_len
= strlen(verb
);
13968 if (len
>= strlen(verb
) && !memcmp(verb
, ptr
, verb_len
))
13975 #define SKIP_SPACES(min_spaces) \
13976 if ((arg_len = skip_spaces(ptr, len)) < (min_spaces)) \
13978 ptr += arg_len; len -= arg_len;
13980 #define GET_INT_ARG(v) \
13981 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
13983 ptr += arg_len; len -= arg_len;
13987 ** Parse a control command
13990 static int ncr_user_command(ncb_p np
, char *buffer
, int length
)
13992 char *ptr
= buffer
;
13994 struct usrcmd
*uc
= &np
->user
;
13998 bzero(uc
, sizeof(*uc
));
14000 if (len
> 0 && ptr
[len
-1] == '\n')
14003 if ((arg_len
= is_keyword(ptr
, len
, "setsync")) != 0)
14004 uc
->cmd
= UC_SETSYNC
;
14005 else if ((arg_len
= is_keyword(ptr
, len
, "settags")) != 0)
14006 uc
->cmd
= UC_SETTAGS
;
14007 else if ((arg_len
= is_keyword(ptr
, len
, "setorder")) != 0)
14008 uc
->cmd
= UC_SETORDER
;
14009 else if ((arg_len
= is_keyword(ptr
, len
, "setverbose")) != 0)
14010 uc
->cmd
= UC_SETVERBOSE
;
14011 else if ((arg_len
= is_keyword(ptr
, len
, "setwide")) != 0)
14012 uc
->cmd
= UC_SETWIDE
;
14013 else if ((arg_len
= is_keyword(ptr
, len
, "setdebug")) != 0)
14014 uc
->cmd
= UC_SETDEBUG
;
14015 else if ((arg_len
= is_keyword(ptr
, len
, "setflag")) != 0)
14016 uc
->cmd
= UC_SETFLAG
;
14017 else if ((arg_len
= is_keyword(ptr
, len
, "resetdev")) != 0)
14018 uc
->cmd
= UC_RESETDEV
;
14019 else if ((arg_len
= is_keyword(ptr
, len
, "cleardev")) != 0)
14020 uc
->cmd
= UC_CLEARDEV
;
14024 #ifdef DEBUG_PROC_INFO
14025 printk("ncr_user_command: arg_len=%d, cmd=%ld\n", arg_len
, uc
->cmd
);
14030 ptr
+= arg_len
; len
-= arg_len
;
14040 if ((arg_len
= is_keyword(ptr
, len
, "all")) != 0) {
14041 ptr
+= arg_len
; len
-= arg_len
;
14044 GET_INT_ARG(target
);
14045 uc
->target
= (1<<target
);
14046 #ifdef DEBUG_PROC_INFO
14047 printk("ncr_user_command: target=%ld\n", target
);
14054 case UC_SETVERBOSE
:
14059 GET_INT_ARG(uc
->data
);
14060 #ifdef DEBUG_PROC_INFO
14061 printk("ncr_user_command: data=%ld\n", uc
->data
);
14066 if ((arg_len
= is_keyword(ptr
, len
, "simple")))
14067 uc
->data
= M_SIMPLE_TAG
;
14068 else if ((arg_len
= is_keyword(ptr
, len
, "ordered")))
14069 uc
->data
= M_ORDERED_TAG
;
14070 else if ((arg_len
= is_keyword(ptr
, len
, "default")))
14078 if ((arg_len
= is_keyword(ptr
, len
, "alloc")))
14079 uc
->data
|= DEBUG_ALLOC
;
14080 else if ((arg_len
= is_keyword(ptr
, len
, "phase")))
14081 uc
->data
|= DEBUG_PHASE
;
14082 else if ((arg_len
= is_keyword(ptr
, len
, "queue")))
14083 uc
->data
|= DEBUG_QUEUE
;
14084 else if ((arg_len
= is_keyword(ptr
, len
, "result")))
14085 uc
->data
|= DEBUG_RESULT
;
14086 else if ((arg_len
= is_keyword(ptr
, len
, "pointer")))
14087 uc
->data
|= DEBUG_POINTER
;
14088 else if ((arg_len
= is_keyword(ptr
, len
, "script")))
14089 uc
->data
|= DEBUG_SCRIPT
;
14090 else if ((arg_len
= is_keyword(ptr
, len
, "tiny")))
14091 uc
->data
|= DEBUG_TINY
;
14092 else if ((arg_len
= is_keyword(ptr
, len
, "timing")))
14093 uc
->data
|= DEBUG_TIMING
;
14094 else if ((arg_len
= is_keyword(ptr
, len
, "nego")))
14095 uc
->data
|= DEBUG_NEGO
;
14096 else if ((arg_len
= is_keyword(ptr
, len
, "tags")))
14097 uc
->data
|= DEBUG_TAGS
;
14100 ptr
+= arg_len
; len
-= arg_len
;
14102 #ifdef DEBUG_PROC_INFO
14103 printk("ncr_user_command: data=%ld\n", uc
->data
);
14109 if ((arg_len
= is_keyword(ptr
, len
, "trace")))
14110 uc
->data
|= UF_TRACE
;
14111 else if ((arg_len
= is_keyword(ptr
, len
, "no_disc")))
14112 uc
->data
|= UF_NODISC
;
14115 ptr
+= arg_len
; len
-= arg_len
;
14125 unsigned long flags
;
14127 NCR_LOCK_NCB(np
, flags
);
14129 NCR_UNLOCK_NCB(np
, flags
);
14134 #endif /* SCSI_NCR_USER_COMMAND_SUPPORT */
14136 #ifdef SCSI_NCR_USER_INFO_SUPPORT
14146 static void copy_mem_info(struct info_str
*info
, char *data
, int len
)
14148 if (info
->pos
+ len
> info
->length
)
14149 len
= info
->length
- info
->pos
;
14151 if (info
->pos
+ len
< info
->offset
) {
14155 if (info
->pos
< info
->offset
) {
14156 data
+= (info
->offset
- info
->pos
);
14157 len
-= (info
->offset
- info
->pos
);
14161 memcpy(info
->buffer
+ info
->pos
, data
, len
);
14166 static int copy_info(struct info_str
*info
, char *fmt
, ...)
14172 va_start(args
, fmt
);
14173 len
= vsprintf(buf
, fmt
, args
);
14176 copy_mem_info(info
, buf
, len
);
14181 ** Copy formatted information into the input buffer.
14184 static int ncr_host_info(ncb_p np
, char *ptr
, off_t offset
, int len
)
14186 struct info_str info
;
14190 info
.offset
= offset
;
14193 copy_info(&info
, "General information:\n");
14194 copy_info(&info
, " Chip " NAME53C
"%s, device id 0x%x, "
14195 "revision id 0x%x\n",
14196 np
->chip_name
, np
->device_id
, np
->revision_id
);
14197 copy_info(&info
, " On PCI bus %d, device %d, function %d, "
14203 np
->bus
, (np
->device_fn
& 0xf8) >> 3, np
->device_fn
& 7,
14205 __irq_itoa(np
->irq
));
14209 copy_info(&info
, " Synchronous period factor %d, "
14210 "max commands per lun %d\n",
14211 (int) np
->minsync
, MAX_TAGS
);
14213 if (driver_setup
.debug
|| driver_setup
.verbose
> 1) {
14214 copy_info(&info
, " Debug flags 0x%x, verbosity level %d\n",
14215 driver_setup
.debug
, driver_setup
.verbose
);
14218 return info
.pos
> info
.offset
? info
.pos
- info
.offset
: 0;
14221 #endif /* SCSI_NCR_USER_INFO_SUPPORT */
14224 ** Entry point of the scsi proc fs of the driver.
14225 ** - func = 0 means read (returns adapter infos)
14226 ** - func = 1 means write (parse user control command)
14229 static int sym53c8xx_proc_info(char *buffer
, char **start
, off_t offset
,
14230 int length
, int hostno
, int func
)
14232 struct Scsi_Host
*host
;
14233 struct host_data
*host_data
;
14237 #ifdef DEBUG_PROC_INFO
14238 printk("sym53c8xx_proc_info: hostno=%d, func=%d\n", hostno
, func
);
14241 host
= scsi_host_hn_get(hostno
);
14245 host_data
= (struct host_data
*) host
->hostdata
;
14246 ncb
= host_data
->ncb
;
14252 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
14253 retv
= ncr_user_command(ncb
, buffer
, length
);
14258 #ifdef SCSI_NCR_USER_INFO_SUPPORT
14259 retv
= ncr_host_info(ncb
, buffer
, offset
, length
);
14264 scsi_host_put(host
);
14269 /*=========================================================================
14270 ** End of proc file system stuff
14271 **=========================================================================
14276 #ifdef SCSI_NCR_NVRAM_SUPPORT
14279 * 24C16 EEPROM reading.
14281 * GPOI0 - data in/data out
14283 * Symbios NVRAM wiring now also used by Tekram.
14292 * Set/clear data/clock bit in GPIO0
14295 S24C16_set_bit(ncr_slot
*np
, u_char write_bit
, u_char
*gpreg
, int bit_mode
)
14300 *gpreg
|= write_bit
;
14313 OUTB (nc_gpreg
, *gpreg
);
14318 * Send START condition to NVRAM to wake it up.
14320 static void __init
S24C16_start(ncr_slot
*np
, u_char
*gpreg
)
14322 S24C16_set_bit(np
, 1, gpreg
, SET_BIT
);
14323 S24C16_set_bit(np
, 0, gpreg
, SET_CLK
);
14324 S24C16_set_bit(np
, 0, gpreg
, CLR_BIT
);
14325 S24C16_set_bit(np
, 0, gpreg
, CLR_CLK
);
14329 * Send STOP condition to NVRAM - puts NVRAM to sleep... ZZzzzz!!
14331 static void __init
S24C16_stop(ncr_slot
*np
, u_char
*gpreg
)
14333 S24C16_set_bit(np
, 0, gpreg
, SET_CLK
);
14334 S24C16_set_bit(np
, 1, gpreg
, SET_BIT
);
14338 * Read or write a bit to the NVRAM,
14339 * read if GPIO0 input else write if GPIO0 output
14342 S24C16_do_bit(ncr_slot
*np
, u_char
*read_bit
, u_char write_bit
, u_char
*gpreg
)
14344 S24C16_set_bit(np
, write_bit
, gpreg
, SET_BIT
);
14345 S24C16_set_bit(np
, 0, gpreg
, SET_CLK
);
14347 *read_bit
= INB (nc_gpreg
);
14348 S24C16_set_bit(np
, 0, gpreg
, CLR_CLK
);
14349 S24C16_set_bit(np
, 0, gpreg
, CLR_BIT
);
14353 * Output an ACK to the NVRAM after reading,
14354 * change GPIO0 to output and when done back to an input
14357 S24C16_write_ack(ncr_slot
*np
, u_char write_bit
, u_char
*gpreg
, u_char
*gpcntl
)
14359 OUTB (nc_gpcntl
, *gpcntl
& 0xfe);
14360 S24C16_do_bit(np
, 0, write_bit
, gpreg
);
14361 OUTB (nc_gpcntl
, *gpcntl
);
14365 * Input an ACK from NVRAM after writing,
14366 * change GPIO0 to input and when done back to an output
14369 S24C16_read_ack(ncr_slot
*np
, u_char
*read_bit
, u_char
*gpreg
, u_char
*gpcntl
)
14371 OUTB (nc_gpcntl
, *gpcntl
| 0x01);
14372 S24C16_do_bit(np
, read_bit
, 1, gpreg
);
14373 OUTB (nc_gpcntl
, *gpcntl
);
14377 * WRITE a byte to the NVRAM and then get an ACK to see it was accepted OK,
14378 * GPIO0 must already be set as an output
14381 S24C16_write_byte(ncr_slot
*np
, u_char
*ack_data
, u_char write_data
,
14382 u_char
*gpreg
, u_char
*gpcntl
)
14386 for (x
= 0; x
< 8; x
++)
14387 S24C16_do_bit(np
, 0, (write_data
>> (7 - x
)) & 0x01, gpreg
);
14389 S24C16_read_ack(np
, ack_data
, gpreg
, gpcntl
);
14393 * READ a byte from the NVRAM and then send an ACK to say we have got it,
14394 * GPIO0 must already be set as an input
14397 S24C16_read_byte(ncr_slot
*np
, u_char
*read_data
, u_char ack_data
,
14398 u_char
*gpreg
, u_char
*gpcntl
)
14404 for (x
= 0; x
< 8; x
++) {
14405 S24C16_do_bit(np
, &read_bit
, 1, gpreg
);
14406 *read_data
|= ((read_bit
& 0x01) << (7 - x
));
14409 S24C16_write_ack(np
, ack_data
, gpreg
, gpcntl
);
14413 * Read 'len' bytes starting at 'offset'.
14416 sym_read_S24C16_nvram (ncr_slot
*np
, int offset
, u_char
*data
, int len
)
14418 u_char gpcntl
, gpreg
;
14419 u_char old_gpcntl
, old_gpreg
;
14424 /* save current state of GPCNTL and GPREG */
14425 old_gpreg
= INB (nc_gpreg
);
14426 old_gpcntl
= INB (nc_gpcntl
);
14427 gpcntl
= old_gpcntl
& 0x1c;
14429 /* set up GPREG & GPCNTL to set GPIO0 and GPIO1 in to known state */
14430 OUTB (nc_gpreg
, old_gpreg
);
14431 OUTB (nc_gpcntl
, gpcntl
);
14433 /* this is to set NVRAM into a known state with GPIO0/1 both low */
14435 S24C16_set_bit(np
, 0, &gpreg
, CLR_CLK
);
14436 S24C16_set_bit(np
, 0, &gpreg
, CLR_BIT
);
14438 /* now set NVRAM inactive with GPIO0/1 both high */
14439 S24C16_stop(np
, &gpreg
);
14441 /* activate NVRAM */
14442 S24C16_start(np
, &gpreg
);
14444 /* write device code and random address MSB */
14445 S24C16_write_byte(np
, &ack_data
,
14446 0xa0 | ((offset
>> 7) & 0x0e), &gpreg
, &gpcntl
);
14447 if (ack_data
& 0x01)
14450 /* write random address LSB */
14451 S24C16_write_byte(np
, &ack_data
,
14452 offset
& 0xff, &gpreg
, &gpcntl
);
14453 if (ack_data
& 0x01)
14456 /* regenerate START state to set up for reading */
14457 S24C16_start(np
, &gpreg
);
14459 /* rewrite device code and address MSB with read bit set (lsb = 0x01) */
14460 S24C16_write_byte(np
, &ack_data
,
14461 0xa1 | ((offset
>> 7) & 0x0e), &gpreg
, &gpcntl
);
14462 if (ack_data
& 0x01)
14465 /* now set up GPIO0 for inputting data */
14467 OUTB (nc_gpcntl
, gpcntl
);
14469 /* input all requested data - only part of total NVRAM */
14470 for (x
= 0; x
< len
; x
++)
14471 S24C16_read_byte(np
, &data
[x
], (x
== (len
-1)), &gpreg
, &gpcntl
);
14473 /* finally put NVRAM back in inactive mode */
14475 OUTB (nc_gpcntl
, gpcntl
);
14476 S24C16_stop(np
, &gpreg
);
14479 /* return GPIO0/1 to original states after having accessed NVRAM */
14480 OUTB (nc_gpcntl
, old_gpcntl
);
14481 OUTB (nc_gpreg
, old_gpreg
);
14492 * Try reading Symbios NVRAM.
14495 static int __init
sym_read_Symbios_nvram (ncr_slot
*np
, Symbios_nvram
*nvram
)
14497 static u_char Symbios_trailer
[6] = {0xfe, 0xfe, 0, 0, 0, 0};
14498 u_char
*data
= (u_char
*) nvram
;
14499 int len
= sizeof(*nvram
);
14503 /* probe the 24c16 and read the SYMBIOS 24c16 area */
14504 if (sym_read_S24C16_nvram (np
, SYMBIOS_NVRAM_ADDRESS
, data
, len
))
14507 /* check valid NVRAM signature, verify byte count and checksum */
14508 if (nvram
->type
!= 0 ||
14509 memcmp(nvram
->trailer
, Symbios_trailer
, 6) ||
14510 nvram
->byte_count
!= len
- 12)
14513 /* verify checksum */
14514 for (x
= 6, csum
= 0; x
< len
- 6; x
++)
14516 if (csum
!= nvram
->checksum
)
14523 * 93C46 EEPROM reading.
14528 * GPIO4 - chip select
14534 * Pulse clock bit in GPIO0
14536 static void __init
T93C46_Clk(ncr_slot
*np
, u_char
*gpreg
)
14538 OUTB (nc_gpreg
, *gpreg
| 0x04);
14540 OUTB (nc_gpreg
, *gpreg
);
14544 * Read bit from NVRAM
14546 static void __init
T93C46_Read_Bit(ncr_slot
*np
, u_char
*read_bit
, u_char
*gpreg
)
14549 T93C46_Clk(np
, gpreg
);
14550 *read_bit
= INB (nc_gpreg
);
14554 * Write bit to GPIO0
14556 static void __init
T93C46_Write_Bit(ncr_slot
*np
, u_char write_bit
, u_char
*gpreg
)
14558 if (write_bit
& 0x01)
14565 OUTB (nc_gpreg
, *gpreg
);
14568 T93C46_Clk(np
, gpreg
);
14572 * Send STOP condition to NVRAM - puts NVRAM to sleep... ZZZzzz!!
14574 static void __init
T93C46_Stop(ncr_slot
*np
, u_char
*gpreg
)
14577 OUTB (nc_gpreg
, *gpreg
);
14580 T93C46_Clk(np
, gpreg
);
14584 * Send read command and address to NVRAM
14587 T93C46_Send_Command(ncr_slot
*np
, u_short write_data
,
14588 u_char
*read_bit
, u_char
*gpreg
)
14592 /* send 9 bits, start bit (1), command (2), address (6) */
14593 for (x
= 0; x
< 9; x
++)
14594 T93C46_Write_Bit(np
, (u_char
) (write_data
>> (8 - x
)), gpreg
);
14596 *read_bit
= INB (nc_gpreg
);
14600 * READ 2 bytes from the NVRAM
14603 T93C46_Read_Word(ncr_slot
*np
, u_short
*nvram_data
, u_char
*gpreg
)
14609 for (x
= 0; x
< 16; x
++) {
14610 T93C46_Read_Bit(np
, &read_bit
, gpreg
);
14612 if (read_bit
& 0x01)
14613 *nvram_data
|= (0x01 << (15 - x
));
14615 *nvram_data
&= ~(0x01 << (15 - x
));
14620 * Read Tekram NvRAM data.
14623 T93C46_Read_Data(ncr_slot
*np
, u_short
*data
,int len
,u_char
*gpreg
)
14628 for (x
= 0; x
< len
; x
++) {
14630 /* output read command and address */
14631 T93C46_Send_Command(np
, 0x180 | x
, &read_bit
, gpreg
);
14632 if (read_bit
& 0x01)
14633 return 1; /* Bad */
14634 T93C46_Read_Word(np
, &data
[x
], gpreg
);
14635 T93C46_Stop(np
, gpreg
);
14642 * Try reading 93C46 Tekram NVRAM.
14645 sym_read_T93C46_nvram (ncr_slot
*np
, Tekram_nvram
*nvram
)
14647 u_char gpcntl
, gpreg
;
14648 u_char old_gpcntl
, old_gpreg
;
14651 /* save current state of GPCNTL and GPREG */
14652 old_gpreg
= INB (nc_gpreg
);
14653 old_gpcntl
= INB (nc_gpcntl
);
14655 /* set up GPREG & GPCNTL to set GPIO0/1/2/4 in to known state, 0 in,
14657 gpreg
= old_gpreg
& 0xe9;
14658 OUTB (nc_gpreg
, gpreg
);
14659 gpcntl
= (old_gpcntl
& 0xe9) | 0x09;
14660 OUTB (nc_gpcntl
, gpcntl
);
14662 /* input all of NVRAM, 64 words */
14663 retv
= T93C46_Read_Data(np
, (u_short
*) nvram
,
14664 sizeof(*nvram
) / sizeof(short), &gpreg
);
14666 /* return GPIO0/1/2/4 to original states after having accessed NVRAM */
14667 OUTB (nc_gpcntl
, old_gpcntl
);
14668 OUTB (nc_gpreg
, old_gpreg
);
14674 * Try reading Tekram NVRAM.
14678 sym_read_Tekram_nvram (ncr_slot
*np
, u_short device_id
, Tekram_nvram
*nvram
)
14680 u_char
*data
= (u_char
*) nvram
;
14681 int len
= sizeof(*nvram
);
14685 switch (device_id
) {
14686 case PCI_DEVICE_ID_NCR_53C885
:
14687 case PCI_DEVICE_ID_NCR_53C895
:
14688 case PCI_DEVICE_ID_NCR_53C896
:
14689 x
= sym_read_S24C16_nvram(np
, TEKRAM_24C16_NVRAM_ADDRESS
,
14692 case PCI_DEVICE_ID_NCR_53C875
:
14693 x
= sym_read_S24C16_nvram(np
, TEKRAM_24C16_NVRAM_ADDRESS
,
14698 x
= sym_read_T93C46_nvram(np
, nvram
);
14704 /* verify checksum */
14705 for (x
= 0, csum
= 0; x
< len
- 1; x
+= 2)
14706 csum
+= data
[x
] + (data
[x
+1] << 8);
14707 if (csum
!= 0x1234)
14713 #endif /* SCSI_NCR_NVRAM_SUPPORT */
14719 MODULE_LICENSE("GPL");
14721 static Scsi_Host_Template driver_template
= {
14722 .name
= "sym53c8xx",
14723 .detect
= sym53c8xx_detect
,
14724 .release
= sym53c8xx_release
,
14725 .info
= sym53c8xx_info
,
14726 .queuecommand
= sym53c8xx_queue_command
,
14727 .slave_configure
= sym53c8xx_slave_configure
,
14728 .abort
= sym53c8xx_abort
,
14729 .reset
= sym53c8xx_reset
,
14730 .can_queue
= SCSI_NCR_CAN_QUEUE
,
14732 .sg_tablesize
= SCSI_NCR_SG_TABLESIZE
,
14733 .cmd_per_lun
= SCSI_NCR_CMD_PER_LUN
,
14734 .max_sectors
= MAX_HW_SEGMENTS
*8,
14735 .use_clustering
= DISABLE_CLUSTERING
,
14738 #include "scsi_module.c"