blob: d95a1d4f4e021167ce50131f0f0735f0603f0a23 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Oak Generic NCR5380 driver
3 *
4 * Copyright 1995-2002, Russell King
5 */
6
7#include <linux/module.h>
8#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/ioport.h>
10#include <linux/delay.h>
11#include <linux/blkdev.h>
12#include <linux/init.h>
13
14#include <asm/ecard.h>
15#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <scsi/scsi_host.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*#define PSEUDO_DMA*/
Arnd Bergmannea065f12012-04-30 16:26:31 +000020#define DONT_USE_INTR
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Russell King8b801ea2007-07-20 10:38:54 +010022#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
Russell King8b801ea2007-07-20 10:38:54 +010023
Finn Thain54d8fe42016-01-03 16:05:06 +110024#define NCR5380_read(reg) \
25 readb(priv(instance)->base + ((reg) << 2))
26#define NCR5380_write(reg, value) \
27 writeb(value, priv(instance)->base + ((reg) << 2))
28
Finn Thainff3d4572016-01-03 16:05:25 +110029#define NCR5380_dma_xfer_len(instance, cmd, phase) (cmd->transfersize)
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#define NCR5380_queue_command oakscsi_queue_command
Finn Thain8c325132014-11-12 16:11:58 +110032#define NCR5380_info oakscsi_info
Al Virodd7ab712013-03-31 01:15:54 -040033#define NCR5380_show_info oakscsi_show_info
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Russell King8b801ea2007-07-20 10:38:54 +010035#define NCR5380_implementation_fields \
36 void __iomem *base
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include "../NCR5380.h"
39
40#undef START_DMA_INITIATOR_RECEIVE_REG
Russell King8b801ea2007-07-20 10:38:54 +010041#define START_DMA_INITIATOR_RECEIVE_REG (128 + 7)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Russell King8b801ea2007-07-20 10:38:54 +010043#define STAT ((128 + 16) << 2)
44#define DATA ((128 + 8) << 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr,
47 int len)
48{
Russell King8b801ea2007-07-20 10:38:54 +010049 void __iomem *base = priv(instance)->base;
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051printk("writing %p len %d\n",addr, len);
52 if(!len) return -1;
53
54 while(1)
55 {
56 int status;
Russell King8b801ea2007-07-20 10:38:54 +010057 while (((status = readw(base + STAT)) & 0x100)==0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 }
59}
60
61static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr,
62 int len)
63{
Russell King8b801ea2007-07-20 10:38:54 +010064 void __iomem *base = priv(instance)->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065printk("reading %p len %d\n", addr, len);
66 while(len > 0)
67 {
Russell King8b801ea2007-07-20 10:38:54 +010068 unsigned int status, timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 unsigned long b;
70
71 timeout = 0x01FFFFFF;
72
Russell King8b801ea2007-07-20 10:38:54 +010073 while (((status = readw(base + STAT)) & 0x100)==0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 {
75 timeout--;
76 if(status & 0x200 || !timeout)
77 {
Russell King8b801ea2007-07-20 10:38:54 +010078 printk("status = %08X\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 return 1;
80 }
81 }
Russell King8b801ea2007-07-20 10:38:54 +010082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if(len >= 128)
84 {
Russell King8b801ea2007-07-20 10:38:54 +010085 readsw(base + DATA, addr, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 addr += 128;
87 len -= 128;
88 }
89 else
90 {
Russell King8b801ea2007-07-20 10:38:54 +010091 b = (unsigned long) readw(base + DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 *addr ++ = b;
93 len -= 1;
94 if(len)
95 *addr ++ = b>>8;
96 len -= 1;
97 }
98 }
99 return 0;
100}
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#undef STAT
Russell King8b801ea2007-07-20 10:38:54 +0100103#undef DATA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105#include "../NCR5380.c"
106
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100107static struct scsi_host_template oakscsi_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 .module = THIS_MODULE,
Al Virodd7ab712013-03-31 01:15:54 -0400109 .show_info = oakscsi_show_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 .name = "Oak 16-bit SCSI",
111 .info = oakscsi_info,
112 .queuecommand = oakscsi_queue_command,
113 .eh_abort_handler = NCR5380_abort,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 .eh_bus_reset_handler = NCR5380_bus_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 .can_queue = 16,
116 .this_id = 7,
117 .sg_tablesize = SG_ALL,
118 .cmd_per_lun = 2,
119 .use_clustering = DISABLE_CLUSTERING,
120 .proc_name = "oakscsi",
121};
122
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800123static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 struct Scsi_Host *host;
126 int ret = -ENOMEM;
127
Russell King8b801ea2007-07-20 10:38:54 +0100128 ret = ecard_request_resources(ec);
129 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 goto out;
131
Russell King8b801ea2007-07-20 10:38:54 +0100132 host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
133 if (!host) {
134 ret = -ENOMEM;
135 goto release;
136 }
137
138 priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
139 ecard_resource_len(ec, ECARD_RES_MEMC));
140 if (!priv(host)->base) {
141 ret = -ENOMEM;
142 goto unreg;
143 }
144
Finn Thain22f5f102014-11-12 16:11:56 +1100145 host->irq = NO_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 host->n_io_port = 255;
147
Finn Thain0ad0eff2016-01-03 16:05:21 +1100148 ret = NCR5380_init(host, 0);
149 if (ret)
150 goto out_unmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Finn Thainb6488f92016-01-03 16:05:08 +1100152 NCR5380_maybe_reset_bus(host);
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 ret = scsi_add_host(host, &ec->dev);
155 if (ret)
Finn Thain0ad0eff2016-01-03 16:05:21 +1100156 goto out_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 scsi_scan_host(host);
159 goto out;
160
Finn Thain0ad0eff2016-01-03 16:05:21 +1100161 out_exit:
162 NCR5380_exit(host);
Russell King8b801ea2007-07-20 10:38:54 +0100163 out_unmap:
164 iounmap(priv(host)->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 unreg:
166 scsi_host_put(host);
Russell King8b801ea2007-07-20 10:38:54 +0100167 release:
168 ecard_release_resources(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 out:
170 return ret;
171}
172
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800173static void oakscsi_remove(struct expansion_card *ec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
175 struct Scsi_Host *host = ecard_get_drvdata(ec);
176
177 ecard_set_drvdata(ec, NULL);
178 scsi_remove_host(host);
179
180 NCR5380_exit(host);
Russell King8b801ea2007-07-20 10:38:54 +0100181 iounmap(priv(host)->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 scsi_host_put(host);
Russell King8b801ea2007-07-20 10:38:54 +0100183 ecard_release_resources(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
186static const struct ecard_id oakscsi_cids[] = {
187 { MANU_OAK, PROD_OAK_SCSI },
188 { 0xffff, 0xffff }
189};
190
191static struct ecard_driver oakscsi_driver = {
192 .probe = oakscsi_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800193 .remove = oakscsi_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 .id_table = oakscsi_cids,
195 .drv = {
196 .name = "oakscsi",
197 },
198};
199
200static int __init oakscsi_init(void)
201{
202 return ecard_register_driver(&oakscsi_driver);
203}
204
205static void __exit oakscsi_exit(void)
206{
207 ecard_remove_driver(&oakscsi_driver);
208}
209
210module_init(oakscsi_init);
211module_exit(oakscsi_exit);
212
213MODULE_AUTHOR("Russell King");
214MODULE_DESCRIPTION("Oak SCSI driver");
215MODULE_LICENSE("GPL");
216