blz1230.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /* blz1230.c: Driver for Blizzard 1230 SCSI IV 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. #define MKIV 1
  35. /* The controller registers can be found in the Z2 config area at these
  36. * offsets:
  37. */
  38. #define BLZ1230_ESP_ADDR 0x8000
  39. #define BLZ1230_DMA_ADDR 0x10000
  40. #define BLZ1230II_ESP_ADDR 0x10000
  41. #define BLZ1230II_DMA_ADDR 0x10021
  42. /* The Blizzard 1230 DMA interface
  43. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. * Only two things can be programmed in the Blizzard DMA:
  45. * 1) The data direction is controlled by the status of bit 31 (1 = write)
  46. * 2) The source/dest address (word aligned, shifted one right) in bits 30-0
  47. *
  48. * Program DMA by first latching the highest byte of the address/direction
  49. * (i.e. bits 31-24 of the long word constructed as described in steps 1+2
  50. * above). Then write each byte of the address/direction (starting with the
  51. * top byte, working down) to the DMA address register.
  52. *
  53. * Figure out interrupt status by reading the ESP status byte.
  54. */
  55. struct blz1230_dma_registers {
  56. volatile unsigned char dma_addr; /* DMA address [0x0000] */
  57. unsigned char dmapad2[0x7fff];
  58. volatile unsigned char dma_latch; /* DMA latch [0x8000] */
  59. };
  60. struct blz1230II_dma_registers {
  61. volatile unsigned char dma_addr; /* DMA address [0x0000] */
  62. unsigned char dmapad2[0xf];
  63. volatile unsigned char dma_latch; /* DMA latch [0x0010] */
  64. };
  65. #define BLZ1230_DMA_WRITE 0x80000000
  66. static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
  67. static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
  68. static void dma_dump_state(struct NCR_ESP *esp);
  69. static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
  70. static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
  71. static void dma_ints_off(struct NCR_ESP *esp);
  72. static void dma_ints_on(struct NCR_ESP *esp);
  73. static int dma_irq_p(struct NCR_ESP *esp);
  74. static int dma_ports_p(struct NCR_ESP *esp);
  75. static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
  76. static volatile unsigned char cmd_buffer[16];
  77. /* This is where all commands are put
  78. * before they are transferred to the ESP chip
  79. * via PIO.
  80. */
  81. /***************************************************************** Detection */
  82. int __init blz1230_esp_detect(struct scsi_host_template *tpnt)
  83. {
  84. struct NCR_ESP *esp;
  85. struct zorro_dev *z = NULL;
  86. unsigned long address;
  87. struct ESP_regs *eregs;
  88. unsigned long board;
  89. #if MKIV
  90. #define REAL_BLZ1230_ID ZORRO_PROD_PHASE5_BLIZZARD_1230_IV_1260
  91. #define REAL_BLZ1230_ESP_ADDR BLZ1230_ESP_ADDR
  92. #define REAL_BLZ1230_DMA_ADDR BLZ1230_DMA_ADDR
  93. #else
  94. #define REAL_BLZ1230_ID ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060
  95. #define REAL_BLZ1230_ESP_ADDR BLZ1230II_ESP_ADDR
  96. #define REAL_BLZ1230_DMA_ADDR BLZ1230II_DMA_ADDR
  97. #endif
  98. if ((z = zorro_find_device(REAL_BLZ1230_ID, z))) {
  99. board = z->resource.start;
  100. if (request_mem_region(board+REAL_BLZ1230_ESP_ADDR,
  101. sizeof(struct ESP_regs), "NCR53C9x")) {
  102. /* Do some magic to figure out if the blizzard is
  103. * equipped with a SCSI controller
  104. */
  105. address = ZTWO_VADDR(board);
  106. eregs = (struct ESP_regs *)(address + REAL_BLZ1230_ESP_ADDR);
  107. esp = esp_allocate(tpnt, (void *)board+REAL_BLZ1230_ESP_ADDR);
  108. esp_write(eregs->esp_cfg1, (ESP_CONFIG1_PENABLE | 7));
  109. udelay(5);
  110. if(esp_read(eregs->esp_cfg1) != (ESP_CONFIG1_PENABLE | 7))
  111. goto err_out;
  112. /* Do command transfer with programmed I/O */
  113. esp->do_pio_cmds = 1;
  114. /* Required functions */
  115. esp->dma_bytes_sent = &dma_bytes_sent;
  116. esp->dma_can_transfer = &dma_can_transfer;
  117. esp->dma_dump_state = &dma_dump_state;
  118. esp->dma_init_read = &dma_init_read;
  119. esp->dma_init_write = &dma_init_write;
  120. esp->dma_ints_off = &dma_ints_off;
  121. esp->dma_ints_on = &dma_ints_on;
  122. esp->dma_irq_p = &dma_irq_p;
  123. esp->dma_ports_p = &dma_ports_p;
  124. esp->dma_setup = &dma_setup;
  125. /* Optional functions */
  126. esp->dma_barrier = 0;
  127. esp->dma_drain = 0;
  128. esp->dma_invalidate = 0;
  129. esp->dma_irq_entry = 0;
  130. esp->dma_irq_exit = 0;
  131. esp->dma_led_on = 0;
  132. esp->dma_led_off = 0;
  133. esp->dma_poll = 0;
  134. esp->dma_reset = 0;
  135. /* SCSI chip speed */
  136. esp->cfreq = 40000000;
  137. /* The DMA registers on the Blizzard are mapped
  138. * relative to the device (i.e. in the same Zorro
  139. * I/O block).
  140. */
  141. esp->dregs = (void *)(address + REAL_BLZ1230_DMA_ADDR);
  142. /* ESP register base */
  143. esp->eregs = eregs;
  144. /* Set the command buffer */
  145. esp->esp_command = cmd_buffer;
  146. esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
  147. esp->irq = IRQ_AMIGA_PORTS;
  148. esp->slot = board+REAL_BLZ1230_ESP_ADDR;
  149. if (request_irq(IRQ_AMIGA_PORTS, esp_intr, SA_SHIRQ,
  150. "Blizzard 1230 SCSI IV", esp->ehost))
  151. goto err_out;
  152. /* Figure out our scsi ID on the bus */
  153. esp->scsi_id = 7;
  154. /* We don't have a differential SCSI-bus. */
  155. esp->diff = 0;
  156. esp_initialize(esp);
  157. printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
  158. esps_running = esps_in_use;
  159. return esps_in_use;
  160. }
  161. }
  162. return 0;
  163. err_out:
  164. scsi_unregister(esp->ehost);
  165. esp_deallocate(esp);
  166. release_mem_region(board+REAL_BLZ1230_ESP_ADDR,
  167. sizeof(struct ESP_regs));
  168. return 0;
  169. }
  170. /************************************************************* DMA Functions */
  171. static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
  172. {
  173. /* Since the Blizzard DMA is fully dedicated to the ESP chip,
  174. * the number of bytes sent (to the ESP chip) equals the number
  175. * of bytes in the FIFO - there is no buffering in the DMA controller.
  176. * XXXX Do I read this right? It is from host to ESP, right?
  177. */
  178. return fifo_count;
  179. }
  180. static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
  181. {
  182. /* I don't think there's any limit on the Blizzard DMA. So we use what
  183. * the ESP chip can handle (24 bit).
  184. */
  185. unsigned long sz = sp->SCp.this_residual;
  186. if(sz > 0x1000000)
  187. sz = 0x1000000;
  188. return sz;
  189. }
  190. static void dma_dump_state(struct NCR_ESP *esp)
  191. {
  192. ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
  193. amiga_custom.intreqr, amiga_custom.intenar));
  194. }
  195. void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
  196. {
  197. #if MKIV
  198. struct blz1230_dma_registers *dregs =
  199. (struct blz1230_dma_registers *) (esp->dregs);
  200. #else
  201. struct blz1230II_dma_registers *dregs =
  202. (struct blz1230II_dma_registers *) (esp->dregs);
  203. #endif
  204. cache_clear(addr, length);
  205. addr >>= 1;
  206. addr &= ~(BLZ1230_DMA_WRITE);
  207. /* First set latch */
  208. dregs->dma_latch = (addr >> 24) & 0xff;
  209. /* Then pump the address to the DMA address register */
  210. #if MKIV
  211. dregs->dma_addr = (addr >> 24) & 0xff;
  212. #endif
  213. dregs->dma_addr = (addr >> 16) & 0xff;
  214. dregs->dma_addr = (addr >> 8) & 0xff;
  215. dregs->dma_addr = (addr ) & 0xff;
  216. }
  217. void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
  218. {
  219. #if MKIV
  220. struct blz1230_dma_registers *dregs =
  221. (struct blz1230_dma_registers *) (esp->dregs);
  222. #else
  223. struct blz1230II_dma_registers *dregs =
  224. (struct blz1230II_dma_registers *) (esp->dregs);
  225. #endif
  226. cache_push(addr, length);
  227. addr >>= 1;
  228. addr |= BLZ1230_DMA_WRITE;
  229. /* First set latch */
  230. dregs->dma_latch = (addr >> 24) & 0xff;
  231. /* Then pump the address to the DMA address register */
  232. #if MKIV
  233. dregs->dma_addr = (addr >> 24) & 0xff;
  234. #endif
  235. dregs->dma_addr = (addr >> 16) & 0xff;
  236. dregs->dma_addr = (addr >> 8) & 0xff;
  237. dregs->dma_addr = (addr ) & 0xff;
  238. }
  239. static void dma_ints_off(struct NCR_ESP *esp)
  240. {
  241. disable_irq(esp->irq);
  242. }
  243. static void dma_ints_on(struct NCR_ESP *esp)
  244. {
  245. enable_irq(esp->irq);
  246. }
  247. static int dma_irq_p(struct NCR_ESP *esp)
  248. {
  249. return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
  250. }
  251. static int dma_ports_p(struct NCR_ESP *esp)
  252. {
  253. return ((amiga_custom.intenar) & IF_PORTS);
  254. }
  255. static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
  256. {
  257. /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
  258. * so when (write) is true, it actually means READ!
  259. */
  260. if(write){
  261. dma_init_read(esp, addr, count);
  262. } else {
  263. dma_init_write(esp, addr, count);
  264. }
  265. }
  266. #define HOSTS_C
  267. int blz1230_esp_release(struct Scsi_Host *instance)
  268. {
  269. #ifdef MODULE
  270. unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
  271. esp_deallocate((struct NCR_ESP *)instance->hostdata);
  272. esp_release();
  273. release_mem_region(address, sizeof(struct ESP_regs));
  274. free_irq(IRQ_AMIGA_PORTS, esp_intr);
  275. #endif
  276. return 1;
  277. }
  278. static struct scsi_host_template driver_template = {
  279. .proc_name = "esp-blz1230",
  280. .proc_info = esp_proc_info,
  281. .name = "Blizzard1230 SCSI IV",
  282. .detect = blz1230_esp_detect,
  283. .slave_alloc = esp_slave_alloc,
  284. .slave_destroy = esp_slave_destroy,
  285. .release = blz1230_esp_release,
  286. .queuecommand = esp_queue,
  287. .eh_abort_handler = esp_abort,
  288. .eh_bus_reset_handler = esp_reset,
  289. .can_queue = 7,
  290. .this_id = 7,
  291. .sg_tablesize = SG_ALL,
  292. .cmd_per_lun = 1,
  293. .use_clustering = ENABLE_CLUSTERING
  294. };
  295. #include "scsi_module.c"
  296. MODULE_LICENSE("GPL");