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 irqreturn_t mvme147_intr(int irq, void *data)
  15. {
  16. struct Scsi_Host *instance = data;
  17. if (irq == MVME147_IRQ_SCSI_PORT)
  18. wd33c93_intr(instance);
  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 Scsi_Host *instance = cmd->device->host;
  26. struct WD33C93_hostdata *hdata = shost_priv(instance);
  27. unsigned char flags = 0x01;
  28. unsigned long addr = virt_to_bus(cmd->SCp.ptr);
  29. /* setup dma direction */
  30. if (!dir_in)
  31. flags |= 0x04;
  32. /* remember direction */
  33. hdata->dma_dir = dir_in;
  34. if (dir_in) {
  35. /* invalidate any cache */
  36. cache_clear(addr, cmd->SCp.this_residual);
  37. } else {
  38. /* push any dirty cache */
  39. cache_push(addr, cmd->SCp.this_residual);
  40. }
  41. /* start DMA */
  42. m147_pcc->dma_bcr = cmd->SCp.this_residual | (1 << 24);
  43. m147_pcc->dma_dadr = addr;
  44. m147_pcc->dma_cntrl = flags;
  45. /* return success */
  46. return 0;
  47. }
  48. static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
  49. int status)
  50. {
  51. m147_pcc->dma_cntrl = 0;
  52. }
  53. int mvme147_detect(struct scsi_host_template *tpnt)
  54. {
  55. static unsigned char called = 0;
  56. struct Scsi_Host *instance;
  57. wd33c93_regs regs;
  58. struct WD33C93_hostdata *hdata;
  59. if (!MACH_IS_MVME147 || called)
  60. return 0;
  61. called++;
  62. tpnt->proc_name = "MVME147";
  63. tpnt->proc_info = &wd33c93_proc_info;
  64. instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
  65. if (!instance)
  66. goto err_out;
  67. instance->base = 0xfffe4000;
  68. instance->irq = MVME147_IRQ_SCSI_PORT;
  69. regs.SASR = (volatile unsigned char *)0xfffe4000;
  70. regs.SCMD = (volatile unsigned char *)0xfffe4001;
  71. hdata = shost_priv(instance);
  72. hdata->no_sync = 0xff;
  73. hdata->fast = 0;
  74. hdata->dma_mode = CTRL_DMA;
  75. wd33c93_init(instance, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
  76. if (request_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr, 0,
  77. "MVME147 SCSI PORT", instance))
  78. goto err_unregister;
  79. if (request_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr, 0,
  80. "MVME147 SCSI DMA", instance))
  81. goto err_free_irq;
  82. #if 0 /* Disabled; causes problems booting */
  83. m147_pcc->scsi_interrupt = 0x10; /* Assert SCSI bus reset */
  84. udelay(100);
  85. m147_pcc->scsi_interrupt = 0x00; /* Negate SCSI bus reset */
  86. udelay(2000);
  87. m147_pcc->scsi_interrupt = 0x40; /* Clear bus reset interrupt */
  88. #endif
  89. m147_pcc->scsi_interrupt = 0x09; /* Enable interrupt */
  90. m147_pcc->dma_cntrl = 0x00; /* ensure DMA is stopped */
  91. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  92. return 1;
  93. err_free_irq:
  94. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
  95. err_unregister:
  96. scsi_unregister(instance);
  97. err_out:
  98. return 0;
  99. }
  100. static int mvme147_bus_reset(struct scsi_cmnd *cmd)
  101. {
  102. /* FIXME perform bus-specific reset */
  103. /* FIXME 2: kill this function, and let midlayer fallback to
  104. the same result, calling wd33c93_host_reset() */
  105. spin_lock_irq(cmd->device->host->host_lock);
  106. wd33c93_host_reset(cmd);
  107. spin_unlock_irq(cmd->device->host->host_lock);
  108. return SUCCESS;
  109. }
  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. }