Lines Matching refs:np

331 #define sym_verbose	(np->verbose)
758 #define _sym_calloc_dma(np, s, n) __sym_calloc_dma(np->bus_dmat, s, n) argument
759 #define _sym_mfree_dma(np, p, s, n) \ argument
760 __sym_mfree_dma(np->bus_dmat, _uvptv_(p), s, n)
761 #define sym_calloc_dma(s, n) _sym_calloc_dma(np, s, n)
762 #define sym_mfree_dma(p, s, n) _sym_mfree_dma(np, p, s, n)
763 #define _vtobus(np, p) __vtobus(np->bus_dmat, _uvptv_(p)) argument
764 #define vtobus(p) _vtobus(np, p)
856 #define INB_OFF(o) bus_read_1(np->io_res, (o))
857 #define INW_OFF(o) bus_read_2(np->io_res, (o))
858 #define INL_OFF(o) bus_read_4(np->io_res, (o))
860 #define OUTB_OFF(o, v) bus_write_1(np->io_res, (o), (v))
861 #define OUTW_OFF(o, v) bus_write_2(np->io_res, (o), (v))
862 #define OUTL_OFF(o, v) bus_write_4(np->io_res, (o), (v))
866 #define INB_OFF(o) bus_read_1(np->mmio_res, (o))
867 #define INW_OFF(o) bus_read_2(np->mmio_res, (o))
868 #define INL_OFF(o) bus_read_4(np->mmio_res, (o))
870 #define OUTB_OFF(o, v) bus_write_1(np->mmio_res, (o), (v))
871 #define OUTW_OFF(o, v) bus_write_2(np->mmio_res, (o), (v))
872 #define OUTL_OFF(o, v) bus_write_4(np->mmio_res, (o), (v))
877 bus_write_region_1(np->ram_res, (o), (a), (l))
1012 #define SYM_LOCK() mtx_lock(&np->mtx)
1013 #define SYM_LOCK_ASSERT(_what) mtx_assert(&np->mtx, (_what))
1014 #define SYM_LOCK_DESTROY() mtx_destroy(&np->mtx)
1015 #define SYM_LOCK_INIT() mtx_init(&np->mtx, "sym_lock", NULL, MTX_DEF)
1016 #define SYM_LOCK_INITIALIZED() mtx_initialized(&np->mtx)
1017 #define SYM_UNLOCK() mtx_unlock(&np->mtx)
1595 void (*fw_setup)(hcb_p np, const struct sym_fw *fw);
1596 void (*fw_patch)(hcb_p np);
1705 #define HCB_BA(np, lbl) (np->hcb_ba + offsetof(struct sym_hcb, lbl)) argument
1710 static __inline const char *sym_name(hcb_p np) in sym_name() argument
1712 return device_get_nameunit(np->device); in sym_name()
1776 sym_fw1_patch(hcb_p np) in sym_fw1_patch() argument
1781 scripta0 = (struct sym_fw1a_scr *) np->scripta0; in sym_fw1_patch()
1782 scriptb0 = (struct sym_fw1b_scr *) np->scriptb0; in sym_fw1_patch()
1787 if (!(np->features & FE_LED0)) { in sym_fw1_patch()
1807 scriptb0->startpos[0] = cpu_to_scr(np->squeue_ba); in sym_fw1_patch()
1808 scriptb0->done_pos[0] = cpu_to_scr(np->dqueue_ba); in sym_fw1_patch()
1809 scriptb0->targtbl[0] = cpu_to_scr(np->targtbl_ba); in sym_fw1_patch()
1817 sym_fw2_patch(hcb_p np) in sym_fw2_patch() argument
1822 scripta0 = (struct sym_fw2a_scr *) np->scripta0; in sym_fw2_patch()
1823 scriptb0 = (struct sym_fw2b_scr *) np->scriptb0; in sym_fw2_patch()
1828 if (!(np->features & FE_LED0)) { in sym_fw2_patch()
1848 scriptb0->startpos[0] = cpu_to_scr(np->squeue_ba); in sym_fw2_patch()
1849 scriptb0->done_pos[0] = cpu_to_scr(np->dqueue_ba); in sym_fw2_patch()
1850 scriptb0->targtbl[0] = cpu_to_scr(np->targtbl_ba); in sym_fw2_patch()
1855 if (!(np->features & FE_C10)) { in sym_fw2_patch()
1864 if (!(np->device_id == PCI_ID_LSI53C1010_2 && in sym_fw2_patch()
1865 np->revision_id < 0x1 && in sym_fw2_patch()
1866 np->pciclk_khz < 60000)) { in sym_fw2_patch()
1870 if (!(np->device_id == PCI_ID_LSI53C1010 && in sym_fw2_patch()
1881 cpu_to_scr(np->scripta_ba + in sym_fw2_patch()
1884 cpu_to_scr(np->scripta_ba + in sym_fw2_patch()
1910 sym_fw_setup_bus_addresses(hcb_p np, const struct sym_fw *fw) in sym_fw_setup_bus_addresses() argument
1921 pa = (u32 *) &np->fwa_bas; in sym_fw_setup_bus_addresses()
1922 for (i = 0 ; i < sizeof(np->fwa_bas)/sizeof(u32) ; i++) in sym_fw_setup_bus_addresses()
1923 pa[i] = np->scripta_ba + po[i]; in sym_fw_setup_bus_addresses()
1929 pa = (u32 *) &np->fwb_bas; in sym_fw_setup_bus_addresses()
1930 for (i = 0 ; i < sizeof(np->fwb_bas)/sizeof(u32) ; i++) in sym_fw_setup_bus_addresses()
1931 pa[i] = np->scriptb_ba + po[i]; in sym_fw_setup_bus_addresses()
1939 sym_fw1_setup(hcb_p np, const struct sym_fw *fw) in sym_fw1_setup() argument
1943 scripta0 = (struct sym_fw1a_scr *) np->scripta0; in sym_fw1_setup()
1953 sym_fw_setup_bus_addresses(np, fw); in sym_fw1_setup()
1961 sym_fw2_setup(hcb_p np, const struct sym_fw *fw) in sym_fw2_setup() argument
1965 scripta0 = (struct sym_fw2a_scr *) np->scripta0; in sym_fw2_setup()
1975 sym_fw_setup_bus_addresses(np, fw); in sym_fw2_setup()
2005 static void sym_fw_bind_script (hcb_p np, u32 *start, int len) in sym_fw_bind_script() argument
2026 sym_name(np), (int) (cur-start)); in sym_fw_bind_script()
2070 sym_name(np), (int) (cur-start)); in sym_fw_bind_script()
2078 !(np->features & FE_PFEN)) { in sym_fw_bind_script()
2086 if (!(np->features & FE_WIDE)) in sym_fw_bind_script()
2094 if (!(np->features & FE_WIDE)) in sym_fw_bind_script()
2144 new = (old & ~RELOC_MASK) + np->mmio_ba; in sym_fw_bind_script()
2147 new = (old & ~RELOC_MASK) + np->scripta_ba; in sym_fw_bind_script()
2150 new = (old & ~RELOC_MASK) + np->scriptb_ba; in sym_fw_bind_script()
2153 new = (old & ~RELOC_MASK) + np->hcb_ba; in sym_fw_bind_script()
2185 static void sym_save_initial_setting (hcb_p np);
2186 static int sym_prepare_setting (hcb_p np, struct sym_nvram *nvram);
2187 static int sym_prepare_nego (hcb_p np, ccb_p cp, int nego, u_char *msgptr);
2188 static void sym_put_start_queue (hcb_p np, ccb_p cp);
2189 static void sym_chip_reset (hcb_p np);
2190 static void sym_soft_reset (hcb_p np);
2191 static void sym_start_reset (hcb_p np);
2192 static int sym_reset_scsi_bus (hcb_p np, int enab_int);
2193 static int sym_wakeup_done (hcb_p np);
2194 static void sym_flush_busy_queue (hcb_p np, int cam_status);
2195 static void sym_flush_comp_queue (hcb_p np, int cam_status);
2196 static void sym_init (hcb_p np, int reason);
2197 static int sym_getsync(hcb_p np, u_char dt, u_char sfac, u_char *divp,
2199 static void sym_setsync (hcb_p np, ccb_p cp, u_char ofs, u_char per,
2201 static void sym_setwide (hcb_p np, ccb_p cp, u_char wide);
2202 static void sym_setpprot(hcb_p np, ccb_p cp, u_char dt, u_char ofs,
2204 static void sym_settrans(hcb_p np, ccb_p cp, u_char dt, u_char ofs,
2206 static void sym_log_hard_error (hcb_p np, u_short sist, u_char dstat);
2209 static void sym_recover_scsi_int (hcb_p np, u_char hsts);
2210 static void sym_int_sto (hcb_p np);
2211 static void sym_int_udc (hcb_p np);
2212 static void sym_int_sbmc (hcb_p np);
2213 static void sym_int_par (hcb_p np, u_short sist);
2214 static void sym_int_ma (hcb_p np);
2215 static int sym_dequeue_from_squeue(hcb_p np, int i, int target, int lun,
2217 static void sym_sir_bad_scsi_status (hcb_p np, ccb_p cp);
2218 static int sym_clear_tasks (hcb_p np, int status, int targ, int lun, int task);
2219 static void sym_sir_task_recovery (hcb_p np, int num);
2220 static int sym_evaluate_dp (hcb_p np, ccb_p cp, u32 scr, int *ofs);
2221 static void sym_modify_dp(hcb_p np, ccb_p cp, int ofs);
2222 static int sym_compute_residual (hcb_p np, ccb_p cp);
2225 static void sym_sync_nego (hcb_p np, tcb_p tp, ccb_p cp);
2226 static void sym_ppr_nego (hcb_p np, tcb_p tp, ccb_p cp);
2227 static void sym_wide_nego (hcb_p np, tcb_p tp, ccb_p cp);
2228 static void sym_nego_default (hcb_p np, tcb_p tp, ccb_p cp);
2229 static void sym_nego_rejected (hcb_p np, tcb_p tp, ccb_p cp);
2230 static void sym_int_sir (hcb_p np);
2231 static void sym_free_ccb (hcb_p np, ccb_p cp);
2232 static ccb_p sym_get_ccb (hcb_p np, u_char tn, u_char ln, u_char tag_order);
2233 static ccb_p sym_alloc_ccb (hcb_p np);
2234 static ccb_p sym_ccb_from_dsa (hcb_p np, u32 dsa);
2235 static lcb_p sym_alloc_lcb (hcb_p np, u_char tn, u_char ln);
2236 static void sym_alloc_lcb_tags (hcb_p np, u_char tn, u_char ln);
2237 static int sym_snooptest (hcb_p np);
2238 static void sym_selectclock(hcb_p np, u_char scntl3);
2239 static void sym_getclock (hcb_p np, int mult);
2240 static int sym_getpciclock (hcb_p np);
2241 static void sym_complete_ok (hcb_p np, ccb_p cp);
2242 static void sym_complete_error (hcb_p np, ccb_p cp);
2244 static int sym_abort_scsiio (hcb_p np, union ccb *ccb, int timed_out);
2245 static void sym_reset_dev (hcb_p np, union ccb *ccb);
2247 static int sym_setup_cdb (hcb_p np, struct ccb_scsiio *csio, ccb_p cp);
2248 static void sym_setup_data_and_start (hcb_p np, struct ccb_scsiio *csio,
2250 static int sym_fast_scatter_sg_physical(hcb_p np, ccb_p cp,
2252 static int sym_scatter_sg_physical (hcb_p np, ccb_p cp,
2255 static void sym_update_trans(hcb_p np, struct sym_trans *tip,
2257 static void sym_update_dflags(hcb_p np, u_char *flags,
2264 static void sym_pci_free (hcb_p np);
2265 static int sym_cam_attach (hcb_p np);
2266 static void sym_cam_free (hcb_p np);
2268 static void sym_nvram_setup_host (hcb_p np, struct sym_nvram *nvram);
2269 static void sym_nvram_setup_target (hcb_p np, int targ, struct sym_nvram *nvp);
2270 static int sym_read_nvram (hcb_p np, struct sym_nvram *nvp);
2276 static void PRINT_TARGET (hcb_p np, int target) in PRINT_TARGET() argument
2278 printf ("%s:%d:", sym_name(np), target); in PRINT_TARGET()
2281 static void PRINT_LUN(hcb_p np, int target, int lun) in PRINT_LUN() argument
2283 printf ("%s:%d:%d:", sym_name(np), target, lun); in PRINT_LUN()
2327 hcb_p np; in sym_enqueue_cam_ccb() local
2331 np = (hcb_p) cp->arg; in sym_enqueue_cam_ccb()
2339 ccb->ccb_h.sym_hcb_ptr = np; in sym_enqueue_cam_ccb()
2341 sym_insque_tail(sym_qptr(&ccb->ccb_h.sim_links), &np->cam_ccbq); in sym_enqueue_cam_ccb()
2348 static void sym_xpt_done(hcb_p np, union ccb *ccb, ccb_p cp) in sym_xpt_done() argument
2362 static void sym_xpt_done2(hcb_p np, union ccb *ccb, int cam_status) in sym_xpt_done2() argument
2410 static __inline void sym_init_burst(hcb_p np, u_char bc) in sym_init_burst() argument
2412 np->rv_ctest4 &= ~0x80; in sym_init_burst()
2413 np->rv_dmode &= ~(0x3 << 6); in sym_init_burst()
2414 np->rv_ctest5 &= ~0x4; in sym_init_burst()
2417 np->rv_ctest4 |= 0x80; in sym_init_burst()
2421 np->rv_dmode |= ((bc & 0x3) << 6); in sym_init_burst()
2422 np->rv_ctest5 |= (bc & 0x4); in sym_init_burst()
2429 static void sym_print_targets_flag(hcb_p np, int mask, char *msg) in sym_print_targets_flag() argument
2435 if (i == np->myaddr) in sym_print_targets_flag()
2437 if (np->target[i].usrflags & mask) { in sym_print_targets_flag()
2440 sym_name(np), msg); in sym_print_targets_flag()
2457 static void sym_save_initial_setting (hcb_p np) in sym_save_initial_setting() argument
2459 np->sv_scntl0 = INB(nc_scntl0) & 0x0a; in sym_save_initial_setting()
2460 np->sv_scntl3 = INB(nc_scntl3) & 0x07; in sym_save_initial_setting()
2461 np->sv_dmode = INB(nc_dmode) & 0xce; in sym_save_initial_setting()
2462 np->sv_dcntl = INB(nc_dcntl) & 0xa8; in sym_save_initial_setting()
2463 np->sv_ctest3 = INB(nc_ctest3) & 0x01; in sym_save_initial_setting()
2464 np->sv_ctest4 = INB(nc_ctest4) & 0x80; in sym_save_initial_setting()
2465 np->sv_gpcntl = INB(nc_gpcntl); in sym_save_initial_setting()
2466 np->sv_stest1 = INB(nc_stest1); in sym_save_initial_setting()
2467 np->sv_stest2 = INB(nc_stest2) & 0x20; in sym_save_initial_setting()
2468 np->sv_stest4 = INB(nc_stest4); in sym_save_initial_setting()
2469 if (np->features & FE_C10) { /* Always large DMA fifo + ultra3 */ in sym_save_initial_setting()
2470 np->sv_scntl4 = INB(nc_scntl4); in sym_save_initial_setting()
2471 np->sv_ctest5 = INB(nc_ctest5) & 0x04; in sym_save_initial_setting()
2474 np->sv_ctest5 = INB(nc_ctest5) & 0x24; in sym_save_initial_setting()
2481 static int sym_prepare_setting(hcb_p np, struct sym_nvram *nvram) in sym_prepare_setting() argument
2490 np->maxwide = (np->features & FE_WIDE)? 1 : 0; in sym_prepare_setting()
2495 if (np->features & FE_QUAD) in sym_prepare_setting()
2496 np->multiplier = 4; in sym_prepare_setting()
2497 else if (np->features & FE_DBLR) in sym_prepare_setting()
2498 np->multiplier = 2; in sym_prepare_setting()
2500 np->multiplier = 1; in sym_prepare_setting()
2502 np->clock_khz = (np->features & FE_CLK80)? 80000 : 40000; in sym_prepare_setting()
2503 np->clock_khz *= np->multiplier; in sym_prepare_setting()
2505 if (np->clock_khz != 40000) in sym_prepare_setting()
2506 sym_getclock(np, np->multiplier); in sym_prepare_setting()
2511 i = np->clock_divn - 1; in sym_prepare_setting()
2513 if (10ul * SYM_CONF_MIN_ASYNC * np->clock_khz > div_10M[i]) { in sym_prepare_setting()
2518 np->rv_scntl3 = i+1; in sym_prepare_setting()
2524 if (np->features & FE_C10) in sym_prepare_setting()
2525 np->rv_scntl3 = 0; in sym_prepare_setting()
2531 period = howmany(4 * div_10M[0], np->clock_khz); in sym_prepare_setting()
2532 if (period <= 250) np->minsync = 10; in sym_prepare_setting()
2533 else if (period <= 303) np->minsync = 11; in sym_prepare_setting()
2534 else if (period <= 500) np->minsync = 12; in sym_prepare_setting()
2535 else np->minsync = howmany(period, 40); in sym_prepare_setting()
2540 if (np->minsync < 25 && in sym_prepare_setting()
2541 !(np->features & (FE_ULTRA|FE_ULTRA2|FE_ULTRA3))) in sym_prepare_setting()
2542 np->minsync = 25; in sym_prepare_setting()
2543 else if (np->minsync < 12 && in sym_prepare_setting()
2544 !(np->features & (FE_ULTRA2|FE_ULTRA3))) in sym_prepare_setting()
2545 np->minsync = 12; in sym_prepare_setting()
2550 period = (11 * div_10M[np->clock_divn - 1]) / (4 * np->clock_khz); in sym_prepare_setting()
2551 np->maxsync = period > 2540 ? 254 : period / 10; in sym_prepare_setting()
2556 if ((np->features & (FE_C10|FE_ULTRA3)) == (FE_C10|FE_ULTRA3)) { in sym_prepare_setting()
2557 if (np->clock_khz == 160000) { in sym_prepare_setting()
2558 np->minsync_dt = 9; in sym_prepare_setting()
2559 np->maxsync_dt = 50; in sym_prepare_setting()
2560 np->maxoffs_dt = 62; in sym_prepare_setting()
2567 if (np->features & FE_DAC) in sym_prepare_setting()
2569 np->rv_ccntl1 |= (XTIMOD | EXTIBMV); in sym_prepare_setting()
2571 np->rv_ccntl1 |= (DDAC); in sym_prepare_setting()
2577 if (np->features & FE_NOPM) in sym_prepare_setting()
2578 np->rv_ccntl0 |= (ENPMJ); in sym_prepare_setting()
2585 if (np->device_id == PCI_ID_LSI53C1010 && in sym_prepare_setting()
2586 np->revision_id < 0x2) in sym_prepare_setting()
2587 np->rv_ccntl0 |= DILS; in sym_prepare_setting()
2594 burst_max = burst_code(np->sv_dmode, np->sv_ctest4, in sym_prepare_setting()
2595 np->sv_ctest5); in sym_prepare_setting()
2598 if (burst_max > np->maxburst) in sym_prepare_setting()
2599 burst_max = np->maxburst; in sym_prepare_setting()
2609 if ((np->device_id == PCI_ID_SYM53C810 && in sym_prepare_setting()
2610 np->revision_id >= 0x10 && np->revision_id <= 0x11) || in sym_prepare_setting()
2611 (np->device_id == PCI_ID_SYM53C860 && in sym_prepare_setting()
2612 np->revision_id <= 0x1)) in sym_prepare_setting()
2613 np->features &= ~(FE_WRIE|FE_ERL|FE_ERMP); in sym_prepare_setting()
2621 if (np->features & FE_ERL) in sym_prepare_setting()
2622 np->rv_dmode |= ERL; /* Enable Read Line */ in sym_prepare_setting()
2623 if (np->features & FE_BOF) in sym_prepare_setting()
2624 np->rv_dmode |= BOF; /* Burst Opcode Fetch */ in sym_prepare_setting()
2625 if (np->features & FE_ERMP) in sym_prepare_setting()
2626 np->rv_dmode |= ERMP; /* Enable Read Multiple */ in sym_prepare_setting()
2628 if ((np->features & FE_PFEN) && !np->ram_ba) in sym_prepare_setting()
2630 if (np->features & FE_PFEN) in sym_prepare_setting()
2632 np->rv_dcntl |= PFEN; /* Prefetch Enable */ in sym_prepare_setting()
2633 if (np->features & FE_CLSE) in sym_prepare_setting()
2634 np->rv_dcntl |= CLSE; /* Cache Line Size Enable */ in sym_prepare_setting()
2635 if (np->features & FE_WRIE) in sym_prepare_setting()
2636 np->rv_ctest3 |= WRIE; /* Write and Invalidate */ in sym_prepare_setting()
2637 if (np->features & FE_DFS) in sym_prepare_setting()
2638 np->rv_ctest5 |= DFS; /* Dma Fifo Size */ in sym_prepare_setting()
2644 np->rv_ctest4 |= MPEE; /* Master parity checking */ in sym_prepare_setting()
2646 np->rv_scntl0 |= 0x0a; /* full arb., ena parity, par->ATN */ in sym_prepare_setting()
2651 np->myaddr = 255; in sym_prepare_setting()
2652 sym_nvram_setup_host (np, nvram); in sym_prepare_setting()
2654 np->myaddr = OF_getscsinitid(np->device); in sym_prepare_setting()
2660 if (np->myaddr == 255) { in sym_prepare_setting()
2661 np->myaddr = INB(nc_scid) & 0x07; in sym_prepare_setting()
2662 if (!np->myaddr) in sym_prepare_setting()
2663 np->myaddr = SYM_SETUP_HOST_ID; in sym_prepare_setting()
2669 sym_init_burst(np, burst_max); in sym_prepare_setting()
2679 np->scsi_mode = SMODE_SE; in sym_prepare_setting()
2680 if (np->features & (FE_ULTRA2|FE_ULTRA3)) in sym_prepare_setting()
2681 np->scsi_mode = (np->sv_stest4 & SMODE); in sym_prepare_setting()
2682 else if (np->features & FE_DIFF) { in sym_prepare_setting()
2684 if (np->sv_scntl3) { in sym_prepare_setting()
2685 if (np->sv_stest2 & 0x20) in sym_prepare_setting()
2686 np->scsi_mode = SMODE_HVD; in sym_prepare_setting()
2690 np->scsi_mode = SMODE_HVD; in sym_prepare_setting()
2694 np->scsi_mode = SMODE_HVD; in sym_prepare_setting()
2696 if (np->scsi_mode == SMODE_HVD) in sym_prepare_setting()
2697 np->rv_stest2 |= 0x20; in sym_prepare_setting()
2708 np->device_id == PCI_ID_SYM53C895))) && in sym_prepare_setting()
2709 !(np->features & FE_LEDC) && !(np->sv_gpcntl & 0x01)) in sym_prepare_setting()
2710 np->features |= FE_LED0; in sym_prepare_setting()
2717 np->rv_dcntl |= IRQM; in sym_prepare_setting()
2720 np->rv_dcntl |= (np->sv_dcntl & IRQM); in sym_prepare_setting()
2731 tcb_p tp = &np->target[i]; in sym_prepare_setting()
2735 tp->tinfo.user.period = np->minsync; in sym_prepare_setting()
2736 if (np->features & FE_ULTRA3) in sym_prepare_setting()
2737 tp->tinfo.user.period = np->minsync_dt; in sym_prepare_setting()
2738 tp->tinfo.user.offset = np->maxoffs; in sym_prepare_setting()
2739 tp->tinfo.user.width = np->maxwide ? BUS_16_BIT : BUS_8_BIT; in sym_prepare_setting()
2743 sym_nvram_setup_target (np, i, nvram); in sym_prepare_setting()
2749 if (np->features & FE_ULTRA3) { in sym_prepare_setting()
2753 tp->tinfo.user.offset = np->maxoffs_dt; in sym_prepare_setting()
2766 printf("%s: %s NVRAM, ID %d, Fast-%d, %s, %s\n", sym_name(np), in sym_prepare_setting()
2769 np->myaddr, in sym_prepare_setting()
2770 (np->features & FE_ULTRA3) ? 80 : in sym_prepare_setting()
2771 (np->features & FE_ULTRA2) ? 40 : in sym_prepare_setting()
2772 (np->features & FE_ULTRA) ? 20 : 10, in sym_prepare_setting()
2773 sym_scsi_bus_mode(np->scsi_mode), in sym_prepare_setting()
2774 (np->rv_scntl0 & 0xa) ? "parity checking" : "NO parity"); in sym_prepare_setting()
2780 sym_name(np), in sym_prepare_setting()
2781 np->rv_dcntl & IRQM ? "totem pole" : "open drain", in sym_prepare_setting()
2782 np->ram_ba ? ", using on-chip SRAM" : ""); in sym_prepare_setting()
2783 printf("%s: using %s firmware.\n", sym_name(np), np->fw_name); in sym_prepare_setting()
2784 if (np->features & FE_NOPM) in sym_prepare_setting()
2786 sym_name(np)); in sym_prepare_setting()
2794 sym_name(np), np->sv_scntl3, np->sv_dmode, np->sv_dcntl, in sym_prepare_setting()
2795 np->sv_ctest3, np->sv_ctest4, np->sv_ctest5); in sym_prepare_setting()
2799 sym_name(np), np->rv_scntl3, np->rv_dmode, np->rv_dcntl, in sym_prepare_setting()
2800 np->rv_ctest3, np->rv_ctest4, np->rv_ctest5); in sym_prepare_setting()
2805 sym_print_targets_flag(np, SYM_SCAN_BOOT_DISABLED, "SCAN AT BOOT"); in sym_prepare_setting()
2807 sym_print_targets_flag(np, SYM_SCAN_LUNS_DISABLED, in sym_prepare_setting()
2820 static int sym_prepare_nego(hcb_p np, ccb_p cp, int nego, u_char *msgptr) in sym_prepare_nego() argument
2822 tcb_p tp = &np->target[cp->target]; in sym_prepare_nego()
2829 if (!(np->features & FE_U3EN)) in sym_prepare_nego()
2891 static void sym_put_start_queue(hcb_p np, ccb_p cp) in sym_put_start_queue() argument
2904 if (np->last_cp && np->iarb_count < np->iarb_max) { in sym_put_start_queue()
2905 np->last_cp->host_flags |= HF_HINT_IARB; in sym_put_start_queue()
2906 ++np->iarb_count; in sym_put_start_queue()
2909 np->iarb_count = 0; in sym_put_start_queue()
2910 np->last_cp = cp; in sym_put_start_queue()
2917 qidx = np->squeueput + 2; in sym_put_start_queue()
2920 np->squeue [qidx] = cpu_to_scr(np->idletask_ba); in sym_put_start_queue()
2922 np->squeue [np->squeueput] = cpu_to_scr(cp->ccb_ba); in sym_put_start_queue()
2924 np->squeueput = qidx; in sym_put_start_queue()
2927 printf ("%s: queuepos=%d.\n", sym_name (np), np->squeueput); in sym_put_start_queue()
2934 OUTB (nc_istat, SIGP|np->istat_sem); in sym_put_start_queue()
2945 static void sym_chip_reset (hcb_p np) in sym_chip_reset() argument
2962 static void sym_soft_reset (hcb_p np) in sym_soft_reset() argument
2982 sym_name(np)); in sym_soft_reset()
2983 sym_chip_reset (np); in sym_soft_reset()
2991 static void sym_start_reset(hcb_p np) in sym_start_reset() argument
2993 (void) sym_reset_scsi_bus(np, 1); in sym_start_reset()
2996 static int sym_reset_scsi_bus(hcb_p np, int enab_int) in sym_reset_scsi_bus() argument
3001 sym_soft_reset(np); /* Soft reset the chip */ in sym_reset_scsi_bus()
3009 OUTB (nc_dcntl, (np->rv_dcntl & IRQM)); in sym_reset_scsi_bus()
3028 if (!(np->features & FE_WIDE)) in sym_reset_scsi_bus()
3033 sym_name(np)); in sym_reset_scsi_bus()
3036 sym_name(np), in sym_reset_scsi_bus()
3037 (np->features & FE_WIDE) ? "dp1,d15-8," : "", in sym_reset_scsi_bus()
3055 static int sym_wakeup_done (hcb_p np) in sym_wakeup_done() argument
3064 i = np->dqueueget; in sym_wakeup_done()
3066 dsa = scr_to_cpu(np->dqueue[i]); in sym_wakeup_done()
3069 np->dqueue[i] = 0; in sym_wakeup_done()
3073 cp = sym_ccb_from_dsa(np, dsa); in sym_wakeup_done()
3076 sym_complete_ok (np, cp); in sym_wakeup_done()
3081 sym_name(np), (u_int) dsa); in sym_wakeup_done()
3083 np->dqueueget = i; in sym_wakeup_done()
3092 static void sym_flush_busy_queue (hcb_p np, int cam_status) in sym_flush_busy_queue() argument
3098 sym_que_splice(&np->busy_ccbq, &np->comp_ccbq); in sym_flush_busy_queue()
3099 sym_que_init(&np->busy_ccbq); in sym_flush_busy_queue()
3100 sym_flush_comp_queue(np, cam_status); in sym_flush_busy_queue()
3111 static void sym_init (hcb_p np, int reason) in sym_init() argument
3122 sym_soft_reset(np); in sym_init()
3131 phys = np->squeue_ba; in sym_init()
3133 np->squeue[i] = cpu_to_scr(np->idletask_ba); in sym_init()
3134 np->squeue[i+1] = cpu_to_scr(phys + (i+2)*4); in sym_init()
3136 np->squeue[MAX_QUEUE*2-1] = cpu_to_scr(phys); in sym_init()
3141 np->squeueput = 0; in sym_init()
3146 phys = np->dqueue_ba; in sym_init()
3148 np->dqueue[i] = 0; in sym_init()
3149 np->dqueue[i+1] = cpu_to_scr(phys + (i+2)*4); in sym_init()
3151 np->dqueue[MAX_QUEUE*2-1] = cpu_to_scr(phys); in sym_init()
3156 np->dqueueget = 0; in sym_init()
3163 np->fw_patch(np); in sym_init()
3168 sym_flush_busy_queue(np, CAM_SCSI_BUS_RESET); in sym_init()
3176 OUTB (nc_scntl0, np->rv_scntl0 | 0xc0); in sym_init()
3180 sym_selectclock(np, np->rv_scntl3); /* Select SCSI clock */ in sym_init()
3182 OUTB (nc_scid , RRE|np->myaddr); /* Adapter SCSI address */ in sym_init()
3183 OUTW (nc_respid, 1ul<<np->myaddr); /* Id to respond to */ in sym_init()
3185 OUTB (nc_dmode , np->rv_dmode); /* Burst length, dma mode */ in sym_init()
3186 OUTB (nc_ctest5, np->rv_ctest5); /* Large fifo + large burst */ in sym_init()
3188 OUTB (nc_dcntl , NOCOM|np->rv_dcntl); /* Protect SFBR */ in sym_init()
3189 OUTB (nc_ctest3, np->rv_ctest3); /* Write and invalidate */ in sym_init()
3190 OUTB (nc_ctest4, np->rv_ctest4); /* Master parity checking */ in sym_init()
3193 if (np->features & FE_C10) in sym_init()
3194 OUTB (nc_stest2, np->rv_stest2); in sym_init()
3196 OUTB (nc_stest2, EXT|np->rv_stest2); in sym_init()
3204 if (np->device_id == PCI_ID_LSI53C1010_2) in sym_init()
3214 if (np->device_id == PCI_ID_LSI53C1010 && in sym_init()
3223 if (np->device_id == PCI_ID_SYM53C875) in sym_init()
3225 else if (np->device_id == PCI_ID_SYM53C896) in sym_init()
3226 np->rv_ccntl0 |= DPR; in sym_init()
3233 if (np->features & (FE_DAC|FE_NOPM)) { in sym_init()
3234 OUTB (nc_ccntl0, np->rv_ccntl0); in sym_init()
3235 OUTB (nc_ccntl1, np->rv_ccntl1); in sym_init()
3242 if (np->features & FE_NOPM) { in sym_init()
3243 OUTL (nc_pmjad1, SCRIPTB_BA (np, pm_handle)); in sym_init()
3244 OUTL (nc_pmjad2, SCRIPTB_BA (np, pm_handle)); in sym_init()
3251 if (np->features & FE_LED0) in sym_init()
3253 else if (np->features & FE_LEDC) in sym_init()
3267 if (np->features & (FE_ULTRA2|FE_ULTRA3)) { in sym_init()
3273 np->scsi_mode = INB (nc_stest4) & SMODE; in sym_init()
3283 tcb_p tp = &np->target[i]; in sym_init()
3287 tp->head.wval = np->rv_scntl3; in sym_init()
3300 if (np->ram_ba) { in sym_init()
3303 sym_name(np)); in sym_init()
3304 if (np->ram_ws == 8192) { in sym_init()
3305 OUTRAM_OFF(4096, np->scriptb0, np->scriptb_sz); in sym_init()
3306 OUTL (nc_mmws, np->scr_ram_seg); in sym_init()
3307 OUTL (nc_mmrs, np->scr_ram_seg); in sym_init()
3308 OUTL (nc_sfs, np->scr_ram_seg); in sym_init()
3309 phys = SCRIPTB_BA (np, start64); in sym_init()
3312 phys = SCRIPTA_BA (np, init); in sym_init()
3313 OUTRAM_OFF(0, np->scripta0, np->scripta_sz); in sym_init()
3316 phys = SCRIPTA_BA (np, init); in sym_init()
3318 np->istat_sem = 0; in sym_init()
3320 OUTL (nc_dsa, np->hcb_ba); in sym_init()
3327 xpt_async(AC_BUS_RESET, np->path, NULL); in sym_init()
3335 sym_getsync(hcb_p np, u_char dt, u_char sfac, u_char *divp, u_char *fakp) in sym_getsync() argument
3337 u32 clk = np->clock_khz; /* SCSI clock frequency in kHz */ in sym_getsync()
3338 int div = np->clock_divn; /* Number of divisors supported */ in sym_getsync()
3366 if ((np->features & (FE_C10|FE_U3EN)) == FE_C10) { in sym_getsync()
3379 if (div == np->clock_divn) { /* Are we too fast ? */ in sym_getsync()
3428 sym_xpt_async_transfer_neg(hcb_p np, int target, u_int spi_valid) in sym_xpt_async_transfer_neg() argument
3433 tcb_p tp = &np->target[target]; in sym_xpt_async_transfer_neg()
3435 sts = xpt_create_path(&path, NULL, cam_sim_path(np->sim), target, in sym_xpt_async_transfer_neg()
3484 static void sym_setwide(hcb_p np, ccb_p cp, u_char wide) in sym_setwide() argument
3486 tcb_p tp = &np->target[cp->target]; in sym_setwide()
3488 sym_settrans(np, cp, 0, 0, 0, wide, 0, 0); in sym_setwide()
3498 sym_xpt_async_transfer_neg(np, cp->target, SYM_SPI_VALID_WDTR); in sym_setwide()
3506 sym_setsync(hcb_p np, ccb_p cp, u_char ofs, u_char per, u_char div, u_char fak) in sym_setsync() argument
3508 tcb_p tp = &np->target[cp->target]; in sym_setsync()
3511 sym_settrans(np, cp, 0, ofs, per, wide, div, fak); in sym_setsync()
3520 sym_xpt_async_transfer_neg(np, cp->target, SYM_SPI_VALID_SDTR); in sym_setsync()
3527 static void sym_setpprot(hcb_p np, ccb_p cp, u_char dt, u_char ofs, in sym_setpprot() argument
3530 tcb_p tp = &np->target[cp->target]; in sym_setpprot()
3532 sym_settrans(np, cp, dt, ofs, per, wide, div, fak); in sym_setpprot()
3542 sym_xpt_async_transfer_neg(np, cp->target, SYM_SPI_VALID_PPR); in sym_setpprot()
3548 static void sym_settrans(hcb_p np, ccb_p cp, u_char dt, u_char ofs, in sym_settrans() argument
3563 tp = &np->target[target]; in sym_settrans()
3571 sval, wval, uval, np->rv_scntl3); in sym_settrans()
3576 if (!(np->features & FE_C10)) in sym_settrans()
3586 if (!(np->features & FE_C10)) in sym_settrans()
3605 if (np->features & FE_C10) { in sym_settrans()
3608 assert(np->features & FE_U3EN); in sym_settrans()
3632 if (per < 50 && !(np->features & FE_C10)) in sym_settrans()
3641 if (np->features & FE_C10) { in sym_settrans()
3648 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { in sym_settrans()
3654 if (np->features & FE_C10) { in sym_settrans()
3686 static void sym_log_hard_error(hcb_p np, u_short sist, u_char dstat) in sym_log_hard_error() argument
3697 if (dsp > np->scripta_ba && in sym_log_hard_error()
3698 dsp <= np->scripta_ba + np->scripta_sz) { in sym_log_hard_error()
3699 script_ofs = dsp - np->scripta_ba; in sym_log_hard_error()
3700 script_size = np->scripta_sz; in sym_log_hard_error()
3701 script_base = (u_char *) np->scripta0; in sym_log_hard_error()
3704 else if (np->scriptb_ba < dsp && in sym_log_hard_error()
3705 dsp <= np->scriptb_ba + np->scriptb_sz) { in sym_log_hard_error()
3706 script_ofs = dsp - np->scriptb_ba; in sym_log_hard_error()
3707 script_size = np->scriptb_sz; in sym_log_hard_error()
3708 script_base = (u_char *) np->scriptb0; in sym_log_hard_error()
3718 sym_name (np), (unsigned)INB (nc_sdid)&0x0f, dstat, sist, in sym_log_hard_error()
3726 printf ("%s: script cmd = %08x\n", sym_name(np), in sym_log_hard_error()
3730 printf ("%s: regdump:", sym_name(np)); in sym_log_hard_error()
3740 pci_sts = pci_read_config(np->device, PCIR_STATUS, 2); in sym_log_hard_error()
3742 pci_write_config(np->device, PCIR_STATUS, pci_sts, 2); in sym_log_hard_error()
3744 sym_name(np), pci_sts & 0xf900); in sym_log_hard_error()
3811 static void sym_intr1 (hcb_p np) in sym_intr1() argument
3828 OUTB (nc_istat, (istat & SIGP) | INTF | np->istat_sem); in sym_intr1()
3831 (void)sym_wakeup_done (np); in sym_intr1()
3891 if (sist & PAR) sym_int_par (np, sist); in sym_intr1()
3892 else if (sist & MA) sym_int_ma (np); in sym_intr1()
3893 else if (dstat & SIR) sym_int_sir (np); in sym_intr1()
3911 xpt_print_path(np->path); in sym_intr1()
3913 sym_init (np, 1); in sym_intr1()
3917 OUTB (nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */ in sym_intr1()
3922 if (sist & SBMC) sym_int_sbmc (np); in sym_intr1()
3923 else if (sist & STO) sym_int_sto (np); in sym_intr1()
3924 else if (sist & UDC) sym_int_udc (np); in sym_intr1()
3936 sym_log_hard_error(np, sist, dstat); in sym_intr1()
3940 sym_start_reset(np); in sym_intr1()
3951 sym_name(np), istat, dstat, sist); in sym_intr1()
3956 hcb_p np = arg; in sym_intr() local
3998 static void sym_recover_scsi_int (hcb_p np, u_char hsts) in sym_recover_scsi_int() argument
4002 ccb_p cp = sym_ccb_from_dsa(np, dsa); in sym_recover_scsi_int()
4009 if ((!(dsp > SCRIPTA_BA (np, getjob_begin) && in sym_recover_scsi_int()
4010 dsp < SCRIPTA_BA (np, getjob_end) + 1)) && in sym_recover_scsi_int()
4011 (!(dsp > SCRIPTA_BA (np, ungetjob) && in sym_recover_scsi_int()
4012 dsp < SCRIPTA_BA (np, reselect) + 1)) && in sym_recover_scsi_int()
4013 (!(dsp > SCRIPTB_BA (np, sel_for_abort) && in sym_recover_scsi_int()
4014 dsp < SCRIPTB_BA (np, sel_for_abort_1) + 1)) && in sym_recover_scsi_int()
4015 (!(dsp > SCRIPTA_BA (np, done) && in sym_recover_scsi_int()
4016 dsp < SCRIPTA_BA (np, done_end) + 1))) { in sym_recover_scsi_int()
4017 OUTB (nc_ctest3, np->rv_ctest3 | CLF); /* clear dma fifo */ in sym_recover_scsi_int()
4027 OUTL_DSP (SCRIPTA_BA (np, complete_error)); in sym_recover_scsi_int()
4034 OUTL_DSP (SCRIPTA_BA (np, start)); in sym_recover_scsi_int()
4043 sym_start_reset(np); in sym_recover_scsi_int()
4049 static void sym_int_sto (hcb_p np) in sym_int_sto() argument
4055 if (dsp == SCRIPTA_BA (np, wf_sel_done) + 8) in sym_int_sto()
4056 sym_recover_scsi_int(np, HS_SEL_TIMEOUT); in sym_int_sto()
4058 sym_start_reset(np); in sym_int_sto()
4064 static void sym_int_udc (hcb_p np) in sym_int_udc() argument
4066 printf ("%s: unexpected disconnect\n", sym_name(np)); in sym_int_udc()
4067 sym_recover_scsi_int(np, HS_UNEXPECTED); in sym_int_udc()
4080 static void sym_int_sbmc (hcb_p np) in sym_int_sbmc() argument
4087 xpt_print_path(np->path); in sym_int_sbmc()
4089 sym_scsi_bus_mode(np->scsi_mode), sym_scsi_bus_mode(scsi_mode)); in sym_int_sbmc()
4095 sym_init (np, 2); in sym_int_sbmc()
4122 static void sym_int_par (hcb_p np, u_short sist) in sym_int_par() argument
4131 ccb_p cp = sym_ccb_from_dsa(np, dsa); in sym_int_par()
4134 sym_name(np), hsts, dbc, sbcl); in sym_int_par()
4140 sym_recover_scsi_int(np, HS_UNEXPECTED); in sym_int_par()
4167 np->msgout[0] = (phase == 7) ? M_PARITY : M_ID_ERROR; in sym_int_par()
4178 if (dsp == SCRIPTB_BA (np, pm_handle)) in sym_int_par()
4182 sym_int_ma (np); in sym_int_par()
4186 OUTL_DSP (SCRIPTA_BA (np, dispatch)); in sym_int_par()
4190 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_int_par()
4194 sym_start_reset(np); in sym_int_par()
4203 static void sym_int_ma (hcb_p np) in sym_int_ma() argument
4231 cp = sym_ccb_from_dsa(np, dsa); in sym_int_ma()
4242 if (np->features & FE_DFBC) in sym_int_ma()
4272 if (!(np->features & FE_C10)) in sym_int_ma()
4277 if (!(np->features & FE_C10)) in sym_int_ma()
4284 OUTB (nc_ctest3, np->rv_ctest3 | CLF); /* dma fifo */ in sym_int_ma()
4301 if (dsp > np->scripta_ba && in sym_int_ma()
4302 dsp <= np->scripta_ba + np->scripta_sz) { in sym_int_ma()
4303 vdsp = (u32 *)((char*)np->scripta0 + (dsp-np->scripta_ba-8)); in sym_int_ma()
4306 else if (dsp > np->scriptb_ba && in sym_int_ma()
4307 dsp <= np->scriptb_ba + np->scriptb_sz) { in sym_int_ma()
4308 vdsp = (u32 *)((char*)np->scriptb0 + (dsp-np->scriptb_ba-8)); in sym_int_ma()
4322 sym_name (np)); in sym_int_ma()
4328 sym_name (np)); in sym_int_ma()
4401 newcmd = SCRIPTA_BA (np, pm0_data); in sym_int_ma()
4405 newcmd = SCRIPTA_BA (np, pm1_data); in sym_int_ma()
4425 nxtdsp = SCRIPTA_BA (np, dispatch); in sym_int_ma()
4453 nxtdsp = SCRIPTB_BA (np, wsr_ma_helper); in sym_int_ma()
4505 nxtdsp = SCRIPTA_BA (np, dispatch); in sym_int_ma()
4509 nxtdsp = SCRIPTA_BA (np, dispatch); in sym_int_ma()
4519 if (dsp == SCRIPTA_BA (np, send_ident)) { in sym_int_ma()
4522 np->msgout[0] = M_IDENTIFY | cp->lun; in sym_int_ma()
4523 nxtdsp = SCRIPTB_BA (np, ident_break_atn); in sym_int_ma()
4526 nxtdsp = SCRIPTB_BA (np, ident_break); in sym_int_ma()
4528 else if (dsp == SCRIPTB_BA (np, send_wdtr) || in sym_int_ma()
4529 dsp == SCRIPTB_BA (np, send_sdtr) || in sym_int_ma()
4530 dsp == SCRIPTB_BA (np, send_ppr)) { in sym_int_ma()
4531 nxtdsp = SCRIPTB_BA (np, nego_bad_phase); in sym_int_ma()
4536 nxtdsp = SCRIPTA_BA (np, clrack); in sym_int_ma()
4547 sym_start_reset(np); in sym_int_ma()
4559 sym_dequeue_from_squeue(hcb_p np, int i, int target, int lun, int task) in sym_dequeue_from_squeue() argument
4574 while (i != np->squeueput) { in sym_dequeue_from_squeue()
4575 cp = sym_ccb_from_dsa(np, scr_to_cpu(np->squeue[i])); in sym_dequeue_from_squeue()
4586 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq); in sym_dequeue_from_squeue()
4590 np->squeue[j] = np->squeue[i]; in sym_dequeue_from_squeue()
4596 np->squeue[j] = np->squeue[i]; in sym_dequeue_from_squeue()
4597 np->squeueput = j; /* Update our current start queue pointer */ in sym_dequeue_from_squeue()
4617 sym_flush_comp_queue(hcb_p np, int cam_status) in sym_flush_comp_queue() argument
4622 while ((qp = sym_remque_head(&np->comp_ccbq)) != NULL) { in sym_flush_comp_queue()
4625 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq); in sym_flush_comp_queue()
4633 sym_xpt_done(np, ccb, cp); in sym_flush_comp_queue()
4634 sym_free_ccb(np, cp); in sym_flush_comp_queue()
4656 static void sym_sir_bad_scsi_status(hcb_p np, ccb_p cp) in sym_sir_bad_scsi_status() argument
4658 tcb_p tp = &np->target[cp->target]; in sym_sir_bad_scsi_status()
4671 i = (INL (nc_scratcha) - np->squeue_ba) / 4; in sym_sir_bad_scsi_status()
4678 if (np->last_cp) in sym_sir_bad_scsi_status()
4679 np->last_cp = NULL; in sym_sir_bad_scsi_status()
4693 sym_complete_error (np, cp); in sym_sir_bad_scsi_status()
4701 sym_complete_error (np, cp); in sym_sir_bad_scsi_status()
4709 (void) sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1); in sym_sir_bad_scsi_status()
4710 OUTL_DSP (SCRIPTA_BA (np, start)); in sym_sir_bad_scsi_status()
4718 cp->sv_resid = sym_compute_residual(np, cp); in sym_sir_bad_scsi_status()
4751 sym_prepare_nego (np,cp, nego, &cp->scsi_smsg2[msglen]); in sym_sir_bad_scsi_status()
4784 startp = SCRIPTB_BA (np, sdata_in); in sym_sir_bad_scsi_status()
4798 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA (np, select)); in sym_sir_bad_scsi_status()
4803 sym_put_start_queue(np, cp); in sym_sir_bad_scsi_status()
4808 sym_flush_comp_queue(np, 0); in sym_sir_bad_scsi_status()
4828 sym_clear_tasks(hcb_p np, int cam_status, int target, int lun, int task) in sym_clear_tasks() argument
4838 sym_que_splice(&np->busy_ccbq, &qtmp); in sym_clear_tasks()
4839 sym_que_init(&np->busy_ccbq); in sym_clear_tasks()
4855 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq); in sym_clear_tasks()
4858 sym_insque_tail(&cp->link_ccbq, &np->comp_ccbq); in sym_clear_tasks()
4911 static void sym_sir_task_recovery(hcb_p np, int num) in sym_sir_task_recovery() argument
4930 tp = &np->target[i]; in sym_sir_task_recovery()
4953 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { in sym_sir_task_recovery()
4969 tp = &np->target[target]; in sym_sir_task_recovery()
4970 np->abrt_sel.sel_id = target; in sym_sir_task_recovery()
4971 np->abrt_sel.sel_scntl3 = tp->head.wval; in sym_sir_task_recovery()
4972 np->abrt_sel.sel_sxfer = tp->head.sval; in sym_sir_task_recovery()
4973 OUTL(nc_dsa, np->hcb_ba); in sym_sir_task_recovery()
4974 OUTL_DSP (SCRIPTB_BA (np, sel_for_abort)); in sym_sir_task_recovery()
4985 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { in sym_sir_task_recovery()
4998 if (cp == np->last_cp) { in sym_sir_task_recovery()
5012 np->istat_sem = 0; in sym_sir_task_recovery()
5021 i = (INL (nc_scratcha) - np->squeue_ba) / 4; in sym_sir_task_recovery()
5022 i = sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1); in sym_sir_task_recovery()
5040 sym_flush_comp_queue(np, 0); in sym_sir_task_recovery()
5048 tp = &np->target[target]; in sym_sir_task_recovery()
5050 np->abrt_tbl.addr = cpu_to_scr(vtobus(np->abrt_msg)); in sym_sir_task_recovery()
5058 np->abrt_msg[0] = M_RESET; in sym_sir_task_recovery()
5059 np->abrt_tbl.size = 1; in sym_sir_task_recovery()
5085 np->abrt_msg[0] = M_IDENTIFY | lun; in sym_sir_task_recovery()
5086 np->abrt_msg[1] = M_ABORT; in sym_sir_task_recovery()
5087 np->abrt_tbl.size = 2; in sym_sir_task_recovery()
5097 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { in sym_sir_task_recovery()
5117 np->abrt_msg[0] = M_ABORT; in sym_sir_task_recovery()
5118 np->abrt_tbl.size = 1; in sym_sir_task_recovery()
5126 np->abrt_msg[0] = M_IDENTIFY | cp->lun; in sym_sir_task_recovery()
5135 np->abrt_msg[1] = M_ABORT; in sym_sir_task_recovery()
5136 np->abrt_tbl.size = 2; in sym_sir_task_recovery()
5139 np->abrt_msg[1] = cp->scsi_smsg[1]; in sym_sir_task_recovery()
5140 np->abrt_msg[2] = cp->scsi_smsg[2]; in sym_sir_task_recovery()
5141 np->abrt_msg[3] = M_ABORT_TAG; in sym_sir_task_recovery()
5142 np->abrt_tbl.size = 4; in sym_sir_task_recovery()
5160 tp = &np->target[target]; in sym_sir_task_recovery()
5165 if (np->abrt_msg[0] == M_ABORT) in sym_sir_task_recovery()
5178 if (np->abrt_msg[0] == M_RESET) { in sym_sir_task_recovery()
5180 tp->head.wval = np->rv_scntl3; in sym_sir_task_recovery()
5195 lun = np->abrt_msg[0] & 0x3f; in sym_sir_task_recovery()
5196 if (np->abrt_msg[1] == M_ABORT_TAG) in sym_sir_task_recovery()
5197 task = np->abrt_msg[2]; in sym_sir_task_recovery()
5204 i = (INL (nc_scratcha) - np->squeue_ba) / 4; in sym_sir_task_recovery()
5205 (void) sym_dequeue_from_squeue(np, i, target, lun, -1); in sym_sir_task_recovery()
5206 (void) sym_clear_tasks(np, CAM_REQ_ABORTED, target, lun, task); in sym_sir_task_recovery()
5207 sym_flush_comp_queue(np, 0); in sym_sir_task_recovery()
5212 if (np->abrt_msg[0] == M_RESET) in sym_sir_task_recovery()
5213 xpt_async(AC_SENT_BDR, np->path, NULL); in sym_sir_task_recovery()
5221 PRINT_TARGET(np, target); in sym_sir_task_recovery()
5222 sym_printl_hex("control msgout:", np->abrt_msg, in sym_sir_task_recovery()
5223 np->abrt_tbl.size); in sym_sir_task_recovery()
5224 np->abrt_tbl.size = cpu_to_scr(np->abrt_tbl.size); in sym_sir_task_recovery()
5259 static int sym_evaluate_dp(hcb_p np, ccb_p cp, u32 scr, int *ofs) in sym_evaluate_dp() argument
5272 if (dp_scr == SCRIPTA_BA (np, pm0_data)) in sym_evaluate_dp()
5274 else if (dp_scr == SCRIPTA_BA (np, pm1_data)) in sym_evaluate_dp()
5376 static void sym_modify_dp(hcb_p np, ccb_p cp, int ofs) in sym_modify_dp() argument
5396 dp_sg = sym_evaluate_dp(np, cp, dp_scr, &dp_ofs); in sym_modify_dp()
5426 dp_scr = SCRIPTA_BA (np, pm0_data); in sym_modify_dp()
5430 dp_scr = SCRIPTA_BA (np, pm1_data); in sym_modify_dp()
5452 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_modify_dp()
5456 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_modify_dp()
5473 static int sym_compute_residual(hcb_p np, ccb_p cp) in sym_compute_residual() argument
5506 sym_evaluate_dp(np, cp, scr_to_cpu(cp->phys.head.lastp), in sym_compute_residual()
5602 static void sym_sync_nego(hcb_p np, tcb_p tp, ccb_p cp) in sym_sync_nego() argument
5611 sym_print_msg(cp, "sync msgin", np->msgin); in sym_sync_nego()
5628 per = np->msgin[3]; in sym_sync_nego()
5629 ofs = np->msgin[4]; in sym_sync_nego()
5635 if (ofs > np->maxoffs) in sym_sync_nego()
5636 {chg = 1; ofs = np->maxoffs;} in sym_sync_nego()
5644 if (per < np->minsync) in sym_sync_nego()
5645 {chg = 1; per = np->minsync;} in sym_sync_nego()
5653 if (ofs && sym_getsync(np, 0, per, &div, &fak) < 0) in sym_sync_nego()
5668 sym_setsync (np, cp, ofs, per, div, fak); in sym_sync_nego()
5669 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_sync_nego()
5677 sym_setsync (np, cp, ofs, per, div, fak); in sym_sync_nego()
5679 np->msgout[0] = M_EXTENDED; in sym_sync_nego()
5680 np->msgout[1] = 3; in sym_sync_nego()
5681 np->msgout[2] = M_X_SYNC_REQ; in sym_sync_nego()
5682 np->msgout[3] = per; in sym_sync_nego()
5683 np->msgout[4] = ofs; in sym_sync_nego()
5688 sym_print_msg(cp, "sync msgout", np->msgout); in sym_sync_nego()
5691 np->msgin [0] = M_NOOP; in sym_sync_nego()
5693 OUTL_DSP (SCRIPTB_BA (np, sdtr_resp)); in sym_sync_nego()
5696 sym_setsync (np, cp, 0, 0, 0, 0); in sym_sync_nego()
5697 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_sync_nego()
5703 static void sym_ppr_nego(hcb_p np, tcb_p tp, ccb_p cp) in sym_ppr_nego() argument
5712 sym_print_msg(cp, "ppr msgin", np->msgin); in sym_ppr_nego()
5719 per = np->msgin[3]; in sym_ppr_nego()
5720 ofs = np->msgin[5]; in sym_ppr_nego()
5721 wide = np->msgin[6]; in sym_ppr_nego()
5722 dt = np->msgin[7] & PPR_OPT_DT; in sym_ppr_nego()
5737 if (wide > np->maxwide) in sym_ppr_nego()
5738 {chg = 1; wide = np->maxwide;} in sym_ppr_nego()
5739 if (!wide || !(np->features & FE_ULTRA3)) in sym_ppr_nego()
5746 if (!(np->features & FE_U3EN)) /* Broken U3EN bit not supported */ in sym_ppr_nego()
5749 if (dt != (np->msgin[7] & PPR_OPT_MASK)) chg = 1; in sym_ppr_nego()
5753 if (ofs > np->maxoffs_dt) in sym_ppr_nego()
5754 {chg = 1; ofs = np->maxoffs_dt;} in sym_ppr_nego()
5756 else if (ofs > np->maxoffs) in sym_ppr_nego()
5757 {chg = 1; ofs = np->maxoffs;} in sym_ppr_nego()
5766 if (per < np->minsync_dt) in sym_ppr_nego()
5767 {chg = 1; per = np->minsync_dt;} in sym_ppr_nego()
5769 else if (per < np->minsync) in sym_ppr_nego()
5770 {chg = 1; per = np->minsync;} in sym_ppr_nego()
5778 if (ofs && sym_getsync(np, dt, per, &div, &fak) < 0) in sym_ppr_nego()
5794 sym_setpprot (np, cp, dt, ofs, per, wide, div, fak); in sym_ppr_nego()
5795 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_ppr_nego()
5803 sym_setpprot (np, cp, dt, ofs, per, wide, div, fak); in sym_ppr_nego()
5805 np->msgout[0] = M_EXTENDED; in sym_ppr_nego()
5806 np->msgout[1] = 6; in sym_ppr_nego()
5807 np->msgout[2] = M_X_PPR_REQ; in sym_ppr_nego()
5808 np->msgout[3] = per; in sym_ppr_nego()
5809 np->msgout[4] = 0; in sym_ppr_nego()
5810 np->msgout[5] = ofs; in sym_ppr_nego()
5811 np->msgout[6] = wide; in sym_ppr_nego()
5812 np->msgout[7] = dt; in sym_ppr_nego()
5817 sym_print_msg(cp, "ppr msgout", np->msgout); in sym_ppr_nego()
5820 np->msgin [0] = M_NOOP; in sym_ppr_nego()
5822 OUTL_DSP (SCRIPTB_BA (np, ppr_resp)); in sym_ppr_nego()
5825 sym_setpprot (np, cp, 0, 0, 0, 0, 0, 0); in sym_ppr_nego()
5826 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_ppr_nego()
5842 static void sym_wide_nego(hcb_p np, tcb_p tp, ccb_p cp) in sym_wide_nego() argument
5851 sym_print_msg(cp, "wide msgin", np->msgin); in sym_wide_nego()
5868 wide = np->msgin[3]; in sym_wide_nego()
5873 if (wide > np->maxwide) in sym_wide_nego()
5874 {chg = 1; wide = np->maxwide;} in sym_wide_nego()
5891 sym_setwide (np, cp, wide); in sym_wide_nego()
5899 np->msgout[0] = M_EXTENDED; in sym_wide_nego()
5900 np->msgout[1] = 3; in sym_wide_nego()
5901 np->msgout[2] = M_X_SYNC_REQ; in sym_wide_nego()
5902 np->msgout[3] = tp->tinfo.goal.period; in sym_wide_nego()
5903 np->msgout[4] = tp->tinfo.goal.offset; in sym_wide_nego()
5906 sym_print_msg(cp, "sync msgout", np->msgout); in sym_wide_nego()
5911 OUTL_DSP (SCRIPTB_BA (np, sdtr_resp)); in sym_wide_nego()
5915 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_wide_nego()
5923 sym_setwide (np, cp, wide); in sym_wide_nego()
5925 np->msgout[0] = M_EXTENDED; in sym_wide_nego()
5926 np->msgout[1] = 2; in sym_wide_nego()
5927 np->msgout[2] = M_X_WIDE_REQ; in sym_wide_nego()
5928 np->msgout[3] = wide; in sym_wide_nego()
5930 np->msgin [0] = M_NOOP; in sym_wide_nego()
5935 sym_print_msg(cp, "wide msgout", np->msgout); in sym_wide_nego()
5938 OUTL_DSP (SCRIPTB_BA (np, wdtr_resp)); in sym_wide_nego()
5941 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_wide_nego()
5953 static void sym_nego_default(hcb_p np, tcb_p tp, ccb_p cp) in sym_nego_default() argument
5962 sym_setpprot (np, cp, 0, 0, 0, 0, 0, 0); in sym_nego_default()
5965 if (tp->tinfo.goal.period < np->minsync) in sym_nego_default()
5966 tp->tinfo.goal.period = np->minsync; in sym_nego_default()
5967 if (tp->tinfo.goal.offset > np->maxoffs) in sym_nego_default()
5968 tp->tinfo.goal.offset = np->maxoffs; in sym_nego_default()
5972 sym_setsync (np, cp, 0, 0, 0, 0); in sym_nego_default()
5975 sym_setwide (np, cp, 0); in sym_nego_default()
5978 np->msgin [0] = M_NOOP; in sym_nego_default()
5979 np->msgout[0] = M_NOOP; in sym_nego_default()
5987 static void sym_nego_rejected(hcb_p np, tcb_p tp, ccb_p cp) in sym_nego_rejected() argument
5989 sym_nego_default(np, tp, cp); in sym_nego_rejected()
5996 static void sym_int_sir (hcb_p np) in sym_int_sir() argument
6000 ccb_p cp = sym_ccb_from_dsa(np, dsa); in sym_int_sir()
6002 tcb_p tp = &np->target[target]; in sym_int_sir()
6015 sym_complete_error(np, cp); in sym_int_sir()
6024 sym_sir_task_recovery(np, num); in sym_int_sir()
6033 sym_name (np), target); in sym_int_sir()
6041 sym_name (np), target); in sym_int_sir()
6049 sym_name (np), target); in sym_int_sir()
6055 np->msgout[0] = M_RESET; in sym_int_sir()
6062 np->msgout[0] = M_ABORT; in sym_int_sir()
6069 np->msgout[0] = M_ABORT_TAG; in sym_int_sir()
6076 np->lastmsg = np->msgout[0]; in sym_int_sir()
6077 np->msgout[0] = M_NOOP; in sym_int_sir()
6079 sym_name (np), target, np->lastmsg); in sym_int_sir()
6086 np->lastmsg = np->msgout[0]; in sym_int_sir()
6087 np->msgout[0] = M_NOOP; in sym_int_sir()
6089 if (np->lastmsg == M_PARITY || np->lastmsg == M_ID_ERROR) { in sym_int_sir()
6105 sym_sir_bad_scsi_status(np, cp); in sym_int_sir()
6112 sym_print_msg(cp, "M_REJECT to send for ", np->msgin); in sym_int_sir()
6113 np->msgout[0] = M_REJECT; in sym_int_sir()
6166 switch (np->msgin [0]) { in sym_int_sir()
6173 switch (np->msgin [2]) { in sym_int_sir()
6176 sym_print_msg(cp,"modify DP",np->msgin); in sym_int_sir()
6177 tmp = (np->msgin[3]<<24) + (np->msgin[4]<<16) + in sym_int_sir()
6178 (np->msgin[5]<<8) + (np->msgin[6]); in sym_int_sir()
6179 sym_modify_dp(np, cp, tmp); in sym_int_sir()
6182 sym_sync_nego(np, tp, cp); in sym_int_sir()
6185 sym_ppr_nego(np, tp, cp); in sym_int_sir()
6188 sym_wide_nego(np, tp, cp); in sym_int_sir()
6203 sym_print_msg(cp,"ign wide residue", np->msgin); in sym_int_sir()
6204 sym_modify_dp(np, cp, -1); in sym_int_sir()
6208 sym_nego_rejected(np, tp, cp); in sym_int_sir()
6212 scr_to_cpu(np->lastmsg), np->msgout[0]); in sym_int_sir()
6225 sym_print_msg(cp, "WEIRD message received", np->msgin); in sym_int_sir()
6226 OUTL_DSP (SCRIPTB_BA (np, msg_weird)); in sym_int_sir()
6240 sym_nego_default(np, tp, cp); in sym_int_sir()
6248 OUTL_DSP (SCRIPTB_BA (np, msg_bad)); in sym_int_sir()
6251 OUTL_DSP (SCRIPTA_BA (np, clrack)); in sym_int_sir()
6260 static ccb_p sym_get_ccb (hcb_p np, u_char tn, u_char ln, u_char tag_order) in sym_get_ccb() argument
6262 tcb_p tp = &np->target[tn]; in sym_get_ccb()
6271 if (sym_que_empty(&np->free_ccbq)) in sym_get_ccb()
6273 qp = sym_remque_head(&np->free_ccbq); in sym_get_ccb()
6283 lp = sym_alloc_lcb(np, tn, ln); in sym_get_ccb()
6312 sym_alloc_lcb_tags(np, tn, ln); in sym_get_ccb()
6329 cpu_to_scr(SCRIPTA_BA (np, resel_tag)); in sym_get_ccb()
6352 cpu_to_scr(SCRIPTA_BA (np, resel_no_tag)); in sym_get_ccb()
6361 sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq); in sym_get_ccb()
6372 PRINT_LUN(np, tn, ln); in sym_get_ccb()
6379 sym_insque_head(&cp->link_ccbq, &np->free_ccbq); in sym_get_ccb()
6386 static void sym_free_ccb(hcb_p np, ccb_p cp) in sym_free_ccb() argument
6388 tcb_p tp = &np->target[cp->target]; in sym_free_ccb()
6392 PRINT_LUN(np, cp->target, cp->lun); in sym_free_ccb()
6414 lp->itlq_tbl[cp->tag] = cpu_to_scr(np->bad_itlq_ba); in sym_free_ccb()
6421 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba); in sym_free_ccb()
6429 cpu_to_scr(SCRIPTB_BA (np, resel_bad_lun)); in sym_free_ccb()
6451 if (cp == np->last_cp) in sym_free_ccb()
6452 np->last_cp = NULL; in sym_free_ccb()
6459 bus_dmamap_unload(np->data_dmat, cp->dmamap); in sym_free_ccb()
6469 sym_insque_head(&cp->link_ccbq, &np->free_ccbq); in sym_free_ccb()
6475 static ccb_p sym_alloc_ccb(hcb_p np) in sym_alloc_ccb() argument
6486 if (np->actccbs >= SYM_CONF_MAX_START) in sym_alloc_ccb()
6506 if (bus_dmamap_create(np->data_dmat, 0, &cp->dmamap)) in sym_alloc_ccb()
6511 np->actccbs++; in sym_alloc_ccb()
6527 cp->link_ccbh = np->ccbh[hcode]; in sym_alloc_ccb()
6528 np->ccbh[hcode] = cp; in sym_alloc_ccb()
6533 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA (np, idle)); in sym_alloc_ccb()
6534 cp->phys.head.go.restart = cpu_to_scr(SCRIPTB_BA (np, bad_i_t_l)); in sym_alloc_ccb()
6539 cp->phys.smsg_ext.addr = cpu_to_scr(HCB_BA(np, msgin[2])); in sym_alloc_ccb()
6544 sym_insque_head(&cp->link_ccbq, &np->free_ccbq); in sym_alloc_ccb()
6557 static ccb_p sym_ccb_from_dsa(hcb_p np, u32 dsa) in sym_ccb_from_dsa() argument
6563 cp = np->ccbh[hcode]; in sym_ccb_from_dsa()
6576 static lcb_p sym_alloc_lcb (hcb_p np, u_char tn, u_char ln) in sym_alloc_lcb() argument
6578 tcb_p tp = &np->target[tn]; in sym_alloc_lcb()
6602 tp->luntbl[i] = cpu_to_scr(vtobus(&np->badlun_sa)); in sym_alloc_lcb()
6635 lp->head.itl_task_sa = cpu_to_scr(np->bad_itl_ba); in sym_alloc_lcb()
6640 lp->head.resel_sa = cpu_to_scr(SCRIPTB_BA (np, resel_bad_lun)); in sym_alloc_lcb()
6654 static void sym_alloc_lcb_tags (hcb_p np, u_char tn, u_char ln) in sym_alloc_lcb_tags() argument
6656 tcb_p tp = &np->target[tn]; in sym_alloc_lcb_tags()
6663 if (!lp && !(lp = sym_alloc_lcb(np, tn, ln))) in sym_alloc_lcb_tags()
6684 lp->itlq_tbl[i] = cpu_to_scr(np->notask_ba); in sym_alloc_lcb_tags()
6705 static int sym_regtest (hcb_p np) argument
6729 static int sym_snooptest (hcb_p np) argument
6734 err |= sym_regtest (np);
6742 OUTB (nc_ctest4, (np->rv_ctest4 & MPEE));
6746 pc = SCRIPTB0_BA (np, snooptest);
6752 np->cache = cpu_to_scr(host_wr);
6757 OUTL (nc_dsa, np->hcb_ba);
6774 if ((dstat & MDPE) && (np->rv_ctest4 & MPEE)) {
6777 sym_name(np));
6778 np->rv_ctest4 &= ~MPEE;
6793 host_rd = scr_to_cpu(np->cache);
6800 if (pc != SCRIPTB0_BA (np, snoopend)+8) {
6803 (u_long) SCRIPTB0_BA (np, snooptest), (u_long) pc,
6804 (u_long) SCRIPTB0_BA (np, snoopend) +8);
6850 static void sym_selectclock(hcb_p np, u_char scntl3) argument
6855 if (np->multiplier <= 1) {
6861 printf ("%s: enabling clock multiplier\n", sym_name(np));
6868 if (np->features & FE_LCKFRQ) {
6874 sym_name(np));
6886 static unsigned getfreq (hcb_p np, int gen) argument
6930 sym_name(np), gen, ms, f);
6935 static unsigned sym_getfreq (hcb_p np) argument
6940 (void) getfreq (np, gen); /* throw away first result */
6941 f1 = getfreq (np, gen);
6942 f2 = getfreq (np, gen);
6950 static void sym_getclock (hcb_p np, int mult) argument
6952 unsigned char scntl3 = np->sv_scntl3;
6953 unsigned char stest1 = np->sv_stest1;
6959 if (np->features & FE_C10) {
6960 np->multiplier = mult;
6961 np->clock_khz = 40000 * mult;
6965 np->multiplier = 1;
6972 printf ("%s: clock multiplier found\n", sym_name(np));
6973 np->multiplier = mult;
6981 if (np->multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) {
6983 f1 = sym_getfreq (np);
6986 printf ("%s: chip clock is %uKHz\n", sym_name(np), f1);
6995 sym_name(np));
6996 np->multiplier = mult;
7003 f1 /= np->multiplier;
7009 f1 *= np->multiplier;
7010 np->clock_khz = f1;
7016 static int sym_getpciclock (hcb_p np) argument
7025 if (!(np->features & FE_C10)) {
7027 f = (int) sym_getfreq (np);
7030 np->pciclk_khz = f;
7093 static void sym_complete_error (hcb_p np, ccb_p cp) argument
7133 csio->resid = sym_compute_residual(np, cp);
7176 sym_clear_tasks(np, CAM_REQ_ABORTED,
7211 i = (INL (nc_scratcha) - np->squeue_ba) / 4;
7212 (void) sym_dequeue_from_squeue(np, i, cp->target, cp->lun, -1);
7217 OUTL_DSP (SCRIPTA_BA (np, start));
7223 bus_dmamap_sync(np->data_dmat, cp->dmamap,
7234 sym_insque_head(&cp->link_ccbq, &np->comp_ccbq);
7235 sym_flush_comp_queue(np, 0);
7247 static void sym_complete_ok (hcb_p np, ccb_p cp) argument
7266 tp = &np->target[cp->target];
7281 csio->resid = sym_compute_residual(np, cp);
7295 bus_dmamap_sync(np->data_dmat, cp->dmamap,
7304 sym_xpt_done(np, (union ccb *) csio, cp);
7305 sym_free_ccb(np, cp);
7314 hcb_p np = ccb->ccb_h.sym_hcb_ptr; local
7319 if (!np)
7326 (void) sym_abort_scsiio(np, ccb, 1);
7338 static int sym_abort_scsiio(hcb_p np, union ccb *ccb, int timed_out) argument
7349 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
7364 sym_reset_scsi_bus(np, 1);
7377 np->istat_sem = SEM;
7385 static void sym_reset_dev(hcb_p np, union ccb *ccb) argument
7392 if (ccb_h->target_id == np->myaddr ||
7395 sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
7399 tp = &np->target[ccb_h->target_id];
7402 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
7404 np->istat_sem = SEM;
7413 hcb_p np; local
7428 np = (hcb_p) cam_sim_softc(sim);
7455 if (ccb_h->target_id == np->myaddr ||
7458 sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
7465 tp = &np->target[ccb_h->target_id];
7487 sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
7496 cp = sym_get_ccb(np, ccb_h->target_id, ccb_h->target_lun, tmp);
7498 sym_xpt_done2(np, ccb, CAM_RESRC_UNAVAIL);
7558 msglen += sym_prepare_nego(np, cp, 0, msgptr + msglen);
7568 cp->phys.head.go.start = cpu_to_scr(SCRIPTA_BA (np, select));
7569 cp->phys.head.go.restart = cpu_to_scr(SCRIPTA_BA (np, resel_dsa));
7588 if (sym_setup_cdb(np, csio, cp) < 0) {
7589 sym_xpt_done(np, ccb, cp);
7590 sym_free_ccb(np, cp);
7618 sym_setup_data_and_start(np, csio, cp);
7626 static int sym_setup_cdb(hcb_p np, struct ccb_scsiio *csio, ccb_p cp) argument
7676 sym_setup_data_pointers(hcb_p np, ccb_p cp, int dir) argument
7693 goalp = SCRIPTA_BA (np, data_out2) + 8;
7698 goalp = SCRIPTA_BA (np, data_in2) + 8;
7703 lastp = goalp = SCRIPTB_BA (np, no_data);
7722 hcb_p np; local
7727 np = (hcb_p) cp->arg;
7752 if (np->device_id == PCI_ID_SYM53C896 && np->revision_id <= 1)
7753 retv = sym_scatter_sg_physical(np, cp, psegs, nsegs);
7755 retv = sym_fast_scatter_sg_physical(np,cp, psegs,nsegs);
7767 bus_dmamap_sync(np->data_dmat, cp->dmamap,
7781 sym_setup_data_pointers(np, cp, (ccb->ccb_h.flags & CAM_DIR_MASK));
7807 sym_put_start_queue(np, cp);
7810 sym_xpt_done(np, ccb, cp);
7811 sym_free_ccb(np, cp);
7819 sym_setup_data_and_start(hcb_p np, struct ccb_scsiio *csio, ccb_p cp) argument
7832 cp->arg = np;
7844 retv = bus_dmamap_load_ccb(np->data_dmat, cp->dmamap,
7848 xpt_freeze_simq(np->sim, 1);
7857 sym_fast_scatter_sg_physical(hcb_p np, ccb_p cp, argument
7877 sym_name(np), (long) psegs2->ds_addr,
7894 sym_scatter_sg_physical(hcb_p np, ccb_p cp, bus_dma_segment_t *psegs, int nsegs) argument
7914 sym_name(np), pn, k);
7944 hcb_p np; local
7952 np = (hcb_p) cam_sim_softc(sim);
7961 tp = &np->target[ccb_h->target_id];
7969 sym_update_trans(np, &tp->tinfo.goal, cts);
7971 sym_update_dflags(np, &lp->current_flags, cts);
7974 sym_update_trans(np, &tp->tinfo.user, cts);
7976 sym_update_dflags(np, &lp->user_flags, cts);
7979 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
7983 tp = &np->target[ccb_h->target_id];
8023 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8027 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8033 if ((np->features & FE_WIDE) != 0)
8037 if (np->usrflags & SYM_SCAN_TARGETS_HILO)
8039 if (np->usrflags & SYM_AVOID_BUS_RESET)
8042 cpi->max_target = (np->features & FE_WIDE) ? 15 : 7;
8048 cpi->initiator_id = np->myaddr;
8060 if (np->features & FE_ULTRA3) {
8066 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8072 if (sym_abort_scsiio(np, abort_ccb, 0) == 0) {
8073 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8077 sym_xpt_done2(np, ccb, CAM_UA_ABORT);
8082 sym_reset_dev(np, ccb);
8085 sym_reset_scsi_bus(np, 0);
8087 xpt_print_path(np->path);
8090 sym_init (np, 1);
8091 sym_xpt_done2(np, ccb, CAM_REQ_CMP);
8095 sym_xpt_done2(np, ccb, CAM_REQ_INVALID);
8106 hcb_p np; local
8112 np = (hcb_p) cam_sim_softc(sim);
8122 tp = &np->target[tn];
8126 tp->head.wval = np->rv_scntl3;
8143 static void sym_update_trans(hcb_p np, struct sym_trans *tip, argument
8183 if (tip->width > np->maxwide)
8184 tip->width = np->maxwide;
8189 if (!((np->features & (FE_C10|FE_ULTRA3)) == (FE_C10|FE_ULTRA3)) ||
8199 if (tip->period < np->minsync_dt)
8200 tip->period = np->minsync_dt;
8201 if (tip->period > np->maxsync_dt)
8202 tip->period = np->maxsync_dt;
8203 if (tip->offset > np->maxoffs_dt)
8204 tip->offset = np->maxoffs_dt;
8207 if (tip->period < np->minsync)
8208 tip->period = np->minsync;
8209 if (tip->period > np->maxsync)
8210 tip->period = np->maxsync;
8211 if (tip->offset > np->maxoffs)
8212 tip->offset = np->maxoffs;
8221 sym_update_dflags(hcb_p np, u_char *flags, struct ccb_trans_settings *cts) argument
8403 struct sym_hcb *np = NULL; local
8425 np = __sym_calloc_dma(bus_dmat, sizeof(*np), "HCB");
8426 if (np)
8427 np->bus_dmat = bus_dmat;
8430 device_set_softc(dev, np);
8437 np->hcb_ba = vtobus(np);
8438 np->verbose = bootverbose;
8439 np->device = dev;
8440 np->device_id = pci_get_device(dev);
8441 np->revision_id = pci_get_revid(dev);
8442 np->features = chip->features;
8443 np->clock_divn = chip->nr_divisor;
8444 np->maxoffs = chip->offset_max;
8445 np->maxburst = chip->burst_max;
8446 np->scripta_sz = fw->a_size;
8447 np->scriptb_sz = fw->b_size;
8448 np->fw_setup = fw->setup;
8449 np->fw_patch = fw->patch;
8450 np->fw_name = fw->name;
8453 np->target = sym_calloc_dma(SYM_CONF_MAX_TARGET * sizeof(*(np->target)),
8455 if (!np->target)
8462 sym_que_init(&np->free_ccbq);
8463 sym_que_init(&np->busy_ccbq);
8464 sym_que_init(&np->comp_ccbq);
8465 sym_que_init(&np->cam_ccbq);
8470 if (bus_dma_tag_create(np->bus_dmat, 1, SYM_CONF_DMA_BOUNDARY,
8473 0, busdma_lock_mutex, &np->mtx, &np->data_dmat)) {
8504 np->mmio_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &i,
8506 if (!np->mmio_res) {
8510 np->mmio_ba = rman_get_start(np->mmio_res);
8516 np->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &i,
8518 if (!np->irq_res) {
8529 np->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &i, RF_ACTIVE);
8530 if (!np->io_res) {
8541 if (np->features & (FE_RAM|FE_RAM8K)) {
8543 if (np->features & FE_64BIT)
8545 np->ram_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
8547 if (!np->ram_res) {
8551 np->ram_id = regs_id;
8552 np->ram_ba = rman_get_start(np->ram_res);
8559 sym_save_initial_setting (np);
8566 sym_chip_reset (np);
8571 (void) sym_read_nvram(np, &nvram);
8577 (void) sym_prepare_setting(np, &nvram);
8584 i = sym_getpciclock(np);
8591 np->squeue = (u32 *) sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"SQUEUE");
8592 if (!np->squeue)
8594 np->squeue_ba = vtobus(np->squeue);
8599 np->dqueue = (u32 *) sym_calloc_dma(sizeof(u32)*(MAX_QUEUE*2),"DQUEUE");
8600 if (!np->dqueue)
8602 np->dqueue_ba = vtobus(np->dqueue);
8607 np->targtbl = (u32 *) sym_calloc_dma(256, "TARGTBL");
8608 if (!np->targtbl)
8610 np->targtbl_ba = vtobus(np->targtbl);
8615 np->scripta0 = sym_calloc_dma(np->scripta_sz, "SCRIPTA0");
8616 np->scriptb0 = sym_calloc_dma(np->scriptb_sz, "SCRIPTB0");
8617 if (!np->scripta0 || !np->scriptb0)
8623 for (i = 0; sym_alloc_ccb(np) != NULL; i++)
8632 np->scripta_ba = vtobus(np->scripta0);
8633 np->scriptb_ba = vtobus(np->scriptb0);
8634 np->scriptb0_ba = np->scriptb_ba;
8636 if (np->ram_ba) {
8637 np->scripta_ba = np->ram_ba;
8638 if (np->features & FE_RAM8K) {
8639 np->ram_ws = 8192;
8640 np->scriptb_ba = np->scripta_ba + 4096;
8642 np->scr_ram_seg = cpu_to_scr(np->scripta_ba >> 32);
8646 np->ram_ws = 4096;
8652 bcopy(fw->a_base, np->scripta0, np->scripta_sz);
8653 bcopy(fw->b_base, np->scriptb0, np->scriptb_sz);
8659 np->fw_setup(np, fw);
8665 sym_fw_bind_script(np, (u32 *) np->scripta0, np->scripta_sz);
8666 sym_fw_bind_script(np, (u32 *) np->scriptb0, np->scriptb_sz);
8676 np->iarb_max = SYM_SETUP_IARB_MAX;
8678 np->iarb_max = 4;
8685 np->idletask.start = cpu_to_scr(SCRIPTA_BA (np, idle));
8686 np->idletask.restart = cpu_to_scr(SCRIPTB_BA (np, bad_i_t_l));
8687 np->idletask_ba = vtobus(&np->idletask);
8689 np->notask.start = cpu_to_scr(SCRIPTA_BA (np, idle));
8690 np->notask.restart = cpu_to_scr(SCRIPTB_BA (np, bad_i_t_l));
8691 np->notask_ba = vtobus(&np->notask);
8693 np->bad_itl.start = cpu_to_scr(SCRIPTA_BA (np, idle));
8694 np->bad_itl.restart = cpu_to_scr(SCRIPTB_BA (np, bad_i_t_l));
8695 np->bad_itl_ba = vtobus(&np->bad_itl);
8697 np->bad_itlq.start = cpu_to_scr(SCRIPTA_BA (np, idle));
8698 np->bad_itlq.restart = cpu_to_scr(SCRIPTB_BA (np,bad_i_t_l_q));
8699 np->bad_itlq_ba = vtobus(&np->bad_itlq);
8707 np->badluntbl = sym_calloc_dma(256, "BADLUNTBL");
8708 if (!np->badluntbl)
8711 np->badlun_sa = cpu_to_scr(SCRIPTB_BA (np, resel_bad_lun));
8713 np->badluntbl[i] = cpu_to_scr(vtobus(&np->badlun_sa));
8721 np->targtbl[i] = cpu_to_scr(vtobus(&np->target[i]));
8722 np->target[i].head.luntbl_sa =
8723 cpu_to_scr(vtobus(np->badluntbl));
8724 np->target[i].head.lun0_sa =
8725 cpu_to_scr(vtobus(&np->badlun_sa));
8731 if (sym_snooptest (np)) {
8740 if (!sym_cam_attach(np))
8755 if (np)
8756 sym_pci_free(np);
8763 static void sym_pci_free(hcb_p np) argument
8774 sym_cam_free(np);
8780 if (np->ram_res)
8781 bus_release_resource(np->device, SYS_RES_MEMORY,
8782 np->ram_id, np->ram_res);
8783 if (np->mmio_res)
8784 bus_release_resource(np->device, SYS_RES_MEMORY,
8785 SYM_PCI_MMIO, np->mmio_res);
8786 if (np->io_res)
8787 bus_release_resource(np->device, SYS_RES_IOPORT,
8788 SYM_PCI_IO, np->io_res);
8789 if (np->irq_res)
8790 bus_release_resource(np->device, SYS_RES_IRQ,
8791 0, np->irq_res);
8793 if (np->scriptb0)
8794 sym_mfree_dma(np->scriptb0, np->scriptb_sz, "SCRIPTB0");
8795 if (np->scripta0)
8796 sym_mfree_dma(np->scripta0, np->scripta_sz, "SCRIPTA0");
8797 if (np->squeue)
8798 sym_mfree_dma(np->squeue, sizeof(u32)*(MAX_QUEUE*2), "SQUEUE");
8799 if (np->dqueue)
8800 sym_mfree_dma(np->dqueue, sizeof(u32)*(MAX_QUEUE*2), "DQUEUE");
8802 while ((qp = sym_remque_head(&np->free_ccbq)) != NULL) {
8804 bus_dmamap_destroy(np->data_dmat, cp->dmamap);
8809 if (np->badluntbl)
8810 sym_mfree_dma(np->badluntbl, 256,"BADLUNTBL");
8813 tp = &np->target[target];
8833 if (np->target)
8834 sym_mfree_dma(np->target,
8835 SYM_CONF_MAX_TARGET * sizeof(*(np->target)), "TARGET");
8837 if (np->targtbl)
8838 sym_mfree_dma(np->targtbl, 256, "TARGTBL");
8839 if (np->data_dmat)
8840 bus_dma_tag_destroy(np->data_dmat);
8843 device_set_softc(np->device, NULL);
8844 sym_mfree_dma(np, sizeof(*np), "HCB");
8850 static int sym_cam_attach(hcb_p np) argument
8860 err = bus_setup_intr(np->device, np->irq_res,
8862 NULL, sym_intr, np, &np->intr);
8864 device_printf(np->device, "bus_setup_intr() failed: %d\n",
8879 sim = cam_sim_alloc(sym_action, sym_poll, "sym", np,
8880 device_get_unit(np->device),
8881 &np->mtx, 1, SYM_SETUP_MAX_TAG, devq);
8887 if (xpt_bus_register(sim, np->device, 0) != CAM_SUCCESS)
8889 np->sim = sim;
8893 cam_sim_path(np->sim), CAM_TARGET_WILDCARD,
8897 np->path = path;
8902 if (xpt_register_async(AC_LOST_DEVICE, sym_async, np->sim, path) !=
8912 sym_init (np, 0);
8925 sym_cam_free(np);
8933 static void sym_cam_free(hcb_p np) argument
8938 if (np->intr) {
8939 bus_teardown_intr(np->device, np->irq_res, np->intr);
8940 np->intr = NULL;
8945 if (np->sim) {
8946 xpt_bus_deregister(cam_sim_path(np->sim));
8947 cam_sim_free(np->sim, /*free_devq*/ TRUE);
8948 np->sim = NULL;
8950 if (np->path) {
8951 xpt_free_path(np->path);
8952 np->path = NULL;
8963 static void sym_nvram_setup_host (hcb_p np, struct sym_nvram *nvram) argument
8973 np->rv_scntl0 &= ~0x0a;
8974 np->myaddr = nvram->data.Symbios.host_id & 0x0f;
8976 np->verbose += 1;
8978 np->usrflags |= SYM_SCAN_TARGETS_HILO;
8980 np->usrflags |= SYM_AVOID_BUS_RESET;
8983 np->myaddr = nvram->data.Tekram.host_id & 0x0f;
8995 static void sym_Symbios_setup_target(hcb_p np,int target, Symbios_nvram *nvram);
8996 static void sym_Tekram_setup_target(hcb_p np,int target, Tekram_nvram *nvram);
9000 sym_nvram_setup_target (hcb_p np, int target, struct sym_nvram *nvp) argument
9005 sym_Symbios_setup_target (np, target, &nvp->data.Symbios);
9008 sym_Tekram_setup_target (np, target, &nvp->data.Tekram);
9021 sym_Symbios_setup_target(hcb_p np, int target, Symbios_nvram *nvram) argument
9023 tcb_p tp = &np->target[target];
9043 sym_Tekram_setup_target(hcb_p np, int target, Tekram_nvram *nvram) argument
9045 tcb_p tp = &np->target[target];
9066 np->rv_scntl0 &= ~0x0a; /* SCSI parity checking disabled */
9073 static void sym_display_Symbios_nvram(hcb_p np, Symbios_nvram *nvram) argument
9079 sym_name(np), nvram->host_id & 0x0f,
9091 sym_name(np), i,
9106 static void sym_display_Tekram_nvram(hcb_p np, Tekram_nvram *nvram) argument
9124 sym_name(np), nvram->host_id & 0x0f,
9142 sym_name(np), i,
9159 static int sym_read_Symbios_nvram (hcb_p np, Symbios_nvram *nvram);
9160 static int sym_read_Tekram_nvram (hcb_p np, Tekram_nvram *nvram);
9163 static int sym_read_nvram(hcb_p np, struct sym_nvram *nvp) argument
9171 !sym_read_Symbios_nvram (np, &nvp->data.Symbios)) {
9174 sym_display_Symbios_nvram(np, &nvp->data.Symbios);
9178 !sym_read_Tekram_nvram (np, &nvp->data.Tekram)) {
9181 sym_display_Tekram_nvram(np, &nvp->data.Tekram);
9209 static void S24C16_set_bit(hcb_p np, u_char write_bit, u_char *gpreg, argument
9235 static void S24C16_start(hcb_p np, u_char *gpreg) argument
9237 S24C16_set_bit(np, 1, gpreg, SET_BIT);
9238 S24C16_set_bit(np, 0, gpreg, SET_CLK);
9239 S24C16_set_bit(np, 0, gpreg, CLR_BIT);
9240 S24C16_set_bit(np, 0, gpreg, CLR_CLK);
9246 static void S24C16_stop(hcb_p np, u_char *gpreg) argument
9248 S24C16_set_bit(np, 0, gpreg, SET_CLK);
9249 S24C16_set_bit(np, 1, gpreg, SET_BIT);
9256 static void S24C16_do_bit(hcb_p np, u_char *read_bit, u_char write_bit, argument
9259 S24C16_set_bit(np, write_bit, gpreg, SET_BIT);
9260 S24C16_set_bit(np, 0, gpreg, SET_CLK);
9263 S24C16_set_bit(np, 0, gpreg, CLR_CLK);
9264 S24C16_set_bit(np, 0, gpreg, CLR_BIT);
9271 static void S24C16_write_ack(hcb_p np, u_char write_bit, u_char *gpreg, argument
9275 S24C16_do_bit(np, 0, write_bit, gpreg);
9283 static void S24C16_read_ack(hcb_p np, u_char *read_bit, u_char *gpreg, argument
9287 S24C16_do_bit(np, read_bit, 1, gpreg);
9295 static void S24C16_write_byte(hcb_p np, u_char *ack_data, u_char write_data, argument
9301 S24C16_do_bit(np, 0, (write_data >> (7 - x)) & 0x01, gpreg);
9303 S24C16_read_ack(np, ack_data, gpreg, gpcntl);
9310 static void S24C16_read_byte(hcb_p np, u_char *read_data, u_char ack_data, argument
9318 S24C16_do_bit(np, &read_bit, 1, gpreg);
9322 S24C16_write_ack(np, ack_data, gpreg, gpcntl);
9328 static int sym_read_S24C16_nvram (hcb_p np, int offset, u_char *data, int len) argument
9347 S24C16_set_bit(np, 0, &gpreg, CLR_CLK);
9348 S24C16_set_bit(np, 0, &gpreg, CLR_BIT);
9351 S24C16_stop(np, &gpreg);
9354 S24C16_start(np, &gpreg);
9357 S24C16_write_byte(np, &ack_data,
9363 S24C16_write_byte(np, &ack_data,
9369 S24C16_start(np, &gpreg);
9372 S24C16_write_byte(np, &ack_data,
9383 S24C16_read_byte(np, &data[x], (x == (len-1)), &gpreg, &gpcntl);
9388 S24C16_stop(np, &gpreg);
9407 static int sym_read_Symbios_nvram (hcb_p np, Symbios_nvram *nvram) argument
9416 if (sym_read_S24C16_nvram (np, SYMBIOS_NVRAM_ADDRESS, data, len))
9448 static void T93C46_Clk(hcb_p np, u_char *gpreg) argument
9458 static void T93C46_Read_Bit(hcb_p np, u_char *read_bit, u_char *gpreg) argument
9461 T93C46_Clk(np, gpreg);
9468 static void T93C46_Write_Bit(hcb_p np, u_char write_bit, u_char *gpreg) argument
9480 T93C46_Clk(np, gpreg);
9486 static void T93C46_Stop(hcb_p np, u_char *gpreg) argument
9492 T93C46_Clk(np, gpreg);
9498 static void T93C46_Send_Command(hcb_p np, u_short write_data, argument
9505 T93C46_Write_Bit(np, (u_char) (write_data >> (8 - x)), gpreg);
9513 static void T93C46_Read_Word(hcb_p np, u_short *nvram_data, u_char *gpreg) argument
9520 T93C46_Read_Bit(np, &read_bit, gpreg);
9532 static int T93C46_Read_Data(hcb_p np, u_short *data,int len,u_char *gpreg) argument
9540 T93C46_Send_Command(np, 0x180 | x, &read_bit, gpreg);
9543 T93C46_Read_Word(np, &data[x], gpreg);
9544 T93C46_Stop(np, gpreg);
9553 static int sym_read_T93C46_nvram (hcb_p np, Tekram_nvram *nvram) argument
9571 retv = T93C46_Read_Data(np, (u_short *) nvram,
9585 static int sym_read_Tekram_nvram (hcb_p np, Tekram_nvram *nvram) argument
9592 switch (np->device_id) {
9596 x = sym_read_S24C16_nvram(np, TEKRAM_24C16_NVRAM_ADDRESS,
9600 x = sym_read_S24C16_nvram(np, TEKRAM_24C16_NVRAM_ADDRESS,
9605 x = sym_read_T93C46_nvram(np, nvram);