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