1 /************************************************************************
3 * ICP vortex GmbH: GDT ISA/EISA/PCI Disk Array Controllers *
4 * Intel Corporation: Storage RAID Controllers *
7 * Copyright (C) 1995-04 ICP vortex GmbH, Achim Leubner *
8 * Copyright (C) 2002-04 Intel Corporation *
9 * Copyright (C) 2003-04 Adaptec Inc. *
10 * <achim_leubner@adaptec.com> *
13 * Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com> *
14 * Johannes Dinner <johannes_dinner@adaptec.com> *
16 * This program is free software; you can redistribute it and/or modify *
17 * it under the terms of the GNU General Public License as published *
18 * by the Free Software Foundation; either version 2 of the License, *
19 * or (at your option) any later version. *
21 * This program is distributed in the hope that it will be useful, *
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
24 * GNU General Public License for more details. *
26 * You should have received a copy of the GNU General Public License *
27 * along with this kernel; if not, write to the Free Software *
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
30 * Linux kernel 2.2.x, 2.4.x, 2.6.x supported *
33 * Revision 1.73 2004/03/31 13:33:03 achim
34 * Special command 0xfd implemented to detect 64-bit DMA support
36 * Revision 1.72 2004/03/17 08:56:04 achim
37 * 64-bit DMA only enabled if FW >= x.43
39 * Revision 1.71 2004/03/05 15:51:29 achim
40 * Screen service: separate message buffer, bugfixes
42 * Revision 1.70 2004/02/27 12:19:07 achim
43 * Bugfix: Reset bit in config (0xfe) call removed
45 * Revision 1.69 2004/02/20 09:50:24 achim
46 * Compatibility changes for kernels < 2.4.20
47 * Bugfix screen service command size
48 * pci_set_dma_mask() error handling added
50 * Revision 1.68 2004/02/19 15:46:54 achim
52 * Drive size bugfix for drives > 1TB
54 * Revision 1.67 2004/01/14 13:11:57 achim
55 * Tool access over /proc no longer supported
58 * Revision 1.66 2003/12/19 15:04:06 achim
59 * Bugfixes support for drives > 2TB
61 * Revision 1.65 2003/12/15 11:21:56 achim
62 * 64-bit DMA support added
63 * Support for drives > 2 TB implemented
64 * Kernels 2.2.x, 2.4.x, 2.6.x supported
66 * Revision 1.64 2003/09/17 08:30:26 achim
67 * EISA/ISA controller scan disabled
68 * Command line switch probe_eisa_isa added
70 * Revision 1.63 2003/07/12 14:01:00 Daniele Bellucci <bellucda@tiscali.it>
71 * Minor cleanups in gdth_ioctl.
73 * Revision 1.62 2003/02/27 15:01:59 achim
74 * Dynamic DMA mapping implemented
75 * New (character device) IOCTL interface added
76 * Other controller related changes made
78 * Revision 1.61 2002/11/08 13:09:52 boji
79 * Added support for XSCALE based RAID Controllers
80 * Fixed SCREENSERVICE initialization in SMP cases
81 * Added checks for gdth_polling before GDTH_HA_LOCK
83 * Revision 1.60 2002/02/05 09:35:22 achim
84 * MODULE_LICENSE only if kernel >= 2.4.11
86 * Revision 1.59 2002/01/30 09:46:33 achim
89 * Revision 1.58 2002/01/29 15:30:02 achim
90 * Set default value of shared_access to Y
91 * New status S_CACHE_RESERV for clustering added
93 * Revision 1.57 2001/08/21 11:16:35 achim
96 * Revision 1.56 2001/08/09 11:19:39 achim
97 * Scsi_Host_Template changes
99 * Revision 1.55 2001/08/09 10:11:28 achim
100 * Command HOST_UNFREEZE_IO before cache service init.
102 * Revision 1.54 2001/07/20 13:48:12 achim
103 * Expand: gdth_analyse_hdrive() removed
105 * Revision 1.53 2001/07/17 09:52:49 achim
106 * Small OEM related change
108 * Revision 1.52 2001/06/19 15:06:20 achim
109 * New host command GDT_UNFREEZE_IO added
111 * Revision 1.51 2001/05/22 06:42:37 achim
112 * PCI: Subdevice ID added
114 * Revision 1.50 2001/05/17 13:42:16 achim
115 * Support for Intel Storage RAID Controllers added
117 * Revision 1.50 2001/05/17 12:12:34 achim
118 * Support for Intel Storage RAID Controllers added
120 * Revision 1.49 2001/03/15 15:07:17 achim
121 * New __setup interface for boot command line options added
123 * Revision 1.48 2001/02/06 12:36:28 achim
124 * Bugfix Cluster protocol
126 * Revision 1.47 2001/01/10 14:42:06 achim
127 * New switch shared_access added
129 * Revision 1.46 2001/01/09 08:11:35 achim
130 * gdth_command() removed
131 * meaning of Scsi_Pointer members changed
133 * Revision 1.45 2000/11/16 12:02:24 achim
134 * Changes for kernel 2.4
136 * Revision 1.44 2000/10/11 08:44:10 achim
137 * Clustering changes: New flag media_changed added
139 * Revision 1.43 2000/09/20 12:59:01 achim
140 * DPMEM remap functions for all PCI controller types implemented
141 * Small changes for ia64 platform
143 * Revision 1.42 2000/07/20 09:04:50 achim
144 * Small changes for kernel 2.4
146 * Revision 1.41 2000/07/04 14:11:11 achim
147 * gdth_analyse_hdrive() added to rescan drives after online expansion
149 * Revision 1.40 2000/06/27 11:24:16 achim
150 * Changes Clustering, Screenservice
152 * Revision 1.39 2000/06/15 13:09:04 achim
153 * Changes for gdth_do_cmd()
155 * Revision 1.38 2000/06/15 12:08:43 achim
156 * Bugfix gdth_sync_event(), service SCREENSERVICE
157 * Data direction for command 0xc2 changed to DOU
159 * Revision 1.37 2000/05/25 13:50:10 achim
160 * New driver parameter virt_ctr added
162 * Revision 1.36 2000/05/04 08:50:46 achim
163 * Event buffer now in gdth_ha_str
165 * Revision 1.35 2000/03/03 10:44:08 achim
166 * New event_string only valid for the RP controller family
168 * Revision 1.34 2000/03/02 14:55:29 achim
169 * New mechanism for async. event handling implemented
171 * Revision 1.33 2000/02/21 15:37:37 achim
172 * Bugfix Alpha platform + DPMEM above 4GB
174 * Revision 1.32 2000/02/14 16:17:37 achim
175 * Bugfix sense_buffer[] + raw devices
177 * Revision 1.31 2000/02/10 10:29:00 achim
178 * Delete sense_buffer[0], if command OK
180 * Revision 1.30 1999/11/02 13:42:39 achim
181 * ARRAY_DRV_LIST2 implemented
182 * Now 255 log. and 100 host drives supported
184 * Revision 1.29 1999/10/05 13:28:47 achim
185 * GDT_CLUST_RESET added
187 * Revision 1.28 1999/08/12 13:44:54 achim
189 * Cluster drives -> removeable drives
191 * Revision 1.27 1999/06/22 07:22:38 achim
194 * Revision 1.26 1999/06/10 16:09:12 achim
195 * Cluster Host Drive support: Bugfixes
197 * Revision 1.25 1999/06/01 16:03:56 achim
198 * gdth_init_pci(): Manipulate config. space to start RP controller
200 * Revision 1.24 1999/05/26 11:53:06 achim
201 * Cluster Host Drive support added
203 * Revision 1.23 1999/03/26 09:12:31 achim
204 * Default value for hdr_channel set to 0
206 * Revision 1.22 1999/03/22 16:27:16 achim
207 * Bugfix: gdth_store_event() must not be locked with GDTH_LOCK_HA()
209 * Revision 1.21 1999/03/16 13:40:34 achim
210 * Problems with reserved drives solved
211 * gdth_eh_bus_reset() implemented
213 * Revision 1.20 1999/03/10 09:08:13 achim
214 * Bugfix: Corrections in gdth_direction_tab[] made
215 * Bugfix: Increase command timeout (gdth_update_timeout()) NOT in gdth_putq()
217 * Revision 1.19 1999/03/05 14:38:16 achim
218 * Bugfix: Heads/Sectors mapping for reserved devices possibly wrong
219 * -> gdth_eval_mapping() implemented, changes in gdth_bios_param()
220 * INIT_RETRIES set to 100s to avoid DEINIT-Timeout for controllers
221 * with BIOS disabled and memory test set to Intensive
222 * Enhanced /proc support
224 * Revision 1.18 1999/02/24 09:54:33 achim
225 * Command line parameter hdr_channel implemented
226 * Bugfix for EISA controllers + Linux 2.2.x
228 * Revision 1.17 1998/12/17 15:58:11 achim
229 * Command line parameters implemented
230 * Changes for Alpha platforms
231 * PCI controller scan changed
232 * SMP support improved (spin_lock_irqsave(),...)
233 * New async. events, new scan/reserve commands included
235 * Revision 1.16 1998/09/28 16:08:46 achim
236 * GDT_PCIMPR: DPMEM remapping, if required
239 * Revision 1.15 1998/06/03 14:54:06 achim
240 * gdth_delay(), gdth_flush() implemented
241 * Bugfix: gdth_release() changed
243 * Revision 1.14 1998/05/22 10:01:17 achim
244 * mj: pcibios_strerror() removed
245 * Improved SMP support (if version >= 2.1.95)
246 * gdth_halt(): halt_called flag added (if version < 2.1)
248 * Revision 1.13 1998/04/16 09:14:57 achim
249 * Reserve drives (for raw service) implemented
250 * New error handling code enabled
251 * Get controller name from board_info() IOCTL
252 * Final round of PCI device driver patches by Martin Mares
254 * Revision 1.12 1998/03/03 09:32:37 achim
255 * Fibre channel controller support added
257 * Revision 1.11 1998/01/27 16:19:14 achim
259 * add_timer()/del_timer() instead of GDTH_TIMER
260 * scsi_add_timer()/scsi_del_timer() instead of SCSI_TIMER
261 * New error handling included
263 * Revision 1.10 1997/10/31 12:29:57 achim
264 * Read heads/sectors from host drive
266 * Revision 1.9 1997/09/04 10:07:25 achim
267 * IO-mapping with virt_to_bus(), gdth_readb(), gdth_writeb(), ...
268 * register_reboot_notifier() to get a notify on shutown used
270 * Revision 1.8 1997/04/02 12:14:30 achim
271 * Version 1.00 (see gdth.h), tested with kernel 2.0.29
273 * Revision 1.7 1997/03/12 13:33:37 achim
274 * gdth_reset() changed, new async. events
276 * Revision 1.6 1997/03/04 14:01:11 achim
277 * Shutdown routine gdth_halt() implemented
279 * Revision 1.5 1997/02/21 09:08:36 achim
280 * New controller included (RP, RP1, RP2 series)
281 * IOCTL interface implemented
283 * Revision 1.4 1996/07/05 12:48:55 achim
284 * Function gdth_bios_param() implemented
285 * New constant GDTH_MAXC_P_L inserted
286 * GDT_WRITE_THR, GDT_EXT_INFO implemented
287 * Function gdth_reset() changed
289 * Revision 1.3 1996/05/10 09:04:41 achim
290 * Small changes for Linux 1.2.13
292 * Revision 1.2 1996/05/09 12:45:27 achim
293 * Loadable module support implemented
294 * /proc support corrections made
296 * Revision 1.1 1996/04/11 07:35:57 achim
299 ************************************************************************/
301 /* All GDT Disk Array Controllers are fully supported by this driver.
302 * This includes the PCI/EISA/ISA SCSI Disk Array Controllers and the
303 * PCI Fibre Channel Disk Array Controllers. See gdth.h for a complete
304 * list of all controller types.
306 * If you have one or more GDT3000/3020 EISA controllers with
307 * controller BIOS disabled, you have to set the IRQ values with the
308 * command line option "gdth=irq1,irq2,...", where the irq1,irq2,... are
309 * the IRQ values for the EISA controllers.
311 * After the optional list of IRQ values, other possible
312 * command line options are:
313 * disable:Y disable driver
314 * disable:N enable driver
315 * reserve_mode:0 reserve no drives for the raw service
316 * reserve_mode:1 reserve all not init., removable drives
317 * reserve_mode:2 reserve all not init. drives
318 * reserve_list:h,b,t,l,h,b,t,l,... reserve particular drive(s) with
319 * h- controller no., b- channel no.,
320 * t- target ID, l- LUN
321 * reverse_scan:Y reverse scan order for PCI controllers
322 * reverse_scan:N scan PCI controllers like BIOS
323 * max_ids:x x - target ID count per channel (1..MAXID)
324 * rescan:Y rescan all channels/IDs
325 * rescan:N use all devices found until now
326 * virt_ctr:Y map every channel to a virtual controller
327 * virt_ctr:N use multi channel support
328 * hdr_channel:x x - number of virtual bus for host drives
329 * shared_access:Y disable driver reserve/release protocol to
330 * access a shared resource from several nodes,
331 * appropiate controller firmware required
332 * shared_access:N enable driver reserve/release protocol
333 * probe_eisa_isa:Y scan for EISA/ISA controllers
334 * probe_eisa_isa:N do not scan for EISA/ISA controllers
335 * force_dma32:Y use only 32 bit DMA mode
336 * force_dma32:N use 64 bit DMA mode, if supported
338 * The default values are: "gdth=disable:N,reserve_mode:1,reverse_scan:N,
339 * max_ids:127,rescan:N,virt_ctr:N,hdr_channel:0,
340 * shared_access:Y,probe_eisa_isa:N,force_dma32:N".
341 * Here is another example: "gdth=reserve_list:0,1,2,0,0,1,3,0,rescan:Y".
343 * When loading the gdth driver as a module, the same options are available.
344 * You can set the IRQs with "IRQ=...". However, the syntax to specify the
345 * options changes slightly. You must replace all ',' between options
346 * with ' ' and all ':' with '=' and you must use
347 * '1' in place of 'Y' and '0' in place of 'N'.
349 * Default: "modprobe gdth disable=0 reserve_mode=1 reverse_scan=0
350 * max_ids=127 rescan=0 virt_ctr=0 hdr_channel=0 shared_access=0
351 * probe_eisa_isa=0 force_dma32=0"
352 * The other example: "modprobe gdth reserve_list=0,1,2,0,0,1,3,0 rescan=1".
355 /* The meaning of the Scsi_Pointer members in this driver is as follows:
357 * this_residual: Command priority
358 * buffer: phys. DMA sense buffer
359 * dma_handle: phys. DMA buffer (kernel >= 2.4.0)
360 * buffers_residual: Timeout value
361 * Status: Command status (gdth_do_cmd()), DMA mem. mappings
362 * Message: Additional info (gdth_do_cmd()), DMA direction
363 * have_data_in: Flag for gdth_wait_completion()
364 * sent_command: Opcode special command
365 * phase: Service/parameter/return code special command
369 /* interrupt coalescing */
370 /* #define INT_COAL */
373 #define GDTH_STATISTICS
375 #include <linux/module.h>
377 #include <linux/version.h>
378 #include <linux/kernel.h>
379 #include <linux/types.h>
380 #include <linux/pci.h>
381 #include <linux/string.h>
382 #include <linux/ctype.h>
383 #include <linux/ioport.h>
384 #include <linux/delay.h>
385 #include <linux/sched.h>
386 #include <linux/interrupt.h>
387 #include <linux/in.h>
388 #include <linux/proc_fs.h>
389 #include <linux/time.h>
390 #include <linux/timer.h>
392 #include <linux/mc146818rtc.h>
394 #include <linux/reboot.h>
397 #include <asm/system.h>
399 #include <asm/uaccess.h>
400 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
401 #include <linux/spinlock.h>
403 #include <asm/spinlock.h>
405 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
406 #include <linux/blkdev.h>
408 #include <linux/blk.h>
413 #include <scsi/scsi_host.h>
416 static void gdth_delay(int milliseconds
);
417 static void gdth_eval_mapping(ulong32 size
, ulong32
*cyls
, int *heads
, int *secs
);
418 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
419 static irqreturn_t
gdth_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
421 static void gdth_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
423 static int gdth_sync_event(int hanum
,int service
,unchar index
,Scsi_Cmnd
*scp
);
424 static int gdth_async_event(int hanum
);
425 static void gdth_log_event(gdth_evt_data
*dvr
, char *buffer
);
427 static void gdth_putq(int hanum
,Scsi_Cmnd
*scp
,unchar priority
);
428 static void gdth_next(int hanum
);
429 static int gdth_fill_raw_cmd(int hanum
,Scsi_Cmnd
*scp
,unchar b
);
430 static int gdth_special_cmd(int hanum
,Scsi_Cmnd
*scp
);
431 static gdth_evt_str
*gdth_store_event(gdth_ha_str
*ha
, ushort source
,
432 ushort idx
, gdth_evt_data
*evt
);
433 static int gdth_read_event(gdth_ha_str
*ha
, int handle
, gdth_evt_str
*estr
);
434 static void gdth_readapp_event(gdth_ha_str
*ha
, unchar application
,
436 static void gdth_clear_events(void);
438 static void gdth_copy_internal_data(int hanum
,Scsi_Cmnd
*scp
,
439 char *buffer
,ushort count
);
440 static int gdth_internal_cache_cmd(int hanum
,Scsi_Cmnd
*scp
);
441 static int gdth_fill_cache_cmd(int hanum
,Scsi_Cmnd
*scp
,ushort hdrive
);
443 static int gdth_search_eisa(ushort eisa_adr
);
444 static int gdth_search_isa(ulong32 bios_adr
);
445 static int gdth_search_pci(gdth_pci_str
*pcistr
);
446 static void gdth_search_dev(gdth_pci_str
*pcistr
, ushort
*cnt
,
447 ushort vendor
, ushort dev
);
448 static void gdth_sort_pci(gdth_pci_str
*pcistr
, int cnt
);
449 static int gdth_init_eisa(ushort eisa_adr
,gdth_ha_str
*ha
);
450 static int gdth_init_isa(ulong32 bios_adr
,gdth_ha_str
*ha
);
451 static int gdth_init_pci(gdth_pci_str
*pcistr
,gdth_ha_str
*ha
);
453 static void gdth_enable_int(int hanum
);
454 static int gdth_get_status(unchar
*pIStatus
,int irq
);
455 static int gdth_test_busy(int hanum
);
456 static int gdth_get_cmd_index(int hanum
);
457 static void gdth_release_event(int hanum
);
458 static int gdth_wait(int hanum
,int index
,ulong32 time
);
459 static int gdth_internal_cmd(int hanum
,unchar service
,ushort opcode
,ulong32 p1
,
460 ulong64 p2
,ulong64 p3
);
461 static int gdth_search_drives(int hanum
);
462 static int gdth_analyse_hdrive(int hanum
, ushort hdrive
);
464 static const char *gdth_ctr_name(int hanum
);
466 static int gdth_open(struct inode
*inode
, struct file
*filep
);
467 static int gdth_close(struct inode
*inode
, struct file
*filep
);
468 static int gdth_ioctl(struct inode
*inode
, struct file
*filep
,
469 unsigned int cmd
, unsigned long arg
);
471 static void gdth_flush(int hanum
);
472 static int gdth_halt(struct notifier_block
*nb
, ulong event
, void *buf
);
475 static unchar DebugState
= DEBUG_GDTH
;
478 #define MAX_SERBUF 160
479 static void ser_init(void);
480 static void ser_puts(char *str
);
481 static void ser_putc(char c
);
482 static int ser_printk(const char *fmt
, ...);
483 static char strbuf
[MAX_SERBUF
+1];
485 #define COM_BASE 0x2f8
487 #define COM_BASE 0x3f8
489 static void ser_init()
491 unsigned port
=COM_BASE
;
495 /* 19200 Baud, if 9600: outb(12,port) */
505 static void ser_puts(char *str
)
510 for (ptr
=str
;*ptr
;++ptr
)
514 static void ser_putc(char c
)
516 unsigned port
=COM_BASE
;
518 while ((inb(port
+5) & 0x20)==0);
522 while ((inb(port
+5) & 0x20)==0);
527 static int ser_printk(const char *fmt
, ...)
533 i
= vsprintf(strbuf
,fmt
,args
);
539 #define TRACE(a) {if (DebugState==1) {ser_printk a;}}
540 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}}
541 #define TRACE3(a) {if (DebugState!=0) {ser_printk a;}}
543 #else /* !__SERIAL__ */
544 #define TRACE(a) {if (DebugState==1) {printk a;}}
545 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {printk a;}}
546 #define TRACE3(a) {if (DebugState!=0) {printk a;}}
555 #ifdef GDTH_STATISTICS
556 static ulong32 max_rq
=0, max_index
=0, max_sg
=0;
558 static ulong32 max_int_coal
=0;
560 static ulong32 act_ints
=0, act_ios
=0, act_stats
=0, act_rq
=0;
561 static struct timer_list gdth_timer
;
564 #define PTR2USHORT(a) (ushort)(ulong)(a)
565 #define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b)
566 #define INDEX_OK(i,t) ((i)<sizeof(t)/sizeof((t)[0]))
568 #define NUMDATA(a) ( (gdth_num_str *)((a)->hostdata))
569 #define HADATA(a) (&((gdth_ext_str *)((a)->hostdata))->haext)
570 #define CMDDATA(a) (&((gdth_ext_str *)((a)->hostdata))->cmdext)
572 #define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b))
574 #define gdth_readb(addr) readb(addr)
575 #define gdth_readw(addr) readw(addr)
576 #define gdth_readl(addr) readl(addr)
577 #define gdth_writeb(b,addr) writeb((b),(addr))
578 #define gdth_writew(b,addr) writew((b),(addr))
579 #define gdth_writel(b,addr) writel((b),(addr))
581 static unchar gdth_drq_tab
[4] = {5,6,7,7}; /* DRQ table */
582 static unchar gdth_irq_tab
[6] = {0,10,11,12,14,0}; /* IRQ table */
583 static unchar gdth_polling
; /* polling if TRUE */
584 static unchar gdth_from_wait
= FALSE
; /* gdth_wait() */
585 static int wait_index
,wait_hanum
; /* gdth_wait() */
586 static int gdth_ctr_count
= 0; /* controller count */
587 static int gdth_ctr_vcount
= 0; /* virt. ctr. count */
588 static int gdth_ctr_released
= 0; /* gdth_release() */
589 static struct Scsi_Host
*gdth_ctr_tab
[MAXHA
]; /* controller table */
590 static struct Scsi_Host
*gdth_ctr_vtab
[MAXHA
*MAXBUS
]; /* virt. ctr. table */
591 static unchar gdth_write_through
= FALSE
; /* write through */
592 static gdth_evt_str ebuffer
[MAX_EVENTS
]; /* event buffer */
597 #define DIN 1 /* IN data direction */
598 #define DOU 2 /* OUT data direction */
599 #define DNO DIN /* no data transfer */
600 #define DUN DIN /* unknown data direction */
601 static unchar gdth_direction_tab
[0x100] = {
602 DNO
,DNO
,DIN
,DIN
,DOU
,DIN
,DIN
,DOU
,DIN
,DUN
,DOU
,DOU
,DUN
,DUN
,DUN
,DIN
,
603 DNO
,DIN
,DIN
,DOU
,DIN
,DOU
,DNO
,DNO
,DOU
,DNO
,DIN
,DNO
,DIN
,DOU
,DNO
,DUN
,
604 DIN
,DUN
,DIN
,DUN
,DOU
,DIN
,DUN
,DUN
,DIN
,DIN
,DOU
,DNO
,DUN
,DIN
,DOU
,DOU
,
605 DOU
,DOU
,DOU
,DNO
,DIN
,DNO
,DNO
,DIN
,DOU
,DOU
,DOU
,DOU
,DIN
,DOU
,DIN
,DOU
,
606 DOU
,DOU
,DIN
,DIN
,DIN
,DNO
,DUN
,DNO
,DNO
,DNO
,DUN
,DNO
,DOU
,DIN
,DUN
,DUN
,
607 DUN
,DUN
,DUN
,DUN
,DUN
,DOU
,DUN
,DUN
,DUN
,DUN
,DIN
,DUN
,DUN
,DUN
,DUN
,DUN
,
608 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
609 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
610 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DIN
,DUN
,DOU
,DUN
,DUN
,DUN
,DUN
,DUN
,
611 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DIN
,DUN
,
612 DUN
,DUN
,DUN
,DUN
,DUN
,DNO
,DNO
,DUN
,DIN
,DNO
,DOU
,DUN
,DNO
,DUN
,DOU
,DOU
,
613 DOU
,DOU
,DOU
,DNO
,DUN
,DIN
,DOU
,DIN
,DIN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
614 DUN
,DUN
,DOU
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
615 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,
616 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DOU
,DUN
,DUN
,DUN
,DUN
,DUN
,
617 DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
,DUN
620 /* __initfunc, __initdata macros */
621 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
622 #define GDTH_INITFUNC(type, func) type __init func
623 #include <linux/init.h>
625 #define GDTH_INITFUNC(type, func) __initfunc(type func)
626 #include <linux/init.h>
629 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
630 #define GDTH_INIT_LOCK_HA(ha) spin_lock_init(&(ha)->smp_lock)
631 #define GDTH_LOCK_HA(ha,flags) spin_lock_irqsave(&(ha)->smp_lock,flags)
632 #define GDTH_UNLOCK_HA(ha,flags) spin_unlock_irqrestore(&(ha)->smp_lock,flags)
634 #define GDTH_LOCK_SCSI_DONE(dev, flags) spin_lock_irqsave(dev->host_lock,flags)
635 #define GDTH_UNLOCK_SCSI_DONE(dev, flags) spin_unlock_irqrestore(dev->host_lock,flags)
638 #define GDTH_INIT_LOCK_HA(ha) spin_lock_init(&(ha)->smp_lock)
639 #define GDTH_LOCK_HA(ha,flags) spin_lock_irqsave(&(ha)->smp_lock,flags)
640 #define GDTH_UNLOCK_HA(ha,flags) spin_unlock_irqrestore(&(ha)->smp_lock,flags)
642 #define GDTH_LOCK_SCSI_DONE(flags) spin_lock_irqsave(&io_request_lock,flags)
643 #define GDTH_UNLOCK_SCSI_DONE(flags) spin_unlock_irqrestore(&io_request_lock,flags)
646 /* LILO and modprobe/insmod parameters */
647 /* IRQ list for GDT3000/3020 EISA controllers */
648 static int irq
[MAXHA
] __initdata
=
649 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
650 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
651 /* disable driver flag */
652 static int disable __initdata
= 0;
654 static int reserve_mode
= 1;
656 static int reserve_list
[MAX_RES_ARGS
] =
657 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
658 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
659 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
660 /* scan order for PCI controllers */
661 static int reverse_scan
= 0;
662 /* virtual channel for the host drives */
663 static int hdr_channel
= 0;
664 /* max. IDs per channel */
665 static int max_ids
= MAXID
;
667 static int rescan
= 0;
668 /* map channels to virtual controllers */
669 static int virt_ctr
= 0;
671 static int shared_access
= 1;
672 /* enable support for EISA and ISA controllers */
673 static int probe_eisa_isa
= 0;
674 /* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */
675 static int force_dma32
= 0;
678 /* parameters for modprobe/insmod */
679 MODULE_PARM(irq
, "i");
680 MODULE_PARM(disable
, "i");
681 MODULE_PARM(reserve_mode
, "i");
682 MODULE_PARM(reserve_list
, "4-" __MODULE_STRING(MAX_RES_ARGS
) "i");
683 MODULE_PARM(reverse_scan
, "i");
684 MODULE_PARM(hdr_channel
, "i");
685 MODULE_PARM(max_ids
, "i");
686 MODULE_PARM(rescan
, "i");
687 MODULE_PARM(virt_ctr
, "i");
688 MODULE_PARM(shared_access
, "i");
689 MODULE_PARM(probe_eisa_isa
, "i");
690 MODULE_PARM(force_dma32
, "i");
691 MODULE_AUTHOR("Achim Leubner");
692 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,11)
693 MODULE_LICENSE("GPL");
697 /* ioctl interface */
698 static struct file_operations gdth_fops
= {
699 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
702 .release
= gdth_close
,
711 #include <linux/stat.h>
712 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
713 struct proc_dir_entry proc_scsi_gdth
= {
714 PROC_SCSI_GDTH
, 4, "gdth",
715 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
719 #include "gdth_proc.h"
720 #include "gdth_proc.c"
722 /* notifier block to get a notify on system shutdown/halt/reboot */
723 static struct notifier_block gdth_notifier
= {
728 static void gdth_delay(int milliseconds
)
730 if (milliseconds
== 0) {
733 mdelay(milliseconds
);
737 static void gdth_eval_mapping(ulong32 size
, ulong32
*cyls
, int *heads
, int *secs
)
739 *cyls
= size
/HEADS
/SECS
;
740 if (*cyls
<= MAXCYLS
) {
743 } else { /* too high for 64*32 */
744 *cyls
= size
/MEDHEADS
/MEDSECS
;
745 if (*cyls
<= MAXCYLS
) {
748 } else { /* too high for 127*63 */
749 *cyls
= size
/BIGHEADS
/BIGSECS
;
756 /* controller search and initialization functions */
758 GDTH_INITFUNC(static int, gdth_search_eisa(ushort eisa_adr
))
762 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr
));
763 id
= inl(eisa_adr
+ID0REG
);
764 if (id
== GDT3A_ID
|| id
== GDT3B_ID
) { /* GDT3000A or GDT3000B */
765 if ((inb(eisa_adr
+EISAREG
) & 8) == 0)
766 return 0; /* not EISA configured */
769 if (id
== GDT3_ID
) /* GDT3000 */
776 GDTH_INITFUNC(static int, gdth_search_isa(ulong32 bios_adr
))
781 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr
));
782 if ((addr
= ioremap(bios_adr
+BIOS_ID_OFFS
, sizeof(ulong32
))) != NULL
) {
783 id
= gdth_readl(addr
);
785 if (id
== GDT2_ID
) /* GDT2000 */
792 GDTH_INITFUNC(static int, gdth_search_pci(gdth_pci_str
*pcistr
))
796 TRACE(("gdth_search_pci()\n"));
799 for (device
= 0; device
<= PCI_DEVICE_ID_VORTEX_GDT6555
; ++device
)
800 gdth_search_dev(pcistr
, &cnt
, PCI_VENDOR_ID_VORTEX
, device
);
801 for (device
= PCI_DEVICE_ID_VORTEX_GDT6x17RP
;
802 device
<= PCI_DEVICE_ID_VORTEX_GDTMAXRP
; ++device
)
803 gdth_search_dev(pcistr
, &cnt
, PCI_VENDOR_ID_VORTEX
, device
);
804 gdth_search_dev(pcistr
, &cnt
, PCI_VENDOR_ID_VORTEX
,
805 PCI_DEVICE_ID_VORTEX_GDTNEWRX
);
806 gdth_search_dev(pcistr
, &cnt
, PCI_VENDOR_ID_VORTEX
,
807 PCI_DEVICE_ID_VORTEX_GDTNEWRX2
);
808 gdth_search_dev(pcistr
, &cnt
, PCI_VENDOR_ID_INTEL
,
809 PCI_DEVICE_ID_INTEL_SRC
);
810 gdth_search_dev(pcistr
, &cnt
, PCI_VENDOR_ID_INTEL
,
811 PCI_DEVICE_ID_INTEL_SRC_XSCALE
);
815 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
816 /* Vortex only makes RAID controllers.
817 * We do not really want to specify all 550 ids here, so wildcard match.
819 static struct pci_device_id gdthtable
[] __devinitdata
= {
820 {PCI_VENDOR_ID_VORTEX
,PCI_ANY_ID
,PCI_ANY_ID
, PCI_ANY_ID
},
821 {PCI_VENDOR_ID_INTEL
,PCI_DEVICE_ID_INTEL_SRC
,PCI_ANY_ID
,PCI_ANY_ID
},
822 {PCI_VENDOR_ID_INTEL
,PCI_DEVICE_ID_INTEL_SRC_XSCALE
,PCI_ANY_ID
,PCI_ANY_ID
},
825 MODULE_DEVICE_TABLE(pci
,gdthtable
);
828 GDTH_INITFUNC(static void, gdth_search_dev(gdth_pci_str
*pcistr
, ushort
*cnt
,
829 ushort vendor
, ushort device
))
831 ulong base0
, base1
, base2
;
832 struct pci_dev
*pdev
;
834 TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
835 *cnt
, vendor
, device
));
837 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
839 while ((pdev
= pci_find_device(vendor
, device
, pdev
))
841 if (pci_enable_device(pdev
))
845 /* GDT PCI controller found, resources are already in pdev */
846 pcistr
[*cnt
].pdev
= pdev
;
847 pcistr
[*cnt
].vendor_id
= vendor
;
848 pcistr
[*cnt
].device_id
= device
;
849 pcistr
[*cnt
].subdevice_id
= pdev
->subsystem_device
;
850 pcistr
[*cnt
].bus
= pdev
->bus
->number
;
851 pcistr
[*cnt
].device_fn
= pdev
->devfn
;
852 pcistr
[*cnt
].irq
= pdev
->irq
;
853 base0
= pci_resource_flags(pdev
, 0);
854 base1
= pci_resource_flags(pdev
, 1);
855 base2
= pci_resource_flags(pdev
, 2);
856 if (device
<= PCI_DEVICE_ID_VORTEX_GDT6000B
|| /* GDT6000/B */
857 device
>= PCI_DEVICE_ID_VORTEX_GDT6x17RP
) { /* MPR */
858 if (!(base0
& IORESOURCE_MEM
))
860 pcistr
[*cnt
].dpmem
= pci_resource_start(pdev
, 0);
861 } else { /* GDT6110, GDT6120, .. */
862 if (!(base0
& IORESOURCE_MEM
) ||
863 !(base2
& IORESOURCE_MEM
) ||
864 !(base1
& IORESOURCE_IO
))
866 pcistr
[*cnt
].dpmem
= pci_resource_start(pdev
, 2);
867 pcistr
[*cnt
].io_mm
= pci_resource_start(pdev
, 0);
868 pcistr
[*cnt
].io
= pci_resource_start(pdev
, 1);
870 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
871 pcistr
[*cnt
].bus
, PCI_SLOT(pcistr
[*cnt
].device_fn
),
872 pcistr
[*cnt
].irq
, pcistr
[*cnt
].dpmem
));
877 while ((pdev
= pci_find_device(vendor
, device
, pdev
))
881 /* GDT PCI controller found, resources are already in pdev */
882 pcistr
[*cnt
].pdev
= pdev
;
883 pcistr
[*cnt
].vendor_id
= vendor
;
884 pcistr
[*cnt
].device_id
= device
;
885 pcistr
[*cnt
].bus
= pdev
->bus
->number
;
886 pcistr
[*cnt
].device_fn
= pdev
->devfn
;
887 pcibios_read_config_word(pcistr
[*cnt
].bus
, pcistr
[*cnt
].device_fn
,
888 PCI_SUBSYSTEM_ID
, &pcistr
[*cnt
].subdevice_id
);
889 pcistr
[*cnt
].irq
= pdev
->irq
;
890 base0
= pdev
->base_address
[0];
891 base1
= pdev
->base_address
[1];
892 base2
= pdev
->base_address
[2];
893 if (device
<= PCI_DEVICE_ID_VORTEX_GDT6000B
|| /* GDT6000/B */
894 device
>= PCI_DEVICE_ID_VORTEX_GDT6x17RP
) { /* MPR */
895 if ((base0
& PCI_BASE_ADDRESS_SPACE
) !=
896 PCI_BASE_ADDRESS_SPACE_MEMORY
)
898 pcistr
[*cnt
].dpmem
= base0
& PCI_BASE_ADDRESS_MEM_MASK
;
899 } else { /* GDT6110, GDT6120, .. */
900 if ((base0
& PCI_BASE_ADDRESS_SPACE
) !=
901 PCI_BASE_ADDRESS_SPACE_MEMORY
||
902 (base2
& PCI_BASE_ADDRESS_SPACE
) !=
903 PCI_BASE_ADDRESS_SPACE_MEMORY
||
904 (base1
& PCI_BASE_ADDRESS_SPACE
) !=
905 PCI_BASE_ADDRESS_SPACE_IO
)
907 pcistr
[*cnt
].dpmem
= base2
& PCI_BASE_ADDRESS_MEM_MASK
;
908 pcistr
[*cnt
].io_mm
= base0
& PCI_BASE_ADDRESS_MEM_MASK
;
909 pcistr
[*cnt
].io
= base1
& PCI_BASE_ADDRESS_IO_MASK
;
911 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
912 pcistr
[*cnt
].bus
, PCI_SLOT(pcistr
[*cnt
].device_fn
),
913 pcistr
[*cnt
].irq
, pcistr
[*cnt
].dpmem
));
920 GDTH_INITFUNC(static void, gdth_sort_pci(gdth_pci_str
*pcistr
, int cnt
))
925 TRACE(("gdth_sort_pci() cnt %d\n",cnt
));
931 for (i
= 0; i
< cnt
-1; ++i
) {
933 if ((pcistr
[i
].bus
> pcistr
[i
+1].bus
) ||
934 (pcistr
[i
].bus
== pcistr
[i
+1].bus
&&
935 PCI_SLOT(pcistr
[i
].device_fn
) >
936 PCI_SLOT(pcistr
[i
+1].device_fn
))) {
938 pcistr
[i
] = pcistr
[i
+1];
943 if ((pcistr
[i
].bus
< pcistr
[i
+1].bus
) ||
944 (pcistr
[i
].bus
== pcistr
[i
+1].bus
&&
945 PCI_SLOT(pcistr
[i
].device_fn
) <
946 PCI_SLOT(pcistr
[i
+1].device_fn
))) {
948 pcistr
[i
] = pcistr
[i
+1];
958 GDTH_INITFUNC(static int, gdth_init_eisa(ushort eisa_adr
,gdth_ha_str
*ha
))
961 unchar prot_ver
,eisacf
,i
,irq_found
;
963 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr
));
965 /* disable board interrupts, deinitialize services */
966 outb(0xff,eisa_adr
+EDOORREG
);
967 outb(0x00,eisa_adr
+EDENABREG
);
968 outb(0x00,eisa_adr
+EINTENABREG
);
970 outb(0xff,eisa_adr
+LDOORREG
);
971 retries
= INIT_RETRIES
;
973 while (inb(eisa_adr
+EDOORREG
) != 0xff) {
974 if (--retries
== 0) {
975 printk("GDT-EISA: Initialization error (DEINIT failed)\n");
979 TRACE2(("wait for DEINIT: retries=%d\n",retries
));
981 prot_ver
= inb(eisa_adr
+MAILBOXREG
);
982 outb(0xff,eisa_adr
+EDOORREG
);
983 if (prot_ver
!= PROTOCOL_VERSION
) {
984 printk("GDT-EISA: Illegal protocol version\n");
988 ha
->brd_phys
= (ulong32
)eisa_adr
>> 12;
990 outl(0,eisa_adr
+MAILBOXREG
);
991 outl(0,eisa_adr
+MAILBOXREG
+4);
992 outl(0,eisa_adr
+MAILBOXREG
+8);
993 outl(0,eisa_adr
+MAILBOXREG
+12);
996 if ((id
= inl(eisa_adr
+ID0REG
)) == GDT3_ID
) {
997 ha
->oem_id
= OEM_ID_ICP
;
1000 outl(1,eisa_adr
+MAILBOXREG
+8);
1001 outb(0xfe,eisa_adr
+LDOORREG
);
1002 retries
= INIT_RETRIES
;
1004 while (inb(eisa_adr
+EDOORREG
) != 0xfe) {
1005 if (--retries
== 0) {
1006 printk("GDT-EISA: Initialization error (get IRQ failed)\n");
1011 ha
->irq
= inb(eisa_adr
+MAILBOXREG
);
1012 outb(0xff,eisa_adr
+EDOORREG
);
1013 TRACE2(("GDT3000/3020: IRQ=%d\n",ha
->irq
));
1014 /* check the result */
1016 TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
1017 for (i
= 0, irq_found
= FALSE
;
1018 i
< MAXHA
&& irq
[i
] != 0xff; ++i
) {
1019 if (irq
[i
]==10 || irq
[i
]==11 || irq
[i
]==12 || irq
[i
]==14) {
1027 printk("GDT-EISA: Can not detect controller IRQ,\n");
1028 printk("Use IRQ setting from command line (IRQ = %d)\n",
1031 printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
1032 printk("the controller BIOS or use command line parameters\n");
1037 eisacf
= inb(eisa_adr
+EISAREG
) & 7;
1038 if (eisacf
> 4) /* level triggered */
1040 ha
->irq
= gdth_irq_tab
[eisacf
];
1041 ha
->oem_id
= OEM_ID_ICP
;
1042 ha
->type
= GDT_EISA
;
1046 ha
->dma64_support
= 0;
1051 GDTH_INITFUNC(static int, gdth_init_isa(ulong32 bios_adr
,gdth_ha_str
*ha
))
1053 register gdt2_dpram_str __iomem
*dp2_ptr
;
1055 unchar irq_drq
,prot_ver
;
1058 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr
));
1060 ha
->brd
= ioremap(bios_adr
, sizeof(gdt2_dpram_str
));
1061 if (ha
->brd
== NULL
) {
1062 printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
1066 gdth_writeb(1, &dp2_ptr
->io
.memlock
); /* switch off write protection */
1067 /* reset interface area */
1068 memset_io(&dp2_ptr
->u
, 0, sizeof(dp2_ptr
->u
));
1069 if (gdth_readl(&dp2_ptr
->u
) != 0) {
1070 printk("GDT-ISA: Initialization error (DPMEM write error)\n");
1075 /* disable board interrupts, read DRQ and IRQ */
1076 gdth_writeb(0xff, &dp2_ptr
->io
.irqdel
);
1077 gdth_writeb(0x00, &dp2_ptr
->io
.irqen
);
1078 gdth_writeb(0x00, &dp2_ptr
->u
.ic
.S_Status
);
1079 gdth_writeb(0x00, &dp2_ptr
->u
.ic
.Cmd_Index
);
1081 irq_drq
= gdth_readb(&dp2_ptr
->io
.rq
);
1082 for (i
=0; i
<3; ++i
) {
1083 if ((irq_drq
& 1)==0)
1087 ha
->drq
= gdth_drq_tab
[i
];
1089 irq_drq
= gdth_readb(&dp2_ptr
->io
.rq
) >> 3;
1090 for (i
=1; i
<5; ++i
) {
1091 if ((irq_drq
& 1)==0)
1095 ha
->irq
= gdth_irq_tab
[i
];
1097 /* deinitialize services */
1098 gdth_writel(bios_adr
, &dp2_ptr
->u
.ic
.S_Info
[0]);
1099 gdth_writeb(0xff, &dp2_ptr
->u
.ic
.S_Cmd_Indx
);
1100 gdth_writeb(0, &dp2_ptr
->io
.event
);
1101 retries
= INIT_RETRIES
;
1103 while (gdth_readb(&dp2_ptr
->u
.ic
.S_Status
) != 0xff) {
1104 if (--retries
== 0) {
1105 printk("GDT-ISA: Initialization error (DEINIT failed)\n");
1111 prot_ver
= (unchar
)gdth_readl(&dp2_ptr
->u
.ic
.S_Info
[0]);
1112 gdth_writeb(0, &dp2_ptr
->u
.ic
.Status
);
1113 gdth_writeb(0xff, &dp2_ptr
->io
.irqdel
);
1114 if (prot_ver
!= PROTOCOL_VERSION
) {
1115 printk("GDT-ISA: Illegal protocol version\n");
1120 ha
->oem_id
= OEM_ID_ICP
;
1122 ha
->ic_all_size
= sizeof(dp2_ptr
->u
);
1124 ha
->brd_phys
= bios_adr
>> 4;
1126 /* special request to controller BIOS */
1127 gdth_writel(0x00, &dp2_ptr
->u
.ic
.S_Info
[0]);
1128 gdth_writel(0x00, &dp2_ptr
->u
.ic
.S_Info
[1]);
1129 gdth_writel(0x01, &dp2_ptr
->u
.ic
.S_Info
[2]);
1130 gdth_writel(0x00, &dp2_ptr
->u
.ic
.S_Info
[3]);
1131 gdth_writeb(0xfe, &dp2_ptr
->u
.ic
.S_Cmd_Indx
);
1132 gdth_writeb(0, &dp2_ptr
->io
.event
);
1133 retries
= INIT_RETRIES
;
1135 while (gdth_readb(&dp2_ptr
->u
.ic
.S_Status
) != 0xfe) {
1136 if (--retries
== 0) {
1137 printk("GDT-ISA: Initialization error\n");
1143 gdth_writeb(0, &dp2_ptr
->u
.ic
.Status
);
1144 gdth_writeb(0xff, &dp2_ptr
->io
.irqdel
);
1146 ha
->dma64_support
= 0;
1151 GDTH_INITFUNC(static int, gdth_init_pci(gdth_pci_str
*pcistr
,gdth_ha_str
*ha
))
1153 register gdt6_dpram_str __iomem
*dp6_ptr
;
1154 register gdt6c_dpram_str __iomem
*dp6c_ptr
;
1155 register gdt6m_dpram_str __iomem
*dp6m_ptr
;
1159 int i
, found
= FALSE
;
1161 TRACE(("gdth_init_pci()\n"));
1163 if (pcistr
->vendor_id
== PCI_VENDOR_ID_INTEL
)
1164 ha
->oem_id
= OEM_ID_INTEL
;
1166 ha
->oem_id
= OEM_ID_ICP
;
1167 ha
->brd_phys
= (pcistr
->bus
<< 8) | (pcistr
->device_fn
& 0xf8);
1168 ha
->stype
= (ulong32
)pcistr
->device_id
;
1169 ha
->subdevice_id
= pcistr
->subdevice_id
;
1170 ha
->irq
= pcistr
->irq
;
1171 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1172 ha
->pdev
= pcistr
->pdev
;
1175 if (ha
->stype
<= PCI_DEVICE_ID_VORTEX_GDT6000B
) { /* GDT6000/B */
1176 TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr
->dpmem
,ha
->irq
));
1177 ha
->brd
= ioremap(pcistr
->dpmem
, sizeof(gdt6_dpram_str
));
1178 if (ha
->brd
== NULL
) {
1179 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1182 /* check and reset interface area */
1184 gdth_writel(DPMEM_MAGIC
, &dp6_ptr
->u
);
1185 if (gdth_readl(&dp6_ptr
->u
) != DPMEM_MAGIC
) {
1186 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1189 for (i
= 0xC8000; i
< 0xE8000; i
+= 0x4000) {
1191 ha
->brd
= ioremap(i
, sizeof(ushort
));
1192 if (ha
->brd
== NULL
) {
1193 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1196 if (gdth_readw(ha
->brd
) != 0xffff) {
1197 TRACE2(("init_pci_old() address 0x%x busy\n", i
));
1201 pci_write_config_dword(pcistr
->pdev
,
1202 PCI_BASE_ADDRESS_0
, i
);
1203 ha
->brd
= ioremap(i
, sizeof(gdt6_dpram_str
));
1204 if (ha
->brd
== NULL
) {
1205 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1209 gdth_writel(DPMEM_MAGIC
, &dp6_ptr
->u
);
1210 if (gdth_readl(&dp6_ptr
->u
) == DPMEM_MAGIC
) {
1211 printk("GDT-PCI: Use free address at 0x%x\n", i
);
1217 printk("GDT-PCI: No free address found!\n");
1222 memset_io(&dp6_ptr
->u
, 0, sizeof(dp6_ptr
->u
));
1223 if (gdth_readl(&dp6_ptr
->u
) != 0) {
1224 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1229 /* disable board interrupts, deinit services */
1230 gdth_writeb(0xff, &dp6_ptr
->io
.irqdel
);
1231 gdth_writeb(0x00, &dp6_ptr
->io
.irqen
);
1232 gdth_writeb(0x00, &dp6_ptr
->u
.ic
.S_Status
);
1233 gdth_writeb(0x00, &dp6_ptr
->u
.ic
.Cmd_Index
);
1235 gdth_writel(pcistr
->dpmem
, &dp6_ptr
->u
.ic
.S_Info
[0]);
1236 gdth_writeb(0xff, &dp6_ptr
->u
.ic
.S_Cmd_Indx
);
1237 gdth_writeb(0, &dp6_ptr
->io
.event
);
1238 retries
= INIT_RETRIES
;
1240 while (gdth_readb(&dp6_ptr
->u
.ic
.S_Status
) != 0xff) {
1241 if (--retries
== 0) {
1242 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1248 prot_ver
= (unchar
)gdth_readl(&dp6_ptr
->u
.ic
.S_Info
[0]);
1249 gdth_writeb(0, &dp6_ptr
->u
.ic
.S_Status
);
1250 gdth_writeb(0xff, &dp6_ptr
->io
.irqdel
);
1251 if (prot_ver
!= PROTOCOL_VERSION
) {
1252 printk("GDT-PCI: Illegal protocol version\n");
1258 ha
->ic_all_size
= sizeof(dp6_ptr
->u
);
1260 /* special command to controller BIOS */
1261 gdth_writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[0]);
1262 gdth_writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[1]);
1263 gdth_writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[2]);
1264 gdth_writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[3]);
1265 gdth_writeb(0xfe, &dp6_ptr
->u
.ic
.S_Cmd_Indx
);
1266 gdth_writeb(0, &dp6_ptr
->io
.event
);
1267 retries
= INIT_RETRIES
;
1269 while (gdth_readb(&dp6_ptr
->u
.ic
.S_Status
) != 0xfe) {
1270 if (--retries
== 0) {
1271 printk("GDT-PCI: Initialization error\n");
1277 gdth_writeb(0, &dp6_ptr
->u
.ic
.S_Status
);
1278 gdth_writeb(0xff, &dp6_ptr
->io
.irqdel
);
1280 ha
->dma64_support
= 0;
1282 } else if (ha
->stype
<= PCI_DEVICE_ID_VORTEX_GDT6555
) { /* GDT6110, ... */
1283 ha
->plx
= (gdt6c_plx_regs
*)pcistr
->io
;
1284 TRACE2(("init_pci_new() dpmem %lx irq %d\n",
1285 pcistr
->dpmem
,ha
->irq
));
1286 ha
->brd
= ioremap(pcistr
->dpmem
, sizeof(gdt6c_dpram_str
));
1287 if (ha
->brd
== NULL
) {
1288 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1292 /* check and reset interface area */
1294 gdth_writel(DPMEM_MAGIC
, &dp6c_ptr
->u
);
1295 if (gdth_readl(&dp6c_ptr
->u
) != DPMEM_MAGIC
) {
1296 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1299 for (i
= 0xC8000; i
< 0xE8000; i
+= 0x4000) {
1301 ha
->brd
= ioremap(i
, sizeof(ushort
));
1302 if (ha
->brd
== NULL
) {
1303 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1306 if (gdth_readw(ha
->brd
) != 0xffff) {
1307 TRACE2(("init_pci_plx() address 0x%x busy\n", i
));
1311 pci_write_config_dword(pcistr
->pdev
,
1312 PCI_BASE_ADDRESS_2
, i
);
1313 ha
->brd
= ioremap(i
, sizeof(gdt6c_dpram_str
));
1314 if (ha
->brd
== NULL
) {
1315 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1319 gdth_writel(DPMEM_MAGIC
, &dp6c_ptr
->u
);
1320 if (gdth_readl(&dp6c_ptr
->u
) == DPMEM_MAGIC
) {
1321 printk("GDT-PCI: Use free address at 0x%x\n", i
);
1327 printk("GDT-PCI: No free address found!\n");
1332 memset_io(&dp6c_ptr
->u
, 0, sizeof(dp6c_ptr
->u
));
1333 if (gdth_readl(&dp6c_ptr
->u
) != 0) {
1334 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1339 /* disable board interrupts, deinit services */
1340 outb(0x00,PTR2USHORT(&ha
->plx
->control1
));
1341 outb(0xff,PTR2USHORT(&ha
->plx
->edoor_reg
));
1343 gdth_writeb(0x00, &dp6c_ptr
->u
.ic
.S_Status
);
1344 gdth_writeb(0x00, &dp6c_ptr
->u
.ic
.Cmd_Index
);
1346 gdth_writel(pcistr
->dpmem
, &dp6c_ptr
->u
.ic
.S_Info
[0]);
1347 gdth_writeb(0xff, &dp6c_ptr
->u
.ic
.S_Cmd_Indx
);
1349 outb(1,PTR2USHORT(&ha
->plx
->ldoor_reg
));
1351 retries
= INIT_RETRIES
;
1353 while (gdth_readb(&dp6c_ptr
->u
.ic
.S_Status
) != 0xff) {
1354 if (--retries
== 0) {
1355 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1361 prot_ver
= (unchar
)gdth_readl(&dp6c_ptr
->u
.ic
.S_Info
[0]);
1362 gdth_writeb(0, &dp6c_ptr
->u
.ic
.Status
);
1363 if (prot_ver
!= PROTOCOL_VERSION
) {
1364 printk("GDT-PCI: Illegal protocol version\n");
1369 ha
->type
= GDT_PCINEW
;
1370 ha
->ic_all_size
= sizeof(dp6c_ptr
->u
);
1372 /* special command to controller BIOS */
1373 gdth_writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[0]);
1374 gdth_writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[1]);
1375 gdth_writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[2]);
1376 gdth_writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[3]);
1377 gdth_writeb(0xfe, &dp6c_ptr
->u
.ic
.S_Cmd_Indx
);
1379 outb(1,PTR2USHORT(&ha
->plx
->ldoor_reg
));
1381 retries
= INIT_RETRIES
;
1383 while (gdth_readb(&dp6c_ptr
->u
.ic
.S_Status
) != 0xfe) {
1384 if (--retries
== 0) {
1385 printk("GDT-PCI: Initialization error\n");
1391 gdth_writeb(0, &dp6c_ptr
->u
.ic
.S_Status
);
1393 ha
->dma64_support
= 0;
1396 TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr
->dpmem
,ha
->irq
));
1397 ha
->brd
= ioremap(pcistr
->dpmem
, sizeof(gdt6m_dpram_str
));
1398 if (ha
->brd
== NULL
) {
1399 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1403 /* manipulate config. space to enable DPMEM, start RP controller */
1404 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1405 pci_read_config_word(pcistr
->pdev
, PCI_COMMAND
, &command
);
1407 pci_write_config_word(pcistr
->pdev
, PCI_COMMAND
, command
);
1408 if (pci_resource_start(pcistr
->pdev
, 8) == 1UL)
1409 pci_resource_start(pcistr
->pdev
, 8) = 0UL;
1411 pci_write_config_dword(pcistr
->pdev
, PCI_ROM_ADDRESS
, i
);
1413 pci_write_config_dword(pcistr
->pdev
, PCI_ROM_ADDRESS
,
1414 pci_resource_start(pcistr
->pdev
, 8));
1416 pci_read_config_word(pcistr
->pdev
, PCI_COMMAND
, &command
);
1418 pci_write_config_word(pcistr
->pdev
, PCI_COMMAND
, command
);
1419 if (pcistr
->pdev
->rom_address
== 1UL)
1420 pcistr
->pdev
->rom_address
= 0UL;
1422 pci_write_config_dword(pcistr
->pdev
, PCI_ROM_ADDRESS
, i
);
1424 pci_write_config_dword(pcistr
->pdev
, PCI_ROM_ADDRESS
,
1425 pcistr
->pdev
->rom_address
);
1430 /* Ensure that it is safe to access the non HW portions of DPMEM.
1431 * Aditional check needed for Xscale based RAID controllers */
1432 while( ((int)gdth_readb(&dp6m_ptr
->i960r
.sema0_reg
) ) & 3 )
1435 /* check and reset interface area */
1436 gdth_writel(DPMEM_MAGIC
, &dp6m_ptr
->u
);
1437 if (gdth_readl(&dp6m_ptr
->u
) != DPMEM_MAGIC
) {
1438 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1441 for (i
= 0xC8000; i
< 0xE8000; i
+= 0x4000) {
1443 ha
->brd
= ioremap(i
, sizeof(ushort
));
1444 if (ha
->brd
== NULL
) {
1445 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1448 if (gdth_readw(ha
->brd
) != 0xffff) {
1449 TRACE2(("init_pci_mpr() address 0x%x busy\n", i
));
1453 pci_write_config_dword(pcistr
->pdev
,
1454 PCI_BASE_ADDRESS_0
, i
);
1455 ha
->brd
= ioremap(i
, sizeof(gdt6m_dpram_str
));
1456 if (ha
->brd
== NULL
) {
1457 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1461 gdth_writel(DPMEM_MAGIC
, &dp6m_ptr
->u
);
1462 if (gdth_readl(&dp6m_ptr
->u
) == DPMEM_MAGIC
) {
1463 printk("GDT-PCI: Use free address at 0x%x\n", i
);
1469 printk("GDT-PCI: No free address found!\n");
1474 memset_io(&dp6m_ptr
->u
, 0, sizeof(dp6m_ptr
->u
));
1476 /* disable board interrupts, deinit services */
1477 gdth_writeb(gdth_readb(&dp6m_ptr
->i960r
.edoor_en_reg
) | 4,
1478 &dp6m_ptr
->i960r
.edoor_en_reg
);
1479 gdth_writeb(0xff, &dp6m_ptr
->i960r
.edoor_reg
);
1480 gdth_writeb(0x00, &dp6m_ptr
->u
.ic
.S_Status
);
1481 gdth_writeb(0x00, &dp6m_ptr
->u
.ic
.Cmd_Index
);
1483 gdth_writel(pcistr
->dpmem
, &dp6m_ptr
->u
.ic
.S_Info
[0]);
1484 gdth_writeb(0xff, &dp6m_ptr
->u
.ic
.S_Cmd_Indx
);
1485 gdth_writeb(1, &dp6m_ptr
->i960r
.ldoor_reg
);
1486 retries
= INIT_RETRIES
;
1488 while (gdth_readb(&dp6m_ptr
->u
.ic
.S_Status
) != 0xff) {
1489 if (--retries
== 0) {
1490 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1496 prot_ver
= (unchar
)gdth_readl(&dp6m_ptr
->u
.ic
.S_Info
[0]);
1497 gdth_writeb(0, &dp6m_ptr
->u
.ic
.S_Status
);
1498 if (prot_ver
!= PROTOCOL_VERSION
) {
1499 printk("GDT-PCI: Illegal protocol version\n");
1504 ha
->type
= GDT_PCIMPR
;
1505 ha
->ic_all_size
= sizeof(dp6m_ptr
->u
);
1507 /* special command to controller BIOS */
1508 gdth_writel(0x00, &dp6m_ptr
->u
.ic
.S_Info
[0]);
1509 gdth_writel(0x00, &dp6m_ptr
->u
.ic
.S_Info
[1]);
1510 gdth_writel(0x00, &dp6m_ptr
->u
.ic
.S_Info
[2]);
1511 gdth_writel(0x00, &dp6m_ptr
->u
.ic
.S_Info
[3]);
1512 gdth_writeb(0xfe, &dp6m_ptr
->u
.ic
.S_Cmd_Indx
);
1513 gdth_writeb(1, &dp6m_ptr
->i960r
.ldoor_reg
);
1514 retries
= INIT_RETRIES
;
1516 while (gdth_readb(&dp6m_ptr
->u
.ic
.S_Status
) != 0xfe) {
1517 if (--retries
== 0) {
1518 printk("GDT-PCI: Initialization error\n");
1524 gdth_writeb(0, &dp6m_ptr
->u
.ic
.S_Status
);
1526 /* read FW version to detect 64-bit DMA support */
1527 gdth_writeb(0xfd, &dp6m_ptr
->u
.ic
.S_Cmd_Indx
);
1528 gdth_writeb(1, &dp6m_ptr
->i960r
.ldoor_reg
);
1529 retries
= INIT_RETRIES
;
1531 while (gdth_readb(&dp6m_ptr
->u
.ic
.S_Status
) != 0xfd) {
1532 if (--retries
== 0) {
1533 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1539 prot_ver
= (unchar
)(gdth_readl(&dp6m_ptr
->u
.ic
.S_Info
[0]) >> 16);
1540 gdth_writeb(0, &dp6m_ptr
->u
.ic
.S_Status
);
1541 if (prot_ver
< 0x2b) /* FW < x.43: no 64-bit DMA support */
1542 ha
->dma64_support
= 0;
1544 ha
->dma64_support
= 1;
1551 /* controller protocol functions */
1553 GDTH_INITFUNC(static void, gdth_enable_int(int hanum
))
1557 gdt2_dpram_str __iomem
*dp2_ptr
;
1558 gdt6_dpram_str __iomem
*dp6_ptr
;
1559 gdt6m_dpram_str __iomem
*dp6m_ptr
;
1561 TRACE(("gdth_enable_int() hanum %d\n",hanum
));
1562 ha
= HADATA(gdth_ctr_tab
[hanum
]);
1563 GDTH_LOCK_HA(ha
, flags
);
1565 if (ha
->type
== GDT_EISA
) {
1566 outb(0xff, ha
->bmic
+ EDOORREG
);
1567 outb(0xff, ha
->bmic
+ EDENABREG
);
1568 outb(0x01, ha
->bmic
+ EINTENABREG
);
1569 } else if (ha
->type
== GDT_ISA
) {
1571 gdth_writeb(1, &dp2_ptr
->io
.irqdel
);
1572 gdth_writeb(0, &dp2_ptr
->u
.ic
.Cmd_Index
);
1573 gdth_writeb(1, &dp2_ptr
->io
.irqen
);
1574 } else if (ha
->type
== GDT_PCI
) {
1576 gdth_writeb(1, &dp6_ptr
->io
.irqdel
);
1577 gdth_writeb(0, &dp6_ptr
->u
.ic
.Cmd_Index
);
1578 gdth_writeb(1, &dp6_ptr
->io
.irqen
);
1579 } else if (ha
->type
== GDT_PCINEW
) {
1580 outb(0xff, PTR2USHORT(&ha
->plx
->edoor_reg
));
1581 outb(0x03, PTR2USHORT(&ha
->plx
->control1
));
1582 } else if (ha
->type
== GDT_PCIMPR
) {
1584 gdth_writeb(0xff, &dp6m_ptr
->i960r
.edoor_reg
);
1585 gdth_writeb(gdth_readb(&dp6m_ptr
->i960r
.edoor_en_reg
) & ~4,
1586 &dp6m_ptr
->i960r
.edoor_en_reg
);
1588 GDTH_UNLOCK_HA(ha
, flags
);
1592 static int gdth_get_status(unchar
*pIStatus
,int irq
)
1594 register gdth_ha_str
*ha
;
1597 TRACE(("gdth_get_status() irq %d ctr_count %d\n",
1598 irq
,gdth_ctr_count
));
1601 for (i
=0; i
<gdth_ctr_count
; ++i
) {
1602 ha
= HADATA(gdth_ctr_tab
[i
]);
1603 if (ha
->irq
!= (unchar
)irq
) /* check IRQ */
1605 if (ha
->type
== GDT_EISA
)
1606 *pIStatus
= inb((ushort
)ha
->bmic
+ EDOORREG
);
1607 else if (ha
->type
== GDT_ISA
)
1609 gdth_readb(&((gdt2_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Cmd_Index
);
1610 else if (ha
->type
== GDT_PCI
)
1612 gdth_readb(&((gdt6_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Cmd_Index
);
1613 else if (ha
->type
== GDT_PCINEW
)
1614 *pIStatus
= inb(PTR2USHORT(&ha
->plx
->edoor_reg
));
1615 else if (ha
->type
== GDT_PCIMPR
)
1617 gdth_readb(&((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.edoor_reg
);
1620 return i
; /* board found */
1626 static int gdth_test_busy(int hanum
)
1628 register gdth_ha_str
*ha
;
1629 register int gdtsema0
= 0;
1631 TRACE(("gdth_test_busy() hanum %d\n",hanum
));
1633 ha
= HADATA(gdth_ctr_tab
[hanum
]);
1634 if (ha
->type
== GDT_EISA
)
1635 gdtsema0
= (int)inb(ha
->bmic
+ SEMA0REG
);
1636 else if (ha
->type
== GDT_ISA
)
1637 gdtsema0
= (int)gdth_readb(&((gdt2_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Sema0
);
1638 else if (ha
->type
== GDT_PCI
)
1639 gdtsema0
= (int)gdth_readb(&((gdt6_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Sema0
);
1640 else if (ha
->type
== GDT_PCINEW
)
1641 gdtsema0
= (int)inb(PTR2USHORT(&ha
->plx
->sema0_reg
));
1642 else if (ha
->type
== GDT_PCIMPR
)
1644 (int)gdth_readb(&((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.sema0_reg
);
1646 return (gdtsema0
& 1);
1650 static int gdth_get_cmd_index(int hanum
)
1652 register gdth_ha_str
*ha
;
1655 TRACE(("gdth_get_cmd_index() hanum %d\n",hanum
));
1657 ha
= HADATA(gdth_ctr_tab
[hanum
]);
1658 for (i
=0; i
<GDTH_MAXCMDS
; ++i
) {
1659 if (ha
->cmd_tab
[i
].cmnd
== UNUSED_CMND
) {
1660 ha
->cmd_tab
[i
].cmnd
= ha
->pccb
->RequestBuffer
;
1661 ha
->cmd_tab
[i
].service
= ha
->pccb
->Service
;
1662 ha
->pccb
->CommandIndex
= (ulong32
)i
+2;
1670 static void gdth_set_sema0(int hanum
)
1672 register gdth_ha_str
*ha
;
1674 TRACE(("gdth_set_sema0() hanum %d\n",hanum
));
1676 ha
= HADATA(gdth_ctr_tab
[hanum
]);
1677 if (ha
->type
== GDT_EISA
) {
1678 outb(1, ha
->bmic
+ SEMA0REG
);
1679 } else if (ha
->type
== GDT_ISA
) {
1680 gdth_writeb(1, &((gdt2_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Sema0
);
1681 } else if (ha
->type
== GDT_PCI
) {
1682 gdth_writeb(1, &((gdt6_dpram_str __iomem
*)ha
->brd
)->u
.ic
.Sema0
);
1683 } else if (ha
->type
== GDT_PCINEW
) {
1684 outb(1, PTR2USHORT(&ha
->plx
->sema0_reg
));
1685 } else if (ha
->type
== GDT_PCIMPR
) {
1686 gdth_writeb(1, &((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.sema0_reg
);
1691 static void gdth_copy_command(int hanum
)
1693 register gdth_ha_str
*ha
;
1694 register gdth_cmd_str
*cmd_ptr
;
1695 register gdt6m_dpram_str __iomem
*dp6m_ptr
;
1696 register gdt6c_dpram_str __iomem
*dp6c_ptr
;
1697 gdt6_dpram_str __iomem
*dp6_ptr
;
1698 gdt2_dpram_str __iomem
*dp2_ptr
;
1699 ushort cp_count
,dp_offset
,cmd_no
;
1701 TRACE(("gdth_copy_command() hanum %d\n",hanum
));
1703 ha
= HADATA(gdth_ctr_tab
[hanum
]);
1704 cp_count
= ha
->cmd_len
;
1705 dp_offset
= ha
->cmd_offs_dpmem
;
1706 cmd_no
= ha
->cmd_cnt
;
1710 if (ha
->type
== GDT_EISA
)
1711 return; /* no DPMEM, no copy */
1713 /* set cpcount dword aligned */
1715 cp_count
+= (4 - (cp_count
& 3));
1717 ha
->cmd_offs_dpmem
+= cp_count
;
1719 /* set offset and service, copy command to DPMEM */
1720 if (ha
->type
== GDT_ISA
) {
1722 gdth_writew(dp_offset
+ DPMEM_COMMAND_OFFSET
,
1723 &dp2_ptr
->u
.ic
.comm_queue
[cmd_no
].offset
);
1724 gdth_writew((ushort
)cmd_ptr
->Service
,
1725 &dp2_ptr
->u
.ic
.comm_queue
[cmd_no
].serv_id
);
1726 memcpy_toio(&dp2_ptr
->u
.ic
.gdt_dpr_cmd
[dp_offset
],cmd_ptr
,cp_count
);
1727 } else if (ha
->type
== GDT_PCI
) {
1729 gdth_writew(dp_offset
+ DPMEM_COMMAND_OFFSET
,
1730 &dp6_ptr
->u
.ic
.comm_queue
[cmd_no
].offset
);
1731 gdth_writew((ushort
)cmd_ptr
->Service
,
1732 &dp6_ptr
->u
.ic
.comm_queue
[cmd_no
].serv_id
);
1733 memcpy_toio(&dp6_ptr
->u
.ic
.gdt_dpr_cmd
[dp_offset
],cmd_ptr
,cp_count
);
1734 } else if (ha
->type
== GDT_PCINEW
) {
1736 gdth_writew(dp_offset
+ DPMEM_COMMAND_OFFSET
,
1737 &dp6c_ptr
->u
.ic
.comm_queue
[cmd_no
].offset
);
1738 gdth_writew((ushort
)cmd_ptr
->Service
,
1739 &dp6c_ptr
->u
.ic
.comm_queue
[cmd_no
].serv_id
);
1740 memcpy_toio(&dp6c_ptr
->u
.ic
.gdt_dpr_cmd
[dp_offset
],cmd_ptr
,cp_count
);
1741 } else if (ha
->type
== GDT_PCIMPR
) {
1743 gdth_writew(dp_offset
+ DPMEM_COMMAND_OFFSET
,
1744 &dp6m_ptr
->u
.ic
.comm_queue
[cmd_no
].offset
);
1745 gdth_writew((ushort
)cmd_ptr
->Service
,
1746 &dp6m_ptr
->u
.ic
.comm_queue
[cmd_no
].serv_id
);
1747 memcpy_toio(&dp6m_ptr
->u
.ic
.gdt_dpr_cmd
[dp_offset
],cmd_ptr
,cp_count
);
1752 static void gdth_release_event(int hanum
)
1754 register gdth_ha_str
*ha
;
1756 TRACE(("gdth_release_event() hanum %d\n",hanum
));
1757 ha
= HADATA(gdth_ctr_tab
[hanum
]);
1759 #ifdef GDTH_STATISTICS
1762 for (i
=0,j
=0; j
<GDTH_MAXCMDS
; ++j
) {
1763 if (ha
->cmd_tab
[j
].cmnd
!= UNUSED_CMND
)
1766 if (max_index
< i
) {
1768 TRACE3(("GDT: max_index = %d\n",(ushort
)i
));
1773 if (ha
->pccb
->OpCode
== GDT_INIT
)
1774 ha
->pccb
->Service
|= 0x80;
1776 if (ha
->type
== GDT_EISA
) {
1777 if (ha
->pccb
->OpCode
== GDT_INIT
) /* store DMA buffer */
1778 outl(ha
->ccb_phys
, ha
->bmic
+ MAILBOXREG
);
1779 outb(ha
->pccb
->Service
, ha
->bmic
+ LDOORREG
);
1780 } else if (ha
->type
== GDT_ISA
) {
1781 gdth_writeb(0, &((gdt2_dpram_str __iomem
*)ha
->brd
)->io
.event
);
1782 } else if (ha
->type
== GDT_PCI
) {
1783 gdth_writeb(0, &((gdt6_dpram_str __iomem
*)ha
->brd
)->io
.event
);
1784 } else if (ha
->type
== GDT_PCINEW
) {
1785 outb(1, PTR2USHORT(&ha
->plx
->ldoor_reg
));
1786 } else if (ha
->type
== GDT_PCIMPR
) {
1787 gdth_writeb(1, &((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.ldoor_reg
);
1792 static int gdth_wait(int hanum
,int index
,ulong32 time
)
1795 int answer_found
= FALSE
;
1797 TRACE(("gdth_wait() hanum %d index %d time %d\n",hanum
,index
,time
));
1799 ha
= HADATA(gdth_ctr_tab
[hanum
]);
1801 return 1; /* no wait required */
1803 gdth_from_wait
= TRUE
;
1805 gdth_interrupt((int)ha
->irq
,ha
,NULL
);
1806 if (wait_hanum
==hanum
&& wait_index
==index
) {
1807 answer_found
= TRUE
;
1812 gdth_from_wait
= FALSE
;
1814 while (gdth_test_busy(hanum
))
1817 return (answer_found
);
1821 static int gdth_internal_cmd(int hanum
,unchar service
,ushort opcode
,ulong32 p1
,
1822 ulong64 p2
,ulong64 p3
)
1824 register gdth_ha_str
*ha
;
1825 register gdth_cmd_str
*cmd_ptr
;
1828 TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service
,opcode
));
1830 ha
= HADATA(gdth_ctr_tab
[hanum
]);
1832 memset((char*)cmd_ptr
,0,sizeof(gdth_cmd_str
));
1835 for (retries
= INIT_RETRIES
;;) {
1836 cmd_ptr
->Service
= service
;
1837 cmd_ptr
->RequestBuffer
= INTERNAL_CMND
;
1838 if (!(index
=gdth_get_cmd_index(hanum
))) {
1839 TRACE(("GDT: No free command index found\n"));
1842 gdth_set_sema0(hanum
);
1843 cmd_ptr
->OpCode
= opcode
;
1844 cmd_ptr
->BoardNode
= LOCALBOARD
;
1845 if (service
== CACHESERVICE
) {
1846 if (opcode
== GDT_IOCTL
) {
1847 cmd_ptr
->u
.ioctl
.subfunc
= p1
;
1848 cmd_ptr
->u
.ioctl
.channel
= (ulong32
)p2
;
1849 cmd_ptr
->u
.ioctl
.param_size
= (ushort
)p3
;
1850 cmd_ptr
->u
.ioctl
.p_param
= ha
->scratch_phys
;
1852 if (ha
->cache_feat
& GDT_64BIT
) {
1853 cmd_ptr
->u
.cache64
.DeviceNo
= (ushort
)p1
;
1854 cmd_ptr
->u
.cache64
.BlockNo
= p2
;
1856 cmd_ptr
->u
.cache
.DeviceNo
= (ushort
)p1
;
1857 cmd_ptr
->u
.cache
.BlockNo
= (ulong32
)p2
;
1860 } else if (service
== SCSIRAWSERVICE
) {
1861 if (ha
->raw_feat
& GDT_64BIT
) {
1862 cmd_ptr
->u
.raw64
.direction
= p1
;
1863 cmd_ptr
->u
.raw64
.bus
= (unchar
)p2
;
1864 cmd_ptr
->u
.raw64
.target
= (unchar
)p3
;
1865 cmd_ptr
->u
.raw64
.lun
= (unchar
)(p3
>> 8);
1867 cmd_ptr
->u
.raw
.direction
= p1
;
1868 cmd_ptr
->u
.raw
.bus
= (unchar
)p2
;
1869 cmd_ptr
->u
.raw
.target
= (unchar
)p3
;
1870 cmd_ptr
->u
.raw
.lun
= (unchar
)(p3
>> 8);
1872 } else if (service
== SCREENSERVICE
) {
1873 if (opcode
== GDT_REALTIME
) {
1874 *(ulong32
*)&cmd_ptr
->u
.screen
.su
.data
[0] = p1
;
1875 *(ulong32
*)&cmd_ptr
->u
.screen
.su
.data
[4] = (ulong32
)p2
;
1876 *(ulong32
*)&cmd_ptr
->u
.screen
.su
.data
[8] = (ulong32
)p3
;
1879 ha
->cmd_len
= sizeof(gdth_cmd_str
);
1880 ha
->cmd_offs_dpmem
= 0;
1882 gdth_copy_command(hanum
);
1883 gdth_release_event(hanum
);
1885 if (!gdth_wait(hanum
,index
,INIT_TIMEOUT
)) {
1886 printk("GDT: Initialization error (timeout service %d)\n",service
);
1889 if (ha
->status
!= S_BSY
|| --retries
== 0)
1894 return (ha
->status
!= S_OK
? 0:1);
1898 /* search for devices */
1900 GDTH_INITFUNC(static int, gdth_search_drives(int hanum
))
1902 register gdth_ha_str
*ha
;
1905 ulong32 bus_no
, drv_cnt
, drv_no
, j
;
1906 gdth_getch_str
*chn
;
1907 gdth_drlist_str
*drl
;
1908 gdth_iochan_str
*ioc
;
1909 gdth_raw_iochan_str
*iocr
;
1910 gdth_arcdl_str
*alst
;
1911 gdth_alist_str
*alst2
;
1912 gdth_oem_str_ioctl
*oemstr
;
1914 gdth_perf_modes
*pmod
;
1922 TRACE(("gdth_search_drives() hanum %d\n",hanum
));
1923 ha
= HADATA(gdth_ctr_tab
[hanum
]);
1926 /* initialize controller services, at first: screen service */
1927 ha
->screen_feat
= 0;
1929 ok
= gdth_internal_cmd(hanum
,SCREENSERVICE
,GDT_X_INIT_SCR
,0,0,0);
1931 ha
->screen_feat
= GDT_64BIT
;
1933 if (force_dma32
|| (!ok
&& ha
->status
== (ushort
)S_NOFUNC
))
1934 ok
= gdth_internal_cmd(hanum
,SCREENSERVICE
,GDT_INIT
,0,0,0);
1936 printk("GDT-HA %d: Initialization error screen service (code %d)\n",
1940 TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n"));
1943 /* read realtime clock info, send to controller */
1944 /* 1. wait for the falling edge of update flag */
1945 spin_lock_irqsave(&rtc_lock
, flags
);
1946 for (j
= 0; j
< 1000000; ++j
)
1947 if (CMOS_READ(RTC_FREQ_SELECT
) & RTC_UIP
)
1949 for (j
= 0; j
< 1000000; ++j
)
1950 if (!(CMOS_READ(RTC_FREQ_SELECT
) & RTC_UIP
))
1954 for (j
= 0; j
< 12; ++j
)
1955 rtc
[j
] = CMOS_READ(j
);
1956 } while (rtc
[0] != CMOS_READ(0));
1957 spin_lock_irqrestore(&rtc_lock
, flags
);
1958 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32
*)&rtc
[0],
1959 *(ulong32
*)&rtc
[4], *(ulong32
*)&rtc
[8]));
1960 /* 3. send to controller firmware */
1961 gdth_internal_cmd(hanum
,SCREENSERVICE
,GDT_REALTIME
, *(ulong32
*)&rtc
[0],
1962 *(ulong32
*)&rtc
[4], *(ulong32
*)&rtc
[8]);
1965 /* unfreeze all IOs */
1966 gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_UNFREEZE_IO
,0,0,0);
1968 /* initialize cache service */
1971 ok
= gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_X_INIT_HOST
,LINUX_OS
,0,0);
1973 ha
->cache_feat
= GDT_64BIT
;
1975 if (force_dma32
|| (!ok
&& ha
->status
== (ushort
)S_NOFUNC
))
1976 ok
= gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_INIT
,LINUX_OS
,0,0);
1978 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1982 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
1983 cdev_cnt
= (ushort
)ha
->info
;
1984 ha
->fw_vers
= ha
->service
;
1987 if (ha
->type
== GDT_PCIMPR
) {
1988 /* set perf. modes */
1989 pmod
= (gdth_perf_modes
*)ha
->pscratch
;
1991 pmod
->st_mode
= 1; /* enable one status buffer */
1992 *((ulong64
*)&pmod
->st_buff_addr1
) = ha
->coal_stat_phys
;
1993 pmod
->st_buff_indx1
= COALINDEX
;
1994 pmod
->st_buff_addr2
= 0;
1995 pmod
->st_buff_u_addr2
= 0;
1996 pmod
->st_buff_indx2
= 0;
1997 pmod
->st_buff_size
= sizeof(gdth_coal_status
) * MAXOFFSETS
;
1998 pmod
->cmd_mode
= 0; // disable all cmd buffers
1999 pmod
->cmd_buff_addr1
= 0;
2000 pmod
->cmd_buff_u_addr1
= 0;
2001 pmod
->cmd_buff_indx1
= 0;
2002 pmod
->cmd_buff_addr2
= 0;
2003 pmod
->cmd_buff_u_addr2
= 0;
2004 pmod
->cmd_buff_indx2
= 0;
2005 pmod
->cmd_buff_size
= 0;
2006 pmod
->reserved1
= 0;
2007 pmod
->reserved2
= 0;
2008 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,SET_PERF_MODES
,
2009 INVALID_CHANNEL
,sizeof(gdth_perf_modes
))) {
2010 printk("GDT-HA %d: Interrupt coalescing activated\n", hanum
);
2015 /* detect number of buses - try new IOCTL */
2016 iocr
= (gdth_raw_iochan_str
*)ha
->pscratch
;
2017 iocr
->hdr
.version
= 0xffffffff;
2018 iocr
->hdr
.list_entries
= MAXBUS
;
2019 iocr
->hdr
.first_chan
= 0;
2020 iocr
->hdr
.last_chan
= MAXBUS
-1;
2021 iocr
->hdr
.list_offset
= GDTOFFSOF(gdth_raw_iochan_str
, list
[0]);
2022 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,IOCHAN_RAW_DESC
,
2023 INVALID_CHANNEL
,sizeof(gdth_raw_iochan_str
))) {
2024 TRACE2(("IOCHAN_RAW_DESC supported!\n"));
2025 ha
->bus_cnt
= iocr
->hdr
.chan_count
;
2026 for (bus_no
= 0; bus_no
< ha
->bus_cnt
; ++bus_no
) {
2027 if (iocr
->list
[bus_no
].proc_id
< MAXID
)
2028 ha
->bus_id
[bus_no
] = iocr
->list
[bus_no
].proc_id
;
2030 ha
->bus_id
[bus_no
] = 0xff;
2034 chn
= (gdth_getch_str
*)ha
->pscratch
;
2035 for (bus_no
= 0; bus_no
< MAXBUS
; ++bus_no
) {
2036 chn
->channel_no
= bus_no
;
2037 if (!gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,
2038 SCSI_CHAN_CNT
| L_CTRL_PATTERN
,
2039 IO_CHANNEL
| INVALID_CHANNEL
,
2040 sizeof(gdth_getch_str
))) {
2042 printk("GDT-HA %d: Error detecting channel count (0x%x)\n",
2048 if (chn
->siop_id
< MAXID
)
2049 ha
->bus_id
[bus_no
] = chn
->siop_id
;
2051 ha
->bus_id
[bus_no
] = 0xff;
2053 ha
->bus_cnt
= (unchar
)bus_no
;
2055 TRACE2(("gdth_search_drives() %d channels\n",ha
->bus_cnt
));
2057 /* read cache configuration */
2058 if (!gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,CACHE_INFO
,
2059 INVALID_CHANNEL
,sizeof(gdth_cinfo_str
))) {
2060 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
2064 ha
->cpar
= ((gdth_cinfo_str
*)ha
->pscratch
)->cpar
;
2065 TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
2066 ha
->cpar
.version
,ha
->cpar
.state
,ha
->cpar
.strategy
,
2067 ha
->cpar
.write_back
,ha
->cpar
.block_size
));
2069 /* read board info and features */
2070 ha
->more_proc
= FALSE
;
2071 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,BOARD_INFO
,
2072 INVALID_CHANNEL
,sizeof(gdth_binfo_str
))) {
2073 memcpy(&ha
->binfo
, (gdth_binfo_str
*)ha
->pscratch
,
2074 sizeof(gdth_binfo_str
));
2075 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,BOARD_FEATURES
,
2076 INVALID_CHANNEL
,sizeof(gdth_bfeat_str
))) {
2077 TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n"));
2078 ha
->bfeat
= *(gdth_bfeat_str
*)ha
->pscratch
;
2079 ha
->more_proc
= TRUE
;
2082 TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n"));
2083 strcpy(ha
->binfo
.type_string
, gdth_ctr_name(hanum
));
2085 TRACE2(("Controller name: %s\n",ha
->binfo
.type_string
));
2087 /* read more informations */
2088 if (ha
->more_proc
) {
2089 /* physical drives, channel addresses */
2090 ioc
= (gdth_iochan_str
*)ha
->pscratch
;
2091 ioc
->hdr
.version
= 0xffffffff;
2092 ioc
->hdr
.list_entries
= MAXBUS
;
2093 ioc
->hdr
.first_chan
= 0;
2094 ioc
->hdr
.last_chan
= MAXBUS
-1;
2095 ioc
->hdr
.list_offset
= GDTOFFSOF(gdth_iochan_str
, list
[0]);
2096 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,IOCHAN_DESC
,
2097 INVALID_CHANNEL
,sizeof(gdth_iochan_str
))) {
2098 for (bus_no
= 0; bus_no
< ha
->bus_cnt
; ++bus_no
) {
2099 ha
->raw
[bus_no
].address
= ioc
->list
[bus_no
].address
;
2100 ha
->raw
[bus_no
].local_no
= ioc
->list
[bus_no
].local_no
;
2103 for (bus_no
= 0; bus_no
< ha
->bus_cnt
; ++bus_no
) {
2104 ha
->raw
[bus_no
].address
= IO_CHANNEL
;
2105 ha
->raw
[bus_no
].local_no
= bus_no
;
2108 for (bus_no
= 0; bus_no
< ha
->bus_cnt
; ++bus_no
) {
2109 chn
= (gdth_getch_str
*)ha
->pscratch
;
2110 chn
->channel_no
= ha
->raw
[bus_no
].local_no
;
2111 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,
2112 SCSI_CHAN_CNT
| L_CTRL_PATTERN
,
2113 ha
->raw
[bus_no
].address
| INVALID_CHANNEL
,
2114 sizeof(gdth_getch_str
))) {
2115 ha
->raw
[bus_no
].pdev_cnt
= chn
->drive_cnt
;
2116 TRACE2(("Channel %d: %d phys. drives\n",
2117 bus_no
,chn
->drive_cnt
));
2119 if (ha
->raw
[bus_no
].pdev_cnt
> 0) {
2120 drl
= (gdth_drlist_str
*)ha
->pscratch
;
2121 drl
->sc_no
= ha
->raw
[bus_no
].local_no
;
2122 drl
->sc_cnt
= ha
->raw
[bus_no
].pdev_cnt
;
2123 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,
2124 SCSI_DR_LIST
| L_CTRL_PATTERN
,
2125 ha
->raw
[bus_no
].address
| INVALID_CHANNEL
,
2126 sizeof(gdth_drlist_str
))) {
2127 for (j
= 0; j
< ha
->raw
[bus_no
].pdev_cnt
; ++j
)
2128 ha
->raw
[bus_no
].id_list
[j
] = drl
->sc_list
[j
];
2130 ha
->raw
[bus_no
].pdev_cnt
= 0;
2135 /* logical drives */
2136 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,CACHE_DRV_CNT
,
2137 INVALID_CHANNEL
,sizeof(ulong32
))) {
2138 drv_cnt
= *(ulong32
*)ha
->pscratch
;
2139 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,CACHE_DRV_LIST
,
2140 INVALID_CHANNEL
,drv_cnt
* sizeof(ulong32
))) {
2141 for (j
= 0; j
< drv_cnt
; ++j
) {
2142 drv_no
= ((ulong32
*)ha
->pscratch
)[j
];
2143 if (drv_no
< MAX_LDRIVES
) {
2144 ha
->hdr
[drv_no
].is_logdrv
= TRUE
;
2145 TRACE2(("Drive %d is log. drive\n",drv_no
));
2149 alst
= (gdth_arcdl_str
*)ha
->pscratch
;
2150 alst
->entries_avail
= MAX_LDRIVES
;
2151 alst
->first_entry
= 0;
2152 alst
->list_offset
= GDTOFFSOF(gdth_arcdl_str
, list
[0]);
2153 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,
2154 ARRAY_DRV_LIST2
| LA_CTRL_PATTERN
,
2155 INVALID_CHANNEL
, sizeof(gdth_arcdl_str
) +
2156 (alst
->entries_avail
-1) * sizeof(gdth_alist_str
))) {
2157 for (j
= 0; j
< alst
->entries_init
; ++j
) {
2158 ha
->hdr
[j
].is_arraydrv
= alst
->list
[j
].is_arrayd
;
2159 ha
->hdr
[j
].is_master
= alst
->list
[j
].is_master
;
2160 ha
->hdr
[j
].is_parity
= alst
->list
[j
].is_parity
;
2161 ha
->hdr
[j
].is_hotfix
= alst
->list
[j
].is_hotfix
;
2162 ha
->hdr
[j
].master_no
= alst
->list
[j
].cd_handle
;
2164 } else if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,
2165 ARRAY_DRV_LIST
| LA_CTRL_PATTERN
,
2166 0, 35 * sizeof(gdth_alist_str
))) {
2167 for (j
= 0; j
< 35; ++j
) {
2168 alst2
= &((gdth_alist_str
*)ha
->pscratch
)[j
];
2169 ha
->hdr
[j
].is_arraydrv
= alst2
->is_arrayd
;
2170 ha
->hdr
[j
].is_master
= alst2
->is_master
;
2171 ha
->hdr
[j
].is_parity
= alst2
->is_parity
;
2172 ha
->hdr
[j
].is_hotfix
= alst2
->is_hotfix
;
2173 ha
->hdr
[j
].master_no
= alst2
->cd_handle
;
2179 /* initialize raw service */
2182 ok
= gdth_internal_cmd(hanum
,SCSIRAWSERVICE
,GDT_X_INIT_RAW
,0,0,0);
2184 ha
->raw_feat
= GDT_64BIT
;
2186 if (force_dma32
|| (!ok
&& ha
->status
== (ushort
)S_NOFUNC
))
2187 ok
= gdth_internal_cmd(hanum
,SCSIRAWSERVICE
,GDT_INIT
,0,0,0);
2189 printk("GDT-HA %d: Initialization error raw service (code %d)\n",
2193 TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n"));
2195 /* set/get features raw service (scatter/gather) */
2196 if (gdth_internal_cmd(hanum
,SCSIRAWSERVICE
,GDT_SET_FEAT
,SCATTER_GATHER
,
2198 TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
2199 if (gdth_internal_cmd(hanum
,SCSIRAWSERVICE
,GDT_GET_FEAT
,0,0,0)) {
2200 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
2202 ha
->raw_feat
|= (ushort
)ha
->info
;
2206 /* set/get features cache service (equal to raw service) */
2207 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_SET_FEAT
,0,
2208 SCATTER_GATHER
,0)) {
2209 TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
2210 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_GET_FEAT
,0,0,0)) {
2211 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
2213 ha
->cache_feat
|= (ushort
)ha
->info
;
2217 /* reserve drives for raw service */
2218 if (reserve_mode
!= 0) {
2219 gdth_internal_cmd(hanum
,SCSIRAWSERVICE
,GDT_RESERVE_ALL
,
2220 reserve_mode
== 1 ? 1 : 3, 0, 0);
2221 TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n",
2224 for (i
= 0; i
< MAX_RES_ARGS
; i
+= 4) {
2225 if (reserve_list
[i
] == hanum
&& reserve_list
[i
+1] < ha
->bus_cnt
&&
2226 reserve_list
[i
+2] < ha
->tid_cnt
&& reserve_list
[i
+3] < MAXLUN
) {
2227 TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
2228 reserve_list
[i
], reserve_list
[i
+1],
2229 reserve_list
[i
+2], reserve_list
[i
+3]));
2230 if (!gdth_internal_cmd(hanum
,SCSIRAWSERVICE
,GDT_RESERVE
,0,
2231 reserve_list
[i
+1], reserve_list
[i
+2] |
2232 (reserve_list
[i
+3] << 8))) {
2233 printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n",
2239 /* Determine OEM string using IOCTL */
2240 oemstr
= (gdth_oem_str_ioctl
*)ha
->pscratch
;
2241 oemstr
->params
.ctl_version
= 0x01;
2242 oemstr
->params
.buffer_size
= sizeof(oemstr
->text
);
2243 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_IOCTL
,
2244 CACHE_READ_OEM_STRING_RECORD
,INVALID_CHANNEL
,
2245 sizeof(gdth_oem_str_ioctl
))) {
2246 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n"));
2247 printk("GDT-HA %d: Vendor: %s Name: %s\n",
2248 hanum
,oemstr
->text
.oem_company_name
,ha
->binfo
.type_string
);
2249 /* Save the Host Drive inquiry data */
2250 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2251 strlcpy(ha
->oem_name
,oemstr
->text
.scsi_host_drive_inquiry_vendor_id
,
2252 sizeof(ha
->oem_name
));
2254 strncpy(ha
->oem_name
,oemstr
->text
.scsi_host_drive_inquiry_vendor_id
,7);
2255 ha
->oem_name
[7] = '\0';
2258 /* Old method, based on PCI ID */
2259 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
2260 printk("GDT-HA %d: Name: %s\n",
2261 hanum
,ha
->binfo
.type_string
);
2262 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2263 if (ha
->oem_id
== OEM_ID_INTEL
)
2264 strlcpy(ha
->oem_name
,"Intel ", sizeof(ha
->oem_name
));
2266 strlcpy(ha
->oem_name
,"ICP ", sizeof(ha
->oem_name
));
2268 if (ha
->oem_id
== OEM_ID_INTEL
)
2269 strcpy(ha
->oem_name
,"Intel ");
2271 strcpy(ha
->oem_name
,"ICP ");
2275 /* scanning for host drives */
2276 for (i
= 0; i
< cdev_cnt
; ++i
)
2277 gdth_analyse_hdrive(hanum
,i
);
2279 TRACE(("gdth_search_drives() OK\n"));
2283 static int gdth_analyse_hdrive(int hanum
,ushort hdrive
)
2285 register gdth_ha_str
*ha
;
2287 int drv_hds
, drv_secs
;
2289 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n",hanum
,hdrive
));
2290 if (hdrive
>= MAX_HDRIVES
)
2292 ha
= HADATA(gdth_ctr_tab
[hanum
]);
2294 if (!gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_INFO
,hdrive
,0,0))
2296 ha
->hdr
[hdrive
].present
= TRUE
;
2297 ha
->hdr
[hdrive
].size
= ha
->info
;
2299 /* evaluate mapping (sectors per head, heads per cylinder) */
2300 ha
->hdr
[hdrive
].size
&= ~SECS32
;
2301 if (ha
->info2
== 0) {
2302 gdth_eval_mapping(ha
->hdr
[hdrive
].size
,&drv_cyls
,&drv_hds
,&drv_secs
);
2304 drv_hds
= ha
->info2
& 0xff;
2305 drv_secs
= (ha
->info2
>> 8) & 0xff;
2306 drv_cyls
= (ulong32
)ha
->hdr
[hdrive
].size
/ drv_hds
/ drv_secs
;
2308 ha
->hdr
[hdrive
].heads
= (unchar
)drv_hds
;
2309 ha
->hdr
[hdrive
].secs
= (unchar
)drv_secs
;
2311 ha
->hdr
[hdrive
].size
= drv_cyls
* drv_hds
* drv_secs
;
2313 if (ha
->cache_feat
& GDT_64BIT
) {
2314 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_X_INFO
,hdrive
,0,0)
2315 && ha
->info2
!= 0) {
2316 ha
->hdr
[hdrive
].size
= ((ulong64
)ha
->info2
<< 32) | ha
->info
;
2319 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
2320 hdrive
,ha
->hdr
[hdrive
].size
,drv_hds
,drv_secs
));
2322 /* get informations about device */
2323 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_DEVTYPE
,hdrive
,0,0)) {
2324 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
2326 ha
->hdr
[hdrive
].devtype
= (ushort
)ha
->info
;
2330 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_CLUST_INFO
,hdrive
,0,0)) {
2331 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
2334 ha
->hdr
[hdrive
].cluster_type
= (unchar
)ha
->info
;
2337 /* R/W attributes */
2338 if (gdth_internal_cmd(hanum
,CACHESERVICE
,GDT_RW_ATTRIBS
,hdrive
,0,0)) {
2339 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
2341 ha
->hdr
[hdrive
].rw_attribs
= (unchar
)ha
->info
;
2348 /* command queueing/sending functions */
2350 static void gdth_putq(int hanum
,Scsi_Cmnd
*scp
,unchar priority
)
2352 register gdth_ha_str
*ha
;
2353 register Scsi_Cmnd
*pscp
;
2354 register Scsi_Cmnd
*nscp
;
2358 TRACE(("gdth_putq() priority %d\n",priority
));
2359 ha
= HADATA(gdth_ctr_tab
[hanum
]);
2360 GDTH_LOCK_HA(ha
, flags
);
2362 scp
->SCp
.this_residual
= (int)priority
;
2363 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2364 b
= virt_ctr
? NUMDATA(scp
->device
->host
)->busnum
: scp
->device
->channel
;
2365 t
= scp
->device
->id
;
2367 b
= virt_ctr
? NUMDATA(scp
->host
)->busnum
: scp
->channel
;
2370 if (priority
>= DEFAULT_PRI
) {
2371 if ((b
!= ha
->virt_bus
&& ha
->raw
[BUS_L2P(ha
,b
)].lock
) ||
2372 (b
== ha
->virt_bus
&& t
< MAX_HDRIVES
&& ha
->hdr
[t
].lock
)) {
2373 TRACE2(("gdth_putq(): locked IO -> update_timeout()\n"));
2374 scp
->SCp
.buffers_residual
= gdth_update_timeout(hanum
, scp
, 0);
2378 if (ha
->req_first
==NULL
) {
2379 ha
->req_first
= scp
; /* queue was empty */
2380 scp
->SCp
.ptr
= NULL
;
2381 } else { /* queue not empty */
2382 pscp
= ha
->req_first
;
2383 nscp
= (Scsi_Cmnd
*)pscp
->SCp
.ptr
;
2384 /* priority: 0-highest,..,0xff-lowest */
2385 while (nscp
&& (unchar
)nscp
->SCp
.this_residual
<= priority
) {
2387 nscp
= (Scsi_Cmnd
*)pscp
->SCp
.ptr
;
2389 pscp
->SCp
.ptr
= (char *)scp
;
2390 scp
->SCp
.ptr
= (char *)nscp
;
2392 GDTH_UNLOCK_HA(ha
, flags
);
2394 #ifdef GDTH_STATISTICS
2396 for (nscp
=ha
->req_first
; nscp
; nscp
=(Scsi_Cmnd
*)nscp
->SCp
.ptr
)
2398 if (max_rq
< flags
) {
2400 TRACE3(("GDT: max_rq = %d\n",(ushort
)max_rq
));
2405 static void gdth_next(int hanum
)
2407 register gdth_ha_str
*ha
;
2408 register Scsi_Cmnd
*pscp
;
2409 register Scsi_Cmnd
*nscp
;
2410 unchar b
, t
, l
, firsttime
;
2411 unchar this_cmd
, next_cmd
;
2415 TRACE(("gdth_next() hanum %d\n",hanum
));
2416 ha
= HADATA(gdth_ctr_tab
[hanum
]);
2418 GDTH_LOCK_HA(ha
, flags
);
2420 ha
->cmd_cnt
= ha
->cmd_offs_dpmem
= 0;
2421 this_cmd
= firsttime
= TRUE
;
2422 next_cmd
= gdth_polling
? FALSE
:TRUE
;
2425 for (nscp
= pscp
= ha
->req_first
; nscp
; nscp
= (Scsi_Cmnd
*)nscp
->SCp
.ptr
) {
2426 if (nscp
!= pscp
&& nscp
!= (Scsi_Cmnd
*)pscp
->SCp
.ptr
)
2427 pscp
= (Scsi_Cmnd
*)pscp
->SCp
.ptr
;
2428 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2429 b
= virt_ctr
? NUMDATA(nscp
->device
->host
)->busnum
: nscp
->device
->channel
;
2430 t
= nscp
->device
->id
;
2431 l
= nscp
->device
->lun
;
2433 b
= virt_ctr
? NUMDATA(nscp
->host
)->busnum
: nscp
->channel
;
2437 if (nscp
->SCp
.this_residual
>= DEFAULT_PRI
) {
2438 if ((b
!= ha
->virt_bus
&& ha
->raw
[BUS_L2P(ha
,b
)].lock
) ||
2439 (b
== ha
->virt_bus
&& t
< MAX_HDRIVES
&& ha
->hdr
[t
].lock
))
2444 if (gdth_test_busy(hanum
)) { /* controller busy ? */
2445 TRACE(("gdth_next() controller %d busy !\n",hanum
));
2446 if (!gdth_polling
) {
2447 GDTH_UNLOCK_HA(ha
, flags
);
2450 while (gdth_test_busy(hanum
))
2456 if (nscp
->done
!= gdth_scsi_done
|| nscp
->cmnd
[0] != 0xff) {
2457 if (nscp
->SCp
.phase
== -1) {
2458 nscp
->SCp
.phase
= CACHESERVICE
; /* default: cache svc. */
2459 if (nscp
->cmnd
[0] == TEST_UNIT_READY
) {
2460 TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
2462 /* TEST_UNIT_READY -> set scan mode */
2463 if ((ha
->scan_mode
& 0x0f) == 0) {
2464 if (b
== 0 && t
== 0 && l
== 0) {
2466 TRACE2(("Scan mode: 0x%x\n", ha
->scan_mode
));
2468 } else if ((ha
->scan_mode
& 0x0f) == 1) {
2469 if (b
== 0 && ((t
== 0 && l
== 1) ||
2470 (t
== 1 && l
== 0))) {
2471 nscp
->SCp
.sent_command
= GDT_SCAN_START
;
2472 nscp
->SCp
.phase
= ((ha
->scan_mode
& 0x10 ? 1:0) << 8)
2474 ha
->scan_mode
= 0x12;
2475 TRACE2(("Scan mode: 0x%x (SCAN_START)\n",
2478 ha
->scan_mode
&= 0x10;
2479 TRACE2(("Scan mode: 0x%x\n", ha
->scan_mode
));
2481 } else if (ha
->scan_mode
== 0x12) {
2482 if (b
== ha
->bus_cnt
&& t
== ha
->tid_cnt
-1) {
2483 nscp
->SCp
.phase
= SCSIRAWSERVICE
;
2484 nscp
->SCp
.sent_command
= GDT_SCAN_END
;
2485 ha
->scan_mode
&= 0x10;
2486 TRACE2(("Scan mode: 0x%x (SCAN_END)\n",
2491 if (b
== ha
->virt_bus
&& nscp
->cmnd
[0] != INQUIRY
&&
2492 nscp
->cmnd
[0] != READ_CAPACITY
&& nscp
->cmnd
[0] != MODE_SENSE
&&
2493 (ha
->hdr
[t
].cluster_type
& CLUSTER_DRIVE
)) {
2494 /* always GDT_CLUST_INFO! */
2495 nscp
->SCp
.sent_command
= GDT_CLUST_INFO
;
2500 if (nscp
->SCp
.sent_command
!= -1) {
2501 if ((nscp
->SCp
.phase
& 0xff) == CACHESERVICE
) {
2502 if (!(cmd_index
=gdth_fill_cache_cmd(hanum
,nscp
,t
)))
2505 } else if ((nscp
->SCp
.phase
& 0xff) == SCSIRAWSERVICE
) {
2506 if (!(cmd_index
=gdth_fill_raw_cmd(hanum
,nscp
,BUS_L2P(ha
,b
))))
2510 memset((char*)nscp
->sense_buffer
,0,16);
2511 nscp
->sense_buffer
[0] = 0x70;
2512 nscp
->sense_buffer
[2] = NOT_READY
;
2513 nscp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
2514 if (!nscp
->SCp
.have_data_in
)
2515 nscp
->SCp
.have_data_in
++;
2518 GDTH_UNLOCK_HA(ha
,flags
);
2519 /* io_request_lock already active ! */
2520 nscp
->scsi_done(nscp
);
2522 GDTH_LOCK_HA(ha
,flags
);
2525 } else if (nscp
->done
== gdth_scsi_done
&& nscp
->cmnd
[0] == 0xff) {
2526 if (!(cmd_index
=gdth_special_cmd(hanum
,nscp
)))
2529 } else if (b
!= ha
->virt_bus
) {
2530 if (ha
->raw
[BUS_L2P(ha
,b
)].io_cnt
[t
] >= GDTH_MAX_RAW
||
2531 !(cmd_index
=gdth_fill_raw_cmd(hanum
,nscp
,BUS_L2P(ha
,b
))))
2534 ha
->raw
[BUS_L2P(ha
,b
)].io_cnt
[t
]++;
2535 } else if (t
>= MAX_HDRIVES
|| !ha
->hdr
[t
].present
|| l
!= 0) {
2536 TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
2537 nscp
->cmnd
[0], b
, t
, l
));
2538 nscp
->result
= DID_BAD_TARGET
<< 16;
2539 if (!nscp
->SCp
.have_data_in
)
2540 nscp
->SCp
.have_data_in
++;
2543 GDTH_UNLOCK_HA(ha
,flags
);
2544 /* io_request_lock already active ! */
2545 nscp
->scsi_done(nscp
);
2547 GDTH_LOCK_HA(ha
,flags
);
2550 switch (nscp
->cmnd
[0]) {
2551 case TEST_UNIT_READY
:
2558 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2559 case SERVICE_ACTION_IN
:
2561 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp
->cmnd
[0],
2562 nscp
->cmnd
[1],nscp
->cmnd
[2],nscp
->cmnd
[3],
2563 nscp
->cmnd
[4],nscp
->cmnd
[5]));
2564 if (ha
->hdr
[t
].media_changed
&& nscp
->cmnd
[0] != INQUIRY
) {
2565 /* return UNIT_ATTENTION */
2566 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2568 ha
->hdr
[t
].media_changed
= FALSE
;
2569 memset((char*)nscp
->sense_buffer
,0,16);
2570 nscp
->sense_buffer
[0] = 0x70;
2571 nscp
->sense_buffer
[2] = UNIT_ATTENTION
;
2572 nscp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
2573 if (!nscp
->SCp
.have_data_in
)
2574 nscp
->SCp
.have_data_in
++;
2577 GDTH_UNLOCK_HA(ha
,flags
);
2578 /* io_request_lock already active ! */
2579 nscp
->scsi_done(nscp
);
2581 GDTH_LOCK_HA(ha
,flags
);
2583 } else if (gdth_internal_cache_cmd(hanum
,nscp
)) {
2585 GDTH_UNLOCK_HA(ha
,flags
);
2586 /* io_request_lock already active ! */
2587 nscp
->scsi_done(nscp
);
2589 GDTH_LOCK_HA(ha
,flags
);
2593 case ALLOW_MEDIUM_REMOVAL
:
2594 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp
->cmnd
[0],
2595 nscp
->cmnd
[1],nscp
->cmnd
[2],nscp
->cmnd
[3],
2596 nscp
->cmnd
[4],nscp
->cmnd
[5]));
2597 if ( (nscp
->cmnd
[4]&1) && !(ha
->hdr
[t
].devtype
&1) ) {
2598 TRACE(("Prevent r. nonremov. drive->do nothing\n"));
2599 nscp
->result
= DID_OK
<< 16;
2600 nscp
->sense_buffer
[0] = 0;
2601 if (!nscp
->SCp
.have_data_in
)
2602 nscp
->SCp
.have_data_in
++;
2605 GDTH_UNLOCK_HA(ha
,flags
);
2606 /* io_request_lock already active ! */
2607 nscp
->scsi_done(nscp
);
2609 GDTH_LOCK_HA(ha
,flags
);
2612 nscp
->cmnd
[3] = (ha
->hdr
[t
].devtype
&1) ? 1:0;
2613 TRACE(("Prevent/allow r. %d rem. drive %d\n",
2614 nscp
->cmnd
[4],nscp
->cmnd
[3]));
2615 if (!(cmd_index
=gdth_fill_cache_cmd(hanum
,nscp
,t
)))
2622 TRACE2(("cache cmd %s\n",nscp
->cmnd
[0] == RESERVE
?
2623 "RESERVE" : "RELEASE"));
2624 if (!(cmd_index
=gdth_fill_cache_cmd(hanum
,nscp
,t
)))
2632 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2636 if (ha
->hdr
[t
].media_changed
) {
2637 /* return UNIT_ATTENTION */
2638 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2640 ha
->hdr
[t
].media_changed
= FALSE
;
2641 memset((char*)nscp
->sense_buffer
,0,16);
2642 nscp
->sense_buffer
[0] = 0x70;
2643 nscp
->sense_buffer
[2] = UNIT_ATTENTION
;
2644 nscp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
2645 if (!nscp
->SCp
.have_data_in
)
2646 nscp
->SCp
.have_data_in
++;
2649 GDTH_UNLOCK_HA(ha
,flags
);
2650 /* io_request_lock already active ! */
2651 nscp
->scsi_done(nscp
);
2653 GDTH_LOCK_HA(ha
,flags
);
2655 } else if (!(cmd_index
=gdth_fill_cache_cmd(hanum
,nscp
,t
)))
2660 TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp
->cmnd
[0],
2661 nscp
->cmnd
[1],nscp
->cmnd
[2],nscp
->cmnd
[3],
2662 nscp
->cmnd
[4],nscp
->cmnd
[5]));
2663 printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n",
2664 hanum
, nscp
->cmnd
[0]);
2665 nscp
->result
= DID_ABORT
<< 16;
2666 if (!nscp
->SCp
.have_data_in
)
2667 nscp
->SCp
.have_data_in
++;
2670 GDTH_UNLOCK_HA(ha
,flags
);
2671 /* io_request_lock already active ! */
2672 nscp
->scsi_done(nscp
);
2674 GDTH_LOCK_HA(ha
,flags
);
2682 if (nscp
== ha
->req_first
)
2683 ha
->req_first
= pscp
= (Scsi_Cmnd
*)nscp
->SCp
.ptr
;
2685 pscp
->SCp
.ptr
= nscp
->SCp
.ptr
;
2690 if (ha
->cmd_cnt
> 0) {
2691 gdth_release_event(hanum
);
2695 GDTH_UNLOCK_HA(ha
, flags
);
2697 if (gdth_polling
&& ha
->cmd_cnt
> 0) {
2698 if (!gdth_wait(hanum
,cmd_index
,POLL_TIMEOUT
))
2699 printk("GDT-HA %d: Command %d timed out !\n",
2704 static void gdth_copy_internal_data(int hanum
,Scsi_Cmnd
*scp
,
2705 char *buffer
,ushort count
)
2709 struct scatterlist
*sl
;
2714 cpcount
= count
<=(ushort
)scp
->bufflen
? count
:(ushort
)scp
->bufflen
;
2715 ha
= HADATA(gdth_ctr_tab
[hanum
]);
2718 sl
= (struct scatterlist
*)scp
->request_buffer
;
2719 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
2720 sgcnt
= pci_map_sg(ha
->pdev
,sl
,scp
->use_sg
,PCI_DMA_FROMDEVICE
);
2721 for (i
=0,cpsum
=0; i
<sgcnt
; ++i
,++sl
) {
2722 cpnow
= (ushort
)sg_dma_len(sl
);
2723 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2724 cpnow
,cpsum
,cpcount
,(ushort
)scp
->bufflen
));
2725 if (cpsum
+cpnow
> cpcount
)
2726 cpnow
= cpcount
- cpsum
;
2729 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
2733 address
= (char *)(page_address(sl
->page
) + sl
->offset
);
2734 memcpy(address
,buffer
,cpnow
);
2735 if (cpsum
== cpcount
)
2739 pci_unmap_sg(ha
->pdev
,scp
->request_buffer
,
2740 scp
->use_sg
,PCI_DMA_FROMDEVICE
);
2742 sgcnt
= scp
->use_sg
;
2743 for (i
=0,cpsum
=0; i
<sgcnt
; ++i
,++sl
) {
2744 cpnow
= (ushort
)sl
->length
;
2745 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2746 cpnow
,cpsum
,cpcount
,(ushort
)scp
->bufflen
));
2747 if (cpsum
+cpnow
> cpcount
)
2748 cpnow
= cpcount
- cpsum
;
2750 address
= (char *)sl
->address
;
2751 memcpy(address
,buffer
,cpnow
);
2752 if (cpsum
== cpcount
)
2758 TRACE(("copy_internal() count %d\n",cpcount
));
2759 memcpy((char*)scp
->request_buffer
,buffer
,cpcount
);
2763 static int gdth_internal_cache_cmd(int hanum
,Scsi_Cmnd
*scp
)
2765 register gdth_ha_str
*ha
;
2768 gdth_rdcap_data rdc
;
2770 gdth_modep_data mpd
;
2772 ha
= HADATA(gdth_ctr_tab
[hanum
]);
2773 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2774 t
= scp
->device
->id
;
2778 TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
2781 scp
->result
= DID_OK
<< 16;
2782 scp
->sense_buffer
[0] = 0;
2784 switch (scp
->cmnd
[0]) {
2785 case TEST_UNIT_READY
:
2788 TRACE2(("Test/Verify/Start hdrive %d\n",t
));
2792 TRACE2(("Inquiry hdrive %d devtype %d\n",
2793 t
,ha
->hdr
[t
].devtype
));
2794 inq
.type_qual
= (ha
->hdr
[t
].devtype
&4) ? TYPE_ROM
:TYPE_DISK
;
2795 /* you can here set all disks to removable, if you want to do
2796 a flush using the ALLOW_MEDIUM_REMOVAL command */
2797 inq
.modif_rmb
= 0x00;
2798 if ((ha
->hdr
[t
].devtype
& 1) ||
2799 (ha
->hdr
[t
].cluster_type
& CLUSTER_DRIVE
))
2800 inq
.modif_rmb
= 0x80;
2804 strcpy(inq
.vendor
,ha
->oem_name
);
2805 sprintf(inq
.product
,"Host Drive #%02d",t
);
2806 strcpy(inq
.revision
," ");
2807 gdth_copy_internal_data(hanum
,scp
,(char*)&inq
,sizeof(gdth_inq_data
));
2811 TRACE2(("Request sense hdrive %d\n",t
));
2812 sd
.errorcode
= 0x70;
2817 gdth_copy_internal_data(hanum
,scp
,(char*)&sd
,sizeof(gdth_sense_data
));
2821 TRACE2(("Mode sense hdrive %d\n",t
));
2822 memset((char*)&mpd
,0,sizeof(gdth_modep_data
));
2823 mpd
.hd
.data_length
= sizeof(gdth_modep_data
);
2824 mpd
.hd
.dev_par
= (ha
->hdr
[t
].devtype
&2) ? 0x80:0;
2825 mpd
.hd
.bd_length
= sizeof(mpd
.bd
);
2826 mpd
.bd
.block_length
[0] = (SECTOR_SIZE
& 0x00ff0000) >> 16;
2827 mpd
.bd
.block_length
[1] = (SECTOR_SIZE
& 0x0000ff00) >> 8;
2828 mpd
.bd
.block_length
[2] = (SECTOR_SIZE
& 0x000000ff);
2829 gdth_copy_internal_data(hanum
,scp
,(char*)&mpd
,sizeof(gdth_modep_data
));
2833 TRACE2(("Read capacity hdrive %d\n",t
));
2834 if (ha
->hdr
[t
].size
> (ulong64
)0xffffffff)
2835 rdc
.last_block_no
= 0xffffffff;
2837 rdc
.last_block_no
= cpu_to_be32(ha
->hdr
[t
].size
-1);
2838 rdc
.block_length
= cpu_to_be32(SECTOR_SIZE
);
2839 gdth_copy_internal_data(hanum
,scp
,(char*)&rdc
,sizeof(gdth_rdcap_data
));
2842 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2843 case SERVICE_ACTION_IN
:
2844 if ((scp
->cmnd
[1] & 0x1f) == SAI_READ_CAPACITY_16
&&
2845 (ha
->cache_feat
& GDT_64BIT
)) {
2846 gdth_rdcap16_data rdc16
;
2848 TRACE2(("Read capacity (16) hdrive %d\n",t
));
2849 rdc16
.last_block_no
= cpu_to_be64(ha
->hdr
[t
].size
-1);
2850 rdc16
.block_length
= cpu_to_be32(SECTOR_SIZE
);
2851 gdth_copy_internal_data(hanum
,scp
,(char*)&rdc16
,sizeof(gdth_rdcap16_data
));
2853 scp
->result
= DID_ABORT
<< 16;
2859 TRACE2(("Internal cache cmd 0x%x unknown\n",scp
->cmnd
[0]));
2863 if (!scp
->SCp
.have_data_in
)
2864 scp
->SCp
.have_data_in
++;
2871 static int gdth_fill_cache_cmd(int hanum
,Scsi_Cmnd
*scp
,ushort hdrive
)
2873 register gdth_ha_str
*ha
;
2874 register gdth_cmd_str
*cmdp
;
2875 struct scatterlist
*sl
;
2876 ulong32 cnt
, blockcnt
;
2877 ulong64 no
, blockno
;
2878 dma_addr_t phys_addr
;
2879 int i
, cmd_index
, read_write
, sgcnt
, mode64
;
2880 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
2885 ha
= HADATA(gdth_ctr_tab
[hanum
]);
2887 TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
2888 scp
->cmnd
[0],scp
->cmd_len
,hdrive
));
2890 if (ha
->type
==GDT_EISA
&& ha
->cmd_cnt
>0)
2893 mode64
= (ha
->cache_feat
& GDT_64BIT
) ? TRUE
: FALSE
;
2894 /* test for READ_16, WRITE_16 if !mode64 ? ---
2895 not required, should not occur due to error return on
2898 cmdp
->Service
= CACHESERVICE
;
2899 cmdp
->RequestBuffer
= scp
;
2900 /* search free command index */
2901 if (!(cmd_index
=gdth_get_cmd_index(hanum
))) {
2902 TRACE(("GDT: No free command index found\n"));
2905 /* if it's the first command, set command semaphore */
2906 if (ha
->cmd_cnt
== 0)
2907 gdth_set_sema0(hanum
);
2911 if (scp
->SCp
.sent_command
!= -1)
2912 cmdp
->OpCode
= scp
->SCp
.sent_command
; /* special cache cmd. */
2913 else if (scp
->cmnd
[0] == RESERVE
)
2914 cmdp
->OpCode
= GDT_RESERVE_DRV
;
2915 else if (scp
->cmnd
[0] == RELEASE
)
2916 cmdp
->OpCode
= GDT_RELEASE_DRV
;
2917 else if (scp
->cmnd
[0] == ALLOW_MEDIUM_REMOVAL
) {
2918 if (scp
->cmnd
[4] & 1) /* prevent ? */
2919 cmdp
->OpCode
= GDT_MOUNT
;
2920 else if (scp
->cmnd
[3] & 1) /* removable drive ? */
2921 cmdp
->OpCode
= GDT_UNMOUNT
;
2923 cmdp
->OpCode
= GDT_FLUSH
;
2924 } else if (scp
->cmnd
[0] == WRITE_6
|| scp
->cmnd
[0] == WRITE_10
||
2925 scp
->cmnd
[0] == WRITE_12
2926 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2927 || scp
->cmnd
[0] == WRITE_16
2931 if (gdth_write_through
|| ((ha
->hdr
[hdrive
].rw_attribs
& 1) &&
2932 (ha
->cache_feat
& GDT_WR_THROUGH
)))
2933 cmdp
->OpCode
= GDT_WRITE_THR
;
2935 cmdp
->OpCode
= GDT_WRITE
;
2938 cmdp
->OpCode
= GDT_READ
;
2941 cmdp
->BoardNode
= LOCALBOARD
;
2943 cmdp
->u
.cache64
.DeviceNo
= hdrive
;
2944 cmdp
->u
.cache64
.BlockNo
= 1;
2945 cmdp
->u
.cache64
.sg_canz
= 0;
2947 cmdp
->u
.cache
.DeviceNo
= hdrive
;
2948 cmdp
->u
.cache
.BlockNo
= 1;
2949 cmdp
->u
.cache
.sg_canz
= 0;
2953 if (scp
->cmd_len
== 16) {
2954 memcpy(&no
, &scp
->cmnd
[2], sizeof(ulong64
));
2955 blockno
= be64_to_cpu(no
);
2956 memcpy(&cnt
, &scp
->cmnd
[10], sizeof(ulong32
));
2957 blockcnt
= be32_to_cpu(cnt
);
2958 } else if (scp
->cmd_len
== 10) {
2959 memcpy(&no
, &scp
->cmnd
[2], sizeof(ulong32
));
2960 blockno
= be32_to_cpu(no
);
2961 memcpy(&cnt
, &scp
->cmnd
[7], sizeof(ushort
));
2962 blockcnt
= be16_to_cpu(cnt
);
2964 memcpy(&no
, &scp
->cmnd
[0], sizeof(ulong32
));
2965 blockno
= be32_to_cpu(no
) & 0x001fffffUL
;
2966 blockcnt
= scp
->cmnd
[4]==0 ? 0x100 : scp
->cmnd
[4];
2969 cmdp
->u
.cache64
.BlockNo
= blockno
;
2970 cmdp
->u
.cache64
.BlockCnt
= blockcnt
;
2972 cmdp
->u
.cache
.BlockNo
= (ulong32
)blockno
;
2973 cmdp
->u
.cache
.BlockCnt
= blockcnt
;
2977 sl
= (struct scatterlist
*)scp
->request_buffer
;
2978 sgcnt
= scp
->use_sg
;
2979 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
2980 scp
->SCp
.Status
= GDTH_MAP_SG
;
2981 scp
->SCp
.Message
= (read_write
== 1 ?
2982 PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
);
2983 sgcnt
= pci_map_sg(ha
->pdev
,sl
,scp
->use_sg
,scp
->SCp
.Message
);
2985 cmdp
->u
.cache64
.DestAddr
= (ulong64
)-1;
2986 cmdp
->u
.cache64
.sg_canz
= sgcnt
;
2987 for (i
=0; i
<sgcnt
; ++i
,++sl
) {
2988 cmdp
->u
.cache64
.sg_lst
[i
].sg_ptr
= sg_dma_address(sl
);
2989 #ifdef GDTH_DMA_STATISTICS
2990 if (cmdp
->u
.cache64
.sg_lst
[i
].sg_ptr
> (ulong64
)0xffffffff)
2995 cmdp
->u
.cache64
.sg_lst
[i
].sg_len
= sg_dma_len(sl
);
2998 cmdp
->u
.cache
.DestAddr
= 0xffffffff;
2999 cmdp
->u
.cache
.sg_canz
= sgcnt
;
3000 for (i
=0; i
<sgcnt
; ++i
,++sl
) {
3001 cmdp
->u
.cache
.sg_lst
[i
].sg_ptr
= sg_dma_address(sl
);
3002 #ifdef GDTH_DMA_STATISTICS
3005 cmdp
->u
.cache
.sg_lst
[i
].sg_len
= sg_dma_len(sl
);
3010 cmdp
->u
.cache64
.DestAddr
= (ulong64
)-1;
3011 cmdp
->u
.cache64
.sg_canz
= sgcnt
;
3012 for (i
=0; i
<sgcnt
; ++i
,++sl
) {
3013 cmdp
->u
.cache64
.sg_lst
[i
].sg_ptr
= virt_to_bus(sl
->address
);
3014 cmdp
->u
.cache64
.sg_lst
[i
].sg_len
= (ulong32
)sl
->length
;
3017 cmdp
->u
.cache
.DestAddr
= 0xffffffff;
3018 cmdp
->u
.cache
.sg_canz
= sgcnt
;
3019 for (i
=0; i
<sgcnt
; ++i
,++sl
) {
3020 cmdp
->u
.cache
.sg_lst
[i
].sg_ptr
= virt_to_bus(sl
->address
);
3021 cmdp
->u
.cache
.sg_lst
[i
].sg_len
= (ulong32
)sl
->length
;
3026 #ifdef GDTH_STATISTICS
3027 if (max_sg
< (ulong32
)sgcnt
) {
3028 max_sg
= (ulong32
)sgcnt
;
3029 TRACE3(("GDT: max_sg = %d\n",max_sg
));
3034 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3035 scp
->SCp
.Status
= GDTH_MAP_SINGLE
;
3036 scp
->SCp
.Message
= (read_write
== 1 ?
3037 PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
);
3038 page
= virt_to_page(scp
->request_buffer
);
3039 offset
= (ulong
)scp
->request_buffer
& ~PAGE_MASK
;
3040 phys_addr
= pci_map_page(ha
->pdev
,page
,offset
,
3041 scp
->request_bufflen
,scp
->SCp
.Message
);
3042 scp
->SCp
.dma_handle
= phys_addr
;
3044 phys_addr
= virt_to_bus(scp
->request_buffer
);
3047 if (ha
->cache_feat
& SCATTER_GATHER
) {
3048 cmdp
->u
.cache64
.DestAddr
= (ulong64
)-1;
3049 cmdp
->u
.cache64
.sg_canz
= 1;
3050 cmdp
->u
.cache64
.sg_lst
[0].sg_ptr
= phys_addr
;
3051 cmdp
->u
.cache64
.sg_lst
[0].sg_len
= scp
->request_bufflen
;
3052 cmdp
->u
.cache64
.sg_lst
[1].sg_len
= 0;
3054 cmdp
->u
.cache64
.DestAddr
= phys_addr
;
3055 cmdp
->u
.cache64
.sg_canz
= 0;
3058 if (ha
->cache_feat
& SCATTER_GATHER
) {
3059 cmdp
->u
.cache
.DestAddr
= 0xffffffff;
3060 cmdp
->u
.cache
.sg_canz
= 1;
3061 cmdp
->u
.cache
.sg_lst
[0].sg_ptr
= phys_addr
;
3062 cmdp
->u
.cache
.sg_lst
[0].sg_len
= scp
->request_bufflen
;
3063 cmdp
->u
.cache
.sg_lst
[1].sg_len
= 0;
3065 cmdp
->u
.cache
.DestAddr
= phys_addr
;
3066 cmdp
->u
.cache
.sg_canz
= 0;
3071 /* evaluate command size, check space */
3073 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3074 cmdp
->u
.cache64
.DestAddr
,cmdp
->u
.cache64
.sg_canz
,
3075 cmdp
->u
.cache64
.sg_lst
[0].sg_ptr
,
3076 cmdp
->u
.cache64
.sg_lst
[0].sg_len
));
3077 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
3078 cmdp
->OpCode
,cmdp
->u
.cache64
.BlockNo
,cmdp
->u
.cache64
.BlockCnt
));
3079 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.cache64
.sg_lst
) +
3080 (ushort
)cmdp
->u
.cache64
.sg_canz
* sizeof(gdth_sg64_str
);
3082 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3083 cmdp
->u
.cache
.DestAddr
,cmdp
->u
.cache
.sg_canz
,
3084 cmdp
->u
.cache
.sg_lst
[0].sg_ptr
,
3085 cmdp
->u
.cache
.sg_lst
[0].sg_len
));
3086 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
3087 cmdp
->OpCode
,cmdp
->u
.cache
.BlockNo
,cmdp
->u
.cache
.BlockCnt
));
3088 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.cache
.sg_lst
) +
3089 (ushort
)cmdp
->u
.cache
.sg_canz
* sizeof(gdth_sg_str
);
3091 if (ha
->cmd_len
& 3)
3092 ha
->cmd_len
+= (4 - (ha
->cmd_len
& 3));
3094 if (ha
->cmd_cnt
> 0) {
3095 if ((ha
->cmd_offs_dpmem
+ ha
->cmd_len
+ DPMEM_COMMAND_OFFSET
) >
3097 TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
3098 ha
->cmd_tab
[cmd_index
-2].cmnd
= UNUSED_CMND
;
3104 gdth_copy_command(hanum
);
3108 static int gdth_fill_raw_cmd(int hanum
,Scsi_Cmnd
*scp
,unchar b
)
3110 register gdth_ha_str
*ha
;
3111 register gdth_cmd_str
*cmdp
;
3112 struct scatterlist
*sl
;
3114 dma_addr_t phys_addr
, sense_paddr
;
3115 int cmd_index
, sgcnt
, mode64
;
3117 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3122 ha
= HADATA(gdth_ctr_tab
[hanum
]);
3123 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3124 t
= scp
->device
->id
;
3125 l
= scp
->device
->lun
;
3131 TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
3132 scp
->cmnd
[0],b
,t
,l
));
3134 if (ha
->type
==GDT_EISA
&& ha
->cmd_cnt
>0)
3137 mode64
= (ha
->raw_feat
& GDT_64BIT
) ? TRUE
: FALSE
;
3139 cmdp
->Service
= SCSIRAWSERVICE
;
3140 cmdp
->RequestBuffer
= scp
;
3141 /* search free command index */
3142 if (!(cmd_index
=gdth_get_cmd_index(hanum
))) {
3143 TRACE(("GDT: No free command index found\n"));
3146 /* if it's the first command, set command semaphore */
3147 if (ha
->cmd_cnt
== 0)
3148 gdth_set_sema0(hanum
);
3151 if (scp
->SCp
.sent_command
!= -1) {
3152 cmdp
->OpCode
= scp
->SCp
.sent_command
; /* special raw cmd. */
3153 cmdp
->BoardNode
= LOCALBOARD
;
3155 cmdp
->u
.raw64
.direction
= (scp
->SCp
.phase
>> 8);
3156 TRACE2(("special raw cmd 0x%x param 0x%x\n",
3157 cmdp
->OpCode
, cmdp
->u
.raw64
.direction
));
3158 /* evaluate command size */
3159 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.raw64
.sg_lst
);
3161 cmdp
->u
.raw
.direction
= (scp
->SCp
.phase
>> 8);
3162 TRACE2(("special raw cmd 0x%x param 0x%x\n",
3163 cmdp
->OpCode
, cmdp
->u
.raw
.direction
));
3164 /* evaluate command size */
3165 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.raw
.sg_lst
);
3169 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3170 page
= virt_to_page(scp
->sense_buffer
);
3171 offset
= (ulong
)scp
->sense_buffer
& ~PAGE_MASK
;
3172 sense_paddr
= pci_map_page(ha
->pdev
,page
,offset
,
3173 16,PCI_DMA_FROMDEVICE
);
3174 scp
->SCp
.buffer
= (struct scatterlist
*)((ulong32
)sense_paddr
);
3175 /* high part, if 64bit */
3176 scp
->host_scribble
= (char *)(ulong32
)((ulong64
)sense_paddr
>> 32);
3178 sense_paddr
= virt_to_bus(scp
->sense_buffer
);
3180 cmdp
->OpCode
= GDT_WRITE
; /* always */
3181 cmdp
->BoardNode
= LOCALBOARD
;
3183 cmdp
->u
.raw64
.reserved
= 0;
3184 cmdp
->u
.raw64
.mdisc_time
= 0;
3185 cmdp
->u
.raw64
.mcon_time
= 0;
3186 cmdp
->u
.raw64
.clen
= scp
->cmd_len
;
3187 cmdp
->u
.raw64
.target
= t
;
3188 cmdp
->u
.raw64
.lun
= l
;
3189 cmdp
->u
.raw64
.bus
= b
;
3190 cmdp
->u
.raw64
.priority
= 0;
3191 cmdp
->u
.raw64
.sdlen
= scp
->request_bufflen
;
3192 cmdp
->u
.raw64
.sense_len
= 16;
3193 cmdp
->u
.raw64
.sense_data
= sense_paddr
;
3194 cmdp
->u
.raw64
.direction
=
3195 gdth_direction_tab
[scp
->cmnd
[0]]==DOU
? GDTH_DATA_OUT
:GDTH_DATA_IN
;
3196 memcpy(cmdp
->u
.raw64
.cmd
,scp
->cmnd
,16);
3198 cmdp
->u
.raw
.reserved
= 0;
3199 cmdp
->u
.raw
.mdisc_time
= 0;
3200 cmdp
->u
.raw
.mcon_time
= 0;
3201 cmdp
->u
.raw
.clen
= scp
->cmd_len
;
3202 cmdp
->u
.raw
.target
= t
;
3203 cmdp
->u
.raw
.lun
= l
;
3204 cmdp
->u
.raw
.bus
= b
;
3205 cmdp
->u
.raw
.priority
= 0;
3206 cmdp
->u
.raw
.link_p
= 0;
3207 cmdp
->u
.raw
.sdlen
= scp
->request_bufflen
;
3208 cmdp
->u
.raw
.sense_len
= 16;
3209 cmdp
->u
.raw
.sense_data
= sense_paddr
;
3210 cmdp
->u
.raw
.direction
=
3211 gdth_direction_tab
[scp
->cmnd
[0]]==DOU
? GDTH_DATA_OUT
:GDTH_DATA_IN
;
3212 memcpy(cmdp
->u
.raw
.cmd
,scp
->cmnd
,12);
3216 sl
= (struct scatterlist
*)scp
->request_buffer
;
3217 sgcnt
= scp
->use_sg
;
3218 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3219 scp
->SCp
.Status
= GDTH_MAP_SG
;
3220 scp
->SCp
.Message
= PCI_DMA_BIDIRECTIONAL
;
3221 sgcnt
= pci_map_sg(ha
->pdev
,sl
,scp
->use_sg
,scp
->SCp
.Message
);
3223 cmdp
->u
.raw64
.sdata
= (ulong64
)-1;
3224 cmdp
->u
.raw64
.sg_ranz
= sgcnt
;
3225 for (i
=0; i
<sgcnt
; ++i
,++sl
) {
3226 cmdp
->u
.raw64
.sg_lst
[i
].sg_ptr
= sg_dma_address(sl
);
3227 #ifdef GDTH_DMA_STATISTICS
3228 if (cmdp
->u
.raw64
.sg_lst
[i
].sg_ptr
> (ulong64
)0xffffffff)
3233 cmdp
->u
.raw64
.sg_lst
[i
].sg_len
= sg_dma_len(sl
);
3236 cmdp
->u
.raw
.sdata
= 0xffffffff;
3237 cmdp
->u
.raw
.sg_ranz
= sgcnt
;
3238 for (i
=0; i
<sgcnt
; ++i
,++sl
) {
3239 cmdp
->u
.raw
.sg_lst
[i
].sg_ptr
= sg_dma_address(sl
);
3240 #ifdef GDTH_DMA_STATISTICS
3243 cmdp
->u
.raw
.sg_lst
[i
].sg_len
= sg_dma_len(sl
);
3248 cmdp
->u
.raw64
.sdata
= (ulong64
)-1;
3249 cmdp
->u
.raw64
.sg_ranz
= sgcnt
;
3250 for (i
=0; i
<sgcnt
; ++i
,++sl
) {
3251 cmdp
->u
.raw64
.sg_lst
[i
].sg_ptr
= virt_to_bus(sl
->address
);
3252 cmdp
->u
.raw64
.sg_lst
[i
].sg_len
= (ulong32
)sl
->length
;
3255 cmdp
->u
.raw
.sdata
= 0xffffffff;
3256 cmdp
->u
.raw
.sg_ranz
= sgcnt
;
3257 for (i
=0; i
<sgcnt
; ++i
,++sl
) {
3258 cmdp
->u
.raw
.sg_lst
[i
].sg_ptr
= virt_to_bus(sl
->address
);
3259 cmdp
->u
.raw
.sg_lst
[i
].sg_len
= (ulong32
)sl
->length
;
3264 #ifdef GDTH_STATISTICS
3265 if (max_sg
< sgcnt
) {
3267 TRACE3(("GDT: max_sg = %d\n",sgcnt
));
3272 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3273 scp
->SCp
.Status
= GDTH_MAP_SINGLE
;
3274 scp
->SCp
.Message
= PCI_DMA_BIDIRECTIONAL
;
3275 page
= virt_to_page(scp
->request_buffer
);
3276 offset
= (ulong
)scp
->request_buffer
& ~PAGE_MASK
;
3277 phys_addr
= pci_map_page(ha
->pdev
,page
,offset
,
3278 scp
->request_bufflen
,scp
->SCp
.Message
);
3279 scp
->SCp
.dma_handle
= phys_addr
;
3281 phys_addr
= virt_to_bus(scp
->request_buffer
);
3284 if (ha
->raw_feat
& SCATTER_GATHER
) {
3285 cmdp
->u
.raw64
.sdata
= (ulong64
)-1;
3286 cmdp
->u
.raw64
.sg_ranz
= 1;
3287 cmdp
->u
.raw64
.sg_lst
[0].sg_ptr
= phys_addr
;
3288 cmdp
->u
.raw64
.sg_lst
[0].sg_len
= scp
->request_bufflen
;
3289 cmdp
->u
.raw64
.sg_lst
[1].sg_len
= 0;
3291 cmdp
->u
.raw64
.sdata
= phys_addr
;
3292 cmdp
->u
.raw64
.sg_ranz
= 0;
3295 if (ha
->raw_feat
& SCATTER_GATHER
) {
3296 cmdp
->u
.raw
.sdata
= 0xffffffff;
3297 cmdp
->u
.raw
.sg_ranz
= 1;
3298 cmdp
->u
.raw
.sg_lst
[0].sg_ptr
= phys_addr
;
3299 cmdp
->u
.raw
.sg_lst
[0].sg_len
= scp
->request_bufflen
;
3300 cmdp
->u
.raw
.sg_lst
[1].sg_len
= 0;
3302 cmdp
->u
.raw
.sdata
= phys_addr
;
3303 cmdp
->u
.raw
.sg_ranz
= 0;
3308 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3309 cmdp
->u
.raw64
.sdata
,cmdp
->u
.raw64
.sg_ranz
,
3310 cmdp
->u
.raw64
.sg_lst
[0].sg_ptr
,
3311 cmdp
->u
.raw64
.sg_lst
[0].sg_len
));
3312 /* evaluate command size */
3313 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.raw64
.sg_lst
) +
3314 (ushort
)cmdp
->u
.raw64
.sg_ranz
* sizeof(gdth_sg64_str
);
3316 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3317 cmdp
->u
.raw
.sdata
,cmdp
->u
.raw
.sg_ranz
,
3318 cmdp
->u
.raw
.sg_lst
[0].sg_ptr
,
3319 cmdp
->u
.raw
.sg_lst
[0].sg_len
));
3320 /* evaluate command size */
3321 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.raw
.sg_lst
) +
3322 (ushort
)cmdp
->u
.raw
.sg_ranz
* sizeof(gdth_sg_str
);
3326 if (ha
->cmd_len
& 3)
3327 ha
->cmd_len
+= (4 - (ha
->cmd_len
& 3));
3329 if (ha
->cmd_cnt
> 0) {
3330 if ((ha
->cmd_offs_dpmem
+ ha
->cmd_len
+ DPMEM_COMMAND_OFFSET
) >
3332 TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
3333 ha
->cmd_tab
[cmd_index
-2].cmnd
= UNUSED_CMND
;
3339 gdth_copy_command(hanum
);
3343 static int gdth_special_cmd(int hanum
,Scsi_Cmnd
*scp
)
3345 register gdth_ha_str
*ha
;
3346 register gdth_cmd_str
*cmdp
;
3349 ha
= HADATA(gdth_ctr_tab
[hanum
]);
3351 TRACE2(("gdth_special_cmd(): "));
3353 if (ha
->type
==GDT_EISA
&& ha
->cmd_cnt
>0)
3356 memcpy( cmdp
, scp
->request_buffer
, sizeof(gdth_cmd_str
));
3357 cmdp
->RequestBuffer
= scp
;
3359 /* search free command index */
3360 if (!(cmd_index
=gdth_get_cmd_index(hanum
))) {
3361 TRACE(("GDT: No free command index found\n"));
3365 /* if it's the first command, set command semaphore */
3366 if (ha
->cmd_cnt
== 0)
3367 gdth_set_sema0(hanum
);
3369 /* evaluate command size, check space */
3370 if (cmdp
->OpCode
== GDT_IOCTL
) {
3371 TRACE2(("IOCTL\n"));
3373 GDTOFFSOF(gdth_cmd_str
,u
.ioctl
.p_param
) + sizeof(ulong64
);
3374 } else if (cmdp
->Service
== CACHESERVICE
) {
3375 TRACE2(("cache command %d\n",cmdp
->OpCode
));
3376 if (ha
->cache_feat
& GDT_64BIT
)
3378 GDTOFFSOF(gdth_cmd_str
,u
.cache64
.sg_lst
) + sizeof(gdth_sg64_str
);
3381 GDTOFFSOF(gdth_cmd_str
,u
.cache
.sg_lst
) + sizeof(gdth_sg_str
);
3382 } else if (cmdp
->Service
== SCSIRAWSERVICE
) {
3383 TRACE2(("raw command %d\n",cmdp
->OpCode
));
3384 if (ha
->raw_feat
& GDT_64BIT
)
3386 GDTOFFSOF(gdth_cmd_str
,u
.raw64
.sg_lst
) + sizeof(gdth_sg64_str
);
3389 GDTOFFSOF(gdth_cmd_str
,u
.raw
.sg_lst
) + sizeof(gdth_sg_str
);
3392 if (ha
->cmd_len
& 3)
3393 ha
->cmd_len
+= (4 - (ha
->cmd_len
& 3));
3395 if (ha
->cmd_cnt
> 0) {
3396 if ((ha
->cmd_offs_dpmem
+ ha
->cmd_len
+ DPMEM_COMMAND_OFFSET
) >
3398 TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
3399 ha
->cmd_tab
[cmd_index
-2].cmnd
= UNUSED_CMND
;
3405 gdth_copy_command(hanum
);
3410 /* Controller event handling functions */
3411 static gdth_evt_str
*gdth_store_event(gdth_ha_str
*ha
, ushort source
,
3412 ushort idx
, gdth_evt_data
*evt
)
3417 /* no GDTH_LOCK_HA() ! */
3418 TRACE2(("gdth_store_event() source %d idx %d\n", source
, idx
));
3419 if (source
== 0) /* no source -> no event */
3422 if (ebuffer
[elastidx
].event_source
== source
&&
3423 ebuffer
[elastidx
].event_idx
== idx
&&
3424 ((evt
->size
!= 0 && ebuffer
[elastidx
].event_data
.size
!= 0 &&
3425 !memcmp((char *)&ebuffer
[elastidx
].event_data
.eu
,
3426 (char *)&evt
->eu
, evt
->size
)) ||
3427 (evt
->size
== 0 && ebuffer
[elastidx
].event_data
.size
== 0 &&
3428 !strcmp((char *)&ebuffer
[elastidx
].event_data
.event_string
,
3429 (char *)&evt
->event_string
)))) {
3430 e
= &ebuffer
[elastidx
];
3431 do_gettimeofday(&tv
);
3432 e
->last_stamp
= tv
.tv_sec
;
3435 if (ebuffer
[elastidx
].event_source
!= 0) { /* entry not free ? */
3437 if (elastidx
== MAX_EVENTS
)
3439 if (elastidx
== eoldidx
) { /* reached mark ? */
3441 if (eoldidx
== MAX_EVENTS
)
3445 e
= &ebuffer
[elastidx
];
3446 e
->event_source
= source
;
3448 do_gettimeofday(&tv
);
3449 e
->first_stamp
= e
->last_stamp
= tv
.tv_sec
;
3451 e
->event_data
= *evt
;
3457 static int gdth_read_event(gdth_ha_str
*ha
, int handle
, gdth_evt_str
*estr
)
3463 TRACE2(("gdth_read_event() handle %d\n", handle
));
3464 GDTH_LOCK_HA(ha
, flags
);
3469 estr
->event_source
= 0;
3471 if (eindex
>= MAX_EVENTS
) {
3472 GDTH_UNLOCK_HA(ha
, flags
);
3475 e
= &ebuffer
[eindex
];
3476 if (e
->event_source
!= 0) {
3477 if (eindex
!= elastidx
) {
3478 if (++eindex
== MAX_EVENTS
)
3483 memcpy(estr
, e
, sizeof(gdth_evt_str
));
3485 GDTH_UNLOCK_HA(ha
, flags
);
3489 static void gdth_readapp_event(gdth_ha_str
*ha
,
3490 unchar application
, gdth_evt_str
*estr
)
3495 unchar found
= FALSE
;
3497 TRACE2(("gdth_readapp_event() app. %d\n", application
));
3498 GDTH_LOCK_HA(ha
, flags
);
3501 e
= &ebuffer
[eindex
];
3502 if (e
->event_source
== 0)
3504 if ((e
->application
& application
) == 0) {
3505 e
->application
|= application
;
3509 if (eindex
== elastidx
)
3511 if (++eindex
== MAX_EVENTS
)
3515 memcpy(estr
, e
, sizeof(gdth_evt_str
));
3517 estr
->event_source
= 0;
3518 GDTH_UNLOCK_HA(ha
, flags
);
3521 static void gdth_clear_events(void)
3523 TRACE(("gdth_clear_events()"));
3525 eoldidx
= elastidx
= 0;
3526 ebuffer
[0].event_source
= 0;
3530 /* SCSI interface functions */
3532 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3533 static irqreturn_t
gdth_interrupt(int irq
,void *dev_id
,struct pt_regs
*regs
)
3535 static void gdth_interrupt(int irq
,void *dev_id
,struct pt_regs
*regs
)
3538 register gdth_ha_str
*ha
;
3539 gdt6m_dpram_str __iomem
*dp6m_ptr
= NULL
;
3540 gdt6_dpram_str __iomem
*dp6_ptr
;
3541 gdt2_dpram_str __iomem
*dp2_ptr
;
3548 int coalesced
= FALSE
;
3550 gdth_coal_status
*pcs
= NULL
;
3551 int act_int_coal
= 0;
3554 TRACE(("gdth_interrupt() IRQ %d\n",irq
));
3556 /* if polling and not from gdth_wait() -> return */
3558 if (!gdth_from_wait
) {
3559 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3568 GDTH_LOCK_HA((gdth_ha_str
*)dev_id
,flags
);
3571 /* search controller */
3572 if ((hanum
= gdth_get_status(&IStatus
,irq
)) == -1) {
3573 /* spurious interrupt */
3575 GDTH_UNLOCK_HA((gdth_ha_str
*)dev_id
,flags
);
3576 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3582 ha
= HADATA(gdth_ctr_tab
[hanum
]);
3584 #ifdef GDTH_STATISTICS
3589 /* See if the fw is returning coalesced status */
3590 if (IStatus
== COALINDEX
) {
3591 /* Coalesced status. Setup the initial status
3592 buffer pointer and flags */
3593 pcs
= ha
->coal_stat
;
3600 /* For coalesced requests all status
3601 information is found in the status buffer */
3602 IStatus
= (unchar
)(pcs
->status
& 0xff);
3606 if (ha
->type
== GDT_EISA
) {
3607 if (IStatus
& 0x80) { /* error flag */
3609 ha
->status
= inw(ha
->bmic
+ MAILBOXREG
+8);
3610 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3611 } else /* no error */
3613 ha
->info
= inl(ha
->bmic
+ MAILBOXREG
+12);
3614 ha
->service
= inw(ha
->bmic
+ MAILBOXREG
+10);
3615 ha
->info2
= inl(ha
->bmic
+ MAILBOXREG
+4);
3617 outb(0xff, ha
->bmic
+ EDOORREG
); /* acknowledge interrupt */
3618 outb(0x00, ha
->bmic
+ SEMA1REG
); /* reset status semaphore */
3619 } else if (ha
->type
== GDT_ISA
) {
3621 if (IStatus
& 0x80) { /* error flag */
3623 ha
->status
= gdth_readw(&dp2_ptr
->u
.ic
.Status
);
3624 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3625 } else /* no error */
3627 ha
->info
= gdth_readl(&dp2_ptr
->u
.ic
.Info
[0]);
3628 ha
->service
= gdth_readw(&dp2_ptr
->u
.ic
.Service
);
3629 ha
->info2
= gdth_readl(&dp2_ptr
->u
.ic
.Info
[1]);
3631 gdth_writeb(0xff, &dp2_ptr
->io
.irqdel
); /* acknowledge interrupt */
3632 gdth_writeb(0, &dp2_ptr
->u
.ic
.Cmd_Index
);/* reset command index */
3633 gdth_writeb(0, &dp2_ptr
->io
.Sema1
); /* reset status semaphore */
3634 } else if (ha
->type
== GDT_PCI
) {
3636 if (IStatus
& 0x80) { /* error flag */
3638 ha
->status
= gdth_readw(&dp6_ptr
->u
.ic
.Status
);
3639 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3640 } else /* no error */
3642 ha
->info
= gdth_readl(&dp6_ptr
->u
.ic
.Info
[0]);
3643 ha
->service
= gdth_readw(&dp6_ptr
->u
.ic
.Service
);
3644 ha
->info2
= gdth_readl(&dp6_ptr
->u
.ic
.Info
[1]);
3646 gdth_writeb(0xff, &dp6_ptr
->io
.irqdel
); /* acknowledge interrupt */
3647 gdth_writeb(0, &dp6_ptr
->u
.ic
.Cmd_Index
);/* reset command index */
3648 gdth_writeb(0, &dp6_ptr
->io
.Sema1
); /* reset status semaphore */
3649 } else if (ha
->type
== GDT_PCINEW
) {
3650 if (IStatus
& 0x80) { /* error flag */
3652 ha
->status
= inw(PTR2USHORT(&ha
->plx
->status
));
3653 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3656 ha
->info
= inl(PTR2USHORT(&ha
->plx
->info
[0]));
3657 ha
->service
= inw(PTR2USHORT(&ha
->plx
->service
));
3658 ha
->info2
= inl(PTR2USHORT(&ha
->plx
->info
[1]));
3660 outb(0xff, PTR2USHORT(&ha
->plx
->edoor_reg
));
3661 outb(0x00, PTR2USHORT(&ha
->plx
->sema1_reg
));
3662 } else if (ha
->type
== GDT_PCIMPR
) {
3664 if (IStatus
& 0x80) { /* error flag */
3668 ha
->status
= pcs
->ext_status
&& 0xffff;
3671 ha
->status
= gdth_readw(&dp6m_ptr
->i960r
.status
);
3672 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus
,ha
->status
));
3673 } else /* no error */
3676 /* get information */
3678 ha
->info
= pcs
->info0
;
3679 ha
->info2
= pcs
->info1
;
3680 ha
->service
= (pcs
->ext_status
>> 16) && 0xffff;
3684 ha
->info
= gdth_readl(&dp6m_ptr
->i960r
.info
[0]);
3685 ha
->service
= gdth_readw(&dp6m_ptr
->i960r
.service
);
3686 ha
->info2
= gdth_readl(&dp6m_ptr
->i960r
.info
[1]);
3689 if (IStatus
== ASYNCINDEX
) {
3690 if (ha
->service
!= SCREENSERVICE
&&
3691 (ha
->fw_vers
& 0xff) >= 0x1a) {
3692 ha
->dvr
.severity
= gdth_readb
3693 (&((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.severity
);
3694 for (i
= 0; i
< 256; ++i
) {
3695 ha
->dvr
.event_string
[i
] = gdth_readb
3696 (&((gdt6m_dpram_str __iomem
*)ha
->brd
)->i960r
.evt_str
[i
]);
3697 if (ha
->dvr
.event_string
[i
] == 0)
3703 /* Make sure that non coalesced interrupts get cleared
3704 before being handled by gdth_async_event/gdth_sync_event */
3708 gdth_writeb(0xff, &dp6m_ptr
->i960r
.edoor_reg
);
3709 gdth_writeb(0, &dp6m_ptr
->i960r
.sema1_reg
);
3712 TRACE2(("gdth_interrupt() unknown controller type\n"));
3714 GDTH_UNLOCK_HA((gdth_ha_str
*)dev_id
,flags
);
3715 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3722 TRACE(("gdth_interrupt() index %d stat %d info %d\n",
3723 IStatus
,ha
->status
,ha
->info
));
3725 if (gdth_from_wait
) {
3727 wait_index
= (int)IStatus
;
3730 if (IStatus
== ASYNCINDEX
) {
3731 TRACE2(("gdth_interrupt() async. event\n"));
3732 gdth_async_event(hanum
);
3734 GDTH_UNLOCK_HA((gdth_ha_str
*)dev_id
,flags
);
3736 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3743 if (IStatus
== SPEZINDEX
) {
3744 TRACE2(("Service unknown or not initialized !\n"));
3745 ha
->dvr
.size
= sizeof(ha
->dvr
.eu
.driver
);
3746 ha
->dvr
.eu
.driver
.ionode
= hanum
;
3747 gdth_store_event(ha
, ES_DRIVER
, 4, &ha
->dvr
);
3749 GDTH_UNLOCK_HA((gdth_ha_str
*)dev_id
,flags
);
3750 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3756 scp
= ha
->cmd_tab
[IStatus
-2].cmnd
;
3757 Service
= ha
->cmd_tab
[IStatus
-2].service
;
3758 ha
->cmd_tab
[IStatus
-2].cmnd
= UNUSED_CMND
;
3759 if (scp
== UNUSED_CMND
) {
3760 TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus
));
3761 ha
->dvr
.size
= sizeof(ha
->dvr
.eu
.driver
);
3762 ha
->dvr
.eu
.driver
.ionode
= hanum
;
3763 ha
->dvr
.eu
.driver
.index
= IStatus
;
3764 gdth_store_event(ha
, ES_DRIVER
, 1, &ha
->dvr
);
3766 GDTH_UNLOCK_HA((gdth_ha_str
*)dev_id
,flags
);
3767 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3773 if (scp
== INTERNAL_CMND
) {
3774 TRACE(("gdth_interrupt() answer to internal command\n"));
3776 GDTH_UNLOCK_HA((gdth_ha_str
*)dev_id
,flags
);
3777 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3784 TRACE(("gdth_interrupt() sync. status\n"));
3785 rval
= gdth_sync_event(hanum
,Service
,IStatus
,scp
);
3787 GDTH_UNLOCK_HA((gdth_ha_str
*)dev_id
,flags
);
3789 gdth_putq(hanum
,scp
,scp
->SCp
.this_residual
);
3790 } else if (rval
== 1) {
3791 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3792 GDTH_LOCK_SCSI_DONE(scp
->device
->host
, flags
);
3793 scp
->scsi_done(scp
);
3794 GDTH_UNLOCK_SCSI_DONE(scp
->device
->host
, flags
);
3796 GDTH_LOCK_SCSI_DONE(flags
);
3797 scp
->scsi_done(scp
);
3798 GDTH_UNLOCK_SCSI_DONE(flags
);
3804 /* go to the next status in the status buffer */
3806 #ifdef GDTH_STATISTICS
3808 if (act_int_coal
> max_int_coal
) {
3809 max_int_coal
= act_int_coal
;
3810 printk("GDT: max_int_coal = %d\n",(ushort
)max_int_coal
);
3813 /* see if there is another status */
3814 if (pcs
->status
== 0)
3815 /* Stop the coalesce loop */
3820 /* coalescing only for new GDT_PCIMPR controllers available */
3821 if (ha
->type
== GDT_PCIMPR
&& coalesced
) {
3822 gdth_writeb(0xff, &dp6m_ptr
->i960r
.edoor_reg
);
3823 gdth_writeb(0, &dp6m_ptr
->i960r
.sema1_reg
);
3828 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3833 static int gdth_sync_event(int hanum
,int service
,unchar index
,Scsi_Cmnd
*scp
)
3835 register gdth_ha_str
*ha
;
3840 ha
= HADATA(gdth_ctr_tab
[hanum
]);
3842 TRACE(("gdth_sync_event() serv %d status %d\n",
3843 service
,ha
->status
));
3845 if (service
== SCREENSERVICE
) {
3847 TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
3848 msg
->msg_len
,msg
->msg_answer
,msg
->msg_ext
,msg
->msg_alen
));
3849 if (msg
->msg_len
> MSGLEN
+1)
3850 msg
->msg_len
= MSGLEN
+1;
3852 if (!(msg
->msg_answer
&& msg
->msg_ext
)) {
3853 msg
->msg_text
[msg
->msg_len
] = '\0';
3854 printk("%s",msg
->msg_text
);
3857 if (msg
->msg_ext
&& !msg
->msg_answer
) {
3858 while (gdth_test_busy(hanum
))
3860 cmdp
->Service
= SCREENSERVICE
;
3861 cmdp
->RequestBuffer
= SCREEN_CMND
;
3862 gdth_get_cmd_index(hanum
);
3863 gdth_set_sema0(hanum
);
3864 cmdp
->OpCode
= GDT_READ
;
3865 cmdp
->BoardNode
= LOCALBOARD
;
3866 cmdp
->u
.screen
.reserved
= 0;
3867 cmdp
->u
.screen
.su
.msg
.msg_handle
= msg
->msg_handle
;
3868 cmdp
->u
.screen
.su
.msg
.msg_addr
= ha
->msg_phys
;
3869 ha
->cmd_offs_dpmem
= 0;
3870 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.screen
.su
.msg
.msg_addr
)
3873 gdth_copy_command(hanum
);
3874 gdth_release_event(hanum
);
3878 if (msg
->msg_answer
&& msg
->msg_alen
) {
3879 /* default answers (getchar() not possible) */
3880 if (msg
->msg_alen
== 1) {
3883 msg
->msg_text
[0] = 0;
3887 msg
->msg_text
[0] = 1;
3888 msg
->msg_text
[1] = 0;
3891 msg
->msg_answer
= 0;
3892 while (gdth_test_busy(hanum
))
3894 cmdp
->Service
= SCREENSERVICE
;
3895 cmdp
->RequestBuffer
= SCREEN_CMND
;
3896 gdth_get_cmd_index(hanum
);
3897 gdth_set_sema0(hanum
);
3898 cmdp
->OpCode
= GDT_WRITE
;
3899 cmdp
->BoardNode
= LOCALBOARD
;
3900 cmdp
->u
.screen
.reserved
= 0;
3901 cmdp
->u
.screen
.su
.msg
.msg_handle
= msg
->msg_handle
;
3902 cmdp
->u
.screen
.su
.msg
.msg_addr
= ha
->msg_phys
;
3903 ha
->cmd_offs_dpmem
= 0;
3904 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.screen
.su
.msg
.msg_addr
)
3907 gdth_copy_command(hanum
);
3908 gdth_release_event(hanum
);
3914 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3915 b
= virt_ctr
? NUMDATA(scp
->device
->host
)->busnum
: scp
->device
->channel
;
3916 t
= scp
->device
->id
;
3918 b
= virt_ctr
? NUMDATA(scp
->host
)->busnum
: scp
->channel
;
3921 if (scp
->SCp
.sent_command
== -1 && b
!= ha
->virt_bus
) {
3922 ha
->raw
[BUS_L2P(ha
,b
)].io_cnt
[t
]--;
3924 /* cache or raw service */
3925 if (ha
->status
== S_BSY
) {
3926 TRACE2(("Controller busy -> retry !\n"));
3927 if (scp
->SCp
.sent_command
== GDT_MOUNT
)
3928 scp
->SCp
.sent_command
= GDT_CLUST_INFO
;
3932 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,13)
3933 if (scp
->SCp
.Status
== GDTH_MAP_SG
)
3934 pci_unmap_sg(ha
->pdev
,scp
->request_buffer
,
3935 scp
->use_sg
,scp
->SCp
.Message
);
3936 else if (scp
->SCp
.Status
== GDTH_MAP_SINGLE
)
3937 pci_unmap_page(ha
->pdev
,scp
->SCp
.dma_handle
,
3938 scp
->request_bufflen
,scp
->SCp
.Message
);
3939 if (scp
->SCp
.buffer
) {
3941 addr
= (dma_addr_t
)(ulong32
)scp
->SCp
.buffer
;
3942 if (scp
->host_scribble
)
3943 addr
+= (dma_addr_t
)((ulong64
)(ulong32
)scp
->host_scribble
<< 32);
3944 pci_unmap_page(ha
->pdev
,addr
,16,PCI_DMA_FROMDEVICE
);
3947 if (ha
->status
== S_OK
) {
3948 scp
->SCp
.Status
= S_OK
;
3949 scp
->SCp
.Message
= ha
->info
;
3950 if (scp
->SCp
.sent_command
!= -1) {
3951 TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
3952 scp
->SCp
.sent_command
));
3953 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
3954 if (scp
->SCp
.sent_command
== GDT_CLUST_INFO
) {
3955 ha
->hdr
[t
].cluster_type
= (unchar
)ha
->info
;
3956 if (!(ha
->hdr
[t
].cluster_type
&
3958 /* NOT MOUNTED -> MOUNT */
3959 scp
->SCp
.sent_command
= GDT_MOUNT
;
3960 if (ha
->hdr
[t
].cluster_type
&
3962 /* cluster drive RESERVED (on the other node) */
3963 scp
->SCp
.phase
= -2; /* reservation conflict */
3966 scp
->SCp
.sent_command
= -1;
3969 if (scp
->SCp
.sent_command
== GDT_MOUNT
) {
3970 ha
->hdr
[t
].cluster_type
|= CLUSTER_MOUNTED
;
3971 ha
->hdr
[t
].media_changed
= TRUE
;
3972 } else if (scp
->SCp
.sent_command
== GDT_UNMOUNT
) {
3973 ha
->hdr
[t
].cluster_type
&= ~CLUSTER_MOUNTED
;
3974 ha
->hdr
[t
].media_changed
= TRUE
;
3976 scp
->SCp
.sent_command
= -1;
3979 scp
->SCp
.this_residual
= HIGH_PRI
;
3982 /* RESERVE/RELEASE ? */
3983 if (scp
->cmnd
[0] == RESERVE
) {
3984 ha
->hdr
[t
].cluster_type
|= CLUSTER_RESERVED
;
3985 } else if (scp
->cmnd
[0] == RELEASE
) {
3986 ha
->hdr
[t
].cluster_type
&= ~CLUSTER_RESERVED
;
3988 scp
->result
= DID_OK
<< 16;
3989 scp
->sense_buffer
[0] = 0;
3992 scp
->SCp
.Status
= ha
->status
;
3993 scp
->SCp
.Message
= ha
->info
;
3995 if (scp
->SCp
.sent_command
!= -1) {
3996 TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
3997 scp
->SCp
.sent_command
, ha
->status
));
3998 if (scp
->SCp
.sent_command
== GDT_SCAN_START
||
3999 scp
->SCp
.sent_command
== GDT_SCAN_END
) {
4000 scp
->SCp
.sent_command
= -1;
4002 scp
->SCp
.this_residual
= HIGH_PRI
;
4005 memset((char*)scp
->sense_buffer
,0,16);
4006 scp
->sense_buffer
[0] = 0x70;
4007 scp
->sense_buffer
[2] = NOT_READY
;
4008 scp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
4009 } else if (service
== CACHESERVICE
) {
4010 if (ha
->status
== S_CACHE_UNKNOWN
&&
4011 (ha
->hdr
[t
].cluster_type
&
4012 CLUSTER_RESERVE_STATE
) == CLUSTER_RESERVE_STATE
) {
4013 /* bus reset -> force GDT_CLUST_INFO */
4014 ha
->hdr
[t
].cluster_type
&= ~CLUSTER_RESERVED
;
4016 memset((char*)scp
->sense_buffer
,0,16);
4017 if (ha
->status
== (ushort
)S_CACHE_RESERV
) {
4018 scp
->result
= (DID_OK
<< 16) | (RESERVATION_CONFLICT
<< 1);
4020 scp
->sense_buffer
[0] = 0x70;
4021 scp
->sense_buffer
[2] = NOT_READY
;
4022 scp
->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
4024 if (scp
->done
!= gdth_scsi_done
) {
4025 ha
->dvr
.size
= sizeof(ha
->dvr
.eu
.sync
);
4026 ha
->dvr
.eu
.sync
.ionode
= hanum
;
4027 ha
->dvr
.eu
.sync
.service
= service
;
4028 ha
->dvr
.eu
.sync
.status
= ha
->status
;
4029 ha
->dvr
.eu
.sync
.info
= ha
->info
;
4030 ha
->dvr
.eu
.sync
.hostdrive
= t
;
4031 if (ha
->status
>= 0x8000)
4032 gdth_store_event(ha
, ES_SYNC
, 0, &ha
->dvr
);
4034 gdth_store_event(ha
, ES_SYNC
, service
, &ha
->dvr
);
4037 /* sense buffer filled from controller firmware (DMA) */
4038 if (ha
->status
!= S_RAW_SCSI
|| ha
->info
>= 0x100) {
4039 scp
->result
= DID_BAD_TARGET
<< 16;
4041 scp
->result
= (DID_OK
<< 16) | ha
->info
;
4045 if (!scp
->SCp
.have_data_in
)
4046 scp
->SCp
.have_data_in
++;
4054 static char *async_cache_tab
[] = {
4055 /* 0*/ "\011\000\002\002\002\004\002\006\004"
4056 "GDT HA %u, service %u, async. status %u/%lu unknown",
4057 /* 1*/ "\011\000\002\002\002\004\002\006\004"
4058 "GDT HA %u, service %u, async. status %u/%lu unknown",
4059 /* 2*/ "\005\000\002\006\004"
4060 "GDT HA %u, Host Drive %lu not ready",
4061 /* 3*/ "\005\000\002\006\004"
4062 "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",
4063 /* 4*/ "\005\000\002\006\004"
4064 "GDT HA %u, mirror update on Host Drive %lu failed",
4065 /* 5*/ "\005\000\002\006\004"
4066 "GDT HA %u, Mirror Drive %lu failed",
4067 /* 6*/ "\005\000\002\006\004"
4068 "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",
4069 /* 7*/ "\005\000\002\006\004"
4070 "GDT HA %u, Host Drive %lu write protected",
4071 /* 8*/ "\005\000\002\006\004"
4072 "GDT HA %u, media changed in Host Drive %lu",
4073 /* 9*/ "\005\000\002\006\004"
4074 "GDT HA %u, Host Drive %lu is offline",
4075 /*10*/ "\005\000\002\006\004"
4076 "GDT HA %u, media change of Mirror Drive %lu",
4077 /*11*/ "\005\000\002\006\004"
4078 "GDT HA %u, Mirror Drive %lu is write protected",
4079 /*12*/ "\005\000\002\006\004"
4080 "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
4081 /*13*/ "\007\000\002\006\002\010\002"
4082 "GDT HA %u, Array Drive %u: Cache Drive %u failed",
4083 /*14*/ "\005\000\002\006\002"
4084 "GDT HA %u, Array Drive %u: FAIL state entered",
4085 /*15*/ "\005\000\002\006\002"
4086 "GDT HA %u, Array Drive %u: error",
4087 /*16*/ "\007\000\002\006\002\010\002"
4088 "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
4089 /*17*/ "\005\000\002\006\002"
4090 "GDT HA %u, Array Drive %u: parity build failed",
4091 /*18*/ "\005\000\002\006\002"
4092 "GDT HA %u, Array Drive %u: drive rebuild failed",
4093 /*19*/ "\005\000\002\010\002"
4094 "GDT HA %u, Test of Hot Fix %u failed",
4095 /*20*/ "\005\000\002\006\002"
4096 "GDT HA %u, Array Drive %u: drive build finished successfully",
4097 /*21*/ "\005\000\002\006\002"
4098 "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
4099 /*22*/ "\007\000\002\006\002\010\002"
4100 "GDT HA %u, Array Drive %u: Hot Fix %u activated",
4101 /*23*/ "\005\000\002\006\002"
4102 "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
4103 /*24*/ "\005\000\002\010\002"
4104 "GDT HA %u, mirror update on Cache Drive %u completed",
4105 /*25*/ "\005\000\002\010\002"
4106 "GDT HA %u, mirror update on Cache Drive %lu failed",
4107 /*26*/ "\005\000\002\006\002"
4108 "GDT HA %u, Array Drive %u: drive rebuild started",
4109 /*27*/ "\005\000\002\012\001"
4110 "GDT HA %u, Fault bus %u: SHELF OK detected",
4111 /*28*/ "\005\000\002\012\001"
4112 "GDT HA %u, Fault bus %u: SHELF not OK detected",
4113 /*29*/ "\007\000\002\012\001\013\001"
4114 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
4115 /*30*/ "\007\000\002\012\001\013\001"
4116 "GDT HA %u, Fault bus %u, ID %u: new disk detected",
4117 /*31*/ "\007\000\002\012\001\013\001"
4118 "GDT HA %u, Fault bus %u, ID %u: old disk detected",
4119 /*32*/ "\007\000\002\012\001\013\001"
4120 "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid",
4121 /*33*/ "\007\000\002\012\001\013\001"
4122 "GDT HA %u, Fault bus %u, ID %u: invalid device detected",
4123 /*34*/ "\011\000\002\012\001\013\001\006\004"
4124 "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
4125 /*35*/ "\007\000\002\012\001\013\001"
4126 "GDT HA %u, Fault bus %u, ID %u: disk write protected",
4127 /*36*/ "\007\000\002\012\001\013\001"
4128 "GDT HA %u, Fault bus %u, ID %u: disk not available",
4129 /*37*/ "\007\000\002\012\001\006\004"
4130 "GDT HA %u, Fault bus %u: swap detected (%lu)",
4131 /*38*/ "\007\000\002\012\001\013\001"
4132 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
4133 /*39*/ "\007\000\002\012\001\013\001"
4134 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
4135 /*40*/ "\007\000\002\012\001\013\001"
4136 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
4137 /*41*/ "\007\000\002\012\001\013\001"
4138 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
4139 /*42*/ "\005\000\002\006\002"
4140 "GDT HA %u, Array Drive %u: drive build started",
4141 /*43*/ "\003\000\002"
4142 "GDT HA %u, DRAM parity error detected",
4143 /*44*/ "\005\000\002\006\002"
4144 "GDT HA %u, Mirror Drive %u: update started",
4145 /*45*/ "\007\000\002\006\002\010\002"
4146 "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
4147 /*46*/ "\005\000\002\006\002"
4148 "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
4149 /*47*/ "\005\000\002\006\002"
4150 "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
4151 /*48*/ "\005\000\002\006\002"
4152 "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
4153 /*49*/ "\005\000\002\006\002"
4154 "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
4155 /*50*/ "\007\000\002\012\001\013\001"
4156 "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
4157 /*51*/ "\005\000\002\006\002"
4158 "GDT HA %u, Array Drive %u: expand started",
4159 /*52*/ "\005\000\002\006\002"
4160 "GDT HA %u, Array Drive %u: expand finished successfully",
4161 /*53*/ "\005\000\002\006\002"
4162 "GDT HA %u, Array Drive %u: expand failed",
4163 /*54*/ "\003\000\002"
4164 "GDT HA %u, CPU temperature critical",
4165 /*55*/ "\003\000\002"
4166 "GDT HA %u, CPU temperature OK",
4167 /*56*/ "\005\000\002\006\004"
4168 "GDT HA %u, Host drive %lu created",
4169 /*57*/ "\005\000\002\006\002"
4170 "GDT HA %u, Array Drive %u: expand restarted",
4171 /*58*/ "\005\000\002\006\002"
4172 "GDT HA %u, Array Drive %u: expand stopped",
4173 /*59*/ "\005\000\002\010\002"
4174 "GDT HA %u, Mirror Drive %u: drive build quited",
4175 /*60*/ "\005\000\002\006\002"
4176 "GDT HA %u, Array Drive %u: parity build quited",
4177 /*61*/ "\005\000\002\006\002"
4178 "GDT HA %u, Array Drive %u: drive rebuild quited",
4179 /*62*/ "\005\000\002\006\002"
4180 "GDT HA %u, Array Drive %u: parity verify started",
4181 /*63*/ "\005\000\002\006\002"
4182 "GDT HA %u, Array Drive %u: parity verify done",
4183 /*64*/ "\005\000\002\006\002"
4184 "GDT HA %u, Array Drive %u: parity verify failed",
4185 /*65*/ "\005\000\002\006\002"
4186 "GDT HA %u, Array Drive %u: parity error detected",
4187 /*66*/ "\005\000\002\006\002"
4188 "GDT HA %u, Array Drive %u: parity verify quited",
4189 /*67*/ "\005\000\002\006\002"
4190 "GDT HA %u, Host Drive %u reserved",
4191 /*68*/ "\005\000\002\006\002"
4192 "GDT HA %u, Host Drive %u mounted and released",
4193 /*69*/ "\005\000\002\006\002"
4194 "GDT HA %u, Host Drive %u released",
4195 /*70*/ "\003\000\002"
4196 "GDT HA %u, DRAM error detected and corrected with ECC",
4197 /*71*/ "\003\000\002"
4198 "GDT HA %u, Uncorrectable DRAM error detected with ECC",
4199 /*72*/ "\011\000\002\012\001\013\001\014\001"
4200 "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
4201 /*73*/ "\005\000\002\006\002"
4202 "GDT HA %u, Host drive %u resetted locally",
4203 /*74*/ "\005\000\002\006\002"
4204 "GDT HA %u, Host drive %u resetted remotely",
4205 /*75*/ "\003\000\002"
4206 "GDT HA %u, async. status 75 unknown",
4210 static int gdth_async_event(int hanum
)
4216 ha
= HADATA(gdth_ctr_tab
[hanum
]);
4218 TRACE2(("gdth_async_event() ha %d serv %d\n",
4219 hanum
,ha
->service
));
4221 if (ha
->service
== SCREENSERVICE
) {
4222 if (ha
->status
== MSG_REQUEST
) {
4223 while (gdth_test_busy(hanum
))
4225 cmdp
->Service
= SCREENSERVICE
;
4226 cmdp
->RequestBuffer
= SCREEN_CMND
;
4227 cmd_index
= gdth_get_cmd_index(hanum
);
4228 gdth_set_sema0(hanum
);
4229 cmdp
->OpCode
= GDT_READ
;
4230 cmdp
->BoardNode
= LOCALBOARD
;
4231 cmdp
->u
.screen
.reserved
= 0;
4232 cmdp
->u
.screen
.su
.msg
.msg_handle
= MSG_INV_HANDLE
;
4233 cmdp
->u
.screen
.su
.msg
.msg_addr
= ha
->msg_phys
;
4234 ha
->cmd_offs_dpmem
= 0;
4235 ha
->cmd_len
= GDTOFFSOF(gdth_cmd_str
,u
.screen
.su
.msg
.msg_addr
)
4238 gdth_copy_command(hanum
);
4239 if (ha
->type
== GDT_EISA
)
4240 printk("[EISA slot %d] ",(ushort
)ha
->brd_phys
);
4241 else if (ha
->type
== GDT_ISA
)
4242 printk("[DPMEM 0x%4X] ",(ushort
)ha
->brd_phys
);
4244 printk("[PCI %d/%d] ",(ushort
)(ha
->brd_phys
>>8),
4245 (ushort
)((ha
->brd_phys
>>3)&0x1f));
4246 gdth_release_event(hanum
);
4250 if (ha
->type
== GDT_PCIMPR
&&
4251 (ha
->fw_vers
& 0xff) >= 0x1a) {
4253 ha
->dvr
.eu
.async
.ionode
= hanum
;
4254 ha
->dvr
.eu
.async
.status
= ha
->status
;
4255 /* severity and event_string already set! */
4257 ha
->dvr
.size
= sizeof(ha
->dvr
.eu
.async
);
4258 ha
->dvr
.eu
.async
.ionode
= hanum
;
4259 ha
->dvr
.eu
.async
.service
= ha
->service
;
4260 ha
->dvr
.eu
.async
.status
= ha
->status
;
4261 ha
->dvr
.eu
.async
.info
= ha
->info
;
4262 *(ulong32
*)ha
->dvr
.eu
.async
.scsi_coord
= ha
->info2
;
4264 gdth_store_event( ha
, ES_ASYNC
, ha
->service
, &ha
->dvr
);
4265 gdth_log_event( &ha
->dvr
, NULL
);
4267 /* new host drive from expand? */
4268 if (ha
->service
== CACHESERVICE
&& ha
->status
== 56) {
4269 TRACE2(("gdth_async_event(): new host drive %d created\n",
4271 /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
4277 static void gdth_log_event(gdth_evt_data
*dvr
, char *buffer
)
4279 gdth_stackframe stack
;
4283 TRACE2(("gdth_log_event()\n"));
4284 if (dvr
->size
== 0) {
4285 if (buffer
== NULL
) {
4286 printk("Adapter %d: %s\n",dvr
->eu
.async
.ionode
,dvr
->event_string
);
4288 sprintf(buffer
,"Adapter %d: %s\n",
4289 dvr
->eu
.async
.ionode
,dvr
->event_string
);
4291 } else if (dvr
->eu
.async
.service
== CACHESERVICE
&&
4292 INDEX_OK(dvr
->eu
.async
.status
, async_cache_tab
)) {
4293 TRACE2(("GDT: Async. event cache service, event no.: %d\n",
4294 dvr
->eu
.async
.status
));
4296 f
= async_cache_tab
[dvr
->eu
.async
.status
];
4298 /* i: parameter to push, j: stack element to fill */
4299 for (j
=0,i
=1; i
< f
[0]; i
+=2) {
4302 stack
.b
[j
++] = *(ulong32
*)&dvr
->eu
.stream
[(int)f
[i
]];
4305 stack
.b
[j
++] = *(ushort
*)&dvr
->eu
.stream
[(int)f
[i
]];
4308 stack
.b
[j
++] = *(unchar
*)&dvr
->eu
.stream
[(int)f
[i
]];
4315 if (buffer
== NULL
) {
4316 printk(&f
[(int)f
[0]],stack
);
4319 sprintf(buffer
,&f
[(int)f
[0]],stack
);
4323 if (buffer
== NULL
) {
4324 printk("GDT HA %u, Unknown async. event service %d event no. %d\n",
4325 dvr
->eu
.async
.ionode
,dvr
->eu
.async
.service
,dvr
->eu
.async
.status
);
4327 sprintf(buffer
,"GDT HA %u, Unknown async. event service %d event no. %d",
4328 dvr
->eu
.async
.ionode
,dvr
->eu
.async
.service
,dvr
->eu
.async
.status
);
4333 #ifdef GDTH_STATISTICS
4334 void gdth_timeout(ulong data
)
4342 ha
= HADATA(gdth_ctr_tab
[hanum
]);
4343 GDTH_LOCK_HA(ha
, flags
);
4345 for (act_stats
=0,i
=0; i
<GDTH_MAXCMDS
; ++i
)
4346 if (ha
->cmd_tab
[i
].cmnd
!= UNUSED_CMND
)
4349 for (act_rq
=0,nscp
=ha
->req_first
; nscp
; nscp
=(Scsi_Cmnd
*)nscp
->SCp
.ptr
)
4352 TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
4353 act_ints
, act_ios
, act_stats
, act_rq
));
4354 act_ints
= act_ios
= 0;
4356 gdth_timer
.expires
= jiffies
+ 30 * HZ
;
4357 add_timer(&gdth_timer
);
4358 GDTH_UNLOCK_HA(ha
, flags
);
4362 GDTH_INITFUNC(void, internal_setup(char *str
,int *ints
))
4365 char *cur_str
, *argv
;
4367 TRACE2(("internal_setup() str %s ints[0] %d\n",
4368 str
? str
:"NULL", ints
? ints
[0]:0));
4370 /* read irq[] from ints[] */
4376 for (i
= 0; i
< argc
; ++i
)
4381 /* analyse string */
4383 while (argv
&& (cur_str
= strchr(argv
, ':'))) {
4384 int val
= 0, c
= *++cur_str
;
4386 if (c
== 'n' || c
== 'N')
4388 else if (c
== 'y' || c
== 'Y')
4391 val
= (int)simple_strtoul(cur_str
, NULL
, 0);
4393 if (!strncmp(argv
, "disable:", 8))
4395 else if (!strncmp(argv
, "reserve_mode:", 13))
4397 else if (!strncmp(argv
, "reverse_scan:", 13))
4399 else if (!strncmp(argv
, "hdr_channel:", 12))
4401 else if (!strncmp(argv
, "max_ids:", 8))
4403 else if (!strncmp(argv
, "rescan:", 7))
4405 else if (!strncmp(argv
, "virt_ctr:", 9))
4407 else if (!strncmp(argv
, "shared_access:", 14))
4408 shared_access
= val
;
4409 else if (!strncmp(argv
, "probe_eisa_isa:", 15))
4410 probe_eisa_isa
= val
;
4411 else if (!strncmp(argv
, "reserve_list:", 13)) {
4412 reserve_list
[0] = val
;
4413 for (i
= 1; i
< MAX_RES_ARGS
; i
++) {
4414 cur_str
= strchr(cur_str
, ',');
4417 if (!isdigit((int)*++cur_str
)) {
4422 (int)simple_strtoul(cur_str
, NULL
, 0);
4430 if ((argv
= strchr(argv
, ',')))
4435 GDTH_INITFUNC(int, option_setup(char *str
))
4441 TRACE2(("option_setup() str %s\n", str
? str
:"NULL"));
4443 while (cur
&& isdigit(*cur
) && i
<= MAXHA
) {
4444 ints
[i
++] = simple_strtoul(cur
, NULL
, 0);
4445 if ((cur
= strchr(cur
, ',')) != NULL
) cur
++;
4449 internal_setup(cur
, ints
);
4453 GDTH_INITFUNC(int, gdth_detect(Scsi_Host_Template
*shtp
))
4455 struct Scsi_Host
*shp
;
4456 gdth_pci_str pcistr
[MAXHA
];
4460 int i
,hanum
,cnt
,ctr
,err
;
4465 printk("GDT: This driver contains debugging information !! Trace level = %d\n",
4467 printk(" Destination of debugging information: ");
4470 printk("Serial port COM2\n");
4472 printk("Serial port COM1\n");
4475 printk("Console\n");
4480 TRACE(("gdth_detect()\n"));
4483 printk("GDT-HA: Controller driver disabled from command line !\n");
4487 printk("GDT-HA: Storage RAID Controller Driver. Version: %s \n",GDTH_VERSION_STR
);
4488 /* initializations */
4489 gdth_polling
= TRUE
; b
= 0;
4490 gdth_clear_events();
4492 /* As default we do not probe for EISA or ISA controllers */
4493 if (probe_eisa_isa
) {
4494 /* scanning for controllers, at first: ISA controller */
4495 for (isa_bios
=0xc8000UL
; isa_bios
<=0xd8000UL
; isa_bios
+=0x8000UL
) {
4496 dma_addr_t scratch_dma_handle
;
4497 scratch_dma_handle
= 0;
4499 if (gdth_ctr_count
>= MAXHA
)
4501 if (gdth_search_isa(isa_bios
)) { /* controller found */
4502 shp
= scsi_register(shtp
,sizeof(gdth_ext_str
));
4507 if (!gdth_init_isa(isa_bios
,ha
)) {
4508 scsi_unregister(shp
);
4514 /* controller found and initialized */
4515 printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
4516 isa_bios
,ha
->irq
,ha
->drq
);
4518 if (request_irq(ha
->irq
,gdth_interrupt
,SA_INTERRUPT
,"gdth",ha
)) {
4519 printk("GDT-ISA: Unable to allocate IRQ\n");
4520 scsi_unregister(shp
);
4523 if (request_dma(ha
->drq
,"gdth")) {
4524 printk("GDT-ISA: Unable to allocate DMA channel\n");
4525 free_irq(ha
->irq
,ha
);
4526 scsi_unregister(shp
);
4529 set_dma_mode(ha
->drq
,DMA_MODE_CASCADE
);
4530 enable_dma(ha
->drq
);
4531 shp
->unchecked_isa_dma
= 1;
4533 shp
->dma_channel
= ha
->drq
;
4534 hanum
= gdth_ctr_count
;
4535 gdth_ctr_tab
[gdth_ctr_count
++] = shp
;
4536 gdth_ctr_vtab
[gdth_ctr_vcount
++] = shp
;
4538 NUMDATA(shp
)->hanum
= (ushort
)hanum
;
4539 NUMDATA(shp
)->busnum
= 0;
4541 ha
->pccb
= CMDDATA(shp
);
4543 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4545 ha
->pscratch
= pci_alloc_consistent(ha
->pdev
, GDTH_SCRATCH
,
4546 &scratch_dma_handle
);
4547 ha
->scratch_phys
= scratch_dma_handle
;
4548 ha
->pmsg
= pci_alloc_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4549 &scratch_dma_handle
);
4550 ha
->msg_phys
= scratch_dma_handle
;
4552 ha
->coal_stat
= (gdth_coal_status
*)
4553 pci_alloc_consistent(ha
->pdev
, sizeof(gdth_coal_status
) *
4554 MAXOFFSETS
, &scratch_dma_handle
);
4555 ha
->coal_stat_phys
= scratch_dma_handle
;
4558 ha
->pscratch
= scsi_init_malloc(GDTH_SCRATCH
, GFP_ATOMIC
| GFP_DMA
);
4560 ha
->scratch_phys
= virt_to_bus(ha
->pscratch
);
4561 ha
->pmsg
= scsi_init_malloc(sizeof(gdth_msg_str
), GFP_ATOMIC
| GFP_DMA
);
4563 ha
->msg_phys
= virt_to_bus(ha
->pmsg
);
4566 scsi_init_malloc(sizeof(gdth_coal_status
) * MAXOFFSETS
,
4567 GFP_ATOMIC
| GFP_DMA
);
4569 ha
->coal_stat_phys
= virt_to_bus(ha
->coal_stat
);
4572 ha
->scratch_busy
= FALSE
;
4573 ha
->req_first
= NULL
;
4574 ha
->tid_cnt
= MAX_HDRIVES
;
4575 if (max_ids
> 0 && max_ids
< ha
->tid_cnt
)
4576 ha
->tid_cnt
= max_ids
;
4577 for (i
=0; i
<GDTH_MAXCMDS
; ++i
)
4578 ha
->cmd_tab
[i
].cmnd
= UNUSED_CMND
;
4579 ha
->scan_mode
= rescan
? 0x10 : 0;
4581 if (ha
->pscratch
== NULL
|| ha
->pmsg
== NULL
||
4582 !gdth_search_drives(hanum
)) {
4583 printk("GDT-ISA: Error during device scan\n");
4586 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4589 pci_free_consistent(ha
->pdev
, sizeof(gdth_coal_status
) *
4590 MAXOFFSETS
, ha
->coal_stat
,
4591 ha
->coal_stat_phys
);
4594 pci_free_consistent(ha
->pdev
, GDTH_SCRATCH
,
4595 ha
->pscratch
, ha
->scratch_phys
);
4597 pci_free_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4598 ha
->pmsg
, ha
->msg_phys
);
4602 scsi_init_free((void *)ha
->coal_stat
,
4603 sizeof(gdth_coal_status
) * MAXOFFSETS
);
4606 scsi_init_free((void *)ha
->pscratch
, GDTH_SCRATCH
);
4608 scsi_init_free((void *)ha
->pmsg
, sizeof(gdth_msg_str
));
4610 free_irq(ha
->irq
,ha
);
4611 scsi_unregister(shp
);
4614 if (hdr_channel
< 0 || hdr_channel
> ha
->bus_cnt
)
4615 hdr_channel
= ha
->bus_cnt
;
4616 ha
->virt_bus
= hdr_channel
;
4618 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4619 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
4620 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4621 shp
->highmem_io
= 0;
4623 if (ha
->cache_feat
& ha
->raw_feat
& ha
->screen_feat
& GDT_64BIT
)
4624 shp
->max_cmd_len
= 16;
4626 shp
->max_id
= ha
->tid_cnt
;
4627 shp
->max_lun
= MAXLUN
;
4628 shp
->max_channel
= virt_ctr
? 0 : ha
->bus_cnt
;
4631 /* register addit. SCSI channels as virtual controllers */
4632 for (b
= 1; b
< ha
->bus_cnt
+ 1; ++b
) {
4633 shp
= scsi_register(shtp
,sizeof(gdth_num_str
));
4634 shp
->unchecked_isa_dma
= 1;
4636 shp
->dma_channel
= ha
->drq
;
4637 gdth_ctr_vtab
[gdth_ctr_vcount
++] = shp
;
4638 NUMDATA(shp
)->hanum
= (ushort
)hanum
;
4639 NUMDATA(shp
)->busnum
= b
;
4643 GDTH_INIT_LOCK_HA(ha
);
4644 gdth_enable_int(hanum
);
4645 #endif /* !__ia64__ */
4649 /* scanning for EISA controllers */
4650 for (eisa_slot
=0x1000; eisa_slot
<=0x8000; eisa_slot
+=0x1000) {
4651 dma_addr_t scratch_dma_handle
;
4652 scratch_dma_handle
= 0;
4654 if (gdth_ctr_count
>= MAXHA
)
4656 if (gdth_search_eisa(eisa_slot
)) { /* controller found */
4657 shp
= scsi_register(shtp
,sizeof(gdth_ext_str
));
4662 if (!gdth_init_eisa(eisa_slot
,ha
)) {
4663 scsi_unregister(shp
);
4666 /* controller found and initialized */
4667 printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
4668 eisa_slot
>>12,ha
->irq
);
4670 if (request_irq(ha
->irq
,gdth_interrupt
,SA_INTERRUPT
,"gdth",ha
)) {
4671 printk("GDT-EISA: Unable to allocate IRQ\n");
4672 scsi_unregister(shp
);
4675 shp
->unchecked_isa_dma
= 0;
4677 shp
->dma_channel
= 0xff;
4678 hanum
= gdth_ctr_count
;
4679 gdth_ctr_tab
[gdth_ctr_count
++] = shp
;
4680 gdth_ctr_vtab
[gdth_ctr_vcount
++] = shp
;
4682 NUMDATA(shp
)->hanum
= (ushort
)hanum
;
4683 NUMDATA(shp
)->busnum
= 0;
4684 TRACE2(("EISA detect Bus 0: hanum %d\n",
4685 NUMDATA(shp
)->hanum
));
4687 ha
->pccb
= CMDDATA(shp
);
4689 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4691 ha
->pscratch
= pci_alloc_consistent(ha
->pdev
, GDTH_SCRATCH
,
4692 &scratch_dma_handle
);
4693 ha
->scratch_phys
= scratch_dma_handle
;
4694 ha
->pmsg
= pci_alloc_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4695 &scratch_dma_handle
);
4696 ha
->msg_phys
= scratch_dma_handle
;
4698 ha
->coal_stat
= (gdth_coal_status
*)
4699 pci_alloc_consistent(ha
->pdev
, sizeof(gdth_coal_status
) *
4700 MAXOFFSETS
, &scratch_dma_handle
);
4701 ha
->coal_stat_phys
= scratch_dma_handle
;
4704 pci_map_single(ha
->pdev
,ha
->pccb
,
4705 sizeof(gdth_cmd_str
),PCI_DMA_BIDIRECTIONAL
);
4707 ha
->pscratch
= scsi_init_malloc(GDTH_SCRATCH
, GFP_ATOMIC
| GFP_DMA
);
4709 ha
->scratch_phys
= virt_to_bus(ha
->pscratch
);
4710 ha
->pmsg
= scsi_init_malloc(sizeof(gdth_msg_str
), GFP_ATOMIC
| GFP_DMA
);
4712 ha
->msg_phys
= virt_to_bus(ha
->pmsg
);
4715 scsi_init_malloc(sizeof(gdth_coal_status
) * MAXOFFSETS
,
4716 GFP_ATOMIC
| GFP_DMA
);
4718 ha
->coal_stat_phys
= virt_to_bus(ha
->coal_stat
);
4720 ha
->ccb_phys
= virt_to_bus(ha
->pccb
);
4722 ha
->scratch_busy
= FALSE
;
4723 ha
->req_first
= NULL
;
4724 ha
->tid_cnt
= MAX_HDRIVES
;
4725 if (max_ids
> 0 && max_ids
< ha
->tid_cnt
)
4726 ha
->tid_cnt
= max_ids
;
4727 for (i
=0; i
<GDTH_MAXCMDS
; ++i
)
4728 ha
->cmd_tab
[i
].cmnd
= UNUSED_CMND
;
4729 ha
->scan_mode
= rescan
? 0x10 : 0;
4731 if (ha
->pscratch
== NULL
|| ha
->pmsg
== NULL
||
4732 !gdth_search_drives(hanum
)) {
4733 printk("GDT-EISA: Error during device scan\n");
4736 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4739 pci_free_consistent(ha
->pdev
, sizeof(gdth_coal_status
) *
4740 MAXOFFSETS
, ha
->coal_stat
,
4741 ha
->coal_stat_phys
);
4744 pci_free_consistent(ha
->pdev
, GDTH_SCRATCH
,
4745 ha
->pscratch
, ha
->scratch_phys
);
4747 pci_free_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4748 ha
->pmsg
, ha
->msg_phys
);
4750 pci_unmap_single(ha
->pdev
,ha
->ccb_phys
,
4751 sizeof(gdth_cmd_str
),PCI_DMA_BIDIRECTIONAL
);
4755 scsi_init_free((void *)ha
->coal_stat
,
4756 sizeof(gdth_coal_status
) * MAXOFFSETS
);
4759 scsi_init_free((void *)ha
->pscratch
, GDTH_SCRATCH
);
4761 scsi_init_free((void *)ha
->pmsg
, sizeof(gdth_msg_str
));
4763 free_irq(ha
->irq
,ha
);
4764 scsi_unregister(shp
);
4767 if (hdr_channel
< 0 || hdr_channel
> ha
->bus_cnt
)
4768 hdr_channel
= ha
->bus_cnt
;
4769 ha
->virt_bus
= hdr_channel
;
4771 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4772 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
4773 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4774 shp
->highmem_io
= 0;
4776 if (ha
->cache_feat
& ha
->raw_feat
& ha
->screen_feat
& GDT_64BIT
)
4777 shp
->max_cmd_len
= 16;
4779 shp
->max_id
= ha
->tid_cnt
;
4780 shp
->max_lun
= MAXLUN
;
4781 shp
->max_channel
= virt_ctr
? 0 : ha
->bus_cnt
;
4784 /* register addit. SCSI channels as virtual controllers */
4785 for (b
= 1; b
< ha
->bus_cnt
+ 1; ++b
) {
4786 shp
= scsi_register(shtp
,sizeof(gdth_num_str
));
4787 shp
->unchecked_isa_dma
= 0;
4789 shp
->dma_channel
= 0xff;
4790 gdth_ctr_vtab
[gdth_ctr_vcount
++] = shp
;
4791 NUMDATA(shp
)->hanum
= (ushort
)hanum
;
4792 NUMDATA(shp
)->busnum
= b
;
4796 GDTH_INIT_LOCK_HA(ha
);
4797 gdth_enable_int(hanum
);
4802 /* scanning for PCI controllers */
4803 cnt
= gdth_search_pci(pcistr
);
4804 printk("GDT-HA: Found %d PCI Storage RAID Controllers\n",cnt
);
4805 gdth_sort_pci(pcistr
,cnt
);
4806 for (ctr
= 0; ctr
< cnt
; ++ctr
) {
4807 dma_addr_t scratch_dma_handle
;
4808 scratch_dma_handle
= 0;
4810 if (gdth_ctr_count
>= MAXHA
)
4812 shp
= scsi_register(shtp
,sizeof(gdth_ext_str
));
4817 if (!gdth_init_pci(&pcistr
[ctr
],ha
)) {
4818 scsi_unregister(shp
);
4821 /* controller found and initialized */
4822 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
4823 pcistr
[ctr
].bus
,PCI_SLOT(pcistr
[ctr
].device_fn
),ha
->irq
);
4825 if (request_irq(ha
->irq
, gdth_interrupt
,
4826 SA_INTERRUPT
|SA_SHIRQ
, "gdth", ha
))
4828 printk("GDT-PCI: Unable to allocate IRQ\n");
4829 scsi_unregister(shp
);
4832 shp
->unchecked_isa_dma
= 0;
4834 shp
->dma_channel
= 0xff;
4835 hanum
= gdth_ctr_count
;
4836 gdth_ctr_tab
[gdth_ctr_count
++] = shp
;
4837 gdth_ctr_vtab
[gdth_ctr_vcount
++] = shp
;
4839 NUMDATA(shp
)->hanum
= (ushort
)hanum
;
4840 NUMDATA(shp
)->busnum
= 0;
4842 ha
->pccb
= CMDDATA(shp
);
4844 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4845 ha
->pscratch
= pci_alloc_consistent(ha
->pdev
, GDTH_SCRATCH
,
4846 &scratch_dma_handle
);
4847 ha
->scratch_phys
= scratch_dma_handle
;
4848 ha
->pmsg
= pci_alloc_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4849 &scratch_dma_handle
);
4850 ha
->msg_phys
= scratch_dma_handle
;
4852 ha
->coal_stat
= (gdth_coal_status
*)
4853 pci_alloc_consistent(ha
->pdev
, sizeof(gdth_coal_status
) *
4854 MAXOFFSETS
, &scratch_dma_handle
);
4855 ha
->coal_stat_phys
= scratch_dma_handle
;
4858 ha
->pscratch
= scsi_init_malloc(GDTH_SCRATCH
, GFP_ATOMIC
| GFP_DMA
);
4860 ha
->scratch_phys
= virt_to_bus(ha
->pscratch
);
4861 ha
->pmsg
= scsi_init_malloc(sizeof(gdth_msg_str
), GFP_ATOMIC
| GFP_DMA
);
4863 ha
->msg_phys
= virt_to_bus(ha
->pmsg
);
4866 scsi_init_malloc(sizeof(gdth_coal_status
) * MAXOFFSETS
,
4867 GFP_ATOMIC
| GFP_DMA
);
4869 ha
->coal_stat_phys
= virt_to_bus(ha
->coal_stat
);
4872 ha
->scratch_busy
= FALSE
;
4873 ha
->req_first
= NULL
;
4874 ha
->tid_cnt
= pcistr
[ctr
].device_id
>= 0x200 ? MAXID
: MAX_HDRIVES
;
4875 if (max_ids
> 0 && max_ids
< ha
->tid_cnt
)
4876 ha
->tid_cnt
= max_ids
;
4877 for (i
=0; i
<GDTH_MAXCMDS
; ++i
)
4878 ha
->cmd_tab
[i
].cmnd
= UNUSED_CMND
;
4879 ha
->scan_mode
= rescan
? 0x10 : 0;
4882 if (ha
->pscratch
== NULL
|| ha
->pmsg
== NULL
||
4883 !gdth_search_drives(hanum
)) {
4886 if (hdr_channel
< 0 || hdr_channel
> ha
->bus_cnt
)
4887 hdr_channel
= ha
->bus_cnt
;
4888 ha
->virt_bus
= hdr_channel
;
4890 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4891 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4892 scsi_set_device(shp
, &pcistr
[ctr
].pdev
->dev
);
4894 scsi_set_pci_device(shp
, pcistr
[ctr
].pdev
);
4896 if (!(ha
->cache_feat
& ha
->raw_feat
& ha
->screen_feat
&GDT_64BIT
)||
4897 /* 64-bit DMA only supported from FW >= x.43 */
4898 (!ha
->dma64_support
)) {
4899 if (pci_set_dma_mask(pcistr
[ctr
].pdev
, 0xffffffff)) {
4900 printk(KERN_WARNING
"GDT-PCI %d: Unable to set 32-bit DMA\n", hanum
);
4904 shp
->max_cmd_len
= 16;
4905 if (!pci_set_dma_mask(pcistr
[ctr
].pdev
, 0xffffffffffffffffULL
)) {
4906 printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum
);
4907 } else if (pci_set_dma_mask(pcistr
[ctr
].pdev
, 0xffffffff)) {
4908 printk(KERN_WARNING
"GDT-PCI %d: Unable to set 64/32-bit DMA\n", hanum
);
4916 printk("GDT-PCI %d: Error during device scan\n", hanum
);
4919 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4922 pci_free_consistent(ha
->pdev
, sizeof(gdth_coal_status
) *
4923 MAXOFFSETS
, ha
->coal_stat
,
4924 ha
->coal_stat_phys
);
4927 pci_free_consistent(ha
->pdev
, GDTH_SCRATCH
,
4928 ha
->pscratch
, ha
->scratch_phys
);
4930 pci_free_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
4931 ha
->pmsg
, ha
->msg_phys
);
4935 scsi_init_free((void *)ha
->coal_stat
,
4936 sizeof(gdth_coal_status
) * MAXOFFSETS
);
4939 scsi_init_free((void *)ha
->pscratch
, GDTH_SCRATCH
);
4941 scsi_init_free((void *)ha
->pmsg
, sizeof(gdth_msg_str
));
4943 free_irq(ha
->irq
,ha
);
4944 scsi_unregister(shp
);
4948 shp
->max_id
= ha
->tid_cnt
;
4949 shp
->max_lun
= MAXLUN
;
4950 shp
->max_channel
= virt_ctr
? 0 : ha
->bus_cnt
;
4953 /* register addit. SCSI channels as virtual controllers */
4954 for (b
= 1; b
< ha
->bus_cnt
+ 1; ++b
) {
4955 shp
= scsi_register(shtp
,sizeof(gdth_num_str
));
4956 shp
->unchecked_isa_dma
= 0;
4958 shp
->dma_channel
= 0xff;
4959 gdth_ctr_vtab
[gdth_ctr_vcount
++] = shp
;
4960 NUMDATA(shp
)->hanum
= (ushort
)hanum
;
4961 NUMDATA(shp
)->busnum
= b
;
4966 GDTH_INIT_LOCK_HA(ha
);
4967 gdth_enable_int(hanum
);
4970 TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count
));
4971 if (gdth_ctr_count
> 0) {
4972 #ifdef GDTH_STATISTICS
4973 TRACE2(("gdth_detect(): Initializing timer !\n"));
4974 init_timer(&gdth_timer
);
4975 gdth_timer
.expires
= jiffies
+ HZ
;
4976 gdth_timer
.data
= 0L;
4977 gdth_timer
.function
= gdth_timeout
;
4978 add_timer(&gdth_timer
);
4980 major
= register_chrdev(0,"gdth",&gdth_fops
);
4981 register_reboot_notifier(&gdth_notifier
);
4983 gdth_polling
= FALSE
;
4984 return gdth_ctr_vcount
;
4988 int gdth_release(struct Scsi_Host
*shp
)
4993 TRACE2(("gdth_release()\n"));
4994 if (NUMDATA(shp
)->busnum
== 0) {
4995 hanum
= NUMDATA(shp
)->hanum
;
4996 ha
= HADATA(gdth_ctr_tab
[hanum
]);
4997 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4999 scsi_free_host_dev(ha
->sdev
);
5006 free_irq(shp
->irq
,ha
);
5009 if (shp
->dma_channel
!= 0xff) {
5010 free_dma(shp
->dma_channel
);
5013 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5016 pci_free_consistent(ha
->pdev
, sizeof(gdth_coal_status
) *
5017 MAXOFFSETS
, ha
->coal_stat
, ha
->coal_stat_phys
);
5020 pci_free_consistent(ha
->pdev
, GDTH_SCRATCH
,
5021 ha
->pscratch
, ha
->scratch_phys
);
5023 pci_free_consistent(ha
->pdev
, sizeof(gdth_msg_str
),
5024 ha
->pmsg
, ha
->msg_phys
);
5026 pci_unmap_single(ha
->pdev
,ha
->ccb_phys
,
5027 sizeof(gdth_cmd_str
),PCI_DMA_BIDIRECTIONAL
);
5031 scsi_init_free((void *)ha
->coal_stat
,
5032 sizeof(gdth_coal_status
) * MAXOFFSETS
);
5035 scsi_init_free((void *)ha
->pscratch
, GDTH_SCRATCH
);
5037 scsi_init_free((void *)ha
->pmsg
, sizeof(gdth_msg_str
));
5039 gdth_ctr_released
++;
5040 TRACE2(("gdth_release(): HA %d of %d\n",
5041 gdth_ctr_released
, gdth_ctr_count
));
5043 if (gdth_ctr_released
== gdth_ctr_count
) {
5044 #ifdef GDTH_STATISTICS
5045 del_timer(&gdth_timer
);
5047 unregister_chrdev(major
,"gdth");
5048 unregister_reboot_notifier(&gdth_notifier
);
5052 scsi_unregister(shp
);
5057 static const char *gdth_ctr_name(int hanum
)
5061 TRACE2(("gdth_ctr_name()\n"));
5063 ha
= HADATA(gdth_ctr_tab
[hanum
]);
5065 if (ha
->type
== GDT_EISA
) {
5066 switch (ha
->stype
) {
5068 return("GDT3000/3020");
5070 return("GDT3000A/3020A/3050A");
5072 return("GDT3000B/3010A");
5074 } else if (ha
->type
== GDT_ISA
) {
5075 return("GDT2000/2020");
5076 } else if (ha
->type
== GDT_PCI
) {
5077 switch (ha
->stype
) {
5078 case PCI_DEVICE_ID_VORTEX_GDT60x0
:
5079 return("GDT6000/6020/6050");
5080 case PCI_DEVICE_ID_VORTEX_GDT6000B
:
5081 return("GDT6000B/6010");
5084 /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
5089 const char *gdth_info(struct Scsi_Host
*shp
)
5094 TRACE2(("gdth_info()\n"));
5095 hanum
= NUMDATA(shp
)->hanum
;
5096 ha
= HADATA(gdth_ctr_tab
[hanum
]);
5098 return ((const char *)ha
->binfo
.type_string
);
5101 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
5102 /* old error handling */
5103 int gdth_abort(Scsi_Cmnd
*scp
)
5105 TRACE2(("gdth_abort() reason %d\n",scp
->abort_reason
));
5106 return SCSI_ABORT_SNOOZE
;
5109 int gdth_reset(Scsi_Cmnd
*scp
, unsigned int reset_flags
)
5111 TRACE2(("gdth_reset()\n"));
5112 return SCSI_RESET_PUNT
;
5116 /* new error handling */
5117 int gdth_eh_abort(Scsi_Cmnd
*scp
)
5119 TRACE2(("gdth_eh_abort()\n"));
5123 int gdth_eh_device_reset(Scsi_Cmnd
*scp
)
5125 TRACE2(("gdth_eh_device_reset()\n"));
5129 int gdth_eh_bus_reset(Scsi_Cmnd
*scp
)
5137 TRACE2(("gdth_eh_bus_reset()\n"));
5138 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5139 hanum
= NUMDATA(scp
->device
->host
)->hanum
;
5140 b
= virt_ctr
? NUMDATA(scp
->device
->host
)->busnum
: scp
->device
->channel
;
5142 hanum
= NUMDATA(scp
->host
)->hanum
;
5143 b
= virt_ctr
? NUMDATA(scp
->host
)->busnum
: scp
->channel
;
5145 ha
= HADATA(gdth_ctr_tab
[hanum
]);
5147 /* clear command tab */
5148 GDTH_LOCK_HA(ha
, flags
);
5149 for (i
= 0; i
< GDTH_MAXCMDS
; ++i
) {
5150 cmnd
= ha
->cmd_tab
[i
].cmnd
;
5151 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5152 if (!SPECIAL_SCP(cmnd
) && cmnd
->device
->channel
== b
)
5154 if (!SPECIAL_SCP(cmnd
) && cmnd
->channel
== b
)
5156 ha
->cmd_tab
[i
].cmnd
= UNUSED_CMND
;
5158 GDTH_UNLOCK_HA(ha
, flags
);
5160 if (b
== ha
->virt_bus
) {
5162 for (i
= 0; i
< MAX_HDRIVES
; ++i
) {
5163 if (ha
->hdr
[i
].present
) {
5164 GDTH_LOCK_HA(ha
, flags
);
5165 gdth_polling
= TRUE
;
5166 while (gdth_test_busy(hanum
))
5168 if (gdth_internal_cmd(hanum
, CACHESERVICE
,
5169 GDT_CLUST_RESET
, i
, 0, 0))
5170 ha
->hdr
[i
].cluster_type
&= ~CLUSTER_RESERVED
;
5171 gdth_polling
= FALSE
;
5172 GDTH_UNLOCK_HA(ha
, flags
);
5177 GDTH_LOCK_HA(ha
, flags
);
5178 for (i
= 0; i
< MAXID
; ++i
)
5179 ha
->raw
[BUS_L2P(ha
,b
)].io_cnt
[i
] = 0;
5180 gdth_polling
= TRUE
;
5181 while (gdth_test_busy(hanum
))
5183 gdth_internal_cmd(hanum
, SCSIRAWSERVICE
, GDT_RESET_BUS
,
5184 BUS_L2P(ha
,b
), 0, 0);
5185 gdth_polling
= FALSE
;
5186 GDTH_UNLOCK_HA(ha
, flags
);
5191 int gdth_eh_host_reset(Scsi_Cmnd
*scp
)
5193 TRACE2(("gdth_eh_host_reset()\n"));
5198 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5199 int gdth_bios_param(struct scsi_device
*sdev
,struct block_device
*bdev
,sector_t cap
,int *ip
)
5201 int gdth_bios_param(Disk
*disk
,kdev_t dev
,int *ip
)
5207 struct scsi_device
*sd
;
5210 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5215 capacity
= disk
->capacity
;
5217 hanum
= NUMDATA(sd
->host
)->hanum
;
5218 b
= virt_ctr
? NUMDATA(sd
->host
)->busnum
: sd
->channel
;
5220 TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", hanum
, b
, t
));
5221 ha
= HADATA(gdth_ctr_tab
[hanum
]);
5223 if (b
!= ha
->virt_bus
|| ha
->hdr
[t
].heads
== 0) {
5224 /* raw device or host drive without mapping information */
5225 TRACE2(("Evaluate mapping\n"));
5226 gdth_eval_mapping(capacity
,&ip
[2],&ip
[0],&ip
[1]);
5228 ip
[0] = ha
->hdr
[t
].heads
;
5229 ip
[1] = ha
->hdr
[t
].secs
;
5230 ip
[2] = capacity
/ ip
[0] / ip
[1];
5233 TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
5234 ip
[0],ip
[1],ip
[2]));
5239 int gdth_queuecommand(Scsi_Cmnd
*scp
,void (*done
)(Scsi_Cmnd
*))
5244 TRACE(("gdth_queuecommand() cmd 0x%x\n", scp
->cmnd
[0]));
5246 scp
->scsi_done
= (void *)done
;
5247 scp
->SCp
.have_data_in
= 1;
5248 scp
->SCp
.phase
= -1;
5249 scp
->SCp
.sent_command
= -1;
5250 scp
->SCp
.Status
= GDTH_MAP_NONE
;
5251 scp
->SCp
.buffer
= (struct scatterlist
*)NULL
;
5252 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5253 hanum
= NUMDATA(scp
->device
->host
)->hanum
;
5255 hanum
= NUMDATA(scp
->host
)->hanum
;
5257 #ifdef GDTH_STATISTICS
5261 priority
= DEFAULT_PRI
;
5262 if (scp
->done
== gdth_scsi_done
)
5263 priority
= scp
->SCp
.this_residual
;
5264 gdth_update_timeout(hanum
, scp
, scp
->timeout_per_command
* 6);
5265 gdth_putq( hanum
, scp
, priority
);
5271 static int gdth_open(struct inode
*inode
, struct file
*filep
)
5273 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5277 for (i
= 0; i
< gdth_ctr_count
; i
++) {
5278 ha
= HADATA(gdth_ctr_tab
[i
]);
5280 ha
->sdev
= scsi_get_host_dev(gdth_ctr_tab
[i
]);
5284 TRACE(("gdth_open()\n"));
5288 static int gdth_close(struct inode
*inode
, struct file
*filep
)
5290 TRACE(("gdth_close()\n"));
5294 static int ioc_event(void __user
*arg
)
5296 gdth_ioctl_event evt
;
5300 if (copy_from_user(&evt
, arg
, sizeof(gdth_ioctl_event
)) ||
5301 evt
.ionode
>= gdth_ctr_count
)
5303 ha
= HADATA(gdth_ctr_tab
[evt
.ionode
]);
5305 if (evt
.erase
== 0xff) {
5306 if (evt
.event
.event_source
== ES_TEST
)
5307 evt
.event
.event_data
.size
=sizeof(evt
.event
.event_data
.eu
.test
);
5308 else if (evt
.event
.event_source
== ES_DRIVER
)
5309 evt
.event
.event_data
.size
=sizeof(evt
.event
.event_data
.eu
.driver
);
5310 else if (evt
.event
.event_source
== ES_SYNC
)
5311 evt
.event
.event_data
.size
=sizeof(evt
.event
.event_data
.eu
.sync
);
5313 evt
.event
.event_data
.size
=sizeof(evt
.event
.event_data
.eu
.async
);
5314 GDTH_LOCK_HA(ha
, flags
);
5315 gdth_store_event(ha
, evt
.event
.event_source
, evt
.event
.event_idx
,
5316 &evt
.event
.event_data
);
5317 GDTH_UNLOCK_HA(ha
, flags
);
5318 } else if (evt
.erase
== 0xfe) {
5319 gdth_clear_events();
5320 } else if (evt
.erase
== 0) {
5321 evt
.handle
= gdth_read_event(ha
, evt
.handle
, &evt
.event
);
5323 gdth_readapp_event(ha
, evt
.erase
, &evt
.event
);
5325 if (copy_to_user(arg
, &evt
, sizeof(gdth_ioctl_event
)))
5330 static int ioc_lockdrv(void __user
*arg
)
5332 gdth_ioctl_lockdrv ldrv
;
5337 if (copy_from_user(&ldrv
, arg
, sizeof(gdth_ioctl_lockdrv
)) ||
5338 ldrv
.ionode
>= gdth_ctr_count
)
5340 ha
= HADATA(gdth_ctr_tab
[ldrv
.ionode
]);
5342 for (i
= 0; i
< ldrv
.drive_cnt
&& i
< MAX_HDRIVES
; ++i
) {
5344 if (j
>= MAX_HDRIVES
|| !ha
->hdr
[j
].present
)
5347 GDTH_LOCK_HA(ha
, flags
);
5348 ha
->hdr
[j
].lock
= 1;
5349 GDTH_UNLOCK_HA(ha
, flags
);
5350 gdth_wait_completion(ldrv
.ionode
, ha
->bus_cnt
, j
);
5351 gdth_stop_timeout(ldrv
.ionode
, ha
->bus_cnt
, j
);
5353 GDTH_LOCK_HA(ha
, flags
);
5354 ha
->hdr
[j
].lock
= 0;
5355 GDTH_UNLOCK_HA(ha
, flags
);
5356 gdth_start_timeout(ldrv
.ionode
, ha
->bus_cnt
, j
);
5357 gdth_next(ldrv
.ionode
);
5363 static int ioc_resetdrv(void __user
*arg
, char *cmnd
)
5365 gdth_ioctl_reset res
;
5369 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5371 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5377 if (copy_from_user(&res
, arg
, sizeof(gdth_ioctl_reset
)) ||
5378 res
.ionode
>= gdth_ctr_count
|| res
.number
>= MAX_HDRIVES
)
5381 ha
= HADATA(gdth_ctr_tab
[hanum
]);
5383 if (!ha
->hdr
[res
.number
].present
)
5385 memset(&cmd
, 0, sizeof(gdth_cmd_str
));
5386 cmd
.Service
= CACHESERVICE
;
5387 cmd
.OpCode
= GDT_CLUST_RESET
;
5388 if (ha
->cache_feat
& GDT_64BIT
)
5389 cmd
.u
.cache64
.DeviceNo
= res
.number
;
5391 cmd
.u
.cache
.DeviceNo
= res
.number
;
5392 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5393 srp
= scsi_allocate_request(ha
->sdev
, GFP_KERNEL
);
5396 srp
->sr_cmd_len
= 12;
5398 gdth_do_req(srp
, &cmd
, cmnd
, 30);
5399 res
.status
= (ushort
)srp
->sr_command
->SCp
.Status
;
5400 scsi_release_request(srp
);
5401 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5402 scp
= scsi_allocate_device(ha
->sdev
, 1, FALSE
);
5407 gdth_do_cmd(scp
, &cmd
, cmnd
, 30);
5408 res
.status
= (ushort
)scp
->SCp
.Status
;
5409 scsi_release_command(scp
);
5411 memset(&ha
->sdev
,0,sizeof(Scsi_Device
));
5412 memset(&scp
, 0,sizeof(Scsi_Cmnd
));
5413 ha
->sdev
.host
= scp
.host
= gdth_ctr_tab
[hanum
];
5414 ha
->sdev
.id
= scp
.target
= ha
->sdev
.host
->this_id
;
5415 scp
.device
= &ha
->sdev
;
5416 gdth_do_cmd(&scp
, &cmd
, cmnd
, 30);
5417 res
.status
= (ushort
)scp
.SCp
.Status
;
5419 if (copy_to_user(arg
, &res
, sizeof(gdth_ioctl_reset
)))
5424 static int ioc_general(void __user
*arg
, char *cmnd
)
5426 gdth_ioctl_general gen
;
5431 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5433 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5439 if (copy_from_user(&gen
, arg
, sizeof(gdth_ioctl_general
)) ||
5440 gen
.ionode
>= gdth_ctr_count
)
5443 ha
= HADATA(gdth_ctr_tab
[hanum
]);
5444 if (gen
.data_len
+ gen
.sense_len
!= 0) {
5445 if (!(buf
= gdth_ioctl_alloc(hanum
, gen
.data_len
+ gen
.sense_len
,
5448 if (copy_from_user(buf
, arg
+ sizeof(gdth_ioctl_general
),
5449 gen
.data_len
+ gen
.sense_len
)) {
5450 gdth_ioctl_free(hanum
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
5454 if (gen
.command
.OpCode
== GDT_IOCTL
) {
5455 gen
.command
.u
.ioctl
.p_param
= paddr
;
5456 } else if (gen
.command
.Service
== CACHESERVICE
) {
5457 if (ha
->cache_feat
& GDT_64BIT
) {
5458 /* copy elements from 32-bit IOCTL structure */
5459 gen
.command
.u
.cache64
.BlockCnt
= gen
.command
.u
.cache
.BlockCnt
;
5460 gen
.command
.u
.cache64
.BlockNo
= gen
.command
.u
.cache
.BlockNo
;
5461 gen
.command
.u
.cache64
.DeviceNo
= gen
.command
.u
.cache
.DeviceNo
;
5463 if (ha
->cache_feat
& SCATTER_GATHER
) {
5464 gen
.command
.u
.cache64
.DestAddr
= (ulong64
)-1;
5465 gen
.command
.u
.cache64
.sg_canz
= 1;
5466 gen
.command
.u
.cache64
.sg_lst
[0].sg_ptr
= paddr
;
5467 gen
.command
.u
.cache64
.sg_lst
[0].sg_len
= gen
.data_len
;
5468 gen
.command
.u
.cache64
.sg_lst
[1].sg_len
= 0;
5470 gen
.command
.u
.cache64
.DestAddr
= paddr
;
5471 gen
.command
.u
.cache64
.sg_canz
= 0;
5474 if (ha
->cache_feat
& SCATTER_GATHER
) {
5475 gen
.command
.u
.cache
.DestAddr
= 0xffffffff;
5476 gen
.command
.u
.cache
.sg_canz
= 1;
5477 gen
.command
.u
.cache
.sg_lst
[0].sg_ptr
= (ulong32
)paddr
;
5478 gen
.command
.u
.cache
.sg_lst
[0].sg_len
= gen
.data_len
;
5479 gen
.command
.u
.cache
.sg_lst
[1].sg_len
= 0;
5481 gen
.command
.u
.cache
.DestAddr
= paddr
;
5482 gen
.command
.u
.cache
.sg_canz
= 0;
5485 } else if (gen
.command
.Service
== SCSIRAWSERVICE
) {
5486 if (ha
->raw_feat
& GDT_64BIT
) {
5487 /* copy elements from 32-bit IOCTL structure */
5489 gen
.command
.u
.raw64
.sense_len
= gen
.command
.u
.raw
.sense_len
;
5490 gen
.command
.u
.raw64
.bus
= gen
.command
.u
.raw
.bus
;
5491 gen
.command
.u
.raw64
.lun
= gen
.command
.u
.raw
.lun
;
5492 gen
.command
.u
.raw64
.target
= gen
.command
.u
.raw
.target
;
5493 memcpy(cmd
, gen
.command
.u
.raw
.cmd
, 16);
5494 memcpy(gen
.command
.u
.raw64
.cmd
, cmd
, 16);
5495 gen
.command
.u
.raw64
.clen
= gen
.command
.u
.raw
.clen
;
5496 gen
.command
.u
.raw64
.sdlen
= gen
.command
.u
.raw
.sdlen
;
5497 gen
.command
.u
.raw64
.direction
= gen
.command
.u
.raw
.direction
;
5499 if (ha
->raw_feat
& SCATTER_GATHER
) {
5500 gen
.command
.u
.raw64
.sdata
= (ulong64
)-1;
5501 gen
.command
.u
.raw64
.sg_ranz
= 1;
5502 gen
.command
.u
.raw64
.sg_lst
[0].sg_ptr
= paddr
;
5503 gen
.command
.u
.raw64
.sg_lst
[0].sg_len
= gen
.data_len
;
5504 gen
.command
.u
.raw64
.sg_lst
[1].sg_len
= 0;
5506 gen
.command
.u
.raw64
.sdata
= paddr
;
5507 gen
.command
.u
.raw64
.sg_ranz
= 0;
5509 gen
.command
.u
.raw64
.sense_data
= paddr
+ gen
.data_len
;
5511 if (ha
->raw_feat
& SCATTER_GATHER
) {
5512 gen
.command
.u
.raw
.sdata
= 0xffffffff;
5513 gen
.command
.u
.raw
.sg_ranz
= 1;
5514 gen
.command
.u
.raw
.sg_lst
[0].sg_ptr
= (ulong32
)paddr
;
5515 gen
.command
.u
.raw
.sg_lst
[0].sg_len
= gen
.data_len
;
5516 gen
.command
.u
.raw
.sg_lst
[1].sg_len
= 0;
5518 gen
.command
.u
.raw
.sdata
= paddr
;
5519 gen
.command
.u
.raw
.sg_ranz
= 0;
5521 gen
.command
.u
.raw
.sense_data
= (ulong32
)paddr
+ gen
.data_len
;
5524 gdth_ioctl_free(hanum
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
5529 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5530 srp
= scsi_allocate_request(ha
->sdev
, GFP_KERNEL
);
5533 srp
->sr_cmd_len
= 12;
5535 gdth_do_req(srp
, &gen
.command
, cmnd
, gen
.timeout
);
5536 gen
.status
= srp
->sr_command
->SCp
.Status
;
5537 gen
.info
= srp
->sr_command
->SCp
.Message
;
5538 scsi_release_request(srp
);
5539 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5540 scp
= scsi_allocate_device(ha
->sdev
, 1, FALSE
);
5545 gdth_do_cmd(scp
, &gen
.command
, cmnd
, gen
.timeout
);
5546 gen
.status
= scp
->SCp
.Status
;
5547 gen
.info
= scp
->SCp
.Message
;
5548 scsi_release_command(scp
);
5550 memset(&ha
->sdev
,0,sizeof(Scsi_Device
));
5551 memset(&scp
, 0,sizeof(Scsi_Cmnd
));
5552 ha
->sdev
.host
= scp
.host
= gdth_ctr_tab
[hanum
];
5553 ha
->sdev
.id
= scp
.target
= ha
->sdev
.host
->this_id
;
5554 scp
.device
= &ha
->sdev
;
5555 gdth_do_cmd(&scp
, &gen
.command
, cmnd
, gen
.timeout
);
5556 gen
.status
= scp
.SCp
.Status
;
5557 gen
.info
= scp
.SCp
.Message
;
5560 if (copy_to_user(arg
+ sizeof(gdth_ioctl_general
), buf
,
5561 gen
.data_len
+ gen
.sense_len
)) {
5562 gdth_ioctl_free(hanum
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
5565 if (copy_to_user(arg
, &gen
,
5566 sizeof(gdth_ioctl_general
) - sizeof(gdth_cmd_str
))) {
5567 gdth_ioctl_free(hanum
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
5570 gdth_ioctl_free(hanum
, gen
.data_len
+gen
.sense_len
, buf
, paddr
);
5574 static int ioc_hdrlist(void __user
*arg
, char *cmnd
)
5576 gdth_ioctl_rescan rsc
;
5581 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5583 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5589 if (copy_from_user(&rsc
, arg
, sizeof(gdth_ioctl_rescan
)) ||
5590 rsc
.ionode
>= gdth_ctr_count
)
5593 ha
= HADATA(gdth_ctr_tab
[hanum
]);
5594 memset(&cmd
, 0, sizeof(gdth_cmd_str
));
5596 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5597 srp
= scsi_allocate_request(ha
->sdev
, GFP_KERNEL
);
5600 srp
->sr_cmd_len
= 12;
5602 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5603 scp
= scsi_allocate_device(ha
->sdev
, 1, FALSE
);
5609 memset(&ha
->sdev
,0,sizeof(Scsi_Device
));
5610 memset(&scp
, 0,sizeof(Scsi_Cmnd
));
5611 ha
->sdev
.host
= scp
.host
= gdth_ctr_tab
[hanum
];
5612 ha
->sdev
.id
= scp
.target
= ha
->sdev
.host
->this_id
;
5613 scp
.device
= &ha
->sdev
;
5616 for (i
= 0; i
< MAX_HDRIVES
; ++i
) {
5617 if (!ha
->hdr
[i
].present
) {
5618 rsc
.hdr_list
[i
].bus
= 0xff;
5621 rsc
.hdr_list
[i
].bus
= ha
->virt_bus
;
5622 rsc
.hdr_list
[i
].target
= i
;
5623 rsc
.hdr_list
[i
].lun
= 0;
5624 rsc
.hdr_list
[i
].cluster_type
= ha
->hdr
[i
].cluster_type
;
5625 if (ha
->hdr
[i
].cluster_type
& CLUSTER_DRIVE
) {
5626 cmd
.Service
= CACHESERVICE
;
5627 cmd
.OpCode
= GDT_CLUST_INFO
;
5628 if (ha
->cache_feat
& GDT_64BIT
)
5629 cmd
.u
.cache64
.DeviceNo
= i
;
5631 cmd
.u
.cache
.DeviceNo
= i
;
5632 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5633 gdth_do_req(srp
, &cmd
, cmnd
, 30);
5634 if (srp
->sr_command
->SCp
.Status
== S_OK
)
5635 rsc
.hdr_list
[i
].cluster_type
= srp
->sr_command
->SCp
.Message
;
5636 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5637 gdth_do_cmd(scp
, &cmd
, cmnd
, 30);
5638 if (scp
->SCp
.Status
== S_OK
)
5639 rsc
.hdr_list
[i
].cluster_type
= scp
->SCp
.Message
;
5641 gdth_do_cmd(&scp
, &cmd
, cmnd
, 30);
5642 if (scp
.SCp
.Status
== S_OK
)
5643 rsc
.hdr_list
[i
].cluster_type
= scp
.SCp
.Message
;
5647 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5648 scsi_release_request(srp
);
5649 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5650 scsi_release_command(scp
);
5653 if (copy_to_user(arg
, &rsc
, sizeof(gdth_ioctl_rescan
)))
5658 static int ioc_rescan(void __user
*arg
, char *cmnd
)
5660 gdth_ioctl_rescan rsc
;
5662 ushort i
, status
, hdr_cnt
;
5664 int hanum
, cyls
, hds
, secs
;
5667 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5669 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5675 if (copy_from_user(&rsc
, arg
, sizeof(gdth_ioctl_rescan
)) ||
5676 rsc
.ionode
>= gdth_ctr_count
)
5679 ha
= HADATA(gdth_ctr_tab
[hanum
]);
5680 memset(&cmd
, 0, sizeof(gdth_cmd_str
));
5682 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5683 srp
= scsi_allocate_request(ha
->sdev
, GFP_KERNEL
);
5686 srp
->sr_cmd_len
= 12;
5688 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5689 scp
= scsi_allocate_device(ha
->sdev
, 1, FALSE
);
5695 memset(&ha
->sdev
,0,sizeof(Scsi_Device
));
5696 memset(&scp
, 0,sizeof(Scsi_Cmnd
));
5697 ha
->sdev
.host
= scp
.host
= gdth_ctr_tab
[hanum
];
5698 ha
->sdev
.id
= scp
.target
= ha
->sdev
.host
->this_id
;
5699 scp
.device
= &ha
->sdev
;
5702 if (rsc
.flag
== 0) {
5703 /* old method: re-init. cache service */
5704 cmd
.Service
= CACHESERVICE
;
5705 if (ha
->cache_feat
& GDT_64BIT
) {
5706 cmd
.OpCode
= GDT_X_INIT_HOST
;
5707 cmd
.u
.cache64
.DeviceNo
= LINUX_OS
;
5709 cmd
.OpCode
= GDT_INIT
;
5710 cmd
.u
.cache
.DeviceNo
= LINUX_OS
;
5712 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5713 gdth_do_req(srp
, &cmd
, cmnd
, 30);
5714 status
= (ushort
)srp
->sr_command
->SCp
.Status
;
5715 info
= (ulong32
)srp
->sr_command
->SCp
.Message
;
5716 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5717 gdth_do_cmd(scp
, &cmd
, cmnd
, 30);
5718 status
= (ushort
)scp
->SCp
.Status
;
5719 info
= (ulong32
)scp
->SCp
.Message
;
5721 gdth_do_cmd(&scp
, &cmd
, cmnd
, 30);
5722 status
= (ushort
)scp
.SCp
.Status
;
5723 info
= (ulong32
)scp
.SCp
.Message
;
5726 hdr_cnt
= (status
== S_OK
? (ushort
)info
: 0);
5731 for (; i
< hdr_cnt
&& i
< MAX_HDRIVES
; ++i
) {
5732 cmd
.Service
= CACHESERVICE
;
5733 cmd
.OpCode
= GDT_INFO
;
5734 if (ha
->cache_feat
& GDT_64BIT
)
5735 cmd
.u
.cache64
.DeviceNo
= i
;
5737 cmd
.u
.cache
.DeviceNo
= i
;
5738 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5739 gdth_do_req(srp
, &cmd
, cmnd
, 30);
5740 status
= (ushort
)srp
->sr_command
->SCp
.Status
;
5741 info
= (ulong32
)srp
->sr_command
->SCp
.Message
;
5742 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5743 gdth_do_cmd(scp
, &cmd
, cmnd
, 30);
5744 status
= (ushort
)scp
->SCp
.Status
;
5745 info
= (ulong32
)scp
->SCp
.Message
;
5747 gdth_do_cmd(&scp
, &cmd
, cmnd
, 30);
5748 status
= (ushort
)scp
.SCp
.Status
;
5749 info
= (ulong32
)scp
.SCp
.Message
;
5751 GDTH_LOCK_HA(ha
, flags
);
5752 rsc
.hdr_list
[i
].bus
= ha
->virt_bus
;
5753 rsc
.hdr_list
[i
].target
= i
;
5754 rsc
.hdr_list
[i
].lun
= 0;
5755 if (status
!= S_OK
) {
5756 ha
->hdr
[i
].present
= FALSE
;
5758 ha
->hdr
[i
].present
= TRUE
;
5759 ha
->hdr
[i
].size
= info
;
5760 /* evaluate mapping */
5761 ha
->hdr
[i
].size
&= ~SECS32
;
5762 gdth_eval_mapping(ha
->hdr
[i
].size
,&cyls
,&hds
,&secs
);
5763 ha
->hdr
[i
].heads
= hds
;
5764 ha
->hdr
[i
].secs
= secs
;
5766 ha
->hdr
[i
].size
= cyls
* hds
* secs
;
5768 GDTH_UNLOCK_HA(ha
, flags
);
5772 /* extended info, if GDT_64BIT, for drives > 2 TB */
5773 /* but we need ha->info2, not yet stored in scp->SCp */
5775 /* devtype, cluster info, R/W attribs */
5776 cmd
.Service
= CACHESERVICE
;
5777 cmd
.OpCode
= GDT_DEVTYPE
;
5778 if (ha
->cache_feat
& GDT_64BIT
)
5779 cmd
.u
.cache64
.DeviceNo
= i
;
5781 cmd
.u
.cache
.DeviceNo
= i
;
5782 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5783 gdth_do_req(srp
, &cmd
, cmnd
, 30);
5784 status
= (ushort
)srp
->sr_command
->SCp
.Status
;
5785 info
= (ulong32
)srp
->sr_command
->SCp
.Message
;
5786 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5787 gdth_do_cmd(scp
, &cmd
, cmnd
, 30);
5788 status
= (ushort
)scp
->SCp
.Status
;
5789 info
= (ulong32
)scp
->SCp
.Message
;
5791 gdth_do_cmd(&scp
, &cmd
, cmnd
, 30);
5792 status
= (ushort
)scp
.SCp
.Status
;
5793 info
= (ulong32
)scp
.SCp
.Message
;
5795 GDTH_LOCK_HA(ha
, flags
);
5796 ha
->hdr
[i
].devtype
= (status
== S_OK
? (ushort
)info
: 0);
5797 GDTH_UNLOCK_HA(ha
, flags
);
5799 cmd
.Service
= CACHESERVICE
;
5800 cmd
.OpCode
= GDT_CLUST_INFO
;
5801 if (ha
->cache_feat
& GDT_64BIT
)
5802 cmd
.u
.cache64
.DeviceNo
= i
;
5804 cmd
.u
.cache
.DeviceNo
= i
;
5805 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5806 gdth_do_req(srp
, &cmd
, cmnd
, 30);
5807 status
= (ushort
)srp
->sr_command
->SCp
.Status
;
5808 info
= (ulong32
)srp
->sr_command
->SCp
.Message
;
5809 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5810 gdth_do_cmd(scp
, &cmd
, cmnd
, 30);
5811 status
= (ushort
)scp
->SCp
.Status
;
5812 info
= (ulong32
)scp
->SCp
.Message
;
5814 gdth_do_cmd(&scp
, &cmd
, cmnd
, 30);
5815 status
= (ushort
)scp
.SCp
.Status
;
5816 info
= (ulong32
)scp
.SCp
.Message
;
5818 GDTH_LOCK_HA(ha
, flags
);
5819 ha
->hdr
[i
].cluster_type
=
5820 ((status
== S_OK
&& !shared_access
) ? (ushort
)info
: 0);
5821 GDTH_UNLOCK_HA(ha
, flags
);
5822 rsc
.hdr_list
[i
].cluster_type
= ha
->hdr
[i
].cluster_type
;
5824 cmd
.Service
= CACHESERVICE
;
5825 cmd
.OpCode
= GDT_RW_ATTRIBS
;
5826 if (ha
->cache_feat
& GDT_64BIT
)
5827 cmd
.u
.cache64
.DeviceNo
= i
;
5829 cmd
.u
.cache
.DeviceNo
= i
;
5830 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5831 gdth_do_req(srp
, &cmd
, cmnd
, 30);
5832 status
= (ushort
)srp
->sr_command
->SCp
.Status
;
5833 info
= (ulong32
)srp
->sr_command
->SCp
.Message
;
5834 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5835 gdth_do_cmd(scp
, &cmd
, cmnd
, 30);
5836 status
= (ushort
)scp
->SCp
.Status
;
5837 info
= (ulong32
)scp
->SCp
.Message
;
5839 gdth_do_cmd(&scp
, &cmd
, cmnd
, 30);
5840 status
= (ushort
)scp
.SCp
.Status
;
5841 info
= (ulong32
)scp
.SCp
.Message
;
5843 GDTH_LOCK_HA(ha
, flags
);
5844 ha
->hdr
[i
].rw_attribs
= (status
== S_OK
? (ushort
)info
: 0);
5845 GDTH_UNLOCK_HA(ha
, flags
);
5847 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5848 scsi_release_request(srp
);
5849 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5850 scsi_release_command(scp
);
5853 if (copy_to_user(arg
, &rsc
, sizeof(gdth_ioctl_rescan
)))
5858 static int gdth_ioctl(struct inode
*inode
, struct file
*filep
,
5859 unsigned int cmd
, unsigned long arg
)
5862 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5864 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5870 char cmnd
[MAX_COMMAND_SIZE
];
5871 void __user
*argp
= (void __user
*)arg
;
5873 memset(cmnd
, 0xff, 12);
5875 TRACE(("gdth_ioctl() cmd 0x%x\n", cmd
));
5878 case GDTIOCTL_CTRCNT
:
5880 int cnt
= gdth_ctr_count
;
5881 if (put_user(cnt
, (int __user
*)argp
))
5886 case GDTIOCTL_DRVERS
:
5888 int ver
= (GDTH_VERSION
<<8) | GDTH_SUBVERSION
;
5889 if (put_user(ver
, (int __user
*)argp
))
5894 case GDTIOCTL_OSVERS
:
5896 gdth_ioctl_osvers osv
;
5898 osv
.version
= (unchar
)(LINUX_VERSION_CODE
>> 16);
5899 osv
.subversion
= (unchar
)(LINUX_VERSION_CODE
>> 8);
5900 osv
.revision
= (ushort
)(LINUX_VERSION_CODE
& 0xff);
5901 if (copy_to_user(argp
, &osv
, sizeof(gdth_ioctl_osvers
)))
5906 case GDTIOCTL_CTRTYPE
:
5908 gdth_ioctl_ctrtype ctrt
;
5910 if (copy_from_user(&ctrt
, argp
, sizeof(gdth_ioctl_ctrtype
)) ||
5911 ctrt
.ionode
>= gdth_ctr_count
)
5913 ha
= HADATA(gdth_ctr_tab
[ctrt
.ionode
]);
5914 if (ha
->type
== GDT_ISA
|| ha
->type
== GDT_EISA
) {
5915 ctrt
.type
= (unchar
)((ha
->stype
>>20) - 0x10);
5917 if (ha
->type
!= GDT_PCIMPR
) {
5918 ctrt
.type
= (unchar
)((ha
->stype
<<4) + 6);
5921 (ha
->oem_id
== OEM_ID_INTEL
? 0xfd : 0xfe);
5922 if (ha
->stype
>= 0x300)
5923 ctrt
.ext_type
= 0x6000 | ha
->subdevice_id
;
5925 ctrt
.ext_type
= 0x6000 | ha
->stype
;
5927 ctrt
.device_id
= ha
->stype
;
5928 ctrt
.sub_device_id
= ha
->subdevice_id
;
5930 ctrt
.info
= ha
->brd_phys
;
5931 ctrt
.oem_id
= ha
->oem_id
;
5932 if (copy_to_user(argp
, &ctrt
, sizeof(gdth_ioctl_ctrtype
)))
5937 case GDTIOCTL_GENERAL
:
5938 return ioc_general(argp
, cmnd
);
5940 case GDTIOCTL_EVENT
:
5941 return ioc_event(argp
);
5943 case GDTIOCTL_LOCKDRV
:
5944 return ioc_lockdrv(argp
);
5946 case GDTIOCTL_LOCKCHN
:
5948 gdth_ioctl_lockchn lchn
;
5951 if (copy_from_user(&lchn
, argp
, sizeof(gdth_ioctl_lockchn
)) ||
5952 lchn
.ionode
>= gdth_ctr_count
)
5954 ha
= HADATA(gdth_ctr_tab
[lchn
.ionode
]);
5957 if (i
< ha
->bus_cnt
) {
5959 GDTH_LOCK_HA(ha
, flags
);
5960 ha
->raw
[i
].lock
= 1;
5961 GDTH_UNLOCK_HA(ha
, flags
);
5962 for (j
= 0; j
< ha
->tid_cnt
; ++j
) {
5963 gdth_wait_completion(lchn
.ionode
, i
, j
);
5964 gdth_stop_timeout(lchn
.ionode
, i
, j
);
5967 GDTH_LOCK_HA(ha
, flags
);
5968 ha
->raw
[i
].lock
= 0;
5969 GDTH_UNLOCK_HA(ha
, flags
);
5970 for (j
= 0; j
< ha
->tid_cnt
; ++j
) {
5971 gdth_start_timeout(lchn
.ionode
, i
, j
);
5972 gdth_next(lchn
.ionode
);
5979 case GDTIOCTL_RESCAN
:
5980 return ioc_rescan(argp
, cmnd
);
5982 case GDTIOCTL_HDRLIST
:
5983 return ioc_hdrlist(argp
, cmnd
);
5985 case GDTIOCTL_RESET_BUS
:
5987 gdth_ioctl_reset res
;
5990 if (copy_from_user(&res
, argp
, sizeof(gdth_ioctl_reset
)) ||
5991 res
.ionode
>= gdth_ctr_count
)
5994 ha
= HADATA(gdth_ctr_tab
[hanum
]);
5996 /* Because we need a Scsi_Cmnd struct., we make a scsi_allocate device also for kernels >=2.6.x */
5997 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5998 scp
= scsi_get_command(ha
->sdev
, GFP_KERNEL
);
6003 scp
->device
->channel
= virt_ctr
? 0 : res
.number
;
6004 rval
= gdth_eh_bus_reset(scp
);
6005 res
.status
= (rval
== SUCCESS
? S_OK
: S_GENERR
);
6006 scsi_put_command(scp
);
6007 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6008 scp
= scsi_allocate_device(ha
->sdev
, 1, FALSE
);
6013 scp
->channel
= virt_ctr
? 0 : res
.number
;
6014 rval
= gdth_eh_bus_reset(scp
);
6015 res
.status
= (rval
== SUCCESS
? S_OK
: S_GENERR
);
6016 scsi_release_command(scp
);
6018 memset(&ha
->sdev
,0,sizeof(Scsi_Device
));
6019 memset(&scp
, 0,sizeof(Scsi_Cmnd
));
6020 ha
->sdev
.host
= scp
.host
= gdth_ctr_tab
[hanum
];
6021 ha
->sdev
.id
= scp
.target
= ha
->sdev
.host
->this_id
;
6022 scp
.device
= &ha
->sdev
;
6023 scp
.channel
= virt_ctr
? 0 : res
.number
;
6024 rval
= gdth_eh_bus_reset(&scp
);
6025 res
.status
= (rval
== SUCCESS
? S_OK
: S_GENERR
);
6027 if (copy_to_user(argp
, &res
, sizeof(gdth_ioctl_reset
)))
6032 case GDTIOCTL_RESET_DRV
:
6033 return ioc_resetdrv(argp
, cmnd
);
6043 static void gdth_flush(int hanum
)
6047 gdth_cmd_str gdtcmd
;
6048 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6051 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6058 char cmnd
[MAX_COMMAND_SIZE
];
6059 memset(cmnd
, 0xff, MAX_COMMAND_SIZE
);
6061 TRACE2(("gdth_flush() hanum %d\n",hanum
));
6062 ha
= HADATA(gdth_ctr_tab
[hanum
]);
6064 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6065 sdev
= scsi_get_host_dev(gdth_ctr_tab
[hanum
]);
6066 srp
= scsi_allocate_request(sdev
, GFP_KERNEL
);
6069 srp
->sr_cmd_len
= 12;
6071 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6072 sdev
= scsi_get_host_dev(gdth_ctr_tab
[hanum
]);
6073 scp
= scsi_allocate_device(sdev
, 1, FALSE
);
6079 memset(&sdev
,0,sizeof(Scsi_Device
));
6080 memset(&scp
, 0,sizeof(Scsi_Cmnd
));
6081 sdev
.host
= scp
.host
= gdth_ctr_tab
[hanum
];
6082 sdev
.id
= scp
.target
= sdev
.host
->this_id
;
6086 for (i
= 0; i
< MAX_HDRIVES
; ++i
) {
6087 if (ha
->hdr
[i
].present
) {
6088 gdtcmd
.BoardNode
= LOCALBOARD
;
6089 gdtcmd
.Service
= CACHESERVICE
;
6090 gdtcmd
.OpCode
= GDT_FLUSH
;
6091 if (ha
->cache_feat
& GDT_64BIT
) {
6092 gdtcmd
.u
.cache64
.DeviceNo
= i
;
6093 gdtcmd
.u
.cache64
.BlockNo
= 1;
6094 gdtcmd
.u
.cache64
.sg_canz
= 0;
6096 gdtcmd
.u
.cache
.DeviceNo
= i
;
6097 gdtcmd
.u
.cache
.BlockNo
= 1;
6098 gdtcmd
.u
.cache
.sg_canz
= 0;
6100 TRACE2(("gdth_flush(): flush ha %d drive %d\n", hanum
, i
));
6101 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6102 gdth_do_req(srp
, &gdtcmd
, cmnd
, 30);
6103 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6104 gdth_do_cmd(scp
, &gdtcmd
, cmnd
, 30);
6106 gdth_do_cmd(&scp
, &gdtcmd
, cmnd
, 30);
6110 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6111 scsi_release_request(srp
);
6112 scsi_free_host_dev(sdev
);
6113 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6114 scsi_release_command(scp
);
6115 scsi_free_host_dev(sdev
);
6119 /* shutdown routine */
6120 static int gdth_halt(struct notifier_block
*nb
, ulong event
, void *buf
)
6124 gdth_cmd_str gdtcmd
;
6125 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6128 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6135 char cmnd
[MAX_COMMAND_SIZE
];
6138 TRACE2(("gdth_halt() event %d\n",(int)event
));
6139 if (event
!= SYS_RESTART
&& event
!= SYS_HALT
&& event
!= SYS_POWER_OFF
)
6142 printk("GDT-HA: Flushing all host drives .. ");
6143 for (hanum
= 0; hanum
< gdth_ctr_count
; ++hanum
) {
6147 /* controller reset */
6148 memset(cmnd
, 0xff, MAX_COMMAND_SIZE
);
6149 gdtcmd
.BoardNode
= LOCALBOARD
;
6150 gdtcmd
.Service
= CACHESERVICE
;
6151 gdtcmd
.OpCode
= GDT_RESET
;
6152 TRACE2(("gdth_halt(): reset controller %d\n", hanum
));
6153 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6154 sdev
= scsi_get_host_dev(gdth_ctr_tab
[hanum
]);
6155 srp
= scsi_allocate_request(sdev
, GFP_KERNEL
);
6157 unregister_reboot_notifier(&gdth_notifier
);
6160 srp
->sr_cmd_len
= 12;
6162 gdth_do_req(srp
, &gdtcmd
, cmnd
, 10);
6163 scsi_release_request(srp
);
6164 scsi_free_host_dev(sdev
);
6165 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6166 sdev
= scsi_get_host_dev(gdth_ctr_tab
[hanum
]);
6167 scp
= scsi_allocate_device(sdev
, 1, FALSE
);
6169 unregister_reboot_notifier(&gdth_notifier
);
6174 gdth_do_cmd(scp
, &gdtcmd
, cmnd
, 10);
6175 scsi_release_command(scp
);
6176 scsi_free_host_dev(sdev
);
6178 memset(&sdev
,0,sizeof(Scsi_Device
));
6179 memset(&scp
, 0,sizeof(Scsi_Cmnd
));
6180 sdev
.host
= scp
.host
= gdth_ctr_tab
[hanum
];
6181 sdev
.id
= scp
.target
= sdev
.host
->this_id
;
6183 gdth_do_cmd(&scp
, &gdtcmd
, cmnd
, 10);
6189 #ifdef GDTH_STATISTICS
6190 del_timer(&gdth_timer
);
6192 unregister_reboot_notifier(&gdth_notifier
);
6197 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) && !defined(MODULE)
6199 GDTH_INITFUNC(void, gdth_setup(char *str
,int *ints
))
6201 TRACE2(("gdth_setup() str %s ints[0] %d\n",
6202 str
? str
:"NULL", ints
? ints
[0]:0));
6203 internal_setup(str
, ints
);
6208 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6209 static Scsi_Host_Template driver_template
= {
6210 .proc_name
= "gdth",
6211 .proc_info
= gdth_proc_info
,
6212 .name
= "GDT SCSI Disk Array Controller",
6213 .detect
= gdth_detect
,
6214 .release
= gdth_release
,
6216 .queuecommand
= gdth_queuecommand
,
6217 .eh_abort_handler
= gdth_eh_abort
,
6218 .eh_device_reset_handler
= gdth_eh_device_reset
,
6219 .eh_bus_reset_handler
= gdth_eh_bus_reset
,
6220 .eh_host_reset_handler
= gdth_eh_host_reset
,
6221 .bios_param
= gdth_bios_param
,
6222 .can_queue
= GDTH_MAXCMDS
,
6224 .sg_tablesize
= GDTH_MAXSG
,
6225 .cmd_per_lun
= GDTH_MAXC_P_L
,
6226 .unchecked_isa_dma
= 1,
6227 .use_clustering
= ENABLE_CLUSTERING
,
6228 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
6229 .use_new_eh_code
= 1,
6230 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
6236 static Scsi_Host_Template driver_template
= GDTH
;
6239 #include "scsi_module.c"
6241 __setup("gdth=", option_setup
);