cyberstormII.c 8.6 KB

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