1 /************************************************************************
3 * ICP vortex GmbH: GDT ISA/EISA/PCI Disk Array Controllers *
4 * Intel Corporation: Storage RAID Controllers *
7 * Copyright (C) 1995-06 ICP vortex GmbH, Achim Leubner *
8 * Copyright (C) 2002-04 Intel Corporation *
9 * Copyright (C) 2003-06 Adaptec Inc. *
10 * <achim_leubner@adaptec.com> *
13 * Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com> *
14 * Johannes Dinner <johannes_dinner@adaptec.com> *
16 * This program is free software; you can redistribute it and/or modify *
17 * it under the terms of the GNU General Public License as published *
18 * by the Free Software Foundation; either version 2 of the License, *
19 * or (at your option) any later version. *
21 * This program is distributed in the hope that it will be useful, *
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
24 * GNU General Public License for more details. *
26 * You should have received a copy of the GNU General Public License *
27 * along with this kernel; if not, write to the Free Software *
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
30 * Linux kernel 2.6.x supported *
32 ************************************************************************/
34 /* All GDT Disk Array Controllers are fully supported by this driver.
35 * This includes the PCI/EISA/ISA SCSI Disk Array Controllers and the
36 * PCI Fibre Channel Disk Array Controllers. See gdth.h for a complete
37 * list of all controller types.
39 * If you have one or more GDT3000/3020 EISA controllers with
40 * controller BIOS disabled, you have to set the IRQ values with the
41 * command line option "gdth=irq1,irq2,...", where the irq1,irq2,... are
42 * the IRQ values for the EISA controllers.
44 * After the optional list of IRQ values, other possible
45 * command line options are:
46 * disable:Y disable driver
47 * disable:N enable driver
48 * reserve_mode:0 reserve no drives for the raw service
49 * reserve_mode:1 reserve all not init., removable drives
50 * reserve_mode:2 reserve all not init. drives
51 * reserve_list:h,b,t,l,h,b,t,l,... reserve particular drive(s) with
52 * h- controller no., b- channel no.,
53 * t- target ID, l- LUN
54 * reverse_scan:Y reverse scan order for PCI controllers
55 * reverse_scan:N scan PCI controllers like BIOS
56 * max_ids:x x - target ID count per channel (1..MAXID)
57 * rescan:Y rescan all channels/IDs
58 * rescan:N use all devices found until now
59 * virt_ctr:Y map every channel to a virtual controller
60 * virt_ctr:N use multi channel support
61 * hdr_channel:x x - number of virtual bus for host drives
62 * shared_access:Y disable driver reserve/release protocol to
63 * access a shared resource from several nodes,
64 * appropriate controller firmware required
65 * shared_access:N enable driver reserve/release protocol
66 * probe_eisa_isa:Y scan for EISA/ISA controllers
67 * probe_eisa_isa:N do not scan for EISA/ISA controllers
68 * force_dma32:Y use only 32 bit DMA mode
69 * force_dma32:N use 64 bit DMA mode, if supported
71 * The default values are: "gdth=disable:N,reserve_mode:1,reverse_scan:N,
72 * max_ids:127,rescan:N,virt_ctr:N,hdr_channel:0,
73 * shared_access:Y,probe_eisa_isa:N,force_dma32:N".
74 * Here is another example: "gdth=reserve_list:0,1,2,0,0,1,3,0,rescan:Y".
76 * When loading the gdth driver as a module, the same options are available.
77 * You can set the IRQs with "IRQ=...". However, the syntax to specify the
78 * options changes slightly. You must replace all ',' between options
79 * with ' ' and all ':' with '=' and you must use
80 * '1' in place of 'Y' and '0' in place of 'N'.
82 * Default: "modprobe gdth disable=0 reserve_mode=1 reverse_scan=0
83 * max_ids=127 rescan=0 virt_ctr=0 hdr_channel=0 shared_access=0
84 * probe_eisa_isa=0 force_dma32=0"
85 * The other example: "modprobe gdth reserve_list=0,1,2,0,0,1,3,0 rescan=1".
88 /* The meaning of the Scsi_Pointer members in this driver is as follows:
90 * this_residual: Command priority
91 * buffer: phys. DMA sense buffer
92 * dma_handle: phys. DMA buffer (kernel >= 2.4.0)
93 * buffers_residual: Timeout value
94 * Status: Command status (gdth_do_cmd()), DMA mem. mappings
95 * Message: Additional info (gdth_do_cmd()), DMA direction
96 * have_data_in: Flag for gdth_wait_completion()
97 * sent_command: Opcode special command
98 * phase: Service/parameter/return code special command
102 /* interrupt coalescing */
103 /* #define INT_COAL */
106 #define GDTH_STATISTICS
108 #include <linux/module.h>
110 #include <linux/version.h>
111 #include <linux/kernel.h>
112 #include <linux/types.h>
113 #include <linux/pci.h>
114 #include <linux/string.h>
115 #include <linux/ctype.h>
116 #include <linux/ioport.h>
117 #include <linux/delay.h>
118 #include <linux/interrupt.h>
119 #include <linux/in.h>
120 #include <linux/proc_fs.h>
121 #include <linux/time.h>
122 #include <linux/timer.h>
123 #include <linux/dma-mapping.h>
126 #include <linux/mc146818rtc.h>
128 #include <linux/reboot.h>
131 #include <asm/system.h>
133 #include <asm/uaccess.h>
134 #include <linux/spinlock.h>
135 #include <linux/blkdev.h>
138 #include <scsi/scsi_host.h>
141 static void gdth_delay(int milliseconds);
142 static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs);
143 static irqreturn_t gdth_interrupt(int irq, void *dev_id);
144 static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp);
145 static int gdth_async_event(int hanum);
146 static void gdth_log_event(gdth_evt_data *dvr, char *buffer);
148 static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority);
149 static void gdth_next(int hanum);
150 static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b);
151 static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp);
152 static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
153 ushort idx, gdth_evt_data *evt);
154 static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr);
155 static void gdth_readapp_event(gdth_ha_str *ha, unchar application,
157 static void gdth_clear_events(void);
159 static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
160 char *buffer,ushort count);
161 static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp);
162 static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive);
164 static void gdth_enable_int(int hanum);
165 static int gdth_get_status(unchar *pIStatus,int irq);
166 static int gdth_test_busy(int hanum);
167 static int gdth_get_cmd_index(int hanum);
168 static void gdth_release_event(int hanum);
169 static int gdth_wait(int hanum,int index,ulong32 time);
170 static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
171 ulong64 p2,ulong64 p3);
172 static int gdth_search_drives(int hanum);
173 static int gdth_analyse_hdrive(int hanum, ushort hdrive);
175 static const char *gdth_ctr_name(int hanum);
177 static int gdth_open(struct inode *inode, struct file *filep);
178 static int gdth_close(struct inode *inode, struct file *filep);
179 static int gdth_ioctl(struct inode *inode, struct file *filep,
180 unsigned int cmd, unsigned long arg);
182 static void gdth_flush(int hanum);
183 static int gdth_halt(struct notifier_block *nb, ulong event, void *buf);
184 static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *));
185 static void gdth_scsi_done(struct scsi_cmnd *scp);
187 static int gdth_isa_probe_one(struct scsi_host_template *, ulong32);
190 static int gdth_eisa_probe_one(struct scsi_host_template *, ushort);
193 static int gdth_pci_probe_one(struct scsi_host_template *, gdth_pci_str *, int);
197 static unchar DebugState = DEBUG_GDTH;
200 #define MAX_SERBUF 160
201 static void ser_init(void);
202 static void ser_puts(char *str);
203 static void ser_putc(char c);
204 static int ser_printk(const char *fmt, ...);
205 static char strbuf[MAX_SERBUF+1];
207 #define COM_BASE 0x2f8
209 #define COM_BASE 0x3f8
211 static void ser_init()
213 unsigned port=COM_BASE;
217 /* 19200 Baud, if 9600: outb(12,port) */
227 static void ser_puts(char *str)
232 for (ptr=str;*ptr;++ptr)
236 static void ser_putc(char c)
238 unsigned port=COM_BASE;
240 while ((inb(port+5) & 0x20)==0);
244 while ((inb(port+5) & 0x20)==0);
249 static int ser_printk(const char *fmt, ...)
255 i = vsprintf(strbuf,fmt,args);
261 #define TRACE(a) {if (DebugState==1) {ser_printk a;}}
262 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}}
263 #define TRACE3(a) {if (DebugState!=0) {ser_printk a;}}
265 #else /* !__SERIAL__ */
266 #define TRACE(a) {if (DebugState==1) {printk a;}}
267 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {printk a;}}
268 #define TRACE3(a) {if (DebugState!=0) {printk a;}}
277 #ifdef GDTH_STATISTICS
278 static ulong32 max_rq=0, max_index=0, max_sg=0;
280 static ulong32 max_int_coal=0;
282 static ulong32 act_ints=0, act_ios=0, act_stats=0, act_rq=0;
283 static struct timer_list gdth_timer;
286 #define PTR2USHORT(a) (ushort)(ulong)(a)
287 #define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b)
288 #define INDEX_OK(i,t) ((i)<ARRAY_SIZE(t))
290 #define NUMDATA(a) ( (gdth_num_str *)((a)->hostdata))
291 #define HADATA(a) (&((gdth_ext_str *)((a)->hostdata))->haext)
292 #define CMDDATA(a) (&((gdth_ext_str *)((a)->hostdata))->cmdext)
294 #define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b))
296 #define gdth_readb(addr) readb(addr)
297 #define gdth_readw(addr) readw(addr)
298 #define gdth_readl(addr) readl(addr)
299 #define gdth_writeb(b,addr) writeb((b),(addr))
300 #define gdth_writew(b,addr) writew((b),(addr))
301 #define gdth_writel(b,addr) writel((b),(addr))
304 static unchar gdth_drq_tab[4] = {5,6,7,7}; /* DRQ table */
307 static unchar gdth_irq_tab[6] = {0,10,11,12,14,0}; /* IRQ table */
309 static unchar gdth_polling; /* polling if TRUE */
310 static unchar gdth_from_wait = FALSE; /* gdth_wait() */
311 static int wait_index,wait_hanum; /* gdth_wait() */
312 static int gdth_ctr_count = 0; /* controller count */
313 static int gdth_ctr_vcount = 0; /* virt. ctr. count */
314 static int gdth_ctr_released = 0; /* gdth_release() */
315 static struct Scsi_Host *gdth_ctr_tab[MAXHA]; /* controller table */
316 static struct Scsi_Host *gdth_ctr_vtab[MAXHA*MAXBUS]; /* virt. ctr. table */
317 static unchar gdth_write_through = FALSE; /* write through */
318 static gdth_evt_str ebuffer[MAX_EVENTS]; /* event buffer */
323 #define DIN 1 /* IN data direction */
324 #define DOU 2 /* OUT data direction */
325 #define DNO DIN /* no data transfer */
326 #define DUN DIN /* unknown data direction */
327 static unchar gdth_direction_tab[0x100] = {
328 DNO,DNO,DIN,DIN,DOU,DIN,DIN,DOU,DIN,DUN,DOU,DOU,DUN,DUN,DUN,DIN,
329 DNO,DIN,DIN,DOU,DIN,DOU,DNO,DNO,DOU,DNO,DIN,DNO,DIN,DOU,DNO,DUN,
330 DIN,DUN,DIN,DUN,DOU,DIN,DUN,DUN,DIN,DIN,DOU,DNO,DUN,DIN,DOU,DOU,
331 DOU,DOU,DOU,DNO,DIN,DNO,DNO,DIN,DOU,DOU,DOU,DOU,DIN,DOU,DIN,DOU,
332 DOU,DOU,DIN,DIN,DIN,DNO,DUN,DNO,DNO,DNO,DUN,DNO,DOU,DIN,DUN,DUN,
333 DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DIN,DUN,DUN,DUN,DUN,DUN,
334 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
335 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
336 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,
337 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,
338 DUN,DUN,DUN,DUN,DUN,DNO,DNO,DUN,DIN,DNO,DOU,DUN,DNO,DUN,DOU,DOU,
339 DOU,DOU,DOU,DNO,DUN,DIN,DOU,DIN,DIN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
340 DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
341 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
342 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,
343 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN
346 /* LILO and modprobe/insmod parameters */
347 /* IRQ list for GDT3000/3020 EISA controllers */
348 static int irq[MAXHA] __initdata =
349 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
350 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
351 /* disable driver flag */
352 static int disable __initdata = 0;
354 static int reserve_mode = 1;
356 static int reserve_list[MAX_RES_ARGS] =
357 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
358 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
359 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
360 /* scan order for PCI controllers */
361 static int reverse_scan = 0;
362 /* virtual channel for the host drives */
363 static int hdr_channel = 0;
364 /* max. IDs per channel */
365 static int max_ids = MAXID;
367 static int rescan = 0;
368 /* map channels to virtual controllers */
369 static int virt_ctr = 0;
371 static int shared_access = 1;
372 /* enable support for EISA and ISA controllers */
373 static int probe_eisa_isa = 0;
374 /* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */
375 static int force_dma32 = 0;
377 /* parameters for modprobe/insmod */
378 module_param_array(irq, int, NULL, 0);
379 module_param(disable, int, 0);
380 module_param(reserve_mode, int, 0);
381 module_param_array(reserve_list, int, NULL, 0);
382 module_param(reverse_scan, int, 0);
383 module_param(hdr_channel, int, 0);
384 module_param(max_ids, int, 0);
385 module_param(rescan, int, 0);
386 module_param(virt_ctr, int, 0);
387 module_param(shared_access, int, 0);
388 module_param(probe_eisa_isa, int, 0);
389 module_param(force_dma32, int, 0);
390 MODULE_AUTHOR("Achim Leubner");
391 MODULE_LICENSE("GPL");
393 /* ioctl interface */
394 static const struct file_operations gdth_fops = {
397 .release = gdth_close,
400 #define GDTH_MAGIC 0xc2e7c389 /* I got it from /dev/urandom */
401 #define IS_GDTH_INTERNAL_CMD(scp) (scp->underflow == GDTH_MAGIC)
403 #include "gdth_proc.h"
404 #include "gdth_proc.c"
406 /* notifier block to get a notify on system shutdown/halt/reboot */
407 static struct notifier_block gdth_notifier = {
410 static int notifier_disabled = 0;
412 static void gdth_delay(int milliseconds)
414 if (milliseconds == 0) {
417 mdelay(milliseconds);
421 static void gdth_scsi_done(struct scsi_cmnd *scp)
423 TRACE2(("gdth_scsi_done()\n"));
425 if (IS_GDTH_INTERNAL_CMD(scp))
426 complete((struct completion *)scp->request);
431 int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
432 int timeout, u32 *info)
435 DECLARE_COMPLETION_ONSTACK(wait);
438 scp = kzalloc(sizeof(*scp), GFP_KERNEL);
443 /* use request field to save the ptr. to completion struct. */
444 scp->request = (struct request *)&wait;
445 scp->timeout_per_command = timeout*HZ;
446 scp->request_buffer = gdtcmd;
448 memcpy(scp->cmnd, cmnd, 12);
449 scp->SCp.this_residual = IOCTL_PRI; /* priority */
450 scp->underflow = GDTH_MAGIC;
451 gdth_queuecommand(scp, NULL);
452 wait_for_completion(&wait);
454 rval = scp->SCp.Status;
456 *info = scp->SCp.Message;
461 int gdth_execute(struct Scsi_Host *shost, gdth_cmd_str *gdtcmd, char *cmnd,
462 int timeout, u32 *info)
464 struct scsi_device *sdev = scsi_get_host_dev(shost);
465 int rval = __gdth_execute(sdev, gdtcmd, cmnd, timeout, info);
467 scsi_free_host_dev(sdev);
471 static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs)
473 *cyls = size /HEADS/SECS;
474 if (*cyls <= MAXCYLS) {
477 } else { /* too high for 64*32 */
478 *cyls = size /MEDHEADS/MEDSECS;
479 if (*cyls <= MAXCYLS) {
482 } else { /* too high for 127*63 */
483 *cyls = size /BIGHEADS/BIGSECS;
490 /* controller search and initialization functions */
492 static int __init gdth_search_eisa(ushort eisa_adr)
496 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr));
497 id = inl(eisa_adr+ID0REG);
498 if (id == GDT3A_ID || id == GDT3B_ID) { /* GDT3000A or GDT3000B */
499 if ((inb(eisa_adr+EISAREG) & 8) == 0)
500 return 0; /* not EISA configured */
503 if (id == GDT3_ID) /* GDT3000 */
508 #endif /* CONFIG_EISA */
511 static int __init gdth_search_isa(ulong32 bios_adr)
516 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
517 if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) {
518 id = gdth_readl(addr);
520 if (id == GDT2_ID) /* GDT2000 */
525 #endif /* CONFIG_ISA */
528 static void gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
529 ushort vendor, ushort dev);
531 static int __init gdth_search_pci(gdth_pci_str *pcistr)
535 TRACE(("gdth_search_pci()\n"));
538 for (device = 0; device <= PCI_DEVICE_ID_VORTEX_GDT6555; ++device)
539 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
540 for (device = PCI_DEVICE_ID_VORTEX_GDT6x17RP;
541 device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP; ++device)
542 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
543 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
544 PCI_DEVICE_ID_VORTEX_GDTNEWRX);
545 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
546 PCI_DEVICE_ID_VORTEX_GDTNEWRX2);
547 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
548 PCI_DEVICE_ID_INTEL_SRC);
549 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
550 PCI_DEVICE_ID_INTEL_SRC_XSCALE);
554 /* Vortex only makes RAID controllers.
555 * We do not really want to specify all 550 ids here, so wildcard match.
557 static struct pci_device_id gdthtable[] __maybe_unused = {
558 {PCI_VENDOR_ID_VORTEX,PCI_ANY_ID,PCI_ANY_ID, PCI_ANY_ID},
559 {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC,PCI_ANY_ID,PCI_ANY_ID},
560 {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC_XSCALE,PCI_ANY_ID,PCI_ANY_ID},
563 MODULE_DEVICE_TABLE(pci,gdthtable);
565 static void __init gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
566 ushort vendor, ushort device)
568 ulong base0, base1, base2;
569 struct pci_dev *pdev;
571 TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
572 *cnt, vendor, device));
575 while ((pdev = pci_find_device(vendor, device, pdev))
577 if (pci_enable_device(pdev))
581 /* GDT PCI controller found, resources are already in pdev */
582 pcistr[*cnt].pdev = pdev;
583 pcistr[*cnt].irq = pdev->irq;
584 base0 = pci_resource_flags(pdev, 0);
585 base1 = pci_resource_flags(pdev, 1);
586 base2 = pci_resource_flags(pdev, 2);
587 if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
588 device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
589 if (!(base0 & IORESOURCE_MEM))
591 pcistr[*cnt].dpmem = pci_resource_start(pdev, 0);
592 } else { /* GDT6110, GDT6120, .. */
593 if (!(base0 & IORESOURCE_MEM) ||
594 !(base2 & IORESOURCE_MEM) ||
595 !(base1 & IORESOURCE_IO))
597 pcistr[*cnt].dpmem = pci_resource_start(pdev, 2);
598 pcistr[*cnt].io_mm = pci_resource_start(pdev, 0);
599 pcistr[*cnt].io = pci_resource_start(pdev, 1);
601 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
602 pcistr[*cnt].pdev->bus->number,
603 PCI_SLOT(pcistr[*cnt].pdev->devfn),
604 pcistr[*cnt].irq, pcistr[*cnt].dpmem));
609 static void __init gdth_sort_pci(gdth_pci_str *pcistr, int cnt)
614 TRACE(("gdth_sort_pci() cnt %d\n",cnt));
620 for (i = 0; i < cnt-1; ++i) {
622 if ((pcistr[i].pdev->bus->number > pcistr[i+1].pdev->bus->number) ||
623 (pcistr[i].pdev->bus->number == pcistr[i+1].pdev->bus->number &&
624 PCI_SLOT(pcistr[i].pdev->devfn) >
625 PCI_SLOT(pcistr[i+1].pdev->devfn))) {
627 pcistr[i] = pcistr[i+1];
632 if ((pcistr[i].pdev->bus->number < pcistr[i+1].pdev->bus->number) ||
633 (pcistr[i].pdev->bus->number == pcistr[i+1].pdev->bus->number &&
634 PCI_SLOT(pcistr[i].pdev->devfn) <
635 PCI_SLOT(pcistr[i+1].pdev->devfn))) {
637 pcistr[i] = pcistr[i+1];
645 #endif /* CONFIG_PCI */
648 static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha)
651 unchar prot_ver,eisacf,i,irq_found;
653 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr));
655 /* disable board interrupts, deinitialize services */
656 outb(0xff,eisa_adr+EDOORREG);
657 outb(0x00,eisa_adr+EDENABREG);
658 outb(0x00,eisa_adr+EINTENABREG);
660 outb(0xff,eisa_adr+LDOORREG);
661 retries = INIT_RETRIES;
663 while (inb(eisa_adr+EDOORREG) != 0xff) {
664 if (--retries == 0) {
665 printk("GDT-EISA: Initialization error (DEINIT failed)\n");
669 TRACE2(("wait for DEINIT: retries=%d\n",retries));
671 prot_ver = inb(eisa_adr+MAILBOXREG);
672 outb(0xff,eisa_adr+EDOORREG);
673 if (prot_ver != PROTOCOL_VERSION) {
674 printk("GDT-EISA: Illegal protocol version\n");
678 ha->brd_phys = (ulong32)eisa_adr >> 12;
680 outl(0,eisa_adr+MAILBOXREG);
681 outl(0,eisa_adr+MAILBOXREG+4);
682 outl(0,eisa_adr+MAILBOXREG+8);
683 outl(0,eisa_adr+MAILBOXREG+12);
686 if ((id = inl(eisa_adr+ID0REG)) == GDT3_ID) {
687 ha->oem_id = OEM_ID_ICP;
690 outl(1,eisa_adr+MAILBOXREG+8);
691 outb(0xfe,eisa_adr+LDOORREG);
692 retries = INIT_RETRIES;
694 while (inb(eisa_adr+EDOORREG) != 0xfe) {
695 if (--retries == 0) {
696 printk("GDT-EISA: Initialization error (get IRQ failed)\n");
701 ha->irq = inb(eisa_adr+MAILBOXREG);
702 outb(0xff,eisa_adr+EDOORREG);
703 TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq));
704 /* check the result */
706 TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
707 for (i = 0, irq_found = FALSE;
708 i < MAXHA && irq[i] != 0xff; ++i) {
709 if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) {
717 printk("GDT-EISA: Can not detect controller IRQ,\n");
718 printk("Use IRQ setting from command line (IRQ = %d)\n",
721 printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
722 printk("the controller BIOS or use command line parameters\n");
727 eisacf = inb(eisa_adr+EISAREG) & 7;
728 if (eisacf > 4) /* level triggered */
730 ha->irq = gdth_irq_tab[eisacf];
731 ha->oem_id = OEM_ID_ICP;
736 ha->dma64_support = 0;
739 #endif /* CONFIG_EISA */
742 static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
744 register gdt2_dpram_str __iomem *dp2_ptr;
746 unchar irq_drq,prot_ver;
749 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr));
751 ha->brd = ioremap(bios_adr, sizeof(gdt2_dpram_str));
752 if (ha->brd == NULL) {
753 printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
757 gdth_writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
758 /* reset interface area */
759 memset_io(&dp2_ptr->u, 0, sizeof(dp2_ptr->u));
760 if (gdth_readl(&dp2_ptr->u) != 0) {
761 printk("GDT-ISA: Initialization error (DPMEM write error)\n");
766 /* disable board interrupts, read DRQ and IRQ */
767 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
768 gdth_writeb(0x00, &dp2_ptr->io.irqen);
769 gdth_writeb(0x00, &dp2_ptr->u.ic.S_Status);
770 gdth_writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
772 irq_drq = gdth_readb(&dp2_ptr->io.rq);
773 for (i=0; i<3; ++i) {
774 if ((irq_drq & 1)==0)
778 ha->drq = gdth_drq_tab[i];
780 irq_drq = gdth_readb(&dp2_ptr->io.rq) >> 3;
781 for (i=1; i<5; ++i) {
782 if ((irq_drq & 1)==0)
786 ha->irq = gdth_irq_tab[i];
788 /* deinitialize services */
789 gdth_writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
790 gdth_writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
791 gdth_writeb(0, &dp2_ptr->io.event);
792 retries = INIT_RETRIES;
794 while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
795 if (--retries == 0) {
796 printk("GDT-ISA: Initialization error (DEINIT failed)\n");
802 prot_ver = (unchar)gdth_readl(&dp2_ptr->u.ic.S_Info[0]);
803 gdth_writeb(0, &dp2_ptr->u.ic.Status);
804 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
805 if (prot_ver != PROTOCOL_VERSION) {
806 printk("GDT-ISA: Illegal protocol version\n");
811 ha->oem_id = OEM_ID_ICP;
813 ha->ic_all_size = sizeof(dp2_ptr->u);
815 ha->brd_phys = bios_adr >> 4;
817 /* special request to controller BIOS */
818 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
819 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
820 gdth_writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
821 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
822 gdth_writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
823 gdth_writeb(0, &dp2_ptr->io.event);
824 retries = INIT_RETRIES;
826 while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
827 if (--retries == 0) {
828 printk("GDT-ISA: Initialization error\n");
834 gdth_writeb(0, &dp2_ptr->u.ic.Status);
835 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
837 ha->dma64_support = 0;
840 #endif /* CONFIG_ISA */
843 static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
845 register gdt6_dpram_str __iomem *dp6_ptr;
846 register gdt6c_dpram_str __iomem *dp6c_ptr;
847 register gdt6m_dpram_str __iomem *dp6m_ptr;
851 int i, found = FALSE;
853 TRACE(("gdth_init_pci()\n"));
855 if (pcistr->pdev->vendor == PCI_VENDOR_ID_INTEL)
856 ha->oem_id = OEM_ID_INTEL;
858 ha->oem_id = OEM_ID_ICP;
859 ha->brd_phys = (pcistr->pdev->bus->number << 8) | (pcistr->pdev->devfn & 0xf8);
860 ha->stype = (ulong32)pcistr->pdev->device;
861 ha->irq = pcistr->irq;
862 ha->pdev = pcistr->pdev;
864 if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */
865 TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
866 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6_dpram_str));
867 if (ha->brd == NULL) {
868 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
871 /* check and reset interface area */
873 gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
874 if (gdth_readl(&dp6_ptr->u) != DPMEM_MAGIC) {
875 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
878 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
880 ha->brd = ioremap(i, sizeof(ushort));
881 if (ha->brd == NULL) {
882 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
885 if (gdth_readw(ha->brd) != 0xffff) {
886 TRACE2(("init_pci_old() address 0x%x busy\n", i));
890 pci_write_config_dword(pcistr->pdev,
891 PCI_BASE_ADDRESS_0, i);
892 ha->brd = ioremap(i, sizeof(gdt6_dpram_str));
893 if (ha->brd == NULL) {
894 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
898 gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
899 if (gdth_readl(&dp6_ptr->u) == DPMEM_MAGIC) {
900 printk("GDT-PCI: Use free address at 0x%x\n", i);
906 printk("GDT-PCI: No free address found!\n");
911 memset_io(&dp6_ptr->u, 0, sizeof(dp6_ptr->u));
912 if (gdth_readl(&dp6_ptr->u) != 0) {
913 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
918 /* disable board interrupts, deinit services */
919 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
920 gdth_writeb(0x00, &dp6_ptr->io.irqen);
921 gdth_writeb(0x00, &dp6_ptr->u.ic.S_Status);
922 gdth_writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
924 gdth_writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
925 gdth_writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
926 gdth_writeb(0, &dp6_ptr->io.event);
927 retries = INIT_RETRIES;
929 while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
930 if (--retries == 0) {
931 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
937 prot_ver = (unchar)gdth_readl(&dp6_ptr->u.ic.S_Info[0]);
938 gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
939 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
940 if (prot_ver != PROTOCOL_VERSION) {
941 printk("GDT-PCI: Illegal protocol version\n");
947 ha->ic_all_size = sizeof(dp6_ptr->u);
949 /* special command to controller BIOS */
950 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
951 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
952 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[2]);
953 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
954 gdth_writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
955 gdth_writeb(0, &dp6_ptr->io.event);
956 retries = INIT_RETRIES;
958 while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
959 if (--retries == 0) {
960 printk("GDT-PCI: Initialization error\n");
966 gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
967 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
969 ha->dma64_support = 0;
971 } else if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */
972 ha->plx = (gdt6c_plx_regs *)pcistr->io;
973 TRACE2(("init_pci_new() dpmem %lx irq %d\n",
974 pcistr->dpmem,ha->irq));
975 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6c_dpram_str));
976 if (ha->brd == NULL) {
977 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
981 /* check and reset interface area */
983 gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
984 if (gdth_readl(&dp6c_ptr->u) != DPMEM_MAGIC) {
985 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
988 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
990 ha->brd = ioremap(i, sizeof(ushort));
991 if (ha->brd == NULL) {
992 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
995 if (gdth_readw(ha->brd) != 0xffff) {
996 TRACE2(("init_pci_plx() address 0x%x busy\n", i));
1000 pci_write_config_dword(pcistr->pdev,
1001 PCI_BASE_ADDRESS_2, i);
1002 ha->brd = ioremap(i, sizeof(gdt6c_dpram_str));
1003 if (ha->brd == NULL) {
1004 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1008 gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
1009 if (gdth_readl(&dp6c_ptr->u) == DPMEM_MAGIC) {
1010 printk("GDT-PCI: Use free address at 0x%x\n", i);
1016 printk("GDT-PCI: No free address found!\n");
1021 memset_io(&dp6c_ptr->u, 0, sizeof(dp6c_ptr->u));
1022 if (gdth_readl(&dp6c_ptr->u) != 0) {
1023 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1028 /* disable board interrupts, deinit services */
1029 outb(0x00,PTR2USHORT(&ha->plx->control1));
1030 outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
1032 gdth_writeb(0x00, &dp6c_ptr->u.ic.S_Status);
1033 gdth_writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
1035 gdth_writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
1036 gdth_writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
1038 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1040 retries = INIT_RETRIES;
1042 while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
1043 if (--retries == 0) {
1044 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1050 prot_ver = (unchar)gdth_readl(&dp6c_ptr->u.ic.S_Info[0]);
1051 gdth_writeb(0, &dp6c_ptr->u.ic.Status);
1052 if (prot_ver != PROTOCOL_VERSION) {
1053 printk("GDT-PCI: Illegal protocol version\n");
1058 ha->type = GDT_PCINEW;
1059 ha->ic_all_size = sizeof(dp6c_ptr->u);
1061 /* special command to controller BIOS */
1062 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
1063 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
1064 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[2]);
1065 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
1066 gdth_writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
1068 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1070 retries = INIT_RETRIES;
1072 while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
1073 if (--retries == 0) {
1074 printk("GDT-PCI: Initialization error\n");
1080 gdth_writeb(0, &dp6c_ptr->u.ic.S_Status);
1082 ha->dma64_support = 0;
1085 TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
1086 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6m_dpram_str));
1087 if (ha->brd == NULL) {
1088 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1092 /* manipulate config. space to enable DPMEM, start RP controller */
1093 pci_read_config_word(pcistr->pdev, PCI_COMMAND, &command);
1095 pci_write_config_word(pcistr->pdev, PCI_COMMAND, command);
1096 if (pci_resource_start(pcistr->pdev, 8) == 1UL)
1097 pci_resource_start(pcistr->pdev, 8) = 0UL;
1099 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS, i);
1101 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS,
1102 pci_resource_start(pcistr->pdev, 8));
1106 /* Ensure that it is safe to access the non HW portions of DPMEM.
1107 * Aditional check needed for Xscale based RAID controllers */
1108 while( ((int)gdth_readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 )
1111 /* check and reset interface area */
1112 gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
1113 if (gdth_readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
1114 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1117 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1119 ha->brd = ioremap(i, sizeof(ushort));
1120 if (ha->brd == NULL) {
1121 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1124 if (gdth_readw(ha->brd) != 0xffff) {
1125 TRACE2(("init_pci_mpr() address 0x%x busy\n", i));
1129 pci_write_config_dword(pcistr->pdev,
1130 PCI_BASE_ADDRESS_0, i);
1131 ha->brd = ioremap(i, sizeof(gdt6m_dpram_str));
1132 if (ha->brd == NULL) {
1133 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1137 gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
1138 if (gdth_readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
1139 printk("GDT-PCI: Use free address at 0x%x\n", i);
1145 printk("GDT-PCI: No free address found!\n");
1150 memset_io(&dp6m_ptr->u, 0, sizeof(dp6m_ptr->u));
1152 /* disable board interrupts, deinit services */
1153 gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
1154 &dp6m_ptr->i960r.edoor_en_reg);
1155 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1156 gdth_writeb(0x00, &dp6m_ptr->u.ic.S_Status);
1157 gdth_writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
1159 gdth_writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
1160 gdth_writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
1161 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1162 retries = INIT_RETRIES;
1164 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
1165 if (--retries == 0) {
1166 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1172 prot_ver = (unchar)gdth_readl(&dp6m_ptr->u.ic.S_Info[0]);
1173 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1174 if (prot_ver != PROTOCOL_VERSION) {
1175 printk("GDT-PCI: Illegal protocol version\n");
1180 ha->type = GDT_PCIMPR;
1181 ha->ic_all_size = sizeof(dp6m_ptr->u);
1183 /* special command to controller BIOS */
1184 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
1185 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
1186 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[2]);
1187 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
1188 gdth_writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
1189 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1190 retries = INIT_RETRIES;
1192 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
1193 if (--retries == 0) {
1194 printk("GDT-PCI: Initialization error\n");
1200 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1202 /* read FW version to detect 64-bit DMA support */
1203 gdth_writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx);
1204 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1205 retries = INIT_RETRIES;
1207 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) {
1208 if (--retries == 0) {
1209 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1215 prot_ver = (unchar)(gdth_readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
1216 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1217 if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */
1218 ha->dma64_support = 0;
1220 ha->dma64_support = 1;
1225 #endif /* CONFIG_PCI */
1227 /* controller protocol functions */
1229 static void __init gdth_enable_int(int hanum)
1233 gdt2_dpram_str __iomem *dp2_ptr;
1234 gdt6_dpram_str __iomem *dp6_ptr;
1235 gdt6m_dpram_str __iomem *dp6m_ptr;
1237 TRACE(("gdth_enable_int() hanum %d\n",hanum));
1238 ha = HADATA(gdth_ctr_tab[hanum]);
1239 spin_lock_irqsave(&ha->smp_lock, flags);
1241 if (ha->type == GDT_EISA) {
1242 outb(0xff, ha->bmic + EDOORREG);
1243 outb(0xff, ha->bmic + EDENABREG);
1244 outb(0x01, ha->bmic + EINTENABREG);
1245 } else if (ha->type == GDT_ISA) {
1247 gdth_writeb(1, &dp2_ptr->io.irqdel);
1248 gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);
1249 gdth_writeb(1, &dp2_ptr->io.irqen);
1250 } else if (ha->type == GDT_PCI) {
1252 gdth_writeb(1, &dp6_ptr->io.irqdel);
1253 gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);
1254 gdth_writeb(1, &dp6_ptr->io.irqen);
1255 } else if (ha->type == GDT_PCINEW) {
1256 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
1257 outb(0x03, PTR2USHORT(&ha->plx->control1));
1258 } else if (ha->type == GDT_PCIMPR) {
1260 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1261 gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
1262 &dp6m_ptr->i960r.edoor_en_reg);
1264 spin_unlock_irqrestore(&ha->smp_lock, flags);
1268 static int gdth_get_status(unchar *pIStatus,int irq)
1270 register gdth_ha_str *ha;
1273 TRACE(("gdth_get_status() irq %d ctr_count %d\n",
1274 irq,gdth_ctr_count));
1277 for (i=0; i<gdth_ctr_count; ++i) {
1278 ha = HADATA(gdth_ctr_tab[i]);
1279 if (ha->irq != (unchar)irq) /* check IRQ */
1281 if (ha->type == GDT_EISA)
1282 *pIStatus = inb((ushort)ha->bmic + EDOORREG);
1283 else if (ha->type == GDT_ISA)
1285 gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
1286 else if (ha->type == GDT_PCI)
1288 gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
1289 else if (ha->type == GDT_PCINEW)
1290 *pIStatus = inb(PTR2USHORT(&ha->plx->edoor_reg));
1291 else if (ha->type == GDT_PCIMPR)
1293 gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg);
1296 return i; /* board found */
1302 static int gdth_test_busy(int hanum)
1304 register gdth_ha_str *ha;
1305 register int gdtsema0 = 0;
1307 TRACE(("gdth_test_busy() hanum %d\n",hanum));
1309 ha = HADATA(gdth_ctr_tab[hanum]);
1310 if (ha->type == GDT_EISA)
1311 gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
1312 else if (ha->type == GDT_ISA)
1313 gdtsema0 = (int)gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1314 else if (ha->type == GDT_PCI)
1315 gdtsema0 = (int)gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1316 else if (ha->type == GDT_PCINEW)
1317 gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg));
1318 else if (ha->type == GDT_PCIMPR)
1320 (int)gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
1322 return (gdtsema0 & 1);
1326 static int gdth_get_cmd_index(int hanum)
1328 register gdth_ha_str *ha;
1331 TRACE(("gdth_get_cmd_index() hanum %d\n",hanum));
1333 ha = HADATA(gdth_ctr_tab[hanum]);
1334 for (i=0; i<GDTH_MAXCMDS; ++i) {
1335 if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
1336 ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
1337 ha->cmd_tab[i].service = ha->pccb->Service;
1338 ha->pccb->CommandIndex = (ulong32)i+2;
1346 static void gdth_set_sema0(int hanum)
1348 register gdth_ha_str *ha;
1350 TRACE(("gdth_set_sema0() hanum %d\n",hanum));
1352 ha = HADATA(gdth_ctr_tab[hanum]);
1353 if (ha->type == GDT_EISA) {
1354 outb(1, ha->bmic + SEMA0REG);
1355 } else if (ha->type == GDT_ISA) {
1356 gdth_writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1357 } else if (ha->type == GDT_PCI) {
1358 gdth_writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1359 } else if (ha->type == GDT_PCINEW) {
1360 outb(1, PTR2USHORT(&ha->plx->sema0_reg));
1361 } else if (ha->type == GDT_PCIMPR) {
1362 gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
1367 static void gdth_copy_command(int hanum)
1369 register gdth_ha_str *ha;
1370 register gdth_cmd_str *cmd_ptr;
1371 register gdt6m_dpram_str __iomem *dp6m_ptr;
1372 register gdt6c_dpram_str __iomem *dp6c_ptr;
1373 gdt6_dpram_str __iomem *dp6_ptr;
1374 gdt2_dpram_str __iomem *dp2_ptr;
1375 ushort cp_count,dp_offset,cmd_no;
1377 TRACE(("gdth_copy_command() hanum %d\n",hanum));
1379 ha = HADATA(gdth_ctr_tab[hanum]);
1380 cp_count = ha->cmd_len;
1381 dp_offset= ha->cmd_offs_dpmem;
1382 cmd_no = ha->cmd_cnt;
1386 if (ha->type == GDT_EISA)
1387 return; /* no DPMEM, no copy */
1389 /* set cpcount dword aligned */
1391 cp_count += (4 - (cp_count & 3));
1393 ha->cmd_offs_dpmem += cp_count;
1395 /* set offset and service, copy command to DPMEM */
1396 if (ha->type == GDT_ISA) {
1398 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1399 &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
1400 gdth_writew((ushort)cmd_ptr->Service,
1401 &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
1402 memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1403 } else if (ha->type == GDT_PCI) {
1405 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1406 &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
1407 gdth_writew((ushort)cmd_ptr->Service,
1408 &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
1409 memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1410 } else if (ha->type == GDT_PCINEW) {
1412 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1413 &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
1414 gdth_writew((ushort)cmd_ptr->Service,
1415 &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
1416 memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1417 } else if (ha->type == GDT_PCIMPR) {
1419 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1420 &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
1421 gdth_writew((ushort)cmd_ptr->Service,
1422 &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
1423 memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1428 static void gdth_release_event(int hanum)
1430 register gdth_ha_str *ha;
1432 TRACE(("gdth_release_event() hanum %d\n",hanum));
1433 ha = HADATA(gdth_ctr_tab[hanum]);
1435 #ifdef GDTH_STATISTICS
1438 for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
1439 if (ha->cmd_tab[j].cmnd != UNUSED_CMND)
1442 if (max_index < i) {
1444 TRACE3(("GDT: max_index = %d\n",(ushort)i));
1449 if (ha->pccb->OpCode == GDT_INIT)
1450 ha->pccb->Service |= 0x80;
1452 if (ha->type == GDT_EISA) {
1453 if (ha->pccb->OpCode == GDT_INIT) /* store DMA buffer */
1454 outl(ha->ccb_phys, ha->bmic + MAILBOXREG);
1455 outb(ha->pccb->Service, ha->bmic + LDOORREG);
1456 } else if (ha->type == GDT_ISA) {
1457 gdth_writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event);
1458 } else if (ha->type == GDT_PCI) {
1459 gdth_writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event);
1460 } else if (ha->type == GDT_PCINEW) {
1461 outb(1, PTR2USHORT(&ha->plx->ldoor_reg));
1462 } else if (ha->type == GDT_PCIMPR) {
1463 gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg);
1468 static int gdth_wait(int hanum,int index,ulong32 time)
1471 int answer_found = FALSE;
1473 TRACE(("gdth_wait() hanum %d index %d time %d\n",hanum,index,time));
1475 ha = HADATA(gdth_ctr_tab[hanum]);
1477 return 1; /* no wait required */
1479 gdth_from_wait = TRUE;
1481 gdth_interrupt((int)ha->irq,ha);
1482 if (wait_hanum==hanum && wait_index==index) {
1483 answer_found = TRUE;
1488 gdth_from_wait = FALSE;
1490 while (gdth_test_busy(hanum))
1493 return (answer_found);
1497 static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
1498 ulong64 p2,ulong64 p3)
1500 register gdth_ha_str *ha;
1501 register gdth_cmd_str *cmd_ptr;
1504 TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode));
1506 ha = HADATA(gdth_ctr_tab[hanum]);
1508 memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str));
1511 for (retries = INIT_RETRIES;;) {
1512 cmd_ptr->Service = service;
1513 cmd_ptr->RequestBuffer = INTERNAL_CMND;
1514 if (!(index=gdth_get_cmd_index(hanum))) {
1515 TRACE(("GDT: No free command index found\n"));
1518 gdth_set_sema0(hanum);
1519 cmd_ptr->OpCode = opcode;
1520 cmd_ptr->BoardNode = LOCALBOARD;
1521 if (service == CACHESERVICE) {
1522 if (opcode == GDT_IOCTL) {
1523 cmd_ptr->u.ioctl.subfunc = p1;
1524 cmd_ptr->u.ioctl.channel = (ulong32)p2;
1525 cmd_ptr->u.ioctl.param_size = (ushort)p3;
1526 cmd_ptr->u.ioctl.p_param = ha->scratch_phys;
1528 if (ha->cache_feat & GDT_64BIT) {
1529 cmd_ptr->u.cache64.DeviceNo = (ushort)p1;
1530 cmd_ptr->u.cache64.BlockNo = p2;
1532 cmd_ptr->u.cache.DeviceNo = (ushort)p1;
1533 cmd_ptr->u.cache.BlockNo = (ulong32)p2;
1536 } else if (service == SCSIRAWSERVICE) {
1537 if (ha->raw_feat & GDT_64BIT) {
1538 cmd_ptr->u.raw64.direction = p1;
1539 cmd_ptr->u.raw64.bus = (unchar)p2;
1540 cmd_ptr->u.raw64.target = (unchar)p3;
1541 cmd_ptr->u.raw64.lun = (unchar)(p3 >> 8);
1543 cmd_ptr->u.raw.direction = p1;
1544 cmd_ptr->u.raw.bus = (unchar)p2;
1545 cmd_ptr->u.raw.target = (unchar)p3;
1546 cmd_ptr->u.raw.lun = (unchar)(p3 >> 8);
1548 } else if (service == SCREENSERVICE) {
1549 if (opcode == GDT_REALTIME) {
1550 *(ulong32 *)&cmd_ptr->u.screen.su.data[0] = p1;
1551 *(ulong32 *)&cmd_ptr->u.screen.su.data[4] = (ulong32)p2;
1552 *(ulong32 *)&cmd_ptr->u.screen.su.data[8] = (ulong32)p3;
1555 ha->cmd_len = sizeof(gdth_cmd_str);
1556 ha->cmd_offs_dpmem = 0;
1558 gdth_copy_command(hanum);
1559 gdth_release_event(hanum);
1561 if (!gdth_wait(hanum,index,INIT_TIMEOUT)) {
1562 printk("GDT: Initialization error (timeout service %d)\n",service);
1565 if (ha->status != S_BSY || --retries == 0)
1570 return (ha->status != S_OK ? 0:1);
1574 /* search for devices */
1576 static int __init gdth_search_drives(int hanum)
1578 register gdth_ha_str *ha;
1581 ulong32 bus_no, drv_cnt, drv_no, j;
1582 gdth_getch_str *chn;
1583 gdth_drlist_str *drl;
1584 gdth_iochan_str *ioc;
1585 gdth_raw_iochan_str *iocr;
1586 gdth_arcdl_str *alst;
1587 gdth_alist_str *alst2;
1588 gdth_oem_str_ioctl *oemstr;
1590 gdth_perf_modes *pmod;
1598 TRACE(("gdth_search_drives() hanum %d\n",hanum));
1599 ha = HADATA(gdth_ctr_tab[hanum]);
1602 /* initialize controller services, at first: screen service */
1603 ha->screen_feat = 0;
1605 ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_X_INIT_SCR,0,0,0);
1607 ha->screen_feat = GDT_64BIT;
1609 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1610 ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_INIT,0,0,0);
1612 printk("GDT-HA %d: Initialization error screen service (code %d)\n",
1616 TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n"));
1619 /* read realtime clock info, send to controller */
1620 /* 1. wait for the falling edge of update flag */
1621 spin_lock_irqsave(&rtc_lock, flags);
1622 for (j = 0; j < 1000000; ++j)
1623 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
1625 for (j = 0; j < 1000000; ++j)
1626 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
1630 for (j = 0; j < 12; ++j)
1631 rtc[j] = CMOS_READ(j);
1632 } while (rtc[0] != CMOS_READ(0));
1633 spin_unlock_irqrestore(&rtc_lock, flags);
1634 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32 *)&rtc[0],
1635 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]));
1636 /* 3. send to controller firmware */
1637 gdth_internal_cmd(hanum,SCREENSERVICE,GDT_REALTIME, *(ulong32 *)&rtc[0],
1638 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]);
1641 /* unfreeze all IOs */
1642 gdth_internal_cmd(hanum,CACHESERVICE,GDT_UNFREEZE_IO,0,0,0);
1644 /* initialize cache service */
1647 ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INIT_HOST,LINUX_OS,0,0);
1649 ha->cache_feat = GDT_64BIT;
1651 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1652 ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_INIT,LINUX_OS,0,0);
1654 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1658 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
1659 cdev_cnt = (ushort)ha->info;
1660 ha->fw_vers = ha->service;
1663 if (ha->type == GDT_PCIMPR) {
1664 /* set perf. modes */
1665 pmod = (gdth_perf_modes *)ha->pscratch;
1667 pmod->st_mode = 1; /* enable one status buffer */
1668 *((ulong64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys;
1669 pmod->st_buff_indx1 = COALINDEX;
1670 pmod->st_buff_addr2 = 0;
1671 pmod->st_buff_u_addr2 = 0;
1672 pmod->st_buff_indx2 = 0;
1673 pmod->st_buff_size = sizeof(gdth_coal_status) * MAXOFFSETS;
1674 pmod->cmd_mode = 0; // disable all cmd buffers
1675 pmod->cmd_buff_addr1 = 0;
1676 pmod->cmd_buff_u_addr1 = 0;
1677 pmod->cmd_buff_indx1 = 0;
1678 pmod->cmd_buff_addr2 = 0;
1679 pmod->cmd_buff_u_addr2 = 0;
1680 pmod->cmd_buff_indx2 = 0;
1681 pmod->cmd_buff_size = 0;
1682 pmod->reserved1 = 0;
1683 pmod->reserved2 = 0;
1684 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,SET_PERF_MODES,
1685 INVALID_CHANNEL,sizeof(gdth_perf_modes))) {
1686 printk("GDT-HA %d: Interrupt coalescing activated\n", hanum);
1691 /* detect number of buses - try new IOCTL */
1692 iocr = (gdth_raw_iochan_str *)ha->pscratch;
1693 iocr->hdr.version = 0xffffffff;
1694 iocr->hdr.list_entries = MAXBUS;
1695 iocr->hdr.first_chan = 0;
1696 iocr->hdr.last_chan = MAXBUS-1;
1697 iocr->hdr.list_offset = GDTOFFSOF(gdth_raw_iochan_str, list[0]);
1698 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_RAW_DESC,
1699 INVALID_CHANNEL,sizeof(gdth_raw_iochan_str))) {
1700 TRACE2(("IOCHAN_RAW_DESC supported!\n"));
1701 ha->bus_cnt = iocr->hdr.chan_count;
1702 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1703 if (iocr->list[bus_no].proc_id < MAXID)
1704 ha->bus_id[bus_no] = iocr->list[bus_no].proc_id;
1706 ha->bus_id[bus_no] = 0xff;
1710 chn = (gdth_getch_str *)ha->pscratch;
1711 for (bus_no = 0; bus_no < MAXBUS; ++bus_no) {
1712 chn->channel_no = bus_no;
1713 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
1714 SCSI_CHAN_CNT | L_CTRL_PATTERN,
1715 IO_CHANNEL | INVALID_CHANNEL,
1716 sizeof(gdth_getch_str))) {
1718 printk("GDT-HA %d: Error detecting channel count (0x%x)\n",
1724 if (chn->siop_id < MAXID)
1725 ha->bus_id[bus_no] = chn->siop_id;
1727 ha->bus_id[bus_no] = 0xff;
1729 ha->bus_cnt = (unchar)bus_no;
1731 TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt));
1733 /* read cache configuration */
1734 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_INFO,
1735 INVALID_CHANNEL,sizeof(gdth_cinfo_str))) {
1736 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1740 ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar;
1741 TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
1742 ha->cpar.version,ha->cpar.state,ha->cpar.strategy,
1743 ha->cpar.write_back,ha->cpar.block_size));
1745 /* read board info and features */
1746 ha->more_proc = FALSE;
1747 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_INFO,
1748 INVALID_CHANNEL,sizeof(gdth_binfo_str))) {
1749 memcpy(&ha->binfo, (gdth_binfo_str *)ha->pscratch,
1750 sizeof(gdth_binfo_str));
1751 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_FEATURES,
1752 INVALID_CHANNEL,sizeof(gdth_bfeat_str))) {
1753 TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n"));
1754 ha->bfeat = *(gdth_bfeat_str *)ha->pscratch;
1755 ha->more_proc = TRUE;
1758 TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n"));
1759 strcpy(ha->binfo.type_string, gdth_ctr_name(hanum));
1761 TRACE2(("Controller name: %s\n",ha->binfo.type_string));
1763 /* read more informations */
1764 if (ha->more_proc) {
1765 /* physical drives, channel addresses */
1766 ioc = (gdth_iochan_str *)ha->pscratch;
1767 ioc->hdr.version = 0xffffffff;
1768 ioc->hdr.list_entries = MAXBUS;
1769 ioc->hdr.first_chan = 0;
1770 ioc->hdr.last_chan = MAXBUS-1;
1771 ioc->hdr.list_offset = GDTOFFSOF(gdth_iochan_str, list[0]);
1772 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_DESC,
1773 INVALID_CHANNEL,sizeof(gdth_iochan_str))) {
1774 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1775 ha->raw[bus_no].address = ioc->list[bus_no].address;
1776 ha->raw[bus_no].local_no = ioc->list[bus_no].local_no;
1779 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1780 ha->raw[bus_no].address = IO_CHANNEL;
1781 ha->raw[bus_no].local_no = bus_no;
1784 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1785 chn = (gdth_getch_str *)ha->pscratch;
1786 chn->channel_no = ha->raw[bus_no].local_no;
1787 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
1788 SCSI_CHAN_CNT | L_CTRL_PATTERN,
1789 ha->raw[bus_no].address | INVALID_CHANNEL,
1790 sizeof(gdth_getch_str))) {
1791 ha->raw[bus_no].pdev_cnt = chn->drive_cnt;
1792 TRACE2(("Channel %d: %d phys. drives\n",
1793 bus_no,chn->drive_cnt));
1795 if (ha->raw[bus_no].pdev_cnt > 0) {
1796 drl = (gdth_drlist_str *)ha->pscratch;
1797 drl->sc_no = ha->raw[bus_no].local_no;
1798 drl->sc_cnt = ha->raw[bus_no].pdev_cnt;
1799 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
1800 SCSI_DR_LIST | L_CTRL_PATTERN,
1801 ha->raw[bus_no].address | INVALID_CHANNEL,
1802 sizeof(gdth_drlist_str))) {
1803 for (j = 0; j < ha->raw[bus_no].pdev_cnt; ++j)
1804 ha->raw[bus_no].id_list[j] = drl->sc_list[j];
1806 ha->raw[bus_no].pdev_cnt = 0;
1811 /* logical drives */
1812 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_CNT,
1813 INVALID_CHANNEL,sizeof(ulong32))) {
1814 drv_cnt = *(ulong32 *)ha->pscratch;
1815 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_LIST,
1816 INVALID_CHANNEL,drv_cnt * sizeof(ulong32))) {
1817 for (j = 0; j < drv_cnt; ++j) {
1818 drv_no = ((ulong32 *)ha->pscratch)[j];
1819 if (drv_no < MAX_LDRIVES) {
1820 ha->hdr[drv_no].is_logdrv = TRUE;
1821 TRACE2(("Drive %d is log. drive\n",drv_no));
1825 alst = (gdth_arcdl_str *)ha->pscratch;
1826 alst->entries_avail = MAX_LDRIVES;
1827 alst->first_entry = 0;
1828 alst->list_offset = GDTOFFSOF(gdth_arcdl_str, list[0]);
1829 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
1830 ARRAY_DRV_LIST2 | LA_CTRL_PATTERN,
1831 INVALID_CHANNEL, sizeof(gdth_arcdl_str) +
1832 (alst->entries_avail-1) * sizeof(gdth_alist_str))) {
1833 for (j = 0; j < alst->entries_init; ++j) {
1834 ha->hdr[j].is_arraydrv = alst->list[j].is_arrayd;
1835 ha->hdr[j].is_master = alst->list[j].is_master;
1836 ha->hdr[j].is_parity = alst->list[j].is_parity;
1837 ha->hdr[j].is_hotfix = alst->list[j].is_hotfix;
1838 ha->hdr[j].master_no = alst->list[j].cd_handle;
1840 } else if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
1841 ARRAY_DRV_LIST | LA_CTRL_PATTERN,
1842 0, 35 * sizeof(gdth_alist_str))) {
1843 for (j = 0; j < 35; ++j) {
1844 alst2 = &((gdth_alist_str *)ha->pscratch)[j];
1845 ha->hdr[j].is_arraydrv = alst2->is_arrayd;
1846 ha->hdr[j].is_master = alst2->is_master;
1847 ha->hdr[j].is_parity = alst2->is_parity;
1848 ha->hdr[j].is_hotfix = alst2->is_hotfix;
1849 ha->hdr[j].master_no = alst2->cd_handle;
1855 /* initialize raw service */
1858 ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_X_INIT_RAW,0,0,0);
1860 ha->raw_feat = GDT_64BIT;
1862 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1863 ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_INIT,0,0,0);
1865 printk("GDT-HA %d: Initialization error raw service (code %d)\n",
1869 TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n"));
1871 /* set/get features raw service (scatter/gather) */
1872 if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_SET_FEAT,SCATTER_GATHER,
1874 TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
1875 if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_GET_FEAT,0,0,0)) {
1876 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
1878 ha->raw_feat |= (ushort)ha->info;
1882 /* set/get features cache service (equal to raw service) */
1883 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_SET_FEAT,0,
1884 SCATTER_GATHER,0)) {
1885 TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
1886 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_GET_FEAT,0,0,0)) {
1887 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
1889 ha->cache_feat |= (ushort)ha->info;
1893 /* reserve drives for raw service */
1894 if (reserve_mode != 0) {
1895 gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE_ALL,
1896 reserve_mode == 1 ? 1 : 3, 0, 0);
1897 TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n",
1900 for (i = 0; i < MAX_RES_ARGS; i += 4) {
1901 if (reserve_list[i] == hanum && reserve_list[i+1] < ha->bus_cnt &&
1902 reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) {
1903 TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
1904 reserve_list[i], reserve_list[i+1],
1905 reserve_list[i+2], reserve_list[i+3]));
1906 if (!gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE,0,
1907 reserve_list[i+1], reserve_list[i+2] |
1908 (reserve_list[i+3] << 8))) {
1909 printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n",
1915 /* Determine OEM string using IOCTL */
1916 oemstr = (gdth_oem_str_ioctl *)ha->pscratch;
1917 oemstr->params.ctl_version = 0x01;
1918 oemstr->params.buffer_size = sizeof(oemstr->text);
1919 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
1920 CACHE_READ_OEM_STRING_RECORD,INVALID_CHANNEL,
1921 sizeof(gdth_oem_str_ioctl))) {
1922 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n"));
1923 printk("GDT-HA %d: Vendor: %s Name: %s\n",
1924 hanum,oemstr->text.oem_company_name,ha->binfo.type_string);
1925 /* Save the Host Drive inquiry data */
1926 strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,
1927 sizeof(ha->oem_name));
1929 /* Old method, based on PCI ID */
1930 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
1931 printk("GDT-HA %d: Name: %s\n",
1932 hanum,ha->binfo.type_string);
1933 if (ha->oem_id == OEM_ID_INTEL)
1934 strlcpy(ha->oem_name,"Intel ", sizeof(ha->oem_name));
1936 strlcpy(ha->oem_name,"ICP ", sizeof(ha->oem_name));
1939 /* scanning for host drives */
1940 for (i = 0; i < cdev_cnt; ++i)
1941 gdth_analyse_hdrive(hanum,i);
1943 TRACE(("gdth_search_drives() OK\n"));
1947 static int gdth_analyse_hdrive(int hanum,ushort hdrive)
1949 register gdth_ha_str *ha;
1951 int drv_hds, drv_secs;
1953 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n",hanum,hdrive));
1954 if (hdrive >= MAX_HDRIVES)
1956 ha = HADATA(gdth_ctr_tab[hanum]);
1958 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_INFO,hdrive,0,0))
1960 ha->hdr[hdrive].present = TRUE;
1961 ha->hdr[hdrive].size = ha->info;
1963 /* evaluate mapping (sectors per head, heads per cylinder) */
1964 ha->hdr[hdrive].size &= ~SECS32;
1965 if (ha->info2 == 0) {
1966 gdth_eval_mapping(ha->hdr[hdrive].size,&drv_cyls,&drv_hds,&drv_secs);
1968 drv_hds = ha->info2 & 0xff;
1969 drv_secs = (ha->info2 >> 8) & 0xff;
1970 drv_cyls = (ulong32)ha->hdr[hdrive].size / drv_hds / drv_secs;
1972 ha->hdr[hdrive].heads = (unchar)drv_hds;
1973 ha->hdr[hdrive].secs = (unchar)drv_secs;
1975 ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs;
1977 if (ha->cache_feat & GDT_64BIT) {
1978 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INFO,hdrive,0,0)
1979 && ha->info2 != 0) {
1980 ha->hdr[hdrive].size = ((ulong64)ha->info2 << 32) | ha->info;
1983 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
1984 hdrive,ha->hdr[hdrive].size,drv_hds,drv_secs));
1986 /* get informations about device */
1987 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_DEVTYPE,hdrive,0,0)) {
1988 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
1990 ha->hdr[hdrive].devtype = (ushort)ha->info;
1994 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_CLUST_INFO,hdrive,0,0)) {
1995 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
1998 ha->hdr[hdrive].cluster_type = (unchar)ha->info;
2001 /* R/W attributes */
2002 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_RW_ATTRIBS,hdrive,0,0)) {
2003 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
2005 ha->hdr[hdrive].rw_attribs = (unchar)ha->info;
2012 /* command queueing/sending functions */
2014 static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority)
2016 register gdth_ha_str *ha;
2017 register Scsi_Cmnd *pscp;
2018 register Scsi_Cmnd *nscp;
2022 TRACE(("gdth_putq() priority %d\n",priority));
2023 ha = HADATA(gdth_ctr_tab[hanum]);
2024 spin_lock_irqsave(&ha->smp_lock, flags);
2026 if (!IS_GDTH_INTERNAL_CMD(scp)) {
2027 scp->SCp.this_residual = (int)priority;
2028 b = virt_ctr ? NUMDATA(scp->device->host)->busnum:scp->device->channel;
2029 t = scp->device->id;
2030 if (priority >= DEFAULT_PRI) {
2031 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2032 (b==ha->virt_bus && t<MAX_HDRIVES && ha->hdr[t].lock)) {
2033 TRACE2(("gdth_putq(): locked IO ->update_timeout()\n"));
2034 scp->SCp.buffers_residual = gdth_update_timeout(hanum, scp, 0);
2039 if (ha->req_first==NULL) {
2040 ha->req_first = scp; /* queue was empty */
2041 scp->SCp.ptr = NULL;
2042 } else { /* queue not empty */
2043 pscp = ha->req_first;
2044 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2045 /* priority: 0-highest,..,0xff-lowest */
2046 while (nscp && (unchar)nscp->SCp.this_residual <= priority) {
2048 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2050 pscp->SCp.ptr = (char *)scp;
2051 scp->SCp.ptr = (char *)nscp;
2053 spin_unlock_irqrestore(&ha->smp_lock, flags);
2055 #ifdef GDTH_STATISTICS
2057 for (nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
2059 if (max_rq < flags) {
2061 TRACE3(("GDT: max_rq = %d\n",(ushort)max_rq));
2066 static void gdth_next(int hanum)
2068 register gdth_ha_str *ha;
2069 register Scsi_Cmnd *pscp;
2070 register Scsi_Cmnd *nscp;
2071 unchar b, t, l, firsttime;
2072 unchar this_cmd, next_cmd;
2076 TRACE(("gdth_next() hanum %d\n",hanum));
2077 ha = HADATA(gdth_ctr_tab[hanum]);
2079 spin_lock_irqsave(&ha->smp_lock, flags);
2081 ha->cmd_cnt = ha->cmd_offs_dpmem = 0;
2082 this_cmd = firsttime = TRUE;
2083 next_cmd = gdth_polling ? FALSE:TRUE;
2086 for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) {
2087 if (nscp != pscp && nscp != (Scsi_Cmnd *)pscp->SCp.ptr)
2088 pscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2089 if (!IS_GDTH_INTERNAL_CMD(nscp)) {
2091 NUMDATA(nscp->device->host)->busnum : nscp->device->channel;
2092 t = nscp->device->id;
2093 l = nscp->device->lun;
2094 if (nscp->SCp.this_residual >= DEFAULT_PRI) {
2095 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2096 (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock))
2103 if (gdth_test_busy(hanum)) { /* controller busy ? */
2104 TRACE(("gdth_next() controller %d busy !\n",hanum));
2105 if (!gdth_polling) {
2106 spin_unlock_irqrestore(&ha->smp_lock, flags);
2109 while (gdth_test_busy(hanum))
2115 if (!IS_GDTH_INTERNAL_CMD(nscp)) {
2116 if (nscp->SCp.phase == -1) {
2117 nscp->SCp.phase = CACHESERVICE; /* default: cache svc. */
2118 if (nscp->cmnd[0] == TEST_UNIT_READY) {
2119 TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
2121 /* TEST_UNIT_READY -> set scan mode */
2122 if ((ha->scan_mode & 0x0f) == 0) {
2123 if (b == 0 && t == 0 && l == 0) {
2125 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2127 } else if ((ha->scan_mode & 0x0f) == 1) {
2128 if (b == 0 && ((t == 0 && l == 1) ||
2129 (t == 1 && l == 0))) {
2130 nscp->SCp.sent_command = GDT_SCAN_START;
2131 nscp->SCp.phase = ((ha->scan_mode & 0x10 ? 1:0) << 8)
2133 ha->scan_mode = 0x12;
2134 TRACE2(("Scan mode: 0x%x (SCAN_START)\n",
2137 ha->scan_mode &= 0x10;
2138 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2140 } else if (ha->scan_mode == 0x12) {
2141 if (b == ha->bus_cnt && t == ha->tid_cnt-1) {
2142 nscp->SCp.phase = SCSIRAWSERVICE;
2143 nscp->SCp.sent_command = GDT_SCAN_END;
2144 ha->scan_mode &= 0x10;
2145 TRACE2(("Scan mode: 0x%x (SCAN_END)\n",
2150 if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY &&
2151 nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE &&
2152 (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) {
2153 /* always GDT_CLUST_INFO! */
2154 nscp->SCp.sent_command = GDT_CLUST_INFO;
2159 if (nscp->SCp.sent_command != -1) {
2160 if ((nscp->SCp.phase & 0xff) == CACHESERVICE) {
2161 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2164 } else if ((nscp->SCp.phase & 0xff) == SCSIRAWSERVICE) {
2165 if (!(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
2169 memset((char*)nscp->sense_buffer,0,16);
2170 nscp->sense_buffer[0] = 0x70;
2171 nscp->sense_buffer[2] = NOT_READY;
2172 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2173 if (!nscp->SCp.have_data_in)
2174 nscp->SCp.have_data_in++;
2176 gdth_scsi_done(nscp);
2178 } else if (IS_GDTH_INTERNAL_CMD(nscp)) {
2179 if (!(cmd_index=gdth_special_cmd(hanum,nscp)))
2182 } else if (b != ha->virt_bus) {
2183 if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW ||
2184 !(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
2187 ha->raw[BUS_L2P(ha,b)].io_cnt[t]++;
2188 } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || l != 0) {
2189 TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
2190 nscp->cmnd[0], b, t, l));
2191 nscp->result = DID_BAD_TARGET << 16;
2192 if (!nscp->SCp.have_data_in)
2193 nscp->SCp.have_data_in++;
2195 gdth_scsi_done(nscp);
2197 switch (nscp->cmnd[0]) {
2198 case TEST_UNIT_READY:
2205 case SERVICE_ACTION_IN:
2206 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2207 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2208 nscp->cmnd[4],nscp->cmnd[5]));
2209 if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) {
2210 /* return UNIT_ATTENTION */
2211 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2213 ha->hdr[t].media_changed = FALSE;
2214 memset((char*)nscp->sense_buffer,0,16);
2215 nscp->sense_buffer[0] = 0x70;
2216 nscp->sense_buffer[2] = UNIT_ATTENTION;
2217 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2218 if (!nscp->SCp.have_data_in)
2219 nscp->SCp.have_data_in++;
2221 gdth_scsi_done(nscp);
2222 } else if (gdth_internal_cache_cmd(hanum, nscp))
2223 gdth_scsi_done(nscp);
2226 case ALLOW_MEDIUM_REMOVAL:
2227 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2228 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2229 nscp->cmnd[4],nscp->cmnd[5]));
2230 if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) {
2231 TRACE(("Prevent r. nonremov. drive->do nothing\n"));
2232 nscp->result = DID_OK << 16;
2233 nscp->sense_buffer[0] = 0;
2234 if (!nscp->SCp.have_data_in)
2235 nscp->SCp.have_data_in++;
2237 gdth_scsi_done(nscp);
2239 nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0;
2240 TRACE(("Prevent/allow r. %d rem. drive %d\n",
2241 nscp->cmnd[4],nscp->cmnd[3]));
2242 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2249 TRACE2(("cache cmd %s\n",nscp->cmnd[0] == RESERVE ?
2250 "RESERVE" : "RELEASE"));
2251 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2261 if (ha->hdr[t].media_changed) {
2262 /* return UNIT_ATTENTION */
2263 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2265 ha->hdr[t].media_changed = FALSE;
2266 memset((char*)nscp->sense_buffer,0,16);
2267 nscp->sense_buffer[0] = 0x70;
2268 nscp->sense_buffer[2] = UNIT_ATTENTION;
2269 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2270 if (!nscp->SCp.have_data_in)
2271 nscp->SCp.have_data_in++;
2273 gdth_scsi_done(nscp);
2274 } else if (!(cmd_index=gdth_fill_cache_cmd(hanum, nscp, t)))
2279 TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0],
2280 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2281 nscp->cmnd[4],nscp->cmnd[5]));
2282 printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n",
2283 hanum, nscp->cmnd[0]);
2284 nscp->result = DID_ABORT << 16;
2285 if (!nscp->SCp.have_data_in)
2286 nscp->SCp.have_data_in++;
2288 gdth_scsi_done(nscp);
2295 if (nscp == ha->req_first)
2296 ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
2298 pscp->SCp.ptr = nscp->SCp.ptr;
2303 if (ha->cmd_cnt > 0) {
2304 gdth_release_event(hanum);
2308 spin_unlock_irqrestore(&ha->smp_lock, flags);
2310 if (gdth_polling && ha->cmd_cnt > 0) {
2311 if (!gdth_wait(hanum,cmd_index,POLL_TIMEOUT))
2312 printk("GDT-HA %d: Command %d timed out !\n",
2317 static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
2318 char *buffer,ushort count)
2322 struct scatterlist *sl;
2326 cpcount = count<=(ushort)scp->request_bufflen ? count:(ushort)scp->request_bufflen;
2327 ha = HADATA(gdth_ctr_tab[hanum]);
2330 sl = (struct scatterlist *)scp->request_buffer;
2331 for (i=0,cpsum=0; i<scp->use_sg; ++i,++sl) {
2332 unsigned long flags;
2333 cpnow = (ushort)sl->length;
2334 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2335 cpnow,cpsum,cpcount,(ushort)scp->bufflen));
2336 if (cpsum+cpnow > cpcount)
2337 cpnow = cpcount - cpsum;
2340 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
2344 local_irq_save(flags);
2345 address = kmap_atomic(sl->page, KM_BIO_SRC_IRQ) + sl->offset;
2346 memcpy(address,buffer,cpnow);
2347 flush_dcache_page(sl->page);
2348 kunmap_atomic(address, KM_BIO_SRC_IRQ);
2349 local_irq_restore(flags);
2350 if (cpsum == cpcount)
2355 TRACE(("copy_internal() count %d\n",cpcount));
2356 memcpy((char*)scp->request_buffer,buffer,cpcount);
2360 static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp)
2362 register gdth_ha_str *ha;
2365 gdth_rdcap_data rdc;
2367 gdth_modep_data mpd;
2369 ha = HADATA(gdth_ctr_tab[hanum]);
2370 t = scp->device->id;
2371 TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
2374 scp->result = DID_OK << 16;
2375 scp->sense_buffer[0] = 0;
2377 switch (scp->cmnd[0]) {
2378 case TEST_UNIT_READY:
2381 TRACE2(("Test/Verify/Start hdrive %d\n",t));
2385 TRACE2(("Inquiry hdrive %d devtype %d\n",
2386 t,ha->hdr[t].devtype));
2387 inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK;
2388 /* you can here set all disks to removable, if you want to do
2389 a flush using the ALLOW_MEDIUM_REMOVAL command */
2390 inq.modif_rmb = 0x00;
2391 if ((ha->hdr[t].devtype & 1) ||
2392 (ha->hdr[t].cluster_type & CLUSTER_DRIVE))
2393 inq.modif_rmb = 0x80;
2397 strcpy(inq.vendor,ha->oem_name);
2398 sprintf(inq.product,"Host Drive #%02d",t);
2399 strcpy(inq.revision," ");
2400 gdth_copy_internal_data(hanum,scp,(char*)&inq,sizeof(gdth_inq_data));
2404 TRACE2(("Request sense hdrive %d\n",t));
2405 sd.errorcode = 0x70;
2410 gdth_copy_internal_data(hanum,scp,(char*)&sd,sizeof(gdth_sense_data));
2414 TRACE2(("Mode sense hdrive %d\n",t));
2415 memset((char*)&mpd,0,sizeof(gdth_modep_data));
2416 mpd.hd.data_length = sizeof(gdth_modep_data);
2417 mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0;
2418 mpd.hd.bd_length = sizeof(mpd.bd);
2419 mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
2420 mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
2421 mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
2422 gdth_copy_internal_data(hanum,scp,(char*)&mpd,sizeof(gdth_modep_data));
2426 TRACE2(("Read capacity hdrive %d\n",t));
2427 if (ha->hdr[t].size > (ulong64)0xffffffff)
2428 rdc.last_block_no = 0xffffffff;
2430 rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1);
2431 rdc.block_length = cpu_to_be32(SECTOR_SIZE);
2432 gdth_copy_internal_data(hanum,scp,(char*)&rdc,sizeof(gdth_rdcap_data));
2435 case SERVICE_ACTION_IN:
2436 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 &&
2437 (ha->cache_feat & GDT_64BIT)) {
2438 gdth_rdcap16_data rdc16;
2440 TRACE2(("Read capacity (16) hdrive %d\n",t));
2441 rdc16.last_block_no = cpu_to_be64(ha->hdr[t].size-1);
2442 rdc16.block_length = cpu_to_be32(SECTOR_SIZE);
2443 gdth_copy_internal_data(hanum,scp,(char*)&rdc16,sizeof(gdth_rdcap16_data));
2445 scp->result = DID_ABORT << 16;
2450 TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0]));
2454 if (!scp->SCp.have_data_in)
2455 scp->SCp.have_data_in++;
2462 static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive)
2464 register gdth_ha_str *ha;
2465 register gdth_cmd_str *cmdp;
2466 struct scatterlist *sl;
2467 ulong32 cnt, blockcnt;
2468 ulong64 no, blockno;
2469 dma_addr_t phys_addr;
2470 int i, cmd_index, read_write, sgcnt, mode64;
2474 ha = HADATA(gdth_ctr_tab[hanum]);
2476 TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
2477 scp->cmnd[0],scp->cmd_len,hdrive));
2479 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2482 mode64 = (ha->cache_feat & GDT_64BIT) ? TRUE : FALSE;
2483 /* test for READ_16, WRITE_16 if !mode64 ? ---
2484 not required, should not occur due to error return on
2487 cmdp->Service = CACHESERVICE;
2488 cmdp->RequestBuffer = scp;
2489 /* search free command index */
2490 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
2491 TRACE(("GDT: No free command index found\n"));
2494 /* if it's the first command, set command semaphore */
2495 if (ha->cmd_cnt == 0)
2496 gdth_set_sema0(hanum);
2500 if (scp->SCp.sent_command != -1)
2501 cmdp->OpCode = scp->SCp.sent_command; /* special cache cmd. */
2502 else if (scp->cmnd[0] == RESERVE)
2503 cmdp->OpCode = GDT_RESERVE_DRV;
2504 else if (scp->cmnd[0] == RELEASE)
2505 cmdp->OpCode = GDT_RELEASE_DRV;
2506 else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
2507 if (scp->cmnd[4] & 1) /* prevent ? */
2508 cmdp->OpCode = GDT_MOUNT;
2509 else if (scp->cmnd[3] & 1) /* removable drive ? */
2510 cmdp->OpCode = GDT_UNMOUNT;
2512 cmdp->OpCode = GDT_FLUSH;
2513 } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10 ||
2514 scp->cmnd[0] == WRITE_12 || scp->cmnd[0] == WRITE_16
2517 if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) &&
2518 (ha->cache_feat & GDT_WR_THROUGH)))
2519 cmdp->OpCode = GDT_WRITE_THR;
2521 cmdp->OpCode = GDT_WRITE;
2524 cmdp->OpCode = GDT_READ;
2527 cmdp->BoardNode = LOCALBOARD;
2529 cmdp->u.cache64.DeviceNo = hdrive;
2530 cmdp->u.cache64.BlockNo = 1;
2531 cmdp->u.cache64.sg_canz = 0;
2533 cmdp->u.cache.DeviceNo = hdrive;
2534 cmdp->u.cache.BlockNo = 1;
2535 cmdp->u.cache.sg_canz = 0;
2539 if (scp->cmd_len == 16) {
2540 memcpy(&no, &scp->cmnd[2], sizeof(ulong64));
2541 blockno = be64_to_cpu(no);
2542 memcpy(&cnt, &scp->cmnd[10], sizeof(ulong32));
2543 blockcnt = be32_to_cpu(cnt);
2544 } else if (scp->cmd_len == 10) {
2545 memcpy(&no, &scp->cmnd[2], sizeof(ulong32));
2546 blockno = be32_to_cpu(no);
2547 memcpy(&cnt, &scp->cmnd[7], sizeof(ushort));
2548 blockcnt = be16_to_cpu(cnt);
2550 memcpy(&no, &scp->cmnd[0], sizeof(ulong32));
2551 blockno = be32_to_cpu(no) & 0x001fffffUL;
2552 blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
2555 cmdp->u.cache64.BlockNo = blockno;
2556 cmdp->u.cache64.BlockCnt = blockcnt;
2558 cmdp->u.cache.BlockNo = (ulong32)blockno;
2559 cmdp->u.cache.BlockCnt = blockcnt;
2563 sl = (struct scatterlist *)scp->request_buffer;
2564 sgcnt = scp->use_sg;
2565 scp->SCp.Status = GDTH_MAP_SG;
2566 scp->SCp.Message = (read_write == 1 ?
2567 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
2568 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
2570 cmdp->u.cache64.DestAddr= (ulong64)-1;
2571 cmdp->u.cache64.sg_canz = sgcnt;
2572 for (i=0; i<sgcnt; ++i,++sl) {
2573 cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2574 #ifdef GDTH_DMA_STATISTICS
2575 if (cmdp->u.cache64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2580 cmdp->u.cache64.sg_lst[i].sg_len = sg_dma_len(sl);
2583 cmdp->u.cache.DestAddr= 0xffffffff;
2584 cmdp->u.cache.sg_canz = sgcnt;
2585 for (i=0; i<sgcnt; ++i,++sl) {
2586 cmdp->u.cache.sg_lst[i].sg_ptr = sg_dma_address(sl);
2587 #ifdef GDTH_DMA_STATISTICS
2590 cmdp->u.cache.sg_lst[i].sg_len = sg_dma_len(sl);
2594 #ifdef GDTH_STATISTICS
2595 if (max_sg < (ulong32)sgcnt) {
2596 max_sg = (ulong32)sgcnt;
2597 TRACE3(("GDT: max_sg = %d\n",max_sg));
2601 } else if (scp->request_bufflen) {
2602 scp->SCp.Status = GDTH_MAP_SINGLE;
2603 scp->SCp.Message = (read_write == 1 ?
2604 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
2605 page = virt_to_page(scp->request_buffer);
2606 offset = (ulong)scp->request_buffer & ~PAGE_MASK;
2607 phys_addr = pci_map_page(ha->pdev,page,offset,
2608 scp->request_bufflen,scp->SCp.Message);
2609 scp->SCp.dma_handle = phys_addr;
2611 if (ha->cache_feat & SCATTER_GATHER) {
2612 cmdp->u.cache64.DestAddr = (ulong64)-1;
2613 cmdp->u.cache64.sg_canz = 1;
2614 cmdp->u.cache64.sg_lst[0].sg_ptr = phys_addr;
2615 cmdp->u.cache64.sg_lst[0].sg_len = scp->request_bufflen;
2616 cmdp->u.cache64.sg_lst[1].sg_len = 0;
2618 cmdp->u.cache64.DestAddr = phys_addr;
2619 cmdp->u.cache64.sg_canz= 0;
2622 if (ha->cache_feat & SCATTER_GATHER) {
2623 cmdp->u.cache.DestAddr = 0xffffffff;
2624 cmdp->u.cache.sg_canz = 1;
2625 cmdp->u.cache.sg_lst[0].sg_ptr = phys_addr;
2626 cmdp->u.cache.sg_lst[0].sg_len = scp->request_bufflen;
2627 cmdp->u.cache.sg_lst[1].sg_len = 0;
2629 cmdp->u.cache.DestAddr = phys_addr;
2630 cmdp->u.cache.sg_canz= 0;
2635 /* evaluate command size, check space */
2637 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2638 cmdp->u.cache64.DestAddr,cmdp->u.cache64.sg_canz,
2639 cmdp->u.cache64.sg_lst[0].sg_ptr,
2640 cmdp->u.cache64.sg_lst[0].sg_len));
2641 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2642 cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt));
2643 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) +
2644 (ushort)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str);
2646 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2647 cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
2648 cmdp->u.cache.sg_lst[0].sg_ptr,
2649 cmdp->u.cache.sg_lst[0].sg_len));
2650 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2651 cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
2652 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
2653 (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str);
2655 if (ha->cmd_len & 3)
2656 ha->cmd_len += (4 - (ha->cmd_len & 3));
2658 if (ha->cmd_cnt > 0) {
2659 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2661 TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
2662 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2668 gdth_copy_command(hanum);
2672 static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b)
2674 register gdth_ha_str *ha;
2675 register gdth_cmd_str *cmdp;
2676 struct scatterlist *sl;
2678 dma_addr_t phys_addr, sense_paddr;
2679 int cmd_index, sgcnt, mode64;
2684 ha = HADATA(gdth_ctr_tab[hanum]);
2685 t = scp->device->id;
2686 l = scp->device->lun;
2688 TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
2689 scp->cmnd[0],b,t,l));
2691 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2694 mode64 = (ha->raw_feat & GDT_64BIT) ? TRUE : FALSE;
2696 cmdp->Service = SCSIRAWSERVICE;
2697 cmdp->RequestBuffer = scp;
2698 /* search free command index */
2699 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
2700 TRACE(("GDT: No free command index found\n"));
2703 /* if it's the first command, set command semaphore */
2704 if (ha->cmd_cnt == 0)
2705 gdth_set_sema0(hanum);
2708 if (scp->SCp.sent_command != -1) {
2709 cmdp->OpCode = scp->SCp.sent_command; /* special raw cmd. */
2710 cmdp->BoardNode = LOCALBOARD;
2712 cmdp->u.raw64.direction = (scp->SCp.phase >> 8);
2713 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2714 cmdp->OpCode, cmdp->u.raw64.direction));
2715 /* evaluate command size */
2716 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst);
2718 cmdp->u.raw.direction = (scp->SCp.phase >> 8);
2719 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2720 cmdp->OpCode, cmdp->u.raw.direction));
2721 /* evaluate command size */
2722 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst);
2726 page = virt_to_page(scp->sense_buffer);
2727 offset = (ulong)scp->sense_buffer & ~PAGE_MASK;
2728 sense_paddr = pci_map_page(ha->pdev,page,offset,
2729 16,PCI_DMA_FROMDEVICE);
2730 *(ulong32 *)&scp->SCp.buffer = (ulong32)sense_paddr;
2731 /* high part, if 64bit */
2732 *(ulong32 *)&scp->host_scribble = (ulong32)((ulong64)sense_paddr >> 32);
2733 cmdp->OpCode = GDT_WRITE; /* always */
2734 cmdp->BoardNode = LOCALBOARD;
2736 cmdp->u.raw64.reserved = 0;
2737 cmdp->u.raw64.mdisc_time = 0;
2738 cmdp->u.raw64.mcon_time = 0;
2739 cmdp->u.raw64.clen = scp->cmd_len;
2740 cmdp->u.raw64.target = t;
2741 cmdp->u.raw64.lun = l;
2742 cmdp->u.raw64.bus = b;
2743 cmdp->u.raw64.priority = 0;
2744 cmdp->u.raw64.sdlen = scp->request_bufflen;
2745 cmdp->u.raw64.sense_len = 16;
2746 cmdp->u.raw64.sense_data = sense_paddr;
2747 cmdp->u.raw64.direction =
2748 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
2749 memcpy(cmdp->u.raw64.cmd,scp->cmnd,16);
2750 cmdp->u.raw64.sg_ranz = 0;
2752 cmdp->u.raw.reserved = 0;
2753 cmdp->u.raw.mdisc_time = 0;
2754 cmdp->u.raw.mcon_time = 0;
2755 cmdp->u.raw.clen = scp->cmd_len;
2756 cmdp->u.raw.target = t;
2757 cmdp->u.raw.lun = l;
2758 cmdp->u.raw.bus = b;
2759 cmdp->u.raw.priority = 0;
2760 cmdp->u.raw.link_p = 0;
2761 cmdp->u.raw.sdlen = scp->request_bufflen;
2762 cmdp->u.raw.sense_len = 16;
2763 cmdp->u.raw.sense_data = sense_paddr;
2764 cmdp->u.raw.direction =
2765 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
2766 memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
2767 cmdp->u.raw.sg_ranz = 0;
2771 sl = (struct scatterlist *)scp->request_buffer;
2772 sgcnt = scp->use_sg;
2773 scp->SCp.Status = GDTH_MAP_SG;
2774 scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
2775 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
2777 cmdp->u.raw64.sdata = (ulong64)-1;
2778 cmdp->u.raw64.sg_ranz = sgcnt;
2779 for (i=0; i<sgcnt; ++i,++sl) {
2780 cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2781 #ifdef GDTH_DMA_STATISTICS
2782 if (cmdp->u.raw64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2787 cmdp->u.raw64.sg_lst[i].sg_len = sg_dma_len(sl);
2790 cmdp->u.raw.sdata = 0xffffffff;
2791 cmdp->u.raw.sg_ranz = sgcnt;
2792 for (i=0; i<sgcnt; ++i,++sl) {
2793 cmdp->u.raw.sg_lst[i].sg_ptr = sg_dma_address(sl);
2794 #ifdef GDTH_DMA_STATISTICS
2797 cmdp->u.raw.sg_lst[i].sg_len = sg_dma_len(sl);
2801 #ifdef GDTH_STATISTICS
2802 if (max_sg < sgcnt) {
2804 TRACE3(("GDT: max_sg = %d\n",sgcnt));
2808 } else if (scp->request_bufflen) {
2809 scp->SCp.Status = GDTH_MAP_SINGLE;
2810 scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
2811 page = virt_to_page(scp->request_buffer);
2812 offset = (ulong)scp->request_buffer & ~PAGE_MASK;
2813 phys_addr = pci_map_page(ha->pdev,page,offset,
2814 scp->request_bufflen,scp->SCp.Message);
2815 scp->SCp.dma_handle = phys_addr;
2818 if (ha->raw_feat & SCATTER_GATHER) {
2819 cmdp->u.raw64.sdata = (ulong64)-1;
2820 cmdp->u.raw64.sg_ranz= 1;
2821 cmdp->u.raw64.sg_lst[0].sg_ptr = phys_addr;
2822 cmdp->u.raw64.sg_lst[0].sg_len = scp->request_bufflen;
2823 cmdp->u.raw64.sg_lst[1].sg_len = 0;
2825 cmdp->u.raw64.sdata = phys_addr;
2826 cmdp->u.raw64.sg_ranz= 0;
2829 if (ha->raw_feat & SCATTER_GATHER) {
2830 cmdp->u.raw.sdata = 0xffffffff;
2831 cmdp->u.raw.sg_ranz= 1;
2832 cmdp->u.raw.sg_lst[0].sg_ptr = phys_addr;
2833 cmdp->u.raw.sg_lst[0].sg_len = scp->request_bufflen;
2834 cmdp->u.raw.sg_lst[1].sg_len = 0;
2836 cmdp->u.raw.sdata = phys_addr;
2837 cmdp->u.raw.sg_ranz= 0;
2842 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2843 cmdp->u.raw64.sdata,cmdp->u.raw64.sg_ranz,
2844 cmdp->u.raw64.sg_lst[0].sg_ptr,
2845 cmdp->u.raw64.sg_lst[0].sg_len));
2846 /* evaluate command size */
2847 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) +
2848 (ushort)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str);
2850 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2851 cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
2852 cmdp->u.raw.sg_lst[0].sg_ptr,
2853 cmdp->u.raw.sg_lst[0].sg_len));
2854 /* evaluate command size */
2855 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
2856 (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
2860 if (ha->cmd_len & 3)
2861 ha->cmd_len += (4 - (ha->cmd_len & 3));
2863 if (ha->cmd_cnt > 0) {
2864 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2866 TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
2867 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2873 gdth_copy_command(hanum);
2877 static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp)
2879 register gdth_ha_str *ha;
2880 register gdth_cmd_str *cmdp;
2883 ha = HADATA(gdth_ctr_tab[hanum]);
2885 TRACE2(("gdth_special_cmd(): "));
2887 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2890 memcpy( cmdp, scp->request_buffer, sizeof(gdth_cmd_str));
2891 cmdp->RequestBuffer = scp;
2893 /* search free command index */
2894 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
2895 TRACE(("GDT: No free command index found\n"));
2899 /* if it's the first command, set command semaphore */
2900 if (ha->cmd_cnt == 0)
2901 gdth_set_sema0(hanum);
2903 /* evaluate command size, check space */
2904 if (cmdp->OpCode == GDT_IOCTL) {
2905 TRACE2(("IOCTL\n"));
2907 GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong64);
2908 } else if (cmdp->Service == CACHESERVICE) {
2909 TRACE2(("cache command %d\n",cmdp->OpCode));
2910 if (ha->cache_feat & GDT_64BIT)
2912 GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + sizeof(gdth_sg64_str);
2915 GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
2916 } else if (cmdp->Service == SCSIRAWSERVICE) {
2917 TRACE2(("raw command %d\n",cmdp->OpCode));
2918 if (ha->raw_feat & GDT_64BIT)
2920 GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + sizeof(gdth_sg64_str);
2923 GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
2926 if (ha->cmd_len & 3)
2927 ha->cmd_len += (4 - (ha->cmd_len & 3));
2929 if (ha->cmd_cnt > 0) {
2930 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2932 TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
2933 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2939 gdth_copy_command(hanum);
2944 /* Controller event handling functions */
2945 static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
2946 ushort idx, gdth_evt_data *evt)
2951 /* no GDTH_LOCK_HA() ! */
2952 TRACE2(("gdth_store_event() source %d idx %d\n", source, idx));
2953 if (source == 0) /* no source -> no event */
2956 if (ebuffer[elastidx].event_source == source &&
2957 ebuffer[elastidx].event_idx == idx &&
2958 ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
2959 !memcmp((char *)&ebuffer[elastidx].event_data.eu,
2960 (char *)&evt->eu, evt->size)) ||
2961 (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
2962 !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
2963 (char *)&evt->event_string)))) {
2964 e = &ebuffer[elastidx];
2965 do_gettimeofday(&tv);
2966 e->last_stamp = tv.tv_sec;
2969 if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
2971 if (elastidx == MAX_EVENTS)
2973 if (elastidx == eoldidx) { /* reached mark ? */
2975 if (eoldidx == MAX_EVENTS)
2979 e = &ebuffer[elastidx];
2980 e->event_source = source;
2982 do_gettimeofday(&tv);
2983 e->first_stamp = e->last_stamp = tv.tv_sec;
2985 e->event_data = *evt;
2991 static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
2997 TRACE2(("gdth_read_event() handle %d\n", handle));
2998 spin_lock_irqsave(&ha->smp_lock, flags);
3003 estr->event_source = 0;
3005 if (eindex >= MAX_EVENTS) {
3006 spin_unlock_irqrestore(&ha->smp_lock, flags);
3009 e = &ebuffer[eindex];
3010 if (e->event_source != 0) {
3011 if (eindex != elastidx) {
3012 if (++eindex == MAX_EVENTS)
3017 memcpy(estr, e, sizeof(gdth_evt_str));
3019 spin_unlock_irqrestore(&ha->smp_lock, flags);
3023 static void gdth_readapp_event(gdth_ha_str *ha,
3024 unchar application, gdth_evt_str *estr)
3029 unchar found = FALSE;
3031 TRACE2(("gdth_readapp_event() app. %d\n", application));
3032 spin_lock_irqsave(&ha->smp_lock, flags);
3035 e = &ebuffer[eindex];
3036 if (e->event_source == 0)
3038 if ((e->application & application) == 0) {
3039 e->application |= application;
3043 if (eindex == elastidx)
3045 if (++eindex == MAX_EVENTS)
3049 memcpy(estr, e, sizeof(gdth_evt_str));
3051 estr->event_source = 0;
3052 spin_unlock_irqrestore(&ha->smp_lock, flags);
3055 static void gdth_clear_events(void)
3057 TRACE(("gdth_clear_events()"));
3059 eoldidx = elastidx = 0;
3060 ebuffer[0].event_source = 0;
3064 /* SCSI interface functions */
3066 static irqreturn_t gdth_interrupt(int irq,void *dev_id)
3068 gdth_ha_str *ha2 = (gdth_ha_str *)dev_id;
3069 register gdth_ha_str *ha;
3070 gdt6m_dpram_str __iomem *dp6m_ptr = NULL;
3071 gdt6_dpram_str __iomem *dp6_ptr;
3072 gdt2_dpram_str __iomem *dp2_ptr;
3079 int coalesced = FALSE;
3081 gdth_coal_status *pcs = NULL;
3082 int act_int_coal = 0;
3085 TRACE(("gdth_interrupt() IRQ %d\n",irq));
3087 /* if polling and not from gdth_wait() -> return */
3089 if (!gdth_from_wait) {
3095 spin_lock_irqsave(&ha2->smp_lock, flags);
3098 /* search controller */
3099 if ((hanum = gdth_get_status(&IStatus,irq)) == -1) {
3100 /* spurious interrupt */
3102 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3105 ha = HADATA(gdth_ctr_tab[hanum]);
3107 #ifdef GDTH_STATISTICS
3112 /* See if the fw is returning coalesced status */
3113 if (IStatus == COALINDEX) {
3114 /* Coalesced status. Setup the initial status
3115 buffer pointer and flags */
3116 pcs = ha->coal_stat;
3123 /* For coalesced requests all status
3124 information is found in the status buffer */
3125 IStatus = (unchar)(pcs->status & 0xff);
3129 if (ha->type == GDT_EISA) {
3130 if (IStatus & 0x80) { /* error flag */
3132 ha->status = inw(ha->bmic + MAILBOXREG+8);
3133 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3134 } else /* no error */
3136 ha->info = inl(ha->bmic + MAILBOXREG+12);
3137 ha->service = inw(ha->bmic + MAILBOXREG+10);
3138 ha->info2 = inl(ha->bmic + MAILBOXREG+4);
3140 outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */
3141 outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */
3142 } else if (ha->type == GDT_ISA) {
3144 if (IStatus & 0x80) { /* error flag */
3146 ha->status = gdth_readw(&dp2_ptr->u.ic.Status);
3147 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3148 } else /* no error */
3150 ha->info = gdth_readl(&dp2_ptr->u.ic.Info[0]);
3151 ha->service = gdth_readw(&dp2_ptr->u.ic.Service);
3152 ha->info2 = gdth_readl(&dp2_ptr->u.ic.Info[1]);
3154 gdth_writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
3155 gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */
3156 gdth_writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */
3157 } else if (ha->type == GDT_PCI) {
3159 if (IStatus & 0x80) { /* error flag */
3161 ha->status = gdth_readw(&dp6_ptr->u.ic.Status);
3162 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3163 } else /* no error */
3165 ha->info = gdth_readl(&dp6_ptr->u.ic.Info[0]);
3166 ha->service = gdth_readw(&dp6_ptr->u.ic.Service);
3167 ha->info2 = gdth_readl(&dp6_ptr->u.ic.Info[1]);
3169 gdth_writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
3170 gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */
3171 gdth_writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */
3172 } else if (ha->type == GDT_PCINEW) {
3173 if (IStatus & 0x80) { /* error flag */
3175 ha->status = inw(PTR2USHORT(&ha->plx->status));
3176 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3179 ha->info = inl(PTR2USHORT(&ha->plx->info[0]));
3180 ha->service = inw(PTR2USHORT(&ha->plx->service));
3181 ha->info2 = inl(PTR2USHORT(&ha->plx->info[1]));
3183 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
3184 outb(0x00, PTR2USHORT(&ha->plx->sema1_reg));
3185 } else if (ha->type == GDT_PCIMPR) {
3187 if (IStatus & 0x80) { /* error flag */
3191 ha->status = pcs->ext_status & 0xffff;
3194 ha->status = gdth_readw(&dp6m_ptr->i960r.status);
3195 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3196 } else /* no error */
3199 /* get information */
3201 ha->info = pcs->info0;
3202 ha->info2 = pcs->info1;
3203 ha->service = (pcs->ext_status >> 16) & 0xffff;
3207 ha->info = gdth_readl(&dp6m_ptr->i960r.info[0]);
3208 ha->service = gdth_readw(&dp6m_ptr->i960r.service);
3209 ha->info2 = gdth_readl(&dp6m_ptr->i960r.info[1]);
3212 if (IStatus == ASYNCINDEX) {
3213 if (ha->service != SCREENSERVICE &&
3214 (ha->fw_vers & 0xff) >= 0x1a) {
3215 ha->dvr.severity = gdth_readb
3216 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.severity);
3217 for (i = 0; i < 256; ++i) {
3218 ha->dvr.event_string[i] = gdth_readb
3219 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.evt_str[i]);
3220 if (ha->dvr.event_string[i] == 0)
3226 /* Make sure that non coalesced interrupts get cleared
3227 before being handled by gdth_async_event/gdth_sync_event */
3231 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3232 gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
3235 TRACE2(("gdth_interrupt() unknown controller type\n"));
3237 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3241 TRACE(("gdth_interrupt() index %d stat %d info %d\n",
3242 IStatus,ha->status,ha->info));
3244 if (gdth_from_wait) {
3246 wait_index = (int)IStatus;
3249 if (IStatus == ASYNCINDEX) {
3250 TRACE2(("gdth_interrupt() async. event\n"));
3251 gdth_async_event(hanum);
3253 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3258 if (IStatus == SPEZINDEX) {
3259 TRACE2(("Service unknown or not initialized !\n"));
3260 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3261 ha->dvr.eu.driver.ionode = hanum;
3262 gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr);
3264 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3267 scp = ha->cmd_tab[IStatus-2].cmnd;
3268 Service = ha->cmd_tab[IStatus-2].service;
3269 ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND;
3270 if (scp == UNUSED_CMND) {
3271 TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus));
3272 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3273 ha->dvr.eu.driver.ionode = hanum;
3274 ha->dvr.eu.driver.index = IStatus;
3275 gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr);
3277 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3280 if (scp == INTERNAL_CMND) {
3281 TRACE(("gdth_interrupt() answer to internal command\n"));
3283 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3287 TRACE(("gdth_interrupt() sync. status\n"));
3288 rval = gdth_sync_event(hanum,Service,IStatus,scp);
3290 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3292 gdth_putq(hanum,scp,scp->SCp.this_residual);
3293 } else if (rval == 1) {
3294 gdth_scsi_done(scp);
3299 /* go to the next status in the status buffer */
3301 #ifdef GDTH_STATISTICS
3303 if (act_int_coal > max_int_coal) {
3304 max_int_coal = act_int_coal;
3305 printk("GDT: max_int_coal = %d\n",(ushort)max_int_coal);
3308 /* see if there is another status */
3309 if (pcs->status == 0)
3310 /* Stop the coalesce loop */
3315 /* coalescing only for new GDT_PCIMPR controllers available */
3316 if (ha->type == GDT_PCIMPR && coalesced) {
3317 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3318 gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
3326 static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp)
3328 register gdth_ha_str *ha;
3333 ha = HADATA(gdth_ctr_tab[hanum]);
3335 TRACE(("gdth_sync_event() serv %d status %d\n",
3336 service,ha->status));
3338 if (service == SCREENSERVICE) {
3340 TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
3341 msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
3342 if (msg->msg_len > MSGLEN+1)
3343 msg->msg_len = MSGLEN+1;
3345 if (!(msg->msg_answer && msg->msg_ext)) {
3346 msg->msg_text[msg->msg_len] = '\0';
3347 printk("%s",msg->msg_text);
3350 if (msg->msg_ext && !msg->msg_answer) {
3351 while (gdth_test_busy(hanum))
3353 cmdp->Service = SCREENSERVICE;
3354 cmdp->RequestBuffer = SCREEN_CMND;
3355 gdth_get_cmd_index(hanum);
3356 gdth_set_sema0(hanum);
3357 cmdp->OpCode = GDT_READ;
3358 cmdp->BoardNode = LOCALBOARD;
3359 cmdp->u.screen.reserved = 0;
3360 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3361 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3362 ha->cmd_offs_dpmem = 0;
3363 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3366 gdth_copy_command(hanum);
3367 gdth_release_event(hanum);
3371 if (msg->msg_answer && msg->msg_alen) {
3372 /* default answers (getchar() not possible) */
3373 if (msg->msg_alen == 1) {
3376 msg->msg_text[0] = 0;
3380 msg->msg_text[0] = 1;
3381 msg->msg_text[1] = 0;
3384 msg->msg_answer = 0;
3385 while (gdth_test_busy(hanum))
3387 cmdp->Service = SCREENSERVICE;
3388 cmdp->RequestBuffer = SCREEN_CMND;
3389 gdth_get_cmd_index(hanum);
3390 gdth_set_sema0(hanum);
3391 cmdp->OpCode = GDT_WRITE;
3392 cmdp->BoardNode = LOCALBOARD;
3393 cmdp->u.screen.reserved = 0;
3394 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3395 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3396 ha->cmd_offs_dpmem = 0;
3397 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3400 gdth_copy_command(hanum);
3401 gdth_release_event(hanum);
3407 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
3408 t = scp->device->id;
3409 if (scp->SCp.sent_command == -1 && b != ha->virt_bus) {
3410 ha->raw[BUS_L2P(ha,b)].io_cnt[t]--;
3412 /* cache or raw service */
3413 if (ha->status == S_BSY) {
3414 TRACE2(("Controller busy -> retry !\n"));
3415 if (scp->SCp.sent_command == GDT_MOUNT)
3416 scp->SCp.sent_command = GDT_CLUST_INFO;
3420 if (scp->SCp.Status == GDTH_MAP_SG)
3421 pci_unmap_sg(ha->pdev,scp->request_buffer,
3422 scp->use_sg,scp->SCp.Message);
3423 else if (scp->SCp.Status == GDTH_MAP_SINGLE)
3424 pci_unmap_page(ha->pdev,scp->SCp.dma_handle,
3425 scp->request_bufflen,scp->SCp.Message);
3426 if (scp->SCp.buffer) {
3428 addr = (dma_addr_t)*(ulong32 *)&scp->SCp.buffer;
3429 if (scp->host_scribble)
3430 addr += (dma_addr_t)
3431 ((ulong64)(*(ulong32 *)&scp->host_scribble) << 32);
3432 pci_unmap_page(ha->pdev,addr,16,PCI_DMA_FROMDEVICE);
3435 if (ha->status == S_OK) {
3436 scp->SCp.Status = S_OK;
3437 scp->SCp.Message = ha->info;
3438 if (scp->SCp.sent_command != -1) {
3439 TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
3440 scp->SCp.sent_command));
3441 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
3442 if (scp->SCp.sent_command == GDT_CLUST_INFO) {
3443 ha->hdr[t].cluster_type = (unchar)ha->info;
3444 if (!(ha->hdr[t].cluster_type &
3446 /* NOT MOUNTED -> MOUNT */
3447 scp->SCp.sent_command = GDT_MOUNT;
3448 if (ha->hdr[t].cluster_type &
3450 /* cluster drive RESERVED (on the other node) */
3451 scp->SCp.phase = -2; /* reservation conflict */
3454 scp->SCp.sent_command = -1;
3457 if (scp->SCp.sent_command == GDT_MOUNT) {
3458 ha->hdr[t].cluster_type |= CLUSTER_MOUNTED;
3459 ha->hdr[t].media_changed = TRUE;
3460 } else if (scp->SCp.sent_command == GDT_UNMOUNT) {
3461 ha->hdr[t].cluster_type &= ~CLUSTER_MOUNTED;
3462 ha->hdr[t].media_changed = TRUE;
3464 scp->SCp.sent_command = -1;
3467 scp->SCp.this_residual = HIGH_PRI;
3470 /* RESERVE/RELEASE ? */
3471 if (scp->cmnd[0] == RESERVE) {
3472 ha->hdr[t].cluster_type |= CLUSTER_RESERVED;
3473 } else if (scp->cmnd[0] == RELEASE) {
3474 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3476 scp->result = DID_OK << 16;
3477 scp->sense_buffer[0] = 0;
3480 scp->SCp.Status = ha->status;
3481 scp->SCp.Message = ha->info;
3483 if (scp->SCp.sent_command != -1) {
3484 TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
3485 scp->SCp.sent_command, ha->status));
3486 if (scp->SCp.sent_command == GDT_SCAN_START ||
3487 scp->SCp.sent_command == GDT_SCAN_END) {
3488 scp->SCp.sent_command = -1;
3490 scp->SCp.this_residual = HIGH_PRI;
3493 memset((char*)scp->sense_buffer,0,16);
3494 scp->sense_buffer[0] = 0x70;
3495 scp->sense_buffer[2] = NOT_READY;
3496 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
3497 } else if (service == CACHESERVICE) {
3498 if (ha->status == S_CACHE_UNKNOWN &&
3499 (ha->hdr[t].cluster_type &
3500 CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) {
3501 /* bus reset -> force GDT_CLUST_INFO */
3502 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3504 memset((char*)scp->sense_buffer,0,16);
3505 if (ha->status == (ushort)S_CACHE_RESERV) {
3506 scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
3508 scp->sense_buffer[0] = 0x70;
3509 scp->sense_buffer[2] = NOT_READY;
3510 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
3512 if (!IS_GDTH_INTERNAL_CMD(scp)) {
3513 ha->dvr.size = sizeof(ha->dvr.eu.sync);
3514 ha->dvr.eu.sync.ionode = hanum;
3515 ha->dvr.eu.sync.service = service;
3516 ha->dvr.eu.sync.status = ha->status;
3517 ha->dvr.eu.sync.info = ha->info;
3518 ha->dvr.eu.sync.hostdrive = t;
3519 if (ha->status >= 0x8000)
3520 gdth_store_event(ha, ES_SYNC, 0, &ha->dvr);
3522 gdth_store_event(ha, ES_SYNC, service, &ha->dvr);
3525 /* sense buffer filled from controller firmware (DMA) */
3526 if (ha->status != S_RAW_SCSI || ha->info >= 0x100) {
3527 scp->result = DID_BAD_TARGET << 16;
3529 scp->result = (DID_OK << 16) | ha->info;
3533 if (!scp->SCp.have_data_in)
3534 scp->SCp.have_data_in++;
3542 static char *async_cache_tab[] = {
3543 /* 0*/ "\011\000\002\002\002\004\002\006\004"
3544 "GDT HA %u, service %u, async. status %u/%lu unknown",
3545 /* 1*/ "\011\000\002\002\002\004\002\006\004"
3546 "GDT HA %u, service %u, async. status %u/%lu unknown",
3547 /* 2*/ "\005\000\002\006\004"
3548 "GDT HA %u, Host Drive %lu not ready",
3549 /* 3*/ "\005\000\002\006\004"
3550 "GDT HA %u, Host Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced",
3551 /* 4*/ "\005\000\002\006\004"
3552 "GDT HA %u, mirror update on Host Drive %lu failed",
3553 /* 5*/ "\005\000\002\006\004"
3554 "GDT HA %u, Mirror Drive %lu failed",
3555 /* 6*/ "\005\000\002\006\004"
3556 "GDT HA %u, Mirror Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced",
3557 /* 7*/ "\005\000\002\006\004"
3558 "GDT HA %u, Host Drive %lu write protected",
3559 /* 8*/ "\005\000\002\006\004"
3560 "GDT HA %u, media changed in Host Drive %lu",
3561 /* 9*/ "\005\000\002\006\004"
3562 "GDT HA %u, Host Drive %lu is offline",
3563 /*10*/ "\005\000\002\006\004"
3564 "GDT HA %u, media change of Mirror Drive %lu",
3565 /*11*/ "\005\000\002\006\004"
3566 "GDT HA %u, Mirror Drive %lu is write protected",
3567 /*12*/ "\005\000\002\006\004"
3568 "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
3569 /*13*/ "\007\000\002\006\002\010\002"
3570 "GDT HA %u, Array Drive %u: Cache Drive %u failed",
3571 /*14*/ "\005\000\002\006\002"
3572 "GDT HA %u, Array Drive %u: FAIL state entered",
3573 /*15*/ "\005\000\002\006\002"
3574 "GDT HA %u, Array Drive %u: error",
3575 /*16*/ "\007\000\002\006\002\010\002"
3576 "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
3577 /*17*/ "\005\000\002\006\002"
3578 "GDT HA %u, Array Drive %u: parity build failed",
3579 /*18*/ "\005\000\002\006\002"
3580 "GDT HA %u, Array Drive %u: drive rebuild failed",
3581 /*19*/ "\005\000\002\010\002"
3582 "GDT HA %u, Test of Hot Fix %u failed",
3583 /*20*/ "\005\000\002\006\002"
3584 "GDT HA %u, Array Drive %u: drive build finished successfully",
3585 /*21*/ "\005\000\002\006\002"
3586 "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
3587 /*22*/ "\007\000\002\006\002\010\002"
3588 "GDT HA %u, Array Drive %u: Hot Fix %u activated",
3589 /*23*/ "\005\000\002\006\002"
3590 "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
3591 /*24*/ "\005\000\002\010\002"
3592 "GDT HA %u, mirror update on Cache Drive %u completed",
3593 /*25*/ "\005\000\002\010\002"
3594 "GDT HA %u, mirror update on Cache Drive %lu failed",
3595 /*26*/ "\005\000\002\006\002"
3596 "GDT HA %u, Array Drive %u: drive rebuild started",
3597 /*27*/ "\005\000\002\012\001"
3598 "GDT HA %u, Fault bus %u: SHELF OK detected",
3599 /*28*/ "\005\000\002\012\001"
3600 "GDT HA %u, Fault bus %u: SHELF not OK detected",
3601 /*29*/ "\007\000\002\012\001\013\001"
3602 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
3603 /*30*/ "\007\000\002\012\001\013\001"
3604 "GDT HA %u, Fault bus %u, ID %u: new disk detected",
3605 /*31*/ "\007\000\002\012\001\013\001"
3606 "GDT HA %u, Fault bus %u, ID %u: old disk detected",
3607 /*32*/ "\007\000\002\012\001\013\001"
3608 "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid",
3609 /*33*/ "\007\000\002\012\001\013\001"
3610 "GDT HA %u, Fault bus %u, ID %u: invalid device detected",
3611 /*34*/ "\011\000\002\012\001\013\001\006\004"
3612 "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
3613 /*35*/ "\007\000\002\012\001\013\001"
3614 "GDT HA %u, Fault bus %u, ID %u: disk write protected",
3615 /*36*/ "\007\000\002\012\001\013\001"
3616 "GDT HA %u, Fault bus %u, ID %u: disk not available",
3617 /*37*/ "\007\000\002\012\001\006\004"
3618 "GDT HA %u, Fault bus %u: swap detected (%lu)",
3619 /*38*/ "\007\000\002\012\001\013\001"
3620 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
3621 /*39*/ "\007\000\002\012\001\013\001"
3622 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
3623 /*40*/ "\007\000\002\012\001\013\001"
3624 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
3625 /*41*/ "\007\000\002\012\001\013\001"
3626 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
3627 /*42*/ "\005\000\002\006\002"
3628 "GDT HA %u, Array Drive %u: drive build started",
3629 /*43*/ "\003\000\002"
3630 "GDT HA %u, DRAM parity error detected",
3631 /*44*/ "\005\000\002\006\002"
3632 "GDT HA %u, Mirror Drive %u: update started",
3633 /*45*/ "\007\000\002\006\002\010\002"
3634 "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
3635 /*46*/ "\005\000\002\006\002"
3636 "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
3637 /*47*/ "\005\000\002\006\002"
3638 "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
3639 /*48*/ "\005\000\002\006\002"
3640 "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
3641 /*49*/ "\005\000\002\006\002"
3642 "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
3643 /*50*/ "\007\000\002\012\001\013\001"
3644 "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
3645 /*51*/ "\005\000\002\006\002"
3646 "GDT HA %u, Array Drive %u: expand started",
3647 /*52*/ "\005\000\002\006\002"
3648 "GDT HA %u, Array Drive %u: expand finished successfully",
3649 /*53*/ "\005\000\002\006\002"
3650 "GDT HA %u, Array Drive %u: expand failed",
3651 /*54*/ "\003\000\002"
3652 "GDT HA %u, CPU temperature critical",
3653 /*55*/ "\003\000\002"
3654 "GDT HA %u, CPU temperature OK",
3655 /*56*/ "\005\000\002\006\004"
3656 "GDT HA %u, Host drive %lu created",
3657 /*57*/ "\005\000\002\006\002"
3658 "GDT HA %u, Array Drive %u: expand restarted",
3659 /*58*/ "\005\000\002\006\002"
3660 "GDT HA %u, Array Drive %u: expand stopped",
3661 /*59*/ "\005\000\002\010\002"
3662 "GDT HA %u, Mirror Drive %u: drive build quited",
3663 /*60*/ "\005\000\002\006\002"
3664 "GDT HA %u, Array Drive %u: parity build quited",
3665 /*61*/ "\005\000\002\006\002"
3666 "GDT HA %u, Array Drive %u: drive rebuild quited",
3667 /*62*/ "\005\000\002\006\002"
3668 "GDT HA %u, Array Drive %u: parity verify started",
3669 /*63*/ "\005\000\002\006\002"
3670 "GDT HA %u, Array Drive %u: parity verify done",
3671 /*64*/ "\005\000\002\006\002"
3672 "GDT HA %u, Array Drive %u: parity verify failed",
3673 /*65*/ "\005\000\002\006\002"
3674 "GDT HA %u, Array Drive %u: parity error detected",
3675 /*66*/ "\005\000\002\006\002"
3676 "GDT HA %u, Array Drive %u: parity verify quited",
3677 /*67*/ "\005\000\002\006\002"
3678 "GDT HA %u, Host Drive %u reserved",
3679 /*68*/ "\005\000\002\006\002"
3680 "GDT HA %u, Host Drive %u mounted and released",
3681 /*69*/ "\005\000\002\006\002"
3682 "GDT HA %u, Host Drive %u released",
3683 /*70*/ "\003\000\002"
3684 "GDT HA %u, DRAM error detected and corrected with ECC",
3685 /*71*/ "\003\000\002"
3686 "GDT HA %u, Uncorrectable DRAM error detected with ECC",
3687 /*72*/ "\011\000\002\012\001\013\001\014\001"
3688 "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
3689 /*73*/ "\005\000\002\006\002"
3690 "GDT HA %u, Host drive %u resetted locally",
3691 /*74*/ "\005\000\002\006\002"
3692 "GDT HA %u, Host drive %u resetted remotely",
3693 /*75*/ "\003\000\002"
3694 "GDT HA %u, async. status 75 unknown",
3698 static int gdth_async_event(int hanum)
3704 ha = HADATA(gdth_ctr_tab[hanum]);
3706 TRACE2(("gdth_async_event() ha %d serv %d\n",
3707 hanum,ha->service));
3709 if (ha->service == SCREENSERVICE) {
3710 if (ha->status == MSG_REQUEST) {
3711 while (gdth_test_busy(hanum))
3713 cmdp->Service = SCREENSERVICE;
3714 cmdp->RequestBuffer = SCREEN_CMND;
3715 cmd_index = gdth_get_cmd_index(hanum);
3716 gdth_set_sema0(hanum);
3717 cmdp->OpCode = GDT_READ;
3718 cmdp->BoardNode = LOCALBOARD;
3719 cmdp->u.screen.reserved = 0;
3720 cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE;
3721 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3722 ha->cmd_offs_dpmem = 0;
3723 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3726 gdth_copy_command(hanum);
3727 if (ha->type == GDT_EISA)
3728 printk("[EISA slot %d] ",(ushort)ha->brd_phys);
3729 else if (ha->type == GDT_ISA)
3730 printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys);
3732 printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8),
3733 (ushort)((ha->brd_phys>>3)&0x1f));
3734 gdth_release_event(hanum);
3738 if (ha->type == GDT_PCIMPR &&
3739 (ha->fw_vers & 0xff) >= 0x1a) {
3741 ha->dvr.eu.async.ionode = hanum;
3742 ha->dvr.eu.async.status = ha->status;
3743 /* severity and event_string already set! */
3745 ha->dvr.size = sizeof(ha->dvr.eu.async);
3746 ha->dvr.eu.async.ionode = hanum;
3747 ha->dvr.eu.async.service = ha->service;
3748 ha->dvr.eu.async.status = ha->status;
3749 ha->dvr.eu.async.info = ha->info;
3750 *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2;
3752 gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr );
3753 gdth_log_event( &ha->dvr, NULL );
3755 /* new host drive from expand? */
3756 if (ha->service == CACHESERVICE && ha->status == 56) {
3757 TRACE2(("gdth_async_event(): new host drive %d created\n",
3759 /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
3765 static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
3767 gdth_stackframe stack;
3771 TRACE2(("gdth_log_event()\n"));
3772 if (dvr->size == 0) {
3773 if (buffer == NULL) {
3774 printk("Adapter %d: %s\n",dvr->eu.async.ionode,dvr->event_string);
3776 sprintf(buffer,"Adapter %d: %s\n",
3777 dvr->eu.async.ionode,dvr->event_string);
3779 } else if (dvr->eu.async.service == CACHESERVICE &&
3780 INDEX_OK(dvr->eu.async.status, async_cache_tab)) {
3781 TRACE2(("GDT: Async. event cache service, event no.: %d\n",
3782 dvr->eu.async.status));
3784 f = async_cache_tab[dvr->eu.async.status];
3786 /* i: parameter to push, j: stack element to fill */
3787 for (j=0,i=1; i < f[0]; i+=2) {
3790 stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]];
3793 stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]];
3796 stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]];
3803 if (buffer == NULL) {
3804 printk(&f[(int)f[0]],stack);
3807 sprintf(buffer,&f[(int)f[0]],stack);
3811 if (buffer == NULL) {
3812 printk("GDT HA %u, Unknown async. event service %d event no. %d\n",
3813 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
3815 sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d",
3816 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
3821 #ifdef GDTH_STATISTICS
3822 static void gdth_timeout(ulong data)
3830 ha = HADATA(gdth_ctr_tab[hanum]);
3831 spin_lock_irqsave(&ha->smp_lock, flags);
3833 for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i)
3834 if (ha->cmd_tab[i].cmnd != UNUSED_CMND)
3837 for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
3840 TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
3841 act_ints, act_ios, act_stats, act_rq));
3842 act_ints = act_ios = 0;
3844 gdth_timer.expires = jiffies + 30 * HZ;
3845 add_timer(&gdth_timer);
3846 spin_unlock_irqrestore(&ha->smp_lock, flags);
3850 static void __init internal_setup(char *str,int *ints)
3853 char *cur_str, *argv;
3855 TRACE2(("internal_setup() str %s ints[0] %d\n",
3856 str ? str:"NULL", ints ? ints[0]:0));
3858 /* read irq[] from ints[] */
3864 for (i = 0; i < argc; ++i)
3869 /* analyse string */
3871 while (argv && (cur_str = strchr(argv, ':'))) {
3872 int val = 0, c = *++cur_str;
3874 if (c == 'n' || c == 'N')
3876 else if (c == 'y' || c == 'Y')
3879 val = (int)simple_strtoul(cur_str, NULL, 0);
3881 if (!strncmp(argv, "disable:", 8))
3883 else if (!strncmp(argv, "reserve_mode:", 13))
3885 else if (!strncmp(argv, "reverse_scan:", 13))
3887 else if (!strncmp(argv, "hdr_channel:", 12))
3889 else if (!strncmp(argv, "max_ids:", 8))
3891 else if (!strncmp(argv, "rescan:", 7))
3893 else if (!strncmp(argv, "virt_ctr:", 9))
3895 else if (!strncmp(argv, "shared_access:", 14))
3896 shared_access = val;
3897 else if (!strncmp(argv, "probe_eisa_isa:", 15))
3898 probe_eisa_isa = val;
3899 else if (!strncmp(argv, "reserve_list:", 13)) {
3900 reserve_list[0] = val;
3901 for (i = 1; i < MAX_RES_ARGS; i++) {
3902 cur_str = strchr(cur_str, ',');
3905 if (!isdigit((int)*++cur_str)) {
3910 (int)simple_strtoul(cur_str, NULL, 0);
3918 if ((argv = strchr(argv, ',')))
3923 int __init option_setup(char *str)
3929 TRACE2(("option_setup() str %s\n", str ? str:"NULL"));
3931 while (cur && isdigit(*cur) && i <= MAXHA) {
3932 ints[i++] = simple_strtoul(cur, NULL, 0);
3933 if ((cur = strchr(cur, ',')) != NULL) cur++;
3937 internal_setup(cur, ints);
3942 static int __init gdth_detect(struct scsi_host_template *shtp)
3945 printk("GDT: This driver contains debugging information !! Trace level = %d\n",
3947 printk(" Destination of debugging information: ");
3950 printk("Serial port COM2\n");
3952 printk("Serial port COM1\n");
3955 printk("Console\n");
3960 TRACE(("gdth_detect()\n"));
3963 printk("GDT-HA: Controller driver disabled from command line !\n");
3967 printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n",GDTH_VERSION_STR);
3968 /* initializations */
3969 gdth_polling = TRUE;
3970 gdth_clear_events();
3972 /* As default we do not probe for EISA or ISA controllers */
3973 if (probe_eisa_isa) {
3974 /* scanning for controllers, at first: ISA controller */
3977 for (isa_bios = 0xc8000UL; isa_bios <= 0xd8000UL;
3978 isa_bios += 0x8000UL) {
3979 if (gdth_ctr_count >= MAXHA)
3981 gdth_isa_probe_one(shtp, isa_bios);
3987 for (eisa_slot = 0x1000; eisa_slot <= 0x8000; eisa_slot += 0x1000) {
3988 if (gdth_ctr_count >= MAXHA)
3990 gdth_eisa_probe_one(shtp, eisa_slot);
3997 /* scanning for PCI controllers */
3999 gdth_pci_str pcistr[MAXHA];
4002 cnt = gdth_search_pci(pcistr);
4003 printk("GDT-HA: Found %d PCI Storage RAID Controllers\n",cnt);
4004 gdth_sort_pci(pcistr,cnt);
4005 for (ctr = 0; ctr < cnt; ++ctr) {
4006 if (gdth_ctr_count >= MAXHA)
4008 gdth_pci_probe_one(shtp, pcistr, ctr);
4011 #endif /* CONFIG_PCI */
4013 TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count));
4014 if (gdth_ctr_count > 0) {
4015 #ifdef GDTH_STATISTICS
4016 TRACE2(("gdth_detect(): Initializing timer !\n"));
4017 init_timer(&gdth_timer);
4018 gdth_timer.expires = jiffies + HZ;
4019 gdth_timer.data = 0L;
4020 gdth_timer.function = gdth_timeout;
4021 add_timer(&gdth_timer);
4023 major = register_chrdev(0,"gdth",&gdth_fops);
4024 notifier_disabled = 0;
4025 register_reboot_notifier(&gdth_notifier);
4027 gdth_polling = FALSE;
4028 return gdth_ctr_vcount;
4031 static int gdth_release(struct Scsi_Host *shp)
4036 TRACE2(("gdth_release()\n"));
4037 if (NUMDATA(shp)->busnum == 0) {
4038 hanum = NUMDATA(shp)->hanum;
4039 ha = HADATA(gdth_ctr_tab[hanum]);
4041 scsi_free_host_dev(ha->sdev);
4047 free_irq(shp->irq,ha);
4050 if (shp->dma_channel != 0xff) {
4051 free_dma(shp->dma_channel);
4056 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4057 MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys);
4060 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4061 ha->pscratch, ha->scratch_phys);
4063 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4064 ha->pmsg, ha->msg_phys);
4066 pci_unmap_single(ha->pdev,ha->ccb_phys,
4067 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
4068 gdth_ctr_released++;
4069 TRACE2(("gdth_release(): HA %d of %d\n",
4070 gdth_ctr_released, gdth_ctr_count));
4072 if (gdth_ctr_released == gdth_ctr_count) {
4073 #ifdef GDTH_STATISTICS
4074 del_timer(&gdth_timer);
4076 unregister_chrdev(major,"gdth");
4077 unregister_reboot_notifier(&gdth_notifier);
4081 scsi_unregister(shp);
4086 static const char *gdth_ctr_name(int hanum)
4090 TRACE2(("gdth_ctr_name()\n"));
4092 ha = HADATA(gdth_ctr_tab[hanum]);
4094 if (ha->type == GDT_EISA) {
4095 switch (ha->stype) {
4097 return("GDT3000/3020");
4099 return("GDT3000A/3020A/3050A");
4101 return("GDT3000B/3010A");
4103 } else if (ha->type == GDT_ISA) {
4104 return("GDT2000/2020");
4105 } else if (ha->type == GDT_PCI) {
4106 switch (ha->pdev->device) {
4107 case PCI_DEVICE_ID_VORTEX_GDT60x0:
4108 return("GDT6000/6020/6050");
4109 case PCI_DEVICE_ID_VORTEX_GDT6000B:
4110 return("GDT6000B/6010");
4113 /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
4118 static const char *gdth_info(struct Scsi_Host *shp)
4123 TRACE2(("gdth_info()\n"));
4124 hanum = NUMDATA(shp)->hanum;
4125 ha = HADATA(gdth_ctr_tab[hanum]);
4127 return ((const char *)ha->binfo.type_string);
4130 static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
4138 TRACE2(("gdth_eh_bus_reset()\n"));
4140 hanum = NUMDATA(scp->device->host)->hanum;
4141 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
4142 ha = HADATA(gdth_ctr_tab[hanum]);
4144 /* clear command tab */
4145 spin_lock_irqsave(&ha->smp_lock, flags);
4146 for (i = 0; i < GDTH_MAXCMDS; ++i) {
4147 cmnd = ha->cmd_tab[i].cmnd;
4148 if (!SPECIAL_SCP(cmnd) && cmnd->device->channel == b)
4149 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4151 spin_unlock_irqrestore(&ha->smp_lock, flags);
4153 if (b == ha->virt_bus) {
4155 for (i = 0; i < MAX_HDRIVES; ++i) {
4156 if (ha->hdr[i].present) {
4157 spin_lock_irqsave(&ha->smp_lock, flags);
4158 gdth_polling = TRUE;
4159 while (gdth_test_busy(hanum))
4161 if (gdth_internal_cmd(hanum, CACHESERVICE,
4162 GDT_CLUST_RESET, i, 0, 0))
4163 ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED;
4164 gdth_polling = FALSE;
4165 spin_unlock_irqrestore(&ha->smp_lock, flags);
4170 spin_lock_irqsave(&ha->smp_lock, flags);
4171 for (i = 0; i < MAXID; ++i)
4172 ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0;
4173 gdth_polling = TRUE;
4174 while (gdth_test_busy(hanum))
4176 gdth_internal_cmd(hanum, SCSIRAWSERVICE, GDT_RESET_BUS,
4177 BUS_L2P(ha,b), 0, 0);
4178 gdth_polling = FALSE;
4179 spin_unlock_irqrestore(&ha->smp_lock, flags);
4184 static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip)
4189 struct scsi_device *sd;
4194 hanum = NUMDATA(sd->host)->hanum;
4195 b = virt_ctr ? NUMDATA(sd->host)->busnum : sd->channel;
4197 TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", hanum, b, t));
4198 ha = HADATA(gdth_ctr_tab[hanum]);
4200 if (b != ha->virt_bus || ha->hdr[t].heads == 0) {
4201 /* raw device or host drive without mapping information */
4202 TRACE2(("Evaluate mapping\n"));
4203 gdth_eval_mapping(capacity,&ip[2],&ip[0],&ip[1]);
4205 ip[0] = ha->hdr[t].heads;
4206 ip[1] = ha->hdr[t].secs;
4207 ip[2] = capacity / ip[0] / ip[1];
4210 TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
4211 ip[0],ip[1],ip[2]));
4216 static int gdth_queuecommand(struct scsi_cmnd *scp,
4217 void (*done)(struct scsi_cmnd *))
4222 TRACE(("gdth_queuecommand() cmd 0x%x\n", scp->cmnd[0]));
4224 scp->scsi_done = done;
4225 scp->SCp.have_data_in = 1;
4226 scp->SCp.phase = -1;
4227 scp->SCp.sent_command = -1;
4228 scp->SCp.Status = GDTH_MAP_NONE;
4229 scp->SCp.buffer = (struct scatterlist *)NULL;
4231 hanum = NUMDATA(scp->device->host)->hanum;
4232 #ifdef GDTH_STATISTICS
4236 priority = DEFAULT_PRI;
4237 if (IS_GDTH_INTERNAL_CMD(scp))
4238 priority = scp->SCp.this_residual;
4240 gdth_update_timeout(hanum, scp, scp->timeout_per_command * 6);
4242 gdth_putq( hanum, scp, priority );
4248 static int gdth_open(struct inode *inode, struct file *filep)
4253 for (i = 0; i < gdth_ctr_count; i++) {
4254 ha = HADATA(gdth_ctr_tab[i]);
4256 ha->sdev = scsi_get_host_dev(gdth_ctr_tab[i]);
4259 TRACE(("gdth_open()\n"));
4263 static int gdth_close(struct inode *inode, struct file *filep)
4265 TRACE(("gdth_close()\n"));
4269 static int ioc_event(void __user *arg)
4271 gdth_ioctl_event evt;
4275 if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event)) ||
4276 evt.ionode >= gdth_ctr_count)
4278 ha = HADATA(gdth_ctr_tab[evt.ionode]);
4280 if (evt.erase == 0xff) {
4281 if (evt.event.event_source == ES_TEST)
4282 evt.event.event_data.size=sizeof(evt.event.event_data.eu.test);
4283 else if (evt.event.event_source == ES_DRIVER)
4284 evt.event.event_data.size=sizeof(evt.event.event_data.eu.driver);
4285 else if (evt.event.event_source == ES_SYNC)
4286 evt.event.event_data.size=sizeof(evt.event.event_data.eu.sync);
4288 evt.event.event_data.size=sizeof(evt.event.event_data.eu.async);
4289 spin_lock_irqsave(&ha->smp_lock, flags);
4290 gdth_store_event(ha, evt.event.event_source, evt.event.event_idx,
4291 &evt.event.event_data);
4292 spin_unlock_irqrestore(&ha->smp_lock, flags);
4293 } else if (evt.erase == 0xfe) {
4294 gdth_clear_events();
4295 } else if (evt.erase == 0) {
4296 evt.handle = gdth_read_event(ha, evt.handle, &evt.event);
4298 gdth_readapp_event(ha, evt.erase, &evt.event);
4300 if (copy_to_user(arg, &evt, sizeof(gdth_ioctl_event)))
4305 static int ioc_lockdrv(void __user *arg)
4307 gdth_ioctl_lockdrv ldrv;
4312 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)) ||
4313 ldrv.ionode >= gdth_ctr_count)
4315 ha = HADATA(gdth_ctr_tab[ldrv.ionode]);
4317 for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) {
4319 if (j >= MAX_HDRIVES || !ha->hdr[j].present)
4322 spin_lock_irqsave(&ha->smp_lock, flags);
4323 ha->hdr[j].lock = 1;
4324 spin_unlock_irqrestore(&ha->smp_lock, flags);
4325 gdth_wait_completion(ldrv.ionode, ha->bus_cnt, j);
4326 gdth_stop_timeout(ldrv.ionode, ha->bus_cnt, j);
4328 spin_lock_irqsave(&ha->smp_lock, flags);
4329 ha->hdr[j].lock = 0;
4330 spin_unlock_irqrestore(&ha->smp_lock, flags);
4331 gdth_start_timeout(ldrv.ionode, ha->bus_cnt, j);
4332 gdth_next(ldrv.ionode);
4338 static int ioc_resetdrv(void __user *arg, char *cmnd)
4340 gdth_ioctl_reset res;
4346 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
4347 res.ionode >= gdth_ctr_count || res.number >= MAX_HDRIVES)
4350 ha = HADATA(gdth_ctr_tab[hanum]);
4352 if (!ha->hdr[res.number].present)
4354 memset(&cmd, 0, sizeof(gdth_cmd_str));
4355 cmd.Service = CACHESERVICE;
4356 cmd.OpCode = GDT_CLUST_RESET;
4357 if (ha->cache_feat & GDT_64BIT)
4358 cmd.u.cache64.DeviceNo = res.number;
4360 cmd.u.cache.DeviceNo = res.number;
4362 rval = __gdth_execute(ha->sdev, &cmd, cmnd, 30, NULL);
4367 if (copy_to_user(arg, &res, sizeof(gdth_ioctl_reset)))
4372 static int ioc_general(void __user *arg, char *cmnd)
4374 gdth_ioctl_general gen;
4381 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)) ||
4382 gen.ionode >= gdth_ctr_count)
4385 ha = HADATA(gdth_ctr_tab[hanum]);
4386 if (gen.data_len + gen.sense_len != 0) {
4387 if (!(buf = gdth_ioctl_alloc(hanum, gen.data_len + gen.sense_len,
4390 if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general),
4391 gen.data_len + gen.sense_len)) {
4392 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
4396 if (gen.command.OpCode == GDT_IOCTL) {
4397 gen.command.u.ioctl.p_param = paddr;
4398 } else if (gen.command.Service == CACHESERVICE) {
4399 if (ha->cache_feat & GDT_64BIT) {
4400 /* copy elements from 32-bit IOCTL structure */
4401 gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt;
4402 gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo;
4403 gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo;
4405 if (ha->cache_feat & SCATTER_GATHER) {
4406 gen.command.u.cache64.DestAddr = (ulong64)-1;
4407 gen.command.u.cache64.sg_canz = 1;
4408 gen.command.u.cache64.sg_lst[0].sg_ptr = paddr;
4409 gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len;
4410 gen.command.u.cache64.sg_lst[1].sg_len = 0;
4412 gen.command.u.cache64.DestAddr = paddr;
4413 gen.command.u.cache64.sg_canz = 0;
4416 if (ha->cache_feat & SCATTER_GATHER) {
4417 gen.command.u.cache.DestAddr = 0xffffffff;
4418 gen.command.u.cache.sg_canz = 1;
4419 gen.command.u.cache.sg_lst[0].sg_ptr = (ulong32)paddr;
4420 gen.command.u.cache.sg_lst[0].sg_len = gen.data_len;
4421 gen.command.u.cache.sg_lst[1].sg_len = 0;
4423 gen.command.u.cache.DestAddr = paddr;
4424 gen.command.u.cache.sg_canz = 0;
4427 } else if (gen.command.Service == SCSIRAWSERVICE) {
4428 if (ha->raw_feat & GDT_64BIT) {
4429 /* copy elements from 32-bit IOCTL structure */
4431 gen.command.u.raw64.sense_len = gen.command.u.raw.sense_len;
4432 gen.command.u.raw64.bus = gen.command.u.raw.bus;
4433 gen.command.u.raw64.lun = gen.command.u.raw.lun;
4434 gen.command.u.raw64.target = gen.command.u.raw.target;
4435 memcpy(cmd, gen.command.u.raw.cmd, 16);
4436 memcpy(gen.command.u.raw64.cmd, cmd, 16);
4437 gen.command.u.raw64.clen = gen.command.u.raw.clen;
4438 gen.command.u.raw64.sdlen = gen.command.u.raw.sdlen;
4439 gen.command.u.raw64.direction = gen.command.u.raw.direction;
4441 if (ha->raw_feat & SCATTER_GATHER) {
4442 gen.command.u.raw64.sdata = (ulong64)-1;
4443 gen.command.u.raw64.sg_ranz = 1;
4444 gen.command.u.raw64.sg_lst[0].sg_ptr = paddr;
4445 gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len;
4446 gen.command.u.raw64.sg_lst[1].sg_len = 0;
4448 gen.command.u.raw64.sdata = paddr;
4449 gen.command.u.raw64.sg_ranz = 0;
4451 gen.command.u.raw64.sense_data = paddr + gen.data_len;
4453 if (ha->raw_feat & SCATTER_GATHER) {
4454 gen.command.u.raw.sdata = 0xffffffff;
4455 gen.command.u.raw.sg_ranz = 1;
4456 gen.command.u.raw.sg_lst[0].sg_ptr = (ulong32)paddr;
4457 gen.command.u.raw.sg_lst[0].sg_len = gen.data_len;
4458 gen.command.u.raw.sg_lst[1].sg_len = 0;
4460 gen.command.u.raw.sdata = paddr;
4461 gen.command.u.raw.sg_ranz = 0;
4463 gen.command.u.raw.sense_data = (ulong32)paddr + gen.data_len;
4466 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
4471 rval = __gdth_execute(ha->sdev, &gen.command, cmnd, gen.timeout, &gen.info);
4476 if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf,
4477 gen.data_len + gen.sense_len)) {
4478 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
4481 if (copy_to_user(arg, &gen,
4482 sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) {
4483 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
4486 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
4490 static int ioc_hdrlist(void __user *arg, char *cmnd)
4492 gdth_ioctl_rescan *rsc;
4496 int hanum, rc = -ENOMEM;
4497 u32 cluster_type = 0;
4499 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
4500 cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
4504 if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
4505 rsc->ionode >= gdth_ctr_count) {
4509 hanum = rsc->ionode;
4510 ha = HADATA(gdth_ctr_tab[hanum]);
4511 memset(cmd, 0, sizeof(gdth_cmd_str));
4513 for (i = 0; i < MAX_HDRIVES; ++i) {
4514 if (!ha->hdr[i].present) {
4515 rsc->hdr_list[i].bus = 0xff;
4518 rsc->hdr_list[i].bus = ha->virt_bus;
4519 rsc->hdr_list[i].target = i;
4520 rsc->hdr_list[i].lun = 0;
4521 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
4522 if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) {
4523 cmd->Service = CACHESERVICE;
4524 cmd->OpCode = GDT_CLUST_INFO;
4525 if (ha->cache_feat & GDT_64BIT)
4526 cmd->u.cache64.DeviceNo = i;
4528 cmd->u.cache.DeviceNo = i;
4529 if (__gdth_execute(ha->sdev, cmd, cmnd, 30, &cluster_type) == S_OK)
4530 rsc->hdr_list[i].cluster_type = cluster_type;
4534 if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
4545 static int ioc_rescan(void __user *arg, char *cmnd)
4547 gdth_ioctl_rescan *rsc;
4549 ushort i, status, hdr_cnt;
4551 int hanum, cyls, hds, secs;
4556 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
4557 cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
4561 if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
4562 rsc->ionode >= gdth_ctr_count) {
4566 hanum = rsc->ionode;
4567 ha = HADATA(gdth_ctr_tab[hanum]);
4568 memset(cmd, 0, sizeof(gdth_cmd_str));
4570 if (rsc->flag == 0) {
4571 /* old method: re-init. cache service */
4572 cmd->Service = CACHESERVICE;
4573 if (ha->cache_feat & GDT_64BIT) {
4574 cmd->OpCode = GDT_X_INIT_HOST;
4575 cmd->u.cache64.DeviceNo = LINUX_OS;
4577 cmd->OpCode = GDT_INIT;
4578 cmd->u.cache.DeviceNo = LINUX_OS;
4581 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4583 hdr_cnt = (status == S_OK ? (ushort)info : 0);
4589 for (; i < hdr_cnt && i < MAX_HDRIVES; ++i) {
4590 cmd->Service = CACHESERVICE;
4591 cmd->OpCode = GDT_INFO;
4592 if (ha->cache_feat & GDT_64BIT)
4593 cmd->u.cache64.DeviceNo = i;
4595 cmd->u.cache.DeviceNo = i;
4597 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4599 spin_lock_irqsave(&ha->smp_lock, flags);
4600 rsc->hdr_list[i].bus = ha->virt_bus;
4601 rsc->hdr_list[i].target = i;
4602 rsc->hdr_list[i].lun = 0;
4603 if (status != S_OK) {
4604 ha->hdr[i].present = FALSE;
4606 ha->hdr[i].present = TRUE;
4607 ha->hdr[i].size = info;
4608 /* evaluate mapping */
4609 ha->hdr[i].size &= ~SECS32;
4610 gdth_eval_mapping(ha->hdr[i].size,&cyls,&hds,&secs);
4611 ha->hdr[i].heads = hds;
4612 ha->hdr[i].secs = secs;
4614 ha->hdr[i].size = cyls * hds * secs;
4616 spin_unlock_irqrestore(&ha->smp_lock, flags);
4620 /* extended info, if GDT_64BIT, for drives > 2 TB */
4621 /* but we need ha->info2, not yet stored in scp->SCp */
4623 /* devtype, cluster info, R/W attribs */
4624 cmd->Service = CACHESERVICE;
4625 cmd->OpCode = GDT_DEVTYPE;
4626 if (ha->cache_feat & GDT_64BIT)
4627 cmd->u.cache64.DeviceNo = i;
4629 cmd->u.cache.DeviceNo = i;
4631 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4633 spin_lock_irqsave(&ha->smp_lock, flags);
4634 ha->hdr[i].devtype = (status == S_OK ? (ushort)info : 0);
4635 spin_unlock_irqrestore(&ha->smp_lock, flags);
4637 cmd->Service = CACHESERVICE;
4638 cmd->OpCode = GDT_CLUST_INFO;
4639 if (ha->cache_feat & GDT_64BIT)
4640 cmd->u.cache64.DeviceNo = i;
4642 cmd->u.cache.DeviceNo = i;
4644 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4646 spin_lock_irqsave(&ha->smp_lock, flags);
4647 ha->hdr[i].cluster_type =
4648 ((status == S_OK && !shared_access) ? (ushort)info : 0);
4649 spin_unlock_irqrestore(&ha->smp_lock, flags);
4650 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
4652 cmd->Service = CACHESERVICE;
4653 cmd->OpCode = GDT_RW_ATTRIBS;
4654 if (ha->cache_feat & GDT_64BIT)
4655 cmd->u.cache64.DeviceNo = i;
4657 cmd->u.cache.DeviceNo = i;
4659 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4661 spin_lock_irqsave(&ha->smp_lock, flags);
4662 ha->hdr[i].rw_attribs = (status == S_OK ? (ushort)info : 0);
4663 spin_unlock_irqrestore(&ha->smp_lock, flags);
4666 if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
4677 static int gdth_ioctl(struct inode *inode, struct file *filep,
4678 unsigned int cmd, unsigned long arg)
4683 char cmnd[MAX_COMMAND_SIZE];
4684 void __user *argp = (void __user *)arg;
4686 memset(cmnd, 0xff, 12);
4688 TRACE(("gdth_ioctl() cmd 0x%x\n", cmd));
4691 case GDTIOCTL_CTRCNT:
4693 int cnt = gdth_ctr_count;
4694 if (put_user(cnt, (int __user *)argp))
4699 case GDTIOCTL_DRVERS:
4701 int ver = (GDTH_VERSION<<8) | GDTH_SUBVERSION;
4702 if (put_user(ver, (int __user *)argp))
4707 case GDTIOCTL_OSVERS:
4709 gdth_ioctl_osvers osv;
4711 osv.version = (unchar)(LINUX_VERSION_CODE >> 16);
4712 osv.subversion = (unchar)(LINUX_VERSION_CODE >> 8);
4713 osv.revision = (ushort)(LINUX_VERSION_CODE & 0xff);
4714 if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers)))
4719 case GDTIOCTL_CTRTYPE:
4721 gdth_ioctl_ctrtype ctrt;
4723 if (copy_from_user(&ctrt, argp, sizeof(gdth_ioctl_ctrtype)) ||
4724 ctrt.ionode >= gdth_ctr_count)
4726 ha = HADATA(gdth_ctr_tab[ctrt.ionode]);
4727 if (ha->type == GDT_ISA || ha->type == GDT_EISA) {
4728 ctrt.type = (unchar)((ha->stype>>20) - 0x10);
4730 if (ha->type != GDT_PCIMPR) {
4731 ctrt.type = (unchar)((ha->stype<<4) + 6);
4734 (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe);
4735 if (ha->stype >= 0x300)
4736 ctrt.ext_type = 0x6000 | ha->pdev->subsystem_device;
4738 ctrt.ext_type = 0x6000 | ha->stype;
4740 ctrt.device_id = ha->pdev->device;
4741 ctrt.sub_device_id = ha->pdev->subsystem_device;
4743 ctrt.info = ha->brd_phys;
4744 ctrt.oem_id = ha->oem_id;
4745 if (copy_to_user(argp, &ctrt, sizeof(gdth_ioctl_ctrtype)))
4750 case GDTIOCTL_GENERAL:
4751 return ioc_general(argp, cmnd);
4753 case GDTIOCTL_EVENT:
4754 return ioc_event(argp);
4756 case GDTIOCTL_LOCKDRV:
4757 return ioc_lockdrv(argp);
4759 case GDTIOCTL_LOCKCHN:
4761 gdth_ioctl_lockchn lchn;
4764 if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) ||
4765 lchn.ionode >= gdth_ctr_count)
4767 ha = HADATA(gdth_ctr_tab[lchn.ionode]);
4770 if (i < ha->bus_cnt) {
4772 spin_lock_irqsave(&ha->smp_lock, flags);
4773 ha->raw[i].lock = 1;
4774 spin_unlock_irqrestore(&ha->smp_lock, flags);
4775 for (j = 0; j < ha->tid_cnt; ++j) {
4776 gdth_wait_completion(lchn.ionode, i, j);
4777 gdth_stop_timeout(lchn.ionode, i, j);
4780 spin_lock_irqsave(&ha->smp_lock, flags);
4781 ha->raw[i].lock = 0;
4782 spin_unlock_irqrestore(&ha->smp_lock, flags);
4783 for (j = 0; j < ha->tid_cnt; ++j) {
4784 gdth_start_timeout(lchn.ionode, i, j);
4785 gdth_next(lchn.ionode);
4792 case GDTIOCTL_RESCAN:
4793 return ioc_rescan(argp, cmnd);
4795 case GDTIOCTL_HDRLIST:
4796 return ioc_hdrlist(argp, cmnd);
4798 case GDTIOCTL_RESET_BUS:
4800 gdth_ioctl_reset res;
4803 if (copy_from_user(&res, argp, sizeof(gdth_ioctl_reset)) ||
4804 res.ionode >= gdth_ctr_count)
4807 ha = HADATA(gdth_ctr_tab[hanum]);
4809 scp = kzalloc(sizeof(*scp), GFP_KERNEL);
4812 scp->device = ha->sdev;
4815 scp->device->channel = virt_ctr ? 0 : res.number;
4816 rval = gdth_eh_bus_reset(scp);
4817 res.status = (rval == SUCCESS ? S_OK : S_GENERR);
4820 if (copy_to_user(argp, &res, sizeof(gdth_ioctl_reset)))
4825 case GDTIOCTL_RESET_DRV:
4826 return ioc_resetdrv(argp, cmnd);
4836 static void gdth_flush(int hanum)
4840 gdth_cmd_str gdtcmd;
4841 char cmnd[MAX_COMMAND_SIZE];
4842 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
4844 TRACE2(("gdth_flush() hanum %d\n",hanum));
4845 ha = HADATA(gdth_ctr_tab[hanum]);
4847 for (i = 0; i < MAX_HDRIVES; ++i) {
4848 if (ha->hdr[i].present) {
4849 gdtcmd.BoardNode = LOCALBOARD;
4850 gdtcmd.Service = CACHESERVICE;
4851 gdtcmd.OpCode = GDT_FLUSH;
4852 if (ha->cache_feat & GDT_64BIT) {
4853 gdtcmd.u.cache64.DeviceNo = i;
4854 gdtcmd.u.cache64.BlockNo = 1;
4855 gdtcmd.u.cache64.sg_canz = 0;
4857 gdtcmd.u.cache.DeviceNo = i;
4858 gdtcmd.u.cache.BlockNo = 1;
4859 gdtcmd.u.cache.sg_canz = 0;
4861 TRACE2(("gdth_flush(): flush ha %d drive %d\n", hanum, i));
4863 gdth_execute(gdth_ctr_tab[hanum], &gdtcmd, cmnd, 30, NULL);
4868 /* shutdown routine */
4869 static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
4873 gdth_cmd_str gdtcmd;
4874 char cmnd[MAX_COMMAND_SIZE];
4877 if (notifier_disabled)
4880 TRACE2(("gdth_halt() event %d\n",(int)event));
4881 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
4884 notifier_disabled = 1;
4885 printk("GDT-HA: Flushing all host drives .. ");
4886 for (hanum = 0; hanum < gdth_ctr_count; ++hanum) {
4890 /* controller reset */
4891 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
4892 gdtcmd.BoardNode = LOCALBOARD;
4893 gdtcmd.Service = CACHESERVICE;
4894 gdtcmd.OpCode = GDT_RESET;
4895 TRACE2(("gdth_halt(): reset controller %d\n", hanum));
4896 gdth_execute(gdth_ctr_tab[hanum], &gdtcmd, cmnd, 10, NULL);
4901 #ifdef GDTH_STATISTICS
4902 del_timer(&gdth_timer);
4908 static int gdth_slave_configure(struct scsi_device *sdev)
4910 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
4911 sdev->skip_ms_page_3f = 1;
4912 sdev->skip_ms_page_8 = 1;
4916 static struct scsi_host_template driver_template = {
4917 .proc_name = "gdth",
4918 .proc_info = gdth_proc_info,
4919 .name = "GDT SCSI Disk Array Controller",
4920 .detect = gdth_detect,
4921 .release = gdth_release,
4923 .queuecommand = gdth_queuecommand,
4924 .eh_bus_reset_handler = gdth_eh_bus_reset,
4925 .bios_param = gdth_bios_param,
4926 .can_queue = GDTH_MAXCMDS,
4927 .slave_configure = gdth_slave_configure,
4929 .sg_tablesize = GDTH_MAXSG,
4930 .cmd_per_lun = GDTH_MAXC_P_L,
4931 .unchecked_isa_dma = 1,
4932 .use_clustering = ENABLE_CLUSTERING,
4936 static int gdth_isa_probe_one(struct scsi_host_template *shtp, ulong32 isa_bios)
4938 struct Scsi_Host *shp;
4940 dma_addr_t scratch_dma_handle = 0;
4941 int error, hanum, i;
4944 if (!gdth_search_isa(isa_bios))
4947 shp = scsi_register(shtp, sizeof(gdth_ext_str));
4953 if (!gdth_init_isa(isa_bios,ha))
4956 /* controller found and initialized */
4957 printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
4958 isa_bios, ha->irq, ha->drq);
4960 error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha);
4962 printk("GDT-ISA: Unable to allocate IRQ\n");
4966 error = request_dma(ha->drq, "gdth");
4968 printk("GDT-ISA: Unable to allocate DMA channel\n");
4972 set_dma_mode(ha->drq,DMA_MODE_CASCADE);
4973 enable_dma(ha->drq);
4974 shp->unchecked_isa_dma = 1;
4976 shp->dma_channel = ha->drq;
4977 hanum = gdth_ctr_count;
4978 gdth_ctr_tab[gdth_ctr_count++] = shp;
4979 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4981 NUMDATA(shp)->hanum = (ushort)hanum;
4982 NUMDATA(shp)->busnum= 0;
4984 ha->pccb = CMDDATA(shp);
4990 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4991 &scratch_dma_handle);
4993 goto out_dec_counters;
4994 ha->scratch_phys = scratch_dma_handle;
4996 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4997 &scratch_dma_handle);
4999 goto out_free_pscratch;
5000 ha->msg_phys = scratch_dma_handle;
5003 ha->coal_stat = pci_alloc_consistent(ha->pdev,
5004 sizeof(gdth_coal_status) * MAXOFFSETS,
5005 &scratch_dma_handle);
5008 ha->coal_stat_phys = scratch_dma_handle;
5011 ha->scratch_busy = FALSE;
5012 ha->req_first = NULL;
5013 ha->tid_cnt = MAX_HDRIVES;
5014 if (max_ids > 0 && max_ids < ha->tid_cnt)
5015 ha->tid_cnt = max_ids;
5016 for (i = 0; i < GDTH_MAXCMDS; ++i)
5017 ha->cmd_tab[i].cmnd = UNUSED_CMND;
5018 ha->scan_mode = rescan ? 0x10 : 0;
5021 if (!gdth_search_drives(hanum)) {
5022 printk("GDT-ISA: Error during device scan\n");
5023 goto out_free_coal_stat;
5026 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
5027 hdr_channel = ha->bus_cnt;
5028 ha->virt_bus = hdr_channel;
5030 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
5031 shp->max_cmd_len = 16;
5033 shp->max_id = ha->tid_cnt;
5034 shp->max_lun = MAXLUN;
5035 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
5038 /* register addit. SCSI channels as virtual controllers */
5039 for (b = 1; b < ha->bus_cnt + 1; ++b) {
5040 shp = scsi_register(shtp,sizeof(gdth_num_str));
5041 shp->unchecked_isa_dma = 1;
5043 shp->dma_channel = ha->drq;
5044 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
5045 NUMDATA(shp)->hanum = (ushort)hanum;
5046 NUMDATA(shp)->busnum = b;
5050 spin_lock_init(&ha->smp_lock);
5051 gdth_enable_int(hanum);
5057 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
5058 ha->coal_stat, ha->coal_stat_phys);
5061 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5062 ha->pmsg, ha->msg_phys);
5064 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5065 ha->pscratch, ha->scratch_phys);
5070 free_irq(ha->irq, ha);
5072 scsi_unregister(shp);
5075 #endif /* CONFIG_ISA */
5078 static int gdth_eisa_probe_one(struct scsi_host_template *shtp,
5081 struct Scsi_Host *shp;
5083 dma_addr_t scratch_dma_handle = 0;
5084 int error, hanum, i;
5087 if (!gdth_search_eisa(eisa_slot))
5090 shp = scsi_register(shtp,sizeof(gdth_ext_str));
5096 if (!gdth_init_eisa(eisa_slot,ha))
5099 /* controller found and initialized */
5100 printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
5101 eisa_slot >> 12, ha->irq);
5103 error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha);
5105 printk("GDT-EISA: Unable to allocate IRQ\n");
5109 shp->unchecked_isa_dma = 0;
5111 shp->dma_channel = 0xff;
5112 hanum = gdth_ctr_count;
5113 gdth_ctr_tab[gdth_ctr_count++] = shp;
5114 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
5116 NUMDATA(shp)->hanum = (ushort)hanum;
5117 NUMDATA(shp)->busnum= 0;
5118 TRACE2(("EISA detect Bus 0: hanum %d\n",
5119 NUMDATA(shp)->hanum));
5121 ha->pccb = CMDDATA(shp);
5127 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
5128 &scratch_dma_handle);
5131 ha->scratch_phys = scratch_dma_handle;
5133 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
5134 &scratch_dma_handle);
5136 goto out_free_pscratch;
5137 ha->msg_phys = scratch_dma_handle;
5140 ha->coal_stat = pci_alloc_consistent(ha->pdev,
5141 sizeof(gdth_coal_status) * MAXOFFSETS,
5142 &scratch_dma_handle);
5145 ha->coal_stat_phys = scratch_dma_handle;
5148 ha->ccb_phys = pci_map_single(ha->pdev,ha->pccb,
5149 sizeof(gdth_cmd_str), PCI_DMA_BIDIRECTIONAL);
5151 goto out_free_coal_stat;
5153 ha->scratch_busy = FALSE;
5154 ha->req_first = NULL;
5155 ha->tid_cnt = MAX_HDRIVES;
5156 if (max_ids > 0 && max_ids < ha->tid_cnt)
5157 ha->tid_cnt = max_ids;
5158 for (i = 0; i < GDTH_MAXCMDS; ++i)
5159 ha->cmd_tab[i].cmnd = UNUSED_CMND;
5160 ha->scan_mode = rescan ? 0x10 : 0;
5162 if (!gdth_search_drives(hanum)) {
5163 printk("GDT-EISA: Error during device scan\n");
5165 goto out_free_ccb_phys;
5168 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
5169 hdr_channel = ha->bus_cnt;
5170 ha->virt_bus = hdr_channel;
5172 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
5173 shp->max_cmd_len = 16;
5175 shp->max_id = ha->tid_cnt;
5176 shp->max_lun = MAXLUN;
5177 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
5180 /* register addit. SCSI channels as virtual controllers */
5181 for (b = 1; b < ha->bus_cnt + 1; ++b) {
5182 shp = scsi_register(shtp,sizeof(gdth_num_str));
5183 shp->unchecked_isa_dma = 0;
5185 shp->dma_channel = 0xff;
5186 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
5187 NUMDATA(shp)->hanum = (ushort)hanum;
5188 NUMDATA(shp)->busnum = b;
5192 spin_lock_init(&ha->smp_lock);
5193 gdth_enable_int(hanum);
5197 pci_unmap_single(ha->pdev,ha->ccb_phys, sizeof(gdth_cmd_str),
5198 PCI_DMA_BIDIRECTIONAL);
5201 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
5202 ha->coal_stat, ha->coal_stat_phys);
5205 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5206 ha->pmsg, ha->msg_phys);
5208 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5209 ha->pscratch, ha->scratch_phys);
5211 free_irq(ha->irq, ha);
5215 scsi_unregister(shp);
5218 #endif /* CONFIG_EISA */
5221 static int gdth_pci_probe_one(struct scsi_host_template *shtp,
5222 gdth_pci_str *pcistr, int ctr)
5224 struct Scsi_Host *shp;
5226 dma_addr_t scratch_dma_handle = 0;
5227 int error, hanum, i;
5230 shp = scsi_register(shtp,sizeof(gdth_ext_str));
5236 if (!gdth_init_pci(&pcistr[ctr],ha))
5239 /* controller found and initialized */
5240 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
5241 pcistr[ctr].pdev->bus->number,
5242 PCI_SLOT(pcistr[ctr].pdev->devfn),
5245 error = request_irq(ha->irq, gdth_interrupt,
5246 IRQF_DISABLED|IRQF_SHARED, "gdth", ha);
5248 printk("GDT-PCI: Unable to allocate IRQ\n");
5252 shp->unchecked_isa_dma = 0;
5254 shp->dma_channel = 0xff;
5255 hanum = gdth_ctr_count;
5256 gdth_ctr_tab[gdth_ctr_count++] = shp;
5257 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
5259 NUMDATA(shp)->hanum = (ushort)hanum;
5260 NUMDATA(shp)->busnum= 0;
5262 ha->pccb = CMDDATA(shp);
5267 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
5268 &scratch_dma_handle);
5271 ha->scratch_phys = scratch_dma_handle;
5273 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
5274 &scratch_dma_handle);
5276 goto out_free_pscratch;
5277 ha->msg_phys = scratch_dma_handle;
5280 ha->coal_stat = pci_alloc_consistent(ha->pdev,
5281 sizeof(gdth_coal_status) * MAXOFFSETS,
5282 &scratch_dma_handle);
5285 ha->coal_stat_phys = scratch_dma_handle;
5288 ha->scratch_busy = FALSE;
5289 ha->req_first = NULL;
5290 ha->tid_cnt = pcistr[ctr].pdev->device >= 0x200 ? MAXID : MAX_HDRIVES;
5291 if (max_ids > 0 && max_ids < ha->tid_cnt)
5292 ha->tid_cnt = max_ids;
5293 for (i = 0; i < GDTH_MAXCMDS; ++i)
5294 ha->cmd_tab[i].cmnd = UNUSED_CMND;
5295 ha->scan_mode = rescan ? 0x10 : 0;
5298 if (!gdth_search_drives(hanum)) {
5299 printk("GDT-PCI %d: Error during device scan\n", hanum);
5300 goto out_free_coal_stat;
5303 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
5304 hdr_channel = ha->bus_cnt;
5305 ha->virt_bus = hdr_channel;
5307 /* 64-bit DMA only supported from FW >= x.43 */
5308 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) ||
5309 !ha->dma64_support) {
5310 if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
5311 printk(KERN_WARNING "GDT-PCI %d: "
5312 "Unable to set 32-bit DMA\n", hanum);
5313 goto out_free_coal_stat;
5316 shp->max_cmd_len = 16;
5317 if (!pci_set_dma_mask(pcistr[ctr].pdev, DMA_64BIT_MASK)) {
5318 printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);
5319 } else if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
5320 printk(KERN_WARNING "GDT-PCI %d: "
5321 "Unable to set 64/32-bit DMA\n", hanum);
5322 goto out_free_coal_stat;
5326 shp->max_id = ha->tid_cnt;
5327 shp->max_lun = MAXLUN;
5328 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
5331 /* register addit. SCSI channels as virtual controllers */
5332 for (b = 1; b < ha->bus_cnt + 1; ++b) {
5333 shp = scsi_register(shtp,sizeof(gdth_num_str));
5334 shp->unchecked_isa_dma = 0;
5336 shp->dma_channel = 0xff;
5337 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
5338 NUMDATA(shp)->hanum = (ushort)hanum;
5339 NUMDATA(shp)->busnum = b;
5343 spin_lock_init(&ha->smp_lock);
5344 gdth_enable_int(hanum);
5349 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
5350 ha->coal_stat, ha->coal_stat_phys);
5353 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5354 ha->pmsg, ha->msg_phys);
5356 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5357 ha->pscratch, ha->scratch_phys);
5359 free_irq(ha->irq, ha);
5363 scsi_unregister(shp);
5366 #endif /* CONFIG_PCI */
5368 #include "scsi_module.c"
5370 __setup("gdth=", option_setup);