Lines Matching +full:fixed +full:- +full:factor +full:- +full:clock

3  * of PCI-SCSI IO processors.
5 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
6 * Copyright (c) 2003-2005 Matthew Wilcox <matthew@wil.cx>
9 * Copyright (C) 1998-2000 Gerard Roudier
12 * a port of the FreeBSD ncr driver to Linux-1.2.13.
16 * Stefan Esser <se@mi.Uni-Koeln.de>
24 *-----------------------------------------------------------------------------
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
68 while (n-- > 0) in sym_printl_hex()
75 sym_print_addr(cp->cmd, "%s: ", label); in sym_print_msg()
83 struct sym_tcb *tp = &np->target[target]; in sym_print_nego_msg()
84 dev_info(&tp->starget->dev, "%s: ", label); in sym_print_nego_msg()
146 * Some 896 and 876 chip revisions may hang-up if we set
157 if (!(np->features & FE_ISTAT1) || !(INB(np, nc_istat1) & SCRUN)) in sym_soft_reset()
161 for (i = 100000 ; i ; --i) { in sym_soft_reset()
203 OUTB(np, nc_dcntl, (np->rv_dcntl & IRQM)); in sym_reset_scsi_bus()
219 ((INW(np, nc_sbdl) & 0xff) << 9) | /* d7-0 */ in sym_reset_scsi_bus()
220 ((INW(np, nc_sbdl) & 0xff00) << 10) | /* d15-8 */ in sym_reset_scsi_bus()
223 if (!np->maxwide) in sym_reset_scsi_bus()
229 printf("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = " in sym_reset_scsi_bus()
232 (np->features & FE_WIDE) ? "dp1,d15-8," : "", in sym_reset_scsi_bus()
243 * Select SCSI clock frequency
250 if (np->multiplier <= 1) { in sym_selectclock()
256 printf ("%s: enabling clock multiplier\n", sym_name(np)); in sym_selectclock()
258 OUTB(np, nc_stest1, DBLEN); /* Enable clock multiplier */ in sym_selectclock()
261 * Otherwise wait 50 micro-seconds (at least). in sym_selectclock()
263 if (np->features & FE_LCKFRQ) { in sym_selectclock()
265 while (!(INB(np, nc_stest4) & LCKFRQ) && --i > 0) in sym_selectclock()
274 OUTB(np, nc_stest3, HSC); /* Halt the scsi clock */ in sym_selectclock()
276 OUTB(np, nc_stest1, (DBLEN|DBLSEL));/* Select clock multiplier */ in sym_selectclock()
277 OUTB(np, nc_stest3, 0x00); /* Restart scsi clock */ in sym_selectclock()
282 * Determine the chip's clock frequency.
290 * Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
292 * do not have a clock doubler and so are provided with a
293 * 80 MHz clock. All other fast20 boards incorporate a doubler
294 * and so should be delivered with a 40 MHz clock.
296 * clock and provide a clock quadrupler (160 Mhz).
300 * calculate SCSI clock frequency (in KHz)
309 * to calculate SCSI clock frequency in getfreq()
327 * The C1010-33 core does not report GEN in SIST, in getfreq()
329 * I don't know yet if the C1010-66 behaves the same way. in getfreq()
331 if (np->features & FE_C10) { in getfreq()
335 OUTB(np, nc_scntl3, 4); /* set pre-scaler to divide by 3 */ in getfreq()
342 * Undo C1010-33 specific settings. in getfreq()
344 if (np->features & FE_C10) { in getfreq()
361 * The C1010-33 result is biased by a factor in getfreq()
364 if (np->features & FE_C10) in getfreq()
387 * Get/probe chip SCSI clock frequency
391 unsigned char scntl3 = np->sv_scntl3; in sym_getclock()
392 unsigned char stest1 = np->sv_stest1; in sym_getclock()
395 np->multiplier = 1; in sym_getclock()
398 * True with 875/895/896/895A with clock multiplier selected in sym_getclock()
402 printf ("%s: clock multiplier found\n", sym_name(np)); in sym_getclock()
403 np->multiplier = mult; in sym_getclock()
411 if (np->multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) { in sym_getclock()
416 printf ("%s: chip clock is %uKHz\n", sym_name(np), f1); in sym_getclock()
424 printf ("%s: clock multiplier assumed\n", in sym_getclock()
426 np->multiplier = mult; in sym_getclock()
433 f1 /= np->multiplier; in sym_getclock()
439 f1 *= np->multiplier; in sym_getclock()
440 np->clock_khz = f1; in sym_getclock()
444 * Get/probe PCI clock frequency
452 * PCI BUS clock frequency for C1010-66 chips.
455 if (np->features & FE_66MHZ) {
459 OUTB(np, nc_stest1, SCLK); /* Use the PCI clock as SCSI clock */
463 np->pciclk_khz = f;
469 * SYMBIOS chip clock divisor table.
478 * Get clock factor and sync divisor for a given
479 * synchronous factor period.
484 u32 clk = np->clock_khz; /* SCSI clock frequency in kHz */
485 int div = np->clock_divn; /* Number of divisors supported */
486 u32 fak; /* Sync factor in sxfer */
492 * Compute the synchronous period in tenths of nano-seconds
509 * to 5 Mega-transfers per second and may result in
510 * using higher clock divisors.
513 if ((np->features & (FE_C10|FE_U3EN)) == FE_C10) {
515 * Look for the lowest clock divisor that allows an
519 --div;
526 if (div == np->clock_divn) { /* Are we too fast ? */
527 ret = -1;
536 * Look for the greatest clock divisor that allows an
539 while (div-- > 0)
543 * Calculate the lowest clock factor that allows an output
549 fak = (kpc - 1) / (div_10M[div] << 1) + 1 - 2;
550 /* ret = ((2+fak)*div_10M[div])/np->clock_khz; */
552 fak = (kpc - 1) / div_10M[div] + 1 - 4;
553 /* ret = ((4+fak)*div_10M[div])/np->clock_khz; */
561 ret = -1;
604 np->rv_ctest4 &= ~0x80;
605 np->rv_dmode &= ~(0x3 << 6);
606 np->rv_ctest5 &= ~0x4;
609 np->rv_ctest4 |= 0x80;
612 --bc;
613 np->rv_dmode |= ((bc & 0x3) << 6);
614 np->rv_ctest5 |= (bc & 0x4);
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;
649 * - LVD capable chips (895/895A/896/1010) report the current BUS mode
651 * - For previous generation chips (825/825A/875), the user has to tell us
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;
667 } else if (nvram->type == SYM_SYMBIOS_NVRAM) {
669 np->scsi_mode = SMODE_HVD;
672 np->scsi_mode = SMODE_HVD;
674 if (np->scsi_mode == SMODE_HVD)
675 np->rv_stest2 |= 0x20;
685 struct pci_dev *pdev = sym_data->pdev;
690 np->maxwide = (np->features & FE_WIDE) ? 1 : 0;
693 * Guess the frequency of the chip's clock.
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;
703 * Get the clock multiplier factor.
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;
713 * Measure SCSI clock frequency for chips
716 if (np->features & FE_VARCLK)
717 sym_getclock(np, np->multiplier);
720 * Divisor to be used for async (timer pre-scaler).
722 i = np->clock_divn - 1;
723 while (--i >= 0) {
724 if (10ul * SYM_CONF_MIN_ASYNC * np->clock_khz > div_10M[i]) {
729 np->rv_scntl3 = i+1;
733 * So, we just throw away, the async. divisor.:-)
735 if (np->features & FE_C10)
736 np->rv_scntl3 = 0;
739 * Minimum synchronous period factor supported by the chip.
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;
750 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
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;
760 * Maximum synchronous period factor supported by the chip.
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) {
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);
795 * C1010-33 Errata: Part Number:609-039638 (rev. 1) is fixed.
799 if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
800 pdev->revision < 0x1)
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;
816 * DEL 352 - 53C810 Rev x11 - Part Number 609-0392140 - ITEM 2.
821 * LOAD/STORE instructions does not need this work-around.
823 if ((pdev->device == PCI_DEVICE_ID_NCR_53C810 &&
824 pdev->revision >= 0x10 && pdev->revision <= 0x11) ||
825 (pdev->device == PCI_DEVICE_ID_NCR_53C860 &&
826 pdev->revision <= 0x1))
827 np->features &= ~(FE_WRIE|FE_ERL|FE_ERMP);
831 * If we are using on-board RAM for scripts, prefetch (PFEN)
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;
870 if (np->myaddr == 255) {
871 np->myaddr = INB(np, nc_scid) & 0x07;
872 if (!np->myaddr)
873 np->myaddr = SYM_SETUP_HOST_ID;
890 (nvram->type == SYM_SYMBIOS_NVRAM ||
891 (nvram->type == SYM_TEKRAM_NVRAM &&
892 pdev->device == PCI_DEVICE_ID_NCR_53C895))) &&
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];
917 tp->usrflags |= (SYM_DISC_ENABLED | SYM_TAGS_ENABLED);
918 tp->usrtags = SYM_SETUP_MAX_TAG;
919 tp->usr_width = np->maxwide;
920 tp->usr_period = 9;
924 if (!tp->usrtags)
925 tp->usrflags &= ~SYM_TAGS_ENABLED;
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");
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)
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);
970 * Test the pci bus snoop logic :-(
991 printf ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
1017 OUTB(np, nc_ctest4, (np->rv_ctest4 & MPEE));
1027 np->scratch = cpu_to_scr(host_wr);
1032 OUTL(np, nc_dsa, np->hcb_ba);
1049 if ((dstat & MDPE) && (np->rv_ctest4 & MPEE)) {
1050 printf ("%s: PCI DATA PARITY ERROR DETECTED - "
1053 np->rv_ctest4 &= ~MPEE;
1068 host_rd = scr_to_cpu(np->scratch);
1106 * sym0 targ 0?: ERROR (ds:si) (so-si-sd) (sx/s3/s4) @ name (dsp:dbc).
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;
1162 printf ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x/%x) @ (%s %x:%08x).\n",
1167 (np->features & FE_C10) ? (unsigned)INB(np, nc_scntl4) : 0,
1263 {PCI_DEVICE_ID_LSI_53C1010_33, 0x00, "1010-33", 6, 31, 7, 8,
1268 {PCI_DEVICE_ID_LSI_53C1010_33, 0xff, "1010-33", 6, 31, 7, 8,
1273 {PCI_DEVICE_ID_LSI_53C1010_66, 0xff, "1010-66", 6, 31, 7, 8,
1299 if (device_id != chip->device_id)
1301 if (revision > chip->revision_id)
1323 for (i = SYM_DMAP_SIZE-1; i > 0; i--) {
1324 if (h == np->dmap_bah[i])
1328 if (!np->dmap_bah[s])
1330 /* Collision -> lookup free mappings */
1331 for (s = SYM_DMAP_SIZE-1; s > 0; s--) {
1332 if (!np->dmap_bah[s])
1337 return -1;
1339 np->dmap_bah[s] = h;
1340 np->dmap_dirty = 1;
1352 if (!np->dmap_dirty)
1356 OUTL_OFF(np, o, np->dmap_bah[i]);
1359 np->dmap_dirty = 0;
1368 goal->width = 0;
1371 goal->iu = 0;
1372 goal->dt = 0;
1373 goal->qas = 0;
1374 goal->offset = 0;
1380 goal->dt = 1;
1382 if (goal->offset == 0)
1383 goal->dt = 0;
1385 goal->dt = 0;
1389 if ((np->scsi_mode != SMODE_LVD) || !(np->features & FE_U3EN))
1390 goal->dt = 0;
1392 if (goal->dt) {
1394 goal->width = 1;
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;
1402 goal->iu = goal->qas = 0;
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;
1421 struct sym_tcb *tp = &np->target[cp->target];
1422 struct scsi_target *starget = tp->starget;
1423 struct sym_trans *goal = &tp->tgoal;
1433 if (goal->renego == NS_PPR || (goal->offset &&
1434 (goal->iu || goal->dt || goal->qas || (goal->period < 0xa)))) {
1436 } else if (goal->renego == NS_WIDE || goal->width) {
1438 } else if (goal->renego == NS_SYNC || goal->offset) {
1441 goal->check_nego = 0;
1447 msglen += spi_populate_sync_msg(msgptr + msglen, goal->period,
1448 goal->offset);
1451 msglen += spi_populate_width_msg(msgptr + msglen, goal->width);
1454 msglen += spi_populate_ppr_msg(msgptr + msglen, goal->period,
1455 goal->offset, goal->width,
1456 (goal->iu ? PPR_OPT_IU : 0) |
1457 (goal->dt ? PPR_OPT_DT : 0) |
1458 (goal->qas ? PPR_OPT_QAS : 0));
1462 cp->nego_status = nego;
1465 tp->nego_cp = cp; /* Keep track a nego will be performed */
1467 sym_print_nego_msg(np, cp->target,
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;
1505 * segment registers not being up-to-date.
1507 if (np->dmap_dirty)
1508 cp->host_xflags |= HX_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;
1525 scmd_printk(KERN_DEBUG, cp->cmd, "queuepos=%d\n",
1526 np->squeueput);
1533 OUTB(np, nc_istat, SIGP|np->istat_sem);
1538 * Start next ready-to-start CCBs.
1546 * Paranoia, as usual. :-)
1548 assert(!lp->started_tags || !lp->started_no_tag);
1555 while (maxn--) {
1556 qp = sym_remque_head(&lp->waiting_ccbq);
1560 if (cp->tag != NO_TAG) {
1561 if (lp->started_no_tag ||
1562 lp->started_tags >= lp->started_max) {
1563 sym_insque_head(qp, &lp->waiting_ccbq);
1566 lp->itlq_tbl[cp->tag] = cpu_to_scr(cp->ccb_ba);
1567 lp->head.resel_sa =
1569 ++lp->started_tags;
1571 if (lp->started_no_tag || lp->started_tags) {
1572 sym_insque_head(qp, &lp->waiting_ccbq);
1575 lp->head.itl_task_sa = cpu_to_scr(cp->ccb_ba);
1576 lp->head.resel_sa =
1578 ++lp->started_no_tag;
1580 cp->started = 1;
1581 sym_insque_tail(qp, &lp->started_ccbq);
1601 i = np->dqueueget;
1605 dsa = scr_to_cpu(np->dqueue[i]);
1608 np->dqueue[i] = 0;
1622 np->dqueueget = i;
1631 * - Not to be referenced either by devices or
1632 * SCRIPTS-related queues and datas.
1633 * - To have to be completed with an error condition
1646 while ((qp = sym_remque_head(&np->comp_ccbq)) != NULL) {
1649 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
1651 if (cp->host_status == HS_WAIT)
1653 cmd = cp->cmd;
1658 struct sym_tcb *tp = &np->target[cp->target];
1659 struct sym_lcb *lp = sym_lp(tp, cp->lun);
1661 sym_remque(&cp->link2_ccbq);
1662 sym_insque_tail(&cp->link2_ccbq,
1663 &lp->waiting_ccbq);
1664 if (cp->started) {
1665 if (cp->tag != NO_TAG)
1666 --lp->started_tags;
1668 --lp->started_no_tag;
1671 cp->started = 0;
1690 sym_que_splice(&np->busy_ccbq, &np->comp_ccbq);
1691 sym_que_init(&np->busy_ccbq);
1706 struct pci_dev *pdev = sym_data->pdev;
1707 struct sym_hcb *np = sym_data->ncb;
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);
1770 OUTB(np, nc_scntl0, np->rv_scntl0 | 0xc0);
1771 /* full arb., ena parity, par->ATN */
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 */
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);
1796 * For now, disable AIP generation on C1010-66.
1798 if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_66)
1808 if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
1809 pdev->revision < 1)
1813 * DEL 441 - 53C876 Rev 5 - Part Number 609-0392787/2788 - ITEM 2.
1815 * regardless revision id (kind of post-chip-design feature. ;-))
1817 if (pdev->device == PCI_DEVICE_ID_NCR_53C875)
1819 else if (pdev->device == PCI_DEVICE_ID_NCR_53C896)
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);
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) {
1857 if (np->features & FE_LED0)
1859 else if (np->features & FE_LEDC)
1873 if (np->features & (FE_ULTRA2|FE_ULTRA3)) {
1880 np->scsi_mode = INB(np, nc_stest4) & SMODE;
1890 struct sym_tcb *tp = &np->target[i];
1892 tp->to_reset = 0;
1893 tp->head.sval = 0;
1894 tp->head.wval = np->rv_scntl3;
1895 tp->head.uval = 0;
1896 if (tp->lun0p)
1897 tp->lun0p->to_clear = 0;
1898 if (tp->lunmp) {
1902 if (tp->lunmp[ln])
1903 tp->lunmp[ln]->to_clear = 0;
1908 * Download SCSI SCRIPTS to on-chip RAM if present,
1915 if (np->ram_ba) {
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);
1929 np->istat_sem = 0;
1931 OUTL(np, nc_dsa, np->hcb_ba);
1949 struct sym_tcb *tp = &np->target[target];
1953 sval = tp->head.sval;
1954 wval = tp->head.wval;
1955 uval = tp->head.uval;
1959 sval, wval, uval, np->rv_scntl3);
1964 if (!(np->features & FE_C10))
1970 * Set the sync divisor and extra clock factor.
1974 if (!(np->features & FE_C10))
1993 if (np->features & FE_C10) {
1996 assert(np->features & FE_U3EN);
2007 if (tp->head.sval == sval &&
2008 tp->head.wval == wval &&
2009 tp->head.uval == uval)
2011 tp->head.sval = sval;
2012 tp->head.wval = wval;
2013 tp->head.uval = uval;
2019 if (per < 50 && !(np->features & FE_C10))
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) {
2038 if (cp->target != target)
2040 cp->phys.select.sel_scntl3 = tp->head.wval;
2041 cp->phys.select.sel_sxfer = tp->head.sval;
2042 if (np->features & FE_C10) {
2043 cp->phys.select.sel_scntl4 = tp->head.uval;
2050 struct scsi_target *starget = tp->starget;
2052 if (tp->tprint.period != spi_period(starget) ||
2053 tp->tprint.offset != spi_offset(starget) ||
2054 tp->tprint.width != spi_width(starget) ||
2055 tp->tprint.iu != spi_iu(starget) ||
2056 tp->tprint.dt != spi_dt(starget) ||
2057 tp->tprint.qas != spi_qas(starget) ||
2058 !tp->tprint.check_nego) {
2059 tp->tprint.period = spi_period(starget);
2060 tp->tprint.offset = spi_offset(starget);
2061 tp->tprint.width = spi_width(starget);
2062 tp->tprint.iu = spi_iu(starget);
2063 tp->tprint.dt = spi_dt(starget);
2064 tp->tprint.qas = spi_qas(starget);
2065 tp->tprint.check_nego = 1;
2077 struct sym_tcb *tp = &np->target[target];
2078 struct scsi_target *starget = tp->starget;
2083 tp->tgoal.renego = NS_WIDE;
2085 tp->tgoal.renego = 0;
2086 tp->tgoal.check_nego = 0;
2087 tp->tgoal.width = wide;
2107 struct sym_tcb *tp = &np->target[target];
2108 struct scsi_target *starget = tp->starget;
2109 u_char wide = (tp->head.wval & EWS) ? BUS_16_BIT : BUS_8_BIT;
2114 tp->tgoal.renego = NS_WIDE;
2116 tp->tgoal.renego = NS_SYNC;
2118 tp->tgoal.renego = 0;
2123 if (!tp->tgoal.dt && !tp->tgoal.iu && !tp->tgoal.qas) {
2124 tp->tgoal.period = per;
2125 tp->tgoal.offset = ofs;
2126 tp->tgoal.check_nego = 0;
2140 struct sym_tcb *tp = &np->target[target];
2141 struct scsi_target *starget = tp->starget;
2146 tp->tgoal.renego = NS_PPR;
2148 tp->tgoal.renego = 0;
2149 spi_width(starget) = tp->tgoal.width = wide;
2150 spi_period(starget) = tp->tgoal.period = per;
2151 spi_offset(starget) = tp->tgoal.offset = ofs;
2152 spi_iu(starget) = tp->tgoal.iu = !!(opts & PPR_OPT_IU);
2153 spi_dt(starget) = tp->tgoal.dt = !!(opts & PPR_OPT_DT);
2154 spi_qas(starget) = tp->tgoal.qas = !!(opts & PPR_OPT_QAS);
2155 tp->tgoal.check_nego = 0;
2205 OUTB(np, nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */
2214 cp->host_status = hsts;
2261 * spi2-r12 11.2.3 says a transceiver mode change must
2277 sym_scsi_bus_mode(np->scsi_mode), sym_scsi_bus_mode(scsi_mode));
2295 * - The complete scatter entry has been transferred
2300 * - A phase mismatch occurs before the MOV finished
2305 * - A phase mismatch occurs before the MOV finished and
2351 cp->xerr_status |= XE_PARITY_ERR;
2356 np->msgout[0] = (phase == 7) ? M_PARITY : M_ID_ERROR;
2379 #if 1 /* in message-in phase due to the relection */
2438 if (np->features & FE_DFBC)
2444 * Read DFIFO, CTEST[4-6] using 1 PCI bus ownership.
2454 (dfifo & 0xff)) - rest) & 0x3ff;
2456 delta = ((dfifo & 0xff) - rest) & 0x7f;
2461 * the target -> add the amount to the rest
2468 if (!(np->features & FE_C10))
2470 if (cp && (cp->phys.select.sel_scntl3 & EWS)) {
2473 if (!(np->features & FE_C10))
2480 OUTB(np, nc_ctest3, np->rv_ctest3 | CLF); /* dma fifo */
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));
2534 tblp = (u32 *) ((char*) &cp->phys + oadr);
2556 sym_print_addr(cp->cmd,
2567 sym_print_addr(cp->cmd,
2568 "phase change %x-%x %d@%08x resid=%d.\n",
2587 nxtdsp = scr_to_cpu(cp->phys.pm0.ret);
2589 nxtdsp = scr_to_cpu(cp->phys.pm1.ret);
2596 pm = &cp->phys.pm0;
2600 pm = &cp->phys.pm1;
2611 pm->sg.addr = cpu_to_scr(oadr + olen - rest);
2612 pm->sg.size = cpu_to_scr(rest);
2613 pm->ret = cpu_to_scr(nxtdsp);
2617 * - prepare the address to write the SWIDE from SCRIPTS,
2618 * - compute the SCRIPTS address to restart from,
2619 * - move current data pointer context by one byte.
2622 if ((cmd & 7) == 1 && cp && (cp->phys.select.sel_scntl3 & EWS) &&
2631 tmp = scr_to_cpu(pm->sg.addr);
2632 cp->phys.wresid.addr = cpu_to_scr(tmp);
2633 pm->sg.addr = cpu_to_scr(tmp + 1);
2634 tmp = scr_to_cpu(pm->sg.size);
2635 cp->phys.wresid.size = cpu_to_scr((tmp&0xff000000) | 1);
2636 pm->sg.size = cpu_to_scr(tmp - 1);
2643 newcmd = pm->ret;
2653 sym_print_addr(cp->cmd, "PM %x %x %x / %x %x %x.\n",
2655 (unsigned)scr_to_cpu(pm->sg.addr),
2656 (unsigned)scr_to_cpu(pm->sg.size),
2657 (unsigned)scr_to_cpu(pm->ret));
2675 * COMMAND --> MSG IN SCSI parity error detected by target.
2676 * COMMAND --> STATUS Bad command or refused by target.
2677 * MSG OUT --> MSG IN Message rejected by target.
2678 * MSG OUT --> COMMAND Bogus target that discards extended
2695 dsp -= 8;
2715 if (cp->tag != NO_TAG && olen - rest <= 3) {
2716 cp->host_status = HS_BUSY;
2717 np->msgout[0] = IDENTIFY(0, cp->lun);
2728 struct scsi_device *dev = cp->cmd->device;
2729 dev->ppr = 0;
2768 * - SCSI parity error + Phase mismatch (PAR|MA)
2770 * and the device switches to msg-in phase inside a
2772 * - SCSI parity error + Unexpected disconnect (PAR|UDC)
2775 * - Some combinations of STO, PAR, UDC, ...
2808 * ask me for any guarantee that it will never fail. :-)
2815 struct sym_hcb *np = sym_data->ncb;
2816 struct pci_dev *pdev = sym_data->pdev;
2834 OUTB(np, nc_istat, (istat & SIGP) | INTF | np->istat_sem);
2922 * On STO and UDC, we complete the CCB with the corres-
2931 OUTB(np, nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */
2971 * a given target/lun/task condition (-1 means all),
2993 while (i != np->squeueput) {
2994 cp = sym_ccb_from_dsa(np, scr_to_cpu(np->squeue[i]));
2998 cp->host_flags &= ~HF_HINT_IARB;
3000 if ((target == -1 || cp->target == target) &&
3001 (lun == -1 || cp->lun == lun) &&
3002 (task == -1 || cp->tag == task)) {
3003 sym_set_cam_status(cp->cmd, DID_SOFT_ERROR);
3004 sym_remque(&cp->link_ccbq);
3005 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq);
3009 np->squeue[j] = np->squeue[i];
3015 np->squeue[j] = np->squeue[i];
3016 np->squeueput = j; /* Update our current start queue pointer */
3018 return (i - j) / 2;
3042 u_char s_status = cp->ssss_status;
3043 u_char h_flags = cp->host_flags;
3050 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
3057 if (np->last_cp)
3058 np->last_cp = 0;
3068 sym_print_addr(cp->cmd, "%s\n",
3088 sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1);
3095 cp->sv_scsi_status = cp->ssss_status;
3096 cp->sv_xerr_status = cp->xerr_status;
3097 cp->sv_resid = sym_compute_residual(np, cp);
3104 cp->scsi_smsg2[0] = IDENTIFY(0, cp->lun);
3115 * cp->nego_status is filled by sym_prepare_nego().
3117 cp->nego_status = 0;
3118 msglen += sym_prepare_nego(np, cp, &cp->scsi_smsg2[msglen]);
3122 cp->phys.smsg.addr = CCB_BA(cp, scsi_smsg2);
3123 cp->phys.smsg.size = cpu_to_scr(msglen);
3128 cp->phys.cmd.addr = CCB_BA(cp, sensecmd);
3129 cp->phys.cmd.size = cpu_to_scr(6);
3134 cp->sensecmd[0] = REQUEST_SENSE;
3135 cp->sensecmd[1] = 0;
3136 if (cp->cmd->device->scsi_level <= SCSI_2 && cp->lun <= 7)
3137 cp->sensecmd[1] = cp->lun << 5;
3138 cp->sensecmd[4] = SYM_SNS_BBUF_LEN;
3139 cp->data_len = SYM_SNS_BBUF_LEN;
3144 memset(cp->sns_bbuf, 0, SYM_SNS_BBUF_LEN);
3145 cp->phys.sense.addr = CCB_BA(cp, sns_bbuf);
3146 cp->phys.sense.size = cpu_to_scr(SYM_SNS_BBUF_LEN);
3153 cp->phys.head.savep = cpu_to_scr(startp);
3154 cp->phys.head.lastp = cpu_to_scr(startp);
3155 cp->startp = cpu_to_scr(startp);
3156 cp->goalp = cpu_to_scr(startp + 16);
3158 cp->host_xflags = 0;
3159 cp->host_status = cp->nego_status ? HS_NEGOTIATE : HS_BUSY;
3160 cp->ssss_status = S_ILLEGAL;
3161 cp->host_flags = (HF_SENSE|HF_DATA_IN);
3162 cp->xerr_status = 0;
3163 cp->extra_bytes = 0;
3165 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA(np, select));
3191 * - lun=-1 means any logical UNIT otherwise a given one.
3192 * - task=-1 means any task, otherwise a given one.
3204 sym_que_splice(&np->busy_ccbq, &qtmp);
3205 sym_que_init(&np->busy_ccbq);
3215 cmd = cp->cmd;
3216 if (cp->host_status != HS_DISCONNECT ||
3217 cp->target != target ||
3218 (lun != -1 && cp->lun != lun) ||
3219 (task != -1 &&
3220 (cp->tag != NO_TAG && cp->scsi_smsg[2] != task))) {
3221 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
3224 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq);
3259 * - If nothing, we just sent a M_ABORT message to the
3262 * - If the target is to be reset, we send it a M_RESET
3264 * - If a logical UNIT is to be cleared , we send the
3266 * - If an untagged task is to be aborted, we send the
3268 * - If a tagged task is to be aborted, we send the
3283 int target=-1, lun=-1, task;
3297 tp = &np->target[i];
3298 if (tp->to_reset ||
3299 (tp->lun0p && tp->lun0p->to_clear)) {
3303 if (!tp->lunmp)
3306 if (tp->lunmp[k] && tp->lunmp[k]->to_clear) {
3311 if (target != -1)
3319 if (target == -1) {
3320 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
3322 if (cp->host_status != HS_DISCONNECT)
3324 if (cp->to_abort) {
3325 target = cp->target;
3335 if (target != -1) {
3336 tp = &np->target[target];
3337 np->abrt_sel.sel_id = target;
3338 np->abrt_sel.sel_scntl3 = tp->head.wval;
3339 np->abrt_sel.sel_sxfer = tp->head.sval;
3340 OUTL(np, nc_dsa, np->hcb_ba);
3352 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
3354 if (cp->host_status != HS_BUSY &&
3355 cp->host_status != HS_NEGOTIATE)
3357 if (!cp->to_abort)
3365 if (cp == np->last_cp) {
3366 cp->to_abort = 0;
3379 np->istat_sem = 0;
3388 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
3389 i = sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1);
3395 assert(i && sym_get_cam_status(cp->cmd) == DID_SOFT_ERROR);
3397 sym_remque(&cp->link_ccbq);
3398 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq);
3403 if (cp->to_abort == 2)
3404 sym_set_cam_status(cp->cmd, DID_TIME_OUT);
3406 sym_set_cam_status(cp->cmd, DID_ABORT);
3419 tp = &np->target[target];
3421 np->abrt_tbl.addr = cpu_to_scr(vtobus(np->abrt_msg));
3428 if (tp->to_reset) {
3429 np->abrt_msg[0] = M_RESET;
3430 np->abrt_tbl.size = 1;
3431 tp->to_reset = 0;
3438 if (tp->lun0p && tp->lun0p->to_clear)
3440 else if (tp->lunmp) {
3442 if (tp->lunmp[k] && tp->lunmp[k]->to_clear) {
3453 if (lun != -1) {
3455 lp->to_clear = 0; /* We don't expect to fail here */
3456 np->abrt_msg[0] = IDENTIFY(0, lun);
3457 np->abrt_msg[1] = M_ABORT;
3458 np->abrt_tbl.size = 2;
3468 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
3470 if (cp->host_status != HS_DISCONNECT)
3472 if (cp->target != target)
3474 if (!cp->to_abort)
3488 np->abrt_msg[0] = M_ABORT;
3489 np->abrt_tbl.size = 1;
3497 np->abrt_msg[0] = IDENTIFY(0, cp->lun);
3505 if (cp->tag == NO_TAG) {
3506 np->abrt_msg[1] = M_ABORT;
3507 np->abrt_tbl.size = 2;
3509 np->abrt_msg[1] = cp->scsi_smsg[1];
3510 np->abrt_msg[2] = cp->scsi_smsg[2];
3511 np->abrt_msg[3] = M_ABORT_TAG;
3512 np->abrt_tbl.size = 4;
3519 if (cp->to_abort == 2)
3520 sym_set_cam_status(cp->cmd, DID_TIME_OUT);
3521 cp->to_abort = 0; /* We donnot expect to fail here */
3530 tp = &np->target[target];
3531 starget = tp->starget;
3536 if (np->abrt_msg[0] == M_ABORT)
3542 * - Reset everything to async 8 bit
3543 * - Tell ourself to negotiate next time :-)
3544 * - Prepare to clear all disconnected CCBs for
3545 * this target from our task list (lun=task=-1)
3547 lun = -1;
3548 task = -1;
3549 if (np->abrt_msg[0] == M_RESET) {
3550 tp->head.sval = 0;
3551 tp->head.wval = np->rv_scntl3;
3552 tp->head.uval = 0;
3559 tp->tgoal.check_nego = 1;
3560 tp->tgoal.renego = 0;
3567 * or an ABORT message :-)
3570 lun = np->abrt_msg[0] & 0x3f;
3571 if (np->abrt_msg[1] == M_ABORT_TAG)
3572 task = np->abrt_msg[2];
3579 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
3580 sym_dequeue_from_squeue(np, i, target, lun, -1);
3587 if (np->abrt_msg[0] == M_RESET)
3597 dev_info(&tp->starget->dev, "control msgout:");
3598 sym_printl_hex(np->abrt_msg, np->abrt_tbl.size);
3599 np->abrt_tbl.size = cpu_to_scr(np->abrt_tbl.size);
3619 * - dp_sg = SYM_CONF_MAX_SG
3621 * - dp_sg < SYM_CONF_MAX_SG
3624 * - dp_ofs < 0
3627 * - dp_ofs = 0
3649 pm = &cp->phys.pm0;
3651 pm = &cp->phys.pm1;
3656 dp_scr = scr_to_cpu(pm->ret);
3657 dp_ofs -= scr_to_cpu(pm->sg.size) & 0x00ffffff;
3661 * If we are auto-sensing, then we are done.
3663 if (cp->host_flags & HF_SENSE) {
3674 tmp = scr_to_cpu(cp->goalp);
3677 dp_sg -= (tmp - 8 - (int)dp_scr) / (2*4);
3678 dp_sgmin = SYM_CONF_MAX_SG - cp->segments;
3695 --dp_sg;
3696 tmp = scr_to_cpu(cp->phys.data[dp_sg].size);
3707 tmp = scr_to_cpu(cp->phys.data[dp_sg].size);
3708 dp_ofs -= (tmp & 0xffffff);
3728 if (dp_sg > cp->ext_sg ||
3729 (dp_sg == cp->ext_sg && dp_ofs > cp->ext_ofs)) {
3730 cp->ext_sg = dp_sg;
3731 cp->ext_ofs = dp_ofs;
3741 return -1;
3750 * is equivalent to a MODIFY DATA POINTER (offset=-1).
3764 * Not supported for auto-sense.
3766 if (cp->host_flags & HF_SENSE)
3781 dp_ret = cpu_to_scr(cp->goalp);
3782 dp_ret = dp_ret - 8 - (SYM_CONF_MAX_SG - dp_sg) * (2*4);
3802 pm = &cp->phys.pm0;
3806 pm = &cp->phys.pm1;
3818 * corresponding to index dp_sg-1 prior to returning
3821 pm->ret = cpu_to_scr(dp_ret);
3822 tmp = scr_to_cpu(cp->phys.data[dp_sg-1].addr);
3823 tmp += scr_to_cpu(cp->phys.data[dp_sg-1].size) + dp_ofs;
3824 pm->sg.addr = cpu_to_scr(tmp);
3825 pm->sg.size = cpu_to_scr(-dp_ofs);
3862 * than our residual be zero. :-)
3864 if (cp->xerr_status & (XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN)) {
3865 if (cp->xerr_status & XE_EXTRA_DATA)
3866 resid -= cp->extra_bytes;
3867 if (cp->xerr_status & XE_SODL_UNRUN)
3869 if (cp->xerr_status & XE_SWIDE_OVRUN)
3870 --resid;
3877 if (cp->phys.head.lastp == cp->goalp)
3884 if (cp->startp == cp->phys.head.lastp ||
3885 sym_evaluate_dp(np, cp, scr_to_cpu(cp->phys.head.lastp),
3887 return cp->data_len - cp->odd_byte_adjustment;
3891 * If we were auto-sensing, then we are done.
3893 if (cp->host_flags & HF_SENSE) {
3894 return -dp_ofs;
3901 dp_sgmin = SYM_CONF_MAX_SG - cp->segments;
3902 resid = -cp->ext_ofs;
3903 for (dp_sg = cp->ext_sg; dp_sg < SYM_CONF_MAX_SG; ++dp_sg) {
3904 u_int tmp = scr_to_cpu(cp->phys.data[dp_sg].size);
3908 resid -= cp->odd_byte_adjustment;
3956 int target = cp->target;
3960 sym_print_nego_msg(np, target, "sync msgin", np->msgin);
3967 per = np->msgin[3];
3968 ofs = np->msgin[4];
3974 if (ofs > np->maxoffs)
3975 {chg = 1; ofs = np->maxoffs;}
3979 if (per < np->minsync)
3980 {chg = 1; per = np->minsync;}
3991 sym_print_addr(cp->cmd,
4017 spi_populate_sync_msg(np->msgout, per, ofs);
4020 sym_print_nego_msg(np, target, "sync msgout", np->msgout);
4023 np->msgin [0] = M_NOOP;
4029 return -1;
4042 if (cp->nego_status && cp->nego_status != NS_SYNC)
4054 cp->nego_status = NS_SYNC;
4071 struct sym_tcb *tp = &np->target[target];
4075 unsigned char per = np->msgin[3];
4076 unsigned char ofs = np->msgin[5];
4077 unsigned char wide = np->msgin[6];
4078 unsigned char opts = np->msgin[7] & PPR_OPT_MASK;
4081 sym_print_nego_msg(np, target, "ppr msgin", np->msgin);
4087 if (wide > np->maxwide) {
4089 wide = np->maxwide;
4091 if (!wide || !(np->features & FE_U3EN))
4094 if (opts != (np->msgin[7] & PPR_OPT_MASK))
4100 unsigned char maxoffs = dt ? np->maxoffs_dt : np->maxoffs;
4108 unsigned char minsync = dt ? np->minsync_dt : np->minsync;
4143 spi_populate_ppr_msg(np->msgout, per, ofs, wide, opts);
4146 sym_print_nego_msg(np, target, "ppr msgout", np->msgout);
4149 np->msgin [0] = M_NOOP;
4160 tp->tgoal.period = per;
4161 tp->tgoal.offset = ofs;
4162 tp->tgoal.width = wide;
4163 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
4164 tp->tgoal.check_nego = 1;
4166 return -1;
4179 if (cp->nego_status && cp->nego_status != NS_PPR)
4187 result = sym_ppr_nego_check(np, req, cp->target);
4191 cp->nego_status = NS_PPR;
4208 int target = cp->target;
4212 sym_print_nego_msg(np, target, "wide msgin", np->msgin);
4219 wide = np->msgin[3];
4224 if (wide > np->maxwide) {
4226 wide = np->maxwide;
4230 sym_print_addr(cp->cmd, "wdtr: wide=%d chg=%d.\n",
4255 spi_populate_width_msg(np->msgout, wide);
4257 np->msgin [0] = M_NOOP;
4260 sym_print_nego_msg(np, target, "wide msgout", np->msgout);
4266 return -1;
4279 if (cp->nego_status && cp->nego_status != NS_WIDE)
4291 cp->nego_status = NS_WIDE;
4299 if (tp->tgoal.offset) {
4300 spi_populate_sync_msg(np->msgout, tp->tgoal.period,
4301 tp->tgoal.offset);
4304 sym_print_nego_msg(np, cp->target,
4305 "sync msgout", np->msgout);
4308 cp->nego_status = NS_SYNC;
4335 switch (cp->nego_status) {
4338 sym_setpprot (np, cp->target, 0, 0, 0, 0, 0, 0);
4340 if (tp->tgoal.period < np->minsync)
4341 tp->tgoal.period = np->minsync;
4342 if (tp->tgoal.offset > np->maxoffs)
4343 tp->tgoal.offset = np->maxoffs;
4344 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
4345 tp->tgoal.check_nego = 1;
4349 sym_setsync (np, cp->target, 0, 0, 0, 0);
4352 sym_setwide (np, cp->target, 0);
4355 np->msgin [0] = M_NOOP;
4356 np->msgout[0] = M_NOOP;
4357 cp->nego_status = 0;
4379 struct sym_tcb *tp = &np->target[target];
4396 * or has been auto-sensed.
4415 scmd_printk(KERN_WARNING, cp->cmd,
4423 scmd_printk(KERN_WARNING, cp->cmd,
4431 scmd_printk(KERN_WARNING, cp->cmd,
4438 np->msgout[0] = M_RESET;
4445 np->msgout[0] = M_ABORT;
4451 np->msgout[0] = M_ABORT_TAG;
4458 np->lastmsg = np->msgout[0];
4459 np->msgout[0] = M_NOOP;
4460 scmd_printk(KERN_WARNING, cp->cmd,
4461 "message %x sent on bad reselection\n", np->lastmsg);
4468 np->lastmsg = np->msgout[0];
4469 np->msgout[0] = M_NOOP;
4471 if (np->lastmsg == M_PARITY || np->lastmsg == M_ID_ERROR) {
4473 cp->xerr_status &= ~XE_PARITY_ERR;
4474 if (!cp->xerr_status)
4494 sym_print_msg(cp, "M_REJECT to send for ", np->msgin);
4495 np->msgout[0] = M_REJECT;
4506 cp->xerr_status |= XE_SWIDE_OVRUN;
4517 cp->xerr_status |= XE_SODL_UNRUN;
4529 cp->xerr_status |= XE_EXTRA_DATA;
4530 cp->extra_bytes += INL(np, nc_scratcha);
4539 cp->xerr_status |= XE_BAD_PHASE;
4548 switch (np->msgin [0]) {
4555 switch (np->msgin [2]) {
4559 np->msgin);
4560 tmp = (np->msgin[3]<<24) + (np->msgin[4]<<16) +
4561 (np->msgin[5]<<8) + (np->msgin[6]);
4582 * WIDE RESIDUE messages are aliased as MODIFY DP (-1).
4586 sym_print_msg(cp, "1 or 2 byte ", np->msgin);
4587 if (cp->host_flags & HF_SENSE)
4590 sym_modify_dp(np, tp, cp, -1);
4596 sym_print_addr(cp->cmd,
4598 scr_to_cpu(np->lastmsg), np->msgout[0]);
4611 sym_print_msg(cp, "WEIRD message received", np->msgin);
4648 u_char tn = cmd->device->id;
4649 u_char ln = cmd->device->lun;
4650 struct sym_tcb *tp = &np->target[tn];
4659 if (sym_que_empty(&np->free_ccbq))
4661 qp = sym_remque_head(&np->free_ccbq);
4675 if (lp->busy_itl != 0)
4681 if (!lp->cb_tags) {
4683 if (!lp->cb_tags)
4692 if (lp->busy_itlq < SYM_CONF_MAX_TASK) {
4693 tag = lp->cb_tags[lp->ia_tag];
4694 if (++lp->ia_tag == SYM_CONF_MAX_TASK)
4695 lp->ia_tag = 0;
4696 ++lp->busy_itlq;
4698 lp->itlq_tbl[tag] = cpu_to_scr(cp->ccb_ba);
4699 lp->head.resel_sa =
4703 cp->tags_si = lp->tags_si;
4704 ++lp->tags_sum[cp->tags_si];
4705 ++lp->tags_since;
4721 if (lp->busy_itl != 0 || lp->busy_itlq != 0)
4729 ++lp->busy_itl;
4731 if (lp->busy_itl == 1) {
4732 lp->head.itl_task_sa = cpu_to_scr(cp->ccb_ba);
4733 lp->head.resel_sa =
4744 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
4747 sym_remque(&cp->link2_ccbq);
4748 sym_insque_tail(&cp->link2_ccbq, &lp->waiting_ccbq);
4752 cp->to_abort = 0;
4753 cp->odd_byte_adjustment = 0;
4754 cp->tag = tag;
4755 cp->order = tag_order;
4756 cp->target = tn;
4757 cp->lun = ln;
4766 sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
4775 struct sym_tcb *tp = &np->target[cp->target];
4776 struct sym_lcb *lp = sym_lp(tp, cp->lun);
4779 sym_print_addr(cp->cmd, "ccb @%p freeing tag %d.\n",
4780 cp, cp->tag);
4790 if (cp->tag != NO_TAG) {
4792 --lp->tags_sum[cp->tags_si];
4797 lp->cb_tags[lp->if_tag] = cp->tag;
4798 if (++lp->if_tag == SYM_CONF_MAX_TASK)
4799 lp->if_tag = 0;
4804 lp->itlq_tbl[cp->tag] = cpu_to_scr(np->bad_itlq_ba);
4805 --lp->busy_itlq;
4811 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba);
4812 --lp->busy_itl;
4817 if (lp->busy_itlq == 0 && lp->busy_itl == 0)
4818 lp->head.resel_sa =
4827 if (cp == tp->nego_cp)
4828 tp->nego_cp = NULL;
4835 if (cp == np->last_cp)
4836 np->last_cp = 0;
4842 cp->cmd = NULL;
4843 cp->host_status = HS_IDLE;
4844 sym_remque(&cp->link_ccbq);
4845 sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
4849 sym_remque(&cp->link2_ccbq);
4850 sym_insque_tail(&cp->link2_ccbq, &np->dummy_ccbq);
4851 if (cp->started) {
4852 if (cp->tag != NO_TAG)
4853 --lp->started_tags;
4855 --lp->started_no_tag;
4858 cp->started = 0;
4863 * Allocate a CCB from memory and initialize its fixed part.
4874 if (np->actccbs >= SYM_CONF_MAX_START)
4887 np->actccbs++;
4892 cp->ccb_ba = vtobus(cp);
4897 hcode = CCB_HASH_CODE(cp->ccb_ba);
4898 cp->link_ccbh = np->ccbh[hcode];
4899 np->ccbh[hcode] = cp;
4904 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA(np, idle));
4905 cp->phys.head.go.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
4910 cp->phys.smsg_ext.addr = cpu_to_scr(HCB_BA(np, msgin[2]));
4915 sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
4921 sym_insque_head(&cp->link2_ccbq, &np->dummy_ccbq);
4939 cp = np->ccbh[hcode];
4941 if (cp->ccb_ba == dsa)
4943 cp = cp->link_ccbh;
4971 struct sym_tcb *tp = &np->target[tn];
4983 if (ln && !tp->luntbl) {
4986 tp->luntbl = sym_calloc_dma(256, "LUNTBL");
4987 if (!tp->luntbl)
4990 tp->luntbl[i] = cpu_to_scr(vtobus(&np->badlun_sa));
4991 tp->head.luntbl_sa = cpu_to_scr(vtobus(tp->luntbl));
4997 if (ln && !tp->lunmp) {
4998 tp->lunmp = kcalloc(SYM_CONF_MAX_LUN, sizeof(struct sym_lcb *),
5000 if (!tp->lunmp)
5012 tp->lunmp[ln] = lp;
5013 tp->luntbl[ln] = cpu_to_scr(vtobus(lp));
5016 tp->lun0p = lp;
5017 tp->head.lun0_sa = cpu_to_scr(vtobus(lp));
5019 tp->nlcb++;
5024 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba);
5029 lp->head.resel_sa = cpu_to_scr(SCRIPTB_BA(np, resel_bad_lun));
5034 lp->user_flags = tp->usrflags & (SYM_DISC_ENABLED | SYM_TAGS_ENABLED);
5040 sym_que_init(&lp->waiting_ccbq);
5041 sym_que_init(&lp->started_ccbq);
5042 lp->started_max = SYM_CONF_MAX_TASK;
5043 lp->started_limit = SYM_CONF_MAX_TASK;
5055 struct sym_tcb *tp = &np->target[tn];
5063 lp->itlq_tbl = sym_calloc_dma(SYM_CONF_MAX_TASK*4, "ITLQ_TBL");
5064 if (!lp->itlq_tbl)
5066 lp->cb_tags = kcalloc(SYM_CONF_MAX_TASK, 1, GFP_ATOMIC);
5067 if (!lp->cb_tags) {
5068 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK*4, "ITLQ_TBL");
5069 lp->itlq_tbl = NULL;
5077 lp->itlq_tbl[i] = cpu_to_scr(np->notask_ba);
5083 lp->cb_tags[i] = i;
5089 lp->head.itlq_tbl_sa = cpu_to_scr(vtobus(lp->itlq_tbl));
5102 struct sym_tcb *tp = &np->target[tn];
5105 tp->nlcb--;
5108 if (!tp->nlcb) {
5109 kfree(tp->lunmp);
5110 sym_mfree_dma(tp->luntbl, 256, "LUNTBL");
5111 tp->lunmp = NULL;
5112 tp->luntbl = NULL;
5113 tp->head.luntbl_sa = cpu_to_scr(vtobus(np->badluntbl));
5115 tp->luntbl[ln] = cpu_to_scr(vtobus(&np->badlun_sa));
5116 tp->lunmp[ln] = NULL;
5119 tp->lun0p = NULL;
5120 tp->head.lun0_sa = cpu_to_scr(vtobus(&np->badlun_sa));
5123 if (lp->itlq_tbl) {
5124 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK*4, "ITLQ_TBL");
5125 kfree(lp->cb_tags);
5130 return tp->nlcb;
5138 struct scsi_device *sdev = cmd->device;
5148 cp->cmd = cmd;
5153 tp = &np->target[cp->target];
5158 lp = sym_lp(tp, sdev->lun);
5160 can_disconnect = (cp->tag != NO_TAG) ||
5161 (lp && (lp->curr_flags & SYM_DISC_ENABLED));
5163 msgptr = cp->scsi_smsg;
5165 msgptr[msglen++] = IDENTIFY(can_disconnect, sdev->lun);
5170 if (cp->tag != NO_TAG) {
5171 u_char order = cp->order;
5188 if (lp && lp->tags_since > 3*SYM_CONF_MAX_TAG) {
5189 lp->tags_si = !(lp->tags_si);
5190 if (lp->tags_sum[lp->tags_si]) {
5197 lp->tags_since = 0;
5210 msgptr[msglen++] = cp->tag;
5212 msgptr[msglen++] = (cp->tag << 1) + 1;
5223 cp->nego_status = 0;
5224 if ((tp->tgoal.check_nego ||
5225 cmd->cmnd[0] == INQUIRY || cmd->cmnd[0] == REQUEST_SENSE) &&
5226 !tp->nego_cp && lp) {
5233 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA(np, select));
5234 cp->phys.head.go.restart = cpu_to_scr(SCRIPTA_BA(np, resel_dsa));
5239 cp->phys.select.sel_id = cp->target;
5240 cp->phys.select.sel_scntl3 = tp->head.wval;
5241 cp->phys.select.sel_sxfer = tp->head.sval;
5242 cp->phys.select.sel_scntl4 = tp->head.uval;
5247 cp->phys.smsg.addr = CCB_BA(cp, scsi_smsg);
5248 cp->phys.smsg.size = cpu_to_scr(msglen);
5253 cp->host_xflags = 0;
5254 cp->host_status = cp->nego_status ? HS_NEGOTIATE : HS_BUSY;
5255 cp->ssss_status = S_ILLEGAL;
5256 cp->xerr_status = 0;
5257 cp->host_flags = 0;
5258 cp->extra_bytes = 0;
5262 * shall be positive, so -1 is lower than lowest.:)
5264 cp->ext_sg = -1;
5265 cp->ext_ofs = 0;
5281 if (target == np->myaddr || (u_int)target >= SYM_CONF_MAX_TARGET)
5282 return -1;
5284 tp = &np->target[target];
5285 tp->to_reset = 1;
5287 np->istat_sem = SEM;
5301 if (!cp || !cp->host_status || cp->host_status == HS_WAIT)
5302 return -1;
5308 if (cp->to_abort) {
5316 cp->to_abort = timed_out ? 2 : 1;
5321 np->istat_sem = SEM;
5335 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
5337 if (cp2->cmd == cmd) {
5348 * error, SCSI status error, or having been auto-sensed.
5368 if (!cp || !cp->cmd)
5371 cmd = cp->cmd;
5372 sdev = cmd->device;
5374 dev_info(&sdev->sdev_gendev, "CCB=%p STAT=%x/%x/%x\n", cp,
5375 cp->host_status, cp->ssss_status, cp->host_flags);
5381 tp = &np->target[cp->target];
5382 lp = sym_lp(tp, sdev->lun);
5387 if (cp->xerr_status) {
5389 sym_print_xerr(cmd, cp->xerr_status);
5390 if (cp->host_status == HS_COMPLETE)
5391 cp->host_status = HS_COMP_ERR;
5401 cp->sv_resid = 0;
5405 printf("XXXX RESID= %d - 0x%x\n", resid, resid);
5412 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
5413 i = sym_dequeue_from_squeue(np, i, cp->target, sdev->lun, -1);
5421 if (cp->host_status == HS_COMPLETE &&
5422 cp->ssss_status == S_QUEUE_FULL) {
5423 if (!lp || lp->started_tags - i < 2)
5428 lp->started_max = lp->started_tags - i - 1;
5429 lp->num_sgood = 0;
5433 lp->started_max);
5439 cp->host_status = HS_BUSY;
5440 cp->ssss_status = S_ILLEGAL;
5461 sym_remque(&cp->link_ccbq);
5462 sym_insque_head(&cp->link_ccbq, &np->comp_ccbq);
5497 if (!cp || !cp->cmd)
5499 assert (cp->host_status == HS_COMPLETE);
5504 cmd = cp->cmd;
5509 tp = &np->target[cp->target];
5510 lp = sym_lp(tp, cp->lun);
5517 if (cp->phys.head.lastp != cp->goalp)
5529 printf("XXXX RESID= %d - 0x%x\n", resid, resid);
5542 if (lp && lp->started_max < lp->started_limit) {
5543 ++lp->num_sgood;
5544 if (lp->num_sgood >= 200) {
5545 lp->num_sgood = 0;
5546 ++lp->started_max;
5549 lp->started_max);
5564 if (!sym_que_empty(&lp->waiting_ccbq))
5574 * Soft-attach the controller.
5584 np->scripta_sz = fw->a_size;
5585 np->scriptb_sz = fw->b_size;
5586 np->scriptz_sz = fw->z_size;
5587 np->fw_setup = fw->setup;
5588 np->fw_patch = fw->patch;
5589 np->fw_name = fw->name;
5599 * that SCSI clock calibration may not work properly
5606 * to chip features, user set-up and driver set-up.
5611 * Check the PCI clock frequency.
5613 * STEST1 that is used to probe for the clock doubler.
5616 if (i > 37000 && !(np->features & FE_66MHZ))
5617 printf("%s: PCI BUS clock seems too high: %u KHz.\n",
5623 np->squeue = sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"SQUEUE");
5624 if (!np->squeue)
5626 np->squeue_ba = vtobus(np->squeue);
5631 np->dqueue = sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"DQUEUE");
5632 if (!np->dqueue)
5634 np->dqueue_ba = vtobus(np->dqueue);
5639 np->targtbl = sym_calloc_dma(256, "TARGTBL");
5640 if (!np->targtbl)
5642 np->targtbl_ba = vtobus(np->targtbl);
5647 np->scripta0 = sym_calloc_dma(np->scripta_sz, "SCRIPTA0");
5648 np->scriptb0 = sym_calloc_dma(np->scriptb_sz, "SCRIPTB0");
5649 np->scriptz0 = sym_calloc_dma(np->scriptz_sz, "SCRIPTZ0");
5650 if (!np->scripta0 || !np->scriptb0 || !np->scriptz0)
5656 np->ccbh = kcalloc(CCB_HASH_SIZE, sizeof(struct sym_ccb **), GFP_KERNEL);
5657 if (!np->ccbh)
5663 sym_que_init(&np->free_ccbq);
5664 sym_que_init(&np->busy_ccbq);
5665 sym_que_init(&np->comp_ccbq);
5672 sym_que_init(&np->dummy_ccbq);
5684 np->scripta_ba = vtobus(np->scripta0);
5685 np->scriptb_ba = vtobus(np->scriptb0);
5686 np->scriptz_ba = vtobus(np->scriptz0);
5688 if (np->ram_ba) {
5689 np->scripta_ba = np->ram_ba;
5690 if (np->features & FE_RAM8K) {
5691 np->scriptb_ba = np->scripta_ba + 4096;
5693 np->scr_ram_seg = cpu_to_scr(np->scripta_ba >> 32);
5701 memcpy(np->scripta0, fw->a_base, np->scripta_sz);
5702 memcpy(np->scriptb0, fw->b_base, np->scriptb_sz);
5703 memcpy(np->scriptz0, fw->z_base, np->scriptz_sz);
5709 np->fw_setup(np, fw);
5715 sym_fw_bind_script(np, (u32 *) np->scripta0, np->scripta_sz);
5716 sym_fw_bind_script(np, (u32 *) np->scriptb0, np->scriptb_sz);
5717 sym_fw_bind_script(np, (u32 *) np->scriptz0, np->scriptz_sz);
5727 np->iarb_max = SYM_SETUP_IARB_MAX;
5729 np->iarb_max = 4;
5736 np->idletask.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5737 np->idletask.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
5738 np->idletask_ba = vtobus(&np->idletask);
5740 np->notask.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5741 np->notask.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
5742 np->notask_ba = vtobus(&np->notask);
5744 np->bad_itl.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5745 np->bad_itl.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
5746 np->bad_itl_ba = vtobus(&np->bad_itl);
5748 np->bad_itlq.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5749 np->bad_itlq.restart = cpu_to_scr(SCRIPTB_BA(np,bad_i_t_l_q));
5750 np->bad_itlq_ba = vtobus(&np->bad_itlq);
5758 np->badluntbl = sym_calloc_dma(256, "BADLUNTBL");
5759 if (!np->badluntbl)
5762 np->badlun_sa = cpu_to_scr(SCRIPTB_BA(np, resel_bad_lun));
5764 np->badluntbl[i] = cpu_to_scr(vtobus(&np->badlun_sa));
5772 np->targtbl[i] = cpu_to_scr(vtobus(&np->target[i]));
5773 np->target[i].head.luntbl_sa =
5774 cpu_to_scr(vtobus(np->badluntbl));
5775 np->target[i].head.lun0_sa =
5776 cpu_to_scr(vtobus(&np->badlun_sa));
5793 return -ENXIO;
5806 if (np->scriptz0)
5807 sym_mfree_dma(np->scriptz0, np->scriptz_sz, "SCRIPTZ0");
5808 if (np->scriptb0)
5809 sym_mfree_dma(np->scriptb0, np->scriptb_sz, "SCRIPTB0");
5810 if (np->scripta0)
5811 sym_mfree_dma(np->scripta0, np->scripta_sz, "SCRIPTA0");
5812 if (np->squeue)
5813 sym_mfree_dma(np->squeue, sizeof(u32)*(MAX_QUEUE*2), "SQUEUE");
5814 if (np->dqueue)
5815 sym_mfree_dma(np->dqueue, sizeof(u32)*(MAX_QUEUE*2), "DQUEUE");
5817 if (np->actccbs) {
5818 while ((qp = sym_remque_head(&np->free_ccbq)) != NULL) {
5823 kfree(np->ccbh);
5825 if (np->badluntbl)
5826 sym_mfree_dma(np->badluntbl, 256,"BADLUNTBL");
5829 tp = &np->target[target];
5830 if (tp->luntbl)
5831 sym_mfree_dma(tp->luntbl, 256, "LUNTBL");
5833 kfree(tp->lunmp);
5836 if (np->targtbl)
5837 sym_mfree_dma(np->targtbl, 256, "TARGTBL");