1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81#define SCSI_NCR_DRIVER_NAME "ncr53c8xx-3.4.3g"
82
83#define SCSI_NCR_DEBUG_FLAGS (0)
84
85#include <linux/blkdev.h>
86#include <linux/delay.h>
87#include <linux/dma-mapping.h>
88#include <linux/errno.h>
89#include <linux/gfp.h>
90#include <linux/init.h>
91#include <linux/interrupt.h>
92#include <linux/ioport.h>
93#include <linux/mm.h>
94#include <linux/module.h>
95#include <linux/sched.h>
96#include <linux/signal.h>
97#include <linux/spinlock.h>
98#include <linux/stat.h>
99#include <linux/string.h>
100#include <linux/time.h>
101#include <linux/timer.h>
102#include <linux/types.h>
103
104#include <asm/dma.h>
105#include <asm/io.h>
106
107#include <scsi/scsi.h>
108#include <scsi/scsi_cmnd.h>
109#include <scsi/scsi_dbg.h>
110#include <scsi/scsi_device.h>
111#include <scsi/scsi_tcq.h>
112#include <scsi/scsi_transport.h>
113#include <scsi/scsi_transport_spi.h>
114
115#include "ncr53c8xx.h"
116
117#define NAME53C8XX "ncr53c8xx"
118
119
120
121
122
123
124
125
126#define DEBUG_ALLOC (0x0001)
127#define DEBUG_PHASE (0x0002)
128#define DEBUG_QUEUE (0x0008)
129#define DEBUG_RESULT (0x0010)
130#define DEBUG_POINTER (0x0020)
131#define DEBUG_SCRIPT (0x0040)
132#define DEBUG_TINY (0x0080)
133#define DEBUG_TIMING (0x0100)
134#define DEBUG_NEGO (0x0200)
135#define DEBUG_TAGS (0x0400)
136#define DEBUG_SCATTER (0x0800)
137#define DEBUG_IC (0x1000)
138
139
140
141
142
143
144#ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
145static int ncr_debug = SCSI_NCR_DEBUG_FLAGS;
146 #define DEBUG_FLAGS ncr_debug
147#else
148 #define DEBUG_FLAGS SCSI_NCR_DEBUG_FLAGS
149#endif
150
151
152
153
154#define SAM_STAT_ILLEGAL 0xff
155
156static inline struct list_head *ncr_list_pop(struct list_head *head)
157{
158 if (!list_empty(head)) {
159 struct list_head *elem = head->next;
160
161 list_del(elem);
162 return elem;
163 }
164
165 return NULL;
166}
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186#define MEMO_SHIFT 4
187#if PAGE_SIZE >= 8192
188#define MEMO_PAGE_ORDER 0
189#else
190#define MEMO_PAGE_ORDER 1
191#endif
192#define MEMO_FREE_UNUSED
193#define MEMO_WARN 1
194#define MEMO_GFP_FLAGS GFP_ATOMIC
195#define MEMO_CLUSTER_SHIFT (PAGE_SHIFT+MEMO_PAGE_ORDER)
196#define MEMO_CLUSTER_SIZE (1UL << MEMO_CLUSTER_SHIFT)
197#define MEMO_CLUSTER_MASK (MEMO_CLUSTER_SIZE-1)
198
199typedef u_long m_addr_t;
200typedef struct device *m_bush_t;
201
202typedef struct m_link {
203 struct m_link *next;
204} m_link_s;
205
206typedef struct m_vtob {
207 struct m_vtob *next;
208 m_addr_t vaddr;
209 m_addr_t baddr;
210} m_vtob_s;
211#define VTOB_HASH_SHIFT 5
212#define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT)
213#define VTOB_HASH_MASK (VTOB_HASH_SIZE-1)
214#define VTOB_HASH_CODE(m) \
215 ((((m_addr_t) (m)) >> MEMO_CLUSTER_SHIFT) & VTOB_HASH_MASK)
216
217typedef struct m_pool {
218 m_bush_t bush;
219 m_addr_t (*getp)(struct m_pool *);
220 void (*freep)(struct m_pool *, m_addr_t);
221 int nump;
222 m_vtob_s *(vtob[VTOB_HASH_SIZE]);
223 struct m_pool *next;
224 struct m_link h[PAGE_SHIFT-MEMO_SHIFT+MEMO_PAGE_ORDER+1];
225} m_pool_s;
226
227static void *___m_alloc(m_pool_s *mp, int size)
228{
229 int i = 0;
230 int s = (1 << MEMO_SHIFT);
231 int j;
232 m_addr_t a;
233 m_link_s *h = mp->h;
234
235 if (size > (PAGE_SIZE << MEMO_PAGE_ORDER))
236 return NULL;
237
238 while (size > s) {
239 s <<= 1;
240 ++i;
241 }
242
243 j = i;
244 while (!h[j].next) {
245 if (s == (PAGE_SIZE << MEMO_PAGE_ORDER)) {
246 h[j].next = (m_link_s *)mp->getp(mp);
247 if (h[j].next)
248 h[j].next->next = NULL;
249 break;
250 }
251 ++j;
252 s <<= 1;
253 }
254 a = (m_addr_t) h[j].next;
255 if (a) {
256 h[j].next = h[j].next->next;
257 while (j > i) {
258 j -= 1;
259 s >>= 1;
260 h[j].next = (m_link_s *) (a+s);
261 h[j].next->next = NULL;
262 }
263 }
264#ifdef DEBUG
265 printk("___m_alloc(%d) = %p\n", size, (void *) a);
266#endif
267 return (void *) a;
268}
269
270static void ___m_free(m_pool_s *mp, void *ptr, int size)
271{
272 int i = 0;
273 int s = (1 << MEMO_SHIFT);
274 m_link_s *q;
275 m_addr_t a, b;
276 m_link_s *h = mp->h;
277
278#ifdef DEBUG
279 printk("___m_free(%p, %d)\n", ptr, size);
280#endif
281
282 if (size > (PAGE_SIZE << MEMO_PAGE_ORDER))
283 return;
284
285 while (size > s) {
286 s <<= 1;
287 ++i;
288 }
289
290 a = (m_addr_t) ptr;
291
292 while (1) {
293#ifdef MEMO_FREE_UNUSED
294 if (s == (PAGE_SIZE << MEMO_PAGE_ORDER)) {
295 mp->freep(mp, a);
296 break;
297 }
298#endif
299 b = a ^ s;
300 q = &h[i];
301 while (q->next && q->next != (m_link_s *) b) {
302 q = q->next;
303 }
304 if (!q->next) {
305 ((m_link_s *) a)->next = h[i].next;
306 h[i].next = (m_link_s *) a;
307 break;
308 }
309 q->next = q->next->next;
310 a = a & b;
311 s <<= 1;
312 ++i;
313 }
314}
315
316static DEFINE_SPINLOCK(ncr53c8xx_lock);
317
318static void *__m_calloc2(m_pool_s *mp, int size, char *name, int uflags)
319{
320 void *p;
321
322 p = ___m_alloc(mp, size);
323
324 if (DEBUG_FLAGS & DEBUG_ALLOC)
325 printk ("new %-10s[%4d] @%p.\n", name, size, p);
326
327 if (p)
328 memset(p, 0, size);
329 else if (uflags & MEMO_WARN)
330 printk (NAME53C8XX ": failed to allocate %s[%d]\n", name, size);
331
332 return p;
333}
334
335#define __m_calloc(mp, s, n) __m_calloc2(mp, s, n, MEMO_WARN)
336
337static void __m_free(m_pool_s *mp, void *ptr, int size, char *name)
338{
339 if (DEBUG_FLAGS & DEBUG_ALLOC)
340 printk ("freeing %-10s[%4d] @%p.\n", name, size, ptr);
341
342 ___m_free(mp, ptr, size);
343
344}
345
346
347
348
349
350
351
352static m_addr_t ___mp0_getp(m_pool_s *mp)
353{
354 m_addr_t m = __get_free_pages(MEMO_GFP_FLAGS, MEMO_PAGE_ORDER);
355 if (m)
356 ++mp->nump;
357 return m;
358}
359
360static void ___mp0_freep(m_pool_s *mp, m_addr_t m)
361{
362 free_pages(m, MEMO_PAGE_ORDER);
363 --mp->nump;
364}
365
366static m_pool_s mp0 = {NULL, ___mp0_getp, ___mp0_freep};
367
368
369
370
371
372
373
374
375
376static m_addr_t ___dma_getp(m_pool_s *mp)
377{
378 m_addr_t vp;
379 m_vtob_s *vbp;
380
381 vbp = __m_calloc(&mp0, sizeof(*vbp), "VTOB");
382 if (vbp) {
383 dma_addr_t daddr;
384 vp = (m_addr_t) dma_alloc_coherent(mp->bush,
385 PAGE_SIZE<<MEMO_PAGE_ORDER,
386 &daddr, GFP_ATOMIC);
387 if (vp) {
388 int hc = VTOB_HASH_CODE(vp);
389 vbp->vaddr = vp;
390 vbp->baddr = daddr;
391 vbp->next = mp->vtob[hc];
392 mp->vtob[hc] = vbp;
393 ++mp->nump;
394 return vp;
395 }
396 }
397 if (vbp)
398 __m_free(&mp0, vbp, sizeof(*vbp), "VTOB");
399 return 0;
400}
401
402static void ___dma_freep(m_pool_s *mp, m_addr_t m)
403{
404 m_vtob_s **vbpp, *vbp;
405 int hc = VTOB_HASH_CODE(m);
406
407 vbpp = &mp->vtob[hc];
408 while (*vbpp && (*vbpp)->vaddr != m)
409 vbpp = &(*vbpp)->next;
410 if (*vbpp) {
411 vbp = *vbpp;
412 *vbpp = (*vbpp)->next;
413 dma_free_coherent(mp->bush, PAGE_SIZE<<MEMO_PAGE_ORDER,
414 (void *)vbp->vaddr, (dma_addr_t)vbp->baddr);
415 __m_free(&mp0, vbp, sizeof(*vbp), "VTOB");
416 --mp->nump;
417 }
418}
419
420static inline m_pool_s *___get_dma_pool(m_bush_t bush)
421{
422 m_pool_s *mp;
423 for (mp = mp0.next; mp && mp->bush != bush; mp = mp->next);
424 return mp;
425}
426
427static m_pool_s *___cre_dma_pool(m_bush_t bush)
428{
429 m_pool_s *mp;
430 mp = __m_calloc(&mp0, sizeof(*mp), "MPOOL");
431 if (mp) {
432 memset(mp, 0, sizeof(*mp));
433 mp->bush = bush;
434 mp->getp = ___dma_getp;
435 mp->freep = ___dma_freep;
436 mp->next = mp0.next;
437 mp0.next = mp;
438 }
439 return mp;
440}
441
442static void ___del_dma_pool(m_pool_s *p)
443{
444 struct m_pool **pp = &mp0.next;
445
446 while (*pp && *pp != p)
447 pp = &(*pp)->next;
448 if (*pp) {
449 *pp = (*pp)->next;
450 __m_free(&mp0, p, sizeof(*p), "MPOOL");
451 }
452}
453
454static void *__m_calloc_dma(m_bush_t bush, int size, char *name)
455{
456 u_long flags;
457 struct m_pool *mp;
458 void *m = NULL;
459
460 spin_lock_irqsave(&ncr53c8xx_lock, flags);
461 mp = ___get_dma_pool(bush);
462 if (!mp)
463 mp = ___cre_dma_pool(bush);
464 if (mp)
465 m = __m_calloc(mp, size, name);
466 if (mp && !mp->nump)
467 ___del_dma_pool(mp);
468 spin_unlock_irqrestore(&ncr53c8xx_lock, flags);
469
470 return m;
471}
472
473static void __m_free_dma(m_bush_t bush, void *m, int size, char *name)
474{
475 u_long flags;
476 struct m_pool *mp;
477
478 spin_lock_irqsave(&ncr53c8xx_lock, flags);
479 mp = ___get_dma_pool(bush);
480 if (mp)
481 __m_free(mp, m, size, name);
482 if (mp && !mp->nump)
483 ___del_dma_pool(mp);
484 spin_unlock_irqrestore(&ncr53c8xx_lock, flags);
485}
486
487static m_addr_t __vtobus(m_bush_t bush, void *m)
488{
489 u_long flags;
490 m_pool_s *mp;
491 int hc = VTOB_HASH_CODE(m);
492 m_vtob_s *vp = NULL;
493 m_addr_t a = ((m_addr_t) m) & ~MEMO_CLUSTER_MASK;
494
495 spin_lock_irqsave(&ncr53c8xx_lock, flags);
496 mp = ___get_dma_pool(bush);
497 if (mp) {
498 vp = mp->vtob[hc];
499 while (vp && (m_addr_t) vp->vaddr != a)
500 vp = vp->next;
501 }
502 spin_unlock_irqrestore(&ncr53c8xx_lock, flags);
503 return vp ? vp->baddr + (((m_addr_t) m) - a) : 0;
504}
505
506#define _m_calloc_dma(np, s, n) __m_calloc_dma(np->dev, s, n)
507#define _m_free_dma(np, p, s, n) __m_free_dma(np->dev, p, s, n)
508#define m_calloc_dma(s, n) _m_calloc_dma(np, s, n)
509#define m_free_dma(p, s, n) _m_free_dma(np, p, s, n)
510#define _vtobus(np, p) __vtobus(np->dev, p)
511#define vtobus(p) _vtobus(np, p)
512
513
514
515
516
517
518#define __data_mapped SCp.phase
519#define __data_mapping SCp.have_data_in
520
521static void __unmap_scsi_data(struct device *dev, struct scsi_cmnd *cmd)
522{
523 switch(cmd->__data_mapped) {
524 case 2:
525 scsi_dma_unmap(cmd);
526 break;
527 }
528 cmd->__data_mapped = 0;
529}
530
531static int __map_scsi_sg_data(struct device *dev, struct scsi_cmnd *cmd)
532{
533 int use_sg;
534
535 use_sg = scsi_dma_map(cmd);
536 if (!use_sg)
537 return 0;
538
539 cmd->__data_mapped = 2;
540 cmd->__data_mapping = use_sg;
541
542 return use_sg;
543}
544
545#define unmap_scsi_data(np, cmd) __unmap_scsi_data(np->dev, cmd)
546#define map_scsi_sg_data(np, cmd) __map_scsi_sg_data(np->dev, cmd)
547
548
549
550
551
552
553
554
555
556
557
558static struct ncr_driver_setup
559 driver_setup = SCSI_NCR_DRIVER_SETUP;
560
561#ifndef MODULE
562#ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
563static struct ncr_driver_setup
564 driver_safe_setup __initdata = SCSI_NCR_DRIVER_SAFE_SETUP;
565#endif
566#endif
567
568#define initverbose (driver_setup.verbose)
569#define bootverbose (np->verbose)
570
571
572
573
574
575
576
577
578
579#ifdef MODULE
580#define ARG_SEP ' '
581#else
582#define ARG_SEP ','
583#endif
584
585#define OPT_TAGS 1
586#define OPT_MASTER_PARITY 2
587#define OPT_SCSI_PARITY 3
588#define OPT_DISCONNECTION 4
589#define OPT_SPECIAL_FEATURES 5
590#define OPT_UNUSED_1 6
591#define OPT_FORCE_SYNC_NEGO 7
592#define OPT_REVERSE_PROBE 8
593#define OPT_DEFAULT_SYNC 9
594#define OPT_VERBOSE 10
595#define OPT_DEBUG 11
596#define OPT_BURST_MAX 12
597#define OPT_LED_PIN 13
598#define OPT_MAX_WIDE 14
599#define OPT_SETTLE_DELAY 15
600#define OPT_DIFF_SUPPORT 16
601#define OPT_IRQM 17
602#define OPT_PCI_FIX_UP 18
603#define OPT_BUS_CHECK 19
604#define OPT_OPTIMIZE 20
605#define OPT_RECOVERY 21
606#define OPT_SAFE_SETUP 22
607#define OPT_USE_NVRAM 23
608#define OPT_EXCLUDE 24
609#define OPT_HOST_ID 25
610
611#ifdef SCSI_NCR_IARB_SUPPORT
612#define OPT_IARB 26
613#endif
614
615#ifdef MODULE
616#define ARG_SEP ' '
617#else
618#define ARG_SEP ','
619#endif
620
621#ifndef MODULE
622static char setup_token[] __initdata =
623 "tags:" "mpar:"
624 "spar:" "disc:"
625 "specf:" "ultra:"
626 "fsn:" "revprob:"
627 "sync:" "verb:"
628 "debug:" "burst:"
629 "led:" "wide:"
630 "settle:" "diff:"
631 "irqm:" "pcifix:"
632 "buschk:" "optim:"
633 "recovery:"
634 "safe:" "nvram:"
635 "excl:" "hostid:"
636#ifdef SCSI_NCR_IARB_SUPPORT
637 "iarb:"
638#endif
639 ;
640
641static int __init get_setup_token(char *p)
642{
643 char *cur = setup_token;
644 char *pc;
645 int i = 0;
646
647 while (cur != NULL && (pc = strchr(cur, ':')) != NULL) {
648 ++pc;
649 ++i;
650 if (!strncmp(p, cur, pc - cur))
651 return i;
652 cur = pc;
653 }
654 return 0;
655}
656
657static int __init sym53c8xx__setup(char *str)
658{
659#ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
660 char *cur = str;
661 char *pc, *pv;
662 int i, val, c;
663 int xi = 0;
664
665 while (cur != NULL && (pc = strchr(cur, ':')) != NULL) {
666 char *pe;
667
668 val = 0;
669 pv = pc;
670 c = *++pv;
671
672 if (c == 'n')
673 val = 0;
674 else if (c == 'y')
675 val = 1;
676 else
677 val = (int) simple_strtoul(pv, &pe, 0);
678
679 switch (get_setup_token(cur)) {
680 case OPT_TAGS:
681 driver_setup.default_tags = val;
682 if (pe && *pe == '/') {
683 i = 0;
684 while (*pe && *pe != ARG_SEP &&
685 i < sizeof(driver_setup.tag_ctrl)-1) {
686 driver_setup.tag_ctrl[i++] = *pe++;
687 }
688 driver_setup.tag_ctrl[i] = '\0';
689 }
690 break;
691 case OPT_MASTER_PARITY:
692 driver_setup.master_parity = val;
693 break;
694 case OPT_SCSI_PARITY:
695 driver_setup.scsi_parity = val;
696 break;
697 case OPT_DISCONNECTION:
698 driver_setup.disconnection = val;
699 break;
700 case OPT_SPECIAL_FEATURES:
701 driver_setup.special_features = val;
702 break;
703 case OPT_FORCE_SYNC_NEGO:
704 driver_setup.force_sync_nego = val;
705 break;
706 case OPT_REVERSE_PROBE:
707 driver_setup.reverse_probe = val;
708 break;
709 case OPT_DEFAULT_SYNC:
710 driver_setup.default_sync = val;
711 break;
712 case OPT_VERBOSE:
713 driver_setup.verbose = val;
714 break;
715 case OPT_DEBUG:
716 driver_setup.debug = val;
717 break;
718 case OPT_BURST_MAX:
719 driver_setup.burst_max = val;
720 break;
721 case OPT_LED_PIN:
722 driver_setup.led_pin = val;
723 break;
724 case OPT_MAX_WIDE:
725 driver_setup.max_wide = val? 1:0;
726 break;
727 case OPT_SETTLE_DELAY:
728 driver_setup.settle_delay = val;
729 break;
730 case OPT_DIFF_SUPPORT:
731 driver_setup.diff_support = val;
732 break;
733 case OPT_IRQM:
734 driver_setup.irqm = val;
735 break;
736 case OPT_PCI_FIX_UP:
737 driver_setup.pci_fix_up = val;
738 break;
739 case OPT_BUS_CHECK:
740 driver_setup.bus_check = val;
741 break;
742 case OPT_OPTIMIZE:
743 driver_setup.optimize = val;
744 break;
745 case OPT_RECOVERY:
746 driver_setup.recovery = val;
747 break;
748 case OPT_USE_NVRAM:
749 driver_setup.use_nvram = val;
750 break;
751 case OPT_SAFE_SETUP:
752 memcpy(&driver_setup, &driver_safe_setup,
753 sizeof(driver_setup));
754 break;
755 case OPT_EXCLUDE:
756 if (xi < SCSI_NCR_MAX_EXCLUDES)
757 driver_setup.excludes[xi++] = val;
758 break;
759 case OPT_HOST_ID:
760 driver_setup.host_id = val;
761 break;
762#ifdef SCSI_NCR_IARB_SUPPORT
763 case OPT_IARB:
764 driver_setup.iarb = val;
765 break;
766#endif
767 default:
768 printk("sym53c8xx_setup: unexpected boot option '%.*s' ignored\n", (int)(pc-cur+1), cur);
769 break;
770 }
771
772 if ((cur = strchr(cur, ARG_SEP)) != NULL)
773 ++cur;
774 }
775#endif
776 return 1;
777}
778#endif
779
780
781
782
783
784
785
786#define DEF_DEPTH (driver_setup.default_tags)
787#define ALL_TARGETS -2
788#define NO_TARGET -1
789#define ALL_LUNS -2
790#define NO_LUN -1
791
792static int device_queue_depth(int unit, int target, int lun)
793{
794 int c, h, t, u, v;
795 char *p = driver_setup.tag_ctrl;
796 char *ep;
797
798 h = -1;
799 t = NO_TARGET;
800 u = NO_LUN;
801 while ((c = *p++) != 0) {
802 v = simple_strtoul(p, &ep, 0);
803 switch(c) {
804 case '/':
805 ++h;
806 t = ALL_TARGETS;
807 u = ALL_LUNS;
808 break;
809 case 't':
810 if (t != target)
811 t = (target == v) ? v : NO_TARGET;
812 u = ALL_LUNS;
813 break;
814 case 'u':
815 if (u != lun)
816 u = (lun == v) ? v : NO_LUN;
817 break;
818 case 'q':
819 if (h == unit &&
820 (t == ALL_TARGETS || t == target) &&
821 (u == ALL_LUNS || u == lun))
822 return v;
823 break;
824 case '-':
825 t = ALL_TARGETS;
826 u = ALL_LUNS;
827 break;
828 default:
829 break;
830 }
831 p = ep;
832 }
833 return DEF_DEPTH;
834}
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854#define SCSI_NCR_CCB_DONE_SUPPORT
855#ifdef SCSI_NCR_CCB_DONE_SUPPORT
856
857#define MAX_DONE 24
858#define CCB_DONE_EMPTY 0xffffffffUL
859
860
861#if BITS_PER_LONG == 32
862#define CCB_DONE_VALID(cp) (((u_long) cp) != CCB_DONE_EMPTY)
863
864
865#else
866#define CCB_DONE_VALID(cp) \
867 ((((u_long) cp) & 0xffffffff00000000ul) && \
868 (((u_long) cp) & 0xfffffffful) != CCB_DONE_EMPTY)
869#endif
870
871#endif
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886#ifndef SCSI_NCR_MYADDR
887#define SCSI_NCR_MYADDR (7)
888#endif
889
890
891
892
893
894
895#ifndef SCSI_NCR_MAX_TAGS
896#define SCSI_NCR_MAX_TAGS (8)
897#endif
898
899
900
901
902
903#if SCSI_NCR_MAX_TAGS > 64
904#define MAX_TAGS (64)
905#else
906#define MAX_TAGS SCSI_NCR_MAX_TAGS
907#endif
908
909#define NO_TAG (255)
910
911
912
913
914#if MAX_TAGS > 32
915typedef u64 tagmap_t;
916#else
917typedef u32 tagmap_t;
918#endif
919
920
921
922
923
924
925
926
927#ifdef SCSI_NCR_MAX_TARGET
928#define MAX_TARGET (SCSI_NCR_MAX_TARGET)
929#else
930#define MAX_TARGET (16)
931#endif
932
933
934
935
936
937
938
939
940#ifdef SCSI_NCR_MAX_LUN
941#define MAX_LUN SCSI_NCR_MAX_LUN
942#else
943#define MAX_LUN (1)
944#endif
945
946
947
948
949
950#ifndef SCSI_NCR_MIN_ASYNC
951#define SCSI_NCR_MIN_ASYNC (40)
952#endif
953
954
955
956
957
958
959
960
961#ifdef SCSI_NCR_CAN_QUEUE
962#define MAX_START (SCSI_NCR_CAN_QUEUE + 4)
963#else
964#define MAX_START (MAX_TARGET + 7 * MAX_TAGS)
965#endif
966
967
968
969
970
971
972#if MAX_START > 250
973#undef MAX_START
974#define MAX_START 250
975#endif
976
977
978
979
980
981
982
983
984
985
986#define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)
987
988#if (MAX_SCATTER > 80)
989#define MAX_SCATTERL 80
990#define MAX_SCATTERH (MAX_SCATTER - MAX_SCATTERL)
991#else
992#define MAX_SCATTERL (MAX_SCATTER-1)
993#define MAX_SCATTERH 1
994#endif
995
996
997
998
999
1000#define NCR_SNOOP_TIMEOUT (1000000)
1001
1002
1003
1004
1005
1006#define initverbose (driver_setup.verbose)
1007#define bootverbose (np->verbose)
1008
1009
1010
1011
1012
1013
1014
1015
1016#define HS_IDLE (0)
1017#define HS_BUSY (1)
1018#define HS_NEGOTIATE (2)
1019#define HS_DISCONNECT (3)
1020
1021#define HS_DONEMASK (0x80)
1022#define HS_COMPLETE (4|HS_DONEMASK)
1023#define HS_SEL_TIMEOUT (5|HS_DONEMASK)
1024#define HS_RESET (6|HS_DONEMASK)
1025#define HS_ABORTED (7|HS_DONEMASK)
1026#define HS_TIMEOUT (8|HS_DONEMASK)
1027#define HS_FAIL (9|HS_DONEMASK)
1028#define HS_UNEXPECTED (10|HS_DONEMASK)
1029
1030
1031
1032
1033
1034
1035
1036#define HS_INVALMASK (0x40)
1037#define HS_SELECTING (0|HS_INVALMASK)
1038#define HS_IN_RESELECT (1|HS_INVALMASK)
1039#define HS_STARTING (2|HS_INVALMASK)
1040
1041
1042
1043
1044
1045#define HS_SKIPMASK (0x20)
1046
1047
1048
1049
1050
1051
1052
1053
1054#define SIR_BAD_STATUS (1)
1055#define SIR_XXXXXXXXXX (2)
1056#define SIR_NEGO_SYNC (3)
1057#define SIR_NEGO_WIDE (4)
1058#define SIR_NEGO_FAILED (5)
1059#define SIR_NEGO_PROTO (6)
1060#define SIR_REJECT_RECEIVED (7)
1061#define SIR_REJECT_SENT (8)
1062#define SIR_IGN_RESIDUE (9)
1063#define SIR_MISSING_SAVE (10)
1064#define SIR_RESEL_NO_MSG_IN (11)
1065#define SIR_RESEL_NO_IDENTIFY (12)
1066#define SIR_RESEL_BAD_LUN (13)
1067#define SIR_RESEL_BAD_TARGET (14)
1068#define SIR_RESEL_BAD_I_T_L (15)
1069#define SIR_RESEL_BAD_I_T_L_Q (16)
1070#define SIR_DONE_OVERFLOW (17)
1071#define SIR_INTFLY (18)
1072#define SIR_MAX (18)
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082#define XE_OK (0)
1083#define XE_EXTRA_DATA (1)
1084#define XE_BAD_PHASE (2)
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094#define NS_NOCHANGE (0)
1095#define NS_SYNC (1)
1096#define NS_WIDE (2)
1097#define NS_PPR (4)
1098
1099
1100
1101
1102
1103
1104
1105
1106#define CCB_MAGIC (0xf2691ad2)
1107
1108
1109
1110
1111
1112
1113
1114
1115static struct scsi_transport_template *ncr53c8xx_transport_template = NULL;
1116
1117struct tcb;
1118struct lcb;
1119struct ccb;
1120struct ncb;
1121struct script;
1122
1123struct link {
1124 ncrcmd l_cmd;
1125 ncrcmd l_paddr;
1126};
1127
1128struct usrcmd {
1129 u_long target;
1130 u_long lun;
1131 u_long data;
1132 u_long cmd;
1133};
1134
1135#define UC_SETSYNC 10
1136#define UC_SETTAGS 11
1137#define UC_SETDEBUG 12
1138#define UC_SETORDER 13
1139#define UC_SETWIDE 14
1140#define UC_SETFLAG 15
1141#define UC_SETVERBOSE 17
1142
1143#define UF_TRACE (0x01)
1144#define UF_NODISC (0x02)
1145#define UF_NOSCAN (0x04)
1146
1147
1148
1149
1150
1151
1152
1153struct tcb {
1154
1155
1156
1157
1158
1159
1160
1161
1162 struct link jump_tcb;
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172 ncrcmd getscr[6];
1173
1174
1175
1176
1177
1178
1179
1180 struct link call_lun;
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192 struct link jump_lcb[4];
1193 struct lcb * lp[MAX_LUN];
1194
1195
1196
1197
1198
1199
1200
1201 struct ccb * nego_cp;
1202
1203
1204
1205
1206
1207 u_long transfers;
1208 u_long bytes;
1209
1210
1211
1212
1213
1214#ifdef SCSI_NCR_BIG_ENDIAN
1215 u16 period;
1216 u_char sval;
1217 u_char minsync;
1218 u_char wval;
1219 u_char widedone;
1220 u_char quirks;
1221 u_char maxoffs;
1222#else
1223 u_char minsync;
1224 u_char sval;
1225 u16 period;
1226 u_char maxoffs;
1227 u_char quirks;
1228 u_char widedone;
1229 u_char wval;
1230#endif
1231
1232
1233 u_char usrsync;
1234 u_char usrwide;
1235 u_char usrtags;
1236 u_char usrflag;
1237 struct scsi_target *starget;
1238};
1239
1240
1241
1242
1243
1244
1245
1246struct lcb {
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261 struct link jump_lcb;
1262 ncrcmd load_jump_ccb[3];
1263 struct link jump_tag;
1264 ncrcmd p_jump_ccb;
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274 u32 jump_ccb_0;
1275 u32 *jump_ccb;
1276
1277
1278
1279
1280
1281 struct list_head free_ccbq;
1282 struct list_head busy_ccbq;
1283 struct list_head wait_ccbq;
1284 struct list_head skip_ccbq;
1285 u_char actccbs;
1286 u_char busyccbs;
1287 u_char queuedccbs;
1288 u_char queuedepth;
1289 u_char scdev_depth;
1290 u_char maxnxs;
1291
1292
1293
1294
1295
1296
1297
1298 u_char ia_tag;
1299 u_char if_tag;
1300 u_char cb_tags[MAX_TAGS];
1301 u_char usetags;
1302 u_char maxtags;
1303 u_char numtags;
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313 u16 num_good;
1314 tagmap_t tags_umap;
1315 tagmap_t tags_smap;
1316 u_long tags_stime;
1317 struct ccb * held_ccb;
1318};
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332struct launch {
1333
1334
1335
1336
1337
1338 ncrcmd setup_dsa[3];
1339 struct link schedule;
1340 ncrcmd p_phys;
1341};
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357struct head {
1358
1359
1360
1361
1362
1363
1364
1365
1366 u32 savep;
1367 u32 lastp;
1368 u32 goalp;
1369
1370
1371
1372
1373
1374
1375
1376 u32 wlastp;
1377 u32 wgoalp;
1378
1379
1380
1381
1382
1383 struct ccb * cp;
1384
1385
1386
1387
1388
1389 u_char scr_st[4];
1390 u_char status[4];
1391
1392};
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420#define QU_REG scr0
1421#define HS_REG scr1
1422#define HS_PRT nc_scr1
1423#define SS_REG scr2
1424#define SS_PRT nc_scr2
1425#define PS_REG scr3
1426
1427
1428
1429
1430#ifdef SCSI_NCR_BIG_ENDIAN
1431#define actualquirks phys.header.status[3]
1432#define host_status phys.header.status[2]
1433#define scsi_status phys.header.status[1]
1434#define parity_status phys.header.status[0]
1435#else
1436#define actualquirks phys.header.status[0]
1437#define host_status phys.header.status[1]
1438#define scsi_status phys.header.status[2]
1439#define parity_status phys.header.status[3]
1440#endif
1441
1442
1443
1444
1445#define xerr_st header.scr_st[0]
1446#define sync_st header.scr_st[1]
1447#define nego_st header.scr_st[2]
1448#define wide_st header.scr_st[3]
1449
1450
1451
1452
1453#define xerr_status phys.xerr_st
1454#define nego_status phys.nego_st
1455
1456#if 0
1457#define sync_status phys.sync_st
1458#define wide_status phys.wide_st
1459#endif
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477struct dsb {
1478
1479
1480
1481
1482
1483 struct head header;
1484
1485
1486
1487
1488
1489 struct scr_tblsel select;
1490 struct scr_tblmove smsg ;
1491 struct scr_tblmove cmd ;
1492 struct scr_tblmove sense ;
1493 struct scr_tblmove data[MAX_SCATTER];
1494};
1495
1496
1497
1498
1499
1500
1501
1502
1503struct ccb {
1504
1505
1506
1507
1508
1509
1510
1511 struct dsb phys;
1512
1513
1514
1515
1516
1517
1518
1519 struct launch start;
1520
1521
1522
1523
1524
1525
1526
1527 struct launch restart;
1528
1529
1530
1531
1532
1533
1534
1535
1536 ncrcmd patch[8];
1537
1538
1539
1540
1541
1542
1543 struct scsi_cmnd *cmd;
1544 u_char cdb_buf[16];
1545 u_char sense_buf[64];
1546 int data_len;
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558 u_char scsi_smsg [8];
1559 u_char scsi_smsg2[8];
1560
1561
1562
1563
1564
1565 u_long p_ccb;
1566 u_char sensecmd[6];
1567 u_char tag;
1568
1569 u_char target;
1570 u_char lun;
1571 u_char queued;
1572 u_char auto_sense;
1573 struct ccb * link_ccb;
1574 struct list_head link_ccbq;
1575 u32 startp;
1576 u_long magic;
1577};
1578
1579#define CCB_PHYS(cp,lbl) (cp->p_ccb + offsetof(struct ccb, lbl))
1580
1581
1582
1583
1584
1585
1586
1587
1588struct ncb {
1589
1590
1591
1592
1593
1594
1595
1596 struct head header;
1597
1598
1599
1600
1601
1602 struct scsi_cmnd *waiting_list;
1603
1604 struct scsi_cmnd *done_list;
1605
1606 spinlock_t smp_lock;
1607
1608
1609
1610
1611
1612 int unit;
1613 char inst_name[16];
1614
1615
1616
1617
1618
1619
1620
1621 u_char sv_scntl0, sv_scntl3, sv_dmode, sv_dcntl, sv_ctest0, sv_ctest3,
1622 sv_ctest4, sv_ctest5, sv_gpcntl, sv_stest2, sv_stest4;
1623
1624
1625
1626
1627
1628
1629
1630 u_char rv_scntl0, rv_scntl3, rv_dmode, rv_dcntl, rv_ctest0, rv_ctest3,
1631 rv_ctest4, rv_ctest5, rv_stest2;
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644 struct link jump_tcb[4];
1645 struct tcb target[MAX_TARGET];
1646
1647
1648
1649
1650
1651 void __iomem *vaddr;
1652 unsigned long paddr;
1653 unsigned long paddr2;
1654 volatile
1655 struct ncr_reg __iomem *reg;
1656
1657
1658
1659
1660
1661
1662
1663 struct script *script0;
1664 struct scripth *scripth0;
1665 struct scripth *scripth;
1666 u_long p_script;
1667 u_long p_scripth;
1668
1669
1670
1671
1672
1673 struct device *dev;
1674 u_char revision_id;
1675 u32 irq;
1676 u32 features;
1677 u_char myaddr;
1678 u_char maxburst;
1679 u_char maxwide;
1680 u_char minsync;
1681 u_char maxsync;
1682 u_char maxoffs;
1683 u_char multiplier;
1684 u_char clock_divn;
1685 u_long clock_khz;
1686
1687
1688
1689
1690
1691
1692
1693 u16 squeueput;
1694 u16 actccbs;
1695 u16 queuedccbs;
1696 u16 queuedepth;
1697
1698
1699
1700
1701
1702 struct timer_list timer;
1703 u_long lasttime;
1704 u_long settle_time;
1705
1706
1707
1708
1709
1710 struct ncr_reg regdump;
1711 u_long regtime;
1712
1713
1714
1715
1716
1717
1718
1719 u_char msgout[8];
1720 u_char msgin [8];
1721 u32 lastmsg;
1722 u_char scratch;
1723
1724
1725
1726
1727
1728 u_char disc;
1729 u_char scsi_mode;
1730 u_char order;
1731 u_char verbose;
1732 int ncr_cache;
1733 u_long p_ncb;
1734
1735
1736
1737
1738
1739#ifdef SCSI_NCR_CCB_DONE_SUPPORT
1740 struct ccb *(ccb_done[MAX_DONE]);
1741 int ccb_done_ic;
1742#endif
1743
1744
1745
1746
1747 struct ccb *ccb;
1748 struct usrcmd user;
1749 volatile u_char release_stage;
1750};
1751
1752#define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
1753#define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785#ifdef CONFIG_NCR53C8XX_PREFETCH
1786#define PREFETCH_FLUSH_CNT 2
1787#define PREFETCH_FLUSH SCR_CALL, PADDRH (wait_dma),
1788#else
1789#define PREFETCH_FLUSH_CNT 0
1790#define PREFETCH_FLUSH
1791#endif
1792
1793
1794
1795
1796
1797struct script {
1798 ncrcmd start [ 5];
1799 ncrcmd startpos [ 1];
1800 ncrcmd select [ 6];
1801 ncrcmd select2 [ 9 + PREFETCH_FLUSH_CNT];
1802 ncrcmd loadpos [ 4];
1803 ncrcmd send_ident [ 9];
1804 ncrcmd prepare [ 6];
1805 ncrcmd prepare2 [ 7];
1806 ncrcmd command [ 6];
1807 ncrcmd dispatch [ 32];
1808 ncrcmd clrack [ 4];
1809 ncrcmd no_data [ 17];
1810 ncrcmd status [ 8];
1811 ncrcmd msg_in [ 2];
1812 ncrcmd msg_in2 [ 16];
1813 ncrcmd msg_bad [ 4];
1814 ncrcmd setmsg [ 7];
1815 ncrcmd cleanup [ 6];
1816 ncrcmd complete [ 9];
1817 ncrcmd cleanup_ok [ 8 + PREFETCH_FLUSH_CNT];
1818 ncrcmd cleanup0 [ 1];
1819#ifndef SCSI_NCR_CCB_DONE_SUPPORT
1820 ncrcmd signal [ 12];
1821#else
1822 ncrcmd signal [ 9];
1823 ncrcmd done_pos [ 1];
1824 ncrcmd done_plug [ 2];
1825 ncrcmd done_end [ 7];
1826#endif
1827 ncrcmd save_dp [ 7];
1828 ncrcmd restore_dp [ 5];
1829 ncrcmd disconnect [ 10];
1830 ncrcmd msg_out [ 9];
1831 ncrcmd msg_out_done [ 7];
1832 ncrcmd idle [ 2];
1833 ncrcmd reselect [ 8];
1834 ncrcmd reselected [ 8];
1835 ncrcmd resel_dsa [ 6 + PREFETCH_FLUSH_CNT];
1836 ncrcmd loadpos1 [ 4];
1837 ncrcmd resel_lun [ 6];
1838 ncrcmd resel_tag [ 6];
1839 ncrcmd jump_to_nexus [ 4 + PREFETCH_FLUSH_CNT];
1840 ncrcmd nexus_indirect [ 4];
1841 ncrcmd resel_notag [ 4];
1842 ncrcmd data_in [MAX_SCATTERL * 4];
1843 ncrcmd data_in2 [ 4];
1844 ncrcmd data_out [MAX_SCATTERL * 4];
1845 ncrcmd data_out2 [ 4];
1846};
1847
1848
1849
1850
1851struct scripth {
1852 ncrcmd tryloop [MAX_START*2];
1853 ncrcmd tryloop2 [ 2];
1854#ifdef SCSI_NCR_CCB_DONE_SUPPORT
1855 ncrcmd done_queue [MAX_DONE*5];
1856 ncrcmd done_queue2 [ 2];
1857#endif
1858 ncrcmd select_no_atn [ 8];
1859 ncrcmd cancel [ 4];
1860 ncrcmd skip [ 9 + PREFETCH_FLUSH_CNT];
1861 ncrcmd skip2 [ 19];
1862 ncrcmd par_err_data_in [ 6];
1863 ncrcmd par_err_other [ 4];
1864 ncrcmd msg_reject [ 8];
1865 ncrcmd msg_ign_residue [ 24];
1866 ncrcmd msg_extended [ 10];
1867 ncrcmd msg_ext_2 [ 10];
1868 ncrcmd msg_wdtr [ 14];
1869 ncrcmd send_wdtr [ 7];
1870 ncrcmd msg_ext_3 [ 10];
1871 ncrcmd msg_sdtr [ 14];
1872 ncrcmd send_sdtr [ 7];
1873 ncrcmd nego_bad_phase [ 4];
1874 ncrcmd msg_out_abort [ 10];
1875 ncrcmd hdata_in [MAX_SCATTERH * 4];
1876 ncrcmd hdata_in2 [ 2];
1877 ncrcmd hdata_out [MAX_SCATTERH * 4];
1878 ncrcmd hdata_out2 [ 2];
1879 ncrcmd reset [ 4];
1880 ncrcmd aborttag [ 4];
1881 ncrcmd abort [ 2];
1882 ncrcmd abort_resel [ 20];
1883 ncrcmd resend_ident [ 4];
1884 ncrcmd clratn_go_on [ 3];
1885 ncrcmd nxtdsp_go_on [ 1];
1886 ncrcmd sdata_in [ 8];
1887 ncrcmd data_io [ 18];
1888 ncrcmd bad_identify [ 12];
1889 ncrcmd bad_i_t_l [ 4];
1890 ncrcmd bad_i_t_l_q [ 4];
1891 ncrcmd bad_target [ 8];
1892 ncrcmd bad_status [ 8];
1893 ncrcmd start_ram [ 4 + PREFETCH_FLUSH_CNT];
1894 ncrcmd start_ram0 [ 4];
1895 ncrcmd sto_restart [ 5];
1896 ncrcmd wait_dma [ 2];
1897 ncrcmd snooptest [ 9];
1898 ncrcmd snoopend [ 2];
1899};
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910static void ncr_alloc_ccb (struct ncb *np, u_char tn, u_char ln);
1911static void ncr_complete (struct ncb *np, struct ccb *cp);
1912static void ncr_exception (struct ncb *np);
1913static void ncr_free_ccb (struct ncb *np, struct ccb *cp);
1914static void ncr_init_ccb (struct ncb *np, struct ccb *cp);
1915static void ncr_init_tcb (struct ncb *np, u_char tn);
1916static struct lcb * ncr_alloc_lcb (struct ncb *np, u_char tn, u_char ln);
1917static struct lcb * ncr_setup_lcb (struct ncb *np, struct scsi_device *sdev);
1918static void ncr_getclock (struct ncb *np, int mult);
1919static void ncr_selectclock (struct ncb *np, u_char scntl3);
1920static struct ccb *ncr_get_ccb (struct ncb *np, struct scsi_cmnd *cmd);
1921static void ncr_chip_reset (struct ncb *np, int delay);
1922static void ncr_init (struct ncb *np, int reset, char * msg, u_long code);
1923static int ncr_int_sbmc (struct ncb *np);
1924static int ncr_int_par (struct ncb *np);
1925static void ncr_int_ma (struct ncb *np);
1926static void ncr_int_sir (struct ncb *np);
1927static void ncr_int_sto (struct ncb *np);
1928static void ncr_negotiate (struct ncb* np, struct tcb* tp);
1929static int ncr_prepare_nego(struct ncb *np, struct ccb *cp, u_char *msgptr);
1930
1931static void ncr_script_copy_and_bind
1932 (struct ncb *np, ncrcmd *src, ncrcmd *dst, int len);
1933static void ncr_script_fill (struct script * scr, struct scripth * scripth);
1934static int ncr_scatter (struct ncb *np, struct ccb *cp, struct scsi_cmnd *cmd);
1935static void ncr_getsync (struct ncb *np, u_char sfac, u_char *fakp, u_char *scntl3p);
1936static void ncr_setsync (struct ncb *np, struct ccb *cp, u_char scntl3, u_char sxfer);
1937static void ncr_setup_tags (struct ncb *np, struct scsi_device *sdev);
1938static void ncr_setwide (struct ncb *np, struct ccb *cp, u_char wide, u_char ack);
1939static int ncr_snooptest (struct ncb *np);
1940static void ncr_timeout (struct ncb *np);
1941static void ncr_wakeup (struct ncb *np, u_long code);
1942static void ncr_wakeup_done (struct ncb *np);
1943static void ncr_start_next_ccb (struct ncb *np, struct lcb * lp, int maxn);
1944static void ncr_put_start_queue(struct ncb *np, struct ccb *cp);
1945
1946static void insert_into_waiting_list(struct ncb *np, struct scsi_cmnd *cmd);
1947static struct scsi_cmnd *retrieve_from_waiting_list(int to_remove, struct ncb *np, struct scsi_cmnd *cmd);
1948static void process_waiting_list(struct ncb *np, int sts);
1949
1950#define remove_from_waiting_list(np, cmd) \
1951 retrieve_from_waiting_list(1, (np), (cmd))
1952#define requeue_waiting_list(np) process_waiting_list((np), DID_OK)
1953#define reset_waiting_list(np) process_waiting_list((np), DID_RESET)
1954
1955static inline char *ncr_name (struct ncb *np)
1956{
1957 return np->inst_name;
1958}
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980#define RELOC_SOFTC 0x40000000
1981#define RELOC_LABEL 0x50000000
1982#define RELOC_REGISTER 0x60000000
1983#if 0
1984#define RELOC_KVAR 0x70000000
1985#endif
1986#define RELOC_LABELH 0x80000000
1987#define RELOC_MASK 0xf0000000
1988
1989#define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
1990#define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
1991#define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
1992#define RADDR(label) (RELOC_REGISTER | REG(label))
1993#define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
1994#if 0
1995#define KVAR(which) (RELOC_KVAR | (which))
1996#endif
1997
1998#if 0
1999#define SCRIPT_KVAR_JIFFIES (0)
2000#define SCRIPT_KVAR_FIRST SCRIPT_KVAR_JIFFIES
2001#define SCRIPT_KVAR_LAST SCRIPT_KVAR_JIFFIES
2002
2003
2004
2005
2006static void *script_kvars[] __initdata =
2007 { (void *)&jiffies };
2008#endif
2009
2010static struct script script0 __initdata = {
2011 {
2012
2013
2014
2015
2016 SCR_NO_OP,
2017 0,
2018
2019
2020
2021 SCR_FROM_REG (ctest2),
2022 0,
2023
2024
2025
2026
2027
2028 SCR_JUMP,
2029},{
2030 PADDRH(tryloop),
2031
2032},{
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045 SCR_CLR (SCR_TRG),
2046 0,
2047 SCR_LOAD_REG (HS_REG, HS_SELECTING),
2048 0,
2049
2050
2051
2052
2053 SCR_SEL_TBL_ATN ^ offsetof (struct dsb, select),
2054 PADDR (reselect),
2055
2056},{
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085 SCR_JUMPR ^ IFFALSE (WHEN (SCR_MSG_OUT)),
2086 0,
2087
2088
2089
2090
2091 SCR_COPY (4),
2092 RADDR (temp),
2093 PADDR (startpos),
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103 SCR_COPY_F (4),
2104 RADDR (dsa),
2105 PADDR (loadpos),
2106
2107
2108
2109 PREFETCH_FLUSH
2110
2111
2112
2113 SCR_COPY (sizeof (struct head)),
2114
2115
2116
2117},{
2118 0,
2119 NADDR (header),
2120
2121
2122
2123
2124 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
2125 PADDR (prepare),
2126
2127},{
2128
2129
2130
2131
2132
2133 SCR_MOVE_TBL ^ SCR_MSG_OUT,
2134 offsetof (struct dsb, smsg),
2135 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_OUT)),
2136 PADDRH (resend_ident),
2137 SCR_LOAD_REG (scratcha, 0x80),
2138 0,
2139 SCR_COPY (1),
2140 RADDR (scratcha),
2141 NADDR (lastmsg),
2142},{
2143
2144
2145
2146
2147 SCR_COPY (4),
2148 NADDR (header.savep),
2149 RADDR (temp),
2150
2151
2152
2153 SCR_COPY (4),
2154 NADDR (header.status),
2155 RADDR (scr0),
2156},{
2157
2158
2159
2160 SCR_LOAD_REG (scratcha, NOP),
2161 0,
2162 SCR_COPY (1),
2163 RADDR (scratcha),
2164 NADDR (msgout),
2165#if 0
2166 SCR_COPY (1),
2167 RADDR (scratcha),
2168 NADDR (msgin),
2169#endif
2170
2171
2172
2173
2174 SCR_JUMP ^ IFFALSE (WHEN (SCR_COMMAND)),
2175 PADDR (dispatch),
2176
2177},{
2178
2179
2180
2181 SCR_MOVE_TBL ^ SCR_COMMAND,
2182 offsetof (struct dsb, cmd),
2183
2184
2185
2186
2187
2188 SCR_FROM_REG (HS_REG),
2189 0,
2190 SCR_INT ^ IFTRUE (DATA (HS_NEGOTIATE)),
2191 SIR_NEGO_FAILED,
2192
2193},{
2194
2195
2196
2197
2198
2199 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
2200 PADDR (msg_in),
2201
2202 SCR_RETURN ^ IFTRUE (IF (SCR_DATA_OUT)),
2203 0,
2204
2205
2206
2207
2208
2209
2210
2211 SCR_JUMPR ^ IFFALSE (IF (SCR_DATA_IN)),
2212 20,
2213 SCR_COPY (4),
2214 RADDR (scratcha),
2215 RADDR (scratcha),
2216 SCR_RETURN,
2217 0,
2218 SCR_JUMP ^ IFTRUE (IF (SCR_STATUS)),
2219 PADDR (status),
2220 SCR_JUMP ^ IFTRUE (IF (SCR_COMMAND)),
2221 PADDR (command),
2222 SCR_JUMP ^ IFTRUE (IF (SCR_MSG_OUT)),
2223 PADDR (msg_out),
2224
2225
2226
2227 SCR_LOAD_REG (scratcha, XE_BAD_PHASE),
2228 0,
2229 SCR_COPY (1),
2230 RADDR (scratcha),
2231 NADDR (xerr_st),
2232 SCR_JUMPR ^ IFFALSE (IF (SCR_ILG_OUT)),
2233 8,
2234 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT,
2235 NADDR (scratch),
2236 SCR_JUMPR ^ IFFALSE (IF (SCR_ILG_IN)),
2237 8,
2238 SCR_MOVE_ABS (1) ^ SCR_ILG_IN,
2239 NADDR (scratch),
2240 SCR_JUMP,
2241 PADDR (dispatch),
2242
2243},{
2244
2245
2246
2247 SCR_CLR (SCR_ACK),
2248 0,
2249 SCR_JUMP,
2250 PADDR (dispatch),
2251
2252},{
2253
2254
2255
2256
2257
2258 SCR_LOAD_REG (scratcha, XE_EXTRA_DATA),
2259 0,
2260 SCR_COPY (1),
2261 RADDR (scratcha),
2262 NADDR (xerr_st),
2263
2264
2265
2266 SCR_JUMPR ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2267 8,
2268 SCR_MOVE_ABS (1) ^ SCR_DATA_OUT,
2269 NADDR (scratch),
2270 SCR_JUMPR ^ IFFALSE (IF (SCR_DATA_IN)),
2271 8,
2272 SCR_MOVE_ABS (1) ^ SCR_DATA_IN,
2273 NADDR (scratch),
2274
2275
2276
2277 SCR_CALL,
2278 PADDR (dispatch),
2279 SCR_JUMP,
2280 PADDR (no_data),
2281
2282},{
2283
2284
2285
2286 SCR_MOVE_ABS (1) ^ SCR_STATUS,
2287 NADDR (scratch),
2288
2289
2290
2291
2292 SCR_TO_REG (SS_REG),
2293 0,
2294 SCR_LOAD_REG (HS_REG, HS_COMPLETE),
2295 0,
2296 SCR_JUMP,
2297 PADDR (dispatch),
2298},{
2299
2300
2301
2302
2303
2304
2305
2306 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2307 NADDR (msgin[0]),
2308},{
2309
2310
2311
2312 SCR_JUMP ^ IFTRUE (DATA (COMMAND_COMPLETE)),
2313 PADDR (complete),
2314 SCR_JUMP ^ IFTRUE (DATA (DISCONNECT)),
2315 PADDR (disconnect),
2316 SCR_JUMP ^ IFTRUE (DATA (SAVE_POINTERS)),
2317 PADDR (save_dp),
2318 SCR_JUMP ^ IFTRUE (DATA (RESTORE_POINTERS)),
2319 PADDR (restore_dp),
2320 SCR_JUMP ^ IFTRUE (DATA (EXTENDED_MESSAGE)),
2321 PADDRH (msg_extended),
2322 SCR_JUMP ^ IFTRUE (DATA (NOP)),
2323 PADDR (clrack),
2324 SCR_JUMP ^ IFTRUE (DATA (MESSAGE_REJECT)),
2325 PADDRH (msg_reject),
2326 SCR_JUMP ^ IFTRUE (DATA (IGNORE_WIDE_RESIDUE)),
2327 PADDRH (msg_ign_residue),
2328
2329
2330
2331
2332
2333
2334
2335},{
2336
2337
2338
2339 SCR_INT,
2340 SIR_REJECT_SENT,
2341 SCR_LOAD_REG (scratcha, MESSAGE_REJECT),
2342 0,
2343},{
2344 SCR_COPY (1),
2345 RADDR (scratcha),
2346 NADDR (msgout),
2347 SCR_SET (SCR_ATN),
2348 0,
2349 SCR_JUMP,
2350 PADDR (clrack),
2351},{
2352
2353
2354
2355
2356
2357
2358 SCR_FROM_REG (dsa),
2359 0,
2360 SCR_JUMP ^ IFTRUE (DATA (0xff)),
2361 PADDR (start),
2362
2363
2364
2365
2366 SCR_JUMP,
2367 PADDR (cleanup_ok),
2368
2369},{
2370
2371
2372
2373
2374
2375 SCR_COPY (4),
2376 RADDR (temp),
2377 NADDR (header.lastp),
2378
2379
2380
2381
2382
2383
2384
2385
2386 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
2387 0,
2388
2389
2390
2391 SCR_CLR (SCR_ACK|SCR_ATN),
2392 0,
2393
2394
2395
2396 SCR_WAIT_DISC,
2397 0,
2398},{
2399
2400
2401
2402 SCR_COPY (4),
2403 RADDR (scr0),
2404 NADDR (header.status),
2405
2406
2407
2408 SCR_COPY_F (4),
2409 RADDR (dsa),
2410 PADDR (cleanup0),
2411
2412
2413
2414 PREFETCH_FLUSH
2415 SCR_COPY (sizeof (struct head)),
2416 NADDR (header),
2417},{
2418 0,
2419},{
2420
2421
2422
2423 SCR_FROM_REG (HS_REG),
2424 0,
2425
2426
2427
2428 SCR_JUMP ^ IFTRUE (MASK (0, (HS_DONEMASK|HS_SKIPMASK))),
2429 PADDR(start),
2430
2431
2432
2433
2434 SCR_FROM_REG (SS_REG),
2435 0,
2436 SCR_CALL ^ IFFALSE (DATA (SAM_STAT_GOOD)),
2437 PADDRH (bad_status),
2438
2439#ifndef SCSI_NCR_CCB_DONE_SUPPORT
2440
2441
2442
2443
2444 SCR_INT,
2445 SIR_INTFLY,
2446
2447
2448
2449 SCR_JUMP,
2450 PADDR(start),
2451
2452#else
2453
2454
2455
2456
2457 SCR_JUMP,
2458},{
2459 PADDRH (done_queue),
2460},{
2461 SCR_INT,
2462 SIR_DONE_OVERFLOW,
2463},{
2464 SCR_INT,
2465 SIR_INTFLY,
2466 SCR_COPY (4),
2467 RADDR (temp),
2468 PADDR (done_pos),
2469 SCR_JUMP,
2470 PADDR (start),
2471
2472#endif
2473
2474},{
2475
2476
2477
2478
2479 SCR_COPY (4),
2480 RADDR (temp),
2481 NADDR (header.savep),
2482 SCR_CLR (SCR_ACK),
2483 0,
2484 SCR_JUMP,
2485 PADDR (dispatch),
2486},{
2487
2488
2489
2490
2491 SCR_COPY (4),
2492 NADDR (header.savep),
2493 RADDR (temp),
2494 SCR_JUMP,
2495 PADDR (clrack),
2496
2497},{
2498
2499
2500
2501
2502
2503
2504 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
2505 0,
2506 SCR_CLR (SCR_ACK|SCR_ATN),
2507 0,
2508
2509
2510
2511 SCR_WAIT_DISC,
2512 0,
2513
2514
2515
2516 SCR_LOAD_REG (HS_REG, HS_DISCONNECT),
2517 0,
2518 SCR_JUMP,
2519 PADDR (cleanup_ok),
2520
2521},{
2522
2523
2524
2525 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
2526 NADDR (msgout),
2527 SCR_COPY (1),
2528 NADDR (msgout),
2529 NADDR (lastmsg),
2530
2531
2532
2533 SCR_JUMP ^ IFTRUE (DATA (ABORT_TASK_SET)),
2534 PADDRH (msg_out_abort),
2535
2536
2537
2538
2539 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_OUT)),
2540 PADDR (msg_out),
2541},{
2542
2543
2544
2545 SCR_LOAD_REG (scratcha, NOP),
2546 0,
2547 SCR_COPY (4),
2548 RADDR (scratcha),
2549 NADDR (msgout),
2550
2551
2552
2553 SCR_JUMP,
2554 PADDR (dispatch),
2555},{
2556
2557
2558
2559
2560
2561
2562 SCR_NO_OP,
2563 0,
2564},{
2565
2566
2567
2568 SCR_LOAD_REG (dsa, 0xff),
2569 0,
2570 SCR_CLR (SCR_TRG),
2571 0,
2572 SCR_LOAD_REG (HS_REG, HS_IN_RESELECT),
2573 0,
2574
2575
2576
2577
2578
2579
2580 SCR_WAIT_RESEL,
2581 PADDR(start),
2582},{
2583
2584
2585
2586
2587 SCR_NO_OP,
2588 0,
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602 SCR_REG_SFBR (ssid, SCR_AND, 0x8F),
2603 0,
2604 SCR_TO_REG (sdid),
2605 0,
2606 SCR_JUMP,
2607 NADDR (jump_tcb),
2608
2609},{
2610
2611
2612
2613 SCR_CLR (SCR_ACK),
2614 0,
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624 SCR_COPY_F (4),
2625 RADDR (dsa),
2626 PADDR (loadpos1),
2627
2628
2629
2630 PREFETCH_FLUSH
2631
2632
2633
2634 SCR_COPY (sizeof (struct head)),
2635
2636
2637
2638
2639},{
2640 0,
2641 NADDR (header),
2642
2643
2644
2645 SCR_JUMP,
2646 PADDR (prepare),
2647
2648},{
2649
2650
2651
2652
2653
2654 SCR_INT ^ IFFALSE (WHEN (SCR_MSG_IN)),
2655 SIR_RESEL_NO_MSG_IN,
2656
2657
2658
2659
2660
2661
2662 SCR_FROM_REG (sbdl),
2663 0,
2664
2665
2666
2667 SCR_RETURN,
2668 0,
2669},{
2670
2671
2672
2673
2674
2675
2676 SCR_MOVE_ABS (3) ^ SCR_MSG_IN,
2677 NADDR (msgin),
2678
2679
2680
2681
2682
2683
2684
2685 SCR_REG_SFBR (sidl, SCR_SHL, 0),
2686 0,
2687 SCR_SFBR_REG (temp, SCR_AND, 0xfc),
2688 0,
2689},{
2690 SCR_COPY_F (4),
2691 RADDR (temp),
2692 PADDR (nexus_indirect),
2693
2694
2695
2696 PREFETCH_FLUSH
2697 SCR_COPY (4),
2698},{
2699 0,
2700 RADDR (temp),
2701 SCR_RETURN,
2702 0,
2703},{
2704
2705
2706
2707
2708 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2709 NADDR (msgin),
2710 SCR_JUMP,
2711 PADDR (jump_to_nexus),
2712},{
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
27270
2728},{
2729 SCR_CALL,
2730 PADDR (dispatch),
2731 SCR_JUMP,
2732 PADDR (no_data),
2733},{
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
27480
2749},{
2750 SCR_CALL,
2751 PADDR (dispatch),
2752 SCR_JUMP,
2753 PADDR (no_data),
2754}
2755};
2756
2757static struct scripth scripth0 __initdata = {
2758{
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
27770
2778},{
2779 SCR_JUMP,
2780 PADDRH(tryloop),
2781
2782#ifdef SCSI_NCR_CCB_DONE_SUPPORT
2783
2784},{
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
28030
2804},{
2805 SCR_JUMP,
2806 PADDRH (done_queue),
2807
2808#endif
2809},{
2810
2811
2812
2813
2814
2815 SCR_CLR (SCR_TRG),
2816 0,
2817 SCR_LOAD_REG (HS_REG, HS_SELECTING),
2818 0,
2819 SCR_SEL_TBL ^ offsetof (struct dsb, select),
2820 PADDR (reselect),
2821 SCR_JUMP,
2822 PADDR (select2),
2823
2824},{
2825
2826 SCR_LOAD_REG (scratcha, HS_ABORTED),
2827 0,
2828 SCR_JUMPR,
2829 8,
2830},{
2831 SCR_LOAD_REG (scratcha, 0),
2832 0,
2833
2834
2835
2836
2837 SCR_COPY (4),
2838 RADDR (temp),
2839 PADDR (startpos),
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849 SCR_COPY_F (4),
2850 RADDR (dsa),
2851 PADDRH (skip2),
2852
2853
2854
2855 PREFETCH_FLUSH
2856
2857
2858
2859 SCR_COPY (sizeof (struct head)),
2860
2861
2862
2863},{
2864 0,
2865 NADDR (header),
2866
2867
2868
2869 SCR_COPY (4),
2870 NADDR (header.status),
2871 RADDR (scr0),
2872
2873
2874
2875 SCR_FROM_REG (scratcha),
2876 0,
2877 SCR_JUMPR ^ IFFALSE (MASK (0, HS_DONEMASK)),
2878 16,
2879 SCR_REG_REG (HS_REG, SCR_OR, HS_SKIPMASK),
2880 0,
2881 SCR_JUMPR,
2882 8,
2883 SCR_TO_REG (HS_REG),
2884 0,
2885 SCR_LOAD_REG (SS_REG, SAM_STAT_GOOD),
2886 0,
2887 SCR_JUMP,
2888 PADDR (cleanup_ok),
2889
2890},{
2891
2892
2893
2894 SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_IN)),
2895 PADDRH (par_err_other),
2896 SCR_MOVE_ABS (1) ^ SCR_DATA_IN,
2897 NADDR (scratch),
2898 SCR_JUMPR,
2899 -24,
2900},{
2901
2902
2903
2904 SCR_REG_REG (PS_REG, SCR_ADD, 0x01),
2905 0,
2906
2907
2908
2909 SCR_JUMP,
2910 PADDR (dispatch),
2911},{
2912
2913
2914
2915
2916
2917
2918 SCR_FROM_REG (HS_REG),
2919 0,
2920 SCR_INT ^ IFFALSE (DATA (HS_NEGOTIATE)),
2921 SIR_REJECT_RECEIVED,
2922 SCR_INT ^ IFTRUE (DATA (HS_NEGOTIATE)),
2923 SIR_NEGO_FAILED,
2924 SCR_JUMP,
2925 PADDR (clrack),
2926
2927},{
2928
2929
2930
2931 SCR_CLR (SCR_ACK),
2932 0,
2933 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2934 PADDR (dispatch),
2935
2936
2937
2938 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2939 NADDR (msgin[1]),
2940
2941
2942
2943 SCR_JUMP ^ IFTRUE (DATA (0)),
2944 PADDR (clrack),
2945
2946
2947
2948 SCR_JUMPR ^ IFFALSE (DATA (1)),
2949 40,
2950
2951
2952
2953 SCR_FROM_REG (scntl2),
2954 0,
2955 SCR_JUMPR ^ IFFALSE (MASK (WSR, WSR)),
2956 16,
2957
2958
2959
2960
2961 SCR_REG_REG (scntl2, SCR_OR, WSR),
2962 0,
2963 SCR_JUMP,
2964 PADDR (clrack),
2965
2966
2967
2968 SCR_FROM_REG (scratcha),
2969 0,
2970 SCR_INT,
2971 SIR_IGN_RESIDUE,
2972 SCR_JUMP,
2973 PADDR (clrack),
2974
2975},{
2976
2977
2978
2979 SCR_CLR (SCR_ACK),
2980 0,
2981 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2982 PADDR (dispatch),
2983
2984
2985
2986 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2987 NADDR (msgin[1]),
2988
2989
2990 SCR_JUMP ^ IFTRUE (DATA (3)),
2991 PADDRH (msg_ext_3),
2992 SCR_JUMP ^ IFFALSE (DATA (2)),
2993 PADDR (msg_bad),
2994},{
2995 SCR_CLR (SCR_ACK),
2996 0,
2997 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2998 PADDR (dispatch),
2999
3000
3001
3002 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
3003 NADDR (msgin[2]),
3004 SCR_JUMP ^ IFTRUE (DATA (EXTENDED_WDTR)),
3005 PADDRH (msg_wdtr),
3006
3007
3008
3009 SCR_JUMP,
3010 PADDR (msg_bad)
3011},{
3012 SCR_CLR (SCR_ACK),
3013 0,
3014 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
3015 PADDR (dispatch),
3016
3017
3018
3019 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
3020 NADDR (msgin[3]),
3021
3022
3023
3024 SCR_INT,
3025 SIR_NEGO_WIDE,
3026
3027
3028
3029 SCR_SET (SCR_ATN),
3030 0,
3031 SCR_CLR (SCR_ACK),
3032 0,
3033 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
3034 PADDRH (nego_bad_phase),
3035
3036},{
3037
3038
3039
3040 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT,
3041 NADDR (msgout),
3042 SCR_COPY (1),
3043 NADDR (msgout),
3044 NADDR (lastmsg),
3045 SCR_JUMP,
3046 PADDR (msg_out_done),
3047
3048},{
3049 SCR_CLR (SCR_ACK),
3050 0,
3051 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
3052 PADDR (dispatch),
3053
3054
3055
3056 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
3057 NADDR (msgin[2]),
3058 SCR_JUMP ^ IFTRUE (DATA (EXTENDED_SDTR)),
3059 PADDRH (msg_sdtr),
3060
3061
3062
3063 SCR_JUMP,
3064 PADDR (msg_bad)
3065
3066},{
3067 SCR_CLR (SCR_ACK),
3068 0,
3069 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
3070 PADDR (dispatch),
3071
3072
3073
3074 SCR_MOVE_ABS (2) ^ SCR_MSG_IN,
3075 NADDR (msgin[3]),
3076
3077
3078
3079 SCR_INT,
3080 SIR_NEGO_SYNC,
3081
3082
3083
3084 SCR_SET (SCR_ATN),
3085 0,
3086 SCR_CLR (SCR_ACK),
3087 0,
3088 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
3089 PADDRH (nego_bad_phase),
3090
3091},{
3092
3093
3094
3095 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT,
3096 NADDR (msgout),
3097 SCR_COPY (1),
3098 NADDR (msgout),
3099 NADDR (lastmsg),
3100 SCR_JUMP,
3101 PADDR (msg_out_done),
3102
3103},{
3104 SCR_INT,
3105 SIR_NEGO_PROTO,
3106 SCR_JUMP,
3107 PADDR (dispatch),
3108
3109},{
3110
3111
3112
3113
3114
3115 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
3116 0,
3117 SCR_CLR (SCR_ACK|SCR_ATN),
3118 0,
3119 SCR_WAIT_DISC,
3120 0,
3121
3122
3123
3124 SCR_LOAD_REG (HS_REG, HS_ABORTED),
3125 0,
3126 SCR_JUMP,
3127 PADDR (cleanup),
3128
3129},{
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
31440
3145},{
3146 SCR_JUMP,
3147 PADDR (data_in),
3148
3149},{
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
31640
3165},{
3166 SCR_JUMP,
3167 PADDR (data_out),
3168
3169},{
3170
3171
3172
3173
3174 SCR_LOAD_REG (scratcha, ABORT_TASK),
3175 0,
3176 SCR_JUMP,
3177 PADDRH (abort_resel),
3178},{
3179
3180
3181
3182 SCR_LOAD_REG (scratcha, ABORT_TASK),
3183 0,
3184 SCR_JUMP,
3185 PADDRH (abort_resel),
3186},{
3187
3188
3189
3190 SCR_LOAD_REG (scratcha, ABORT_TASK_SET),
3191 0,
3192},{
3193 SCR_COPY (1),
3194 RADDR (scratcha),
3195 NADDR (msgout),
3196 SCR_SET (SCR_ATN),
3197 0,
3198 SCR_CLR (SCR_ACK),
3199 0,
3200
3201
3202
3203
3204 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
3205 0,
3206 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
3207 NADDR (msgout),
3208 SCR_COPY (1),
3209 NADDR (msgout),
3210 NADDR (lastmsg),
3211 SCR_CLR (SCR_ACK|SCR_ATN),
3212 0,
3213 SCR_WAIT_DISC,
3214 0,
3215 SCR_JUMP,
3216 PADDR (start),
3217},{
3218
3219
3220
3221
3222
3223
3224 SCR_SET (SCR_ATN),
3225 0,
3226 SCR_JUMP,
3227 PADDR (send_ident),
3228},{
3229 SCR_CLR (SCR_ATN),
3230 0,
3231 SCR_JUMP,
3232},{
3233 0,
3234},{
3235 SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
3236 PADDR (dispatch),
3237 SCR_MOVE_TBL ^ SCR_DATA_IN,
3238 offsetof (struct dsb, sense),
3239 SCR_CALL,
3240 PADDR (dispatch),
3241 SCR_JUMP,
3242 PADDR (no_data),
3243},{
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256 SCR_JUMPR ^ IFTRUE (WHEN (SCR_DATA_OUT)),
3257 32,
3258
3259
3260
3261
3262 SCR_COPY (4),
3263 NADDR (header.lastp),
3264 NADDR (header.savep),
3265
3266
3267
3268
3269 SCR_COPY (4),
3270 NADDR (header.savep),
3271 RADDR (temp),
3272 SCR_RETURN,
3273 0,
3274
3275
3276
3277 SCR_COPY (4),
3278 NADDR (header.wlastp),
3279 NADDR (header.lastp),
3280 SCR_COPY (4),
3281 NADDR (header.wgoalp),
3282 NADDR (header.goalp),
3283 SCR_JUMPR,
3284 -64,
3285},{
3286
3287
3288
3289
3290
3291 SCR_JUMPR ^ IFTRUE (MASK (0x80, 0x80)),
3292 16,
3293 SCR_INT,
3294 SIR_RESEL_NO_IDENTIFY,
3295 SCR_JUMP,
3296 PADDRH (reset),
3297
3298
3299
3300
3301
3302
3303
3304 SCR_INT,
3305 SIR_RESEL_BAD_LUN,
3306 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
3307 NADDR (msgin),
3308 SCR_JUMP,
3309 PADDRH (abort),
3310},{
3311
3312
3313
3314
3315
3316 SCR_INT,
3317 SIR_RESEL_BAD_I_T_L,
3318 SCR_JUMP,
3319 PADDRH (abort),
3320},{
3321
3322
3323
3324
3325
3326 SCR_INT,
3327 SIR_RESEL_BAD_I_T_L_Q,
3328 SCR_JUMP,
3329 PADDRH (aborttag),
3330},{
3331
3332
3333
3334
3335
3336
3337 SCR_INT,
3338 SIR_RESEL_BAD_TARGET,
3339 SCR_JUMPR ^ IFFALSE (WHEN (SCR_MSG_IN)),
3340 8,
3341 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
3342 NADDR (msgin),
3343 SCR_JUMP,
3344 PADDRH (reset),
3345},{
3346
3347
3348
3349
3350
3351 SCR_INT ^ IFTRUE (DATA (SAM_STAT_TASK_SET_FULL)),
3352 SIR_BAD_STATUS,
3353 SCR_INT ^ IFTRUE (DATA (SAM_STAT_CHECK_CONDITION)),
3354 SIR_BAD_STATUS,
3355 SCR_INT ^ IFTRUE (DATA (SAM_STAT_COMMAND_TERMINATED)),
3356 SIR_BAD_STATUS,
3357 SCR_RETURN,
3358 0,
3359},{
3360
3361
3362
3363
3364 SCR_COPY_F (4),
3365 RADDR (scratcha),
3366 PADDRH (start_ram0),
3367
3368
3369
3370 PREFETCH_FLUSH
3371 SCR_COPY (sizeof (struct script)),
3372},{
3373 0,
3374 PADDR (start),
3375 SCR_JUMP,
3376 PADDR (start),
3377},{
3378
3379
3380
3381
3382
3383 SCR_COPY (4),
3384 RADDR (temp),
3385 PADDR (startpos),
3386 SCR_JUMP,
3387 PADDR (start),
3388},{
3389
3390
3391
3392
3393
3394
3395
3396
3397 SCR_RETURN,
3398 0,
3399},{
3400
3401
3402
3403 SCR_COPY (4),
3404 NADDR(ncr_cache),
3405 RADDR (scratcha),
3406
3407
3408
3409 SCR_COPY (4),
3410 RADDR (temp),
3411 NADDR(ncr_cache),
3412
3413
3414
3415 SCR_COPY (4),
3416 NADDR(ncr_cache),
3417 RADDR (temp),
3418},{
3419
3420
3421
3422 SCR_INT,
3423 99,
3424}
3425};
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436void __init ncr_script_fill (struct script * scr, struct scripth * scrh)
3437{
3438 int i;
3439 ncrcmd *p;
3440
3441 p = scrh->tryloop;
3442 for (i=0; i<MAX_START; i++) {
3443 *p++ =SCR_CALL;
3444 *p++ =PADDR (idle);
3445 }
3446
3447 BUG_ON((u_long)p != (u_long)&scrh->tryloop + sizeof (scrh->tryloop));
3448
3449#ifdef SCSI_NCR_CCB_DONE_SUPPORT
3450
3451 p = scrh->done_queue;
3452 for (i = 0; i<MAX_DONE; i++) {
3453 *p++ =SCR_COPY (sizeof(struct ccb *));
3454 *p++ =NADDR (header.cp);
3455 *p++ =NADDR (ccb_done[i]);
3456 *p++ =SCR_CALL;
3457 *p++ =PADDR (done_end);
3458 }
3459
3460 BUG_ON((u_long)p != (u_long)&scrh->done_queue+sizeof(scrh->done_queue));
3461
3462#endif
3463
3464 p = scrh->hdata_in;
3465 for (i=0; i<MAX_SCATTERH; i++) {
3466 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN));
3467 *p++ =PADDR (dispatch);
3468 *p++ =SCR_MOVE_TBL ^ SCR_DATA_IN;
3469 *p++ =offsetof (struct dsb, data[i]);
3470 }
3471
3472 BUG_ON((u_long)p != (u_long)&scrh->hdata_in + sizeof (scrh->hdata_in));
3473
3474 p = scr->data_in;
3475 for (i=MAX_SCATTERH; i<MAX_SCATTERH+MAX_SCATTERL; i++) {
3476 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN));
3477 *p++ =PADDR (dispatch);
3478 *p++ =SCR_MOVE_TBL ^ SCR_DATA_IN;
3479 *p++ =offsetof (struct dsb, data[i]);
3480 }
3481
3482 BUG_ON((u_long)p != (u_long)&scr->data_in + sizeof (scr->data_in));
3483
3484 p = scrh->hdata_out;
3485 for (i=0; i<MAX_SCATTERH; i++) {
3486 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT));
3487 *p++ =PADDR (dispatch);
3488 *p++ =SCR_MOVE_TBL ^ SCR_DATA_OUT;
3489 *p++ =offsetof (struct dsb, data[i]);
3490 }
3491
3492 BUG_ON((u_long)p != (u_long)&scrh->hdata_out + sizeof (scrh->hdata_out));
3493
3494 p = scr->data_out;
3495 for (i=MAX_SCATTERH; i<MAX_SCATTERH+MAX_SCATTERL; i++) {
3496 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT));
3497 *p++ =PADDR (dispatch);
3498 *p++ =SCR_MOVE_TBL ^ SCR_DATA_OUT;
3499 *p++ =offsetof (struct dsb, data[i]);
3500 }
3501
3502 BUG_ON((u_long) p != (u_long)&scr->data_out + sizeof (scr->data_out));
3503}
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514static void __init
3515ncr_script_copy_and_bind (struct ncb *np, ncrcmd *src, ncrcmd *dst, int len)
3516{
3517 ncrcmd opcode, new, old, tmp1, tmp2;
3518 ncrcmd *start, *end;
3519 int relocs;
3520 int opchanged = 0;
3521
3522 start = src;
3523 end = src + len/4;
3524
3525 while (src < end) {
3526
3527 opcode = *src++;
3528 *dst++ = cpu_to_scr(opcode);
3529
3530
3531
3532
3533
3534
3535
3536
3537 if (opcode == 0) {
3538 printk (KERN_ERR "%s: ERROR0 IN SCRIPT at %d.\n",
3539 ncr_name(np), (int) (src-start-1));
3540 mdelay(1000);
3541 }
3542
3543 if (DEBUG_FLAGS & DEBUG_SCRIPT)
3544 printk (KERN_DEBUG "%p: <%x>\n",
3545 (src-1), (unsigned)opcode);
3546
3547
3548
3549
3550 switch (opcode >> 28) {
3551
3552 case 0xc:
3553
3554
3555
3556 relocs = 2;
3557 tmp1 = src[0];
3558#ifdef RELOC_KVAR
3559 if ((tmp1 & RELOC_MASK) == RELOC_KVAR)
3560 tmp1 = 0;
3561#endif
3562 tmp2 = src[1];
3563#ifdef RELOC_KVAR
3564 if ((tmp2 & RELOC_MASK) == RELOC_KVAR)
3565 tmp2 = 0;
3566#endif
3567 if ((tmp1 ^ tmp2) & 3) {
3568 printk (KERN_ERR"%s: ERROR1 IN SCRIPT at %d.\n",
3569 ncr_name(np), (int) (src-start-1));
3570 mdelay(1000);
3571 }
3572
3573
3574
3575
3576 if ((opcode & SCR_NO_FLUSH) && !(np->features & FE_PFEN)) {
3577 dst[-1] = cpu_to_scr(opcode & ~SCR_NO_FLUSH);
3578 ++opchanged;
3579 }
3580 break;
3581
3582 case 0x0:
3583
3584
3585
3586 relocs = 1;
3587 break;
3588
3589 case 0x8:
3590
3591
3592
3593
3594 if (opcode & 0x00800000)
3595 relocs = 0;
3596 else
3597 relocs = 1;
3598 break;
3599
3600 case 0x4:
3601 case 0x5:
3602 case 0x6:
3603 case 0x7:
3604 relocs = 1;
3605 break;
3606
3607 default:
3608 relocs = 0;
3609 break;
3610 }
3611
3612 if (relocs) {
3613 while (relocs--) {
3614 old = *src++;
3615
3616 switch (old & RELOC_MASK) {
3617 case RELOC_REGISTER:
3618 new = (old & ~RELOC_MASK) + np->paddr;
3619 break;
3620 case RELOC_LABEL:
3621 new = (old & ~RELOC_MASK) + np->p_script;
3622 break;
3623 case RELOC_LABELH:
3624 new = (old & ~RELOC_MASK) + np->p_scripth;
3625 break;
3626 case RELOC_SOFTC:
3627 new = (old & ~RELOC_MASK) + np->p_ncb;
3628 break;
3629#ifdef RELOC_KVAR
3630 case RELOC_KVAR:
3631 if (((old & ~RELOC_MASK) <
3632 SCRIPT_KVAR_FIRST) ||
3633 ((old & ~RELOC_MASK) >
3634 SCRIPT_KVAR_LAST))
3635 panic("ncr KVAR out of range");
3636 new = vtophys(script_kvars[old &
3637 ~RELOC_MASK]);
3638 break;
3639#endif
3640 case 0:
3641
3642 if (old == 0) {
3643 new = old;
3644 break;
3645 }
3646 fallthrough;
3647 default:
3648 panic("ncr_script_copy_and_bind: weird relocation %x\n", old);
3649 break;
3650 }
3651
3652 *dst++ = cpu_to_scr(new);
3653 }
3654 } else
3655 *dst++ = cpu_to_scr(*src++);
3656
3657 }
3658}
3659
3660
3661
3662
3663
3664struct host_data {
3665 struct ncb *ncb;
3666};
3667
3668#define PRINT_ADDR(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
3669
3670static void ncr_print_msg(struct ccb *cp, char *label, u_char *msg)
3671{
3672 PRINT_ADDR(cp->cmd, "%s: ", label);
3673
3674 spi_print_msg(msg);
3675 printk("\n");
3676}
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687#define _5M 5000000
3688static u_long div_10M[] =
3689 {2*_5M, 3*_5M, 4*_5M, 6*_5M, 8*_5M, 12*_5M, 16*_5M};
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708#define burst_length(bc) (!(bc))? 0 : 1 << (bc)
3709
3710
3711
3712
3713#define burst_code(dmode, ctest0) \
3714 (ctest0) & 0x80 ? 0 : (((dmode) & 0xc0) >> 6) + 1
3715
3716
3717
3718
3719static inline void ncr_init_burst(struct ncb *np, u_char bc)
3720{
3721 u_char *be = &np->rv_ctest0;
3722 *be &= ~0x80;
3723 np->rv_dmode &= ~(0x3 << 6);
3724 np->rv_ctest5 &= ~0x4;
3725
3726 if (!bc) {
3727 *be |= 0x80;
3728 } else {
3729 --bc;
3730 np->rv_dmode |= ((bc & 0x3) << 6);
3731 np->rv_ctest5 |= (bc & 0x4);
3732 }
3733}
3734
3735static void __init ncr_prepare_setting(struct ncb *np)
3736{
3737 u_char burst_max;
3738 u_long period;
3739 int i;
3740
3741
3742
3743
3744
3745 np->sv_scntl0 = INB(nc_scntl0) & 0x0a;
3746 np->sv_scntl3 = INB(nc_scntl3) & 0x07;
3747 np->sv_dmode = INB(nc_dmode) & 0xce;
3748 np->sv_dcntl = INB(nc_dcntl) & 0xa8;
3749 np->sv_ctest0 = INB(nc_ctest0) & 0x84;
3750 np->sv_ctest3 = INB(nc_ctest3) & 0x01;
3751 np->sv_ctest4 = INB(nc_ctest4) & 0x80;
3752 np->sv_ctest5 = INB(nc_ctest5) & 0x24;
3753 np->sv_gpcntl = INB(nc_gpcntl);
3754 np->sv_stest2 = INB(nc_stest2) & 0x20;
3755 np->sv_stest4 = INB(nc_stest4);
3756
3757
3758
3759
3760
3761 np->maxwide = (np->features & FE_WIDE)? 1 : 0;
3762
3763
3764
3765
3766 if (np->features & FE_ULTRA)
3767 np->clock_khz = 80000;
3768 else
3769 np->clock_khz = 40000;
3770
3771
3772
3773
3774 if (np->features & FE_QUAD)
3775 np->multiplier = 4;
3776 else if (np->features & FE_DBLR)
3777 np->multiplier = 2;
3778 else
3779 np->multiplier = 1;
3780
3781
3782
3783
3784
3785 if (np->features & FE_VARCLK)
3786 ncr_getclock(np, np->multiplier);
3787
3788
3789
3790
3791 i = np->clock_divn - 1;
3792 while (--i >= 0) {
3793 if (10ul * SCSI_NCR_MIN_ASYNC * np->clock_khz > div_10M[i]) {
3794 ++i;
3795 break;
3796 }
3797 }
3798 np->rv_scntl3 = i+1;
3799
3800
3801
3802
3803
3804
3805 period = (4 * div_10M[0] + np->clock_khz - 1) / np->clock_khz;
3806 if (period <= 250) np->minsync = 10;
3807 else if (period <= 303) np->minsync = 11;
3808 else if (period <= 500) np->minsync = 12;
3809 else np->minsync = (period + 40 - 1) / 40;
3810
3811
3812
3813
3814
3815 if (np->minsync < 25 && !(np->features & FE_ULTRA))
3816 np->minsync = 25;
3817
3818
3819
3820
3821
3822 period = (11 * div_10M[np->clock_divn - 1]) / (4 * np->clock_khz);
3823 np->maxsync = period > 2540 ? 254 : period / 10;
3824
3825
3826
3827
3828#if defined SCSI_NCR_TRUST_BIOS_SETTING
3829 np->rv_scntl0 = np->sv_scntl0;
3830 np->rv_dmode = np->sv_dmode;
3831 np->rv_dcntl = np->sv_dcntl;
3832 np->rv_ctest0 = np->sv_ctest0;
3833 np->rv_ctest3 = np->sv_ctest3;
3834 np->rv_ctest4 = np->sv_ctest4;
3835 np->rv_ctest5 = np->sv_ctest5;
3836 burst_max = burst_code(np->sv_dmode, np->sv_ctest0);
3837#else
3838
3839
3840
3841
3842 burst_max = driver_setup.burst_max;
3843 if (burst_max == 255)
3844 burst_max = burst_code(np->sv_dmode, np->sv_ctest0);
3845 if (burst_max > 7)
3846 burst_max = 7;
3847 if (burst_max > np->maxburst)
3848 burst_max = np->maxburst;
3849
3850
3851
3852
3853 if (np->features & FE_ERL)
3854 np->rv_dmode |= ERL;
3855 if (np->features & FE_BOF)
3856 np->rv_dmode |= BOF;
3857 if (np->features & FE_ERMP)
3858 np->rv_dmode |= ERMP;
3859 if (np->features & FE_PFEN)
3860 np->rv_dcntl |= PFEN;
3861 if (np->features & FE_CLSE)
3862 np->rv_dcntl |= CLSE;
3863 if (np->features & FE_WRIE)
3864 np->rv_ctest3 |= WRIE;
3865 if (np->features & FE_DFS)
3866 np->rv_ctest5 |= DFS;
3867 if (np->features & FE_MUX)
3868 np->rv_ctest4 |= MUX;
3869 if (np->features & FE_EA)
3870 np->rv_dcntl |= EA;
3871 if (np->features & FE_EHP)
3872 np->rv_ctest0 |= EHP;
3873
3874
3875
3876
3877 if (driver_setup.master_parity)
3878 np->rv_ctest4 |= MPEE;
3879 if (driver_setup.scsi_parity)
3880 np->rv_scntl0 |= 0x0a;
3881
3882
3883
3884
3885 if (np->myaddr == 255) {
3886 np->myaddr = INB(nc_scid) & 0x07;
3887 if (!np->myaddr)
3888 np->myaddr = SCSI_NCR_MYADDR;
3889 }
3890
3891#endif
3892
3893
3894
3895
3896 ncr_init_burst(np, burst_max);
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907 np->scsi_mode = SMODE_SE;
3908 if (np->features & FE_DIFF) {
3909 switch(driver_setup.diff_support) {
3910 case 4:
3911 if (np->sv_scntl3) {
3912 if (np->sv_stest2 & 0x20)
3913 np->scsi_mode = SMODE_HVD;
3914 break;
3915 }
3916 fallthrough;
3917 case 3:
3918 if (INB(nc_gpreg) & 0x08)
3919 break;
3920 fallthrough;
3921 case 2:
3922 np->scsi_mode = SMODE_HVD;
3923 fallthrough;
3924 case 1:
3925 if (np->sv_stest2 & 0x20)
3926 np->scsi_mode = SMODE_HVD;
3927 break;
3928 default:
3929 break;
3930 }
3931 }
3932 if (np->scsi_mode == SMODE_HVD)
3933 np->rv_stest2 |= 0x20;
3934
3935
3936
3937
3938
3939
3940
3941
3942 if ((driver_setup.led_pin) &&
3943 !(np->features & FE_LEDC) && !(np->sv_gpcntl & 0x01))
3944 np->features |= FE_LED0;
3945
3946
3947
3948
3949 switch(driver_setup.irqm & 3) {
3950 case 2:
3951 np->rv_dcntl |= IRQM;
3952 break;
3953 case 1:
3954 np->rv_dcntl |= (np->sv_dcntl & IRQM);
3955 break;
3956 default:
3957 break;
3958 }
3959
3960
3961
3962
3963
3964
3965 for (i = 0 ; i < MAX_TARGET ; i++) {
3966 struct tcb *tp = &np->target[i];
3967
3968 tp->usrsync = driver_setup.default_sync;
3969 tp->usrwide = driver_setup.max_wide;
3970 tp->usrtags = MAX_TAGS;
3971 tp->period = 0xffff;
3972 if (!driver_setup.disconnection)
3973 np->target[i].usrflag = UF_NODISC;
3974 }
3975
3976
3977
3978
3979
3980 printk(KERN_INFO "%s: ID %d, Fast-%d%s%s\n", ncr_name(np),
3981 np->myaddr,
3982 np->minsync < 12 ? 40 : (np->minsync < 25 ? 20 : 10),
3983 (np->rv_scntl0 & 0xa) ? ", Parity Checking" : ", NO Parity",
3984 (np->rv_stest2 & 0x20) ? ", Differential" : "");
3985
3986 if (bootverbose > 1) {
3987 printk (KERN_INFO "%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3988 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3989 ncr_name(np), np->sv_scntl3, np->sv_dmode, np->sv_dcntl,
3990 np->sv_ctest3, np->sv_ctest4, np->sv_ctest5);
3991
3992 printk (KERN_INFO "%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3993 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3994 ncr_name(np), np->rv_scntl3, np->rv_dmode, np->rv_dcntl,
3995 np->rv_ctest3, np->rv_ctest4, np->rv_ctest5);
3996 }
3997
3998 if (bootverbose && np->paddr2)
3999 printk (KERN_INFO "%s: on-chip RAM at 0x%lx\n",
4000 ncr_name(np), np->paddr2);
4001}
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022static inline void ncr_queue_done_cmd(struct ncb *np, struct scsi_cmnd *cmd)
4023{
4024 unmap_scsi_data(np, cmd);
4025 cmd->host_scribble = (char *) np->done_list;
4026 np->done_list = cmd;
4027}
4028
4029static inline void ncr_flush_done_cmds(struct scsi_cmnd *lcmd)
4030{
4031 struct scsi_cmnd *cmd;
4032
4033 while (lcmd) {
4034 cmd = lcmd;
4035 lcmd = (struct scsi_cmnd *) cmd->host_scribble;
4036 cmd->scsi_done(cmd);
4037 }
4038}
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054static int ncr_prepare_nego(struct ncb *np, struct ccb *cp, u_char *msgptr)
4055{
4056 struct tcb *tp = &np->target[cp->target];
4057 int msglen = 0;
4058 int nego = 0;
4059 struct scsi_target *starget = tp->starget;
4060
4061
4062 if (!tp->widedone) {
4063 if (spi_support_wide(starget)) {
4064 nego = NS_WIDE;
4065 } else
4066 tp->widedone=1;
4067 }
4068
4069
4070 if (!nego && !tp->period) {
4071 if (spi_support_sync(starget)) {
4072 nego = NS_SYNC;
4073 } else {
4074 tp->period =0xffff;
4075 dev_info(&starget->dev, "target did not report SYNC.\n");
4076 }
4077 }
4078
4079 switch (nego) {
4080 case NS_SYNC:
4081 msglen += spi_populate_sync_msg(msgptr + msglen,
4082 tp->maxoffs ? tp->minsync : 0, tp->maxoffs);
4083 break;
4084 case NS_WIDE:
4085 msglen += spi_populate_width_msg(msgptr + msglen, tp->usrwide);
4086 break;
4087 }
4088
4089 cp->nego_status = nego;
4090
4091 if (nego) {
4092 tp->nego_cp = cp;
4093 if (DEBUG_FLAGS & DEBUG_NEGO) {
4094 ncr_print_msg(cp, nego == NS_WIDE ?
4095 "wide msgout":"sync_msgout", msgptr);
4096 }
4097 }
4098
4099 return msglen;
4100}
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113static int ncr_queue_command (struct ncb *np, struct scsi_cmnd *cmd)
4114{
4115 struct scsi_device *sdev = cmd->device;
4116 struct tcb *tp = &np->target[sdev->id];
4117 struct lcb *lp = tp->lp[sdev->lun];
4118 struct ccb *cp;
4119
4120 int segments;
4121 u_char idmsg, *msgptr;
4122 u32 msglen;
4123 int direction;
4124 u32 lastp, goalp;
4125
4126
4127
4128
4129
4130
4131
4132 if ((sdev->id == np->myaddr ) ||
4133 (sdev->id >= MAX_TARGET) ||
4134 (sdev->lun >= MAX_LUN )) {
4135 return(DID_BAD_TARGET);
4136 }
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147 if ((cmd->cmnd[0] == 0 || cmd->cmnd[0] == 0x12) &&
4148 (tp->usrflag & UF_NOSCAN)) {
4149 tp->usrflag &= ~UF_NOSCAN;
4150 return DID_BAD_TARGET;
4151 }
4152
4153 if (DEBUG_FLAGS & DEBUG_TINY) {
4154 PRINT_ADDR(cmd, "CMD=%x ", cmd->cmnd[0]);
4155 }
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167 if (np->settle_time && cmd->request->timeout >= HZ) {
4168 u_long tlimit = jiffies + cmd->request->timeout - HZ;
4169 if (time_after(np->settle_time, tlimit))
4170 np->settle_time = tlimit;
4171 }
4172
4173 if (np->settle_time || !(cp=ncr_get_ccb (np, cmd))) {
4174 insert_into_waiting_list(np, cmd);
4175 return(DID_OK);
4176 }
4177 cp->cmd = cmd;
4178
4179
4180
4181
4182
4183
4184
4185
4186 idmsg = IDENTIFY(0, sdev->lun);
4187
4188 if (cp ->tag != NO_TAG ||
4189 (cp != np->ccb && np->disc && !(tp->usrflag & UF_NODISC)))
4190 idmsg |= 0x40;
4191
4192 msgptr = cp->scsi_smsg;
4193 msglen = 0;
4194 msgptr[msglen++] = idmsg;
4195
4196 if (cp->tag != NO_TAG) {
4197 char order = np->order;
4198
4199
4200
4201
4202
4203 if (lp && time_after(jiffies, lp->tags_stime)) {
4204 if (lp->tags_smap) {
4205 order = ORDERED_QUEUE_TAG;
4206 if ((DEBUG_FLAGS & DEBUG_TAGS)||bootverbose>2){
4207 PRINT_ADDR(cmd,
4208 "ordered tag forced.\n");
4209 }
4210 }
4211 lp->tags_stime = jiffies + 3*HZ;
4212 lp->tags_smap = lp->tags_umap;
4213 }
4214
4215 if (order == 0) {
4216
4217
4218
4219 switch (cmd->cmnd[0]) {
4220 case 0x08:
4221 case 0x28:
4222 case 0xa8:
4223 order = SIMPLE_QUEUE_TAG;
4224 break;
4225 default:
4226 order = ORDERED_QUEUE_TAG;
4227 }
4228 }
4229 msgptr[msglen++] = order;
4230
4231
4232
4233
4234
4235 msgptr[msglen++] = (cp->tag << 1) + 1;
4236 }
4237
4238
4239
4240
4241
4242
4243
4244
4245 direction = cmd->sc_data_direction;
4246 if (direction != DMA_NONE) {
4247 segments = ncr_scatter(np, cp, cp->cmd);
4248 if (segments < 0) {
4249 ncr_free_ccb(np, cp);
4250 return(DID_ERROR);
4251 }
4252 }
4253 else {
4254 cp->data_len = 0;
4255 segments = 0;
4256 }
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267 cp->nego_status = 0;
4268
4269 if ((!tp->widedone || !tp->period) && !tp->nego_cp && lp) {
4270 msglen += ncr_prepare_nego (np, cp, msgptr + msglen);
4271 }
4272
4273
4274
4275
4276
4277
4278
4279 if (!cp->data_len)
4280 direction = DMA_NONE;
4281
4282
4283
4284
4285
4286
4287
4288 switch(direction) {
4289 case DMA_BIDIRECTIONAL:
4290 case DMA_TO_DEVICE:
4291 goalp = NCB_SCRIPT_PHYS (np, data_out2) + 8;
4292 if (segments <= MAX_SCATTERL)
4293 lastp = goalp - 8 - (segments * 16);
4294 else {
4295 lastp = NCB_SCRIPTH_PHYS (np, hdata_out2);
4296 lastp -= (segments - MAX_SCATTERL) * 16;
4297 }
4298 if (direction != DMA_BIDIRECTIONAL)
4299 break;
4300 cp->phys.header.wgoalp = cpu_to_scr(goalp);
4301 cp->phys.header.wlastp = cpu_to_scr(lastp);
4302 fallthrough;
4303 case DMA_FROM_DEVICE:
4304 goalp = NCB_SCRIPT_PHYS (np, data_in2) + 8;
4305 if (segments <= MAX_SCATTERL)
4306 lastp = goalp - 8 - (segments * 16);
4307 else {
4308 lastp = NCB_SCRIPTH_PHYS (np, hdata_in2);
4309 lastp -= (segments - MAX_SCATTERL) * 16;
4310 }
4311 break;
4312 default:
4313 case DMA_NONE:
4314 lastp = goalp = NCB_SCRIPT_PHYS (np, no_data);
4315 break;
4316 }
4317
4318
4319
4320
4321
4322 cp->phys.header.lastp = cpu_to_scr(lastp);
4323 cp->phys.header.goalp = cpu_to_scr(goalp);
4324
4325 if (direction == DMA_BIDIRECTIONAL)
4326 cp->phys.header.savep =
4327 cpu_to_scr(NCB_SCRIPTH_PHYS (np, data_io));
4328 else
4329 cp->phys.header.savep= cpu_to_scr(lastp);
4330
4331
4332
4333
4334
4335 cp->startp = cp->phys.header.savep;
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351 cp->start.schedule.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, select));
4352 cp->restart.schedule.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, resel_dsa));
4353
4354
4355
4356 cp->phys.select.sel_id = sdev_id(sdev);
4357 cp->phys.select.sel_scntl3 = tp->wval;
4358 cp->phys.select.sel_sxfer = tp->sval;
4359
4360
4361
4362 cp->phys.smsg.addr = cpu_to_scr(CCB_PHYS (cp, scsi_smsg));
4363 cp->phys.smsg.size = cpu_to_scr(msglen);
4364
4365
4366
4367
4368 memcpy(cp->cdb_buf, cmd->cmnd, min_t(int, cmd->cmd_len, sizeof(cp->cdb_buf)));
4369 cp->phys.cmd.addr = cpu_to_scr(CCB_PHYS (cp, cdb_buf[0]));
4370 cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
4371
4372
4373
4374
4375 cp->actualquirks = 0;
4376 cp->host_status = cp->nego_status ? HS_NEGOTIATE : HS_BUSY;
4377 cp->scsi_status = SAM_STAT_ILLEGAL;
4378 cp->parity_status = 0;
4379
4380 cp->xerr_status = XE_OK;
4381#if 0
4382 cp->sync_status = tp->sval;
4383 cp->wide_status = tp->wval;
4384#endif
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394 cp->magic = CCB_MAGIC;
4395
4396
4397
4398
4399
4400 cp->auto_sense = 0;
4401 if (lp)
4402 ncr_start_next_ccb(np, lp, 2);
4403 else
4404 ncr_put_start_queue(np, cp);
4405
4406
4407
4408 return DID_OK;
4409}
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422static void ncr_start_next_ccb(struct ncb *np, struct lcb *lp, int maxn)
4423{
4424 struct list_head *qp;
4425 struct ccb *cp;
4426
4427 if (lp->held_ccb)
4428 return;
4429
4430 while (maxn-- && lp->queuedccbs < lp->queuedepth) {
4431 qp = ncr_list_pop(&lp->wait_ccbq);
4432 if (!qp)
4433 break;
4434 ++lp->queuedccbs;
4435 cp = list_entry(qp, struct ccb, link_ccbq);
4436 list_add_tail(qp, &lp->busy_ccbq);
4437 lp->jump_ccb[cp->tag == NO_TAG ? 0 : cp->tag] =
4438 cpu_to_scr(CCB_PHYS (cp, restart));
4439 ncr_put_start_queue(np, cp);
4440 }
4441}
4442
4443static void ncr_put_start_queue(struct ncb *np, struct ccb *cp)
4444{
4445 u16 qidx;
4446
4447
4448
4449
4450 if (!np->squeueput) np->squeueput = 1;
4451 qidx = np->squeueput + 2;
4452 if (qidx >= MAX_START + MAX_START) qidx = 1;
4453
4454 np->scripth->tryloop [qidx] = cpu_to_scr(NCB_SCRIPT_PHYS (np, idle));
4455 MEMORY_BARRIER();
4456 np->scripth->tryloop [np->squeueput] = cpu_to_scr(CCB_PHYS (cp, start));
4457
4458 np->squeueput = qidx;
4459 ++np->queuedccbs;
4460 cp->queued = 1;
4461
4462 if (DEBUG_FLAGS & DEBUG_QUEUE)
4463 printk ("%s: queuepos=%d.\n", ncr_name (np), np->squeueput);
4464
4465
4466
4467
4468
4469 MEMORY_BARRIER();
4470 OUTB (nc_istat, SIGP);
4471}
4472
4473
4474static int ncr_reset_scsi_bus(struct ncb *np, int enab_int, int settle_delay)
4475{
4476 u32 term;
4477 int retv = 0;
4478
4479 np->settle_time = jiffies + settle_delay * HZ;
4480
4481 if (bootverbose > 1)
4482 printk("%s: resetting, "
4483 "command processing suspended for %d seconds\n",
4484 ncr_name(np), settle_delay);
4485
4486 ncr_chip_reset(np, 100);
4487 udelay(2000);
4488 if (enab_int)
4489 OUTW (nc_sien, RST);
4490
4491
4492
4493
4494 OUTB (nc_stest3, TE);
4495 OUTB (nc_scntl1, CRST);
4496 udelay(200);
4497
4498 if (!driver_setup.bus_check)
4499 goto out;
4500
4501
4502
4503
4504
4505
4506
4507 term = INB(nc_sstat0);
4508 term = ((term & 2) << 7) + ((term & 1) << 17);
4509 term |= ((INB(nc_sstat2) & 0x01) << 26) |
4510 ((INW(nc_sbdl) & 0xff) << 9) |
4511 ((INW(nc_sbdl) & 0xff00) << 10) |
4512 INB(nc_sbcl);
4513
4514 if (!(np->features & FE_WIDE))
4515 term &= 0x3ffff;
4516
4517 if (term != (2<<7)) {
4518 printk("%s: suspicious SCSI data while resetting the BUS.\n",
4519 ncr_name(np));
4520 printk("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
4521 "0x%lx, expecting 0x%lx\n",
4522 ncr_name(np),
4523 (np->features & FE_WIDE) ? "dp1,d15-8," : "",
4524 (u_long)term, (u_long)(2<<7));
4525 if (driver_setup.bus_check == 1)
4526 retv = 1;
4527 }
4528out:
4529 OUTB (nc_scntl1, 0);
4530 return retv;
4531}
4532
4533
4534
4535
4536
4537
4538
4539
4540static void ncr_start_reset(struct ncb *np)
4541{
4542 if (!np->settle_time) {
4543 ncr_reset_scsi_bus(np, 1, driver_setup.settle_delay);
4544 }
4545}
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556static int ncr_reset_bus (struct ncb *np, struct scsi_cmnd *cmd, int sync_reset)
4557{
4558
4559 struct ccb *cp;
4560 int found;
4561
4562
4563
4564
4565 if (np->settle_time) {
4566 return FAILED;
4567 }
4568
4569
4570
4571
4572
4573
4574 ncr_start_reset(np);
4575
4576
4577
4578 for (found=0, cp=np->ccb; cp; cp=cp->link_ccb) {
4579
4580
4581
4582 if (cp->host_status == HS_IDLE) continue;
4583 if (cp->cmd == cmd) {
4584 found = 1;
4585 break;
4586 }
4587 }
4588
4589
4590
4591 if (!found && retrieve_from_waiting_list(0, np, cmd))
4592 found = 1;
4593
4594
4595
4596 reset_waiting_list(np);
4597
4598
4599
4600 ncr_wakeup(np, HS_RESET);
4601
4602
4603
4604
4605
4606
4607 if (!found && sync_reset && !retrieve_from_waiting_list(0, np, cmd)) {
4608 set_host_byte(cmd, DID_RESET);
4609 ncr_queue_done_cmd(np, cmd);
4610 }
4611
4612 return SUCCESS;
4613}
4614
4615#if 0
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625static int ncr_abort_command (struct ncb *np, struct scsi_cmnd *cmd)
4626{
4627
4628 struct ccb *cp;
4629 int found;
4630 int retv;
4631
4632
4633
4634
4635 if (remove_from_waiting_list(np, cmd)) {
4636 set_host_byte(cmd, DID_ABORT);
4637 ncr_queue_done_cmd(np, cmd);
4638 return SCSI_ABORT_SUCCESS;
4639 }
4640
4641
4642
4643
4644 for (found=0, cp=np->ccb; cp; cp=cp->link_ccb) {
4645
4646
4647
4648 if (cp->host_status == HS_IDLE) continue;
4649 if (cp->cmd == cmd) {
4650 found = 1;
4651 break;
4652 }
4653 }
4654
4655 if (!found) {
4656 return SCSI_ABORT_NOT_RUNNING;
4657 }
4658
4659 if (np->settle_time) {
4660 return SCSI_ABORT_SNOOZE;
4661 }
4662
4663
4664
4665
4666
4667
4668 switch(cp->host_status) {
4669 case HS_BUSY:
4670 case HS_NEGOTIATE:
4671 printk ("%s: abort ccb=%p (cancel)\n", ncr_name (np), cp);
4672 cp->start.schedule.l_paddr =
4673 cpu_to_scr(NCB_SCRIPTH_PHYS (np, cancel));
4674 retv = SCSI_ABORT_PENDING;
4675 break;
4676 case HS_DISCONNECT:
4677 cp->restart.schedule.l_paddr =
4678 cpu_to_scr(NCB_SCRIPTH_PHYS (np, abort));
4679 retv = SCSI_ABORT_PENDING;
4680 break;
4681 default:
4682 retv = SCSI_ABORT_NOT_RUNNING;
4683 break;
4684
4685 }
4686
4687
4688
4689
4690
4691
4692 OUTB (nc_istat, SIGP);