GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / scsi / NCR_D700.c
blob8f50c2a5935e502ee286a50284f3971072e9c83c
1 /* -*- mode: c; c-basic-offset: 8 -*- */
3 /* NCR Dual 700 MCA SCSI Driver
5 * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
6 **-----------------------------------------------------------------------------
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 2 of the License, or
11 ** (at your option) any later version.
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 **-----------------------------------------------------------------------------
25 /* Notes:
27 * Most of the work is done in the chip specific module, 53c700.o
29 * TODO List:
31 * 1. Extract the SCSI ID from the voyager CMOS table (necessary to
32 * support multi-host environments.
34 * */
37 /* CHANGELOG
39 * Version 2.2
41 * Added mca_set_adapter_name().
43 * Version 2.1
45 * Modularise the driver into a Board piece (this file) and a chip
46 * piece 53c700.[ch] and 53c700.scr, added module options. You can
47 * now specify the scsi id by the parameters
49 * NCR_D700=slot:<n> [siop:<n>] id:<n> ....
51 * They need to be comma separated if compiled into the kernel
53 * Version 2.0
55 * Initial implementation of TCQ (Tag Command Queueing). TCQ is full
56 * featured and uses the clock algorithm to keep track of outstanding
57 * tags and guard against individual tag starvation. Also fixed a bug
58 * in all of the 1.x versions where the D700_data_residue() function
59 * was returning results off by 32 bytes (and thus causing the same 32
60 * bytes to be written twice corrupting the data block). It turns out
61 * the 53c700 only has a 6 bit DBC and DFIFO registers not 7 bit ones
62 * like the 53c710 (The 710 is the only data manual still available,
63 * which I'd been using to program the 700).
65 * Version 1.2
67 * Much improved message handling engine
69 * Version 1.1
71 * Add code to handle selection reasonably correctly. By the time we
72 * get the selection interrupt, we've already responded, but drop off the
73 * bus and hope the selector will go away.
75 * Version 1.0:
77 * Initial release. Fully functional except for procfs and tag
78 * command queueing. Has only been tested on cards with 53c700-66
79 * chips and only single ended. Features are
81 * 1. Synchronous data transfers to offset 8 (limit of 700-66) and
82 * 100ns (10MHz) limit of SCSI-2
84 * 2. Disconnection and reselection
86 * Testing:
88 * I've only really tested this with the 700-66 chip, but have done
89 * soak tests in multi-device environments to verify that
90 * disconnections and reselections are being processed correctly.
91 * */
93 #define NCR_D700_VERSION "2.2"
95 #include <linux/blkdev.h>
96 #include <linux/interrupt.h>
97 #include <linux/kernel.h>
98 #include <linux/module.h>
99 #include <linux/mca.h>
100 #include <linux/slab.h>
101 #include <asm/io.h>
102 #include <scsi/scsi_host.h>
103 #include <scsi/scsi_device.h>
104 #include <scsi/scsi_transport.h>
105 #include <scsi/scsi_transport_spi.h>
107 #include "53c700.h"
108 #include "NCR_D700.h"
110 static char *NCR_D700; /* command line from insmod */
112 MODULE_AUTHOR("James Bottomley");
113 MODULE_DESCRIPTION("NCR Dual700 SCSI Driver");
114 MODULE_LICENSE("GPL");
115 module_param(NCR_D700, charp, 0);
117 static __u8 __devinitdata id_array[2*(MCA_MAX_SLOT_NR + 1)] =
118 { [0 ... 2*(MCA_MAX_SLOT_NR + 1)-1] = 7 };
120 #ifdef MODULE
121 #define ARG_SEP ' '
122 #else
123 #define ARG_SEP ','
124 #endif
126 static int __init
127 param_setup(char *string)
129 char *pos = string, *next;
130 int slot = -1, siop = -1;
132 while(pos != NULL && (next = strchr(pos, ':')) != NULL) {
133 int val = (int)simple_strtoul(++next, NULL, 0);
135 if(!strncmp(pos, "slot:", 5))
136 slot = val;
137 else if(!strncmp(pos, "siop:", 5))
138 siop = val;
139 else if(!strncmp(pos, "id:", 3)) {
140 if(slot == -1) {
141 printk(KERN_WARNING "NCR D700: Must specify slot for id parameter\n");
142 } else if(slot > MCA_MAX_SLOT_NR) {
143 printk(KERN_WARNING "NCR D700: Illegal slot %d for id %d\n", slot, val);
144 } else {
145 if(siop != 0 && siop != 1) {
146 id_array[slot*2] = val;
147 id_array[slot*2 + 1] =val;
148 } else {
149 id_array[slot*2 + siop] = val;
153 if((pos = strchr(pos, ARG_SEP)) != NULL)
154 pos++;
156 return 1;
159 /* Host template. The 53c700 routine NCR_700_detect will
160 * fill in all of the missing routines */
161 static struct scsi_host_template NCR_D700_driver_template = {
162 .module = THIS_MODULE,
163 .name = "NCR Dual 700 MCA",
164 .proc_name = "NCR_D700",
165 .this_id = 7,
168 /* We needs this helper because we have two hosts per struct device */
169 struct NCR_D700_private {
170 struct device *dev;
171 struct Scsi_Host *hosts[2];
172 char name[30];
173 char pad;
176 static int __devinit
177 NCR_D700_probe_one(struct NCR_D700_private *p, int siop, int irq,
178 int slot, u32 region, int differential)
180 struct NCR_700_Host_Parameters *hostdata;
181 struct Scsi_Host *host;
182 int ret;
184 hostdata = kzalloc(sizeof(*hostdata), GFP_KERNEL);
185 if (!hostdata) {
186 printk(KERN_ERR "NCR D700: SIOP%d: Failed to allocate host"
187 "data, detatching\n", siop);
188 return -ENOMEM;
191 if (!request_region(region, 64, "NCR_D700")) {
192 printk(KERN_ERR "NCR D700: Failed to reserve IO region 0x%x\n",
193 region);
194 ret = -ENODEV;
195 goto region_failed;
198 /* Fill in the three required pieces of hostdata */
199 hostdata->base = ioport_map(region, 64);
200 hostdata->differential = (((1<<siop) & differential) != 0);
201 hostdata->clock = NCR_D700_CLOCK_MHZ;
202 hostdata->burst_length = 8;
204 /* and register the siop */
205 host = NCR_700_detect(&NCR_D700_driver_template, hostdata, p->dev);
206 if (!host) {
207 ret = -ENOMEM;
208 goto detect_failed;
211 p->hosts[siop] = host;
212 host->this_id = id_array[slot * 2 + siop];
213 host->irq = irq;
214 host->base = region;
215 scsi_scan_host(host);
217 return 0;
219 detect_failed:
220 release_region(region, 64);
221 region_failed:
222 kfree(hostdata);
224 return ret;
227 static irqreturn_t
228 NCR_D700_intr(int irq, void *data)
230 struct NCR_D700_private *p = (struct NCR_D700_private *)data;
231 int i, found = 0;
233 for (i = 0; i < 2; i++)
234 if (p->hosts[i] &&
235 NCR_700_intr(irq, p->hosts[i]) == IRQ_HANDLED)
236 found++;
238 return found ? IRQ_HANDLED : IRQ_NONE;
241 /* Detect a D700 card. Note, because of the setup --- the chips are
242 * essentially connectecd to the MCA bus independently, it is easier
243 * to set them up as two separate host adapters, rather than one
244 * adapter with two channels */
245 static int __devinit
246 NCR_D700_probe(struct device *dev)
248 struct NCR_D700_private *p;
249 int differential;
250 static int banner = 1;
251 struct mca_device *mca_dev = to_mca_device(dev);
252 int slot = mca_dev->slot;
253 int found = 0;
254 int irq, i;
255 int pos3j, pos3k, pos3a, pos3b, pos4;
256 __u32 base_addr, offset_addr;
258 /* enable board interrupt */
259 pos4 = mca_device_read_pos(mca_dev, 4);
260 pos4 |= 0x4;
261 mca_device_write_pos(mca_dev, 4, pos4);
263 mca_device_write_pos(mca_dev, 6, 9);
264 pos3j = mca_device_read_pos(mca_dev, 3);
265 mca_device_write_pos(mca_dev, 6, 10);
266 pos3k = mca_device_read_pos(mca_dev, 3);
267 mca_device_write_pos(mca_dev, 6, 0);
268 pos3a = mca_device_read_pos(mca_dev, 3);
269 mca_device_write_pos(mca_dev, 6, 1);
270 pos3b = mca_device_read_pos(mca_dev, 3);
272 base_addr = ((pos3j << 8) | pos3k) & 0xfffffff0;
273 offset_addr = ((pos3a << 8) | pos3b) & 0xffffff70;
275 irq = (pos4 & 0x3) + 11;
276 if(irq >= 13)
277 irq++;
278 if(banner) {
279 printk(KERN_NOTICE "NCR D700: Driver Version " NCR_D700_VERSION "\n"
280 "NCR D700: Copyright (c) 2001 by James.Bottomley@HansenPartnership.com\n"
281 "NCR D700:\n");
282 banner = 0;
284 /* now do the bus related transforms */
285 irq = mca_device_transform_irq(mca_dev, irq);
286 base_addr = mca_device_transform_ioport(mca_dev, base_addr);
287 offset_addr = mca_device_transform_ioport(mca_dev, offset_addr);
289 printk(KERN_NOTICE "NCR D700: found in slot %d irq = %d I/O base = 0x%x\n", slot, irq, offset_addr);
291 /*outb(BOARD_RESET, base_addr);*/
293 /* clear any pending interrupts */
294 (void)inb(base_addr + 0x08);
295 /* get modctl, used later for setting diff bits */
296 switch(differential = (inb(base_addr + 0x08) >> 6)) {
297 case 0x00:
298 /* only SIOP1 differential */
299 differential = 0x02;
300 break;
301 case 0x01:
302 /* Both SIOPs differential */
303 differential = 0x03;
304 break;
305 case 0x03:
306 /* No SIOPs differential */
307 differential = 0x00;
308 break;
309 default:
310 printk(KERN_ERR "D700: UNEXPECTED DIFFERENTIAL RESULT 0x%02x\n",
311 differential);
312 differential = 0x00;
313 break;
316 p = kzalloc(sizeof(*p), GFP_KERNEL);
317 if (!p)
318 return -ENOMEM;
320 p->dev = dev;
321 snprintf(p->name, sizeof(p->name), "D700(%s)", dev_name(dev));
322 if (request_irq(irq, NCR_D700_intr, IRQF_SHARED, p->name, p)) {
323 printk(KERN_ERR "D700: request_irq failed\n");
324 kfree(p);
325 return -EBUSY;
327 /* plumb in both 700 chips */
328 for (i = 0; i < 2; i++) {
329 int err;
331 if ((err = NCR_D700_probe_one(p, i, irq, slot,
332 offset_addr + (0x80 * i),
333 differential)) != 0)
334 printk("D700: SIOP%d: probe failed, error = %d\n",
335 i, err);
336 else
337 found++;
340 if (!found) {
341 kfree(p);
342 return -ENODEV;
345 mca_device_set_claim(mca_dev, 1);
346 mca_device_set_name(mca_dev, "NCR_D700");
347 dev_set_drvdata(dev, p);
348 return 0;
351 static void __devexit
352 NCR_D700_remove_one(struct Scsi_Host *host)
354 scsi_remove_host(host);
355 NCR_700_release(host);
356 kfree((struct NCR_700_Host_Parameters *)host->hostdata[0]);
357 free_irq(host->irq, host);
358 release_region(host->base, 64);
361 static int __devexit
362 NCR_D700_remove(struct device *dev)
364 struct NCR_D700_private *p = dev_get_drvdata(dev);
365 int i;
367 for (i = 0; i < 2; i++)
368 NCR_D700_remove_one(p->hosts[i]);
370 kfree(p);
371 return 0;
374 static short NCR_D700_id_table[] = { NCR_D700_MCA_ID, 0 };
376 static struct mca_driver NCR_D700_driver = {
377 .id_table = NCR_D700_id_table,
378 .driver = {
379 .name = "NCR_D700",
380 .bus = &mca_bus_type,
381 .probe = NCR_D700_probe,
382 .remove = __devexit_p(NCR_D700_remove),
386 static int __init NCR_D700_init(void)
388 #ifdef MODULE
389 if (NCR_D700)
390 param_setup(NCR_D700);
391 #endif
393 return mca_register_driver(&NCR_D700_driver);
396 static void __exit NCR_D700_exit(void)
398 mca_unregister_driver(&NCR_D700_driver);
401 module_init(NCR_D700_init);
402 module_exit(NCR_D700_exit);
404 __setup("NCR_D700=", param_setup);