Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * linux/drivers/scsi/arm/arxescsi.c
0004  *
0005  * Copyright (C) 1997-2000 Russell King, Stefan Hanske
0006  *
0007  * This driver is based on experimentation.  Hence, it may have made
0008  * assumptions about the particular card that I have available, and
0009  * may not be reliable!
0010  *
0011  * Changelog:
0012  *  30-08-1997  RMK 0.0.0   Created, READONLY version as cumana_2.c
0013  *  22-01-1998  RMK 0.0.1   Updated to 2.1.80
0014  *  15-04-1998  RMK 0.0.1   Only do PIO if FAS216 will allow it.
0015  *  11-06-1998  SH  0.0.2   Changed to support ARXE 16-bit SCSI card
0016  *              enabled writing
0017  *  01-01-2000  SH  0.1.0   Added *real* pseudo dma writing
0018  *              (arxescsi_pseudo_dma_write)
0019  *  02-04-2000  RMK 0.1.1   Updated for new error handling code.
0020  *  22-10-2000  SH      Updated for new registering scheme.
0021  */
0022 #include <linux/module.h>
0023 #include <linux/blkdev.h>
0024 #include <linux/kernel.h>
0025 #include <linux/string.h>
0026 #include <linux/ioport.h>
0027 #include <linux/proc_fs.h>
0028 #include <linux/unistd.h>
0029 #include <linux/stat.h>
0030 #include <linux/delay.h>
0031 #include <linux/init.h>
0032 #include <linux/interrupt.h>
0033 
0034 #include <asm/dma.h>
0035 #include <asm/io.h>
0036 #include <asm/ecard.h>
0037 
0038 #include <scsi/scsi.h>
0039 #include <scsi/scsi_cmnd.h>
0040 #include <scsi/scsi_device.h>
0041 #include <scsi/scsi_eh.h>
0042 #include <scsi/scsi_host.h>
0043 #include <scsi/scsi_tcq.h>
0044 #include "fas216.h"
0045 
0046 struct arxescsi_info {
0047     FAS216_Info     info;
0048     struct expansion_card   *ec;
0049     void __iomem        *base;
0050 };
0051 
0052 #define DMADATA_OFFSET  (0x200)
0053 
0054 #define DMASTAT_OFFSET  (0x600)
0055 #define DMASTAT_DRQ (1 << 0)
0056 
0057 #define CSTATUS_IRQ (1 << 0)
0058 
0059 #define VERSION "1.10 (23/01/2003 2.5.57)"
0060 
0061 /*
0062  * Function: int arxescsi_dma_setup(host, SCpnt, direction, min_type)
0063  * Purpose : initialises DMA/PIO
0064  * Params  : host      - host
0065  *       SCpnt     - command
0066  *       direction - DMA on to/off of card
0067  *       min_type  - minimum DMA support that we must have for this transfer
0068  * Returns : 0 if we should not set CMD_WITHDMA for transfer info command
0069  */
0070 static fasdmatype_t
0071 arxescsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
0072                fasdmadir_t direction, fasdmatype_t min_type)
0073 {
0074     /*
0075      * We don't do real DMA
0076      */
0077     return fasdma_pseudo;
0078 }
0079 
0080 static void arxescsi_pseudo_dma_write(unsigned char *addr, void __iomem *base)
0081 {
0082        __asm__ __volatile__(
0083        "               stmdb   sp!, {r0-r12}\n"
0084        "               mov     r3, %0\n"
0085        "               mov     r1, %1\n"
0086        "               add     r2, r1, #512\n"
0087        "               mov     r4, #256\n"
0088        ".loop_1:       ldmia   r3!, {r6, r8, r10, r12}\n"
0089        "               mov     r5, r6, lsl #16\n"
0090        "               mov     r7, r8, lsl #16\n"
0091        ".loop_2:       ldrb    r0, [r1, #1536]\n"
0092        "               tst     r0, #1\n"
0093        "               beq     .loop_2\n"
0094        "               stmia   r2, {r5-r8}\n\t"
0095        "               mov     r9, r10, lsl #16\n"
0096        "               mov     r11, r12, lsl #16\n"
0097        ".loop_3:       ldrb    r0, [r1, #1536]\n"
0098        "               tst     r0, #1\n"
0099        "               beq     .loop_3\n"
0100        "               stmia   r2, {r9-r12}\n"
0101        "               subs    r4, r4, #16\n"
0102        "               bne     .loop_1\n"
0103        "               ldmia   sp!, {r0-r12}\n"
0104        :
0105        : "r" (addr), "r" (base));
0106 }
0107 
0108 /*
0109  * Function: int arxescsi_dma_pseudo(host, SCpnt, direction, transfer)
0110  * Purpose : handles pseudo DMA
0111  * Params  : host      - host
0112  *       SCpnt     - command
0113  *       direction - DMA on to/off of card
0114  *       transfer  - minimum number of bytes we expect to transfer
0115  */
0116 static void
0117 arxescsi_dma_pseudo(struct Scsi_Host *host, struct scsi_pointer *SCp,
0118             fasdmadir_t direction, int transfer)
0119 {
0120     struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
0121     unsigned int length, error = 0;
0122     void __iomem *base = info->info.scsi.io_base;
0123     unsigned char *addr;
0124 
0125     length = SCp->this_residual;
0126     addr = SCp->ptr;
0127 
0128     if (direction == DMA_OUT) {
0129         unsigned int word;
0130         while (length > 256) {
0131             if (readb(base + 0x80) & STAT_INT) {
0132                 error = 1;
0133                 break;
0134             }
0135             arxescsi_pseudo_dma_write(addr, base);
0136             addr += 256;
0137             length -= 256;
0138         }
0139 
0140         if (!error)
0141             while (length > 0) {
0142                 if (readb(base + 0x80) & STAT_INT)
0143                     break;
0144      
0145                 if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
0146                     continue;
0147 
0148                 word = *addr | *(addr + 1) << 8;
0149 
0150                 writew(word, base + DMADATA_OFFSET);
0151                 if (length > 1) {
0152                     addr += 2;
0153                     length -= 2;
0154                 } else {
0155                     addr += 1;
0156                     length -= 1;
0157                 }
0158             }
0159     }
0160     else {
0161         if (transfer && (transfer & 255)) {
0162             while (length >= 256) {
0163                 if (readb(base + 0x80) & STAT_INT) {
0164                     error = 1;
0165                     break;
0166                 }
0167         
0168                 if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
0169                     continue;
0170 
0171                 readsw(base + DMADATA_OFFSET, addr, 256 >> 1);
0172                 addr += 256;
0173                 length -= 256;
0174             }
0175         }
0176 
0177         if (!(error))
0178             while (length > 0) {
0179                 unsigned long word;
0180 
0181                 if (readb(base + 0x80) & STAT_INT)
0182                     break;
0183 
0184                 if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
0185                     continue;
0186 
0187                 word = readw(base + DMADATA_OFFSET);
0188                 *addr++ = word;
0189                 if (--length > 0) {
0190                     *addr++ = word >> 8;
0191                     length --;
0192                 }
0193             }
0194     }
0195 }
0196 
0197 /*
0198  * Function: int arxescsi_dma_stop(host, SCpnt)
0199  * Purpose : stops DMA/PIO
0200  * Params  : host  - host
0201  *       SCpnt - command
0202  */
0203 static void arxescsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
0204 {
0205     /*
0206      * no DMA to stop
0207      */
0208 }
0209 
0210 /*
0211  * Function: const char *arxescsi_info(struct Scsi_Host * host)
0212  * Purpose : returns a descriptive string about this interface,
0213  * Params  : host - driver host structure to return info for.
0214  * Returns : pointer to a static buffer containing null terminated string.
0215  */
0216 static const char *arxescsi_info(struct Scsi_Host *host)
0217 {
0218     struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
0219     static char string[150];
0220 
0221     sprintf(string, "%s (%s) in slot %d v%s",
0222         host->hostt->name, info->info.scsi.type, info->ec->slot_no,
0223         VERSION);
0224 
0225     return string;
0226 }
0227 
0228 static int
0229 arxescsi_show_info(struct seq_file *m, struct Scsi_Host *host)
0230 {
0231     struct arxescsi_info *info;
0232     info = (struct arxescsi_info *)host->hostdata;
0233 
0234     seq_printf(m, "ARXE 16-bit SCSI driver v%s\n", VERSION);
0235     fas216_print_host(&info->info, m);
0236     fas216_print_stats(&info->info, m);
0237     fas216_print_devices(&info->info, m);
0238     return 0;
0239 }
0240 
0241 static struct scsi_host_template arxescsi_template = {
0242     .show_info          = arxescsi_show_info,
0243     .name               = "ARXE SCSI card",
0244     .info               = arxescsi_info,
0245     .queuecommand           = fas216_noqueue_command,
0246     .eh_host_reset_handler      = fas216_eh_host_reset,
0247     .eh_bus_reset_handler       = fas216_eh_bus_reset,
0248     .eh_device_reset_handler    = fas216_eh_device_reset,
0249     .eh_abort_handler       = fas216_eh_abort,
0250     .cmd_size           = sizeof(struct fas216_cmd_priv),
0251     .can_queue          = 0,
0252     .this_id            = 7,
0253     .sg_tablesize           = SG_ALL,
0254     .dma_boundary           = PAGE_SIZE - 1,
0255     .proc_name          = "arxescsi",
0256 };
0257 
0258 static int arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
0259 {
0260     struct Scsi_Host *host;
0261     struct arxescsi_info *info;
0262     void __iomem *base;
0263     int ret;
0264 
0265     ret = ecard_request_resources(ec);
0266     if (ret)
0267         goto out;
0268 
0269     base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
0270     if (!base) {
0271         ret = -ENOMEM;
0272         goto out_region;
0273     }
0274 
0275     host = scsi_host_alloc(&arxescsi_template, sizeof(struct arxescsi_info));
0276     if (!host) {
0277         ret = -ENOMEM;
0278         goto out_region;
0279     }
0280 
0281     info = (struct arxescsi_info *)host->hostdata;
0282     info->ec = ec;
0283     info->base = base;
0284 
0285     info->info.scsi.io_base     = base + 0x2000;
0286     info->info.scsi.irq     = 0;
0287     info->info.scsi.dma     = NO_DMA;
0288     info->info.scsi.io_shift    = 5;
0289     info->info.ifcfg.clockrate  = 24; /* MHz */
0290     info->info.ifcfg.select_timeout = 255;
0291     info->info.ifcfg.asyncperiod    = 200; /* ns */
0292     info->info.ifcfg.sync_max_depth = 0;
0293     info->info.ifcfg.cntl3      = CNTL3_FASTSCSI | CNTL3_FASTCLK;
0294     info->info.ifcfg.disconnect_ok  = 0;
0295     info->info.ifcfg.wide_max_size  = 0;
0296     info->info.ifcfg.capabilities   = FASCAP_PSEUDODMA;
0297     info->info.dma.setup        = arxescsi_dma_setup;
0298     info->info.dma.pseudo       = arxescsi_dma_pseudo;
0299     info->info.dma.stop     = arxescsi_dma_stop;
0300         
0301     ec->irqaddr = base;
0302     ec->irqmask = CSTATUS_IRQ;
0303 
0304     ret = fas216_init(host);
0305     if (ret)
0306         goto out_unregister;
0307 
0308     ret = fas216_add(host, &ec->dev);
0309     if (ret == 0)
0310         goto out;
0311 
0312     fas216_release(host);
0313  out_unregister:
0314     scsi_host_put(host);
0315  out_region:
0316     ecard_release_resources(ec);
0317  out:
0318     return ret;
0319 }
0320 
0321 static void arxescsi_remove(struct expansion_card *ec)
0322 {
0323     struct Scsi_Host *host = ecard_get_drvdata(ec);
0324 
0325     ecard_set_drvdata(ec, NULL);
0326     fas216_remove(host);
0327 
0328     fas216_release(host);
0329     scsi_host_put(host);
0330     ecard_release_resources(ec);
0331 }
0332 
0333 static const struct ecard_id arxescsi_cids[] = {
0334     { MANU_ARXE, PROD_ARXE_SCSI },
0335     { 0xffff, 0xffff },
0336 };
0337 
0338 static struct ecard_driver arxescsi_driver = {
0339     .probe      = arxescsi_probe,
0340     .remove     = arxescsi_remove,
0341     .id_table   = arxescsi_cids,
0342     .drv = {
0343         .name       = "arxescsi",
0344     },
0345 };
0346 
0347 static int __init init_arxe_scsi_driver(void)
0348 {
0349     return ecard_register_driver(&arxescsi_driver);
0350 }
0351 
0352 static void __exit exit_arxe_scsi_driver(void)
0353 {
0354     ecard_remove_driver(&arxescsi_driver);
0355 }
0356 
0357 module_init(init_arxe_scsi_driver);
0358 module_exit(exit_arxe_scsi_driver);
0359 
0360 MODULE_AUTHOR("Stefan Hanske");
0361 MODULE_DESCRIPTION("ARXESCSI driver for Acorn machines");
0362 MODULE_LICENSE("GPL");
0363