mvme147.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include <linux/types.h>
  2. #include <linux/mm.h>
  3. #include <linux/blkdev.h>
  4. #include <linux/sched.h>
  5. #include <linux/version.h>
  6. #include <linux/interrupt.h>
  7. #include <asm/page.h>
  8. #include <asm/pgtable.h>
  9. #include <asm/mvme147hw.h>
  10. #include <asm/irq.h>
  11. #include "scsi.h"
  12. #include <scsi/scsi_host.h>
  13. #include "wd33c93.h"
  14. #include "mvme147.h"
  15. #include<linux/stat.h>
  16. #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
  17. static struct Scsi_Host *mvme147_host = NULL;
  18. static irqreturn_t mvme147_intr (int irq, void *dummy, struct pt_regs *fp)
  19. {
  20. if (irq == MVME147_IRQ_SCSI_PORT)
  21. wd33c93_intr (mvme147_host);
  22. else
  23. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  24. return IRQ_HANDLED;
  25. }
  26. static int dma_setup (Scsi_Cmnd *cmd, int dir_in)
  27. {
  28. unsigned char flags = 0x01;
  29. unsigned long addr = virt_to_bus(cmd->SCp.ptr);
  30. /* setup dma direction */
  31. if (!dir_in)
  32. flags |= 0x04;
  33. /* remember direction */
  34. HDATA(mvme147_host)->dma_dir = dir_in;
  35. if (dir_in)
  36. /* invalidate any cache */
  37. cache_clear (addr, cmd->SCp.this_residual);
  38. else
  39. /* push any dirty cache */
  40. cache_push (addr, cmd->SCp.this_residual);
  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, Scsi_Cmnd *SCpnt,
  49. int status)
  50. {
  51. m147_pcc->dma_cntrl = 0;
  52. }
  53. int mvme147_detect(Scsi_Host_Template *tpnt)
  54. {
  55. static unsigned char called = 0;
  56. wd33c93_regs regs;
  57. if (!MACH_IS_MVME147 || called)
  58. return 0;
  59. called++;
  60. tpnt->proc_name = "MVME147";
  61. tpnt->proc_info = &wd33c93_proc_info;
  62. mvme147_host = scsi_register (tpnt, sizeof(struct WD33C93_hostdata));
  63. if (!mvme147_host)
  64. goto err_out;
  65. mvme147_host->base = 0xfffe4000;
  66. mvme147_host->irq = MVME147_IRQ_SCSI_PORT;
  67. regs.SASR = (volatile unsigned char *)0xfffe4000;
  68. regs.SCMD = (volatile unsigned char *)0xfffe4001;
  69. wd33c93_init(mvme147_host, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
  70. if (request_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr, 0, "MVME147 SCSI PORT", mvme147_intr))
  71. goto err_unregister;
  72. if (request_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr, 0, "MVME147 SCSI DMA", mvme147_intr))
  73. goto err_free_irq;
  74. #if 0 /* Disabled; causes problems booting */
  75. m147_pcc->scsi_interrupt = 0x10; /* Assert SCSI bus reset */
  76. udelay(100);
  77. m147_pcc->scsi_interrupt = 0x00; /* Negate SCSI bus reset */
  78. udelay(2000);
  79. m147_pcc->scsi_interrupt = 0x40; /* Clear bus reset interrupt */
  80. #endif
  81. m147_pcc->scsi_interrupt = 0x09; /* Enable interrupt */
  82. m147_pcc->dma_cntrl = 0x00; /* ensure DMA is stopped */
  83. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  84. return 1;
  85. err_free_irq:
  86. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
  87. err_unregister:
  88. wd33c93_release();
  89. scsi_unregister(mvme147_host);
  90. err_out:
  91. return 0;
  92. }
  93. static int mvme147_bus_reset(Scsi_Cmnd *cmd)
  94. {
  95. /* FIXME perform bus-specific reset */
  96. /* FIXME 2: kill this function, and let midlayer fallback to
  97. the same result, calling wd33c93_host_reset() */
  98. spin_lock_irq(cmd->device->host->host_lock);
  99. wd33c93_host_reset(cmd);
  100. spin_unlock_irq(cmd->device->host->host_lock);
  101. return SUCCESS;
  102. }
  103. #define HOSTS_C
  104. #include "mvme147.h"
  105. static Scsi_Host_Template driver_template = {
  106. .proc_name = "MVME147",
  107. .name = "MVME147 built-in SCSI",
  108. .detect = mvme147_detect,
  109. .release = mvme147_release,
  110. .queuecommand = wd33c93_queuecommand,
  111. .eh_abort_handler = wd33c93_abort,
  112. .eh_bus_reset_handler = mvme147_bus_reset,
  113. .eh_host_reset_handler = wd33c93_host_reset,
  114. .can_queue = CAN_QUEUE,
  115. .this_id = 7,
  116. .sg_tablesize = SG_ALL,
  117. .cmd_per_lun = CMD_PER_LUN,
  118. .use_clustering = ENABLE_CLUSTERING
  119. };
  120. #include "scsi_module.c"
  121. int mvme147_release(struct Scsi_Host *instance)
  122. {
  123. #ifdef MODULE
  124. /* XXX Make sure DMA is stopped! */
  125. wd33c93_release();
  126. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
  127. free_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr);
  128. #endif
  129. return 1;
  130. }