Lines Matching refs:np

54 static void sym_int_ma (struct sym_hcb *np);
56 static struct sym_ccb *sym_alloc_ccb(struct sym_hcb *np);
57 static struct sym_ccb *sym_ccb_from_dsa(struct sym_hcb *np, u32 dsa);
58 static void sym_alloc_lcb_tags (struct sym_hcb *np, u_char tn, u_char ln);
59 static void sym_complete_error (struct sym_hcb *np, struct sym_ccb *cp);
60 static void sym_complete_ok (struct sym_hcb *np, struct sym_ccb *cp);
61 static int sym_compute_residual(struct sym_hcb *np, struct sym_ccb *cp);
81 static void sym_print_nego_msg(struct sym_hcb *np, int target, char *label, u_char *msg)
83 struct sym_tcb *tp = &np->target[target];
133 static void sym_chip_reset (struct sym_hcb *np)
135 OUTB(np, nc_istat, SRST);
136 INB(np, nc_mbox1);
138 OUTB(np, nc_istat, 0);
139 INB(np, nc_mbox1);
152 static void sym_soft_reset (struct sym_hcb *np)
157 if (!(np->features & FE_ISTAT1) || !(INB(np, nc_istat1) & SCRUN))
160 OUTB(np, nc_istat, CABRT);
162 istat = INB(np, nc_istat);
164 INW(np, nc_sist);
167 if (INB(np, nc_dstat) & ABRT)
172 OUTB(np, nc_istat, 0);
175 "ISTAT=0x%02x.\n", sym_name(np), istat);
177 sym_chip_reset(np);
185 static void sym_start_reset(struct sym_hcb *np)
187 sym_reset_scsi_bus(np, 1);
190 int sym_reset_scsi_bus(struct sym_hcb *np, int enab_int)
195 sym_soft_reset(np); /* Soft reset the chip */
197 OUTW(np, nc_sien, RST);
202 OUTB(np, nc_stest3, TE);
203 OUTB(np, nc_dcntl, (np->rv_dcntl & IRQM));
204 OUTB(np, nc_scntl1, CRST);
205 INB(np, nc_mbox1);
216 term = INB(np, nc_sstat0);
218 term |= ((INB(np, nc_sstat2) & 0x01) << 26) | /* sdp1 */
219 ((INW(np, nc_sbdl) & 0xff) << 9) | /* d7-0 */
220 ((INW(np, nc_sbdl) & 0xff00) << 10) | /* d15-8 */
221 INB(np, nc_sbcl); /* req ack bsy sel atn msg cd io */
223 if (!np->maxwide)
228 sym_name(np));
231 sym_name(np),
232 (np->features & FE_WIDE) ? "dp1,d15-8," : "",
238 OUTB(np, nc_scntl1, 0);
245 static void sym_selectclock(struct sym_hcb *np, u_char scntl3)
250 if (np->multiplier <= 1) {
251 OUTB(np, nc_scntl3, scntl3);
256 printf ("%s: enabling clock multiplier\n", sym_name(np));
258 OUTB(np, nc_stest1, DBLEN); /* Enable clock multiplier */
263 if (np->features & FE_LCKFRQ) {
265 while (!(INB(np, nc_stest4) & LCKFRQ) && --i > 0)
269 sym_name(np));
271 INB(np, nc_mbox1);
274 OUTB(np, nc_stest3, HSC); /* Halt the scsi clock */
275 OUTB(np, nc_scntl3, scntl3);
276 OUTB(np, nc_stest1, (DBLEN|DBLSEL));/* Select clock multiplier */
277 OUTB(np, nc_stest3, 0x00); /* Restart scsi clock */
302 static unsigned getfreq (struct sym_hcb *np, int gen)
322 OUTW(np, nc_sien, 0); /* mask all scsi interrupts */
323 INW(np, nc_sist); /* clear pending scsi interrupt */
324 OUTB(np, nc_dien, 0); /* mask all dma interrupts */
325 INW(np, nc_sist); /* another one, just to be sure :) */
331 if (np->features & FE_C10) {
332 OUTW(np, nc_sien, GEN);
333 OUTB(np, nc_istat1, SIRQD);
335 OUTB(np, nc_scntl3, 4); /* set pre-scaler to divide by 3 */
336 OUTB(np, nc_stime1, 0); /* disable general purpose timer */
337 OUTB(np, nc_stime1, gen); /* set to nominal delay of 1<<gen * 125us */
338 while (!(INW(np, nc_sist) & GEN) && ms++ < 100000)
340 OUTB(np, nc_stime1, 0); /* disable general purpose timer */
344 if (np->features & FE_C10) {
345 OUTW(np, nc_sien, 0);
346 OUTB(np, nc_istat1, 0);
353 OUTB(np, nc_scntl3, 0);
364 if (np->features & FE_C10)
369 sym_name(np), gen, ms/4, f);
374 static unsigned sym_getfreq (struct sym_hcb *np)
379 getfreq (np, gen); /* throw away first result */
380 f1 = getfreq (np, gen);
381 f2 = getfreq (np, gen);
389 static void sym_getclock (struct sym_hcb *np, int mult)
391 unsigned char scntl3 = np->sv_scntl3;
392 unsigned char stest1 = np->sv_stest1;
395 np->multiplier = 1;
402 printf ("%s: clock multiplier found\n", sym_name(np));
403 np->multiplier = mult;
411 if (np->multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) {
412 OUTB(np, nc_stest1, 0); /* make sure doubler is OFF */
413 f1 = sym_getfreq (np);
416 printf ("%s: chip clock is %uKHz\n", sym_name(np), f1);
425 sym_name(np));
426 np->multiplier = mult;
433 f1 /= np->multiplier;
439 f1 *= np->multiplier;
440 np->clock_khz = f1;
446 static int sym_getpciclock (struct sym_hcb *np)
455 if (np->features & FE_66MHZ) {
459 OUTB(np, nc_stest1, SCLK); /* Use the PCI clock as SCSI clock */
460 f = sym_getfreq(np);
461 OUTB(np, nc_stest1, 0);
463 np->pciclk_khz = f;
482 sym_getsync(struct sym_hcb *np, u_char dt, u_char sfac, u_char *divp, u_char *fakp)
484 u32 clk = np->clock_khz; /* SCSI clock frequency in kHz */
485 int div = np->clock_divn; /* Number of divisors supported */
513 if ((np->features & (FE_C10|FE_U3EN)) == FE_C10) {
526 if (div == np->clock_divn) { /* Are we too fast ? */
550 /* ret = ((2+fak)*div_10M[div])/np->clock_khz; */
553 /* ret = ((4+fak)*div_10M[div])/np->clock_khz; */
602 static inline void sym_init_burst(struct sym_hcb *np, u_char bc)
604 np->rv_ctest4 &= ~0x80;
605 np->rv_dmode &= ~(0x3 << 6);
606 np->rv_ctest5 &= ~0x4;
609 np->rv_ctest4 |= 0x80;
613 np->rv_dmode |= ((bc & 0x3) << 6);
614 np->rv_ctest5 |= (bc & 0x4);
627 static void sym_save_initial_setting (struct sym_hcb *np)
629 np->sv_scntl0 = INB(np, nc_scntl0) & 0x0a;
630 np->sv_scntl3 = INB(np, nc_scntl3) & 0x07;
631 np->sv_dmode = INB(np, nc_dmode) & 0xce;
632 np->sv_dcntl = INB(np, nc_dcntl) & 0xa8;
633 np->sv_ctest3 = INB(np, nc_ctest3) & 0x01;
634 np->sv_ctest4 = INB(np, nc_ctest4) & 0x80;
635 np->sv_gpcntl = INB(np, nc_gpcntl);
636 np->sv_stest1 = INB(np, nc_stest1);
637 np->sv_stest2 = INB(np, nc_stest2) & 0x20;
638 np->sv_stest4 = INB(np, nc_stest4);
639 if (np->features & FE_C10) { /* Always large DMA fifo + ultra3 */
640 np->sv_scntl4 = INB(np, nc_scntl4);
641 np->sv_ctest5 = INB(np, nc_ctest5) & 0x04;
644 np->sv_ctest5 = INB(np, nc_ctest5) & 0x24;
654 static void sym_set_bus_mode(struct sym_hcb *np, struct sym_nvram *nvram)
656 if (np->scsi_mode)
659 np->scsi_mode = SMODE_SE;
660 if (np->features & (FE_ULTRA2|FE_ULTRA3))
661 np->scsi_mode = (np->sv_stest4 & SMODE);
662 else if (np->features & FE_DIFF) {
664 if (np->sv_scntl3) {
665 if (np->sv_stest2 & 0x20)
666 np->scsi_mode = SMODE_HVD;
668 if (!(INB(np, nc_gpreg) & 0x08))
669 np->scsi_mode = SMODE_HVD;
672 np->scsi_mode = SMODE_HVD;
674 if (np->scsi_mode == SMODE_HVD)
675 np->rv_stest2 |= 0x20;
682 static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, struct sym_nvram *nvram)
690 np->maxwide = (np->features & FE_WIDE) ? 1 : 0;
695 if (np->features & (FE_ULTRA3 | FE_ULTRA2))
696 np->clock_khz = 160000;
697 else if (np->features & FE_ULTRA)
698 np->clock_khz = 80000;
700 np->clock_khz = 40000;
705 if (np->features & FE_QUAD)
706 np->multiplier = 4;
707 else if (np->features & FE_DBLR)
708 np->multiplier = 2;
710 np->multiplier = 1;
716 if (np->features & FE_VARCLK)
717 sym_getclock(np, np->multiplier);
722 i = np->clock_divn - 1;
724 if (10ul * SYM_CONF_MIN_ASYNC * np->clock_khz > div_10M[i]) {
729 np->rv_scntl3 = i+1;
735 if (np->features & FE_C10)
736 np->rv_scntl3 = 0;
742 period = (4 * div_10M[0] + np->clock_khz - 1) / np->clock_khz;
744 if (period <= 250) np->minsync = 10;
745 else if (period <= 303) np->minsync = 11;
746 else if (period <= 500) np->minsync = 12;
747 else np->minsync = (period + 40 - 1) / 40;
752 if (np->minsync < 25 &&
753 !(np->features & (FE_ULTRA|FE_ULTRA2|FE_ULTRA3)))
754 np->minsync = 25;
755 else if (np->minsync < 12 &&
756 !(np->features & (FE_ULTRA2|FE_ULTRA3)))
757 np->minsync = 12;
762 period = (11 * div_10M[np->clock_divn - 1]) / (4 * np->clock_khz);
763 np->maxsync = period > 2540 ? 254 : period / 10;
768 if ((np->features & (FE_C10|FE_ULTRA3)) == (FE_C10|FE_ULTRA3)) {
769 if (np->clock_khz == 160000) {
770 np->minsync_dt = 9;
771 np->maxsync_dt = 50;
772 np->maxoffs_dt = nvram->type ? 62 : 31;
779 if (np->features & FE_DAC) {
780 if (!use_dac(np))
781 np->rv_ccntl1 |= (DDAC);
783 np->rv_ccntl1 |= (XTIMOD | EXTIBMV);
785 np->rv_ccntl1 |= (0 | EXTIBMV);
791 if (np->features & FE_NOPM)
792 np->rv_ccntl0 |= (ENPMJ);
801 np->rv_ccntl0 |= DILS;
808 burst_max = burst_code(np->sv_dmode, np->sv_ctest4,
809 np->sv_ctest5);
812 if (burst_max > np->maxburst)
813 burst_max = np->maxburst;
827 np->features &= ~(FE_WRIE|FE_ERL|FE_ERMP);
835 if (np->features & FE_ERL)
836 np->rv_dmode |= ERL; /* Enable Read Line */
837 if (np->features & FE_BOF)
838 np->rv_dmode |= BOF; /* Burst Opcode Fetch */
839 if (np->features & FE_ERMP)
840 np->rv_dmode |= ERMP; /* Enable Read Multiple */
842 if ((np->features & FE_PFEN) && !np->ram_ba)
844 if (np->features & FE_PFEN)
846 np->rv_dcntl |= PFEN; /* Prefetch Enable */
847 if (np->features & FE_CLSE)
848 np->rv_dcntl |= CLSE; /* Cache Line Size Enable */
849 if (np->features & FE_WRIE)
850 np->rv_ctest3 |= WRIE; /* Write and Invalidate */
851 if (np->features & FE_DFS)
852 np->rv_ctest5 |= DFS; /* Dma Fifo Size */
857 np->rv_ctest4 |= MPEE; /* Master parity checking */
858 np->rv_scntl0 |= 0x0a; /* full arb., ena parity, par->ATN */
863 np->myaddr = 255;
864 np->scsi_mode = 0;
865 sym_nvram_setup_host(shost, np, nvram);
870 if (np->myaddr == 255) {
871 np->myaddr = INB(np, nc_scid) & 0x07;
872 if (!np->myaddr)
873 np->myaddr = SYM_SETUP_HOST_ID;
879 sym_init_burst(np, burst_max);
881 sym_set_bus_mode(np, nvram);
893 !(np->features & FE_LEDC) && !(np->sv_gpcntl & 0x01))
894 np->features |= FE_LED0;
901 np->rv_dcntl |= IRQM;
904 np->rv_dcntl |= (np->sv_dcntl & IRQM);
915 struct sym_tcb *tp = &np->target[i];
919 tp->usr_width = np->maxwide;
931 printf("%s: %s, ID %d, Fast-%d, %s, %s\n", sym_name(np),
932 sym_nvram_type(nvram), np->myaddr,
933 (np->features & FE_ULTRA3) ? 80 :
934 (np->features & FE_ULTRA2) ? 40 :
935 (np->features & FE_ULTRA) ? 20 : 10,
936 sym_scsi_bus_mode(np->scsi_mode),
937 (np->rv_scntl0 & 0xa) ? "parity checking" : "NO parity");
943 sym_name(np),
944 np->rv_dcntl & IRQM ? "totem pole" : "open drain",
945 np->ram_ba ? ", using on-chip SRAM" : "");
946 printf("%s: using %s firmware.\n", sym_name(np), np->fw_name);
947 if (np->features & FE_NOPM)
949 sym_name(np));
957 sym_name(np), np->sv_scntl3, np->sv_dmode, np->sv_dcntl,
958 np->sv_ctest3, np->sv_ctest4, np->sv_ctest5);
962 sym_name(np), np->rv_scntl3, np->rv_dmode, np->rv_dcntl,
963 np->rv_ctest3, np->rv_ctest4, np->rv_ctest5);
975 static int sym_regtest(struct sym_hcb *np)
984 OUTL(np, nc_dstat, data);
985 data = INL(np, nc_dstat);
998 static inline int sym_regtest(struct sym_hcb *np)
1004 static int sym_snooptest(struct sym_hcb *np)
1009 err = sym_regtest(np);
1017 OUTB(np, nc_ctest4, (np->rv_ctest4 & MPEE));
1021 pc = SCRIPTZ_BA(np, snooptest);
1027 np->scratch = cpu_to_scr(host_wr);
1028 OUTL(np, nc_temp, sym_wr);
1032 OUTL(np, nc_dsa, np->hcb_ba);
1033 OUTL_DSP(np, pc);
1038 if (INB(np, nc_istat) & (INTF|SIP|DIP))
1047 dstat = INB(np, nc_dstat);
1049 if ((dstat & MDPE) && (np->rv_ctest4 & MPEE)) {
1052 sym_name(np));
1053 np->rv_ctest4 &= ~MPEE;
1064 pc = INL(np, nc_dsp);
1068 host_rd = scr_to_cpu(np->scratch);
1069 sym_rd = INL(np, nc_scratcha);
1070 sym_bk = INL(np, nc_temp);
1074 if (pc != SCRIPTZ_BA(np, snoopend)+8) {
1077 (u_long) SCRIPTZ_BA(np, snooptest), (u_long) pc,
1078 (u_long) SCRIPTZ_BA(np, snoopend) +8);
1132 struct sym_hcb *np = sym_get_hcb(shost);
1140 dsp = INL(np, nc_dsp);
1142 if (dsp > np->scripta_ba &&
1143 dsp <= np->scripta_ba + np->scripta_sz) {
1144 script_ofs = dsp - np->scripta_ba;
1145 script_size = np->scripta_sz;
1146 script_base = (u_char *) np->scripta0;
1149 else if (np->scriptb_ba < dsp &&
1150 dsp <= np->scriptb_ba + np->scriptb_sz) {
1151 script_ofs = dsp - np->scriptb_ba;
1152 script_size = np->scriptb_sz;
1153 script_base = (u_char *) np->scriptb0;
1163 sym_name(np), (unsigned)INB(np, nc_sdid)&0x0f, dstat, sist,
1164 (unsigned)INB(np, nc_socl), (unsigned)INB(np, nc_sbcl),
1165 (unsigned)INB(np, nc_sbdl), (unsigned)INB(np, nc_sxfer),
1166 (unsigned)INB(np, nc_scntl3),
1167 (np->features & FE_C10) ? (unsigned)INB(np, nc_scntl4) : 0,
1168 script_name, script_ofs, (unsigned)INL(np, nc_dbc));
1172 printf ("%s: script cmd = %08x\n", sym_name(np),
1176 printf("%s: regdump:", sym_name(np));
1178 printf(" %02x", (unsigned)INB_OFF(np, i));
1190 struct sym_hcb *np = sym_get_hcb(shost);
1194 sist = INW(np, nc_sist);
1195 dstat = INB(np, nc_dstat);
1315 int sym_lookup_dmap(struct sym_hcb *np, u32 h, int s)
1319 if (!use_dac(np))
1324 if (h == np->dmap_bah[i])
1328 if (!np->dmap_bah[s])
1332 if (!np->dmap_bah[s])
1339 np->dmap_bah[s] = h;
1340 np->dmap_dirty = 1;
1348 static void sym_update_dmap_regs(struct sym_hcb *np)
1352 if (!np->dmap_dirty)
1356 OUTL_OFF(np, o, np->dmap_bah[i]);
1359 np->dmap_dirty = 0;
1364 static void sym_check_goals(struct sym_hcb *np, struct scsi_target *starget,
1389 if ((np->scsi_mode != SMODE_LVD) || !(np->features & FE_U3EN))
1395 if (goal->offset > np->maxoffs_dt)
1396 goal->offset = np->maxoffs_dt;
1397 if (goal->period < np->minsync_dt)
1398 goal->period = np->minsync_dt;
1399 if (goal->period > np->maxsync_dt)
1400 goal->period = np->maxsync_dt;
1403 if (goal->offset > np->maxoffs)
1404 goal->offset = np->maxoffs;
1405 if (goal->period < np->minsync)
1406 goal->period = np->minsync;
1407 if (goal->period > np->maxsync)
1408 goal->period = np->maxsync;
1419 static int sym_prepare_nego(struct sym_hcb *np, struct sym_ccb *cp, u_char *msgptr)
1421 struct sym_tcb *tp = &np->target[cp->target];
1427 sym_check_goals(np, starget, goal);
1467 sym_print_nego_msg(np, cp->target,
1480 void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp)
1493 if (np->last_cp && np->iarb_count < np->iarb_max) {
1494 np->last_cp->host_flags |= HF_HINT_IARB;
1495 ++np->iarb_count;
1498 np->iarb_count = 0;
1499 np->last_cp = cp;
1507 if (np->dmap_dirty)
1515 qidx = np->squeueput + 2;
1518 np->squeue [qidx] = cpu_to_scr(np->idletask_ba);
1520 np->squeue [np->squeueput] = cpu_to_scr(cp->ccb_ba);
1522 np->squeueput = qidx;
1526 np->squeueput);
1533 OUTB(np, nc_istat, SIGP|np->istat_sem);
1540 void sym_start_next_ccbs(struct sym_hcb *np, struct sym_lcb *lp, int maxn)
1568 cpu_to_scr(SCRIPTA_BA(np, resel_tag));
1577 cpu_to_scr(SCRIPTA_BA(np, resel_no_tag));
1582 sym_put_start_queue(np, cp);
1594 static int sym_wakeup_done (struct sym_hcb *np)
1601 i = np->dqueueget;
1605 dsa = scr_to_cpu(np->dqueue[i]);
1608 np->dqueue[i] = 0;
1612 cp = sym_ccb_from_dsa(np, dsa);
1615 sym_complete_ok (np, cp);
1620 sym_name(np), (u_int) dsa);
1622 np->dqueueget = i;
1641 static void sym_flush_comp_queue(struct sym_hcb *np, int cam_status)
1646 while ((qp = sym_remque_head(&np->comp_ccbq)) != NULL) {
1649 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
1658 struct sym_tcb *tp = &np->target[cp->target];
1675 sym_free_ccb(np, cp);
1676 sym_xpt_done(np, cmd);
1684 static void sym_flush_busy_queue (struct sym_hcb *np, int cam_status)
1690 sym_que_splice(&np->busy_ccbq, &np->comp_ccbq);
1691 sym_que_init(&np->busy_ccbq);
1692 sym_flush_comp_queue(np, cam_status);
1707 struct sym_hcb *np = sym_data->ncb;
1715 sym_soft_reset(np);
1717 OUTB(np, nc_stest3, TE|CSF);
1718 OUTONB(np, nc_ctest3, CLF);
1724 phys = np->squeue_ba;
1726 np->squeue[i] = cpu_to_scr(np->idletask_ba);
1727 np->squeue[i+1] = cpu_to_scr(phys + (i+2)*4);
1729 np->squeue[MAX_QUEUE*2-1] = cpu_to_scr(phys);
1734 np->squeueput = 0;
1739 phys = np->dqueue_ba;
1741 np->dqueue[i] = 0;
1742 np->dqueue[i+1] = cpu_to_scr(phys + (i+2)*4);
1744 np->dqueue[MAX_QUEUE*2-1] = cpu_to_scr(phys);
1749 np->dqueueget = 0;
1756 np->fw_patch(shost);
1761 sym_flush_busy_queue(np, DID_RESET);
1766 OUTB(np, nc_istat, 0x00); /* Remove Reset, abort */
1767 INB(np, nc_mbox1);
1770 OUTB(np, nc_scntl0, np->rv_scntl0 | 0xc0);
1772 OUTB(np, nc_scntl1, 0x00); /* odd parity, and remove CRST!! */
1774 sym_selectclock(np, np->rv_scntl3); /* Select SCSI clock */
1776 OUTB(np, nc_scid , RRE|np->myaddr); /* Adapter SCSI address */
1777 OUTW(np, nc_respid, 1ul<<np->myaddr); /* Id to respond to */
1778 OUTB(np, nc_istat , SIGP ); /* Signal Process */
1779 OUTB(np, nc_dmode , np->rv_dmode); /* Burst length, dma mode */
1780 OUTB(np, nc_ctest5, np->rv_ctest5); /* Large fifo + large burst */
1782 OUTB(np, nc_dcntl , NOCOM|np->rv_dcntl); /* Protect SFBR */
1783 OUTB(np, nc_ctest3, np->rv_ctest3); /* Write and invalidate */
1784 OUTB(np, nc_ctest4, np->rv_ctest4); /* Master parity checking */
1787 if (np->features & FE_C10)
1788 OUTB(np, nc_stest2, np->rv_stest2);
1790 OUTB(np, nc_stest2, EXT|np->rv_stest2);
1792 OUTB(np, nc_stest3, TE); /* TolerANT enable */
1793 OUTB(np, nc_stime0, 0x0c); /* HTH disabled STO 0.25 sec */
1799 OUTB(np, nc_aipcntl1, DISAIP);
1810 OUTB(np, nc_stest1, INB(np, nc_stest1) | 0x30);
1818 OUTB(np, nc_ctest0, (1<<5));
1820 np->rv_ccntl0 |= DPR;
1827 if (np->features & (FE_DAC|FE_NOPM)) {
1828 OUTB(np, nc_ccntl0, np->rv_ccntl0);
1829 OUTB(np, nc_ccntl1, np->rv_ccntl1);
1837 if (use_dac(np)) {
1838 np->dmap_bah[0] = 0; /* ??? */
1839 OUTL(np, nc_scrx[0], np->dmap_bah[0]);
1840 OUTL(np, nc_drs, np->dmap_bah[0]);
1848 if (np->features & FE_NOPM) {
1849 OUTL(np, nc_pmjad1, SCRIPTB_BA(np, pm_handle));
1850 OUTL(np, nc_pmjad2, SCRIPTB_BA(np, pm_handle));
1857 if (np->features & FE_LED0)
1858 OUTB(np, nc_gpcntl, INB(np, nc_gpcntl) & ~0x01);
1859 else if (np->features & FE_LEDC)
1860 OUTB(np, nc_gpcntl, (INB(np, nc_gpcntl) & ~0x41) | 0x20);
1865 OUTW(np, nc_sien , STO|HTH|MA|SGE|UDC|RST|PAR);
1866 OUTB(np, nc_dien , MDPE|BF|SSI|SIR|IID);
1873 if (np->features & (FE_ULTRA2|FE_ULTRA3)) {
1874 OUTONW(np, nc_sien, SBMC);
1876 INB(np, nc_mbox1);
1878 INW(np, nc_sist);
1880 np->scsi_mode = INB(np, nc_stest4) & SMODE;
1890 struct sym_tcb *tp = &np->target[i];
1894 tp->head.wval = np->rv_scntl3;
1914 phys = SCRIPTA_BA(np, init);
1915 if (np->ram_ba) {
1917 printf("%s: Downloading SCSI SCRIPTS.\n", sym_name(np));
1918 memcpy_toio(np->s.ramaddr, np->scripta0, np->scripta_sz);
1919 if (np->features & FE_RAM8K) {
1920 memcpy_toio(np->s.ramaddr + 4096, np->scriptb0, np->scriptb_sz);
1921 phys = scr_to_cpu(np->scr_ram_seg);
1922 OUTL(np, nc_mmws, phys);
1923 OUTL(np, nc_mmrs, phys);
1924 OUTL(np, nc_sfs, phys);
1925 phys = SCRIPTB_BA(np, start64);
1929 np->istat_sem = 0;
1931 OUTL(np, nc_dsa, np->hcb_ba);
1932 OUTL_DSP(np, phys);
1938 sym_xpt_async_bus_reset(np);
1944 static void sym_settrans(struct sym_hcb *np, int target, u_char opts, u_char ofs,
1949 struct sym_tcb *tp = &np->target[target];
1951 assert(target == (INB(np, nc_sdid) & 0x0f));
1959 sval, wval, uval, np->rv_scntl3);
1964 if (!(np->features & FE_C10))
1974 if (!(np->features & FE_C10))
1993 if (np->features & FE_C10) {
1996 assert(np->features & FE_U3EN);
2019 if (per < 50 && !(np->features & FE_C10))
2020 OUTOFFB(np, nc_stest2, EXT);
2025 OUTB(np, nc_sxfer, tp->head.sval);
2026 OUTB(np, nc_scntl3, tp->head.wval);
2028 if (np->features & FE_C10) {
2029 OUTB(np, nc_scntl4, tp->head.uval);
2035 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
2042 if (np->features & FE_C10) {
2075 static void sym_setwide(struct sym_hcb *np, int target, u_char wide)
2077 struct sym_tcb *tp = &np->target[target];
2080 sym_settrans(np, target, 0, 0, 0, wide, 0, 0);
2104 sym_setsync(struct sym_hcb *np, int target,
2107 struct sym_tcb *tp = &np->target[target];
2111 sym_settrans(np, target, 0, ofs, per, wide, div, fak);
2137 sym_setpprot(struct sym_hcb *np, int target, u_char opts, u_char ofs,
2140 struct sym_tcb *tp = &np->target[target];
2143 sym_settrans(np, target, opts, ofs, per, wide, div, fak);
2186 static void sym_recover_scsi_int (struct sym_hcb *np, u_char hsts)
2188 u32 dsp = INL(np, nc_dsp);
2189 u32 dsa = INL(np, nc_dsa);
2190 struct sym_ccb *cp = sym_ccb_from_dsa(np, dsa);
2197 if ((!(dsp > SCRIPTA_BA(np, getjob_begin) &&
2198 dsp < SCRIPTA_BA(np, getjob_end) + 1)) &&
2199 (!(dsp > SCRIPTA_BA(np, ungetjob) &&
2200 dsp < SCRIPTA_BA(np, reselect) + 1)) &&
2201 (!(dsp > SCRIPTB_BA(np, sel_for_abort) &&
2202 dsp < SCRIPTB_BA(np, sel_for_abort_1) + 1)) &&
2203 (!(dsp > SCRIPTA_BA(np, done) &&
2204 dsp < SCRIPTA_BA(np, done_end) + 1))) {
2205 OUTB(np, nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */
2206 OUTB(np, nc_stest3, TE|CSF); /* clear scsi fifo */
2215 OUTL_DSP(np, SCRIPTA_BA(np, complete_error));
2221 OUTL(np, nc_dsa, 0xffffff);
2222 OUTL_DSP(np, SCRIPTA_BA(np, start));
2231 sym_start_reset(np);
2237 static void sym_int_sto (struct sym_hcb *np)
2239 u32 dsp = INL(np, nc_dsp);
2243 if (dsp == SCRIPTA_BA(np, wf_sel_done) + 8)
2244 sym_recover_scsi_int(np, HS_SEL_TIMEOUT);
2246 sym_start_reset(np);
2252 static void sym_int_udc (struct sym_hcb *np)
2254 printf ("%s: unexpected disconnect\n", sym_name(np));
2255 sym_recover_scsi_int(np, HS_UNEXPECTED);
2270 struct sym_hcb *np = sym_get_hcb(shost);
2271 u_char scsi_mode = INB(np, nc_stest4) & SMODE;
2276 printf("%s: SCSI BUS mode change from %s to %s.\n", sym_name(np),
2277 sym_scsi_bus_mode(np->scsi_mode), sym_scsi_bus_mode(scsi_mode));
2310 static void sym_int_par (struct sym_hcb *np, u_short sist)
2312 u_char hsts = INB(np, HS_PRT);
2313 u32 dsp = INL(np, nc_dsp);
2314 u32 dbc = INL(np, nc_dbc);
2315 u32 dsa = INL(np, nc_dsa);
2316 u_char sbcl = INB(np, nc_sbcl);
2319 struct sym_ccb *cp = sym_ccb_from_dsa(np, dsa);
2323 sym_name(np), hsts, dbc, sbcl);
2328 if (!(INB(np, nc_scntl1) & ISCON)) {
2329 sym_recover_scsi_int(np, HS_UNEXPECTED);
2350 OUTONB(np, HF_PRT, HF_EXT_ERR);
2356 np->msgout[0] = (phase == 7) ? M_PARITY : M_ID_ERROR;
2367 if (dsp == SCRIPTB_BA(np, pm_handle))
2368 OUTL_DSP(np, dsp);
2371 sym_int_ma (np);
2374 sym_set_script_dp (np, cp, dsp);
2375 OUTL_DSP(np, SCRIPTA_BA(np, dispatch));
2382 OUTL_DSP(np, SCRIPTA_BA(np, clrack));
2385 OUTL_DSP(np, SCRIPTA_BA(np, dispatch));
2389 sym_start_reset(np);
2399 static void sym_int_ma (struct sym_hcb *np)
2416 dsp = INL(np, nc_dsp);
2417 dbc = INL(np, nc_dbc);
2418 dsa = INL(np, nc_dsa);
2427 cp = sym_ccb_from_dsa(np, dsa);
2438 if (np->features & FE_DFBC)
2439 delta = INW(np, nc_dfbc);
2446 dfifo = INL(np, nc_dfifo);
2466 ss0 = INB(np, nc_sstat0);
2468 if (!(np->features & FE_C10))
2471 ss2 = INB(np, nc_sstat2);
2473 if (!(np->features & FE_C10))
2480 OUTB(np, nc_ctest3, np->rv_ctest3 | CLF); /* dma fifo */
2481 OUTB(np, nc_stest3, TE|CSF); /* scsi fifo */
2488 printf ("P%x%x RL=%d D=%d ", cmd&7, INB(np, nc_sbcl)&7,
2497 if (dsp > np->scripta_ba &&
2498 dsp <= np->scripta_ba + np->scripta_sz) {
2499 vdsp = (u32 *)((char*)np->scripta0 + (dsp-np->scripta_ba-8));
2502 else if (dsp > np->scriptb_ba &&
2503 dsp <= np->scriptb_ba + np->scriptb_sz) {
2504 vdsp = (u32 *)((char*)np->scriptb0 + (dsp-np->scriptb_ba-8));
2518 sym_name (np));
2524 sym_name (np));
2569 cmd&7, INB(np, nc_sbcl)&7, (unsigned)olen,
2582 hflags0 = INB(np, HF_PRT);
2597 newcmd = SCRIPTA_BA(np, pm0_data);
2601 newcmd = SCRIPTA_BA(np, pm1_data);
2606 OUTB(np, HF_PRT, hflags);
2621 nxtdsp = SCRIPTA_BA(np, dispatch);
2623 (INB(np, nc_scntl2) & WSR)) {
2649 nxtdsp = SCRIPTB_BA(np, wsr_ma_helper);
2663 sym_set_script_dp (np, cp, newcmd);
2664 OUTL_DSP(np, nxtdsp);
2700 nxtdsp = SCRIPTA_BA(np, dispatch);
2704 nxtdsp = SCRIPTA_BA(np, dispatch);
2714 if (dsp == SCRIPTA_BA(np, send_ident)) {
2717 np->msgout[0] = IDENTIFY(0, cp->lun);
2718 nxtdsp = SCRIPTB_BA(np, ident_break_atn);
2721 nxtdsp = SCRIPTB_BA(np, ident_break);
2723 else if (dsp == SCRIPTB_BA(np, send_wdtr) ||
2724 dsp == SCRIPTB_BA(np, send_sdtr) ||
2725 dsp == SCRIPTB_BA(np, send_ppr)) {
2726 nxtdsp = SCRIPTB_BA(np, nego_bad_phase);
2727 if (dsp == SCRIPTB_BA(np, send_ppr)) {
2735 nxtdsp = SCRIPTA_BA(np, clrack);
2741 OUTL_DSP(np, nxtdsp);
2746 sym_start_reset(np);
2815 struct sym_hcb *np = sym_data->ncb;
2832 istat = INB(np, nc_istat);
2834 OUTB(np, nc_istat, (istat & SIGP) | INTF | np->istat_sem);
2835 istat |= INB(np, nc_istat); /* DUMMY READ */
2837 sym_wakeup_done(np);
2845 OUTB(np, nc_istat, CABRT);
2863 sist |= INW(np, nc_sist);
2865 dstat |= INB(np, nc_dstat);
2866 istatc = INB(np, nc_istat);
2879 (int)INB(np, nc_scr0),
2881 (unsigned)INL(np, nc_dsp),
2882 (unsigned)INL(np, nc_dbc));
2906 if (sist & PAR) sym_int_par (np, sist);
2907 else if (sist & MA) sym_int_ma (np);
2908 else if (dstat & SIR) sym_int_sir(np);
2926 printf("%s: SCSI BUS reset detected.\n", sym_name(np));
2931 OUTB(np, nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */
2932 OUTB(np, nc_stest3, TE|CSF); /* clear scsi fifo */
2937 else if (sist & STO) sym_int_sto (np);
2938 else if (sist & UDC) sym_int_udc (np);
2954 sym_start_reset(np);
2965 sym_name(np), istat, dstat, sist);
2978 sym_dequeue_from_squeue(struct sym_hcb *np, int i, int target, int lun, int task)
2993 while (i != np->squeueput) {
2994 cp = sym_ccb_from_dsa(np, scr_to_cpu(np->squeue[i]));
3009 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq);
3013 np->squeue[j] = np->squeue[i];
3019 np->squeue[j] = np->squeue[i];
3020 np->squeueput = j; /* Update our current start queue pointer */
3043 static void sym_sir_bad_scsi_status(struct sym_hcb *np, int num, struct sym_ccb *cp)
3054 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
3061 if (np->last_cp)
3062 np->last_cp = 0;
3076 sym_complete_error (np, cp);
3084 sym_complete_error (np, cp);
3092 sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1);
3093 OUTL_DSP(np, SCRIPTA_BA(np, start));
3101 cp->sv_resid = sym_compute_residual(np, cp);
3122 msglen += sym_prepare_nego(np, cp, &cp->scsi_smsg2[msglen]);
3155 startp = SCRIPTB_BA(np, sdata_in);
3169 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA(np, select));
3174 sym_put_start_queue(np, cp);
3179 sym_flush_comp_queue(np, 0);
3198 int sym_clear_tasks(struct sym_hcb *np, int cam_status, int target, int lun, int task)
3208 sym_que_splice(&np->busy_ccbq, &qtmp);
3209 sym_que_init(&np->busy_ccbq);
3225 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
3228 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq);
3281 static void sym_sir_task_recovery(struct sym_hcb *np, int num)
3301 tp = &np->target[i];
3324 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
3340 tp = &np->target[target];
3341 np->abrt_sel.sel_id = target;
3342 np->abrt_sel.sel_scntl3 = tp->head.wval;
3343 np->abrt_sel.sel_sxfer = tp->head.sval;
3344 OUTL(np, nc_dsa, np->hcb_ba);
3345 OUTL_DSP(np, SCRIPTB_BA(np, sel_for_abort));
3356 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
3369 if (cp == np->last_cp) {
3383 np->istat_sem = 0;
3384 OUTB(np, nc_istat, SIGP);
3392 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
3393 i = sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1);
3402 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq);
3415 sym_flush_comp_queue(np, 0);
3422 target = INB(np, nc_sdid) & 0xf;
3423 tp = &np->target[target];
3425 np->abrt_tbl.addr = cpu_to_scr(vtobus(np->abrt_msg));
3433 np->abrt_msg[0] = M_RESET;
3434 np->abrt_tbl.size = 1;
3460 np->abrt_msg[0] = IDENTIFY(0, lun);
3461 np->abrt_msg[1] = M_ABORT;
3462 np->abrt_tbl.size = 2;
3472 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
3492 np->abrt_msg[0] = M_ABORT;
3493 np->abrt_tbl.size = 1;
3501 np->abrt_msg[0] = IDENTIFY(0, cp->lun);
3510 np->abrt_msg[1] = M_ABORT;
3511 np->abrt_tbl.size = 2;
3513 np->abrt_msg[1] = cp->scsi_smsg[1];
3514 np->abrt_msg[2] = cp->scsi_smsg[2];
3515 np->abrt_msg[3] = M_ABORT_TAG;
3516 np->abrt_tbl.size = 4;
3533 target = INB(np, nc_sdid) & 0xf;
3534 tp = &np->target[target];
3540 if (np->abrt_msg[0] == M_ABORT)
3553 if (np->abrt_msg[0] == M_RESET) {
3555 tp->head.wval = np->rv_scntl3;
3574 lun = np->abrt_msg[0] & 0x3f;
3575 if (np->abrt_msg[1] == M_ABORT_TAG)
3576 task = np->abrt_msg[2];
3583 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
3584 sym_dequeue_from_squeue(np, i, target, lun, -1);
3585 sym_clear_tasks(np, DID_ABORT, target, lun, task);
3586 sym_flush_comp_queue(np, 0);
3591 if (np->abrt_msg[0] == M_RESET)
3602 sym_printl_hex(np->abrt_msg, np->abrt_tbl.size);
3603 np->abrt_tbl.size = cpu_to_scr(np->abrt_tbl.size);
3639 static int sym_evaluate_dp(struct sym_hcb *np, struct sym_ccb *cp, u32 scr, int *ofs)
3652 if (dp_scr == SCRIPTA_BA(np, pm0_data))
3654 else if (dp_scr == SCRIPTA_BA(np, pm1_data))
3757 static void sym_modify_dp(struct sym_hcb *np, struct sym_tcb *tp, struct sym_ccb *cp, int ofs)
3760 u32 dp_scr = sym_get_script_dp (np, cp);
3777 dp_sg = sym_evaluate_dp(np, cp, dp_scr, &dp_ofs);
3800 hflags = INB(np, HF_PRT);
3807 dp_scr = SCRIPTA_BA(np, pm0_data);
3811 dp_scr = SCRIPTA_BA(np, pm1_data);
3816 OUTB(np, HF_PRT, hflags);
3832 sym_set_script_dp (np, cp, dp_scr);
3833 OUTL_DSP(np, SCRIPTA_BA(np, clrack));
3837 OUTL_DSP(np, SCRIPTB_BA(np, msg_bad));
3856 int sym_compute_residual(struct sym_hcb *np, struct sym_ccb *cp)
3889 sym_evaluate_dp(np, cp, scr_to_cpu(cp->phys.head.lastp),
3958 sym_sync_nego_check(struct sym_hcb *np, int req, struct sym_ccb *cp)
3964 sym_print_nego_msg(np, target, "sync msgin", np->msgin);
3971 per = np->msgin[3];
3972 ofs = np->msgin[4];
3978 if (ofs > np->maxoffs)
3979 {chg = 1; ofs = np->maxoffs;}
3983 if (per < np->minsync)
3984 {chg = 1; per = np->minsync;}
3991 if (ofs && sym_getsync(np, 0, per, &div, &fak) < 0)
4010 sym_setsync (np, target, ofs, per, div, fak);
4021 spi_populate_sync_msg(np->msgout, per, ofs);
4024 sym_print_nego_msg(np, target, "sync msgout", np->msgout);
4027 np->msgin [0] = M_NOOP;
4032 sym_setsync (np, target, 0, 0, 0, 0);
4036 static void sym_sync_nego(struct sym_hcb *np, struct sym_tcb *tp, struct sym_ccb *cp)
4044 if (INB(np, HS_PRT) == HS_NEGOTIATE) {
4045 OUTB(np, HS_PRT, HS_BUSY);
4054 result = sym_sync_nego_check(np, req, cp);
4059 OUTL_DSP(np, SCRIPTB_BA(np, sdtr_resp));
4062 OUTL_DSP(np, SCRIPTA_BA(np, clrack));
4066 OUTL_DSP(np, SCRIPTB_BA(np, msg_bad));
4073 sym_ppr_nego_check(struct sym_hcb *np, int req, int target)
4075 struct sym_tcb *tp = &np->target[target];
4079 unsigned char per = np->msgin[3];
4080 unsigned char ofs = np->msgin[5];
4081 unsigned char wide = np->msgin[6];
4082 unsigned char opts = np->msgin[7] & PPR_OPT_MASK;
4085 sym_print_nego_msg(np, target, "ppr msgin", np->msgin);
4091 if (wide > np->maxwide) {
4093 wide = np->maxwide;
4095 if (!wide || !(np->features & FE_U3EN))
4098 if (opts != (np->msgin[7] & PPR_OPT_MASK))
4104 unsigned char maxoffs = dt ? np->maxoffs_dt : np->maxoffs;
4112 unsigned char minsync = dt ? np->minsync_dt : np->minsync;
4123 if (ofs && sym_getsync(np, dt, per, &div, &fak) < 0)
4136 sym_setpprot(np, target, opts, ofs, per, wide, div, fak);
4147 spi_populate_ppr_msg(np->msgout, per, ofs, wide, opts);
4150 sym_print_nego_msg(np, target, "ppr msgout", np->msgout);
4153 np->msgin [0] = M_NOOP;
4158 sym_setpprot (np, target, 0, 0, 0, 0, 0, 0);
4173 static void sym_ppr_nego(struct sym_hcb *np, struct sym_tcb *tp, struct sym_ccb *cp)
4181 if (INB(np, HS_PRT) == HS_NEGOTIATE) {
4182 OUTB(np, HS_PRT, HS_BUSY);
4191 result = sym_ppr_nego_check(np, req, cp->target);
4196 OUTL_DSP(np, SCRIPTB_BA(np, ppr_resp));
4199 OUTL_DSP(np, SCRIPTA_BA(np, clrack));
4203 OUTL_DSP(np, SCRIPTB_BA(np, msg_bad));
4210 sym_wide_nego_check(struct sym_hcb *np, int req, struct sym_ccb *cp)
4216 sym_print_nego_msg(np, target, "wide msgin", np->msgin);
4223 wide = np->msgin[3];
4228 if (wide > np->maxwide) {
4230 wide = np->maxwide;
4248 sym_setwide (np, target, wide);
4259 spi_populate_width_msg(np->msgout, wide);
4261 np->msgin [0] = M_NOOP;
4264 sym_print_nego_msg(np, target, "wide msgout", np->msgout);
4273 static void sym_wide_nego(struct sym_hcb *np, struct sym_tcb *tp, struct sym_ccb *cp)
4281 if (INB(np, HS_PRT) == HS_NEGOTIATE) {
4282 OUTB(np, HS_PRT, HS_BUSY);
4291 result = sym_wide_nego_check(np, req, cp);
4296 OUTL_DSP(np, SCRIPTB_BA(np, wdtr_resp));
4304 spi_populate_sync_msg(np->msgout, tp->tgoal.period,
4308 sym_print_nego_msg(np, cp->target,
4309 "sync msgout", np->msgout);
4313 OUTB(np, HS_PRT, HS_NEGOTIATE);
4314 OUTL_DSP(np, SCRIPTB_BA(np, sdtr_resp));
4317 OUTL_DSP(np, SCRIPTA_BA(np, clrack));
4323 OUTL_DSP(np, SCRIPTB_BA(np, msg_bad));
4337 static void sym_nego_default(struct sym_hcb *np, struct sym_tcb *tp, struct sym_ccb *cp)
4342 sym_setpprot (np, cp->target, 0, 0, 0, 0, 0, 0);
4344 if (tp->tgoal.period < np->minsync)
4345 tp->tgoal.period = np->minsync;
4346 if (tp->tgoal.offset > np->maxoffs)
4347 tp->tgoal.offset = np->maxoffs;
4353 sym_setsync (np, cp->target, 0, 0, 0, 0);
4356 sym_setwide (np, cp->target, 0);
4359 np->msgin [0] = M_NOOP;
4360 np->msgout[0] = M_NOOP;
4368 static void sym_nego_rejected(struct sym_hcb *np, struct sym_tcb *tp, struct sym_ccb *cp)
4370 sym_nego_default(np, tp, cp);
4371 OUTB(np, HS_PRT, HS_BUSY);
4377 static void sym_int_sir(struct sym_hcb *np)
4379 u_char num = INB(np, nc_dsps);
4380 u32 dsa = INL(np, nc_dsa);
4381 struct sym_ccb *cp = sym_ccb_from_dsa(np, dsa);
4382 u_char target = INB(np, nc_sdid) & 0x0f;
4383 struct sym_tcb *tp = &np->target[target];
4395 sym_update_dmap_regs(np);
4403 sym_complete_error(np, cp);
4412 sym_sir_task_recovery(np, num);
4442 np->msgout[0] = M_RESET;
4449 np->msgout[0] = M_ABORT;
4455 np->msgout[0] = M_ABORT_TAG;
4462 np->lastmsg = np->msgout[0];
4463 np->msgout[0] = M_NOOP;
4465 "message %x sent on bad reselection\n", np->lastmsg);
4472 np->lastmsg = np->msgout[0];
4473 np->msgout[0] = M_NOOP;
4475 if (np->lastmsg == M_PARITY || np->lastmsg == M_ID_ERROR) {
4479 OUTOFFB(np, HF_PRT, HF_EXT_ERR);
4491 sym_sir_bad_scsi_status(np, num, cp);
4498 sym_print_msg(cp, "M_REJECT to send for ", np->msgin);
4499 np->msgout[0] = M_REJECT;
4509 OUTONB(np, HF_PRT, HF_EXT_ERR);
4520 OUTONB(np, HF_PRT, HF_EXT_ERR);
4532 OUTONB(np, HF_PRT, HF_EXT_ERR);
4534 cp->extra_bytes += INL(np, nc_scratcha);
4542 OUTONB(np, HF_PRT, HF_EXT_ERR);
4552 switch (np->msgin [0]) {
4559 switch (np->msgin [2]) {
4563 np->msgin);
4564 tmp = (np->msgin[3]<<24) + (np->msgin[4]<<16) +
4565 (np->msgin[5]<<8) + (np->msgin[6]);
4566 sym_modify_dp(np, tp, cp, tmp);
4569 sym_sync_nego(np, tp, cp);
4572 sym_ppr_nego(np, tp, cp);
4575 sym_wide_nego(np, tp, cp);
4590 sym_print_msg(cp, "1 or 2 byte ", np->msgin);
4592 OUTL_DSP(np, SCRIPTA_BA(np, clrack));
4594 sym_modify_dp(np, tp, cp, -1);
4597 if (INB(np, HS_PRT) == HS_NEGOTIATE)
4598 sym_nego_rejected(np, tp, cp);
4602 scr_to_cpu(np->lastmsg), np->msgout[0]);
4615 sym_print_msg(cp, "WEIRD message received", np->msgin);
4616 OUTL_DSP(np, SCRIPTB_BA(np, msg_weird));
4624 OUTB(np, HS_PRT, HS_BUSY);
4630 sym_nego_default(np, tp, cp);
4638 OUTL_DSP(np, SCRIPTB_BA(np, msg_bad));
4641 OUTL_DSP(np, SCRIPTA_BA(np, clrack));
4650 struct sym_ccb *sym_get_ccb (struct sym_hcb *np, struct scsi_cmnd *cmd, u_char tag_order)
4654 struct sym_tcb *tp = &np->target[tn];
4663 if (sym_que_empty(&np->free_ccbq))
4664 sym_alloc_ccb(np);
4665 qp = sym_remque_head(&np->free_ccbq);
4686 sym_alloc_lcb_tags(np, tn, ln);
4704 cpu_to_scr(SCRIPTA_BA(np, resel_tag));
4738 cpu_to_scr(SCRIPTA_BA(np, resel_no_tag));
4748 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
4770 sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
4777 void sym_free_ccb (struct sym_hcb *np, struct sym_ccb *cp)
4779 struct sym_tcb *tp = &np->target[cp->target];
4808 lp->itlq_tbl[cp->tag] = cpu_to_scr(np->bad_itlq_ba);
4815 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba);
4823 cpu_to_scr(SCRIPTB_BA(np, resel_bad_lun));
4839 if (cp == np->last_cp)
4840 np->last_cp = 0;
4849 sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
4854 sym_insque_tail(&cp->link2_ccbq, &np->dummy_ccbq);
4869 static struct sym_ccb *sym_alloc_ccb(struct sym_hcb *np)
4878 if (np->actccbs >= SYM_CONF_MAX_START)
4891 np->actccbs++;
4902 cp->link_ccbh = np->ccbh[hcode];
4903 np->ccbh[hcode] = cp;
4908 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA(np, idle));
4909 cp->phys.head.go.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
4914 cp->phys.smsg_ext.addr = cpu_to_scr(HCB_BA(np, msgin[2]));
4919 sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
4925 sym_insque_head(&cp->link2_ccbq, &np->dummy_ccbq);
4937 static struct sym_ccb *sym_ccb_from_dsa(struct sym_hcb *np, u32 dsa)
4943 cp = np->ccbh[hcode];
4957 static void sym_init_tcb (struct sym_hcb *np, u_char tn)
4973 struct sym_lcb *sym_alloc_lcb (struct sym_hcb *np, u_char tn, u_char ln)
4975 struct sym_tcb *tp = &np->target[tn];
4981 sym_init_tcb (np, tn);
4994 tp->luntbl[i] = cpu_to_scr(vtobus(&np->badlun_sa));
5028 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba);
5033 lp->head.resel_sa = cpu_to_scr(SCRIPTB_BA(np, resel_bad_lun));
5057 static void sym_alloc_lcb_tags (struct sym_hcb *np, u_char tn, u_char ln)
5059 struct sym_tcb *tp = &np->target[tn];
5081 lp->itlq_tbl[i] = cpu_to_scr(np->notask_ba);
5104 int sym_free_lcb(struct sym_hcb *np, u_char tn, u_char ln)
5106 struct sym_tcb *tp = &np->target[tn];
5117 tp->head.luntbl_sa = cpu_to_scr(vtobus(np->badluntbl));
5119 tp->luntbl[ln] = cpu_to_scr(vtobus(&np->badlun_sa));
5124 tp->head.lun0_sa = cpu_to_scr(vtobus(&np->badlun_sa));
5140 int sym_queue_scsiio(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
5157 tp = &np->target[cp->target];
5231 msglen += sym_prepare_nego(np, cp, msgptr + msglen);
5237 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA(np, select));
5238 cp->phys.head.go.restart = cpu_to_scr(SCRIPTA_BA(np, resel_dsa));
5275 return sym_setup_data_and_start(np, cmd, cp);
5281 int sym_reset_scsi_target(struct sym_hcb *np, int target)
5285 if (target == np->myaddr || (u_int)target >= SYM_CONF_MAX_TARGET)
5288 tp = &np->target[target];
5291 np->istat_sem = SEM;
5292 OUTB(np, nc_istat, SIGP|SEM);
5300 static int sym_abort_ccb(struct sym_hcb *np, struct sym_ccb *cp, int timed_out)
5313 sym_reset_scsi_bus(np, 1);
5325 np->istat_sem = SEM;
5326 OUTB(np, nc_istat, SIGP|SEM);
5330 int sym_abort_scsiio(struct sym_hcb *np, struct scsi_cmnd *cmd, int timed_out)
5339 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
5347 return sym_abort_ccb(np, cp, timed_out);
5360 void sym_complete_error(struct sym_hcb *np, struct sym_ccb *cp)
5385 tp = &np->target[cp->target];
5401 resid = sym_compute_residual(np, cp);
5416 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
5417 i = sym_dequeue_from_squeue(np, i, cp->target, sdev->lun, -1);
5422 OUTL_DSP(np, SCRIPTA_BA(np, start));
5457 sym_set_cam_result_error(np, cp, resid);
5466 sym_insque_head(&cp->link_ccbq, &np->comp_ccbq);
5472 sym_flush_comp_queue(np, 0);
5478 sym_start_next_ccbs(np, lp, 1);
5491 void sym_complete_ok (struct sym_hcb *np, struct sym_ccb *cp)
5513 tp = &np->target[cp->target];
5522 resid = sym_compute_residual(np, cp);
5562 sym_free_ccb (np, cp);
5569 sym_start_next_ccbs(np, lp, 2);
5574 sym_xpt_done(np, cmd);
5582 struct sym_hcb *np = sym_get_hcb(shost);
5588 np->scripta_sz = fw->a_size;
5589 np->scriptb_sz = fw->b_size;
5590 np->scriptz_sz = fw->z_size;
5591 np->fw_setup = fw->setup;
5592 np->fw_patch = fw->patch;
5593 np->fw_name = fw->name;
5599 sym_save_initial_setting (np);
5606 sym_chip_reset(np);
5612 sym_prepare_setting(shost, np, nvram);
5619 i = sym_getpciclock(np);
5620 if (i > 37000 && !(np->features & FE_66MHZ))
5622 sym_name(np), i);
5627 np->squeue = sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"SQUEUE");
5628 if (!np->squeue)
5630 np->squeue_ba = vtobus(np->squeue);
5635 np->dqueue = sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"DQUEUE");
5636 if (!np->dqueue)
5638 np->dqueue_ba = vtobus(np->dqueue);
5643 np->targtbl = sym_calloc_dma(256, "TARGTBL");
5644 if (!np->targtbl)
5646 np->targtbl_ba = vtobus(np->targtbl);
5651 np->scripta0 = sym_calloc_dma(np->scripta_sz, "SCRIPTA0");
5652 np->scriptb0 = sym_calloc_dma(np->scriptb_sz, "SCRIPTB0");
5653 np->scriptz0 = sym_calloc_dma(np->scriptz_sz, "SCRIPTZ0");
5654 if (!np->scripta0 || !np->scriptb0 || !np->scriptz0)
5660 np->ccbh = kcalloc(CCB_HASH_SIZE, sizeof(struct sym_ccb **), GFP_KERNEL);
5661 if (!np->ccbh)
5667 sym_que_init(&np->free_ccbq);
5668 sym_que_init(&np->busy_ccbq);
5669 sym_que_init(&np->comp_ccbq);
5676 sym_que_init(&np->dummy_ccbq);
5681 if (!sym_alloc_ccb(np))
5688 np->scripta_ba = vtobus(np->scripta0);
5689 np->scriptb_ba = vtobus(np->scriptb0);
5690 np->scriptz_ba = vtobus(np->scriptz0);
5692 if (np->ram_ba) {
5693 np->scripta_ba = np->ram_ba;
5694 if (np->features & FE_RAM8K) {
5695 np->scriptb_ba = np->scripta_ba + 4096;
5697 np->scr_ram_seg = cpu_to_scr(np->scripta_ba >> 32);
5705 memcpy(np->scripta0, fw->a_base, np->scripta_sz);
5706 memcpy(np->scriptb0, fw->b_base, np->scriptb_sz);
5707 memcpy(np->scriptz0, fw->z_base, np->scriptz_sz);
5713 np->fw_setup(np, fw);
5719 sym_fw_bind_script(np, (u32 *) np->scripta0, np->scripta_sz);
5720 sym_fw_bind_script(np, (u32 *) np->scriptb0, np->scriptb_sz);
5721 sym_fw_bind_script(np, (u32 *) np->scriptz0, np->scriptz_sz);
5731 np->iarb_max = SYM_SETUP_IARB_MAX;
5733 np->iarb_max = 4;
5740 np->idletask.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5741 np->idletask.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
5742 np->idletask_ba = vtobus(&np->idletask);
5744 np->notask.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5745 np->notask.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
5746 np->notask_ba = vtobus(&np->notask);
5748 np->bad_itl.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5749 np->bad_itl.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
5750 np->bad_itl_ba = vtobus(&np->bad_itl);
5752 np->bad_itlq.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5753 np->bad_itlq.restart = cpu_to_scr(SCRIPTB_BA(np,bad_i_t_l_q));
5754 np->bad_itlq_ba = vtobus(&np->bad_itlq);
5762 np->badluntbl = sym_calloc_dma(256, "BADLUNTBL");
5763 if (!np->badluntbl)
5766 np->badlun_sa = cpu_to_scr(SCRIPTB_BA(np, resel_bad_lun));
5768 np->badluntbl[i] = cpu_to_scr(vtobus(&np->badlun_sa));
5776 np->targtbl[i] = cpu_to_scr(vtobus(&np->target[i]));
5777 np->target[i].head.luntbl_sa =
5778 cpu_to_scr(vtobus(np->badluntbl));
5779 np->target[i].head.lun0_sa =
5780 cpu_to_scr(vtobus(&np->badlun_sa));
5786 if (sym_snooptest (np)) {
5787 printf("%s: CACHE INCORRECTLY CONFIGURED.\n", sym_name(np));
5803 void sym_hcb_free(struct sym_hcb *np)
5810 if (np->scriptz0)
5811 sym_mfree_dma(np->scriptz0, np->scriptz_sz, "SCRIPTZ0");
5812 if (np->scriptb0)
5813 sym_mfree_dma(np->scriptb0, np->scriptb_sz, "SCRIPTB0");
5814 if (np->scripta0)
5815 sym_mfree_dma(np->scripta0, np->scripta_sz, "SCRIPTA0");
5816 if (np->squeue)
5817 sym_mfree_dma(np->squeue, sizeof(u32)*(MAX_QUEUE*2), "SQUEUE");
5818 if (np->dqueue)
5819 sym_mfree_dma(np->dqueue, sizeof(u32)*(MAX_QUEUE*2), "DQUEUE");
5821 if (np->actccbs) {
5822 while ((qp = sym_remque_head(&np->free_ccbq)) != NULL) {
5827 kfree(np->ccbh);
5829 if (np->badluntbl)
5830 sym_mfree_dma(np->badluntbl, 256,"BADLUNTBL");
5833 tp = &np->target[target];
5840 if (np->targtbl)
5841 sym_mfree_dma(np->targtbl, 256, "TARGTBL");