93 #define SCSI_NCR_DRIVER_NAME "ncr53c8xx-3.4.3g"
95 #define SCSI_NCR_DEBUG_FLAGS (0)
100 #include <linux/errno.h>
106 #include <linux/module.h>
107 #include <linux/sched.h>
108 #include <linux/signal.h>
110 #include <linux/stat.h>
111 #include <linux/string.h>
112 #include <linux/time.h>
114 #include <linux/types.h>
119 #include <scsi/scsi.h>
129 #define NAME53C8XX "ncr53c8xx"
138 #define DEBUG_ALLOC (0x0001)
139 #define DEBUG_PHASE (0x0002)
140 #define DEBUG_QUEUE (0x0008)
141 #define DEBUG_RESULT (0x0010)
142 #define DEBUG_POINTER (0x0020)
143 #define DEBUG_SCRIPT (0x0040)
144 #define DEBUG_TINY (0x0080)
145 #define DEBUG_TIMING (0x0100)
146 #define DEBUG_NEGO (0x0200)
147 #define DEBUG_TAGS (0x0400)
148 #define DEBUG_SCATTER (0x0800)
149 #define DEBUG_IC (0x1000)
156 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
158 #define DEBUG_FLAGS ncr_debug
160 #define DEBUG_FLAGS SCSI_NCR_DEBUG_FLAGS
165 if (!list_empty(head)) {
194 #if PAGE_SIZE >= 8192
195 #define MEMO_PAGE_ORDER 0
197 #define MEMO_PAGE_ORDER 1
199 #define MEMO_FREE_UNUSED
201 #define MEMO_GFP_FLAGS GFP_ATOMIC
202 #define MEMO_CLUSTER_SHIFT (PAGE_SHIFT+MEMO_PAGE_ORDER)
203 #define MEMO_CLUSTER_SIZE (1UL << MEMO_CLUSTER_SHIFT)
204 #define MEMO_CLUSTER_MASK (MEMO_CLUSTER_SIZE-1)
218 #define VTOB_HASH_SHIFT 5
219 #define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT)
220 #define VTOB_HASH_MASK (VTOB_HASH_SIZE-1)
221 #define VTOB_HASH_CODE(m) \
222 ((((m_addr_t) (m)) >> MEMO_CLUSTER_SHIFT) & VTOB_HASH_MASK)
272 printk(
"___m_alloc(%d) = %p\n", size, (
void *) a);
277 static void ___m_free(
m_pool_s *mp,
void *
ptr,
int size)
286 printk(
"___m_free(%p, %d)\n", ptr, size);
300 #ifdef MEMO_FREE_UNUSED
325 static void *__m_calloc2(
m_pool_s *mp,
int size,
char *
name,
int uflags)
329 p = ___m_alloc(mp, size);
332 printk (
"new %-10s[%4d] @%p.\n", name, size, p);
342 #define __m_calloc(mp, s, n) __m_calloc2(mp, s, n, MEMO_WARN)
344 static void __m_free(
m_pool_s *mp,
void *ptr,
int size,
char *name)
347 printk (
"freeing %-10s[%4d] @%p.\n", name, size, ptr);
349 ___m_free(mp, ptr, size);
373 static m_pool_s mp0 = {
NULL, ___mp0_getp, ___mp0_freep};
405 __m_free(&mp0, vbp,
sizeof(*vbp),
"VTOB");
414 vbpp = &mp->
vtob[hc];
415 while (*vbpp && (*vbpp)->
vaddr != m)
416 vbpp = &(*vbpp)->
next;
419 *vbpp = (*vbpp)->
next;
422 __m_free(&mp0, vbp,
sizeof(*vbp),
"VTOB");
427 static inline m_pool_s *___get_dma_pool(m_bush_t bush)
430 for (mp = mp0.
next; mp && mp->
bush != bush; mp = mp->
next);
434 static m_pool_s *___cre_dma_pool(m_bush_t bush)
439 memset(mp, 0,
sizeof(*mp));
441 mp->
getp = ___dma_getp;
442 mp->
freep = ___dma_freep;
449 static void ___del_dma_pool(
m_pool_s *p)
453 while (*pp && *pp != p)
457 __m_free(&mp0, p,
sizeof(*p),
"MPOOL");
461 static void *__m_calloc_dma(m_bush_t bush,
int size,
char *name)
468 mp = ___get_dma_pool(bush);
470 mp = ___cre_dma_pool(bush);
475 spin_unlock_irqrestore(&ncr53c8xx_lock, flags);
480 static void __m_free_dma(m_bush_t bush,
void *m,
int size,
char *name)
486 mp = ___get_dma_pool(bush);
488 __m_free(mp, m, size, name);
491 spin_unlock_irqrestore(&ncr53c8xx_lock, flags);
494 static m_addr_t __vtobus(m_bush_t bush,
void *m)
503 mp = ___get_dma_pool(bush);
509 spin_unlock_irqrestore(&ncr53c8xx_lock, flags);
513 #define _m_calloc_dma(np, s, n) __m_calloc_dma(np->dev, s, n)
514 #define _m_free_dma(np, p, s, n) __m_free_dma(np->dev, p, s, n)
515 #define m_calloc_dma(s, n) _m_calloc_dma(np, s, n)
516 #define m_free_dma(p, s, n) _m_free_dma(np, p, s, n)
517 #define _vtobus(np, p) __vtobus(np->dev, p)
518 #define vtobus(p) _vtobus(np, p)
525 #define __data_mapped SCp.phase
526 #define __data_mapping SCp.have_data_in
530 switch(cmd->__data_mapped) {
535 cmd->__data_mapped = 0;
546 cmd->__data_mapped = 2;
547 cmd->__data_mapping = use_sg;
552 #define unmap_scsi_data(np, cmd) __unmap_scsi_data(np->dev, cmd)
553 #define map_scsi_sg_data(np, cmd) __map_scsi_sg_data(np->dev, cmd)
569 #ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
575 #define initverbose (driver_setup.verbose)
576 #define bootverbose (np->verbose)
593 #define OPT_MASTER_PARITY 2
594 #define OPT_SCSI_PARITY 3
595 #define OPT_DISCONNECTION 4
596 #define OPT_SPECIAL_FEATURES 5
597 #define OPT_UNUSED_1 6
598 #define OPT_FORCE_SYNC_NEGO 7
599 #define OPT_REVERSE_PROBE 8
600 #define OPT_DEFAULT_SYNC 9
601 #define OPT_VERBOSE 10
603 #define OPT_BURST_MAX 12
604 #define OPT_LED_PIN 13
605 #define OPT_MAX_WIDE 14
606 #define OPT_SETTLE_DELAY 15
607 #define OPT_DIFF_SUPPORT 16
609 #define OPT_PCI_FIX_UP 18
610 #define OPT_BUS_CHECK 19
611 #define OPT_OPTIMIZE 20
612 #define OPT_RECOVERY 21
613 #define OPT_SAFE_SETUP 22
614 #define OPT_USE_NVRAM 23
615 #define OPT_EXCLUDE 24
616 #define OPT_HOST_ID 25
618 #ifdef SCSI_NCR_IARB_SUPPORT
629 static char setup_token[] __initdata =
643 #ifdef SCSI_NCR_IARB_SUPPORT
648 static int __init get_setup_token(
char *p)
650 char *
cur = setup_token;
657 if (!
strncmp(p, cur, pc - cur))
664 static int __init sym53c8xx__setup(
char *
str)
666 #ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
686 switch (get_setup_token(cur)) {
689 if (pe && *pe ==
'/') {
691 while (*pe && *pe !=
ARG_SEP &&
692 i <
sizeof(driver_setup.
tag_ctrl)-1) {
759 memcpy(&driver_setup, &driver_safe_setup,
760 sizeof(driver_setup));
769 #ifdef SCSI_NCR_IARB_SUPPORT
775 printk(
"sym53c8xx_setup: unexpected boot option '%.*s' ignored\n", (
int)(pc-cur+1), cur);
793 #define DEF_DEPTH (driver_setup.default_tags)
794 #define ALL_TARGETS -2
808 while ((c = *p++) != 0) {
861 #define SCSI_NCR_CCB_DONE_SUPPORT
862 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
865 #define CCB_DONE_EMPTY 0xffffffffUL
868 #if BITS_PER_LONG == 32
869 #define CCB_DONE_VALID(cp) (((u_long) cp) != CCB_DONE_EMPTY)
873 #define CCB_DONE_VALID(cp) \
874 ((((u_long) cp) & 0xffffffff00000000ul) && \
875 (((u_long) cp) & 0xfffffffful) != CCB_DONE_EMPTY)
893 #ifndef SCSI_NCR_MYADDR
894 #define SCSI_NCR_MYADDR (7)
902 #ifndef SCSI_NCR_MAX_TAGS
903 #define SCSI_NCR_MAX_TAGS (8)
910 #if SCSI_NCR_MAX_TAGS > 64
911 #define MAX_TAGS (64)
913 #define MAX_TAGS SCSI_NCR_MAX_TAGS
934 #ifdef SCSI_NCR_MAX_TARGET
935 #define MAX_TARGET (SCSI_NCR_MAX_TARGET)
937 #define MAX_TARGET (16)
947 #ifdef SCSI_NCR_MAX_LUN
948 #define MAX_LUN SCSI_NCR_MAX_LUN
957 #ifndef SCSI_NCR_MIN_ASYNC
958 #define SCSI_NCR_MIN_ASYNC (40)
968 #ifdef SCSI_NCR_CAN_QUEUE
969 #define MAX_START (SCSI_NCR_CAN_QUEUE + 4)
971 #define MAX_START (MAX_TARGET + 7 * MAX_TAGS)
981 #define MAX_START 250
993 #define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)
995 #if (MAX_SCATTER > 80)
996 #define MAX_SCATTERL 80
997 #define MAX_SCATTERH (MAX_SCATTER - MAX_SCATTERL)
999 #define MAX_SCATTERL (MAX_SCATTER-1)
1000 #define MAX_SCATTERH 1
1007 #define NCR_SNOOP_TIMEOUT (1000000)
1013 #define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))
1015 #define initverbose (driver_setup.verbose)
1016 #define bootverbose (np->verbose)
1027 #define HS_NEGOTIATE (2)
1028 #define HS_DISCONNECT (3)
1030 #define HS_DONEMASK (0x80)
1031 #define HS_COMPLETE (4|HS_DONEMASK)
1032 #define HS_SEL_TIMEOUT (5|HS_DONEMASK)
1033 #define HS_RESET (6|HS_DONEMASK)
1034 #define HS_ABORTED (7|HS_DONEMASK)
1035 #define HS_TIMEOUT (8|HS_DONEMASK)
1036 #define HS_FAIL (9|HS_DONEMASK)
1037 #define HS_UNEXPECTED (10|HS_DONEMASK)
1045 #define HS_INVALMASK (0x40)
1046 #define HS_SELECTING (0|HS_INVALMASK)
1047 #define HS_IN_RESELECT (1|HS_INVALMASK)
1048 #define HS_STARTING (2|HS_INVALMASK)
1054 #define HS_SKIPMASK (0x20)
1063 #define SIR_BAD_STATUS (1)
1064 #define SIR_XXXXXXXXXX (2)
1065 #define SIR_NEGO_SYNC (3)
1066 #define SIR_NEGO_WIDE (4)
1067 #define SIR_NEGO_FAILED (5)
1068 #define SIR_NEGO_PROTO (6)
1069 #define SIR_REJECT_RECEIVED (7)
1070 #define SIR_REJECT_SENT (8)
1071 #define SIR_IGN_RESIDUE (9)
1072 #define SIR_MISSING_SAVE (10)
1073 #define SIR_RESEL_NO_MSG_IN (11)
1074 #define SIR_RESEL_NO_IDENTIFY (12)
1075 #define SIR_RESEL_BAD_LUN (13)
1076 #define SIR_RESEL_BAD_TARGET (14)
1077 #define SIR_RESEL_BAD_I_T_L (15)
1078 #define SIR_RESEL_BAD_I_T_L_Q (16)
1079 #define SIR_DONE_OVERFLOW (17)
1080 #define SIR_INTFLY (18)
1081 #define SIR_MAX (18)
1092 #define XE_EXTRA_DATA (1)
1093 #define XE_BAD_PHASE (2)
1103 #define NS_NOCHANGE (0)
1115 #define CCB_MAGIC (0xf2691ad2)
1144 #define UC_SETSYNC 10
1145 #define UC_SETTAGS 11
1146 #define UC_SETDEBUG 12
1147 #define UC_SETORDER 13
1148 #define UC_SETWIDE 14
1149 #define UC_SETFLAG 15
1150 #define UC_SETVERBOSE 17
1152 #define UF_TRACE (0x01)
1153 #define UF_NODISC (0x02)
1154 #define UF_NOSCAN (0x04)
1223 #ifdef SCSI_NCR_BIG_ENDIAN
1431 #define HS_PRT nc_scr1
1433 #define SS_PRT nc_scr2
1439 #ifdef SCSI_NCR_BIG_ENDIAN
1440 #define actualquirks phys.header.status[3]
1441 #define host_status phys.header.status[2]
1442 #define scsi_status phys.header.status[1]
1443 #define parity_status phys.header.status[0]
1445 #define actualquirks phys.header.status[0]
1446 #define host_status phys.header.status[1]
1447 #define scsi_status phys.header.status[2]
1448 #define parity_status phys.header.status[3]
1454 #define xerr_st header.scr_st[0]
1455 #define sync_st header.scr_st[1]
1456 #define nego_st header.scr_st[2]
1457 #define wide_st header.scr_st[3]
1462 #define xerr_status phys.xerr_st
1463 #define nego_status phys.nego_st
1466 #define sync_status phys.sync_st
1467 #define wide_status phys.wide_st
1588 #define CCB_PHYS(cp,lbl) (cp->p_ccb + offsetof(struct ccb, lbl))
1748 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1761 #define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
1762 #define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
1794 #ifdef CONFIG_NCR53C8XX_PREFETCH
1795 #define PREFETCH_FLUSH_CNT 2
1796 #define PREFETCH_FLUSH SCR_CALL, PADDRH (wait_dma),
1798 #define PREFETCH_FLUSH_CNT 0
1799 #define PREFETCH_FLUSH
1828 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
1863 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1920 static void ncr_complete (
struct ncb *np,
struct ccb *
cp);
1921 static void ncr_exception (
struct ncb *np);
1922 static void ncr_free_ccb (
struct ncb *np,
struct ccb *
cp);
1923 static void ncr_init_ccb (
struct ncb *np,
struct ccb *
cp);
1924 static void ncr_init_tcb (
struct ncb *np,
u_char tn);
1927 static void ncr_getclock (
struct ncb *np,
int mult);
1928 static void ncr_selectclock (
struct ncb *np,
u_char scntl3);
1929 static struct ccb *ncr_get_ccb (
struct ncb *np,
struct scsi_cmnd *cmd);
1930 static void ncr_chip_reset (
struct ncb *np,
int delay);
1932 static int ncr_int_sbmc (
struct ncb *np);
1933 static int ncr_int_par (
struct ncb *np);
1934 static void ncr_int_ma (
struct ncb *np);
1935 static void ncr_int_sir (
struct ncb *np);
1936 static void ncr_int_sto (
struct ncb *np);
1937 static void ncr_negotiate (
struct ncb* np,
struct tcb* tp);
1938 static int ncr_prepare_nego(
struct ncb *np,
struct ccb *
cp,
u_char *msgptr);
1940 static void ncr_script_copy_and_bind
1946 static void ncr_setup_tags (
struct ncb *np,
struct scsi_device *sdev);
1948 static int ncr_snooptest (
struct ncb *np);
1949 static void ncr_timeout (
struct ncb *np);
1951 static void ncr_wakeup_done (
struct ncb *np);
1952 static void ncr_start_next_ccb (
struct ncb *np,
struct lcb *
lp,
int maxn);
1953 static void ncr_put_start_queue(
struct ncb *np,
struct ccb *
cp);
1955 static void insert_into_waiting_list(
struct ncb *np,
struct scsi_cmnd *cmd);
1956 static struct scsi_cmnd *retrieve_from_waiting_list(
int to_remove,
struct ncb *np,
struct scsi_cmnd *cmd);
1957 static void process_waiting_list(
struct ncb *np,
int sts);
1959 #define remove_from_waiting_list(np, cmd) \
1960 retrieve_from_waiting_list(1, (np), (cmd))
1961 #define requeue_waiting_list(np) process_waiting_list((np), DID_OK)
1962 #define reset_waiting_list(np) process_waiting_list((np), DID_RESET)
1964 static inline char *ncr_name (
struct ncb *np)
1989 #define RELOC_SOFTC 0x40000000
1990 #define RELOC_LABEL 0x50000000
1991 #define RELOC_REGISTER 0x60000000
1993 #define RELOC_KVAR 0x70000000
1995 #define RELOC_LABELH 0x80000000
1996 #define RELOC_MASK 0xf0000000
1998 #define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
1999 #define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
2000 #define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
2001 #define RADDR(label) (RELOC_REGISTER | REG(label))
2002 #define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
2004 #define KVAR(which) (RELOC_KVAR | (which))
2008 #define SCRIPT_KVAR_JIFFIES (0)
2009 #define SCRIPT_KVAR_FIRST SCRIPT_KVAR_JIFFIES
2010 #define SCRIPT_KVAR_LAST SCRIPT_KVAR_JIFFIES
2015 static void *script_kvars[] __initdata =
2019 static struct script script0 __initdata = {
2336 PADDRH (msg_ign_residue),
2448 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
2766 static struct scripth scripth0 __initdata = {
2791 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
3055 PADDR (msg_out_done),
3110 PADDR (msg_out_done),
3458 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
3464 *p++ =
NADDR (ccb_done[i]);
3466 *p++ =
PADDR (done_end);
3476 *p++ =
PADDR (dispatch);
3484 for (i=MAX_SCATTERH; i<MAX_SCATTERH+
MAX_SCATTERL; i++) {
3486 *p++ =
PADDR (dispatch);
3496 *p++ =
PADDR (dispatch);
3504 for (i=MAX_SCATTERH; i<MAX_SCATTERH+
MAX_SCATTERL; i++) {
3506 *p++ =
PADDR (dispatch);
3548 ncr_name(np), (
int) (src-start-1));
3554 (src-1), (
unsigned)opcode);
3559 switch (opcode >> 28) {
3573 if ((tmp2 & RELOC_MASK) == RELOC_KVAR)
3576 if ((tmp1 ^ tmp2) & 3) {
3578 ncr_name(np), (
int) (src-start-1));
3586 dst[-1] =
cpu_to_scr(opcode & ~SCR_NO_FLUSH);
3603 if (opcode & 0x00800000)
3627 new = (old & ~RELOC_MASK) + np->
paddr;
3630 new = (old & ~RELOC_MASK) + np->
p_script;
3633 new = (old & ~RELOC_MASK) + np->
p_scripth;
3636 new = (old & ~RELOC_MASK) + np->
p_ncb;
3640 if (((old & ~RELOC_MASK) <
3641 SCRIPT_KVAR_FIRST) ||
3642 ((old & ~RELOC_MASK) >
3644 panic(
"ncr KVAR out of range");
3645 new = vtophys(script_kvars[old &
3657 panic(
"ncr_script_copy_and_bind: weird relocation %x\n", old);
3677 #define PRINT_ADDR(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
3697 static u_long div_10M[] =
3717 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
3722 #define burst_code(dmode, ctest0) \
3723 (ctest0) & 0x80 ? 0 : (((dmode) & 0xc0) >> 6) + 1
3728 static inline void ncr_init_burst(
struct ncb *np,
u_char bc)
3744 static void __init ncr_prepare_setting(
struct ncb *np)
3816 else if (period <= 303) np->
minsync = 11;
3817 else if (period <= 500) np->
minsync = 12;
3818 else np->
minsync = (period + 40 - 1) / 40;
3832 np->
maxsync = period > 2540 ? 254 : period / 10;
3837 #if defined SCSI_NCR_TRUST_BIOS_SETTING
3852 if (burst_max == 255)
3905 ncr_init_burst(np, burst_max);
3926 if (
INB(nc_gpreg) & 0x08)
3955 switch(driver_setup.
irqm & 3) {
3989 (np->
rv_scntl0 & 0xa) ?
", Parity Checking" :
", NO Parity",
3990 (np->
rv_stest2 & 0x20) ?
", Differential" :
"");
3994 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3999 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
4006 ncr_name(np), np->
paddr2);
4028 static inline void ncr_queue_done_cmd(
struct ncb *np,
struct scsi_cmnd *cmd)
4035 static inline void ncr_flush_done_cmds(
struct scsi_cmnd *lcmd)
4060 static int ncr_prepare_nego(
struct ncb *np,
struct ccb *
cp,
u_char *msgptr)
4076 if (!nego && !tp->
period) {
4081 dev_info(&starget->
dev,
"target did not report SYNC.\n");
4095 cp->nego_status = nego;
4100 ncr_print_msg(cp, nego ==
NS_WIDE ?
4101 "wide msgout":
"sync_msgout", msgptr);
4119 static int ncr_queue_command (
struct ncb *np,
struct scsi_cmnd *cmd)
4139 (sdev->
id >= MAX_TARGET) ||
4153 if ((cmd->
cmnd[0] == 0 || cmd->
cmnd[0] == 0x12) &&
4179 if (np->
settle_time || !(cp=ncr_get_ccb (np, cmd))) {
4180 insert_into_waiting_list(np, cmd);
4200 msgptr[msglen++] = idmsg;
4214 "ordered tag forced.\n");
4225 switch (cmd->
cmnd[0]) {
4235 msgptr[msglen++] =
order;
4241 msgptr[msglen++] = (cp->
tag << 1) + 1;
4253 segments = ncr_scatter(np, cp, cp->
cmd);
4255 ncr_free_ccb(np, cp);
4273 cp->nego_status = 0;
4276 msglen += ncr_prepare_nego (np, cp, msgptr + msglen);
4299 lastp = goalp - 8 - (segments * 16);
4312 lastp = goalp - 8 - (segments * 16);
4332 cp->
phys.header.savep =
4362 cp->
phys.select.sel_id = sdev_id(sdev);
4363 cp->
phys.select.sel_scntl3 = tp->
wval;
4364 cp->
phys.select.sel_sxfer = tp->
sval;
4381 cp->actualquirks = 0;
4384 cp->parity_status = 0;
4386 cp->xerr_status =
XE_OK;
4388 cp->sync_status = tp->
sval;
4389 cp->wide_status = tp->
wval;
4408 ncr_start_next_ccb(np, lp, 2);
4410 ncr_put_start_queue(np, cp);
4428 static void ncr_start_next_ccb(
struct ncb *np,
struct lcb *lp,
int maxn)
4445 ncr_put_start_queue(np, cp);
4449 static void ncr_put_start_queue(
struct ncb *np,
struct ccb *cp)
4480 static int ncr_reset_scsi_bus(
struct ncb *np,
int enab_int,
int settle_delay)
4489 "command processing suspended for %d seconds\n",
4490 ncr_name(np), settle_delay);
4492 ncr_chip_reset(np, 100);
4513 term =
INB(nc_sstat0);
4514 term = ((term & 2) << 7) + ((term & 1) << 17);
4515 term |= ((
INB(nc_sstat2) & 0x01) << 26) |
4516 ((
INW(nc_sbdl) & 0xff) << 9) |
4517 ((
INW(nc_sbdl) & 0xff00) << 10) |
4523 if (term != (2<<7)) {
4524 printk(
"%s: suspicious SCSI data while resetting the BUS.\n",
4526 printk(
"%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
4527 "0x%lx, expecting 0x%lx\n",
4535 OUTB (nc_scntl1, 0);
4546 static void ncr_start_reset(
struct ncb *np)
4562 static int ncr_reset_bus (
struct ncb *np,
struct scsi_cmnd *cmd,
int sync_reset)
4580 ncr_start_reset(np);
4588 if (cp->host_status ==
HS_IDLE)
continue;
4589 if (cp->
cmd == cmd) {
4597 if (!found && retrieve_from_waiting_list(0, np, cmd))
4613 if (!found && sync_reset && !retrieve_from_waiting_list(0, np, cmd)) {
4615 ncr_queue_done_cmd(np, cmd);
4631 static int ncr_abort_command (
struct ncb *np,
struct scsi_cmnd *cmd)
4643 ncr_queue_done_cmd(np, cmd);
4654 if (cp->host_status ==
HS_IDLE)
continue;
4655 if (cp->
cmd == cmd) {
4674 switch(cp->host_status) {
4677 printk (
"%s: abort ccb=%p (cancel)\n", ncr_name (np), cp);
4678 cp->
start.schedule.l_paddr =
4683 cp->
restart.schedule.l_paddr =
4704 static void ncr_detach(
struct ncb *np)
4714 strlcpy(inst_name, ncr_name(np),
sizeof(inst_name));
4716 printk(
"%s: releasing host resources\n", ncr_name(np));
4723 #ifdef DEBUG_NCR53C8XX
4724 printk(
"%s: stopping the timer\n", ncr_name(np));
4730 printk(
"%s: the timer seems to be already stopped\n", ncr_name(np));
4737 #ifdef DEBUG_NCR53C8XX
4738 printk(
"%s: disabling chip interrupts\n", ncr_name(np));
4748 printk(
"%s: resetting chip\n", ncr_name(np));
4749 ncr_chip_reset(np, 100);
4766 while ((cp=np->
ccb->link_ccb) !=
NULL) {
4768 if (cp->host_status) {
4769 printk(
"%s: shall free an active ccb (host_status=%d)\n",
4770 ncr_name(np), cp->host_status);
4772 #ifdef DEBUG_NCR53C8XX
4773 printk(
"%s: freeing ccb (%lx)\n", ncr_name(np), (
u_long) cp);
4780 for (target = 0; target <
MAX_TARGET ; target++) {
4782 for (lun = 0 ; lun <
MAX_LUN ; lun++) {
4785 #ifdef DEBUG_NCR53C8XX
4786 printk(
"%s: freeing lp (%lx)\n", ncr_name(np), (
u_long) lp);
4803 printk(
"%s: host resources successfully released\n", inst_name);
4816 void ncr_complete (
struct ncb *np,
struct ccb *cp)
4834 printk (
"CCB=%lx STAT=%x/%x\n", (
unsigned long)cp,
4835 cp->host_status,cp->scsi_status);
4878 if (cp->parity_status > 1) {
4879 PRINT_ADDR(cmd,
"%d parity error(s).\n",cp->parity_status);
4886 if (cp->xerr_status !=
XE_OK) {
4887 switch (cp->xerr_status) {
4889 PRINT_ADDR(cmd,
"extraneous data discarded.\n");
4892 PRINT_ADDR(cmd,
"invalid scsi phase (4/5).\n");
4908 PRINT_ADDR(cmd,
"ERROR: cmd=%x host_status=%x "
4909 "scsi_status=%x\n", cmd->
cmnd[0],
4910 cp->host_status, cp->scsi_status);
4918 && (cp->scsi_status ==
S_GOOD ||
4952 ncr_setup_tags (np, cmd->
device);
4973 for (i=0; i<14; i++)
printk (
" %x", *p++);
4984 && (cp->scsi_status ==
S_BUSY ||
5000 }
else if (cp->host_status ==
HS_RESET) {
5019 PRINT_ADDR(cmd,
"COMMAND FAILED (%x %x) @%p.\n",
5020 cp->host_status, cp->scsi_status, cp);
5037 switch (cp->scsi_status) {
5044 for (i=0; i<14; i++)
5048 printk (
" STAT: %x\n", cp->scsi_status);
5051 }
else printk (
" HOSTERROR: %x", cp->host_status);
5058 ncr_free_ccb (np, cp);
5065 ncr_start_next_ccb(np, lp, 2);
5076 ncr_queue_done_cmd(np, cmd);
5092 static void ncr_ccb_skipped(
struct ncb *np,
struct ccb *cp)
5097 if (lp && cp != np->
ccb) {
5099 cp->
start.schedule.l_paddr =
5116 void ncr_wakeup_done (
struct ncb *np)
5119 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
5133 np->
scripth->done_queue[5*j + 4] =
5136 np->
scripth->done_queue[5*i + 4] =
5140 ncr_complete (np, cp);
5142 ncr_ccb_skipped (np, cp);
5151 ncr_complete (np, cp);
5153 ncr_ccb_skipped (np, cp);
5164 struct ccb *cp = np->
ccb;
5167 if (cp->host_status !=
HS_IDLE) {
5168 cp->host_status =
code;
5169 ncr_complete (np, cp);
5183 static void ncr_chip_reset(
struct ncb *np,
int delay)
5187 OUTB (nc_istat, 0 );
5205 void ncr_init (
struct ncb *np,
int reset,
char *
msg,
u_long code)
5226 if (msg)
printk (
KERN_INFO "%s: restart (%s).\n", ncr_name (np), msg);
5242 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
5248 np->
scripth0->done_queue[5*i + 4] =
5258 np->
scripth0->done_queue[5*(MAX_DONE-1) + 4] =
5264 ncr_wakeup (np, code);
5274 ncr_chip_reset(np, 2000);
5278 OUTB (nc_scntl1, 0x00);
5295 OUTB (nc_stime0, 0x0c );
5351 printk (
"%s: Downloading SCSI SCRIPTS.\n",
5368 static void ncr_negotiate (
struct ncb* np,
struct tcb* tp)
5381 if (minsync < 12) minsync = 12;
5388 if (minsync < np->minsync)
5437 if (sfac <= 10) per = 250;
5438 else if (sfac == 11) per = 303;
5439 else if (sfac == 12) per = 500;
5440 else per = 40 * sfac;
5448 if (kpc >= (div_10M[div] << 2))
break;
5454 fak = (kpc - 1) / div_10M[div] + 1;
5458 per = (fak * div_10M[
div]) / clk;
5465 if (div >= 1 && fak < 8) {
5467 fak2 = (kpc - 1) / div_10M[div-1] + 1;
5468 per2 = (fak2 * div_10M[div-1]) / clk;
5469 if (per2 < per && fak2 <= 8) {
5477 if (fak < 4) fak = 4;
5483 *scntl3p = ((div+1) << 4) + (sfac < 25 ? 0x80 : 0);
5495 static void ncr_set_sync_wide_status (
struct ncb *np,
u_char target)
5504 np->sync_st = tp->
sval;
5506 np->wide_st = tp->
wval;
5512 if (!cp->
cmd)
continue;
5515 cp->sync_status = tp->
sval;
5516 cp->wide_status = tp->
wval;
5518 cp->
phys.select.sel_scntl3 = tp->
wval;
5519 cp->
phys.select.sel_sxfer = tp->
sval;
5530 static void ncr_setsync (
struct ncb *np,
struct ccb *cp,
u_char scntl3,
u_char sxfer)
5541 if (!scntl3 || !(sxfer & 0x1f))
5550 idiv = ((scntl3 >> 4) & 0x7);
5551 if ((sxfer & 0x1f) && idiv)
5557 if (tp->
sval == sxfer && tp->
wval == scntl3)
5562 if (sxfer & 0x01f) {
5574 ncr_set_sync_wide_status(np, target);
5590 u16 target =
INB (nc_sdid) & 0x0f;
5599 scntl3 = (tp->
wval & (~
EWS)) | (wide ?
EWS : 0);
5601 sxfer = ack ? 0 : tp->
sval;
5606 if (tp->
sval == sxfer && tp->
wval == scntl3)
return;
5615 (scntl3 &
EWS) ?
"en" :
"dis");
5622 ncr_set_sync_wide_status(np, target);
5632 static void ncr_setup_tags (
struct ncb *np,
struct scsi_device *sdev)
5634 unsigned char tn = sdev->
id, ln = sdev->
lun;
5636 struct lcb *lp = tp->
lp[ln];
5637 u_char reqtags, maxdepth;
5642 if ((!tp) || (!lp) || !sdev)
5683 if (reqtags > 1 && lp->
usetags) {
5688 else if (reqtags <= 1 && !lp->
usetags) {
5696 lp->
usetags = reqtags > 1 ? 1 : 0;
5712 "tagged command queue depth set to %d\n",
5716 "tagged command queueing disabled\n");
5735 static void ncr_timeout (
struct ncb *np)
5760 printk(
"%s: command processing resumed\n", ncr_name(np));
5773 if (np->
lasttime + 4*HZ < thistime) {
5780 #ifdef SCSI_NCR_BROKEN_INTR
5836 script_size =
sizeof(
struct script);
5838 script_name =
"script";
5843 script_size =
sizeof(
struct scripth);
5845 script_name =
"scripth";
5850 script_name =
"mem";
5853 printk (
"%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x) @ (%s %x:%08x).\n",
5854 ncr_name (np), (
unsigned)
INB (nc_sdid)&0x0f, dstat, sist,
5855 (
unsigned)
INB (nc_socl), (
unsigned)
INB (nc_sbcl), (
unsigned)
INB (nc_sbdl),
5856 (
unsigned)
INB (nc_sxfer),(
unsigned)
INB (nc_scntl3), script_name, script_ofs,
5857 (
unsigned)
INL (nc_dbc));
5859 if (((script_ofs & 3) == 0) &&
5860 (
unsigned)script_ofs < script_size) {
5861 printk (
"%s: script cmd = %08x\n", ncr_name(np),
5865 printk (
"%s: regdump:", ncr_name(np));
5903 void ncr_exception (
struct ncb *np)
5916 istat =
INB (nc_istat);
5918 OUTB (nc_istat, (istat &
SIGP) | INTF);
5919 istat =
INB (nc_istat);
5921 ncr_wakeup_done (np);
5924 if (!(istat & (
SIP|
DIP)))
5928 OUTB (nc_istat, CABRT);
5935 sist = (istat &
SIP) ?
INW (nc_sist) : 0;
5936 dstat = (istat &
DIP) ?
INB (nc_dstat) : 0;
5939 printk (
"<%d|%x:%x|%x:%x>",
5942 (
unsigned)
INL(nc_dsp),
5943 (
unsigned)
INL(nc_dbc));
5960 if ((sist &
SBMC) && ncr_int_sbmc (np))
5962 if ((sist &
PAR) && ncr_int_par (np))
5975 if (!(sist & (SBMC|PAR)) && !(dstat &
SSI)) {
5976 printk(
"%s: unknown interrupt(s) ignored, "
5977 "ISTAT=%x DSTAT=%x SIST=%x\n",
5978 ncr_name(np), istat, dstat, sist);
6031 for (i = 0; i<
sizeof(np->
regdump); i++)
6037 ncr_log_hard_error(np, sist, dstat);
6039 printk (
"%s: have to clear fifos.\n", ncr_name (np));
6043 if ((sist & (
SGE)) ||
6045 ncr_start_reset(np);
6050 printk (
"%s: handshake timeout\n", ncr_name(np));
6051 ncr_start_reset(np);
6056 printk (
"%s: unexpected disconnect\n", ncr_name(np));
6067 printk (
"%s: unknown interrupt\n", ncr_name(np));
6086 void ncr_int_sto (
struct ncb *np)
6103 ncr_complete (np, cp);
6131 static int ncr_int_sbmc (
struct ncb *np)
6136 printk(
"%s: SCSI bus mode change from %x to %x.\n",
6137 ncr_name(np), np->
scsi_mode, scsi_mode);
6163 static int ncr_int_par (
struct ncb *np)
6172 printk(
"%s: SCSI parity error detected: SCR1=%d DBC=%x SSTAT1=%x\n",
6173 ncr_name(np), hsts, dbc, sstat1);
6198 if (!(dbc & 0xc0000000))
6199 phase = (dbc >> 24) & 7;
6225 ncr_start_reset(np);
6243 static void ncr_int_ma (
struct ncb *np)
6260 sbcl =
INB (nc_sbcl);
6263 rest = dbc & 0xffffff;
6270 if ((cmd & 1) == 0) {
6276 delta=(((ctest5 << 8) | (
INB (nc_dfifo) & 0xff)) -
rest) & 0x3ff;
6278 delta=(
INB (nc_dfifo) -
rest) & 0x7f;
6288 ss0 =
INB (nc_sstat0);
6289 if (ss0 &
OLF) rest++;
6290 if (ss0 &
ORF) rest++;
6291 if (
INB(nc_scntl3) &
EWS) {
6292 ss2 =
INB (nc_sstat2);
6293 if (ss2 &
OLF1) rest++;
6294 if (ss2 &
ORF1) rest++;
6298 printk (
"P%x%x RL=%d D=%d SS0=%x ", cmd&7, sbcl&7,
6299 (
unsigned) rest, (
unsigned) delta, ss0);
6303 printk (
"P%x%x RL=%d ", cmd&7, sbcl&7, rest);
6346 vdsp = &cp->
patch[0];
6350 vdsp = &cp->
patch[4];
6360 printk (
"\nCP=%p CP2=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
6363 (
unsigned)nxtdsp, vdsp, cmd);
6373 printk (
"%s: SCSI phase error fixup: "
6374 "CCB already dequeued (0x%08lx)\n",
6386 tblp = (
u32 *) ((
char*) &cp->
phys + oadr);
6395 printk (
"OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
6407 PRINT_ADDR(cp->
cmd,
"internal error: cmd=%02x != %02x=(vdsp[0] "
6419 if (cp != np->
header.cp) {
6420 printk (
"%s: SCSI phase error fixup: "
6421 "CCB address mismatch (0x%08lx != 0x%08lx)\n",
6430 PRINT_ADDR(cp->
cmd,
"phase change %x-%x %d@%08x resid=%d.\n",
6431 cmd&7, sbcl&7, (
unsigned)olen,
6432 (
unsigned)oadr, (
unsigned)rest);
6433 goto unexpected_phase;
6444 newcmd = &cp->
patch[4];
6452 newcmd[0] =
cpu_to_scr(((cmd & 0x0f) << 24) | rest);
6459 (
int) (newcmd - cp->
patch),
6469 OUTL (nc_temp, newtmp);
6537 ncr_start_reset(np);
6541 static void ncr_sir_to_redo(
struct ncb *np,
int num,
struct ccb *cp)
6567 cp2->
start.schedule.l_paddr =
6584 PRINT_ADDR(cmd,
"QUEUE FULL! %d busy, %d disconnected "
6585 "CCBs\n", busy_cnt, disc_cnt);
6587 if (disc_cnt < lp->numtags) {
6588 lp->
numtags = disc_cnt > 2 ? disc_cnt : 2;
6590 ncr_setup_tags (np, cmd->
device);
6602 ncr_put_start_queue(np, cp);
6652 cp->
phys.header.goalp = startp + 24;
6654 cp->
phys.header.wgoalp = startp + 24;
6661 cp->
start.schedule.l_paddr =
6667 if (cmd->
device->select_no_atn)
6668 cp->
start.schedule.l_paddr =
6671 ncr_put_start_queue(np, cp);
6692 void ncr_int_sir (
struct ncb *np)
6711 ncr_wakeup_done(np);
6712 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
6733 printk (
"%s:%d: SIR %d, "
6734 "incorrect nexus identification on reselection\n",
6735 ncr_name (np), target, num);
6738 printk (
"%s:%d: SIR %d, "
6739 "CCB done queue overflow\n",
6740 ncr_name (np), target, num);
6746 ncr_sir_to_redo(np, num, cp);
6759 if (!cp || cp != np->
header.cp)
6849 "status=%x.\n", num, cp->nego_status);
6856 switch (cp->nego_status) {
6861 ncr_setsync (np, cp, 0, 0xe0);
6866 ncr_setwide (np, cp, 0, 0);
6872 cp->nego_status = 0;
6877 ncr_print_msg(cp,
"sync msgin", np->
msgin);
6883 if (ofs==0) per=255;
6897 if (per < np->minsync)
6899 if (per < tp->minsync)
6910 ncr_getsync(np, per, &fak, &scntl3);
6925 "fak=%d chg=%d.\n", per, scntl3, ofs, fak, chg);
6930 switch (cp->nego_status) {
6938 ncr_setsync(np, cp, 0, 0xe0);
6944 ncr_setsync(np, cp, scntl3, (fak<<5)|ofs);
6951 ncr_setwide(np, cp, 0, 0);
6963 ncr_setsync(np, cp, scntl3, (fak<<5)|ofs);
6969 ncr_print_msg(cp,
"sync msgout", np->
msgout);
6985 ncr_print_msg(cp,
"wide msgin", np->
msgin);
6993 wide = np->
msgin[3];
7000 if (wide && starget)
7008 {chg = 1; wide = tp->
usrwide;}
7017 switch (cp->nego_status) {
7026 ncr_setwide(np, cp, 0, 1);
7031 ncr_setwide(np, cp, wide, 1);
7039 ncr_setsync(np, cp, 0, 0xe0);
7050 ncr_setwide(np, cp, wide, 1);
7058 ncr_print_msg(cp,
"wide msgout", np->
msgin);
7089 ncr_print_msg(cp,
"MESSAGE_REJECT sent for", np->
msgin);
7108 PRINT_ADDR(cp->
cmd,
"IGNORE_WIDE_RESIDUE received, but not yet "
7122 "not saved: data=%x save=%x goal=%x.\n",
7123 (
unsigned)
INL (nc_temp),
7148 struct lcb *lp = tp->
lp[ln];
7167 ncr_alloc_ccb(np, tn, ln);
7208 if (flags & SCSI_NOSLEEP)
break;
7209 if (tsleep ((
caddr_t)cp, PRIBIO|PCATCH,
"ncr", 0))
7239 PRINT_ADDR(cmd,
"ccb @%p using tag %d.\n", cp, tag);
7254 static void ncr_free_ccb (
struct ncb *np,
struct ccb *cp)
7309 #define ncr_reg_bus_addr(r) (np->paddr + offsetof (struct ncr_reg, r))
7316 static void ncr_init_ccb(
struct ncb *np,
struct ccb *cp)
7358 struct lcb *lp = tp->
lp[ln];
7373 memset(cp, 0,
sizeof (*cp));
7374 ncr_init_ccb(np, cp);
7381 np->
ccb->link_ccb =
cp;
7404 static void ncr_init_tcb (
struct ncb *np,
u_char tn)
7425 #ifdef SCSI_NCR_BIG_ENDIAN
7437 #ifdef SCSI_NCR_BIG_ENDIAN
7455 for (i = 0 ; i < 4 ; i++) {
7470 #ifdef SCSI_NCR_BIG_ENDIAN
7494 struct lcb *lp = tp->
lp[ln];
7510 memset(lp, 0,
sizeof(*lp));
7517 ncr_init_tcb(np, tn);
7583 unsigned char tn = sdev->
id, ln = sdev->
lun;
7585 struct lcb *lp = tp->
lp[ln];
7588 if (!lp && !(lp = ncr_alloc_lcb(np, tn, ln)))
7603 for (i = 0 ; i < 64 ; i++)
7610 ncr_setup_tags (np, sdev);
7647 static int ncr_scatter(
struct ncb *np,
struct ccb *cp,
struct scsi_cmnd *cmd)
7650 int use_sg = scsi_sg_count(cmd);
7690 static int __init ncr_regtest (
struct ncb* np)
7702 if (data == 0xffffffff) {
7704 if ((data & 0xe2f0fffd) != 0x02000080) {
7706 printk (
"CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
7713 static int __init ncr_snooptest (
struct ncb* np)
7715 u32 ncr_rd, ncr_wr, ncr_bk, host_rd, host_wr,
pc;
7718 err |= ncr_regtest (np);
7731 OUTL (nc_temp, ncr_wr);
7750 ncr_rd =
INL (nc_scratcha);
7751 ncr_bk =
INL (nc_temp);
7755 ncr_chip_reset(np, 100);
7759 if (i>=NCR_SNOOP_TIMEOUT) {
7760 printk (
"CACHE TEST FAILED: timeout.\n");
7767 printk (
"CACHE TEST FAILED: script execution failed.\n");
7768 printk (
"start=%08lx, pc=%08lx, end=%08lx\n",
7776 if (host_wr != ncr_rd) {
7777 printk (
"CACHE TEST FAILED: host wrote %d, ncr read %d.\n",
7778 (
int) host_wr, (
int) ncr_rd);
7781 if (host_rd != ncr_wr) {
7782 printk (
"CACHE TEST FAILED: ncr wrote %d, host read %d.\n",
7783 (
int) ncr_wr, (
int) host_rd);
7786 if (ncr_bk != ncr_wr) {
7787 printk (
"CACHE TEST FAILED: ncr wrote %d, read back %d.\n",
7788 (
int) ncr_wr, (
int) ncr_bk);
7820 static void ncr_selectclock(
struct ncb *np,
u_char scntl3)
7823 OUTB(nc_scntl3, scntl3);
7828 printk (
"%s: enabling clock multiplier\n", ncr_name(np));
7833 while (!(
INB(nc_stest4) &
LCKFRQ) && --i > 0)
7836 printk(
"%s: the chip cannot lock the frequency\n", ncr_name(np));
7840 OUTB(nc_scntl3, scntl3);
7842 OUTB(nc_stest3, 0x00);
7849 static unsigned __init ncrgetfreq (
struct ncb *np,
int gen)
7869 OUTB (nc_stest1, 0);
7874 OUTB (nc_scntl3, 4);
7875 OUTB (nc_stime1, 0);
7876 OUTB (nc_stime1, gen);
7877 while (!(
INW(nc_sist) &
GEN) && ms++ < 100000) {
7878 for (count = 0; count < 10; count ++)
7881 OUTB (nc_stime1, 0);
7887 OUTB (nc_scntl3, 0);
7890 printk (
"%s: Delay (GEN=%d): %u msec\n", ncr_name(np), gen, ms);
7894 return ms ? ((1 <<
gen) * 4340) / ms : 0;
7902 unsigned char scntl3 =
INB(nc_scntl3);
7903 unsigned char stest1 =
INB(nc_stest1);
7914 printk (
"%s: clock multiplier found\n", ncr_name(np));
7923 if (np->
multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) {
7926 ncr_chip_reset(np, 5);
7928 (
void) ncrgetfreq (np, 11);
7929 f1 = ncrgetfreq (np, 11);
7930 f2 = ncrgetfreq (np, 11);
7933 printk (
"%s: NCR clock is %uKHz, %uKHz\n", ncr_name(np), f1, f2);
7935 if (f1 > f2) f1 =
f2;
7937 if (f1 < 45000) f1 = 40000;
7938 else if (f1 < 55000) f1 = 50000;
7941 if (f1 < 80000 && mult > 1) {
7943 printk (
"%s: clock multiplier assumed\n", ncr_name(np));
7947 if ((scntl3 & 7) == 3) f1 = 40000;
7948 else if ((scntl3 & 7) == 5) f1 = 80000;
7966 struct ncb *np = ((
struct host_data *) host->hostdata)->ncb;
7976 struct ncb *np = ((
struct host_data *) host->hostdata)->ncb;
7978 struct lcb *lp = tp->
lp[device->
lun];
7981 ncr_setup_lcb(np, device);
7989 numtags = device_queue_depth(np->
unit, device->
id, device->
lun);
7995 if (depth_to_use < 2)
8018 ncr_setup_tags (np, device);
8020 #ifdef DEBUG_NCR53C8XX
8021 printk(
"ncr53c8xx_select_queue_depth: host=%d, id=%d, lun=%d, depth=%d\n",
8022 np->
unit, device->
id, device->
lun, depth_to_use);
8034 unsigned long flags;
8037 #ifdef DEBUG_NCR53C8XX
8038 printk(
"ncr53c8xx_queue_command\n");
8043 cmd->__data_mapped = 0;
8044 cmd->__data_mapping = 0;
8048 if ((sts = ncr_queue_command(np, cmd)) !=
DID_OK) {
8050 #ifdef DEBUG_NCR53C8XX
8051 printk(
"ncr53c8xx : command not queued - result=%d\n", sts);
8054 #ifdef DEBUG_NCR53C8XX
8056 printk(
"ncr53c8xx : command successfully queued\n");
8059 spin_unlock_irqrestore(&np->
smp_lock, flags);
8074 unsigned long flags;
8077 struct ncb *np = host_data->
ncb;
8080 #ifdef DEBUG_NCR53C8XX
8081 printk(
"ncr53c8xx : interrupt received\n");
8090 spin_unlock_irqrestore(&np->
smp_lock, flags);
8095 ncr_flush_done_cmds(done_list);
8099 static void ncr53c8xx_timeout(
unsigned long npref)
8101 struct ncb *np = (
struct ncb *) npref;
8102 unsigned long flags;
8109 spin_unlock_irqrestore(&np->
smp_lock, flags);
8112 ncr_flush_done_cmds(done_list);
8115 static int ncr53c8xx_bus_reset(
struct scsi_cmnd *cmd)
8117 struct ncb *np = ((
struct host_data *) cmd->
device->host->hostdata)->ncb;
8119 unsigned long flags;
8130 sts = ncr_reset_bus(np, cmd, 1);
8134 spin_unlock_irqrestore(&np->
smp_lock, flags);
8136 ncr_flush_done_cmds(done_list);
8142 static int ncr53c8xx_abort(
struct scsi_cmnd *cmd)
8144 struct ncb *np = ((
struct host_data *) cmd->
device->host->hostdata)->ncb;
8146 unsigned long flags;
8149 printk(
"ncr53c8xx_abort\n");
8151 NCR_LOCK_NCB(np, flags);
8153 sts = ncr_abort_command(np, cmd);
8157 NCR_UNLOCK_NCB(np, flags);
8159 ncr_flush_done_cmds(done_list);
8179 #define next_wcmd host_scribble
8181 static void insert_into_waiting_list(
struct ncb *np,
struct scsi_cmnd *cmd)
8185 #ifdef DEBUG_WAITING_LIST
8186 printk(
"%s: cmd %lx inserted into waiting list\n", ncr_name(np), (
u_long) cmd);
8188 cmd->next_wcmd =
NULL;
8191 while (wcmd->next_wcmd)
8192 wcmd = (
struct scsi_cmnd *) wcmd->next_wcmd;
8193 wcmd->next_wcmd = (
char *)
cmd;
8197 static struct scsi_cmnd *retrieve_from_waiting_list(
int to_remove,
struct ncb *np,
struct scsi_cmnd *cmd)
8204 *pcmd = (
struct scsi_cmnd *) cmd->next_wcmd;
8205 cmd->next_wcmd =
NULL;
8207 #ifdef DEBUG_WAITING_LIST
8208 printk(
"%s: cmd %lx retrieved from waiting list\n", ncr_name(np), (
u_long) cmd);
8212 pcmd = (
struct scsi_cmnd **) &(*pcmd)->next_wcmd;
8217 static void process_waiting_list(
struct ncb *np,
int sts)
8224 #ifdef DEBUG_WAITING_LIST
8225 if (waiting_list)
printk(
"%s: waiting_list=%lx processing sts=%d\n", ncr_name(np), (
u_long) waiting_list, sts);
8227 while ((wcmd = waiting_list) !=
NULL) {
8228 waiting_list = (
struct scsi_cmnd *) wcmd->next_wcmd;
8229 wcmd->next_wcmd =
NULL;
8231 #ifdef DEBUG_WAITING_LIST
8232 printk(
"%s: cmd %lx trying to requeue\n", ncr_name(np), (
u_long) wcmd);
8234 sts = ncr_queue_command(np, wcmd);
8237 #ifdef DEBUG_WAITING_LIST
8238 printk(
"%s: cmd %lx done forced sts=%d\n", ncr_name(np), (
u_long) wcmd, sts);
8241 ncr_queue_done_cmd(np, wcmd);
8248 static ssize_t show_ncr53c8xx_revision(
struct device *dev,
8252 struct host_data *host_data = (
struct host_data *)host->hostdata;
8254 return snprintf(buf, 20,
"0x%x\n", host_data->
ncb->revision_id);
8258 .attr = { .name =
"revision", .mode =
S_IRUGO, },
8259 .show = show_ncr53c8xx_revision,
8263 &ncr53c8xx_revision_attr,
8279 static int __init ncr53c8xx_setup(
char *str)
8281 return sym53c8xx__setup(str);
8284 __setup(
"ncr53c8xx=", ncr53c8xx_setup);
8300 struct host_data *host_data;
8325 unit, device->
chip.revision_id, device->
slot.irq);
8330 host_data = (
struct host_data *) instance->hostdata;
8332 np = __m_calloc_dma(device->
dev,
sizeof(
struct ncb),
"NCB");
8338 host_data->
ncb = np;
8365 np->
timer.function = ncr53c8xx_timeout;
8379 "%s: can't map memory mapped IO region\n",ncr_name(np));
8384 "%s: using memory mapped IO at virtual address 0x%lx\n", ncr_name(np), (
u_long) np->
vaddr);
8394 ncr_prepare_setting(np);
8407 instance->
irq = device->
slot.irq;
8414 BUG_ON(!ncr53c8xx_transport_template);
8415 instance->
transportt = ncr53c8xx_transport_template;
8418 ncr_script_fill(&script0, &scripth0);
8424 ncr_script_copy_and_bind(np, (
ncrcmd *) &script0,
8426 ncr_script_copy_and_bind(np, (
ncrcmd *) &scripth0,
8446 for (i = 0 ; i < 4 ; i++) {
8453 ncr_chip_reset(np, 100);
8457 if (ncr_snooptest(np)) {
8466 ncr_init_ccb(np, np->
ccb);
8475 if (ncr_reset_scsi_bus(np, 0, driver_setup.
settle_delay) != 0) {
8476 printk(
KERN_ERR "%s: FATAL ERROR: CHECK SCSI BUS - CABLES, TERMINATION, DEVICE POWER etc.!\n", ncr_name(np));
8478 spin_unlock_irqrestore(&np->
smp_lock, flags);
8490 printk(
KERN_INFO "%s: waiting %d seconds for scsi devices to settle...\n",
8500 #ifdef SCSI_NCR_ALWAYS_SIMPLE_TAG
8504 spin_unlock_irqrestore(&np->
smp_lock, flags);
8532 struct host_data *host_data = shost_priv(host);
8533 #ifdef DEBUG_NCR53C8XX
8534 printk(
"ncr53c8xx: release\n");
8537 ncr_detach(host_data->
ncb);
8541 static void ncr53c8xx_set_period(
struct scsi_target *starget,
int period)
8543 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
8544 struct ncb *np = ((
struct host_data *)shost->hostdata)->ncb;
8549 else if (period < np->minsync)
8554 ncr_negotiate(np, tp);
8559 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
8560 struct ncb *np = ((
struct host_data *)shost->hostdata)->ncb;
8565 else if (offset < 0)
8570 ncr_negotiate(np, tp);
8575 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
8576 struct ncb *np = ((
struct host_data *)shost->hostdata)->ncb;
8586 ncr_negotiate(np, tp);
8589 static void ncr53c8xx_get_signalling(
struct Scsi_Host *shost)
8591 struct ncb *np = ((
struct host_data *)shost->hostdata)->ncb;
8609 .set_period = ncr53c8xx_set_period,
8611 .set_offset = ncr53c8xx_set_offset,
8613 .set_width = ncr53c8xx_set_width,
8615 .get_signalling = ncr53c8xx_get_signalling,
8621 if (!ncr53c8xx_transport_template)