1 /************************************************************************
3 * ICP vortex GmbH: GDT ISA/EISA/PCI Disk Array Controllers *
4 * Intel Corporation: Storage RAID Controllers *
7 * Copyright (C) 1995-04 ICP vortex GmbH, Achim Leubner *
8 * Copyright (C) 2002-04 Intel Corporation *
9 * Copyright (C) 2003-04 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.2.x, 2.4.x, 2.6.x supported *
33 * Revision 1.73 2004/03/31 13:33:03 achim
34 * Special command 0xfd implemented to detect 64-bit DMA support
36 * Revision 1.72 2004/03/17 08:56:04 achim
37 * 64-bit DMA only enabled if FW >= x.43
39 * Revision 1.71 2004/03/05 15:51:29 achim
40 * Screen service: separate message buffer, bugfixes
42 * Revision 1.70 2004/02/27 12:19:07 achim
43 * Bugfix: Reset bit in config (0xfe) call removed
45 * Revision 1.69 2004/02/20 09:50:24 achim
46 * Compatibility changes for kernels < 2.4.20
47 * Bugfix screen service command size
48 * pci_set_dma_mask() error handling added
50 * Revision 1.68 2004/02/19 15:46:54 achim
52 * Drive size bugfix for drives > 1TB
54 * Revision 1.67 2004/01/14 13:11:57 achim
55 * Tool access over /proc no longer supported
58 * Revision 1.66 2003/12/19 15:04:06 achim
59 * Bugfixes support for drives > 2TB
61 * Revision 1.65 2003/12/15 11:21:56 achim
62 * 64-bit DMA support added
63 * Support for drives > 2 TB implemented
64 * Kernels 2.2.x, 2.4.x, 2.6.x supported
66 * Revision 1.64 2003/09/17 08:30:26 achim
67 * EISA/ISA controller scan disabled
68 * Command line switch probe_eisa_isa added
70 * Revision 1.63 2003/07/12 14:01:00 Daniele Bellucci <bellucda@tiscali.it>
71 * Minor cleanups in gdth_ioctl.
73 * Revision 1.62 2003/02/27 15:01:59 achim
74 * Dynamic DMA mapping implemented
75 * New (character device) IOCTL interface added
76 * Other controller related changes made
78 * Revision 1.61 2002/11/08 13:09:52 boji
79 * Added support for XSCALE based RAID Controllers
80 * Fixed SCREENSERVICE initialization in SMP cases
81 * Added checks for gdth_polling before GDTH_HA_LOCK
83 * Revision 1.60 2002/02/05 09:35:22 achim
84 * MODULE_LICENSE only if kernel >= 2.4.11
86 * Revision 1.59 2002/01/30 09:46:33 achim
89 * Revision 1.58 2002/01/29 15:30:02 achim
90 * Set default value of shared_access to Y
91 * New status S_CACHE_RESERV for clustering added
93 * Revision 1.57 2001/08/21 11:16:35 achim
96 * Revision 1.56 2001/08/09 11:19:39 achim
97 * Scsi_Host_Template changes
99 * Revision 1.55 2001/08/09 10:11:28 achim
100 * Command HOST_UNFREEZE_IO before cache service init.
102 * Revision 1.54 2001/07/20 13:48:12 achim
103 * Expand: gdth_analyse_hdrive() removed
105 * Revision 1.53 2001/07/17 09:52:49 achim
106 * Small OEM related change
108 * Revision 1.52 2001/06/19 15:06:20 achim
109 * New host command GDT_UNFREEZE_IO added
111 * Revision 1.51 2001/05/22 06:42:37 achim
112 * PCI: Subdevice ID added
114 * Revision 1.50 2001/05/17 13:42:16 achim
115 * Support for Intel Storage RAID Controllers added
117 * Revision 1.50 2001/05/17 12:12:34 achim
118 * Support for Intel Storage RAID Controllers added
120 * Revision 1.49 2001/03/15 15:07:17 achim
121 * New __setup interface for boot command line options added
123 * Revision 1.48 2001/02/06 12:36:28 achim
124 * Bugfix Cluster protocol
126 * Revision 1.47 2001/01/10 14:42:06 achim
127 * New switch shared_access added
129 * Revision 1.46 2001/01/09 08:11:35 achim
130 * gdth_command() removed
131 * meaning of Scsi_Pointer members changed
133 * Revision 1.45 2000/11/16 12:02:24 achim
134 * Changes for kernel 2.4
136 * Revision 1.44 2000/10/11 08:44:10 achim
137 * Clustering changes: New flag media_changed added
139 * Revision 1.43 2000/09/20 12:59:01 achim
140 * DPMEM remap functions for all PCI controller types implemented
141 * Small changes for ia64 platform
143 * Revision 1.42 2000/07/20 09:04:50 achim
144 * Small changes for kernel 2.4
146 * Revision 1.41 2000/07/04 14:11:11 achim
147 * gdth_analyse_hdrive() added to rescan drives after online expansion
149 * Revision 1.40 2000/06/27 11:24:16 achim
150 * Changes Clustering, Screenservice
152 * Revision 1.39 2000/06/15 13:09:04 achim
153 * Changes for gdth_do_cmd()
155 * Revision 1.38 2000/06/15 12:08:43 achim
156 * Bugfix gdth_sync_event(), service SCREENSERVICE
157 * Data direction for command 0xc2 changed to DOU
159 * Revision 1.37 2000/05/25 13:50:10 achim
160 * New driver parameter virt_ctr added
162 * Revision 1.36 2000/05/04 08:50:46 achim
163 * Event buffer now in gdth_ha_str
165 * Revision 1.35 2000/03/03 10:44:08 achim
166 * New event_string only valid for the RP controller family
168 * Revision 1.34 2000/03/02 14:55:29 achim
169 * New mechanism for async. event handling implemented
171 * Revision 1.33 2000/02/21 15:37:37 achim
172 * Bugfix Alpha platform + DPMEM above 4GB
174 * Revision 1.32 2000/02/14 16:17:37 achim
175 * Bugfix sense_buffer[] + raw devices
177 * Revision 1.31 2000/02/10 10:29:00 achim
178 * Delete sense_buffer[0], if command OK
180 * Revision 1.30 1999/11/02 13:42:39 achim
181 * ARRAY_DRV_LIST2 implemented
182 * Now 255 log. and 100 host drives supported
184 * Revision 1.29 1999/10/05 13:28:47 achim
185 * GDT_CLUST_RESET added
187 * Revision 1.28 1999/08/12 13:44:54 achim
189 * Cluster drives -> removeable drives
191 * Revision 1.27 1999/06/22 07:22:38 achim
194 * Revision 1.26 1999/06/10 16:09:12 achim
195 * Cluster Host Drive support: Bugfixes
197 * Revision 1.25 1999/06/01 16:03:56 achim
198 * gdth_init_pci(): Manipulate config. space to start RP controller
200 * Revision 1.24 1999/05/26 11:53:06 achim
201 * Cluster Host Drive support added
203 * Revision 1.23 1999/03/26 09:12:31 achim
204 * Default value for hdr_channel set to 0
206 * Revision 1.22 1999/03/22 16:27:16 achim
207 * Bugfix: gdth_store_event() must not be locked with GDTH_LOCK_HA()
209 * Revision 1.21 1999/03/16 13:40:34 achim
210 * Problems with reserved drives solved
211 * gdth_eh_bus_reset() implemented
213 * Revision 1.20 1999/03/10 09:08:13 achim
214 * Bugfix: Corrections in gdth_direction_tab[] made
215 * Bugfix: Increase command timeout (gdth_update_timeout()) NOT in gdth_putq()
217 * Revision 1.19 1999/03/05 14:38:16 achim
218 * Bugfix: Heads/Sectors mapping for reserved devices possibly wrong
219 * -> gdth_eval_mapping() implemented, changes in gdth_bios_param()
220 * INIT_RETRIES set to 100s to avoid DEINIT-Timeout for controllers
221 * with BIOS disabled and memory test set to Intensive
222 * Enhanced /proc support
224 * Revision 1.18 1999/02/24 09:54:33 achim
225 * Command line parameter hdr_channel implemented
226 * Bugfix for EISA controllers + Linux 2.2.x
228 * Revision 1.17 1998/12/17 15:58:11 achim
229 * Command line parameters implemented
230 * Changes for Alpha platforms
231 * PCI controller scan changed
232 * SMP support improved (spin_lock_irqsave(),...)
233 * New async. events, new scan/reserve commands included
235 * Revision 1.16 1998/09/28 16:08:46 achim
236 * GDT_PCIMPR: DPMEM remapping, if required
239 * Revision 1.15 1998/06/03 14:54:06 achim
240 * gdth_delay(), gdth_flush() implemented
241 * Bugfix: gdth_release() changed
243 * Revision 1.14 1998/05/22 10:01:17 achim
244 * mj: pcibios_strerror() removed
245 * Improved SMP support (if version >= 2.1.95)
246 * gdth_halt(): halt_called flag added (if version < 2.1)
248 * Revision 1.13 1998/04/16 09:14:57 achim
249 * Reserve drives (for raw service) implemented
250 * New error handling code enabled
251 * Get controller name from board_info() IOCTL
252 * Final round of PCI device driver patches by Martin Mares
254 * Revision 1.12 1998/03/03 09:32:37 achim
255 * Fibre channel controller support added
257 * Revision 1.11 1998/01/27 16:19:14 achim
259 * add_timer()/del_timer() instead of GDTH_TIMER
260 * scsi_add_timer()/scsi_del_timer() instead of SCSI_TIMER
261 * New error handling included
263 * Revision 1.10 1997/10/31 12:29:57 achim
264 * Read heads/sectors from host drive
266 * Revision 1.9 1997/09/04 10:07:25 achim
267 * IO-mapping with virt_to_bus(), gdth_readb(), gdth_writeb(), ...
268 * register_reboot_notifier() to get a notify on shutown used
270 * Revision 1.8 1997/04/02 12:14:30 achim
271 * Version 1.00 (see gdth.h), tested with kernel 2.0.29
273 * Revision 1.7 1997/03/12 13:33:37 achim
274 * gdth_reset() changed, new async. events
276 * Revision 1.6 1997/03/04 14:01:11 achim
277 * Shutdown routine gdth_halt() implemented
279 * Revision 1.5 1997/02/21 09:08:36 achim
280 * New controller included (RP, RP1, RP2 series)
281 * IOCTL interface implemented
283 * Revision 1.4 1996/07/05 12:48:55 achim
284 * Function gdth_bios_param() implemented
285 * New constant GDTH_MAXC_P_L inserted
286 * GDT_WRITE_THR, GDT_EXT_INFO implemented
287 * Function gdth_reset() changed
289 * Revision 1.3 1996/05/10 09:04:41 achim
290 * Small changes for Linux 1.2.13
292 * Revision 1.2 1996/05/09 12:45:27 achim
293 * Loadable module support implemented
294 * /proc support corrections made
296 * Revision 1.1 1996/04/11 07:35:57 achim
299 ************************************************************************/
301 /* All GDT Disk Array Controllers are fully supported by this driver.
302 * This includes the PCI/EISA/ISA SCSI Disk Array Controllers and the
303 * PCI Fibre Channel Disk Array Controllers. See gdth.h for a complete
304 * list of all controller types.
306 * If you have one or more GDT3000/3020 EISA controllers with
307 * controller BIOS disabled, you have to set the IRQ values with the
308 * command line option "gdth=irq1,irq2,...", where the irq1,irq2,... are
309 * the IRQ values for the EISA controllers.
311 * After the optional list of IRQ values, other possible
312 * command line options are:
313 * disable:Y disable driver
314 * disable:N enable driver
315 * reserve_mode:0 reserve no drives for the raw service
316 * reserve_mode:1 reserve all not init., removable drives
317 * reserve_mode:2 reserve all not init. drives
318 * reserve_list:h,b,t,l,h,b,t,l,... reserve particular drive(s) with
319 * h- controller no., b- channel no.,
320 * t- target ID, l- LUN
321 * reverse_scan:Y reverse scan order for PCI controllers
322 * reverse_scan:N scan PCI controllers like BIOS
323 * max_ids:x x - target ID count per channel (1..MAXID)
324 * rescan:Y rescan all channels/IDs
325 * rescan:N use all devices found until now
326 * virt_ctr:Y map every channel to a virtual controller
327 * virt_ctr:N use multi channel support
328 * hdr_channel:x x - number of virtual bus for host drives
329 * shared_access:Y disable driver reserve/release protocol to
330 * access a shared resource from several nodes,
331 * appropiate controller firmware required
332 * shared_access:N enable driver reserve/release protocol
333 * probe_eisa_isa:Y scan for EISA/ISA controllers
334 * probe_eisa_isa:N do not scan for EISA/ISA controllers
335 * force_dma32:Y use only 32 bit DMA mode
336 * force_dma32:N use 64 bit DMA mode, if supported
338 * The default values are: "gdth=disable:N,reserve_mode:1,reverse_scan:N,
339 * max_ids:127,rescan:N,virt_ctr:N,hdr_channel:0,
340 * shared_access:Y,probe_eisa_isa:N,force_dma32:N".
341 * Here is another example: "gdth=reserve_list:0,1,2,0,0,1,3,0,rescan:Y".
343 * When loading the gdth driver as a module, the same options are available.
344 * You can set the IRQs with "IRQ=...". However, the syntax to specify the
345 * options changes slightly. You must replace all ',' between options
346 * with ' ' and all ':' with '=' and you must use
347 * '1' in place of 'Y' and '0' in place of 'N'.
349 * Default: "modprobe gdth disable=0 reserve_mode=1 reverse_scan=0
350 * max_ids=127 rescan=0 virt_ctr=0 hdr_channel=0 shared_access=0
351 * probe_eisa_isa=0 force_dma32=0"
352 * The other example: "modprobe gdth reserve_list=0,1,2,0,0,1,3,0 rescan=1".
355 /* The meaning of the Scsi_Pointer members in this driver is as follows:
357 * this_residual: Command priority
358 * buffer: phys. DMA sense buffer
359 * dma_handle: phys. DMA buffer (kernel >= 2.4.0)
360 * buffers_residual: Timeout value
361 * Status: Command status (gdth_do_cmd()), DMA mem. mappings
362 * Message: Additional info (gdth_do_cmd()), DMA direction
363 * have_data_in: Flag for gdth_wait_completion()
364 * sent_command: Opcode special command
365 * phase: Service/parameter/return code special command
369 /* interrupt coalescing */
370 /* #define INT_COAL */
373 #define GDTH_STATISTICS
375 #include <linux/module.h>
377 #include <linux/version.h>
378 #include <linux/kernel.h>
379 #include <linux/types.h>
380 #include <linux/pci.h>
381 #include <linux/string.h>
382 #include <linux/ctype.h>
383 #include <linux/ioport.h>
384 #include <linux/delay.h>
385 #include <linux/sched.h>
386 #include <linux/interrupt.h>
387 #include <linux/in.h>
388 #include <linux/proc_fs.h>
389 #include <linux/time.h>
390 #include <linux/timer.h>
392 #include <linux/mc146818rtc.h>
394 #include <linux/reboot.h>
397 #include <asm/system.h>
399 #include <asm/uaccess.h>
400 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
401 #include <linux/spinlock.h>
403 #include <asm/spinlock.h>
405 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
406 #include <linux/blkdev.h>
408 #include <linux/blk.h>
413 #include <scsi/scsi_host.h>
416 static void gdth_delay(int milliseconds);
417 static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs);
418 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
419 static irqreturn_t gdth_interrupt(int irq, void *dev_id, struct pt_regs *regs);
421 static void gdth_interrupt(int irq, void *dev_id, struct pt_regs *regs);
423 static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp);
424 static int gdth_async_event(int hanum);
425 static void gdth_log_event(gdth_evt_data *dvr, char *buffer);
427 static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority);
428 static void gdth_next(int hanum);
429 static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b);
430 static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp);
431 static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
432 ushort idx, gdth_evt_data *evt);
433 static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr);
434 static void gdth_readapp_event(gdth_ha_str *ha, unchar application,
436 static void gdth_clear_events(void);
438 static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
439 char *buffer,ushort count);
440 static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp);
441 static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive);
443 static int gdth_search_eisa(ushort eisa_adr);
444 static int gdth_search_isa(ulong32 bios_adr);
445 static int gdth_search_pci(gdth_pci_str *pcistr);
446 static void gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
447 ushort vendor, ushort dev);
448 static void gdth_sort_pci(gdth_pci_str *pcistr, int cnt);
449 static int gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha);
450 static int gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha);
451 static int gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha);
453 static void gdth_enable_int(int hanum);
454 static int gdth_get_status(unchar *pIStatus,int irq);
455 static int gdth_test_busy(int hanum);
456 static int gdth_get_cmd_index(int hanum);
457 static void gdth_release_event(int hanum);
458 static int gdth_wait(int hanum,int index,ulong32 time);
459 static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
460 ulong64 p2,ulong64 p3);
461 static int gdth_search_drives(int hanum);
462 static int gdth_analyse_hdrive(int hanum, ushort hdrive);
464 static const char *gdth_ctr_name(int hanum);
466 static int gdth_open(struct inode *inode, struct file *filep);
467 static int gdth_close(struct inode *inode, struct file *filep);
468 static int gdth_ioctl(struct inode *inode, struct file *filep,
469 unsigned int cmd, unsigned long arg);
471 static void gdth_flush(int hanum);
472 static int gdth_halt(struct notifier_block *nb, ulong event, void *buf);
475 static unchar DebugState = DEBUG_GDTH;
478 #define MAX_SERBUF 160
479 static void ser_init(void);
480 static void ser_puts(char *str);
481 static void ser_putc(char c);
482 static int ser_printk(const char *fmt, ...);
483 static char strbuf[MAX_SERBUF+1];
485 #define COM_BASE 0x2f8
487 #define COM_BASE 0x3f8
489 static void ser_init()
491 unsigned port=COM_BASE;
495 /* 19200 Baud, if 9600: outb(12,port) */
505 static void ser_puts(char *str)
510 for (ptr=str;*ptr;++ptr)
514 static void ser_putc(char c)
516 unsigned port=COM_BASE;
518 while ((inb(port+5) & 0x20)==0);
522 while ((inb(port+5) & 0x20)==0);
527 static int ser_printk(const char *fmt, ...)
533 i = vsprintf(strbuf,fmt,args);
539 #define TRACE(a) {if (DebugState==1) {ser_printk a;}}
540 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}}
541 #define TRACE3(a) {if (DebugState!=0) {ser_printk a;}}
543 #else /* !__SERIAL__ */
544 #define TRACE(a) {if (DebugState==1) {printk a;}}
545 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {printk a;}}
546 #define TRACE3(a) {if (DebugState!=0) {printk a;}}
555 #ifdef GDTH_STATISTICS
556 static ulong32 max_rq=0, max_index=0, max_sg=0;
558 static ulong32 max_int_coal=0;
560 static ulong32 act_ints=0, act_ios=0, act_stats=0, act_rq=0;
561 static struct timer_list gdth_timer;
564 #define PTR2USHORT(a) (ushort)(ulong)(a)
565 #define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b)
566 #define INDEX_OK(i,t) ((i)<sizeof(t)/sizeof((t)[0]))
568 #define NUMDATA(a) ( (gdth_num_str *)((a)->hostdata))
569 #define HADATA(a) (&((gdth_ext_str *)((a)->hostdata))->haext)
570 #define CMDDATA(a) (&((gdth_ext_str *)((a)->hostdata))->cmdext)
572 #define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b))
574 #define gdth_readb(addr) readb(addr)
575 #define gdth_readw(addr) readw(addr)
576 #define gdth_readl(addr) readl(addr)
577 #define gdth_writeb(b,addr) writeb((b),(addr))
578 #define gdth_writew(b,addr) writew((b),(addr))
579 #define gdth_writel(b,addr) writel((b),(addr))
581 static unchar gdth_drq_tab[4] = {5,6,7,7}; /* DRQ table */
582 static unchar gdth_irq_tab[6] = {0,10,11,12,14,0}; /* IRQ table */
583 static unchar gdth_polling; /* polling if TRUE */
584 static unchar gdth_from_wait = FALSE; /* gdth_wait() */
585 static int wait_index,wait_hanum; /* gdth_wait() */
586 static int gdth_ctr_count = 0; /* controller count */
587 static int gdth_ctr_vcount = 0; /* virt. ctr. count */
588 static int gdth_ctr_released = 0; /* gdth_release() */
589 static struct Scsi_Host *gdth_ctr_tab[MAXHA]; /* controller table */
590 static struct Scsi_Host *gdth_ctr_vtab[MAXHA*MAXBUS]; /* virt. ctr. table */
591 static unchar gdth_write_through = FALSE; /* write through */
592 static gdth_evt_str ebuffer[MAX_EVENTS]; /* event buffer */
597 #define DIN 1 /* IN data direction */
598 #define DOU 2 /* OUT data direction */
599 #define DNO DIN /* no data transfer */
600 #define DUN DIN /* unknown data direction */
601 static unchar gdth_direction_tab[0x100] = {
602 DNO,DNO,DIN,DIN,DOU,DIN,DIN,DOU,DIN,DUN,DOU,DOU,DUN,DUN,DUN,DIN,
603 DNO,DIN,DIN,DOU,DIN,DOU,DNO,DNO,DOU,DNO,DIN,DNO,DIN,DOU,DNO,DUN,
604 DIN,DUN,DIN,DUN,DOU,DIN,DUN,DUN,DIN,DIN,DOU,DNO,DUN,DIN,DOU,DOU,
605 DOU,DOU,DOU,DNO,DIN,DNO,DNO,DIN,DOU,DOU,DOU,DOU,DIN,DOU,DIN,DOU,
606 DOU,DOU,DIN,DIN,DIN,DNO,DUN,DNO,DNO,DNO,DUN,DNO,DOU,DIN,DUN,DUN,
607 DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DIN,DUN,DUN,DUN,DUN,DUN,
608 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
609 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
610 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,
611 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,
612 DUN,DUN,DUN,DUN,DUN,DNO,DNO,DUN,DIN,DNO,DOU,DUN,DNO,DUN,DOU,DOU,
613 DOU,DOU,DOU,DNO,DUN,DIN,DOU,DIN,DIN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
614 DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
615 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
616 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,
617 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN
620 /* __initfunc, __initdata macros */
621 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
622 #define GDTH_INITFUNC(type, func) type __init func
623 #include <linux/init.h>
625 #define GDTH_INITFUNC(type, func) __initfunc(type func)
626 #include <linux/init.h>
629 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
630 #define GDTH_INIT_LOCK_HA(ha) spin_lock_init(&(ha)->smp_lock)
631 #define GDTH_LOCK_HA(ha,flags) spin_lock_irqsave(&(ha)->smp_lock,flags)
632 #define GDTH_UNLOCK_HA(ha,flags) spin_unlock_irqrestore(&(ha)->smp_lock,flags)
634 #define GDTH_LOCK_SCSI_DONE(dev, flags) spin_lock_irqsave(dev->host_lock,flags)
635 #define GDTH_UNLOCK_SCSI_DONE(dev, flags) spin_unlock_irqrestore(dev->host_lock,flags)
638 #define GDTH_INIT_LOCK_HA(ha) spin_lock_init(&(ha)->smp_lock)
639 #define GDTH_LOCK_HA(ha,flags) spin_lock_irqsave(&(ha)->smp_lock,flags)
640 #define GDTH_UNLOCK_HA(ha,flags) spin_unlock_irqrestore(&(ha)->smp_lock,flags)
642 #define GDTH_LOCK_SCSI_DONE(flags) spin_lock_irqsave(&io_request_lock,flags)
643 #define GDTH_UNLOCK_SCSI_DONE(flags) spin_unlock_irqrestore(&io_request_lock,flags)
646 /* LILO and modprobe/insmod parameters */
647 /* IRQ list for GDT3000/3020 EISA controllers */
648 static int irq[MAXHA] __initdata =
649 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
650 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
651 /* disable driver flag */
652 static int disable __initdata = 0;
654 static int reserve_mode = 1;
656 static int reserve_list[MAX_RES_ARGS] =
657 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
658 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
659 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
660 /* scan order for PCI controllers */
661 static int reverse_scan = 0;
662 /* virtual channel for the host drives */
663 static int hdr_channel = 0;
664 /* max. IDs per channel */
665 static int max_ids = MAXID;
667 static int rescan = 0;
668 /* map channels to virtual controllers */
669 static int virt_ctr = 0;
671 static int shared_access = 1;
672 /* enable support for EISA and ISA controllers */
673 static int probe_eisa_isa = 0;
674 /* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */
675 static int force_dma32 = 0;
678 /* parameters for modprobe/insmod */
679 MODULE_PARM(irq, "i");
680 MODULE_PARM(disable, "i");
681 MODULE_PARM(reserve_mode, "i");
682 MODULE_PARM(reserve_list, "4-" __MODULE_STRING(MAX_RES_ARGS) "i");
683 MODULE_PARM(reverse_scan, "i");
684 MODULE_PARM(hdr_channel, "i");
685 MODULE_PARM(max_ids, "i");
686 MODULE_PARM(rescan, "i");
687 MODULE_PARM(virt_ctr, "i");
688 MODULE_PARM(shared_access, "i");
689 MODULE_PARM(probe_eisa_isa, "i");
690 MODULE_PARM(force_dma32, "i");
691 MODULE_AUTHOR("Achim Leubner");
692 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,11)
693 MODULE_LICENSE("GPL");
694 MODULE_VERSION(GDTH_VERSION_STR);
698 /* ioctl interface */
699 static struct file_operations gdth_fops = {
700 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
703 .release = gdth_close,
712 #include <linux/stat.h>
713 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
714 struct proc_dir_entry proc_scsi_gdth = {
715 PROC_SCSI_GDTH, 4, "gdth",
716 S_IFDIR | S_IRUGO | S_IXUGO, 2
720 #include "gdth_proc.h"
721 #include "gdth_proc.c"
723 /* notifier block to get a notify on system shutdown/halt/reboot */
724 static struct notifier_block gdth_notifier = {
729 static void gdth_delay(int milliseconds)
731 if (milliseconds == 0) {
734 mdelay(milliseconds);
738 static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs)
740 *cyls = size /HEADS/SECS;
741 if (*cyls <= MAXCYLS) {
744 } else { /* too high for 64*32 */
745 *cyls = size /MEDHEADS/MEDSECS;
746 if (*cyls <= MAXCYLS) {
749 } else { /* too high for 127*63 */
750 *cyls = size /BIGHEADS/BIGSECS;
757 /* controller search and initialization functions */
759 GDTH_INITFUNC(static int, gdth_search_eisa(ushort eisa_adr))
763 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr));
764 id = inl(eisa_adr+ID0REG);
765 if (id == GDT3A_ID || id == GDT3B_ID) { /* GDT3000A or GDT3000B */
766 if ((inb(eisa_adr+EISAREG) & 8) == 0)
767 return 0; /* not EISA configured */
770 if (id == GDT3_ID) /* GDT3000 */
777 GDTH_INITFUNC(static int, gdth_search_isa(ulong32 bios_adr))
782 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
783 if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) {
784 id = gdth_readl(addr);
786 if (id == GDT2_ID) /* GDT2000 */
793 GDTH_INITFUNC(static int, gdth_search_pci(gdth_pci_str *pcistr))
797 TRACE(("gdth_search_pci()\n"));
800 for (device = 0; device <= PCI_DEVICE_ID_VORTEX_GDT6555; ++device)
801 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
802 for (device = PCI_DEVICE_ID_VORTEX_GDT6x17RP;
803 device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP; ++device)
804 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
805 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
806 PCI_DEVICE_ID_VORTEX_GDTNEWRX);
807 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
808 PCI_DEVICE_ID_VORTEX_GDTNEWRX2);
809 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
810 PCI_DEVICE_ID_INTEL_SRC);
811 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
812 PCI_DEVICE_ID_INTEL_SRC_XSCALE);
816 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
817 /* Vortex only makes RAID controllers.
818 * We do not really want to specify all 550 ids here, so wildcard match.
820 static struct pci_device_id gdthtable[] __devinitdata = {
821 {PCI_VENDOR_ID_VORTEX,PCI_ANY_ID,PCI_ANY_ID, PCI_ANY_ID},
822 {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC,PCI_ANY_ID,PCI_ANY_ID},
823 {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC_XSCALE,PCI_ANY_ID,PCI_ANY_ID},
826 MODULE_DEVICE_TABLE(pci,gdthtable);
829 GDTH_INITFUNC(static void, gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
830 ushort vendor, ushort device))
832 ulong base0, base1, base2;
833 struct pci_dev *pdev;
835 TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
836 *cnt, vendor, device));
838 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
840 while ((pdev = pci_find_device(vendor, device, pdev))
842 if (pci_enable_device(pdev))
846 /* GDT PCI controller found, resources are already in pdev */
847 pcistr[*cnt].pdev = pdev;
848 pcistr[*cnt].vendor_id = vendor;
849 pcistr[*cnt].device_id = device;
850 pcistr[*cnt].subdevice_id = pdev->subsystem_device;
851 pcistr[*cnt].bus = pdev->bus->number;
852 pcistr[*cnt].device_fn = pdev->devfn;
853 pcistr[*cnt].irq = pdev->irq;
854 base0 = pci_resource_flags(pdev, 0);
855 base1 = pci_resource_flags(pdev, 1);
856 base2 = pci_resource_flags(pdev, 2);
857 if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
858 device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
859 if (!(base0 & IORESOURCE_MEM))
861 pcistr[*cnt].dpmem = pci_resource_start(pdev, 0);
862 } else { /* GDT6110, GDT6120, .. */
863 if (!(base0 & IORESOURCE_MEM) ||
864 !(base2 & IORESOURCE_MEM) ||
865 !(base1 & IORESOURCE_IO))
867 pcistr[*cnt].dpmem = pci_resource_start(pdev, 2);
868 pcistr[*cnt].io_mm = pci_resource_start(pdev, 0);
869 pcistr[*cnt].io = pci_resource_start(pdev, 1);
871 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
872 pcistr[*cnt].bus, PCI_SLOT(pcistr[*cnt].device_fn),
873 pcistr[*cnt].irq, pcistr[*cnt].dpmem));
878 while ((pdev = pci_find_device(vendor, device, pdev))
882 /* GDT PCI controller found, resources are already in pdev */
883 pcistr[*cnt].pdev = pdev;
884 pcistr[*cnt].vendor_id = vendor;
885 pcistr[*cnt].device_id = device;
886 pcistr[*cnt].bus = pdev->bus->number;
887 pcistr[*cnt].device_fn = pdev->devfn;
888 pcibios_read_config_word(pcistr[*cnt].bus, pcistr[*cnt].device_fn,
889 PCI_SUBSYSTEM_ID, &pcistr[*cnt].subdevice_id);
890 pcistr[*cnt].irq = pdev->irq;
891 base0 = pdev->base_address[0];
892 base1 = pdev->base_address[1];
893 base2 = pdev->base_address[2];
894 if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
895 device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
896 if ((base0 & PCI_BASE_ADDRESS_SPACE) !=
897 PCI_BASE_ADDRESS_SPACE_MEMORY)
899 pcistr[*cnt].dpmem = base0 & PCI_BASE_ADDRESS_MEM_MASK;
900 } else { /* GDT6110, GDT6120, .. */
901 if ((base0 & PCI_BASE_ADDRESS_SPACE) !=
902 PCI_BASE_ADDRESS_SPACE_MEMORY ||
903 (base2 & PCI_BASE_ADDRESS_SPACE) !=
904 PCI_BASE_ADDRESS_SPACE_MEMORY ||
905 (base1 & PCI_BASE_ADDRESS_SPACE) !=
906 PCI_BASE_ADDRESS_SPACE_IO)
908 pcistr[*cnt].dpmem = base2 & PCI_BASE_ADDRESS_MEM_MASK;
909 pcistr[*cnt].io_mm = base0 & PCI_BASE_ADDRESS_MEM_MASK;
910 pcistr[*cnt].io = base1 & PCI_BASE_ADDRESS_IO_MASK;
912 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
913 pcistr[*cnt].bus, PCI_SLOT(pcistr[*cnt].device_fn),
914 pcistr[*cnt].irq, pcistr[*cnt].dpmem));
921 GDTH_INITFUNC(static void, gdth_sort_pci(gdth_pci_str *pcistr, int cnt))
926 TRACE(("gdth_sort_pci() cnt %d\n",cnt));
932 for (i = 0; i < cnt-1; ++i) {
934 if ((pcistr[i].bus > pcistr[i+1].bus) ||
935 (pcistr[i].bus == pcistr[i+1].bus &&
936 PCI_SLOT(pcistr[i].device_fn) >
937 PCI_SLOT(pcistr[i+1].device_fn))) {
939 pcistr[i] = pcistr[i+1];
944 if ((pcistr[i].bus < pcistr[i+1].bus) ||
945 (pcistr[i].bus == pcistr[i+1].bus &&
946 PCI_SLOT(pcistr[i].device_fn) <
947 PCI_SLOT(pcistr[i+1].device_fn))) {
949 pcistr[i] = pcistr[i+1];
959 GDTH_INITFUNC(static int, gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha))
962 unchar prot_ver,eisacf,i,irq_found;
964 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr));
966 /* disable board interrupts, deinitialize services */
967 outb(0xff,eisa_adr+EDOORREG);
968 outb(0x00,eisa_adr+EDENABREG);
969 outb(0x00,eisa_adr+EINTENABREG);
971 outb(0xff,eisa_adr+LDOORREG);
972 retries = INIT_RETRIES;
974 while (inb(eisa_adr+EDOORREG) != 0xff) {
975 if (--retries == 0) {
976 printk("GDT-EISA: Initialization error (DEINIT failed)\n");
980 TRACE2(("wait for DEINIT: retries=%d\n",retries));
982 prot_ver = inb(eisa_adr+MAILBOXREG);
983 outb(0xff,eisa_adr+EDOORREG);
984 if (prot_ver != PROTOCOL_VERSION) {
985 printk("GDT-EISA: Illegal protocol version\n");
989 ha->brd_phys = (ulong32)eisa_adr >> 12;
991 outl(0,eisa_adr+MAILBOXREG);
992 outl(0,eisa_adr+MAILBOXREG+4);
993 outl(0,eisa_adr+MAILBOXREG+8);
994 outl(0,eisa_adr+MAILBOXREG+12);
997 if ((id = inl(eisa_adr+ID0REG)) == GDT3_ID) {
998 ha->oem_id = OEM_ID_ICP;
1001 outl(1,eisa_adr+MAILBOXREG+8);
1002 outb(0xfe,eisa_adr+LDOORREG);
1003 retries = INIT_RETRIES;
1005 while (inb(eisa_adr+EDOORREG) != 0xfe) {
1006 if (--retries == 0) {
1007 printk("GDT-EISA: Initialization error (get IRQ failed)\n");
1012 ha->irq = inb(eisa_adr+MAILBOXREG);
1013 outb(0xff,eisa_adr+EDOORREG);
1014 TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq));
1015 /* check the result */
1017 TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
1018 for (i = 0, irq_found = FALSE;
1019 i < MAXHA && irq[i] != 0xff; ++i) {
1020 if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) {
1028 printk("GDT-EISA: Can not detect controller IRQ,\n");
1029 printk("Use IRQ setting from command line (IRQ = %d)\n",
1032 printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
1033 printk("the controller BIOS or use command line parameters\n");
1038 eisacf = inb(eisa_adr+EISAREG) & 7;
1039 if (eisacf > 4) /* level triggered */
1041 ha->irq = gdth_irq_tab[eisacf];
1042 ha->oem_id = OEM_ID_ICP;
1043 ha->type = GDT_EISA;
1047 ha->dma64_support = 0;
1052 GDTH_INITFUNC(static int, gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha))
1054 register gdt2_dpram_str __iomem *dp2_ptr;
1056 unchar irq_drq,prot_ver;
1059 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr));
1061 ha->brd = ioremap(bios_adr, sizeof(gdt2_dpram_str));
1062 if (ha->brd == NULL) {
1063 printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
1067 gdth_writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
1068 /* reset interface area */
1069 memset_io(&dp2_ptr->u, 0, sizeof(dp2_ptr->u));
1070 if (gdth_readl(&dp2_ptr->u) != 0) {
1071 printk("GDT-ISA: Initialization error (DPMEM write error)\n");
1076 /* disable board interrupts, read DRQ and IRQ */
1077 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
1078 gdth_writeb(0x00, &dp2_ptr->io.irqen);
1079 gdth_writeb(0x00, &dp2_ptr->u.ic.S_Status);
1080 gdth_writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
1082 irq_drq = gdth_readb(&dp2_ptr->io.rq);
1083 for (i=0; i<3; ++i) {
1084 if ((irq_drq & 1)==0)
1088 ha->drq = gdth_drq_tab[i];
1090 irq_drq = gdth_readb(&dp2_ptr->io.rq) >> 3;
1091 for (i=1; i<5; ++i) {
1092 if ((irq_drq & 1)==0)
1096 ha->irq = gdth_irq_tab[i];
1098 /* deinitialize services */
1099 gdth_writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
1100 gdth_writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
1101 gdth_writeb(0, &dp2_ptr->io.event);
1102 retries = INIT_RETRIES;
1104 while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
1105 if (--retries == 0) {
1106 printk("GDT-ISA: Initialization error (DEINIT failed)\n");
1112 prot_ver = (unchar)gdth_readl(&dp2_ptr->u.ic.S_Info[0]);
1113 gdth_writeb(0, &dp2_ptr->u.ic.Status);
1114 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
1115 if (prot_ver != PROTOCOL_VERSION) {
1116 printk("GDT-ISA: Illegal protocol version\n");
1121 ha->oem_id = OEM_ID_ICP;
1123 ha->ic_all_size = sizeof(dp2_ptr->u);
1125 ha->brd_phys = bios_adr >> 4;
1127 /* special request to controller BIOS */
1128 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
1129 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
1130 gdth_writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
1131 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
1132 gdth_writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
1133 gdth_writeb(0, &dp2_ptr->io.event);
1134 retries = INIT_RETRIES;
1136 while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
1137 if (--retries == 0) {
1138 printk("GDT-ISA: Initialization error\n");
1144 gdth_writeb(0, &dp2_ptr->u.ic.Status);
1145 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
1147 ha->dma64_support = 0;
1152 GDTH_INITFUNC(static int, gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha))
1154 register gdt6_dpram_str __iomem *dp6_ptr;
1155 register gdt6c_dpram_str __iomem *dp6c_ptr;
1156 register gdt6m_dpram_str __iomem *dp6m_ptr;
1160 int i, found = FALSE;
1162 TRACE(("gdth_init_pci()\n"));
1164 if (pcistr->vendor_id == PCI_VENDOR_ID_INTEL)
1165 ha->oem_id = OEM_ID_INTEL;
1167 ha->oem_id = OEM_ID_ICP;
1168 ha->brd_phys = (pcistr->bus << 8) | (pcistr->device_fn & 0xf8);
1169 ha->stype = (ulong32)pcistr->device_id;
1170 ha->subdevice_id = pcistr->subdevice_id;
1171 ha->irq = pcistr->irq;
1172 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1173 ha->pdev = pcistr->pdev;
1176 if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */
1177 TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
1178 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6_dpram_str));
1179 if (ha->brd == NULL) {
1180 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1183 /* check and reset interface area */
1185 gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
1186 if (gdth_readl(&dp6_ptr->u) != DPMEM_MAGIC) {
1187 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1190 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1192 ha->brd = ioremap(i, sizeof(ushort));
1193 if (ha->brd == NULL) {
1194 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1197 if (gdth_readw(ha->brd) != 0xffff) {
1198 TRACE2(("init_pci_old() address 0x%x busy\n", i));
1202 pci_write_config_dword(pcistr->pdev,
1203 PCI_BASE_ADDRESS_0, i);
1204 ha->brd = ioremap(i, sizeof(gdt6_dpram_str));
1205 if (ha->brd == NULL) {
1206 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1210 gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
1211 if (gdth_readl(&dp6_ptr->u) == DPMEM_MAGIC) {
1212 printk("GDT-PCI: Use free address at 0x%x\n", i);
1218 printk("GDT-PCI: No free address found!\n");
1223 memset_io(&dp6_ptr->u, 0, sizeof(dp6_ptr->u));
1224 if (gdth_readl(&dp6_ptr->u) != 0) {
1225 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1230 /* disable board interrupts, deinit services */
1231 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
1232 gdth_writeb(0x00, &dp6_ptr->io.irqen);
1233 gdth_writeb(0x00, &dp6_ptr->u.ic.S_Status);
1234 gdth_writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
1236 gdth_writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
1237 gdth_writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
1238 gdth_writeb(0, &dp6_ptr->io.event);
1239 retries = INIT_RETRIES;
1241 while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
1242 if (--retries == 0) {
1243 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1249 prot_ver = (unchar)gdth_readl(&dp6_ptr->u.ic.S_Info[0]);
1250 gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
1251 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
1252 if (prot_ver != PROTOCOL_VERSION) {
1253 printk("GDT-PCI: Illegal protocol version\n");
1259 ha->ic_all_size = sizeof(dp6_ptr->u);
1261 /* special command to controller BIOS */
1262 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
1263 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
1264 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[2]);
1265 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
1266 gdth_writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
1267 gdth_writeb(0, &dp6_ptr->io.event);
1268 retries = INIT_RETRIES;
1270 while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
1271 if (--retries == 0) {
1272 printk("GDT-PCI: Initialization error\n");
1278 gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
1279 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
1281 ha->dma64_support = 0;
1283 } else if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */
1284 ha->plx = (gdt6c_plx_regs *)pcistr->io;
1285 TRACE2(("init_pci_new() dpmem %lx irq %d\n",
1286 pcistr->dpmem,ha->irq));
1287 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6c_dpram_str));
1288 if (ha->brd == NULL) {
1289 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1293 /* check and reset interface area */
1295 gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
1296 if (gdth_readl(&dp6c_ptr->u) != DPMEM_MAGIC) {
1297 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1300 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1302 ha->brd = ioremap(i, sizeof(ushort));
1303 if (ha->brd == NULL) {
1304 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1307 if (gdth_readw(ha->brd) != 0xffff) {
1308 TRACE2(("init_pci_plx() address 0x%x busy\n", i));
1312 pci_write_config_dword(pcistr->pdev,
1313 PCI_BASE_ADDRESS_2, i);
1314 ha->brd = ioremap(i, sizeof(gdt6c_dpram_str));
1315 if (ha->brd == NULL) {
1316 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1320 gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
1321 if (gdth_readl(&dp6c_ptr->u) == DPMEM_MAGIC) {
1322 printk("GDT-PCI: Use free address at 0x%x\n", i);
1328 printk("GDT-PCI: No free address found!\n");
1333 memset_io(&dp6c_ptr->u, 0, sizeof(dp6c_ptr->u));
1334 if (gdth_readl(&dp6c_ptr->u) != 0) {
1335 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1340 /* disable board interrupts, deinit services */
1341 outb(0x00,PTR2USHORT(&ha->plx->control1));
1342 outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
1344 gdth_writeb(0x00, &dp6c_ptr->u.ic.S_Status);
1345 gdth_writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
1347 gdth_writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
1348 gdth_writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
1350 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1352 retries = INIT_RETRIES;
1354 while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
1355 if (--retries == 0) {
1356 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1362 prot_ver = (unchar)gdth_readl(&dp6c_ptr->u.ic.S_Info[0]);
1363 gdth_writeb(0, &dp6c_ptr->u.ic.Status);
1364 if (prot_ver != PROTOCOL_VERSION) {
1365 printk("GDT-PCI: Illegal protocol version\n");
1370 ha->type = GDT_PCINEW;
1371 ha->ic_all_size = sizeof(dp6c_ptr->u);
1373 /* special command to controller BIOS */
1374 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
1375 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
1376 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[2]);
1377 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
1378 gdth_writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
1380 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1382 retries = INIT_RETRIES;
1384 while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
1385 if (--retries == 0) {
1386 printk("GDT-PCI: Initialization error\n");
1392 gdth_writeb(0, &dp6c_ptr->u.ic.S_Status);
1394 ha->dma64_support = 0;
1397 TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
1398 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6m_dpram_str));
1399 if (ha->brd == NULL) {
1400 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1404 /* manipulate config. space to enable DPMEM, start RP controller */
1405 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1406 pci_read_config_word(pcistr->pdev, PCI_COMMAND, &command);
1408 pci_write_config_word(pcistr->pdev, PCI_COMMAND, command);
1409 if (pci_resource_start(pcistr->pdev, 8) == 1UL)
1410 pci_resource_start(pcistr->pdev, 8) = 0UL;
1412 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS, i);
1414 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS,
1415 pci_resource_start(pcistr->pdev, 8));
1417 pci_read_config_word(pcistr->pdev, PCI_COMMAND, &command);
1419 pci_write_config_word(pcistr->pdev, PCI_COMMAND, command);
1420 if (pcistr->pdev->rom_address == 1UL)
1421 pcistr->pdev->rom_address = 0UL;
1423 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS, i);
1425 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS,
1426 pcistr->pdev->rom_address);
1431 /* Ensure that it is safe to access the non HW portions of DPMEM.
1432 * Aditional check needed for Xscale based RAID controllers */
1433 while( ((int)gdth_readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 )
1436 /* check and reset interface area */
1437 gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
1438 if (gdth_readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
1439 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1442 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1444 ha->brd = ioremap(i, sizeof(ushort));
1445 if (ha->brd == NULL) {
1446 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1449 if (gdth_readw(ha->brd) != 0xffff) {
1450 TRACE2(("init_pci_mpr() address 0x%x busy\n", i));
1454 pci_write_config_dword(pcistr->pdev,
1455 PCI_BASE_ADDRESS_0, i);
1456 ha->brd = ioremap(i, sizeof(gdt6m_dpram_str));
1457 if (ha->brd == NULL) {
1458 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1462 gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
1463 if (gdth_readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
1464 printk("GDT-PCI: Use free address at 0x%x\n", i);
1470 printk("GDT-PCI: No free address found!\n");
1475 memset_io(&dp6m_ptr->u, 0, sizeof(dp6m_ptr->u));
1477 /* disable board interrupts, deinit services */
1478 gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
1479 &dp6m_ptr->i960r.edoor_en_reg);
1480 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1481 gdth_writeb(0x00, &dp6m_ptr->u.ic.S_Status);
1482 gdth_writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
1484 gdth_writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
1485 gdth_writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
1486 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1487 retries = INIT_RETRIES;
1489 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
1490 if (--retries == 0) {
1491 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1497 prot_ver = (unchar)gdth_readl(&dp6m_ptr->u.ic.S_Info[0]);
1498 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1499 if (prot_ver != PROTOCOL_VERSION) {
1500 printk("GDT-PCI: Illegal protocol version\n");
1505 ha->type = GDT_PCIMPR;
1506 ha->ic_all_size = sizeof(dp6m_ptr->u);
1508 /* special command to controller BIOS */
1509 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
1510 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
1511 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[2]);
1512 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
1513 gdth_writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
1514 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1515 retries = INIT_RETRIES;
1517 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
1518 if (--retries == 0) {
1519 printk("GDT-PCI: Initialization error\n");
1525 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1527 /* read FW version to detect 64-bit DMA support */
1528 gdth_writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx);
1529 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1530 retries = INIT_RETRIES;
1532 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) {
1533 if (--retries == 0) {
1534 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1540 prot_ver = (unchar)(gdth_readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
1541 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1542 if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */
1543 ha->dma64_support = 0;
1545 ha->dma64_support = 1;
1552 /* controller protocol functions */
1554 GDTH_INITFUNC(static void, gdth_enable_int(int hanum))
1558 gdt2_dpram_str __iomem *dp2_ptr;
1559 gdt6_dpram_str __iomem *dp6_ptr;
1560 gdt6m_dpram_str __iomem *dp6m_ptr;
1562 TRACE(("gdth_enable_int() hanum %d\n",hanum));
1563 ha = HADATA(gdth_ctr_tab[hanum]);
1564 GDTH_LOCK_HA(ha, flags);
1566 if (ha->type == GDT_EISA) {
1567 outb(0xff, ha->bmic + EDOORREG);
1568 outb(0xff, ha->bmic + EDENABREG);
1569 outb(0x01, ha->bmic + EINTENABREG);
1570 } else if (ha->type == GDT_ISA) {
1572 gdth_writeb(1, &dp2_ptr->io.irqdel);
1573 gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);
1574 gdth_writeb(1, &dp2_ptr->io.irqen);
1575 } else if (ha->type == GDT_PCI) {
1577 gdth_writeb(1, &dp6_ptr->io.irqdel);
1578 gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);
1579 gdth_writeb(1, &dp6_ptr->io.irqen);
1580 } else if (ha->type == GDT_PCINEW) {
1581 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
1582 outb(0x03, PTR2USHORT(&ha->plx->control1));
1583 } else if (ha->type == GDT_PCIMPR) {
1585 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1586 gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
1587 &dp6m_ptr->i960r.edoor_en_reg);
1589 GDTH_UNLOCK_HA(ha, flags);
1593 static int gdth_get_status(unchar *pIStatus,int irq)
1595 register gdth_ha_str *ha;
1598 TRACE(("gdth_get_status() irq %d ctr_count %d\n",
1599 irq,gdth_ctr_count));
1602 for (i=0; i<gdth_ctr_count; ++i) {
1603 ha = HADATA(gdth_ctr_tab[i]);
1604 if (ha->irq != (unchar)irq) /* check IRQ */
1606 if (ha->type == GDT_EISA)
1607 *pIStatus = inb((ushort)ha->bmic + EDOORREG);
1608 else if (ha->type == GDT_ISA)
1610 gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
1611 else if (ha->type == GDT_PCI)
1613 gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
1614 else if (ha->type == GDT_PCINEW)
1615 *pIStatus = inb(PTR2USHORT(&ha->plx->edoor_reg));
1616 else if (ha->type == GDT_PCIMPR)
1618 gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg);
1621 return i; /* board found */
1627 static int gdth_test_busy(int hanum)
1629 register gdth_ha_str *ha;
1630 register int gdtsema0 = 0;
1632 TRACE(("gdth_test_busy() hanum %d\n",hanum));
1634 ha = HADATA(gdth_ctr_tab[hanum]);
1635 if (ha->type == GDT_EISA)
1636 gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
1637 else if (ha->type == GDT_ISA)
1638 gdtsema0 = (int)gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1639 else if (ha->type == GDT_PCI)
1640 gdtsema0 = (int)gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1641 else if (ha->type == GDT_PCINEW)
1642 gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg));
1643 else if (ha->type == GDT_PCIMPR)
1645 (int)gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
1647 return (gdtsema0 & 1);
1651 static int gdth_get_cmd_index(int hanum)
1653 register gdth_ha_str *ha;
1656 TRACE(("gdth_get_cmd_index() hanum %d\n",hanum));
1658 ha = HADATA(gdth_ctr_tab[hanum]);
1659 for (i=0; i<GDTH_MAXCMDS; ++i) {
1660 if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
1661 ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
1662 ha->cmd_tab[i].service = ha->pccb->Service;
1663 ha->pccb->CommandIndex = (ulong32)i+2;
1671 static void gdth_set_sema0(int hanum)
1673 register gdth_ha_str *ha;
1675 TRACE(("gdth_set_sema0() hanum %d\n",hanum));
1677 ha = HADATA(gdth_ctr_tab[hanum]);
1678 if (ha->type == GDT_EISA) {
1679 outb(1, ha->bmic + SEMA0REG);
1680 } else if (ha->type == GDT_ISA) {
1681 gdth_writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1682 } else if (ha->type == GDT_PCI) {
1683 gdth_writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1684 } else if (ha->type == GDT_PCINEW) {
1685 outb(1, PTR2USHORT(&ha->plx->sema0_reg));
1686 } else if (ha->type == GDT_PCIMPR) {
1687 gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
1692 static void gdth_copy_command(int hanum)
1694 register gdth_ha_str *ha;
1695 register gdth_cmd_str *cmd_ptr;
1696 register gdt6m_dpram_str __iomem *dp6m_ptr;
1697 register gdt6c_dpram_str __iomem *dp6c_ptr;
1698 gdt6_dpram_str __iomem *dp6_ptr;
1699 gdt2_dpram_str __iomem *dp2_ptr;
1700 ushort cp_count,dp_offset,cmd_no;
1702 TRACE(("gdth_copy_command() hanum %d\n",hanum));
1704 ha = HADATA(gdth_ctr_tab[hanum]);
1705 cp_count = ha->cmd_len;
1706 dp_offset= ha->cmd_offs_dpmem;
1707 cmd_no = ha->cmd_cnt;
1711 if (ha->type == GDT_EISA)
1712 return; /* no DPMEM, no copy */
1714 /* set cpcount dword aligned */
1716 cp_count += (4 - (cp_count & 3));
1718 ha->cmd_offs_dpmem += cp_count;
1720 /* set offset and service, copy command to DPMEM */
1721 if (ha->type == GDT_ISA) {
1723 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1724 &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
1725 gdth_writew((ushort)cmd_ptr->Service,
1726 &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
1727 memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1728 } else if (ha->type == GDT_PCI) {
1730 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1731 &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
1732 gdth_writew((ushort)cmd_ptr->Service,
1733 &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
1734 memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1735 } else if (ha->type == GDT_PCINEW) {
1737 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1738 &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
1739 gdth_writew((ushort)cmd_ptr->Service,
1740 &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
1741 memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1742 } else if (ha->type == GDT_PCIMPR) {
1744 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1745 &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
1746 gdth_writew((ushort)cmd_ptr->Service,
1747 &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
1748 memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1753 static void gdth_release_event(int hanum)
1755 register gdth_ha_str *ha;
1757 TRACE(("gdth_release_event() hanum %d\n",hanum));
1758 ha = HADATA(gdth_ctr_tab[hanum]);
1760 #ifdef GDTH_STATISTICS
1763 for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
1764 if (ha->cmd_tab[j].cmnd != UNUSED_CMND)
1767 if (max_index < i) {
1769 TRACE3(("GDT: max_index = %d\n",(ushort)i));
1774 if (ha->pccb->OpCode == GDT_INIT)
1775 ha->pccb->Service |= 0x80;
1777 if (ha->type == GDT_EISA) {
1778 if (ha->pccb->OpCode == GDT_INIT) /* store DMA buffer */
1779 outl(ha->ccb_phys, ha->bmic + MAILBOXREG);
1780 outb(ha->pccb->Service, ha->bmic + LDOORREG);
1781 } else if (ha->type == GDT_ISA) {
1782 gdth_writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event);
1783 } else if (ha->type == GDT_PCI) {
1784 gdth_writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event);
1785 } else if (ha->type == GDT_PCINEW) {
1786 outb(1, PTR2USHORT(&ha->plx->ldoor_reg));
1787 } else if (ha->type == GDT_PCIMPR) {
1788 gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg);
1793 static int gdth_wait(int hanum,int index,ulong32 time)
1796 int answer_found = FALSE;
1798 TRACE(("gdth_wait() hanum %d index %d time %d\n",hanum,index,time));
1800 ha = HADATA(gdth_ctr_tab[hanum]);
1802 return 1; /* no wait required */
1804 gdth_from_wait = TRUE;
1806 gdth_interrupt((int)ha->irq,ha,NULL);
1807 if (wait_hanum==hanum && wait_index==index) {
1808 answer_found = TRUE;
1813 gdth_from_wait = FALSE;
1815 while (gdth_test_busy(hanum))
1818 return (answer_found);
1822 static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
1823 ulong64 p2,ulong64 p3)
1825 register gdth_ha_str *ha;
1826 register gdth_cmd_str *cmd_ptr;
1829 TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode));
1831 ha = HADATA(gdth_ctr_tab[hanum]);
1833 memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str));
1836 for (retries = INIT_RETRIES;;) {
1837 cmd_ptr->Service = service;
1838 cmd_ptr->RequestBuffer = INTERNAL_CMND;
1839 if (!(index=gdth_get_cmd_index(hanum))) {
1840 TRACE(("GDT: No free command index found\n"));
1843 gdth_set_sema0(hanum);
1844 cmd_ptr->OpCode = opcode;
1845 cmd_ptr->BoardNode = LOCALBOARD;
1846 if (service == CACHESERVICE) {
1847 if (opcode == GDT_IOCTL) {
1848 cmd_ptr->u.ioctl.subfunc = p1;
1849 cmd_ptr->u.ioctl.channel = (ulong32)p2;
1850 cmd_ptr->u.ioctl.param_size = (ushort)p3;
1851 cmd_ptr->u.ioctl.p_param = ha->scratch_phys;
1853 if (ha->cache_feat & GDT_64BIT) {
1854 cmd_ptr->u.cache64.DeviceNo = (ushort)p1;
1855 cmd_ptr->u.cache64.BlockNo = p2;
1857 cmd_ptr->u.cache.DeviceNo = (ushort)p1;
1858 cmd_ptr->u.cache.BlockNo = (ulong32)p2;
1861 } else if (service == SCSIRAWSERVICE) {
1862 if (ha->raw_feat & GDT_64BIT) {
1863 cmd_ptr->u.raw64.direction = p1;
1864 cmd_ptr->u.raw64.bus = (unchar)p2;
1865 cmd_ptr->u.raw64.target = (unchar)p3;
1866 cmd_ptr->u.raw64.lun = (unchar)(p3 >> 8);
1868 cmd_ptr->u.raw.direction = p1;
1869 cmd_ptr->u.raw.bus = (unchar)p2;
1870 cmd_ptr->u.raw.target = (unchar)p3;
1871 cmd_ptr->u.raw.lun = (unchar)(p3 >> 8);
1873 } else if (service == SCREENSERVICE) {
1874 if (opcode == GDT_REALTIME) {
1875 *(ulong32 *)&cmd_ptr->u.screen.su.data[0] = p1;
1876 *(ulong32 *)&cmd_ptr->u.screen.su.data[4] = (ulong32)p2;
1877 *(ulong32 *)&cmd_ptr->u.screen.su.data[8] = (ulong32)p3;
1880 ha->cmd_len = sizeof(gdth_cmd_str);
1881 ha->cmd_offs_dpmem = 0;
1883 gdth_copy_command(hanum);
1884 gdth_release_event(hanum);
1886 if (!gdth_wait(hanum,index,INIT_TIMEOUT)) {
1887 printk("GDT: Initialization error (timeout service %d)\n",service);
1890 if (ha->status != S_BSY || --retries == 0)
1895 return (ha->status != S_OK ? 0:1);
1899 /* search for devices */
1901 GDTH_INITFUNC(static int, gdth_search_drives(int hanum))
1903 register gdth_ha_str *ha;
1906 ulong32 bus_no, drv_cnt, drv_no, j;
1907 gdth_getch_str *chn;
1908 gdth_drlist_str *drl;
1909 gdth_iochan_str *ioc;
1910 gdth_raw_iochan_str *iocr;
1911 gdth_arcdl_str *alst;
1912 gdth_alist_str *alst2;
1913 gdth_oem_str_ioctl *oemstr;
1915 gdth_perf_modes *pmod;
1923 TRACE(("gdth_search_drives() hanum %d\n",hanum));
1924 ha = HADATA(gdth_ctr_tab[hanum]);
1927 /* initialize controller services, at first: screen service */
1928 ha->screen_feat = 0;
1930 ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_X_INIT_SCR,0,0,0);
1932 ha->screen_feat = GDT_64BIT;
1934 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1935 ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_INIT,0,0,0);
1937 printk("GDT-HA %d: Initialization error screen service (code %d)\n",
1941 TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n"));
1944 /* read realtime clock info, send to controller */
1945 /* 1. wait for the falling edge of update flag */
1946 spin_lock_irqsave(&rtc_lock, flags);
1947 for (j = 0; j < 1000000; ++j)
1948 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
1950 for (j = 0; j < 1000000; ++j)
1951 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
1955 for (j = 0; j < 12; ++j)
1956 rtc[j] = CMOS_READ(j);
1957 } while (rtc[0] != CMOS_READ(0));
1958 spin_lock_irqrestore(&rtc_lock, flags);
1959 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32 *)&rtc[0],
1960 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]));
1961 /* 3. send to controller firmware */
1962 gdth_internal_cmd(hanum,SCREENSERVICE,GDT_REALTIME, *(ulong32 *)&rtc[0],
1963 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]);
1966 /* unfreeze all IOs */
1967 gdth_internal_cmd(hanum,CACHESERVICE,GDT_UNFREEZE_IO,0,0,0);
1969 /* initialize cache service */
1972 ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INIT_HOST,LINUX_OS,0,0);
1974 ha->cache_feat = GDT_64BIT;
1976 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1977 ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_INIT,LINUX_OS,0,0);
1979 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1983 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
1984 cdev_cnt = (ushort)ha->info;
1985 ha->fw_vers = ha->service;
1988 if (ha->type == GDT_PCIMPR) {
1989 /* set perf. modes */
1990 pmod = (gdth_perf_modes *)ha->pscratch;
1992 pmod->st_mode = 1; /* enable one status buffer */
1993 *((ulong64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys;
1994 pmod->st_buff_indx1 = COALINDEX;
1995 pmod->st_buff_addr2 = 0;
1996 pmod->st_buff_u_addr2 = 0;
1997 pmod->st_buff_indx2 = 0;
1998 pmod->st_buff_size = sizeof(gdth_coal_status) * MAXOFFSETS;
1999 pmod->cmd_mode = 0; // disable all cmd buffers
2000 pmod->cmd_buff_addr1 = 0;
2001 pmod->cmd_buff_u_addr1 = 0;
2002 pmod->cmd_buff_indx1 = 0;
2003 pmod->cmd_buff_addr2 = 0;
2004 pmod->cmd_buff_u_addr2 = 0;
2005 pmod->cmd_buff_indx2 = 0;
2006 pmod->cmd_buff_size = 0;
2007 pmod->reserved1 = 0;
2008 pmod->reserved2 = 0;
2009 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,SET_PERF_MODES,
2010 INVALID_CHANNEL,sizeof(gdth_perf_modes))) {
2011 printk("GDT-HA %d: Interrupt coalescing activated\n", hanum);
2016 /* detect number of buses - try new IOCTL */
2017 iocr = (gdth_raw_iochan_str *)ha->pscratch;
2018 iocr->hdr.version = 0xffffffff;
2019 iocr->hdr.list_entries = MAXBUS;
2020 iocr->hdr.first_chan = 0;
2021 iocr->hdr.last_chan = MAXBUS-1;
2022 iocr->hdr.list_offset = GDTOFFSOF(gdth_raw_iochan_str, list[0]);
2023 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_RAW_DESC,
2024 INVALID_CHANNEL,sizeof(gdth_raw_iochan_str))) {
2025 TRACE2(("IOCHAN_RAW_DESC supported!\n"));
2026 ha->bus_cnt = iocr->hdr.chan_count;
2027 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
2028 if (iocr->list[bus_no].proc_id < MAXID)
2029 ha->bus_id[bus_no] = iocr->list[bus_no].proc_id;
2031 ha->bus_id[bus_no] = 0xff;
2035 chn = (gdth_getch_str *)ha->pscratch;
2036 for (bus_no = 0; bus_no < MAXBUS; ++bus_no) {
2037 chn->channel_no = bus_no;
2038 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2039 SCSI_CHAN_CNT | L_CTRL_PATTERN,
2040 IO_CHANNEL | INVALID_CHANNEL,
2041 sizeof(gdth_getch_str))) {
2043 printk("GDT-HA %d: Error detecting channel count (0x%x)\n",
2049 if (chn->siop_id < MAXID)
2050 ha->bus_id[bus_no] = chn->siop_id;
2052 ha->bus_id[bus_no] = 0xff;
2054 ha->bus_cnt = (unchar)bus_no;
2056 TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt));
2058 /* read cache configuration */
2059 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_INFO,
2060 INVALID_CHANNEL,sizeof(gdth_cinfo_str))) {
2061 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
2065 ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar;
2066 TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
2067 ha->cpar.version,ha->cpar.state,ha->cpar.strategy,
2068 ha->cpar.write_back,ha->cpar.block_size));
2070 /* read board info and features */
2071 ha->more_proc = FALSE;
2072 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_INFO,
2073 INVALID_CHANNEL,sizeof(gdth_binfo_str))) {
2074 memcpy(&ha->binfo, (gdth_binfo_str *)ha->pscratch,
2075 sizeof(gdth_binfo_str));
2076 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_FEATURES,
2077 INVALID_CHANNEL,sizeof(gdth_bfeat_str))) {
2078 TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n"));
2079 ha->bfeat = *(gdth_bfeat_str *)ha->pscratch;
2080 ha->more_proc = TRUE;
2083 TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n"));
2084 strcpy(ha->binfo.type_string, gdth_ctr_name(hanum));
2086 TRACE2(("Controller name: %s\n",ha->binfo.type_string));
2088 /* read more informations */
2089 if (ha->more_proc) {
2090 /* physical drives, channel addresses */
2091 ioc = (gdth_iochan_str *)ha->pscratch;
2092 ioc->hdr.version = 0xffffffff;
2093 ioc->hdr.list_entries = MAXBUS;
2094 ioc->hdr.first_chan = 0;
2095 ioc->hdr.last_chan = MAXBUS-1;
2096 ioc->hdr.list_offset = GDTOFFSOF(gdth_iochan_str, list[0]);
2097 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_DESC,
2098 INVALID_CHANNEL,sizeof(gdth_iochan_str))) {
2099 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
2100 ha->raw[bus_no].address = ioc->list[bus_no].address;
2101 ha->raw[bus_no].local_no = ioc->list[bus_no].local_no;
2104 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
2105 ha->raw[bus_no].address = IO_CHANNEL;
2106 ha->raw[bus_no].local_no = bus_no;
2109 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
2110 chn = (gdth_getch_str *)ha->pscratch;
2111 chn->channel_no = ha->raw[bus_no].local_no;
2112 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2113 SCSI_CHAN_CNT | L_CTRL_PATTERN,
2114 ha->raw[bus_no].address | INVALID_CHANNEL,
2115 sizeof(gdth_getch_str))) {
2116 ha->raw[bus_no].pdev_cnt = chn->drive_cnt;
2117 TRACE2(("Channel %d: %d phys. drives\n",
2118 bus_no,chn->drive_cnt));
2120 if (ha->raw[bus_no].pdev_cnt > 0) {
2121 drl = (gdth_drlist_str *)ha->pscratch;
2122 drl->sc_no = ha->raw[bus_no].local_no;
2123 drl->sc_cnt = ha->raw[bus_no].pdev_cnt;
2124 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2125 SCSI_DR_LIST | L_CTRL_PATTERN,
2126 ha->raw[bus_no].address | INVALID_CHANNEL,
2127 sizeof(gdth_drlist_str))) {
2128 for (j = 0; j < ha->raw[bus_no].pdev_cnt; ++j)
2129 ha->raw[bus_no].id_list[j] = drl->sc_list[j];
2131 ha->raw[bus_no].pdev_cnt = 0;
2136 /* logical drives */
2137 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_CNT,
2138 INVALID_CHANNEL,sizeof(ulong32))) {
2139 drv_cnt = *(ulong32 *)ha->pscratch;
2140 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_LIST,
2141 INVALID_CHANNEL,drv_cnt * sizeof(ulong32))) {
2142 for (j = 0; j < drv_cnt; ++j) {
2143 drv_no = ((ulong32 *)ha->pscratch)[j];
2144 if (drv_no < MAX_LDRIVES) {
2145 ha->hdr[drv_no].is_logdrv = TRUE;
2146 TRACE2(("Drive %d is log. drive\n",drv_no));
2150 alst = (gdth_arcdl_str *)ha->pscratch;
2151 alst->entries_avail = MAX_LDRIVES;
2152 alst->first_entry = 0;
2153 alst->list_offset = GDTOFFSOF(gdth_arcdl_str, list[0]);
2154 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2155 ARRAY_DRV_LIST2 | LA_CTRL_PATTERN,
2156 INVALID_CHANNEL, sizeof(gdth_arcdl_str) +
2157 (alst->entries_avail-1) * sizeof(gdth_alist_str))) {
2158 for (j = 0; j < alst->entries_init; ++j) {
2159 ha->hdr[j].is_arraydrv = alst->list[j].is_arrayd;
2160 ha->hdr[j].is_master = alst->list[j].is_master;
2161 ha->hdr[j].is_parity = alst->list[j].is_parity;
2162 ha->hdr[j].is_hotfix = alst->list[j].is_hotfix;
2163 ha->hdr[j].master_no = alst->list[j].cd_handle;
2165 } else if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2166 ARRAY_DRV_LIST | LA_CTRL_PATTERN,
2167 0, 35 * sizeof(gdth_alist_str))) {
2168 for (j = 0; j < 35; ++j) {
2169 alst2 = &((gdth_alist_str *)ha->pscratch)[j];
2170 ha->hdr[j].is_arraydrv = alst2->is_arrayd;
2171 ha->hdr[j].is_master = alst2->is_master;
2172 ha->hdr[j].is_parity = alst2->is_parity;
2173 ha->hdr[j].is_hotfix = alst2->is_hotfix;
2174 ha->hdr[j].master_no = alst2->cd_handle;
2180 /* initialize raw service */
2183 ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_X_INIT_RAW,0,0,0);
2185 ha->raw_feat = GDT_64BIT;
2187 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
2188 ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_INIT,0,0,0);
2190 printk("GDT-HA %d: Initialization error raw service (code %d)\n",
2194 TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n"));
2196 /* set/get features raw service (scatter/gather) */
2197 if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_SET_FEAT,SCATTER_GATHER,
2199 TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
2200 if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_GET_FEAT,0,0,0)) {
2201 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
2203 ha->raw_feat |= (ushort)ha->info;
2207 /* set/get features cache service (equal to raw service) */
2208 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_SET_FEAT,0,
2209 SCATTER_GATHER,0)) {
2210 TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
2211 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_GET_FEAT,0,0,0)) {
2212 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
2214 ha->cache_feat |= (ushort)ha->info;
2218 /* reserve drives for raw service */
2219 if (reserve_mode != 0) {
2220 gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE_ALL,
2221 reserve_mode == 1 ? 1 : 3, 0, 0);
2222 TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n",
2225 for (i = 0; i < MAX_RES_ARGS; i += 4) {
2226 if (reserve_list[i] == hanum && reserve_list[i+1] < ha->bus_cnt &&
2227 reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) {
2228 TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
2229 reserve_list[i], reserve_list[i+1],
2230 reserve_list[i+2], reserve_list[i+3]));
2231 if (!gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE,0,
2232 reserve_list[i+1], reserve_list[i+2] |
2233 (reserve_list[i+3] << 8))) {
2234 printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n",
2240 /* Determine OEM string using IOCTL */
2241 oemstr = (gdth_oem_str_ioctl *)ha->pscratch;
2242 oemstr->params.ctl_version = 0x01;
2243 oemstr->params.buffer_size = sizeof(oemstr->text);
2244 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2245 CACHE_READ_OEM_STRING_RECORD,INVALID_CHANNEL,
2246 sizeof(gdth_oem_str_ioctl))) {
2247 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n"));
2248 printk("GDT-HA %d: Vendor: %s Name: %s\n",
2249 hanum,oemstr->text.oem_company_name,ha->binfo.type_string);
2250 /* Save the Host Drive inquiry data */
2251 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2252 strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,
2253 sizeof(ha->oem_name));
2255 strncpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,7);
2256 ha->oem_name[7] = '\0';
2259 /* Old method, based on PCI ID */
2260 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
2261 printk("GDT-HA %d: Name: %s\n",
2262 hanum,ha->binfo.type_string);
2263 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2264 if (ha->oem_id == OEM_ID_INTEL)
2265 strlcpy(ha->oem_name,"Intel ", sizeof(ha->oem_name));
2267 strlcpy(ha->oem_name,"ICP ", sizeof(ha->oem_name));
2269 if (ha->oem_id == OEM_ID_INTEL)
2270 strcpy(ha->oem_name,"Intel ");
2272 strcpy(ha->oem_name,"ICP ");
2276 /* scanning for host drives */
2277 for (i = 0; i < cdev_cnt; ++i)
2278 gdth_analyse_hdrive(hanum,i);
2280 TRACE(("gdth_search_drives() OK\n"));
2284 static int gdth_analyse_hdrive(int hanum,ushort hdrive)
2286 register gdth_ha_str *ha;
2288 int drv_hds, drv_secs;
2290 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n",hanum,hdrive));
2291 if (hdrive >= MAX_HDRIVES)
2293 ha = HADATA(gdth_ctr_tab[hanum]);
2295 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_INFO,hdrive,0,0))
2297 ha->hdr[hdrive].present = TRUE;
2298 ha->hdr[hdrive].size = ha->info;
2300 /* evaluate mapping (sectors per head, heads per cylinder) */
2301 ha->hdr[hdrive].size &= ~SECS32;
2302 if (ha->info2 == 0) {
2303 gdth_eval_mapping(ha->hdr[hdrive].size,&drv_cyls,&drv_hds,&drv_secs);
2305 drv_hds = ha->info2 & 0xff;
2306 drv_secs = (ha->info2 >> 8) & 0xff;
2307 drv_cyls = (ulong32)ha->hdr[hdrive].size / drv_hds / drv_secs;
2309 ha->hdr[hdrive].heads = (unchar)drv_hds;
2310 ha->hdr[hdrive].secs = (unchar)drv_secs;
2312 ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs;
2314 if (ha->cache_feat & GDT_64BIT) {
2315 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INFO,hdrive,0,0)
2316 && ha->info2 != 0) {
2317 ha->hdr[hdrive].size = ((ulong64)ha->info2 << 32) | ha->info;
2320 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
2321 hdrive,ha->hdr[hdrive].size,drv_hds,drv_secs));
2323 /* get informations about device */
2324 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_DEVTYPE,hdrive,0,0)) {
2325 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
2327 ha->hdr[hdrive].devtype = (ushort)ha->info;
2331 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_CLUST_INFO,hdrive,0,0)) {
2332 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
2335 ha->hdr[hdrive].cluster_type = (unchar)ha->info;
2338 /* R/W attributes */
2339 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_RW_ATTRIBS,hdrive,0,0)) {
2340 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
2342 ha->hdr[hdrive].rw_attribs = (unchar)ha->info;
2349 /* command queueing/sending functions */
2351 static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority)
2353 register gdth_ha_str *ha;
2354 register Scsi_Cmnd *pscp;
2355 register Scsi_Cmnd *nscp;
2359 TRACE(("gdth_putq() priority %d\n",priority));
2360 ha = HADATA(gdth_ctr_tab[hanum]);
2361 GDTH_LOCK_HA(ha, flags);
2363 scp->SCp.this_residual = (int)priority;
2364 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2365 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
2366 t = scp->device->id;
2368 b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
2371 if (priority >= DEFAULT_PRI) {
2372 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2373 (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock)) {
2374 TRACE2(("gdth_putq(): locked IO -> update_timeout()\n"));
2375 scp->SCp.buffers_residual = gdth_update_timeout(hanum, scp, 0);
2379 if (ha->req_first==NULL) {
2380 ha->req_first = scp; /* queue was empty */
2381 scp->SCp.ptr = NULL;
2382 } else { /* queue not empty */
2383 pscp = ha->req_first;
2384 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2385 /* priority: 0-highest,..,0xff-lowest */
2386 while (nscp && (unchar)nscp->SCp.this_residual <= priority) {
2388 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2390 pscp->SCp.ptr = (char *)scp;
2391 scp->SCp.ptr = (char *)nscp;
2393 GDTH_UNLOCK_HA(ha, flags);
2395 #ifdef GDTH_STATISTICS
2397 for (nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
2399 if (max_rq < flags) {
2401 TRACE3(("GDT: max_rq = %d\n",(ushort)max_rq));
2406 static void gdth_next(int hanum)
2408 register gdth_ha_str *ha;
2409 register Scsi_Cmnd *pscp;
2410 register Scsi_Cmnd *nscp;
2411 unchar b, t, l, firsttime;
2412 unchar this_cmd, next_cmd;
2416 TRACE(("gdth_next() hanum %d\n",hanum));
2417 ha = HADATA(gdth_ctr_tab[hanum]);
2419 GDTH_LOCK_HA(ha, flags);
2421 ha->cmd_cnt = ha->cmd_offs_dpmem = 0;
2422 this_cmd = firsttime = TRUE;
2423 next_cmd = gdth_polling ? FALSE:TRUE;
2426 for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) {
2427 if (nscp != pscp && nscp != (Scsi_Cmnd *)pscp->SCp.ptr)
2428 pscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2429 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2430 b = virt_ctr ? NUMDATA(nscp->device->host)->busnum : nscp->device->channel;
2431 t = nscp->device->id;
2432 l = nscp->device->lun;
2434 b = virt_ctr ? NUMDATA(nscp->host)->busnum : nscp->channel;
2438 if (nscp->SCp.this_residual >= DEFAULT_PRI) {
2439 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2440 (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock))
2445 if (gdth_test_busy(hanum)) { /* controller busy ? */
2446 TRACE(("gdth_next() controller %d busy !\n",hanum));
2447 if (!gdth_polling) {
2448 GDTH_UNLOCK_HA(ha, flags);
2451 while (gdth_test_busy(hanum))
2457 if (nscp->done != gdth_scsi_done || nscp->cmnd[0] != 0xff) {
2458 if (nscp->SCp.phase == -1) {
2459 nscp->SCp.phase = CACHESERVICE; /* default: cache svc. */
2460 if (nscp->cmnd[0] == TEST_UNIT_READY) {
2461 TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
2463 /* TEST_UNIT_READY -> set scan mode */
2464 if ((ha->scan_mode & 0x0f) == 0) {
2465 if (b == 0 && t == 0 && l == 0) {
2467 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2469 } else if ((ha->scan_mode & 0x0f) == 1) {
2470 if (b == 0 && ((t == 0 && l == 1) ||
2471 (t == 1 && l == 0))) {
2472 nscp->SCp.sent_command = GDT_SCAN_START;
2473 nscp->SCp.phase = ((ha->scan_mode & 0x10 ? 1:0) << 8)
2475 ha->scan_mode = 0x12;
2476 TRACE2(("Scan mode: 0x%x (SCAN_START)\n",
2479 ha->scan_mode &= 0x10;
2480 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2482 } else if (ha->scan_mode == 0x12) {
2483 if (b == ha->bus_cnt && t == ha->tid_cnt-1) {
2484 nscp->SCp.phase = SCSIRAWSERVICE;
2485 nscp->SCp.sent_command = GDT_SCAN_END;
2486 ha->scan_mode &= 0x10;
2487 TRACE2(("Scan mode: 0x%x (SCAN_END)\n",
2492 if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY &&
2493 nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE &&
2494 (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) {
2495 /* always GDT_CLUST_INFO! */
2496 nscp->SCp.sent_command = GDT_CLUST_INFO;
2501 if (nscp->SCp.sent_command != -1) {
2502 if ((nscp->SCp.phase & 0xff) == CACHESERVICE) {
2503 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2506 } else if ((nscp->SCp.phase & 0xff) == SCSIRAWSERVICE) {
2507 if (!(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
2511 memset((char*)nscp->sense_buffer,0,16);
2512 nscp->sense_buffer[0] = 0x70;
2513 nscp->sense_buffer[2] = NOT_READY;
2514 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2515 if (!nscp->SCp.have_data_in)
2516 nscp->SCp.have_data_in++;
2519 GDTH_UNLOCK_HA(ha,flags);
2520 /* io_request_lock already active ! */
2521 nscp->scsi_done(nscp);
2523 GDTH_LOCK_HA(ha,flags);
2526 } else if (nscp->done == gdth_scsi_done && nscp->cmnd[0] == 0xff) {
2527 if (!(cmd_index=gdth_special_cmd(hanum,nscp)))
2530 } else if (b != ha->virt_bus) {
2531 if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW ||
2532 !(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
2535 ha->raw[BUS_L2P(ha,b)].io_cnt[t]++;
2536 } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || l != 0) {
2537 TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
2538 nscp->cmnd[0], b, t, l));
2539 nscp->result = DID_BAD_TARGET << 16;
2540 if (!nscp->SCp.have_data_in)
2541 nscp->SCp.have_data_in++;
2544 GDTH_UNLOCK_HA(ha,flags);
2545 /* io_request_lock already active ! */
2546 nscp->scsi_done(nscp);
2548 GDTH_LOCK_HA(ha,flags);
2551 switch (nscp->cmnd[0]) {
2552 case TEST_UNIT_READY:
2559 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2560 case SERVICE_ACTION_IN:
2562 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2563 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2564 nscp->cmnd[4],nscp->cmnd[5]));
2565 if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) {
2566 /* return UNIT_ATTENTION */
2567 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2569 ha->hdr[t].media_changed = FALSE;
2570 memset((char*)nscp->sense_buffer,0,16);
2571 nscp->sense_buffer[0] = 0x70;
2572 nscp->sense_buffer[2] = UNIT_ATTENTION;
2573 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2574 if (!nscp->SCp.have_data_in)
2575 nscp->SCp.have_data_in++;
2578 GDTH_UNLOCK_HA(ha,flags);
2579 /* io_request_lock already active ! */
2580 nscp->scsi_done(nscp);
2582 GDTH_LOCK_HA(ha,flags);
2584 } else if (gdth_internal_cache_cmd(hanum,nscp)) {
2586 GDTH_UNLOCK_HA(ha,flags);
2587 /* io_request_lock already active ! */
2588 nscp->scsi_done(nscp);
2590 GDTH_LOCK_HA(ha,flags);
2594 case ALLOW_MEDIUM_REMOVAL:
2595 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2596 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2597 nscp->cmnd[4],nscp->cmnd[5]));
2598 if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) {
2599 TRACE(("Prevent r. nonremov. drive->do nothing\n"));
2600 nscp->result = DID_OK << 16;
2601 nscp->sense_buffer[0] = 0;
2602 if (!nscp->SCp.have_data_in)
2603 nscp->SCp.have_data_in++;
2606 GDTH_UNLOCK_HA(ha,flags);
2607 /* io_request_lock already active ! */
2608 nscp->scsi_done(nscp);
2610 GDTH_LOCK_HA(ha,flags);
2613 nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0;
2614 TRACE(("Prevent/allow r. %d rem. drive %d\n",
2615 nscp->cmnd[4],nscp->cmnd[3]));
2616 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2623 TRACE2(("cache cmd %s\n",nscp->cmnd[0] == RESERVE ?
2624 "RESERVE" : "RELEASE"));
2625 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2633 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2637 if (ha->hdr[t].media_changed) {
2638 /* return UNIT_ATTENTION */
2639 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2641 ha->hdr[t].media_changed = FALSE;
2642 memset((char*)nscp->sense_buffer,0,16);
2643 nscp->sense_buffer[0] = 0x70;
2644 nscp->sense_buffer[2] = UNIT_ATTENTION;
2645 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2646 if (!nscp->SCp.have_data_in)
2647 nscp->SCp.have_data_in++;
2650 GDTH_UNLOCK_HA(ha,flags);
2651 /* io_request_lock already active ! */
2652 nscp->scsi_done(nscp);
2654 GDTH_LOCK_HA(ha,flags);
2656 } else if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2661 TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0],
2662 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2663 nscp->cmnd[4],nscp->cmnd[5]));
2664 printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n",
2665 hanum, nscp->cmnd[0]);
2666 nscp->result = DID_ABORT << 16;
2667 if (!nscp->SCp.have_data_in)
2668 nscp->SCp.have_data_in++;
2671 GDTH_UNLOCK_HA(ha,flags);
2672 /* io_request_lock already active ! */
2673 nscp->scsi_done(nscp);
2675 GDTH_LOCK_HA(ha,flags);
2683 if (nscp == ha->req_first)
2684 ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
2686 pscp->SCp.ptr = nscp->SCp.ptr;
2691 if (ha->cmd_cnt > 0) {
2692 gdth_release_event(hanum);
2696 GDTH_UNLOCK_HA(ha, flags);
2698 if (gdth_polling && ha->cmd_cnt > 0) {
2699 if (!gdth_wait(hanum,cmd_index,POLL_TIMEOUT))
2700 printk("GDT-HA %d: Command %d timed out !\n",
2705 static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
2706 char *buffer,ushort count)
2710 struct scatterlist *sl;
2715 cpcount = count<=(ushort)scp->bufflen ? count:(ushort)scp->bufflen;
2716 ha = HADATA(gdth_ctr_tab[hanum]);
2719 sl = (struct scatterlist *)scp->request_buffer;
2720 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
2721 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,PCI_DMA_FROMDEVICE);
2722 for (i=0,cpsum=0; i<sgcnt; ++i,++sl) {
2723 cpnow = (ushort)sg_dma_len(sl);
2724 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2725 cpnow,cpsum,cpcount,(ushort)scp->bufflen));
2726 if (cpsum+cpnow > cpcount)
2727 cpnow = cpcount - cpsum;
2730 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
2734 address = (char *)(page_address(sl->page) + sl->offset);
2735 memcpy(address,buffer,cpnow);
2736 if (cpsum == cpcount)
2740 pci_unmap_sg(ha->pdev,scp->request_buffer,
2741 scp->use_sg,PCI_DMA_FROMDEVICE);
2743 sgcnt = scp->use_sg;
2744 for (i=0,cpsum=0; i<sgcnt; ++i,++sl) {
2745 cpnow = (ushort)sl->length;
2746 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2747 cpnow,cpsum,cpcount,(ushort)scp->bufflen));
2748 if (cpsum+cpnow > cpcount)
2749 cpnow = cpcount - cpsum;
2751 address = (char *)sl->address;
2752 memcpy(address,buffer,cpnow);
2753 if (cpsum == cpcount)
2759 TRACE(("copy_internal() count %d\n",cpcount));
2760 memcpy((char*)scp->request_buffer,buffer,cpcount);
2764 static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp)
2766 register gdth_ha_str *ha;
2769 gdth_rdcap_data rdc;
2771 gdth_modep_data mpd;
2773 ha = HADATA(gdth_ctr_tab[hanum]);
2774 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2775 t = scp->device->id;
2779 TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
2782 scp->result = DID_OK << 16;
2783 scp->sense_buffer[0] = 0;
2785 switch (scp->cmnd[0]) {
2786 case TEST_UNIT_READY:
2789 TRACE2(("Test/Verify/Start hdrive %d\n",t));
2793 TRACE2(("Inquiry hdrive %d devtype %d\n",
2794 t,ha->hdr[t].devtype));
2795 inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK;
2796 /* you can here set all disks to removable, if you want to do
2797 a flush using the ALLOW_MEDIUM_REMOVAL command */
2798 inq.modif_rmb = 0x00;
2799 if ((ha->hdr[t].devtype & 1) ||
2800 (ha->hdr[t].cluster_type & CLUSTER_DRIVE))
2801 inq.modif_rmb = 0x80;
2805 strcpy(inq.vendor,ha->oem_name);
2806 sprintf(inq.product,"Host Drive #%02d",t);
2807 strcpy(inq.revision," ");
2808 gdth_copy_internal_data(hanum,scp,(char*)&inq,sizeof(gdth_inq_data));
2812 TRACE2(("Request sense hdrive %d\n",t));
2813 sd.errorcode = 0x70;
2818 gdth_copy_internal_data(hanum,scp,(char*)&sd,sizeof(gdth_sense_data));
2822 TRACE2(("Mode sense hdrive %d\n",t));
2823 memset((char*)&mpd,0,sizeof(gdth_modep_data));
2824 mpd.hd.data_length = sizeof(gdth_modep_data);
2825 mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0;
2826 mpd.hd.bd_length = sizeof(mpd.bd);
2827 mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
2828 mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
2829 mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
2830 gdth_copy_internal_data(hanum,scp,(char*)&mpd,sizeof(gdth_modep_data));
2834 TRACE2(("Read capacity hdrive %d\n",t));
2835 if (ha->hdr[t].size > (ulong64)0xffffffff)
2836 rdc.last_block_no = 0xffffffff;
2838 rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1);
2839 rdc.block_length = cpu_to_be32(SECTOR_SIZE);
2840 gdth_copy_internal_data(hanum,scp,(char*)&rdc,sizeof(gdth_rdcap_data));
2843 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2844 case SERVICE_ACTION_IN:
2845 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 &&
2846 (ha->cache_feat & GDT_64BIT)) {
2847 gdth_rdcap16_data rdc16;
2849 TRACE2(("Read capacity (16) hdrive %d\n",t));
2850 rdc16.last_block_no = cpu_to_be64(ha->hdr[t].size-1);
2851 rdc16.block_length = cpu_to_be32(SECTOR_SIZE);
2852 gdth_copy_internal_data(hanum,scp,(char*)&rdc16,sizeof(gdth_rdcap16_data));
2854 scp->result = DID_ABORT << 16;
2860 TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0]));
2864 if (!scp->SCp.have_data_in)
2865 scp->SCp.have_data_in++;
2872 static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive)
2874 register gdth_ha_str *ha;
2875 register gdth_cmd_str *cmdp;
2876 struct scatterlist *sl;
2877 ulong32 cnt, blockcnt;
2878 ulong64 no, blockno;
2879 dma_addr_t phys_addr;
2880 int i, cmd_index, read_write, sgcnt, mode64;
2881 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
2886 ha = HADATA(gdth_ctr_tab[hanum]);
2888 TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
2889 scp->cmnd[0],scp->cmd_len,hdrive));
2891 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2894 mode64 = (ha->cache_feat & GDT_64BIT) ? TRUE : FALSE;
2895 /* test for READ_16, WRITE_16 if !mode64 ? ---
2896 not required, should not occur due to error return on
2899 cmdp->Service = CACHESERVICE;
2900 cmdp->RequestBuffer = scp;
2901 /* search free command index */
2902 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
2903 TRACE(("GDT: No free command index found\n"));
2906 /* if it's the first command, set command semaphore */
2907 if (ha->cmd_cnt == 0)
2908 gdth_set_sema0(hanum);
2912 if (scp->SCp.sent_command != -1)
2913 cmdp->OpCode = scp->SCp.sent_command; /* special cache cmd. */
2914 else if (scp->cmnd[0] == RESERVE)
2915 cmdp->OpCode = GDT_RESERVE_DRV;
2916 else if (scp->cmnd[0] == RELEASE)
2917 cmdp->OpCode = GDT_RELEASE_DRV;
2918 else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
2919 if (scp->cmnd[4] & 1) /* prevent ? */
2920 cmdp->OpCode = GDT_MOUNT;
2921 else if (scp->cmnd[3] & 1) /* removable drive ? */
2922 cmdp->OpCode = GDT_UNMOUNT;
2924 cmdp->OpCode = GDT_FLUSH;
2925 } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10 ||
2926 scp->cmnd[0] == WRITE_12
2927 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2928 || scp->cmnd[0] == WRITE_16
2932 if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) &&
2933 (ha->cache_feat & GDT_WR_THROUGH)))
2934 cmdp->OpCode = GDT_WRITE_THR;
2936 cmdp->OpCode = GDT_WRITE;
2939 cmdp->OpCode = GDT_READ;
2942 cmdp->BoardNode = LOCALBOARD;
2944 cmdp->u.cache64.DeviceNo = hdrive;
2945 cmdp->u.cache64.BlockNo = 1;
2946 cmdp->u.cache64.sg_canz = 0;
2948 cmdp->u.cache.DeviceNo = hdrive;
2949 cmdp->u.cache.BlockNo = 1;
2950 cmdp->u.cache.sg_canz = 0;
2954 if (scp->cmd_len == 16) {
2955 memcpy(&no, &scp->cmnd[2], sizeof(ulong64));
2956 blockno = be64_to_cpu(no);
2957 memcpy(&cnt, &scp->cmnd[10], sizeof(ulong32));
2958 blockcnt = be32_to_cpu(cnt);
2959 } else if (scp->cmd_len == 10) {
2960 memcpy(&no, &scp->cmnd[2], sizeof(ulong32));
2961 blockno = be32_to_cpu(no);
2962 memcpy(&cnt, &scp->cmnd[7], sizeof(ushort));
2963 blockcnt = be16_to_cpu(cnt);
2965 memcpy(&no, &scp->cmnd[0], sizeof(ulong32));
2966 blockno = be32_to_cpu(no) & 0x001fffffUL;
2967 blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
2970 cmdp->u.cache64.BlockNo = blockno;
2971 cmdp->u.cache64.BlockCnt = blockcnt;
2973 cmdp->u.cache.BlockNo = (ulong32)blockno;
2974 cmdp->u.cache.BlockCnt = blockcnt;
2978 sl = (struct scatterlist *)scp->request_buffer;
2979 sgcnt = scp->use_sg;
2980 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
2981 scp->SCp.Status = GDTH_MAP_SG;
2982 scp->SCp.Message = (read_write == 1 ?
2983 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
2984 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
2986 cmdp->u.cache64.DestAddr= (ulong64)-1;
2987 cmdp->u.cache64.sg_canz = sgcnt;
2988 for (i=0; i<sgcnt; ++i,++sl) {
2989 cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2990 #ifdef GDTH_DMA_STATISTICS
2991 if (cmdp->u.cache64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2996 cmdp->u.cache64.sg_lst[i].sg_len = sg_dma_len(sl);
2999 cmdp->u.cache.DestAddr= 0xffffffff;
3000 cmdp->u.cache.sg_canz = sgcnt;
3001 for (i=0; i<sgcnt; ++i,++sl) {
3002 cmdp->u.cache.sg_lst[i].sg_ptr = sg_dma_address(sl);
3003 #ifdef GDTH_DMA_STATISTICS
3006 cmdp->u.cache.sg_lst[i].sg_len = sg_dma_len(sl);
3011 cmdp->u.cache64.DestAddr= (ulong64)-1;
3012 cmdp->u.cache64.sg_canz = sgcnt;
3013 for (i=0; i<sgcnt; ++i,++sl) {
3014 cmdp->u.cache64.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
3015 cmdp->u.cache64.sg_lst[i].sg_len = (ulong32)sl->length;
3018 cmdp->u.cache.DestAddr= 0xffffffff;
3019 cmdp->u.cache.sg_canz = sgcnt;
3020 for (i=0; i<sgcnt; ++i,++sl) {
3021 cmdp->u.cache.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
3022 cmdp->u.cache.sg_lst[i].sg_len = (ulong32)sl->length;
3027 #ifdef GDTH_STATISTICS
3028 if (max_sg < (ulong32)sgcnt) {
3029 max_sg = (ulong32)sgcnt;
3030 TRACE3(("GDT: max_sg = %d\n",max_sg));
3035 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3036 scp->SCp.Status = GDTH_MAP_SINGLE;
3037 scp->SCp.Message = (read_write == 1 ?
3038 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
3039 page = virt_to_page(scp->request_buffer);
3040 offset = (ulong)scp->request_buffer & ~PAGE_MASK;
3041 phys_addr = pci_map_page(ha->pdev,page,offset,
3042 scp->request_bufflen,scp->SCp.Message);
3043 scp->SCp.dma_handle = phys_addr;
3045 phys_addr = virt_to_bus(scp->request_buffer);
3048 if (ha->cache_feat & SCATTER_GATHER) {
3049 cmdp->u.cache64.DestAddr = (ulong64)-1;
3050 cmdp->u.cache64.sg_canz = 1;
3051 cmdp->u.cache64.sg_lst[0].sg_ptr = phys_addr;
3052 cmdp->u.cache64.sg_lst[0].sg_len = scp->request_bufflen;
3053 cmdp->u.cache64.sg_lst[1].sg_len = 0;
3055 cmdp->u.cache64.DestAddr = phys_addr;
3056 cmdp->u.cache64.sg_canz= 0;
3059 if (ha->cache_feat & SCATTER_GATHER) {
3060 cmdp->u.cache.DestAddr = 0xffffffff;
3061 cmdp->u.cache.sg_canz = 1;
3062 cmdp->u.cache.sg_lst[0].sg_ptr = phys_addr;
3063 cmdp->u.cache.sg_lst[0].sg_len = scp->request_bufflen;
3064 cmdp->u.cache.sg_lst[1].sg_len = 0;
3066 cmdp->u.cache.DestAddr = phys_addr;
3067 cmdp->u.cache.sg_canz= 0;
3072 /* evaluate command size, check space */
3074 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3075 cmdp->u.cache64.DestAddr,cmdp->u.cache64.sg_canz,
3076 cmdp->u.cache64.sg_lst[0].sg_ptr,
3077 cmdp->u.cache64.sg_lst[0].sg_len));
3078 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
3079 cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt));
3080 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) +
3081 (ushort)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str);
3083 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3084 cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
3085 cmdp->u.cache.sg_lst[0].sg_ptr,
3086 cmdp->u.cache.sg_lst[0].sg_len));
3087 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
3088 cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
3089 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
3090 (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str);
3092 if (ha->cmd_len & 3)
3093 ha->cmd_len += (4 - (ha->cmd_len & 3));
3095 if (ha->cmd_cnt > 0) {
3096 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
3098 TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
3099 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
3105 gdth_copy_command(hanum);
3109 static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b)
3111 register gdth_ha_str *ha;
3112 register gdth_cmd_str *cmdp;
3113 struct scatterlist *sl;
3115 dma_addr_t phys_addr, sense_paddr;
3116 int cmd_index, sgcnt, mode64;
3118 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3123 ha = HADATA(gdth_ctr_tab[hanum]);
3124 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3125 t = scp->device->id;
3126 l = scp->device->lun;
3132 TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
3133 scp->cmnd[0],b,t,l));
3135 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
3138 mode64 = (ha->raw_feat & GDT_64BIT) ? TRUE : FALSE;
3140 cmdp->Service = SCSIRAWSERVICE;
3141 cmdp->RequestBuffer = scp;
3142 /* search free command index */
3143 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
3144 TRACE(("GDT: No free command index found\n"));
3147 /* if it's the first command, set command semaphore */
3148 if (ha->cmd_cnt == 0)
3149 gdth_set_sema0(hanum);
3152 if (scp->SCp.sent_command != -1) {
3153 cmdp->OpCode = scp->SCp.sent_command; /* special raw cmd. */
3154 cmdp->BoardNode = LOCALBOARD;
3156 cmdp->u.raw64.direction = (scp->SCp.phase >> 8);
3157 TRACE2(("special raw cmd 0x%x param 0x%x\n",
3158 cmdp->OpCode, cmdp->u.raw64.direction));
3159 /* evaluate command size */
3160 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst);
3162 cmdp->u.raw.direction = (scp->SCp.phase >> 8);
3163 TRACE2(("special raw cmd 0x%x param 0x%x\n",
3164 cmdp->OpCode, cmdp->u.raw.direction));
3165 /* evaluate command size */
3166 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst);
3170 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3171 page = virt_to_page(scp->sense_buffer);
3172 offset = (ulong)scp->sense_buffer & ~PAGE_MASK;
3173 sense_paddr = pci_map_page(ha->pdev,page,offset,
3174 16,PCI_DMA_FROMDEVICE);
3175 scp->SCp.buffer = (struct scatterlist *)((ulong32)sense_paddr);
3176 /* high part, if 64bit */
3177 scp->host_scribble = (char *)(ulong32)((ulong64)sense_paddr >> 32);
3179 sense_paddr = virt_to_bus(scp->sense_buffer);
3181 cmdp->OpCode = GDT_WRITE; /* always */
3182 cmdp->BoardNode = LOCALBOARD;
3184 cmdp->u.raw64.reserved = 0;
3185 cmdp->u.raw64.mdisc_time = 0;
3186 cmdp->u.raw64.mcon_time = 0;
3187 cmdp->u.raw64.clen = scp->cmd_len;
3188 cmdp->u.raw64.target = t;
3189 cmdp->u.raw64.lun = l;
3190 cmdp->u.raw64.bus = b;
3191 cmdp->u.raw64.priority = 0;
3192 cmdp->u.raw64.sdlen = scp->request_bufflen;
3193 cmdp->u.raw64.sense_len = 16;
3194 cmdp->u.raw64.sense_data = sense_paddr;
3195 cmdp->u.raw64.direction =
3196 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
3197 memcpy(cmdp->u.raw64.cmd,scp->cmnd,16);
3199 cmdp->u.raw.reserved = 0;
3200 cmdp->u.raw.mdisc_time = 0;
3201 cmdp->u.raw.mcon_time = 0;
3202 cmdp->u.raw.clen = scp->cmd_len;
3203 cmdp->u.raw.target = t;
3204 cmdp->u.raw.lun = l;
3205 cmdp->u.raw.bus = b;
3206 cmdp->u.raw.priority = 0;
3207 cmdp->u.raw.link_p = 0;
3208 cmdp->u.raw.sdlen = scp->request_bufflen;
3209 cmdp->u.raw.sense_len = 16;
3210 cmdp->u.raw.sense_data = sense_paddr;
3211 cmdp->u.raw.direction =
3212 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
3213 memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
3217 sl = (struct scatterlist *)scp->request_buffer;
3218 sgcnt = scp->use_sg;
3219 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3220 scp->SCp.Status = GDTH_MAP_SG;
3221 scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
3222 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
3224 cmdp->u.raw64.sdata = (ulong64)-1;
3225 cmdp->u.raw64.sg_ranz = sgcnt;
3226 for (i=0; i<sgcnt; ++i,++sl) {
3227 cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl);
3228 #ifdef GDTH_DMA_STATISTICS
3229 if (cmdp->u.raw64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
3234 cmdp->u.raw64.sg_lst[i].sg_len = sg_dma_len(sl);
3237 cmdp->u.raw.sdata = 0xffffffff;
3238 cmdp->u.raw.sg_ranz = sgcnt;
3239 for (i=0; i<sgcnt; ++i,++sl) {
3240 cmdp->u.raw.sg_lst[i].sg_ptr = sg_dma_address(sl);
3241 #ifdef GDTH_DMA_STATISTICS
3244 cmdp->u.raw.sg_lst[i].sg_len = sg_dma_len(sl);
3249 cmdp->u.raw64.sdata = (ulong64)-1;
3250 cmdp->u.raw64.sg_ranz = sgcnt;
3251 for (i=0; i<sgcnt; ++i,++sl) {
3252 cmdp->u.raw64.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
3253 cmdp->u.raw64.sg_lst[i].sg_len = (ulong32)sl->length;
3256 cmdp->u.raw.sdata = 0xffffffff;
3257 cmdp->u.raw.sg_ranz = sgcnt;
3258 for (i=0; i<sgcnt; ++i,++sl) {
3259 cmdp->u.raw.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
3260 cmdp->u.raw.sg_lst[i].sg_len = (ulong32)sl->length;
3265 #ifdef GDTH_STATISTICS
3266 if (max_sg < sgcnt) {
3268 TRACE3(("GDT: max_sg = %d\n",sgcnt));
3273 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3274 scp->SCp.Status = GDTH_MAP_SINGLE;
3275 scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
3276 page = virt_to_page(scp->request_buffer);
3277 offset = (ulong)scp->request_buffer & ~PAGE_MASK;
3278 phys_addr = pci_map_page(ha->pdev,page,offset,
3279 scp->request_bufflen,scp->SCp.Message);
3280 scp->SCp.dma_handle = phys_addr;
3282 phys_addr = virt_to_bus(scp->request_buffer);
3285 if (ha->raw_feat & SCATTER_GATHER) {
3286 cmdp->u.raw64.sdata = (ulong64)-1;
3287 cmdp->u.raw64.sg_ranz= 1;
3288 cmdp->u.raw64.sg_lst[0].sg_ptr = phys_addr;
3289 cmdp->u.raw64.sg_lst[0].sg_len = scp->request_bufflen;
3290 cmdp->u.raw64.sg_lst[1].sg_len = 0;
3292 cmdp->u.raw64.sdata = phys_addr;
3293 cmdp->u.raw64.sg_ranz= 0;
3296 if (ha->raw_feat & SCATTER_GATHER) {
3297 cmdp->u.raw.sdata = 0xffffffff;
3298 cmdp->u.raw.sg_ranz= 1;
3299 cmdp->u.raw.sg_lst[0].sg_ptr = phys_addr;
3300 cmdp->u.raw.sg_lst[0].sg_len = scp->request_bufflen;
3301 cmdp->u.raw.sg_lst[1].sg_len = 0;
3303 cmdp->u.raw.sdata = phys_addr;
3304 cmdp->u.raw.sg_ranz= 0;
3309 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3310 cmdp->u.raw64.sdata,cmdp->u.raw64.sg_ranz,
3311 cmdp->u.raw64.sg_lst[0].sg_ptr,
3312 cmdp->u.raw64.sg_lst[0].sg_len));
3313 /* evaluate command size */
3314 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) +
3315 (ushort)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str);
3317 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3318 cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
3319 cmdp->u.raw.sg_lst[0].sg_ptr,
3320 cmdp->u.raw.sg_lst[0].sg_len));
3321 /* evaluate command size */
3322 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
3323 (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
3327 if (ha->cmd_len & 3)
3328 ha->cmd_len += (4 - (ha->cmd_len & 3));
3330 if (ha->cmd_cnt > 0) {
3331 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
3333 TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
3334 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
3340 gdth_copy_command(hanum);
3344 static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp)
3346 register gdth_ha_str *ha;
3347 register gdth_cmd_str *cmdp;
3350 ha = HADATA(gdth_ctr_tab[hanum]);
3352 TRACE2(("gdth_special_cmd(): "));
3354 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
3357 memcpy( cmdp, scp->request_buffer, sizeof(gdth_cmd_str));
3358 cmdp->RequestBuffer = scp;
3360 /* search free command index */
3361 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
3362 TRACE(("GDT: No free command index found\n"));
3366 /* if it's the first command, set command semaphore */
3367 if (ha->cmd_cnt == 0)
3368 gdth_set_sema0(hanum);
3370 /* evaluate command size, check space */
3371 if (cmdp->OpCode == GDT_IOCTL) {
3372 TRACE2(("IOCTL\n"));
3374 GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong64);
3375 } else if (cmdp->Service == CACHESERVICE) {
3376 TRACE2(("cache command %d\n",cmdp->OpCode));
3377 if (ha->cache_feat & GDT_64BIT)
3379 GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + sizeof(gdth_sg64_str);
3382 GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
3383 } else if (cmdp->Service == SCSIRAWSERVICE) {
3384 TRACE2(("raw command %d\n",cmdp->OpCode));
3385 if (ha->raw_feat & GDT_64BIT)
3387 GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + sizeof(gdth_sg64_str);
3390 GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
3393 if (ha->cmd_len & 3)
3394 ha->cmd_len += (4 - (ha->cmd_len & 3));
3396 if (ha->cmd_cnt > 0) {
3397 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
3399 TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
3400 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
3406 gdth_copy_command(hanum);
3411 /* Controller event handling functions */
3412 static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
3413 ushort idx, gdth_evt_data *evt)
3418 /* no GDTH_LOCK_HA() ! */
3419 TRACE2(("gdth_store_event() source %d idx %d\n", source, idx));
3420 if (source == 0) /* no source -> no event */
3423 if (ebuffer[elastidx].event_source == source &&
3424 ebuffer[elastidx].event_idx == idx &&
3425 ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
3426 !memcmp((char *)&ebuffer[elastidx].event_data.eu,
3427 (char *)&evt->eu, evt->size)) ||
3428 (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
3429 !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
3430 (char *)&evt->event_string)))) {
3431 e = &ebuffer[elastidx];
3432 do_gettimeofday(&tv);
3433 e->last_stamp = tv.tv_sec;
3436 if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
3438 if (elastidx == MAX_EVENTS)
3440 if (elastidx == eoldidx) { /* reached mark ? */
3442 if (eoldidx == MAX_EVENTS)
3446 e = &ebuffer[elastidx];
3447 e->event_source = source;
3449 do_gettimeofday(&tv);
3450 e->first_stamp = e->last_stamp = tv.tv_sec;
3452 e->event_data = *evt;
3458 static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
3464 TRACE2(("gdth_read_event() handle %d\n", handle));
3465 GDTH_LOCK_HA(ha, flags);
3470 estr->event_source = 0;
3472 if (eindex >= MAX_EVENTS) {
3473 GDTH_UNLOCK_HA(ha, flags);
3476 e = &ebuffer[eindex];
3477 if (e->event_source != 0) {
3478 if (eindex != elastidx) {
3479 if (++eindex == MAX_EVENTS)
3484 memcpy(estr, e, sizeof(gdth_evt_str));
3486 GDTH_UNLOCK_HA(ha, flags);
3490 static void gdth_readapp_event(gdth_ha_str *ha,
3491 unchar application, gdth_evt_str *estr)
3496 unchar found = FALSE;
3498 TRACE2(("gdth_readapp_event() app. %d\n", application));
3499 GDTH_LOCK_HA(ha, flags);
3502 e = &ebuffer[eindex];
3503 if (e->event_source == 0)
3505 if ((e->application & application) == 0) {
3506 e->application |= application;
3510 if (eindex == elastidx)
3512 if (++eindex == MAX_EVENTS)
3516 memcpy(estr, e, sizeof(gdth_evt_str));
3518 estr->event_source = 0;
3519 GDTH_UNLOCK_HA(ha, flags);
3522 static void gdth_clear_events(void)
3524 TRACE(("gdth_clear_events()"));
3526 eoldidx = elastidx = 0;
3527 ebuffer[0].event_source = 0;
3531 /* SCSI interface functions */
3533 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3534 static irqreturn_t gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs)
3536 static void gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs)
3539 register gdth_ha_str *ha;
3540 gdt6m_dpram_str __iomem *dp6m_ptr = NULL;
3541 gdt6_dpram_str __iomem *dp6_ptr;
3542 gdt2_dpram_str __iomem *dp2_ptr;
3549 int coalesced = FALSE;
3551 gdth_coal_status *pcs = NULL;
3552 int act_int_coal = 0;
3555 TRACE(("gdth_interrupt() IRQ %d\n",irq));
3557 /* if polling and not from gdth_wait() -> return */
3559 if (!gdth_from_wait) {
3560 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3569 GDTH_LOCK_HA((gdth_ha_str *)dev_id,flags);
3572 /* search controller */
3573 if ((hanum = gdth_get_status(&IStatus,irq)) == -1) {
3574 /* spurious interrupt */
3576 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3577 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3583 ha = HADATA(gdth_ctr_tab[hanum]);
3585 #ifdef GDTH_STATISTICS
3590 /* See if the fw is returning coalesced status */
3591 if (IStatus == COALINDEX) {
3592 /* Coalesced status. Setup the initial status
3593 buffer pointer and flags */
3594 pcs = ha->coal_stat;
3601 /* For coalesced requests all status
3602 information is found in the status buffer */
3603 IStatus = (unchar)(pcs->status & 0xff);
3607 if (ha->type == GDT_EISA) {
3608 if (IStatus & 0x80) { /* error flag */
3610 ha->status = inw(ha->bmic + MAILBOXREG+8);
3611 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3612 } else /* no error */
3614 ha->info = inl(ha->bmic + MAILBOXREG+12);
3615 ha->service = inw(ha->bmic + MAILBOXREG+10);
3616 ha->info2 = inl(ha->bmic + MAILBOXREG+4);
3618 outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */
3619 outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */
3620 } else if (ha->type == GDT_ISA) {
3622 if (IStatus & 0x80) { /* error flag */
3624 ha->status = gdth_readw(&dp2_ptr->u.ic.Status);
3625 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3626 } else /* no error */
3628 ha->info = gdth_readl(&dp2_ptr->u.ic.Info[0]);
3629 ha->service = gdth_readw(&dp2_ptr->u.ic.Service);
3630 ha->info2 = gdth_readl(&dp2_ptr->u.ic.Info[1]);
3632 gdth_writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
3633 gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */
3634 gdth_writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */
3635 } else if (ha->type == GDT_PCI) {
3637 if (IStatus & 0x80) { /* error flag */
3639 ha->status = gdth_readw(&dp6_ptr->u.ic.Status);
3640 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3641 } else /* no error */
3643 ha->info = gdth_readl(&dp6_ptr->u.ic.Info[0]);
3644 ha->service = gdth_readw(&dp6_ptr->u.ic.Service);
3645 ha->info2 = gdth_readl(&dp6_ptr->u.ic.Info[1]);
3647 gdth_writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
3648 gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */
3649 gdth_writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */
3650 } else if (ha->type == GDT_PCINEW) {
3651 if (IStatus & 0x80) { /* error flag */
3653 ha->status = inw(PTR2USHORT(&ha->plx->status));
3654 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3657 ha->info = inl(PTR2USHORT(&ha->plx->info[0]));
3658 ha->service = inw(PTR2USHORT(&ha->plx->service));
3659 ha->info2 = inl(PTR2USHORT(&ha->plx->info[1]));
3661 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
3662 outb(0x00, PTR2USHORT(&ha->plx->sema1_reg));
3663 } else if (ha->type == GDT_PCIMPR) {
3665 if (IStatus & 0x80) { /* error flag */
3669 ha->status = pcs->ext_status && 0xffff;
3672 ha->status = gdth_readw(&dp6m_ptr->i960r.status);
3673 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3674 } else /* no error */
3677 /* get information */
3679 ha->info = pcs->info0;
3680 ha->info2 = pcs->info1;
3681 ha->service = (pcs->ext_status >> 16) && 0xffff;
3685 ha->info = gdth_readl(&dp6m_ptr->i960r.info[0]);
3686 ha->service = gdth_readw(&dp6m_ptr->i960r.service);
3687 ha->info2 = gdth_readl(&dp6m_ptr->i960r.info[1]);
3690 if (IStatus == ASYNCINDEX) {
3691 if (ha->service != SCREENSERVICE &&
3692 (ha->fw_vers & 0xff) >= 0x1a) {
3693 ha->dvr.severity = gdth_readb
3694 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.severity);
3695 for (i = 0; i < 256; ++i) {
3696 ha->dvr.event_string[i] = gdth_readb
3697 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.evt_str[i]);
3698 if (ha->dvr.event_string[i] == 0)
3704 /* Make sure that non coalesced interrupts get cleared
3705 before being handled by gdth_async_event/gdth_sync_event */
3709 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3710 gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
3713 TRACE2(("gdth_interrupt() unknown controller type\n"));
3715 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3716 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3723 TRACE(("gdth_interrupt() index %d stat %d info %d\n",
3724 IStatus,ha->status,ha->info));
3726 if (gdth_from_wait) {
3728 wait_index = (int)IStatus;
3731 if (IStatus == ASYNCINDEX) {
3732 TRACE2(("gdth_interrupt() async. event\n"));
3733 gdth_async_event(hanum);
3735 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3737 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3744 if (IStatus == SPEZINDEX) {
3745 TRACE2(("Service unknown or not initialized !\n"));
3746 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3747 ha->dvr.eu.driver.ionode = hanum;
3748 gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr);
3750 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3751 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3757 scp = ha->cmd_tab[IStatus-2].cmnd;
3758 Service = ha->cmd_tab[IStatus-2].service;
3759 ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND;
3760 if (scp == UNUSED_CMND) {
3761 TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus));
3762 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3763 ha->dvr.eu.driver.ionode = hanum;
3764 ha->dvr.eu.driver.index = IStatus;
3765 gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr);
3767 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3768 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3774 if (scp == INTERNAL_CMND) {
3775 TRACE(("gdth_interrupt() answer to internal command\n"));
3777 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3778 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3785 TRACE(("gdth_interrupt() sync. status\n"));
3786 rval = gdth_sync_event(hanum,Service,IStatus,scp);
3788 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3790 gdth_putq(hanum,scp,scp->SCp.this_residual);
3791 } else if (rval == 1) {
3792 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3793 GDTH_LOCK_SCSI_DONE(scp->device->host, flags);
3794 scp->scsi_done(scp);
3795 GDTH_UNLOCK_SCSI_DONE(scp->device->host, flags);
3797 GDTH_LOCK_SCSI_DONE(flags);
3798 scp->scsi_done(scp);
3799 GDTH_UNLOCK_SCSI_DONE(flags);
3805 /* go to the next status in the status buffer */
3807 #ifdef GDTH_STATISTICS
3809 if (act_int_coal > max_int_coal) {
3810 max_int_coal = act_int_coal;
3811 printk("GDT: max_int_coal = %d\n",(ushort)max_int_coal);
3814 /* see if there is another status */
3815 if (pcs->status == 0)
3816 /* Stop the coalesce loop */
3821 /* coalescing only for new GDT_PCIMPR controllers available */
3822 if (ha->type == GDT_PCIMPR && coalesced) {
3823 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3824 gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
3829 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3834 static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp)
3836 register gdth_ha_str *ha;
3841 ha = HADATA(gdth_ctr_tab[hanum]);
3843 TRACE(("gdth_sync_event() serv %d status %d\n",
3844 service,ha->status));
3846 if (service == SCREENSERVICE) {
3848 TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
3849 msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
3850 if (msg->msg_len > MSGLEN+1)
3851 msg->msg_len = MSGLEN+1;
3853 if (!(msg->msg_answer && msg->msg_ext)) {
3854 msg->msg_text[msg->msg_len] = '\0';
3855 printk("%s",msg->msg_text);
3858 if (msg->msg_ext && !msg->msg_answer) {
3859 while (gdth_test_busy(hanum))
3861 cmdp->Service = SCREENSERVICE;
3862 cmdp->RequestBuffer = SCREEN_CMND;
3863 gdth_get_cmd_index(hanum);
3864 gdth_set_sema0(hanum);
3865 cmdp->OpCode = GDT_READ;
3866 cmdp->BoardNode = LOCALBOARD;
3867 cmdp->u.screen.reserved = 0;
3868 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3869 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3870 ha->cmd_offs_dpmem = 0;
3871 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3874 gdth_copy_command(hanum);
3875 gdth_release_event(hanum);
3879 if (msg->msg_answer && msg->msg_alen) {
3880 /* default answers (getchar() not possible) */
3881 if (msg->msg_alen == 1) {
3884 msg->msg_text[0] = 0;
3888 msg->msg_text[0] = 1;
3889 msg->msg_text[1] = 0;
3892 msg->msg_answer = 0;
3893 while (gdth_test_busy(hanum))
3895 cmdp->Service = SCREENSERVICE;
3896 cmdp->RequestBuffer = SCREEN_CMND;
3897 gdth_get_cmd_index(hanum);
3898 gdth_set_sema0(hanum);
3899 cmdp->OpCode = GDT_WRITE;
3900 cmdp->BoardNode = LOCALBOARD;
3901 cmdp->u.screen.reserved = 0;
3902 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3903 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3904 ha->cmd_offs_dpmem = 0;
3905 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3908 gdth_copy_command(hanum);
3909 gdth_release_event(hanum);
3915 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3916 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
3917 t = scp->device->id;
3919 b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
3922 if (scp->SCp.sent_command == -1 && b != ha->virt_bus) {
3923 ha->raw[BUS_L2P(ha,b)].io_cnt[t]--;
3925 /* cache or raw service */
3926 if (ha->status == S_BSY) {
3927 TRACE2(("Controller busy -> retry !\n"));
3928 if (scp->SCp.sent_command == GDT_MOUNT)
3929 scp->SCp.sent_command = GDT_CLUST_INFO;
3933 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3934 if (scp->SCp.Status == GDTH_MAP_SG)
3935 pci_unmap_sg(ha->pdev,scp->request_buffer,
3936 scp->use_sg,scp->SCp.Message);
3937 else if (scp->SCp.Status == GDTH_MAP_SINGLE)
3938 pci_unmap_page(ha->pdev,scp->SCp.dma_handle,
3939 scp->request_bufflen,scp->SCp.Message);
3940 if (scp->SCp.buffer) {
3942 addr = (dma_addr_t)(ulong32)scp->SCp.buffer;
3943 if (scp->host_scribble)
3944 addr += (dma_addr_t)((ulong64)(ulong32)scp->host_scribble << 32);
3945 pci_unmap_page(ha->pdev,addr,16,PCI_DMA_FROMDEVICE);
3948 if (ha->status == S_OK) {
3949 scp->SCp.Status = S_OK;
3950 scp->SCp.Message = ha->info;
3951 if (scp->SCp.sent_command != -1) {
3952 TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
3953 scp->SCp.sent_command));
3954 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
3955 if (scp->SCp.sent_command == GDT_CLUST_INFO) {
3956 ha->hdr[t].cluster_type = (unchar)ha->info;
3957 if (!(ha->hdr[t].cluster_type &
3959 /* NOT MOUNTED -> MOUNT */
3960 scp->SCp.sent_command = GDT_MOUNT;
3961 if (ha->hdr[t].cluster_type &
3963 /* cluster drive RESERVED (on the other node) */
3964 scp->SCp.phase = -2; /* reservation conflict */
3967 scp->SCp.sent_command = -1;
3970 if (scp->SCp.sent_command == GDT_MOUNT) {
3971 ha->hdr[t].cluster_type |= CLUSTER_MOUNTED;
3972 ha->hdr[t].media_changed = TRUE;
3973 } else if (scp->SCp.sent_command == GDT_UNMOUNT) {
3974 ha->hdr[t].cluster_type &= ~CLUSTER_MOUNTED;
3975 ha->hdr[t].media_changed = TRUE;
3977 scp->SCp.sent_command = -1;
3980 scp->SCp.this_residual = HIGH_PRI;
3983 /* RESERVE/RELEASE ? */
3984 if (scp->cmnd[0] == RESERVE) {
3985 ha->hdr[t].cluster_type |= CLUSTER_RESERVED;
3986 } else if (scp->cmnd[0] == RELEASE) {
3987 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3989 scp->result = DID_OK << 16;
3990 scp->sense_buffer[0] = 0;
3993 scp->SCp.Status = ha->status;
3994 scp->SCp.Message = ha->info;
3996 if (scp->SCp.sent_command != -1) {
3997 TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
3998 scp->SCp.sent_command, ha->status));
3999 if (scp->SCp.sent_command == GDT_SCAN_START ||
4000 scp->SCp.sent_command == GDT_SCAN_END) {
4001 scp->SCp.sent_command = -1;
4003 scp->SCp.this_residual = HIGH_PRI;
4006 memset((char*)scp->sense_buffer,0,16);
4007 scp->sense_buffer[0] = 0x70;
4008 scp->sense_buffer[2] = NOT_READY;
4009 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
4010 } else if (service == CACHESERVICE) {
4011 if (ha->status == S_CACHE_UNKNOWN &&
4012 (ha->hdr[t].cluster_type &
4013 CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) {
4014 /* bus reset -> force GDT_CLUST_INFO */
4015 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
4017 memset((char*)scp->sense_buffer,0,16);
4018 if (ha->status == (ushort)S_CACHE_RESERV) {
4019 scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
4021 scp->sense_buffer[0] = 0x70;
4022 scp->sense_buffer[2] = NOT_READY;
4023 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
4025 if (scp->done != gdth_scsi_done) {
4026 ha->dvr.size = sizeof(ha->dvr.eu.sync);
4027 ha->dvr.eu.sync.ionode = hanum;
4028 ha->dvr.eu.sync.service = service;
4029 ha->dvr.eu.sync.status = ha->status;
4030 ha->dvr.eu.sync.info = ha->info;
4031 ha->dvr.eu.sync.hostdrive = t;
4032 if (ha->status >= 0x8000)
4033 gdth_store_event(ha, ES_SYNC, 0, &ha->dvr);
4035 gdth_store_event(ha, ES_SYNC, service, &ha->dvr);
4038 /* sense buffer filled from controller firmware (DMA) */
4039 if (ha->status != S_RAW_SCSI || ha->info >= 0x100) {
4040 scp->result = DID_BAD_TARGET << 16;
4042 scp->result = (DID_OK << 16) | ha->info;
4046 if (!scp->SCp.have_data_in)
4047 scp->SCp.have_data_in++;
4055 static char *async_cache_tab[] = {
4056 /* 0*/ "\011\000\002\002\002\004\002\006\004"
4057 "GDT HA %u, service %u, async. status %u/%lu unknown",
4058 /* 1*/ "\011\000\002\002\002\004\002\006\004"
4059 "GDT HA %u, service %u, async. status %u/%lu unknown",
4060 /* 2*/ "\005\000\002\006\004"
4061 "GDT HA %u, Host Drive %lu not ready",
4062 /* 3*/ "\005\000\002\006\004"
4063 "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",
4064 /* 4*/ "\005\000\002\006\004"
4065 "GDT HA %u, mirror update on Host Drive %lu failed",
4066 /* 5*/ "\005\000\002\006\004"
4067 "GDT HA %u, Mirror Drive %lu failed",
4068 /* 6*/ "\005\000\002\006\004"
4069 "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",
4070 /* 7*/ "\005\000\002\006\004"
4071 "GDT HA %u, Host Drive %lu write protected",
4072 /* 8*/ "\005\000\002\006\004"
4073 "GDT HA %u, media changed in Host Drive %lu",
4074 /* 9*/ "\005\000\002\006\004"
4075 "GDT HA %u, Host Drive %lu is offline",
4076 /*10*/ "\005\000\002\006\004"
4077 "GDT HA %u, media change of Mirror Drive %lu",
4078 /*11*/ "\005\000\002\006\004"
4079 "GDT HA %u, Mirror Drive %lu is write protected",
4080 /*12*/ "\005\000\002\006\004"
4081 "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
4082 /*13*/ "\007\000\002\006\002\010\002"
4083 "GDT HA %u, Array Drive %u: Cache Drive %u failed",
4084 /*14*/ "\005\000\002\006\002"
4085 "GDT HA %u, Array Drive %u: FAIL state entered",
4086 /*15*/ "\005\000\002\006\002"
4087 "GDT HA %u, Array Drive %u: error",
4088 /*16*/ "\007\000\002\006\002\010\002"
4089 "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
4090 /*17*/ "\005\000\002\006\002"
4091 "GDT HA %u, Array Drive %u: parity build failed",
4092 /*18*/ "\005\000\002\006\002"
4093 "GDT HA %u, Array Drive %u: drive rebuild failed",
4094 /*19*/ "\005\000\002\010\002"
4095 "GDT HA %u, Test of Hot Fix %u failed",
4096 /*20*/ "\005\000\002\006\002"
4097 "GDT HA %u, Array Drive %u: drive build finished successfully",
4098 /*21*/ "\005\000\002\006\002"
4099 "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
4100 /*22*/ "\007\000\002\006\002\010\002"
4101 "GDT HA %u, Array Drive %u: Hot Fix %u activated",
4102 /*23*/ "\005\000\002\006\002"
4103 "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
4104 /*24*/ "\005\000\002\010\002"
4105 "GDT HA %u, mirror update on Cache Drive %u completed",
4106 /*25*/ "\005\000\002\010\002"
4107 "GDT HA %u, mirror update on Cache Drive %lu failed",
4108 /*26*/ "\005\000\002\006\002"
4109 "GDT HA %u, Array Drive %u: drive rebuild started",
4110 /*27*/ "\005\000\002\012\001"
4111 "GDT HA %u, Fault bus %u: SHELF OK detected",
4112 /*28*/ "\005\000\002\012\001"
4113 "GDT HA %u, Fault bus %u: SHELF not OK detected",
4114 /*29*/ "\007\000\002\012\001\013\001"
4115 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
4116 /*30*/ "\007\000\002\012\001\013\001"
4117 "GDT HA %u, Fault bus %u, ID %u: new disk detected",
4118 /*31*/ "\007\000\002\012\001\013\001"
4119 "GDT HA %u, Fault bus %u, ID %u: old disk detected",
4120 /*32*/ "\007\000\002\012\001\013\001"
4121 "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid",
4122 /*33*/ "\007\000\002\012\001\013\001"
4123 "GDT HA %u, Fault bus %u, ID %u: invalid device detected",
4124 /*34*/ "\011\000\002\012\001\013\001\006\004"
4125 "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
4126 /*35*/ "\007\000\002\012\001\013\001"
4127 "GDT HA %u, Fault bus %u, ID %u: disk write protected",
4128 /*36*/ "\007\000\002\012\001\013\001"
4129 "GDT HA %u, Fault bus %u, ID %u: disk not available",
4130 /*37*/ "\007\000\002\012\001\006\004"
4131 "GDT HA %u, Fault bus %u: swap detected (%lu)",
4132 /*38*/ "\007\000\002\012\001\013\001"
4133 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
4134 /*39*/ "\007\000\002\012\001\013\001"
4135 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
4136 /*40*/ "\007\000\002\012\001\013\001"
4137 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
4138 /*41*/ "\007\000\002\012\001\013\001"
4139 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
4140 /*42*/ "\005\000\002\006\002"
4141 "GDT HA %u, Array Drive %u: drive build started",
4142 /*43*/ "\003\000\002"
4143 "GDT HA %u, DRAM parity error detected",
4144 /*44*/ "\005\000\002\006\002"
4145 "GDT HA %u, Mirror Drive %u: update started",
4146 /*45*/ "\007\000\002\006\002\010\002"
4147 "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
4148 /*46*/ "\005\000\002\006\002"
4149 "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
4150 /*47*/ "\005\000\002\006\002"
4151 "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
4152 /*48*/ "\005\000\002\006\002"
4153 "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
4154 /*49*/ "\005\000\002\006\002"
4155 "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
4156 /*50*/ "\007\000\002\012\001\013\001"
4157 "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
4158 /*51*/ "\005\000\002\006\002"
4159 "GDT HA %u, Array Drive %u: expand started",
4160 /*52*/ "\005\000\002\006\002"
4161 "GDT HA %u, Array Drive %u: expand finished successfully",
4162 /*53*/ "\005\000\002\006\002"
4163 "GDT HA %u, Array Drive %u: expand failed",
4164 /*54*/ "\003\000\002"
4165 "GDT HA %u, CPU temperature critical",
4166 /*55*/ "\003\000\002"
4167 "GDT HA %u, CPU temperature OK",
4168 /*56*/ "\005\000\002\006\004"
4169 "GDT HA %u, Host drive %lu created",
4170 /*57*/ "\005\000\002\006\002"
4171 "GDT HA %u, Array Drive %u: expand restarted",
4172 /*58*/ "\005\000\002\006\002"
4173 "GDT HA %u, Array Drive %u: expand stopped",
4174 /*59*/ "\005\000\002\010\002"
4175 "GDT HA %u, Mirror Drive %u: drive build quited",
4176 /*60*/ "\005\000\002\006\002"
4177 "GDT HA %u, Array Drive %u: parity build quited",
4178 /*61*/ "\005\000\002\006\002"
4179 "GDT HA %u, Array Drive %u: drive rebuild quited",
4180 /*62*/ "\005\000\002\006\002"
4181 "GDT HA %u, Array Drive %u: parity verify started",
4182 /*63*/ "\005\000\002\006\002"
4183 "GDT HA %u, Array Drive %u: parity verify done",
4184 /*64*/ "\005\000\002\006\002"
4185 "GDT HA %u, Array Drive %u: parity verify failed",
4186 /*65*/ "\005\000\002\006\002"
4187 "GDT HA %u, Array Drive %u: parity error detected",
4188 /*66*/ "\005\000\002\006\002"
4189 "GDT HA %u, Array Drive %u: parity verify quited",
4190 /*67*/ "\005\000\002\006\002"
4191 "GDT HA %u, Host Drive %u reserved",
4192 /*68*/ "\005\000\002\006\002"
4193 "GDT HA %u, Host Drive %u mounted and released",
4194 /*69*/ "\005\000\002\006\002"
4195 "GDT HA %u, Host Drive %u released",
4196 /*70*/ "\003\000\002"
4197 "GDT HA %u, DRAM error detected and corrected with ECC",
4198 /*71*/ "\003\000\002"
4199 "GDT HA %u, Uncorrectable DRAM error detected with ECC",
4200 /*72*/ "\011\000\002\012\001\013\001\014\001"
4201 "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
4202 /*73*/ "\005\000\002\006\002"
4203 "GDT HA %u, Host drive %u resetted locally",
4204 /*74*/ "\005\000\002\006\002"
4205 "GDT HA %u, Host drive %u resetted remotely",
4206 /*75*/ "\003\000\002"
4207 "GDT HA %u, async. status 75 unknown",
4211 static int gdth_async_event(int hanum)
4217 ha = HADATA(gdth_ctr_tab[hanum]);
4219 TRACE2(("gdth_async_event() ha %d serv %d\n",
4220 hanum,ha->service));
4222 if (ha->service == SCREENSERVICE) {
4223 if (ha->status == MSG_REQUEST) {
4224 while (gdth_test_busy(hanum))
4226 cmdp->Service = SCREENSERVICE;
4227 cmdp->RequestBuffer = SCREEN_CMND;
4228 cmd_index = gdth_get_cmd_index(hanum);
4229 gdth_set_sema0(hanum);
4230 cmdp->OpCode = GDT_READ;
4231 cmdp->BoardNode = LOCALBOARD;
4232 cmdp->u.screen.reserved = 0;
4233 cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE;
4234 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
4235 ha->cmd_offs_dpmem = 0;
4236 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
4239 gdth_copy_command(hanum);
4240 if (ha->type == GDT_EISA)
4241 printk("[EISA slot %d] ",(ushort)ha->brd_phys);
4242 else if (ha->type == GDT_ISA)
4243 printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys);
4245 printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8),
4246 (ushort)((ha->brd_phys>>3)&0x1f));
4247 gdth_release_event(hanum);
4251 if (ha->type == GDT_PCIMPR &&
4252 (ha->fw_vers & 0xff) >= 0x1a) {
4254 ha->dvr.eu.async.ionode = hanum;
4255 ha->dvr.eu.async.status = ha->status;
4256 /* severity and event_string already set! */
4258 ha->dvr.size = sizeof(ha->dvr.eu.async);
4259 ha->dvr.eu.async.ionode = hanum;
4260 ha->dvr.eu.async.service = ha->service;
4261 ha->dvr.eu.async.status = ha->status;
4262 ha->dvr.eu.async.info = ha->info;
4263 *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2;
4265 gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr );
4266 gdth_log_event( &ha->dvr, NULL );
4268 /* new host drive from expand? */
4269 if (ha->service == CACHESERVICE && ha->status == 56) {
4270 TRACE2(("gdth_async_event(): new host drive %d created\n",
4272 /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
4278 static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
4280 gdth_stackframe stack;
4284 TRACE2(("gdth_log_event()\n"));
4285 if (dvr->size == 0) {
4286 if (buffer == NULL) {
4287 printk("Adapter %d: %s\n",dvr->eu.async.ionode,dvr->event_string);
4289 sprintf(buffer,"Adapter %d: %s\n",
4290 dvr->eu.async.ionode,dvr->event_string);
4292 } else if (dvr->eu.async.service == CACHESERVICE &&
4293 INDEX_OK(dvr->eu.async.status, async_cache_tab)) {
4294 TRACE2(("GDT: Async. event cache service, event no.: %d\n",
4295 dvr->eu.async.status));
4297 f = async_cache_tab[dvr->eu.async.status];
4299 /* i: parameter to push, j: stack element to fill */
4300 for (j=0,i=1; i < f[0]; i+=2) {
4303 stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]];
4306 stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]];
4309 stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]];
4316 if (buffer == NULL) {
4317 printk(&f[(int)f[0]],stack);
4320 sprintf(buffer,&f[(int)f[0]],stack);
4324 if (buffer == NULL) {
4325 printk("GDT HA %u, Unknown async. event service %d event no. %d\n",
4326 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
4328 sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d",
4329 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
4334 #ifdef GDTH_STATISTICS
4335 void gdth_timeout(ulong data)
4343 ha = HADATA(gdth_ctr_tab[hanum]);
4344 GDTH_LOCK_HA(ha, flags);
4346 for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i)
4347 if (ha->cmd_tab[i].cmnd != UNUSED_CMND)
4350 for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
4353 TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
4354 act_ints, act_ios, act_stats, act_rq));
4355 act_ints = act_ios = 0;
4357 gdth_timer.expires = jiffies + 30 * HZ;
4358 add_timer(&gdth_timer);
4359 GDTH_UNLOCK_HA(ha, flags);
4363 GDTH_INITFUNC(void, internal_setup(char *str,int *ints))
4366 char *cur_str, *argv;
4368 TRACE2(("internal_setup() str %s ints[0] %d\n",
4369 str ? str:"NULL", ints ? ints[0]:0));
4371 /* read irq[] from ints[] */
4377 for (i = 0; i < argc; ++i)
4382 /* analyse string */
4384 while (argv && (cur_str = strchr(argv, ':'))) {
4385 int val = 0, c = *++cur_str;
4387 if (c == 'n' || c == 'N')
4389 else if (c == 'y' || c == 'Y')
4392 val = (int)simple_strtoul(cur_str, NULL, 0);
4394 if (!strncmp(argv, "disable:", 8))
4396 else if (!strncmp(argv, "reserve_mode:", 13))
4398 else if (!strncmp(argv, "reverse_scan:", 13))
4400 else if (!strncmp(argv, "hdr_channel:", 12))
4402 else if (!strncmp(argv, "max_ids:", 8))
4404 else if (!strncmp(argv, "rescan:", 7))
4406 else if (!strncmp(argv, "virt_ctr:", 9))
4408 else if (!strncmp(argv, "shared_access:", 14))
4409 shared_access = val;
4410 else if (!strncmp(argv, "probe_eisa_isa:", 15))
4411 probe_eisa_isa = val;
4412 else if (!strncmp(argv, "reserve_list:", 13)) {
4413 reserve_list[0] = val;
4414 for (i = 1; i < MAX_RES_ARGS; i++) {
4415 cur_str = strchr(cur_str, ',');
4418 if (!isdigit((int)*++cur_str)) {
4423 (int)simple_strtoul(cur_str, NULL, 0);
4431 if ((argv = strchr(argv, ',')))
4436 GDTH_INITFUNC(int, option_setup(char *str))
4442 TRACE2(("option_setup() str %s\n", str ? str:"NULL"));
4444 while (cur && isdigit(*cur) && i <= MAXHA) {
4445 ints[i++] = simple_strtoul(cur, NULL, 0);
4446 if ((cur = strchr(cur, ',')) != NULL) cur++;
4450 internal_setup(cur, ints);
4454 GDTH_INITFUNC(int, gdth_detect(Scsi_Host_Template *shtp))
4456 struct Scsi_Host *shp;
4457 gdth_pci_str pcistr[MAXHA];
4461 int i,hanum,cnt,ctr,err;
4466 printk("GDT: This driver contains debugging information !! Trace level = %d\n",
4468 printk(" Destination of debugging information: ");
4471 printk("Serial port COM2\n");
4473 printk("Serial port COM1\n");
4476 printk("Console\n");
4481 TRACE(("gdth_detect()\n"));
4484 printk("GDT-HA: Controller driver disabled from command line !\n");
4488 printk("GDT-HA: Storage RAID Controller Driver. Version: %s \n",GDTH_VERSION_STR);
4489 /* initializations */
4490 gdth_polling = TRUE; b = 0;
4491 gdth_clear_events();
4493 /* As default we do not probe for EISA or ISA controllers */
4494 if (probe_eisa_isa) {
4495 /* scanning for controllers, at first: ISA controller */
4496 for (isa_bios=0xc8000UL; isa_bios<=0xd8000UL; isa_bios+=0x8000UL) {
4497 dma_addr_t scratch_dma_handle;
4498 scratch_dma_handle = 0;
4500 if (gdth_ctr_count >= MAXHA)
4502 if (gdth_search_isa(isa_bios)) { /* controller found */
4503 shp = scsi_register(shtp,sizeof(gdth_ext_str));
4508 if (!gdth_init_isa(isa_bios,ha)) {
4509 scsi_unregister(shp);
4515 /* controller found and initialized */
4516 printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
4517 isa_bios,ha->irq,ha->drq);
4519 if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha)) {
4520 printk("GDT-ISA: Unable to allocate IRQ\n");
4521 scsi_unregister(shp);
4524 if (request_dma(ha->drq,"gdth")) {
4525 printk("GDT-ISA: Unable to allocate DMA channel\n");
4526 free_irq(ha->irq,ha);
4527 scsi_unregister(shp);
4530 set_dma_mode(ha->drq,DMA_MODE_CASCADE);
4531 enable_dma(ha->drq);
4532 shp->unchecked_isa_dma = 1;
4534 shp->dma_channel = ha->drq;
4535 hanum = gdth_ctr_count;
4536 gdth_ctr_tab[gdth_ctr_count++] = shp;
4537 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4539 NUMDATA(shp)->hanum = (ushort)hanum;
4540 NUMDATA(shp)->busnum= 0;
4542 ha->pccb = CMDDATA(shp);
4544 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4546 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4547 &scratch_dma_handle);
4548 ha->scratch_phys = scratch_dma_handle;
4549 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4550 &scratch_dma_handle);
4551 ha->msg_phys = scratch_dma_handle;
4553 ha->coal_stat = (gdth_coal_status *)
4554 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4555 MAXOFFSETS, &scratch_dma_handle);
4556 ha->coal_stat_phys = scratch_dma_handle;
4559 ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
4561 ha->scratch_phys = virt_to_bus(ha->pscratch);
4562 ha->pmsg = scsi_init_malloc(sizeof(gdth_msg_str), GFP_ATOMIC | GFP_DMA);
4564 ha->msg_phys = virt_to_bus(ha->pmsg);
4567 scsi_init_malloc(sizeof(gdth_coal_status) * MAXOFFSETS,
4568 GFP_ATOMIC | GFP_DMA);
4570 ha->coal_stat_phys = virt_to_bus(ha->coal_stat);
4573 ha->scratch_busy = FALSE;
4574 ha->req_first = NULL;
4575 ha->tid_cnt = MAX_HDRIVES;
4576 if (max_ids > 0 && max_ids < ha->tid_cnt)
4577 ha->tid_cnt = max_ids;
4578 for (i=0; i<GDTH_MAXCMDS; ++i)
4579 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4580 ha->scan_mode = rescan ? 0x10 : 0;
4582 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4583 !gdth_search_drives(hanum)) {
4584 printk("GDT-ISA: Error during device scan\n");
4587 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4590 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4591 MAXOFFSETS, ha->coal_stat,
4592 ha->coal_stat_phys);
4595 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4596 ha->pscratch, ha->scratch_phys);
4598 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4599 ha->pmsg, ha->msg_phys);
4603 scsi_init_free((void *)ha->coal_stat,
4604 sizeof(gdth_coal_status) * MAXOFFSETS);
4607 scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
4609 scsi_init_free((void *)ha->pmsg, sizeof(gdth_msg_str));
4611 free_irq(ha->irq,ha);
4612 scsi_unregister(shp);
4615 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4616 hdr_channel = ha->bus_cnt;
4617 ha->virt_bus = hdr_channel;
4619 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4620 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
4621 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4622 shp->highmem_io = 0;
4624 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4625 shp->max_cmd_len = 16;
4627 shp->max_id = ha->tid_cnt;
4628 shp->max_lun = MAXLUN;
4629 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4632 /* register addit. SCSI channels as virtual controllers */
4633 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4634 shp = scsi_register(shtp,sizeof(gdth_num_str));
4635 shp->unchecked_isa_dma = 1;
4637 shp->dma_channel = ha->drq;
4638 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4639 NUMDATA(shp)->hanum = (ushort)hanum;
4640 NUMDATA(shp)->busnum = b;
4644 GDTH_INIT_LOCK_HA(ha);
4645 gdth_enable_int(hanum);
4646 #endif /* !__ia64__ */
4650 /* scanning for EISA controllers */
4651 for (eisa_slot=0x1000; eisa_slot<=0x8000; eisa_slot+=0x1000) {
4652 dma_addr_t scratch_dma_handle;
4653 scratch_dma_handle = 0;
4655 if (gdth_ctr_count >= MAXHA)
4657 if (gdth_search_eisa(eisa_slot)) { /* controller found */
4658 shp = scsi_register(shtp,sizeof(gdth_ext_str));
4663 if (!gdth_init_eisa(eisa_slot,ha)) {
4664 scsi_unregister(shp);
4667 /* controller found and initialized */
4668 printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
4669 eisa_slot>>12,ha->irq);
4671 if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha)) {
4672 printk("GDT-EISA: Unable to allocate IRQ\n");
4673 scsi_unregister(shp);
4676 shp->unchecked_isa_dma = 0;
4678 shp->dma_channel = 0xff;
4679 hanum = gdth_ctr_count;
4680 gdth_ctr_tab[gdth_ctr_count++] = shp;
4681 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4683 NUMDATA(shp)->hanum = (ushort)hanum;
4684 NUMDATA(shp)->busnum= 0;
4685 TRACE2(("EISA detect Bus 0: hanum %d\n",
4686 NUMDATA(shp)->hanum));
4688 ha->pccb = CMDDATA(shp);
4690 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4692 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4693 &scratch_dma_handle);
4694 ha->scratch_phys = scratch_dma_handle;
4695 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4696 &scratch_dma_handle);
4697 ha->msg_phys = scratch_dma_handle;
4699 ha->coal_stat = (gdth_coal_status *)
4700 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4701 MAXOFFSETS, &scratch_dma_handle);
4702 ha->coal_stat_phys = scratch_dma_handle;
4705 pci_map_single(ha->pdev,ha->pccb,
4706 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
4708 ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
4710 ha->scratch_phys = virt_to_bus(ha->pscratch);
4711 ha->pmsg = scsi_init_malloc(sizeof(gdth_msg_str), GFP_ATOMIC | GFP_DMA);
4713 ha->msg_phys = virt_to_bus(ha->pmsg);
4716 scsi_init_malloc(sizeof(gdth_coal_status) * MAXOFFSETS,
4717 GFP_ATOMIC | GFP_DMA);
4719 ha->coal_stat_phys = virt_to_bus(ha->coal_stat);
4721 ha->ccb_phys = virt_to_bus(ha->pccb);
4723 ha->scratch_busy = FALSE;
4724 ha->req_first = NULL;
4725 ha->tid_cnt = MAX_HDRIVES;
4726 if (max_ids > 0 && max_ids < ha->tid_cnt)
4727 ha->tid_cnt = max_ids;
4728 for (i=0; i<GDTH_MAXCMDS; ++i)
4729 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4730 ha->scan_mode = rescan ? 0x10 : 0;
4732 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4733 !gdth_search_drives(hanum)) {
4734 printk("GDT-EISA: Error during device scan\n");
4737 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4740 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4741 MAXOFFSETS, ha->coal_stat,
4742 ha->coal_stat_phys);
4745 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4746 ha->pscratch, ha->scratch_phys);
4748 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4749 ha->pmsg, ha->msg_phys);
4751 pci_unmap_single(ha->pdev,ha->ccb_phys,
4752 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
4756 scsi_init_free((void *)ha->coal_stat,
4757 sizeof(gdth_coal_status) * MAXOFFSETS);
4760 scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
4762 scsi_init_free((void *)ha->pmsg, sizeof(gdth_msg_str));
4764 free_irq(ha->irq,ha);
4765 scsi_unregister(shp);
4768 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4769 hdr_channel = ha->bus_cnt;
4770 ha->virt_bus = hdr_channel;
4772 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4773 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
4774 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4775 shp->highmem_io = 0;
4777 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4778 shp->max_cmd_len = 16;
4780 shp->max_id = ha->tid_cnt;
4781 shp->max_lun = MAXLUN;
4782 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4785 /* register addit. SCSI channels as virtual controllers */
4786 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4787 shp = scsi_register(shtp,sizeof(gdth_num_str));
4788 shp->unchecked_isa_dma = 0;
4790 shp->dma_channel = 0xff;
4791 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4792 NUMDATA(shp)->hanum = (ushort)hanum;
4793 NUMDATA(shp)->busnum = b;
4797 GDTH_INIT_LOCK_HA(ha);
4798 gdth_enable_int(hanum);
4803 /* scanning for PCI controllers */
4804 cnt = gdth_search_pci(pcistr);
4805 printk("GDT-HA: Found %d PCI Storage RAID Controllers\n",cnt);
4806 gdth_sort_pci(pcistr,cnt);
4807 for (ctr = 0; ctr < cnt; ++ctr) {
4808 dma_addr_t scratch_dma_handle;
4809 scratch_dma_handle = 0;
4811 if (gdth_ctr_count >= MAXHA)
4813 shp = scsi_register(shtp,sizeof(gdth_ext_str));
4818 if (!gdth_init_pci(&pcistr[ctr],ha)) {
4819 scsi_unregister(shp);
4822 /* controller found and initialized */
4823 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
4824 pcistr[ctr].bus,PCI_SLOT(pcistr[ctr].device_fn),ha->irq);
4826 if (request_irq(ha->irq, gdth_interrupt,
4827 SA_INTERRUPT|SA_SHIRQ, "gdth", ha))
4829 printk("GDT-PCI: Unable to allocate IRQ\n");
4830 scsi_unregister(shp);
4833 shp->unchecked_isa_dma = 0;
4835 shp->dma_channel = 0xff;
4836 hanum = gdth_ctr_count;
4837 gdth_ctr_tab[gdth_ctr_count++] = shp;
4838 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4840 NUMDATA(shp)->hanum = (ushort)hanum;
4841 NUMDATA(shp)->busnum= 0;
4843 ha->pccb = CMDDATA(shp);
4845 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4846 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4847 &scratch_dma_handle);
4848 ha->scratch_phys = scratch_dma_handle;
4849 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4850 &scratch_dma_handle);
4851 ha->msg_phys = scratch_dma_handle;
4853 ha->coal_stat = (gdth_coal_status *)
4854 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4855 MAXOFFSETS, &scratch_dma_handle);
4856 ha->coal_stat_phys = scratch_dma_handle;
4859 ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
4861 ha->scratch_phys = virt_to_bus(ha->pscratch);
4862 ha->pmsg = scsi_init_malloc(sizeof(gdth_msg_str), GFP_ATOMIC | GFP_DMA);
4864 ha->msg_phys = virt_to_bus(ha->pmsg);
4867 scsi_init_malloc(sizeof(gdth_coal_status) * MAXOFFSETS,
4868 GFP_ATOMIC | GFP_DMA);
4870 ha->coal_stat_phys = virt_to_bus(ha->coal_stat);
4873 ha->scratch_busy = FALSE;
4874 ha->req_first = NULL;
4875 ha->tid_cnt = pcistr[ctr].device_id >= 0x200 ? MAXID : MAX_HDRIVES;
4876 if (max_ids > 0 && max_ids < ha->tid_cnt)
4877 ha->tid_cnt = max_ids;
4878 for (i=0; i<GDTH_MAXCMDS; ++i)
4879 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4880 ha->scan_mode = rescan ? 0x10 : 0;
4883 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4884 !gdth_search_drives(hanum)) {
4887 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4888 hdr_channel = ha->bus_cnt;
4889 ha->virt_bus = hdr_channel;
4891 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4892 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4893 scsi_set_device(shp, &pcistr[ctr].pdev->dev);
4895 scsi_set_pci_device(shp, pcistr[ctr].pdev);
4897 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat &GDT_64BIT)||
4898 /* 64-bit DMA only supported from FW >= x.43 */
4899 (!ha->dma64_support)) {
4900 if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) {
4901 printk(KERN_WARNING "GDT-PCI %d: Unable to set 32-bit DMA\n", hanum);
4905 shp->max_cmd_len = 16;
4906 if (!pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffffffffffffULL)) {
4907 printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);
4908 } else if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) {
4909 printk(KERN_WARNING "GDT-PCI %d: Unable to set 64/32-bit DMA\n", hanum);
4917 printk("GDT-PCI %d: Error during device scan\n", hanum);
4920 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4923 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4924 MAXOFFSETS, ha->coal_stat,
4925 ha->coal_stat_phys);
4928 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4929 ha->pscratch, ha->scratch_phys);
4931 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4932 ha->pmsg, ha->msg_phys);
4936 scsi_init_free((void *)ha->coal_stat,
4937 sizeof(gdth_coal_status) * MAXOFFSETS);
4940 scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
4942 scsi_init_free((void *)ha->pmsg, sizeof(gdth_msg_str));
4944 free_irq(ha->irq,ha);
4945 scsi_unregister(shp);
4949 shp->max_id = ha->tid_cnt;
4950 shp->max_lun = MAXLUN;
4951 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4954 /* register addit. SCSI channels as virtual controllers */
4955 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4956 shp = scsi_register(shtp,sizeof(gdth_num_str));
4957 shp->unchecked_isa_dma = 0;
4959 shp->dma_channel = 0xff;
4960 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4961 NUMDATA(shp)->hanum = (ushort)hanum;
4962 NUMDATA(shp)->busnum = b;
4967 GDTH_INIT_LOCK_HA(ha);
4968 gdth_enable_int(hanum);
4971 TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count));
4972 if (gdth_ctr_count > 0) {
4973 #ifdef GDTH_STATISTICS
4974 TRACE2(("gdth_detect(): Initializing timer !\n"));
4975 init_timer(&gdth_timer);
4976 gdth_timer.expires = jiffies + HZ;
4977 gdth_timer.data = 0L;
4978 gdth_timer.function = gdth_timeout;
4979 add_timer(&gdth_timer);
4981 major = register_chrdev(0,"gdth",&gdth_fops);
4982 register_reboot_notifier(&gdth_notifier);
4984 gdth_polling = FALSE;
4985 return gdth_ctr_vcount;
4989 int gdth_release(struct Scsi_Host *shp)
4994 TRACE2(("gdth_release()\n"));
4995 if (NUMDATA(shp)->busnum == 0) {
4996 hanum = NUMDATA(shp)->hanum;
4997 ha = HADATA(gdth_ctr_tab[hanum]);
4998 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5000 scsi_free_host_dev(ha->sdev);
5007 free_irq(shp->irq,ha);
5010 if (shp->dma_channel != 0xff) {
5011 free_dma(shp->dma_channel);
5014 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5017 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
5018 MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys);
5021 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5022 ha->pscratch, ha->scratch_phys);
5024 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5025 ha->pmsg, ha->msg_phys);
5027 pci_unmap_single(ha->pdev,ha->ccb_phys,
5028 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
5032 scsi_init_free((void *)ha->coal_stat,
5033 sizeof(gdth_coal_status) * MAXOFFSETS);
5036 scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
5038 scsi_init_free((void *)ha->pmsg, sizeof(gdth_msg_str));
5040 gdth_ctr_released++;
5041 TRACE2(("gdth_release(): HA %d of %d\n",
5042 gdth_ctr_released, gdth_ctr_count));
5044 if (gdth_ctr_released == gdth_ctr_count) {
5045 #ifdef GDTH_STATISTICS
5046 del_timer(&gdth_timer);
5048 unregister_chrdev(major,"gdth");
5049 unregister_reboot_notifier(&gdth_notifier);
5053 scsi_unregister(shp);
5058 static const char *gdth_ctr_name(int hanum)
5062 TRACE2(("gdth_ctr_name()\n"));
5064 ha = HADATA(gdth_ctr_tab[hanum]);
5066 if (ha->type == GDT_EISA) {
5067 switch (ha->stype) {
5069 return("GDT3000/3020");
5071 return("GDT3000A/3020A/3050A");
5073 return("GDT3000B/3010A");
5075 } else if (ha->type == GDT_ISA) {
5076 return("GDT2000/2020");
5077 } else if (ha->type == GDT_PCI) {
5078 switch (ha->stype) {
5079 case PCI_DEVICE_ID_VORTEX_GDT60x0:
5080 return("GDT6000/6020/6050");
5081 case PCI_DEVICE_ID_VORTEX_GDT6000B:
5082 return("GDT6000B/6010");
5085 /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
5090 const char *gdth_info(struct Scsi_Host *shp)
5095 TRACE2(("gdth_info()\n"));
5096 hanum = NUMDATA(shp)->hanum;
5097 ha = HADATA(gdth_ctr_tab[hanum]);
5099 return ((const char *)ha->binfo.type_string);
5102 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
5103 /* old error handling */
5104 int gdth_abort(Scsi_Cmnd *scp)
5106 TRACE2(("gdth_abort() reason %d\n",scp->abort_reason));
5107 return SCSI_ABORT_SNOOZE;
5110 int gdth_reset(Scsi_Cmnd *scp, unsigned int reset_flags)
5112 TRACE2(("gdth_reset()\n"));
5113 return SCSI_RESET_PUNT;
5117 /* new error handling */
5118 int gdth_eh_abort(Scsi_Cmnd *scp)
5120 TRACE2(("gdth_eh_abort()\n"));
5124 int gdth_eh_device_reset(Scsi_Cmnd *scp)
5126 TRACE2(("gdth_eh_device_reset()\n"));
5130 int gdth_eh_bus_reset(Scsi_Cmnd *scp)
5138 TRACE2(("gdth_eh_bus_reset()\n"));
5139 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5140 hanum = NUMDATA(scp->device->host)->hanum;
5141 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
5143 hanum = NUMDATA(scp->host)->hanum;
5144 b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
5146 ha = HADATA(gdth_ctr_tab[hanum]);
5148 /* clear command tab */
5149 GDTH_LOCK_HA(ha, flags);
5150 for (i = 0; i < GDTH_MAXCMDS; ++i) {
5151 cmnd = ha->cmd_tab[i].cmnd;
5152 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5153 if (!SPECIAL_SCP(cmnd) && cmnd->device->channel == b)
5155 if (!SPECIAL_SCP(cmnd) && cmnd->channel == b)
5157 ha->cmd_tab[i].cmnd = UNUSED_CMND;
5159 GDTH_UNLOCK_HA(ha, flags);
5161 if (b == ha->virt_bus) {
5163 for (i = 0; i < MAX_HDRIVES; ++i) {
5164 if (ha->hdr[i].present) {
5165 GDTH_LOCK_HA(ha, flags);
5166 gdth_polling = TRUE;
5167 while (gdth_test_busy(hanum))
5169 if (gdth_internal_cmd(hanum, CACHESERVICE,
5170 GDT_CLUST_RESET, i, 0, 0))
5171 ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED;
5172 gdth_polling = FALSE;
5173 GDTH_UNLOCK_HA(ha, flags);
5178 GDTH_LOCK_HA(ha, flags);
5179 for (i = 0; i < MAXID; ++i)
5180 ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0;
5181 gdth_polling = TRUE;
5182 while (gdth_test_busy(hanum))
5184 gdth_internal_cmd(hanum, SCSIRAWSERVICE, GDT_RESET_BUS,
5185 BUS_L2P(ha,b), 0, 0);
5186 gdth_polling = FALSE;
5187 GDTH_UNLOCK_HA(ha, flags);
5192 int gdth_eh_host_reset(Scsi_Cmnd *scp)
5194 TRACE2(("gdth_eh_host_reset()\n"));
5199 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5200 int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip)
5202 int gdth_bios_param(Disk *disk,kdev_t dev,int *ip)
5208 struct scsi_device *sd;
5211 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5216 capacity = disk->capacity;
5218 hanum = NUMDATA(sd->host)->hanum;
5219 b = virt_ctr ? NUMDATA(sd->host)->busnum : sd->channel;
5221 TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", hanum, b, t));
5222 ha = HADATA(gdth_ctr_tab[hanum]);
5224 if (b != ha->virt_bus || ha->hdr[t].heads == 0) {
5225 /* raw device or host drive without mapping information */
5226 TRACE2(("Evaluate mapping\n"));
5227 gdth_eval_mapping(capacity,&ip[2],&ip[0],&ip[1]);
5229 ip[0] = ha->hdr[t].heads;
5230 ip[1] = ha->hdr[t].secs;
5231 ip[2] = capacity / ip[0] / ip[1];
5234 TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
5235 ip[0],ip[1],ip[2]));
5240 int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *))
5245 TRACE(("gdth_queuecommand() cmd 0x%x\n", scp->cmnd[0]));
5247 scp->scsi_done = (void *)done;
5248 scp->SCp.have_data_in = 1;
5249 scp->SCp.phase = -1;
5250 scp->SCp.sent_command = -1;
5251 scp->SCp.Status = GDTH_MAP_NONE;
5252 scp->SCp.buffer = (struct scatterlist *)NULL;
5253 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5254 hanum = NUMDATA(scp->device->host)->hanum;
5256 hanum = NUMDATA(scp->host)->hanum;
5258 #ifdef GDTH_STATISTICS
5262 priority = DEFAULT_PRI;
5263 if (scp->done == gdth_scsi_done)
5264 priority = scp->SCp.this_residual;
5265 gdth_update_timeout(hanum, scp, scp->timeout_per_command * 6);
5266 gdth_putq( hanum, scp, priority );
5272 static int gdth_open(struct inode *inode, struct file *filep)
5274 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5278 for (i = 0; i < gdth_ctr_count; i++) {
5279 ha = HADATA(gdth_ctr_tab[i]);
5281 ha->sdev = scsi_get_host_dev(gdth_ctr_tab[i]);
5285 TRACE(("gdth_open()\n"));
5289 static int gdth_close(struct inode *inode, struct file *filep)
5291 TRACE(("gdth_close()\n"));
5295 static int ioc_event(void __user *arg)
5297 gdth_ioctl_event evt;
5301 if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event)) ||
5302 evt.ionode >= gdth_ctr_count)
5304 ha = HADATA(gdth_ctr_tab[evt.ionode]);
5306 if (evt.erase == 0xff) {
5307 if (evt.event.event_source == ES_TEST)
5308 evt.event.event_data.size=sizeof(evt.event.event_data.eu.test);
5309 else if (evt.event.event_source == ES_DRIVER)
5310 evt.event.event_data.size=sizeof(evt.event.event_data.eu.driver);
5311 else if (evt.event.event_source == ES_SYNC)
5312 evt.event.event_data.size=sizeof(evt.event.event_data.eu.sync);
5314 evt.event.event_data.size=sizeof(evt.event.event_data.eu.async);
5315 GDTH_LOCK_HA(ha, flags);
5316 gdth_store_event(ha, evt.event.event_source, evt.event.event_idx,
5317 &evt.event.event_data);
5318 GDTH_UNLOCK_HA(ha, flags);
5319 } else if (evt.erase == 0xfe) {
5320 gdth_clear_events();
5321 } else if (evt.erase == 0) {
5322 evt.handle = gdth_read_event(ha, evt.handle, &evt.event);
5324 gdth_readapp_event(ha, evt.erase, &evt.event);
5326 if (copy_to_user(arg, &evt, sizeof(gdth_ioctl_event)))
5331 static int ioc_lockdrv(void __user *arg)
5333 gdth_ioctl_lockdrv ldrv;
5338 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)) ||
5339 ldrv.ionode >= gdth_ctr_count)
5341 ha = HADATA(gdth_ctr_tab[ldrv.ionode]);
5343 for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) {
5345 if (j >= MAX_HDRIVES || !ha->hdr[j].present)
5348 GDTH_LOCK_HA(ha, flags);
5349 ha->hdr[j].lock = 1;
5350 GDTH_UNLOCK_HA(ha, flags);
5351 gdth_wait_completion(ldrv.ionode, ha->bus_cnt, j);
5352 gdth_stop_timeout(ldrv.ionode, ha->bus_cnt, j);
5354 GDTH_LOCK_HA(ha, flags);
5355 ha->hdr[j].lock = 0;
5356 GDTH_UNLOCK_HA(ha, flags);
5357 gdth_start_timeout(ldrv.ionode, ha->bus_cnt, j);
5358 gdth_next(ldrv.ionode);
5364 static int ioc_resetdrv(void __user *arg, char *cmnd)
5366 gdth_ioctl_reset res;
5370 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5372 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5378 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
5379 res.ionode >= gdth_ctr_count || res.number >= MAX_HDRIVES)
5382 ha = HADATA(gdth_ctr_tab[hanum]);
5384 if (!ha->hdr[res.number].present)
5386 memset(&cmd, 0, sizeof(gdth_cmd_str));
5387 cmd.Service = CACHESERVICE;
5388 cmd.OpCode = GDT_CLUST_RESET;
5389 if (ha->cache_feat & GDT_64BIT)
5390 cmd.u.cache64.DeviceNo = res.number;
5392 cmd.u.cache.DeviceNo = res.number;
5393 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5394 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5397 srp->sr_cmd_len = 12;
5399 gdth_do_req(srp, &cmd, cmnd, 30);
5400 res.status = (ushort)srp->sr_command->SCp.Status;
5401 scsi_release_request(srp);
5402 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5403 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5408 gdth_do_cmd(scp, &cmd, cmnd, 30);
5409 res.status = (ushort)scp->SCp.Status;
5410 scsi_release_command(scp);
5412 memset(&ha->sdev,0,sizeof(Scsi_Device));
5413 memset(&scp, 0,sizeof(Scsi_Cmnd));
5414 ha->sdev.host = scp.host = gdth_ctr_tab[hanum];
5415 ha->sdev.id = scp.target = ha->sdev.host->this_id;
5416 scp.device = &ha->sdev;
5417 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5418 res.status = (ushort)scp.SCp.Status;
5420 if (copy_to_user(arg, &res, sizeof(gdth_ioctl_reset)))
5425 static int ioc_general(void __user *arg, char *cmnd)
5427 gdth_ioctl_general gen;
5432 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5434 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5440 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)) ||
5441 gen.ionode >= gdth_ctr_count)
5444 ha = HADATA(gdth_ctr_tab[hanum]);
5445 if (gen.data_len + gen.sense_len != 0) {
5446 if (!(buf = gdth_ioctl_alloc(hanum, gen.data_len + gen.sense_len,
5449 if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general),
5450 gen.data_len + gen.sense_len)) {
5451 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5455 if (gen.command.OpCode == GDT_IOCTL) {
5456 gen.command.u.ioctl.p_param = paddr;
5457 } else if (gen.command.Service == CACHESERVICE) {
5458 if (ha->cache_feat & GDT_64BIT) {
5459 /* copy elements from 32-bit IOCTL structure */
5460 gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt;
5461 gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo;
5462 gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo;
5464 if (ha->cache_feat & SCATTER_GATHER) {
5465 gen.command.u.cache64.DestAddr = (ulong64)-1;
5466 gen.command.u.cache64.sg_canz = 1;
5467 gen.command.u.cache64.sg_lst[0].sg_ptr = paddr;
5468 gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len;
5469 gen.command.u.cache64.sg_lst[1].sg_len = 0;
5471 gen.command.u.cache64.DestAddr = paddr;
5472 gen.command.u.cache64.sg_canz = 0;
5475 if (ha->cache_feat & SCATTER_GATHER) {
5476 gen.command.u.cache.DestAddr = 0xffffffff;
5477 gen.command.u.cache.sg_canz = 1;
5478 gen.command.u.cache.sg_lst[0].sg_ptr = (ulong32)paddr;
5479 gen.command.u.cache.sg_lst[0].sg_len = gen.data_len;
5480 gen.command.u.cache.sg_lst[1].sg_len = 0;
5482 gen.command.u.cache.DestAddr = paddr;
5483 gen.command.u.cache.sg_canz = 0;
5486 } else if (gen.command.Service == SCSIRAWSERVICE) {
5487 if (ha->raw_feat & GDT_64BIT) {
5488 /* copy elements from 32-bit IOCTL structure */
5490 gen.command.u.raw64.sense_len = gen.command.u.raw.sense_len;
5491 gen.command.u.raw64.bus = gen.command.u.raw.bus;
5492 gen.command.u.raw64.lun = gen.command.u.raw.lun;
5493 gen.command.u.raw64.target = gen.command.u.raw.target;
5494 memcpy(cmd, gen.command.u.raw.cmd, 16);
5495 memcpy(gen.command.u.raw64.cmd, cmd, 16);
5496 gen.command.u.raw64.clen = gen.command.u.raw.clen;
5497 gen.command.u.raw64.sdlen = gen.command.u.raw.sdlen;
5498 gen.command.u.raw64.direction = gen.command.u.raw.direction;
5500 if (ha->raw_feat & SCATTER_GATHER) {
5501 gen.command.u.raw64.sdata = (ulong64)-1;
5502 gen.command.u.raw64.sg_ranz = 1;
5503 gen.command.u.raw64.sg_lst[0].sg_ptr = paddr;
5504 gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len;
5505 gen.command.u.raw64.sg_lst[1].sg_len = 0;
5507 gen.command.u.raw64.sdata = paddr;
5508 gen.command.u.raw64.sg_ranz = 0;
5510 gen.command.u.raw64.sense_data = paddr + gen.data_len;
5512 if (ha->raw_feat & SCATTER_GATHER) {
5513 gen.command.u.raw.sdata = 0xffffffff;
5514 gen.command.u.raw.sg_ranz = 1;
5515 gen.command.u.raw.sg_lst[0].sg_ptr = (ulong32)paddr;
5516 gen.command.u.raw.sg_lst[0].sg_len = gen.data_len;
5517 gen.command.u.raw.sg_lst[1].sg_len = 0;
5519 gen.command.u.raw.sdata = paddr;
5520 gen.command.u.raw.sg_ranz = 0;
5522 gen.command.u.raw.sense_data = (ulong32)paddr + gen.data_len;
5525 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5530 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5531 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5534 srp->sr_cmd_len = 12;
5536 gdth_do_req(srp, &gen.command, cmnd, gen.timeout);
5537 gen.status = srp->sr_command->SCp.Status;
5538 gen.info = srp->sr_command->SCp.Message;
5539 scsi_release_request(srp);
5540 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5541 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5546 gdth_do_cmd(scp, &gen.command, cmnd, gen.timeout);
5547 gen.status = scp->SCp.Status;
5548 gen.info = scp->SCp.Message;
5549 scsi_release_command(scp);
5551 memset(&ha->sdev,0,sizeof(Scsi_Device));
5552 memset(&scp, 0,sizeof(Scsi_Cmnd));
5553 ha->sdev.host = scp.host = gdth_ctr_tab[hanum];
5554 ha->sdev.id = scp.target = ha->sdev.host->this_id;
5555 scp.device = &ha->sdev;
5556 gdth_do_cmd(&scp, &gen.command, cmnd, gen.timeout);
5557 gen.status = scp.SCp.Status;
5558 gen.info = scp.SCp.Message;
5561 if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf,
5562 gen.data_len + gen.sense_len)) {
5563 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5566 if (copy_to_user(arg, &gen,
5567 sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) {
5568 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5571 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5575 static int ioc_hdrlist(void __user *arg, char *cmnd)
5577 gdth_ioctl_rescan rsc;
5582 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5584 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5590 if (copy_from_user(&rsc, arg, sizeof(gdth_ioctl_rescan)) ||
5591 rsc.ionode >= gdth_ctr_count)
5594 ha = HADATA(gdth_ctr_tab[hanum]);
5595 memset(&cmd, 0, sizeof(gdth_cmd_str));
5597 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5598 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5601 srp->sr_cmd_len = 12;
5603 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5604 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5610 memset(&ha->sdev,0,sizeof(Scsi_Device));
5611 memset(&scp, 0,sizeof(Scsi_Cmnd));
5612 ha->sdev.host = scp.host = gdth_ctr_tab[hanum];
5613 ha->sdev.id = scp.target = ha->sdev.host->this_id;
5614 scp.device = &ha->sdev;
5617 for (i = 0; i < MAX_HDRIVES; ++i) {
5618 if (!ha->hdr[i].present) {
5619 rsc.hdr_list[i].bus = 0xff;
5622 rsc.hdr_list[i].bus = ha->virt_bus;
5623 rsc.hdr_list[i].target = i;
5624 rsc.hdr_list[i].lun = 0;
5625 rsc.hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
5626 if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) {
5627 cmd.Service = CACHESERVICE;
5628 cmd.OpCode = GDT_CLUST_INFO;
5629 if (ha->cache_feat & GDT_64BIT)
5630 cmd.u.cache64.DeviceNo = i;
5632 cmd.u.cache.DeviceNo = i;
5633 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5634 gdth_do_req(srp, &cmd, cmnd, 30);
5635 if (srp->sr_command->SCp.Status == S_OK)
5636 rsc.hdr_list[i].cluster_type = srp->sr_command->SCp.Message;
5637 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5638 gdth_do_cmd(scp, &cmd, cmnd, 30);
5639 if (scp->SCp.Status == S_OK)
5640 rsc.hdr_list[i].cluster_type = scp->SCp.Message;
5642 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5643 if (scp.SCp.Status == S_OK)
5644 rsc.hdr_list[i].cluster_type = scp.SCp.Message;
5648 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5649 scsi_release_request(srp);
5650 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5651 scsi_release_command(scp);
5654 if (copy_to_user(arg, &rsc, sizeof(gdth_ioctl_rescan)))
5659 static int ioc_rescan(void __user *arg, char *cmnd)
5661 gdth_ioctl_rescan rsc;
5663 ushort i, status, hdr_cnt;
5665 int hanum, cyls, hds, secs;
5668 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5670 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5676 if (copy_from_user(&rsc, arg, sizeof(gdth_ioctl_rescan)) ||
5677 rsc.ionode >= gdth_ctr_count)
5680 ha = HADATA(gdth_ctr_tab[hanum]);
5681 memset(&cmd, 0, sizeof(gdth_cmd_str));
5683 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5684 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5687 srp->sr_cmd_len = 12;
5689 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5690 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5696 memset(&ha->sdev,0,sizeof(Scsi_Device));
5697 memset(&scp, 0,sizeof(Scsi_Cmnd));
5698 ha->sdev.host = scp.host = gdth_ctr_tab[hanum];
5699 ha->sdev.id = scp.target = ha->sdev.host->this_id;
5700 scp.device = &ha->sdev;
5703 if (rsc.flag == 0) {
5704 /* old method: re-init. cache service */
5705 cmd.Service = CACHESERVICE;
5706 if (ha->cache_feat & GDT_64BIT) {
5707 cmd.OpCode = GDT_X_INIT_HOST;
5708 cmd.u.cache64.DeviceNo = LINUX_OS;
5710 cmd.OpCode = GDT_INIT;
5711 cmd.u.cache.DeviceNo = LINUX_OS;
5713 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5714 gdth_do_req(srp, &cmd, cmnd, 30);
5715 status = (ushort)srp->sr_command->SCp.Status;
5716 info = (ulong32)srp->sr_command->SCp.Message;
5717 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5718 gdth_do_cmd(scp, &cmd, cmnd, 30);
5719 status = (ushort)scp->SCp.Status;
5720 info = (ulong32)scp->SCp.Message;
5722 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5723 status = (ushort)scp.SCp.Status;
5724 info = (ulong32)scp.SCp.Message;
5727 hdr_cnt = (status == S_OK ? (ushort)info : 0);
5732 for (; i < hdr_cnt && i < MAX_HDRIVES; ++i) {
5733 cmd.Service = CACHESERVICE;
5734 cmd.OpCode = GDT_INFO;
5735 if (ha->cache_feat & GDT_64BIT)
5736 cmd.u.cache64.DeviceNo = i;
5738 cmd.u.cache.DeviceNo = i;
5739 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5740 gdth_do_req(srp, &cmd, cmnd, 30);
5741 status = (ushort)srp->sr_command->SCp.Status;
5742 info = (ulong32)srp->sr_command->SCp.Message;
5743 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5744 gdth_do_cmd(scp, &cmd, cmnd, 30);
5745 status = (ushort)scp->SCp.Status;
5746 info = (ulong32)scp->SCp.Message;
5748 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5749 status = (ushort)scp.SCp.Status;
5750 info = (ulong32)scp.SCp.Message;
5752 GDTH_LOCK_HA(ha, flags);
5753 rsc.hdr_list[i].bus = ha->virt_bus;
5754 rsc.hdr_list[i].target = i;
5755 rsc.hdr_list[i].lun = 0;
5756 if (status != S_OK) {
5757 ha->hdr[i].present = FALSE;
5759 ha->hdr[i].present = TRUE;
5760 ha->hdr[i].size = info;
5761 /* evaluate mapping */
5762 ha->hdr[i].size &= ~SECS32;
5763 gdth_eval_mapping(ha->hdr[i].size,&cyls,&hds,&secs);
5764 ha->hdr[i].heads = hds;
5765 ha->hdr[i].secs = secs;
5767 ha->hdr[i].size = cyls * hds * secs;
5769 GDTH_UNLOCK_HA(ha, flags);
5773 /* extended info, if GDT_64BIT, for drives > 2 TB */
5774 /* but we need ha->info2, not yet stored in scp->SCp */
5776 /* devtype, cluster info, R/W attribs */
5777 cmd.Service = CACHESERVICE;
5778 cmd.OpCode = GDT_DEVTYPE;
5779 if (ha->cache_feat & GDT_64BIT)
5780 cmd.u.cache64.DeviceNo = i;
5782 cmd.u.cache.DeviceNo = i;
5783 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5784 gdth_do_req(srp, &cmd, cmnd, 30);
5785 status = (ushort)srp->sr_command->SCp.Status;
5786 info = (ulong32)srp->sr_command->SCp.Message;
5787 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5788 gdth_do_cmd(scp, &cmd, cmnd, 30);
5789 status = (ushort)scp->SCp.Status;
5790 info = (ulong32)scp->SCp.Message;
5792 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5793 status = (ushort)scp.SCp.Status;
5794 info = (ulong32)scp.SCp.Message;
5796 GDTH_LOCK_HA(ha, flags);
5797 ha->hdr[i].devtype = (status == S_OK ? (ushort)info : 0);
5798 GDTH_UNLOCK_HA(ha, flags);
5800 cmd.Service = CACHESERVICE;
5801 cmd.OpCode = GDT_CLUST_INFO;
5802 if (ha->cache_feat & GDT_64BIT)
5803 cmd.u.cache64.DeviceNo = i;
5805 cmd.u.cache.DeviceNo = i;
5806 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5807 gdth_do_req(srp, &cmd, cmnd, 30);
5808 status = (ushort)srp->sr_command->SCp.Status;
5809 info = (ulong32)srp->sr_command->SCp.Message;
5810 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5811 gdth_do_cmd(scp, &cmd, cmnd, 30);
5812 status = (ushort)scp->SCp.Status;
5813 info = (ulong32)scp->SCp.Message;
5815 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5816 status = (ushort)scp.SCp.Status;
5817 info = (ulong32)scp.SCp.Message;
5819 GDTH_LOCK_HA(ha, flags);
5820 ha->hdr[i].cluster_type =
5821 ((status == S_OK && !shared_access) ? (ushort)info : 0);
5822 GDTH_UNLOCK_HA(ha, flags);
5823 rsc.hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
5825 cmd.Service = CACHESERVICE;
5826 cmd.OpCode = GDT_RW_ATTRIBS;
5827 if (ha->cache_feat & GDT_64BIT)
5828 cmd.u.cache64.DeviceNo = i;
5830 cmd.u.cache.DeviceNo = i;
5831 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5832 gdth_do_req(srp, &cmd, cmnd, 30);
5833 status = (ushort)srp->sr_command->SCp.Status;
5834 info = (ulong32)srp->sr_command->SCp.Message;
5835 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5836 gdth_do_cmd(scp, &cmd, cmnd, 30);
5837 status = (ushort)scp->SCp.Status;
5838 info = (ulong32)scp->SCp.Message;
5840 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5841 status = (ushort)scp.SCp.Status;
5842 info = (ulong32)scp.SCp.Message;
5844 GDTH_LOCK_HA(ha, flags);
5845 ha->hdr[i].rw_attribs = (status == S_OK ? (ushort)info : 0);
5846 GDTH_UNLOCK_HA(ha, flags);
5848 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5849 scsi_release_request(srp);
5850 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5851 scsi_release_command(scp);
5854 if (copy_to_user(arg, &rsc, sizeof(gdth_ioctl_rescan)))
5859 static int gdth_ioctl(struct inode *inode, struct file *filep,
5860 unsigned int cmd, unsigned long arg)
5863 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5865 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5871 char cmnd[MAX_COMMAND_SIZE];
5872 void __user *argp = (void __user *)arg;
5874 memset(cmnd, 0xff, 12);
5876 TRACE(("gdth_ioctl() cmd 0x%x\n", cmd));
5879 case GDTIOCTL_CTRCNT:
5881 int cnt = gdth_ctr_count;
5882 if (put_user(cnt, (int __user *)argp))
5887 case GDTIOCTL_DRVERS:
5889 int ver = (GDTH_VERSION<<8) | GDTH_SUBVERSION;
5890 if (put_user(ver, (int __user *)argp))
5895 case GDTIOCTL_OSVERS:
5897 gdth_ioctl_osvers osv;
5899 osv.version = (unchar)(LINUX_VERSION_CODE >> 16);
5900 osv.subversion = (unchar)(LINUX_VERSION_CODE >> 8);
5901 osv.revision = (ushort)(LINUX_VERSION_CODE & 0xff);
5902 if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers)))
5907 case GDTIOCTL_CTRTYPE:
5909 gdth_ioctl_ctrtype ctrt;
5911 if (copy_from_user(&ctrt, argp, sizeof(gdth_ioctl_ctrtype)) ||
5912 ctrt.ionode >= gdth_ctr_count)
5914 ha = HADATA(gdth_ctr_tab[ctrt.ionode]);
5915 if (ha->type == GDT_ISA || ha->type == GDT_EISA) {
5916 ctrt.type = (unchar)((ha->stype>>20) - 0x10);
5918 if (ha->type != GDT_PCIMPR) {
5919 ctrt.type = (unchar)((ha->stype<<4) + 6);
5922 (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe);
5923 if (ha->stype >= 0x300)
5924 ctrt.ext_type = 0x6000 | ha->subdevice_id;
5926 ctrt.ext_type = 0x6000 | ha->stype;
5928 ctrt.device_id = ha->stype;
5929 ctrt.sub_device_id = ha->subdevice_id;
5931 ctrt.info = ha->brd_phys;
5932 ctrt.oem_id = ha->oem_id;
5933 if (copy_to_user(argp, &ctrt, sizeof(gdth_ioctl_ctrtype)))
5938 case GDTIOCTL_GENERAL:
5939 return ioc_general(argp, cmnd);
5941 case GDTIOCTL_EVENT:
5942 return ioc_event(argp);
5944 case GDTIOCTL_LOCKDRV:
5945 return ioc_lockdrv(argp);
5947 case GDTIOCTL_LOCKCHN:
5949 gdth_ioctl_lockchn lchn;
5952 if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) ||
5953 lchn.ionode >= gdth_ctr_count)
5955 ha = HADATA(gdth_ctr_tab[lchn.ionode]);
5958 if (i < ha->bus_cnt) {
5960 GDTH_LOCK_HA(ha, flags);
5961 ha->raw[i].lock = 1;
5962 GDTH_UNLOCK_HA(ha, flags);
5963 for (j = 0; j < ha->tid_cnt; ++j) {
5964 gdth_wait_completion(lchn.ionode, i, j);
5965 gdth_stop_timeout(lchn.ionode, i, j);
5968 GDTH_LOCK_HA(ha, flags);
5969 ha->raw[i].lock = 0;
5970 GDTH_UNLOCK_HA(ha, flags);
5971 for (j = 0; j < ha->tid_cnt; ++j) {
5972 gdth_start_timeout(lchn.ionode, i, j);
5973 gdth_next(lchn.ionode);
5980 case GDTIOCTL_RESCAN:
5981 return ioc_rescan(argp, cmnd);
5983 case GDTIOCTL_HDRLIST:
5984 return ioc_hdrlist(argp, cmnd);
5986 case GDTIOCTL_RESET_BUS:
5988 gdth_ioctl_reset res;
5991 if (copy_from_user(&res, argp, sizeof(gdth_ioctl_reset)) ||
5992 res.ionode >= gdth_ctr_count)
5995 ha = HADATA(gdth_ctr_tab[hanum]);
5997 /* Because we need a Scsi_Cmnd struct., we make a scsi_allocate device also for kernels >=2.6.x */
5998 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5999 scp = scsi_get_command(ha->sdev, GFP_KERNEL);
6004 scp->device->channel = virt_ctr ? 0 : res.number;
6005 rval = gdth_eh_bus_reset(scp);
6006 res.status = (rval == SUCCESS ? S_OK : S_GENERR);
6007 scsi_put_command(scp);
6008 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6009 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
6014 scp->channel = virt_ctr ? 0 : res.number;
6015 rval = gdth_eh_bus_reset(scp);
6016 res.status = (rval == SUCCESS ? S_OK : S_GENERR);
6017 scsi_release_command(scp);
6019 memset(&ha->sdev,0,sizeof(Scsi_Device));
6020 memset(&scp, 0,sizeof(Scsi_Cmnd));
6021 ha->sdev.host = scp.host = gdth_ctr_tab[hanum];
6022 ha->sdev.id = scp.target = ha->sdev.host->this_id;
6023 scp.device = &ha->sdev;
6024 scp.channel = virt_ctr ? 0 : res.number;
6025 rval = gdth_eh_bus_reset(&scp);
6026 res.status = (rval == SUCCESS ? S_OK : S_GENERR);
6028 if (copy_to_user(argp, &res, sizeof(gdth_ioctl_reset)))
6033 case GDTIOCTL_RESET_DRV:
6034 return ioc_resetdrv(argp, cmnd);
6044 static void gdth_flush(int hanum)
6048 gdth_cmd_str gdtcmd;
6049 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6052 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6059 char cmnd[MAX_COMMAND_SIZE];
6060 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
6062 TRACE2(("gdth_flush() hanum %d\n",hanum));
6063 ha = HADATA(gdth_ctr_tab[hanum]);
6065 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6066 sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
6067 srp = scsi_allocate_request(sdev, GFP_KERNEL);
6070 srp->sr_cmd_len = 12;
6072 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6073 sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
6074 scp = scsi_allocate_device(sdev, 1, FALSE);
6080 memset(&sdev,0,sizeof(Scsi_Device));
6081 memset(&scp, 0,sizeof(Scsi_Cmnd));
6082 sdev.host = scp.host = gdth_ctr_tab[hanum];
6083 sdev.id = scp.target = sdev.host->this_id;
6087 for (i = 0; i < MAX_HDRIVES; ++i) {
6088 if (ha->hdr[i].present) {
6089 gdtcmd.BoardNode = LOCALBOARD;
6090 gdtcmd.Service = CACHESERVICE;
6091 gdtcmd.OpCode = GDT_FLUSH;
6092 if (ha->cache_feat & GDT_64BIT) {
6093 gdtcmd.u.cache64.DeviceNo = i;
6094 gdtcmd.u.cache64.BlockNo = 1;
6095 gdtcmd.u.cache64.sg_canz = 0;
6097 gdtcmd.u.cache.DeviceNo = i;
6098 gdtcmd.u.cache.BlockNo = 1;
6099 gdtcmd.u.cache.sg_canz = 0;
6101 TRACE2(("gdth_flush(): flush ha %d drive %d\n", hanum, i));
6102 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6103 gdth_do_req(srp, &gdtcmd, cmnd, 30);
6104 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6105 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
6107 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
6111 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6112 scsi_release_request(srp);
6113 scsi_free_host_dev(sdev);
6114 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6115 scsi_release_command(scp);
6116 scsi_free_host_dev(sdev);
6120 /* shutdown routine */
6121 static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
6125 gdth_cmd_str gdtcmd;
6126 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6129 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6136 char cmnd[MAX_COMMAND_SIZE];
6139 TRACE2(("gdth_halt() event %d\n",(int)event));
6140 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
6143 printk("GDT-HA: Flushing all host drives .. ");
6144 for (hanum = 0; hanum < gdth_ctr_count; ++hanum) {
6148 /* controller reset */
6149 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
6150 gdtcmd.BoardNode = LOCALBOARD;
6151 gdtcmd.Service = CACHESERVICE;
6152 gdtcmd.OpCode = GDT_RESET;
6153 TRACE2(("gdth_halt(): reset controller %d\n", hanum));
6154 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6155 sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
6156 srp = scsi_allocate_request(sdev, GFP_KERNEL);
6158 unregister_reboot_notifier(&gdth_notifier);
6161 srp->sr_cmd_len = 12;
6163 gdth_do_req(srp, &gdtcmd, cmnd, 10);
6164 scsi_release_request(srp);
6165 scsi_free_host_dev(sdev);
6166 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6167 sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
6168 scp = scsi_allocate_device(sdev, 1, FALSE);
6170 unregister_reboot_notifier(&gdth_notifier);
6175 gdth_do_cmd(scp, &gdtcmd, cmnd, 10);
6176 scsi_release_command(scp);
6177 scsi_free_host_dev(sdev);
6179 memset(&sdev,0,sizeof(Scsi_Device));
6180 memset(&scp, 0,sizeof(Scsi_Cmnd));
6181 sdev.host = scp.host = gdth_ctr_tab[hanum];
6182 sdev.id = scp.target = sdev.host->this_id;
6184 gdth_do_cmd(&scp, &gdtcmd, cmnd, 10);
6190 #ifdef GDTH_STATISTICS
6191 del_timer(&gdth_timer);
6193 unregister_reboot_notifier(&gdth_notifier);
6198 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) && !defined(MODULE)
6200 GDTH_INITFUNC(void, gdth_setup(char *str,int *ints))
6202 TRACE2(("gdth_setup() str %s ints[0] %d\n",
6203 str ? str:"NULL", ints ? ints[0]:0));
6204 internal_setup(str, ints);
6209 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6210 static Scsi_Host_Template driver_template = {
6211 .proc_name = "gdth",
6212 .proc_info = gdth_proc_info,
6213 .name = "GDT SCSI Disk Array Controller",
6214 .detect = gdth_detect,
6215 .release = gdth_release,
6217 .queuecommand = gdth_queuecommand,
6218 .eh_abort_handler = gdth_eh_abort,
6219 .eh_device_reset_handler = gdth_eh_device_reset,
6220 .eh_bus_reset_handler = gdth_eh_bus_reset,
6221 .eh_host_reset_handler = gdth_eh_host_reset,
6222 .bios_param = gdth_bios_param,
6223 .can_queue = GDTH_MAXCMDS,
6225 .sg_tablesize = GDTH_MAXSG,
6226 .cmd_per_lun = GDTH_MAXC_P_L,
6227 .unchecked_isa_dma = 1,
6228 .use_clustering = ENABLE_CLUSTERING,
6229 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
6230 .use_new_eh_code = 1,
6231 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
6237 static Scsi_Host_Template driver_template = GDTH;
6240 #include "scsi_module.c"
6242 __setup("gdth=", option_setup);