sun3_scsi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /*
  2. * Sun3 SCSI stuff by Erik Verbruggen (erik@bigmama.xtdnet.nl)
  3. *
  4. * Sun3 DMA routines added by Sam Creasey (sammy@sammy.net)
  5. *
  6. * VME support added by Sam Creasey
  7. *
  8. * TODO: modify this driver to support multiple Sun3 SCSI VME boards
  9. *
  10. * Adapted from mac_scsinew.c:
  11. */
  12. /*
  13. * Generic Macintosh NCR5380 driver
  14. *
  15. * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov>
  16. *
  17. * derived in part from:
  18. */
  19. /*
  20. * Generic Generic NCR5380 driver
  21. *
  22. * Copyright 1995, Russell King
  23. *
  24. * ALPHA RELEASE 1.
  25. *
  26. * For more information, please consult
  27. *
  28. * NCR 5380 Family
  29. * SCSI Protocol Controller
  30. * Databook
  31. *
  32. * NCR Microelectronics
  33. * 1635 Aeroplaza Drive
  34. * Colorado Springs, CO 80916
  35. * 1+ (719) 578-3400
  36. * 1+ (800) 334-5454
  37. */
  38. /*
  39. * This is from mac_scsi.h, but hey, maybe this is useful for Sun3 too! :)
  40. *
  41. * Options :
  42. *
  43. * PARITY - enable parity checking. Not supported.
  44. *
  45. * SCSI2 - enable support for SCSI-II tagged queueing. Untested.
  46. *
  47. * USLEEP - enable support for devices that don't disconnect. Untested.
  48. */
  49. #define AUTOSENSE
  50. #include <linux/types.h>
  51. #include <linux/stddef.h>
  52. #include <linux/ctype.h>
  53. #include <linux/delay.h>
  54. #include <linux/module.h>
  55. #include <linux/signal.h>
  56. #include <linux/ioport.h>
  57. #include <linux/init.h>
  58. #include <linux/blkdev.h>
  59. #include <asm/io.h>
  60. #include <asm/sun3ints.h>
  61. #include <asm/dvma.h>
  62. #include <asm/idprom.h>
  63. #include <asm/machines.h>
  64. /* dma on! */
  65. #define REAL_DMA
  66. #include "scsi.h"
  67. #include <scsi/scsi_host.h>
  68. #include "sun3_scsi.h"
  69. #include "NCR5380.h"
  70. extern int sun3_map_test(unsigned long, char *);
  71. #define USE_WRAPPER
  72. /*#define RESET_BOOT */
  73. #define DRIVER_SETUP
  74. /*
  75. * BUG can be used to trigger a strange code-size related hang on 2.1 kernels
  76. */
  77. #ifdef BUG
  78. #undef RESET_BOOT
  79. #undef DRIVER_SETUP
  80. #endif
  81. /* #define SUPPORT_TAGS */
  82. #ifdef SUN3_SCSI_VME
  83. #define ENABLE_IRQ()
  84. #else
  85. #define ENABLE_IRQ() enable_irq( IRQ_SUN3_SCSI );
  86. #endif
  87. static irqreturn_t scsi_sun3_intr(int irq, void *dummy);
  88. static inline unsigned char sun3scsi_read(int reg);
  89. static inline void sun3scsi_write(int reg, int value);
  90. static int setup_can_queue = -1;
  91. module_param(setup_can_queue, int, 0);
  92. static int setup_cmd_per_lun = -1;
  93. module_param(setup_cmd_per_lun, int, 0);
  94. static int setup_sg_tablesize = -1;
  95. module_param(setup_sg_tablesize, int, 0);
  96. #ifdef SUPPORT_TAGS
  97. static int setup_use_tagged_queuing = -1;
  98. module_param(setup_use_tagged_queuing, int, 0);
  99. #endif
  100. static int setup_hostid = -1;
  101. module_param(setup_hostid, int, 0);
  102. static struct scsi_cmnd *sun3_dma_setup_done = NULL;
  103. #define RESET_RUN_DONE
  104. #define AFTER_RESET_DELAY (HZ/2)
  105. /* ms to wait after hitting dma regs */
  106. #define SUN3_DMA_DELAY 10
  107. /* dvma buffer to allocate -- 32k should hopefully be more than sufficient */
  108. #define SUN3_DVMA_BUFSIZE 0xe000
  109. /* minimum number of bytes to do dma on */
  110. #define SUN3_DMA_MINSIZE 128
  111. static volatile unsigned char *sun3_scsi_regp;
  112. static volatile struct sun3_dma_regs *dregs;
  113. #ifndef SUN3_SCSI_VME
  114. static struct sun3_udc_regs *udc_regs = NULL;
  115. #endif
  116. static unsigned char *sun3_dma_orig_addr = NULL;
  117. static unsigned long sun3_dma_orig_count = 0;
  118. static int sun3_dma_active = 0;
  119. static unsigned long last_residual = 0;
  120. /*
  121. * NCR 5380 register access functions
  122. */
  123. static inline unsigned char sun3scsi_read(int reg)
  124. {
  125. return( sun3_scsi_regp[reg] );
  126. }
  127. static inline void sun3scsi_write(int reg, int value)
  128. {
  129. sun3_scsi_regp[reg] = value;
  130. }
  131. #ifndef SUN3_SCSI_VME
  132. /* dma controller register access functions */
  133. static inline unsigned short sun3_udc_read(unsigned char reg)
  134. {
  135. unsigned short ret;
  136. dregs->udc_addr = UDC_CSR;
  137. udelay(SUN3_DMA_DELAY);
  138. ret = dregs->udc_data;
  139. udelay(SUN3_DMA_DELAY);
  140. return ret;
  141. }
  142. static inline void sun3_udc_write(unsigned short val, unsigned char reg)
  143. {
  144. dregs->udc_addr = reg;
  145. udelay(SUN3_DMA_DELAY);
  146. dregs->udc_data = val;
  147. udelay(SUN3_DMA_DELAY);
  148. }
  149. #endif
  150. /*
  151. * XXX: status debug
  152. */
  153. static struct Scsi_Host *default_instance;
  154. /*
  155. * Function : int sun3scsi_detect(struct scsi_host_template * tpnt)
  156. *
  157. * Purpose : initializes mac NCR5380 driver based on the
  158. * command line / compile time port and irq definitions.
  159. *
  160. * Inputs : tpnt - template for this SCSI adapter.
  161. *
  162. * Returns : 1 if a host adapter was found, 0 if not.
  163. *
  164. */
  165. static int __init sun3scsi_detect(struct scsi_host_template *tpnt)
  166. {
  167. unsigned long ioaddr, irq;
  168. static int called = 0;
  169. struct Scsi_Host *instance;
  170. #ifdef SUN3_SCSI_VME
  171. int i;
  172. unsigned long addrs[3] = { IOBASE_SUN3_VMESCSI,
  173. IOBASE_SUN3_VMESCSI + 0x4000,
  174. 0 };
  175. unsigned long vecs[3] = { SUN3_VEC_VMESCSI0,
  176. SUN3_VEC_VMESCSI1,
  177. 0 };
  178. #endif
  179. /* check that this machine has an onboard 5380 */
  180. switch(idprom->id_machtype) {
  181. #ifdef SUN3_SCSI_VME
  182. case SM_SUN3|SM_3_160:
  183. case SM_SUN3|SM_3_260:
  184. break;
  185. #else
  186. case SM_SUN3|SM_3_50:
  187. case SM_SUN3|SM_3_60:
  188. break;
  189. #endif
  190. default:
  191. return 0;
  192. }
  193. if(called)
  194. return 0;
  195. #ifdef SUN3_SCSI_VME
  196. tpnt->proc_name = "Sun3 5380 VME SCSI";
  197. #else
  198. tpnt->proc_name = "Sun3 5380 SCSI";
  199. #endif
  200. /* setup variables */
  201. tpnt->can_queue =
  202. (setup_can_queue > 0) ? setup_can_queue : CAN_QUEUE;
  203. tpnt->cmd_per_lun =
  204. (setup_cmd_per_lun > 0) ? setup_cmd_per_lun : CMD_PER_LUN;
  205. tpnt->sg_tablesize =
  206. (setup_sg_tablesize >= 0) ? setup_sg_tablesize : SG_TABLESIZE;
  207. if (setup_hostid >= 0)
  208. tpnt->this_id = setup_hostid;
  209. else {
  210. /* use 7 as default */
  211. tpnt->this_id = 7;
  212. }
  213. #ifdef SUN3_SCSI_VME
  214. ioaddr = 0;
  215. for (i = 0; addrs[i] != 0; i++) {
  216. unsigned char x;
  217. ioaddr = (unsigned long)sun3_ioremap(addrs[i], PAGE_SIZE,
  218. SUN3_PAGE_TYPE_VME16);
  219. irq = vecs[i];
  220. sun3_scsi_regp = (unsigned char *)ioaddr;
  221. dregs = (struct sun3_dma_regs *)(((unsigned char *)ioaddr) + 8);
  222. if (sun3_map_test((unsigned long)dregs, &x)) {
  223. unsigned short oldcsr;
  224. oldcsr = dregs->csr;
  225. dregs->csr = 0;
  226. udelay(SUN3_DMA_DELAY);
  227. if (dregs->csr == 0x1400)
  228. break;
  229. dregs->csr = oldcsr;
  230. }
  231. iounmap((void *)ioaddr);
  232. ioaddr = 0;
  233. }
  234. if (!ioaddr)
  235. return 0;
  236. #else
  237. irq = IRQ_SUN3_SCSI;
  238. ioaddr = (unsigned long)ioremap(IOBASE_SUN3_SCSI, PAGE_SIZE);
  239. sun3_scsi_regp = (unsigned char *)ioaddr;
  240. dregs = (struct sun3_dma_regs *)(((unsigned char *)ioaddr) + 8);
  241. if((udc_regs = dvma_malloc(sizeof(struct sun3_udc_regs)))
  242. == NULL) {
  243. printk("SUN3 Scsi couldn't allocate DVMA memory!\n");
  244. return 0;
  245. }
  246. #endif
  247. #ifdef SUPPORT_TAGS
  248. if (setup_use_tagged_queuing < 0)
  249. setup_use_tagged_queuing = USE_TAGGED_QUEUING;
  250. #endif
  251. instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
  252. if(instance == NULL)
  253. return 0;
  254. default_instance = instance;
  255. instance->io_port = (unsigned long) ioaddr;
  256. instance->irq = irq;
  257. NCR5380_init(instance, 0);
  258. instance->n_io_port = 32;
  259. ((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0;
  260. if (request_irq(instance->irq, scsi_sun3_intr,
  261. 0, "Sun3SCSI-5380", instance)) {
  262. #ifndef REAL_DMA
  263. printk("scsi%d: IRQ%d not free, interrupts disabled\n",
  264. instance->host_no, instance->irq);
  265. instance->irq = SCSI_IRQ_NONE;
  266. #else
  267. printk("scsi%d: IRQ%d not free, bailing out\n",
  268. instance->host_no, instance->irq);
  269. return 0;
  270. #endif
  271. }
  272. pr_info("scsi%d: %s at port %lX irq", instance->host_no,
  273. tpnt->proc_name, instance->io_port);
  274. if (instance->irq == SCSI_IRQ_NONE)
  275. printk ("s disabled");
  276. else
  277. printk (" %d", instance->irq);
  278. printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
  279. instance->can_queue, instance->cmd_per_lun,
  280. SUN3SCSI_PUBLIC_RELEASE);
  281. printk("\nscsi%d:", instance->host_no);
  282. NCR5380_print_options(instance);
  283. printk("\n");
  284. dregs->csr = 0;
  285. udelay(SUN3_DMA_DELAY);
  286. dregs->csr = CSR_SCSI | CSR_FIFO | CSR_INTR;
  287. udelay(SUN3_DMA_DELAY);
  288. dregs->fifo_count = 0;
  289. #ifdef SUN3_SCSI_VME
  290. dregs->fifo_count_hi = 0;
  291. dregs->dma_addr_hi = 0;
  292. dregs->dma_addr_lo = 0;
  293. dregs->dma_count_hi = 0;
  294. dregs->dma_count_lo = 0;
  295. dregs->ivect = VME_DATA24 | (instance->irq & 0xff);
  296. #endif
  297. called = 1;
  298. #ifdef RESET_BOOT
  299. sun3_scsi_reset_boot(instance);
  300. #endif
  301. return 1;
  302. }
  303. int sun3scsi_release (struct Scsi_Host *shpnt)
  304. {
  305. if (shpnt->irq != SCSI_IRQ_NONE)
  306. free_irq(shpnt->irq, shpnt);
  307. iounmap((void *)sun3_scsi_regp);
  308. NCR5380_exit(shpnt);
  309. return 0;
  310. }
  311. #ifdef RESET_BOOT
  312. /*
  313. * Our 'bus reset on boot' function
  314. */
  315. static void sun3_scsi_reset_boot(struct Scsi_Host *instance)
  316. {
  317. unsigned long end;
  318. NCR5380_local_declare();
  319. NCR5380_setup(instance);
  320. /*
  321. * Do a SCSI reset to clean up the bus during initialization. No
  322. * messing with the queues, interrupts, or locks necessary here.
  323. */
  324. printk( "Sun3 SCSI: resetting the SCSI bus..." );
  325. /* switch off SCSI IRQ - catch an interrupt without IRQ bit set else */
  326. // sun3_disable_irq( IRQ_SUN3_SCSI );
  327. /* get in phase */
  328. NCR5380_write( TARGET_COMMAND_REG,
  329. PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
  330. /* assert RST */
  331. NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
  332. /* The min. reset hold time is 25us, so 40us should be enough */
  333. udelay( 50 );
  334. /* reset RST and interrupt */
  335. NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
  336. NCR5380_read( RESET_PARITY_INTERRUPT_REG );
  337. for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); )
  338. barrier();
  339. /* switch on SCSI IRQ again */
  340. // sun3_enable_irq( IRQ_SUN3_SCSI );
  341. printk( " done\n" );
  342. }
  343. #endif
  344. static const char *sun3scsi_info(struct Scsi_Host *spnt)
  345. {
  346. return "";
  347. }
  348. // safe bits for the CSR
  349. #define CSR_GOOD 0x060f
  350. static irqreturn_t scsi_sun3_intr(int irq, void *dummy)
  351. {
  352. unsigned short csr = dregs->csr;
  353. int handled = 0;
  354. #ifdef SUN3_SCSI_VME
  355. dregs->csr &= ~CSR_DMA_ENABLE;
  356. #endif
  357. if(csr & ~CSR_GOOD) {
  358. if(csr & CSR_DMA_BUSERR) {
  359. printk("scsi%d: bus error in dma\n", default_instance->host_no);
  360. }
  361. if(csr & CSR_DMA_CONFLICT) {
  362. printk("scsi%d: dma conflict\n", default_instance->host_no);
  363. }
  364. handled = 1;
  365. }
  366. if(csr & (CSR_SDB_INT | CSR_DMA_INT)) {
  367. NCR5380_intr(irq, dummy);
  368. handled = 1;
  369. }
  370. return IRQ_RETVAL(handled);
  371. }
  372. /*
  373. * Debug stuff - to be called on NMI, or sysrq key. Use at your own risk;
  374. * reentering NCR5380_print_status seems to have ugly side effects
  375. */
  376. /* this doesn't seem to get used at all -- sam */
  377. #if 0
  378. void sun3_sun3_debug (void)
  379. {
  380. unsigned long flags;
  381. NCR5380_local_declare();
  382. if (default_instance) {
  383. local_irq_save(flags);
  384. NCR5380_print_status(default_instance);
  385. local_irq_restore(flags);
  386. }
  387. }
  388. #endif
  389. /* sun3scsi_dma_setup() -- initialize the dma controller for a read/write */
  390. static unsigned long sun3scsi_dma_setup(void *data, unsigned long count, int write_flag)
  391. {
  392. void *addr;
  393. if(sun3_dma_orig_addr != NULL)
  394. dvma_unmap(sun3_dma_orig_addr);
  395. #ifdef SUN3_SCSI_VME
  396. addr = (void *)dvma_map_vme((unsigned long) data, count);
  397. #else
  398. addr = (void *)dvma_map((unsigned long) data, count);
  399. #endif
  400. sun3_dma_orig_addr = addr;
  401. sun3_dma_orig_count = count;
  402. #ifndef SUN3_SCSI_VME
  403. dregs->fifo_count = 0;
  404. sun3_udc_write(UDC_RESET, UDC_CSR);
  405. /* reset fifo */
  406. dregs->csr &= ~CSR_FIFO;
  407. dregs->csr |= CSR_FIFO;
  408. #endif
  409. /* set direction */
  410. if(write_flag)
  411. dregs->csr |= CSR_SEND;
  412. else
  413. dregs->csr &= ~CSR_SEND;
  414. #ifdef SUN3_SCSI_VME
  415. dregs->csr |= CSR_PACK_ENABLE;
  416. dregs->dma_addr_hi = ((unsigned long)addr >> 16);
  417. dregs->dma_addr_lo = ((unsigned long)addr & 0xffff);
  418. dregs->dma_count_hi = 0;
  419. dregs->dma_count_lo = 0;
  420. dregs->fifo_count_hi = 0;
  421. dregs->fifo_count = 0;
  422. #else
  423. /* byte count for fifo */
  424. dregs->fifo_count = count;
  425. sun3_udc_write(UDC_RESET, UDC_CSR);
  426. /* reset fifo */
  427. dregs->csr &= ~CSR_FIFO;
  428. dregs->csr |= CSR_FIFO;
  429. if(dregs->fifo_count != count) {
  430. printk("scsi%d: fifo_mismatch %04x not %04x\n",
  431. default_instance->host_no, dregs->fifo_count,
  432. (unsigned int) count);
  433. NCR5380_dprint(NDEBUG_DMA, default_instance);
  434. }
  435. /* setup udc */
  436. udc_regs->addr_hi = (((unsigned long)(addr) & 0xff0000) >> 8);
  437. udc_regs->addr_lo = ((unsigned long)(addr) & 0xffff);
  438. udc_regs->count = count/2; /* count in words */
  439. udc_regs->mode_hi = UDC_MODE_HIWORD;
  440. if(write_flag) {
  441. if(count & 1)
  442. udc_regs->count++;
  443. udc_regs->mode_lo = UDC_MODE_LSEND;
  444. udc_regs->rsel = UDC_RSEL_SEND;
  445. } else {
  446. udc_regs->mode_lo = UDC_MODE_LRECV;
  447. udc_regs->rsel = UDC_RSEL_RECV;
  448. }
  449. /* announce location of regs block */
  450. sun3_udc_write(((dvma_vtob(udc_regs) & 0xff0000) >> 8),
  451. UDC_CHN_HI);
  452. sun3_udc_write((dvma_vtob(udc_regs) & 0xffff), UDC_CHN_LO);
  453. /* set dma master on */
  454. sun3_udc_write(0xd, UDC_MODE);
  455. /* interrupt enable */
  456. sun3_udc_write(UDC_INT_ENABLE, UDC_CSR);
  457. #endif
  458. return count;
  459. }
  460. #ifndef SUN3_SCSI_VME
  461. static inline unsigned long sun3scsi_dma_count(struct Scsi_Host *instance)
  462. {
  463. unsigned short resid;
  464. dregs->udc_addr = 0x32;
  465. udelay(SUN3_DMA_DELAY);
  466. resid = dregs->udc_data;
  467. udelay(SUN3_DMA_DELAY);
  468. resid *= 2;
  469. return (unsigned long) resid;
  470. }
  471. #endif
  472. static inline unsigned long sun3scsi_dma_residual(struct Scsi_Host *instance)
  473. {
  474. return last_residual;
  475. }
  476. static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted,
  477. struct scsi_cmnd *cmd,
  478. int write_flag)
  479. {
  480. if (cmd->request->cmd_type == REQ_TYPE_FS)
  481. return wanted;
  482. else
  483. return 0;
  484. }
  485. static inline int sun3scsi_dma_start(unsigned long count, unsigned char *data)
  486. {
  487. #ifdef SUN3_SCSI_VME
  488. unsigned short csr;
  489. csr = dregs->csr;
  490. dregs->dma_count_hi = (sun3_dma_orig_count >> 16);
  491. dregs->dma_count_lo = (sun3_dma_orig_count & 0xffff);
  492. dregs->fifo_count_hi = (sun3_dma_orig_count >> 16);
  493. dregs->fifo_count = (sun3_dma_orig_count & 0xffff);
  494. /* if(!(csr & CSR_DMA_ENABLE))
  495. * dregs->csr |= CSR_DMA_ENABLE;
  496. */
  497. #else
  498. sun3_udc_write(UDC_CHN_START, UDC_CSR);
  499. #endif
  500. return 0;
  501. }
  502. /* clean up after our dma is done */
  503. static int sun3scsi_dma_finish(int write_flag)
  504. {
  505. unsigned short __maybe_unused count;
  506. unsigned short fifo;
  507. int ret = 0;
  508. sun3_dma_active = 0;
  509. #ifdef SUN3_SCSI_VME
  510. dregs->csr &= ~CSR_DMA_ENABLE;
  511. fifo = dregs->fifo_count;
  512. if (write_flag) {
  513. if ((fifo > 0) && (fifo < sun3_dma_orig_count))
  514. fifo++;
  515. }
  516. last_residual = fifo;
  517. /* empty bytes from the fifo which didn't make it */
  518. if ((!write_flag) && (dregs->csr & CSR_LEFT)) {
  519. unsigned char *vaddr;
  520. vaddr = (unsigned char *)dvma_vmetov(sun3_dma_orig_addr);
  521. vaddr += (sun3_dma_orig_count - fifo);
  522. vaddr--;
  523. switch (dregs->csr & CSR_LEFT) {
  524. case CSR_LEFT_3:
  525. *vaddr = (dregs->bpack_lo & 0xff00) >> 8;
  526. vaddr--;
  527. case CSR_LEFT_2:
  528. *vaddr = (dregs->bpack_hi & 0x00ff);
  529. vaddr--;
  530. case CSR_LEFT_1:
  531. *vaddr = (dregs->bpack_hi & 0xff00) >> 8;
  532. break;
  533. }
  534. }
  535. #else
  536. // check to empty the fifo on a read
  537. if(!write_flag) {
  538. int tmo = 20000; /* .2 sec */
  539. while(1) {
  540. if(dregs->csr & CSR_FIFO_EMPTY)
  541. break;
  542. if(--tmo <= 0) {
  543. printk("sun3scsi: fifo failed to empty!\n");
  544. return 1;
  545. }
  546. udelay(10);
  547. }
  548. }
  549. count = sun3scsi_dma_count(default_instance);
  550. fifo = dregs->fifo_count;
  551. last_residual = fifo;
  552. /* empty bytes from the fifo which didn't make it */
  553. if((!write_flag) && (count - fifo) == 2) {
  554. unsigned short data;
  555. unsigned char *vaddr;
  556. data = dregs->fifo_data;
  557. vaddr = (unsigned char *)dvma_btov(sun3_dma_orig_addr);
  558. vaddr += (sun3_dma_orig_count - fifo);
  559. vaddr[-2] = (data & 0xff00) >> 8;
  560. vaddr[-1] = (data & 0xff);
  561. }
  562. #endif
  563. dvma_unmap(sun3_dma_orig_addr);
  564. sun3_dma_orig_addr = NULL;
  565. #ifdef SUN3_SCSI_VME
  566. dregs->dma_addr_hi = 0;
  567. dregs->dma_addr_lo = 0;
  568. dregs->dma_count_hi = 0;
  569. dregs->dma_count_lo = 0;
  570. dregs->fifo_count = 0;
  571. dregs->fifo_count_hi = 0;
  572. dregs->csr &= ~CSR_SEND;
  573. /* dregs->csr |= CSR_DMA_ENABLE; */
  574. #else
  575. sun3_udc_write(UDC_RESET, UDC_CSR);
  576. dregs->fifo_count = 0;
  577. dregs->csr &= ~CSR_SEND;
  578. /* reset fifo */
  579. dregs->csr &= ~CSR_FIFO;
  580. dregs->csr |= CSR_FIFO;
  581. #endif
  582. sun3_dma_setup_done = NULL;
  583. return ret;
  584. }
  585. #include "sun3_NCR5380.c"
  586. static struct scsi_host_template driver_template = {
  587. .show_info = sun3scsi_show_info,
  588. .name = SUN3_SCSI_NAME,
  589. .detect = sun3scsi_detect,
  590. .release = sun3scsi_release,
  591. .info = sun3scsi_info,
  592. .queuecommand = sun3scsi_queue_command,
  593. .eh_abort_handler = sun3scsi_abort,
  594. .eh_bus_reset_handler = sun3scsi_bus_reset,
  595. .can_queue = CAN_QUEUE,
  596. .this_id = 7,
  597. .sg_tablesize = SG_TABLESIZE,
  598. .cmd_per_lun = CMD_PER_LUN,
  599. .use_clustering = DISABLE_CLUSTERING
  600. };
  601. #include "scsi_module.c"
  602. MODULE_LICENSE("GPL");