gvp11.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. #include <linux/types.h>
  2. #include <linux/mm.h>
  3. #include <linux/slab.h>
  4. #include <linux/blkdev.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. 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. struct Scsi_Host *instance = cmd->device->host;
  42. struct WD33C93_hostdata *hdata = shost_priv(instance);
  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->dma_xfer_mask) {
  49. hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
  50. if (!scsi_alloc_out_of_range) {
  51. hdata->dma_bounce_buffer =
  52. kmalloc(hdata->dma_bounce_len, GFP_KERNEL);
  53. hdata->dma_buffer_pool = BUF_SCSI_ALLOCED;
  54. }
  55. if (scsi_alloc_out_of_range ||
  56. !hdata->dma_bounce_buffer) {
  57. hdata->dma_bounce_buffer =
  58. amiga_chip_alloc(hdata->dma_bounce_len,
  59. "GVP II SCSI Bounce Buffer");
  60. if (!hdata->dma_bounce_buffer) {
  61. hdata->dma_bounce_len = 0;
  62. return 1;
  63. }
  64. hdata->dma_buffer_pool = BUF_CHIP_ALLOCED;
  65. }
  66. /* check if the address of the bounce buffer is OK */
  67. addr = virt_to_bus(hdata->dma_bounce_buffer);
  68. if (addr & hdata->dma_xfer_mask) {
  69. /* fall back to Chip RAM if address out of range */
  70. if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED) {
  71. kfree(hdata->dma_bounce_buffer);
  72. scsi_alloc_out_of_range = 1;
  73. } else {
  74. amiga_chip_free(hdata->dma_bounce_buffer);
  75. }
  76. hdata->dma_bounce_buffer =
  77. amiga_chip_alloc(hdata->dma_bounce_len,
  78. "GVP II SCSI Bounce Buffer");
  79. if (!hdata->dma_bounce_buffer) {
  80. hdata->dma_bounce_len = 0;
  81. return 1;
  82. }
  83. addr = virt_to_bus(hdata->dma_bounce_buffer);
  84. hdata->dma_buffer_pool = BUF_CHIP_ALLOCED;
  85. }
  86. if (!dir_in) {
  87. /* copy to bounce buffer for a write */
  88. memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr,
  89. cmd->SCp.this_residual);
  90. }
  91. }
  92. /* setup dma direction */
  93. if (!dir_in)
  94. cntr |= GVP11_DMAC_DIR_WRITE;
  95. hdata->dma_dir = dir_in;
  96. DMA(cmd->device->host)->CNTR = cntr;
  97. /* setup DMA *physical* address */
  98. DMA(cmd->device->host)->ACR = addr;
  99. if (dir_in) {
  100. /* invalidate any cache */
  101. cache_clear(addr, cmd->SCp.this_residual);
  102. } else {
  103. /* push any dirty cache */
  104. cache_push(addr, cmd->SCp.this_residual);
  105. }
  106. bank_mask = (~hdata->dma_xfer_mask >> 18) & 0x01c0;
  107. if (bank_mask)
  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. struct WD33C93_hostdata *hdata = shost_priv(instance);
  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->dma_bounce_buffer) {
  124. if (hdata->dma_dir && SCpnt)
  125. memcpy(SCpnt->SCp.ptr, hdata->dma_bounce_buffer,
  126. SCpnt->SCp.this_residual);
  127. if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED)
  128. kfree(hdata->dma_bounce_buffer);
  129. else
  130. amiga_chip_free(hdata->dma_bounce_buffer);
  131. hdata->dma_bounce_buffer = NULL;
  132. hdata->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. struct WD33C93_hostdata *hdata;
  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. /*
  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. hdata = shost_priv(instance);
  256. if (gvp11_xfer_mask)
  257. hdata->dma_xfer_mask = gvp11_xfer_mask;
  258. else
  259. hdata->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. ;
  265. DMA(instance)->CNTR = 0;
  266. DMA(instance)->BANK = 0;
  267. epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000);
  268. /*
  269. * Check for 14MHz SCSI clock
  270. */
  271. regs.SASR = &(DMA(instance)->SASR);
  272. regs.SCMD = &(DMA(instance)->SCMD);
  273. hdata->no_sync = 0xff;
  274. hdata->fast = 0;
  275. hdata->dma_mode = CTRL_DMA;
  276. wd33c93_init(instance, regs, dma_setup, dma_stop,
  277. (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10
  278. : WD33C93_FS_12_15);
  279. if (request_irq(IRQ_AMIGA_PORTS, gvp11_intr, IRQF_SHARED,
  280. "GVP11 SCSI", instance))
  281. goto unregister;
  282. DMA(instance)->CNTR = GVP11_DMAC_INT_ENABLE;
  283. num_gvp11++;
  284. continue;
  285. unregister:
  286. scsi_unregister(instance);
  287. release:
  288. release_mem_region(address, 256);
  289. }
  290. return num_gvp11;
  291. }
  292. static int gvp11_bus_reset(struct scsi_cmnd *cmd)
  293. {
  294. /* FIXME perform bus-specific reset */
  295. /* FIXME 2: shouldn't we no-op this function (return
  296. FAILED), and fall back to host reset function,
  297. wd33c93_host_reset ? */
  298. spin_lock_irq(cmd->device->host->host_lock);
  299. wd33c93_host_reset(cmd);
  300. spin_unlock_irq(cmd->device->host->host_lock);
  301. return SUCCESS;
  302. }
  303. #define HOSTS_C
  304. #include "gvp11.h"
  305. static struct scsi_host_template driver_template = {
  306. .proc_name = "GVP11",
  307. .name = "GVP Series II SCSI",
  308. .detect = gvp11_detect,
  309. .release = gvp11_release,
  310. .queuecommand = wd33c93_queuecommand,
  311. .eh_abort_handler = wd33c93_abort,
  312. .eh_bus_reset_handler = gvp11_bus_reset,
  313. .eh_host_reset_handler = wd33c93_host_reset,
  314. .can_queue = CAN_QUEUE,
  315. .this_id = 7,
  316. .sg_tablesize = SG_ALL,
  317. .cmd_per_lun = CMD_PER_LUN,
  318. .use_clustering = DISABLE_CLUSTERING
  319. };
  320. #include "scsi_module.c"
  321. int gvp11_release(struct Scsi_Host *instance)
  322. {
  323. #ifdef MODULE
  324. DMA(instance)->CNTR = 0;
  325. release_mem_region(ZTWO_PADDR(instance->base), 256);
  326. free_irq(IRQ_AMIGA_PORTS, instance);
  327. #endif
  328. return 1;
  329. }
  330. MODULE_LICENSE("GPL");