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: gdth_bufflen
91 * buffers_residual: gdth_sg_count
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,
376 * gdth scsi_command access wrappers.
377 * below 6 functions are used throughout the driver to access scsi_command's
378 * io parameters. The reason we do not use the regular accessors from
379 * scsi_cmnd.h is because of gdth_execute(). Since it is unrecommended for
380 * llds to directly set scsi_cmnd's IO members. This driver will use SCp
381 * members for IO parameters, and will copy scsi_cmnd's members to Scp
382 * members in queuecommand. For internal commands through gdth_execute()
383 * SCp's members will be set directly.
385 static inline unsigned gdth_bufflen(struct scsi_cmnd *cmd)
387 return (unsigned)cmd->SCp.this_residual;
390 static inline void gdth_set_bufflen(struct scsi_cmnd *cmd, unsigned bufflen)
392 cmd->SCp.this_residual = bufflen;
395 static inline unsigned gdth_sg_count(struct scsi_cmnd *cmd)
397 return (unsigned)cmd->SCp.buffers_residual;
400 static inline void gdth_set_sg_count(struct scsi_cmnd *cmd, unsigned sg_count)
402 cmd->SCp.buffers_residual = sg_count;
405 static inline struct scatterlist *gdth_sglist(struct scsi_cmnd *cmd)
407 return cmd->SCp.buffer;
410 static inline void gdth_set_sglist(struct scsi_cmnd *cmd,
411 struct scatterlist *sglist)
413 cmd->SCp.buffer = sglist;
416 #include "gdth_proc.h"
417 #include "gdth_proc.c"
419 static gdth_ha_str *gdth_find_ha(int hanum)
423 list_for_each_entry(ha, &gdth_instances, list)
424 if (hanum == ha->hanum)
430 static struct gdth_cmndinfo *gdth_get_cmndinfo(gdth_ha_str *ha)
432 struct gdth_cmndinfo *priv = NULL;
436 spin_lock_irqsave(&ha->smp_lock, flags);
438 for (i=0; i<GDTH_MAXCMDS; ++i) {
439 if (ha->cmndinfo[i].index == 0) {
440 priv = &ha->cmndinfo[i];
441 memset(priv, 0, sizeof(*priv));
447 spin_unlock_irqrestore(&ha->smp_lock, flags);
452 static void gdth_put_cmndinfo(struct gdth_cmndinfo *priv)
458 static void gdth_delay(int milliseconds)
460 if (milliseconds == 0) {
463 mdelay(milliseconds);
467 static void gdth_scsi_done(struct scsi_cmnd *scp)
469 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
470 int internal_command = cmndinfo->internal_command;
472 TRACE2(("gdth_scsi_done()\n"));
474 gdth_put_cmndinfo(cmndinfo);
475 scp->host_scribble = NULL;
477 if (internal_command)
478 complete((struct completion *)scp->request);
483 int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
484 int timeout, u32 *info)
486 gdth_ha_str *ha = shost_priv(sdev->host);
488 struct gdth_cmndinfo cmndinfo;
489 DECLARE_COMPLETION_ONSTACK(wait);
492 scp = kzalloc(sizeof(*scp), GFP_KERNEL);
496 scp->sense_buffer = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
497 if (!scp->sense_buffer) {
503 memset(&cmndinfo, 0, sizeof(cmndinfo));
505 /* use request field to save the ptr. to completion struct. */
506 scp->request = (struct request *)&wait;
507 scp->timeout_per_command = timeout*HZ;
509 memcpy(scp->cmnd, cmnd, 12);
510 cmndinfo.priority = IOCTL_PRI;
511 cmndinfo.internal_cmd_str = gdtcmd;
512 cmndinfo.internal_command = 1;
514 TRACE(("__gdth_execute() cmd 0x%x\n", scp->cmnd[0]));
515 __gdth_queuecommand(ha, scp, &cmndinfo);
517 wait_for_completion(&wait);
519 rval = cmndinfo.status;
521 *info = cmndinfo.info;
522 kfree(scp->sense_buffer);
527 int gdth_execute(struct Scsi_Host *shost, gdth_cmd_str *gdtcmd, char *cmnd,
528 int timeout, u32 *info)
530 struct scsi_device *sdev = scsi_get_host_dev(shost);
531 int rval = __gdth_execute(sdev, gdtcmd, cmnd, timeout, info);
533 scsi_free_host_dev(sdev);
537 static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs)
539 *cyls = size /HEADS/SECS;
540 if (*cyls <= MAXCYLS) {
543 } else { /* too high for 64*32 */
544 *cyls = size /MEDHEADS/MEDSECS;
545 if (*cyls <= MAXCYLS) {
548 } else { /* too high for 127*63 */
549 *cyls = size /BIGHEADS/BIGSECS;
556 /* controller search and initialization functions */
558 static int __init gdth_search_eisa(ushort eisa_adr)
562 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr));
563 id = inl(eisa_adr+ID0REG);
564 if (id == GDT3A_ID || id == GDT3B_ID) { /* GDT3000A or GDT3000B */
565 if ((inb(eisa_adr+EISAREG) & 8) == 0)
566 return 0; /* not EISA configured */
569 if (id == GDT3_ID) /* GDT3000 */
574 #endif /* CONFIG_EISA */
577 static int __init gdth_search_isa(ulong32 bios_adr)
582 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
583 if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) {
586 if (id == GDT2_ID) /* GDT2000 */
591 #endif /* CONFIG_ISA */
594 static bool gdth_pci_registered;
596 static bool gdth_search_vortex(ushort device)
598 if (device <= PCI_DEVICE_ID_VORTEX_GDT6555)
600 if (device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP &&
601 device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP)
603 if (device == PCI_DEVICE_ID_VORTEX_GDTNEWRX ||
604 device == PCI_DEVICE_ID_VORTEX_GDTNEWRX2)
609 static int gdth_pci_probe_one(gdth_pci_str *pcistr, gdth_ha_str **ha_out);
610 static int gdth_pci_init_one(struct pci_dev *pdev,
611 const struct pci_device_id *ent);
612 static void gdth_pci_remove_one(struct pci_dev *pdev);
613 static void gdth_remove_one(gdth_ha_str *ha);
615 /* Vortex only makes RAID controllers.
616 * We do not really want to specify all 550 ids here, so wildcard match.
618 static const struct pci_device_id gdthtable[] = {
619 { PCI_VDEVICE(VORTEX, PCI_ANY_ID) },
620 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC) },
621 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC_XSCALE) },
622 { } /* terminate list */
624 MODULE_DEVICE_TABLE(pci, gdthtable);
626 static struct pci_driver gdth_pci_driver = {
628 .id_table = gdthtable,
629 .probe = gdth_pci_init_one,
630 .remove = gdth_pci_remove_one,
633 static void gdth_pci_remove_one(struct pci_dev *pdev)
635 gdth_ha_str *ha = pci_get_drvdata(pdev);
637 pci_set_drvdata(pdev, NULL);
642 pci_disable_device(pdev);
645 static int gdth_pci_init_one(struct pci_dev *pdev,
646 const struct pci_device_id *ent)
648 ushort vendor = pdev->vendor;
649 ushort device = pdev->device;
650 ulong base0, base1, base2;
652 gdth_pci_str gdth_pcistr;
653 gdth_ha_str *ha = NULL;
655 TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
656 gdth_ctr_count, vendor, device));
658 memset(&gdth_pcistr, 0, sizeof(gdth_pcistr));
660 if (vendor == PCI_VENDOR_ID_VORTEX && !gdth_search_vortex(device))
663 rc = pci_enable_device(pdev);
667 if (gdth_ctr_count >= MAXHA)
670 /* GDT PCI controller found, resources are already in pdev */
671 gdth_pcistr.pdev = pdev;
672 base0 = pci_resource_flags(pdev, 0);
673 base1 = pci_resource_flags(pdev, 1);
674 base2 = pci_resource_flags(pdev, 2);
675 if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
676 device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
677 if (!(base0 & IORESOURCE_MEM))
679 gdth_pcistr.dpmem = pci_resource_start(pdev, 0);
680 } else { /* GDT6110, GDT6120, .. */
681 if (!(base0 & IORESOURCE_MEM) ||
682 !(base2 & IORESOURCE_MEM) ||
683 !(base1 & IORESOURCE_IO))
685 gdth_pcistr.dpmem = pci_resource_start(pdev, 2);
686 gdth_pcistr.io = pci_resource_start(pdev, 1);
688 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
689 gdth_pcistr.pdev->bus->number,
690 PCI_SLOT(gdth_pcistr.pdev->devfn),
694 rc = gdth_pci_probe_one(&gdth_pcistr, &ha);
700 #endif /* CONFIG_PCI */
703 static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha)
706 unchar prot_ver,eisacf,i,irq_found;
708 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr));
710 /* disable board interrupts, deinitialize services */
711 outb(0xff,eisa_adr+EDOORREG);
712 outb(0x00,eisa_adr+EDENABREG);
713 outb(0x00,eisa_adr+EINTENABREG);
715 outb(0xff,eisa_adr+LDOORREG);
716 retries = INIT_RETRIES;
718 while (inb(eisa_adr+EDOORREG) != 0xff) {
719 if (--retries == 0) {
720 printk("GDT-EISA: Initialization error (DEINIT failed)\n");
724 TRACE2(("wait for DEINIT: retries=%d\n",retries));
726 prot_ver = inb(eisa_adr+MAILBOXREG);
727 outb(0xff,eisa_adr+EDOORREG);
728 if (prot_ver != PROTOCOL_VERSION) {
729 printk("GDT-EISA: Illegal protocol version\n");
733 ha->brd_phys = (ulong32)eisa_adr >> 12;
735 outl(0,eisa_adr+MAILBOXREG);
736 outl(0,eisa_adr+MAILBOXREG+4);
737 outl(0,eisa_adr+MAILBOXREG+8);
738 outl(0,eisa_adr+MAILBOXREG+12);
741 if ((id = inl(eisa_adr+ID0REG)) == GDT3_ID) {
742 ha->oem_id = OEM_ID_ICP;
745 outl(1,eisa_adr+MAILBOXREG+8);
746 outb(0xfe,eisa_adr+LDOORREG);
747 retries = INIT_RETRIES;
749 while (inb(eisa_adr+EDOORREG) != 0xfe) {
750 if (--retries == 0) {
751 printk("GDT-EISA: Initialization error (get IRQ failed)\n");
756 ha->irq = inb(eisa_adr+MAILBOXREG);
757 outb(0xff,eisa_adr+EDOORREG);
758 TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq));
759 /* check the result */
761 TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
762 for (i = 0, irq_found = FALSE;
763 i < MAXHA && irq[i] != 0xff; ++i) {
764 if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) {
772 printk("GDT-EISA: Can not detect controller IRQ,\n");
773 printk("Use IRQ setting from command line (IRQ = %d)\n",
776 printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
777 printk("the controller BIOS or use command line parameters\n");
782 eisacf = inb(eisa_adr+EISAREG) & 7;
783 if (eisacf > 4) /* level triggered */
785 ha->irq = gdth_irq_tab[eisacf];
786 ha->oem_id = OEM_ID_ICP;
791 ha->dma64_support = 0;
794 #endif /* CONFIG_EISA */
797 static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
799 register gdt2_dpram_str __iomem *dp2_ptr;
801 unchar irq_drq,prot_ver;
804 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr));
806 ha->brd = ioremap(bios_adr, sizeof(gdt2_dpram_str));
807 if (ha->brd == NULL) {
808 printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
812 writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
813 /* reset interface area */
814 memset_io(&dp2_ptr->u, 0, sizeof(dp2_ptr->u));
815 if (readl(&dp2_ptr->u) != 0) {
816 printk("GDT-ISA: Initialization error (DPMEM write error)\n");
821 /* disable board interrupts, read DRQ and IRQ */
822 writeb(0xff, &dp2_ptr->io.irqdel);
823 writeb(0x00, &dp2_ptr->io.irqen);
824 writeb(0x00, &dp2_ptr->u.ic.S_Status);
825 writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
827 irq_drq = readb(&dp2_ptr->io.rq);
828 for (i=0; i<3; ++i) {
829 if ((irq_drq & 1)==0)
833 ha->drq = gdth_drq_tab[i];
835 irq_drq = readb(&dp2_ptr->io.rq) >> 3;
836 for (i=1; i<5; ++i) {
837 if ((irq_drq & 1)==0)
841 ha->irq = gdth_irq_tab[i];
843 /* deinitialize services */
844 writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
845 writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
846 writeb(0, &dp2_ptr->io.event);
847 retries = INIT_RETRIES;
849 while (readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
850 if (--retries == 0) {
851 printk("GDT-ISA: Initialization error (DEINIT failed)\n");
857 prot_ver = (unchar)readl(&dp2_ptr->u.ic.S_Info[0]);
858 writeb(0, &dp2_ptr->u.ic.Status);
859 writeb(0xff, &dp2_ptr->io.irqdel);
860 if (prot_ver != PROTOCOL_VERSION) {
861 printk("GDT-ISA: Illegal protocol version\n");
866 ha->oem_id = OEM_ID_ICP;
868 ha->ic_all_size = sizeof(dp2_ptr->u);
870 ha->brd_phys = bios_adr >> 4;
872 /* special request to controller BIOS */
873 writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
874 writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
875 writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
876 writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
877 writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
878 writeb(0, &dp2_ptr->io.event);
879 retries = INIT_RETRIES;
881 while (readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
882 if (--retries == 0) {
883 printk("GDT-ISA: Initialization error\n");
889 writeb(0, &dp2_ptr->u.ic.Status);
890 writeb(0xff, &dp2_ptr->io.irqdel);
892 ha->dma64_support = 0;
895 #endif /* CONFIG_ISA */
898 static int gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
901 register gdt6_dpram_str __iomem *dp6_ptr;
902 register gdt6c_dpram_str __iomem *dp6c_ptr;
903 register gdt6m_dpram_str __iomem *dp6m_ptr;
907 int i, found = FALSE;
909 TRACE(("gdth_init_pci()\n"));
911 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
912 ha->oem_id = OEM_ID_INTEL;
914 ha->oem_id = OEM_ID_ICP;
915 ha->brd_phys = (pdev->bus->number << 8) | (pdev->devfn & 0xf8);
916 ha->stype = (ulong32)pdev->device;
920 if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */
921 TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
922 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6_dpram_str));
923 if (ha->brd == NULL) {
924 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
927 /* check and reset interface area */
929 writel(DPMEM_MAGIC, &dp6_ptr->u);
930 if (readl(&dp6_ptr->u) != DPMEM_MAGIC) {
931 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
934 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
936 ha->brd = ioremap(i, sizeof(ushort));
937 if (ha->brd == NULL) {
938 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
941 if (readw(ha->brd) != 0xffff) {
942 TRACE2(("init_pci_old() address 0x%x busy\n", i));
946 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i);
947 ha->brd = ioremap(i, sizeof(gdt6_dpram_str));
948 if (ha->brd == NULL) {
949 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
953 writel(DPMEM_MAGIC, &dp6_ptr->u);
954 if (readl(&dp6_ptr->u) == DPMEM_MAGIC) {
955 printk("GDT-PCI: Use free address at 0x%x\n", i);
961 printk("GDT-PCI: No free address found!\n");
966 memset_io(&dp6_ptr->u, 0, sizeof(dp6_ptr->u));
967 if (readl(&dp6_ptr->u) != 0) {
968 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
973 /* disable board interrupts, deinit services */
974 writeb(0xff, &dp6_ptr->io.irqdel);
975 writeb(0x00, &dp6_ptr->io.irqen);
976 writeb(0x00, &dp6_ptr->u.ic.S_Status);
977 writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
979 writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
980 writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
981 writeb(0, &dp6_ptr->io.event);
982 retries = INIT_RETRIES;
984 while (readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
985 if (--retries == 0) {
986 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
992 prot_ver = (unchar)readl(&dp6_ptr->u.ic.S_Info[0]);
993 writeb(0, &dp6_ptr->u.ic.S_Status);
994 writeb(0xff, &dp6_ptr->io.irqdel);
995 if (prot_ver != PROTOCOL_VERSION) {
996 printk("GDT-PCI: Illegal protocol version\n");
1002 ha->ic_all_size = sizeof(dp6_ptr->u);
1004 /* special command to controller BIOS */
1005 writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
1006 writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
1007 writel(0x00, &dp6_ptr->u.ic.S_Info[2]);
1008 writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
1009 writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
1010 writeb(0, &dp6_ptr->io.event);
1011 retries = INIT_RETRIES;
1013 while (readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
1014 if (--retries == 0) {
1015 printk("GDT-PCI: Initialization error\n");
1021 writeb(0, &dp6_ptr->u.ic.S_Status);
1022 writeb(0xff, &dp6_ptr->io.irqdel);
1024 ha->dma64_support = 0;
1026 } else if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */
1027 ha->plx = (gdt6c_plx_regs *)pcistr->io;
1028 TRACE2(("init_pci_new() dpmem %lx irq %d\n",
1029 pcistr->dpmem,ha->irq));
1030 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6c_dpram_str));
1031 if (ha->brd == NULL) {
1032 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1036 /* check and reset interface area */
1038 writel(DPMEM_MAGIC, &dp6c_ptr->u);
1039 if (readl(&dp6c_ptr->u) != DPMEM_MAGIC) {
1040 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1043 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1045 ha->brd = ioremap(i, sizeof(ushort));
1046 if (ha->brd == NULL) {
1047 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1050 if (readw(ha->brd) != 0xffff) {
1051 TRACE2(("init_pci_plx() address 0x%x busy\n", i));
1055 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_2, i);
1056 ha->brd = ioremap(i, sizeof(gdt6c_dpram_str));
1057 if (ha->brd == NULL) {
1058 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1062 writel(DPMEM_MAGIC, &dp6c_ptr->u);
1063 if (readl(&dp6c_ptr->u) == DPMEM_MAGIC) {
1064 printk("GDT-PCI: Use free address at 0x%x\n", i);
1070 printk("GDT-PCI: No free address found!\n");
1075 memset_io(&dp6c_ptr->u, 0, sizeof(dp6c_ptr->u));
1076 if (readl(&dp6c_ptr->u) != 0) {
1077 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1082 /* disable board interrupts, deinit services */
1083 outb(0x00,PTR2USHORT(&ha->plx->control1));
1084 outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
1086 writeb(0x00, &dp6c_ptr->u.ic.S_Status);
1087 writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
1089 writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
1090 writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
1092 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1094 retries = INIT_RETRIES;
1096 while (readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
1097 if (--retries == 0) {
1098 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1104 prot_ver = (unchar)readl(&dp6c_ptr->u.ic.S_Info[0]);
1105 writeb(0, &dp6c_ptr->u.ic.Status);
1106 if (prot_ver != PROTOCOL_VERSION) {
1107 printk("GDT-PCI: Illegal protocol version\n");
1112 ha->type = GDT_PCINEW;
1113 ha->ic_all_size = sizeof(dp6c_ptr->u);
1115 /* special command to controller BIOS */
1116 writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
1117 writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
1118 writel(0x00, &dp6c_ptr->u.ic.S_Info[2]);
1119 writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
1120 writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
1122 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1124 retries = INIT_RETRIES;
1126 while (readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
1127 if (--retries == 0) {
1128 printk("GDT-PCI: Initialization error\n");
1134 writeb(0, &dp6c_ptr->u.ic.S_Status);
1136 ha->dma64_support = 0;
1139 TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
1140 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6m_dpram_str));
1141 if (ha->brd == NULL) {
1142 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1146 /* manipulate config. space to enable DPMEM, start RP controller */
1147 pci_read_config_word(pdev, PCI_COMMAND, &command);
1149 pci_write_config_word(pdev, PCI_COMMAND, command);
1150 if (pci_resource_start(pdev, 8) == 1UL)
1151 pci_resource_start(pdev, 8) = 0UL;
1153 pci_write_config_dword(pdev, PCI_ROM_ADDRESS, i);
1155 pci_write_config_dword(pdev, PCI_ROM_ADDRESS,
1156 pci_resource_start(pdev, 8));
1160 /* Ensure that it is safe to access the non HW portions of DPMEM.
1161 * Aditional check needed for Xscale based RAID controllers */
1162 while( ((int)readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 )
1165 /* check and reset interface area */
1166 writel(DPMEM_MAGIC, &dp6m_ptr->u);
1167 if (readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
1168 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1171 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1173 ha->brd = ioremap(i, sizeof(ushort));
1174 if (ha->brd == NULL) {
1175 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1178 if (readw(ha->brd) != 0xffff) {
1179 TRACE2(("init_pci_mpr() address 0x%x busy\n", i));
1183 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i);
1184 ha->brd = ioremap(i, sizeof(gdt6m_dpram_str));
1185 if (ha->brd == NULL) {
1186 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1190 writel(DPMEM_MAGIC, &dp6m_ptr->u);
1191 if (readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
1192 printk("GDT-PCI: Use free address at 0x%x\n", i);
1198 printk("GDT-PCI: No free address found!\n");
1203 memset_io(&dp6m_ptr->u, 0, sizeof(dp6m_ptr->u));
1205 /* disable board interrupts, deinit services */
1206 writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
1207 &dp6m_ptr->i960r.edoor_en_reg);
1208 writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1209 writeb(0x00, &dp6m_ptr->u.ic.S_Status);
1210 writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
1212 writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
1213 writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
1214 writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1215 retries = INIT_RETRIES;
1217 while (readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
1218 if (--retries == 0) {
1219 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1225 prot_ver = (unchar)readl(&dp6m_ptr->u.ic.S_Info[0]);
1226 writeb(0, &dp6m_ptr->u.ic.S_Status);
1227 if (prot_ver != PROTOCOL_VERSION) {
1228 printk("GDT-PCI: Illegal protocol version\n");
1233 ha->type = GDT_PCIMPR;
1234 ha->ic_all_size = sizeof(dp6m_ptr->u);
1236 /* special command to controller BIOS */
1237 writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
1238 writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
1239 writel(0x00, &dp6m_ptr->u.ic.S_Info[2]);
1240 writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
1241 writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
1242 writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1243 retries = INIT_RETRIES;
1245 while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
1246 if (--retries == 0) {
1247 printk("GDT-PCI: Initialization error\n");
1253 writeb(0, &dp6m_ptr->u.ic.S_Status);
1255 /* read FW version to detect 64-bit DMA support */
1256 writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx);
1257 writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1258 retries = INIT_RETRIES;
1260 while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) {
1261 if (--retries == 0) {
1262 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1268 prot_ver = (unchar)(readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
1269 writeb(0, &dp6m_ptr->u.ic.S_Status);
1270 if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */
1271 ha->dma64_support = 0;
1273 ha->dma64_support = 1;
1278 #endif /* CONFIG_PCI */
1280 /* controller protocol functions */
1282 static void __init gdth_enable_int(gdth_ha_str *ha)
1285 gdt2_dpram_str __iomem *dp2_ptr;
1286 gdt6_dpram_str __iomem *dp6_ptr;
1287 gdt6m_dpram_str __iomem *dp6m_ptr;
1289 TRACE(("gdth_enable_int() hanum %d\n",ha->hanum));
1290 spin_lock_irqsave(&ha->smp_lock, flags);
1292 if (ha->type == GDT_EISA) {
1293 outb(0xff, ha->bmic + EDOORREG);
1294 outb(0xff, ha->bmic + EDENABREG);
1295 outb(0x01, ha->bmic + EINTENABREG);
1296 } else if (ha->type == GDT_ISA) {
1298 writeb(1, &dp2_ptr->io.irqdel);
1299 writeb(0, &dp2_ptr->u.ic.Cmd_Index);
1300 writeb(1, &dp2_ptr->io.irqen);
1301 } else if (ha->type == GDT_PCI) {
1303 writeb(1, &dp6_ptr->io.irqdel);
1304 writeb(0, &dp6_ptr->u.ic.Cmd_Index);
1305 writeb(1, &dp6_ptr->io.irqen);
1306 } else if (ha->type == GDT_PCINEW) {
1307 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
1308 outb(0x03, PTR2USHORT(&ha->plx->control1));
1309 } else if (ha->type == GDT_PCIMPR) {
1311 writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1312 writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
1313 &dp6m_ptr->i960r.edoor_en_reg);
1315 spin_unlock_irqrestore(&ha->smp_lock, flags);
1318 /* return IStatus if interrupt was from this card else 0 */
1319 static unchar gdth_get_status(gdth_ha_str *ha)
1323 TRACE(("gdth_get_status() irq %d ctr_count %d\n", ha->irq, gdth_ctr_count));
1325 if (ha->type == GDT_EISA)
1326 IStatus = inb((ushort)ha->bmic + EDOORREG);
1327 else if (ha->type == GDT_ISA)
1329 readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
1330 else if (ha->type == GDT_PCI)
1332 readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
1333 else if (ha->type == GDT_PCINEW)
1334 IStatus = inb(PTR2USHORT(&ha->plx->edoor_reg));
1335 else if (ha->type == GDT_PCIMPR)
1337 readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg);
1342 static int gdth_test_busy(gdth_ha_str *ha)
1344 register int gdtsema0 = 0;
1346 TRACE(("gdth_test_busy() hanum %d\n", ha->hanum));
1348 if (ha->type == GDT_EISA)
1349 gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
1350 else if (ha->type == GDT_ISA)
1351 gdtsema0 = (int)readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1352 else if (ha->type == GDT_PCI)
1353 gdtsema0 = (int)readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1354 else if (ha->type == GDT_PCINEW)
1355 gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg));
1356 else if (ha->type == GDT_PCIMPR)
1358 (int)readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
1360 return (gdtsema0 & 1);
1364 static int gdth_get_cmd_index(gdth_ha_str *ha)
1368 TRACE(("gdth_get_cmd_index() hanum %d\n", ha->hanum));
1370 for (i=0; i<GDTH_MAXCMDS; ++i) {
1371 if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
1372 ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
1373 ha->cmd_tab[i].service = ha->pccb->Service;
1374 ha->pccb->CommandIndex = (ulong32)i+2;
1382 static void gdth_set_sema0(gdth_ha_str *ha)
1384 TRACE(("gdth_set_sema0() hanum %d\n", ha->hanum));
1386 if (ha->type == GDT_EISA) {
1387 outb(1, ha->bmic + SEMA0REG);
1388 } else if (ha->type == GDT_ISA) {
1389 writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1390 } else if (ha->type == GDT_PCI) {
1391 writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1392 } else if (ha->type == GDT_PCINEW) {
1393 outb(1, PTR2USHORT(&ha->plx->sema0_reg));
1394 } else if (ha->type == GDT_PCIMPR) {
1395 writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
1400 static void gdth_copy_command(gdth_ha_str *ha)
1402 register gdth_cmd_str *cmd_ptr;
1403 register gdt6m_dpram_str __iomem *dp6m_ptr;
1404 register gdt6c_dpram_str __iomem *dp6c_ptr;
1405 gdt6_dpram_str __iomem *dp6_ptr;
1406 gdt2_dpram_str __iomem *dp2_ptr;
1407 ushort cp_count,dp_offset,cmd_no;
1409 TRACE(("gdth_copy_command() hanum %d\n", ha->hanum));
1411 cp_count = ha->cmd_len;
1412 dp_offset= ha->cmd_offs_dpmem;
1413 cmd_no = ha->cmd_cnt;
1417 if (ha->type == GDT_EISA)
1418 return; /* no DPMEM, no copy */
1420 /* set cpcount dword aligned */
1422 cp_count += (4 - (cp_count & 3));
1424 ha->cmd_offs_dpmem += cp_count;
1426 /* set offset and service, copy command to DPMEM */
1427 if (ha->type == GDT_ISA) {
1429 writew(dp_offset + DPMEM_COMMAND_OFFSET,
1430 &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
1431 writew((ushort)cmd_ptr->Service,
1432 &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
1433 memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1434 } else if (ha->type == GDT_PCI) {
1436 writew(dp_offset + DPMEM_COMMAND_OFFSET,
1437 &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
1438 writew((ushort)cmd_ptr->Service,
1439 &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
1440 memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1441 } else if (ha->type == GDT_PCINEW) {
1443 writew(dp_offset + DPMEM_COMMAND_OFFSET,
1444 &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
1445 writew((ushort)cmd_ptr->Service,
1446 &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
1447 memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1448 } else if (ha->type == GDT_PCIMPR) {
1450 writew(dp_offset + DPMEM_COMMAND_OFFSET,
1451 &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
1452 writew((ushort)cmd_ptr->Service,
1453 &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
1454 memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1459 static void gdth_release_event(gdth_ha_str *ha)
1461 TRACE(("gdth_release_event() hanum %d\n", ha->hanum));
1463 #ifdef GDTH_STATISTICS
1466 for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
1467 if (ha->cmd_tab[j].cmnd != UNUSED_CMND)
1470 if (max_index < i) {
1472 TRACE3(("GDT: max_index = %d\n",(ushort)i));
1477 if (ha->pccb->OpCode == GDT_INIT)
1478 ha->pccb->Service |= 0x80;
1480 if (ha->type == GDT_EISA) {
1481 if (ha->pccb->OpCode == GDT_INIT) /* store DMA buffer */
1482 outl(ha->ccb_phys, ha->bmic + MAILBOXREG);
1483 outb(ha->pccb->Service, ha->bmic + LDOORREG);
1484 } else if (ha->type == GDT_ISA) {
1485 writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event);
1486 } else if (ha->type == GDT_PCI) {
1487 writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event);
1488 } else if (ha->type == GDT_PCINEW) {
1489 outb(1, PTR2USHORT(&ha->plx->ldoor_reg));
1490 } else if (ha->type == GDT_PCIMPR) {
1491 writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg);
1495 static int gdth_wait(gdth_ha_str *ha, int index, ulong32 time)
1497 int answer_found = FALSE;
1500 TRACE(("gdth_wait() hanum %d index %d time %d\n", ha->hanum, index, time));
1503 return 1; /* no wait required */
1506 __gdth_interrupt(ha, true, &wait_index);
1507 if (wait_index == index) {
1508 answer_found = TRUE;
1514 while (gdth_test_busy(ha))
1517 return (answer_found);
1521 static int gdth_internal_cmd(gdth_ha_str *ha, unchar service, ushort opcode,
1522 ulong32 p1, ulong64 p2, ulong64 p3)
1524 register gdth_cmd_str *cmd_ptr;
1527 TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode));
1530 memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str));
1533 for (retries = INIT_RETRIES;;) {
1534 cmd_ptr->Service = service;
1535 cmd_ptr->RequestBuffer = INTERNAL_CMND;
1536 if (!(index=gdth_get_cmd_index(ha))) {
1537 TRACE(("GDT: No free command index found\n"));
1541 cmd_ptr->OpCode = opcode;
1542 cmd_ptr->BoardNode = LOCALBOARD;
1543 if (service == CACHESERVICE) {
1544 if (opcode == GDT_IOCTL) {
1545 cmd_ptr->u.ioctl.subfunc = p1;
1546 cmd_ptr->u.ioctl.channel = (ulong32)p2;
1547 cmd_ptr->u.ioctl.param_size = (ushort)p3;
1548 cmd_ptr->u.ioctl.p_param = ha->scratch_phys;
1550 if (ha->cache_feat & GDT_64BIT) {
1551 cmd_ptr->u.cache64.DeviceNo = (ushort)p1;
1552 cmd_ptr->u.cache64.BlockNo = p2;
1554 cmd_ptr->u.cache.DeviceNo = (ushort)p1;
1555 cmd_ptr->u.cache.BlockNo = (ulong32)p2;
1558 } else if (service == SCSIRAWSERVICE) {
1559 if (ha->raw_feat & GDT_64BIT) {
1560 cmd_ptr->u.raw64.direction = p1;
1561 cmd_ptr->u.raw64.bus = (unchar)p2;
1562 cmd_ptr->u.raw64.target = (unchar)p3;
1563 cmd_ptr->u.raw64.lun = (unchar)(p3 >> 8);
1565 cmd_ptr->u.raw.direction = p1;
1566 cmd_ptr->u.raw.bus = (unchar)p2;
1567 cmd_ptr->u.raw.target = (unchar)p3;
1568 cmd_ptr->u.raw.lun = (unchar)(p3 >> 8);
1570 } else if (service == SCREENSERVICE) {
1571 if (opcode == GDT_REALTIME) {
1572 *(ulong32 *)&cmd_ptr->u.screen.su.data[0] = p1;
1573 *(ulong32 *)&cmd_ptr->u.screen.su.data[4] = (ulong32)p2;
1574 *(ulong32 *)&cmd_ptr->u.screen.su.data[8] = (ulong32)p3;
1577 ha->cmd_len = sizeof(gdth_cmd_str);
1578 ha->cmd_offs_dpmem = 0;
1580 gdth_copy_command(ha);
1581 gdth_release_event(ha);
1583 if (!gdth_wait(ha, index, INIT_TIMEOUT)) {
1584 printk("GDT: Initialization error (timeout service %d)\n",service);
1587 if (ha->status != S_BSY || --retries == 0)
1592 return (ha->status != S_OK ? 0:1);
1596 /* search for devices */
1598 static int __init gdth_search_drives(gdth_ha_str *ha)
1602 ulong32 bus_no, drv_cnt, drv_no, j;
1603 gdth_getch_str *chn;
1604 gdth_drlist_str *drl;
1605 gdth_iochan_str *ioc;
1606 gdth_raw_iochan_str *iocr;
1607 gdth_arcdl_str *alst;
1608 gdth_alist_str *alst2;
1609 gdth_oem_str_ioctl *oemstr;
1611 gdth_perf_modes *pmod;
1619 TRACE(("gdth_search_drives() hanum %d\n", ha->hanum));
1622 /* initialize controller services, at first: screen service */
1623 ha->screen_feat = 0;
1625 ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_X_INIT_SCR, 0, 0, 0);
1627 ha->screen_feat = GDT_64BIT;
1629 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1630 ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_INIT, 0, 0, 0);
1632 printk("GDT-HA %d: Initialization error screen service (code %d)\n",
1633 ha->hanum, ha->status);
1636 TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n"));
1639 /* read realtime clock info, send to controller */
1640 /* 1. wait for the falling edge of update flag */
1641 spin_lock_irqsave(&rtc_lock, flags);
1642 for (j = 0; j < 1000000; ++j)
1643 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
1645 for (j = 0; j < 1000000; ++j)
1646 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
1650 for (j = 0; j < 12; ++j)
1651 rtc[j] = CMOS_READ(j);
1652 } while (rtc[0] != CMOS_READ(0));
1653 spin_unlock_irqrestore(&rtc_lock, flags);
1654 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32 *)&rtc[0],
1655 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]));
1656 /* 3. send to controller firmware */
1657 gdth_internal_cmd(ha, SCREENSERVICE, GDT_REALTIME, *(ulong32 *)&rtc[0],
1658 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]);
1661 /* unfreeze all IOs */
1662 gdth_internal_cmd(ha, CACHESERVICE, GDT_UNFREEZE_IO, 0, 0, 0);
1664 /* initialize cache service */
1667 ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INIT_HOST, LINUX_OS,
1670 ha->cache_feat = GDT_64BIT;
1672 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1673 ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_INIT, LINUX_OS, 0, 0);
1675 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1676 ha->hanum, ha->status);
1679 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
1680 cdev_cnt = (ushort)ha->info;
1681 ha->fw_vers = ha->service;
1684 if (ha->type == GDT_PCIMPR) {
1685 /* set perf. modes */
1686 pmod = (gdth_perf_modes *)ha->pscratch;
1688 pmod->st_mode = 1; /* enable one status buffer */
1689 *((ulong64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys;
1690 pmod->st_buff_indx1 = COALINDEX;
1691 pmod->st_buff_addr2 = 0;
1692 pmod->st_buff_u_addr2 = 0;
1693 pmod->st_buff_indx2 = 0;
1694 pmod->st_buff_size = sizeof(gdth_coal_status) * MAXOFFSETS;
1695 pmod->cmd_mode = 0; // disable all cmd buffers
1696 pmod->cmd_buff_addr1 = 0;
1697 pmod->cmd_buff_u_addr1 = 0;
1698 pmod->cmd_buff_indx1 = 0;
1699 pmod->cmd_buff_addr2 = 0;
1700 pmod->cmd_buff_u_addr2 = 0;
1701 pmod->cmd_buff_indx2 = 0;
1702 pmod->cmd_buff_size = 0;
1703 pmod->reserved1 = 0;
1704 pmod->reserved2 = 0;
1705 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, SET_PERF_MODES,
1706 INVALID_CHANNEL,sizeof(gdth_perf_modes))) {
1707 printk("GDT-HA %d: Interrupt coalescing activated\n", ha->hanum);
1712 /* detect number of buses - try new IOCTL */
1713 iocr = (gdth_raw_iochan_str *)ha->pscratch;
1714 iocr->hdr.version = 0xffffffff;
1715 iocr->hdr.list_entries = MAXBUS;
1716 iocr->hdr.first_chan = 0;
1717 iocr->hdr.last_chan = MAXBUS-1;
1718 iocr->hdr.list_offset = GDTOFFSOF(gdth_raw_iochan_str, list[0]);
1719 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, IOCHAN_RAW_DESC,
1720 INVALID_CHANNEL,sizeof(gdth_raw_iochan_str))) {
1721 TRACE2(("IOCHAN_RAW_DESC supported!\n"));
1722 ha->bus_cnt = iocr->hdr.chan_count;
1723 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1724 if (iocr->list[bus_no].proc_id < MAXID)
1725 ha->bus_id[bus_no] = iocr->list[bus_no].proc_id;
1727 ha->bus_id[bus_no] = 0xff;
1731 chn = (gdth_getch_str *)ha->pscratch;
1732 for (bus_no = 0; bus_no < MAXBUS; ++bus_no) {
1733 chn->channel_no = bus_no;
1734 if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
1735 SCSI_CHAN_CNT | L_CTRL_PATTERN,
1736 IO_CHANNEL | INVALID_CHANNEL,
1737 sizeof(gdth_getch_str))) {
1739 printk("GDT-HA %d: Error detecting channel count (0x%x)\n",
1740 ha->hanum, ha->status);
1745 if (chn->siop_id < MAXID)
1746 ha->bus_id[bus_no] = chn->siop_id;
1748 ha->bus_id[bus_no] = 0xff;
1750 ha->bus_cnt = (unchar)bus_no;
1752 TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt));
1754 /* read cache configuration */
1755 if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_INFO,
1756 INVALID_CHANNEL,sizeof(gdth_cinfo_str))) {
1757 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1758 ha->hanum, ha->status);
1761 ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar;
1762 TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
1763 ha->cpar.version,ha->cpar.state,ha->cpar.strategy,
1764 ha->cpar.write_back,ha->cpar.block_size));
1766 /* read board info and features */
1767 ha->more_proc = FALSE;
1768 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, BOARD_INFO,
1769 INVALID_CHANNEL,sizeof(gdth_binfo_str))) {
1770 memcpy(&ha->binfo, (gdth_binfo_str *)ha->pscratch,
1771 sizeof(gdth_binfo_str));
1772 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, BOARD_FEATURES,
1773 INVALID_CHANNEL,sizeof(gdth_bfeat_str))) {
1774 TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n"));
1775 ha->bfeat = *(gdth_bfeat_str *)ha->pscratch;
1776 ha->more_proc = TRUE;
1779 TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n"));
1780 strcpy(ha->binfo.type_string, gdth_ctr_name(ha));
1782 TRACE2(("Controller name: %s\n",ha->binfo.type_string));
1784 /* read more informations */
1785 if (ha->more_proc) {
1786 /* physical drives, channel addresses */
1787 ioc = (gdth_iochan_str *)ha->pscratch;
1788 ioc->hdr.version = 0xffffffff;
1789 ioc->hdr.list_entries = MAXBUS;
1790 ioc->hdr.first_chan = 0;
1791 ioc->hdr.last_chan = MAXBUS-1;
1792 ioc->hdr.list_offset = GDTOFFSOF(gdth_iochan_str, list[0]);
1793 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, IOCHAN_DESC,
1794 INVALID_CHANNEL,sizeof(gdth_iochan_str))) {
1795 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1796 ha->raw[bus_no].address = ioc->list[bus_no].address;
1797 ha->raw[bus_no].local_no = ioc->list[bus_no].local_no;
1800 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1801 ha->raw[bus_no].address = IO_CHANNEL;
1802 ha->raw[bus_no].local_no = bus_no;
1805 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1806 chn = (gdth_getch_str *)ha->pscratch;
1807 chn->channel_no = ha->raw[bus_no].local_no;
1808 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
1809 SCSI_CHAN_CNT | L_CTRL_PATTERN,
1810 ha->raw[bus_no].address | INVALID_CHANNEL,
1811 sizeof(gdth_getch_str))) {
1812 ha->raw[bus_no].pdev_cnt = chn->drive_cnt;
1813 TRACE2(("Channel %d: %d phys. drives\n",
1814 bus_no,chn->drive_cnt));
1816 if (ha->raw[bus_no].pdev_cnt > 0) {
1817 drl = (gdth_drlist_str *)ha->pscratch;
1818 drl->sc_no = ha->raw[bus_no].local_no;
1819 drl->sc_cnt = ha->raw[bus_no].pdev_cnt;
1820 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
1821 SCSI_DR_LIST | L_CTRL_PATTERN,
1822 ha->raw[bus_no].address | INVALID_CHANNEL,
1823 sizeof(gdth_drlist_str))) {
1824 for (j = 0; j < ha->raw[bus_no].pdev_cnt; ++j)
1825 ha->raw[bus_no].id_list[j] = drl->sc_list[j];
1827 ha->raw[bus_no].pdev_cnt = 0;
1832 /* logical drives */
1833 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_CNT,
1834 INVALID_CHANNEL,sizeof(ulong32))) {
1835 drv_cnt = *(ulong32 *)ha->pscratch;
1836 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_LIST,
1837 INVALID_CHANNEL,drv_cnt * sizeof(ulong32))) {
1838 for (j = 0; j < drv_cnt; ++j) {
1839 drv_no = ((ulong32 *)ha->pscratch)[j];
1840 if (drv_no < MAX_LDRIVES) {
1841 ha->hdr[drv_no].is_logdrv = TRUE;
1842 TRACE2(("Drive %d is log. drive\n",drv_no));
1846 alst = (gdth_arcdl_str *)ha->pscratch;
1847 alst->entries_avail = MAX_LDRIVES;
1848 alst->first_entry = 0;
1849 alst->list_offset = GDTOFFSOF(gdth_arcdl_str, list[0]);
1850 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
1851 ARRAY_DRV_LIST2 | LA_CTRL_PATTERN,
1852 INVALID_CHANNEL, sizeof(gdth_arcdl_str) +
1853 (alst->entries_avail-1) * sizeof(gdth_alist_str))) {
1854 for (j = 0; j < alst->entries_init; ++j) {
1855 ha->hdr[j].is_arraydrv = alst->list[j].is_arrayd;
1856 ha->hdr[j].is_master = alst->list[j].is_master;
1857 ha->hdr[j].is_parity = alst->list[j].is_parity;
1858 ha->hdr[j].is_hotfix = alst->list[j].is_hotfix;
1859 ha->hdr[j].master_no = alst->list[j].cd_handle;
1861 } else if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
1862 ARRAY_DRV_LIST | LA_CTRL_PATTERN,
1863 0, 35 * sizeof(gdth_alist_str))) {
1864 for (j = 0; j < 35; ++j) {
1865 alst2 = &((gdth_alist_str *)ha->pscratch)[j];
1866 ha->hdr[j].is_arraydrv = alst2->is_arrayd;
1867 ha->hdr[j].is_master = alst2->is_master;
1868 ha->hdr[j].is_parity = alst2->is_parity;
1869 ha->hdr[j].is_hotfix = alst2->is_hotfix;
1870 ha->hdr[j].master_no = alst2->cd_handle;
1876 /* initialize raw service */
1879 ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_X_INIT_RAW, 0, 0, 0);
1881 ha->raw_feat = GDT_64BIT;
1883 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1884 ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_INIT, 0, 0, 0);
1886 printk("GDT-HA %d: Initialization error raw service (code %d)\n",
1887 ha->hanum, ha->status);
1890 TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n"));
1892 /* set/get features raw service (scatter/gather) */
1893 if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_SET_FEAT, SCATTER_GATHER,
1895 TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
1896 if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_GET_FEAT, 0, 0, 0)) {
1897 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
1899 ha->raw_feat |= (ushort)ha->info;
1903 /* set/get features cache service (equal to raw service) */
1904 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_SET_FEAT, 0,
1905 SCATTER_GATHER,0)) {
1906 TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
1907 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_GET_FEAT, 0, 0, 0)) {
1908 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
1910 ha->cache_feat |= (ushort)ha->info;
1914 /* reserve drives for raw service */
1915 if (reserve_mode != 0) {
1916 gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESERVE_ALL,
1917 reserve_mode == 1 ? 1 : 3, 0, 0);
1918 TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n",
1921 for (i = 0; i < MAX_RES_ARGS; i += 4) {
1922 if (reserve_list[i] == ha->hanum && reserve_list[i+1] < ha->bus_cnt &&
1923 reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) {
1924 TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
1925 reserve_list[i], reserve_list[i+1],
1926 reserve_list[i+2], reserve_list[i+3]));
1927 if (!gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESERVE, 0,
1928 reserve_list[i+1], reserve_list[i+2] |
1929 (reserve_list[i+3] << 8))) {
1930 printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n",
1931 ha->hanum, ha->status);
1936 /* Determine OEM string using IOCTL */
1937 oemstr = (gdth_oem_str_ioctl *)ha->pscratch;
1938 oemstr->params.ctl_version = 0x01;
1939 oemstr->params.buffer_size = sizeof(oemstr->text);
1940 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
1941 CACHE_READ_OEM_STRING_RECORD,INVALID_CHANNEL,
1942 sizeof(gdth_oem_str_ioctl))) {
1943 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n"));
1944 printk("GDT-HA %d: Vendor: %s Name: %s\n",
1945 ha->hanum, oemstr->text.oem_company_name, ha->binfo.type_string);
1946 /* Save the Host Drive inquiry data */
1947 strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,
1948 sizeof(ha->oem_name));
1950 /* Old method, based on PCI ID */
1951 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
1952 printk("GDT-HA %d: Name: %s\n",
1953 ha->hanum, ha->binfo.type_string);
1954 if (ha->oem_id == OEM_ID_INTEL)
1955 strlcpy(ha->oem_name,"Intel ", sizeof(ha->oem_name));
1957 strlcpy(ha->oem_name,"ICP ", sizeof(ha->oem_name));
1960 /* scanning for host drives */
1961 for (i = 0; i < cdev_cnt; ++i)
1962 gdth_analyse_hdrive(ha, i);
1964 TRACE(("gdth_search_drives() OK\n"));
1968 static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive)
1971 int drv_hds, drv_secs;
1973 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n", ha->hanum, hdrive));
1974 if (hdrive >= MAX_HDRIVES)
1977 if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_INFO, hdrive, 0, 0))
1979 ha->hdr[hdrive].present = TRUE;
1980 ha->hdr[hdrive].size = ha->info;
1982 /* evaluate mapping (sectors per head, heads per cylinder) */
1983 ha->hdr[hdrive].size &= ~SECS32;
1984 if (ha->info2 == 0) {
1985 gdth_eval_mapping(ha->hdr[hdrive].size,&drv_cyls,&drv_hds,&drv_secs);
1987 drv_hds = ha->info2 & 0xff;
1988 drv_secs = (ha->info2 >> 8) & 0xff;
1989 drv_cyls = (ulong32)ha->hdr[hdrive].size / drv_hds / drv_secs;
1991 ha->hdr[hdrive].heads = (unchar)drv_hds;
1992 ha->hdr[hdrive].secs = (unchar)drv_secs;
1994 ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs;
1996 if (ha->cache_feat & GDT_64BIT) {
1997 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INFO, hdrive, 0, 0)
1998 && ha->info2 != 0) {
1999 ha->hdr[hdrive].size = ((ulong64)ha->info2 << 32) | ha->info;
2002 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
2003 hdrive,ha->hdr[hdrive].size,drv_hds,drv_secs));
2005 /* get informations about device */
2006 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_DEVTYPE, hdrive, 0, 0)) {
2007 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
2009 ha->hdr[hdrive].devtype = (ushort)ha->info;
2013 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_CLUST_INFO, hdrive, 0, 0)) {
2014 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
2017 ha->hdr[hdrive].cluster_type = (unchar)ha->info;
2020 /* R/W attributes */
2021 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_RW_ATTRIBS, hdrive, 0, 0)) {
2022 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
2024 ha->hdr[hdrive].rw_attribs = (unchar)ha->info;
2031 /* command queueing/sending functions */
2033 static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar priority)
2035 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
2036 register Scsi_Cmnd *pscp;
2037 register Scsi_Cmnd *nscp;
2041 TRACE(("gdth_putq() priority %d\n",priority));
2042 spin_lock_irqsave(&ha->smp_lock, flags);
2044 if (!cmndinfo->internal_command) {
2045 cmndinfo->priority = priority;
2046 b = scp->device->channel;
2047 t = scp->device->id;
2048 if (priority >= DEFAULT_PRI) {
2049 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2050 (b==ha->virt_bus && t<MAX_HDRIVES && ha->hdr[t].lock)) {
2051 TRACE2(("gdth_putq(): locked IO ->update_timeout()\n"));
2052 cmndinfo->timeout = gdth_update_timeout(scp, 0);
2057 if (ha->req_first==NULL) {
2058 ha->req_first = scp; /* queue was empty */
2059 scp->SCp.ptr = NULL;
2060 } else { /* queue not empty */
2061 pscp = ha->req_first;
2062 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2063 /* priority: 0-highest,..,0xff-lowest */
2064 while (nscp && gdth_cmnd_priv(nscp)->priority <= priority) {
2066 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2068 pscp->SCp.ptr = (char *)scp;
2069 scp->SCp.ptr = (char *)nscp;
2071 spin_unlock_irqrestore(&ha->smp_lock, flags);
2073 #ifdef GDTH_STATISTICS
2075 for (nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
2077 if (max_rq < flags) {
2079 TRACE3(("GDT: max_rq = %d\n",(ushort)max_rq));
2084 static void gdth_next(gdth_ha_str *ha)
2086 register Scsi_Cmnd *pscp;
2087 register Scsi_Cmnd *nscp;
2088 unchar b, t, l, firsttime;
2089 unchar this_cmd, next_cmd;
2093 TRACE(("gdth_next() hanum %d\n", ha->hanum));
2095 spin_lock_irqsave(&ha->smp_lock, flags);
2097 ha->cmd_cnt = ha->cmd_offs_dpmem = 0;
2098 this_cmd = firsttime = TRUE;
2099 next_cmd = gdth_polling ? FALSE:TRUE;
2102 for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) {
2103 struct gdth_cmndinfo *nscp_cmndinfo = gdth_cmnd_priv(nscp);
2104 if (nscp != pscp && nscp != (Scsi_Cmnd *)pscp->SCp.ptr)
2105 pscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2106 if (!nscp_cmndinfo->internal_command) {
2107 b = nscp->device->channel;
2108 t = nscp->device->id;
2109 l = nscp->device->lun;
2110 if (nscp_cmndinfo->priority >= DEFAULT_PRI) {
2111 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2112 (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock))
2119 if (gdth_test_busy(ha)) { /* controller busy ? */
2120 TRACE(("gdth_next() controller %d busy !\n", ha->hanum));
2121 if (!gdth_polling) {
2122 spin_unlock_irqrestore(&ha->smp_lock, flags);
2125 while (gdth_test_busy(ha))
2131 if (!nscp_cmndinfo->internal_command) {
2132 if (nscp_cmndinfo->phase == -1) {
2133 nscp_cmndinfo->phase = CACHESERVICE; /* default: cache svc. */
2134 if (nscp->cmnd[0] == TEST_UNIT_READY) {
2135 TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
2137 /* TEST_UNIT_READY -> set scan mode */
2138 if ((ha->scan_mode & 0x0f) == 0) {
2139 if (b == 0 && t == 0 && l == 0) {
2141 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2143 } else if ((ha->scan_mode & 0x0f) == 1) {
2144 if (b == 0 && ((t == 0 && l == 1) ||
2145 (t == 1 && l == 0))) {
2146 nscp_cmndinfo->OpCode = GDT_SCAN_START;
2147 nscp_cmndinfo->phase = ((ha->scan_mode & 0x10 ? 1:0) << 8)
2149 ha->scan_mode = 0x12;
2150 TRACE2(("Scan mode: 0x%x (SCAN_START)\n",
2153 ha->scan_mode &= 0x10;
2154 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2156 } else if (ha->scan_mode == 0x12) {
2157 if (b == ha->bus_cnt && t == ha->tid_cnt-1) {
2158 nscp_cmndinfo->phase = SCSIRAWSERVICE;
2159 nscp_cmndinfo->OpCode = GDT_SCAN_END;
2160 ha->scan_mode &= 0x10;
2161 TRACE2(("Scan mode: 0x%x (SCAN_END)\n",
2166 if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY &&
2167 nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE &&
2168 (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) {
2169 /* always GDT_CLUST_INFO! */
2170 nscp_cmndinfo->OpCode = GDT_CLUST_INFO;
2175 if (nscp_cmndinfo->OpCode != -1) {
2176 if ((nscp_cmndinfo->phase & 0xff) == CACHESERVICE) {
2177 if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t)))
2180 } else if ((nscp_cmndinfo->phase & 0xff) == SCSIRAWSERVICE) {
2181 if (!(cmd_index=gdth_fill_raw_cmd(ha, nscp, BUS_L2P(ha, b))))
2185 memset((char*)nscp->sense_buffer,0,16);
2186 nscp->sense_buffer[0] = 0x70;
2187 nscp->sense_buffer[2] = NOT_READY;
2188 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2189 if (!nscp_cmndinfo->wait_for_completion)
2190 nscp_cmndinfo->wait_for_completion++;
2192 gdth_scsi_done(nscp);
2194 } else if (gdth_cmnd_priv(nscp)->internal_command) {
2195 if (!(cmd_index=gdth_special_cmd(ha, nscp)))
2198 } else if (b != ha->virt_bus) {
2199 if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW ||
2200 !(cmd_index=gdth_fill_raw_cmd(ha, nscp, BUS_L2P(ha, b))))
2203 ha->raw[BUS_L2P(ha,b)].io_cnt[t]++;
2204 } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || l != 0) {
2205 TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
2206 nscp->cmnd[0], b, t, l));
2207 nscp->result = DID_BAD_TARGET << 16;
2208 if (!nscp_cmndinfo->wait_for_completion)
2209 nscp_cmndinfo->wait_for_completion++;
2211 gdth_scsi_done(nscp);
2213 switch (nscp->cmnd[0]) {
2214 case TEST_UNIT_READY:
2221 case SERVICE_ACTION_IN:
2222 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2223 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2224 nscp->cmnd[4],nscp->cmnd[5]));
2225 if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) {
2226 /* return UNIT_ATTENTION */
2227 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2229 ha->hdr[t].media_changed = FALSE;
2230 memset((char*)nscp->sense_buffer,0,16);
2231 nscp->sense_buffer[0] = 0x70;
2232 nscp->sense_buffer[2] = UNIT_ATTENTION;
2233 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2234 if (!nscp_cmndinfo->wait_for_completion)
2235 nscp_cmndinfo->wait_for_completion++;
2237 gdth_scsi_done(nscp);
2238 } else if (gdth_internal_cache_cmd(ha, nscp))
2239 gdth_scsi_done(nscp);
2242 case ALLOW_MEDIUM_REMOVAL:
2243 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2244 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2245 nscp->cmnd[4],nscp->cmnd[5]));
2246 if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) {
2247 TRACE(("Prevent r. nonremov. drive->do nothing\n"));
2248 nscp->result = DID_OK << 16;
2249 nscp->sense_buffer[0] = 0;
2250 if (!nscp_cmndinfo->wait_for_completion)
2251 nscp_cmndinfo->wait_for_completion++;
2253 gdth_scsi_done(nscp);
2255 nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0;
2256 TRACE(("Prevent/allow r. %d rem. drive %d\n",
2257 nscp->cmnd[4],nscp->cmnd[3]));
2258 if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t)))
2265 TRACE2(("cache cmd %s\n",nscp->cmnd[0] == RESERVE ?
2266 "RESERVE" : "RELEASE"));
2267 if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t)))
2277 if (ha->hdr[t].media_changed) {
2278 /* return UNIT_ATTENTION */
2279 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2281 ha->hdr[t].media_changed = FALSE;
2282 memset((char*)nscp->sense_buffer,0,16);
2283 nscp->sense_buffer[0] = 0x70;
2284 nscp->sense_buffer[2] = UNIT_ATTENTION;
2285 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2286 if (!nscp_cmndinfo->wait_for_completion)
2287 nscp_cmndinfo->wait_for_completion++;
2289 gdth_scsi_done(nscp);
2290 } else if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t)))
2295 TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0],
2296 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2297 nscp->cmnd[4],nscp->cmnd[5]));
2298 printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n",
2299 ha->hanum, nscp->cmnd[0]);
2300 nscp->result = DID_ABORT << 16;
2301 if (!nscp_cmndinfo->wait_for_completion)
2302 nscp_cmndinfo->wait_for_completion++;
2304 gdth_scsi_done(nscp);
2311 if (nscp == ha->req_first)
2312 ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
2314 pscp->SCp.ptr = nscp->SCp.ptr;
2319 if (ha->cmd_cnt > 0) {
2320 gdth_release_event(ha);
2324 spin_unlock_irqrestore(&ha->smp_lock, flags);
2326 if (gdth_polling && ha->cmd_cnt > 0) {
2327 if (!gdth_wait(ha, cmd_index, POLL_TIMEOUT))
2328 printk("GDT-HA %d: Command %d timed out !\n",
2329 ha->hanum, cmd_index);
2334 * gdth_copy_internal_data() - copy to/from a buffer onto a scsi_cmnd's
2335 * buffers, kmap_atomic() as needed.
2337 static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp,
2338 char *buffer, ushort count)
2340 ushort cpcount,i, max_sg = gdth_sg_count(scp);
2342 struct scatterlist *sl;
2345 cpcount = min_t(ushort, count, gdth_bufflen(scp));
2349 scsi_for_each_sg(scp, sl, max_sg, i) {
2350 unsigned long flags;
2351 cpnow = (ushort)sl->length;
2352 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2353 cpnow, cpsum, cpcount, gdth_bufflen(scp)));
2354 if (cpsum+cpnow > cpcount)
2355 cpnow = cpcount - cpsum;
2358 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
2362 local_irq_save(flags);
2363 address = kmap_atomic(sg_page(sl), KM_BIO_SRC_IRQ) + sl->offset;
2364 memcpy(address, buffer, cpnow);
2365 flush_dcache_page(sg_page(sl));
2366 kunmap_atomic(address, KM_BIO_SRC_IRQ);
2367 local_irq_restore(flags);
2368 if (cpsum == cpcount)
2373 printk("GDT-HA %d: SCSI command with no buffers but data transfer expected!\n",
2379 static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
2383 gdth_rdcap_data rdc;
2385 gdth_modep_data mpd;
2386 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
2388 t = scp->device->id;
2389 TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
2392 scp->result = DID_OK << 16;
2393 scp->sense_buffer[0] = 0;
2395 switch (scp->cmnd[0]) {
2396 case TEST_UNIT_READY:
2399 TRACE2(("Test/Verify/Start hdrive %d\n",t));
2403 TRACE2(("Inquiry hdrive %d devtype %d\n",
2404 t,ha->hdr[t].devtype));
2405 inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK;
2406 /* you can here set all disks to removable, if you want to do
2407 a flush using the ALLOW_MEDIUM_REMOVAL command */
2408 inq.modif_rmb = 0x00;
2409 if ((ha->hdr[t].devtype & 1) ||
2410 (ha->hdr[t].cluster_type & CLUSTER_DRIVE))
2411 inq.modif_rmb = 0x80;
2415 strcpy(inq.vendor,ha->oem_name);
2416 sprintf(inq.product,"Host Drive #%02d",t);
2417 strcpy(inq.revision," ");
2418 gdth_copy_internal_data(ha, scp, (char*)&inq, sizeof(gdth_inq_data));
2422 TRACE2(("Request sense hdrive %d\n",t));
2423 sd.errorcode = 0x70;
2428 gdth_copy_internal_data(ha, scp, (char*)&sd, sizeof(gdth_sense_data));
2432 TRACE2(("Mode sense hdrive %d\n",t));
2433 memset((char*)&mpd,0,sizeof(gdth_modep_data));
2434 mpd.hd.data_length = sizeof(gdth_modep_data);
2435 mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0;
2436 mpd.hd.bd_length = sizeof(mpd.bd);
2437 mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
2438 mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
2439 mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
2440 gdth_copy_internal_data(ha, scp, (char*)&mpd, sizeof(gdth_modep_data));
2444 TRACE2(("Read capacity hdrive %d\n",t));
2445 if (ha->hdr[t].size > (ulong64)0xffffffff)
2446 rdc.last_block_no = 0xffffffff;
2448 rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1);
2449 rdc.block_length = cpu_to_be32(SECTOR_SIZE);
2450 gdth_copy_internal_data(ha, scp, (char*)&rdc, sizeof(gdth_rdcap_data));
2453 case SERVICE_ACTION_IN:
2454 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 &&
2455 (ha->cache_feat & GDT_64BIT)) {
2456 gdth_rdcap16_data rdc16;
2458 TRACE2(("Read capacity (16) hdrive %d\n",t));
2459 rdc16.last_block_no = cpu_to_be64(ha->hdr[t].size-1);
2460 rdc16.block_length = cpu_to_be32(SECTOR_SIZE);
2461 gdth_copy_internal_data(ha, scp, (char*)&rdc16,
2462 sizeof(gdth_rdcap16_data));
2464 scp->result = DID_ABORT << 16;
2469 TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0]));
2473 if (!cmndinfo->wait_for_completion)
2474 cmndinfo->wait_for_completion++;
2481 static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
2483 register gdth_cmd_str *cmdp;
2484 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
2485 ulong32 cnt, blockcnt;
2486 ulong64 no, blockno;
2487 int i, cmd_index, read_write, sgcnt, mode64;
2490 TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
2491 scp->cmnd[0],scp->cmd_len,hdrive));
2493 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2496 mode64 = (ha->cache_feat & GDT_64BIT) ? TRUE : FALSE;
2497 /* test for READ_16, WRITE_16 if !mode64 ? ---
2498 not required, should not occur due to error return on
2501 cmdp->Service = CACHESERVICE;
2502 cmdp->RequestBuffer = scp;
2503 /* search free command index */
2504 if (!(cmd_index=gdth_get_cmd_index(ha))) {
2505 TRACE(("GDT: No free command index found\n"));
2508 /* if it's the first command, set command semaphore */
2509 if (ha->cmd_cnt == 0)
2514 if (cmndinfo->OpCode != -1)
2515 cmdp->OpCode = cmndinfo->OpCode; /* special cache cmd. */
2516 else if (scp->cmnd[0] == RESERVE)
2517 cmdp->OpCode = GDT_RESERVE_DRV;
2518 else if (scp->cmnd[0] == RELEASE)
2519 cmdp->OpCode = GDT_RELEASE_DRV;
2520 else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
2521 if (scp->cmnd[4] & 1) /* prevent ? */
2522 cmdp->OpCode = GDT_MOUNT;
2523 else if (scp->cmnd[3] & 1) /* removable drive ? */
2524 cmdp->OpCode = GDT_UNMOUNT;
2526 cmdp->OpCode = GDT_FLUSH;
2527 } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10 ||
2528 scp->cmnd[0] == WRITE_12 || scp->cmnd[0] == WRITE_16
2531 if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) &&
2532 (ha->cache_feat & GDT_WR_THROUGH)))
2533 cmdp->OpCode = GDT_WRITE_THR;
2535 cmdp->OpCode = GDT_WRITE;
2538 cmdp->OpCode = GDT_READ;
2541 cmdp->BoardNode = LOCALBOARD;
2543 cmdp->u.cache64.DeviceNo = hdrive;
2544 cmdp->u.cache64.BlockNo = 1;
2545 cmdp->u.cache64.sg_canz = 0;
2547 cmdp->u.cache.DeviceNo = hdrive;
2548 cmdp->u.cache.BlockNo = 1;
2549 cmdp->u.cache.sg_canz = 0;
2553 if (scp->cmd_len == 16) {
2554 memcpy(&no, &scp->cmnd[2], sizeof(ulong64));
2555 blockno = be64_to_cpu(no);
2556 memcpy(&cnt, &scp->cmnd[10], sizeof(ulong32));
2557 blockcnt = be32_to_cpu(cnt);
2558 } else if (scp->cmd_len == 10) {
2559 memcpy(&no, &scp->cmnd[2], sizeof(ulong32));
2560 blockno = be32_to_cpu(no);
2561 memcpy(&cnt, &scp->cmnd[7], sizeof(ushort));
2562 blockcnt = be16_to_cpu(cnt);
2564 memcpy(&no, &scp->cmnd[0], sizeof(ulong32));
2565 blockno = be32_to_cpu(no) & 0x001fffffUL;
2566 blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
2569 cmdp->u.cache64.BlockNo = blockno;
2570 cmdp->u.cache64.BlockCnt = blockcnt;
2572 cmdp->u.cache.BlockNo = (ulong32)blockno;
2573 cmdp->u.cache.BlockCnt = blockcnt;
2576 if (gdth_bufflen(scp)) {
2577 cmndinfo->dma_dir = (read_write == 1 ?
2578 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
2579 sgcnt = pci_map_sg(ha->pdev, gdth_sglist(scp), gdth_sg_count(scp),
2582 struct scatterlist *sl;
2584 cmdp->u.cache64.DestAddr= (ulong64)-1;
2585 cmdp->u.cache64.sg_canz = sgcnt;
2586 scsi_for_each_sg(scp, sl, sgcnt, i) {
2587 cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2588 #ifdef GDTH_DMA_STATISTICS
2589 if (cmdp->u.cache64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2594 cmdp->u.cache64.sg_lst[i].sg_len = sg_dma_len(sl);
2597 struct scatterlist *sl;
2599 cmdp->u.cache.DestAddr= 0xffffffff;
2600 cmdp->u.cache.sg_canz = sgcnt;
2601 scsi_for_each_sg(scp, sl, sgcnt, i) {
2602 cmdp->u.cache.sg_lst[i].sg_ptr = sg_dma_address(sl);
2603 #ifdef GDTH_DMA_STATISTICS
2606 cmdp->u.cache.sg_lst[i].sg_len = sg_dma_len(sl);
2610 #ifdef GDTH_STATISTICS
2611 if (max_sg < (ulong32)sgcnt) {
2612 max_sg = (ulong32)sgcnt;
2613 TRACE3(("GDT: max_sg = %d\n",max_sg));
2619 /* evaluate command size, check space */
2621 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2622 cmdp->u.cache64.DestAddr,cmdp->u.cache64.sg_canz,
2623 cmdp->u.cache64.sg_lst[0].sg_ptr,
2624 cmdp->u.cache64.sg_lst[0].sg_len));
2625 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2626 cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt));
2627 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) +
2628 (ushort)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str);
2630 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2631 cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
2632 cmdp->u.cache.sg_lst[0].sg_ptr,
2633 cmdp->u.cache.sg_lst[0].sg_len));
2634 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2635 cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
2636 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
2637 (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str);
2639 if (ha->cmd_len & 3)
2640 ha->cmd_len += (4 - (ha->cmd_len & 3));
2642 if (ha->cmd_cnt > 0) {
2643 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2645 TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
2646 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2652 gdth_copy_command(ha);
2656 static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b)
2658 register gdth_cmd_str *cmdp;
2660 dma_addr_t sense_paddr;
2661 int cmd_index, sgcnt, mode64;
2665 struct gdth_cmndinfo *cmndinfo;
2667 t = scp->device->id;
2668 l = scp->device->lun;
2670 TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
2671 scp->cmnd[0],b,t,l));
2673 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2676 mode64 = (ha->raw_feat & GDT_64BIT) ? TRUE : FALSE;
2678 cmdp->Service = SCSIRAWSERVICE;
2679 cmdp->RequestBuffer = scp;
2680 /* search free command index */
2681 if (!(cmd_index=gdth_get_cmd_index(ha))) {
2682 TRACE(("GDT: No free command index found\n"));
2685 /* if it's the first command, set command semaphore */
2686 if (ha->cmd_cnt == 0)
2689 cmndinfo = gdth_cmnd_priv(scp);
2691 if (cmndinfo->OpCode != -1) {
2692 cmdp->OpCode = cmndinfo->OpCode; /* special raw cmd. */
2693 cmdp->BoardNode = LOCALBOARD;
2695 cmdp->u.raw64.direction = (cmndinfo->phase >> 8);
2696 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2697 cmdp->OpCode, cmdp->u.raw64.direction));
2698 /* evaluate command size */
2699 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst);
2701 cmdp->u.raw.direction = (cmndinfo->phase >> 8);
2702 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2703 cmdp->OpCode, cmdp->u.raw.direction));
2704 /* evaluate command size */
2705 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst);
2709 page = virt_to_page(scp->sense_buffer);
2710 offset = (ulong)scp->sense_buffer & ~PAGE_MASK;
2711 sense_paddr = pci_map_page(ha->pdev,page,offset,
2712 16,PCI_DMA_FROMDEVICE);
2714 cmndinfo->sense_paddr = sense_paddr;
2715 cmdp->OpCode = GDT_WRITE; /* always */
2716 cmdp->BoardNode = LOCALBOARD;
2718 cmdp->u.raw64.reserved = 0;
2719 cmdp->u.raw64.mdisc_time = 0;
2720 cmdp->u.raw64.mcon_time = 0;
2721 cmdp->u.raw64.clen = scp->cmd_len;
2722 cmdp->u.raw64.target = t;
2723 cmdp->u.raw64.lun = l;
2724 cmdp->u.raw64.bus = b;
2725 cmdp->u.raw64.priority = 0;
2726 cmdp->u.raw64.sdlen = gdth_bufflen(scp);
2727 cmdp->u.raw64.sense_len = 16;
2728 cmdp->u.raw64.sense_data = sense_paddr;
2729 cmdp->u.raw64.direction =
2730 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
2731 memcpy(cmdp->u.raw64.cmd,scp->cmnd,16);
2732 cmdp->u.raw64.sg_ranz = 0;
2734 cmdp->u.raw.reserved = 0;
2735 cmdp->u.raw.mdisc_time = 0;
2736 cmdp->u.raw.mcon_time = 0;
2737 cmdp->u.raw.clen = scp->cmd_len;
2738 cmdp->u.raw.target = t;
2739 cmdp->u.raw.lun = l;
2740 cmdp->u.raw.bus = b;
2741 cmdp->u.raw.priority = 0;
2742 cmdp->u.raw.link_p = 0;
2743 cmdp->u.raw.sdlen = gdth_bufflen(scp);
2744 cmdp->u.raw.sense_len = 16;
2745 cmdp->u.raw.sense_data = sense_paddr;
2746 cmdp->u.raw.direction =
2747 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
2748 memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
2749 cmdp->u.raw.sg_ranz = 0;
2752 if (gdth_bufflen(scp)) {
2753 cmndinfo->dma_dir = PCI_DMA_BIDIRECTIONAL;
2754 sgcnt = pci_map_sg(ha->pdev, gdth_sglist(scp), gdth_sg_count(scp),
2757 struct scatterlist *sl;
2759 cmdp->u.raw64.sdata = (ulong64)-1;
2760 cmdp->u.raw64.sg_ranz = sgcnt;
2761 scsi_for_each_sg(scp, sl, sgcnt, i) {
2762 cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2763 #ifdef GDTH_DMA_STATISTICS
2764 if (cmdp->u.raw64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2769 cmdp->u.raw64.sg_lst[i].sg_len = sg_dma_len(sl);
2772 struct scatterlist *sl;
2774 cmdp->u.raw.sdata = 0xffffffff;
2775 cmdp->u.raw.sg_ranz = sgcnt;
2776 scsi_for_each_sg(scp, sl, sgcnt, i) {
2777 cmdp->u.raw.sg_lst[i].sg_ptr = sg_dma_address(sl);
2778 #ifdef GDTH_DMA_STATISTICS
2781 cmdp->u.raw.sg_lst[i].sg_len = sg_dma_len(sl);
2785 #ifdef GDTH_STATISTICS
2786 if (max_sg < sgcnt) {
2788 TRACE3(("GDT: max_sg = %d\n",sgcnt));
2794 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2795 cmdp->u.raw64.sdata,cmdp->u.raw64.sg_ranz,
2796 cmdp->u.raw64.sg_lst[0].sg_ptr,
2797 cmdp->u.raw64.sg_lst[0].sg_len));
2798 /* evaluate command size */
2799 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) +
2800 (ushort)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str);
2802 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2803 cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
2804 cmdp->u.raw.sg_lst[0].sg_ptr,
2805 cmdp->u.raw.sg_lst[0].sg_len));
2806 /* evaluate command size */
2807 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
2808 (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
2812 if (ha->cmd_len & 3)
2813 ha->cmd_len += (4 - (ha->cmd_len & 3));
2815 if (ha->cmd_cnt > 0) {
2816 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2818 TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
2819 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2825 gdth_copy_command(ha);
2829 static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
2831 register gdth_cmd_str *cmdp;
2832 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
2836 TRACE2(("gdth_special_cmd(): "));
2838 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2841 *cmdp = *cmndinfo->internal_cmd_str;
2842 cmdp->RequestBuffer = scp;
2844 /* search free command index */
2845 if (!(cmd_index=gdth_get_cmd_index(ha))) {
2846 TRACE(("GDT: No free command index found\n"));
2850 /* if it's the first command, set command semaphore */
2851 if (ha->cmd_cnt == 0)
2854 /* evaluate command size, check space */
2855 if (cmdp->OpCode == GDT_IOCTL) {
2856 TRACE2(("IOCTL\n"));
2858 GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong64);
2859 } else if (cmdp->Service == CACHESERVICE) {
2860 TRACE2(("cache command %d\n",cmdp->OpCode));
2861 if (ha->cache_feat & GDT_64BIT)
2863 GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + sizeof(gdth_sg64_str);
2866 GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
2867 } else if (cmdp->Service == SCSIRAWSERVICE) {
2868 TRACE2(("raw command %d\n",cmdp->OpCode));
2869 if (ha->raw_feat & GDT_64BIT)
2871 GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + sizeof(gdth_sg64_str);
2874 GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
2877 if (ha->cmd_len & 3)
2878 ha->cmd_len += (4 - (ha->cmd_len & 3));
2880 if (ha->cmd_cnt > 0) {
2881 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2883 TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
2884 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2890 gdth_copy_command(ha);
2895 /* Controller event handling functions */
2896 static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
2897 ushort idx, gdth_evt_data *evt)
2902 /* no GDTH_LOCK_HA() ! */
2903 TRACE2(("gdth_store_event() source %d idx %d\n", source, idx));
2904 if (source == 0) /* no source -> no event */
2907 if (ebuffer[elastidx].event_source == source &&
2908 ebuffer[elastidx].event_idx == idx &&
2909 ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
2910 !memcmp((char *)&ebuffer[elastidx].event_data.eu,
2911 (char *)&evt->eu, evt->size)) ||
2912 (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
2913 !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
2914 (char *)&evt->event_string)))) {
2915 e = &ebuffer[elastidx];
2916 do_gettimeofday(&tv);
2917 e->last_stamp = tv.tv_sec;
2920 if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
2922 if (elastidx == MAX_EVENTS)
2924 if (elastidx == eoldidx) { /* reached mark ? */
2926 if (eoldidx == MAX_EVENTS)
2930 e = &ebuffer[elastidx];
2931 e->event_source = source;
2933 do_gettimeofday(&tv);
2934 e->first_stamp = e->last_stamp = tv.tv_sec;
2936 e->event_data = *evt;
2942 static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
2948 TRACE2(("gdth_read_event() handle %d\n", handle));
2949 spin_lock_irqsave(&ha->smp_lock, flags);
2954 estr->event_source = 0;
2956 if (eindex >= MAX_EVENTS) {
2957 spin_unlock_irqrestore(&ha->smp_lock, flags);
2960 e = &ebuffer[eindex];
2961 if (e->event_source != 0) {
2962 if (eindex != elastidx) {
2963 if (++eindex == MAX_EVENTS)
2968 memcpy(estr, e, sizeof(gdth_evt_str));
2970 spin_unlock_irqrestore(&ha->smp_lock, flags);
2974 static void gdth_readapp_event(gdth_ha_str *ha,
2975 unchar application, gdth_evt_str *estr)
2980 unchar found = FALSE;
2982 TRACE2(("gdth_readapp_event() app. %d\n", application));
2983 spin_lock_irqsave(&ha->smp_lock, flags);
2986 e = &ebuffer[eindex];
2987 if (e->event_source == 0)
2989 if ((e->application & application) == 0) {
2990 e->application |= application;
2994 if (eindex == elastidx)
2996 if (++eindex == MAX_EVENTS)
3000 memcpy(estr, e, sizeof(gdth_evt_str));
3002 estr->event_source = 0;
3003 spin_unlock_irqrestore(&ha->smp_lock, flags);
3006 static void gdth_clear_events(void)
3008 TRACE(("gdth_clear_events()"));
3010 eoldidx = elastidx = 0;
3011 ebuffer[0].event_source = 0;
3015 /* SCSI interface functions */
3017 static irqreturn_t __gdth_interrupt(gdth_ha_str *ha,
3018 int gdth_from_wait, int* pIndex)
3020 gdt6m_dpram_str __iomem *dp6m_ptr = NULL;
3021 gdt6_dpram_str __iomem *dp6_ptr;
3022 gdt2_dpram_str __iomem *dp2_ptr;
3029 int coalesced = FALSE;
3031 gdth_coal_status *pcs = NULL;
3032 int act_int_coal = 0;
3035 TRACE(("gdth_interrupt() IRQ %d\n", ha->irq));
3037 /* if polling and not from gdth_wait() -> return */
3039 if (!gdth_from_wait) {
3045 spin_lock_irqsave(&ha->smp_lock, flags);
3047 /* search controller */
3048 IStatus = gdth_get_status(ha);
3050 /* spurious interrupt */
3052 spin_unlock_irqrestore(&ha->smp_lock, flags);
3056 #ifdef GDTH_STATISTICS
3061 /* See if the fw is returning coalesced status */
3062 if (IStatus == COALINDEX) {
3063 /* Coalesced status. Setup the initial status
3064 buffer pointer and flags */
3065 pcs = ha->coal_stat;
3072 /* For coalesced requests all status
3073 information is found in the status buffer */
3074 IStatus = (unchar)(pcs->status & 0xff);
3078 if (ha->type == GDT_EISA) {
3079 if (IStatus & 0x80) { /* error flag */
3081 ha->status = inw(ha->bmic + MAILBOXREG+8);
3082 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3083 } else /* no error */
3085 ha->info = inl(ha->bmic + MAILBOXREG+12);
3086 ha->service = inw(ha->bmic + MAILBOXREG+10);
3087 ha->info2 = inl(ha->bmic + MAILBOXREG+4);
3089 outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */
3090 outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */
3091 } else if (ha->type == GDT_ISA) {
3093 if (IStatus & 0x80) { /* error flag */
3095 ha->status = readw(&dp2_ptr->u.ic.Status);
3096 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3097 } else /* no error */
3099 ha->info = readl(&dp2_ptr->u.ic.Info[0]);
3100 ha->service = readw(&dp2_ptr->u.ic.Service);
3101 ha->info2 = readl(&dp2_ptr->u.ic.Info[1]);
3103 writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
3104 writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */
3105 writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */
3106 } else if (ha->type == GDT_PCI) {
3108 if (IStatus & 0x80) { /* error flag */
3110 ha->status = readw(&dp6_ptr->u.ic.Status);
3111 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3112 } else /* no error */
3114 ha->info = readl(&dp6_ptr->u.ic.Info[0]);
3115 ha->service = readw(&dp6_ptr->u.ic.Service);
3116 ha->info2 = readl(&dp6_ptr->u.ic.Info[1]);
3118 writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
3119 writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */
3120 writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */
3121 } else if (ha->type == GDT_PCINEW) {
3122 if (IStatus & 0x80) { /* error flag */
3124 ha->status = inw(PTR2USHORT(&ha->plx->status));
3125 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3128 ha->info = inl(PTR2USHORT(&ha->plx->info[0]));
3129 ha->service = inw(PTR2USHORT(&ha->plx->service));
3130 ha->info2 = inl(PTR2USHORT(&ha->plx->info[1]));
3132 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
3133 outb(0x00, PTR2USHORT(&ha->plx->sema1_reg));
3134 } else if (ha->type == GDT_PCIMPR) {
3136 if (IStatus & 0x80) { /* error flag */
3140 ha->status = pcs->ext_status & 0xffff;
3143 ha->status = readw(&dp6m_ptr->i960r.status);
3144 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3145 } else /* no error */
3148 /* get information */
3150 ha->info = pcs->info0;
3151 ha->info2 = pcs->info1;
3152 ha->service = (pcs->ext_status >> 16) & 0xffff;
3156 ha->info = readl(&dp6m_ptr->i960r.info[0]);
3157 ha->service = readw(&dp6m_ptr->i960r.service);
3158 ha->info2 = readl(&dp6m_ptr->i960r.info[1]);
3161 if (IStatus == ASYNCINDEX) {
3162 if (ha->service != SCREENSERVICE &&
3163 (ha->fw_vers & 0xff) >= 0x1a) {
3164 ha->dvr.severity = readb
3165 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.severity);
3166 for (i = 0; i < 256; ++i) {
3167 ha->dvr.event_string[i] = readb
3168 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.evt_str[i]);
3169 if (ha->dvr.event_string[i] == 0)
3175 /* Make sure that non coalesced interrupts get cleared
3176 before being handled by gdth_async_event/gdth_sync_event */
3180 writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3181 writeb(0, &dp6m_ptr->i960r.sema1_reg);
3184 TRACE2(("gdth_interrupt() unknown controller type\n"));
3186 spin_unlock_irqrestore(&ha->smp_lock, flags);
3190 TRACE(("gdth_interrupt() index %d stat %d info %d\n",
3191 IStatus,ha->status,ha->info));
3193 if (gdth_from_wait) {
3194 *pIndex = (int)IStatus;
3197 if (IStatus == ASYNCINDEX) {
3198 TRACE2(("gdth_interrupt() async. event\n"));
3199 gdth_async_event(ha);
3201 spin_unlock_irqrestore(&ha->smp_lock, flags);
3206 if (IStatus == SPEZINDEX) {
3207 TRACE2(("Service unknown or not initialized !\n"));
3208 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3209 ha->dvr.eu.driver.ionode = ha->hanum;
3210 gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr);
3212 spin_unlock_irqrestore(&ha->smp_lock, flags);
3215 scp = ha->cmd_tab[IStatus-2].cmnd;
3216 Service = ha->cmd_tab[IStatus-2].service;
3217 ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND;
3218 if (scp == UNUSED_CMND) {
3219 TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus));
3220 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3221 ha->dvr.eu.driver.ionode = ha->hanum;
3222 ha->dvr.eu.driver.index = IStatus;
3223 gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr);
3225 spin_unlock_irqrestore(&ha->smp_lock, flags);
3228 if (scp == INTERNAL_CMND) {
3229 TRACE(("gdth_interrupt() answer to internal command\n"));
3231 spin_unlock_irqrestore(&ha->smp_lock, flags);
3235 TRACE(("gdth_interrupt() sync. status\n"));
3236 rval = gdth_sync_event(ha,Service,IStatus,scp);
3238 spin_unlock_irqrestore(&ha->smp_lock, flags);
3240 gdth_putq(ha, scp, gdth_cmnd_priv(scp)->priority);
3241 } else if (rval == 1) {
3242 gdth_scsi_done(scp);
3247 /* go to the next status in the status buffer */
3249 #ifdef GDTH_STATISTICS
3251 if (act_int_coal > max_int_coal) {
3252 max_int_coal = act_int_coal;
3253 printk("GDT: max_int_coal = %d\n",(ushort)max_int_coal);
3256 /* see if there is another status */
3257 if (pcs->status == 0)
3258 /* Stop the coalesce loop */
3263 /* coalescing only for new GDT_PCIMPR controllers available */
3264 if (ha->type == GDT_PCIMPR && coalesced) {
3265 writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3266 writeb(0, &dp6m_ptr->i960r.sema1_reg);
3274 static irqreturn_t gdth_interrupt(int irq, void *dev_id)
3276 gdth_ha_str *ha = dev_id;
3278 return __gdth_interrupt(ha, false, NULL);
3281 static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index,
3287 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
3290 TRACE(("gdth_sync_event() serv %d status %d\n",
3291 service,ha->status));
3293 if (service == SCREENSERVICE) {
3295 TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
3296 msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
3297 if (msg->msg_len > MSGLEN+1)
3298 msg->msg_len = MSGLEN+1;
3300 if (!(msg->msg_answer && msg->msg_ext)) {
3301 msg->msg_text[msg->msg_len] = '\0';
3302 printk("%s",msg->msg_text);
3305 if (msg->msg_ext && !msg->msg_answer) {
3306 while (gdth_test_busy(ha))
3308 cmdp->Service = SCREENSERVICE;
3309 cmdp->RequestBuffer = SCREEN_CMND;
3310 gdth_get_cmd_index(ha);
3312 cmdp->OpCode = GDT_READ;
3313 cmdp->BoardNode = LOCALBOARD;
3314 cmdp->u.screen.reserved = 0;
3315 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3316 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3317 ha->cmd_offs_dpmem = 0;
3318 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3321 gdth_copy_command(ha);
3322 gdth_release_event(ha);
3326 if (msg->msg_answer && msg->msg_alen) {
3327 /* default answers (getchar() not possible) */
3328 if (msg->msg_alen == 1) {
3331 msg->msg_text[0] = 0;
3335 msg->msg_text[0] = 1;
3336 msg->msg_text[1] = 0;
3339 msg->msg_answer = 0;
3340 while (gdth_test_busy(ha))
3342 cmdp->Service = SCREENSERVICE;
3343 cmdp->RequestBuffer = SCREEN_CMND;
3344 gdth_get_cmd_index(ha);
3346 cmdp->OpCode = GDT_WRITE;
3347 cmdp->BoardNode = LOCALBOARD;
3348 cmdp->u.screen.reserved = 0;
3349 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3350 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3351 ha->cmd_offs_dpmem = 0;
3352 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3355 gdth_copy_command(ha);
3356 gdth_release_event(ha);
3362 b = scp->device->channel;
3363 t = scp->device->id;
3364 if (cmndinfo->OpCode == -1 && b != ha->virt_bus) {
3365 ha->raw[BUS_L2P(ha,b)].io_cnt[t]--;
3367 /* cache or raw service */
3368 if (ha->status == S_BSY) {
3369 TRACE2(("Controller busy -> retry !\n"));
3370 if (cmndinfo->OpCode == GDT_MOUNT)
3371 cmndinfo->OpCode = GDT_CLUST_INFO;
3375 if (gdth_bufflen(scp))
3376 pci_unmap_sg(ha->pdev, gdth_sglist(scp), gdth_sg_count(scp),
3379 if (cmndinfo->sense_paddr)
3380 pci_unmap_page(ha->pdev, cmndinfo->sense_paddr, 16,
3381 PCI_DMA_FROMDEVICE);
3383 if (ha->status == S_OK) {
3384 cmndinfo->status = S_OK;
3385 cmndinfo->info = ha->info;
3386 if (cmndinfo->OpCode != -1) {
3387 TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
3389 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
3390 if (cmndinfo->OpCode == GDT_CLUST_INFO) {
3391 ha->hdr[t].cluster_type = (unchar)ha->info;
3392 if (!(ha->hdr[t].cluster_type &
3394 /* NOT MOUNTED -> MOUNT */
3395 cmndinfo->OpCode = GDT_MOUNT;
3396 if (ha->hdr[t].cluster_type &
3398 /* cluster drive RESERVED (on the other node) */
3399 cmndinfo->phase = -2; /* reservation conflict */
3402 cmndinfo->OpCode = -1;
3405 if (cmndinfo->OpCode == GDT_MOUNT) {
3406 ha->hdr[t].cluster_type |= CLUSTER_MOUNTED;
3407 ha->hdr[t].media_changed = TRUE;
3408 } else if (cmndinfo->OpCode == GDT_UNMOUNT) {
3409 ha->hdr[t].cluster_type &= ~CLUSTER_MOUNTED;
3410 ha->hdr[t].media_changed = TRUE;
3412 cmndinfo->OpCode = -1;
3415 cmndinfo->priority = HIGH_PRI;
3418 /* RESERVE/RELEASE ? */
3419 if (scp->cmnd[0] == RESERVE) {
3420 ha->hdr[t].cluster_type |= CLUSTER_RESERVED;
3421 } else if (scp->cmnd[0] == RELEASE) {
3422 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3424 scp->result = DID_OK << 16;
3425 scp->sense_buffer[0] = 0;
3428 cmndinfo->status = ha->status;
3429 cmndinfo->info = ha->info;
3431 if (cmndinfo->OpCode != -1) {
3432 TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
3433 cmndinfo->OpCode, ha->status));
3434 if (cmndinfo->OpCode == GDT_SCAN_START ||
3435 cmndinfo->OpCode == GDT_SCAN_END) {
3436 cmndinfo->OpCode = -1;
3438 cmndinfo->priority = HIGH_PRI;
3441 memset((char*)scp->sense_buffer,0,16);
3442 scp->sense_buffer[0] = 0x70;
3443 scp->sense_buffer[2] = NOT_READY;
3444 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
3445 } else if (service == CACHESERVICE) {
3446 if (ha->status == S_CACHE_UNKNOWN &&
3447 (ha->hdr[t].cluster_type &
3448 CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) {
3449 /* bus reset -> force GDT_CLUST_INFO */
3450 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3452 memset((char*)scp->sense_buffer,0,16);
3453 if (ha->status == (ushort)S_CACHE_RESERV) {
3454 scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
3456 scp->sense_buffer[0] = 0x70;
3457 scp->sense_buffer[2] = NOT_READY;
3458 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
3460 if (!cmndinfo->internal_command) {
3461 ha->dvr.size = sizeof(ha->dvr.eu.sync);
3462 ha->dvr.eu.sync.ionode = ha->hanum;
3463 ha->dvr.eu.sync.service = service;
3464 ha->dvr.eu.sync.status = ha->status;
3465 ha->dvr.eu.sync.info = ha->info;
3466 ha->dvr.eu.sync.hostdrive = t;
3467 if (ha->status >= 0x8000)
3468 gdth_store_event(ha, ES_SYNC, 0, &ha->dvr);
3470 gdth_store_event(ha, ES_SYNC, service, &ha->dvr);
3473 /* sense buffer filled from controller firmware (DMA) */
3474 if (ha->status != S_RAW_SCSI || ha->info >= 0x100) {
3475 scp->result = DID_BAD_TARGET << 16;
3477 scp->result = (DID_OK << 16) | ha->info;
3481 if (!cmndinfo->wait_for_completion)
3482 cmndinfo->wait_for_completion++;
3490 static char *async_cache_tab[] = {
3491 /* 0*/ "\011\000\002\002\002\004\002\006\004"
3492 "GDT HA %u, service %u, async. status %u/%lu unknown",
3493 /* 1*/ "\011\000\002\002\002\004\002\006\004"
3494 "GDT HA %u, service %u, async. status %u/%lu unknown",
3495 /* 2*/ "\005\000\002\006\004"
3496 "GDT HA %u, Host Drive %lu not ready",
3497 /* 3*/ "\005\000\002\006\004"
3498 "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",
3499 /* 4*/ "\005\000\002\006\004"
3500 "GDT HA %u, mirror update on Host Drive %lu failed",
3501 /* 5*/ "\005\000\002\006\004"
3502 "GDT HA %u, Mirror Drive %lu failed",
3503 /* 6*/ "\005\000\002\006\004"
3504 "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",
3505 /* 7*/ "\005\000\002\006\004"
3506 "GDT HA %u, Host Drive %lu write protected",
3507 /* 8*/ "\005\000\002\006\004"
3508 "GDT HA %u, media changed in Host Drive %lu",
3509 /* 9*/ "\005\000\002\006\004"
3510 "GDT HA %u, Host Drive %lu is offline",
3511 /*10*/ "\005\000\002\006\004"
3512 "GDT HA %u, media change of Mirror Drive %lu",
3513 /*11*/ "\005\000\002\006\004"
3514 "GDT HA %u, Mirror Drive %lu is write protected",
3515 /*12*/ "\005\000\002\006\004"
3516 "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
3517 /*13*/ "\007\000\002\006\002\010\002"
3518 "GDT HA %u, Array Drive %u: Cache Drive %u failed",
3519 /*14*/ "\005\000\002\006\002"
3520 "GDT HA %u, Array Drive %u: FAIL state entered",
3521 /*15*/ "\005\000\002\006\002"
3522 "GDT HA %u, Array Drive %u: error",
3523 /*16*/ "\007\000\002\006\002\010\002"
3524 "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
3525 /*17*/ "\005\000\002\006\002"
3526 "GDT HA %u, Array Drive %u: parity build failed",
3527 /*18*/ "\005\000\002\006\002"
3528 "GDT HA %u, Array Drive %u: drive rebuild failed",
3529 /*19*/ "\005\000\002\010\002"
3530 "GDT HA %u, Test of Hot Fix %u failed",
3531 /*20*/ "\005\000\002\006\002"
3532 "GDT HA %u, Array Drive %u: drive build finished successfully",
3533 /*21*/ "\005\000\002\006\002"
3534 "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
3535 /*22*/ "\007\000\002\006\002\010\002"
3536 "GDT HA %u, Array Drive %u: Hot Fix %u activated",
3537 /*23*/ "\005\000\002\006\002"
3538 "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
3539 /*24*/ "\005\000\002\010\002"
3540 "GDT HA %u, mirror update on Cache Drive %u completed",
3541 /*25*/ "\005\000\002\010\002"
3542 "GDT HA %u, mirror update on Cache Drive %lu failed",
3543 /*26*/ "\005\000\002\006\002"
3544 "GDT HA %u, Array Drive %u: drive rebuild started",
3545 /*27*/ "\005\000\002\012\001"
3546 "GDT HA %u, Fault bus %u: SHELF OK detected",
3547 /*28*/ "\005\000\002\012\001"
3548 "GDT HA %u, Fault bus %u: SHELF not OK detected",
3549 /*29*/ "\007\000\002\012\001\013\001"
3550 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
3551 /*30*/ "\007\000\002\012\001\013\001"
3552 "GDT HA %u, Fault bus %u, ID %u: new disk detected",
3553 /*31*/ "\007\000\002\012\001\013\001"
3554 "GDT HA %u, Fault bus %u, ID %u: old disk detected",
3555 /*32*/ "\007\000\002\012\001\013\001"
3556 "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid",
3557 /*33*/ "\007\000\002\012\001\013\001"
3558 "GDT HA %u, Fault bus %u, ID %u: invalid device detected",
3559 /*34*/ "\011\000\002\012\001\013\001\006\004"
3560 "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
3561 /*35*/ "\007\000\002\012\001\013\001"
3562 "GDT HA %u, Fault bus %u, ID %u: disk write protected",
3563 /*36*/ "\007\000\002\012\001\013\001"
3564 "GDT HA %u, Fault bus %u, ID %u: disk not available",
3565 /*37*/ "\007\000\002\012\001\006\004"
3566 "GDT HA %u, Fault bus %u: swap detected (%lu)",
3567 /*38*/ "\007\000\002\012\001\013\001"
3568 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
3569 /*39*/ "\007\000\002\012\001\013\001"
3570 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
3571 /*40*/ "\007\000\002\012\001\013\001"
3572 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
3573 /*41*/ "\007\000\002\012\001\013\001"
3574 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
3575 /*42*/ "\005\000\002\006\002"
3576 "GDT HA %u, Array Drive %u: drive build started",
3577 /*43*/ "\003\000\002"
3578 "GDT HA %u, DRAM parity error detected",
3579 /*44*/ "\005\000\002\006\002"
3580 "GDT HA %u, Mirror Drive %u: update started",
3581 /*45*/ "\007\000\002\006\002\010\002"
3582 "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
3583 /*46*/ "\005\000\002\006\002"
3584 "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
3585 /*47*/ "\005\000\002\006\002"
3586 "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
3587 /*48*/ "\005\000\002\006\002"
3588 "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
3589 /*49*/ "\005\000\002\006\002"
3590 "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
3591 /*50*/ "\007\000\002\012\001\013\001"
3592 "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
3593 /*51*/ "\005\000\002\006\002"
3594 "GDT HA %u, Array Drive %u: expand started",
3595 /*52*/ "\005\000\002\006\002"
3596 "GDT HA %u, Array Drive %u: expand finished successfully",
3597 /*53*/ "\005\000\002\006\002"
3598 "GDT HA %u, Array Drive %u: expand failed",
3599 /*54*/ "\003\000\002"
3600 "GDT HA %u, CPU temperature critical",
3601 /*55*/ "\003\000\002"
3602 "GDT HA %u, CPU temperature OK",
3603 /*56*/ "\005\000\002\006\004"
3604 "GDT HA %u, Host drive %lu created",
3605 /*57*/ "\005\000\002\006\002"
3606 "GDT HA %u, Array Drive %u: expand restarted",
3607 /*58*/ "\005\000\002\006\002"
3608 "GDT HA %u, Array Drive %u: expand stopped",
3609 /*59*/ "\005\000\002\010\002"
3610 "GDT HA %u, Mirror Drive %u: drive build quited",
3611 /*60*/ "\005\000\002\006\002"
3612 "GDT HA %u, Array Drive %u: parity build quited",
3613 /*61*/ "\005\000\002\006\002"
3614 "GDT HA %u, Array Drive %u: drive rebuild quited",
3615 /*62*/ "\005\000\002\006\002"
3616 "GDT HA %u, Array Drive %u: parity verify started",
3617 /*63*/ "\005\000\002\006\002"
3618 "GDT HA %u, Array Drive %u: parity verify done",
3619 /*64*/ "\005\000\002\006\002"
3620 "GDT HA %u, Array Drive %u: parity verify failed",
3621 /*65*/ "\005\000\002\006\002"
3622 "GDT HA %u, Array Drive %u: parity error detected",
3623 /*66*/ "\005\000\002\006\002"
3624 "GDT HA %u, Array Drive %u: parity verify quited",
3625 /*67*/ "\005\000\002\006\002"
3626 "GDT HA %u, Host Drive %u reserved",
3627 /*68*/ "\005\000\002\006\002"
3628 "GDT HA %u, Host Drive %u mounted and released",
3629 /*69*/ "\005\000\002\006\002"
3630 "GDT HA %u, Host Drive %u released",
3631 /*70*/ "\003\000\002"
3632 "GDT HA %u, DRAM error detected and corrected with ECC",
3633 /*71*/ "\003\000\002"
3634 "GDT HA %u, Uncorrectable DRAM error detected with ECC",
3635 /*72*/ "\011\000\002\012\001\013\001\014\001"
3636 "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
3637 /*73*/ "\005\000\002\006\002"
3638 "GDT HA %u, Host drive %u resetted locally",
3639 /*74*/ "\005\000\002\006\002"
3640 "GDT HA %u, Host drive %u resetted remotely",
3641 /*75*/ "\003\000\002"
3642 "GDT HA %u, async. status 75 unknown",
3646 static int gdth_async_event(gdth_ha_str *ha)
3652 TRACE2(("gdth_async_event() ha %d serv %d\n",
3653 ha->hanum, ha->service));
3655 if (ha->service == SCREENSERVICE) {
3656 if (ha->status == MSG_REQUEST) {
3657 while (gdth_test_busy(ha))
3659 cmdp->Service = SCREENSERVICE;
3660 cmdp->RequestBuffer = SCREEN_CMND;
3661 cmd_index = gdth_get_cmd_index(ha);
3663 cmdp->OpCode = GDT_READ;
3664 cmdp->BoardNode = LOCALBOARD;
3665 cmdp->u.screen.reserved = 0;
3666 cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE;
3667 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3668 ha->cmd_offs_dpmem = 0;
3669 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3672 gdth_copy_command(ha);
3673 if (ha->type == GDT_EISA)
3674 printk("[EISA slot %d] ",(ushort)ha->brd_phys);
3675 else if (ha->type == GDT_ISA)
3676 printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys);
3678 printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8),
3679 (ushort)((ha->brd_phys>>3)&0x1f));
3680 gdth_release_event(ha);
3684 if (ha->type == GDT_PCIMPR &&
3685 (ha->fw_vers & 0xff) >= 0x1a) {
3687 ha->dvr.eu.async.ionode = ha->hanum;
3688 ha->dvr.eu.async.status = ha->status;
3689 /* severity and event_string already set! */
3691 ha->dvr.size = sizeof(ha->dvr.eu.async);
3692 ha->dvr.eu.async.ionode = ha->hanum;
3693 ha->dvr.eu.async.service = ha->service;
3694 ha->dvr.eu.async.status = ha->status;
3695 ha->dvr.eu.async.info = ha->info;
3696 *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2;
3698 gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr );
3699 gdth_log_event( &ha->dvr, NULL );
3701 /* new host drive from expand? */
3702 if (ha->service == CACHESERVICE && ha->status == 56) {
3703 TRACE2(("gdth_async_event(): new host drive %d created\n",
3705 /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
3711 static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
3713 gdth_stackframe stack;
3717 TRACE2(("gdth_log_event()\n"));
3718 if (dvr->size == 0) {
3719 if (buffer == NULL) {
3720 printk("Adapter %d: %s\n",dvr->eu.async.ionode,dvr->event_string);
3722 sprintf(buffer,"Adapter %d: %s\n",
3723 dvr->eu.async.ionode,dvr->event_string);
3725 } else if (dvr->eu.async.service == CACHESERVICE &&
3726 INDEX_OK(dvr->eu.async.status, async_cache_tab)) {
3727 TRACE2(("GDT: Async. event cache service, event no.: %d\n",
3728 dvr->eu.async.status));
3730 f = async_cache_tab[dvr->eu.async.status];
3732 /* i: parameter to push, j: stack element to fill */
3733 for (j=0,i=1; i < f[0]; i+=2) {
3736 stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]];
3739 stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]];
3742 stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]];
3749 if (buffer == NULL) {
3750 printk(&f[(int)f[0]],stack);
3753 sprintf(buffer,&f[(int)f[0]],stack);
3757 if (buffer == NULL) {
3758 printk("GDT HA %u, Unknown async. event service %d event no. %d\n",
3759 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
3761 sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d",
3762 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
3767 #ifdef GDTH_STATISTICS
3768 static void gdth_timeout(ulong data)
3775 BUG_ON(list_empty(&gdth_instances));
3777 ha = list_first_entry(&gdth_instances, gdth_ha_str, list);
3778 spin_lock_irqsave(&ha->smp_lock, flags);
3780 for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i)
3781 if (ha->cmd_tab[i].cmnd != UNUSED_CMND)
3784 for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
3787 TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
3788 act_ints, act_ios, act_stats, act_rq));
3789 act_ints = act_ios = 0;
3791 gdth_timer.expires = jiffies + 30 * HZ;
3792 add_timer(&gdth_timer);
3793 spin_unlock_irqrestore(&ha->smp_lock, flags);
3797 static void __init internal_setup(char *str,int *ints)
3800 char *cur_str, *argv;
3802 TRACE2(("internal_setup() str %s ints[0] %d\n",
3803 str ? str:"NULL", ints ? ints[0]:0));
3805 /* read irq[] from ints[] */
3811 for (i = 0; i < argc; ++i)
3816 /* analyse string */
3818 while (argv && (cur_str = strchr(argv, ':'))) {
3819 int val = 0, c = *++cur_str;
3821 if (c == 'n' || c == 'N')
3823 else if (c == 'y' || c == 'Y')
3826 val = (int)simple_strtoul(cur_str, NULL, 0);
3828 if (!strncmp(argv, "disable:", 8))
3830 else if (!strncmp(argv, "reserve_mode:", 13))
3832 else if (!strncmp(argv, "reverse_scan:", 13))
3834 else if (!strncmp(argv, "hdr_channel:", 12))
3836 else if (!strncmp(argv, "max_ids:", 8))
3838 else if (!strncmp(argv, "rescan:", 7))
3840 else if (!strncmp(argv, "shared_access:", 14))
3841 shared_access = val;
3842 else if (!strncmp(argv, "probe_eisa_isa:", 15))
3843 probe_eisa_isa = val;
3844 else if (!strncmp(argv, "reserve_list:", 13)) {
3845 reserve_list[0] = val;
3846 for (i = 1; i < MAX_RES_ARGS; i++) {
3847 cur_str = strchr(cur_str, ',');
3850 if (!isdigit((int)*++cur_str)) {
3855 (int)simple_strtoul(cur_str, NULL, 0);
3863 if ((argv = strchr(argv, ',')))
3868 int __init option_setup(char *str)
3874 TRACE2(("option_setup() str %s\n", str ? str:"NULL"));
3876 while (cur && isdigit(*cur) && i <= MAXHA) {
3877 ints[i++] = simple_strtoul(cur, NULL, 0);
3878 if ((cur = strchr(cur, ',')) != NULL) cur++;
3882 internal_setup(cur, ints);
3886 static const char *gdth_ctr_name(gdth_ha_str *ha)
3888 TRACE2(("gdth_ctr_name()\n"));
3890 if (ha->type == GDT_EISA) {
3891 switch (ha->stype) {
3893 return("GDT3000/3020");
3895 return("GDT3000A/3020A/3050A");
3897 return("GDT3000B/3010A");
3899 } else if (ha->type == GDT_ISA) {
3900 return("GDT2000/2020");
3901 } else if (ha->type == GDT_PCI) {
3902 switch (ha->pdev->device) {
3903 case PCI_DEVICE_ID_VORTEX_GDT60x0:
3904 return("GDT6000/6020/6050");
3905 case PCI_DEVICE_ID_VORTEX_GDT6000B:
3906 return("GDT6000B/6010");
3909 /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
3914 static const char *gdth_info(struct Scsi_Host *shp)
3916 gdth_ha_str *ha = shost_priv(shp);
3918 TRACE2(("gdth_info()\n"));
3919 return ((const char *)ha->binfo.type_string);
3922 static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
3924 gdth_ha_str *ha = shost_priv(scp->device->host);
3930 TRACE2(("gdth_eh_bus_reset()\n"));
3932 b = scp->device->channel;
3934 /* clear command tab */
3935 spin_lock_irqsave(&ha->smp_lock, flags);
3936 for (i = 0; i < GDTH_MAXCMDS; ++i) {
3937 cmnd = ha->cmd_tab[i].cmnd;
3938 if (!SPECIAL_SCP(cmnd) && cmnd->device->channel == b)
3939 ha->cmd_tab[i].cmnd = UNUSED_CMND;
3941 spin_unlock_irqrestore(&ha->smp_lock, flags);
3943 if (b == ha->virt_bus) {
3945 for (i = 0; i < MAX_HDRIVES; ++i) {
3946 if (ha->hdr[i].present) {
3947 spin_lock_irqsave(&ha->smp_lock, flags);
3948 gdth_polling = TRUE;
3949 while (gdth_test_busy(ha))
3951 if (gdth_internal_cmd(ha, CACHESERVICE,
3952 GDT_CLUST_RESET, i, 0, 0))
3953 ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED;
3954 gdth_polling = FALSE;
3955 spin_unlock_irqrestore(&ha->smp_lock, flags);
3960 spin_lock_irqsave(&ha->smp_lock, flags);
3961 for (i = 0; i < MAXID; ++i)
3962 ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0;
3963 gdth_polling = TRUE;
3964 while (gdth_test_busy(ha))
3966 gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESET_BUS,
3967 BUS_L2P(ha,b), 0, 0);
3968 gdth_polling = FALSE;
3969 spin_unlock_irqrestore(&ha->smp_lock, flags);
3974 static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip)
3977 gdth_ha_str *ha = shost_priv(sdev->host);
3978 struct scsi_device *sd;
3985 TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", ha->hanum, b, t));
3987 if (b != ha->virt_bus || ha->hdr[t].heads == 0) {
3988 /* raw device or host drive without mapping information */
3989 TRACE2(("Evaluate mapping\n"));
3990 gdth_eval_mapping(capacity,&ip[2],&ip[0],&ip[1]);
3992 ip[0] = ha->hdr[t].heads;
3993 ip[1] = ha->hdr[t].secs;
3994 ip[2] = capacity / ip[0] / ip[1];
3997 TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
3998 ip[0],ip[1],ip[2]));
4003 static int gdth_queuecommand(struct scsi_cmnd *scp,
4004 void (*done)(struct scsi_cmnd *))
4006 gdth_ha_str *ha = shost_priv(scp->device->host);
4007 struct gdth_cmndinfo *cmndinfo;
4009 TRACE(("gdth_queuecommand() cmd 0x%x\n", scp->cmnd[0]));
4011 cmndinfo = gdth_get_cmndinfo(ha);
4014 scp->scsi_done = done;
4015 gdth_update_timeout(scp, scp->timeout_per_command * 6);
4016 cmndinfo->priority = DEFAULT_PRI;
4018 gdth_set_bufflen(scp, scsi_bufflen(scp));
4019 gdth_set_sg_count(scp, scsi_sg_count(scp));
4020 gdth_set_sglist(scp, scsi_sglist(scp));
4022 return __gdth_queuecommand(ha, scp, cmndinfo);
4025 static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp,
4026 struct gdth_cmndinfo *cmndinfo)
4028 scp->host_scribble = (unsigned char *)cmndinfo;
4029 cmndinfo->wait_for_completion = 1;
4030 cmndinfo->phase = -1;
4031 cmndinfo->OpCode = -1;
4033 #ifdef GDTH_STATISTICS
4037 gdth_putq(ha, scp, cmndinfo->priority);
4043 static int gdth_open(struct inode *inode, struct file *filep)
4047 list_for_each_entry(ha, &gdth_instances, list) {
4049 ha->sdev = scsi_get_host_dev(ha->shost);
4052 TRACE(("gdth_open()\n"));
4056 static int gdth_close(struct inode *inode, struct file *filep)
4058 TRACE(("gdth_close()\n"));
4062 static int ioc_event(void __user *arg)
4064 gdth_ioctl_event evt;
4068 if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event)))
4070 ha = gdth_find_ha(evt.ionode);
4074 if (evt.erase == 0xff) {
4075 if (evt.event.event_source == ES_TEST)
4076 evt.event.event_data.size=sizeof(evt.event.event_data.eu.test);
4077 else if (evt.event.event_source == ES_DRIVER)
4078 evt.event.event_data.size=sizeof(evt.event.event_data.eu.driver);
4079 else if (evt.event.event_source == ES_SYNC)
4080 evt.event.event_data.size=sizeof(evt.event.event_data.eu.sync);
4082 evt.event.event_data.size=sizeof(evt.event.event_data.eu.async);
4083 spin_lock_irqsave(&ha->smp_lock, flags);
4084 gdth_store_event(ha, evt.event.event_source, evt.event.event_idx,
4085 &evt.event.event_data);
4086 spin_unlock_irqrestore(&ha->smp_lock, flags);
4087 } else if (evt.erase == 0xfe) {
4088 gdth_clear_events();
4089 } else if (evt.erase == 0) {
4090 evt.handle = gdth_read_event(ha, evt.handle, &evt.event);
4092 gdth_readapp_event(ha, evt.erase, &evt.event);
4094 if (copy_to_user(arg, &evt, sizeof(gdth_ioctl_event)))
4099 static int ioc_lockdrv(void __user *arg)
4101 gdth_ioctl_lockdrv ldrv;
4106 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
4108 ha = gdth_find_ha(ldrv.ionode);
4112 for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) {
4114 if (j >= MAX_HDRIVES || !ha->hdr[j].present)
4117 spin_lock_irqsave(&ha->smp_lock, flags);
4118 ha->hdr[j].lock = 1;
4119 spin_unlock_irqrestore(&ha->smp_lock, flags);
4120 gdth_wait_completion(ha, ha->bus_cnt, j);
4121 gdth_stop_timeout(ha, ha->bus_cnt, j);
4123 spin_lock_irqsave(&ha->smp_lock, flags);
4124 ha->hdr[j].lock = 0;
4125 spin_unlock_irqrestore(&ha->smp_lock, flags);
4126 gdth_start_timeout(ha, ha->bus_cnt, j);
4133 static int ioc_resetdrv(void __user *arg, char *cmnd)
4135 gdth_ioctl_reset res;
4140 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
4141 res.number >= MAX_HDRIVES)
4143 ha = gdth_find_ha(res.ionode);
4147 if (!ha->hdr[res.number].present)
4149 memset(&cmd, 0, sizeof(gdth_cmd_str));
4150 cmd.Service = CACHESERVICE;
4151 cmd.OpCode = GDT_CLUST_RESET;
4152 if (ha->cache_feat & GDT_64BIT)
4153 cmd.u.cache64.DeviceNo = res.number;
4155 cmd.u.cache.DeviceNo = res.number;
4157 rval = __gdth_execute(ha->sdev, &cmd, cmnd, 30, NULL);
4162 if (copy_to_user(arg, &res, sizeof(gdth_ioctl_reset)))
4167 static int ioc_general(void __user *arg, char *cmnd)
4169 gdth_ioctl_general gen;
4175 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
4177 ha = gdth_find_ha(gen.ionode);
4180 if (gen.data_len + gen.sense_len != 0) {
4181 if (!(buf = gdth_ioctl_alloc(ha, gen.data_len + gen.sense_len,
4184 if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general),
4185 gen.data_len + gen.sense_len)) {
4186 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
4190 if (gen.command.OpCode == GDT_IOCTL) {
4191 gen.command.u.ioctl.p_param = paddr;
4192 } else if (gen.command.Service == CACHESERVICE) {
4193 if (ha->cache_feat & GDT_64BIT) {
4194 /* copy elements from 32-bit IOCTL structure */
4195 gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt;
4196 gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo;
4197 gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo;
4199 if (ha->cache_feat & SCATTER_GATHER) {
4200 gen.command.u.cache64.DestAddr = (ulong64)-1;
4201 gen.command.u.cache64.sg_canz = 1;
4202 gen.command.u.cache64.sg_lst[0].sg_ptr = paddr;
4203 gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len;
4204 gen.command.u.cache64.sg_lst[1].sg_len = 0;
4206 gen.command.u.cache64.DestAddr = paddr;
4207 gen.command.u.cache64.sg_canz = 0;
4210 if (ha->cache_feat & SCATTER_GATHER) {
4211 gen.command.u.cache.DestAddr = 0xffffffff;
4212 gen.command.u.cache.sg_canz = 1;
4213 gen.command.u.cache.sg_lst[0].sg_ptr = (ulong32)paddr;
4214 gen.command.u.cache.sg_lst[0].sg_len = gen.data_len;
4215 gen.command.u.cache.sg_lst[1].sg_len = 0;
4217 gen.command.u.cache.DestAddr = paddr;
4218 gen.command.u.cache.sg_canz = 0;
4221 } else if (gen.command.Service == SCSIRAWSERVICE) {
4222 if (ha->raw_feat & GDT_64BIT) {
4223 /* copy elements from 32-bit IOCTL structure */
4225 gen.command.u.raw64.sense_len = gen.command.u.raw.sense_len;
4226 gen.command.u.raw64.bus = gen.command.u.raw.bus;
4227 gen.command.u.raw64.lun = gen.command.u.raw.lun;
4228 gen.command.u.raw64.target = gen.command.u.raw.target;
4229 memcpy(cmd, gen.command.u.raw.cmd, 16);
4230 memcpy(gen.command.u.raw64.cmd, cmd, 16);
4231 gen.command.u.raw64.clen = gen.command.u.raw.clen;
4232 gen.command.u.raw64.sdlen = gen.command.u.raw.sdlen;
4233 gen.command.u.raw64.direction = gen.command.u.raw.direction;
4235 if (ha->raw_feat & SCATTER_GATHER) {
4236 gen.command.u.raw64.sdata = (ulong64)-1;
4237 gen.command.u.raw64.sg_ranz = 1;
4238 gen.command.u.raw64.sg_lst[0].sg_ptr = paddr;
4239 gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len;
4240 gen.command.u.raw64.sg_lst[1].sg_len = 0;
4242 gen.command.u.raw64.sdata = paddr;
4243 gen.command.u.raw64.sg_ranz = 0;
4245 gen.command.u.raw64.sense_data = paddr + gen.data_len;
4247 if (ha->raw_feat & SCATTER_GATHER) {
4248 gen.command.u.raw.sdata = 0xffffffff;
4249 gen.command.u.raw.sg_ranz = 1;
4250 gen.command.u.raw.sg_lst[0].sg_ptr = (ulong32)paddr;
4251 gen.command.u.raw.sg_lst[0].sg_len = gen.data_len;
4252 gen.command.u.raw.sg_lst[1].sg_len = 0;
4254 gen.command.u.raw.sdata = paddr;
4255 gen.command.u.raw.sg_ranz = 0;
4257 gen.command.u.raw.sense_data = (ulong32)paddr + gen.data_len;
4260 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
4265 rval = __gdth_execute(ha->sdev, &gen.command, cmnd, gen.timeout, &gen.info);
4270 if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf,
4271 gen.data_len + gen.sense_len)) {
4272 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
4275 if (copy_to_user(arg, &gen,
4276 sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) {
4277 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
4280 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
4284 static int ioc_hdrlist(void __user *arg, char *cmnd)
4286 gdth_ioctl_rescan *rsc;
4291 u32 cluster_type = 0;
4293 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
4294 cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
4298 if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
4299 (NULL == (ha = gdth_find_ha(rsc->ionode)))) {
4303 memset(cmd, 0, sizeof(gdth_cmd_str));
4305 for (i = 0; i < MAX_HDRIVES; ++i) {
4306 if (!ha->hdr[i].present) {
4307 rsc->hdr_list[i].bus = 0xff;
4310 rsc->hdr_list[i].bus = ha->virt_bus;
4311 rsc->hdr_list[i].target = i;
4312 rsc->hdr_list[i].lun = 0;
4313 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
4314 if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) {
4315 cmd->Service = CACHESERVICE;
4316 cmd->OpCode = GDT_CLUST_INFO;
4317 if (ha->cache_feat & GDT_64BIT)
4318 cmd->u.cache64.DeviceNo = i;
4320 cmd->u.cache.DeviceNo = i;
4321 if (__gdth_execute(ha->sdev, cmd, cmnd, 30, &cluster_type) == S_OK)
4322 rsc->hdr_list[i].cluster_type = cluster_type;
4326 if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
4337 static int ioc_rescan(void __user *arg, char *cmnd)
4339 gdth_ioctl_rescan *rsc;
4341 ushort i, status, hdr_cnt;
4343 int cyls, hds, secs;
4348 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
4349 cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
4353 if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
4354 (NULL == (ha = gdth_find_ha(rsc->ionode)))) {
4358 memset(cmd, 0, sizeof(gdth_cmd_str));
4360 if (rsc->flag == 0) {
4361 /* old method: re-init. cache service */
4362 cmd->Service = CACHESERVICE;
4363 if (ha->cache_feat & GDT_64BIT) {
4364 cmd->OpCode = GDT_X_INIT_HOST;
4365 cmd->u.cache64.DeviceNo = LINUX_OS;
4367 cmd->OpCode = GDT_INIT;
4368 cmd->u.cache.DeviceNo = LINUX_OS;
4371 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4373 hdr_cnt = (status == S_OK ? (ushort)info : 0);
4379 for (; i < hdr_cnt && i < MAX_HDRIVES; ++i) {
4380 cmd->Service = CACHESERVICE;
4381 cmd->OpCode = GDT_INFO;
4382 if (ha->cache_feat & GDT_64BIT)
4383 cmd->u.cache64.DeviceNo = i;
4385 cmd->u.cache.DeviceNo = i;
4387 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4389 spin_lock_irqsave(&ha->smp_lock, flags);
4390 rsc->hdr_list[i].bus = ha->virt_bus;
4391 rsc->hdr_list[i].target = i;
4392 rsc->hdr_list[i].lun = 0;
4393 if (status != S_OK) {
4394 ha->hdr[i].present = FALSE;
4396 ha->hdr[i].present = TRUE;
4397 ha->hdr[i].size = info;
4398 /* evaluate mapping */
4399 ha->hdr[i].size &= ~SECS32;
4400 gdth_eval_mapping(ha->hdr[i].size,&cyls,&hds,&secs);
4401 ha->hdr[i].heads = hds;
4402 ha->hdr[i].secs = secs;
4404 ha->hdr[i].size = cyls * hds * secs;
4406 spin_unlock_irqrestore(&ha->smp_lock, flags);
4410 /* extended info, if GDT_64BIT, for drives > 2 TB */
4411 /* but we need ha->info2, not yet stored in scp->SCp */
4413 /* devtype, cluster info, R/W attribs */
4414 cmd->Service = CACHESERVICE;
4415 cmd->OpCode = GDT_DEVTYPE;
4416 if (ha->cache_feat & GDT_64BIT)
4417 cmd->u.cache64.DeviceNo = i;
4419 cmd->u.cache.DeviceNo = i;
4421 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4423 spin_lock_irqsave(&ha->smp_lock, flags);
4424 ha->hdr[i].devtype = (status == S_OK ? (ushort)info : 0);
4425 spin_unlock_irqrestore(&ha->smp_lock, flags);
4427 cmd->Service = CACHESERVICE;
4428 cmd->OpCode = GDT_CLUST_INFO;
4429 if (ha->cache_feat & GDT_64BIT)
4430 cmd->u.cache64.DeviceNo = i;
4432 cmd->u.cache.DeviceNo = i;
4434 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4436 spin_lock_irqsave(&ha->smp_lock, flags);
4437 ha->hdr[i].cluster_type =
4438 ((status == S_OK && !shared_access) ? (ushort)info : 0);
4439 spin_unlock_irqrestore(&ha->smp_lock, flags);
4440 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
4442 cmd->Service = CACHESERVICE;
4443 cmd->OpCode = GDT_RW_ATTRIBS;
4444 if (ha->cache_feat & GDT_64BIT)
4445 cmd->u.cache64.DeviceNo = i;
4447 cmd->u.cache.DeviceNo = i;
4449 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4451 spin_lock_irqsave(&ha->smp_lock, flags);
4452 ha->hdr[i].rw_attribs = (status == S_OK ? (ushort)info : 0);
4453 spin_unlock_irqrestore(&ha->smp_lock, flags);
4456 if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
4467 static int gdth_ioctl(struct inode *inode, struct file *filep,
4468 unsigned int cmd, unsigned long arg)
4473 char cmnd[MAX_COMMAND_SIZE];
4474 void __user *argp = (void __user *)arg;
4476 memset(cmnd, 0xff, 12);
4478 TRACE(("gdth_ioctl() cmd 0x%x\n", cmd));
4481 case GDTIOCTL_CTRCNT:
4483 int cnt = gdth_ctr_count;
4484 if (put_user(cnt, (int __user *)argp))
4489 case GDTIOCTL_DRVERS:
4491 int ver = (GDTH_VERSION<<8) | GDTH_SUBVERSION;
4492 if (put_user(ver, (int __user *)argp))
4497 case GDTIOCTL_OSVERS:
4499 gdth_ioctl_osvers osv;
4501 osv.version = (unchar)(LINUX_VERSION_CODE >> 16);
4502 osv.subversion = (unchar)(LINUX_VERSION_CODE >> 8);
4503 osv.revision = (ushort)(LINUX_VERSION_CODE & 0xff);
4504 if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers)))
4509 case GDTIOCTL_CTRTYPE:
4511 gdth_ioctl_ctrtype ctrt;
4513 if (copy_from_user(&ctrt, argp, sizeof(gdth_ioctl_ctrtype)) ||
4514 (NULL == (ha = gdth_find_ha(ctrt.ionode))))
4517 if (ha->type == GDT_ISA || ha->type == GDT_EISA) {
4518 ctrt.type = (unchar)((ha->stype>>20) - 0x10);
4520 if (ha->type != GDT_PCIMPR) {
4521 ctrt.type = (unchar)((ha->stype<<4) + 6);
4524 (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe);
4525 if (ha->stype >= 0x300)
4526 ctrt.ext_type = 0x6000 | ha->pdev->subsystem_device;
4528 ctrt.ext_type = 0x6000 | ha->stype;
4530 ctrt.device_id = ha->pdev->device;
4531 ctrt.sub_device_id = ha->pdev->subsystem_device;
4533 ctrt.info = ha->brd_phys;
4534 ctrt.oem_id = ha->oem_id;
4535 if (copy_to_user(argp, &ctrt, sizeof(gdth_ioctl_ctrtype)))
4540 case GDTIOCTL_GENERAL:
4541 return ioc_general(argp, cmnd);
4543 case GDTIOCTL_EVENT:
4544 return ioc_event(argp);
4546 case GDTIOCTL_LOCKDRV:
4547 return ioc_lockdrv(argp);
4549 case GDTIOCTL_LOCKCHN:
4551 gdth_ioctl_lockchn lchn;
4554 if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) ||
4555 (NULL == (ha = gdth_find_ha(lchn.ionode))))
4559 if (i < ha->bus_cnt) {
4561 spin_lock_irqsave(&ha->smp_lock, flags);
4562 ha->raw[i].lock = 1;
4563 spin_unlock_irqrestore(&ha->smp_lock, flags);
4564 for (j = 0; j < ha->tid_cnt; ++j) {
4565 gdth_wait_completion(ha, i, j);
4566 gdth_stop_timeout(ha, i, j);
4569 spin_lock_irqsave(&ha->smp_lock, flags);
4570 ha->raw[i].lock = 0;
4571 spin_unlock_irqrestore(&ha->smp_lock, flags);
4572 for (j = 0; j < ha->tid_cnt; ++j) {
4573 gdth_start_timeout(ha, i, j);
4581 case GDTIOCTL_RESCAN:
4582 return ioc_rescan(argp, cmnd);
4584 case GDTIOCTL_HDRLIST:
4585 return ioc_hdrlist(argp, cmnd);
4587 case GDTIOCTL_RESET_BUS:
4589 gdth_ioctl_reset res;
4592 if (copy_from_user(&res, argp, sizeof(gdth_ioctl_reset)) ||
4593 (NULL == (ha = gdth_find_ha(res.ionode))))
4596 scp = kzalloc(sizeof(*scp), GFP_KERNEL);
4599 scp->device = ha->sdev;
4601 scp->device->channel = res.number;
4602 rval = gdth_eh_bus_reset(scp);
4603 res.status = (rval == SUCCESS ? S_OK : S_GENERR);
4606 if (copy_to_user(argp, &res, sizeof(gdth_ioctl_reset)))
4611 case GDTIOCTL_RESET_DRV:
4612 return ioc_resetdrv(argp, cmnd);
4622 static void gdth_flush(gdth_ha_str *ha)
4625 gdth_cmd_str gdtcmd;
4626 char cmnd[MAX_COMMAND_SIZE];
4627 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
4629 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
4631 for (i = 0; i < MAX_HDRIVES; ++i) {
4632 if (ha->hdr[i].present) {
4633 gdtcmd.BoardNode = LOCALBOARD;
4634 gdtcmd.Service = CACHESERVICE;
4635 gdtcmd.OpCode = GDT_FLUSH;
4636 if (ha->cache_feat & GDT_64BIT) {
4637 gdtcmd.u.cache64.DeviceNo = i;
4638 gdtcmd.u.cache64.BlockNo = 1;
4639 gdtcmd.u.cache64.sg_canz = 0;
4641 gdtcmd.u.cache.DeviceNo = i;
4642 gdtcmd.u.cache.BlockNo = 1;
4643 gdtcmd.u.cache.sg_canz = 0;
4645 TRACE2(("gdth_flush(): flush ha %d drive %d\n", ha->hanum, i));
4647 gdth_execute(ha->shost, &gdtcmd, cmnd, 30, NULL);
4653 static int gdth_slave_configure(struct scsi_device *sdev)
4655 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
4656 sdev->skip_ms_page_3f = 1;
4657 sdev->skip_ms_page_8 = 1;
4661 static struct scsi_host_template gdth_template = {
4662 .name = "GDT SCSI Disk Array Controller",
4664 .queuecommand = gdth_queuecommand,
4665 .eh_bus_reset_handler = gdth_eh_bus_reset,
4666 .slave_configure = gdth_slave_configure,
4667 .bios_param = gdth_bios_param,
4668 .proc_info = gdth_proc_info,
4669 .proc_name = "gdth",
4670 .can_queue = GDTH_MAXCMDS,
4672 .sg_tablesize = GDTH_MAXSG,
4673 .cmd_per_lun = GDTH_MAXC_P_L,
4674 .unchecked_isa_dma = 1,
4675 .use_clustering = ENABLE_CLUSTERING,
4679 static int __init gdth_isa_probe_one(ulong32 isa_bios)
4681 struct Scsi_Host *shp;
4683 dma_addr_t scratch_dma_handle = 0;
4686 if (!gdth_search_isa(isa_bios))
4689 shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str));
4692 ha = shost_priv(shp);
4695 if (!gdth_init_isa(isa_bios,ha))
4698 /* controller found and initialized */
4699 printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
4700 isa_bios, ha->irq, ha->drq);
4702 error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha);
4704 printk("GDT-ISA: Unable to allocate IRQ\n");
4708 error = request_dma(ha->drq, "gdth");
4710 printk("GDT-ISA: Unable to allocate DMA channel\n");
4714 set_dma_mode(ha->drq,DMA_MODE_CASCADE);
4715 enable_dma(ha->drq);
4716 shp->unchecked_isa_dma = 1;
4718 shp->dma_channel = ha->drq;
4720 ha->hanum = gdth_ctr_count++;
4723 ha->pccb = &ha->cmdext;
4729 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4730 &scratch_dma_handle);
4732 goto out_dec_counters;
4733 ha->scratch_phys = scratch_dma_handle;
4735 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4736 &scratch_dma_handle);
4738 goto out_free_pscratch;
4739 ha->msg_phys = scratch_dma_handle;
4742 ha->coal_stat = pci_alloc_consistent(ha->pdev,
4743 sizeof(gdth_coal_status) * MAXOFFSETS,
4744 &scratch_dma_handle);
4747 ha->coal_stat_phys = scratch_dma_handle;
4750 ha->scratch_busy = FALSE;
4751 ha->req_first = NULL;
4752 ha->tid_cnt = MAX_HDRIVES;
4753 if (max_ids > 0 && max_ids < ha->tid_cnt)
4754 ha->tid_cnt = max_ids;
4755 for (i = 0; i < GDTH_MAXCMDS; ++i)
4756 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4757 ha->scan_mode = rescan ? 0x10 : 0;
4760 if (!gdth_search_drives(ha)) {
4761 printk("GDT-ISA: Error during device scan\n");
4762 goto out_free_coal_stat;
4765 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4766 hdr_channel = ha->bus_cnt;
4767 ha->virt_bus = hdr_channel;
4769 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4770 shp->max_cmd_len = 16;
4772 shp->max_id = ha->tid_cnt;
4773 shp->max_lun = MAXLUN;
4774 shp->max_channel = ha->bus_cnt;
4776 spin_lock_init(&ha->smp_lock);
4777 gdth_enable_int(ha);
4779 error = scsi_add_host(shp, NULL);
4781 goto out_free_coal_stat;
4782 list_add_tail(&ha->list, &gdth_instances);
4784 scsi_scan_host(shp);
4790 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
4791 ha->coal_stat, ha->coal_stat_phys);
4794 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4795 ha->pmsg, ha->msg_phys);
4797 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4798 ha->pscratch, ha->scratch_phys);
4802 free_irq(ha->irq, ha);
4807 #endif /* CONFIG_ISA */
4810 static int __init gdth_eisa_probe_one(ushort eisa_slot)
4812 struct Scsi_Host *shp;
4814 dma_addr_t scratch_dma_handle = 0;
4817 if (!gdth_search_eisa(eisa_slot))
4820 shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str));
4823 ha = shost_priv(shp);
4826 if (!gdth_init_eisa(eisa_slot,ha))
4829 /* controller found and initialized */
4830 printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
4831 eisa_slot >> 12, ha->irq);
4833 error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha);
4835 printk("GDT-EISA: Unable to allocate IRQ\n");
4839 shp->unchecked_isa_dma = 0;
4841 shp->dma_channel = 0xff;
4843 ha->hanum = gdth_ctr_count++;
4846 TRACE2(("EISA detect Bus 0: hanum %d\n", ha->hanum));
4848 ha->pccb = &ha->cmdext;
4854 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4855 &scratch_dma_handle);
4858 ha->scratch_phys = scratch_dma_handle;
4860 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4861 &scratch_dma_handle);
4863 goto out_free_pscratch;
4864 ha->msg_phys = scratch_dma_handle;
4867 ha->coal_stat = pci_alloc_consistent(ha->pdev,
4868 sizeof(gdth_coal_status) * MAXOFFSETS,
4869 &scratch_dma_handle);
4872 ha->coal_stat_phys = scratch_dma_handle;
4875 ha->ccb_phys = pci_map_single(ha->pdev,ha->pccb,
4876 sizeof(gdth_cmd_str), PCI_DMA_BIDIRECTIONAL);
4878 goto out_free_coal_stat;
4880 ha->scratch_busy = FALSE;
4881 ha->req_first = NULL;
4882 ha->tid_cnt = MAX_HDRIVES;
4883 if (max_ids > 0 && max_ids < ha->tid_cnt)
4884 ha->tid_cnt = max_ids;
4885 for (i = 0; i < GDTH_MAXCMDS; ++i)
4886 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4887 ha->scan_mode = rescan ? 0x10 : 0;
4889 if (!gdth_search_drives(ha)) {
4890 printk("GDT-EISA: Error during device scan\n");
4892 goto out_free_ccb_phys;
4895 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4896 hdr_channel = ha->bus_cnt;
4897 ha->virt_bus = hdr_channel;
4899 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4900 shp->max_cmd_len = 16;
4902 shp->max_id = ha->tid_cnt;
4903 shp->max_lun = MAXLUN;
4904 shp->max_channel = ha->bus_cnt;
4906 spin_lock_init(&ha->smp_lock);
4907 gdth_enable_int(ha);
4909 error = scsi_add_host(shp, NULL);
4911 goto out_free_coal_stat;
4912 list_add_tail(&ha->list, &gdth_instances);
4914 scsi_scan_host(shp);
4919 pci_unmap_single(ha->pdev,ha->ccb_phys, sizeof(gdth_cmd_str),
4920 PCI_DMA_BIDIRECTIONAL);
4923 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
4924 ha->coal_stat, ha->coal_stat_phys);
4927 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4928 ha->pmsg, ha->msg_phys);
4930 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4931 ha->pscratch, ha->scratch_phys);
4933 free_irq(ha->irq, ha);
4939 #endif /* CONFIG_EISA */
4942 static int gdth_pci_probe_one(gdth_pci_str *pcistr,
4943 gdth_ha_str **ha_out)
4945 struct Scsi_Host *shp;
4947 dma_addr_t scratch_dma_handle = 0;
4949 struct pci_dev *pdev = pcistr->pdev;
4953 shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str));
4956 ha = shost_priv(shp);
4959 if (!gdth_init_pci(pdev, pcistr, ha))
4962 /* controller found and initialized */
4963 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
4965 PCI_SLOT(pdev->devfn),
4968 error = request_irq(ha->irq, gdth_interrupt,
4969 IRQF_DISABLED|IRQF_SHARED, "gdth", ha);
4971 printk("GDT-PCI: Unable to allocate IRQ\n");
4975 shp->unchecked_isa_dma = 0;
4977 shp->dma_channel = 0xff;
4979 ha->hanum = gdth_ctr_count++;
4982 ha->pccb = &ha->cmdext;
4987 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4988 &scratch_dma_handle);
4991 ha->scratch_phys = scratch_dma_handle;
4993 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4994 &scratch_dma_handle);
4996 goto out_free_pscratch;
4997 ha->msg_phys = scratch_dma_handle;
5000 ha->coal_stat = pci_alloc_consistent(ha->pdev,
5001 sizeof(gdth_coal_status) * MAXOFFSETS,
5002 &scratch_dma_handle);
5005 ha->coal_stat_phys = scratch_dma_handle;
5008 ha->scratch_busy = FALSE;
5009 ha->req_first = NULL;
5010 ha->tid_cnt = pdev->device >= 0x200 ? MAXID : MAX_HDRIVES;
5011 if (max_ids > 0 && max_ids < ha->tid_cnt)
5012 ha->tid_cnt = max_ids;
5013 for (i = 0; i < GDTH_MAXCMDS; ++i)
5014 ha->cmd_tab[i].cmnd = UNUSED_CMND;
5015 ha->scan_mode = rescan ? 0x10 : 0;
5018 if (!gdth_search_drives(ha)) {
5019 printk("GDT-PCI %d: Error during device scan\n", ha->hanum);
5020 goto out_free_coal_stat;
5023 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
5024 hdr_channel = ha->bus_cnt;
5025 ha->virt_bus = hdr_channel;
5027 /* 64-bit DMA only supported from FW >= x.43 */
5028 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) ||
5029 !ha->dma64_support) {
5030 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
5031 printk(KERN_WARNING "GDT-PCI %d: "
5032 "Unable to set 32-bit DMA\n", ha->hanum);
5033 goto out_free_coal_stat;
5036 shp->max_cmd_len = 16;
5037 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
5038 printk("GDT-PCI %d: 64-bit DMA enabled\n", ha->hanum);
5039 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
5040 printk(KERN_WARNING "GDT-PCI %d: "
5041 "Unable to set 64/32-bit DMA\n", ha->hanum);
5042 goto out_free_coal_stat;
5046 shp->max_id = ha->tid_cnt;
5047 shp->max_lun = MAXLUN;
5048 shp->max_channel = ha->bus_cnt;
5050 spin_lock_init(&ha->smp_lock);
5051 gdth_enable_int(ha);
5053 error = scsi_add_host(shp, &pdev->dev);
5055 goto out_free_coal_stat;
5056 list_add_tail(&ha->list, &gdth_instances);
5058 pci_set_drvdata(ha->pdev, ha);
5060 scsi_scan_host(shp);
5068 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
5069 ha->coal_stat, ha->coal_stat_phys);
5072 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5073 ha->pmsg, ha->msg_phys);
5075 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5076 ha->pscratch, ha->scratch_phys);
5078 free_irq(ha->irq, ha);
5084 #endif /* CONFIG_PCI */
5086 static void gdth_remove_one(gdth_ha_str *ha)
5088 struct Scsi_Host *shp = ha->shost;
5090 TRACE2(("gdth_remove_one()\n"));
5092 scsi_remove_host(shp);
5097 scsi_free_host_dev(ha->sdev);
5102 free_irq(shp->irq,ha);
5105 if (shp->dma_channel != 0xff)
5106 free_dma(shp->dma_channel);
5110 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
5111 MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys);
5114 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5115 ha->pscratch, ha->scratch_phys);
5117 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5118 ha->pmsg, ha->msg_phys);
5120 pci_unmap_single(ha->pdev,ha->ccb_phys,
5121 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
5126 static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
5130 TRACE2(("gdth_halt() event %d\n", (int)event));
5131 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
5134 list_for_each_entry(ha, &gdth_instances, list)
5140 static struct notifier_block gdth_notifier = {
5144 static int __init gdth_init(void)
5147 printk("GDT-HA: Controller driver disabled from"
5148 " command line !\n");
5152 printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n",
5155 /* initializations */
5156 gdth_polling = TRUE;
5157 gdth_clear_events();
5159 /* As default we do not probe for EISA or ISA controllers */
5160 if (probe_eisa_isa) {
5161 /* scanning for controllers, at first: ISA controller */
5164 for (isa_bios = 0xc8000UL; isa_bios <= 0xd8000UL;
5165 isa_bios += 0x8000UL)
5166 gdth_isa_probe_one(isa_bios);
5171 for (eisa_slot = 0x1000; eisa_slot <= 0x8000;
5172 eisa_slot += 0x1000)
5173 gdth_eisa_probe_one(eisa_slot);
5179 /* scanning for PCI controllers */
5180 if (pci_register_driver(&gdth_pci_driver) == 0)
5181 gdth_pci_registered = true;
5182 #endif /* CONFIG_PCI */
5184 TRACE2(("gdth_detect() %d controller detected\n", gdth_ctr_count));
5186 if (list_empty(&gdth_instances))
5189 #ifdef GDTH_STATISTICS
5190 TRACE2(("gdth_detect(): Initializing timer !\n"));
5191 init_timer(&gdth_timer);
5192 gdth_timer.expires = jiffies + HZ;
5193 gdth_timer.data = 0L;
5194 gdth_timer.function = gdth_timeout;
5195 add_timer(&gdth_timer);
5197 major = register_chrdev(0,"gdth", &gdth_fops);
5198 register_reboot_notifier(&gdth_notifier);
5199 gdth_polling = FALSE;
5203 static void __exit gdth_exit(void)
5207 unregister_chrdev(major, "gdth");
5208 unregister_reboot_notifier(&gdth_notifier);
5210 #ifdef GDTH_STATISTICS
5211 del_timer_sync(&gdth_timer);
5215 if (gdth_pci_registered)
5216 pci_unregister_driver(&gdth_pci_driver);
5219 list_for_each_entry(ha, &gdth_instances, list)
5220 gdth_remove_one(ha);
5223 module_init(gdth_init);
5224 module_exit(gdth_exit);
5227 __setup("gdth=", option_setup);