mvme147.c 4.0 KB

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