gvp11.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. #include <linux/types.h>
  2. #include <linux/mm.h>
  3. #include <linux/blkdev.h>
  4. #include <linux/sched.h>
  5. #include <linux/init.h>
  6. #include <linux/interrupt.h>
  7. #include <asm/setup.h>
  8. #include <asm/page.h>
  9. #include <asm/pgtable.h>
  10. #include <asm/amigaints.h>
  11. #include <asm/amigahw.h>
  12. #include <linux/zorro.h>
  13. #include <asm/irq.h>
  14. #include <linux/spinlock.h>
  15. #include "scsi.h"
  16. #include <scsi/scsi_host.h>
  17. #include "wd33c93.h"
  18. #include "gvp11.h"
  19. #include<linux/stat.h>
  20. #define DMA(ptr) ((gvp11_scsiregs *)((ptr)->base))
  21. #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
  22. static irqreturn_t gvp11_intr (int irq, void *_instance, struct pt_regs *fp)
  23. {
  24. unsigned long flags;
  25. unsigned int status;
  26. struct Scsi_Host *instance = (struct Scsi_Host *)_instance;
  27. status = DMA(instance)->CNTR;
  28. if (!(status & GVP11_DMAC_INT_PENDING))
  29. return IRQ_NONE;
  30. spin_lock_irqsave(instance->host_lock, flags);
  31. wd33c93_intr(instance);
  32. spin_unlock_irqrestore(instance->host_lock, flags);
  33. return IRQ_HANDLED;
  34. }
  35. static int gvp11_xfer_mask = 0;
  36. void gvp11_setup (char *str, int *ints)
  37. {
  38. gvp11_xfer_mask = ints[1];
  39. }
  40. static int dma_setup (Scsi_Cmnd *cmd, int dir_in)
  41. {
  42. unsigned short cntr = GVP11_DMAC_INT_ENABLE;
  43. unsigned long addr = virt_to_bus(cmd->SCp.ptr);
  44. int bank_mask;
  45. static int scsi_alloc_out_of_range = 0;
  46. /* use bounce buffer if the physical address is bad */
  47. if (addr & HDATA(cmd->device->host)->dma_xfer_mask ||
  48. (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
  49. {
  50. HDATA(cmd->device->host)->dma_bounce_len = (cmd->SCp.this_residual + 511)
  51. & ~0x1ff;
  52. if( !scsi_alloc_out_of_range ) {
  53. HDATA(cmd->device->host)->dma_bounce_buffer =
  54. kmalloc (HDATA(cmd->device->host)->dma_bounce_len, GFP_KERNEL);
  55. HDATA(cmd->device->host)->dma_buffer_pool = BUF_SCSI_ALLOCED;
  56. }
  57. if (scsi_alloc_out_of_range ||
  58. !HDATA(cmd->device->host)->dma_bounce_buffer) {
  59. HDATA(cmd->device->host)->dma_bounce_buffer =
  60. amiga_chip_alloc(HDATA(cmd->device->host)->dma_bounce_len,
  61. "GVP II SCSI Bounce Buffer");
  62. if(!HDATA(cmd->device->host)->dma_bounce_buffer)
  63. {
  64. HDATA(cmd->device->host)->dma_bounce_len = 0;
  65. return 1;
  66. }
  67. HDATA(cmd->device->host)->dma_buffer_pool = BUF_CHIP_ALLOCED;
  68. }
  69. /* check if the address of the bounce buffer is OK */
  70. addr = virt_to_bus(HDATA(cmd->device->host)->dma_bounce_buffer);
  71. if (addr & HDATA(cmd->device->host)->dma_xfer_mask) {
  72. /* fall back to Chip RAM if address out of range */
  73. if( HDATA(cmd->device->host)->dma_buffer_pool == BUF_SCSI_ALLOCED) {
  74. kfree (HDATA(cmd->device->host)->dma_bounce_buffer);
  75. scsi_alloc_out_of_range = 1;
  76. } else {
  77. amiga_chip_free (HDATA(cmd->device->host)->dma_bounce_buffer);
  78. }
  79. HDATA(cmd->device->host)->dma_bounce_buffer =
  80. amiga_chip_alloc(HDATA(cmd->device->host)->dma_bounce_len,
  81. "GVP II SCSI Bounce Buffer");
  82. if(!HDATA(cmd->device->host)->dma_bounce_buffer)
  83. {
  84. HDATA(cmd->device->host)->dma_bounce_len = 0;
  85. return 1;
  86. }
  87. addr = virt_to_bus(HDATA(cmd->device->host)->dma_bounce_buffer);
  88. HDATA(cmd->device->host)->dma_buffer_pool = BUF_CHIP_ALLOCED;
  89. }
  90. if (!dir_in) {
  91. /* copy to bounce buffer for a write */
  92. memcpy (HDATA(cmd->device->host)->dma_bounce_buffer,
  93. cmd->SCp.ptr, cmd->SCp.this_residual);
  94. }
  95. }
  96. /* setup dma direction */
  97. if (!dir_in)
  98. cntr |= GVP11_DMAC_DIR_WRITE;
  99. HDATA(cmd->device->host)->dma_dir = dir_in;
  100. DMA(cmd->device->host)->CNTR = cntr;
  101. /* setup DMA *physical* address */
  102. DMA(cmd->device->host)->ACR = addr;
  103. if (dir_in)
  104. /* invalidate any cache */
  105. cache_clear (addr, cmd->SCp.this_residual);
  106. else
  107. /* push any dirty cache */
  108. cache_push (addr, cmd->SCp.this_residual);
  109. if ((bank_mask = (~HDATA(cmd->device->host)->dma_xfer_mask >> 18) & 0x01c0))
  110. DMA(cmd->device->host)->BANK = bank_mask & (addr >> 18);
  111. /* start DMA */
  112. DMA(cmd->device->host)->ST_DMA = 1;
  113. /* return success */
  114. return 0;
  115. }
  116. static void dma_stop (struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
  117. int status)
  118. {
  119. /* stop DMA */
  120. DMA(instance)->SP_DMA = 1;
  121. /* remove write bit from CONTROL bits */
  122. DMA(instance)->CNTR = GVP11_DMAC_INT_ENABLE;
  123. /* copy from a bounce buffer, if necessary */
  124. if (status && HDATA(instance)->dma_bounce_buffer) {
  125. if (HDATA(instance)->dma_dir && SCpnt)
  126. memcpy (SCpnt->SCp.ptr,
  127. HDATA(instance)->dma_bounce_buffer,
  128. SCpnt->SCp.this_residual);
  129. if (HDATA(instance)->dma_buffer_pool == BUF_SCSI_ALLOCED)
  130. kfree (HDATA(instance)->dma_bounce_buffer);
  131. else
  132. amiga_chip_free(HDATA(instance)->dma_bounce_buffer);
  133. HDATA(instance)->dma_bounce_buffer = NULL;
  134. HDATA(instance)->dma_bounce_len = 0;
  135. }
  136. }
  137. #define CHECK_WD33C93
  138. int __init gvp11_detect(struct scsi_host_template *tpnt)
  139. {
  140. static unsigned char called = 0;
  141. struct Scsi_Host *instance;
  142. unsigned long address;
  143. unsigned int epc;
  144. struct zorro_dev *z = NULL;
  145. unsigned int default_dma_xfer_mask;
  146. wd33c93_regs regs;
  147. int num_gvp11 = 0;
  148. #ifdef CHECK_WD33C93
  149. volatile unsigned char *sasr_3393, *scmd_3393;
  150. unsigned char save_sasr;
  151. unsigned char q, qq;
  152. #endif
  153. if (!MACH_IS_AMIGA || called)
  154. return 0;
  155. called = 1;
  156. tpnt->proc_name = "GVP11";
  157. tpnt->proc_info = &wd33c93_proc_info;
  158. while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
  159. /*
  160. * This should (hopefully) be the correct way to identify
  161. * all the different GVP SCSI controllers (except for the
  162. * SERIES I though).
  163. */
  164. if (z->id == ZORRO_PROD_GVP_COMBO_030_R3_SCSI ||
  165. z->id == ZORRO_PROD_GVP_SERIES_II)
  166. default_dma_xfer_mask = ~0x00ffffff;
  167. else if (z->id == ZORRO_PROD_GVP_GFORCE_030_SCSI ||
  168. z->id == ZORRO_PROD_GVP_A530_SCSI ||
  169. z->id == ZORRO_PROD_GVP_COMBO_030_R4_SCSI)
  170. default_dma_xfer_mask = ~0x01ffffff;
  171. else if (z->id == ZORRO_PROD_GVP_A1291 ||
  172. z->id == ZORRO_PROD_GVP_GFORCE_040_SCSI_1)
  173. default_dma_xfer_mask = ~0x07ffffff;
  174. else
  175. continue;
  176. /*
  177. * Rumors state that some GVP ram boards use the same product
  178. * code as the SCSI controllers. Therefore if the board-size
  179. * is not 64KB we asume it is a ram board and bail out.
  180. */
  181. if (z->resource.end-z->resource.start != 0xffff)
  182. continue;
  183. address = z->resource.start;
  184. if (!request_mem_region(address, 256, "wd33c93"))
  185. continue;
  186. #ifdef CHECK_WD33C93
  187. /*
  188. * These darn GVP boards are a problem - it can be tough to tell
  189. * whether or not they include a SCSI controller. This is the
  190. * ultimate Yet-Another-GVP-Detection-Hack in that it actually
  191. * probes for a WD33c93 chip: If we find one, it's extremely
  192. * likely that this card supports SCSI, regardless of Product_
  193. * Code, Board_Size, etc.
  194. */
  195. /* Get pointers to the presumed register locations and save contents */
  196. sasr_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SASR);
  197. scmd_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SCMD);
  198. save_sasr = *sasr_3393;
  199. /* First test the AuxStatus Reg */
  200. q = *sasr_3393; /* read it */
  201. if (q & 0x08) /* bit 3 should always be clear */
  202. goto release;
  203. *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */
  204. if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */
  205. *sasr_3393 = save_sasr; /* Oops - restore this byte */
  206. goto release;
  207. }
  208. if (*sasr_3393 != q) { /* should still read the same */
  209. *sasr_3393 = save_sasr; /* Oops - restore this byte */
  210. goto release;
  211. }
  212. if (*scmd_3393 != q) /* and so should the image at 0x1f */
  213. goto release;
  214. /* Ok, we probably have a wd33c93, but let's check a few other places
  215. * for good measure. Make sure that this works for both 'A and 'B
  216. * chip versions.
  217. */
  218. *sasr_3393 = WD_SCSI_STATUS;
  219. q = *scmd_3393;
  220. *sasr_3393 = WD_SCSI_STATUS;
  221. *scmd_3393 = ~q;
  222. *sasr_3393 = WD_SCSI_STATUS;
  223. qq = *scmd_3393;
  224. *sasr_3393 = WD_SCSI_STATUS;
  225. *scmd_3393 = q;
  226. if (qq != q) /* should be read only */
  227. goto release;
  228. *sasr_3393 = 0x1e; /* this register is unimplemented */
  229. q = *scmd_3393;
  230. *sasr_3393 = 0x1e;
  231. *scmd_3393 = ~q;
  232. *sasr_3393 = 0x1e;
  233. qq = *scmd_3393;
  234. *sasr_3393 = 0x1e;
  235. *scmd_3393 = q;
  236. if (qq != q || qq != 0xff) /* should be read only, all 1's */
  237. goto release;
  238. *sasr_3393 = WD_TIMEOUT_PERIOD;
  239. q = *scmd_3393;
  240. *sasr_3393 = WD_TIMEOUT_PERIOD;
  241. *scmd_3393 = ~q;
  242. *sasr_3393 = WD_TIMEOUT_PERIOD;
  243. qq = *scmd_3393;
  244. *sasr_3393 = WD_TIMEOUT_PERIOD;
  245. *scmd_3393 = q;
  246. if (qq != (~q & 0xff)) /* should be read/write */
  247. goto release;
  248. #endif
  249. instance = scsi_register (tpnt, sizeof (struct WD33C93_hostdata));
  250. if(instance == NULL)
  251. goto release;
  252. instance->base = ZTWO_VADDR(address);
  253. instance->irq = IRQ_AMIGA_PORTS;
  254. instance->unique_id = z->slotaddr;
  255. if (gvp11_xfer_mask)
  256. HDATA(instance)->dma_xfer_mask = gvp11_xfer_mask;
  257. else
  258. HDATA(instance)->dma_xfer_mask = default_dma_xfer_mask;
  259. DMA(instance)->secret2 = 1;
  260. DMA(instance)->secret1 = 0;
  261. DMA(instance)->secret3 = 15;
  262. while (DMA(instance)->CNTR & GVP11_DMAC_BUSY) ;
  263. DMA(instance)->CNTR = 0;
  264. DMA(instance)->BANK = 0;
  265. epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000);
  266. /*
  267. * Check for 14MHz SCSI clock
  268. */
  269. regs.SASR = &(DMA(instance)->SASR);
  270. regs.SCMD = &(DMA(instance)->SCMD);
  271. wd33c93_init(instance, regs, dma_setup, dma_stop,
  272. (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10
  273. : WD33C93_FS_12_15);
  274. request_irq(IRQ_AMIGA_PORTS, gvp11_intr, SA_SHIRQ, "GVP11 SCSI",
  275. instance);
  276. DMA(instance)->CNTR = GVP11_DMAC_INT_ENABLE;
  277. num_gvp11++;
  278. continue;
  279. release:
  280. release_mem_region(address, 256);
  281. }
  282. return num_gvp11;
  283. }
  284. static int gvp11_bus_reset(Scsi_Cmnd *cmd)
  285. {
  286. /* FIXME perform bus-specific reset */
  287. /* FIXME 2: shouldn't we no-op this function (return
  288. FAILED), and fall back to host reset function,
  289. wd33c93_host_reset ? */
  290. spin_lock_irq(cmd->device->host->host_lock);
  291. wd33c93_host_reset(cmd);
  292. spin_unlock_irq(cmd->device->host->host_lock);
  293. return SUCCESS;
  294. }
  295. #define HOSTS_C
  296. #include "gvp11.h"
  297. static struct scsi_host_template driver_template = {
  298. .proc_name = "GVP11",
  299. .name = "GVP Series II SCSI",
  300. .detect = gvp11_detect,
  301. .release = gvp11_release,
  302. .queuecommand = wd33c93_queuecommand,
  303. .eh_abort_handler = wd33c93_abort,
  304. .eh_bus_reset_handler = gvp11_bus_reset,
  305. .eh_host_reset_handler = wd33c93_host_reset,
  306. .can_queue = CAN_QUEUE,
  307. .this_id = 7,
  308. .sg_tablesize = SG_ALL,
  309. .cmd_per_lun = CMD_PER_LUN,
  310. .use_clustering = DISABLE_CLUSTERING
  311. };
  312. #include "scsi_module.c"
  313. int gvp11_release(struct Scsi_Host *instance)
  314. {
  315. #ifdef MODULE
  316. DMA(instance)->CNTR = 0;
  317. release_mem_region(ZTWO_PADDR(instance->base), 256);
  318. free_irq(IRQ_AMIGA_PORTS, instance);
  319. wd33c93_release();
  320. #endif
  321. return 1;
  322. }
  323. MODULE_LICENSE("GPL");