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>
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((ulong)(addr))
575 #define gdth_readw(addr) readw((ulong)(addr))
576 #define gdth_readl(addr) (ulong32)readl((ulong)(addr))
577 #define gdth_writeb(b,addr) writeb((b),(ulong)(addr))
578 #define gdth_writew(b,addr) writew((b),(ulong)(addr))
579 #define gdth_writel(b,addr) writel((ulong32)(b),(ulong)(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,6,0)
622 #define __devinitdata
624 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
625 #define GDTH_INITFUNC(type, func) type __init func
626 #include <linux/init.h>
628 #define GDTH_INITFUNC(type, func) __initfunc(type func)
629 #include <linux/init.h>
632 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
633 #define GDTH_INIT_LOCK_HA(ha) spin_lock_init(&(ha)->smp_lock)
634 #define GDTH_LOCK_HA(ha,flags) spin_lock_irqsave(&(ha)->smp_lock,flags)
635 #define GDTH_UNLOCK_HA(ha,flags) spin_unlock_irqrestore(&(ha)->smp_lock,flags)
637 #define GDTH_LOCK_SCSI_DONE(dev, flags) spin_lock_irqsave(dev->host_lock,flags)
638 #define GDTH_UNLOCK_SCSI_DONE(dev, flags) spin_unlock_irqrestore(dev->host_lock,flags)
641 #define GDTH_INIT_LOCK_HA(ha) spin_lock_init(&(ha)->smp_lock)
642 #define GDTH_LOCK_HA(ha,flags) spin_lock_irqsave(&(ha)->smp_lock,flags)
643 #define GDTH_UNLOCK_HA(ha,flags) spin_unlock_irqrestore(&(ha)->smp_lock,flags)
645 #define GDTH_LOCK_SCSI_DONE(flags) spin_lock_irqsave(&io_request_lock,flags)
646 #define GDTH_UNLOCK_SCSI_DONE(flags) spin_unlock_irqrestore(&io_request_lock,flags)
649 /* LILO and modprobe/insmod parameters */
650 /* IRQ list for GDT3000/3020 EISA controllers */
651 static int irq[MAXHA] __initdata =
652 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
653 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
654 /* disable driver flag */
655 static int disable __initdata = 0;
657 static int reserve_mode = 1;
659 static int reserve_list[MAX_RES_ARGS] =
660 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
661 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
662 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
663 /* scan order for PCI controllers */
664 static int reverse_scan = 0;
665 /* virtual channel for the host drives */
666 static int hdr_channel = 0;
667 /* max. IDs per channel */
668 static int max_ids = MAXID;
670 static int rescan = 0;
671 /* map channels to virtual controllers */
672 static int virt_ctr = 0;
674 static int shared_access = 1;
675 /* enable support for EISA and ISA controllers */
676 static int probe_eisa_isa = 0;
677 /* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */
678 static int force_dma32 = 0;
681 /* parameters for modprobe/insmod */
682 MODULE_PARM(irq, "i");
683 MODULE_PARM(disable, "i");
684 MODULE_PARM(reserve_mode, "i");
685 MODULE_PARM(reserve_list, "4-" __MODULE_STRING(MAX_RES_ARGS) "i");
686 MODULE_PARM(reverse_scan, "i");
687 MODULE_PARM(hdr_channel, "i");
688 MODULE_PARM(max_ids, "i");
689 MODULE_PARM(rescan, "i");
690 MODULE_PARM(virt_ctr, "i");
691 MODULE_PARM(shared_access, "i");
692 MODULE_PARM(probe_eisa_isa, "i");
693 MODULE_PARM(force_dma32, "i");
694 MODULE_AUTHOR("Achim Leubner");
695 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,11)
696 MODULE_LICENSE("GPL");
700 /* ioctl interface */
701 static struct file_operations gdth_fops = {
702 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
705 .release = gdth_close,
714 #include <linux/stat.h>
715 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
716 struct proc_dir_entry proc_scsi_gdth = {
717 PROC_SCSI_GDTH, 4, "gdth",
718 S_IFDIR | S_IRUGO | S_IXUGO, 2
722 #include "gdth_proc.h"
723 #include "gdth_proc.c"
725 /* notifier block to get a notify on system shutdown/halt/reboot */
726 static struct notifier_block gdth_notifier = {
731 static void gdth_delay(int milliseconds)
733 if (milliseconds == 0) {
736 mdelay(milliseconds);
740 static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs)
742 *cyls = size /HEADS/SECS;
743 if (*cyls <= MAXCYLS) {
746 } else { /* too high for 64*32 */
747 *cyls = size /MEDHEADS/MEDSECS;
748 if (*cyls <= MAXCYLS) {
751 } else { /* too high for 127*63 */
752 *cyls = size /BIGHEADS/BIGSECS;
759 /* controller search and initialization functions */
761 GDTH_INITFUNC(static int, gdth_search_eisa(ushort eisa_adr))
765 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr));
766 id = inl(eisa_adr+ID0REG);
767 if (id == GDT3A_ID || id == GDT3B_ID) { /* GDT3000A or GDT3000B */
768 if ((inb(eisa_adr+EISAREG) & 8) == 0)
769 return 0; /* not EISA configured */
772 if (id == GDT3_ID) /* GDT3000 */
779 GDTH_INITFUNC(static int, gdth_search_isa(ulong32 bios_adr))
784 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
785 if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) {
786 id = gdth_readl(addr);
788 if (id == GDT2_ID) /* GDT2000 */
795 GDTH_INITFUNC(static int, gdth_search_pci(gdth_pci_str *pcistr))
799 TRACE(("gdth_search_pci()\n"));
802 for (device = 0; device <= PCI_DEVICE_ID_VORTEX_GDT6555; ++device)
803 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
804 for (device = PCI_DEVICE_ID_VORTEX_GDT6x17RP;
805 device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP; ++device)
806 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
807 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
808 PCI_DEVICE_ID_VORTEX_GDTNEWRX);
809 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
810 PCI_DEVICE_ID_VORTEX_GDTNEWRX2);
811 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
812 PCI_DEVICE_ID_INTEL_SRC);
813 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
814 PCI_DEVICE_ID_INTEL_SRC_XSCALE);
818 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
819 /* Vortex only makes RAID controllers.
820 * We do not really want to specify all 550 ids here, so wildcard match.
822 static struct pci_device_id gdthtable[] __devinitdata = {
823 {PCI_VENDOR_ID_VORTEX,PCI_ANY_ID,PCI_ANY_ID, PCI_ANY_ID},
824 {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC,PCI_ANY_ID,PCI_ANY_ID},
825 {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC_XSCALE,PCI_ANY_ID,PCI_ANY_ID},
828 MODULE_DEVICE_TABLE(pci,gdthtable);
831 GDTH_INITFUNC(static void, gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
832 ushort vendor, ushort device))
834 ulong base0, base1, base2;
835 struct pci_dev *pdev;
837 TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
838 *cnt, vendor, device));
840 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
842 while ((pdev = pci_find_device(vendor, device, pdev))
844 if (pci_enable_device(pdev))
848 /* GDT PCI controller found, resources are already in pdev */
849 pcistr[*cnt].pdev = pdev;
850 pcistr[*cnt].vendor_id = vendor;
851 pcistr[*cnt].device_id = device;
852 pcistr[*cnt].subdevice_id = pdev->subsystem_device;
853 pcistr[*cnt].bus = pdev->bus->number;
854 pcistr[*cnt].device_fn = pdev->devfn;
855 pcistr[*cnt].irq = pdev->irq;
856 base0 = pci_resource_flags(pdev, 0);
857 base1 = pci_resource_flags(pdev, 1);
858 base2 = pci_resource_flags(pdev, 2);
859 if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
860 device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
861 if (!(base0 & IORESOURCE_MEM))
863 pcistr[*cnt].dpmem = pci_resource_start(pdev, 0);
864 } else { /* GDT6110, GDT6120, .. */
865 if (!(base0 & IORESOURCE_MEM) ||
866 !(base2 & IORESOURCE_MEM) ||
867 !(base1 & IORESOURCE_IO))
869 pcistr[*cnt].dpmem = pci_resource_start(pdev, 2);
870 pcistr[*cnt].io_mm = pci_resource_start(pdev, 0);
871 pcistr[*cnt].io = pci_resource_start(pdev, 1);
873 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
874 pcistr[*cnt].bus, PCI_SLOT(pcistr[*cnt].device_fn),
875 pcistr[*cnt].irq, pcistr[*cnt].dpmem));
880 while ((pdev = pci_find_device(vendor, device, pdev))
884 /* GDT PCI controller found, resources are already in pdev */
885 pcistr[*cnt].pdev = pdev;
886 pcistr[*cnt].vendor_id = vendor;
887 pcistr[*cnt].device_id = device;
888 pcistr[*cnt].bus = pdev->bus->number;
889 pcistr[*cnt].device_fn = pdev->devfn;
890 pcibios_read_config_word(pcistr[*cnt].bus, pcistr[*cnt].device_fn,
891 PCI_SUBSYSTEM_ID, &pcistr[*cnt].subdevice_id);
892 pcistr[*cnt].irq = pdev->irq;
893 base0 = pdev->base_address[0];
894 base1 = pdev->base_address[1];
895 base2 = pdev->base_address[2];
896 if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
897 device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
898 if ((base0 & PCI_BASE_ADDRESS_SPACE) !=
899 PCI_BASE_ADDRESS_SPACE_MEMORY)
901 pcistr[*cnt].dpmem = base0 & PCI_BASE_ADDRESS_MEM_MASK;
902 } else { /* GDT6110, GDT6120, .. */
903 if ((base0 & PCI_BASE_ADDRESS_SPACE) !=
904 PCI_BASE_ADDRESS_SPACE_MEMORY ||
905 (base2 & PCI_BASE_ADDRESS_SPACE) !=
906 PCI_BASE_ADDRESS_SPACE_MEMORY ||
907 (base1 & PCI_BASE_ADDRESS_SPACE) !=
908 PCI_BASE_ADDRESS_SPACE_IO)
910 pcistr[*cnt].dpmem = base2 & PCI_BASE_ADDRESS_MEM_MASK;
911 pcistr[*cnt].io_mm = base0 & PCI_BASE_ADDRESS_MEM_MASK;
912 pcistr[*cnt].io = base1 & PCI_BASE_ADDRESS_IO_MASK;
914 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
915 pcistr[*cnt].bus, PCI_SLOT(pcistr[*cnt].device_fn),
916 pcistr[*cnt].irq, pcistr[*cnt].dpmem));
923 GDTH_INITFUNC(static void, gdth_sort_pci(gdth_pci_str *pcistr, int cnt))
928 TRACE(("gdth_sort_pci() cnt %d\n",cnt));
934 for (i = 0; i < cnt-1; ++i) {
936 if ((pcistr[i].bus > pcistr[i+1].bus) ||
937 (pcistr[i].bus == pcistr[i+1].bus &&
938 PCI_SLOT(pcistr[i].device_fn) >
939 PCI_SLOT(pcistr[i+1].device_fn))) {
941 pcistr[i] = pcistr[i+1];
946 if ((pcistr[i].bus < pcistr[i+1].bus) ||
947 (pcistr[i].bus == pcistr[i+1].bus &&
948 PCI_SLOT(pcistr[i].device_fn) <
949 PCI_SLOT(pcistr[i+1].device_fn))) {
951 pcistr[i] = pcistr[i+1];
961 GDTH_INITFUNC(static int, gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha))
964 unchar prot_ver,eisacf,i,irq_found;
966 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr));
968 /* disable board interrupts, deinitialize services */
969 outb(0xff,eisa_adr+EDOORREG);
970 outb(0x00,eisa_adr+EDENABREG);
971 outb(0x00,eisa_adr+EINTENABREG);
973 outb(0xff,eisa_adr+LDOORREG);
974 retries = INIT_RETRIES;
976 while (inb(eisa_adr+EDOORREG) != 0xff) {
977 if (--retries == 0) {
978 printk("GDT-EISA: Initialization error (DEINIT failed)\n");
982 TRACE2(("wait for DEINIT: retries=%d\n",retries));
984 prot_ver = inb(eisa_adr+MAILBOXREG);
985 outb(0xff,eisa_adr+EDOORREG);
986 if (prot_ver != PROTOCOL_VERSION) {
987 printk("GDT-EISA: Illegal protocol version\n");
991 ha->brd_phys = (ulong32)eisa_adr >> 12;
993 outl(0,eisa_adr+MAILBOXREG);
994 outl(0,eisa_adr+MAILBOXREG+4);
995 outl(0,eisa_adr+MAILBOXREG+8);
996 outl(0,eisa_adr+MAILBOXREG+12);
999 if ((id = inl(eisa_adr+ID0REG)) == GDT3_ID) {
1000 ha->oem_id = OEM_ID_ICP;
1001 ha->type = GDT_EISA;
1003 outl(1,eisa_adr+MAILBOXREG+8);
1004 outb(0xfe,eisa_adr+LDOORREG);
1005 retries = INIT_RETRIES;
1007 while (inb(eisa_adr+EDOORREG) != 0xfe) {
1008 if (--retries == 0) {
1009 printk("GDT-EISA: Initialization error (get IRQ failed)\n");
1014 ha->irq = inb(eisa_adr+MAILBOXREG);
1015 outb(0xff,eisa_adr+EDOORREG);
1016 TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq));
1017 /* check the result */
1019 TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
1020 for (i = 0, irq_found = FALSE;
1021 i < MAXHA && irq[i] != 0xff; ++i) {
1022 if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) {
1030 printk("GDT-EISA: Can not detect controller IRQ,\n");
1031 printk("Use IRQ setting from command line (IRQ = %d)\n",
1034 printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
1035 printk("the controller BIOS or use command line parameters\n");
1040 eisacf = inb(eisa_adr+EISAREG) & 7;
1041 if (eisacf > 4) /* level triggered */
1043 ha->irq = gdth_irq_tab[eisacf];
1044 ha->oem_id = OEM_ID_ICP;
1045 ha->type = GDT_EISA;
1049 ha->dma64_support = 0;
1054 GDTH_INITFUNC(static int, gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha))
1056 register gdt2_dpram_str *dp2_ptr;
1058 unchar irq_drq,prot_ver;
1061 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr));
1063 ha->brd = ioremap(bios_adr, sizeof(gdt2_dpram_str));
1064 if (ha->brd == NULL) {
1065 printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
1068 dp2_ptr = (gdt2_dpram_str *)ha->brd;
1069 gdth_writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
1070 /* reset interface area */
1071 memset_io((char *)&dp2_ptr->u,0,sizeof(dp2_ptr->u));
1072 if (gdth_readl(&dp2_ptr->u) != 0) {
1073 printk("GDT-ISA: Initialization error (DPMEM write error)\n");
1078 /* disable board interrupts, read DRQ and IRQ */
1079 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
1080 gdth_writeb(0x00, &dp2_ptr->io.irqen);
1081 gdth_writeb(0x00, &dp2_ptr->u.ic.S_Status);
1082 gdth_writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
1084 irq_drq = gdth_readb(&dp2_ptr->io.rq);
1085 for (i=0; i<3; ++i) {
1086 if ((irq_drq & 1)==0)
1090 ha->drq = gdth_drq_tab[i];
1092 irq_drq = gdth_readb(&dp2_ptr->io.rq) >> 3;
1093 for (i=1; i<5; ++i) {
1094 if ((irq_drq & 1)==0)
1098 ha->irq = gdth_irq_tab[i];
1100 /* deinitialize services */
1101 gdth_writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
1102 gdth_writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
1103 gdth_writeb(0, &dp2_ptr->io.event);
1104 retries = INIT_RETRIES;
1106 while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
1107 if (--retries == 0) {
1108 printk("GDT-ISA: Initialization error (DEINIT failed)\n");
1114 prot_ver = (unchar)gdth_readl(&dp2_ptr->u.ic.S_Info[0]);
1115 gdth_writeb(0, &dp2_ptr->u.ic.Status);
1116 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
1117 if (prot_ver != PROTOCOL_VERSION) {
1118 printk("GDT-ISA: Illegal protocol version\n");
1123 ha->oem_id = OEM_ID_ICP;
1125 ha->ic_all_size = sizeof(dp2_ptr->u);
1127 ha->brd_phys = bios_adr >> 4;
1129 /* special request to controller BIOS */
1130 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
1131 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
1132 gdth_writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
1133 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
1134 gdth_writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
1135 gdth_writeb(0, &dp2_ptr->io.event);
1136 retries = INIT_RETRIES;
1138 while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
1139 if (--retries == 0) {
1140 printk("GDT-ISA: Initialization error\n");
1146 gdth_writeb(0, &dp2_ptr->u.ic.Status);
1147 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
1149 ha->dma64_support = 0;
1154 GDTH_INITFUNC(static int, gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha))
1156 register gdt6_dpram_str *dp6_ptr;
1157 register gdt6c_dpram_str *dp6c_ptr;
1158 register gdt6m_dpram_str *dp6m_ptr;
1162 int i, found = FALSE;
1164 TRACE(("gdth_init_pci()\n"));
1166 if (pcistr->vendor_id == PCI_VENDOR_ID_INTEL)
1167 ha->oem_id = OEM_ID_INTEL;
1169 ha->oem_id = OEM_ID_ICP;
1170 ha->brd_phys = (pcistr->bus << 8) | (pcistr->device_fn & 0xf8);
1171 ha->stype = (ulong32)pcistr->device_id;
1172 ha->subdevice_id = pcistr->subdevice_id;
1173 ha->irq = pcistr->irq;
1174 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1175 ha->pdev = pcistr->pdev;
1178 if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */
1179 TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
1180 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6_dpram_str));
1181 if (ha->brd == NULL) {
1182 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1185 /* check and reset interface area */
1186 dp6_ptr = (gdt6_dpram_str *)ha->brd;
1187 gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
1188 if (gdth_readl(&dp6_ptr->u) != DPMEM_MAGIC) {
1189 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1192 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1194 ha->brd = ioremap(i, sizeof(ushort));
1195 if (ha->brd == NULL) {
1196 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1199 if (gdth_readw(ha->brd) != 0xffff) {
1200 TRACE2(("init_pci_old() address 0x%x busy\n", i));
1204 pci_write_config_dword(pcistr->pdev,
1205 PCI_BASE_ADDRESS_0, i);
1206 ha->brd = ioremap(i, sizeof(gdt6_dpram_str));
1207 if (ha->brd == NULL) {
1208 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1211 dp6_ptr = (gdt6_dpram_str *)ha->brd;
1212 gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
1213 if (gdth_readl(&dp6_ptr->u) == DPMEM_MAGIC) {
1214 printk("GDT-PCI: Use free address at 0x%x\n", i);
1220 printk("GDT-PCI: No free address found!\n");
1225 memset_io((char *)&dp6_ptr->u,0,sizeof(dp6_ptr->u));
1226 if (gdth_readl(&dp6_ptr->u) != 0) {
1227 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1232 /* disable board interrupts, deinit services */
1233 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
1234 gdth_writeb(0x00, &dp6_ptr->io.irqen);
1235 gdth_writeb(0x00, &dp6_ptr->u.ic.S_Status);
1236 gdth_writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
1238 gdth_writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
1239 gdth_writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
1240 gdth_writeb(0, &dp6_ptr->io.event);
1241 retries = INIT_RETRIES;
1243 while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
1244 if (--retries == 0) {
1245 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1251 prot_ver = (unchar)gdth_readl(&dp6_ptr->u.ic.S_Info[0]);
1252 gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
1253 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
1254 if (prot_ver != PROTOCOL_VERSION) {
1255 printk("GDT-PCI: Illegal protocol version\n");
1261 ha->ic_all_size = sizeof(dp6_ptr->u);
1263 /* special command to controller BIOS */
1264 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
1265 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
1266 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[2]);
1267 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
1268 gdth_writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
1269 gdth_writeb(0, &dp6_ptr->io.event);
1270 retries = INIT_RETRIES;
1272 while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
1273 if (--retries == 0) {
1274 printk("GDT-PCI: Initialization error\n");
1280 gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
1281 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
1283 ha->dma64_support = 0;
1285 } else if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */
1286 ha->plx = (gdt6c_plx_regs *)pcistr->io;
1287 TRACE2(("init_pci_new() dpmem %lx irq %d\n",
1288 pcistr->dpmem,ha->irq));
1289 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6c_dpram_str));
1290 if (ha->brd == NULL) {
1291 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1295 /* check and reset interface area */
1296 dp6c_ptr = (gdt6c_dpram_str *)ha->brd;
1297 gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
1298 if (gdth_readl(&dp6c_ptr->u) != DPMEM_MAGIC) {
1299 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1302 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1304 ha->brd = ioremap(i, sizeof(ushort));
1305 if (ha->brd == NULL) {
1306 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1309 if (gdth_readw(ha->brd) != 0xffff) {
1310 TRACE2(("init_pci_plx() address 0x%x busy\n", i));
1314 pci_write_config_dword(pcistr->pdev,
1315 PCI_BASE_ADDRESS_2, i);
1316 ha->brd = ioremap(i, sizeof(gdt6c_dpram_str));
1317 if (ha->brd == NULL) {
1318 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1321 dp6c_ptr = (gdt6c_dpram_str *)ha->brd;
1322 gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
1323 if (gdth_readl(&dp6c_ptr->u) == DPMEM_MAGIC) {
1324 printk("GDT-PCI: Use free address at 0x%x\n", i);
1330 printk("GDT-PCI: No free address found!\n");
1335 memset_io((char *)&dp6c_ptr->u,0,sizeof(dp6c_ptr->u));
1336 if (gdth_readl(&dp6c_ptr->u) != 0) {
1337 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1342 /* disable board interrupts, deinit services */
1343 outb(0x00,PTR2USHORT(&ha->plx->control1));
1344 outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
1346 gdth_writeb(0x00, &dp6c_ptr->u.ic.S_Status);
1347 gdth_writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
1349 gdth_writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
1350 gdth_writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
1352 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1354 retries = INIT_RETRIES;
1356 while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
1357 if (--retries == 0) {
1358 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1364 prot_ver = (unchar)gdth_readl(&dp6c_ptr->u.ic.S_Info[0]);
1365 gdth_writeb(0, &dp6c_ptr->u.ic.Status);
1366 if (prot_ver != PROTOCOL_VERSION) {
1367 printk("GDT-PCI: Illegal protocol version\n");
1372 ha->type = GDT_PCINEW;
1373 ha->ic_all_size = sizeof(dp6c_ptr->u);
1375 /* special command to controller BIOS */
1376 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
1377 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
1378 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[2]);
1379 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
1380 gdth_writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
1382 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1384 retries = INIT_RETRIES;
1386 while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
1387 if (--retries == 0) {
1388 printk("GDT-PCI: Initialization error\n");
1394 gdth_writeb(0, &dp6c_ptr->u.ic.S_Status);
1396 ha->dma64_support = 0;
1399 TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
1400 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6m_dpram_str));
1401 if (ha->brd == NULL) {
1402 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1406 /* manipulate config. space to enable DPMEM, start RP controller */
1407 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1408 pci_read_config_word(pcistr->pdev, PCI_COMMAND, &command);
1410 pci_write_config_word(pcistr->pdev, PCI_COMMAND, command);
1411 if (pci_resource_start(pcistr->pdev, 8) == 1UL)
1412 pci_resource_start(pcistr->pdev, 8) = 0UL;
1414 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS, i);
1416 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS,
1417 pci_resource_start(pcistr->pdev, 8));
1419 pci_read_config_word(pcistr->pdev, PCI_COMMAND, &command);
1421 pci_write_config_word(pcistr->pdev, PCI_COMMAND, command);
1422 if (pcistr->pdev->rom_address == 1UL)
1423 pcistr->pdev->rom_address = 0UL;
1425 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS, i);
1427 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS,
1428 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(&((gdt6m_dpram_str *)ha->brd)->i960r.sema0_reg) ) & 3 )
1436 /* check and reset interface area */
1437 dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
1438 gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
1439 if (gdth_readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
1440 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1443 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1445 ha->brd = ioremap(i, sizeof(ushort));
1446 if (ha->brd == NULL) {
1447 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1450 if (gdth_readw(ha->brd) != 0xffff) {
1451 TRACE2(("init_pci_mpr() address 0x%x busy\n", i));
1455 pci_write_config_dword(pcistr->pdev,
1456 PCI_BASE_ADDRESS_0, i);
1457 ha->brd = ioremap(i, sizeof(gdt6m_dpram_str));
1458 if (ha->brd == NULL) {
1459 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1462 dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
1463 gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
1464 if (gdth_readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
1465 printk("GDT-PCI: Use free address at 0x%x\n", i);
1471 printk("GDT-PCI: No free address found!\n");
1476 memset_io((char *)&dp6m_ptr->u,0,sizeof(dp6m_ptr->u));
1478 /* disable board interrupts, deinit services */
1479 gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
1480 &dp6m_ptr->i960r.edoor_en_reg);
1481 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1482 gdth_writeb(0x00, &dp6m_ptr->u.ic.S_Status);
1483 gdth_writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
1485 gdth_writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
1486 gdth_writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
1487 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1488 retries = INIT_RETRIES;
1490 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
1491 if (--retries == 0) {
1492 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1498 prot_ver = (unchar)gdth_readl(&dp6m_ptr->u.ic.S_Info[0]);
1499 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1500 if (prot_ver != PROTOCOL_VERSION) {
1501 printk("GDT-PCI: Illegal protocol version\n");
1506 ha->type = GDT_PCIMPR;
1507 ha->ic_all_size = sizeof(dp6m_ptr->u);
1509 /* special command to controller BIOS */
1510 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
1511 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
1512 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[2]);
1513 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
1514 gdth_writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
1515 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1516 retries = INIT_RETRIES;
1518 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
1519 if (--retries == 0) {
1520 printk("GDT-PCI: Initialization error\n");
1526 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1528 /* read FW version to detect 64-bit DMA support */
1529 gdth_writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx);
1530 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1531 retries = INIT_RETRIES;
1533 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) {
1534 if (--retries == 0) {
1535 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1541 prot_ver = (unchar)(gdth_readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
1542 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1543 if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */
1544 ha->dma64_support = 0;
1546 ha->dma64_support = 1;
1553 /* controller protocol functions */
1555 GDTH_INITFUNC(static void, gdth_enable_int(int hanum))
1559 gdt2_dpram_str *dp2_ptr;
1560 gdt6_dpram_str *dp6_ptr;
1561 gdt6m_dpram_str *dp6m_ptr;
1563 TRACE(("gdth_enable_int() hanum %d\n",hanum));
1564 ha = HADATA(gdth_ctr_tab[hanum]);
1565 GDTH_LOCK_HA(ha, flags);
1567 if (ha->type == GDT_EISA) {
1568 outb(0xff, ha->bmic + EDOORREG);
1569 outb(0xff, ha->bmic + EDENABREG);
1570 outb(0x01, ha->bmic + EINTENABREG);
1571 } else if (ha->type == GDT_ISA) {
1572 dp2_ptr = (gdt2_dpram_str *)ha->brd;
1573 gdth_writeb(1, &dp2_ptr->io.irqdel);
1574 gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);
1575 gdth_writeb(1, &dp2_ptr->io.irqen);
1576 } else if (ha->type == GDT_PCI) {
1577 dp6_ptr = (gdt6_dpram_str *)ha->brd;
1578 gdth_writeb(1, &dp6_ptr->io.irqdel);
1579 gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);
1580 gdth_writeb(1, &dp6_ptr->io.irqen);
1581 } else if (ha->type == GDT_PCINEW) {
1582 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
1583 outb(0x03, PTR2USHORT(&ha->plx->control1));
1584 } else if (ha->type == GDT_PCIMPR) {
1585 dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
1586 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1587 gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
1588 &dp6m_ptr->i960r.edoor_en_reg);
1590 GDTH_UNLOCK_HA(ha, flags);
1594 static int gdth_get_status(unchar *pIStatus,int irq)
1596 register gdth_ha_str *ha;
1599 TRACE(("gdth_get_status() irq %d ctr_count %d\n",
1600 irq,gdth_ctr_count));
1603 for (i=0; i<gdth_ctr_count; ++i) {
1604 ha = HADATA(gdth_ctr_tab[i]);
1605 if (ha->irq != (unchar)irq) /* check IRQ */
1607 if (ha->type == GDT_EISA)
1608 *pIStatus = inb((ushort)ha->bmic + EDOORREG);
1609 else if (ha->type == GDT_ISA)
1611 gdth_readb(&((gdt2_dpram_str *)ha->brd)->u.ic.Cmd_Index);
1612 else if (ha->type == GDT_PCI)
1614 gdth_readb(&((gdt6_dpram_str *)ha->brd)->u.ic.Cmd_Index);
1615 else if (ha->type == GDT_PCINEW)
1616 *pIStatus = inb(PTR2USHORT(&ha->plx->edoor_reg));
1617 else if (ha->type == GDT_PCIMPR)
1619 gdth_readb(&((gdt6m_dpram_str *)ha->brd)->i960r.edoor_reg);
1622 return i; /* board found */
1628 static int gdth_test_busy(int hanum)
1630 register gdth_ha_str *ha;
1631 register int gdtsema0 = 0;
1633 TRACE(("gdth_test_busy() hanum %d\n",hanum));
1635 ha = HADATA(gdth_ctr_tab[hanum]);
1636 if (ha->type == GDT_EISA)
1637 gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
1638 else if (ha->type == GDT_ISA)
1639 gdtsema0 = (int)gdth_readb(&((gdt2_dpram_str *)ha->brd)->u.ic.Sema0);
1640 else if (ha->type == GDT_PCI)
1641 gdtsema0 = (int)gdth_readb(&((gdt6_dpram_str *)ha->brd)->u.ic.Sema0);
1642 else if (ha->type == GDT_PCINEW)
1643 gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg));
1644 else if (ha->type == GDT_PCIMPR)
1646 (int)gdth_readb(&((gdt6m_dpram_str *)ha->brd)->i960r.sema0_reg);
1648 return (gdtsema0 & 1);
1652 static int gdth_get_cmd_index(int hanum)
1654 register gdth_ha_str *ha;
1657 TRACE(("gdth_get_cmd_index() hanum %d\n",hanum));
1659 ha = HADATA(gdth_ctr_tab[hanum]);
1660 for (i=0; i<GDTH_MAXCMDS; ++i) {
1661 if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
1662 ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
1663 ha->cmd_tab[i].service = ha->pccb->Service;
1664 ha->pccb->CommandIndex = (ulong32)i+2;
1672 static void gdth_set_sema0(int hanum)
1674 register gdth_ha_str *ha;
1676 TRACE(("gdth_set_sema0() hanum %d\n",hanum));
1678 ha = HADATA(gdth_ctr_tab[hanum]);
1679 if (ha->type == GDT_EISA) {
1680 outb(1, ha->bmic + SEMA0REG);
1681 } else if (ha->type == GDT_ISA) {
1682 gdth_writeb(1, &((gdt2_dpram_str *)ha->brd)->u.ic.Sema0);
1683 } else if (ha->type == GDT_PCI) {
1684 gdth_writeb(1, &((gdt6_dpram_str *)ha->brd)->u.ic.Sema0);
1685 } else if (ha->type == GDT_PCINEW) {
1686 outb(1, PTR2USHORT(&ha->plx->sema0_reg));
1687 } else if (ha->type == GDT_PCIMPR) {
1688 gdth_writeb(1, &((gdt6m_dpram_str *)ha->brd)->i960r.sema0_reg);
1693 static void gdth_copy_command(int hanum)
1695 register gdth_ha_str *ha;
1696 register gdth_cmd_str *cmd_ptr;
1697 register gdt6m_dpram_str *dp6m_ptr;
1698 register gdt6c_dpram_str *dp6c_ptr;
1699 gdt6_dpram_str *dp6_ptr;
1700 gdt2_dpram_str *dp2_ptr;
1701 ushort cp_count,dp_offset,cmd_no;
1703 TRACE(("gdth_copy_command() hanum %d\n",hanum));
1705 ha = HADATA(gdth_ctr_tab[hanum]);
1706 cp_count = ha->cmd_len;
1707 dp_offset= ha->cmd_offs_dpmem;
1708 cmd_no = ha->cmd_cnt;
1712 if (ha->type == GDT_EISA)
1713 return; /* no DPMEM, no copy */
1715 /* set cpcount dword aligned */
1717 cp_count += (4 - (cp_count & 3));
1719 ha->cmd_offs_dpmem += cp_count;
1721 /* set offset and service, copy command to DPMEM */
1722 if (ha->type == GDT_ISA) {
1723 dp2_ptr = (gdt2_dpram_str *)ha->brd;
1724 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1725 &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
1726 gdth_writew((ushort)cmd_ptr->Service,
1727 &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
1728 memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1729 } else if (ha->type == GDT_PCI) {
1730 dp6_ptr = (gdt6_dpram_str *)ha->brd;
1731 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1732 &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
1733 gdth_writew((ushort)cmd_ptr->Service,
1734 &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
1735 memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1736 } else if (ha->type == GDT_PCINEW) {
1737 dp6c_ptr = (gdt6c_dpram_str *)ha->brd;
1738 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1739 &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
1740 gdth_writew((ushort)cmd_ptr->Service,
1741 &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
1742 memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1743 } else if (ha->type == GDT_PCIMPR) {
1744 dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
1745 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1746 &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
1747 gdth_writew((ushort)cmd_ptr->Service,
1748 &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
1749 memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1754 static void gdth_release_event(int hanum)
1756 register gdth_ha_str *ha;
1758 TRACE(("gdth_release_event() hanum %d\n",hanum));
1759 ha = HADATA(gdth_ctr_tab[hanum]);
1761 #ifdef GDTH_STATISTICS
1764 for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
1765 if (ha->cmd_tab[j].cmnd != UNUSED_CMND)
1768 if (max_index < i) {
1770 TRACE3(("GDT: max_index = %d\n",(ushort)i));
1775 if (ha->pccb->OpCode == GDT_INIT)
1776 ha->pccb->Service |= 0x80;
1778 if (ha->type == GDT_EISA) {
1779 if (ha->pccb->OpCode == GDT_INIT) /* store DMA buffer */
1780 outl(ha->ccb_phys, ha->bmic + MAILBOXREG);
1781 outb(ha->pccb->Service, ha->bmic + LDOORREG);
1782 } else if (ha->type == GDT_ISA) {
1783 gdth_writeb(0, &((gdt2_dpram_str *)ha->brd)->io.event);
1784 } else if (ha->type == GDT_PCI) {
1785 gdth_writeb(0, &((gdt6_dpram_str *)ha->brd)->io.event);
1786 } else if (ha->type == GDT_PCINEW) {
1787 outb(1, PTR2USHORT(&ha->plx->ldoor_reg));
1788 } else if (ha->type == GDT_PCIMPR) {
1789 gdth_writeb(1, &((gdt6m_dpram_str *)ha->brd)->i960r.ldoor_reg);
1794 static int gdth_wait(int hanum,int index,ulong32 time)
1797 int answer_found = FALSE;
1799 TRACE(("gdth_wait() hanum %d index %d time %d\n",hanum,index,time));
1801 ha = HADATA(gdth_ctr_tab[hanum]);
1803 return 1; /* no wait required */
1805 gdth_from_wait = TRUE;
1807 gdth_interrupt((int)ha->irq,ha,NULL);
1808 if (wait_hanum==hanum && wait_index==index) {
1809 answer_found = TRUE;
1814 gdth_from_wait = FALSE;
1816 while (gdth_test_busy(hanum))
1819 return (answer_found);
1823 static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
1824 ulong64 p2,ulong64 p3)
1826 register gdth_ha_str *ha;
1827 register gdth_cmd_str *cmd_ptr;
1830 TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode));
1832 ha = HADATA(gdth_ctr_tab[hanum]);
1834 memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str));
1837 for (retries = INIT_RETRIES;;) {
1838 cmd_ptr->Service = service;
1839 cmd_ptr->RequestBuffer = INTERNAL_CMND;
1840 if (!(index=gdth_get_cmd_index(hanum))) {
1841 TRACE(("GDT: No free command index found\n"));
1844 gdth_set_sema0(hanum);
1845 cmd_ptr->OpCode = opcode;
1846 cmd_ptr->BoardNode = LOCALBOARD;
1847 if (service == CACHESERVICE) {
1848 if (opcode == GDT_IOCTL) {
1849 cmd_ptr->u.ioctl.subfunc = p1;
1850 cmd_ptr->u.ioctl.channel = (ulong32)p2;
1851 cmd_ptr->u.ioctl.param_size = (ushort)p3;
1852 cmd_ptr->u.ioctl.p_param = ha->scratch_phys;
1854 if (ha->cache_feat & GDT_64BIT) {
1855 cmd_ptr->u.cache64.DeviceNo = (ushort)p1;
1856 cmd_ptr->u.cache64.BlockNo = p2;
1858 cmd_ptr->u.cache.DeviceNo = (ushort)p1;
1859 cmd_ptr->u.cache.BlockNo = (ulong32)p2;
1862 } else if (service == SCSIRAWSERVICE) {
1863 if (ha->raw_feat & GDT_64BIT) {
1864 cmd_ptr->u.raw64.direction = p1;
1865 cmd_ptr->u.raw64.bus = (unchar)p2;
1866 cmd_ptr->u.raw64.target = (unchar)p3;
1867 cmd_ptr->u.raw64.lun = (unchar)(p3 >> 8);
1869 cmd_ptr->u.raw.direction = p1;
1870 cmd_ptr->u.raw.bus = (unchar)p2;
1871 cmd_ptr->u.raw.target = (unchar)p3;
1872 cmd_ptr->u.raw.lun = (unchar)(p3 >> 8);
1874 } else if (service == SCREENSERVICE) {
1875 if (opcode == GDT_REALTIME) {
1876 *(ulong32 *)&cmd_ptr->u.screen.su.data[0] = p1;
1877 *(ulong32 *)&cmd_ptr->u.screen.su.data[4] = (ulong32)p2;
1878 *(ulong32 *)&cmd_ptr->u.screen.su.data[8] = (ulong32)p3;
1881 ha->cmd_len = sizeof(gdth_cmd_str);
1882 ha->cmd_offs_dpmem = 0;
1884 gdth_copy_command(hanum);
1885 gdth_release_event(hanum);
1887 if (!gdth_wait(hanum,index,INIT_TIMEOUT)) {
1888 printk("GDT: Initialization error (timeout service %d)\n",service);
1891 if (ha->status != S_BSY || --retries == 0)
1896 return (ha->status != S_OK ? 0:1);
1900 /* search for devices */
1902 GDTH_INITFUNC(static int, gdth_search_drives(int hanum))
1904 register gdth_ha_str *ha;
1907 ulong32 bus_no, drv_cnt, drv_no, j;
1908 gdth_getch_str *chn;
1909 gdth_drlist_str *drl;
1910 gdth_iochan_str *ioc;
1911 gdth_raw_iochan_str *iocr;
1912 gdth_arcdl_str *alst;
1913 gdth_alist_str *alst2;
1914 gdth_oem_str_ioctl *oemstr;
1916 gdth_perf_modes *pmod;
1924 TRACE(("gdth_search_drives() hanum %d\n",hanum));
1925 ha = HADATA(gdth_ctr_tab[hanum]);
1928 /* initialize controller services, at first: screen service */
1929 ha->screen_feat = 0;
1931 ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_X_INIT_SCR,0,0,0);
1933 ha->screen_feat = GDT_64BIT;
1935 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1936 ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_INIT,0,0,0);
1938 printk("GDT-HA %d: Initialization error screen service (code %d)\n",
1942 TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n"));
1945 /* read realtime clock info, send to controller */
1946 /* 1. wait for the falling edge of update flag */
1947 spin_lock_irqsave(&rtc_lock, flags);
1948 for (j = 0; j < 1000000; ++j)
1949 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
1951 for (j = 0; j < 1000000; ++j)
1952 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
1956 for (j = 0; j < 12; ++j)
1957 rtc[j] = CMOS_READ(j);
1958 } while (rtc[0] != CMOS_READ(0));
1959 spin_lock_irqrestore(&rtc_lock, flags);
1960 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32 *)&rtc[0],
1961 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]));
1962 /* 3. send to controller firmware */
1963 gdth_internal_cmd(hanum,SCREENSERVICE,GDT_REALTIME, *(ulong32 *)&rtc[0],
1964 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]);
1967 /* unfreeze all IOs */
1968 gdth_internal_cmd(hanum,CACHESERVICE,GDT_UNFREEZE_IO,0,0,0);
1970 /* initialize cache service */
1973 ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INIT_HOST,LINUX_OS,0,0);
1975 ha->cache_feat = GDT_64BIT;
1977 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1978 ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_INIT,LINUX_OS,0,0);
1980 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1984 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
1985 cdev_cnt = (ushort)ha->info;
1986 ha->fw_vers = ha->service;
1989 if (ha->type == GDT_PCIMPR) {
1990 /* set perf. modes */
1991 pmod = (gdth_perf_modes *)ha->pscratch;
1993 pmod->st_mode = 1; /* enable one status buffer */
1994 *((ulong64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys;
1995 pmod->st_buff_indx1 = COALINDEX;
1996 pmod->st_buff_addr2 = 0;
1997 pmod->st_buff_u_addr2 = 0;
1998 pmod->st_buff_indx2 = 0;
1999 pmod->st_buff_size = sizeof(gdth_coal_status) * MAXOFFSETS;
2000 pmod->cmd_mode = 0; // disable all cmd buffers
2001 pmod->cmd_buff_addr1 = 0;
2002 pmod->cmd_buff_u_addr1 = 0;
2003 pmod->cmd_buff_indx1 = 0;
2004 pmod->cmd_buff_addr2 = 0;
2005 pmod->cmd_buff_u_addr2 = 0;
2006 pmod->cmd_buff_indx2 = 0;
2007 pmod->cmd_buff_size = 0;
2008 pmod->reserved1 = 0;
2009 pmod->reserved2 = 0;
2010 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,SET_PERF_MODES,
2011 INVALID_CHANNEL,sizeof(gdth_perf_modes))) {
2012 printk("GDT-HA %d: Interrupt coalescing activated\n", hanum);
2017 /* detect number of buses - try new IOCTL */
2018 iocr = (gdth_raw_iochan_str *)ha->pscratch;
2019 iocr->hdr.version = 0xffffffff;
2020 iocr->hdr.list_entries = MAXBUS;
2021 iocr->hdr.first_chan = 0;
2022 iocr->hdr.last_chan = MAXBUS-1;
2023 iocr->hdr.list_offset = GDTOFFSOF(gdth_raw_iochan_str, list[0]);
2024 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_RAW_DESC,
2025 INVALID_CHANNEL,sizeof(gdth_raw_iochan_str))) {
2026 TRACE2(("IOCHAN_RAW_DESC supported!\n"));
2027 ha->bus_cnt = iocr->hdr.chan_count;
2028 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
2029 if (iocr->list[bus_no].proc_id < MAXID)
2030 ha->bus_id[bus_no] = iocr->list[bus_no].proc_id;
2032 ha->bus_id[bus_no] = 0xff;
2036 chn = (gdth_getch_str *)ha->pscratch;
2037 for (bus_no = 0; bus_no < MAXBUS; ++bus_no) {
2038 chn->channel_no = bus_no;
2039 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2040 SCSI_CHAN_CNT | L_CTRL_PATTERN,
2041 IO_CHANNEL | INVALID_CHANNEL,
2042 sizeof(gdth_getch_str))) {
2044 printk("GDT-HA %d: Error detecting channel count (0x%x)\n",
2050 if (chn->siop_id < MAXID)
2051 ha->bus_id[bus_no] = chn->siop_id;
2053 ha->bus_id[bus_no] = 0xff;
2055 ha->bus_cnt = (unchar)bus_no;
2057 TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt));
2059 /* read cache configuration */
2060 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_INFO,
2061 INVALID_CHANNEL,sizeof(gdth_cinfo_str))) {
2062 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
2066 ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar;
2067 TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
2068 ha->cpar.version,ha->cpar.state,ha->cpar.strategy,
2069 ha->cpar.write_back,ha->cpar.block_size));
2071 /* read board info and features */
2072 ha->more_proc = FALSE;
2073 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_INFO,
2074 INVALID_CHANNEL,sizeof(gdth_binfo_str))) {
2075 memcpy(&ha->binfo, (gdth_binfo_str *)ha->pscratch,
2076 sizeof(gdth_binfo_str));
2077 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_FEATURES,
2078 INVALID_CHANNEL,sizeof(gdth_bfeat_str))) {
2079 TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n"));
2080 ha->bfeat = *(gdth_bfeat_str *)ha->pscratch;
2081 ha->more_proc = TRUE;
2084 TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n"));
2085 strcpy(ha->binfo.type_string, gdth_ctr_name(hanum));
2087 TRACE2(("Controller name: %s\n",ha->binfo.type_string));
2089 /* read more informations */
2090 if (ha->more_proc) {
2091 /* physical drives, channel addresses */
2092 ioc = (gdth_iochan_str *)ha->pscratch;
2093 ioc->hdr.version = 0xffffffff;
2094 ioc->hdr.list_entries = MAXBUS;
2095 ioc->hdr.first_chan = 0;
2096 ioc->hdr.last_chan = MAXBUS-1;
2097 ioc->hdr.list_offset = GDTOFFSOF(gdth_iochan_str, list[0]);
2098 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_DESC,
2099 INVALID_CHANNEL,sizeof(gdth_iochan_str))) {
2100 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
2101 ha->raw[bus_no].address = ioc->list[bus_no].address;
2102 ha->raw[bus_no].local_no = ioc->list[bus_no].local_no;
2105 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
2106 ha->raw[bus_no].address = IO_CHANNEL;
2107 ha->raw[bus_no].local_no = bus_no;
2110 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
2111 chn = (gdth_getch_str *)ha->pscratch;
2112 chn->channel_no = ha->raw[bus_no].local_no;
2113 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2114 SCSI_CHAN_CNT | L_CTRL_PATTERN,
2115 ha->raw[bus_no].address | INVALID_CHANNEL,
2116 sizeof(gdth_getch_str))) {
2117 ha->raw[bus_no].pdev_cnt = chn->drive_cnt;
2118 TRACE2(("Channel %d: %d phys. drives\n",
2119 bus_no,chn->drive_cnt));
2121 if (ha->raw[bus_no].pdev_cnt > 0) {
2122 drl = (gdth_drlist_str *)ha->pscratch;
2123 drl->sc_no = ha->raw[bus_no].local_no;
2124 drl->sc_cnt = ha->raw[bus_no].pdev_cnt;
2125 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2126 SCSI_DR_LIST | L_CTRL_PATTERN,
2127 ha->raw[bus_no].address | INVALID_CHANNEL,
2128 sizeof(gdth_drlist_str))) {
2129 for (j = 0; j < ha->raw[bus_no].pdev_cnt; ++j)
2130 ha->raw[bus_no].id_list[j] = drl->sc_list[j];
2132 ha->raw[bus_no].pdev_cnt = 0;
2137 /* logical drives */
2138 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_CNT,
2139 INVALID_CHANNEL,sizeof(ulong32))) {
2140 drv_cnt = *(ulong32 *)ha->pscratch;
2141 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_LIST,
2142 INVALID_CHANNEL,drv_cnt * sizeof(ulong32))) {
2143 for (j = 0; j < drv_cnt; ++j) {
2144 drv_no = ((ulong32 *)ha->pscratch)[j];
2145 if (drv_no < MAX_LDRIVES) {
2146 ha->hdr[drv_no].is_logdrv = TRUE;
2147 TRACE2(("Drive %d is log. drive\n",drv_no));
2151 alst = (gdth_arcdl_str *)ha->pscratch;
2152 alst->entries_avail = MAX_LDRIVES;
2153 alst->first_entry = 0;
2154 alst->list_offset = GDTOFFSOF(gdth_arcdl_str, list[0]);
2155 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2156 ARRAY_DRV_LIST2 | LA_CTRL_PATTERN,
2157 INVALID_CHANNEL, sizeof(gdth_arcdl_str) +
2158 (alst->entries_avail-1) * sizeof(gdth_alist_str))) {
2159 for (j = 0; j < alst->entries_init; ++j) {
2160 ha->hdr[j].is_arraydrv = alst->list[j].is_arrayd;
2161 ha->hdr[j].is_master = alst->list[j].is_master;
2162 ha->hdr[j].is_parity = alst->list[j].is_parity;
2163 ha->hdr[j].is_hotfix = alst->list[j].is_hotfix;
2164 ha->hdr[j].master_no = alst->list[j].cd_handle;
2166 } else if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2167 ARRAY_DRV_LIST | LA_CTRL_PATTERN,
2168 0, 35 * sizeof(gdth_alist_str))) {
2169 for (j = 0; j < 35; ++j) {
2170 alst2 = &((gdth_alist_str *)ha->pscratch)[j];
2171 ha->hdr[j].is_arraydrv = alst2->is_arrayd;
2172 ha->hdr[j].is_master = alst2->is_master;
2173 ha->hdr[j].is_parity = alst2->is_parity;
2174 ha->hdr[j].is_hotfix = alst2->is_hotfix;
2175 ha->hdr[j].master_no = alst2->cd_handle;
2181 /* initialize raw service */
2184 ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_X_INIT_RAW,0,0,0);
2186 ha->raw_feat = GDT_64BIT;
2188 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
2189 ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_INIT,0,0,0);
2191 printk("GDT-HA %d: Initialization error raw service (code %d)\n",
2195 TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n"));
2197 /* set/get features raw service (scatter/gather) */
2198 if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_SET_FEAT,SCATTER_GATHER,
2200 TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
2201 if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_GET_FEAT,0,0,0)) {
2202 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
2204 ha->raw_feat |= (ushort)ha->info;
2208 /* set/get features cache service (equal to raw service) */
2209 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_SET_FEAT,0,
2210 SCATTER_GATHER,0)) {
2211 TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
2212 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_GET_FEAT,0,0,0)) {
2213 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
2215 ha->cache_feat |= (ushort)ha->info;
2219 /* reserve drives for raw service */
2220 if (reserve_mode != 0) {
2221 gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE_ALL,
2222 reserve_mode == 1 ? 1 : 3, 0, 0);
2223 TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n",
2226 for (i = 0; i < MAX_RES_ARGS; i += 4) {
2227 if (reserve_list[i] == hanum && reserve_list[i+1] < ha->bus_cnt &&
2228 reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) {
2229 TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
2230 reserve_list[i], reserve_list[i+1],
2231 reserve_list[i+2], reserve_list[i+3]));
2232 if (!gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE,0,
2233 reserve_list[i+1], reserve_list[i+2] |
2234 (reserve_list[i+3] << 8))) {
2235 printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n",
2241 /* Determine OEM string using IOCTL */
2242 oemstr = (gdth_oem_str_ioctl *)ha->pscratch;
2243 oemstr->params.ctl_version = 0x01;
2244 oemstr->params.buffer_size = sizeof(oemstr->text);
2245 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2246 CACHE_READ_OEM_STRING_RECORD,INVALID_CHANNEL,
2247 sizeof(gdth_oem_str_ioctl))) {
2248 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n"));
2249 printk("GDT-HA %d: Vendor: %s Name: %s\n",
2250 hanum,oemstr->text.oem_company_name,ha->binfo.type_string);
2251 /* Save the Host Drive inquiry data */
2252 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2253 strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,
2254 sizeof(ha->oem_name));
2256 strncpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,7);
2257 ha->oem_name[7] = '\0';
2260 /* Old method, based on PCI ID */
2261 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
2262 printk("GDT-HA %d: Name: %s\n",
2263 hanum,ha->binfo.type_string);
2264 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2265 if (ha->oem_id == OEM_ID_INTEL)
2266 strlcpy(ha->oem_name,"Intel ", sizeof(ha->oem_name));
2268 strlcpy(ha->oem_name,"ICP ", sizeof(ha->oem_name));
2270 if (ha->oem_id == OEM_ID_INTEL)
2271 strcpy(ha->oem_name,"Intel ");
2273 strcpy(ha->oem_name,"ICP ");
2277 /* scanning for host drives */
2278 for (i = 0; i < cdev_cnt; ++i)
2279 gdth_analyse_hdrive(hanum,i);
2281 TRACE(("gdth_search_drives() OK\n"));
2285 static int gdth_analyse_hdrive(int hanum,ushort hdrive)
2287 register gdth_ha_str *ha;
2289 int drv_hds, drv_secs;
2291 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n",hanum,hdrive));
2292 if (hdrive >= MAX_HDRIVES)
2294 ha = HADATA(gdth_ctr_tab[hanum]);
2296 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_INFO,hdrive,0,0))
2298 ha->hdr[hdrive].present = TRUE;
2299 ha->hdr[hdrive].size = ha->info;
2301 /* evaluate mapping (sectors per head, heads per cylinder) */
2302 ha->hdr[hdrive].size &= ~SECS32;
2303 if (ha->info2 == 0) {
2304 gdth_eval_mapping(ha->hdr[hdrive].size,&drv_cyls,&drv_hds,&drv_secs);
2306 drv_hds = ha->info2 & 0xff;
2307 drv_secs = (ha->info2 >> 8) & 0xff;
2308 drv_cyls = (ulong32)ha->hdr[hdrive].size / drv_hds / drv_secs;
2310 ha->hdr[hdrive].heads = (unchar)drv_hds;
2311 ha->hdr[hdrive].secs = (unchar)drv_secs;
2313 ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs;
2315 if (ha->cache_feat & GDT_64BIT) {
2316 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INFO,hdrive,0,0)
2317 && ha->info2 != 0) {
2318 ha->hdr[hdrive].size = ((ulong64)ha->info2 << 32) | ha->info;
2321 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
2322 hdrive,ha->hdr[hdrive].size,drv_hds,drv_secs));
2324 /* get informations about device */
2325 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_DEVTYPE,hdrive,0,0)) {
2326 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
2328 ha->hdr[hdrive].devtype = (ushort)ha->info;
2332 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_CLUST_INFO,hdrive,0,0)) {
2333 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
2336 ha->hdr[hdrive].cluster_type = (unchar)ha->info;
2339 /* R/W attributes */
2340 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_RW_ATTRIBS,hdrive,0,0)) {
2341 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
2343 ha->hdr[hdrive].rw_attribs = (unchar)ha->info;
2350 /* command queueing/sending functions */
2352 static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority)
2354 register gdth_ha_str *ha;
2355 register Scsi_Cmnd *pscp;
2356 register Scsi_Cmnd *nscp;
2360 TRACE(("gdth_putq() priority %d\n",priority));
2361 ha = HADATA(gdth_ctr_tab[hanum]);
2362 GDTH_LOCK_HA(ha, flags);
2364 scp->SCp.this_residual = (int)priority;
2365 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2366 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
2367 t = scp->device->id;
2369 b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
2372 if (priority >= DEFAULT_PRI) {
2373 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2374 (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock)) {
2375 TRACE2(("gdth_putq(): locked IO -> update_timeout()\n"));
2376 scp->SCp.buffers_residual = gdth_update_timeout(hanum, scp, 0);
2380 if (ha->req_first==NULL) {
2381 ha->req_first = scp; /* queue was empty */
2382 scp->SCp.ptr = NULL;
2383 } else { /* queue not empty */
2384 pscp = ha->req_first;
2385 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2386 /* priority: 0-highest,..,0xff-lowest */
2387 while (nscp && (unchar)nscp->SCp.this_residual <= priority) {
2389 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2391 pscp->SCp.ptr = (char *)scp;
2392 scp->SCp.ptr = (char *)nscp;
2394 GDTH_UNLOCK_HA(ha, flags);
2396 #ifdef GDTH_STATISTICS
2398 for (nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
2400 if (max_rq < flags) {
2402 TRACE3(("GDT: max_rq = %d\n",(ushort)max_rq));
2407 static void gdth_next(int hanum)
2409 register gdth_ha_str *ha;
2410 register Scsi_Cmnd *pscp;
2411 register Scsi_Cmnd *nscp;
2412 unchar b, t, l, firsttime;
2413 unchar this_cmd, next_cmd;
2417 TRACE(("gdth_next() hanum %d\n",hanum));
2418 ha = HADATA(gdth_ctr_tab[hanum]);
2420 GDTH_LOCK_HA(ha, flags);
2422 ha->cmd_cnt = ha->cmd_offs_dpmem = 0;
2423 this_cmd = firsttime = TRUE;
2424 next_cmd = gdth_polling ? FALSE:TRUE;
2427 for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) {
2428 if (nscp != pscp && nscp != (Scsi_Cmnd *)pscp->SCp.ptr)
2429 pscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2430 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2431 b = virt_ctr ? NUMDATA(nscp->device->host)->busnum : nscp->device->channel;
2432 t = nscp->device->id;
2433 l = nscp->device->lun;
2435 b = virt_ctr ? NUMDATA(nscp->host)->busnum : nscp->channel;
2439 if (nscp->SCp.this_residual >= DEFAULT_PRI) {
2440 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2441 (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock))
2446 if (gdth_test_busy(hanum)) { /* controller busy ? */
2447 TRACE(("gdth_next() controller %d busy !\n",hanum));
2448 if (!gdth_polling) {
2449 GDTH_UNLOCK_HA(ha, flags);
2452 while (gdth_test_busy(hanum))
2458 if (nscp->done != gdth_scsi_done || nscp->cmnd[0] != 0xff) {
2459 if (nscp->SCp.phase == -1) {
2460 nscp->SCp.phase = CACHESERVICE; /* default: cache svc. */
2461 if (nscp->cmnd[0] == TEST_UNIT_READY) {
2462 TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
2464 /* TEST_UNIT_READY -> set scan mode */
2465 if ((ha->scan_mode & 0x0f) == 0) {
2466 if (b == 0 && t == 0 && l == 0) {
2468 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2470 } else if ((ha->scan_mode & 0x0f) == 1) {
2471 if (b == 0 && ((t == 0 && l == 1) ||
2472 (t == 1 && l == 0))) {
2473 nscp->SCp.sent_command = GDT_SCAN_START;
2474 nscp->SCp.phase = ((ha->scan_mode & 0x10 ? 1:0) << 8)
2476 ha->scan_mode = 0x12;
2477 TRACE2(("Scan mode: 0x%x (SCAN_START)\n",
2480 ha->scan_mode &= 0x10;
2481 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2483 } else if (ha->scan_mode == 0x12) {
2484 if (b == ha->bus_cnt && t == ha->tid_cnt-1) {
2485 nscp->SCp.phase = SCSIRAWSERVICE;
2486 nscp->SCp.sent_command = GDT_SCAN_END;
2487 ha->scan_mode &= 0x10;
2488 TRACE2(("Scan mode: 0x%x (SCAN_END)\n",
2493 if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY &&
2494 nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE &&
2495 (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) {
2496 /* always GDT_CLUST_INFO! */
2497 nscp->SCp.sent_command = GDT_CLUST_INFO;
2502 if (nscp->SCp.sent_command != -1) {
2503 if ((nscp->SCp.phase & 0xff) == CACHESERVICE) {
2504 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2507 } else if ((nscp->SCp.phase & 0xff) == SCSIRAWSERVICE) {
2508 if (!(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
2512 memset((char*)nscp->sense_buffer,0,16);
2513 nscp->sense_buffer[0] = 0x70;
2514 nscp->sense_buffer[2] = NOT_READY;
2515 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2516 if (!nscp->SCp.have_data_in)
2517 nscp->SCp.have_data_in++;
2520 GDTH_UNLOCK_HA(ha,flags);
2521 /* io_request_lock already active ! */
2522 nscp->scsi_done(nscp);
2524 GDTH_LOCK_HA(ha,flags);
2527 } else if (nscp->done == gdth_scsi_done && nscp->cmnd[0] == 0xff) {
2528 if (!(cmd_index=gdth_special_cmd(hanum,nscp)))
2531 } else if (b != ha->virt_bus) {
2532 if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW ||
2533 !(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
2536 ha->raw[BUS_L2P(ha,b)].io_cnt[t]++;
2537 } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || l != 0) {
2538 TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
2539 nscp->cmnd[0], b, t, l));
2540 nscp->result = DID_BAD_TARGET << 16;
2541 if (!nscp->SCp.have_data_in)
2542 nscp->SCp.have_data_in++;
2545 GDTH_UNLOCK_HA(ha,flags);
2546 /* io_request_lock already active ! */
2547 nscp->scsi_done(nscp);
2549 GDTH_LOCK_HA(ha,flags);
2552 switch (nscp->cmnd[0]) {
2553 case TEST_UNIT_READY:
2560 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2561 case SERVICE_ACTION_IN:
2563 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2564 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2565 nscp->cmnd[4],nscp->cmnd[5]));
2566 if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) {
2567 /* return UNIT_ATTENTION */
2568 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2570 ha->hdr[t].media_changed = FALSE;
2571 memset((char*)nscp->sense_buffer,0,16);
2572 nscp->sense_buffer[0] = 0x70;
2573 nscp->sense_buffer[2] = UNIT_ATTENTION;
2574 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2575 if (!nscp->SCp.have_data_in)
2576 nscp->SCp.have_data_in++;
2579 GDTH_UNLOCK_HA(ha,flags);
2580 /* io_request_lock already active ! */
2581 nscp->scsi_done(nscp);
2583 GDTH_LOCK_HA(ha,flags);
2585 } else if (gdth_internal_cache_cmd(hanum,nscp)) {
2587 GDTH_UNLOCK_HA(ha,flags);
2588 /* io_request_lock already active ! */
2589 nscp->scsi_done(nscp);
2591 GDTH_LOCK_HA(ha,flags);
2595 case ALLOW_MEDIUM_REMOVAL:
2596 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2597 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2598 nscp->cmnd[4],nscp->cmnd[5]));
2599 if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) {
2600 TRACE(("Prevent r. nonremov. drive->do nothing\n"));
2601 nscp->result = DID_OK << 16;
2602 nscp->sense_buffer[0] = 0;
2603 if (!nscp->SCp.have_data_in)
2604 nscp->SCp.have_data_in++;
2607 GDTH_UNLOCK_HA(ha,flags);
2608 /* io_request_lock already active ! */
2609 nscp->scsi_done(nscp);
2611 GDTH_LOCK_HA(ha,flags);
2614 nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0;
2615 TRACE(("Prevent/allow r. %d rem. drive %d\n",
2616 nscp->cmnd[4],nscp->cmnd[3]));
2617 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2624 TRACE2(("cache cmd %s\n",nscp->cmnd[0] == RESERVE ?
2625 "RESERVE" : "RELEASE"));
2626 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2634 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2638 if (ha->hdr[t].media_changed) {
2639 /* return UNIT_ATTENTION */
2640 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2642 ha->hdr[t].media_changed = FALSE;
2643 memset((char*)nscp->sense_buffer,0,16);
2644 nscp->sense_buffer[0] = 0x70;
2645 nscp->sense_buffer[2] = UNIT_ATTENTION;
2646 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2647 if (!nscp->SCp.have_data_in)
2648 nscp->SCp.have_data_in++;
2651 GDTH_UNLOCK_HA(ha,flags);
2652 /* io_request_lock already active ! */
2653 nscp->scsi_done(nscp);
2655 GDTH_LOCK_HA(ha,flags);
2657 } else if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2662 TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0],
2663 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2664 nscp->cmnd[4],nscp->cmnd[5]));
2665 printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n",
2666 hanum, nscp->cmnd[0]);
2667 nscp->result = DID_ABORT << 16;
2668 if (!nscp->SCp.have_data_in)
2669 nscp->SCp.have_data_in++;
2672 GDTH_UNLOCK_HA(ha,flags);
2673 /* io_request_lock already active ! */
2674 nscp->scsi_done(nscp);
2676 GDTH_LOCK_HA(ha,flags);
2684 if (nscp == ha->req_first)
2685 ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
2687 pscp->SCp.ptr = nscp->SCp.ptr;
2692 if (ha->cmd_cnt > 0) {
2693 gdth_release_event(hanum);
2697 GDTH_UNLOCK_HA(ha, flags);
2699 if (gdth_polling && ha->cmd_cnt > 0) {
2700 if (!gdth_wait(hanum,cmd_index,POLL_TIMEOUT))
2701 printk("GDT-HA %d: Command %d timed out !\n",
2706 static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
2707 char *buffer,ushort count)
2711 struct scatterlist *sl;
2716 cpcount = count<=(ushort)scp->bufflen ? count:(ushort)scp->bufflen;
2717 ha = HADATA(gdth_ctr_tab[hanum]);
2720 sl = (struct scatterlist *)scp->request_buffer;
2721 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
2722 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,PCI_DMA_FROMDEVICE);
2723 for (i=0,cpsum=0; i<sgcnt; ++i,++sl) {
2724 cpnow = (ushort)sg_dma_len(sl);
2725 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2726 cpnow,cpsum,cpcount,(ushort)scp->bufflen));
2727 if (cpsum+cpnow > cpcount)
2728 cpnow = cpcount - cpsum;
2731 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
2735 address = (char *)(page_address(sl->page) + sl->offset);
2736 memcpy(address,buffer,cpnow);
2737 if (cpsum == cpcount)
2741 pci_unmap_sg(ha->pdev,scp->request_buffer,
2742 scp->use_sg,PCI_DMA_FROMDEVICE);
2744 sgcnt = scp->use_sg;
2745 for (i=0,cpsum=0; i<sgcnt; ++i,++sl) {
2746 cpnow = (ushort)sl->length;
2747 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2748 cpnow,cpsum,cpcount,(ushort)scp->bufflen));
2749 if (cpsum+cpnow > cpcount)
2750 cpnow = cpcount - cpsum;
2752 address = (char *)sl->address;
2753 memcpy(address,buffer,cpnow);
2754 if (cpsum == cpcount)
2760 TRACE(("copy_internal() count %d\n",cpcount));
2761 memcpy((char*)scp->request_buffer,buffer,cpcount);
2765 static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp)
2767 register gdth_ha_str *ha;
2770 gdth_rdcap_data rdc;
2772 gdth_modep_data mpd;
2774 ha = HADATA(gdth_ctr_tab[hanum]);
2775 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2776 t = scp->device->id;
2780 TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
2783 scp->result = DID_OK << 16;
2784 scp->sense_buffer[0] = 0;
2786 switch (scp->cmnd[0]) {
2787 case TEST_UNIT_READY:
2790 TRACE2(("Test/Verify/Start hdrive %d\n",t));
2794 TRACE2(("Inquiry hdrive %d devtype %d\n",
2795 t,ha->hdr[t].devtype));
2796 inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK;
2797 /* you can here set all disks to removable, if you want to do
2798 a flush using the ALLOW_MEDIUM_REMOVAL command */
2799 inq.modif_rmb = 0x00;
2800 if ((ha->hdr[t].devtype & 1) ||
2801 (ha->hdr[t].cluster_type & CLUSTER_DRIVE))
2802 inq.modif_rmb = 0x80;
2806 strcpy(inq.vendor,ha->oem_name);
2807 sprintf(inq.product,"Host Drive #%02d",t);
2808 strcpy(inq.revision," ");
2809 gdth_copy_internal_data(hanum,scp,(char*)&inq,sizeof(gdth_inq_data));
2813 TRACE2(("Request sense hdrive %d\n",t));
2814 sd.errorcode = 0x70;
2819 gdth_copy_internal_data(hanum,scp,(char*)&sd,sizeof(gdth_sense_data));
2823 TRACE2(("Mode sense hdrive %d\n",t));
2824 memset((char*)&mpd,0,sizeof(gdth_modep_data));
2825 mpd.hd.data_length = sizeof(gdth_modep_data);
2826 mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0;
2827 mpd.hd.bd_length = sizeof(mpd.bd);
2828 mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
2829 mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
2830 mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
2831 gdth_copy_internal_data(hanum,scp,(char*)&mpd,sizeof(gdth_modep_data));
2835 TRACE2(("Read capacity hdrive %d\n",t));
2836 if (ha->hdr[t].size > (ulong64)0xffffffff)
2837 rdc.last_block_no = 0xffffffff;
2839 rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1);
2840 rdc.block_length = cpu_to_be32(SECTOR_SIZE);
2841 gdth_copy_internal_data(hanum,scp,(char*)&rdc,sizeof(gdth_rdcap_data));
2844 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2845 case SERVICE_ACTION_IN:
2846 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 &&
2847 (ha->cache_feat & GDT_64BIT)) {
2848 gdth_rdcap16_data rdc16;
2850 TRACE2(("Read capacity (16) hdrive %d\n",t));
2851 rdc16.last_block_no = cpu_to_be64(ha->hdr[t].size-1);
2852 rdc16.block_length = cpu_to_be32(SECTOR_SIZE);
2853 gdth_copy_internal_data(hanum,scp,(char*)&rdc16,sizeof(gdth_rdcap16_data));
2855 scp->result = DID_ABORT << 16;
2861 TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0]));
2865 if (!scp->SCp.have_data_in)
2866 scp->SCp.have_data_in++;
2873 static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive)
2875 register gdth_ha_str *ha;
2876 register gdth_cmd_str *cmdp;
2877 struct scatterlist *sl;
2878 ulong32 cnt, blockcnt;
2879 ulong64 no, blockno;
2880 dma_addr_t phys_addr;
2881 int i, cmd_index, read_write, sgcnt, mode64;
2882 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
2887 ha = HADATA(gdth_ctr_tab[hanum]);
2889 TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
2890 scp->cmnd[0],scp->cmd_len,hdrive));
2892 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2895 mode64 = (ha->cache_feat & GDT_64BIT) ? TRUE : FALSE;
2896 /* test for READ_16, WRITE_16 if !mode64 ? ---
2897 not required, should not occur due to error return on
2900 cmdp->Service = CACHESERVICE;
2901 cmdp->RequestBuffer = scp;
2902 /* search free command index */
2903 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
2904 TRACE(("GDT: No free command index found\n"));
2907 /* if it's the first command, set command semaphore */
2908 if (ha->cmd_cnt == 0)
2909 gdth_set_sema0(hanum);
2913 if (scp->SCp.sent_command != -1)
2914 cmdp->OpCode = scp->SCp.sent_command; /* special cache cmd. */
2915 else if (scp->cmnd[0] == RESERVE)
2916 cmdp->OpCode = GDT_RESERVE_DRV;
2917 else if (scp->cmnd[0] == RELEASE)
2918 cmdp->OpCode = GDT_RELEASE_DRV;
2919 else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
2920 if (scp->cmnd[4] & 1) /* prevent ? */
2921 cmdp->OpCode = GDT_MOUNT;
2922 else if (scp->cmnd[3] & 1) /* removable drive ? */
2923 cmdp->OpCode = GDT_UNMOUNT;
2925 cmdp->OpCode = GDT_FLUSH;
2926 } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10 ||
2927 scp->cmnd[0] == WRITE_12
2928 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2929 || scp->cmnd[0] == WRITE_16
2933 if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) &&
2934 (ha->cache_feat & GDT_WR_THROUGH)))
2935 cmdp->OpCode = GDT_WRITE_THR;
2937 cmdp->OpCode = GDT_WRITE;
2940 cmdp->OpCode = GDT_READ;
2943 cmdp->BoardNode = LOCALBOARD;
2945 cmdp->u.cache64.DeviceNo = hdrive;
2946 cmdp->u.cache64.BlockNo = 1;
2947 cmdp->u.cache64.sg_canz = 0;
2949 cmdp->u.cache.DeviceNo = hdrive;
2950 cmdp->u.cache.BlockNo = 1;
2951 cmdp->u.cache.sg_canz = 0;
2955 if (scp->cmd_len == 16) {
2956 memcpy(&no, &scp->cmnd[2], sizeof(ulong64));
2957 blockno = be64_to_cpu(no);
2958 memcpy(&cnt, &scp->cmnd[10], sizeof(ulong32));
2959 blockcnt = be32_to_cpu(cnt);
2960 } else if (scp->cmd_len == 10) {
2961 memcpy(&no, &scp->cmnd[2], sizeof(ulong32));
2962 blockno = be32_to_cpu(no);
2963 memcpy(&cnt, &scp->cmnd[7], sizeof(ushort));
2964 blockcnt = be16_to_cpu(cnt);
2966 memcpy(&no, &scp->cmnd[0], sizeof(ulong32));
2967 blockno = be32_to_cpu(no) & 0x001fffffUL;
2968 blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
2971 cmdp->u.cache64.BlockNo = blockno;
2972 cmdp->u.cache64.BlockCnt = blockcnt;
2974 cmdp->u.cache.BlockNo = (ulong32)blockno;
2975 cmdp->u.cache.BlockCnt = blockcnt;
2979 sl = (struct scatterlist *)scp->request_buffer;
2980 sgcnt = scp->use_sg;
2981 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
2982 scp->SCp.Status = GDTH_MAP_SG;
2983 scp->SCp.Message = (read_write == 1 ?
2984 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
2985 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
2987 cmdp->u.cache64.DestAddr= (ulong64)-1;
2988 cmdp->u.cache64.sg_canz = sgcnt;
2989 for (i=0; i<sgcnt; ++i,++sl) {
2990 cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2991 #ifdef GDTH_DMA_STATISTICS
2992 if (cmdp->u.cache64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2997 cmdp->u.cache64.sg_lst[i].sg_len = sg_dma_len(sl);
3000 cmdp->u.cache.DestAddr= 0xffffffff;
3001 cmdp->u.cache.sg_canz = sgcnt;
3002 for (i=0; i<sgcnt; ++i,++sl) {
3003 cmdp->u.cache.sg_lst[i].sg_ptr = sg_dma_address(sl);
3004 #ifdef GDTH_DMA_STATISTICS
3007 cmdp->u.cache.sg_lst[i].sg_len = sg_dma_len(sl);
3012 cmdp->u.cache64.DestAddr= (ulong64)-1;
3013 cmdp->u.cache64.sg_canz = sgcnt;
3014 for (i=0; i<sgcnt; ++i,++sl) {
3015 cmdp->u.cache64.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
3016 cmdp->u.cache64.sg_lst[i].sg_len = (ulong32)sl->length;
3019 cmdp->u.cache.DestAddr= 0xffffffff;
3020 cmdp->u.cache.sg_canz = sgcnt;
3021 for (i=0; i<sgcnt; ++i,++sl) {
3022 cmdp->u.cache.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
3023 cmdp->u.cache.sg_lst[i].sg_len = (ulong32)sl->length;
3028 #ifdef GDTH_STATISTICS
3029 if (max_sg < (ulong32)sgcnt) {
3030 max_sg = (ulong32)sgcnt;
3031 TRACE3(("GDT: max_sg = %d\n",max_sg));
3036 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3037 scp->SCp.Status = GDTH_MAP_SINGLE;
3038 scp->SCp.Message = (read_write == 1 ?
3039 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
3040 page = virt_to_page(scp->request_buffer);
3041 offset = (ulong)scp->request_buffer & ~PAGE_MASK;
3042 phys_addr = pci_map_page(ha->pdev,page,offset,
3043 scp->request_bufflen,scp->SCp.Message);
3044 scp->SCp.dma_handle = phys_addr;
3046 phys_addr = virt_to_bus(scp->request_buffer);
3049 if (ha->cache_feat & SCATTER_GATHER) {
3050 cmdp->u.cache64.DestAddr = (ulong64)-1;
3051 cmdp->u.cache64.sg_canz = 1;
3052 cmdp->u.cache64.sg_lst[0].sg_ptr = phys_addr;
3053 cmdp->u.cache64.sg_lst[0].sg_len = scp->request_bufflen;
3054 cmdp->u.cache64.sg_lst[1].sg_len = 0;
3056 cmdp->u.cache64.DestAddr = phys_addr;
3057 cmdp->u.cache64.sg_canz= 0;
3060 if (ha->cache_feat & SCATTER_GATHER) {
3061 cmdp->u.cache.DestAddr = 0xffffffff;
3062 cmdp->u.cache.sg_canz = 1;
3063 cmdp->u.cache.sg_lst[0].sg_ptr = phys_addr;
3064 cmdp->u.cache.sg_lst[0].sg_len = scp->request_bufflen;
3065 cmdp->u.cache.sg_lst[1].sg_len = 0;
3067 cmdp->u.cache.DestAddr = phys_addr;
3068 cmdp->u.cache.sg_canz= 0;
3073 /* evaluate command size, check space */
3075 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3076 cmdp->u.cache64.DestAddr,cmdp->u.cache64.sg_canz,
3077 cmdp->u.cache64.sg_lst[0].sg_ptr,
3078 cmdp->u.cache64.sg_lst[0].sg_len));
3079 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
3080 cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt));
3081 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) +
3082 (ushort)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str);
3084 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3085 cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
3086 cmdp->u.cache.sg_lst[0].sg_ptr,
3087 cmdp->u.cache.sg_lst[0].sg_len));
3088 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
3089 cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
3090 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
3091 (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str);
3093 if (ha->cmd_len & 3)
3094 ha->cmd_len += (4 - (ha->cmd_len & 3));
3096 if (ha->cmd_cnt > 0) {
3097 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
3099 TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
3100 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
3106 gdth_copy_command(hanum);
3110 static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b)
3112 register gdth_ha_str *ha;
3113 register gdth_cmd_str *cmdp;
3114 struct scatterlist *sl;
3116 dma_addr_t phys_addr, sense_paddr;
3117 int cmd_index, sgcnt, mode64;
3119 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3124 ha = HADATA(gdth_ctr_tab[hanum]);
3125 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3126 t = scp->device->id;
3127 l = scp->device->lun;
3133 TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
3134 scp->cmnd[0],b,t,l));
3136 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
3139 mode64 = (ha->raw_feat & GDT_64BIT) ? TRUE : FALSE;
3141 cmdp->Service = SCSIRAWSERVICE;
3142 cmdp->RequestBuffer = scp;
3143 /* search free command index */
3144 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
3145 TRACE(("GDT: No free command index found\n"));
3148 /* if it's the first command, set command semaphore */
3149 if (ha->cmd_cnt == 0)
3150 gdth_set_sema0(hanum);
3153 if (scp->SCp.sent_command != -1) {
3154 cmdp->OpCode = scp->SCp.sent_command; /* special raw cmd. */
3155 cmdp->BoardNode = LOCALBOARD;
3157 cmdp->u.raw64.direction = (scp->SCp.phase >> 8);
3158 TRACE2(("special raw cmd 0x%x param 0x%x\n",
3159 cmdp->OpCode, cmdp->u.raw64.direction));
3160 /* evaluate command size */
3161 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst);
3163 cmdp->u.raw.direction = (scp->SCp.phase >> 8);
3164 TRACE2(("special raw cmd 0x%x param 0x%x\n",
3165 cmdp->OpCode, cmdp->u.raw.direction));
3166 /* evaluate command size */
3167 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst);
3171 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3172 page = virt_to_page(scp->sense_buffer);
3173 offset = (ulong)scp->sense_buffer & ~PAGE_MASK;
3174 sense_paddr = pci_map_page(ha->pdev,page,offset,
3175 16,PCI_DMA_FROMDEVICE);
3176 scp->SCp.buffer = (struct scatterlist *)((ulong32)sense_paddr);
3177 /* high part, if 64bit */
3178 scp->host_scribble = (char *)(ulong32)((ulong64)sense_paddr >> 32);
3180 sense_paddr = virt_to_bus(scp->sense_buffer);
3182 cmdp->OpCode = GDT_WRITE; /* always */
3183 cmdp->BoardNode = LOCALBOARD;
3185 cmdp->u.raw64.reserved = 0;
3186 cmdp->u.raw64.mdisc_time = 0;
3187 cmdp->u.raw64.mcon_time = 0;
3188 cmdp->u.raw64.clen = scp->cmd_len;
3189 cmdp->u.raw64.target = t;
3190 cmdp->u.raw64.lun = l;
3191 cmdp->u.raw64.bus = b;
3192 cmdp->u.raw64.priority = 0;
3193 cmdp->u.raw64.sdlen = scp->request_bufflen;
3194 cmdp->u.raw64.sense_len = 16;
3195 cmdp->u.raw64.sense_data = sense_paddr;
3196 cmdp->u.raw64.direction =
3197 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
3198 memcpy(cmdp->u.raw64.cmd,scp->cmnd,16);
3200 cmdp->u.raw.reserved = 0;
3201 cmdp->u.raw.mdisc_time = 0;
3202 cmdp->u.raw.mcon_time = 0;
3203 cmdp->u.raw.clen = scp->cmd_len;
3204 cmdp->u.raw.target = t;
3205 cmdp->u.raw.lun = l;
3206 cmdp->u.raw.bus = b;
3207 cmdp->u.raw.priority = 0;
3208 cmdp->u.raw.link_p = 0;
3209 cmdp->u.raw.sdlen = scp->request_bufflen;
3210 cmdp->u.raw.sense_len = 16;
3211 cmdp->u.raw.sense_data = sense_paddr;
3212 cmdp->u.raw.direction =
3213 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
3214 memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
3218 sl = (struct scatterlist *)scp->request_buffer;
3219 sgcnt = scp->use_sg;
3220 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3221 scp->SCp.Status = GDTH_MAP_SG;
3222 scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
3223 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
3225 cmdp->u.raw64.sdata = (ulong64)-1;
3226 cmdp->u.raw64.sg_ranz = sgcnt;
3227 for (i=0; i<sgcnt; ++i,++sl) {
3228 cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl);
3229 #ifdef GDTH_DMA_STATISTICS
3230 if (cmdp->u.raw64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
3235 cmdp->u.raw64.sg_lst[i].sg_len = sg_dma_len(sl);
3238 cmdp->u.raw.sdata = 0xffffffff;
3239 cmdp->u.raw.sg_ranz = sgcnt;
3240 for (i=0; i<sgcnt; ++i,++sl) {
3241 cmdp->u.raw.sg_lst[i].sg_ptr = sg_dma_address(sl);
3242 #ifdef GDTH_DMA_STATISTICS
3245 cmdp->u.raw.sg_lst[i].sg_len = sg_dma_len(sl);
3250 cmdp->u.raw64.sdata = (ulong64)-1;
3251 cmdp->u.raw64.sg_ranz = sgcnt;
3252 for (i=0; i<sgcnt; ++i,++sl) {
3253 cmdp->u.raw64.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
3254 cmdp->u.raw64.sg_lst[i].sg_len = (ulong32)sl->length;
3257 cmdp->u.raw.sdata = 0xffffffff;
3258 cmdp->u.raw.sg_ranz = sgcnt;
3259 for (i=0; i<sgcnt; ++i,++sl) {
3260 cmdp->u.raw.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
3261 cmdp->u.raw.sg_lst[i].sg_len = (ulong32)sl->length;
3266 #ifdef GDTH_STATISTICS
3267 if (max_sg < sgcnt) {
3269 TRACE3(("GDT: max_sg = %d\n",sgcnt));
3274 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3275 scp->SCp.Status = GDTH_MAP_SINGLE;
3276 scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
3277 page = virt_to_page(scp->request_buffer);
3278 offset = (ulong)scp->request_buffer & ~PAGE_MASK;
3279 phys_addr = pci_map_page(ha->pdev,page,offset,
3280 scp->request_bufflen,scp->SCp.Message);
3281 scp->SCp.dma_handle = phys_addr;
3283 phys_addr = virt_to_bus(scp->request_buffer);
3286 if (ha->raw_feat & SCATTER_GATHER) {
3287 cmdp->u.raw64.sdata = (ulong64)-1;
3288 cmdp->u.raw64.sg_ranz= 1;
3289 cmdp->u.raw64.sg_lst[0].sg_ptr = phys_addr;
3290 cmdp->u.raw64.sg_lst[0].sg_len = scp->request_bufflen;
3291 cmdp->u.raw64.sg_lst[1].sg_len = 0;
3293 cmdp->u.raw64.sdata = phys_addr;
3294 cmdp->u.raw64.sg_ranz= 0;
3297 if (ha->raw_feat & SCATTER_GATHER) {
3298 cmdp->u.raw.sdata = 0xffffffff;
3299 cmdp->u.raw.sg_ranz= 1;
3300 cmdp->u.raw.sg_lst[0].sg_ptr = phys_addr;
3301 cmdp->u.raw.sg_lst[0].sg_len = scp->request_bufflen;
3302 cmdp->u.raw.sg_lst[1].sg_len = 0;
3304 cmdp->u.raw.sdata = phys_addr;
3305 cmdp->u.raw.sg_ranz= 0;
3310 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3311 cmdp->u.raw64.sdata,cmdp->u.raw64.sg_ranz,
3312 cmdp->u.raw64.sg_lst[0].sg_ptr,
3313 cmdp->u.raw64.sg_lst[0].sg_len));
3314 /* evaluate command size */
3315 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) +
3316 (ushort)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str);
3318 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3319 cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
3320 cmdp->u.raw.sg_lst[0].sg_ptr,
3321 cmdp->u.raw.sg_lst[0].sg_len));
3322 /* evaluate command size */
3323 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
3324 (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
3328 if (ha->cmd_len & 3)
3329 ha->cmd_len += (4 - (ha->cmd_len & 3));
3331 if (ha->cmd_cnt > 0) {
3332 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
3334 TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
3335 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
3341 gdth_copy_command(hanum);
3345 static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp)
3347 register gdth_ha_str *ha;
3348 register gdth_cmd_str *cmdp;
3351 ha = HADATA(gdth_ctr_tab[hanum]);
3353 TRACE2(("gdth_special_cmd(): "));
3355 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
3358 memcpy( cmdp, scp->request_buffer, sizeof(gdth_cmd_str));
3359 cmdp->RequestBuffer = scp;
3361 /* search free command index */
3362 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
3363 TRACE(("GDT: No free command index found\n"));
3367 /* if it's the first command, set command semaphore */
3368 if (ha->cmd_cnt == 0)
3369 gdth_set_sema0(hanum);
3371 /* evaluate command size, check space */
3372 if (cmdp->OpCode == GDT_IOCTL) {
3373 TRACE2(("IOCTL\n"));
3375 GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong64);
3376 } else if (cmdp->Service == CACHESERVICE) {
3377 TRACE2(("cache command %d\n",cmdp->OpCode));
3378 if (ha->cache_feat & GDT_64BIT)
3380 GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + sizeof(gdth_sg64_str);
3383 GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
3384 } else if (cmdp->Service == SCSIRAWSERVICE) {
3385 TRACE2(("raw command %d\n",cmdp->OpCode));
3386 if (ha->raw_feat & GDT_64BIT)
3388 GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + sizeof(gdth_sg64_str);
3391 GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
3394 if (ha->cmd_len & 3)
3395 ha->cmd_len += (4 - (ha->cmd_len & 3));
3397 if (ha->cmd_cnt > 0) {
3398 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
3400 TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
3401 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
3407 gdth_copy_command(hanum);
3412 /* Controller event handling functions */
3413 static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
3414 ushort idx, gdth_evt_data *evt)
3419 /* no GDTH_LOCK_HA() ! */
3420 TRACE2(("gdth_store_event() source %d idx %d\n", source, idx));
3421 if (source == 0) /* no source -> no event */
3424 if (ebuffer[elastidx].event_source == source &&
3425 ebuffer[elastidx].event_idx == idx &&
3426 ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
3427 !memcmp((char *)&ebuffer[elastidx].event_data.eu,
3428 (char *)&evt->eu, evt->size)) ||
3429 (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
3430 !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
3431 (char *)&evt->event_string)))) {
3432 e = &ebuffer[elastidx];
3433 do_gettimeofday(&tv);
3434 e->last_stamp = tv.tv_sec;
3437 if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
3439 if (elastidx == MAX_EVENTS)
3441 if (elastidx == eoldidx) { /* reached mark ? */
3443 if (eoldidx == MAX_EVENTS)
3447 e = &ebuffer[elastidx];
3448 e->event_source = source;
3450 do_gettimeofday(&tv);
3451 e->first_stamp = e->last_stamp = tv.tv_sec;
3453 e->event_data = *evt;
3459 static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
3465 TRACE2(("gdth_read_event() handle %d\n", handle));
3466 GDTH_LOCK_HA(ha, flags);
3471 estr->event_source = 0;
3473 if (eindex >= MAX_EVENTS) {
3474 GDTH_UNLOCK_HA(ha, flags);
3477 e = &ebuffer[eindex];
3478 if (e->event_source != 0) {
3479 if (eindex != elastidx) {
3480 if (++eindex == MAX_EVENTS)
3485 memcpy(estr, e, sizeof(gdth_evt_str));
3487 GDTH_UNLOCK_HA(ha, flags);
3491 static void gdth_readapp_event(gdth_ha_str *ha,
3492 unchar application, gdth_evt_str *estr)
3497 unchar found = FALSE;
3499 TRACE2(("gdth_readapp_event() app. %d\n", application));
3500 GDTH_LOCK_HA(ha, flags);
3503 e = &ebuffer[eindex];
3504 if (e->event_source == 0)
3506 if ((e->application & application) == 0) {
3507 e->application |= application;
3511 if (eindex == elastidx)
3513 if (++eindex == MAX_EVENTS)
3517 memcpy(estr, e, sizeof(gdth_evt_str));
3519 estr->event_source = 0;
3520 GDTH_UNLOCK_HA(ha, flags);
3523 static void gdth_clear_events()
3525 TRACE(("gdth_clear_events()"));
3527 eoldidx = elastidx = 0;
3528 ebuffer[0].event_source = 0;
3532 /* SCSI interface functions */
3534 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3535 static irqreturn_t gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs)
3537 static void gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs)
3540 register gdth_ha_str *ha;
3541 gdt6m_dpram_str *dp6m_ptr = NULL;
3542 gdt6_dpram_str *dp6_ptr;
3543 gdt2_dpram_str *dp2_ptr;
3550 int coalesced = FALSE;
3552 gdth_coal_status *pcs = NULL;
3553 int act_int_coal = 0;
3556 TRACE(("gdth_interrupt() IRQ %d\n",irq));
3558 /* if polling and not from gdth_wait() -> return */
3560 if (!gdth_from_wait) {
3561 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3570 GDTH_LOCK_HA((gdth_ha_str *)dev_id,flags);
3573 /* search controller */
3574 if ((hanum = gdth_get_status(&IStatus,irq)) == -1) {
3575 /* spurious interrupt */
3577 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3578 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3584 ha = HADATA(gdth_ctr_tab[hanum]);
3586 #ifdef GDTH_STATISTICS
3591 /* See if the fw is returning coalesced status */
3592 if (IStatus == COALINDEX) {
3593 /* Coalesced status. Setup the initial status
3594 buffer pointer and flags */
3595 pcs = ha->coal_stat;
3602 /* For coalesced requests all status
3603 information is found in the status buffer */
3604 IStatus = (unchar)(pcs->status & 0xff);
3608 if (ha->type == GDT_EISA) {
3609 if (IStatus & 0x80) { /* error flag */
3611 ha->status = inw(ha->bmic + MAILBOXREG+8);
3612 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3613 } else /* no error */
3615 ha->info = inl(ha->bmic + MAILBOXREG+12);
3616 ha->service = inw(ha->bmic + MAILBOXREG+10);
3617 ha->info2 = inl(ha->bmic + MAILBOXREG+4);
3619 outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */
3620 outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */
3621 } else if (ha->type == GDT_ISA) {
3622 dp2_ptr = (gdt2_dpram_str *)ha->brd;
3623 if (IStatus & 0x80) { /* error flag */
3625 ha->status = gdth_readw(&dp2_ptr->u.ic.Status);
3626 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3627 } else /* no error */
3629 ha->info = gdth_readl(&dp2_ptr->u.ic.Info[0]);
3630 ha->service = gdth_readw(&dp2_ptr->u.ic.Service);
3631 ha->info2 = gdth_readl(&dp2_ptr->u.ic.Info[1]);
3633 gdth_writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
3634 gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */
3635 gdth_writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */
3636 } else if (ha->type == GDT_PCI) {
3637 dp6_ptr = (gdt6_dpram_str *)ha->brd;
3638 if (IStatus & 0x80) { /* error flag */
3640 ha->status = gdth_readw(&dp6_ptr->u.ic.Status);
3641 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3642 } else /* no error */
3644 ha->info = gdth_readl(&dp6_ptr->u.ic.Info[0]);
3645 ha->service = gdth_readw(&dp6_ptr->u.ic.Service);
3646 ha->info2 = gdth_readl(&dp6_ptr->u.ic.Info[1]);
3648 gdth_writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
3649 gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */
3650 gdth_writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */
3651 } else if (ha->type == GDT_PCINEW) {
3652 if (IStatus & 0x80) { /* error flag */
3654 ha->status = inw(PTR2USHORT(&ha->plx->status));
3655 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3658 ha->info = inl(PTR2USHORT(&ha->plx->info[0]));
3659 ha->service = inw(PTR2USHORT(&ha->plx->service));
3660 ha->info2 = inl(PTR2USHORT(&ha->plx->info[1]));
3662 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
3663 outb(0x00, PTR2USHORT(&ha->plx->sema1_reg));
3664 } else if (ha->type == GDT_PCIMPR) {
3665 dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
3666 if (IStatus & 0x80) { /* error flag */
3670 ha->status = pcs->ext_status && 0xffff;
3673 ha->status = gdth_readw(&dp6m_ptr->i960r.status);
3674 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3675 } else /* no error */
3678 /* get information */
3680 ha->info = pcs->info0;
3681 ha->info2 = pcs->info1;
3682 ha->service = (pcs->ext_status >> 16) && 0xffff;
3686 ha->info = gdth_readl(&dp6m_ptr->i960r.info[0]);
3687 ha->service = gdth_readw(&dp6m_ptr->i960r.service);
3688 ha->info2 = gdth_readl(&dp6m_ptr->i960r.info[1]);
3691 if (IStatus == ASYNCINDEX) {
3692 if (ha->service != SCREENSERVICE &&
3693 (ha->fw_vers & 0xff) >= 0x1a) {
3694 ha->dvr.severity = gdth_readb
3695 (&((gdt6m_dpram_str *)ha->brd)->i960r.severity);
3696 for (i = 0; i < 256; ++i) {
3697 ha->dvr.event_string[i] = gdth_readb
3698 (&((gdt6m_dpram_str *)ha->brd)->i960r.evt_str[i]);
3699 if (ha->dvr.event_string[i] == 0)
3705 /* Make sure that non coalesced interrupts get cleared
3706 before being handled by gdth_async_event/gdth_sync_event */
3710 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3711 gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
3714 TRACE2(("gdth_interrupt() unknown controller type\n"));
3716 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3717 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3724 TRACE(("gdth_interrupt() index %d stat %d info %d\n",
3725 IStatus,ha->status,ha->info));
3727 if (gdth_from_wait) {
3729 wait_index = (int)IStatus;
3732 if (IStatus == ASYNCINDEX) {
3733 TRACE2(("gdth_interrupt() async. event\n"));
3734 gdth_async_event(hanum);
3736 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3738 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3745 if (IStatus == SPEZINDEX) {
3746 TRACE2(("Service unknown or not initialized !\n"));
3747 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3748 ha->dvr.eu.driver.ionode = hanum;
3749 gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr);
3751 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3752 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3758 scp = ha->cmd_tab[IStatus-2].cmnd;
3759 Service = ha->cmd_tab[IStatus-2].service;
3760 ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND;
3761 if (scp == UNUSED_CMND) {
3762 TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus));
3763 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3764 ha->dvr.eu.driver.ionode = hanum;
3765 ha->dvr.eu.driver.index = IStatus;
3766 gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr);
3768 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3769 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3775 if (scp == INTERNAL_CMND) {
3776 TRACE(("gdth_interrupt() answer to internal command\n"));
3778 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3779 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3786 TRACE(("gdth_interrupt() sync. status\n"));
3787 rval = gdth_sync_event(hanum,Service,IStatus,scp);
3789 GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
3791 gdth_putq(hanum,scp,scp->SCp.this_residual);
3792 } else if (rval == 1) {
3793 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3794 GDTH_LOCK_SCSI_DONE(scp->device->host, flags);
3795 scp->scsi_done(scp);
3796 GDTH_UNLOCK_SCSI_DONE(scp->device->host, flags);
3798 GDTH_LOCK_SCSI_DONE(flags);
3799 scp->scsi_done(scp);
3800 GDTH_UNLOCK_SCSI_DONE(flags);
3806 /* go to the next status in the status buffer */
3808 #ifdef GDTH_STATISTICS
3810 if (act_int_coal > max_int_coal) {
3811 max_int_coal = act_int_coal;
3812 printk("GDT: max_int_coal = %d\n",(ushort)max_int_coal);
3815 /* see if there is another status */
3816 if (pcs->status == 0)
3817 /* Stop the coalesce loop */
3822 /* coalescing only for new GDT_PCIMPR controllers available */
3823 if (ha->type == GDT_PCIMPR && coalesced) {
3824 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3825 gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
3830 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3835 static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp)
3837 register gdth_ha_str *ha;
3842 ha = HADATA(gdth_ctr_tab[hanum]);
3844 TRACE(("gdth_sync_event() serv %d status %d\n",
3845 service,ha->status));
3847 if (service == SCREENSERVICE) {
3849 TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
3850 msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
3851 if (msg->msg_len > MSGLEN+1)
3852 msg->msg_len = MSGLEN+1;
3854 if (!(msg->msg_answer && msg->msg_ext)) {
3855 msg->msg_text[msg->msg_len] = '\0';
3856 printk("%s",msg->msg_text);
3859 if (msg->msg_ext && !msg->msg_answer) {
3860 while (gdth_test_busy(hanum))
3862 cmdp->Service = SCREENSERVICE;
3863 cmdp->RequestBuffer = SCREEN_CMND;
3864 gdth_get_cmd_index(hanum);
3865 gdth_set_sema0(hanum);
3866 cmdp->OpCode = GDT_READ;
3867 cmdp->BoardNode = LOCALBOARD;
3868 cmdp->u.screen.reserved = 0;
3869 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3870 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3871 ha->cmd_offs_dpmem = 0;
3872 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3875 gdth_copy_command(hanum);
3876 gdth_release_event(hanum);
3880 if (msg->msg_answer && msg->msg_alen) {
3881 /* default answers (getchar() not possible) */
3882 if (msg->msg_alen == 1) {
3885 msg->msg_text[0] = 0;
3889 msg->msg_text[0] = 1;
3890 msg->msg_text[1] = 0;
3893 msg->msg_answer = 0;
3894 while (gdth_test_busy(hanum))
3896 cmdp->Service = SCREENSERVICE;
3897 cmdp->RequestBuffer = SCREEN_CMND;
3898 gdth_get_cmd_index(hanum);
3899 gdth_set_sema0(hanum);
3900 cmdp->OpCode = GDT_WRITE;
3901 cmdp->BoardNode = LOCALBOARD;
3902 cmdp->u.screen.reserved = 0;
3903 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3904 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3905 ha->cmd_offs_dpmem = 0;
3906 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3909 gdth_copy_command(hanum);
3910 gdth_release_event(hanum);
3916 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3917 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
3918 t = scp->device->id;
3920 b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
3923 if (scp->SCp.sent_command == -1 && b != ha->virt_bus) {
3924 ha->raw[BUS_L2P(ha,b)].io_cnt[t]--;
3926 /* cache or raw service */
3927 if (ha->status == S_BSY) {
3928 TRACE2(("Controller busy -> retry !\n"));
3929 if (scp->SCp.sent_command == GDT_MOUNT)
3930 scp->SCp.sent_command = GDT_CLUST_INFO;
3934 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3935 if (scp->SCp.Status == GDTH_MAP_SG)
3936 pci_unmap_sg(ha->pdev,scp->request_buffer,
3937 scp->use_sg,scp->SCp.Message);
3938 else if (scp->SCp.Status == GDTH_MAP_SINGLE)
3939 pci_unmap_page(ha->pdev,scp->SCp.dma_handle,
3940 scp->request_bufflen,scp->SCp.Message);
3941 if (scp->SCp.buffer) {
3943 addr = (dma_addr_t)(ulong32)scp->SCp.buffer;
3944 if (scp->host_scribble)
3945 addr += (dma_addr_t)((ulong64)(ulong32)scp->host_scribble << 32);
3946 pci_unmap_page(ha->pdev,addr,16,PCI_DMA_FROMDEVICE);
3949 if (ha->status == S_OK) {
3950 scp->SCp.Status = S_OK;
3951 scp->SCp.Message = ha->info;
3952 if (scp->SCp.sent_command != -1) {
3953 TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
3954 scp->SCp.sent_command));
3955 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
3956 if (scp->SCp.sent_command == GDT_CLUST_INFO) {
3957 ha->hdr[t].cluster_type = (unchar)ha->info;
3958 if (!(ha->hdr[t].cluster_type &
3960 /* NOT MOUNTED -> MOUNT */
3961 scp->SCp.sent_command = GDT_MOUNT;
3962 if (ha->hdr[t].cluster_type &
3964 /* cluster drive RESERVED (on the other node) */
3965 scp->SCp.phase = -2; /* reservation conflict */
3968 scp->SCp.sent_command = -1;
3971 if (scp->SCp.sent_command == GDT_MOUNT) {
3972 ha->hdr[t].cluster_type |= CLUSTER_MOUNTED;
3973 ha->hdr[t].media_changed = TRUE;
3974 } else if (scp->SCp.sent_command == GDT_UNMOUNT) {
3975 ha->hdr[t].cluster_type &= ~CLUSTER_MOUNTED;
3976 ha->hdr[t].media_changed = TRUE;
3978 scp->SCp.sent_command = -1;
3981 scp->SCp.this_residual = HIGH_PRI;
3984 /* RESERVE/RELEASE ? */
3985 if (scp->cmnd[0] == RESERVE) {
3986 ha->hdr[t].cluster_type |= CLUSTER_RESERVED;
3987 } else if (scp->cmnd[0] == RELEASE) {
3988 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3990 scp->result = DID_OK << 16;
3991 scp->sense_buffer[0] = 0;
3994 scp->SCp.Status = ha->status;
3995 scp->SCp.Message = ha->info;
3997 if (scp->SCp.sent_command != -1) {
3998 TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
3999 scp->SCp.sent_command, ha->status));
4000 if (scp->SCp.sent_command == GDT_SCAN_START ||
4001 scp->SCp.sent_command == GDT_SCAN_END) {
4002 scp->SCp.sent_command = -1;
4004 scp->SCp.this_residual = HIGH_PRI;
4007 memset((char*)scp->sense_buffer,0,16);
4008 scp->sense_buffer[0] = 0x70;
4009 scp->sense_buffer[2] = NOT_READY;
4010 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
4011 } else if (service == CACHESERVICE) {
4012 if (ha->status == S_CACHE_UNKNOWN &&
4013 (ha->hdr[t].cluster_type &
4014 CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) {
4015 /* bus reset -> force GDT_CLUST_INFO */
4016 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
4018 memset((char*)scp->sense_buffer,0,16);
4019 if (ha->status == (ushort)S_CACHE_RESERV) {
4020 scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
4022 scp->sense_buffer[0] = 0x70;
4023 scp->sense_buffer[2] = NOT_READY;
4024 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
4026 if (scp->done != gdth_scsi_done) {
4027 ha->dvr.size = sizeof(ha->dvr.eu.sync);
4028 ha->dvr.eu.sync.ionode = hanum;
4029 ha->dvr.eu.sync.service = service;
4030 ha->dvr.eu.sync.status = ha->status;
4031 ha->dvr.eu.sync.info = ha->info;
4032 ha->dvr.eu.sync.hostdrive = t;
4033 if (ha->status >= 0x8000)
4034 gdth_store_event(ha, ES_SYNC, 0, &ha->dvr);
4036 gdth_store_event(ha, ES_SYNC, service, &ha->dvr);
4039 /* sense buffer filled from controller firmware (DMA) */
4040 if (ha->status != S_RAW_SCSI || ha->info >= 0x100) {
4041 scp->result = DID_BAD_TARGET << 16;
4043 scp->result = (DID_OK << 16) | ha->info;
4047 if (!scp->SCp.have_data_in)
4048 scp->SCp.have_data_in++;
4056 static char *async_cache_tab[] = {
4057 /* 0*/ "\011\000\002\002\002\004\002\006\004"
4058 "GDT HA %u, service %u, async. status %u/%lu unknown",
4059 /* 1*/ "\011\000\002\002\002\004\002\006\004"
4060 "GDT HA %u, service %u, async. status %u/%lu unknown",
4061 /* 2*/ "\005\000\002\006\004"
4062 "GDT HA %u, Host Drive %lu not ready",
4063 /* 3*/ "\005\000\002\006\004"
4064 "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",
4065 /* 4*/ "\005\000\002\006\004"
4066 "GDT HA %u, mirror update on Host Drive %lu failed",
4067 /* 5*/ "\005\000\002\006\004"
4068 "GDT HA %u, Mirror Drive %lu failed",
4069 /* 6*/ "\005\000\002\006\004"
4070 "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",
4071 /* 7*/ "\005\000\002\006\004"
4072 "GDT HA %u, Host Drive %lu write protected",
4073 /* 8*/ "\005\000\002\006\004"
4074 "GDT HA %u, media changed in Host Drive %lu",
4075 /* 9*/ "\005\000\002\006\004"
4076 "GDT HA %u, Host Drive %lu is offline",
4077 /*10*/ "\005\000\002\006\004"
4078 "GDT HA %u, media change of Mirror Drive %lu",
4079 /*11*/ "\005\000\002\006\004"
4080 "GDT HA %u, Mirror Drive %lu is write protected",
4081 /*12*/ "\005\000\002\006\004"
4082 "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
4083 /*13*/ "\007\000\002\006\002\010\002"
4084 "GDT HA %u, Array Drive %u: Cache Drive %u failed",
4085 /*14*/ "\005\000\002\006\002"
4086 "GDT HA %u, Array Drive %u: FAIL state entered",
4087 /*15*/ "\005\000\002\006\002"
4088 "GDT HA %u, Array Drive %u: error",
4089 /*16*/ "\007\000\002\006\002\010\002"
4090 "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
4091 /*17*/ "\005\000\002\006\002"
4092 "GDT HA %u, Array Drive %u: parity build failed",
4093 /*18*/ "\005\000\002\006\002"
4094 "GDT HA %u, Array Drive %u: drive rebuild failed",
4095 /*19*/ "\005\000\002\010\002"
4096 "GDT HA %u, Test of Hot Fix %u failed",
4097 /*20*/ "\005\000\002\006\002"
4098 "GDT HA %u, Array Drive %u: drive build finished successfully",
4099 /*21*/ "\005\000\002\006\002"
4100 "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
4101 /*22*/ "\007\000\002\006\002\010\002"
4102 "GDT HA %u, Array Drive %u: Hot Fix %u activated",
4103 /*23*/ "\005\000\002\006\002"
4104 "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
4105 /*24*/ "\005\000\002\010\002"
4106 "GDT HA %u, mirror update on Cache Drive %u completed",
4107 /*25*/ "\005\000\002\010\002"
4108 "GDT HA %u, mirror update on Cache Drive %lu failed",
4109 /*26*/ "\005\000\002\006\002"
4110 "GDT HA %u, Array Drive %u: drive rebuild started",
4111 /*27*/ "\005\000\002\012\001"
4112 "GDT HA %u, Fault bus %u: SHELF OK detected",
4113 /*28*/ "\005\000\002\012\001"
4114 "GDT HA %u, Fault bus %u: SHELF not OK detected",
4115 /*29*/ "\007\000\002\012\001\013\001"
4116 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
4117 /*30*/ "\007\000\002\012\001\013\001"
4118 "GDT HA %u, Fault bus %u, ID %u: new disk detected",
4119 /*31*/ "\007\000\002\012\001\013\001"
4120 "GDT HA %u, Fault bus %u, ID %u: old disk detected",
4121 /*32*/ "\007\000\002\012\001\013\001"
4122 "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid",
4123 /*33*/ "\007\000\002\012\001\013\001"
4124 "GDT HA %u, Fault bus %u, ID %u: invalid device detected",
4125 /*34*/ "\011\000\002\012\001\013\001\006\004"
4126 "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
4127 /*35*/ "\007\000\002\012\001\013\001"
4128 "GDT HA %u, Fault bus %u, ID %u: disk write protected",
4129 /*36*/ "\007\000\002\012\001\013\001"
4130 "GDT HA %u, Fault bus %u, ID %u: disk not available",
4131 /*37*/ "\007\000\002\012\001\006\004"
4132 "GDT HA %u, Fault bus %u: swap detected (%lu)",
4133 /*38*/ "\007\000\002\012\001\013\001"
4134 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
4135 /*39*/ "\007\000\002\012\001\013\001"
4136 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
4137 /*40*/ "\007\000\002\012\001\013\001"
4138 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
4139 /*41*/ "\007\000\002\012\001\013\001"
4140 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
4141 /*42*/ "\005\000\002\006\002"
4142 "GDT HA %u, Array Drive %u: drive build started",
4143 /*43*/ "\003\000\002"
4144 "GDT HA %u, DRAM parity error detected",
4145 /*44*/ "\005\000\002\006\002"
4146 "GDT HA %u, Mirror Drive %u: update started",
4147 /*45*/ "\007\000\002\006\002\010\002"
4148 "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
4149 /*46*/ "\005\000\002\006\002"
4150 "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
4151 /*47*/ "\005\000\002\006\002"
4152 "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
4153 /*48*/ "\005\000\002\006\002"
4154 "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
4155 /*49*/ "\005\000\002\006\002"
4156 "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
4157 /*50*/ "\007\000\002\012\001\013\001"
4158 "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
4159 /*51*/ "\005\000\002\006\002"
4160 "GDT HA %u, Array Drive %u: expand started",
4161 /*52*/ "\005\000\002\006\002"
4162 "GDT HA %u, Array Drive %u: expand finished successfully",
4163 /*53*/ "\005\000\002\006\002"
4164 "GDT HA %u, Array Drive %u: expand failed",
4165 /*54*/ "\003\000\002"
4166 "GDT HA %u, CPU temperature critical",
4167 /*55*/ "\003\000\002"
4168 "GDT HA %u, CPU temperature OK",
4169 /*56*/ "\005\000\002\006\004"
4170 "GDT HA %u, Host drive %lu created",
4171 /*57*/ "\005\000\002\006\002"
4172 "GDT HA %u, Array Drive %u: expand restarted",
4173 /*58*/ "\005\000\002\006\002"
4174 "GDT HA %u, Array Drive %u: expand stopped",
4175 /*59*/ "\005\000\002\010\002"
4176 "GDT HA %u, Mirror Drive %u: drive build quited",
4177 /*60*/ "\005\000\002\006\002"
4178 "GDT HA %u, Array Drive %u: parity build quited",
4179 /*61*/ "\005\000\002\006\002"
4180 "GDT HA %u, Array Drive %u: drive rebuild quited",
4181 /*62*/ "\005\000\002\006\002"
4182 "GDT HA %u, Array Drive %u: parity verify started",
4183 /*63*/ "\005\000\002\006\002"
4184 "GDT HA %u, Array Drive %u: parity verify done",
4185 /*64*/ "\005\000\002\006\002"
4186 "GDT HA %u, Array Drive %u: parity verify failed",
4187 /*65*/ "\005\000\002\006\002"
4188 "GDT HA %u, Array Drive %u: parity error detected",
4189 /*66*/ "\005\000\002\006\002"
4190 "GDT HA %u, Array Drive %u: parity verify quited",
4191 /*67*/ "\005\000\002\006\002"
4192 "GDT HA %u, Host Drive %u reserved",
4193 /*68*/ "\005\000\002\006\002"
4194 "GDT HA %u, Host Drive %u mounted and released",
4195 /*69*/ "\005\000\002\006\002"
4196 "GDT HA %u, Host Drive %u released",
4197 /*70*/ "\003\000\002"
4198 "GDT HA %u, DRAM error detected and corrected with ECC",
4199 /*71*/ "\003\000\002"
4200 "GDT HA %u, Uncorrectable DRAM error detected with ECC",
4201 /*72*/ "\011\000\002\012\001\013\001\014\001"
4202 "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
4203 /*73*/ "\005\000\002\006\002"
4204 "GDT HA %u, Host drive %u resetted locally",
4205 /*74*/ "\005\000\002\006\002"
4206 "GDT HA %u, Host drive %u resetted remotely",
4207 /*75*/ "\003\000\002"
4208 "GDT HA %u, async. status 75 unknown",
4212 static int gdth_async_event(int hanum)
4218 ha = HADATA(gdth_ctr_tab[hanum]);
4220 TRACE2(("gdth_async_event() ha %d serv %d\n",
4221 hanum,ha->service));
4223 if (ha->service == SCREENSERVICE) {
4224 if (ha->status == MSG_REQUEST) {
4225 while (gdth_test_busy(hanum))
4227 cmdp->Service = SCREENSERVICE;
4228 cmdp->RequestBuffer = SCREEN_CMND;
4229 cmd_index = gdth_get_cmd_index(hanum);
4230 gdth_set_sema0(hanum);
4231 cmdp->OpCode = GDT_READ;
4232 cmdp->BoardNode = LOCALBOARD;
4233 cmdp->u.screen.reserved = 0;
4234 cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE;
4235 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
4236 ha->cmd_offs_dpmem = 0;
4237 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
4240 gdth_copy_command(hanum);
4241 if (ha->type == GDT_EISA)
4242 printk("[EISA slot %d] ",(ushort)ha->brd_phys);
4243 else if (ha->type == GDT_ISA)
4244 printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys);
4246 printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8),
4247 (ushort)((ha->brd_phys>>3)&0x1f));
4248 gdth_release_event(hanum);
4252 if (ha->type == GDT_PCIMPR &&
4253 (ha->fw_vers & 0xff) >= 0x1a) {
4255 ha->dvr.eu.async.ionode = hanum;
4256 ha->dvr.eu.async.status = ha->status;
4257 /* severity and event_string already set! */
4259 ha->dvr.size = sizeof(ha->dvr.eu.async);
4260 ha->dvr.eu.async.ionode = hanum;
4261 ha->dvr.eu.async.service = ha->service;
4262 ha->dvr.eu.async.status = ha->status;
4263 ha->dvr.eu.async.info = ha->info;
4264 *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2;
4266 gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr );
4267 gdth_log_event( &ha->dvr, NULL );
4269 /* new host drive from expand? */
4270 if (ha->service == CACHESERVICE && ha->status == 56) {
4271 TRACE2(("gdth_async_event(): new host drive %d created\n",
4273 /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
4279 static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
4281 gdth_stackframe stack;
4285 TRACE2(("gdth_log_event()\n"));
4286 if (dvr->size == 0) {
4287 if (buffer == NULL) {
4288 printk("Adapter %d: %s\n",dvr->eu.async.ionode,dvr->event_string);
4290 sprintf(buffer,"Adapter %d: %s\n",
4291 dvr->eu.async.ionode,dvr->event_string);
4293 } else if (dvr->eu.async.service == CACHESERVICE &&
4294 INDEX_OK(dvr->eu.async.status, async_cache_tab)) {
4295 TRACE2(("GDT: Async. event cache service, event no.: %d\n",
4296 dvr->eu.async.status));
4298 f = async_cache_tab[dvr->eu.async.status];
4300 /* i: parameter to push, j: stack element to fill */
4301 for (j=0,i=1; i < f[0]; i+=2) {
4304 stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]];
4307 stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]];
4310 stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]];
4317 if (buffer == NULL) {
4318 printk(&f[(int)f[0]],stack);
4321 sprintf(buffer,&f[(int)f[0]],stack);
4325 if (buffer == NULL) {
4326 printk("GDT HA %u, Unknown async. event service %d event no. %d\n",
4327 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
4329 sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d",
4330 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
4335 #ifdef GDTH_STATISTICS
4336 void gdth_timeout(ulong data)
4344 ha = HADATA(gdth_ctr_tab[hanum]);
4345 GDTH_LOCK_HA(ha, flags);
4347 for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i)
4348 if (ha->cmd_tab[i].cmnd != UNUSED_CMND)
4351 for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
4354 TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
4355 act_ints, act_ios, act_stats, act_rq));
4356 act_ints = act_ios = 0;
4358 gdth_timer.expires = jiffies + 30 * HZ;
4359 add_timer(&gdth_timer);
4360 GDTH_UNLOCK_HA(ha, flags);
4364 GDTH_INITFUNC(void, internal_setup(char *str,int *ints))
4367 char *cur_str, *argv;
4369 TRACE2(("internal_setup() str %s ints[0] %d\n",
4370 str ? str:"NULL", ints ? ints[0]:0));
4372 /* read irq[] from ints[] */
4378 for (i = 0; i < argc; ++i)
4383 /* analyse string */
4385 while (argv && (cur_str = strchr(argv, ':'))) {
4386 int val = 0, c = *++cur_str;
4388 if (c == 'n' || c == 'N')
4390 else if (c == 'y' || c == 'Y')
4393 val = (int)simple_strtoul(cur_str, NULL, 0);
4395 if (!strncmp(argv, "disable:", 8))
4397 else if (!strncmp(argv, "reserve_mode:", 13))
4399 else if (!strncmp(argv, "reverse_scan:", 13))
4401 else if (!strncmp(argv, "hdr_channel:", 12))
4403 else if (!strncmp(argv, "max_ids:", 8))
4405 else if (!strncmp(argv, "rescan:", 7))
4407 else if (!strncmp(argv, "virt_ctr:", 9))
4409 else if (!strncmp(argv, "shared_access:", 14))
4410 shared_access = val;
4411 else if (!strncmp(argv, "probe_eisa_isa:", 15))
4412 probe_eisa_isa = val;
4413 else if (!strncmp(argv, "reserve_list:", 13)) {
4414 reserve_list[0] = val;
4415 for (i = 1; i < MAX_RES_ARGS; i++) {
4416 cur_str = strchr(cur_str, ',');
4419 if (!isdigit((int)*++cur_str)) {
4424 (int)simple_strtoul(cur_str, NULL, 0);
4432 if ((argv = strchr(argv, ',')))
4437 GDTH_INITFUNC(int, option_setup(char *str))
4443 TRACE2(("option_setup() str %s\n", str ? str:"NULL"));
4445 while (cur && isdigit(*cur) && i <= MAXHA) {
4446 ints[i++] = simple_strtoul(cur, NULL, 0);
4447 if ((cur = strchr(cur, ',')) != NULL) cur++;
4451 internal_setup(cur, ints);
4455 GDTH_INITFUNC(int, gdth_detect(Scsi_Host_Template *shtp))
4457 struct Scsi_Host *shp;
4458 gdth_pci_str pcistr[MAXHA];
4462 int i,hanum,cnt,ctr,err;
4467 printk("GDT: This driver contains debugging information !! Trace level = %d\n",
4469 printk(" Destination of debugging information: ");
4472 printk("Serial port COM2\n");
4474 printk("Serial port COM1\n");
4477 printk("Console\n");
4482 TRACE(("gdth_detect()\n"));
4485 printk("GDT-HA: Controller driver disabled from command line !\n");
4489 printk("GDT-HA: Storage RAID Controller Driver. Version: %s \n",GDTH_VERSION_STR);
4490 /* initializations */
4491 gdth_polling = TRUE; b = 0;
4492 gdth_clear_events();
4494 /* As default we do not probe for EISA or ISA controllers */
4495 if (probe_eisa_isa) {
4496 /* scanning for controllers, at first: ISA controller */
4497 for (isa_bios=0xc8000UL; isa_bios<=0xd8000UL; isa_bios+=0x8000UL) {
4498 dma_addr_t scratch_dma_handle;
4499 scratch_dma_handle = 0;
4501 if (gdth_ctr_count >= MAXHA)
4503 if (gdth_search_isa(isa_bios)) { /* controller found */
4504 shp = scsi_register(shtp,sizeof(gdth_ext_str));
4509 if (!gdth_init_isa(isa_bios,ha)) {
4510 scsi_unregister(shp);
4516 /* controller found and initialized */
4517 printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
4518 isa_bios,ha->irq,ha->drq);
4520 if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha)) {
4521 printk("GDT-ISA: Unable to allocate IRQ\n");
4522 scsi_unregister(shp);
4525 if (request_dma(ha->drq,"gdth")) {
4526 printk("GDT-ISA: Unable to allocate DMA channel\n");
4527 free_irq(ha->irq,ha);
4528 scsi_unregister(shp);
4531 set_dma_mode(ha->drq,DMA_MODE_CASCADE);
4532 enable_dma(ha->drq);
4533 shp->unchecked_isa_dma = 1;
4535 shp->dma_channel = ha->drq;
4536 hanum = gdth_ctr_count;
4537 gdth_ctr_tab[gdth_ctr_count++] = shp;
4538 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4540 NUMDATA(shp)->hanum = (ushort)hanum;
4541 NUMDATA(shp)->busnum= 0;
4543 ha->pccb = CMDDATA(shp);
4545 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4547 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4548 &scratch_dma_handle);
4549 ha->scratch_phys = scratch_dma_handle;
4550 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4551 &scratch_dma_handle);
4552 ha->msg_phys = scratch_dma_handle;
4554 ha->coal_stat = (gdth_coal_status *)
4555 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4556 MAXOFFSETS, &scratch_dma_handle);
4557 ha->coal_stat_phys = scratch_dma_handle;
4560 ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
4562 ha->scratch_phys = virt_to_bus(ha->pscratch);
4563 ha->pmsg = scsi_init_malloc(sizeof(gdth_msg_str), GFP_ATOMIC | GFP_DMA);
4565 ha->msg_phys = virt_to_bus(ha->pmsg);
4568 scsi_init_malloc(sizeof(gdth_coal_status) * MAXOFFSETS,
4569 GFP_ATOMIC | GFP_DMA);
4571 ha->coal_stat_phys = virt_to_bus(ha->coal_stat);
4574 ha->scratch_busy = FALSE;
4575 ha->req_first = NULL;
4576 ha->tid_cnt = MAX_HDRIVES;
4577 if (max_ids > 0 && max_ids < ha->tid_cnt)
4578 ha->tid_cnt = max_ids;
4579 for (i=0; i<GDTH_MAXCMDS; ++i)
4580 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4581 ha->scan_mode = rescan ? 0x10 : 0;
4583 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4584 !gdth_search_drives(hanum)) {
4585 printk("GDT-ISA: Error during device scan\n");
4588 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4591 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4592 MAXOFFSETS, ha->coal_stat,
4593 ha->coal_stat_phys);
4596 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4597 ha->pscratch, ha->scratch_phys);
4599 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4600 ha->pmsg, ha->msg_phys);
4604 scsi_init_free((void *)ha->coal_stat,
4605 sizeof(gdth_coal_status) * MAXOFFSETS);
4608 scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
4610 scsi_init_free((void *)ha->pmsg, sizeof(gdth_msg_str));
4612 free_irq(ha->irq,ha);
4613 scsi_unregister(shp);
4616 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4617 hdr_channel = ha->bus_cnt;
4618 ha->virt_bus = hdr_channel;
4620 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4621 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
4622 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4623 shp->highmem_io = 0;
4625 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4626 shp->max_cmd_len = 16;
4628 shp->max_id = ha->tid_cnt;
4629 shp->max_lun = MAXLUN;
4630 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4633 /* register addit. SCSI channels as virtual controllers */
4634 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4635 shp = scsi_register(shtp,sizeof(gdth_num_str));
4636 shp->unchecked_isa_dma = 1;
4638 shp->dma_channel = ha->drq;
4639 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4640 NUMDATA(shp)->hanum = (ushort)hanum;
4641 NUMDATA(shp)->busnum = b;
4645 GDTH_INIT_LOCK_HA(ha);
4646 gdth_enable_int(hanum);
4647 #endif /* !__ia64__ */
4651 /* scanning for EISA controllers */
4652 for (eisa_slot=0x1000; eisa_slot<=0x8000; eisa_slot+=0x1000) {
4653 dma_addr_t scratch_dma_handle;
4654 scratch_dma_handle = 0;
4656 if (gdth_ctr_count >= MAXHA)
4658 if (gdth_search_eisa(eisa_slot)) { /* controller found */
4659 shp = scsi_register(shtp,sizeof(gdth_ext_str));
4664 if (!gdth_init_eisa(eisa_slot,ha)) {
4665 scsi_unregister(shp);
4668 /* controller found and initialized */
4669 printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
4670 eisa_slot>>12,ha->irq);
4672 if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha)) {
4673 printk("GDT-EISA: Unable to allocate IRQ\n");
4674 scsi_unregister(shp);
4677 shp->unchecked_isa_dma = 0;
4679 shp->dma_channel = 0xff;
4680 hanum = gdth_ctr_count;
4681 gdth_ctr_tab[gdth_ctr_count++] = shp;
4682 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4684 NUMDATA(shp)->hanum = (ushort)hanum;
4685 NUMDATA(shp)->busnum= 0;
4686 TRACE2(("EISA detect Bus 0: hanum %d\n",
4687 NUMDATA(shp)->hanum));
4689 ha->pccb = CMDDATA(shp);
4691 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4693 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4694 &scratch_dma_handle);
4695 ha->scratch_phys = scratch_dma_handle;
4696 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4697 &scratch_dma_handle);
4698 ha->msg_phys = scratch_dma_handle;
4700 ha->coal_stat = (gdth_coal_status *)
4701 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4702 MAXOFFSETS, &scratch_dma_handle);
4703 ha->coal_stat_phys = scratch_dma_handle;
4706 pci_map_single(ha->pdev,ha->pccb,
4707 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
4709 ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
4711 ha->scratch_phys = virt_to_bus(ha->pscratch);
4712 ha->pmsg = scsi_init_malloc(sizeof(gdth_msg_str), GFP_ATOMIC | GFP_DMA);
4714 ha->msg_phys = virt_to_bus(ha->pmsg);
4717 scsi_init_malloc(sizeof(gdth_coal_status) * MAXOFFSETS,
4718 GFP_ATOMIC | GFP_DMA);
4720 ha->coal_stat_phys = virt_to_bus(ha->coal_stat);
4722 ha->ccb_phys = virt_to_bus(ha->pccb);
4724 ha->scratch_busy = FALSE;
4725 ha->req_first = NULL;
4726 ha->tid_cnt = MAX_HDRIVES;
4727 if (max_ids > 0 && max_ids < ha->tid_cnt)
4728 ha->tid_cnt = max_ids;
4729 for (i=0; i<GDTH_MAXCMDS; ++i)
4730 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4731 ha->scan_mode = rescan ? 0x10 : 0;
4733 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4734 !gdth_search_drives(hanum)) {
4735 printk("GDT-EISA: Error during device scan\n");
4738 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4741 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4742 MAXOFFSETS, ha->coal_stat,
4743 ha->coal_stat_phys);
4746 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4747 ha->pscratch, ha->scratch_phys);
4749 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4750 ha->pmsg, ha->msg_phys);
4752 pci_unmap_single(ha->pdev,ha->ccb_phys,
4753 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
4757 scsi_init_free((void *)ha->coal_stat,
4758 sizeof(gdth_coal_status) * MAXOFFSETS);
4761 scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
4763 scsi_init_free((void *)ha->pmsg, sizeof(gdth_msg_str));
4765 free_irq(ha->irq,ha);
4766 scsi_unregister(shp);
4769 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4770 hdr_channel = ha->bus_cnt;
4771 ha->virt_bus = hdr_channel;
4773 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4774 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
4775 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4776 shp->highmem_io = 0;
4778 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4779 shp->max_cmd_len = 16;
4781 shp->max_id = ha->tid_cnt;
4782 shp->max_lun = MAXLUN;
4783 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4786 /* register addit. SCSI channels as virtual controllers */
4787 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4788 shp = scsi_register(shtp,sizeof(gdth_num_str));
4789 shp->unchecked_isa_dma = 0;
4791 shp->dma_channel = 0xff;
4792 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4793 NUMDATA(shp)->hanum = (ushort)hanum;
4794 NUMDATA(shp)->busnum = b;
4798 GDTH_INIT_LOCK_HA(ha);
4799 gdth_enable_int(hanum);
4804 /* scanning for PCI controllers */
4805 cnt = gdth_search_pci(pcistr);
4806 printk("GDT-HA: Found %d PCI Storage RAID Controllers\n",cnt);
4807 gdth_sort_pci(pcistr,cnt);
4808 for (ctr = 0; ctr < cnt; ++ctr) {
4809 dma_addr_t scratch_dma_handle;
4810 scratch_dma_handle = 0;
4812 if (gdth_ctr_count >= MAXHA)
4814 shp = scsi_register(shtp,sizeof(gdth_ext_str));
4819 if (!gdth_init_pci(&pcistr[ctr],ha)) {
4820 scsi_unregister(shp);
4823 /* controller found and initialized */
4824 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
4825 pcistr[ctr].bus,PCI_SLOT(pcistr[ctr].device_fn),ha->irq);
4827 if (request_irq(ha->irq, gdth_interrupt,
4828 SA_INTERRUPT|SA_SHIRQ, "gdth", ha))
4830 printk("GDT-PCI: Unable to allocate IRQ\n");
4831 scsi_unregister(shp);
4834 shp->unchecked_isa_dma = 0;
4836 shp->dma_channel = 0xff;
4837 hanum = gdth_ctr_count;
4838 gdth_ctr_tab[gdth_ctr_count++] = shp;
4839 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4841 NUMDATA(shp)->hanum = (ushort)hanum;
4842 NUMDATA(shp)->busnum= 0;
4844 ha->pccb = CMDDATA(shp);
4846 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4847 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4848 &scratch_dma_handle);
4849 ha->scratch_phys = scratch_dma_handle;
4850 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4851 &scratch_dma_handle);
4852 ha->msg_phys = scratch_dma_handle;
4854 ha->coal_stat = (gdth_coal_status *)
4855 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4856 MAXOFFSETS, &scratch_dma_handle);
4857 ha->coal_stat_phys = scratch_dma_handle;
4860 ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
4862 ha->scratch_phys = virt_to_bus(ha->pscratch);
4863 ha->pmsg = scsi_init_malloc(sizeof(gdth_msg_str), GFP_ATOMIC | GFP_DMA);
4865 ha->msg_phys = virt_to_bus(ha->pmsg);
4868 scsi_init_malloc(sizeof(gdth_coal_status) * MAXOFFSETS,
4869 GFP_ATOMIC | GFP_DMA);
4871 ha->coal_stat_phys = virt_to_bus(ha->coal_stat);
4874 ha->scratch_busy = FALSE;
4875 ha->req_first = NULL;
4876 ha->tid_cnt = pcistr[ctr].device_id >= 0x200 ? MAXID : MAX_HDRIVES;
4877 if (max_ids > 0 && max_ids < ha->tid_cnt)
4878 ha->tid_cnt = max_ids;
4879 for (i=0; i<GDTH_MAXCMDS; ++i)
4880 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4881 ha->scan_mode = rescan ? 0x10 : 0;
4884 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4885 !gdth_search_drives(hanum)) {
4888 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4889 hdr_channel = ha->bus_cnt;
4890 ha->virt_bus = hdr_channel;
4892 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4893 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4894 scsi_set_device(shp, &pcistr[ctr].pdev->dev);
4896 scsi_set_pci_device(shp, pcistr[ctr].pdev);
4898 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat &GDT_64BIT)||
4899 /* 64-bit DMA only supported from FW >= x.43 */
4900 (!ha->dma64_support)) {
4901 if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) {
4902 printk(KERN_WARNING "GDT-PCI %d: Unable to set 32-bit DMA\n", hanum);
4906 shp->max_cmd_len = 16;
4907 if (!pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffffffffffffULL)) {
4908 printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);
4909 } else if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) {
4910 printk(KERN_WARNING "GDT-PCI %d: Unable to set 64/32-bit DMA\n", hanum);
4918 printk("GDT-PCI %d: Error during device scan\n", hanum);
4921 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4924 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4925 MAXOFFSETS, ha->coal_stat,
4926 ha->coal_stat_phys);
4929 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4930 ha->pscratch, ha->scratch_phys);
4932 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4933 ha->pmsg, ha->msg_phys);
4937 scsi_init_free((void *)ha->coal_stat,
4938 sizeof(gdth_coal_status) * MAXOFFSETS);
4941 scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
4943 scsi_init_free((void *)ha->pmsg, sizeof(gdth_msg_str));
4945 free_irq(ha->irq,ha);
4946 scsi_unregister(shp);
4950 shp->max_id = ha->tid_cnt;
4951 shp->max_lun = MAXLUN;
4952 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4955 /* register addit. SCSI channels as virtual controllers */
4956 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4957 shp = scsi_register(shtp,sizeof(gdth_num_str));
4958 shp->unchecked_isa_dma = 0;
4960 shp->dma_channel = 0xff;
4961 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4962 NUMDATA(shp)->hanum = (ushort)hanum;
4963 NUMDATA(shp)->busnum = b;
4968 GDTH_INIT_LOCK_HA(ha);
4969 gdth_enable_int(hanum);
4972 TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count));
4973 if (gdth_ctr_count > 0) {
4974 #ifdef GDTH_STATISTICS
4975 TRACE2(("gdth_detect(): Initializing timer !\n"));
4976 init_timer(&gdth_timer);
4977 gdth_timer.expires = jiffies + HZ;
4978 gdth_timer.data = 0L;
4979 gdth_timer.function = gdth_timeout;
4980 add_timer(&gdth_timer);
4982 major = register_chrdev(0,"gdth",&gdth_fops);
4983 register_reboot_notifier(&gdth_notifier);
4985 gdth_polling = FALSE;
4986 return gdth_ctr_vcount;
4990 int gdth_release(struct Scsi_Host *shp)
4995 TRACE2(("gdth_release()\n"));
4996 if (NUMDATA(shp)->busnum == 0) {
4997 hanum = NUMDATA(shp)->hanum;
4998 ha = HADATA(gdth_ctr_tab[hanum]);
4999 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5001 scsi_free_host_dev(ha->sdev);
5008 free_irq(shp->irq,ha);
5011 if (shp->dma_channel != 0xff) {
5012 free_dma(shp->dma_channel);
5015 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5018 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
5019 MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys);
5022 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5023 ha->pscratch, ha->scratch_phys);
5025 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5026 ha->pmsg, ha->msg_phys);
5028 pci_unmap_single(ha->pdev,ha->ccb_phys,
5029 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
5033 scsi_init_free((void *)ha->coal_stat,
5034 sizeof(gdth_coal_status) * MAXOFFSETS);
5037 scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
5039 scsi_init_free((void *)ha->pmsg, sizeof(gdth_msg_str));
5041 gdth_ctr_released++;
5042 TRACE2(("gdth_release(): HA %d of %d\n",
5043 gdth_ctr_released, gdth_ctr_count));
5045 if (gdth_ctr_released == gdth_ctr_count) {
5046 #ifdef GDTH_STATISTICS
5047 del_timer(&gdth_timer);
5049 unregister_chrdev(major,"gdth");
5050 unregister_reboot_notifier(&gdth_notifier);
5054 scsi_unregister(shp);
5059 static const char *gdth_ctr_name(int hanum)
5063 TRACE2(("gdth_ctr_name()\n"));
5065 ha = HADATA(gdth_ctr_tab[hanum]);
5067 if (ha->type == GDT_EISA) {
5068 switch (ha->stype) {
5070 return("GDT3000/3020");
5072 return("GDT3000A/3020A/3050A");
5074 return("GDT3000B/3010A");
5076 } else if (ha->type == GDT_ISA) {
5077 return("GDT2000/2020");
5078 } else if (ha->type == GDT_PCI) {
5079 switch (ha->stype) {
5080 case PCI_DEVICE_ID_VORTEX_GDT60x0:
5081 return("GDT6000/6020/6050");
5082 case PCI_DEVICE_ID_VORTEX_GDT6000B:
5083 return("GDT6000B/6010");
5086 /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
5091 const char *gdth_info(struct Scsi_Host *shp)
5096 TRACE2(("gdth_info()\n"));
5097 hanum = NUMDATA(shp)->hanum;
5098 ha = HADATA(gdth_ctr_tab[hanum]);
5100 return ((const char *)ha->binfo.type_string);
5103 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
5104 /* old error handling */
5105 int gdth_abort(Scsi_Cmnd *scp)
5107 TRACE2(("gdth_abort() reason %d\n",scp->abort_reason));
5108 return SCSI_ABORT_SNOOZE;
5111 int gdth_reset(Scsi_Cmnd *scp, unsigned int reset_flags)
5113 TRACE2(("gdth_reset()\n"));
5114 return SCSI_RESET_PUNT;
5118 /* new error handling */
5119 int gdth_eh_abort(Scsi_Cmnd *scp)
5121 TRACE2(("gdth_eh_abort()\n"));
5125 int gdth_eh_device_reset(Scsi_Cmnd *scp)
5127 TRACE2(("gdth_eh_device_reset()\n"));
5131 int gdth_eh_bus_reset(Scsi_Cmnd *scp)
5139 TRACE2(("gdth_eh_bus_reset()\n"));
5140 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5141 hanum = NUMDATA(scp->device->host)->hanum;
5142 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
5144 hanum = NUMDATA(scp->host)->hanum;
5145 b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
5147 ha = HADATA(gdth_ctr_tab[hanum]);
5149 /* clear command tab */
5150 GDTH_LOCK_HA(ha, flags);
5151 for (i = 0; i < GDTH_MAXCMDS; ++i) {
5152 cmnd = ha->cmd_tab[i].cmnd;
5153 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5154 if (!SPECIAL_SCP(cmnd) && cmnd->device->channel == b)
5156 if (!SPECIAL_SCP(cmnd) && cmnd->channel == b)
5158 ha->cmd_tab[i].cmnd = UNUSED_CMND;
5160 GDTH_UNLOCK_HA(ha, flags);
5162 if (b == ha->virt_bus) {
5164 for (i = 0; i < MAX_HDRIVES; ++i) {
5165 if (ha->hdr[i].present) {
5166 GDTH_LOCK_HA(ha, flags);
5167 gdth_polling = TRUE;
5168 while (gdth_test_busy(hanum))
5170 if (gdth_internal_cmd(hanum, CACHESERVICE,
5171 GDT_CLUST_RESET, i, 0, 0))
5172 ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED;
5173 gdth_polling = FALSE;
5174 GDTH_UNLOCK_HA(ha, flags);
5179 GDTH_LOCK_HA(ha, flags);
5180 for (i = 0; i < MAXID; ++i)
5181 ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0;
5182 gdth_polling = TRUE;
5183 while (gdth_test_busy(hanum))
5185 gdth_internal_cmd(hanum, SCSIRAWSERVICE, GDT_RESET_BUS,
5186 BUS_L2P(ha,b), 0, 0);
5187 gdth_polling = FALSE;
5188 GDTH_UNLOCK_HA(ha, flags);
5193 int gdth_eh_host_reset(Scsi_Cmnd *scp)
5195 TRACE2(("gdth_eh_host_reset()\n"));
5200 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5201 int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip)
5203 int gdth_bios_param(Disk *disk,kdev_t dev,int *ip)
5209 struct scsi_device *sd;
5212 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5217 capacity = disk->capacity;
5219 hanum = NUMDATA(sd->host)->hanum;
5220 b = virt_ctr ? NUMDATA(sd->host)->busnum : sd->channel;
5222 TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", hanum, b, t));
5223 ha = HADATA(gdth_ctr_tab[hanum]);
5225 if (b != ha->virt_bus || ha->hdr[t].heads == 0) {
5226 /* raw device or host drive without mapping information */
5227 TRACE2(("Evaluate mapping\n"));
5228 gdth_eval_mapping(capacity,&ip[2],&ip[0],&ip[1]);
5230 ip[0] = ha->hdr[t].heads;
5231 ip[1] = ha->hdr[t].secs;
5232 ip[2] = capacity / ip[0] / ip[1];
5235 TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
5236 ip[0],ip[1],ip[2]));
5241 int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *))
5246 TRACE(("gdth_queuecommand() cmd 0x%x\n", scp->cmnd[0]));
5248 scp->scsi_done = (void *)done;
5249 scp->SCp.have_data_in = 1;
5250 scp->SCp.phase = -1;
5251 scp->SCp.sent_command = -1;
5252 scp->SCp.Status = GDTH_MAP_NONE;
5253 scp->SCp.buffer = (struct scatterlist *)NULL;
5254 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5255 hanum = NUMDATA(scp->device->host)->hanum;
5257 hanum = NUMDATA(scp->host)->hanum;
5259 #ifdef GDTH_STATISTICS
5263 priority = DEFAULT_PRI;
5264 if (scp->done == gdth_scsi_done)
5265 priority = scp->SCp.this_residual;
5266 gdth_update_timeout(hanum, scp, scp->timeout_per_command * 6);
5267 gdth_putq( hanum, scp, priority );
5273 static int gdth_open(struct inode *inode, struct file *filep)
5275 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5279 for (i = 0; i < gdth_ctr_count; i++) {
5280 ha = HADATA(gdth_ctr_tab[i]);
5282 ha->sdev = scsi_get_host_dev(gdth_ctr_tab[i]);
5286 TRACE(("gdth_open()\n"));
5290 static int gdth_close(struct inode *inode, struct file *filep)
5292 TRACE(("gdth_close()\n"));
5296 static int ioc_event(unsigned long arg)
5298 gdth_ioctl_event evt;
5302 if (copy_from_user(&evt, (char *)arg, sizeof(gdth_ioctl_event)) ||
5303 evt.ionode >= gdth_ctr_count)
5305 ha = HADATA(gdth_ctr_tab[evt.ionode]);
5307 if (evt.erase == 0xff) {
5308 if (evt.event.event_source == ES_TEST)
5309 evt.event.event_data.size=sizeof(evt.event.event_data.eu.test);
5310 else if (evt.event.event_source == ES_DRIVER)
5311 evt.event.event_data.size=sizeof(evt.event.event_data.eu.driver);
5312 else if (evt.event.event_source == ES_SYNC)
5313 evt.event.event_data.size=sizeof(evt.event.event_data.eu.sync);
5315 evt.event.event_data.size=sizeof(evt.event.event_data.eu.async);
5316 GDTH_LOCK_HA(ha, flags);
5317 gdth_store_event(ha, evt.event.event_source, evt.event.event_idx,
5318 &evt.event.event_data);
5319 GDTH_UNLOCK_HA(ha, flags);
5320 } else if (evt.erase == 0xfe) {
5321 gdth_clear_events();
5322 } else if (evt.erase == 0) {
5323 evt.handle = gdth_read_event(ha, evt.handle, &evt.event);
5325 gdth_readapp_event(ha, evt.erase, &evt.event);
5327 if (copy_to_user((char *)arg, &evt, sizeof(gdth_ioctl_event)))
5332 static int ioc_lockdrv(unsigned long arg)
5334 gdth_ioctl_lockdrv ldrv;
5339 if (copy_from_user(&ldrv, (char *)arg, sizeof(gdth_ioctl_lockdrv)) ||
5340 ldrv.ionode >= gdth_ctr_count)
5342 ha = HADATA(gdth_ctr_tab[ldrv.ionode]);
5344 for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) {
5346 if (j >= MAX_HDRIVES || !ha->hdr[j].present)
5349 GDTH_LOCK_HA(ha, flags);
5350 ha->hdr[j].lock = 1;
5351 GDTH_UNLOCK_HA(ha, flags);
5352 gdth_wait_completion(ldrv.ionode, ha->bus_cnt, j);
5353 gdth_stop_timeout(ldrv.ionode, ha->bus_cnt, j);
5355 GDTH_LOCK_HA(ha, flags);
5356 ha->hdr[j].lock = 0;
5357 GDTH_UNLOCK_HA(ha, flags);
5358 gdth_start_timeout(ldrv.ionode, ha->bus_cnt, j);
5359 gdth_next(ldrv.ionode);
5365 static int ioc_resetdrv(unsigned long arg, char *cmnd)
5367 gdth_ioctl_reset res;
5371 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5373 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5379 if (copy_from_user(&res, (char *)arg, sizeof(gdth_ioctl_reset)) ||
5380 res.ionode >= gdth_ctr_count || res.number >= MAX_HDRIVES)
5383 ha = HADATA(gdth_ctr_tab[hanum]);
5385 if (!ha->hdr[res.number].present)
5387 memset(&cmd, 0, sizeof(gdth_cmd_str));
5388 cmd.Service = CACHESERVICE;
5389 cmd.OpCode = GDT_CLUST_RESET;
5390 if (ha->cache_feat & GDT_64BIT)
5391 cmd.u.cache64.DeviceNo = res.number;
5393 cmd.u.cache.DeviceNo = res.number;
5394 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5395 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5398 srp->sr_cmd_len = 12;
5400 gdth_do_req(srp, &cmd, cmnd, 30);
5401 res.status = (ushort)srp->sr_command->SCp.Status;
5402 scsi_release_request(srp);
5403 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5404 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5409 gdth_do_cmd(scp, &cmd, cmnd, 30);
5410 res.status = (ushort)scp->SCp.Status;
5411 scsi_release_command(scp);
5413 memset(&ha->sdev,0,sizeof(Scsi_Device));
5414 memset(&scp, 0,sizeof(Scsi_Cmnd));
5415 ha->sdev.host = scp.host = gdth_ctr_tab[hanum];
5416 ha->sdev.id = scp.target = ha->sdev.host->this_id;
5417 scp.device = &ha->sdev;
5418 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5419 res.status = (ushort)scp.SCp.Status;
5421 if (copy_to_user((char *)arg, &res, sizeof(gdth_ioctl_reset)))
5426 static int ioc_general(unsigned long arg, char *cmnd)
5428 gdth_ioctl_general gen;
5433 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5435 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5441 if (copy_from_user(&gen, (char *)arg, sizeof(gdth_ioctl_general)) ||
5442 gen.ionode >= gdth_ctr_count)
5445 ha = HADATA(gdth_ctr_tab[hanum]);
5446 if (gen.data_len + gen.sense_len != 0) {
5447 if (!(buf = gdth_ioctl_alloc(hanum, gen.data_len + gen.sense_len,
5450 if (copy_from_user(buf, (char *)arg + sizeof(gdth_ioctl_general),
5451 gen.data_len + gen.sense_len)) {
5452 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5456 if (gen.command.OpCode == GDT_IOCTL) {
5457 gen.command.u.ioctl.p_param = paddr;
5458 } else if (gen.command.Service == CACHESERVICE) {
5459 if (ha->cache_feat & GDT_64BIT) {
5460 /* copy elements from 32-bit IOCTL structure */
5461 gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt;
5462 gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo;
5463 gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo;
5465 if (ha->cache_feat & SCATTER_GATHER) {
5466 gen.command.u.cache64.DestAddr = (ulong64)-1;
5467 gen.command.u.cache64.sg_canz = 1;
5468 gen.command.u.cache64.sg_lst[0].sg_ptr = paddr;
5469 gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len;
5470 gen.command.u.cache64.sg_lst[1].sg_len = 0;
5472 gen.command.u.cache64.DestAddr = paddr;
5473 gen.command.u.cache64.sg_canz = 0;
5476 if (ha->cache_feat & SCATTER_GATHER) {
5477 gen.command.u.cache.DestAddr = 0xffffffff;
5478 gen.command.u.cache.sg_canz = 1;
5479 gen.command.u.cache.sg_lst[0].sg_ptr = (ulong32)paddr;
5480 gen.command.u.cache.sg_lst[0].sg_len = gen.data_len;
5481 gen.command.u.cache.sg_lst[1].sg_len = 0;
5483 gen.command.u.cache.DestAddr = paddr;
5484 gen.command.u.cache.sg_canz = 0;
5487 } else if (gen.command.Service == SCSIRAWSERVICE) {
5488 if (ha->raw_feat & GDT_64BIT) {
5489 /* copy elements from 32-bit IOCTL structure */
5491 gen.command.u.raw64.sense_len = gen.command.u.raw.sense_len;
5492 gen.command.u.raw64.bus = gen.command.u.raw.bus;
5493 gen.command.u.raw64.lun = gen.command.u.raw.lun;
5494 gen.command.u.raw64.target = gen.command.u.raw.target;
5495 memcpy(cmd, gen.command.u.raw.cmd, 16);
5496 memcpy(gen.command.u.raw64.cmd, cmd, 16);
5497 gen.command.u.raw64.clen = gen.command.u.raw.clen;
5498 gen.command.u.raw64.sdlen = gen.command.u.raw.sdlen;
5499 gen.command.u.raw64.direction = gen.command.u.raw.direction;
5501 if (ha->raw_feat & SCATTER_GATHER) {
5502 gen.command.u.raw64.sdata = (ulong64)-1;
5503 gen.command.u.raw64.sg_ranz = 1;
5504 gen.command.u.raw64.sg_lst[0].sg_ptr = paddr;
5505 gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len;
5506 gen.command.u.raw64.sg_lst[1].sg_len = 0;
5508 gen.command.u.raw64.sdata = paddr;
5509 gen.command.u.raw64.sg_ranz = 0;
5511 gen.command.u.raw64.sense_data = paddr + gen.data_len;
5513 if (ha->raw_feat & SCATTER_GATHER) {
5514 gen.command.u.raw.sdata = 0xffffffff;
5515 gen.command.u.raw.sg_ranz = 1;
5516 gen.command.u.raw.sg_lst[0].sg_ptr = (ulong32)paddr;
5517 gen.command.u.raw.sg_lst[0].sg_len = gen.data_len;
5518 gen.command.u.raw.sg_lst[1].sg_len = 0;
5520 gen.command.u.raw.sdata = paddr;
5521 gen.command.u.raw.sg_ranz = 0;
5523 gen.command.u.raw.sense_data = (ulong32)paddr + gen.data_len;
5526 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5531 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5532 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5535 srp->sr_cmd_len = 12;
5537 gdth_do_req(srp, &gen.command, cmnd, gen.timeout);
5538 gen.status = srp->sr_command->SCp.Status;
5539 gen.info = srp->sr_command->SCp.Message;
5540 scsi_release_request(srp);
5541 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5542 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5547 gdth_do_cmd(scp, &gen.command, cmnd, gen.timeout);
5548 gen.status = scp->SCp.Status;
5549 gen.info = scp->SCp.Message;
5550 scsi_release_command(scp);
5552 memset(&ha->sdev,0,sizeof(Scsi_Device));
5553 memset(&scp, 0,sizeof(Scsi_Cmnd));
5554 ha->sdev.host = scp.host = gdth_ctr_tab[hanum];
5555 ha->sdev.id = scp.target = ha->sdev.host->this_id;
5556 scp.device = &ha->sdev;
5557 gdth_do_cmd(&scp, &gen.command, cmnd, gen.timeout);
5558 gen.status = scp.SCp.Status;
5559 gen.info = scp.SCp.Message;
5562 if (copy_to_user((char *)arg + sizeof(gdth_ioctl_general), buf,
5563 gen.data_len + gen.sense_len)) {
5564 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5567 if (copy_to_user((char *)arg, &gen,
5568 sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) {
5569 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5572 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5576 static int ioc_hdrlist(unsigned long arg, char *cmnd)
5578 gdth_ioctl_rescan rsc;
5583 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5585 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5591 if (copy_from_user(&rsc, (char *)arg, sizeof(gdth_ioctl_rescan)) ||
5592 rsc.ionode >= gdth_ctr_count)
5595 ha = HADATA(gdth_ctr_tab[hanum]);
5596 memset(&cmd, 0, sizeof(gdth_cmd_str));
5598 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5599 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5602 srp->sr_cmd_len = 12;
5604 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5605 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5611 memset(&ha->sdev,0,sizeof(Scsi_Device));
5612 memset(&scp, 0,sizeof(Scsi_Cmnd));
5613 ha->sdev.host = scp.host = gdth_ctr_tab[hanum];
5614 ha->sdev.id = scp.target = ha->sdev.host->this_id;
5615 scp.device = &ha->sdev;
5618 for (i = 0; i < MAX_HDRIVES; ++i) {
5619 if (!ha->hdr[i].present) {
5620 rsc.hdr_list[i].bus = 0xff;
5623 rsc.hdr_list[i].bus = ha->virt_bus;
5624 rsc.hdr_list[i].target = i;
5625 rsc.hdr_list[i].lun = 0;
5626 rsc.hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
5627 if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) {
5628 cmd.Service = CACHESERVICE;
5629 cmd.OpCode = GDT_CLUST_INFO;
5630 if (ha->cache_feat & GDT_64BIT)
5631 cmd.u.cache64.DeviceNo = i;
5633 cmd.u.cache.DeviceNo = i;
5634 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5635 gdth_do_req(srp, &cmd, cmnd, 30);
5636 if (srp->sr_command->SCp.Status == S_OK)
5637 rsc.hdr_list[i].cluster_type = srp->sr_command->SCp.Message;
5638 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5639 gdth_do_cmd(scp, &cmd, cmnd, 30);
5640 if (scp->SCp.Status == S_OK)
5641 rsc.hdr_list[i].cluster_type = scp->SCp.Message;
5643 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5644 if (scp.SCp.Status == S_OK)
5645 rsc.hdr_list[i].cluster_type = scp.SCp.Message;
5649 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5650 scsi_release_request(srp);
5651 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5652 scsi_release_command(scp);
5655 if (copy_to_user((char *)arg, &rsc, sizeof(gdth_ioctl_rescan)))
5660 static int ioc_rescan(unsigned long arg, char *cmnd)
5662 gdth_ioctl_rescan rsc;
5664 ushort i, status, hdr_cnt;
5666 int hanum, cyls, hds, secs;
5669 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5671 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5677 if (copy_from_user(&rsc, (char *)arg, sizeof(gdth_ioctl_rescan)) ||
5678 rsc.ionode >= gdth_ctr_count)
5681 ha = HADATA(gdth_ctr_tab[hanum]);
5682 memset(&cmd, 0, sizeof(gdth_cmd_str));
5684 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5685 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5688 srp->sr_cmd_len = 12;
5690 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5691 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5697 memset(&ha->sdev,0,sizeof(Scsi_Device));
5698 memset(&scp, 0,sizeof(Scsi_Cmnd));
5699 ha->sdev.host = scp.host = gdth_ctr_tab[hanum];
5700 ha->sdev.id = scp.target = ha->sdev.host->this_id;
5701 scp.device = &ha->sdev;
5704 if (rsc.flag == 0) {
5705 /* old method: re-init. cache service */
5706 cmd.Service = CACHESERVICE;
5707 if (ha->cache_feat & GDT_64BIT) {
5708 cmd.OpCode = GDT_X_INIT_HOST;
5709 cmd.u.cache64.DeviceNo = LINUX_OS;
5711 cmd.OpCode = GDT_INIT;
5712 cmd.u.cache.DeviceNo = LINUX_OS;
5714 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5715 gdth_do_req(srp, &cmd, cmnd, 30);
5716 status = (ushort)srp->sr_command->SCp.Status;
5717 info = (ulong32)srp->sr_command->SCp.Message;
5718 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5719 gdth_do_cmd(scp, &cmd, cmnd, 30);
5720 status = (ushort)scp->SCp.Status;
5721 info = (ulong32)scp->SCp.Message;
5723 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5724 status = (ushort)scp.SCp.Status;
5725 info = (ulong32)scp.SCp.Message;
5728 hdr_cnt = (status == S_OK ? (ushort)info : 0);
5733 for (; i < hdr_cnt && i < MAX_HDRIVES; ++i) {
5734 cmd.Service = CACHESERVICE;
5735 cmd.OpCode = GDT_INFO;
5736 if (ha->cache_feat & GDT_64BIT)
5737 cmd.u.cache64.DeviceNo = i;
5739 cmd.u.cache.DeviceNo = i;
5740 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5741 gdth_do_req(srp, &cmd, cmnd, 30);
5742 status = (ushort)srp->sr_command->SCp.Status;
5743 info = (ulong32)srp->sr_command->SCp.Message;
5744 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5745 gdth_do_cmd(scp, &cmd, cmnd, 30);
5746 status = (ushort)scp->SCp.Status;
5747 info = (ulong32)scp->SCp.Message;
5749 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5750 status = (ushort)scp.SCp.Status;
5751 info = (ulong32)scp.SCp.Message;
5753 GDTH_LOCK_HA(ha, flags);
5754 rsc.hdr_list[i].bus = ha->virt_bus;
5755 rsc.hdr_list[i].target = i;
5756 rsc.hdr_list[i].lun = 0;
5757 if (status != S_OK) {
5758 ha->hdr[i].present = FALSE;
5760 ha->hdr[i].present = TRUE;
5761 ha->hdr[i].size = info;
5762 /* evaluate mapping */
5763 ha->hdr[i].size &= ~SECS32;
5764 gdth_eval_mapping(ha->hdr[i].size,&cyls,&hds,&secs);
5765 ha->hdr[i].heads = hds;
5766 ha->hdr[i].secs = secs;
5768 ha->hdr[i].size = cyls * hds * secs;
5770 GDTH_UNLOCK_HA(ha, flags);
5774 /* extended info, if GDT_64BIT, for drives > 2 TB */
5775 /* but we need ha->info2, not yet stored in scp->SCp */
5777 /* devtype, cluster info, R/W attribs */
5778 cmd.Service = CACHESERVICE;
5779 cmd.OpCode = GDT_DEVTYPE;
5780 if (ha->cache_feat & GDT_64BIT)
5781 cmd.u.cache64.DeviceNo = i;
5783 cmd.u.cache.DeviceNo = i;
5784 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5785 gdth_do_req(srp, &cmd, cmnd, 30);
5786 status = (ushort)srp->sr_command->SCp.Status;
5787 info = (ulong32)srp->sr_command->SCp.Message;
5788 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5789 gdth_do_cmd(scp, &cmd, cmnd, 30);
5790 status = (ushort)scp->SCp.Status;
5791 info = (ulong32)scp->SCp.Message;
5793 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5794 status = (ushort)scp.SCp.Status;
5795 info = (ulong32)scp.SCp.Message;
5797 GDTH_LOCK_HA(ha, flags);
5798 ha->hdr[i].devtype = (status == S_OK ? (ushort)info : 0);
5799 GDTH_UNLOCK_HA(ha, flags);
5801 cmd.Service = CACHESERVICE;
5802 cmd.OpCode = GDT_CLUST_INFO;
5803 if (ha->cache_feat & GDT_64BIT)
5804 cmd.u.cache64.DeviceNo = i;
5806 cmd.u.cache.DeviceNo = i;
5807 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5808 gdth_do_req(srp, &cmd, cmnd, 30);
5809 status = (ushort)srp->sr_command->SCp.Status;
5810 info = (ulong32)srp->sr_command->SCp.Message;
5811 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5812 gdth_do_cmd(scp, &cmd, cmnd, 30);
5813 status = (ushort)scp->SCp.Status;
5814 info = (ulong32)scp->SCp.Message;
5816 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5817 status = (ushort)scp.SCp.Status;
5818 info = (ulong32)scp.SCp.Message;
5820 GDTH_LOCK_HA(ha, flags);
5821 ha->hdr[i].cluster_type =
5822 ((status == S_OK && !shared_access) ? (ushort)info : 0);
5823 GDTH_UNLOCK_HA(ha, flags);
5824 rsc.hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
5826 cmd.Service = CACHESERVICE;
5827 cmd.OpCode = GDT_RW_ATTRIBS;
5828 if (ha->cache_feat & GDT_64BIT)
5829 cmd.u.cache64.DeviceNo = i;
5831 cmd.u.cache.DeviceNo = i;
5832 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5833 gdth_do_req(srp, &cmd, cmnd, 30);
5834 status = (ushort)srp->sr_command->SCp.Status;
5835 info = (ulong32)srp->sr_command->SCp.Message;
5836 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5837 gdth_do_cmd(scp, &cmd, cmnd, 30);
5838 status = (ushort)scp->SCp.Status;
5839 info = (ulong32)scp->SCp.Message;
5841 gdth_do_cmd(&scp, &cmd, cmnd, 30);
5842 status = (ushort)scp.SCp.Status;
5843 info = (ulong32)scp.SCp.Message;
5845 GDTH_LOCK_HA(ha, flags);
5846 ha->hdr[i].rw_attribs = (status == S_OK ? (ushort)info : 0);
5847 GDTH_UNLOCK_HA(ha, flags);
5849 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5850 scsi_release_request(srp);
5851 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5852 scsi_release_command(scp);
5855 if (copy_to_user((char *)arg, &rsc, sizeof(gdth_ioctl_rescan)))
5860 static int gdth_ioctl(struct inode *inode, struct file *filep,
5861 unsigned int cmd, unsigned long arg)
5864 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5866 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5872 char cmnd[MAX_COMMAND_SIZE];
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 *)arg))
5887 case GDTIOCTL_DRVERS:
5889 int ver = (GDTH_VERSION<<8) | GDTH_SUBVERSION;
5890 if (put_user(ver, (int *)arg))
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((char *)arg, &osv, sizeof(gdth_ioctl_osvers)))
5907 case GDTIOCTL_CTRTYPE:
5909 gdth_ioctl_ctrtype ctrt;
5911 if (copy_from_user(&ctrt, (char *)arg, 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((char *)arg, &ctrt, sizeof(gdth_ioctl_ctrtype)))
5938 case GDTIOCTL_GENERAL:
5939 return ioc_general(arg, cmnd);
5941 case GDTIOCTL_EVENT:
5942 return ioc_event(arg);
5944 case GDTIOCTL_LOCKDRV:
5945 return ioc_lockdrv(arg);
5947 case GDTIOCTL_LOCKCHN:
5949 gdth_ioctl_lockchn lchn;
5952 if (copy_from_user(&lchn, (char *)arg, 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(arg, cmnd);
5983 case GDTIOCTL_HDRLIST:
5984 return ioc_hdrlist(arg, cmnd);
5986 case GDTIOCTL_RESET_BUS:
5988 gdth_ioctl_reset res;
5991 if (copy_from_user(&res, (char *)arg, 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((char *)arg, &res, sizeof(gdth_ioctl_reset)))
6033 case GDTIOCTL_RESET_DRV:
6034 return ioc_resetdrv(arg, 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);