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;