blz2060.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* blz2060.c: Driver for Blizzard 2060 SCSI Controller.
  2. *
  3. * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
  4. *
  5. * This driver is based on the CyberStorm driver, hence the occasional
  6. * reference to CyberStorm.
  7. */
  8. /* TODO:
  9. *
  10. * 1) Figure out how to make a cleaner merge with the sparc driver with regard
  11. * to the caches and the Sparc MMU mapping.
  12. * 2) Make as few routines required outside the generic driver. A lot of the
  13. * routines in this file used to be inline!
  14. */
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/delay.h>
  19. #include <linux/types.h>
  20. #include <linux/string.h>
  21. #include <linux/slab.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/proc_fs.h>
  24. #include <linux/stat.h>
  25. #include <linux/interrupt.h>
  26. #include "scsi.h"
  27. #include <scsi/scsi_host.h>
  28. #include "NCR53C9x.h"
  29. #include <linux/zorro.h>
  30. #include <asm/irq.h>
  31. #include <asm/amigaints.h>
  32. #include <asm/amigahw.h>
  33. #include <asm/pgtable.h>
  34. /* The controller registers can be found in the Z2 config area at these
  35. * offsets:
  36. */
  37. #define BLZ2060_ESP_ADDR 0x1ff00
  38. #define BLZ2060_DMA_ADDR 0x1ffe0
  39. /* The Blizzard 2060 DMA interface
  40. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. * Only two things can be programmed in the Blizzard DMA:
  42. * 1) The data direction is controlled by the status of bit 31 (1 = write)
  43. * 2) The source/dest address (word aligned, shifted one right) in bits 30-0
  44. *
  45. * Figure out interrupt status by reading the ESP status byte.
  46. */
  47. struct blz2060_dma_registers {
  48. volatile unsigned char dma_led_ctrl; /* DMA led control [0x000] */
  49. unsigned char dmapad1[0x0f];
  50. volatile unsigned char dma_addr0; /* DMA address (MSB) [0x010] */
  51. unsigned char dmapad2[0x03];
  52. volatile unsigned char dma_addr1; /* DMA address [0x014] */
  53. unsigned char dmapad3[0x03];
  54. volatile unsigned char dma_addr2; /* DMA address [0x018] */
  55. unsigned char dmapad4[0x03];
  56. volatile unsigned char dma_addr3; /* DMA address (LSB) [0x01c] */
  57. };
  58. #define BLZ2060_DMA_WRITE 0x80000000
  59. /* DMA control bits */
  60. #define BLZ2060_DMA_LED 0x02 /* HD led control 1 = off */
  61. static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
  62. static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
  63. static void dma_dump_state(struct NCR_ESP *esp);
  64. static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
  65. static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
  66. static void dma_ints_off(struct NCR_ESP *esp);
  67. static void dma_ints_on(struct NCR_ESP *esp);
  68. static int dma_irq_p(struct NCR_ESP *esp);
  69. static void dma_led_off(struct NCR_ESP *esp);
  70. static void dma_led_on(struct NCR_ESP *esp);
  71. static int dma_ports_p(struct NCR_ESP *esp);
  72. static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
  73. static volatile unsigned char cmd_buffer[16];
  74. /* This is where all commands are put
  75. * before they are transferred to the ESP chip
  76. * via PIO.
  77. */
  78. /***************************************************************** Detection */
  79. int __init blz2060_esp_detect(struct scsi_host_template *tpnt)
  80. {
  81. struct NCR_ESP *esp;
  82. struct zorro_dev *z = NULL;
  83. unsigned long address;
  84. if ((z = zorro_find_device(ZORRO_PROD_PHASE5_BLIZZARD_2060, z))) {
  85. unsigned long board = z->resource.start;
  86. if (request_mem_region(board+BLZ2060_ESP_ADDR,
  87. sizeof(struct ESP_regs), "NCR53C9x")) {
  88. esp = esp_allocate(tpnt, (void *)board+BLZ2060_ESP_ADDR);
  89. /* Do command transfer with programmed I/O */
  90. esp->do_pio_cmds = 1;
  91. /* Required functions */
  92. esp->dma_bytes_sent = &dma_bytes_sent;
  93. esp->dma_can_transfer = &dma_can_transfer;
  94. esp->dma_dump_state = &dma_dump_state;
  95. esp->dma_init_read = &dma_init_read;
  96. esp->dma_init_write = &dma_init_write;
  97. esp->dma_ints_off = &dma_ints_off;
  98. esp->dma_ints_on = &dma_ints_on;
  99. esp->dma_irq_p = &dma_irq_p;
  100. esp->dma_ports_p = &dma_ports_p;
  101. esp->dma_setup = &dma_setup;
  102. /* Optional functions */
  103. esp->dma_barrier = 0;
  104. esp->dma_drain = 0;
  105. esp->dma_invalidate = 0;
  106. esp->dma_irq_entry = 0;
  107. esp->dma_irq_exit = 0;
  108. esp->dma_led_on = &dma_led_on;
  109. esp->dma_led_off = &dma_led_off;
  110. esp->dma_poll = 0;
  111. esp->dma_reset = 0;
  112. /* SCSI chip speed */
  113. esp->cfreq = 40000000;
  114. /* The DMA registers on the Blizzard are mapped
  115. * relative to the device (i.e. in the same Zorro
  116. * I/O block).
  117. */
  118. address = (unsigned long)ZTWO_VADDR(board);
  119. esp->dregs = (void *)(address + BLZ2060_DMA_ADDR);
  120. /* ESP register base */
  121. esp->eregs = (struct ESP_regs *)(address + BLZ2060_ESP_ADDR);
  122. /* Set the command buffer */
  123. esp->esp_command = cmd_buffer;
  124. esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
  125. esp->irq = IRQ_AMIGA_PORTS;
  126. request_irq(IRQ_AMIGA_PORTS, esp_intr, SA_SHIRQ,
  127. "Blizzard 2060 SCSI", esp->ehost);
  128. /* Figure out our scsi ID on the bus */
  129. esp->scsi_id = 7;
  130. /* We don't have a differential SCSI-bus. */
  131. esp->diff = 0;
  132. esp_initialize(esp);
  133. printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
  134. esps_running = esps_in_use;
  135. return esps_in_use;
  136. }
  137. }
  138. return 0;
  139. }
  140. /************************************************************* DMA Functions */
  141. static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
  142. {
  143. /* Since the Blizzard DMA is fully dedicated to the ESP chip,
  144. * the number of bytes sent (to the ESP chip) equals the number
  145. * of bytes in the FIFO - there is no buffering in the DMA controller.
  146. * XXXX Do I read this right? It is from host to ESP, right?
  147. */
  148. return fifo_count;
  149. }
  150. static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
  151. {
  152. /* I don't think there's any limit on the Blizzard DMA. So we use what
  153. * the ESP chip can handle (24 bit).
  154. */
  155. unsigned long sz = sp->SCp.this_residual;
  156. if(sz > 0x1000000)
  157. sz = 0x1000000;
  158. return sz;
  159. }
  160. static void dma_dump_state(struct NCR_ESP *esp)
  161. {
  162. ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
  163. amiga_custom.intreqr, amiga_custom.intenar));
  164. }
  165. static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
  166. {
  167. struct blz2060_dma_registers *dregs =
  168. (struct blz2060_dma_registers *) (esp->dregs);
  169. cache_clear(addr, length);
  170. addr >>= 1;
  171. addr &= ~(BLZ2060_DMA_WRITE);
  172. dregs->dma_addr3 = (addr ) & 0xff;
  173. dregs->dma_addr2 = (addr >> 8) & 0xff;
  174. dregs->dma_addr1 = (addr >> 16) & 0xff;
  175. dregs->dma_addr0 = (addr >> 24) & 0xff;
  176. }
  177. static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
  178. {
  179. struct blz2060_dma_registers *dregs =
  180. (struct blz2060_dma_registers *) (esp->dregs);
  181. cache_push(addr, length);
  182. addr >>= 1;
  183. addr |= BLZ2060_DMA_WRITE;
  184. dregs->dma_addr3 = (addr ) & 0xff;
  185. dregs->dma_addr2 = (addr >> 8) & 0xff;
  186. dregs->dma_addr1 = (addr >> 16) & 0xff;
  187. dregs->dma_addr0 = (addr >> 24) & 0xff;
  188. }
  189. static void dma_ints_off(struct NCR_ESP *esp)
  190. {
  191. disable_irq(esp->irq);
  192. }
  193. static void dma_ints_on(struct NCR_ESP *esp)
  194. {
  195. enable_irq(esp->irq);
  196. }
  197. static int dma_irq_p(struct NCR_ESP *esp)
  198. {
  199. return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
  200. }
  201. static void dma_led_off(struct NCR_ESP *esp)
  202. {
  203. ((struct blz2060_dma_registers *) (esp->dregs))->dma_led_ctrl =
  204. BLZ2060_DMA_LED;
  205. }
  206. static void dma_led_on(struct NCR_ESP *esp)
  207. {
  208. ((struct blz2060_dma_registers *) (esp->dregs))->dma_led_ctrl = 0;
  209. }
  210. static int dma_ports_p(struct NCR_ESP *esp)
  211. {
  212. return ((amiga_custom.intenar) & IF_PORTS);
  213. }
  214. static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
  215. {
  216. /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
  217. * so when (write) is true, it actually means READ!
  218. */
  219. if(write){
  220. dma_init_read(esp, addr, count);
  221. } else {
  222. dma_init_write(esp, addr, count);
  223. }
  224. }
  225. #define HOSTS_C
  226. int blz2060_esp_release(struct Scsi_Host *instance)
  227. {
  228. #ifdef MODULE
  229. unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
  230. esp_deallocate((struct NCR_ESP *)instance->hostdata);
  231. esp_release();
  232. release_mem_region(address, sizeof(struct ESP_regs));
  233. free_irq(IRQ_AMIGA_PORTS, esp_intr);
  234. #endif
  235. return 1;
  236. }
  237. static struct scsi_host_template driver_template = {
  238. .proc_name = "esp-blz2060",
  239. .proc_info = esp_proc_info,
  240. .name = "Blizzard2060 SCSI",
  241. .detect = blz2060_esp_detect,
  242. .slave_alloc = esp_slave_alloc,
  243. .slave_destroy = esp_slave_destroy,
  244. .release = blz2060_esp_release,
  245. .queuecommand = esp_queue,
  246. .eh_abort_handler = esp_abort,
  247. .eh_bus_reset_handler = esp_reset,
  248. .can_queue = 7,
  249. .this_id = 7,
  250. .sg_tablesize = SG_ALL,
  251. .cmd_per_lun = 1,
  252. .use_clustering = ENABLE_CLUSTERING
  253. };
  254. #include "scsi_module.c"
  255. MODULE_LICENSE("GPL");