/kern_oII/drivers/scsi/sym53c8xx_2/sym_hipd.c

http://omnia2droid.googlecode.com/ · C · 5840 lines · 3185 code · 571 blank · 2084 comment · 818 complexity · 607009861f7d5813b3cca1d9d87f7518 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
  3. * of PCI-SCSI IO processors.
  4. *
  5. * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
  6. * Copyright (c) 2003-2005 Matthew Wilcox <matthew@wil.cx>
  7. *
  8. * This driver is derived from the Linux sym53c8xx driver.
  9. * Copyright (C) 1998-2000 Gerard Roudier
  10. *
  11. * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
  12. * a port of the FreeBSD ncr driver to Linux-1.2.13.
  13. *
  14. * The original ncr driver has been written for 386bsd and FreeBSD by
  15. * Wolfgang Stanglmeier <wolf@cologne.de>
  16. * Stefan Esser <se@mi.Uni-Koeln.de>
  17. * Copyright (C) 1994 Wolfgang Stanglmeier
  18. *
  19. * Other major contributions:
  20. *
  21. * NVRAM detection and reading.
  22. * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
  23. *
  24. *-----------------------------------------------------------------------------
  25. *
  26. * This program is free software; you can redistribute it and/or modify
  27. * it under the terms of the GNU General Public License as published by
  28. * the Free Software Foundation; either version 2 of the License, or
  29. * (at your option) any later version.
  30. *
  31. * This program is distributed in the hope that it will be useful,
  32. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. * GNU General Public License for more details.
  35. *
  36. * You should have received a copy of the GNU General Public License
  37. * along with this program; if not, write to the Free Software
  38. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  39. */
  40. #include <linux/slab.h>
  41. #include <asm/param.h> /* for timeouts in units of HZ */
  42. #include "sym_glue.h"
  43. #include "sym_nvram.h"
  44. #if 0
  45. #define SYM_DEBUG_GENERIC_SUPPORT
  46. #endif
  47. /*
  48. * Needed function prototypes.
  49. */
  50. static void sym_int_ma (struct sym_hcb *np);
  51. static void sym_int_sir(struct sym_hcb *);
  52. static struct sym_ccb *sym_alloc_ccb(struct sym_hcb *np);
  53. static struct sym_ccb *sym_ccb_from_dsa(struct sym_hcb *np, u32 dsa);
  54. static void sym_alloc_lcb_tags (struct sym_hcb *np, u_char tn, u_char ln);
  55. static void sym_complete_error (struct sym_hcb *np, struct sym_ccb *cp);
  56. static void sym_complete_ok (struct sym_hcb *np, struct sym_ccb *cp);
  57. static int sym_compute_residual(struct sym_hcb *np, struct sym_ccb *cp);
  58. /*
  59. * Print a buffer in hexadecimal format with a ".\n" at end.
  60. */
  61. static void sym_printl_hex(u_char *p, int n)
  62. {
  63. while (n-- > 0)
  64. printf (" %x", *p++);
  65. printf (".\n");
  66. }
  67. static void sym_print_msg(struct sym_ccb *cp, char *label, u_char *msg)
  68. {
  69. if (label)
  70. sym_print_addr(cp->cmd, "%s: ", label);
  71. else
  72. sym_print_addr(cp->cmd, "");
  73. spi_print_msg(msg);
  74. printf("\n");
  75. }
  76. static void sym_print_nego_msg(struct sym_hcb *np, int target, char *label, u_char *msg)
  77. {
  78. struct sym_tcb *tp = &np->target[target];
  79. dev_info(&tp->starget->dev, "%s: ", label);
  80. spi_print_msg(msg);
  81. printf("\n");
  82. }
  83. /*
  84. * Print something that tells about extended errors.
  85. */
  86. void sym_print_xerr(struct scsi_cmnd *cmd, int x_status)
  87. {
  88. if (x_status & XE_PARITY_ERR) {
  89. sym_print_addr(cmd, "unrecovered SCSI parity error.\n");
  90. }
  91. if (x_status & XE_EXTRA_DATA) {
  92. sym_print_addr(cmd, "extraneous data discarded.\n");
  93. }
  94. if (x_status & XE_BAD_PHASE) {
  95. sym_print_addr(cmd, "illegal scsi phase (4/5).\n");
  96. }
  97. if (x_status & XE_SODL_UNRUN) {
  98. sym_print_addr(cmd, "ODD transfer in DATA OUT phase.\n");
  99. }
  100. if (x_status & XE_SWIDE_OVRUN) {
  101. sym_print_addr(cmd, "ODD transfer in DATA IN phase.\n");
  102. }
  103. }
  104. /*
  105. * Return a string for SCSI BUS mode.
  106. */
  107. static char *sym_scsi_bus_mode(int mode)
  108. {
  109. switch(mode) {
  110. case SMODE_HVD: return "HVD";
  111. case SMODE_SE: return "SE";
  112. case SMODE_LVD: return "LVD";
  113. }
  114. return "??";
  115. }
  116. /*
  117. * Soft reset the chip.
  118. *
  119. * Raising SRST when the chip is running may cause
  120. * problems on dual function chips (see below).
  121. * On the other hand, LVD devices need some delay
  122. * to settle and report actual BUS mode in STEST4.
  123. */
  124. static void sym_chip_reset (struct sym_hcb *np)
  125. {
  126. OUTB(np, nc_istat, SRST);
  127. INB(np, nc_mbox1);
  128. udelay(10);
  129. OUTB(np, nc_istat, 0);
  130. INB(np, nc_mbox1);
  131. udelay(2000); /* For BUS MODE to settle */
  132. }
  133. /*
  134. * Really soft reset the chip.:)
  135. *
  136. * Some 896 and 876 chip revisions may hang-up if we set
  137. * the SRST (soft reset) bit at the wrong time when SCRIPTS
  138. * are running.
  139. * So, we need to abort the current operation prior to
  140. * soft resetting the chip.
  141. */
  142. static void sym_soft_reset (struct sym_hcb *np)
  143. {
  144. u_char istat = 0;
  145. int i;
  146. if (!(np->features & FE_ISTAT1) || !(INB(np, nc_istat1) & SCRUN))
  147. goto do_chip_reset;
  148. OUTB(np, nc_istat, CABRT);
  149. for (i = 100000 ; i ; --i) {
  150. istat = INB(np, nc_istat);
  151. if (istat & SIP) {
  152. INW(np, nc_sist);
  153. }
  154. else if (istat & DIP) {
  155. if (INB(np, nc_dstat) & ABRT)
  156. break;
  157. }
  158. udelay(5);
  159. }
  160. OUTB(np, nc_istat, 0);
  161. if (!i)
  162. printf("%s: unable to abort current chip operation, "
  163. "ISTAT=0x%02x.\n", sym_name(np), istat);
  164. do_chip_reset:
  165. sym_chip_reset(np);
  166. }
  167. /*
  168. * Start reset process.
  169. *
  170. * The interrupt handler will reinitialize the chip.
  171. */
  172. static void sym_start_reset(struct sym_hcb *np)
  173. {
  174. sym_reset_scsi_bus(np, 1);
  175. }
  176. int sym_reset_scsi_bus(struct sym_hcb *np, int enab_int)
  177. {
  178. u32 term;
  179. int retv = 0;
  180. sym_soft_reset(np); /* Soft reset the chip */
  181. if (enab_int)
  182. OUTW(np, nc_sien, RST);
  183. /*
  184. * Enable Tolerant, reset IRQD if present and
  185. * properly set IRQ mode, prior to resetting the bus.
  186. */
  187. OUTB(np, nc_stest3, TE);
  188. OUTB(np, nc_dcntl, (np->rv_dcntl & IRQM));
  189. OUTB(np, nc_scntl1, CRST);
  190. INB(np, nc_mbox1);
  191. udelay(200);
  192. if (!SYM_SETUP_SCSI_BUS_CHECK)
  193. goto out;
  194. /*
  195. * Check for no terminators or SCSI bus shorts to ground.
  196. * Read SCSI data bus, data parity bits and control signals.
  197. * We are expecting RESET to be TRUE and other signals to be
  198. * FALSE.
  199. */
  200. term = INB(np, nc_sstat0);
  201. term = ((term & 2) << 7) + ((term & 1) << 17); /* rst sdp0 */
  202. term |= ((INB(np, nc_sstat2) & 0x01) << 26) | /* sdp1 */
  203. ((INW(np, nc_sbdl) & 0xff) << 9) | /* d7-0 */
  204. ((INW(np, nc_sbdl) & 0xff00) << 10) | /* d15-8 */
  205. INB(np, nc_sbcl); /* req ack bsy sel atn msg cd io */
  206. if (!np->maxwide)
  207. term &= 0x3ffff;
  208. if (term != (2<<7)) {
  209. printf("%s: suspicious SCSI data while resetting the BUS.\n",
  210. sym_name(np));
  211. printf("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
  212. "0x%lx, expecting 0x%lx\n",
  213. sym_name(np),
  214. (np->features & FE_WIDE) ? "dp1,d15-8," : "",
  215. (u_long)term, (u_long)(2<<7));
  216. if (SYM_SETUP_SCSI_BUS_CHECK == 1)
  217. retv = 1;
  218. }
  219. out:
  220. OUTB(np, nc_scntl1, 0);
  221. return retv;
  222. }
  223. /*
  224. * Select SCSI clock frequency
  225. */
  226. static void sym_selectclock(struct sym_hcb *np, u_char scntl3)
  227. {
  228. /*
  229. * If multiplier not present or not selected, leave here.
  230. */
  231. if (np->multiplier <= 1) {
  232. OUTB(np, nc_scntl3, scntl3);
  233. return;
  234. }
  235. if (sym_verbose >= 2)
  236. printf ("%s: enabling clock multiplier\n", sym_name(np));
  237. OUTB(np, nc_stest1, DBLEN); /* Enable clock multiplier */
  238. /*
  239. * Wait for the LCKFRQ bit to be set if supported by the chip.
  240. * Otherwise wait 50 micro-seconds (at least).
  241. */
  242. if (np->features & FE_LCKFRQ) {
  243. int i = 20;
  244. while (!(INB(np, nc_stest4) & LCKFRQ) && --i > 0)
  245. udelay(20);
  246. if (!i)
  247. printf("%s: the chip cannot lock the frequency\n",
  248. sym_name(np));
  249. } else {
  250. INB(np, nc_mbox1);
  251. udelay(50+10);
  252. }
  253. OUTB(np, nc_stest3, HSC); /* Halt the scsi clock */
  254. OUTB(np, nc_scntl3, scntl3);
  255. OUTB(np, nc_stest1, (DBLEN|DBLSEL));/* Select clock multiplier */
  256. OUTB(np, nc_stest3, 0x00); /* Restart scsi clock */
  257. }
  258. /*
  259. * Determine the chip's clock frequency.
  260. *
  261. * This is essential for the negotiation of the synchronous
  262. * transfer rate.
  263. *
  264. * Note: we have to return the correct value.
  265. * THERE IS NO SAFE DEFAULT VALUE.
  266. *
  267. * Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
  268. * 53C860 and 53C875 rev. 1 support fast20 transfers but
  269. * do not have a clock doubler and so are provided with a
  270. * 80 MHz clock. All other fast20 boards incorporate a doubler
  271. * and so should be delivered with a 40 MHz clock.
  272. * The recent fast40 chips (895/896/895A/1010) use a 40 Mhz base
  273. * clock and provide a clock quadrupler (160 Mhz).
  274. */
  275. /*
  276. * calculate SCSI clock frequency (in KHz)
  277. */
  278. static unsigned getfreq (struct sym_hcb *np, int gen)
  279. {
  280. unsigned int ms = 0;
  281. unsigned int f;
  282. /*
  283. * Measure GEN timer delay in order
  284. * to calculate SCSI clock frequency
  285. *
  286. * This code will never execute too
  287. * many loop iterations (if DELAY is
  288. * reasonably correct). It could get
  289. * too low a delay (too high a freq.)
  290. * if the CPU is slow executing the
  291. * loop for some reason (an NMI, for
  292. * example). For this reason we will
  293. * if multiple measurements are to be
  294. * performed trust the higher delay
  295. * (lower frequency returned).
  296. */
  297. OUTW(np, nc_sien, 0); /* mask all scsi interrupts */
  298. INW(np, nc_sist); /* clear pending scsi interrupt */
  299. OUTB(np, nc_dien, 0); /* mask all dma interrupts */
  300. INW(np, nc_sist); /* another one, just to be sure :) */
  301. /*
  302. * The C1010-33 core does not report GEN in SIST,
  303. * if this interrupt is masked in SIEN.
  304. * I don't know yet if the C1010-66 behaves the same way.
  305. */
  306. if (np->features & FE_C10) {
  307. OUTW(np, nc_sien, GEN);
  308. OUTB(np, nc_istat1, SIRQD);
  309. }
  310. OUTB(np, nc_scntl3, 4); /* set pre-scaler to divide by 3 */
  311. OUTB(np, nc_stime1, 0); /* disable general purpose timer */
  312. OUTB(np, nc_stime1, gen); /* set to nominal delay of 1<<gen * 125us */
  313. while (!(INW(np, nc_sist) & GEN) && ms++ < 100000)
  314. udelay(1000/4); /* count in 1/4 of ms */
  315. OUTB(np, nc_stime1, 0); /* disable general purpose timer */
  316. /*
  317. * Undo C1010-33 specific settings.
  318. */
  319. if (np->features & FE_C10) {
  320. OUTW(np, nc_sien, 0);
  321. OUTB(np, nc_istat1, 0);
  322. }
  323. /*
  324. * set prescaler to divide by whatever 0 means
  325. * 0 ought to choose divide by 2, but appears
  326. * to set divide by 3.5 mode in my 53c810 ...
  327. */
  328. OUTB(np, nc_scntl3, 0);
  329. /*
  330. * adjust for prescaler, and convert into KHz
  331. */
  332. f = ms ? ((1 << gen) * (4340*4)) / ms : 0;
  333. /*
  334. * The C1010-33 result is biased by a factor
  335. * of 2/3 compared to earlier chips.
  336. */
  337. if (np->features & FE_C10)
  338. f = (f * 2) / 3;
  339. if (sym_verbose >= 2)
  340. printf ("%s: Delay (GEN=%d): %u msec, %u KHz\n",
  341. sym_name(np), gen, ms/4, f);
  342. return f;
  343. }
  344. static unsigned sym_getfreq (struct sym_hcb *np)
  345. {
  346. u_int f1, f2;
  347. int gen = 8;
  348. getfreq (np, gen); /* throw away first result */
  349. f1 = getfreq (np, gen);
  350. f2 = getfreq (np, gen);
  351. if (f1 > f2) f1 = f2; /* trust lower result */
  352. return f1;
  353. }
  354. /*
  355. * Get/probe chip SCSI clock frequency
  356. */
  357. static void sym_getclock (struct sym_hcb *np, int mult)
  358. {
  359. unsigned char scntl3 = np->sv_scntl3;
  360. unsigned char stest1 = np->sv_stest1;
  361. unsigned f1;
  362. np->multiplier = 1;
  363. f1 = 40000;
  364. /*
  365. * True with 875/895/896/895A with clock multiplier selected
  366. */
  367. if (mult > 1 && (stest1 & (DBLEN+DBLSEL)) == DBLEN+DBLSEL) {
  368. if (sym_verbose >= 2)
  369. printf ("%s: clock multiplier found\n", sym_name(np));
  370. np->multiplier = mult;
  371. }
  372. /*
  373. * If multiplier not found or scntl3 not 7,5,3,
  374. * reset chip and get frequency from general purpose timer.
  375. * Otherwise trust scntl3 BIOS setting.
  376. */
  377. if (np->multiplier != mult || (scntl3 & 7) < 3 || !(scntl3 & 1)) {
  378. OUTB(np, nc_stest1, 0); /* make sure doubler is OFF */
  379. f1 = sym_getfreq (np);
  380. if (sym_verbose)
  381. printf ("%s: chip clock is %uKHz\n", sym_name(np), f1);
  382. if (f1 < 45000) f1 = 40000;
  383. else if (f1 < 55000) f1 = 50000;
  384. else f1 = 80000;
  385. if (f1 < 80000 && mult > 1) {
  386. if (sym_verbose >= 2)
  387. printf ("%s: clock multiplier assumed\n",
  388. sym_name(np));
  389. np->multiplier = mult;
  390. }
  391. } else {
  392. if ((scntl3 & 7) == 3) f1 = 40000;
  393. else if ((scntl3 & 7) == 5) f1 = 80000;
  394. else f1 = 160000;
  395. f1 /= np->multiplier;
  396. }
  397. /*
  398. * Compute controller synchronous parameters.
  399. */
  400. f1 *= np->multiplier;
  401. np->clock_khz = f1;
  402. }
  403. /*
  404. * Get/probe PCI clock frequency
  405. */
  406. static int sym_getpciclock (struct sym_hcb *np)
  407. {
  408. int f = 0;
  409. /*
  410. * For now, we only need to know about the actual
  411. * PCI BUS clock frequency for C1010-66 chips.
  412. */
  413. #if 1
  414. if (np->features & FE_66MHZ) {
  415. #else
  416. if (1) {
  417. #endif
  418. OUTB(np, nc_stest1, SCLK); /* Use the PCI clock as SCSI clock */
  419. f = sym_getfreq(np);
  420. OUTB(np, nc_stest1, 0);
  421. }
  422. np->pciclk_khz = f;
  423. return f;
  424. }
  425. /*
  426. * SYMBIOS chip clock divisor table.
  427. *
  428. * Divisors are multiplied by 10,000,000 in order to make
  429. * calculations more simple.
  430. */
  431. #define _5M 5000000
  432. static const u32 div_10M[] = {2*_5M, 3*_5M, 4*_5M, 6*_5M, 8*_5M, 12*_5M, 16*_5M};
  433. /*
  434. * Get clock factor and sync divisor for a given
  435. * synchronous factor period.
  436. */
  437. static int
  438. sym_getsync(struct sym_hcb *np, u_char dt, u_char sfac, u_char *divp, u_char *fakp)
  439. {
  440. u32 clk = np->clock_khz; /* SCSI clock frequency in kHz */
  441. int div = np->clock_divn; /* Number of divisors supported */
  442. u32 fak; /* Sync factor in sxfer */
  443. u32 per; /* Period in tenths of ns */
  444. u32 kpc; /* (per * clk) */
  445. int ret;
  446. /*
  447. * Compute the synchronous period in tenths of nano-seconds
  448. */
  449. if (dt && sfac <= 9) per = 125;
  450. else if (sfac <= 10) per = 250;
  451. else if (sfac == 11) per = 303;
  452. else if (sfac == 12) per = 500;
  453. else per = 40 * sfac;
  454. ret = per;
  455. kpc = per * clk;
  456. if (dt)
  457. kpc <<= 1;
  458. /*
  459. * For earliest C10 revision 0, we cannot use extra
  460. * clocks for the setting of the SCSI clocking.
  461. * Note that this limits the lowest sync data transfer
  462. * to 5 Mega-transfers per second and may result in
  463. * using higher clock divisors.
  464. */
  465. #if 1
  466. if ((np->features & (FE_C10|FE_U3EN)) == FE_C10) {
  467. /*
  468. * Look for the lowest clock divisor that allows an
  469. * output speed not faster than the period.
  470. */
  471. while (div > 0) {
  472. --div;
  473. if (kpc > (div_10M[div] << 2)) {
  474. ++div;
  475. break;
  476. }
  477. }
  478. fak = 0; /* No extra clocks */
  479. if (div == np->clock_divn) { /* Are we too fast ? */
  480. ret = -1;
  481. }
  482. *divp = div;
  483. *fakp = fak;
  484. return ret;
  485. }
  486. #endif
  487. /*
  488. * Look for the greatest clock divisor that allows an
  489. * input speed faster than the period.
  490. */
  491. while (div-- > 0)
  492. if (kpc >= (div_10M[div] << 2)) break;
  493. /*
  494. * Calculate the lowest clock factor that allows an output
  495. * speed not faster than the period, and the max output speed.
  496. * If fak >= 1 we will set both XCLKH_ST and XCLKH_DT.
  497. * If fak >= 2 we will also set XCLKS_ST and XCLKS_DT.
  498. */
  499. if (dt) {
  500. fak = (kpc - 1) / (div_10M[div] << 1) + 1 - 2;
  501. /* ret = ((2+fak)*div_10M[div])/np->clock_khz; */
  502. } else {
  503. fak = (kpc - 1) / div_10M[div] + 1 - 4;
  504. /* ret = ((4+fak)*div_10M[div])/np->clock_khz; */
  505. }
  506. /*
  507. * Check against our hardware limits, or bugs :).
  508. */
  509. if (fak > 2) {
  510. fak = 2;
  511. ret = -1;
  512. }
  513. /*
  514. * Compute and return sync parameters.
  515. */
  516. *divp = div;
  517. *fakp = fak;
  518. return ret;
  519. }
  520. /*
  521. * SYMBIOS chips allow burst lengths of 2, 4, 8, 16, 32, 64,
  522. * 128 transfers. All chips support at least 16 transfers
  523. * bursts. The 825A, 875 and 895 chips support bursts of up
  524. * to 128 transfers and the 895A and 896 support bursts of up
  525. * to 64 transfers. All other chips support up to 16
  526. * transfers bursts.
  527. *
  528. * For PCI 32 bit data transfers each transfer is a DWORD.
  529. * It is a QUADWORD (8 bytes) for PCI 64 bit data transfers.
  530. *
  531. * We use log base 2 (burst length) as internal code, with
  532. * value 0 meaning "burst disabled".
  533. */
  534. /*
  535. * Burst length from burst code.
  536. */
  537. #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
  538. /*
  539. * Burst code from io register bits.
  540. */
  541. #define burst_code(dmode, ctest4, ctest5) \
  542. (ctest4) & 0x80? 0 : (((dmode) & 0xc0) >> 6) + ((ctest5) & 0x04) + 1
  543. /*
  544. * Set initial io register bits from burst code.
  545. */
  546. static inline void sym_init_burst(struct sym_hcb *np, u_char bc)
  547. {
  548. np->rv_ctest4 &= ~0x80;
  549. np->rv_dmode &= ~(0x3 << 6);
  550. np->rv_ctest5 &= ~0x4;
  551. if (!bc) {
  552. np->rv_ctest4 |= 0x80;
  553. }
  554. else {
  555. --bc;
  556. np->rv_dmode |= ((bc & 0x3) << 6);
  557. np->rv_ctest5 |= (bc & 0x4);
  558. }
  559. }
  560. /*
  561. * Save initial settings of some IO registers.
  562. * Assumed to have been set by BIOS.
  563. * We cannot reset the chip prior to reading the
  564. * IO registers, since informations will be lost.
  565. * Since the SCRIPTS processor may be running, this
  566. * is not safe on paper, but it seems to work quite
  567. * well. :)
  568. */
  569. static void sym_save_initial_setting (struct sym_hcb *np)
  570. {
  571. np->sv_scntl0 = INB(np, nc_scntl0) & 0x0a;
  572. np->sv_scntl3 = INB(np, nc_scntl3) & 0x07;
  573. np->sv_dmode = INB(np, nc_dmode) & 0xce;
  574. np->sv_dcntl = INB(np, nc_dcntl) & 0xa8;
  575. np->sv_ctest3 = INB(np, nc_ctest3) & 0x01;
  576. np->sv_ctest4 = INB(np, nc_ctest4) & 0x80;
  577. np->sv_gpcntl = INB(np, nc_gpcntl);
  578. np->sv_stest1 = INB(np, nc_stest1);
  579. np->sv_stest2 = INB(np, nc_stest2) & 0x20;
  580. np->sv_stest4 = INB(np, nc_stest4);
  581. if (np->features & FE_C10) { /* Always large DMA fifo + ultra3 */
  582. np->sv_scntl4 = INB(np, nc_scntl4);
  583. np->sv_ctest5 = INB(np, nc_ctest5) & 0x04;
  584. }
  585. else
  586. np->sv_ctest5 = INB(np, nc_ctest5) & 0x24;
  587. }
  588. /*
  589. * Set SCSI BUS mode.
  590. * - LVD capable chips (895/895A/896/1010) report the current BUS mode
  591. * through the STEST4 IO register.
  592. * - For previous generation chips (825/825A/875), the user has to tell us
  593. * how to check against HVD, since a 100% safe algorithm is not possible.
  594. */
  595. static void sym_set_bus_mode(struct sym_hcb *np, struct sym_nvram *nvram)
  596. {
  597. if (np->scsi_mode)
  598. return;
  599. np->scsi_mode = SMODE_SE;
  600. if (np->features & (FE_ULTRA2|FE_ULTRA3))
  601. np->scsi_mode = (np->sv_stest4 & SMODE);
  602. else if (np->features & FE_DIFF) {
  603. if (SYM_SETUP_SCSI_DIFF == 1) {
  604. if (np->sv_scntl3) {
  605. if (np->sv_stest2 & 0x20)
  606. np->scsi_mode = SMODE_HVD;
  607. } else if (nvram->type == SYM_SYMBIOS_NVRAM) {
  608. if (!(INB(np, nc_gpreg) & 0x08))
  609. np->scsi_mode = SMODE_HVD;
  610. }
  611. } else if (SYM_SETUP_SCSI_DIFF == 2)
  612. np->scsi_mode = SMODE_HVD;
  613. }
  614. if (np->scsi_mode == SMODE_HVD)
  615. np->rv_stest2 |= 0x20;
  616. }
  617. /*
  618. * Prepare io register values used by sym_start_up()
  619. * according to selected and supported features.
  620. */
  621. static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, struct sym_nvram *nvram)
  622. {
  623. struct sym_data *sym_data = shost_priv(shost);
  624. struct pci_dev *pdev = sym_data->pdev;
  625. u_char burst_max;
  626. u32 period;
  627. int i;
  628. np->maxwide = (np->features & FE_WIDE) ? 1 : 0;
  629. /*
  630. * Guess the frequency of the chip's clock.
  631. */
  632. if (np->features & (FE_ULTRA3 | FE_ULTRA2))
  633. np->clock_khz = 160000;
  634. else if (np->features & FE_ULTRA)
  635. np->clock_khz = 80000;
  636. else
  637. np->clock_khz = 40000;
  638. /*
  639. * Get the clock multiplier factor.
  640. */
  641. if (np->features & FE_QUAD)
  642. np->multiplier = 4;
  643. else if (np->features & FE_DBLR)
  644. np->multiplier = 2;
  645. else
  646. np->multiplier = 1;
  647. /*
  648. * Measure SCSI clock frequency for chips
  649. * it may vary from assumed one.
  650. */
  651. if (np->features & FE_VARCLK)
  652. sym_getclock(np, np->multiplier);
  653. /*
  654. * Divisor to be used for async (timer pre-scaler).
  655. */
  656. i = np->clock_divn - 1;
  657. while (--i >= 0) {
  658. if (10ul * SYM_CONF_MIN_ASYNC * np->clock_khz > div_10M[i]) {
  659. ++i;
  660. break;
  661. }
  662. }
  663. np->rv_scntl3 = i+1;
  664. /*
  665. * The C1010 uses hardwired divisors for async.
  666. * So, we just throw away, the async. divisor.:-)
  667. */
  668. if (np->features & FE_C10)
  669. np->rv_scntl3 = 0;
  670. /*
  671. * Minimum synchronous period factor supported by the chip.
  672. * Btw, 'period' is in tenths of nanoseconds.
  673. */
  674. period = (4 * div_10M[0] + np->clock_khz - 1) / np->clock_khz;
  675. if (period <= 250) np->minsync = 10;
  676. else if (period <= 303) np->minsync = 11;
  677. else if (period <= 500) np->minsync = 12;
  678. else np->minsync = (period + 40 - 1) / 40;
  679. /*
  680. * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
  681. */
  682. if (np->minsync < 25 &&
  683. !(np->features & (FE_ULTRA|FE_ULTRA2|FE_ULTRA3)))
  684. np->minsync = 25;
  685. else if (np->minsync < 12 &&
  686. !(np->features & (FE_ULTRA2|FE_ULTRA3)))
  687. np->minsync = 12;
  688. /*
  689. * Maximum synchronous period factor supported by the chip.
  690. */
  691. period = (11 * div_10M[np->clock_divn - 1]) / (4 * np->clock_khz);
  692. np->maxsync = period > 2540 ? 254 : period / 10;
  693. /*
  694. * If chip is a C1010, guess the sync limits in DT mode.
  695. */
  696. if ((np->features & (FE_C10|FE_ULTRA3)) == (FE_C10|FE_ULTRA3)) {
  697. if (np->clock_khz == 160000) {
  698. np->minsync_dt = 9;
  699. np->maxsync_dt = 50;
  700. np->maxoffs_dt = nvram->type ? 62 : 31;
  701. }
  702. }
  703. /*
  704. * 64 bit addressing (895A/896/1010) ?
  705. */
  706. if (np->features & FE_DAC) {
  707. if (!use_dac(np))
  708. np->rv_ccntl1 |= (DDAC);
  709. else if (SYM_CONF_DMA_ADDRESSING_MODE == 1)
  710. np->rv_ccntl1 |= (XTIMOD | EXTIBMV);
  711. else if (SYM_CONF_DMA_ADDRESSING_MODE == 2)
  712. np->rv_ccntl1 |= (0 | EXTIBMV);
  713. }
  714. /*
  715. * Phase mismatch handled by SCRIPTS (895A/896/1010) ?
  716. */
  717. if (np->features & FE_NOPM)
  718. np->rv_ccntl0 |= (ENPMJ);
  719. /*
  720. * C1010-33 Errata: Part Number:609-039638 (rev. 1) is fixed.
  721. * In dual channel mode, contention occurs if internal cycles
  722. * are used. Disable internal cycles.
  723. */
  724. if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
  725. pdev->revision < 0x1)
  726. np->rv_ccntl0 |= DILS;
  727. /*
  728. * Select burst length (dwords)
  729. */
  730. burst_max = SYM_SETUP_BURST_ORDER;
  731. if (burst_max == 255)
  732. burst_max = burst_code(np->sv_dmode, np->sv_ctest4,
  733. np->sv_ctest5);
  734. if (burst_max > 7)
  735. burst_max = 7;
  736. if (burst_max > np->maxburst)
  737. burst_max = np->maxburst;
  738. /*
  739. * DEL 352 - 53C810 Rev x11 - Part Number 609-0392140 - ITEM 2.
  740. * This chip and the 860 Rev 1 may wrongly use PCI cache line
  741. * based transactions on LOAD/STORE instructions. So we have
  742. * to prevent these chips from using such PCI transactions in
  743. * this driver. The generic ncr driver that does not use
  744. * LOAD/STORE instructions does not need this work-around.
  745. */
  746. if ((pdev->device == PCI_DEVICE_ID_NCR_53C810 &&
  747. pdev->revision >= 0x10 && pdev->revision <= 0x11) ||
  748. (pdev->device == PCI_DEVICE_ID_NCR_53C860 &&
  749. pdev->revision <= 0x1))
  750. np->features &= ~(FE_WRIE|FE_ERL|FE_ERMP);
  751. /*
  752. * Select all supported special features.
  753. * If we are using on-board RAM for scripts, prefetch (PFEN)
  754. * does not help, but burst op fetch (BOF) does.
  755. * Disabling PFEN makes sure BOF will be used.
  756. */
  757. if (np->features & FE_ERL)
  758. np->rv_dmode |= ERL; /* Enable Read Line */
  759. if (np->features & FE_BOF)
  760. np->rv_dmode |= BOF; /* Burst Opcode Fetch */
  761. if (np->features & FE_ERMP)
  762. np->rv_dmode |= ERMP; /* Enable Read Multiple */
  763. #if 1
  764. if ((np->features & FE_PFEN) && !np->ram_ba)
  765. #else
  766. if (np->features & FE_PFEN)
  767. #endif
  768. np->rv_dcntl |= PFEN; /* Prefetch Enable */
  769. if (np->features & FE_CLSE)
  770. np->rv_dcntl |= CLSE; /* Cache Line Size Enable */
  771. if (np->features & FE_WRIE)
  772. np->rv_ctest3 |= WRIE; /* Write and Invalidate */
  773. if (np->features & FE_DFS)
  774. np->rv_ctest5 |= DFS; /* Dma Fifo Size */
  775. /*
  776. * Select some other
  777. */
  778. np->rv_ctest4 |= MPEE; /* Master parity checking */
  779. np->rv_scntl0 |= 0x0a; /* full arb., ena parity, par->ATN */
  780. /*
  781. * Get parity checking, host ID and verbose mode from NVRAM
  782. */
  783. np->myaddr = 255;
  784. np->scsi_mode = 0;
  785. sym_nvram_setup_host(shost, np, nvram);
  786. /*
  787. * Get SCSI addr of host adapter (set by bios?).
  788. */
  789. if (np->myaddr == 255) {
  790. np->myaddr = INB(np, nc_scid) & 0x07;
  791. if (!np->myaddr)
  792. np->myaddr = SYM_SETUP_HOST_ID;
  793. }
  794. /*
  795. * Prepare initial io register bits for burst length
  796. */
  797. sym_init_burst(np, burst_max);
  798. sym_set_bus_mode(np, nvram);
  799. /*
  800. * Set LED support from SCRIPTS.
  801. * Ignore this feature for boards known to use a
  802. * specific GPIO wiring and for the 895A, 896
  803. * and 1010 that drive the LED directly.
  804. */
  805. if ((SYM_SETUP_SCSI_LED ||
  806. (nvram->type == SYM_SYMBIOS_NVRAM ||
  807. (nvram->type == SYM_TEKRAM_NVRAM &&
  808. pdev->device == PCI_DEVICE_ID_NCR_53C895))) &&
  809. !(np->features & FE_LEDC) && !(np->sv_gpcntl & 0x01))
  810. np->features |= FE_LED0;
  811. /*
  812. * Set irq mode.
  813. */
  814. switch(SYM_SETUP_IRQ_MODE & 3) {
  815. case 2:
  816. np->rv_dcntl |= IRQM;
  817. break;
  818. case 1:
  819. np->rv_dcntl |= (np->sv_dcntl & IRQM);
  820. break;
  821. default:
  822. break;
  823. }
  824. /*
  825. * Configure targets according to driver setup.
  826. * If NVRAM present get targets setup from NVRAM.
  827. */
  828. for (i = 0 ; i < SYM_CONF_MAX_TARGET ; i++) {
  829. struct sym_tcb *tp = &np->target[i];
  830. tp->usrflags |= (SYM_DISC_ENABLED | SYM_TAGS_ENABLED);
  831. tp->usrtags = SYM_SETUP_MAX_TAG;
  832. tp->usr_width = np->maxwide;
  833. tp->usr_period = 9;
  834. sym_nvram_setup_target(tp, i, nvram);
  835. if (!tp->usrtags)
  836. tp->usrflags &= ~SYM_TAGS_ENABLED;
  837. }
  838. /*
  839. * Let user know about the settings.
  840. */
  841. printf("%s: %s, ID %d, Fast-%d, %s, %s\n", sym_name(np),
  842. sym_nvram_type(nvram), np->myaddr,
  843. (np->features & FE_ULTRA3) ? 80 :
  844. (np->features & FE_ULTRA2) ? 40 :
  845. (np->features & FE_ULTRA) ? 20 : 10,
  846. sym_scsi_bus_mode(np->scsi_mode),
  847. (np->rv_scntl0 & 0xa) ? "parity checking" : "NO parity");
  848. /*
  849. * Tell him more on demand.
  850. */
  851. if (sym_verbose) {
  852. printf("%s: %s IRQ line driver%s\n",
  853. sym_name(np),
  854. np->rv_dcntl & IRQM ? "totem pole" : "open drain",
  855. np->ram_ba ? ", using on-chip SRAM" : "");
  856. printf("%s: using %s firmware.\n", sym_name(np), np->fw_name);
  857. if (np->features & FE_NOPM)
  858. printf("%s: handling phase mismatch from SCRIPTS.\n",
  859. sym_name(np));
  860. }
  861. /*
  862. * And still more.
  863. */
  864. if (sym_verbose >= 2) {
  865. printf ("%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
  866. "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
  867. sym_name(np), np->sv_scntl3, np->sv_dmode, np->sv_dcntl,
  868. np->sv_ctest3, np->sv_ctest4, np->sv_ctest5);
  869. printf ("%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
  870. "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
  871. sym_name(np), np->rv_scntl3, np->rv_dmode, np->rv_dcntl,
  872. np->rv_ctest3, np->rv_ctest4, np->rv_ctest5);
  873. }
  874. return 0;
  875. }
  876. /*
  877. * Test the pci bus snoop logic :-(
  878. *
  879. * Has to be called with interrupts disabled.
  880. */
  881. #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
  882. static int sym_regtest(struct sym_hcb *np)
  883. {
  884. register volatile u32 data;
  885. /*
  886. * chip registers may NOT be cached.
  887. * write 0xffffffff to a read only register area,
  888. * and try to read it back.
  889. */
  890. data = 0xffffffff;
  891. OUTL(np, nc_dstat, data);
  892. data = INL(np, nc_dstat);
  893. #if 1
  894. if (data == 0xffffffff) {
  895. #else
  896. if ((data & 0xe2f0fffd) != 0x02000080) {
  897. #endif
  898. printf ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
  899. (unsigned) data);
  900. return 0x10;
  901. }
  902. return 0;
  903. }
  904. #else
  905. static inline int sym_regtest(struct sym_hcb *np)
  906. {
  907. return 0;
  908. }
  909. #endif
  910. static int sym_snooptest(struct sym_hcb *np)
  911. {
  912. u32 sym_rd, sym_wr, sym_bk, host_rd, host_wr, pc, dstat;
  913. int i, err;
  914. err = sym_regtest(np);
  915. if (err)
  916. return err;
  917. restart_test:
  918. /*
  919. * Enable Master Parity Checking as we intend
  920. * to enable it for normal operations.
  921. */
  922. OUTB(np, nc_ctest4, (np->rv_ctest4 & MPEE));
  923. /*
  924. * init
  925. */
  926. pc = SCRIPTZ_BA(np, snooptest);
  927. host_wr = 1;
  928. sym_wr = 2;
  929. /*
  930. * Set memory and register.
  931. */
  932. np->scratch = cpu_to_scr(host_wr);
  933. OUTL(np, nc_temp, sym_wr);
  934. /*
  935. * Start script (exchange values)
  936. */
  937. OUTL(np, nc_dsa, np->hcb_ba);
  938. OUTL_DSP(np, pc);
  939. /*
  940. * Wait 'til done (with timeout)
  941. */
  942. for (i=0; i<SYM_SNOOP_TIMEOUT; i++)
  943. if (INB(np, nc_istat) & (INTF|SIP|DIP))
  944. break;
  945. if (i>=SYM_SNOOP_TIMEOUT) {
  946. printf ("CACHE TEST FAILED: timeout.\n");
  947. return (0x20);
  948. }
  949. /*
  950. * Check for fatal DMA errors.
  951. */
  952. dstat = INB(np, nc_dstat);
  953. #if 1 /* Band aiding for broken hardwares that fail PCI parity */
  954. if ((dstat & MDPE) && (np->rv_ctest4 & MPEE)) {
  955. printf ("%s: PCI DATA PARITY ERROR DETECTED - "
  956. "DISABLING MASTER DATA PARITY CHECKING.\n",
  957. sym_name(np));
  958. np->rv_ctest4 &= ~MPEE;
  959. goto restart_test;
  960. }
  961. #endif
  962. if (dstat & (MDPE|BF|IID)) {
  963. printf ("CACHE TEST FAILED: DMA error (dstat=0x%02x).", dstat);
  964. return (0x80);
  965. }
  966. /*
  967. * Save termination position.
  968. */
  969. pc = INL(np, nc_dsp);
  970. /*
  971. * Read memory and register.
  972. */
  973. host_rd = scr_to_cpu(np->scratch);
  974. sym_rd = INL(np, nc_scratcha);
  975. sym_bk = INL(np, nc_temp);
  976. /*
  977. * Check termination position.
  978. */
  979. if (pc != SCRIPTZ_BA(np, snoopend)+8) {
  980. printf ("CACHE TEST FAILED: script execution failed.\n");
  981. printf ("start=%08lx, pc=%08lx, end=%08lx\n",
  982. (u_long) SCRIPTZ_BA(np, snooptest), (u_long) pc,
  983. (u_long) SCRIPTZ_BA(np, snoopend) +8);
  984. return (0x40);
  985. }
  986. /*
  987. * Show results.
  988. */
  989. if (host_wr != sym_rd) {
  990. printf ("CACHE TEST FAILED: host wrote %d, chip read %d.\n",
  991. (int) host_wr, (int) sym_rd);
  992. err |= 1;
  993. }
  994. if (host_rd != sym_wr) {
  995. printf ("CACHE TEST FAILED: chip wrote %d, host read %d.\n",
  996. (int) sym_wr, (int) host_rd);
  997. err |= 2;
  998. }
  999. if (sym_bk != sym_wr) {
  1000. printf ("CACHE TEST FAILED: chip wrote %d, read back %d.\n",
  1001. (int) sym_wr, (int) sym_bk);
  1002. err |= 4;
  1003. }
  1004. return err;
  1005. }
  1006. /*
  1007. * log message for real hard errors
  1008. *
  1009. * sym0 targ 0?: ERROR (ds:si) (so-si-sd) (sx/s3/s4) @ name (dsp:dbc).
  1010. * reg: r0 r1 r2 r3 r4 r5 r6 ..... rf.
  1011. *
  1012. * exception register:
  1013. * ds: dstat
  1014. * si: sist
  1015. *
  1016. * SCSI bus lines:
  1017. * so: control lines as driven by chip.
  1018. * si: control lines as seen by chip.
  1019. * sd: scsi data lines as seen by chip.
  1020. *
  1021. * wide/fastmode:
  1022. * sx: sxfer (see the manual)
  1023. * s3: scntl3 (see the manual)
  1024. * s4: scntl4 (see the manual)
  1025. *
  1026. * current script command:
  1027. * dsp: script address (relative to start of script).
  1028. * dbc: first word of script command.
  1029. *
  1030. * First 24 register of the chip:
  1031. * r0..rf
  1032. */
  1033. static void sym_log_hard_error(struct Scsi_Host *shost, u_short sist, u_char dstat)
  1034. {
  1035. struct sym_hcb *np = sym_get_hcb(shost);
  1036. u32 dsp;
  1037. int script_ofs;
  1038. int script_size;
  1039. char *script_name;
  1040. u_char *script_base;
  1041. int i;
  1042. dsp = INL(np, nc_dsp);
  1043. if (dsp > np->scripta_ba &&
  1044. dsp <= np->scripta_ba + np->scripta_sz) {
  1045. script_ofs = dsp - np->scripta_ba;
  1046. script_size = np->scripta_sz;
  1047. script_base = (u_char *) np->scripta0;
  1048. script_name = "scripta";
  1049. }
  1050. else if (np->scriptb_ba < dsp &&
  1051. dsp <= np->scriptb_ba + np->scriptb_sz) {
  1052. script_ofs = dsp - np->scriptb_ba;
  1053. script_size = np->scriptb_sz;
  1054. script_base = (u_char *) np->scriptb0;
  1055. script_name = "scriptb";
  1056. } else {
  1057. script_ofs = dsp;
  1058. script_size = 0;
  1059. script_base = NULL;
  1060. script_name = "mem";
  1061. }
  1062. printf ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x/%x) @ (%s %x:%08x).\n",
  1063. sym_name(np), (unsigned)INB(np, nc_sdid)&0x0f, dstat, sist,
  1064. (unsigned)INB(np, nc_socl), (unsigned)INB(np, nc_sbcl),
  1065. (unsigned)INB(np, nc_sbdl), (unsigned)INB(np, nc_sxfer),
  1066. (unsigned)INB(np, nc_scntl3),
  1067. (np->features & FE_C10) ? (unsigned)INB(np, nc_scntl4) : 0,
  1068. script_name, script_ofs, (unsigned)INL(np, nc_dbc));
  1069. if (((script_ofs & 3) == 0) &&
  1070. (unsigned)script_ofs < script_size) {
  1071. printf ("%s: script cmd = %08x\n", sym_name(np),
  1072. scr_to_cpu((int) *(u32 *)(script_base + script_ofs)));
  1073. }
  1074. printf("%s: regdump:", sym_name(np));
  1075. for (i = 0; i < 24; i++)
  1076. printf(" %02x", (unsigned)INB_OFF(np, i));
  1077. printf(".\n");
  1078. /*
  1079. * PCI BUS error.
  1080. */
  1081. if (dstat & (MDPE|BF))
  1082. sym_log_bus_error(shost);
  1083. }
  1084. void sym_dump_registers(struct Scsi_Host *shost)
  1085. {
  1086. struct sym_hcb *np = sym_get_hcb(shost);
  1087. u_short sist;
  1088. u_char dstat;
  1089. sist = INW(np, nc_sist);
  1090. dstat = INB(np, nc_dstat);
  1091. sym_log_hard_error(shost, sist, dstat);
  1092. }
  1093. static struct sym_chip sym_dev_table[] = {
  1094. {PCI_DEVICE_ID_NCR_53C810, 0x0f, "810", 4, 8, 4, 64,
  1095. FE_ERL}
  1096. ,
  1097. #ifdef SYM_DEBUG_GENERIC_SUPPORT
  1098. {PCI_DEVICE_ID_NCR_53C810, 0xff, "810a", 4, 8, 4, 1,
  1099. FE_BOF}
  1100. ,
  1101. #else
  1102. {PCI_DEVICE_ID_NCR_53C810, 0xff, "810a", 4, 8, 4, 1,
  1103. FE_CACHE_SET|FE_LDSTR|FE_PFEN|FE_BOF}
  1104. ,
  1105. #endif
  1106. {PCI_DEVICE_ID_NCR_53C815, 0xff, "815", 4, 8, 4, 64,
  1107. FE_BOF|FE_ERL}
  1108. ,
  1109. {PCI_DEVICE_ID_NCR_53C825, 0x0f, "825", 6, 8, 4, 64,
  1110. FE_WIDE|FE_BOF|FE_ERL|FE_DIFF}
  1111. ,
  1112. {PCI_DEVICE_ID_NCR_53C825, 0xff, "825a", 6, 8, 4, 2,
  1113. FE_WIDE|FE_CACHE0_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|FE_RAM|FE_DIFF}
  1114. ,
  1115. {PCI_DEVICE_ID_NCR_53C860, 0xff, "860", 4, 8, 5, 1,
  1116. FE_ULTRA|FE_CACHE_SET|FE_BOF|FE_LDSTR|FE_PFEN}
  1117. ,
  1118. {PCI_DEVICE_ID_NCR_53C875, 0x01, "875", 6, 16, 5, 2,
  1119. FE_WIDE|FE_ULTRA|FE_CACHE0_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|
  1120. FE_RAM|FE_DIFF|FE_VARCLK}
  1121. ,
  1122. {PCI_DEVICE_ID_NCR_53C875, 0xff, "875", 6, 16, 5, 2,
  1123. FE_WIDE|FE_ULTRA|FE_DBLR|FE_CACHE0_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|
  1124. FE_RAM|FE_DIFF|FE_VARCLK}
  1125. ,
  1126. {PCI_DEVICE_ID_NCR_53C875J, 0xff, "875J", 6, 16, 5, 2,
  1127. FE_WIDE|FE_ULTRA|FE_DBLR|FE_CACHE0_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|
  1128. FE_RAM|FE_DIFF|FE_VARCLK}
  1129. ,
  1130. {PCI_DEVICE_ID_NCR_53C885, 0xff, "885", 6, 16, 5, 2,
  1131. FE_WIDE|FE_ULTRA|FE_DBLR|FE_CACHE0_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|
  1132. FE_RAM|FE_DIFF|FE_VARCLK}
  1133. ,
  1134. #ifdef SYM_DEBUG_GENERIC_SUPPORT
  1135. {PCI_DEVICE_ID_NCR_53C895, 0xff, "895", 6, 31, 7, 2,
  1136. FE_WIDE|FE_ULTRA2|FE_QUAD|FE_CACHE_SET|FE_BOF|FE_DFS|
  1137. FE_RAM|FE_LCKFRQ}
  1138. ,
  1139. #else
  1140. {PCI_DEVICE_ID_NCR_53C895, 0xff, "895", 6, 31, 7, 2,
  1141. FE_WIDE|FE_ULTRA2|FE_QUAD|FE_CACHE_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|
  1142. FE_RAM|FE_LCKFRQ}
  1143. ,
  1144. #endif
  1145. {PCI_DEVICE_ID_NCR_53C896, 0xff, "896", 6, 31, 7, 4,
  1146. FE_WIDE|FE_ULTRA2|FE_QUAD|FE_CACHE_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|
  1147. FE_RAM|FE_RAM8K|FE_64BIT|FE_DAC|FE_IO256|FE_NOPM|FE_LEDC|FE_LCKFRQ}
  1148. ,
  1149. {PCI_DEVICE_ID_LSI_53C895A, 0xff, "895a", 6, 31, 7, 4,
  1150. FE_WIDE|FE_ULTRA2|FE_QUAD|FE_CACHE_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|
  1151. FE_RAM|FE_RAM8K|FE_DAC|FE_IO256|FE_NOPM|FE_LEDC|FE_LCKFRQ}
  1152. ,
  1153. {PCI_DEVICE_ID_LSI_53C875A, 0xff, "875a", 6, 31, 7, 4,
  1154. FE_WIDE|FE_ULTRA|FE_QUAD|FE_CACHE_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|
  1155. FE_RAM|FE_DAC|FE_IO256|FE_NOPM|FE_LEDC|FE_LCKFRQ}
  1156. ,
  1157. {PCI_DEVICE_ID_LSI_53C1010_33, 0x00, "1010-33", 6, 31, 7, 8,
  1158. FE_WIDE|FE_ULTRA3|FE_QUAD|FE_CACHE_SET|FE_BOF|FE_DFBC|FE_LDSTR|FE_PFEN|
  1159. FE_RAM|FE_RAM8K|FE_64BIT|FE_DAC|FE_IO256|FE_NOPM|FE_LEDC|FE_CRC|
  1160. FE_C10}
  1161. ,
  1162. {PCI_DEVICE_ID_LSI_53C1010_33, 0xff, "1010-33", 6, 31, 7, 8,
  1163. FE_WIDE|FE_ULTRA3|FE_QUAD|FE_CACHE_SET|FE_BOF|FE_DFBC|FE_LDSTR|FE_PFEN|
  1164. FE_RAM|FE_RAM8K|FE_64BIT|FE_DAC|FE_IO256|FE_NOPM|FE_LEDC|FE_CRC|
  1165. FE_C10|FE_U3EN}
  1166. ,
  1167. {PCI_DEVICE_ID_LSI_53C1010_66, 0xff, "1010-66", 6, 31, 7, 8,
  1168. FE_WIDE|FE_ULTRA3|FE_QUAD|FE_CACHE_SET|FE_BOF|FE_DFBC|FE_LDSTR|FE_PFEN|
  1169. FE_RAM|FE_RAM8K|FE_64BIT|FE_DAC|FE_IO256|FE_NOPM|FE_LEDC|FE_66MHZ|FE_CRC|
  1170. FE_C10|FE_U3EN}
  1171. ,
  1172. {PCI_DEVICE_ID_LSI_53C1510, 0xff, "1510d", 6, 31, 7, 4,
  1173. FE_WIDE|FE_ULTRA2|FE_QUAD|FE_CACHE_SET|FE_BOF|FE_DFS|FE_LDSTR|FE_PFEN|
  1174. FE_RAM|FE_IO256|FE_LEDC}
  1175. };
  1176. #define sym_num_devs (ARRAY_SIZE(sym_dev_table))
  1177. /*
  1178. * Look up the chip table.
  1179. *
  1180. * Return a pointer to the chip entry if found,
  1181. * zero otherwise.
  1182. */
  1183. struct sym_chip *
  1184. sym_lookup_chip_table (u_short device_id, u_char revision)
  1185. {
  1186. struct sym_chip *chip;
  1187. int i;
  1188. for (i = 0; i < sym_num_devs; i++) {
  1189. chip = &sym_dev_table[i];
  1190. if (device_id != chip->device_id)
  1191. continue;
  1192. if (revision > chip->revision_id)
  1193. continue;
  1194. return chip;
  1195. }
  1196. return NULL;
  1197. }
  1198. #if SYM_CONF_DMA_ADDRESSING_MODE == 2
  1199. /*
  1200. * Lookup the 64 bit DMA segments map.
  1201. * This is only used if the direct mapping
  1202. * has been unsuccessful.
  1203. */
  1204. int sym_lookup_dmap(struct sym_hcb *np, u32 h, int s)
  1205. {
  1206. int i;
  1207. if (!use_dac(np))
  1208. goto weird;
  1209. /* Look up existing mappings */
  1210. for (i = SYM_DMAP_SIZE-1; i > 0; i--) {
  1211. if (h == np->dmap_bah[i])
  1212. return i;
  1213. }
  1214. /* If direct mapping is free, get it */
  1215. if (!np->dmap_bah[s])
  1216. goto new;
  1217. /* Collision -> lookup free mappings */
  1218. for (s = SYM_DMAP_SIZE-1; s > 0; s--) {
  1219. if (!np->dmap_bah[s])
  1220. goto new;
  1221. }
  1222. weird:
  1223. panic("sym: ran out of 64 bit DMA segment registers");
  1224. return -1;
  1225. new:
  1226. np->dmap_bah[s] = h;
  1227. np->dmap_dirty = 1;
  1228. return s;
  1229. }
  1230. /*
  1231. * Update IO registers scratch C..R so they will be
  1232. * in sync. with queued CCB expectations.
  1233. */
  1234. static void sym_update_dmap_regs(struct sym_hcb *np)
  1235. {
  1236. int o, i;
  1237. if (!np->dmap_dirty)
  1238. return;
  1239. o = offsetof(struct sym_reg, nc_scrx[0]);
  1240. for (i = 0; i < SYM_DMAP_SIZE; i++) {
  1241. OUTL_OFF(np, o, np->dmap_bah[i]);
  1242. o += 4;
  1243. }
  1244. np->dmap_dirty = 0;
  1245. }
  1246. #endif
  1247. /* Enforce all the fiddly SPI rules and the chip limitations */
  1248. static void sym_check_goals(struct sym_hcb *np, struct scsi_target *starget,
  1249. struct sym_trans *goal)
  1250. {
  1251. if (!spi_support_wide(starget))
  1252. goal->width = 0;
  1253. if (!spi_support_sync(starget)) {
  1254. goal->iu = 0;
  1255. goal->dt = 0;
  1256. goal->qas = 0;
  1257. goal->offset = 0;
  1258. return;
  1259. }
  1260. if (spi_support_dt(starget)) {
  1261. if (spi_support_dt_only(starget))
  1262. goal->dt = 1;
  1263. if (goal->offset == 0)
  1264. goal->dt = 0;
  1265. } else {
  1266. goal->dt = 0;
  1267. }
  1268. /* Some targets fail to properly negotiate DT in SE mode */
  1269. if ((np->scsi_mode != SMODE_LVD) || !(np->features & FE_U3EN))
  1270. goal->dt = 0;
  1271. if (goal->dt) {
  1272. /* all DT transfers must be wide */
  1273. goal->width = 1;
  1274. if (goal->offset > np->maxoffs_dt)
  1275. goal->offset = np->maxoffs_dt;
  1276. if (goal->period < np->minsync_dt)
  1277. goal->period = np->minsync_dt;
  1278. if (goal->period > np->maxsync_dt)
  1279. goal->period = np->maxsync_dt;
  1280. } else {
  1281. goal->iu = goal->qas = 0;
  1282. if (goal->offset > np->maxoffs)
  1283. goal->offset = np->maxoffs;
  1284. if (goal->period < np->minsync)
  1285. goal->period = np->minsync;
  1286. if (goal->period > np->maxsync)
  1287. goal->period = np->maxsync;
  1288. }
  1289. }
  1290. /*
  1291. * Prepare the next negotiation message if needed.
  1292. *
  1293. * Fill in the part of message buffer that contains the
  1294. * negotiation and the nego_status field of the CCB.
  1295. * Returns the size of the message in bytes.
  1296. */
  1297. static int sym_prepare_nego(struct sym_hcb *np, struct sym_ccb *cp, u_char *msgptr)
  1298. {
  1299. struct sym_tcb *tp = &np->target[cp->target];
  1300. struct scsi_target *starget = tp->starget;
  1301. struct sym_trans *goal = &tp->tgoal;
  1302. int msglen = 0;
  1303. int nego;
  1304. sym_check_goals(np, starget, goal);
  1305. /*
  1306. * Many devices implement PPR in a buggy way, so only use it if we
  1307. * really want to.
  1308. */
  1309. if (goal->renego == NS_PPR || (goal->offset &&
  1310. (goal->iu || goal->dt || goal->qas || (goal->period < 0xa)))) {
  1311. nego = NS_PPR;
  1312. } else if (goal->renego == NS_WIDE || goal->width) {
  1313. nego = NS_WIDE;
  1314. } else if (goal->renego == NS_SYNC || goal->offset) {
  1315. nego = NS_SYNC;
  1316. } else {
  1317. goal->check_nego = 0;
  1318. nego = 0;
  1319. }
  1320. switch (nego) {
  1321. case NS_SYNC:
  1322. msglen += spi_populate_sync_msg(msgptr + msglen, goal->period,
  1323. goal->offset);
  1324. break;
  1325. case NS_WIDE:
  1326. msglen += spi_populate_width_msg(msgptr + msglen, goal->width);
  1327. break;
  1328. case NS_PPR:
  1329. msglen += spi_populate_ppr_msg(msgptr + msglen, goal->period,
  1330. goal->offset, goal->width,
  1331. (goal->iu ? PPR_OPT_IU : 0) |
  1332. (goal->dt ? PPR_OPT_DT : 0) |
  1333. (goal->qas ? PPR_OPT_QAS : 0));
  1334. break;
  1335. }
  1336. cp->nego_status = nego;
  1337. if (nego) {
  1338. tp->nego_cp = cp; /* Keep track a nego will be performed */
  1339. if (DEBUG_FLAGS & DEBUG_NEGO) {
  1340. sym_print_nego_msg(np, cp->target,
  1341. nego == NS_SYNC ? "sync msgout" :
  1342. nego == NS_WIDE ? "wide msgout" :
  1343. "ppr msgout", msgptr);
  1344. }
  1345. }
  1346. return msglen;
  1347. }
  1348. /*
  1349. * Insert a job into the start queue.
  1350. */
  1351. void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp)
  1352. {
  1353. u_short qidx;
  1354. #ifdef SYM_CONF_IARB_SUPPORT
  1355. /*
  1356. * If the previously queued CCB is not yet done,
  1357. * set the IARB hint. The SCRIPTS will go with IARB
  1358. * for this job when starting the previous one.
  1359. * We leave devices a chance to win arbitration by
  1360. * not using more than 'iarb_max' consecutive
  1361. * immediate arbitrations.
  1362. */
  1363. if (np->last_cp && np->iarb_count < np->iarb_max) {
  1364. np->last_cp->host_flags |= HF_HINT_IARB;
  1365. ++np->iarb_count;
  1366. }
  1367. else
  1368. np->iarb_count = 0;
  1369. np->last_cp = cp;
  1370. #endif
  1371. #if SYM_CONF_DMA_ADDRESSING_MODE == 2
  1372. /*
  1373. * Make SCRIPTS aware of the 64 bit DMA
  1374. * segment registers not being up-to-date.
  1375. */
  1376. if (np->dmap_dirty)
  1377. cp->host_xflags |= HX_DMAP_DIRTY;
  1378. #endif
  1379. /*
  1380. * Insert first the idle task and then our job.
  1381. * The MBs should ensure proper ordering.
  1382. */
  1383. qidx = np->squeueput + 2;
  1384. if (qidx >= MAX_QUEUE*2) qidx = 0;
  1385. np->squeue [qidx] = cpu_to_scr(np->idletask_ba);
  1386. MEMORY_WRITE_BARRIER();
  1387. np->squeue [np->squeueput] = cpu_to_scr(cp->ccb_ba);
  1388. np->squeueput = qidx;
  1389. if (DEBUG_FLAGS & DEBUG_QUEUE)
  1390. scmd_printk(KERN_DEBUG, cp->cmd, "queuepos=%d\n",
  1391. np->squeueput);
  1392. /*
  1393. * Script processor may be waiting for reselect.
  1394. * Wake it up.
  1395. */
  1396. MEMORY_WRITE_BARRIER();
  1397. OUTB(np, nc_istat, SIGP|np->istat_sem);
  1398. }
  1399. #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
  1400. /*
  1401. * Start next ready-to-start CCBs.
  1402. */
  1403. void sym_start_next_ccbs(struct sym_hcb *np, struct sym_lcb *lp, int maxn)
  1404. {
  1405. SYM_QUEHEAD *qp;
  1406. struct sym_ccb *cp;
  1407. /*
  1408. * Paranoia, as usual. :-)
  1409. */
  1410. assert(!lp->started_tags || !lp->started_no_tag);
  1411. /*
  1412. * Try to start as many commands as asked by caller.
  1413. * Prevent from having both tagged and untagged
  1414. * commands queued to the device at the same time.
  1415. */
  1416. while (maxn--) {
  1417. qp = sym_remque_head(&lp->waiting_ccbq);
  1418. if (!qp)
  1419. break;
  1420. cp = sym_que_entry(qp, struct sym_ccb, link2_ccbq);
  1421. if (cp->tag != NO_TAG) {
  1422. if (lp->started_no_tag ||
  1423. lp->started_tags >= lp->started_max) {
  1424. sym_insque_head(qp, &lp->waiting_ccbq);
  1425. break;
  1426. }
  1427. lp->itlq_tbl[cp->tag] = cpu_to_scr(cp->ccb_ba);
  1428. lp->head.resel_sa =
  1429. cpu_to_scr(SCRIPTA_BA(np, resel_tag));
  1430. ++lp->started_tags;
  1431. } else {
  1432. if (lp->started_no_tag || lp->started_tags) {
  1433. sym_insque_head(qp, &lp->waiting_ccbq);
  1434. break;
  1435. }
  1436. lp->head.itl_task_sa = cpu_to_scr(cp->ccb_ba);
  1437. lp->head.resel_sa =
  1438. cpu_to_scr(SCRIPTA_BA(np, resel_no_tag));
  1439. ++lp->started_no_tag;
  1440. }
  1441. cp->started = 1;
  1442. sym_insque_tail(qp, &lp->started_ccbq);
  1443. sym_put_start_queue(np, cp);
  1444. }
  1445. }
  1446. #endif /* SYM_OPT_HANDLE_DEVICE_QUEUEING */
  1447. /*
  1448. * The chip may have completed jobs. Look at the DONE QUEUE.
  1449. *
  1450. * On paper, memory read barriers may be needed here to
  1451. * prevent out of order LOADs by the CPU from having
  1452. * prefetched stale data prior to DMA having occurred.
  1453. */
  1454. static int sym_wakeup_done (struct sym_hcb *np)
  1455. {
  1456. struct sym_ccb *cp;
  1457. int i, n;
  1458. u32 dsa;
  1459. n = 0;
  1460. i = np->dqueueget;
  1461. /* MEMORY_READ_BARRIER(); */
  1462. while (1) {
  1463. dsa = scr_to_cpu(np->dqueue[i]);
  1464. if (!dsa)
  1465. break;
  1466. np->dqueue[i] = 0;
  1467. if ((i = i+2) >= MAX_QUEUE*2)
  1468. i = 0;
  1469. cp = sym_ccb_from_dsa(np, dsa);
  1470. if (cp) {
  1471. MEMORY_READ_BARRIER();
  1472. sym_complete_ok (np, cp);
  1473. ++n;
  1474. }
  1475. else
  1476. printf ("%s: bad DSA (%x) in done queue.\n",
  1477. sym_name(np), (u_int) dsa);
  1478. }
  1479. np->dqueueget = i;
  1480. return n;
  1481. }
  1482. /*
  1483. * Complete all CCBs queued to the COMP queue.
  1484. *
  1485. * These CCBs are assumed:
  1486. * - Not to be referenced either by devices or
  1487. * SCRIPTS-related queues and datas.
  1488. * - To have to be completed with an error condition
  1489. * or requeued.
  1490. *
  1491. * The device queue freeze count is incremented
  1492. * for each CCB that does not prevent this.
  1493. * This function is called when all CCBs involved
  1494. * in error handling/recovery have been reaped.
  1495. */
  1496. static void sym_flush_comp_queue(struct sym_hcb *np, int cam_status)
  1497. {
  1498. SYM_QUEHEAD *qp;
  1499. struct sym_ccb *cp;
  1500. while ((qp = sym_remque_head(&np->comp_ccbq)) != NULL) {
  1501. struct scsi_cmnd *cmd;
  1502. cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
  1503. sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
  1504. /* Leave quiet CCBs waiting for resources */
  1505. if (cp->host_status == HS_WAIT)
  1506. continue;
  1507. cmd = cp->cmd;
  1508. if (cam_status)
  1509. sym_set_cam_status(cmd, cam_status);
  1510. #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
  1511. if (sym_get_cam_status(cmd) == DID_SOFT_ERROR) {
  1512. struct sym_tcb *tp = &np->target[cp->target];
  1513. struct sym_lcb *lp = sym_lp(tp, cp->lun);
  1514. if (lp) {
  1515. sym_remque(&cp->link2_ccbq);
  1516. sym_insque_tail(&cp->link2_ccbq,
  1517. &lp->waiting_ccbq);
  1518. if (cp->started) {
  1519. if (cp->tag != NO_TAG)
  1520. --lp->started_tags;
  1521. else
  1522. --lp->started_no_tag;
  1523. }
  1524. }
  1525. cp->started = 0;
  1526. continue;
  1527. }
  1528. #endif
  1529. sym_free_ccb(np, cp);
  1530. sym_xpt_done(np, cmd);
  1531. }
  1532. }
  1533. /*
  1534. * Complete all active CCBs with error.
  1535. * Used on CHIP/SCSI RESET.
  1536. */
  1537. static void sym_flush_busy_queue (struct sym_hcb *np, int cam_status)
  1538. {
  1539. /*
  1540. * Move all active CCBs to the COMP queue
  1541. * and flush this queue.
  1542. */
  1543. sym_que_splice(&np->busy_ccbq, &np->comp_ccbq);
  1544. sym_que_init(&np->busy_ccbq);
  1545. sym_flush_comp_queue(np, cam_status);
  1546. }
  1547. /*
  1548. * Start chip.
  1549. *
  1550. * 'reason' means:
  1551. * 0: initialisation.
  1552. * 1: SCSI BUS RESET delivered or received.
  1553. * 2: SCSI BUS MODE changed.
  1554. */
  1555. void sym_start_up(struct Scsi_Host *shost, int reason)
  1556. {
  1557. struct sym_data *sym_data = shost_priv(shost);
  1558. struct pci_dev *pdev = sym_data->pdev;
  1559. struct sym_hcb *np = sym_data->ncb;
  1560. int i;
  1561. u32 phys;
  1562. /*
  1563. * Reset chip if asked, otherwise just clear fifos.
  1564. */
  1565. if (reason == 1)
  1566. sym_soft_reset(np);
  1567. else {
  1568. OUTB(np, nc_stest3, TE|CSF);
  1569. OUTONB(np, nc_ctest3, CLF);
  1570. }
  1571. /*
  1572. * Clear Start Queue
  1573. */
  1574. phys = np->squeue_ba;
  1575. for (i = 0; i < MAX_QUEUE*2; i += 2) {
  1576. np->squeue[i] = cpu_to_scr(np->idletask_ba);
  1577. np->squeue[i+1] = cpu_to_scr(phys + (i+2)*4);
  1578. }
  1579. np->squeue[MAX_QUEUE*2-1] = cpu_to_scr(phys);
  1580. /*
  1581. * Start at first entry.
  1582. */
  1583. np->squeueput = 0;
  1584. /*
  1585. * Clear Done Queue
  1586. */
  1587. phys = np->dqueue_ba;
  1588. for (i = 0; i < MAX_QUEUE*2; i += 2) {
  1589. np->dqueue[i] = 0;
  1590. np->dqueue[i+1] = cpu_to_scr(phys + (i+2)*4);
  1591. }
  1592. np->dqueue[MAX_QUEUE*2-1] = cpu_to_scr(phys);
  1593. /*
  1594. * Start at first entry.
  1595. */
  1596. np->dqueueget = 0;
  1597. /*
  1598. * Install patches in scripts.
  1599. * This also let point to first position the start
  1600. * and done queue pointers used from SCRIPTS.
  1601. */
  1602. np->fw_patch(shost);
  1603. /*
  1604. * Wakeup all pending jobs.
  1605. */
  1606. sym_flush_busy_queue(np, DID_RESET);
  1607. /*
  1608. * Init chip.
  1609. */
  1610. OUTB(np, nc_istat, 0x00); /* Remove Reset, abort */
  1611. INB(np, nc_mbox1);
  1612. udelay(2000); /* The 895 needs time for the bus mode to settle */
  1613. OUTB(np, nc_scntl0, np->rv_scntl0 | 0xc0);
  1614. /* full arb., ena parity, par->ATN */
  1615. OUTB(np, nc_scntl1, 0x00); /* odd parity, and remove CRST!! */
  1616. sym_selectclock(np, np->rv_scntl3); /* Select SCSI clock */
  1617. OUTB(np, nc_scid , RRE|np->myaddr); /* Adapter SCSI address */
  1618. OUTW(np, nc_respid, 1ul<<np->myaddr); /* Id to respond to */
  1619. OUTB(np, nc_istat , SIGP ); /* Signal Process */
  1620. OUTB(np, nc_dmode , np->rv_dmode); /* Burst length, dma mode */
  1621. OUTB(np, nc_ctest5, np->rv_ctest5); /* Large fifo + large burst */
  1622. OUTB(np, nc_dcntl , NOCOM|np->rv_dcntl); /* Protect SFBR */
  1623. OUTB(np, nc_ctest3, np->rv_ctest3); /* Write and invalidate */
  1624. OUTB(np, nc_ctest4, np->rv_ctest4); /* Master parity checking */
  1625. /* Extended Sreq/Sack filtering not supported on the C10 */
  1626. if (np->features & FE_C10)
  1627. OUTB(np, nc_stest2, np->rv_stest2);
  1628. else
  1629. OUTB(np, nc_stest2, EXT|np->rv_stest2);
  1630. OUTB(np, nc_stest3, TE); /* TolerANT enable */
  1631. OUTB(np, nc_stime0, 0x0c); /* HTH disabled STO 0.25 sec */
  1632. /*
  1633. * For now, disable AIP generation on C1010-66.
  1634. */
  1635. if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_66)
  1636. OUTB(np, nc_aipcntl1, DISAIP);
  1637. /*
  1638. * C10101 rev. 0 errata.
  1639. * Errant SGE's when in narrow. Write bits 4 & 5 of
  1640. * STEST1 register to disable SGE. We probably should do
  1641. * that from SCRIPTS for each selection/reselection, but
  1642. * I just don't want. :)
  1643. */
  1644. if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
  1645. pdev->revision < 1)
  1646. OUTB(np, nc_stest1, INB(np, nc_stest1) | 0x30);
  1647. /*
  1648. * DEL 441 - 53C876 Rev 5 - Part Number 609-0392787/2788 - ITEM 2.
  1649. * Disable overlapped arbitration for some dual function devices,
  1650. * regardless revision id (kind of post-chip-design feature. ;-))
  1651. */
  1652. if (pdev->device == PCI_DEVICE_ID_NCR_53C875)
  1653. OUTB(np, nc_ctest0, (1<<5));
  1654. else if (pdev->device == PCI_DEVICE_ID_NCR_53C896)
  1655. np->rv_ccntl0 |= DPR;
  1656. /*
  1657. * Write CCNTL0/CCNTL1 for chips capable of 64 bit addressing
  1658. * and/or hardware phase mismatch, since only such chips
  1659. * seem to support those IO registers.
  1660. */
  1661. if (np->features & (FE_DAC|FE_NOPM)) {
  1662. OUTB(np, nc_ccntl0, np->rv_ccntl0);
  1663. OUTB(np, nc_ccntl1, np->rv_ccntl1);
  1664. }
  1665. #if SYM_CONF_DMA_ADDRESSING_MODE == 2
  1666. /*
  1667. * Set up scratch C and DRS IO registers to map the 32 bit
  1668. * DMA address range our data structures are located in.
  1669. */
  1670. if (use_dac(np)) {
  1671. np->dmap_bah[0] = 0; /* ??? */
  1672. OUTL(np, nc_scrx[0], np->dmap_bah[0]);
  1673. OUTL(np, nc_drs, np->dmap_bah[0]);
  1674. }
  1675. #endif
  1676. /*
  1677. * If phase mismatch handled by scripts (895A/896/1010),
  1678. * set PM jump addresses.
  1679. */
  1680. if (np->features & FE_NOPM) {
  1681. OUTL(np, nc_pmjad1, SCRIPTB_BA(np, pm_handle));
  1682. OUTL(np, nc_pmjad2, SCRIPTB_BA(np, pm_handle));
  1683. }
  1684. /*
  1685. * Enable GPIO0 pin for writing if LED support from SCRIPTS.
  1686. * Also set GPIO5 and clear GPIO6 if hardware LED control.
  1687. */
  1688. if (np->features & FE_LED0)
  1689. OUTB(np, nc_gpcntl, INB(np, nc_gpcntl) & ~0x01);
  1690. else if (np->features & FE_LEDC)
  1691. OUTB(np, nc_gpcntl, (INB(np, nc_gpcntl) & ~0x41) | 0x20);
  1692. /*
  1693. * enable ints
  1694. */
  1695. OUTW(np, nc_sien , STO|HTH|MA|SGE|UDC|RST|PAR);
  1696. OUTB(np, nc_dien , MDPE|BF|SSI|SIR|IID);
  1697. /*
  1698. * For 895/6 enable SBMC interrupt and save current SCSI bus mode.
  1699. * Try to eat the spurious SBMC interrupt that may occur when
  1700. * we reset the chip but not the SCSI BUS (at initialization).
  1701. */
  1702. if (np->features & (FE_ULTRA2|FE_ULTRA3)) {
  1703. OUTONW(np, nc_sien, SBMC);
  1704. if (reason == 0) {
  1705. INB(np, nc_mbox1);
  1706. mdelay(100);
  1707. INW(np, nc_sist);
  1708. }
  1709. np->scsi_mode = INB(np, nc_stest4) & SMODE;
  1710. }
  1711. /*
  1712. * Fill in target structure.
  1713. * Reinitialize usrsync.
  1714. * Reinitialize usrwide.
  1715. * Prepare sync negotiation according to actual SCSI bus mode.
  1716. */
  1717. for (i=0;i<SYM_CONF_MAX_TARGET;i++) {
  1718. struct sym_tcb *tp = &np->target[i];
  1719. tp->to_reset = 0;
  1720. tp->head.sval = 0;
  1721. tp->head.wval = np->rv_scntl3;
  1722. tp->head.uval = 0;
  1723. if (tp->lun0p)
  1724. tp->lun0p->to_clear = 0;
  1725. if (tp->lunmp) {
  1726. int ln;
  1727. for (ln = 1; ln < SYM_CONF_MAX_LUN; ln++)
  1728. if (tp->lunmp[ln])
  1729. tp->lunmp[ln]->to_clear = 0;
  1730. }
  1731. }
  1732. /*
  1733. * Download SCSI SCRIPTS to on-chip RAM if present,
  1734. * and start script processor.
  1735. * We do the download preferently from the CPU.
  1736. * For platforms that may not support PCI memory mapping,
  1737. * we use simple SCRIPTS that performs MEMORY MOVEs.
  1738. */
  1739. phys = SCRIPTA_BA(np, init);
  1740. if (np->ram_ba) {
  1741. if (sym_verbose >= 2)
  1742. printf("%s: Downloading SCSI SCRIPTS.\n", sym_name(np));
  1743. memcpy_toio(np->s.ramaddr, np->scripta0, np->s