a3000.c revision a8169e6057e9b7dd41c9e3b7a41efebc4bd859c9
1#include <linux/types.h> 2#include <linux/mm.h> 3#include <linux/slab.h> 4#include <linux/blkdev.h> 5#include <linux/ioport.h> 6#include <linux/init.h> 7#include <linux/spinlock.h> 8#include <linux/interrupt.h> 9 10#include <asm/setup.h> 11#include <asm/page.h> 12#include <asm/pgtable.h> 13#include <asm/amigaints.h> 14#include <asm/amigahw.h> 15#include <asm/irq.h> 16 17#include "scsi.h" 18#include <scsi/scsi_host.h> 19#include "wd33c93.h" 20#include "a3000.h" 21 22#include <linux/stat.h> 23 24 25static int a3000_release(struct Scsi_Host *instance); 26 27static irqreturn_t a3000_intr(int irq, void *data) 28{ 29 struct Scsi_Host *instance = data; 30 a3000_scsiregs *regs = (a3000_scsiregs *)(instance->base); 31 unsigned int status = regs->ISTR; 32 unsigned long flags; 33 34 if (!(status & ISTR_INT_P)) 35 return IRQ_NONE; 36 if (status & ISTR_INTS) { 37 spin_lock_irqsave(instance->host_lock, flags); 38 wd33c93_intr(instance); 39 spin_unlock_irqrestore(instance->host_lock, flags); 40 return IRQ_HANDLED; 41 } 42 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n", status); 43 return IRQ_NONE; 44} 45 46static int dma_setup(struct scsi_cmnd *cmd, int dir_in) 47{ 48 struct Scsi_Host *instance = cmd->device->host; 49 struct WD33C93_hostdata *hdata = shost_priv(instance); 50 a3000_scsiregs *regs = (a3000_scsiregs *)(instance->base); 51 unsigned short cntr = CNTR_PDMD | CNTR_INTEN; 52 unsigned long addr = virt_to_bus(cmd->SCp.ptr); 53 54 /* 55 * if the physical address has the wrong alignment, or if 56 * physical address is bad, or if it is a write and at the 57 * end of a physical memory chunk, then allocate a bounce 58 * buffer 59 */ 60 if (addr & A3000_XFER_MASK) { 61 hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff; 62 hdata->dma_bounce_buffer = kmalloc(hdata->dma_bounce_len, 63 GFP_KERNEL); 64 65 /* can't allocate memory; use PIO */ 66 if (!hdata->dma_bounce_buffer) { 67 hdata->dma_bounce_len = 0; 68 return 1; 69 } 70 71 if (!dir_in) { 72 /* copy to bounce buffer for a write */ 73 memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr, 74 cmd->SCp.this_residual); 75 } 76 77 addr = virt_to_bus(hdata->dma_bounce_buffer); 78 } 79 80 /* setup dma direction */ 81 if (!dir_in) 82 cntr |= CNTR_DDIR; 83 84 /* remember direction */ 85 hdata->dma_dir = dir_in; 86 87 regs->CNTR = cntr; 88 89 /* setup DMA *physical* address */ 90 regs->ACR = addr; 91 92 if (dir_in) { 93 /* invalidate any cache */ 94 cache_clear(addr, cmd->SCp.this_residual); 95 } else { 96 /* push any dirty cache */ 97 cache_push(addr, cmd->SCp.this_residual); 98 } 99 100 /* start DMA */ 101 mb(); /* make sure setup is completed */ 102 regs->ST_DMA = 1; 103 mb(); /* make sure DMA has started before next IO */ 104 105 /* return success */ 106 return 0; 107} 108 109static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, 110 int status) 111{ 112 struct WD33C93_hostdata *hdata = shost_priv(instance); 113 a3000_scsiregs *regs = (a3000_scsiregs *)(instance->base); 114 115 /* disable SCSI interrupts */ 116 unsigned short cntr = CNTR_PDMD; 117 118 if (!hdata->dma_dir) 119 cntr |= CNTR_DDIR; 120 121 regs->CNTR = cntr; 122 mb(); /* make sure CNTR is updated before next IO */ 123 124 /* flush if we were reading */ 125 if (hdata->dma_dir) { 126 regs->FLUSH = 1; 127 mb(); /* don't allow prefetch */ 128 while (!(regs->ISTR & ISTR_FE_FLG)) 129 barrier(); 130 mb(); /* no IO until FLUSH is done */ 131 } 132 133 /* clear a possible interrupt */ 134 /* I think that this CINT is only necessary if you are 135 * using the terminal count features. HM 7 Mar 1994 136 */ 137 regs->CINT = 1; 138 139 /* stop DMA */ 140 regs->SP_DMA = 1; 141 mb(); /* make sure DMA is stopped before next IO */ 142 143 /* restore the CONTROL bits (minus the direction flag) */ 144 regs->CNTR = CNTR_PDMD | CNTR_INTEN; 145 mb(); /* make sure CNTR is updated before next IO */ 146 147 /* copy from a bounce buffer, if necessary */ 148 if (status && hdata->dma_bounce_buffer) { 149 if (SCpnt) { 150 if (hdata->dma_dir && SCpnt) 151 memcpy(SCpnt->SCp.ptr, 152 hdata->dma_bounce_buffer, 153 SCpnt->SCp.this_residual); 154 kfree(hdata->dma_bounce_buffer); 155 hdata->dma_bounce_buffer = NULL; 156 hdata->dma_bounce_len = 0; 157 } else { 158 kfree(hdata->dma_bounce_buffer); 159 hdata->dma_bounce_buffer = NULL; 160 hdata->dma_bounce_len = 0; 161 } 162 } 163} 164 165static int __init a3000_detect(struct scsi_host_template *tpnt) 166{ 167 struct Scsi_Host *instance; 168 wd33c93_regs wdregs; 169 a3000_scsiregs *regs; 170 struct WD33C93_hostdata *hdata; 171 172 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(A3000_SCSI)) 173 return 0; 174 if (!request_mem_region(0xDD0000, 256, "wd33c93")) 175 return 0; 176 177 tpnt->proc_name = "A3000"; 178 tpnt->proc_info = &wd33c93_proc_info; 179 180 instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata)); 181 if (instance == NULL) 182 goto fail_register; 183 184 instance->base = ZTWO_VADDR(0xDD0000); 185 instance->irq = IRQ_AMIGA_PORTS; 186 regs = (a3000_scsiregs *)(instance->base); 187 regs->DAWR = DAWR_A3000; 188 wdregs.SASR = ®s->SASR; 189 wdregs.SCMD = ®s->SCMD; 190 hdata = shost_priv(instance); 191 hdata->no_sync = 0xff; 192 hdata->fast = 0; 193 hdata->dma_mode = CTRL_DMA; 194 wd33c93_init(instance, wdregs, dma_setup, dma_stop, WD33C93_FS_12_15); 195 if (request_irq(IRQ_AMIGA_PORTS, a3000_intr, IRQF_SHARED, "A3000 SCSI", 196 instance)) 197 goto fail_irq; 198 regs->CNTR = CNTR_PDMD | CNTR_INTEN; 199 200 return 1; 201 202fail_irq: 203 scsi_unregister(instance); 204fail_register: 205 release_mem_region(0xDD0000, 256); 206 return 0; 207} 208 209static int a3000_bus_reset(struct scsi_cmnd *cmd) 210{ 211 /* FIXME perform bus-specific reset */ 212 213 /* FIXME 2: kill this entire function, which should 214 cause mid-layer to call wd33c93_host_reset anyway? */ 215 216 spin_lock_irq(cmd->device->host->host_lock); 217 wd33c93_host_reset(cmd); 218 spin_unlock_irq(cmd->device->host->host_lock); 219 220 return SUCCESS; 221} 222 223#define HOSTS_C 224 225static struct scsi_host_template driver_template = { 226 .proc_name = "A3000", 227 .name = "Amiga 3000 built-in SCSI", 228 .detect = a3000_detect, 229 .release = a3000_release, 230 .queuecommand = wd33c93_queuecommand, 231 .eh_abort_handler = wd33c93_abort, 232 .eh_bus_reset_handler = a3000_bus_reset, 233 .eh_host_reset_handler = wd33c93_host_reset, 234 .can_queue = CAN_QUEUE, 235 .this_id = 7, 236 .sg_tablesize = SG_ALL, 237 .cmd_per_lun = CMD_PER_LUN, 238 .use_clustering = ENABLE_CLUSTERING 239}; 240 241 242#include "scsi_module.c" 243 244static int a3000_release(struct Scsi_Host *instance) 245{ 246 a3000_scsiregs *regs = (a3000_scsiregs *)(instance->base); 247 248 regs->CNTR = 0; 249 release_mem_region(0xDD0000, 256); 250 free_irq(IRQ_AMIGA_PORTS, a3000_intr); 251 return 1; 252} 253 254MODULE_LICENSE("GPL"); 255