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
94
95
96
97
98
99
100
101
102
103
104
105
106#define SCSI_NCR_DRIVER_NAME "ncr53c8xx-3.4.3b-20010512"
107
108#define SCSI_NCR_DEBUG_FLAGS (0)
109
110
111
112
113
114
115
116
117#define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))
118
119#include <linux/module.h>
120#include <asm/dma.h>
121#include <asm/io.h>
122#include <asm/system.h>
123#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,17)
124#include <linux/spinlock.h>
125#elif LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93)
126#include <asm/spinlock.h>
127#endif
128#include <linux/delay.h>
129#include <linux/signal.h>
130#include <linux/sched.h>
131#include <linux/errno.h>
132#include <linux/pci.h>
133#include <linux/string.h>
134#include <linux/mm.h>
135#include <linux/ioport.h>
136#include <linux/time.h>
137#include <linux/timer.h>
138#include <linux/stat.h>
139
140#include <linux/version.h>
141#include <linux/blk.h>
142
143#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,35)
144#include <linux/init.h>
145#endif
146
147#ifndef __init
148#define __init
149#endif
150#ifndef __initdata
151#define __initdata
152#endif
153
154#if LINUX_VERSION_CODE <= LinuxVersionCode(2,1,92)
155#include <linux/bios32.h>
156#endif
157
158#include "scsi.h"
159#include "hosts.h"
160#include "constants.h"
161#include "sd.h"
162
163#include <linux/types.h>
164
165
166
167
168#ifndef BITS_PER_LONG
169#if (~0UL) == 0xffffffffUL
170#define BITS_PER_LONG 32
171#else
172#define BITS_PER_LONG 64
173#endif
174#endif
175
176
177
178
179
180typedef u32 u_int32;
181typedef u64 u_int64;
182typedef u_long vm_offset_t;
183#include "ncr53c8xx.h"
184
185
186
187
188
189
190#if 0
191#define SCSI_NCR_INTEGRITY_CHECKING
192#endif
193
194#define NAME53C "ncr53c"
195#define NAME53C8XX "ncr53c8xx"
196#define DRIVER_SMP_LOCK ncr53c8xx_lock
197
198#include "sym53c8xx_comm.h"
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217#define SCSI_NCR_CCB_DONE_SUPPORT
218#ifdef SCSI_NCR_CCB_DONE_SUPPORT
219
220#define MAX_DONE 24
221#define CCB_DONE_EMPTY 0xffffffffUL
222
223
224#if BITS_PER_LONG == 32
225#define CCB_DONE_VALID(cp) (((u_long) cp) != CCB_DONE_EMPTY)
226
227
228#else
229#define CCB_DONE_VALID(cp) \
230 ((((u_long) cp) & 0xffffffff00000000ul) && \
231 (((u_long) cp) & 0xfffffffful) != CCB_DONE_EMPTY)
232#endif
233
234#endif
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249#ifndef SCSI_NCR_MYADDR
250#define SCSI_NCR_MYADDR (7)
251#endif
252
253
254
255
256
257
258#ifndef SCSI_NCR_MAX_TAGS
259#define SCSI_NCR_MAX_TAGS (8)
260#endif
261
262
263
264
265
266#if SCSI_NCR_MAX_TAGS > 64
267#define MAX_TAGS (64)
268#else
269#define MAX_TAGS SCSI_NCR_MAX_TAGS
270#endif
271
272#define NO_TAG (255)
273
274
275
276
277#if MAX_TAGS > 32
278typedef u_int64 tagmap_t;
279#else
280typedef u_int32 tagmap_t;
281#endif
282
283
284
285
286
287
288
289
290#ifdef SCSI_NCR_MAX_TARGET
291#define MAX_TARGET (SCSI_NCR_MAX_TARGET)
292#else
293#define MAX_TARGET (16)
294#endif
295
296
297
298
299
300
301
302
303#ifdef SCSI_NCR_MAX_LUN
304#define MAX_LUN SCSI_NCR_MAX_LUN
305#else
306#define MAX_LUN (1)
307#endif
308
309
310
311
312
313#ifndef SCSI_NCR_MIN_ASYNC
314#define SCSI_NCR_MIN_ASYNC (40)
315#endif
316
317
318
319
320
321
322
323
324#ifdef SCSI_NCR_CAN_QUEUE
325#define MAX_START (SCSI_NCR_CAN_QUEUE + 4)
326#else
327#define MAX_START (MAX_TARGET + 7 * MAX_TAGS)
328#endif
329
330
331
332
333
334
335#if MAX_START > 250
336#undef MAX_START
337#define MAX_START 250
338#endif
339
340
341
342
343
344
345
346
347
348
349#define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)
350
351#if (MAX_SCATTER > 80)
352#define MAX_SCATTERL 80
353#define MAX_SCATTERH (MAX_SCATTER - MAX_SCATTERL)
354#else
355#define MAX_SCATTERL (MAX_SCATTER-1)
356#define MAX_SCATTERH 1
357#endif
358
359
360
361
362
363#define NCR_SNOOP_TIMEOUT (1000000)
364
365
366
367
368
369
370
371
372
373static struct Scsi_Host *first_host = NULL;
374static Scsi_Host_Template *the_template = NULL;
375
376
377
378
379
380#define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))
381
382static void ncr53c8xx_select_queue_depths(
383 struct Scsi_Host *host, struct scsi_device *devlist);
384static void ncr53c8xx_intr(int irq, void *dev_id, struct pt_regs * regs);
385static void ncr53c8xx_timeout(unsigned long np);
386
387#define initverbose (driver_setup.verbose)
388#define bootverbose (np->verbose)
389
390#ifdef SCSI_NCR_NVRAM_SUPPORT
391static u_char Tekram_sync[16] __initdata =
392 {25,31,37,43, 50,62,75,125, 12,15,18,21, 6,7,9,10};
393#endif
394
395
396
397
398
399
400
401
402#define HS_IDLE (0)
403#define HS_BUSY (1)
404#define HS_NEGOTIATE (2)
405#define HS_DISCONNECT (3)
406
407#define HS_DONEMASK (0x80)
408#define HS_COMPLETE (4|HS_DONEMASK)
409#define HS_SEL_TIMEOUT (5|HS_DONEMASK)
410#define HS_RESET (6|HS_DONEMASK)
411#define HS_ABORTED (7|HS_DONEMASK)
412#define HS_TIMEOUT (8|HS_DONEMASK)
413#define HS_FAIL (9|HS_DONEMASK)
414#define HS_UNEXPECTED (10|HS_DONEMASK)
415
416
417
418
419
420
421
422#define HS_INVALMASK (0x40)
423#define HS_SELECTING (0|HS_INVALMASK)
424#define HS_IN_RESELECT (1|HS_INVALMASK)
425#define HS_STARTING (2|HS_INVALMASK)
426
427
428
429
430
431#define HS_SKIPMASK (0x20)
432
433
434
435
436
437
438
439
440#define SIR_BAD_STATUS (1)
441#define SIR_XXXXXXXXXX (2)
442#define SIR_NEGO_SYNC (3)
443#define SIR_NEGO_WIDE (4)
444#define SIR_NEGO_FAILED (5)
445#define SIR_NEGO_PROTO (6)
446#define SIR_REJECT_RECEIVED (7)
447#define SIR_REJECT_SENT (8)
448#define SIR_IGN_RESIDUE (9)
449#define SIR_MISSING_SAVE (10)
450#define SIR_RESEL_NO_MSG_IN (11)
451#define SIR_RESEL_NO_IDENTIFY (12)
452#define SIR_RESEL_BAD_LUN (13)
453#define SIR_RESEL_BAD_TARGET (14)
454#define SIR_RESEL_BAD_I_T_L (15)
455#define SIR_RESEL_BAD_I_T_L_Q (16)
456#define SIR_DONE_OVERFLOW (17)
457#define SIR_MAX (17)
458
459
460
461
462
463
464
465
466
467#define XE_OK (0)
468#define XE_EXTRA_DATA (1)
469#define XE_BAD_PHASE (2)
470
471
472
473
474
475
476
477
478
479#define NS_NOCHANGE (0)
480#define NS_SYNC (1)
481#define NS_WIDE (2)
482#define NS_PPR (4)
483
484
485
486
487
488
489
490
491
492
493#define QUIRK_AUTOSAVE (0x01)
494#define QUIRK_NOMSG (0x02)
495#define QUIRK_NOSYNC (0x10)
496#define QUIRK_NOWIDE16 (0x20)
497
498
499
500
501
502
503
504
505#define INQ7_QUEUE (0x02)
506#define INQ7_SYNC (0x10)
507#define INQ7_WIDE16 (0x20)
508
509
510
511
512
513
514
515
516#define CCB_MAGIC (0xf2691ad2)
517
518
519
520
521
522
523
524
525struct tcb;
526struct lcb;
527struct ccb;
528struct ncb;
529struct script;
530
531typedef struct ncb * ncb_p;
532typedef struct tcb * tcb_p;
533typedef struct lcb * lcb_p;
534typedef struct ccb * ccb_p;
535
536struct link {
537 ncrcmd l_cmd;
538 ncrcmd l_paddr;
539};
540
541struct usrcmd {
542 u_long target;
543 u_long lun;
544 u_long data;
545 u_long cmd;
546};
547
548#define UC_SETSYNC 10
549#define UC_SETTAGS 11
550#define UC_SETDEBUG 12
551#define UC_SETORDER 13
552#define UC_SETWIDE 14
553#define UC_SETFLAG 15
554#define UC_SETVERBOSE 17
555
556#define UF_TRACE (0x01)
557#define UF_NODISC (0x02)
558#define UF_NOSCAN (0x04)
559
560
561
562
563
564
565
566struct tcb {
567
568
569
570
571
572
573
574
575 struct link jump_tcb;
576
577
578
579
580
581
582
583
584
585 ncrcmd getscr[6];
586
587
588
589
590
591
592
593 struct link call_lun;
594
595
596
597
598
599
600
601
602
603
604
605 struct link jump_lcb[4];
606 lcb_p lp[MAX_LUN];
607 u_char inq_done;
608 u_char inq_byte7;
609
610
611
612
613
614
615
616 ccb_p nego_cp;
617
618
619
620
621
622 u_long transfers;
623 u_long bytes;
624
625
626
627
628
629 u_char minsync;
630 u_char sval;
631 u_short period;
632 u_char maxoffs;
633 u_char quirks;
634 u_char widedone;
635 u_char wval;
636
637#ifdef SCSI_NCR_INTEGRITY_CHECKING
638 u_char ic_min_sync;
639 u_char ic_max_width;
640 u_char ic_maximums_set;
641 u_char ic_done;
642#endif
643
644
645
646
647
648
649 u_char usrsync;
650 u_char usrwide;
651 u_char usrtags;
652 u_char usrflag;
653};
654
655
656
657
658
659
660
661struct lcb {
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676 struct link jump_lcb;
677 ncrcmd load_jump_ccb[3];
678 struct link jump_tag;
679 ncrcmd p_jump_ccb;
680
681
682
683
684
685
686
687
688
689 u_int32 jump_ccb_0;
690 u_int32 *jump_ccb;
691
692
693
694
695
696 XPT_QUEHEAD free_ccbq;
697 XPT_QUEHEAD busy_ccbq;
698 XPT_QUEHEAD wait_ccbq;
699 XPT_QUEHEAD skip_ccbq;
700 u_char actccbs;
701 u_char busyccbs;
702 u_char queuedccbs;
703 u_char queuedepth;
704 u_char scdev_depth;
705 u_char maxnxs;
706
707
708
709
710
711
712
713 u_char ia_tag;
714 u_char if_tag;
715 u_char cb_tags[MAX_TAGS];
716 u_char usetags;
717 u_char maxtags;
718 u_char numtags;
719 u_char inq_byte7;
720
721
722
723
724
725
726
727
728
729 u_short num_good;
730 tagmap_t tags_umap;
731 tagmap_t tags_smap;
732 u_long tags_stime;
733 ccb_p held_ccb;
734};
735
736
737
738
739
740
741
742
743
744
745
746
747
748struct launch {
749
750
751
752
753
754 ncrcmd setup_dsa[3];
755 struct link schedule;
756 ncrcmd p_phys;
757};
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773struct head {
774
775
776
777
778
779
780
781
782 u_int32 savep;
783 u_int32 lastp;
784 u_int32 goalp;
785
786
787
788
789
790
791
792 u_int32 wlastp;
793 u_int32 wgoalp;
794
795
796
797
798
799 ccb_p cp;
800
801
802
803
804
805 u_char scr_st[4];
806 u_char status[4];
807
808};
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836#define QU_REG scr0
837#define HS_REG scr1
838#define HS_PRT nc_scr1
839#define SS_REG scr2
840#define SS_PRT nc_scr2
841#define PS_REG scr3
842
843
844
845
846#define actualquirks phys.header.status[0]
847#define host_status phys.header.status[1]
848#define scsi_status phys.header.status[2]
849#define parity_status phys.header.status[3]
850
851
852
853
854#define xerr_st header.scr_st[0]
855#define sync_st header.scr_st[1]
856#define nego_st header.scr_st[2]
857#define wide_st header.scr_st[3]
858
859
860
861
862#define xerr_status phys.xerr_st
863#define nego_status phys.nego_st
864
865#if 0
866#define sync_status phys.sync_st
867#define wide_status phys.wide_st
868#endif
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886struct dsb {
887
888
889
890
891
892 struct head header;
893
894
895
896
897
898 struct scr_tblsel select;
899 struct scr_tblmove smsg ;
900 struct scr_tblmove cmd ;
901 struct scr_tblmove sense ;
902 struct scr_tblmove data [MAX_SCATTER];
903};
904
905
906
907
908
909
910
911
912struct ccb {
913
914
915
916
917
918
919
920 struct dsb phys;
921
922
923
924
925
926
927
928 struct launch start;
929
930
931
932
933
934
935
936 struct launch restart;
937
938
939
940
941
942
943
944
945 ncrcmd patch[8];
946
947
948
949
950
951
952 Scsi_Cmnd *cmd;
953 u_char cdb_buf[16];
954 u_char sense_buf[64];
955 int data_len;
956
957
958
959
960
961
962
963
964
965
966
967 u_char scsi_smsg [8];
968 u_char scsi_smsg2[8];
969
970
971
972
973
974 u_long p_ccb;
975 u_char sensecmd[6];
976 u_char tag;
977
978 u_char target;
979 u_char lun;
980 u_char queued;
981 u_char auto_sense;
982 ccb_p link_ccb;
983 XPT_QUEHEAD link_ccbq;
984 u_int32 startp;
985 u_long magic;
986};
987
988#define CCB_PHYS(cp,lbl) (cp->p_ccb + offsetof(struct ccb, lbl))
989
990
991
992
993
994
995
996
997struct ncb {
998
999
1000
1001
1002
1003
1004
1005 struct head header;
1006
1007
1008
1009
1010
1011 Scsi_Cmnd *waiting_list;
1012
1013 Scsi_Cmnd *done_list;
1014
1015#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93)
1016 spinlock_t smp_lock;
1017#endif
1018
1019
1020
1021
1022
1023 int unit;
1024 char chip_name[8];
1025 char inst_name[16];
1026
1027
1028
1029
1030
1031
1032
1033 u_char sv_scntl0, sv_scntl3, sv_dmode, sv_dcntl, sv_ctest3, sv_ctest4,
1034 sv_ctest5, sv_gpcntl, sv_stest2, sv_stest4;
1035
1036
1037
1038
1039
1040
1041
1042 u_char rv_scntl0, rv_scntl3, rv_dmode, rv_dcntl, rv_ctest3, rv_ctest4,
1043 rv_ctest5, rv_stest2;
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056 struct link jump_tcb[4];
1057 struct tcb target[MAX_TARGET];
1058
1059
1060
1061
1062
1063 vm_offset_t vaddr;
1064 vm_offset_t paddr;
1065 vm_offset_t paddr2;
1066 volatile
1067 struct ncr_reg *reg;
1068
1069
1070
1071
1072
1073
1074
1075 struct script *script0;
1076 struct scripth *scripth0;
1077 struct scripth *scripth;
1078 u_long p_script;
1079 u_long p_scripth;
1080
1081
1082
1083
1084
1085 pcidev_t pdev;
1086 u_short device_id;
1087 u_char revision_id;
1088 u_char bus;
1089 u_char device_fn;
1090 u_long base_io;
1091 u_int irq;
1092 u_int features;
1093 u_char myaddr;
1094 u_char maxburst;
1095 u_char maxwide;
1096 u_char minsync;
1097 u_char maxsync;
1098 u_char maxoffs;
1099 u_char multiplier;
1100 u_char clock_divn;
1101 u_long clock_khz;
1102
1103
1104
1105
1106
1107
1108
1109 u_short squeueput;
1110 u_short actccbs;
1111 u_short queuedccbs;
1112 u_short queuedepth;
1113
1114
1115
1116
1117
1118 struct timer_list timer;
1119 u_long lasttime;
1120 u_long settle_time;
1121
1122
1123
1124
1125
1126 struct ncr_reg regdump;
1127 u_long regtime;
1128
1129
1130
1131
1132
1133
1134
1135 u_char msgout[8];
1136 u_char msgin [8];
1137 u_int32 lastmsg;
1138 u_char scratch;
1139
1140
1141
1142
1143
1144 u_char disc;
1145 u_char scsi_mode;
1146 u_char order;
1147 u_char verbose;
1148 int ncr_cache;
1149 u_long p_ncb;
1150
1151
1152
1153
1154
1155#ifdef SCSI_NCR_CCB_DONE_SUPPORT
1156 struct ccb *(ccb_done[MAX_DONE]);
1157 int ccb_done_ic;
1158#endif
1159
1160
1161
1162
1163 struct ccb *ccb;
1164 struct usrcmd user;
1165 u_char release_stage;
1166
1167#ifdef SCSI_NCR_INTEGRITY_CHECKING
1168
1169
1170
1171
1172 unsigned char check_integrity;
1173
1174 unsigned char check_integ_par;
1175
1176#endif
1177};
1178
1179#define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
1180#define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207struct script {
1208 ncrcmd start [ 5];
1209 ncrcmd startpos [ 1];
1210 ncrcmd select [ 6];
1211 ncrcmd select2 [ 9];
1212 ncrcmd loadpos [ 4];
1213 ncrcmd send_ident [ 9];
1214 ncrcmd prepare [ 6];
1215 ncrcmd prepare2 [ 7];
1216 ncrcmd command [ 6];
1217 ncrcmd dispatch [ 32];
1218 ncrcmd clrack [ 4];
1219 ncrcmd no_data [ 17];
1220 ncrcmd status [ 8];
1221 ncrcmd msg_in [ 2];
1222 ncrcmd msg_in2 [ 16];
1223 ncrcmd msg_bad [ 4];
1224 ncrcmd setmsg [ 7];
1225 ncrcmd cleanup [ 6];
1226 ncrcmd complete [ 9];
1227 ncrcmd cleanup_ok [ 8];
1228 ncrcmd cleanup0 [ 1];
1229#ifndef SCSI_NCR_CCB_DONE_SUPPORT
1230 ncrcmd signal [ 12];
1231#else
1232 ncrcmd signal [ 9];
1233 ncrcmd done_pos [ 1];
1234 ncrcmd done_plug [ 2];
1235 ncrcmd done_end [ 7];
1236#endif
1237 ncrcmd save_dp [ 7];
1238 ncrcmd restore_dp [ 5];
1239 ncrcmd disconnect [ 17];
1240 ncrcmd msg_out [ 9];
1241 ncrcmd msg_out_done [ 7];
1242 ncrcmd idle [ 2];
1243 ncrcmd reselect [ 8];
1244 ncrcmd reselected [ 8];
1245 ncrcmd resel_dsa [ 6];
1246 ncrcmd loadpos1 [ 4];
1247 ncrcmd resel_lun [ 6];
1248 ncrcmd resel_tag [ 6];
1249 ncrcmd jump_to_nexus [ 4];
1250 ncrcmd nexus_indirect [ 4];
1251 ncrcmd resel_notag [ 4];
1252 ncrcmd data_in [MAX_SCATTERL * 4];
1253 ncrcmd data_in2 [ 4];
1254 ncrcmd data_out [MAX_SCATTERL * 4];
1255 ncrcmd data_out2 [ 4];
1256};
1257
1258
1259
1260
1261struct scripth {
1262 ncrcmd tryloop [MAX_START*2];
1263 ncrcmd tryloop2 [ 2];
1264#ifdef SCSI_NCR_CCB_DONE_SUPPORT
1265 ncrcmd done_queue [MAX_DONE*5];
1266 ncrcmd done_queue2 [ 2];
1267#endif
1268 ncrcmd select_no_atn [ 8];
1269 ncrcmd cancel [ 4];
1270 ncrcmd skip [ 9];
1271 ncrcmd skip2 [ 19];
1272 ncrcmd par_err_data_in [ 6];
1273 ncrcmd par_err_other [ 4];
1274 ncrcmd msg_reject [ 8];
1275 ncrcmd msg_ign_residue [ 24];
1276 ncrcmd msg_extended [ 10];
1277 ncrcmd msg_ext_2 [ 10];
1278 ncrcmd msg_wdtr [ 14];
1279 ncrcmd send_wdtr [ 7];
1280 ncrcmd msg_ext_3 [ 10];
1281 ncrcmd msg_sdtr [ 14];
1282 ncrcmd send_sdtr [ 7];
1283 ncrcmd nego_bad_phase [ 4];
1284 ncrcmd msg_out_abort [ 10];
1285 ncrcmd hdata_in [MAX_SCATTERH * 4];
1286 ncrcmd hdata_in2 [ 2];
1287 ncrcmd hdata_out [MAX_SCATTERH * 4];
1288 ncrcmd hdata_out2 [ 2];
1289 ncrcmd reset [ 4];
1290 ncrcmd aborttag [ 4];
1291 ncrcmd abort [ 2];
1292 ncrcmd abort_resel [ 20];
1293 ncrcmd resend_ident [ 4];
1294 ncrcmd clratn_go_on [ 3];
1295 ncrcmd nxtdsp_go_on [ 1];
1296 ncrcmd sdata_in [ 8];
1297 ncrcmd data_io [ 18];
1298 ncrcmd bad_identify [ 12];
1299 ncrcmd bad_i_t_l [ 4];
1300 ncrcmd bad_i_t_l_q [ 4];
1301 ncrcmd bad_target [ 8];
1302 ncrcmd bad_status [ 8];
1303 ncrcmd start_ram [ 4];
1304 ncrcmd start_ram0 [ 4];
1305 ncrcmd sto_restart [ 5];
1306 ncrcmd snooptest [ 9];
1307 ncrcmd snoopend [ 2];
1308};
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319static void ncr_alloc_ccb (ncb_p np, u_char tn, u_char ln);
1320static void ncr_complete (ncb_p np, ccb_p cp);
1321static void ncr_exception (ncb_p np);
1322static void ncr_free_ccb (ncb_p np, ccb_p cp);
1323static void ncr_init_ccb (ncb_p np, ccb_p cp);
1324static void ncr_init_tcb (ncb_p np, u_char tn);
1325static lcb_p ncr_alloc_lcb (ncb_p np, u_char tn, u_char ln);
1326static lcb_p ncr_setup_lcb (ncb_p np, u_char tn, u_char ln,
1327 u_char *inq_data);
1328static void ncr_getclock (ncb_p np, int mult);
1329static void ncr_selectclock (ncb_p np, u_char scntl3);
1330static ccb_p ncr_get_ccb (ncb_p np, u_char tn, u_char ln);
1331static void ncr_init (ncb_p np, int reset, char * msg, u_long code);
1332static int ncr_int_sbmc (ncb_p np);
1333static int ncr_int_par (ncb_p np);
1334static void ncr_int_ma (ncb_p np);
1335static void ncr_int_sir (ncb_p np);
1336static void ncr_int_sto (ncb_p np);
1337static u_long ncr_lookup (char* id);
1338static void ncr_negotiate (struct ncb* np, struct tcb* tp);
1339static int ncr_prepare_nego(ncb_p np, ccb_p cp, u_char *msgptr);
1340#ifdef SCSI_NCR_INTEGRITY_CHECKING
1341static int ncr_ic_nego(ncb_p np, ccb_p cp, Scsi_Cmnd *cmd, u_char *msgptr);
1342#endif
1343
1344static void ncr_script_copy_and_bind
1345 (ncb_p np, ncrcmd *src, ncrcmd *dst, int len);
1346static void ncr_script_fill (struct script * scr, struct scripth * scripth);
1347static int ncr_scatter (ncb_p np, ccb_p cp, Scsi_Cmnd *cmd);
1348static void ncr_getsync (ncb_p np, u_char sfac, u_char *fakp, u_char *scntl3p);
1349static void ncr_setsync (ncb_p np, ccb_p cp, u_char scntl3, u_char sxfer);
1350static void ncr_setup_tags (ncb_p np, u_char tn, u_char ln);
1351static void ncr_setwide (ncb_p np, ccb_p cp, u_char wide, u_char ack);
1352static int ncr_show_msg (u_char * msg);
1353static void ncr_print_msg (ccb_p cp, char *label, u_char *msg);
1354static int ncr_snooptest (ncb_p np);
1355static void ncr_timeout (ncb_p np);
1356static void ncr_wakeup (ncb_p np, u_long code);
1357static void ncr_wakeup_done (ncb_p np);
1358static void ncr_start_next_ccb (ncb_p np, lcb_p lp, int maxn);
1359static void ncr_put_start_queue(ncb_p np, ccb_p cp);
1360static void ncr_start_reset (ncb_p np);
1361static int ncr_reset_scsi_bus (ncb_p np, int enab_int, int settle_delay);
1362
1363#ifdef SCSI_NCR_USER_COMMAND_SUPPORT
1364static void ncr_usercmd (ncb_p np);
1365#endif
1366
1367static int ncr_attach (Scsi_Host_Template *tpnt, int unit, ncr_device *device);
1368
1369static void insert_into_waiting_list(ncb_p np, Scsi_Cmnd *cmd);
1370static Scsi_Cmnd *retrieve_from_waiting_list(int to_remove, ncb_p np, Scsi_Cmnd *cmd);
1371static void process_waiting_list(ncb_p np, int sts);
1372
1373#define remove_from_waiting_list(np, cmd) \
1374 retrieve_from_waiting_list(1, (np), (cmd))
1375#define requeue_waiting_list(np) process_waiting_list((np), DID_OK)
1376#define reset_waiting_list(np) process_waiting_list((np), DID_RESET)
1377
1378static inline char *ncr_name (ncb_p np)
1379{
1380 return np->inst_name;
1381}
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403#define RELOC_SOFTC 0x40000000
1404#define RELOC_LABEL 0x50000000
1405#define RELOC_REGISTER 0x60000000
1406#if 0
1407#define RELOC_KVAR 0x70000000
1408#endif
1409#define RELOC_LABELH 0x80000000
1410#define RELOC_MASK 0xf0000000
1411
1412#define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
1413#define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
1414#define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
1415#define RADDR(label) (RELOC_REGISTER | REG(label))
1416#define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
1417#if 0
1418#define KVAR(which) (RELOC_KVAR | (which))
1419#endif
1420
1421#if 0
1422#define SCRIPT_KVAR_JIFFIES (0)
1423#define SCRIPT_KVAR_FIRST SCRIPT_KVAR_JIFFIES
1424#define SCRIPT_KVAR_LAST SCRIPT_KVAR_JIFFIES
1425
1426
1427
1428
1429static void *script_kvars[] __initdata =
1430 { (void *)&jiffies };
1431#endif
1432
1433static struct script script0 __initdata = {
1434 {
1435
1436
1437
1438
1439 SCR_NO_OP,
1440 0,
1441
1442
1443
1444 SCR_FROM_REG (ctest2),
1445 0,
1446
1447
1448
1449
1450
1451 SCR_JUMP,
1452},{
1453 PADDRH(tryloop),
1454
1455},{
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468 SCR_CLR (SCR_TRG),
1469 0,
1470 SCR_LOAD_REG (HS_REG, HS_SELECTING),
1471 0,
1472
1473
1474
1475
1476 SCR_SEL_TBL_ATN ^ offsetof (struct dsb, select),
1477 PADDR (reselect),
1478
1479},{
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508 SCR_JUMPR ^ IFFALSE (WHEN (SCR_MSG_OUT)),
1509 0,
1510
1511
1512
1513
1514 SCR_COPY (4),
1515 RADDR (temp),
1516 PADDR (startpos),
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526 SCR_COPY_F (4),
1527 RADDR (dsa),
1528 PADDR (loadpos),
1529
1530
1531
1532 SCR_COPY (sizeof (struct head)),
1533
1534
1535
1536},{
1537 0,
1538 NADDR (header),
1539
1540
1541
1542
1543 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
1544 PADDR (prepare),
1545
1546},{
1547
1548
1549
1550
1551
1552 SCR_MOVE_TBL ^ SCR_MSG_OUT,
1553 offsetof (struct dsb, smsg),
1554 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_OUT)),
1555 PADDRH (resend_ident),
1556 SCR_LOAD_REG (scratcha, 0x80),
1557 0,
1558 SCR_COPY (1),
1559 RADDR (scratcha),
1560 NADDR (lastmsg),
1561},{
1562
1563
1564
1565
1566 SCR_COPY (4),
1567 NADDR (header.savep),
1568 RADDR (temp),
1569
1570
1571
1572 SCR_COPY (4),
1573 NADDR (header.status),
1574 RADDR (scr0),
1575},{
1576
1577
1578
1579 SCR_LOAD_REG (scratcha, M_NOOP),
1580 0,
1581 SCR_COPY (1),
1582 RADDR (scratcha),
1583 NADDR (msgout),
1584#if 0
1585 SCR_COPY (1),
1586 RADDR (scratcha),
1587 NADDR (msgin),
1588#endif
1589
1590
1591
1592
1593 SCR_JUMP ^ IFFALSE (WHEN (SCR_COMMAND)),
1594 PADDR (dispatch),
1595
1596},{
1597
1598
1599
1600 SCR_MOVE_TBL ^ SCR_COMMAND,
1601 offsetof (struct dsb, cmd),
1602
1603
1604
1605
1606
1607 SCR_FROM_REG (HS_REG),
1608 0,
1609 SCR_INT ^ IFTRUE (DATA (HS_NEGOTIATE)),
1610 SIR_NEGO_FAILED,
1611
1612},{
1613
1614
1615
1616
1617
1618 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
1619 PADDR (msg_in),
1620
1621 SCR_RETURN ^ IFTRUE (IF (SCR_DATA_OUT)),
1622 0,
1623
1624
1625
1626
1627
1628
1629
1630 SCR_JUMPR ^ IFFALSE (IF (SCR_DATA_IN)),
1631 20,
1632 SCR_COPY (4),
1633 RADDR (scratcha),
1634 RADDR (scratcha),
1635 SCR_RETURN,
1636 0,
1637 SCR_JUMP ^ IFTRUE (IF (SCR_STATUS)),
1638 PADDR (status),
1639 SCR_JUMP ^ IFTRUE (IF (SCR_COMMAND)),
1640 PADDR (command),
1641 SCR_JUMP ^ IFTRUE (IF (SCR_MSG_OUT)),
1642 PADDR (msg_out),
1643
1644
1645
1646 SCR_LOAD_REG (scratcha, XE_BAD_PHASE),
1647 0,
1648 SCR_COPY (1),
1649 RADDR (scratcha),
1650 NADDR (xerr_st),
1651 SCR_JUMPR ^ IFFALSE (IF (SCR_ILG_OUT)),
1652 8,
1653 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT,
1654 NADDR (scratch),
1655 SCR_JUMPR ^ IFFALSE (IF (SCR_ILG_IN)),
1656 8,
1657 SCR_MOVE_ABS (1) ^ SCR_ILG_IN,
1658 NADDR (scratch),
1659 SCR_JUMP,
1660 PADDR (dispatch),
1661
1662},{
1663
1664
1665
1666 SCR_CLR (SCR_ACK),
1667 0,
1668 SCR_JUMP,
1669 PADDR (dispatch),
1670
1671},{
1672
1673
1674
1675
1676
1677 SCR_LOAD_REG (scratcha, XE_EXTRA_DATA),
1678 0,
1679 SCR_COPY (1),
1680 RADDR (scratcha),
1681 NADDR (xerr_st),
1682
1683
1684
1685 SCR_JUMPR ^ IFFALSE (WHEN (SCR_DATA_OUT)),
1686 8,
1687 SCR_MOVE_ABS (1) ^ SCR_DATA_OUT,
1688 NADDR (scratch),
1689 SCR_JUMPR ^ IFFALSE (IF (SCR_DATA_IN)),
1690 8,
1691 SCR_MOVE_ABS (1) ^ SCR_DATA_IN,
1692 NADDR (scratch),
1693
1694
1695
1696 SCR_CALL,
1697 PADDR (dispatch),
1698 SCR_JUMP,
1699 PADDR (no_data),
1700
1701},{
1702
1703
1704
1705 SCR_MOVE_ABS (1) ^ SCR_STATUS,
1706 NADDR (scratch),
1707
1708
1709
1710
1711 SCR_TO_REG (SS_REG),
1712 0,
1713 SCR_LOAD_REG (HS_REG, HS_COMPLETE),
1714 0,
1715 SCR_JUMP,
1716 PADDR (dispatch),
1717},{
1718
1719
1720
1721
1722
1723
1724
1725 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
1726 NADDR (msgin[0]),
1727},{
1728
1729
1730
1731 SCR_JUMP ^ IFTRUE (DATA (M_COMPLETE)),
1732 PADDR (complete),
1733 SCR_JUMP ^ IFTRUE (DATA (M_DISCONNECT)),
1734 PADDR (disconnect),
1735 SCR_JUMP ^ IFTRUE (DATA (M_SAVE_DP)),
1736 PADDR (save_dp),
1737 SCR_JUMP ^ IFTRUE (DATA (M_RESTORE_DP)),
1738 PADDR (restore_dp),
1739 SCR_JUMP ^ IFTRUE (DATA (M_EXTENDED)),
1740 PADDRH (msg_extended),
1741 SCR_JUMP ^ IFTRUE (DATA (M_NOOP)),
1742 PADDR (clrack),
1743 SCR_JUMP ^ IFTRUE (DATA (M_REJECT)),
1744 PADDRH (msg_reject),
1745 SCR_JUMP ^ IFTRUE (DATA (M_IGN_RESIDUE)),
1746 PADDRH (msg_ign_residue),
1747
1748
1749
1750
1751
1752
1753
1754},{
1755
1756
1757
1758 SCR_INT,
1759 SIR_REJECT_SENT,
1760 SCR_LOAD_REG (scratcha, M_REJECT),
1761 0,
1762},{
1763 SCR_COPY (1),
1764 RADDR (scratcha),
1765 NADDR (msgout),
1766 SCR_SET (SCR_ATN),
1767 0,
1768 SCR_JUMP,
1769 PADDR (clrack),
1770},{
1771
1772
1773
1774
1775
1776
1777 SCR_FROM_REG (dsa),
1778 0,
1779 SCR_JUMP ^ IFTRUE (DATA (0xff)),
1780 PADDR (start),
1781
1782
1783
1784
1785 SCR_JUMP,
1786 PADDR (cleanup_ok),
1787
1788},{
1789
1790
1791
1792
1793
1794 SCR_COPY (4),
1795 RADDR (temp),
1796 NADDR (header.lastp),
1797
1798
1799
1800
1801
1802
1803
1804
1805 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
1806 0,
1807
1808
1809
1810 SCR_CLR (SCR_ACK|SCR_ATN),
1811 0,
1812
1813
1814
1815 SCR_WAIT_DISC,
1816 0,
1817},{
1818
1819
1820
1821 SCR_COPY (4),
1822 RADDR (scr0),
1823 NADDR (header.status),
1824
1825
1826
1827 SCR_COPY_F (4),
1828 RADDR (dsa),
1829 PADDR (cleanup0),
1830 SCR_COPY (sizeof (struct head)),
1831 NADDR (header),
1832},{
1833 0,
1834},{
1835
1836
1837
1838 SCR_FROM_REG (HS_REG),
1839 0,
1840
1841
1842
1843 SCR_JUMP ^ IFTRUE (MASK (0, (HS_DONEMASK|HS_SKIPMASK))),
1844 PADDR(start),
1845
1846
1847
1848
1849 SCR_FROM_REG (SS_REG),
1850 0,
1851 SCR_CALL ^ IFFALSE (DATA (S_GOOD)),
1852 PADDRH (bad_status),
1853
1854#ifndef SCSI_NCR_CCB_DONE_SUPPORT
1855
1856
1857
1858
1859 SCR_INT_FLY,
1860 0,
1861
1862
1863
1864 SCR_JUMP,
1865 PADDR(start),
1866
1867#else
1868
1869
1870
1871
1872 SCR_JUMP,
1873},{
1874 PADDRH (done_queue),
1875},{
1876 SCR_INT,
1877 SIR_DONE_OVERFLOW,
1878},{
1879 SCR_INT_FLY,
1880 0,
1881 SCR_COPY (4),
1882 RADDR (temp),
1883 PADDR (done_pos),
1884 SCR_JUMP,
1885 PADDR (start),
1886
1887#endif
1888
1889},{
1890
1891
1892
1893
1894 SCR_COPY (4),
1895 RADDR (temp),
1896 NADDR (header.savep),
1897 SCR_CLR (SCR_ACK),
1898 0,
1899 SCR_JUMP,
1900 PADDR (dispatch),
1901},{
1902
1903
1904
1905
1906 SCR_COPY (4),
1907 NADDR (header.savep),
1908 RADDR (temp),
1909 SCR_JUMP,
1910 PADDR (clrack),
1911
1912},{
1913
1914
1915
1916
1917
1918
1919 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
1920 0,
1921 SCR_CLR (SCR_ACK|SCR_ATN),
1922 0,
1923
1924
1925
1926 SCR_WAIT_DISC,
1927 0,
1928
1929
1930
1931 SCR_LOAD_REG (HS_REG, HS_DISCONNECT),
1932 0,
1933
1934
1935
1936
1937 SCR_FROM_REG (QU_REG),
1938 0,
1939 SCR_JUMP ^ IFFALSE (MASK (QUIRK_AUTOSAVE, QUIRK_AUTOSAVE)),
1940 PADDR (cleanup_ok),
1941
1942
1943
1944
1945 SCR_COPY (4),
1946 RADDR (temp),
1947 NADDR (header.savep),
1948 SCR_JUMP,
1949 PADDR (cleanup_ok),
1950
1951},{
1952
1953
1954
1955 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
1956 NADDR (msgout),
1957 SCR_COPY (1),
1958 NADDR (msgout),
1959 NADDR (lastmsg),
1960
1961
1962
1963 SCR_JUMP ^ IFTRUE (DATA (M_ABORT)),
1964 PADDRH (msg_out_abort),
1965
1966
1967
1968
1969 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_OUT)),
1970 PADDR (msg_out),
1971},{
1972
1973
1974
1975 SCR_LOAD_REG (scratcha, M_NOOP),
1976 0,
1977 SCR_COPY (4),
1978 RADDR (scratcha),
1979 NADDR (msgout),
1980
1981
1982
1983 SCR_JUMP,
1984 PADDR (dispatch),
1985},{
1986
1987
1988
1989
1990
1991
1992 SCR_NO_OP,
1993 0,
1994},{
1995
1996
1997
1998 SCR_LOAD_REG (dsa, 0xff),
1999 0,
2000 SCR_CLR (SCR_TRG),
2001 0,
2002 SCR_LOAD_REG (HS_REG, HS_IN_RESELECT),
2003 0,
2004
2005
2006
2007
2008
2009
2010 SCR_WAIT_RESEL,
2011 PADDR(start),
2012},{
2013
2014
2015
2016
2017 SCR_NO_OP,
2018 0,
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032 SCR_REG_SFBR (ssid, SCR_AND, 0x8F),
2033 0,
2034 SCR_TO_REG (sdid),
2035 0,
2036 SCR_JUMP,
2037 NADDR (jump_tcb),
2038
2039},{
2040
2041
2042
2043 SCR_CLR (SCR_ACK),
2044 0,
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054 SCR_COPY_F (4),
2055 RADDR (dsa),
2056 PADDR (loadpos1),
2057
2058
2059
2060 SCR_COPY (sizeof (struct head)),
2061
2062
2063
2064
2065},{
2066 0,
2067 NADDR (header),
2068
2069
2070
2071 SCR_JUMP,
2072 PADDR (prepare),
2073
2074},{
2075
2076
2077
2078
2079
2080 SCR_INT ^ IFFALSE (WHEN (SCR_MSG_IN)),
2081 SIR_RESEL_NO_MSG_IN,
2082
2083
2084
2085
2086
2087
2088 SCR_FROM_REG (sbdl),
2089 0,
2090
2091
2092
2093 SCR_RETURN,
2094 0,
2095},{
2096
2097
2098
2099
2100
2101
2102 SCR_MOVE_ABS (3) ^ SCR_MSG_IN,
2103 NADDR (msgin),
2104
2105
2106
2107
2108
2109
2110
2111 SCR_REG_SFBR (sidl, SCR_SHL, 0),
2112 0,
2113 SCR_SFBR_REG (temp, SCR_AND, 0xfc),
2114 0,
2115},{
2116 SCR_COPY_F (4),
2117 RADDR (temp),
2118 PADDR (nexus_indirect),
2119 SCR_COPY (4),
2120},{
2121 0,
2122 RADDR (temp),
2123 SCR_RETURN,
2124 0,
2125},{
2126
2127
2128
2129
2130 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2131 NADDR (msgin),
2132 SCR_JUMP,
2133 PADDR (jump_to_nexus),
2134},{
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
21490
2150},{
2151 SCR_CALL,
2152 PADDR (dispatch),
2153 SCR_JUMP,
2154 PADDR (no_data),
2155},{
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
21700
2171},{
2172 SCR_CALL,
2173 PADDR (dispatch),
2174 SCR_JUMP,
2175 PADDR (no_data),
2176}
2177};
2178
2179static struct scripth scripth0 __initdata = {
2180{
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
21990
2200},{
2201 SCR_JUMP,
2202 PADDRH(tryloop),
2203
2204#ifdef SCSI_NCR_CCB_DONE_SUPPORT
2205
2206},{
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
22250
2226},{
2227 SCR_JUMP,
2228 PADDRH (done_queue),
2229
2230#endif
2231},{
2232
2233
2234
2235
2236
2237 SCR_CLR (SCR_TRG),
2238 0,
2239 SCR_LOAD_REG (HS_REG, HS_SELECTING),
2240 0,
2241 SCR_SEL_TBL ^ offsetof (struct dsb, select),
2242 PADDR (reselect),
2243 SCR_JUMP,
2244 PADDR (select2),
2245
2246},{
2247
2248 SCR_LOAD_REG (scratcha, HS_ABORTED),
2249 0,
2250 SCR_JUMPR,
2251 8,
2252},{
2253 SCR_LOAD_REG (scratcha, 0),
2254 0,
2255
2256
2257
2258
2259 SCR_COPY (4),
2260 RADDR (temp),
2261 PADDR (startpos),
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271 SCR_COPY_F (4),
2272 RADDR (dsa),
2273 PADDRH (skip2),
2274
2275
2276
2277 SCR_COPY (sizeof (struct head)),
2278
2279
2280
2281},{
2282 0,
2283 NADDR (header),
2284
2285
2286
2287 SCR_COPY (4),
2288 NADDR (header.status),
2289 RADDR (scr0),
2290
2291
2292
2293 SCR_FROM_REG (scratcha),
2294 0,
2295 SCR_JUMPR ^ IFFALSE (MASK (0, HS_DONEMASK)),
2296 16,
2297 SCR_REG_REG (HS_REG, SCR_OR, HS_SKIPMASK),
2298 0,
2299 SCR_JUMPR,
2300 8,
2301 SCR_TO_REG (HS_REG),
2302 0,
2303 SCR_LOAD_REG (SS_REG, S_GOOD),
2304 0,
2305 SCR_JUMP,
2306 PADDR (cleanup_ok),
2307
2308},{
2309
2310
2311
2312 SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_IN)),
2313 PADDRH (par_err_other),
2314 SCR_MOVE_ABS (1) ^ SCR_DATA_IN,
2315 NADDR (scratch),
2316 SCR_JUMPR,
2317 -24,
2318},{
2319
2320
2321
2322 SCR_REG_REG (PS_REG, SCR_ADD, 0x01),
2323 0,
2324
2325
2326
2327 SCR_JUMP,
2328 PADDR (dispatch),
2329},{
2330
2331
2332
2333
2334
2335
2336 SCR_FROM_REG (HS_REG),
2337 0,
2338 SCR_INT ^ IFFALSE (DATA (HS_NEGOTIATE)),
2339 SIR_REJECT_RECEIVED,
2340 SCR_INT ^ IFTRUE (DATA (HS_NEGOTIATE)),
2341 SIR_NEGO_FAILED,
2342 SCR_JUMP,
2343 PADDR (clrack),
2344
2345},{
2346
2347
2348
2349 SCR_CLR (SCR_ACK),
2350 0,
2351 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2352 PADDR (dispatch),
2353
2354
2355
2356 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2357 NADDR (msgin[1]),
2358
2359
2360
2361 SCR_JUMP ^ IFTRUE (DATA (0)),
2362 PADDR (clrack),
2363
2364
2365
2366 SCR_JUMPR ^ IFFALSE (DATA (1)),
2367 40,
2368
2369
2370
2371 SCR_FROM_REG (scntl2),
2372 0,
2373 SCR_JUMPR ^ IFFALSE (MASK (WSR, WSR)),
2374 16,
2375
2376
2377
2378
2379 SCR_REG_REG (scntl2, SCR_OR, WSR),
2380 0,
2381 SCR_JUMP,
2382 PADDR (clrack),
2383
2384
2385
2386 SCR_FROM_REG (scratcha),
2387 0,
2388 SCR_INT,
2389 SIR_IGN_RESIDUE,
2390 SCR_JUMP,
2391 PADDR (clrack),
2392
2393},{
2394
2395
2396
2397 SCR_CLR (SCR_ACK),
2398 0,
2399 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2400 PADDR (dispatch),
2401
2402
2403
2404 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2405 NADDR (msgin[1]),
2406
2407
2408 SCR_JUMP ^ IFTRUE (DATA (3)),
2409 PADDRH (msg_ext_3),
2410 SCR_JUMP ^ IFFALSE (DATA (2)),
2411 PADDR (msg_bad),
2412},{
2413 SCR_CLR (SCR_ACK),
2414 0,
2415 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2416 PADDR (dispatch),
2417
2418
2419
2420 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2421 NADDR (msgin[2]),
2422 SCR_JUMP ^ IFTRUE (DATA (M_X_WIDE_REQ)),
2423 PADDRH (msg_wdtr),
2424
2425
2426
2427 SCR_JUMP,
2428 PADDR (msg_bad)
2429},{
2430 SCR_CLR (SCR_ACK),
2431 0,
2432 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2433 PADDR (dispatch),
2434
2435
2436
2437 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2438 NADDR (msgin[3]),
2439
2440
2441
2442 SCR_INT,
2443 SIR_NEGO_WIDE,
2444
2445
2446
2447 SCR_SET (SCR_ATN),
2448 0,
2449 SCR_CLR (SCR_ACK),
2450 0,
2451 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
2452 PADDRH (nego_bad_phase),
2453
2454},{
2455
2456
2457
2458 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT,
2459 NADDR (msgout),
2460 SCR_COPY (1),
2461 NADDR (msgout),
2462 NADDR (lastmsg),
2463 SCR_JUMP,
2464 PADDR (msg_out_done),
2465
2466},{
2467 SCR_CLR (SCR_ACK),
2468 0,
2469 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2470 PADDR (dispatch),
2471
2472
2473
2474 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2475 NADDR (msgin[2]),
2476 SCR_JUMP ^ IFTRUE (DATA (M_X_SYNC_REQ)),
2477 PADDRH (msg_sdtr),
2478
2479
2480
2481 SCR_JUMP,
2482 PADDR (msg_bad)
2483
2484},{
2485 SCR_CLR (SCR_ACK),
2486 0,
2487 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
2488 PADDR (dispatch),
2489
2490
2491
2492 SCR_MOVE_ABS (2) ^ SCR_MSG_IN,
2493 NADDR (msgin[3]),
2494
2495
2496
2497 SCR_INT,
2498 SIR_NEGO_SYNC,
2499
2500
2501
2502 SCR_SET (SCR_ATN),
2503 0,
2504 SCR_CLR (SCR_ACK),
2505 0,
2506 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
2507 PADDRH (nego_bad_phase),
2508
2509},{
2510
2511
2512
2513 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT,
2514 NADDR (msgout),
2515 SCR_COPY (1),
2516 NADDR (msgout),
2517 NADDR (lastmsg),
2518 SCR_JUMP,
2519 PADDR (msg_out_done),
2520
2521},{
2522 SCR_INT,
2523 SIR_NEGO_PROTO,
2524 SCR_JUMP,
2525 PADDR (dispatch),
2526
2527},{
2528
2529
2530
2531
2532
2533 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
2534 0,
2535 SCR_CLR (SCR_ACK|SCR_ATN),
2536 0,
2537 SCR_WAIT_DISC,
2538 0,
2539
2540
2541
2542 SCR_LOAD_REG (HS_REG, HS_ABORTED),
2543 0,
2544 SCR_JUMP,
2545 PADDR (cleanup),
2546
2547},{
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
25620
2563},{
2564 SCR_JUMP,
2565 PADDR (data_in),
2566
2567},{
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
25820
2583},{
2584 SCR_JUMP,
2585 PADDR (data_out),
2586
2587},{
2588
2589
2590
2591
2592 SCR_LOAD_REG (scratcha, M_ABORT_TAG),
2593 0,
2594 SCR_JUMP,
2595 PADDRH (abort_resel),
2596},{
2597
2598
2599
2600 SCR_LOAD_REG (scratcha, M_ABORT_TAG),
2601 0,
2602 SCR_JUMP,
2603 PADDRH (abort_resel),
2604},{
2605
2606
2607
2608 SCR_LOAD_REG (scratcha, M_ABORT),
2609 0,
2610},{
2611 SCR_COPY (1),
2612 RADDR (scratcha),
2613 NADDR (msgout),
2614 SCR_SET (SCR_ATN),
2615 0,
2616 SCR_CLR (SCR_ACK),
2617 0,
2618
2619
2620
2621
2622 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
2623 0,
2624 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
2625 NADDR (msgout),
2626 SCR_COPY (1),
2627 NADDR (msgout),
2628 NADDR (lastmsg),
2629 SCR_CLR (SCR_ACK|SCR_ATN),
2630 0,
2631 SCR_WAIT_DISC,
2632 0,
2633 SCR_JUMP,
2634 PADDR (start),
2635},{
2636
2637
2638
2639
2640
2641
2642 SCR_SET (SCR_ATN),
2643 0,
2644 SCR_JUMP,
2645 PADDR (send_ident),
2646},{
2647 SCR_CLR (SCR_ATN),
2648 0,
2649 SCR_JUMP,
2650},{
2651 0,
2652},{
2653 SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2654 PADDR (dispatch),
2655 SCR_MOVE_TBL ^ SCR_DATA_IN,
2656 offsetof (struct dsb, sense),
2657 SCR_CALL,
2658 PADDR (dispatch),
2659 SCR_JUMP,
2660 PADDR (no_data),
2661},{
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674 SCR_JUMPR ^ IFTRUE (WHEN (SCR_DATA_OUT)),
2675 32,
2676
2677
2678
2679
2680 SCR_COPY (4),
2681 NADDR (header.lastp),
2682 NADDR (header.savep),
2683
2684
2685
2686
2687 SCR_COPY (4),
2688 NADDR (header.savep),
2689 RADDR (temp),
2690 SCR_RETURN,
2691 0,
2692
2693
2694
2695 SCR_COPY (4),
2696 NADDR (header.wlastp),
2697 NADDR (header.lastp),
2698 SCR_COPY (4),
2699 NADDR (header.wgoalp),
2700 NADDR (header.goalp),
2701 SCR_JUMPR,
2702 -64,
2703},{
2704
2705
2706
2707
2708
2709 SCR_JUMPR ^ IFTRUE (MASK (0x80, 0x80)),
2710 16,
2711 SCR_INT,
2712 SIR_RESEL_NO_IDENTIFY,
2713 SCR_JUMP,
2714 PADDRH (reset),
2715
2716
2717
2718
2719
2720
2721
2722 SCR_INT,
2723 SIR_RESEL_BAD_LUN,
2724 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2725 NADDR (msgin),
2726 SCR_JUMP,
2727 PADDRH (abort),
2728},{
2729
2730
2731
2732
2733
2734 SCR_INT,
2735 SIR_RESEL_BAD_I_T_L,
2736 SCR_JUMP,
2737 PADDRH (abort),
2738},{
2739
2740
2741
2742
2743
2744 SCR_INT,
2745 SIR_RESEL_BAD_I_T_L_Q,
2746 SCR_JUMP,
2747 PADDRH (aborttag),
2748},{
2749
2750
2751
2752
2753
2754
2755 SCR_INT,
2756 SIR_RESEL_BAD_TARGET,
2757 SCR_JUMPR ^ IFFALSE (WHEN (SCR_MSG_IN)),
2758 8,
2759 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
2760 NADDR (msgin),
2761 SCR_JUMP,
2762 PADDRH (reset),
2763},{
2764
2765
2766
2767
2768
2769 SCR_INT ^ IFTRUE (DATA (S_QUEUE_FULL)),
2770 SIR_BAD_STATUS,
2771 SCR_INT ^ IFTRUE (DATA (S_CHECK_COND)),
2772 SIR_BAD_STATUS,
2773 SCR_INT ^ IFTRUE (DATA (S_TERMINATED)),
2774 SIR_BAD_STATUS,
2775 SCR_RETURN,
2776 0,
2777},{
2778
2779
2780
2781
2782 SCR_COPY_F (4),
2783 RADDR (scratcha),
2784 PADDRH (start_ram0),
2785 SCR_COPY (sizeof (struct script)),
2786},{
2787 0,
2788 PADDR (start),
2789 SCR_JUMP,
2790 PADDR (start),
2791},{
2792
2793
2794
2795
2796
2797 SCR_COPY (4),
2798 RADDR (temp),
2799 PADDR (startpos),
2800 SCR_JUMP,
2801 PADDR (start),
2802},{
2803
2804
2805
2806 SCR_COPY (4),
2807 NADDR(ncr_cache),
2808 RADDR (scratcha),
2809
2810
2811
2812 SCR_COPY (4),
2813 RADDR (temp),
2814 NADDR(ncr_cache),
2815
2816
2817
2818 SCR_COPY (4),
2819 NADDR(ncr_cache),
2820 RADDR (temp),
2821},{
2822
2823
2824
2825 SCR_INT,
2826 99,
2827}
2828};
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839void __init ncr_script_fill (struct script * scr, struct scripth * scrh)
2840{
2841 int i;
2842 ncrcmd *p;
2843
2844 p = scrh->tryloop;
2845 for (i=0; i<MAX_START; i++) {
2846 *p++ =SCR_CALL;
2847 *p++ =PADDR (idle);
2848 };
2849
2850 assert ((u_long)p == (u_long)&scrh->tryloop + sizeof (scrh->tryloop));
2851
2852#ifdef SCSI_NCR_CCB_DONE_SUPPORT
2853
2854 p = scrh->done_queue;
2855 for (i = 0; i<MAX_DONE; i++) {
2856 *p++ =SCR_COPY (sizeof(ccb_p));
2857 *p++ =NADDR (header.cp);
2858 *p++ =NADDR (ccb_done[i]);
2859 *p++ =SCR_CALL;
2860 *p++ =PADDR (done_end);
2861 }
2862
2863 assert ((u_long)p ==(u_long)&scrh->done_queue+sizeof(scrh->done_queue));
2864
2865#endif
2866
2867 p = scrh->hdata_in;
2868 for (i=0; i<MAX_SCATTERH; i++) {
2869 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN));
2870 *p++ =PADDR (dispatch);
2871 *p++ =SCR_MOVE_TBL ^ SCR_DATA_IN;
2872 *p++ =offsetof (struct dsb, data[i]);
2873 };
2874 assert ((u_long)p == (u_long)&scrh->hdata_in + sizeof (scrh->hdata_in));
2875
2876 p = scr->data_in;
2877 for (i=MAX_SCATTERH; i<MAX_SCATTERH+MAX_SCATTERL; i++) {
2878 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN));
2879 *p++ =PADDR (dispatch);
2880 *p++ =SCR_MOVE_TBL ^ SCR_DATA_IN;
2881 *p++ =offsetof (struct dsb, data[i]);
2882 };
2883 assert ((u_long)p == (u_long)&scr->data_in + sizeof (scr->data_in));
2884
2885 p = scrh->hdata_out;
2886 for (i=0; i<MAX_SCATTERH; i++) {
2887 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT));
2888 *p++ =PADDR (dispatch);
2889 *p++ =SCR_MOVE_TBL ^ SCR_DATA_OUT;
2890 *p++ =offsetof (struct dsb, data[i]);
2891 };
2892 assert ((u_long)p==(u_long)&scrh->hdata_out + sizeof (scrh->hdata_out));
2893
2894 p = scr->data_out;
2895 for (i=MAX_SCATTERH; i<MAX_SCATTERH+MAX_SCATTERL; i++) {
2896 *p++ =SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT));
2897 *p++ =PADDR (dispatch);
2898 *p++ =SCR_MOVE_TBL ^ SCR_DATA_OUT;
2899 *p++ =offsetof (struct dsb, data[i]);
2900 };
2901
2902 assert ((u_long)p == (u_long)&scr->data_out + sizeof (scr->data_out));
2903}
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914static void __init
2915ncr_script_copy_and_bind (ncb_p np, ncrcmd *src, ncrcmd *dst, int len)
2916{
2917 ncrcmd opcode, new, old, tmp1, tmp2;
2918 ncrcmd *start, *end;
2919 int relocs;
2920 int opchanged = 0;
2921
2922 start = src;
2923 end = src + len/4;
2924
2925 while (src < end) {
2926
2927 opcode = *src++;
2928 *dst++ = cpu_to_scr(opcode);
2929
2930
2931
2932
2933
2934
2935
2936
2937 if (opcode == 0) {
2938 printk (KERN_ERR "%s: ERROR0 IN SCRIPT at %d.\n",
2939 ncr_name(np), (int) (src-start-1));
2940 MDELAY (1000);
2941 };
2942
2943 if (DEBUG_FLAGS & DEBUG_SCRIPT)
2944 printk (KERN_DEBUG "%p: <%x>\n",
2945 (src-1), (unsigned)opcode);
2946
2947
2948
2949
2950 switch (opcode >> 28) {
2951
2952 case 0xc:
2953
2954
2955
2956 relocs = 2;
2957 tmp1 = src[0];
2958#ifdef RELOC_KVAR
2959 if ((tmp1 & RELOC_MASK) == RELOC_KVAR)
2960 tmp1 = 0;
2961#endif
2962 tmp2 = src[1];
2963#ifdef RELOC_KVAR
2964 if ((tmp2 & RELOC_MASK) == RELOC_KVAR)
2965 tmp2 = 0;
2966#endif
2967 if ((tmp1 ^ tmp2) & 3) {
2968 printk (KERN_ERR"%s: ERROR1 IN SCRIPT at %d.\n",
2969 ncr_name(np), (int) (src-start-1));
2970 MDELAY (1000);
2971 }
2972
2973
2974
2975
2976 if ((opcode & SCR_NO_FLUSH) && !(np->features & FE_PFEN)) {
2977 dst[-1] = cpu_to_scr(opcode & ~SCR_NO_FLUSH);
2978 ++opchanged;
2979 }
2980 break;
2981
2982 case 0x0:
2983
2984
2985
2986 relocs = 1;
2987 break;
2988
2989 case 0x8:
2990
2991
2992
2993
2994 if (opcode & 0x00800000)
2995 relocs = 0;
2996 else
2997 relocs = 1;
2998 break;
2999
3000 case 0x4:
3001 case 0x5:
3002 case 0x6:
3003 case 0x7:
3004 relocs = 1;
3005 break;
3006
3007 default:
3008 relocs = 0;
3009 break;
3010 };
3011
3012 if (relocs) {
3013 while (relocs--) {
3014 old = *src++;
3015
3016 switch (old & RELOC_MASK) {
3017 case RELOC_REGISTER:
3018 new = (old & ~RELOC_MASK) + np->paddr;
3019 break;
3020 case RELOC_LABEL:
3021 new = (old & ~RELOC_MASK) + np->p_script;
3022 break;
3023 case RELOC_LABELH:
3024 new = (old & ~RELOC_MASK) + np->p_scripth;
3025 break;
3026 case RELOC_SOFTC:
3027 new = (old & ~RELOC_MASK) + np->p_ncb;
3028 break;
3029#ifdef RELOC_KVAR
3030 case RELOC_KVAR:
3031 if (((old & ~RELOC_MASK) <
3032 SCRIPT_KVAR_FIRST) ||
3033 ((old & ~RELOC_MASK) >
3034 SCRIPT_KVAR_LAST))
3035 panic("ncr KVAR out of range");
3036 new = vtophys(script_kvars[old &
3037 ~RELOC_MASK]);
3038 break;
3039#endif
3040 case 0:
3041
3042 if (old == 0) {
3043 new = old;
3044 break;
3045 }
3046
3047 default:
3048 panic("ncr_script_copy_and_bind: weird relocation %x\n", old);
3049 break;
3050 }
3051
3052 *dst++ = cpu_to_scr(new);
3053 }
3054 } else
3055 *dst++ = cpu_to_scr(*src++);
3056
3057 };
3058}
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077struct host_data {
3078 struct ncb *ncb;
3079};
3080
3081
3082
3083
3084
3085
3086static void PRINT_TARGET(ncb_p np, int target)
3087{
3088 printk(KERN_INFO "%s-<%d,*>: ", ncr_name(np), target);
3089}
3090
3091static void PRINT_LUN(ncb_p np, int target, int lun)
3092{
3093 printk(KERN_INFO "%s-<%d,%d>: ", ncr_name(np), target, lun);
3094}
3095
3096static void PRINT_ADDR(Scsi_Cmnd *cmd)
3097{
3098 struct host_data *host_data = (struct host_data *) cmd->host->hostdata;
3099 PRINT_LUN(host_data->ncb, cmd->target, cmd->lun);
3100}
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111#define _5M 5000000
3112static u_long div_10M[] =
3113 {2*_5M, 3*_5M, 4*_5M, 6*_5M, 8*_5M, 12*_5M, 16*_5M};
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132#define burst_length(bc) (!(bc))? 0 : 1 << (bc)
3133
3134
3135
3136
3137#define burst_code(dmode, ctest4, ctest5) \
3138 (ctest4) & 0x80? 0 : (((dmode) & 0xc0) >> 6) + ((ctest5) & 0x04) + 1
3139
3140
3141
3142
3143static inline void ncr_init_burst(ncb_p np, u_char bc)
3144{
3145 np->rv_ctest4 &= ~0x80;
3146 np->rv_dmode &= ~(0x3 << 6);
3147 np->rv_ctest5 &= ~0x4;
3148
3149 if (!bc) {
3150 np->rv_ctest4 |= 0x80;
3151 }
3152 else {
3153 --bc;
3154 np->rv_dmode |= ((bc & 0x3) << 6);
3155 np->rv_ctest5 |= (bc & 0x4);
3156 }
3157}
3158
3159#ifdef SCSI_NCR_NVRAM_SUPPORT
3160
3161
3162
3163
3164
3165static void __init
3166ncr_Symbios_setup_target(ncb_p np, int target, Symbios_nvram *nvram)
3167{
3168 tcb_p tp = &np->target[target];
3169 Symbios_target *tn = &nvram->target[target];
3170
3171 tp->usrsync = tn->sync_period ? (tn->sync_period + 3) / 4 : 255;
3172 tp->usrwide = tn->bus_width == 0x10 ? 1 : 0;
3173 tp->usrtags =
3174 (tn->flags & SYMBIOS_QUEUE_TAGS_ENABLED)? MAX_TAGS : 0;
3175
3176 if (!(tn->flags & SYMBIOS_DISCONNECT_ENABLE))
3177 tp->usrflag |= UF_NODISC;
3178 if (!(tn->flags & SYMBIOS_SCAN_AT_BOOT_TIME))
3179 tp->usrflag |= UF_NOSCAN;
3180}
3181
3182
3183
3184
3185
3186static void __init
3187ncr_Tekram_setup_target(ncb_p np, int target, Tekram_nvram *nvram)
3188{
3189 tcb_p tp = &np->target[target];
3190 struct Tekram_target *tn = &nvram->target[target];
3191 int i;
3192
3193 if (tn->flags & TEKRAM_SYNC_NEGO) {
3194 i = tn->sync_index & 0xf;
3195 tp->usrsync = Tekram_sync[i];
3196 }
3197
3198 tp->usrwide = (tn->flags & TEKRAM_WIDE_NEGO) ? 1 : 0;
3199
3200 if (tn->flags & TEKRAM_TAGGED_COMMANDS) {
3201 tp->usrtags = 2 << nvram->max_tags_index;
3202 }
3203
3204 if (!(tn->flags & TEKRAM_DISCONNECT_ENABLE))
3205 tp->usrflag = UF_NODISC;
3206
3207
3208 if (!(tn->flags & TEKRAM_PARITY_CHECK))
3209 np->rv_scntl0 &= ~0x0a;
3210}
3211#endif
3212
3213static int __init ncr_prepare_setting(ncb_p np, ncr_nvram *nvram)
3214{
3215 u_char burst_max;
3216 u_long period;
3217 int i;
3218
3219
3220
3221
3222
3223 np->sv_scntl0 = INB(nc_scntl0) & 0x0a;
3224 np->sv_scntl3 = INB(nc_scntl3) & 0x07;
3225 np->sv_dmode = INB(nc_dmode) & 0xce;
3226 np->sv_dcntl = INB(nc_dcntl) & 0xa8;
3227 np->sv_ctest3 = INB(nc_ctest3) & 0x01;
3228 np->sv_ctest4 = INB(nc_ctest4) & 0x80;
3229 np->sv_ctest5 = INB(nc_ctest5) & 0x24;
3230 np->sv_gpcntl = INB(nc_gpcntl);
3231 np->sv_stest2 = INB(nc_stest2) & 0x20;
3232 np->sv_stest4 = INB(nc_stest4);
3233
3234
3235
3236
3237
3238 np->maxwide = (np->features & FE_WIDE)? 1 : 0;
3239
3240
3241
3242
3243 if (np->features & (FE_ULTRA3 | FE_ULTRA2))
3244 np->clock_khz = 160000;
3245 else if (np->features & FE_ULTRA)
3246 np->clock_khz = 80000;
3247 else
3248 np->clock_khz = 40000;
3249
3250
3251
3252
3253 if (np->features & FE_QUAD)
3254 np->multiplier = 4;
3255 else if (np->features & FE_DBLR)
3256 np->multiplier = 2;
3257 else
3258 np->multiplier = 1;
3259
3260
3261
3262
3263
3264 if (np->features & FE_VARCLK)
3265 ncr_getclock(np, np->multiplier);
3266
3267
3268
3269
3270 i = np->clock_divn - 1;
3271 while (--i >= 0) {
3272 if (10ul * SCSI_NCR_MIN_ASYNC * np->clock_khz > div_10M[i]) {
3273 ++i;
3274 break;
3275 }
3276 }
3277 np->rv_scntl3 = i+1;
3278
3279
3280
3281
3282
3283
3284 period = (4 * div_10M[0] + np->clock_khz - 1) / np->clock_khz;
3285 if (period <= 250) np->minsync = 10;
3286 else if (period <= 303) np->minsync = 11;
3287 else if (period <= 500) np->minsync = 12;
3288 else np->minsync = (period + 40 - 1) / 40;
3289
3290
3291
3292
3293
3294 if (np->minsync < 25 && !(np->features & (FE_ULTRA|FE_ULTRA2)))
3295 np->minsync = 25;
3296 else if (np->minsync < 12 && !(np->features & FE_ULTRA2))
3297 np->minsync = 12;
3298
3299
3300
3301
3302
3303 period = (11 * div_10M[np->clock_divn - 1]) / (4 * np->clock_khz);
3304 np->maxsync = period > 2540 ? 254 : period / 10;
3305
3306
3307
3308
3309#if defined SCSI_NCR_TRUST_BIOS_SETTING
3310 np->rv_scntl0 = np->sv_scntl0;
3311 np->rv_dmode = np->sv_dmode;
3312 np->rv_dcntl = np->sv_dcntl;
3313 np->rv_ctest3 = np->sv_ctest3;
3314 np->rv_ctest4 = np->sv_ctest4;
3315 np->rv_ctest5 = np->sv_ctest5;
3316 burst_max = burst_code(np->sv_dmode, np->sv_ctest4, np->sv_ctest5);
3317#else
3318
3319
3320
3321
3322 burst_max = driver_setup.burst_max;
3323 if (burst_max == 255)
3324 burst_max = burst_code(np->sv_dmode, np->sv_ctest4, np->sv_ctest5);
3325 if (burst_max > 7)
3326 burst_max = 7;
3327 if (burst_max > np->maxburst)
3328 burst_max = np->maxburst;
3329
3330
3331
3332
3333 if (np->features & FE_ERL)
3334 np->rv_dmode |= ERL;
3335 if (np->features & FE_BOF)
3336 np->rv_dmode |= BOF;
3337 if (np->features & FE_ERMP)
3338 np->rv_dmode |= ERMP;
3339 if (np->features & FE_PFEN)
3340 np->rv_dcntl |= PFEN;
3341 if (np->features & FE_CLSE)
3342 np->rv_dcntl |= CLSE;
3343 if (np->features & FE_WRIE)
3344 np->rv_ctest3 |= WRIE;
3345 if (np->features & FE_DFS)
3346 np->rv_ctest5 |= DFS;
3347
3348
3349
3350
3351 if (driver_setup.master_parity)
3352 np->rv_ctest4 |= MPEE;
3353 if (driver_setup.scsi_parity)
3354 np->rv_scntl0 |= 0x0a;
3355
3356#ifdef SCSI_NCR_NVRAM_SUPPORT
3357
3358
3359
3360 if (nvram) {
3361 switch(nvram->type) {
3362 case SCSI_NCR_TEKRAM_NVRAM:
3363 np->myaddr = nvram->data.Tekram.host_id & 0x0f;
3364 break;
3365 case SCSI_NCR_SYMBIOS_NVRAM:
3366 if (!(nvram->data.Symbios.flags & SYMBIOS_PARITY_ENABLE))
3367 np->rv_scntl0 &= ~0x0a;
3368 np->myaddr = nvram->data.Symbios.host_id & 0x0f;
3369 if (nvram->data.Symbios.flags & SYMBIOS_VERBOSE_MSGS)
3370 np->verbose += 1;
3371 break;
3372 }
3373 }
3374#endif
3375
3376
3377
3378 if (np->myaddr == 255) {
3379 np->myaddr = INB(nc_scid) & 0x07;
3380 if (!np->myaddr)
3381 np->myaddr = SCSI_NCR_MYADDR;
3382 }
3383
3384#endif
3385
3386
3387
3388
3389 ncr_init_burst(np, burst_max);
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400 np->scsi_mode = SMODE_SE;
3401 if (np->features & FE_ULTRA2)
3402 np->scsi_mode = (np->sv_stest4 & SMODE);
3403 else if (np->features & FE_DIFF) {
3404 switch(driver_setup.diff_support) {
3405 case 4:
3406 if (np->sv_scntl3) {
3407 if (np->sv_stest2 & 0x20)
3408 np->scsi_mode = SMODE_HVD;
3409 break;
3410 }
3411 case 3:
3412 if (nvram && nvram->type != SCSI_NCR_SYMBIOS_NVRAM)
3413 break;
3414 if (INB(nc_gpreg) & 0x08)
3415 break;
3416 case 2:
3417 np->scsi_mode = SMODE_HVD;
3418 case 1:
3419 if (np->sv_stest2 & 0x20)
3420 np->scsi_mode = SMODE_HVD;
3421 break;
3422 default:
3423 break;
3424 }
3425 }
3426 if (np->scsi_mode == SMODE_HVD)
3427 np->rv_stest2 |= 0x20;
3428
3429
3430
3431
3432
3433
3434
3435
3436 if ((driver_setup.led_pin ||
3437 (nvram && nvram->type == SCSI_NCR_SYMBIOS_NVRAM)) &&
3438 !(np->features & FE_LEDC) && !(np->sv_gpcntl & 0x01))
3439 np->features |= FE_LED0;
3440
3441
3442
3443
3444 switch(driver_setup.irqm & 3) {
3445 case 2:
3446 np->rv_dcntl |= IRQM;
3447 break;
3448 case 1:
3449 np->rv_dcntl |= (np->sv_dcntl & IRQM);
3450 break;
3451 default:
3452 break;
3453 }
3454
3455
3456
3457
3458
3459
3460
3461 for (i = 0 ; i < MAX_TARGET ; i++) {
3462 tcb_p tp = &np->target[i];
3463
3464 tp->usrsync = 255;
3465#ifdef SCSI_NCR_NVRAM_SUPPORT
3466 if (nvram) {
3467 switch(nvram->type) {
3468 case SCSI_NCR_TEKRAM_NVRAM:
3469 ncr_Tekram_setup_target(np, i, &nvram->data.Tekram);
3470 break;
3471 case SCSI_NCR_SYMBIOS_NVRAM:
3472 ncr_Symbios_setup_target(np, i, &nvram->data.Symbios);
3473 break;
3474 }
3475 if (driver_setup.use_nvram & 0x2)
3476 tp->usrsync = driver_setup.default_sync;
3477 if (driver_setup.use_nvram & 0x4)
3478 tp->usrwide = driver_setup.max_wide;
3479 if (driver_setup.use_nvram & 0x8)
3480 tp->usrflag &= ~UF_NOSCAN;
3481 }
3482 else {
3483#else
3484 if (1) {
3485#endif
3486 tp->usrsync = driver_setup.default_sync;
3487 tp->usrwide = driver_setup.max_wide;
3488 tp->usrtags = MAX_TAGS;
3489 if (!driver_setup.disconnection)
3490 np->target[i].usrflag = UF_NODISC;
3491 }
3492 }
3493
3494
3495
3496
3497
3498 i = nvram ? nvram->type : 0;
3499 printk(KERN_INFO "%s: %sID %d, Fast-%d%s%s\n", ncr_name(np),
3500 i == SCSI_NCR_SYMBIOS_NVRAM ? "Symbios format NVRAM, " :
3501 (i == SCSI_NCR_TEKRAM_NVRAM ? "Tekram format NVRAM, " : ""),
3502 np->myaddr,
3503 np->minsync < 12 ? 40 : (np->minsync < 25 ? 20 : 10),
3504 (np->rv_scntl0 & 0xa) ? ", Parity Checking" : ", NO Parity",
3505 (np->rv_stest2 & 0x20) ? ", Differential" : "");
3506
3507 if (bootverbose > 1) {
3508 printk (KERN_INFO "%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3509 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3510 ncr_name(np), np->sv_scntl3, np->sv_dmode, np->sv_dcntl,
3511 np->sv_ctest3, np->sv_ctest4, np->sv_ctest5);
3512
3513 printk (KERN_INFO "%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3514 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3515 ncr_name(np), np->rv_scntl3, np->rv_dmode, np->rv_dcntl,
3516 np->rv_ctest3, np->rv_ctest4, np->rv_ctest5);
3517 }
3518
3519 if (bootverbose && np->paddr2)
3520 printk (KERN_INFO "%s: on-chip RAM at 0x%lx\n",
3521 ncr_name(np), np->paddr2);
3522
3523 return 0;
3524}
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536static int __init
3537ncr_attach (Scsi_Host_Template *tpnt, int unit, ncr_device *device)
3538{
3539 struct host_data *host_data;
3540 ncb_p np = 0;
3541 struct Scsi_Host *instance = 0;
3542 u_long flags = 0;
3543 ncr_nvram *nvram = device->nvram;
3544 int i;
3545
3546 printk(KERN_INFO "ncr53c%s-%d: rev 0x%x on pci bus %d device %d function %d "
3547#ifdef __sparc__
3548 "irq %s\n",
3549#else
3550 "irq %d\n",
3551#endif
3552 device->chip.name, unit, device->chip.revision_id,
3553 device->slot.bus, (device->slot.device_fn & 0xf8) >> 3,
3554 device->slot.device_fn & 7,
3555#ifdef __sparc__
3556 __irq_itoa(device->slot.irq));
3557#else
3558 device->slot.irq);
3559#endif
3560
3561
3562
3563
3564 if (!(instance = scsi_register(tpnt, sizeof(*host_data))))
3565 goto attach_error;
3566 host_data = (struct host_data *) instance->hostdata;
3567
3568
3569
3570
3571 np = __m_calloc_dma(device->pdev, sizeof(struct ncb), "NCB");
3572 if (!np)
3573 goto attach_error;
3574 NCR_INIT_LOCK_NCB(np);
3575 np->pdev = device->pdev;
3576 np->p_ncb = vtobus(np);
3577 host_data->ncb = np;
3578
3579
3580
3581
3582 np->ccb = (ccb_p) m_calloc_dma(sizeof(struct ccb), "CCB");
3583 if (!np->ccb)
3584 goto attach_error;
3585
3586
3587
3588
3589 strncpy(np->chip_name, device->chip.name, sizeof(np->chip_name) - 1);
3590 np->unit = unit;
3591 np->verbose = driver_setup.verbose;
3592 sprintf(np->inst_name, "ncr53c%s-%d", np->chip_name, np->unit);
3593 np->device_id = device->chip.device_id;
3594 np->revision_id = device->chip.revision_id;
3595 np->bus = device->slot.bus;
3596 np->device_fn = device->slot.device_fn;
3597 np->features = device->chip.features;
3598 np->clock_divn = device->chip.nr_divisor;
3599 np->maxoffs = device->chip.offset_max;
3600 np->maxburst = device->chip.burst_max;
3601 np->myaddr = device->host_id;
3602
3603
3604
3605
3606 np->script0 = (struct script *)
3607 m_calloc_dma(sizeof(struct script), "SCRIPT");
3608 if (!np->script0)
3609 goto attach_error;
3610 np->scripth0 = (struct scripth *)
3611 m_calloc_dma(sizeof(struct scripth), "SCRIPTH");
3612 if (!np->scripth0)
3613 goto attach_error;
3614
3615
3616
3617
3618
3619 init_timer(&np->timer);
3620 np->timer.data = (unsigned long) np;
3621 np->timer.function = ncr53c8xx_timeout;
3622
3623
3624
3625
3626
3627
3628 np->paddr = device->slot.base;
3629 np->paddr2 = (np->features & FE_RAM)? device->slot.base_2 : 0;
3630
3631#ifndef SCSI_NCR_IOMAPPED
3632 np->vaddr = remap_pci_mem(device->slot.base_c, (u_long) 128);
3633 if (!np->vaddr) {
3634 printk(KERN_ERR
3635 "%s: can't map memory mapped IO region\n",ncr_name(np));
3636 goto attach_error;
3637 }
3638 else
3639 if (bootverbose > 1)
3640 printk(KERN_INFO
3641 "%s: using memory mapped IO at virtual address 0x%lx\n", ncr_name(np), (u_long) np->vaddr);
3642
3643
3644
3645
3646
3647
3648
3649 np->reg = (struct ncr_reg*) np->vaddr;
3650
3651#endif
3652
3653
3654
3655
3656
3657 request_region(device->slot.io_port, 128, "ncr53c8xx");
3658 np->base_io = device->slot.io_port;
3659
3660#ifdef SCSI_NCR_NVRAM_SUPPORT
3661 if (nvram) {
3662 switch(nvram->type) {
3663 case SCSI_NCR_SYMBIOS_NVRAM:
3664#ifdef SCSI_NCR_DEBUG_NVRAM
3665 ncr_display_Symbios_nvram(&nvram->data.Symbios);
3666#endif
3667 break;
3668 case SCSI_NCR_TEKRAM_NVRAM:
3669#ifdef SCSI_NCR_DEBUG_NVRAM
3670 ncr_display_Tekram_nvram(&nvram->data.Tekram);
3671#endif
3672 break;
3673 default:
3674 nvram = 0;
3675#ifdef SCSI_NCR_DEBUG_NVRAM
3676 printk(KERN_DEBUG "%s: NVRAM: None or invalid data.\n", ncr_name(np));
3677#endif
3678 }
3679 }
3680#endif
3681
3682
3683
3684
3685 (void)ncr_prepare_setting(np, nvram);
3686
3687 if (np->paddr2 && sizeof(struct script) > 4096) {
3688 np->paddr2 = 0;
3689 printk(KERN_WARNING "%s: script too large, NOT using on chip RAM.\n",
3690 ncr_name(np));
3691 }
3692
3693
3694
3695
3696 instance->max_channel = 0;
3697 instance->this_id = np->myaddr;
3698 instance->max_id = np->maxwide ? 16 : 8;
3699 instance->max_lun = SCSI_NCR_MAX_LUN;
3700#ifndef SCSI_NCR_IOMAPPED
3701#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,29)
3702 instance->base = (unsigned long) np->reg;
3703#else
3704 instance->base = (char *) np->reg;
3705#endif
3706#endif
3707 instance->irq = device->slot.irq;
3708 instance->unique_id = device->slot.io_port;
3709 instance->io_port = device->slot.io_port;
3710 instance->n_io_port = 128;
3711 instance->dma_channel = 0;
3712 instance->cmd_per_lun = MAX_TAGS;
3713 instance->can_queue = (MAX_START-4);
3714 instance->select_queue_depths = ncr53c8xx_select_queue_depths;
3715 scsi_set_pci_device(instance, device->pdev);
3716
3717#ifdef SCSI_NCR_INTEGRITY_CHECKING
3718 np->check_integrity = 0;
3719 instance->check_integrity = 0;
3720
3721#ifdef SCSI_NCR_ENABLE_INTEGRITY_CHECK
3722 if ( !(driver_setup.bus_check & 0x04) ) {
3723 np->check_integrity = 1;
3724 instance->check_integrity = 1;
3725 }
3726#endif
3727#endif
3728
3729
3730
3731 ncr_script_fill (&script0, &scripth0);
3732
3733 np->scripth = np->scripth0;
3734 np->p_scripth = vtobus(np->scripth);
3735
3736 np->p_script = (np->paddr2) ? np->paddr2 : vtobus(np->script0);
3737
3738 ncr_script_copy_and_bind (np, (ncrcmd *) &script0, (ncrcmd *) np->script0, sizeof(struct script));
3739 ncr_script_copy_and_bind (np, (ncrcmd *) &scripth0, (ncrcmd *) np->scripth0, sizeof(struct scripth));
3740 np->ccb->p_ccb = vtobus (np->ccb);
3741
3742
3743
3744
3745
3746 if (np->features & FE_LED0) {
3747 np->script0->idle[0] =
3748 cpu_to_scr(SCR_REG_REG(gpreg, SCR_OR, 0x01));
3749 np->script0->reselected[0] =
3750 cpu_to_scr(SCR_REG_REG(gpreg, SCR_AND, 0xfe));
3751 np->script0->start[0] =
3752 cpu_to_scr(SCR_REG_REG(gpreg, SCR_AND, 0xfe));
3753 }
3754
3755
3756
3757
3758
3759
3760 for (i = 0 ; i < 4 ; i++) {
3761 np->jump_tcb[i].l_cmd =
3762 cpu_to_scr((SCR_JUMP ^ IFTRUE (MASK (i, 3))));
3763 np->jump_tcb[i].l_paddr =
3764 cpu_to_scr(NCB_SCRIPTH_PHYS (np, bad_target));
3765 }
3766
3767
3768
3769
3770
3771 OUTB (nc_istat, SRST);
3772 UDELAY (100);
3773 OUTB (nc_istat, 0 );
3774
3775
3776
3777
3778
3779 if (ncr_snooptest (np)) {
3780 printk (KERN_ERR "CACHE INCORRECTLY CONFIGURED.\n");
3781 goto attach_error;
3782 };
3783
3784
3785
3786
3787
3788 if (request_irq(device->slot.irq, ncr53c8xx_intr,
3789 ((driver_setup.irqm & 0x10) ? 0 : SA_SHIRQ) |
3790#if LINUX_VERSION_CODE < LinuxVersionCode(2,2,0)
3791 ((driver_setup.irqm & 0x20) ? 0 : SA_INTERRUPT),
3792#else
3793 0,
3794#endif
3795 "ncr53c8xx", np)) {
3796#ifdef __sparc__
3797 printk(KERN_ERR "%s: request irq %s failure\n",
3798 ncr_name(np), __irq_itoa(device->slot.irq));
3799#else
3800 printk(KERN_ERR "%s: request irq %d failure\n",
3801 ncr_name(np), device->slot.irq);
3802#endif
3803 goto attach_error;
3804 }
3805
3806 np->irq = device->slot.irq;
3807
3808
3809
3810
3811 ncr_init_ccb(np, np->ccb);
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821 NCR_LOCK_NCB(np, flags);
3822 if (ncr_reset_scsi_bus(np, 0, driver_setup.settle_delay) != 0) {
3823 printk(KERN_ERR "%s: FATAL ERROR: CHECK SCSI BUS - CABLES, TERMINATION, DEVICE POWER etc.!\n", ncr_name(np));
3824
3825 NCR_UNLOCK_NCB(np, flags);
3826 goto attach_error;
3827 }
3828 ncr_exception (np);
3829
3830 np->disc = 1;
3831
3832
3833
3834
3835
3836
3837 if (driver_setup.settle_delay > 2) {
3838 printk(KERN_INFO "%s: waiting %d seconds for scsi devices to settle...\n",
3839 ncr_name(np), driver_setup.settle_delay);
3840 MDELAY (1000 * driver_setup.settle_delay);
3841 }
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851 np->lasttime=0;
3852 ncr_timeout (np);
3853
3854
3855
3856
3857#ifdef SCSI_NCR_ALWAYS_SIMPLE_TAG
3858 np->order = M_SIMPLE_TAG;
3859#endif
3860
3861
3862
3863
3864 if (!the_template) {
3865 the_template = instance->hostt;
3866 first_host = instance;
3867 }
3868
3869 NCR_UNLOCK_NCB(np, flags);
3870
3871 return 0;
3872
3873attach_error:
3874 if (!instance) return -1;
3875 printk(KERN_INFO "%s: detaching...\n", ncr_name(np));
3876 if (!np)
3877 goto unregister;
3878#ifndef SCSI_NCR_IOMAPPED
3879 if (np->vaddr) {
3880#ifdef DEBUG_NCR53C8XX
3881 printk(KERN_DEBUG "%s: releasing memory mapped IO region %lx[%d]\n", ncr_name(np), (u_long) np->vaddr, 128);
3882#endif
3883 unmap_pci_mem((vm_offset_t) np->vaddr, (u_long) 128);
3884 }
3885#endif
3886 if (np->base_io) {
3887#ifdef DEBUG_NCR53C8XX
3888 printk(KERN_DEBUG "%s: releasing IO region %x[%d]\n", ncr_name(np), np->base_io, 128);
3889#endif
3890 release_region(np->base_io, 128);
3891 }
3892 if (np->irq) {
3893#ifdef DEBUG_NCR53C8XX
3894#ifdef __sparc__
3895 printk(KERN_INFO "%s: freeing irq %s\n", ncr_name(np),
3896 __irq_itoa(np->irq));
3897#else
3898 printk(KERN_INFO "%s: freeing irq %d\n", ncr_name(np), np->irq);
3899#endif
3900#endif
3901 free_irq(np->irq, np);
3902 }
3903 if (np->scripth0)
3904 m_free_dma(np->scripth0, sizeof(struct scripth), "SCRIPTH");
3905 if (np->script0)
3906 m_free_dma(np->script0, sizeof(struct script), "SCRIPT");
3907 if (np->ccb)
3908 m_free_dma(np->ccb, sizeof(struct ccb), "CCB");
3909 m_free_dma(np, sizeof(struct ncb), "NCB");
3910
3911unregister:
3912 scsi_unregister(instance);
3913
3914 return -1;
3915 }
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937static inline void ncr_queue_done_cmd(ncb_p np, Scsi_Cmnd *cmd)
3938{
3939 unmap_scsi_data(np, cmd);
3940 cmd->host_scribble = (char *) np->done_list;
3941 np->done_list = cmd;
3942}
3943
3944static inline void ncr_flush_done_cmds(Scsi_Cmnd *lcmd)
3945{
3946 Scsi_Cmnd *cmd;
3947
3948 while (lcmd) {
3949 cmd = lcmd;
3950 lcmd = (Scsi_Cmnd *) cmd->host_scribble;
3951 cmd->scsi_done(cmd);
3952 }
3953}
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969#ifdef SCSI_NCR_INTEGRITY_CHECKING
3970static int ncr_ic_nego(ncb_p np, ccb_p cp, Scsi_Cmnd *cmd, u_char *msgptr)
3971{
3972 tcb_p tp = &np->target[cp->target];
3973 int msglen = 0;
3974 int nego = 0;
3975 u_char no_increase;
3976
3977 if (tp->inq_done) {
3978
3979 if (!tp->ic_maximums_set) {
3980 tp->ic_maximums_set = 1;
3981
3982
3983 if ( (tp->inq_byte7 & INQ7_WIDE16) &&
3984 np->maxwide && tp->usrwide )
3985 tp->ic_max_width = 1;
3986 else
3987 tp->ic_max_width = 0;
3988
3989 if ((tp->inq_byte7 & INQ7_SYNC) && tp->maxoffs) {
3990 tp->ic_min_sync = (tp->minsync < np->minsync) ?
3991 np->minsync : tp->minsync;
3992 }
3993 else
3994 tp->ic_min_sync = 255;
3995
3996 tp->period = 1;
3997 tp->widedone = 1;
3998 }
3999
4000 if (DEBUG_FLAGS & DEBUG_IC) {
4001 printk("%s: cmd->ic_nego %d, 1st byte 0x%2X\n",
4002 ncr_name(np), cmd->ic_nego, cmd->cmnd[0]);
4003 }
4004
4005
4006
4007
4008 if ((cmd->ic_nego & NS_PPR) == NS_PPR)
4009 cmd->ic_nego &= ~NS_PPR;
4010
4011
4012
4013
4014
4015
4016 if (np->check_integ_par) {
4017 printk("%s: Parity Error. Target set to narrow.\n",
4018 ncr_name(np));
4019 tp->ic_max_width = 0;
4020 tp->widedone = tp->period = 0;
4021 }
4022
4023
4024
4025
4026
4027 no_increase = 0;
4028 if (tp->widedone == 0) {
4029 cmd->ic_nego = NS_WIDE;
4030 tp->widedone = 1;
4031 no_increase = 1;
4032 }
4033 else if (tp->period == 0) {
4034 cmd->ic_nego = NS_SYNC;
4035 tp->period = 1;
4036 no_increase = 1;
4037 }
4038
4039 switch (cmd->ic_nego) {
4040 case NS_WIDE:
4041
4042
4043
4044
4045
4046 if (tp->ic_max_width | np->check_integ_par) {
4047 nego = NS_WIDE;
4048
4049 msgptr[msglen++] = M_EXTENDED;
4050 msgptr[msglen++] = 2;
4051 msgptr[msglen++] = M_X_WIDE_REQ;
4052 msgptr[msglen++] = cmd->ic_nego_width & tp->ic_max_width;
4053 }
4054 else
4055 cmd->ic_nego_width &= tp->ic_max_width;
4056
4057 break;
4058
4059 case NS_SYNC:
4060
4061
4062
4063
4064
4065
4066
4067 if (tp->inq_byte7 & INQ7_SYNC) {
4068
4069 nego = NS_SYNC;
4070
4071 msgptr[msglen++] = M_EXTENDED;
4072 msgptr[msglen++] = 3;
4073 msgptr[msglen++] = M_X_SYNC_REQ;
4074
4075 switch (cmd->ic_nego_sync) {
4076 case 2:
4077 if (!no_increase) {
4078 if (tp->ic_min_sync <= 0x0A)
4079 tp->ic_min_sync = 0x0C;
4080 else if (tp->ic_min_sync <= 0x0C)
4081 tp->ic_min_sync = 0x19;
4082 else if (tp->ic_min_sync <= 0x19)
4083 tp->ic_min_sync *= 2;
4084 else {
4085 tp->ic_min_sync = 255;
4086 cmd->ic_nego_sync = 0;
4087 tp->maxoffs = 0;
4088 }
4089 }
4090 msgptr[msglen++] = tp->maxoffs?tp->ic_min_sync:0;
4091 msgptr[msglen++] = tp->maxoffs;
4092 break;
4093
4094 case 1:
4095 msgptr[msglen++] = tp->maxoffs?tp->ic_min_sync:0;
4096 msgptr[msglen++] = tp->maxoffs;
4097 break;
4098
4099 case 0:
4100 default:
4101 msgptr[msglen++] = 0;
4102 msgptr[msglen++] = 0;
4103 break;
4104 };
4105 }
4106 else
4107 cmd->ic_nego_sync = 0;
4108 break;
4109
4110 case NS_NOCHANGE:
4111 default:
4112 break;
4113 };
4114 };
4115
4116 cp->nego_status = nego;
4117 np->check_integ_par = 0;
4118
4119 if (nego) {
4120 tp->nego_cp = cp;
4121 if (DEBUG_FLAGS & DEBUG_NEGO) {
4122 ncr_print_msg(cp, nego == NS_WIDE ?
4123 "wide/narrow msgout": "sync/async msgout", msgptr);
4124 };
4125 };
4126
4127 return msglen;
4128}
4129#endif
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145static int ncr_prepare_nego(ncb_p np, ccb_p cp, u_char *msgptr)
4146{
4147 tcb_p tp = &np->target[cp->target];
4148 int msglen = 0;
4149 int nego = 0;
4150
4151 if (tp->inq_done) {
4152
4153
4154
4155
4156
4157 if (!tp->widedone) {
4158 if (tp->inq_byte7 & INQ7_WIDE16) {
4159 nego = NS_WIDE;
4160#ifdef SCSI_NCR_INTEGRITY_CHECKING
4161 if (tp->ic_done)
4162 tp->usrwide &= tp->ic_max_width;
4163#endif
4164 } else
4165 tp->widedone=1;
4166
4167 };
4168
4169
4170
4171
4172
4173 if (!nego && !tp->period) {
4174 if (tp->inq_byte7 & INQ7_SYNC) {
4175 nego = NS_SYNC;
4176#ifdef SCSI_NCR_INTEGRITY_CHECKING
4177 if ((tp->ic_done) &&
4178 (tp->minsync < tp->ic_min_sync))
4179 tp->minsync = tp->ic_min_sync;
4180#endif
4181 } else {
4182 tp->period =0xffff;
4183 PRINT_TARGET(np, cp->target);
4184 printk ("target did not report SYNC.\n");
4185 };
4186 };
4187 };
4188
4189 switch (nego) {
4190 case NS_SYNC:
4191 msgptr[msglen++] = M_EXTENDED;
4192 msgptr[msglen++] = 3;
4193 msgptr[msglen++] = M_X_SYNC_REQ;
4194 msgptr[msglen++] = tp->maxoffs ? tp->minsync : 0;
4195 msgptr[msglen++] = tp->maxoffs;
4196 break;
4197 case NS_WIDE:
4198 msgptr[msglen++] = M_EXTENDED;
4199 msgptr[msglen++] = 2;
4200 msgptr[msglen++] = M_X_WIDE_REQ;
4201 msgptr[msglen++] = tp->usrwide;
4202 break;
4203 };
4204
4205 cp->nego_status = nego;
4206
4207 if (nego) {
4208 tp->nego_cp = cp;
4209 if (DEBUG_FLAGS & DEBUG_NEGO) {
4210 ncr_print_msg(cp, nego == NS_WIDE ?
4211 "wide msgout":"sync_msgout", msgptr);
4212 };
4213 };
4214
4215 return msglen;
4216}
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229static int ncr_queue_command (ncb_p np, Scsi_Cmnd *cmd)
4230{
4231
4232 tcb_p tp = &np->target[cmd->target];
4233 lcb_p lp = tp->lp[cmd->lun];
4234 ccb_p cp;
4235
4236 int segments;
4237 u_char idmsg, *msgptr;
4238 u_int msglen;
4239 int direction;
4240 u_int32 lastp, goalp;
4241
4242
4243
4244
4245
4246
4247
4248 if ((cmd->target == np->myaddr ) ||
4249 (cmd->target >= MAX_TARGET) ||
4250 (cmd->lun >= MAX_LUN )) {
4251 return(DID_BAD_TARGET);
4252 }
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263 if ((cmd->cmnd[0] == 0 || cmd->cmnd[0] == 0x12) &&
4264 (tp->usrflag & UF_NOSCAN)) {
4265 tp->usrflag &= ~UF_NOSCAN;
4266 return DID_BAD_TARGET;
4267 }
4268
4269 if (DEBUG_FLAGS & DEBUG_TINY) {
4270 PRINT_ADDR(cmd);
4271 printk ("CMD=%x ", cmd->cmnd[0]);
4272 }
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284 if (np->settle_time && cmd->timeout_per_command >= HZ) {
4285 u_long tlimit = ktime_get(cmd->timeout_per_command - HZ);
4286 if (ktime_dif(np->settle_time, tlimit) > 0)
4287 np->settle_time = tlimit;
4288 }
4289
4290 if (np->settle_time || !(cp=ncr_get_ccb (np, cmd->target, cmd->lun))) {
4291 insert_into_waiting_list(np, cmd);
4292 return(DID_OK);
4293 }
4294 cp->cmd = cmd;
4295
4296
4297
4298
4299
4300
4301
4302#if 0
4303 if (lp && !lp->numtags && cmd->device && cmd->device->tagged_queue) {
4304 lp->numtags = tp->usrtags;
4305 ncr_setup_tags (np, cmd->target, cmd->lun);
4306 }
4307#endif
4308
4309
4310
4311
4312
4313
4314
4315
4316 idmsg = M_IDENTIFY | cmd->lun;
4317
4318 if (cp ->tag != NO_TAG ||
4319 (cp != np->ccb && np->disc && !(tp->usrflag & UF_NODISC)))
4320 idmsg |= 0x40;
4321
4322 msgptr = cp->scsi_smsg;
4323 msglen = 0;
4324 msgptr[msglen++] = idmsg;
4325
4326 if (cp->tag != NO_TAG) {
4327 char order = np->order;
4328
4329
4330
4331
4332
4333 if (lp && ktime_exp(lp->tags_stime)) {
4334 if (lp->tags_smap) {
4335 order = M_ORDERED_TAG;
4336 if ((DEBUG_FLAGS & DEBUG_TAGS)||bootverbose>2){
4337 PRINT_ADDR(cmd);
4338 printk("ordered tag forced.\n");
4339 }
4340 }
4341 lp->tags_stime = ktime_get(3*HZ);
4342 lp->tags_smap = lp->tags_umap;
4343 }
4344
4345 if (order == 0) {
4346
4347
4348
4349 switch (cmd->cmnd[0]) {
4350 case 0x08:
4351 case 0x28:
4352 case 0xa8:
4353 order = M_SIMPLE_TAG;
4354 break;
4355 default:
4356 order = M_ORDERED_TAG;
4357 }
4358 }
4359 msgptr[msglen++] = order;
4360
4361
4362
4363
4364
4365 msgptr[msglen++] = (cp->tag << 1) + 1;
4366 }
4367
4368
4369
4370
4371
4372
4373
4374
4375 direction = scsi_data_direction(cmd);
4376 if (direction != SCSI_DATA_NONE) {
4377 segments = ncr_scatter (np, cp, cp->cmd);
4378 if (segments < 0) {
4379 ncr_free_ccb(np, cp);
4380 return(DID_ERROR);
4381 }
4382 }
4383 else {
4384 cp->data_len = 0;
4385 segments = 0;
4386 }
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397 cp->nego_status = 0;
4398
4399#ifdef SCSI_NCR_INTEGRITY_CHECKING
4400 if ((np->check_integrity && tp->ic_done) || !np->check_integrity) {
4401 if ((!tp->widedone || !tp->period) && !tp->nego_cp && lp) {
4402 msglen += ncr_prepare_nego (np, cp, msgptr + msglen);
4403 }
4404 }
4405 else if (np->check_integrity && (cmd->ic_in_progress)) {
4406 msglen += ncr_ic_nego (np, cp, cmd, msgptr + msglen);
4407 }
4408 else if (np->check_integrity && cmd->ic_complete) {
4409
4410
4411
4412
4413
4414
4415 {
4416 u_char idiv;
4417 idiv = (tp->wval>>4) & 0x07;
4418 if ((tp->sval&0x1f) && idiv )
4419 tp->period = (((tp->sval>>5)+4)
4420 *div_10M[idiv-1])/np->clock_khz;
4421 else
4422 tp->period = 0xffff;
4423 }
4424
4425
4426
4427
4428 if (tp->period <= 250) tp->ic_min_sync = 10;
4429 else if (tp->period <= 303) tp->ic_min_sync = 11;
4430 else if (tp->period <= 500) tp->ic_min_sync = 12;
4431 else
4432 tp->ic_min_sync = (tp->period + 40 - 1) / 40;
4433
4434
4435
4436
4437
4438 tp->ic_max_width = (tp->wval & EWS) ? 1: 0;
4439 tp->ic_done = 1;
4440 tp->widedone = 1;
4441
4442 printk("%s: Integrity Check Complete: \n", ncr_name(np));
4443
4444 printk("%s: %s %s SCSI", ncr_name(np),
4445 (tp->sval&0x1f)?"SYNC":"ASYNC",
4446 tp->ic_max_width?"WIDE":"NARROW");
4447
4448 if (tp->sval&0x1f) {
4449 u_long mbs = 10000 * (tp->ic_max_width + 1);
4450
4451 printk(" %d.%d MB/s",
4452 (int) (mbs / tp->period), (int) (mbs % tp->period));
4453
4454 printk(" (%d ns, %d offset)\n",
4455 tp->period/10, tp->sval&0x1f);
4456 }
4457 else
4458 printk(" %d MB/s. \n ", (tp->ic_max_width+1)*5);
4459 }
4460#else
4461 if ((!tp->widedone || !tp->period) && !tp->nego_cp && lp) {
4462 msglen += ncr_prepare_nego (np, cp, msgptr + msglen);
4463 }
4464#endif
4465
4466
4467
4468
4469
4470
4471
4472 if (!cp->data_len)
4473 direction = SCSI_DATA_NONE;
4474
4475
4476
4477
4478
4479
4480
4481 switch(direction) {
4482 case SCSI_DATA_UNKNOWN:
4483 case SCSI_DATA_WRITE:
4484 goalp = NCB_SCRIPT_PHYS (np, data_out2) + 8;
4485 if (segments <= MAX_SCATTERL)
4486 lastp = goalp - 8 - (segments * 16);
4487 else {
4488 lastp = NCB_SCRIPTH_PHYS (np, hdata_out2);
4489 lastp -= (segments - MAX_SCATTERL) * 16;
4490 }
4491 if (direction != SCSI_DATA_UNKNOWN)
4492 break;
4493 cp->phys.header.wgoalp = cpu_to_scr(goalp);
4494 cp->phys.header.wlastp = cpu_to_scr(lastp);
4495
4496 case SCSI_DATA_READ:
4497 goalp = NCB_SCRIPT_PHYS (np, data_in2) + 8;
4498 if (segments <= MAX_SCATTERL)
4499 lastp = goalp - 8 - (segments * 16);
4500 else {
4501 lastp = NCB_SCRIPTH_PHYS (np, hdata_in2);
4502 lastp -= (segments - MAX_SCATTERL) * 16;
4503 }
4504 break;
4505 default:
4506 case SCSI_DATA_NONE:
4507 lastp = goalp = NCB_SCRIPT_PHYS (np, no_data);
4508 break;
4509 }
4510
4511
4512
4513
4514
4515 cp->phys.header.lastp = cpu_to_scr(lastp);
4516 cp->phys.header.goalp = cpu_to_scr(goalp);
4517
4518 if (direction == SCSI_DATA_UNKNOWN)
4519 cp->phys.header.savep =
4520 cpu_to_scr(NCB_SCRIPTH_PHYS (np, data_io));
4521 else
4522 cp->phys.header.savep= cpu_to_scr(lastp);
4523
4524
4525
4526
4527
4528 cp->startp = cp->phys.header.savep;
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544 cp->start.schedule.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, select));
4545 cp->restart.schedule.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, resel_dsa));
4546
4547
4548
4549 cp->phys.select.sel_id = cmd->target;
4550 cp->phys.select.sel_scntl3 = tp->wval;
4551 cp->phys.select.sel_sxfer = tp->sval;
4552
4553
4554
4555 cp->phys.smsg.addr = cpu_to_scr(CCB_PHYS (cp, scsi_smsg));
4556 cp->phys.smsg.size = cpu_to_scr(msglen);
4557
4558
4559
4560
4561 memcpy(cp->cdb_buf, cmd->cmnd, MIN(cmd->cmd_len, sizeof(cp->cdb_buf)));
4562 cp->phys.cmd.addr = cpu_to_scr(CCB_PHYS (cp, cdb_buf[0]));
4563 cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
4564
4565
4566
4567
4568 cp->actualquirks = tp->quirks;
4569 cp->host_status = cp->nego_status ? HS_NEGOTIATE : HS_BUSY;
4570 cp->scsi_status = S_ILLEGAL;
4571 cp->parity_status = 0;
4572
4573 cp->xerr_status = XE_OK;
4574#if 0
4575 cp->sync_status = tp->sval;
4576 cp->wide_status = tp->wval;
4577#endif
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589 cp->magic = CCB_MAGIC;
4590
4591
4592
4593
4594
4595 cp->auto_sense = 0;
4596 if (lp)
4597 ncr_start_next_ccb(np, lp, 2);
4598 else
4599 ncr_put_start_queue(np, cp);
4600
4601
4602
4603
4604
4605 return(DID_OK);
4606}
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619static void ncr_start_next_ccb(ncb_p np, lcb_p lp, int maxn)
4620{
4621 XPT_QUEHEAD *qp;
4622 ccb_p cp;
4623
4624 if (lp->held_ccb)
4625 return;
4626
4627 while (maxn-- && lp->queuedccbs < lp->queuedepth) {
4628 qp = xpt_remque_head(&lp->wait_ccbq);
4629 if (!qp)
4630 break;
4631 ++lp->queuedccbs;
4632 cp = xpt_que_entry(qp, struct ccb, link_ccbq);
4633 xpt_insque_tail(qp, &lp->busy_ccbq);
4634 lp->jump_ccb[cp->tag == NO_TAG ? 0 : cp->tag] =
4635 cpu_to_scr(CCB_PHYS (cp, restart));
4636 ncr_put_start_queue(np, cp);
4637 }
4638}
4639
4640static void ncr_put_start_queue(ncb_p np, ccb_p cp)
4641{
4642 u_short qidx;
4643
4644
4645
4646
4647 if (!np->squeueput) np->squeueput = 1;
4648 qidx = np->squeueput + 2;
4649 if (qidx >= MAX_START + MAX_START) qidx = 1;
4650
4651 np->scripth->tryloop [qidx] = cpu_to_scr(NCB_SCRIPT_PHYS (np, idle));
4652 MEMORY_BARRIER();
4653 np->scripth->tryloop [np->squeueput] = cpu_to_scr(CCB_PHYS (cp, start));
4654
4655 np->squeueput = qidx;
4656 ++np->queuedccbs;
4657 cp->queued = 1;
4658
4659 if (DEBUG_FLAGS & DEBUG_QUEUE)
4660 printk ("%s: queuepos=%d.\n", ncr_name (np), np->squeueput);
4661
4662
4663
4664
4665
4666 MEMORY_BARRIER();
4667 OUTB (nc_istat, SIGP);
4668}
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683static void ncr_start_reset(ncb_p np)
4684{
4685 if (!np->settle_time) {
4686 (void) ncr_reset_scsi_bus(np, 1, driver_setup.settle_delay);
4687 }
4688 }
4689
4690static int ncr_reset_scsi_bus(ncb_p np, int enab_int, int settle_delay)
4691{
4692 u_int32 term;
4693 int retv = 0;
4694
4695 np->settle_time = ktime_get(settle_delay * HZ);
4696
4697 if (bootverbose > 1)
4698 printk("%s: resetting, "
4699 "command processing suspended for %d seconds\n",
4700 ncr_name(np), settle_delay);
4701
4702 OUTB (nc_istat, SRST);
4703 UDELAY (100);
4704 OUTB (nc_istat, 0);
4705 UDELAY (2000);
4706 if (enab_int)
4707 OUTW (nc_sien, RST);
4708
4709
4710
4711
4712 OUTB (nc_stest3, TE);
4713 OUTB (nc_dcntl, (np->rv_dcntl & IRQM));
4714 OUTB (nc_scntl1, CRST);
4715 UDELAY (200);
4716
4717 if (!driver_setup.bus_check)
4718 goto out;
4719
4720
4721
4722
4723
4724
4725
4726 term = INB(nc_sstat0);
4727 term = ((term & 2) << 7) + ((term & 1) << 17);
4728 term |= ((INB(nc_sstat2) & 0x01) << 26) |
4729 ((INW(nc_sbdl) & 0xff) << 9) |
4730 ((INW(nc_sbdl) & 0xff00) << 10) |
4731 INB(nc_sbcl);
4732
4733 if (!(np->features & FE_WIDE))
4734 term &= 0x3ffff;
4735
4736 if (term != (2<<7)) {
4737 printk("%s: suspicious SCSI data while resetting the BUS.\n",
4738 ncr_name(np));
4739 printk("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
4740 "0x%lx, expecting 0x%lx\n",
4741 ncr_name(np),
4742 (np->features & FE_WIDE) ? "dp1,d15-8," : "",
4743 (u_long)term, (u_long)(2<<7));
4744 if (driver_setup.bus_check == 1)
4745 retv = 1;
4746 }
4747out:
4748 OUTB (nc_scntl1, 0);
4749 return retv;
4750}
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761static int ncr_reset_bus (ncb_p np, Scsi_Cmnd *cmd, int sync_reset)
4762{
4763
4764 ccb_p cp;
4765 int found;
4766
4767
4768
4769
4770 if (np->settle_time) {
4771 return SCSI_RESET_PUNT;
4772 }
4773
4774
4775
4776
4777
4778
4779 ncr_start_reset(np);
4780
4781
4782
4783 for (found=0, cp=np->ccb; cp; cp=cp->link_ccb) {
4784
4785
4786
4787 if (cp->host_status == HS_IDLE) continue;
4788 if (cp->cmd == cmd) {
4789 found = 1;
4790 break;
4791 }
4792 }
4793
4794
4795
4796 if (!found && retrieve_from_waiting_list(0, np, cmd))
4797 found = 1;
4798
4799
4800
4801 reset_waiting_list(np);
4802
4803
4804
4805 ncr_wakeup(np, HS_RESET);
4806
4807
4808
4809
4810
4811
4812 if (!found && sync_reset && !retrieve_from_waiting_list(0, np, cmd)) {
4813 cmd->result = ScsiResult(DID_RESET, 0);
4814 ncr_queue_done_cmd(np, cmd);
4815 }
4816
4817 return SCSI_RESET_SUCCESS;
4818}
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829static int ncr_abort_command (ncb_p np, Scsi_Cmnd *cmd)
4830{
4831
4832 ccb_p cp;
4833 int found;
4834 int retv;
4835
4836
4837
4838
4839 if (remove_from_waiting_list(np, cmd)) {
4840 cmd->result = ScsiResult(DID_ABORT, 0);
4841 ncr_queue_done_cmd(np, cmd);
4842 return SCSI_ABORT_SUCCESS;
4843 }
4844
4845
4846
4847
4848 for (found=0, cp=np->ccb; cp; cp=cp->link_ccb) {
4849
4850
4851
4852 if (cp->host_status == HS_IDLE) continue;
4853 if (cp->cmd == cmd) {
4854 found = 1;
4855 break;
4856 }
4857 }
4858
4859 if (!found) {
4860 return SCSI_ABORT_NOT_RUNNING;
4861 }
4862
4863 if (np->settle_time) {
4864 return SCSI_ABORT_SNOOZE;
4865 }
4866
4867
4868
4869
4870
4871
4872 switch(cp->host_status) {
4873 case HS_BUSY:
4874 case HS_NEGOTIATE:
4875 printk ("%s: abort ccb=%p (cancel)\n", ncr_name (np), cp);
4876 cp->start.schedule.l_paddr =
4877 cpu_to_scr(NCB_SCRIPTH_PHYS (np, cancel));
4878 retv = SCSI_ABORT_PENDING;
4879 break;
4880 case HS_DISCONNECT:
4881 cp->restart.schedule.l_paddr =
4882 cpu_to_scr(NCB_SCRIPTH_PHYS (np, abort));
4883 retv = SCSI_ABORT_PENDING;
4884 break;
4885 default:
4886 retv = SCSI_ABORT_NOT_RUNNING;
4887 break;
4888
4889 }
4890
4891
4892
4893
4894
4895
4896 OUTB (nc_istat, SIGP);
4897
4898 return retv;
4899}
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912#ifdef MODULE
4913static int ncr_detach(ncb_p np)
4914{
4915 ccb_p cp;
4916 tcb_p tp;
4917 lcb_p lp;
4918 int target, lun;
4919 int i;
4920
4921 printk("%s: releasing host resources\n", ncr_name(np));
4922
4923
4924
4925
4926
4927
4928#ifdef DEBUG_NCR53C8XX
4929 printk("%s: stopping the timer\n", ncr_name(np));
4930#endif
4931 np->release_stage = 1;
4932 for (i = 50 ; i && np->release_stage != 2 ; i--) MDELAY (100);
4933 if (np->release_stage != 2)
4934 printk("%s: the timer seems to be already stopped\n", ncr_name(np));
4935 else np->release_stage = 2;
4936
4937
4938
4939
4940
4941#ifdef DEBUG_NCR53C8XX
4942 printk("%s: disabling chip interrupts\n", ncr_name(np));
4943#endif
4944 OUTW (nc_sien , 0);
4945 OUTB (nc_dien , 0);
4946
4947
4948
4949
4950
4951#ifdef DEBUG_NCR53C8XX
4952#ifdef __sparc__
4953 printk("%s: freeing irq %s\n", ncr_name(np), __irq_itoa(np->irq));
4954#else
4955 printk("%s: freeing irq %d\n", ncr_name(np), np->irq);
4956#endif
4957#endif
4958 free_irq(np->irq, np);
4959
4960
4961
4962
4963
4964
4965 printk("%s: resetting chip\n", ncr_name(np));
4966 OUTB (nc_istat, SRST);
4967 UDELAY (100);
4968 OUTB (nc_istat, 0 );
4969
4970 OUTB(nc_dmode, np->sv_dmode);
4971 OUTB(nc_dcntl, np->sv_dcntl);
4972 OUTB(nc_ctest3, np->sv_ctest3);
4973 OUTB(nc_ctest4, np->sv_ctest4);
4974 OUTB(nc_ctest5, np->sv_ctest5);
4975 OUTB(nc_gpcntl, np->sv_gpcntl);
4976 OUTB(nc_stest2, np->sv_stest2);
4977
4978 ncr_selectclock(np, np->sv_scntl3);
4979
4980
4981
4982
4983
4984#ifndef SCSI_NCR_IOMAPPED
4985#ifdef DEBUG_NCR53C8XX
4986 printk("%s: releasing memory mapped IO region %lx[%d]\n", ncr_name(np), (u_long) np->vaddr, 128);
4987#endif
4988 unmap_pci_mem((vm_offset_t) np->vaddr, (u_long) 128);
4989#endif
4990
4991#ifdef DEBUG_NCR53C8XX
4992 printk("%s: releasing IO region %x[%d]\n", ncr_name(np), np->base_io, 128);
4993#endif
4994 release_region(np->base_io, 128);
4995
4996
4997
4998
4999
5000 while ((cp=np->ccb->link_ccb) != NULL) {
5001 np->ccb->link_ccb = cp->link_ccb;
5002 if (cp->host_status) {
5003 printk("%s: shall free an active ccb (host_status=%d)\n",
5004 ncr_name(np), cp->host_status);
5005 }
5006#ifdef DEBUG_NCR53C8XX
5007 printk("%s: freeing ccb (%lx)\n", ncr_name(np), (u_long) cp);
5008#endif
5009 m_free_dma(cp, sizeof(*cp), "CCB");
5010 }
5011
5012
5013
5014
5015
5016 for (target = 0; target < MAX_TARGET ; target++) {
5017 tp=&np->target[target];
5018 for (lun = 0 ; lun < MAX_LUN ; lun++) {
5019 lp = tp->lp[lun];
5020 if (lp) {
5021#ifdef DEBUG_NCR53C8XX
5022 printk("%s: freeing lp (%lx)\n", ncr_name(np), (u_long) lp);
5023#endif
5024 if (lp->jump_ccb != &lp->jump_ccb_0)
5025 m_free_dma(lp->jump_ccb,256,"JUMP_CCB");
5026 m_free_dma(lp, sizeof(*lp), "LCB");
5027 }
5028 }
5029 }
5030
5031 if (np->scripth0)
5032 m_free_dma(np->scripth0, sizeof(struct scripth), "SCRIPTH");
5033 if (np->script0)
5034 m_free_dma(np->script0, sizeof(struct script), "SCRIPT");
5035 if (np->ccb)
5036 m_free_dma(np->ccb, sizeof(struct ccb), "CCB");
5037 m_free_dma(np, sizeof(struct ncb), "NCB");
5038
5039 printk("%s: host resources successfully released\n", ncr_name(np));
5040
5041 return 1;
5042}
5043#endif
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055void ncr_complete (ncb_p np, ccb_p cp)
5056{
5057 Scsi_Cmnd *cmd;
5058 tcb_p tp;
5059 lcb_p lp;
5060
5061
5062
5063
5064
5065 if (!cp || cp->magic != CCB_MAGIC || !cp->cmd)
5066 return;
5067
5068
5069
5070
5071
5072 if (DEBUG_FLAGS & DEBUG_TINY)
5073 printk ("CCB=%lx STAT=%x/%x\n", (unsigned long)cp,
5074 cp->host_status,cp->scsi_status);
5075
5076
5077
5078
5079
5080 cmd = cp->cmd;
5081 cp->cmd = NULL;
5082 tp = &np->target[cmd->target];
5083 lp = tp->lp[cmd->lun];
5084
5085
5086
5087
5088
5089
5090
5091 if (cp == tp->nego_cp)
5092 tp->nego_cp = 0;
5093
5094
5095
5096
5097 if (cp->auto_sense) {
5098 cp->scsi_status = cp->auto_sense;
5099 }
5100
5101
5102
5103
5104
5105
5106 if (lp && lp->held_ccb) {
5107 if (cp == lp->held_ccb) {
5108 xpt_que_splice(&lp->skip_ccbq, &lp->wait_ccbq);
5109 xpt_que_init(&lp->skip_ccbq);
5110 lp->held_ccb = 0;
5111 }
5112 }
5113
5114
5115
5116
5117
5118 if (cp->parity_status > 1) {
5119 PRINT_ADDR(cmd);
5120 printk ("%d parity error(s).\n",cp->parity_status);
5121 }
5122
5123
5124
5125
5126
5127 if (cp->xerr_status != XE_OK) {
5128 PRINT_ADDR(cmd);
5129 switch (cp->xerr_status) {
5130 case XE_EXTRA_DATA:
5131 printk ("extraneous data discarded.\n");
5132 break;
5133 case XE_BAD_PHASE:
5134 printk ("illegal scsi phase (4/5).\n");
5135 break;
5136 default:
5137 printk ("extended error %d.\n", cp->xerr_status);
5138 break;
5139 }
5140 if (cp->host_status==HS_COMPLETE)
5141 cp->host_status = HS_FAIL;
5142 }
5143
5144
5145
5146
5147 if (DEBUG_FLAGS & (DEBUG_RESULT|DEBUG_TINY)) {
5148 if (cp->host_status!=HS_COMPLETE || cp->scsi_status!=S_GOOD) {
5149 PRINT_ADDR(cmd);
5150 printk ("ERROR: cmd=%x host_status=%x scsi_status=%x\n",
5151 cmd->cmnd[0], cp->host_status, cp->scsi_status);
5152 }
5153 }
5154
5155
5156
5157
5158 if ( (cp->host_status == HS_COMPLETE)
5159 && (cp->scsi_status == S_GOOD ||
5160 cp->scsi_status == S_COND_MET)) {
5161
5162
5163
5164
5165
5166 cmd->result = ScsiResult(DID_OK, cp->scsi_status);
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178 if (!lp)
5179 ncr_alloc_lcb (np, cmd->target, cmd->lun);
5180
5181
5182
5183
5184
5185
5186 if (cmd->cmnd[0] == 0x12 && !(cmd->cmnd[1] & 0x3) &&
5187 cmd->cmnd[4] >= 7 && !cmd->use_sg) {
5188 sync_scsi_data(np, cmd);
5189 ncr_setup_lcb (np, cmd->target, cmd->lun,
5190 (char *) cmd->request_buffer);
5191 }
5192
5193 tp->bytes += cp->data_len;
5194 tp->transfers ++;
5195
5196
5197
5198
5199
5200 if (lp && lp->usetags && lp->numtags < lp->maxtags) {
5201 ++lp->num_good;
5202 if (lp->num_good >= 1000) {
5203 lp->num_good = 0;
5204 ++lp->numtags;
5205 ncr_setup_tags (np, cmd->target, cmd->lun);
5206 }
5207 }
5208 } else if ((cp->host_status == HS_COMPLETE)
5209 && (cp->scsi_status == S_CHECK_COND)) {
5210
5211
5212
5213 cmd->result = ScsiResult(DID_OK, S_CHECK_COND);
5214
5215
5216
5217
5218 memcpy(cmd->sense_buffer, cp->sense_buf,
5219 MIN(sizeof(cmd->sense_buffer), sizeof(cp->sense_buf)));
5220
5221 if (DEBUG_FLAGS & (DEBUG_RESULT|DEBUG_TINY)) {
5222 u_char * p = (u_char*) & cmd->sense_buffer;
5223 int i;
5224 PRINT_ADDR(cmd);
5225 printk ("sense data:");
5226 for (i=0; i<14; i++) printk (" %x", *p++);
5227 printk (".\n");
5228 }
5229 } else if ((cp->host_status == HS_COMPLETE)
5230 && (cp->scsi_status == S_CONFLICT)) {
5231
5232
5233
5234 cmd->result = ScsiResult(DID_OK, S_CONFLICT);
5235
5236 } else if ((cp->host_status == HS_COMPLETE)
5237 && (cp->scsi_status == S_BUSY ||
5238 cp->scsi_status == S_QUEUE_FULL)) {
5239
5240
5241
5242
5243 cmd->result = ScsiResult(DID_OK, cp->scsi_status);
5244
5245 } else if ((cp->host_status == HS_SEL_TIMEOUT)
5246 || (cp->host_status == HS_TIMEOUT)) {
5247
5248
5249
5250
5251 cmd->result = ScsiResult(DID_TIME_OUT, cp->scsi_status);
5252
5253 } else if (cp->host_status == HS_RESET) {
5254
5255
5256
5257
5258 cmd->result = ScsiResult(DID_RESET, cp->scsi_status);
5259
5260 } else if (cp->host_status == HS_ABORTED) {
5261
5262
5263
5264
5265 cmd->result = ScsiResult(DID_ABORT, cp->scsi_status);
5266
5267 } else {
5268
5269
5270
5271
5272 PRINT_ADDR(cmd);
5273 printk ("COMMAND FAILED (%x %x) @%p.\n",
5274 cp->host_status, cp->scsi_status, cp);
5275
5276 cmd->result = ScsiResult(DID_ERROR, cp->scsi_status);
5277 }
5278
5279
5280
5281
5282
5283 if (tp->usrflag & UF_TRACE) {
5284 u_char * p;
5285 int i;
5286 PRINT_ADDR(cmd);
5287 printk (" CMD:");
5288 p = (u_char*) &cmd->cmnd[0];
5289 for (i=0; i<cmd->cmd_len; i++) printk (" %x", *p++);
5290
5291 if (cp->host_status==HS_COMPLETE) {
5292 switch (cp->scsi_status) {
5293 case S_GOOD:
5294 printk (" GOOD");
5295 break;
5296 case S_CHECK_COND:
5297 printk (" SENSE:");
5298 p = (u_char*) &cmd->sense_buffer;
5299 for (i=0; i<14; i++)
5300 printk (" %x", *p++);
5301 break;
5302 default:
5303 printk (" STAT: %x\n", cp->scsi_status);
5304 break;
5305 }
5306 } else printk (" HOSTERROR: %x", cp->host_status);
5307 printk ("\n");
5308 }
5309
5310
5311
5312
5313 ncr_free_ccb (np, cp);
5314
5315
5316
5317
5318 if (lp && lp->queuedccbs < lp->queuedepth &&
5319 !xpt_que_empty(&lp->wait_ccbq))
5320 ncr_start_next_ccb(np, lp, 2);
5321
5322
5323
5324
5325 if (np->waiting_list)
5326 requeue_waiting_list(np);
5327
5328
5329
5330
5331 ncr_queue_done_cmd(np, cmd);
5332}
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347static void ncr_ccb_skipped(ncb_p np, ccb_p cp)
5348{
5349 tcb_p tp = &np->target[cp->target];
5350 lcb_p lp = tp->lp[cp->lun];
5351
5352 if (lp && cp != np->ccb) {
5353 cp->host_status &= ~HS_SKIPMASK;
5354 cp->start.schedule.l_paddr =
5355 cpu_to_scr(NCB_SCRIPT_PHYS (np, select));
5356 xpt_remque(&cp->link_ccbq);
5357 xpt_insque_tail(&cp->link_ccbq, &lp->skip_ccbq);
5358 if (cp->queued) {
5359 --lp->queuedccbs;
5360 }
5361 }
5362 if (cp->queued) {
5363 --np->queuedccbs;
5364 cp->queued = 0;
5365 }
5366}
5367
5368
5369
5370
5371
5372void ncr_wakeup_done (ncb_p np)
5373{
5374 ccb_p cp;
5375#ifdef SCSI_NCR_CCB_DONE_SUPPORT
5376 int i, j;
5377
5378 i = np->ccb_done_ic;
5379 while (1) {
5380 j = i+1;
5381 if (j >= MAX_DONE)
5382 j = 0;
5383
5384 cp = np->ccb_done[j];
5385 if (!CCB_DONE_VALID(cp))
5386 break;
5387
5388 np->ccb_done[j] = (ccb_p) CCB_DONE_EMPTY;
5389 np->scripth->done_queue[5*j + 4] =
5390 cpu_to_scr(NCB_SCRIPT_PHYS (np, done_plug));
5391 MEMORY_BARRIER();
5392 np->scripth->done_queue[5*i + 4] =
5393 cpu_to_scr(NCB_SCRIPT_PHYS (np, done_end));
5394
5395 if (cp->host_status & HS_DONEMASK)
5396 ncr_complete (np, cp);
5397 else if (cp->host_status & HS_SKIPMASK)
5398 ncr_ccb_skipped (np, cp);
5399
5400 i = j;
5401 }
5402 np->ccb_done_ic = i;
5403#else
5404 cp = np->ccb;
5405 while (cp) {
5406 if (cp->host_status & HS_DONEMASK)
5407 ncr_complete (np, cp);
5408 else if (cp->host_status & HS_SKIPMASK)
5409 ncr_ccb_skipped (np, cp);
5410 cp = cp->link_ccb;
5411 }
5412#endif
5413}
5414
5415
5416
5417
5418void ncr_wakeup (ncb_p np, u_long code)
5419{
5420 ccb_p cp = np->ccb;
5421
5422 while (cp) {
5423 if (cp->host_status != HS_IDLE) {
5424 cp->host_status = code;
5425 ncr_complete (np, cp);
5426 }
5427 cp = cp->link_ccb;
5428 }
5429}
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440void ncr_init (ncb_p np, int reset, char * msg, u_long code)
5441{
5442 int i;
5443
5444
5445
5446
5447
5448 if (reset) {
5449 OUTB (nc_istat, SRST);
5450 UDELAY (100);
5451 }
5452 else {
5453 OUTB (nc_stest3, TE|CSF);
5454 OUTONB (nc_ctest3, CLF);
5455 }
5456
5457
5458
5459
5460
5461 if (msg) printk (KERN_INFO "%s: restart (%s).\n", ncr_name (np), msg);
5462
5463
5464
5465
5466 np->queuedepth = MAX_START - 1;
5467 for (i = 1; i < MAX_START + MAX_START; i += 2)
5468 np->scripth0->tryloop[i] =
5469 cpu_to_scr(NCB_SCRIPT_PHYS (np, idle));
5470
5471
5472
5473
5474 np->squeueput = 0;
5475 np->script0->startpos[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np, tryloop));
5476
5477
5478
5479
5480 for (i = 0; i < MAX_DONE; i++) {
5481 np->ccb_done[i] = (ccb_p) CCB_DONE_EMPTY;
5482 np->scripth0->done_queue[5*i + 4] =
5483 cpu_to_scr(NCB_SCRIPT_PHYS (np, done_end));
5484 }
5485
5486
5487
5488
5489 np->script0->done_pos[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np,done_queue));
5490 np->ccb_done_ic = MAX_DONE-1;
5491 np->scripth0->done_queue[5*(MAX_DONE-1) + 4] =
5492 cpu_to_scr(NCB_SCRIPT_PHYS (np, done_plug));
5493
5494
5495
5496
5497 ncr_wakeup (np, code);
5498
5499
5500
5501
5502
5503 OUTB (nc_istat, 0x00 );
5504 UDELAY (2000);
5505
5506 OUTB (nc_scntl0, np->rv_scntl0 | 0xc0);
5507
5508 OUTB (nc_scntl1, 0x00);
5509
5510 ncr_selectclock(np, np->rv_scntl3);
5511
5512 OUTB (nc_scid , RRE|np->myaddr);
5513 OUTW (nc_respid, 1ul<<np->myaddr);
5514 OUTB (nc_istat , SIGP );
5515 OUTB (nc_dmode , np->rv_dmode);
5516 OUTB (nc_ctest5, np->rv_ctest5);
5517
5518 OUTB (nc_dcntl , NOCOM|np->rv_dcntl);
5519 OUTB (nc_ctest3, np->rv_ctest3);
5520 OUTB (nc_ctest4, np->rv_ctest4);
5521
5522 OUTB (nc_stest2, EXT|np->rv_stest2);
5523 OUTB (nc_stest3, TE);
5524 OUTB (nc_stime0, 0x0c );
5525
5526
5527
5528
5529
5530 np->disc = 0;
5531
5532
5533
5534
5535
5536 if (np->features & FE_LED0) {
5537 OUTOFFB (nc_gpcntl, 0x01);
5538 }
5539
5540
5541
5542
5543
5544 OUTW (nc_sien , STO|HTH|MA|SGE|UDC|RST|PAR);
5545 OUTB (nc_dien , MDPE|BF|ABRT|SSI|SIR|IID);
5546
5547
5548
5549
5550 if (np->features & FE_ULTRA2) {
5551 OUTONW (nc_sien, SBMC);
5552 np->scsi_mode = INB (nc_stest4) & SMODE;
5553 }
5554
5555
5556
5557
5558
5559
5560 if (np->device_id == PCI_DEVICE_ID_NCR_53C875)
5561 OUTB (nc_ctest0, (1<<5));
5562 else if (np->device_id == PCI_DEVICE_ID_NCR_53C896)
5563 OUTB (nc_ccntl0, DPR);
5564
5565
5566
5567
5568
5569
5570
5571
5572 for (i=0;i<MAX_TARGET;i++) {
5573 tcb_p tp = &np->target[i];
5574
5575 tp->sval = 0;
5576 tp->wval = np->rv_scntl3;
5577
5578 if (tp->usrsync != 255) {
5579 if (tp->usrsync <= np->maxsync) {
5580 if (tp->usrsync < np->minsync) {
5581 tp->usrsync = np->minsync;
5582 }
5583 }
5584 else
5585 tp->usrsync = 255;
5586 };
5587
5588 if (tp->usrwide > np->maxwide)
5589 tp->usrwide = np->maxwide;
5590
5591 ncr_negotiate (np, tp);
5592 }
5593
5594
5595
5596
5597 if (np->paddr2) {
5598 if (bootverbose)
5599 printk ("%s: Downloading SCSI SCRIPTS.\n",
5600 ncr_name(np));
5601 OUTL (nc_scratcha, vtobus(np->script0));
5602 OUTL_DSP (NCB_SCRIPTH_PHYS (np, start_ram));
5603 }
5604 else
5605 OUTL_DSP (NCB_SCRIPT_PHYS (np, start));
5606}
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616static void ncr_negotiate (struct ncb* np, struct tcb* tp)
5617{
5618
5619
5620
5621
5622 u_long minsync = tp->usrsync;
5623
5624
5625
5626
5627
5628 if (np->scsi_mode && np->scsi_mode == SMODE_SE) {
5629 if (minsync < 12) minsync = 12;
5630 }
5631
5632
5633
5634
5635
5636 if (minsync < np->minsync)
5637 minsync = np->minsync;
5638
5639
5640
5641
5642
5643 if (minsync > np->maxsync)
5644 minsync = 255;
5645
5646 tp->minsync = minsync;
5647 tp->maxoffs = (minsync<255 ? np->maxoffs : 0);
5648
5649
5650
5651
5652
5653 tp->period=0;
5654
5655
5656
5657
5658 tp->widedone=0;
5659}
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671static void ncr_getsync(ncb_p np, u_char sfac, u_char *fakp, u_char *scntl3p)
5672{
5673 u_long clk = np->clock_khz;
5674 int div = np->clock_divn;
5675 u_long fak;
5676 u_long per;
5677 u_long kpc;
5678
5679
5680
5681
5682 if (sfac <= 10) per = 250;
5683 else if (sfac == 11) per = 303;
5684 else if (sfac == 12) per = 500;
5685 else per = 40 * sfac;
5686
5687
5688
5689
5690
5691 kpc = per * clk;
5692 while (--div >= 0)
5693 if (kpc >= (div_10M[div] << 2)) break;
5694
5695
5696
5697
5698
5699 fak = (kpc - 1) / div_10M[div] + 1;
5700
5701#if 0
5702
5703 per = (fak * div_10M[div]) / clk;
5704
5705
5706
5707
5708
5709
5710 if (div >= 1 && fak < 8) {
5711 u_long fak2, per2;
5712 fak2 = (kpc - 1) / div_10M[div-1] + 1;
5713 per2 = (fak2 * div_10M[div-1]) / clk;
5714 if (per2 < per && fak2 <= 8) {
5715 fak = fak2;
5716 per = per2;
5717 --div;
5718 }
5719 }
5720#endif
5721
5722 if (fak < 4) fak = 4;
5723
5724
5725
5726
5727 *fakp = fak - 4;
5728 *scntl3p = ((div+1) << 4) + (sfac < 25 ? 0x80 : 0);
5729}
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740static void ncr_set_sync_wide_status (ncb_p np, u_char target)
5741{
5742 ccb_p cp;
5743 tcb_p tp = &np->target[target];
5744
5745
5746
5747
5748 OUTB (nc_sxfer, tp->sval);
5749 np->sync_st = tp->sval;
5750 OUTB (nc_scntl3, tp->wval);
5751 np->wide_st = tp->wval;
5752
5753
5754
5755
5756 for (cp = np->ccb; cp; cp = cp->link_ccb) {
5757 if (!cp->cmd) continue;
5758 if (cp->cmd->target != target) continue;
5759#if 0
5760 cp->sync_status = tp->sval;
5761 cp->wide_status = tp->wval;
5762#endif
5763 cp->phys.select.sel_scntl3 = tp->wval;
5764 cp->phys.select.sel_sxfer = tp->sval;
5765 };
5766}
5767
5768
5769
5770
5771
5772
5773
5774
5775static void ncr_setsync (ncb_p np, ccb_p cp, u_char scntl3, u_char sxfer)
5776{
5777 Scsi_Cmnd *cmd;
5778 tcb_p tp;
5779 u_char target = INB (nc_sdid) & 0x0f;
5780 u_char idiv;
5781
5782 assert (cp && cp->cmd);
5783 if (!cp) return;
5784
5785 cmd = cp->cmd;
5786 if (!cmd) return;
5787
5788 assert (target == (cmd->target & 0xf));
5789
5790 tp = &np->target[target];
5791
5792 if (!scntl3 || !(sxfer & 0x1f))
5793 scntl3 = np->rv_scntl3;
5794 scntl3 = (scntl3 & 0xf0) | (tp->wval & EWS) | (np->rv_scntl3 & 0x07);
5795
5796
5797
5798
5799
5800
5801 idiv = ((scntl3 >> 4) & 0x7);
5802 if ((sxfer & 0x1f) && idiv)
5803 tp->period = (((sxfer>>5)+4)*div_10M[idiv-1])/np->clock_khz;
5804 else
5805 tp->period = 0xffff;
5806
5807
5808
5809
5810 if (tp->sval == sxfer && tp->wval == scntl3) return;
5811 tp->sval = sxfer;
5812 tp->wval = scntl3;
5813
5814
5815
5816
5817 PRINT_TARGET(np, target);
5818 if (sxfer & 0x01f) {
5819 unsigned f10 = 100000 << (tp->widedone ? tp->widedone -1 : 0);
5820 unsigned mb10 = (f10 + tp->period/2) / tp->period;
5821 char *scsi;
5822
5823
5824
5825
5826 if (tp->period <= 2000) OUTOFFB (nc_stest2, EXT);
5827
5828
5829
5830
5831 if (tp->period < 500) scsi = "FAST-40";
5832 else if (tp->period < 1000) scsi = "FAST-20";
5833 else if (tp->period < 2000) scsi = "FAST-10";
5834 else scsi = "FAST-5";
5835
5836 printk ("%s %sSCSI %d.%d MB/s (%d ns, offset %d)\n", scsi,
5837 tp->widedone > 1 ? "WIDE " : "",
5838 mb10 / 10, mb10 % 10, tp->period / 10, sxfer & 0x1f);
5839 } else
5840 printk ("%sasynchronous.\n", tp->widedone > 1 ? "wide " : "");
5841
5842
5843
5844
5845
5846 ncr_set_sync_wide_status(np, target);
5847}
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859static void ncr_setwide (ncb_p np, ccb_p cp, u_char wide, u_char ack)
5860{
5861 Scsi_Cmnd *cmd;
5862 u_short target = INB (nc_sdid) & 0x0f;
5863 tcb_p tp;
5864 u_char scntl3;
5865 u_char sxfer;
5866
5867 assert (cp && cp->cmd);
5868 if (!cp) return;
5869
5870 cmd = cp->cmd;
5871 if (!cmd) return;
5872
5873 assert (target == (cmd->target & 0xf));
5874
5875 tp = &np->target[target];
5876 tp->widedone = wide+1;
5877 scntl3 = (tp->wval & (~EWS)) | (wide ? EWS : 0);
5878
5879 sxfer = ack ? 0 : tp->sval;
5880
5881
5882
5883
5884 if (tp->sval == sxfer && tp->wval == scntl3) return;
5885 tp->sval = sxfer;
5886 tp->wval = scntl3;
5887
5888
5889
5890
5891 if (bootverbose >= 2) {
5892 PRINT_TARGET(np, target);
5893 if (scntl3 & EWS)
5894 printk ("WIDE SCSI (16 bit) enabled.\n");
5895 else
5896 printk ("WIDE SCSI disabled.\n");
5897 }
5898
5899
5900
5901
5902
5903 ncr_set_sync_wide_status(np, target);
5904}
5905
5906
5907
5908
5909
5910
5911
5912
5913static void ncr_setup_tags (ncb_p np, u_char tn, u_char ln)
5914{
5915 tcb_p tp = &np->target[tn];
5916 lcb_p lp = tp->lp[ln];
5917 u_char reqtags, maxdepth;
5918
5919
5920
5921
5922 if ((!tp) || (!lp))
5923 return;
5924
5925
5926
5927
5928 if (!lp->scdev_depth)
5929 return;
5930
5931
5932
5933
5934
5935
5936 maxdepth = lp->scdev_depth;
5937 if (maxdepth > lp->maxnxs) maxdepth = lp->maxnxs;
5938 if (lp->maxtags > maxdepth) lp->maxtags = maxdepth;
5939 if (lp->numtags > maxdepth) lp->numtags = maxdepth;
5940
5941
5942
5943
5944
5945
5946 if ((lp->inq_byte7 & INQ7_QUEUE) && lp->numtags > 1) {
5947 reqtags = lp->numtags;
5948 } else {
5949 reqtags = 1;
5950 };
5951
5952
5953
5954
5955 lp->numtags = reqtags;
5956 if (lp->numtags > lp->maxtags)
5957 lp->maxtags = lp->numtags;
5958
5959
5960
5961
5962
5963 if (reqtags > 1 && lp->usetags) {
5964 if (lp->queuedepth == reqtags)
5965 return;
5966 lp->queuedepth = reqtags;
5967 }
5968 else if (reqtags <= 1 && !lp->usetags) {
5969 lp->queuedepth = reqtags;
5970 return;
5971 }
5972 else {
5973 if (lp->busyccbs)
5974 return;
5975 lp->queuedepth = reqtags;
5976 lp->usetags = reqtags > 1 ? 1 : 0;
5977 }
5978
5979
5980
5981
5982 lp->jump_tag.l_paddr = lp->usetags?
5983 cpu_to_scr(NCB_SCRIPT_PHYS(np, resel_tag)) :
5984 cpu_to_scr(NCB_SCRIPT_PHYS(np, resel_notag));
5985
5986
5987
5988
5989 if (bootverbose) {
5990 PRINT_LUN(np, tn, ln);
5991 if (lp->usetags) {
5992 printk("tagged command queue depth set to %d\n", reqtags);
5993 }
5994 else {
5995 printk("tagged command queueing disabled\n");
5996 }
5997 }
5998}
5999
6000
6001
6002
6003
6004
6005
6006
6007#ifdef SCSI_NCR_USER_COMMAND_SUPPORT
6008
6009static void ncr_usercmd (ncb_p np)
6010{
6011 u_char t;
6012 tcb_p tp;
6013
6014 switch (np->user.cmd) {
6015
6016 case 0: return;
6017
6018 case UC_SETSYNC:
6019 for (t=0; t<MAX_TARGET; t++) {
6020 if (!((np->user.target>>t)&1)) continue;
6021 tp = &np->target[t];
6022 tp->usrsync = np->user.data;
6023 ncr_negotiate (np, tp);
6024 };
6025 break;
6026
6027 case UC_SETTAGS:
6028 for (t=0; t<MAX_TARGET; t++) {
6029 int ln;
6030 if (!((np->user.target>>t)&1)) continue;
6031 np->target[t].usrtags = np->user.data;
6032 for (ln = 0; ln < MAX_LUN; ln++) {
6033 lcb_p lp = np->target[t].lp[ln];
6034 if (!lp)
6035 continue;
6036 lp->maxtags = lp->numtags = np->user.data;
6037 ncr_setup_tags (np, t, ln);
6038 }
6039 };
6040 break;
6041
6042 case UC_SETDEBUG:
6043#ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
6044 ncr_debug = np->user.data;
6045#endif
6046 break;
6047
6048 case UC_SETORDER:
6049 np->order = np->user.data;
6050 break;
6051
6052 case UC_SETVERBOSE:
6053 np->verbose = np->user.data;
6054 break;
6055
6056 case UC_SETWIDE:
6057 for (t=0; t<MAX_TARGET; t++) {
6058 u_long size;
6059 if (!((np->user.target>>t)&1)) continue;
6060 tp = &np->target[t];
6061 size = np->user.data;
6062 if (size > np->maxwide) size=np->maxwide;
6063 tp->usrwide = size;
6064 ncr_negotiate (np, tp);
6065 };
6066 break;
6067
6068 case UC_SETFLAG:
6069 for (t=0; t<MAX_TARGET; t++) {
6070 if (!((np->user.target>>t)&1)) continue;
6071 tp = &np->target[t];
6072 tp->usrflag = np->user.data;
6073 };
6074 break;
6075 }
6076 np->user.cmd=0;
6077}
6078#endif
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094static void ncr_timeout (ncb_p np)
6095{
6096 u_long thistime = ktime_get(0);
6097
6098
6099
6100
6101
6102
6103
6104 if (np->release_stage) {
6105 if (np->release_stage == 1) np->release_stage = 2;
6106 return;
6107 }
6108
6109 np->timer.expires = ktime_get(SCSI_NCR_TIMER_INTERVAL);
6110 add_timer(&np->timer);
6111
6112
6113
6114
6115
6116 if (np->settle_time) {
6117 if (np->settle_time <= thistime) {
6118 if (bootverbose > 1)
6119 printk("%s: command processing resumed\n", ncr_name(np));
6120 np->settle_time = 0;
6121 np->disc = 1;
6122 requeue_waiting_list(np);
6123 }
6124 return;
6125 }
6126
6127
6128
6129
6130
6131
6132 if (np->lasttime + 4*HZ < thistime) {
6133
6134
6135
6136 np->lasttime = thistime;
6137 }
6138
6139#ifdef SCSI_NCR_BROKEN_INTR
6140 if (INB(nc_istat) & (INTF|SIP|DIP)) {
6141
6142
6143
6144
6145 if (DEBUG_FLAGS & DEBUG_TINY) printk ("{");
6146 ncr_exception (np);
6147 if (DEBUG_FLAGS & DEBUG_TINY) printk ("}");
6148 }
6149#endif
6150}
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182static void ncr_log_hard_error(ncb_p np, u_short sist, u_char dstat)
6183{
6184 u_int32 dsp;
6185 int script_ofs;
6186 int script_size;
6187 char *script_name;
6188 u_char *script_base;
6189 int i;
6190
6191 dsp = INL (nc_dsp);
6192
6193 if (dsp > np->p_script && dsp <= np->p_script + sizeof(struct script)) {
6194 script_ofs = dsp - np->p_script;
6195 script_size = sizeof(struct script);
6196 script_base = (u_char *) np->script0;
6197 script_name = "script";
6198 }
6199 else if (np->p_scripth < dsp &&
6200 dsp <= np->p_scripth + sizeof(struct scripth)) {
6201 script_ofs = dsp - np->p_scripth;
6202 script_size = sizeof(struct scripth);
6203 script_base = (u_char *) np->scripth0;
6204 script_name = "scripth";
6205 } else {
6206 script_ofs = dsp;
6207 script_size = 0;
6208 script_base = 0;
6209 script_name = "mem";
6210 }
6211
6212 printk ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x) @ (%s %x:%08x).\n",
6213 ncr_name (np), (unsigned)INB (nc_sdid)&0x0f, dstat, sist,
6214 (unsigned)INB (nc_socl), (unsigned)INB (nc_sbcl), (unsigned)INB (nc_sbdl),
6215 (unsigned)INB (nc_sxfer),(unsigned)INB (nc_scntl3), script_name, script_ofs,
6216 (unsigned)INL (nc_dbc));
6217
6218 if (((script_ofs & 3) == 0) &&
6219 (unsigned)script_ofs < script_size) {
6220 printk ("%s: script cmd = %08x\n", ncr_name(np),
6221 scr_to_cpu((int) *(ncrcmd *)(script_base + script_ofs)));
6222 }
6223
6224 printk ("%s: regdump:", ncr_name(np));
6225 for (i=0; i<16;i++)
6226 printk (" %02x", (unsigned)INB_OFF(i));
6227 printk (".\n");
6228}
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262void ncr_exception (ncb_p np)
6263{
6264 u_char istat, dstat;
6265 u_short sist;
6266 int i;
6267
6268
6269
6270
6271
6272
6273
6274
6275 istat = INB (nc_istat);
6276 if (istat & INTF) {
6277 OUTB (nc_istat, (istat & SIGP) | INTF);
6278 istat = INB (nc_istat);
6279 if (DEBUG_FLAGS & DEBUG_TINY) printk ("F ");
6280 ncr_wakeup_done (np);
6281 };
6282
6283 if (!(istat & (SIP|DIP)))
6284 return;
6285
6286 if (istat & CABRT)
6287 OUTB (nc_istat, CABRT);
6288
6289
6290
6291
6292
6293
6294 sist = (istat & SIP) ? INW (nc_sist) : 0;
6295 dstat = (istat & DIP) ? INB (nc_dstat) : 0;
6296
6297 if (DEBUG_FLAGS & DEBUG_TINY)
6298 printk ("<%d|%x:%x|%x:%x>",
6299 (int)INB(nc_scr0),
6300 dstat,sist,
6301 (unsigned)INL(nc_dsp),
6302 (unsigned)INL(nc_dbc));
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317 if (!(sist & (STO|GEN|HTH|SGE|UDC|RST)) &&
6318 !(dstat & (MDPE|BF|ABRT|IID))) {
6319 if ((sist & SBMC) && ncr_int_sbmc (np))
6320 return;
6321 if ((sist & PAR) && ncr_int_par (np))
6322 return;
6323 if (sist & MA) {
6324 ncr_int_ma (np);
6325 return;
6326 }
6327 if (dstat & SIR) {
6328 ncr_int_sir (np);
6329 return;
6330 }
6331
6332
6333
6334 if (!(sist & (SBMC|PAR)) && !(dstat & SSI)) {
6335 printk( "%s: unknown interrupt(s) ignored, "
6336 "ISTAT=%x DSTAT=%x SIST=%x\n",
6337 ncr_name(np), istat, dstat, sist);
6338 return;
6339 }
6340 OUTONB_STD ();
6341 return;
6342 };
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359 if (sist & RST) {
6360 ncr_init (np, 1, bootverbose ? "scsi reset" : NULL, HS_RESET);
6361 return;
6362 };
6363
6364 if ((sist & STO) &&
6365 !(dstat & (MDPE|BF|ABRT))) {
6366
6367
6368
6369 OUTONB (nc_ctest3, CLF);
6370
6371 ncr_int_sto (np);
6372 return;
6373 };
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388 if (ktime_exp(np->regtime)) {
6389 np->regtime = ktime_get(10*HZ);
6390 for (i = 0; i<sizeof(np->regdump); i++)
6391 ((char*)&np->regdump)[i] = INB_OFF(i);
6392 np->regdump.nc_dstat = dstat;
6393 np->regdump.nc_sist = sist;
6394 };
6395
6396 ncr_log_hard_error(np, sist, dstat);
6397
6398 printk ("%s: have to clear fifos.\n", ncr_name (np));
6399 OUTB (nc_stest3, TE|CSF);
6400 OUTONB (nc_ctest3, CLF);
6401
6402 if ((sist & (SGE)) ||
6403 (dstat & (MDPE|BF|ABRT|IID))) {
6404 ncr_start_reset(np);
6405 return;
6406 };
6407
6408 if (sist & HTH) {
6409 printk ("%s: handshake timeout\n", ncr_name(np));
6410 ncr_start_reset(np);
6411 return;
6412 };
6413
6414 if (sist & UDC) {
6415 printk ("%s: unexpected disconnect\n", ncr_name(np));
6416 OUTB (HS_PRT, HS_UNEXPECTED);
6417 OUTL_DSP (NCB_SCRIPT_PHYS (np, cleanup));
6418 return;
6419 };
6420
6421
6422
6423
6424
6425
6426 printk ("%s: unknown interrupt\n", ncr_name(np));
6427}
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445void ncr_int_sto (ncb_p np)
6446{
6447 u_long dsa;
6448 ccb_p cp;
6449 if (DEBUG_FLAGS & DEBUG_TINY) printk ("T");
6450
6451
6452
6453
6454
6455 dsa = INL (nc_dsa);
6456 cp = np->ccb;
6457 while (cp && (CCB_PHYS (cp, phys) != dsa))
6458 cp = cp->link_ccb;
6459
6460 if (cp) {
6461 cp-> host_status = HS_SEL_TIMEOUT;
6462 ncr_complete (np, cp);
6463 };
6464
6465
6466
6467
6468
6469 OUTL_DSP (NCB_SCRIPTH_PHYS (np, sto_restart));
6470 return;
6471}
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490static int ncr_int_sbmc (ncb_p np)
6491{
6492 u_char scsi_mode = INB (nc_stest4) & SMODE;
6493
6494 if (scsi_mode != np->scsi_mode) {
6495 printk("%s: SCSI bus mode change from %x to %x.\n",
6496 ncr_name(np), np->scsi_mode, scsi_mode);
6497
6498 np->scsi_mode = scsi_mode;
6499
6500
6501
6502
6503
6504
6505 np->settle_time = ktime_get(1*HZ);
6506 ncr_init (np, 0, bootverbose ? "scsi mode change" : NULL, HS_RESET);
6507 return 1;
6508 }
6509 return 0;
6510}
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522static int ncr_int_par (ncb_p np)
6523{
6524 u_char hsts = INB (HS_PRT);
6525 u_int32 dbc = INL (nc_dbc);
6526 u_char sstat1 = INB (nc_sstat1);
6527 int phase = -1;
6528 int msg = -1;
6529 u_int32 jmp;
6530
6531 printk("%s: SCSI parity error detected: SCR1=%d DBC=%x SSTAT1=%x\n",
6532 ncr_name(np), hsts, dbc, sstat1);
6533
6534
6535
6536
6537
6538
6539 if (!(INB (nc_scntl1) & ISCON))
6540 return 0;
6541
6542
6543
6544
6545
6546 if (hsts & HS_INVALMASK)
6547 goto reset_all;
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557 if (!(dbc & 0xc0000000))
6558 phase = (dbc >> 24) & 7;
6559 if (phase == 7)
6560 msg = M_PARITY;
6561 else
6562 msg = M_ID_ERROR;
6563
6564#ifdef SCSI_NCR_INTEGRITY_CHECKING
6565
6566
6567
6568 if (np->check_integrity)
6569 np->check_integ_par = msg;
6570#endif
6571
6572
6573
6574
6575
6576
6577
6578 if (phase == 1)
6579 jmp = NCB_SCRIPTH_PHYS (np, par_err_data_in);
6580 else
6581 jmp = NCB_SCRIPTH_PHYS (np, par_err_other);
6582
6583 OUTONB (nc_ctest3, CLF );
6584 OUTB (nc_stest3, TE|CSF);
6585
6586 np->msgout[0] = msg;
6587 OUTL_DSP (jmp);
6588 return 1;
6589
6590reset_all:
6591 ncr_start_reset(np);
6592 return 1;
6593}
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609static void ncr_int_ma (ncb_p np)
6610{
6611 u_int32 dbc;
6612 u_int32 rest;
6613 u_int32 dsp;
6614 u_int32 dsa;
6615 u_int32 nxtdsp;
6616 u_int32 newtmp;
6617 u_int32 *vdsp;
6618 u_int32 oadr, olen;
6619 u_int32 *tblp;
6620 ncrcmd *newcmd;
6621 u_char cmd, sbcl;
6622 ccb_p cp;
6623
6624 dsp = INL (nc_dsp);
6625 dbc = INL (nc_dbc);
6626 sbcl = INB (nc_sbcl);
6627
6628 cmd = dbc >> 24;
6629 rest = dbc & 0xffffff;
6630
6631
6632
6633
6634
6635
6636 if ((cmd & 1) == 0) {
6637 u_char ctest5, ss0, ss2;
6638 u_short delta;
6639
6640 ctest5 = (np->rv_ctest5 & DFS) ? INB (nc_ctest5) : 0;
6641 if (ctest5 & DFS)
6642 delta=(((ctest5 << 8) | (INB (nc_dfifo) & 0xff)) - rest) & 0x3ff;
6643 else
6644 delta=(INB (nc_dfifo) - rest) & 0x7f;
6645
6646
6647
6648
6649
6650
6651
6652
6653 rest += delta;
6654 ss0 = INB (nc_sstat0);
6655 if (ss0 & OLF) rest++;
6656 if (ss0 & ORF) rest++;
6657 if (INB(nc_scntl3) & EWS) {
6658 ss2 = INB (nc_sstat2);
6659 if (ss2 & OLF1) rest++;
6660 if (ss2 & ORF1) rest++;
6661 };
6662
6663 if (DEBUG_FLAGS & (DEBUG_TINY|DEBUG_PHASE))
6664 printk ("P%x%x RL=%d D=%d SS0=%x ", cmd&7, sbcl&7,
6665 (unsigned) rest, (unsigned) delta, ss0);
6666
6667 } else {
6668 if (DEBUG_FLAGS & (DEBUG_TINY|DEBUG_PHASE))
6669 printk ("P%x%x RL=%d ", cmd&7, sbcl&7, rest);
6670 }
6671
6672
6673
6674
6675 OUTONB (nc_ctest3, CLF );
6676 OUTB (nc_stest3, TE|CSF);
6677
6678
6679
6680
6681
6682
6683 dsa = INL (nc_dsa);
6684 if (!(cmd & 6)) {
6685 cp = np->header.cp;
6686 if (CCB_PHYS(cp, phys) != dsa)
6687 cp = 0;
6688 } else {
6689 cp = np->ccb;
6690 while (cp && (CCB_PHYS (cp, phys) != dsa))
6691 cp = cp->link_ccb;
6692 }
6693
6694
6695
6696
6697
6698 vdsp = 0;
6699 nxtdsp = 0;
6700 if (dsp > np->p_script &&
6701 dsp <= np->p_script + sizeof(struct script)) {
6702 vdsp = (u_int32 *)((char*)np->script0 + (dsp-np->p_script-8));
6703 nxtdsp = dsp;
6704 }
6705 else if (dsp > np->p_scripth &&
6706 dsp <= np->p_scripth + sizeof(struct scripth)) {
6707 vdsp = (u_int32 *)((char*)np->scripth0 + (dsp-np->p_scripth-8));
6708 nxtdsp = dsp;
6709 }
6710 else if (cp) {
6711 if (dsp == CCB_PHYS (cp, patch[2])) {
6712 vdsp = &cp->patch[0];
6713 nxtdsp = scr_to_cpu(vdsp[3]);
6714 }
6715 else if (dsp == CCB_PHYS (cp, patch[6])) {
6716 vdsp = &cp->patch[4];
6717 nxtdsp = scr_to_cpu(vdsp[3]);
6718 }
6719 }
6720
6721
6722
6723
6724
6725 if (DEBUG_FLAGS & DEBUG_PHASE) {
6726 printk ("\nCP=%p CP2=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
6727 cp, np->header.cp,
6728 (unsigned)dsp,
6729 (unsigned)nxtdsp, vdsp, cmd);
6730 };
6731
6732
6733
6734
6735
6736
6737
6738 if (!cp) {
6739 printk ("%s: SCSI phase error fixup: "
6740 "CCB already dequeued (0x%08lx)\n",
6741 ncr_name (np), (u_long) np->header.cp);
6742 goto reset_all;
6743 }
6744
6745
6746
6747
6748
6749 oadr = scr_to_cpu(vdsp[1]);
6750
6751 if (cmd & 0x10) {
6752 tblp = (u_int32 *) ((char*) &cp->phys + oadr);
6753 olen = scr_to_cpu(tblp[0]);
6754 oadr = scr_to_cpu(tblp[1]);
6755 } else {
6756 tblp = (u_int32 *) 0;
6757 olen = scr_to_cpu(vdsp[0]) & 0xffffff;
6758 };
6759
6760 if (DEBUG_FLAGS & DEBUG_PHASE) {
6761 printk ("OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
6762 (unsigned) (scr_to_cpu(vdsp[0]) >> 24),
6763 tblp,
6764 (unsigned) olen,
6765 (unsigned) oadr);
6766 };
6767
6768
6769
6770
6771
6772 if (cmd != (scr_to_cpu(vdsp[0]) >> 24)) {
6773 PRINT_ADDR(cp->cmd);
6774 printk ("internal error: cmd=%02x != %02x=(vdsp[0] >> 24)\n",
6775 (unsigned)cmd, (unsigned)scr_to_cpu(vdsp[0]) >> 24);
6776
6777 goto reset_all;
6778 }
6779
6780
6781
6782
6783
6784
6785
6786 if (cp != np->header.cp) {
6787 printk ("%s: SCSI phase error fixup: "
6788 "CCB address mismatch (0x%08lx != 0x%08lx)\n",
6789 ncr_name (np), (u_long) cp, (u_long) np->header.cp);
6790 }
6791
6792
6793
6794
6795
6796 if (cmd & 0x06) {
6797 PRINT_ADDR(cp->cmd);
6798 printk ("phase change %x-%x %d@%08x resid=%d.\n",
6799 cmd&7, sbcl&7, (unsigned)olen,
6800 (unsigned)oadr, (unsigned)rest);
6801 goto unexpected_phase;
6802 };
6803
6804
6805
6806
6807
6808
6809 newcmd = cp->patch;
6810 newtmp = CCB_PHYS (cp, patch);
6811 if (newtmp == scr_to_cpu(cp->phys.header.savep)) {
6812 newcmd = &cp->patch[4];
6813 newtmp = CCB_PHYS (cp, patch[4]);
6814 }
6815
6816
6817
6818
6819
6820 newcmd[0] = cpu_to_scr(((cmd & 0x0f) << 24) | rest);
6821 newcmd[1] = cpu_to_scr(oadr + olen - rest);
6822 newcmd[2] = cpu_to_scr(SCR_JUMP);
6823 newcmd[3] = cpu_to_scr(nxtdsp);
6824
6825 if (DEBUG_FLAGS & DEBUG_PHASE) {
6826 PRINT_ADDR(cp->cmd);
6827 printk ("newcmd[%d] %x %x %x %x.\n",
6828 (int) (newcmd - cp->patch),
6829 (unsigned)scr_to_cpu(newcmd[0]),
6830 (unsigned)scr_to_cpu(newcmd[1]),
6831 (unsigned)scr_to_cpu(newcmd[2]),
6832 (unsigned)scr_to_cpu(newcmd[3]));
6833 }
6834
6835
6836
6837
6838 OUTL (nc_temp, newtmp);
6839 OUTL_DSP (NCB_SCRIPT_PHYS (np, dispatch));
6840 return;
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869unexpected_phase:
6870 dsp -= 8;
6871 nxtdsp = 0;
6872
6873 switch (cmd & 7) {
6874 case 2:
6875 nxtdsp = NCB_SCRIPT_PHYS (np, dispatch);
6876 break;
6877#if 0
6878 case 3:
6879 nxtdsp = NCB_SCRIPT_PHYS (np, dispatch);
6880 break;
6881#endif
6882 case 6:
6883 np->scripth->nxtdsp_go_on[0] = cpu_to_scr(dsp + 8);
6884 if (dsp == NCB_SCRIPT_PHYS (np, send_ident)) {
6885 cp->host_status = HS_BUSY;
6886 nxtdsp = NCB_SCRIPTH_PHYS (np, clratn_go_on);
6887 }
6888 else if (dsp == NCB_SCRIPTH_PHYS (np, send_wdtr) ||
6889 dsp == NCB_SCRIPTH_PHYS (np, send_sdtr)) {
6890 nxtdsp = NCB_SCRIPTH_PHYS (np, nego_bad_phase);
6891 }
6892 break;
6893#if 0
6894 case 7:
6895 nxtdsp = NCB_SCRIPT_PHYS (np, clrack);
6896 break;
6897#endif
6898 }
6899
6900 if (nxtdsp) {
6901 OUTL_DSP (nxtdsp);
6902 return;
6903 }
6904
6905reset_all:
6906 ncr_start_reset(np);
6907}
6908
6909
6910static void ncr_sir_to_redo(ncb_p np, int num, ccb_p cp)
6911{
6912 Scsi_Cmnd *cmd = cp->cmd;
6913 tcb_p tp = &np->target[cmd->target];
6914 lcb_p lp = tp->lp[cmd->lun];
6915 XPT_QUEHEAD *qp;
6916 ccb_p cp2;
6917 int disc_cnt = 0;
6918 int busy_cnt = 0;
6919 u_int32 startp;
6920 u_char s_status = INB (SS_PRT);
6921
6922
6923
6924
6925
6926
6927
6928 if (lp) {
6929 qp = lp->busy_ccbq.blink;
6930 while (qp != &lp->busy_ccbq) {
6931 cp2 = xpt_que_entry(qp, struct ccb, link_ccbq);
6932 qp = qp->blink;
6933 ++busy_cnt;
6934 if (cp2 == cp)
6935 break;
6936 cp2->start.schedule.l_paddr =
6937 cpu_to_scr(NCB_SCRIPTH_PHYS (np, skip));
6938 }
6939 lp->held_ccb = cp;
6940 disc_cnt = lp->queuedccbs - busy_cnt;
6941 }
6942
6943 switch(s_status) {
6944 default:
6945 case S_QUEUE_FULL:
6946
6947
6948
6949
6950 if (!lp)
6951 goto out;
6952 if (bootverbose >= 1) {
6953 PRINT_ADDR(cmd);
6954 printk ("QUEUE FULL! %d busy, %d disconnected CCBs\n",
6955 busy_cnt, disc_cnt);
6956 }
6957 if (disc_cnt < lp->numtags) {
6958 lp->numtags = disc_cnt > 2 ? disc_cnt : 2;
6959 lp->num_good = 0;
6960 ncr_setup_tags (np, cmd->target, cmd->lun);
6961 }
6962
6963
6964
6965
6966
6967
6968 cp->phys.header.savep = cp->startp;
6969 cp->host_status = HS_BUSY;
6970 cp->scsi_status = S_ILLEGAL;
6971
6972 ncr_put_start_queue(np, cp);
6973 if (disc_cnt)
6974 INB (nc_ctest2);
6975 OUTL_DSP (NCB_SCRIPT_PHYS (np, reselect));
6976 return;
6977 case S_TERMINATED:
6978 case S_CHECK_COND:
6979
6980
6981
6982 if (cp->auto_sense)
6983 goto out;
6984
6985
6986
6987
6988
6989
6990
6991
6992 cp->scsi_smsg2[0] = M_IDENTIFY | cmd->lun;
6993 cp->phys.smsg.addr = cpu_to_scr(CCB_PHYS (cp, scsi_smsg2));
6994 cp->phys.smsg.size = cpu_to_scr(1);
6995
6996
6997
6998
6999 cp->phys.cmd.addr = cpu_to_scr(CCB_PHYS (cp, sensecmd));
7000 cp->phys.cmd.size = cpu_to_scr(6);
7001
7002
7003
7004
7005 cp->sensecmd[0] = 0x03;
7006 cp->sensecmd[1] = cmd->lun << 5;
7007 cp->sensecmd[4] = sizeof(cp->sense_buf);
7008
7009
7010
7011
7012 bzero(cp->sense_buf, sizeof(cp->sense_buf));
7013 cp->phys.sense.addr = cpu_to_scr(CCB_PHYS(cp,sense_buf[0]));
7014 cp->phys.sense.size = cpu_to_scr(sizeof(cp->sense_buf));
7015
7016
7017
7018
7019 startp = cpu_to_scr(NCB_SCRIPTH_PHYS (np, sdata_in));
7020
7021 cp->phys.header.savep = startp;
7022 cp->phys.header.goalp = startp + 24;
7023 cp->phys.header.lastp = startp;
7024 cp->phys.header.wgoalp = startp + 24;
7025 cp->phys.header.wlastp = startp;
7026
7027 cp->host_status = HS_BUSY;
7028 cp->scsi_status = S_ILLEGAL;
7029 cp->auto_sense = s_status;
7030
7031 cp->start.schedule.l_paddr =
7032 cpu_to_scr(NCB_SCRIPT_PHYS (np, select));
7033
7034
7035
7036
7037 if (tp->quirks & QUIRK_NOMSG)
7038 cp->start.schedule.l_paddr =
7039 cpu_to_scr(NCB_SCRIPTH_PHYS (np, select_no_atn));
7040
7041 ncr_put_start_queue(np, cp);
7042
7043 OUTL_DSP (NCB_SCRIPT_PHYS (np, start));
7044 return;
7045 }
7046
7047out:
7048 OUTONB_STD ();
7049 return;
7050}
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062static int ncr_show_msg (u_char * msg)
7063{
7064 u_char i;
7065 printk ("%x",*msg);
7066 if (*msg==M_EXTENDED) {
7067 for (i=1;i<8;i++) {
7068 if (i-1>msg[1]) break;
7069 printk ("-%x",msg[i]);
7070 };
7071 return (i+1);
7072 } else if ((*msg & 0xf0) == 0x20) {
7073 printk ("-%x",msg[1]);
7074 return (2);
7075 };
7076 return (1);
7077}
7078
7079static void ncr_print_msg ( ccb_p cp, char *label, u_char *msg)
7080{
7081 if (cp)
7082 PRINT_ADDR(cp->cmd);
7083 if (label)
7084 printk("%s: ", label);
7085
7086 (void) ncr_show_msg (msg);
7087 printk(".\n");
7088}
7089
7090void ncr_int_sir (ncb_p np)
7091{
7092 u_char scntl3;
7093 u_char chg, ofs, per, fak, wide;
7094 u_char num = INB (nc_dsps);
7095 ccb_p cp=0;
7096 u_long dsa = INL (nc_dsa);
7097 u_char target = INB (nc_sdid) & 0x0f;
7098 tcb_p tp = &np->target[target];
7099
7100 if (DEBUG_FLAGS & DEBUG_TINY) printk ("I#%d", num);
7101
7102 switch (num) {
7103 case SIR_RESEL_NO_MSG_IN:
7104 case SIR_RESEL_NO_IDENTIFY:
7105
7106
7107
7108
7109
7110 if (tp->lp[0]) {
7111 OUTL_DSP (scr_to_cpu(tp->lp[0]->jump_ccb[0]));
7112 return;
7113 }
7114 case SIR_RESEL_BAD_TARGET:
7115 case SIR_RESEL_BAD_LUN:
7116 case SIR_RESEL_BAD_I_T_L_Q:
7117 case SIR_RESEL_BAD_I_T_L:
7118 printk ("%s:%d: SIR %d, "
7119 "incorrect nexus identification on reselection\n",
7120 ncr_name (np), target, num);
7121 goto out;
7122 case SIR_DONE_OVERFLOW:
7123 printk ("%s:%d: SIR %d, "
7124 "CCB done queue overflow\n",
7125 ncr_name (np), target, num);
7126 goto out;
7127 case SIR_BAD_STATUS:
7128 cp = np->header.cp;
7129 if (!cp || CCB_PHYS (cp, phys) != dsa)
7130 goto out;
7131 ncr_sir_to_redo(np, num, cp);
7132 return;
7133 default:
7134
7135
7136
7137 cp = np->ccb;
7138 while (cp && (CCB_PHYS (cp, phys) != dsa))
7139 cp = cp->link_ccb;
7140
7141 assert (cp && cp == np->header.cp);
7142
7143 if (!cp || cp != np->header.cp)
7144 goto out;
7145 }
7146
7147 switch (num) {
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205 case SIR_NEGO_FAILED:
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216 OUTB (HS_PRT, HS_BUSY);
7217
7218
7219
7220 case SIR_NEGO_PROTO:
7221
7222
7223
7224
7225
7226
7227
7228
7229 if (DEBUG_FLAGS & DEBUG_NEGO) {
7230 PRINT_ADDR(cp->cmd);
7231 printk ("negotiation failed sir=%x status=%x.\n",
7232 num, cp->nego_status);
7233 };
7234
7235
7236
7237
7238
7239 switch (cp->nego_status) {
7240
7241 case NS_SYNC:
7242 ncr_setsync (np, cp, 0, 0xe0);
7243 break;
7244
7245 case NS_WIDE:
7246 ncr_setwide (np, cp, 0, 0);
7247 break;
7248
7249 };
7250 np->msgin [0] = M_NOOP;
7251 np->msgout[0] = M_NOOP;
7252 cp->nego_status = 0;
7253 break;
7254
7255 case SIR_NEGO_SYNC:
7256
7257
7258
7259
7260 if (DEBUG_FLAGS & DEBUG_NEGO) {
7261 PRINT_ADDR(cp->cmd);
7262 printk ("sync msgin: ");
7263 (void) ncr_show_msg (np->msgin);
7264 printk (".\n");
7265 };
7266
7267
7268
7269
7270
7271 chg = 0;
7272 per = np->msgin[3];
7273 ofs = np->msgin[4];
7274 if (ofs==0) per=255;
7275
7276
7277
7278
7279
7280
7281 if (ofs)
7282 tp->inq_byte7 |= INQ7_SYNC;
7283
7284
7285
7286
7287
7288 if (per < np->minsync)
7289 {chg = 1; per = np->minsync;}
7290 if (per < tp->minsync)
7291 {chg = 1; per = tp->minsync;}
7292 if (ofs > tp->maxoffs)
7293 {chg = 1; ofs = tp->maxoffs;}
7294
7295
7296
7297
7298 fak = 7;
7299 scntl3 = 0;
7300 if (ofs != 0) {
7301 ncr_getsync(np, per, &fak, &scntl3);
7302 if (fak > 7) {
7303 chg = 1;
7304 ofs = 0;
7305 }
7306 }
7307 if (ofs == 0) {
7308 fak = 7;
7309 per = 0;
7310 scntl3 = 0;
7311 tp->minsync = 0;
7312 }
7313
7314 if (DEBUG_FLAGS & DEBUG_NEGO) {
7315 PRINT_ADDR(cp->cmd);
7316 printk ("sync: per=%d scntl3=0x%x ofs=%d fak=%d chg=%d.\n",
7317 per, scntl3, ofs, fak, chg);
7318 }
7319
7320 if (INB (HS_PRT) == HS_NEGOTIATE) {
7321 OUTB (HS_PRT, HS_BUSY);
7322 switch (cp->nego_status) {
7323
7324 case NS_SYNC:
7325
7326
7327
7328 if (chg) {
7329
7330
7331
7332 ncr_setsync (np, cp, 0, 0xe0);
7333 OUTL_DSP (NCB_SCRIPT_PHYS (np, msg_bad));
7334 } else {
7335
7336
7337
7338 ncr_setsync (np, cp, scntl3, (fak<<5)|ofs);
7339 OUTL_DSP (NCB_SCRIPT_PHYS (np, clrack));
7340 };
7341 return;
7342
7343 case NS_WIDE:
7344 ncr_setwide (np, cp, 0, 0);
7345 break;
7346 };
7347 };
7348
7349
7350
7351
7352
7353
7354 ncr_setsync (np, cp, scntl3, (fak<<5)|ofs);
7355
7356 np->msgout[0] = M_EXTENDED;
7357 np->msgout[1] = 3;
7358 np->msgout[2] = M_X_SYNC_REQ;
7359 np->msgout[3] = per;
7360 np->msgout[4] = ofs;
7361
7362 cp->nego_status = NS_SYNC;
7363
7364 if (DEBUG_FLAGS & DEBUG_NEGO) {
7365 PRINT_ADDR(cp->cmd);
7366 printk ("sync msgout: ");
7367 (void) ncr_show_msg (np->msgout);
7368 printk (".\n");
7369 }
7370
7371 if (!ofs) {
7372 OUTL_DSP (NCB_SCRIPT_PHYS (np, msg_bad));
7373 return;
7374 }
7375 np->msgin [0] = M_NOOP;
7376
7377 break;
7378
7379 case SIR_NEGO_WIDE:
7380
7381
7382
7383 if (DEBUG_FLAGS & DEBUG_NEGO) {
7384 PRINT_ADDR(cp->cmd);
7385 printk ("wide msgin: ");
7386 (void) ncr_show_msg (np->msgin);
7387 printk (".\n");
7388 };
7389
7390
7391
7392
7393
7394 chg = 0;
7395 wide = np->msgin[3];
7396
7397
7398
7399
7400
7401
7402 if (wide)
7403 tp->inq_byte7 |= INQ7_WIDE16;
7404
7405
7406
7407
7408
7409 if (wide > tp->usrwide)
7410 {chg = 1; wide = tp->usrwide;}
7411
7412 if (DEBUG_FLAGS & DEBUG_NEGO) {
7413 PRINT_ADDR(cp->cmd);
7414 printk ("wide: wide=%d chg=%d.\n", wide, chg);
7415 }
7416
7417 if (INB (HS_PRT) == HS_NEGOTIATE) {
7418 OUTB (HS_PRT, HS_BUSY);
7419 switch (cp->nego_status) {
7420
7421 case NS_WIDE:
7422
7423
7424
7425 if (chg) {
7426
7427
7428
7429 ncr_setwide (np, cp, 0, 1);
7430 OUTL_DSP (NCB_SCRIPT_PHYS (np, msg_bad));
7431 } else {
7432
7433
7434
7435 ncr_setwide (np, cp, wide, 1);
7436 OUTL_DSP (NCB_SCRIPT_PHYS (np, clrack));
7437 };
7438 return;
7439
7440 case NS_SYNC:
7441 ncr_setsync (np, cp, 0, 0xe0);
7442 break;
7443 };
7444 };
7445
7446
7447
7448
7449
7450
7451 ncr_setwide (np, cp, wide, 1);
7452
7453 np->msgout[0] = M_EXTENDED;
7454 np->msgout[1] = 2;
7455 np->msgout[2] = M_X_WIDE_REQ;
7456 np->msgout[3] = wide;
7457
7458 np->msgin [0] = M_NOOP;
7459
7460 cp->nego_status = NS_WIDE;
7461
7462 if (DEBUG_FLAGS & DEBUG_NEGO) {
7463 PRINT_ADDR(cp->cmd);
7464 printk ("wide msgout: ");
7465 (void) ncr_show_msg (np->msgin);
7466 printk (".\n");
7467 }
7468 break;
7469
7470
7471
7472
7473
7474
7475
7476
7477 case SIR_REJECT_RECEIVED:
7478
7479
7480
7481
7482
7483
7484
7485 PRINT_ADDR(cp->cmd);
7486 printk ("M_REJECT received (%x:%x).\n",
7487 (unsigned)scr_to_cpu(np->lastmsg), np->msgout[0]);
7488 break;
7489
7490 case SIR_REJECT_SENT:
7491
7492
7493
7494
7495
7496
7497
7498 PRINT_ADDR(cp->cmd);
7499 printk ("M_REJECT sent for ");
7500 (void) ncr_show_msg (np->msgin);
7501 printk (".\n");
7502 break;
7503
7504
7505
7506
7507
7508
7509
7510
7511 case SIR_IGN_RESIDUE:
7512
7513
7514
7515
7516
7517
7518
7519
7520 PRINT_ADDR(cp->cmd);
7521 printk ("M_IGN_RESIDUE received, but not yet implemented.\n");
7522 break;
7523#if 0
7524 case SIR_MISSING_SAVE:
7525
7526
7527
7528
7529
7530
7531
7532
7533 PRINT_ADDR(cp->cmd);
7534 printk ("M_DISCONNECT received, but datapointer not saved: "
7535 "data=%x save=%x goal=%x.\n",
7536 (unsigned) INL (nc_temp),
7537 (unsigned) scr_to_cpu(np->header.savep),
7538 (unsigned) scr_to_cpu(np->header.goalp));
7539 break;
7540#endif
7541 };
7542
7543out:
7544 OUTONB_STD ();
7545}
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556static ccb_p ncr_get_ccb (ncb_p np, u_char tn, u_char ln)
7557{
7558 tcb_p tp = &np->target[tn];
7559 lcb_p lp = tp->lp[ln];
7560 u_char tag = NO_TAG;
7561 ccb_p cp = (ccb_p) 0;
7562
7563
7564
7565
7566 if (lp) {
7567 XPT_QUEHEAD *qp;
7568
7569
7570
7571 if (lp->usetags && lp->busyccbs >= lp->maxnxs)
7572 return (ccb_p) 0;
7573
7574
7575
7576
7577 if (xpt_que_empty(&lp->free_ccbq))
7578 ncr_alloc_ccb(np, tn, ln);
7579
7580
7581
7582
7583 if (lp->queuedepth != lp->numtags) {
7584 ncr_setup_tags(np, tn, ln);
7585 }
7586
7587
7588
7589
7590 qp = xpt_remque_head(&lp->free_ccbq);
7591 if (qp) {
7592 cp = xpt_que_entry(qp, struct ccb, link_ccbq);
7593 if (cp->magic) {
7594 PRINT_LUN(np, tn, ln);
7595 printk ("ccb free list corrupted (@%p)\n", cp);
7596 cp = 0;
7597 }
7598 else {
7599 xpt_insque_tail(qp, &lp->wait_ccbq);
7600 ++lp->busyccbs;
7601 }
7602 }
7603
7604
7605
7606
7607
7608 if (cp) {
7609 if (lp->usetags)
7610 tag = lp->cb_tags[lp->ia_tag];
7611 }
7612 else if (lp->actccbs > 0)
7613 return (ccb_p) 0;
7614 }
7615
7616
7617
7618
7619 if (!cp)
7620 cp = np->ccb;
7621
7622
7623
7624
7625#if 0
7626 while (cp->magic) {
7627 if (flags & SCSI_NOSLEEP) break;
7628 if (tsleep ((caddr_t)cp, PRIBIO|PCATCH, "ncr", 0))
7629 break;
7630 };
7631#endif
7632
7633 if (cp->magic)
7634 return ((ccb_p) 0);
7635
7636 cp->magic = 1;
7637
7638
7639
7640
7641 if (lp) {
7642 if (tag != NO_TAG) {
7643 ++lp->ia_tag;
7644 if (lp->ia_tag == MAX_TAGS)
7645 lp->ia_tag = 0;
7646 lp->tags_umap |= (((tagmap_t) 1) << tag);
7647 }
7648 }
7649
7650
7651
7652
7653 cp->tag = tag;
7654 cp->target = tn;
7655 cp->lun = ln;
7656
7657 if (DEBUG_FLAGS & DEBUG_TAGS) {
7658 PRINT_LUN(np, tn, ln);
7659 printk ("ccb @%p using tag %d.\n", cp, tag);
7660 }
7661
7662 return cp;
7663}
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674static void ncr_free_ccb (ncb_p np, ccb_p cp)
7675{
7676 tcb_p tp = &np->target[cp->target];
7677 lcb_p lp = tp->lp[cp->lun];
7678
7679 if (DEBUG_FLAGS & DEBUG_TAGS) {
7680 PRINT_LUN(np, cp->target, cp->lun);
7681 printk ("ccb @%p freeing tag %d.\n", cp, cp->tag);
7682 }
7683
7684
7685
7686
7687
7688
7689 if (lp) {
7690 if (cp->tag != NO_TAG) {
7691 lp->cb_tags[lp->if_tag++] = cp->tag;
7692 if (lp->if_tag == MAX_TAGS)
7693 lp->if_tag = 0;
7694 lp->tags_umap &= ~(((tagmap_t) 1) << cp->tag);
7695 lp->tags_smap &= lp->tags_umap;
7696 lp->jump_ccb[cp->tag] =
7697 cpu_to_scr(NCB_SCRIPTH_PHYS(np, bad_i_t_l_q));
7698 } else {
7699 lp->jump_ccb[0] =
7700 cpu_to_scr(NCB_SCRIPTH_PHYS(np, bad_i_t_l));
7701 }
7702 }
7703
7704
7705
7706
7707
7708 if (lp) {
7709 if (cp != np->ccb) {
7710 xpt_remque(&cp->link_ccbq);
7711 xpt_insque_head(&cp->link_ccbq, &lp->free_ccbq);
7712 }
7713 --lp->busyccbs;
7714 if (cp->queued) {
7715 --lp->queuedccbs;
7716 }
7717 }
7718 cp -> host_status = HS_IDLE;
7719 cp -> magic = 0;
7720 if (cp->queued) {
7721 --np->queuedccbs;
7722 cp->queued = 0;
7723 }
7724
7725#if 0
7726 if (cp == np->ccb)
7727 wakeup ((caddr_t) cp);
7728#endif
7729}
7730
7731
7732#define ncr_reg_bus_addr(r) (np->paddr + offsetof (struct ncr_reg, r))
7733
7734
7735
7736
7737
7738
7739static void ncr_init_ccb(ncb_p np, ccb_p cp)
7740{
7741 ncrcmd copy_4 = np->features & FE_PFEN ? SCR_COPY(4) : SCR_COPY_F(4);
7742
7743
7744
7745
7746 cp->p_ccb = vtobus(cp);
7747 cp->phys.header.cp = cp;
7748
7749
7750
7751
7752 xpt_que_init(&cp->link_ccbq);
7753
7754
7755
7756
7757
7758
7759
7760 cp->start.setup_dsa[0] = cpu_to_scr(copy_4);
7761 cp->start.setup_dsa[1] = cpu_to_scr(CCB_PHYS(cp, start.p_phys));
7762 cp->start.setup_dsa[2] = cpu_to_scr(ncr_reg_bus_addr(nc_dsa));
7763 cp->start.schedule.l_cmd = cpu_to_scr(SCR_JUMP);
7764 cp->start.p_phys = cpu_to_scr(CCB_PHYS(cp, phys));
7765
7766 bcopy(&cp->start, &cp->restart, sizeof(cp->restart));
7767
7768 cp->start.schedule.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, idle));
7769 cp->restart.schedule.l_paddr = cpu_to_scr(NCB_SCRIPTH_PHYS (np, abort));
7770}
7771
7772
7773
7774
7775
7776
7777
7778static void ncr_alloc_ccb(ncb_p np, u_char tn, u_char ln)
7779{
7780 tcb_p tp = &np->target[tn];
7781 lcb_p lp = tp->lp[ln];
7782 ccb_p cp = 0;
7783
7784
7785
7786
7787 cp = m_calloc_dma(sizeof(struct ccb), "CCB");
7788 if (!cp)
7789 return;
7790
7791
7792
7793
7794 lp->actccbs++;
7795 np->actccbs++;
7796 bzero (cp, sizeof (*cp));
7797 ncr_init_ccb(np, cp);
7798
7799
7800
7801
7802
7803 cp->link_ccb = np->ccb->link_ccb;
7804 np->ccb->link_ccb = cp;
7805
7806 xpt_insque_head(&cp->link_ccbq, &lp->free_ccbq);
7807 ncr_setup_tags (np, tn, ln);
7808}
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828static void ncr_init_tcb (ncb_p np, u_char tn)
7829{
7830 tcb_p tp = &np->target[tn];
7831 ncrcmd copy_1 = np->features & FE_PFEN ? SCR_COPY(1) : SCR_COPY_F(1);
7832 int th = tn & 3;
7833 int i;
7834
7835
7836
7837
7838
7839 tp->jump_tcb.l_cmd =
7840 cpu_to_scr((SCR_JUMP ^ IFFALSE (DATA (0x80 + tn))));
7841 tp->jump_tcb.l_paddr = np->jump_tcb[th].l_paddr;
7842
7843
7844
7845
7846
7847 tp->getscr[0] = cpu_to_scr(copy_1);
7848 tp->getscr[1] = cpu_to_scr(vtobus (&tp->sval));
7849 tp->getscr[2] = cpu_to_scr(ncr_reg_bus_addr(nc_sxfer));
7850
7851
7852
7853
7854
7855 tp->getscr[3] = cpu_to_scr(copy_1);
7856 tp->getscr[4] = cpu_to_scr(vtobus (&tp->wval));
7857 tp->getscr[5] = cpu_to_scr(ncr_reg_bus_addr(nc_scntl3));
7858
7859
7860
7861
7862
7863 tp->call_lun.l_cmd = cpu_to_scr(SCR_CALL);
7864 tp->call_lun.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, resel_lun));
7865
7866
7867
7868
7869
7870
7871 for (i = 0 ; i < 4 ; i++) {
7872 tp->jump_lcb[i].l_cmd =
7873 cpu_to_scr((SCR_JUMP ^ IFTRUE (MASK (i, 3))));
7874 tp->jump_lcb[i].l_paddr =
7875 cpu_to_scr(NCB_SCRIPTH_PHYS (np, bad_identify));
7876 }
7877
7878
7879
7880
7881 np->jump_tcb[th].l_paddr = cpu_to_scr(vtobus (&tp->jump_tcb));
7882
7883
7884
7885
7886 assert (( (offsetof(struct ncr_reg, nc_sxfer) ^
7887 offsetof(struct tcb , sval )) &3) == 0);
7888 assert (( (offsetof(struct ncr_reg, nc_scntl3) ^
7889 offsetof(struct tcb , wval )) &3) == 0);
7890}
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900static lcb_p ncr_alloc_lcb (ncb_p np, u_char tn, u_char ln)
7901{
7902 tcb_p tp = &np->target[tn];
7903 lcb_p lp = tp->lp[ln];
7904 ncrcmd copy_4 = np->features & FE_PFEN ? SCR_COPY(4) : SCR_COPY_F(4);
7905 int lh = ln & 3;
7906
7907
7908
7909
7910 if (lp)
7911 return lp;
7912
7913
7914
7915
7916 lp = m_calloc_dma(sizeof(struct lcb), "LCB");
7917 if (!lp)
7918 goto fail;
7919 bzero(lp, sizeof(*lp));
7920 tp->lp[ln] = lp;
7921
7922
7923
7924
7925 if (!tp->jump_tcb.l_cmd)
7926 ncr_init_tcb(np, tn);
7927
7928
7929
7930
7931 xpt_que_init(&lp->free_ccbq);
7932 xpt_que_init(&lp->busy_ccbq);
7933 xpt_que_init(&lp->wait_ccbq);
7934 xpt_que_init(&lp->skip_ccbq);
7935
7936
7937
7938
7939
7940 lp->maxnxs = 1;
7941 lp->jump_ccb = &lp->jump_ccb_0;
7942 lp->p_jump_ccb = cpu_to_scr(vtobus(lp->jump_ccb));
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955 lp->jump_lcb.l_cmd =
7956 cpu_to_scr((SCR_JUMP ^ IFFALSE (MASK (0x80+ln, 0xff))));
7957 lp->jump_lcb.l_paddr = tp->jump_lcb[lh].l_paddr;
7958
7959 lp->load_jump_ccb[0] = cpu_to_scr(copy_4);
7960 lp->load_jump_ccb[1] = cpu_to_scr(vtobus (&lp->p_jump_ccb));
7961 lp->load_jump_ccb[2] = cpu_to_scr(ncr_reg_bus_addr(nc_temp));
7962
7963 lp->jump_tag.l_cmd = cpu_to_scr(SCR_JUMP);
7964 lp->jump_tag.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, resel_notag));
7965
7966
7967
7968
7969 tp->jump_lcb[lh].l_paddr = cpu_to_scr(vtobus (&lp->jump_lcb));
7970
7971
7972
7973
7974 lp->busyccbs = 1;
7975 lp->queuedccbs = 1;
7976 lp->queuedepth = 1;
7977fail:
7978 return lp;
7979}
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990static lcb_p ncr_setup_lcb (ncb_p np, u_char tn, u_char ln, u_char *inq_data)
7991{
7992 tcb_p tp = &np->target[tn];
7993 lcb_p lp = tp->lp[ln];
7994 u_char inq_byte7;
7995
7996
7997
7998
7999 if (!lp && !(lp = ncr_alloc_lcb(np, tn, ln)))
8000 goto fail;
8001
8002
8003
8004
8005 tp->quirks = ncr_lookup (inq_data);
8006 if (tp->quirks && bootverbose) {
8007 PRINT_LUN(np, tn, ln);
8008 printk ("quirks=%x.\n", tp->quirks);
8009 }
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019 inq_byte7 = 0;
8020 if ((inq_data[2] & 0x7) >= 2 && (inq_data[3] & 0xf) == 2)
8021 inq_byte7 = inq_data[7];
8022 else if ((inq_data[2] & 0x7) == 1 && (inq_data[3] & 0xf) == 1)
8023 inq_byte7 = INQ7_SYNC;
8024
8025
8026
8027
8028
8029 if ((inq_data[0] & 0xe0) > 0x20 || (inq_data[0] & 0x1f) == 0x1f)
8030 inq_byte7 &= (INQ7_SYNC | INQ7_WIDE16);
8031
8032
8033
8034
8035 if (driver_setup.force_sync_nego)
8036 inq_byte7 |= INQ7_SYNC;
8037
8038
8039
8040
8041 tp->inq_done = 1;
8042 if ((inq_byte7 ^ tp->inq_byte7) & (INQ7_SYNC | INQ7_WIDE16)) {
8043 tp->inq_byte7 = inq_byte7;
8044 ncr_negotiate(np, tp);
8045 }
8046
8047
8048
8049
8050
8051 if ((inq_byte7 & INQ7_QUEUE) && lp->jump_ccb == &lp->jump_ccb_0) {
8052 int i;
8053 lp->jump_ccb = m_calloc_dma(256, "JUMP_CCB");
8054 if (!lp->jump_ccb) {
8055 lp->jump_ccb = &lp->jump_ccb_0;
8056 goto fail;
8057 }
8058 lp->p_jump_ccb = cpu_to_scr(vtobus(lp->jump_ccb));
8059 for (i = 0 ; i < 64 ; i++)
8060 lp->jump_ccb[i] =
8061 cpu_to_scr(NCB_SCRIPTH_PHYS (np, bad_i_t_l_q));
8062 for (i = 0 ; i < MAX_TAGS ; i++)
8063 lp->cb_tags[i] = i;
8064 lp->maxnxs = MAX_TAGS;
8065 lp->tags_stime = ktime_get(3*HZ);
8066 }
8067
8068
8069
8070
8071 if ((inq_byte7 ^ lp->inq_byte7) & INQ7_QUEUE) {
8072 lp->inq_byte7 = inq_byte7;
8073 lp->numtags = lp->maxtags;
8074 ncr_setup_tags (np, tn, ln);
8075 }
8076
8077fail:
8078 return lp;
8079}
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110static int ncr_scatter(ncb_p np, ccb_p cp, Scsi_Cmnd *cmd)
8111{
8112 struct scr_tblmove *data;
8113 int segment = 0;
8114 int use_sg = (int) cmd->use_sg;
8115
8116 data = cp->phys.data;
8117 cp->data_len = 0;
8118
8119 if (!use_sg) {
8120 if (cmd->request_bufflen) {
8121 u_long baddr = map_scsi_single_data(np, cmd);
8122
8123 data = &data[MAX_SCATTER - 1];
8124 data[0].addr = cpu_to_scr(baddr);
8125 data[0].size = cpu_to_scr(cmd->request_bufflen);
8126 cp->data_len = cmd->request_bufflen;
8127 segment = 1;
8128 }
8129 }
8130 else if (use_sg <= MAX_SCATTER) {
8131 struct scatterlist *scatter = (struct scatterlist *)cmd->buffer;
8132
8133 use_sg = map_scsi_sg_data(np, cmd);
8134 data = &data[MAX_SCATTER - use_sg];
8135
8136 while (segment < use_sg) {
8137 u_long baddr = scsi_sg_dma_address(&scatter[segment]);
8138 unsigned int len = scsi_sg_dma_len(&scatter[segment]);
8139
8140 data[segment].addr = cpu_to_scr(baddr);
8141 data[segment].size = cpu_to_scr(len);
8142 cp->data_len += len;
8143 ++segment;
8144 }
8145 }
8146 else {
8147 return -1;
8148 }
8149
8150 return segment;
8151}
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164#ifndef SCSI_NCR_IOMAPPED
8165static int __init ncr_regtest (struct ncb* np)
8166{
8167 register volatile u_int32 data;
8168
8169
8170
8171
8172
8173 data = 0xffffffff;
8174 OUTL_OFF(offsetof(struct ncr_reg, nc_dstat), data);
8175 data = INL_OFF(offsetof(struct ncr_reg, nc_dstat));
8176#if 1
8177 if (data == 0xffffffff) {
8178#else
8179 if ((data & 0xe2f0fffd) != 0x02000080) {
8180#endif
8181 printk ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
8182 (unsigned) data);
8183 return (0x10);
8184 };
8185 return (0);
8186}
8187#endif
8188
8189static int __init ncr_snooptest (struct ncb* np)
8190{
8191 u_int32 ncr_rd, ncr_wr, ncr_bk, host_rd, host_wr, pc;
8192 int i, err=0;
8193#ifndef SCSI_NCR_IOMAPPED
8194 if (np->reg) {
8195 err |= ncr_regtest (np);
8196 if (err) return (err);
8197 }
8198#endif
8199
8200
8201
8202 pc = NCB_SCRIPTH_PHYS (np, snooptest);
8203 host_wr = 1;
8204 ncr_wr = 2;
8205
8206
8207
8208 np->ncr_cache = cpu_to_scr(host_wr);
8209 OUTL (nc_temp, ncr_wr);
8210
8211
8212
8213 OUTL_DSP (pc);
8214
8215
8216
8217 for (i=0; i<NCR_SNOOP_TIMEOUT; i++)
8218 if (INB(nc_istat) & (INTF|SIP|DIP))
8219 break;
8220
8221
8222
8223 pc = INL (nc_dsp);
8224
8225
8226
8227 host_rd = scr_to_cpu(np->ncr_cache);
8228 ncr_rd = INL (nc_scratcha);
8229 ncr_bk = INL (nc_temp);
8230
8231
8232
8233 OUTB (nc_istat, SRST);
8234 UDELAY (100);
8235 OUTB (nc_istat, 0 );
8236
8237
8238
8239 if (i>=NCR_SNOOP_TIMEOUT) {
8240 printk ("CACHE TEST FAILED: timeout.\n");
8241 return (0x20);
8242 };
8243
8244
8245
8246 if (pc != NCB_SCRIPTH_PHYS (np, snoopend)+8) {
8247 printk ("CACHE TEST FAILED: script execution failed.\n");
8248 printk ("start=%08lx, pc=%08lx, end=%08lx\n",
8249 (u_long) NCB_SCRIPTH_PHYS (np, snooptest), (u_long) pc,
8250 (u_long) NCB_SCRIPTH_PHYS (np, snoopend) +8);
8251 return (0x40);
8252 };
8253
8254
8255
8256 if (host_wr != ncr_rd) {
8257 printk ("CACHE TEST FAILED: host wrote %d, ncr read %d.\n",
8258 (int) host_wr, (int) ncr_rd);
8259 err |= 1;
8260 };
8261 if (host_rd != ncr_wr) {
8262 printk ("CACHE TEST FAILED: ncr wrote %d, host read %d.\n",
8263 (int) ncr_wr, (int) host_rd);
8264 err |= 2;
8265 };
8266 if (ncr_bk != ncr_wr) {
8267 printk ("CACHE TEST FAILED: ncr wrote %d, read back %d.\n",
8268 (int) ncr_wr, (int) ncr_bk);
8269 err |= 4;
8270 };
8271 return (err);
8272}
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285struct table_entry {
8286 char * manufacturer;
8287 char * model;
8288 char * version;
8289 u_long info;
8290};
8291
8292static struct table_entry device_tab[] =
8293{
8294#if 0
8295 {"", "", "", QUIRK_NOMSG},
8296#endif
8297 {"SONY", "SDT-5000", "3.17", QUIRK_NOMSG},
8298 {"WangDAT", "Model 2600", "01.7", QUIRK_NOMSG},
8299 {"WangDAT", "Model 3200", "02.2", QUIRK_NOMSG},
8300 {"WangDAT", "Model 1300", "02.4", QUIRK_NOMSG},
8301 {"", "", "", 0}
8302};
8303
8304static u_long ncr_lookup(char * id)
8305{
8306 struct table_entry * p = device_tab;
8307 char *d, *r, c;
8308
8309 for (;;p++) {
8310
8311 d = id+8;
8312 r = p->manufacturer;
8313 while ((c=*r++)) if (c!=*d++) break;
8314 if (c) continue;
8315
8316 d = id+16;
8317 r = p->model;
8318 while ((c=*r++)) if (c!=*d++) break;
8319 if (c) continue;
8320
8321 d = id+32;
8322 r = p->version;
8323 while ((c=*r++)) if (c!=*d++) break;
8324 if (c) continue;
8325
8326 return (p->info);
8327 }
8328}
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356static void ncr_selectclock(ncb_p np, u_char scntl3)
8357{
8358 if (np->multiplier < 2) {
8359 OUTB(nc_scntl3, scntl3);
8360 return;
8361 }
8362
8363 if (bootverbose >= 2)
8364 printk ("%s: enabling clock multiplier\n", ncr_name(np));
8365
8366 OUTB(nc_stest1, DBLEN);
8367 if (np->multiplier > 2) {
8368 int i = 20;
8369 while (!(INB(nc_stest4) & LCKFRQ) && --i > 0)
8370 UDELAY (20);
8371 if (!i)
8372 printk("%s: the chip cannot lock the frequency\n", ncr_name(np));
8373 } else
8374 UDELAY (20);
8375 OUTB(nc_stest3, HSC);
8376 OUTB(nc_scntl3, scntl3);
8377 OUTB(nc_stest1, (DBLEN|DBLSEL));
8378 OUTB(nc_stest3, 0x00);
8379}
8380
8381
8382
8383
8384
8385static unsigned __init ncrgetfreq (ncb_p np, int gen)
8386{
8387 unsigned ms = 0;
8388 char count = 0;
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405 OUTB (nc_stest1, 0);
8406 OUTW (nc_sien , 0);
8407 (void) INW (nc_sist);
8408 OUTB (nc_dien , 0);
8409 (void) INW (nc_sist);
8410 OUTB (nc_scntl3, 4);
8411 OUTB (nc_stime1, 0);
8412 OUTB (nc_stime1, gen);
8413 while (!(INW(nc_sist) & GEN) && ms++ < 100000) {
8414 for (count = 0; count < 10; count ++)
8415 UDELAY (100);
8416 }
8417 OUTB (nc_stime1, 0);
8418
8419
8420
8421
8422
8423 OUTB (nc_scntl3, 0);
8424
8425 if (bootverbose >= 2)
8426 printk ("%s: Delay (GEN=%d): %u msec\n", ncr_name(np), gen, ms);
8427
8428
8429
8430 return ms ? ((1 << gen) * 4340) / ms : 0;
8431}
8432
8433
8434
8435
8436static void __init ncr_getclock (ncb_p np, int mult)
8437{
8438 unsigned char scntl3 = INB(nc_scntl3);
8439 unsigned char stest1 = INB(nc_stest1);
8440 unsigned f1;
8441
8442 np->multiplier = 1;
8443 f1 = 40000;
8444
8445
8446
8447
8448 if (mult > 1 && (stest1 & (DBLEN+DBLSEL)) == DBLEN+DBLSEL) {
8449 if (bootverbose >= 2)
8450 printk ("%s: clock multiplier found\n", ncr_name(np));
8451 np->multiplier = mult;
8452 }
8453
8454
8455
8456
8457
8458
8459 if (np->multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) {
8460 unsigned f2;
8461
8462 OUTB(nc_istat, SRST); UDELAY (5); OUTB(nc_istat, 0);
8463
8464 (void) ncrgetfreq (np, 11);
8465 f1 = ncrgetfreq (np, 11);
8466 f2 = ncrgetfreq (np, 11);
8467
8468 if (bootverbose)
8469 printk ("%s: NCR clock is %uKHz, %uKHz\n", ncr_name(np), f1, f2);
8470
8471 if (f1 > f2) f1 = f2;
8472
8473 if (f1 < 45000) f1 = 40000;
8474 else if (f1 < 55000) f1 = 50000;
8475 else f1 = 80000;
8476
8477 if (f1 < 80000 && mult > 1) {
8478 if (bootverbose >= 2)
8479 printk ("%s: clock multiplier assumed\n", ncr_name(np));
8480 np->multiplier = mult;
8481 }
8482 } else {
8483 if ((scntl3 & 7) == 3) f1 = 40000;
8484 else if ((scntl3 & 7) == 5) f1 = 80000;
8485 else f1 = 160000;
8486
8487 f1 /= np->multiplier;
8488 }
8489
8490
8491
8492
8493 f1 *= np->multiplier;
8494 np->clock_khz = f1;
8495}
8496
8497
8498
8499
8500
8501
8502
8503static void ncr53c8xx_select_queue_depths(struct Scsi_Host *host, struct scsi_device *devlist)
8504{
8505 struct scsi_device *device;
8506
8507 for (device = devlist; device; device = device->next) {
8508 ncb_p np;
8509 tcb_p tp;
8510 lcb_p lp;
8511 int numtags;
8512
8513 if (device->host != host)
8514 continue;
8515
8516 np = ((struct host_data *) host->hostdata)->ncb;
8517 tp = &np->target[device->id];
8518 lp = tp->lp[device->lun];
8519
8520
8521
8522
8523
8524
8525
8526 numtags = device_queue_depth(np->unit, device->id, device->lun);
8527 if (numtags > tp->usrtags)
8528 numtags = tp->usrtags;
8529 if (!device->tagged_supported)
8530 numtags = 1;
8531 device->queue_depth = numtags;
8532 if (device->queue_depth < 2)
8533 device->queue_depth = 2;
8534 if (device->queue_depth > MAX_TAGS)
8535 device->queue_depth = MAX_TAGS;
8536
8537
8538
8539
8540
8541
8542 if (lp) {
8543 lp->numtags = lp->maxtags = numtags;
8544 lp->scdev_depth = device->queue_depth;
8545 }
8546 ncr_setup_tags (np, device->id, device->lun);
8547
8548#ifdef DEBUG_NCR53C8XX
8549printk("ncr53c8xx_select_queue_depth: host=%d, id=%d, lun=%d, depth=%d\n",
8550 np->unit, device->id, device->lun, device->queue_depth);
8551#endif
8552 }
8553}
8554
8555
8556
8557
8558
8559int ncr53c8xx_queue_command (Scsi_Cmnd *cmd, void (* done)(Scsi_Cmnd *))
8560{
8561 ncb_p np = ((struct host_data *) cmd->host->hostdata)->ncb;
8562 unsigned long flags;
8563 int sts;
8564
8565#ifdef DEBUG_NCR53C8XX
8566printk("ncr53c8xx_queue_command\n");
8567#endif
8568
8569 cmd->scsi_done = done;
8570 cmd->host_scribble = NULL;
8571#ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
8572 cmd->__data_mapped = 0;
8573 cmd->__data_mapping = 0;
8574#endif
8575
8576 NCR_LOCK_NCB(np, flags);
8577
8578 if ((sts = ncr_queue_command(np, cmd)) != DID_OK) {
8579 cmd->result = ScsiResult(sts, 0);
8580#ifdef DEBUG_NCR53C8XX
8581printk("ncr53c8xx : command not queued - result=%d\n", sts);
8582#endif
8583 }
8584#ifdef DEBUG_NCR53C8XX
8585 else
8586printk("ncr53c8xx : command successfully queued\n");
8587#endif
8588
8589 NCR_UNLOCK_NCB(np, flags);
8590
8591 if (sts != DID_OK) {
8592 unmap_scsi_data(np, cmd);
8593 done(cmd);
8594 }
8595
8596 return sts;
8597}
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607static void ncr53c8xx_intr(int irq, void *dev_id, struct pt_regs * regs)
8608{
8609 unsigned long flags;
8610 ncb_p np = (ncb_p) dev_id;
8611 Scsi_Cmnd *done_list;
8612
8613#ifdef DEBUG_NCR53C8XX
8614 printk("ncr53c8xx : interrupt received\n");
8615#endif
8616
8617 if (DEBUG_FLAGS & DEBUG_TINY) printk ("[");
8618
8619 NCR_LOCK_NCB(np, flags);
8620 ncr_exception(np);
8621 done_list = np->done_list;
8622 np->done_list = 0;
8623 NCR_UNLOCK_NCB(np, flags);
8624
8625 if (DEBUG_FLAGS & DEBUG_TINY) printk ("]\n");
8626
8627 if (done_list) {
8628 NCR_LOCK_SCSI_DONE(np, flags);
8629 ncr_flush_done_cmds(done_list);
8630 NCR_UNLOCK_SCSI_DONE(np, flags);
8631 }
8632}
8633
8634
8635
8636
8637
8638static void ncr53c8xx_timeout(unsigned long npref)
8639{
8640 ncb_p np = (ncb_p) npref;
8641 unsigned long flags;
8642 Scsi_Cmnd *done_list;
8643
8644 NCR_LOCK_NCB(np, flags);
8645 ncr_timeout((ncb_p) np);
8646 done_list = np->done_list;
8647 np->done_list = 0;
8648 NCR_UNLOCK_NCB(np, flags);
8649
8650 if (done_list) {
8651 NCR_LOCK_SCSI_DONE(np, flags);
8652 ncr_flush_done_cmds(done_list);
8653 NCR_UNLOCK_SCSI_DONE(np, flags);
8654 }
8655}
8656
8657
8658
8659
8660
8661#if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
8662int ncr53c8xx_reset(Scsi_Cmnd *cmd, unsigned int reset_flags)
8663#else
8664int ncr53c8xx_reset(Scsi_Cmnd *cmd)
8665#endif
8666{
8667 ncb_p np = ((struct host_data *) cmd->host->hostdata)->ncb;
8668 int sts;
8669 unsigned long flags;
8670 Scsi_Cmnd *done_list;
8671
8672#if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
8673 printk("ncr53c8xx_reset: pid=%lu reset_flags=%x serial_number=%ld serial_number_at_timeout=%ld\n",
8674 cmd->pid, reset_flags, cmd->serial_number, cmd->serial_number_at_timeout);
8675#else
8676 printk("ncr53c8xx_reset: command pid %lu\n", cmd->pid);
8677#endif
8678
8679 NCR_LOCK_NCB(np, flags);
8680
8681
8682
8683
8684#if defined SCSI_RESET_NOT_RUNNING
8685 if (cmd->serial_number != cmd->serial_number_at_timeout) {
8686 sts = SCSI_RESET_NOT_RUNNING;
8687 goto out;
8688 }
8689#endif
8690
8691
8692
8693
8694
8695
8696
8697#if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
8698 sts = ncr_reset_bus(np, cmd,
8699 (reset_flags & (SCSI_RESET_SYNCHRONOUS | SCSI_RESET_ASYNCHRONOUS)) == SCSI_RESET_SYNCHRONOUS);
8700#else
8701 sts = ncr_reset_bus(np, cmd, 0);
8702#endif
8703
8704
8705
8706
8707
8708#if defined SCSI_RESET_HOST_RESET
8709 if (sts == SCSI_RESET_SUCCESS)
8710 sts |= SCSI_RESET_HOST_RESET;
8711#endif
8712
8713out:
8714 done_list = np->done_list;
8715 np->done_list = 0;
8716 NCR_UNLOCK_NCB(np, flags);
8717
8718 ncr_flush_done_cmds(done_list);
8719
8720 return sts;
8721}
8722
8723
8724
8725
8726
8727int ncr53c8xx_abort(Scsi_Cmnd *cmd)
8728{
8729 ncb_p np = ((struct host_data *) cmd->host->hostdata)->ncb;
8730 int sts;
8731 unsigned long flags;
8732 Scsi_Cmnd *done_list;
8733
8734#if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
8735 printk("ncr53c8xx_abort: pid=%lu serial_number=%ld serial_number_at_timeout=%ld\n",
8736 cmd->pid, cmd->serial_number, cmd->serial_number_at_timeout);
8737#else
8738 printk("ncr53c8xx_abort: command pid %lu\n", cmd->pid);
8739#endif
8740
8741 NCR_LOCK_NCB(np, flags);
8742
8743#if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
8744
8745
8746
8747 if (cmd->serial_number != cmd->serial_number_at_timeout) {
8748 sts = SCSI_ABORT_NOT_RUNNING;
8749 goto out;
8750 }
8751#endif
8752
8753 sts = ncr_abort_command(np, cmd);
8754out:
8755 done_list = np->done_list;
8756 np->done_list = 0;
8757 NCR_UNLOCK_NCB(np, flags);
8758
8759 ncr_flush_done_cmds(done_list);
8760
8761 return sts;
8762}
8763
8764
8765#ifdef MODULE
8766int ncr53c8xx_release(struct Scsi_Host *host)
8767{
8768#ifdef DEBUG_NCR53C8XX
8769printk("ncr53c8xx : release\n");
8770#endif
8771 ncr_detach(((struct host_data *) host->hostdata)->ncb);
8772
8773 return 1;
8774}
8775#endif
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791#define next_wcmd host_scribble
8792
8793static void insert_into_waiting_list(ncb_p np, Scsi_Cmnd *cmd)
8794{
8795 Scsi_Cmnd *wcmd;
8796
8797#ifdef DEBUG_WAITING_LIST
8798 printk("%s: cmd %lx inserted into waiting list\n", ncr_name(np), (u_long) cmd);
8799#endif
8800 cmd->next_wcmd = 0;
8801 if (!(wcmd = np->waiting_list)) np->waiting_list = cmd;
8802 else {
8803 while ((wcmd->next_wcmd) != 0)
8804 wcmd = (Scsi_Cmnd *) wcmd->next_wcmd;
8805 wcmd->next_wcmd = (char *) cmd;
8806 }
8807}
8808
8809static Scsi_Cmnd *retrieve_from_waiting_list(int to_remove, ncb_p np, Scsi_Cmnd *cmd)
8810{
8811 Scsi_Cmnd **pcmd = &np->waiting_list;
8812
8813 while (*pcmd) {
8814 if (cmd == *pcmd) {
8815 if (to_remove) {
8816 *pcmd = (Scsi_Cmnd *) cmd->next_wcmd;
8817 cmd->next_wcmd = 0;
8818 }
8819#ifdef DEBUG_WAITING_LIST
8820 printk("%s: cmd %lx retrieved from waiting list\n", ncr_name(np), (u_long) cmd);
8821#endif
8822 return cmd;
8823 }
8824 pcmd = (Scsi_Cmnd **) &(*pcmd)->next_wcmd;
8825 }
8826 return 0;
8827}
8828
8829static void process_waiting_list(ncb_p np, int sts)
8830{
8831 Scsi_Cmnd *waiting_list, *wcmd;
8832
8833 waiting_list = np->waiting_list;
8834 np->waiting_list = 0;
8835
8836#ifdef DEBUG_WAITING_LIST
8837 if (waiting_list) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np), (u_long) waiting_list, sts);
8838#endif
8839 while ((wcmd = waiting_list) != 0) {
8840 waiting_list = (Scsi_Cmnd *) wcmd->next_wcmd;
8841 wcmd->next_wcmd = 0;
8842 if (sts == DID_OK) {
8843#ifdef DEBUG_WAITING_LIST
8844 printk("%s: cmd %lx trying to requeue\n", ncr_name(np), (u_long) wcmd);
8845#endif
8846 sts = ncr_queue_command(np, wcmd);
8847 }
8848 if (sts != DID_OK) {
8849#ifdef DEBUG_WAITING_LIST
8850 printk("%s: cmd %lx done forced sts=%d\n", ncr_name(np), (u_long) wcmd, sts);
8851#endif
8852 wcmd->result = ScsiResult(sts, 0);
8853 ncr_queue_done_cmd(np, wcmd);
8854 }
8855 }
8856}
8857
8858#undef next_wcmd
8859
8860#ifdef SCSI_NCR_PROC_INFO_SUPPORT
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872#ifdef SCSI_NCR_USER_COMMAND_SUPPORT
8873
8874#define is_digit(c) ((c) >= '0' && (c) <= '9')
8875#define digit_to_bin(c) ((c) - '0')
8876#define is_space(c) ((c) == ' ' || (c) == '\t')
8877
8878static int skip_spaces(char *ptr, int len)
8879{
8880 int cnt, c;
8881
8882 for (cnt = len; cnt > 0 && (c = *ptr++) && is_space(c); cnt--);
8883
8884 return (len - cnt);
8885}
8886
8887static int get_int_arg(char *ptr, int len, u_long *pv)
8888{
8889 int cnt, c;
8890 u_long v;
8891
8892 for (v = 0, cnt = len; cnt > 0 && (c = *ptr++) && is_digit(c); cnt--) {
8893 v = (v * 10) + digit_to_bin(c);
8894 }
8895
8896 if (pv)
8897 *pv = v;
8898
8899 return (len - cnt);
8900}
8901
8902static int is_keyword(char *ptr, int len, char *verb)
8903{
8904 int verb_len = strlen(verb);
8905
8906 if (len >= strlen(verb) && !memcmp(verb, ptr, verb_len))
8907 return verb_len;
8908 else
8909 return 0;
8910
8911}
8912
8913#define SKIP_SPACES(min_spaces) \
8914 if ((arg_len = skip_spaces(ptr, len)) < (min_spaces)) \
8915 return -EINVAL; \
8916 ptr += arg_len; len -= arg_len;
8917
8918#define GET_INT_ARG(v) \
8919 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
8920 return -EINVAL; \
8921 ptr += arg_len; len -= arg_len;
8922
8923
8924
8925
8926
8927
8928static int ncr_user_command(ncb_p np, char *buffer, int length)
8929{
8930 char *ptr = buffer;
8931 int len = length;
8932 struct usrcmd *uc = &np->user;
8933 int arg_len;
8934 u_long target;
8935
8936 bzero(uc, sizeof(*uc));
8937
8938 if (len > 0 && ptr[len-1] == '\n')
8939 --len;
8940
8941 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
8942 uc->cmd = UC_SETSYNC;
8943 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
8944 uc->cmd = UC_SETTAGS;
8945 else if ((arg_len = is_keyword(ptr, len, "setorder")) != 0)
8946 uc->cmd = UC_SETORDER;
8947 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
8948 uc->cmd = UC_SETVERBOSE;
8949 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
8950 uc->cmd = UC_SETWIDE;
8951 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
8952 uc->cmd = UC_SETDEBUG;
8953 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
8954 uc->cmd = UC_SETFLAG;
8955 else
8956 arg_len = 0;
8957
8958#ifdef DEBUG_PROC_INFO
8959printk("ncr_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
8960#endif
8961
8962 if (!arg_len)
8963 return -EINVAL;
8964 ptr += arg_len; len -= arg_len;
8965
8966 switch(uc->cmd) {
8967 case UC_SETSYNC:
8968 case UC_SETTAGS:
8969 case UC_SETWIDE:
8970 case UC_SETFLAG:
8971 SKIP_SPACES(1);
8972 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
8973 ptr += arg_len; len -= arg_len;
8974 uc->target = ~0;
8975 } else {
8976 GET_INT_ARG(target);
8977 uc->target = (1<<target);
8978#ifdef DEBUG_PROC_INFO
8979printk("ncr_user_command: target=%ld\n", target);
8980#endif
8981 }
8982 break;
8983 }
8984
8985 switch(uc->cmd) {
8986 case UC_SETVERBOSE:
8987 case UC_SETSYNC:
8988 case UC_SETTAGS:
8989 case UC_SETWIDE:
8990 SKIP_SPACES(1);
8991 GET_INT_ARG(uc->data);
8992#ifdef DEBUG_PROC_INFO
8993printk("ncr_user_command: data=%ld\n", uc->data);
8994#endif
8995 break;
8996 case UC_SETORDER:
8997 SKIP_SPACES(1);
8998 if ((arg_len = is_keyword(ptr, len, "simple")))
8999 uc->data = M_SIMPLE_TAG;
9000 else if ((arg_len = is_keyword(ptr, len, "ordered")))
9001 uc->data = M_ORDERED_TAG;
9002 else if ((arg_len = is_keyword(ptr, len, "default")))
9003 uc->data = 0;
9004 else
9005 return -EINVAL;
9006 break;
9007 case UC_SETDEBUG:
9008 while (len > 0) {
9009 SKIP_SPACES(1);
9010 if ((arg_len = is_keyword(ptr, len, "alloc")))
9011 uc->data |= DEBUG_ALLOC;
9012 else if ((arg_len = is_keyword(ptr, len, "phase")))
9013 uc->data |= DEBUG_PHASE;
9014 else if ((arg_len = is_keyword(ptr, len, "queue")))
9015 uc->data |= DEBUG_QUEUE;
9016 else if ((arg_len = is_keyword(ptr, len, "result")))
9017 uc->data |= DEBUG_RESULT;
9018 else if ((arg_len = is_keyword(ptr, len, "scatter")))
9019 uc->data |= DEBUG_SCATTER;
9020 else if ((arg_len = is_keyword(ptr, len, "script")))
9021 uc->data |= DEBUG_SCRIPT;
9022 else if ((arg_len = is_keyword(ptr, len, "tiny")))
9023 uc->data |= DEBUG_TINY;
9024 else if ((arg_len = is_keyword(ptr, len, "timing")))
9025 uc->data |= DEBUG_TIMING;
9026 else if ((arg_len = is_keyword(ptr, len, "nego")))
9027 uc->data |= DEBUG_NEGO;
9028 else if ((arg_len = is_keyword(ptr, len, "tags")))
9029 uc->data |= DEBUG_TAGS;
9030 else
9031 return -EINVAL;
9032 ptr += arg_len; len -= arg_len;
9033 }
9034#ifdef DEBUG_PROC_INFO
9035printk("ncr_user_command: data=%ld\n", uc->data);
9036#endif
9037 break;
9038 case UC_SETFLAG:
9039 while (len > 0) {
9040 SKIP_SPACES(1);
9041 if ((arg_len = is_keyword(ptr, len, "trace")))
9042 uc->data |= UF_TRACE;
9043 else if ((arg_len = is_keyword(ptr, len, "no_disc")))
9044 uc->data |= UF_NODISC;
9045 else
9046 return -EINVAL;
9047 ptr += arg_len; len -= arg_len;
9048 }
9049 break;
9050 default:
9051 break;
9052 }
9053
9054 if (len)
9055 return -EINVAL;
9056 else {
9057 long flags;
9058
9059 NCR_LOCK_NCB(np, flags);
9060 ncr_usercmd (np);
9061 NCR_UNLOCK_NCB(np, flags);
9062 }
9063 return length;
9064}
9065
9066#endif
9067
9068
9069#ifdef SCSI_NCR_USER_INFO_SUPPORT
9070
9071
9072
9073
9074static int ncr_host_info(ncb_p np, char *ptr, off_t offset, int len)
9075{
9076 struct info_str info;
9077
9078 info.buffer = ptr;
9079 info.length = len;
9080 info.offset = offset;
9081 info.pos = 0;
9082
9083 copy_info(&info, " Chip NCR53C%s, device id 0x%x, "
9084 "revision id 0x%x\n",
9085 np->chip_name, np->device_id, np->revision_id);
9086 copy_info(&info, " On PCI bus %d, device %d, function %d, "
9087#ifdef __sparc__
9088 "IRQ %s\n",
9089#else
9090 "IRQ %d\n",
9091#endif
9092 np->bus, (np->device_fn & 0xf8) >> 3, np->device_fn & 7,
9093#ifdef __sparc__
9094 __irq_itoa(np->irq));
9095#else
9096 (int) np->irq);
9097#endif
9098 copy_info(&info, " Synchronous period factor %d, "
9099 "max commands per lun %d\n",
9100 (int) np->minsync, MAX_TAGS);
9101
9102 if (driver_setup.debug || driver_setup.verbose > 1) {
9103 copy_info(&info, " Debug flags 0x%x, verbosity level %d\n",
9104 driver_setup.debug, driver_setup.verbose);
9105 }
9106
9107 return info.pos > info.offset? info.pos - info.offset : 0;
9108}
9109
9110#endif
9111
9112
9113
9114
9115
9116
9117
9118static int ncr53c8xx_proc_info(char *buffer, char **start, off_t offset,
9119 int length, int hostno, int func)
9120{
9121 struct Scsi_Host *host;
9122 struct host_data *host_data;
9123 ncb_p ncb = 0;
9124 int retv;
9125
9126#ifdef DEBUG_PROC_INFO
9127printk("ncr53c8xx_proc_info: hostno=%d, func=%d\n", hostno, func);
9128#endif
9129
9130 for (host = first_host; host; host = host->next) {
9131 if (host->hostt == the_template && host->host_no == hostno) {
9132 host_data = (struct host_data *) host->hostdata;
9133 ncb = host_data->ncb;
9134 break;
9135 }
9136 }
9137
9138 if (!ncb)
9139 return -EINVAL;
9140
9141 if (func) {
9142#ifdef SCSI_NCR_USER_COMMAND_SUPPORT
9143 retv = ncr_user_command(ncb, buffer, length);
9144#else
9145 retv = -EINVAL;
9146#endif
9147 }
9148 else {
9149 if (start)
9150 *start = buffer;
9151#ifdef SCSI_NCR_USER_INFO_SUPPORT
9152 retv = ncr_host_info(ncb, buffer, offset, length);
9153#else
9154 retv = -EINVAL;
9155#endif
9156 }
9157
9158 return retv;
9159}
9160
9161
9162
9163
9164
9165#endif
9166
9167
9168
9169
9170
9171
9172
9173
9174#if LINUX_VERSION_CODE < LinuxVersionCode(2,3,27)
9175static struct proc_dir_entry proc_scsi_ncr53c8xx = {
9176 PROC_SCSI_NCR53C8XX, 9, NAME53C8XX,
9177 S_IFDIR | S_IRUGO | S_IXUGO, 2
9178};
9179#endif
9180
9181
9182
9183
9184
9185
9186
9187#ifdef MODULE
9188char *ncr53c8xx = 0;
9189# if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,30)
9190MODULE_PARM(ncr53c8xx, "s");
9191# endif
9192#endif
9193
9194int __init ncr53c8xx_setup(char *str)
9195{
9196 return sym53c8xx__setup(str);
9197}
9198
9199#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,13)
9200#ifndef MODULE
9201__setup("ncr53c8xx=", ncr53c8xx_setup);
9202#endif
9203#endif
9204
9205
9206
9207
9208
9209
9210
9211
9212static u_short ncr_chip_ids[] __initdata = {
9213 PCI_DEVICE_ID_NCR_53C810,
9214 PCI_DEVICE_ID_NCR_53C815,
9215 PCI_DEVICE_ID_NCR_53C820,
9216 PCI_DEVICE_ID_NCR_53C825,
9217 PCI_DEVICE_ID_NCR_53C860,
9218 PCI_DEVICE_ID_NCR_53C875,
9219 PCI_DEVICE_ID_NCR_53C875J,
9220 PCI_DEVICE_ID_NCR_53C885,
9221 PCI_DEVICE_ID_NCR_53C895,
9222 PCI_DEVICE_ID_NCR_53C896,
9223 PCI_DEVICE_ID_NCR_53C895A,
9224 PCI_DEVICE_ID_NCR_53C1510D
9225};
9226
9227
9228
9229
9230
9231
9232
9233int __init ncr53c8xx_detect(Scsi_Host_Template *tpnt)
9234{
9235
9236
9237
9238#ifdef SCSI_NCR_PROC_INFO_SUPPORT
9239#if LINUX_VERSION_CODE < LinuxVersionCode(2,3,27)
9240 tpnt->proc_dir = &proc_scsi_ncr53c8xx;
9241#else
9242 tpnt->proc_name = NAME53C8XX;
9243#endif
9244 tpnt->proc_info = ncr53c8xx_proc_info;
9245#endif
9246
9247#if defined(SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT) && defined(MODULE)
9248if (ncr53c8xx)
9249 ncr53c8xx_setup(ncr53c8xx);
9250#endif
9251
9252 return sym53c8xx__detect(tpnt, ncr_chip_ids,
9253 sizeof(ncr_chip_ids)/sizeof(ncr_chip_ids[0]));
9254}
9255
9256
9257
9258
9259
9260
9261
9262const char *ncr53c8xx_info (struct Scsi_Host *host)
9263{
9264 return SCSI_NCR_DRIVER_NAME;
9265}
9266
9267
9268
9269
9270MODULE_LICENSE("GPL");
9271
9272#if LINUX_VERSION_CODE >= LinuxVersionCode(2,4,0)
9273static
9274#endif
9275#if LINUX_VERSION_CODE >= LinuxVersionCode(2,4,0) || defined(MODULE)
9276Scsi_Host_Template driver_template = NCR53C8XX;
9277#include "scsi_module.c"
9278#endif
9279