mvme147.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/types.h>
  3. #include <linux/mm.h>
  4. #include <linux/blkdev.h>
  5. #include <linux/interrupt.h>
  6. #include <linux/init.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <asm/page.h>
  10. #include <asm/mvme147hw.h>
  11. #include <asm/irq.h>
  12. #include <scsi/scsi.h>
  13. #include <scsi/scsi_cmnd.h>
  14. #include <scsi/scsi_device.h>
  15. #include <scsi/scsi_eh.h>
  16. #include <scsi/scsi_host.h>
  17. #include <scsi/scsi_tcq.h>
  18. #include "wd33c93.h"
  19. #include "mvme147.h"
  20. static irqreturn_t mvme147_intr(int irq, void *data)
  21. {
  22. struct Scsi_Host *instance = data;
  23. if (irq == MVME147_IRQ_SCSI_PORT)
  24. wd33c93_intr(instance);
  25. else
  26. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  27. return IRQ_HANDLED;
  28. }
  29. static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
  30. {
  31. struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd);
  32. struct Scsi_Host *instance = cmd->device->host;
  33. struct WD33C93_hostdata *hdata = shost_priv(instance);
  34. unsigned char flags = 0x01;
  35. unsigned long addr = virt_to_bus(scsi_pointer->ptr);
  36. /* setup dma direction */
  37. if (!dir_in)
  38. flags |= 0x04;
  39. /* remember direction */
  40. hdata->dma_dir = dir_in;
  41. if (dir_in) {
  42. /* invalidate any cache */
  43. cache_clear(addr, scsi_pointer->this_residual);
  44. } else {
  45. /* push any dirty cache */
  46. cache_push(addr, scsi_pointer->this_residual);
  47. }
  48. /* start DMA */
  49. m147_pcc->dma_bcr = scsi_pointer->this_residual | (1 << 24);
  50. m147_pcc->dma_dadr = addr;
  51. m147_pcc->dma_cntrl = flags;
  52. /* return success */
  53. return 0;
  54. }
  55. static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
  56. int status)
  57. {
  58. m147_pcc->dma_cntrl = 0;
  59. }
  60. static struct scsi_host_template mvme147_host_template = {
  61. .module = THIS_MODULE,
  62. .proc_name = "MVME147",
  63. .name = "MVME147 built-in SCSI",
  64. .queuecommand = wd33c93_queuecommand,
  65. .eh_abort_handler = wd33c93_abort,
  66. .eh_host_reset_handler = wd33c93_host_reset,
  67. .show_info = wd33c93_show_info,
  68. .write_info = wd33c93_write_info,
  69. .can_queue = CAN_QUEUE,
  70. .this_id = 7,
  71. .sg_tablesize = SG_ALL,
  72. .cmd_per_lun = CMD_PER_LUN,
  73. .cmd_size = sizeof(struct scsi_pointer),
  74. };
  75. static struct Scsi_Host *mvme147_shost;
  76. static int __init mvme147_init(void)
  77. {
  78. wd33c93_regs regs;
  79. struct WD33C93_hostdata *hdata;
  80. int error = -ENOMEM;
  81. if (!MACH_IS_MVME147)
  82. return 0;
  83. mvme147_shost = scsi_host_alloc(&mvme147_host_template,
  84. sizeof(struct WD33C93_hostdata));
  85. if (!mvme147_shost)
  86. goto err_out;
  87. mvme147_shost->base = 0xfffe4000;
  88. mvme147_shost->irq = MVME147_IRQ_SCSI_PORT;
  89. regs.SASR = (volatile unsigned char *)0xfffe4000;
  90. regs.SCMD = (volatile unsigned char *)0xfffe4001;
  91. hdata = shost_priv(mvme147_shost);
  92. hdata->no_sync = 0xff;
  93. hdata->fast = 0;
  94. hdata->dma_mode = CTRL_DMA;
  95. wd33c93_init(mvme147_shost, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
  96. error = request_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr, 0,
  97. "MVME147 SCSI PORT", mvme147_shost);
  98. if (error)
  99. goto err_unregister;
  100. error = request_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr, 0,
  101. "MVME147 SCSI DMA", mvme147_shost);
  102. if (error)
  103. goto err_free_irq;
  104. #if 0 /* Disabled; causes problems booting */
  105. m147_pcc->scsi_interrupt = 0x10; /* Assert SCSI bus reset */
  106. udelay(100);
  107. m147_pcc->scsi_interrupt = 0x00; /* Negate SCSI bus reset */
  108. udelay(2000);
  109. m147_pcc->scsi_interrupt = 0x40; /* Clear bus reset interrupt */
  110. #endif
  111. m147_pcc->scsi_interrupt = 0x09; /* Enable interrupt */
  112. m147_pcc->dma_cntrl = 0x00; /* ensure DMA is stopped */
  113. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  114. error = scsi_add_host(mvme147_shost, NULL);
  115. if (error)
  116. goto err_free_irq;
  117. scsi_scan_host(mvme147_shost);
  118. return 0;
  119. err_free_irq:
  120. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_shost);
  121. err_unregister:
  122. scsi_host_put(mvme147_shost);
  123. err_out:
  124. return error;
  125. }
  126. static void __exit mvme147_exit(void)
  127. {
  128. scsi_remove_host(mvme147_shost);
  129. /* XXX Make sure DMA is stopped! */
  130. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_shost);
  131. free_irq(MVME147_IRQ_SCSI_DMA, mvme147_shost);
  132. scsi_host_put(mvme147_shost);
  133. }
  134. module_init(mvme147_init);
  135. module_exit(mvme147_exit);