41 #include <linux/slab.h>
42 #include <asm/param.h>
48 #define SYM_DEBUG_GENERIC_SUPPORT
54 static void sym_int_ma (
struct sym_hcb *np);
55 static void sym_int_sir(
struct sym_hcb *);
66 static void sym_printl_hex(
u_char *
p,
int n)
115 static char *sym_scsi_bus_mode(
int mode)
133 static void sym_chip_reset (
struct sym_hcb *np)
138 OUTB(np, nc_istat, 0);
152 static void sym_soft_reset (
struct sym_hcb *np)
161 for (i = 100000 ;
i ; --
i) {
162 istat =
INB(np, nc_istat);
166 else if (istat &
DIP) {
172 OUTB(np, nc_istat, 0);
174 printf(
"%s: unable to abort current chip operation, "
175 "ISTAT=0x%02x.\n",
sym_name(np), istat);
185 static void sym_start_reset(
struct sym_hcb *np)
216 term =
INB(np, nc_sstat0);
217 term = ((term & 2) << 7) + ((term & 1) << 17);
218 term |= ((
INB(np, nc_sstat2) & 0x01) << 26) |
219 ((
INW(np, nc_sbdl) & 0xff) << 9) |
220 ((
INW(np, nc_sbdl) & 0xff00) << 10) |
226 if (term != (2<<7)) {
227 printf(
"%s: suspicious SCSI data while resetting the BUS.\n",
229 printf(
"%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
230 "0x%lx, expecting 0x%lx\n",
238 OUTB(np, nc_scntl1, 0);
245 static void sym_selectclock(
struct sym_hcb *np,
u_char scntl3)
251 OUTB(np, nc_scntl3, scntl3);
265 while (!(
INB(np, nc_stest4) &
LCKFRQ) && --i > 0)
268 printf(
"%s: the chip cannot lock the frequency\n",
275 OUTB(np, nc_scntl3, scntl3);
277 OUTB(np, nc_stest3, 0x00);
302 static unsigned getfreq (
struct sym_hcb *np,
int gen)
322 OUTW(np, nc_sien, 0);
324 OUTB(np, nc_dien, 0);
335 OUTB(np, nc_scntl3, 4);
336 OUTB(np, nc_stime1, 0);
337 OUTB(np, nc_stime1, gen);
338 while (!(
INW(np, nc_sist) &
GEN) && ms++ < 100000)
340 OUTB(np, nc_stime1, 0);
345 OUTW(np, nc_sien, 0);
346 OUTB(np, nc_istat1, 0);
353 OUTB(np, nc_scntl3, 0);
358 f = ms ? ((1 <<
gen) * (4340*4)) / ms : 0;
368 printf (
"%s: Delay (GEN=%d): %u msec, %u KHz\n",
374 static unsigned sym_getfreq (
struct sym_hcb *np)
380 f1 = getfreq (np, gen);
381 f2 = getfreq (np, gen);
382 if (f1 > f2) f1 =
f2;
389 static void sym_getclock (
struct sym_hcb *np,
int mult)
411 if (np->
multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) {
412 OUTB(np, nc_stest1, 0);
413 f1 = sym_getfreq (np);
418 if (f1 < 45000) f1 = 40000;
419 else if (f1 < 55000) f1 = 50000;
422 if (f1 < 80000 && mult > 1) {
424 printf (
"%s: clock multiplier assumed\n",
429 if ((scntl3 & 7) == 3) f1 = 40000;
430 else if ((scntl3 & 7) == 5) f1 = 80000;
446 static int sym_getpciclock (
struct sym_hcb *np)
461 OUTB(np, nc_stest1, 0);
494 if (dt && sfac <= 9) per = 125;
495 else if (sfac <= 10) per = 250;
496 else if (sfac == 11) per = 303;
497 else if (sfac == 12) per = 500;
498 else per = 40 * sfac;
520 if (kpc > (div_10M[div] << 2)) {
540 if (kpc >= (div_10M[div] << 2))
break;
549 fak = (kpc - 1) / (div_10M[div] << 1) + 1 - 2;
552 fak = (kpc - 1) / div_10M[div] + 1 - 4;
591 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
596 #define burst_code(dmode, ctest4, ctest5) \
597 (ctest4) & 0x80? 0 : (((dmode) & 0xc0) >> 6) + ((ctest5) & 0x04) + 1
627 static void sym_save_initial_setting (
struct sym_hcb *np)
668 if (!(
INB(np, nc_gpreg) & 0x08))
745 else if (period <= 303) np->
minsync = 11;
746 else if (period <= 500) np->
minsync = 12;
747 else np->
minsync = (period + 40 - 1) / 40;
763 np->
maxsync = period > 2540 ? 254 : period / 10;
807 if (burst_max == 255)
879 sym_init_burst(np, burst_max);
881 sym_set_bus_mode(np, nvram);
937 (np->
rv_scntl0 & 0xa) ?
"parity checking" :
"NO parity");
942 printf(
"%s: %s IRQ line driver%s\n",
945 np->
ram_ba ?
", using on-chip SRAM" :
"");
948 printf(
"%s: handling phase mismatch from SCRIPTS.\n",
955 printf (
"%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
956 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
960 printf (
"%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
961 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
974 #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
975 static int sym_regtest(
struct sym_hcb *np)
984 OUTL(np, nc_dstat, data);
985 data =
INL(np, nc_dstat);
987 if (data == 0xffffffff) {
989 if ((data & 0xe2f0fffd) != 0x02000080) {
991 printf (
"CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
998 static inline int sym_regtest(
struct sym_hcb *np)
1004 static int sym_snooptest(
struct sym_hcb *np)
1006 u32 sym_rd, sym_wr, sym_bk, host_rd, host_wr,
pc,
dstat;
1009 err = sym_regtest(np);
1028 OUTL(np, nc_temp, sym_wr);
1038 if (
INB(np, nc_istat) & (
INTF|SIP|DIP))
1040 if (i>=SYM_SNOOP_TIMEOUT) {
1041 printf (
"CACHE TEST FAILED: timeout.\n");
1047 dstat =
INB(np, nc_dstat);
1050 printf (
"%s: PCI DATA PARITY ERROR DETECTED - "
1051 "DISABLING MASTER DATA PARITY CHECKING.\n",
1057 if (dstat & (MDPE|BF|
IID)) {
1058 printf (
"CACHE TEST FAILED: DMA error (dstat=0x%02x).", dstat);
1064 pc =
INL(np, nc_dsp);
1069 sym_rd =
INL(np, nc_scratcha);
1070 sym_bk =
INL(np, nc_temp);
1075 printf (
"CACHE TEST FAILED: script execution failed.\n");
1076 printf (
"start=%08lx, pc=%08lx, end=%08lx\n",
1084 if (host_wr != sym_rd) {
1085 printf (
"CACHE TEST FAILED: host wrote %d, chip read %d.\n",
1086 (
int) host_wr, (
int) sym_rd);
1089 if (host_rd != sym_wr) {
1090 printf (
"CACHE TEST FAILED: chip wrote %d, host read %d.\n",
1091 (
int) sym_wr, (
int) host_rd);
1094 if (sym_bk != sym_wr) {
1095 printf (
"CACHE TEST FAILED: chip wrote %d, read back %d.\n",
1096 (
int) sym_wr, (
int) sym_bk);
1132 struct sym_hcb *np = sym_get_hcb(shost);
1140 dsp =
INL(np, nc_dsp);
1147 script_name =
"scripta";
1154 script_name =
"scriptb";
1159 script_name =
"mem";
1162 printf (
"%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x/%x) @ (%s %x:%08x).\n",
1163 sym_name(np), (
unsigned)
INB(np, nc_sdid)&0x0f, dstat, sist,
1164 (
unsigned)
INB(np, nc_socl), (
unsigned)
INB(np, nc_sbcl),
1165 (
unsigned)
INB(np, nc_sbdl), (
unsigned)
INB(np, nc_sxfer),
1166 (
unsigned)
INB(np, nc_scntl3),
1168 script_name, script_ofs, (
unsigned)
INL(np, nc_dbc));
1170 if (((script_ofs & 3) == 0) &&
1171 (
unsigned)script_ofs < script_size) {
1177 for (i = 0; i < 24; i++)
1184 if (dstat & (MDPE|BF))
1190 struct sym_hcb *np = sym_get_hcb(shost);
1194 sist =
INW(np, nc_sist);
1195 dstat =
INB(np, nc_dstat);
1196 sym_log_hard_error(shost, sist, dstat);
1199 static struct sym_chip sym_dev_table[] = {
1203 #ifdef SYM_DEBUG_GENERIC_SUPPORT
1240 #ifdef SYM_DEBUG_GENERIC_SUPPORT
1283 #define sym_num_devs (ARRAY_SIZE(sym_dev_table))
1298 chip = &sym_dev_table[
i];
1309 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1323 for (i = SYM_DMAP_SIZE-1; i > 0; i--) {
1324 if (h == np->dmap_bah[i])
1328 if (!np->dmap_bah[s])
1331 for (s = SYM_DMAP_SIZE-1; s > 0; s--) {
1332 if (!np->dmap_bah[s])
1336 panic(
"sym: ran out of 64 bit DMA segment registers");
1339 np->dmap_bah[
s] =
h;
1348 static void sym_update_dmap_regs(
struct sym_hcb *np)
1352 if (!np->dmap_dirty)
1355 for (i = 0; i < SYM_DMAP_SIZE; i++) {
1402 goal->
iu = goal->
qas = 0;
1427 sym_check_goals(np, starget, goal);
1434 (goal->
iu || goal->
dt || goal->
qas || (goal->
period < 0xa)))) {
1467 sym_print_nego_msg(np, cp->
target,
1468 nego ==
NS_SYNC ?
"sync msgout" :
1469 nego ==
NS_WIDE ?
"wide msgout" :
1470 "ppr msgout", msgptr);
1484 #ifdef SYM_CONF_IARB_SUPPORT
1493 if (np->last_cp && np->iarb_count < np->iarb_max) {
1494 np->last_cp->host_flags |= HF_HINT_IARB;
1502 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1508 cp->host_xflags |= HX_DMAP_DIRTY;
1536 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1548 assert(!lp->started_tags || !lp->started_no_tag);
1556 qp = sym_remque_head(&lp->waiting_ccbq);
1561 if (lp->started_no_tag ||
1562 lp->started_tags >= lp->started_max) {
1571 if (lp->started_no_tag || lp->started_tags) {
1578 ++lp->started_no_tag;
1594 static int sym_wakeup_done (
struct sym_hcb *np)
1612 cp = sym_ccb_from_dsa(np, dsa);
1615 sym_complete_ok (np, cp);
1619 printf (
"%s: bad DSA (%x) in done queue.\n",
1651 if (cp->host_status ==
HS_WAIT)
1655 sym_set_cam_status(cmd, cam_status);
1656 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1668 --lp->started_no_tag;
1684 static void sym_flush_busy_queue (
struct sym_hcb *np,
int cam_status)
1692 sym_flush_comp_queue(np, cam_status);
1705 struct sym_data *sym_data = shost_priv(shost);
1740 for (i = 0; i < MAX_QUEUE*2; i += 2) {
1766 OUTB(np, nc_istat, 0x00);
1772 OUTB(np, nc_scntl1, 0x00);
1793 OUTB(np, nc_stime0, 0x0c);
1810 OUTB(np, nc_stest1,
INB(np, nc_stest1) | 0x30);
1818 OUTB(np, nc_ctest0, (1<<5));
1832 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1838 np->dmap_bah[0] = 0;
1839 OUTL(np, nc_scrx[0], np->dmap_bah[0]);
1840 OUTL(np, nc_drs, np->dmap_bah[0]);
1858 OUTB(np, nc_gpcntl,
INB(np, nc_gpcntl) & ~0x01);
1860 OUTB(np, nc_gpcntl, (
INB(np, nc_gpcntl) & ~0x41) | 0x20);
1897 tp->
lun0p->to_clear = 0;
1903 tp->lunmp[ln]->to_clear = 0;
1922 OUTL(np, nc_mmws, phys);
1923 OUTL(np, nc_mmrs, phys);
1924 OUTL(np, nc_sfs, phys);
1951 assert(target == (
INB(np, nc_sdid) & 0x0f));
1953 sval = tp->
head.sval;
1954 wval = tp->
head.wval;
1955 uval = tp->
head.uval;
1958 printf(
"XXXX sval=%x wval=%x uval=%x (%x)\n",
1965 sval = (sval & ~0x1f) | ofs;
1967 sval = (sval & ~0x3f) | ofs;
1973 wval = (wval & ~0x70) | ((div+1) << 4);
1975 sval = (sval & ~0xe0) | (fak << 5);
2000 wval = wval & ~
ULTRA;
2001 if (per <= 12) wval |=
ULTRA;
2007 if (tp->
head.sval == sval &&
2008 tp->
head.wval == wval &&
2009 tp->
head.uval == uval)
2011 tp->
head.sval = sval;
2012 tp->
head.wval = wval;
2013 tp->
head.uval = uval;
2026 OUTB(np, nc_scntl3, tp->
head.wval);
2029 OUTB(np, nc_scntl4, tp->
head.uval);
2038 if (cp->
target != target)
2040 cp->
phys.select.sel_scntl3 = tp->
head.wval;
2041 cp->
phys.select.sel_sxfer = tp->
head.sval;
2043 cp->
phys.select.sel_scntl4 = tp->
head.uval;
2048 static void sym_announce_transfer_rate(
struct sym_tcb *tp)
2058 !tp->
tprint.check_nego) {
2065 tp->
tprint.check_nego = 1;
2075 static void sym_setwide(
struct sym_hcb *np,
int target,
u_char wide)
2080 sym_settrans(np, target, 0, 0, 0, wide, 0, 0);
2085 tp->
tgoal.renego = 0;
2086 tp->
tgoal.check_nego = 0;
2096 sym_announce_transfer_rate(tp);
2104 sym_setsync(
struct sym_hcb *np,
int target,
2111 sym_settrans(np, target, 0, ofs, per, wide, div, fak);
2118 tp->
tgoal.renego = 0;
2125 tp->
tgoal.offset = ofs;
2126 tp->
tgoal.check_nego = 0;
2129 sym_announce_transfer_rate(tp);
2143 sym_settrans(np, target, opts, ofs, per, wide, div, fak);
2148 tp->
tgoal.renego = 0;
2155 tp->
tgoal.check_nego = 0;
2157 sym_announce_transfer_rate(tp);
2186 static void sym_recover_scsi_int (
struct sym_hcb *np,
u_char hsts)
2188 u32 dsp =
INL(np, nc_dsp);
2189 u32 dsa =
INL(np, nc_dsa);
2190 struct sym_ccb *cp = sym_ccb_from_dsa(np, dsa);
2202 dsp <
SCRIPTB_BA(np, sel_for_abort_1) + 1)) &&
2214 cp->host_status = hsts;
2221 OUTL(np, nc_dsa, 0xffffff);
2231 sym_start_reset(np);
2237 static void sym_int_sto (
struct sym_hcb *np)
2239 u32 dsp =
INL(np, nc_dsp);
2246 sym_start_reset(np);
2252 static void sym_int_udc (
struct sym_hcb *np)
2268 static void sym_int_sbmc(
struct Scsi_Host *shost)
2270 struct sym_hcb *np = sym_get_hcb(shost);
2276 printf(
"%s: SCSI BUS mode change from %s to %s.\n",
sym_name(np),
2277 sym_scsi_bus_mode(np->
scsi_mode), sym_scsi_bus_mode(scsi_mode));
2313 u32 dsp =
INL(np, nc_dsp);
2314 u32 dbc =
INL(np, nc_dbc);
2315 u32 dsa =
INL(np, nc_dsa);
2318 int phase = cmd & 7;
2319 struct sym_ccb *cp = sym_ccb_from_dsa(np, dsa);
2321 if (printk_ratelimit())
2322 printf(
"%s: SCSI parity error detected: SCR1=%d DBC=%x SBCL=%x\n",
2328 if (!(
INB(np, nc_scntl1) &
ISCON)) {
2344 if ((cmd & 0xc0) || !(phase & 1) || !(sbcl & 0x8))
2365 if (phase == 1 || phase == 5) {
2378 else if (phase == 7)
2389 sym_start_reset(np);
2399 static void sym_int_ma (
struct sym_hcb *np)
2416 dsp =
INL(np, nc_dsp);
2417 dbc =
INL(np, nc_dbc);
2418 dsa =
INL(np, nc_dsa);
2421 rest = dbc & 0xffffff;
2427 cp = sym_ccb_from_dsa(np, dsa);
2435 if ((cmd & 7) != 1 && (cmd & 7) != 5) {
2439 delta =
INW(np, nc_dfbc);
2446 dfifo =
INL(np, nc_dfifo);
2452 if (dfifo & (
DFS << 16))
2453 delta = ((((dfifo >> 8) & 0x300) |
2454 (dfifo & 0xff)) -
rest) & 0x3ff;
2456 delta = ((dfifo & 0xff) - rest) & 0x7f;
2466 ss0 =
INB(np, nc_sstat0);
2467 if (ss0 &
OLF) rest++;
2469 if (ss0 &
ORF) rest++;
2470 if (cp && (cp->
phys.select.sel_scntl3 &
EWS)) {
2471 ss2 =
INB(np, nc_sstat2);
2472 if (ss2 &
OLF1) rest++;
2474 if (ss2 &
ORF1) rest++;
2488 printf (
"P%x%x RL=%d D=%d ", cmd&7,
INB(np, nc_sbcl)&7,
2489 (
unsigned) rest, (
unsigned) delta);
2512 printf (
"\nCP=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
2513 cp, (
unsigned)dsp, (
unsigned)nxtdsp, vdsp, cmd);
2517 printf (
"%s: interrupted SCRIPT address not found.\n",
2523 printf (
"%s: SCSI phase error fixup: CCB already dequeued.\n",
2534 tblp = (
u32 *) ((
char*) &cp->
phys + oadr);
2543 printf (
"OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
2555 if (((cmd & 2) ? cmd : (cmd & ~4)) != (
scr_to_cpu(vdsp[0]) >> 24)) {
2557 "internal error: cmd=%02x != %02x=(vdsp[0] >> 24)\n",
2568 "phase change %x-%x %d@%08x resid=%d.\n",
2569 cmd&7,
INB(np, nc_sbcl)&7, (
unsigned)olen,
2570 (
unsigned)oadr, (
unsigned)rest);
2571 goto unexpected_phase;
2605 if (hflags != hflags0)
2622 if ((cmd & 7) == 1 && cp && (cp->
phys.select.sel_scntl3 &
EWS) &&
2623 (
INB(np, nc_scntl2) &
WSR)) {
2642 if ((tmp&0xffffff) == 1)
2654 hflags0, hflags, newcmd,
2715 if (cp->
tag !=
NO_TAG && olen - rest <= 3) {
2746 sym_start_reset(np);
2814 struct sym_data *sym_data = shost_priv(shost);
2832 istat =
INB(np, nc_istat);
2835 istat |=
INB(np, nc_istat);
2837 sym_wakeup_done(np);
2840 if (!(istat & (SIP|DIP)))
2845 OUTB(np, nc_istat, CABRT);
2863 sist |=
INW(np, nc_sist);
2865 dstat |=
INB(np, nc_dstat);
2866 istatc =
INB(np, nc_istat);
2871 if (
unlikely(sist == 0xffff && dstat == 0xff)) {
2872 if (pci_channel_offline(pdev))
2875 }
while (istatc & (SIP|DIP));
2878 printf (
"<%d|%x:%x|%x:%x>",
2879 (
int)
INB(np, nc_scr0),
2881 (
unsigned)
INL(np, nc_dsp),
2882 (
unsigned)
INL(np, nc_dbc));
2906 if (sist &
PAR) sym_int_par (np, sist);
2907 else if (sist & MA) sym_int_ma (np);
2908 else if (dstat &
SIR) sym_int_sir(np);
2910 else goto unknown_int;
2934 if (!(sist & (GEN|
HTH|
SGE)) &&
2936 if (sist &
SBMC) sym_int_sbmc(shost);
2937 else if (sist &
STO) sym_int_sto (np);
2938 else if (sist &
UDC) sym_int_udc (np);
2939 else goto unknown_int;
2950 sym_log_hard_error(shost, sist, dstat);
2952 if ((sist & (GEN|
HTH|
SGE)) ||
2954 sym_start_reset(np);
2963 printf(
"%s: unknown interrupt(s) ignored, "
2964 "ISTAT=0x%x DSTAT=0x%x SIST=0x%x\n",
2978 sym_dequeue_from_squeue(
struct sym_hcb *np,
int i,
int target,
int lun,
int task)
2996 #ifdef SYM_CONF_IARB_SUPPORT
2998 cp->host_flags &= ~HF_HINT_IARB;
3000 if ((target == -1 || cp->
target == target) &&
3001 (lun == -1 || cp->
lun == lun) &&
3002 (task == -1 || cp->
tag == task)) {
3039 static void sym_sir_bad_scsi_status(
struct sym_hcb *np,
int num,
struct sym_ccb *cp)
3042 u_char s_status = cp->ssss_status;
3043 u_char h_flags = cp->host_flags;
3056 #ifdef SYM_CONF_IARB_SUPPORT
3069 s_status ==
S_BUSY ?
"BUSY" :
"QUEUE FULL\n");
3072 sym_complete_error (np, cp);
3080 sym_complete_error (np, cp);
3088 sym_dequeue_from_squeue(np, i, cp->
target, cp->
lun, -1);
3097 cp->
sv_resid = sym_compute_residual(np, cp);
3118 msglen += sym_prepare_nego(np, cp, &cp->
scsi_smsg2[msglen]);
3136 if (cp->
cmd->device->scsi_level <=
SCSI_2 && cp->
lun <= 7)
3158 cp->host_xflags = 0;
3175 sym_flush_comp_queue(np, 0);
3212 while ((qp = sym_remque_head(&qtmp)) !=
NULL) {
3218 (lun != -1 && cp->
lun != lun) ||
3228 sym_set_cam_status(cmd, cam_status);
3231 printf(
"XXXX TASK @%p CLEARED\n", cp);
3277 static void sym_sir_task_recovery(
struct sym_hcb *np,
int num)
3283 int target=-1, lun=-1,
task;
3306 if (tp->lunmp[k] && tp->lunmp[k]->to_clear) {
3354 if (cp->host_status !=
HS_BUSY &&
3359 #ifdef SYM_CONF_IARB_SUPPORT
3365 if (cp == np->last_cp) {
3389 i = sym_dequeue_from_squeue(np, i, cp->
target, cp->
lun, -1);
3394 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
3411 sym_flush_comp_queue(np, 0);
3418 target =
INB(np, nc_sdid) & 0xf;
3440 else if (tp->lunmp) {
3442 if (tp->lunmp[k] && tp->lunmp[k]->to_clear) {
3472 if (cp->
target != target)
3529 target =
INB(np, nc_sdid) & 0xf;
3559 tp->
tgoal.check_nego = 1;
3560 tp->
tgoal.renego = 0;
3580 sym_dequeue_from_squeue(np, i, target, lun, -1);
3582 sym_flush_comp_queue(np, 0);
3589 "has been reset\n");
3638 int dp_ofs, dp_sg, dp_sgmin;
3663 if (cp->host_flags & HF_SENSE) {
3677 dp_sg -= (tmp - 8 - (
int)dp_scr) / (2*4);
3694 while (dp_sg > dp_sgmin) {
3697 n = dp_ofs + (tmp & 0xffffff);
3705 else if (dp_ofs > 0) {
3708 dp_ofs -= (tmp & 0xffffff);
3719 if (dp_sg < dp_sgmin || (dp_sg == dp_sgmin && dp_ofs < 0))
3728 if (dp_sg > cp->
ext_sg ||
3766 if (cp->host_flags & HF_SENSE)
3773 dp_sg = sym_evaluate_dp(np, cp, dp_scr, &dp_ofs);
3801 if (!(hflags & HF_ACT_PM)) {
3854 int dp_sg, dp_sgmin, resid = 0;
3893 if (cp->host_flags & HF_SENSE) {
3905 resid += (tmp & 0xffffff);
3960 sym_print_nego_msg(np, target,
"sync msgin", np->
msgin);
3979 if (per < np->minsync)
3987 if (ofs && sym_getsync(np, 0, per, &div, &fak) < 0)
3992 "sdtr: ofs=%d per=%d div=%d fak=%d chg=%d.\n",
3993 ofs, per, div, fak, chg);
4006 sym_setsync (np, target, ofs, per, div, fak);
4020 sym_print_nego_msg(np, target,
"sync msgout", np->
msgout);
4028 sym_setsync (np, target, 0, 0, 0, 0);
4050 result = sym_sync_nego_check(np, req, cp);
4069 sym_ppr_nego_check(
struct sym_hcb *np,
int req,
int target)
4072 unsigned char fak,
div;
4075 unsigned char per = np->
msgin[3];
4076 unsigned char ofs = np->
msgin[5];
4077 unsigned char wide = np->
msgin[6];
4081 sym_print_nego_msg(np, target,
"ppr msgin", np->
msgin);
4101 if (ofs > maxoffs) {
4109 if (per < minsync) {
4119 if (ofs && sym_getsync(np, dt, per, &div, &fak) < 0)
4132 sym_setpprot(np, target, opts, ofs, per, wide, div, fak);
4146 sym_print_nego_msg(np, target,
"ppr msgout", np->
msgout);
4154 sym_setpprot (np, target, 0, 0, 0, 0, 0, 0);
4159 if (!req && !opts) {
4161 tp->
tgoal.offset = ofs;
4164 tp->
tgoal.check_nego = 1;
4187 result = sym_ppr_nego_check(np, req, cp->
target);
4206 sym_wide_nego_check(
struct sym_hcb *np,
int req,
struct sym_ccb *cp)
4212 sym_print_nego_msg(np, target,
"wide msgin", np->
msgin);
4219 wide = np->
msgin[3];
4244 sym_setwide (np, target, wide);
4260 sym_print_nego_msg(np, target,
"wide msgout", np->
msgout);
4287 result = sym_wide_nego_check(np, req, cp);
4299 if (tp->
tgoal.offset) {
4304 sym_print_nego_msg(np, cp->
target,
4305 "sync msgout", np->
msgout);
4338 sym_setpprot (np, cp->
target, 0, 0, 0, 0, 0, 0);
4345 tp->
tgoal.check_nego = 1;
4349 sym_setsync (np, cp->
target, 0, 0, 0, 0);
4352 sym_setwide (np, cp->
target, 0);
4366 sym_nego_default(np, tp, cp);
4373 static void sym_int_sir(
struct sym_hcb *np)
4376 u32 dsa =
INL(np, nc_dsa);
4377 struct sym_ccb *cp = sym_ccb_from_dsa(np, dsa);
4378 u_char target =
INB(np, nc_sdid) & 0x0f;
4385 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
4390 case SIR_DMAP_DIRTY:
4391 sym_update_dmap_regs(np);
4399 sym_complete_error(np, cp);
4408 sym_sir_task_recovery(np, num);
4416 "No MSG OUT phase after selection with ATN\n");
4424 "No MSG IN phase after reselection\n");
4432 "No IDENTIFY after reselection\n");
4461 "message %x sent on bad reselection\n", np->
lastmsg);
4487 sym_sir_bad_scsi_status(np, num, cp);
4494 sym_print_msg(cp,
"M_REJECT to send for ", np->
msgin);
4548 switch (np->
msgin [0]) {
4555 switch (np->
msgin [2]) {
4558 sym_print_msg(cp,
"extended msg ",
4560 tmp = (np->
msgin[3]<<24) + (np->
msgin[4]<<16) +
4562 sym_modify_dp(np, tp, cp, tmp);
4565 sym_sync_nego(np, tp, cp);
4568 sym_ppr_nego(np, tp, cp);
4571 sym_wide_nego(np, tp, cp);
4586 sym_print_msg(cp,
"1 or 2 byte ", np->
msgin);
4587 if (cp->host_flags & HF_SENSE)
4590 sym_modify_dp(np, tp, cp, -1);
4594 sym_nego_rejected(np, tp, cp);
4597 "M_REJECT received (%x:%x).\n",
4611 sym_print_msg(cp,
"WEIRD message received", np->
msgin);
4626 sym_nego_default(np, tp, cp);
4674 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4682 sym_alloc_lcb_tags(np, tn, ln);
4697 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4702 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
4703 cp->tags_si = lp->tags_si;
4704 ++lp->tags_sum[cp->tags_si];
4720 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4730 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4745 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
4755 cp->
order = tag_order;
4791 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
4792 --lp->tags_sum[cp->tags_si];
4830 #ifdef SYM_CONF_IARB_SUPPORT
4835 if (cp == np->last_cp)
4847 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
4855 --lp->started_no_tag;
4920 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
4939 cp = np->
ccbh[hcode];
4977 sym_init_tcb (np, tn);
4989 for (i = 0 ; i < 64 ; i++)
4997 if (ln && !tp->lunmp) {
4998 tp->lunmp = kcalloc(SYM_CONF_MAX_LUN,
sizeof(
struct sym_lcb *),
5036 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5116 tp->lunmp[ln] =
NULL;
5165 msgptr[msglen++] =
IDENTIFY(can_disconnect, sdev->
lun);
5181 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
5189 lp->tags_si = !(lp->tags_si);
5190 if (lp->tags_sum[lp->tags_si]) {
5194 "ordered tag forced.\n");
5200 msgptr[msglen++] =
order;
5209 #if SYM_CONF_MAX_TASK > (512/4)
5210 msgptr[msglen++] = cp->
tag;
5212 msgptr[msglen++] = (cp->
tag << 1) + 1;
5224 if ((tp->
tgoal.check_nego ||
5227 msglen += sym_prepare_nego(np, cp, msgptr + msglen);
5240 cp->
phys.select.sel_scntl3 = tp->
head.wval;
5241 cp->
phys.select.sel_sxfer = tp->
head.sval;
5242 cp->
phys.select.sel_scntl4 = tp->
head.uval;
5253 cp->host_xflags = 0;
5281 if (target == np->
myaddr || (
u_int)target >= SYM_CONF_MAX_TARGET)
5296 static int sym_abort_ccb(
struct sym_hcb *np,
struct sym_ccb *cp,
int timed_out)
5301 if (!cp || !cp->host_status || cp->host_status ==
HS_WAIT)
5337 if (cp2->
cmd == cmd) {
5343 return sym_abort_ccb(np, cp, timed_out);
5368 if (!cp || !cp->
cmd)
5374 dev_info(&sdev->sdev_gendev,
"CCB=%p STAT=%x/%x/%x\n", cp,
5375 cp->host_status, cp->ssss_status, cp->host_flags);
5397 resid = sym_compute_residual(np, cp);
5405 printf(
"XXXX RESID= %d - 0x%x\n", resid, resid);
5413 i = sym_dequeue_from_squeue(np, i, cp->
target, sdev->
lun, -1);
5420 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5423 if (!lp || lp->started_tags - i < 2)
5428 lp->started_max = lp->started_tags - i - 1;
5455 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5468 sym_flush_comp_queue(np, 0);
5470 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5474 sym_start_next_ccbs(np, lp, 1);
5497 if (!cp || !cp->
cmd)
5518 resid = sym_compute_residual(np, cp);
5529 printf(
"XXXX RESID= %d - 0x%x\n", resid, resid);
5535 sym_set_cam_result_ok(cp, cmd, resid);
5537 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5542 if (lp && lp->started_max < lp->started_limit) {
5544 if (lp->num_sgood >= 200) {
5560 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5564 if (!sym_que_empty(&lp->waiting_ccbq))
5565 sym_start_next_ccbs(np, lp, 2);
5578 struct sym_hcb *np = sym_get_hcb(shost);
5595 sym_save_initial_setting (np);
5608 sym_prepare_setting(shost, np, nvram);
5615 i = sym_getpciclock(np);
5617 printf(
"%s: PCI BUS clock seems too high: %u KHz.\n",
5671 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5677 if (!sym_alloc_ccb(np))
5719 #ifdef SYM_CONF_IARB_SUPPORT
5726 #ifdef SYM_SETUP_IARB_MAX
5727 np->iarb_max = SYM_SETUP_IARB_MAX;
5763 for (i = 0 ; i < 64 ; i++)
5773 np->
target[
i].head.luntbl_sa =
5782 if (sym_snooptest (np)) {
5832 #if SYM_CONF_MAX_LUN > 1