1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93#define NCR_D700_VERSION "2.2"
94
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>
106
107#include "53c700.h"
108#include "NCR_D700.h"
109
110static char *NCR_D700;
111
112MODULE_AUTHOR("James Bottomley");
113MODULE_DESCRIPTION("NCR Dual700 SCSI Driver");
114MODULE_LICENSE("GPL");
115module_param(NCR_D700, charp, 0);
116
117static __u8 id_array[2*(MCA_MAX_SLOT_NR + 1)] =
118 { [0 ... 2*(MCA_MAX_SLOT_NR + 1)-1] = 7 };
119
120#ifdef MODULE
121#define ARG_SEP ' '
122#else
123#define ARG_SEP ','
124#endif
125
126static int __init
127param_setup(char *string)
128{
129 char *pos = string, *next;
130 int slot = -1, siop = -1;
131
132 while(pos != NULL && (next = strchr(pos, ':')) != NULL) {
133 int val = (int)simple_strtoul(++next, NULL, 0);
134
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;
150 }
151 }
152 }
153 if((pos = strchr(pos, ARG_SEP)) != NULL)
154 pos++;
155 }
156 return 1;
157}
158
159
160
161static 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,
166};
167
168
169struct NCR_D700_private {
170 struct device *dev;
171 struct Scsi_Host *hosts[2];
172 char name[30];
173 char pad;
174};
175
176static int
177NCR_D700_probe_one(struct NCR_D700_private *p, int siop, int irq,
178 int slot, u32 region, int differential)
179{
180 struct NCR_700_Host_Parameters *hostdata;
181 struct Scsi_Host *host;
182 int ret;
183
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;
189 }
190
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;
196 }
197
198
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;
203
204
205 host = NCR_700_detect(&NCR_D700_driver_template, hostdata, p->dev);
206 if (!host) {
207 ret = -ENOMEM;
208 goto detect_failed;
209 }
210
211 p->hosts[siop] = host;
212
213 host->this_id = id_array[slot * 2 + siop];
214 host->irq = irq;
215 host->base = region;
216 scsi_scan_host(host);
217
218 return 0;
219
220 detect_failed:
221 release_region(region, 64);
222 region_failed:
223 kfree(hostdata);
224
225 return ret;
226}
227
228static irqreturn_t
229NCR_D700_intr(int irq, void *data)
230{
231 struct NCR_D700_private *p = (struct NCR_D700_private *)data;
232 int i, found = 0;
233
234 for (i = 0; i < 2; i++)
235 if (p->hosts[i] &&
236 NCR_700_intr(irq, p->hosts[i]) == IRQ_HANDLED)
237 found++;
238
239 return found ? IRQ_HANDLED : IRQ_NONE;
240}
241
242
243
244
245
246static int
247NCR_D700_probe(struct device *dev)
248{
249 struct NCR_D700_private *p;
250 int differential;
251 static int banner = 1;
252 struct mca_device *mca_dev = to_mca_device(dev);
253 int slot = mca_dev->slot;
254 int found = 0;
255 int irq, i;
256 int pos3j, pos3k, pos3a, pos3b, pos4;
257 __u32 base_addr, offset_addr;
258
259
260 pos4 = mca_device_read_pos(mca_dev, 4);
261 pos4 |= 0x4;
262 mca_device_write_pos(mca_dev, 4, pos4);
263
264 mca_device_write_pos(mca_dev, 6, 9);
265 pos3j = mca_device_read_pos(mca_dev, 3);
266 mca_device_write_pos(mca_dev, 6, 10);
267 pos3k = mca_device_read_pos(mca_dev, 3);
268 mca_device_write_pos(mca_dev, 6, 0);
269 pos3a = mca_device_read_pos(mca_dev, 3);
270 mca_device_write_pos(mca_dev, 6, 1);
271 pos3b = mca_device_read_pos(mca_dev, 3);
272
273 base_addr = ((pos3j << 8) | pos3k) & 0xfffffff0;
274 offset_addr = ((pos3a << 8) | pos3b) & 0xffffff70;
275
276 irq = (pos4 & 0x3) + 11;
277 if(irq >= 13)
278 irq++;
279 if(banner) {
280 printk(KERN_NOTICE "NCR D700: Driver Version " NCR_D700_VERSION "\n"
281 "NCR D700: Copyright (c) 2001 by James.Bottomley@HansenPartnership.com\n"
282 "NCR D700:\n");
283 banner = 0;
284 }
285
286 irq = mca_device_transform_irq(mca_dev, irq);
287 base_addr = mca_device_transform_ioport(mca_dev, base_addr);
288 offset_addr = mca_device_transform_ioport(mca_dev, offset_addr);
289
290 printk(KERN_NOTICE "NCR D700: found in slot %d irq = %d I/O base = 0x%x\n", slot, irq, offset_addr);
291
292
293
294
295 (void)inb(base_addr + 0x08);
296
297 switch(differential = (inb(base_addr + 0x08) >> 6)) {
298 case 0x00:
299
300 differential = 0x02;
301 break;
302 case 0x01:
303
304 differential = 0x03;
305 break;
306 case 0x03:
307
308 differential = 0x00;
309 break;
310 default:
311 printk(KERN_ERR "D700: UNEXPECTED DIFFERENTIAL RESULT 0x%02x\n",
312 differential);
313 differential = 0x00;
314 break;
315 }
316
317 p = kzalloc(sizeof(*p), GFP_KERNEL);
318 if (!p)
319 return -ENOMEM;
320
321 p->dev = dev;
322 snprintf(p->name, sizeof(p->name), "D700(%s)", dev_name(dev));
323 if (request_irq(irq, NCR_D700_intr, IRQF_SHARED, p->name, p)) {
324 printk(KERN_ERR "D700: request_irq failed\n");
325 kfree(p);
326 return -EBUSY;
327 }
328
329 for (i = 0; i < 2; i++) {
330 int err;
331
332 if ((err = NCR_D700_probe_one(p, i, irq, slot,
333 offset_addr + (0x80 * i),
334 differential)) != 0)
335 printk("D700: SIOP%d: probe failed, error = %d\n",
336 i, err);
337 else
338 found++;
339 }
340
341 if (!found) {
342 kfree(p);
343 return -ENODEV;
344 }
345
346 mca_device_set_claim(mca_dev, 1);
347 mca_device_set_name(mca_dev, "NCR_D700");
348 dev_set_drvdata(dev, p);
349 return 0;
350}
351
352static void
353NCR_D700_remove_one(struct Scsi_Host *host)
354{
355 scsi_remove_host(host);
356 NCR_700_release(host);
357 kfree((struct NCR_700_Host_Parameters *)host->hostdata[0]);
358 free_irq(host->irq, host);
359 release_region(host->base, 64);
360}
361
362static int
363NCR_D700_remove(struct device *dev)
364{
365 struct NCR_D700_private *p = dev_get_drvdata(dev);
366 int i;
367
368 for (i = 0; i < 2; i++)
369 NCR_D700_remove_one(p->hosts[i]);
370
371 kfree(p);
372 return 0;
373}
374
375static short NCR_D700_id_table[] = { NCR_D700_MCA_ID, 0 };
376
377static struct mca_driver NCR_D700_driver = {
378 .id_table = NCR_D700_id_table,
379 .driver = {
380 .name = "NCR_D700",
381 .bus = &mca_bus_type,
382 .probe = NCR_D700_probe,
383 .remove = NCR_D700_remove,
384 },
385};
386
387static int __init NCR_D700_init(void)
388{
389#ifdef MODULE
390 if (NCR_D700)
391 param_setup(NCR_D700);
392#endif
393
394 return mca_register_driver(&NCR_D700_driver);
395}
396
397static void __exit NCR_D700_exit(void)
398{
399 mca_unregister_driver(&NCR_D700_driver);
400}
401
402module_init(NCR_D700_init);
403module_exit(NCR_D700_exit);
404
405__setup("NCR_D700=", param_setup);
406