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 * hdr_channel:x x - number of virtual bus for host drives
60 * shared_access:Y disable driver reserve/release protocol to
61 * access a shared resource from several nodes,
62 * appropriate controller firmware required
63 * shared_access:N enable driver reserve/release protocol
64 * probe_eisa_isa:Y scan for EISA/ISA controllers
65 * probe_eisa_isa:N do not scan for EISA/ISA controllers
66 * force_dma32:Y use only 32 bit DMA mode
67 * force_dma32:N use 64 bit DMA mode, if supported
69 * The default values are: "gdth=disable:N,reserve_mode:1,reverse_scan:N,
70 * max_ids:127,rescan:N,hdr_channel:0,
71 * shared_access:Y,probe_eisa_isa:N,force_dma32:N".
72 * Here is another example: "gdth=reserve_list:0,1,2,0,0,1,3,0,rescan:Y".
74 * When loading the gdth driver as a module, the same options are available.
75 * You can set the IRQs with "IRQ=...". However, the syntax to specify the
76 * options changes slightly. You must replace all ',' between options
77 * with ' ' and all ':' with '=' and you must use
78 * '1' in place of 'Y' and '0' in place of 'N'.
80 * Default: "modprobe gdth disable=0 reserve_mode=1 reverse_scan=0
81 * max_ids=127 rescan=0 hdr_channel=0 shared_access=0
82 * probe_eisa_isa=0 force_dma32=0"
83 * The other example: "modprobe gdth reserve_list=0,1,2,0,0,1,3,0 rescan=1".
86 /* The meaning of the Scsi_Pointer members in this driver is as follows:
88 * this_residual: unused
91 * buffers_residual: unused
94 * have_data_in: unused
95 * sent_command: unused
100 /* interrupt coalescing */
101 /* #define INT_COAL */
104 #define GDTH_STATISTICS
106 #include <linux/module.h>
108 #include <linux/version.h>
109 #include <linux/kernel.h>
110 #include <linux/types.h>
111 #include <linux/pci.h>
112 #include <linux/string.h>
113 #include <linux/ctype.h>
114 #include <linux/ioport.h>
115 #include <linux/delay.h>
116 #include <linux/interrupt.h>
117 #include <linux/in.h>
118 #include <linux/proc_fs.h>
119 #include <linux/time.h>
120 #include <linux/timer.h>
121 #include <linux/dma-mapping.h>
122 #include <linux/list.h>
125 #include <linux/mc146818rtc.h>
127 #include <linux/reboot.h>
130 #include <asm/system.h>
132 #include <asm/uaccess.h>
133 #include <linux/spinlock.h>
134 #include <linux/blkdev.h>
135 #include <linux/scatterlist.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 irqreturn_t
__gdth_interrupt(gdth_ha_str
*ha
,
145 int gdth_from_wait
, int* pIndex
);
146 static int gdth_sync_event(gdth_ha_str
*ha
, int service
, unchar index
,
148 static int gdth_async_event(gdth_ha_str
*ha
);
149 static void gdth_log_event(gdth_evt_data
*dvr
, char *buffer
);
151 static void gdth_putq(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
, unchar priority
);
152 static void gdth_next(gdth_ha_str
*ha
);
153 static int gdth_fill_raw_cmd(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
, unchar b
);
154 static int gdth_special_cmd(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
);
155 static gdth_evt_str
*gdth_store_event(gdth_ha_str
*ha
, ushort source
,
156 ushort idx
, gdth_evt_data
*evt
);
157 static int gdth_read_event(gdth_ha_str
*ha
, int handle
, gdth_evt_str
*estr
);
158 static void gdth_readapp_event(gdth_ha_str
*ha
, unchar application
,
160 static void gdth_clear_events(void);
162 static void gdth_copy_internal_data(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
,
163 char *buffer
, ushort count
);
164 static int gdth_internal_cache_cmd(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
);
165 static int gdth_fill_cache_cmd(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
, ushort hdrive
);
167 static void gdth_enable_int(gdth_ha_str
*ha
);
168 static int gdth_test_busy(gdth_ha_str
*ha
);
169 static int gdth_get_cmd_index(gdth_ha_str
*ha
);
170 static void gdth_release_event(gdth_ha_str
*ha
);
171 static int gdth_wait(gdth_ha_str
*ha
, int index
,ulong32 time
);
172 static int gdth_internal_cmd(gdth_ha_str
*ha
, unchar service
, ushort opcode
,
173 ulong32 p1
, ulong64 p2
,ulong64 p3
);
174 static int gdth_search_drives(gdth_ha_str
*ha
);
175 static int gdth_analyse_hdrive(gdth_ha_str
*ha
, ushort hdrive
);
177 static const char *gdth_ctr_name(gdth_ha_str
*ha
);
179 static int gdth_open(struct inode
*inode
, struct file
*filep
);
180 static int gdth_close(struct inode
*inode
, struct file
*filep
);
181 static int gdth_ioctl(struct inode
*inode
, struct file
*filep
,
182 unsigned int cmd
, unsigned long arg
);
184 static void gdth_flush(gdth_ha_str
*ha
);
185 static int gdth_queuecommand(Scsi_Cmnd
*scp
,void (*done
)(Scsi_Cmnd
*));
186 static int __gdth_queuecommand(gdth_ha_str
*ha
, struct scsi_cmnd
*scp
,
187 struct gdth_cmndinfo
*cmndinfo
);
188 static void gdth_scsi_done(struct scsi_cmnd
*scp
);
191 static unchar DebugState
= DEBUG_GDTH
;
194 #define MAX_SERBUF 160
195 static void ser_init(void);
196 static void ser_puts(char *str
);
197 static void ser_putc(char c
);
198 static int ser_printk(const char *fmt
, ...);
199 static char strbuf
[MAX_SERBUF
+1];
201 #define COM_BASE 0x2f8
203 #define COM_BASE 0x3f8
205 static void ser_init()
207 unsigned port
=COM_BASE
;
211 /* 19200 Baud, if 9600: outb(12,port) */
221 static void ser_puts(char *str
)
226 for (ptr
=str
;*ptr
;++ptr
)
230 static void ser_putc(char c
)
232 unsigned port
=COM_BASE
;
234 while ((inb(port
+5) & 0x20)==0);
238 while ((inb(port
+5) & 0x20)==0);
243 static int ser_printk(const char *fmt
, ...)
249 i
= vsprintf(strbuf
,fmt
,args
);
255 #define TRACE(a) {if (DebugState==1) {ser_printk a;}}
256 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}}
257 #define TRACE3(a) {if (DebugState!=0) {ser_printk a;}}
259 #else /* !__SERIAL__ */
260 #define TRACE(a) {if (DebugState==1) {printk a;}}
261 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {printk a;}}
262 #define TRACE3(a) {if (DebugState!=0) {printk a;}}
271 #ifdef GDTH_STATISTICS
272 static ulong32 max_rq
=0, max_index
=0, max_sg
=0;
274 static ulong32 max_int_coal
=0;
276 static ulong32 act_ints
=0, act_ios
=0, act_stats
=0, act_rq
=0;
277 static struct timer_list gdth_timer
;
280 #define PTR2USHORT(a) (ushort)(ulong)(a)
281 #define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b)
282 #define INDEX_OK(i,t) ((i)<ARRAY_SIZE(t))
284 #define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b))
287 static unchar gdth_drq_tab
[4] = {5,6,7,7}; /* DRQ table */
289 #if defined(CONFIG_EISA) || defined(CONFIG_ISA)
290 static unchar gdth_irq_tab
[6] = {0,10,11,12,14,0}; /* IRQ table */
292 static unchar gdth_polling
; /* polling if TRUE */
293 static int gdth_ctr_count
= 0; /* controller count */
294 static LIST_HEAD(gdth_instances
); /* controller list */
295 static unchar gdth_write_through
= FALSE
; /* write through */
296 static gdth_evt_str ebuffer
[MAX_EVENTS
]; /* event buffer */
301 #define DIN 1 /* IN data direction */
302 #define DOU 2 /* OUT data direction */
303 #define DNO DIN /* no data transfer */
304 #define DUN DIN /* unknown data direction */
305 static unchar gdth_direction_tab
[0x100] = {
306 DNO
,DNO
,DIN
,DIN
,DOU
,DIN
,DIN
,DOU
,DIN
,DUN
,DOU
,DOU
,DUN
,DUN
,DUN
,DIN
,
307 DNO
,DIN
,DIN
,DOU
,DIN
,DOU
,DNO
,DNO
,DOU
,DNO
,DIN
,DNO
,DIN
,DOU
,DNO
,DUN
,
308 DIN
,DUN
,DIN
,DUN
,DOU
,DIN
,DUN
,DUN
,DIN
,DIN
,DOU
,DNO
,DUN
,DIN
,DOU
,DOU
,
309 DOU
,DOU
,DOU
,DNO
,DIN
,DNO
,DNO
,DIN
,DOU
,DOU
,DOU
,DOU
,DIN
,DOU
,DIN
,DOU
,
310 DOU
,DOU
,DIN
,DIN
,DIN
,DNO
,DUN
,DNO
,DNO
,DNO
,DUN
,DNO
,DOU
,DIN
,DUN
,DUN
,
311 DUN
,DUN
,DUN
,DUN
,DUN
,DOU
,DUN
,DUN
,DUN
,DUN
,DIN
,DUN
,DUN
,DUN
,DUN
,DUN
,
312 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
313 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
314 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DIN
,DUN
,DOU
,DUN
,DUN
,DUN
,DUN
,DUN
,
315 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DIN
,DUN
,
316 DUN
,DUN
,DUN
,DUN
,DUN
,DNO
,DNO
,DUN
,DIN
,DNO
,DOU
,DUN
,DNO
,DUN
,DOU
,DOU
,
317 DOU
,DOU
,DOU
,DNO
,DUN
,DIN
,DOU
,DIN
,DIN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
318 DUN
,DUN
,DOU
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
319 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
320 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DOU
,DUN
,DUN
,DUN
,DUN
,DUN
,
321 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
324 /* LILO and modprobe/insmod parameters */
325 /* IRQ list for GDT3000/3020 EISA controllers */
326 static int irq
[MAXHA
] __initdata
=
327 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
328 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
329 /* disable driver flag */
330 static int disable __initdata
= 0;
332 static int reserve_mode
= 1;
334 static int reserve_list
[MAX_RES_ARGS
] =
335 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
336 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
337 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
338 /* scan order for PCI controllers */
339 static int reverse_scan
= 0;
340 /* virtual channel for the host drives */
341 static int hdr_channel
= 0;
342 /* max. IDs per channel */
343 static int max_ids
= MAXID
;
345 static int rescan
= 0;
347 static int shared_access
= 1;
348 /* enable support for EISA and ISA controllers */
349 static int probe_eisa_isa
= 0;
350 /* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */
351 static int force_dma32
= 0;
353 /* parameters for modprobe/insmod */
354 module_param_array(irq
, int, NULL
, 0);
355 module_param(disable
, int, 0);
356 module_param(reserve_mode
, int, 0);
357 module_param_array(reserve_list
, int, NULL
, 0);
358 module_param(reverse_scan
, int, 0);
359 module_param(hdr_channel
, int, 0);
360 module_param(max_ids
, int, 0);
361 module_param(rescan
, int, 0);
362 module_param(shared_access
, int, 0);
363 module_param(probe_eisa_isa
, int, 0);
364 module_param(force_dma32
, int, 0);
365 MODULE_AUTHOR("Achim Leubner");
366 MODULE_LICENSE("GPL");
368 /* ioctl interface */
369 static const struct file_operations gdth_fops
= {
372 .release
= gdth_close
,
375 #include "gdth_proc.h"
376 #include "gdth_proc.c"
378 static gdth_ha_str
*gdth_find_ha(int hanum
)
382 list_for_each_entry(ha
, &gdth_instances
, list
)
383 if (hanum
== ha
->hanum
)
389 static struct gdth_cmndinfo
*gdth_get_cmndinfo(gdth_ha_str
*ha
)
391 struct gdth_cmndinfo
*priv
= NULL
;
395 spin_lock_irqsave(&ha
->smp_lock
, flags
);
397 for (i
=0; i
<GDTH_MAXCMDS
; ++i
) {
398 if (ha
->cmndinfo
[i
].index
== 0) {
399 priv
= &ha
->cmndinfo
[i
];
400 memset(priv
, 0, sizeof(*priv
));
406 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
411 static void gdth_put_cmndinfo(struct gdth_cmndinfo
*priv
)
417 static void gdth_delay(int milliseconds
)
419 if (milliseconds
== 0) {
422 mdelay(milliseconds
);
426 static void gdth_scsi_done(struct scsi_cmnd
*scp
)
428 struct gdth_cmndinfo
*cmndinfo
= gdth_cmnd_priv(scp
);
429 int internal_command
= cmndinfo
->internal_command
;
431 TRACE2(("gdth_scsi_done()\n"));
433 gdth_put_cmndinfo(cmndinfo
);
434 scp
->host_scribble
= NULL
;
436 if (internal_command
)
437 complete((struct completion
*)scp
->request
);
442 int __gdth_execute(struct scsi_device
*sdev
, gdth_cmd_str
*gdtcmd
, char *cmnd
,
443 int timeout
, u32
*info
)
445 gdth_ha_str
*ha
= shost_priv(sdev
->host
);
447 struct gdth_cmndinfo cmndinfo
;
448 DECLARE_COMPLETION_ONSTACK(wait
);
451 scp
= kzalloc(sizeof(*scp
), GFP_KERNEL
);
455 scp
->sense_buffer
= kzalloc(SCSI_SENSE_BUFFERSIZE
, GFP_KERNEL
);
456 if (!scp
->sense_buffer
) {
462 memset(&cmndinfo
, 0, sizeof(cmndinfo
));
464 /* use request field to save the ptr. to completion struct. */
465 scp
->request
= (struct request
*)&wait
;
466 scp
->timeout_per_command
= timeout
*HZ
;
469 cmndinfo
.priority
= IOCTL_PRI
;
470 cmndinfo
.internal_cmd_str
= gdtcmd
;
471 cmndinfo
.internal_command
= 1;
473 TRACE(("__gdth_execute() cmd 0x%x\n", scp
->cmnd
[0]));
474 __gdth_queuecommand(ha
, scp
, &cmndinfo
);
476 wait_for_completion(&wait
);
478 rval
= cmndinfo
.status
;
480 *info
= cmndinfo
.info
;
481 kfree(scp
->sense_buffer
);
486 int gdth_execute(struct Scsi_Host
*shost
, gdth_cmd_str
*gdtcmd
, char *cmnd
,
487 int timeout
, u32
*info
)
489 struct scsi_device
*sdev
= scsi_get_host_dev(shost
);
490 int rval
= __gdth_execute(sdev
, gdtcmd
, cmnd
, timeout
, info
);
492 scsi_free_host_dev(sdev
);
496 static void gdth_eval_mapping(ulong32 size
, ulong32
*cyls
, int *heads
, int *secs
)
498 *cyls
= size
/HEADS
/SECS
;
499 if (*cyls
<= MAXCYLS
) {
502 } else { /* too high for 64*32 */
503 *cyls
= size
/MEDHEADS
/MEDSECS
;
504 if (*cyls
<= MAXCYLS
) {
507 } else { /* too high for 127*63 */
508 *cyls
= size
/BIGHEADS
/BIGSECS
;
515 /* controller search and initialization functions */
517 static int __init
gdth_search_eisa(ushort eisa_adr
)
521 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr
));
522 id
= inl(eisa_adr
+ID0REG
);
523 if (id
== GDT3A_ID
|| id
== GDT3B_ID
) { /* GDT3000A or GDT3000B */
524 if ((inb(eisa_adr
+EISAREG
) & 8) == 0)
525 return 0; /* not EISA configured */
528 if (id
== GDT3_ID
) /* GDT3000 */
533 #endif /* CONFIG_EISA */
536 static int __init
gdth_search_isa(ulong32 bios_adr
)
541 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr
));
542 if ((addr
= ioremap(bios_adr
+BIOS_ID_OFFS
, sizeof(ulong32
))) != NULL
) {
545 if (id
== GDT2_ID
) /* GDT2000 */
550 #endif /* CONFIG_ISA */
554 static bool gdth_search_vortex(ushort device
)
556 if (device
<= PCI_DEVICE_ID_VORTEX_GDT6555
)
558 if (device
>= PCI_DEVICE_ID_VORTEX_GDT6x17RP
&&
559 device
<= PCI_DEVICE_ID_VORTEX_GDTMAXRP
)
561 if (device
== PCI_DEVICE_ID_VORTEX_GDTNEWRX
||
562 device
== PCI_DEVICE_ID_VORTEX_GDTNEWRX2
)
567 static int gdth_pci_probe_one(gdth_pci_str
*pcistr
, gdth_ha_str
**ha_out
);
568 static int gdth_pci_init_one(struct pci_dev
*pdev
,
569 const struct pci_device_id
*ent
);
570 static void gdth_pci_remove_one(struct pci_dev
*pdev
);
571 static void gdth_remove_one(gdth_ha_str
*ha
);
573 /* Vortex only makes RAID controllers.
574 * We do not really want to specify all 550 ids here, so wildcard match.
576 static const struct pci_device_id gdthtable
[] = {
577 { PCI_VDEVICE(VORTEX
, PCI_ANY_ID
) },
578 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_SRC
) },
579 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_SRC_XSCALE
) },
580 { } /* terminate list */
582 MODULE_DEVICE_TABLE(pci
, gdthtable
);
584 static struct pci_driver gdth_pci_driver
= {
586 .id_table
= gdthtable
,
587 .probe
= gdth_pci_init_one
,
588 .remove
= gdth_pci_remove_one
,
591 static void gdth_pci_remove_one(struct pci_dev
*pdev
)
593 gdth_ha_str
*ha
= pci_get_drvdata(pdev
);
595 pci_set_drvdata(pdev
, NULL
);
600 pci_disable_device(pdev
);
603 static int gdth_pci_init_one(struct pci_dev
*pdev
,
604 const struct pci_device_id
*ent
)
606 ushort vendor
= pdev
->vendor
;
607 ushort device
= pdev
->device
;
608 ulong base0
, base1
, base2
;
610 gdth_pci_str gdth_pcistr
;
611 gdth_ha_str
*ha
= NULL
;
613 TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
614 gdth_ctr_count
, vendor
, device
));
616 memset(&gdth_pcistr
, 0, sizeof(gdth_pcistr
));
618 if (vendor
== PCI_VENDOR_ID_VORTEX
&& !gdth_search_vortex(device
))
621 rc
= pci_enable_device(pdev
);
625 if (gdth_ctr_count
>= MAXHA
)
628 /* GDT PCI controller found, resources are already in pdev */
629 gdth_pcistr
.pdev
= pdev
;
630 base0
= pci_resource_flags(pdev
, 0);
631 base1
= pci_resource_flags(pdev
, 1);
632 base2
= pci_resource_flags(pdev
, 2);
633 if (device
<= PCI_DEVICE_ID_VORTEX_GDT6000B
|| /* GDT6000/B */
634 device
>= PCI_DEVICE_ID_VORTEX_GDT6x17RP
) { /* MPR */
635 if (!(base0
& IORESOURCE_MEM
))
637 gdth_pcistr
.dpmem
= pci_resource_start(pdev
, 0);
638 } else { /* GDT6110, GDT6120, .. */
639 if (!(base0
& IORESOURCE_MEM
) ||
640 !(base2
& IORESOURCE_MEM
) ||
641 !(base1
& IORESOURCE_IO
))
643 gdth_pcistr
.dpmem
= pci_resource_start(pdev
, 2);
644 gdth_pcistr
.io
= pci_resource_start(pdev
, 1);
646 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
647 gdth_pcistr
.pdev
->bus
->number
,
648 PCI_SLOT(gdth_pcistr
.pdev
->devfn
),
652 rc
= gdth_pci_probe_one(&gdth_pcistr
, &ha
);
658 #endif /* CONFIG_PCI */
661 static int __init
gdth_init_eisa(ushort eisa_adr
,gdth_ha_str
*ha
)
664 unchar prot_ver
,eisacf
,i
,irq_found
;
666 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr
));
668 /* disable board interrupts, deinitialize services */
669 outb(0xff,eisa_adr
+EDOORREG
);
670 outb(0x00,eisa_adr
+EDENABREG
);
671 outb(0x00,eisa_adr
+EINTENABREG
);
673 outb(0xff,eisa_adr
+LDOORREG
);
674 retries
= INIT_RETRIES
;
676 while (inb(eisa_adr
+EDOORREG
) != 0xff) {
677 if (--retries
== 0) {
678 printk("GDT-EISA: Initialization error (DEINIT failed)\n");
682 TRACE2(("wait for DEINIT: retries=%d\n",retries
));
684 prot_ver
= inb(eisa_adr
+MAILBOXREG
);
685 outb(0xff,eisa_adr
+EDOORREG
);
686 if (prot_ver
!= PROTOCOL_VERSION
) {
687 printk("GDT-EISA: Illegal protocol version\n");
691 ha
->brd_phys
= (ulong32
)eisa_adr
>> 12;
693 outl(0,eisa_adr
+MAILBOXREG
);
694 outl(0,eisa_adr
+MAILBOXREG
+4);
695 outl(0,eisa_adr
+MAILBOXREG
+8);
696 outl(0,eisa_adr
+MAILBOXREG
+12);
699 if ((id
= inl(eisa_adr
+ID0REG
)) == GDT3_ID
) {
700 ha
->oem_id
= OEM_ID_ICP
;
703 outl(1,eisa_adr
+MAILBOXREG
+8);
704 outb(0xfe,eisa_adr
+LDOORREG
);
705 retries
= INIT_RETRIES
;
707 while (inb(eisa_adr
+EDOORREG
) != 0xfe) {
708 if (--retries
== 0) {
709 printk("GDT-EISA: Initialization error (get IRQ failed)\n");
714 ha
->irq
= inb(eisa_adr
+MAILBOXREG
);
715 outb(0xff,eisa_adr
+EDOORREG
);
716 TRACE2(("GDT3000/3020: IRQ=%d\n",ha
->irq
));
717 /* check the result */
719 TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
720 for (i
= 0, irq_found
= FALSE
;
721 i
< MAXHA
&& irq
[i
] != 0xff; ++i
) {
722 if (irq
[i
]==10 || irq
[i
]==11 || irq
[i
]==12 || irq
[i
]==14) {
730 printk("GDT-EISA: Can not detect controller IRQ,\n");
731 printk("Use IRQ setting from command line (IRQ = %d)\n",
734 printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
735 printk("the controller BIOS or use command line parameters\n");
740 eisacf
= inb(eisa_adr
+EISAREG
) & 7;
741 if (eisacf
> 4) /* level triggered */
743 ha
->irq
= gdth_irq_tab
[eisacf
];
744 ha
->oem_id
= OEM_ID_ICP
;
749 ha
->dma64_support
= 0;
752 #endif /* CONFIG_EISA */
755 static int __init
gdth_init_isa(ulong32 bios_adr
,gdth_ha_str
*ha
)
757 register gdt2_dpram_str __iomem
*dp2_ptr
;
759 unchar irq_drq
,prot_ver
;
762 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr
));
764 ha
->brd
= ioremap(bios_adr
, sizeof(gdt2_dpram_str
));
765 if (ha
->brd
== NULL
) {
766 printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
770 writeb(1, &dp2_ptr
->io
.memlock
); /* switch off write protection */
771 /* reset interface area */
772 memset_io(&dp2_ptr
->u
, 0, sizeof(dp2_ptr
->u
));
773 if (readl(&dp2_ptr
->u
) != 0) {
774 printk("GDT-ISA: Initialization error (DPMEM write error)\n");
779 /* disable board interrupts, read DRQ and IRQ */
780 writeb(0xff, &dp2_ptr
->io
.irqdel
);
781 writeb(0x00, &dp2_ptr
->io
.irqen
);
782 writeb(0x00, &dp2_ptr
->u
.ic
.S_Status
);
783 writeb(0x00, &dp2_ptr
->u
.ic
.Cmd_Index
);
785 irq_drq
= readb(&dp2_ptr
->io
.rq
);
786 for (i
=0; i
<3; ++i
) {
787 if ((irq_drq
& 1)==0)
791 ha
->drq
= gdth_drq_tab
[i
];
793 irq_drq
= readb(&dp2_ptr
->io
.rq
) >> 3;
794 for (i
=1; i
<5; ++i
) {
795 if ((irq_drq
& 1)==0)
799 ha
->irq
= gdth_irq_tab
[i
];
801 /* deinitialize services */
802 writel(bios_adr
, &dp2_ptr
->u
.ic
.S_Info
[0]);
803 writeb(0xff, &dp2_ptr
->u
.ic
.S_Cmd_Indx
);
804 writeb(0, &dp2_ptr
->io
.event
);
805 retries
= INIT_RETRIES
;
807 while (readb(&dp2_ptr
->u
.ic
.S_Status
) != 0xff) {
808 if (--retries
== 0) {
809 printk("GDT-ISA: Initialization error (DEINIT failed)\n");
815 prot_ver
= (unchar
)readl(&dp2_ptr
->u
.ic
.S_Info
[0]);
816 writeb(0, &dp2_ptr
->u
.ic
.Status
);
817 writeb(0xff, &dp2_ptr
->io
.irqdel
);
818 if (prot_ver
!= PROTOCOL_VERSION
) {
819 printk("GDT-ISA: Illegal protocol version\n");
824 ha
->oem_id
= OEM_ID_ICP
;
826 ha
->ic_all_size
= sizeof(dp2_ptr
->u
);
828 ha
->brd_phys
= bios_adr
>> 4;
830 /* special request to controller BIOS */
831 writel(0x00, &dp2_ptr
->u
.ic
.S_Info
[0]);
832 writel(0x00, &dp2_ptr
->u
.ic
.S_Info
[1]);
833 writel(0x01, &dp2_ptr
->u
.ic
.S_Info
[2]);
834 writel(0x00, &dp2_ptr
->u
.ic
.S_Info
[3]);
835 writeb(0xfe, &dp2_ptr
->u
.ic
.S_Cmd_Indx
);
836 writeb(0, &dp2_ptr
->io
.event
);
837 retries
= INIT_RETRIES
;
839 while (readb(&dp2_ptr
->u
.ic
.S_Status
) != 0xfe) {
840 if (--retries
== 0) {
841 printk("GDT-ISA: Initialization error\n");
847 writeb(0, &dp2_ptr
->u
.ic
.Status
);
848 writeb(0xff, &dp2_ptr
->io
.irqdel
);
850 ha
->dma64_support
= 0;
853 #endif /* CONFIG_ISA */
856 static int gdth_init_pci(struct pci_dev
*pdev
, gdth_pci_str
*pcistr
,
859 register gdt6_dpram_str __iomem
*dp6_ptr
;
860 register gdt6c_dpram_str __iomem
*dp6c_ptr
;
861 register gdt6m_dpram_str __iomem
*dp6m_ptr
;
865 int i
, found
= FALSE
;
867 TRACE(("gdth_init_pci()\n"));
869 if (pdev
->vendor
== PCI_VENDOR_ID_INTEL
)
870 ha
->oem_id
= OEM_ID_INTEL
;
872 ha
->oem_id
= OEM_ID_ICP
;
873 ha
->brd_phys
= (pdev
->bus
->number
<< 8) | (pdev
->devfn
& 0xf8);
874 ha
->stype
= (ulong32
)pdev
->device
;
878 if (ha
->pdev
->device
<= PCI_DEVICE_ID_VORTEX_GDT6000B
) { /* GDT6000/B */
879 TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr
->dpmem
,ha
->irq
));
880 ha
->brd
= ioremap(pcistr
->dpmem
, sizeof(gdt6_dpram_str
));
881 if (ha
->brd
== NULL
) {
882 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
885 /* check and reset interface area */
887 writel(DPMEM_MAGIC
, &dp6_ptr
->u
);
888 if (readl(&dp6_ptr
->u
) != DPMEM_MAGIC
) {
889 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
892 for (i
= 0xC8000; i
< 0xE8000; i
+= 0x4000) {
894 ha
->brd
= ioremap(i
, sizeof(ushort
));
895 if (ha
->brd
== NULL
) {
896 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
899 if (readw(ha
->brd
) != 0xffff) {
900 TRACE2(("init_pci_old() address 0x%x busy\n", i
));
904 pci_write_config_dword(pdev
, PCI_BASE_ADDRESS_0
, i
);
905 ha
->brd
= ioremap(i
, sizeof(gdt6_dpram_str
));
906 if (ha
->brd
== NULL
) {
907 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
911 writel(DPMEM_MAGIC
, &dp6_ptr
->u
);
912 if (readl(&dp6_ptr
->u
) == DPMEM_MAGIC
) {
913 printk("GDT-PCI: Use free address at 0x%x\n", i
);
919 printk("GDT-PCI: No free address found!\n");
924 memset_io(&dp6_ptr
->u
, 0, sizeof(dp6_ptr
->u
));
925 if (readl(&dp6_ptr
->u
) != 0) {
926 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
931 /* disable board interrupts, deinit services */
932 writeb(0xff, &dp6_ptr
->io
.irqdel
);
933 writeb(0x00, &dp6_ptr
->io
.irqen
);
934 writeb(0x00, &dp6_ptr
->u
.ic
.S_Status
);
935 writeb(0x00, &dp6_ptr
->u
.ic
.Cmd_Index
);
937 writel(pcistr
->dpmem
, &dp6_ptr
->u
.ic
.S_Info
[0]);
938 writeb(0xff, &dp6_ptr
->u
.ic
.S_Cmd_Indx
);
939 writeb(0, &dp6_ptr
->io
.event
);
940 retries
= INIT_RETRIES
;
942 while (readb(&dp6_ptr
->u
.ic
.S_Status
) != 0xff) {
943 if (--retries
== 0) {
944 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
950 prot_ver
= (unchar
)readl(&dp6_ptr
->u
.ic
.S_Info
[0]);
951 writeb(0, &dp6_ptr
->u
.ic
.S_Status
);
952 writeb(0xff, &dp6_ptr
->io
.irqdel
);
953 if (prot_ver
!= PROTOCOL_VERSION
) {
954 printk("GDT-PCI: Illegal protocol version\n");
960 ha
->ic_all_size
= sizeof(dp6_ptr
->u
);
962 /* special command to controller BIOS */
963 writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[0]);
964 writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[1]);
965 writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[2]);
966 writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[3]);
967 writeb(0xfe, &dp6_ptr
->u
.ic
.S_Cmd_Indx
);
968 writeb(0, &dp6_ptr
->io
.event
);
969 retries
= INIT_RETRIES
;
971 while (readb(&dp6_ptr
->u
.ic
.S_Status
) != 0xfe) {
972 if (--retries
== 0) {
973 printk("GDT-PCI: Initialization error\n");
979 writeb(0, &dp6_ptr
->u
.ic
.S_Status
);
980 writeb(0xff, &dp6_ptr
->io
.irqdel
);
982 ha
->dma64_support
= 0;
984 } else if (ha
->pdev
->device
<= PCI_DEVICE_ID_VORTEX_GDT6555
) { /* GDT6110, ... */
985 ha
->plx
= (gdt6c_plx_regs
*)pcistr
->io
;
986 TRACE2(("init_pci_new() dpmem %lx irq %d\n",
987 pcistr
->dpmem
,ha
->irq
));
988 ha
->brd
= ioremap(pcistr
->dpmem
, sizeof(gdt6c_dpram_str
));
989 if (ha
->brd
== NULL
) {
990 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
994 /* check and reset interface area */
996 writel(DPMEM_MAGIC
, &dp6c_ptr
->u
);
997 if (readl(&dp6c_ptr
->u
) != DPMEM_MAGIC
) {
998 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1001 for (i
= 0xC8000; i
< 0xE8000; i
+= 0x4000) {
1003 ha
->brd
= ioremap(i
, sizeof(ushort
));
1004 if (ha
->brd
== NULL
) {
1005 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1008 if (readw(ha
->brd
) != 0xffff) {
1009 TRACE2(("init_pci_plx() address 0x%x busy\n", i
));
1013 pci_write_config_dword(pdev
, PCI_BASE_ADDRESS_2
, i
);
1014 ha
->brd
= ioremap(i
, sizeof(gdt6c_dpram_str
));
1015 if (ha
->brd
== NULL
) {
1016 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1020 writel(DPMEM_MAGIC
, &dp6c_ptr
->u
);
1021 if (readl(&dp6c_ptr
->u
) == DPMEM_MAGIC
) {
1022 printk("GDT-PCI: Use free address at 0x%x\n", i
);
1028 printk("GDT-PCI: No free address found!\n");
1033 memset_io(&dp6c_ptr
->u
, 0, sizeof(dp6c_ptr
->u
));
1034 if (readl(&dp6c_ptr
->u
) != 0) {
1035 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1040 /* disable board interrupts, deinit services */
1041 outb(0x00,PTR2USHORT(&ha
->plx
->control1
));
1042 outb(0xff,PTR2USHORT(&ha
->plx
->edoor_reg
));
1044 writeb(0x00, &dp6c_ptr
->u
.ic
.S_Status
);
1045 writeb(0x00, &dp6c_ptr
->u
.ic
.Cmd_Index
);
1047 writel(pcistr
->dpmem
, &dp6c_ptr
->u
.ic
.S_Info
[0]);
1048 writeb(0xff, &dp6c_ptr
->u
.ic
.S_Cmd_Indx
);
1050 outb(1,PTR2USHORT(&ha
->plx
->ldoor_reg
));
1052 retries
= INIT_RETRIES
;
1054 while (readb(&dp6c_ptr
->u
.ic
.S_Status
) != 0xff) {
1055 if (--retries
== 0) {
1056 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1062 prot_ver
= (unchar
)readl(&dp6c_ptr
->u
.ic
.S_Info
[0]);
1063 writeb(0, &dp6c_ptr
->u
.ic
.Status
);
1064 if (prot_ver
!= PROTOCOL_VERSION
) {
1065 printk("GDT-PCI: Illegal protocol version\n");
1070 ha
->type
= GDT_PCINEW
;
1071 ha
->ic_all_size
= sizeof(dp6c_ptr
->u
);
1073 /* special command to controller BIOS */
1074 writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[0]);
1075 writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[1]);
1076 writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[2]);
1077 writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[3]);
1078 writeb(0xfe, &dp6c_ptr
->u
.ic
.S_Cmd_Indx
);
1080 outb(1,PTR2USHORT(&ha
->plx
->ldoor_reg
));
1082 retries
= INIT_RETRIES
;
1084 while (readb(&dp6c_ptr
->u
.ic
.S_Status
) != 0xfe) {
1085 if (--retries
== 0) {
1086 printk("GDT-PCI: Initialization error\n");
1092 writeb(0, &dp6c_ptr
->u
.ic
.S_Status
);
1094 ha
->dma64_support
= 0;
1097 TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr
->dpmem
,ha
->irq
));
1098 ha
->brd
= ioremap(pcistr
->dpmem
, sizeof(gdt6m_dpram_str
));
1099 if (ha
->brd
== NULL
) {
1100 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1104 /* manipulate config. space to enable DPMEM, start RP controller */
1105 pci_read_config_word(pdev
, PCI_COMMAND
, &command
);
1107 pci_write_config_word(pdev
, PCI_COMMAND
, command
);
1108 if (pci_resource_start(pdev
, 8) == 1UL)
1109 pci_resource_start(pdev
, 8) = 0UL;
1111 pci_write_config_dword(pdev
, PCI_ROM_ADDRESS
, i
);
1113 pci_write_config_dword(pdev
, PCI_ROM_ADDRESS
,
1114 pci_resource_start(pdev
, 8));
1118 /* Ensure that it is safe to access the non HW portions of DPMEM.
1119 * Aditional check needed for Xscale based RAID controllers */
1120 while( ((int)readb(&dp6m_ptr
->i960r
.sema0_reg
) ) & 3 )
1123 /* check and reset interface area */
1124 writel(DPMEM_MAGIC
, &dp6m_ptr
->u
);
1125 if (readl(&dp6m_ptr
->u
) != DPMEM_MAGIC
) {
1126 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1129 for (i
= 0xC8000; i
< 0xE8000; i
+= 0x4000) {
1131 ha
->brd
= ioremap(i
, sizeof(ushort
));
1132 if (ha
->brd
== NULL
) {
1133 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1136 if (readw(ha
->brd
) != 0xffff) {
1137 TRACE2(("init_pci_mpr() address 0x%x busy\n", i
));
1141 pci_write_config_dword(pdev
, PCI_BASE_ADDRESS_0
, i
);
1142 ha
->brd
= ioremap(i
, sizeof(gdt6m_dpram_str
));
1143 if (ha
->brd
== NULL
) {
1144 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1148 writel(DPMEM_MAGIC
, &dp6m_ptr
->u
);
1149 if (readl(&dp6m_ptr
->u
) == DPMEM_MAGIC
) {
1150 printk("GDT-PCI: Use free address at 0x%x\n", i
);
1156 printk("GDT-PCI: No free address found!\n");
1161 memset_io(&dp6m_ptr
->u
, 0, sizeof(dp6m_ptr
->u
));
1163 /* disable board interrupts, deinit services */
1164 writeb(readb(&dp6m_ptr
->i960r
.edoor_en_reg
) | 4,
1165 &dp6m_ptr
->i960r
.edoor_en_reg
);
1166 writeb(0xff, &dp6m_ptr
->i960r
.edoor_reg
);
1167 writeb(0x00, &dp6m_ptr
->u
.ic
.S_Status
);
1168 writeb(0x00, &dp6m_ptr
->u
.ic
.Cmd_Index
);
1170 writel(pcistr
->dpmem
, &dp6m_ptr
->u
.ic
.S_Info
[0]);
1171 writeb(0xff, &dp6m_ptr
->u
.ic
.S_Cmd_Indx
);
1172 writeb(1, &dp6m_ptr
->i960r
.ldoor_reg
);
1173 retries
= INIT_RETRIES
;
1175 while (readb(&dp6m_ptr
->u
.ic
.S_Status
) != 0xff) {
1176 if (--retries
== 0) {
1177 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1183 prot_ver
= (unchar
)readl(&dp6m_ptr
->u
.ic
.S_Info
[0]);
1184 writeb(0, &dp6m_ptr
->u
.ic
.S_Status
);
1185 if (prot_ver
!= PROTOCOL_VERSION
) {
1186 printk("GDT-PCI: Illegal protocol version\n");
1191 ha
->type
= GDT_PCIMPR
;
1192 ha
->ic_all_size
= sizeof(dp6m_ptr
->u
);
1194 /* special command to controller BIOS */
1195 writel(0x00, &dp6m_ptr
->u
.ic
.S_Info
[0]);
1196 writel(0x00, &dp6m_ptr
->u
.ic
.S_Info
[1]);
1197 writel(0x00, &dp6m_ptr
->u
.ic
.S_Info
[2]);
1198 writel(0x00, &dp6m_ptr
->u
.ic
.S_Info
[3]);
1199 writeb(0xfe, &dp6m_ptr
->u
.ic
.S_Cmd_Indx
);
1200 writeb(1, &dp6m_ptr
->i960r
.ldoor_reg
);
1201 retries
= INIT_RETRIES
;
1203 while (readb(&dp6m_ptr
->u
.ic
.S_Status
) != 0xfe) {
1204 if (--retries
== 0) {
1205 printk("GDT-PCI: Initialization error\n");
1211 writeb(0, &dp6m_ptr
->u
.ic
.S_Status
);
1213 /* read FW version to detect 64-bit DMA support */
1214 writeb(0xfd, &dp6m_ptr
->u
.ic
.S_Cmd_Indx
);
1215 writeb(1, &dp6m_ptr
->i960r
.ldoor_reg
);
1216 retries
= INIT_RETRIES
;
1218 while (readb(&dp6m_ptr
->u
.ic
.S_Status
) != 0xfd) {
1219 if (--retries
== 0) {
1220 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1226 prot_ver
= (unchar
)(readl(&dp6m_ptr
->u
.ic
.S_Info
[0]) >> 16);
1227 writeb(0, &dp6m_ptr
->u
.ic
.S_Status
);
1228 if (prot_ver
< 0x2b) /* FW < x.43: no 64-bit DMA support */
1229 ha
->dma64_support
= 0;
1231 ha
->dma64_support
= 1;
1236 #endif /* CONFIG_PCI */
1238 /* controller protocol functions */
1240 static void __init
gdth_enable_int(gdth_ha_str
*ha
)
1243 gdt2_dpram_str __iomem
*dp2_ptr
;
1244 gdt6_dpram_str __iomem
*dp6_ptr
;
1245 gdt6m_dpram_str __iomem
*dp6m_ptr
;
1247 TRACE(("gdth_enable_int() hanum %d\n",ha
->hanum
));
1248 spin_lock_irqsave(&ha
->smp_lock
, flags
);
1250 if (ha
->type
== GDT_EISA
) {
1251 outb(0xff, ha
->bmic
+ EDOORREG
);
1252 outb(0xff, ha
->bmic
+ EDENABREG
);
1253 outb(0x01, ha
->bmic
+ EINTENABREG
);
1254 } else if (ha
->type
== GDT_ISA
) {
1256 writeb(1, &dp2_ptr
->io
.irqdel
);
1257 writeb(0, &dp2_ptr
->u
.ic
.Cmd_Index
);
1258 writeb(1, &dp2_ptr
->io
.irqen
);
1259 } else if (ha
->type
== GDT_PCI
) {
1261 writeb(1, &dp6_ptr
->io
.irqdel
);
1262 writeb(0, &dp6_ptr
->u
.ic
.Cmd_Index
);
1263 writeb(1, &dp6_ptr
->io
.irqen
);
1264 } else if (ha
->type
== GDT_PCINEW
) {
1265 outb(0xff, PTR2USHORT(&ha
->plx
->edoor_reg
));
1266 outb(0x03, PTR2USHORT(&ha
->plx
->control1
));
1267 } else if (ha
->type
== GDT_PCIMPR
) {
1269 writeb(0xff, &dp6m_ptr
->i960r
.edoor_reg
);
1270 writeb(readb(&dp6m_ptr
->i960r
.edoor_en_reg
) & ~4,
1271 &dp6m_ptr
->i960r
.edoor_en_reg
);
1273 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
1276 /* return IStatus if interrupt was from this card else 0 */
1277 static unchar
gdth_get_status(gdth_ha_str
*ha
)
1281 TRACE(("gdth_get_status() irq %d ctr_count %d\n", ha
->irq
, gdth_ctr_count
));
1283 if (ha
->type
== GDT_EISA
)
1284 IStatus
= inb((ushort
)ha
->bmic
+ EDOORREG
);
1285 else if (ha
->type
== GDT_ISA
)
1287 readb(&((gdt2_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Cmd_Index
);
1288 else if (ha
->type
== GDT_PCI
)
1290 readb(&((gdt6_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Cmd_Index
);
1291 else if (ha
->type
== GDT_PCINEW
)
1292 IStatus
= inb(PTR2USHORT(&ha
->plx
->edoor_reg
));
1293 else if (ha
->type
== GDT_PCIMPR
)
1295 readb(&((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.edoor_reg
);
1300 static int gdth_test_busy(gdth_ha_str
*ha
)
1302 register int gdtsema0
= 0;
1304 TRACE(("gdth_test_busy() hanum %d\n", ha
->hanum
));
1306 if (ha
->type
== GDT_EISA
)
1307 gdtsema0
= (int)inb(ha
->bmic
+ SEMA0REG
);
1308 else if (ha
->type
== GDT_ISA
)
1309 gdtsema0
= (int)readb(&((gdt2_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Sema0
);
1310 else if (ha
->type
== GDT_PCI
)
1311 gdtsema0
= (int)readb(&((gdt6_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Sema0
);
1312 else if (ha
->type
== GDT_PCINEW
)
1313 gdtsema0
= (int)inb(PTR2USHORT(&ha
->plx
->sema0_reg
));
1314 else if (ha
->type
== GDT_PCIMPR
)
1316 (int)readb(&((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.sema0_reg
);
1318 return (gdtsema0
& 1);
1322 static int gdth_get_cmd_index(gdth_ha_str
*ha
)
1326 TRACE(("gdth_get_cmd_index() hanum %d\n", ha
->hanum
));
1328 for (i
=0; i
<GDTH_MAXCMDS
; ++i
) {
1329 if (ha
->cmd_tab
[i
].cmnd
== UNUSED_CMND
) {
1330 ha
->cmd_tab
[i
].cmnd
= ha
->pccb
->RequestBuffer
;
1331 ha
->cmd_tab
[i
].service
= ha
->pccb
->Service
;
1332 ha
->pccb
->CommandIndex
= (ulong32
)i
+2;
1340 static void gdth_set_sema0(gdth_ha_str
*ha
)
1342 TRACE(("gdth_set_sema0() hanum %d\n", ha
->hanum
));
1344 if (ha
->type
== GDT_EISA
) {
1345 outb(1, ha
->bmic
+ SEMA0REG
);
1346 } else if (ha
->type
== GDT_ISA
) {
1347 writeb(1, &((gdt2_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Sema0
);
1348 } else if (ha
->type
== GDT_PCI
) {
1349 writeb(1, &((gdt6_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Sema0
);
1350 } else if (ha
->type
== GDT_PCINEW
) {
1351 outb(1, PTR2USHORT(&ha
->plx
->sema0_reg
));
1352 } else if (ha
->type
== GDT_PCIMPR
) {
1353 writeb(1, &((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.sema0_reg
);
1358 static void gdth_copy_command(gdth_ha_str
*ha
)
1360 register gdth_cmd_str
*cmd_ptr
;
1361 register gdt6m_dpram_str __iomem
*dp6m_ptr
;
1362 register gdt6c_dpram_str __iomem
*dp6c_ptr
;
1363 gdt6_dpram_str __iomem
*dp6_ptr
;
1364 gdt2_dpram_str __iomem
*dp2_ptr
;
1365 ushort cp_count
,dp_offset
,cmd_no
;
1367 TRACE(("gdth_copy_command() hanum %d\n", ha
->hanum
));
1369 cp_count
= ha
->cmd_len
;
1370 dp_offset
= ha
->cmd_offs_dpmem
;
1371 cmd_no
= ha
->cmd_cnt
;
1375 if (ha
->type
== GDT_EISA
)
1376 return; /* no DPMEM, no copy */
1378 /* set cpcount dword aligned */
1380 cp_count
+= (4 - (cp_count
& 3));
1382 ha
->cmd_offs_dpmem
+= cp_count
;
1384 /* set offset and service, copy command to DPMEM */
1385 if (ha
->type
== GDT_ISA
) {
1387 writew(dp_offset
+ DPMEM_COMMAND_OFFSET
,
1388 &dp2_ptr
->u
.ic
.comm_queue
[cmd_no
].offset
);
1389 writew((ushort
)cmd_ptr
->Service
,
1390 &dp2_ptr
->u
.ic
.comm_queue
[cmd_no
].serv_id
);
1391 memcpy_toio(&dp2_ptr
->u
.ic
.gdt_dpr_cmd
[dp_offset
],cmd_ptr
,cp_count
);
1392 } else if (ha
->type
== GDT_PCI
) {
1394 writew(dp_offset
+ DPMEM_COMMAND_OFFSET
,
1395 &dp6_ptr
->u
.ic
.comm_queue
[cmd_no
].offset
);
1396 writew((ushort
)cmd_ptr
->Service
,
1397 &dp6_ptr
->u
.ic
.comm_queue
[cmd_no
].serv_id
);
1398 memcpy_toio(&dp6_ptr
->u
.ic
.gdt_dpr_cmd
[dp_offset
],cmd_ptr
,cp_count
);
1399 } else if (ha
->type
== GDT_PCINEW
) {
1401 writew(dp_offset
+ DPMEM_COMMAND_OFFSET
,
1402 &dp6c_ptr
->u
.ic
.comm_queue
[cmd_no
].offset
);
1403 writew((ushort
)cmd_ptr
->Service
,
1404 &dp6c_ptr
->u
.ic
.comm_queue
[cmd_no
].serv_id
);
1405 memcpy_toio(&dp6c_ptr
->u
.ic
.gdt_dpr_cmd
[dp_offset
],cmd_ptr
,cp_count
);
1406 } else if (ha
->type
== GDT_PCIMPR
) {
1408 writew(dp_offset
+ DPMEM_COMMAND_OFFSET
,
1409 &dp6m_ptr
->u
.ic
.comm_queue
[cmd_no
].offset
);
1410 writew((ushort
)cmd_ptr
->Service
,
1411 &dp6m_ptr
->u
.ic
.comm_queue
[cmd_no
].serv_id
);
1412 memcpy_toio(&dp6m_ptr
->u
.ic
.gdt_dpr_cmd
[dp_offset
],cmd_ptr
,cp_count
);
1417 static void gdth_release_event(gdth_ha_str
*ha
)
1419 TRACE(("gdth_release_event() hanum %d\n", ha
->hanum
));
1421 #ifdef GDTH_STATISTICS
1424 for (i
=0,j
=0; j
<GDTH_MAXCMDS
; ++j
) {
1425 if (ha
->cmd_tab
[j
].cmnd
!= UNUSED_CMND
)
1428 if (max_index
< i
) {
1430 TRACE3(("GDT: max_index = %d\n",(ushort
)i
));
1435 if (ha
->pccb
->OpCode
== GDT_INIT
)
1436 ha
->pccb
->Service
|= 0x80;
1438 if (ha
->type
== GDT_EISA
) {
1439 if (ha
->pccb
->OpCode
== GDT_INIT
) /* store DMA buffer */
1440 outl(ha
->ccb_phys
, ha
->bmic
+ MAILBOXREG
);
1441 outb(ha
->pccb
->Service
, ha
->bmic
+ LDOORREG
);
1442 } else if (ha
->type
== GDT_ISA
) {
1443 writeb(0, &((gdt2_dpram_str __iomem
*)ha
->brd
)->io
.event
);
1444 } else if (ha
->type
== GDT_PCI
) {
1445 writeb(0, &((gdt6_dpram_str __iomem
*)ha
->brd
)->io
.event
);
1446 } else if (ha
->type
== GDT_PCINEW
) {
1447 outb(1, PTR2USHORT(&ha
->plx
->ldoor_reg
));
1448 } else if (ha
->type
== GDT_PCIMPR
) {
1449 writeb(1, &((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.ldoor_reg
);
1453 static int gdth_wait(gdth_ha_str
*ha
, int index
, ulong32 time
)
1455 int answer_found
= FALSE
;
1458 TRACE(("gdth_wait() hanum %d index %d time %d\n", ha
->hanum
, index
, time
));
1461 return 1; /* no wait required */
1464 __gdth_interrupt(ha
, true, &wait_index
);
1465 if (wait_index
== index
) {
1466 answer_found
= TRUE
;
1472 while (gdth_test_busy(ha
))
1475 return (answer_found
);
1479 static int gdth_internal_cmd(gdth_ha_str
*ha
, unchar service
, ushort opcode
,
1480 ulong32 p1
, ulong64 p2
, ulong64 p3
)
1482 register gdth_cmd_str
*cmd_ptr
;
1485 TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service
,opcode
));
1488 memset((char*)cmd_ptr
,0,sizeof(gdth_cmd_str
));
1491 for (retries
= INIT_RETRIES
;;) {
1492 cmd_ptr
->Service
= service
;
1493 cmd_ptr
->RequestBuffer
= INTERNAL_CMND
;
1494 if (!(index
=gdth_get_cmd_index(ha
))) {
1495 TRACE(("GDT: No free command index found\n"));
1499 cmd_ptr
->OpCode
= opcode
;
1500 cmd_ptr
->BoardNode
= LOCALBOARD
;
1501 if (service
== CACHESERVICE
) {
1502 if (opcode
== GDT_IOCTL
) {
1503 cmd_ptr
->u
.ioctl
.subfunc
= p1
;
1504 cmd_ptr
->u
.ioctl
.channel
= (ulong32
)p2
;
1505 cmd_ptr
->u
.ioctl
.param_size
= (ushort
)p3
;
1506 cmd_ptr
->u
.ioctl
.p_param
= ha
->scratch_phys
;
1508 if (ha
->cache_feat
& GDT_64BIT
) {
1509 cmd_ptr
->u
.cache64
.DeviceNo
= (ushort
)p1
;
1510 cmd_ptr
->u
.cache64
.BlockNo
= p2
;
1512 cmd_ptr
->u
.cache
.DeviceNo
= (ushort
)p1
;
1513 cmd_ptr
->u
.cache
.BlockNo
= (ulong32
)p2
;
1516 } else if (service
== SCSIRAWSERVICE
) {
1517 if (ha
->raw_feat
& GDT_64BIT
) {
1518 cmd_ptr
->u
.raw64
.direction
= p1
;
1519 cmd_ptr
->u
.raw64
.bus
= (unchar
)p2
;
1520 cmd_ptr
->u
.raw64
.target
= (unchar
)p3
;
1521 cmd_ptr
->u
.raw64
.lun
= (unchar
)(p3
>> 8);
1523 cmd_ptr
->u
.raw
.direction
= p1
;
1524 cmd_ptr
->u
.raw
.bus
= (unchar
)p2
;
1525 cmd_ptr
->u
.raw
.target
= (unchar
)p3
;
1526 cmd_ptr
->u
.raw
.lun
= (unchar
)(p3
>> 8);
1528 } else if (service
== SCREENSERVICE
) {
1529 if (opcode
== GDT_REALTIME
) {
1530 *(ulong32
*)&cmd_ptr
->u
.screen
.su
.data
[0] = p1
;
1531 *(ulong32
*)&cmd_ptr
->u
.screen
.su
.data
[4] = (ulong32
)p2
;
1532 *(ulong32
*)&cmd_ptr
->u
.screen
.su
.data
[8] = (ulong32
)p3
;
1535 ha
->cmd_len
= sizeof(gdth_cmd_str
);
1536 ha
->cmd_offs_dpmem
= 0;
1538 gdth_copy_command(ha
);
1539 gdth_release_event(ha
);
1541 if (!gdth_wait(ha
, index
, INIT_TIMEOUT
)) {
1542 printk("GDT: Initialization error (timeout service %d)\n",service
);
1545 if (ha
->status
!= S_BSY
|| --retries
== 0)
1550 return (ha
->status
!= S_OK
? 0:1);
1554 /* search for devices */
1556 static int __init
gdth_search_drives(gdth_ha_str
*ha
)
1560 ulong32 bus_no
, drv_cnt
, drv_no
, j
;
1561 gdth_getch_str
*chn
;
1562 gdth_drlist_str
*drl
;
1563 gdth_iochan_str
*ioc
;
1564 gdth_raw_iochan_str
*iocr
;
1565 gdth_arcdl_str
*alst
;
1566 gdth_alist_str
*alst2
;
1567 gdth_oem_str_ioctl
*oemstr
;
1569 gdth_perf_modes
*pmod
;
1577 TRACE(("gdth_search_drives() hanum %d\n", ha
->hanum
));
1580 /* initialize controller services, at first: screen service */
1581 ha
->screen_feat
= 0;
1583 ok
= gdth_internal_cmd(ha
, SCREENSERVICE
, GDT_X_INIT_SCR
, 0, 0, 0);
1585 ha
->screen_feat
= GDT_64BIT
;
1587 if (force_dma32
|| (!ok
&& ha
->status
== (ushort
)S_NOFUNC
))
1588 ok
= gdth_internal_cmd(ha
, SCREENSERVICE
, GDT_INIT
, 0, 0, 0);
1590 printk("GDT-HA %d: Initialization error screen service (code %d)\n",
1591 ha
->hanum
, ha
->status
);
1594 TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n"));
1597 /* read realtime clock info, send to controller */
1598 /* 1. wait for the falling edge of update flag */
1599 spin_lock_irqsave(&rtc_lock
, flags
);
1600 for (j
= 0; j
< 1000000; ++j
)
1601 if (CMOS_READ(RTC_FREQ_SELECT
) & RTC_UIP
)
1603 for (j
= 0; j
< 1000000; ++j
)
1604 if (!(CMOS_READ(RTC_FREQ_SELECT
) & RTC_UIP
))
1608 for (j
= 0; j
< 12; ++j
)
1609 rtc
[j
] = CMOS_READ(j
);
1610 } while (rtc
[0] != CMOS_READ(0));
1611 spin_unlock_irqrestore(&rtc_lock
, flags
);
1612 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32
*)&rtc
[0],
1613 *(ulong32
*)&rtc
[4], *(ulong32
*)&rtc
[8]));
1614 /* 3. send to controller firmware */
1615 gdth_internal_cmd(ha
, SCREENSERVICE
, GDT_REALTIME
, *(ulong32
*)&rtc
[0],
1616 *(ulong32
*)&rtc
[4], *(ulong32
*)&rtc
[8]);
1619 /* unfreeze all IOs */
1620 gdth_internal_cmd(ha
, CACHESERVICE
, GDT_UNFREEZE_IO
, 0, 0, 0);
1622 /* initialize cache service */
1625 ok
= gdth_internal_cmd(ha
, CACHESERVICE
, GDT_X_INIT_HOST
, LINUX_OS
,
1628 ha
->cache_feat
= GDT_64BIT
;
1630 if (force_dma32
|| (!ok
&& ha
->status
== (ushort
)S_NOFUNC
))
1631 ok
= gdth_internal_cmd(ha
, CACHESERVICE
, GDT_INIT
, LINUX_OS
, 0, 0);
1633 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1634 ha
->hanum
, ha
->status
);
1637 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
1638 cdev_cnt
= (ushort
)ha
->info
;
1639 ha
->fw_vers
= ha
->service
;
1642 if (ha
->type
== GDT_PCIMPR
) {
1643 /* set perf. modes */
1644 pmod
= (gdth_perf_modes
*)ha
->pscratch
;
1646 pmod
->st_mode
= 1; /* enable one status buffer */
1647 *((ulong64
*)&pmod
->st_buff_addr1
) = ha
->coal_stat_phys
;
1648 pmod
->st_buff_indx1
= COALINDEX
;
1649 pmod
->st_buff_addr2
= 0;
1650 pmod
->st_buff_u_addr2
= 0;
1651 pmod
->st_buff_indx2
= 0;
1652 pmod
->st_buff_size
= sizeof(gdth_coal_status
) * MAXOFFSETS
;
1653 pmod
->cmd_mode
= 0; // disable all cmd buffers
1654 pmod
->cmd_buff_addr1
= 0;
1655 pmod
->cmd_buff_u_addr1
= 0;
1656 pmod
->cmd_buff_indx1
= 0;
1657 pmod
->cmd_buff_addr2
= 0;
1658 pmod
->cmd_buff_u_addr2
= 0;
1659 pmod
->cmd_buff_indx2
= 0;
1660 pmod
->cmd_buff_size
= 0;
1661 pmod
->reserved1
= 0;
1662 pmod
->reserved2
= 0;
1663 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
, SET_PERF_MODES
,
1664 INVALID_CHANNEL
,sizeof(gdth_perf_modes
))) {
1665 printk("GDT-HA %d: Interrupt coalescing activated\n", ha
->hanum
);
1670 /* detect number of buses - try new IOCTL */
1671 iocr
= (gdth_raw_iochan_str
*)ha
->pscratch
;
1672 iocr
->hdr
.version
= 0xffffffff;
1673 iocr
->hdr
.list_entries
= MAXBUS
;
1674 iocr
->hdr
.first_chan
= 0;
1675 iocr
->hdr
.last_chan
= MAXBUS
-1;
1676 iocr
->hdr
.list_offset
= GDTOFFSOF(gdth_raw_iochan_str
, list
[0]);
1677 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
, IOCHAN_RAW_DESC
,
1678 INVALID_CHANNEL
,sizeof(gdth_raw_iochan_str
))) {
1679 TRACE2(("IOCHAN_RAW_DESC supported!\n"));
1680 ha
->bus_cnt
= iocr
->hdr
.chan_count
;
1681 for (bus_no
= 0; bus_no
< ha
->bus_cnt
; ++bus_no
) {
1682 if (iocr
->list
[bus_no
].proc_id
< MAXID
)
1683 ha
->bus_id
[bus_no
] = iocr
->list
[bus_no
].proc_id
;
1685 ha
->bus_id
[bus_no
] = 0xff;
1689 chn
= (gdth_getch_str
*)ha
->pscratch
;
1690 for (bus_no
= 0; bus_no
< MAXBUS
; ++bus_no
) {
1691 chn
->channel_no
= bus_no
;
1692 if (!gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
,
1693 SCSI_CHAN_CNT
| L_CTRL_PATTERN
,
1694 IO_CHANNEL
| INVALID_CHANNEL
,
1695 sizeof(gdth_getch_str
))) {
1697 printk("GDT-HA %d: Error detecting channel count (0x%x)\n",
1698 ha
->hanum
, ha
->status
);
1703 if (chn
->siop_id
< MAXID
)
1704 ha
->bus_id
[bus_no
] = chn
->siop_id
;
1706 ha
->bus_id
[bus_no
] = 0xff;
1708 ha
->bus_cnt
= (unchar
)bus_no
;
1710 TRACE2(("gdth_search_drives() %d channels\n",ha
->bus_cnt
));
1712 /* read cache configuration */
1713 if (!gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
, CACHE_INFO
,
1714 INVALID_CHANNEL
,sizeof(gdth_cinfo_str
))) {
1715 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1716 ha
->hanum
, ha
->status
);
1719 ha
->cpar
= ((gdth_cinfo_str
*)ha
->pscratch
)->cpar
;
1720 TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
1721 ha
->cpar
.version
,ha
->cpar
.state
,ha
->cpar
.strategy
,
1722 ha
->cpar
.write_back
,ha
->cpar
.block_size
));
1724 /* read board info and features */
1725 ha
->more_proc
= FALSE
;
1726 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
, BOARD_INFO
,
1727 INVALID_CHANNEL
,sizeof(gdth_binfo_str
))) {
1728 memcpy(&ha
->binfo
, (gdth_binfo_str
*)ha
->pscratch
,
1729 sizeof(gdth_binfo_str
));
1730 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
, BOARD_FEATURES
,
1731 INVALID_CHANNEL
,sizeof(gdth_bfeat_str
))) {
1732 TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n"));
1733 ha
->bfeat
= *(gdth_bfeat_str
*)ha
->pscratch
;
1734 ha
->more_proc
= TRUE
;
1737 TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n"));
1738 strcpy(ha
->binfo
.type_string
, gdth_ctr_name(ha
));
1740 TRACE2(("Controller name: %s\n",ha
->binfo
.type_string
));
1742 /* read more informations */
1743 if (ha
->more_proc
) {
1744 /* physical drives, channel addresses */
1745 ioc
= (gdth_iochan_str
*)ha
->pscratch
;
1746 ioc
->hdr
.version
= 0xffffffff;
1747 ioc
->hdr
.list_entries
= MAXBUS
;
1748 ioc
->hdr
.first_chan
= 0;
1749 ioc
->hdr
.last_chan
= MAXBUS
-1;
1750 ioc
->hdr
.list_offset
= GDTOFFSOF(gdth_iochan_str
, list
[0]);
1751 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
, IOCHAN_DESC
,
1752 INVALID_CHANNEL
,sizeof(gdth_iochan_str
))) {
1753 for (bus_no
= 0; bus_no
< ha
->bus_cnt
; ++bus_no
) {
1754 ha
->raw
[bus_no
].address
= ioc
->list
[bus_no
].address
;
1755 ha
->raw
[bus_no
].local_no
= ioc
->list
[bus_no
].local_no
;
1758 for (bus_no
= 0; bus_no
< ha
->bus_cnt
; ++bus_no
) {
1759 ha
->raw
[bus_no
].address
= IO_CHANNEL
;
1760 ha
->raw
[bus_no
].local_no
= bus_no
;
1763 for (bus_no
= 0; bus_no
< ha
->bus_cnt
; ++bus_no
) {
1764 chn
= (gdth_getch_str
*)ha
->pscratch
;
1765 chn
->channel_no
= ha
->raw
[bus_no
].local_no
;
1766 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
,
1767 SCSI_CHAN_CNT
| L_CTRL_PATTERN
,
1768 ha
->raw
[bus_no
].address
| INVALID_CHANNEL
,
1769 sizeof(gdth_getch_str
))) {
1770 ha
->raw
[bus_no
].pdev_cnt
= chn
->drive_cnt
;
1771 TRACE2(("Channel %d: %d phys. drives\n",
1772 bus_no
,chn
->drive_cnt
));
1774 if (ha
->raw
[bus_no
].pdev_cnt
> 0) {
1775 drl
= (gdth_drlist_str
*)ha
->pscratch
;
1776 drl
->sc_no
= ha
->raw
[bus_no
].local_no
;
1777 drl
->sc_cnt
= ha
->raw
[bus_no
].pdev_cnt
;
1778 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
,
1779 SCSI_DR_LIST
| L_CTRL_PATTERN
,
1780 ha
->raw
[bus_no
].address
| INVALID_CHANNEL
,
1781 sizeof(gdth_drlist_str
))) {
1782 for (j
= 0; j
< ha
->raw
[bus_no
].pdev_cnt
; ++j
)
1783 ha
->raw
[bus_no
].id_list
[j
] = drl
->sc_list
[j
];
1785 ha
->raw
[bus_no
].pdev_cnt
= 0;
1790 /* logical drives */
1791 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
, CACHE_DRV_CNT
,
1792 INVALID_CHANNEL
,sizeof(ulong32
))) {
1793 drv_cnt
= *(ulong32
*)ha
->pscratch
;
1794 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
, CACHE_DRV_LIST
,
1795 INVALID_CHANNEL
,drv_cnt
* sizeof(ulong32
))) {
1796 for (j
= 0; j
< drv_cnt
; ++j
) {
1797 drv_no
= ((ulong32
*)ha
->pscratch
)[j
];
1798 if (drv_no
< MAX_LDRIVES
) {
1799 ha
->hdr
[drv_no
].is_logdrv
= TRUE
;
1800 TRACE2(("Drive %d is log. drive\n",drv_no
));
1804 alst
= (gdth_arcdl_str
*)ha
->pscratch
;
1805 alst
->entries_avail
= MAX_LDRIVES
;
1806 alst
->first_entry
= 0;
1807 alst
->list_offset
= GDTOFFSOF(gdth_arcdl_str
, list
[0]);
1808 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
,
1809 ARRAY_DRV_LIST2
| LA_CTRL_PATTERN
,
1810 INVALID_CHANNEL
, sizeof(gdth_arcdl_str
) +
1811 (alst
->entries_avail
-1) * sizeof(gdth_alist_str
))) {
1812 for (j
= 0; j
< alst
->entries_init
; ++j
) {
1813 ha
->hdr
[j
].is_arraydrv
= alst
->list
[j
].is_arrayd
;
1814 ha
->hdr
[j
].is_master
= alst
->list
[j
].is_master
;
1815 ha
->hdr
[j
].is_parity
= alst
->list
[j
].is_parity
;
1816 ha
->hdr
[j
].is_hotfix
= alst
->list
[j
].is_hotfix
;
1817 ha
->hdr
[j
].master_no
= alst
->list
[j
].cd_handle
;
1819 } else if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
,
1820 ARRAY_DRV_LIST
| LA_CTRL_PATTERN
,
1821 0, 35 * sizeof(gdth_alist_str
))) {
1822 for (j
= 0; j
< 35; ++j
) {
1823 alst2
= &((gdth_alist_str
*)ha
->pscratch
)[j
];
1824 ha
->hdr
[j
].is_arraydrv
= alst2
->is_arrayd
;
1825 ha
->hdr
[j
].is_master
= alst2
->is_master
;
1826 ha
->hdr
[j
].is_parity
= alst2
->is_parity
;
1827 ha
->hdr
[j
].is_hotfix
= alst2
->is_hotfix
;
1828 ha
->hdr
[j
].master_no
= alst2
->cd_handle
;
1834 /* initialize raw service */
1837 ok
= gdth_internal_cmd(ha
, SCSIRAWSERVICE
, GDT_X_INIT_RAW
, 0, 0, 0);
1839 ha
->raw_feat
= GDT_64BIT
;
1841 if (force_dma32
|| (!ok
&& ha
->status
== (ushort
)S_NOFUNC
))
1842 ok
= gdth_internal_cmd(ha
, SCSIRAWSERVICE
, GDT_INIT
, 0, 0, 0);
1844 printk("GDT-HA %d: Initialization error raw service (code %d)\n",
1845 ha
->hanum
, ha
->status
);
1848 TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n"));
1850 /* set/get features raw service (scatter/gather) */
1851 if (gdth_internal_cmd(ha
, SCSIRAWSERVICE
, GDT_SET_FEAT
, SCATTER_GATHER
,
1853 TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
1854 if (gdth_internal_cmd(ha
, SCSIRAWSERVICE
, GDT_GET_FEAT
, 0, 0, 0)) {
1855 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
1857 ha
->raw_feat
|= (ushort
)ha
->info
;
1861 /* set/get features cache service (equal to raw service) */
1862 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_SET_FEAT
, 0,
1863 SCATTER_GATHER
,0)) {
1864 TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
1865 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_GET_FEAT
, 0, 0, 0)) {
1866 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
1868 ha
->cache_feat
|= (ushort
)ha
->info
;
1872 /* reserve drives for raw service */
1873 if (reserve_mode
!= 0) {
1874 gdth_internal_cmd(ha
, SCSIRAWSERVICE
, GDT_RESERVE_ALL
,
1875 reserve_mode
== 1 ? 1 : 3, 0, 0);
1876 TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n",
1879 for (i
= 0; i
< MAX_RES_ARGS
; i
+= 4) {
1880 if (reserve_list
[i
] == ha
->hanum
&& reserve_list
[i
+1] < ha
->bus_cnt
&&
1881 reserve_list
[i
+2] < ha
->tid_cnt
&& reserve_list
[i
+3] < MAXLUN
) {
1882 TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
1883 reserve_list
[i
], reserve_list
[i
+1],
1884 reserve_list
[i
+2], reserve_list
[i
+3]));
1885 if (!gdth_internal_cmd(ha
, SCSIRAWSERVICE
, GDT_RESERVE
, 0,
1886 reserve_list
[i
+1], reserve_list
[i
+2] |
1887 (reserve_list
[i
+3] << 8))) {
1888 printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n",
1889 ha
->hanum
, ha
->status
);
1894 /* Determine OEM string using IOCTL */
1895 oemstr
= (gdth_oem_str_ioctl
*)ha
->pscratch
;
1896 oemstr
->params
.ctl_version
= 0x01;
1897 oemstr
->params
.buffer_size
= sizeof(oemstr
->text
);
1898 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_IOCTL
,
1899 CACHE_READ_OEM_STRING_RECORD
,INVALID_CHANNEL
,
1900 sizeof(gdth_oem_str_ioctl
))) {
1901 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n"));
1902 printk("GDT-HA %d: Vendor: %s Name: %s\n",
1903 ha
->hanum
, oemstr
->text
.oem_company_name
, ha
->binfo
.type_string
);
1904 /* Save the Host Drive inquiry data */
1905 strlcpy(ha
->oem_name
,oemstr
->text
.scsi_host_drive_inquiry_vendor_id
,
1906 sizeof(ha
->oem_name
));
1908 /* Old method, based on PCI ID */
1909 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
1910 printk("GDT-HA %d: Name: %s\n",
1911 ha
->hanum
, ha
->binfo
.type_string
);
1912 if (ha
->oem_id
== OEM_ID_INTEL
)
1913 strlcpy(ha
->oem_name
,"Intel ", sizeof(ha
->oem_name
));
1915 strlcpy(ha
->oem_name
,"ICP ", sizeof(ha
->oem_name
));
1918 /* scanning for host drives */
1919 for (i
= 0; i
< cdev_cnt
; ++i
)
1920 gdth_analyse_hdrive(ha
, i
);
1922 TRACE(("gdth_search_drives() OK\n"));
1926 static int gdth_analyse_hdrive(gdth_ha_str
*ha
, ushort hdrive
)
1929 int drv_hds
, drv_secs
;
1931 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n", ha
->hanum
, hdrive
));
1932 if (hdrive
>= MAX_HDRIVES
)
1935 if (!gdth_internal_cmd(ha
, CACHESERVICE
, GDT_INFO
, hdrive
, 0, 0))
1937 ha
->hdr
[hdrive
].present
= TRUE
;
1938 ha
->hdr
[hdrive
].size
= ha
->info
;
1940 /* evaluate mapping (sectors per head, heads per cylinder) */
1941 ha
->hdr
[hdrive
].size
&= ~SECS32
;
1942 if (ha
->info2
== 0) {
1943 gdth_eval_mapping(ha
->hdr
[hdrive
].size
,&drv_cyls
,&drv_hds
,&drv_secs
);
1945 drv_hds
= ha
->info2
& 0xff;
1946 drv_secs
= (ha
->info2
>> 8) & 0xff;
1947 drv_cyls
= (ulong32
)ha
->hdr
[hdrive
].size
/ drv_hds
/ drv_secs
;
1949 ha
->hdr
[hdrive
].heads
= (unchar
)drv_hds
;
1950 ha
->hdr
[hdrive
].secs
= (unchar
)drv_secs
;
1952 ha
->hdr
[hdrive
].size
= drv_cyls
* drv_hds
* drv_secs
;
1954 if (ha
->cache_feat
& GDT_64BIT
) {
1955 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_X_INFO
, hdrive
, 0, 0)
1956 && ha
->info2
!= 0) {
1957 ha
->hdr
[hdrive
].size
= ((ulong64
)ha
->info2
<< 32) | ha
->info
;
1960 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
1961 hdrive
,ha
->hdr
[hdrive
].size
,drv_hds
,drv_secs
));
1963 /* get informations about device */
1964 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_DEVTYPE
, hdrive
, 0, 0)) {
1965 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
1967 ha
->hdr
[hdrive
].devtype
= (ushort
)ha
->info
;
1971 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_CLUST_INFO
, hdrive
, 0, 0)) {
1972 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
1975 ha
->hdr
[hdrive
].cluster_type
= (unchar
)ha
->info
;
1978 /* R/W attributes */
1979 if (gdth_internal_cmd(ha
, CACHESERVICE
, GDT_RW_ATTRIBS
, hdrive
, 0, 0)) {
1980 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
1982 ha
->hdr
[hdrive
].rw_attribs
= (unchar
)ha
->info
;
1989 /* command queueing/sending functions */
1991 static void gdth_putq(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
, unchar priority
)
1993 struct gdth_cmndinfo
*cmndinfo
= gdth_cmnd_priv(scp
);
1994 register Scsi_Cmnd
*pscp
;
1995 register Scsi_Cmnd
*nscp
;
1999 TRACE(("gdth_putq() priority %d\n",priority
));
2000 spin_lock_irqsave(&ha
->smp_lock
, flags
);
2002 if (!cmndinfo
->internal_command
) {
2003 cmndinfo
->priority
= priority
;
2004 b
= scp
->device
->channel
;
2005 t
= scp
->device
->id
;
2006 if (priority
>= DEFAULT_PRI
) {
2007 if ((b
!= ha
->virt_bus
&& ha
->raw
[BUS_L2P(ha
,b
)].lock
) ||
2008 (b
==ha
->virt_bus
&& t
<MAX_HDRIVES
&& ha
->hdr
[t
].lock
)) {
2009 TRACE2(("gdth_putq(): locked IO ->update_timeout()\n"));
2010 cmndinfo
->timeout
= gdth_update_timeout(scp
, 0);
2015 if (ha
->req_first
==NULL
) {
2016 ha
->req_first
= scp
; /* queue was empty */
2017 scp
->SCp
.ptr
= NULL
;
2018 } else { /* queue not empty */
2019 pscp
= ha
->req_first
;
2020 nscp
= (Scsi_Cmnd
*)pscp
->SCp
.ptr
;
2021 /* priority: 0-highest,..,0xff-lowest */
2022 while (nscp
&& gdth_cmnd_priv(nscp
)->priority
<= priority
) {
2024 nscp
= (Scsi_Cmnd
*)pscp
->SCp
.ptr
;
2026 pscp
->SCp
.ptr
= (char *)scp
;
2027 scp
->SCp
.ptr
= (char *)nscp
;
2029 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
2031 #ifdef GDTH_STATISTICS
2033 for (nscp
=ha
->req_first
; nscp
; nscp
=(Scsi_Cmnd
*)nscp
->SCp
.ptr
)
2035 if (max_rq
< flags
) {
2037 TRACE3(("GDT: max_rq = %d\n",(ushort
)max_rq
));
2042 static void gdth_next(gdth_ha_str
*ha
)
2044 register Scsi_Cmnd
*pscp
;
2045 register Scsi_Cmnd
*nscp
;
2046 unchar b
, t
, l
, firsttime
;
2047 unchar this_cmd
, next_cmd
;
2051 TRACE(("gdth_next() hanum %d\n", ha
->hanum
));
2053 spin_lock_irqsave(&ha
->smp_lock
, flags
);
2055 ha
->cmd_cnt
= ha
->cmd_offs_dpmem
= 0;
2056 this_cmd
= firsttime
= TRUE
;
2057 next_cmd
= gdth_polling
? FALSE
:TRUE
;
2060 for (nscp
= pscp
= ha
->req_first
; nscp
; nscp
= (Scsi_Cmnd
*)nscp
->SCp
.ptr
) {
2061 struct gdth_cmndinfo
*nscp_cmndinfo
= gdth_cmnd_priv(nscp
);
2062 if (nscp
!= pscp
&& nscp
!= (Scsi_Cmnd
*)pscp
->SCp
.ptr
)
2063 pscp
= (Scsi_Cmnd
*)pscp
->SCp
.ptr
;
2064 if (!nscp_cmndinfo
->internal_command
) {
2065 b
= nscp
->device
->channel
;
2066 t
= nscp
->device
->id
;
2067 l
= nscp
->device
->lun
;
2068 if (nscp_cmndinfo
->priority
>= DEFAULT_PRI
) {
2069 if ((b
!= ha
->virt_bus
&& ha
->raw
[BUS_L2P(ha
,b
)].lock
) ||
2070 (b
== ha
->virt_bus
&& t
< MAX_HDRIVES
&& ha
->hdr
[t
].lock
))
2077 if (gdth_test_busy(ha
)) { /* controller busy ? */
2078 TRACE(("gdth_next() controller %d busy !\n", ha
->hanum
));
2079 if (!gdth_polling
) {
2080 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
2083 while (gdth_test_busy(ha
))
2089 if (!nscp_cmndinfo
->internal_command
) {
2090 if (nscp_cmndinfo
->phase
== -1) {
2091 nscp_cmndinfo
->phase
= CACHESERVICE
; /* default: cache svc. */
2092 if (nscp
->cmnd
[0] == TEST_UNIT_READY
) {
2093 TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
2095 /* TEST_UNIT_READY -> set scan mode */
2096 if ((ha
->scan_mode
& 0x0f) == 0) {
2097 if (b
== 0 && t
== 0 && l
== 0) {
2099 TRACE2(("Scan mode: 0x%x\n", ha
->scan_mode
));
2101 } else if ((ha
->scan_mode
& 0x0f) == 1) {
2102 if (b
== 0 && ((t
== 0 && l
== 1) ||
2103 (t
== 1 && l
== 0))) {
2104 nscp_cmndinfo
->OpCode
= GDT_SCAN_START
;
2105 nscp_cmndinfo
->phase
= ((ha
->scan_mode
& 0x10 ? 1:0) << 8)
2107 ha
->scan_mode
= 0x12;
2108 TRACE2(("Scan mode: 0x%x (SCAN_START)\n",
2111 ha
->scan_mode
&= 0x10;
2112 TRACE2(("Scan mode: 0x%x\n", ha
->scan_mode
));
2114 } else if (ha
->scan_mode
== 0x12) {
2115 if (b
== ha
->bus_cnt
&& t
== ha
->tid_cnt
-1) {
2116 nscp_cmndinfo
->phase
= SCSIRAWSERVICE
;
2117 nscp_cmndinfo
->OpCode
= GDT_SCAN_END
;
2118 ha
->scan_mode
&= 0x10;
2119 TRACE2(("Scan mode: 0x%x (SCAN_END)\n",
2124 if (b
== ha
->virt_bus
&& nscp
->cmnd
[0] != INQUIRY
&&
2125 nscp
->cmnd
[0] != READ_CAPACITY
&& nscp
->cmnd
[0] != MODE_SENSE
&&
2126 (ha
->hdr
[t
].cluster_type
& CLUSTER_DRIVE
)) {
2127 /* always GDT_CLUST_INFO! */
2128 nscp_cmndinfo
->OpCode
= GDT_CLUST_INFO
;
2133 if (nscp_cmndinfo
->OpCode
!= -1) {
2134 if ((nscp_cmndinfo
->phase
& 0xff) == CACHESERVICE
) {
2135 if (!(cmd_index
=gdth_fill_cache_cmd(ha
, nscp
, t
)))
2138 } else if ((nscp_cmndinfo
->phase
& 0xff) == SCSIRAWSERVICE
) {
2139 if (!(cmd_index
=gdth_fill_raw_cmd(ha
, nscp
, BUS_L2P(ha
, b
))))
2143 memset((char*)nscp
->sense_buffer
,0,16);
2144 nscp
->sense_buffer
[0] = 0x70;
2145 nscp
->sense_buffer
[2] = NOT_READY
;
2146 nscp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
2147 if (!nscp_cmndinfo
->wait_for_completion
)
2148 nscp_cmndinfo
->wait_for_completion
++;
2150 gdth_scsi_done(nscp
);
2152 } else if (gdth_cmnd_priv(nscp
)->internal_command
) {
2153 if (!(cmd_index
=gdth_special_cmd(ha
, nscp
)))
2156 } else if (b
!= ha
->virt_bus
) {
2157 if (ha
->raw
[BUS_L2P(ha
,b
)].io_cnt
[t
] >= GDTH_MAX_RAW
||
2158 !(cmd_index
=gdth_fill_raw_cmd(ha
, nscp
, BUS_L2P(ha
, b
))))
2161 ha
->raw
[BUS_L2P(ha
,b
)].io_cnt
[t
]++;
2162 } else if (t
>= MAX_HDRIVES
|| !ha
->hdr
[t
].present
|| l
!= 0) {
2163 TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
2164 nscp
->cmnd
[0], b
, t
, l
));
2165 nscp
->result
= DID_BAD_TARGET
<< 16;
2166 if (!nscp_cmndinfo
->wait_for_completion
)
2167 nscp_cmndinfo
->wait_for_completion
++;
2169 gdth_scsi_done(nscp
);
2171 switch (nscp
->cmnd
[0]) {
2172 case TEST_UNIT_READY
:
2179 case SERVICE_ACTION_IN
:
2180 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp
->cmnd
[0],
2181 nscp
->cmnd
[1],nscp
->cmnd
[2],nscp
->cmnd
[3],
2182 nscp
->cmnd
[4],nscp
->cmnd
[5]));
2183 if (ha
->hdr
[t
].media_changed
&& nscp
->cmnd
[0] != INQUIRY
) {
2184 /* return UNIT_ATTENTION */
2185 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2187 ha
->hdr
[t
].media_changed
= FALSE
;
2188 memset((char*)nscp
->sense_buffer
,0,16);
2189 nscp
->sense_buffer
[0] = 0x70;
2190 nscp
->sense_buffer
[2] = UNIT_ATTENTION
;
2191 nscp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
2192 if (!nscp_cmndinfo
->wait_for_completion
)
2193 nscp_cmndinfo
->wait_for_completion
++;
2195 gdth_scsi_done(nscp
);
2196 } else if (gdth_internal_cache_cmd(ha
, nscp
))
2197 gdth_scsi_done(nscp
);
2200 case ALLOW_MEDIUM_REMOVAL
:
2201 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp
->cmnd
[0],
2202 nscp
->cmnd
[1],nscp
->cmnd
[2],nscp
->cmnd
[3],
2203 nscp
->cmnd
[4],nscp
->cmnd
[5]));
2204 if ( (nscp
->cmnd
[4]&1) && !(ha
->hdr
[t
].devtype
&1) ) {
2205 TRACE(("Prevent r. nonremov. drive->do nothing\n"));
2206 nscp
->result
= DID_OK
<< 16;
2207 nscp
->sense_buffer
[0] = 0;
2208 if (!nscp_cmndinfo
->wait_for_completion
)
2209 nscp_cmndinfo
->wait_for_completion
++;
2211 gdth_scsi_done(nscp
);
2213 nscp
->cmnd
[3] = (ha
->hdr
[t
].devtype
&1) ? 1:0;
2214 TRACE(("Prevent/allow r. %d rem. drive %d\n",
2215 nscp
->cmnd
[4],nscp
->cmnd
[3]));
2216 if (!(cmd_index
=gdth_fill_cache_cmd(ha
, nscp
, t
)))
2223 TRACE2(("cache cmd %s\n",nscp
->cmnd
[0] == RESERVE
?
2224 "RESERVE" : "RELEASE"));
2225 if (!(cmd_index
=gdth_fill_cache_cmd(ha
, nscp
, t
)))
2235 if (ha
->hdr
[t
].media_changed
) {
2236 /* return UNIT_ATTENTION */
2237 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2239 ha
->hdr
[t
].media_changed
= FALSE
;
2240 memset((char*)nscp
->sense_buffer
,0,16);
2241 nscp
->sense_buffer
[0] = 0x70;
2242 nscp
->sense_buffer
[2] = UNIT_ATTENTION
;
2243 nscp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
2244 if (!nscp_cmndinfo
->wait_for_completion
)
2245 nscp_cmndinfo
->wait_for_completion
++;
2247 gdth_scsi_done(nscp
);
2248 } else if (!(cmd_index
=gdth_fill_cache_cmd(ha
, nscp
, t
)))
2253 TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp
->cmnd
[0],
2254 nscp
->cmnd
[1],nscp
->cmnd
[2],nscp
->cmnd
[3],
2255 nscp
->cmnd
[4],nscp
->cmnd
[5]));
2256 printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n",
2257 ha
->hanum
, nscp
->cmnd
[0]);
2258 nscp
->result
= DID_ABORT
<< 16;
2259 if (!nscp_cmndinfo
->wait_for_completion
)
2260 nscp_cmndinfo
->wait_for_completion
++;
2262 gdth_scsi_done(nscp
);
2269 if (nscp
== ha
->req_first
)
2270 ha
->req_first
= pscp
= (Scsi_Cmnd
*)nscp
->SCp
.ptr
;
2272 pscp
->SCp
.ptr
= nscp
->SCp
.ptr
;
2277 if (ha
->cmd_cnt
> 0) {
2278 gdth_release_event(ha
);
2282 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
2284 if (gdth_polling
&& ha
->cmd_cnt
> 0) {
2285 if (!gdth_wait(ha
, cmd_index
, POLL_TIMEOUT
))
2286 printk("GDT-HA %d: Command %d timed out !\n",
2287 ha
->hanum
, cmd_index
);
2292 * gdth_copy_internal_data() - copy to/from a buffer onto a scsi_cmnd's
2293 * buffers, kmap_atomic() as needed.
2295 static void gdth_copy_internal_data(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
,
2296 char *buffer
, ushort count
)
2298 ushort cpcount
,i
, max_sg
= scsi_sg_count(scp
);
2300 struct scatterlist
*sl
;
2303 cpcount
= min_t(ushort
, count
, scsi_bufflen(scp
));
2307 scsi_for_each_sg(scp
, sl
, max_sg
, i
) {
2308 unsigned long flags
;
2309 cpnow
= (ushort
)sl
->length
;
2310 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2311 cpnow
, cpsum
, cpcount
, scsi_bufflen(scp
)));
2312 if (cpsum
+cpnow
> cpcount
)
2313 cpnow
= cpcount
- cpsum
;
2316 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
2320 local_irq_save(flags
);
2321 address
= kmap_atomic(sg_page(sl
), KM_BIO_SRC_IRQ
) + sl
->offset
;
2322 memcpy(address
, buffer
, cpnow
);
2323 flush_dcache_page(sg_page(sl
));
2324 kunmap_atomic(address
, KM_BIO_SRC_IRQ
);
2325 local_irq_restore(flags
);
2326 if (cpsum
== cpcount
)
2331 printk("GDT-HA %d: SCSI command with no buffers but data transfer expected!\n",
2337 static int gdth_internal_cache_cmd(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
)
2341 gdth_rdcap_data rdc
;
2343 gdth_modep_data mpd
;
2344 struct gdth_cmndinfo
*cmndinfo
= gdth_cmnd_priv(scp
);
2346 t
= scp
->device
->id
;
2347 TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
2350 scp
->result
= DID_OK
<< 16;
2351 scp
->sense_buffer
[0] = 0;
2353 switch (scp
->cmnd
[0]) {
2354 case TEST_UNIT_READY
:
2357 TRACE2(("Test/Verify/Start hdrive %d\n",t
));
2361 TRACE2(("Inquiry hdrive %d devtype %d\n",
2362 t
,ha
->hdr
[t
].devtype
));
2363 inq
.type_qual
= (ha
->hdr
[t
].devtype
&4) ? TYPE_ROM
:TYPE_DISK
;
2364 /* you can here set all disks to removable, if you want to do
2365 a flush using the ALLOW_MEDIUM_REMOVAL command */
2366 inq
.modif_rmb
= 0x00;
2367 if ((ha
->hdr
[t
].devtype
& 1) ||
2368 (ha
->hdr
[t
].cluster_type
& CLUSTER_DRIVE
))
2369 inq
.modif_rmb
= 0x80;
2373 strcpy(inq
.vendor
,ha
->oem_name
);
2374 sprintf(inq
.product
,"Host Drive #%02d",t
);
2375 strcpy(inq
.revision
," ");
2376 gdth_copy_internal_data(ha
, scp
, (char*)&inq
, sizeof(gdth_inq_data
));
2380 TRACE2(("Request sense hdrive %d\n",t
));
2381 sd
.errorcode
= 0x70;
2386 gdth_copy_internal_data(ha
, scp
, (char*)&sd
, sizeof(gdth_sense_data
));
2390 TRACE2(("Mode sense hdrive %d\n",t
));
2391 memset((char*)&mpd
,0,sizeof(gdth_modep_data
));
2392 mpd
.hd
.data_length
= sizeof(gdth_modep_data
);
2393 mpd
.hd
.dev_par
= (ha
->hdr
[t
].devtype
&2) ? 0x80:0;
2394 mpd
.hd
.bd_length
= sizeof(mpd
.bd
);
2395 mpd
.bd
.block_length
[0] = (SECTOR_SIZE
& 0x00ff0000) >> 16;
2396 mpd
.bd
.block_length
[1] = (SECTOR_SIZE
& 0x0000ff00) >> 8;
2397 mpd
.bd
.block_length
[2] = (SECTOR_SIZE
& 0x000000ff);
2398 gdth_copy_internal_data(ha
, scp
, (char*)&mpd
, sizeof(gdth_modep_data
));
2402 TRACE2(("Read capacity hdrive %d\n",t
));
2403 if (ha
->hdr
[t
].size
> (ulong64
)0xffffffff)
2404 rdc
.last_block_no
= 0xffffffff;
2406 rdc
.last_block_no
= cpu_to_be32(ha
->hdr
[t
].size
-1);
2407 rdc
.block_length
= cpu_to_be32(SECTOR_SIZE
);
2408 gdth_copy_internal_data(ha
, scp
, (char*)&rdc
, sizeof(gdth_rdcap_data
));
2411 case SERVICE_ACTION_IN
:
2412 if ((scp
->cmnd
[1] & 0x1f) == SAI_READ_CAPACITY_16
&&
2413 (ha
->cache_feat
& GDT_64BIT
)) {
2414 gdth_rdcap16_data rdc16
;
2416 TRACE2(("Read capacity (16) hdrive %d\n",t
));
2417 rdc16
.last_block_no
= cpu_to_be64(ha
->hdr
[t
].size
-1);
2418 rdc16
.block_length
= cpu_to_be32(SECTOR_SIZE
);
2419 gdth_copy_internal_data(ha
, scp
, (char*)&rdc16
,
2420 sizeof(gdth_rdcap16_data
));
2422 scp
->result
= DID_ABORT
<< 16;
2427 TRACE2(("Internal cache cmd 0x%x unknown\n",scp
->cmnd
[0]));
2431 if (!cmndinfo
->wait_for_completion
)
2432 cmndinfo
->wait_for_completion
++;
2439 static int gdth_fill_cache_cmd(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
, ushort hdrive
)
2441 register gdth_cmd_str
*cmdp
;
2442 struct gdth_cmndinfo
*cmndinfo
= gdth_cmnd_priv(scp
);
2443 ulong32 cnt
, blockcnt
;
2444 ulong64 no
, blockno
;
2445 int i
, cmd_index
, read_write
, sgcnt
, mode64
;
2448 TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
2449 scp
->cmnd
[0],scp
->cmd_len
,hdrive
));
2451 if (ha
->type
==GDT_EISA
&& ha
->cmd_cnt
>0)
2454 mode64
= (ha
->cache_feat
& GDT_64BIT
) ? TRUE
: FALSE
;
2455 /* test for READ_16, WRITE_16 if !mode64 ? ---
2456 not required, should not occur due to error return on
2459 cmdp
->Service
= CACHESERVICE
;
2460 cmdp
->RequestBuffer
= scp
;
2461 /* search free command index */
2462 if (!(cmd_index
=gdth_get_cmd_index(ha
))) {
2463 TRACE(("GDT: No free command index found\n"));
2466 /* if it's the first command, set command semaphore */
2467 if (ha
->cmd_cnt
== 0)
2472 if (cmndinfo
->OpCode
!= -1)
2473 cmdp
->OpCode
= cmndinfo
->OpCode
; /* special cache cmd. */
2474 else if (scp
->cmnd
[0] == RESERVE
)
2475 cmdp
->OpCode
= GDT_RESERVE_DRV
;
2476 else if (scp
->cmnd
[0] == RELEASE
)
2477 cmdp
->OpCode
= GDT_RELEASE_DRV
;
2478 else if (scp
->cmnd
[0] == ALLOW_MEDIUM_REMOVAL
) {
2479 if (scp
->cmnd
[4] & 1) /* prevent ? */
2480 cmdp
->OpCode
= GDT_MOUNT
;
2481 else if (scp
->cmnd
[3] & 1) /* removable drive ? */
2482 cmdp
->OpCode
= GDT_UNMOUNT
;
2484 cmdp
->OpCode
= GDT_FLUSH
;
2485 } else if (scp
->cmnd
[0] == WRITE_6
|| scp
->cmnd
[0] == WRITE_10
||
2486 scp
->cmnd
[0] == WRITE_12
|| scp
->cmnd
[0] == WRITE_16
2489 if (gdth_write_through
|| ((ha
->hdr
[hdrive
].rw_attribs
& 1) &&
2490 (ha
->cache_feat
& GDT_WR_THROUGH
)))
2491 cmdp
->OpCode
= GDT_WRITE_THR
;
2493 cmdp
->OpCode
= GDT_WRITE
;
2496 cmdp
->OpCode
= GDT_READ
;
2499 cmdp
->BoardNode
= LOCALBOARD
;
2501 cmdp
->u
.cache64
.DeviceNo
= hdrive
;
2502 cmdp
->u
.cache64
.BlockNo
= 1;
2503 cmdp
->u
.cache64
.sg_canz
= 0;
2505 cmdp
->u
.cache
.DeviceNo
= hdrive
;
2506 cmdp
->u
.cache
.BlockNo
= 1;
2507 cmdp
->u
.cache
.sg_canz
= 0;
2511 if (scp
->cmd_len
== 16) {
2512 memcpy(&no
, &scp
->cmnd
[2], sizeof(ulong64
));
2513 blockno
= be64_to_cpu(no
);
2514 memcpy(&cnt
, &scp
->cmnd
[10], sizeof(ulong32
));
2515 blockcnt
= be32_to_cpu(cnt
);
2516 } else if (scp
->cmd_len
== 10) {
2517 memcpy(&no
, &scp
->cmnd
[2], sizeof(ulong32
));
2518 blockno
= be32_to_cpu(no
);
2519 memcpy(&cnt
, &scp
->cmnd
[7], sizeof(ushort
));
2520 blockcnt
= be16_to_cpu(cnt
);
2522 memcpy(&no
, &scp
->cmnd
[0], sizeof(ulong32
));
2523 blockno
= be32_to_cpu(no
) & 0x001fffffUL
;
2524 blockcnt
= scp
->cmnd
[4]==0 ? 0x100 : scp
->cmnd
[4];
2527 cmdp
->u
.cache64
.BlockNo
= blockno
;
2528 cmdp
->u
.cache64
.BlockCnt
= blockcnt
;
2530 cmdp
->u
.cache
.BlockNo
= (ulong32
)blockno
;
2531 cmdp
->u
.cache
.BlockCnt
= blockcnt
;
2534 if (scsi_bufflen(scp
)) {
2535 cmndinfo
->dma_dir
= (read_write
== 1 ?
2536 PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
);
2537 sgcnt
= pci_map_sg(ha
->pdev
, scsi_sglist(scp
), scsi_sg_count(scp
),
2540 struct scatterlist
*sl
;
2542 cmdp
->u
.cache64
.DestAddr
= (ulong64
)-1;
2543 cmdp
->u
.cache64
.sg_canz
= sgcnt
;
2544 scsi_for_each_sg(scp
, sl
, sgcnt
, i
) {
2545 cmdp
->u
.cache64
.sg_lst
[i
].sg_ptr
= sg_dma_address(sl
);
2546 #ifdef GDTH_DMA_STATISTICS
2547 if (cmdp
->u
.cache64
.sg_lst
[i
].sg_ptr
> (ulong64
)0xffffffff)
2552 cmdp
->u
.cache64
.sg_lst
[i
].sg_len
= sg_dma_len(sl
);
2555 struct scatterlist
*sl
;
2557 cmdp
->u
.cache
.DestAddr
= 0xffffffff;
2558 cmdp
->u
.cache
.sg_canz
= sgcnt
;
2559 scsi_for_each_sg(scp
, sl
, sgcnt
, i
) {
2560 cmdp
->u
.cache
.sg_lst
[i
].sg_ptr
= sg_dma_address(sl
);
2561 #ifdef GDTH_DMA_STATISTICS
2564 cmdp
->u
.cache
.sg_lst
[i
].sg_len
= sg_dma_len(sl
);
2568 #ifdef GDTH_STATISTICS
2569 if (max_sg
< (ulong32
)sgcnt
) {
2570 max_sg
= (ulong32
)sgcnt
;
2571 TRACE3(("GDT: max_sg = %d\n",max_sg
));
2577 /* evaluate command size, check space */
2579 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2580 cmdp
->u
.cache64
.DestAddr
,cmdp
->u
.cache64
.sg_canz
,
2581 cmdp
->u
.cache64
.sg_lst
[0].sg_ptr
,
2582 cmdp
->u
.cache64
.sg_lst
[0].sg_len
));
2583 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2584 cmdp
->OpCode
,cmdp
->u
.cache64
.BlockNo
,cmdp
->u
.cache64
.BlockCnt
));
2585 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.cache64
.sg_lst
) +
2586 (ushort
)cmdp
->u
.cache64
.sg_canz
* sizeof(gdth_sg64_str
);
2588 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2589 cmdp
->u
.cache
.DestAddr
,cmdp
->u
.cache
.sg_canz
,
2590 cmdp
->u
.cache
.sg_lst
[0].sg_ptr
,
2591 cmdp
->u
.cache
.sg_lst
[0].sg_len
));
2592 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2593 cmdp
->OpCode
,cmdp
->u
.cache
.BlockNo
,cmdp
->u
.cache
.BlockCnt
));
2594 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.cache
.sg_lst
) +
2595 (ushort
)cmdp
->u
.cache
.sg_canz
* sizeof(gdth_sg_str
);
2597 if (ha
->cmd_len
& 3)
2598 ha
->cmd_len
+= (4 - (ha
->cmd_len
& 3));
2600 if (ha
->cmd_cnt
> 0) {
2601 if ((ha
->cmd_offs_dpmem
+ ha
->cmd_len
+ DPMEM_COMMAND_OFFSET
) >
2603 TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
2604 ha
->cmd_tab
[cmd_index
-2].cmnd
= UNUSED_CMND
;
2610 gdth_copy_command(ha
);
2614 static int gdth_fill_raw_cmd(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
, unchar b
)
2616 register gdth_cmd_str
*cmdp
;
2618 dma_addr_t sense_paddr
;
2619 int cmd_index
, sgcnt
, mode64
;
2623 struct gdth_cmndinfo
*cmndinfo
;
2625 t
= scp
->device
->id
;
2626 l
= scp
->device
->lun
;
2628 TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
2629 scp
->cmnd
[0],b
,t
,l
));
2631 if (ha
->type
==GDT_EISA
&& ha
->cmd_cnt
>0)
2634 mode64
= (ha
->raw_feat
& GDT_64BIT
) ? TRUE
: FALSE
;
2636 cmdp
->Service
= SCSIRAWSERVICE
;
2637 cmdp
->RequestBuffer
= scp
;
2638 /* search free command index */
2639 if (!(cmd_index
=gdth_get_cmd_index(ha
))) {
2640 TRACE(("GDT: No free command index found\n"));
2643 /* if it's the first command, set command semaphore */
2644 if (ha
->cmd_cnt
== 0)
2647 cmndinfo
= gdth_cmnd_priv(scp
);
2649 if (cmndinfo
->OpCode
!= -1) {
2650 cmdp
->OpCode
= cmndinfo
->OpCode
; /* special raw cmd. */
2651 cmdp
->BoardNode
= LOCALBOARD
;
2653 cmdp
->u
.raw64
.direction
= (cmndinfo
->phase
>> 8);
2654 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2655 cmdp
->OpCode
, cmdp
->u
.raw64
.direction
));
2656 /* evaluate command size */
2657 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.raw64
.sg_lst
);
2659 cmdp
->u
.raw
.direction
= (cmndinfo
->phase
>> 8);
2660 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2661 cmdp
->OpCode
, cmdp
->u
.raw
.direction
));
2662 /* evaluate command size */
2663 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.raw
.sg_lst
);
2667 page
= virt_to_page(scp
->sense_buffer
);
2668 offset
= (ulong
)scp
->sense_buffer
& ~PAGE_MASK
;
2669 sense_paddr
= pci_map_page(ha
->pdev
,page
,offset
,
2670 16,PCI_DMA_FROMDEVICE
);
2672 cmndinfo
->sense_paddr
= sense_paddr
;
2673 cmdp
->OpCode
= GDT_WRITE
; /* always */
2674 cmdp
->BoardNode
= LOCALBOARD
;
2676 cmdp
->u
.raw64
.reserved
= 0;
2677 cmdp
->u
.raw64
.mdisc_time
= 0;
2678 cmdp
->u
.raw64
.mcon_time
= 0;
2679 cmdp
->u
.raw64
.clen
= scp
->cmd_len
;
2680 cmdp
->u
.raw64
.target
= t
;
2681 cmdp
->u
.raw64
.lun
= l
;
2682 cmdp
->u
.raw64
.bus
= b
;
2683 cmdp
->u
.raw64
.priority
= 0;
2684 cmdp
->u
.raw64
.sdlen
= scsi_bufflen(scp
);
2685 cmdp
->u
.raw64
.sense_len
= 16;
2686 cmdp
->u
.raw64
.sense_data
= sense_paddr
;
2687 cmdp
->u
.raw64
.direction
=
2688 gdth_direction_tab
[scp
->cmnd
[0]]==DOU
? GDTH_DATA_OUT
:GDTH_DATA_IN
;
2689 memcpy(cmdp
->u
.raw64
.cmd
,scp
->cmnd
,16);
2690 cmdp
->u
.raw64
.sg_ranz
= 0;
2692 cmdp
->u
.raw
.reserved
= 0;
2693 cmdp
->u
.raw
.mdisc_time
= 0;
2694 cmdp
->u
.raw
.mcon_time
= 0;
2695 cmdp
->u
.raw
.clen
= scp
->cmd_len
;
2696 cmdp
->u
.raw
.target
= t
;
2697 cmdp
->u
.raw
.lun
= l
;
2698 cmdp
->u
.raw
.bus
= b
;
2699 cmdp
->u
.raw
.priority
= 0;
2700 cmdp
->u
.raw
.link_p
= 0;
2701 cmdp
->u
.raw
.sdlen
= scsi_bufflen(scp
);
2702 cmdp
->u
.raw
.sense_len
= 16;
2703 cmdp
->u
.raw
.sense_data
= sense_paddr
;
2704 cmdp
->u
.raw
.direction
=
2705 gdth_direction_tab
[scp
->cmnd
[0]]==DOU
? GDTH_DATA_OUT
:GDTH_DATA_IN
;
2706 memcpy(cmdp
->u
.raw
.cmd
,scp
->cmnd
,12);
2707 cmdp
->u
.raw
.sg_ranz
= 0;
2710 if (scsi_bufflen(scp
)) {
2711 cmndinfo
->dma_dir
= PCI_DMA_BIDIRECTIONAL
;
2712 sgcnt
= pci_map_sg(ha
->pdev
, scsi_sglist(scp
), scsi_sg_count(scp
),
2715 struct scatterlist
*sl
;
2717 cmdp
->u
.raw64
.sdata
= (ulong64
)-1;
2718 cmdp
->u
.raw64
.sg_ranz
= sgcnt
;
2719 scsi_for_each_sg(scp
, sl
, sgcnt
, i
) {
2720 cmdp
->u
.raw64
.sg_lst
[i
].sg_ptr
= sg_dma_address(sl
);
2721 #ifdef GDTH_DMA_STATISTICS
2722 if (cmdp
->u
.raw64
.sg_lst
[i
].sg_ptr
> (ulong64
)0xffffffff)
2727 cmdp
->u
.raw64
.sg_lst
[i
].sg_len
= sg_dma_len(sl
);
2730 struct scatterlist
*sl
;
2732 cmdp
->u
.raw
.sdata
= 0xffffffff;
2733 cmdp
->u
.raw
.sg_ranz
= sgcnt
;
2734 scsi_for_each_sg(scp
, sl
, sgcnt
, i
) {
2735 cmdp
->u
.raw
.sg_lst
[i
].sg_ptr
= sg_dma_address(sl
);
2736 #ifdef GDTH_DMA_STATISTICS
2739 cmdp
->u
.raw
.sg_lst
[i
].sg_len
= sg_dma_len(sl
);
2743 #ifdef GDTH_STATISTICS
2744 if (max_sg
< sgcnt
) {
2746 TRACE3(("GDT: max_sg = %d\n",sgcnt
));
2752 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2753 cmdp
->u
.raw64
.sdata
,cmdp
->u
.raw64
.sg_ranz
,
2754 cmdp
->u
.raw64
.sg_lst
[0].sg_ptr
,
2755 cmdp
->u
.raw64
.sg_lst
[0].sg_len
));
2756 /* evaluate command size */
2757 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.raw64
.sg_lst
) +
2758 (ushort
)cmdp
->u
.raw64
.sg_ranz
* sizeof(gdth_sg64_str
);
2760 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2761 cmdp
->u
.raw
.sdata
,cmdp
->u
.raw
.sg_ranz
,
2762 cmdp
->u
.raw
.sg_lst
[0].sg_ptr
,
2763 cmdp
->u
.raw
.sg_lst
[0].sg_len
));
2764 /* evaluate command size */
2765 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.raw
.sg_lst
) +
2766 (ushort
)cmdp
->u
.raw
.sg_ranz
* sizeof(gdth_sg_str
);
2770 if (ha
->cmd_len
& 3)
2771 ha
->cmd_len
+= (4 - (ha
->cmd_len
& 3));
2773 if (ha
->cmd_cnt
> 0) {
2774 if ((ha
->cmd_offs_dpmem
+ ha
->cmd_len
+ DPMEM_COMMAND_OFFSET
) >
2776 TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
2777 ha
->cmd_tab
[cmd_index
-2].cmnd
= UNUSED_CMND
;
2783 gdth_copy_command(ha
);
2787 static int gdth_special_cmd(gdth_ha_str
*ha
, Scsi_Cmnd
*scp
)
2789 register gdth_cmd_str
*cmdp
;
2790 struct gdth_cmndinfo
*cmndinfo
= gdth_cmnd_priv(scp
);
2794 TRACE2(("gdth_special_cmd(): "));
2796 if (ha
->type
==GDT_EISA
&& ha
->cmd_cnt
>0)
2799 *cmdp
= *cmndinfo
->internal_cmd_str
;
2800 cmdp
->RequestBuffer
= scp
;
2802 /* search free command index */
2803 if (!(cmd_index
=gdth_get_cmd_index(ha
))) {
2804 TRACE(("GDT: No free command index found\n"));
2808 /* if it's the first command, set command semaphore */
2809 if (ha
->cmd_cnt
== 0)
2812 /* evaluate command size, check space */
2813 if (cmdp
->OpCode
== GDT_IOCTL
) {
2814 TRACE2(("IOCTL\n"));
2816 GDTOFFSOF(gdth_cmd_str
,u
.ioctl
.p_param
) + sizeof(ulong64
);
2817 } else if (cmdp
->Service
== CACHESERVICE
) {
2818 TRACE2(("cache command %d\n",cmdp
->OpCode
));
2819 if (ha
->cache_feat
& GDT_64BIT
)
2821 GDTOFFSOF(gdth_cmd_str
,u
.cache64
.sg_lst
) + sizeof(gdth_sg64_str
);
2824 GDTOFFSOF(gdth_cmd_str
,u
.cache
.sg_lst
) + sizeof(gdth_sg_str
);
2825 } else if (cmdp
->Service
== SCSIRAWSERVICE
) {
2826 TRACE2(("raw command %d\n",cmdp
->OpCode
));
2827 if (ha
->raw_feat
& GDT_64BIT
)
2829 GDTOFFSOF(gdth_cmd_str
,u
.raw64
.sg_lst
) + sizeof(gdth_sg64_str
);
2832 GDTOFFSOF(gdth_cmd_str
,u
.raw
.sg_lst
) + sizeof(gdth_sg_str
);
2835 if (ha
->cmd_len
& 3)
2836 ha
->cmd_len
+= (4 - (ha
->cmd_len
& 3));
2838 if (ha
->cmd_cnt
> 0) {
2839 if ((ha
->cmd_offs_dpmem
+ ha
->cmd_len
+ DPMEM_COMMAND_OFFSET
) >
2841 TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
2842 ha
->cmd_tab
[cmd_index
-2].cmnd
= UNUSED_CMND
;
2848 gdth_copy_command(ha
);
2853 /* Controller event handling functions */
2854 static gdth_evt_str
*gdth_store_event(gdth_ha_str
*ha
, ushort source
,
2855 ushort idx
, gdth_evt_data
*evt
)
2860 /* no GDTH_LOCK_HA() ! */
2861 TRACE2(("gdth_store_event() source %d idx %d\n", source
, idx
));
2862 if (source
== 0) /* no source -> no event */
2865 if (ebuffer
[elastidx
].event_source
== source
&&
2866 ebuffer
[elastidx
].event_idx
== idx
&&
2867 ((evt
->size
!= 0 && ebuffer
[elastidx
].event_data
.size
!= 0 &&
2868 !memcmp((char *)&ebuffer
[elastidx
].event_data
.eu
,
2869 (char *)&evt
->eu
, evt
->size
)) ||
2870 (evt
->size
== 0 && ebuffer
[elastidx
].event_data
.size
== 0 &&
2871 !strcmp((char *)&ebuffer
[elastidx
].event_data
.event_string
,
2872 (char *)&evt
->event_string
)))) {
2873 e
= &ebuffer
[elastidx
];
2874 do_gettimeofday(&tv
);
2875 e
->last_stamp
= tv
.tv_sec
;
2878 if (ebuffer
[elastidx
].event_source
!= 0) { /* entry not free ? */
2880 if (elastidx
== MAX_EVENTS
)
2882 if (elastidx
== eoldidx
) { /* reached mark ? */
2884 if (eoldidx
== MAX_EVENTS
)
2888 e
= &ebuffer
[elastidx
];
2889 e
->event_source
= source
;
2891 do_gettimeofday(&tv
);
2892 e
->first_stamp
= e
->last_stamp
= tv
.tv_sec
;
2894 e
->event_data
= *evt
;
2900 static int gdth_read_event(gdth_ha_str
*ha
, int handle
, gdth_evt_str
*estr
)
2906 TRACE2(("gdth_read_event() handle %d\n", handle
));
2907 spin_lock_irqsave(&ha
->smp_lock
, flags
);
2912 estr
->event_source
= 0;
2914 if (eindex
>= MAX_EVENTS
) {
2915 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
2918 e
= &ebuffer
[eindex
];
2919 if (e
->event_source
!= 0) {
2920 if (eindex
!= elastidx
) {
2921 if (++eindex
== MAX_EVENTS
)
2926 memcpy(estr
, e
, sizeof(gdth_evt_str
));
2928 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
2932 static void gdth_readapp_event(gdth_ha_str
*ha
,
2933 unchar application
, gdth_evt_str
*estr
)
2938 unchar found
= FALSE
;
2940 TRACE2(("gdth_readapp_event() app. %d\n", application
));
2941 spin_lock_irqsave(&ha
->smp_lock
, flags
);
2944 e
= &ebuffer
[eindex
];
2945 if (e
->event_source
== 0)
2947 if ((e
->application
& application
) == 0) {
2948 e
->application
|= application
;
2952 if (eindex
== elastidx
)
2954 if (++eindex
== MAX_EVENTS
)
2958 memcpy(estr
, e
, sizeof(gdth_evt_str
));
2960 estr
->event_source
= 0;
2961 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
2964 static void gdth_clear_events(void)
2966 TRACE(("gdth_clear_events()"));
2968 eoldidx
= elastidx
= 0;
2969 ebuffer
[0].event_source
= 0;
2973 /* SCSI interface functions */
2975 static irqreturn_t
__gdth_interrupt(gdth_ha_str
*ha
,
2976 int gdth_from_wait
, int* pIndex
)
2978 gdt6m_dpram_str __iomem
*dp6m_ptr
= NULL
;
2979 gdt6_dpram_str __iomem
*dp6_ptr
;
2980 gdt2_dpram_str __iomem
*dp2_ptr
;
2987 int coalesced
= FALSE
;
2989 gdth_coal_status
*pcs
= NULL
;
2990 int act_int_coal
= 0;
2993 TRACE(("gdth_interrupt() IRQ %d\n", ha
->irq
));
2995 /* if polling and not from gdth_wait() -> return */
2997 if (!gdth_from_wait
) {
3003 spin_lock_irqsave(&ha
->smp_lock
, flags
);
3005 /* search controller */
3006 IStatus
= gdth_get_status(ha
);
3008 /* spurious interrupt */
3010 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3014 #ifdef GDTH_STATISTICS
3019 /* See if the fw is returning coalesced status */
3020 if (IStatus
== COALINDEX
) {
3021 /* Coalesced status. Setup the initial status
3022 buffer pointer and flags */
3023 pcs
= ha
->coal_stat
;
3030 /* For coalesced requests all status
3031 information is found in the status buffer */
3032 IStatus
= (unchar
)(pcs
->status
& 0xff);
3036 if (ha
->type
== GDT_EISA
) {
3037 if (IStatus
& 0x80) { /* error flag */
3039 ha
->status
= inw(ha
->bmic
+ MAILBOXREG
+8);
3040 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3041 } else /* no error */
3043 ha
->info
= inl(ha
->bmic
+ MAILBOXREG
+12);
3044 ha
->service
= inw(ha
->bmic
+ MAILBOXREG
+10);
3045 ha
->info2
= inl(ha
->bmic
+ MAILBOXREG
+4);
3047 outb(0xff, ha
->bmic
+ EDOORREG
); /* acknowledge interrupt */
3048 outb(0x00, ha
->bmic
+ SEMA1REG
); /* reset status semaphore */
3049 } else if (ha
->type
== GDT_ISA
) {
3051 if (IStatus
& 0x80) { /* error flag */
3053 ha
->status
= readw(&dp2_ptr
->u
.ic
.Status
);
3054 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3055 } else /* no error */
3057 ha
->info
= readl(&dp2_ptr
->u
.ic
.Info
[0]);
3058 ha
->service
= readw(&dp2_ptr
->u
.ic
.Service
);
3059 ha
->info2
= readl(&dp2_ptr
->u
.ic
.Info
[1]);
3061 writeb(0xff, &dp2_ptr
->io
.irqdel
); /* acknowledge interrupt */
3062 writeb(0, &dp2_ptr
->u
.ic
.Cmd_Index
);/* reset command index */
3063 writeb(0, &dp2_ptr
->io
.Sema1
); /* reset status semaphore */
3064 } else if (ha
->type
== GDT_PCI
) {
3066 if (IStatus
& 0x80) { /* error flag */
3068 ha
->status
= readw(&dp6_ptr
->u
.ic
.Status
);
3069 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3070 } else /* no error */
3072 ha
->info
= readl(&dp6_ptr
->u
.ic
.Info
[0]);
3073 ha
->service
= readw(&dp6_ptr
->u
.ic
.Service
);
3074 ha
->info2
= readl(&dp6_ptr
->u
.ic
.Info
[1]);
3076 writeb(0xff, &dp6_ptr
->io
.irqdel
); /* acknowledge interrupt */
3077 writeb(0, &dp6_ptr
->u
.ic
.Cmd_Index
);/* reset command index */
3078 writeb(0, &dp6_ptr
->io
.Sema1
); /* reset status semaphore */
3079 } else if (ha
->type
== GDT_PCINEW
) {
3080 if (IStatus
& 0x80) { /* error flag */
3082 ha
->status
= inw(PTR2USHORT(&ha
->plx
->status
));
3083 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3086 ha
->info
= inl(PTR2USHORT(&ha
->plx
->info
[0]));
3087 ha
->service
= inw(PTR2USHORT(&ha
->plx
->service
));
3088 ha
->info2
= inl(PTR2USHORT(&ha
->plx
->info
[1]));
3090 outb(0xff, PTR2USHORT(&ha
->plx
->edoor_reg
));
3091 outb(0x00, PTR2USHORT(&ha
->plx
->sema1_reg
));
3092 } else if (ha
->type
== GDT_PCIMPR
) {
3094 if (IStatus
& 0x80) { /* error flag */
3098 ha
->status
= pcs
->ext_status
& 0xffff;
3101 ha
->status
= readw(&dp6m_ptr
->i960r
.status
);
3102 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3103 } else /* no error */
3106 /* get information */
3108 ha
->info
= pcs
->info0
;
3109 ha
->info2
= pcs
->info1
;
3110 ha
->service
= (pcs
->ext_status
>> 16) & 0xffff;
3114 ha
->info
= readl(&dp6m_ptr
->i960r
.info
[0]);
3115 ha
->service
= readw(&dp6m_ptr
->i960r
.service
);
3116 ha
->info2
= readl(&dp6m_ptr
->i960r
.info
[1]);
3119 if (IStatus
== ASYNCINDEX
) {
3120 if (ha
->service
!= SCREENSERVICE
&&
3121 (ha
->fw_vers
& 0xff) >= 0x1a) {
3122 ha
->dvr
.severity
= readb
3123 (&((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.severity
);
3124 for (i
= 0; i
< 256; ++i
) {
3125 ha
->dvr
.event_string
[i
] = readb
3126 (&((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.evt_str
[i
]);
3127 if (ha
->dvr
.event_string
[i
] == 0)
3133 /* Make sure that non coalesced interrupts get cleared
3134 before being handled by gdth_async_event/gdth_sync_event */
3138 writeb(0xff, &dp6m_ptr
->i960r
.edoor_reg
);
3139 writeb(0, &dp6m_ptr
->i960r
.sema1_reg
);
3142 TRACE2(("gdth_interrupt() unknown controller type\n"));
3144 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3148 TRACE(("gdth_interrupt() index %d stat %d info %d\n",
3149 IStatus
,ha
->status
,ha
->info
));
3151 if (gdth_from_wait
) {
3152 *pIndex
= (int)IStatus
;
3155 if (IStatus
== ASYNCINDEX
) {
3156 TRACE2(("gdth_interrupt() async. event\n"));
3157 gdth_async_event(ha
);
3159 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3164 if (IStatus
== SPEZINDEX
) {
3165 TRACE2(("Service unknown or not initialized !\n"));
3166 ha
->dvr
.size
= sizeof(ha
->dvr
.eu
.driver
);
3167 ha
->dvr
.eu
.driver
.ionode
= ha
->hanum
;
3168 gdth_store_event(ha
, ES_DRIVER
, 4, &ha
->dvr
);
3170 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3173 scp
= ha
->cmd_tab
[IStatus
-2].cmnd
;
3174 Service
= ha
->cmd_tab
[IStatus
-2].service
;
3175 ha
->cmd_tab
[IStatus
-2].cmnd
= UNUSED_CMND
;
3176 if (scp
== UNUSED_CMND
) {
3177 TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus
));
3178 ha
->dvr
.size
= sizeof(ha
->dvr
.eu
.driver
);
3179 ha
->dvr
.eu
.driver
.ionode
= ha
->hanum
;
3180 ha
->dvr
.eu
.driver
.index
= IStatus
;
3181 gdth_store_event(ha
, ES_DRIVER
, 1, &ha
->dvr
);
3183 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3186 if (scp
== INTERNAL_CMND
) {
3187 TRACE(("gdth_interrupt() answer to internal command\n"));
3189 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3193 TRACE(("gdth_interrupt() sync. status\n"));
3194 rval
= gdth_sync_event(ha
,Service
,IStatus
,scp
);
3196 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3198 gdth_putq(ha
, scp
, gdth_cmnd_priv(scp
)->priority
);
3199 } else if (rval
== 1) {
3200 gdth_scsi_done(scp
);
3205 /* go to the next status in the status buffer */
3207 #ifdef GDTH_STATISTICS
3209 if (act_int_coal
> max_int_coal
) {
3210 max_int_coal
= act_int_coal
;
3211 printk("GDT: max_int_coal = %d\n",(ushort
)max_int_coal
);
3214 /* see if there is another status */
3215 if (pcs
->status
== 0)
3216 /* Stop the coalesce loop */
3221 /* coalescing only for new GDT_PCIMPR controllers available */
3222 if (ha
->type
== GDT_PCIMPR
&& coalesced
) {
3223 writeb(0xff, &dp6m_ptr
->i960r
.edoor_reg
);
3224 writeb(0, &dp6m_ptr
->i960r
.sema1_reg
);
3232 static irqreturn_t
gdth_interrupt(int irq
, void *dev_id
)
3234 gdth_ha_str
*ha
= dev_id
;
3236 return __gdth_interrupt(ha
, false, NULL
);
3239 static int gdth_sync_event(gdth_ha_str
*ha
, int service
, unchar index
,
3245 struct gdth_cmndinfo
*cmndinfo
= gdth_cmnd_priv(scp
);
3248 TRACE(("gdth_sync_event() serv %d status %d\n",
3249 service
,ha
->status
));
3251 if (service
== SCREENSERVICE
) {
3253 TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
3254 msg
->msg_len
,msg
->msg_answer
,msg
->msg_ext
,msg
->msg_alen
));
3255 if (msg
->msg_len
> MSGLEN
+1)
3256 msg
->msg_len
= MSGLEN
+1;
3258 if (!(msg
->msg_answer
&& msg
->msg_ext
)) {
3259 msg
->msg_text
[msg
->msg_len
] = '\0';
3260 printk("%s",msg
->msg_text
);
3263 if (msg
->msg_ext
&& !msg
->msg_answer
) {
3264 while (gdth_test_busy(ha
))
3266 cmdp
->Service
= SCREENSERVICE
;
3267 cmdp
->RequestBuffer
= SCREEN_CMND
;
3268 gdth_get_cmd_index(ha
);
3270 cmdp
->OpCode
= GDT_READ
;
3271 cmdp
->BoardNode
= LOCALBOARD
;
3272 cmdp
->u
.screen
.reserved
= 0;
3273 cmdp
->u
.screen
.su
.msg
.msg_handle
= msg
->msg_handle
;
3274 cmdp
->u
.screen
.su
.msg
.msg_addr
= ha
->msg_phys
;
3275 ha
->cmd_offs_dpmem
= 0;
3276 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.screen
.su
.msg
.msg_addr
)
3279 gdth_copy_command(ha
);
3280 gdth_release_event(ha
);
3284 if (msg
->msg_answer
&& msg
->msg_alen
) {
3285 /* default answers (getchar() not possible) */
3286 if (msg
->msg_alen
== 1) {
3289 msg
->msg_text
[0] = 0;
3293 msg
->msg_text
[0] = 1;
3294 msg
->msg_text
[1] = 0;
3297 msg
->msg_answer
= 0;
3298 while (gdth_test_busy(ha
))
3300 cmdp
->Service
= SCREENSERVICE
;
3301 cmdp
->RequestBuffer
= SCREEN_CMND
;
3302 gdth_get_cmd_index(ha
);
3304 cmdp
->OpCode
= GDT_WRITE
;
3305 cmdp
->BoardNode
= LOCALBOARD
;
3306 cmdp
->u
.screen
.reserved
= 0;
3307 cmdp
->u
.screen
.su
.msg
.msg_handle
= msg
->msg_handle
;
3308 cmdp
->u
.screen
.su
.msg
.msg_addr
= ha
->msg_phys
;
3309 ha
->cmd_offs_dpmem
= 0;
3310 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.screen
.su
.msg
.msg_addr
)
3313 gdth_copy_command(ha
);
3314 gdth_release_event(ha
);
3320 b
= scp
->device
->channel
;
3321 t
= scp
->device
->id
;
3322 if (cmndinfo
->OpCode
== -1 && b
!= ha
->virt_bus
) {
3323 ha
->raw
[BUS_L2P(ha
,b
)].io_cnt
[t
]--;
3325 /* cache or raw service */
3326 if (ha
->status
== S_BSY
) {
3327 TRACE2(("Controller busy -> retry !\n"));
3328 if (cmndinfo
->OpCode
== GDT_MOUNT
)
3329 cmndinfo
->OpCode
= GDT_CLUST_INFO
;
3333 if (scsi_bufflen(scp
))
3334 pci_unmap_sg(ha
->pdev
, scsi_sglist(scp
), scsi_sg_count(scp
),
3337 if (cmndinfo
->sense_paddr
)
3338 pci_unmap_page(ha
->pdev
, cmndinfo
->sense_paddr
, 16,
3339 PCI_DMA_FROMDEVICE
);
3341 if (ha
->status
== S_OK
) {
3342 cmndinfo
->status
= S_OK
;
3343 cmndinfo
->info
= ha
->info
;
3344 if (cmndinfo
->OpCode
!= -1) {
3345 TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
3347 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
3348 if (cmndinfo
->OpCode
== GDT_CLUST_INFO
) {
3349 ha
->hdr
[t
].cluster_type
= (unchar
)ha
->info
;
3350 if (!(ha
->hdr
[t
].cluster_type
&
3352 /* NOT MOUNTED -> MOUNT */
3353 cmndinfo
->OpCode
= GDT_MOUNT
;
3354 if (ha
->hdr
[t
].cluster_type
&
3356 /* cluster drive RESERVED (on the other node) */
3357 cmndinfo
->phase
= -2; /* reservation conflict */
3360 cmndinfo
->OpCode
= -1;
3363 if (cmndinfo
->OpCode
== GDT_MOUNT
) {
3364 ha
->hdr
[t
].cluster_type
|= CLUSTER_MOUNTED
;
3365 ha
->hdr
[t
].media_changed
= TRUE
;
3366 } else if (cmndinfo
->OpCode
== GDT_UNMOUNT
) {
3367 ha
->hdr
[t
].cluster_type
&= ~CLUSTER_MOUNTED
;
3368 ha
->hdr
[t
].media_changed
= TRUE
;
3370 cmndinfo
->OpCode
= -1;
3373 cmndinfo
->priority
= HIGH_PRI
;
3376 /* RESERVE/RELEASE ? */
3377 if (scp
->cmnd
[0] == RESERVE
) {
3378 ha
->hdr
[t
].cluster_type
|= CLUSTER_RESERVED
;
3379 } else if (scp
->cmnd
[0] == RELEASE
) {
3380 ha
->hdr
[t
].cluster_type
&= ~CLUSTER_RESERVED
;
3382 scp
->result
= DID_OK
<< 16;
3383 scp
->sense_buffer
[0] = 0;
3386 cmndinfo
->status
= ha
->status
;
3387 cmndinfo
->info
= ha
->info
;
3389 if (cmndinfo
->OpCode
!= -1) {
3390 TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
3391 cmndinfo
->OpCode
, ha
->status
));
3392 if (cmndinfo
->OpCode
== GDT_SCAN_START
||
3393 cmndinfo
->OpCode
== GDT_SCAN_END
) {
3394 cmndinfo
->OpCode
= -1;
3396 cmndinfo
->priority
= HIGH_PRI
;
3399 memset((char*)scp
->sense_buffer
,0,16);
3400 scp
->sense_buffer
[0] = 0x70;
3401 scp
->sense_buffer
[2] = NOT_READY
;
3402 scp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
3403 } else if (service
== CACHESERVICE
) {
3404 if (ha
->status
== S_CACHE_UNKNOWN
&&
3405 (ha
->hdr
[t
].cluster_type
&
3406 CLUSTER_RESERVE_STATE
) == CLUSTER_RESERVE_STATE
) {
3407 /* bus reset -> force GDT_CLUST_INFO */
3408 ha
->hdr
[t
].cluster_type
&= ~CLUSTER_RESERVED
;
3410 memset((char*)scp
->sense_buffer
,0,16);
3411 if (ha
->status
== (ushort
)S_CACHE_RESERV
) {
3412 scp
->result
= (DID_OK
<< 16) | (RESERVATION_CONFLICT
<< 1);
3414 scp
->sense_buffer
[0] = 0x70;
3415 scp
->sense_buffer
[2] = NOT_READY
;
3416 scp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
3418 if (!cmndinfo
->internal_command
) {
3419 ha
->dvr
.size
= sizeof(ha
->dvr
.eu
.sync
);
3420 ha
->dvr
.eu
.sync
.ionode
= ha
->hanum
;
3421 ha
->dvr
.eu
.sync
.service
= service
;
3422 ha
->dvr
.eu
.sync
.status
= ha
->status
;
3423 ha
->dvr
.eu
.sync
.info
= ha
->info
;
3424 ha
->dvr
.eu
.sync
.hostdrive
= t
;
3425 if (ha
->status
>= 0x8000)
3426 gdth_store_event(ha
, ES_SYNC
, 0, &ha
->dvr
);
3428 gdth_store_event(ha
, ES_SYNC
, service
, &ha
->dvr
);
3431 /* sense buffer filled from controller firmware (DMA) */
3432 if (ha
->status
!= S_RAW_SCSI
|| ha
->info
>= 0x100) {
3433 scp
->result
= DID_BAD_TARGET
<< 16;
3435 scp
->result
= (DID_OK
<< 16) | ha
->info
;
3439 if (!cmndinfo
->wait_for_completion
)
3440 cmndinfo
->wait_for_completion
++;
3448 static char *async_cache_tab
[] = {
3449 /* 0*/ "\011\000\002\002\002\004\002\006\004"
3450 "GDT HA %u, service %u, async. status %u/%lu unknown",
3451 /* 1*/ "\011\000\002\002\002\004\002\006\004"
3452 "GDT HA %u, service %u, async. status %u/%lu unknown",
3453 /* 2*/ "\005\000\002\006\004"
3454 "GDT HA %u, Host Drive %lu not ready",
3455 /* 3*/ "\005\000\002\006\004"
3456 "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",
3457 /* 4*/ "\005\000\002\006\004"
3458 "GDT HA %u, mirror update on Host Drive %lu failed",
3459 /* 5*/ "\005\000\002\006\004"
3460 "GDT HA %u, Mirror Drive %lu failed",
3461 /* 6*/ "\005\000\002\006\004"
3462 "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",
3463 /* 7*/ "\005\000\002\006\004"
3464 "GDT HA %u, Host Drive %lu write protected",
3465 /* 8*/ "\005\000\002\006\004"
3466 "GDT HA %u, media changed in Host Drive %lu",
3467 /* 9*/ "\005\000\002\006\004"
3468 "GDT HA %u, Host Drive %lu is offline",
3469 /*10*/ "\005\000\002\006\004"
3470 "GDT HA %u, media change of Mirror Drive %lu",
3471 /*11*/ "\005\000\002\006\004"
3472 "GDT HA %u, Mirror Drive %lu is write protected",
3473 /*12*/ "\005\000\002\006\004"
3474 "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
3475 /*13*/ "\007\000\002\006\002\010\002"
3476 "GDT HA %u, Array Drive %u: Cache Drive %u failed",
3477 /*14*/ "\005\000\002\006\002"
3478 "GDT HA %u, Array Drive %u: FAIL state entered",
3479 /*15*/ "\005\000\002\006\002"
3480 "GDT HA %u, Array Drive %u: error",
3481 /*16*/ "\007\000\002\006\002\010\002"
3482 "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
3483 /*17*/ "\005\000\002\006\002"
3484 "GDT HA %u, Array Drive %u: parity build failed",
3485 /*18*/ "\005\000\002\006\002"
3486 "GDT HA %u, Array Drive %u: drive rebuild failed",
3487 /*19*/ "\005\000\002\010\002"
3488 "GDT HA %u, Test of Hot Fix %u failed",
3489 /*20*/ "\005\000\002\006\002"
3490 "GDT HA %u, Array Drive %u: drive build finished successfully",
3491 /*21*/ "\005\000\002\006\002"
3492 "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
3493 /*22*/ "\007\000\002\006\002\010\002"
3494 "GDT HA %u, Array Drive %u: Hot Fix %u activated",
3495 /*23*/ "\005\000\002\006\002"
3496 "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
3497 /*24*/ "\005\000\002\010\002"
3498 "GDT HA %u, mirror update on Cache Drive %u completed",
3499 /*25*/ "\005\000\002\010\002"
3500 "GDT HA %u, mirror update on Cache Drive %lu failed",
3501 /*26*/ "\005\000\002\006\002"
3502 "GDT HA %u, Array Drive %u: drive rebuild started",
3503 /*27*/ "\005\000\002\012\001"
3504 "GDT HA %u, Fault bus %u: SHELF OK detected",
3505 /*28*/ "\005\000\002\012\001"
3506 "GDT HA %u, Fault bus %u: SHELF not OK detected",
3507 /*29*/ "\007\000\002\012\001\013\001"
3508 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
3509 /*30*/ "\007\000\002\012\001\013\001"
3510 "GDT HA %u, Fault bus %u, ID %u: new disk detected",
3511 /*31*/ "\007\000\002\012\001\013\001"
3512 "GDT HA %u, Fault bus %u, ID %u: old disk detected",
3513 /*32*/ "\007\000\002\012\001\013\001"
3514 "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid",
3515 /*33*/ "\007\000\002\012\001\013\001"
3516 "GDT HA %u, Fault bus %u, ID %u: invalid device detected",
3517 /*34*/ "\011\000\002\012\001\013\001\006\004"
3518 "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
3519 /*35*/ "\007\000\002\012\001\013\001"
3520 "GDT HA %u, Fault bus %u, ID %u: disk write protected",
3521 /*36*/ "\007\000\002\012\001\013\001"
3522 "GDT HA %u, Fault bus %u, ID %u: disk not available",
3523 /*37*/ "\007\000\002\012\001\006\004"
3524 "GDT HA %u, Fault bus %u: swap detected (%lu)",
3525 /*38*/ "\007\000\002\012\001\013\001"
3526 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
3527 /*39*/ "\007\000\002\012\001\013\001"
3528 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
3529 /*40*/ "\007\000\002\012\001\013\001"
3530 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
3531 /*41*/ "\007\000\002\012\001\013\001"
3532 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
3533 /*42*/ "\005\000\002\006\002"
3534 "GDT HA %u, Array Drive %u: drive build started",
3535 /*43*/ "\003\000\002"
3536 "GDT HA %u, DRAM parity error detected",
3537 /*44*/ "\005\000\002\006\002"
3538 "GDT HA %u, Mirror Drive %u: update started",
3539 /*45*/ "\007\000\002\006\002\010\002"
3540 "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
3541 /*46*/ "\005\000\002\006\002"
3542 "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
3543 /*47*/ "\005\000\002\006\002"
3544 "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
3545 /*48*/ "\005\000\002\006\002"
3546 "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
3547 /*49*/ "\005\000\002\006\002"
3548 "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
3549 /*50*/ "\007\000\002\012\001\013\001"
3550 "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
3551 /*51*/ "\005\000\002\006\002"
3552 "GDT HA %u, Array Drive %u: expand started",
3553 /*52*/ "\005\000\002\006\002"
3554 "GDT HA %u, Array Drive %u: expand finished successfully",
3555 /*53*/ "\005\000\002\006\002"
3556 "GDT HA %u, Array Drive %u: expand failed",
3557 /*54*/ "\003\000\002"
3558 "GDT HA %u, CPU temperature critical",
3559 /*55*/ "\003\000\002"
3560 "GDT HA %u, CPU temperature OK",
3561 /*56*/ "\005\000\002\006\004"
3562 "GDT HA %u, Host drive %lu created",
3563 /*57*/ "\005\000\002\006\002"
3564 "GDT HA %u, Array Drive %u: expand restarted",
3565 /*58*/ "\005\000\002\006\002"
3566 "GDT HA %u, Array Drive %u: expand stopped",
3567 /*59*/ "\005\000\002\010\002"
3568 "GDT HA %u, Mirror Drive %u: drive build quited",
3569 /*60*/ "\005\000\002\006\002"
3570 "GDT HA %u, Array Drive %u: parity build quited",
3571 /*61*/ "\005\000\002\006\002"
3572 "GDT HA %u, Array Drive %u: drive rebuild quited",
3573 /*62*/ "\005\000\002\006\002"
3574 "GDT HA %u, Array Drive %u: parity verify started",
3575 /*63*/ "\005\000\002\006\002"
3576 "GDT HA %u, Array Drive %u: parity verify done",
3577 /*64*/ "\005\000\002\006\002"
3578 "GDT HA %u, Array Drive %u: parity verify failed",
3579 /*65*/ "\005\000\002\006\002"
3580 "GDT HA %u, Array Drive %u: parity error detected",
3581 /*66*/ "\005\000\002\006\002"
3582 "GDT HA %u, Array Drive %u: parity verify quited",
3583 /*67*/ "\005\000\002\006\002"
3584 "GDT HA %u, Host Drive %u reserved",
3585 /*68*/ "\005\000\002\006\002"
3586 "GDT HA %u, Host Drive %u mounted and released",
3587 /*69*/ "\005\000\002\006\002"
3588 "GDT HA %u, Host Drive %u released",
3589 /*70*/ "\003\000\002"
3590 "GDT HA %u, DRAM error detected and corrected with ECC",
3591 /*71*/ "\003\000\002"
3592 "GDT HA %u, Uncorrectable DRAM error detected with ECC",
3593 /*72*/ "\011\000\002\012\001\013\001\014\001"
3594 "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
3595 /*73*/ "\005\000\002\006\002"
3596 "GDT HA %u, Host drive %u resetted locally",
3597 /*74*/ "\005\000\002\006\002"
3598 "GDT HA %u, Host drive %u resetted remotely",
3599 /*75*/ "\003\000\002"
3600 "GDT HA %u, async. status 75 unknown",
3604 static int gdth_async_event(gdth_ha_str
*ha
)
3610 TRACE2(("gdth_async_event() ha %d serv %d\n",
3611 ha
->hanum
, ha
->service
));
3613 if (ha
->service
== SCREENSERVICE
) {
3614 if (ha
->status
== MSG_REQUEST
) {
3615 while (gdth_test_busy(ha
))
3617 cmdp
->Service
= SCREENSERVICE
;
3618 cmdp
->RequestBuffer
= SCREEN_CMND
;
3619 cmd_index
= gdth_get_cmd_index(ha
);
3621 cmdp
->OpCode
= GDT_READ
;
3622 cmdp
->BoardNode
= LOCALBOARD
;
3623 cmdp
->u
.screen
.reserved
= 0;
3624 cmdp
->u
.screen
.su
.msg
.msg_handle
= MSG_INV_HANDLE
;
3625 cmdp
->u
.screen
.su
.msg
.msg_addr
= ha
->msg_phys
;
3626 ha
->cmd_offs_dpmem
= 0;
3627 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.screen
.su
.msg
.msg_addr
)
3630 gdth_copy_command(ha
);
3631 if (ha
->type
== GDT_EISA
)
3632 printk("[EISA slot %d] ",(ushort
)ha
->brd_phys
);
3633 else if (ha
->type
== GDT_ISA
)
3634 printk("[DPMEM 0x%4X] ",(ushort
)ha
->brd_phys
);
3636 printk("[PCI %d/%d] ",(ushort
)(ha
->brd_phys
>>8),
3637 (ushort
)((ha
->brd_phys
>>3)&0x1f));
3638 gdth_release_event(ha
);
3642 if (ha
->type
== GDT_PCIMPR
&&
3643 (ha
->fw_vers
& 0xff) >= 0x1a) {
3645 ha
->dvr
.eu
.async
.ionode
= ha
->hanum
;
3646 ha
->dvr
.eu
.async
.status
= ha
->status
;
3647 /* severity and event_string already set! */
3649 ha
->dvr
.size
= sizeof(ha
->dvr
.eu
.async
);
3650 ha
->dvr
.eu
.async
.ionode
= ha
->hanum
;
3651 ha
->dvr
.eu
.async
.service
= ha
->service
;
3652 ha
->dvr
.eu
.async
.status
= ha
->status
;
3653 ha
->dvr
.eu
.async
.info
= ha
->info
;
3654 *(ulong32
*)ha
->dvr
.eu
.async
.scsi_coord
= ha
->info2
;
3656 gdth_store_event( ha
, ES_ASYNC
, ha
->service
, &ha
->dvr
);
3657 gdth_log_event( &ha
->dvr
, NULL
);
3659 /* new host drive from expand? */
3660 if (ha
->service
== CACHESERVICE
&& ha
->status
== 56) {
3661 TRACE2(("gdth_async_event(): new host drive %d created\n",
3663 /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
3669 static void gdth_log_event(gdth_evt_data
*dvr
, char *buffer
)
3671 gdth_stackframe stack
;
3675 TRACE2(("gdth_log_event()\n"));
3676 if (dvr
->size
== 0) {
3677 if (buffer
== NULL
) {
3678 printk("Adapter %d: %s\n",dvr
->eu
.async
.ionode
,dvr
->event_string
);
3680 sprintf(buffer
,"Adapter %d: %s\n",
3681 dvr
->eu
.async
.ionode
,dvr
->event_string
);
3683 } else if (dvr
->eu
.async
.service
== CACHESERVICE
&&
3684 INDEX_OK(dvr
->eu
.async
.status
, async_cache_tab
)) {
3685 TRACE2(("GDT: Async. event cache service, event no.: %d\n",
3686 dvr
->eu
.async
.status
));
3688 f
= async_cache_tab
[dvr
->eu
.async
.status
];
3690 /* i: parameter to push, j: stack element to fill */
3691 for (j
=0,i
=1; i
< f
[0]; i
+=2) {
3694 stack
.b
[j
++] = *(ulong32
*)&dvr
->eu
.stream
[(int)f
[i
]];
3697 stack
.b
[j
++] = *(ushort
*)&dvr
->eu
.stream
[(int)f
[i
]];
3700 stack
.b
[j
++] = *(unchar
*)&dvr
->eu
.stream
[(int)f
[i
]];
3707 if (buffer
== NULL
) {
3708 printk(&f
[(int)f
[0]],stack
);
3711 sprintf(buffer
,&f
[(int)f
[0]],stack
);
3715 if (buffer
== NULL
) {
3716 printk("GDT HA %u, Unknown async. event service %d event no. %d\n",
3717 dvr
->eu
.async
.ionode
,dvr
->eu
.async
.service
,dvr
->eu
.async
.status
);
3719 sprintf(buffer
,"GDT HA %u, Unknown async. event service %d event no. %d",
3720 dvr
->eu
.async
.ionode
,dvr
->eu
.async
.service
,dvr
->eu
.async
.status
);
3725 #ifdef GDTH_STATISTICS
3726 static unchar gdth_timer_running
;
3728 static void gdth_timeout(ulong data
)
3735 if(unlikely(list_empty(&gdth_instances
))) {
3736 gdth_timer_running
= 0;
3740 ha
= list_first_entry(&gdth_instances
, gdth_ha_str
, list
);
3741 spin_lock_irqsave(&ha
->smp_lock
, flags
);
3743 for (act_stats
=0,i
=0; i
<GDTH_MAXCMDS
; ++i
)
3744 if (ha
->cmd_tab
[i
].cmnd
!= UNUSED_CMND
)
3747 for (act_rq
=0,nscp
=ha
->req_first
; nscp
; nscp
=(Scsi_Cmnd
*)nscp
->SCp
.ptr
)
3750 TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
3751 act_ints
, act_ios
, act_stats
, act_rq
));
3752 act_ints
= act_ios
= 0;
3754 gdth_timer
.expires
= jiffies
+ 30 * HZ
;
3755 add_timer(&gdth_timer
);
3756 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3759 static void gdth_timer_init(void)
3761 if (gdth_timer_running
)
3763 gdth_timer_running
= 1;
3764 TRACE2(("gdth_detect(): Initializing timer !\n"));
3765 gdth_timer
.expires
= jiffies
+ HZ
;
3766 gdth_timer
.data
= 0L;
3767 gdth_timer
.function
= gdth_timeout
;
3768 add_timer(&gdth_timer
);
3771 static inline void gdth_timer_init(void)
3776 static void __init
internal_setup(char *str
,int *ints
)
3779 char *cur_str
, *argv
;
3781 TRACE2(("internal_setup() str %s ints[0] %d\n",
3782 str
? str
:"NULL", ints
? ints
[0]:0));
3784 /* read irq[] from ints[] */
3790 for (i
= 0; i
< argc
; ++i
)
3795 /* analyse string */
3797 while (argv
&& (cur_str
= strchr(argv
, ':'))) {
3798 int val
= 0, c
= *++cur_str
;
3800 if (c
== 'n' || c
== 'N')
3802 else if (c
== 'y' || c
== 'Y')
3805 val
= (int)simple_strtoul(cur_str
, NULL
, 0);
3807 if (!strncmp(argv
, "disable:", 8))
3809 else if (!strncmp(argv
, "reserve_mode:", 13))
3811 else if (!strncmp(argv
, "reverse_scan:", 13))
3813 else if (!strncmp(argv
, "hdr_channel:", 12))
3815 else if (!strncmp(argv
, "max_ids:", 8))
3817 else if (!strncmp(argv
, "rescan:", 7))
3819 else if (!strncmp(argv
, "shared_access:", 14))
3820 shared_access
= val
;
3821 else if (!strncmp(argv
, "probe_eisa_isa:", 15))
3822 probe_eisa_isa
= val
;
3823 else if (!strncmp(argv
, "reserve_list:", 13)) {
3824 reserve_list
[0] = val
;
3825 for (i
= 1; i
< MAX_RES_ARGS
; i
++) {
3826 cur_str
= strchr(cur_str
, ',');
3829 if (!isdigit((int)*++cur_str
)) {
3834 (int)simple_strtoul(cur_str
, NULL
, 0);
3842 if ((argv
= strchr(argv
, ',')))
3847 int __init
option_setup(char *str
)
3853 TRACE2(("option_setup() str %s\n", str
? str
:"NULL"));
3855 while (cur
&& isdigit(*cur
) && i
<= MAXHA
) {
3856 ints
[i
++] = simple_strtoul(cur
, NULL
, 0);
3857 if ((cur
= strchr(cur
, ',')) != NULL
) cur
++;
3861 internal_setup(cur
, ints
);
3865 static const char *gdth_ctr_name(gdth_ha_str
*ha
)
3867 TRACE2(("gdth_ctr_name()\n"));
3869 if (ha
->type
== GDT_EISA
) {
3870 switch (ha
->stype
) {
3872 return("GDT3000/3020");
3874 return("GDT3000A/3020A/3050A");
3876 return("GDT3000B/3010A");
3878 } else if (ha
->type
== GDT_ISA
) {
3879 return("GDT2000/2020");
3880 } else if (ha
->type
== GDT_PCI
) {
3881 switch (ha
->pdev
->device
) {
3882 case PCI_DEVICE_ID_VORTEX_GDT60x0
:
3883 return("GDT6000/6020/6050");
3884 case PCI_DEVICE_ID_VORTEX_GDT6000B
:
3885 return("GDT6000B/6010");
3888 /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
3893 static const char *gdth_info(struct Scsi_Host
*shp
)
3895 gdth_ha_str
*ha
= shost_priv(shp
);
3897 TRACE2(("gdth_info()\n"));
3898 return ((const char *)ha
->binfo
.type_string
);
3901 static int gdth_eh_bus_reset(Scsi_Cmnd
*scp
)
3903 gdth_ha_str
*ha
= shost_priv(scp
->device
->host
);
3909 TRACE2(("gdth_eh_bus_reset()\n"));
3911 b
= scp
->device
->channel
;
3913 /* clear command tab */
3914 spin_lock_irqsave(&ha
->smp_lock
, flags
);
3915 for (i
= 0; i
< GDTH_MAXCMDS
; ++i
) {
3916 cmnd
= ha
->cmd_tab
[i
].cmnd
;
3917 if (!SPECIAL_SCP(cmnd
) && cmnd
->device
->channel
== b
)
3918 ha
->cmd_tab
[i
].cmnd
= UNUSED_CMND
;
3920 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3922 if (b
== ha
->virt_bus
) {
3924 for (i
= 0; i
< MAX_HDRIVES
; ++i
) {
3925 if (ha
->hdr
[i
].present
) {
3926 spin_lock_irqsave(&ha
->smp_lock
, flags
);
3927 gdth_polling
= TRUE
;
3928 while (gdth_test_busy(ha
))
3930 if (gdth_internal_cmd(ha
, CACHESERVICE
,
3931 GDT_CLUST_RESET
, i
, 0, 0))
3932 ha
->hdr
[i
].cluster_type
&= ~CLUSTER_RESERVED
;
3933 gdth_polling
= FALSE
;
3934 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3939 spin_lock_irqsave(&ha
->smp_lock
, flags
);
3940 for (i
= 0; i
< MAXID
; ++i
)
3941 ha
->raw
[BUS_L2P(ha
,b
)].io_cnt
[i
] = 0;
3942 gdth_polling
= TRUE
;
3943 while (gdth_test_busy(ha
))
3945 gdth_internal_cmd(ha
, SCSIRAWSERVICE
, GDT_RESET_BUS
,
3946 BUS_L2P(ha
,b
), 0, 0);
3947 gdth_polling
= FALSE
;
3948 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
3953 static int gdth_bios_param(struct scsi_device
*sdev
,struct block_device
*bdev
,sector_t cap
,int *ip
)
3956 gdth_ha_str
*ha
= shost_priv(sdev
->host
);
3957 struct scsi_device
*sd
;
3964 TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", ha
->hanum
, b
, t
));
3966 if (b
!= ha
->virt_bus
|| ha
->hdr
[t
].heads
== 0) {
3967 /* raw device or host drive without mapping information */
3968 TRACE2(("Evaluate mapping\n"));
3969 gdth_eval_mapping(capacity
,&ip
[2],&ip
[0],&ip
[1]);
3971 ip
[0] = ha
->hdr
[t
].heads
;
3972 ip
[1] = ha
->hdr
[t
].secs
;
3973 ip
[2] = capacity
/ ip
[0] / ip
[1];
3976 TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
3977 ip
[0],ip
[1],ip
[2]));
3982 static int gdth_queuecommand(struct scsi_cmnd
*scp
,
3983 void (*done
)(struct scsi_cmnd
*))
3985 gdth_ha_str
*ha
= shost_priv(scp
->device
->host
);
3986 struct gdth_cmndinfo
*cmndinfo
;
3988 TRACE(("gdth_queuecommand() cmd 0x%x\n", scp
->cmnd
[0]));
3990 cmndinfo
= gdth_get_cmndinfo(ha
);
3993 scp
->scsi_done
= done
;
3994 gdth_update_timeout(scp
, scp
->timeout_per_command
* 6);
3995 cmndinfo
->priority
= DEFAULT_PRI
;
3997 return __gdth_queuecommand(ha
, scp
, cmndinfo
);
4000 static int __gdth_queuecommand(gdth_ha_str
*ha
, struct scsi_cmnd
*scp
,
4001 struct gdth_cmndinfo
*cmndinfo
)
4003 scp
->host_scribble
= (unsigned char *)cmndinfo
;
4004 cmndinfo
->wait_for_completion
= 1;
4005 cmndinfo
->phase
= -1;
4006 cmndinfo
->OpCode
= -1;
4008 #ifdef GDTH_STATISTICS
4012 gdth_putq(ha
, scp
, cmndinfo
->priority
);
4018 static int gdth_open(struct inode
*inode
, struct file
*filep
)
4022 list_for_each_entry(ha
, &gdth_instances
, list
) {
4024 ha
->sdev
= scsi_get_host_dev(ha
->shost
);
4027 TRACE(("gdth_open()\n"));
4031 static int gdth_close(struct inode
*inode
, struct file
*filep
)
4033 TRACE(("gdth_close()\n"));
4037 static int ioc_event(void __user
*arg
)
4039 gdth_ioctl_event evt
;
4043 if (copy_from_user(&evt
, arg
, sizeof(gdth_ioctl_event
)))
4045 ha
= gdth_find_ha(evt
.ionode
);
4049 if (evt
.erase
== 0xff) {
4050 if (evt
.event
.event_source
== ES_TEST
)
4051 evt
.event
.event_data
.size
=sizeof(evt
.event
.event_data
.eu
.test
);
4052 else if (evt
.event
.event_source
== ES_DRIVER
)
4053 evt
.event
.event_data
.size
=sizeof(evt
.event
.event_data
.eu
.driver
);
4054 else if (evt
.event
.event_source
== ES_SYNC
)
4055 evt
.event
.event_data
.size
=sizeof(evt
.event
.event_data
.eu
.sync
);
4057 evt
.event
.event_data
.size
=sizeof(evt
.event
.event_data
.eu
.async
);
4058 spin_lock_irqsave(&ha
->smp_lock
, flags
);
4059 gdth_store_event(ha
, evt
.event
.event_source
, evt
.event
.event_idx
,
4060 &evt
.event
.event_data
);
4061 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
4062 } else if (evt
.erase
== 0xfe) {
4063 gdth_clear_events();
4064 } else if (evt
.erase
== 0) {
4065 evt
.handle
= gdth_read_event(ha
, evt
.handle
, &evt
.event
);
4067 gdth_readapp_event(ha
, evt
.erase
, &evt
.event
);
4069 if (copy_to_user(arg
, &evt
, sizeof(gdth_ioctl_event
)))
4074 static int ioc_lockdrv(void __user
*arg
)
4076 gdth_ioctl_lockdrv ldrv
;
4081 if (copy_from_user(&ldrv
, arg
, sizeof(gdth_ioctl_lockdrv
)))
4083 ha
= gdth_find_ha(ldrv
.ionode
);
4087 for (i
= 0; i
< ldrv
.drive_cnt
&& i
< MAX_HDRIVES
; ++i
) {
4089 if (j
>= MAX_HDRIVES
|| !ha
->hdr
[j
].present
)
4092 spin_lock_irqsave(&ha
->smp_lock
, flags
);
4093 ha
->hdr
[j
].lock
= 1;
4094 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
4095 gdth_wait_completion(ha
, ha
->bus_cnt
, j
);
4096 gdth_stop_timeout(ha
, ha
->bus_cnt
, j
);
4098 spin_lock_irqsave(&ha
->smp_lock
, flags
);
4099 ha
->hdr
[j
].lock
= 0;
4100 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
4101 gdth_start_timeout(ha
, ha
->bus_cnt
, j
);
4108 static int ioc_resetdrv(void __user
*arg
, char *cmnd
)
4110 gdth_ioctl_reset res
;
4115 if (copy_from_user(&res
, arg
, sizeof(gdth_ioctl_reset
)) ||
4116 res
.number
>= MAX_HDRIVES
)
4118 ha
= gdth_find_ha(res
.ionode
);
4122 if (!ha
->hdr
[res
.number
].present
)
4124 memset(&cmd
, 0, sizeof(gdth_cmd_str
));
4125 cmd
.Service
= CACHESERVICE
;
4126 cmd
.OpCode
= GDT_CLUST_RESET
;
4127 if (ha
->cache_feat
& GDT_64BIT
)
4128 cmd
.u
.cache64
.DeviceNo
= res
.number
;
4130 cmd
.u
.cache
.DeviceNo
= res
.number
;
4132 rval
= __gdth_execute(ha
->sdev
, &cmd
, cmnd
, 30, NULL
);
4137 if (copy_to_user(arg
, &res
, sizeof(gdth_ioctl_reset
)))
4142 static int ioc_general(void __user
*arg
, char *cmnd
)
4144 gdth_ioctl_general gen
;
4150 if (copy_from_user(&gen
, arg
, sizeof(gdth_ioctl_general
)))
4152 ha
= gdth_find_ha(gen
.ionode
);
4155 if (gen
.data_len
+ gen
.sense_len
!= 0) {
4156 if (!(buf
= gdth_ioctl_alloc(ha
, gen
.data_len
+ gen
.sense_len
,
4159 if (copy_from_user(buf
, arg
+ sizeof(gdth_ioctl_general
),
4160 gen
.data_len
+ gen
.sense_len
)) {
4161 gdth_ioctl_free(ha
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
4165 if (gen
.command
.OpCode
== GDT_IOCTL
) {
4166 gen
.command
.u
.ioctl
.p_param
= paddr
;
4167 } else if (gen
.command
.Service
== CACHESERVICE
) {
4168 if (ha
->cache_feat
& GDT_64BIT
) {
4169 /* copy elements from 32-bit IOCTL structure */
4170 gen
.command
.u
.cache64
.BlockCnt
= gen
.command
.u
.cache
.BlockCnt
;
4171 gen
.command
.u
.cache64
.BlockNo
= gen
.command
.u
.cache
.BlockNo
;
4172 gen
.command
.u
.cache64
.DeviceNo
= gen
.command
.u
.cache
.DeviceNo
;
4174 if (ha
->cache_feat
& SCATTER_GATHER
) {
4175 gen
.command
.u
.cache64
.DestAddr
= (ulong64
)-1;
4176 gen
.command
.u
.cache64
.sg_canz
= 1;
4177 gen
.command
.u
.cache64
.sg_lst
[0].sg_ptr
= paddr
;
4178 gen
.command
.u
.cache64
.sg_lst
[0].sg_len
= gen
.data_len
;
4179 gen
.command
.u
.cache64
.sg_lst
[1].sg_len
= 0;
4181 gen
.command
.u
.cache64
.DestAddr
= paddr
;
4182 gen
.command
.u
.cache64
.sg_canz
= 0;
4185 if (ha
->cache_feat
& SCATTER_GATHER
) {
4186 gen
.command
.u
.cache
.DestAddr
= 0xffffffff;
4187 gen
.command
.u
.cache
.sg_canz
= 1;
4188 gen
.command
.u
.cache
.sg_lst
[0].sg_ptr
= (ulong32
)paddr
;
4189 gen
.command
.u
.cache
.sg_lst
[0].sg_len
= gen
.data_len
;
4190 gen
.command
.u
.cache
.sg_lst
[1].sg_len
= 0;
4192 gen
.command
.u
.cache
.DestAddr
= paddr
;
4193 gen
.command
.u
.cache
.sg_canz
= 0;
4196 } else if (gen
.command
.Service
== SCSIRAWSERVICE
) {
4197 if (ha
->raw_feat
& GDT_64BIT
) {
4198 /* copy elements from 32-bit IOCTL structure */
4200 gen
.command
.u
.raw64
.sense_len
= gen
.command
.u
.raw
.sense_len
;
4201 gen
.command
.u
.raw64
.bus
= gen
.command
.u
.raw
.bus
;
4202 gen
.command
.u
.raw64
.lun
= gen
.command
.u
.raw
.lun
;
4203 gen
.command
.u
.raw64
.target
= gen
.command
.u
.raw
.target
;
4204 memcpy(cmd
, gen
.command
.u
.raw
.cmd
, 16);
4205 memcpy(gen
.command
.u
.raw64
.cmd
, cmd
, 16);
4206 gen
.command
.u
.raw64
.clen
= gen
.command
.u
.raw
.clen
;
4207 gen
.command
.u
.raw64
.sdlen
= gen
.command
.u
.raw
.sdlen
;
4208 gen
.command
.u
.raw64
.direction
= gen
.command
.u
.raw
.direction
;
4210 if (ha
->raw_feat
& SCATTER_GATHER
) {
4211 gen
.command
.u
.raw64
.sdata
= (ulong64
)-1;
4212 gen
.command
.u
.raw64
.sg_ranz
= 1;
4213 gen
.command
.u
.raw64
.sg_lst
[0].sg_ptr
= paddr
;
4214 gen
.command
.u
.raw64
.sg_lst
[0].sg_len
= gen
.data_len
;
4215 gen
.command
.u
.raw64
.sg_lst
[1].sg_len
= 0;
4217 gen
.command
.u
.raw64
.sdata
= paddr
;
4218 gen
.command
.u
.raw64
.sg_ranz
= 0;
4220 gen
.command
.u
.raw64
.sense_data
= paddr
+ gen
.data_len
;
4222 if (ha
->raw_feat
& SCATTER_GATHER
) {
4223 gen
.command
.u
.raw
.sdata
= 0xffffffff;
4224 gen
.command
.u
.raw
.sg_ranz
= 1;
4225 gen
.command
.u
.raw
.sg_lst
[0].sg_ptr
= (ulong32
)paddr
;
4226 gen
.command
.u
.raw
.sg_lst
[0].sg_len
= gen
.data_len
;
4227 gen
.command
.u
.raw
.sg_lst
[1].sg_len
= 0;
4229 gen
.command
.u
.raw
.sdata
= paddr
;
4230 gen
.command
.u
.raw
.sg_ranz
= 0;
4232 gen
.command
.u
.raw
.sense_data
= (ulong32
)paddr
+ gen
.data_len
;
4235 gdth_ioctl_free(ha
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
4240 rval
= __gdth_execute(ha
->sdev
, &gen
.command
, cmnd
, gen
.timeout
, &gen
.info
);
4245 if (copy_to_user(arg
+ sizeof(gdth_ioctl_general
), buf
,
4246 gen
.data_len
+ gen
.sense_len
)) {
4247 gdth_ioctl_free(ha
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
4250 if (copy_to_user(arg
, &gen
,
4251 sizeof(gdth_ioctl_general
) - sizeof(gdth_cmd_str
))) {
4252 gdth_ioctl_free(ha
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
4255 gdth_ioctl_free(ha
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
4259 static int ioc_hdrlist(void __user
*arg
, char *cmnd
)
4261 gdth_ioctl_rescan
*rsc
;
4266 u32 cluster_type
= 0;
4268 rsc
= kmalloc(sizeof(*rsc
), GFP_KERNEL
);
4269 cmd
= kmalloc(sizeof(*cmd
), GFP_KERNEL
);
4273 if (copy_from_user(rsc
, arg
, sizeof(gdth_ioctl_rescan
)) ||
4274 (NULL
== (ha
= gdth_find_ha(rsc
->ionode
)))) {
4278 memset(cmd
, 0, sizeof(gdth_cmd_str
));
4280 for (i
= 0; i
< MAX_HDRIVES
; ++i
) {
4281 if (!ha
->hdr
[i
].present
) {
4282 rsc
->hdr_list
[i
].bus
= 0xff;
4285 rsc
->hdr_list
[i
].bus
= ha
->virt_bus
;
4286 rsc
->hdr_list
[i
].target
= i
;
4287 rsc
->hdr_list
[i
].lun
= 0;
4288 rsc
->hdr_list
[i
].cluster_type
= ha
->hdr
[i
].cluster_type
;
4289 if (ha
->hdr
[i
].cluster_type
& CLUSTER_DRIVE
) {
4290 cmd
->Service
= CACHESERVICE
;
4291 cmd
->OpCode
= GDT_CLUST_INFO
;
4292 if (ha
->cache_feat
& GDT_64BIT
)
4293 cmd
->u
.cache64
.DeviceNo
= i
;
4295 cmd
->u
.cache
.DeviceNo
= i
;
4296 if (__gdth_execute(ha
->sdev
, cmd
, cmnd
, 30, &cluster_type
) == S_OK
)
4297 rsc
->hdr_list
[i
].cluster_type
= cluster_type
;
4301 if (copy_to_user(arg
, rsc
, sizeof(gdth_ioctl_rescan
)))
4312 static int ioc_rescan(void __user
*arg
, char *cmnd
)
4314 gdth_ioctl_rescan
*rsc
;
4316 ushort i
, status
, hdr_cnt
;
4318 int cyls
, hds
, secs
;
4323 rsc
= kmalloc(sizeof(*rsc
), GFP_KERNEL
);
4324 cmd
= kmalloc(sizeof(*cmd
), GFP_KERNEL
);
4328 if (copy_from_user(rsc
, arg
, sizeof(gdth_ioctl_rescan
)) ||
4329 (NULL
== (ha
= gdth_find_ha(rsc
->ionode
)))) {
4333 memset(cmd
, 0, sizeof(gdth_cmd_str
));
4335 if (rsc
->flag
== 0) {
4336 /* old method: re-init. cache service */
4337 cmd
->Service
= CACHESERVICE
;
4338 if (ha
->cache_feat
& GDT_64BIT
) {
4339 cmd
->OpCode
= GDT_X_INIT_HOST
;
4340 cmd
->u
.cache64
.DeviceNo
= LINUX_OS
;
4342 cmd
->OpCode
= GDT_INIT
;
4343 cmd
->u
.cache
.DeviceNo
= LINUX_OS
;
4346 status
= __gdth_execute(ha
->sdev
, cmd
, cmnd
, 30, &info
);
4348 hdr_cnt
= (status
== S_OK
? (ushort
)info
: 0);
4354 for (; i
< hdr_cnt
&& i
< MAX_HDRIVES
; ++i
) {
4355 cmd
->Service
= CACHESERVICE
;
4356 cmd
->OpCode
= GDT_INFO
;
4357 if (ha
->cache_feat
& GDT_64BIT
)
4358 cmd
->u
.cache64
.DeviceNo
= i
;
4360 cmd
->u
.cache
.DeviceNo
= i
;
4362 status
= __gdth_execute(ha
->sdev
, cmd
, cmnd
, 30, &info
);
4364 spin_lock_irqsave(&ha
->smp_lock
, flags
);
4365 rsc
->hdr_list
[i
].bus
= ha
->virt_bus
;
4366 rsc
->hdr_list
[i
].target
= i
;
4367 rsc
->hdr_list
[i
].lun
= 0;
4368 if (status
!= S_OK
) {
4369 ha
->hdr
[i
].present
= FALSE
;
4371 ha
->hdr
[i
].present
= TRUE
;
4372 ha
->hdr
[i
].size
= info
;
4373 /* evaluate mapping */
4374 ha
->hdr
[i
].size
&= ~SECS32
;
4375 gdth_eval_mapping(ha
->hdr
[i
].size
,&cyls
,&hds
,&secs
);
4376 ha
->hdr
[i
].heads
= hds
;
4377 ha
->hdr
[i
].secs
= secs
;
4379 ha
->hdr
[i
].size
= cyls
* hds
* secs
;
4381 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
4385 /* extended info, if GDT_64BIT, for drives > 2 TB */
4386 /* but we need ha->info2, not yet stored in scp->SCp */
4388 /* devtype, cluster info, R/W attribs */
4389 cmd
->Service
= CACHESERVICE
;
4390 cmd
->OpCode
= GDT_DEVTYPE
;
4391 if (ha
->cache_feat
& GDT_64BIT
)
4392 cmd
->u
.cache64
.DeviceNo
= i
;
4394 cmd
->u
.cache
.DeviceNo
= i
;
4396 status
= __gdth_execute(ha
->sdev
, cmd
, cmnd
, 30, &info
);
4398 spin_lock_irqsave(&ha
->smp_lock
, flags
);
4399 ha
->hdr
[i
].devtype
= (status
== S_OK
? (ushort
)info
: 0);
4400 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
4402 cmd
->Service
= CACHESERVICE
;
4403 cmd
->OpCode
= GDT_CLUST_INFO
;
4404 if (ha
->cache_feat
& GDT_64BIT
)
4405 cmd
->u
.cache64
.DeviceNo
= i
;
4407 cmd
->u
.cache
.DeviceNo
= i
;
4409 status
= __gdth_execute(ha
->sdev
, cmd
, cmnd
, 30, &info
);
4411 spin_lock_irqsave(&ha
->smp_lock
, flags
);
4412 ha
->hdr
[i
].cluster_type
=
4413 ((status
== S_OK
&& !shared_access
) ? (ushort
)info
: 0);
4414 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
4415 rsc
->hdr_list
[i
].cluster_type
= ha
->hdr
[i
].cluster_type
;
4417 cmd
->Service
= CACHESERVICE
;
4418 cmd
->OpCode
= GDT_RW_ATTRIBS
;
4419 if (ha
->cache_feat
& GDT_64BIT
)
4420 cmd
->u
.cache64
.DeviceNo
= i
;
4422 cmd
->u
.cache
.DeviceNo
= i
;
4424 status
= __gdth_execute(ha
->sdev
, cmd
, cmnd
, 30, &info
);
4426 spin_lock_irqsave(&ha
->smp_lock
, flags
);
4427 ha
->hdr
[i
].rw_attribs
= (status
== S_OK
? (ushort
)info
: 0);
4428 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
4431 if (copy_to_user(arg
, rsc
, sizeof(gdth_ioctl_rescan
)))
4442 static int gdth_ioctl(struct inode
*inode
, struct file
*filep
,
4443 unsigned int cmd
, unsigned long arg
)
4448 char cmnd
[MAX_COMMAND_SIZE
];
4449 void __user
*argp
= (void __user
*)arg
;
4451 memset(cmnd
, 0xff, 12);
4453 TRACE(("gdth_ioctl() cmd 0x%x\n", cmd
));
4456 case GDTIOCTL_CTRCNT
:
4458 int cnt
= gdth_ctr_count
;
4459 if (put_user(cnt
, (int __user
*)argp
))
4464 case GDTIOCTL_DRVERS
:
4466 int ver
= (GDTH_VERSION
<<8) | GDTH_SUBVERSION
;
4467 if (put_user(ver
, (int __user
*)argp
))
4472 case GDTIOCTL_OSVERS
:
4474 gdth_ioctl_osvers osv
;
4476 osv
.version
= (unchar
)(LINUX_VERSION_CODE
>> 16);
4477 osv
.subversion
= (unchar
)(LINUX_VERSION_CODE
>> 8);
4478 osv
.revision
= (ushort
)(LINUX_VERSION_CODE
& 0xff);
4479 if (copy_to_user(argp
, &osv
, sizeof(gdth_ioctl_osvers
)))
4484 case GDTIOCTL_CTRTYPE
:
4486 gdth_ioctl_ctrtype ctrt
;
4488 if (copy_from_user(&ctrt
, argp
, sizeof(gdth_ioctl_ctrtype
)) ||
4489 (NULL
== (ha
= gdth_find_ha(ctrt
.ionode
))))
4492 if (ha
->type
== GDT_ISA
|| ha
->type
== GDT_EISA
) {
4493 ctrt
.type
= (unchar
)((ha
->stype
>>20) - 0x10);
4495 if (ha
->type
!= GDT_PCIMPR
) {
4496 ctrt
.type
= (unchar
)((ha
->stype
<<4) + 6);
4499 (ha
->oem_id
== OEM_ID_INTEL
? 0xfd : 0xfe);
4500 if (ha
->stype
>= 0x300)
4501 ctrt
.ext_type
= 0x6000 | ha
->pdev
->subsystem_device
;
4503 ctrt
.ext_type
= 0x6000 | ha
->stype
;
4505 ctrt
.device_id
= ha
->pdev
->device
;
4506 ctrt
.sub_device_id
= ha
->pdev
->subsystem_device
;
4508 ctrt
.info
= ha
->brd_phys
;
4509 ctrt
.oem_id
= ha
->oem_id
;
4510 if (copy_to_user(argp
, &ctrt
, sizeof(gdth_ioctl_ctrtype
)))
4515 case GDTIOCTL_GENERAL
:
4516 return ioc_general(argp
, cmnd
);
4518 case GDTIOCTL_EVENT
:
4519 return ioc_event(argp
);
4521 case GDTIOCTL_LOCKDRV
:
4522 return ioc_lockdrv(argp
);
4524 case GDTIOCTL_LOCKCHN
:
4526 gdth_ioctl_lockchn lchn
;
4529 if (copy_from_user(&lchn
, argp
, sizeof(gdth_ioctl_lockchn
)) ||
4530 (NULL
== (ha
= gdth_find_ha(lchn
.ionode
))))
4534 if (i
< ha
->bus_cnt
) {
4536 spin_lock_irqsave(&ha
->smp_lock
, flags
);
4537 ha
->raw
[i
].lock
= 1;
4538 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
4539 for (j
= 0; j
< ha
->tid_cnt
; ++j
) {
4540 gdth_wait_completion(ha
, i
, j
);
4541 gdth_stop_timeout(ha
, i
, j
);
4544 spin_lock_irqsave(&ha
->smp_lock
, flags
);
4545 ha
->raw
[i
].lock
= 0;
4546 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
4547 for (j
= 0; j
< ha
->tid_cnt
; ++j
) {
4548 gdth_start_timeout(ha
, i
, j
);
4556 case GDTIOCTL_RESCAN
:
4557 return ioc_rescan(argp
, cmnd
);
4559 case GDTIOCTL_HDRLIST
:
4560 return ioc_hdrlist(argp
, cmnd
);
4562 case GDTIOCTL_RESET_BUS
:
4564 gdth_ioctl_reset res
;
4567 if (copy_from_user(&res
, argp
, sizeof(gdth_ioctl_reset
)) ||
4568 (NULL
== (ha
= gdth_find_ha(res
.ionode
))))
4571 scp
= kzalloc(sizeof(*scp
), GFP_KERNEL
);
4574 scp
->device
= ha
->sdev
;
4576 scp
->device
->channel
= res
.number
;
4577 rval
= gdth_eh_bus_reset(scp
);
4578 res
.status
= (rval
== SUCCESS
? S_OK
: S_GENERR
);
4581 if (copy_to_user(argp
, &res
, sizeof(gdth_ioctl_reset
)))
4586 case GDTIOCTL_RESET_DRV
:
4587 return ioc_resetdrv(argp
, cmnd
);
4597 static void gdth_flush(gdth_ha_str
*ha
)
4600 gdth_cmd_str gdtcmd
;
4601 char cmnd
[MAX_COMMAND_SIZE
];
4602 memset(cmnd
, 0xff, MAX_COMMAND_SIZE
);
4604 TRACE2(("gdth_flush() hanum %d\n", ha
->hanum
));
4606 for (i
= 0; i
< MAX_HDRIVES
; ++i
) {
4607 if (ha
->hdr
[i
].present
) {
4608 gdtcmd
.BoardNode
= LOCALBOARD
;
4609 gdtcmd
.Service
= CACHESERVICE
;
4610 gdtcmd
.OpCode
= GDT_FLUSH
;
4611 if (ha
->cache_feat
& GDT_64BIT
) {
4612 gdtcmd
.u
.cache64
.DeviceNo
= i
;
4613 gdtcmd
.u
.cache64
.BlockNo
= 1;
4614 gdtcmd
.u
.cache64
.sg_canz
= 0;
4616 gdtcmd
.u
.cache
.DeviceNo
= i
;
4617 gdtcmd
.u
.cache
.BlockNo
= 1;
4618 gdtcmd
.u
.cache
.sg_canz
= 0;
4620 TRACE2(("gdth_flush(): flush ha %d drive %d\n", ha
->hanum
, i
));
4622 gdth_execute(ha
->shost
, &gdtcmd
, cmnd
, 30, NULL
);
4628 static int gdth_slave_configure(struct scsi_device
*sdev
)
4630 scsi_adjust_queue_depth(sdev
, 0, sdev
->host
->cmd_per_lun
);
4631 sdev
->skip_ms_page_3f
= 1;
4632 sdev
->skip_ms_page_8
= 1;
4636 static struct scsi_host_template gdth_template
= {
4637 .name
= "GDT SCSI Disk Array Controller",
4639 .queuecommand
= gdth_queuecommand
,
4640 .eh_bus_reset_handler
= gdth_eh_bus_reset
,
4641 .slave_configure
= gdth_slave_configure
,
4642 .bios_param
= gdth_bios_param
,
4643 .proc_info
= gdth_proc_info
,
4644 .proc_name
= "gdth",
4645 .can_queue
= GDTH_MAXCMDS
,
4647 .sg_tablesize
= GDTH_MAXSG
,
4648 .cmd_per_lun
= GDTH_MAXC_P_L
,
4649 .unchecked_isa_dma
= 1,
4650 .use_clustering
= ENABLE_CLUSTERING
,
4654 static int __init
gdth_isa_probe_one(ulong32 isa_bios
)
4656 struct Scsi_Host
*shp
;
4658 dma_addr_t scratch_dma_handle
= 0;
4661 if (!gdth_search_isa(isa_bios
))
4664 shp
= scsi_host_alloc(&gdth_template
, sizeof(gdth_ha_str
));
4667 ha
= shost_priv(shp
);
4670 if (!gdth_init_isa(isa_bios
,ha
))
4673 /* controller found and initialized */
4674 printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
4675 isa_bios
, ha
->irq
, ha
->drq
);
4677 error
= request_irq(ha
->irq
, gdth_interrupt
, IRQF_DISABLED
, "gdth", ha
);
4679 printk("GDT-ISA: Unable to allocate IRQ\n");
4683 error
= request_dma(ha
->drq
, "gdth");
4685 printk("GDT-ISA: Unable to allocate DMA channel\n");
4689 set_dma_mode(ha
->drq
,DMA_MODE_CASCADE
);
4690 enable_dma(ha
->drq
);
4691 shp
->unchecked_isa_dma
= 1;
4693 shp
->dma_channel
= ha
->drq
;
4695 ha
->hanum
= gdth_ctr_count
++;
4698 ha
->pccb
= &ha
->cmdext
;
4704 ha
->pscratch
= pci_alloc_consistent(ha
->pdev
, GDTH_SCRATCH
,
4705 &scratch_dma_handle
);
4707 goto out_dec_counters
;
4708 ha
->scratch_phys
= scratch_dma_handle
;
4710 ha
->pmsg
= pci_alloc_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4711 &scratch_dma_handle
);
4713 goto out_free_pscratch
;
4714 ha
->msg_phys
= scratch_dma_handle
;
4717 ha
->coal_stat
= pci_alloc_consistent(ha
->pdev
,
4718 sizeof(gdth_coal_status
) * MAXOFFSETS
,
4719 &scratch_dma_handle
);
4722 ha
->coal_stat_phys
= scratch_dma_handle
;
4725 ha
->scratch_busy
= FALSE
;
4726 ha
->req_first
= NULL
;
4727 ha
->tid_cnt
= MAX_HDRIVES
;
4728 if (max_ids
> 0 && max_ids
< ha
->tid_cnt
)
4729 ha
->tid_cnt
= max_ids
;
4730 for (i
= 0; i
< GDTH_MAXCMDS
; ++i
)
4731 ha
->cmd_tab
[i
].cmnd
= UNUSED_CMND
;
4732 ha
->scan_mode
= rescan
? 0x10 : 0;
4735 if (!gdth_search_drives(ha
)) {
4736 printk("GDT-ISA: Error during device scan\n");
4737 goto out_free_coal_stat
;
4740 if (hdr_channel
< 0 || hdr_channel
> ha
->bus_cnt
)
4741 hdr_channel
= ha
->bus_cnt
;
4742 ha
->virt_bus
= hdr_channel
;
4744 if (ha
->cache_feat
& ha
->raw_feat
& ha
->screen_feat
& GDT_64BIT
)
4745 shp
->max_cmd_len
= 16;
4747 shp
->max_id
= ha
->tid_cnt
;
4748 shp
->max_lun
= MAXLUN
;
4749 shp
->max_channel
= ha
->bus_cnt
;
4751 spin_lock_init(&ha
->smp_lock
);
4752 gdth_enable_int(ha
);
4754 error
= scsi_add_host(shp
, NULL
);
4756 goto out_free_coal_stat
;
4757 list_add_tail(&ha
->list
, &gdth_instances
);
4760 scsi_scan_host(shp
);
4766 pci_free_consistent(ha
->pdev
, sizeof(gdth_coal_status
) * MAXOFFSETS
,
4767 ha
->coal_stat
, ha
->coal_stat_phys
);
4770 pci_free_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4771 ha
->pmsg
, ha
->msg_phys
);
4773 pci_free_consistent(ha
->pdev
, GDTH_SCRATCH
,
4774 ha
->pscratch
, ha
->scratch_phys
);
4778 free_irq(ha
->irq
, ha
);
4783 #endif /* CONFIG_ISA */
4786 static int __init
gdth_eisa_probe_one(ushort eisa_slot
)
4788 struct Scsi_Host
*shp
;
4790 dma_addr_t scratch_dma_handle
= 0;
4793 if (!gdth_search_eisa(eisa_slot
))
4796 shp
= scsi_host_alloc(&gdth_template
, sizeof(gdth_ha_str
));
4799 ha
= shost_priv(shp
);
4802 if (!gdth_init_eisa(eisa_slot
,ha
))
4805 /* controller found and initialized */
4806 printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
4807 eisa_slot
>> 12, ha
->irq
);
4809 error
= request_irq(ha
->irq
, gdth_interrupt
, IRQF_DISABLED
, "gdth", ha
);
4811 printk("GDT-EISA: Unable to allocate IRQ\n");
4815 shp
->unchecked_isa_dma
= 0;
4817 shp
->dma_channel
= 0xff;
4819 ha
->hanum
= gdth_ctr_count
++;
4822 TRACE2(("EISA detect Bus 0: hanum %d\n", ha
->hanum
));
4824 ha
->pccb
= &ha
->cmdext
;
4830 ha
->pscratch
= pci_alloc_consistent(ha
->pdev
, GDTH_SCRATCH
,
4831 &scratch_dma_handle
);
4834 ha
->scratch_phys
= scratch_dma_handle
;
4836 ha
->pmsg
= pci_alloc_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4837 &scratch_dma_handle
);
4839 goto out_free_pscratch
;
4840 ha
->msg_phys
= scratch_dma_handle
;
4843 ha
->coal_stat
= pci_alloc_consistent(ha
->pdev
,
4844 sizeof(gdth_coal_status
) * MAXOFFSETS
,
4845 &scratch_dma_handle
);
4848 ha
->coal_stat_phys
= scratch_dma_handle
;
4851 ha
->ccb_phys
= pci_map_single(ha
->pdev
,ha
->pccb
,
4852 sizeof(gdth_cmd_str
), PCI_DMA_BIDIRECTIONAL
);
4854 goto out_free_coal_stat
;
4856 ha
->scratch_busy
= FALSE
;
4857 ha
->req_first
= NULL
;
4858 ha
->tid_cnt
= MAX_HDRIVES
;
4859 if (max_ids
> 0 && max_ids
< ha
->tid_cnt
)
4860 ha
->tid_cnt
= max_ids
;
4861 for (i
= 0; i
< GDTH_MAXCMDS
; ++i
)
4862 ha
->cmd_tab
[i
].cmnd
= UNUSED_CMND
;
4863 ha
->scan_mode
= rescan
? 0x10 : 0;
4865 if (!gdth_search_drives(ha
)) {
4866 printk("GDT-EISA: Error during device scan\n");
4868 goto out_free_ccb_phys
;
4871 if (hdr_channel
< 0 || hdr_channel
> ha
->bus_cnt
)
4872 hdr_channel
= ha
->bus_cnt
;
4873 ha
->virt_bus
= hdr_channel
;
4875 if (ha
->cache_feat
& ha
->raw_feat
& ha
->screen_feat
& GDT_64BIT
)
4876 shp
->max_cmd_len
= 16;
4878 shp
->max_id
= ha
->tid_cnt
;
4879 shp
->max_lun
= MAXLUN
;
4880 shp
->max_channel
= ha
->bus_cnt
;
4882 spin_lock_init(&ha
->smp_lock
);
4883 gdth_enable_int(ha
);
4885 error
= scsi_add_host(shp
, NULL
);
4887 goto out_free_coal_stat
;
4888 list_add_tail(&ha
->list
, &gdth_instances
);
4891 scsi_scan_host(shp
);
4896 pci_unmap_single(ha
->pdev
,ha
->ccb_phys
, sizeof(gdth_cmd_str
),
4897 PCI_DMA_BIDIRECTIONAL
);
4900 pci_free_consistent(ha
->pdev
, sizeof(gdth_coal_status
) * MAXOFFSETS
,
4901 ha
->coal_stat
, ha
->coal_stat_phys
);
4904 pci_free_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4905 ha
->pmsg
, ha
->msg_phys
);
4907 pci_free_consistent(ha
->pdev
, GDTH_SCRATCH
,
4908 ha
->pscratch
, ha
->scratch_phys
);
4910 free_irq(ha
->irq
, ha
);
4916 #endif /* CONFIG_EISA */
4919 static int gdth_pci_probe_one(gdth_pci_str
*pcistr
,
4920 gdth_ha_str
**ha_out
)
4922 struct Scsi_Host
*shp
;
4924 dma_addr_t scratch_dma_handle
= 0;
4926 struct pci_dev
*pdev
= pcistr
->pdev
;
4930 shp
= scsi_host_alloc(&gdth_template
, sizeof(gdth_ha_str
));
4933 ha
= shost_priv(shp
);
4936 if (!gdth_init_pci(pdev
, pcistr
, ha
))
4939 /* controller found and initialized */
4940 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
4942 PCI_SLOT(pdev
->devfn
),
4945 error
= request_irq(ha
->irq
, gdth_interrupt
,
4946 IRQF_DISABLED
|IRQF_SHARED
, "gdth", ha
);
4948 printk("GDT-PCI: Unable to allocate IRQ\n");
4952 shp
->unchecked_isa_dma
= 0;
4954 shp
->dma_channel
= 0xff;
4956 ha
->hanum
= gdth_ctr_count
++;
4959 ha
->pccb
= &ha
->cmdext
;
4964 ha
->pscratch
= pci_alloc_consistent(ha
->pdev
, GDTH_SCRATCH
,
4965 &scratch_dma_handle
);
4968 ha
->scratch_phys
= scratch_dma_handle
;
4970 ha
->pmsg
= pci_alloc_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4971 &scratch_dma_handle
);
4973 goto out_free_pscratch
;
4974 ha
->msg_phys
= scratch_dma_handle
;
4977 ha
->coal_stat
= pci_alloc_consistent(ha
->pdev
,
4978 sizeof(gdth_coal_status
) * MAXOFFSETS
,
4979 &scratch_dma_handle
);
4982 ha
->coal_stat_phys
= scratch_dma_handle
;
4985 ha
->scratch_busy
= FALSE
;
4986 ha
->req_first
= NULL
;
4987 ha
->tid_cnt
= pdev
->device
>= 0x200 ? MAXID
: MAX_HDRIVES
;
4988 if (max_ids
> 0 && max_ids
< ha
->tid_cnt
)
4989 ha
->tid_cnt
= max_ids
;
4990 for (i
= 0; i
< GDTH_MAXCMDS
; ++i
)
4991 ha
->cmd_tab
[i
].cmnd
= UNUSED_CMND
;
4992 ha
->scan_mode
= rescan
? 0x10 : 0;
4995 if (!gdth_search_drives(ha
)) {
4996 printk("GDT-PCI %d: Error during device scan\n", ha
->hanum
);
4997 goto out_free_coal_stat
;
5000 if (hdr_channel
< 0 || hdr_channel
> ha
->bus_cnt
)
5001 hdr_channel
= ha
->bus_cnt
;
5002 ha
->virt_bus
= hdr_channel
;
5004 /* 64-bit DMA only supported from FW >= x.43 */
5005 if (!(ha
->cache_feat
& ha
->raw_feat
& ha
->screen_feat
& GDT_64BIT
) ||
5006 !ha
->dma64_support
) {
5007 if (pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) {
5008 printk(KERN_WARNING
"GDT-PCI %d: "
5009 "Unable to set 32-bit DMA\n", ha
->hanum
);
5010 goto out_free_coal_stat
;
5013 shp
->max_cmd_len
= 16;
5014 if (!pci_set_dma_mask(pdev
, DMA_64BIT_MASK
)) {
5015 printk("GDT-PCI %d: 64-bit DMA enabled\n", ha
->hanum
);
5016 } else if (pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) {
5017 printk(KERN_WARNING
"GDT-PCI %d: "
5018 "Unable to set 64/32-bit DMA\n", ha
->hanum
);
5019 goto out_free_coal_stat
;
5023 shp
->max_id
= ha
->tid_cnt
;
5024 shp
->max_lun
= MAXLUN
;
5025 shp
->max_channel
= ha
->bus_cnt
;
5027 spin_lock_init(&ha
->smp_lock
);
5028 gdth_enable_int(ha
);
5030 error
= scsi_add_host(shp
, &pdev
->dev
);
5032 goto out_free_coal_stat
;
5033 list_add_tail(&ha
->list
, &gdth_instances
);
5035 pci_set_drvdata(ha
->pdev
, ha
);
5038 scsi_scan_host(shp
);
5046 pci_free_consistent(ha
->pdev
, sizeof(gdth_coal_status
) * MAXOFFSETS
,
5047 ha
->coal_stat
, ha
->coal_stat_phys
);
5050 pci_free_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
5051 ha
->pmsg
, ha
->msg_phys
);
5053 pci_free_consistent(ha
->pdev
, GDTH_SCRATCH
,
5054 ha
->pscratch
, ha
->scratch_phys
);
5056 free_irq(ha
->irq
, ha
);
5062 #endif /* CONFIG_PCI */
5064 static void gdth_remove_one(gdth_ha_str
*ha
)
5066 struct Scsi_Host
*shp
= ha
->shost
;
5068 TRACE2(("gdth_remove_one()\n"));
5070 scsi_remove_host(shp
);
5075 scsi_free_host_dev(ha
->sdev
);
5080 free_irq(shp
->irq
,ha
);
5083 if (shp
->dma_channel
!= 0xff)
5084 free_dma(shp
->dma_channel
);
5088 pci_free_consistent(ha
->pdev
, sizeof(gdth_coal_status
) *
5089 MAXOFFSETS
, ha
->coal_stat
, ha
->coal_stat_phys
);
5092 pci_free_consistent(ha
->pdev
, GDTH_SCRATCH
,
5093 ha
->pscratch
, ha
->scratch_phys
);
5095 pci_free_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
5096 ha
->pmsg
, ha
->msg_phys
);
5098 pci_unmap_single(ha
->pdev
,ha
->ccb_phys
,
5099 sizeof(gdth_cmd_str
),PCI_DMA_BIDIRECTIONAL
);
5104 static int gdth_halt(struct notifier_block
*nb
, ulong event
, void *buf
)
5108 TRACE2(("gdth_halt() event %d\n", (int)event
));
5109 if (event
!= SYS_RESTART
&& event
!= SYS_HALT
&& event
!= SYS_POWER_OFF
)
5112 list_for_each_entry(ha
, &gdth_instances
, list
)
5118 static struct notifier_block gdth_notifier
= {
5122 static int __init
gdth_init(void)
5125 printk("GDT-HA: Controller driver disabled from"
5126 " command line !\n");
5130 printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n",
5133 /* initializations */
5134 gdth_polling
= TRUE
;
5135 gdth_clear_events();
5136 init_timer(&gdth_timer
);
5138 /* As default we do not probe for EISA or ISA controllers */
5139 if (probe_eisa_isa
) {
5140 /* scanning for controllers, at first: ISA controller */
5143 for (isa_bios
= 0xc8000UL
; isa_bios
<= 0xd8000UL
;
5144 isa_bios
+= 0x8000UL
)
5145 gdth_isa_probe_one(isa_bios
);
5150 for (eisa_slot
= 0x1000; eisa_slot
<= 0x8000;
5151 eisa_slot
+= 0x1000)
5152 gdth_eisa_probe_one(eisa_slot
);
5158 /* scanning for PCI controllers */
5159 if (pci_register_driver(&gdth_pci_driver
)) {
5162 list_for_each_entry(ha
, &gdth_instances
, list
)
5163 gdth_remove_one(ha
);
5166 #endif /* CONFIG_PCI */
5168 TRACE2(("gdth_detect() %d controller detected\n", gdth_ctr_count
));
5170 major
= register_chrdev(0,"gdth", &gdth_fops
);
5171 register_reboot_notifier(&gdth_notifier
);
5172 gdth_polling
= FALSE
;
5176 static void __exit
gdth_exit(void)
5180 unregister_chrdev(major
, "gdth");
5181 unregister_reboot_notifier(&gdth_notifier
);
5183 #ifdef GDTH_STATISTICS
5184 del_timer_sync(&gdth_timer
);
5188 pci_unregister_driver(&gdth_pci_driver
);
5191 list_for_each_entry(ha
, &gdth_instances
, list
)
5192 gdth_remove_one(ha
);
5195 module_init(gdth_init
);
5196 module_exit(gdth_exit
);
5199 __setup("gdth=", option_setup
);