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->show_info = wd33c93_show_info,
  64. tpnt->write_info = wd33c93_write_info,
  65. instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
  66. if (!instance)
  67. goto err_out;
  68. instance->base = 0xfffe4000;
  69. instance->irq = MVME147_IRQ_SCSI_PORT;
  70. regs.SASR = (volatile unsigned char *)0xfffe4000;
  71. regs.SCMD = (volatile unsigned char *)0xfffe4001;
  72. hdata = shost_priv(instance);
  73. hdata->no_sync = 0xff;
  74. hdata->fast = 0;
  75. hdata->dma_mode = CTRL_DMA;
  76. wd33c93_init(instance, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
  77. if (request_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr, 0,
  78. "MVME147 SCSI PORT", instance))
  79. goto err_unregister;
  80. if (request_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr, 0,
  81. "MVME147 SCSI DMA", instance))
  82. goto err_free_irq;
  83. #if 0 /* Disabled; causes problems booting */
  84. m147_pcc->scsi_interrupt = 0x10; /* Assert SCSI bus reset */
  85. udelay(100);
  86. m147_pcc->scsi_interrupt = 0x00; /* Negate SCSI bus reset */
  87. udelay(2000);
  88. m147_pcc->scsi_interrupt = 0x40; /* Clear bus reset interrupt */
  89. #endif
  90. m147_pcc->scsi_interrupt = 0x09; /* Enable interrupt */
  91. m147_pcc->dma_cntrl = 0x00; /* ensure DMA is stopped */
  92. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  93. return 1;
  94. err_free_irq:
  95. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
  96. err_unregister:
  97. scsi_unregister(instance);
  98. err_out:
  99. return 0;
  100. }
  101. static int mvme147_bus_reset(struct scsi_cmnd *cmd)
  102. {
  103. /* FIXME perform bus-specific reset */
  104. /* FIXME 2: kill this function, and let midlayer fallback to
  105. the same result, calling wd33c93_host_reset() */
  106. spin_lock_irq(cmd->device->host->host_lock);
  107. wd33c93_host_reset(cmd);
  108. spin_unlock_irq(cmd->device->host->host_lock);
  109. return SUCCESS;
  110. }
  111. static struct scsi_host_template driver_template = {
  112. .proc_name = "MVME147",
  113. .name = "MVME147 built-in SCSI",
  114. .detect = mvme147_detect,
  115. .release = mvme147_release,
  116. .queuecommand = wd33c93_queuecommand,
  117. .eh_abort_handler = wd33c93_abort,
  118. .eh_bus_reset_handler = mvme147_bus_reset,
  119. .eh_host_reset_handler = wd33c93_host_reset,
  120. .can_queue = CAN_QUEUE,
  121. .this_id = 7,
  122. .sg_tablesize = SG_ALL,
  123. .cmd_per_lun = CMD_PER_LUN,
  124. .use_clustering = ENABLE_CLUSTERING
  125. };
  126. #include "scsi_module.c"
  127. int mvme147_release(struct Scsi_Host *instance)
  128. {
  129. #ifdef MODULE
  130. /* XXX Make sure DMA is stopped! */
  131. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
  132. free_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr);
  133. #endif
  134. return 1;
  135. }