mvme147.c 3.9 KB

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