Lines Matching refs:np

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)
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)
576 #define bootverbose (np->verbose)
1016 #define bootverbose (np->verbose)
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))
1919 static void ncr_alloc_ccb (struct ncb *np, u_char tn, u_char ln);
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);
1925 static struct lcb * ncr_alloc_lcb (struct ncb *np, u_char tn, u_char ln);
1926 static struct lcb * ncr_setup_lcb (struct ncb *np, struct scsi_device *sdev);
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);
1931 static void ncr_init (struct ncb *np, int reset, char * msg, u_long code);
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);
1941 (struct ncb *np, ncrcmd *src, ncrcmd *dst, int len);
1943 static int ncr_scatter (struct ncb *np, struct ccb *cp, struct scsi_cmnd *cmd);
1944 static void ncr_getsync (struct ncb *np, u_char sfac, u_char *fakp, u_char *scntl3p);
1945 static void ncr_setsync (struct ncb *np, struct ccb *cp, u_char scntl3, u_char sxfer);
1946 static void ncr_setup_tags (struct ncb *np, struct scsi_device *sdev);
1947 static void ncr_setwide (struct ncb *np, struct ccb *cp, u_char wide, u_char ack);
1948 static int ncr_snooptest (struct ncb *np);
1949 static void ncr_timeout (struct ncb *np);
1950 static void ncr_wakeup (struct ncb *np, u_long code);
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)
1966 return np->inst_name;
3524 ncr_script_copy_and_bind (struct ncb *np, ncrcmd *src, ncrcmd *dst, int len)
3548 ncr_name(np), (int) (src-start-1));
3578 ncr_name(np), (int) (src-start-1));
3585 if ((opcode & SCR_NO_FLUSH) && !(np->features & FE_PFEN)) {
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;
3728 static inline void ncr_init_burst(struct ncb *np, u_char bc)
3730 u_char *be = &np->rv_ctest0;
3732 np->rv_dmode &= ~(0x3 << 6);
3733 np->rv_ctest5 &= ~0x4;
3739 np->rv_dmode |= ((bc & 0x3) << 6);
3740 np->rv_ctest5 |= (bc & 0x4);
3744 static void __init ncr_prepare_setting(struct ncb *np)
3754 np->sv_scntl0 = INB(nc_scntl0) & 0x0a;
3755 np->sv_scntl3 = INB(nc_scntl3) & 0x07;
3756 np->sv_dmode = INB(nc_dmode) & 0xce;
3757 np->sv_dcntl = INB(nc_dcntl) & 0xa8;
3758 np->sv_ctest0 = INB(nc_ctest0) & 0x84;
3759 np->sv_ctest3 = INB(nc_ctest3) & 0x01;
3760 np->sv_ctest4 = INB(nc_ctest4) & 0x80;
3761 np->sv_ctest5 = INB(nc_ctest5) & 0x24;
3762 np->sv_gpcntl = INB(nc_gpcntl);
3763 np->sv_stest2 = INB(nc_stest2) & 0x20;
3764 np->sv_stest4 = INB(nc_stest4);
3770 np->maxwide = (np->features & FE_WIDE)? 1 : 0;
3775 if (np->features & FE_ULTRA)
3776 np->clock_khz = 80000;
3778 np->clock_khz = 40000;
3783 if (np->features & FE_QUAD)
3784 np->multiplier = 4;
3785 else if (np->features & FE_DBLR)
3786 np->multiplier = 2;
3788 np->multiplier = 1;
3794 if (np->features & FE_VARCLK)
3795 ncr_getclock(np, np->multiplier);
3800 i = np->clock_divn - 1;
3802 if (10ul * SCSI_NCR_MIN_ASYNC * np->clock_khz > div_10M[i]) {
3807 np->rv_scntl3 = i+1;
3814 period = (4 * div_10M[0] + np->clock_khz - 1) / np->clock_khz;
3815 if (period <= 250) np->minsync = 10;
3816 else if (period <= 303) np->minsync = 11;
3817 else if (period <= 500) np->minsync = 12;
3818 else np->minsync = (period + 40 - 1) / 40;
3824 if (np->minsync < 25 && !(np->features & FE_ULTRA))
3825 np->minsync = 25;
3831 period = (11 * div_10M[np->clock_divn - 1]) / (4 * np->clock_khz);
3832 np->maxsync = period > 2540 ? 254 : period / 10;
3838 np->rv_scntl0 = np->sv_scntl0;
3839 np->rv_dmode = np->sv_dmode;
3840 np->rv_dcntl = np->sv_dcntl;
3841 np->rv_ctest0 = np->sv_ctest0;
3842 np->rv_ctest3 = np->sv_ctest3;
3843 np->rv_ctest4 = np->sv_ctest4;
3844 np->rv_ctest5 = np->sv_ctest5;
3845 burst_max = burst_code(np->sv_dmode, np->sv_ctest0);
3853 burst_max = burst_code(np->sv_dmode, np->sv_ctest0);
3856 if (burst_max > np->maxburst)
3857 burst_max = np->maxburst;
3862 if (np->features & FE_ERL)
3863 np->rv_dmode |= ERL; /* Enable Read Line */
3864 if (np->features & FE_BOF)
3865 np->rv_dmode |= BOF; /* Burst Opcode Fetch */
3866 if (np->features & FE_ERMP)
3867 np->rv_dmode |= ERMP; /* Enable Read Multiple */
3868 if (np->features & FE_PFEN)
3869 np->rv_dcntl |= PFEN; /* Prefetch Enable */
3870 if (np->features & FE_CLSE)
3871 np->rv_dcntl |= CLSE; /* Cache Line Size Enable */
3872 if (np->features & FE_WRIE)
3873 np->rv_ctest3 |= WRIE; /* Write and Invalidate */
3874 if (np->features & FE_DFS)
3875 np->rv_ctest5 |= DFS; /* Dma Fifo Size */
3876 if (np->features & FE_MUX)
3877 np->rv_ctest4 |= MUX; /* Host bus multiplex mode */
3878 if (np->features & FE_EA)
3879 np->rv_dcntl |= EA; /* Enable ACK */
3880 if (np->features & FE_EHP)
3881 np->rv_ctest0 |= EHP; /* Even host parity */
3887 np->rv_ctest4 |= MPEE; /* Master parity checking */
3889 np->rv_scntl0 |= 0x0a; /* full arb., ena parity, par->ATN */
3894 if (np->myaddr == 255) {
3895 np->myaddr = INB(nc_scid) & 0x07;
3896 if (!np->myaddr)
3897 np->myaddr = SCSI_NCR_MYADDR;
3905 ncr_init_burst(np, burst_max);
3916 np->scsi_mode = SMODE_SE;
3917 if (np->features & FE_DIFF) {
3920 if (np->sv_scntl3) {
3921 if (np->sv_stest2 & 0x20)
3922 np->scsi_mode = SMODE_HVD;
3929 np->scsi_mode = SMODE_HVD;
3931 if (np->sv_stest2 & 0x20)
3932 np->scsi_mode = SMODE_HVD;
3938 if (np->scsi_mode == SMODE_HVD)
3939 np->rv_stest2 |= 0x20;
3949 !(np->features & FE_LEDC) && !(np->sv_gpcntl & 0x01))
3950 np->features |= FE_LED0;
3957 np->rv_dcntl |= IRQM;
3960 np->rv_dcntl |= (np->sv_dcntl & IRQM);
3972 struct tcb *tp = &np->target[i];
3979 np->target[i].usrflag = UF_NODISC;
3986 printk(KERN_INFO "%s: ID %d, Fast-%d%s%s\n", ncr_name(np),
3987 np->myaddr,
3988 np->minsync < 12 ? 40 : (np->minsync < 25 ? 20 : 10),
3989 (np->rv_scntl0 & 0xa) ? ", Parity Checking" : ", NO Parity",
3990 (np->rv_stest2 & 0x20) ? ", Differential" : "");
3995 ncr_name(np), np->sv_scntl3, np->sv_dmode, np->sv_dcntl,
3996 np->sv_ctest3, np->sv_ctest4, np->sv_ctest5);
4000 ncr_name(np), np->rv_scntl3, np->rv_dmode, np->rv_dcntl,
4001 np->rv_ctest3, np->rv_ctest4, np->rv_ctest5);
4004 if (bootverbose && np->paddr2)
4006 ncr_name(np), np->paddr2);
4028 static inline void ncr_queue_done_cmd(struct ncb *np, struct scsi_cmnd *cmd)
4030 unmap_scsi_data(np, cmd);
4031 cmd->host_scribble = (char *) np->done_list;
4032 np->done_list = cmd;
4060 static int ncr_prepare_nego(struct ncb *np, struct ccb *cp, u_char *msgptr)
4062 struct tcb *tp = &np->target[cp->target];
4119 static int ncr_queue_command (struct ncb *np, struct scsi_cmnd *cmd)
4122 struct tcb *tp = &np->target[sdev->id];
4138 if ((sdev->id == np->myaddr ) ||
4173 if (np->settle_time && cmd->request->timeout >= HZ) {
4175 if (time_after(np->settle_time, tlimit))
4176 np->settle_time = tlimit;
4179 if (np->settle_time || !(cp=ncr_get_ccb (np, cmd))) {
4180 insert_into_waiting_list(np, cmd);
4195 (cp != np->ccb && np->disc && !(tp->usrflag & UF_NODISC)))
4203 char order = np->order;
4253 segments = ncr_scatter(np, cp, cp->cmd);
4255 ncr_free_ccb(np, cp);
4276 msglen += ncr_prepare_nego (np, cp, msgptr + msglen);
4297 goalp = NCB_SCRIPT_PHYS (np, data_out2) + 8;
4301 lastp = NCB_SCRIPTH_PHYS (np, hdata_out2);
4310 goalp = NCB_SCRIPT_PHYS (np, data_in2) + 8;
4314 lastp = NCB_SCRIPTH_PHYS (np, hdata_in2);
4320 lastp = goalp = NCB_SCRIPT_PHYS (np, no_data);
4333 cpu_to_scr(NCB_SCRIPTH_PHYS (np, data_io));
4357 cp->start.schedule.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, select));
4358 cp->restart.schedule.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, resel_dsa));
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)
4456 if (!np->squeueput) np->squeueput = 1;
4457 qidx = np->squeueput + 2;
4460 np->scripth->tryloop [qidx] = cpu_to_scr(NCB_SCRIPT_PHYS (np, idle));
4462 np->scripth->tryloop [np->squeueput] = cpu_to_scr(CCB_PHYS (cp, start));
4464 np->squeueput = qidx;
4465 ++np->queuedccbs;
4469 printk ("%s: queuepos=%d.\n", ncr_name (np), np->squeueput);
4480 static int ncr_reset_scsi_bus(struct ncb *np, int enab_int, int settle_delay)
4485 np->settle_time = jiffies + settle_delay * HZ;
4490 ncr_name(np), settle_delay);
4492 ncr_chip_reset(np, 100);
4520 if (!(np->features & FE_WIDE))
4525 ncr_name(np));
4528 ncr_name(np),
4529 (np->features & FE_WIDE) ? "dp1,d15-8," : "",
4546 static void ncr_start_reset(struct ncb *np)
4548 if (!np->settle_time) {
4549 ncr_reset_scsi_bus(np, 1, driver_setup.settle_delay);
4562 static int ncr_reset_bus (struct ncb *np, struct scsi_cmnd *cmd, int sync_reset)
4571 if (np->settle_time) {
4580 ncr_start_reset(np);
4584 for (found=0, cp=np->ccb; cp; cp=cp->link_ccb) {
4597 if (!found && retrieve_from_waiting_list(0, np, cmd))
4602 reset_waiting_list(np);
4606 ncr_wakeup(np, HS_RESET);
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)
4641 if (remove_from_waiting_list(np, cmd)) {
4643 ncr_queue_done_cmd(np, cmd);
4650 for (found=0, cp=np->ccb; cp; cp=cp->link_ccb) {
4665 if (np->settle_time) {
4677 printk ("%s: abort ccb=%p (cancel)\n", ncr_name (np), cp);
4679 cpu_to_scr(NCB_SCRIPTH_PHYS (np, cancel));
4684 cpu_to_scr(NCB_SCRIPTH_PHYS (np, abort));
4704 static void ncr_detach(struct ncb *np)
4713 /* Local copy so we don't access np after freeing it! */
4714 strlcpy(inst_name, ncr_name(np), sizeof(inst_name));
4716 printk("%s: releasing host resources\n", ncr_name(np));
4724 printk("%s: stopping the timer\n", ncr_name(np));
4726 np->release_stage = 1;
4727 for (i = 50 ; i && np->release_stage != 2 ; i--)
4729 if (np->release_stage != 2)
4730 printk("%s: the timer seems to be already stopped\n", ncr_name(np));
4731 else np->release_stage = 2;
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);
4751 OUTB(nc_dmode, np->sv_dmode);
4752 OUTB(nc_dcntl, np->sv_dcntl);
4753 OUTB(nc_ctest0, np->sv_ctest0);
4754 OUTB(nc_ctest3, np->sv_ctest3);
4755 OUTB(nc_ctest4, np->sv_ctest4);
4756 OUTB(nc_ctest5, np->sv_ctest5);
4757 OUTB(nc_gpcntl, np->sv_gpcntl);
4758 OUTB(nc_stest2, np->sv_stest2);
4760 ncr_selectclock(np, np->sv_scntl3);
4766 while ((cp=np->ccb->link_ccb) != NULL) {
4767 np->ccb->link_ccb = cp->link_ccb;
4770 ncr_name(np), cp->host_status);
4773 printk("%s: freeing ccb (%lx)\n", ncr_name(np), (u_long) cp);
4781 tp=&np->target[target];
4786 printk("%s: freeing lp (%lx)\n", ncr_name(np), (u_long) lp);
4795 if (np->scripth0)
4796 m_free_dma(np->scripth0, sizeof(struct scripth), "SCRIPTH");
4797 if (np->script0)
4798 m_free_dma(np->script0, sizeof(struct script), "SCRIPT");
4799 if (np->ccb)
4800 m_free_dma(np->ccb, sizeof(struct ccb), "CCB");
4801 m_free_dma(np, sizeof(struct ncb), "NCB");
4816 void ncr_complete (struct ncb *np, struct ccb *cp)
4843 tp = &np->target[cmd->device->id];
4938 ncr_alloc_lcb (np, cmd->device->id, cmd->device->lun);
4952 ncr_setup_tags (np, cmd->device);
5058 ncr_free_ccb (np, cp);
5065 ncr_start_next_ccb(np, lp, 2);
5070 if (np->waiting_list)
5071 requeue_waiting_list(np);
5076 ncr_queue_done_cmd(np, cmd);
5092 static void ncr_ccb_skipped(struct ncb *np, struct ccb *cp)
5094 struct tcb *tp = &np->target[cp->target];
5097 if (lp && cp != np->ccb) {
5100 cpu_to_scr(NCB_SCRIPT_PHYS (np, select));
5107 --np->queuedccbs;
5116 void ncr_wakeup_done (struct ncb *np)
5122 i = np->ccb_done_ic;
5128 cp = np->ccb_done[j];
5132 np->ccb_done[j] = (struct ccb *)CCB_DONE_EMPTY;
5133 np->scripth->done_queue[5*j + 4] =
5134 cpu_to_scr(NCB_SCRIPT_PHYS (np, done_plug));
5136 np->scripth->done_queue[5*i + 4] =
5137 cpu_to_scr(NCB_SCRIPT_PHYS (np, done_end));
5140 ncr_complete (np, cp);
5142 ncr_ccb_skipped (np, cp);
5146 np->ccb_done_ic = i;
5148 cp = np->ccb;
5151 ncr_complete (np, cp);
5153 ncr_ccb_skipped (np, cp);
5162 void ncr_wakeup (struct ncb *np, u_long code)
5164 struct ccb *cp = np->ccb;
5169 ncr_complete (np, cp);
5183 static void ncr_chip_reset(struct ncb *np, int delay)
5189 if (np->features & FE_EHP)
5191 if (np->features & FE_MUX)
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);
5231 np->queuedepth = MAX_START - 1; /* 1 entry needed as end marker */
5233 np->scripth0->tryloop[i] =
5234 cpu_to_scr(NCB_SCRIPT_PHYS (np, idle));
5239 np->squeueput = 0;
5240 np->script0->startpos[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np, tryloop));
5247 np->ccb_done[i] = (struct ccb *)CCB_DONE_EMPTY;
5248 np->scripth0->done_queue[5*i + 4] =
5249 cpu_to_scr(NCB_SCRIPT_PHYS (np, done_end));
5256 np->script0->done_pos[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np,done_queue));
5257 np->ccb_done_ic = MAX_DONE-1;
5258 np->scripth0->done_queue[5*(MAX_DONE-1) + 4] =
5259 cpu_to_scr(NCB_SCRIPT_PHYS (np, done_plug));
5264 ncr_wakeup (np, code);
5274 ncr_chip_reset(np, 2000);
5276 OUTB (nc_scntl0, np->rv_scntl0 | 0xc0);
5280 ncr_selectclock(np, np->rv_scntl3); /* Select SCSI clock */
5282 OUTB (nc_scid , RRE|np->myaddr); /* Adapter SCSI address */
5283 OUTW (nc_respid, 1ul<<np->myaddr); /* Id to respond to */
5285 OUTB (nc_dmode , np->rv_dmode); /* Burst length, dma mode */
5286 OUTB (nc_ctest5, np->rv_ctest5); /* Large fifo + large burst */
5288 OUTB (nc_dcntl , NOCOM|np->rv_dcntl); /* Protect SFBR */
5289 OUTB (nc_ctest0, np->rv_ctest0); /* 720: CDIS and EHP */
5290 OUTB (nc_ctest3, np->rv_ctest3); /* Write and invalidate */
5291 OUTB (nc_ctest4, np->rv_ctest4); /* Master parity checking */
5293 OUTB (nc_stest2, EXT|np->rv_stest2); /* Extended Sreq/Sack filtering */
5301 np->disc = 0;
5307 if (np->features & FE_LED0) {
5326 struct tcb *tp = &np->target[i];
5329 tp->wval = np->rv_scntl3;
5332 if (tp->usrsync <= np->maxsync) {
5333 if (tp->usrsync < np->minsync) {
5334 tp->usrsync = np->minsync;
5341 if (tp->usrwide > np->maxwide)
5342 tp->usrwide = np->maxwide;
5349 if (np->paddr2) {
5352 ncr_name(np));
5353 OUTL (nc_scratcha, vtobus(np->script0));
5354 OUTL_DSP (NCB_SCRIPTH_PHYS (np, start_ram));
5357 OUTL_DSP (NCB_SCRIPT_PHYS (np, start));
5368 static void ncr_negotiate (struct ncb* np, struct tcb* tp)
5380 if (np->scsi_mode && np->scsi_mode == SMODE_SE) {
5388 if (minsync < np->minsync)
5389 minsync = np->minsync;
5395 if (minsync > np->maxsync)
5398 if (tp->maxoffs > np->maxoffs)
5399 tp->maxoffs = np->maxoffs;
5426 static void ncr_getsync(struct ncb *np, u_char sfac, u_char *fakp, u_char *scntl3p)
5428 u_long clk = np->clock_khz; /* SCSI clock frequency in kHz */
5429 int div = np->clock_divn; /* Number of divisors supported */
5495 static void ncr_set_sync_wide_status (struct ncb *np, u_char target)
5498 struct tcb *tp = &np->target[target];
5504 np->sync_st = tp->sval;
5506 np->wide_st = tp->wval;
5511 for (cp = np->ccb; cp; cp = cp->link_ccb) {
5530 static void ncr_setsync (struct ncb *np, struct ccb *cp, u_char scntl3, u_char sxfer)
5539 tp = &np->target[target];
5542 scntl3 = np->rv_scntl3;
5543 scntl3 = (scntl3 & 0xf0) | (tp->wval & EWS) | (np->rv_scntl3 & 0x07);
5552 tp->period = (((sxfer>>5)+4)*div_10M[idiv-1])/np->clock_khz;
5574 ncr_set_sync_wide_status(np, target);
5587 static void ncr_setwide (struct ncb *np, struct ccb *cp, u_char wide, u_char ack)
5597 tp = &np->target[target];
5622 ncr_set_sync_wide_status(np, target);
5632 static void ncr_setup_tags (struct ncb *np, struct scsi_device *sdev)
5635 struct tcb *tp = &np->target[tn];
5703 cpu_to_scr(NCB_SCRIPT_PHYS(np, resel_tag)) :
5704 cpu_to_scr(NCB_SCRIPT_PHYS(np, resel_notag));
5735 static void ncr_timeout (struct ncb *np)
5745 if (np->release_stage) {
5746 if (np->release_stage == 1) np->release_stage = 2;
5750 np->timer.expires = jiffies + SCSI_NCR_TIMER_INTERVAL;
5751 add_timer(&np->timer);
5757 if (np->settle_time) {
5758 if (np->settle_time <= thistime) {
5760 printk("%s: command processing resumed\n", ncr_name(np));
5761 np->settle_time = 0;
5762 np->disc = 1;
5763 requeue_waiting_list(np);
5773 if (np->lasttime + 4*HZ < thistime) {
5777 np->lasttime = thistime;
5787 ncr_exception (np);
5823 static void ncr_log_hard_error(struct ncb *np, u16 sist, u_char dstat)
5834 if (dsp > np->p_script && dsp <= np->p_script + sizeof(struct script)) {
5835 script_ofs = dsp - np->p_script;
5837 script_base = (u_char *) np->script0;
5840 else if (np->p_scripth < dsp &&
5841 dsp <= np->p_scripth + sizeof(struct scripth)) {
5842 script_ofs = dsp - np->p_scripth;
5844 script_base = (u_char *) np->scripth0;
5854 ncr_name (np), (unsigned)INB (nc_sdid)&0x0f, dstat, sist,
5861 printk ("%s: script cmd = %08x\n", ncr_name(np),
5865 printk ("%s: regdump:", ncr_name(np));
5903 void ncr_exception (struct ncb *np)
5921 ncr_wakeup_done (np);
5960 if ((sist & SBMC) && ncr_int_sbmc (np))
5962 if ((sist & PAR) && ncr_int_par (np))
5965 ncr_int_ma (np);
5969 ncr_int_sir (np);
5978 ncr_name(np), istat, dstat, sist);
6001 ncr_init (np, 1, bootverbose ? "scsi reset" : NULL, HS_RESET);
6012 ncr_int_sto (np);
6029 if (time_after(jiffies, np->regtime)) {
6030 np->regtime = jiffies + 10*HZ;
6031 for (i = 0; i<sizeof(np->regdump); i++)
6032 ((char*)&np->regdump)[i] = INB_OFF(i);
6033 np->regdump.nc_dstat = dstat;
6034 np->regdump.nc_sist = sist;
6037 ncr_log_hard_error(np, sist, dstat);
6039 printk ("%s: have to clear fifos.\n", ncr_name (np));
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));
6058 OUTL_DSP (NCB_SCRIPT_PHYS (np, cleanup));
6067 printk ("%s: unknown interrupt\n", ncr_name(np));
6086 void ncr_int_sto (struct ncb *np)
6097 cp = np->ccb;
6103 ncr_complete (np, cp);
6110 OUTL_DSP (NCB_SCRIPTH_PHYS (np, sto_restart));
6131 static int ncr_int_sbmc (struct ncb *np)
6135 if (scsi_mode != np->scsi_mode) {
6137 ncr_name(np), np->scsi_mode, scsi_mode);
6139 np->scsi_mode = scsi_mode;
6146 np->settle_time = jiffies + HZ;
6147 ncr_init (np, 0, bootverbose ? "scsi mode change" : NULL, HS_RESET);
6163 static int ncr_int_par (struct ncb *np)
6173 ncr_name(np), hsts, dbc, sstat1);
6213 jmp = NCB_SCRIPTH_PHYS (np, par_err_data_in);
6215 jmp = NCB_SCRIPTH_PHYS (np, par_err_other);
6220 np->msgout[0] = msg;
6225 ncr_start_reset(np);
6243 static void ncr_int_ma (struct ncb *np)
6274 ctest5 = (np->rv_ctest5 & DFS) ? INB (nc_ctest5) : 0;
6319 cp = np->header.cp;
6323 cp = np->ccb;
6334 if (dsp > np->p_script &&
6335 dsp <= np->p_script + sizeof(struct script)) {
6336 vdsp = (u32 *)((char*)np->script0 + (dsp-np->p_script-8));
6339 else if (dsp > np->p_scripth &&
6340 dsp <= np->p_scripth + sizeof(struct scripth)) {
6341 vdsp = (u32 *)((char*)np->scripth0 + (dsp-np->p_scripth-8));
6361 cp, np->header.cp,
6375 ncr_name (np), (u_long) np->header.cp);
6414 ** cp != np->header.cp means that the header of the CCB
6419 if (cp != np->header.cp) {
6422 ncr_name (np), (u_long) cp, (u_long) np->header.cp);
6470 OUTL_DSP (NCB_SCRIPT_PHYS (np, dispatch));
6506 nxtdsp = NCB_SCRIPT_PHYS (np, dispatch);
6510 nxtdsp = NCB_SCRIPT_PHYS (np, dispatch);
6514 np->scripth->nxtdsp_go_on[0] = cpu_to_scr(dsp + 8);
6515 if (dsp == NCB_SCRIPT_PHYS (np, send_ident)) {
6517 nxtdsp = NCB_SCRIPTH_PHYS (np, clratn_go_on);
6519 else if (dsp == NCB_SCRIPTH_PHYS (np, send_wdtr) ||
6520 dsp == NCB_SCRIPTH_PHYS (np, send_sdtr)) {
6521 nxtdsp = NCB_SCRIPTH_PHYS (np, nego_bad_phase);
6526 nxtdsp = NCB_SCRIPT_PHYS (np, clrack);
6537 ncr_start_reset(np);
6541 static void ncr_sir_to_redo(struct ncb *np, int num, struct ccb *cp)
6544 struct tcb *tp = &np->target[cmd->device->id];
6568 cpu_to_scr(NCB_SCRIPTH_PHYS (np, skip));
6590 ncr_setup_tags (np, cmd->device);
6602 ncr_put_start_queue(np, cp);
6605 OUTL_DSP (NCB_SCRIPT_PHYS (np, reselect));
6649 startp = cpu_to_scr(NCB_SCRIPTH_PHYS (np, sdata_in));
6662 cpu_to_scr(NCB_SCRIPT_PHYS (np, select));
6669 cpu_to_scr(NCB_SCRIPTH_PHYS (np, select_no_atn));
6671 ncr_put_start_queue(np, cp);
6673 OUTL_DSP (NCB_SCRIPT_PHYS (np, start));
6692 void ncr_int_sir (struct ncb *np)
6700 struct tcb *tp = &np->target[target];
6711 ncr_wakeup_done(np);
6713 OUTL(nc_dsp, NCB_SCRIPT_PHYS (np, done_end) + 8);
6715 OUTL(nc_dsp, NCB_SCRIPT_PHYS (np, start));
6735 ncr_name (np), target, num);
6740 ncr_name (np), target, num);
6743 cp = np->header.cp;
6746 ncr_sir_to_redo(np, num, cp);
6752 cp = np->ccb;
6757 BUG_ON(cp != np->header.cp);
6759 if (!cp || cp != np->header.cp)
6861 ncr_setsync (np, cp, 0, 0xe0);
6866 ncr_setwide (np, cp, 0, 0);
6870 np->msgin [0] = NOP;
6871 np->msgout[0] = NOP;
6877 ncr_print_msg(cp, "sync msgin", np->msgin);
6881 per = np->msgin[3];
6882 ofs = np->msgin[4];
6897 if (per < np->minsync)
6898 {chg = 1; per = np->minsync;}
6910 ncr_getsync(np, per, &fak, &scntl3);
6938 ncr_setsync(np, cp, 0, 0xe0);
6939 OUTL_DSP(NCB_SCRIPT_PHYS (np, msg_bad));
6944 ncr_setsync(np, cp, scntl3, (fak<<5)|ofs);
6945 OUTL_DSP(NCB_SCRIPT_PHYS (np, clrack));
6951 ncr_setwide(np, cp, 0, 0);
6963 ncr_setsync(np, cp, scntl3, (fak<<5)|ofs);
6965 spi_populate_sync_msg(np->msgout, per, ofs);
6969 ncr_print_msg(cp, "sync msgout", np->msgout);
6973 OUTL_DSP (NCB_SCRIPT_PHYS (np, msg_bad));
6976 np->msgin [0] = NOP;
6985 ncr_print_msg(cp, "wide msgin", np->msgin);
6993 wide = np->msgin[3];
7026 ncr_setwide(np, cp, 0, 1);
7027 OUTL_DSP (NCB_SCRIPT_PHYS (np, msg_bad));
7031 ncr_setwide(np, cp, wide, 1);
7032 OUTL_DSP (NCB_SCRIPT_PHYS (np, clrack));
7039 ncr_setsync(np, cp, 0, 0xe0);
7050 ncr_setwide(np, cp, wide, 1);
7051 spi_populate_width_msg(np->msgout, wide);
7053 np->msgin [0] = NOP;
7058 ncr_print_msg(cp, "wide msgout", np->msgin);
7078 (unsigned)scr_to_cpu(np->lastmsg), np->msgout[0]);
7089 ncr_print_msg(cp, "MESSAGE_REJECT sent for", np->msgin);
7124 (unsigned) scr_to_cpu(np->header.savep),
7125 (unsigned) scr_to_cpu(np->header.goalp));
7143 static struct ccb *ncr_get_ccb(struct ncb *np, struct scsi_cmnd *cmd)
7147 struct tcb *tp = &np->target[tn];
7167 ncr_alloc_ccb(np, tn, ln);
7201 cp = np->ccb;
7254 static void ncr_free_ccb (struct ncb *np, struct ccb *cp)
7256 struct tcb *tp = &np->target[cp->target];
7276 cpu_to_scr(NCB_SCRIPTH_PHYS(np, bad_i_t_l_q));
7279 cpu_to_scr(NCB_SCRIPTH_PHYS(np, bad_i_t_l));
7288 if (cp != np->ccb)
7298 --np->queuedccbs;
7303 if (cp == np->ccb)
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)
7318 ncrcmd copy_4 = np->features & FE_PFEN ? SCR_COPY(4) : SCR_COPY_F(4);
7345 cp->start.schedule.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, idle));
7346 cp->restart.schedule.l_paddr = cpu_to_scr(NCB_SCRIPTH_PHYS (np, abort));
7355 static void ncr_alloc_ccb(struct ncb *np, u_char tn, u_char ln)
7357 struct tcb *tp = &np->target[tn];
7372 np->actccbs++;
7374 ncr_init_ccb(np, cp);
7380 cp->link_ccb = np->ccb->link_ccb;
7381 np->ccb->link_ccb = cp;
7404 static void ncr_init_tcb (struct ncb *np, u_char tn)
7406 struct tcb *tp = &np->target[tn];
7407 ncrcmd copy_1 = np->features & FE_PFEN ? SCR_COPY(1) : SCR_COPY_F(1);
7417 tp->jump_tcb.l_paddr = np->jump_tcb[th].l_paddr;
7448 tp->call_lun.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, resel_lun));
7459 cpu_to_scr(NCB_SCRIPTH_PHYS (np, bad_identify));
7465 np->jump_tcb[th].l_paddr = cpu_to_scr(vtobus (&tp->jump_tcb));
7491 static struct lcb *ncr_alloc_lcb (struct ncb *np, u_char tn, u_char ln)
7493 struct tcb *tp = &np->target[tn];
7495 ncrcmd copy_4 = np->features & FE_PFEN ? SCR_COPY(4) : SCR_COPY_F(4);
7517 ncr_init_tcb(np, tn);
7555 lp->jump_tag.l_paddr = cpu_to_scr(NCB_SCRIPT_PHYS (np, resel_notag));
7581 static struct lcb *ncr_setup_lcb (struct ncb *np, struct scsi_device *sdev)
7584 struct tcb *tp = &np->target[tn];
7588 if (!lp && !(lp = ncr_alloc_lcb(np, tn, ln)))
7605 cpu_to_scr(NCB_SCRIPTH_PHYS (np, bad_i_t_l_q));
7610 ncr_setup_tags (np, sdev);
7647 static int ncr_scatter(struct ncb *np, struct ccb *cp, struct scsi_cmnd *cmd)
7654 use_sg = map_scsi_sg_data(np, cmd);
7660 unmap_scsi_data(np, cmd);
7670 ncr_build_sge(np, &data[segment], baddr, len);
7690 static int __init ncr_regtest (struct ncb* np)
7713 static int __init ncr_snooptest (struct ncb* np)
7717 if (np->reg) {
7718 err |= ncr_regtest (np);
7724 pc = NCB_SCRIPTH_PHYS (np, snooptest);
7730 np->ncr_cache = cpu_to_scr(host_wr);
7749 host_rd = scr_to_cpu(np->ncr_cache);
7755 ncr_chip_reset(np, 100);
7766 if (pc != NCB_SCRIPTH_PHYS (np, snoopend)+8) {
7769 (u_long) NCB_SCRIPTH_PHYS (np, snooptest), (u_long) pc,
7770 (u_long) NCB_SCRIPTH_PHYS (np, snoopend) +8);
7820 static void ncr_selectclock(struct ncb *np, u_char scntl3)
7822 if (np->multiplier < 2) {
7828 printk ("%s: enabling clock multiplier\n", ncr_name(np));
7831 if (np->multiplier > 2) { /* Poll bit 5 of stest4 for quadrupler */
7836 printk("%s: the chip cannot lock the frequency\n", ncr_name(np));
7849 static unsigned __init ncrgetfreq (struct ncb *np, int gen)
7890 printk ("%s: Delay (GEN=%d): %u msec\n", ncr_name(np), gen, ms);
7900 static void __init ncr_getclock (struct ncb *np, int mult)
7906 np->multiplier = 1;
7914 printk ("%s: clock multiplier found\n", ncr_name(np));
7915 np->multiplier = mult;
7923 if (np->multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) {
7926 ncr_chip_reset(np, 5);
7928 (void) ncrgetfreq (np, 11); /* throw away first result */
7929 f1 = ncrgetfreq (np, 11);
7930 f2 = ncrgetfreq (np, 11);
7933 printk ("%s: NCR clock is %uKHz, %uKHz\n", ncr_name(np), f1, f2);
7943 printk ("%s: clock multiplier assumed\n", ncr_name(np));
7944 np->multiplier = mult;
7951 f1 /= np->multiplier;
7957 f1 *= np->multiplier;
7958 np->clock_khz = f1;
7966 struct ncb *np = ((struct host_data *) host->hostdata)->ncb;
7967 struct tcb *tp = &np->target[device->id];
7976 struct ncb *np = ((struct host_data *) host->hostdata)->ncb;
7977 struct tcb *tp = &np->target[device->id];
7981 ncr_setup_lcb(np, device);
7989 numtags = device_queue_depth(np->unit, device->id, device->lun);
8018 ncr_setup_tags (np, device);
8022 np->unit, device->id, device->lun, depth_to_use);
8033 struct ncb *np = ((struct host_data *) cmd->device->host->hostdata)->ncb;
8046 spin_lock_irqsave(&np->smp_lock, flags);
8048 if ((sts = ncr_queue_command(np, cmd)) != DID_OK) {
8059 spin_unlock_irqrestore(&np->smp_lock, flags);
8062 unmap_scsi_data(np, cmd);
8077 struct ncb *np = host_data->ncb;
8086 spin_lock_irqsave(&np->smp_lock, flags);
8087 ncr_exception(np);
8088 done_list = np->done_list;
8089 np->done_list = NULL;
8090 spin_unlock_irqrestore(&np->smp_lock, flags);
8101 struct ncb *np = (struct ncb *) npref;
8105 spin_lock_irqsave(&np->smp_lock, flags);
8106 ncr_timeout(np);
8107 done_list = np->done_list;
8108 np->done_list = NULL;
8109 spin_unlock_irqrestore(&np->smp_lock, flags);
8117 struct ncb *np = ((struct host_data *) cmd->device->host->hostdata)->ncb;
8129 spin_lock_irqsave(&np->smp_lock, flags);
8130 sts = ncr_reset_bus(np, cmd, 1);
8132 done_list = np->done_list;
8133 np->done_list = NULL;
8134 spin_unlock_irqrestore(&np->smp_lock, flags);
8144 struct ncb *np = ((struct host_data *) cmd->device->host->hostdata)->ncb;
8151 NCR_LOCK_NCB(np, flags);
8153 sts = ncr_abort_command(np, cmd);
8155 done_list = np->done_list;
8156 np->done_list = NULL;
8157 NCR_UNLOCK_NCB(np, flags);
8181 static void insert_into_waiting_list(struct ncb *np, struct scsi_cmnd *cmd)
8186 printk("%s: cmd %lx inserted into waiting list\n", ncr_name(np), (u_long) cmd);
8189 if (!(wcmd = np->waiting_list)) np->waiting_list = cmd;
8197 static struct scsi_cmnd *retrieve_from_waiting_list(int to_remove, struct ncb *np, struct scsi_cmnd *cmd)
8199 struct scsi_cmnd **pcmd = &np->waiting_list;
8208 printk("%s: cmd %lx retrieved from waiting list\n", ncr_name(np), (u_long) cmd);
8217 static void process_waiting_list(struct ncb *np, int sts)
8221 waiting_list = np->waiting_list;
8222 np->waiting_list = NULL;
8225 if (waiting_list) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np), (u_long) waiting_list, sts);
8232 printk("%s: cmd %lx trying to requeue\n", ncr_name(np), (u_long) wcmd);
8234 sts = ncr_queue_command(np, wcmd);
8238 printk("%s: cmd %lx done forced sts=%d\n", ncr_name(np), (u_long) wcmd, sts);
8241 ncr_queue_done_cmd(np, wcmd);
8301 struct ncb *np = NULL;
8332 np = __m_calloc_dma(device->dev, sizeof(struct ncb), "NCB");
8333 if (!np)
8335 spin_lock_init(&np->smp_lock);
8336 np->dev = device->dev;
8337 np->p_ncb = vtobus(np);
8338 host_data->ncb = np;
8340 np->ccb = m_calloc_dma(sizeof(struct ccb), "CCB");
8341 if (!np->ccb)
8345 np->unit = unit;
8346 np->verbose = driver_setup.verbose;
8347 sprintf(np->inst_name, "ncr53c720-%d", np->unit);
8348 np->revision_id = device->chip.revision_id;
8349 np->features = device->chip.features;
8350 np->clock_divn = device->chip.nr_divisor;
8351 np->maxoffs = device->chip.offset_max;
8352 np->maxburst = device->chip.burst_max;
8353 np->myaddr = device->host_id;
8356 np->script0 = m_calloc_dma(sizeof(struct script), "SCRIPT");
8357 if (!np->script0)
8359 np->scripth0 = m_calloc_dma(sizeof(struct scripth), "SCRIPTH");
8360 if (!np->scripth0)
8363 init_timer(&np->timer);
8364 np->timer.data = (unsigned long) np;
8365 np->timer.function = ncr53c8xx_timeout;
8369 np->paddr = device->slot.base;
8370 np->paddr2 = (np->features & FE_RAM) ? device->slot.base_2 : 0;
8373 np->vaddr = device->slot.base_v;
8375 np->vaddr = ioremap(device->slot.base_c, 128);
8377 if (!np->vaddr) {
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);
8391 np->reg = (struct ncr_reg __iomem *)np->vaddr;
8394 ncr_prepare_setting(np);
8396 if (np->paddr2 && sizeof(struct script) > 4096) {
8397 np->paddr2 = 0;
8399 ncr_name(np));
8403 instance->this_id = np->myaddr;
8404 instance->max_id = np->maxwide ? 16 : 8;
8406 instance->base = (unsigned long) np->reg;
8420 np->scripth = np->scripth0;
8421 np->p_scripth = vtobus(np->scripth);
8422 np->p_script = (np->paddr2) ? np->paddr2 : vtobus(np->script0);
8424 ncr_script_copy_and_bind(np, (ncrcmd *) &script0,
8425 (ncrcmd *) np->script0, sizeof(struct script));
8426 ncr_script_copy_and_bind(np, (ncrcmd *) &scripth0,
8427 (ncrcmd *) np->scripth0, sizeof(struct scripth));
8428 np->ccb->p_ccb = vtobus (np->ccb);
8432 if (np->features & FE_LED0) {
8433 np->script0->idle[0] =
8435 np->script0->reselected[0] =
8437 np->script0->start[0] =
8447 np->jump_tcb[i].l_cmd =
8449 np->jump_tcb[i].l_paddr =
8450 cpu_to_scr(NCB_SCRIPTH_PHYS (np, bad_target));
8453 ncr_chip_reset(np, 100);
8457 if (ncr_snooptest(np)) {
8463 np->irq = device->slot.irq;
8466 ncr_init_ccb(np, np->ccb);
8474 spin_lock_irqsave(&np->smp_lock, flags);
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);
8481 ncr_exception(np);
8483 np->disc = 1;
8491 ncr_name(np), driver_setup.settle_delay);
8496 np->lasttime=0;
8497 ncr_timeout (np);
8501 np->order = SIMPLE_QUEUE_TAG;
8504 spin_unlock_irqrestore(&np->smp_lock, flags);
8511 printk(KERN_INFO "%s: detaching...\n", ncr_name(np));
8512 if (!np)
8514 if (np->scripth0)
8515 m_free_dma(np->scripth0, sizeof(struct scripth), "SCRIPTH");
8516 if (np->script0)
8517 m_free_dma(np->script0, sizeof(struct script), "SCRIPT");
8518 if (np->ccb)
8519 m_free_dma(np->ccb, sizeof(struct ccb), "CCB");
8520 m_free_dma(np, sizeof(struct ncb), "NCB");
8544 struct ncb *np = ((struct host_data *)shost->hostdata)->ncb;
8545 struct tcb *tp = &np->target[starget->id];
8547 if (period > np->maxsync)
8548 period = np->maxsync;
8549 else if (period < np->minsync)
8550 period = np->minsync;
8554 ncr_negotiate(np, tp);
8560 struct ncb *np = ((struct host_data *)shost->hostdata)->ncb;
8561 struct tcb *tp = &np->target[starget->id];
8563 if (offset > np->maxoffs)
8564 offset = np->maxoffs;
8570 ncr_negotiate(np, tp);
8576 struct ncb *np = ((struct host_data *)shost->hostdata)->ncb;
8577 struct tcb *tp = &np->target[starget->id];
8579 if (width > np->maxwide)
8580 width = np->maxwide;
8586 ncr_negotiate(np, tp);
8591 struct ncb *np = ((struct host_data *)shost->hostdata)->ncb;
8594 switch (np->scsi_mode) {