gvp11.c 11 KB

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