Lines Matching +full:chg +full:- +full:status
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * of PCI-SCSI IO processors.
6 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
7 * Copyright (c) 2003-2005 Matthew Wilcox <matthew@wil.cx>
10 * Copyright (C) 1998-2000 Gerard Roudier
13 * a port of the FreeBSD ncr driver to Linux-1.2.13.
17 * Stefan Esser <se@mi.Uni-Koeln.de>
25 *-----------------------------------------------------------------------------
55 while (n-- > 0) in sym_printl_hex()
62 sym_print_addr(cp->cmd, "%s: ", label); in sym_print_msg()
70 struct sym_tcb *tp = &np->target[target]; in sym_print_nego_msg()
71 dev_info(&tp->starget->dev, "%s: ", label); in sym_print_nego_msg()
133 * Some 896 and 876 chip revisions may hang-up if we set
144 if (!(np->features & FE_ISTAT1) || !(INB(np, nc_istat1) & SCRUN)) in sym_soft_reset()
148 for (i = 100000 ; i ; --i) { in sym_soft_reset()
190 OUTB(np, nc_dcntl, (np->rv_dcntl & IRQM)); in sym_reset_scsi_bus()
206 ((INW(np, nc_sbdl) & 0xff) << 9) | /* d7-0 */ in sym_reset_scsi_bus()
207 ((INW(np, nc_sbdl) & 0xff00) << 10) | /* d15-8 */ in sym_reset_scsi_bus()
210 if (!np->maxwide) in sym_reset_scsi_bus()
216 printf("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = " in sym_reset_scsi_bus()
219 (np->features & FE_WIDE) ? "dp1,d15-8," : "", in sym_reset_scsi_bus()
237 if (np->multiplier <= 1) { in sym_selectclock()
248 * Otherwise wait 50 micro-seconds (at least). in sym_selectclock()
250 if (np->features & FE_LCKFRQ) { in sym_selectclock()
252 while (!(INB(np, nc_stest4) & LCKFRQ) && --i > 0) in sym_selectclock()
314 * The C1010-33 core does not report GEN in SIST, in getfreq()
316 * I don't know yet if the C1010-66 behaves the same way. in getfreq()
318 if (np->features & FE_C10) { in getfreq()
322 OUTB(np, nc_scntl3, 4); /* set pre-scaler to divide by 3 */ in getfreq()
329 * Undo C1010-33 specific settings. in getfreq()
331 if (np->features & FE_C10) { in getfreq()
348 * The C1010-33 result is biased by a factor in getfreq()
351 if (np->features & FE_C10) in getfreq()
378 unsigned char scntl3 = np->sv_scntl3; in sym_getclock()
379 unsigned char stest1 = np->sv_stest1; in sym_getclock()
382 np->multiplier = 1; in sym_getclock()
390 np->multiplier = mult; in sym_getclock()
398 if (np->multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) { in sym_getclock()
413 np->multiplier = mult; in sym_getclock()
420 f1 /= np->multiplier; in sym_getclock()
426 f1 *= np->multiplier; in sym_getclock()
427 np->clock_khz = f1; in sym_getclock()
439 * PCI BUS clock frequency for C1010-66 chips.
442 if (np->features & FE_66MHZ) {
450 np->pciclk_khz = f;
471 u32 clk = np->clock_khz; /* SCSI clock frequency in kHz */
472 int div = np->clock_divn; /* Number of divisors supported */
479 * Compute the synchronous period in tenths of nano-seconds
496 * to 5 Mega-transfers per second and may result in
500 if ((np->features & (FE_C10|FE_U3EN)) == FE_C10) {
506 --div;
513 if (div == np->clock_divn) { /* Are we too fast ? */
514 ret = -1;
526 while (--div > 0)
536 fak = (kpc - 1) / (div_10M[div] << 1) + 1 - 2;
537 /* ret = ((2+fak)*div_10M[div])/np->clock_khz; */
539 fak = (kpc - 1) / div_10M[div] + 1 - 4;
540 /* ret = ((4+fak)*div_10M[div])/np->clock_khz; */
548 ret = -1;
591 np->rv_ctest4 &= ~0x80;
592 np->rv_dmode &= ~(0x3 << 6);
593 np->rv_ctest5 &= ~0x4;
596 np->rv_ctest4 |= 0x80;
599 --bc;
600 np->rv_dmode |= ((bc & 0x3) << 6);
601 np->rv_ctest5 |= (bc & 0x4);
616 np->sv_scntl0 = INB(np, nc_scntl0) & 0x0a;
617 np->sv_scntl3 = INB(np, nc_scntl3) & 0x07;
618 np->sv_dmode = INB(np, nc_dmode) & 0xce;
619 np->sv_dcntl = INB(np, nc_dcntl) & 0xa8;
620 np->sv_ctest3 = INB(np, nc_ctest3) & 0x01;
621 np->sv_ctest4 = INB(np, nc_ctest4) & 0x80;
622 np->sv_gpcntl = INB(np, nc_gpcntl);
623 np->sv_stest1 = INB(np, nc_stest1);
624 np->sv_stest2 = INB(np, nc_stest2) & 0x20;
625 np->sv_stest4 = INB(np, nc_stest4);
626 if (np->features & FE_C10) { /* Always large DMA fifo + ultra3 */
627 np->sv_scntl4 = INB(np, nc_scntl4);
628 np->sv_ctest5 = INB(np, nc_ctest5) & 0x04;
631 np->sv_ctest5 = INB(np, nc_ctest5) & 0x24;
636 * - LVD capable chips (895/895A/896/1010) report the current BUS mode
638 * - For previous generation chips (825/825A/875), the user has to tell us
643 if (np->scsi_mode)
646 np->scsi_mode = SMODE_SE;
647 if (np->features & (FE_ULTRA2|FE_ULTRA3))
648 np->scsi_mode = (np->sv_stest4 & SMODE);
649 else if (np->features & FE_DIFF) {
651 if (np->sv_scntl3) {
652 if (np->sv_stest2 & 0x20)
653 np->scsi_mode = SMODE_HVD;
654 } else if (nvram->type == SYM_SYMBIOS_NVRAM) {
656 np->scsi_mode = SMODE_HVD;
659 np->scsi_mode = SMODE_HVD;
661 if (np->scsi_mode == SMODE_HVD)
662 np->rv_stest2 |= 0x20;
672 struct pci_dev *pdev = sym_data->pdev;
677 np->maxwide = (np->features & FE_WIDE) ? 1 : 0;
682 if (np->features & (FE_ULTRA3 | FE_ULTRA2))
683 np->clock_khz = 160000;
684 else if (np->features & FE_ULTRA)
685 np->clock_khz = 80000;
687 np->clock_khz = 40000;
692 if (np->features & FE_QUAD)
693 np->multiplier = 4;
694 else if (np->features & FE_DBLR)
695 np->multiplier = 2;
697 np->multiplier = 1;
703 if (np->features & FE_VARCLK)
704 sym_getclock(np, np->multiplier);
707 * Divisor to be used for async (timer pre-scaler).
709 i = np->clock_divn - 1;
710 while (--i >= 0) {
711 if (10ul * SYM_CONF_MIN_ASYNC * np->clock_khz > div_10M[i]) {
716 np->rv_scntl3 = i+1;
720 * So, we just throw away, the async. divisor.:-)
722 if (np->features & FE_C10)
723 np->rv_scntl3 = 0;
729 period = (4 * div_10M[0] + np->clock_khz - 1) / np->clock_khz;
731 if (period <= 250) np->minsync = 10;
732 else if (period <= 303) np->minsync = 11;
733 else if (period <= 500) np->minsync = 12;
734 else np->minsync = (period + 40 - 1) / 40;
737 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
739 if (np->minsync < 25 &&
740 !(np->features & (FE_ULTRA|FE_ULTRA2|FE_ULTRA3)))
741 np->minsync = 25;
742 else if (np->minsync < 12 &&
743 !(np->features & (FE_ULTRA2|FE_ULTRA3)))
744 np->minsync = 12;
749 period = div64_ul(11 * div_10M[np->clock_divn - 1], 4 * np->clock_khz);
750 np->maxsync = period > 2540 ? 254 : period / 10;
755 if ((np->features & (FE_C10|FE_ULTRA3)) == (FE_C10|FE_ULTRA3)) {
756 if (np->clock_khz == 160000) {
757 np->minsync_dt = 9;
758 np->maxsync_dt = 50;
759 np->maxoffs_dt = nvram->type ? 62 : 31;
766 if (np->features & FE_DAC) {
768 np->rv_ccntl1 |= (DDAC);
770 np->rv_ccntl1 |= (XTIMOD | EXTIBMV);
772 np->rv_ccntl1 |= (0 | EXTIBMV);
778 if (np->features & FE_NOPM)
779 np->rv_ccntl0 |= (ENPMJ);
782 * C1010-33 Errata: Part Number:609-039638 (rev. 1) is fixed.
786 if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
787 pdev->revision < 0x1)
788 np->rv_ccntl0 |= DILS;
795 burst_max = burst_code(np->sv_dmode, np->sv_ctest4,
796 np->sv_ctest5);
799 if (burst_max > np->maxburst)
800 burst_max = np->maxburst;
803 * DEL 352 - 53C810 Rev x11 - Part Number 609-0392140 - ITEM 2.
808 * LOAD/STORE instructions does not need this work-around.
810 if ((pdev->device == PCI_DEVICE_ID_NCR_53C810 &&
811 pdev->revision >= 0x10 && pdev->revision <= 0x11) ||
812 (pdev->device == PCI_DEVICE_ID_NCR_53C860 &&
813 pdev->revision <= 0x1))
814 np->features &= ~(FE_WRIE|FE_ERL|FE_ERMP);
818 * If we are using on-board RAM for scripts, prefetch (PFEN)
822 if (np->features & FE_ERL)
823 np->rv_dmode |= ERL; /* Enable Read Line */
824 if (np->features & FE_BOF)
825 np->rv_dmode |= BOF; /* Burst Opcode Fetch */
826 if (np->features & FE_ERMP)
827 np->rv_dmode |= ERMP; /* Enable Read Multiple */
829 if ((np->features & FE_PFEN) && !np->ram_ba)
831 if (np->features & FE_PFEN)
833 np->rv_dcntl |= PFEN; /* Prefetch Enable */
834 if (np->features & FE_CLSE)
835 np->rv_dcntl |= CLSE; /* Cache Line Size Enable */
836 if (np->features & FE_WRIE)
837 np->rv_ctest3 |= WRIE; /* Write and Invalidate */
838 if (np->features & FE_DFS)
839 np->rv_ctest5 |= DFS; /* Dma Fifo Size */
844 np->rv_ctest4 |= MPEE; /* Master parity checking */
845 np->rv_scntl0 |= 0x0a; /* full arb., ena parity, par->ATN */
850 np->myaddr = 255;
851 np->scsi_mode = 0;
857 if (np->myaddr == 255) {
858 np->myaddr = INB(np, nc_scid) & 0x07;
859 if (!np->myaddr)
860 np->myaddr = SYM_SETUP_HOST_ID;
877 (nvram->type == SYM_SYMBIOS_NVRAM ||
878 (nvram->type == SYM_TEKRAM_NVRAM &&
879 pdev->device == PCI_DEVICE_ID_NCR_53C895))) &&
880 !(np->features & FE_LEDC) && !(np->sv_gpcntl & 0x01))
881 np->features |= FE_LED0;
888 np->rv_dcntl |= IRQM;
891 np->rv_dcntl |= (np->sv_dcntl & IRQM);
902 struct sym_tcb *tp = &np->target[i];
904 tp->usrflags |= (SYM_DISC_ENABLED | SYM_TAGS_ENABLED);
905 tp->usrtags = SYM_SETUP_MAX_TAG;
906 tp->usr_width = np->maxwide;
907 tp->usr_period = 9;
911 if (!tp->usrtags)
912 tp->usrflags &= ~SYM_TAGS_ENABLED;
918 printf("%s: %s, ID %d, Fast-%d, %s, %s\n", sym_name(np),
919 sym_nvram_type(nvram), np->myaddr,
920 (np->features & FE_ULTRA3) ? 80 :
921 (np->features & FE_ULTRA2) ? 40 :
922 (np->features & FE_ULTRA) ? 20 : 10,
923 sym_scsi_bus_mode(np->scsi_mode),
924 (np->rv_scntl0 & 0xa) ? "parity checking" : "NO parity");
931 np->rv_dcntl & IRQM ? "totem pole" : "open drain",
932 np->ram_ba ? ", using on-chip SRAM" : "");
933 printf("%s: using %s firmware.\n", sym_name(np), np->fw_name);
934 if (np->features & FE_NOPM)
944 sym_name(np), np->sv_scntl3, np->sv_dmode, np->sv_dcntl,
945 np->sv_ctest3, np->sv_ctest4, np->sv_ctest5);
949 sym_name(np), np->rv_scntl3, np->rv_dmode, np->rv_dcntl,
950 np->rv_ctest3, np->rv_ctest4, np->rv_ctest5);
957 * Test the pci bus snoop logic :-(
978 printf ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
1004 OUTB(np, nc_ctest4, (np->rv_ctest4 & MPEE));
1014 np->scratch = cpu_to_scr(host_wr);
1019 OUTL(np, nc_dsa, np->hcb_ba);
1036 if ((dstat & MDPE) && (np->rv_ctest4 & MPEE)) {
1037 printf ("%s: PCI DATA PARITY ERROR DETECTED - "
1040 np->rv_ctest4 &= ~MPEE;
1055 host_rd = scr_to_cpu(np->scratch);
1093 * sym0 targ 0?: ERROR (ds:si) (so-si-sd) (sx/s3/s4) @ name (dsp:dbc).
1129 if (dsp > np->scripta_ba &&
1130 dsp <= np->scripta_ba + np->scripta_sz) {
1131 script_ofs = dsp - np->scripta_ba;
1132 script_size = np->scripta_sz;
1133 script_base = (u_char *) np->scripta0;
1136 else if (np->scriptb_ba < dsp &&
1137 dsp <= np->scriptb_ba + np->scriptb_sz) {
1138 script_ofs = dsp - np->scriptb_ba;
1139 script_size = np->scriptb_sz;
1140 script_base = (u_char *) np->scriptb0;
1149 printf ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x/%x) @ (%s %x:%08x).\n",
1154 (np->features & FE_C10) ? (unsigned)INB(np, nc_scntl4) : 0,
1250 {PCI_DEVICE_ID_LSI_53C1010_33, 0x00, "1010-33", 6, 31, 7, 8,
1255 {PCI_DEVICE_ID_LSI_53C1010_33, 0xff, "1010-33", 6, 31, 7, 8,
1260 {PCI_DEVICE_ID_LSI_53C1010_66, 0xff, "1010-66", 6, 31, 7, 8,
1286 if (device_id != chip->device_id)
1288 if (revision > chip->revision_id)
1310 for (i = SYM_DMAP_SIZE-1; i > 0; i--) {
1311 if (h == np->dmap_bah[i])
1315 if (!np->dmap_bah[s])
1317 /* Collision -> lookup free mappings */
1318 for (s = SYM_DMAP_SIZE-1; s > 0; s--) {
1319 if (!np->dmap_bah[s])
1324 return -1;
1326 np->dmap_bah[s] = h;
1327 np->dmap_dirty = 1;
1339 if (!np->dmap_dirty)
1343 OUTL_OFF(np, o, np->dmap_bah[i]);
1346 np->dmap_dirty = 0;
1355 goal->width = 0;
1358 goal->iu = 0;
1359 goal->dt = 0;
1360 goal->qas = 0;
1361 goal->offset = 0;
1367 goal->dt = 1;
1369 if (goal->offset == 0)
1370 goal->dt = 0;
1372 goal->dt = 0;
1376 if ((np->scsi_mode != SMODE_LVD) || !(np->features & FE_U3EN))
1377 goal->dt = 0;
1379 if (goal->dt) {
1381 goal->width = 1;
1382 if (goal->offset > np->maxoffs_dt)
1383 goal->offset = np->maxoffs_dt;
1384 if (goal->period < np->minsync_dt)
1385 goal->period = np->minsync_dt;
1386 if (goal->period > np->maxsync_dt)
1387 goal->period = np->maxsync_dt;
1389 goal->iu = goal->qas = 0;
1390 if (goal->offset > np->maxoffs)
1391 goal->offset = np->maxoffs;
1392 if (goal->period < np->minsync)
1393 goal->period = np->minsync;
1394 if (goal->period > np->maxsync)
1395 goal->period = np->maxsync;
1408 struct sym_tcb *tp = &np->target[cp->target];
1409 struct scsi_target *starget = tp->starget;
1410 struct sym_trans *goal = &tp->tgoal;
1420 if (goal->renego == NS_PPR || (goal->offset &&
1421 (goal->iu || goal->dt || goal->qas || (goal->period < 0xa)))) {
1423 } else if (goal->renego == NS_WIDE || goal->width) {
1425 } else if (goal->renego == NS_SYNC || goal->offset) {
1428 goal->check_nego = 0;
1434 msglen += spi_populate_sync_msg(msgptr + msglen, goal->period,
1435 goal->offset);
1438 msglen += spi_populate_width_msg(msgptr + msglen, goal->width);
1441 msglen += spi_populate_ppr_msg(msgptr + msglen, goal->period,
1442 goal->offset, goal->width,
1443 (goal->iu ? PPR_OPT_IU : 0) |
1444 (goal->dt ? PPR_OPT_DT : 0) |
1445 (goal->qas ? PPR_OPT_QAS : 0));
1449 cp->nego_status = nego;
1452 tp->nego_cp = cp; /* Keep track a nego will be performed */
1454 sym_print_nego_msg(np, cp->target,
1480 if (np->last_cp && np->iarb_count < np->iarb_max) {
1481 np->last_cp->host_flags |= HF_HINT_IARB;
1482 ++np->iarb_count;
1485 np->iarb_count = 0;
1486 np->last_cp = cp;
1492 * segment registers not being up-to-date.
1494 if (np->dmap_dirty)
1495 cp->host_xflags |= HX_DMAP_DIRTY;
1502 qidx = np->squeueput + 2;
1505 np->squeue [qidx] = cpu_to_scr(np->idletask_ba);
1507 np->squeue [np->squeueput] = cpu_to_scr(cp->ccb_ba);
1509 np->squeueput = qidx;
1512 scmd_printk(KERN_DEBUG, cp->cmd, "queuepos=%d\n",
1513 np->squeueput);
1520 OUTB(np, nc_istat, SIGP|np->istat_sem);
1525 * Start next ready-to-start CCBs.
1533 * Paranoia, as usual. :-)
1535 assert(!lp->started_tags || !lp->started_no_tag);
1542 while (maxn--) {
1543 qp = sym_remque_head(&lp->waiting_ccbq);
1547 if (cp->tag != NO_TAG) {
1548 if (lp->started_no_tag ||
1549 lp->started_tags >= lp->started_max) {
1550 sym_insque_head(qp, &lp->waiting_ccbq);
1553 lp->itlq_tbl[cp->tag] = cpu_to_scr(cp->ccb_ba);
1554 lp->head.resel_sa =
1556 ++lp->started_tags;
1558 if (lp->started_no_tag || lp->started_tags) {
1559 sym_insque_head(qp, &lp->waiting_ccbq);
1562 lp->head.itl_task_sa = cpu_to_scr(cp->ccb_ba);
1563 lp->head.resel_sa =
1565 ++lp->started_no_tag;
1567 cp->started = 1;
1568 sym_insque_tail(qp, &lp->started_ccbq);
1588 i = np->dqueueget;
1592 dsa = scr_to_cpu(np->dqueue[i]);
1595 np->dqueue[i] = 0;
1609 np->dqueueget = i;
1618 * - Not to be referenced either by devices or
1619 * SCRIPTS-related queues and datas.
1620 * - To have to be completed with an error condition
1633 while ((qp = sym_remque_head(&np->comp_ccbq)) != NULL) {
1636 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
1638 if (cp->host_status == HS_WAIT)
1640 cmd = cp->cmd;
1645 struct sym_tcb *tp = &np->target[cp->target];
1646 struct sym_lcb *lp = sym_lp(tp, cp->lun);
1648 sym_remque(&cp->link2_ccbq);
1649 sym_insque_tail(&cp->link2_ccbq,
1650 &lp->waiting_ccbq);
1651 if (cp->started) {
1652 if (cp->tag != NO_TAG)
1653 --lp->started_tags;
1655 --lp->started_no_tag;
1658 cp->started = 0;
1677 sym_que_splice(&np->busy_ccbq, &np->comp_ccbq);
1678 sym_que_init(&np->busy_ccbq);
1693 struct pci_dev *pdev = sym_data->pdev;
1694 struct sym_hcb *np = sym_data->ncb;
1711 phys = np->squeue_ba;
1713 np->squeue[i] = cpu_to_scr(np->idletask_ba);
1714 np->squeue[i+1] = cpu_to_scr(phys + (i+2)*4);
1716 np->squeue[MAX_QUEUE*2-1] = cpu_to_scr(phys);
1721 np->squeueput = 0;
1726 phys = np->dqueue_ba;
1728 np->dqueue[i] = 0;
1729 np->dqueue[i+1] = cpu_to_scr(phys + (i+2)*4);
1731 np->dqueue[MAX_QUEUE*2-1] = cpu_to_scr(phys);
1736 np->dqueueget = 0;
1743 np->fw_patch(shost);
1757 OUTB(np, nc_scntl0, np->rv_scntl0 | 0xc0);
1758 /* full arb., ena parity, par->ATN */
1761 sym_selectclock(np, np->rv_scntl3); /* Select SCSI clock */
1763 OUTB(np, nc_scid , RRE|np->myaddr); /* Adapter SCSI address */
1764 OUTW(np, nc_respid, 1ul<<np->myaddr); /* Id to respond to */
1766 OUTB(np, nc_dmode , np->rv_dmode); /* Burst length, dma mode */
1767 OUTB(np, nc_ctest5, np->rv_ctest5); /* Large fifo + large burst */
1769 OUTB(np, nc_dcntl , NOCOM|np->rv_dcntl); /* Protect SFBR */
1770 OUTB(np, nc_ctest3, np->rv_ctest3); /* Write and invalidate */
1771 OUTB(np, nc_ctest4, np->rv_ctest4); /* Master parity checking */
1774 if (np->features & FE_C10)
1775 OUTB(np, nc_stest2, np->rv_stest2);
1777 OUTB(np, nc_stest2, EXT|np->rv_stest2);
1783 * For now, disable AIP generation on C1010-66.
1785 if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_66)
1795 if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
1796 pdev->revision < 1)
1800 * DEL 441 - 53C876 Rev 5 - Part Number 609-0392787/2788 - ITEM 2.
1802 * regardless revision id (kind of post-chip-design feature. ;-))
1804 if (pdev->device == PCI_DEVICE_ID_NCR_53C875)
1806 else if (pdev->device == PCI_DEVICE_ID_NCR_53C896)
1807 np->rv_ccntl0 |= DPR;
1814 if (np->features & (FE_DAC|FE_NOPM)) {
1815 OUTB(np, nc_ccntl0, np->rv_ccntl0);
1816 OUTB(np, nc_ccntl1, np->rv_ccntl1);
1825 np->dmap_bah[0] = 0; /* ??? */
1826 OUTL(np, nc_scrx[0], np->dmap_bah[0]);
1827 OUTL(np, nc_drs, np->dmap_bah[0]);
1835 if (np->features & FE_NOPM) {
1844 if (np->features & FE_LED0)
1846 else if (np->features & FE_LEDC)
1860 if (np->features & (FE_ULTRA2|FE_ULTRA3)) {
1867 np->scsi_mode = INB(np, nc_stest4) & SMODE;
1877 struct sym_tcb *tp = &np->target[i];
1879 tp->to_reset = 0;
1880 tp->head.sval = 0;
1881 tp->head.wval = np->rv_scntl3;
1882 tp->head.uval = 0;
1883 if (tp->lun0p)
1884 tp->lun0p->to_clear = 0;
1885 if (tp->lunmp) {
1889 if (tp->lunmp[ln])
1890 tp->lunmp[ln]->to_clear = 0;
1895 * Download SCSI SCRIPTS to on-chip RAM if present,
1902 if (np->ram_ba) {
1905 memcpy_toio(np->s.ramaddr, np->scripta0, np->scripta_sz);
1906 if (np->features & FE_RAM8K) {
1907 memcpy_toio(np->s.ramaddr + 4096, np->scriptb0, np->scriptb_sz);
1908 phys = scr_to_cpu(np->scr_ram_seg);
1916 np->istat_sem = 0;
1918 OUTL(np, nc_dsa, np->hcb_ba);
1936 struct sym_tcb *tp = &np->target[target];
1940 sval = tp->head.sval;
1941 wval = tp->head.wval;
1942 uval = tp->head.uval;
1946 sval, wval, uval, np->rv_scntl3);
1951 if (!(np->features & FE_C10))
1961 if (!(np->features & FE_C10))
1980 if (np->features & FE_C10) {
1983 assert(np->features & FE_U3EN);
1994 if (tp->head.sval == sval &&
1995 tp->head.wval == wval &&
1996 tp->head.uval == uval)
1998 tp->head.sval = sval;
1999 tp->head.wval = wval;
2000 tp->head.uval = uval;
2006 if (per < 50 && !(np->features & FE_C10))
2012 OUTB(np, nc_sxfer, tp->head.sval);
2013 OUTB(np, nc_scntl3, tp->head.wval);
2015 if (np->features & FE_C10) {
2016 OUTB(np, nc_scntl4, tp->head.uval);
2022 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
2025 if (cp->target != target)
2027 cp->phys.select.sel_scntl3 = tp->head.wval;
2028 cp->phys.select.sel_sxfer = tp->head.sval;
2029 if (np->features & FE_C10) {
2030 cp->phys.select.sel_scntl4 = tp->head.uval;
2037 struct scsi_target *starget = tp->starget;
2039 if (tp->tprint.period != spi_period(starget) ||
2040 tp->tprint.offset != spi_offset(starget) ||
2041 tp->tprint.width != spi_width(starget) ||
2042 tp->tprint.iu != spi_iu(starget) ||
2043 tp->tprint.dt != spi_dt(starget) ||
2044 tp->tprint.qas != spi_qas(starget) ||
2045 !tp->tprint.check_nego) {
2046 tp->tprint.period = spi_period(starget);
2047 tp->tprint.offset = spi_offset(starget);
2048 tp->tprint.width = spi_width(starget);
2049 tp->tprint.iu = spi_iu(starget);
2050 tp->tprint.dt = spi_dt(starget);
2051 tp->tprint.qas = spi_qas(starget);
2052 tp->tprint.check_nego = 1;
2064 struct sym_tcb *tp = &np->target[target];
2065 struct scsi_target *starget = tp->starget;
2070 tp->tgoal.renego = NS_WIDE;
2072 tp->tgoal.renego = 0;
2073 tp->tgoal.check_nego = 0;
2074 tp->tgoal.width = wide;
2094 struct sym_tcb *tp = &np->target[target];
2095 struct scsi_target *starget = tp->starget;
2096 u_char wide = (tp->head.wval & EWS) ? BUS_16_BIT : BUS_8_BIT;
2101 tp->tgoal.renego = NS_WIDE;
2103 tp->tgoal.renego = NS_SYNC;
2105 tp->tgoal.renego = 0;
2110 if (!tp->tgoal.dt && !tp->tgoal.iu && !tp->tgoal.qas) {
2111 tp->tgoal.period = per;
2112 tp->tgoal.offset = ofs;
2113 tp->tgoal.check_nego = 0;
2127 struct sym_tcb *tp = &np->target[target];
2128 struct scsi_target *starget = tp->starget;
2133 tp->tgoal.renego = NS_PPR;
2135 tp->tgoal.renego = 0;
2136 spi_width(starget) = tp->tgoal.width = wide;
2137 spi_period(starget) = tp->tgoal.period = per;
2138 spi_offset(starget) = tp->tgoal.offset = ofs;
2139 spi_iu(starget) = tp->tgoal.iu = !!(opts & PPR_OPT_IU);
2140 spi_dt(starget) = tp->tgoal.dt = !!(opts & PPR_OPT_DT);
2141 spi_qas(starget) = tp->tgoal.qas = !!(opts & PPR_OPT_QAS);
2142 tp->tgoal.check_nego = 0;
2192 OUTB(np, nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */
2201 cp->host_status = hsts;
2248 * spi2-r12 11.2.3 says a transceiver mode change must
2264 sym_scsi_bus_mode(np->scsi_mode), sym_scsi_bus_mode(scsi_mode));
2282 * - The complete scatter entry has been transferred
2287 * - A phase mismatch occurs before the MOV finished
2292 * - A phase mismatch occurs before the MOV finished and
2338 cp->xerr_status |= XE_PARITY_ERR;
2343 np->msgout[0] = (phase == 7) ? M_PARITY : M_ID_ERROR;
2348 * For other input phases (MSG IN and STATUS), the device
2366 #if 1 /* in message-in phase due to the relection */
2425 if (np->features & FE_DFBC)
2431 * Read DFIFO, CTEST[4-6] using 1 PCI bus ownership.
2441 (dfifo & 0xff)) - rest) & 0x3ff;
2443 delta = ((dfifo & 0xff) - rest) & 0x7f;
2448 * the target -> add the amount to the rest
2455 if (!(np->features & FE_C10))
2457 if (cp && (cp->phys.select.sel_scntl3 & EWS)) {
2460 if (!(np->features & FE_C10))
2467 OUTB(np, nc_ctest3, np->rv_ctest3 | CLF); /* dma fifo */
2484 if (dsp > np->scripta_ba &&
2485 dsp <= np->scripta_ba + np->scripta_sz) {
2486 vdsp = (u32 *)((char*)np->scripta0 + (dsp-np->scripta_ba-8));
2489 else if (dsp > np->scriptb_ba &&
2490 dsp <= np->scriptb_ba + np->scriptb_sz) {
2491 vdsp = (u32 *)((char*)np->scriptb0 + (dsp-np->scriptb_ba-8));
2521 tblp = (u32 *) ((char*) &cp->phys + oadr);
2543 sym_print_addr(cp->cmd,
2554 sym_print_addr(cp->cmd,
2555 "phase change %x-%x %d@%08x resid=%d.\n",
2574 nxtdsp = scr_to_cpu(cp->phys.pm0.ret);
2576 nxtdsp = scr_to_cpu(cp->phys.pm1.ret);
2583 pm = &cp->phys.pm0;
2587 pm = &cp->phys.pm1;
2598 pm->sg.addr = cpu_to_scr(oadr + olen - rest);
2599 pm->sg.size = cpu_to_scr(rest);
2600 pm->ret = cpu_to_scr(nxtdsp);
2604 * - prepare the address to write the SWIDE from SCRIPTS,
2605 * - compute the SCRIPTS address to restart from,
2606 * - move current data pointer context by one byte.
2609 if ((cmd & 7) == 1 && cp && (cp->phys.select.sel_scntl3 & EWS) &&
2618 tmp = scr_to_cpu(pm->sg.addr);
2619 cp->phys.wresid.addr = cpu_to_scr(tmp);
2620 pm->sg.addr = cpu_to_scr(tmp + 1);
2621 tmp = scr_to_cpu(pm->sg.size);
2622 cp->phys.wresid.size = cpu_to_scr((tmp&0xff000000) | 1);
2623 pm->sg.size = cpu_to_scr(tmp - 1);
2630 newcmd = pm->ret;
2640 sym_print_addr(cp->cmd, "PM %x %x %x / %x %x %x.\n",
2642 (unsigned)scr_to_cpu(pm->sg.addr),
2643 (unsigned)scr_to_cpu(pm->sg.size),
2644 (unsigned)scr_to_cpu(pm->ret));
2662 * COMMAND --> MSG IN SCSI parity error detected by target.
2663 * COMMAND --> STATUS Bad command or refused by target.
2664 * MSG OUT --> MSG IN Message rejected by target.
2665 * MSG OUT --> COMMAND Bogus target that discards extended
2674 * messages and clears the negotiation status.
2682 dsp -= 8;
2690 case 3: /* STATUS phase */
2702 if (cp->tag != NO_TAG && olen - rest <= 3) {
2703 cp->host_status = HS_BUSY;
2704 np->msgout[0] = IDENTIFY(0, cp->lun);
2715 struct scsi_device *dev = cp->cmd->device;
2716 dev->ppr = 0;
2755 * - SCSI parity error + Phase mismatch (PAR|MA)
2757 * and the device switches to msg-in phase inside a
2759 * - SCSI parity error + Unexpected disconnect (PAR|UDC)
2762 * - Some combinations of STO, PAR, UDC, ...
2795 * ask me for any guarantee that it will never fail. :-)
2802 struct sym_hcb *np = sym_data->ncb;
2803 struct pci_dev *pdev = sym_data->pdev;
2821 OUTB(np, nc_istat, (istat & SIGP) | INTF | np->istat_sem);
2907 * active CCBs with RESET status, prepare all devices
2909 * On STO and UDC, we complete the CCB with the corres-
2910 * ponding status and restart the SCRIPTS.
2918 OUTB(np, nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */
2958 * a given target/lun/task condition (-1 means all),
2960 * with DID_SOFT_ERROR status condition.
2980 while (i != np->squeueput) {
2981 cp = sym_ccb_from_dsa(np, scr_to_cpu(np->squeue[i]));
2985 cp->host_flags &= ~HF_HINT_IARB;
2987 if ((target == -1 || cp->target == target) &&
2988 (lun == -1 || cp->lun == lun) &&
2989 (task == -1 || cp->tag == task)) {
2991 sym_set_cam_status(cp->cmd, DID_SOFT_ERROR);
2993 sym_set_cam_status(cp->cmd, DID_REQUEUE);
2995 sym_remque(&cp->link_ccbq);
2996 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq);
3000 np->squeue[j] = np->squeue[i];
3006 np->squeue[j] = np->squeue[i];
3007 np->squeueput = j; /* Update our current start queue pointer */
3009 return (i - j) / 2;
3013 * chip handler for bad SCSI status condition
3015 * In case of bad SCSI status, we unqueue all the tasks
3023 * For CHECK CONDITION and COMMAND TERMINATED status, we use
3033 u_char s_status = cp->ssss_status;
3034 u_char h_flags = cp->host_flags;
3041 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
3048 if (np->last_cp)
3049 np->last_cp = 0;
3053 * Now deal with the SCSI status.
3059 sym_print_addr(cp->cmd, "%s\n",
3080 sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1);
3087 cp->sv_scsi_status = cp->ssss_status;
3088 cp->sv_xerr_status = cp->xerr_status;
3089 cp->sv_resid = sym_compute_residual(np, cp);
3096 cp->scsi_smsg2[0] = IDENTIFY(0, cp->lun);
3107 * cp->nego_status is filled by sym_prepare_nego().
3109 cp->nego_status = 0;
3110 msglen += sym_prepare_nego(np, cp, &cp->scsi_smsg2[msglen]);
3114 cp->phys.smsg.addr = CCB_BA(cp, scsi_smsg2);
3115 cp->phys.smsg.size = cpu_to_scr(msglen);
3120 cp->phys.cmd.addr = CCB_BA(cp, sensecmd);
3121 cp->phys.cmd.size = cpu_to_scr(6);
3126 cp->sensecmd[0] = REQUEST_SENSE;
3127 cp->sensecmd[1] = 0;
3128 if (cp->cmd->device->scsi_level <= SCSI_2 && cp->lun <= 7)
3129 cp->sensecmd[1] = cp->lun << 5;
3130 cp->sensecmd[4] = SYM_SNS_BBUF_LEN;
3131 cp->data_len = SYM_SNS_BBUF_LEN;
3136 memset(cp->sns_bbuf, 0, SYM_SNS_BBUF_LEN);
3137 cp->phys.sense.addr = CCB_BA(cp, sns_bbuf);
3138 cp->phys.sense.size = cpu_to_scr(SYM_SNS_BBUF_LEN);
3145 cp->phys.head.savep = cpu_to_scr(startp);
3146 cp->phys.head.lastp = cpu_to_scr(startp);
3147 cp->startp = cpu_to_scr(startp);
3148 cp->goalp = cpu_to_scr(startp + 16);
3150 cp->host_xflags = 0;
3151 cp->host_status = cp->nego_status ? HS_NEGOTIATE : HS_BUSY;
3152 cp->ssss_status = S_ILLEGAL;
3153 cp->host_flags = (HF_SENSE|HF_DATA_IN);
3154 cp->xerr_status = 0;
3155 cp->extra_bytes = 0;
3157 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA(np, select));
3183 * - lun=-1 means any logical UNIT otherwise a given one.
3184 * - task=-1 means any task, otherwise a given one.
3196 sym_que_splice(&np->busy_ccbq, &qtmp);
3197 sym_que_init(&np->busy_ccbq);
3207 cmd = cp->cmd;
3208 if (cp->host_status != HS_DISCONNECT ||
3209 cp->target != target ||
3210 (lun != -1 && cp->lun != lun) ||
3211 (task != -1 &&
3212 (cp->tag != NO_TAG && cp->scsi_smsg[2] != task))) {
3213 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
3216 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq);
3251 * - If nothing, we just sent a M_ABORT message to the
3254 * - If the target is to be reset, we send it a M_RESET
3256 * - If a logical UNIT is to be cleared , we send the
3258 * - If an untagged task is to be aborted, we send the
3260 * - If a tagged task is to be aborted, we send the
3275 int target=-1, lun=-1, task;
3289 tp = &np->target[i];
3290 if (tp->to_reset ||
3291 (tp->lun0p && tp->lun0p->to_clear)) {
3295 if (!tp->lunmp)
3298 if (tp->lunmp[k] && tp->lunmp[k]->to_clear) {
3303 if (target != -1)
3311 if (target == -1) {
3312 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
3314 if (cp->host_status != HS_DISCONNECT)
3316 if (cp->to_abort) {
3317 target = cp->target;
3327 if (target != -1) {
3328 tp = &np->target[target];
3329 np->abrt_sel.sel_id = target;
3330 np->abrt_sel.sel_scntl3 = tp->head.wval;
3331 np->abrt_sel.sel_sxfer = tp->head.sval;
3332 OUTL(np, nc_dsa, np->hcb_ba);
3344 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
3346 if (cp->host_status != HS_BUSY &&
3347 cp->host_status != HS_NEGOTIATE)
3349 if (!cp->to_abort)
3357 if (cp == np->last_cp) {
3358 cp->to_abort = 0;
3371 np->istat_sem = 0;
3380 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
3381 i = sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1);
3387 assert(i && sym_get_cam_status(cp->cmd) == DID_SOFT_ERROR);
3389 sym_remque(&cp->link_ccbq);
3390 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq);
3393 * Keep track in cam status of the reason of the abort.
3395 if (cp->to_abort == 2)
3396 sym_set_cam_status(cp->cmd, DID_TIME_OUT);
3398 sym_set_cam_status(cp->cmd, DID_ABORT);
3411 tp = &np->target[target];
3413 np->abrt_tbl.addr = cpu_to_scr(vtobus(np->abrt_msg));
3420 if (tp->to_reset) {
3421 np->abrt_msg[0] = M_RESET;
3422 np->abrt_tbl.size = 1;
3423 tp->to_reset = 0;
3430 if (tp->lun0p && tp->lun0p->to_clear)
3432 else if (tp->lunmp) {
3434 if (tp->lunmp[k] && tp->lunmp[k]->to_clear) {
3445 if (lun != -1) {
3447 lp->to_clear = 0; /* We don't expect to fail here */
3448 np->abrt_msg[0] = IDENTIFY(0, lun);
3449 np->abrt_msg[1] = M_ABORT;
3450 np->abrt_tbl.size = 2;
3460 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
3462 if (cp->host_status != HS_DISCONNECT)
3464 if (cp->target != target)
3466 if (!cp->to_abort)
3480 np->abrt_msg[0] = M_ABORT;
3481 np->abrt_tbl.size = 1;
3489 np->abrt_msg[0] = IDENTIFY(0, cp->lun);
3497 if (cp->tag == NO_TAG) {
3498 np->abrt_msg[1] = M_ABORT;
3499 np->abrt_tbl.size = 2;
3501 np->abrt_msg[1] = cp->scsi_smsg[1];
3502 np->abrt_msg[2] = cp->scsi_smsg[2];
3503 np->abrt_msg[3] = M_ABORT_TAG;
3504 np->abrt_tbl.size = 4;
3511 if (cp->to_abort == 2)
3512 sym_set_cam_status(cp->cmd, DID_TIME_OUT);
3513 cp->to_abort = 0; /* We donnot expect to fail here */
3522 tp = &np->target[target];
3523 starget = tp->starget;
3528 if (np->abrt_msg[0] == M_ABORT)
3534 * - Reset everything to async 8 bit
3535 * - Tell ourself to negotiate next time :-)
3536 * - Prepare to clear all disconnected CCBs for
3537 * this target from our task list (lun=task=-1)
3539 lun = -1;
3540 task = -1;
3541 if (np->abrt_msg[0] == M_RESET) {
3542 tp->head.sval = 0;
3543 tp->head.wval = np->rv_scntl3;
3544 tp->head.uval = 0;
3551 tp->tgoal.check_nego = 1;
3552 tp->tgoal.renego = 0;
3559 * or an ABORT message :-)
3562 lun = np->abrt_msg[0] & 0x3f;
3563 if (np->abrt_msg[1] == M_ABORT_TAG)
3564 task = np->abrt_msg[2];
3571 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
3572 sym_dequeue_from_squeue(np, i, target, lun, -1);
3579 if (np->abrt_msg[0] == M_RESET)
3589 dev_info(&tp->starget->dev, "control msgout:");
3590 sym_printl_hex(np->abrt_msg, np->abrt_tbl.size);
3591 np->abrt_tbl.size = cpu_to_scr(np->abrt_tbl.size);
3611 * - dp_sg = SYM_CONF_MAX_SG
3613 * - dp_sg < SYM_CONF_MAX_SG
3616 * - dp_ofs < 0
3619 * - dp_ofs = 0
3641 pm = &cp->phys.pm0;
3643 pm = &cp->phys.pm1;
3648 dp_scr = scr_to_cpu(pm->ret);
3649 dp_ofs -= scr_to_cpu(pm->sg.size) & 0x00ffffff;
3653 * If we are auto-sensing, then we are done.
3655 if (cp->host_flags & HF_SENSE) {
3666 tmp = scr_to_cpu(cp->goalp);
3669 dp_sg -= (tmp - 8 - (int)dp_scr) / (2*4);
3670 dp_sgmin = SYM_CONF_MAX_SG - cp->segments;
3687 --dp_sg;
3688 tmp = scr_to_cpu(cp->phys.data[dp_sg].size);
3699 tmp = scr_to_cpu(cp->phys.data[dp_sg].size);
3700 dp_ofs -= (tmp & 0xffffff);
3720 if (dp_sg > cp->ext_sg ||
3721 (dp_sg == cp->ext_sg && dp_ofs > cp->ext_ofs)) {
3722 cp->ext_sg = dp_sg;
3723 cp->ext_ofs = dp_ofs;
3733 return -1;
3742 * is equivalent to a MODIFY DATA POINTER (offset=-1).
3756 * Not supported for auto-sense.
3758 if (cp->host_flags & HF_SENSE)
3773 dp_ret = cpu_to_scr(cp->goalp);
3774 dp_ret = dp_ret - 8 - (SYM_CONF_MAX_SG - dp_sg) * (2*4);
3794 pm = &cp->phys.pm0;
3798 pm = &cp->phys.pm1;
3810 * corresponding to index dp_sg-1 prior to returning
3813 pm->ret = cpu_to_scr(dp_ret);
3814 tmp = scr_to_cpu(cp->phys.data[dp_sg-1].addr);
3815 tmp += scr_to_cpu(cp->phys.data[dp_sg-1].size) + dp_ofs;
3816 pm->sg.addr = cpu_to_scr(tmp);
3817 pm->sg.size = cpu_to_scr(-dp_ofs);
3854 * than our residual be zero. :-)
3856 if (cp->xerr_status & (XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN)) {
3857 if (cp->xerr_status & XE_EXTRA_DATA)
3858 resid -= cp->extra_bytes;
3859 if (cp->xerr_status & XE_SODL_UNRUN)
3861 if (cp->xerr_status & XE_SWIDE_OVRUN)
3862 --resid;
3869 if (cp->phys.head.lastp == cp->goalp)
3876 if (cp->startp == cp->phys.head.lastp ||
3877 sym_evaluate_dp(np, cp, scr_to_cpu(cp->phys.head.lastp),
3879 return cp->data_len - cp->odd_byte_adjustment;
3883 * If we were auto-sensing, then we are done.
3885 if (cp->host_flags & HF_SENSE) {
3886 return -dp_ofs;
3893 resid = -cp->ext_ofs;
3894 for (dp_sg = cp->ext_sg; dp_sg < SYM_CONF_MAX_SG; ++dp_sg) {
3895 u_int tmp = scr_to_cpu(cp->phys.data[dp_sg].size);
3899 resid -= cp->odd_byte_adjustment;
3912 * The host status field is set to HS_NEGOTIATE to mark this
3918 * The handler removes the HS_NEGOTIATE status, and sets the
3947 int target = cp->target;
3948 u_char chg, ofs, per, fak, div; local
3951 sym_print_nego_msg(np, target, "sync msgin", np->msgin);
3957 chg = 0;
3958 per = np->msgin[3];
3959 ofs = np->msgin[4];
3965 if (ofs > np->maxoffs)
3966 {chg = 1; ofs = np->maxoffs;}
3970 if (per < np->minsync)
3971 {chg = 1; per = np->minsync;}
3982 sym_print_addr(cp->cmd,
3983 "sdtr: ofs=%d per=%d div=%d fak=%d chg=%d.\n",
3984 ofs, per, div, fak, chg);
3991 if (!req && chg)
4008 spi_populate_sync_msg(np->msgout, per, ofs);
4011 sym_print_nego_msg(np, target, "sync msgout", np->msgout);
4014 np->msgin [0] = M_NOOP;
4020 return -1;
4033 if (cp->nego_status && cp->nego_status != NS_SYNC)
4045 cp->nego_status = NS_SYNC;
4062 struct sym_tcb *tp = &np->target[target];
4064 int dt, chg = 0; local
4066 unsigned char per = np->msgin[3];
4067 unsigned char ofs = np->msgin[5];
4068 unsigned char wide = np->msgin[6];
4069 unsigned char opts = np->msgin[7] & PPR_OPT_MASK;
4072 sym_print_nego_msg(np, target, "ppr msgin", np->msgin);
4078 if (wide > np->maxwide) {
4079 chg = 1;
4080 wide = np->maxwide;
4082 if (!wide || !(np->features & FE_U3EN))
4085 if (opts != (np->msgin[7] & PPR_OPT_MASK))
4086 chg = 1;
4091 unsigned char maxoffs = dt ? np->maxoffs_dt : np->maxoffs;
4093 chg = 1;
4099 unsigned char minsync = dt ? np->minsync_dt : np->minsync;
4101 chg = 1;
4117 if (!req && chg)
4134 spi_populate_ppr_msg(np->msgout, per, ofs, wide, opts);
4137 sym_print_nego_msg(np, target, "ppr msgout", np->msgout);
4140 np->msgin [0] = M_NOOP;
4151 tp->tgoal.period = per;
4152 tp->tgoal.offset = ofs;
4153 tp->tgoal.width = wide;
4154 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
4155 tp->tgoal.check_nego = 1;
4157 return -1;
4170 if (cp->nego_status && cp->nego_status != NS_PPR)
4178 result = sym_ppr_nego_check(np, req, cp->target);
4182 cp->nego_status = NS_PPR;
4199 int target = cp->target;
4200 u_char chg, wide; local
4203 sym_print_nego_msg(np, target, "wide msgin", np->msgin);
4209 chg = 0;
4210 wide = np->msgin[3];
4215 if (wide > np->maxwide) {
4216 chg = 1;
4217 wide = np->maxwide;
4221 sym_print_addr(cp->cmd, "wdtr: wide=%d chg=%d.\n",
4222 wide, chg);
4229 if (!req && chg)
4246 spi_populate_width_msg(np->msgout, wide);
4248 np->msgin [0] = M_NOOP;
4251 sym_print_nego_msg(np, target, "wide msgout", np->msgout);
4257 return -1;
4270 if (cp->nego_status && cp->nego_status != NS_WIDE)
4282 cp->nego_status = NS_WIDE;
4290 if (tp->tgoal.offset) {
4291 spi_populate_sync_msg(np->msgout, tp->tgoal.period,
4292 tp->tgoal.offset);
4295 sym_print_nego_msg(np, cp->target,
4296 "sync msgout", np->msgout);
4299 cp->nego_status = NS_SYNC;
4326 switch (cp->nego_status) {
4329 sym_setpprot (np, cp->target, 0, 0, 0, 0, 0, 0);
4331 if (tp->tgoal.period < np->minsync)
4332 tp->tgoal.period = np->minsync;
4333 if (tp->tgoal.offset > np->maxoffs)
4334 tp->tgoal.offset = np->maxoffs;
4335 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
4336 tp->tgoal.check_nego = 1;
4340 sym_setsync (np, cp->target, 0, 0, 0, 0);
4343 sym_setwide (np, cp->target, 0);
4346 np->msgin [0] = M_NOOP;
4347 np->msgout[0] = M_NOOP;
4348 cp->nego_status = 0;
4363 scmd_printk(lvl, cp->cmd, fmt, ##v); \
4365 starget_printk(lvl, tp->starget, fmt, ##v); \
4377 struct sym_tcb *tp = &np->target[target];
4394 * or has been auto-sensed.
4436 np->msgout[0] = M_RESET;
4443 np->msgout[0] = M_ABORT;
4449 np->msgout[0] = M_ABORT_TAG;
4456 np->lastmsg = np->msgout[0];
4457 np->msgout[0] = M_NOOP;
4459 "message %x sent on bad reselection\n", np->lastmsg);
4466 np->lastmsg = np->msgout[0];
4467 np->msgout[0] = M_NOOP;
4469 if (np->lastmsg == M_PARITY || np->lastmsg == M_ID_ERROR) {
4471 cp->xerr_status &= ~XE_PARITY_ERR;
4472 if (!cp->xerr_status)
4478 * The device didn't send a GOOD SCSI status.
4492 sym_print_msg(cp, "M_REJECT to send for ", np->msgin);
4493 np->msgout[0] = M_REJECT;
4504 cp->xerr_status |= XE_SWIDE_OVRUN;
4515 cp->xerr_status |= XE_SODL_UNRUN;
4527 cp->xerr_status |= XE_EXTRA_DATA;
4528 cp->extra_bytes += INL(np, nc_scratcha);
4537 cp->xerr_status |= XE_BAD_PHASE;
4546 switch (np->msgin [0]) {
4553 switch (np->msgin [2]) {
4557 np->msgin);
4558 tmp = (np->msgin[3]<<24) + (np->msgin[4]<<16) +
4559 (np->msgin[5]<<8) + (np->msgin[6]);
4580 * WIDE RESIDUE messages are aliased as MODIFY DP (-1).
4584 sym_print_msg(cp, "1 or 2 byte ", np->msgin);
4585 if (cp->host_flags & HF_SENSE)
4588 sym_modify_dp(np, tp, cp, -1);
4594 sym_print_addr(cp->cmd,
4596 scr_to_cpu(np->lastmsg), np->msgout[0]);
4608 sym_print_msg(cp, "WEIRD message received", np->msgin);
4614 * Remove the HS_NEGOTIATE status.
4646 u_char tn = cmd->device->id;
4647 u_char ln = cmd->device->lun;
4648 struct sym_tcb *tp = &np->target[tn];
4657 if (sym_que_empty(&np->free_ccbq))
4659 qp = sym_remque_head(&np->free_ccbq);
4673 if (lp->busy_itl != 0)
4679 if (!lp->cb_tags) {
4681 if (!lp->cb_tags)
4690 if (lp->busy_itlq < SYM_CONF_MAX_TASK) {
4691 tag = lp->cb_tags[lp->ia_tag];
4692 if (++lp->ia_tag == SYM_CONF_MAX_TASK)
4693 lp->ia_tag = 0;
4694 ++lp->busy_itlq;
4696 lp->itlq_tbl[tag] = cpu_to_scr(cp->ccb_ba);
4697 lp->head.resel_sa =
4701 cp->tags_si = lp->tags_si;
4702 ++lp->tags_sum[cp->tags_si];
4703 ++lp->tags_since;
4719 if (lp->busy_itl != 0 || lp->busy_itlq != 0)
4727 ++lp->busy_itl;
4729 if (lp->busy_itl == 1) {
4730 lp->head.itl_task_sa = cpu_to_scr(cp->ccb_ba);
4731 lp->head.resel_sa =
4742 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
4745 sym_remque(&cp->link2_ccbq);
4746 sym_insque_tail(&cp->link2_ccbq, &lp->waiting_ccbq);
4750 cp->to_abort = 0;
4751 cp->odd_byte_adjustment = 0;
4752 cp->tag = tag;
4753 cp->order = tag_order;
4754 cp->target = tn;
4755 cp->lun = ln;
4764 sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
4773 struct sym_tcb *tp = &np->target[cp->target];
4774 struct sym_lcb *lp = sym_lp(tp, cp->lun);
4777 sym_print_addr(cp->cmd, "ccb @%p freeing tag %d.\n",
4778 cp, cp->tag);
4788 if (cp->tag != NO_TAG) {
4790 --lp->tags_sum[cp->tags_si];
4795 lp->cb_tags[lp->if_tag] = cp->tag;
4796 if (++lp->if_tag == SYM_CONF_MAX_TASK)
4797 lp->if_tag = 0;
4802 lp->itlq_tbl[cp->tag] = cpu_to_scr(np->bad_itlq_ba);
4803 --lp->busy_itlq;
4809 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba);
4810 --lp->busy_itl;
4815 if (lp->busy_itlq == 0 && lp->busy_itl == 0)
4816 lp->head.resel_sa =
4825 if (cp == tp->nego_cp)
4826 tp->nego_cp = NULL;
4833 if (cp == np->last_cp)
4834 np->last_cp = 0;
4840 cp->cmd = NULL;
4841 cp->host_status = HS_IDLE;
4842 sym_remque(&cp->link_ccbq);
4843 sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
4847 sym_remque(&cp->link2_ccbq);
4848 sym_insque_tail(&cp->link2_ccbq, &np->dummy_ccbq);
4849 if (cp->started) {
4850 if (cp->tag != NO_TAG)
4851 --lp->started_tags;
4853 --lp->started_no_tag;
4856 cp->started = 0;
4872 if (np->actccbs >= SYM_CONF_MAX_START)
4885 np->actccbs++;
4890 cp->ccb_ba = vtobus(cp);
4895 hcode = CCB_HASH_CODE(cp->ccb_ba);
4896 cp->link_ccbh = np->ccbh[hcode];
4897 np->ccbh[hcode] = cp;
4902 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA(np, idle));
4903 cp->phys.head.go.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
4908 cp->phys.smsg_ext.addr = cpu_to_scr(HCB_BA(np, msgin[2]));
4913 sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
4919 sym_insque_head(&cp->link2_ccbq, &np->dummy_ccbq);
4937 cp = np->ccbh[hcode];
4939 if (cp->ccb_ba == dsa)
4941 cp = cp->link_ccbh;
4969 struct sym_tcb *tp = &np->target[tn];
4981 if (ln && !tp->luntbl) {
4982 tp->luntbl = sym_calloc_dma(256, "LUNTBL");
4983 if (!tp->luntbl)
4985 memset32(tp->luntbl, cpu_to_scr(vtobus(&np->badlun_sa)), 64);
4986 tp->head.luntbl_sa = cpu_to_scr(vtobus(tp->luntbl));
4992 if (ln && !tp->lunmp) {
4993 tp->lunmp = kcalloc(SYM_CONF_MAX_LUN, sizeof(struct sym_lcb *),
4995 if (!tp->lunmp)
5007 tp->lunmp[ln] = lp;
5008 tp->luntbl[ln] = cpu_to_scr(vtobus(lp));
5011 tp->lun0p = lp;
5012 tp->head.lun0_sa = cpu_to_scr(vtobus(lp));
5014 tp->nlcb++;
5019 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba);
5024 lp->head.resel_sa = cpu_to_scr(SCRIPTB_BA(np, resel_bad_lun));
5029 lp->user_flags = tp->usrflags & (SYM_DISC_ENABLED | SYM_TAGS_ENABLED);
5035 sym_que_init(&lp->waiting_ccbq);
5036 sym_que_init(&lp->started_ccbq);
5037 lp->started_max = SYM_CONF_MAX_TASK;
5038 lp->started_limit = SYM_CONF_MAX_TASK;
5050 struct sym_tcb *tp = &np->target[tn];
5058 lp->itlq_tbl = sym_calloc_dma(SYM_CONF_MAX_TASK*4, "ITLQ_TBL");
5059 if (!lp->itlq_tbl)
5061 lp->cb_tags = kcalloc(SYM_CONF_MAX_TASK, 1, GFP_ATOMIC);
5062 if (!lp->cb_tags) {
5063 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK*4, "ITLQ_TBL");
5064 lp->itlq_tbl = NULL;
5071 memset32(lp->itlq_tbl, cpu_to_scr(np->notask_ba), SYM_CONF_MAX_TASK);
5077 lp->cb_tags[i] = i;
5083 lp->head.itlq_tbl_sa = cpu_to_scr(vtobus(lp->itlq_tbl));
5096 struct sym_tcb *tp = &np->target[tn];
5099 tp->nlcb--;
5102 if (!tp->nlcb) {
5103 kfree(tp->lunmp);
5104 sym_mfree_dma(tp->luntbl, 256, "LUNTBL");
5105 tp->lunmp = NULL;
5106 tp->luntbl = NULL;
5107 tp->head.luntbl_sa = cpu_to_scr(vtobus(np->badluntbl));
5109 tp->luntbl[ln] = cpu_to_scr(vtobus(&np->badlun_sa));
5110 tp->lunmp[ln] = NULL;
5113 tp->lun0p = NULL;
5114 tp->head.lun0_sa = cpu_to_scr(vtobus(&np->badlun_sa));
5117 if (lp->itlq_tbl) {
5118 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK*4, "ITLQ_TBL");
5119 kfree(lp->cb_tags);
5124 return tp->nlcb;
5132 struct scsi_device *sdev = cmd->device;
5142 cp->cmd = cmd;
5147 tp = &np->target[cp->target];
5152 lp = sym_lp(tp, sdev->lun);
5154 can_disconnect = (cp->tag != NO_TAG) ||
5155 (lp && (lp->curr_flags & SYM_DISC_ENABLED));
5157 msgptr = cp->scsi_smsg;
5159 msgptr[msglen++] = IDENTIFY(can_disconnect, sdev->lun);
5164 if (cp->tag != NO_TAG) {
5165 u_char order = cp->order;
5182 if (lp && lp->tags_since > 3*SYM_CONF_MAX_TAG) {
5183 lp->tags_si = !(lp->tags_si);
5184 if (lp->tags_sum[lp->tags_si]) {
5191 lp->tags_since = 0;
5204 msgptr[msglen++] = cp->tag;
5206 msgptr[msglen++] = (cp->tag << 1) + 1;
5217 cp->nego_status = 0;
5218 if ((tp->tgoal.check_nego ||
5219 cmd->cmnd[0] == INQUIRY || cmd->cmnd[0] == REQUEST_SENSE) &&
5220 !tp->nego_cp && lp) {
5227 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA(np, select));
5228 cp->phys.head.go.restart = cpu_to_scr(SCRIPTA_BA(np, resel_dsa));
5233 cp->phys.select.sel_id = cp->target;
5234 cp->phys.select.sel_scntl3 = tp->head.wval;
5235 cp->phys.select.sel_sxfer = tp->head.sval;
5236 cp->phys.select.sel_scntl4 = tp->head.uval;
5241 cp->phys.smsg.addr = CCB_BA(cp, scsi_smsg);
5242 cp->phys.smsg.size = cpu_to_scr(msglen);
5245 * status
5247 cp->host_xflags = 0;
5248 cp->host_status = cp->nego_status ? HS_NEGOTIATE : HS_BUSY;
5249 cp->ssss_status = S_ILLEGAL;
5250 cp->xerr_status = 0;
5251 cp->host_flags = 0;
5252 cp->extra_bytes = 0;
5256 * shall be positive, so -1 is lower than lowest.:)
5258 cp->ext_sg = -1;
5259 cp->ext_ofs = 0;
5275 if (target == np->myaddr || (u_int)target >= SYM_CONF_MAX_TARGET)
5276 return -1;
5278 tp = &np->target[target];
5279 tp->to_reset = 1;
5281 np->istat_sem = SEM;
5295 if (!cp || !cp->host_status || cp->host_status == HS_WAIT)
5296 return -1;
5302 if (cp->to_abort) {
5310 cp->to_abort = timed_out ? 2 : 1;
5315 np->istat_sem = SEM;
5329 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
5331 if (cp2->cmd == cmd) {
5342 * error, SCSI status error, or having been auto-sensed.
5364 if (!cp || !cp->cmd)
5367 cmd = cp->cmd;
5368 sdev = cmd->device;
5370 dev_info(&sdev->sdev_gendev, "CCB=%p STAT=%x/%x/%x\n", cp,
5371 cp->host_status, cp->ssss_status, cp->host_flags);
5378 tp = &np->target[cp->target];
5379 lp = sym_lp(tp, sdev->lun);
5385 if (cp->xerr_status) {
5387 sym_print_xerr(cmd, cp->xerr_status);
5388 if (cp->host_status == HS_COMPLETE)
5389 cp->host_status = HS_COMP_ERR;
5399 cp->sv_resid = 0;
5403 printf("XXXX RESID= %d - 0x%x\n", resid, resid);
5410 i = (INL(np, nc_scratcha) - np->squeue_ba) / 4;
5411 i = sym_dequeue_from_squeue(np, i, cp->target, sdev->lun, -1);
5419 if (cp->host_status == HS_COMPLETE &&
5420 cp->ssss_status == S_QUEUE_FULL) {
5421 if (!lp || lp->started_tags - i < 2)
5426 lp->started_max = lp->started_tags - i - 1;
5427 lp->num_sgood = 0;
5431 lp->started_max);
5437 cp->host_status = HS_BUSY;
5438 cp->ssss_status = S_ILLEGAL;
5459 sym_remque(&cp->link_ccbq);
5460 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;
5510 tp = &np->target[cp->target];
5511 lp = sym_lp(tp, cp->lun);
5519 if (cp->phys.head.lastp != cp->goalp)
5531 printf("XXXX RESID= %d - 0x%x\n", resid, resid);
5542 * increase it if 200 good status received.
5544 if (lp && lp->started_max < lp->started_limit) {
5545 ++lp->num_sgood;
5546 if (lp->num_sgood >= 200) {
5547 lp->num_sgood = 0;
5548 ++lp->started_max;
5551 lp->started_max);
5566 if (!sym_que_empty(&lp->waiting_ccbq))
5576 * Soft-attach the controller.
5586 np->scripta_sz = fw->a_size;
5587 np->scriptb_sz = fw->b_size;
5588 np->scriptz_sz = fw->z_size;
5589 np->fw_setup = fw->setup;
5590 np->fw_patch = fw->patch;
5591 np->fw_name = fw->name;
5608 * to chip features, user set-up and driver set-up.
5618 if (i > 37000 && !(np->features & FE_66MHZ))
5625 np->squeue = sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"SQUEUE");
5626 if (!np->squeue)
5628 np->squeue_ba = vtobus(np->squeue);
5633 np->dqueue = sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"DQUEUE");
5634 if (!np->dqueue)
5636 np->dqueue_ba = vtobus(np->dqueue);
5641 np->targtbl = sym_calloc_dma(256, "TARGTBL");
5642 if (!np->targtbl)
5644 np->targtbl_ba = vtobus(np->targtbl);
5649 np->scripta0 = sym_calloc_dma(np->scripta_sz, "SCRIPTA0");
5650 np->scriptb0 = sym_calloc_dma(np->scriptb_sz, "SCRIPTB0");
5651 np->scriptz0 = sym_calloc_dma(np->scriptz_sz, "SCRIPTZ0");
5652 if (!np->scripta0 || !np->scriptb0 || !np->scriptz0)
5658 np->ccbh = kcalloc(CCB_HASH_SIZE, sizeof(*np->ccbh), GFP_KERNEL);
5659 if (!np->ccbh)
5665 sym_que_init(&np->free_ccbq);
5666 sym_que_init(&np->busy_ccbq);
5667 sym_que_init(&np->comp_ccbq);
5674 sym_que_init(&np->dummy_ccbq);
5686 np->scripta_ba = vtobus(np->scripta0);
5687 np->scriptb_ba = vtobus(np->scriptb0);
5688 np->scriptz_ba = vtobus(np->scriptz0);
5690 if (np->ram_ba) {
5691 np->scripta_ba = np->ram_ba;
5692 if (np->features & FE_RAM8K) {
5693 np->scriptb_ba = np->scripta_ba + 4096;
5695 np->scr_ram_seg = cpu_to_scr(np->scripta_ba >> 32);
5703 memcpy(np->scripta0, fw->a_base, np->scripta_sz);
5704 memcpy(np->scriptb0, fw->b_base, np->scriptb_sz);
5705 memcpy(np->scriptz0, fw->z_base, np->scriptz_sz);
5711 np->fw_setup(np, fw);
5717 sym_fw_bind_script(np, (u32 *) np->scripta0, np->scripta_sz);
5718 sym_fw_bind_script(np, (u32 *) np->scriptb0, np->scriptb_sz);
5719 sym_fw_bind_script(np, (u32 *) np->scriptz0, np->scriptz_sz);
5729 np->iarb_max = SYM_SETUP_IARB_MAX;
5731 np->iarb_max = 4;
5738 np->idletask.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5739 np->idletask.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
5740 np->idletask_ba = vtobus(&np->idletask);
5742 np->notask.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5743 np->notask.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
5744 np->notask_ba = vtobus(&np->notask);
5746 np->bad_itl.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5747 np->bad_itl.restart = cpu_to_scr(SCRIPTB_BA(np, bad_i_t_l));
5748 np->bad_itl_ba = vtobus(&np->bad_itl);
5750 np->bad_itlq.start = cpu_to_scr(SCRIPTA_BA(np, idle));
5751 np->bad_itlq.restart = cpu_to_scr(SCRIPTB_BA(np,bad_i_t_l_q));
5752 np->bad_itlq_ba = vtobus(&np->bad_itlq);
5760 np->badluntbl = sym_calloc_dma(256, "BADLUNTBL");
5761 if (!np->badluntbl)
5764 np->badlun_sa = cpu_to_scr(SCRIPTB_BA(np, resel_bad_lun));
5765 memset32(np->badluntbl, cpu_to_scr(vtobus(&np->badlun_sa)), 64);
5773 np->targtbl[i] = cpu_to_scr(vtobus(&np->target[i]));
5774 np->target[i].head.luntbl_sa =
5775 cpu_to_scr(vtobus(np->badluntbl));
5776 np->target[i].head.lun0_sa =
5777 cpu_to_scr(vtobus(&np->badlun_sa));
5794 return -ENXIO;
5807 if (np->scriptz0)
5808 sym_mfree_dma(np->scriptz0, np->scriptz_sz, "SCRIPTZ0");
5809 if (np->scriptb0)
5810 sym_mfree_dma(np->scriptb0, np->scriptb_sz, "SCRIPTB0");
5811 if (np->scripta0)
5812 sym_mfree_dma(np->scripta0, np->scripta_sz, "SCRIPTA0");
5813 if (np->squeue)
5814 sym_mfree_dma(np->squeue, sizeof(u32)*(MAX_QUEUE*2), "SQUEUE");
5815 if (np->dqueue)
5816 sym_mfree_dma(np->dqueue, sizeof(u32)*(MAX_QUEUE*2), "DQUEUE");
5818 if (np->actccbs) {
5819 while ((qp = sym_remque_head(&np->free_ccbq)) != NULL) {
5824 kfree(np->ccbh);
5826 if (np->badluntbl)
5827 sym_mfree_dma(np->badluntbl, 256,"BADLUNTBL");
5830 tp = &np->target[target];
5831 if (tp->luntbl)
5832 sym_mfree_dma(tp->luntbl, 256, "LUNTBL");
5834 kfree(tp->lunmp);
5837 if (np->targtbl)
5838 sym_mfree_dma(np->targtbl, 256, "TARGTBL");