mvme147.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include <linux/types.h>
  2. #include <linux/mm.h>
  3. #include <linux/blkdev.h>
  4. #include <linux/interrupt.h>
  5. #include <asm/page.h>
  6. #include <asm/pgtable.h>
  7. #include <asm/mvme147hw.h>
  8. #include <asm/irq.h>
  9. #include "scsi.h"
  10. #include <scsi/scsi_host.h>
  11. #include "wd33c93.h"
  12. #include "mvme147.h"
  13. #include <linux/stat.h>
  14. static struct Scsi_Host *mvme147_host = NULL;
  15. static irqreturn_t mvme147_intr(int irq, void *dummy)
  16. {
  17. if (irq == MVME147_IRQ_SCSI_PORT)
  18. wd33c93_intr(mvme147_host);
  19. else
  20. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  21. return IRQ_HANDLED;
  22. }
  23. static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
  24. {
  25. struct WD33C93_hostdata *hdata = shost_priv(mvme147_host);
  26. unsigned char flags = 0x01;
  27. unsigned long addr = virt_to_bus(cmd->SCp.ptr);
  28. /* setup dma direction */
  29. if (!dir_in)
  30. flags |= 0x04;
  31. /* remember direction */
  32. hdata->dma_dir = dir_in;
  33. if (dir_in) {
  34. /* invalidate any cache */
  35. cache_clear(addr, cmd->SCp.this_residual);
  36. } else {
  37. /* push any dirty cache */
  38. cache_push(addr, cmd->SCp.this_residual);
  39. }
  40. /* start DMA */
  41. m147_pcc->dma_bcr = cmd->SCp.this_residual | (1 << 24);
  42. m147_pcc->dma_dadr = addr;
  43. m147_pcc->dma_cntrl = flags;
  44. /* return success */
  45. return 0;
  46. }
  47. static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
  48. int status)
  49. {
  50. m147_pcc->dma_cntrl = 0;
  51. }
  52. int mvme147_detect(struct scsi_host_template *tpnt)
  53. {
  54. static unsigned char called = 0;
  55. wd33c93_regs regs;
  56. struct WD33C93_hostdata *hdata;
  57. if (!MACH_IS_MVME147 || called)
  58. return 0;
  59. called++;
  60. tpnt->proc_name = "MVME147";
  61. tpnt->proc_info = &wd33c93_proc_info;
  62. mvme147_host = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
  63. if (!mvme147_host)
  64. goto err_out;
  65. mvme147_host->base = 0xfffe4000;
  66. mvme147_host->irq = MVME147_IRQ_SCSI_PORT;
  67. regs.SASR = (volatile unsigned char *)0xfffe4000;
  68. regs.SCMD = (volatile unsigned char *)0xfffe4001;
  69. hdata = shost_priv(mvme147_host);
  70. hdata->no_sync = 0xff;
  71. hdata->fast = 0;
  72. hdata->dma_mode = CTRL_DMA;
  73. wd33c93_init(mvme147_host, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
  74. if (request_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr, 0,
  75. "MVME147 SCSI PORT", mvme147_intr))
  76. goto err_unregister;
  77. if (request_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr, 0,
  78. "MVME147 SCSI DMA", mvme147_intr))
  79. goto err_free_irq;
  80. #if 0 /* Disabled; causes problems booting */
  81. m147_pcc->scsi_interrupt = 0x10; /* Assert SCSI bus reset */
  82. udelay(100);
  83. m147_pcc->scsi_interrupt = 0x00; /* Negate SCSI bus reset */
  84. udelay(2000);
  85. m147_pcc->scsi_interrupt = 0x40; /* Clear bus reset interrupt */
  86. #endif
  87. m147_pcc->scsi_interrupt = 0x09; /* Enable interrupt */
  88. m147_pcc->dma_cntrl = 0x00; /* ensure DMA is stopped */
  89. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  90. return 1;
  91. err_free_irq:
  92. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
  93. err_unregister:
  94. scsi_unregister(mvme147_host);
  95. err_out:
  96. return 0;
  97. }
  98. static int mvme147_bus_reset(struct scsi_cmnd *cmd)
  99. {
  100. /* FIXME perform bus-specific reset */
  101. /* FIXME 2: kill this function, and let midlayer fallback to
  102. the same result, calling wd33c93_host_reset() */
  103. spin_lock_irq(cmd->device->host->host_lock);
  104. wd33c93_host_reset(cmd);
  105. spin_unlock_irq(cmd->device->host->host_lock);
  106. return SUCCESS;
  107. }
  108. #define HOSTS_C
  109. #include "mvme147.h"
  110. static struct scsi_host_template driver_template = {
  111. .proc_name = "MVME147",
  112. .name = "MVME147 built-in SCSI",
  113. .detect = mvme147_detect,
  114. .release = mvme147_release,
  115. .queuecommand = wd33c93_queuecommand,
  116. .eh_abort_handler = wd33c93_abort,
  117. .eh_bus_reset_handler = mvme147_bus_reset,
  118. .eh_host_reset_handler = wd33c93_host_reset,
  119. .can_queue = CAN_QUEUE,
  120. .this_id = 7,
  121. .sg_tablesize = SG_ALL,
  122. .cmd_per_lun = CMD_PER_LUN,
  123. .use_clustering = ENABLE_CLUSTERING
  124. };
  125. #include "scsi_module.c"
  126. int mvme147_release(struct Scsi_Host *instance)
  127. {
  128. #ifdef MODULE
  129. /* XXX Make sure DMA is stopped! */
  130. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
  131. free_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr);
  132. #endif
  133. return 1;
  134. }