mvme147.c 4.1 KB

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