1 #include <linux/types.h>
 
   3 #include <linux/blkdev.h>
 
   4 #include <linux/sched.h>
 
   5 #include <linux/init.h>
 
   6 #include <linux/interrupt.h>
 
  10 #include <asm/pgtable.h>
 
  11 #include <asm/amigaints.h>
 
  12 #include <asm/amigahw.h>
 
  13 #include <linux/zorro.h>
 
  15 #include <linux/spinlock.h>
 
  18 #include <scsi/scsi_host.h>
 
  22 #include<linux/stat.h>
 
  24 #define DMA(ptr) ((gvp11_scsiregs *)((ptr)->base))
 
  25 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
 
  27 static irqreturn_t gvp11_intr (int irq, void *_instance, struct pt_regs *fp)
 
  31     struct Scsi_Host *instance = (struct Scsi_Host *)_instance;
 
  33     status = DMA(instance)->CNTR;
 
  34     if (!(status & GVP11_DMAC_INT_PENDING))
 
  37     spin_lock_irqsave(instance->host_lock, flags);
 
  38     wd33c93_intr(instance);
 
  39     spin_unlock_irqrestore(instance->host_lock, flags);
 
  43 static int gvp11_xfer_mask = 0;
 
  45 void gvp11_setup (char *str, int *ints)
 
  47     gvp11_xfer_mask = ints[1];
 
  50 static int dma_setup (Scsi_Cmnd *cmd, int dir_in)
 
  52     unsigned short cntr = GVP11_DMAC_INT_ENABLE;
 
  53     unsigned long addr = virt_to_bus(cmd->SCp.ptr);
 
  55     static int scsi_alloc_out_of_range = 0;
 
  57     /* use bounce buffer if the physical address is bad */
 
  58     if (addr & HDATA(cmd->device->host)->dma_xfer_mask ||
 
  59         (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
 
  61         HDATA(cmd->device->host)->dma_bounce_len = (cmd->SCp.this_residual + 511)
 
  64         if( !scsi_alloc_out_of_range ) {
 
  65             HDATA(cmd->device->host)->dma_bounce_buffer =
 
  66                 kmalloc (HDATA(cmd->device->host)->dma_bounce_len, GFP_KERNEL);
 
  67             HDATA(cmd->device->host)->dma_buffer_pool = BUF_SCSI_ALLOCED;
 
  70         if (scsi_alloc_out_of_range ||
 
  71             !HDATA(cmd->device->host)->dma_bounce_buffer) {
 
  72             HDATA(cmd->device->host)->dma_bounce_buffer =
 
  73                 amiga_chip_alloc(HDATA(cmd->device->host)->dma_bounce_len,
 
  74                                        "GVP II SCSI Bounce Buffer");
 
  76             if(!HDATA(cmd->device->host)->dma_bounce_buffer)
 
  78                 HDATA(cmd->device->host)->dma_bounce_len = 0;
 
  82             HDATA(cmd->device->host)->dma_buffer_pool = BUF_CHIP_ALLOCED;
 
  85         /* check if the address of the bounce buffer is OK */
 
  86         addr = virt_to_bus(HDATA(cmd->device->host)->dma_bounce_buffer);
 
  88         if (addr & HDATA(cmd->device->host)->dma_xfer_mask) {
 
  89             /* fall back to Chip RAM if address out of range */
 
  90             if( HDATA(cmd->device->host)->dma_buffer_pool == BUF_SCSI_ALLOCED) {
 
  91                 kfree (HDATA(cmd->device->host)->dma_bounce_buffer);
 
  92                 scsi_alloc_out_of_range = 1;
 
  94                 amiga_chip_free (HDATA(cmd->device->host)->dma_bounce_buffer);
 
  97             HDATA(cmd->device->host)->dma_bounce_buffer =
 
  98                 amiga_chip_alloc(HDATA(cmd->device->host)->dma_bounce_len,
 
  99                                        "GVP II SCSI Bounce Buffer");
 
 101             if(!HDATA(cmd->device->host)->dma_bounce_buffer)
 
 103                 HDATA(cmd->device->host)->dma_bounce_len = 0;
 
 107             addr = virt_to_bus(HDATA(cmd->device->host)->dma_bounce_buffer);
 
 108             HDATA(cmd->device->host)->dma_buffer_pool = BUF_CHIP_ALLOCED;
 
 112             /* copy to bounce buffer for a write */
 
 113             memcpy (HDATA(cmd->device->host)->dma_bounce_buffer,
 
 114                     cmd->SCp.ptr, cmd->SCp.this_residual);
 
 118     /* setup dma direction */
 
 120         cntr |= GVP11_DMAC_DIR_WRITE;
 
 122     HDATA(cmd->device->host)->dma_dir = dir_in;
 
 123     DMA(cmd->device->host)->CNTR = cntr;
 
 125     /* setup DMA *physical* address */
 
 126     DMA(cmd->device->host)->ACR = addr;
 
 129         /* invalidate any cache */
 
 130         cache_clear (addr, cmd->SCp.this_residual);
 
 132         /* push any dirty cache */
 
 133         cache_push (addr, cmd->SCp.this_residual);
 
 135     if ((bank_mask = (~HDATA(cmd->device->host)->dma_xfer_mask >> 18) & 0x01c0))
 
 136             DMA(cmd->device->host)->BANK = bank_mask & (addr >> 18);
 
 139     DMA(cmd->device->host)->ST_DMA = 1;
 
 145 static void dma_stop (struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
 
 149     DMA(instance)->SP_DMA = 1;
 
 150     /* remove write bit from CONTROL bits */
 
 151     DMA(instance)->CNTR = GVP11_DMAC_INT_ENABLE;
 
 153     /* copy from a bounce buffer, if necessary */
 
 154     if (status && HDATA(instance)->dma_bounce_buffer) {
 
 155         if (HDATA(instance)->dma_dir && SCpnt)
 
 156             memcpy (SCpnt->SCp.ptr, 
 
 157                     HDATA(instance)->dma_bounce_buffer,
 
 158                     SCpnt->SCp.this_residual);
 
 160         if (HDATA(instance)->dma_buffer_pool == BUF_SCSI_ALLOCED)
 
 161             kfree (HDATA(instance)->dma_bounce_buffer);
 
 163             amiga_chip_free(HDATA(instance)->dma_bounce_buffer);
 
 165         HDATA(instance)->dma_bounce_buffer = NULL;
 
 166         HDATA(instance)->dma_bounce_len = 0;
 
 170 #define CHECK_WD33C93
 
 172 int __init gvp11_detect(struct scsi_host_template *tpnt)
 
 174     static unsigned char called = 0;
 
 175     struct Scsi_Host *instance;
 
 176     unsigned long address;
 
 178     struct zorro_dev *z = NULL;
 
 179     unsigned int default_dma_xfer_mask;
 
 183     volatile unsigned char *sasr_3393, *scmd_3393;
 
 184     unsigned char save_sasr;
 
 188     if (!MACH_IS_AMIGA || called)
 
 192     tpnt->proc_name = "GVP11";
 
 193     tpnt->proc_info = &wd33c93_proc_info;
 
 195     while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
 
 197          * This should (hopefully) be the correct way to identify
 
 198          * all the different GVP SCSI controllers (except for the
 
 202         if (z->id == ZORRO_PROD_GVP_COMBO_030_R3_SCSI ||
 
 203             z->id == ZORRO_PROD_GVP_SERIES_II)
 
 204             default_dma_xfer_mask = ~0x00ffffff;
 
 205         else if (z->id == ZORRO_PROD_GVP_GFORCE_030_SCSI ||
 
 206                  z->id == ZORRO_PROD_GVP_A530_SCSI ||
 
 207                  z->id == ZORRO_PROD_GVP_COMBO_030_R4_SCSI)
 
 208             default_dma_xfer_mask = ~0x01ffffff;
 
 209         else if (z->id == ZORRO_PROD_GVP_A1291 ||
 
 210                  z->id == ZORRO_PROD_GVP_GFORCE_040_SCSI_1)
 
 211             default_dma_xfer_mask = ~0x07ffffff;
 
 216          * Rumors state that some GVP ram boards use the same product
 
 217          * code as the SCSI controllers. Therefore if the board-size
 
 218          * is not 64KB we asume it is a ram board and bail out.
 
 220         if (z->resource.end-z->resource.start != 0xffff)
 
 223         address = z->resource.start;
 
 224         if (!request_mem_region(address, 256, "wd33c93"))
 
 230          * These darn GVP boards are a problem - it can be tough to tell
 
 231          * whether or not they include a SCSI controller. This is the
 
 232          * ultimate Yet-Another-GVP-Detection-Hack in that it actually
 
 233          * probes for a WD33c93 chip: If we find one, it's extremely
 
 234          * likely that this card supports SCSI, regardless of Product_
 
 235          * Code, Board_Size, etc. 
 
 238     /* Get pointers to the presumed register locations and save contents */
 
 240         sasr_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SASR);
 
 241         scmd_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SCMD);
 
 242         save_sasr = *sasr_3393;
 
 244     /* First test the AuxStatus Reg */
 
 246         q = *sasr_3393;         /* read it */
 
 247         if (q & 0x08)           /* bit 3 should always be clear */
 
 249         *sasr_3393 = WD_AUXILIARY_STATUS;        /* setup indirect address */
 
 250         if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */
 
 251                 *sasr_3393 = save_sasr; /* Oops - restore this byte */
 
 254         if (*sasr_3393 != q) {  /* should still read the same */
 
 255                 *sasr_3393 = save_sasr; /* Oops - restore this byte */
 
 258         if (*scmd_3393 != q)    /* and so should the image at 0x1f */
 
 262     /* Ok, we probably have a wd33c93, but let's check a few other places
 
 263      * for good measure. Make sure that this works for both 'A and 'B    
 
 267         *sasr_3393 = WD_SCSI_STATUS;
 
 269         *sasr_3393 = WD_SCSI_STATUS;
 
 271         *sasr_3393 = WD_SCSI_STATUS;
 
 273         *sasr_3393 = WD_SCSI_STATUS;
 
 275         if (qq != q)                    /* should be read only */
 
 277         *sasr_3393 = 0x1e;      /* this register is unimplemented */
 
 285         if (qq != q || qq != 0xff)      /* should be read only, all 1's */
 
 287         *sasr_3393 = WD_TIMEOUT_PERIOD;
 
 289         *sasr_3393 = WD_TIMEOUT_PERIOD;
 
 291         *sasr_3393 = WD_TIMEOUT_PERIOD;
 
 293         *sasr_3393 = WD_TIMEOUT_PERIOD;
 
 295         if (qq != (~q & 0xff))          /* should be read/write */
 
 299         instance = scsi_register (tpnt, sizeof (struct WD33C93_hostdata));
 
 302         instance->base = ZTWO_VADDR(address);
 
 303         instance->irq = IRQ_AMIGA_PORTS;
 
 304         instance->unique_id = z->slotaddr;
 
 307                 HDATA(instance)->dma_xfer_mask = gvp11_xfer_mask;
 
 309                 HDATA(instance)->dma_xfer_mask = default_dma_xfer_mask;
 
 312         DMA(instance)->secret2 = 1;
 
 313         DMA(instance)->secret1 = 0;
 
 314         DMA(instance)->secret3 = 15;
 
 315         while (DMA(instance)->CNTR & GVP11_DMAC_BUSY) ;
 
 316         DMA(instance)->CNTR = 0;
 
 318         DMA(instance)->BANK = 0;
 
 320         epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000);
 
 323          * Check for 14MHz SCSI clock
 
 325         regs.SASR = &(DMA(instance)->SASR);
 
 326         regs.SCMD = &(DMA(instance)->SCMD);
 
 327         wd33c93_init(instance, regs, dma_setup, dma_stop,
 
 328                      (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10
 
 331         request_irq(IRQ_AMIGA_PORTS, gvp11_intr, SA_SHIRQ, "GVP11 SCSI",
 
 333         DMA(instance)->CNTR = GVP11_DMAC_INT_ENABLE;
 
 338         release_mem_region(address, 256);
 
 344 static int gvp11_bus_reset(Scsi_Cmnd *cmd)
 
 346         /* FIXME perform bus-specific reset */
 
 348         /* FIXME 2: shouldn't we no-op this function (return
 
 349            FAILED), and fall back to host reset function,
 
 350            wd33c93_host_reset ? */
 
 352         spin_lock_irq(cmd->device->host->host_lock);
 
 353         wd33c93_host_reset(cmd);
 
 354         spin_unlock_irq(cmd->device->host->host_lock);
 
 364 static struct scsi_host_template driver_template = {
 
 365         .proc_name              = "GVP11",
 
 366         .name                   = "GVP Series II SCSI",
 
 367         .detect                 = gvp11_detect,
 
 368         .release                = gvp11_release,
 
 369         .queuecommand           = wd33c93_queuecommand,
 
 370         .eh_abort_handler       = wd33c93_abort,
 
 371         .eh_bus_reset_handler   = gvp11_bus_reset,
 
 372         .eh_host_reset_handler  = wd33c93_host_reset,
 
 373         .can_queue              = CAN_QUEUE,
 
 375         .sg_tablesize           = SG_ALL,
 
 376         .cmd_per_lun            = CMD_PER_LUN,
 
 377         .use_clustering         = DISABLE_CLUSTERING
 
 381 #include "scsi_module.c"
 
 383 int gvp11_release(struct Scsi_Host *instance)
 
 386     DMA(instance)->CNTR = 0;
 
 387     release_mem_region(ZTWO_PADDR(instance->base), 256);
 
 388     free_irq(IRQ_AMIGA_PORTS, instance);
 
 394 MODULE_LICENSE("GPL");