Lines Matching full:np
324 #define sym_verbose (np->verbose)
749 #define _sym_calloc_dma(np, s, n) __sym_calloc_dma(np->bus_dmat, s, n) argument
750 #define _sym_mfree_dma(np, p, s, n) \ argument
751 __sym_mfree_dma(np->bus_dmat, _uvptv_(p), s, n)
752 #define sym_calloc_dma(s, n) _sym_calloc_dma(np, s, n)
753 #define sym_mfree_dma(p, s, n) _sym_mfree_dma(np, p, s, n)
754 #define _vtobus(np, p) __vtobus(np->bus_dmat, _uvptv_(p)) argument
755 #define vtobus(p) _vtobus(np, p)
847 #define INB_OFF(o) bus_read_1(np->io_res, (o))
848 #define INW_OFF(o) bus_read_2(np->io_res, (o))
849 #define INL_OFF(o) bus_read_4(np->io_res, (o))
851 #define OUTB_OFF(o, v) bus_write_1(np->io_res, (o), (v))
852 #define OUTW_OFF(o, v) bus_write_2(np->io_res, (o), (v))
853 #define OUTL_OFF(o, v) bus_write_4(np->io_res, (o), (v))
857 #define INB_OFF(o) bus_read_1(np->mmio_res, (o))
858 #define INW_OFF(o) bus_read_2(np->mmio_res, (o))
859 #define INL_OFF(o) bus_read_4(np->mmio_res, (o))
861 #define OUTB_OFF(o, v) bus_write_1(np->mmio_res, (o), (v))
862 #define OUTW_OFF(o, v) bus_write_2(np->mmio_res, (o), (v))
863 #define OUTL_OFF(o, v) bus_write_4(np->mmio_res, (o), (v))
868 bus_write_region_1(np->ram_res, (o), (a), (l))
1003 #define SYM_LOCK() mtx_lock(&np->mtx)
1004 #define SYM_LOCK_ASSERT(_what) mtx_assert(&np->mtx, (_what))
1005 #define SYM_LOCK_DESTROY() mtx_destroy(&np->mtx)
1006 #define SYM_LOCK_INIT() mtx_init(&np->mtx, "sym_lock", NULL, MTX_DEF)
1007 #define SYM_LOCK_INITIALIZED() mtx_initialized(&np->mtx)
1008 #define SYM_UNLOCK() mtx_unlock(&np->mtx)
1586 void (*fw_setup)(hcb_p np, const struct sym_fw *fw);
1587 void (*fw_patch)(hcb_p np);
1696 #define HCB_BA(np, lbl) (np->hcb_ba + offsetof(struct sym_hcb, lbl)) argument
1701 static __inline const char *sym_name(hcb_p np) in sym_name() argument
1703 return device_get_nameunit(np->device); in sym_name()
1767 sym_fw1_patch(hcb_p np) in sym_fw1_patch() argument
1772 scripta0 = (struct sym_fw1a_scr *) np->scripta0; in sym_fw1_patch()
1773 scriptb0 = (struct sym_fw1b_scr *) np->scriptb0; in sym_fw1_patch()
1778 if (!(np->features & FE_LED0)) { in sym_fw1_patch()
1798 scriptb0->startpos[0] = cpu_to_scr(np->squeue_ba); in sym_fw1_patch()
1799 scriptb0->done_pos[0] = cpu_to_scr(np->dqueue_ba); in sym_fw1_patch()
1800 scriptb0->targtbl[0] = cpu_to_scr(np->targtbl_ba); in sym_fw1_patch()
1808 sym_fw2_patch(hcb_p np) in sym_fw2_patch() argument
1813 scripta0 = (struct sym_fw2a_scr *) np->scripta0; in sym_fw2_patch()
1814 scriptb0 = (struct sym_fw2b_scr *) np->scriptb0; in sym_fw2_patch()
1819 if (!(np->features & FE_LED0)) { in sym_fw2_patch()
1839 scriptb0->startpos[0] = cpu_to_scr(np->squeue_ba); in sym_fw2_patch()
1840 scriptb0->done_pos[0] = cpu_to_scr(np->dqueue_ba); in sym_fw2_patch()
1841 scriptb0->targtbl[0] = cpu_to_scr(np->targtbl_ba); in sym_fw2_patch()
1846 if (!(np->features & FE_C10)) { in sym_fw2_patch()
1855 if (!(np->device_id == PCI_ID_LSI53C1010_2 && in sym_fw2_patch()
1856 np->revision_id < 0x1 && in sym_fw2_patch()
1857 np->pciclk_khz < 60000)) { in sym_fw2_patch()
1861 if (!(np->device_id == PCI_ID_LSI53C1010 && in sym_fw2_patch()
1862 /* np->revision_id < 0xff */ 1)) { in sym_fw2_patch()
1872 cpu_to_scr(np->scripta_ba + in sym_fw2_patch()
1875 cpu_to_scr(np->scripta_ba + in sym_fw2_patch()
1901 sym_fw_setup_bus_addresses(hcb_p np, const struct sym_fw *fw) in sym_fw_setup_bus_addresses() argument
1912 pa = (u32 *) &np->fwa_bas; in sym_fw_setup_bus_addresses()
1913 for (i = 0 ; i < sizeof(np->fwa_bas)/sizeof(u32) ; i++) in sym_fw_setup_bus_addresses()
1914 pa[i] = np->scripta_ba + po[i]; in sym_fw_setup_bus_addresses()
1920 pa = (u32 *) &np->fwb_bas; in sym_fw_setup_bus_addresses()
1921 for (i = 0 ; i < sizeof(np->fwb_bas)/sizeof(u32) ; i++) in sym_fw_setup_bus_addresses()
1922 pa[i] = np->scriptb_ba + po[i]; in sym_fw_setup_bus_addresses()
1930 sym_fw1_setup(hcb_p np, const struct sym_fw *fw) in sym_fw1_setup() argument
1934 scripta0 = (struct sym_fw1a_scr *) np->scripta0; in sym_fw1_setup()
1944 sym_fw_setup_bus_addresses(np, fw); in sym_fw1_setup()
1952 sym_fw2_setup(hcb_p np, const struct sym_fw *fw) in sym_fw2_setup() argument
1956 scripta0 = (struct sym_fw2a_scr *) np->scripta0; in sym_fw2_setup()
1966 sym_fw_setup_bus_addresses(np, fw); in sym_fw2_setup()
1996 static void sym_fw_bind_script (hcb_p np, u32 *start, int len) in sym_fw_bind_script() argument
2016 sym_name(np), (int) (cur-start)); in sym_fw_bind_script()
2060 sym_name(np), (int) (cur-start)); in sym_fw_bind_script()
2068 !(np->features & FE_PFEN)) { in sym_fw_bind_script()
2076 if (!(np->features & FE_WIDE)) in sym_fw_bind_script()
2084 if (!(np->features & FE_WIDE)) in sym_fw_bind_script()
2134 new = (old & ~RELOC_MASK) + np->mmio_ba; in sym_fw_bind_script()
2137 new = (old & ~RELOC_MASK) + np->scripta_ba; in sym_fw_bind_script()
2140 new = (old & ~RELOC_MASK) + np->scriptb_ba; in sym_fw_bind_script()
2143 new = (old & ~RELOC_MASK) + np->hcb_ba; in sym_fw_bind_script()
2175 static void sym_save_initial_setting (hcb_p np);
2176 static int sym_prepare_setting (hcb_p np, struct sym_nvram *nvram);
2177 static int sym_prepare_nego (hcb_p np, ccb_p cp, int nego, u_char *msgptr);
2178 static void sym_put_start_queue (hcb_p np, ccb_p cp);
2179 static void sym_chip_reset (hcb_p np);
2180 static void sym_soft_reset (hcb_p np);
2181 static void sym_start_reset (hcb_p np);
2182 static int sym_reset_scsi_bus (hcb_p np, int enab_int);
2183 static int sym_wakeup_done (hcb_p np);
2184 static void sym_flush_busy_queue (hcb_p np, int cam_status);
2185 static void sym_flush_comp_queue (hcb_p np, int cam_status);
2186 static void sym_init (hcb_p np, int reason);
2187 static int sym_getsync(hcb_p np, u_char dt, u_char sfac, u_char *divp,
2189 static void sym_setsync (hcb_p np, ccb_p cp, u_char ofs, u_char per,
2191 static void sym_setwide (hcb_p np, ccb_p cp, u_char wide);
2192 static void sym_setpprot(hcb_p np, ccb_p cp, u_char dt, u_char ofs,
2194 static void sym_settrans(hcb_p np, ccb_p cp, u_char dt, u_char ofs,
2196 static void sym_log_hard_error (hcb_p np, u_short sist, u_char dstat);
2199 static void sym_recover_scsi_int (hcb_p np, u_char hsts);
2200 static void sym_int_sto (hcb_p np);
2201 static void sym_int_udc (hcb_p np);
2202 static void sym_int_sbmc (hcb_p np);
2203 static void sym_int_par (hcb_p np, u_short sist);
2204 static void sym_int_ma (hcb_p np);
2205 static int sym_dequeue_from_squeue(hcb_p np, int i, int target, int lun,
2207 static void sym_sir_bad_scsi_status (hcb_p np, ccb_p cp);
2208 static int sym_clear_tasks (hcb_p np, int status, int targ, int lun, int task);
2209 static void sym_sir_task_recovery (hcb_p np, int num);
2210 static int sym_evaluate_dp (hcb_p np, ccb_p cp, u32 scr, int *ofs);
2211 static void sym_modify_dp(hcb_p np, ccb_p cp, int ofs);
2212 static int sym_compute_residual (hcb_p np, ccb_p cp);
2215 static void sym_sync_nego (hcb_p np, tcb_p tp, ccb_p cp);
2216 static void sym_ppr_nego (hcb_p np, tcb_p tp, ccb_p cp);
2217 static void sym_wide_nego (hcb_p np, tcb_p tp, ccb_p cp);
2218 static void sym_nego_default (hcb_p np, tcb_p tp, ccb_p cp);
2219 static void sym_nego_rejected (hcb_p np, tcb_p tp, ccb_p cp);
2220 static void sym_int_sir (hcb_p np);
2221 static void sym_free_ccb (hcb_p np, ccb_p cp);
2222 static ccb_p sym_get_ccb (hcb_p np, u_char tn, u_char ln, u_char tag_order);
2223 static ccb_p sym_alloc_ccb (hcb_p np);
2224 static ccb_p sym_ccb_from_dsa (hcb_p np, u32 dsa);
2225 static lcb_p sym_alloc_lcb (hcb_p np, u_char tn, u_char ln);
2226 static void sym_alloc_lcb_tags (hcb_p np, u_char tn, u_char ln);
2227 static int sym_snooptest (hcb_p np);
2228 static void sym_selectclock(hcb_p np, u_char scntl3);
2229 static void sym_getclock (hcb_p np, int mult);
2230 static int sym_getpciclock (hcb_p np);
2231 static void sym_complete_ok (hcb_p np, ccb_p cp);
2232 static void sym_complete_error (hcb_p np, ccb_p cp);
2234 static int sym_abort_scsiio (hcb_p np, union ccb *ccb, int timed_out);
2235 static void sym_reset_dev (hcb_p np, union ccb *ccb);
2237 static int sym_setup_cdb (hcb_p np, struct ccb_scsiio *csio, ccb_p cp);
2238 static void sym_setup_data_and_start (hcb_p np, struct ccb_scsiio *csio,
2240 static int sym_fast_scatter_sg_physical(hcb_p np, ccb_p cp,
2242 static int sym_scatter_sg_physical (hcb_p np, ccb_p cp,
2245 static void sym_update_trans(hcb_p np, struct sym_trans *tip,
2247 static void sym_update_dflags(hcb_p np, u_char *flags,
2254 static void sym_pci_free (hcb_p np);
2255 static int sym_cam_attach (hcb_p np);
2256 static void sym_cam_free (hcb_p np);
2258 static void sym_nvram_setup_host (hcb_p np, struct sym_nvram *nvram);
2259 static void sym_nvram_setup_target (hcb_p np, int targ, struct sym_nvram *nvp);
2260 static int sym_read_nvram (hcb_p np, struct sym_nvram *nvp);
2266 static void PRINT_TARGET (hcb_p np, int target) in PRINT_TARGET() argument
2268 printf ("%s:%d:", sym_name(np), target); in PRINT_TARGET()
2271 static void PRINT_LUN(hcb_p np, int target, int lun) in PRINT_LUN() argument
2273 printf ("%s:%d:%d:", sym_name(np), target, lun); in PRINT_LUN()
2317 hcb_p np; in sym_enqueue_cam_ccb() local
2321 np = (hcb_p) cp->arg; in sym_enqueue_cam_ccb()
2329 ccb->ccb_h.sym_hcb_ptr = np; in sym_enqueue_cam_ccb()
2331 sym_insque_tail(sym_qptr(&ccb->ccb_h.sim_links), &np->cam_ccbq); in sym_enqueue_cam_ccb()
2338 static void sym_xpt_done(hcb_p np, union ccb *ccb, ccb_p cp) in sym_xpt_done() argument
2352 static void sym_xpt_done2(hcb_p np, union ccb *ccb, int cam_status) in sym_xpt_done2() argument
2400 static __inline void sym_init_burst(hcb_p np, u_char bc) in sym_init_burst() argument
2402 np->rv_ctest4 &= ~0x80; in sym_init_burst()
2403 np->rv_dmode &= ~(0x3 << 6); in sym_init_burst()
2404 np->rv_ctest5 &= ~0x4; in sym_init_burst()
2407 np->rv_ctest4 |= 0x80; in sym_init_burst()
2411 np->rv_dmode |= ((bc & 0x3) << 6); in sym_init_burst()
2412 np->rv_ctest5 |= (bc & 0x4); in sym_init_burst()
2419 static void sym_print_targets_flag(hcb_p np, int mask, char *msg) in sym_print_targets_flag() argument
2425 if (i == np->myaddr) in sym_print_targets_flag()
2427 if (np->target[i].usrflags & mask) { in sym_print_targets_flag()
2430 sym_name(np), msg); in sym_print_targets_flag()
2447 static void sym_save_initial_setting (hcb_p np) in sym_save_initial_setting() argument
2449 np->sv_scntl0 = INB(nc_scntl0) & 0x0a; in sym_save_initial_setting()
2450 np->sv_scntl3 = INB(nc_scntl3) & 0x07; in sym_save_initial_setting()
2451 np->sv_dmode = INB(nc_dmode) & 0xce; in sym_save_initial_setting()
2452 np->sv_dcntl = INB(nc_dcntl) & 0xa8; in sym_save_initial_setting()
2453 np->sv_ctest3 = INB(nc_ctest3) & 0x01; in sym_save_initial_setting()
2454 np->sv_ctest4 = INB(nc_ctest4) & 0x80; in sym_save_initial_setting()
2455 np->sv_gpcntl = INB(nc_gpcntl); in sym_save_initial_setting()
2456 np->sv_stest1 = INB(nc_stest1); in sym_save_initial_setting()
2457 np->sv_stest2 = INB(nc_stest2) & 0x20; in sym_save_initial_setting()
2458 np->sv_stest4 = INB(nc_stest4); in sym_save_initial_setting()
2459 if (np->features & FE_C10) { /* Always large DMA fifo + ultra3 */ in sym_save_initial_setting()
2460 np->sv_scntl4 = INB(nc_scntl4); in sym_save_initial_setting()
2461 np->sv_ctest5 = INB(nc_ctest5) & 0x04; in sym_save_initial_setting()
2464 np->sv_ctest5 = INB(nc_ctest5) & 0x24; in sym_save_initial_setting()
2471 static int sym_prepare_setting(hcb_p np, struct sym_nvram *nvram) in sym_prepare_setting() argument
2480 np->maxwide = (np->features & FE_WIDE)? 1 : 0; in sym_prepare_setting()
2485 if (np->features & FE_QUAD) in sym_prepare_setting()
2486 np->multiplier = 4; in sym_prepare_setting()
2487 else if (np->features & FE_DBLR) in sym_prepare_setting()
2488 np->multiplier = 2; in sym_prepare_setting()
2490 np->multiplier = 1; in sym_prepare_setting()
2492 np->clock_khz = (np->features & FE_CLK80)? 80000 : 40000; in sym_prepare_setting()
2493 np->clock_khz *= np->multiplier; in sym_prepare_setting()
2495 if (np->clock_khz != 40000) in sym_prepare_setting()
2496 sym_getclock(np, np->multiplier); in sym_prepare_setting()
2501 i = np->clock_divn - 1; in sym_prepare_setting()
2503 if (10ul * SYM_CONF_MIN_ASYNC * np->clock_khz > div_10M[i]) { in sym_prepare_setting()
2508 np->rv_scntl3 = i+1; in sym_prepare_setting()
2514 if (np->features & FE_C10) in sym_prepare_setting()
2515 np->rv_scntl3 = 0; in sym_prepare_setting()
2521 period = howmany(4 * div_10M[0], np->clock_khz); in sym_prepare_setting()
2522 if (period <= 250) np->minsync = 10; in sym_prepare_setting()
2523 else if (period <= 303) np->minsync = 11; in sym_prepare_setting()
2524 else if (period <= 500) np->minsync = 12; in sym_prepare_setting()
2525 else np->minsync = howmany(period, 40); in sym_prepare_setting()
2530 if (np->minsync < 25 && in sym_prepare_setting()
2531 !(np->features & (FE_ULTRA|FE_ULTRA2|FE_ULTRA3))) in sym_prepare_setting()
2532 np->minsync = 25; in sym_prepare_setting()
2533 else if (np->minsync < 12 && in sym_prepare_setting()
2534 !(np->features & (FE_ULTRA2|FE_ULTRA3))) in sym_prepare_setting()
2535 np->minsync = 12; in sym_prepare_setting()
2540 period = (11 * div_10M[np->clock_divn - 1]) / (4 * np->clock_khz); in sym_prepare_setting()
2541 np->maxsync = period > 2540 ? 254 : period / 10; in sym_prepare_setting()
2546 if ((np->features & (FE_C10|FE_ULTRA3)) == (FE_C10|FE_ULTRA3)) { in sym_prepare_setting()
2547 if (np->clock_khz == 160000) { in sym_prepare_setting()
2548 np->minsync_dt = 9; in sym_prepare_setting()
2549 np->maxsync_dt = 50; in sym_prepare_setting()
2550 np->maxoffs_dt = 62; in sym_prepare_setting()
2557 if (np->features & FE_DAC) in sym_prepare_setting()
2559 np->rv_ccntl1 |= (XTIMOD | EXTIBMV); in sym_prepare_setting()
2561 np->rv_ccntl1 |= (DDAC); in sym_prepare_setting()
2567 if (np->features & FE_NOPM) in sym_prepare_setting()
2568 np->rv_ccntl0 |= (ENPMJ); in sym_prepare_setting()
2575 if (np->device_id == PCI_ID_LSI53C1010 && in sym_prepare_setting()
2576 np->revision_id < 0x2) in sym_prepare_setting()
2577 np->rv_ccntl0 |= DILS; in sym_prepare_setting()
2584 burst_max = burst_code(np->sv_dmode, np->sv_ctest4, in sym_prepare_setting()
2585 np->sv_ctest5); in sym_prepare_setting()
2588 if (burst_max > np->maxburst) in sym_prepare_setting()
2589 burst_max = np->maxburst; in sym_prepare_setting()
2599 if ((np->device_id == PCI_ID_SYM53C810 && in sym_prepare_setting()
2600 np->revision_id >= 0x10 && np->revision_id <= 0x11) || in sym_prepare_setting()
2601 (np->device_id == PCI_ID_SYM53C860 && in sym_prepare_setting()
2602 np->revision_id <= 0x1)) in sym_prepare_setting()
2603 np->features &= ~(FE_WRIE|FE_ERL|FE_ERMP); in sym_prepare_setting()
2611 if (np->features & FE_ERL) in sym_prepare_setting()
2612 np->rv_dmode |= ERL; /* Enable Read Line */ in sym_prepare_setting()
2613 if (np->features & FE_BOF) in sym_prepare_setting()
2614 np->rv_dmode |= BOF; /* Burst Opcode Fetch */ in sym_prepare_setting()
2615 if (np->features & FE_ERMP) in sym_prepare_setting()
2616 np->rv_dmode |= ERMP; /* Enable Read Multiple */ in sym_prepare_setting()
2618 if ((np->features & FE_PFEN) && !np->ram_ba) in sym_prepare_setting()
2620 if (np->features & FE_PFEN) in sym_prepare_setting()
2622 np->rv_dcntl |= PFEN; /* Prefetch Enable */ in sym_prepare_setting()
2623 if (np->features & FE_CLSE) in sym_prepare_setting()
2624 np->rv_dcntl |= CLSE; /* Cache Line Size Enable */ in sym_prepare_setting()
2625 if (np->features & FE_WRIE) in sym_prepare_setting()
2626 np->rv_ctest3 |= WRIE; /* Write and Invalidate */ in sym_prepare_setting()
2627 if (np->features & FE_DFS) in sym_prepare_setting()
2628 np->rv_ctest5 |= DFS; /* Dma Fifo Size */ in sym_prepare_setting()
2634 np->rv_ctest4 |= MPEE; /* Master parity checking */ in sym_prepare_setting()
2636 np->rv_scntl0 |= 0x0a; /* full arb., ena parity, par->ATN */ in sym_prepare_setting()
2641 np->myaddr = 255; in sym_prepare_setting()
2642 sym_nvram_setup_host (np, nvram); in sym_prepare_setting()
2647 if (np->myaddr == 255) { in sym_prepare_setting()
2648 np->myaddr = INB(nc_scid) & 0x07; in sym_prepare_setting()
2649 if (!np->myaddr) in sym_prepare_setting()
2650 np->myaddr = SYM_SETUP_HOST_ID; in sym_prepare_setting()
2656 sym_init_burst(np, burst_max); in sym_prepare_setting()
2666 np->scsi_mode = SMODE_SE; in sym_prepare_setting()
2667 if (np->features & (FE_ULTRA2|FE_ULTRA3)) in sym_prepare_setting()
2668 np->scsi_mode = (np->sv_stest4 & SMODE); in sym_prepare_setting()
2669 else if (np->features & FE_DIFF) { in sym_prepare_setting()
2671 if (np->sv_scntl3) { in sym_prepare_setting()
2672 if (np->sv_stest2 & 0x20) in sym_prepare_setting()
2673 np->scsi_mode = SMODE_HVD; in sym_prepare_setting()
2677 np->scsi_mode = SMODE_HVD; in sym_prepare_setting()
2681 np->scsi_mode = SMODE_HVD; in sym_prepare_setting()
2683 if (np->scsi_mode == SMODE_HVD) in sym_prepare_setting()
2684 np->rv_stest2 |= 0x20; in sym_prepare_setting()
2695 np->device_id == PCI_ID_SYM53C895))) && in sym_prepare_setting()
2696 !(np->features & FE_LEDC) && !(np->sv_gpcntl & 0x01)) in sym_prepare_setting()
2697 np->features |= FE_LED0; in sym_prepare_setting()
2704 np->rv_dcntl |= IRQM; in sym_prepare_setting()
2707 np->rv_dcntl |= (np->sv_dcntl & IRQM); in sym_prepare_setting()
2718 tcb_p tp = &np->target[i]; in sym_prepare_setting()
2722 tp->tinfo.user.period = np->minsync; in sym_prepare_setting()
2723 if (np->features & FE_ULTRA3) in sym_prepare_setting()
2724 tp->tinfo.user.period = np->minsync_dt; in sym_prepare_setting()
2725 tp->tinfo.user.offset = np->maxoffs; in sym_prepare_setting()
2726 tp->tinfo.user.width = np->maxwide ? BUS_16_BIT : BUS_8_BIT; in sym_prepare_setting()
2730 sym_nvram_setup_target (np, i, nvram); in sym_prepare_setting()
2736 if (np->features & FE_ULTRA3) { in sym_prepare_setting()
2740 tp->tinfo.user.offset = np->maxoffs_dt; in sym_prepare_setting()
2753 printf("%s: %s NVRAM, ID %d, Fast-%d, %s, %s\n", sym_name(np), in sym_prepare_setting()
2756 np->myaddr, in sym_prepare_setting()
2757 (np->features & FE_ULTRA3) ? 80 : in sym_prepare_setting()
2758 (np->features & FE_ULTRA2) ? 40 : in sym_prepare_setting()
2759 (np->features & FE_ULTRA) ? 20 : 10, in sym_prepare_setting()
2760 sym_scsi_bus_mode(np->scsi_mode), in sym_prepare_setting()
2761 (np->rv_scntl0 & 0xa) ? "parity checking" : "NO parity"); in sym_prepare_setting()
2767 sym_name(np), in sym_prepare_setting()
2768 np->rv_dcntl & IRQM ? "totem pole" : "open drain", in sym_prepare_setting()
2769 np->ram_ba ? ", using on-chip SRAM" : ""); in sym_prepare_setting()
2770 printf("%s: using %s firmware.\n", sym_name(np), np->fw_name); in sym_prepare_setting()
2771 if (np->features & FE_NOPM) in sym_prepare_setting()
2773 sym_name(np)); in sym_prepare_setting()
2781 sym_name(np), np->sv_scntl3, np->sv_dmode, np->sv_dcntl, in sym_prepare_setting()
2782 np->sv_ctest3, np->sv_ctest4, np->sv_ctest5); in sym_prepare_setting()
2786 sym_name(np), np->rv_scntl3, np->rv_dmode, np->rv_dcntl, in sym_prepare_setting()
2787 np->rv_ctest3, np->rv_ctest4, np->rv_ctest5); in sym_prepare_setting()
2792 sym_print_targets_flag(np, SYM_SCAN_BOOT_DISABLED, "SCAN AT BOOT"); in sym_prepare_setting()
2794 sym_print_targets_flag(np, SYM_SCAN_LUNS_DISABLED, in sym_prepare_setting()
2807 static int sym_prepare_nego(hcb_p np, ccb_p cp, int nego, u_char *msgptr) in sym_prepare_nego() argument
2809 tcb_p tp = &np->target[cp->target]; in sym_prepare_nego()
2816 if (!(np->features & FE_U3EN)) in sym_prepare_nego()
2878 static void sym_put_start_queue(hcb_p np, ccb_p cp) in sym_put_start_queue() argument
2891 if (np->last_cp && np->iarb_count < np->iarb_max) { in sym_put_start_queue()
2892 np->last_cp->host_flags |= HF_HINT_IARB; in sym_put_start_queue()
2893 ++np->iarb_count; in sym_put_start_queue()
2896 np->iarb_count = 0; in sym_put_start_queue()
2897 np->last_cp = cp; in sym_put_start_queue()
2904 qidx = np->squeueput + 2; in sym_put_start_queue()
2907 np->squeue [qidx] = cpu_to_scr(np->idletask_ba); in sym_put_start_queue()
2909 np->squeue [np->squeueput] = cpu_to_scr(cp->ccb_ba); in sym_put_start_queue()
2911 np->squeueput = qidx; in sym_put_start_queue()
2914 printf ("%s: queuepos=%d.\n", sym_name (np), np->squeueput); in sym_put_start_queue()
2921 OUTB (nc_istat, SIGP|np->istat_sem); in sym_put_start_queue()
2932 static void sym_chip_reset (hcb_p np) in sym_chip_reset() argument
2949 static void sym_soft_reset (hcb_p np) in sym_soft_reset() argument
2969 sym_name(np)); in sym_soft_reset()
2970 sym_chip_reset (np); in sym_soft_reset()
2978 static void sym_start_reset(hcb_p np) in sym_start_reset() argument
2980 (void) sym_reset_scsi_bus(np, 1); in sym_start_reset()
2983 static int sym_reset_scsi_bus(hcb_p np, int enab_int) in sym_reset_scsi_bus() argument
2988 sym_soft_reset(np); /* Soft reset the chip */ in sym_reset_scsi_bus()
2996 OUTB (nc_dcntl, (np->rv_dcntl & IRQM)); in sym_reset_scsi_bus()
3015 if (!(np->features & FE_WIDE)) in sym_reset_scsi_bus()
3020 sym_name(np)); in sym_reset_scsi_bus()
3023 sym_name(np), in sym_reset_scsi_bus()
3024 (np->features & FE_WIDE) ? "dp1,d15-8," : "", in sym_reset_scsi_bus()
3042 static int sym_wakeup_done (hcb_p np) in sym_wakeup_done() argument
3051 i = np->dqueueget; in sym_wakeup_done()
3053 dsa = scr_to_cpu(np->dqueue[i]); in sym_wakeup_done()
3056 np->dqueue[i] = 0; in sym_wakeup_done()
3060 cp = sym_ccb_from_dsa(np, dsa); in sym_wakeup_done()
3063 sym_complete_ok (np, cp); in sym_wakeup_done()
3068 sym_name(np), (u_int) dsa); in sym_wakeup_done()
3070 np->dqueueget = i; in sym_wakeup_done()
3079 static void sym_flush_busy_queue (hcb_p np, int cam_status) in sym_flush_busy_queue() argument
3085 sym_que_splice(&np->busy_ccbq, &np->comp_ccbq); in sym_flush_busy_queue()
3086 sym_que_init(&np->busy_ccbq); in sym_flush_busy_queue()
3087 sym_flush_comp_queue(np, cam_status); in sym_flush_busy_queue()
3098 static void sym_init (hcb_p np, int reason) in sym_init() argument
3109 sym_soft_reset(np); in sym_init()
3118 phys = np->squeue_ba; in sym_init()
3120 np->squeue[i] = cpu_to_scr(np->idletask_ba); in sym_init()
3121 np->squeue[i+1] = cpu_to_scr(phys + (i+2)*4); in sym_init()
3123 np->squeue[MAX_QUEUE*2-1] = cpu_to_scr(phys); in sym_init()
3128 np->squeueput = 0; in sym_init()
3133 phys = np->dqueue_ba; in sym_init()
3135 np->dqueue[i] = 0; in sym_init()
3136 np->dqueue[i+1] = cpu_to_scr(phys + (i+2)*4); in sym_init()
3138 np->dqueue[MAX_QUEUE*2-1] = cpu_to_scr(phys); in sym_init()
3143 np->dqueueget = 0; in sym_init()
3150 np->fw_patch(np); in sym_init()
3155 sym_flush_busy_queue(np, CAM_SCSI_BUS_RESET); in sym_init()
3163 OUTB (nc_scntl0, np->rv_scntl0 | 0xc0); in sym_init()
3167 sym_selectclock(np, np->rv_scntl3); /* Select SCSI clock */ in sym_init()
3169 OUTB (nc_scid , RRE|np->myaddr); /* Adapter SCSI address */ in sym_init()
3170 OUTW (nc_respid, 1ul<<np->myaddr); /* Id to respond to */ in sym_init()
3172 OUTB (nc_dmode , np->rv_dmode); /* Burst length, dma mode */ in sym_init()
3173 OUTB (nc_ctest5, np->rv_ctest5); /* Large fifo + large burst */ in sym_init()
3175 OUTB (nc_dcntl , NOCOM|np->rv_dcntl); /* Protect SFBR */ in sym_init()
3176 OUTB (nc_ctest3, np->rv_ctest3); /* Write and invalidate */ in sym_init()
3177 OUTB (nc_ctest4, np->rv_ctest4); /* Master parity checking */ in sym_init()
3180 if (np->features & FE_C10) in sym_init()
3181 OUTB (nc_stest2, np->rv_stest2); in sym_init()
3183 OUTB (nc_stest2, EXT|np->rv_stest2); in sym_init()
3191 if (np->device_id == PCI_ID_LSI53C1010_2) in sym_init()
3201 if (np->device_id == PCI_ID_LSI53C1010 && in sym_init()
3202 /* np->revision_id < 0xff */ 1) in sym_init()
3210 if (np->device_id == PCI_ID_SYM53C875) in sym_init()
3212 else if (np->device_id == PCI_ID_SYM53C896) in sym_init()
3213 np->rv_ccntl0 |= DPR; in sym_init()
3220 if (np->features & (FE_DAC|FE_NOPM)) { in sym_init()
3221 OUTB (nc_ccntl0, np->rv_ccntl0); in sym_init()
3222 OUTB (nc_ccntl1, np->rv_ccntl1); in sym_init()
3229 if (np->features & FE_NOPM) { in sym_init()
3230 OUTL (nc_pmjad1, SCRIPTB_BA (np, pm_handle)); in sym_init()
3231 OUTL (nc_pmjad2, SCRIPTB_BA (np, pm_handle)); in sym_init()
3238 if (np->features & FE_LED0) in sym_init()
3240 else if (np->features & FE_LEDC) in sym_init()
3254 if (np->features & (FE_ULTRA2|FE_ULTRA3)) { in sym_init()
3260 np->scsi_mode = INB (nc_stest4) & SMODE; in sym_init()
3270 tcb_p tp = &np->target[i]; in sym_init()
3274 tp->head.wval = np->rv_scntl3; in sym_init()
3287 if (np->ram_ba) { in sym_init()
3290 sym_name(np)); in sym_init()
3291 if (np->ram_ws == 8192) { in sym_init()
3292 OUTRAM_OFF(4096, np->scriptb0, np->scriptb_sz); in sym_init()
3293 OUTL (nc_mmws, np->scr_ram_seg); in sym_init()
3294 OUTL (nc_mmrs, np->scr_ram_seg); in sym_init()
3295 OUTL (nc_sfs, np->scr_ram_seg); in sym_init()
3296 phys = SCRIPTB_BA (np, start64); in sym_init()
3299 phys = SCRIPTA_BA (np, init); in sym_init()
3300 OUTRAM_OFF(0, np->scripta0, np->scripta_sz); in sym_init()
3303 phys = SCRIPTA_BA (np, init); in sym_init()
3305 np->istat_sem = 0; in sym_init()
3307 OUTL (nc_dsa, np->hcb_ba); in sym_init()
3314 xpt_async(AC_BUS_RESET, np->path, NULL); in sym_init()
3322 sym_getsync(hcb_p np, u_char dt, u_char sfac, u_char *divp, u_char *fakp) in sym_getsync() argument
3324 u32 clk = np->clock_khz; /* SCSI clock frequency in kHz */ in sym_getsync()
3325 int div = np->clock_divn; /* Number of divisors supported */ in sym_getsync()
3353 if ((np->features & (FE_C10|FE_U3EN)) == FE_C10) { in sym_getsync()
3366 if (div == np->clock_divn) { /* Are we too fast ? */ in sym_getsync()
3390 /* ret = ((2+fak)*div_10M[div])/np->clock_khz; */ in sym_getsync()
3394 /* ret = ((4+fak)*div_10M[div])/np->clock_khz; */ in sym_getsync()
3415 sym_xpt_async_transfer_neg(hcb_p np, int target, u_int spi_valid) in sym_xpt_async_transfer_neg() argument
3420 tcb_p tp = &np->target[target]; in sym_xpt_async_transfer_neg()
3422 sts = xpt_create_path(&path, NULL, cam_sim_path(np->sim), target, in sym_xpt_async_transfer_neg()
3471 static void sym_setwide(hcb_p np, ccb_p cp, u_char wide) in sym_setwide() argument
3473 tcb_p tp = &np->target[cp->target]; in sym_setwide()
3475 sym_settrans(np, cp, 0, 0, 0, wide, 0, 0); in sym_setwide()
3485 sym_xpt_async_transfer_neg(np, cp->target, SYM_SPI_VALID_WDTR); in sym_setwide()
3493 sym_setsync(hcb_p np, ccb_p cp, u_char ofs, u_char per, u_char div, u_char fak) in sym_setsync() argument
3495 tcb_p tp = &np->target[cp->target]; in sym_setsync()
3498 sym_settrans(np, cp, 0, ofs, per, wide, div, fak); in sym_setsync()
3507 sym_xpt_async_transfer_neg(np, cp->target, SYM_SPI_VALID_SDTR); in sym_setsync()
3514 static void sym_setpprot(hcb_p np, ccb_p cp, u_char dt, u_char ofs, in sym_setpprot() argument
3517 tcb_p tp = &np->target[cp->target]; in sym_setpprot()
3519 sym_settrans(np, cp, dt, ofs, per, wide, div, fak); in sym_setpprot()
3529 sym_xpt_async_transfer_neg(np, cp->target, SYM_SPI_VALID_PPR); in sym_setpprot()
3535 static void sym_settrans(hcb_p np, ccb_p cp, u_char dt, u_char ofs, in sym_settrans() argument
3550 tp = &np->target[target]; in sym_settrans()
3558 sval, wval, uval, np->rv_scntl3); in sym_settrans()
3563 if (!(np->features & FE_C10)) in sym_settrans()
3573 if (!(np->features & FE_C10)) in sym_settrans()
3592 if (np->features & FE_C10) { in sym_settrans()
3595 assert(np->features & FE_U3EN); in sym_settrans()
3619 if (per < 50 && !(np->features & FE_C10)) in sym_settrans()
3628 if (np->features & FE_C10) { in sym_settrans()
3635 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { in sym_settrans()
3641 if (np->features & FE_C10) { in sym_settrans()
3673 static void sym_log_hard_error(hcb_p np, u_short sist, u_char dstat) in sym_log_hard_error() argument
3684 if (dsp > np->scripta_ba && in sym_log_hard_error()
3685 dsp <= np->scripta_ba + np->scripta_sz) { in sym_log_hard_error()
3686 script_ofs = dsp - np->scripta_ba; in sym_log_hard_error()
3687 script_size = np->scripta_sz; in sym_log_hard_error()
3688 script_base = (u_char *) np->scripta0; in sym_log_hard_error()
3691 else if (np->scriptb_ba < dsp && in sym_log_hard_error()
3692 dsp <= np->scriptb_ba + np->scriptb_sz) { in sym_log_hard_error()
3693 script_ofs = dsp - np->scriptb_ba; in sym_log_hard_error()
3694 script_size = np->scriptb_sz; in sym_log_hard_error()
3695 script_base = (u_char *) np->scriptb0; in sym_log_hard_error()
3705 sym_name (np), (unsigned)INB (nc_sdid)&0x0f, dstat, sist, in sym_log_hard_error()
3713 printf ("%s: script cmd = %08x\n", sym_name(np), in sym_log_hard_error()
3717 printf ("%s: regdump:", sym_name(np)); in sym_log_hard_error()
3727 pci_sts = pci_read_config(np->device, PCIR_STATUS, 2); in sym_log_hard_error()
3729 pci_write_config(np->device, PCIR_STATUS, pci_sts, 2); in sym_log_hard_error()
3731 sym_name(np), pci_sts & 0xf900); in sym_log_hard_error()
3798 static void sym_intr1 (hcb_p np) in sym_intr1() argument
3815 OUTB (nc_istat, (istat & SIGP) | INTF | np->istat_sem); in sym_intr1()
3818 (void)sym_wakeup_done (np); in sym_intr1()
3878 if (sist & PAR) sym_int_par (np, sist); in sym_intr1()
3879 else if (sist & MA) sym_int_ma (np); in sym_intr1()
3880 else if (dstat & SIR) sym_int_sir (np); in sym_intr1()
3898 xpt_print_path(np->path); in sym_intr1()
3900 sym_init (np, 1); in sym_intr1()
3904 OUTB (nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */ in sym_intr1()
3909 if (sist & SBMC) sym_int_sbmc (np); in sym_intr1()
3910 else if (sist & STO) sym_int_sto (np); in sym_intr1()
3911 else if (sist & UDC) sym_int_udc (np); in sym_intr1()
3923 sym_log_hard_error(np, sist, dstat); in sym_intr1()
3927 sym_start_reset(np); in sym_intr1()
3938 sym_name(np), istat, dstat, sist); in sym_intr1()
3943 hcb_p np = arg; in sym_intr() local
3985 static void sym_recover_scsi_int (hcb_p np, u_char hsts) in sym_recover_scsi_int() argument
3989 ccb_p cp = sym_ccb_from_dsa(np, dsa); in sym_recover_scsi_int()
3996 if ((!(dsp > SCRIPTA_BA (np, getjob_begin) && in sym_recover_scsi_int()
3997 dsp < SCRIPTA_BA (np, getjob_end) + 1)) && in sym_recover_scsi_int()
3998 (!(dsp > SCRIPTA_BA (np, ungetjob) && in sym_recover_scsi_int()
3999 dsp < SCRIPTA_BA (np, reselect) + 1)) && in sym_recover_scsi_int()
4000 (!(dsp > SCRIPTB_BA (np, sel_for_abort) && in sym_recover_scsi_int()
4001 dsp < SCRIPTB_BA (np, sel_for_abort_1) + 1)) && in sym_recover_scsi_int()
4002 (!(dsp > SCRIPTA_BA (np, done) && in sym_recover_scsi_int()
4003 dsp < SCRIPTA_BA (np, done_end) + 1))) { in sym_recover_scsi_int()
4004 OUTB (nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */ in sym_recover_scsi_int()
4014 OUTL_DSP (SCRIPTA_BA (np, complete_error)); in sym_recover_scsi_int()
4021 OUTL_DSP (SCRIPTA_BA (np, start)); in sym_recover_scsi_int()
4030 sym_start_reset(np); in sym_recover_scsi_int()
4036 static void sym_int_sto (hcb_p np) in sym_int_sto() argument
4042 if (dsp == SCRIPTA_BA (np, wf_sel_done) + 8) in sym_int_sto()
4043 sym_recover_scsi_int(np, HS_SEL_TIMEOUT); in sym_int_sto()
4045 sym_start_reset(np); in sym_int_sto()
4051 static void sym_int_udc (hcb_p np) in sym_int_udc() argument
4053 printf ("%s: unexpected disconnect\n", sym_name(np)); in sym_int_udc()
4054 sym_recover_scsi_int(np, HS_UNEXPECTED); in sym_int_udc()
4067 static void sym_int_sbmc (hcb_p np) in sym_int_sbmc() argument
4074 xpt_print_path(np->path); in sym_int_sbmc()
4076 sym_scsi_bus_mode(np->scsi_mode), sym_scsi_bus_mode(scsi_mode)); in sym_int_sbmc()
4082 sym_init (np, 2); in sym_int_sbmc()
4109 static void sym_int_par (hcb_p np, u_short sist) in sym_int_par() argument
4118 ccb_p cp = sym_ccb_from_dsa(np, dsa); in sym_int_par()
4121 sym_name(np), hsts, dbc, sbcl); in sym_int_par()
4127 sym_recover_scsi_int(np, HS_UNEXPECTED); in sym_int_par()
4154 np->msgout[0] = (phase == 7) ? M_PARITY : M_ID_ERROR; in sym_int_par()
4165 if (dsp == SCRIPTB_BA (np, pm_handle)) in sym_int_par()
4169 sym_int_ma (np); in sym_int_par()
4173 OUTL_DSP (SCRIPTA_BA (np, dispatch)); in sym_int_par()
4177 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_int_par()
4181 sym_start_reset(np); in sym_int_par()
4190 static void sym_int_ma (hcb_p np) in sym_int_ma() argument
4218 cp = sym_ccb_from_dsa(np, dsa); in sym_int_ma()
4229 if (np->features & FE_DFBC) in sym_int_ma()
4259 if (!(np->features & FE_C10)) in sym_int_ma()
4264 if (!(np->features & FE_C10)) in sym_int_ma()
4271 OUTB (nc_ctest3, np->rv_ctest3 | CLF); /* dma fifo */ in sym_int_ma()
4288 if (dsp > np->scripta_ba && in sym_int_ma()
4289 dsp <= np->scripta_ba + np->scripta_sz) { in sym_int_ma()
4290 vdsp = (u32 *)((char*)np->scripta0 + (dsp-np->scripta_ba-8)); in sym_int_ma()
4293 else if (dsp > np->scriptb_ba && in sym_int_ma()
4294 dsp <= np->scriptb_ba + np->scriptb_sz) { in sym_int_ma()
4295 vdsp = (u32 *)((char*)np->scriptb0 + (dsp-np->scriptb_ba-8)); in sym_int_ma()
4309 sym_name (np)); in sym_int_ma()
4315 sym_name (np)); in sym_int_ma()
4388 newcmd = SCRIPTA_BA (np, pm0_data); in sym_int_ma()
4392 newcmd = SCRIPTA_BA (np, pm1_data); in sym_int_ma()
4412 nxtdsp = SCRIPTA_BA (np, dispatch); in sym_int_ma()
4440 nxtdsp = SCRIPTB_BA (np, wsr_ma_helper); in sym_int_ma()
4492 nxtdsp = SCRIPTA_BA (np, dispatch); in sym_int_ma()
4496 nxtdsp = SCRIPTA_BA (np, dispatch); in sym_int_ma()
4506 if (dsp == SCRIPTA_BA (np, send_ident)) { in sym_int_ma()
4509 np->msgout[0] = M_IDENTIFY | cp->lun; in sym_int_ma()
4510 nxtdsp = SCRIPTB_BA (np, ident_break_atn); in sym_int_ma()
4513 nxtdsp = SCRIPTB_BA (np, ident_break); in sym_int_ma()
4515 else if (dsp == SCRIPTB_BA (np, send_wdtr) || in sym_int_ma()
4516 dsp == SCRIPTB_BA (np, send_sdtr) || in sym_int_ma()
4517 dsp == SCRIPTB_BA (np, send_ppr)) { in sym_int_ma()
4518 nxtdsp = SCRIPTB_BA (np, nego_bad_phase); in sym_int_ma()
4523 nxtdsp = SCRIPTA_BA (np, clrack); in sym_int_ma()
4534 sym_start_reset(np); in sym_int_ma()
4546 sym_dequeue_from_squeue(hcb_p np, int i, int target, int lun, int task) in sym_dequeue_from_squeue() argument
4561 while (i != np->squeueput) { in sym_dequeue_from_squeue()
4562 cp = sym_ccb_from_dsa(np, scr_to_cpu(np->squeue[i])); in sym_dequeue_from_squeue()
4573 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq); in sym_dequeue_from_squeue()
4577 np->squeue[j] = np->squeue[i]; in sym_dequeue_from_squeue()
4583 np->squeue[j] = np->squeue[i]; in sym_dequeue_from_squeue()
4584 np->squeueput = j; /* Update our current start queue pointer */ in sym_dequeue_from_squeue()
4604 sym_flush_comp_queue(hcb_p np, int cam_status) in sym_flush_comp_queue() argument
4609 while ((qp = sym_remque_head(&np->comp_ccbq)) != NULL) { in sym_flush_comp_queue()
4612 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq); in sym_flush_comp_queue()
4620 sym_xpt_done(np, ccb, cp); in sym_flush_comp_queue()
4621 sym_free_ccb(np, cp); in sym_flush_comp_queue()
4643 static void sym_sir_bad_scsi_status(hcb_p np, ccb_p cp) in sym_sir_bad_scsi_status() argument
4645 tcb_p tp = &np->target[cp->target]; in sym_sir_bad_scsi_status()
4658 i = (INL (nc_scratcha) - np->squeue_ba) / 4; in sym_sir_bad_scsi_status()
4665 if (np->last_cp) in sym_sir_bad_scsi_status()
4666 np->last_cp = NULL; in sym_sir_bad_scsi_status()
4681 sym_complete_error (np, cp); in sym_sir_bad_scsi_status()
4689 sym_complete_error (np, cp); in sym_sir_bad_scsi_status()
4697 (void) sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1); in sym_sir_bad_scsi_status()
4698 OUTL_DSP (SCRIPTA_BA (np, start)); in sym_sir_bad_scsi_status()
4706 cp->sv_resid = sym_compute_residual(np, cp); in sym_sir_bad_scsi_status()
4739 sym_prepare_nego (np,cp, nego, &cp->scsi_smsg2[msglen]); in sym_sir_bad_scsi_status()
4772 startp = SCRIPTB_BA (np, sdata_in); in sym_sir_bad_scsi_status()
4786 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA (np, select)); in sym_sir_bad_scsi_status()
4791 sym_put_start_queue(np, cp); in sym_sir_bad_scsi_status()
4796 sym_flush_comp_queue(np, 0); in sym_sir_bad_scsi_status()
4816 sym_clear_tasks(hcb_p np, int cam_status, int target, int lun, int task) in sym_clear_tasks() argument
4826 sym_que_splice(&np->busy_ccbq, &qtmp); in sym_clear_tasks()
4827 sym_que_init(&np->busy_ccbq); in sym_clear_tasks()
4843 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq); in sym_clear_tasks()
4846 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq); in sym_clear_tasks()
4899 static void sym_sir_task_recovery(hcb_p np, int num) in sym_sir_task_recovery() argument
4918 tp = &np->target[i]; in sym_sir_task_recovery()
4941 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { in sym_sir_task_recovery()
4957 tp = &np->target[target]; in sym_sir_task_recovery()
4958 np->abrt_sel.sel_id = target; in sym_sir_task_recovery()
4959 np->abrt_sel.sel_scntl3 = tp->head.wval; in sym_sir_task_recovery()
4960 np->abrt_sel.sel_sxfer = tp->head.sval; in sym_sir_task_recovery()
4961 OUTL(nc_dsa, np->hcb_ba); in sym_sir_task_recovery()
4962 OUTL_DSP (SCRIPTB_BA (np, sel_for_abort)); in sym_sir_task_recovery()
4973 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { in sym_sir_task_recovery()
4986 if (cp == np->last_cp) { in sym_sir_task_recovery()
5000 np->istat_sem = 0; in sym_sir_task_recovery()
5009 i = (INL (nc_scratcha) - np->squeue_ba) / 4; in sym_sir_task_recovery()
5010 i = sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1); in sym_sir_task_recovery()
5028 sym_flush_comp_queue(np, 0); in sym_sir_task_recovery()
5036 tp = &np->target[target]; in sym_sir_task_recovery()
5038 np->abrt_tbl.addr = cpu_to_scr(vtobus(np->abrt_msg)); in sym_sir_task_recovery()
5046 np->abrt_msg[0] = M_RESET; in sym_sir_task_recovery()
5047 np->abrt_tbl.size = 1; in sym_sir_task_recovery()
5073 np->abrt_msg[0] = M_IDENTIFY | lun; in sym_sir_task_recovery()
5074 np->abrt_msg[1] = M_ABORT; in sym_sir_task_recovery()
5075 np->abrt_tbl.size = 2; in sym_sir_task_recovery()
5085 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { in sym_sir_task_recovery()
5105 np->abrt_msg[0] = M_ABORT; in sym_sir_task_recovery()
5106 np->abrt_tbl.size = 1; in sym_sir_task_recovery()
5114 np->abrt_msg[0] = M_IDENTIFY | cp->lun; in sym_sir_task_recovery()
5123 np->abrt_msg[1] = M_ABORT; in sym_sir_task_recovery()
5124 np->abrt_tbl.size = 2; in sym_sir_task_recovery()
5127 np->abrt_msg[1] = cp->scsi_smsg[1]; in sym_sir_task_recovery()
5128 np->abrt_msg[2] = cp->scsi_smsg[2]; in sym_sir_task_recovery()
5129 np->abrt_msg[3] = M_ABORT_TAG; in sym_sir_task_recovery()
5130 np->abrt_tbl.size = 4; in sym_sir_task_recovery()
5148 tp = &np->target[target]; in sym_sir_task_recovery()
5153 if (np->abrt_msg[0] == M_ABORT) in sym_sir_task_recovery()
5166 if (np->abrt_msg[0] == M_RESET) { in sym_sir_task_recovery()
5168 tp->head.wval = np->rv_scntl3; in sym_sir_task_recovery()
5183 lun = np->abrt_msg[0] & 0x3f; in sym_sir_task_recovery()
5184 if (np->abrt_msg[1] == M_ABORT_TAG) in sym_sir_task_recovery()
5185 task = np->abrt_msg[2]; in sym_sir_task_recovery()
5192 i = (INL (nc_scratcha) - np->squeue_ba) / 4; in sym_sir_task_recovery()
5193 (void) sym_dequeue_from_squeue(np, i, target, lun, -1); in sym_sir_task_recovery()
5194 (void) sym_clear_tasks(np, CAM_REQ_ABORTED, target, lun, task); in sym_sir_task_recovery()
5195 sym_flush_comp_queue(np, 0); in sym_sir_task_recovery()
5200 if (np->abrt_msg[0] == M_RESET) in sym_sir_task_recovery()
5201 xpt_async(AC_SENT_BDR, np->path, NULL); in sym_sir_task_recovery()
5209 PRINT_TARGET(np, target); in sym_sir_task_recovery()
5210 sym_printl_hex("control msgout:", np->abrt_msg, in sym_sir_task_recovery()
5211 np->abrt_tbl.size); in sym_sir_task_recovery()
5212 np->abrt_tbl.size = cpu_to_scr(np->abrt_tbl.size); in sym_sir_task_recovery()
5247 static int sym_evaluate_dp(hcb_p np, ccb_p cp, u32 scr, int *ofs) in sym_evaluate_dp() argument
5260 if (dp_scr == SCRIPTA_BA (np, pm0_data)) in sym_evaluate_dp()
5262 else if (dp_scr == SCRIPTA_BA (np, pm1_data)) in sym_evaluate_dp()
5364 static void sym_modify_dp(hcb_p np, ccb_p cp, int ofs) in sym_modify_dp() argument
5384 dp_sg = sym_evaluate_dp(np, cp, dp_scr, &dp_ofs); in sym_modify_dp()
5414 dp_scr = SCRIPTA_BA (np, pm0_data); in sym_modify_dp()
5418 dp_scr = SCRIPTA_BA (np, pm1_data); in sym_modify_dp()
5440 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_modify_dp()
5444 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_modify_dp()
5461 static int sym_compute_residual(hcb_p np, ccb_p cp) in sym_compute_residual() argument
5494 sym_evaluate_dp(np, cp, scr_to_cpu(cp->phys.head.lastp), in sym_compute_residual()
5589 static void sym_sync_nego(hcb_p np, tcb_p tp, ccb_p cp) in sym_sync_nego() argument
5598 sym_print_msg(cp, "sync msgin", np->msgin); in sym_sync_nego()
5615 per = np->msgin[3]; in sym_sync_nego()
5616 ofs = np->msgin[4]; in sym_sync_nego()
5622 if (ofs > np->maxoffs) in sym_sync_nego()
5623 {chg = 1; ofs = np->maxoffs;} in sym_sync_nego()
5631 if (per < np->minsync) in sym_sync_nego()
5632 {chg = 1; per = np->minsync;} in sym_sync_nego()
5640 if (ofs && sym_getsync(np, 0, per, &div, &fak) < 0) in sym_sync_nego()
5655 sym_setsync (np, cp, ofs, per, div, fak); in sym_sync_nego()
5656 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_sync_nego()
5664 sym_setsync (np, cp, ofs, per, div, fak); in sym_sync_nego()
5666 np->msgout[0] = M_EXTENDED; in sym_sync_nego()
5667 np->msgout[1] = 3; in sym_sync_nego()
5668 np->msgout[2] = M_X_SYNC_REQ; in sym_sync_nego()
5669 np->msgout[3] = per; in sym_sync_nego()
5670 np->msgout[4] = ofs; in sym_sync_nego()
5675 sym_print_msg(cp, "sync msgout", np->msgout); in sym_sync_nego()
5678 np->msgin [0] = M_NOOP; in sym_sync_nego()
5680 OUTL_DSP (SCRIPTB_BA (np, sdtr_resp)); in sym_sync_nego()
5683 sym_setsync (np, cp, 0, 0, 0, 0); in sym_sync_nego()
5684 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_sync_nego()
5690 static void sym_ppr_nego(hcb_p np, tcb_p tp, ccb_p cp) in sym_ppr_nego() argument
5699 sym_print_msg(cp, "ppr msgin", np->msgin); in sym_ppr_nego()
5706 per = np->msgin[3]; in sym_ppr_nego()
5707 ofs = np->msgin[5]; in sym_ppr_nego()
5708 wide = np->msgin[6]; in sym_ppr_nego()
5709 dt = np->msgin[7] & PPR_OPT_DT; in sym_ppr_nego()
5724 if (wide > np->maxwide) in sym_ppr_nego()
5725 {chg = 1; wide = np->maxwide;} in sym_ppr_nego()
5726 if (!wide || !(np->features & FE_ULTRA3)) in sym_ppr_nego()
5733 if (!(np->features & FE_U3EN)) /* Broken U3EN bit not supported */ in sym_ppr_nego()
5736 if (dt != (np->msgin[7] & PPR_OPT_MASK)) chg = 1; in sym_ppr_nego()
5740 if (ofs > np->maxoffs_dt) in sym_ppr_nego()
5741 {chg = 1; ofs = np->maxoffs_dt;} in sym_ppr_nego()
5743 else if (ofs > np->maxoffs) in sym_ppr_nego()
5744 {chg = 1; ofs = np->maxoffs;} in sym_ppr_nego()
5753 if (per < np->minsync_dt) in sym_ppr_nego()
5754 {chg = 1; per = np->minsync_dt;} in sym_ppr_nego()
5756 else if (per < np->minsync) in sym_ppr_nego()
5757 {chg = 1; per = np->minsync;} in sym_ppr_nego()
5765 if (ofs && sym_getsync(np, dt, per, &div, &fak) < 0) in sym_ppr_nego()
5781 sym_setpprot (np, cp, dt, ofs, per, wide, div, fak); in sym_ppr_nego()
5782 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_ppr_nego()
5790 sym_setpprot (np, cp, dt, ofs, per, wide, div, fak); in sym_ppr_nego()
5792 np->msgout[0] = M_EXTENDED; in sym_ppr_nego()
5793 np->msgout[1] = 6; in sym_ppr_nego()
5794 np->msgout[2] = M_X_PPR_REQ; in sym_ppr_nego()
5795 np->msgout[3] = per; in sym_ppr_nego()
5796 np->msgout[4] = 0; in sym_ppr_nego()
5797 np->msgout[5] = ofs; in sym_ppr_nego()
5798 np->msgout[6] = wide; in sym_ppr_nego()
5799 np->msgout[7] = dt; in sym_ppr_nego()
5804 sym_print_msg(cp, "ppr msgout", np->msgout); in sym_ppr_nego()
5807 np->msgin [0] = M_NOOP; in sym_ppr_nego()
5809 OUTL_DSP (SCRIPTB_BA (np, ppr_resp)); in sym_ppr_nego()
5812 sym_setpprot (np, cp, 0, 0, 0, 0, 0, 0); in sym_ppr_nego()
5813 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_ppr_nego()
5829 static void sym_wide_nego(hcb_p np, tcb_p tp, ccb_p cp) in sym_wide_nego() argument
5838 sym_print_msg(cp, "wide msgin", np->msgin); in sym_wide_nego()
5855 wide = np->msgin[3]; in sym_wide_nego()
5860 if (wide > np->maxwide) in sym_wide_nego()
5861 {chg = 1; wide = np->maxwide;} in sym_wide_nego()
5878 sym_setwide (np, cp, wide); in sym_wide_nego()
5886 np->msgout[0] = M_EXTENDED; in sym_wide_nego()
5887 np->msgout[1] = 3; in sym_wide_nego()
5888 np->msgout[2] = M_X_SYNC_REQ; in sym_wide_nego()
5889 np->msgout[3] = tp->tinfo.goal.period; in sym_wide_nego()
5890 np->msgout[4] = tp->tinfo.goal.offset; in sym_wide_nego()
5893 sym_print_msg(cp, "sync msgout", np->msgout); in sym_wide_nego()
5898 OUTL_DSP (SCRIPTB_BA (np, sdtr_resp)); in sym_wide_nego()
5902 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_wide_nego()
5910 sym_setwide (np, cp, wide); in sym_wide_nego()
5912 np->msgout[0] = M_EXTENDED; in sym_wide_nego()
5913 np->msgout[1] = 2; in sym_wide_nego()
5914 np->msgout[2] = M_X_WIDE_REQ; in sym_wide_nego()
5915 np->msgout[3] = wide; in sym_wide_nego()
5917 np->msgin [0] = M_NOOP; in sym_wide_nego()
5922 sym_print_msg(cp, "wide msgout", np->msgout); in sym_wide_nego()
5925 OUTL_DSP (SCRIPTB_BA (np, wdtr_resp)); in sym_wide_nego()
5928 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_wide_nego()
5940 static void sym_nego_default(hcb_p np, tcb_p tp, ccb_p cp) in sym_nego_default() argument
5949 sym_setpprot (np, cp, 0, 0, 0, 0, 0, 0); in sym_nego_default()
5952 if (tp->tinfo.goal.period < np->minsync) in sym_nego_default()
5953 tp->tinfo.goal.period = np->minsync; in sym_nego_default()
5954 if (tp->tinfo.goal.offset > np->maxoffs) in sym_nego_default()
5955 tp->tinfo.goal.offset = np->maxoffs; in sym_nego_default()
5959 sym_setsync (np, cp, 0, 0, 0, 0); in sym_nego_default()
5962 sym_setwide (np, cp, 0); in sym_nego_default()
5965 np->msgin [0] = M_NOOP; in sym_nego_default()
5966 np->msgout[0] = M_NOOP; in sym_nego_default()
5974 static void sym_nego_rejected(hcb_p np, tcb_p tp, ccb_p cp) in sym_nego_rejected() argument
5976 sym_nego_default(np, tp, cp); in sym_nego_rejected()
5983 static void sym_int_sir (hcb_p np) in sym_int_sir() argument
5987 ccb_p cp = sym_ccb_from_dsa(np, dsa); in sym_int_sir()
5989 tcb_p tp = &np->target[target]; in sym_int_sir()
6004 sym_complete_error(np, cp); in sym_int_sir()
6013 sym_sir_task_recovery(np, num); in sym_int_sir()
6022 sym_name (np), target); in sym_int_sir()
6030 sym_name (np), target); in sym_int_sir()
6038 sym_name (np), target); in sym_int_sir()
6044 np->msgout[0] = M_RESET; in sym_int_sir()
6051 np->msgout[0] = M_ABORT; in sym_int_sir()
6058 np->msgout[0] = M_ABORT_TAG; in sym_int_sir()
6065 np->lastmsg = np->msgout[0]; in sym_int_sir()
6066 np->msgout[0] = M_NOOP; in sym_int_sir()
6068 sym_name (np), target, np->lastmsg); in sym_int_sir()
6075 np->lastmsg = np->msgout[0]; in sym_int_sir()
6076 np->msgout[0] = M_NOOP; in sym_int_sir()
6078 if (np->lastmsg == M_PARITY || np->lastmsg == M_ID_ERROR) { in sym_int_sir()
6094 sym_sir_bad_scsi_status(np, cp); in sym_int_sir()
6101 sym_print_msg(cp, "M_REJECT to send for ", np->msgin); in sym_int_sir()
6102 np->msgout[0] = M_REJECT; in sym_int_sir()
6155 switch (np->msgin [0]) { in sym_int_sir()
6162 switch (np->msgin [2]) { in sym_int_sir()
6165 sym_print_msg(cp,"modify DP",np->msgin); in sym_int_sir()
6166 tmp = (np->msgin[3]<<24) + (np->msgin[4]<<16) + in sym_int_sir()
6167 (np->msgin[5]<<8) + (np->msgin[6]); in sym_int_sir()
6168 sym_modify_dp(np, cp, tmp); in sym_int_sir()
6171 sym_sync_nego(np, tp, cp); in sym_int_sir()
6174 sym_ppr_nego(np, tp, cp); in sym_int_sir()
6177 sym_wide_nego(np, tp, cp); in sym_int_sir()
6192 sym_print_msg(cp,"ign wide residue", np->msgin); in sym_int_sir()
6193 sym_modify_dp(np, cp, -1); in sym_int_sir()
6197 sym_nego_rejected(np, tp, cp); in sym_int_sir()
6201 scr_to_cpu(np->lastmsg), np->msgout[0]); in sym_int_sir()
6214 sym_print_msg(cp, "WEIRD message received", np->msgin); in sym_int_sir()
6215 OUTL_DSP (SCRIPTB_BA (np, msg_weird)); in sym_int_sir()
6231 sym_nego_default(np, tp, cp); in sym_int_sir()
6239 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_int_sir()
6242 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_int_sir()
6251 static ccb_p sym_get_ccb (hcb_p np, u_char tn, u_char ln, u_char tag_order) in sym_get_ccb() argument
6253 tcb_p tp = &np->target[tn]; in sym_get_ccb()
6262 if (sym_que_empty(&np->free_ccbq)) in sym_get_ccb()
6264 qp = sym_remque_head(&np->free_ccbq); in sym_get_ccb()
6274 lp = sym_alloc_lcb(np, tn, ln); in sym_get_ccb()
6302 sym_alloc_lcb_tags(np, tn, ln); in sym_get_ccb()
6319 cpu_to_scr(SCRIPTA_BA (np, resel_tag)); in sym_get_ccb()
6340 cpu_to_scr(SCRIPTA_BA (np, resel_no_tag)); in sym_get_ccb()
6346 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq); in sym_get_ccb()
6357 PRINT_LUN(np, tn, ln); in sym_get_ccb()
6364 sym_insque_head(&cp->link_ccbq, &np->free_ccbq); in sym_get_ccb()
6371 static void sym_free_ccb(hcb_p np, ccb_p cp) in sym_free_ccb() argument
6373 tcb_p tp = &np->target[cp->target]; in sym_free_ccb()
6377 PRINT_LUN(np, cp->target, cp->lun); in sym_free_ccb()
6399 lp->itlq_tbl[cp->tag] = cpu_to_scr(np->bad_itlq_ba); in sym_free_ccb()
6406 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba); in sym_free_ccb()
6414 cpu_to_scr(SCRIPTB_BA (np, resel_bad_lun)); in sym_free_ccb()
6436 if (cp == np->last_cp) in sym_free_ccb()
6437 np->last_cp = NULL; in sym_free_ccb()
6444 bus_dmamap_unload(np->data_dmat, cp->dmamap); in sym_free_ccb()
6454 sym_insque_head(&cp->link_ccbq, &np->free_ccbq); in sym_free_ccb()
6460 static ccb_p sym_alloc_ccb(hcb_p np) in sym_alloc_ccb() argument
6471 if (np->actccbs >= SYM_CONF_MAX_START) in sym_alloc_ccb()
6491 if (bus_dmamap_create(np->data_dmat, 0, &cp->dmamap)) in sym_alloc_ccb()
6496 np->actccbs++; in sym_alloc_ccb()
6512 cp->link_ccbh = np->ccbh[hcode]; in sym_alloc_ccb()
6513 np->ccbh[hcode] = cp; in sym_alloc_ccb()
6518 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA (np, idle)); in sym_alloc_ccb()
6519 cp->phys.head.go.restart = cpu_to_scr(SCRIPTB_BA (np, bad_i_t_l)); in sym_alloc_ccb()
6524 cp->phys.smsg_ext.addr = cpu_to_scr(HCB_BA(np, msgin[2])); in sym_alloc_ccb()
6529 sym_insque_head(&cp->link_ccbq, &np->free_ccbq); in sym_alloc_ccb()
6542 static ccb_p sym_ccb_from_dsa(hcb_p np, u32 dsa) in sym_ccb_from_dsa() argument
6548 cp = np->ccbh[hcode]; in sym_ccb_from_dsa()
6561 static lcb_p sym_alloc_lcb (hcb_p np, u_char tn, u_char ln) in sym_alloc_lcb() argument
6563 tcb_p tp = &np->target[tn]; in sym_alloc_lcb()
6587 tp->luntbl[i] = cpu_to_scr(vtobus(&np->badlun_sa)); in sym_alloc_lcb()
6620 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba); in sym_alloc_lcb()
6625 lp->head.resel_sa = cpu_to_scr(SCRIPTB_BA (np, resel_bad_lun)); in sym_alloc_lcb()
6639 static void sym_alloc_lcb_tags (hcb_p np, u_char tn, u_char ln) in sym_alloc_lcb_tags() argument
6641 tcb_p tp = &np->target[tn]; in sym_alloc_lcb_tags()
6648 if (!lp && !(lp = sym_alloc_lcb(np, tn, ln))) in sym_alloc_lcb_tags()
6669 lp->itlq_tbl[i] = cpu_to_scr(np->notask_ba); in sym_alloc_lcb_tags()
6690 static int sym_regtest (hcb_p np) argument
6714 static int sym_snooptest (hcb_p np) argument
6719 err |= sym_regtest (np);
6727 OUTB (nc_ctest4, (np->rv_ctest4 & MPEE));
6731 pc = SCRIPTB0_BA (np, snooptest);
6737 np->cache = cpu_to_scr(host_wr);
6742 OUTL (nc_dsa, np->hcb_ba);
6759 if ((dstat & MDPE) && (np->rv_ctest4 & MPEE)) {
6762 sym_name(np));
6763 np->rv_ctest4 &= ~MPEE;
6778 host_rd = scr_to_cpu(np->cache);
6785 if (pc != SCRIPTB0_BA (np, snoopend)+8) {
6788 (u_long) SCRIPTB0_BA (np, snooptest), (u_long) pc,
6789 (u_long) SCRIPTB0_BA (np, snoopend) +8);
6835 static void sym_selectclock(hcb_p np, u_char scntl3) argument
6840 if (np->multiplier <= 1) {
6846 printf ("%s: enabling clock multiplier\n", sym_name(np));
6853 if (np->features & FE_LCKFRQ) {
6859 sym_name(np));
6871 static unsigned getfreq (hcb_p np, int gen) argument
6915 sym_name(np), gen, ms, f);
6920 static unsigned sym_getfreq (hcb_p np) argument
6925 (void) getfreq (np, gen); /* throw away first result */
6926 f1 = getfreq (np, gen);
6927 f2 = getfreq (np, gen);
6935 static void sym_getclock (hcb_p np, int mult) argument
6937 unsigned char scntl3 = np->sv_scntl3;
6938 unsigned char stest1 = np->sv_stest1;
6944 if (np->features & FE_C10) {
6945 np->multiplier = mult;
6946 np->clock_khz = 40000 * mult;
6950 np->multiplier = 1;
6957 printf ("%s: clock multiplier found\n", sym_name(np));
6958 np->multiplier = mult;
6966 if (np->multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) {
6968 f1 = sym_getfreq (np);
6971 printf ("%s: chip clock is %uKHz\n", sym_name(np), f1);
6980 sym_name(np));
6981 np->multiplier = mult;
6988 f1 /= np->multiplier;
6994 f1 *= np->multiplier;
6995 np->clock_khz = f1;
7001 static int sym_getpciclock (hcb_p np) argument
7010 if (!(np->features & FE_C10)) {
7012 f = (int) sym_getfreq (np);
7015 np->pciclk_khz = f;
7078 static void sym_complete_error (hcb_p np, ccb_p cp) argument
7118 csio->resid = sym_compute_residual(np, cp);
7161 sym_clear_tasks(np, CAM_REQ_ABORTED,
7196 i = (INL (nc_scratcha) - np->squeue_ba) / 4;
7197 (void) sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1);
7202 OUTL_DSP (SCRIPTA_BA (np, start));
7208 bus_dmamap_sync(np->data_dmat, cp->dmamap,
7219 sym_insque_head(&cp->link_ccbq, &np->comp_ccbq);
7220 sym_flush_comp_queue(np, 0);
7232 static void sym_complete_ok (hcb_p np, ccb_p cp) argument
7251 tp = &np->target[cp->target];
7266 csio->resid = sym_compute_residual(np, cp);
7280 bus_dmamap_sync(np->data_dmat, cp->dmamap,
7289 sym_xpt_done(np, (union ccb *) csio, cp);
7290 sym_free_ccb(np, cp);
7299 hcb_p np = ccb->ccb_h.sym_hcb_ptr; local
7304 if (!np)
7311 (void) sym_abort_scsiio(np, ccb, 1);
7323 static int sym_abort_scsiio(hcb_p np, union ccb *ccb, int timed_out) argument
7334 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
7349 sym_reset_scsi_bus(np, 1);
7362 np->istat_sem = SEM;
7370 static void sym_reset_dev(hcb_p np, union ccb *ccb) argument
7377 if (ccb_h->target_id == np->myaddr ||
7380 sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
7384 tp = &np->target[ccb_h->target_id];
7387 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
7389 np->istat_sem = SEM;
7398 hcb_p np; local
7413 np = (hcb_p) cam_sim_softc(sim);
7440 if (ccb_h->target_id == np->myaddr ||
7443 sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
7450 tp = &np->target[ccb_h->target_id];
7472 sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
7481 cp = sym_get_ccb(np, ccb_h->target_id, ccb_h->target_lun, tmp);
7483 sym_xpt_done2(np, ccb, CAM_RESRC_UNAVAIL);
7543 msglen += sym_prepare_nego(np, cp, 0, msgptr + msglen);
7553 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA (np, select));
7554 cp->phys.head.go.restart = cpu_to_scr(SCRIPTA_BA (np, resel_dsa));
7573 if (sym_setup_cdb(np, csio, cp) < 0) {
7574 sym_xpt_done(np, ccb, cp);
7575 sym_free_ccb(np, cp);
7603 sym_setup_data_and_start(np, csio, cp);
7611 static int sym_setup_cdb(hcb_p np, struct ccb_scsiio *csio, ccb_p cp) argument
7661 sym_setup_data_pointers(hcb_p np, ccb_p cp, int dir) argument
7678 goalp = SCRIPTA_BA (np, data_out2) + 8;
7683 goalp = SCRIPTA_BA (np, data_in2) + 8;
7688 lastp = goalp = SCRIPTB_BA (np, no_data);
7707 hcb_p np; local
7712 np = (hcb_p) cp->arg;
7737 if (np->device_id == PCI_ID_SYM53C896 && np->revision_id <= 1)
7738 retv = sym_scatter_sg_physical(np, cp, psegs, nsegs);
7740 retv = sym_fast_scatter_sg_physical(np,cp, psegs,nsegs);
7752 bus_dmamap_sync(np->data_dmat, cp->dmamap,
7766 sym_setup_data_pointers(np, cp, (ccb->ccb_h.flags & CAM_DIR_MASK));
7792 sym_put_start_queue(np, cp);
7795 sym_xpt_done(np, ccb, cp);
7796 sym_free_ccb(np, cp);
7804 sym_setup_data_and_start(hcb_p np, struct ccb_scsiio *csio, ccb_p cp) argument
7817 cp->arg = np;
7829 retv = bus_dmamap_load_ccb(np->data_dmat, cp->dmamap,
7833 xpt_freeze_simq(np->sim, 1);
7842 sym_fast_scatter_sg_physical(hcb_p np, ccb_p cp, argument
7862 sym_name(np), (long) psegs2->ds_addr,
7879 sym_scatter_sg_physical(hcb_p np, ccb_p cp, bus_dma_segment_t *psegs, int nsegs) argument
7899 sym_name(np), pn, k);
7929 hcb_p np; local
7937 np = (hcb_p) cam_sim_softc(sim);
7946 tp = &np->target[ccb_h->target_id];
7954 sym_update_trans(np, &tp->tinfo.goal, cts);
7956 sym_update_dflags(np, &lp->current_flags, cts);
7959 sym_update_trans(np, &tp->tinfo.user, cts);
7961 sym_update_dflags(np, &lp->user_flags, cts);
7964 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
7968 tp = &np->target[ccb_h->target_id];
8008 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8012 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8018 if ((np->features & FE_WIDE) != 0)
8022 if (np->usrflags & SYM_SCAN_TARGETS_HILO)
8024 if (np->usrflags & SYM_AVOID_BUS_RESET)
8027 cpi->max_target = (np->features & FE_WIDE) ? 15 : 7;
8033 cpi->initiator_id = np->myaddr;
8045 if (np->features & FE_ULTRA3) {
8051 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8057 if (sym_abort_scsiio(np, abort_ccb, 0) == 0) {
8058 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8062 sym_xpt_done2(np, ccb, CAM_UA_ABORT);
8067 sym_reset_dev(np, ccb);
8070 sym_reset_scsi_bus(np, 0);
8072 xpt_print_path(np->path);
8075 sym_init (np, 1);
8076 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8080 sym_xpt_done2(np, ccb, CAM_REQ_INVALID);
8091 hcb_p np; local
8097 np = (hcb_p) cam_sim_softc(sim);
8107 tp = &np->target[tn];
8111 tp->head.wval = np->rv_scntl3;
8128 static void sym_update_trans(hcb_p np, struct sym_trans *tip, argument
8168 if (tip->width > np->maxwide)
8169 tip->width = np->maxwide;
8174 if (!((np->features & (FE_C10|FE_ULTRA3)) == (FE_C10|FE_ULTRA3)) ||
8184 if (tip->period < np->minsync_dt)
8185 tip->period = np->minsync_dt;
8186 if (tip->period > np->maxsync_dt)
8187 tip->period = np->maxsync_dt;
8188 if (tip->offset > np->maxoffs_dt)
8189 tip->offset = np->maxoffs_dt;
8192 if (tip->period < np->minsync)
8193 tip->period = np->minsync;
8194 if (tip->period > np->maxsync)
8195 tip->period = np->maxsync;
8196 if (tip->offset > np->maxoffs)
8197 tip->offset = np->maxoffs;
8206 sym_update_dflags(hcb_p np, u_char *flags, struct ccb_trans_settings *cts) argument
8385 struct sym_hcb *np = NULL; local
8407 np = __sym_calloc_dma(bus_dmat, sizeof(*np), "HCB");
8408 if (np)
8409 np->bus_dmat = bus_dmat;
8412 device_set_softc(dev, np);
8419 np->hcb_ba = vtobus(np);
8420 np->verbose = bootverbose;
8421 np->device = dev;
8422 np->device_id = pci_get_device(dev);
8423 np->revision_id = pci_get_revid(dev);
8424 np->features = chip->features;
8425 np->clock_divn = chip->nr_divisor;
8426 np->maxoffs = chip->offset_max;
8427 np->maxburst = chip->burst_max;
8428 np->scripta_sz = fw->a_size;
8429 np->scriptb_sz = fw->b_size;
8430 np->fw_setup = fw->setup;
8431 np->fw_patch = fw->patch;
8432 np->fw_name = fw->name;
8435 np->target = sym_calloc_dma(SYM_CONF_MAX_TARGET * sizeof(*(np->target)),
8437 if (!np->target)
8444 sym_que_init(&np->free_ccbq);
8445 sym_que_init(&np->busy_ccbq);
8446 sym_que_init(&np->comp_ccbq);
8447 sym_que_init(&np->cam_ccbq);
8452 if (bus_dma_tag_create(np->bus_dmat, 1, SYM_CONF_DMA_BOUNDARY,
8455 0, busdma_lock_mutex, &np->mtx, &np->data_dmat)) {
8486 np->mmio_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &i,
8488 if (!np->mmio_res) {
8492 np->mmio_ba = rman_get_start(np->mmio_res);
8498 np->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &i,
8500 if (!np->irq_res) {
8511 np->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &i, RF_ACTIVE);
8512 if (!np->io_res) {
8523 if (np->features & (FE_RAM|FE_RAM8K)) {
8525 if (np->features & FE_64BIT)
8527 np->ram_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
8529 if (!np->ram_res) {
8533 np->ram_id = regs_id;
8534 np->ram_ba = rman_get_start(np->ram_res);
8541 sym_save_initial_setting (np);
8548 sym_chip_reset (np);
8553 (void) sym_read_nvram(np, &nvram);
8559 (void) sym_prepare_setting(np, &nvram);
8566 i = sym_getpciclock(np);
8573 np->squeue = (u32 *) sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"SQUEUE");
8574 if (!np->squeue)
8576 np->squeue_ba = vtobus(np->squeue);
8581 np->dqueue = (u32 *) sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"DQUEUE");
8582 if (!np->dqueue)
8584 np->dqueue_ba = vtobus(np->dqueue);
8589 np->targtbl = (u32 *) sym_calloc_dma(256, "TARGTBL");
8590 if (!np->targtbl)
8592 np->targtbl_ba = vtobus(np->targtbl);
8597 np->scripta0 = sym_calloc_dma(np->scripta_sz, "SCRIPTA0");
8598 np->scriptb0 = sym_calloc_dma(np->scriptb_sz, "SCRIPTB0");
8599 if (!np->scripta0 || !np->scriptb0)
8605 for (i = 0; sym_alloc_ccb(np) != NULL; i++)
8614 np->scripta_ba = vtobus(np->scripta0);
8615 np->scriptb_ba = vtobus(np->scriptb0);
8616 np->scriptb0_ba = np->scriptb_ba;
8618 if (np->ram_ba) {
8619 np->scripta_ba = np->ram_ba;
8620 if (np->features & FE_RAM8K) {
8621 np->ram_ws = 8192;
8622 np->scriptb_ba = np->scripta_ba + 4096;
8624 np->scr_ram_seg = cpu_to_scr(np->scripta_ba >> 32);
8628 np->ram_ws = 4096;
8634 bcopy(fw->a_base, np->scripta0, np->scripta_sz);
8635 bcopy(fw->b_base, np->scriptb0, np->scriptb_sz);
8641 np->fw_setup(np, fw);
8647 sym_fw_bind_script(np, (u32 *) np->scripta0, np->scripta_sz);
8648 sym_fw_bind_script(np, (u32 *) np->scriptb0, np->scriptb_sz);
8658 np->iarb_max = SYM_SETUP_IARB_MAX;
8660 np->iarb_max = 4;
8667 np->idletask.start = cpu_to_scr(SCRIPTA_BA (np, idle));
8668 np->idletask.restart = cpu_to_scr(SCRIPTB_BA (np, bad_i_t_l));
8669 np->idletask_ba = vtobus(&np->idletask);
8671 np->notask.start = cpu_to_scr(SCRIPTA_BA (np, idle));
8672 np->notask.restart = cpu_to_scr(SCRIPTB_BA (np, bad_i_t_l));
8673 np->notask_ba = vtobus(&np->notask);
8675 np->bad_itl.start = cpu_to_scr(SCRIPTA_BA (np, idle));
8676 np->bad_itl.restart = cpu_to_scr(SCRIPTB_BA (np, bad_i_t_l));
8677 np->bad_itl_ba = vtobus(&np->bad_itl);
8679 np->bad_itlq.start = cpu_to_scr(SCRIPTA_BA (np, idle));
8680 np->bad_itlq.restart = cpu_to_scr(SCRIPTB_BA (np,bad_i_t_l_q));
8681 np->bad_itlq_ba = vtobus(&np->bad_itlq);
8689 np->badluntbl = sym_calloc_dma(256, "BADLUNTBL");
8690 if (!np->badluntbl)
8693 np->badlun_sa = cpu_to_scr(SCRIPTB_BA (np, resel_bad_lun));
8695 np->badluntbl[i] = cpu_to_scr(vtobus(&np->badlun_sa));
8703 np->targtbl[i] = cpu_to_scr(vtobus(&np->target[i]));
8704 np->target[i].head.luntbl_sa =
8705 cpu_to_scr(vtobus(np->badluntbl));
8706 np->target[i].head.lun0_sa =
8707 cpu_to_scr(vtobus(&np->badlun_sa));
8713 if (sym_snooptest (np)) {
8722 if (!sym_cam_attach(np))
8737 if (np)
8738 sym_pci_free(np);
8745 static void sym_pci_free(hcb_p np) argument
8756 sym_cam_free(np);
8762 if (np->ram_res)
8763 bus_release_resource(np->device, SYS_RES_MEMORY,
8764 np->ram_id, np->ram_res);
8765 if (np->mmio_res)
8766 bus_release_resource(np->device, SYS_RES_MEMORY,
8767 SYM_PCI_MMIO, np->mmio_res);
8768 if (np->io_res)
8769 bus_release_resource(np->device, SYS_RES_IOPORT,
8770 SYM_PCI_IO, np->io_res);
8771 if (np->irq_res)
8772 bus_release_resource(np->device, SYS_RES_IRQ,
8773 0, np->irq_res);
8775 if (np->scriptb0)
8776 sym_mfree_dma(np->scriptb0, np->scriptb_sz, "SCRIPTB0");
8777 if (np->scripta0)
8778 sym_mfree_dma(np->scripta0, np->scripta_sz, "SCRIPTA0");
8779 if (np->squeue)
8780 sym_mfree_dma(np->squeue, sizeof(u32)*(MAX_QUEUE*2), "SQUEUE");
8781 if (np->dqueue)
8782 sym_mfree_dma(np->dqueue, sizeof(u32)*(MAX_QUEUE*2), "DQUEUE");
8784 while ((qp = sym_remque_head(&np->free_ccbq)) != NULL) {
8786 bus_dmamap_destroy(np->data_dmat, cp->dmamap);
8791 if (np->badluntbl)
8792 sym_mfree_dma(np->badluntbl, 256,"BADLUNTBL");
8795 tp = &np->target[target];
8815 if (np->target)
8816 sym_mfree_dma(np->target,
8817 SYM_CONF_MAX_TARGET * sizeof(*(np->target)), "TARGET");
8819 if (np->targtbl)
8820 sym_mfree_dma(np->targtbl, 256, "TARGTBL");
8821 if (np->data_dmat)
8822 bus_dma_tag_destroy(np->data_dmat);
8825 device_set_softc(np->device, NULL);
8826 sym_mfree_dma(np, sizeof(*np), "HCB");
8832 static int sym_cam_attach(hcb_p np) argument
8842 err = bus_setup_intr(np->device, np->irq_res,
8844 NULL, sym_intr, np, &np->intr);
8846 device_printf(np->device, "bus_setup_intr() failed: %d\n",
8861 sim = cam_sim_alloc(sym_action, sym_poll, "sym", np,
8862 device_get_unit(np->device),
8863 &np->mtx, 1, SYM_SETUP_MAX_TAG, devq);
8869 if (xpt_bus_register(sim, np->device, 0) != CAM_SUCCESS)
8871 np->sim = sim;
8875 cam_sim_path(np->sim), CAM_TARGET_WILDCARD,
8879 np->path = path;
8884 if (xpt_register_async(AC_LOST_DEVICE, sym_async, np->sim, path) !=
8894 sym_init (np, 0);
8907 sym_cam_free(np);
8915 static void sym_cam_free(hcb_p np) argument
8920 if (np->intr) {
8921 bus_teardown_intr(np->device, np->irq_res, np->intr);
8922 np->intr = NULL;
8927 if (np->sim) {
8928 xpt_bus_deregister(cam_sim_path(np->sim));
8929 cam_sim_free(np->sim, /*free_devq*/ TRUE);
8930 np->sim = NULL;
8932 if (np->path) {
8933 xpt_free_path(np->path);
8934 np->path = NULL;
8945 static void sym_nvram_setup_host (hcb_p np, struct sym_nvram *nvram) argument
8955 np->rv_scntl0 &= ~0x0a;
8956 np->myaddr = nvram->data.Symbios.host_id & 0x0f;
8958 np->verbose += 1;
8960 np->usrflags |= SYM_SCAN_TARGETS_HILO;
8962 np->usrflags |= SYM_AVOID_BUS_RESET;
8965 np->myaddr = nvram->data.Tekram.host_id & 0x0f;
8977 static void sym_Symbios_setup_target(hcb_p np,int target, Symbios_nvram *nvram);
8978 static void sym_Tekram_setup_target(hcb_p np,int target, Tekram_nvram *nvram);
8982 sym_nvram_setup_target (hcb_p np, int target, struct sym_nvram *nvp) argument
8987 sym_Symbios_setup_target (np, target, &nvp->data.Symbios);
8990 sym_Tekram_setup_target (np, target, &nvp->data.Tekram);
9003 sym_Symbios_setup_target(hcb_p np, int target, Symbios_nvram *nvram) argument
9005 tcb_p tp = &np->target[target];
9025 sym_Tekram_setup_target(hcb_p np, int target, Tekram_nvram *nvram) argument
9027 tcb_p tp = &np->target[target];
9048 np->rv_scntl0 &= ~0x0a; /* SCSI parity checking disabled */
9055 static void sym_display_Symbios_nvram(hcb_p np, Symbios_nvram *nvram) argument
9061 sym_name(np), nvram->host_id & 0x0f,
9073 sym_name(np), i,
9088 static void sym_display_Tekram_nvram(hcb_p np, Tekram_nvram *nvram) argument
9106 sym_name(np), nvram->host_id & 0x0f,
9124 sym_name(np), i,
9141 static int sym_read_Symbios_nvram (hcb_p np, Symbios_nvram *nvram);
9142 static int sym_read_Tekram_nvram (hcb_p np, Tekram_nvram *nvram);
9145 static int sym_read_nvram(hcb_p np, struct sym_nvram *nvp) argument
9153 !sym_read_Symbios_nvram (np, &nvp->data.Symbios)) {
9156 sym_display_Symbios_nvram(np, &nvp->data.Symbios);
9160 !sym_read_Tekram_nvram (np, &nvp->data.Tekram)) {
9163 sym_display_Tekram_nvram(np, &nvp->data.Tekram);
9191 static void S24C16_set_bit(hcb_p np, u_char write_bit, u_char *gpreg, argument
9216 static void S24C16_start(hcb_p np, u_char *gpreg) argument
9218 S24C16_set_bit(np, 1, gpreg, SET_BIT);
9219 S24C16_set_bit(np, 0, gpreg, SET_CLK);
9220 S24C16_set_bit(np, 0, gpreg, CLR_BIT);
9221 S24C16_set_bit(np, 0, gpreg, CLR_CLK);
9227 static void S24C16_stop(hcb_p np, u_char *gpreg) argument
9229 S24C16_set_bit(np, 0, gpreg, SET_CLK);
9230 S24C16_set_bit(np, 1, gpreg, SET_BIT);
9237 static void S24C16_do_bit(hcb_p np, u_char *read_bit, u_char write_bit, argument
9240 S24C16_set_bit(np, write_bit, gpreg, SET_BIT);
9241 S24C16_set_bit(np, 0, gpreg, SET_CLK);
9244 S24C16_set_bit(np, 0, gpreg, CLR_CLK);
9245 S24C16_set_bit(np, 0, gpreg, CLR_BIT);
9252 static void S24C16_write_ack(hcb_p np, u_char write_bit, u_char *gpreg, argument
9256 S24C16_do_bit(np, 0, write_bit, gpreg);
9264 static void S24C16_read_ack(hcb_p np, u_char *read_bit, u_char *gpreg, argument
9268 S24C16_do_bit(np, read_bit, 1, gpreg);
9276 static void S24C16_write_byte(hcb_p np, u_char *ack_data, u_char write_data, argument
9282 S24C16_do_bit(np, 0, (write_data >> (7 - x)) & 0x01, gpreg);
9284 S24C16_read_ack(np, ack_data, gpreg, gpcntl);
9291 static void S24C16_read_byte(hcb_p np, u_char *read_data, u_char ack_data, argument
9299 S24C16_do_bit(np, &read_bit, 1, gpreg);
9303 S24C16_write_ack(np, ack_data, gpreg, gpcntl);
9309 static int sym_read_S24C16_nvram (hcb_p np, int offset, u_char *data, int len) argument
9328 S24C16_set_bit(np, 0, &gpreg, CLR_CLK);
9329 S24C16_set_bit(np, 0, &gpreg, CLR_BIT);
9332 S24C16_stop(np, &gpreg);
9335 S24C16_start(np, &gpreg);
9338 S24C16_write_byte(np, &ack_data,
9344 S24C16_write_byte(np, &ack_data,
9350 S24C16_start(np, &gpreg);
9353 S24C16_write_byte(np, &ack_data,
9364 S24C16_read_byte(np, &data[x], (x == (len-1)), &gpreg, &gpcntl);
9369 S24C16_stop(np, &gpreg);
9388 static int sym_read_Symbios_nvram (hcb_p np, Symbios_nvram *nvram) argument
9397 if (sym_read_S24C16_nvram (np, SYMBIOS_NVRAM_ADDRESS, data, len))
9429 static void T93C46_Clk(hcb_p np, u_char *gpreg) argument
9439 static void T93C46_Read_Bit(hcb_p np, u_char *read_bit, u_char *gpreg) argument
9442 T93C46_Clk(np, gpreg);
9449 static void T93C46_Write_Bit(hcb_p np, u_char write_bit, u_char *gpreg) argument
9461 T93C46_Clk(np, gpreg);
9467 static void T93C46_Stop(hcb_p np, u_char *gpreg) argument
9473 T93C46_Clk(np, gpreg);
9479 static void T93C46_Send_Command(hcb_p np, u_short write_data, argument
9486 T93C46_Write_Bit(np, (u_char) (write_data >> (8 - x)), gpreg);
9494 static void T93C46_Read_Word(hcb_p np, u_short *nvram_data, u_char *gpreg) argument
9501 T93C46_Read_Bit(np, &read_bit, gpreg);
9513 static int T93C46_Read_Data(hcb_p np, u_short *data,int len,u_char *gpreg) argument
9520 T93C46_Send_Command(np, 0x180 | x, &read_bit, gpreg);
9523 T93C46_Read_Word(np, &data[x], gpreg);
9524 T93C46_Stop(np, gpreg);
9533 static int sym_read_T93C46_nvram (hcb_p np, Tekram_nvram *nvram) argument
9551 retv = T93C46_Read_Data(np, (u_short *) nvram,
9565 static int sym_read_Tekram_nvram (hcb_p np, Tekram_nvram *nvram) argument
9572 switch (np->device_id) {
9576 x = sym_read_S24C16_nvram(np, TEKRAM_24C16_NVRAM_ADDRESS,
9580 x = sym_read_S24C16_nvram(np, TEKRAM_24C16_NVRAM_ADDRESS,
9585 x = sym_read_T93C46_nvram(np, nvram);