[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / scsi / gdth.c
bloba9eaab9fbd5ea7761e53d436dee64654a1402236
1 /************************************************************************
2 * Linux driver for *
3 * ICP vortex GmbH: GDT ISA/EISA/PCI Disk Array Controllers *
4 * Intel Corporation: Storage RAID Controllers *
5 * *
6 * gdth.c *
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> *
11 * *
12 * Additions/Fixes: *
13 * Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com> *
14 * Johannes Dinner <johannes_dinner@adaptec.com> *
15 * *
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. *
20 * *
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. *
25 * *
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. *
29 * *
30 * Linux kernel 2.2.x, 2.4.x, 2.6.x supported *
31 * *
32 * $Log: gdth.c,v $
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
51 * 64-bit DMA bugfixes
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
56 * Bugfixes IOCTLs
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
87 * Small changes
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
94 * Bugfix free_irq()
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
188 * MOUNTALL removed
189 * Cluster drives -> removeable drives
191 * Revision 1.27 1999/06/22 07:22:38 achim
192 * Small changes
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
237 * mdelay() added
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
258 * SA_SHIRQ added
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
297 * Initial revision
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:
356 * ptr: Chaining
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 */
372 /* statistics */
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>
391 #ifdef GDTH_RTC
392 #include <linux/mc146818rtc.h>
393 #endif
394 #include <linux/reboot.h>
396 #include <asm/dma.h>
397 #include <asm/system.h>
398 #include <asm/io.h>
399 #include <asm/uaccess.h>
400 #include <linux/spinlock.h>
401 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
402 #include <linux/blkdev.h>
403 #else
404 #include <linux/blk.h>
405 #include "sd.h"
406 #endif
408 #include "scsi.h"
409 #include <scsi/scsi_host.h>
410 #include "gdth.h"
411 #include "gdth_kcompat.h"
413 static void gdth_delay(int milliseconds);
414 static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs);
415 static irqreturn_t gdth_interrupt(int irq, void *dev_id, struct pt_regs *regs);
416 static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp);
417 static int gdth_async_event(int hanum);
418 static void gdth_log_event(gdth_evt_data *dvr, char *buffer);
420 static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority);
421 static void gdth_next(int hanum);
422 static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b);
423 static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp);
424 static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
425 ushort idx, gdth_evt_data *evt);
426 static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr);
427 static void gdth_readapp_event(gdth_ha_str *ha, unchar application,
428 gdth_evt_str *estr);
429 static void gdth_clear_events(void);
431 static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
432 char *buffer,ushort count);
433 static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp);
434 static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive);
436 static int gdth_search_eisa(ushort eisa_adr);
437 static int gdth_search_isa(ulong32 bios_adr);
438 static int gdth_search_pci(gdth_pci_str *pcistr);
439 static void gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
440 ushort vendor, ushort dev);
441 static void gdth_sort_pci(gdth_pci_str *pcistr, int cnt);
442 static int gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha);
443 static int gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha);
444 static int gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha);
446 static void gdth_enable_int(int hanum);
447 static int gdth_get_status(unchar *pIStatus,int irq);
448 static int gdth_test_busy(int hanum);
449 static int gdth_get_cmd_index(int hanum);
450 static void gdth_release_event(int hanum);
451 static int gdth_wait(int hanum,int index,ulong32 time);
452 static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
453 ulong64 p2,ulong64 p3);
454 static int gdth_search_drives(int hanum);
455 static int gdth_analyse_hdrive(int hanum, ushort hdrive);
457 static const char *gdth_ctr_name(int hanum);
459 static int gdth_open(struct inode *inode, struct file *filep);
460 static int gdth_close(struct inode *inode, struct file *filep);
461 static int gdth_ioctl(struct inode *inode, struct file *filep,
462 unsigned int cmd, unsigned long arg);
464 static void gdth_flush(int hanum);
465 static int gdth_halt(struct notifier_block *nb, ulong event, void *buf);
467 #ifdef DEBUG_GDTH
468 static unchar DebugState = DEBUG_GDTH;
470 #ifdef __SERIAL__
471 #define MAX_SERBUF 160
472 static void ser_init(void);
473 static void ser_puts(char *str);
474 static void ser_putc(char c);
475 static int ser_printk(const char *fmt, ...);
476 static char strbuf[MAX_SERBUF+1];
477 #ifdef __COM2__
478 #define COM_BASE 0x2f8
479 #else
480 #define COM_BASE 0x3f8
481 #endif
482 static void ser_init()
484 unsigned port=COM_BASE;
486 outb(0x80,port+3);
487 outb(0,port+1);
488 /* 19200 Baud, if 9600: outb(12,port) */
489 outb(6, port);
490 outb(3,port+3);
491 outb(0,port+1);
493 ser_putc('I');
494 ser_putc(' ');
498 static void ser_puts(char *str)
500 char *ptr;
502 ser_init();
503 for (ptr=str;*ptr;++ptr)
504 ser_putc(*ptr);
507 static void ser_putc(char c)
509 unsigned port=COM_BASE;
511 while ((inb(port+5) & 0x20)==0);
512 outb(c,port);
513 if (c==0x0a)
515 while ((inb(port+5) & 0x20)==0);
516 outb(0x0d,port);
520 static int ser_printk(const char *fmt, ...)
522 va_list args;
523 int i;
525 va_start(args,fmt);
526 i = vsprintf(strbuf,fmt,args);
527 ser_puts(strbuf);
528 va_end(args);
529 return i;
532 #define TRACE(a) {if (DebugState==1) {ser_printk a;}}
533 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}}
534 #define TRACE3(a) {if (DebugState!=0) {ser_printk a;}}
536 #else /* !__SERIAL__ */
537 #define TRACE(a) {if (DebugState==1) {printk a;}}
538 #define TRACE2(a) {if (DebugState==1 || DebugState==2) {printk a;}}
539 #define TRACE3(a) {if (DebugState!=0) {printk a;}}
540 #endif
542 #else /* !DEBUG */
543 #define TRACE(a)
544 #define TRACE2(a)
545 #define TRACE3(a)
546 #endif
548 #ifdef GDTH_STATISTICS
549 static ulong32 max_rq=0, max_index=0, max_sg=0;
550 #ifdef INT_COAL
551 static ulong32 max_int_coal=0;
552 #endif
553 static ulong32 act_ints=0, act_ios=0, act_stats=0, act_rq=0;
554 static struct timer_list gdth_timer;
555 #endif
557 #define PTR2USHORT(a) (ushort)(ulong)(a)
558 #define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b)
559 #define INDEX_OK(i,t) ((i)<sizeof(t)/sizeof((t)[0]))
561 #define NUMDATA(a) ( (gdth_num_str *)((a)->hostdata))
562 #define HADATA(a) (&((gdth_ext_str *)((a)->hostdata))->haext)
563 #define CMDDATA(a) (&((gdth_ext_str *)((a)->hostdata))->cmdext)
565 #define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b))
567 #define gdth_readb(addr) readb(addr)
568 #define gdth_readw(addr) readw(addr)
569 #define gdth_readl(addr) readl(addr)
570 #define gdth_writeb(b,addr) writeb((b),(addr))
571 #define gdth_writew(b,addr) writew((b),(addr))
572 #define gdth_writel(b,addr) writel((b),(addr))
574 static unchar gdth_drq_tab[4] = {5,6,7,7}; /* DRQ table */
575 static unchar gdth_irq_tab[6] = {0,10,11,12,14,0}; /* IRQ table */
576 static unchar gdth_polling; /* polling if TRUE */
577 static unchar gdth_from_wait = FALSE; /* gdth_wait() */
578 static int wait_index,wait_hanum; /* gdth_wait() */
579 static int gdth_ctr_count = 0; /* controller count */
580 static int gdth_ctr_vcount = 0; /* virt. ctr. count */
581 static int gdth_ctr_released = 0; /* gdth_release() */
582 static struct Scsi_Host *gdth_ctr_tab[MAXHA]; /* controller table */
583 static struct Scsi_Host *gdth_ctr_vtab[MAXHA*MAXBUS]; /* virt. ctr. table */
584 static unchar gdth_write_through = FALSE; /* write through */
585 static gdth_evt_str ebuffer[MAX_EVENTS]; /* event buffer */
586 static int elastidx;
587 static int eoldidx;
588 static int major;
590 #define DIN 1 /* IN data direction */
591 #define DOU 2 /* OUT data direction */
592 #define DNO DIN /* no data transfer */
593 #define DUN DIN /* unknown data direction */
594 static unchar gdth_direction_tab[0x100] = {
595 DNO,DNO,DIN,DIN,DOU,DIN,DIN,DOU,DIN,DUN,DOU,DOU,DUN,DUN,DUN,DIN,
596 DNO,DIN,DIN,DOU,DIN,DOU,DNO,DNO,DOU,DNO,DIN,DNO,DIN,DOU,DNO,DUN,
597 DIN,DUN,DIN,DUN,DOU,DIN,DUN,DUN,DIN,DIN,DOU,DNO,DUN,DIN,DOU,DOU,
598 DOU,DOU,DOU,DNO,DIN,DNO,DNO,DIN,DOU,DOU,DOU,DOU,DIN,DOU,DIN,DOU,
599 DOU,DOU,DIN,DIN,DIN,DNO,DUN,DNO,DNO,DNO,DUN,DNO,DOU,DIN,DUN,DUN,
600 DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DIN,DUN,DUN,DUN,DUN,DUN,
601 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
602 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
603 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,
604 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,
605 DUN,DUN,DUN,DUN,DUN,DNO,DNO,DUN,DIN,DNO,DOU,DUN,DNO,DUN,DOU,DOU,
606 DOU,DOU,DOU,DNO,DUN,DIN,DOU,DIN,DIN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
607 DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,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,DOU,DUN,DUN,DUN,DUN,DUN,
610 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN
613 /* LILO and modprobe/insmod parameters */
614 /* IRQ list for GDT3000/3020 EISA controllers */
615 static int irq[MAXHA] __initdata =
616 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
617 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
618 /* disable driver flag */
619 static int disable __initdata = 0;
620 /* reserve flag */
621 static int reserve_mode = 1;
622 /* reserve list */
623 static int reserve_list[MAX_RES_ARGS] =
624 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
625 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
626 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
627 /* scan order for PCI controllers */
628 static int reverse_scan = 0;
629 /* virtual channel for the host drives */
630 static int hdr_channel = 0;
631 /* max. IDs per channel */
632 static int max_ids = MAXID;
633 /* rescan all IDs */
634 static int rescan = 0;
635 /* map channels to virtual controllers */
636 static int virt_ctr = 0;
637 /* shared access */
638 static int shared_access = 1;
639 /* enable support for EISA and ISA controllers */
640 static int probe_eisa_isa = 0;
641 /* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */
642 static int force_dma32 = 0;
644 /* parameters for modprobe/insmod */
645 module_param_array(irq, int, NULL, 0);
646 module_param(disable, int, 0);
647 module_param(reserve_mode, int, 0);
648 module_param_array(reserve_list, int, NULL, 0);
649 module_param(reverse_scan, int, 0);
650 module_param(hdr_channel, int, 0);
651 module_param(max_ids, int, 0);
652 module_param(rescan, int, 0);
653 module_param(virt_ctr, int, 0);
654 module_param(shared_access, int, 0);
655 module_param(probe_eisa_isa, int, 0);
656 module_param(force_dma32, int, 0);
657 MODULE_AUTHOR("Achim Leubner");
658 MODULE_LICENSE("GPL");
660 /* ioctl interface */
661 static struct file_operations gdth_fops = {
662 .ioctl = gdth_ioctl,
663 .open = gdth_open,
664 .release = gdth_close,
667 #include "gdth_proc.h"
668 #include "gdth_proc.c"
670 /* notifier block to get a notify on system shutdown/halt/reboot */
671 static struct notifier_block gdth_notifier = {
672 gdth_halt, NULL, 0
676 static void gdth_delay(int milliseconds)
678 if (milliseconds == 0) {
679 udelay(1);
680 } else {
681 mdelay(milliseconds);
685 static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs)
687 *cyls = size /HEADS/SECS;
688 if (*cyls <= MAXCYLS) {
689 *heads = HEADS;
690 *secs = SECS;
691 } else { /* too high for 64*32 */
692 *cyls = size /MEDHEADS/MEDSECS;
693 if (*cyls <= MAXCYLS) {
694 *heads = MEDHEADS;
695 *secs = MEDSECS;
696 } else { /* too high for 127*63 */
697 *cyls = size /BIGHEADS/BIGSECS;
698 *heads = BIGHEADS;
699 *secs = BIGSECS;
704 /* controller search and initialization functions */
706 static int __init gdth_search_eisa(ushort eisa_adr)
708 ulong32 id;
710 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr));
711 id = inl(eisa_adr+ID0REG);
712 if (id == GDT3A_ID || id == GDT3B_ID) { /* GDT3000A or GDT3000B */
713 if ((inb(eisa_adr+EISAREG) & 8) == 0)
714 return 0; /* not EISA configured */
715 return 1;
717 if (id == GDT3_ID) /* GDT3000 */
718 return 1;
720 return 0;
724 static int __init gdth_search_isa(ulong32 bios_adr)
726 void __iomem *addr;
727 ulong32 id;
729 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
730 if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) {
731 id = gdth_readl(addr);
732 iounmap(addr);
733 if (id == GDT2_ID) /* GDT2000 */
734 return 1;
736 return 0;
740 static int __init gdth_search_pci(gdth_pci_str *pcistr)
742 ushort device, cnt;
744 TRACE(("gdth_search_pci()\n"));
746 cnt = 0;
747 for (device = 0; device <= PCI_DEVICE_ID_VORTEX_GDT6555; ++device)
748 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
749 for (device = PCI_DEVICE_ID_VORTEX_GDT6x17RP;
750 device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP; ++device)
751 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
752 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
753 PCI_DEVICE_ID_VORTEX_GDTNEWRX);
754 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
755 PCI_DEVICE_ID_VORTEX_GDTNEWRX2);
756 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
757 PCI_DEVICE_ID_INTEL_SRC);
758 gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
759 PCI_DEVICE_ID_INTEL_SRC_XSCALE);
760 return cnt;
763 /* Vortex only makes RAID controllers.
764 * We do not really want to specify all 550 ids here, so wildcard match.
766 static struct pci_device_id gdthtable[] __attribute_used__ = {
767 {PCI_VENDOR_ID_VORTEX,PCI_ANY_ID,PCI_ANY_ID, PCI_ANY_ID},
768 {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC,PCI_ANY_ID,PCI_ANY_ID},
769 {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC_XSCALE,PCI_ANY_ID,PCI_ANY_ID},
772 MODULE_DEVICE_TABLE(pci,gdthtable);
774 static void __init gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
775 ushort vendor, ushort device)
777 ulong base0, base1, base2;
778 struct pci_dev *pdev;
780 TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
781 *cnt, vendor, device));
783 pdev = NULL;
784 while ((pdev = pci_find_device(vendor, device, pdev))
785 != NULL) {
786 if (pci_enable_device(pdev))
787 continue;
788 if (*cnt >= MAXHA)
789 return;
790 /* GDT PCI controller found, resources are already in pdev */
791 pcistr[*cnt].pdev = pdev;
792 pcistr[*cnt].vendor_id = vendor;
793 pcistr[*cnt].device_id = device;
794 pcistr[*cnt].subdevice_id = pdev->subsystem_device;
795 pcistr[*cnt].bus = pdev->bus->number;
796 pcistr[*cnt].device_fn = pdev->devfn;
797 pcistr[*cnt].irq = pdev->irq;
798 base0 = pci_resource_flags(pdev, 0);
799 base1 = pci_resource_flags(pdev, 1);
800 base2 = pci_resource_flags(pdev, 2);
801 if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
802 device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
803 if (!(base0 & IORESOURCE_MEM))
804 continue;
805 pcistr[*cnt].dpmem = pci_resource_start(pdev, 0);
806 } else { /* GDT6110, GDT6120, .. */
807 if (!(base0 & IORESOURCE_MEM) ||
808 !(base2 & IORESOURCE_MEM) ||
809 !(base1 & IORESOURCE_IO))
810 continue;
811 pcistr[*cnt].dpmem = pci_resource_start(pdev, 2);
812 pcistr[*cnt].io_mm = pci_resource_start(pdev, 0);
813 pcistr[*cnt].io = pci_resource_start(pdev, 1);
815 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
816 pcistr[*cnt].bus, PCI_SLOT(pcistr[*cnt].device_fn),
817 pcistr[*cnt].irq, pcistr[*cnt].dpmem));
818 (*cnt)++;
823 static void __init gdth_sort_pci(gdth_pci_str *pcistr, int cnt)
825 gdth_pci_str temp;
826 int i, changed;
828 TRACE(("gdth_sort_pci() cnt %d\n",cnt));
829 if (cnt == 0)
830 return;
832 do {
833 changed = FALSE;
834 for (i = 0; i < cnt-1; ++i) {
835 if (!reverse_scan) {
836 if ((pcistr[i].bus > pcistr[i+1].bus) ||
837 (pcistr[i].bus == pcistr[i+1].bus &&
838 PCI_SLOT(pcistr[i].device_fn) >
839 PCI_SLOT(pcistr[i+1].device_fn))) {
840 temp = pcistr[i];
841 pcistr[i] = pcistr[i+1];
842 pcistr[i+1] = temp;
843 changed = TRUE;
845 } else {
846 if ((pcistr[i].bus < pcistr[i+1].bus) ||
847 (pcistr[i].bus == pcistr[i+1].bus &&
848 PCI_SLOT(pcistr[i].device_fn) <
849 PCI_SLOT(pcistr[i+1].device_fn))) {
850 temp = pcistr[i];
851 pcistr[i] = pcistr[i+1];
852 pcistr[i+1] = temp;
853 changed = TRUE;
857 } while (changed);
861 static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha)
863 ulong32 retries,id;
864 unchar prot_ver,eisacf,i,irq_found;
866 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr));
868 /* disable board interrupts, deinitialize services */
869 outb(0xff,eisa_adr+EDOORREG);
870 outb(0x00,eisa_adr+EDENABREG);
871 outb(0x00,eisa_adr+EINTENABREG);
873 outb(0xff,eisa_adr+LDOORREG);
874 retries = INIT_RETRIES;
875 gdth_delay(20);
876 while (inb(eisa_adr+EDOORREG) != 0xff) {
877 if (--retries == 0) {
878 printk("GDT-EISA: Initialization error (DEINIT failed)\n");
879 return 0;
881 gdth_delay(1);
882 TRACE2(("wait for DEINIT: retries=%d\n",retries));
884 prot_ver = inb(eisa_adr+MAILBOXREG);
885 outb(0xff,eisa_adr+EDOORREG);
886 if (prot_ver != PROTOCOL_VERSION) {
887 printk("GDT-EISA: Illegal protocol version\n");
888 return 0;
890 ha->bmic = eisa_adr;
891 ha->brd_phys = (ulong32)eisa_adr >> 12;
893 outl(0,eisa_adr+MAILBOXREG);
894 outl(0,eisa_adr+MAILBOXREG+4);
895 outl(0,eisa_adr+MAILBOXREG+8);
896 outl(0,eisa_adr+MAILBOXREG+12);
898 /* detect IRQ */
899 if ((id = inl(eisa_adr+ID0REG)) == GDT3_ID) {
900 ha->oem_id = OEM_ID_ICP;
901 ha->type = GDT_EISA;
902 ha->stype = id;
903 outl(1,eisa_adr+MAILBOXREG+8);
904 outb(0xfe,eisa_adr+LDOORREG);
905 retries = INIT_RETRIES;
906 gdth_delay(20);
907 while (inb(eisa_adr+EDOORREG) != 0xfe) {
908 if (--retries == 0) {
909 printk("GDT-EISA: Initialization error (get IRQ failed)\n");
910 return 0;
912 gdth_delay(1);
914 ha->irq = inb(eisa_adr+MAILBOXREG);
915 outb(0xff,eisa_adr+EDOORREG);
916 TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq));
917 /* check the result */
918 if (ha->irq == 0) {
919 TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
920 for (i = 0, irq_found = FALSE;
921 i < MAXHA && irq[i] != 0xff; ++i) {
922 if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) {
923 irq_found = TRUE;
924 break;
927 if (irq_found) {
928 ha->irq = irq[i];
929 irq[i] = 0;
930 printk("GDT-EISA: Can not detect controller IRQ,\n");
931 printk("Use IRQ setting from command line (IRQ = %d)\n",
932 ha->irq);
933 } else {
934 printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
935 printk("the controller BIOS or use command line parameters\n");
936 return 0;
939 } else {
940 eisacf = inb(eisa_adr+EISAREG) & 7;
941 if (eisacf > 4) /* level triggered */
942 eisacf -= 4;
943 ha->irq = gdth_irq_tab[eisacf];
944 ha->oem_id = OEM_ID_ICP;
945 ha->type = GDT_EISA;
946 ha->stype = id;
949 ha->dma64_support = 0;
950 return 1;
954 static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
956 register gdt2_dpram_str __iomem *dp2_ptr;
957 int i;
958 unchar irq_drq,prot_ver;
959 ulong32 retries;
961 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr));
963 ha->brd = ioremap(bios_adr, sizeof(gdt2_dpram_str));
964 if (ha->brd == NULL) {
965 printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
966 return 0;
968 dp2_ptr = ha->brd;
969 gdth_writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
970 /* reset interface area */
971 memset_io(&dp2_ptr->u, 0, sizeof(dp2_ptr->u));
972 if (gdth_readl(&dp2_ptr->u) != 0) {
973 printk("GDT-ISA: Initialization error (DPMEM write error)\n");
974 iounmap(ha->brd);
975 return 0;
978 /* disable board interrupts, read DRQ and IRQ */
979 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
980 gdth_writeb(0x00, &dp2_ptr->io.irqen);
981 gdth_writeb(0x00, &dp2_ptr->u.ic.S_Status);
982 gdth_writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
984 irq_drq = gdth_readb(&dp2_ptr->io.rq);
985 for (i=0; i<3; ++i) {
986 if ((irq_drq & 1)==0)
987 break;
988 irq_drq >>= 1;
990 ha->drq = gdth_drq_tab[i];
992 irq_drq = gdth_readb(&dp2_ptr->io.rq) >> 3;
993 for (i=1; i<5; ++i) {
994 if ((irq_drq & 1)==0)
995 break;
996 irq_drq >>= 1;
998 ha->irq = gdth_irq_tab[i];
1000 /* deinitialize services */
1001 gdth_writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
1002 gdth_writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
1003 gdth_writeb(0, &dp2_ptr->io.event);
1004 retries = INIT_RETRIES;
1005 gdth_delay(20);
1006 while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
1007 if (--retries == 0) {
1008 printk("GDT-ISA: Initialization error (DEINIT failed)\n");
1009 iounmap(ha->brd);
1010 return 0;
1012 gdth_delay(1);
1014 prot_ver = (unchar)gdth_readl(&dp2_ptr->u.ic.S_Info[0]);
1015 gdth_writeb(0, &dp2_ptr->u.ic.Status);
1016 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
1017 if (prot_ver != PROTOCOL_VERSION) {
1018 printk("GDT-ISA: Illegal protocol version\n");
1019 iounmap(ha->brd);
1020 return 0;
1023 ha->oem_id = OEM_ID_ICP;
1024 ha->type = GDT_ISA;
1025 ha->ic_all_size = sizeof(dp2_ptr->u);
1026 ha->stype= GDT2_ID;
1027 ha->brd_phys = bios_adr >> 4;
1029 /* special request to controller BIOS */
1030 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
1031 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
1032 gdth_writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
1033 gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
1034 gdth_writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
1035 gdth_writeb(0, &dp2_ptr->io.event);
1036 retries = INIT_RETRIES;
1037 gdth_delay(20);
1038 while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
1039 if (--retries == 0) {
1040 printk("GDT-ISA: Initialization error\n");
1041 iounmap(ha->brd);
1042 return 0;
1044 gdth_delay(1);
1046 gdth_writeb(0, &dp2_ptr->u.ic.Status);
1047 gdth_writeb(0xff, &dp2_ptr->io.irqdel);
1049 ha->dma64_support = 0;
1050 return 1;
1054 static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
1056 register gdt6_dpram_str __iomem *dp6_ptr;
1057 register gdt6c_dpram_str __iomem *dp6c_ptr;
1058 register gdt6m_dpram_str __iomem *dp6m_ptr;
1059 ulong32 retries;
1060 unchar prot_ver;
1061 ushort command;
1062 int i, found = FALSE;
1064 TRACE(("gdth_init_pci()\n"));
1066 if (pcistr->vendor_id == PCI_VENDOR_ID_INTEL)
1067 ha->oem_id = OEM_ID_INTEL;
1068 else
1069 ha->oem_id = OEM_ID_ICP;
1070 ha->brd_phys = (pcistr->bus << 8) | (pcistr->device_fn & 0xf8);
1071 ha->stype = (ulong32)pcistr->device_id;
1072 ha->subdevice_id = pcistr->subdevice_id;
1073 ha->irq = pcistr->irq;
1074 ha->pdev = pcistr->pdev;
1076 if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */
1077 TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
1078 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6_dpram_str));
1079 if (ha->brd == NULL) {
1080 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1081 return 0;
1083 /* check and reset interface area */
1084 dp6_ptr = ha->brd;
1085 gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
1086 if (gdth_readl(&dp6_ptr->u) != DPMEM_MAGIC) {
1087 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1088 pcistr->dpmem);
1089 found = FALSE;
1090 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1091 iounmap(ha->brd);
1092 ha->brd = ioremap(i, sizeof(ushort));
1093 if (ha->brd == NULL) {
1094 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1095 return 0;
1097 if (gdth_readw(ha->brd) != 0xffff) {
1098 TRACE2(("init_pci_old() address 0x%x busy\n", i));
1099 continue;
1101 iounmap(ha->brd);
1102 pci_write_config_dword(pcistr->pdev,
1103 PCI_BASE_ADDRESS_0, i);
1104 ha->brd = ioremap(i, sizeof(gdt6_dpram_str));
1105 if (ha->brd == NULL) {
1106 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1107 return 0;
1109 dp6_ptr = ha->brd;
1110 gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
1111 if (gdth_readl(&dp6_ptr->u) == DPMEM_MAGIC) {
1112 printk("GDT-PCI: Use free address at 0x%x\n", i);
1113 found = TRUE;
1114 break;
1117 if (!found) {
1118 printk("GDT-PCI: No free address found!\n");
1119 iounmap(ha->brd);
1120 return 0;
1123 memset_io(&dp6_ptr->u, 0, sizeof(dp6_ptr->u));
1124 if (gdth_readl(&dp6_ptr->u) != 0) {
1125 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1126 iounmap(ha->brd);
1127 return 0;
1130 /* disable board interrupts, deinit services */
1131 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
1132 gdth_writeb(0x00, &dp6_ptr->io.irqen);
1133 gdth_writeb(0x00, &dp6_ptr->u.ic.S_Status);
1134 gdth_writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
1136 gdth_writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
1137 gdth_writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
1138 gdth_writeb(0, &dp6_ptr->io.event);
1139 retries = INIT_RETRIES;
1140 gdth_delay(20);
1141 while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
1142 if (--retries == 0) {
1143 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1144 iounmap(ha->brd);
1145 return 0;
1147 gdth_delay(1);
1149 prot_ver = (unchar)gdth_readl(&dp6_ptr->u.ic.S_Info[0]);
1150 gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
1151 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
1152 if (prot_ver != PROTOCOL_VERSION) {
1153 printk("GDT-PCI: Illegal protocol version\n");
1154 iounmap(ha->brd);
1155 return 0;
1158 ha->type = GDT_PCI;
1159 ha->ic_all_size = sizeof(dp6_ptr->u);
1161 /* special command to controller BIOS */
1162 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
1163 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
1164 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[2]);
1165 gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
1166 gdth_writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
1167 gdth_writeb(0, &dp6_ptr->io.event);
1168 retries = INIT_RETRIES;
1169 gdth_delay(20);
1170 while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
1171 if (--retries == 0) {
1172 printk("GDT-PCI: Initialization error\n");
1173 iounmap(ha->brd);
1174 return 0;
1176 gdth_delay(1);
1178 gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
1179 gdth_writeb(0xff, &dp6_ptr->io.irqdel);
1181 ha->dma64_support = 0;
1183 } else if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */
1184 ha->plx = (gdt6c_plx_regs *)pcistr->io;
1185 TRACE2(("init_pci_new() dpmem %lx irq %d\n",
1186 pcistr->dpmem,ha->irq));
1187 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6c_dpram_str));
1188 if (ha->brd == NULL) {
1189 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1190 iounmap(ha->brd);
1191 return 0;
1193 /* check and reset interface area */
1194 dp6c_ptr = ha->brd;
1195 gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
1196 if (gdth_readl(&dp6c_ptr->u) != DPMEM_MAGIC) {
1197 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1198 pcistr->dpmem);
1199 found = FALSE;
1200 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1201 iounmap(ha->brd);
1202 ha->brd = ioremap(i, sizeof(ushort));
1203 if (ha->brd == NULL) {
1204 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1205 return 0;
1207 if (gdth_readw(ha->brd) != 0xffff) {
1208 TRACE2(("init_pci_plx() address 0x%x busy\n", i));
1209 continue;
1211 iounmap(ha->brd);
1212 pci_write_config_dword(pcistr->pdev,
1213 PCI_BASE_ADDRESS_2, i);
1214 ha->brd = ioremap(i, sizeof(gdt6c_dpram_str));
1215 if (ha->brd == NULL) {
1216 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1217 return 0;
1219 dp6c_ptr = ha->brd;
1220 gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
1221 if (gdth_readl(&dp6c_ptr->u) == DPMEM_MAGIC) {
1222 printk("GDT-PCI: Use free address at 0x%x\n", i);
1223 found = TRUE;
1224 break;
1227 if (!found) {
1228 printk("GDT-PCI: No free address found!\n");
1229 iounmap(ha->brd);
1230 return 0;
1233 memset_io(&dp6c_ptr->u, 0, sizeof(dp6c_ptr->u));
1234 if (gdth_readl(&dp6c_ptr->u) != 0) {
1235 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1236 iounmap(ha->brd);
1237 return 0;
1240 /* disable board interrupts, deinit services */
1241 outb(0x00,PTR2USHORT(&ha->plx->control1));
1242 outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
1244 gdth_writeb(0x00, &dp6c_ptr->u.ic.S_Status);
1245 gdth_writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
1247 gdth_writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
1248 gdth_writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
1250 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1252 retries = INIT_RETRIES;
1253 gdth_delay(20);
1254 while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
1255 if (--retries == 0) {
1256 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1257 iounmap(ha->brd);
1258 return 0;
1260 gdth_delay(1);
1262 prot_ver = (unchar)gdth_readl(&dp6c_ptr->u.ic.S_Info[0]);
1263 gdth_writeb(0, &dp6c_ptr->u.ic.Status);
1264 if (prot_ver != PROTOCOL_VERSION) {
1265 printk("GDT-PCI: Illegal protocol version\n");
1266 iounmap(ha->brd);
1267 return 0;
1270 ha->type = GDT_PCINEW;
1271 ha->ic_all_size = sizeof(dp6c_ptr->u);
1273 /* special command to controller BIOS */
1274 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
1275 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
1276 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[2]);
1277 gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
1278 gdth_writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
1280 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1282 retries = INIT_RETRIES;
1283 gdth_delay(20);
1284 while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
1285 if (--retries == 0) {
1286 printk("GDT-PCI: Initialization error\n");
1287 iounmap(ha->brd);
1288 return 0;
1290 gdth_delay(1);
1292 gdth_writeb(0, &dp6c_ptr->u.ic.S_Status);
1294 ha->dma64_support = 0;
1296 } else { /* MPR */
1297 TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
1298 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6m_dpram_str));
1299 if (ha->brd == NULL) {
1300 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1301 return 0;
1304 /* manipulate config. space to enable DPMEM, start RP controller */
1305 pci_read_config_word(pcistr->pdev, PCI_COMMAND, &command);
1306 command |= 6;
1307 pci_write_config_word(pcistr->pdev, PCI_COMMAND, command);
1308 if (pci_resource_start(pcistr->pdev, 8) == 1UL)
1309 pci_resource_start(pcistr->pdev, 8) = 0UL;
1310 i = 0xFEFF0001UL;
1311 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS, i);
1312 gdth_delay(1);
1313 pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS,
1314 pci_resource_start(pcistr->pdev, 8));
1316 dp6m_ptr = ha->brd;
1318 /* Ensure that it is safe to access the non HW portions of DPMEM.
1319 * Aditional check needed for Xscale based RAID controllers */
1320 while( ((int)gdth_readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 )
1321 gdth_delay(1);
1323 /* check and reset interface area */
1324 gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
1325 if (gdth_readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
1326 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1327 pcistr->dpmem);
1328 found = FALSE;
1329 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1330 iounmap(ha->brd);
1331 ha->brd = ioremap(i, sizeof(ushort));
1332 if (ha->brd == NULL) {
1333 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1334 return 0;
1336 if (gdth_readw(ha->brd) != 0xffff) {
1337 TRACE2(("init_pci_mpr() address 0x%x busy\n", i));
1338 continue;
1340 iounmap(ha->brd);
1341 pci_write_config_dword(pcistr->pdev,
1342 PCI_BASE_ADDRESS_0, i);
1343 ha->brd = ioremap(i, sizeof(gdt6m_dpram_str));
1344 if (ha->brd == NULL) {
1345 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1346 return 0;
1348 dp6m_ptr = ha->brd;
1349 gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
1350 if (gdth_readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
1351 printk("GDT-PCI: Use free address at 0x%x\n", i);
1352 found = TRUE;
1353 break;
1356 if (!found) {
1357 printk("GDT-PCI: No free address found!\n");
1358 iounmap(ha->brd);
1359 return 0;
1362 memset_io(&dp6m_ptr->u, 0, sizeof(dp6m_ptr->u));
1364 /* disable board interrupts, deinit services */
1365 gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
1366 &dp6m_ptr->i960r.edoor_en_reg);
1367 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1368 gdth_writeb(0x00, &dp6m_ptr->u.ic.S_Status);
1369 gdth_writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
1371 gdth_writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
1372 gdth_writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
1373 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1374 retries = INIT_RETRIES;
1375 gdth_delay(20);
1376 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
1377 if (--retries == 0) {
1378 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1379 iounmap(ha->brd);
1380 return 0;
1382 gdth_delay(1);
1384 prot_ver = (unchar)gdth_readl(&dp6m_ptr->u.ic.S_Info[0]);
1385 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1386 if (prot_ver != PROTOCOL_VERSION) {
1387 printk("GDT-PCI: Illegal protocol version\n");
1388 iounmap(ha->brd);
1389 return 0;
1392 ha->type = GDT_PCIMPR;
1393 ha->ic_all_size = sizeof(dp6m_ptr->u);
1395 /* special command to controller BIOS */
1396 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
1397 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
1398 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[2]);
1399 gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
1400 gdth_writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
1401 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1402 retries = INIT_RETRIES;
1403 gdth_delay(20);
1404 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
1405 if (--retries == 0) {
1406 printk("GDT-PCI: Initialization error\n");
1407 iounmap(ha->brd);
1408 return 0;
1410 gdth_delay(1);
1412 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1414 /* read FW version to detect 64-bit DMA support */
1415 gdth_writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx);
1416 gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
1417 retries = INIT_RETRIES;
1418 gdth_delay(20);
1419 while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) {
1420 if (--retries == 0) {
1421 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1422 iounmap(ha->brd);
1423 return 0;
1425 gdth_delay(1);
1427 prot_ver = (unchar)(gdth_readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
1428 gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
1429 if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */
1430 ha->dma64_support = 0;
1431 else
1432 ha->dma64_support = 1;
1435 return 1;
1439 /* controller protocol functions */
1441 static void __init gdth_enable_int(int hanum)
1443 gdth_ha_str *ha;
1444 ulong flags;
1445 gdt2_dpram_str __iomem *dp2_ptr;
1446 gdt6_dpram_str __iomem *dp6_ptr;
1447 gdt6m_dpram_str __iomem *dp6m_ptr;
1449 TRACE(("gdth_enable_int() hanum %d\n",hanum));
1450 ha = HADATA(gdth_ctr_tab[hanum]);
1451 spin_lock_irqsave(&ha->smp_lock, flags);
1453 if (ha->type == GDT_EISA) {
1454 outb(0xff, ha->bmic + EDOORREG);
1455 outb(0xff, ha->bmic + EDENABREG);
1456 outb(0x01, ha->bmic + EINTENABREG);
1457 } else if (ha->type == GDT_ISA) {
1458 dp2_ptr = ha->brd;
1459 gdth_writeb(1, &dp2_ptr->io.irqdel);
1460 gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);
1461 gdth_writeb(1, &dp2_ptr->io.irqen);
1462 } else if (ha->type == GDT_PCI) {
1463 dp6_ptr = ha->brd;
1464 gdth_writeb(1, &dp6_ptr->io.irqdel);
1465 gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);
1466 gdth_writeb(1, &dp6_ptr->io.irqen);
1467 } else if (ha->type == GDT_PCINEW) {
1468 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
1469 outb(0x03, PTR2USHORT(&ha->plx->control1));
1470 } else if (ha->type == GDT_PCIMPR) {
1471 dp6m_ptr = ha->brd;
1472 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1473 gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
1474 &dp6m_ptr->i960r.edoor_en_reg);
1476 spin_unlock_irqrestore(&ha->smp_lock, flags);
1480 static int gdth_get_status(unchar *pIStatus,int irq)
1482 register gdth_ha_str *ha;
1483 int i;
1485 TRACE(("gdth_get_status() irq %d ctr_count %d\n",
1486 irq,gdth_ctr_count));
1488 *pIStatus = 0;
1489 for (i=0; i<gdth_ctr_count; ++i) {
1490 ha = HADATA(gdth_ctr_tab[i]);
1491 if (ha->irq != (unchar)irq) /* check IRQ */
1492 continue;
1493 if (ha->type == GDT_EISA)
1494 *pIStatus = inb((ushort)ha->bmic + EDOORREG);
1495 else if (ha->type == GDT_ISA)
1496 *pIStatus =
1497 gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
1498 else if (ha->type == GDT_PCI)
1499 *pIStatus =
1500 gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
1501 else if (ha->type == GDT_PCINEW)
1502 *pIStatus = inb(PTR2USHORT(&ha->plx->edoor_reg));
1503 else if (ha->type == GDT_PCIMPR)
1504 *pIStatus =
1505 gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg);
1507 if (*pIStatus)
1508 return i; /* board found */
1510 return -1;
1514 static int gdth_test_busy(int hanum)
1516 register gdth_ha_str *ha;
1517 register int gdtsema0 = 0;
1519 TRACE(("gdth_test_busy() hanum %d\n",hanum));
1521 ha = HADATA(gdth_ctr_tab[hanum]);
1522 if (ha->type == GDT_EISA)
1523 gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
1524 else if (ha->type == GDT_ISA)
1525 gdtsema0 = (int)gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1526 else if (ha->type == GDT_PCI)
1527 gdtsema0 = (int)gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1528 else if (ha->type == GDT_PCINEW)
1529 gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg));
1530 else if (ha->type == GDT_PCIMPR)
1531 gdtsema0 =
1532 (int)gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
1534 return (gdtsema0 & 1);
1538 static int gdth_get_cmd_index(int hanum)
1540 register gdth_ha_str *ha;
1541 int i;
1543 TRACE(("gdth_get_cmd_index() hanum %d\n",hanum));
1545 ha = HADATA(gdth_ctr_tab[hanum]);
1546 for (i=0; i<GDTH_MAXCMDS; ++i) {
1547 if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
1548 ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
1549 ha->cmd_tab[i].service = ha->pccb->Service;
1550 ha->pccb->CommandIndex = (ulong32)i+2;
1551 return (i+2);
1554 return 0;
1558 static void gdth_set_sema0(int hanum)
1560 register gdth_ha_str *ha;
1562 TRACE(("gdth_set_sema0() hanum %d\n",hanum));
1564 ha = HADATA(gdth_ctr_tab[hanum]);
1565 if (ha->type == GDT_EISA) {
1566 outb(1, ha->bmic + SEMA0REG);
1567 } else if (ha->type == GDT_ISA) {
1568 gdth_writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1569 } else if (ha->type == GDT_PCI) {
1570 gdth_writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
1571 } else if (ha->type == GDT_PCINEW) {
1572 outb(1, PTR2USHORT(&ha->plx->sema0_reg));
1573 } else if (ha->type == GDT_PCIMPR) {
1574 gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
1579 static void gdth_copy_command(int hanum)
1581 register gdth_ha_str *ha;
1582 register gdth_cmd_str *cmd_ptr;
1583 register gdt6m_dpram_str __iomem *dp6m_ptr;
1584 register gdt6c_dpram_str __iomem *dp6c_ptr;
1585 gdt6_dpram_str __iomem *dp6_ptr;
1586 gdt2_dpram_str __iomem *dp2_ptr;
1587 ushort cp_count,dp_offset,cmd_no;
1589 TRACE(("gdth_copy_command() hanum %d\n",hanum));
1591 ha = HADATA(gdth_ctr_tab[hanum]);
1592 cp_count = ha->cmd_len;
1593 dp_offset= ha->cmd_offs_dpmem;
1594 cmd_no = ha->cmd_cnt;
1595 cmd_ptr = ha->pccb;
1597 ++ha->cmd_cnt;
1598 if (ha->type == GDT_EISA)
1599 return; /* no DPMEM, no copy */
1601 /* set cpcount dword aligned */
1602 if (cp_count & 3)
1603 cp_count += (4 - (cp_count & 3));
1605 ha->cmd_offs_dpmem += cp_count;
1607 /* set offset and service, copy command to DPMEM */
1608 if (ha->type == GDT_ISA) {
1609 dp2_ptr = ha->brd;
1610 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1611 &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
1612 gdth_writew((ushort)cmd_ptr->Service,
1613 &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
1614 memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1615 } else if (ha->type == GDT_PCI) {
1616 dp6_ptr = ha->brd;
1617 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1618 &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
1619 gdth_writew((ushort)cmd_ptr->Service,
1620 &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
1621 memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1622 } else if (ha->type == GDT_PCINEW) {
1623 dp6c_ptr = ha->brd;
1624 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1625 &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
1626 gdth_writew((ushort)cmd_ptr->Service,
1627 &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
1628 memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1629 } else if (ha->type == GDT_PCIMPR) {
1630 dp6m_ptr = ha->brd;
1631 gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
1632 &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
1633 gdth_writew((ushort)cmd_ptr->Service,
1634 &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
1635 memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1640 static void gdth_release_event(int hanum)
1642 register gdth_ha_str *ha;
1644 TRACE(("gdth_release_event() hanum %d\n",hanum));
1645 ha = HADATA(gdth_ctr_tab[hanum]);
1647 #ifdef GDTH_STATISTICS
1649 ulong32 i,j;
1650 for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
1651 if (ha->cmd_tab[j].cmnd != UNUSED_CMND)
1652 ++i;
1654 if (max_index < i) {
1655 max_index = i;
1656 TRACE3(("GDT: max_index = %d\n",(ushort)i));
1659 #endif
1661 if (ha->pccb->OpCode == GDT_INIT)
1662 ha->pccb->Service |= 0x80;
1664 if (ha->type == GDT_EISA) {
1665 if (ha->pccb->OpCode == GDT_INIT) /* store DMA buffer */
1666 outl(ha->ccb_phys, ha->bmic + MAILBOXREG);
1667 outb(ha->pccb->Service, ha->bmic + LDOORREG);
1668 } else if (ha->type == GDT_ISA) {
1669 gdth_writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event);
1670 } else if (ha->type == GDT_PCI) {
1671 gdth_writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event);
1672 } else if (ha->type == GDT_PCINEW) {
1673 outb(1, PTR2USHORT(&ha->plx->ldoor_reg));
1674 } else if (ha->type == GDT_PCIMPR) {
1675 gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg);
1680 static int gdth_wait(int hanum,int index,ulong32 time)
1682 gdth_ha_str *ha;
1683 int answer_found = FALSE;
1685 TRACE(("gdth_wait() hanum %d index %d time %d\n",hanum,index,time));
1687 ha = HADATA(gdth_ctr_tab[hanum]);
1688 if (index == 0)
1689 return 1; /* no wait required */
1691 gdth_from_wait = TRUE;
1692 do {
1693 gdth_interrupt((int)ha->irq,ha,NULL);
1694 if (wait_hanum==hanum && wait_index==index) {
1695 answer_found = TRUE;
1696 break;
1698 gdth_delay(1);
1699 } while (--time);
1700 gdth_from_wait = FALSE;
1702 while (gdth_test_busy(hanum))
1703 gdth_delay(0);
1705 return (answer_found);
1709 static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
1710 ulong64 p2,ulong64 p3)
1712 register gdth_ha_str *ha;
1713 register gdth_cmd_str *cmd_ptr;
1714 int retries,index;
1716 TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode));
1718 ha = HADATA(gdth_ctr_tab[hanum]);
1719 cmd_ptr = ha->pccb;
1720 memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str));
1722 /* make command */
1723 for (retries = INIT_RETRIES;;) {
1724 cmd_ptr->Service = service;
1725 cmd_ptr->RequestBuffer = INTERNAL_CMND;
1726 if (!(index=gdth_get_cmd_index(hanum))) {
1727 TRACE(("GDT: No free command index found\n"));
1728 return 0;
1730 gdth_set_sema0(hanum);
1731 cmd_ptr->OpCode = opcode;
1732 cmd_ptr->BoardNode = LOCALBOARD;
1733 if (service == CACHESERVICE) {
1734 if (opcode == GDT_IOCTL) {
1735 cmd_ptr->u.ioctl.subfunc = p1;
1736 cmd_ptr->u.ioctl.channel = (ulong32)p2;
1737 cmd_ptr->u.ioctl.param_size = (ushort)p3;
1738 cmd_ptr->u.ioctl.p_param = ha->scratch_phys;
1739 } else {
1740 if (ha->cache_feat & GDT_64BIT) {
1741 cmd_ptr->u.cache64.DeviceNo = (ushort)p1;
1742 cmd_ptr->u.cache64.BlockNo = p2;
1743 } else {
1744 cmd_ptr->u.cache.DeviceNo = (ushort)p1;
1745 cmd_ptr->u.cache.BlockNo = (ulong32)p2;
1748 } else if (service == SCSIRAWSERVICE) {
1749 if (ha->raw_feat & GDT_64BIT) {
1750 cmd_ptr->u.raw64.direction = p1;
1751 cmd_ptr->u.raw64.bus = (unchar)p2;
1752 cmd_ptr->u.raw64.target = (unchar)p3;
1753 cmd_ptr->u.raw64.lun = (unchar)(p3 >> 8);
1754 } else {
1755 cmd_ptr->u.raw.direction = p1;
1756 cmd_ptr->u.raw.bus = (unchar)p2;
1757 cmd_ptr->u.raw.target = (unchar)p3;
1758 cmd_ptr->u.raw.lun = (unchar)(p3 >> 8);
1760 } else if (service == SCREENSERVICE) {
1761 if (opcode == GDT_REALTIME) {
1762 *(ulong32 *)&cmd_ptr->u.screen.su.data[0] = p1;
1763 *(ulong32 *)&cmd_ptr->u.screen.su.data[4] = (ulong32)p2;
1764 *(ulong32 *)&cmd_ptr->u.screen.su.data[8] = (ulong32)p3;
1767 ha->cmd_len = sizeof(gdth_cmd_str);
1768 ha->cmd_offs_dpmem = 0;
1769 ha->cmd_cnt = 0;
1770 gdth_copy_command(hanum);
1771 gdth_release_event(hanum);
1772 gdth_delay(20);
1773 if (!gdth_wait(hanum,index,INIT_TIMEOUT)) {
1774 printk("GDT: Initialization error (timeout service %d)\n",service);
1775 return 0;
1777 if (ha->status != S_BSY || --retries == 0)
1778 break;
1779 gdth_delay(1);
1782 return (ha->status != S_OK ? 0:1);
1786 /* search for devices */
1788 static int __init gdth_search_drives(int hanum)
1790 register gdth_ha_str *ha;
1791 ushort cdev_cnt, i;
1792 int ok;
1793 ulong32 bus_no, drv_cnt, drv_no, j;
1794 gdth_getch_str *chn;
1795 gdth_drlist_str *drl;
1796 gdth_iochan_str *ioc;
1797 gdth_raw_iochan_str *iocr;
1798 gdth_arcdl_str *alst;
1799 gdth_alist_str *alst2;
1800 gdth_oem_str_ioctl *oemstr;
1801 #ifdef INT_COAL
1802 gdth_perf_modes *pmod;
1803 #endif
1805 #ifdef GDTH_RTC
1806 unchar rtc[12];
1807 ulong flags;
1808 #endif
1810 TRACE(("gdth_search_drives() hanum %d\n",hanum));
1811 ha = HADATA(gdth_ctr_tab[hanum]);
1812 ok = 0;
1814 /* initialize controller services, at first: screen service */
1815 ha->screen_feat = 0;
1816 if (!force_dma32) {
1817 ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_X_INIT_SCR,0,0,0);
1818 if (ok)
1819 ha->screen_feat = GDT_64BIT;
1821 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1822 ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_INIT,0,0,0);
1823 if (!ok) {
1824 printk("GDT-HA %d: Initialization error screen service (code %d)\n",
1825 hanum, ha->status);
1826 return 0;
1828 TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n"));
1830 #ifdef GDTH_RTC
1831 /* read realtime clock info, send to controller */
1832 /* 1. wait for the falling edge of update flag */
1833 spin_lock_irqsave(&rtc_lock, flags);
1834 for (j = 0; j < 1000000; ++j)
1835 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
1836 break;
1837 for (j = 0; j < 1000000; ++j)
1838 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
1839 break;
1840 /* 2. read info */
1841 do {
1842 for (j = 0; j < 12; ++j)
1843 rtc[j] = CMOS_READ(j);
1844 } while (rtc[0] != CMOS_READ(0));
1845 spin_lock_irqrestore(&rtc_lock, flags);
1846 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32 *)&rtc[0],
1847 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]));
1848 /* 3. send to controller firmware */
1849 gdth_internal_cmd(hanum,SCREENSERVICE,GDT_REALTIME, *(ulong32 *)&rtc[0],
1850 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]);
1851 #endif
1853 /* unfreeze all IOs */
1854 gdth_internal_cmd(hanum,CACHESERVICE,GDT_UNFREEZE_IO,0,0,0);
1856 /* initialize cache service */
1857 ha->cache_feat = 0;
1858 if (!force_dma32) {
1859 ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INIT_HOST,LINUX_OS,0,0);
1860 if (ok)
1861 ha->cache_feat = GDT_64BIT;
1863 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
1864 ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_INIT,LINUX_OS,0,0);
1865 if (!ok) {
1866 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1867 hanum, ha->status);
1868 return 0;
1870 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
1871 cdev_cnt = (ushort)ha->info;
1872 ha->fw_vers = ha->service;
1874 #ifdef INT_COAL
1875 if (ha->type == GDT_PCIMPR) {
1876 /* set perf. modes */
1877 pmod = (gdth_perf_modes *)ha->pscratch;
1878 pmod->version = 1;
1879 pmod->st_mode = 1; /* enable one status buffer */
1880 *((ulong64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys;
1881 pmod->st_buff_indx1 = COALINDEX;
1882 pmod->st_buff_addr2 = 0;
1883 pmod->st_buff_u_addr2 = 0;
1884 pmod->st_buff_indx2 = 0;
1885 pmod->st_buff_size = sizeof(gdth_coal_status) * MAXOFFSETS;
1886 pmod->cmd_mode = 0; // disable all cmd buffers
1887 pmod->cmd_buff_addr1 = 0;
1888 pmod->cmd_buff_u_addr1 = 0;
1889 pmod->cmd_buff_indx1 = 0;
1890 pmod->cmd_buff_addr2 = 0;
1891 pmod->cmd_buff_u_addr2 = 0;
1892 pmod->cmd_buff_indx2 = 0;
1893 pmod->cmd_buff_size = 0;
1894 pmod->reserved1 = 0;
1895 pmod->reserved2 = 0;
1896 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,SET_PERF_MODES,
1897 INVALID_CHANNEL,sizeof(gdth_perf_modes))) {
1898 printk("GDT-HA %d: Interrupt coalescing activated\n", hanum);
1901 #endif
1903 /* detect number of buses - try new IOCTL */
1904 iocr = (gdth_raw_iochan_str *)ha->pscratch;
1905 iocr->hdr.version = 0xffffffff;
1906 iocr->hdr.list_entries = MAXBUS;
1907 iocr->hdr.first_chan = 0;
1908 iocr->hdr.last_chan = MAXBUS-1;
1909 iocr->hdr.list_offset = GDTOFFSOF(gdth_raw_iochan_str, list[0]);
1910 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_RAW_DESC,
1911 INVALID_CHANNEL,sizeof(gdth_raw_iochan_str))) {
1912 TRACE2(("IOCHAN_RAW_DESC supported!\n"));
1913 ha->bus_cnt = iocr->hdr.chan_count;
1914 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1915 if (iocr->list[bus_no].proc_id < MAXID)
1916 ha->bus_id[bus_no] = iocr->list[bus_no].proc_id;
1917 else
1918 ha->bus_id[bus_no] = 0xff;
1920 } else {
1921 /* old method */
1922 chn = (gdth_getch_str *)ha->pscratch;
1923 for (bus_no = 0; bus_no < MAXBUS; ++bus_no) {
1924 chn->channel_no = bus_no;
1925 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
1926 SCSI_CHAN_CNT | L_CTRL_PATTERN,
1927 IO_CHANNEL | INVALID_CHANNEL,
1928 sizeof(gdth_getch_str))) {
1929 if (bus_no == 0) {
1930 printk("GDT-HA %d: Error detecting channel count (0x%x)\n",
1931 hanum, ha->status);
1932 return 0;
1934 break;
1936 if (chn->siop_id < MAXID)
1937 ha->bus_id[bus_no] = chn->siop_id;
1938 else
1939 ha->bus_id[bus_no] = 0xff;
1941 ha->bus_cnt = (unchar)bus_no;
1943 TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt));
1945 /* read cache configuration */
1946 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_INFO,
1947 INVALID_CHANNEL,sizeof(gdth_cinfo_str))) {
1948 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
1949 hanum, ha->status);
1950 return 0;
1952 ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar;
1953 TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
1954 ha->cpar.version,ha->cpar.state,ha->cpar.strategy,
1955 ha->cpar.write_back,ha->cpar.block_size));
1957 /* read board info and features */
1958 ha->more_proc = FALSE;
1959 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_INFO,
1960 INVALID_CHANNEL,sizeof(gdth_binfo_str))) {
1961 memcpy(&ha->binfo, (gdth_binfo_str *)ha->pscratch,
1962 sizeof(gdth_binfo_str));
1963 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_FEATURES,
1964 INVALID_CHANNEL,sizeof(gdth_bfeat_str))) {
1965 TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n"));
1966 ha->bfeat = *(gdth_bfeat_str *)ha->pscratch;
1967 ha->more_proc = TRUE;
1969 } else {
1970 TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n"));
1971 strcpy(ha->binfo.type_string, gdth_ctr_name(hanum));
1973 TRACE2(("Controller name: %s\n",ha->binfo.type_string));
1975 /* read more informations */
1976 if (ha->more_proc) {
1977 /* physical drives, channel addresses */
1978 ioc = (gdth_iochan_str *)ha->pscratch;
1979 ioc->hdr.version = 0xffffffff;
1980 ioc->hdr.list_entries = MAXBUS;
1981 ioc->hdr.first_chan = 0;
1982 ioc->hdr.last_chan = MAXBUS-1;
1983 ioc->hdr.list_offset = GDTOFFSOF(gdth_iochan_str, list[0]);
1984 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_DESC,
1985 INVALID_CHANNEL,sizeof(gdth_iochan_str))) {
1986 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1987 ha->raw[bus_no].address = ioc->list[bus_no].address;
1988 ha->raw[bus_no].local_no = ioc->list[bus_no].local_no;
1990 } else {
1991 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1992 ha->raw[bus_no].address = IO_CHANNEL;
1993 ha->raw[bus_no].local_no = bus_no;
1996 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1997 chn = (gdth_getch_str *)ha->pscratch;
1998 chn->channel_no = ha->raw[bus_no].local_no;
1999 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2000 SCSI_CHAN_CNT | L_CTRL_PATTERN,
2001 ha->raw[bus_no].address | INVALID_CHANNEL,
2002 sizeof(gdth_getch_str))) {
2003 ha->raw[bus_no].pdev_cnt = chn->drive_cnt;
2004 TRACE2(("Channel %d: %d phys. drives\n",
2005 bus_no,chn->drive_cnt));
2007 if (ha->raw[bus_no].pdev_cnt > 0) {
2008 drl = (gdth_drlist_str *)ha->pscratch;
2009 drl->sc_no = ha->raw[bus_no].local_no;
2010 drl->sc_cnt = ha->raw[bus_no].pdev_cnt;
2011 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2012 SCSI_DR_LIST | L_CTRL_PATTERN,
2013 ha->raw[bus_no].address | INVALID_CHANNEL,
2014 sizeof(gdth_drlist_str))) {
2015 for (j = 0; j < ha->raw[bus_no].pdev_cnt; ++j)
2016 ha->raw[bus_no].id_list[j] = drl->sc_list[j];
2017 } else {
2018 ha->raw[bus_no].pdev_cnt = 0;
2023 /* logical drives */
2024 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_CNT,
2025 INVALID_CHANNEL,sizeof(ulong32))) {
2026 drv_cnt = *(ulong32 *)ha->pscratch;
2027 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_LIST,
2028 INVALID_CHANNEL,drv_cnt * sizeof(ulong32))) {
2029 for (j = 0; j < drv_cnt; ++j) {
2030 drv_no = ((ulong32 *)ha->pscratch)[j];
2031 if (drv_no < MAX_LDRIVES) {
2032 ha->hdr[drv_no].is_logdrv = TRUE;
2033 TRACE2(("Drive %d is log. drive\n",drv_no));
2037 alst = (gdth_arcdl_str *)ha->pscratch;
2038 alst->entries_avail = MAX_LDRIVES;
2039 alst->first_entry = 0;
2040 alst->list_offset = GDTOFFSOF(gdth_arcdl_str, list[0]);
2041 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2042 ARRAY_DRV_LIST2 | LA_CTRL_PATTERN,
2043 INVALID_CHANNEL, sizeof(gdth_arcdl_str) +
2044 (alst->entries_avail-1) * sizeof(gdth_alist_str))) {
2045 for (j = 0; j < alst->entries_init; ++j) {
2046 ha->hdr[j].is_arraydrv = alst->list[j].is_arrayd;
2047 ha->hdr[j].is_master = alst->list[j].is_master;
2048 ha->hdr[j].is_parity = alst->list[j].is_parity;
2049 ha->hdr[j].is_hotfix = alst->list[j].is_hotfix;
2050 ha->hdr[j].master_no = alst->list[j].cd_handle;
2052 } else if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2053 ARRAY_DRV_LIST | LA_CTRL_PATTERN,
2054 0, 35 * sizeof(gdth_alist_str))) {
2055 for (j = 0; j < 35; ++j) {
2056 alst2 = &((gdth_alist_str *)ha->pscratch)[j];
2057 ha->hdr[j].is_arraydrv = alst2->is_arrayd;
2058 ha->hdr[j].is_master = alst2->is_master;
2059 ha->hdr[j].is_parity = alst2->is_parity;
2060 ha->hdr[j].is_hotfix = alst2->is_hotfix;
2061 ha->hdr[j].master_no = alst2->cd_handle;
2067 /* initialize raw service */
2068 ha->raw_feat = 0;
2069 if (!force_dma32) {
2070 ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_X_INIT_RAW,0,0,0);
2071 if (ok)
2072 ha->raw_feat = GDT_64BIT;
2074 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
2075 ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_INIT,0,0,0);
2076 if (!ok) {
2077 printk("GDT-HA %d: Initialization error raw service (code %d)\n",
2078 hanum, ha->status);
2079 return 0;
2081 TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n"));
2083 /* set/get features raw service (scatter/gather) */
2084 if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_SET_FEAT,SCATTER_GATHER,
2085 0,0)) {
2086 TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
2087 if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_GET_FEAT,0,0,0)) {
2088 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
2089 ha->info));
2090 ha->raw_feat |= (ushort)ha->info;
2094 /* set/get features cache service (equal to raw service) */
2095 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_SET_FEAT,0,
2096 SCATTER_GATHER,0)) {
2097 TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
2098 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_GET_FEAT,0,0,0)) {
2099 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
2100 ha->info));
2101 ha->cache_feat |= (ushort)ha->info;
2105 /* reserve drives for raw service */
2106 if (reserve_mode != 0) {
2107 gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE_ALL,
2108 reserve_mode == 1 ? 1 : 3, 0, 0);
2109 TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n",
2110 ha->status));
2112 for (i = 0; i < MAX_RES_ARGS; i += 4) {
2113 if (reserve_list[i] == hanum && reserve_list[i+1] < ha->bus_cnt &&
2114 reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) {
2115 TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
2116 reserve_list[i], reserve_list[i+1],
2117 reserve_list[i+2], reserve_list[i+3]));
2118 if (!gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE,0,
2119 reserve_list[i+1], reserve_list[i+2] |
2120 (reserve_list[i+3] << 8))) {
2121 printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n",
2122 hanum, ha->status);
2127 /* Determine OEM string using IOCTL */
2128 oemstr = (gdth_oem_str_ioctl *)ha->pscratch;
2129 oemstr->params.ctl_version = 0x01;
2130 oemstr->params.buffer_size = sizeof(oemstr->text);
2131 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
2132 CACHE_READ_OEM_STRING_RECORD,INVALID_CHANNEL,
2133 sizeof(gdth_oem_str_ioctl))) {
2134 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n"));
2135 printk("GDT-HA %d: Vendor: %s Name: %s\n",
2136 hanum,oemstr->text.oem_company_name,ha->binfo.type_string);
2137 /* Save the Host Drive inquiry data */
2138 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2139 strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,
2140 sizeof(ha->oem_name));
2141 #else
2142 strncpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,7);
2143 ha->oem_name[7] = '\0';
2144 #endif
2145 } else {
2146 /* Old method, based on PCI ID */
2147 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
2148 printk("GDT-HA %d: Name: %s\n",
2149 hanum,ha->binfo.type_string);
2150 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2151 if (ha->oem_id == OEM_ID_INTEL)
2152 strlcpy(ha->oem_name,"Intel ", sizeof(ha->oem_name));
2153 else
2154 strlcpy(ha->oem_name,"ICP ", sizeof(ha->oem_name));
2155 #else
2156 if (ha->oem_id == OEM_ID_INTEL)
2157 strcpy(ha->oem_name,"Intel ");
2158 else
2159 strcpy(ha->oem_name,"ICP ");
2160 #endif
2163 /* scanning for host drives */
2164 for (i = 0; i < cdev_cnt; ++i)
2165 gdth_analyse_hdrive(hanum,i);
2167 TRACE(("gdth_search_drives() OK\n"));
2168 return 1;
2171 static int gdth_analyse_hdrive(int hanum,ushort hdrive)
2173 register gdth_ha_str *ha;
2174 ulong32 drv_cyls;
2175 int drv_hds, drv_secs;
2177 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n",hanum,hdrive));
2178 if (hdrive >= MAX_HDRIVES)
2179 return 0;
2180 ha = HADATA(gdth_ctr_tab[hanum]);
2182 if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_INFO,hdrive,0,0))
2183 return 0;
2184 ha->hdr[hdrive].present = TRUE;
2185 ha->hdr[hdrive].size = ha->info;
2187 /* evaluate mapping (sectors per head, heads per cylinder) */
2188 ha->hdr[hdrive].size &= ~SECS32;
2189 if (ha->info2 == 0) {
2190 gdth_eval_mapping(ha->hdr[hdrive].size,&drv_cyls,&drv_hds,&drv_secs);
2191 } else {
2192 drv_hds = ha->info2 & 0xff;
2193 drv_secs = (ha->info2 >> 8) & 0xff;
2194 drv_cyls = (ulong32)ha->hdr[hdrive].size / drv_hds / drv_secs;
2196 ha->hdr[hdrive].heads = (unchar)drv_hds;
2197 ha->hdr[hdrive].secs = (unchar)drv_secs;
2198 /* round size */
2199 ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs;
2201 if (ha->cache_feat & GDT_64BIT) {
2202 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INFO,hdrive,0,0)
2203 && ha->info2 != 0) {
2204 ha->hdr[hdrive].size = ((ulong64)ha->info2 << 32) | ha->info;
2207 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
2208 hdrive,ha->hdr[hdrive].size,drv_hds,drv_secs));
2210 /* get informations about device */
2211 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_DEVTYPE,hdrive,0,0)) {
2212 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
2213 hdrive,ha->info));
2214 ha->hdr[hdrive].devtype = (ushort)ha->info;
2217 /* cluster info */
2218 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_CLUST_INFO,hdrive,0,0)) {
2219 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
2220 hdrive,ha->info));
2221 if (!shared_access)
2222 ha->hdr[hdrive].cluster_type = (unchar)ha->info;
2225 /* R/W attributes */
2226 if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_RW_ATTRIBS,hdrive,0,0)) {
2227 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
2228 hdrive,ha->info));
2229 ha->hdr[hdrive].rw_attribs = (unchar)ha->info;
2232 return 1;
2236 /* command queueing/sending functions */
2238 static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority)
2240 register gdth_ha_str *ha;
2241 register Scsi_Cmnd *pscp;
2242 register Scsi_Cmnd *nscp;
2243 ulong flags;
2244 unchar b, t;
2246 TRACE(("gdth_putq() priority %d\n",priority));
2247 ha = HADATA(gdth_ctr_tab[hanum]);
2248 spin_lock_irqsave(&ha->smp_lock, flags);
2250 scp->SCp.this_residual = (int)priority;
2251 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
2252 t = scp->device->id;
2253 if (priority >= DEFAULT_PRI) {
2254 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2255 (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock)) {
2256 TRACE2(("gdth_putq(): locked IO -> update_timeout()\n"));
2257 scp->SCp.buffers_residual = gdth_update_timeout(hanum, scp, 0);
2261 if (ha->req_first==NULL) {
2262 ha->req_first = scp; /* queue was empty */
2263 scp->SCp.ptr = NULL;
2264 } else { /* queue not empty */
2265 pscp = ha->req_first;
2266 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2267 /* priority: 0-highest,..,0xff-lowest */
2268 while (nscp && (unchar)nscp->SCp.this_residual <= priority) {
2269 pscp = nscp;
2270 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2272 pscp->SCp.ptr = (char *)scp;
2273 scp->SCp.ptr = (char *)nscp;
2275 spin_unlock_irqrestore(&ha->smp_lock, flags);
2277 #ifdef GDTH_STATISTICS
2278 flags = 0;
2279 for (nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
2280 ++flags;
2281 if (max_rq < flags) {
2282 max_rq = flags;
2283 TRACE3(("GDT: max_rq = %d\n",(ushort)max_rq));
2285 #endif
2288 static void gdth_next(int hanum)
2290 register gdth_ha_str *ha;
2291 register Scsi_Cmnd *pscp;
2292 register Scsi_Cmnd *nscp;
2293 unchar b, t, l, firsttime;
2294 unchar this_cmd, next_cmd;
2295 ulong flags = 0;
2296 int cmd_index;
2298 TRACE(("gdth_next() hanum %d\n",hanum));
2299 ha = HADATA(gdth_ctr_tab[hanum]);
2300 if (!gdth_polling)
2301 spin_lock_irqsave(&ha->smp_lock, flags);
2303 ha->cmd_cnt = ha->cmd_offs_dpmem = 0;
2304 this_cmd = firsttime = TRUE;
2305 next_cmd = gdth_polling ? FALSE:TRUE;
2306 cmd_index = 0;
2308 for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) {
2309 if (nscp != pscp && nscp != (Scsi_Cmnd *)pscp->SCp.ptr)
2310 pscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2311 b = virt_ctr ? NUMDATA(nscp->device->host)->busnum : nscp->device->channel;
2312 t = nscp->device->id;
2313 l = nscp->device->lun;
2314 if (nscp->SCp.this_residual >= DEFAULT_PRI) {
2315 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2316 (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock))
2317 continue;
2320 if (firsttime) {
2321 if (gdth_test_busy(hanum)) { /* controller busy ? */
2322 TRACE(("gdth_next() controller %d busy !\n",hanum));
2323 if (!gdth_polling) {
2324 spin_unlock_irqrestore(&ha->smp_lock, flags);
2325 return;
2327 while (gdth_test_busy(hanum))
2328 gdth_delay(1);
2330 firsttime = FALSE;
2333 if (nscp->done != gdth_scsi_done || nscp->cmnd[0] != 0xff) {
2334 if (nscp->SCp.phase == -1) {
2335 nscp->SCp.phase = CACHESERVICE; /* default: cache svc. */
2336 if (nscp->cmnd[0] == TEST_UNIT_READY) {
2337 TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
2338 b, t, l));
2339 /* TEST_UNIT_READY -> set scan mode */
2340 if ((ha->scan_mode & 0x0f) == 0) {
2341 if (b == 0 && t == 0 && l == 0) {
2342 ha->scan_mode |= 1;
2343 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2345 } else if ((ha->scan_mode & 0x0f) == 1) {
2346 if (b == 0 && ((t == 0 && l == 1) ||
2347 (t == 1 && l == 0))) {
2348 nscp->SCp.sent_command = GDT_SCAN_START;
2349 nscp->SCp.phase = ((ha->scan_mode & 0x10 ? 1:0) << 8)
2350 | SCSIRAWSERVICE;
2351 ha->scan_mode = 0x12;
2352 TRACE2(("Scan mode: 0x%x (SCAN_START)\n",
2353 ha->scan_mode));
2354 } else {
2355 ha->scan_mode &= 0x10;
2356 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2358 } else if (ha->scan_mode == 0x12) {
2359 if (b == ha->bus_cnt && t == ha->tid_cnt-1) {
2360 nscp->SCp.phase = SCSIRAWSERVICE;
2361 nscp->SCp.sent_command = GDT_SCAN_END;
2362 ha->scan_mode &= 0x10;
2363 TRACE2(("Scan mode: 0x%x (SCAN_END)\n",
2364 ha->scan_mode));
2368 if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY &&
2369 nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE &&
2370 (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) {
2371 /* always GDT_CLUST_INFO! */
2372 nscp->SCp.sent_command = GDT_CLUST_INFO;
2377 if (nscp->SCp.sent_command != -1) {
2378 if ((nscp->SCp.phase & 0xff) == CACHESERVICE) {
2379 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2380 this_cmd = FALSE;
2381 next_cmd = FALSE;
2382 } else if ((nscp->SCp.phase & 0xff) == SCSIRAWSERVICE) {
2383 if (!(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
2384 this_cmd = FALSE;
2385 next_cmd = FALSE;
2386 } else {
2387 memset((char*)nscp->sense_buffer,0,16);
2388 nscp->sense_buffer[0] = 0x70;
2389 nscp->sense_buffer[2] = NOT_READY;
2390 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2391 if (!nscp->SCp.have_data_in)
2392 nscp->SCp.have_data_in++;
2393 else
2394 nscp->scsi_done(nscp);
2396 } else if (nscp->done == gdth_scsi_done && nscp->cmnd[0] == 0xff) {
2397 if (!(cmd_index=gdth_special_cmd(hanum,nscp)))
2398 this_cmd = FALSE;
2399 next_cmd = FALSE;
2400 } else if (b != ha->virt_bus) {
2401 if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW ||
2402 !(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
2403 this_cmd = FALSE;
2404 else
2405 ha->raw[BUS_L2P(ha,b)].io_cnt[t]++;
2406 } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || l != 0) {
2407 TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
2408 nscp->cmnd[0], b, t, l));
2409 nscp->result = DID_BAD_TARGET << 16;
2410 if (!nscp->SCp.have_data_in)
2411 nscp->SCp.have_data_in++;
2412 else
2413 nscp->scsi_done(nscp);
2414 } else {
2415 switch (nscp->cmnd[0]) {
2416 case TEST_UNIT_READY:
2417 case INQUIRY:
2418 case REQUEST_SENSE:
2419 case READ_CAPACITY:
2420 case VERIFY:
2421 case START_STOP:
2422 case MODE_SENSE:
2423 case SERVICE_ACTION_IN:
2424 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2425 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2426 nscp->cmnd[4],nscp->cmnd[5]));
2427 if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) {
2428 /* return UNIT_ATTENTION */
2429 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2430 nscp->cmnd[0], t));
2431 ha->hdr[t].media_changed = FALSE;
2432 memset((char*)nscp->sense_buffer,0,16);
2433 nscp->sense_buffer[0] = 0x70;
2434 nscp->sense_buffer[2] = UNIT_ATTENTION;
2435 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2436 if (!nscp->SCp.have_data_in)
2437 nscp->SCp.have_data_in++;
2438 else
2439 nscp->scsi_done(nscp);
2440 } else if (gdth_internal_cache_cmd(hanum,nscp))
2441 nscp->scsi_done(nscp);
2442 break;
2444 case ALLOW_MEDIUM_REMOVAL:
2445 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2446 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2447 nscp->cmnd[4],nscp->cmnd[5]));
2448 if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) {
2449 TRACE(("Prevent r. nonremov. drive->do nothing\n"));
2450 nscp->result = DID_OK << 16;
2451 nscp->sense_buffer[0] = 0;
2452 if (!nscp->SCp.have_data_in)
2453 nscp->SCp.have_data_in++;
2454 else
2455 nscp->scsi_done(nscp);
2456 } else {
2457 nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0;
2458 TRACE(("Prevent/allow r. %d rem. drive %d\n",
2459 nscp->cmnd[4],nscp->cmnd[3]));
2460 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2461 this_cmd = FALSE;
2463 break;
2465 case RESERVE:
2466 case RELEASE:
2467 TRACE2(("cache cmd %s\n",nscp->cmnd[0] == RESERVE ?
2468 "RESERVE" : "RELEASE"));
2469 if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2470 this_cmd = FALSE;
2471 break;
2473 case READ_6:
2474 case WRITE_6:
2475 case READ_10:
2476 case WRITE_10:
2477 case READ_16:
2478 case WRITE_16:
2479 if (ha->hdr[t].media_changed) {
2480 /* return UNIT_ATTENTION */
2481 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2482 nscp->cmnd[0], t));
2483 ha->hdr[t].media_changed = FALSE;
2484 memset((char*)nscp->sense_buffer,0,16);
2485 nscp->sense_buffer[0] = 0x70;
2486 nscp->sense_buffer[2] = UNIT_ATTENTION;
2487 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2488 if (!nscp->SCp.have_data_in)
2489 nscp->SCp.have_data_in++;
2490 else
2491 nscp->scsi_done(nscp);
2492 } else if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
2493 this_cmd = FALSE;
2494 break;
2496 default:
2497 TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0],
2498 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2499 nscp->cmnd[4],nscp->cmnd[5]));
2500 printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n",
2501 hanum, nscp->cmnd[0]);
2502 nscp->result = DID_ABORT << 16;
2503 if (!nscp->SCp.have_data_in)
2504 nscp->SCp.have_data_in++;
2505 else
2506 nscp->scsi_done(nscp);
2507 break;
2511 if (!this_cmd)
2512 break;
2513 if (nscp == ha->req_first)
2514 ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
2515 else
2516 pscp->SCp.ptr = nscp->SCp.ptr;
2517 if (!next_cmd)
2518 break;
2521 if (ha->cmd_cnt > 0) {
2522 gdth_release_event(hanum);
2525 if (!gdth_polling)
2526 spin_unlock_irqrestore(&ha->smp_lock, flags);
2528 if (gdth_polling && ha->cmd_cnt > 0) {
2529 if (!gdth_wait(hanum,cmd_index,POLL_TIMEOUT))
2530 printk("GDT-HA %d: Command %d timed out !\n",
2531 hanum,cmd_index);
2535 static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
2536 char *buffer,ushort count)
2538 ushort cpcount,i;
2539 ushort cpsum,cpnow;
2540 struct scatterlist *sl;
2541 gdth_ha_str *ha;
2542 char *address;
2544 cpcount = count<=(ushort)scp->bufflen ? count:(ushort)scp->bufflen;
2545 ha = HADATA(gdth_ctr_tab[hanum]);
2547 if (scp->use_sg) {
2548 sl = (struct scatterlist *)scp->request_buffer;
2549 for (i=0,cpsum=0; i<scp->use_sg; ++i,++sl) {
2550 unsigned long flags;
2551 cpnow = (ushort)sl->length;
2552 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2553 cpnow,cpsum,cpcount,(ushort)scp->bufflen));
2554 if (cpsum+cpnow > cpcount)
2555 cpnow = cpcount - cpsum;
2556 cpsum += cpnow;
2557 if (!sl->page) {
2558 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
2559 hanum);
2560 return;
2562 local_irq_save(flags);
2563 address = kmap_atomic(sl->page, KM_BIO_SRC_IRQ) + sl->offset;
2564 memcpy(address,buffer,cpnow);
2565 flush_dcache_page(sl->page);
2566 kunmap_atomic(address, KM_BIO_SRC_IRQ);
2567 local_irq_restore(flags);
2568 if (cpsum == cpcount)
2569 break;
2570 buffer += cpnow;
2572 } else {
2573 TRACE(("copy_internal() count %d\n",cpcount));
2574 memcpy((char*)scp->request_buffer,buffer,cpcount);
2578 static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp)
2580 register gdth_ha_str *ha;
2581 unchar t;
2582 gdth_inq_data inq;
2583 gdth_rdcap_data rdc;
2584 gdth_sense_data sd;
2585 gdth_modep_data mpd;
2587 ha = HADATA(gdth_ctr_tab[hanum]);
2588 t = scp->device->id;
2589 TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
2590 scp->cmnd[0],t));
2592 scp->result = DID_OK << 16;
2593 scp->sense_buffer[0] = 0;
2595 switch (scp->cmnd[0]) {
2596 case TEST_UNIT_READY:
2597 case VERIFY:
2598 case START_STOP:
2599 TRACE2(("Test/Verify/Start hdrive %d\n",t));
2600 break;
2602 case INQUIRY:
2603 TRACE2(("Inquiry hdrive %d devtype %d\n",
2604 t,ha->hdr[t].devtype));
2605 inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK;
2606 /* you can here set all disks to removable, if you want to do
2607 a flush using the ALLOW_MEDIUM_REMOVAL command */
2608 inq.modif_rmb = 0x00;
2609 if ((ha->hdr[t].devtype & 1) ||
2610 (ha->hdr[t].cluster_type & CLUSTER_DRIVE))
2611 inq.modif_rmb = 0x80;
2612 inq.version = 2;
2613 inq.resp_aenc = 2;
2614 inq.add_length= 32;
2615 strcpy(inq.vendor,ha->oem_name);
2616 sprintf(inq.product,"Host Drive #%02d",t);
2617 strcpy(inq.revision," ");
2618 gdth_copy_internal_data(hanum,scp,(char*)&inq,sizeof(gdth_inq_data));
2619 break;
2621 case REQUEST_SENSE:
2622 TRACE2(("Request sense hdrive %d\n",t));
2623 sd.errorcode = 0x70;
2624 sd.segno = 0x00;
2625 sd.key = NO_SENSE;
2626 sd.info = 0;
2627 sd.add_length= 0;
2628 gdth_copy_internal_data(hanum,scp,(char*)&sd,sizeof(gdth_sense_data));
2629 break;
2631 case MODE_SENSE:
2632 TRACE2(("Mode sense hdrive %d\n",t));
2633 memset((char*)&mpd,0,sizeof(gdth_modep_data));
2634 mpd.hd.data_length = sizeof(gdth_modep_data);
2635 mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0;
2636 mpd.hd.bd_length = sizeof(mpd.bd);
2637 mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
2638 mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
2639 mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
2640 gdth_copy_internal_data(hanum,scp,(char*)&mpd,sizeof(gdth_modep_data));
2641 break;
2643 case READ_CAPACITY:
2644 TRACE2(("Read capacity hdrive %d\n",t));
2645 if (ha->hdr[t].size > (ulong64)0xffffffff)
2646 rdc.last_block_no = 0xffffffff;
2647 else
2648 rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1);
2649 rdc.block_length = cpu_to_be32(SECTOR_SIZE);
2650 gdth_copy_internal_data(hanum,scp,(char*)&rdc,sizeof(gdth_rdcap_data));
2651 break;
2653 case SERVICE_ACTION_IN:
2654 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 &&
2655 (ha->cache_feat & GDT_64BIT)) {
2656 gdth_rdcap16_data rdc16;
2658 TRACE2(("Read capacity (16) hdrive %d\n",t));
2659 rdc16.last_block_no = cpu_to_be64(ha->hdr[t].size-1);
2660 rdc16.block_length = cpu_to_be32(SECTOR_SIZE);
2661 gdth_copy_internal_data(hanum,scp,(char*)&rdc16,sizeof(gdth_rdcap16_data));
2662 } else {
2663 scp->result = DID_ABORT << 16;
2665 break;
2667 default:
2668 TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0]));
2669 break;
2672 if (!scp->SCp.have_data_in)
2673 scp->SCp.have_data_in++;
2674 else
2675 return 1;
2677 return 0;
2680 static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive)
2682 register gdth_ha_str *ha;
2683 register gdth_cmd_str *cmdp;
2684 struct scatterlist *sl;
2685 ulong32 cnt, blockcnt;
2686 ulong64 no, blockno;
2687 dma_addr_t phys_addr;
2688 int i, cmd_index, read_write, sgcnt, mode64;
2689 struct page *page;
2690 ulong offset;
2692 ha = HADATA(gdth_ctr_tab[hanum]);
2693 cmdp = ha->pccb;
2694 TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
2695 scp->cmnd[0],scp->cmd_len,hdrive));
2697 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2698 return 0;
2700 mode64 = (ha->cache_feat & GDT_64BIT) ? TRUE : FALSE;
2701 /* test for READ_16, WRITE_16 if !mode64 ? ---
2702 not required, should not occur due to error return on
2703 READ_CAPACITY_16 */
2705 cmdp->Service = CACHESERVICE;
2706 cmdp->RequestBuffer = scp;
2707 /* search free command index */
2708 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
2709 TRACE(("GDT: No free command index found\n"));
2710 return 0;
2712 /* if it's the first command, set command semaphore */
2713 if (ha->cmd_cnt == 0)
2714 gdth_set_sema0(hanum);
2716 /* fill command */
2717 read_write = 0;
2718 if (scp->SCp.sent_command != -1)
2719 cmdp->OpCode = scp->SCp.sent_command; /* special cache cmd. */
2720 else if (scp->cmnd[0] == RESERVE)
2721 cmdp->OpCode = GDT_RESERVE_DRV;
2722 else if (scp->cmnd[0] == RELEASE)
2723 cmdp->OpCode = GDT_RELEASE_DRV;
2724 else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
2725 if (scp->cmnd[4] & 1) /* prevent ? */
2726 cmdp->OpCode = GDT_MOUNT;
2727 else if (scp->cmnd[3] & 1) /* removable drive ? */
2728 cmdp->OpCode = GDT_UNMOUNT;
2729 else
2730 cmdp->OpCode = GDT_FLUSH;
2731 } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10 ||
2732 scp->cmnd[0] == WRITE_12 || scp->cmnd[0] == WRITE_16
2734 read_write = 1;
2735 if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) &&
2736 (ha->cache_feat & GDT_WR_THROUGH)))
2737 cmdp->OpCode = GDT_WRITE_THR;
2738 else
2739 cmdp->OpCode = GDT_WRITE;
2740 } else {
2741 read_write = 2;
2742 cmdp->OpCode = GDT_READ;
2745 cmdp->BoardNode = LOCALBOARD;
2746 if (mode64) {
2747 cmdp->u.cache64.DeviceNo = hdrive;
2748 cmdp->u.cache64.BlockNo = 1;
2749 cmdp->u.cache64.sg_canz = 0;
2750 } else {
2751 cmdp->u.cache.DeviceNo = hdrive;
2752 cmdp->u.cache.BlockNo = 1;
2753 cmdp->u.cache.sg_canz = 0;
2756 if (read_write) {
2757 if (scp->cmd_len == 16) {
2758 memcpy(&no, &scp->cmnd[2], sizeof(ulong64));
2759 blockno = be64_to_cpu(no);
2760 memcpy(&cnt, &scp->cmnd[10], sizeof(ulong32));
2761 blockcnt = be32_to_cpu(cnt);
2762 } else if (scp->cmd_len == 10) {
2763 memcpy(&no, &scp->cmnd[2], sizeof(ulong32));
2764 blockno = be32_to_cpu(no);
2765 memcpy(&cnt, &scp->cmnd[7], sizeof(ushort));
2766 blockcnt = be16_to_cpu(cnt);
2767 } else {
2768 memcpy(&no, &scp->cmnd[0], sizeof(ulong32));
2769 blockno = be32_to_cpu(no) & 0x001fffffUL;
2770 blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
2772 if (mode64) {
2773 cmdp->u.cache64.BlockNo = blockno;
2774 cmdp->u.cache64.BlockCnt = blockcnt;
2775 } else {
2776 cmdp->u.cache.BlockNo = (ulong32)blockno;
2777 cmdp->u.cache.BlockCnt = blockcnt;
2780 if (scp->use_sg) {
2781 sl = (struct scatterlist *)scp->request_buffer;
2782 sgcnt = scp->use_sg;
2783 scp->SCp.Status = GDTH_MAP_SG;
2784 scp->SCp.Message = (read_write == 1 ?
2785 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
2786 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
2787 if (mode64) {
2788 cmdp->u.cache64.DestAddr= (ulong64)-1;
2789 cmdp->u.cache64.sg_canz = sgcnt;
2790 for (i=0; i<sgcnt; ++i,++sl) {
2791 cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2792 #ifdef GDTH_DMA_STATISTICS
2793 if (cmdp->u.cache64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2794 ha->dma64_cnt++;
2795 else
2796 ha->dma32_cnt++;
2797 #endif
2798 cmdp->u.cache64.sg_lst[i].sg_len = sg_dma_len(sl);
2800 } else {
2801 cmdp->u.cache.DestAddr= 0xffffffff;
2802 cmdp->u.cache.sg_canz = sgcnt;
2803 for (i=0; i<sgcnt; ++i,++sl) {
2804 cmdp->u.cache.sg_lst[i].sg_ptr = sg_dma_address(sl);
2805 #ifdef GDTH_DMA_STATISTICS
2806 ha->dma32_cnt++;
2807 #endif
2808 cmdp->u.cache.sg_lst[i].sg_len = sg_dma_len(sl);
2812 #ifdef GDTH_STATISTICS
2813 if (max_sg < (ulong32)sgcnt) {
2814 max_sg = (ulong32)sgcnt;
2815 TRACE3(("GDT: max_sg = %d\n",max_sg));
2817 #endif
2819 } else {
2820 scp->SCp.Status = GDTH_MAP_SINGLE;
2821 scp->SCp.Message = (read_write == 1 ?
2822 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
2823 page = virt_to_page(scp->request_buffer);
2824 offset = (ulong)scp->request_buffer & ~PAGE_MASK;
2825 phys_addr = pci_map_page(ha->pdev,page,offset,
2826 scp->request_bufflen,scp->SCp.Message);
2827 scp->SCp.dma_handle = phys_addr;
2828 if (mode64) {
2829 if (ha->cache_feat & SCATTER_GATHER) {
2830 cmdp->u.cache64.DestAddr = (ulong64)-1;
2831 cmdp->u.cache64.sg_canz = 1;
2832 cmdp->u.cache64.sg_lst[0].sg_ptr = phys_addr;
2833 cmdp->u.cache64.sg_lst[0].sg_len = scp->request_bufflen;
2834 cmdp->u.cache64.sg_lst[1].sg_len = 0;
2835 } else {
2836 cmdp->u.cache64.DestAddr = phys_addr;
2837 cmdp->u.cache64.sg_canz= 0;
2839 } else {
2840 if (ha->cache_feat & SCATTER_GATHER) {
2841 cmdp->u.cache.DestAddr = 0xffffffff;
2842 cmdp->u.cache.sg_canz = 1;
2843 cmdp->u.cache.sg_lst[0].sg_ptr = phys_addr;
2844 cmdp->u.cache.sg_lst[0].sg_len = scp->request_bufflen;
2845 cmdp->u.cache.sg_lst[1].sg_len = 0;
2846 } else {
2847 cmdp->u.cache.DestAddr = phys_addr;
2848 cmdp->u.cache.sg_canz= 0;
2853 /* evaluate command size, check space */
2854 if (mode64) {
2855 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2856 cmdp->u.cache64.DestAddr,cmdp->u.cache64.sg_canz,
2857 cmdp->u.cache64.sg_lst[0].sg_ptr,
2858 cmdp->u.cache64.sg_lst[0].sg_len));
2859 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2860 cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt));
2861 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) +
2862 (ushort)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str);
2863 } else {
2864 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2865 cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
2866 cmdp->u.cache.sg_lst[0].sg_ptr,
2867 cmdp->u.cache.sg_lst[0].sg_len));
2868 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2869 cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
2870 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
2871 (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str);
2873 if (ha->cmd_len & 3)
2874 ha->cmd_len += (4 - (ha->cmd_len & 3));
2876 if (ha->cmd_cnt > 0) {
2877 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2878 ha->ic_all_size) {
2879 TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
2880 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2881 return 0;
2885 /* copy command */
2886 gdth_copy_command(hanum);
2887 return cmd_index;
2890 static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b)
2892 register gdth_ha_str *ha;
2893 register gdth_cmd_str *cmdp;
2894 struct scatterlist *sl;
2895 ushort i;
2896 dma_addr_t phys_addr, sense_paddr;
2897 int cmd_index, sgcnt, mode64;
2898 unchar t,l;
2899 struct page *page;
2900 ulong offset;
2902 ha = HADATA(gdth_ctr_tab[hanum]);
2903 t = scp->device->id;
2904 l = scp->device->lun;
2905 cmdp = ha->pccb;
2906 TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
2907 scp->cmnd[0],b,t,l));
2909 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2910 return 0;
2912 mode64 = (ha->raw_feat & GDT_64BIT) ? TRUE : FALSE;
2914 cmdp->Service = SCSIRAWSERVICE;
2915 cmdp->RequestBuffer = scp;
2916 /* search free command index */
2917 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
2918 TRACE(("GDT: No free command index found\n"));
2919 return 0;
2921 /* if it's the first command, set command semaphore */
2922 if (ha->cmd_cnt == 0)
2923 gdth_set_sema0(hanum);
2925 /* fill command */
2926 if (scp->SCp.sent_command != -1) {
2927 cmdp->OpCode = scp->SCp.sent_command; /* special raw cmd. */
2928 cmdp->BoardNode = LOCALBOARD;
2929 if (mode64) {
2930 cmdp->u.raw64.direction = (scp->SCp.phase >> 8);
2931 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2932 cmdp->OpCode, cmdp->u.raw64.direction));
2933 /* evaluate command size */
2934 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst);
2935 } else {
2936 cmdp->u.raw.direction = (scp->SCp.phase >> 8);
2937 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2938 cmdp->OpCode, cmdp->u.raw.direction));
2939 /* evaluate command size */
2940 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst);
2943 } else {
2944 page = virt_to_page(scp->sense_buffer);
2945 offset = (ulong)scp->sense_buffer & ~PAGE_MASK;
2946 sense_paddr = pci_map_page(ha->pdev,page,offset,
2947 16,PCI_DMA_FROMDEVICE);
2948 scp->SCp.buffer = (struct scatterlist *)((ulong32)sense_paddr);
2949 /* high part, if 64bit */
2950 scp->host_scribble = (char *)(ulong32)((ulong64)sense_paddr >> 32);
2951 cmdp->OpCode = GDT_WRITE; /* always */
2952 cmdp->BoardNode = LOCALBOARD;
2953 if (mode64) {
2954 cmdp->u.raw64.reserved = 0;
2955 cmdp->u.raw64.mdisc_time = 0;
2956 cmdp->u.raw64.mcon_time = 0;
2957 cmdp->u.raw64.clen = scp->cmd_len;
2958 cmdp->u.raw64.target = t;
2959 cmdp->u.raw64.lun = l;
2960 cmdp->u.raw64.bus = b;
2961 cmdp->u.raw64.priority = 0;
2962 cmdp->u.raw64.sdlen = scp->request_bufflen;
2963 cmdp->u.raw64.sense_len = 16;
2964 cmdp->u.raw64.sense_data = sense_paddr;
2965 cmdp->u.raw64.direction =
2966 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
2967 memcpy(cmdp->u.raw64.cmd,scp->cmnd,16);
2968 } else {
2969 cmdp->u.raw.reserved = 0;
2970 cmdp->u.raw.mdisc_time = 0;
2971 cmdp->u.raw.mcon_time = 0;
2972 cmdp->u.raw.clen = scp->cmd_len;
2973 cmdp->u.raw.target = t;
2974 cmdp->u.raw.lun = l;
2975 cmdp->u.raw.bus = b;
2976 cmdp->u.raw.priority = 0;
2977 cmdp->u.raw.link_p = 0;
2978 cmdp->u.raw.sdlen = scp->request_bufflen;
2979 cmdp->u.raw.sense_len = 16;
2980 cmdp->u.raw.sense_data = sense_paddr;
2981 cmdp->u.raw.direction =
2982 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
2983 memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
2986 if (scp->use_sg) {
2987 sl = (struct scatterlist *)scp->request_buffer;
2988 sgcnt = scp->use_sg;
2989 scp->SCp.Status = GDTH_MAP_SG;
2990 scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
2991 sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
2992 if (mode64) {
2993 cmdp->u.raw64.sdata = (ulong64)-1;
2994 cmdp->u.raw64.sg_ranz = sgcnt;
2995 for (i=0; i<sgcnt; ++i,++sl) {
2996 cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2997 #ifdef GDTH_DMA_STATISTICS
2998 if (cmdp->u.raw64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2999 ha->dma64_cnt++;
3000 else
3001 ha->dma32_cnt++;
3002 #endif
3003 cmdp->u.raw64.sg_lst[i].sg_len = sg_dma_len(sl);
3005 } else {
3006 cmdp->u.raw.sdata = 0xffffffff;
3007 cmdp->u.raw.sg_ranz = sgcnt;
3008 for (i=0; i<sgcnt; ++i,++sl) {
3009 cmdp->u.raw.sg_lst[i].sg_ptr = sg_dma_address(sl);
3010 #ifdef GDTH_DMA_STATISTICS
3011 ha->dma32_cnt++;
3012 #endif
3013 cmdp->u.raw.sg_lst[i].sg_len = sg_dma_len(sl);
3017 #ifdef GDTH_STATISTICS
3018 if (max_sg < sgcnt) {
3019 max_sg = sgcnt;
3020 TRACE3(("GDT: max_sg = %d\n",sgcnt));
3022 #endif
3024 } else {
3025 scp->SCp.Status = GDTH_MAP_SINGLE;
3026 scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
3027 page = virt_to_page(scp->request_buffer);
3028 offset = (ulong)scp->request_buffer & ~PAGE_MASK;
3029 phys_addr = pci_map_page(ha->pdev,page,offset,
3030 scp->request_bufflen,scp->SCp.Message);
3031 scp->SCp.dma_handle = phys_addr;
3033 if (mode64) {
3034 if (ha->raw_feat & SCATTER_GATHER) {
3035 cmdp->u.raw64.sdata = (ulong64)-1;
3036 cmdp->u.raw64.sg_ranz= 1;
3037 cmdp->u.raw64.sg_lst[0].sg_ptr = phys_addr;
3038 cmdp->u.raw64.sg_lst[0].sg_len = scp->request_bufflen;
3039 cmdp->u.raw64.sg_lst[1].sg_len = 0;
3040 } else {
3041 cmdp->u.raw64.sdata = phys_addr;
3042 cmdp->u.raw64.sg_ranz= 0;
3044 } else {
3045 if (ha->raw_feat & SCATTER_GATHER) {
3046 cmdp->u.raw.sdata = 0xffffffff;
3047 cmdp->u.raw.sg_ranz= 1;
3048 cmdp->u.raw.sg_lst[0].sg_ptr = phys_addr;
3049 cmdp->u.raw.sg_lst[0].sg_len = scp->request_bufflen;
3050 cmdp->u.raw.sg_lst[1].sg_len = 0;
3051 } else {
3052 cmdp->u.raw.sdata = phys_addr;
3053 cmdp->u.raw.sg_ranz= 0;
3057 if (mode64) {
3058 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3059 cmdp->u.raw64.sdata,cmdp->u.raw64.sg_ranz,
3060 cmdp->u.raw64.sg_lst[0].sg_ptr,
3061 cmdp->u.raw64.sg_lst[0].sg_len));
3062 /* evaluate command size */
3063 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) +
3064 (ushort)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str);
3065 } else {
3066 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
3067 cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
3068 cmdp->u.raw.sg_lst[0].sg_ptr,
3069 cmdp->u.raw.sg_lst[0].sg_len));
3070 /* evaluate command size */
3071 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
3072 (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
3075 /* check space */
3076 if (ha->cmd_len & 3)
3077 ha->cmd_len += (4 - (ha->cmd_len & 3));
3079 if (ha->cmd_cnt > 0) {
3080 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
3081 ha->ic_all_size) {
3082 TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
3083 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
3084 return 0;
3088 /* copy command */
3089 gdth_copy_command(hanum);
3090 return cmd_index;
3093 static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp)
3095 register gdth_ha_str *ha;
3096 register gdth_cmd_str *cmdp;
3097 int cmd_index;
3099 ha = HADATA(gdth_ctr_tab[hanum]);
3100 cmdp= ha->pccb;
3101 TRACE2(("gdth_special_cmd(): "));
3103 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
3104 return 0;
3106 memcpy( cmdp, scp->request_buffer, sizeof(gdth_cmd_str));
3107 cmdp->RequestBuffer = scp;
3109 /* search free command index */
3110 if (!(cmd_index=gdth_get_cmd_index(hanum))) {
3111 TRACE(("GDT: No free command index found\n"));
3112 return 0;
3115 /* if it's the first command, set command semaphore */
3116 if (ha->cmd_cnt == 0)
3117 gdth_set_sema0(hanum);
3119 /* evaluate command size, check space */
3120 if (cmdp->OpCode == GDT_IOCTL) {
3121 TRACE2(("IOCTL\n"));
3122 ha->cmd_len =
3123 GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong64);
3124 } else if (cmdp->Service == CACHESERVICE) {
3125 TRACE2(("cache command %d\n",cmdp->OpCode));
3126 if (ha->cache_feat & GDT_64BIT)
3127 ha->cmd_len =
3128 GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + sizeof(gdth_sg64_str);
3129 else
3130 ha->cmd_len =
3131 GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
3132 } else if (cmdp->Service == SCSIRAWSERVICE) {
3133 TRACE2(("raw command %d\n",cmdp->OpCode));
3134 if (ha->raw_feat & GDT_64BIT)
3135 ha->cmd_len =
3136 GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + sizeof(gdth_sg64_str);
3137 else
3138 ha->cmd_len =
3139 GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
3142 if (ha->cmd_len & 3)
3143 ha->cmd_len += (4 - (ha->cmd_len & 3));
3145 if (ha->cmd_cnt > 0) {
3146 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
3147 ha->ic_all_size) {
3148 TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
3149 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
3150 return 0;
3154 /* copy command */
3155 gdth_copy_command(hanum);
3156 return cmd_index;
3160 /* Controller event handling functions */
3161 static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
3162 ushort idx, gdth_evt_data *evt)
3164 gdth_evt_str *e;
3165 struct timeval tv;
3167 /* no GDTH_LOCK_HA() ! */
3168 TRACE2(("gdth_store_event() source %d idx %d\n", source, idx));
3169 if (source == 0) /* no source -> no event */
3170 return NULL;
3172 if (ebuffer[elastidx].event_source == source &&
3173 ebuffer[elastidx].event_idx == idx &&
3174 ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
3175 !memcmp((char *)&ebuffer[elastidx].event_data.eu,
3176 (char *)&evt->eu, evt->size)) ||
3177 (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
3178 !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
3179 (char *)&evt->event_string)))) {
3180 e = &ebuffer[elastidx];
3181 do_gettimeofday(&tv);
3182 e->last_stamp = tv.tv_sec;
3183 ++e->same_count;
3184 } else {
3185 if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
3186 ++elastidx;
3187 if (elastidx == MAX_EVENTS)
3188 elastidx = 0;
3189 if (elastidx == eoldidx) { /* reached mark ? */
3190 ++eoldidx;
3191 if (eoldidx == MAX_EVENTS)
3192 eoldidx = 0;
3195 e = &ebuffer[elastidx];
3196 e->event_source = source;
3197 e->event_idx = idx;
3198 do_gettimeofday(&tv);
3199 e->first_stamp = e->last_stamp = tv.tv_sec;
3200 e->same_count = 1;
3201 e->event_data = *evt;
3202 e->application = 0;
3204 return e;
3207 static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
3209 gdth_evt_str *e;
3210 int eindex;
3211 ulong flags;
3213 TRACE2(("gdth_read_event() handle %d\n", handle));
3214 spin_lock_irqsave(&ha->smp_lock, flags);
3215 if (handle == -1)
3216 eindex = eoldidx;
3217 else
3218 eindex = handle;
3219 estr->event_source = 0;
3221 if (eindex >= MAX_EVENTS) {
3222 spin_unlock_irqrestore(&ha->smp_lock, flags);
3223 return eindex;
3225 e = &ebuffer[eindex];
3226 if (e->event_source != 0) {
3227 if (eindex != elastidx) {
3228 if (++eindex == MAX_EVENTS)
3229 eindex = 0;
3230 } else {
3231 eindex = -1;
3233 memcpy(estr, e, sizeof(gdth_evt_str));
3235 spin_unlock_irqrestore(&ha->smp_lock, flags);
3236 return eindex;
3239 static void gdth_readapp_event(gdth_ha_str *ha,
3240 unchar application, gdth_evt_str *estr)
3242 gdth_evt_str *e;
3243 int eindex;
3244 ulong flags;
3245 unchar found = FALSE;
3247 TRACE2(("gdth_readapp_event() app. %d\n", application));
3248 spin_lock_irqsave(&ha->smp_lock, flags);
3249 eindex = eoldidx;
3250 for (;;) {
3251 e = &ebuffer[eindex];
3252 if (e->event_source == 0)
3253 break;
3254 if ((e->application & application) == 0) {
3255 e->application |= application;
3256 found = TRUE;
3257 break;
3259 if (eindex == elastidx)
3260 break;
3261 if (++eindex == MAX_EVENTS)
3262 eindex = 0;
3264 if (found)
3265 memcpy(estr, e, sizeof(gdth_evt_str));
3266 else
3267 estr->event_source = 0;
3268 spin_unlock_irqrestore(&ha->smp_lock, flags);
3271 static void gdth_clear_events(void)
3273 TRACE(("gdth_clear_events()"));
3275 eoldidx = elastidx = 0;
3276 ebuffer[0].event_source = 0;
3280 /* SCSI interface functions */
3282 static irqreturn_t gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs)
3284 gdth_ha_str *ha2 = (gdth_ha_str *)dev_id;
3285 register gdth_ha_str *ha;
3286 gdt6m_dpram_str __iomem *dp6m_ptr = NULL;
3287 gdt6_dpram_str __iomem *dp6_ptr;
3288 gdt2_dpram_str __iomem *dp2_ptr;
3289 Scsi_Cmnd *scp;
3290 int hanum, rval, i;
3291 unchar IStatus;
3292 ushort Service;
3293 ulong flags = 0;
3294 #ifdef INT_COAL
3295 int coalesced = FALSE;
3296 int next = FALSE;
3297 gdth_coal_status *pcs = NULL;
3298 int act_int_coal = 0;
3299 #endif
3301 TRACE(("gdth_interrupt() IRQ %d\n",irq));
3303 /* if polling and not from gdth_wait() -> return */
3304 if (gdth_polling) {
3305 if (!gdth_from_wait) {
3306 return IRQ_HANDLED;
3310 if (!gdth_polling)
3311 spin_lock_irqsave(&ha2->smp_lock, flags);
3312 wait_index = 0;
3314 /* search controller */
3315 if ((hanum = gdth_get_status(&IStatus,irq)) == -1) {
3316 /* spurious interrupt */
3317 if (!gdth_polling)
3318 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3319 return IRQ_HANDLED;
3321 ha = HADATA(gdth_ctr_tab[hanum]);
3323 #ifdef GDTH_STATISTICS
3324 ++act_ints;
3325 #endif
3327 #ifdef INT_COAL
3328 /* See if the fw is returning coalesced status */
3329 if (IStatus == COALINDEX) {
3330 /* Coalesced status. Setup the initial status
3331 buffer pointer and flags */
3332 pcs = ha->coal_stat;
3333 coalesced = TRUE;
3334 next = TRUE;
3337 do {
3338 if (coalesced) {
3339 /* For coalesced requests all status
3340 information is found in the status buffer */
3341 IStatus = (unchar)(pcs->status & 0xff);
3343 #endif
3345 if (ha->type == GDT_EISA) {
3346 if (IStatus & 0x80) { /* error flag */
3347 IStatus &= ~0x80;
3348 ha->status = inw(ha->bmic + MAILBOXREG+8);
3349 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3350 } else /* no error */
3351 ha->status = S_OK;
3352 ha->info = inl(ha->bmic + MAILBOXREG+12);
3353 ha->service = inw(ha->bmic + MAILBOXREG+10);
3354 ha->info2 = inl(ha->bmic + MAILBOXREG+4);
3356 outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */
3357 outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */
3358 } else if (ha->type == GDT_ISA) {
3359 dp2_ptr = ha->brd;
3360 if (IStatus & 0x80) { /* error flag */
3361 IStatus &= ~0x80;
3362 ha->status = gdth_readw(&dp2_ptr->u.ic.Status);
3363 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3364 } else /* no error */
3365 ha->status = S_OK;
3366 ha->info = gdth_readl(&dp2_ptr->u.ic.Info[0]);
3367 ha->service = gdth_readw(&dp2_ptr->u.ic.Service);
3368 ha->info2 = gdth_readl(&dp2_ptr->u.ic.Info[1]);
3370 gdth_writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
3371 gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */
3372 gdth_writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */
3373 } else if (ha->type == GDT_PCI) {
3374 dp6_ptr = ha->brd;
3375 if (IStatus & 0x80) { /* error flag */
3376 IStatus &= ~0x80;
3377 ha->status = gdth_readw(&dp6_ptr->u.ic.Status);
3378 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3379 } else /* no error */
3380 ha->status = S_OK;
3381 ha->info = gdth_readl(&dp6_ptr->u.ic.Info[0]);
3382 ha->service = gdth_readw(&dp6_ptr->u.ic.Service);
3383 ha->info2 = gdth_readl(&dp6_ptr->u.ic.Info[1]);
3385 gdth_writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
3386 gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */
3387 gdth_writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */
3388 } else if (ha->type == GDT_PCINEW) {
3389 if (IStatus & 0x80) { /* error flag */
3390 IStatus &= ~0x80;
3391 ha->status = inw(PTR2USHORT(&ha->plx->status));
3392 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3393 } else
3394 ha->status = S_OK;
3395 ha->info = inl(PTR2USHORT(&ha->plx->info[0]));
3396 ha->service = inw(PTR2USHORT(&ha->plx->service));
3397 ha->info2 = inl(PTR2USHORT(&ha->plx->info[1]));
3399 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
3400 outb(0x00, PTR2USHORT(&ha->plx->sema1_reg));
3401 } else if (ha->type == GDT_PCIMPR) {
3402 dp6m_ptr = ha->brd;
3403 if (IStatus & 0x80) { /* error flag */
3404 IStatus &= ~0x80;
3405 #ifdef INT_COAL
3406 if (coalesced)
3407 ha->status = pcs->ext_status && 0xffff;
3408 else
3409 #endif
3410 ha->status = gdth_readw(&dp6m_ptr->i960r.status);
3411 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3412 } else /* no error */
3413 ha->status = S_OK;
3414 #ifdef INT_COAL
3415 /* get information */
3416 if (coalesced) {
3417 ha->info = pcs->info0;
3418 ha->info2 = pcs->info1;
3419 ha->service = (pcs->ext_status >> 16) && 0xffff;
3420 } else
3421 #endif
3423 ha->info = gdth_readl(&dp6m_ptr->i960r.info[0]);
3424 ha->service = gdth_readw(&dp6m_ptr->i960r.service);
3425 ha->info2 = gdth_readl(&dp6m_ptr->i960r.info[1]);
3427 /* event string */
3428 if (IStatus == ASYNCINDEX) {
3429 if (ha->service != SCREENSERVICE &&
3430 (ha->fw_vers & 0xff) >= 0x1a) {
3431 ha->dvr.severity = gdth_readb
3432 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.severity);
3433 for (i = 0; i < 256; ++i) {
3434 ha->dvr.event_string[i] = gdth_readb
3435 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.evt_str[i]);
3436 if (ha->dvr.event_string[i] == 0)
3437 break;
3441 #ifdef INT_COAL
3442 /* Make sure that non coalesced interrupts get cleared
3443 before being handled by gdth_async_event/gdth_sync_event */
3444 if (!coalesced)
3445 #endif
3447 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3448 gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
3450 } else {
3451 TRACE2(("gdth_interrupt() unknown controller type\n"));
3452 if (!gdth_polling)
3453 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3454 return IRQ_HANDLED;
3457 TRACE(("gdth_interrupt() index %d stat %d info %d\n",
3458 IStatus,ha->status,ha->info));
3460 if (gdth_from_wait) {
3461 wait_hanum = hanum;
3462 wait_index = (int)IStatus;
3465 if (IStatus == ASYNCINDEX) {
3466 TRACE2(("gdth_interrupt() async. event\n"));
3467 gdth_async_event(hanum);
3468 if (!gdth_polling)
3469 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3470 gdth_next(hanum);
3471 return IRQ_HANDLED;
3474 if (IStatus == SPEZINDEX) {
3475 TRACE2(("Service unknown or not initialized !\n"));
3476 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3477 ha->dvr.eu.driver.ionode = hanum;
3478 gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr);
3479 if (!gdth_polling)
3480 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3481 return IRQ_HANDLED;
3483 scp = ha->cmd_tab[IStatus-2].cmnd;
3484 Service = ha->cmd_tab[IStatus-2].service;
3485 ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND;
3486 if (scp == UNUSED_CMND) {
3487 TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus));
3488 ha->dvr.size = sizeof(ha->dvr.eu.driver);
3489 ha->dvr.eu.driver.ionode = hanum;
3490 ha->dvr.eu.driver.index = IStatus;
3491 gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr);
3492 if (!gdth_polling)
3493 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3494 return IRQ_HANDLED;
3496 if (scp == INTERNAL_CMND) {
3497 TRACE(("gdth_interrupt() answer to internal command\n"));
3498 if (!gdth_polling)
3499 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3500 return IRQ_HANDLED;
3503 TRACE(("gdth_interrupt() sync. status\n"));
3504 rval = gdth_sync_event(hanum,Service,IStatus,scp);
3505 if (!gdth_polling)
3506 spin_unlock_irqrestore(&ha2->smp_lock, flags);
3507 if (rval == 2) {
3508 gdth_putq(hanum,scp,scp->SCp.this_residual);
3509 } else if (rval == 1) {
3510 scp->scsi_done(scp);
3513 #ifdef INT_COAL
3514 if (coalesced) {
3515 /* go to the next status in the status buffer */
3516 ++pcs;
3517 #ifdef GDTH_STATISTICS
3518 ++act_int_coal;
3519 if (act_int_coal > max_int_coal) {
3520 max_int_coal = act_int_coal;
3521 printk("GDT: max_int_coal = %d\n",(ushort)max_int_coal);
3523 #endif
3524 /* see if there is another status */
3525 if (pcs->status == 0)
3526 /* Stop the coalesce loop */
3527 next = FALSE;
3529 } while (next);
3531 /* coalescing only for new GDT_PCIMPR controllers available */
3532 if (ha->type == GDT_PCIMPR && coalesced) {
3533 gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3534 gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
3536 #endif
3538 gdth_next(hanum);
3539 return IRQ_HANDLED;
3542 static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp)
3544 register gdth_ha_str *ha;
3545 gdth_msg_str *msg;
3546 gdth_cmd_str *cmdp;
3547 unchar b, t;
3549 ha = HADATA(gdth_ctr_tab[hanum]);
3550 cmdp = ha->pccb;
3551 TRACE(("gdth_sync_event() serv %d status %d\n",
3552 service,ha->status));
3554 if (service == SCREENSERVICE) {
3555 msg = ha->pmsg;
3556 TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
3557 msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
3558 if (msg->msg_len > MSGLEN+1)
3559 msg->msg_len = MSGLEN+1;
3560 if (msg->msg_len)
3561 if (!(msg->msg_answer && msg->msg_ext)) {
3562 msg->msg_text[msg->msg_len] = '\0';
3563 printk("%s",msg->msg_text);
3566 if (msg->msg_ext && !msg->msg_answer) {
3567 while (gdth_test_busy(hanum))
3568 gdth_delay(0);
3569 cmdp->Service = SCREENSERVICE;
3570 cmdp->RequestBuffer = SCREEN_CMND;
3571 gdth_get_cmd_index(hanum);
3572 gdth_set_sema0(hanum);
3573 cmdp->OpCode = GDT_READ;
3574 cmdp->BoardNode = LOCALBOARD;
3575 cmdp->u.screen.reserved = 0;
3576 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3577 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3578 ha->cmd_offs_dpmem = 0;
3579 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3580 + sizeof(ulong64);
3581 ha->cmd_cnt = 0;
3582 gdth_copy_command(hanum);
3583 gdth_release_event(hanum);
3584 return 0;
3587 if (msg->msg_answer && msg->msg_alen) {
3588 /* default answers (getchar() not possible) */
3589 if (msg->msg_alen == 1) {
3590 msg->msg_alen = 0;
3591 msg->msg_len = 1;
3592 msg->msg_text[0] = 0;
3593 } else {
3594 msg->msg_alen -= 2;
3595 msg->msg_len = 2;
3596 msg->msg_text[0] = 1;
3597 msg->msg_text[1] = 0;
3599 msg->msg_ext = 0;
3600 msg->msg_answer = 0;
3601 while (gdth_test_busy(hanum))
3602 gdth_delay(0);
3603 cmdp->Service = SCREENSERVICE;
3604 cmdp->RequestBuffer = SCREEN_CMND;
3605 gdth_get_cmd_index(hanum);
3606 gdth_set_sema0(hanum);
3607 cmdp->OpCode = GDT_WRITE;
3608 cmdp->BoardNode = LOCALBOARD;
3609 cmdp->u.screen.reserved = 0;
3610 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3611 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3612 ha->cmd_offs_dpmem = 0;
3613 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3614 + sizeof(ulong64);
3615 ha->cmd_cnt = 0;
3616 gdth_copy_command(hanum);
3617 gdth_release_event(hanum);
3618 return 0;
3620 printk("\n");
3622 } else {
3623 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
3624 t = scp->device->id;
3625 if (scp->SCp.sent_command == -1 && b != ha->virt_bus) {
3626 ha->raw[BUS_L2P(ha,b)].io_cnt[t]--;
3628 /* cache or raw service */
3629 if (ha->status == S_BSY) {
3630 TRACE2(("Controller busy -> retry !\n"));
3631 if (scp->SCp.sent_command == GDT_MOUNT)
3632 scp->SCp.sent_command = GDT_CLUST_INFO;
3633 /* retry */
3634 return 2;
3636 if (scp->SCp.Status == GDTH_MAP_SG)
3637 pci_unmap_sg(ha->pdev,scp->request_buffer,
3638 scp->use_sg,scp->SCp.Message);
3639 else if (scp->SCp.Status == GDTH_MAP_SINGLE)
3640 pci_unmap_page(ha->pdev,scp->SCp.dma_handle,
3641 scp->request_bufflen,scp->SCp.Message);
3642 if (scp->SCp.buffer) {
3643 dma_addr_t addr;
3644 addr = (dma_addr_t)(ulong32)scp->SCp.buffer;
3645 if (scp->host_scribble)
3646 addr += (dma_addr_t)((ulong64)(ulong32)scp->host_scribble << 32);
3647 pci_unmap_page(ha->pdev,addr,16,PCI_DMA_FROMDEVICE);
3650 if (ha->status == S_OK) {
3651 scp->SCp.Status = S_OK;
3652 scp->SCp.Message = ha->info;
3653 if (scp->SCp.sent_command != -1) {
3654 TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
3655 scp->SCp.sent_command));
3656 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
3657 if (scp->SCp.sent_command == GDT_CLUST_INFO) {
3658 ha->hdr[t].cluster_type = (unchar)ha->info;
3659 if (!(ha->hdr[t].cluster_type &
3660 CLUSTER_MOUNTED)) {
3661 /* NOT MOUNTED -> MOUNT */
3662 scp->SCp.sent_command = GDT_MOUNT;
3663 if (ha->hdr[t].cluster_type &
3664 CLUSTER_RESERVED) {
3665 /* cluster drive RESERVED (on the other node) */
3666 scp->SCp.phase = -2; /* reservation conflict */
3668 } else {
3669 scp->SCp.sent_command = -1;
3671 } else {
3672 if (scp->SCp.sent_command == GDT_MOUNT) {
3673 ha->hdr[t].cluster_type |= CLUSTER_MOUNTED;
3674 ha->hdr[t].media_changed = TRUE;
3675 } else if (scp->SCp.sent_command == GDT_UNMOUNT) {
3676 ha->hdr[t].cluster_type &= ~CLUSTER_MOUNTED;
3677 ha->hdr[t].media_changed = TRUE;
3679 scp->SCp.sent_command = -1;
3681 /* retry */
3682 scp->SCp.this_residual = HIGH_PRI;
3683 return 2;
3684 } else {
3685 /* RESERVE/RELEASE ? */
3686 if (scp->cmnd[0] == RESERVE) {
3687 ha->hdr[t].cluster_type |= CLUSTER_RESERVED;
3688 } else if (scp->cmnd[0] == RELEASE) {
3689 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3691 scp->result = DID_OK << 16;
3692 scp->sense_buffer[0] = 0;
3694 } else {
3695 scp->SCp.Status = ha->status;
3696 scp->SCp.Message = ha->info;
3698 if (scp->SCp.sent_command != -1) {
3699 TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
3700 scp->SCp.sent_command, ha->status));
3701 if (scp->SCp.sent_command == GDT_SCAN_START ||
3702 scp->SCp.sent_command == GDT_SCAN_END) {
3703 scp->SCp.sent_command = -1;
3704 /* retry */
3705 scp->SCp.this_residual = HIGH_PRI;
3706 return 2;
3708 memset((char*)scp->sense_buffer,0,16);
3709 scp->sense_buffer[0] = 0x70;
3710 scp->sense_buffer[2] = NOT_READY;
3711 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
3712 } else if (service == CACHESERVICE) {
3713 if (ha->status == S_CACHE_UNKNOWN &&
3714 (ha->hdr[t].cluster_type &
3715 CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) {
3716 /* bus reset -> force GDT_CLUST_INFO */
3717 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3719 memset((char*)scp->sense_buffer,0,16);
3720 if (ha->status == (ushort)S_CACHE_RESERV) {
3721 scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
3722 } else {
3723 scp->sense_buffer[0] = 0x70;
3724 scp->sense_buffer[2] = NOT_READY;
3725 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
3727 if (scp->done != gdth_scsi_done) {
3728 ha->dvr.size = sizeof(ha->dvr.eu.sync);
3729 ha->dvr.eu.sync.ionode = hanum;
3730 ha->dvr.eu.sync.service = service;
3731 ha->dvr.eu.sync.status = ha->status;
3732 ha->dvr.eu.sync.info = ha->info;
3733 ha->dvr.eu.sync.hostdrive = t;
3734 if (ha->status >= 0x8000)
3735 gdth_store_event(ha, ES_SYNC, 0, &ha->dvr);
3736 else
3737 gdth_store_event(ha, ES_SYNC, service, &ha->dvr);
3739 } else {
3740 /* sense buffer filled from controller firmware (DMA) */
3741 if (ha->status != S_RAW_SCSI || ha->info >= 0x100) {
3742 scp->result = DID_BAD_TARGET << 16;
3743 } else {
3744 scp->result = (DID_OK << 16) | ha->info;
3748 if (!scp->SCp.have_data_in)
3749 scp->SCp.have_data_in++;
3750 else
3751 return 1;
3754 return 0;
3757 static char *async_cache_tab[] = {
3758 /* 0*/ "\011\000\002\002\002\004\002\006\004"
3759 "GDT HA %u, service %u, async. status %u/%lu unknown",
3760 /* 1*/ "\011\000\002\002\002\004\002\006\004"
3761 "GDT HA %u, service %u, async. status %u/%lu unknown",
3762 /* 2*/ "\005\000\002\006\004"
3763 "GDT HA %u, Host Drive %lu not ready",
3764 /* 3*/ "\005\000\002\006\004"
3765 "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",
3766 /* 4*/ "\005\000\002\006\004"
3767 "GDT HA %u, mirror update on Host Drive %lu failed",
3768 /* 5*/ "\005\000\002\006\004"
3769 "GDT HA %u, Mirror Drive %lu failed",
3770 /* 6*/ "\005\000\002\006\004"
3771 "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",
3772 /* 7*/ "\005\000\002\006\004"
3773 "GDT HA %u, Host Drive %lu write protected",
3774 /* 8*/ "\005\000\002\006\004"
3775 "GDT HA %u, media changed in Host Drive %lu",
3776 /* 9*/ "\005\000\002\006\004"
3777 "GDT HA %u, Host Drive %lu is offline",
3778 /*10*/ "\005\000\002\006\004"
3779 "GDT HA %u, media change of Mirror Drive %lu",
3780 /*11*/ "\005\000\002\006\004"
3781 "GDT HA %u, Mirror Drive %lu is write protected",
3782 /*12*/ "\005\000\002\006\004"
3783 "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
3784 /*13*/ "\007\000\002\006\002\010\002"
3785 "GDT HA %u, Array Drive %u: Cache Drive %u failed",
3786 /*14*/ "\005\000\002\006\002"
3787 "GDT HA %u, Array Drive %u: FAIL state entered",
3788 /*15*/ "\005\000\002\006\002"
3789 "GDT HA %u, Array Drive %u: error",
3790 /*16*/ "\007\000\002\006\002\010\002"
3791 "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
3792 /*17*/ "\005\000\002\006\002"
3793 "GDT HA %u, Array Drive %u: parity build failed",
3794 /*18*/ "\005\000\002\006\002"
3795 "GDT HA %u, Array Drive %u: drive rebuild failed",
3796 /*19*/ "\005\000\002\010\002"
3797 "GDT HA %u, Test of Hot Fix %u failed",
3798 /*20*/ "\005\000\002\006\002"
3799 "GDT HA %u, Array Drive %u: drive build finished successfully",
3800 /*21*/ "\005\000\002\006\002"
3801 "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
3802 /*22*/ "\007\000\002\006\002\010\002"
3803 "GDT HA %u, Array Drive %u: Hot Fix %u activated",
3804 /*23*/ "\005\000\002\006\002"
3805 "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
3806 /*24*/ "\005\000\002\010\002"
3807 "GDT HA %u, mirror update on Cache Drive %u completed",
3808 /*25*/ "\005\000\002\010\002"
3809 "GDT HA %u, mirror update on Cache Drive %lu failed",
3810 /*26*/ "\005\000\002\006\002"
3811 "GDT HA %u, Array Drive %u: drive rebuild started",
3812 /*27*/ "\005\000\002\012\001"
3813 "GDT HA %u, Fault bus %u: SHELF OK detected",
3814 /*28*/ "\005\000\002\012\001"
3815 "GDT HA %u, Fault bus %u: SHELF not OK detected",
3816 /*29*/ "\007\000\002\012\001\013\001"
3817 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
3818 /*30*/ "\007\000\002\012\001\013\001"
3819 "GDT HA %u, Fault bus %u, ID %u: new disk detected",
3820 /*31*/ "\007\000\002\012\001\013\001"
3821 "GDT HA %u, Fault bus %u, ID %u: old disk detected",
3822 /*32*/ "\007\000\002\012\001\013\001"
3823 "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid",
3824 /*33*/ "\007\000\002\012\001\013\001"
3825 "GDT HA %u, Fault bus %u, ID %u: invalid device detected",
3826 /*34*/ "\011\000\002\012\001\013\001\006\004"
3827 "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
3828 /*35*/ "\007\000\002\012\001\013\001"
3829 "GDT HA %u, Fault bus %u, ID %u: disk write protected",
3830 /*36*/ "\007\000\002\012\001\013\001"
3831 "GDT HA %u, Fault bus %u, ID %u: disk not available",
3832 /*37*/ "\007\000\002\012\001\006\004"
3833 "GDT HA %u, Fault bus %u: swap detected (%lu)",
3834 /*38*/ "\007\000\002\012\001\013\001"
3835 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
3836 /*39*/ "\007\000\002\012\001\013\001"
3837 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
3838 /*40*/ "\007\000\002\012\001\013\001"
3839 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
3840 /*41*/ "\007\000\002\012\001\013\001"
3841 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
3842 /*42*/ "\005\000\002\006\002"
3843 "GDT HA %u, Array Drive %u: drive build started",
3844 /*43*/ "\003\000\002"
3845 "GDT HA %u, DRAM parity error detected",
3846 /*44*/ "\005\000\002\006\002"
3847 "GDT HA %u, Mirror Drive %u: update started",
3848 /*45*/ "\007\000\002\006\002\010\002"
3849 "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
3850 /*46*/ "\005\000\002\006\002"
3851 "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
3852 /*47*/ "\005\000\002\006\002"
3853 "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
3854 /*48*/ "\005\000\002\006\002"
3855 "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
3856 /*49*/ "\005\000\002\006\002"
3857 "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
3858 /*50*/ "\007\000\002\012\001\013\001"
3859 "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
3860 /*51*/ "\005\000\002\006\002"
3861 "GDT HA %u, Array Drive %u: expand started",
3862 /*52*/ "\005\000\002\006\002"
3863 "GDT HA %u, Array Drive %u: expand finished successfully",
3864 /*53*/ "\005\000\002\006\002"
3865 "GDT HA %u, Array Drive %u: expand failed",
3866 /*54*/ "\003\000\002"
3867 "GDT HA %u, CPU temperature critical",
3868 /*55*/ "\003\000\002"
3869 "GDT HA %u, CPU temperature OK",
3870 /*56*/ "\005\000\002\006\004"
3871 "GDT HA %u, Host drive %lu created",
3872 /*57*/ "\005\000\002\006\002"
3873 "GDT HA %u, Array Drive %u: expand restarted",
3874 /*58*/ "\005\000\002\006\002"
3875 "GDT HA %u, Array Drive %u: expand stopped",
3876 /*59*/ "\005\000\002\010\002"
3877 "GDT HA %u, Mirror Drive %u: drive build quited",
3878 /*60*/ "\005\000\002\006\002"
3879 "GDT HA %u, Array Drive %u: parity build quited",
3880 /*61*/ "\005\000\002\006\002"
3881 "GDT HA %u, Array Drive %u: drive rebuild quited",
3882 /*62*/ "\005\000\002\006\002"
3883 "GDT HA %u, Array Drive %u: parity verify started",
3884 /*63*/ "\005\000\002\006\002"
3885 "GDT HA %u, Array Drive %u: parity verify done",
3886 /*64*/ "\005\000\002\006\002"
3887 "GDT HA %u, Array Drive %u: parity verify failed",
3888 /*65*/ "\005\000\002\006\002"
3889 "GDT HA %u, Array Drive %u: parity error detected",
3890 /*66*/ "\005\000\002\006\002"
3891 "GDT HA %u, Array Drive %u: parity verify quited",
3892 /*67*/ "\005\000\002\006\002"
3893 "GDT HA %u, Host Drive %u reserved",
3894 /*68*/ "\005\000\002\006\002"
3895 "GDT HA %u, Host Drive %u mounted and released",
3896 /*69*/ "\005\000\002\006\002"
3897 "GDT HA %u, Host Drive %u released",
3898 /*70*/ "\003\000\002"
3899 "GDT HA %u, DRAM error detected and corrected with ECC",
3900 /*71*/ "\003\000\002"
3901 "GDT HA %u, Uncorrectable DRAM error detected with ECC",
3902 /*72*/ "\011\000\002\012\001\013\001\014\001"
3903 "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
3904 /*73*/ "\005\000\002\006\002"
3905 "GDT HA %u, Host drive %u resetted locally",
3906 /*74*/ "\005\000\002\006\002"
3907 "GDT HA %u, Host drive %u resetted remotely",
3908 /*75*/ "\003\000\002"
3909 "GDT HA %u, async. status 75 unknown",
3913 static int gdth_async_event(int hanum)
3915 gdth_ha_str *ha;
3916 gdth_cmd_str *cmdp;
3917 int cmd_index;
3919 ha = HADATA(gdth_ctr_tab[hanum]);
3920 cmdp= ha->pccb;
3921 TRACE2(("gdth_async_event() ha %d serv %d\n",
3922 hanum,ha->service));
3924 if (ha->service == SCREENSERVICE) {
3925 if (ha->status == MSG_REQUEST) {
3926 while (gdth_test_busy(hanum))
3927 gdth_delay(0);
3928 cmdp->Service = SCREENSERVICE;
3929 cmdp->RequestBuffer = SCREEN_CMND;
3930 cmd_index = gdth_get_cmd_index(hanum);
3931 gdth_set_sema0(hanum);
3932 cmdp->OpCode = GDT_READ;
3933 cmdp->BoardNode = LOCALBOARD;
3934 cmdp->u.screen.reserved = 0;
3935 cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE;
3936 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3937 ha->cmd_offs_dpmem = 0;
3938 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3939 + sizeof(ulong64);
3940 ha->cmd_cnt = 0;
3941 gdth_copy_command(hanum);
3942 if (ha->type == GDT_EISA)
3943 printk("[EISA slot %d] ",(ushort)ha->brd_phys);
3944 else if (ha->type == GDT_ISA)
3945 printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys);
3946 else
3947 printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8),
3948 (ushort)((ha->brd_phys>>3)&0x1f));
3949 gdth_release_event(hanum);
3952 } else {
3953 if (ha->type == GDT_PCIMPR &&
3954 (ha->fw_vers & 0xff) >= 0x1a) {
3955 ha->dvr.size = 0;
3956 ha->dvr.eu.async.ionode = hanum;
3957 ha->dvr.eu.async.status = ha->status;
3958 /* severity and event_string already set! */
3959 } else {
3960 ha->dvr.size = sizeof(ha->dvr.eu.async);
3961 ha->dvr.eu.async.ionode = hanum;
3962 ha->dvr.eu.async.service = ha->service;
3963 ha->dvr.eu.async.status = ha->status;
3964 ha->dvr.eu.async.info = ha->info;
3965 *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2;
3967 gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr );
3968 gdth_log_event( &ha->dvr, NULL );
3970 /* new host drive from expand? */
3971 if (ha->service == CACHESERVICE && ha->status == 56) {
3972 TRACE2(("gdth_async_event(): new host drive %d created\n",
3973 (ushort)ha->info));
3974 /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
3977 return 1;
3980 static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
3982 gdth_stackframe stack;
3983 char *f = NULL;
3984 int i,j;
3986 TRACE2(("gdth_log_event()\n"));
3987 if (dvr->size == 0) {
3988 if (buffer == NULL) {
3989 printk("Adapter %d: %s\n",dvr->eu.async.ionode,dvr->event_string);
3990 } else {
3991 sprintf(buffer,"Adapter %d: %s\n",
3992 dvr->eu.async.ionode,dvr->event_string);
3994 } else if (dvr->eu.async.service == CACHESERVICE &&
3995 INDEX_OK(dvr->eu.async.status, async_cache_tab)) {
3996 TRACE2(("GDT: Async. event cache service, event no.: %d\n",
3997 dvr->eu.async.status));
3999 f = async_cache_tab[dvr->eu.async.status];
4001 /* i: parameter to push, j: stack element to fill */
4002 for (j=0,i=1; i < f[0]; i+=2) {
4003 switch (f[i+1]) {
4004 case 4:
4005 stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]];
4006 break;
4007 case 2:
4008 stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]];
4009 break;
4010 case 1:
4011 stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]];
4012 break;
4013 default:
4014 break;
4018 if (buffer == NULL) {
4019 printk(&f[(int)f[0]],stack);
4020 printk("\n");
4021 } else {
4022 sprintf(buffer,&f[(int)f[0]],stack);
4025 } else {
4026 if (buffer == NULL) {
4027 printk("GDT HA %u, Unknown async. event service %d event no. %d\n",
4028 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
4029 } else {
4030 sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d",
4031 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
4036 #ifdef GDTH_STATISTICS
4037 static void gdth_timeout(ulong data)
4039 ulong32 i;
4040 Scsi_Cmnd *nscp;
4041 gdth_ha_str *ha;
4042 ulong flags;
4043 int hanum = 0;
4045 ha = HADATA(gdth_ctr_tab[hanum]);
4046 spin_lock_irqsave(&ha->smp_lock, flags);
4048 for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i)
4049 if (ha->cmd_tab[i].cmnd != UNUSED_CMND)
4050 ++act_stats;
4052 for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
4053 ++act_rq;
4055 TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
4056 act_ints, act_ios, act_stats, act_rq));
4057 act_ints = act_ios = 0;
4059 gdth_timer.expires = jiffies + 30 * HZ;
4060 add_timer(&gdth_timer);
4061 spin_unlock_irqrestore(&ha->smp_lock, flags);
4063 #endif
4065 static void __init internal_setup(char *str,int *ints)
4067 int i, argc;
4068 char *cur_str, *argv;
4070 TRACE2(("internal_setup() str %s ints[0] %d\n",
4071 str ? str:"NULL", ints ? ints[0]:0));
4073 /* read irq[] from ints[] */
4074 if (ints) {
4075 argc = ints[0];
4076 if (argc > 0) {
4077 if (argc > MAXHA)
4078 argc = MAXHA;
4079 for (i = 0; i < argc; ++i)
4080 irq[i] = ints[i+1];
4084 /* analyse string */
4085 argv = str;
4086 while (argv && (cur_str = strchr(argv, ':'))) {
4087 int val = 0, c = *++cur_str;
4089 if (c == 'n' || c == 'N')
4090 val = 0;
4091 else if (c == 'y' || c == 'Y')
4092 val = 1;
4093 else
4094 val = (int)simple_strtoul(cur_str, NULL, 0);
4096 if (!strncmp(argv, "disable:", 8))
4097 disable = val;
4098 else if (!strncmp(argv, "reserve_mode:", 13))
4099 reserve_mode = val;
4100 else if (!strncmp(argv, "reverse_scan:", 13))
4101 reverse_scan = val;
4102 else if (!strncmp(argv, "hdr_channel:", 12))
4103 hdr_channel = val;
4104 else if (!strncmp(argv, "max_ids:", 8))
4105 max_ids = val;
4106 else if (!strncmp(argv, "rescan:", 7))
4107 rescan = val;
4108 else if (!strncmp(argv, "virt_ctr:", 9))
4109 virt_ctr = val;
4110 else if (!strncmp(argv, "shared_access:", 14))
4111 shared_access = val;
4112 else if (!strncmp(argv, "probe_eisa_isa:", 15))
4113 probe_eisa_isa = val;
4114 else if (!strncmp(argv, "reserve_list:", 13)) {
4115 reserve_list[0] = val;
4116 for (i = 1; i < MAX_RES_ARGS; i++) {
4117 cur_str = strchr(cur_str, ',');
4118 if (!cur_str)
4119 break;
4120 if (!isdigit((int)*++cur_str)) {
4121 --cur_str;
4122 break;
4124 reserve_list[i] =
4125 (int)simple_strtoul(cur_str, NULL, 0);
4127 if (!cur_str)
4128 break;
4129 argv = ++cur_str;
4130 continue;
4133 if ((argv = strchr(argv, ',')))
4134 ++argv;
4138 int __init option_setup(char *str)
4140 int ints[MAXHA];
4141 char *cur = str;
4142 int i = 1;
4144 TRACE2(("option_setup() str %s\n", str ? str:"NULL"));
4146 while (cur && isdigit(*cur) && i <= MAXHA) {
4147 ints[i++] = simple_strtoul(cur, NULL, 0);
4148 if ((cur = strchr(cur, ',')) != NULL) cur++;
4151 ints[0] = i - 1;
4152 internal_setup(cur, ints);
4153 return 1;
4156 static int __init gdth_detect(Scsi_Host_Template *shtp)
4158 struct Scsi_Host *shp;
4159 gdth_pci_str pcistr[MAXHA];
4160 gdth_ha_str *ha;
4161 ulong32 isa_bios;
4162 ushort eisa_slot;
4163 int i,hanum,cnt,ctr,err;
4164 unchar b;
4167 #ifdef DEBUG_GDTH
4168 printk("GDT: This driver contains debugging information !! Trace level = %d\n",
4169 DebugState);
4170 printk(" Destination of debugging information: ");
4171 #ifdef __SERIAL__
4172 #ifdef __COM2__
4173 printk("Serial port COM2\n");
4174 #else
4175 printk("Serial port COM1\n");
4176 #endif
4177 #else
4178 printk("Console\n");
4179 #endif
4180 gdth_delay(3000);
4181 #endif
4183 TRACE(("gdth_detect()\n"));
4185 if (disable) {
4186 printk("GDT-HA: Controller driver disabled from command line !\n");
4187 return 0;
4190 printk("GDT-HA: Storage RAID Controller Driver. Version: %s \n",GDTH_VERSION_STR);
4191 /* initializations */
4192 gdth_polling = TRUE; b = 0;
4193 gdth_clear_events();
4195 /* As default we do not probe for EISA or ISA controllers */
4196 if (probe_eisa_isa) {
4197 /* scanning for controllers, at first: ISA controller */
4198 for (isa_bios=0xc8000UL; isa_bios<=0xd8000UL; isa_bios+=0x8000UL) {
4199 dma_addr_t scratch_dma_handle;
4200 scratch_dma_handle = 0;
4202 if (gdth_ctr_count >= MAXHA)
4203 break;
4204 if (gdth_search_isa(isa_bios)) { /* controller found */
4205 shp = scsi_register(shtp,sizeof(gdth_ext_str));
4206 if (shp == NULL)
4207 continue;
4209 ha = HADATA(shp);
4210 if (!gdth_init_isa(isa_bios,ha)) {
4211 scsi_unregister(shp);
4212 continue;
4214 #ifdef __ia64__
4215 break;
4216 #else
4217 /* controller found and initialized */
4218 printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
4219 isa_bios,ha->irq,ha->drq);
4221 if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha)) {
4222 printk("GDT-ISA: Unable to allocate IRQ\n");
4223 scsi_unregister(shp);
4224 continue;
4226 if (request_dma(ha->drq,"gdth")) {
4227 printk("GDT-ISA: Unable to allocate DMA channel\n");
4228 free_irq(ha->irq,ha);
4229 scsi_unregister(shp);
4230 continue;
4232 set_dma_mode(ha->drq,DMA_MODE_CASCADE);
4233 enable_dma(ha->drq);
4234 shp->unchecked_isa_dma = 1;
4235 shp->irq = ha->irq;
4236 shp->dma_channel = ha->drq;
4237 hanum = gdth_ctr_count;
4238 gdth_ctr_tab[gdth_ctr_count++] = shp;
4239 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4241 NUMDATA(shp)->hanum = (ushort)hanum;
4242 NUMDATA(shp)->busnum= 0;
4244 ha->pccb = CMDDATA(shp);
4245 ha->ccb_phys = 0L;
4246 ha->pdev = NULL;
4247 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4248 &scratch_dma_handle);
4249 ha->scratch_phys = scratch_dma_handle;
4250 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4251 &scratch_dma_handle);
4252 ha->msg_phys = scratch_dma_handle;
4253 #ifdef INT_COAL
4254 ha->coal_stat = (gdth_coal_status *)
4255 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4256 MAXOFFSETS, &scratch_dma_handle);
4257 ha->coal_stat_phys = scratch_dma_handle;
4258 #endif
4260 ha->scratch_busy = FALSE;
4261 ha->req_first = NULL;
4262 ha->tid_cnt = MAX_HDRIVES;
4263 if (max_ids > 0 && max_ids < ha->tid_cnt)
4264 ha->tid_cnt = max_ids;
4265 for (i=0; i<GDTH_MAXCMDS; ++i)
4266 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4267 ha->scan_mode = rescan ? 0x10 : 0;
4269 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4270 !gdth_search_drives(hanum)) {
4271 printk("GDT-ISA: Error during device scan\n");
4272 --gdth_ctr_count;
4273 --gdth_ctr_vcount;
4275 #ifdef INT_COAL
4276 if (ha->coal_stat)
4277 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4278 MAXOFFSETS, ha->coal_stat,
4279 ha->coal_stat_phys);
4280 #endif
4281 if (ha->pscratch)
4282 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4283 ha->pscratch, ha->scratch_phys);
4284 if (ha->pmsg)
4285 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4286 ha->pmsg, ha->msg_phys);
4288 free_irq(ha->irq,ha);
4289 scsi_unregister(shp);
4290 continue;
4292 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4293 hdr_channel = ha->bus_cnt;
4294 ha->virt_bus = hdr_channel;
4296 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
4297 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4298 shp->highmem_io = 0;
4299 #endif
4300 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4301 shp->max_cmd_len = 16;
4303 shp->max_id = ha->tid_cnt;
4304 shp->max_lun = MAXLUN;
4305 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4306 if (virt_ctr) {
4307 virt_ctr = 1;
4308 /* register addit. SCSI channels as virtual controllers */
4309 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4310 shp = scsi_register(shtp,sizeof(gdth_num_str));
4311 shp->unchecked_isa_dma = 1;
4312 shp->irq = ha->irq;
4313 shp->dma_channel = ha->drq;
4314 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4315 NUMDATA(shp)->hanum = (ushort)hanum;
4316 NUMDATA(shp)->busnum = b;
4320 spin_lock_init(&ha->smp_lock);
4321 gdth_enable_int(hanum);
4322 #endif /* !__ia64__ */
4326 /* scanning for EISA controllers */
4327 for (eisa_slot=0x1000; eisa_slot<=0x8000; eisa_slot+=0x1000) {
4328 dma_addr_t scratch_dma_handle;
4329 scratch_dma_handle = 0;
4331 if (gdth_ctr_count >= MAXHA)
4332 break;
4333 if (gdth_search_eisa(eisa_slot)) { /* controller found */
4334 shp = scsi_register(shtp,sizeof(gdth_ext_str));
4335 if (shp == NULL)
4336 continue;
4338 ha = HADATA(shp);
4339 if (!gdth_init_eisa(eisa_slot,ha)) {
4340 scsi_unregister(shp);
4341 continue;
4343 /* controller found and initialized */
4344 printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
4345 eisa_slot>>12,ha->irq);
4347 if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha)) {
4348 printk("GDT-EISA: Unable to allocate IRQ\n");
4349 scsi_unregister(shp);
4350 continue;
4352 shp->unchecked_isa_dma = 0;
4353 shp->irq = ha->irq;
4354 shp->dma_channel = 0xff;
4355 hanum = gdth_ctr_count;
4356 gdth_ctr_tab[gdth_ctr_count++] = shp;
4357 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4359 NUMDATA(shp)->hanum = (ushort)hanum;
4360 NUMDATA(shp)->busnum= 0;
4361 TRACE2(("EISA detect Bus 0: hanum %d\n",
4362 NUMDATA(shp)->hanum));
4364 ha->pccb = CMDDATA(shp);
4365 ha->ccb_phys = 0L;
4367 ha->pdev = NULL;
4368 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4369 &scratch_dma_handle);
4370 ha->scratch_phys = scratch_dma_handle;
4371 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4372 &scratch_dma_handle);
4373 ha->msg_phys = scratch_dma_handle;
4374 #ifdef INT_COAL
4375 ha->coal_stat = (gdth_coal_status *)
4376 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4377 MAXOFFSETS, &scratch_dma_handle);
4378 ha->coal_stat_phys = scratch_dma_handle;
4379 #endif
4380 ha->ccb_phys =
4381 pci_map_single(ha->pdev,ha->pccb,
4382 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
4383 ha->scratch_busy = FALSE;
4384 ha->req_first = NULL;
4385 ha->tid_cnt = MAX_HDRIVES;
4386 if (max_ids > 0 && max_ids < ha->tid_cnt)
4387 ha->tid_cnt = max_ids;
4388 for (i=0; i<GDTH_MAXCMDS; ++i)
4389 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4390 ha->scan_mode = rescan ? 0x10 : 0;
4392 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4393 !gdth_search_drives(hanum)) {
4394 printk("GDT-EISA: Error during device scan\n");
4395 --gdth_ctr_count;
4396 --gdth_ctr_vcount;
4397 #ifdef INT_COAL
4398 if (ha->coal_stat)
4399 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4400 MAXOFFSETS, ha->coal_stat,
4401 ha->coal_stat_phys);
4402 #endif
4403 if (ha->pscratch)
4404 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4405 ha->pscratch, ha->scratch_phys);
4406 if (ha->pmsg)
4407 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4408 ha->pmsg, ha->msg_phys);
4409 if (ha->ccb_phys)
4410 pci_unmap_single(ha->pdev,ha->ccb_phys,
4411 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
4412 free_irq(ha->irq,ha);
4413 scsi_unregister(shp);
4414 continue;
4416 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4417 hdr_channel = ha->bus_cnt;
4418 ha->virt_bus = hdr_channel;
4420 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
4421 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4422 shp->highmem_io = 0;
4423 #endif
4424 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4425 shp->max_cmd_len = 16;
4427 shp->max_id = ha->tid_cnt;
4428 shp->max_lun = MAXLUN;
4429 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4430 if (virt_ctr) {
4431 virt_ctr = 1;
4432 /* register addit. SCSI channels as virtual controllers */
4433 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4434 shp = scsi_register(shtp,sizeof(gdth_num_str));
4435 shp->unchecked_isa_dma = 0;
4436 shp->irq = ha->irq;
4437 shp->dma_channel = 0xff;
4438 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4439 NUMDATA(shp)->hanum = (ushort)hanum;
4440 NUMDATA(shp)->busnum = b;
4444 spin_lock_init(&ha->smp_lock);
4445 gdth_enable_int(hanum);
4450 /* scanning for PCI controllers */
4451 cnt = gdth_search_pci(pcistr);
4452 printk("GDT-HA: Found %d PCI Storage RAID Controllers\n",cnt);
4453 gdth_sort_pci(pcistr,cnt);
4454 for (ctr = 0; ctr < cnt; ++ctr) {
4455 dma_addr_t scratch_dma_handle;
4456 scratch_dma_handle = 0;
4458 if (gdth_ctr_count >= MAXHA)
4459 break;
4460 shp = scsi_register(shtp,sizeof(gdth_ext_str));
4461 if (shp == NULL)
4462 continue;
4464 ha = HADATA(shp);
4465 if (!gdth_init_pci(&pcistr[ctr],ha)) {
4466 scsi_unregister(shp);
4467 continue;
4469 /* controller found and initialized */
4470 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
4471 pcistr[ctr].bus,PCI_SLOT(pcistr[ctr].device_fn),ha->irq);
4473 if (request_irq(ha->irq, gdth_interrupt,
4474 SA_INTERRUPT|SA_SHIRQ, "gdth", ha))
4476 printk("GDT-PCI: Unable to allocate IRQ\n");
4477 scsi_unregister(shp);
4478 continue;
4480 shp->unchecked_isa_dma = 0;
4481 shp->irq = ha->irq;
4482 shp->dma_channel = 0xff;
4483 hanum = gdth_ctr_count;
4484 gdth_ctr_tab[gdth_ctr_count++] = shp;
4485 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4487 NUMDATA(shp)->hanum = (ushort)hanum;
4488 NUMDATA(shp)->busnum= 0;
4490 ha->pccb = CMDDATA(shp);
4491 ha->ccb_phys = 0L;
4493 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4494 &scratch_dma_handle);
4495 ha->scratch_phys = scratch_dma_handle;
4496 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4497 &scratch_dma_handle);
4498 ha->msg_phys = scratch_dma_handle;
4499 #ifdef INT_COAL
4500 ha->coal_stat = (gdth_coal_status *)
4501 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4502 MAXOFFSETS, &scratch_dma_handle);
4503 ha->coal_stat_phys = scratch_dma_handle;
4504 #endif
4505 ha->scratch_busy = FALSE;
4506 ha->req_first = NULL;
4507 ha->tid_cnt = pcistr[ctr].device_id >= 0x200 ? MAXID : MAX_HDRIVES;
4508 if (max_ids > 0 && max_ids < ha->tid_cnt)
4509 ha->tid_cnt = max_ids;
4510 for (i=0; i<GDTH_MAXCMDS; ++i)
4511 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4512 ha->scan_mode = rescan ? 0x10 : 0;
4514 err = FALSE;
4515 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4516 !gdth_search_drives(hanum)) {
4517 err = TRUE;
4518 } else {
4519 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4520 hdr_channel = ha->bus_cnt;
4521 ha->virt_bus = hdr_channel;
4524 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4525 scsi_set_device(shp, &pcistr[ctr].pdev->dev);
4526 #else
4527 scsi_set_pci_device(shp, pcistr[ctr].pdev);
4528 #endif
4529 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat &GDT_64BIT)||
4530 /* 64-bit DMA only supported from FW >= x.43 */
4531 (!ha->dma64_support)) {
4532 if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) {
4533 printk(KERN_WARNING "GDT-PCI %d: Unable to set 32-bit DMA\n", hanum);
4534 err = TRUE;
4536 } else {
4537 shp->max_cmd_len = 16;
4538 if (!pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffffffffffffULL)) {
4539 printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);
4540 } else if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) {
4541 printk(KERN_WARNING "GDT-PCI %d: Unable to set 64/32-bit DMA\n", hanum);
4542 err = TRUE;
4547 if (err) {
4548 printk("GDT-PCI %d: Error during device scan\n", hanum);
4549 --gdth_ctr_count;
4550 --gdth_ctr_vcount;
4551 #ifdef INT_COAL
4552 if (ha->coal_stat)
4553 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4554 MAXOFFSETS, ha->coal_stat,
4555 ha->coal_stat_phys);
4556 #endif
4557 if (ha->pscratch)
4558 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4559 ha->pscratch, ha->scratch_phys);
4560 if (ha->pmsg)
4561 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4562 ha->pmsg, ha->msg_phys);
4563 free_irq(ha->irq,ha);
4564 scsi_unregister(shp);
4565 continue;
4568 shp->max_id = ha->tid_cnt;
4569 shp->max_lun = MAXLUN;
4570 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4571 if (virt_ctr) {
4572 virt_ctr = 1;
4573 /* register addit. SCSI channels as virtual controllers */
4574 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4575 shp = scsi_register(shtp,sizeof(gdth_num_str));
4576 shp->unchecked_isa_dma = 0;
4577 shp->irq = ha->irq;
4578 shp->dma_channel = 0xff;
4579 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4580 NUMDATA(shp)->hanum = (ushort)hanum;
4581 NUMDATA(shp)->busnum = b;
4585 spin_lock_init(&ha->smp_lock);
4586 gdth_enable_int(hanum);
4589 TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count));
4590 if (gdth_ctr_count > 0) {
4591 #ifdef GDTH_STATISTICS
4592 TRACE2(("gdth_detect(): Initializing timer !\n"));
4593 init_timer(&gdth_timer);
4594 gdth_timer.expires = jiffies + HZ;
4595 gdth_timer.data = 0L;
4596 gdth_timer.function = gdth_timeout;
4597 add_timer(&gdth_timer);
4598 #endif
4599 major = register_chrdev(0,"gdth",&gdth_fops);
4600 register_reboot_notifier(&gdth_notifier);
4602 gdth_polling = FALSE;
4603 return gdth_ctr_vcount;
4607 static int gdth_release(struct Scsi_Host *shp)
4609 int hanum;
4610 gdth_ha_str *ha;
4612 TRACE2(("gdth_release()\n"));
4613 if (NUMDATA(shp)->busnum == 0) {
4614 hanum = NUMDATA(shp)->hanum;
4615 ha = HADATA(gdth_ctr_tab[hanum]);
4616 if (ha->sdev) {
4617 scsi_free_host_dev(ha->sdev);
4618 ha->sdev = NULL;
4620 gdth_flush(hanum);
4622 if (shp->irq) {
4623 free_irq(shp->irq,ha);
4625 #ifndef __ia64__
4626 if (shp->dma_channel != 0xff) {
4627 free_dma(shp->dma_channel);
4629 #endif
4630 #ifdef INT_COAL
4631 if (ha->coal_stat)
4632 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4633 MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys);
4634 #endif
4635 if (ha->pscratch)
4636 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4637 ha->pscratch, ha->scratch_phys);
4638 if (ha->pmsg)
4639 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4640 ha->pmsg, ha->msg_phys);
4641 if (ha->ccb_phys)
4642 pci_unmap_single(ha->pdev,ha->ccb_phys,
4643 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
4644 gdth_ctr_released++;
4645 TRACE2(("gdth_release(): HA %d of %d\n",
4646 gdth_ctr_released, gdth_ctr_count));
4648 if (gdth_ctr_released == gdth_ctr_count) {
4649 #ifdef GDTH_STATISTICS
4650 del_timer(&gdth_timer);
4651 #endif
4652 unregister_chrdev(major,"gdth");
4653 unregister_reboot_notifier(&gdth_notifier);
4657 scsi_unregister(shp);
4658 return 0;
4662 static const char *gdth_ctr_name(int hanum)
4664 gdth_ha_str *ha;
4666 TRACE2(("gdth_ctr_name()\n"));
4668 ha = HADATA(gdth_ctr_tab[hanum]);
4670 if (ha->type == GDT_EISA) {
4671 switch (ha->stype) {
4672 case GDT3_ID:
4673 return("GDT3000/3020");
4674 case GDT3A_ID:
4675 return("GDT3000A/3020A/3050A");
4676 case GDT3B_ID:
4677 return("GDT3000B/3010A");
4679 } else if (ha->type == GDT_ISA) {
4680 return("GDT2000/2020");
4681 } else if (ha->type == GDT_PCI) {
4682 switch (ha->stype) {
4683 case PCI_DEVICE_ID_VORTEX_GDT60x0:
4684 return("GDT6000/6020/6050");
4685 case PCI_DEVICE_ID_VORTEX_GDT6000B:
4686 return("GDT6000B/6010");
4689 /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
4691 return("");
4694 static const char *gdth_info(struct Scsi_Host *shp)
4696 int hanum;
4697 gdth_ha_str *ha;
4699 TRACE2(("gdth_info()\n"));
4700 hanum = NUMDATA(shp)->hanum;
4701 ha = HADATA(gdth_ctr_tab[hanum]);
4703 return ((const char *)ha->binfo.type_string);
4706 /* new error handling */
4707 static int gdth_eh_abort(Scsi_Cmnd *scp)
4709 TRACE2(("gdth_eh_abort()\n"));
4710 return FAILED;
4713 static int gdth_eh_device_reset(Scsi_Cmnd *scp)
4715 TRACE2(("gdth_eh_device_reset()\n"));
4716 return FAILED;
4719 static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
4721 int i, hanum;
4722 gdth_ha_str *ha;
4723 ulong flags;
4724 Scsi_Cmnd *cmnd;
4725 unchar b;
4727 TRACE2(("gdth_eh_bus_reset()\n"));
4729 hanum = NUMDATA(scp->device->host)->hanum;
4730 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
4731 ha = HADATA(gdth_ctr_tab[hanum]);
4733 /* clear command tab */
4734 spin_lock_irqsave(&ha->smp_lock, flags);
4735 for (i = 0; i < GDTH_MAXCMDS; ++i) {
4736 cmnd = ha->cmd_tab[i].cmnd;
4737 if (!SPECIAL_SCP(cmnd) && cmnd->device->channel == b)
4738 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4740 spin_unlock_irqrestore(&ha->smp_lock, flags);
4742 if (b == ha->virt_bus) {
4743 /* host drives */
4744 for (i = 0; i < MAX_HDRIVES; ++i) {
4745 if (ha->hdr[i].present) {
4746 spin_lock_irqsave(&ha->smp_lock, flags);
4747 gdth_polling = TRUE;
4748 while (gdth_test_busy(hanum))
4749 gdth_delay(0);
4750 if (gdth_internal_cmd(hanum, CACHESERVICE,
4751 GDT_CLUST_RESET, i, 0, 0))
4752 ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED;
4753 gdth_polling = FALSE;
4754 spin_unlock_irqrestore(&ha->smp_lock, flags);
4757 } else {
4758 /* raw devices */
4759 spin_lock_irqsave(&ha->smp_lock, flags);
4760 for (i = 0; i < MAXID; ++i)
4761 ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0;
4762 gdth_polling = TRUE;
4763 while (gdth_test_busy(hanum))
4764 gdth_delay(0);
4765 gdth_internal_cmd(hanum, SCSIRAWSERVICE, GDT_RESET_BUS,
4766 BUS_L2P(ha,b), 0, 0);
4767 gdth_polling = FALSE;
4768 spin_unlock_irqrestore(&ha->smp_lock, flags);
4770 return SUCCESS;
4773 static int gdth_eh_host_reset(Scsi_Cmnd *scp)
4775 TRACE2(("gdth_eh_host_reset()\n"));
4776 return FAILED;
4780 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4781 static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip)
4782 #else
4783 static int gdth_bios_param(Disk *disk,kdev_t dev,int *ip)
4784 #endif
4786 unchar b, t;
4787 int hanum;
4788 gdth_ha_str *ha;
4789 struct scsi_device *sd;
4790 unsigned capacity;
4792 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4793 sd = sdev;
4794 capacity = cap;
4795 #else
4796 sd = disk->device;
4797 capacity = disk->capacity;
4798 #endif
4799 hanum = NUMDATA(sd->host)->hanum;
4800 b = virt_ctr ? NUMDATA(sd->host)->busnum : sd->channel;
4801 t = sd->id;
4802 TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", hanum, b, t));
4803 ha = HADATA(gdth_ctr_tab[hanum]);
4805 if (b != ha->virt_bus || ha->hdr[t].heads == 0) {
4806 /* raw device or host drive without mapping information */
4807 TRACE2(("Evaluate mapping\n"));
4808 gdth_eval_mapping(capacity,&ip[2],&ip[0],&ip[1]);
4809 } else {
4810 ip[0] = ha->hdr[t].heads;
4811 ip[1] = ha->hdr[t].secs;
4812 ip[2] = capacity / ip[0] / ip[1];
4815 TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
4816 ip[0],ip[1],ip[2]));
4817 return 0;
4821 static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *))
4823 int hanum;
4824 int priority;
4826 TRACE(("gdth_queuecommand() cmd 0x%x\n", scp->cmnd[0]));
4828 scp->scsi_done = (void *)done;
4829 scp->SCp.have_data_in = 1;
4830 scp->SCp.phase = -1;
4831 scp->SCp.sent_command = -1;
4832 scp->SCp.Status = GDTH_MAP_NONE;
4833 scp->SCp.buffer = (struct scatterlist *)NULL;
4835 hanum = NUMDATA(scp->device->host)->hanum;
4836 #ifdef GDTH_STATISTICS
4837 ++act_ios;
4838 #endif
4840 priority = DEFAULT_PRI;
4841 if (scp->done == gdth_scsi_done)
4842 priority = scp->SCp.this_residual;
4843 gdth_update_timeout(hanum, scp, scp->timeout_per_command * 6);
4844 gdth_putq( hanum, scp, priority );
4845 gdth_next( hanum );
4846 return 0;
4850 static int gdth_open(struct inode *inode, struct file *filep)
4852 gdth_ha_str *ha;
4853 int i;
4855 for (i = 0; i < gdth_ctr_count; i++) {
4856 ha = HADATA(gdth_ctr_tab[i]);
4857 if (!ha->sdev)
4858 ha->sdev = scsi_get_host_dev(gdth_ctr_tab[i]);
4861 TRACE(("gdth_open()\n"));
4862 return 0;
4865 static int gdth_close(struct inode *inode, struct file *filep)
4867 TRACE(("gdth_close()\n"));
4868 return 0;
4871 static int ioc_event(void __user *arg)
4873 gdth_ioctl_event evt;
4874 gdth_ha_str *ha;
4875 ulong flags;
4877 if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event)) ||
4878 evt.ionode >= gdth_ctr_count)
4879 return -EFAULT;
4880 ha = HADATA(gdth_ctr_tab[evt.ionode]);
4882 if (evt.erase == 0xff) {
4883 if (evt.event.event_source == ES_TEST)
4884 evt.event.event_data.size=sizeof(evt.event.event_data.eu.test);
4885 else if (evt.event.event_source == ES_DRIVER)
4886 evt.event.event_data.size=sizeof(evt.event.event_data.eu.driver);
4887 else if (evt.event.event_source == ES_SYNC)
4888 evt.event.event_data.size=sizeof(evt.event.event_data.eu.sync);
4889 else
4890 evt.event.event_data.size=sizeof(evt.event.event_data.eu.async);
4891 spin_lock_irqsave(&ha->smp_lock, flags);
4892 gdth_store_event(ha, evt.event.event_source, evt.event.event_idx,
4893 &evt.event.event_data);
4894 spin_unlock_irqrestore(&ha->smp_lock, flags);
4895 } else if (evt.erase == 0xfe) {
4896 gdth_clear_events();
4897 } else if (evt.erase == 0) {
4898 evt.handle = gdth_read_event(ha, evt.handle, &evt.event);
4899 } else {
4900 gdth_readapp_event(ha, evt.erase, &evt.event);
4902 if (copy_to_user(arg, &evt, sizeof(gdth_ioctl_event)))
4903 return -EFAULT;
4904 return 0;
4907 static int ioc_lockdrv(void __user *arg)
4909 gdth_ioctl_lockdrv ldrv;
4910 unchar i, j;
4911 ulong flags;
4912 gdth_ha_str *ha;
4914 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)) ||
4915 ldrv.ionode >= gdth_ctr_count)
4916 return -EFAULT;
4917 ha = HADATA(gdth_ctr_tab[ldrv.ionode]);
4919 for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) {
4920 j = ldrv.drives[i];
4921 if (j >= MAX_HDRIVES || !ha->hdr[j].present)
4922 continue;
4923 if (ldrv.lock) {
4924 spin_lock_irqsave(&ha->smp_lock, flags);
4925 ha->hdr[j].lock = 1;
4926 spin_unlock_irqrestore(&ha->smp_lock, flags);
4927 gdth_wait_completion(ldrv.ionode, ha->bus_cnt, j);
4928 gdth_stop_timeout(ldrv.ionode, ha->bus_cnt, j);
4929 } else {
4930 spin_lock_irqsave(&ha->smp_lock, flags);
4931 ha->hdr[j].lock = 0;
4932 spin_unlock_irqrestore(&ha->smp_lock, flags);
4933 gdth_start_timeout(ldrv.ionode, ha->bus_cnt, j);
4934 gdth_next(ldrv.ionode);
4937 return 0;
4940 static int ioc_resetdrv(void __user *arg, char *cmnd)
4942 gdth_ioctl_reset res;
4943 gdth_cmd_str cmd;
4944 int hanum;
4945 gdth_ha_str *ha;
4946 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4947 Scsi_Request *srp;
4948 #else
4949 Scsi_Cmnd *scp;
4950 #endif
4952 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
4953 res.ionode >= gdth_ctr_count || res.number >= MAX_HDRIVES)
4954 return -EFAULT;
4955 hanum = res.ionode;
4956 ha = HADATA(gdth_ctr_tab[hanum]);
4958 if (!ha->hdr[res.number].present)
4959 return 0;
4960 memset(&cmd, 0, sizeof(gdth_cmd_str));
4961 cmd.Service = CACHESERVICE;
4962 cmd.OpCode = GDT_CLUST_RESET;
4963 if (ha->cache_feat & GDT_64BIT)
4964 cmd.u.cache64.DeviceNo = res.number;
4965 else
4966 cmd.u.cache.DeviceNo = res.number;
4967 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4968 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
4969 if (!srp)
4970 return -ENOMEM;
4971 srp->sr_cmd_len = 12;
4972 srp->sr_use_sg = 0;
4973 gdth_do_req(srp, &cmd, cmnd, 30);
4974 res.status = (ushort)srp->sr_command->SCp.Status;
4975 scsi_release_request(srp);
4976 #else
4977 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
4978 if (!scp)
4979 return -ENOMEM;
4980 scp->cmd_len = 12;
4981 scp->use_sg = 0;
4982 gdth_do_cmd(scp, &cmd, cmnd, 30);
4983 res.status = (ushort)scp->SCp.Status;
4984 scsi_release_command(scp);
4985 #endif
4987 if (copy_to_user(arg, &res, sizeof(gdth_ioctl_reset)))
4988 return -EFAULT;
4989 return 0;
4992 static int ioc_general(void __user *arg, char *cmnd)
4994 gdth_ioctl_general gen;
4995 char *buf = NULL;
4996 ulong64 paddr;
4997 int hanum;
4998 gdth_ha_str *ha;
4999 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5000 Scsi_Request *srp;
5001 #else
5002 Scsi_Cmnd *scp;
5003 #endif
5005 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)) ||
5006 gen.ionode >= gdth_ctr_count)
5007 return -EFAULT;
5008 hanum = gen.ionode;
5009 ha = HADATA(gdth_ctr_tab[hanum]);
5010 if (gen.data_len + gen.sense_len != 0) {
5011 if (!(buf = gdth_ioctl_alloc(hanum, gen.data_len + gen.sense_len,
5012 FALSE, &paddr)))
5013 return -EFAULT;
5014 if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general),
5015 gen.data_len + gen.sense_len)) {
5016 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5017 return -EFAULT;
5020 if (gen.command.OpCode == GDT_IOCTL) {
5021 gen.command.u.ioctl.p_param = paddr;
5022 } else if (gen.command.Service == CACHESERVICE) {
5023 if (ha->cache_feat & GDT_64BIT) {
5024 /* copy elements from 32-bit IOCTL structure */
5025 gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt;
5026 gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo;
5027 gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo;
5028 /* addresses */
5029 if (ha->cache_feat & SCATTER_GATHER) {
5030 gen.command.u.cache64.DestAddr = (ulong64)-1;
5031 gen.command.u.cache64.sg_canz = 1;
5032 gen.command.u.cache64.sg_lst[0].sg_ptr = paddr;
5033 gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len;
5034 gen.command.u.cache64.sg_lst[1].sg_len = 0;
5035 } else {
5036 gen.command.u.cache64.DestAddr = paddr;
5037 gen.command.u.cache64.sg_canz = 0;
5039 } else {
5040 if (ha->cache_feat & SCATTER_GATHER) {
5041 gen.command.u.cache.DestAddr = 0xffffffff;
5042 gen.command.u.cache.sg_canz = 1;
5043 gen.command.u.cache.sg_lst[0].sg_ptr = (ulong32)paddr;
5044 gen.command.u.cache.sg_lst[0].sg_len = gen.data_len;
5045 gen.command.u.cache.sg_lst[1].sg_len = 0;
5046 } else {
5047 gen.command.u.cache.DestAddr = paddr;
5048 gen.command.u.cache.sg_canz = 0;
5051 } else if (gen.command.Service == SCSIRAWSERVICE) {
5052 if (ha->raw_feat & GDT_64BIT) {
5053 /* copy elements from 32-bit IOCTL structure */
5054 char cmd[16];
5055 gen.command.u.raw64.sense_len = gen.command.u.raw.sense_len;
5056 gen.command.u.raw64.bus = gen.command.u.raw.bus;
5057 gen.command.u.raw64.lun = gen.command.u.raw.lun;
5058 gen.command.u.raw64.target = gen.command.u.raw.target;
5059 memcpy(cmd, gen.command.u.raw.cmd, 16);
5060 memcpy(gen.command.u.raw64.cmd, cmd, 16);
5061 gen.command.u.raw64.clen = gen.command.u.raw.clen;
5062 gen.command.u.raw64.sdlen = gen.command.u.raw.sdlen;
5063 gen.command.u.raw64.direction = gen.command.u.raw.direction;
5064 /* addresses */
5065 if (ha->raw_feat & SCATTER_GATHER) {
5066 gen.command.u.raw64.sdata = (ulong64)-1;
5067 gen.command.u.raw64.sg_ranz = 1;
5068 gen.command.u.raw64.sg_lst[0].sg_ptr = paddr;
5069 gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len;
5070 gen.command.u.raw64.sg_lst[1].sg_len = 0;
5071 } else {
5072 gen.command.u.raw64.sdata = paddr;
5073 gen.command.u.raw64.sg_ranz = 0;
5075 gen.command.u.raw64.sense_data = paddr + gen.data_len;
5076 } else {
5077 if (ha->raw_feat & SCATTER_GATHER) {
5078 gen.command.u.raw.sdata = 0xffffffff;
5079 gen.command.u.raw.sg_ranz = 1;
5080 gen.command.u.raw.sg_lst[0].sg_ptr = (ulong32)paddr;
5081 gen.command.u.raw.sg_lst[0].sg_len = gen.data_len;
5082 gen.command.u.raw.sg_lst[1].sg_len = 0;
5083 } else {
5084 gen.command.u.raw.sdata = paddr;
5085 gen.command.u.raw.sg_ranz = 0;
5087 gen.command.u.raw.sense_data = (ulong32)paddr + gen.data_len;
5089 } else {
5090 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5091 return -EFAULT;
5095 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5096 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5097 if (!srp)
5098 return -ENOMEM;
5099 srp->sr_cmd_len = 12;
5100 srp->sr_use_sg = 0;
5101 gdth_do_req(srp, &gen.command, cmnd, gen.timeout);
5102 gen.status = srp->sr_command->SCp.Status;
5103 gen.info = srp->sr_command->SCp.Message;
5104 scsi_release_request(srp);
5105 #else
5106 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5107 if (!scp)
5108 return -ENOMEM;
5109 scp->cmd_len = 12;
5110 scp->use_sg = 0;
5111 gdth_do_cmd(scp, &gen.command, cmnd, gen.timeout);
5112 gen.status = scp->SCp.Status;
5113 gen.info = scp->SCp.Message;
5114 scsi_release_command(scp);
5115 #endif
5117 if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf,
5118 gen.data_len + gen.sense_len)) {
5119 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5120 return -EFAULT;
5122 if (copy_to_user(arg, &gen,
5123 sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) {
5124 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5125 return -EFAULT;
5127 gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
5128 return 0;
5131 static int ioc_hdrlist(void __user *arg, char *cmnd)
5133 gdth_ioctl_rescan *rsc;
5134 gdth_cmd_str *cmd;
5135 gdth_ha_str *ha;
5136 unchar i;
5137 int hanum, rc = -ENOMEM;
5138 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5139 Scsi_Request *srp;
5140 #else
5141 Scsi_Cmnd *scp;
5142 #endif
5144 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
5145 cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
5146 if (!rsc || !cmd)
5147 goto free_fail;
5149 if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
5150 rsc->ionode >= gdth_ctr_count) {
5151 rc = -EFAULT;
5152 goto free_fail;
5154 hanum = rsc->ionode;
5155 ha = HADATA(gdth_ctr_tab[hanum]);
5156 memset(cmd, 0, sizeof(gdth_cmd_str));
5158 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5159 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5160 if (!srp)
5161 goto free_fail;
5162 srp->sr_cmd_len = 12;
5163 srp->sr_use_sg = 0;
5164 #else
5165 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5166 if (!scp)
5167 goto free_fail;
5168 scp->cmd_len = 12;
5169 scp->use_sg = 0;
5170 #endif
5172 for (i = 0; i < MAX_HDRIVES; ++i) {
5173 if (!ha->hdr[i].present) {
5174 rsc->hdr_list[i].bus = 0xff;
5175 continue;
5177 rsc->hdr_list[i].bus = ha->virt_bus;
5178 rsc->hdr_list[i].target = i;
5179 rsc->hdr_list[i].lun = 0;
5180 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
5181 if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) {
5182 cmd->Service = CACHESERVICE;
5183 cmd->OpCode = GDT_CLUST_INFO;
5184 if (ha->cache_feat & GDT_64BIT)
5185 cmd->u.cache64.DeviceNo = i;
5186 else
5187 cmd->u.cache.DeviceNo = i;
5188 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5189 gdth_do_req(srp, cmd, cmnd, 30);
5190 if (srp->sr_command->SCp.Status == S_OK)
5191 rsc->hdr_list[i].cluster_type = srp->sr_command->SCp.Message;
5192 #else
5193 gdth_do_cmd(scp, cmd, cmnd, 30);
5194 if (scp->SCp.Status == S_OK)
5195 rsc->hdr_list[i].cluster_type = scp->SCp.Message;
5196 #endif
5199 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5200 scsi_release_request(srp);
5201 #else
5202 scsi_release_command(scp);
5203 #endif
5205 if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
5206 rc = -EFAULT;
5207 else
5208 rc = 0;
5210 free_fail:
5211 kfree(rsc);
5212 kfree(cmd);
5213 return rc;
5216 static int ioc_rescan(void __user *arg, char *cmnd)
5218 gdth_ioctl_rescan *rsc;
5219 gdth_cmd_str *cmd;
5220 ushort i, status, hdr_cnt;
5221 ulong32 info;
5222 int hanum, cyls, hds, secs;
5223 int rc = -ENOMEM;
5224 ulong flags;
5225 gdth_ha_str *ha;
5226 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5227 Scsi_Request *srp;
5228 #else
5229 Scsi_Cmnd *scp;
5230 #endif
5232 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
5233 cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
5234 if (!cmd || !rsc)
5235 goto free_fail;
5237 if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
5238 rsc->ionode >= gdth_ctr_count) {
5239 rc = -EFAULT;
5240 goto free_fail;
5242 hanum = rsc->ionode;
5243 ha = HADATA(gdth_ctr_tab[hanum]);
5244 memset(cmd, 0, sizeof(gdth_cmd_str));
5246 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5247 srp = scsi_allocate_request(ha->sdev, GFP_KERNEL);
5248 if (!srp)
5249 goto free_fail;
5250 srp->sr_cmd_len = 12;
5251 srp->sr_use_sg = 0;
5252 #else
5253 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5254 if (!scp)
5255 goto free_fail;
5256 scp->cmd_len = 12;
5257 scp->use_sg = 0;
5258 #endif
5260 if (rsc->flag == 0) {
5261 /* old method: re-init. cache service */
5262 cmd->Service = CACHESERVICE;
5263 if (ha->cache_feat & GDT_64BIT) {
5264 cmd->OpCode = GDT_X_INIT_HOST;
5265 cmd->u.cache64.DeviceNo = LINUX_OS;
5266 } else {
5267 cmd->OpCode = GDT_INIT;
5268 cmd->u.cache.DeviceNo = LINUX_OS;
5270 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5271 gdth_do_req(srp, cmd, cmnd, 30);
5272 status = (ushort)srp->sr_command->SCp.Status;
5273 info = (ulong32)srp->sr_command->SCp.Message;
5274 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5275 gdth_do_cmd(scp, cmd, cmnd, 30);
5276 status = (ushort)scp->SCp.Status;
5277 info = (ulong32)scp->SCp.Message;
5278 #else
5279 gdth_do_cmd(&scp, cmd, cmnd, 30);
5280 status = (ushort)scp.SCp.Status;
5281 info = (ulong32)scp.SCp.Message;
5282 #endif
5283 i = 0;
5284 hdr_cnt = (status == S_OK ? (ushort)info : 0);
5285 } else {
5286 i = rsc->hdr_no;
5287 hdr_cnt = i + 1;
5290 for (; i < hdr_cnt && i < MAX_HDRIVES; ++i) {
5291 cmd->Service = CACHESERVICE;
5292 cmd->OpCode = GDT_INFO;
5293 if (ha->cache_feat & GDT_64BIT)
5294 cmd->u.cache64.DeviceNo = i;
5295 else
5296 cmd->u.cache.DeviceNo = i;
5297 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5298 gdth_do_req(srp, cmd, cmnd, 30);
5299 status = (ushort)srp->sr_command->SCp.Status;
5300 info = (ulong32)srp->sr_command->SCp.Message;
5301 #else
5302 gdth_do_cmd(scp, cmd, cmnd, 30);
5303 status = (ushort)scp->SCp.Status;
5304 info = (ulong32)scp->SCp.Message;
5305 #endif
5306 spin_lock_irqsave(&ha->smp_lock, flags);
5307 rsc->hdr_list[i].bus = ha->virt_bus;
5308 rsc->hdr_list[i].target = i;
5309 rsc->hdr_list[i].lun = 0;
5310 if (status != S_OK) {
5311 ha->hdr[i].present = FALSE;
5312 } else {
5313 ha->hdr[i].present = TRUE;
5314 ha->hdr[i].size = info;
5315 /* evaluate mapping */
5316 ha->hdr[i].size &= ~SECS32;
5317 gdth_eval_mapping(ha->hdr[i].size,&cyls,&hds,&secs);
5318 ha->hdr[i].heads = hds;
5319 ha->hdr[i].secs = secs;
5320 /* round size */
5321 ha->hdr[i].size = cyls * hds * secs;
5323 spin_unlock_irqrestore(&ha->smp_lock, flags);
5324 if (status != S_OK)
5325 continue;
5327 /* extended info, if GDT_64BIT, for drives > 2 TB */
5328 /* but we need ha->info2, not yet stored in scp->SCp */
5330 /* devtype, cluster info, R/W attribs */
5331 cmd->Service = CACHESERVICE;
5332 cmd->OpCode = GDT_DEVTYPE;
5333 if (ha->cache_feat & GDT_64BIT)
5334 cmd->u.cache64.DeviceNo = i;
5335 else
5336 cmd->u.cache.DeviceNo = i;
5337 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5338 gdth_do_req(srp, cmd, cmnd, 30);
5339 status = (ushort)srp->sr_command->SCp.Status;
5340 info = (ulong32)srp->sr_command->SCp.Message;
5341 #else
5342 gdth_do_cmd(scp, cmd, cmnd, 30);
5343 status = (ushort)scp->SCp.Status;
5344 info = (ulong32)scp->SCp.Message;
5345 #endif
5346 spin_lock_irqsave(&ha->smp_lock, flags);
5347 ha->hdr[i].devtype = (status == S_OK ? (ushort)info : 0);
5348 spin_unlock_irqrestore(&ha->smp_lock, flags);
5350 cmd->Service = CACHESERVICE;
5351 cmd->OpCode = GDT_CLUST_INFO;
5352 if (ha->cache_feat & GDT_64BIT)
5353 cmd->u.cache64.DeviceNo = i;
5354 else
5355 cmd->u.cache.DeviceNo = i;
5356 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5357 gdth_do_req(srp, cmd, cmnd, 30);
5358 status = (ushort)srp->sr_command->SCp.Status;
5359 info = (ulong32)srp->sr_command->SCp.Message;
5360 #else
5361 gdth_do_cmd(scp, cmd, cmnd, 30);
5362 status = (ushort)scp->SCp.Status;
5363 info = (ulong32)scp->SCp.Message;
5364 #endif
5365 spin_lock_irqsave(&ha->smp_lock, flags);
5366 ha->hdr[i].cluster_type =
5367 ((status == S_OK && !shared_access) ? (ushort)info : 0);
5368 spin_unlock_irqrestore(&ha->smp_lock, flags);
5369 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
5371 cmd->Service = CACHESERVICE;
5372 cmd->OpCode = GDT_RW_ATTRIBS;
5373 if (ha->cache_feat & GDT_64BIT)
5374 cmd->u.cache64.DeviceNo = i;
5375 else
5376 cmd->u.cache.DeviceNo = i;
5377 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5378 gdth_do_req(srp, cmd, cmnd, 30);
5379 status = (ushort)srp->sr_command->SCp.Status;
5380 info = (ulong32)srp->sr_command->SCp.Message;
5381 #else
5382 gdth_do_cmd(scp, cmd, cmnd, 30);
5383 status = (ushort)scp->SCp.Status;
5384 info = (ulong32)scp->SCp.Message;
5385 #endif
5386 spin_lock_irqsave(&ha->smp_lock, flags);
5387 ha->hdr[i].rw_attribs = (status == S_OK ? (ushort)info : 0);
5388 spin_unlock_irqrestore(&ha->smp_lock, flags);
5390 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5391 scsi_release_request(srp);
5392 #else
5393 scsi_release_command(scp);
5394 #endif
5396 if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
5397 rc = -EFAULT;
5398 else
5399 rc = 0;
5401 free_fail:
5402 kfree(rsc);
5403 kfree(cmd);
5404 return rc;
5407 static int gdth_ioctl(struct inode *inode, struct file *filep,
5408 unsigned int cmd, unsigned long arg)
5410 gdth_ha_str *ha;
5411 Scsi_Cmnd *scp;
5412 ulong flags;
5413 char cmnd[MAX_COMMAND_SIZE];
5414 void __user *argp = (void __user *)arg;
5416 memset(cmnd, 0xff, 12);
5418 TRACE(("gdth_ioctl() cmd 0x%x\n", cmd));
5420 switch (cmd) {
5421 case GDTIOCTL_CTRCNT:
5423 int cnt = gdth_ctr_count;
5424 if (put_user(cnt, (int __user *)argp))
5425 return -EFAULT;
5426 break;
5429 case GDTIOCTL_DRVERS:
5431 int ver = (GDTH_VERSION<<8) | GDTH_SUBVERSION;
5432 if (put_user(ver, (int __user *)argp))
5433 return -EFAULT;
5434 break;
5437 case GDTIOCTL_OSVERS:
5439 gdth_ioctl_osvers osv;
5441 osv.version = (unchar)(LINUX_VERSION_CODE >> 16);
5442 osv.subversion = (unchar)(LINUX_VERSION_CODE >> 8);
5443 osv.revision = (ushort)(LINUX_VERSION_CODE & 0xff);
5444 if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers)))
5445 return -EFAULT;
5446 break;
5449 case GDTIOCTL_CTRTYPE:
5451 gdth_ioctl_ctrtype ctrt;
5453 if (copy_from_user(&ctrt, argp, sizeof(gdth_ioctl_ctrtype)) ||
5454 ctrt.ionode >= gdth_ctr_count)
5455 return -EFAULT;
5456 ha = HADATA(gdth_ctr_tab[ctrt.ionode]);
5457 if (ha->type == GDT_ISA || ha->type == GDT_EISA) {
5458 ctrt.type = (unchar)((ha->stype>>20) - 0x10);
5459 } else {
5460 if (ha->type != GDT_PCIMPR) {
5461 ctrt.type = (unchar)((ha->stype<<4) + 6);
5462 } else {
5463 ctrt.type =
5464 (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe);
5465 if (ha->stype >= 0x300)
5466 ctrt.ext_type = 0x6000 | ha->subdevice_id;
5467 else
5468 ctrt.ext_type = 0x6000 | ha->stype;
5470 ctrt.device_id = ha->stype;
5471 ctrt.sub_device_id = ha->subdevice_id;
5473 ctrt.info = ha->brd_phys;
5474 ctrt.oem_id = ha->oem_id;
5475 if (copy_to_user(argp, &ctrt, sizeof(gdth_ioctl_ctrtype)))
5476 return -EFAULT;
5477 break;
5480 case GDTIOCTL_GENERAL:
5481 return ioc_general(argp, cmnd);
5483 case GDTIOCTL_EVENT:
5484 return ioc_event(argp);
5486 case GDTIOCTL_LOCKDRV:
5487 return ioc_lockdrv(argp);
5489 case GDTIOCTL_LOCKCHN:
5491 gdth_ioctl_lockchn lchn;
5492 unchar i, j;
5494 if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) ||
5495 lchn.ionode >= gdth_ctr_count)
5496 return -EFAULT;
5497 ha = HADATA(gdth_ctr_tab[lchn.ionode]);
5499 i = lchn.channel;
5500 if (i < ha->bus_cnt) {
5501 if (lchn.lock) {
5502 spin_lock_irqsave(&ha->smp_lock, flags);
5503 ha->raw[i].lock = 1;
5504 spin_unlock_irqrestore(&ha->smp_lock, flags);
5505 for (j = 0; j < ha->tid_cnt; ++j) {
5506 gdth_wait_completion(lchn.ionode, i, j);
5507 gdth_stop_timeout(lchn.ionode, i, j);
5509 } else {
5510 spin_lock_irqsave(&ha->smp_lock, flags);
5511 ha->raw[i].lock = 0;
5512 spin_unlock_irqrestore(&ha->smp_lock, flags);
5513 for (j = 0; j < ha->tid_cnt; ++j) {
5514 gdth_start_timeout(lchn.ionode, i, j);
5515 gdth_next(lchn.ionode);
5519 break;
5522 case GDTIOCTL_RESCAN:
5523 return ioc_rescan(argp, cmnd);
5525 case GDTIOCTL_HDRLIST:
5526 return ioc_hdrlist(argp, cmnd);
5528 case GDTIOCTL_RESET_BUS:
5530 gdth_ioctl_reset res;
5531 int hanum, rval;
5533 if (copy_from_user(&res, argp, sizeof(gdth_ioctl_reset)) ||
5534 res.ionode >= gdth_ctr_count)
5535 return -EFAULT;
5536 hanum = res.ionode;
5537 ha = HADATA(gdth_ctr_tab[hanum]);
5539 /* Because we need a Scsi_Cmnd struct., we make a scsi_allocate device also for kernels >=2.6.x */
5540 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5541 scp = scsi_get_command(ha->sdev, GFP_KERNEL);
5542 if (!scp)
5543 return -ENOMEM;
5544 scp->cmd_len = 12;
5545 scp->use_sg = 0;
5546 scp->device->channel = virt_ctr ? 0 : res.number;
5547 rval = gdth_eh_bus_reset(scp);
5548 res.status = (rval == SUCCESS ? S_OK : S_GENERR);
5549 scsi_put_command(scp);
5550 #else
5551 scp = scsi_allocate_device(ha->sdev, 1, FALSE);
5552 if (!scp)
5553 return -ENOMEM;
5554 scp->cmd_len = 12;
5555 scp->use_sg = 0;
5556 scp->channel = virt_ctr ? 0 : res.number;
5557 rval = gdth_eh_bus_reset(scp);
5558 res.status = (rval == SUCCESS ? S_OK : S_GENERR);
5559 scsi_release_command(scp);
5560 #endif
5561 if (copy_to_user(argp, &res, sizeof(gdth_ioctl_reset)))
5562 return -EFAULT;
5563 break;
5566 case GDTIOCTL_RESET_DRV:
5567 return ioc_resetdrv(argp, cmnd);
5569 default:
5570 break;
5572 return 0;
5576 /* flush routine */
5577 static void gdth_flush(int hanum)
5579 int i;
5580 gdth_ha_str *ha;
5581 gdth_cmd_str gdtcmd;
5582 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5583 Scsi_Request *srp;
5584 #else
5585 Scsi_Cmnd *scp;
5586 #endif
5587 Scsi_Device *sdev;
5588 char cmnd[MAX_COMMAND_SIZE];
5589 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
5591 TRACE2(("gdth_flush() hanum %d\n",hanum));
5592 ha = HADATA(gdth_ctr_tab[hanum]);
5594 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5595 sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
5596 srp = scsi_allocate_request(sdev, GFP_KERNEL);
5597 if (!srp)
5598 return;
5599 srp->sr_cmd_len = 12;
5600 srp->sr_use_sg = 0;
5601 #else
5602 sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
5603 scp = scsi_allocate_device(sdev, 1, FALSE);
5604 if (!scp)
5605 return;
5606 scp->cmd_len = 12;
5607 scp->use_sg = 0;
5608 #endif
5610 for (i = 0; i < MAX_HDRIVES; ++i) {
5611 if (ha->hdr[i].present) {
5612 gdtcmd.BoardNode = LOCALBOARD;
5613 gdtcmd.Service = CACHESERVICE;
5614 gdtcmd.OpCode = GDT_FLUSH;
5615 if (ha->cache_feat & GDT_64BIT) {
5616 gdtcmd.u.cache64.DeviceNo = i;
5617 gdtcmd.u.cache64.BlockNo = 1;
5618 gdtcmd.u.cache64.sg_canz = 0;
5619 } else {
5620 gdtcmd.u.cache.DeviceNo = i;
5621 gdtcmd.u.cache.BlockNo = 1;
5622 gdtcmd.u.cache.sg_canz = 0;
5624 TRACE2(("gdth_flush(): flush ha %d drive %d\n", hanum, i));
5625 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5626 gdth_do_req(srp, &gdtcmd, cmnd, 30);
5627 #else
5628 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
5629 #endif
5632 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5633 scsi_release_request(srp);
5634 scsi_free_host_dev(sdev);
5635 #else
5636 scsi_release_command(scp);
5637 scsi_free_host_dev(sdev);
5638 #endif
5641 /* shutdown routine */
5642 static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
5644 int hanum;
5645 #ifndef __alpha__
5646 gdth_cmd_str gdtcmd;
5647 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5648 Scsi_Request *srp;
5649 Scsi_Device *sdev;
5650 #else
5651 Scsi_Cmnd *scp;
5652 Scsi_Device *sdev;
5653 #endif
5654 char cmnd[MAX_COMMAND_SIZE];
5655 #endif
5657 TRACE2(("gdth_halt() event %d\n",(int)event));
5658 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
5659 return NOTIFY_DONE;
5661 printk("GDT-HA: Flushing all host drives .. ");
5662 for (hanum = 0; hanum < gdth_ctr_count; ++hanum) {
5663 gdth_flush(hanum);
5665 #ifndef __alpha__
5666 /* controller reset */
5667 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
5668 gdtcmd.BoardNode = LOCALBOARD;
5669 gdtcmd.Service = CACHESERVICE;
5670 gdtcmd.OpCode = GDT_RESET;
5671 TRACE2(("gdth_halt(): reset controller %d\n", hanum));
5672 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5673 sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
5674 srp = scsi_allocate_request(sdev, GFP_KERNEL);
5675 if (!srp) {
5676 unregister_reboot_notifier(&gdth_notifier);
5677 return NOTIFY_OK;
5679 srp->sr_cmd_len = 12;
5680 srp->sr_use_sg = 0;
5681 gdth_do_req(srp, &gdtcmd, cmnd, 10);
5682 scsi_release_request(srp);
5683 scsi_free_host_dev(sdev);
5684 #else
5685 sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
5686 scp = scsi_allocate_device(sdev, 1, FALSE);
5687 if (!scp) {
5688 unregister_reboot_notifier(&gdth_notifier);
5689 return NOTIFY_OK;
5691 scp->cmd_len = 12;
5692 scp->use_sg = 0;
5693 gdth_do_cmd(scp, &gdtcmd, cmnd, 10);
5694 scsi_release_command(scp);
5695 scsi_free_host_dev(sdev);
5696 #endif
5697 #endif
5699 printk("Done.\n");
5701 #ifdef GDTH_STATISTICS
5702 del_timer(&gdth_timer);
5703 #endif
5704 unregister_reboot_notifier(&gdth_notifier);
5705 return NOTIFY_OK;
5708 static Scsi_Host_Template driver_template = {
5709 .proc_name = "gdth",
5710 .proc_info = gdth_proc_info,
5711 .name = "GDT SCSI Disk Array Controller",
5712 .detect = gdth_detect,
5713 .release = gdth_release,
5714 .info = gdth_info,
5715 .queuecommand = gdth_queuecommand,
5716 .eh_abort_handler = gdth_eh_abort,
5717 .eh_device_reset_handler = gdth_eh_device_reset,
5718 .eh_bus_reset_handler = gdth_eh_bus_reset,
5719 .eh_host_reset_handler = gdth_eh_host_reset,
5720 .bios_param = gdth_bios_param,
5721 .can_queue = GDTH_MAXCMDS,
5722 .this_id = -1,
5723 .sg_tablesize = GDTH_MAXSG,
5724 .cmd_per_lun = GDTH_MAXC_P_L,
5725 .unchecked_isa_dma = 1,
5726 .use_clustering = ENABLE_CLUSTERING,
5727 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
5728 .use_new_eh_code = 1,
5729 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
5730 .highmem_io = 1,
5731 #endif
5732 #endif
5735 #include "scsi_module.c"
5736 #ifndef MODULE
5737 __setup("gdth=", option_setup);
5738 #endif