^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Oak Generic NCR5380 driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 1995-2002, Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/ecard.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define NCR5380_read(reg) readb(hostdata->io + ((reg) << 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define NCR5380_write(reg, value) writeb(value, hostdata->io + ((reg) << 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define NCR5380_dma_xfer_len NCR5380_dma_xfer_none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define NCR5380_dma_recv_setup oakscsi_pread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define NCR5380_dma_send_setup oakscsi_pwrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define NCR5380_dma_residual NCR5380_dma_residual_none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define NCR5380_queue_command oakscsi_queue_command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define NCR5380_info oakscsi_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define NCR5380_implementation_fields /* none */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "../NCR5380.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #undef START_DMA_INITIATOR_RECEIVE_REG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define START_DMA_INITIATOR_RECEIVE_REG (128 + 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define STAT ((128 + 16) << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define DATA ((128 + 8) << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static inline int oakscsi_pwrite(struct NCR5380_hostdata *hostdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unsigned char *addr, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u8 __iomem *base = hostdata->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) printk("writing %p len %d\n",addr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) while(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) while (((status = readw(base + STAT)) & 0x100)==0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static inline int oakscsi_pread(struct NCR5380_hostdata *hostdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned char *addr, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u8 __iomem *base = hostdata->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) printk("reading %p len %d\n", addr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) while(len > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) unsigned int status, timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned long b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) timeout = 0x01FFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) while (((status = readw(base + STAT)) & 0x100)==0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) timeout--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if(status & 0x200 || !timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) printk("status = %08X\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if(len >= 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) readsw(base + DATA, addr, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) addr += 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) len -= 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) b = (unsigned long) readw(base + DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *addr ++ = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) len -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if(len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *addr ++ = b>>8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) len -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #undef STAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #undef DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #include "../NCR5380.c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static struct scsi_host_template oakscsi_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .name = "Oak 16-bit SCSI",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .info = oakscsi_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .queuecommand = oakscsi_queue_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .eh_abort_handler = NCR5380_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .eh_host_reset_handler = NCR5380_host_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .can_queue = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .this_id = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .sg_tablesize = SG_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .cmd_per_lun = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .dma_boundary = PAGE_SIZE - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .proc_name = "oakscsi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .cmd_size = NCR5380_CMD_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .max_sectors = 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) ret = ecard_request_resources(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) priv(host)->io = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ecard_resource_len(ec, ECARD_RES_MEMC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!priv(host)->io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) goto unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) host->irq = NO_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ret = NCR5380_init(host, FLAG_DMA_FIXUP | FLAG_LATE_DMA_SETUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) goto out_unmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) NCR5380_maybe_reset_bus(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ret = scsi_add_host(host, &ec->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) goto out_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) scsi_scan_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) out_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) NCR5380_exit(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) out_unmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) iounmap(priv(host)->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) unreg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ecard_release_resources(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static void oakscsi_remove(struct expansion_card *ec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct Scsi_Host *host = ecard_get_drvdata(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) void __iomem *base = priv(host)->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ecard_set_drvdata(ec, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) scsi_remove_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) NCR5380_exit(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) iounmap(base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ecard_release_resources(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static const struct ecard_id oakscsi_cids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) { MANU_OAK, PROD_OAK_SCSI },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) { 0xffff, 0xffff }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static struct ecard_driver oakscsi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .probe = oakscsi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .remove = oakscsi_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .id_table = oakscsi_cids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) .drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) .name = "oakscsi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int __init oakscsi_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return ecard_register_driver(&oakscsi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void __exit oakscsi_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ecard_remove_driver(&oakscsi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) module_init(oakscsi_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) module_exit(oakscsi_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) MODULE_AUTHOR("Russell King");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) MODULE_DESCRIPTION("Oak SCSI driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)