gvp11.c 11 KB

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