mvme147.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include <linux/types.h>
  2. #include <linux/mm.h>
  3. #include <linux/blkdev.h>
  4. #include <linux/sched.h>
  5. #include <linux/interrupt.h>
  6. #include <asm/page.h>
  7. #include <asm/pgtable.h>
  8. #include <asm/mvme147hw.h>
  9. #include <asm/irq.h>
  10. #include "scsi.h"
  11. #include <scsi/scsi_host.h>
  12. #include "wd33c93.h"
  13. #include "mvme147.h"
  14. #include<linux/stat.h>
  15. #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
  16. static struct Scsi_Host *mvme147_host = NULL;
  17. static irqreturn_t mvme147_intr (int irq, void *dummy, struct pt_regs *fp)
  18. {
  19. if (irq == MVME147_IRQ_SCSI_PORT)
  20. wd33c93_intr (mvme147_host);
  21. else
  22. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  23. return IRQ_HANDLED;
  24. }
  25. static int dma_setup (Scsi_Cmnd *cmd, int dir_in)
  26. {
  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(mvme147_host)->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. /* 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, 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. wd33c93_init(mvme147_host, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
  69. if (request_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr, 0, "MVME147 SCSI PORT", mvme147_intr))
  70. goto err_unregister;
  71. if (request_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr, 0, "MVME147 SCSI DMA", mvme147_intr))
  72. goto err_free_irq;
  73. #if 0 /* Disabled; causes problems booting */
  74. m147_pcc->scsi_interrupt = 0x10; /* Assert SCSI bus reset */
  75. udelay(100);
  76. m147_pcc->scsi_interrupt = 0x00; /* Negate SCSI bus reset */
  77. udelay(2000);
  78. m147_pcc->scsi_interrupt = 0x40; /* Clear bus reset interrupt */
  79. #endif
  80. m147_pcc->scsi_interrupt = 0x09; /* Enable interrupt */
  81. m147_pcc->dma_cntrl = 0x00; /* ensure DMA is stopped */
  82. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  83. return 1;
  84. err_free_irq:
  85. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
  86. err_unregister:
  87. wd33c93_release();
  88. scsi_unregister(mvme147_host);
  89. err_out:
  90. return 0;
  91. }
  92. static int mvme147_bus_reset(Scsi_Cmnd *cmd)
  93. {
  94. /* FIXME perform bus-specific reset */
  95. /* FIXME 2: kill this function, and let midlayer fallback to
  96. the same result, calling wd33c93_host_reset() */
  97. spin_lock_irq(cmd->device->host->host_lock);
  98. wd33c93_host_reset(cmd);
  99. spin_unlock_irq(cmd->device->host->host_lock);
  100. return SUCCESS;
  101. }
  102. #define HOSTS_C
  103. #include "mvme147.h"
  104. static struct scsi_host_template driver_template = {
  105. .proc_name = "MVME147",
  106. .name = "MVME147 built-in SCSI",
  107. .detect = mvme147_detect,
  108. .release = mvme147_release,
  109. .queuecommand = wd33c93_queuecommand,
  110. .eh_abort_handler = wd33c93_abort,
  111. .eh_bus_reset_handler = mvme147_bus_reset,
  112. .eh_host_reset_handler = wd33c93_host_reset,
  113. .can_queue = CAN_QUEUE,
  114. .this_id = 7,
  115. .sg_tablesize = SG_ALL,
  116. .cmd_per_lun = CMD_PER_LUN,
  117. .use_clustering = ENABLE_CLUSTERING
  118. };
  119. #include "scsi_module.c"
  120. int mvme147_release(struct Scsi_Host *instance)
  121. {
  122. #ifdef MODULE
  123. /* XXX Make sure DMA is stopped! */
  124. wd33c93_release();
  125. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
  126. free_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr);
  127. #endif
  128. return 1;
  129. }