gvp11.c 11 KB

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